propane 3.10.0-java → 3.11.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) hide show
  1. checksums.yaml +4 -4
  2. data/.mvn/wrapper/maven-wrapper.properties +1 -1
  3. data/CHANGELOG.md +2 -0
  4. data/README.md +7 -7
  5. data/lib/propane/app.rb +2 -5
  6. data/lib/propane/helper_methods.rb +6 -6
  7. data/lib/propane/version.rb +1 -1
  8. data/lib/{propane-3.10.0.jar → propane-3.11.0.jar} +0 -0
  9. data/pom.rb +6 -6
  10. data/pom.xml +6 -6
  11. data/propane.gemspec +3 -3
  12. data/src/main/java/monkstone/noise/OpenSimplex2F.java +838 -737
  13. data/src/main/java/monkstone/vecmath/vec2/Vec2.java +8 -13
  14. data/src/main/java/monkstone/vecmath/vec3/Vec3.java +14 -28
  15. data/src/main/java/processing/awt/PImageAWT.java +6 -4
  16. data/src/main/java/processing/core/PApplet.java +71 -59
  17. data/src/main/java/processing/core/PImage.java +14 -14
  18. data/src/main/java/processing/opengl/PGraphicsOpenGL.java +13 -13
  19. data/src/main/java/processing/opengl/PShader.java +1 -6
  20. data/src/main/java/processing/opengl/PSurfaceJOGL.java +6 -6
  21. data/{lib/java/processing/opengl → src/main/resources}/cursors/arrow.png +0 -0
  22. data/{lib/java/processing/opengl → src/main/resources}/cursors/cross.png +0 -0
  23. data/{lib/java/processing/opengl → src/main/resources}/cursors/hand.png +0 -0
  24. data/{lib/java/processing/opengl → src/main/resources}/cursors/license.txt +0 -0
  25. data/{lib/java/processing/opengl → src/main/resources}/cursors/move.png +0 -0
  26. data/{lib/java/processing/opengl → src/main/resources}/cursors/text.png +0 -0
  27. data/{lib/java/processing/opengl → src/main/resources}/cursors/wait.png +0 -0
  28. data/{lib/java/processing/opengl → src/main/resources}/shaders/ColorFrag.glsl +0 -0
  29. data/{lib/java/processing/opengl → src/main/resources}/shaders/ColorVert.glsl +0 -0
  30. data/{lib/java/processing/opengl → src/main/resources}/shaders/LightFrag.glsl +0 -0
  31. data/{lib/java/processing/opengl → src/main/resources}/shaders/LightVert.glsl +0 -0
  32. data/{lib/java/processing/opengl → src/main/resources}/shaders/LineFrag.glsl +0 -0
  33. data/{lib/java/processing/opengl → src/main/resources}/shaders/LineVert.glsl +0 -0
  34. data/{lib/java/processing/opengl → src/main/resources}/shaders/MaskFrag.glsl +0 -0
  35. data/{lib/java/processing/opengl → src/main/resources}/shaders/PointFrag.glsl +0 -0
  36. data/{lib/java/processing/opengl → src/main/resources}/shaders/PointVert.glsl +0 -0
  37. data/{lib/java/processing/opengl → src/main/resources}/shaders/TexFrag.glsl +0 -0
  38. data/{lib/java/processing/opengl → src/main/resources}/shaders/TexLightFrag.glsl +0 -0
  39. data/{lib/java/processing/opengl → src/main/resources}/shaders/TexLightVert.glsl +0 -0
  40. data/{lib/java/processing/opengl → src/main/resources}/shaders/TexVert.glsl +0 -0
  41. data/test/test_helper.rb +1 -0
  42. data/vendors/Rakefile +1 -1
  43. metadata +29 -155
  44. data/lib/java/japplemenubar/JAppleMenuBar.java +0 -88
  45. data/lib/java/japplemenubar/libjAppleMenuBar.jnilib +0 -0
  46. data/lib/java/monkstone/ColorUtil.java +0 -127
  47. data/lib/java/monkstone/MathToolModule.java +0 -287
  48. data/lib/java/monkstone/PropaneLibrary.java +0 -46
  49. data/lib/java/monkstone/core/LibraryProxy.java +0 -136
  50. data/lib/java/monkstone/fastmath/DegLutTables.java +0 -111
  51. data/lib/java/monkstone/fastmath/Deglut.java +0 -71
  52. data/lib/java/monkstone/fastmath/package-info.java +0 -6
  53. data/lib/java/monkstone/filechooser/Chooser.java +0 -39
  54. data/lib/java/monkstone/noise/FastTerrain.java +0 -874
  55. data/lib/java/monkstone/noise/Noise.java +0 -90
  56. data/lib/java/monkstone/noise/NoiseGenerator.java +0 -75
  57. data/lib/java/monkstone/noise/NoiseMode.java +0 -28
  58. data/lib/java/monkstone/noise/OpenSimplex2F.java +0 -881
  59. data/lib/java/monkstone/noise/OpenSimplex2S.java +0 -1106
  60. data/lib/java/monkstone/noise/SmoothTerrain.java +0 -1099
  61. data/lib/java/monkstone/slider/CustomHorizontalSlider.java +0 -164
  62. data/lib/java/monkstone/slider/CustomVerticalSlider.java +0 -178
  63. data/lib/java/monkstone/slider/SimpleHorizontalSlider.java +0 -145
  64. data/lib/java/monkstone/slider/SimpleSlider.java +0 -166
  65. data/lib/java/monkstone/slider/SimpleVerticalSlider.java +0 -157
  66. data/lib/java/monkstone/slider/Slider.java +0 -61
  67. data/lib/java/monkstone/slider/SliderBar.java +0 -245
  68. data/lib/java/monkstone/slider/SliderGroup.java +0 -56
  69. data/lib/java/monkstone/slider/WheelHandler.java +0 -35
  70. data/lib/java/monkstone/vecmath/GfxRender.java +0 -86
  71. data/lib/java/monkstone/vecmath/JRender.java +0 -56
  72. data/lib/java/monkstone/vecmath/ShapeRender.java +0 -87
  73. data/lib/java/monkstone/vecmath/package-info.java +0 -20
  74. data/lib/java/monkstone/vecmath/vec2/Vec2.java +0 -802
  75. data/lib/java/monkstone/vecmath/vec2/package-info.java +0 -6
  76. data/lib/java/monkstone/vecmath/vec3/Vec3.java +0 -727
  77. data/lib/java/monkstone/vecmath/vec3/package-info.java +0 -6
  78. data/lib/java/monkstone/videoevent/CaptureEvent.java +0 -27
  79. data/lib/java/monkstone/videoevent/MovieEvent.java +0 -32
  80. data/lib/java/monkstone/videoevent/package-info.java +0 -20
  81. data/lib/java/processing/awt/PGraphicsJava2D.java +0 -3040
  82. data/lib/java/processing/awt/PImageAWT.java +0 -377
  83. data/lib/java/processing/awt/PShapeJava2D.java +0 -387
  84. data/lib/java/processing/awt/PSurfaceAWT.java +0 -1581
  85. data/lib/java/processing/awt/ShimAWT.java +0 -581
  86. data/lib/java/processing/core/PApplet.java +0 -15156
  87. data/lib/java/processing/core/PConstants.java +0 -523
  88. data/lib/java/processing/core/PFont.java +0 -1126
  89. data/lib/java/processing/core/PGraphics.java +0 -8600
  90. data/lib/java/processing/core/PImage.java +0 -3377
  91. data/lib/java/processing/core/PMatrix.java +0 -208
  92. data/lib/java/processing/core/PMatrix2D.java +0 -562
  93. data/lib/java/processing/core/PMatrix3D.java +0 -890
  94. data/lib/java/processing/core/PShape.java +0 -3561
  95. data/lib/java/processing/core/PShapeOBJ.java +0 -483
  96. data/lib/java/processing/core/PShapeSVG.java +0 -2016
  97. data/lib/java/processing/core/PStyle.java +0 -63
  98. data/lib/java/processing/core/PSurface.java +0 -198
  99. data/lib/java/processing/core/PSurfaceNone.java +0 -431
  100. data/lib/java/processing/core/PVector.java +0 -1066
  101. data/lib/java/processing/core/ThinkDifferent.java +0 -115
  102. data/lib/java/processing/data/DoubleDict.java +0 -850
  103. data/lib/java/processing/data/DoubleList.java +0 -928
  104. data/lib/java/processing/data/FloatDict.java +0 -847
  105. data/lib/java/processing/data/FloatList.java +0 -936
  106. data/lib/java/processing/data/IntDict.java +0 -807
  107. data/lib/java/processing/data/IntList.java +0 -936
  108. data/lib/java/processing/data/JSONArray.java +0 -1260
  109. data/lib/java/processing/data/JSONObject.java +0 -2282
  110. data/lib/java/processing/data/JSONTokener.java +0 -435
  111. data/lib/java/processing/data/LongDict.java +0 -802
  112. data/lib/java/processing/data/LongList.java +0 -937
  113. data/lib/java/processing/data/Sort.java +0 -46
  114. data/lib/java/processing/data/StringDict.java +0 -613
  115. data/lib/java/processing/data/StringList.java +0 -800
  116. data/lib/java/processing/data/Table.java +0 -4936
  117. data/lib/java/processing/data/TableRow.java +0 -198
  118. data/lib/java/processing/data/XML.java +0 -1156
  119. data/lib/java/processing/dxf/RawDXF.java +0 -404
  120. data/lib/java/processing/event/Event.java +0 -125
  121. data/lib/java/processing/event/KeyEvent.java +0 -70
  122. data/lib/java/processing/event/MouseEvent.java +0 -114
  123. data/lib/java/processing/event/TouchEvent.java +0 -57
  124. data/lib/java/processing/javafx/PGraphicsFX2D.java +0 -32
  125. data/lib/java/processing/javafx/PSurfaceFX.java +0 -173
  126. data/lib/java/processing/net/Client.java +0 -744
  127. data/lib/java/processing/net/Server.java +0 -388
  128. data/lib/java/processing/opengl/FontTexture.java +0 -378
  129. data/lib/java/processing/opengl/FrameBuffer.java +0 -513
  130. data/lib/java/processing/opengl/LinePath.java +0 -627
  131. data/lib/java/processing/opengl/LineStroker.java +0 -681
  132. data/lib/java/processing/opengl/PGL.java +0 -3483
  133. data/lib/java/processing/opengl/PGraphics2D.java +0 -615
  134. data/lib/java/processing/opengl/PGraphics3D.java +0 -281
  135. data/lib/java/processing/opengl/PGraphicsOpenGL.java +0 -13753
  136. data/lib/java/processing/opengl/PJOGL.java +0 -2008
  137. data/lib/java/processing/opengl/PShader.java +0 -1484
  138. data/lib/java/processing/opengl/PShapeOpenGL.java +0 -5269
  139. data/lib/java/processing/opengl/PSurfaceJOGL.java +0 -1385
  140. data/lib/java/processing/opengl/Texture.java +0 -1696
  141. data/lib/java/processing/opengl/VertexBuffer.java +0 -88
  142. data/lib/java/processing/pdf/PGraphicsPDF.java +0 -581
  143. data/lib/java/processing/svg/PGraphicsSVG.java +0 -378
  144. data/src/main/java/processing/opengl/cursors/arrow.png +0 -0
  145. data/src/main/java/processing/opengl/cursors/cross.png +0 -0
  146. data/src/main/java/processing/opengl/cursors/hand.png +0 -0
  147. data/src/main/java/processing/opengl/cursors/license.txt +0 -27
  148. data/src/main/java/processing/opengl/cursors/move.png +0 -0
  149. data/src/main/java/processing/opengl/cursors/text.png +0 -0
  150. data/src/main/java/processing/opengl/cursors/wait.png +0 -0
  151. data/src/main/java/processing/opengl/shaders/ColorFrag.glsl +0 -32
  152. data/src/main/java/processing/opengl/shaders/ColorVert.glsl +0 -34
  153. data/src/main/java/processing/opengl/shaders/LightFrag.glsl +0 -33
  154. data/src/main/java/processing/opengl/shaders/LightVert.glsl +0 -151
  155. data/src/main/java/processing/opengl/shaders/LineFrag.glsl +0 -32
  156. data/src/main/java/processing/opengl/shaders/LineVert.glsl +0 -100
  157. data/src/main/java/processing/opengl/shaders/MaskFrag.glsl +0 -40
  158. data/src/main/java/processing/opengl/shaders/PointFrag.glsl +0 -32
  159. data/src/main/java/processing/opengl/shaders/PointVert.glsl +0 -56
  160. data/src/main/java/processing/opengl/shaders/TexFrag.glsl +0 -37
  161. data/src/main/java/processing/opengl/shaders/TexLightFrag.glsl +0 -37
  162. data/src/main/java/processing/opengl/shaders/TexLightVert.glsl +0 -157
  163. data/src/main/java/processing/opengl/shaders/TexVert.glsl +0 -38
@@ -1,483 +0,0 @@
1
- package processing.core;
2
-
3
- import java.io.BufferedReader;
4
- import java.io.File;
5
- import java.io.IOException;
6
- import java.util.ArrayList;
7
- import java.util.HashMap;
8
- import java.util.Map;
9
-
10
- /**
11
- * This class is not part of the Processing API and should not be used
12
- * directly. Instead, use loadShape() and methods like it, which will make
13
- * use of this class. Using this class directly will cause your code to break
14
- * when combined with future versions of Processing.
15
- * <p>
16
- * OBJ loading implemented using code from Saito's OBJLoader library:
17
- * http://code.google.com/p/saitoobjloader/
18
- * and OBJReader from Ahmet Kizilay
19
- * http://www.openprocessing.org/visuals/?visualID=191
20
- *
21
- */
22
- public class PShapeOBJ extends PShape {
23
-
24
- /**
25
- * Initializes a new OBJ Object with the given filename.
26
- * @param parent
27
- * @param filename
28
- */
29
- public PShapeOBJ(PApplet parent, String filename) {
30
- this(parent, parent.createReader(filename), getBasePath(parent, filename));
31
- }
32
-
33
- public PShapeOBJ(PApplet parent, BufferedReader reader) {
34
- this(parent, reader, "");
35
- }
36
-
37
- public PShapeOBJ(PApplet parent, BufferedReader reader, String basePath) {
38
- ArrayList<OBJFace> faces = new ArrayList<>();
39
- ArrayList<OBJMaterial> materials = new ArrayList<>();
40
- ArrayList<PVector> coords = new ArrayList<>();
41
- ArrayList<PVector> normals = new ArrayList<>();
42
- ArrayList<PVector> texcoords = new ArrayList<>();
43
- parseOBJ(parent, basePath, reader,
44
- faces, materials, coords, normals, texcoords);
45
-
46
- // The OBJ geometry is stored with each face in a separate child shape.
47
- parent = null;
48
- family = GROUP;
49
- addChildren(faces, materials, coords, normals, texcoords);
50
- }
51
-
52
-
53
- protected PShapeOBJ(OBJFace face, OBJMaterial mtl,
54
- ArrayList<PVector> coords,
55
- ArrayList<PVector> normals,
56
- ArrayList<PVector> texcoords) {
57
- family = GEOMETRY;
58
- switch (face.vertIdx.size()) {
59
- case 3:
60
- kind = TRIANGLES;
61
- break;
62
- case 4:
63
- kind = QUADS;
64
- break;
65
- default:
66
- kind = POLYGON;
67
- break;
68
- }
69
-
70
- stroke = false;
71
- fill = true;
72
-
73
- // Setting material properties for the new face
74
- fillColor = rgbaValue(mtl.kd);
75
- ambientColor = rgbaValue(mtl.ka);
76
- specularColor = rgbaValue(mtl.ks);
77
- shininess = mtl.ns;
78
- if (mtl.kdMap != null) {
79
- // If current material is textured, then tinting the texture using the
80
- // diffuse color.
81
- tintColor = rgbaValue(mtl.kd, mtl.d);
82
- }
83
-
84
- vertexCount = face.vertIdx.size();
85
- vertices = new float[vertexCount][12];
86
- for (int j = 0; j < face.vertIdx.size(); j++){
87
- int vertIdx, normIdx, texIdx;
88
- PVector vert, norms, tex;
89
-
90
- vert = norms = tex = null;
91
-
92
- vertIdx = face.vertIdx.get(j) - 1;
93
- vert = coords.get(vertIdx);
94
-
95
- if (j < face.normIdx.size()) {
96
- normIdx = face.normIdx.get(j) - 1;
97
- if (-1 < normIdx) {
98
- norms = normals.get(normIdx);
99
- }
100
- }
101
-
102
- if (j < face.texIdx.size()) {
103
- texIdx = face.texIdx.get(j) - 1;
104
- if (-1 < texIdx) {
105
- tex = texcoords.get(texIdx);
106
- }
107
- }
108
-
109
- vertices[j][X] = vert.x;
110
- vertices[j][Y] = vert.y;
111
- vertices[j][Z] = vert.z;
112
-
113
- vertices[j][PGraphics.R] = mtl.kd.x;
114
- vertices[j][PGraphics.G] = mtl.kd.y;
115
- vertices[j][PGraphics.B] = mtl.kd.z;
116
- vertices[j][PGraphics.A] = 1;
117
-
118
- if (norms != null) {
119
- vertices[j][PGraphics.NX] = norms.x;
120
- vertices[j][PGraphics.NY] = norms.y;
121
- vertices[j][PGraphics.NZ] = norms.z;
122
- }
123
-
124
- if (tex != null) {
125
- vertices[j][PGraphics.U] = tex.x;
126
- vertices[j][PGraphics.V] = tex.y;
127
- }
128
-
129
- if (mtl != null && mtl.kdMap != null) {
130
- image = mtl.kdMap;
131
- }
132
- }
133
- }
134
-
135
-
136
- protected void addChildren(ArrayList<OBJFace> faces,
137
- ArrayList<OBJMaterial> materials,
138
- ArrayList<PVector> coords,
139
- ArrayList<PVector> normals,
140
- ArrayList<PVector> texcoords) {
141
- int mtlIdxCur = -1;
142
- OBJMaterial mtl = null;
143
- for (int i = 0; i < faces.size(); i++) {
144
- OBJFace face = faces.get(i);
145
-
146
- // Getting current material.
147
- if (mtlIdxCur != face.matIdx || face.matIdx == -1) {
148
- // To make sure that at least we get the default material
149
- mtlIdxCur = PApplet.max(0, face.matIdx);
150
- mtl = materials.get(mtlIdxCur);
151
- }
152
-
153
- // Creating child shape for current face.
154
- PShape child = new PShapeOBJ(face, mtl, coords, normals, texcoords);
155
- addChild(child);
156
- }
157
- }
158
-
159
-
160
- static protected void parseOBJ(PApplet parent, String path,
161
- BufferedReader reader,
162
- ArrayList<OBJFace> faces,
163
- ArrayList<OBJMaterial> materials,
164
- ArrayList<PVector> coords,
165
- ArrayList<PVector> normals,
166
- ArrayList<PVector> texcoords) {
167
- Map<String, Integer> mtlTable = new HashMap<>();
168
- int mtlIdxCur = -1;
169
- boolean readv, readvn, readvt;
170
- try {
171
-
172
- readv = readvn = readvt = false;
173
- String line;
174
- String gname = "object";
175
- while ((line = reader.readLine()) != null) {
176
- // Parse the line.
177
- line = line.trim();
178
- if (line.equals("") || line.indexOf('#') == 0) {
179
- // Empty line of comment, ignore line
180
- continue;
181
- }
182
-
183
- // The below patch/hack comes from Carlos Tomas Marti and is a
184
- // fix for single backslashes in Rhino obj files
185
-
186
- // BEGINNING OF RHINO OBJ FILES HACK
187
- // Statements can be broken in multiple lines using '\' at the
188
- // end of a line.
189
- // In regular expressions, the backslash is also an escape
190
- // character.
191
- // The regular expression \\ matches a single backslash. This
192
- // regular expression as a Java string, becomes "\\\\".
193
- // That's right: 4 backslashes to match a single one.
194
- while (line.contains("\\")) {
195
- line = line.split("\\\\")[0];
196
- final String s = reader.readLine();
197
- if (s != null)
198
- line += s;
199
- }
200
- // END OF RHINO OBJ FILES HACK
201
-
202
- String[] parts = line.split("\\s+");
203
- // if not a blank line, process the line.
204
- if (parts.length > 0) {
205
- switch (parts[0]) {
206
- case "v":
207
- {
208
- // vertex
209
- PVector tempv = new PVector(Float.parseFloat(parts[1]),
210
- Float.parseFloat(parts[2]),
211
- Float.parseFloat(parts[3]));
212
- coords.add(tempv);
213
- readv = true;
214
- break;
215
- }
216
- case "vn":
217
- // normal
218
- PVector tempn = new PVector(Float.parseFloat(parts[1]),
219
- Float.parseFloat(parts[2]),
220
- Float.parseFloat(parts[3]));
221
- normals.add(tempn);
222
- readvn = true;
223
- break;
224
- case "vt":
225
- {
226
- // uv, inverting v to take into account Processing's inverted Y axis
227
- // with respect to OpenGL.
228
- PVector tempv = new PVector(Float.parseFloat(parts[1]),
229
- 1 - Float.parseFloat(parts[2]));
230
- texcoords.add(tempv);
231
- readvt = true;
232
- break;
233
- }
234
- // Object name is ignored, for now.
235
- case "o":
236
- break;
237
- case "mtllib":
238
- if (parts[1] != null) {
239
- String fn = parts[1];
240
- if (!fn.contains(File.separator) && !path.equals("")) {
241
- // Relative file name, adding the base path.
242
- fn = path + File.separator + fn;
243
- }
244
- BufferedReader mreader = parent.createReader(fn);
245
- if (mreader != null) {
246
- parseMTL(parent, fn, path, mreader, materials, mtlTable);
247
- mreader.close();
248
- }
249
- } break;
250
- case "g":
251
- gname = 1 < parts.length ? parts[1] : "";
252
- break;
253
- case "usemtl":
254
- // Getting index of current active material (will be applied on
255
- // all subsequent faces).
256
- if (parts[1] != null) {
257
- String mtlname = parts[1];
258
- if (mtlTable.containsKey(mtlname)) {
259
- Integer tempInt = mtlTable.get(mtlname);
260
- mtlIdxCur = tempInt;
261
- } else {
262
- mtlIdxCur = -1;
263
- }
264
- } break;
265
- case "f":
266
- // Face setting
267
- OBJFace face = new OBJFace();
268
- face.matIdx = mtlIdxCur;
269
- face.name = gname;
270
- for (int i = 1; i < parts.length; i++) {
271
- String seg = parts[i];
272
-
273
- if (seg.indexOf("/") > 0) {
274
- String[] forder = seg.split("/");
275
-
276
- if (forder.length > 2) {
277
- // Getting vertex and texture and normal indexes.
278
- if (forder[0].length() > 0 && readv) {
279
- face.vertIdx.add(Integer.valueOf(forder[0]));
280
- }
281
-
282
- if (forder[1].length() > 0 && readvt) {
283
- face.texIdx.add(Integer.valueOf(forder[1]));
284
- }
285
-
286
- if (forder[2].length() > 0 && readvn) {
287
- face.normIdx.add(Integer.valueOf(forder[2]));
288
- }
289
- } else if (forder.length > 1) {
290
- // Getting vertex and texture/normal indexes.
291
- if (forder[0].length() > 0 && readv) {
292
- face.vertIdx.add(Integer.valueOf(forder[0]));
293
- }
294
-
295
- if (forder[1].length() > 0) {
296
- if (readvt) {
297
- face.texIdx.add(Integer.valueOf(forder[1]));
298
- } else if (readvn) {
299
- face.normIdx.add(Integer.valueOf(forder[1]));
300
- }
301
-
302
- }
303
-
304
- } else if (forder.length > 0) {
305
- // Getting vertex index only.
306
- if (forder[0].length() > 0 && readv) {
307
- face.vertIdx.add(Integer.valueOf(forder[0]));
308
- }
309
- }
310
- } else {
311
- // Getting vertex index only.
312
- if (seg.length() > 0 && readv) {
313
- face.vertIdx.add(Integer.valueOf(seg));
314
- }
315
- }
316
- } faces.add(face);
317
- break;
318
- default:
319
- break;
320
- }
321
- }
322
- }
323
-
324
- if (materials.isEmpty()) {
325
- // No materials definition so far. Adding one default material.
326
- OBJMaterial defMtl = new OBJMaterial();
327
- materials.add(defMtl);
328
- }
329
-
330
- } catch (IOException | NumberFormatException e) {
331
- }
332
- }
333
-
334
-
335
- static protected void parseMTL(PApplet parent, String mtlfn, String path,
336
- BufferedReader reader,
337
- ArrayList<OBJMaterial> materials,
338
- Map<String, Integer> materialsHash) {
339
- try {
340
- String line;
341
- OBJMaterial currentMtl = null;
342
- while ((line = reader.readLine()) != null) {
343
- // Parse the line
344
- line = line.trim();
345
- String[] parts = line.split("\\s+");
346
- if (parts.length > 0) {
347
- // Extract the material data.
348
- if (parts[0].equals("newmtl")) {
349
- // Starting new material.
350
- String mtlname = parts[1];
351
- currentMtl = addMaterial(mtlname, materials, materialsHash);
352
- } else {
353
- if (currentMtl == null) {
354
- currentMtl = addMaterial("material" + materials.size(),
355
- materials, materialsHash);
356
- }
357
- if (parts[0].equals("map_Kd") && parts.length > 1) {
358
- // Loading texture map.
359
- String texname = parts[1];
360
- if (!texname.contains(File.separator) && !path.equals("")) {
361
- // Relative file name, adding the base path.
362
- texname = path + File.separator + texname;
363
- }
364
-
365
- File file = new File(parent.dataPath(texname));
366
- if (file.exists()) {
367
- currentMtl.kdMap = parent.loadImage(texname);
368
- } else {
369
- System.err.println("The texture map \"" + texname + "\" " +
370
- "in the materials definition file \"" + mtlfn + "\" " +
371
- "is missing or inaccessible, make sure " +
372
- "the URL is valid or that the file has been " +
373
- "added to your sketch and is readable.");
374
- }
375
- } else if (parts[0].equals("Ka") && parts.length > 3) {
376
- // The ambient color of the material
377
- currentMtl.ka.x = Float.parseFloat(parts[1]);
378
- currentMtl.ka.y = Float.parseFloat(parts[2]);
379
- currentMtl.ka.z = Float.parseFloat(parts[3]);
380
- } else if (parts[0].equals("Kd") && parts.length > 3) {
381
- // The diffuse color of the material
382
- currentMtl.kd.x = Float.parseFloat(parts[1]);
383
- currentMtl.kd.y = Float.parseFloat(parts[2]);
384
- currentMtl.kd.z = Float.parseFloat(parts[3]);
385
- } else if (parts[0].equals("Ks") && parts.length > 3) {
386
- // The specular color weighted by the specular coefficient
387
- currentMtl.ks.x = Float.parseFloat(parts[1]);
388
- currentMtl.ks.y = Float.parseFloat(parts[2]);
389
- currentMtl.ks.z = Float.parseFloat(parts[3]);
390
- } else if ((parts[0].equals("d") ||
391
- parts[0].equals("Tr")) && parts.length > 1) {
392
- // Reading the alpha transparency.
393
- currentMtl.d = Float.parseFloat(parts[1]);
394
- } else if (parts[0].equals("Ns") && parts.length > 1) {
395
- // The specular component of the Phong shading model
396
- currentMtl.ns = Float.parseFloat(parts[1]);
397
- }
398
- }
399
- }
400
- }
401
- } catch (IOException | NumberFormatException e) {
402
- }
403
- }
404
-
405
- protected static OBJMaterial addMaterial(String mtlname,
406
- ArrayList<OBJMaterial> materials,
407
- Map<String, Integer> materialsHash) {
408
- OBJMaterial currentMtl = new OBJMaterial(mtlname);
409
- materialsHash.put(mtlname, materials.size());
410
- materials.add(currentMtl);
411
- return currentMtl;
412
- }
413
-
414
- protected static int rgbaValue(PVector color) {
415
- return 0xFF000000 | ((int)(color.x * 255) << 16) |
416
- ((int)(color.y * 255) << 8) |
417
- (int)(color.z * 255);
418
- }
419
-
420
-
421
- protected static int rgbaValue(PVector color, float alpha) {
422
- return ((int)(alpha * 255) << 24) |
423
- ((int)(color.x * 255) << 16) |
424
- ((int)(color.y * 255) << 8) |
425
- (int)(color.z * 255);
426
- }
427
-
428
-
429
- // Stores a face from an OBJ file
430
- static protected class OBJFace {
431
- ArrayList<Integer> vertIdx;
432
- ArrayList<Integer> texIdx;
433
- ArrayList<Integer> normIdx;
434
- int matIdx;
435
- String name;
436
-
437
- OBJFace() {
438
- vertIdx = new ArrayList<>();
439
- texIdx = new ArrayList<>();
440
- normIdx = new ArrayList<>();
441
- matIdx = -1;
442
- name = "";
443
- }
444
- }
445
-
446
-
447
- static protected String getBasePath(PApplet parent, String filename) {
448
- // Obtaining the path
449
- File file = new File(parent.dataPath(filename));
450
- if (!file.exists()) {
451
- file = parent.sketchFile(filename);
452
- }
453
- String absolutePath = file.getAbsolutePath();
454
- return absolutePath.substring(0,
455
- absolutePath.lastIndexOf(File.separator));
456
- }
457
-
458
-
459
- // Stores a material defined in an MTL file.
460
- static protected class OBJMaterial {
461
- String name;
462
- PVector ka;
463
- PVector kd;
464
- PVector ks;
465
- float d;
466
- float ns;
467
- PImage kdMap;
468
-
469
- OBJMaterial() {
470
- this("default");
471
- }
472
-
473
- OBJMaterial(String name) {
474
- this.name = name;
475
- ka = new PVector(0.5f, 0.5f, 0.5f);
476
- kd = new PVector(0.5f, 0.5f, 0.5f);
477
- ks = new PVector(0.5f, 0.5f, 0.5f);
478
- d = 1.0f;
479
- ns = 0.0f;
480
- kdMap = null;
481
- }
482
- }
483
- }