Normand Briere
2019-07-27 1af7d3700724834e40ad8636bc9a56cdc3b19b15
CameraPane.java
....@@ -18,7 +18,10 @@
1818 import javax.imageio.ImageIO;
1919 import javax.imageio.ImageWriteParam;
2020 import javax.imageio.ImageWriter;
21
+import javax.imageio.ImageReadParam;
22
+import javax.imageio.ImageReader;
2123 import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
24
+import javax.imageio.stream.ImageInputStream;
2225 import javax.imageio.stream.ImageOutputStream;
2326 import javax.imageio.ImageWriteParam;
2427
....@@ -30,6 +33,7 @@
3033 import java.nio.*;
3134
3235 import gleem.linalg.Mat4f;
36
+import javax.imageio.ImageTypeSpecifier;
3337
3438 class CameraPane extends GLCanvas implements iCameraPane, Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener
3539 {
....@@ -37,7 +41,6 @@
3741 static boolean[] selectedstack = new boolean[65536];
3842 static int materialdepth = 0;
3943
40
- static boolean DEBUG = false;
4144 static boolean FRUSTUM = false; // still bogus true; // frustum culling
4245
4346 // camera change fix
....@@ -45,6 +48,39 @@
4548 static boolean ABORTED = false;
4649
4750 static int STEP = 1;
51
+
52
+ private static BufferedImage CreateBim(byte[] bytes, int width, int height)
53
+ {
54
+ int[] pixels = new int[bytes.length/3];
55
+ for (int i=pixels.length; --i>=0;)
56
+ {
57
+ int i3 = i*3;
58
+ pixels[i] = 0xFF;
59
+ pixels[i] <<= 8;
60
+ pixels[i] |= bytes[i3+2] & 0xFF;
61
+ pixels[i] <<= 8;
62
+ pixels[i] |= bytes[i3+1] & 0xFF;
63
+ pixels[i] <<= 8;
64
+ pixels[i] |= bytes[i3] & 0xFF;
65
+ }
66
+ /*
67
+ int r=0,g=0,b=0,a=0;
68
+ for (int i=0; i<width; i++)
69
+ for (int j=0; j<height; j++)
70
+ {
71
+ int index = j*width+i;
72
+ int p = pixels[index];
73
+ a = ((p>>24) & 0xFF);
74
+ r = ((p>>16) & 0xFF);
75
+ g = ((p>>8) & 0xFF);
76
+ b = (p & 0xFF);
77
+ pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
78
+ }
79
+ /**/
80
+ BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
81
+ rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
82
+ return rendImage;
83
+ }
4884
4985 /*static*/ private boolean CULLFACE = false; // true;
5086 /*static*/ boolean NEAREST = false; // true;
....@@ -56,14 +92,12 @@
5692 static int CURRENTANTIALIAS = 0; // 1;
5793 /*static*/ boolean RENDERSHADOW = true;
5894 /*static*/ int RENDERPROGRAM = 2; // 0 == none, 1 == fast, 2 == normal
59
- static boolean ANIMATION = false;
60
- static String filename;
6195
6296 boolean DISPLAYTEXT = false;
6397 //boolean REDUCETEXTURE = true;
6498 boolean CACHETEXTURE = true;
6599 boolean CLEANCACHE = false; // true;
66
- boolean MIPMAP = false; // true;
100
+ boolean MIPMAP = false; // true; // never works...
67101 boolean COMPRESSTEXTURE = false;
68102 boolean KOMPACTTEXTURE = false; // true;
69103 boolean RESIZETEXTURE = false;
....@@ -92,6 +126,8 @@
92126
93127 static int tickcount = 0; // slow pose issue
94128
129
+static boolean BUTTONLESSWHEEL = false;
130
+static boolean ZOOMBOXMODE = false;
95131 static boolean BOXMODE = false;
96132 static boolean IMAGEFLIP = false;
97133 static boolean SMOOTHFOCUS = false;
....@@ -106,7 +142,7 @@
106142 static boolean OEIL = true;
107143 static boolean OEILONCE = false; // do oeilon then oeiloff
108144 static boolean LOOKAT = true;
109
-static boolean RANDOM = true; // false;
145
+static boolean SWITCH = true; // false;
110146 static boolean HANDLES = false; // selection doesn't work!!
111147 static boolean PAINTMODE = false;
112148
....@@ -150,12 +186,12 @@
150186 defaultcaps.setAccumAlphaBits(16);
151187 }
152188
153
- static CameraPane theRenderer;
189
+ private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
154190
155191 void SetAsGLRenderer(boolean b)
156192 {
157193 isRenderer = b;
158
- theRenderer = this;
194
+ Globals.theRenderer = this;
159195 }
160196
161197 CameraPane(Object3D o, Camera cam, boolean withcontext)
....@@ -170,7 +206,8 @@
170206
171207 SetCamera(cam);
172208
173
- SetLight(new Camera(new cVector(10, 10, -20)));
209
+ // Warning: not used.
210
+ SetLight(new Camera(new cVector(15, 10, -20)));
174211
175212 object = o;
176213
....@@ -193,9 +230,43 @@
193230
194231 /// INTERFACE
195232
233
+ public javax.media.opengl.GL GetGL0()
234
+ {
235
+ return null;
236
+ }
237
+
238
+ public int GenList()
239
+ {
240
+ javax.media.opengl.GL gl = GetGL();
241
+ return gl.glGenLists(1);
242
+ }
243
+
244
+ public void NewList(int id)
245
+ {
246
+ javax.media.opengl.GL gl = GetGL();
247
+ gl.glNewList(id, gl.GL_COMPILE); //_AND_EXECUTE);
248
+ }
249
+
250
+ public void CallList(int id)
251
+ {
252
+ javax.media.opengl.GL gl = GetGL();
253
+ gl.glCallList(id);
254
+ }
255
+
256
+ public void EndList()
257
+ {
258
+ javax.media.opengl.GL gl = GetGL();
259
+ gl.glEndList();
260
+ }
261
+
196262 public boolean IsBoxMode()
197263 {
198264 return BOXMODE;
265
+ }
266
+
267
+ public boolean IsZoomBoxMode()
268
+ {
269
+ return ZOOMBOXMODE;
199270 }
200271
201272 public void ClearDepth()
....@@ -293,7 +364,7 @@
293364 cStatic.objectstack[materialdepth++] = obj;
294365 //System.out.println("material " + material);
295366 //Applet3D.tracein(this, selected);
296
- display.vector2buffer = obj.projectedVertices;
367
+ //display.vector2buffer = obj.projectedVertices;
297368 if (obj instanceof Camera)
298369 {
299370 display.options1[0] = material.shift;
....@@ -302,14 +373,28 @@
302373 display.options1[2] = material.shadowbias;
303374 display.options1[3] = material.aniso;
304375 display.options1[4] = material.anisoV;
376
+// System.out.println("display.options1[0] " + display.options1[0]);
377
+// System.out.println("display.options1[1] " + display.options1[1]);
378
+// System.out.println("display.options1[2] " + display.options1[2]);
379
+// System.out.println("display.options1[3] " + display.options1[3]);
380
+// System.out.println("display.options1[4] " + display.options1[4]);
305381 display.options2[0] = material.opacity;
306382 display.options2[1] = material.diffuse;
307383 display.options2[2] = material.factor;
384
+// System.out.println("display.options2[0] " + display.options2[0]);
385
+// System.out.println("display.options2[1] " + display.options2[1]);
386
+// System.out.println("display.options2[2] " + display.options2[2]);
308387
309388 cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
389
+// System.out.println("display.options3[0] " + display.options3[0]);
390
+// System.out.println("display.options3[1] " + display.options3[1]);
391
+// System.out.println("display.options3[2] " + display.options3[2]);
310392 display.options4[0] = material.cameralight/0.2f;
311393 display.options4[1] = material.subsurface;
312394 display.options4[2] = material.sheen;
395
+// System.out.println("display.options4[0] " + display.options4[0]);
396
+// System.out.println("display.options4[1] " + display.options4[1]);
397
+// System.out.println("display.options4[2] " + display.options4[2]);
313398
314399 // if (display.CURRENTANTIALIAS > 0)
315400 // display.options3[3] /= 4;
....@@ -325,7 +410,7 @@
325410 /**/
326411 } else
327412 {
328
- DrawMaterial(material, selected);
413
+ DrawMaterial(material, selected, obj.projectedVertices);
329414 }
330415 } else
331416 {
....@@ -349,8 +434,8 @@
349434 cStatic.objectstack[materialdepth++] = obj;
350435 //System.out.println("material " + material);
351436 //Applet3D.tracein("selected ", selected);
352
- display.vector2buffer = obj.projectedVertices;
353
- display.DrawMaterial(material, selected);
437
+ //display.vector2buffer = obj.projectedVertices;
438
+ display.DrawMaterial(material, selected, obj.projectedVertices);
354439 }
355440 }
356441
....@@ -367,8 +452,8 @@
367452 materialdepth -= 1;
368453 if (materialdepth > 0)
369454 {
370
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
371
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
455
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
456
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
372457 }
373458 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
374459 } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
....@@ -388,8 +473,8 @@
388473 materialdepth -= 1;
389474 if (materialdepth > 0)
390475 {
391
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
392
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
476
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
477
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
393478 }
394479 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
395480 //else
....@@ -430,10 +515,12 @@
430515 if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
431516 {
432517 //gl.glBegin(gl.GL_TRIANGLES);
433
- boolean hasnorm = pv.norm != null; // && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0);
518
+ boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0)
519
+ // TEST LIVE NORMALS && !obj.dontselect
520
+ ;
434521 if (!hasnorm)
435522 {
436
- // System.out.println("FUCK!!");
523
+ // System.out.println("Mesh normal");
437524 LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
438525 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
439526 LA.vecCross(obj.v0, obj.v1, obj.v2);
....@@ -816,7 +903,7 @@
816903
817904 if ((i % 100) == 0 && i != 0)
818905 {
819
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
906
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
820907 //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
821908 System.out.println((int) (100.0 * i / (br.positions.length / 3)) + "% (" + i + " of " + (br.positions.length / 3) + ")");
822909 }
....@@ -848,7 +935,7 @@
848935
849936 if ((i % 100) == 0 && i != 0)
850937 {
851
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
938
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
852939 //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
853940 System.out.println((int) (100.0 * i / br.VertexCount()) + "% (" + i + " of " + br.VertexCount() + ")");
854941 }
....@@ -1061,7 +1148,342 @@
10611148 gl.glMatrixMode(gl.GL_MODELVIEW);
10621149 }
10631150
1151
+ public void DrawBox(cVector min, cVector max)
1152
+ {
1153
+ javax.media.opengl.GL gl = GetGL();
1154
+ gl.glBegin(gl.GL_LINES);
1155
+
1156
+ gl.glVertex3d(min.x, min.y, min.z);
1157
+ gl.glVertex3d(min.x, min.y, max.z);
1158
+ gl.glVertex3d(min.x, min.y, min.z);
1159
+ gl.glVertex3d(min.x, max.y, min.z);
1160
+ gl.glVertex3d(min.x, min.y, min.z);
1161
+ gl.glVertex3d(max.x, min.y, min.z);
1162
+
1163
+ gl.glVertex3d(max.x, max.y, max.z);
1164
+ gl.glVertex3d(min.x, max.y, max.z);
1165
+ gl.glVertex3d(max.x, max.y, max.z);
1166
+ gl.glVertex3d(max.x, min.y, max.z);
1167
+ gl.glVertex3d(max.x, max.y, max.z);
1168
+ gl.glVertex3d(max.x, max.y, min.z);
1169
+
1170
+ gl.glEnd();
1171
+ }
1172
+
1173
+ public void DrawGeometry(BoundaryRep bRep, boolean flipV, boolean selectmode)
1174
+ {
1175
+ int[] strips = bRep.getRawIndices();
1176
+
1177
+ javax.media.opengl.GL gl = GetGL();
1178
+
1179
+ // TRIANGLE STRIP ARRAY
1180
+ if (bRep.trimmed)
1181
+ {
1182
+ float[] v = bRep.getRawVertices();
1183
+ float[] n = bRep.getRawNormals();
1184
+ float[] c = bRep.getRawColors();
1185
+ float[] uv = bRep.getRawUVMap();
1186
+
1187
+ int count2 = 0;
1188
+ int count3 = 0;
1189
+
1190
+ if (n.length > 0)
1191
+ {
1192
+ for (int i = 0; i < strips.length; i++)
1193
+ {
1194
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1195
+
1196
+ /*
1197
+ boolean locked = false;
1198
+ float eps = 0.1f;
1199
+ boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
1200
+
1201
+ int dot = 0;
1202
+
1203
+ if ((dot&1) == 0)
1204
+ dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
1205
+
1206
+ if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
1207
+ gl.glTexCoord2f((float) qv.s, (float) qv.t);
1208
+ else
1209
+ {
1210
+ locked = true;
1211
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1212
+ }
1213
+ //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
1214
+ gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
1215
+ if (hasnorm)
1216
+ {
1217
+ //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
1218
+ gl.glNormal3f((float) rv.norm.x, (float) rv.norm.y, (float) rv.norm.z);
1219
+ }
1220
+
1221
+ if ((dot&4) == 0)
1222
+ dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
1223
+
1224
+ if (wrap || !locked && (dot&8) != 0)
1225
+ gl.glTexCoord2f((float) rv.s, (float) rv.t);
1226
+ else
1227
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1228
+
1229
+ f.dot = dot;
1230
+ */
1231
+
1232
+ if (!selectmode)
1233
+ {
1234
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1235
+ {
1236
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1237
+ } else
1238
+ {
1239
+ gl.glNormal3f(0, 0, 1);
1240
+ }
1241
+
1242
+ if (c != null)
1243
+ //System.out.println("glcolor = " + c[count3] + ", " + c[count3+1] + ", " + c[count3+2]);
1244
+ {
1245
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1246
+ }
1247
+ }
1248
+
1249
+ if (flipV)
1250
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1251
+ else
1252
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1253
+
1254
+ //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1255
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1256
+
1257
+ count2 += 2;
1258
+ count3 += 3;
1259
+ if (!selectmode)
1260
+ {
1261
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1262
+ {
1263
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1264
+ } else
1265
+ {
1266
+ gl.glNormal3f(0, 0, 1);
1267
+ }
1268
+ if (c != null)
1269
+ {
1270
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1271
+ }
1272
+ }
1273
+
1274
+ if (flipV)
1275
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1276
+ else
1277
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1278
+
1279
+ //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1280
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1281
+
1282
+ count2 += 2;
1283
+ count3 += 3;
1284
+ for (int j = 0; j < strips[i] - 2; j++)
1285
+ {
1286
+ //gl.glTexCoord2d(...);
1287
+ if (!selectmode)
1288
+ {
1289
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1290
+ {
1291
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1292
+ } else
1293
+ {
1294
+ gl.glNormal3f(0, 0, 1);
1295
+ }
1296
+ if (c != null)
1297
+ {
1298
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1299
+ }
1300
+ }
1301
+
1302
+ if (flipV)
1303
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1304
+ else
1305
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1306
+
1307
+ //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
1308
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1309
+
1310
+ count2 += 2;
1311
+ count3 += 3;
1312
+ }
1313
+
1314
+ gl.glEnd();
1315
+ }
1316
+ }
1317
+
1318
+ assert count3 == v.length;
1319
+ }
1320
+ else // !trimmed
1321
+ {
1322
+ int count = 0;
1323
+ for (int i = 0; i < strips.length; i++)
1324
+ {
1325
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1326
+
1327
+ Vertex p = bRep.GetVertex(bRep.indices[count++]);
1328
+ Vertex q = bRep.GetVertex(bRep.indices[count++]);
1329
+
1330
+ drawVertex(gl, p, flipV, selectmode);
1331
+ drawVertex(gl, q, flipV, selectmode);
1332
+
1333
+ for (int j = 0; j < strips[i] - 2; j++)
1334
+ {
1335
+ Vertex r = bRep.GetVertex(bRep.indices[count++]);
1336
+
1337
+ // if (j%2 == 0)
1338
+ // drawFace(p, q, r, display, null);
1339
+ // else
1340
+ // drawFace(p, r, q, display, null);
1341
+
1342
+ // p = q;
1343
+ // q = r;
1344
+ drawVertex(gl, r, flipV, selectmode);
1345
+ }
1346
+
1347
+ gl.glEnd();
1348
+ }
1349
+ }
1350
+ }
1351
+
1352
+ static cSpring.Point3D temp = new cSpring.Point3D();
1353
+ static cSpring.Point3D temp2 = new cSpring.Point3D();
1354
+ static cSpring.Point3D temp3 = new cSpring.Point3D();
1355
+
1356
+ public void DrawDynamicMesh(cMesh mesh)
1357
+ {
1358
+ GL gl = GetGL(); // getGL();
1359
+
1360
+ cSpring.PhysicsController3D Phys = mesh.Phys;
1361
+
1362
+ gl.glDisable(gl.GL_LIGHTING);
1363
+
1364
+ gl.glLineWidth(1);
1365
+ gl.glColor3f(1,1,1);
1366
+ gl.glBegin(gl.GL_LINES);
1367
+ double scale = 0;
1368
+ int count = 0;
1369
+ for (int s=0; s<Phys.allSprings.size(); s++)
1370
+ {
1371
+ cSpring.Spring spring = Phys.allSprings.get(s);
1372
+ if(s == 0)
1373
+ {
1374
+ //System.out.println(" spring : " + spring.a.position + "; " + spring.b.position);
1375
+ }
1376
+ if (mesh.showsprings)
1377
+ {
1378
+ temp.set(spring.a.position);
1379
+ temp.add(spring.b.position);
1380
+ temp.mul(0.5);
1381
+ temp2.set(spring.a.position);
1382
+ temp2.sub(spring.b.position);
1383
+ temp2.mul(spring.restLength/2);
1384
+ temp.sub(temp2);
1385
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1386
+ temp.add(temp2);
1387
+ temp.add(temp2);
1388
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1389
+ }
1390
+
1391
+ if (spring.isHandle)
1392
+ continue;
1393
+
1394
+ //if (scale < spring.restLength)
1395
+ scale += spring.restLength;
1396
+ count++;
1397
+ }
1398
+ gl.glEnd();
1399
+
1400
+ if (count == 0)
1401
+ scale = 0.01;
1402
+ else
1403
+ scale /= count * 3;
1404
+
1405
+ //scale = 0.25;
1406
+
1407
+ if (mesh.ShowInfo())
1408
+ {
1409
+ gl.glLineWidth(4);
1410
+ for (int s=0; s<Phys.allNodes.size(); s++)
1411
+ {
1412
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1413
+ if (node.mass == 0)
1414
+ continue;
1415
+
1416
+ int i = node.springs==null?-1:node.springs.size();
1417
+ gl.glColor3f((i>>2)&1,(i>>1)&1,i&1);
1418
+ //temp.set(node.springForce.x, node.springForce.y, node.springForce.z);
1419
+ //temp.normalize();
1420
+ //gl.glColor3d((temp.x+1)/2, (temp.y+1)/2, (temp.z+1)/2);
1421
+ gl.glBegin(gl.GL_LINES);
1422
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1423
+ //gl.glVertex3d(node.position.x + node.normal.x*scale, node.position.y + node.normal.y*scale, node.position.z + node.normal.z*scale);
1424
+ gl.glVertex3d(node.position.x + mesh.bRep.GetVertex(s).norm.x*scale,
1425
+ node.position.y + mesh.bRep.GetVertex(s).norm.y*scale,
1426
+ node.position.z + mesh.bRep.GetVertex(s).norm.z*scale);
1427
+ gl.glEnd();
1428
+ }
1429
+
1430
+ gl.glLineWidth(8);
1431
+ for (int s=0; s<Phys.allNodes.size(); s++)
1432
+ {
1433
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1434
+
1435
+ if (node.springs != null)
1436
+ {
1437
+ for (int i=0; i<node.springs.size(); i+=1)
1438
+ {
1439
+ cSpring.DynamicNode f = node.springs.get(i).GetOther(node);
1440
+
1441
+ int c = i+1;
1442
+ // c = node.springs.get(i).nbcopies;
1443
+
1444
+ gl.glColor3f((c>>2)&1,(c>>1)&1,c&1);
1445
+ gl.glBegin(gl.GL_LINES);
1446
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1447
+ gl.glVertex3d(f.position.x/3+node.position.x*2/3, f.position.y/3+node.position.y*2/3, f.position.z/3+node.position.z*2/3);
1448
+ gl.glEnd();
1449
+ }
1450
+ }
1451
+ }
1452
+
1453
+ gl.glLineWidth(1);
1454
+ }
1455
+
1456
+ gl.glEnable(gl.GL_LIGHTING);
1457
+ }
1458
+
10641459 /// INTERFACE
1460
+
1461
+ public void StartTriangles()
1462
+ {
1463
+ javax.media.opengl.GL gl = GetGL();
1464
+ gl.glBegin(gl.GL_TRIANGLES);
1465
+ }
1466
+
1467
+ public void EndTriangles()
1468
+ {
1469
+ GetGL().glEnd();
1470
+ }
1471
+
1472
+ void drawVertex(javax.media.opengl.GL gl, Vertex pv, boolean flipV, boolean selectmode)
1473
+ {
1474
+ if (!selectmode)
1475
+ {
1476
+ gl.glNormal3f((float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
1477
+ gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
1478
+
1479
+ if (flipV)
1480
+ gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
1481
+ else
1482
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1483
+ }
1484
+
1485
+ gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
1486
+ }
10651487
10661488 void SetColor(Object3D obj, Vertex p0)
10671489 {
....@@ -1240,7 +1662,7 @@
12401662 // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
12411663 }
12421664
1243
- void DrawMaterial(cMaterial material, boolean selected)
1665
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
12441666 {
12451667 CameraPane display = this;
12461668 //new Exception().printStackTrace();
....@@ -1256,18 +1678,18 @@
12561678 //col.getColorComponents(ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB), CameraPane.modelParams0);
12571679 if (!material.multiply)
12581680 {
1259
- display.color = color;
1681
+ display.color = material.color;
12601682 display.saturation = material.modulation;
12611683 }
12621684 else
12631685 {
1264
- display.color *= color*2;
1686
+ display.color *= material.color*2;
12651687 display.saturation *= material.modulation*2;
12661688 }
12671689
12681690 cColor.HSBtoRGB(display.color, display.saturation, 1, display.modelParams0);
12691691
1270
- float[] colorV = GrafreeD.colorV;
1692
+ float[] colorV = Grafreed.colorV;
12711693
12721694 /**/
12731695 if (display.DrawMode() == display.DEFAULT) // && display.RENDERPROGRAM == 0)
....@@ -1275,7 +1697,7 @@
12751697 colorV[0] = display.modelParams0[0] * material.diffuse;
12761698 colorV[1] = display.modelParams0[1] * material.diffuse;
12771699 colorV[2] = display.modelParams0[2] * material.diffuse;
1278
- colorV[3] = material.opacity;
1700
+ colorV[3] = 1; // material.opacity;
12791701
12801702 gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
12811703 //System.out.println("Opacity = " + opacity);
....@@ -1383,9 +1805,9 @@
13831805 display.modelParams7[2] = 0;
13841806 display.modelParams7[3] = 0;
13851807
1386
- display.modelParams6[0] = 100; // criss de bug de bump
1808
+ //display.modelParams6[0] = 100; // criss de bug de bump
13871809
1388
- Object3D.cVector2[] extparams = display.vector2buffer;
1810
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
13891811 if (extparams != null && extparams.length > 0 && extparams[0] != null)
13901812 {
13911813 display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
....@@ -1527,7 +1949,7 @@
15271949 void PushMatrix(double[][] matrix)
15281950 {
15291951 // GrafreeD.tracein(matrix);
1530
- PushMatrix(matrix,1);
1952
+ PushMatrix(matrix, 1);
15311953 }
15321954
15331955 void PushMatrix()
....@@ -1624,7 +2046,7 @@
16242046
16252047 static int camerachangeframe;
16262048
1627
- boolean SetCamera(Camera cam)
2049
+ public boolean SetCamera(Camera cam)
16282050 {
16292051 // may 2014 if (cam == cameras[0] || cam == cameras[1])
16302052 // return false;
....@@ -1681,7 +2103,7 @@
16812103 //System.err.println("Oeil on");
16822104 OEIL = true;
16832105 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
1684
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2106
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
16852107 //pingthread.StepToTarget(true);
16862108 }
16872109
....@@ -1752,33 +2174,6 @@
17522174 mainDL ^= true;
17532175 }
17542176
1755
- void ToggleTexture()
1756
- {
1757
- textureon ^= true;
1758
- }
1759
-
1760
- void ToggleLive()
1761
- {
1762
- Globals.setLIVE(Globals.isLIVE() ^ true);
1763
-
1764
- System.err.println("LIVE = " + Globals.isLIVE());
1765
-
1766
- if (!Globals.isLIVE()) // save sound
1767
- GrafreeD.savesound = true; // wav.save();
1768
- // else
1769
- repaint(); // start loop // may 2013
1770
- }
1771
-
1772
- void ToggleSupport()
1773
- {
1774
- SUPPORT ^= true;
1775
- }
1776
-
1777
- void ToggleAbort()
1778
- {
1779
- ABORTMODE ^= true;
1780
- }
1781
-
17822177 void ToggleFullScreen()
17832178 {
17842179 FULLSCREEN ^= true;
....@@ -1789,72 +2184,94 @@
17892184 Globals.CROWD ^= true;
17902185 }
17912186
1792
- void ToggleInertia()
1793
- {
1794
- INERTIA ^= true;
1795
- }
1796
-
17972187 void ToggleLocal()
17982188 {
17992189 LOCALTRANSFORM ^= true;
18002190 }
18012191
1802
- void ToggleFast()
2192
+ public void ToggleTexture()
2193
+ {
2194
+ textureon ^= true;
2195
+ }
2196
+
2197
+ public void ToggleLive()
2198
+ {
2199
+ Globals.setLIVE(Globals.isLIVE() ^ true);
2200
+
2201
+ System.err.println("LIVE = " + Globals.isLIVE());
2202
+
2203
+ if (!Globals.isLIVE()) // save sound
2204
+ Grafreed.savesound = true; // wav.save();
2205
+ // else
2206
+ repaint(); // start loop // may 2013
2207
+ }
2208
+
2209
+ public void ToggleSupport()
2210
+ {
2211
+ SUPPORT ^= true;
2212
+ }
2213
+
2214
+ public void ToggleAbort()
2215
+ {
2216
+ ABORTMODE ^= true;
2217
+ }
2218
+
2219
+ public void ToggleInertia()
2220
+ {
2221
+ INERTIA ^= true;
2222
+ }
2223
+
2224
+ public void ToggleFast()
18032225 {
18042226 FAST ^= true;
18052227 }
18062228
1807
- void ToggleSlowPose()
2229
+ public void ToggleSlowPose()
18082230 {
18092231 SLOWPOSE ^= true;
18102232 }
18112233
1812
- void ToggleFootContact()
1813
- {
1814
- FOOTCONTACT ^= true;
1815
- }
1816
-
1817
- void ToggleBoxMode()
2234
+ public void ToggleBoxMode()
18182235 {
18192236 BOXMODE ^= true;
18202237 }
18212238
1822
- void ToggleSmoothFocus()
2239
+ public void ToggleZoomBoxMode()
2240
+ {
2241
+ ZOOMBOXMODE ^= true;
2242
+ }
2243
+
2244
+ public void ToggleSmoothFocus()
18232245 {
18242246 SMOOTHFOCUS ^= true;
18252247 }
18262248
1827
- void ToggleImageFlip()
2249
+ public void ToggleImageFlip()
18282250 {
18292251 IMAGEFLIP ^= true;
18302252 }
18312253
1832
- void ToggleSpeakerMocap()
2254
+ public void ToggleSpeakerMocap()
18332255 {
18342256 SPEAKERMOCAP ^= true;
18352257 }
18362258
1837
- void ToggleSpeakerCamera()
2259
+ public void ToggleSpeakerCamera()
18382260 {
18392261 SPEAKERCAMERA ^= true;
18402262 }
18412263
1842
- void ToggleSpeakerFocus()
2264
+ public void ToggleSpeakerFocus()
18432265 {
18442266 SPEAKERFOCUS ^= true;
18452267 }
18462268
1847
- void ToggleDebug()
1848
- {
1849
- DEBUG ^= true;
1850
- }
1851
-
1852
- void ToggleFrustum()
2269
+ public void ToggleFrustum()
18532270 {
18542271 FRUSTUM ^= true;
18552272 }
18562273
1857
- void ToggleTrack()
2274
+ public void ToggleTrack()
18582275 {
18592276 TRACK ^= true;
18602277 if (TRACK)
....@@ -1873,25 +2290,35 @@
18732290 repaint();
18742291 }
18752292
1876
- void ToggleTrackOnce()
2293
+ public void ToggleTrackOnce()
18772294 {
18782295 TRACKONCE ^= true;
18792296 }
18802297
1881
- void ToggleShadowTrack()
2298
+ public void ToggleShadowTrack()
18822299 {
18832300 SHADOWTRACK ^= true;
18842301 repaint();
18852302 }
18862303
1887
- void ToggleOeil()
2304
+ public void ToggleOeil()
18882305 {
18892306 OEIL ^= true;
18902307 }
18912308
1892
- void ToggleOeilOnce()
2309
+ public void ToggleOeilOnce()
18932310 {
18942311 OEILONCE ^= true;
2312
+ }
2313
+
2314
+ void ToggleFootContact()
2315
+ {
2316
+ FOOTCONTACT ^= true;
2317
+ }
2318
+
2319
+ void ToggleDebug()
2320
+ {
2321
+ Globals.DEBUG ^= true;
18952322 }
18962323
18972324 void ToggleLookAt()
....@@ -1899,9 +2326,9 @@
18992326 LOOKAT ^= true;
19002327 }
19012328
1902
- void ToggleRandom()
2329
+ void ToggleSwitch()
19032330 {
1904
- RANDOM ^= true;
2331
+ SWITCH ^= true;
19052332 }
19062333
19072334 void ToggleHandles()
....@@ -1909,10 +2336,17 @@
19092336 HANDLES ^= true;
19102337 }
19112338
2339
+ Object3D paintFolder;
2340
+
19122341 void TogglePaint()
19132342 {
19142343 PAINTMODE ^= true;
19152344 paintcount = 0;
2345
+
2346
+ if (PAINTMODE)
2347
+ {
2348
+ paintFolder = GetFolder();
2349
+ }
19162350 }
19172351
19182352 void SwapCamera(int a, int b)
....@@ -2008,7 +2442,22 @@
20082442 {
20092443 return currentGL;
20102444 }
2011
-
2445
+
2446
+ static private BufferedImage CreateBim(TextureData texturedata)
2447
+ {
2448
+ Grafreed.Assert(texturedata != null);
2449
+
2450
+ int width = texturedata.getWidth();
2451
+ int height = texturedata.getHeight();
2452
+
2453
+ Buffer buffer = texturedata.getBuffer();
2454
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2455
+
2456
+ byte[] bytes = bytebuf.array();
2457
+
2458
+ return CreateBim(bytes, width, height);
2459
+ }
2460
+
20122461 /**/
20132462 class CacheTexture
20142463 {
....@@ -2017,28 +2466,31 @@
20172466
20182467 int resolution;
20192468
2020
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2469
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
20212470 {
2022
- texture = tex;
2471
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2472
+ texturedata = texdata;
20232473 resolution = res;
20242474 }
20252475 }
20262476 /**/
20272477
20282478 // TEXTURE static Texture texture;
2029
- static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures
2030
- = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>();
2031
- static public java.util.Hashtable<String, String> usedtextures = new java.util.Hashtable<String, String>();
2479
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2480
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2481
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2482
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2483
+
20322484 int pigmentdepth = 0;
20332485 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
20342486 int bumpdepth = 0;
20352487 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
20362488 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
20372489 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2038
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2490
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
20392491 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
20402492
2041
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2493
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
20422494 {
20432495 TextureData texturedata = null;
20442496
....@@ -2057,13 +2509,34 @@
20572509 if (bump)
20582510 texturedata = ConvertBump(texturedata, false);
20592511
2060
- com.sun.opengl.util.texture.Texture texture =
2061
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2512
+// com.sun.opengl.util.texture.Texture texture =
2513
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
20622514
2063
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2064
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
2515
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2516
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
20652517
2066
- return texture;
2518
+ return texturedata;
2519
+ }
2520
+
2521
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2522
+ {
2523
+ TextureData texturedata = null;
2524
+
2525
+ try
2526
+ {
2527
+ texturedata =
2528
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2529
+ bim,
2530
+ true);
2531
+ } catch (Exception e)
2532
+ {
2533
+ throw new javax.media.opengl.GLException(e);
2534
+ }
2535
+
2536
+ if (bump)
2537
+ texturedata = ConvertBump(texturedata, false);
2538
+
2539
+ return texturedata;
20672540 }
20682541
20692542 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3136,6 +3609,8 @@
31363609
31373610 System.out.println("LOADING TEXTURE : " + name);
31383611
3612
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3613
+
31393614 //
31403615 if (false) // compressbit > 0)
31413616 {
....@@ -3840,6 +4315,7 @@
38404315
38414316 com.sun.opengl.util.texture.Texture CompressTexture2(String name)
38424317 {
4318
+ new Exception().printStackTrace();
38434319 System.exit(0);
38444320 com.sun.opengl.util.texture.Texture texture = null;
38454321
....@@ -7533,7 +8009,7 @@
75338009 String pigment = Object3D.GetPigment(tex);
75348010 String bump = Object3D.GetBump(tex);
75358011
7536
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8012
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
75378013 {
75388014 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
75398015 // System.out.println("; bump = " + bump);
....@@ -7548,11 +8024,69 @@
75488024 pigment = null;
75498025 }
75508026
7551
- ReleaseTexture(bump, true);
7552
- ReleaseTexture(pigment, false);
8027
+ ReleaseTexture(tex, true);
8028
+ ReleaseTexture(tex, false);
75538029 }
75548030
7555
- void ReleaseTexture(String tex, boolean bump)
8031
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
8032
+ {
8033
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8034
+ {
8035
+ return;
8036
+ }
8037
+
8038
+ if (tex == null)
8039
+ {
8040
+ ReleaseTexture(null, false);
8041
+ return;
8042
+ }
8043
+
8044
+ String pigment = Object3D.GetPigment(tex);
8045
+
8046
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8047
+ {
8048
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8049
+ // System.out.println("; bump = " + bump);
8050
+ }
8051
+
8052
+ if (pigment.equals(""))
8053
+ {
8054
+ pigment = null;
8055
+ }
8056
+
8057
+ ReleaseTexture(tex, false);
8058
+ }
8059
+
8060
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
8061
+ {
8062
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8063
+ {
8064
+ return;
8065
+ }
8066
+
8067
+ if (tex == null)
8068
+ {
8069
+ ReleaseTexture(null, true);
8070
+ return;
8071
+ }
8072
+
8073
+ String bump = Object3D.GetBump(tex);
8074
+
8075
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8076
+ {
8077
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8078
+ // System.out.println("; bump = " + bump);
8079
+ }
8080
+
8081
+ if (bump.equals(""))
8082
+ {
8083
+ bump = null;
8084
+ }
8085
+
8086
+ ReleaseTexture(tex, true);
8087
+ }
8088
+
8089
+ void ReleaseTexture(cTexture tex, boolean bump)
75568090 {
75578091 if (// DrawMode() != 0 || /*tex == null ||*/
75588092 ambientOcclusion ) // || !textureon)
....@@ -7563,7 +8097,7 @@
75638097 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
75648098
75658099 if (tex != null)
7566
- texture = textures.get(tex);
8100
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
75678101
75688102 // //assert( texture != null );
75698103 // if (texture == null)
....@@ -7655,7 +8189,55 @@
76558189 }
76568190 }
76578191
7658
- /*boolean*/ public void BindTextures(cTexture tex, int resolution) // INTERFACE
8192
+ /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
8193
+ {
8194
+// if (// DrawMode() != 0 || /*tex == null ||*/
8195
+// ambientOcclusion ) // || !textureon)
8196
+// {
8197
+// return; // false;
8198
+// }
8199
+//
8200
+// if (tex == null)
8201
+// {
8202
+// BindTexture(null,false,resolution);
8203
+// BindTexture(null,true,resolution);
8204
+// return;
8205
+// }
8206
+//
8207
+// String pigment = Object3D.GetPigment(tex);
8208
+// String bump = Object3D.GetBump(tex);
8209
+//
8210
+// usedtextures.add(pigment);
8211
+// usedtextures.add(bump);
8212
+//
8213
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8214
+// {
8215
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8216
+// // System.out.println("; bump = " + bump);
8217
+// }
8218
+//
8219
+// if (bump.equals(""))
8220
+// {
8221
+// bump = null;
8222
+// }
8223
+// if (pigment.equals(""))
8224
+// {
8225
+// pigment = null;
8226
+// }
8227
+//
8228
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8229
+// BindTexture(pigment, false, resolution);
8230
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8231
+// BindTexture(bump, true, resolution);
8232
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8233
+//
8234
+// return; // true;
8235
+
8236
+ BindPigmentTexture(tex, resolution);
8237
+ BindBumpTexture(tex, resolution);
8238
+ }
8239
+
8240
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
76598241 {
76608242 if (// DrawMode() != 0 || /*tex == null ||*/
76618243 ambientOcclusion ) // || !textureon)
....@@ -7666,17 +8248,47 @@
76668248 if (tex == null)
76678249 {
76688250 BindTexture(null,false,resolution);
7669
- BindTexture(null,true,resolution);
76708251 return;
76718252 }
76728253
76738254 String pigment = Object3D.GetPigment(tex);
8255
+
8256
+ usedtextures.add(tex);
8257
+
8258
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8259
+ {
8260
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8261
+ // System.out.println("; bump = " + bump);
8262
+ }
8263
+
8264
+ if (pigment.equals(""))
8265
+ {
8266
+ pigment = null;
8267
+ }
8268
+
8269
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8270
+ BindTexture(tex, false, resolution);
8271
+ }
8272
+
8273
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8274
+ {
8275
+ if (// DrawMode() != 0 || /*tex == null ||*/
8276
+ ambientOcclusion ) // || !textureon)
8277
+ {
8278
+ return; // false;
8279
+ }
8280
+
8281
+ if (tex == null)
8282
+ {
8283
+ BindTexture(null,true,resolution);
8284
+ return;
8285
+ }
8286
+
76748287 String bump = Object3D.GetBump(tex);
76758288
7676
- usedtextures.put(pigment, pigment);
7677
- usedtextures.put(bump, bump);
8289
+ usedtextures.add(tex);
76788290
7679
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8291
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
76808292 {
76818293 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
76828294 // System.out.println("; bump = " + bump);
....@@ -7686,43 +8298,94 @@
76868298 {
76878299 bump = null;
76888300 }
7689
- if (pigment.equals(""))
7690
- {
7691
- pigment = null;
7692
- }
76938301
7694
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
7695
- BindTexture(pigment, false, resolution);
76968302 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
7697
- BindTexture(bump, true, resolution);
8303
+ BindTexture(tex, true, resolution);
76988304 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
7699
-
7700
- return; // true;
77018305 }
77028306
7703
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution)
8307
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8308
+
8309
+ private boolean FileExists(String tex)
77048310 {
7705
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8311
+ if (missingTextures.contains(tex))
8312
+ {
8313
+ return false;
8314
+ }
8315
+
8316
+ boolean fileExists = new File(tex).exists();
8317
+
8318
+ if (!fileExists)
8319
+ {
8320
+ // If file exists, the "new File()" is not executed sgain
8321
+ missingTextures.add(tex);
8322
+ }
8323
+
8324
+ return fileExists;
8325
+ }
8326
+
8327
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
8328
+ {
8329
+ CacheTexture texturecache = null;
77068330
77078331 if (tex != null)
77088332 {
7709
- String texname = tex;
8333
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8334
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
77108335
7711
- String[] split = tex.split("Textures");
7712
- if (split.length > 1)
7713
- texname = "/Users/nbriere/Textures" + split[split.length-1];
7714
- else
7715
- if (!texname.startsWith("/"))
7716
- texname = "/Users/nbriere/Textures/" + texname;
8336
+ if (texname.equals("") && texdata == null)
8337
+ {
8338
+ return null;
8339
+ }
8340
+
8341
+ String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
8342
+
8343
+// String[] split = tex.split("Textures");
8344
+// if (split.length > 1)
8345
+// texname = "/Users/nbriere/Textures" + split[split.length-1];
8346
+// else
8347
+// if (!texname.startsWith("/"))
8348
+// texname = "/Users/nbriere/Textures/" + texname;
8349
+ if (!FileExists(texname))
8350
+ {
8351
+ texname = fallbackTextureName;
8352
+ }
77178353
77188354 if (CACHETEXTURE)
7719
- texture = textures.get(texname); // TEXTURE CACHE
7720
-
7721
- TextureData texturedata = null;
7722
-
7723
- if (texture == null || texture.resolution < resolution)
77248355 {
7725
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8356
+ if (texdata == null)
8357
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8358
+ else
8359
+ texturecache = bimtextures.get(texdata);
8360
+ }
8361
+
8362
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8363
+ {
8364
+ TextureData texturedata = null;
8365
+
8366
+ if (texdata != null && textureon)
8367
+ {
8368
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8369
+
8370
+ try
8371
+ {
8372
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8373
+ }
8374
+ catch (Exception e)
8375
+ {
8376
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8377
+ }
8378
+
8379
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8380
+ bimtextures.put(texdata, texturecache);
8381
+
8382
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8383
+
8384
+ //Object bim2 = CreateBim(texturecache.texturedata);
8385
+ //bim2 = bim;
8386
+ }
8387
+ else
8388
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
77268389 {
77278390 assert(!bump);
77288391 // if (bump)
....@@ -7733,19 +8396,23 @@
77338396 // }
77348397 // else
77358398 // {
7736
- texture = textures.get(tex);
7737
- if (texture == null)
8399
+ // texturecache = textures.get(texname); // suspicious
8400
+ if (texturecache == null)
77388401 {
7739
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8402
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
77408403 }
8404
+ else
8405
+ new Exception().printStackTrace();
77418406 // }
77428407 } else
7743
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8408
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
77448409 {
77458410 assert(bump);
7746
- texture = textures.get(tex);
7747
- if (texture == null)
7748
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8411
+ // texturecache = textures.get(texname); // suspicious
8412
+ if (texturecache == null)
8413
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8414
+ else
8415
+ new Exception().printStackTrace();
77498416 } else
77508417 {
77518418 //if (tex.equals("IMMORTAL"))
....@@ -7753,11 +8420,13 @@
77538420 // texture = GetResourceTexture("default.png");
77548421 //} else
77558422 //{
7756
- if (tex.equals("WHITE_NOISE"))
8423
+ if (texname.endsWith("WHITE_NOISE"))
77578424 {
7758
- texture = textures.get(tex);
7759
- if (texture == null)
7760
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8425
+ // texturecache = textures.get(texname); // suspicious
8426
+ if (texturecache == null)
8427
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8428
+ else
8429
+ new Exception().printStackTrace();
77618430 } else
77628431 {
77638432 if (textureon)
....@@ -7782,7 +8451,7 @@
77828451 }
77838452
77848453 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
7785
- if (!new File(cachename).exists())
8454
+ if (!FileExists(cachename))
77868455 cachename = texname;
77878456 else
77888457 processbump = false; // don't process bump map again
....@@ -7804,7 +8473,7 @@
78048473 }
78058474
78068475 cachename = texname.substring(0, texname.length()-4)+ext+".png";
7807
- if (!new File(cachename).exists())
8476
+ if (!FileExists(cachename))
78088477 cachename = texname;
78098478 else
78108479 processbump = false; // don't process bump map again
....@@ -7813,20 +8482,22 @@
78138482 texturedata = GetFileTexture(cachename, processbump, resolution);
78148483
78158484
7816
- if (texturedata != null)
7817
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8485
+ if (texturedata == null)
8486
+ throw new Exception();
8487
+
8488
+ texturecache = new CacheTexture(texturedata,resolution);
78188489 //texture = GetTexture(tex, bump);
78198490 }
78208491 }
78218492 //}
78228493 }
78238494
7824
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8495
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
78258496 {
78268497 //return false;
78278498
78288499 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
7829
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8500
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
78308501 {
78318502 // String ext = "_highres";
78328503 // if (REDUCETEXTURE)
....@@ -7843,52 +8514,17 @@
78438514 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
78448515 if (!cachefile.exists())
78458516 {
7846
- // cache to disk
7847
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
7848
- //buffers[0].
7849
-
7850
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
7851
- int[] pixels = new int[bytebuf.capacity()/3];
7852
-
7853
- // squared size heuristic...
7854
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8517
+ //if (texturedata.getWidth() == texturedata.getHeight())
78558518 {
7856
- for (int i=pixels.length; --i>=0;)
7857
- {
7858
- int i3 = i*3;
7859
- pixels[i] = 0xFF;
7860
- pixels[i] <<= 8;
7861
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
7862
- pixels[i] <<= 8;
7863
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
7864
- pixels[i] <<= 8;
7865
- pixels[i] |= bytebuf.get(i3) & 0xFF;
7866
- }
7867
-
7868
- /*
7869
- int r=0,g=0,b=0,a=0;
7870
- for (int i=0; i<width; i++)
7871
- for (int j=0; j<height; j++)
7872
- {
7873
- int index = j*width+i;
7874
- int p = pixels[index];
7875
- a = ((p>>24) & 0xFF);
7876
- r = ((p>>16) & 0xFF);
7877
- g = ((p>>8) & 0xFF);
7878
- b = (p & 0xFF);
7879
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
7880
- }
7881
- /**/
7882
- int width = (int)Math.sqrt(pixels.length); // squared
7883
- int height = width;
7884
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
7885
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8519
+ BufferedImage rendImage = CreateBim(texturedata);
8520
+
78868521 ImageWriter writer = null;
78878522 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
78888523 if (iter.hasNext()) {
78898524 writer = (ImageWriter)iter.next();
78908525 }
7891
- float compressionQuality = 0.9f;
8526
+
8527
+ float compressionQuality = 0.85f;
78928528 try
78938529 {
78948530 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -7905,18 +8541,20 @@
79058541 }
79068542 }
79078543 }
7908
-
8544
+
8545
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8546
+
79098547 //System.out.println("Texture = " + tex);
7910
- if (textures.containsKey(texname))
8548
+ if (textures.containsKey(tex))
79118549 {
7912
- CacheTexture thetex = textures.get(texname);
8550
+ CacheTexture thetex = textures.get(tex);
79138551 thetex.texture.disable();
79148552 thetex.texture.dispose();
7915
- textures.remove(texname);
8553
+ textures.remove(tex);
79168554 }
79178555
7918
- texture.texturedata = texturedata;
7919
- textures.put(texname, texture);
8556
+ //texture.texturedata = texturedata;
8557
+ textures.put(tex, texturecache);
79208558
79218559 // newtex = true;
79228560 }
....@@ -7932,10 +8570,44 @@
79328570 }
79338571 }
79348572
7935
- return texture;
8573
+ return texturecache;
79368574 }
79378575
7938
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution)
8576
+ static void EmbedTextures(cTexture tex)
8577
+ {
8578
+ if (tex.pigmentdata == null)
8579
+ {
8580
+ //String texname = Object3D.GetPigment(tex);
8581
+
8582
+ CacheTexture texturecache = texturepigment.get(tex);
8583
+
8584
+ if (texturecache != null)
8585
+ {
8586
+ tex.pw = texturecache.texturedata.getWidth();
8587
+ tex.ph = texturecache.texturedata.getHeight();
8588
+ tex.pigmentdata = //CompressJPEG(CreateBim
8589
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8590
+ ;
8591
+ //, tex.pw, tex.ph), 0.5f);
8592
+ }
8593
+ }
8594
+
8595
+ if (tex.bumpdata == null)
8596
+ {
8597
+ //String texname = Object3D.GetBump(tex);
8598
+
8599
+ CacheTexture texturecache = texturebump.get(tex);
8600
+
8601
+ if (texturecache != null)
8602
+ {
8603
+ tex.bw = texturecache.texturedata.getWidth();
8604
+ tex.bh = texturecache.texturedata.getHeight();
8605
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8606
+ }
8607
+ }
8608
+ }
8609
+
8610
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
79398611 {
79408612 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
79418613
....@@ -7953,21 +8625,21 @@
79538625 return texture!=null?texture.texture:null;
79548626 }
79558627
7956
- com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution)
8628
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
79578629 {
79588630 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
79598631
79608632 return texture!=null?texture.texturedata:null;
79618633 }
79628634
7963
- boolean BindTexture(String tex, boolean bump, int resolution)
8635
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
79648636 {
79658637 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
79668638 {
79678639 return false;
79688640 }
79698641
7970
- boolean newtex = false;
8642
+ //boolean newtex = false;
79718643
79728644 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
79738645
....@@ -7999,9 +8671,75 @@
79998671 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
80008672 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
80018673
8002
- return newtex;
8674
+ return true; // Warning: not used.
80038675 }
80048676
8677
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8678
+ {
8679
+ try
8680
+ {
8681
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8682
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8683
+ ImageWriter writer = writers.next();
8684
+
8685
+ ImageWriteParam param = writer.getDefaultWriteParam();
8686
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8687
+ param.setCompressionQuality(quality);
8688
+
8689
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8690
+ writer.setOutput(ios);
8691
+ writer.write(null, new IIOImage(image, null, null), param);
8692
+
8693
+ byte[] data = baos.toByteArray();
8694
+ writer.dispose();
8695
+ return data;
8696
+ }
8697
+ catch (Exception e)
8698
+ {
8699
+ e.printStackTrace();
8700
+ return null;
8701
+ }
8702
+ }
8703
+
8704
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8705
+ {
8706
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8707
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8708
+ ImageReader reader = writers.next();
8709
+
8710
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8711
+
8712
+ ImageReadParam param = reader.getDefaultReadParam();
8713
+ param.setDestination(bim);
8714
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8715
+
8716
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8717
+ reader.setInput(ios);
8718
+ BufferedImage bim2 = reader.read(0, param);
8719
+ reader.dispose();
8720
+
8721
+// WritableRaster raster = bim2.getRaster();
8722
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8723
+// byte[] bytes = data.getData();
8724
+//
8725
+// int[] pixels = new int[bytes.length/3];
8726
+// for (int i=pixels.length; --i>=0;)
8727
+// {
8728
+// int i3 = i*3;
8729
+// pixels[i] = 0xFF;
8730
+// pixels[i] <<= 8;
8731
+// pixels[i] |= bytes[i3+2] & 0xFF;
8732
+// pixels[i] <<= 8;
8733
+// pixels[i] |= bytes[i3+1] & 0xFF;
8734
+// pixels[i] <<= 8;
8735
+// pixels[i] |= bytes[i3] & 0xFF;
8736
+// }
8737
+//
8738
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8739
+
8740
+ return bim;
8741
+ }
8742
+
80058743 ShadowBuffer shadowPBuf;
80068744 AntialiasBuffer antialiasPBuf;
80078745 int MAXSTACK;
....@@ -8837,11 +9575,35 @@
88379575 jy8[3] = 0.5f;
88389576 }
88399577
8840
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9578
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
88419579 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
88429580 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
88439581 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
88449582
9583
+ void ResetOptions()
9584
+ {
9585
+ options1[0] = 100;
9586
+ options1[1] = 0.025f;
9587
+ options1[2] = 0.01f;
9588
+ options1[3] = 0;
9589
+ options1[4] = 0;
9590
+
9591
+ options2[0] = 0;
9592
+ options2[1] = 0.75f;
9593
+ options2[2] = 0;
9594
+ options2[3] = 0;
9595
+
9596
+ options3[0] = 1;
9597
+ options3[1] = 1;
9598
+ options3[2] = 1;
9599
+ options3[3] = 0;
9600
+
9601
+ options4[0] = 1;
9602
+ options4[1] = 0;
9603
+ options4[2] = 1;
9604
+ options4[3] = 0;
9605
+ }
9606
+
88459607 static int imagecount = 0; // movie generation
88469608
88479609 static int jitter = 0;
....@@ -8937,8 +9699,8 @@
89379699 assert (parentcam != renderCamera);
89389700
89399701 if (renderCamera != lightCamera)
8940
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8941
- LA.matConcat(matrix, parentcam.toParent, matrix);
9702
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9703
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
89429704
89439705 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
89449706
....@@ -8953,8 +9715,8 @@
89539715 LA.matCopy(renderCamera.fromScreen, matrix);
89549716
89559717 if (renderCamera != lightCamera)
8956
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8957
- LA.matConcat(parentcam.fromParent, matrix, matrix);
9718
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9719
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
89589720
89599721 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
89609722
....@@ -9026,7 +9788,7 @@
90269788 //gl.glFlush();
90279789 gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE);
90289790
9029
- if (ANIMATION && ABORTED)
9791
+ if (Globals.ANIMATION && ABORTED)
90309792 {
90319793 System.err.println(" ABORTED FRAME");
90329794 break;
....@@ -9056,7 +9818,7 @@
90569818 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
90579819
90589820 // save image
9059
- if (ANIMATION && !ABORTED)
9821
+ if (Globals.ANIMATION && !ABORTED)
90609822 {
90619823 VPwidth = viewport[2];
90629824 VPheight = viewport[3];
....@@ -9167,11 +9929,11 @@
91679929
91689930 // imagecount++;
91699931
9170
- String fullname = filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
9932
+ String fullname = Globals.filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
91719933
91729934 if (!BOXMODE)
91739935 {
9174
- System.out.println("image: " + fullname + " (wav cursor=" + (GrafreeD.wav.cursor / 735 / 4) + ")");
9936
+ System.out.println("image: " + fullname + " (wav cursor=" + (Grafreed.wav.cursor / 735 / 4) + ")");
91759937 }
91769938
91779939 if (!BOXMODE)
....@@ -9209,7 +9971,7 @@
92099971 ABORTED = false;
92109972 }
92119973 else
9212
- GrafreeD.wav.cursor += 735 * ACSIZE;
9974
+ Grafreed.wav.cursor += 735 * ACSIZE;
92139975
92149976 if (false)
92159977 {
....@@ -9872,11 +10634,11 @@
987210634
987310635 public void display(GLAutoDrawable drawable)
987410636 {
9875
- if (GrafreeD.savesound && GrafreeD.hassound)
10637
+ if (Grafreed.savesound && Grafreed.hassound)
987610638 {
9877
- GrafreeD.wav.save();
9878
- GrafreeD.savesound = false;
9879
- GrafreeD.hassound = false;
10639
+ Grafreed.wav.save();
10640
+ Grafreed.savesound = false;
10641
+ Grafreed.hassound = false;
988010642 }
988110643 // if (DEBUG_SELECTION)
988210644 // {
....@@ -9952,6 +10714,7 @@
995210714 ANTIALIAS = 0;
995310715 //System.out.println("RESTART");
995410716 AAtimer.restart();
10717
+ Globals.TIMERRUNNING = true;
995510718 }
995610719 }
995710720 }
....@@ -10006,7 +10769,7 @@
1000610769 Object3D theobject = object;
1000710770 Object3D theparent = object.parent;
1000810771 object.parent = null;
10009
- object = (Object3D)GrafreeD.clone(object);
10772
+ object = (Object3D)Grafreed.clone(object);
1001010773 object.Stripify();
1001110774 if (theobject.selection == null || theobject.selection.Size() == 0)
1001210775 theobject.PreprocessOcclusion(this);
....@@ -10019,13 +10782,14 @@
1001910782 ambientOcclusion = false;
1002010783 }
1002110784
10022
- if (Globals.lighttouched && DrawMode() == DEFAULT && !lightMode) // && !FROZEN)
10785
+ if (//Globals.lighttouched &&
10786
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1002310787 {
1002410788 //if (RENDERSHADOW) // ?
1002510789 if (!IsFrozen())
1002610790 {
1002710791 // dec 2012
10028
- if (!ambientOcclusion && !(!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0))
10792
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
1002910793 {
1003010794 Globals.framecount++;
1003110795 shadowbuffer.display();
....@@ -10152,8 +10916,8 @@
1015210916
1015310917 // if (parentcam != renderCamera) // not a light
1015410918 if (cam != lightCamera)
10155
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10156
- LA.matConcat(matrix, parentcam.toParent, matrix);
10919
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10920
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1015710921
1015810922 for (int j = 0; j < 4; j++)
1015910923 {
....@@ -10167,8 +10931,8 @@
1016710931
1016810932 // if (parentcam != renderCamera) // not a light
1016910933 if (cam != lightCamera)
10170
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10171
- LA.matConcat(parentcam.fromParent, matrix, matrix);
10934
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10935
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1017210936
1017310937 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1017410938
....@@ -10427,7 +11191,16 @@
1042711191 // Bump noise
1042811192 gl.glActiveTexture(GL.GL_TEXTURE6);
1042911193 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
10430
- BindTexture(NOISE_TEXTURE, false, 2);
11194
+
11195
+ try
11196
+ {
11197
+ BindTexture(NOISE_TEXTURE, false, 2);
11198
+ }
11199
+ catch (Exception e)
11200
+ {
11201
+ System.err.println("FAILED: " + NOISE_TEXTURE);
11202
+ }
11203
+
1043111204
1043211205 gl.glActiveTexture(GL.GL_TEXTURE0);
1043311206 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -10450,9 +11223,9 @@
1045011223
1045111224 gl.glMatrixMode(GL.GL_MODELVIEW);
1045211225
10453
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10454
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10455
-//gl.glEnable(gl.GL_MULTISAMPLE);
11226
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11227
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11228
+gl.glEnable(gl.GL_MULTISAMPLE);
1045611229 } else
1045711230 {
1045811231 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -10463,7 +11236,7 @@
1046311236 //System.out.println("BLENDING ON");
1046411237 gl.glEnable(GL.GL_BLEND);
1046511238 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
10466
-
11239
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1046711240 gl.glMatrixMode(gl.GL_PROJECTION);
1046811241 gl.glLoadIdentity();
1046911242
....@@ -10552,8 +11325,8 @@
1055211325 System.err.println("parentcam != renderCamera");
1055311326
1055411327 // if (cam != lightCamera)
10555
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10556
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11328
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11329
+ LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
1055711330 }
1055811331
1055911332 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -10574,8 +11347,8 @@
1057411347 if (true) // TODO
1057511348 {
1057611349 if (cam != lightCamera)
10577
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10578
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11350
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11351
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
1057911352 }
1058011353
1058111354 LA.xformPos(light0, cam.toScreen, light0);
....@@ -10712,7 +11485,7 @@
1071211485 }
1071311486 }
1071411487
10715
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11488
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1071611489 {
1071711490 //gl.glDepthFunc(GL.GL_LEQUAL);
1071811491 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -10720,24 +11493,21 @@
1072011493
1072111494 boolean texon = textureon;
1072211495
10723
- if (RENDERPROGRAM > 0)
10724
- {
10725
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
10726
- textureon = false;
10727
- }
11496
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11497
+ textureon = false;
11498
+
1072811499 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1072911500 //System.out.println("ALLO");
1073011501 gl.glColorMask(false, false, false, false);
1073111502 DrawObject(gl);
10732
- if (RENDERPROGRAM > 0)
10733
- {
10734
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
10735
- textureon = texon;
10736
- }
11503
+
11504
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11505
+ textureon = texon;
11506
+
1073711507 gl.glColorMask(true, true, true, true);
1073811508
1073911509 gl.glDepthFunc(GL.GL_EQUAL);
10740
- //gl.glDepthMask(false);
11510
+ gl.glDepthMask(false);
1074111511 }
1074211512
1074311513 if (false) // DrawMode() == SHADOW)
....@@ -10891,8 +11661,14 @@
1089111661 {
1089211662 renderpass++;
1089311663 // System.out.println("Draw object... ");
11664
+ STEP = 1;
1089411665 if (FAST) // in case there is no script
10895
- STEP = 16;
11666
+ STEP = 8;
11667
+
11668
+ if (CURRENTANTIALIAS == 0 || ACSIZE == 1)
11669
+ {
11670
+ STEP *= 4;
11671
+ }
1089611672
1089711673 //object.FullInvariants();
1089811674
....@@ -10906,23 +11682,44 @@
1090611682 e.printStackTrace();
1090711683 }
1090811684
10909
- if (GrafreeD.RENDERME > 0)
10910
- GrafreeD.RENDERME--; // mechante magouille
11685
+ if (Grafreed.RENDERME > 0)
11686
+ Grafreed.RENDERME--; // mechante magouille
1091111687
1091211688 Globals.ONESTEP = false;
1091311689 }
1091411690
1091511691 static boolean zoomonce = false;
1091611692
11693
+ static void CreateSelectedPoint()
11694
+ {
11695
+ if (selectedpoint == null)
11696
+ {
11697
+ debugpointG = new Sphere();
11698
+ debugpointP = new Sphere();
11699
+ debugpointC = new Sphere();
11700
+ debugpointR = new Sphere();
11701
+
11702
+ selectedpoint = new Superellipsoid();
11703
+
11704
+ for (int i=0; i<8; i++)
11705
+ {
11706
+ debugpoints[i] = new Sphere();
11707
+ }
11708
+ }
11709
+ }
11710
+
1091711711 void DrawObject(GL gl, boolean draw)
1091811712 {
11713
+ // To clear camera values
11714
+ ResetOptions();
11715
+
1091911716 //System.out.println("DRAW OBJECT " + mouseDown);
1092011717 // DrawMode() = SELECTION;
1092111718 //GL gl = getGL();
1092211719 if ((TRACK || SHADOWTRACK) || zoomonce)
1092311720 {
1092411721 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
10925
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11722
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1092611723 pingthread.StepToTarget(true); // true);
1092711724 // zoomonce = false;
1092811725 }
....@@ -10977,7 +11774,14 @@
1097711774
1097811775 usedtextures.clear();
1097911776
10980
- BindTextures(DEFAULT_TEXTURES, 2);
11777
+ try
11778
+ {
11779
+ BindTextures(DEFAULT_TEXTURES, 2);
11780
+ }
11781
+ catch (Exception e)
11782
+ {
11783
+ System.err.println("FAILED: " + DEFAULT_TEXTURES);
11784
+ }
1098111785 }
1098211786 //System.out.println("--> " + stackdepth);
1098311787 // GrafreeD.traceon();
....@@ -10987,8 +11791,9 @@
1098711791
1098811792 if (DrawMode() == DEFAULT)
1098911793 {
10990
- if (DEBUG)
11794
+ if (Globals.DEBUG)
1099111795 {
11796
+ CreateSelectedPoint();
1099211797 float radius = 0.05f;
1099311798 if (selectedpoint.radius != radius)
1099411799 {
....@@ -11042,20 +11847,32 @@
1104211847 ReleaseTextures(DEFAULT_TEXTURES);
1104311848
1104411849 if (CLEANCACHE)
11045
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11850
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1104611851 {
11047
- String tex = e.nextElement();
11852
+ cTexture tex = e.nextElement();
1104811853
1104911854 // System.out.println("Texture --------- " + tex);
1105011855
11051
- if (tex.equals("WHITE_NOISE"))
11856
+ if (tex.equals("WHITE_NOISE:"))
1105211857 continue;
1105311858
11054
- if (!usedtextures.containsKey(tex))
11859
+ if (!usedtextures.contains(tex))
1105511860 {
11861
+ CacheTexture gettex = texturepigment.get(tex);
1105611862 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11057
- textures.get(tex).texture.dispose();
11058
- textures.remove(tex);
11863
+ if (gettex != null)
11864
+ {
11865
+ gettex.texture.dispose();
11866
+ texturepigment.remove(tex);
11867
+ }
11868
+
11869
+ gettex = texturebump.get(tex);
11870
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11871
+ if (gettex != null)
11872
+ {
11873
+ gettex.texture.dispose();
11874
+ texturebump.remove(tex);
11875
+ }
1105911876 }
1106011877 }
1106111878 }
....@@ -11068,7 +11885,14 @@
1106811885 if (checker != null && DrawMode() == DEFAULT)
1106911886 {
1107011887 //BindTexture(IMMORTAL_TEXTURE);
11071
- BindTextures(checker.GetTextures(), checker.texres);
11888
+ try
11889
+ {
11890
+ BindTextures(checker.GetTextures(), checker.texres);
11891
+ }
11892
+ catch (Exception e)
11893
+ {
11894
+ System.err.println("FAILED: " + checker.GetTextures());
11895
+ }
1107211896 // NEAREST
1107311897 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
1107411898 DrawChecker(gl);
....@@ -11150,7 +11974,7 @@
1115011974 return;
1115111975 }
1115211976
11153
- String string = obj.GetToolTip();
11977
+ String string = obj.toString(); //.GetToolTip();
1115411978
1115511979 GL gl = GetGL();
1115611980
....@@ -11467,8 +12291,8 @@
1146712291 //obj.TransformToWorld(light, light);
1146812292 for (int i = tp.size(); --i >= 0;)
1146912293 {
11470
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
11471
- LA.xformPos(light, tp.get(i).toParent, light);
12294
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12295
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1147212296 }
1147312297
1147412298
....@@ -11485,8 +12309,8 @@
1148512309 parentcam = cameras[0];
1148612310 }
1148712311
11488
- for (int count = parentcam.GetTransformCount(); --count>=0;)
11489
- LA.xformPos(light, parentcam.toParent, light); // may 2013
12312
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
12313
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1149012314
1149112315 LA.xformPos(light, renderCamera.toScreen, light);
1149212316
....@@ -11577,7 +12401,74 @@
1157712401 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1157812402
1157912403 String program =
12404
+ // Min shader
1158012405 "!!ARBfp1.0\n" +
12406
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12407
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12408
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12409
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12410
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12411
+ "PARAM light2cam0 = program.env[10];" +
12412
+ "PARAM light2cam1 = program.env[11];" +
12413
+ "PARAM light2cam2 = program.env[12];" +
12414
+ "TEMP temp;" +
12415
+ "TEMP light;" +
12416
+ "TEMP ndotl;" +
12417
+ "TEMP normal;" +
12418
+ "TEMP depth;" +
12419
+ "TEMP eye;" +
12420
+ "TEMP pos;" +
12421
+
12422
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12423
+ Normalize("normal") +
12424
+ "MOV light, state.light[0].position;" +
12425
+ "DP3 ndotl.x, light, normal;" +
12426
+
12427
+ // shadow
12428
+ "MOV pos, fragment.texcoord[1];" +
12429
+ "MOV temp, pos;" +
12430
+ ShadowTextureFetch("depth", "temp", "1") +
12431
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12432
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12433
+
12434
+ // No shadow when out of frustum
12435
+ //"SGE temp.y, depth.z, zero123.y;" +
12436
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12437
+
12438
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12439
+
12440
+ // Backlit
12441
+ "MOV pos.w, zero123.y;" +
12442
+ "DP4 eye.x, pos, light2cam0;" +
12443
+ "DP4 eye.y, pos, light2cam1;" +
12444
+ "DP4 eye.z, pos, light2cam2;" +
12445
+ Normalize("eye") +
12446
+
12447
+ "DP3 ndotl.y, -eye, normal;" +
12448
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12449
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12450
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12451
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12452
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12453
+
12454
+ "MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12455
+
12456
+ // Pigment
12457
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12458
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12459
+ "MUL temp, temp, ndotl.x;" +
12460
+
12461
+ "MUL temp, temp, zero123.z;" +
12462
+
12463
+ //"MUL temp, temp, ndotl.y;" +
12464
+
12465
+ "MOV temp.w, zero123.y;" + // reset alpha
12466
+ "MOV result.color, temp;" +
12467
+ "END";
12468
+
12469
+ String program2 =
12470
+ "!!ARBfp1.0\n" +
12471
+
1158112472 //"OPTION ARB_fragment_program_shadow;" +
1158212473 "PARAM light2cam0 = program.env[10];" +
1158312474 "PARAM light2cam1 = program.env[11];" +
....@@ -11692,8 +12583,7 @@
1169212583 "TEMP shininess;" +
1169312584 "\n" +
1169412585 "MOV texSamp, one;" +
11695
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
11696
-
12586
+
1169712587 "MOV mapgrid.x, one2048th.x;" +
1169812588 "MOV temp, fragment.texcoord[1];" +
1169912589 /*
....@@ -11714,20 +12604,20 @@
1171412604 "MUL temp, floor, mapgrid.x;" +
1171512605 //"TEX depth0, temp, texture[1], 2D;" +
1171612606 (((mode & FP_SOFTSHADOW) == 0) ? "" :
11717
- TextureFetch("depth0", "temp", "1") +
12607
+ ShadowTextureFetch("depth0", "temp", "1") +
1171812608 "") +
1171912609 "ADD temp.x, temp.x, mapgrid.x;" +
1172012610 //"TEX depth1, temp, texture[1], 2D;" +
1172112611 (((mode & FP_SOFTSHADOW) == 0) ? "" :
11722
- TextureFetch("depth1", "temp", "1") +
12612
+ ShadowTextureFetch("depth1", "temp", "1") +
1172312613 "") +
1172412614 "ADD temp.y, temp.y, mapgrid.x;" +
1172512615 //"TEX depth2, temp, texture[1], 2D;" +
11726
- TextureFetch("depth2", "temp", "1") +
12616
+ ShadowTextureFetch("depth2", "temp", "1") +
1172712617 "SUB temp.x, temp.x, mapgrid.x;" +
1172812618 //"TEX depth3, temp, texture[1], 2D;" +
1172912619 (((mode & FP_SOFTSHADOW) == 0) ? "" :
11730
- TextureFetch("depth3", "temp", "1") +
12620
+ ShadowTextureFetch("depth3", "temp", "1") +
1173112621 "") +
1173212622 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1173312623 //"MOV params, material;" +
....@@ -12098,10 +12988,10 @@
1209812988 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1209912989 "") +
1210012990
12101
- // display shadow only (bump == 0)
12991
+ // display shadow only (fakedepth == 0)
1210212992 "SUB temp.x, half.x, shadow.x;" +
12103
- "MOV temp.y, -params6.x;" +
12104
- "SLT temp.z, temp.y, zero.x;" +
12993
+ "MOV temp.y, -params5.z;" + // params6.x;" +
12994
+ "SLT temp.z, temp.y, -one2048th.x;" +
1210512995 "SUB temp.y, one.x, temp.z;" +
1210612996 "MUL temp.x, temp.x, temp.y;" +
1210712997 "KIL temp.x;" +
....@@ -12230,8 +13120,10 @@
1223013120 "MAX ndotl.x, ndotl.x, -ndotl.x;" +
1223113121
1223213122 "SUB temp.x, one.x, ndotl.x;" +
12233
- "ADD temp.x, temp.x, options2.z;" + // lightsheen
12234
- "ADD temp.y, one.y, options2.y;" + // sursurface
13123
+ // Tuning for default skin
13124
+ //"ADD temp.x, temp.x, options2.z;" + // lightsheen
13125
+ "MAD temp.x, options2.z, half.y, temp.x;" + // lightsheen
13126
+ "ADD temp.y, one.y, options2.y;" + // subsurface
1223513127 "MUL temp.x, temp.x, temp.y;" +
1223613128
1223713129 "MUL saturation, saturation, temp.xxxx;" +
....@@ -12430,7 +13322,7 @@
1243013322 //once = true;
1243113323 }
1243213324
12433
- System.out.print("Program #" + mode + "; length = " + program.length());
13325
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1243413326 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1243513327 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1243613328
....@@ -12523,25 +13415,26 @@
1252313415 return out;
1252413416 }
1252513417
12526
- String TextureFetch(String dest, String src, String unit)
13418
+ // Also does frustum culling
13419
+ String ShadowTextureFetch(String dest, String src, String unit)
1252713420 {
1252813421 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1252913422 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1253013423 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13424
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13425
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1253113426 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12532
- "SLT " + src + ".z, " + src + ".x, one.x;" +
12533
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12534
- "SLT " + src + ".z, " + src + ".y, one.x;" +
12535
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13427
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13428
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1253613429 //"SWZ buffer, temp, w,w,w,w;";
12537
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13430
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1253813431 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1253913432 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1254013433 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
12541
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13434
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1254213435
12543
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
12544
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13436
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13437
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1254513438 }
1254613439
1254713440 String Shadow(String depth, String shadow)
....@@ -12563,12 +13456,16 @@
1256313456
1256413457 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1256513458 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13459
+
13460
+ // Compare fragment depth in light space with shadowmap.
1256613461 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1256713462 "SGE temp.y, temp.x, zero.x;" +
12568
- "SUB " + shadow + ".y, one.x, temp.y;" +
13463
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13464
+
13465
+ // Reverse comparison
1256913466 "SUB temp.x, one.x, temp.x;" +
1257013467 "MUL " + shadow + ".x, temp.x, temp.y;" +
12571
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13468
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1257213469 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1257313470
1257413471 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -12582,6 +13479,10 @@
1258213479 // No shadow for backface
1258313480 "DP3 temp.x, normal, lightd;" +
1258413481 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13482
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13483
+
13484
+ // No shadow when out of frustum
13485
+ "SGE temp.x, " + depth + ".z, one.z;" +
1258513486 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1258613487 "";
1258713488 }
....@@ -12728,7 +13629,8 @@
1272813629 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1272913630 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1273013631 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
12731
- Object3D.cVector2[] vector2buffer;
13632
+
13633
+ //Object3D.cVector2[] vector2buffer;
1273213634
1273313635 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1273413636 // OUT : diff, spec
....@@ -12744,9 +13646,10 @@
1274413646 "DP3 " + dest + ".z," + "normals," + "eye;" +
1274513647 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1274613648 //"MOV " + dest + ".w," + "normal.z;" +
12747
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
12748
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
12749
- //"MOV " + dest + ".z," + "params2.w;" +
13649
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13650
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13651
+
13652
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1275013653 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1275113654 "RCP " + dest + ".w," + dest + ".w;" +
1275213655 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13140,7 +14043,7 @@
1314014043 public void mousePressed(MouseEvent e)
1314114044 {
1314214045 //System.out.println("mousePressed: " + e);
13143
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14046
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1314414047 }
1314514048
1314614049 static long prevtime = 0;
....@@ -13167,6 +14070,7 @@
1316714070
1316814071 //System.err.println("Dtime = " + Dtime + "; units = " + e.getUnitsToScroll() + "; ratio (units/ms) = " + ratio);
1316914072
14073
+ if (BUTTONLESSWHEEL)
1317014074 if (Math.abs(ratio) < 0.1 || Math.abs(Dtime) == 0) // < 30)
1317114075 {
1317214076 return;
....@@ -13175,7 +14079,7 @@
1317514079 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
1317614080
1317714081 // TIMER
13178
- if (!wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
14082
+ if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
1317914083 {
1318014084 keepboxmode = BOXMODE;
1318114085 keepsupport = SUPPORT;
....@@ -13215,8 +14119,8 @@
1321514119 // mode |= META;
1321614120 //}
1321714121
13218
- SetMouseMode(WHEEL | e.getModifiersEx());
13219
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14122
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14123
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1322014124 anchorX = ax;
1322114125 anchorY = ay;
1322214126 prevX = px;
....@@ -13250,6 +14154,7 @@
1325014154 else
1325114155 if (evt.getSource() == AAtimer)
1325214156 {
14157
+ Globals.TIMERRUNNING = false;
1325314158 if (mouseDown)
1325414159 {
1325514160 //new Exception().printStackTrace();
....@@ -13275,6 +14180,10 @@
1327514180 // LIVE = waslive;
1327614181 // wasliveok = true;
1327714182 // waslive = false;
14183
+
14184
+ // May 2019 Forget it:
14185
+ if (true)
14186
+ return;
1327814187
1327914188 // source == timer
1328014189 if (mouseDown)
....@@ -13305,7 +14214,7 @@
1330514214
1330614215 // fev 2014???
1330714216 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13308
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14217
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1330914218 pingthread.StepToTarget(true); // true);
1331014219 }
1331114220 // if (!LIVE)
....@@ -13314,12 +14223,13 @@
1331414223
1331514224 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1331614225
13317
- void clickStart(int x, int y, int modifiers)
14226
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1331814227 {
1331914228 if (!wasliveok)
1332014229 return;
1332114230
1332214231 AAtimer.restart(); //
14232
+ Globals.TIMERRUNNING = true;
1332314233
1332414234 // waslive = LIVE;
1332514235 // LIVE = false;
....@@ -13331,7 +14241,7 @@
1333114241 // touched = true; // main DL
1333214242 if (isRenderer)
1333314243 {
13334
- SetMouseMode(modifiers);
14244
+ SetMouseMode(modifiers, modifiersex);
1333514245 }
1333614246
1333714247 selectX = anchorX = x;
....@@ -13344,7 +14254,7 @@
1334414254 clicked = true;
1334514255 hold = false;
1334614256
13347
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14257
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1334814258 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1334914259 {
1335014260 // System.out.println("RESTART II " + modifiers);
....@@ -13369,14 +14279,15 @@
1336914279 drag = false;
1337014280 //System.out.println("Mouse DOWN");
1337114281 editObj = false;
13372
- ClickInfo info = new ClickInfo();
13373
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
13374
- info.pane = this;
13375
- info.camera = renderCamera;
13376
- info.x = x;
13377
- info.y = y;
13378
- info.modifiers = modifiers;
13379
- editObj = object.doEditClick(info, 0);
14282
+ //ClickInfo info = new ClickInfo();
14283
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14284
+ object.clickInfo.pane = this;
14285
+ object.clickInfo.camera = renderCamera;
14286
+ object.clickInfo.x = x;
14287
+ object.clickInfo.y = y;
14288
+ object.clickInfo.modifiers = modifiersex;
14289
+ editObj = object.doEditClick(//info,
14290
+ 0);
1338014291 if (!editObj)
1338114292 {
1338214293 hasMarquee = true;
....@@ -13392,11 +14303,14 @@
1339214303
1339314304 public void mouseDragged(MouseEvent e)
1339414305 {
14306
+ Globals.MOUSEDRAGGED = true;
14307
+
14308
+ //System.out.println("mouseDragged: " + e);
1339514309 if (isRenderer)
1339614310 movingcamera = true;
14311
+
1339714312 //if (drawing)
1339814313 //return;
13399
- //System.out.println("mouseDragged: " + e);
1340014314 if ((e.getModifiersEx() & CTRL) != 0
1340114315 || (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen())
1340214316 {
....@@ -13404,7 +14318,7 @@
1340414318 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1340514319 }
1340614320 else
13407
- drag(e.getX(), e.getY(), e.getModifiersEx());
14321
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1340814322
1340914323 //try { Thread.sleep(1); } catch (Exception ex) {}
1341014324 }
....@@ -13577,6 +14491,7 @@
1357714491
1357814492 public void run()
1357914493 {
14494
+ new Exception().printStackTrace();
1358014495 System.exit(0);
1358114496 for (;;)
1358214497 {
....@@ -13640,7 +14555,7 @@
1364014555 {
1364114556 Globals.lighttouched = true;
1364214557 }
13643
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14558
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1364414559 }
1364514560 //else
1364614561 }
....@@ -13654,12 +14569,12 @@
1365414569 void GoDown(int mod)
1365514570 {
1365614571 MODIFIERS |= COMMAND;
13657
- /*
14572
+ /**/
1365814573 if((mod&SHIFT) == SHIFT)
1365914574 manipCamera.RotatePosition(0, -speed);
1366014575 else
13661
- manipCamera.BackForth(0, -speed*delta, getWidth());
13662
- */
14576
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14577
+ /**/
1366314578 if ((mod & SHIFT) == SHIFT)
1366414579 {
1366514580 mouseMode = mouseMode; // VR??
....@@ -13675,12 +14590,12 @@
1367514590 void GoUp(int mod)
1367614591 {
1367714592 MODIFIERS |= COMMAND;
13678
- /*
14593
+ /**/
1367914594 if((mod&SHIFT) == SHIFT)
1368014595 manipCamera.RotatePosition(0, speed);
1368114596 else
13682
- manipCamera.BackForth(0, speed*delta, getWidth());
13683
- */
14597
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14598
+ /**/
1368414599 if ((mod & SHIFT) == SHIFT)
1368514600 {
1368614601 mouseMode = mouseMode;
....@@ -13696,12 +14611,12 @@
1369614611 void GoLeft(int mod)
1369714612 {
1369814613 MODIFIERS |= COMMAND;
13699
- /*
14614
+ /**/
1370014615 if((mod&SHIFT) == SHIFT)
13701
- manipCamera.RotatePosition(speed, 0);
13702
- else
1370314616 manipCamera.Translate(speed*delta, 0, getWidth());
13704
- */
14617
+ else
14618
+ manipCamera.RotatePosition(speed, 0);
14619
+ /**/
1370514620 if ((mod & SHIFT) == SHIFT)
1370614621 {
1370714622 mouseMode = mouseMode;
....@@ -13717,12 +14632,12 @@
1371714632 void GoRight(int mod)
1371814633 {
1371914634 MODIFIERS |= COMMAND;
13720
- /*
14635
+ /**/
1372114636 if((mod&SHIFT) == SHIFT)
13722
- manipCamera.RotatePosition(-speed, 0);
13723
- else
1372414637 manipCamera.Translate(-speed*delta, 0, getWidth());
13725
- */
14638
+ else
14639
+ manipCamera.RotatePosition(-speed, 0);
14640
+ /**/
1372614641 if ((mod & SHIFT) == SHIFT)
1372714642 {
1372814643 mouseMode = mouseMode;
....@@ -13740,7 +14655,7 @@
1374014655 int X, Y;
1374114656 boolean SX, SY;
1374214657
13743
- void drag(int x, int y, int modifiers)
14658
+ void drag(int x, int y, int modifiers, int modifiersex)
1374414659 {
1374514660 if (IsFrozen())
1374614661 {
....@@ -13749,17 +14664,17 @@
1374914664
1375014665 drag = true; // NEW
1375114666
13752
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14667
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1375314668
1375414669 X = x;
1375514670 Y = y;
1375614671 // floating state for animation
13757
- MODIFIERS = modifiers;
13758
- modifiers &= ~1024;
14672
+ MODIFIERS = modifiersex;
14673
+ modifiersex &= ~1024;
1375914674 if (false) // modifiers != 0)
1376014675 {
1376114676 //new Exception().printStackTrace();
13762
- System.out.println("mouseDragged: " + modifiers);
14677
+ System.out.println("mouseDragged: " + modifiersex);
1376314678 System.out.println("SHIFT = " + SHIFT);
1376414679 System.out.println("CONTROL = " + COMMAND);
1376514680 System.out.println("META = " + META);
....@@ -13772,14 +14687,16 @@
1377214687 if (editObj)
1377314688 {
1377414689 drag = true;
13775
- ClickInfo info = new ClickInfo();
13776
- info.bounds.setBounds(0, 0,
14690
+ //ClickInfo info = new ClickInfo();
14691
+ object.clickInfo.bounds.setBounds(0, 0,
1377714692 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
13778
- info.pane = this;
13779
- info.camera = renderCamera;
13780
- info.x = x;
13781
- info.y = y;
13782
- object.editWindow.copy.doEditDrag(info);
14693
+ object.clickInfo.pane = this;
14694
+ object.clickInfo.camera = renderCamera;
14695
+ object.clickInfo.x = x;
14696
+ object.clickInfo.y = y;
14697
+ object //.GetWindow().copy
14698
+ .doEditDrag(//info,
14699
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1378314700 } else
1378414701 {
1378514702 if (x < startX)
....@@ -13928,23 +14845,27 @@
1392814845 }
1392914846 }
1393014847
14848
+// ClickInfo clickInfo = new ClickInfo();
14849
+
1393114850 public void mouseMoved(MouseEvent e)
1393214851 {
1393314852 //System.out.println("mouseMoved: " + e);
13934
-
1393514853 if (isRenderer)
1393614854 return;
1393714855
13938
- ClickInfo ci = new ClickInfo();
13939
- ci.x = e.getX();
13940
- ci.y = e.getY();
13941
- ci.modifiers = e.getModifiersEx();
13942
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
13943
- ci.pane = this;
13944
- ci.camera = renderCamera;
14856
+ // Mouse cursor feedback
14857
+ object.clickInfo.x = e.getX();
14858
+ object.clickInfo.y = e.getY();
14859
+ object.clickInfo.modifiers = e.getModifiersEx();
14860
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14861
+ object.clickInfo.pane = this;
14862
+ object.clickInfo.camera = renderCamera;
1394514863 if (!isRenderer)
1394614864 {
13947
- if (object.editWindow.copy.doEditClick(ci, 0))
14865
+ //ObjEditor editWindow = object.editWindow;
14866
+ //Object3D copy = editWindow.copy;
14867
+ if (object.doEditClick(//clickInfo,
14868
+ 0))
1394814869 {
1394914870 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1395014871 } else
....@@ -13956,7 +14877,11 @@
1395614877
1395714878 public void mouseReleased(MouseEvent e)
1395814879 {
14880
+ Globals.MOUSEDRAGGED = false;
14881
+
1395914882 movingcamera = false;
14883
+ X = 0; // getBounds().width/2;
14884
+ Y = 0; // getBounds().height/2;
1396014885 //System.out.println("mouseReleased: " + e);
1396114886 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1396214887 }
....@@ -13979,9 +14904,9 @@
1397914904 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1398014905 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1398114906
13982
- if (control || command || IsFrozen())
14907
+// No delay if (control || command || IsFrozen())
1398314908 timeout = true;
13984
- else
14909
+// ?? May 2019 else
1398514910 // timer.setDelay((modifiers & 128) != 0?0:350);
1398614911 mouseDown = false;
1398714912 if (!control && !command) // june 2013
....@@ -14091,7 +15016,7 @@
1409115016 System.out.println("keyReleased: " + e);
1409215017 }
1409315018
14094
- void SetMouseMode(int modifiers)
15019
+ void SetMouseMode(int modifiers, int modifiersex)
1409515020 {
1409615021 //System.out.println("SetMouseMode = " + modifiers);
1409715022 //modifiers &= ~1024;
....@@ -14103,25 +15028,25 @@
1410315028 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1410415029 // return;
1410515030 //System.out.println("SetMode = " + modifiers);
14106
- if ((modifiers & WHEEL) == WHEEL)
15031
+ if ((modifiersex & WHEEL) == WHEEL)
1410715032 {
1410815033 mouseMode |= ZOOM;
1410915034 }
1411015035
1411115036 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
14112
- if (capsLocked || (modifiers & META) == META)
15037
+ if (capsLocked) // || (modifiers & META) == META)
1411315038 {
1411415039 mouseMode |= VR; // BACKFORTH;
1411515040 }
14116
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
15041
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1411715042 {
1411815043 mouseMode |= SELECT;
1411915044 }
14120
- if ((modifiers & COMMAND) == COMMAND)
15045
+ if ((modifiersex & COMMAND) == COMMAND)
1412115046 {
1412215047 mouseMode |= SELECT;
1412315048 }
14124
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15049
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
1412515050 {
1412615051 mouseMode &= ~VR;
1412715052 mouseMode |= TRANSLATE;
....@@ -14150,10 +15075,10 @@
1415015075
1415115076 if (isRenderer) //
1415215077 {
14153
- SetMouseMode(modifiers);
15078
+ SetMouseMode(0, modifiers);
1415415079 }
1415515080
14156
- theRenderer.keyPressed(key);
15081
+ Globals.theRenderer.keyPressed(key);
1415715082 }
1415815083
1415915084 int kompactbit = 4; // power bit
....@@ -14165,7 +15090,7 @@
1416515090 float SATPOW = 1; // 2; // 0.5f;
1416615091 float BRIPOW = 1; // 0.5f; // 0.5f;
1416715092
14168
- void keyPressed(int key)
15093
+ public void keyPressed(int key)
1416915094 {
1417015095 if (key >= '0' && key <= '5')
1417115096 clampbit = (key-'0');
....@@ -14212,7 +15137,8 @@
1421215137 // break;
1421315138 case 'T':
1421415139 CACHETEXTURE ^= true;
14215
- textures.clear();
15140
+ texturepigment.clear();
15141
+ texturebump.clear();
1421615142 // repaint();
1421715143 break;
1421815144 case 'Y':
....@@ -14297,7 +15223,9 @@
1429715223 case 'E' : COMPACT ^= true;
1429815224 repaint();
1429915225 break;
14300
- case 'W' : DEBUGHSB ^= true;
15226
+ case 'W' : // Wide Window (fullscreen)
15227
+ //DEBUGHSB ^= true;
15228
+ ObjEditor.theFrame.ToggleFullScreen();
1430115229 repaint();
1430215230 break;
1430315231 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14322,8 +15250,8 @@
1432215250 RevertCamera();
1432315251 repaint();
1432415252 break;
14325
- case 'L':
1432615253 case 'l':
15254
+ //case 'L':
1432715255 if (lightMode)
1432815256 {
1432915257 lightMode = false;
....@@ -14466,9 +15394,9 @@
1446615394 case '_':
1446715395 kompactbit = 5;
1446815396 break;
14469
- case '+':
14470
- kompactbit = 6;
14471
- break;
15397
+// case '+':
15398
+// kompactbit = 6;
15399
+// break;
1447215400 case ' ':
1447315401 lightMode ^= true;
1447415402 Globals.lighttouched = true;
....@@ -14480,13 +15408,14 @@
1448015408 case ESC:
1448115409 RENDERPROGRAM += 1;
1448215410 RENDERPROGRAM %= 3;
15411
+
1448315412 repaint();
1448415413 break;
1448515414 case 'Z':
1448615415 //RESIZETEXTURE ^= true;
1448715416 //break;
1448815417 case 'z':
14489
- RENDERSHADOW ^= true;
15418
+ Globals.RENDERSHADOW ^= true;
1449015419 Globals.lighttouched = true;
1449115420 repaint();
1449215421 break;
....@@ -14519,8 +15448,9 @@
1451915448 case DELETE:
1452015449 ClearSelection();
1452115450 break;
14522
- /*
1452315451 case '+':
15452
+
15453
+ /*
1452415454 //fontsize += 1;
1452515455 bbzoom *= 2;
1452615456 repaint();
....@@ -14537,17 +15467,17 @@
1453715467 case '=':
1453815468 IncDepth();
1453915469 //fontsize += 1;
14540
- object.editWindow.refreshContents(true);
15470
+ object.GetWindow().refreshContents(true);
1454115471 maskbit = 6;
1454215472 break;
1454315473 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1454415474 DecDepth();
1454515475 maskbit = 5;
1454615476 //if(fontsize > 1) fontsize -= 1;
14547
- if (object.editWindow == null)
14548
- new Exception().printStackTrace();
14549
- else
14550
- object.editWindow.refreshContents(true);
15477
+// if (object.editWindow == null)
15478
+// new Exception().printStackTrace();
15479
+// else
15480
+ object.GetWindow().refreshContents(true);
1455115481 break;
1455215482 case '{':
1455315483 manipCamera.shaper_fovy /= 1.1;
....@@ -14602,6 +15532,7 @@
1460215532 }
1460315533 //System.out.println("shaper_fovy = " + manipCamera.shaper_fovy);
1460415534 }
15535
+
1460515536 static double OCCLUSIONBOOST = 1; // 0.5;
1460615537
1460715538 void keyReleased(int key, int modifiers)
....@@ -14609,11 +15540,11 @@
1460915540 //mode = ROTATE;
1461015541 if ((MODIFIERS & COMMAND) == 0) // VR??
1461115542 {
14612
- SetMouseMode(modifiers);
15543
+ SetMouseMode(0, modifiers);
1461315544 }
1461415545 }
1461515546
14616
- protected void processKeyEvent(KeyEvent e)
15547
+ public void processKeyEvent(KeyEvent e)
1461715548 {
1461815549 switch (e.getID())
1461915550 {
....@@ -14743,8 +15674,9 @@
1474315674
1474415675 protected void processMouseMotionEvent(MouseEvent e)
1474515676 {
14746
- //System.out.println("processMouseMotionEvent: " + mouseMode);
14747
- if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15677
+ //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
15678
+ //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15679
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1474815680 {
1474915681 mouseMoved(e);
1475015682 } else
....@@ -14769,11 +15701,12 @@
1476915701 }
1477015702 */
1477115703
14772
- object.editWindow.EditSelection();
15704
+ object.GetWindow().EditSelection(false);
1477315705 }
1477415706
1477515707 void SelectParent()
1477615708 {
15709
+ new Exception().printStackTrace();
1477715710 System.exit(0);
1477815711 Composite group = (Composite) object;
1477915712 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -14785,10 +15718,10 @@
1478515718 {
1478615719 //selectees.remove(i);
1478715720 System.out.println("select parent of " + elem);
14788
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15721
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1478915722 } else
1479015723 {
14791
- group.editWindow.Select(elem.GetTreePath(), first, true);
15724
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1479215725 }
1479315726
1479415727 first = false;
....@@ -14797,6 +15730,7 @@
1479715730
1479815731 void SelectChildren()
1479915732 {
15733
+ new Exception().printStackTrace();
1480015734 System.exit(0);
1480115735 /*
1480215736 Composite group = (Composite) object;
....@@ -14829,12 +15763,12 @@
1482915763 for (int j = 0; j < group.children.size(); j++)
1483015764 {
1483115765 elem = (Object3D) group.children.elementAt(j);
14832
- object.editWindow.Select(elem.GetTreePath(), first, true);
15766
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1483315767 first = false;
1483415768 }
1483515769 } else
1483615770 {
14837
- object.editWindow.Select(elem.GetTreePath(), first, true);
15771
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1483815772 }
1483915773
1484015774 first = false;
....@@ -14845,21 +15779,21 @@
1484515779 {
1484615780 //Composite group = (Composite) object;
1484715781 Object3D group = object;
14848
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15782
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1484915783 }
1485015784
1485115785 void ResetTransform(int mask)
1485215786 {
1485315787 //Composite group = (Composite) object;
1485415788 Object3D group = object;
14855
- group.editWindow.ResetTransform(mask);
15789
+ group.GetWindow().ResetTransform(mask);
1485615790 }
1485715791
1485815792 void FlipTransform()
1485915793 {
1486015794 //Composite group = (Composite) object;
1486115795 Object3D group = object;
14862
- group.editWindow.FlipTransform();
15796
+ group.GetWindow().FlipTransform();
1486315797 // group.editWindow.ReduceMesh(true);
1486415798 }
1486515799
....@@ -14867,7 +15801,7 @@
1486715801 {
1486815802 //Composite group = (Composite) object;
1486915803 Object3D group = object;
14870
- group.editWindow.PrintMemory();
15804
+ group.GetWindow().PrintMemory();
1487115805 // group.editWindow.ReduceMesh(true);
1487215806 }
1487315807
....@@ -14875,7 +15809,7 @@
1487515809 {
1487615810 //Composite group = (Composite) object;
1487715811 Object3D group = object;
14878
- group.editWindow.ResetCentroid();
15812
+ group.GetWindow().ResetCentroid();
1487915813 }
1488015814
1488115815 void IncDepth()
....@@ -14957,11 +15891,11 @@
1495715891
1495815892 int width = getBounds().width;
1495915893 int height = getBounds().height;
14960
- ClickInfo info = new ClickInfo();
14961
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1496215894 //Image img = CreateImage(width, height);
1496315895 //System.out.println("width = " + width + "; height = " + height + "\n");
15896
+
1496415897 Graphics gr = g; // img.getGraphics();
15898
+
1496515899 if (!hasMarquee)
1496615900 {
1496715901 if (Xmin < Xmax) // !locked)
....@@ -15033,40 +15967,88 @@
1503315967 }
1503415968 if (object != null && !hasMarquee)
1503515969 {
15970
+ if (object.clickInfo == null)
15971
+ object.clickInfo = new ClickInfo();
15972
+ ClickInfo info = object.clickInfo;
15973
+ //ClickInfo info = new ClickInfo();
15974
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
15975
+
1503615976 if (isRenderer)
1503715977 {
15038
- info.flags++;
15978
+ object.clickInfo.flags++;
1503915979 double frameAspect = (double) width / (double) height;
1504015980 if (frameAspect > renderCamera.aspect)
1504115981 {
1504215982 int desired = (int) ((double) height * renderCamera.aspect);
15043
- info.bounds.width -= width - desired;
15044
- info.bounds.x += (width - desired) / 2;
15983
+ object.clickInfo.bounds.width -= width - desired;
15984
+ object.clickInfo.bounds.x += (width - desired) / 2;
1504515985 } else
1504615986 {
1504715987 int desired = (int) ((double) width / renderCamera.aspect);
15048
- info.bounds.height -= height - desired;
15049
- info.bounds.y += (height - desired) / 2;
15988
+ object.clickInfo.bounds.height -= height - desired;
15989
+ object.clickInfo.bounds.y += (height - desired) / 2;
1505015990 }
1505115991 }
15052
- info.g = gr;
15053
- info.camera = renderCamera;
15992
+
15993
+ object.clickInfo.g = gr;
15994
+ object.clickInfo.camera = renderCamera;
1505415995 /*
1505515996 // Memory intensive (brep.verticescopy)
1505615997 if (!(object instanceof Composite))
1505715998 object.draw(info, 0, false); // SLOW :
1505815999 */
15059
- if (!isRenderer)
16000
+ if (!isRenderer) // && drag)
1506016001 {
15061
- object.drawEditHandles(info, 0);
16002
+ Grafreed.Assert(object != null);
16003
+ Grafreed.Assert(object.selection != null);
16004
+ if (object.selection.Size() > 0)
16005
+ {
16006
+ int hitSomething = object.selection.get(0).hitSomething;
16007
+
16008
+ object.clickInfo.DX = 0;
16009
+ object.clickInfo.DY = 0;
16010
+ object.clickInfo.W = 1;
16011
+ if (hitSomething == Object3D.hitCenter)
16012
+ {
16013
+ info.DX = X;
16014
+ if (X != 0)
16015
+ info.DX -= info.bounds.width/2;
16016
+
16017
+ info.DY = Y;
16018
+ if (Y != 0)
16019
+ info.DY -= info.bounds.height/2;
16020
+ }
16021
+
16022
+ object.drawEditHandles(//info,
16023
+ 0);
16024
+
16025
+ if (drag && (X != 0 || Y != 0))
16026
+ {
16027
+ switch (hitSomething)
16028
+ {
16029
+ case Object3D.hitCenter: gr.setColor(Color.pink);
16030
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16031
+ break;
16032
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16033
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16034
+ break;
16035
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16036
+ gr.drawLine(X, Y, 0, 0);
16037
+ break;
16038
+ }
16039
+
16040
+ }
16041
+ }
1506216042 }
1506316043 }
16044
+
1506416045 if (isRenderer)
1506516046 {
1506616047 //gr.setColor(Color.black);
1506716048 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1506816049 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1506916050 }
16051
+
1507016052 if (hasMarquee)
1507116053 {
1507216054 gr.setXORMode(Color.white);
....@@ -15179,6 +16161,7 @@
1517916161 public boolean mouseDown(Event evt, int x, int y)
1518016162 {
1518116163 System.out.println("mouseDown: " + evt);
16164
+ System.exit(0);
1518216165 /*
1518316166 locked = true;
1518416167 drag = false;
....@@ -15222,7 +16205,7 @@
1522216205 {
1522316206 keyPressed(0, modifiers);
1522416207 }
15225
- clickStart(x, y, modifiers);
16208
+ // clickStart(x, y, modifiers);
1522616209 return true;
1522716210 }
1522816211
....@@ -15340,7 +16323,7 @@
1534016323 {
1534116324 keyReleased(0, 0);
1534216325 }
15343
- drag(x, y, modifiers);
16326
+ drag(x, y, 0, modifiers);
1534416327 return true;
1534516328 }
1534616329
....@@ -15472,7 +16455,7 @@
1547216455 Object3D object;
1547316456 static Object3D trackedobject;
1547416457 Camera renderCamera; // Light or Eye (or Occlusion)
15475
- /*static*/ Camera manipCamera; // Light or Eye
16458
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1547616459 /*static*/ Camera eyeCamera;
1547716460 /*static*/ Camera lightCamera;
1547816461 int cameracount;
....@@ -15757,16 +16740,16 @@
1575716740 cStatic.objectstack[materialdepth++] = checker;
1575816741 //System.out.println("material " + material);
1575916742 //Applet3D.tracein(this, selected);
15760
- vector2buffer = checker.projectedVertices;
16743
+ //vector2buffer = checker.projectedVertices;
1576116744
1576216745 //checker.GetMaterial().Draw(this, false); // true);
15763
- DrawMaterial(checker.GetMaterial(), false); // true);
16746
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1576416747
1576516748 materialdepth -= 1;
1576616749 if (materialdepth > 0)
1576716750 {
15768
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
15769
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
16751
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16752
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1577016753 }
1577116754 //checker.GetMaterial().opacity = 1f;
1577216755 ////checker.GetMaterial().ambient = 1f;
....@@ -15852,6 +16835,14 @@
1585216835 }
1585316836 }
1585416837
16838
+ private Object3D GetFolder()
16839
+ {
16840
+ Object3D folder = object.GetWindow().copy;
16841
+ if (object.GetWindow().copy.selection.Size() > 0)
16842
+ folder = object.GetWindow().copy.selection.elementAt(0);
16843
+ return folder;
16844
+ }
16845
+
1585516846 class SelectBuffer implements GLEventListener
1585616847 {
1585716848
....@@ -15910,6 +16901,7 @@
1591016901 {
1591116902 if (!selection)
1591216903 {
16904
+ new Exception().printStackTrace();
1591316905 System.exit(0);
1591416906 return;
1591516907 }
....@@ -15930,6 +16922,17 @@
1593016922
1593116923 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1593216924
16925
+ if (PAINTMODE)
16926
+ {
16927
+ if (object.GetWindow().copy.selection.Size() > 0)
16928
+ {
16929
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16930
+
16931
+ // Make what you paint not selectable.
16932
+ paintobj.ResetSelectable();
16933
+ }
16934
+ }
16935
+
1593316936 //int tmp = selection_view;
1593416937 //selection_view = -1;
1593516938 int temp = DrawMode();
....@@ -15941,6 +16944,17 @@
1594116944 // temp = DEFAULT; // patch for selection debug
1594216945 Globals.drawMode = temp; // WARNING
1594316946
16947
+ if (PAINTMODE)
16948
+ {
16949
+ if (object.GetWindow().copy.selection.Size() > 0)
16950
+ {
16951
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16952
+
16953
+ // Revert.
16954
+ paintobj.RestoreSelectable();
16955
+ }
16956
+ }
16957
+
1594416958 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1594516959
1594616960 // trying different ways of getting the depth info over
....@@ -15988,6 +17002,8 @@
1598817002 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1598917003 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1599017004 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
17005
+
17006
+ CreateSelectedPoint();
1599117007
1599217008 // Will fit the mesh !!!
1599317009 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16037,34 +17053,36 @@
1603717053 System.out.println("; fromto " + sel + " " + Trunk(previousselectedpoint.toParent[3][0]) + " " + Trunk(previousselectedpoint.toParent[3][2]) + " " + Trunk(selectedpoint.toParent[3][0]) + " " + Trunk(selectedpoint.toParent[3][2]));
1603817054 }
1603917055
16040
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
17056
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1604117057 }
1604217058 }
1604317059
1604417060 if (!movingcamera && !PAINTMODE)
16045
- object.editWindow.ScreenFitPoint(); // fev 2014
17061
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1604617062
16047
- if (PAINTMODE && GrafreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17063
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1604817064 {
16049
- Object3D paintobj = GrafreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17065
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1605017066
16051
- Object3D group = new Object3D("inst" + paintcount++);
17067
+ if (object.GetWindow().copy.selection.Size() > 0)
17068
+ {
17069
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1605217070
16053
- group.CreateMaterial(); // use a void leaf to select instances
16054
-
16055
- group.add(paintobj); // link
16056
-
16057
- object.editWindow.SnapObject(group);
16058
-
16059
- Object3D folder = object.editWindow.copy;
16060
-
16061
- if (object.editWindow.copy.selection.Size() > 0)
16062
- folder = object.editWindow.copy.selection.elementAt(0);
16063
-
16064
- folder.add(group);
16065
-
16066
- object.editWindow.ResetModel();
16067
- object.editWindow.refreshContents();
17071
+ Object3D inst = new Object3D("inst" + paintcount++);
17072
+
17073
+ inst.CreateMaterial(); // use a void leaf to select instances
17074
+
17075
+ inst.add(paintobj); // link
17076
+
17077
+ object.GetWindow().SnapObject(inst);
17078
+
17079
+ Object3D folder = paintFolder; // GetFolder();
17080
+
17081
+ folder.add(inst);
17082
+
17083
+ object.GetWindow().ResetModel();
17084
+ object.GetWindow().refreshContents();
17085
+ }
1606817086 }
1606917087 else
1607017088 paintcount = 0;
....@@ -16103,6 +17121,11 @@
1610317121 //System.out.println("objects[color] = " + objects[color]);
1610417122 //objects[color].Select();
1610517123 indexcount = 0;
17124
+ ObjEditor window = object.GetWindow();
17125
+ if (window != null && deselect)
17126
+ {
17127
+ window.Select(null, deselect, true);
17128
+ }
1610617129 object.Select(color, deselect);
1610717130 }
1610817131
....@@ -16202,7 +17225,7 @@
1620217225 gl.glDisable(gl.GL_CULL_FACE);
1620317226 }
1620417227
16205
- if (!RENDERSHADOW)
17228
+ if (!Globals.RENDERSHADOW)
1620617229 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1620717230
1620817231 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -16212,7 +17235,7 @@
1621217235 //gl.glColorMask(false, false, false, false);
1621317236
1621417237 //render_scene_from_light_view(gl, drawable, 0, 0);
16215
- if (RENDERSHADOW && Globals.lighttouched && !movingcamera) // && !parent.IsFreezed())
17238
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1621617239 {
1621717240 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1621817241
....@@ -16628,23 +17651,15 @@
1662817651 int AAbuffersize = 0;
1662917652
1663017653 //double[] selectedpoint = new double[3];
16631
- static Superellipsoid selectedpoint = new Superellipsoid();
17654
+ static Superellipsoid selectedpoint;
1663217655 static Sphere previousselectedpoint = null;
16633
- static Sphere debugpointG = new Sphere();
16634
- static Sphere debugpointP = new Sphere();
16635
- static Sphere debugpointC = new Sphere();
16636
- static Sphere debugpointR = new Sphere();
17656
+ static Sphere debugpointG;
17657
+ static Sphere debugpointP;
17658
+ static Sphere debugpointC;
17659
+ static Sphere debugpointR;
1663717660
1663817661 static Sphere debugpoints[] = new Sphere[8];
1663917662
16640
- static
16641
- {
16642
- for (int i=0; i<8; i++)
16643
- {
16644
- debugpoints[i] = new Sphere();
16645
- }
16646
- }
16647
-
1664817663 static void InitPoints(float radius)
1664917664 {
1665017665 for (int i=0; i<8; i++)
....@@ -16696,10 +17711,11 @@
1669617711 static IntBuffer textbuffer = null; // IntBuffer.allocate(TEXT_WIDTH*8*8 * TEXT_HEIGHT);
1669717712 // Depth buffer format
1669817713 //private int depth_format;
16699
- static public void NextIndex(Object3D o, GL gl)
17714
+
17715
+ public void NextIndex()
1670017716 {
1670117717 indexcount+=16;
16702
- gl.glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
17718
+ GetGL().glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
1670317719 //objects[indexcount] = o;
1670417720 //System.out.println("indexcount = " + indexcount);
1670517721 }