Normand Briere
2019-07-24 f555e2cacc4470c5b2217a14d40d2b39c4a57ba2
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,6 +186,8 @@
150186 defaultcaps.setAccumAlphaBits(16);
151187 }
152188
189
+ private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
190
+
153191 void SetAsGLRenderer(boolean b)
154192 {
155193 isRenderer = b;
....@@ -191,9 +229,43 @@
191229
192230 /// INTERFACE
193231
232
+ public javax.media.opengl.GL GetGL0()
233
+ {
234
+ return null;
235
+ }
236
+
237
+ public int GenList()
238
+ {
239
+ javax.media.opengl.GL gl = GetGL();
240
+ return gl.glGenLists(1);
241
+ }
242
+
243
+ public void NewList(int id)
244
+ {
245
+ javax.media.opengl.GL gl = GetGL();
246
+ gl.glNewList(id, gl.GL_COMPILE); //_AND_EXECUTE);
247
+ }
248
+
249
+ public void CallList(int id)
250
+ {
251
+ javax.media.opengl.GL gl = GetGL();
252
+ gl.glCallList(id);
253
+ }
254
+
255
+ public void EndList()
256
+ {
257
+ javax.media.opengl.GL gl = GetGL();
258
+ gl.glEndList();
259
+ }
260
+
194261 public boolean IsBoxMode()
195262 {
196263 return BOXMODE;
264
+ }
265
+
266
+ public boolean IsZoomBoxMode()
267
+ {
268
+ return ZOOMBOXMODE;
197269 }
198270
199271 public void ClearDepth()
....@@ -291,7 +363,7 @@
291363 cStatic.objectstack[materialdepth++] = obj;
292364 //System.out.println("material " + material);
293365 //Applet3D.tracein(this, selected);
294
- display.vector2buffer = obj.projectedVertices;
366
+ //display.vector2buffer = obj.projectedVertices;
295367 if (obj instanceof Camera)
296368 {
297369 display.options1[0] = material.shift;
....@@ -300,14 +372,28 @@
300372 display.options1[2] = material.shadowbias;
301373 display.options1[3] = material.aniso;
302374 display.options1[4] = material.anisoV;
375
+// System.out.println("display.options1[0] " + display.options1[0]);
376
+// System.out.println("display.options1[1] " + display.options1[1]);
377
+// System.out.println("display.options1[2] " + display.options1[2]);
378
+// System.out.println("display.options1[3] " + display.options1[3]);
379
+// System.out.println("display.options1[4] " + display.options1[4]);
303380 display.options2[0] = material.opacity;
304381 display.options2[1] = material.diffuse;
305382 display.options2[2] = material.factor;
383
+// System.out.println("display.options2[0] " + display.options2[0]);
384
+// System.out.println("display.options2[1] " + display.options2[1]);
385
+// System.out.println("display.options2[2] " + display.options2[2]);
306386
307387 cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
388
+// System.out.println("display.options3[0] " + display.options3[0]);
389
+// System.out.println("display.options3[1] " + display.options3[1]);
390
+// System.out.println("display.options3[2] " + display.options3[2]);
308391 display.options4[0] = material.cameralight/0.2f;
309392 display.options4[1] = material.subsurface;
310393 display.options4[2] = material.sheen;
394
+// System.out.println("display.options4[0] " + display.options4[0]);
395
+// System.out.println("display.options4[1] " + display.options4[1]);
396
+// System.out.println("display.options4[2] " + display.options4[2]);
311397
312398 // if (display.CURRENTANTIALIAS > 0)
313399 // display.options3[3] /= 4;
....@@ -323,7 +409,7 @@
323409 /**/
324410 } else
325411 {
326
- DrawMaterial(material, selected);
412
+ DrawMaterial(material, selected, obj.projectedVertices);
327413 }
328414 } else
329415 {
....@@ -347,8 +433,8 @@
347433 cStatic.objectstack[materialdepth++] = obj;
348434 //System.out.println("material " + material);
349435 //Applet3D.tracein("selected ", selected);
350
- display.vector2buffer = obj.projectedVertices;
351
- display.DrawMaterial(material, selected);
436
+ //display.vector2buffer = obj.projectedVertices;
437
+ display.DrawMaterial(material, selected, obj.projectedVertices);
352438 }
353439 }
354440
....@@ -365,8 +451,8 @@
365451 materialdepth -= 1;
366452 if (materialdepth > 0)
367453 {
368
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
369
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
454
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
455
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
370456 }
371457 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
372458 } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
....@@ -386,8 +472,8 @@
386472 materialdepth -= 1;
387473 if (materialdepth > 0)
388474 {
389
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
390
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
475
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
476
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
391477 }
392478 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
393479 //else
....@@ -428,10 +514,12 @@
428514 if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
429515 {
430516 //gl.glBegin(gl.GL_TRIANGLES);
431
- boolean hasnorm = pv.norm != null; // && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0);
517
+ boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0)
518
+ // TEST LIVE NORMALS && !obj.dontselect
519
+ ;
432520 if (!hasnorm)
433521 {
434
- // System.out.println("FUCK!!");
522
+ // System.out.println("Mesh normal");
435523 LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
436524 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
437525 LA.vecCross(obj.v0, obj.v1, obj.v2);
....@@ -1059,7 +1147,342 @@
10591147 gl.glMatrixMode(gl.GL_MODELVIEW);
10601148 }
10611149
1150
+ public void DrawBox(cVector min, cVector max)
1151
+ {
1152
+ javax.media.opengl.GL gl = GetGL();
1153
+ gl.glBegin(gl.GL_LINES);
1154
+
1155
+ gl.glVertex3d(min.x, min.y, min.z);
1156
+ gl.glVertex3d(min.x, min.y, max.z);
1157
+ gl.glVertex3d(min.x, min.y, min.z);
1158
+ gl.glVertex3d(min.x, max.y, min.z);
1159
+ gl.glVertex3d(min.x, min.y, min.z);
1160
+ gl.glVertex3d(max.x, min.y, min.z);
1161
+
1162
+ gl.glVertex3d(max.x, max.y, max.z);
1163
+ gl.glVertex3d(min.x, max.y, max.z);
1164
+ gl.glVertex3d(max.x, max.y, max.z);
1165
+ gl.glVertex3d(max.x, min.y, max.z);
1166
+ gl.glVertex3d(max.x, max.y, max.z);
1167
+ gl.glVertex3d(max.x, max.y, min.z);
1168
+
1169
+ gl.glEnd();
1170
+ }
1171
+
1172
+ public void DrawGeometry(BoundaryRep bRep, boolean flipV, boolean selectmode)
1173
+ {
1174
+ int[] strips = bRep.getRawIndices();
1175
+
1176
+ javax.media.opengl.GL gl = GetGL();
1177
+
1178
+ // TRIANGLE STRIP ARRAY
1179
+ if (bRep.trimmed)
1180
+ {
1181
+ float[] v = bRep.getRawVertices();
1182
+ float[] n = bRep.getRawNormals();
1183
+ float[] c = bRep.getRawColors();
1184
+ float[] uv = bRep.getRawUVMap();
1185
+
1186
+ int count2 = 0;
1187
+ int count3 = 0;
1188
+
1189
+ if (n.length > 0)
1190
+ {
1191
+ for (int i = 0; i < strips.length; i++)
1192
+ {
1193
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1194
+
1195
+ /*
1196
+ boolean locked = false;
1197
+ float eps = 0.1f;
1198
+ boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
1199
+
1200
+ int dot = 0;
1201
+
1202
+ if ((dot&1) == 0)
1203
+ dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
1204
+
1205
+ if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
1206
+ gl.glTexCoord2f((float) qv.s, (float) qv.t);
1207
+ else
1208
+ {
1209
+ locked = true;
1210
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1211
+ }
1212
+ //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
1213
+ gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
1214
+ if (hasnorm)
1215
+ {
1216
+ //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
1217
+ gl.glNormal3f((float) rv.norm.x, (float) rv.norm.y, (float) rv.norm.z);
1218
+ }
1219
+
1220
+ if ((dot&4) == 0)
1221
+ dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
1222
+
1223
+ if (wrap || !locked && (dot&8) != 0)
1224
+ gl.glTexCoord2f((float) rv.s, (float) rv.t);
1225
+ else
1226
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1227
+
1228
+ f.dot = dot;
1229
+ */
1230
+
1231
+ if (!selectmode)
1232
+ {
1233
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1234
+ {
1235
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1236
+ } else
1237
+ {
1238
+ gl.glNormal3f(0, 0, 1);
1239
+ }
1240
+
1241
+ if (c != null)
1242
+ //System.out.println("glcolor = " + c[count3] + ", " + c[count3+1] + ", " + c[count3+2]);
1243
+ {
1244
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1245
+ }
1246
+ }
1247
+
1248
+ if (flipV)
1249
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1250
+ else
1251
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1252
+
1253
+ //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1254
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1255
+
1256
+ count2 += 2;
1257
+ count3 += 3;
1258
+ if (!selectmode)
1259
+ {
1260
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1261
+ {
1262
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1263
+ } else
1264
+ {
1265
+ gl.glNormal3f(0, 0, 1);
1266
+ }
1267
+ if (c != null)
1268
+ {
1269
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1270
+ }
1271
+ }
1272
+
1273
+ if (flipV)
1274
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1275
+ else
1276
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1277
+
1278
+ //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1279
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1280
+
1281
+ count2 += 2;
1282
+ count3 += 3;
1283
+ for (int j = 0; j < strips[i] - 2; j++)
1284
+ {
1285
+ //gl.glTexCoord2d(...);
1286
+ if (!selectmode)
1287
+ {
1288
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1289
+ {
1290
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1291
+ } else
1292
+ {
1293
+ gl.glNormal3f(0, 0, 1);
1294
+ }
1295
+ if (c != null)
1296
+ {
1297
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1298
+ }
1299
+ }
1300
+
1301
+ if (flipV)
1302
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1303
+ else
1304
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1305
+
1306
+ //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
1307
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1308
+
1309
+ count2 += 2;
1310
+ count3 += 3;
1311
+ }
1312
+
1313
+ gl.glEnd();
1314
+ }
1315
+ }
1316
+
1317
+ assert count3 == v.length;
1318
+ }
1319
+ else // !trimmed
1320
+ {
1321
+ int count = 0;
1322
+ for (int i = 0; i < strips.length; i++)
1323
+ {
1324
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1325
+
1326
+ Vertex p = bRep.GetVertex(bRep.indices[count++]);
1327
+ Vertex q = bRep.GetVertex(bRep.indices[count++]);
1328
+
1329
+ drawVertex(gl, p, flipV, selectmode);
1330
+ drawVertex(gl, q, flipV, selectmode);
1331
+
1332
+ for (int j = 0; j < strips[i] - 2; j++)
1333
+ {
1334
+ Vertex r = bRep.GetVertex(bRep.indices[count++]);
1335
+
1336
+ // if (j%2 == 0)
1337
+ // drawFace(p, q, r, display, null);
1338
+ // else
1339
+ // drawFace(p, r, q, display, null);
1340
+
1341
+ // p = q;
1342
+ // q = r;
1343
+ drawVertex(gl, r, flipV, selectmode);
1344
+ }
1345
+
1346
+ gl.glEnd();
1347
+ }
1348
+ }
1349
+ }
1350
+
1351
+ static cSpring.Point3D temp = new cSpring.Point3D();
1352
+ static cSpring.Point3D temp2 = new cSpring.Point3D();
1353
+ static cSpring.Point3D temp3 = new cSpring.Point3D();
1354
+
1355
+ public void DrawDynamicMesh(cMesh mesh)
1356
+ {
1357
+ GL gl = GetGL(); // getGL();
1358
+
1359
+ cSpring.PhysicsController3D Phys = mesh.Phys;
1360
+
1361
+ gl.glDisable(gl.GL_LIGHTING);
1362
+
1363
+ gl.glLineWidth(1);
1364
+ gl.glColor3f(1,1,1);
1365
+ gl.glBegin(gl.GL_LINES);
1366
+ double scale = 0;
1367
+ int count = 0;
1368
+ for (int s=0; s<Phys.allSprings.size(); s++)
1369
+ {
1370
+ cSpring.Spring spring = Phys.allSprings.get(s);
1371
+ if(s == 0)
1372
+ {
1373
+ //System.out.println(" spring : " + spring.a.position + "; " + spring.b.position);
1374
+ }
1375
+ if (mesh.showsprings)
1376
+ {
1377
+ temp.set(spring.a.position);
1378
+ temp.add(spring.b.position);
1379
+ temp.mul(0.5);
1380
+ temp2.set(spring.a.position);
1381
+ temp2.sub(spring.b.position);
1382
+ temp2.mul(spring.restLength/2);
1383
+ temp.sub(temp2);
1384
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1385
+ temp.add(temp2);
1386
+ temp.add(temp2);
1387
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1388
+ }
1389
+
1390
+ if (spring.isHandle)
1391
+ continue;
1392
+
1393
+ //if (scale < spring.restLength)
1394
+ scale += spring.restLength;
1395
+ count++;
1396
+ }
1397
+ gl.glEnd();
1398
+
1399
+ if (count == 0)
1400
+ scale = 0.01;
1401
+ else
1402
+ scale /= count * 3;
1403
+
1404
+ //scale = 0.25;
1405
+
1406
+ if (mesh.ShowInfo())
1407
+ {
1408
+ gl.glLineWidth(4);
1409
+ for (int s=0; s<Phys.allNodes.size(); s++)
1410
+ {
1411
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1412
+ if (node.mass == 0)
1413
+ continue;
1414
+
1415
+ int i = node.springs==null?-1:node.springs.size();
1416
+ gl.glColor3f((i>>2)&1,(i>>1)&1,i&1);
1417
+ //temp.set(node.springForce.x, node.springForce.y, node.springForce.z);
1418
+ //temp.normalize();
1419
+ //gl.glColor3d((temp.x+1)/2, (temp.y+1)/2, (temp.z+1)/2);
1420
+ gl.glBegin(gl.GL_LINES);
1421
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1422
+ //gl.glVertex3d(node.position.x + node.normal.x*scale, node.position.y + node.normal.y*scale, node.position.z + node.normal.z*scale);
1423
+ gl.glVertex3d(node.position.x + mesh.bRep.GetVertex(s).norm.x*scale,
1424
+ node.position.y + mesh.bRep.GetVertex(s).norm.y*scale,
1425
+ node.position.z + mesh.bRep.GetVertex(s).norm.z*scale);
1426
+ gl.glEnd();
1427
+ }
1428
+
1429
+ gl.glLineWidth(8);
1430
+ for (int s=0; s<Phys.allNodes.size(); s++)
1431
+ {
1432
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1433
+
1434
+ if (node.springs != null)
1435
+ {
1436
+ for (int i=0; i<node.springs.size(); i+=1)
1437
+ {
1438
+ cSpring.DynamicNode f = node.springs.get(i).GetOther(node);
1439
+
1440
+ int c = i+1;
1441
+ // c = node.springs.get(i).nbcopies;
1442
+
1443
+ gl.glColor3f((c>>2)&1,(c>>1)&1,c&1);
1444
+ gl.glBegin(gl.GL_LINES);
1445
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1446
+ 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);
1447
+ gl.glEnd();
1448
+ }
1449
+ }
1450
+ }
1451
+
1452
+ gl.glLineWidth(1);
1453
+ }
1454
+
1455
+ gl.glEnable(gl.GL_LIGHTING);
1456
+ }
1457
+
10621458 /// INTERFACE
1459
+
1460
+ public void StartTriangles()
1461
+ {
1462
+ javax.media.opengl.GL gl = GetGL();
1463
+ gl.glBegin(gl.GL_TRIANGLES);
1464
+ }
1465
+
1466
+ public void EndTriangles()
1467
+ {
1468
+ GetGL().glEnd();
1469
+ }
1470
+
1471
+ void drawVertex(javax.media.opengl.GL gl, Vertex pv, boolean flipV, boolean selectmode)
1472
+ {
1473
+ if (!selectmode)
1474
+ {
1475
+ gl.glNormal3f((float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
1476
+ gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
1477
+
1478
+ if (flipV)
1479
+ gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
1480
+ else
1481
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1482
+ }
1483
+
1484
+ gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
1485
+ }
10631486
10641487 void SetColor(Object3D obj, Vertex p0)
10651488 {
....@@ -1238,7 +1661,7 @@
12381661 // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
12391662 }
12401663
1241
- void DrawMaterial(cMaterial material, boolean selected)
1664
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
12421665 {
12431666 CameraPane display = this;
12441667 //new Exception().printStackTrace();
....@@ -1254,18 +1677,18 @@
12541677 //col.getColorComponents(ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB), CameraPane.modelParams0);
12551678 if (!material.multiply)
12561679 {
1257
- display.color = color;
1680
+ display.color = material.color;
12581681 display.saturation = material.modulation;
12591682 }
12601683 else
12611684 {
1262
- display.color *= color*2;
1685
+ display.color *= material.color*2;
12631686 display.saturation *= material.modulation*2;
12641687 }
12651688
12661689 cColor.HSBtoRGB(display.color, display.saturation, 1, display.modelParams0);
12671690
1268
- float[] colorV = GrafreeD.colorV;
1691
+ float[] colorV = Grafreed.colorV;
12691692
12701693 /**/
12711694 if (display.DrawMode() == display.DEFAULT) // && display.RENDERPROGRAM == 0)
....@@ -1273,7 +1696,7 @@
12731696 colorV[0] = display.modelParams0[0] * material.diffuse;
12741697 colorV[1] = display.modelParams0[1] * material.diffuse;
12751698 colorV[2] = display.modelParams0[2] * material.diffuse;
1276
- colorV[3] = material.opacity;
1699
+ colorV[3] = 1; // material.opacity;
12771700
12781701 gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
12791702 //System.out.println("Opacity = " + opacity);
....@@ -1381,9 +1804,9 @@
13811804 display.modelParams7[2] = 0;
13821805 display.modelParams7[3] = 0;
13831806
1384
- display.modelParams6[0] = 100; // criss de bug de bump
1807
+ //display.modelParams6[0] = 100; // criss de bug de bump
13851808
1386
- Object3D.cVector2[] extparams = display.vector2buffer;
1809
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
13871810 if (extparams != null && extparams.length > 0 && extparams[0] != null)
13881811 {
13891812 display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
....@@ -1525,7 +1948,7 @@
15251948 void PushMatrix(double[][] matrix)
15261949 {
15271950 // GrafreeD.tracein(matrix);
1528
- PushMatrix(matrix,1);
1951
+ PushMatrix(matrix, 1);
15291952 }
15301953
15311954 void PushMatrix()
....@@ -1679,7 +2102,7 @@
16792102 //System.err.println("Oeil on");
16802103 OEIL = true;
16812104 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
1682
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2105
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
16832106 //pingthread.StepToTarget(true);
16842107 }
16852108
....@@ -1777,7 +2200,7 @@
17772200 System.err.println("LIVE = " + Globals.isLIVE());
17782201
17792202 if (!Globals.isLIVE()) // save sound
1780
- GrafreeD.savesound = true; // wav.save();
2203
+ Grafreed.savesound = true; // wav.save();
17812204 // else
17822205 repaint(); // start loop // may 2013
17832206 }
....@@ -1810,6 +2233,11 @@
18102233 public void ToggleBoxMode()
18112234 {
18122235 BOXMODE ^= true;
2236
+ }
2237
+
2238
+ public void ToggleZoomBoxMode()
2239
+ {
2240
+ ZOOMBOXMODE ^= true;
18132241 }
18142242
18152243 public void ToggleSmoothFocus()
....@@ -1889,7 +2317,7 @@
18892317
18902318 void ToggleDebug()
18912319 {
1892
- DEBUG ^= true;
2320
+ Globals.DEBUG ^= true;
18932321 }
18942322
18952323 void ToggleLookAt()
....@@ -1897,9 +2325,9 @@
18972325 LOOKAT ^= true;
18982326 }
18992327
1900
- void ToggleRandom()
2328
+ void ToggleSwitch()
19012329 {
1902
- RANDOM ^= true;
2330
+ SWITCH ^= true;
19032331 }
19042332
19052333 void ToggleHandles()
....@@ -1907,10 +2335,17 @@
19072335 HANDLES ^= true;
19082336 }
19092337
2338
+ Object3D paintFolder;
2339
+
19102340 void TogglePaint()
19112341 {
19122342 PAINTMODE ^= true;
19132343 paintcount = 0;
2344
+
2345
+ if (PAINTMODE)
2346
+ {
2347
+ paintFolder = GetFolder();
2348
+ }
19142349 }
19152350
19162351 void SwapCamera(int a, int b)
....@@ -2006,7 +2441,22 @@
20062441 {
20072442 return currentGL;
20082443 }
2009
-
2444
+
2445
+ static private BufferedImage CreateBim(TextureData texturedata)
2446
+ {
2447
+ Grafreed.Assert(texturedata != null);
2448
+
2449
+ int width = texturedata.getWidth();
2450
+ int height = texturedata.getHeight();
2451
+
2452
+ Buffer buffer = texturedata.getBuffer();
2453
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2454
+
2455
+ byte[] bytes = bytebuf.array();
2456
+
2457
+ return CreateBim(bytes, width, height);
2458
+ }
2459
+
20102460 /**/
20112461 class CacheTexture
20122462 {
....@@ -2015,28 +2465,31 @@
20152465
20162466 int resolution;
20172467
2018
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2468
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
20192469 {
2020
- texture = tex;
2470
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2471
+ texturedata = texdata;
20212472 resolution = res;
20222473 }
20232474 }
20242475 /**/
20252476
20262477 // TEXTURE static Texture texture;
2027
- static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures
2028
- = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>();
2029
- static public java.util.Hashtable<String, String> usedtextures = new java.util.Hashtable<String, String>();
2478
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2479
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2480
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2481
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2482
+
20302483 int pigmentdepth = 0;
20312484 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
20322485 int bumpdepth = 0;
20332486 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
20342487 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
20352488 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2036
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2489
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
20372490 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
20382491
2039
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2492
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
20402493 {
20412494 TextureData texturedata = null;
20422495
....@@ -2055,13 +2508,34 @@
20552508 if (bump)
20562509 texturedata = ConvertBump(texturedata, false);
20572510
2058
- com.sun.opengl.util.texture.Texture texture =
2059
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2511
+// com.sun.opengl.util.texture.Texture texture =
2512
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
20602513
2061
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2062
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
2514
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2515
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
20632516
2064
- return texture;
2517
+ return texturedata;
2518
+ }
2519
+
2520
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2521
+ {
2522
+ TextureData texturedata = null;
2523
+
2524
+ try
2525
+ {
2526
+ texturedata =
2527
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2528
+ bim,
2529
+ true);
2530
+ } catch (Exception e)
2531
+ {
2532
+ throw new javax.media.opengl.GLException(e);
2533
+ }
2534
+
2535
+ if (bump)
2536
+ texturedata = ConvertBump(texturedata, false);
2537
+
2538
+ return texturedata;
20652539 }
20662540
20672541 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3134,6 +3608,8 @@
31343608
31353609 System.out.println("LOADING TEXTURE : " + name);
31363610
3611
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3612
+
31373613 //
31383614 if (false) // compressbit > 0)
31393615 {
....@@ -3838,6 +4314,7 @@
38384314
38394315 com.sun.opengl.util.texture.Texture CompressTexture2(String name)
38404316 {
4317
+ new Exception().printStackTrace();
38414318 System.exit(0);
38424319 com.sun.opengl.util.texture.Texture texture = null;
38434320
....@@ -7531,7 +8008,7 @@
75318008 String pigment = Object3D.GetPigment(tex);
75328009 String bump = Object3D.GetBump(tex);
75338010
7534
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8011
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
75358012 {
75368013 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
75378014 // System.out.println("; bump = " + bump);
....@@ -7546,11 +8023,69 @@
75468023 pigment = null;
75478024 }
75488025
7549
- ReleaseTexture(bump, true);
7550
- ReleaseTexture(pigment, false);
8026
+ ReleaseTexture(tex, true);
8027
+ ReleaseTexture(tex, false);
75518028 }
75528029
7553
- void ReleaseTexture(String tex, boolean bump)
8030
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
8031
+ {
8032
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8033
+ {
8034
+ return;
8035
+ }
8036
+
8037
+ if (tex == null)
8038
+ {
8039
+ ReleaseTexture(null, false);
8040
+ return;
8041
+ }
8042
+
8043
+ String pigment = Object3D.GetPigment(tex);
8044
+
8045
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8046
+ {
8047
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8048
+ // System.out.println("; bump = " + bump);
8049
+ }
8050
+
8051
+ if (pigment.equals(""))
8052
+ {
8053
+ pigment = null;
8054
+ }
8055
+
8056
+ ReleaseTexture(tex, false);
8057
+ }
8058
+
8059
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
8060
+ {
8061
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8062
+ {
8063
+ return;
8064
+ }
8065
+
8066
+ if (tex == null)
8067
+ {
8068
+ ReleaseTexture(null, true);
8069
+ return;
8070
+ }
8071
+
8072
+ String bump = Object3D.GetBump(tex);
8073
+
8074
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8075
+ {
8076
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8077
+ // System.out.println("; bump = " + bump);
8078
+ }
8079
+
8080
+ if (bump.equals(""))
8081
+ {
8082
+ bump = null;
8083
+ }
8084
+
8085
+ ReleaseTexture(tex, true);
8086
+ }
8087
+
8088
+ void ReleaseTexture(cTexture tex, boolean bump)
75548089 {
75558090 if (// DrawMode() != 0 || /*tex == null ||*/
75568091 ambientOcclusion ) // || !textureon)
....@@ -7561,7 +8096,7 @@
75618096 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
75628097
75638098 if (tex != null)
7564
- texture = textures.get(tex);
8099
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
75658100
75668101 // //assert( texture != null );
75678102 // if (texture == null)
....@@ -7653,7 +8188,55 @@
76538188 }
76548189 }
76558190
7656
- /*boolean*/ public void BindTextures(cTexture tex, int resolution) // INTERFACE
8191
+ /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
8192
+ {
8193
+// if (// DrawMode() != 0 || /*tex == null ||*/
8194
+// ambientOcclusion ) // || !textureon)
8195
+// {
8196
+// return; // false;
8197
+// }
8198
+//
8199
+// if (tex == null)
8200
+// {
8201
+// BindTexture(null,false,resolution);
8202
+// BindTexture(null,true,resolution);
8203
+// return;
8204
+// }
8205
+//
8206
+// String pigment = Object3D.GetPigment(tex);
8207
+// String bump = Object3D.GetBump(tex);
8208
+//
8209
+// usedtextures.add(pigment);
8210
+// usedtextures.add(bump);
8211
+//
8212
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8213
+// {
8214
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8215
+// // System.out.println("; bump = " + bump);
8216
+// }
8217
+//
8218
+// if (bump.equals(""))
8219
+// {
8220
+// bump = null;
8221
+// }
8222
+// if (pigment.equals(""))
8223
+// {
8224
+// pigment = null;
8225
+// }
8226
+//
8227
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8228
+// BindTexture(pigment, false, resolution);
8229
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8230
+// BindTexture(bump, true, resolution);
8231
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8232
+//
8233
+// return; // true;
8234
+
8235
+ BindPigmentTexture(tex, resolution);
8236
+ BindBumpTexture(tex, resolution);
8237
+ }
8238
+
8239
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
76578240 {
76588241 if (// DrawMode() != 0 || /*tex == null ||*/
76598242 ambientOcclusion ) // || !textureon)
....@@ -7664,17 +8247,47 @@
76648247 if (tex == null)
76658248 {
76668249 BindTexture(null,false,resolution);
7667
- BindTexture(null,true,resolution);
76688250 return;
76698251 }
76708252
76718253 String pigment = Object3D.GetPigment(tex);
8254
+
8255
+ usedtextures.add(tex);
8256
+
8257
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8258
+ {
8259
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8260
+ // System.out.println("; bump = " + bump);
8261
+ }
8262
+
8263
+ if (pigment.equals(""))
8264
+ {
8265
+ pigment = null;
8266
+ }
8267
+
8268
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8269
+ BindTexture(tex, false, resolution);
8270
+ }
8271
+
8272
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8273
+ {
8274
+ if (// DrawMode() != 0 || /*tex == null ||*/
8275
+ ambientOcclusion ) // || !textureon)
8276
+ {
8277
+ return; // false;
8278
+ }
8279
+
8280
+ if (tex == null)
8281
+ {
8282
+ BindTexture(null,true,resolution);
8283
+ return;
8284
+ }
8285
+
76728286 String bump = Object3D.GetBump(tex);
76738287
7674
- usedtextures.put(pigment, pigment);
7675
- usedtextures.put(bump, bump);
8288
+ usedtextures.add(tex);
76768289
7677
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8290
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
76788291 {
76798292 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
76808293 // System.out.println("; bump = " + bump);
....@@ -7684,43 +8297,94 @@
76848297 {
76858298 bump = null;
76868299 }
7687
- if (pigment.equals(""))
7688
- {
7689
- pigment = null;
7690
- }
76918300
7692
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
7693
- BindTexture(pigment, false, resolution);
76948301 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
7695
- BindTexture(bump, true, resolution);
8302
+ BindTexture(tex, true, resolution);
76968303 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
7697
-
7698
- return; // true;
76998304 }
77008305
7701
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution)
8306
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8307
+
8308
+ private boolean FileExists(String tex)
77028309 {
7703
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8310
+ if (missingTextures.contains(tex))
8311
+ {
8312
+ return false;
8313
+ }
8314
+
8315
+ boolean fileExists = new File(tex).exists();
8316
+
8317
+ if (!fileExists)
8318
+ {
8319
+ // If file exists, the "new File()" is not executed sgain
8320
+ missingTextures.add(tex);
8321
+ }
8322
+
8323
+ return fileExists;
8324
+ }
8325
+
8326
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
8327
+ {
8328
+ CacheTexture texturecache = null;
77048329
77058330 if (tex != null)
77068331 {
7707
- String texname = tex;
8332
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8333
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
77088334
7709
- String[] split = tex.split("Textures");
7710
- if (split.length > 1)
7711
- texname = "/Users/nbriere/Textures" + split[split.length-1];
7712
- else
7713
- if (!texname.startsWith("/"))
7714
- texname = "/Users/nbriere/Textures/" + texname;
8335
+ if (texname.equals("") && texdata == null)
8336
+ {
8337
+ return null;
8338
+ }
8339
+
8340
+ String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
8341
+
8342
+// String[] split = tex.split("Textures");
8343
+// if (split.length > 1)
8344
+// texname = "/Users/nbriere/Textures" + split[split.length-1];
8345
+// else
8346
+// if (!texname.startsWith("/"))
8347
+// texname = "/Users/nbriere/Textures/" + texname;
8348
+ if (!FileExists(texname))
8349
+ {
8350
+ texname = fallbackTextureName;
8351
+ }
77158352
77168353 if (CACHETEXTURE)
7717
- texture = textures.get(texname); // TEXTURE CACHE
7718
-
7719
- TextureData texturedata = null;
7720
-
7721
- if (texture == null || texture.resolution < resolution)
77228354 {
7723
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8355
+ if (texdata == null)
8356
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8357
+ else
8358
+ texturecache = bimtextures.get(texdata);
8359
+ }
8360
+
8361
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8362
+ {
8363
+ TextureData texturedata = null;
8364
+
8365
+ if (texdata != null && textureon)
8366
+ {
8367
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8368
+
8369
+ try
8370
+ {
8371
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8372
+ }
8373
+ catch (Exception e)
8374
+ {
8375
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8376
+ }
8377
+
8378
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8379
+ bimtextures.put(texdata, texturecache);
8380
+
8381
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8382
+
8383
+ //Object bim2 = CreateBim(texturecache.texturedata);
8384
+ //bim2 = bim;
8385
+ }
8386
+ else
8387
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
77248388 {
77258389 assert(!bump);
77268390 // if (bump)
....@@ -7731,19 +8395,23 @@
77318395 // }
77328396 // else
77338397 // {
7734
- texture = textures.get(tex);
7735
- if (texture == null)
8398
+ // texturecache = textures.get(texname); // suspicious
8399
+ if (texturecache == null)
77368400 {
7737
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8401
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
77388402 }
8403
+ else
8404
+ new Exception().printStackTrace();
77398405 // }
77408406 } else
7741
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8407
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
77428408 {
77438409 assert(bump);
7744
- texture = textures.get(tex);
7745
- if (texture == null)
7746
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8410
+ // texturecache = textures.get(texname); // suspicious
8411
+ if (texturecache == null)
8412
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8413
+ else
8414
+ new Exception().printStackTrace();
77478415 } else
77488416 {
77498417 //if (tex.equals("IMMORTAL"))
....@@ -7751,11 +8419,13 @@
77518419 // texture = GetResourceTexture("default.png");
77528420 //} else
77538421 //{
7754
- if (tex.equals("WHITE_NOISE"))
8422
+ if (texname.endsWith("WHITE_NOISE"))
77558423 {
7756
- texture = textures.get(tex);
7757
- if (texture == null)
7758
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8424
+ // texturecache = textures.get(texname); // suspicious
8425
+ if (texturecache == null)
8426
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8427
+ else
8428
+ new Exception().printStackTrace();
77598429 } else
77608430 {
77618431 if (textureon)
....@@ -7780,7 +8450,7 @@
77808450 }
77818451
77828452 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
7783
- if (!new File(cachename).exists())
8453
+ if (!FileExists(cachename))
77848454 cachename = texname;
77858455 else
77868456 processbump = false; // don't process bump map again
....@@ -7802,7 +8472,7 @@
78028472 }
78038473
78048474 cachename = texname.substring(0, texname.length()-4)+ext+".png";
7805
- if (!new File(cachename).exists())
8475
+ if (!FileExists(cachename))
78068476 cachename = texname;
78078477 else
78088478 processbump = false; // don't process bump map again
....@@ -7811,20 +8481,22 @@
78118481 texturedata = GetFileTexture(cachename, processbump, resolution);
78128482
78138483
7814
- if (texturedata != null)
7815
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8484
+ if (texturedata == null)
8485
+ throw new Exception();
8486
+
8487
+ texturecache = new CacheTexture(texturedata,resolution);
78168488 //texture = GetTexture(tex, bump);
78178489 }
78188490 }
78198491 //}
78208492 }
78218493
7822
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8494
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
78238495 {
78248496 //return false;
78258497
78268498 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
7827
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8499
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
78288500 {
78298501 // String ext = "_highres";
78308502 // if (REDUCETEXTURE)
....@@ -7841,52 +8513,17 @@
78418513 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
78428514 if (!cachefile.exists())
78438515 {
7844
- // cache to disk
7845
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
7846
- //buffers[0].
7847
-
7848
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
7849
- int[] pixels = new int[bytebuf.capacity()/3];
7850
-
7851
- // squared size heuristic...
7852
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8516
+ //if (texturedata.getWidth() == texturedata.getHeight())
78538517 {
7854
- for (int i=pixels.length; --i>=0;)
7855
- {
7856
- int i3 = i*3;
7857
- pixels[i] = 0xFF;
7858
- pixels[i] <<= 8;
7859
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
7860
- pixels[i] <<= 8;
7861
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
7862
- pixels[i] <<= 8;
7863
- pixels[i] |= bytebuf.get(i3) & 0xFF;
7864
- }
7865
-
7866
- /*
7867
- int r=0,g=0,b=0,a=0;
7868
- for (int i=0; i<width; i++)
7869
- for (int j=0; j<height; j++)
7870
- {
7871
- int index = j*width+i;
7872
- int p = pixels[index];
7873
- a = ((p>>24) & 0xFF);
7874
- r = ((p>>16) & 0xFF);
7875
- g = ((p>>8) & 0xFF);
7876
- b = (p & 0xFF);
7877
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
7878
- }
7879
- /**/
7880
- int width = (int)Math.sqrt(pixels.length); // squared
7881
- int height = width;
7882
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
7883
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8518
+ BufferedImage rendImage = CreateBim(texturedata);
8519
+
78848520 ImageWriter writer = null;
78858521 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
78868522 if (iter.hasNext()) {
78878523 writer = (ImageWriter)iter.next();
78888524 }
7889
- float compressionQuality = 0.9f;
8525
+
8526
+ float compressionQuality = 0.85f;
78908527 try
78918528 {
78928529 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -7903,18 +8540,20 @@
79038540 }
79048541 }
79058542 }
7906
-
8543
+
8544
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8545
+
79078546 //System.out.println("Texture = " + tex);
7908
- if (textures.containsKey(texname))
8547
+ if (textures.containsKey(tex))
79098548 {
7910
- CacheTexture thetex = textures.get(texname);
8549
+ CacheTexture thetex = textures.get(tex);
79118550 thetex.texture.disable();
79128551 thetex.texture.dispose();
7913
- textures.remove(texname);
8552
+ textures.remove(tex);
79148553 }
79158554
7916
- texture.texturedata = texturedata;
7917
- textures.put(texname, texture);
8555
+ //texture.texturedata = texturedata;
8556
+ textures.put(tex, texturecache);
79188557
79198558 // newtex = true;
79208559 }
....@@ -7930,10 +8569,44 @@
79308569 }
79318570 }
79328571
7933
- return texture;
8572
+ return texturecache;
79348573 }
79358574
7936
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution)
8575
+ static void EmbedTextures(cTexture tex)
8576
+ {
8577
+ if (tex.pigmentdata == null)
8578
+ {
8579
+ //String texname = Object3D.GetPigment(tex);
8580
+
8581
+ CacheTexture texturecache = texturepigment.get(tex);
8582
+
8583
+ if (texturecache != null)
8584
+ {
8585
+ tex.pw = texturecache.texturedata.getWidth();
8586
+ tex.ph = texturecache.texturedata.getHeight();
8587
+ tex.pigmentdata = //CompressJPEG(CreateBim
8588
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8589
+ ;
8590
+ //, tex.pw, tex.ph), 0.5f);
8591
+ }
8592
+ }
8593
+
8594
+ if (tex.bumpdata == null)
8595
+ {
8596
+ //String texname = Object3D.GetBump(tex);
8597
+
8598
+ CacheTexture texturecache = texturebump.get(tex);
8599
+
8600
+ if (texturecache != null)
8601
+ {
8602
+ tex.bw = texturecache.texturedata.getWidth();
8603
+ tex.bh = texturecache.texturedata.getHeight();
8604
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8605
+ }
8606
+ }
8607
+ }
8608
+
8609
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
79378610 {
79388611 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
79398612
....@@ -7951,21 +8624,21 @@
79518624 return texture!=null?texture.texture:null;
79528625 }
79538626
7954
- public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution)
8627
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
79558628 {
79568629 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
79578630
79588631 return texture!=null?texture.texturedata:null;
79598632 }
79608633
7961
- boolean BindTexture(String tex, boolean bump, int resolution)
8634
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
79628635 {
79638636 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
79648637 {
79658638 return false;
79668639 }
79678640
7968
- boolean newtex = false;
8641
+ //boolean newtex = false;
79698642
79708643 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
79718644
....@@ -7997,9 +8670,75 @@
79978670 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
79988671 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
79998672
8000
- return newtex;
8673
+ return true; // Warning: not used.
80018674 }
80028675
8676
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8677
+ {
8678
+ try
8679
+ {
8680
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8681
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8682
+ ImageWriter writer = writers.next();
8683
+
8684
+ ImageWriteParam param = writer.getDefaultWriteParam();
8685
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8686
+ param.setCompressionQuality(quality);
8687
+
8688
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8689
+ writer.setOutput(ios);
8690
+ writer.write(null, new IIOImage(image, null, null), param);
8691
+
8692
+ byte[] data = baos.toByteArray();
8693
+ writer.dispose();
8694
+ return data;
8695
+ }
8696
+ catch (Exception e)
8697
+ {
8698
+ e.printStackTrace();
8699
+ return null;
8700
+ }
8701
+ }
8702
+
8703
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8704
+ {
8705
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8706
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8707
+ ImageReader reader = writers.next();
8708
+
8709
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8710
+
8711
+ ImageReadParam param = reader.getDefaultReadParam();
8712
+ param.setDestination(bim);
8713
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8714
+
8715
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8716
+ reader.setInput(ios);
8717
+ BufferedImage bim2 = reader.read(0, param);
8718
+ reader.dispose();
8719
+
8720
+// WritableRaster raster = bim2.getRaster();
8721
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8722
+// byte[] bytes = data.getData();
8723
+//
8724
+// int[] pixels = new int[bytes.length/3];
8725
+// for (int i=pixels.length; --i>=0;)
8726
+// {
8727
+// int i3 = i*3;
8728
+// pixels[i] = 0xFF;
8729
+// pixels[i] <<= 8;
8730
+// pixels[i] |= bytes[i3+2] & 0xFF;
8731
+// pixels[i] <<= 8;
8732
+// pixels[i] |= bytes[i3+1] & 0xFF;
8733
+// pixels[i] <<= 8;
8734
+// pixels[i] |= bytes[i3] & 0xFF;
8735
+// }
8736
+//
8737
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8738
+
8739
+ return bim;
8740
+ }
8741
+
80038742 ShadowBuffer shadowPBuf;
80048743 AntialiasBuffer antialiasPBuf;
80058744 int MAXSTACK;
....@@ -8835,11 +9574,35 @@
88359574 jy8[3] = 0.5f;
88369575 }
88379576
8838
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9577
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
88399578 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
88409579 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
88419580 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
88429581
9582
+ void ResetOptions()
9583
+ {
9584
+ options1[0] = 100;
9585
+ options1[1] = 0.025f;
9586
+ options1[2] = 0.01f;
9587
+ options1[3] = 0;
9588
+ options1[4] = 0;
9589
+
9590
+ options2[0] = 0;
9591
+ options2[1] = 0.75f;
9592
+ options2[2] = 0;
9593
+ options2[3] = 0;
9594
+
9595
+ options3[0] = 1;
9596
+ options3[1] = 1;
9597
+ options3[2] = 1;
9598
+ options3[3] = 0;
9599
+
9600
+ options4[0] = 1;
9601
+ options4[1] = 0;
9602
+ options4[2] = 1;
9603
+ options4[3] = 0;
9604
+ }
9605
+
88439606 static int imagecount = 0; // movie generation
88449607
88459608 static int jitter = 0;
....@@ -8935,8 +9698,8 @@
89359698 assert (parentcam != renderCamera);
89369699
89379700 if (renderCamera != lightCamera)
8938
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8939
- LA.matConcat(matrix, parentcam.toParent, matrix);
9701
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9702
+ LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
89409703
89419704 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
89429705
....@@ -8951,8 +9714,8 @@
89519714 LA.matCopy(renderCamera.fromScreen, matrix);
89529715
89539716 if (renderCamera != lightCamera)
8954
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8955
- LA.matConcat(parentcam.fromParent, matrix, matrix);
9717
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9718
+ LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
89569719
89579720 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
89589721
....@@ -9024,7 +9787,7 @@
90249787 //gl.glFlush();
90259788 gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE);
90269789
9027
- if (ANIMATION && ABORTED)
9790
+ if (Globals.ANIMATION && ABORTED)
90289791 {
90299792 System.err.println(" ABORTED FRAME");
90309793 break;
....@@ -9054,7 +9817,7 @@
90549817 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
90559818
90569819 // save image
9057
- if (ANIMATION && !ABORTED)
9820
+ if (Globals.ANIMATION && !ABORTED)
90589821 {
90599822 VPwidth = viewport[2];
90609823 VPheight = viewport[3];
....@@ -9165,11 +9928,11 @@
91659928
91669929 // imagecount++;
91679930
9168
- String fullname = filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
9931
+ String fullname = Globals.filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
91699932
91709933 if (!BOXMODE)
91719934 {
9172
- System.out.println("image: " + fullname + " (wav cursor=" + (GrafreeD.wav.cursor / 735 / 4) + ")");
9935
+ System.out.println("image: " + fullname + " (wav cursor=" + (Grafreed.wav.cursor / 735 / 4) + ")");
91739936 }
91749937
91759938 if (!BOXMODE)
....@@ -9207,7 +9970,7 @@
92079970 ABORTED = false;
92089971 }
92099972 else
9210
- GrafreeD.wav.cursor += 735 * ACSIZE;
9973
+ Grafreed.wav.cursor += 735 * ACSIZE;
92119974
92129975 if (false)
92139976 {
....@@ -9870,11 +10633,11 @@
987010633
987110634 public void display(GLAutoDrawable drawable)
987210635 {
9873
- if (GrafreeD.savesound && GrafreeD.hassound)
10636
+ if (Grafreed.savesound && Grafreed.hassound)
987410637 {
9875
- GrafreeD.wav.save();
9876
- GrafreeD.savesound = false;
9877
- GrafreeD.hassound = false;
10638
+ Grafreed.wav.save();
10639
+ Grafreed.savesound = false;
10640
+ Grafreed.hassound = false;
987810641 }
987910642 // if (DEBUG_SELECTION)
988010643 // {
....@@ -9950,6 +10713,7 @@
995010713 ANTIALIAS = 0;
995110714 //System.out.println("RESTART");
995210715 AAtimer.restart();
10716
+ Globals.TIMERRUNNING = true;
995310717 }
995410718 }
995510719 }
....@@ -10004,7 +10768,7 @@
1000410768 Object3D theobject = object;
1000510769 Object3D theparent = object.parent;
1000610770 object.parent = null;
10007
- object = (Object3D)GrafreeD.clone(object);
10771
+ object = (Object3D)Grafreed.clone(object);
1000810772 object.Stripify();
1000910773 if (theobject.selection == null || theobject.selection.Size() == 0)
1001010774 theobject.PreprocessOcclusion(this);
....@@ -10017,13 +10781,14 @@
1001710781 ambientOcclusion = false;
1001810782 }
1001910783
10020
- if (Globals.lighttouched && DrawMode() == DEFAULT && !lightMode) // && !FROZEN)
10784
+ if (//Globals.lighttouched &&
10785
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1002110786 {
1002210787 //if (RENDERSHADOW) // ?
1002310788 if (!IsFrozen())
1002410789 {
1002510790 // dec 2012
10026
- if (!ambientOcclusion && !(!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0))
10791
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
1002710792 {
1002810793 Globals.framecount++;
1002910794 shadowbuffer.display();
....@@ -10150,8 +10915,8 @@
1015010915
1015110916 // if (parentcam != renderCamera) // not a light
1015210917 if (cam != lightCamera)
10153
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10154
- LA.matConcat(matrix, parentcam.toParent, matrix);
10918
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10919
+ LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
1015510920
1015610921 for (int j = 0; j < 4; j++)
1015710922 {
....@@ -10165,8 +10930,8 @@
1016510930
1016610931 // if (parentcam != renderCamera) // not a light
1016710932 if (cam != lightCamera)
10168
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10169
- LA.matConcat(parentcam.fromParent, matrix, matrix);
10933
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10934
+ LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
1017010935
1017110936 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1017210937
....@@ -10425,7 +11190,16 @@
1042511190 // Bump noise
1042611191 gl.glActiveTexture(GL.GL_TEXTURE6);
1042711192 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
10428
- BindTexture(NOISE_TEXTURE, false, 2);
11193
+
11194
+ try
11195
+ {
11196
+ BindTexture(NOISE_TEXTURE, false, 2);
11197
+ }
11198
+ catch (Exception e)
11199
+ {
11200
+ System.err.println("FAILED: " + NOISE_TEXTURE);
11201
+ }
11202
+
1042911203
1043011204 gl.glActiveTexture(GL.GL_TEXTURE0);
1043111205 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -10448,9 +11222,9 @@
1044811222
1044911223 gl.glMatrixMode(GL.GL_MODELVIEW);
1045011224
10451
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10452
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10453
-//gl.glEnable(gl.GL_MULTISAMPLE);
11225
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11226
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11227
+gl.glEnable(gl.GL_MULTISAMPLE);
1045411228 } else
1045511229 {
1045611230 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -10461,7 +11235,7 @@
1046111235 //System.out.println("BLENDING ON");
1046211236 gl.glEnable(GL.GL_BLEND);
1046311237 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
10464
-
11238
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1046511239 gl.glMatrixMode(gl.GL_PROJECTION);
1046611240 gl.glLoadIdentity();
1046711241
....@@ -10550,8 +11324,8 @@
1055011324 System.err.println("parentcam != renderCamera");
1055111325
1055211326 // if (cam != lightCamera)
10553
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10554
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11327
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11328
+ LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
1055511329 }
1055611330
1055711331 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -10572,8 +11346,8 @@
1057211346 if (true) // TODO
1057311347 {
1057411348 if (cam != lightCamera)
10575
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10576
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11349
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11350
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
1057711351 }
1057811352
1057911353 LA.xformPos(light0, cam.toScreen, light0);
....@@ -10710,7 +11484,7 @@
1071011484 }
1071111485 }
1071211486
10713
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11487
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1071411488 {
1071511489 //gl.glDepthFunc(GL.GL_LEQUAL);
1071611490 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -10718,24 +11492,21 @@
1071811492
1071911493 boolean texon = textureon;
1072011494
10721
- if (RENDERPROGRAM > 0)
10722
- {
10723
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
10724
- textureon = false;
10725
- }
11495
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11496
+ textureon = false;
11497
+
1072611498 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1072711499 //System.out.println("ALLO");
1072811500 gl.glColorMask(false, false, false, false);
1072911501 DrawObject(gl);
10730
- if (RENDERPROGRAM > 0)
10731
- {
10732
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
10733
- textureon = texon;
10734
- }
11502
+
11503
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11504
+ textureon = texon;
11505
+
1073511506 gl.glColorMask(true, true, true, true);
1073611507
1073711508 gl.glDepthFunc(GL.GL_EQUAL);
10738
- //gl.glDepthMask(false);
11509
+ gl.glDepthMask(false);
1073911510 }
1074011511
1074111512 if (false) // DrawMode() == SHADOW)
....@@ -10889,8 +11660,14 @@
1088911660 {
1089011661 renderpass++;
1089111662 // System.out.println("Draw object... ");
11663
+ STEP = 1;
1089211664 if (FAST) // in case there is no script
10893
- STEP = 16;
11665
+ STEP = 8;
11666
+
11667
+ if (CURRENTANTIALIAS == 0 || ACSIZE == 1)
11668
+ {
11669
+ STEP *= 4;
11670
+ }
1089411671
1089511672 //object.FullInvariants();
1089611673
....@@ -10904,23 +11681,44 @@
1090411681 e.printStackTrace();
1090511682 }
1090611683
10907
- if (GrafreeD.RENDERME > 0)
10908
- GrafreeD.RENDERME--; // mechante magouille
11684
+ if (Grafreed.RENDERME > 0)
11685
+ Grafreed.RENDERME--; // mechante magouille
1090911686
1091011687 Globals.ONESTEP = false;
1091111688 }
1091211689
1091311690 static boolean zoomonce = false;
1091411691
11692
+ static void CreateSelectedPoint()
11693
+ {
11694
+ if (selectedpoint == null)
11695
+ {
11696
+ debugpointG = new Sphere();
11697
+ debugpointP = new Sphere();
11698
+ debugpointC = new Sphere();
11699
+ debugpointR = new Sphere();
11700
+
11701
+ selectedpoint = new Superellipsoid();
11702
+
11703
+ for (int i=0; i<8; i++)
11704
+ {
11705
+ debugpoints[i] = new Sphere();
11706
+ }
11707
+ }
11708
+ }
11709
+
1091511710 void DrawObject(GL gl, boolean draw)
1091611711 {
11712
+ // To clear camera values
11713
+ ResetOptions();
11714
+
1091711715 //System.out.println("DRAW OBJECT " + mouseDown);
1091811716 // DrawMode() = SELECTION;
1091911717 //GL gl = getGL();
1092011718 if ((TRACK || SHADOWTRACK) || zoomonce)
1092111719 {
1092211720 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
10923
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11721
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1092411722 pingthread.StepToTarget(true); // true);
1092511723 // zoomonce = false;
1092611724 }
....@@ -10975,7 +11773,14 @@
1097511773
1097611774 usedtextures.clear();
1097711775
10978
- BindTextures(DEFAULT_TEXTURES, 2);
11776
+ try
11777
+ {
11778
+ BindTextures(DEFAULT_TEXTURES, 2);
11779
+ }
11780
+ catch (Exception e)
11781
+ {
11782
+ System.err.println("FAILED: " + DEFAULT_TEXTURES);
11783
+ }
1097911784 }
1098011785 //System.out.println("--> " + stackdepth);
1098111786 // GrafreeD.traceon();
....@@ -10985,8 +11790,9 @@
1098511790
1098611791 if (DrawMode() == DEFAULT)
1098711792 {
10988
- if (DEBUG)
11793
+ if (Globals.DEBUG)
1098911794 {
11795
+ CreateSelectedPoint();
1099011796 float radius = 0.05f;
1099111797 if (selectedpoint.radius != radius)
1099211798 {
....@@ -11040,20 +11846,32 @@
1104011846 ReleaseTextures(DEFAULT_TEXTURES);
1104111847
1104211848 if (CLEANCACHE)
11043
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11849
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1104411850 {
11045
- String tex = e.nextElement();
11851
+ cTexture tex = e.nextElement();
1104611852
1104711853 // System.out.println("Texture --------- " + tex);
1104811854
11049
- if (tex.equals("WHITE_NOISE"))
11855
+ if (tex.equals("WHITE_NOISE:"))
1105011856 continue;
1105111857
11052
- if (!usedtextures.containsKey(tex))
11858
+ if (!usedtextures.contains(tex))
1105311859 {
11860
+ CacheTexture gettex = texturepigment.get(tex);
1105411861 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11055
- textures.get(tex).texture.dispose();
11056
- textures.remove(tex);
11862
+ if (gettex != null)
11863
+ {
11864
+ gettex.texture.dispose();
11865
+ texturepigment.remove(tex);
11866
+ }
11867
+
11868
+ gettex = texturebump.get(tex);
11869
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11870
+ if (gettex != null)
11871
+ {
11872
+ gettex.texture.dispose();
11873
+ texturebump.remove(tex);
11874
+ }
1105711875 }
1105811876 }
1105911877 }
....@@ -11066,7 +11884,14 @@
1106611884 if (checker != null && DrawMode() == DEFAULT)
1106711885 {
1106811886 //BindTexture(IMMORTAL_TEXTURE);
11069
- BindTextures(checker.GetTextures(), checker.texres);
11887
+ try
11888
+ {
11889
+ BindTextures(checker.GetTextures(), checker.texres);
11890
+ }
11891
+ catch (Exception e)
11892
+ {
11893
+ System.err.println("FAILED: " + checker.GetTextures());
11894
+ }
1107011895 // NEAREST
1107111896 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
1107211897 DrawChecker(gl);
....@@ -11148,7 +11973,7 @@
1114811973 return;
1114911974 }
1115011975
11151
- String string = obj.GetToolTip();
11976
+ String string = obj.toString(); //.GetToolTip();
1115211977
1115311978 GL gl = GetGL();
1115411979
....@@ -11465,8 +12290,8 @@
1146512290 //obj.TransformToWorld(light, light);
1146612291 for (int i = tp.size(); --i >= 0;)
1146712292 {
11468
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
11469
- LA.xformPos(light, tp.get(i).toParent, light);
12293
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12294
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1147012295 }
1147112296
1147212297
....@@ -11483,8 +12308,8 @@
1148312308 parentcam = cameras[0];
1148412309 }
1148512310
11486
- for (int count = parentcam.GetTransformCount(); --count>=0;)
11487
- LA.xformPos(light, parentcam.toParent, light); // may 2013
12311
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
12312
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1148812313
1148912314 LA.xformPos(light, renderCamera.toScreen, light);
1149012315
....@@ -11575,7 +12400,52 @@
1157512400 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1157612401
1157712402 String program =
12403
+ // Min shader
1157812404 "!!ARBfp1.0\n" +
12405
+ "PARAM zero123 = { 0.0, 1.0, 2.0, 1.25 };" +
12406
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12407
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12408
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12409
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12410
+ "TEMP temp;" +
12411
+ "TEMP light;" +
12412
+ "TEMP ndotl;" +
12413
+ "TEMP normal;" +
12414
+ "TEMP depth;" +
12415
+
12416
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12417
+
12418
+ "MOV light, state.light[0].position;" +
12419
+ "DP3 ndotl.x, light, normal;" +
12420
+
12421
+ // shadow
12422
+ "MOV temp, fragment.texcoord[1];" +
12423
+ TextureFetch("depth", "temp", "1") +
12424
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12425
+ "SLT temp.x, fragment.texcoord[1].z, depth.z;" +
12426
+
12427
+
12428
+ // No shadow when out of frustum
12429
+ //"SGE temp.y, depth.z, zero123.y;" +
12430
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12431
+
12432
+ "MUL ndotl.x, ndotl.x, temp.x;" +
12433
+ "MAX ndotl.x, ndotl.x, pow2.y;" +
12434
+
12435
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12436
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12437
+ "MUL temp, temp, ndotl.x;" +
12438
+
12439
+ "MUL temp, temp, zero123.z;" +
12440
+
12441
+ "MOV temp.w, zero123.y;" + // reset alpha
12442
+
12443
+ "MOV result.color, temp;" +
12444
+ "END";
12445
+
12446
+ String program2 =
12447
+ "!!ARBfp1.0\n" +
12448
+
1157912449 //"OPTION ARB_fragment_program_shadow;" +
1158012450 "PARAM light2cam0 = program.env[10];" +
1158112451 "PARAM light2cam1 = program.env[11];" +
....@@ -11690,8 +12560,7 @@
1169012560 "TEMP shininess;" +
1169112561 "\n" +
1169212562 "MOV texSamp, one;" +
11693
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
11694
-
12563
+
1169512564 "MOV mapgrid.x, one2048th.x;" +
1169612565 "MOV temp, fragment.texcoord[1];" +
1169712566 /*
....@@ -12096,10 +12965,10 @@
1209612965 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1209712966 "") +
1209812967
12099
- // display shadow only (bump == 0)
12968
+ // display shadow only (fakedepth == 0)
1210012969 "SUB temp.x, half.x, shadow.x;" +
12101
- "MOV temp.y, -params6.x;" +
12102
- "SLT temp.z, temp.y, zero.x;" +
12970
+ "MOV temp.y, -params5.z;" + // params6.x;" +
12971
+ "SLT temp.z, temp.y, -one2048th.x;" +
1210312972 "SUB temp.y, one.x, temp.z;" +
1210412973 "MUL temp.x, temp.x, temp.y;" +
1210512974 "KIL temp.x;" +
....@@ -12228,8 +13097,10 @@
1222813097 "MAX ndotl.x, ndotl.x, -ndotl.x;" +
1222913098
1223013099 "SUB temp.x, one.x, ndotl.x;" +
12231
- "ADD temp.x, temp.x, options2.z;" + // lightsheen
12232
- "ADD temp.y, one.y, options2.y;" + // sursurface
13100
+ // Tuning for default skin
13101
+ //"ADD temp.x, temp.x, options2.z;" + // lightsheen
13102
+ "MAD temp.x, options2.z, half.y, temp.x;" + // lightsheen
13103
+ "ADD temp.y, one.y, options2.y;" + // subsurface
1223313104 "MUL temp.x, temp.x, temp.y;" +
1223413105
1223513106 "MUL saturation, saturation, temp.xxxx;" +
....@@ -12428,7 +13299,7 @@
1242813299 //once = true;
1242913300 }
1243013301
12431
- System.out.print("Program #" + mode + "; length = " + program.length());
13302
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1243213303 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1243313304 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1243413305
....@@ -12526,20 +13397,20 @@
1252613397 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1252713398 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1252813399 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13400
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13401
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1252913402 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12530
- "SLT " + src + ".z, " + src + ".x, one.x;" +
12531
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12532
- "SLT " + src + ".z, " + src + ".y, one.x;" +
12533
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13403
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13404
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1253413405 //"SWZ buffer, temp, w,w,w,w;";
12535
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13406
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1253613407 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1253713408 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1253813409 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
12539
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13410
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1254013411
12541
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
12542
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13412
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13413
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1254313414 }
1254413415
1254513416 String Shadow(String depth, String shadow)
....@@ -12561,12 +13432,16 @@
1256113432
1256213433 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1256313434 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13435
+
13436
+ // Compare fragment depth in light space with shadowmap.
1256413437 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1256513438 "SGE temp.y, temp.x, zero.x;" +
12566
- "SUB " + shadow + ".y, one.x, temp.y;" +
13439
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13440
+
13441
+ // Reverse comparison
1256713442 "SUB temp.x, one.x, temp.x;" +
1256813443 "MUL " + shadow + ".x, temp.x, temp.y;" +
12569
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13444
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1257013445 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1257113446
1257213447 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -12580,6 +13455,10 @@
1258013455 // No shadow for backface
1258113456 "DP3 temp.x, normal, lightd;" +
1258213457 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13458
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13459
+
13460
+ // No shadow when out of frustum
13461
+ "SGE temp.x, " + depth + ".z, one.z;" +
1258313462 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1258413463 "";
1258513464 }
....@@ -12726,7 +13605,8 @@
1272613605 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1272713606 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1272813607 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
12729
- Object3D.cVector2[] vector2buffer;
13608
+
13609
+ //Object3D.cVector2[] vector2buffer;
1273013610
1273113611 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1273213612 // OUT : diff, spec
....@@ -12742,9 +13622,10 @@
1274213622 "DP3 " + dest + ".z," + "normals," + "eye;" +
1274313623 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1274413624 //"MOV " + dest + ".w," + "normal.z;" +
12745
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
12746
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
12747
- //"MOV " + dest + ".z," + "params2.w;" +
13625
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13626
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13627
+
13628
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1274813629 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1274913630 "RCP " + dest + ".w," + dest + ".w;" +
1275013631 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13138,7 +14019,7 @@
1313814019 public void mousePressed(MouseEvent e)
1313914020 {
1314014021 //System.out.println("mousePressed: " + e);
13141
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14022
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1314214023 }
1314314024
1314414025 static long prevtime = 0;
....@@ -13165,6 +14046,7 @@
1316514046
1316614047 //System.err.println("Dtime = " + Dtime + "; units = " + e.getUnitsToScroll() + "; ratio (units/ms) = " + ratio);
1316714048
14049
+ if (BUTTONLESSWHEEL)
1316814050 if (Math.abs(ratio) < 0.1 || Math.abs(Dtime) == 0) // < 30)
1316914051 {
1317014052 return;
....@@ -13173,7 +14055,7 @@
1317314055 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
1317414056
1317514057 // TIMER
13176
- if (!wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
14058
+ if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
1317714059 {
1317814060 keepboxmode = BOXMODE;
1317914061 keepsupport = SUPPORT;
....@@ -13213,8 +14095,8 @@
1321314095 // mode |= META;
1321414096 //}
1321514097
13216
- SetMouseMode(WHEEL | e.getModifiersEx());
13217
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14098
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14099
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1321814100 anchorX = ax;
1321914101 anchorY = ay;
1322014102 prevX = px;
....@@ -13248,6 +14130,7 @@
1324814130 else
1324914131 if (evt.getSource() == AAtimer)
1325014132 {
14133
+ Globals.TIMERRUNNING = false;
1325114134 if (mouseDown)
1325214135 {
1325314136 //new Exception().printStackTrace();
....@@ -13273,6 +14156,10 @@
1327314156 // LIVE = waslive;
1327414157 // wasliveok = true;
1327514158 // waslive = false;
14159
+
14160
+ // May 2019 Forget it:
14161
+ if (true)
14162
+ return;
1327614163
1327714164 // source == timer
1327814165 if (mouseDown)
....@@ -13303,7 +14190,7 @@
1330314190
1330414191 // fev 2014???
1330514192 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13306
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14193
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1330714194 pingthread.StepToTarget(true); // true);
1330814195 }
1330914196 // if (!LIVE)
....@@ -13312,12 +14199,13 @@
1331214199
1331314200 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1331414201
13315
- void clickStart(int x, int y, int modifiers)
14202
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1331614203 {
1331714204 if (!wasliveok)
1331814205 return;
1331914206
1332014207 AAtimer.restart(); //
14208
+ Globals.TIMERRUNNING = true;
1332114209
1332214210 // waslive = LIVE;
1332314211 // LIVE = false;
....@@ -13329,7 +14217,7 @@
1332914217 // touched = true; // main DL
1333014218 if (isRenderer)
1333114219 {
13332
- SetMouseMode(modifiers);
14220
+ SetMouseMode(modifiers, modifiersex);
1333314221 }
1333414222
1333514223 selectX = anchorX = x;
....@@ -13342,7 +14230,7 @@
1334214230 clicked = true;
1334314231 hold = false;
1334414232
13345
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14233
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1334614234 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1334714235 {
1334814236 // System.out.println("RESTART II " + modifiers);
....@@ -13367,14 +14255,15 @@
1336714255 drag = false;
1336814256 //System.out.println("Mouse DOWN");
1336914257 editObj = false;
13370
- ClickInfo info = new ClickInfo();
13371
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
13372
- info.pane = this;
13373
- info.camera = renderCamera;
13374
- info.x = x;
13375
- info.y = y;
13376
- info.modifiers = modifiers;
13377
- editObj = object.doEditClick(info, 0);
14258
+ //ClickInfo info = new ClickInfo();
14259
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14260
+ object.clickInfo.pane = this;
14261
+ object.clickInfo.camera = renderCamera;
14262
+ object.clickInfo.x = x;
14263
+ object.clickInfo.y = y;
14264
+ object.clickInfo.modifiers = modifiersex;
14265
+ editObj = object.doEditClick(//info,
14266
+ 0);
1337814267 if (!editObj)
1337914268 {
1338014269 hasMarquee = true;
....@@ -13390,11 +14279,14 @@
1339014279
1339114280 public void mouseDragged(MouseEvent e)
1339214281 {
14282
+ Globals.MOUSEDRAGGED = true;
14283
+
14284
+ //System.out.println("mouseDragged: " + e);
1339314285 if (isRenderer)
1339414286 movingcamera = true;
14287
+
1339514288 //if (drawing)
1339614289 //return;
13397
- //System.out.println("mouseDragged: " + e);
1339814290 if ((e.getModifiersEx() & CTRL) != 0
1339914291 || (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen())
1340014292 {
....@@ -13402,7 +14294,7 @@
1340214294 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1340314295 }
1340414296 else
13405
- drag(e.getX(), e.getY(), e.getModifiersEx());
14297
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1340614298
1340714299 //try { Thread.sleep(1); } catch (Exception ex) {}
1340814300 }
....@@ -13575,6 +14467,7 @@
1357514467
1357614468 public void run()
1357714469 {
14470
+ new Exception().printStackTrace();
1357814471 System.exit(0);
1357914472 for (;;)
1358014473 {
....@@ -13638,7 +14531,7 @@
1363814531 {
1363914532 Globals.lighttouched = true;
1364014533 }
13641
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14534
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1364214535 }
1364314536 //else
1364414537 }
....@@ -13652,12 +14545,12 @@
1365214545 void GoDown(int mod)
1365314546 {
1365414547 MODIFIERS |= COMMAND;
13655
- /*
14548
+ /**/
1365614549 if((mod&SHIFT) == SHIFT)
1365714550 manipCamera.RotatePosition(0, -speed);
1365814551 else
13659
- manipCamera.BackForth(0, -speed*delta, getWidth());
13660
- */
14552
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14553
+ /**/
1366114554 if ((mod & SHIFT) == SHIFT)
1366214555 {
1366314556 mouseMode = mouseMode; // VR??
....@@ -13673,12 +14566,12 @@
1367314566 void GoUp(int mod)
1367414567 {
1367514568 MODIFIERS |= COMMAND;
13676
- /*
14569
+ /**/
1367714570 if((mod&SHIFT) == SHIFT)
1367814571 manipCamera.RotatePosition(0, speed);
1367914572 else
13680
- manipCamera.BackForth(0, speed*delta, getWidth());
13681
- */
14573
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14574
+ /**/
1368214575 if ((mod & SHIFT) == SHIFT)
1368314576 {
1368414577 mouseMode = mouseMode;
....@@ -13694,12 +14587,12 @@
1369414587 void GoLeft(int mod)
1369514588 {
1369614589 MODIFIERS |= COMMAND;
13697
- /*
14590
+ /**/
1369814591 if((mod&SHIFT) == SHIFT)
13699
- manipCamera.RotatePosition(speed, 0);
13700
- else
1370114592 manipCamera.Translate(speed*delta, 0, getWidth());
13702
- */
14593
+ else
14594
+ manipCamera.RotatePosition(speed, 0);
14595
+ /**/
1370314596 if ((mod & SHIFT) == SHIFT)
1370414597 {
1370514598 mouseMode = mouseMode;
....@@ -13715,12 +14608,12 @@
1371514608 void GoRight(int mod)
1371614609 {
1371714610 MODIFIERS |= COMMAND;
13718
- /*
14611
+ /**/
1371914612 if((mod&SHIFT) == SHIFT)
13720
- manipCamera.RotatePosition(-speed, 0);
13721
- else
1372214613 manipCamera.Translate(-speed*delta, 0, getWidth());
13723
- */
14614
+ else
14615
+ manipCamera.RotatePosition(-speed, 0);
14616
+ /**/
1372414617 if ((mod & SHIFT) == SHIFT)
1372514618 {
1372614619 mouseMode = mouseMode;
....@@ -13738,7 +14631,7 @@
1373814631 int X, Y;
1373914632 boolean SX, SY;
1374014633
13741
- void drag(int x, int y, int modifiers)
14634
+ void drag(int x, int y, int modifiers, int modifiersex)
1374214635 {
1374314636 if (IsFrozen())
1374414637 {
....@@ -13747,17 +14640,17 @@
1374714640
1374814641 drag = true; // NEW
1374914642
13750
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14643
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1375114644
1375214645 X = x;
1375314646 Y = y;
1375414647 // floating state for animation
13755
- MODIFIERS = modifiers;
13756
- modifiers &= ~1024;
14648
+ MODIFIERS = modifiersex;
14649
+ modifiersex &= ~1024;
1375714650 if (false) // modifiers != 0)
1375814651 {
1375914652 //new Exception().printStackTrace();
13760
- System.out.println("mouseDragged: " + modifiers);
14653
+ System.out.println("mouseDragged: " + modifiersex);
1376114654 System.out.println("SHIFT = " + SHIFT);
1376214655 System.out.println("CONTROL = " + COMMAND);
1376314656 System.out.println("META = " + META);
....@@ -13770,14 +14663,16 @@
1377014663 if (editObj)
1377114664 {
1377214665 drag = true;
13773
- ClickInfo info = new ClickInfo();
13774
- info.bounds.setBounds(0, 0,
14666
+ //ClickInfo info = new ClickInfo();
14667
+ object.clickInfo.bounds.setBounds(0, 0,
1377514668 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
13776
- info.pane = this;
13777
- info.camera = renderCamera;
13778
- info.x = x;
13779
- info.y = y;
13780
- object.editWindow.copy.doEditDrag(info);
14669
+ object.clickInfo.pane = this;
14670
+ object.clickInfo.camera = renderCamera;
14671
+ object.clickInfo.x = x;
14672
+ object.clickInfo.y = y;
14673
+ object //.GetWindow().copy
14674
+ .doEditDrag(//info,
14675
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1378114676 } else
1378214677 {
1378314678 if (x < startX)
....@@ -13926,23 +14821,27 @@
1392614821 }
1392714822 }
1392814823
14824
+// ClickInfo clickInfo = new ClickInfo();
14825
+
1392914826 public void mouseMoved(MouseEvent e)
1393014827 {
1393114828 //System.out.println("mouseMoved: " + e);
13932
-
1393314829 if (isRenderer)
1393414830 return;
1393514831
13936
- ClickInfo ci = new ClickInfo();
13937
- ci.x = e.getX();
13938
- ci.y = e.getY();
13939
- ci.modifiers = e.getModifiersEx();
13940
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
13941
- ci.pane = this;
13942
- ci.camera = renderCamera;
14832
+ // Mouse cursor feedback
14833
+ object.clickInfo.x = e.getX();
14834
+ object.clickInfo.y = e.getY();
14835
+ object.clickInfo.modifiers = e.getModifiersEx();
14836
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14837
+ object.clickInfo.pane = this;
14838
+ object.clickInfo.camera = renderCamera;
1394314839 if (!isRenderer)
1394414840 {
13945
- if (object.editWindow.copy.doEditClick(ci, 0))
14841
+ //ObjEditor editWindow = object.editWindow;
14842
+ //Object3D copy = editWindow.copy;
14843
+ if (object.doEditClick(//clickInfo,
14844
+ 0))
1394614845 {
1394714846 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1394814847 } else
....@@ -13954,7 +14853,11 @@
1395414853
1395514854 public void mouseReleased(MouseEvent e)
1395614855 {
14856
+ Globals.MOUSEDRAGGED = false;
14857
+
1395714858 movingcamera = false;
14859
+ X = 0; // getBounds().width/2;
14860
+ Y = 0; // getBounds().height/2;
1395814861 //System.out.println("mouseReleased: " + e);
1395914862 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1396014863 }
....@@ -13977,9 +14880,9 @@
1397714880 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1397814881 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1397914882
13980
- if (control || command || IsFrozen())
14883
+// No delay if (control || command || IsFrozen())
1398114884 timeout = true;
13982
- else
14885
+// ?? May 2019 else
1398314886 // timer.setDelay((modifiers & 128) != 0?0:350);
1398414887 mouseDown = false;
1398514888 if (!control && !command) // june 2013
....@@ -14089,7 +14992,7 @@
1408914992 System.out.println("keyReleased: " + e);
1409014993 }
1409114994
14092
- void SetMouseMode(int modifiers)
14995
+ void SetMouseMode(int modifiers, int modifiersex)
1409314996 {
1409414997 //System.out.println("SetMouseMode = " + modifiers);
1409514998 //modifiers &= ~1024;
....@@ -14101,25 +15004,25 @@
1410115004 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1410215005 // return;
1410315006 //System.out.println("SetMode = " + modifiers);
14104
- if ((modifiers & WHEEL) == WHEEL)
15007
+ if ((modifiersex & WHEEL) == WHEEL)
1410515008 {
1410615009 mouseMode |= ZOOM;
1410715010 }
1410815011
1410915012 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
14110
- if (capsLocked || (modifiers & META) == META)
15013
+ if (capsLocked) // || (modifiers & META) == META)
1411115014 {
1411215015 mouseMode |= VR; // BACKFORTH;
1411315016 }
14114
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
15017
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1411515018 {
1411615019 mouseMode |= SELECT;
1411715020 }
14118
- if ((modifiers & COMMAND) == COMMAND)
15021
+ if ((modifiersex & COMMAND) == COMMAND)
1411915022 {
1412015023 mouseMode |= SELECT;
1412115024 }
14122
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15025
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
1412315026 {
1412415027 mouseMode &= ~VR;
1412515028 mouseMode |= TRANSLATE;
....@@ -14148,7 +15051,7 @@
1414815051
1414915052 if (isRenderer) //
1415015053 {
14151
- SetMouseMode(modifiers);
15054
+ SetMouseMode(0, modifiers);
1415215055 }
1415315056
1415415057 Globals.theRenderer.keyPressed(key);
....@@ -14210,7 +15113,8 @@
1421015113 // break;
1421115114 case 'T':
1421215115 CACHETEXTURE ^= true;
14213
- textures.clear();
15116
+ texturepigment.clear();
15117
+ texturebump.clear();
1421415118 // repaint();
1421515119 break;
1421615120 case 'Y':
....@@ -14295,7 +15199,9 @@
1429515199 case 'E' : COMPACT ^= true;
1429615200 repaint();
1429715201 break;
14298
- case 'W' : DEBUGHSB ^= true;
15202
+ case 'W' : // Wide Window (fullscreen)
15203
+ //DEBUGHSB ^= true;
15204
+ ObjEditor.theFrame.ToggleFullScreen();
1429915205 repaint();
1430015206 break;
1430115207 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14320,8 +15226,8 @@
1432015226 RevertCamera();
1432115227 repaint();
1432215228 break;
14323
- case 'L':
1432415229 case 'l':
15230
+ //case 'L':
1432515231 if (lightMode)
1432615232 {
1432715233 lightMode = false;
....@@ -14464,9 +15370,9 @@
1446415370 case '_':
1446515371 kompactbit = 5;
1446615372 break;
14467
- case '+':
14468
- kompactbit = 6;
14469
- break;
15373
+// case '+':
15374
+// kompactbit = 6;
15375
+// break;
1447015376 case ' ':
1447115377 lightMode ^= true;
1447215378 Globals.lighttouched = true;
....@@ -14478,13 +15384,14 @@
1447815384 case ESC:
1447915385 RENDERPROGRAM += 1;
1448015386 RENDERPROGRAM %= 3;
15387
+
1448115388 repaint();
1448215389 break;
1448315390 case 'Z':
1448415391 //RESIZETEXTURE ^= true;
1448515392 //break;
1448615393 case 'z':
14487
- RENDERSHADOW ^= true;
15394
+ Globals.RENDERSHADOW ^= true;
1448815395 Globals.lighttouched = true;
1448915396 repaint();
1449015397 break;
....@@ -14517,8 +15424,9 @@
1451715424 case DELETE:
1451815425 ClearSelection();
1451915426 break;
14520
- /*
1452115427 case '+':
15428
+
15429
+ /*
1452215430 //fontsize += 1;
1452315431 bbzoom *= 2;
1452415432 repaint();
....@@ -14535,17 +15443,17 @@
1453515443 case '=':
1453615444 IncDepth();
1453715445 //fontsize += 1;
14538
- object.editWindow.refreshContents(true);
15446
+ object.GetWindow().refreshContents(true);
1453915447 maskbit = 6;
1454015448 break;
1454115449 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1454215450 DecDepth();
1454315451 maskbit = 5;
1454415452 //if(fontsize > 1) fontsize -= 1;
14545
- if (object.editWindow == null)
14546
- new Exception().printStackTrace();
14547
- else
14548
- object.editWindow.refreshContents(true);
15453
+// if (object.editWindow == null)
15454
+// new Exception().printStackTrace();
15455
+// else
15456
+ object.GetWindow().refreshContents(true);
1454915457 break;
1455015458 case '{':
1455115459 manipCamera.shaper_fovy /= 1.1;
....@@ -14608,7 +15516,7 @@
1460815516 //mode = ROTATE;
1460915517 if ((MODIFIERS & COMMAND) == 0) // VR??
1461015518 {
14611
- SetMouseMode(modifiers);
15519
+ SetMouseMode(0, modifiers);
1461215520 }
1461315521 }
1461415522
....@@ -14742,8 +15650,9 @@
1474215650
1474315651 protected void processMouseMotionEvent(MouseEvent e)
1474415652 {
14745
- //System.out.println("processMouseMotionEvent: " + mouseMode);
14746
- if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15653
+ //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
15654
+ //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15655
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1474715656 {
1474815657 mouseMoved(e);
1474915658 } else
....@@ -14768,11 +15677,12 @@
1476815677 }
1476915678 */
1477015679
14771
- object.editWindow.EditSelection();
15680
+ object.GetWindow().EditSelection(false);
1477215681 }
1477315682
1477415683 void SelectParent()
1477515684 {
15685
+ new Exception().printStackTrace();
1477615686 System.exit(0);
1477715687 Composite group = (Composite) object;
1477815688 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -14784,10 +15694,10 @@
1478415694 {
1478515695 //selectees.remove(i);
1478615696 System.out.println("select parent of " + elem);
14787
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15697
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1478815698 } else
1478915699 {
14790
- group.editWindow.Select(elem.GetTreePath(), first, true);
15700
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1479115701 }
1479215702
1479315703 first = false;
....@@ -14796,6 +15706,7 @@
1479615706
1479715707 void SelectChildren()
1479815708 {
15709
+ new Exception().printStackTrace();
1479915710 System.exit(0);
1480015711 /*
1480115712 Composite group = (Composite) object;
....@@ -14828,12 +15739,12 @@
1482815739 for (int j = 0; j < group.children.size(); j++)
1482915740 {
1483015741 elem = (Object3D) group.children.elementAt(j);
14831
- object.editWindow.Select(elem.GetTreePath(), first, true);
15742
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1483215743 first = false;
1483315744 }
1483415745 } else
1483515746 {
14836
- object.editWindow.Select(elem.GetTreePath(), first, true);
15747
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1483715748 }
1483815749
1483915750 first = false;
....@@ -14844,21 +15755,21 @@
1484415755 {
1484515756 //Composite group = (Composite) object;
1484615757 Object3D group = object;
14847
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15758
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1484815759 }
1484915760
1485015761 void ResetTransform(int mask)
1485115762 {
1485215763 //Composite group = (Composite) object;
1485315764 Object3D group = object;
14854
- group.editWindow.ResetTransform(mask);
15765
+ group.GetWindow().ResetTransform(mask);
1485515766 }
1485615767
1485715768 void FlipTransform()
1485815769 {
1485915770 //Composite group = (Composite) object;
1486015771 Object3D group = object;
14861
- group.editWindow.FlipTransform();
15772
+ group.GetWindow().FlipTransform();
1486215773 // group.editWindow.ReduceMesh(true);
1486315774 }
1486415775
....@@ -14866,7 +15777,7 @@
1486615777 {
1486715778 //Composite group = (Composite) object;
1486815779 Object3D group = object;
14869
- group.editWindow.PrintMemory();
15780
+ group.GetWindow().PrintMemory();
1487015781 // group.editWindow.ReduceMesh(true);
1487115782 }
1487215783
....@@ -14874,7 +15785,7 @@
1487415785 {
1487515786 //Composite group = (Composite) object;
1487615787 Object3D group = object;
14877
- group.editWindow.ResetCentroid();
15788
+ group.GetWindow().ResetCentroid();
1487815789 }
1487915790
1488015791 void IncDepth()
....@@ -14956,11 +15867,11 @@
1495615867
1495715868 int width = getBounds().width;
1495815869 int height = getBounds().height;
14959
- ClickInfo info = new ClickInfo();
14960
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1496115870 //Image img = CreateImage(width, height);
1496215871 //System.out.println("width = " + width + "; height = " + height + "\n");
15872
+
1496315873 Graphics gr = g; // img.getGraphics();
15874
+
1496415875 if (!hasMarquee)
1496515876 {
1496615877 if (Xmin < Xmax) // !locked)
....@@ -15032,40 +15943,88 @@
1503215943 }
1503315944 if (object != null && !hasMarquee)
1503415945 {
15946
+ if (object.clickInfo == null)
15947
+ object.clickInfo = new ClickInfo();
15948
+ ClickInfo info = object.clickInfo;
15949
+ //ClickInfo info = new ClickInfo();
15950
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
15951
+
1503515952 if (isRenderer)
1503615953 {
15037
- info.flags++;
15954
+ object.clickInfo.flags++;
1503815955 double frameAspect = (double) width / (double) height;
1503915956 if (frameAspect > renderCamera.aspect)
1504015957 {
1504115958 int desired = (int) ((double) height * renderCamera.aspect);
15042
- info.bounds.width -= width - desired;
15043
- info.bounds.x += (width - desired) / 2;
15959
+ object.clickInfo.bounds.width -= width - desired;
15960
+ object.clickInfo.bounds.x += (width - desired) / 2;
1504415961 } else
1504515962 {
1504615963 int desired = (int) ((double) width / renderCamera.aspect);
15047
- info.bounds.height -= height - desired;
15048
- info.bounds.y += (height - desired) / 2;
15964
+ object.clickInfo.bounds.height -= height - desired;
15965
+ object.clickInfo.bounds.y += (height - desired) / 2;
1504915966 }
1505015967 }
15051
- info.g = gr;
15052
- info.camera = renderCamera;
15968
+
15969
+ object.clickInfo.g = gr;
15970
+ object.clickInfo.camera = renderCamera;
1505315971 /*
1505415972 // Memory intensive (brep.verticescopy)
1505515973 if (!(object instanceof Composite))
1505615974 object.draw(info, 0, false); // SLOW :
1505715975 */
15058
- if (!isRenderer)
15976
+ if (!isRenderer) // && drag)
1505915977 {
15060
- object.drawEditHandles(info, 0);
15978
+ Grafreed.Assert(object != null);
15979
+ Grafreed.Assert(object.selection != null);
15980
+ if (object.selection.Size() > 0)
15981
+ {
15982
+ int hitSomething = object.selection.get(0).hitSomething;
15983
+
15984
+ object.clickInfo.DX = 0;
15985
+ object.clickInfo.DY = 0;
15986
+ object.clickInfo.W = 1;
15987
+ if (hitSomething == Object3D.hitCenter)
15988
+ {
15989
+ info.DX = X;
15990
+ if (X != 0)
15991
+ info.DX -= info.bounds.width/2;
15992
+
15993
+ info.DY = Y;
15994
+ if (Y != 0)
15995
+ info.DY -= info.bounds.height/2;
15996
+ }
15997
+
15998
+ object.drawEditHandles(//info,
15999
+ 0);
16000
+
16001
+ if (drag && (X != 0 || Y != 0))
16002
+ {
16003
+ switch (hitSomething)
16004
+ {
16005
+ case Object3D.hitCenter: gr.setColor(Color.pink);
16006
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16007
+ break;
16008
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16009
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16010
+ break;
16011
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16012
+ gr.drawLine(X, Y, 0, 0);
16013
+ break;
16014
+ }
16015
+
16016
+ }
16017
+ }
1506116018 }
1506216019 }
16020
+
1506316021 if (isRenderer)
1506416022 {
1506516023 //gr.setColor(Color.black);
1506616024 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1506716025 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1506816026 }
16027
+
1506916028 if (hasMarquee)
1507016029 {
1507116030 gr.setXORMode(Color.white);
....@@ -15178,6 +16137,7 @@
1517816137 public boolean mouseDown(Event evt, int x, int y)
1517916138 {
1518016139 System.out.println("mouseDown: " + evt);
16140
+ System.exit(0);
1518116141 /*
1518216142 locked = true;
1518316143 drag = false;
....@@ -15221,7 +16181,7 @@
1522116181 {
1522216182 keyPressed(0, modifiers);
1522316183 }
15224
- clickStart(x, y, modifiers);
16184
+ // clickStart(x, y, modifiers);
1522516185 return true;
1522616186 }
1522716187
....@@ -15339,7 +16299,7 @@
1533916299 {
1534016300 keyReleased(0, 0);
1534116301 }
15342
- drag(x, y, modifiers);
16302
+ drag(x, y, 0, modifiers);
1534316303 return true;
1534416304 }
1534516305
....@@ -15471,7 +16431,7 @@
1547116431 Object3D object;
1547216432 static Object3D trackedobject;
1547316433 Camera renderCamera; // Light or Eye (or Occlusion)
15474
- /*static*/ Camera manipCamera; // Light or Eye
16434
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1547516435 /*static*/ Camera eyeCamera;
1547616436 /*static*/ Camera lightCamera;
1547716437 int cameracount;
....@@ -15756,16 +16716,16 @@
1575616716 cStatic.objectstack[materialdepth++] = checker;
1575716717 //System.out.println("material " + material);
1575816718 //Applet3D.tracein(this, selected);
15759
- vector2buffer = checker.projectedVertices;
16719
+ //vector2buffer = checker.projectedVertices;
1576016720
1576116721 //checker.GetMaterial().Draw(this, false); // true);
15762
- DrawMaterial(checker.GetMaterial(), false); // true);
16722
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1576316723
1576416724 materialdepth -= 1;
1576516725 if (materialdepth > 0)
1576616726 {
15767
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
15768
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
16727
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16728
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1576916729 }
1577016730 //checker.GetMaterial().opacity = 1f;
1577116731 ////checker.GetMaterial().ambient = 1f;
....@@ -15851,6 +16811,14 @@
1585116811 }
1585216812 }
1585316813
16814
+ private Object3D GetFolder()
16815
+ {
16816
+ Object3D folder = object.GetWindow().copy;
16817
+ if (object.GetWindow().copy.selection.Size() > 0)
16818
+ folder = object.GetWindow().copy.selection.elementAt(0);
16819
+ return folder;
16820
+ }
16821
+
1585416822 class SelectBuffer implements GLEventListener
1585516823 {
1585616824
....@@ -15909,6 +16877,7 @@
1590916877 {
1591016878 if (!selection)
1591116879 {
16880
+ new Exception().printStackTrace();
1591216881 System.exit(0);
1591316882 return;
1591416883 }
....@@ -15929,6 +16898,17 @@
1592916898
1593016899 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1593116900
16901
+ if (PAINTMODE)
16902
+ {
16903
+ if (object.GetWindow().copy.selection.Size() > 0)
16904
+ {
16905
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16906
+
16907
+ // Make what you paint not selectable.
16908
+ paintobj.ResetSelectable();
16909
+ }
16910
+ }
16911
+
1593216912 //int tmp = selection_view;
1593316913 //selection_view = -1;
1593416914 int temp = DrawMode();
....@@ -15940,6 +16920,17 @@
1594016920 // temp = DEFAULT; // patch for selection debug
1594116921 Globals.drawMode = temp; // WARNING
1594216922
16923
+ if (PAINTMODE)
16924
+ {
16925
+ if (object.GetWindow().copy.selection.Size() > 0)
16926
+ {
16927
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16928
+
16929
+ // Revert.
16930
+ paintobj.RestoreSelectable();
16931
+ }
16932
+ }
16933
+
1594316934 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1594416935
1594516936 // trying different ways of getting the depth info over
....@@ -15987,6 +16978,8 @@
1598716978 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1598816979 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1598916980 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
16981
+
16982
+ CreateSelectedPoint();
1599016983
1599116984 // Will fit the mesh !!!
1599216985 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16036,34 +17029,36 @@
1603617029 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]));
1603717030 }
1603817031
16039
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
17032
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1604017033 }
1604117034 }
1604217035
1604317036 if (!movingcamera && !PAINTMODE)
16044
- object.editWindow.ScreenFitPoint(); // fev 2014
17037
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1604517038
16046
- if (PAINTMODE && GrafreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17039
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1604717040 {
16048
- Object3D paintobj = GrafreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17041
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1604917042
16050
- Object3D group = new Object3D("inst" + paintcount++);
17043
+ if (object.GetWindow().copy.selection.Size() > 0)
17044
+ {
17045
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1605117046
16052
- group.CreateMaterial(); // use a void leaf to select instances
16053
-
16054
- group.add(paintobj); // link
16055
-
16056
- object.editWindow.SnapObject(group);
16057
-
16058
- Object3D folder = object.editWindow.copy;
16059
-
16060
- if (object.editWindow.copy.selection.Size() > 0)
16061
- folder = object.editWindow.copy.selection.elementAt(0);
16062
-
16063
- folder.add(group);
16064
-
16065
- object.editWindow.ResetModel();
16066
- object.editWindow.refreshContents();
17047
+ Object3D inst = new Object3D("inst" + paintcount++);
17048
+
17049
+ inst.CreateMaterial(); // use a void leaf to select instances
17050
+
17051
+ inst.add(paintobj); // link
17052
+
17053
+ object.GetWindow().SnapObject(inst);
17054
+
17055
+ Object3D folder = paintFolder; // GetFolder();
17056
+
17057
+ folder.add(inst);
17058
+
17059
+ object.GetWindow().ResetModel();
17060
+ object.GetWindow().refreshContents();
17061
+ }
1606717062 }
1606817063 else
1606917064 paintcount = 0;
....@@ -16102,6 +17097,11 @@
1610217097 //System.out.println("objects[color] = " + objects[color]);
1610317098 //objects[color].Select();
1610417099 indexcount = 0;
17100
+ ObjEditor window = object.GetWindow();
17101
+ if (window != null && deselect)
17102
+ {
17103
+ window.Select(null, deselect, true);
17104
+ }
1610517105 object.Select(color, deselect);
1610617106 }
1610717107
....@@ -16201,7 +17201,7 @@
1620117201 gl.glDisable(gl.GL_CULL_FACE);
1620217202 }
1620317203
16204
- if (!RENDERSHADOW)
17204
+ if (!Globals.RENDERSHADOW)
1620517205 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1620617206
1620717207 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -16211,7 +17211,7 @@
1621117211 //gl.glColorMask(false, false, false, false);
1621217212
1621317213 //render_scene_from_light_view(gl, drawable, 0, 0);
16214
- if (RENDERSHADOW && Globals.lighttouched && !movingcamera) // && !parent.IsFreezed())
17214
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1621517215 {
1621617216 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1621717217
....@@ -16627,23 +17627,15 @@
1662717627 int AAbuffersize = 0;
1662817628
1662917629 //double[] selectedpoint = new double[3];
16630
- static Superellipsoid selectedpoint = new Superellipsoid();
17630
+ static Superellipsoid selectedpoint;
1663117631 static Sphere previousselectedpoint = null;
16632
- static Sphere debugpointG = new Sphere();
16633
- static Sphere debugpointP = new Sphere();
16634
- static Sphere debugpointC = new Sphere();
16635
- static Sphere debugpointR = new Sphere();
17632
+ static Sphere debugpointG;
17633
+ static Sphere debugpointP;
17634
+ static Sphere debugpointC;
17635
+ static Sphere debugpointR;
1663617636
1663717637 static Sphere debugpoints[] = new Sphere[8];
1663817638
16639
- static
16640
- {
16641
- for (int i=0; i<8; i++)
16642
- {
16643
- debugpoints[i] = new Sphere();
16644
- }
16645
- }
16646
-
1664717639 static void InitPoints(float radius)
1664817640 {
1664917641 for (int i=0; i<8; i++)
....@@ -16695,10 +17687,11 @@
1669517687 static IntBuffer textbuffer = null; // IntBuffer.allocate(TEXT_WIDTH*8*8 * TEXT_HEIGHT);
1669617688 // Depth buffer format
1669717689 //private int depth_format;
16698
- static public void NextIndex(Object3D o, GL gl)
17690
+
17691
+ public void NextIndex()
1669917692 {
1670017693 indexcount+=16;
16701
- gl.glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
17694
+ GetGL().glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
1670217695 //objects[indexcount] = o;
1670317696 //System.out.println("indexcount = " + indexcount);
1670417697 }