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