Normand Briere
2019-07-22 c570e1e38f2ff8622a71f81436654bad01cfdd5b
CameraPane.java
....@@ -37,7 +37,6 @@
3737 static boolean[] selectedstack = new boolean[65536];
3838 static int materialdepth = 0;
3939
40
- static boolean DEBUG = false;
4140 static boolean FRUSTUM = false; // still bogus true; // frustum culling
4241
4342 // camera change fix
....@@ -45,6 +44,39 @@
4544 static boolean ABORTED = false;
4645
4746 static int STEP = 1;
47
+
48
+ private static BufferedImage CreateBim(byte[] bytes, int width, int height)
49
+ {
50
+ int[] pixels = new int[bytes.length/3];
51
+ for (int i=pixels.length; --i>=0;)
52
+ {
53
+ int i3 = i*3;
54
+ pixels[i] = 0xFF;
55
+ pixels[i] <<= 8;
56
+ pixels[i] |= bytes[i3+2] & 0xFF;
57
+ pixels[i] <<= 8;
58
+ pixels[i] |= bytes[i3+1] & 0xFF;
59
+ pixels[i] <<= 8;
60
+ pixels[i] |= bytes[i3] & 0xFF;
61
+ }
62
+ /*
63
+ int r=0,g=0,b=0,a=0;
64
+ for (int i=0; i<width; i++)
65
+ for (int j=0; j<height; j++)
66
+ {
67
+ int index = j*width+i;
68
+ int p = pixels[index];
69
+ a = ((p>>24) & 0xFF);
70
+ r = ((p>>16) & 0xFF);
71
+ g = ((p>>8) & 0xFF);
72
+ b = (p & 0xFF);
73
+ pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
74
+ }
75
+ /**/
76
+ BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
77
+ rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
78
+ return rendImage;
79
+ }
4880
4981 /*static*/ private boolean CULLFACE = false; // true;
5082 /*static*/ boolean NEAREST = false; // true;
....@@ -56,14 +88,12 @@
5688 static int CURRENTANTIALIAS = 0; // 1;
5789 /*static*/ boolean RENDERSHADOW = true;
5890 /*static*/ int RENDERPROGRAM = 2; // 0 == none, 1 == fast, 2 == normal
59
- static boolean ANIMATION = false;
60
- static String filename;
6191
6292 boolean DISPLAYTEXT = false;
6393 //boolean REDUCETEXTURE = true;
6494 boolean CACHETEXTURE = true;
6595 boolean CLEANCACHE = false; // true;
66
- boolean MIPMAP = false; // true;
96
+ boolean MIPMAP = true; // false; // true;
6797 boolean COMPRESSTEXTURE = false;
6898 boolean KOMPACTTEXTURE = false; // true;
6999 boolean RESIZETEXTURE = false;
....@@ -92,6 +122,8 @@
92122
93123 static int tickcount = 0; // slow pose issue
94124
125
+static boolean BUTTONLESSWHEEL = false;
126
+static boolean ZOOMBOXMODE = false;
95127 static boolean BOXMODE = false;
96128 static boolean IMAGEFLIP = false;
97129 static boolean SMOOTHFOCUS = false;
....@@ -106,7 +138,7 @@
106138 static boolean OEIL = true;
107139 static boolean OEILONCE = false; // do oeilon then oeiloff
108140 static boolean LOOKAT = true;
109
-static boolean RANDOM = true; // false;
141
+static boolean SWITCH = true; // false;
110142 static boolean HANDLES = false; // selection doesn't work!!
111143 static boolean PAINTMODE = false;
112144
....@@ -150,6 +182,8 @@
150182 defaultcaps.setAccumAlphaBits(16);
151183 }
152184
185
+ private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
186
+
153187 void SetAsGLRenderer(boolean b)
154188 {
155189 isRenderer = b;
....@@ -191,9 +225,43 @@
191225
192226 /// INTERFACE
193227
228
+ public javax.media.opengl.GL GetGL0()
229
+ {
230
+ return null;
231
+ }
232
+
233
+ public int GenList()
234
+ {
235
+ javax.media.opengl.GL gl = GetGL();
236
+ return gl.glGenLists(1);
237
+ }
238
+
239
+ public void NewList(int id)
240
+ {
241
+ javax.media.opengl.GL gl = GetGL();
242
+ gl.glNewList(id, gl.GL_COMPILE); //_AND_EXECUTE);
243
+ }
244
+
245
+ public void CallList(int id)
246
+ {
247
+ javax.media.opengl.GL gl = GetGL();
248
+ gl.glCallList(id);
249
+ }
250
+
251
+ public void EndList()
252
+ {
253
+ javax.media.opengl.GL gl = GetGL();
254
+ gl.glEndList();
255
+ }
256
+
194257 public boolean IsBoxMode()
195258 {
196259 return BOXMODE;
260
+ }
261
+
262
+ public boolean IsZoomBoxMode()
263
+ {
264
+ return ZOOMBOXMODE;
197265 }
198266
199267 public void ClearDepth()
....@@ -291,7 +359,7 @@
291359 cStatic.objectstack[materialdepth++] = obj;
292360 //System.out.println("material " + material);
293361 //Applet3D.tracein(this, selected);
294
- display.vector2buffer = obj.projectedVertices;
362
+ //display.vector2buffer = obj.projectedVertices;
295363 if (obj instanceof Camera)
296364 {
297365 display.options1[0] = material.shift;
....@@ -300,14 +368,28 @@
300368 display.options1[2] = material.shadowbias;
301369 display.options1[3] = material.aniso;
302370 display.options1[4] = material.anisoV;
371
+// System.out.println("display.options1[0] " + display.options1[0]);
372
+// System.out.println("display.options1[1] " + display.options1[1]);
373
+// System.out.println("display.options1[2] " + display.options1[2]);
374
+// System.out.println("display.options1[3] " + display.options1[3]);
375
+// System.out.println("display.options1[4] " + display.options1[4]);
303376 display.options2[0] = material.opacity;
304377 display.options2[1] = material.diffuse;
305378 display.options2[2] = material.factor;
379
+// System.out.println("display.options2[0] " + display.options2[0]);
380
+// System.out.println("display.options2[1] " + display.options2[1]);
381
+// System.out.println("display.options2[2] " + display.options2[2]);
306382
307383 cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
384
+// System.out.println("display.options3[0] " + display.options3[0]);
385
+// System.out.println("display.options3[1] " + display.options3[1]);
386
+// System.out.println("display.options3[2] " + display.options3[2]);
308387 display.options4[0] = material.cameralight/0.2f;
309388 display.options4[1] = material.subsurface;
310389 display.options4[2] = material.sheen;
390
+// System.out.println("display.options4[0] " + display.options4[0]);
391
+// System.out.println("display.options4[1] " + display.options4[1]);
392
+// System.out.println("display.options4[2] " + display.options4[2]);
311393
312394 // if (display.CURRENTANTIALIAS > 0)
313395 // display.options3[3] /= 4;
....@@ -323,7 +405,7 @@
323405 /**/
324406 } else
325407 {
326
- DrawMaterial(material, selected);
408
+ DrawMaterial(material, selected, obj.projectedVertices);
327409 }
328410 } else
329411 {
....@@ -347,8 +429,8 @@
347429 cStatic.objectstack[materialdepth++] = obj;
348430 //System.out.println("material " + material);
349431 //Applet3D.tracein("selected ", selected);
350
- display.vector2buffer = obj.projectedVertices;
351
- display.DrawMaterial(material, selected);
432
+ //display.vector2buffer = obj.projectedVertices;
433
+ display.DrawMaterial(material, selected, obj.projectedVertices);
352434 }
353435 }
354436
....@@ -365,8 +447,8 @@
365447 materialdepth -= 1;
366448 if (materialdepth > 0)
367449 {
368
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
369
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
450
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
451
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
370452 }
371453 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
372454 } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
....@@ -386,8 +468,8 @@
386468 materialdepth -= 1;
387469 if (materialdepth > 0)
388470 {
389
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
390
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
471
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
472
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
391473 }
392474 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
393475 //else
....@@ -428,10 +510,12 @@
428510 if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
429511 {
430512 //gl.glBegin(gl.GL_TRIANGLES);
431
- boolean hasnorm = pv.norm != null; // && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0);
513
+ boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0)
514
+ // TEST LIVE NORMALS && !obj.dontselect
515
+ ;
432516 if (!hasnorm)
433517 {
434
- // System.out.println("FUCK!!");
518
+ // System.out.println("Mesh normal");
435519 LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
436520 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
437521 LA.vecCross(obj.v0, obj.v1, obj.v2);
....@@ -1059,7 +1143,342 @@
10591143 gl.glMatrixMode(gl.GL_MODELVIEW);
10601144 }
10611145
1146
+ public void DrawBox(cVector min, cVector max)
1147
+ {
1148
+ javax.media.opengl.GL gl = GetGL();
1149
+ gl.glBegin(gl.GL_LINES);
1150
+
1151
+ gl.glVertex3d(min.x, min.y, min.z);
1152
+ gl.glVertex3d(min.x, min.y, max.z);
1153
+ gl.glVertex3d(min.x, min.y, min.z);
1154
+ gl.glVertex3d(min.x, max.y, min.z);
1155
+ gl.glVertex3d(min.x, min.y, min.z);
1156
+ gl.glVertex3d(max.x, min.y, min.z);
1157
+
1158
+ gl.glVertex3d(max.x, max.y, max.z);
1159
+ gl.glVertex3d(min.x, max.y, max.z);
1160
+ gl.glVertex3d(max.x, max.y, max.z);
1161
+ gl.glVertex3d(max.x, min.y, max.z);
1162
+ gl.glVertex3d(max.x, max.y, max.z);
1163
+ gl.glVertex3d(max.x, max.y, min.z);
1164
+
1165
+ gl.glEnd();
1166
+ }
1167
+
1168
+ public void DrawGeometry(BoundaryRep bRep, boolean flipV, boolean selectmode)
1169
+ {
1170
+ int[] strips = bRep.getRawIndices();
1171
+
1172
+ javax.media.opengl.GL gl = GetGL();
1173
+
1174
+ // TRIANGLE STRIP ARRAY
1175
+ if (bRep.trimmed)
1176
+ {
1177
+ float[] v = bRep.getRawVertices();
1178
+ float[] n = bRep.getRawNormals();
1179
+ float[] c = bRep.getRawColors();
1180
+ float[] uv = bRep.getRawUVMap();
1181
+
1182
+ int count2 = 0;
1183
+ int count3 = 0;
1184
+
1185
+ if (n.length > 0)
1186
+ {
1187
+ for (int i = 0; i < strips.length; i++)
1188
+ {
1189
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1190
+
1191
+ /*
1192
+ boolean locked = false;
1193
+ float eps = 0.1f;
1194
+ boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
1195
+
1196
+ int dot = 0;
1197
+
1198
+ if ((dot&1) == 0)
1199
+ dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
1200
+
1201
+ if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
1202
+ gl.glTexCoord2f((float) qv.s, (float) qv.t);
1203
+ else
1204
+ {
1205
+ locked = true;
1206
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1207
+ }
1208
+ //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
1209
+ gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
1210
+ if (hasnorm)
1211
+ {
1212
+ //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
1213
+ gl.glNormal3f((float) rv.norm.x, (float) rv.norm.y, (float) rv.norm.z);
1214
+ }
1215
+
1216
+ if ((dot&4) == 0)
1217
+ dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
1218
+
1219
+ if (wrap || !locked && (dot&8) != 0)
1220
+ gl.glTexCoord2f((float) rv.s, (float) rv.t);
1221
+ else
1222
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1223
+
1224
+ f.dot = dot;
1225
+ */
1226
+
1227
+ if (!selectmode)
1228
+ {
1229
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1230
+ {
1231
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1232
+ } else
1233
+ {
1234
+ gl.glNormal3f(0, 0, 1);
1235
+ }
1236
+
1237
+ if (c != null)
1238
+ //System.out.println("glcolor = " + c[count3] + ", " + c[count3+1] + ", " + c[count3+2]);
1239
+ {
1240
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1241
+ }
1242
+ }
1243
+
1244
+ if (flipV)
1245
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1246
+ else
1247
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1248
+
1249
+ //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1250
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1251
+
1252
+ count2 += 2;
1253
+ count3 += 3;
1254
+ if (!selectmode)
1255
+ {
1256
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1257
+ {
1258
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1259
+ } else
1260
+ {
1261
+ gl.glNormal3f(0, 0, 1);
1262
+ }
1263
+ if (c != null)
1264
+ {
1265
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1266
+ }
1267
+ }
1268
+
1269
+ if (flipV)
1270
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1271
+ else
1272
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1273
+
1274
+ //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1275
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1276
+
1277
+ count2 += 2;
1278
+ count3 += 3;
1279
+ for (int j = 0; j < strips[i] - 2; j++)
1280
+ {
1281
+ //gl.glTexCoord2d(...);
1282
+ if (!selectmode)
1283
+ {
1284
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1285
+ {
1286
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1287
+ } else
1288
+ {
1289
+ gl.glNormal3f(0, 0, 1);
1290
+ }
1291
+ if (c != null)
1292
+ {
1293
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1294
+ }
1295
+ }
1296
+
1297
+ if (flipV)
1298
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1299
+ else
1300
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1301
+
1302
+ //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
1303
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1304
+
1305
+ count2 += 2;
1306
+ count3 += 3;
1307
+ }
1308
+
1309
+ gl.glEnd();
1310
+ }
1311
+ }
1312
+
1313
+ assert count3 == v.length;
1314
+ }
1315
+ else // !trimmed
1316
+ {
1317
+ int count = 0;
1318
+ for (int i = 0; i < strips.length; i++)
1319
+ {
1320
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1321
+
1322
+ Vertex p = bRep.GetVertex(bRep.indices[count++]);
1323
+ Vertex q = bRep.GetVertex(bRep.indices[count++]);
1324
+
1325
+ drawVertex(gl, p, flipV, selectmode);
1326
+ drawVertex(gl, q, flipV, selectmode);
1327
+
1328
+ for (int j = 0; j < strips[i] - 2; j++)
1329
+ {
1330
+ Vertex r = bRep.GetVertex(bRep.indices[count++]);
1331
+
1332
+ // if (j%2 == 0)
1333
+ // drawFace(p, q, r, display, null);
1334
+ // else
1335
+ // drawFace(p, r, q, display, null);
1336
+
1337
+ // p = q;
1338
+ // q = r;
1339
+ drawVertex(gl, r, flipV, selectmode);
1340
+ }
1341
+
1342
+ gl.glEnd();
1343
+ }
1344
+ }
1345
+ }
1346
+
1347
+ static cSpring.Point3D temp = new cSpring.Point3D();
1348
+ static cSpring.Point3D temp2 = new cSpring.Point3D();
1349
+ static cSpring.Point3D temp3 = new cSpring.Point3D();
1350
+
1351
+ public void DrawDynamicMesh(cMesh mesh)
1352
+ {
1353
+ GL gl = GetGL(); // getGL();
1354
+
1355
+ cSpring.PhysicsController3D Phys = mesh.Phys;
1356
+
1357
+ gl.glDisable(gl.GL_LIGHTING);
1358
+
1359
+ gl.glLineWidth(1);
1360
+ gl.glColor3f(1,1,1);
1361
+ gl.glBegin(gl.GL_LINES);
1362
+ double scale = 0;
1363
+ int count = 0;
1364
+ for (int s=0; s<Phys.allSprings.size(); s++)
1365
+ {
1366
+ cSpring.Spring spring = Phys.allSprings.get(s);
1367
+ if(s == 0)
1368
+ {
1369
+ //System.out.println(" spring : " + spring.a.position + "; " + spring.b.position);
1370
+ }
1371
+ if (mesh.showsprings)
1372
+ {
1373
+ temp.set(spring.a.position);
1374
+ temp.add(spring.b.position);
1375
+ temp.mul(0.5);
1376
+ temp2.set(spring.a.position);
1377
+ temp2.sub(spring.b.position);
1378
+ temp2.mul(spring.restLength/2);
1379
+ temp.sub(temp2);
1380
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1381
+ temp.add(temp2);
1382
+ temp.add(temp2);
1383
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1384
+ }
1385
+
1386
+ if (spring.isHandle)
1387
+ continue;
1388
+
1389
+ //if (scale < spring.restLength)
1390
+ scale += spring.restLength;
1391
+ count++;
1392
+ }
1393
+ gl.glEnd();
1394
+
1395
+ if (count == 0)
1396
+ scale = 0.01;
1397
+ else
1398
+ scale /= count * 3;
1399
+
1400
+ //scale = 0.25;
1401
+
1402
+ if (mesh.ShowInfo())
1403
+ {
1404
+ gl.glLineWidth(4);
1405
+ for (int s=0; s<Phys.allNodes.size(); s++)
1406
+ {
1407
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1408
+ if (node.mass == 0)
1409
+ continue;
1410
+
1411
+ int i = node.springs==null?-1:node.springs.size();
1412
+ gl.glColor3f((i>>2)&1,(i>>1)&1,i&1);
1413
+ //temp.set(node.springForce.x, node.springForce.y, node.springForce.z);
1414
+ //temp.normalize();
1415
+ //gl.glColor3d((temp.x+1)/2, (temp.y+1)/2, (temp.z+1)/2);
1416
+ gl.glBegin(gl.GL_LINES);
1417
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1418
+ //gl.glVertex3d(node.position.x + node.normal.x*scale, node.position.y + node.normal.y*scale, node.position.z + node.normal.z*scale);
1419
+ gl.glVertex3d(node.position.x + mesh.bRep.GetVertex(s).norm.x*scale,
1420
+ node.position.y + mesh.bRep.GetVertex(s).norm.y*scale,
1421
+ node.position.z + mesh.bRep.GetVertex(s).norm.z*scale);
1422
+ gl.glEnd();
1423
+ }
1424
+
1425
+ gl.glLineWidth(8);
1426
+ for (int s=0; s<Phys.allNodes.size(); s++)
1427
+ {
1428
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1429
+
1430
+ if (node.springs != null)
1431
+ {
1432
+ for (int i=0; i<node.springs.size(); i+=1)
1433
+ {
1434
+ cSpring.DynamicNode f = node.springs.get(i).GetOther(node);
1435
+
1436
+ int c = i+1;
1437
+ // c = node.springs.get(i).nbcopies;
1438
+
1439
+ gl.glColor3f((c>>2)&1,(c>>1)&1,c&1);
1440
+ gl.glBegin(gl.GL_LINES);
1441
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1442
+ 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);
1443
+ gl.glEnd();
1444
+ }
1445
+ }
1446
+ }
1447
+
1448
+ gl.glLineWidth(1);
1449
+ }
1450
+
1451
+ gl.glEnable(gl.GL_LIGHTING);
1452
+ }
1453
+
10621454 /// INTERFACE
1455
+
1456
+ public void StartTriangles()
1457
+ {
1458
+ javax.media.opengl.GL gl = GetGL();
1459
+ gl.glBegin(gl.GL_TRIANGLES);
1460
+ }
1461
+
1462
+ public void EndTriangles()
1463
+ {
1464
+ GetGL().glEnd();
1465
+ }
1466
+
1467
+ void drawVertex(javax.media.opengl.GL gl, Vertex pv, boolean flipV, boolean selectmode)
1468
+ {
1469
+ if (!selectmode)
1470
+ {
1471
+ gl.glNormal3f((float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
1472
+ gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
1473
+
1474
+ if (flipV)
1475
+ gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
1476
+ else
1477
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1478
+ }
1479
+
1480
+ gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
1481
+ }
10631482
10641483 void SetColor(Object3D obj, Vertex p0)
10651484 {
....@@ -1238,7 +1657,7 @@
12381657 // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
12391658 }
12401659
1241
- void DrawMaterial(cMaterial material, boolean selected)
1660
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
12421661 {
12431662 CameraPane display = this;
12441663 //new Exception().printStackTrace();
....@@ -1254,18 +1673,18 @@
12541673 //col.getColorComponents(ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB), CameraPane.modelParams0);
12551674 if (!material.multiply)
12561675 {
1257
- display.color = color;
1676
+ display.color = material.color;
12581677 display.saturation = material.modulation;
12591678 }
12601679 else
12611680 {
1262
- display.color *= color*2;
1681
+ display.color *= material.color*2;
12631682 display.saturation *= material.modulation*2;
12641683 }
12651684
12661685 cColor.HSBtoRGB(display.color, display.saturation, 1, display.modelParams0);
12671686
1268
- float[] colorV = GrafreeD.colorV;
1687
+ float[] colorV = Grafreed.colorV;
12691688
12701689 /**/
12711690 if (display.DrawMode() == display.DEFAULT) // && display.RENDERPROGRAM == 0)
....@@ -1273,7 +1692,7 @@
12731692 colorV[0] = display.modelParams0[0] * material.diffuse;
12741693 colorV[1] = display.modelParams0[1] * material.diffuse;
12751694 colorV[2] = display.modelParams0[2] * material.diffuse;
1276
- colorV[3] = material.opacity;
1695
+ colorV[3] = 1; // material.opacity;
12771696
12781697 gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
12791698 //System.out.println("Opacity = " + opacity);
....@@ -1381,9 +1800,9 @@
13811800 display.modelParams7[2] = 0;
13821801 display.modelParams7[3] = 0;
13831802
1384
- display.modelParams6[0] = 100; // criss de bug de bump
1803
+ //display.modelParams6[0] = 100; // criss de bug de bump
13851804
1386
- Object3D.cVector2[] extparams = display.vector2buffer;
1805
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
13871806 if (extparams != null && extparams.length > 0 && extparams[0] != null)
13881807 {
13891808 display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
....@@ -1525,7 +1944,7 @@
15251944 void PushMatrix(double[][] matrix)
15261945 {
15271946 // GrafreeD.tracein(matrix);
1528
- PushMatrix(matrix,1);
1947
+ PushMatrix(matrix, 1);
15291948 }
15301949
15311950 void PushMatrix()
....@@ -1679,7 +2098,7 @@
16792098 //System.err.println("Oeil on");
16802099 OEIL = true;
16812100 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
1682
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2101
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
16832102 //pingthread.StepToTarget(true);
16842103 }
16852104
....@@ -1777,7 +2196,7 @@
17772196 System.err.println("LIVE = " + Globals.isLIVE());
17782197
17792198 if (!Globals.isLIVE()) // save sound
1780
- GrafreeD.savesound = true; // wav.save();
2199
+ Grafreed.savesound = true; // wav.save();
17812200 // else
17822201 repaint(); // start loop // may 2013
17832202 }
....@@ -1810,6 +2229,11 @@
18102229 public void ToggleBoxMode()
18112230 {
18122231 BOXMODE ^= true;
2232
+ }
2233
+
2234
+ public void ToggleZoomBoxMode()
2235
+ {
2236
+ ZOOMBOXMODE ^= true;
18132237 }
18142238
18152239 public void ToggleSmoothFocus()
....@@ -1889,7 +2313,7 @@
18892313
18902314 void ToggleDebug()
18912315 {
1892
- DEBUG ^= true;
2316
+ Globals.DEBUG ^= true;
18932317 }
18942318
18952319 void ToggleLookAt()
....@@ -1897,9 +2321,9 @@
18972321 LOOKAT ^= true;
18982322 }
18992323
1900
- void ToggleRandom()
2324
+ void ToggleSwitch()
19012325 {
1902
- RANDOM ^= true;
2326
+ SWITCH ^= true;
19032327 }
19042328
19052329 void ToggleHandles()
....@@ -1907,10 +2331,17 @@
19072331 HANDLES ^= true;
19082332 }
19092333
2334
+ Object3D paintFolder;
2335
+
19102336 void TogglePaint()
19112337 {
19122338 PAINTMODE ^= true;
19132339 paintcount = 0;
2340
+
2341
+ if (PAINTMODE)
2342
+ {
2343
+ paintFolder = GetFolder();
2344
+ }
19142345 }
19152346
19162347 void SwapCamera(int a, int b)
....@@ -2006,7 +2437,22 @@
20062437 {
20072438 return currentGL;
20082439 }
2009
-
2440
+
2441
+ static private BufferedImage CreateBim(TextureData texturedata)
2442
+ {
2443
+ Grafreed.Assert(texturedata != null);
2444
+
2445
+ int width = texturedata.getWidth();
2446
+ int height = texturedata.getHeight();
2447
+
2448
+ Buffer buffer = texturedata.getBuffer();
2449
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2450
+
2451
+ byte[] bytes = bytebuf.array();
2452
+
2453
+ return CreateBim(bytes, width, height);
2454
+ }
2455
+
20102456 /**/
20112457 class CacheTexture
20122458 {
....@@ -2015,28 +2461,31 @@
20152461
20162462 int resolution;
20172463
2018
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2464
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
20192465 {
2020
- texture = tex;
2466
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2467
+ texturedata = texdata;
20212468 resolution = res;
20222469 }
20232470 }
20242471 /**/
20252472
20262473 // 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>();
2474
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2475
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2476
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2477
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2478
+
20302479 int pigmentdepth = 0;
20312480 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
20322481 int bumpdepth = 0;
20332482 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
20342483 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
20352484 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2036
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2485
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
20372486 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
20382487
2039
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2488
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
20402489 {
20412490 TextureData texturedata = null;
20422491
....@@ -2055,13 +2504,34 @@
20552504 if (bump)
20562505 texturedata = ConvertBump(texturedata, false);
20572506
2058
- com.sun.opengl.util.texture.Texture texture =
2059
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2507
+// com.sun.opengl.util.texture.Texture texture =
2508
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
20602509
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);
2510
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2511
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
20632512
2064
- return texture;
2513
+ return texturedata;
2514
+ }
2515
+
2516
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2517
+ {
2518
+ TextureData texturedata = null;
2519
+
2520
+ try
2521
+ {
2522
+ texturedata =
2523
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2524
+ bim,
2525
+ true);
2526
+ } catch (Exception e)
2527
+ {
2528
+ throw new javax.media.opengl.GLException(e);
2529
+ }
2530
+
2531
+ if (bump)
2532
+ texturedata = ConvertBump(texturedata, false);
2533
+
2534
+ return texturedata;
20652535 }
20662536
20672537 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3134,6 +3604,8 @@
31343604
31353605 System.out.println("LOADING TEXTURE : " + name);
31363606
3607
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3608
+
31373609 //
31383610 if (false) // compressbit > 0)
31393611 {
....@@ -3838,6 +4310,7 @@
38384310
38394311 com.sun.opengl.util.texture.Texture CompressTexture2(String name)
38404312 {
4313
+ new Exception().printStackTrace();
38414314 System.exit(0);
38424315 com.sun.opengl.util.texture.Texture texture = null;
38434316
....@@ -7531,7 +8004,7 @@
75318004 String pigment = Object3D.GetPigment(tex);
75328005 String bump = Object3D.GetBump(tex);
75338006
7534
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8007
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
75358008 {
75368009 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
75378010 // System.out.println("; bump = " + bump);
....@@ -7546,11 +8019,69 @@
75468019 pigment = null;
75478020 }
75488021
7549
- ReleaseTexture(bump, true);
7550
- ReleaseTexture(pigment, false);
8022
+ ReleaseTexture(tex, true);
8023
+ ReleaseTexture(tex, false);
75518024 }
75528025
7553
- void ReleaseTexture(String tex, boolean bump)
8026
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
8027
+ {
8028
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8029
+ {
8030
+ return;
8031
+ }
8032
+
8033
+ if (tex == null)
8034
+ {
8035
+ ReleaseTexture(null, false);
8036
+ return;
8037
+ }
8038
+
8039
+ String pigment = Object3D.GetPigment(tex);
8040
+
8041
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8042
+ {
8043
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8044
+ // System.out.println("; bump = " + bump);
8045
+ }
8046
+
8047
+ if (pigment.equals(""))
8048
+ {
8049
+ pigment = null;
8050
+ }
8051
+
8052
+ ReleaseTexture(tex, false);
8053
+ }
8054
+
8055
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
8056
+ {
8057
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8058
+ {
8059
+ return;
8060
+ }
8061
+
8062
+ if (tex == null)
8063
+ {
8064
+ ReleaseTexture(null, true);
8065
+ return;
8066
+ }
8067
+
8068
+ String bump = Object3D.GetBump(tex);
8069
+
8070
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8071
+ {
8072
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8073
+ // System.out.println("; bump = " + bump);
8074
+ }
8075
+
8076
+ if (bump.equals(""))
8077
+ {
8078
+ bump = null;
8079
+ }
8080
+
8081
+ ReleaseTexture(tex, true);
8082
+ }
8083
+
8084
+ void ReleaseTexture(cTexture tex, boolean bump)
75548085 {
75558086 if (// DrawMode() != 0 || /*tex == null ||*/
75568087 ambientOcclusion ) // || !textureon)
....@@ -7561,7 +8092,7 @@
75618092 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
75628093
75638094 if (tex != null)
7564
- texture = textures.get(tex);
8095
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
75658096
75668097 // //assert( texture != null );
75678098 // if (texture == null)
....@@ -7653,7 +8184,55 @@
76538184 }
76548185 }
76558186
7656
- /*boolean*/ public void BindTextures(cTexture tex, int resolution) // INTERFACE
8187
+ /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
8188
+ {
8189
+// if (// DrawMode() != 0 || /*tex == null ||*/
8190
+// ambientOcclusion ) // || !textureon)
8191
+// {
8192
+// return; // false;
8193
+// }
8194
+//
8195
+// if (tex == null)
8196
+// {
8197
+// BindTexture(null,false,resolution);
8198
+// BindTexture(null,true,resolution);
8199
+// return;
8200
+// }
8201
+//
8202
+// String pigment = Object3D.GetPigment(tex);
8203
+// String bump = Object3D.GetBump(tex);
8204
+//
8205
+// usedtextures.add(pigment);
8206
+// usedtextures.add(bump);
8207
+//
8208
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8209
+// {
8210
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8211
+// // System.out.println("; bump = " + bump);
8212
+// }
8213
+//
8214
+// if (bump.equals(""))
8215
+// {
8216
+// bump = null;
8217
+// }
8218
+// if (pigment.equals(""))
8219
+// {
8220
+// pigment = null;
8221
+// }
8222
+//
8223
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8224
+// BindTexture(pigment, false, resolution);
8225
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8226
+// BindTexture(bump, true, resolution);
8227
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8228
+//
8229
+// return; // true;
8230
+
8231
+ BindPigmentTexture(tex, resolution);
8232
+ BindBumpTexture(tex, resolution);
8233
+ }
8234
+
8235
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
76578236 {
76588237 if (// DrawMode() != 0 || /*tex == null ||*/
76598238 ambientOcclusion ) // || !textureon)
....@@ -7664,17 +8243,47 @@
76648243 if (tex == null)
76658244 {
76668245 BindTexture(null,false,resolution);
7667
- BindTexture(null,true,resolution);
76688246 return;
76698247 }
76708248
76718249 String pigment = Object3D.GetPigment(tex);
8250
+
8251
+ usedtextures.add(tex);
8252
+
8253
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8254
+ {
8255
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8256
+ // System.out.println("; bump = " + bump);
8257
+ }
8258
+
8259
+ if (pigment.equals(""))
8260
+ {
8261
+ pigment = null;
8262
+ }
8263
+
8264
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8265
+ BindTexture(tex, false, resolution);
8266
+ }
8267
+
8268
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8269
+ {
8270
+ if (// DrawMode() != 0 || /*tex == null ||*/
8271
+ ambientOcclusion ) // || !textureon)
8272
+ {
8273
+ return; // false;
8274
+ }
8275
+
8276
+ if (tex == null)
8277
+ {
8278
+ BindTexture(null,true,resolution);
8279
+ return;
8280
+ }
8281
+
76728282 String bump = Object3D.GetBump(tex);
76738283
7674
- usedtextures.put(pigment, pigment);
7675
- usedtextures.put(bump, bump);
8284
+ usedtextures.add(tex);
76768285
7677
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8286
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
76788287 {
76798288 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
76808289 // System.out.println("; bump = " + bump);
....@@ -7684,43 +8293,82 @@
76848293 {
76858294 bump = null;
76868295 }
7687
- if (pigment.equals(""))
7688
- {
7689
- pigment = null;
7690
- }
76918296
7692
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
7693
- BindTexture(pigment, false, resolution);
76948297 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
7695
- BindTexture(bump, true, resolution);
8298
+ BindTexture(tex, true, resolution);
76968299 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
7697
-
7698
- return; // true;
76998300 }
77008301
7701
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution)
8302
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8303
+
8304
+ private boolean FileExists(String tex)
77028305 {
7703
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8306
+ if (missingTextures.contains(tex))
8307
+ {
8308
+ return false;
8309
+ }
8310
+
8311
+ boolean fileExists = new File(tex).exists();
8312
+
8313
+ if (!fileExists)
8314
+ {
8315
+ // If file exists, the "new File()" is not executed sgain
8316
+ missingTextures.add(tex);
8317
+ }
8318
+
8319
+ return fileExists;
8320
+ }
8321
+
8322
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
8323
+ {
8324
+ CacheTexture texturecache = null;
77048325
77058326 if (tex != null)
77068327 {
7707
- String texname = tex;
8328
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8329
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
77088330
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;
8331
+ if (texname.equals("") && texdata == null)
8332
+ {
8333
+ return null;
8334
+ }
8335
+
8336
+ String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
8337
+
8338
+// String[] split = tex.split("Textures");
8339
+// if (split.length > 1)
8340
+// texname = "/Users/nbriere/Textures" + split[split.length-1];
8341
+// else
8342
+// if (!texname.startsWith("/"))
8343
+// texname = "/Users/nbriere/Textures/" + texname;
8344
+ if (!FileExists(texname))
8345
+ {
8346
+ texname = fallbackTextureName;
8347
+ }
77158348
77168349 if (CACHETEXTURE)
7717
- texture = textures.get(texname); // TEXTURE CACHE
7718
-
7719
- TextureData texturedata = null;
7720
-
7721
- if (texture == null || texture.resolution < resolution)
77228350 {
7723
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8351
+ if (texdata == null)
8352
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8353
+ else
8354
+ texturecache = bimtextures.get(texdata);
8355
+ }
8356
+
8357
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8358
+ {
8359
+ TextureData texturedata = null;
8360
+
8361
+ if (texdata != null)
8362
+ {
8363
+ BufferedImage bim = //new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8364
+
8365
+ CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8366
+
8367
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8368
+ bimtextures.put(texdata, texturecache);
8369
+ }
8370
+ else
8371
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
77248372 {
77258373 assert(!bump);
77268374 // if (bump)
....@@ -7731,19 +8379,23 @@
77318379 // }
77328380 // else
77338381 // {
7734
- texture = textures.get(tex);
7735
- if (texture == null)
8382
+ // texturecache = textures.get(texname); // suspicious
8383
+ if (texturecache == null)
77368384 {
7737
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8385
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
77388386 }
8387
+ else
8388
+ new Exception().printStackTrace();
77398389 // }
77408390 } else
7741
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8391
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
77428392 {
77438393 assert(bump);
7744
- texture = textures.get(tex);
7745
- if (texture == null)
7746
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8394
+ // texturecache = textures.get(texname); // suspicious
8395
+ if (texturecache == null)
8396
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8397
+ else
8398
+ new Exception().printStackTrace();
77478399 } else
77488400 {
77498401 //if (tex.equals("IMMORTAL"))
....@@ -7751,11 +8403,13 @@
77518403 // texture = GetResourceTexture("default.png");
77528404 //} else
77538405 //{
7754
- if (tex.equals("WHITE_NOISE"))
8406
+ if (texname.endsWith("WHITE_NOISE"))
77558407 {
7756
- texture = textures.get(tex);
7757
- if (texture == null)
7758
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8408
+ // texturecache = textures.get(texname); // suspicious
8409
+ if (texturecache == null)
8410
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8411
+ else
8412
+ new Exception().printStackTrace();
77598413 } else
77608414 {
77618415 if (textureon)
....@@ -7780,7 +8434,7 @@
77808434 }
77818435
77828436 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
7783
- if (!new File(cachename).exists())
8437
+ if (!FileExists(cachename))
77848438 cachename = texname;
77858439 else
77868440 processbump = false; // don't process bump map again
....@@ -7802,7 +8456,7 @@
78028456 }
78038457
78048458 cachename = texname.substring(0, texname.length()-4)+ext+".png";
7805
- if (!new File(cachename).exists())
8459
+ if (!FileExists(cachename))
78068460 cachename = texname;
78078461 else
78088462 processbump = false; // don't process bump map again
....@@ -7811,20 +8465,22 @@
78118465 texturedata = GetFileTexture(cachename, processbump, resolution);
78128466
78138467
7814
- if (texturedata != null)
7815
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8468
+ if (texturedata == null)
8469
+ throw new Exception();
8470
+
8471
+ texturecache = new CacheTexture(texturedata,resolution);
78168472 //texture = GetTexture(tex, bump);
78178473 }
78188474 }
78198475 //}
78208476 }
78218477
7822
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8478
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
78238479 {
78248480 //return false;
78258481
78268482 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
7827
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8483
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
78288484 {
78298485 // String ext = "_highres";
78308486 // if (REDUCETEXTURE)
....@@ -7841,52 +8497,17 @@
78418497 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
78428498 if (!cachefile.exists())
78438499 {
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))
8500
+ //if (texturedata.getWidth() == texturedata.getHeight())
78538501 {
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);
8502
+ BufferedImage rendImage = CreateBim(texturedata);
8503
+
78848504 ImageWriter writer = null;
78858505 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
78868506 if (iter.hasNext()) {
78878507 writer = (ImageWriter)iter.next();
78888508 }
7889
- float compressionQuality = 0.9f;
8509
+
8510
+ float compressionQuality = 0.85f;
78908511 try
78918512 {
78928513 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -7903,18 +8524,20 @@
79038524 }
79048525 }
79058526 }
7906
-
8527
+
8528
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8529
+
79078530 //System.out.println("Texture = " + tex);
7908
- if (textures.containsKey(texname))
8531
+ if (textures.containsKey(tex))
79098532 {
7910
- CacheTexture thetex = textures.get(texname);
8533
+ CacheTexture thetex = textures.get(tex);
79118534 thetex.texture.disable();
79128535 thetex.texture.dispose();
7913
- textures.remove(texname);
8536
+ textures.remove(tex);
79148537 }
79158538
7916
- texture.texturedata = texturedata;
7917
- textures.put(texname, texture);
8539
+ //texture.texturedata = texturedata;
8540
+ textures.put(tex, texturecache);
79188541
79198542 // newtex = true;
79208543 }
....@@ -7930,10 +8553,41 @@
79308553 }
79318554 }
79328555
7933
- return texture;
8556
+ return texturecache;
79348557 }
79358558
7936
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution)
8559
+ static void EmbedTextures(cTexture tex)
8560
+ {
8561
+ if (tex.pigmentdata == null)
8562
+ {
8563
+ String texname = Object3D.GetPigment(tex);
8564
+
8565
+ CacheTexture texturecache = texturepigment.get(tex);
8566
+
8567
+ if (texturecache != null)
8568
+ {
8569
+ tex.pigmentdata = ((ByteBuffer)texturecache.texturedata.getBuffer()).array();
8570
+ tex.pw = texturecache.texturedata.getWidth();
8571
+ tex.ph = texturecache.texturedata.getHeight();
8572
+ }
8573
+ }
8574
+
8575
+ if (tex.bumpdata == null)
8576
+ {
8577
+ String texname = Object3D.GetBump(tex);
8578
+
8579
+ CacheTexture texturecache = texturebump.get(tex);
8580
+
8581
+ if (texturecache != null)
8582
+ {
8583
+ tex.bumpdata = ((ByteBuffer)texturecache.texturedata.getBuffer()).array();
8584
+ tex.bw = texturecache.texturedata.getWidth();
8585
+ tex.bh = texturecache.texturedata.getHeight();
8586
+ }
8587
+ }
8588
+ }
8589
+
8590
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
79378591 {
79388592 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
79398593
....@@ -7951,21 +8605,21 @@
79518605 return texture!=null?texture.texture:null;
79528606 }
79538607
7954
- public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution)
8608
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
79558609 {
79568610 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
79578611
79588612 return texture!=null?texture.texturedata:null;
79598613 }
79608614
7961
- boolean BindTexture(String tex, boolean bump, int resolution)
8615
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
79628616 {
79638617 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
79648618 {
79658619 return false;
79668620 }
79678621
7968
- boolean newtex = false;
8622
+ //boolean newtex = false;
79698623
79708624 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
79718625
....@@ -7997,7 +8651,7 @@
79978651 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
79988652 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
79998653
8000
- return newtex;
8654
+ return true; // Warning: not used.
80018655 }
80028656
80038657 ShadowBuffer shadowPBuf;
....@@ -8835,11 +9489,35 @@
88359489 jy8[3] = 0.5f;
88369490 }
88379491
8838
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9492
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
88399493 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
88409494 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
88419495 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
88429496
9497
+ void ResetOptions()
9498
+ {
9499
+ options1[0] = 100;
9500
+ options1[1] = 0.025f;
9501
+ options1[2] = 0.01f;
9502
+ options1[3] = 0;
9503
+ options1[4] = 0;
9504
+
9505
+ options2[0] = 0;
9506
+ options2[1] = 0.75f;
9507
+ options2[2] = 0;
9508
+ options2[3] = 0;
9509
+
9510
+ options3[0] = 1;
9511
+ options3[1] = 1;
9512
+ options3[2] = 1;
9513
+ options3[3] = 0;
9514
+
9515
+ options4[0] = 1;
9516
+ options4[1] = 0;
9517
+ options4[2] = 1;
9518
+ options4[3] = 0;
9519
+ }
9520
+
88439521 static int imagecount = 0; // movie generation
88449522
88459523 static int jitter = 0;
....@@ -8935,8 +9613,8 @@
89359613 assert (parentcam != renderCamera);
89369614
89379615 if (renderCamera != lightCamera)
8938
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8939
- LA.matConcat(matrix, parentcam.toParent, matrix);
9616
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9617
+ LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
89409618
89419619 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
89429620
....@@ -8951,8 +9629,8 @@
89519629 LA.matCopy(renderCamera.fromScreen, matrix);
89529630
89539631 if (renderCamera != lightCamera)
8954
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8955
- LA.matConcat(parentcam.fromParent, matrix, matrix);
9632
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9633
+ LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
89569634
89579635 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
89589636
....@@ -9024,7 +9702,7 @@
90249702 //gl.glFlush();
90259703 gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE);
90269704
9027
- if (ANIMATION && ABORTED)
9705
+ if (Globals.ANIMATION && ABORTED)
90289706 {
90299707 System.err.println(" ABORTED FRAME");
90309708 break;
....@@ -9054,7 +9732,7 @@
90549732 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
90559733
90569734 // save image
9057
- if (ANIMATION && !ABORTED)
9735
+ if (Globals.ANIMATION && !ABORTED)
90589736 {
90599737 VPwidth = viewport[2];
90609738 VPheight = viewport[3];
....@@ -9165,11 +9843,11 @@
91659843
91669844 // imagecount++;
91679845
9168
- String fullname = filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
9846
+ String fullname = Globals.filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
91699847
91709848 if (!BOXMODE)
91719849 {
9172
- System.out.println("image: " + fullname + " (wav cursor=" + (GrafreeD.wav.cursor / 735 / 4) + ")");
9850
+ System.out.println("image: " + fullname + " (wav cursor=" + (Grafreed.wav.cursor / 735 / 4) + ")");
91739851 }
91749852
91759853 if (!BOXMODE)
....@@ -9207,7 +9885,7 @@
92079885 ABORTED = false;
92089886 }
92099887 else
9210
- GrafreeD.wav.cursor += 735 * ACSIZE;
9888
+ Grafreed.wav.cursor += 735 * ACSIZE;
92119889
92129890 if (false)
92139891 {
....@@ -9870,11 +10548,11 @@
987010548
987110549 public void display(GLAutoDrawable drawable)
987210550 {
9873
- if (GrafreeD.savesound && GrafreeD.hassound)
10551
+ if (Grafreed.savesound && Grafreed.hassound)
987410552 {
9875
- GrafreeD.wav.save();
9876
- GrafreeD.savesound = false;
9877
- GrafreeD.hassound = false;
10553
+ Grafreed.wav.save();
10554
+ Grafreed.savesound = false;
10555
+ Grafreed.hassound = false;
987810556 }
987910557 // if (DEBUG_SELECTION)
988010558 // {
....@@ -9950,6 +10628,7 @@
995010628 ANTIALIAS = 0;
995110629 //System.out.println("RESTART");
995210630 AAtimer.restart();
10631
+ Globals.TIMERRUNNING = true;
995310632 }
995410633 }
995510634 }
....@@ -10004,7 +10683,7 @@
1000410683 Object3D theobject = object;
1000510684 Object3D theparent = object.parent;
1000610685 object.parent = null;
10007
- object = (Object3D)GrafreeD.clone(object);
10686
+ object = (Object3D)Grafreed.clone(object);
1000810687 object.Stripify();
1000910688 if (theobject.selection == null || theobject.selection.Size() == 0)
1001010689 theobject.PreprocessOcclusion(this);
....@@ -10017,13 +10696,14 @@
1001710696 ambientOcclusion = false;
1001810697 }
1001910698
10020
- if (Globals.lighttouched && DrawMode() == DEFAULT && !lightMode) // && !FROZEN)
10699
+ if (//Globals.lighttouched &&
10700
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1002110701 {
1002210702 //if (RENDERSHADOW) // ?
1002310703 if (!IsFrozen())
1002410704 {
1002510705 // dec 2012
10026
- if (!ambientOcclusion && !(!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0))
10706
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
1002710707 {
1002810708 Globals.framecount++;
1002910709 shadowbuffer.display();
....@@ -10150,8 +10830,8 @@
1015010830
1015110831 // if (parentcam != renderCamera) // not a light
1015210832 if (cam != lightCamera)
10153
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10154
- LA.matConcat(matrix, parentcam.toParent, matrix);
10833
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10834
+ LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
1015510835
1015610836 for (int j = 0; j < 4; j++)
1015710837 {
....@@ -10165,8 +10845,8 @@
1016510845
1016610846 // if (parentcam != renderCamera) // not a light
1016710847 if (cam != lightCamera)
10168
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10169
- LA.matConcat(parentcam.fromParent, matrix, matrix);
10848
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10849
+ LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
1017010850
1017110851 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1017210852
....@@ -10425,7 +11105,16 @@
1042511105 // Bump noise
1042611106 gl.glActiveTexture(GL.GL_TEXTURE6);
1042711107 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
10428
- BindTexture(NOISE_TEXTURE, false, 2);
11108
+
11109
+ try
11110
+ {
11111
+ BindTexture(NOISE_TEXTURE, false, 2);
11112
+ }
11113
+ catch (Exception e)
11114
+ {
11115
+ System.err.println("FAILED: " + NOISE_TEXTURE);
11116
+ }
11117
+
1042911118
1043011119 gl.glActiveTexture(GL.GL_TEXTURE0);
1043111120 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -10448,9 +11137,9 @@
1044811137
1044911138 gl.glMatrixMode(GL.GL_MODELVIEW);
1045011139
10451
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10452
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10453
-//gl.glEnable(gl.GL_MULTISAMPLE);
11140
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11141
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11142
+gl.glEnable(gl.GL_MULTISAMPLE);
1045411143 } else
1045511144 {
1045611145 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -10461,7 +11150,7 @@
1046111150 //System.out.println("BLENDING ON");
1046211151 gl.glEnable(GL.GL_BLEND);
1046311152 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
10464
-
11153
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1046511154 gl.glMatrixMode(gl.GL_PROJECTION);
1046611155 gl.glLoadIdentity();
1046711156
....@@ -10550,8 +11239,8 @@
1055011239 System.err.println("parentcam != renderCamera");
1055111240
1055211241 // if (cam != lightCamera)
10553
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10554
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11242
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11243
+ LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
1055511244 }
1055611245
1055711246 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -10572,8 +11261,8 @@
1057211261 if (true) // TODO
1057311262 {
1057411263 if (cam != lightCamera)
10575
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10576
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11264
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11265
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
1057711266 }
1057811267
1057911268 LA.xformPos(light0, cam.toScreen, light0);
....@@ -10889,8 +11578,14 @@
1088911578 {
1089011579 renderpass++;
1089111580 // System.out.println("Draw object... ");
11581
+ STEP = 1;
1089211582 if (FAST) // in case there is no script
10893
- STEP = 16;
11583
+ STEP = 8;
11584
+
11585
+ if (CURRENTANTIALIAS == 0 || ACSIZE == 1)
11586
+ {
11587
+ STEP *= 4;
11588
+ }
1089411589
1089511590 //object.FullInvariants();
1089611591
....@@ -10904,23 +11599,44 @@
1090411599 e.printStackTrace();
1090511600 }
1090611601
10907
- if (GrafreeD.RENDERME > 0)
10908
- GrafreeD.RENDERME--; // mechante magouille
11602
+ if (Grafreed.RENDERME > 0)
11603
+ Grafreed.RENDERME--; // mechante magouille
1090911604
1091011605 Globals.ONESTEP = false;
1091111606 }
1091211607
1091311608 static boolean zoomonce = false;
1091411609
11610
+ static void CreateSelectedPoint()
11611
+ {
11612
+ if (selectedpoint == null)
11613
+ {
11614
+ debugpointG = new Sphere();
11615
+ debugpointP = new Sphere();
11616
+ debugpointC = new Sphere();
11617
+ debugpointR = new Sphere();
11618
+
11619
+ selectedpoint = new Superellipsoid();
11620
+
11621
+ for (int i=0; i<8; i++)
11622
+ {
11623
+ debugpoints[i] = new Sphere();
11624
+ }
11625
+ }
11626
+ }
11627
+
1091511628 void DrawObject(GL gl, boolean draw)
1091611629 {
11630
+ // To clear camera values
11631
+ ResetOptions();
11632
+
1091711633 //System.out.println("DRAW OBJECT " + mouseDown);
1091811634 // DrawMode() = SELECTION;
1091911635 //GL gl = getGL();
1092011636 if ((TRACK || SHADOWTRACK) || zoomonce)
1092111637 {
1092211638 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
10923
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11639
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1092411640 pingthread.StepToTarget(true); // true);
1092511641 // zoomonce = false;
1092611642 }
....@@ -10975,7 +11691,14 @@
1097511691
1097611692 usedtextures.clear();
1097711693
10978
- BindTextures(DEFAULT_TEXTURES, 2);
11694
+ try
11695
+ {
11696
+ BindTextures(DEFAULT_TEXTURES, 2);
11697
+ }
11698
+ catch (Exception e)
11699
+ {
11700
+ System.err.println("FAILED: " + DEFAULT_TEXTURES);
11701
+ }
1097911702 }
1098011703 //System.out.println("--> " + stackdepth);
1098111704 // GrafreeD.traceon();
....@@ -10985,8 +11708,9 @@
1098511708
1098611709 if (DrawMode() == DEFAULT)
1098711710 {
10988
- if (DEBUG)
11711
+ if (Globals.DEBUG)
1098911712 {
11713
+ CreateSelectedPoint();
1099011714 float radius = 0.05f;
1099111715 if (selectedpoint.radius != radius)
1099211716 {
....@@ -11040,20 +11764,32 @@
1104011764 ReleaseTextures(DEFAULT_TEXTURES);
1104111765
1104211766 if (CLEANCACHE)
11043
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11767
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1104411768 {
11045
- String tex = e.nextElement();
11769
+ cTexture tex = e.nextElement();
1104611770
1104711771 // System.out.println("Texture --------- " + tex);
1104811772
11049
- if (tex.equals("WHITE_NOISE"))
11773
+ if (tex.equals("WHITE_NOISE:"))
1105011774 continue;
1105111775
11052
- if (!usedtextures.containsKey(tex))
11776
+ if (!usedtextures.contains(tex))
1105311777 {
11778
+ CacheTexture gettex = texturepigment.get(tex);
1105411779 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11055
- textures.get(tex).texture.dispose();
11056
- textures.remove(tex);
11780
+ if (gettex != null)
11781
+ {
11782
+ gettex.texture.dispose();
11783
+ texturepigment.remove(tex);
11784
+ }
11785
+
11786
+ gettex = texturebump.get(tex);
11787
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11788
+ if (gettex != null)
11789
+ {
11790
+ gettex.texture.dispose();
11791
+ texturebump.remove(tex);
11792
+ }
1105711793 }
1105811794 }
1105911795 }
....@@ -11066,7 +11802,14 @@
1106611802 if (checker != null && DrawMode() == DEFAULT)
1106711803 {
1106811804 //BindTexture(IMMORTAL_TEXTURE);
11069
- BindTextures(checker.GetTextures(), checker.texres);
11805
+ try
11806
+ {
11807
+ BindTextures(checker.GetTextures(), checker.texres);
11808
+ }
11809
+ catch (Exception e)
11810
+ {
11811
+ System.err.println("FAILED: " + checker.GetTextures());
11812
+ }
1107011813 // NEAREST
1107111814 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
1107211815 DrawChecker(gl);
....@@ -11148,7 +11891,7 @@
1114811891 return;
1114911892 }
1115011893
11151
- String string = obj.GetToolTip();
11894
+ String string = obj.toString(); //.GetToolTip();
1115211895
1115311896 GL gl = GetGL();
1115411897
....@@ -11465,8 +12208,8 @@
1146512208 //obj.TransformToWorld(light, light);
1146612209 for (int i = tp.size(); --i >= 0;)
1146712210 {
11468
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
11469
- LA.xformPos(light, tp.get(i).toParent, light);
12211
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12212
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1147012213 }
1147112214
1147212215
....@@ -11483,8 +12226,8 @@
1148312226 parentcam = cameras[0];
1148412227 }
1148512228
11486
- for (int count = parentcam.GetTransformCount(); --count>=0;)
11487
- LA.xformPos(light, parentcam.toParent, light); // may 2013
12229
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
12230
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1148812231
1148912232 LA.xformPos(light, renderCamera.toScreen, light);
1149012233
....@@ -12098,8 +12841,8 @@
1209812841
1209912842 // display shadow only (bump == 0)
1210012843 "SUB temp.x, half.x, shadow.x;" +
12101
- "MOV temp.y, -params6.x;" +
12102
- "SLT temp.z, temp.y, zero.x;" +
12844
+ "MOV temp.y, -params5.z;" + // params6.x;" +
12845
+ "SLT temp.z, temp.y, -one2048th.x;" +
1210312846 "SUB temp.y, one.x, temp.z;" +
1210412847 "MUL temp.x, temp.x, temp.y;" +
1210512848 "KIL temp.x;" +
....@@ -12228,8 +12971,10 @@
1222812971 "MAX ndotl.x, ndotl.x, -ndotl.x;" +
1222912972
1223012973 "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
12974
+ // Tuning for default skin
12975
+ //"ADD temp.x, temp.x, options2.z;" + // lightsheen
12976
+ "MAD temp.x, options2.z, half.y, temp.x;" + // lightsheen
12977
+ "ADD temp.y, one.y, options2.y;" + // subsurface
1223312978 "MUL temp.x, temp.x, temp.y;" +
1223412979
1223512980 "MUL saturation, saturation, temp.xxxx;" +
....@@ -12428,7 +13173,7 @@
1242813173 //once = true;
1242913174 }
1243013175
12431
- System.out.print("Program #" + mode + "; length = " + program.length());
13176
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1243213177 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1243313178 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1243413179
....@@ -12561,12 +13306,16 @@
1256113306
1256213307 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1256313308 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13309
+
13310
+ // Compare fragment depth in light space with shadowmap.
1256413311 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1256513312 "SGE temp.y, temp.x, zero.x;" +
12566
- "SUB " + shadow + ".y, one.x, temp.y;" +
13313
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13314
+
13315
+ // Reverse comparison
1256713316 "SUB temp.x, one.x, temp.x;" +
1256813317 "MUL " + shadow + ".x, temp.x, temp.y;" +
12569
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13318
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1257013319 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1257113320
1257213321 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -12580,6 +13329,10 @@
1258013329 // No shadow for backface
1258113330 "DP3 temp.x, normal, lightd;" +
1258213331 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13332
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13333
+
13334
+ // No shadow when out of frustrum
13335
+ "SGE temp.x, " + depth + ".z, one.z;" +
1258313336 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1258413337 "";
1258513338 }
....@@ -12726,7 +13479,8 @@
1272613479 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1272713480 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1272813481 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
12729
- Object3D.cVector2[] vector2buffer;
13482
+
13483
+ //Object3D.cVector2[] vector2buffer;
1273013484
1273113485 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1273213486 // OUT : diff, spec
....@@ -12742,9 +13496,10 @@
1274213496 "DP3 " + dest + ".z," + "normals," + "eye;" +
1274313497 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1274413498 //"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;" +
13499
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13500
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13501
+
13502
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1274813503 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1274913504 "RCP " + dest + ".w," + dest + ".w;" +
1275013505 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13138,7 +13893,7 @@
1313813893 public void mousePressed(MouseEvent e)
1313913894 {
1314013895 //System.out.println("mousePressed: " + e);
13141
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
13896
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1314213897 }
1314313898
1314413899 static long prevtime = 0;
....@@ -13165,6 +13920,7 @@
1316513920
1316613921 //System.err.println("Dtime = " + Dtime + "; units = " + e.getUnitsToScroll() + "; ratio (units/ms) = " + ratio);
1316713922
13923
+ if (BUTTONLESSWHEEL)
1316813924 if (Math.abs(ratio) < 0.1 || Math.abs(Dtime) == 0) // < 30)
1316913925 {
1317013926 return;
....@@ -13173,7 +13929,7 @@
1317313929 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
1317413930
1317513931 // TIMER
13176
- if (!wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
13932
+ if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
1317713933 {
1317813934 keepboxmode = BOXMODE;
1317913935 keepsupport = SUPPORT;
....@@ -13213,8 +13969,8 @@
1321313969 // mode |= META;
1321413970 //}
1321513971
13216
- SetMouseMode(WHEEL | e.getModifiersEx());
13217
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
13972
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
13973
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1321813974 anchorX = ax;
1321913975 anchorY = ay;
1322013976 prevX = px;
....@@ -13248,6 +14004,7 @@
1324814004 else
1324914005 if (evt.getSource() == AAtimer)
1325014006 {
14007
+ Globals.TIMERRUNNING = false;
1325114008 if (mouseDown)
1325214009 {
1325314010 //new Exception().printStackTrace();
....@@ -13273,6 +14030,10 @@
1327314030 // LIVE = waslive;
1327414031 // wasliveok = true;
1327514032 // waslive = false;
14033
+
14034
+ // May 2019 Forget it:
14035
+ if (true)
14036
+ return;
1327614037
1327714038 // source == timer
1327814039 if (mouseDown)
....@@ -13303,7 +14064,7 @@
1330314064
1330414065 // fev 2014???
1330514066 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13306
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14067
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1330714068 pingthread.StepToTarget(true); // true);
1330814069 }
1330914070 // if (!LIVE)
....@@ -13312,12 +14073,13 @@
1331214073
1331314074 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1331414075
13315
- void clickStart(int x, int y, int modifiers)
14076
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1331614077 {
1331714078 if (!wasliveok)
1331814079 return;
1331914080
1332014081 AAtimer.restart(); //
14082
+ Globals.TIMERRUNNING = true;
1332114083
1332214084 // waslive = LIVE;
1332314085 // LIVE = false;
....@@ -13329,7 +14091,7 @@
1332914091 // touched = true; // main DL
1333014092 if (isRenderer)
1333114093 {
13332
- SetMouseMode(modifiers);
14094
+ SetMouseMode(modifiers, modifiersex);
1333314095 }
1333414096
1333514097 selectX = anchorX = x;
....@@ -13342,7 +14104,7 @@
1334214104 clicked = true;
1334314105 hold = false;
1334414106
13345
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14107
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1334614108 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1334714109 {
1334814110 // System.out.println("RESTART II " + modifiers);
....@@ -13373,7 +14135,7 @@
1337314135 info.camera = renderCamera;
1337414136 info.x = x;
1337514137 info.y = y;
13376
- info.modifiers = modifiers;
14138
+ info.modifiers = modifiersex;
1337714139 editObj = object.doEditClick(info, 0);
1337814140 if (!editObj)
1337914141 {
....@@ -13390,11 +14152,14 @@
1339014152
1339114153 public void mouseDragged(MouseEvent e)
1339214154 {
14155
+ Globals.MOUSEDRAGGED = true;
14156
+
14157
+ //System.out.println("mouseDragged: " + e);
1339314158 if (isRenderer)
1339414159 movingcamera = true;
14160
+
1339514161 //if (drawing)
1339614162 //return;
13397
- //System.out.println("mouseDragged: " + e);
1339814163 if ((e.getModifiersEx() & CTRL) != 0
1339914164 || (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen())
1340014165 {
....@@ -13402,7 +14167,7 @@
1340214167 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1340314168 }
1340414169 else
13405
- drag(e.getX(), e.getY(), e.getModifiersEx());
14170
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1340614171
1340714172 //try { Thread.sleep(1); } catch (Exception ex) {}
1340814173 }
....@@ -13575,6 +14340,7 @@
1357514340
1357614341 public void run()
1357714342 {
14343
+ new Exception().printStackTrace();
1357814344 System.exit(0);
1357914345 for (;;)
1358014346 {
....@@ -13638,7 +14404,7 @@
1363814404 {
1363914405 Globals.lighttouched = true;
1364014406 }
13641
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14407
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1364214408 }
1364314409 //else
1364414410 }
....@@ -13652,12 +14418,12 @@
1365214418 void GoDown(int mod)
1365314419 {
1365414420 MODIFIERS |= COMMAND;
13655
- /*
14421
+ /**/
1365614422 if((mod&SHIFT) == SHIFT)
1365714423 manipCamera.RotatePosition(0, -speed);
1365814424 else
13659
- manipCamera.BackForth(0, -speed*delta, getWidth());
13660
- */
14425
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14426
+ /**/
1366114427 if ((mod & SHIFT) == SHIFT)
1366214428 {
1366314429 mouseMode = mouseMode; // VR??
....@@ -13673,12 +14439,12 @@
1367314439 void GoUp(int mod)
1367414440 {
1367514441 MODIFIERS |= COMMAND;
13676
- /*
14442
+ /**/
1367714443 if((mod&SHIFT) == SHIFT)
1367814444 manipCamera.RotatePosition(0, speed);
1367914445 else
13680
- manipCamera.BackForth(0, speed*delta, getWidth());
13681
- */
14446
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14447
+ /**/
1368214448 if ((mod & SHIFT) == SHIFT)
1368314449 {
1368414450 mouseMode = mouseMode;
....@@ -13694,12 +14460,12 @@
1369414460 void GoLeft(int mod)
1369514461 {
1369614462 MODIFIERS |= COMMAND;
13697
- /*
14463
+ /**/
1369814464 if((mod&SHIFT) == SHIFT)
13699
- manipCamera.RotatePosition(speed, 0);
13700
- else
1370114465 manipCamera.Translate(speed*delta, 0, getWidth());
13702
- */
14466
+ else
14467
+ manipCamera.RotatePosition(speed, 0);
14468
+ /**/
1370314469 if ((mod & SHIFT) == SHIFT)
1370414470 {
1370514471 mouseMode = mouseMode;
....@@ -13715,12 +14481,12 @@
1371514481 void GoRight(int mod)
1371614482 {
1371714483 MODIFIERS |= COMMAND;
13718
- /*
14484
+ /**/
1371914485 if((mod&SHIFT) == SHIFT)
13720
- manipCamera.RotatePosition(-speed, 0);
13721
- else
1372214486 manipCamera.Translate(-speed*delta, 0, getWidth());
13723
- */
14487
+ else
14488
+ manipCamera.RotatePosition(-speed, 0);
14489
+ /**/
1372414490 if ((mod & SHIFT) == SHIFT)
1372514491 {
1372614492 mouseMode = mouseMode;
....@@ -13738,7 +14504,7 @@
1373814504 int X, Y;
1373914505 boolean SX, SY;
1374014506
13741
- void drag(int x, int y, int modifiers)
14507
+ void drag(int x, int y, int modifiers, int modifiersex)
1374214508 {
1374314509 if (IsFrozen())
1374414510 {
....@@ -13747,17 +14513,17 @@
1374714513
1374814514 drag = true; // NEW
1374914515
13750
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14516
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1375114517
1375214518 X = x;
1375314519 Y = y;
1375414520 // floating state for animation
13755
- MODIFIERS = modifiers;
13756
- modifiers &= ~1024;
14521
+ MODIFIERS = modifiersex;
14522
+ modifiersex &= ~1024;
1375714523 if (false) // modifiers != 0)
1375814524 {
1375914525 //new Exception().printStackTrace();
13760
- System.out.println("mouseDragged: " + modifiers);
14526
+ System.out.println("mouseDragged: " + modifiersex);
1376114527 System.out.println("SHIFT = " + SHIFT);
1376214528 System.out.println("CONTROL = " + COMMAND);
1376314529 System.out.println("META = " + META);
....@@ -13777,7 +14543,8 @@
1377714543 info.camera = renderCamera;
1377814544 info.x = x;
1377914545 info.y = y;
13780
- object.editWindow.copy.doEditDrag(info);
14546
+ object.GetWindow().copy
14547
+ .doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1378114548 } else
1378214549 {
1378314550 if (x < startX)
....@@ -13929,7 +14696,6 @@
1392914696 public void mouseMoved(MouseEvent e)
1393014697 {
1393114698 //System.out.println("mouseMoved: " + e);
13932
-
1393314699 if (isRenderer)
1393414700 return;
1393514701
....@@ -13942,7 +14708,9 @@
1394214708 ci.camera = renderCamera;
1394314709 if (!isRenderer)
1394414710 {
13945
- if (object.editWindow.copy.doEditClick(ci, 0))
14711
+ //ObjEditor editWindow = object.editWindow;
14712
+ //Object3D copy = editWindow.copy;
14713
+ if (object.doEditClick(ci, 0))
1394614714 {
1394714715 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1394814716 } else
....@@ -13954,7 +14722,11 @@
1395414722
1395514723 public void mouseReleased(MouseEvent e)
1395614724 {
14725
+ Globals.MOUSEDRAGGED = false;
14726
+
1395714727 movingcamera = false;
14728
+ X = 0; // getBounds().width/2;
14729
+ Y = 0; // getBounds().height/2;
1395814730 //System.out.println("mouseReleased: " + e);
1395914731 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1396014732 }
....@@ -13977,9 +14749,9 @@
1397714749 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1397814750 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1397914751
13980
- if (control || command || IsFrozen())
14752
+// No delay if (control || command || IsFrozen())
1398114753 timeout = true;
13982
- else
14754
+// ?? May 2019 else
1398314755 // timer.setDelay((modifiers & 128) != 0?0:350);
1398414756 mouseDown = false;
1398514757 if (!control && !command) // june 2013
....@@ -14089,7 +14861,7 @@
1408914861 System.out.println("keyReleased: " + e);
1409014862 }
1409114863
14092
- void SetMouseMode(int modifiers)
14864
+ void SetMouseMode(int modifiers, int modifiersex)
1409314865 {
1409414866 //System.out.println("SetMouseMode = " + modifiers);
1409514867 //modifiers &= ~1024;
....@@ -14101,25 +14873,25 @@
1410114873 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1410214874 // return;
1410314875 //System.out.println("SetMode = " + modifiers);
14104
- if ((modifiers & WHEEL) == WHEEL)
14876
+ if ((modifiersex & WHEEL) == WHEEL)
1410514877 {
1410614878 mouseMode |= ZOOM;
1410714879 }
1410814880
1410914881 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
14110
- if (capsLocked || (modifiers & META) == META)
14882
+ if (capsLocked) // || (modifiers & META) == META)
1411114883 {
1411214884 mouseMode |= VR; // BACKFORTH;
1411314885 }
14114
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
14886
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1411514887 {
1411614888 mouseMode |= SELECT;
1411714889 }
14118
- if ((modifiers & COMMAND) == COMMAND)
14890
+ if ((modifiersex & COMMAND) == COMMAND)
1411914891 {
1412014892 mouseMode |= SELECT;
1412114893 }
14122
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
14894
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
1412314895 {
1412414896 mouseMode &= ~VR;
1412514897 mouseMode |= TRANSLATE;
....@@ -14148,7 +14920,7 @@
1414814920
1414914921 if (isRenderer) //
1415014922 {
14151
- SetMouseMode(modifiers);
14923
+ SetMouseMode(0, modifiers);
1415214924 }
1415314925
1415414926 Globals.theRenderer.keyPressed(key);
....@@ -14210,7 +14982,8 @@
1421014982 // break;
1421114983 case 'T':
1421214984 CACHETEXTURE ^= true;
14213
- textures.clear();
14985
+ texturepigment.clear();
14986
+ texturebump.clear();
1421414987 // repaint();
1421514988 break;
1421614989 case 'Y':
....@@ -14295,7 +15068,9 @@
1429515068 case 'E' : COMPACT ^= true;
1429615069 repaint();
1429715070 break;
14298
- case 'W' : DEBUGHSB ^= true;
15071
+ case 'W' : // Wide Window (fullscreen)
15072
+ //DEBUGHSB ^= true;
15073
+ ObjEditor.theFrame.ToggleFullScreen();
1429915074 repaint();
1430015075 break;
1430115076 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14320,8 +15095,8 @@
1432015095 RevertCamera();
1432115096 repaint();
1432215097 break;
14323
- case 'L':
1432415098 case 'l':
15099
+ //case 'L':
1432515100 if (lightMode)
1432615101 {
1432715102 lightMode = false;
....@@ -14464,9 +15239,9 @@
1446415239 case '_':
1446515240 kompactbit = 5;
1446615241 break;
14467
- case '+':
14468
- kompactbit = 6;
14469
- break;
15242
+// case '+':
15243
+// kompactbit = 6;
15244
+// break;
1447015245 case ' ':
1447115246 lightMode ^= true;
1447215247 Globals.lighttouched = true;
....@@ -14478,13 +15253,14 @@
1447815253 case ESC:
1447915254 RENDERPROGRAM += 1;
1448015255 RENDERPROGRAM %= 3;
15256
+
1448115257 repaint();
1448215258 break;
1448315259 case 'Z':
1448415260 //RESIZETEXTURE ^= true;
1448515261 //break;
1448615262 case 'z':
14487
- RENDERSHADOW ^= true;
15263
+ Globals.RENDERSHADOW ^= true;
1448815264 Globals.lighttouched = true;
1448915265 repaint();
1449015266 break;
....@@ -14517,8 +15293,9 @@
1451715293 case DELETE:
1451815294 ClearSelection();
1451915295 break;
14520
- /*
1452115296 case '+':
15297
+
15298
+ /*
1452215299 //fontsize += 1;
1452315300 bbzoom *= 2;
1452415301 repaint();
....@@ -14535,17 +15312,17 @@
1453515312 case '=':
1453615313 IncDepth();
1453715314 //fontsize += 1;
14538
- object.editWindow.refreshContents(true);
15315
+ object.GetWindow().refreshContents(true);
1453915316 maskbit = 6;
1454015317 break;
1454115318 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1454215319 DecDepth();
1454315320 maskbit = 5;
1454415321 //if(fontsize > 1) fontsize -= 1;
14545
- if (object.editWindow == null)
14546
- new Exception().printStackTrace();
14547
- else
14548
- object.editWindow.refreshContents(true);
15322
+// if (object.editWindow == null)
15323
+// new Exception().printStackTrace();
15324
+// else
15325
+ object.GetWindow().refreshContents(true);
1454915326 break;
1455015327 case '{':
1455115328 manipCamera.shaper_fovy /= 1.1;
....@@ -14608,7 +15385,7 @@
1460815385 //mode = ROTATE;
1460915386 if ((MODIFIERS & COMMAND) == 0) // VR??
1461015387 {
14611
- SetMouseMode(modifiers);
15388
+ SetMouseMode(0, modifiers);
1461215389 }
1461315390 }
1461415391
....@@ -14742,8 +15519,9 @@
1474215519
1474315520 protected void processMouseMotionEvent(MouseEvent e)
1474415521 {
14745
- //System.out.println("processMouseMotionEvent: " + mouseMode);
14746
- if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15522
+ //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
15523
+ //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15524
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1474715525 {
1474815526 mouseMoved(e);
1474915527 } else
....@@ -14768,11 +15546,12 @@
1476815546 }
1476915547 */
1477015548
14771
- object.editWindow.EditSelection();
15549
+ object.GetWindow().EditSelection(false);
1477215550 }
1477315551
1477415552 void SelectParent()
1477515553 {
15554
+ new Exception().printStackTrace();
1477615555 System.exit(0);
1477715556 Composite group = (Composite) object;
1477815557 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -14784,10 +15563,10 @@
1478415563 {
1478515564 //selectees.remove(i);
1478615565 System.out.println("select parent of " + elem);
14787
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15566
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1478815567 } else
1478915568 {
14790
- group.editWindow.Select(elem.GetTreePath(), first, true);
15569
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1479115570 }
1479215571
1479315572 first = false;
....@@ -14796,6 +15575,7 @@
1479615575
1479715576 void SelectChildren()
1479815577 {
15578
+ new Exception().printStackTrace();
1479915579 System.exit(0);
1480015580 /*
1480115581 Composite group = (Composite) object;
....@@ -14828,12 +15608,12 @@
1482815608 for (int j = 0; j < group.children.size(); j++)
1482915609 {
1483015610 elem = (Object3D) group.children.elementAt(j);
14831
- object.editWindow.Select(elem.GetTreePath(), first, true);
15611
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1483215612 first = false;
1483315613 }
1483415614 } else
1483515615 {
14836
- object.editWindow.Select(elem.GetTreePath(), first, true);
15616
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1483715617 }
1483815618
1483915619 first = false;
....@@ -14844,21 +15624,21 @@
1484415624 {
1484515625 //Composite group = (Composite) object;
1484615626 Object3D group = object;
14847
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15627
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1484815628 }
1484915629
1485015630 void ResetTransform(int mask)
1485115631 {
1485215632 //Composite group = (Composite) object;
1485315633 Object3D group = object;
14854
- group.editWindow.ResetTransform(mask);
15634
+ group.GetWindow().ResetTransform(mask);
1485515635 }
1485615636
1485715637 void FlipTransform()
1485815638 {
1485915639 //Composite group = (Composite) object;
1486015640 Object3D group = object;
14861
- group.editWindow.FlipTransform();
15641
+ group.GetWindow().FlipTransform();
1486215642 // group.editWindow.ReduceMesh(true);
1486315643 }
1486415644
....@@ -14866,7 +15646,7 @@
1486615646 {
1486715647 //Composite group = (Composite) object;
1486815648 Object3D group = object;
14869
- group.editWindow.PrintMemory();
15649
+ group.GetWindow().PrintMemory();
1487015650 // group.editWindow.ReduceMesh(true);
1487115651 }
1487215652
....@@ -14874,7 +15654,7 @@
1487415654 {
1487515655 //Composite group = (Composite) object;
1487615656 Object3D group = object;
14877
- group.editWindow.ResetCentroid();
15657
+ group.GetWindow().ResetCentroid();
1487815658 }
1487915659
1488015660 void IncDepth()
....@@ -14960,7 +15740,9 @@
1496015740 info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1496115741 //Image img = CreateImage(width, height);
1496215742 //System.out.println("width = " + width + "; height = " + height + "\n");
15743
+
1496315744 Graphics gr = g; // img.getGraphics();
15745
+
1496415746 if (!hasMarquee)
1496515747 {
1496615748 if (Xmin < Xmax) // !locked)
....@@ -15048,6 +15830,7 @@
1504815830 info.bounds.y += (height - desired) / 2;
1504915831 }
1505015832 }
15833
+
1505115834 info.g = gr;
1505215835 info.camera = renderCamera;
1505315836 /*
....@@ -15057,15 +15840,55 @@
1505715840 */
1505815841 if (!isRenderer)
1505915842 {
15060
- object.drawEditHandles(info, 0);
15843
+ Grafreed.Assert(object != null);
15844
+ Grafreed.Assert(object.selection != null);
15845
+ if (object.selection.Size() > 0)
15846
+ {
15847
+ int hitSomething = object.selection.get(0).hitSomething;
15848
+
15849
+ info.DX = 0;
15850
+ info.DY = 0;
15851
+ info.W = 1;
15852
+ if (hitSomething == Object3D.hitCenter)
15853
+ {
15854
+ info.DX = X;
15855
+ if (X != 0)
15856
+ info.DX -= info.bounds.width/2;
15857
+
15858
+ info.DY = Y;
15859
+ if (Y != 0)
15860
+ info.DY -= info.bounds.height/2;
15861
+ }
15862
+
15863
+ object.drawEditHandles(info, 0);
15864
+
15865
+ if (drag && (X != 0 || Y != 0))
15866
+ {
15867
+ switch (hitSomething)
15868
+ {
15869
+ case Object3D.hitCenter: gr.setColor(Color.pink);
15870
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15871
+ break;
15872
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
15873
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15874
+ break;
15875
+ case Object3D.hitScale: gr.setColor(Color.cyan);
15876
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15877
+ break;
15878
+ }
15879
+
15880
+ }
15881
+ }
1506115882 }
1506215883 }
15884
+
1506315885 if (isRenderer)
1506415886 {
1506515887 //gr.setColor(Color.black);
1506615888 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1506715889 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1506815890 }
15891
+
1506915892 if (hasMarquee)
1507015893 {
1507115894 gr.setXORMode(Color.white);
....@@ -15178,6 +16001,7 @@
1517816001 public boolean mouseDown(Event evt, int x, int y)
1517916002 {
1518016003 System.out.println("mouseDown: " + evt);
16004
+ System.exit(0);
1518116005 /*
1518216006 locked = true;
1518316007 drag = false;
....@@ -15221,7 +16045,7 @@
1522116045 {
1522216046 keyPressed(0, modifiers);
1522316047 }
15224
- clickStart(x, y, modifiers);
16048
+ // clickStart(x, y, modifiers);
1522516049 return true;
1522616050 }
1522716051
....@@ -15339,7 +16163,7 @@
1533916163 {
1534016164 keyReleased(0, 0);
1534116165 }
15342
- drag(x, y, modifiers);
16166
+ drag(x, y, 0, modifiers);
1534316167 return true;
1534416168 }
1534516169
....@@ -15471,7 +16295,7 @@
1547116295 Object3D object;
1547216296 static Object3D trackedobject;
1547316297 Camera renderCamera; // Light or Eye (or Occlusion)
15474
- /*static*/ Camera manipCamera; // Light or Eye
16298
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1547516299 /*static*/ Camera eyeCamera;
1547616300 /*static*/ Camera lightCamera;
1547716301 int cameracount;
....@@ -15756,16 +16580,16 @@
1575616580 cStatic.objectstack[materialdepth++] = checker;
1575716581 //System.out.println("material " + material);
1575816582 //Applet3D.tracein(this, selected);
15759
- vector2buffer = checker.projectedVertices;
16583
+ //vector2buffer = checker.projectedVertices;
1576016584
1576116585 //checker.GetMaterial().Draw(this, false); // true);
15762
- DrawMaterial(checker.GetMaterial(), false); // true);
16586
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1576316587
1576416588 materialdepth -= 1;
1576516589 if (materialdepth > 0)
1576616590 {
15767
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
15768
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
16591
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16592
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1576916593 }
1577016594 //checker.GetMaterial().opacity = 1f;
1577116595 ////checker.GetMaterial().ambient = 1f;
....@@ -15851,6 +16675,14 @@
1585116675 }
1585216676 }
1585316677
16678
+ private Object3D GetFolder()
16679
+ {
16680
+ Object3D folder = object.GetWindow().copy;
16681
+ if (object.GetWindow().copy.selection.Size() > 0)
16682
+ folder = object.GetWindow().copy.selection.elementAt(0);
16683
+ return folder;
16684
+ }
16685
+
1585416686 class SelectBuffer implements GLEventListener
1585516687 {
1585616688
....@@ -15909,6 +16741,7 @@
1590916741 {
1591016742 if (!selection)
1591116743 {
16744
+ new Exception().printStackTrace();
1591216745 System.exit(0);
1591316746 return;
1591416747 }
....@@ -15929,6 +16762,17 @@
1592916762
1593016763 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1593116764
16765
+ if (PAINTMODE)
16766
+ {
16767
+ if (object.GetWindow().copy.selection.Size() > 0)
16768
+ {
16769
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16770
+
16771
+ // Make what you paint not selectable.
16772
+ paintobj.ResetSelectable();
16773
+ }
16774
+ }
16775
+
1593216776 //int tmp = selection_view;
1593316777 //selection_view = -1;
1593416778 int temp = DrawMode();
....@@ -15940,6 +16784,17 @@
1594016784 // temp = DEFAULT; // patch for selection debug
1594116785 Globals.drawMode = temp; // WARNING
1594216786
16787
+ if (PAINTMODE)
16788
+ {
16789
+ if (object.GetWindow().copy.selection.Size() > 0)
16790
+ {
16791
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16792
+
16793
+ // Revert.
16794
+ paintobj.RestoreSelectable();
16795
+ }
16796
+ }
16797
+
1594316798 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1594416799
1594516800 // trying different ways of getting the depth info over
....@@ -15987,6 +16842,8 @@
1598716842 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1598816843 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1598916844 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
16845
+
16846
+ CreateSelectedPoint();
1599016847
1599116848 // Will fit the mesh !!!
1599216849 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16036,34 +16893,36 @@
1603616893 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]));
1603716894 }
1603816895
16039
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
16896
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1604016897 }
1604116898 }
1604216899
1604316900 if (!movingcamera && !PAINTMODE)
16044
- object.editWindow.ScreenFitPoint(); // fev 2014
16901
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1604516902
16046
- if (PAINTMODE && GrafreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
16903
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1604716904 {
16048
- Object3D paintobj = GrafreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
16905
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1604916906
16050
- Object3D group = new Object3D("inst" + paintcount++);
16907
+ if (object.GetWindow().copy.selection.Size() > 0)
16908
+ {
16909
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1605116910
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();
16911
+ Object3D inst = new Object3D("inst" + paintcount++);
16912
+
16913
+ inst.CreateMaterial(); // use a void leaf to select instances
16914
+
16915
+ inst.add(paintobj); // link
16916
+
16917
+ object.GetWindow().SnapObject(inst);
16918
+
16919
+ Object3D folder = paintFolder; // GetFolder();
16920
+
16921
+ folder.add(inst);
16922
+
16923
+ object.GetWindow().ResetModel();
16924
+ object.GetWindow().refreshContents();
16925
+ }
1606716926 }
1606816927 else
1606916928 paintcount = 0;
....@@ -16102,6 +16961,11 @@
1610216961 //System.out.println("objects[color] = " + objects[color]);
1610316962 //objects[color].Select();
1610416963 indexcount = 0;
16964
+ ObjEditor window = object.GetWindow();
16965
+ if (window != null && deselect)
16966
+ {
16967
+ window.Select(null, deselect, true);
16968
+ }
1610516969 object.Select(color, deselect);
1610616970 }
1610716971
....@@ -16201,7 +17065,7 @@
1620117065 gl.glDisable(gl.GL_CULL_FACE);
1620217066 }
1620317067
16204
- if (!RENDERSHADOW)
17068
+ if (!Globals.RENDERSHADOW)
1620517069 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1620617070
1620717071 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -16211,7 +17075,7 @@
1621117075 //gl.glColorMask(false, false, false, false);
1621217076
1621317077 //render_scene_from_light_view(gl, drawable, 0, 0);
16214
- if (RENDERSHADOW && Globals.lighttouched && !movingcamera) // && !parent.IsFreezed())
17078
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1621517079 {
1621617080 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1621717081
....@@ -16627,23 +17491,15 @@
1662717491 int AAbuffersize = 0;
1662817492
1662917493 //double[] selectedpoint = new double[3];
16630
- static Superellipsoid selectedpoint = new Superellipsoid();
17494
+ static Superellipsoid selectedpoint;
1663117495 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();
17496
+ static Sphere debugpointG;
17497
+ static Sphere debugpointP;
17498
+ static Sphere debugpointC;
17499
+ static Sphere debugpointR;
1663617500
1663717501 static Sphere debugpoints[] = new Sphere[8];
1663817502
16639
- static
16640
- {
16641
- for (int i=0; i<8; i++)
16642
- {
16643
- debugpoints[i] = new Sphere();
16644
- }
16645
- }
16646
-
1664717503 static void InitPoints(float radius)
1664817504 {
1664917505 for (int i=0; i<8; i++)
....@@ -16695,10 +17551,11 @@
1669517551 static IntBuffer textbuffer = null; // IntBuffer.allocate(TEXT_WIDTH*8*8 * TEXT_HEIGHT);
1669617552 // Depth buffer format
1669717553 //private int depth_format;
16698
- static public void NextIndex(Object3D o, GL gl)
17554
+
17555
+ public void NextIndex()
1669917556 {
1670017557 indexcount+=16;
16701
- gl.glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
17558
+ GetGL().glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
1670217559 //objects[indexcount] = o;
1670317560 //System.out.println("indexcount = " + indexcount);
1670417561 }