Normand Briere
2019-08-12 b1d79b74514041a059b454a9f6fc3970773c0cb8
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,24 @@
150186 defaultcaps.setAccumAlphaBits(16);
151187 }
152188
153
- static CameraPane theRenderer;
189
+ private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
190
+
191
+ public void LoadSkybox(String name, String ext, boolean mipmap) throws GLException
192
+ {
193
+ try
194
+ {
195
+ cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
196
+ } catch (IOException e)
197
+ {
198
+ System.out.println("NAME = " + name);
199
+ e.printStackTrace(); // throw new RuntimeException(e);
200
+ }
201
+ }
154202
155203 void SetAsGLRenderer(boolean b)
156204 {
157205 isRenderer = b;
158
- theRenderer = this;
206
+ Globals.theRenderer = this;
159207 }
160208
161209 CameraPane(Object3D o, Camera cam, boolean withcontext)
....@@ -170,7 +218,8 @@
170218
171219 SetCamera(cam);
172220
173
- SetLight(new Camera(new cVector(10, 10, -20)));
221
+ // Warning: not used.
222
+ SetLight(new Camera(new cVector(15, 10, -20)));
174223
175224 object = o;
176225
....@@ -193,9 +242,43 @@
193242
194243 /// INTERFACE
195244
245
+ public javax.media.opengl.GL GetGL0()
246
+ {
247
+ return null;
248
+ }
249
+
250
+ public int GenList()
251
+ {
252
+ javax.media.opengl.GL gl = GetGL();
253
+ return gl.glGenLists(1);
254
+ }
255
+
256
+ public void NewList(int id)
257
+ {
258
+ javax.media.opengl.GL gl = GetGL();
259
+ gl.glNewList(id, gl.GL_COMPILE); //_AND_EXECUTE);
260
+ }
261
+
262
+ public void CallList(int id)
263
+ {
264
+ javax.media.opengl.GL gl = GetGL();
265
+ gl.glCallList(id);
266
+ }
267
+
268
+ public void EndList()
269
+ {
270
+ javax.media.opengl.GL gl = GetGL();
271
+ gl.glEndList();
272
+ }
273
+
196274 public boolean IsBoxMode()
197275 {
198276 return BOXMODE;
277
+ }
278
+
279
+ public boolean IsZoomBoxMode()
280
+ {
281
+ return ZOOMBOXMODE;
199282 }
200283
201284 public void ClearDepth()
....@@ -293,7 +376,7 @@
293376 cStatic.objectstack[materialdepth++] = obj;
294377 //System.out.println("material " + material);
295378 //Applet3D.tracein(this, selected);
296
- display.vector2buffer = obj.projectedVertices;
379
+ //display.vector2buffer = obj.projectedVertices;
297380 if (obj instanceof Camera)
298381 {
299382 display.options1[0] = material.shift;
....@@ -302,14 +385,28 @@
302385 display.options1[2] = material.shadowbias;
303386 display.options1[3] = material.aniso;
304387 display.options1[4] = material.anisoV;
388
+// System.out.println("display.options1[0] " + display.options1[0]);
389
+// System.out.println("display.options1[1] " + display.options1[1]);
390
+// System.out.println("display.options1[2] " + display.options1[2]);
391
+// System.out.println("display.options1[3] " + display.options1[3]);
392
+// System.out.println("display.options1[4] " + display.options1[4]);
305393 display.options2[0] = material.opacity;
306394 display.options2[1] = material.diffuse;
307395 display.options2[2] = material.factor;
396
+// System.out.println("display.options2[0] " + display.options2[0]);
397
+// System.out.println("display.options2[1] " + display.options2[1]);
398
+// System.out.println("display.options2[2] " + display.options2[2]);
308399
309400 cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
401
+// System.out.println("display.options3[0] " + display.options3[0]);
402
+// System.out.println("display.options3[1] " + display.options3[1]);
403
+// System.out.println("display.options3[2] " + display.options3[2]);
310404 display.options4[0] = material.cameralight/0.2f;
311405 display.options4[1] = material.subsurface;
312406 display.options4[2] = material.sheen;
407
+// System.out.println("display.options4[0] " + display.options4[0]);
408
+// System.out.println("display.options4[1] " + display.options4[1]);
409
+// System.out.println("display.options4[2] " + display.options4[2]);
313410
314411 // if (display.CURRENTANTIALIAS > 0)
315412 // display.options3[3] /= 4;
....@@ -325,7 +422,7 @@
325422 /**/
326423 } else
327424 {
328
- DrawMaterial(material, selected);
425
+ DrawMaterial(material, selected, obj.projectedVertices);
329426 }
330427 } else
331428 {
....@@ -349,8 +446,8 @@
349446 cStatic.objectstack[materialdepth++] = obj;
350447 //System.out.println("material " + material);
351448 //Applet3D.tracein("selected ", selected);
352
- display.vector2buffer = obj.projectedVertices;
353
- display.DrawMaterial(material, selected);
449
+ //display.vector2buffer = obj.projectedVertices;
450
+ display.DrawMaterial(material, selected, obj.projectedVertices);
354451 }
355452 }
356453
....@@ -367,8 +464,8 @@
367464 materialdepth -= 1;
368465 if (materialdepth > 0)
369466 {
370
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
371
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
467
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
468
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
372469 }
373470 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
374471 } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
....@@ -388,8 +485,8 @@
388485 materialdepth -= 1;
389486 if (materialdepth > 0)
390487 {
391
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
392
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
488
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
489
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
393490 }
394491 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
395492 //else
....@@ -430,10 +527,12 @@
430527 if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
431528 {
432529 //gl.glBegin(gl.GL_TRIANGLES);
433
- boolean hasnorm = pv.norm != null; // && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0);
530
+ boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0)
531
+ // TEST LIVE NORMALS && !obj.dontselect
532
+ ;
434533 if (!hasnorm)
435534 {
436
- // System.out.println("FUCK!!");
535
+ // System.out.println("Mesh normal");
437536 LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
438537 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
439538 LA.vecCross(obj.v0, obj.v1, obj.v2);
....@@ -816,7 +915,7 @@
816915
817916 if ((i % 100) == 0 && i != 0)
818917 {
819
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
918
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
820919 //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
821920 System.out.println((int) (100.0 * i / (br.positions.length / 3)) + "% (" + i + " of " + (br.positions.length / 3) + ")");
822921 }
....@@ -848,7 +947,7 @@
848947
849948 if ((i % 100) == 0 && i != 0)
850949 {
851
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
950
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
852951 //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
853952 System.out.println((int) (100.0 * i / br.VertexCount()) + "% (" + i + " of " + br.VertexCount() + ")");
854953 }
....@@ -1061,8 +1160,345 @@
10611160 gl.glMatrixMode(gl.GL_MODELVIEW);
10621161 }
10631162
1163
+ public void DrawBox(cVector min, cVector max)
1164
+ {
1165
+ javax.media.opengl.GL gl = GetGL();
1166
+ gl.glBegin(gl.GL_LINES);
1167
+
1168
+ gl.glVertex3d(min.x, min.y, min.z);
1169
+ gl.glVertex3d(min.x, min.y, max.z);
1170
+ gl.glVertex3d(min.x, min.y, min.z);
1171
+ gl.glVertex3d(min.x, max.y, min.z);
1172
+ gl.glVertex3d(min.x, min.y, min.z);
1173
+ gl.glVertex3d(max.x, min.y, min.z);
1174
+
1175
+ gl.glVertex3d(max.x, max.y, max.z);
1176
+ gl.glVertex3d(min.x, max.y, max.z);
1177
+ gl.glVertex3d(max.x, max.y, max.z);
1178
+ gl.glVertex3d(max.x, min.y, max.z);
1179
+ gl.glVertex3d(max.x, max.y, max.z);
1180
+ gl.glVertex3d(max.x, max.y, min.z);
1181
+
1182
+ gl.glEnd();
1183
+ }
1184
+
1185
+ public void DrawGeometry(BoundaryRep bRep, boolean flipV, boolean selectmode)
1186
+ {
1187
+ int[] strips = bRep.getRawIndices();
1188
+
1189
+ javax.media.opengl.GL gl = GetGL();
1190
+
1191
+ // TRIANGLE STRIP ARRAY
1192
+ if (bRep.trimmed)
1193
+ {
1194
+ float[] v = bRep.getRawVertices();
1195
+ float[] n = bRep.getRawNormals();
1196
+ float[] c = bRep.getRawColors();
1197
+ float[] uv = bRep.getRawUVMap();
1198
+
1199
+ int count2 = 0;
1200
+ int count3 = 0;
1201
+
1202
+ if (n.length > 0)
1203
+ {
1204
+ for (int i = 0; i < strips.length; i++)
1205
+ {
1206
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1207
+
1208
+ /*
1209
+ boolean locked = false;
1210
+ float eps = 0.1f;
1211
+ boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
1212
+
1213
+ int dot = 0;
1214
+
1215
+ if ((dot&1) == 0)
1216
+ dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
1217
+
1218
+ if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
1219
+ gl.glTexCoord2f((float) qv.s, (float) qv.t);
1220
+ else
1221
+ {
1222
+ locked = true;
1223
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1224
+ }
1225
+ //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
1226
+ gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
1227
+ if (hasnorm)
1228
+ {
1229
+ //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
1230
+ gl.glNormal3f((float) rv.norm.x, (float) rv.norm.y, (float) rv.norm.z);
1231
+ }
1232
+
1233
+ if ((dot&4) == 0)
1234
+ dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
1235
+
1236
+ if (wrap || !locked && (dot&8) != 0)
1237
+ gl.glTexCoord2f((float) rv.s, (float) rv.t);
1238
+ else
1239
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1240
+
1241
+ f.dot = dot;
1242
+ */
1243
+
1244
+ if (!selectmode)
1245
+ {
1246
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1247
+ {
1248
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1249
+ } else
1250
+ {
1251
+ gl.glNormal3f(0, 0, 1);
1252
+ }
1253
+
1254
+ if (c != null)
1255
+ //System.out.println("glcolor = " + c[count3] + ", " + c[count3+1] + ", " + c[count3+2]);
1256
+ {
1257
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1258
+ }
1259
+ }
1260
+
1261
+ if (flipV)
1262
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1263
+ else
1264
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1265
+
1266
+ //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1267
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1268
+
1269
+ count2 += 2;
1270
+ count3 += 3;
1271
+ if (!selectmode)
1272
+ {
1273
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1274
+ {
1275
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1276
+ } else
1277
+ {
1278
+ gl.glNormal3f(0, 0, 1);
1279
+ }
1280
+ if (c != null)
1281
+ {
1282
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1283
+ }
1284
+ }
1285
+
1286
+ if (flipV)
1287
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1288
+ else
1289
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1290
+
1291
+ //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1292
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1293
+
1294
+ count2 += 2;
1295
+ count3 += 3;
1296
+ for (int j = 0; j < strips[i] - 2; j++)
1297
+ {
1298
+ //gl.glTexCoord2d(...);
1299
+ if (!selectmode)
1300
+ {
1301
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1302
+ {
1303
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1304
+ } else
1305
+ {
1306
+ gl.glNormal3f(0, 0, 1);
1307
+ }
1308
+ if (c != null)
1309
+ {
1310
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1311
+ }
1312
+ }
1313
+
1314
+ if (flipV)
1315
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1316
+ else
1317
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1318
+
1319
+ //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
1320
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1321
+
1322
+ count2 += 2;
1323
+ count3 += 3;
1324
+ }
1325
+
1326
+ gl.glEnd();
1327
+ }
1328
+ }
1329
+
1330
+ assert count3 == v.length;
1331
+ }
1332
+ else // !trimmed
1333
+ {
1334
+ int count = 0;
1335
+ for (int i = 0; i < strips.length; i++)
1336
+ {
1337
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1338
+
1339
+ Vertex p = bRep.GetVertex(bRep.indices[count++]);
1340
+ Vertex q = bRep.GetVertex(bRep.indices[count++]);
1341
+
1342
+ drawVertex(gl, p, flipV, selectmode);
1343
+ drawVertex(gl, q, flipV, selectmode);
1344
+
1345
+ for (int j = 0; j < strips[i] - 2; j++)
1346
+ {
1347
+ Vertex r = bRep.GetVertex(bRep.indices[count++]);
1348
+
1349
+ // if (j%2 == 0)
1350
+ // drawFace(p, q, r, display, null);
1351
+ // else
1352
+ // drawFace(p, r, q, display, null);
1353
+
1354
+ // p = q;
1355
+ // q = r;
1356
+ drawVertex(gl, r, flipV, selectmode);
1357
+ }
1358
+
1359
+ gl.glEnd();
1360
+ }
1361
+ }
1362
+ }
1363
+
1364
+ static cSpring.Point3D temp = new cSpring.Point3D();
1365
+ static cSpring.Point3D temp2 = new cSpring.Point3D();
1366
+ static cSpring.Point3D temp3 = new cSpring.Point3D();
1367
+
1368
+ public void DrawDynamicMesh(cMesh mesh)
1369
+ {
1370
+ GL gl = GetGL(); // getGL();
1371
+
1372
+ cSpring.PhysicsController3D Phys = mesh.Phys;
1373
+
1374
+ gl.glDisable(gl.GL_LIGHTING);
1375
+
1376
+ gl.glLineWidth(1);
1377
+ gl.glColor3f(1,1,1);
1378
+ gl.glBegin(gl.GL_LINES);
1379
+ double scale = 0;
1380
+ int count = 0;
1381
+ for (int s=0; s<Phys.allSprings.size(); s++)
1382
+ {
1383
+ cSpring.Spring spring = Phys.allSprings.get(s);
1384
+ if(s == 0)
1385
+ {
1386
+ //System.out.println(" spring : " + spring.a.position + "; " + spring.b.position);
1387
+ }
1388
+ if (mesh.showsprings)
1389
+ {
1390
+ temp.set(spring.a.position);
1391
+ temp.add(spring.b.position);
1392
+ temp.mul(0.5);
1393
+ temp2.set(spring.a.position);
1394
+ temp2.sub(spring.b.position);
1395
+ temp2.mul(spring.restLength/2);
1396
+ temp.sub(temp2);
1397
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1398
+ temp.add(temp2);
1399
+ temp.add(temp2);
1400
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1401
+ }
1402
+
1403
+ if (spring.isHandle)
1404
+ continue;
1405
+
1406
+ //if (scale < spring.restLength)
1407
+ scale += spring.restLength;
1408
+ count++;
1409
+ }
1410
+ gl.glEnd();
1411
+
1412
+ if (count == 0)
1413
+ scale = 0.01;
1414
+ else
1415
+ scale /= count * 3;
1416
+
1417
+ //scale = 0.25;
1418
+
1419
+ if (mesh.ShowInfo())
1420
+ {
1421
+ gl.glLineWidth(4);
1422
+ for (int s=0; s<Phys.allNodes.size(); s++)
1423
+ {
1424
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1425
+ if (node.mass == 0)
1426
+ continue;
1427
+
1428
+ int i = node.springs==null?-1:node.springs.size();
1429
+ gl.glColor3f((i>>2)&1,(i>>1)&1,i&1);
1430
+ //temp.set(node.springForce.x, node.springForce.y, node.springForce.z);
1431
+ //temp.normalize();
1432
+ //gl.glColor3d((temp.x+1)/2, (temp.y+1)/2, (temp.z+1)/2);
1433
+ gl.glBegin(gl.GL_LINES);
1434
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1435
+ //gl.glVertex3d(node.position.x + node.normal.x*scale, node.position.y + node.normal.y*scale, node.position.z + node.normal.z*scale);
1436
+ gl.glVertex3d(node.position.x + mesh.bRep.GetVertex(s).norm.x*scale,
1437
+ node.position.y + mesh.bRep.GetVertex(s).norm.y*scale,
1438
+ node.position.z + mesh.bRep.GetVertex(s).norm.z*scale);
1439
+ gl.glEnd();
1440
+ }
1441
+
1442
+ gl.glLineWidth(8);
1443
+ for (int s=0; s<Phys.allNodes.size(); s++)
1444
+ {
1445
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1446
+
1447
+ if (node.springs != null)
1448
+ {
1449
+ for (int i=0; i<node.springs.size(); i+=1)
1450
+ {
1451
+ cSpring.DynamicNode f = node.springs.get(i).GetOther(node);
1452
+
1453
+ int c = i+1;
1454
+ // c = node.springs.get(i).nbcopies;
1455
+
1456
+ gl.glColor3f((c>>2)&1,(c>>1)&1,c&1);
1457
+ gl.glBegin(gl.GL_LINES);
1458
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1459
+ 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);
1460
+ gl.glEnd();
1461
+ }
1462
+ }
1463
+ }
1464
+
1465
+ gl.glLineWidth(1);
1466
+ }
1467
+
1468
+ gl.glEnable(gl.GL_LIGHTING);
1469
+ }
1470
+
10641471 /// INTERFACE
10651472
1473
+ public void StartTriangles()
1474
+ {
1475
+ javax.media.opengl.GL gl = GetGL();
1476
+ gl.glBegin(gl.GL_TRIANGLES);
1477
+ }
1478
+
1479
+ public void EndTriangles()
1480
+ {
1481
+ GetGL().glEnd();
1482
+ }
1483
+
1484
+ void drawVertex(javax.media.opengl.GL gl, Vertex pv, boolean flipV, boolean selectmode)
1485
+ {
1486
+ if (!selectmode)
1487
+ {
1488
+ gl.glNormal3f((float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
1489
+ gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
1490
+
1491
+ if (flipV)
1492
+ gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
1493
+ else
1494
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1495
+ }
1496
+
1497
+ gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
1498
+ }
1499
+
1500
+ float[] colorV = new float[4];
1501
+
10661502 void SetColor(Object3D obj, Vertex p0)
10671503 {
10681504 CameraPane display = this;
....@@ -1130,8 +1566,6 @@
11301566 {
11311567 return;
11321568 }
1133
-
1134
- float[] colorV = new float[3];
11351569
11361570 if (false) // marked)
11371571 {
....@@ -1240,7 +1674,7 @@
12401674 // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
12411675 }
12421676
1243
- void DrawMaterial(cMaterial material, boolean selected)
1677
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
12441678 {
12451679 CameraPane display = this;
12461680 //new Exception().printStackTrace();
....@@ -1256,18 +1690,18 @@
12561690 //col.getColorComponents(ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB), CameraPane.modelParams0);
12571691 if (!material.multiply)
12581692 {
1259
- display.color = color;
1693
+ display.color = material.color;
12601694 display.saturation = material.modulation;
12611695 }
12621696 else
12631697 {
1264
- display.color *= color*2;
1698
+ display.color *= material.color*2;
12651699 display.saturation *= material.modulation*2;
12661700 }
12671701
12681702 cColor.HSBtoRGB(display.color, display.saturation, 1, display.modelParams0);
12691703
1270
- float[] colorV = GrafreeD.colorV;
1704
+ float[] colorV = Grafreed.colorV;
12711705
12721706 /**/
12731707 if (display.DrawMode() == display.DEFAULT) // && display.RENDERPROGRAM == 0)
....@@ -1275,7 +1709,7 @@
12751709 colorV[0] = display.modelParams0[0] * material.diffuse;
12761710 colorV[1] = display.modelParams0[1] * material.diffuse;
12771711 colorV[2] = display.modelParams0[2] * material.diffuse;
1278
- colorV[3] = material.opacity;
1712
+ colorV[3] = 1; // material.opacity;
12791713
12801714 gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
12811715 //System.out.println("Opacity = " + opacity);
....@@ -1383,9 +1817,9 @@
13831817 display.modelParams7[2] = 0;
13841818 display.modelParams7[3] = 0;
13851819
1386
- display.modelParams6[0] = 100; // criss de bug de bump
1820
+ //display.modelParams6[0] = 100; // criss de bug de bump
13871821
1388
- Object3D.cVector2[] extparams = display.vector2buffer;
1822
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
13891823 if (extparams != null && extparams.length > 0 && extparams[0] != null)
13901824 {
13911825 display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
....@@ -1527,7 +1961,7 @@
15271961 void PushMatrix(double[][] matrix)
15281962 {
15291963 // GrafreeD.tracein(matrix);
1530
- PushMatrix(matrix,1);
1964
+ PushMatrix(matrix, 1);
15311965 }
15321966
15331967 void PushMatrix()
....@@ -1624,7 +2058,7 @@
16242058
16252059 static int camerachangeframe;
16262060
1627
- boolean SetCamera(Camera cam)
2061
+ public boolean SetCamera(Camera cam)
16282062 {
16292063 // may 2014 if (cam == cameras[0] || cam == cameras[1])
16302064 // return false;
....@@ -1681,7 +2115,7 @@
16812115 //System.err.println("Oeil on");
16822116 OEIL = true;
16832117 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
1684
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2118
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
16852119 //pingthread.StepToTarget(true);
16862120 }
16872121
....@@ -1752,33 +2186,6 @@
17522186 mainDL ^= true;
17532187 }
17542188
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
-
17822189 void ToggleFullScreen()
17832190 {
17842191 FULLSCREEN ^= true;
....@@ -1789,72 +2196,94 @@
17892196 Globals.CROWD ^= true;
17902197 }
17912198
1792
- void ToggleInertia()
1793
- {
1794
- INERTIA ^= true;
1795
- }
1796
-
17972199 void ToggleLocal()
17982200 {
17992201 LOCALTRANSFORM ^= true;
18002202 }
18012203
1802
- void ToggleFast()
2204
+ public void ToggleTexture()
2205
+ {
2206
+ textureon ^= true;
2207
+ }
2208
+
2209
+ public void ToggleLive()
2210
+ {
2211
+ Globals.setLIVE(Globals.isLIVE() ^ true);
2212
+
2213
+ System.err.println("LIVE = " + Globals.isLIVE());
2214
+
2215
+ if (!Globals.isLIVE()) // save sound
2216
+ Grafreed.savesound = true; // wav.save();
2217
+ // else
2218
+ repaint(); // start loop // may 2013
2219
+ }
2220
+
2221
+ public void ToggleSupport()
2222
+ {
2223
+ SUPPORT ^= true;
2224
+ }
2225
+
2226
+ public void ToggleAbort()
2227
+ {
2228
+ ABORTMODE ^= true;
2229
+ }
2230
+
2231
+ public void ToggleInertia()
2232
+ {
2233
+ INERTIA ^= true;
2234
+ }
2235
+
2236
+ public void ToggleFast()
18032237 {
18042238 FAST ^= true;
18052239 }
18062240
1807
- void ToggleSlowPose()
2241
+ public void ToggleSlowPose()
18082242 {
18092243 SLOWPOSE ^= true;
18102244 }
18112245
1812
- void ToggleFootContact()
1813
- {
1814
- FOOTCONTACT ^= true;
1815
- }
1816
-
1817
- void ToggleBoxMode()
2246
+ public void ToggleBoxMode()
18182247 {
18192248 BOXMODE ^= true;
18202249 }
18212250
1822
- void ToggleSmoothFocus()
2251
+ public void ToggleZoomBoxMode()
2252
+ {
2253
+ ZOOMBOXMODE ^= true;
2254
+ }
2255
+
2256
+ public void ToggleSmoothFocus()
18232257 {
18242258 SMOOTHFOCUS ^= true;
18252259 }
18262260
1827
- void ToggleImageFlip()
2261
+ public void ToggleImageFlip()
18282262 {
18292263 IMAGEFLIP ^= true;
18302264 }
18312265
1832
- void ToggleSpeakerMocap()
2266
+ public void ToggleSpeakerMocap()
18332267 {
18342268 SPEAKERMOCAP ^= true;
18352269 }
18362270
1837
- void ToggleSpeakerCamera()
2271
+ public void ToggleSpeakerCamera()
18382272 {
18392273 SPEAKERCAMERA ^= true;
18402274 }
18412275
1842
- void ToggleSpeakerFocus()
2276
+ public void ToggleSpeakerFocus()
18432277 {
18442278 SPEAKERFOCUS ^= true;
18452279 }
18462280
1847
- void ToggleDebug()
1848
- {
1849
- DEBUG ^= true;
1850
- }
1851
-
1852
- void ToggleFrustum()
2281
+ public void ToggleFrustum()
18532282 {
18542283 FRUSTUM ^= true;
18552284 }
18562285
1857
- void ToggleTrack()
2286
+ public void ToggleTrack()
18582287 {
18592288 TRACK ^= true;
18602289 if (TRACK)
....@@ -1873,25 +2302,35 @@
18732302 repaint();
18742303 }
18752304
1876
- void ToggleTrackOnce()
2305
+ public void ToggleTrackOnce()
18772306 {
18782307 TRACKONCE ^= true;
18792308 }
18802309
1881
- void ToggleShadowTrack()
2310
+ public void ToggleShadowTrack()
18822311 {
18832312 SHADOWTRACK ^= true;
18842313 repaint();
18852314 }
18862315
1887
- void ToggleOeil()
2316
+ public void ToggleOeil()
18882317 {
18892318 OEIL ^= true;
18902319 }
18912320
1892
- void ToggleOeilOnce()
2321
+ public void ToggleOeilOnce()
18932322 {
18942323 OEILONCE ^= true;
2324
+ }
2325
+
2326
+ void ToggleFootContact()
2327
+ {
2328
+ FOOTCONTACT ^= true;
2329
+ }
2330
+
2331
+ void ToggleDebug()
2332
+ {
2333
+ Globals.DEBUG ^= true;
18952334 }
18962335
18972336 void ToggleLookAt()
....@@ -1899,9 +2338,9 @@
18992338 LOOKAT ^= true;
19002339 }
19012340
1902
- void ToggleRandom()
2341
+ void ToggleSwitch()
19032342 {
1904
- RANDOM ^= true;
2343
+ SWITCH ^= true;
19052344 }
19062345
19072346 void ToggleHandles()
....@@ -1909,10 +2348,17 @@
19092348 HANDLES ^= true;
19102349 }
19112350
2351
+ Object3D paintFolder;
2352
+
19122353 void TogglePaint()
19132354 {
19142355 PAINTMODE ^= true;
19152356 paintcount = 0;
2357
+
2358
+ if (PAINTMODE)
2359
+ {
2360
+ paintFolder = GetFolder();
2361
+ }
19162362 }
19172363
19182364 void SwapCamera(int a, int b)
....@@ -2008,7 +2454,22 @@
20082454 {
20092455 return currentGL;
20102456 }
2011
-
2457
+
2458
+ static private BufferedImage CreateBim(TextureData texturedata)
2459
+ {
2460
+ Grafreed.Assert(texturedata != null);
2461
+
2462
+ int width = texturedata.getWidth();
2463
+ int height = texturedata.getHeight();
2464
+
2465
+ Buffer buffer = texturedata.getBuffer();
2466
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2467
+
2468
+ byte[] bytes = bytebuf.array();
2469
+
2470
+ return CreateBim(bytes, width, height);
2471
+ }
2472
+
20122473 /**/
20132474 class CacheTexture
20142475 {
....@@ -2017,28 +2478,31 @@
20172478
20182479 int resolution;
20192480
2020
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2481
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
20212482 {
2022
- texture = tex;
2483
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2484
+ texturedata = texdata;
20232485 resolution = res;
20242486 }
20252487 }
20262488 /**/
20272489
20282490 // 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>();
2491
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2492
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2493
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2494
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2495
+
20322496 int pigmentdepth = 0;
20332497 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
20342498 int bumpdepth = 0;
20352499 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
20362500 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
20372501 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2038
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2502
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
20392503 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
20402504
2041
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2505
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
20422506 {
20432507 TextureData texturedata = null;
20442508
....@@ -2057,13 +2521,34 @@
20572521 if (bump)
20582522 texturedata = ConvertBump(texturedata, false);
20592523
2060
- com.sun.opengl.util.texture.Texture texture =
2061
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2524
+// com.sun.opengl.util.texture.Texture texture =
2525
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
20622526
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);
2527
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2528
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
20652529
2066
- return texture;
2530
+ return texturedata;
2531
+ }
2532
+
2533
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2534
+ {
2535
+ TextureData texturedata = null;
2536
+
2537
+ try
2538
+ {
2539
+ texturedata =
2540
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2541
+ bim,
2542
+ true);
2543
+ } catch (Exception e)
2544
+ {
2545
+ throw new javax.media.opengl.GLException(e);
2546
+ }
2547
+
2548
+ if (bump)
2549
+ texturedata = ConvertBump(texturedata, false);
2550
+
2551
+ return texturedata;
20672552 }
20682553
20692554 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3136,6 +3621,8 @@
31363621
31373622 System.out.println("LOADING TEXTURE : " + name);
31383623
3624
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3625
+
31393626 //
31403627 if (false) // compressbit > 0)
31413628 {
....@@ -3840,6 +4327,7 @@
38404327
38414328 com.sun.opengl.util.texture.Texture CompressTexture2(String name)
38424329 {
4330
+ new Exception().printStackTrace();
38434331 System.exit(0);
38444332 com.sun.opengl.util.texture.Texture texture = null;
38454333
....@@ -7533,7 +8021,7 @@
75338021 String pigment = Object3D.GetPigment(tex);
75348022 String bump = Object3D.GetBump(tex);
75358023
7536
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8024
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
75378025 {
75388026 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
75398027 // System.out.println("; bump = " + bump);
....@@ -7548,11 +8036,69 @@
75488036 pigment = null;
75498037 }
75508038
7551
- ReleaseTexture(bump, true);
7552
- ReleaseTexture(pigment, false);
8039
+ ReleaseTexture(tex, true);
8040
+ ReleaseTexture(tex, false);
75538041 }
75548042
7555
- void ReleaseTexture(String tex, boolean bump)
8043
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
8044
+ {
8045
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8046
+ {
8047
+ return;
8048
+ }
8049
+
8050
+ if (tex == null)
8051
+ {
8052
+ ReleaseTexture(null, false);
8053
+ return;
8054
+ }
8055
+
8056
+ String pigment = Object3D.GetPigment(tex);
8057
+
8058
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8059
+ {
8060
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8061
+ // System.out.println("; bump = " + bump);
8062
+ }
8063
+
8064
+ if (pigment.equals(""))
8065
+ {
8066
+ pigment = null;
8067
+ }
8068
+
8069
+ ReleaseTexture(tex, false);
8070
+ }
8071
+
8072
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
8073
+ {
8074
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8075
+ {
8076
+ return;
8077
+ }
8078
+
8079
+ if (tex == null)
8080
+ {
8081
+ ReleaseTexture(null, true);
8082
+ return;
8083
+ }
8084
+
8085
+ String bump = Object3D.GetBump(tex);
8086
+
8087
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8088
+ {
8089
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8090
+ // System.out.println("; bump = " + bump);
8091
+ }
8092
+
8093
+ if (bump.equals(""))
8094
+ {
8095
+ bump = null;
8096
+ }
8097
+
8098
+ ReleaseTexture(tex, true);
8099
+ }
8100
+
8101
+ void ReleaseTexture(cTexture tex, boolean bump)
75568102 {
75578103 if (// DrawMode() != 0 || /*tex == null ||*/
75588104 ambientOcclusion ) // || !textureon)
....@@ -7563,7 +8109,7 @@
75638109 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
75648110
75658111 if (tex != null)
7566
- texture = textures.get(tex);
8112
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
75678113
75688114 // //assert( texture != null );
75698115 // if (texture == null)
....@@ -7655,7 +8201,55 @@
76558201 }
76568202 }
76578203
7658
- /*boolean*/ public void BindTextures(cTexture tex, int resolution) // INTERFACE
8204
+ /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
8205
+ {
8206
+// if (// DrawMode() != 0 || /*tex == null ||*/
8207
+// ambientOcclusion ) // || !textureon)
8208
+// {
8209
+// return; // false;
8210
+// }
8211
+//
8212
+// if (tex == null)
8213
+// {
8214
+// BindTexture(null,false,resolution);
8215
+// BindTexture(null,true,resolution);
8216
+// return;
8217
+// }
8218
+//
8219
+// String pigment = Object3D.GetPigment(tex);
8220
+// String bump = Object3D.GetBump(tex);
8221
+//
8222
+// usedtextures.add(pigment);
8223
+// usedtextures.add(bump);
8224
+//
8225
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8226
+// {
8227
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8228
+// // System.out.println("; bump = " + bump);
8229
+// }
8230
+//
8231
+// if (bump.equals(""))
8232
+// {
8233
+// bump = null;
8234
+// }
8235
+// if (pigment.equals(""))
8236
+// {
8237
+// pigment = null;
8238
+// }
8239
+//
8240
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8241
+// BindTexture(pigment, false, resolution);
8242
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8243
+// BindTexture(bump, true, resolution);
8244
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8245
+//
8246
+// return; // true;
8247
+
8248
+ BindPigmentTexture(tex, resolution);
8249
+ BindBumpTexture(tex, resolution);
8250
+ }
8251
+
8252
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
76598253 {
76608254 if (// DrawMode() != 0 || /*tex == null ||*/
76618255 ambientOcclusion ) // || !textureon)
....@@ -7666,17 +8260,47 @@
76668260 if (tex == null)
76678261 {
76688262 BindTexture(null,false,resolution);
7669
- BindTexture(null,true,resolution);
76708263 return;
76718264 }
76728265
76738266 String pigment = Object3D.GetPigment(tex);
8267
+
8268
+ usedtextures.add(tex);
8269
+
8270
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8271
+ {
8272
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8273
+ // System.out.println("; bump = " + bump);
8274
+ }
8275
+
8276
+ if (pigment.equals(""))
8277
+ {
8278
+ pigment = null;
8279
+ }
8280
+
8281
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8282
+ BindTexture(tex, false, resolution);
8283
+ }
8284
+
8285
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8286
+ {
8287
+ if (// DrawMode() != 0 || /*tex == null ||*/
8288
+ ambientOcclusion ) // || !textureon)
8289
+ {
8290
+ return; // false;
8291
+ }
8292
+
8293
+ if (tex == null)
8294
+ {
8295
+ BindTexture(null,true,resolution);
8296
+ return;
8297
+ }
8298
+
76748299 String bump = Object3D.GetBump(tex);
76758300
7676
- usedtextures.put(pigment, pigment);
7677
- usedtextures.put(bump, bump);
8301
+ usedtextures.add(tex);
76788302
7679
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8303
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
76808304 {
76818305 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
76828306 // System.out.println("; bump = " + bump);
....@@ -7686,43 +8310,94 @@
76868310 {
76878311 bump = null;
76888312 }
7689
- if (pigment.equals(""))
7690
- {
7691
- pigment = null;
7692
- }
76938313
7694
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
7695
- BindTexture(pigment, false, resolution);
76968314 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
7697
- BindTexture(bump, true, resolution);
8315
+ BindTexture(tex, true, resolution);
76988316 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
7699
-
7700
- return; // true;
77018317 }
77028318
7703
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution)
8319
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8320
+
8321
+ private boolean FileExists(String tex)
77048322 {
7705
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8323
+ if (missingTextures.contains(tex))
8324
+ {
8325
+ return false;
8326
+ }
8327
+
8328
+ boolean fileExists = new File(tex).exists();
8329
+
8330
+ if (!fileExists)
8331
+ {
8332
+ // If file exists, the "new File()" is not executed sgain
8333
+ missingTextures.add(tex);
8334
+ }
8335
+
8336
+ return fileExists;
8337
+ }
8338
+
8339
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
8340
+ {
8341
+ CacheTexture texturecache = null;
77068342
77078343 if (tex != null)
77088344 {
7709
- String texname = tex;
8345
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8346
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
77108347
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;
8348
+ if (texname.equals("") && texdata == null)
8349
+ {
8350
+ return null;
8351
+ }
8352
+
8353
+ String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
8354
+
8355
+// String[] split = tex.split("Textures");
8356
+// if (split.length > 1)
8357
+// texname = "/Users/nbriere/Textures" + split[split.length-1];
8358
+// else
8359
+// if (!texname.startsWith("/"))
8360
+// texname = "/Users/nbriere/Textures/" + texname;
8361
+ if (!FileExists(texname) && !texname.startsWith("@"))
8362
+ {
8363
+ texname = fallbackTextureName;
8364
+ }
77178365
77188366 if (CACHETEXTURE)
7719
- texture = textures.get(texname); // TEXTURE CACHE
7720
-
7721
- TextureData texturedata = null;
7722
-
7723
- if (texture == null || texture.resolution < resolution)
77248367 {
7725
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8368
+ if (texdata == null)
8369
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8370
+ else
8371
+ texturecache = bimtextures.get(texdata);
8372
+ }
8373
+
8374
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8375
+ {
8376
+ TextureData texturedata = null;
8377
+
8378
+ if (texdata != null && textureon)
8379
+ {
8380
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8381
+
8382
+ try
8383
+ {
8384
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8385
+ }
8386
+ catch (Exception e)
8387
+ {
8388
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8389
+ }
8390
+
8391
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8392
+ bimtextures.put(texdata, texturecache);
8393
+
8394
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8395
+
8396
+ //Object bim2 = CreateBim(texturecache.texturedata);
8397
+ //bim2 = bim;
8398
+ }
8399
+ else
8400
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
77268401 {
77278402 assert(!bump);
77288403 // if (bump)
....@@ -7733,19 +8408,23 @@
77338408 // }
77348409 // else
77358410 // {
7736
- texture = textures.get(tex);
7737
- if (texture == null)
8411
+ // texturecache = textures.get(texname); // suspicious
8412
+ if (texturecache == null)
77388413 {
7739
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8414
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
77408415 }
8416
+ else
8417
+ new Exception().printStackTrace();
77418418 // }
77428419 } else
7743
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8420
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
77448421 {
77458422 assert(bump);
7746
- texture = textures.get(tex);
7747
- if (texture == null)
7748
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8423
+ // texturecache = textures.get(texname); // suspicious
8424
+ if (texturecache == null)
8425
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8426
+ else
8427
+ new Exception().printStackTrace();
77498428 } else
77508429 {
77518430 //if (tex.equals("IMMORTAL"))
....@@ -7753,11 +8432,22 @@
77538432 // texture = GetResourceTexture("default.png");
77548433 //} else
77558434 //{
7756
- if (tex.equals("WHITE_NOISE"))
8435
+ if (texname.endsWith("WHITE_NOISE"))
77578436 {
7758
- texture = textures.get(tex);
7759
- if (texture == null)
7760
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8437
+ // texturecache = textures.get(texname); // suspicious
8438
+ if (texturecache == null)
8439
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8440
+ else
8441
+ new Exception().printStackTrace();
8442
+ } else
8443
+ {
8444
+ if (texname.startsWith("@"))
8445
+ {
8446
+ // texturecache = textures.get(texname); // suspicious
8447
+ if (texturecache == null)
8448
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8449
+ else
8450
+ new Exception().printStackTrace();
77618451 } else
77628452 {
77638453 if (textureon)
....@@ -7782,7 +8472,7 @@
77828472 }
77838473
77848474 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
7785
- if (!new File(cachename).exists())
8475
+ if (!FileExists(cachename))
77868476 cachename = texname;
77878477 else
77888478 processbump = false; // don't process bump map again
....@@ -7804,7 +8494,7 @@
78048494 }
78058495
78068496 cachename = texname.substring(0, texname.length()-4)+ext+".png";
7807
- if (!new File(cachename).exists())
8497
+ if (!FileExists(cachename))
78088498 cachename = texname;
78098499 else
78108500 processbump = false; // don't process bump map again
....@@ -7813,20 +8503,23 @@
78138503 texturedata = GetFileTexture(cachename, processbump, resolution);
78148504
78158505
7816
- if (texturedata != null)
7817
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8506
+ if (texturedata == null)
8507
+ throw new Exception();
8508
+
8509
+ texturecache = new CacheTexture(texturedata,resolution);
78188510 //texture = GetTexture(tex, bump);
78198511 }
8512
+ }
78208513 }
78218514 //}
78228515 }
78238516
7824
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8517
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
78258518 {
78268519 //return false;
78278520
78288521 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
7829
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8522
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
78308523 {
78318524 // String ext = "_highres";
78328525 // if (REDUCETEXTURE)
....@@ -7843,52 +8536,17 @@
78438536 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
78448537 if (!cachefile.exists())
78458538 {
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))
8539
+ //if (texturedata.getWidth() == texturedata.getHeight())
78558540 {
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);
8541
+ BufferedImage rendImage = CreateBim(texturedata);
8542
+
78868543 ImageWriter writer = null;
78878544 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
78888545 if (iter.hasNext()) {
78898546 writer = (ImageWriter)iter.next();
78908547 }
7891
- float compressionQuality = 0.9f;
8548
+
8549
+ float compressionQuality = 0.85f;
78928550 try
78938551 {
78948552 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -7905,18 +8563,20 @@
79058563 }
79068564 }
79078565 }
7908
-
8566
+
8567
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8568
+
79098569 //System.out.println("Texture = " + tex);
7910
- if (textures.containsKey(texname))
8570
+ if (textures.containsKey(tex))
79118571 {
7912
- CacheTexture thetex = textures.get(texname);
8572
+ CacheTexture thetex = textures.get(tex);
79138573 thetex.texture.disable();
79148574 thetex.texture.dispose();
7915
- textures.remove(texname);
8575
+ textures.remove(tex);
79168576 }
79178577
7918
- texture.texturedata = texturedata;
7919
- textures.put(texname, texture);
8578
+ //texture.texturedata = texturedata;
8579
+ textures.put(tex, texturecache);
79208580
79218581 // newtex = true;
79228582 }
....@@ -7932,10 +8592,44 @@
79328592 }
79338593 }
79348594
7935
- return texture;
8595
+ return texturecache;
79368596 }
79378597
7938
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution)
8598
+ static void EmbedTextures(cTexture tex)
8599
+ {
8600
+ if (tex.pigmentdata == null)
8601
+ {
8602
+ //String texname = Object3D.GetPigment(tex);
8603
+
8604
+ CacheTexture texturecache = texturepigment.get(tex);
8605
+
8606
+ if (texturecache != null)
8607
+ {
8608
+ tex.pw = texturecache.texturedata.getWidth();
8609
+ tex.ph = texturecache.texturedata.getHeight();
8610
+ tex.pigmentdata = //CompressJPEG(CreateBim
8611
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8612
+ ;
8613
+ //, tex.pw, tex.ph), 0.5f);
8614
+ }
8615
+ }
8616
+
8617
+ if (tex.bumpdata == null)
8618
+ {
8619
+ //String texname = Object3D.GetBump(tex);
8620
+
8621
+ CacheTexture texturecache = texturebump.get(tex);
8622
+
8623
+ if (texturecache != null)
8624
+ {
8625
+ tex.bw = texturecache.texturedata.getWidth();
8626
+ tex.bh = texturecache.texturedata.getHeight();
8627
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8628
+ }
8629
+ }
8630
+ }
8631
+
8632
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
79398633 {
79408634 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
79418635
....@@ -7953,21 +8647,21 @@
79538647 return texture!=null?texture.texture:null;
79548648 }
79558649
7956
- com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution)
8650
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
79578651 {
79588652 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
79598653
79608654 return texture!=null?texture.texturedata:null;
79618655 }
79628656
7963
- boolean BindTexture(String tex, boolean bump, int resolution)
8657
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
79648658 {
79658659 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
79668660 {
79678661 return false;
79688662 }
79698663
7970
- boolean newtex = false;
8664
+ //boolean newtex = false;
79718665
79728666 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
79738667
....@@ -7999,9 +8693,75 @@
79998693 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
80008694 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
80018695
8002
- return newtex;
8696
+ return true; // Warning: not used.
80038697 }
80048698
8699
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8700
+ {
8701
+ try
8702
+ {
8703
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8704
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8705
+ ImageWriter writer = writers.next();
8706
+
8707
+ ImageWriteParam param = writer.getDefaultWriteParam();
8708
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8709
+ param.setCompressionQuality(quality);
8710
+
8711
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8712
+ writer.setOutput(ios);
8713
+ writer.write(null, new IIOImage(image, null, null), param);
8714
+
8715
+ byte[] data = baos.toByteArray();
8716
+ writer.dispose();
8717
+ return data;
8718
+ }
8719
+ catch (Exception e)
8720
+ {
8721
+ e.printStackTrace();
8722
+ return null;
8723
+ }
8724
+ }
8725
+
8726
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8727
+ {
8728
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8729
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8730
+ ImageReader reader = writers.next();
8731
+
8732
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8733
+
8734
+ ImageReadParam param = reader.getDefaultReadParam();
8735
+ param.setDestination(bim);
8736
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8737
+
8738
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8739
+ reader.setInput(ios);
8740
+ BufferedImage bim2 = reader.read(0, param);
8741
+ reader.dispose();
8742
+
8743
+// WritableRaster raster = bim2.getRaster();
8744
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8745
+// byte[] bytes = data.getData();
8746
+//
8747
+// int[] pixels = new int[bytes.length/3];
8748
+// for (int i=pixels.length; --i>=0;)
8749
+// {
8750
+// int i3 = i*3;
8751
+// pixels[i] = 0xFF;
8752
+// pixels[i] <<= 8;
8753
+// pixels[i] |= bytes[i3+2] & 0xFF;
8754
+// pixels[i] <<= 8;
8755
+// pixels[i] |= bytes[i3+1] & 0xFF;
8756
+// pixels[i] <<= 8;
8757
+// pixels[i] |= bytes[i3] & 0xFF;
8758
+// }
8759
+//
8760
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8761
+
8762
+ return bim;
8763
+ }
8764
+
80058765 ShadowBuffer shadowPBuf;
80068766 AntialiasBuffer antialiasPBuf;
80078767 int MAXSTACK;
....@@ -8194,7 +8954,7 @@
81948954
81958955 if (cubemap == null)
81968956 {
8197
- LoadEnvy(5);
8957
+ //LoadEnvy(1);
81988958 }
81998959
82008960 //cubemap.enable();
....@@ -8481,37 +9241,58 @@
84819241 cubemap = null;
84829242 return;
84839243 case 1:
8484
- name = "cubemaps/box_";
8485
- ext = "png";
9244
+ name = "cubemaps/rgb/";
9245
+ ext = "jpg";
84869246 reverseUP = false;
84879247 break;
84889248 case 2:
8489
- name = "cubemaps/uffizi_";
8490
- ext = "png";
8491
- break; // reverseUP = true; break;
9249
+ name = "cubemaps/uffizi/";
9250
+ ext = "jpg";
9251
+ reverseUP = false;
9252
+ break;
84929253 case 3:
8493
- name = "cubemaps/CloudyHills_";
8494
- ext = "tga";
9254
+ name = "cubemaps/CloudyHills/";
9255
+ ext = "jpg";
84959256 reverseUP = false;
84969257 break;
84979258 case 4:
8498
- name = "cubemaps/cornell_";
9259
+ name = "cubemaps/cornell/";
84999260 ext = "png";
85009261 reverseUP = false;
85019262 break;
9263
+ case 5:
9264
+ name = "cubemaps/skycube/";
9265
+ ext = "jpg";
9266
+ reverseUP = false;
9267
+ break;
9268
+ case 6:
9269
+ name = "cubemaps/SaintLazarusChurch3/";
9270
+ ext = "jpg";
9271
+ reverseUP = false;
9272
+ break;
9273
+ case 7:
9274
+ name = "cubemaps/Sodermalmsallen/";
9275
+ ext = "jpg";
9276
+ reverseUP = false;
9277
+ break;
9278
+ case 8:
9279
+ name = "cubemaps/Sodermalmsallen2/";
9280
+ ext = "jpg";
9281
+ reverseUP = false;
9282
+ break;
9283
+ case 9:
9284
+ name = "cubemaps/UnionSquare/";
9285
+ ext = "jpg";
9286
+ reverseUP = false;
9287
+ break;
85029288 default:
8503
- name = "cubemaps/rgb_";
8504
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9289
+ name = "cubemaps/box/";
9290
+ ext = "png"; /*mipmap = true;*/
9291
+ reverseUP = false;
85059292 break;
85069293 }
8507
-
8508
- try
8509
- {
8510
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
8511
- } catch (IOException e)
8512
- {
8513
- throw new RuntimeException(e);
8514
- }
9294
+
9295
+ LoadSkybox(name, ext, mipmap);
85159296 }
85169297
85179298 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -8543,8 +9324,12 @@
85439324 static double[] model = new double[16];
85449325 double[] camera2light = new double[16];
85459326 double[] light2camera = new double[16];
8546
- int newenvy = -1;
8547
- boolean envyoff = true; // false;
9327
+
9328
+ //int newenvy = -1;
9329
+ //boolean envyoff = false;
9330
+
9331
+ String loadedskyboxname;
9332
+
85489333 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
85499334 //float[] light0 = { 0,0,0 };
85509335 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -8837,11 +9622,35 @@
88379622 jy8[3] = 0.5f;
88389623 }
88399624
8840
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9625
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
88419626 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
88429627 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
88439628 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
88449629
9630
+ void ResetOptions()
9631
+ {
9632
+ options1[0] = 100;
9633
+ options1[1] = 0.025f;
9634
+ options1[2] = 0.01f;
9635
+ options1[3] = 0;
9636
+ options1[4] = 0;
9637
+
9638
+ options2[0] = 0;
9639
+ options2[1] = 0.75f;
9640
+ options2[2] = 0;
9641
+ options2[3] = 0;
9642
+
9643
+ options3[0] = 1;
9644
+ options3[1] = 1;
9645
+ options3[2] = 1;
9646
+ options3[3] = 0;
9647
+
9648
+ options4[0] = 1;
9649
+ options4[1] = 0;
9650
+ options4[2] = 1;
9651
+ options4[3] = 0;
9652
+ }
9653
+
88459654 static int imagecount = 0; // movie generation
88469655
88479656 static int jitter = 0;
....@@ -8937,8 +9746,8 @@
89379746 assert (parentcam != renderCamera);
89389747
89399748 if (renderCamera != lightCamera)
8940
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8941
- LA.matConcat(matrix, parentcam.toParent, matrix);
9749
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9750
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
89429751
89439752 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
89449753
....@@ -8953,8 +9762,8 @@
89539762 LA.matCopy(renderCamera.fromScreen, matrix);
89549763
89559764 if (renderCamera != lightCamera)
8956
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8957
- LA.matConcat(parentcam.fromParent, matrix, matrix);
9765
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9766
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
89589767
89599768 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
89609769
....@@ -9000,10 +9809,12 @@
90009809 rati = 1 / rati;
90019810 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
90029811 }
9003
- assert (newenvy == -1);
9812
+
9813
+ //assert (newenvy == -1);
9814
+
90049815 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
90059816 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9006
- DrawSkyBox(gl);
9817
+ DrawSkyBox(gl, (float)rati);
90079818 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
90089819 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
90099820 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -9026,7 +9837,7 @@
90269837 //gl.glFlush();
90279838 gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE);
90289839
9029
- if (ANIMATION && ABORTED)
9840
+ if (Globals.ANIMATION && ABORTED)
90309841 {
90319842 System.err.println(" ABORTED FRAME");
90329843 break;
....@@ -9056,7 +9867,7 @@
90569867 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
90579868
90589869 // save image
9059
- if (ANIMATION && !ABORTED)
9870
+ if (Globals.ANIMATION && !ABORTED)
90609871 {
90619872 VPwidth = viewport[2];
90629873 VPheight = viewport[3];
....@@ -9167,11 +9978,11 @@
91679978
91689979 // imagecount++;
91699980
9170
- String fullname = filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
9981
+ String fullname = Globals.filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
91719982
91729983 if (!BOXMODE)
91739984 {
9174
- System.out.println("image: " + fullname + " (wav cursor=" + (GrafreeD.wav.cursor / 735 / 4) + ")");
9985
+ System.out.println("image: " + fullname + " (wav cursor=" + (Grafreed.wav.cursor / 735 / 4) + ")");
91759986 }
91769987
91779988 if (!BOXMODE)
....@@ -9209,7 +10020,7 @@
920910020 ABORTED = false;
921010021 }
921110022 else
9212
- GrafreeD.wav.cursor += 735 * ACSIZE;
10023
+ Grafreed.wav.cursor += 735 * ACSIZE;
921310024
921410025 if (false)
921510026 {
....@@ -9872,11 +10683,11 @@
987210683
987310684 public void display(GLAutoDrawable drawable)
987410685 {
9875
- if (GrafreeD.savesound && GrafreeD.hassound)
10686
+ if (Grafreed.savesound && Grafreed.hassound)
987610687 {
9877
- GrafreeD.wav.save();
9878
- GrafreeD.savesound = false;
9879
- GrafreeD.hassound = false;
10688
+ Grafreed.wav.save();
10689
+ Grafreed.savesound = false;
10690
+ Grafreed.hassound = false;
988010691 }
988110692 // if (DEBUG_SELECTION)
988210693 // {
....@@ -9952,6 +10763,7 @@
995210763 ANTIALIAS = 0;
995310764 //System.out.println("RESTART");
995410765 AAtimer.restart();
10766
+ Globals.TIMERRUNNING = true;
995510767 }
995610768 }
995710769 }
....@@ -10006,7 +10818,7 @@
1000610818 Object3D theobject = object;
1000710819 Object3D theparent = object.parent;
1000810820 object.parent = null;
10009
- object = (Object3D)GrafreeD.clone(object);
10821
+ object = (Object3D)Grafreed.clone(object);
1001010822 object.Stripify();
1001110823 if (theobject.selection == null || theobject.selection.Size() == 0)
1001210824 theobject.PreprocessOcclusion(this);
....@@ -10019,13 +10831,14 @@
1001910831 ambientOcclusion = false;
1002010832 }
1002110833
10022
- if (Globals.lighttouched && DrawMode() == DEFAULT && !lightMode) // && !FROZEN)
10834
+ if (//Globals.lighttouched &&
10835
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1002310836 {
1002410837 //if (RENDERSHADOW) // ?
1002510838 if (!IsFrozen())
1002610839 {
1002710840 // dec 2012
10028
- if (!ambientOcclusion && !(!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0))
10841
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
1002910842 {
1003010843 Globals.framecount++;
1003110844 shadowbuffer.display();
....@@ -10038,7 +10851,7 @@
1003810851
1003910852 if (wait)
1004010853 {
10041
- Sleep(500);
10854
+ Sleep(200); // blocks everything
1004210855
1004310856 wait = false;
1004410857 }
....@@ -10152,8 +10965,8 @@
1015210965
1015310966 // if (parentcam != renderCamera) // not a light
1015410967 if (cam != lightCamera)
10155
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10156
- LA.matConcat(matrix, parentcam.toParent, matrix);
10968
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10969
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1015710970
1015810971 for (int j = 0; j < 4; j++)
1015910972 {
....@@ -10167,8 +10980,8 @@
1016710980
1016810981 // if (parentcam != renderCamera) // not a light
1016910982 if (cam != lightCamera)
10170
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10171
- LA.matConcat(parentcam.fromParent, matrix, matrix);
10983
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10984
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1017210985
1017310986 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1017410987
....@@ -10254,13 +11067,27 @@
1025411067 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1025511068 }
1025611069
10257
- if (newenvy > -1)
11070
+// if (newenvy > -1)
11071
+// {
11072
+// LoadEnvy(newenvy);
11073
+// }
11074
+//
11075
+// newenvy = -1;
11076
+
11077
+ if (object.skyboxname != null)
1025811078 {
10259
- LoadEnvy(newenvy);
11079
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11080
+ {
11081
+ LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11082
+ loadedskyboxname = object.skyboxname;
11083
+ }
1026011084 }
10261
-
10262
- newenvy = -1;
10263
-
11085
+ else
11086
+ {
11087
+ cubemap = null;
11088
+ loadedskyboxname = null;
11089
+ }
11090
+
1026411091 ratio = ((double) getWidth()) / getHeight();
1026511092 //System.out.println("ratio = " + ratio);
1026611093
....@@ -10276,7 +11103,7 @@
1027611103
1027711104 if (!IsFrozen() && !ambientOcclusion)
1027811105 {
10279
- DrawSkyBox(gl);
11106
+ DrawSkyBox(gl, (float)ratio);
1028011107 }
1028111108
1028211109 //if (selection_view == -1)
....@@ -10427,7 +11254,16 @@
1042711254 // Bump noise
1042811255 gl.glActiveTexture(GL.GL_TEXTURE6);
1042911256 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
10430
- BindTexture(NOISE_TEXTURE, false, 2);
11257
+
11258
+ try
11259
+ {
11260
+ BindTexture(NOISE_TEXTURE, false, 2);
11261
+ }
11262
+ catch (Exception e)
11263
+ {
11264
+ System.err.println("FAILED: " + NOISE_TEXTURE);
11265
+ }
11266
+
1043111267
1043211268 gl.glActiveTexture(GL.GL_TEXTURE0);
1043311269 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -10450,9 +11286,9 @@
1045011286
1045111287 gl.glMatrixMode(GL.GL_MODELVIEW);
1045211288
10453
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10454
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10455
-//gl.glEnable(gl.GL_MULTISAMPLE);
11289
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11290
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11291
+gl.glEnable(gl.GL_MULTISAMPLE);
1045611292 } else
1045711293 {
1045811294 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -10463,7 +11299,7 @@
1046311299 //System.out.println("BLENDING ON");
1046411300 gl.glEnable(GL.GL_BLEND);
1046511301 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
10466
-
11302
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1046711303 gl.glMatrixMode(gl.GL_PROJECTION);
1046811304 gl.glLoadIdentity();
1046911305
....@@ -10552,8 +11388,8 @@
1055211388 System.err.println("parentcam != renderCamera");
1055311389
1055411390 // if (cam != lightCamera)
10555
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10556
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11391
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11392
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1055711393 }
1055811394
1055911395 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -10574,8 +11410,8 @@
1057411410 if (true) // TODO
1057511411 {
1057611412 if (cam != lightCamera)
10577
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10578
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11413
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11414
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
1057911415 }
1058011416
1058111417 LA.xformPos(light0, cam.toScreen, light0);
....@@ -10712,7 +11548,7 @@
1071211548 }
1071311549 }
1071411550
10715
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11551
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1071611552 {
1071711553 //gl.glDepthFunc(GL.GL_LEQUAL);
1071811554 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -10720,24 +11556,21 @@
1072011556
1072111557 boolean texon = textureon;
1072211558
10723
- if (RENDERPROGRAM > 0)
10724
- {
10725
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
10726
- textureon = false;
10727
- }
11559
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11560
+ textureon = false;
11561
+
1072811562 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1072911563 //System.out.println("ALLO");
1073011564 gl.glColorMask(false, false, false, false);
1073111565 DrawObject(gl);
10732
- if (RENDERPROGRAM > 0)
10733
- {
10734
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
10735
- textureon = texon;
10736
- }
11566
+
11567
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11568
+ textureon = texon;
11569
+
1073711570 gl.glColorMask(true, true, true, true);
1073811571
1073911572 gl.glDepthFunc(GL.GL_EQUAL);
10740
- //gl.glDepthMask(false);
11573
+ gl.glDepthMask(false);
1074111574 }
1074211575
1074311576 if (false) // DrawMode() == SHADOW)
....@@ -10891,8 +11724,14 @@
1089111724 {
1089211725 renderpass++;
1089311726 // System.out.println("Draw object... ");
11727
+ STEP = 1;
1089411728 if (FAST) // in case there is no script
10895
- STEP = 16;
11729
+ STEP = 8;
11730
+
11731
+ if (CURRENTANTIALIAS == 0 || ACSIZE == 1)
11732
+ {
11733
+ STEP *= 4;
11734
+ }
1089611735
1089711736 //object.FullInvariants();
1089811737
....@@ -10906,23 +11745,44 @@
1090611745 e.printStackTrace();
1090711746 }
1090811747
10909
- if (GrafreeD.RENDERME > 0)
10910
- GrafreeD.RENDERME--; // mechante magouille
11748
+ if (Grafreed.RENDERME > 0)
11749
+ Grafreed.RENDERME--; // mechante magouille
1091111750
1091211751 Globals.ONESTEP = false;
1091311752 }
1091411753
1091511754 static boolean zoomonce = false;
1091611755
11756
+ static void CreateSelectedPoint()
11757
+ {
11758
+ if (selectedpoint == null)
11759
+ {
11760
+ debugpointG = new Sphere();
11761
+ debugpointP = new Sphere();
11762
+ debugpointC = new Sphere();
11763
+ debugpointR = new Sphere();
11764
+
11765
+ selectedpoint = new Superellipsoid();
11766
+
11767
+ for (int i=0; i<8; i++)
11768
+ {
11769
+ debugpoints[i] = new Sphere();
11770
+ }
11771
+ }
11772
+ }
11773
+
1091711774 void DrawObject(GL gl, boolean draw)
1091811775 {
11776
+ // To clear camera values
11777
+ ResetOptions();
11778
+
1091911779 //System.out.println("DRAW OBJECT " + mouseDown);
1092011780 // DrawMode() = SELECTION;
1092111781 //GL gl = getGL();
1092211782 if ((TRACK || SHADOWTRACK) || zoomonce)
1092311783 {
1092411784 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
10925
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11785
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1092611786 pingthread.StepToTarget(true); // true);
1092711787 // zoomonce = false;
1092811788 }
....@@ -10977,7 +11837,14 @@
1097711837
1097811838 usedtextures.clear();
1097911839
10980
- BindTextures(DEFAULT_TEXTURES, 2);
11840
+ try
11841
+ {
11842
+ BindTextures(DEFAULT_TEXTURES, 2);
11843
+ }
11844
+ catch (Exception e)
11845
+ {
11846
+ System.err.println("FAILED: " + DEFAULT_TEXTURES);
11847
+ }
1098111848 }
1098211849 //System.out.println("--> " + stackdepth);
1098311850 // GrafreeD.traceon();
....@@ -10987,8 +11854,9 @@
1098711854
1098811855 if (DrawMode() == DEFAULT)
1098911856 {
10990
- if (DEBUG)
11857
+ if (Globals.DEBUG)
1099111858 {
11859
+ CreateSelectedPoint();
1099211860 float radius = 0.05f;
1099311861 if (selectedpoint.radius != radius)
1099411862 {
....@@ -11042,20 +11910,32 @@
1104211910 ReleaseTextures(DEFAULT_TEXTURES);
1104311911
1104411912 if (CLEANCACHE)
11045
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11913
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1104611914 {
11047
- String tex = e.nextElement();
11915
+ cTexture tex = e.nextElement();
1104811916
1104911917 // System.out.println("Texture --------- " + tex);
1105011918
11051
- if (tex.equals("WHITE_NOISE"))
11919
+ if (tex.equals("WHITE_NOISE:"))
1105211920 continue;
1105311921
11054
- if (!usedtextures.containsKey(tex))
11922
+ if (!usedtextures.contains(tex))
1105511923 {
11924
+ CacheTexture gettex = texturepigment.get(tex);
1105611925 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11057
- textures.get(tex).texture.dispose();
11058
- textures.remove(tex);
11926
+ if (gettex != null)
11927
+ {
11928
+ gettex.texture.dispose();
11929
+ texturepigment.remove(tex);
11930
+ }
11931
+
11932
+ gettex = texturebump.get(tex);
11933
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11934
+ if (gettex != null)
11935
+ {
11936
+ gettex.texture.dispose();
11937
+ texturebump.remove(tex);
11938
+ }
1105911939 }
1106011940 }
1106111941 }
....@@ -11068,7 +11948,14 @@
1106811948 if (checker != null && DrawMode() == DEFAULT)
1106911949 {
1107011950 //BindTexture(IMMORTAL_TEXTURE);
11071
- BindTextures(checker.GetTextures(), checker.texres);
11951
+ try
11952
+ {
11953
+ BindTextures(checker.GetTextures(), checker.texres);
11954
+ }
11955
+ catch (Exception e)
11956
+ {
11957
+ System.err.println("FAILED: " + checker.GetTextures());
11958
+ }
1107211959 // NEAREST
1107311960 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
1107411961 DrawChecker(gl);
....@@ -11150,7 +12037,7 @@
1115012037 return;
1115112038 }
1115212039
11153
- String string = obj.GetToolTip();
12040
+ String string = obj.toString(); //.GetToolTip();
1115412041
1115512042 GL gl = GetGL();
1115612043
....@@ -11467,8 +12354,8 @@
1146712354 //obj.TransformToWorld(light, light);
1146812355 for (int i = tp.size(); --i >= 0;)
1146912356 {
11470
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
11471
- LA.xformPos(light, tp.get(i).toParent, light);
12357
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12358
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1147212359 }
1147312360
1147412361
....@@ -11485,8 +12372,8 @@
1148512372 parentcam = cameras[0];
1148612373 }
1148712374
11488
- for (int count = parentcam.GetTransformCount(); --count>=0;)
11489
- LA.xformPos(light, parentcam.toParent, light); // may 2013
12375
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
12376
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1149012377
1149112378 LA.xformPos(light, renderCamera.toScreen, light);
1149212379
....@@ -11576,8 +12463,76 @@
1157612463
1157712464 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1157812465
11579
- String program =
12466
+ String programmin =
12467
+ // Min shader
1158012468 "!!ARBfp1.0\n" +
12469
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12470
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12471
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12472
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12473
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12474
+ "PARAM light2cam0 = program.env[10];" +
12475
+ "PARAM light2cam1 = program.env[11];" +
12476
+ "PARAM light2cam2 = program.env[12];" +
12477
+ "TEMP temp;" +
12478
+ "TEMP light;" +
12479
+ "TEMP ndotl;" +
12480
+ "TEMP normal;" +
12481
+ "TEMP depth;" +
12482
+ "TEMP eye;" +
12483
+ "TEMP pos;" +
12484
+
12485
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12486
+ Normalize("normal") +
12487
+ "MOV light, state.light[0].position;" +
12488
+ "DP3 ndotl.x, light, normal;" +
12489
+
12490
+ // shadow
12491
+ "MOV pos, fragment.texcoord[1];" +
12492
+ "MOV temp, pos;" +
12493
+ ShadowTextureFetch("depth", "temp", "1") +
12494
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12495
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12496
+
12497
+ // No shadow when out of frustum
12498
+ //"SGE temp.y, depth.z, zero123.y;" +
12499
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12500
+
12501
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12502
+
12503
+ // Backlit
12504
+ "MOV pos.w, zero123.y;" +
12505
+ "DP4 eye.x, pos, light2cam0;" +
12506
+ "DP4 eye.y, pos, light2cam1;" +
12507
+ "DP4 eye.z, pos, light2cam2;" +
12508
+ Normalize("eye") +
12509
+
12510
+ "DP3 ndotl.y, -eye, normal;" +
12511
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12512
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12513
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12514
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12515
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12516
+
12517
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12518
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12519
+
12520
+ // Pigment
12521
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12522
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12523
+ "MUL temp, temp, ndotl.x;" +
12524
+
12525
+ "MUL temp, temp, zero123.z;" +
12526
+
12527
+ //"MUL temp, temp, ndotl.y;" +
12528
+
12529
+ "MOV temp.w, zero123.y;" + // reset alpha
12530
+ "MOV result.color, temp;" +
12531
+ "END";
12532
+
12533
+ String programmax =
12534
+ "!!ARBfp1.0\n" +
12535
+
1158112536 //"OPTION ARB_fragment_program_shadow;" +
1158212537 "PARAM light2cam0 = program.env[10];" +
1158312538 "PARAM light2cam1 = program.env[11];" +
....@@ -11692,8 +12647,7 @@
1169212647 "TEMP shininess;" +
1169312648 "\n" +
1169412649 "MOV texSamp, one;" +
11695
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
11696
-
12650
+
1169712651 "MOV mapgrid.x, one2048th.x;" +
1169812652 "MOV temp, fragment.texcoord[1];" +
1169912653 /*
....@@ -11714,20 +12668,20 @@
1171412668 "MUL temp, floor, mapgrid.x;" +
1171512669 //"TEX depth0, temp, texture[1], 2D;" +
1171612670 (((mode & FP_SOFTSHADOW) == 0) ? "" :
11717
- TextureFetch("depth0", "temp", "1") +
12671
+ ShadowTextureFetch("depth0", "temp", "1") +
1171812672 "") +
1171912673 "ADD temp.x, temp.x, mapgrid.x;" +
1172012674 //"TEX depth1, temp, texture[1], 2D;" +
1172112675 (((mode & FP_SOFTSHADOW) == 0) ? "" :
11722
- TextureFetch("depth1", "temp", "1") +
12676
+ ShadowTextureFetch("depth1", "temp", "1") +
1172312677 "") +
1172412678 "ADD temp.y, temp.y, mapgrid.x;" +
1172512679 //"TEX depth2, temp, texture[1], 2D;" +
11726
- TextureFetch("depth2", "temp", "1") +
12680
+ ShadowTextureFetch("depth2", "temp", "1") +
1172712681 "SUB temp.x, temp.x, mapgrid.x;" +
1172812682 //"TEX depth3, temp, texture[1], 2D;" +
1172912683 (((mode & FP_SOFTSHADOW) == 0) ? "" :
11730
- TextureFetch("depth3", "temp", "1") +
12684
+ ShadowTextureFetch("depth3", "temp", "1") +
1173112685 "") +
1173212686 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1173312687 //"MOV params, material;" +
....@@ -12098,10 +13052,10 @@
1209813052 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1209913053 "") +
1210013054
12101
- // display shadow only (bump == 0)
13055
+ // display shadow only (fakedepth == 0)
1210213056 "SUB temp.x, half.x, shadow.x;" +
12103
- "MOV temp.y, -params6.x;" +
12104
- "SLT temp.z, temp.y, zero.x;" +
13057
+ "MOV temp.y, -params5.z;" + // params6.x;" +
13058
+ "SLT temp.z, temp.y, -c256i.x;" +
1210513059 "SUB temp.y, one.x, temp.z;" +
1210613060 "MUL temp.x, temp.x, temp.y;" +
1210713061 "KIL temp.x;" +
....@@ -12230,8 +13184,10 @@
1223013184 "MAX ndotl.x, ndotl.x, -ndotl.x;" +
1223113185
1223213186 "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
13187
+ // Tuning for default skin
13188
+ //"ADD temp.x, temp.x, options2.z;" + // lightsheen
13189
+ "MAD temp.x, options2.z, half.y, temp.x;" + // lightsheen
13190
+ "ADD temp.y, one.y, options2.y;" + // subsurface
1223513191 "MUL temp.x, temp.x, temp.y;" +
1223613192
1223713193 "MUL saturation, saturation, temp.xxxx;" +
....@@ -12430,7 +13386,14 @@
1243013386 //once = true;
1243113387 }
1243213388
12433
- System.out.print("Program #" + mode + "; length = " + program.length());
13389
+ String program = programmax;
13390
+
13391
+ if (Globals.MINSHADER)
13392
+ {
13393
+ program = programmin;
13394
+ }
13395
+
13396
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1243413397 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1243513398 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1243613399
....@@ -12523,25 +13486,26 @@
1252313486 return out;
1252413487 }
1252513488
12526
- String TextureFetch(String dest, String src, String unit)
13489
+ // Also does frustum culling
13490
+ String ShadowTextureFetch(String dest, String src, String unit)
1252713491 {
1252813492 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1252913493 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1253013494 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13495
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13496
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1253113497 "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;" +
13498
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13499
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1253613500 //"SWZ buffer, temp, w,w,w,w;";
12537
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13501
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1253813502 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1253913503 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1254013504 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
12541
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13505
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1254213506
12543
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
12544
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13507
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13508
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1254513509 }
1254613510
1254713511 String Shadow(String depth, String shadow)
....@@ -12563,12 +13527,16 @@
1256313527
1256413528 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1256513529 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13530
+
13531
+ // Compare fragment depth in light space with shadowmap.
1256613532 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1256713533 "SGE temp.y, temp.x, zero.x;" +
12568
- "SUB " + shadow + ".y, one.x, temp.y;" +
13534
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13535
+
13536
+ // Reverse comparison
1256913537 "SUB temp.x, one.x, temp.x;" +
1257013538 "MUL " + shadow + ".x, temp.x, temp.y;" +
12571
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13539
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1257213540 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1257313541
1257413542 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -12582,6 +13550,10 @@
1258213550 // No shadow for backface
1258313551 "DP3 temp.x, normal, lightd;" +
1258413552 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13553
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13554
+
13555
+ // No shadow when out of frustum
13556
+ "SGE temp.x, " + depth + ".z, one.z;" +
1258513557 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1258613558 "";
1258713559 }
....@@ -12728,7 +13700,8 @@
1272813700 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1272913701 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1273013702 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
12731
- Object3D.cVector2[] vector2buffer;
13703
+
13704
+ //Object3D.cVector2[] vector2buffer;
1273213705
1273313706 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1273413707 // OUT : diff, spec
....@@ -12744,9 +13717,10 @@
1274413717 "DP3 " + dest + ".z," + "normals," + "eye;" +
1274513718 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1274613719 //"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;" +
13720
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13721
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13722
+
13723
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1275013724 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1275113725 "RCP " + dest + ".w," + dest + ".w;" +
1275213726 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13140,7 +14114,7 @@
1314014114 public void mousePressed(MouseEvent e)
1314114115 {
1314214116 //System.out.println("mousePressed: " + e);
13143
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14117
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1314414118 }
1314514119
1314614120 static long prevtime = 0;
....@@ -13167,6 +14141,7 @@
1316714141
1316814142 //System.err.println("Dtime = " + Dtime + "; units = " + e.getUnitsToScroll() + "; ratio (units/ms) = " + ratio);
1316914143
14144
+ if (BUTTONLESSWHEEL)
1317014145 if (Math.abs(ratio) < 0.1 || Math.abs(Dtime) == 0) // < 30)
1317114146 {
1317214147 return;
....@@ -13175,7 +14150,7 @@
1317514150 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
1317614151
1317714152 // TIMER
13178
- if (!wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
14153
+ if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
1317914154 {
1318014155 keepboxmode = BOXMODE;
1318114156 keepsupport = SUPPORT;
....@@ -13215,8 +14190,8 @@
1321514190 // mode |= META;
1321614191 //}
1321714192
13218
- SetMouseMode(WHEEL | e.getModifiersEx());
13219
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14193
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14194
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1322014195 anchorX = ax;
1322114196 anchorY = ay;
1322214197 prevX = px;
....@@ -13250,6 +14225,7 @@
1325014225 else
1325114226 if (evt.getSource() == AAtimer)
1325214227 {
14228
+ Globals.TIMERRUNNING = false;
1325314229 if (mouseDown)
1325414230 {
1325514231 //new Exception().printStackTrace();
....@@ -13275,6 +14251,10 @@
1327514251 // LIVE = waslive;
1327614252 // wasliveok = true;
1327714253 // waslive = false;
14254
+
14255
+ // May 2019 Forget it:
14256
+ if (true)
14257
+ return;
1327814258
1327914259 // source == timer
1328014260 if (mouseDown)
....@@ -13305,7 +14285,7 @@
1330514285
1330614286 // fev 2014???
1330714287 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13308
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14288
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1330914289 pingthread.StepToTarget(true); // true);
1331014290 }
1331114291 // if (!LIVE)
....@@ -13314,12 +14294,13 @@
1331414294
1331514295 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1331614296
13317
- void clickStart(int x, int y, int modifiers)
14297
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1331814298 {
1331914299 if (!wasliveok)
1332014300 return;
1332114301
1332214302 AAtimer.restart(); //
14303
+ Globals.TIMERRUNNING = true;
1332314304
1332414305 // waslive = LIVE;
1332514306 // LIVE = false;
....@@ -13331,7 +14312,7 @@
1333114312 // touched = true; // main DL
1333214313 if (isRenderer)
1333314314 {
13334
- SetMouseMode(modifiers);
14315
+ SetMouseMode(modifiers, modifiersex);
1333514316 }
1333614317
1333714318 selectX = anchorX = x;
....@@ -13344,7 +14325,7 @@
1334414325 clicked = true;
1334514326 hold = false;
1334614327
13347
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14328
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1334814329 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1334914330 {
1335014331 // System.out.println("RESTART II " + modifiers);
....@@ -13369,14 +14350,15 @@
1336914350 drag = false;
1337014351 //System.out.println("Mouse DOWN");
1337114352 editObj = false;
13372
- ClickInfo info = new ClickInfo();
13373
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
13374
- info.pane = this;
13375
- info.camera = renderCamera;
13376
- info.x = x;
13377
- info.y = y;
13378
- info.modifiers = modifiers;
13379
- editObj = object.doEditClick(info, 0);
14353
+ //ClickInfo info = new ClickInfo();
14354
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14355
+ object.clickInfo.pane = this;
14356
+ object.clickInfo.camera = renderCamera;
14357
+ object.clickInfo.x = x;
14358
+ object.clickInfo.y = y;
14359
+ object.clickInfo.modifiers = modifiersex;
14360
+ editObj = object.doEditClick(//info,
14361
+ 0);
1338014362 if (!editObj)
1338114363 {
1338214364 hasMarquee = true;
....@@ -13392,11 +14374,14 @@
1339214374
1339314375 public void mouseDragged(MouseEvent e)
1339414376 {
14377
+ Globals.MOUSEDRAGGED = true;
14378
+
14379
+ //System.out.println("mouseDragged: " + e);
1339514380 if (isRenderer)
1339614381 movingcamera = true;
14382
+
1339714383 //if (drawing)
1339814384 //return;
13399
- //System.out.println("mouseDragged: " + e);
1340014385 if ((e.getModifiersEx() & CTRL) != 0
1340114386 || (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen())
1340214387 {
....@@ -13404,7 +14389,7 @@
1340414389 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1340514390 }
1340614391 else
13407
- drag(e.getX(), e.getY(), e.getModifiersEx());
14392
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1340814393
1340914394 //try { Thread.sleep(1); } catch (Exception ex) {}
1341014395 }
....@@ -13577,6 +14562,7 @@
1357714562
1357814563 public void run()
1357914564 {
14565
+ new Exception().printStackTrace();
1358014566 System.exit(0);
1358114567 for (;;)
1358214568 {
....@@ -13640,7 +14626,7 @@
1364014626 {
1364114627 Globals.lighttouched = true;
1364214628 }
13643
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14629
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1364414630 }
1364514631 //else
1364614632 }
....@@ -13654,12 +14640,12 @@
1365414640 void GoDown(int mod)
1365514641 {
1365614642 MODIFIERS |= COMMAND;
13657
- /*
14643
+ /**/
1365814644 if((mod&SHIFT) == SHIFT)
13659
- manipCamera.RotatePosition(0, -speed);
14645
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
1366014646 else
13661
- manipCamera.BackForth(0, -speed*delta, getWidth());
13662
- */
14647
+ manipCamera.RotatePosition(0, -speed);
14648
+ /**/
1366314649 if ((mod & SHIFT) == SHIFT)
1366414650 {
1366514651 mouseMode = mouseMode; // VR??
....@@ -13675,12 +14661,12 @@
1367514661 void GoUp(int mod)
1367614662 {
1367714663 MODIFIERS |= COMMAND;
13678
- /*
14664
+ /**/
1367914665 if((mod&SHIFT) == SHIFT)
13680
- manipCamera.RotatePosition(0, speed);
14666
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
1368114667 else
13682
- manipCamera.BackForth(0, speed*delta, getWidth());
13683
- */
14668
+ manipCamera.RotatePosition(0, speed);
14669
+ /**/
1368414670 if ((mod & SHIFT) == SHIFT)
1368514671 {
1368614672 mouseMode = mouseMode;
....@@ -13696,12 +14682,12 @@
1369614682 void GoLeft(int mod)
1369714683 {
1369814684 MODIFIERS |= COMMAND;
13699
- /*
14685
+ /**/
1370014686 if((mod&SHIFT) == SHIFT)
13701
- manipCamera.RotatePosition(speed, 0);
13702
- else
1370314687 manipCamera.Translate(speed*delta, 0, getWidth());
13704
- */
14688
+ else
14689
+ manipCamera.RotatePosition(speed, 0);
14690
+ /**/
1370514691 if ((mod & SHIFT) == SHIFT)
1370614692 {
1370714693 mouseMode = mouseMode;
....@@ -13717,12 +14703,12 @@
1371714703 void GoRight(int mod)
1371814704 {
1371914705 MODIFIERS |= COMMAND;
13720
- /*
14706
+ /**/
1372114707 if((mod&SHIFT) == SHIFT)
13722
- manipCamera.RotatePosition(-speed, 0);
13723
- else
1372414708 manipCamera.Translate(-speed*delta, 0, getWidth());
13725
- */
14709
+ else
14710
+ manipCamera.RotatePosition(-speed, 0);
14711
+ /**/
1372614712 if ((mod & SHIFT) == SHIFT)
1372714713 {
1372814714 mouseMode = mouseMode;
....@@ -13740,7 +14726,7 @@
1374014726 int X, Y;
1374114727 boolean SX, SY;
1374214728
13743
- void drag(int x, int y, int modifiers)
14729
+ void drag(int x, int y, int modifiers, int modifiersex)
1374414730 {
1374514731 if (IsFrozen())
1374614732 {
....@@ -13749,17 +14735,17 @@
1374914735
1375014736 drag = true; // NEW
1375114737
13752
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14738
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1375314739
1375414740 X = x;
1375514741 Y = y;
1375614742 // floating state for animation
13757
- MODIFIERS = modifiers;
13758
- modifiers &= ~1024;
14743
+ MODIFIERS = modifiersex;
14744
+ modifiersex &= ~1024;
1375914745 if (false) // modifiers != 0)
1376014746 {
1376114747 //new Exception().printStackTrace();
13762
- System.out.println("mouseDragged: " + modifiers);
14748
+ System.out.println("mouseDragged: " + modifiersex);
1376314749 System.out.println("SHIFT = " + SHIFT);
1376414750 System.out.println("CONTROL = " + COMMAND);
1376514751 System.out.println("META = " + META);
....@@ -13772,14 +14758,16 @@
1377214758 if (editObj)
1377314759 {
1377414760 drag = true;
13775
- ClickInfo info = new ClickInfo();
13776
- info.bounds.setBounds(0, 0,
14761
+ //ClickInfo info = new ClickInfo();
14762
+ object.clickInfo.bounds.setBounds(0, 0,
1377714763 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
13778
- info.pane = this;
13779
- info.camera = renderCamera;
13780
- info.x = x;
13781
- info.y = y;
13782
- object.editWindow.copy.doEditDrag(info);
14764
+ object.clickInfo.pane = this;
14765
+ object.clickInfo.camera = renderCamera;
14766
+ object.clickInfo.x = x;
14767
+ object.clickInfo.y = y;
14768
+ object //.GetWindow().copy
14769
+ .doEditDrag(//info,
14770
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1378314771 } else
1378414772 {
1378514773 if (x < startX)
....@@ -13928,23 +14916,27 @@
1392814916 }
1392914917 }
1393014918
14919
+// ClickInfo clickInfo = new ClickInfo();
14920
+
1393114921 public void mouseMoved(MouseEvent e)
1393214922 {
1393314923 //System.out.println("mouseMoved: " + e);
13934
-
1393514924 if (isRenderer)
1393614925 return;
1393714926
13938
- ClickInfo ci = new ClickInfo();
13939
- ci.x = e.getX();
13940
- ci.y = e.getY();
13941
- ci.modifiers = e.getModifiersEx();
13942
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
13943
- ci.pane = this;
13944
- ci.camera = renderCamera;
14927
+ // Mouse cursor feedback
14928
+ object.clickInfo.x = e.getX();
14929
+ object.clickInfo.y = e.getY();
14930
+ object.clickInfo.modifiers = e.getModifiersEx();
14931
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14932
+ object.clickInfo.pane = this;
14933
+ object.clickInfo.camera = renderCamera;
1394514934 if (!isRenderer)
1394614935 {
13947
- if (object.editWindow.copy.doEditClick(ci, 0))
14936
+ //ObjEditor editWindow = object.editWindow;
14937
+ //Object3D copy = editWindow.copy;
14938
+ if (object.doEditClick(//clickInfo,
14939
+ 0))
1394814940 {
1394914941 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1395014942 } else
....@@ -13956,7 +14948,11 @@
1395614948
1395714949 public void mouseReleased(MouseEvent e)
1395814950 {
14951
+ Globals.MOUSEDRAGGED = false;
14952
+
1395914953 movingcamera = false;
14954
+ X = 0; // getBounds().width/2;
14955
+ Y = 0; // getBounds().height/2;
1396014956 //System.out.println("mouseReleased: " + e);
1396114957 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1396214958 }
....@@ -13979,9 +14975,9 @@
1397914975 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1398014976 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1398114977
13982
- if (control || command || IsFrozen())
14978
+// No delay if (control || command || IsFrozen())
1398314979 timeout = true;
13984
- else
14980
+// ?? May 2019 else
1398514981 // timer.setDelay((modifiers & 128) != 0?0:350);
1398614982 mouseDown = false;
1398714983 if (!control && !command) // june 2013
....@@ -14091,7 +15087,7 @@
1409115087 System.out.println("keyReleased: " + e);
1409215088 }
1409315089
14094
- void SetMouseMode(int modifiers)
15090
+ void SetMouseMode(int modifiers, int modifiersex)
1409515091 {
1409615092 //System.out.println("SetMouseMode = " + modifiers);
1409715093 //modifiers &= ~1024;
....@@ -14103,25 +15099,25 @@
1410315099 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1410415100 // return;
1410515101 //System.out.println("SetMode = " + modifiers);
14106
- if ((modifiers & WHEEL) == WHEEL)
15102
+ if ((modifiersex & WHEEL) == WHEEL)
1410715103 {
1410815104 mouseMode |= ZOOM;
1410915105 }
1411015106
1411115107 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
14112
- if (capsLocked || (modifiers & META) == META)
15108
+ if (capsLocked) // || (modifiers & META) == META)
1411315109 {
1411415110 mouseMode |= VR; // BACKFORTH;
1411515111 }
14116
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
15112
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1411715113 {
1411815114 mouseMode |= SELECT;
1411915115 }
14120
- if ((modifiers & COMMAND) == COMMAND)
15116
+ if ((modifiersex & COMMAND) == COMMAND)
1412115117 {
1412215118 mouseMode |= SELECT;
1412315119 }
14124
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15120
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
1412515121 {
1412615122 mouseMode &= ~VR;
1412715123 mouseMode |= TRANSLATE;
....@@ -14150,10 +15146,10 @@
1415015146
1415115147 if (isRenderer) //
1415215148 {
14153
- SetMouseMode(modifiers);
15149
+ SetMouseMode(0, modifiers);
1415415150 }
1415515151
14156
- theRenderer.keyPressed(key);
15152
+ Globals.theRenderer.keyPressed(key);
1415715153 }
1415815154
1415915155 int kompactbit = 4; // power bit
....@@ -14165,7 +15161,7 @@
1416515161 float SATPOW = 1; // 2; // 0.5f;
1416615162 float BRIPOW = 1; // 0.5f; // 0.5f;
1416715163
14168
- void keyPressed(int key)
15164
+ public void keyPressed(int key)
1416915165 {
1417015166 if (key >= '0' && key <= '5')
1417115167 clampbit = (key-'0');
....@@ -14212,7 +15208,8 @@
1421215208 // break;
1421315209 case 'T':
1421415210 CACHETEXTURE ^= true;
14215
- textures.clear();
15211
+ texturepigment.clear();
15212
+ texturebump.clear();
1421615213 // repaint();
1421715214 break;
1421815215 case 'Y':
....@@ -14297,7 +15294,9 @@
1429715294 case 'E' : COMPACT ^= true;
1429815295 repaint();
1429915296 break;
14300
- case 'W' : DEBUGHSB ^= true;
15297
+ case 'W' : // Wide Window (fullscreen)
15298
+ //DEBUGHSB ^= true;
15299
+ ObjEditor.theFrame.ToggleFullScreen();
1430115300 repaint();
1430215301 break;
1430315302 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14322,8 +15321,8 @@
1432215321 RevertCamera();
1432315322 repaint();
1432415323 break;
14325
- case 'L':
1432615324 case 'l':
15325
+ //case 'L':
1432715326 if (lightMode)
1432815327 {
1432915328 lightMode = false;
....@@ -14387,20 +15386,24 @@
1438715386 OCCLUSION_CULLING ^= true;
1438815387 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1438915388 break;
14390
- case '0': envyoff ^= true; repaint(); break;
15389
+ //case '0': envyoff ^= true; repaint(); break;
1439115390 case '1':
1439215391 case '2':
1439315392 case '3':
1439415393 case '4':
1439515394 case '5':
14396
- newenvy = Character.getNumericValue(key);
14397
- repaint();
14398
- break;
1439915395 case '6':
1440015396 case '7':
1440115397 case '8':
1440215398 case '9':
14403
- BGcolor = (key - '6')/3.f;
15399
+ if (true) // envyoff)
15400
+ {
15401
+ BGcolor = (key - '1')/8.f;
15402
+ }
15403
+ else
15404
+ {
15405
+ //newenvy = Character.getNumericValue(key);
15406
+ }
1440415407 repaint();
1440515408 break;
1440615409 case '!':
....@@ -14466,9 +15469,9 @@
1446615469 case '_':
1446715470 kompactbit = 5;
1446815471 break;
14469
- case '+':
14470
- kompactbit = 6;
14471
- break;
15472
+// case '+':
15473
+// kompactbit = 6;
15474
+// break;
1447215475 case ' ':
1447315476 lightMode ^= true;
1447415477 Globals.lighttouched = true;
....@@ -14480,13 +15483,14 @@
1448015483 case ESC:
1448115484 RENDERPROGRAM += 1;
1448215485 RENDERPROGRAM %= 3;
15486
+
1448315487 repaint();
1448415488 break;
1448515489 case 'Z':
1448615490 //RESIZETEXTURE ^= true;
1448715491 //break;
1448815492 case 'z':
14489
- RENDERSHADOW ^= true;
15493
+ Globals.RENDERSHADOW ^= true;
1449015494 Globals.lighttouched = true;
1449115495 repaint();
1449215496 break;
....@@ -14519,8 +15523,9 @@
1451915523 case DELETE:
1452015524 ClearSelection();
1452115525 break;
14522
- /*
1452315526 case '+':
15527
+
15528
+ /*
1452415529 //fontsize += 1;
1452515530 bbzoom *= 2;
1452615531 repaint();
....@@ -14537,17 +15542,17 @@
1453715542 case '=':
1453815543 IncDepth();
1453915544 //fontsize += 1;
14540
- object.editWindow.refreshContents(true);
15545
+ object.GetWindow().refreshContents(true);
1454115546 maskbit = 6;
1454215547 break;
1454315548 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1454415549 DecDepth();
1454515550 maskbit = 5;
1454615551 //if(fontsize > 1) fontsize -= 1;
14547
- if (object.editWindow == null)
14548
- new Exception().printStackTrace();
14549
- else
14550
- object.editWindow.refreshContents(true);
15552
+// if (object.editWindow == null)
15553
+// new Exception().printStackTrace();
15554
+// else
15555
+ object.GetWindow().refreshContents(true);
1455115556 break;
1455215557 case '{':
1455315558 manipCamera.shaper_fovy /= 1.1;
....@@ -14602,6 +15607,7 @@
1460215607 }
1460315608 //System.out.println("shaper_fovy = " + manipCamera.shaper_fovy);
1460415609 }
15610
+
1460515611 static double OCCLUSIONBOOST = 1; // 0.5;
1460615612
1460715613 void keyReleased(int key, int modifiers)
....@@ -14609,11 +15615,11 @@
1460915615 //mode = ROTATE;
1461015616 if ((MODIFIERS & COMMAND) == 0) // VR??
1461115617 {
14612
- SetMouseMode(modifiers);
15618
+ SetMouseMode(0, modifiers);
1461315619 }
1461415620 }
1461515621
14616
- protected void processKeyEvent(KeyEvent e)
15622
+ public void processKeyEvent(KeyEvent e)
1461715623 {
1461815624 switch (e.getID())
1461915625 {
....@@ -14743,8 +15749,9 @@
1474315749
1474415750 protected void processMouseMotionEvent(MouseEvent e)
1474515751 {
14746
- //System.out.println("processMouseMotionEvent: " + mouseMode);
14747
- if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15752
+ //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
15753
+ //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15754
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1474815755 {
1474915756 mouseMoved(e);
1475015757 } else
....@@ -14769,11 +15776,12 @@
1476915776 }
1477015777 */
1477115778
14772
- object.editWindow.EditSelection();
15779
+ object.GetWindow().EditSelection(false);
1477315780 }
1477415781
1477515782 void SelectParent()
1477615783 {
15784
+ new Exception().printStackTrace();
1477715785 System.exit(0);
1477815786 Composite group = (Composite) object;
1477915787 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -14785,10 +15793,10 @@
1478515793 {
1478615794 //selectees.remove(i);
1478715795 System.out.println("select parent of " + elem);
14788
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15796
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1478915797 } else
1479015798 {
14791
- group.editWindow.Select(elem.GetTreePath(), first, true);
15799
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1479215800 }
1479315801
1479415802 first = false;
....@@ -14797,6 +15805,7 @@
1479715805
1479815806 void SelectChildren()
1479915807 {
15808
+ new Exception().printStackTrace();
1480015809 System.exit(0);
1480115810 /*
1480215811 Composite group = (Composite) object;
....@@ -14829,12 +15838,12 @@
1482915838 for (int j = 0; j < group.children.size(); j++)
1483015839 {
1483115840 elem = (Object3D) group.children.elementAt(j);
14832
- object.editWindow.Select(elem.GetTreePath(), first, true);
15841
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1483315842 first = false;
1483415843 }
1483515844 } else
1483615845 {
14837
- object.editWindow.Select(elem.GetTreePath(), first, true);
15846
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1483815847 }
1483915848
1484015849 first = false;
....@@ -14845,21 +15854,21 @@
1484515854 {
1484615855 //Composite group = (Composite) object;
1484715856 Object3D group = object;
14848
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15857
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1484915858 }
1485015859
1485115860 void ResetTransform(int mask)
1485215861 {
1485315862 //Composite group = (Composite) object;
1485415863 Object3D group = object;
14855
- group.editWindow.ResetTransform(mask);
15864
+ group.GetWindow().ResetTransform(mask);
1485615865 }
1485715866
1485815867 void FlipTransform()
1485915868 {
1486015869 //Composite group = (Composite) object;
1486115870 Object3D group = object;
14862
- group.editWindow.FlipTransform();
15871
+ group.GetWindow().FlipTransform();
1486315872 // group.editWindow.ReduceMesh(true);
1486415873 }
1486515874
....@@ -14867,7 +15876,7 @@
1486715876 {
1486815877 //Composite group = (Composite) object;
1486915878 Object3D group = object;
14870
- group.editWindow.PrintMemory();
15879
+ group.GetWindow().PrintMemory();
1487115880 // group.editWindow.ReduceMesh(true);
1487215881 }
1487315882
....@@ -14875,7 +15884,7 @@
1487515884 {
1487615885 //Composite group = (Composite) object;
1487715886 Object3D group = object;
14878
- group.editWindow.ResetCentroid();
15887
+ group.GetWindow().ResetCentroid();
1487915888 }
1488015889
1488115890 void IncDepth()
....@@ -14957,11 +15966,11 @@
1495715966
1495815967 int width = getBounds().width;
1495915968 int height = getBounds().height;
14960
- ClickInfo info = new ClickInfo();
14961
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1496215969 //Image img = CreateImage(width, height);
1496315970 //System.out.println("width = " + width + "; height = " + height + "\n");
15971
+
1496415972 Graphics gr = g; // img.getGraphics();
15973
+
1496515974 if (!hasMarquee)
1496615975 {
1496715976 if (Xmin < Xmax) // !locked)
....@@ -15033,40 +16042,88 @@
1503316042 }
1503416043 if (object != null && !hasMarquee)
1503516044 {
16045
+ if (object.clickInfo == null)
16046
+ object.clickInfo = new ClickInfo();
16047
+ ClickInfo info = object.clickInfo;
16048
+ //ClickInfo info = new ClickInfo();
16049
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16050
+
1503616051 if (isRenderer)
1503716052 {
15038
- info.flags++;
16053
+ object.clickInfo.flags++;
1503916054 double frameAspect = (double) width / (double) height;
1504016055 if (frameAspect > renderCamera.aspect)
1504116056 {
1504216057 int desired = (int) ((double) height * renderCamera.aspect);
15043
- info.bounds.width -= width - desired;
15044
- info.bounds.x += (width - desired) / 2;
16058
+ object.clickInfo.bounds.width -= width - desired;
16059
+ object.clickInfo.bounds.x += (width - desired) / 2;
1504516060 } else
1504616061 {
1504716062 int desired = (int) ((double) width / renderCamera.aspect);
15048
- info.bounds.height -= height - desired;
15049
- info.bounds.y += (height - desired) / 2;
16063
+ object.clickInfo.bounds.height -= height - desired;
16064
+ object.clickInfo.bounds.y += (height - desired) / 2;
1505016065 }
1505116066 }
15052
- info.g = gr;
15053
- info.camera = renderCamera;
16067
+
16068
+ object.clickInfo.g = gr;
16069
+ object.clickInfo.camera = renderCamera;
1505416070 /*
1505516071 // Memory intensive (brep.verticescopy)
1505616072 if (!(object instanceof Composite))
1505716073 object.draw(info, 0, false); // SLOW :
1505816074 */
15059
- if (!isRenderer)
16075
+ if (!isRenderer) // && drag)
1506016076 {
15061
- object.drawEditHandles(info, 0);
16077
+ Grafreed.Assert(object != null);
16078
+ Grafreed.Assert(object.selection != null);
16079
+ if (object.selection.Size() > 0)
16080
+ {
16081
+ int hitSomething = object.selection.get(0).hitSomething;
16082
+
16083
+ object.clickInfo.DX = 0;
16084
+ object.clickInfo.DY = 0;
16085
+ object.clickInfo.W = 1;
16086
+ if (hitSomething == Object3D.hitCenter)
16087
+ {
16088
+ info.DX = X;
16089
+ if (X != 0)
16090
+ info.DX -= info.bounds.width/2;
16091
+
16092
+ info.DY = Y;
16093
+ if (Y != 0)
16094
+ info.DY -= info.bounds.height/2;
16095
+ }
16096
+
16097
+ object.drawEditHandles(//info,
16098
+ 0);
16099
+
16100
+ if (drag && (X != 0 || Y != 0))
16101
+ {
16102
+ switch (hitSomething)
16103
+ {
16104
+ case Object3D.hitCenter: gr.setColor(Color.pink);
16105
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16106
+ break;
16107
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16108
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16109
+ break;
16110
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16111
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16112
+ break;
16113
+ }
16114
+
16115
+ }
16116
+ }
1506216117 }
1506316118 }
16119
+
1506416120 if (isRenderer)
1506516121 {
1506616122 //gr.setColor(Color.black);
1506716123 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1506816124 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1506916125 }
16126
+
1507016127 if (hasMarquee)
1507116128 {
1507216129 gr.setXORMode(Color.white);
....@@ -15179,6 +16236,7 @@
1517916236 public boolean mouseDown(Event evt, int x, int y)
1518016237 {
1518116238 System.out.println("mouseDown: " + evt);
16239
+ System.exit(0);
1518216240 /*
1518316241 locked = true;
1518416242 drag = false;
....@@ -15222,7 +16280,7 @@
1522216280 {
1522316281 keyPressed(0, modifiers);
1522416282 }
15225
- clickStart(x, y, modifiers);
16283
+ // clickStart(x, y, modifiers);
1522616284 return true;
1522716285 }
1522816286
....@@ -15340,7 +16398,7 @@
1534016398 {
1534116399 keyReleased(0, 0);
1534216400 }
15343
- drag(x, y, modifiers);
16401
+ drag(x, y, 0, modifiers);
1534416402 return true;
1534516403 }
1534616404
....@@ -15472,7 +16530,7 @@
1547216530 Object3D object;
1547316531 static Object3D trackedobject;
1547416532 Camera renderCamera; // Light or Eye (or Occlusion)
15475
- /*static*/ Camera manipCamera; // Light or Eye
16533
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1547616534 /*static*/ Camera eyeCamera;
1547716535 /*static*/ Camera lightCamera;
1547816536 int cameracount;
....@@ -15536,6 +16594,8 @@
1553616594 private /*static*/ boolean firstime;
1553716595 private /*static*/ cVector newView = new cVector();
1553816596 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16597
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16598
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1553916599 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1554016600 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1554116601 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -15548,29 +16608,67 @@
1554816608 {
1554916609 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1555016610
16611
+ int usedsuf = 0;
16612
+
1555116613 for (int i = 0; i < suffixes.length; i++)
1555216614 {
15553
- String resourceName = basename + suffixes[i] + "." + suffix;
15554
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
15555
- mipmapped,
15556
- FileUtil.getFileSuffix(resourceName));
15557
- if (data == null)
16615
+ String[] suffixe = suffixes;
16616
+ String[] fallback = suffixes2;
16617
+ String[] fallfallback = suffixes3;
16618
+
16619
+ for (int c=usedsuf; --c>=0;)
1555816620 {
15559
- throw new IOException("Unable to load texture " + resourceName);
16621
+// String[] temp = suffixe;
16622
+// suffixe = fallback;
16623
+// fallback = fallfallback;
16624
+// fallfallback = temp;
1556016625 }
16626
+
16627
+ String resourceName = basename + suffixe[i] + "." + suffix;
16628
+ TextureData data;
16629
+
16630
+ try
16631
+ {
16632
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16633
+ mipmapped,
16634
+ FileUtil.getFileSuffix(resourceName));
16635
+ }
16636
+ catch (Exception e)
16637
+ {
16638
+ try
16639
+ {
16640
+ resourceName = basename + fallback[i] + "." + suffix;
16641
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16642
+ mipmapped,
16643
+ FileUtil.getFileSuffix(resourceName));
16644
+ }
16645
+ catch (Exception e2)
16646
+ {
16647
+ resourceName = basename + fallfallback[i] + "." + suffix;
16648
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16649
+ mipmapped,
16650
+ FileUtil.getFileSuffix(resourceName));
16651
+ }
16652
+ }
16653
+
1556116654 //System.out.println("Target = " + targets[i]);
1556216655 cubemap.updateImage(data, targets[i]);
1556316656 }
1556416657
1556516658 return cubemap;
1556616659 }
16660
+
1556716661 int bigsphere = -1;
1556816662
1556916663 float BGcolor = 0.5f;
1557016664
15571
- private void DrawSkyBox(GL gl)
16665
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16666
+
16667
+ private void DrawSkyBox(GL gl, float ratio)
1557216668 {
15573
- if (envyoff || cubemap == null)
16669
+ if (//envyoff ||
16670
+ WIREFRAME ||
16671
+ cubemap == null)
1557416672 {
1557516673 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1557616674 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -15585,7 +16683,17 @@
1558516683 // Compensates for ExaminerViewer's modification of modelview matrix
1558616684 gl.glMatrixMode(GL.GL_MODELVIEW);
1558716685 gl.glLoadIdentity();
16686
+ gl.glScalef(1,ratio,1);
1558816687
16688
+// colorV[0] = 2;
16689
+// colorV[1] = 2;
16690
+// colorV[2] = 2;
16691
+// colorV[3] = 1;
16692
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16693
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16694
+//
16695
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16696
+
1558916697 //gl.glActiveTexture(GL.GL_TEXTURE1);
1559016698 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1559116699
....@@ -15617,6 +16725,7 @@
1561716725 {
1561816726 gl.glScalef(1.0f, -1.0f, 1.0f);
1561916727 }
16728
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1562016729 gl.glMultMatrixd(viewrot_1, 0);
1562116730 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1562216731 //viewer.updateInverseRotation(gl);
....@@ -15757,16 +16866,16 @@
1575716866 cStatic.objectstack[materialdepth++] = checker;
1575816867 //System.out.println("material " + material);
1575916868 //Applet3D.tracein(this, selected);
15760
- vector2buffer = checker.projectedVertices;
16869
+ //vector2buffer = checker.projectedVertices;
1576116870
1576216871 //checker.GetMaterial().Draw(this, false); // true);
15763
- DrawMaterial(checker.GetMaterial(), false); // true);
16872
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1576416873
1576516874 materialdepth -= 1;
1576616875 if (materialdepth > 0)
1576716876 {
15768
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
15769
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
16877
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16878
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1577016879 }
1577116880 //checker.GetMaterial().opacity = 1f;
1577216881 ////checker.GetMaterial().ambient = 1f;
....@@ -15852,6 +16961,14 @@
1585216961 }
1585316962 }
1585416963
16964
+ private Object3D GetFolder()
16965
+ {
16966
+ Object3D folder = object.GetWindow().copy;
16967
+ if (object.GetWindow().copy.selection.Size() > 0)
16968
+ folder = object.GetWindow().copy.selection.elementAt(0);
16969
+ return folder;
16970
+ }
16971
+
1585516972 class SelectBuffer implements GLEventListener
1585616973 {
1585716974
....@@ -15867,7 +16984,7 @@
1586716984 //new Exception().printStackTrace();
1586816985 System.out.println("select buffer init");
1586916986 // Use debug pipeline
15870
- drawable.setGL(new DebugGL(drawable.getGL()));
16987
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1587116988
1587216989 GL gl = drawable.getGL();
1587316990
....@@ -15910,6 +17027,7 @@
1591017027 {
1591117028 if (!selection)
1591217029 {
17030
+ new Exception().printStackTrace();
1591317031 System.exit(0);
1591417032 return;
1591517033 }
....@@ -15930,6 +17048,17 @@
1593017048
1593117049 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1593217050
17051
+ if (PAINTMODE)
17052
+ {
17053
+ if (object.GetWindow().copy.selection.Size() > 0)
17054
+ {
17055
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17056
+
17057
+ // Make what you paint not selectable.
17058
+ paintobj.ResetSelectable();
17059
+ }
17060
+ }
17061
+
1593317062 //int tmp = selection_view;
1593417063 //selection_view = -1;
1593517064 int temp = DrawMode();
....@@ -15941,6 +17070,17 @@
1594117070 // temp = DEFAULT; // patch for selection debug
1594217071 Globals.drawMode = temp; // WARNING
1594317072
17073
+ if (PAINTMODE)
17074
+ {
17075
+ if (object.GetWindow().copy.selection.Size() > 0)
17076
+ {
17077
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17078
+
17079
+ // Revert.
17080
+ paintobj.RestoreSelectable();
17081
+ }
17082
+ }
17083
+
1594417084 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1594517085
1594617086 // trying different ways of getting the depth info over
....@@ -15988,6 +17128,8 @@
1598817128 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1598917129 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1599017130 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
17131
+
17132
+ CreateSelectedPoint();
1599117133
1599217134 // Will fit the mesh !!!
1599317135 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16037,34 +17179,36 @@
1603717179 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]));
1603817180 }
1603917181
16040
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
17182
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1604117183 }
1604217184 }
1604317185
1604417186 if (!movingcamera && !PAINTMODE)
16045
- object.editWindow.ScreenFitPoint(); // fev 2014
17187
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1604617188
16047
- if (PAINTMODE && GrafreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17189
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1604817190 {
16049
- Object3D paintobj = GrafreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17191
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1605017192
16051
- Object3D group = new Object3D("inst" + paintcount++);
17193
+ if (object.GetWindow().copy.selection.Size() > 0)
17194
+ {
17195
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1605217196
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();
17197
+ Object3D inst = new Object3D("inst" + paintcount++);
17198
+
17199
+ inst.CreateMaterial(); // use a void leaf to select instances
17200
+
17201
+ inst.add(paintobj); // link
17202
+
17203
+ object.GetWindow().SnapObject(inst);
17204
+
17205
+ Object3D folder = paintFolder; // GetFolder();
17206
+
17207
+ folder.add(inst);
17208
+
17209
+ object.GetWindow().ResetModel();
17210
+ object.GetWindow().refreshContents();
17211
+ }
1606817212 }
1606917213 else
1607017214 paintcount = 0;
....@@ -16103,6 +17247,11 @@
1610317247 //System.out.println("objects[color] = " + objects[color]);
1610417248 //objects[color].Select();
1610517249 indexcount = 0;
17250
+ ObjEditor window = object.GetWindow();
17251
+ if (window != null && deselect)
17252
+ {
17253
+ window.Select(null, deselect, true);
17254
+ }
1610617255 object.Select(color, deselect);
1610717256 }
1610817257
....@@ -16202,7 +17351,7 @@
1620217351 gl.glDisable(gl.GL_CULL_FACE);
1620317352 }
1620417353
16205
- if (!RENDERSHADOW)
17354
+ if (!Globals.RENDERSHADOW)
1620617355 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1620717356
1620817357 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -16212,7 +17361,7 @@
1621217361 //gl.glColorMask(false, false, false, false);
1621317362
1621417363 //render_scene_from_light_view(gl, drawable, 0, 0);
16215
- if (RENDERSHADOW && Globals.lighttouched && !movingcamera) // && !parent.IsFreezed())
17364
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1621617365 {
1621717366 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1621817367
....@@ -16628,23 +17777,15 @@
1662817777 int AAbuffersize = 0;
1662917778
1663017779 //double[] selectedpoint = new double[3];
16631
- static Superellipsoid selectedpoint = new Superellipsoid();
17780
+ static Superellipsoid selectedpoint;
1663217781 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();
17782
+ static Sphere debugpointG;
17783
+ static Sphere debugpointP;
17784
+ static Sphere debugpointC;
17785
+ static Sphere debugpointR;
1663717786
1663817787 static Sphere debugpoints[] = new Sphere[8];
1663917788
16640
- static
16641
- {
16642
- for (int i=0; i<8; i++)
16643
- {
16644
- debugpoints[i] = new Sphere();
16645
- }
16646
- }
16647
-
1664817789 static void InitPoints(float radius)
1664917790 {
1665017791 for (int i=0; i<8; i++)
....@@ -16696,10 +17837,11 @@
1669617837 static IntBuffer textbuffer = null; // IntBuffer.allocate(TEXT_WIDTH*8*8 * TEXT_HEIGHT);
1669717838 // Depth buffer format
1669817839 //private int depth_format;
16699
- static public void NextIndex(Object3D o, GL gl)
17840
+
17841
+ public void NextIndex()
1670017842 {
1670117843 indexcount+=16;
16702
- gl.glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
17844
+ GetGL().glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
1670317845 //objects[indexcount] = o;
1670417846 //System.out.println("indexcount = " + indexcount);
1670517847 }