Normand Briere
2019-07-23 0f4fa9dc4191aaee9661c1e6d73725436ae64ac2
CameraPane.java
....@@ -18,7 +18,10 @@
1818 import javax.imageio.ImageIO;
1919 import javax.imageio.ImageWriteParam;
2020 import javax.imageio.ImageWriter;
21
+import javax.imageio.ImageReadParam;
22
+import javax.imageio.ImageReader;
2123 import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
24
+import javax.imageio.stream.ImageInputStream;
2225 import javax.imageio.stream.ImageOutputStream;
2326 import javax.imageio.ImageWriteParam;
2427
....@@ -30,6 +33,7 @@
3033 import java.nio.*;
3134
3235 import gleem.linalg.Mat4f;
36
+import javax.imageio.ImageTypeSpecifier;
3337
3438 class CameraPane extends GLCanvas implements iCameraPane, Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener
3539 {
....@@ -37,7 +41,6 @@
3741 static boolean[] selectedstack = new boolean[65536];
3842 static int materialdepth = 0;
3943
40
- static boolean DEBUG = false;
4144 static boolean FRUSTUM = false; // still bogus true; // frustum culling
4245
4346 // camera change fix
....@@ -45,6 +48,39 @@
4548 static boolean ABORTED = false;
4649
4750 static int STEP = 1;
51
+
52
+ private static BufferedImage CreateBim(byte[] bytes, int width, int height)
53
+ {
54
+ int[] pixels = new int[bytes.length/3];
55
+ for (int i=pixels.length; --i>=0;)
56
+ {
57
+ int i3 = i*3;
58
+ pixels[i] = 0xFF;
59
+ pixels[i] <<= 8;
60
+ pixels[i] |= bytes[i3+2] & 0xFF;
61
+ pixels[i] <<= 8;
62
+ pixels[i] |= bytes[i3+1] & 0xFF;
63
+ pixels[i] <<= 8;
64
+ pixels[i] |= bytes[i3] & 0xFF;
65
+ }
66
+ /*
67
+ int r=0,g=0,b=0,a=0;
68
+ for (int i=0; i<width; i++)
69
+ for (int j=0; j<height; j++)
70
+ {
71
+ int index = j*width+i;
72
+ int p = pixels[index];
73
+ a = ((p>>24) & 0xFF);
74
+ r = ((p>>16) & 0xFF);
75
+ g = ((p>>8) & 0xFF);
76
+ b = (p & 0xFF);
77
+ pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
78
+ }
79
+ /**/
80
+ BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
81
+ rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
82
+ return rendImage;
83
+ }
4884
4985 /*static*/ private boolean CULLFACE = false; // true;
5086 /*static*/ boolean NEAREST = false; // true;
....@@ -56,14 +92,12 @@
5692 static int CURRENTANTIALIAS = 0; // 1;
5793 /*static*/ boolean RENDERSHADOW = true;
5894 /*static*/ int RENDERPROGRAM = 2; // 0 == none, 1 == fast, 2 == normal
59
- static boolean ANIMATION = false;
60
- static String filename;
6195
6296 boolean DISPLAYTEXT = false;
6397 //boolean REDUCETEXTURE = true;
6498 boolean CACHETEXTURE = true;
6599 boolean CLEANCACHE = false; // true;
66
- boolean MIPMAP = false; // true;
100
+ boolean MIPMAP = false; // true; // never works...
67101 boolean COMPRESSTEXTURE = false;
68102 boolean KOMPACTTEXTURE = false; // true;
69103 boolean RESIZETEXTURE = false;
....@@ -92,6 +126,8 @@
92126
93127 static int tickcount = 0; // slow pose issue
94128
129
+static boolean BUTTONLESSWHEEL = false;
130
+static boolean ZOOMBOXMODE = false;
95131 static boolean BOXMODE = false;
96132 static boolean IMAGEFLIP = false;
97133 static boolean SMOOTHFOCUS = false;
....@@ -106,7 +142,7 @@
106142 static boolean OEIL = true;
107143 static boolean OEILONCE = false; // do oeilon then oeiloff
108144 static boolean LOOKAT = true;
109
-static boolean RANDOM = true; // false;
145
+static boolean SWITCH = true; // false;
110146 static boolean HANDLES = false; // selection doesn't work!!
111147 static boolean PAINTMODE = false;
112148
....@@ -150,12 +186,12 @@
150186 defaultcaps.setAccumAlphaBits(16);
151187 }
152188
153
- static CameraPane theRenderer;
189
+ private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
154190
155191 void SetAsGLRenderer(boolean b)
156192 {
157193 isRenderer = b;
158
- theRenderer = this;
194
+ Globals.theRenderer = this;
159195 }
160196
161197 CameraPane(Object3D o, Camera cam, boolean withcontext)
....@@ -193,9 +229,43 @@
193229
194230 /// INTERFACE
195231
232
+ public javax.media.opengl.GL GetGL0()
233
+ {
234
+ return null;
235
+ }
236
+
237
+ public int GenList()
238
+ {
239
+ javax.media.opengl.GL gl = GetGL();
240
+ return gl.glGenLists(1);
241
+ }
242
+
243
+ public void NewList(int id)
244
+ {
245
+ javax.media.opengl.GL gl = GetGL();
246
+ gl.glNewList(id, gl.GL_COMPILE); //_AND_EXECUTE);
247
+ }
248
+
249
+ public void CallList(int id)
250
+ {
251
+ javax.media.opengl.GL gl = GetGL();
252
+ gl.glCallList(id);
253
+ }
254
+
255
+ public void EndList()
256
+ {
257
+ javax.media.opengl.GL gl = GetGL();
258
+ gl.glEndList();
259
+ }
260
+
196261 public boolean IsBoxMode()
197262 {
198263 return BOXMODE;
264
+ }
265
+
266
+ public boolean IsZoomBoxMode()
267
+ {
268
+ return ZOOMBOXMODE;
199269 }
200270
201271 public void ClearDepth()
....@@ -293,7 +363,7 @@
293363 cStatic.objectstack[materialdepth++] = obj;
294364 //System.out.println("material " + material);
295365 //Applet3D.tracein(this, selected);
296
- display.vector2buffer = obj.projectedVertices;
366
+ //display.vector2buffer = obj.projectedVertices;
297367 if (obj instanceof Camera)
298368 {
299369 display.options1[0] = material.shift;
....@@ -302,14 +372,28 @@
302372 display.options1[2] = material.shadowbias;
303373 display.options1[3] = material.aniso;
304374 display.options1[4] = material.anisoV;
375
+// System.out.println("display.options1[0] " + display.options1[0]);
376
+// System.out.println("display.options1[1] " + display.options1[1]);
377
+// System.out.println("display.options1[2] " + display.options1[2]);
378
+// System.out.println("display.options1[3] " + display.options1[3]);
379
+// System.out.println("display.options1[4] " + display.options1[4]);
305380 display.options2[0] = material.opacity;
306381 display.options2[1] = material.diffuse;
307382 display.options2[2] = material.factor;
383
+// System.out.println("display.options2[0] " + display.options2[0]);
384
+// System.out.println("display.options2[1] " + display.options2[1]);
385
+// System.out.println("display.options2[2] " + display.options2[2]);
308386
309387 cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
388
+// System.out.println("display.options3[0] " + display.options3[0]);
389
+// System.out.println("display.options3[1] " + display.options3[1]);
390
+// System.out.println("display.options3[2] " + display.options3[2]);
310391 display.options4[0] = material.cameralight/0.2f;
311392 display.options4[1] = material.subsurface;
312393 display.options4[2] = material.sheen;
394
+// System.out.println("display.options4[0] " + display.options4[0]);
395
+// System.out.println("display.options4[1] " + display.options4[1]);
396
+// System.out.println("display.options4[2] " + display.options4[2]);
313397
314398 // if (display.CURRENTANTIALIAS > 0)
315399 // display.options3[3] /= 4;
....@@ -325,7 +409,7 @@
325409 /**/
326410 } else
327411 {
328
- DrawMaterial(material, selected);
412
+ DrawMaterial(material, selected, obj.projectedVertices);
329413 }
330414 } else
331415 {
....@@ -349,8 +433,8 @@
349433 cStatic.objectstack[materialdepth++] = obj;
350434 //System.out.println("material " + material);
351435 //Applet3D.tracein("selected ", selected);
352
- display.vector2buffer = obj.projectedVertices;
353
- display.DrawMaterial(material, selected);
436
+ //display.vector2buffer = obj.projectedVertices;
437
+ display.DrawMaterial(material, selected, obj.projectedVertices);
354438 }
355439 }
356440
....@@ -367,8 +451,8 @@
367451 materialdepth -= 1;
368452 if (materialdepth > 0)
369453 {
370
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
371
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
454
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
455
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
372456 }
373457 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
374458 } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
....@@ -388,8 +472,8 @@
388472 materialdepth -= 1;
389473 if (materialdepth > 0)
390474 {
391
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
392
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
475
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
476
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
393477 }
394478 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
395479 //else
....@@ -430,10 +514,12 @@
430514 if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
431515 {
432516 //gl.glBegin(gl.GL_TRIANGLES);
433
- boolean hasnorm = pv.norm != null; // && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0);
517
+ boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0)
518
+ // TEST LIVE NORMALS && !obj.dontselect
519
+ ;
434520 if (!hasnorm)
435521 {
436
- // System.out.println("FUCK!!");
522
+ // System.out.println("Mesh normal");
437523 LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
438524 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
439525 LA.vecCross(obj.v0, obj.v1, obj.v2);
....@@ -816,7 +902,7 @@
816902
817903 if ((i % 100) == 0 && i != 0)
818904 {
819
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
905
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
820906 //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
821907 System.out.println((int) (100.0 * i / (br.positions.length / 3)) + "% (" + i + " of " + (br.positions.length / 3) + ")");
822908 }
....@@ -848,7 +934,7 @@
848934
849935 if ((i % 100) == 0 && i != 0)
850936 {
851
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
937
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
852938 //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
853939 System.out.println((int) (100.0 * i / br.VertexCount()) + "% (" + i + " of " + br.VertexCount() + ")");
854940 }
....@@ -1061,7 +1147,342 @@
10611147 gl.glMatrixMode(gl.GL_MODELVIEW);
10621148 }
10631149
1150
+ public void DrawBox(cVector min, cVector max)
1151
+ {
1152
+ javax.media.opengl.GL gl = GetGL();
1153
+ gl.glBegin(gl.GL_LINES);
1154
+
1155
+ gl.glVertex3d(min.x, min.y, min.z);
1156
+ gl.glVertex3d(min.x, min.y, max.z);
1157
+ gl.glVertex3d(min.x, min.y, min.z);
1158
+ gl.glVertex3d(min.x, max.y, min.z);
1159
+ gl.glVertex3d(min.x, min.y, min.z);
1160
+ gl.glVertex3d(max.x, min.y, min.z);
1161
+
1162
+ gl.glVertex3d(max.x, max.y, max.z);
1163
+ gl.glVertex3d(min.x, max.y, max.z);
1164
+ gl.glVertex3d(max.x, max.y, max.z);
1165
+ gl.glVertex3d(max.x, min.y, max.z);
1166
+ gl.glVertex3d(max.x, max.y, max.z);
1167
+ gl.glVertex3d(max.x, max.y, min.z);
1168
+
1169
+ gl.glEnd();
1170
+ }
1171
+
1172
+ public void DrawGeometry(BoundaryRep bRep, boolean flipV, boolean selectmode)
1173
+ {
1174
+ int[] strips = bRep.getRawIndices();
1175
+
1176
+ javax.media.opengl.GL gl = GetGL();
1177
+
1178
+ // TRIANGLE STRIP ARRAY
1179
+ if (bRep.trimmed)
1180
+ {
1181
+ float[] v = bRep.getRawVertices();
1182
+ float[] n = bRep.getRawNormals();
1183
+ float[] c = bRep.getRawColors();
1184
+ float[] uv = bRep.getRawUVMap();
1185
+
1186
+ int count2 = 0;
1187
+ int count3 = 0;
1188
+
1189
+ if (n.length > 0)
1190
+ {
1191
+ for (int i = 0; i < strips.length; i++)
1192
+ {
1193
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1194
+
1195
+ /*
1196
+ boolean locked = false;
1197
+ float eps = 0.1f;
1198
+ boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
1199
+
1200
+ int dot = 0;
1201
+
1202
+ if ((dot&1) == 0)
1203
+ dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
1204
+
1205
+ if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
1206
+ gl.glTexCoord2f((float) qv.s, (float) qv.t);
1207
+ else
1208
+ {
1209
+ locked = true;
1210
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1211
+ }
1212
+ //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
1213
+ gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
1214
+ if (hasnorm)
1215
+ {
1216
+ //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
1217
+ gl.glNormal3f((float) rv.norm.x, (float) rv.norm.y, (float) rv.norm.z);
1218
+ }
1219
+
1220
+ if ((dot&4) == 0)
1221
+ dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
1222
+
1223
+ if (wrap || !locked && (dot&8) != 0)
1224
+ gl.glTexCoord2f((float) rv.s, (float) rv.t);
1225
+ else
1226
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1227
+
1228
+ f.dot = dot;
1229
+ */
1230
+
1231
+ if (!selectmode)
1232
+ {
1233
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1234
+ {
1235
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1236
+ } else
1237
+ {
1238
+ gl.glNormal3f(0, 0, 1);
1239
+ }
1240
+
1241
+ if (c != null)
1242
+ //System.out.println("glcolor = " + c[count3] + ", " + c[count3+1] + ", " + c[count3+2]);
1243
+ {
1244
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1245
+ }
1246
+ }
1247
+
1248
+ if (flipV)
1249
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1250
+ else
1251
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1252
+
1253
+ //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1254
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1255
+
1256
+ count2 += 2;
1257
+ count3 += 3;
1258
+ if (!selectmode)
1259
+ {
1260
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1261
+ {
1262
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1263
+ } else
1264
+ {
1265
+ gl.glNormal3f(0, 0, 1);
1266
+ }
1267
+ if (c != null)
1268
+ {
1269
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1270
+ }
1271
+ }
1272
+
1273
+ if (flipV)
1274
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1275
+ else
1276
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1277
+
1278
+ //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1279
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1280
+
1281
+ count2 += 2;
1282
+ count3 += 3;
1283
+ for (int j = 0; j < strips[i] - 2; j++)
1284
+ {
1285
+ //gl.glTexCoord2d(...);
1286
+ if (!selectmode)
1287
+ {
1288
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1289
+ {
1290
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1291
+ } else
1292
+ {
1293
+ gl.glNormal3f(0, 0, 1);
1294
+ }
1295
+ if (c != null)
1296
+ {
1297
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1298
+ }
1299
+ }
1300
+
1301
+ if (flipV)
1302
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1303
+ else
1304
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1305
+
1306
+ //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
1307
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1308
+
1309
+ count2 += 2;
1310
+ count3 += 3;
1311
+ }
1312
+
1313
+ gl.glEnd();
1314
+ }
1315
+ }
1316
+
1317
+ assert count3 == v.length;
1318
+ }
1319
+ else // !trimmed
1320
+ {
1321
+ int count = 0;
1322
+ for (int i = 0; i < strips.length; i++)
1323
+ {
1324
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1325
+
1326
+ Vertex p = bRep.GetVertex(bRep.indices[count++]);
1327
+ Vertex q = bRep.GetVertex(bRep.indices[count++]);
1328
+
1329
+ drawVertex(gl, p, flipV, selectmode);
1330
+ drawVertex(gl, q, flipV, selectmode);
1331
+
1332
+ for (int j = 0; j < strips[i] - 2; j++)
1333
+ {
1334
+ Vertex r = bRep.GetVertex(bRep.indices[count++]);
1335
+
1336
+ // if (j%2 == 0)
1337
+ // drawFace(p, q, r, display, null);
1338
+ // else
1339
+ // drawFace(p, r, q, display, null);
1340
+
1341
+ // p = q;
1342
+ // q = r;
1343
+ drawVertex(gl, r, flipV, selectmode);
1344
+ }
1345
+
1346
+ gl.glEnd();
1347
+ }
1348
+ }
1349
+ }
1350
+
1351
+ static cSpring.Point3D temp = new cSpring.Point3D();
1352
+ static cSpring.Point3D temp2 = new cSpring.Point3D();
1353
+ static cSpring.Point3D temp3 = new cSpring.Point3D();
1354
+
1355
+ public void DrawDynamicMesh(cMesh mesh)
1356
+ {
1357
+ GL gl = GetGL(); // getGL();
1358
+
1359
+ cSpring.PhysicsController3D Phys = mesh.Phys;
1360
+
1361
+ gl.glDisable(gl.GL_LIGHTING);
1362
+
1363
+ gl.glLineWidth(1);
1364
+ gl.glColor3f(1,1,1);
1365
+ gl.glBegin(gl.GL_LINES);
1366
+ double scale = 0;
1367
+ int count = 0;
1368
+ for (int s=0; s<Phys.allSprings.size(); s++)
1369
+ {
1370
+ cSpring.Spring spring = Phys.allSprings.get(s);
1371
+ if(s == 0)
1372
+ {
1373
+ //System.out.println(" spring : " + spring.a.position + "; " + spring.b.position);
1374
+ }
1375
+ if (mesh.showsprings)
1376
+ {
1377
+ temp.set(spring.a.position);
1378
+ temp.add(spring.b.position);
1379
+ temp.mul(0.5);
1380
+ temp2.set(spring.a.position);
1381
+ temp2.sub(spring.b.position);
1382
+ temp2.mul(spring.restLength/2);
1383
+ temp.sub(temp2);
1384
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1385
+ temp.add(temp2);
1386
+ temp.add(temp2);
1387
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1388
+ }
1389
+
1390
+ if (spring.isHandle)
1391
+ continue;
1392
+
1393
+ //if (scale < spring.restLength)
1394
+ scale += spring.restLength;
1395
+ count++;
1396
+ }
1397
+ gl.glEnd();
1398
+
1399
+ if (count == 0)
1400
+ scale = 0.01;
1401
+ else
1402
+ scale /= count * 3;
1403
+
1404
+ //scale = 0.25;
1405
+
1406
+ if (mesh.ShowInfo())
1407
+ {
1408
+ gl.glLineWidth(4);
1409
+ for (int s=0; s<Phys.allNodes.size(); s++)
1410
+ {
1411
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1412
+ if (node.mass == 0)
1413
+ continue;
1414
+
1415
+ int i = node.springs==null?-1:node.springs.size();
1416
+ gl.glColor3f((i>>2)&1,(i>>1)&1,i&1);
1417
+ //temp.set(node.springForce.x, node.springForce.y, node.springForce.z);
1418
+ //temp.normalize();
1419
+ //gl.glColor3d((temp.x+1)/2, (temp.y+1)/2, (temp.z+1)/2);
1420
+ gl.glBegin(gl.GL_LINES);
1421
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1422
+ //gl.glVertex3d(node.position.x + node.normal.x*scale, node.position.y + node.normal.y*scale, node.position.z + node.normal.z*scale);
1423
+ gl.glVertex3d(node.position.x + mesh.bRep.GetVertex(s).norm.x*scale,
1424
+ node.position.y + mesh.bRep.GetVertex(s).norm.y*scale,
1425
+ node.position.z + mesh.bRep.GetVertex(s).norm.z*scale);
1426
+ gl.glEnd();
1427
+ }
1428
+
1429
+ gl.glLineWidth(8);
1430
+ for (int s=0; s<Phys.allNodes.size(); s++)
1431
+ {
1432
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1433
+
1434
+ if (node.springs != null)
1435
+ {
1436
+ for (int i=0; i<node.springs.size(); i+=1)
1437
+ {
1438
+ cSpring.DynamicNode f = node.springs.get(i).GetOther(node);
1439
+
1440
+ int c = i+1;
1441
+ // c = node.springs.get(i).nbcopies;
1442
+
1443
+ gl.glColor3f((c>>2)&1,(c>>1)&1,c&1);
1444
+ gl.glBegin(gl.GL_LINES);
1445
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1446
+ gl.glVertex3d(f.position.x/3+node.position.x*2/3, f.position.y/3+node.position.y*2/3, f.position.z/3+node.position.z*2/3);
1447
+ gl.glEnd();
1448
+ }
1449
+ }
1450
+ }
1451
+
1452
+ gl.glLineWidth(1);
1453
+ }
1454
+
1455
+ gl.glEnable(gl.GL_LIGHTING);
1456
+ }
1457
+
10641458 /// INTERFACE
1459
+
1460
+ public void StartTriangles()
1461
+ {
1462
+ javax.media.opengl.GL gl = GetGL();
1463
+ gl.glBegin(gl.GL_TRIANGLES);
1464
+ }
1465
+
1466
+ public void EndTriangles()
1467
+ {
1468
+ GetGL().glEnd();
1469
+ }
1470
+
1471
+ void drawVertex(javax.media.opengl.GL gl, Vertex pv, boolean flipV, boolean selectmode)
1472
+ {
1473
+ if (!selectmode)
1474
+ {
1475
+ gl.glNormal3f((float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
1476
+ gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
1477
+
1478
+ if (flipV)
1479
+ gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
1480
+ else
1481
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1482
+ }
1483
+
1484
+ gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
1485
+ }
10651486
10661487 void SetColor(Object3D obj, Vertex p0)
10671488 {
....@@ -1240,7 +1661,7 @@
12401661 // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
12411662 }
12421663
1243
- void DrawMaterial(cMaterial material, boolean selected)
1664
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
12441665 {
12451666 CameraPane display = this;
12461667 //new Exception().printStackTrace();
....@@ -1256,18 +1677,18 @@
12561677 //col.getColorComponents(ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB), CameraPane.modelParams0);
12571678 if (!material.multiply)
12581679 {
1259
- display.color = color;
1680
+ display.color = material.color;
12601681 display.saturation = material.modulation;
12611682 }
12621683 else
12631684 {
1264
- display.color *= color*2;
1685
+ display.color *= material.color*2;
12651686 display.saturation *= material.modulation*2;
12661687 }
12671688
12681689 cColor.HSBtoRGB(display.color, display.saturation, 1, display.modelParams0);
12691690
1270
- float[] colorV = GrafreeD.colorV;
1691
+ float[] colorV = Grafreed.colorV;
12711692
12721693 /**/
12731694 if (display.DrawMode() == display.DEFAULT) // && display.RENDERPROGRAM == 0)
....@@ -1275,7 +1696,7 @@
12751696 colorV[0] = display.modelParams0[0] * material.diffuse;
12761697 colorV[1] = display.modelParams0[1] * material.diffuse;
12771698 colorV[2] = display.modelParams0[2] * material.diffuse;
1278
- colorV[3] = material.opacity;
1699
+ colorV[3] = 1; // material.opacity;
12791700
12801701 gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
12811702 //System.out.println("Opacity = " + opacity);
....@@ -1383,9 +1804,9 @@
13831804 display.modelParams7[2] = 0;
13841805 display.modelParams7[3] = 0;
13851806
1386
- display.modelParams6[0] = 100; // criss de bug de bump
1807
+ //display.modelParams6[0] = 100; // criss de bug de bump
13871808
1388
- Object3D.cVector2[] extparams = display.vector2buffer;
1809
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
13891810 if (extparams != null && extparams.length > 0 && extparams[0] != null)
13901811 {
13911812 display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
....@@ -1527,7 +1948,7 @@
15271948 void PushMatrix(double[][] matrix)
15281949 {
15291950 // GrafreeD.tracein(matrix);
1530
- PushMatrix(matrix,1);
1951
+ PushMatrix(matrix, 1);
15311952 }
15321953
15331954 void PushMatrix()
....@@ -1624,7 +2045,7 @@
16242045
16252046 static int camerachangeframe;
16262047
1627
- boolean SetCamera(Camera cam)
2048
+ public boolean SetCamera(Camera cam)
16282049 {
16292050 // may 2014 if (cam == cameras[0] || cam == cameras[1])
16302051 // return false;
....@@ -1681,7 +2102,7 @@
16812102 //System.err.println("Oeil on");
16822103 OEIL = true;
16832104 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
1684
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2105
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
16852106 //pingthread.StepToTarget(true);
16862107 }
16872108
....@@ -1752,33 +2173,6 @@
17522173 mainDL ^= true;
17532174 }
17542175
1755
- void ToggleTexture()
1756
- {
1757
- textureon ^= true;
1758
- }
1759
-
1760
- void ToggleLive()
1761
- {
1762
- Globals.setLIVE(Globals.isLIVE() ^ true);
1763
-
1764
- System.err.println("LIVE = " + Globals.isLIVE());
1765
-
1766
- if (!Globals.isLIVE()) // save sound
1767
- GrafreeD.savesound = true; // wav.save();
1768
- // else
1769
- repaint(); // start loop // may 2013
1770
- }
1771
-
1772
- void ToggleSupport()
1773
- {
1774
- SUPPORT ^= true;
1775
- }
1776
-
1777
- void ToggleAbort()
1778
- {
1779
- ABORTMODE ^= true;
1780
- }
1781
-
17822176 void ToggleFullScreen()
17832177 {
17842178 FULLSCREEN ^= true;
....@@ -1789,72 +2183,94 @@
17892183 Globals.CROWD ^= true;
17902184 }
17912185
1792
- void ToggleInertia()
1793
- {
1794
- INERTIA ^= true;
1795
- }
1796
-
17972186 void ToggleLocal()
17982187 {
17992188 LOCALTRANSFORM ^= true;
18002189 }
18012190
1802
- void ToggleFast()
2191
+ public void ToggleTexture()
2192
+ {
2193
+ textureon ^= true;
2194
+ }
2195
+
2196
+ public void ToggleLive()
2197
+ {
2198
+ Globals.setLIVE(Globals.isLIVE() ^ true);
2199
+
2200
+ System.err.println("LIVE = " + Globals.isLIVE());
2201
+
2202
+ if (!Globals.isLIVE()) // save sound
2203
+ Grafreed.savesound = true; // wav.save();
2204
+ // else
2205
+ repaint(); // start loop // may 2013
2206
+ }
2207
+
2208
+ public void ToggleSupport()
2209
+ {
2210
+ SUPPORT ^= true;
2211
+ }
2212
+
2213
+ public void ToggleAbort()
2214
+ {
2215
+ ABORTMODE ^= true;
2216
+ }
2217
+
2218
+ public void ToggleInertia()
2219
+ {
2220
+ INERTIA ^= true;
2221
+ }
2222
+
2223
+ public void ToggleFast()
18032224 {
18042225 FAST ^= true;
18052226 }
18062227
1807
- void ToggleSlowPose()
2228
+ public void ToggleSlowPose()
18082229 {
18092230 SLOWPOSE ^= true;
18102231 }
18112232
1812
- void ToggleFootContact()
1813
- {
1814
- FOOTCONTACT ^= true;
1815
- }
1816
-
1817
- void ToggleBoxMode()
2233
+ public void ToggleBoxMode()
18182234 {
18192235 BOXMODE ^= true;
18202236 }
18212237
1822
- void ToggleSmoothFocus()
2238
+ public void ToggleZoomBoxMode()
2239
+ {
2240
+ ZOOMBOXMODE ^= true;
2241
+ }
2242
+
2243
+ public void ToggleSmoothFocus()
18232244 {
18242245 SMOOTHFOCUS ^= true;
18252246 }
18262247
1827
- void ToggleImageFlip()
2248
+ public void ToggleImageFlip()
18282249 {
18292250 IMAGEFLIP ^= true;
18302251 }
18312252
1832
- void ToggleSpeakerMocap()
2253
+ public void ToggleSpeakerMocap()
18332254 {
18342255 SPEAKERMOCAP ^= true;
18352256 }
18362257
1837
- void ToggleSpeakerCamera()
2258
+ public void ToggleSpeakerCamera()
18382259 {
18392260 SPEAKERCAMERA ^= true;
18402261 }
18412262
1842
- void ToggleSpeakerFocus()
2263
+ public void ToggleSpeakerFocus()
18432264 {
18442265 SPEAKERFOCUS ^= true;
18452266 }
18462267
1847
- void ToggleDebug()
1848
- {
1849
- DEBUG ^= true;
1850
- }
1851
-
1852
- void ToggleFrustum()
2268
+ public void ToggleFrustum()
18532269 {
18542270 FRUSTUM ^= true;
18552271 }
18562272
1857
- void ToggleTrack()
2273
+ public void ToggleTrack()
18582274 {
18592275 TRACK ^= true;
18602276 if (TRACK)
....@@ -1873,25 +2289,35 @@
18732289 repaint();
18742290 }
18752291
1876
- void ToggleTrackOnce()
2292
+ public void ToggleTrackOnce()
18772293 {
18782294 TRACKONCE ^= true;
18792295 }
18802296
1881
- void ToggleShadowTrack()
2297
+ public void ToggleShadowTrack()
18822298 {
18832299 SHADOWTRACK ^= true;
18842300 repaint();
18852301 }
18862302
1887
- void ToggleOeil()
2303
+ public void ToggleOeil()
18882304 {
18892305 OEIL ^= true;
18902306 }
18912307
1892
- void ToggleOeilOnce()
2308
+ public void ToggleOeilOnce()
18932309 {
18942310 OEILONCE ^= true;
2311
+ }
2312
+
2313
+ void ToggleFootContact()
2314
+ {
2315
+ FOOTCONTACT ^= true;
2316
+ }
2317
+
2318
+ void ToggleDebug()
2319
+ {
2320
+ Globals.DEBUG ^= true;
18952321 }
18962322
18972323 void ToggleLookAt()
....@@ -1899,9 +2325,9 @@
18992325 LOOKAT ^= true;
19002326 }
19012327
1902
- void ToggleRandom()
2328
+ void ToggleSwitch()
19032329 {
1904
- RANDOM ^= true;
2330
+ SWITCH ^= true;
19052331 }
19062332
19072333 void ToggleHandles()
....@@ -1909,10 +2335,17 @@
19092335 HANDLES ^= true;
19102336 }
19112337
2338
+ Object3D paintFolder;
2339
+
19122340 void TogglePaint()
19132341 {
19142342 PAINTMODE ^= true;
19152343 paintcount = 0;
2344
+
2345
+ if (PAINTMODE)
2346
+ {
2347
+ paintFolder = GetFolder();
2348
+ }
19162349 }
19172350
19182351 void SwapCamera(int a, int b)
....@@ -2008,7 +2441,22 @@
20082441 {
20092442 return currentGL;
20102443 }
2011
-
2444
+
2445
+ static private BufferedImage CreateBim(TextureData texturedata)
2446
+ {
2447
+ Grafreed.Assert(texturedata != null);
2448
+
2449
+ int width = texturedata.getWidth();
2450
+ int height = texturedata.getHeight();
2451
+
2452
+ Buffer buffer = texturedata.getBuffer();
2453
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2454
+
2455
+ byte[] bytes = bytebuf.array();
2456
+
2457
+ return CreateBim(bytes, width, height);
2458
+ }
2459
+
20122460 /**/
20132461 class CacheTexture
20142462 {
....@@ -2017,28 +2465,31 @@
20172465
20182466 int resolution;
20192467
2020
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2468
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
20212469 {
2022
- texture = tex;
2470
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2471
+ texturedata = texdata;
20232472 resolution = res;
20242473 }
20252474 }
20262475 /**/
20272476
20282477 // TEXTURE static Texture texture;
2029
- static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures
2030
- = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>();
2031
- static public java.util.Hashtable<String, String> usedtextures = new java.util.Hashtable<String, String>();
2478
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2479
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2480
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2481
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2482
+
20322483 int pigmentdepth = 0;
20332484 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
20342485 int bumpdepth = 0;
20352486 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
20362487 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
20372488 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2038
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2489
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
20392490 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
20402491
2041
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2492
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
20422493 {
20432494 TextureData texturedata = null;
20442495
....@@ -2057,13 +2508,34 @@
20572508 if (bump)
20582509 texturedata = ConvertBump(texturedata, false);
20592510
2060
- com.sun.opengl.util.texture.Texture texture =
2061
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2511
+// com.sun.opengl.util.texture.Texture texture =
2512
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
20622513
2063
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2064
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
2514
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2515
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
20652516
2066
- return texture;
2517
+ return texturedata;
2518
+ }
2519
+
2520
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2521
+ {
2522
+ TextureData texturedata = null;
2523
+
2524
+ try
2525
+ {
2526
+ texturedata =
2527
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2528
+ bim,
2529
+ true);
2530
+ } catch (Exception e)
2531
+ {
2532
+ throw new javax.media.opengl.GLException(e);
2533
+ }
2534
+
2535
+ if (bump)
2536
+ texturedata = ConvertBump(texturedata, false);
2537
+
2538
+ return texturedata;
20672539 }
20682540
20692541 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3136,6 +3608,8 @@
31363608
31373609 System.out.println("LOADING TEXTURE : " + name);
31383610
3611
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3612
+
31393613 //
31403614 if (false) // compressbit > 0)
31413615 {
....@@ -3840,6 +4314,7 @@
38404314
38414315 com.sun.opengl.util.texture.Texture CompressTexture2(String name)
38424316 {
4317
+ new Exception().printStackTrace();
38434318 System.exit(0);
38444319 com.sun.opengl.util.texture.Texture texture = null;
38454320
....@@ -7533,7 +8008,7 @@
75338008 String pigment = Object3D.GetPigment(tex);
75348009 String bump = Object3D.GetBump(tex);
75358010
7536
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8011
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
75378012 {
75388013 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
75398014 // System.out.println("; bump = " + bump);
....@@ -7548,11 +8023,69 @@
75488023 pigment = null;
75498024 }
75508025
7551
- ReleaseTexture(bump, true);
7552
- ReleaseTexture(pigment, false);
8026
+ ReleaseTexture(tex, true);
8027
+ ReleaseTexture(tex, false);
75538028 }
75548029
7555
- void ReleaseTexture(String tex, boolean bump)
8030
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
8031
+ {
8032
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8033
+ {
8034
+ return;
8035
+ }
8036
+
8037
+ if (tex == null)
8038
+ {
8039
+ ReleaseTexture(null, false);
8040
+ return;
8041
+ }
8042
+
8043
+ String pigment = Object3D.GetPigment(tex);
8044
+
8045
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8046
+ {
8047
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8048
+ // System.out.println("; bump = " + bump);
8049
+ }
8050
+
8051
+ if (pigment.equals(""))
8052
+ {
8053
+ pigment = null;
8054
+ }
8055
+
8056
+ ReleaseTexture(tex, false);
8057
+ }
8058
+
8059
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
8060
+ {
8061
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8062
+ {
8063
+ return;
8064
+ }
8065
+
8066
+ if (tex == null)
8067
+ {
8068
+ ReleaseTexture(null, true);
8069
+ return;
8070
+ }
8071
+
8072
+ String bump = Object3D.GetBump(tex);
8073
+
8074
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8075
+ {
8076
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8077
+ // System.out.println("; bump = " + bump);
8078
+ }
8079
+
8080
+ if (bump.equals(""))
8081
+ {
8082
+ bump = null;
8083
+ }
8084
+
8085
+ ReleaseTexture(tex, true);
8086
+ }
8087
+
8088
+ void ReleaseTexture(cTexture tex, boolean bump)
75568089 {
75578090 if (// DrawMode() != 0 || /*tex == null ||*/
75588091 ambientOcclusion ) // || !textureon)
....@@ -7563,7 +8096,7 @@
75638096 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
75648097
75658098 if (tex != null)
7566
- texture = textures.get(tex);
8099
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
75678100
75688101 // //assert( texture != null );
75698102 // if (texture == null)
....@@ -7655,7 +8188,55 @@
76558188 }
76568189 }
76578190
7658
- /*boolean*/ public void BindTextures(cTexture tex, int resolution) // INTERFACE
8191
+ /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
8192
+ {
8193
+// if (// DrawMode() != 0 || /*tex == null ||*/
8194
+// ambientOcclusion ) // || !textureon)
8195
+// {
8196
+// return; // false;
8197
+// }
8198
+//
8199
+// if (tex == null)
8200
+// {
8201
+// BindTexture(null,false,resolution);
8202
+// BindTexture(null,true,resolution);
8203
+// return;
8204
+// }
8205
+//
8206
+// String pigment = Object3D.GetPigment(tex);
8207
+// String bump = Object3D.GetBump(tex);
8208
+//
8209
+// usedtextures.add(pigment);
8210
+// usedtextures.add(bump);
8211
+//
8212
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8213
+// {
8214
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8215
+// // System.out.println("; bump = " + bump);
8216
+// }
8217
+//
8218
+// if (bump.equals(""))
8219
+// {
8220
+// bump = null;
8221
+// }
8222
+// if (pigment.equals(""))
8223
+// {
8224
+// pigment = null;
8225
+// }
8226
+//
8227
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8228
+// BindTexture(pigment, false, resolution);
8229
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8230
+// BindTexture(bump, true, resolution);
8231
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8232
+//
8233
+// return; // true;
8234
+
8235
+ BindPigmentTexture(tex, resolution);
8236
+ BindBumpTexture(tex, resolution);
8237
+ }
8238
+
8239
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
76598240 {
76608241 if (// DrawMode() != 0 || /*tex == null ||*/
76618242 ambientOcclusion ) // || !textureon)
....@@ -7666,17 +8247,47 @@
76668247 if (tex == null)
76678248 {
76688249 BindTexture(null,false,resolution);
7669
- BindTexture(null,true,resolution);
76708250 return;
76718251 }
76728252
76738253 String pigment = Object3D.GetPigment(tex);
8254
+
8255
+ usedtextures.add(tex);
8256
+
8257
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8258
+ {
8259
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8260
+ // System.out.println("; bump = " + bump);
8261
+ }
8262
+
8263
+ if (pigment.equals(""))
8264
+ {
8265
+ pigment = null;
8266
+ }
8267
+
8268
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8269
+ BindTexture(tex, false, resolution);
8270
+ }
8271
+
8272
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8273
+ {
8274
+ if (// DrawMode() != 0 || /*tex == null ||*/
8275
+ ambientOcclusion ) // || !textureon)
8276
+ {
8277
+ return; // false;
8278
+ }
8279
+
8280
+ if (tex == null)
8281
+ {
8282
+ BindTexture(null,true,resolution);
8283
+ return;
8284
+ }
8285
+
76748286 String bump = Object3D.GetBump(tex);
76758287
7676
- usedtextures.put(pigment, pigment);
7677
- usedtextures.put(bump, bump);
8288
+ usedtextures.add(tex);
76788289
7679
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8290
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
76808291 {
76818292 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
76828293 // System.out.println("; bump = " + bump);
....@@ -7686,43 +8297,94 @@
76868297 {
76878298 bump = null;
76888299 }
7689
- if (pigment.equals(""))
7690
- {
7691
- pigment = null;
7692
- }
76938300
7694
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
7695
- BindTexture(pigment, false, resolution);
76968301 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
7697
- BindTexture(bump, true, resolution);
8302
+ BindTexture(tex, true, resolution);
76988303 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
7699
-
7700
- return; // true;
77018304 }
77028305
7703
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution)
8306
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8307
+
8308
+ private boolean FileExists(String tex)
77048309 {
7705
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8310
+ if (missingTextures.contains(tex))
8311
+ {
8312
+ return false;
8313
+ }
8314
+
8315
+ boolean fileExists = new File(tex).exists();
8316
+
8317
+ if (!fileExists)
8318
+ {
8319
+ // If file exists, the "new File()" is not executed sgain
8320
+ missingTextures.add(tex);
8321
+ }
8322
+
8323
+ return fileExists;
8324
+ }
8325
+
8326
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
8327
+ {
8328
+ CacheTexture texturecache = null;
77068329
77078330 if (tex != null)
77088331 {
7709
- String texname = tex;
8332
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8333
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
77108334
7711
- String[] split = tex.split("Textures");
7712
- if (split.length > 1)
7713
- texname = "/Users/nbriere/Textures" + split[split.length-1];
7714
- else
7715
- if (!texname.startsWith("/"))
7716
- texname = "/Users/nbriere/Textures/" + texname;
8335
+ if (texname.equals("") && texdata == null)
8336
+ {
8337
+ return null;
8338
+ }
8339
+
8340
+ String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
8341
+
8342
+// String[] split = tex.split("Textures");
8343
+// if (split.length > 1)
8344
+// texname = "/Users/nbriere/Textures" + split[split.length-1];
8345
+// else
8346
+// if (!texname.startsWith("/"))
8347
+// texname = "/Users/nbriere/Textures/" + texname;
8348
+ if (!FileExists(texname))
8349
+ {
8350
+ texname = fallbackTextureName;
8351
+ }
77178352
77188353 if (CACHETEXTURE)
7719
- texture = textures.get(texname); // TEXTURE CACHE
7720
-
7721
- TextureData texturedata = null;
7722
-
7723
- if (texture == null || texture.resolution < resolution)
77248354 {
7725
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8355
+ if (texdata == null)
8356
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8357
+ else
8358
+ texturecache = bimtextures.get(texdata);
8359
+ }
8360
+
8361
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8362
+ {
8363
+ TextureData texturedata = null;
8364
+
8365
+ if (texdata != null && textureon)
8366
+ {
8367
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8368
+
8369
+ try
8370
+ {
8371
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8372
+ }
8373
+ catch (Exception e)
8374
+ {
8375
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8376
+ }
8377
+
8378
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8379
+ bimtextures.put(texdata, texturecache);
8380
+
8381
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8382
+
8383
+ //Object bim2 = CreateBim(texturecache.texturedata);
8384
+ //bim2 = bim;
8385
+ }
8386
+ else
8387
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
77268388 {
77278389 assert(!bump);
77288390 // if (bump)
....@@ -7733,19 +8395,23 @@
77338395 // }
77348396 // else
77358397 // {
7736
- texture = textures.get(tex);
7737
- if (texture == null)
8398
+ // texturecache = textures.get(texname); // suspicious
8399
+ if (texturecache == null)
77388400 {
7739
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8401
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
77408402 }
8403
+ else
8404
+ new Exception().printStackTrace();
77418405 // }
77428406 } else
7743
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8407
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
77448408 {
77458409 assert(bump);
7746
- texture = textures.get(tex);
7747
- if (texture == null)
7748
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8410
+ // texturecache = textures.get(texname); // suspicious
8411
+ if (texturecache == null)
8412
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8413
+ else
8414
+ new Exception().printStackTrace();
77498415 } else
77508416 {
77518417 //if (tex.equals("IMMORTAL"))
....@@ -7753,11 +8419,13 @@
77538419 // texture = GetResourceTexture("default.png");
77548420 //} else
77558421 //{
7756
- if (tex.equals("WHITE_NOISE"))
8422
+ if (texname.endsWith("WHITE_NOISE"))
77578423 {
7758
- texture = textures.get(tex);
7759
- if (texture == null)
7760
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8424
+ // texturecache = textures.get(texname); // suspicious
8425
+ if (texturecache == null)
8426
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8427
+ else
8428
+ new Exception().printStackTrace();
77618429 } else
77628430 {
77638431 if (textureon)
....@@ -7782,7 +8450,7 @@
77828450 }
77838451
77848452 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
7785
- if (!new File(cachename).exists())
8453
+ if (!FileExists(cachename))
77868454 cachename = texname;
77878455 else
77888456 processbump = false; // don't process bump map again
....@@ -7804,7 +8472,7 @@
78048472 }
78058473
78068474 cachename = texname.substring(0, texname.length()-4)+ext+".png";
7807
- if (!new File(cachename).exists())
8475
+ if (!FileExists(cachename))
78088476 cachename = texname;
78098477 else
78108478 processbump = false; // don't process bump map again
....@@ -7813,20 +8481,22 @@
78138481 texturedata = GetFileTexture(cachename, processbump, resolution);
78148482
78158483
7816
- if (texturedata != null)
7817
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8484
+ if (texturedata == null)
8485
+ throw new Exception();
8486
+
8487
+ texturecache = new CacheTexture(texturedata,resolution);
78188488 //texture = GetTexture(tex, bump);
78198489 }
78208490 }
78218491 //}
78228492 }
78238493
7824
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8494
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
78258495 {
78268496 //return false;
78278497
78288498 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
7829
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8499
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
78308500 {
78318501 // String ext = "_highres";
78328502 // if (REDUCETEXTURE)
....@@ -7843,52 +8513,17 @@
78438513 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
78448514 if (!cachefile.exists())
78458515 {
7846
- // cache to disk
7847
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
7848
- //buffers[0].
7849
-
7850
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
7851
- int[] pixels = new int[bytebuf.capacity()/3];
7852
-
7853
- // squared size heuristic...
7854
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8516
+ //if (texturedata.getWidth() == texturedata.getHeight())
78558517 {
7856
- for (int i=pixels.length; --i>=0;)
7857
- {
7858
- int i3 = i*3;
7859
- pixels[i] = 0xFF;
7860
- pixels[i] <<= 8;
7861
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
7862
- pixels[i] <<= 8;
7863
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
7864
- pixels[i] <<= 8;
7865
- pixels[i] |= bytebuf.get(i3) & 0xFF;
7866
- }
7867
-
7868
- /*
7869
- int r=0,g=0,b=0,a=0;
7870
- for (int i=0; i<width; i++)
7871
- for (int j=0; j<height; j++)
7872
- {
7873
- int index = j*width+i;
7874
- int p = pixels[index];
7875
- a = ((p>>24) & 0xFF);
7876
- r = ((p>>16) & 0xFF);
7877
- g = ((p>>8) & 0xFF);
7878
- b = (p & 0xFF);
7879
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
7880
- }
7881
- /**/
7882
- int width = (int)Math.sqrt(pixels.length); // squared
7883
- int height = width;
7884
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
7885
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8518
+ BufferedImage rendImage = CreateBim(texturedata);
8519
+
78868520 ImageWriter writer = null;
78878521 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
78888522 if (iter.hasNext()) {
78898523 writer = (ImageWriter)iter.next();
78908524 }
7891
- float compressionQuality = 0.9f;
8525
+
8526
+ float compressionQuality = 0.85f;
78928527 try
78938528 {
78948529 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -7905,18 +8540,20 @@
79058540 }
79068541 }
79078542 }
7908
-
8543
+
8544
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8545
+
79098546 //System.out.println("Texture = " + tex);
7910
- if (textures.containsKey(texname))
8547
+ if (textures.containsKey(tex))
79118548 {
7912
- CacheTexture thetex = textures.get(texname);
8549
+ CacheTexture thetex = textures.get(tex);
79138550 thetex.texture.disable();
79148551 thetex.texture.dispose();
7915
- textures.remove(texname);
8552
+ textures.remove(tex);
79168553 }
79178554
7918
- texture.texturedata = texturedata;
7919
- textures.put(texname, texture);
8555
+ //texture.texturedata = texturedata;
8556
+ textures.put(tex, texturecache);
79208557
79218558 // newtex = true;
79228559 }
....@@ -7932,10 +8569,44 @@
79328569 }
79338570 }
79348571
7935
- return texture;
8572
+ return texturecache;
79368573 }
79378574
7938
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution)
8575
+ static void EmbedTextures(cTexture tex)
8576
+ {
8577
+ if (tex.pigmentdata == null)
8578
+ {
8579
+ //String texname = Object3D.GetPigment(tex);
8580
+
8581
+ CacheTexture texturecache = texturepigment.get(tex);
8582
+
8583
+ if (texturecache != null)
8584
+ {
8585
+ tex.pw = texturecache.texturedata.getWidth();
8586
+ tex.ph = texturecache.texturedata.getHeight();
8587
+ tex.pigmentdata = //CompressJPEG(CreateBim
8588
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8589
+ ;
8590
+ //, tex.pw, tex.ph), 0.5f);
8591
+ }
8592
+ }
8593
+
8594
+ if (tex.bumpdata == null)
8595
+ {
8596
+ //String texname = Object3D.GetBump(tex);
8597
+
8598
+ CacheTexture texturecache = texturebump.get(tex);
8599
+
8600
+ if (texturecache != null)
8601
+ {
8602
+ tex.bw = texturecache.texturedata.getWidth();
8603
+ tex.bh = texturecache.texturedata.getHeight();
8604
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8605
+ }
8606
+ }
8607
+ }
8608
+
8609
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
79398610 {
79408611 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
79418612
....@@ -7953,21 +8624,21 @@
79538624 return texture!=null?texture.texture:null;
79548625 }
79558626
7956
- com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution)
8627
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
79578628 {
79588629 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
79598630
79608631 return texture!=null?texture.texturedata:null;
79618632 }
79628633
7963
- boolean BindTexture(String tex, boolean bump, int resolution)
8634
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
79648635 {
79658636 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
79668637 {
79678638 return false;
79688639 }
79698640
7970
- boolean newtex = false;
8641
+ //boolean newtex = false;
79718642
79728643 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
79738644
....@@ -7999,9 +8670,75 @@
79998670 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
80008671 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
80018672
8002
- return newtex;
8673
+ return true; // Warning: not used.
80038674 }
80048675
8676
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8677
+ {
8678
+ try
8679
+ {
8680
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8681
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8682
+ ImageWriter writer = writers.next();
8683
+
8684
+ ImageWriteParam param = writer.getDefaultWriteParam();
8685
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8686
+ param.setCompressionQuality(quality);
8687
+
8688
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8689
+ writer.setOutput(ios);
8690
+ writer.write(null, new IIOImage(image, null, null), param);
8691
+
8692
+ byte[] data = baos.toByteArray();
8693
+ writer.dispose();
8694
+ return data;
8695
+ }
8696
+ catch (Exception e)
8697
+ {
8698
+ e.printStackTrace();
8699
+ return null;
8700
+ }
8701
+ }
8702
+
8703
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8704
+ {
8705
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8706
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8707
+ ImageReader reader = writers.next();
8708
+
8709
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8710
+
8711
+ ImageReadParam param = reader.getDefaultReadParam();
8712
+ param.setDestination(bim);
8713
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8714
+
8715
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8716
+ reader.setInput(ios);
8717
+ BufferedImage bim2 = reader.read(0, param);
8718
+ reader.dispose();
8719
+
8720
+// WritableRaster raster = bim2.getRaster();
8721
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8722
+// byte[] bytes = data.getData();
8723
+//
8724
+// int[] pixels = new int[bytes.length/3];
8725
+// for (int i=pixels.length; --i>=0;)
8726
+// {
8727
+// int i3 = i*3;
8728
+// pixels[i] = 0xFF;
8729
+// pixels[i] <<= 8;
8730
+// pixels[i] |= bytes[i3+2] & 0xFF;
8731
+// pixels[i] <<= 8;
8732
+// pixels[i] |= bytes[i3+1] & 0xFF;
8733
+// pixels[i] <<= 8;
8734
+// pixels[i] |= bytes[i3] & 0xFF;
8735
+// }
8736
+//
8737
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8738
+
8739
+ return bim;
8740
+ }
8741
+
80058742 ShadowBuffer shadowPBuf;
80068743 AntialiasBuffer antialiasPBuf;
80078744 int MAXSTACK;
....@@ -8837,11 +9574,35 @@
88379574 jy8[3] = 0.5f;
88389575 }
88399576
8840
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9577
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
88419578 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
88429579 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
88439580 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
88449581
9582
+ void ResetOptions()
9583
+ {
9584
+ options1[0] = 100;
9585
+ options1[1] = 0.025f;
9586
+ options1[2] = 0.01f;
9587
+ options1[3] = 0;
9588
+ options1[4] = 0;
9589
+
9590
+ options2[0] = 0;
9591
+ options2[1] = 0.75f;
9592
+ options2[2] = 0;
9593
+ options2[3] = 0;
9594
+
9595
+ options3[0] = 1;
9596
+ options3[1] = 1;
9597
+ options3[2] = 1;
9598
+ options3[3] = 0;
9599
+
9600
+ options4[0] = 1;
9601
+ options4[1] = 0;
9602
+ options4[2] = 1;
9603
+ options4[3] = 0;
9604
+ }
9605
+
88459606 static int imagecount = 0; // movie generation
88469607
88479608 static int jitter = 0;
....@@ -8937,8 +9698,8 @@
89379698 assert (parentcam != renderCamera);
89389699
89399700 if (renderCamera != lightCamera)
8940
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8941
- LA.matConcat(matrix, parentcam.toParent, matrix);
9701
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9702
+ LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
89429703
89439704 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
89449705
....@@ -8953,8 +9714,8 @@
89539714 LA.matCopy(renderCamera.fromScreen, matrix);
89549715
89559716 if (renderCamera != lightCamera)
8956
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8957
- LA.matConcat(parentcam.fromParent, matrix, matrix);
9717
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9718
+ LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
89589719
89599720 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
89609721
....@@ -9026,7 +9787,7 @@
90269787 //gl.glFlush();
90279788 gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE);
90289789
9029
- if (ANIMATION && ABORTED)
9790
+ if (Globals.ANIMATION && ABORTED)
90309791 {
90319792 System.err.println(" ABORTED FRAME");
90329793 break;
....@@ -9056,7 +9817,7 @@
90569817 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
90579818
90589819 // save image
9059
- if (ANIMATION && !ABORTED)
9820
+ if (Globals.ANIMATION && !ABORTED)
90609821 {
90619822 VPwidth = viewport[2];
90629823 VPheight = viewport[3];
....@@ -9167,11 +9928,11 @@
91679928
91689929 // imagecount++;
91699930
9170
- String fullname = filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
9931
+ String fullname = Globals.filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
91719932
91729933 if (!BOXMODE)
91739934 {
9174
- System.out.println("image: " + fullname + " (wav cursor=" + (GrafreeD.wav.cursor / 735 / 4) + ")");
9935
+ System.out.println("image: " + fullname + " (wav cursor=" + (Grafreed.wav.cursor / 735 / 4) + ")");
91759936 }
91769937
91779938 if (!BOXMODE)
....@@ -9209,7 +9970,7 @@
92099970 ABORTED = false;
92109971 }
92119972 else
9212
- GrafreeD.wav.cursor += 735 * ACSIZE;
9973
+ Grafreed.wav.cursor += 735 * ACSIZE;
92139974
92149975 if (false)
92159976 {
....@@ -9872,11 +10633,11 @@
987210633
987310634 public void display(GLAutoDrawable drawable)
987410635 {
9875
- if (GrafreeD.savesound && GrafreeD.hassound)
10636
+ if (Grafreed.savesound && Grafreed.hassound)
987610637 {
9877
- GrafreeD.wav.save();
9878
- GrafreeD.savesound = false;
9879
- GrafreeD.hassound = false;
10638
+ Grafreed.wav.save();
10639
+ Grafreed.savesound = false;
10640
+ Grafreed.hassound = false;
988010641 }
988110642 // if (DEBUG_SELECTION)
988210643 // {
....@@ -9952,6 +10713,7 @@
995210713 ANTIALIAS = 0;
995310714 //System.out.println("RESTART");
995410715 AAtimer.restart();
10716
+ Globals.TIMERRUNNING = true;
995510717 }
995610718 }
995710719 }
....@@ -10006,7 +10768,7 @@
1000610768 Object3D theobject = object;
1000710769 Object3D theparent = object.parent;
1000810770 object.parent = null;
10009
- object = (Object3D)GrafreeD.clone(object);
10771
+ object = (Object3D)Grafreed.clone(object);
1001010772 object.Stripify();
1001110773 if (theobject.selection == null || theobject.selection.Size() == 0)
1001210774 theobject.PreprocessOcclusion(this);
....@@ -10019,13 +10781,14 @@
1001910781 ambientOcclusion = false;
1002010782 }
1002110783
10022
- if (Globals.lighttouched && DrawMode() == DEFAULT && !lightMode) // && !FROZEN)
10784
+ if (//Globals.lighttouched &&
10785
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1002310786 {
1002410787 //if (RENDERSHADOW) // ?
1002510788 if (!IsFrozen())
1002610789 {
1002710790 // dec 2012
10028
- if (!ambientOcclusion && !(!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0))
10791
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
1002910792 {
1003010793 Globals.framecount++;
1003110794 shadowbuffer.display();
....@@ -10152,8 +10915,8 @@
1015210915
1015310916 // if (parentcam != renderCamera) // not a light
1015410917 if (cam != lightCamera)
10155
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10156
- LA.matConcat(matrix, parentcam.toParent, matrix);
10918
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10919
+ LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
1015710920
1015810921 for (int j = 0; j < 4; j++)
1015910922 {
....@@ -10167,8 +10930,8 @@
1016710930
1016810931 // if (parentcam != renderCamera) // not a light
1016910932 if (cam != lightCamera)
10170
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10171
- LA.matConcat(parentcam.fromParent, matrix, matrix);
10933
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10934
+ LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
1017210935
1017310936 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1017410937
....@@ -10427,7 +11190,16 @@
1042711190 // Bump noise
1042811191 gl.glActiveTexture(GL.GL_TEXTURE6);
1042911192 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
10430
- BindTexture(NOISE_TEXTURE, false, 2);
11193
+
11194
+ try
11195
+ {
11196
+ BindTexture(NOISE_TEXTURE, false, 2);
11197
+ }
11198
+ catch (Exception e)
11199
+ {
11200
+ System.err.println("FAILED: " + NOISE_TEXTURE);
11201
+ }
11202
+
1043111203
1043211204 gl.glActiveTexture(GL.GL_TEXTURE0);
1043311205 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -10450,9 +11222,9 @@
1045011222
1045111223 gl.glMatrixMode(GL.GL_MODELVIEW);
1045211224
10453
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10454
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10455
-//gl.glEnable(gl.GL_MULTISAMPLE);
11225
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11226
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11227
+gl.glEnable(gl.GL_MULTISAMPLE);
1045611228 } else
1045711229 {
1045811230 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -10463,7 +11235,7 @@
1046311235 //System.out.println("BLENDING ON");
1046411236 gl.glEnable(GL.GL_BLEND);
1046511237 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
10466
-
11238
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1046711239 gl.glMatrixMode(gl.GL_PROJECTION);
1046811240 gl.glLoadIdentity();
1046911241
....@@ -10552,8 +11324,8 @@
1055211324 System.err.println("parentcam != renderCamera");
1055311325
1055411326 // if (cam != lightCamera)
10555
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10556
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11327
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11328
+ LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
1055711329 }
1055811330
1055911331 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -10574,8 +11346,8 @@
1057411346 if (true) // TODO
1057511347 {
1057611348 if (cam != lightCamera)
10577
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10578
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11349
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11350
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
1057911351 }
1058011352
1058111353 LA.xformPos(light0, cam.toScreen, light0);
....@@ -10712,7 +11484,7 @@
1071211484 }
1071311485 }
1071411486
10715
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11487
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1071611488 {
1071711489 //gl.glDepthFunc(GL.GL_LEQUAL);
1071811490 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -10720,24 +11492,21 @@
1072011492
1072111493 boolean texon = textureon;
1072211494
10723
- if (RENDERPROGRAM > 0)
10724
- {
10725
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
10726
- textureon = false;
10727
- }
11495
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11496
+ textureon = false;
11497
+
1072811498 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1072911499 //System.out.println("ALLO");
1073011500 gl.glColorMask(false, false, false, false);
1073111501 DrawObject(gl);
10732
- if (RENDERPROGRAM > 0)
10733
- {
10734
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
10735
- textureon = texon;
10736
- }
11502
+
11503
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11504
+ textureon = texon;
11505
+
1073711506 gl.glColorMask(true, true, true, true);
1073811507
1073911508 gl.glDepthFunc(GL.GL_EQUAL);
10740
- //gl.glDepthMask(false);
11509
+ gl.glDepthMask(false);
1074111510 }
1074211511
1074311512 if (false) // DrawMode() == SHADOW)
....@@ -10891,8 +11660,14 @@
1089111660 {
1089211661 renderpass++;
1089311662 // System.out.println("Draw object... ");
11663
+ STEP = 1;
1089411664 if (FAST) // in case there is no script
10895
- STEP = 16;
11665
+ STEP = 8;
11666
+
11667
+ if (CURRENTANTIALIAS == 0 || ACSIZE == 1)
11668
+ {
11669
+ STEP *= 4;
11670
+ }
1089611671
1089711672 //object.FullInvariants();
1089811673
....@@ -10906,23 +11681,44 @@
1090611681 e.printStackTrace();
1090711682 }
1090811683
10909
- if (GrafreeD.RENDERME > 0)
10910
- GrafreeD.RENDERME--; // mechante magouille
11684
+ if (Grafreed.RENDERME > 0)
11685
+ Grafreed.RENDERME--; // mechante magouille
1091111686
1091211687 Globals.ONESTEP = false;
1091311688 }
1091411689
1091511690 static boolean zoomonce = false;
1091611691
11692
+ static void CreateSelectedPoint()
11693
+ {
11694
+ if (selectedpoint == null)
11695
+ {
11696
+ debugpointG = new Sphere();
11697
+ debugpointP = new Sphere();
11698
+ debugpointC = new Sphere();
11699
+ debugpointR = new Sphere();
11700
+
11701
+ selectedpoint = new Superellipsoid();
11702
+
11703
+ for (int i=0; i<8; i++)
11704
+ {
11705
+ debugpoints[i] = new Sphere();
11706
+ }
11707
+ }
11708
+ }
11709
+
1091711710 void DrawObject(GL gl, boolean draw)
1091811711 {
11712
+ // To clear camera values
11713
+ ResetOptions();
11714
+
1091911715 //System.out.println("DRAW OBJECT " + mouseDown);
1092011716 // DrawMode() = SELECTION;
1092111717 //GL gl = getGL();
1092211718 if ((TRACK || SHADOWTRACK) || zoomonce)
1092311719 {
1092411720 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
10925
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11721
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1092611722 pingthread.StepToTarget(true); // true);
1092711723 // zoomonce = false;
1092811724 }
....@@ -10977,7 +11773,14 @@
1097711773
1097811774 usedtextures.clear();
1097911775
10980
- BindTextures(DEFAULT_TEXTURES, 2);
11776
+ try
11777
+ {
11778
+ BindTextures(DEFAULT_TEXTURES, 2);
11779
+ }
11780
+ catch (Exception e)
11781
+ {
11782
+ System.err.println("FAILED: " + DEFAULT_TEXTURES);
11783
+ }
1098111784 }
1098211785 //System.out.println("--> " + stackdepth);
1098311786 // GrafreeD.traceon();
....@@ -10987,8 +11790,9 @@
1098711790
1098811791 if (DrawMode() == DEFAULT)
1098911792 {
10990
- if (DEBUG)
11793
+ if (Globals.DEBUG)
1099111794 {
11795
+ CreateSelectedPoint();
1099211796 float radius = 0.05f;
1099311797 if (selectedpoint.radius != radius)
1099411798 {
....@@ -11042,20 +11846,32 @@
1104211846 ReleaseTextures(DEFAULT_TEXTURES);
1104311847
1104411848 if (CLEANCACHE)
11045
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11849
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1104611850 {
11047
- String tex = e.nextElement();
11851
+ cTexture tex = e.nextElement();
1104811852
1104911853 // System.out.println("Texture --------- " + tex);
1105011854
11051
- if (tex.equals("WHITE_NOISE"))
11855
+ if (tex.equals("WHITE_NOISE:"))
1105211856 continue;
1105311857
11054
- if (!usedtextures.containsKey(tex))
11858
+ if (!usedtextures.contains(tex))
1105511859 {
11860
+ CacheTexture gettex = texturepigment.get(tex);
1105611861 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11057
- textures.get(tex).texture.dispose();
11058
- textures.remove(tex);
11862
+ if (gettex != null)
11863
+ {
11864
+ gettex.texture.dispose();
11865
+ texturepigment.remove(tex);
11866
+ }
11867
+
11868
+ gettex = texturebump.get(tex);
11869
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11870
+ if (gettex != null)
11871
+ {
11872
+ gettex.texture.dispose();
11873
+ texturebump.remove(tex);
11874
+ }
1105911875 }
1106011876 }
1106111877 }
....@@ -11068,7 +11884,14 @@
1106811884 if (checker != null && DrawMode() == DEFAULT)
1106911885 {
1107011886 //BindTexture(IMMORTAL_TEXTURE);
11071
- BindTextures(checker.GetTextures(), checker.texres);
11887
+ try
11888
+ {
11889
+ BindTextures(checker.GetTextures(), checker.texres);
11890
+ }
11891
+ catch (Exception e)
11892
+ {
11893
+ System.err.println("FAILED: " + checker.GetTextures());
11894
+ }
1107211895 // NEAREST
1107311896 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
1107411897 DrawChecker(gl);
....@@ -11150,7 +11973,7 @@
1115011973 return;
1115111974 }
1115211975
11153
- String string = obj.GetToolTip();
11976
+ String string = obj.toString(); //.GetToolTip();
1115411977
1115511978 GL gl = GetGL();
1115611979
....@@ -11467,8 +12290,8 @@
1146712290 //obj.TransformToWorld(light, light);
1146812291 for (int i = tp.size(); --i >= 0;)
1146912292 {
11470
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
11471
- LA.xformPos(light, tp.get(i).toParent, light);
12293
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12294
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1147212295 }
1147312296
1147412297
....@@ -11485,8 +12308,8 @@
1148512308 parentcam = cameras[0];
1148612309 }
1148712310
11488
- for (int count = parentcam.GetTransformCount(); --count>=0;)
11489
- LA.xformPos(light, parentcam.toParent, light); // may 2013
12311
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
12312
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1149012313
1149112314 LA.xformPos(light, renderCamera.toScreen, light);
1149212315
....@@ -11577,7 +12400,52 @@
1157712400 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1157812401
1157912402 String program =
12403
+ // Min shader
1158012404 "!!ARBfp1.0\n" +
12405
+ "PARAM zero123 = { 0.0, 1.0, 2.0, 1.25 };" +
12406
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12407
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12408
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12409
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12410
+ "TEMP temp;" +
12411
+ "TEMP light;" +
12412
+ "TEMP ndotl;" +
12413
+ "TEMP normal;" +
12414
+ "TEMP depth;" +
12415
+
12416
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12417
+
12418
+ "MOV light, state.light[0].position;" +
12419
+ "DP3 ndotl.x, light, normal;" +
12420
+
12421
+ // shadow
12422
+ "MOV temp, fragment.texcoord[1];" +
12423
+ TextureFetch("depth", "temp", "1") +
12424
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12425
+ "SLT temp.x, fragment.texcoord[1].z, depth.z;" +
12426
+
12427
+
12428
+ // No shadow when out of frustum
12429
+ //"SGE temp.y, depth.z, zero123.y;" +
12430
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12431
+
12432
+ "MUL ndotl.x, ndotl.x, temp.x;" +
12433
+ "MAX ndotl.x, ndotl.x, pow2.y;" +
12434
+
12435
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12436
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12437
+ "MUL temp, temp, ndotl.x;" +
12438
+
12439
+ "MUL temp, temp, zero123.z;" +
12440
+
12441
+ "MOV temp.w, zero123.y;" + // reset alpha
12442
+
12443
+ "MOV result.color, temp;" +
12444
+ "END";
12445
+
12446
+ String program2 =
12447
+ "!!ARBfp1.0\n" +
12448
+
1158112449 //"OPTION ARB_fragment_program_shadow;" +
1158212450 "PARAM light2cam0 = program.env[10];" +
1158312451 "PARAM light2cam1 = program.env[11];" +
....@@ -11692,8 +12560,7 @@
1169212560 "TEMP shininess;" +
1169312561 "\n" +
1169412562 "MOV texSamp, one;" +
11695
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
11696
-
12563
+
1169712564 "MOV mapgrid.x, one2048th.x;" +
1169812565 "MOV temp, fragment.texcoord[1];" +
1169912566 /*
....@@ -12098,10 +12965,10 @@
1209812965 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1209912966 "") +
1210012967
12101
- // display shadow only (bump == 0)
12968
+ // display shadow only (fakedepth == 0)
1210212969 "SUB temp.x, half.x, shadow.x;" +
12103
- "MOV temp.y, -params6.x;" +
12104
- "SLT temp.z, temp.y, zero.x;" +
12970
+ "MOV temp.y, -params5.z;" + // params6.x;" +
12971
+ "SLT temp.z, temp.y, -one2048th.x;" +
1210512972 "SUB temp.y, one.x, temp.z;" +
1210612973 "MUL temp.x, temp.x, temp.y;" +
1210712974 "KIL temp.x;" +
....@@ -12230,8 +13097,10 @@
1223013097 "MAX ndotl.x, ndotl.x, -ndotl.x;" +
1223113098
1223213099 "SUB temp.x, one.x, ndotl.x;" +
12233
- "ADD temp.x, temp.x, options2.z;" + // lightsheen
12234
- "ADD temp.y, one.y, options2.y;" + // sursurface
13100
+ // Tuning for default skin
13101
+ //"ADD temp.x, temp.x, options2.z;" + // lightsheen
13102
+ "MAD temp.x, options2.z, half.y, temp.x;" + // lightsheen
13103
+ "ADD temp.y, one.y, options2.y;" + // subsurface
1223513104 "MUL temp.x, temp.x, temp.y;" +
1223613105
1223713106 "MUL saturation, saturation, temp.xxxx;" +
....@@ -12430,7 +13299,7 @@
1243013299 //once = true;
1243113300 }
1243213301
12433
- System.out.print("Program #" + mode + "; length = " + program.length());
13302
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1243413303 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1243513304 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1243613305
....@@ -12528,20 +13397,20 @@
1252813397 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1252913398 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1253013399 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13400
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13401
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1253113402 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12532
- "SLT " + src + ".z, " + src + ".x, one.x;" +
12533
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12534
- "SLT " + src + ".z, " + src + ".y, one.x;" +
12535
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13403
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13404
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1253613405 //"SWZ buffer, temp, w,w,w,w;";
12537
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13406
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1253813407 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1253913408 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1254013409 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
12541
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13410
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1254213411
12543
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
12544
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13412
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13413
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1254513414 }
1254613415
1254713416 String Shadow(String depth, String shadow)
....@@ -12563,12 +13432,16 @@
1256313432
1256413433 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1256513434 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13435
+
13436
+ // Compare fragment depth in light space with shadowmap.
1256613437 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1256713438 "SGE temp.y, temp.x, zero.x;" +
12568
- "SUB " + shadow + ".y, one.x, temp.y;" +
13439
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13440
+
13441
+ // Reverse comparison
1256913442 "SUB temp.x, one.x, temp.x;" +
1257013443 "MUL " + shadow + ".x, temp.x, temp.y;" +
12571
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13444
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1257213445 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1257313446
1257413447 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -12582,6 +13455,10 @@
1258213455 // No shadow for backface
1258313456 "DP3 temp.x, normal, lightd;" +
1258413457 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13458
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13459
+
13460
+ // No shadow when out of frustum
13461
+ "SGE temp.x, " + depth + ".z, one.z;" +
1258513462 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1258613463 "";
1258713464 }
....@@ -12728,7 +13605,8 @@
1272813605 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1272913606 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1273013607 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
12731
- Object3D.cVector2[] vector2buffer;
13608
+
13609
+ //Object3D.cVector2[] vector2buffer;
1273213610
1273313611 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1273413612 // OUT : diff, spec
....@@ -12744,9 +13622,10 @@
1274413622 "DP3 " + dest + ".z," + "normals," + "eye;" +
1274513623 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1274613624 //"MOV " + dest + ".w," + "normal.z;" +
12747
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
12748
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
12749
- //"MOV " + dest + ".z," + "params2.w;" +
13625
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13626
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13627
+
13628
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1275013629 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1275113630 "RCP " + dest + ".w," + dest + ".w;" +
1275213631 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13140,7 +14019,7 @@
1314014019 public void mousePressed(MouseEvent e)
1314114020 {
1314214021 //System.out.println("mousePressed: " + e);
13143
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14022
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1314414023 }
1314514024
1314614025 static long prevtime = 0;
....@@ -13167,6 +14046,7 @@
1316714046
1316814047 //System.err.println("Dtime = " + Dtime + "; units = " + e.getUnitsToScroll() + "; ratio (units/ms) = " + ratio);
1316914048
14049
+ if (BUTTONLESSWHEEL)
1317014050 if (Math.abs(ratio) < 0.1 || Math.abs(Dtime) == 0) // < 30)
1317114051 {
1317214052 return;
....@@ -13175,7 +14055,7 @@
1317514055 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
1317614056
1317714057 // TIMER
13178
- if (!wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
14058
+ if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
1317914059 {
1318014060 keepboxmode = BOXMODE;
1318114061 keepsupport = SUPPORT;
....@@ -13215,8 +14095,8 @@
1321514095 // mode |= META;
1321614096 //}
1321714097
13218
- SetMouseMode(WHEEL | e.getModifiersEx());
13219
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14098
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14099
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1322014100 anchorX = ax;
1322114101 anchorY = ay;
1322214102 prevX = px;
....@@ -13250,6 +14130,7 @@
1325014130 else
1325114131 if (evt.getSource() == AAtimer)
1325214132 {
14133
+ Globals.TIMERRUNNING = false;
1325314134 if (mouseDown)
1325414135 {
1325514136 //new Exception().printStackTrace();
....@@ -13275,6 +14156,10 @@
1327514156 // LIVE = waslive;
1327614157 // wasliveok = true;
1327714158 // waslive = false;
14159
+
14160
+ // May 2019 Forget it:
14161
+ if (true)
14162
+ return;
1327814163
1327914164 // source == timer
1328014165 if (mouseDown)
....@@ -13305,7 +14190,7 @@
1330514190
1330614191 // fev 2014???
1330714192 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13308
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14193
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1330914194 pingthread.StepToTarget(true); // true);
1331014195 }
1331114196 // if (!LIVE)
....@@ -13314,12 +14199,13 @@
1331414199
1331514200 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1331614201
13317
- void clickStart(int x, int y, int modifiers)
14202
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1331814203 {
1331914204 if (!wasliveok)
1332014205 return;
1332114206
1332214207 AAtimer.restart(); //
14208
+ Globals.TIMERRUNNING = true;
1332314209
1332414210 // waslive = LIVE;
1332514211 // LIVE = false;
....@@ -13331,7 +14217,7 @@
1333114217 // touched = true; // main DL
1333214218 if (isRenderer)
1333314219 {
13334
- SetMouseMode(modifiers);
14220
+ SetMouseMode(modifiers, modifiersex);
1333514221 }
1333614222
1333714223 selectX = anchorX = x;
....@@ -13344,7 +14230,7 @@
1334414230 clicked = true;
1334514231 hold = false;
1334614232
13347
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14233
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1334814234 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1334914235 {
1335014236 // System.out.println("RESTART II " + modifiers);
....@@ -13375,7 +14261,7 @@
1337514261 info.camera = renderCamera;
1337614262 info.x = x;
1337714263 info.y = y;
13378
- info.modifiers = modifiers;
14264
+ info.modifiers = modifiersex;
1337914265 editObj = object.doEditClick(info, 0);
1338014266 if (!editObj)
1338114267 {
....@@ -13392,11 +14278,14 @@
1339214278
1339314279 public void mouseDragged(MouseEvent e)
1339414280 {
14281
+ Globals.MOUSEDRAGGED = true;
14282
+
14283
+ //System.out.println("mouseDragged: " + e);
1339514284 if (isRenderer)
1339614285 movingcamera = true;
14286
+
1339714287 //if (drawing)
1339814288 //return;
13399
- //System.out.println("mouseDragged: " + e);
1340014289 if ((e.getModifiersEx() & CTRL) != 0
1340114290 || (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen())
1340214291 {
....@@ -13404,7 +14293,7 @@
1340414293 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1340514294 }
1340614295 else
13407
- drag(e.getX(), e.getY(), e.getModifiersEx());
14296
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1340814297
1340914298 //try { Thread.sleep(1); } catch (Exception ex) {}
1341014299 }
....@@ -13577,6 +14466,7 @@
1357714466
1357814467 public void run()
1357914468 {
14469
+ new Exception().printStackTrace();
1358014470 System.exit(0);
1358114471 for (;;)
1358214472 {
....@@ -13640,7 +14530,7 @@
1364014530 {
1364114531 Globals.lighttouched = true;
1364214532 }
13643
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14533
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1364414534 }
1364514535 //else
1364614536 }
....@@ -13654,12 +14544,12 @@
1365414544 void GoDown(int mod)
1365514545 {
1365614546 MODIFIERS |= COMMAND;
13657
- /*
14547
+ /**/
1365814548 if((mod&SHIFT) == SHIFT)
1365914549 manipCamera.RotatePosition(0, -speed);
1366014550 else
13661
- manipCamera.BackForth(0, -speed*delta, getWidth());
13662
- */
14551
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14552
+ /**/
1366314553 if ((mod & SHIFT) == SHIFT)
1366414554 {
1366514555 mouseMode = mouseMode; // VR??
....@@ -13675,12 +14565,12 @@
1367514565 void GoUp(int mod)
1367614566 {
1367714567 MODIFIERS |= COMMAND;
13678
- /*
14568
+ /**/
1367914569 if((mod&SHIFT) == SHIFT)
1368014570 manipCamera.RotatePosition(0, speed);
1368114571 else
13682
- manipCamera.BackForth(0, speed*delta, getWidth());
13683
- */
14572
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14573
+ /**/
1368414574 if ((mod & SHIFT) == SHIFT)
1368514575 {
1368614576 mouseMode = mouseMode;
....@@ -13696,12 +14586,12 @@
1369614586 void GoLeft(int mod)
1369714587 {
1369814588 MODIFIERS |= COMMAND;
13699
- /*
14589
+ /**/
1370014590 if((mod&SHIFT) == SHIFT)
13701
- manipCamera.RotatePosition(speed, 0);
13702
- else
1370314591 manipCamera.Translate(speed*delta, 0, getWidth());
13704
- */
14592
+ else
14593
+ manipCamera.RotatePosition(speed, 0);
14594
+ /**/
1370514595 if ((mod & SHIFT) == SHIFT)
1370614596 {
1370714597 mouseMode = mouseMode;
....@@ -13717,12 +14607,12 @@
1371714607 void GoRight(int mod)
1371814608 {
1371914609 MODIFIERS |= COMMAND;
13720
- /*
14610
+ /**/
1372114611 if((mod&SHIFT) == SHIFT)
13722
- manipCamera.RotatePosition(-speed, 0);
13723
- else
1372414612 manipCamera.Translate(-speed*delta, 0, getWidth());
13725
- */
14613
+ else
14614
+ manipCamera.RotatePosition(-speed, 0);
14615
+ /**/
1372614616 if ((mod & SHIFT) == SHIFT)
1372714617 {
1372814618 mouseMode = mouseMode;
....@@ -13740,7 +14630,7 @@
1374014630 int X, Y;
1374114631 boolean SX, SY;
1374214632
13743
- void drag(int x, int y, int modifiers)
14633
+ void drag(int x, int y, int modifiers, int modifiersex)
1374414634 {
1374514635 if (IsFrozen())
1374614636 {
....@@ -13749,17 +14639,17 @@
1374914639
1375014640 drag = true; // NEW
1375114641
13752
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14642
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1375314643
1375414644 X = x;
1375514645 Y = y;
1375614646 // floating state for animation
13757
- MODIFIERS = modifiers;
13758
- modifiers &= ~1024;
14647
+ MODIFIERS = modifiersex;
14648
+ modifiersex &= ~1024;
1375914649 if (false) // modifiers != 0)
1376014650 {
1376114651 //new Exception().printStackTrace();
13762
- System.out.println("mouseDragged: " + modifiers);
14652
+ System.out.println("mouseDragged: " + modifiersex);
1376314653 System.out.println("SHIFT = " + SHIFT);
1376414654 System.out.println("CONTROL = " + COMMAND);
1376514655 System.out.println("META = " + META);
....@@ -13779,7 +14669,8 @@
1377914669 info.camera = renderCamera;
1378014670 info.x = x;
1378114671 info.y = y;
13782
- object.editWindow.copy.doEditDrag(info);
14672
+ object.GetWindow().copy
14673
+ .doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1378314674 } else
1378414675 {
1378514676 if (x < startX)
....@@ -13931,7 +14822,6 @@
1393114822 public void mouseMoved(MouseEvent e)
1393214823 {
1393314824 //System.out.println("mouseMoved: " + e);
13934
-
1393514825 if (isRenderer)
1393614826 return;
1393714827
....@@ -13944,7 +14834,9 @@
1394414834 ci.camera = renderCamera;
1394514835 if (!isRenderer)
1394614836 {
13947
- if (object.editWindow.copy.doEditClick(ci, 0))
14837
+ //ObjEditor editWindow = object.editWindow;
14838
+ //Object3D copy = editWindow.copy;
14839
+ if (object.doEditClick(ci, 0))
1394814840 {
1394914841 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1395014842 } else
....@@ -13956,7 +14848,11 @@
1395614848
1395714849 public void mouseReleased(MouseEvent e)
1395814850 {
14851
+ Globals.MOUSEDRAGGED = false;
14852
+
1395914853 movingcamera = false;
14854
+ X = 0; // getBounds().width/2;
14855
+ Y = 0; // getBounds().height/2;
1396014856 //System.out.println("mouseReleased: " + e);
1396114857 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1396214858 }
....@@ -13979,9 +14875,9 @@
1397914875 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1398014876 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1398114877
13982
- if (control || command || IsFrozen())
14878
+// No delay if (control || command || IsFrozen())
1398314879 timeout = true;
13984
- else
14880
+// ?? May 2019 else
1398514881 // timer.setDelay((modifiers & 128) != 0?0:350);
1398614882 mouseDown = false;
1398714883 if (!control && !command) // june 2013
....@@ -14091,7 +14987,7 @@
1409114987 System.out.println("keyReleased: " + e);
1409214988 }
1409314989
14094
- void SetMouseMode(int modifiers)
14990
+ void SetMouseMode(int modifiers, int modifiersex)
1409514991 {
1409614992 //System.out.println("SetMouseMode = " + modifiers);
1409714993 //modifiers &= ~1024;
....@@ -14103,25 +14999,25 @@
1410314999 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1410415000 // return;
1410515001 //System.out.println("SetMode = " + modifiers);
14106
- if ((modifiers & WHEEL) == WHEEL)
15002
+ if ((modifiersex & WHEEL) == WHEEL)
1410715003 {
1410815004 mouseMode |= ZOOM;
1410915005 }
1411015006
1411115007 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
14112
- if (capsLocked || (modifiers & META) == META)
15008
+ if (capsLocked) // || (modifiers & META) == META)
1411315009 {
1411415010 mouseMode |= VR; // BACKFORTH;
1411515011 }
14116
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
15012
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1411715013 {
1411815014 mouseMode |= SELECT;
1411915015 }
14120
- if ((modifiers & COMMAND) == COMMAND)
15016
+ if ((modifiersex & COMMAND) == COMMAND)
1412115017 {
1412215018 mouseMode |= SELECT;
1412315019 }
14124
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15020
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
1412515021 {
1412615022 mouseMode &= ~VR;
1412715023 mouseMode |= TRANSLATE;
....@@ -14150,10 +15046,10 @@
1415015046
1415115047 if (isRenderer) //
1415215048 {
14153
- SetMouseMode(modifiers);
15049
+ SetMouseMode(0, modifiers);
1415415050 }
1415515051
14156
- theRenderer.keyPressed(key);
15052
+ Globals.theRenderer.keyPressed(key);
1415715053 }
1415815054
1415915055 int kompactbit = 4; // power bit
....@@ -14165,7 +15061,7 @@
1416515061 float SATPOW = 1; // 2; // 0.5f;
1416615062 float BRIPOW = 1; // 0.5f; // 0.5f;
1416715063
14168
- void keyPressed(int key)
15064
+ public void keyPressed(int key)
1416915065 {
1417015066 if (key >= '0' && key <= '5')
1417115067 clampbit = (key-'0');
....@@ -14212,7 +15108,8 @@
1421215108 // break;
1421315109 case 'T':
1421415110 CACHETEXTURE ^= true;
14215
- textures.clear();
15111
+ texturepigment.clear();
15112
+ texturebump.clear();
1421615113 // repaint();
1421715114 break;
1421815115 case 'Y':
....@@ -14297,7 +15194,9 @@
1429715194 case 'E' : COMPACT ^= true;
1429815195 repaint();
1429915196 break;
14300
- case 'W' : DEBUGHSB ^= true;
15197
+ case 'W' : // Wide Window (fullscreen)
15198
+ //DEBUGHSB ^= true;
15199
+ ObjEditor.theFrame.ToggleFullScreen();
1430115200 repaint();
1430215201 break;
1430315202 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14322,8 +15221,8 @@
1432215221 RevertCamera();
1432315222 repaint();
1432415223 break;
14325
- case 'L':
1432615224 case 'l':
15225
+ //case 'L':
1432715226 if (lightMode)
1432815227 {
1432915228 lightMode = false;
....@@ -14466,9 +15365,9 @@
1446615365 case '_':
1446715366 kompactbit = 5;
1446815367 break;
14469
- case '+':
14470
- kompactbit = 6;
14471
- break;
15368
+// case '+':
15369
+// kompactbit = 6;
15370
+// break;
1447215371 case ' ':
1447315372 lightMode ^= true;
1447415373 Globals.lighttouched = true;
....@@ -14480,13 +15379,14 @@
1448015379 case ESC:
1448115380 RENDERPROGRAM += 1;
1448215381 RENDERPROGRAM %= 3;
15382
+
1448315383 repaint();
1448415384 break;
1448515385 case 'Z':
1448615386 //RESIZETEXTURE ^= true;
1448715387 //break;
1448815388 case 'z':
14489
- RENDERSHADOW ^= true;
15389
+ Globals.RENDERSHADOW ^= true;
1449015390 Globals.lighttouched = true;
1449115391 repaint();
1449215392 break;
....@@ -14519,8 +15419,9 @@
1451915419 case DELETE:
1452015420 ClearSelection();
1452115421 break;
14522
- /*
1452315422 case '+':
15423
+
15424
+ /*
1452415425 //fontsize += 1;
1452515426 bbzoom *= 2;
1452615427 repaint();
....@@ -14537,17 +15438,17 @@
1453715438 case '=':
1453815439 IncDepth();
1453915440 //fontsize += 1;
14540
- object.editWindow.refreshContents(true);
15441
+ object.GetWindow().refreshContents(true);
1454115442 maskbit = 6;
1454215443 break;
1454315444 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1454415445 DecDepth();
1454515446 maskbit = 5;
1454615447 //if(fontsize > 1) fontsize -= 1;
14547
- if (object.editWindow == null)
14548
- new Exception().printStackTrace();
14549
- else
14550
- object.editWindow.refreshContents(true);
15448
+// if (object.editWindow == null)
15449
+// new Exception().printStackTrace();
15450
+// else
15451
+ object.GetWindow().refreshContents(true);
1455115452 break;
1455215453 case '{':
1455315454 manipCamera.shaper_fovy /= 1.1;
....@@ -14602,6 +15503,7 @@
1460215503 }
1460315504 //System.out.println("shaper_fovy = " + manipCamera.shaper_fovy);
1460415505 }
15506
+
1460515507 static double OCCLUSIONBOOST = 1; // 0.5;
1460615508
1460715509 void keyReleased(int key, int modifiers)
....@@ -14609,11 +15511,11 @@
1460915511 //mode = ROTATE;
1461015512 if ((MODIFIERS & COMMAND) == 0) // VR??
1461115513 {
14612
- SetMouseMode(modifiers);
15514
+ SetMouseMode(0, modifiers);
1461315515 }
1461415516 }
1461515517
14616
- protected void processKeyEvent(KeyEvent e)
15518
+ public void processKeyEvent(KeyEvent e)
1461715519 {
1461815520 switch (e.getID())
1461915521 {
....@@ -14743,8 +15645,9 @@
1474315645
1474415646 protected void processMouseMotionEvent(MouseEvent e)
1474515647 {
14746
- //System.out.println("processMouseMotionEvent: " + mouseMode);
14747
- if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15648
+ //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
15649
+ //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15650
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1474815651 {
1474915652 mouseMoved(e);
1475015653 } else
....@@ -14769,11 +15672,12 @@
1476915672 }
1477015673 */
1477115674
14772
- object.editWindow.EditSelection();
15675
+ object.GetWindow().EditSelection(false);
1477315676 }
1477415677
1477515678 void SelectParent()
1477615679 {
15680
+ new Exception().printStackTrace();
1477715681 System.exit(0);
1477815682 Composite group = (Composite) object;
1477915683 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -14785,10 +15689,10 @@
1478515689 {
1478615690 //selectees.remove(i);
1478715691 System.out.println("select parent of " + elem);
14788
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15692
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1478915693 } else
1479015694 {
14791
- group.editWindow.Select(elem.GetTreePath(), first, true);
15695
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1479215696 }
1479315697
1479415698 first = false;
....@@ -14797,6 +15701,7 @@
1479715701
1479815702 void SelectChildren()
1479915703 {
15704
+ new Exception().printStackTrace();
1480015705 System.exit(0);
1480115706 /*
1480215707 Composite group = (Composite) object;
....@@ -14829,12 +15734,12 @@
1482915734 for (int j = 0; j < group.children.size(); j++)
1483015735 {
1483115736 elem = (Object3D) group.children.elementAt(j);
14832
- object.editWindow.Select(elem.GetTreePath(), first, true);
15737
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1483315738 first = false;
1483415739 }
1483515740 } else
1483615741 {
14837
- object.editWindow.Select(elem.GetTreePath(), first, true);
15742
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1483815743 }
1483915744
1484015745 first = false;
....@@ -14845,21 +15750,21 @@
1484515750 {
1484615751 //Composite group = (Composite) object;
1484715752 Object3D group = object;
14848
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15753
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1484915754 }
1485015755
1485115756 void ResetTransform(int mask)
1485215757 {
1485315758 //Composite group = (Composite) object;
1485415759 Object3D group = object;
14855
- group.editWindow.ResetTransform(mask);
15760
+ group.GetWindow().ResetTransform(mask);
1485615761 }
1485715762
1485815763 void FlipTransform()
1485915764 {
1486015765 //Composite group = (Composite) object;
1486115766 Object3D group = object;
14862
- group.editWindow.FlipTransform();
15767
+ group.GetWindow().FlipTransform();
1486315768 // group.editWindow.ReduceMesh(true);
1486415769 }
1486515770
....@@ -14867,7 +15772,7 @@
1486715772 {
1486815773 //Composite group = (Composite) object;
1486915774 Object3D group = object;
14870
- group.editWindow.PrintMemory();
15775
+ group.GetWindow().PrintMemory();
1487115776 // group.editWindow.ReduceMesh(true);
1487215777 }
1487315778
....@@ -14875,7 +15780,7 @@
1487515780 {
1487615781 //Composite group = (Composite) object;
1487715782 Object3D group = object;
14878
- group.editWindow.ResetCentroid();
15783
+ group.GetWindow().ResetCentroid();
1487915784 }
1488015785
1488115786 void IncDepth()
....@@ -14961,7 +15866,9 @@
1496115866 info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1496215867 //Image img = CreateImage(width, height);
1496315868 //System.out.println("width = " + width + "; height = " + height + "\n");
15869
+
1496415870 Graphics gr = g; // img.getGraphics();
15871
+
1496515872 if (!hasMarquee)
1496615873 {
1496715874 if (Xmin < Xmax) // !locked)
....@@ -15049,6 +15956,7 @@
1504915956 info.bounds.y += (height - desired) / 2;
1505015957 }
1505115958 }
15959
+
1505215960 info.g = gr;
1505315961 info.camera = renderCamera;
1505415962 /*
....@@ -15058,15 +15966,55 @@
1505815966 */
1505915967 if (!isRenderer)
1506015968 {
15061
- object.drawEditHandles(info, 0);
15969
+ Grafreed.Assert(object != null);
15970
+ Grafreed.Assert(object.selection != null);
15971
+ if (object.selection.Size() > 0)
15972
+ {
15973
+ int hitSomething = object.selection.get(0).hitSomething;
15974
+
15975
+ info.DX = 0;
15976
+ info.DY = 0;
15977
+ info.W = 1;
15978
+ if (hitSomething == Object3D.hitCenter)
15979
+ {
15980
+ info.DX = X;
15981
+ if (X != 0)
15982
+ info.DX -= info.bounds.width/2;
15983
+
15984
+ info.DY = Y;
15985
+ if (Y != 0)
15986
+ info.DY -= info.bounds.height/2;
15987
+ }
15988
+
15989
+ object.drawEditHandles(info, 0);
15990
+
15991
+ if (drag && (X != 0 || Y != 0))
15992
+ {
15993
+ switch (hitSomething)
15994
+ {
15995
+ case Object3D.hitCenter: gr.setColor(Color.pink);
15996
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15997
+ break;
15998
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
15999
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16000
+ break;
16001
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16002
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16003
+ break;
16004
+ }
16005
+
16006
+ }
16007
+ }
1506216008 }
1506316009 }
16010
+
1506416011 if (isRenderer)
1506516012 {
1506616013 //gr.setColor(Color.black);
1506716014 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1506816015 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1506916016 }
16017
+
1507016018 if (hasMarquee)
1507116019 {
1507216020 gr.setXORMode(Color.white);
....@@ -15179,6 +16127,7 @@
1517916127 public boolean mouseDown(Event evt, int x, int y)
1518016128 {
1518116129 System.out.println("mouseDown: " + evt);
16130
+ System.exit(0);
1518216131 /*
1518316132 locked = true;
1518416133 drag = false;
....@@ -15222,7 +16171,7 @@
1522216171 {
1522316172 keyPressed(0, modifiers);
1522416173 }
15225
- clickStart(x, y, modifiers);
16174
+ // clickStart(x, y, modifiers);
1522616175 return true;
1522716176 }
1522816177
....@@ -15340,7 +16289,7 @@
1534016289 {
1534116290 keyReleased(0, 0);
1534216291 }
15343
- drag(x, y, modifiers);
16292
+ drag(x, y, 0, modifiers);
1534416293 return true;
1534516294 }
1534616295
....@@ -15472,7 +16421,7 @@
1547216421 Object3D object;
1547316422 static Object3D trackedobject;
1547416423 Camera renderCamera; // Light or Eye (or Occlusion)
15475
- /*static*/ Camera manipCamera; // Light or Eye
16424
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1547616425 /*static*/ Camera eyeCamera;
1547716426 /*static*/ Camera lightCamera;
1547816427 int cameracount;
....@@ -15757,16 +16706,16 @@
1575716706 cStatic.objectstack[materialdepth++] = checker;
1575816707 //System.out.println("material " + material);
1575916708 //Applet3D.tracein(this, selected);
15760
- vector2buffer = checker.projectedVertices;
16709
+ //vector2buffer = checker.projectedVertices;
1576116710
1576216711 //checker.GetMaterial().Draw(this, false); // true);
15763
- DrawMaterial(checker.GetMaterial(), false); // true);
16712
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1576416713
1576516714 materialdepth -= 1;
1576616715 if (materialdepth > 0)
1576716716 {
15768
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
15769
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
16717
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16718
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1577016719 }
1577116720 //checker.GetMaterial().opacity = 1f;
1577216721 ////checker.GetMaterial().ambient = 1f;
....@@ -15852,6 +16801,14 @@
1585216801 }
1585316802 }
1585416803
16804
+ private Object3D GetFolder()
16805
+ {
16806
+ Object3D folder = object.GetWindow().copy;
16807
+ if (object.GetWindow().copy.selection.Size() > 0)
16808
+ folder = object.GetWindow().copy.selection.elementAt(0);
16809
+ return folder;
16810
+ }
16811
+
1585516812 class SelectBuffer implements GLEventListener
1585616813 {
1585716814
....@@ -15910,6 +16867,7 @@
1591016867 {
1591116868 if (!selection)
1591216869 {
16870
+ new Exception().printStackTrace();
1591316871 System.exit(0);
1591416872 return;
1591516873 }
....@@ -15930,6 +16888,17 @@
1593016888
1593116889 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1593216890
16891
+ if (PAINTMODE)
16892
+ {
16893
+ if (object.GetWindow().copy.selection.Size() > 0)
16894
+ {
16895
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16896
+
16897
+ // Make what you paint not selectable.
16898
+ paintobj.ResetSelectable();
16899
+ }
16900
+ }
16901
+
1593316902 //int tmp = selection_view;
1593416903 //selection_view = -1;
1593516904 int temp = DrawMode();
....@@ -15941,6 +16910,17 @@
1594116910 // temp = DEFAULT; // patch for selection debug
1594216911 Globals.drawMode = temp; // WARNING
1594316912
16913
+ if (PAINTMODE)
16914
+ {
16915
+ if (object.GetWindow().copy.selection.Size() > 0)
16916
+ {
16917
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16918
+
16919
+ // Revert.
16920
+ paintobj.RestoreSelectable();
16921
+ }
16922
+ }
16923
+
1594416924 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1594516925
1594616926 // trying different ways of getting the depth info over
....@@ -15988,6 +16968,8 @@
1598816968 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1598916969 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1599016970 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
16971
+
16972
+ CreateSelectedPoint();
1599116973
1599216974 // Will fit the mesh !!!
1599316975 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16037,34 +17019,36 @@
1603717019 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]));
1603817020 }
1603917021
16040
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
17022
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1604117023 }
1604217024 }
1604317025
1604417026 if (!movingcamera && !PAINTMODE)
16045
- object.editWindow.ScreenFitPoint(); // fev 2014
17027
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1604617028
16047
- if (PAINTMODE && GrafreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17029
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1604817030 {
16049
- Object3D paintobj = GrafreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17031
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1605017032
16051
- Object3D group = new Object3D("inst" + paintcount++);
17033
+ if (object.GetWindow().copy.selection.Size() > 0)
17034
+ {
17035
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1605217036
16053
- group.CreateMaterial(); // use a void leaf to select instances
16054
-
16055
- group.add(paintobj); // link
16056
-
16057
- object.editWindow.SnapObject(group);
16058
-
16059
- Object3D folder = object.editWindow.copy;
16060
-
16061
- if (object.editWindow.copy.selection.Size() > 0)
16062
- folder = object.editWindow.copy.selection.elementAt(0);
16063
-
16064
- folder.add(group);
16065
-
16066
- object.editWindow.ResetModel();
16067
- object.editWindow.refreshContents();
17037
+ Object3D inst = new Object3D("inst" + paintcount++);
17038
+
17039
+ inst.CreateMaterial(); // use a void leaf to select instances
17040
+
17041
+ inst.add(paintobj); // link
17042
+
17043
+ object.GetWindow().SnapObject(inst);
17044
+
17045
+ Object3D folder = paintFolder; // GetFolder();
17046
+
17047
+ folder.add(inst);
17048
+
17049
+ object.GetWindow().ResetModel();
17050
+ object.GetWindow().refreshContents();
17051
+ }
1606817052 }
1606917053 else
1607017054 paintcount = 0;
....@@ -16103,6 +17087,11 @@
1610317087 //System.out.println("objects[color] = " + objects[color]);
1610417088 //objects[color].Select();
1610517089 indexcount = 0;
17090
+ ObjEditor window = object.GetWindow();
17091
+ if (window != null && deselect)
17092
+ {
17093
+ window.Select(null, deselect, true);
17094
+ }
1610617095 object.Select(color, deselect);
1610717096 }
1610817097
....@@ -16202,7 +17191,7 @@
1620217191 gl.glDisable(gl.GL_CULL_FACE);
1620317192 }
1620417193
16205
- if (!RENDERSHADOW)
17194
+ if (!Globals.RENDERSHADOW)
1620617195 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1620717196
1620817197 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -16212,7 +17201,7 @@
1621217201 //gl.glColorMask(false, false, false, false);
1621317202
1621417203 //render_scene_from_light_view(gl, drawable, 0, 0);
16215
- if (RENDERSHADOW && Globals.lighttouched && !movingcamera) // && !parent.IsFreezed())
17204
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1621617205 {
1621717206 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1621817207
....@@ -16628,23 +17617,15 @@
1662817617 int AAbuffersize = 0;
1662917618
1663017619 //double[] selectedpoint = new double[3];
16631
- static Superellipsoid selectedpoint = new Superellipsoid();
17620
+ static Superellipsoid selectedpoint;
1663217621 static Sphere previousselectedpoint = null;
16633
- static Sphere debugpointG = new Sphere();
16634
- static Sphere debugpointP = new Sphere();
16635
- static Sphere debugpointC = new Sphere();
16636
- static Sphere debugpointR = new Sphere();
17622
+ static Sphere debugpointG;
17623
+ static Sphere debugpointP;
17624
+ static Sphere debugpointC;
17625
+ static Sphere debugpointR;
1663717626
1663817627 static Sphere debugpoints[] = new Sphere[8];
1663917628
16640
- static
16641
- {
16642
- for (int i=0; i<8; i++)
16643
- {
16644
- debugpoints[i] = new Sphere();
16645
- }
16646
- }
16647
-
1664817629 static void InitPoints(float radius)
1664917630 {
1665017631 for (int i=0; i<8; i++)
....@@ -16696,10 +17677,11 @@
1669617677 static IntBuffer textbuffer = null; // IntBuffer.allocate(TEXT_WIDTH*8*8 * TEXT_HEIGHT);
1669717678 // Depth buffer format
1669817679 //private int depth_format;
16699
- static public void NextIndex(Object3D o, GL gl)
17680
+
17681
+ public void NextIndex()
1670017682 {
1670117683 indexcount+=16;
16702
- gl.glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
17684
+ GetGL().glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
1670317685 //objects[indexcount] = o;
1670417686 //System.out.println("indexcount = " + indexcount);
1670517687 }