Normand Briere
2019-08-18 66aca73cce89e4b4d7521862760edf4b0888bc38
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;
....@@ -76,7 +110,11 @@
76110 //private Mat4f spotlightTransform = new Mat4f();
77111 //private Mat4f spotlightInverseTransform = new Mat4f();
78112 static GLContext glcontext = null;
79
- /*static*/ com.sun.opengl.util.texture.Texture cubemap;
113
+ /*static*/ com.sun.opengl.util.texture.Texture cubemap; // Either custom or rgb
114
+ /*static*/ com.sun.opengl.util.texture.Texture cubemapcustom;
115
+ /*static*/ com.sun.opengl.util.texture.Texture cubemaprgb;
116
+ boolean transformMode;
117
+
80118 boolean reverseUP = false;
81119 static boolean frozen = false;
82120 boolean enablebackspace = false; // patch for back buffer refresh
....@@ -92,6 +130,8 @@
92130
93131 static int tickcount = 0; // slow pose issue
94132
133
+static boolean BUTTONLESSWHEEL = false;
134
+static boolean ZOOMBOXMODE = false;
95135 static boolean BOXMODE = false;
96136 static boolean IMAGEFLIP = false;
97137 static boolean SMOOTHFOCUS = false;
....@@ -106,7 +146,7 @@
106146 static boolean OEIL = true;
107147 static boolean OEILONCE = false; // do oeilon then oeiloff
108148 static boolean LOOKAT = true;
109
-static boolean RANDOM = true; // false;
149
+static boolean SWITCH = true; // false;
110150 static boolean HANDLES = false; // selection doesn't work!!
111151 static boolean PAINTMODE = false;
112152
....@@ -128,7 +168,7 @@
128168
129169
130170 // OPTIONS
131
- boolean Skinshader = true;
171
+ boolean Skinshader = false; // true;
132172 boolean cameraLight = false;
133173 boolean UVdebug = false;
134174 boolean Udebug = false;
....@@ -137,7 +177,7 @@
137177 static boolean doublesided = false; // true; // reversed normals are awful for conformance
138178 boolean anisotropy = true;
139179 boolean softshadow = true; // slower but better false;
140
- boolean opacityhalo = false;
180
+ boolean opacityhalo = false; // reverse the halo effect (e.g. glass)
141181
142182 boolean macromode = false;
143183
....@@ -148,6 +188,21 @@
148188 defaultcaps.setAccumGreenBits(16);
149189 defaultcaps.setAccumBlueBits(16);
150190 defaultcaps.setAccumAlphaBits(16);
191
+ }
192
+
193
+ private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
194
+
195
+ public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException
196
+ {
197
+ try
198
+ {
199
+ return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
200
+ } catch (IOException e)
201
+ {
202
+ System.out.println("NAME = " + name);
203
+ e.printStackTrace(); // throw new RuntimeException(e);
204
+ return null;
205
+ }
151206 }
152207
153208 void SetAsGLRenderer(boolean b)
....@@ -168,7 +223,8 @@
168223
169224 SetCamera(cam);
170225
171
- SetLight(new Camera(new cVector(10, 10, -20)));
226
+ // Warning: not used.
227
+ SetLight(new Camera(new cVector(15, 10, -20)));
172228
173229 object = o;
174230
....@@ -191,9 +247,43 @@
191247
192248 /// INTERFACE
193249
250
+ public javax.media.opengl.GL GetGL0()
251
+ {
252
+ return null;
253
+ }
254
+
255
+ public int GenList()
256
+ {
257
+ javax.media.opengl.GL gl = GetGL();
258
+ return gl.glGenLists(1);
259
+ }
260
+
261
+ public void NewList(int id)
262
+ {
263
+ javax.media.opengl.GL gl = GetGL();
264
+ gl.glNewList(id, gl.GL_COMPILE); //_AND_EXECUTE);
265
+ }
266
+
267
+ public void CallList(int id)
268
+ {
269
+ javax.media.opengl.GL gl = GetGL();
270
+ gl.glCallList(id);
271
+ }
272
+
273
+ public void EndList()
274
+ {
275
+ javax.media.opengl.GL gl = GetGL();
276
+ gl.glEndList();
277
+ }
278
+
194279 public boolean IsBoxMode()
195280 {
196281 return BOXMODE;
282
+ }
283
+
284
+ public boolean IsZoomBoxMode()
285
+ {
286
+ return ZOOMBOXMODE;
197287 }
198288
199289 public void ClearDepth()
....@@ -291,7 +381,7 @@
291381 cStatic.objectstack[materialdepth++] = obj;
292382 //System.out.println("material " + material);
293383 //Applet3D.tracein(this, selected);
294
- display.vector2buffer = obj.projectedVertices;
384
+ //display.vector2buffer = obj.projectedVertices;
295385 if (obj instanceof Camera)
296386 {
297387 display.options1[0] = material.shift;
....@@ -300,14 +390,28 @@
300390 display.options1[2] = material.shadowbias;
301391 display.options1[3] = material.aniso;
302392 display.options1[4] = material.anisoV;
393
+// System.out.println("display.options1[0] " + display.options1[0]);
394
+// System.out.println("display.options1[1] " + display.options1[1]);
395
+// System.out.println("display.options1[2] " + display.options1[2]);
396
+// System.out.println("display.options1[3] " + display.options1[3]);
397
+// System.out.println("display.options1[4] " + display.options1[4]);
303398 display.options2[0] = material.opacity;
304399 display.options2[1] = material.diffuse;
305400 display.options2[2] = material.factor;
401
+// System.out.println("display.options2[0] " + display.options2[0]);
402
+// System.out.println("display.options2[1] " + display.options2[1]);
403
+// System.out.println("display.options2[2] " + display.options2[2]);
306404
307405 cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
406
+// System.out.println("display.options3[0] " + display.options3[0]);
407
+// System.out.println("display.options3[1] " + display.options3[1]);
408
+// System.out.println("display.options3[2] " + display.options3[2]);
308409 display.options4[0] = material.cameralight/0.2f;
309410 display.options4[1] = material.subsurface;
310411 display.options4[2] = material.sheen;
412
+// System.out.println("display.options4[0] " + display.options4[0]);
413
+// System.out.println("display.options4[1] " + display.options4[1]);
414
+// System.out.println("display.options4[2] " + display.options4[2]);
311415
312416 // if (display.CURRENTANTIALIAS > 0)
313417 // display.options3[3] /= 4;
....@@ -323,7 +427,7 @@
323427 /**/
324428 } else
325429 {
326
- DrawMaterial(material, selected);
430
+ DrawMaterial(material, selected, obj.projectedVertices);
327431 }
328432 } else
329433 {
....@@ -347,8 +451,8 @@
347451 cStatic.objectstack[materialdepth++] = obj;
348452 //System.out.println("material " + material);
349453 //Applet3D.tracein("selected ", selected);
350
- display.vector2buffer = obj.projectedVertices;
351
- display.DrawMaterial(material, selected);
454
+ //display.vector2buffer = obj.projectedVertices;
455
+ display.DrawMaterial(material, selected, obj.projectedVertices);
352456 }
353457 }
354458
....@@ -365,8 +469,8 @@
365469 materialdepth -= 1;
366470 if (materialdepth > 0)
367471 {
368
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
369
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
472
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
473
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
370474 }
371475 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
372476 } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
....@@ -386,8 +490,8 @@
386490 materialdepth -= 1;
387491 if (materialdepth > 0)
388492 {
389
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
390
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
493
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
494
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
391495 }
392496 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
393497 //else
....@@ -428,10 +532,12 @@
428532 if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
429533 {
430534 //gl.glBegin(gl.GL_TRIANGLES);
431
- boolean hasnorm = pv.norm != null; // && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0);
535
+ boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0)
536
+ // TEST LIVE NORMALS && !obj.dontselect
537
+ ;
432538 if (!hasnorm)
433539 {
434
- // System.out.println("FUCK!!");
540
+ // System.out.println("Mesh normal");
435541 LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
436542 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
437543 LA.vecCross(obj.v0, obj.v1, obj.v2);
....@@ -1059,8 +1165,345 @@
10591165 gl.glMatrixMode(gl.GL_MODELVIEW);
10601166 }
10611167
1168
+ public void DrawBox(cVector min, cVector max)
1169
+ {
1170
+ javax.media.opengl.GL gl = GetGL();
1171
+ gl.glBegin(gl.GL_LINES);
1172
+
1173
+ gl.glVertex3d(min.x, min.y, min.z);
1174
+ gl.glVertex3d(min.x, min.y, max.z);
1175
+ gl.glVertex3d(min.x, min.y, min.z);
1176
+ gl.glVertex3d(min.x, max.y, min.z);
1177
+ gl.glVertex3d(min.x, min.y, min.z);
1178
+ gl.glVertex3d(max.x, min.y, min.z);
1179
+
1180
+ gl.glVertex3d(max.x, max.y, max.z);
1181
+ gl.glVertex3d(min.x, max.y, max.z);
1182
+ gl.glVertex3d(max.x, max.y, max.z);
1183
+ gl.glVertex3d(max.x, min.y, max.z);
1184
+ gl.glVertex3d(max.x, max.y, max.z);
1185
+ gl.glVertex3d(max.x, max.y, min.z);
1186
+
1187
+ gl.glEnd();
1188
+ }
1189
+
1190
+ public void DrawGeometry(BoundaryRep bRep, boolean flipV, boolean selectmode)
1191
+ {
1192
+ int[] strips = bRep.getRawIndices();
1193
+
1194
+ javax.media.opengl.GL gl = GetGL();
1195
+
1196
+ // TRIANGLE STRIP ARRAY
1197
+ if (bRep.trimmed)
1198
+ {
1199
+ float[] v = bRep.getRawVertices();
1200
+ float[] n = bRep.getRawNormals();
1201
+ float[] c = bRep.getRawColors();
1202
+ float[] uv = bRep.getRawUVMap();
1203
+
1204
+ int count2 = 0;
1205
+ int count3 = 0;
1206
+
1207
+ if (n.length > 0)
1208
+ {
1209
+ for (int i = 0; i < strips.length; i++)
1210
+ {
1211
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1212
+
1213
+ /*
1214
+ boolean locked = false;
1215
+ float eps = 0.1f;
1216
+ boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
1217
+
1218
+ int dot = 0;
1219
+
1220
+ if ((dot&1) == 0)
1221
+ dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
1222
+
1223
+ if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
1224
+ gl.glTexCoord2f((float) qv.s, (float) qv.t);
1225
+ else
1226
+ {
1227
+ locked = true;
1228
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1229
+ }
1230
+ //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
1231
+ gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
1232
+ if (hasnorm)
1233
+ {
1234
+ //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
1235
+ gl.glNormal3f((float) rv.norm.x, (float) rv.norm.y, (float) rv.norm.z);
1236
+ }
1237
+
1238
+ if ((dot&4) == 0)
1239
+ dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
1240
+
1241
+ if (wrap || !locked && (dot&8) != 0)
1242
+ gl.glTexCoord2f((float) rv.s, (float) rv.t);
1243
+ else
1244
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1245
+
1246
+ f.dot = dot;
1247
+ */
1248
+
1249
+ if (!selectmode)
1250
+ {
1251
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1252
+ {
1253
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1254
+ } else
1255
+ {
1256
+ gl.glNormal3f(0, 0, 1);
1257
+ }
1258
+
1259
+ if (c != null)
1260
+ //System.out.println("glcolor = " + c[count3] + ", " + c[count3+1] + ", " + c[count3+2]);
1261
+ {
1262
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1263
+ }
1264
+ }
1265
+
1266
+ if (flipV)
1267
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1268
+ else
1269
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1270
+
1271
+ //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1272
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1273
+
1274
+ count2 += 2;
1275
+ count3 += 3;
1276
+ if (!selectmode)
1277
+ {
1278
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1279
+ {
1280
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1281
+ } else
1282
+ {
1283
+ gl.glNormal3f(0, 0, 1);
1284
+ }
1285
+ if (c != null)
1286
+ {
1287
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1288
+ }
1289
+ }
1290
+
1291
+ if (flipV)
1292
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1293
+ else
1294
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1295
+
1296
+ //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1297
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1298
+
1299
+ count2 += 2;
1300
+ count3 += 3;
1301
+ for (int j = 0; j < strips[i] - 2; j++)
1302
+ {
1303
+ //gl.glTexCoord2d(...);
1304
+ if (!selectmode)
1305
+ {
1306
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1307
+ {
1308
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1309
+ } else
1310
+ {
1311
+ gl.glNormal3f(0, 0, 1);
1312
+ }
1313
+ if (c != null)
1314
+ {
1315
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1316
+ }
1317
+ }
1318
+
1319
+ if (flipV)
1320
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1321
+ else
1322
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1323
+
1324
+ //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
1325
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1326
+
1327
+ count2 += 2;
1328
+ count3 += 3;
1329
+ }
1330
+
1331
+ gl.glEnd();
1332
+ }
1333
+ }
1334
+
1335
+ assert count3 == v.length;
1336
+ }
1337
+ else // !trimmed
1338
+ {
1339
+ int count = 0;
1340
+ for (int i = 0; i < strips.length; i++)
1341
+ {
1342
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1343
+
1344
+ Vertex p = bRep.GetVertex(bRep.indices[count++]);
1345
+ Vertex q = bRep.GetVertex(bRep.indices[count++]);
1346
+
1347
+ drawVertex(gl, p, flipV, selectmode);
1348
+ drawVertex(gl, q, flipV, selectmode);
1349
+
1350
+ for (int j = 0; j < strips[i] - 2; j++)
1351
+ {
1352
+ Vertex r = bRep.GetVertex(bRep.indices[count++]);
1353
+
1354
+ // if (j%2 == 0)
1355
+ // drawFace(p, q, r, display, null);
1356
+ // else
1357
+ // drawFace(p, r, q, display, null);
1358
+
1359
+ // p = q;
1360
+ // q = r;
1361
+ drawVertex(gl, r, flipV, selectmode);
1362
+ }
1363
+
1364
+ gl.glEnd();
1365
+ }
1366
+ }
1367
+ }
1368
+
1369
+ static cSpring.Point3D temp = new cSpring.Point3D();
1370
+ static cSpring.Point3D temp2 = new cSpring.Point3D();
1371
+ static cSpring.Point3D temp3 = new cSpring.Point3D();
1372
+
1373
+ public void DrawDynamicMesh(cMesh mesh)
1374
+ {
1375
+ GL gl = GetGL(); // getGL();
1376
+
1377
+ cSpring.PhysicsController3D Phys = mesh.Phys;
1378
+
1379
+ gl.glDisable(gl.GL_LIGHTING);
1380
+
1381
+ gl.glLineWidth(1);
1382
+ gl.glColor3f(1,1,1);
1383
+ gl.glBegin(gl.GL_LINES);
1384
+ double scale = 0;
1385
+ int count = 0;
1386
+ for (int s=0; s<Phys.allSprings.size(); s++)
1387
+ {
1388
+ cSpring.Spring spring = Phys.allSprings.get(s);
1389
+ if(s == 0)
1390
+ {
1391
+ //System.out.println(" spring : " + spring.a.position + "; " + spring.b.position);
1392
+ }
1393
+ if (mesh.showsprings)
1394
+ {
1395
+ temp.set(spring.a.position);
1396
+ temp.add(spring.b.position);
1397
+ temp.mul(0.5);
1398
+ temp2.set(spring.a.position);
1399
+ temp2.sub(spring.b.position);
1400
+ temp2.mul(spring.restLength/2);
1401
+ temp.sub(temp2);
1402
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1403
+ temp.add(temp2);
1404
+ temp.add(temp2);
1405
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1406
+ }
1407
+
1408
+ if (spring.isHandle)
1409
+ continue;
1410
+
1411
+ //if (scale < spring.restLength)
1412
+ scale += spring.restLength;
1413
+ count++;
1414
+ }
1415
+ gl.glEnd();
1416
+
1417
+ if (count == 0)
1418
+ scale = 0.01;
1419
+ else
1420
+ scale /= count * 3;
1421
+
1422
+ //scale = 0.25;
1423
+
1424
+ if (mesh.ShowInfo())
1425
+ {
1426
+ gl.glLineWidth(4);
1427
+ for (int s=0; s<Phys.allNodes.size(); s++)
1428
+ {
1429
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1430
+ if (node.mass == 0)
1431
+ continue;
1432
+
1433
+ int i = node.springs==null?-1:node.springs.size();
1434
+ gl.glColor3f((i>>2)&1,(i>>1)&1,i&1);
1435
+ //temp.set(node.springForce.x, node.springForce.y, node.springForce.z);
1436
+ //temp.normalize();
1437
+ //gl.glColor3d((temp.x+1)/2, (temp.y+1)/2, (temp.z+1)/2);
1438
+ gl.glBegin(gl.GL_LINES);
1439
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1440
+ //gl.glVertex3d(node.position.x + node.normal.x*scale, node.position.y + node.normal.y*scale, node.position.z + node.normal.z*scale);
1441
+ gl.glVertex3d(node.position.x + mesh.bRep.GetVertex(s).norm.x*scale,
1442
+ node.position.y + mesh.bRep.GetVertex(s).norm.y*scale,
1443
+ node.position.z + mesh.bRep.GetVertex(s).norm.z*scale);
1444
+ gl.glEnd();
1445
+ }
1446
+
1447
+ gl.glLineWidth(8);
1448
+ for (int s=0; s<Phys.allNodes.size(); s++)
1449
+ {
1450
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1451
+
1452
+ if (node.springs != null)
1453
+ {
1454
+ for (int i=0; i<node.springs.size(); i+=1)
1455
+ {
1456
+ cSpring.DynamicNode f = node.springs.get(i).GetOther(node);
1457
+
1458
+ int c = i+1;
1459
+ // c = node.springs.get(i).nbcopies;
1460
+
1461
+ gl.glColor3f((c>>2)&1,(c>>1)&1,c&1);
1462
+ gl.glBegin(gl.GL_LINES);
1463
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1464
+ 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);
1465
+ gl.glEnd();
1466
+ }
1467
+ }
1468
+ }
1469
+
1470
+ gl.glLineWidth(1);
1471
+ }
1472
+
1473
+ gl.glEnable(gl.GL_LIGHTING);
1474
+ }
1475
+
10621476 /// INTERFACE
10631477
1478
+ public void StartTriangles()
1479
+ {
1480
+ javax.media.opengl.GL gl = GetGL();
1481
+ gl.glBegin(gl.GL_TRIANGLES);
1482
+ }
1483
+
1484
+ public void EndTriangles()
1485
+ {
1486
+ GetGL().glEnd();
1487
+ }
1488
+
1489
+ void drawVertex(javax.media.opengl.GL gl, Vertex pv, boolean flipV, boolean selectmode)
1490
+ {
1491
+ if (!selectmode)
1492
+ {
1493
+ gl.glNormal3f((float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
1494
+ gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
1495
+
1496
+ if (flipV)
1497
+ gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
1498
+ else
1499
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1500
+ }
1501
+
1502
+ gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
1503
+ }
1504
+
1505
+ float[] colorV = new float[4];
1506
+
10641507 void SetColor(Object3D obj, Vertex p0)
10651508 {
10661509 CameraPane display = this;
....@@ -1128,8 +1571,6 @@
11281571 {
11291572 return;
11301573 }
1131
-
1132
- float[] colorV = new float[3];
11331574
11341575 if (false) // marked)
11351576 {
....@@ -1238,7 +1679,7 @@
12381679 // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
12391680 }
12401681
1241
- void DrawMaterial(cMaterial material, boolean selected)
1682
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
12421683 {
12431684 CameraPane display = this;
12441685 //new Exception().printStackTrace();
....@@ -1254,18 +1695,18 @@
12541695 //col.getColorComponents(ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB), CameraPane.modelParams0);
12551696 if (!material.multiply)
12561697 {
1257
- display.color = color;
1698
+ display.color = material.color;
12581699 display.saturation = material.modulation;
12591700 }
12601701 else
12611702 {
1262
- display.color *= color*2;
1703
+ display.color *= material.color*2;
12631704 display.saturation *= material.modulation*2;
12641705 }
12651706
12661707 cColor.HSBtoRGB(display.color, display.saturation, 1, display.modelParams0);
12671708
1268
- float[] colorV = GrafreeD.colorV;
1709
+ float[] colorV = Grafreed.colorV;
12691710
12701711 /**/
12711712 if (display.DrawMode() == display.DEFAULT) // && display.RENDERPROGRAM == 0)
....@@ -1273,7 +1714,7 @@
12731714 colorV[0] = display.modelParams0[0] * material.diffuse;
12741715 colorV[1] = display.modelParams0[1] * material.diffuse;
12751716 colorV[2] = display.modelParams0[2] * material.diffuse;
1276
- colorV[3] = material.opacity;
1717
+ colorV[3] = 1; // material.opacity;
12771718
12781719 gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
12791720 //System.out.println("Opacity = " + opacity);
....@@ -1381,9 +1822,9 @@
13811822 display.modelParams7[2] = 0;
13821823 display.modelParams7[3] = 0;
13831824
1384
- display.modelParams6[0] = 100; // criss de bug de bump
1825
+ //display.modelParams6[0] = 100; // criss de bug de bump
13851826
1386
- Object3D.cVector2[] extparams = display.vector2buffer;
1827
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
13871828 if (extparams != null && extparams.length > 0 && extparams[0] != null)
13881829 {
13891830 display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
....@@ -1525,7 +1966,7 @@
15251966 void PushMatrix(double[][] matrix)
15261967 {
15271968 // GrafreeD.tracein(matrix);
1528
- PushMatrix(matrix,1);
1969
+ PushMatrix(matrix, 1);
15291970 }
15301971
15311972 void PushMatrix()
....@@ -1611,9 +2052,9 @@
16112052 switch(viewcode)
16122053 {
16132054 case 0: return "main";
1614
- case 1: return "one";
1615
- case 2: return "two";
1616
- case 3: return "three";
2055
+ case 1: return "Red";
2056
+ case 2: return "Green";
2057
+ case 3: return "Blue";
16172058 case 4: return "light";
16182059 }
16192060
....@@ -1679,7 +2120,7 @@
16792120 //System.err.println("Oeil on");
16802121 OEIL = true;
16812122 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
1682
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2123
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
16832124 //pingthread.StepToTarget(true);
16842125 }
16852126
....@@ -1777,7 +2218,7 @@
17772218 System.err.println("LIVE = " + Globals.isLIVE());
17782219
17792220 if (!Globals.isLIVE()) // save sound
1780
- GrafreeD.savesound = true; // wav.save();
2221
+ Grafreed.savesound = true; // wav.save();
17812222 // else
17822223 repaint(); // start loop // may 2013
17832224 }
....@@ -1810,6 +2251,11 @@
18102251 public void ToggleBoxMode()
18112252 {
18122253 BOXMODE ^= true;
2254
+ }
2255
+
2256
+ public void ToggleZoomBoxMode()
2257
+ {
2258
+ ZOOMBOXMODE ^= true;
18132259 }
18142260
18152261 public void ToggleSmoothFocus()
....@@ -1889,7 +2335,7 @@
18892335
18902336 void ToggleDebug()
18912337 {
1892
- DEBUG ^= true;
2338
+ Globals.DEBUG ^= true;
18932339 }
18942340
18952341 void ToggleLookAt()
....@@ -1897,9 +2343,9 @@
18972343 LOOKAT ^= true;
18982344 }
18992345
1900
- void ToggleRandom()
2346
+ void ToggleSwitch()
19012347 {
1902
- RANDOM ^= true;
2348
+ SWITCH ^= true;
19032349 }
19042350
19052351 void ToggleHandles()
....@@ -1907,10 +2353,17 @@
19072353 HANDLES ^= true;
19082354 }
19092355
2356
+ Object3D paintFolder;
2357
+
19102358 void TogglePaint()
19112359 {
19122360 PAINTMODE ^= true;
19132361 paintcount = 0;
2362
+
2363
+ if (PAINTMODE)
2364
+ {
2365
+ paintFolder = GetFolder();
2366
+ }
19142367 }
19152368
19162369 void SwapCamera(int a, int b)
....@@ -2006,7 +2459,22 @@
20062459 {
20072460 return currentGL;
20082461 }
2009
-
2462
+
2463
+ static private BufferedImage CreateBim(TextureData texturedata)
2464
+ {
2465
+ Grafreed.Assert(texturedata != null);
2466
+
2467
+ int width = texturedata.getWidth();
2468
+ int height = texturedata.getHeight();
2469
+
2470
+ Buffer buffer = texturedata.getBuffer();
2471
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2472
+
2473
+ byte[] bytes = bytebuf.array();
2474
+
2475
+ return CreateBim(bytes, width, height);
2476
+ }
2477
+
20102478 /**/
20112479 class CacheTexture
20122480 {
....@@ -2015,28 +2483,31 @@
20152483
20162484 int resolution;
20172485
2018
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2486
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
20192487 {
2020
- texture = tex;
2488
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2489
+ texturedata = texdata;
20212490 resolution = res;
20222491 }
20232492 }
20242493 /**/
20252494
20262495 // TEXTURE static Texture texture;
2027
- static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures
2028
- = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>();
2029
- static public java.util.Hashtable<String, String> usedtextures = new java.util.Hashtable<String, String>();
2496
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2497
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2498
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2499
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2500
+
20302501 int pigmentdepth = 0;
20312502 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
20322503 int bumpdepth = 0;
20332504 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
20342505 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
20352506 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2036
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2507
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
20372508 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
20382509
2039
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2510
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
20402511 {
20412512 TextureData texturedata = null;
20422513
....@@ -2046,7 +2517,7 @@
20462517 com.sun.opengl.util.texture.TextureIO.newTextureData(
20472518 getClass().getClassLoader().getResourceAsStream(name),
20482519 true,
2049
- com.sun.opengl.util.texture.TextureIO.PNG);
2520
+ GetFormat(name)); // com.sun.opengl.util.texture.TextureIO.PNG);
20502521 } catch (java.io.IOException e)
20512522 {
20522523 throw new javax.media.opengl.GLException(e);
....@@ -2055,13 +2526,34 @@
20552526 if (bump)
20562527 texturedata = ConvertBump(texturedata, false);
20572528
2058
- com.sun.opengl.util.texture.Texture texture =
2059
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2529
+// com.sun.opengl.util.texture.Texture texture =
2530
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
20602531
2061
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2062
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
2532
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2533
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
20632534
2064
- return texture;
2535
+ return texturedata;
2536
+ }
2537
+
2538
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2539
+ {
2540
+ TextureData texturedata = null;
2541
+
2542
+ try
2543
+ {
2544
+ texturedata =
2545
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2546
+ bim,
2547
+ true);
2548
+ } catch (Exception e)
2549
+ {
2550
+ throw new javax.media.opengl.GLException(e);
2551
+ }
2552
+
2553
+ if (bump)
2554
+ texturedata = ConvertBump(texturedata, false);
2555
+
2556
+ return texturedata;
20652557 }
20662558
20672559 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3134,6 +3626,8 @@
31343626
31353627 System.out.println("LOADING TEXTURE : " + name);
31363628
3629
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3630
+
31373631 //
31383632 if (false) // compressbit > 0)
31393633 {
....@@ -3838,6 +4332,7 @@
38384332
38394333 com.sun.opengl.util.texture.Texture CompressTexture2(String name)
38404334 {
4335
+ new Exception().printStackTrace();
38414336 System.exit(0);
38424337 com.sun.opengl.util.texture.Texture texture = null;
38434338
....@@ -7531,7 +8026,7 @@
75318026 String pigment = Object3D.GetPigment(tex);
75328027 String bump = Object3D.GetBump(tex);
75338028
7534
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8029
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
75358030 {
75368031 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
75378032 // System.out.println("; bump = " + bump);
....@@ -7546,11 +8041,69 @@
75468041 pigment = null;
75478042 }
75488043
7549
- ReleaseTexture(bump, true);
7550
- ReleaseTexture(pigment, false);
8044
+ ReleaseTexture(tex, true);
8045
+ ReleaseTexture(tex, false);
75518046 }
75528047
7553
- void ReleaseTexture(String tex, boolean bump)
8048
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
8049
+ {
8050
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8051
+ {
8052
+ return;
8053
+ }
8054
+
8055
+ if (tex == null)
8056
+ {
8057
+ ReleaseTexture(null, false);
8058
+ return;
8059
+ }
8060
+
8061
+ String pigment = Object3D.GetPigment(tex);
8062
+
8063
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8064
+ {
8065
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8066
+ // System.out.println("; bump = " + bump);
8067
+ }
8068
+
8069
+ if (pigment.equals(""))
8070
+ {
8071
+ pigment = null;
8072
+ }
8073
+
8074
+ ReleaseTexture(tex, false);
8075
+ }
8076
+
8077
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
8078
+ {
8079
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8080
+ {
8081
+ return;
8082
+ }
8083
+
8084
+ if (tex == null)
8085
+ {
8086
+ ReleaseTexture(null, true);
8087
+ return;
8088
+ }
8089
+
8090
+ String bump = Object3D.GetBump(tex);
8091
+
8092
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8093
+ {
8094
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8095
+ // System.out.println("; bump = " + bump);
8096
+ }
8097
+
8098
+ if (bump.equals(""))
8099
+ {
8100
+ bump = null;
8101
+ }
8102
+
8103
+ ReleaseTexture(tex, true);
8104
+ }
8105
+
8106
+ void ReleaseTexture(cTexture tex, boolean bump)
75548107 {
75558108 if (// DrawMode() != 0 || /*tex == null ||*/
75568109 ambientOcclusion ) // || !textureon)
....@@ -7561,7 +8114,7 @@
75618114 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
75628115
75638116 if (tex != null)
7564
- texture = textures.get(tex);
8117
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
75658118
75668119 // //assert( texture != null );
75678120 // if (texture == null)
....@@ -7653,7 +8206,55 @@
76538206 }
76548207 }
76558208
7656
- /*boolean*/ public void BindTextures(cTexture tex, int resolution) // INTERFACE
8209
+ /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
8210
+ {
8211
+// if (// DrawMode() != 0 || /*tex == null ||*/
8212
+// ambientOcclusion ) // || !textureon)
8213
+// {
8214
+// return; // false;
8215
+// }
8216
+//
8217
+// if (tex == null)
8218
+// {
8219
+// BindTexture(null,false,resolution);
8220
+// BindTexture(null,true,resolution);
8221
+// return;
8222
+// }
8223
+//
8224
+// String pigment = Object3D.GetPigment(tex);
8225
+// String bump = Object3D.GetBump(tex);
8226
+//
8227
+// usedtextures.add(pigment);
8228
+// usedtextures.add(bump);
8229
+//
8230
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8231
+// {
8232
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8233
+// // System.out.println("; bump = " + bump);
8234
+// }
8235
+//
8236
+// if (bump.equals(""))
8237
+// {
8238
+// bump = null;
8239
+// }
8240
+// if (pigment.equals(""))
8241
+// {
8242
+// pigment = null;
8243
+// }
8244
+//
8245
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8246
+// BindTexture(pigment, false, resolution);
8247
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8248
+// BindTexture(bump, true, resolution);
8249
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8250
+//
8251
+// return; // true;
8252
+
8253
+ BindPigmentTexture(tex, resolution);
8254
+ BindBumpTexture(tex, resolution);
8255
+ }
8256
+
8257
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
76578258 {
76588259 if (// DrawMode() != 0 || /*tex == null ||*/
76598260 ambientOcclusion ) // || !textureon)
....@@ -7664,17 +8265,47 @@
76648265 if (tex == null)
76658266 {
76668267 BindTexture(null,false,resolution);
7667
- BindTexture(null,true,resolution);
76688268 return;
76698269 }
76708270
76718271 String pigment = Object3D.GetPigment(tex);
8272
+
8273
+ usedtextures.add(tex);
8274
+
8275
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8276
+ {
8277
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8278
+ // System.out.println("; bump = " + bump);
8279
+ }
8280
+
8281
+ if (pigment.equals(""))
8282
+ {
8283
+ pigment = null;
8284
+ }
8285
+
8286
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8287
+ BindTexture(tex, false, resolution);
8288
+ }
8289
+
8290
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8291
+ {
8292
+ if (// DrawMode() != 0 || /*tex == null ||*/
8293
+ ambientOcclusion ) // || !textureon)
8294
+ {
8295
+ return; // false;
8296
+ }
8297
+
8298
+ if (tex == null)
8299
+ {
8300
+ BindTexture(null,true,resolution);
8301
+ return;
8302
+ }
8303
+
76728304 String bump = Object3D.GetBump(tex);
76738305
7674
- usedtextures.put(pigment, pigment);
7675
- usedtextures.put(bump, bump);
8306
+ usedtextures.add(tex);
76768307
7677
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8308
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
76788309 {
76798310 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
76808311 // System.out.println("; bump = " + bump);
....@@ -7684,43 +8315,94 @@
76848315 {
76858316 bump = null;
76868317 }
7687
- if (pigment.equals(""))
7688
- {
7689
- pigment = null;
7690
- }
76918318
7692
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
7693
- BindTexture(pigment, false, resolution);
76948319 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
7695
- BindTexture(bump, true, resolution);
8320
+ BindTexture(tex, true, resolution);
76968321 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
7697
-
7698
- return; // true;
76998322 }
77008323
7701
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution)
8324
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8325
+
8326
+ private boolean FileExists(String tex)
77028327 {
7703
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8328
+ if (missingTextures.contains(tex))
8329
+ {
8330
+ return false;
8331
+ }
8332
+
8333
+ boolean fileExists = new File(tex).exists();
8334
+
8335
+ if (!fileExists)
8336
+ {
8337
+ // If file exists, the "new File()" is not executed sgain
8338
+ missingTextures.add(tex);
8339
+ }
8340
+
8341
+ return fileExists;
8342
+ }
8343
+
8344
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
8345
+ {
8346
+ CacheTexture texturecache = null;
77048347
77058348 if (tex != null)
77068349 {
7707
- String texname = tex;
8350
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8351
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
77088352
7709
- String[] split = tex.split("Textures");
7710
- if (split.length > 1)
7711
- texname = "/Users/nbriere/Textures" + split[split.length-1];
7712
- else
7713
- if (!texname.startsWith("/"))
7714
- texname = "/Users/nbriere/Textures/" + texname;
8353
+ if (texname.equals("") && texdata == null)
8354
+ {
8355
+ return null;
8356
+ }
8357
+
8358
+ String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
8359
+
8360
+// String[] split = tex.split("Textures");
8361
+// if (split.length > 1)
8362
+// texname = "/Users/nbriere/Textures" + split[split.length-1];
8363
+// else
8364
+// if (!texname.startsWith("/"))
8365
+// texname = "/Users/nbriere/Textures/" + texname;
8366
+ if (!FileExists(texname) && !texname.startsWith("@"))
8367
+ {
8368
+ texname = fallbackTextureName;
8369
+ }
77158370
77168371 if (CACHETEXTURE)
7717
- texture = textures.get(texname); // TEXTURE CACHE
7718
-
7719
- TextureData texturedata = null;
7720
-
7721
- if (texture == null || texture.resolution < resolution)
77228372 {
7723
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8373
+ if (texdata == null)
8374
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8375
+ else
8376
+ texturecache = bimtextures.get(texdata);
8377
+ }
8378
+
8379
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8380
+ {
8381
+ TextureData texturedata = null;
8382
+
8383
+ if (texdata != null && textureon)
8384
+ {
8385
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8386
+
8387
+ try
8388
+ {
8389
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8390
+ }
8391
+ catch (Exception e)
8392
+ {
8393
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8394
+ }
8395
+
8396
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8397
+ bimtextures.put(texdata, texturecache);
8398
+
8399
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8400
+
8401
+ //Object bim2 = CreateBim(texturecache.texturedata);
8402
+ //bim2 = bim;
8403
+ }
8404
+ else
8405
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
77248406 {
77258407 assert(!bump);
77268408 // if (bump)
....@@ -7731,19 +8413,23 @@
77318413 // }
77328414 // else
77338415 // {
7734
- texture = textures.get(tex);
7735
- if (texture == null)
8416
+ // texturecache = textures.get(texname); // suspicious
8417
+ if (texturecache == null)
77368418 {
7737
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8419
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
77388420 }
8421
+ else
8422
+ new Exception().printStackTrace();
77398423 // }
77408424 } else
7741
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8425
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
77428426 {
77438427 assert(bump);
7744
- texture = textures.get(tex);
7745
- if (texture == null)
7746
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8428
+ // texturecache = textures.get(texname); // suspicious
8429
+ if (texturecache == null)
8430
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8431
+ else
8432
+ new Exception().printStackTrace();
77478433 } else
77488434 {
77498435 //if (tex.equals("IMMORTAL"))
....@@ -7751,11 +8437,22 @@
77518437 // texture = GetResourceTexture("default.png");
77528438 //} else
77538439 //{
7754
- if (tex.equals("WHITE_NOISE"))
8440
+ if (texname.endsWith("WHITE_NOISE"))
77558441 {
7756
- texture = textures.get(tex);
7757
- if (texture == null)
7758
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8442
+ // texturecache = textures.get(texname); // suspicious
8443
+ if (texturecache == null)
8444
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8445
+ else
8446
+ new Exception().printStackTrace();
8447
+ } else
8448
+ {
8449
+ if (texname.startsWith("@"))
8450
+ {
8451
+ // texturecache = textures.get(texname); // suspicious
8452
+ if (texturecache == null)
8453
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8454
+ else
8455
+ new Exception().printStackTrace();
77598456 } else
77608457 {
77618458 if (textureon)
....@@ -7780,7 +8477,7 @@
77808477 }
77818478
77828479 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
7783
- if (!new File(cachename).exists())
8480
+ if (!FileExists(cachename))
77848481 cachename = texname;
77858482 else
77868483 processbump = false; // don't process bump map again
....@@ -7802,7 +8499,7 @@
78028499 }
78038500
78048501 cachename = texname.substring(0, texname.length()-4)+ext+".png";
7805
- if (!new File(cachename).exists())
8502
+ if (!FileExists(cachename))
78068503 cachename = texname;
78078504 else
78088505 processbump = false; // don't process bump map again
....@@ -7811,20 +8508,23 @@
78118508 texturedata = GetFileTexture(cachename, processbump, resolution);
78128509
78138510
7814
- if (texturedata != null)
7815
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8511
+ if (texturedata == null)
8512
+ throw new Exception();
8513
+
8514
+ texturecache = new CacheTexture(texturedata,resolution);
78168515 //texture = GetTexture(tex, bump);
78178516 }
8517
+ }
78188518 }
78198519 //}
78208520 }
78218521
7822
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8522
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
78238523 {
78248524 //return false;
78258525
78268526 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
7827
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8527
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
78288528 {
78298529 // String ext = "_highres";
78308530 // if (REDUCETEXTURE)
....@@ -7841,52 +8541,17 @@
78418541 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
78428542 if (!cachefile.exists())
78438543 {
7844
- // cache to disk
7845
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
7846
- //buffers[0].
7847
-
7848
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
7849
- int[] pixels = new int[bytebuf.capacity()/3];
7850
-
7851
- // squared size heuristic...
7852
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8544
+ //if (texturedata.getWidth() == texturedata.getHeight())
78538545 {
7854
- for (int i=pixels.length; --i>=0;)
7855
- {
7856
- int i3 = i*3;
7857
- pixels[i] = 0xFF;
7858
- pixels[i] <<= 8;
7859
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
7860
- pixels[i] <<= 8;
7861
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
7862
- pixels[i] <<= 8;
7863
- pixels[i] |= bytebuf.get(i3) & 0xFF;
7864
- }
7865
-
7866
- /*
7867
- int r=0,g=0,b=0,a=0;
7868
- for (int i=0; i<width; i++)
7869
- for (int j=0; j<height; j++)
7870
- {
7871
- int index = j*width+i;
7872
- int p = pixels[index];
7873
- a = ((p>>24) & 0xFF);
7874
- r = ((p>>16) & 0xFF);
7875
- g = ((p>>8) & 0xFF);
7876
- b = (p & 0xFF);
7877
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
7878
- }
7879
- /**/
7880
- int width = (int)Math.sqrt(pixels.length); // squared
7881
- int height = width;
7882
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
7883
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8546
+ BufferedImage rendImage = CreateBim(texturedata);
8547
+
78848548 ImageWriter writer = null;
78858549 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
78868550 if (iter.hasNext()) {
78878551 writer = (ImageWriter)iter.next();
78888552 }
7889
- float compressionQuality = 0.9f;
8553
+
8554
+ float compressionQuality = 0.85f;
78908555 try
78918556 {
78928557 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -7903,18 +8568,20 @@
79038568 }
79048569 }
79058570 }
7906
-
8571
+
8572
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8573
+
79078574 //System.out.println("Texture = " + tex);
7908
- if (textures.containsKey(texname))
8575
+ if (textures.containsKey(tex))
79098576 {
7910
- CacheTexture thetex = textures.get(texname);
8577
+ CacheTexture thetex = textures.get(tex);
79118578 thetex.texture.disable();
79128579 thetex.texture.dispose();
7913
- textures.remove(texname);
8580
+ textures.remove(tex);
79148581 }
79158582
7916
- texture.texturedata = texturedata;
7917
- textures.put(texname, texture);
8583
+ //texture.texturedata = texturedata;
8584
+ textures.put(tex, texturecache);
79188585
79198586 // newtex = true;
79208587 }
....@@ -7930,10 +8597,44 @@
79308597 }
79318598 }
79328599
7933
- return texture;
8600
+ return texturecache;
79348601 }
79358602
7936
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution)
8603
+ static void EmbedTextures(cTexture tex)
8604
+ {
8605
+ if (tex.pigmentdata == null)
8606
+ {
8607
+ //String texname = Object3D.GetPigment(tex);
8608
+
8609
+ CacheTexture texturecache = texturepigment.get(tex);
8610
+
8611
+ if (texturecache != null)
8612
+ {
8613
+ tex.pw = texturecache.texturedata.getWidth();
8614
+ tex.ph = texturecache.texturedata.getHeight();
8615
+ tex.pigmentdata = //CompressJPEG(CreateBim
8616
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8617
+ ;
8618
+ //, tex.pw, tex.ph), 0.5f);
8619
+ }
8620
+ }
8621
+
8622
+ if (tex.bumpdata == null)
8623
+ {
8624
+ //String texname = Object3D.GetBump(tex);
8625
+
8626
+ CacheTexture texturecache = texturebump.get(tex);
8627
+
8628
+ if (texturecache != null)
8629
+ {
8630
+ tex.bw = texturecache.texturedata.getWidth();
8631
+ tex.bh = texturecache.texturedata.getHeight();
8632
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8633
+ }
8634
+ }
8635
+ }
8636
+
8637
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
79378638 {
79388639 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
79398640
....@@ -7951,21 +8652,21 @@
79518652 return texture!=null?texture.texture:null;
79528653 }
79538654
7954
- public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution)
8655
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
79558656 {
79568657 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
79578658
79588659 return texture!=null?texture.texturedata:null;
79598660 }
79608661
7961
- boolean BindTexture(String tex, boolean bump, int resolution)
8662
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
79628663 {
79638664 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
79648665 {
79658666 return false;
79668667 }
79678668
7968
- boolean newtex = false;
8669
+ //boolean newtex = false;
79698670
79708671 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
79718672
....@@ -7997,9 +8698,75 @@
79978698 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
79988699 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
79998700
8000
- return newtex;
8701
+ return true; // Warning: not used.
80018702 }
80028703
8704
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8705
+ {
8706
+ try
8707
+ {
8708
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8709
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8710
+ ImageWriter writer = writers.next();
8711
+
8712
+ ImageWriteParam param = writer.getDefaultWriteParam();
8713
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8714
+ param.setCompressionQuality(quality);
8715
+
8716
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8717
+ writer.setOutput(ios);
8718
+ writer.write(null, new IIOImage(image, null, null), param);
8719
+
8720
+ byte[] data = baos.toByteArray();
8721
+ writer.dispose();
8722
+ return data;
8723
+ }
8724
+ catch (Exception e)
8725
+ {
8726
+ e.printStackTrace();
8727
+ return null;
8728
+ }
8729
+ }
8730
+
8731
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8732
+ {
8733
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8734
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8735
+ ImageReader reader = writers.next();
8736
+
8737
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8738
+
8739
+ ImageReadParam param = reader.getDefaultReadParam();
8740
+ param.setDestination(bim);
8741
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8742
+
8743
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8744
+ reader.setInput(ios);
8745
+ BufferedImage bim2 = reader.read(0, param);
8746
+ reader.dispose();
8747
+
8748
+// WritableRaster raster = bim2.getRaster();
8749
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8750
+// byte[] bytes = data.getData();
8751
+//
8752
+// int[] pixels = new int[bytes.length/3];
8753
+// for (int i=pixels.length; --i>=0;)
8754
+// {
8755
+// int i3 = i*3;
8756
+// pixels[i] = 0xFF;
8757
+// pixels[i] <<= 8;
8758
+// pixels[i] |= bytes[i3+2] & 0xFF;
8759
+// pixels[i] <<= 8;
8760
+// pixels[i] |= bytes[i3+1] & 0xFF;
8761
+// pixels[i] <<= 8;
8762
+// pixels[i] |= bytes[i3] & 0xFF;
8763
+// }
8764
+//
8765
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8766
+
8767
+ return bim;
8768
+ }
8769
+
80038770 ShadowBuffer shadowPBuf;
80048771 AntialiasBuffer antialiasPBuf;
80058772 int MAXSTACK;
....@@ -8016,10 +8783,12 @@
80168783
80178784 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
80188785 MAXSTACK = temp[0];
8019
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8786
+ if (Globals.DEBUG)
8787
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
80208788 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
80218789 MAXSTACK = temp[0];
8022
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8790
+ if (Globals.DEBUG)
8791
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
80238792
80248793 // Use debug pipeline
80258794 //drawable.setGL(new DebugGL(gl)); //
....@@ -8027,7 +8796,8 @@
80278796 gl = drawable.getGL(); //
80288797
80298798 GL gl3 = getGL();
8030
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8799
+ if (Globals.DEBUG)
8800
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
80318801
80328802
80338803 //float pos[] = { 100, 100, 100, 0 };
....@@ -8192,7 +8962,7 @@
81928962
81938963 if (cubemap == null)
81948964 {
8195
- LoadEnvy(5);
8965
+ //LoadEnvy(1);
81968966 }
81978967
81988968 //cubemap.enable();
....@@ -8468,6 +9238,8 @@
84689238
84699239 void LoadEnvy(int which)
84709240 {
9241
+ assert(false);
9242
+
84719243 String name;
84729244 String ext;
84739245
....@@ -8479,37 +9251,58 @@
84799251 cubemap = null;
84809252 return;
84819253 case 1:
8482
- name = "cubemaps/box_";
8483
- ext = "png";
9254
+ name = "cubemaps/rgb/";
9255
+ ext = "jpg";
84849256 reverseUP = false;
84859257 break;
84869258 case 2:
8487
- name = "cubemaps/uffizi_";
8488
- ext = "png";
8489
- break; // reverseUP = true; break;
9259
+ name = "cubemaps/uffizi/";
9260
+ ext = "jpg";
9261
+ reverseUP = false;
9262
+ break;
84909263 case 3:
8491
- name = "cubemaps/CloudyHills_";
8492
- ext = "tga";
9264
+ name = "cubemaps/CloudyHills/";
9265
+ ext = "jpg";
84939266 reverseUP = false;
84949267 break;
84959268 case 4:
8496
- name = "cubemaps/cornell_";
9269
+ name = "cubemaps/cornell/";
84979270 ext = "png";
84989271 reverseUP = false;
84999272 break;
9273
+ case 5:
9274
+ name = "cubemaps/skycube/";
9275
+ ext = "jpg";
9276
+ reverseUP = false;
9277
+ break;
9278
+ case 6:
9279
+ name = "cubemaps/SaintLazarusChurch3/";
9280
+ ext = "jpg";
9281
+ reverseUP = false;
9282
+ break;
9283
+ case 7:
9284
+ name = "cubemaps/Sodermalmsallen/";
9285
+ ext = "jpg";
9286
+ reverseUP = false;
9287
+ break;
9288
+ case 8:
9289
+ name = "cubemaps/Sodermalmsallen2/";
9290
+ ext = "jpg";
9291
+ reverseUP = false;
9292
+ break;
9293
+ case 9:
9294
+ name = "cubemaps/UnionSquare/";
9295
+ ext = "jpg";
9296
+ reverseUP = false;
9297
+ break;
85009298 default:
8501
- name = "cubemaps/rgb_";
8502
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9299
+ name = "cubemaps/box/";
9300
+ ext = "png"; /*mipmap = true;*/
9301
+ reverseUP = false;
85039302 break;
85049303 }
8505
-
8506
- try
8507
- {
8508
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
8509
- } catch (IOException e)
8510
- {
8511
- throw new RuntimeException(e);
8512
- }
9304
+
9305
+ LoadSkybox(name, ext, mipmap);
85139306 }
85149307
85159308 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -8541,8 +9334,12 @@
85419334 static double[] model = new double[16];
85429335 double[] camera2light = new double[16];
85439336 double[] light2camera = new double[16];
8544
- int newenvy = -1;
8545
- boolean envyoff = true; // false;
9337
+
9338
+ //int newenvy = -1;
9339
+ //boolean envyoff = false;
9340
+
9341
+ String loadedskyboxname;
9342
+
85469343 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
85479344 //float[] light0 = { 0,0,0 };
85489345 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -8835,11 +9632,35 @@
88359632 jy8[3] = 0.5f;
88369633 }
88379634
8838
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9635
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
88399636 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
88409637 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
88419638 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
88429639
9640
+ void ResetOptions()
9641
+ {
9642
+ options1[0] = 100;
9643
+ options1[1] = 0.025f;
9644
+ options1[2] = 0.01f;
9645
+ options1[3] = 0;
9646
+ options1[4] = 0;
9647
+
9648
+ options2[0] = 0;
9649
+ options2[1] = 0.75f;
9650
+ options2[2] = 0;
9651
+ options2[3] = 0;
9652
+
9653
+ options3[0] = 1;
9654
+ options3[1] = 1;
9655
+ options3[2] = 1;
9656
+ options3[3] = 0;
9657
+
9658
+ options4[0] = 1;
9659
+ options4[1] = 0;
9660
+ options4[2] = 1;
9661
+ options4[3] = 0;
9662
+ }
9663
+
88439664 static int imagecount = 0; // movie generation
88449665
88459666 static int jitter = 0;
....@@ -8935,8 +9756,8 @@
89359756 assert (parentcam != renderCamera);
89369757
89379758 if (renderCamera != lightCamera)
8938
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8939
- LA.matConcat(matrix, parentcam.toParent, matrix);
9759
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9760
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
89409761
89419762 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
89429763
....@@ -8951,8 +9772,8 @@
89519772 LA.matCopy(renderCamera.fromScreen, matrix);
89529773
89539774 if (renderCamera != lightCamera)
8954
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8955
- LA.matConcat(parentcam.fromParent, matrix, matrix);
9775
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9776
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
89569777
89579778 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
89589779
....@@ -8998,10 +9819,12 @@
89989819 rati = 1 / rati;
89999820 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
90009821 }
9001
- assert (newenvy == -1);
9822
+
9823
+ //assert (newenvy == -1);
9824
+
90029825 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
90039826 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9004
- DrawSkyBox(gl);
9827
+ DrawSkyBox(gl, (float)rati);
90059828 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
90069829 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
90079830 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -9024,7 +9847,7 @@
90249847 //gl.glFlush();
90259848 gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE);
90269849
9027
- if (ANIMATION && ABORTED)
9850
+ if (Globals.ANIMATION && ABORTED)
90289851 {
90299852 System.err.println(" ABORTED FRAME");
90309853 break;
....@@ -9054,7 +9877,7 @@
90549877 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
90559878
90569879 // save image
9057
- if (ANIMATION && !ABORTED)
9880
+ if (Globals.ANIMATION && !ABORTED)
90589881 {
90599882 VPwidth = viewport[2];
90609883 VPheight = viewport[3];
....@@ -9165,11 +9988,11 @@
91659988
91669989 // imagecount++;
91679990
9168
- String fullname = filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
9991
+ String fullname = Globals.filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
91699992
91709993 if (!BOXMODE)
91719994 {
9172
- System.out.println("image: " + fullname + " (wav cursor=" + (GrafreeD.wav.cursor / 735 / 4) + ")");
9995
+ System.out.println("image: " + fullname + " (wav cursor=" + (Grafreed.wav.cursor / 735 / 4) + ")");
91739996 }
91749997
91759998 if (!BOXMODE)
....@@ -9207,7 +10030,7 @@
920710030 ABORTED = false;
920810031 }
920910032 else
9210
- GrafreeD.wav.cursor += 735 * ACSIZE;
10033
+ Grafreed.wav.cursor += 735 * ACSIZE;
921110034
921210035 if (false)
921310036 {
....@@ -9867,14 +10690,23 @@
986710690 static boolean init = false;
986810691
986910692 double[][] matrix = LA.newMatrix();
10693
+
10694
+ // This is to refresh the UI of the material panel.
10695
+ ObjEditor patchMaterial;
987010696
987110697 public void display(GLAutoDrawable drawable)
987210698 {
9873
- if (GrafreeD.savesound && GrafreeD.hassound)
10699
+ if (patchMaterial.patchMaterial)
987410700 {
9875
- GrafreeD.wav.save();
9876
- GrafreeD.savesound = false;
9877
- GrafreeD.hassound = false;
10701
+ patchMaterial.patchMaterial = false;
10702
+ patchMaterial.objectPanel.setSelectedIndex(0);
10703
+ }
10704
+
10705
+ if (Grafreed.savesound && Grafreed.hassound)
10706
+ {
10707
+ Grafreed.wav.save();
10708
+ Grafreed.savesound = false;
10709
+ Grafreed.hassound = false;
987810710 }
987910711 // if (DEBUG_SELECTION)
988010712 // {
....@@ -9950,6 +10782,7 @@
995010782 ANTIALIAS = 0;
995110783 //System.out.println("RESTART");
995210784 AAtimer.restart();
10785
+ Globals.TIMERRUNNING = true;
995310786 }
995410787 }
995510788 }
....@@ -10004,7 +10837,7 @@
1000410837 Object3D theobject = object;
1000510838 Object3D theparent = object.parent;
1000610839 object.parent = null;
10007
- object = (Object3D)GrafreeD.clone(object);
10840
+ object = (Object3D)Grafreed.clone(object);
1000810841 object.Stripify();
1000910842 if (theobject.selection == null || theobject.selection.Size() == 0)
1001010843 theobject.PreprocessOcclusion(this);
....@@ -10017,13 +10850,14 @@
1001710850 ambientOcclusion = false;
1001810851 }
1001910852
10020
- if (Globals.lighttouched && DrawMode() == DEFAULT && !lightMode) // && !FROZEN)
10853
+ if (//Globals.lighttouched &&
10854
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1002110855 {
1002210856 //if (RENDERSHADOW) // ?
1002310857 if (!IsFrozen())
1002410858 {
1002510859 // dec 2012
10026
- if (!ambientOcclusion && !(!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0))
10860
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
1002710861 {
1002810862 Globals.framecount++;
1002910863 shadowbuffer.display();
....@@ -10036,7 +10870,7 @@
1003610870
1003710871 if (wait)
1003810872 {
10039
- Sleep(500);
10873
+ Sleep(200); // blocks everything
1004010874
1004110875 wait = false;
1004210876 }
....@@ -10150,8 +10984,8 @@
1015010984
1015110985 // if (parentcam != renderCamera) // not a light
1015210986 if (cam != lightCamera)
10153
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10154
- LA.matConcat(matrix, parentcam.toParent, matrix);
10987
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10988
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1015510989
1015610990 for (int j = 0; j < 4; j++)
1015710991 {
....@@ -10165,8 +10999,8 @@
1016510999
1016611000 // if (parentcam != renderCamera) // not a light
1016711001 if (cam != lightCamera)
10168
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10169
- LA.matConcat(parentcam.fromParent, matrix, matrix);
11002
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11003
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1017011004
1017111005 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1017211006
....@@ -10252,13 +11086,43 @@
1025211086 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1025311087 }
1025411088
10255
- if (newenvy > -1)
11089
+// if (newenvy > -1)
11090
+// {
11091
+// LoadEnvy(newenvy);
11092
+// }
11093
+//
11094
+// newenvy = -1;
11095
+
11096
+ if (transformMode) // object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
1025611097 {
10257
- LoadEnvy(newenvy);
11098
+ if (cubemaprgb == null)
11099
+ {
11100
+ cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb2" + "/", "jpg", false);
11101
+ }
11102
+
11103
+ cubemap = cubemaprgb;
1025811104 }
10259
-
10260
- newenvy = -1;
10261
-
11105
+ else
11106
+ {
11107
+ if (object.skyboxname != null)
11108
+ {
11109
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11110
+ {
11111
+ if (cubemap != null && cubemap != cubemaprgb)
11112
+ cubemap.dispose();
11113
+ cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11114
+ loadedskyboxname = object.skyboxname;
11115
+ }
11116
+ }
11117
+ else
11118
+ {
11119
+ cubemapcustom = null;
11120
+ loadedskyboxname = null;
11121
+ }
11122
+
11123
+ cubemap = cubemapcustom;
11124
+ }
11125
+
1026211126 ratio = ((double) getWidth()) / getHeight();
1026311127 //System.out.println("ratio = " + ratio);
1026411128
....@@ -10274,7 +11138,7 @@
1027411138
1027511139 if (!IsFrozen() && !ambientOcclusion)
1027611140 {
10277
- DrawSkyBox(gl);
11141
+ DrawSkyBox(gl, (float)ratio);
1027811142 }
1027911143
1028011144 //if (selection_view == -1)
....@@ -10425,7 +11289,16 @@
1042511289 // Bump noise
1042611290 gl.glActiveTexture(GL.GL_TEXTURE6);
1042711291 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
10428
- BindTexture(NOISE_TEXTURE, false, 2);
11292
+
11293
+ try
11294
+ {
11295
+ BindTexture(NOISE_TEXTURE, false, 2);
11296
+ }
11297
+ catch (Exception e)
11298
+ {
11299
+ System.err.println("FAILED: " + NOISE_TEXTURE);
11300
+ }
11301
+
1042911302
1043011303 gl.glActiveTexture(GL.GL_TEXTURE0);
1043111304 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -10448,9 +11321,9 @@
1044811321
1044911322 gl.glMatrixMode(GL.GL_MODELVIEW);
1045011323
10451
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10452
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10453
-//gl.glEnable(gl.GL_MULTISAMPLE);
11324
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11325
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11326
+gl.glEnable(gl.GL_MULTISAMPLE);
1045411327 } else
1045511328 {
1045611329 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -10461,7 +11334,7 @@
1046111334 //System.out.println("BLENDING ON");
1046211335 gl.glEnable(GL.GL_BLEND);
1046311336 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
10464
-
11337
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1046511338 gl.glMatrixMode(gl.GL_PROJECTION);
1046611339 gl.glLoadIdentity();
1046711340
....@@ -10550,8 +11423,8 @@
1055011423 System.err.println("parentcam != renderCamera");
1055111424
1055211425 // if (cam != lightCamera)
10553
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10554
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11426
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11427
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1055511428 }
1055611429
1055711430 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -10572,8 +11445,8 @@
1057211445 if (true) // TODO
1057311446 {
1057411447 if (cam != lightCamera)
10575
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10576
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11448
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11449
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
1057711450 }
1057811451
1057911452 LA.xformPos(light0, cam.toScreen, light0);
....@@ -10710,7 +11583,7 @@
1071011583 }
1071111584 }
1071211585
10713
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11586
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1071411587 {
1071511588 //gl.glDepthFunc(GL.GL_LEQUAL);
1071611589 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -10718,24 +11591,21 @@
1071811591
1071911592 boolean texon = textureon;
1072011593
10721
- if (RENDERPROGRAM > 0)
10722
- {
10723
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
10724
- textureon = false;
10725
- }
11594
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11595
+ textureon = false;
11596
+
1072611597 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1072711598 //System.out.println("ALLO");
1072811599 gl.glColorMask(false, false, false, false);
1072911600 DrawObject(gl);
10730
- if (RENDERPROGRAM > 0)
10731
- {
10732
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
10733
- textureon = texon;
10734
- }
11601
+
11602
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11603
+ textureon = texon;
11604
+
1073511605 gl.glColorMask(true, true, true, true);
1073611606
1073711607 gl.glDepthFunc(GL.GL_EQUAL);
10738
- //gl.glDepthMask(false);
11608
+ gl.glDepthMask(false);
1073911609 }
1074011610
1074111611 if (false) // DrawMode() == SHADOW)
....@@ -10889,8 +11759,14 @@
1088911759 {
1089011760 renderpass++;
1089111761 // System.out.println("Draw object... ");
11762
+ STEP = 1;
1089211763 if (FAST) // in case there is no script
10893
- STEP = 16;
11764
+ STEP = 8;
11765
+
11766
+ if (CURRENTANTIALIAS == 0 || ACSIZE == 1)
11767
+ {
11768
+ STEP *= 4;
11769
+ }
1089411770
1089511771 //object.FullInvariants();
1089611772
....@@ -10904,23 +11780,44 @@
1090411780 e.printStackTrace();
1090511781 }
1090611782
10907
- if (GrafreeD.RENDERME > 0)
10908
- GrafreeD.RENDERME--; // mechante magouille
11783
+ if (Grafreed.RENDERME > 0)
11784
+ Grafreed.RENDERME--; // mechante magouille
1090911785
1091011786 Globals.ONESTEP = false;
1091111787 }
1091211788
1091311789 static boolean zoomonce = false;
1091411790
11791
+ static void CreateSelectedPoint()
11792
+ {
11793
+ if (selectedpoint == null)
11794
+ {
11795
+ debugpointG = new Sphere();
11796
+ debugpointP = new Sphere();
11797
+ debugpointC = new Sphere();
11798
+ debugpointR = new Sphere();
11799
+
11800
+ selectedpoint = new Superellipsoid();
11801
+
11802
+ for (int i=0; i<8; i++)
11803
+ {
11804
+ debugpoints[i] = new Sphere();
11805
+ }
11806
+ }
11807
+ }
11808
+
1091511809 void DrawObject(GL gl, boolean draw)
1091611810 {
11811
+ // To clear camera values
11812
+ ResetOptions();
11813
+
1091711814 //System.out.println("DRAW OBJECT " + mouseDown);
1091811815 // DrawMode() = SELECTION;
1091911816 //GL gl = getGL();
1092011817 if ((TRACK || SHADOWTRACK) || zoomonce)
1092111818 {
1092211819 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
10923
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11820
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1092411821 pingthread.StepToTarget(true); // true);
1092511822 // zoomonce = false;
1092611823 }
....@@ -10975,7 +11872,14 @@
1097511872
1097611873 usedtextures.clear();
1097711874
10978
- BindTextures(DEFAULT_TEXTURES, 2);
11875
+ try
11876
+ {
11877
+ BindTextures(DEFAULT_TEXTURES, 2);
11878
+ }
11879
+ catch (Exception e)
11880
+ {
11881
+ System.err.println("FAILED: " + DEFAULT_TEXTURES);
11882
+ }
1097911883 }
1098011884 //System.out.println("--> " + stackdepth);
1098111885 // GrafreeD.traceon();
....@@ -10985,8 +11889,9 @@
1098511889
1098611890 if (DrawMode() == DEFAULT)
1098711891 {
10988
- if (DEBUG)
11892
+ if (Globals.DEBUG)
1098911893 {
11894
+ CreateSelectedPoint();
1099011895 float radius = 0.05f;
1099111896 if (selectedpoint.radius != radius)
1099211897 {
....@@ -11040,20 +11945,32 @@
1104011945 ReleaseTextures(DEFAULT_TEXTURES);
1104111946
1104211947 if (CLEANCACHE)
11043
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11948
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1104411949 {
11045
- String tex = e.nextElement();
11950
+ cTexture tex = e.nextElement();
1104611951
1104711952 // System.out.println("Texture --------- " + tex);
1104811953
11049
- if (tex.equals("WHITE_NOISE"))
11954
+ if (tex.equals("WHITE_NOISE:"))
1105011955 continue;
1105111956
11052
- if (!usedtextures.containsKey(tex))
11957
+ if (!usedtextures.contains(tex))
1105311958 {
11959
+ CacheTexture gettex = texturepigment.get(tex);
1105411960 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11055
- textures.get(tex).texture.dispose();
11056
- textures.remove(tex);
11961
+ if (gettex != null)
11962
+ {
11963
+ gettex.texture.dispose();
11964
+ texturepigment.remove(tex);
11965
+ }
11966
+
11967
+ gettex = texturebump.get(tex);
11968
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11969
+ if (gettex != null)
11970
+ {
11971
+ gettex.texture.dispose();
11972
+ texturebump.remove(tex);
11973
+ }
1105711974 }
1105811975 }
1105911976 }
....@@ -11066,7 +11983,14 @@
1106611983 if (checker != null && DrawMode() == DEFAULT)
1106711984 {
1106811985 //BindTexture(IMMORTAL_TEXTURE);
11069
- BindTextures(checker.GetTextures(), checker.texres);
11986
+ try
11987
+ {
11988
+ BindTextures(checker.GetTextures(), checker.texres);
11989
+ }
11990
+ catch (Exception e)
11991
+ {
11992
+ System.err.println("FAILED: " + checker.GetTextures());
11993
+ }
1107011994 // NEAREST
1107111995 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
1107211996 DrawChecker(gl);
....@@ -11148,7 +12072,7 @@
1114812072 return;
1114912073 }
1115012074
11151
- String string = obj.GetToolTip();
12075
+ String string = obj.toString(); //.GetToolTip();
1115212076
1115312077 GL gl = GetGL();
1115412078
....@@ -11465,8 +12389,8 @@
1146512389 //obj.TransformToWorld(light, light);
1146612390 for (int i = tp.size(); --i >= 0;)
1146712391 {
11468
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
11469
- LA.xformPos(light, tp.get(i).toParent, light);
12392
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12393
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1147012394 }
1147112395
1147212396
....@@ -11483,8 +12407,8 @@
1148312407 parentcam = cameras[0];
1148412408 }
1148512409
11486
- for (int count = parentcam.GetTransformCount(); --count>=0;)
11487
- LA.xformPos(light, parentcam.toParent, light); // may 2013
12410
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
12411
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1148812412
1148912413 LA.xformPos(light, renderCamera.toScreen, light);
1149012414
....@@ -11574,8 +12498,76 @@
1157412498
1157512499 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1157612500
11577
- String program =
12501
+ String programmin =
12502
+ // Min shader
1157812503 "!!ARBfp1.0\n" +
12504
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12505
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12506
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12507
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12508
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12509
+ "PARAM light2cam0 = program.env[10];" +
12510
+ "PARAM light2cam1 = program.env[11];" +
12511
+ "PARAM light2cam2 = program.env[12];" +
12512
+ "TEMP temp;" +
12513
+ "TEMP light;" +
12514
+ "TEMP ndotl;" +
12515
+ "TEMP normal;" +
12516
+ "TEMP depth;" +
12517
+ "TEMP eye;" +
12518
+ "TEMP pos;" +
12519
+
12520
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12521
+ Normalize("normal") +
12522
+ "MOV light, state.light[0].position;" +
12523
+ "DP3 ndotl.x, light, normal;" +
12524
+
12525
+ // shadow
12526
+ "MOV pos, fragment.texcoord[1];" +
12527
+ "MOV temp, pos;" +
12528
+ ShadowTextureFetch("depth", "temp", "1") +
12529
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12530
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12531
+
12532
+ // No shadow when out of frustum
12533
+ //"SGE temp.y, depth.z, zero123.y;" +
12534
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12535
+
12536
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12537
+
12538
+ // Backlit
12539
+ "MOV pos.w, zero123.y;" +
12540
+ "DP4 eye.x, pos, light2cam0;" +
12541
+ "DP4 eye.y, pos, light2cam1;" +
12542
+ "DP4 eye.z, pos, light2cam2;" +
12543
+ Normalize("eye") +
12544
+
12545
+ "DP3 ndotl.y, -eye, normal;" +
12546
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12547
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12548
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12549
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12550
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12551
+
12552
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12553
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12554
+
12555
+ // Pigment
12556
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12557
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12558
+ "MUL temp, temp, ndotl.x;" +
12559
+
12560
+ "MUL temp, temp, zero123.z;" +
12561
+
12562
+ //"MUL temp, temp, ndotl.y;" +
12563
+
12564
+ "MOV temp.w, zero123.y;" + // reset alpha
12565
+ "MOV result.color, temp;" +
12566
+ "END";
12567
+
12568
+ String programmax =
12569
+ "!!ARBfp1.0\n" +
12570
+
1157912571 //"OPTION ARB_fragment_program_shadow;" +
1158012572 "PARAM light2cam0 = program.env[10];" +
1158112573 "PARAM light2cam1 = program.env[11];" +
....@@ -11690,8 +12682,7 @@
1169012682 "TEMP shininess;" +
1169112683 "\n" +
1169212684 "MOV texSamp, one;" +
11693
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
11694
-
12685
+
1169512686 "MOV mapgrid.x, one2048th.x;" +
1169612687 "MOV temp, fragment.texcoord[1];" +
1169712688 /*
....@@ -11712,20 +12703,20 @@
1171212703 "MUL temp, floor, mapgrid.x;" +
1171312704 //"TEX depth0, temp, texture[1], 2D;" +
1171412705 (((mode & FP_SOFTSHADOW) == 0) ? "" :
11715
- TextureFetch("depth0", "temp", "1") +
12706
+ ShadowTextureFetch("depth0", "temp", "1") +
1171612707 "") +
1171712708 "ADD temp.x, temp.x, mapgrid.x;" +
1171812709 //"TEX depth1, temp, texture[1], 2D;" +
1171912710 (((mode & FP_SOFTSHADOW) == 0) ? "" :
11720
- TextureFetch("depth1", "temp", "1") +
12711
+ ShadowTextureFetch("depth1", "temp", "1") +
1172112712 "") +
1172212713 "ADD temp.y, temp.y, mapgrid.x;" +
1172312714 //"TEX depth2, temp, texture[1], 2D;" +
11724
- TextureFetch("depth2", "temp", "1") +
12715
+ ShadowTextureFetch("depth2", "temp", "1") +
1172512716 "SUB temp.x, temp.x, mapgrid.x;" +
1172612717 //"TEX depth3, temp, texture[1], 2D;" +
1172712718 (((mode & FP_SOFTSHADOW) == 0) ? "" :
11728
- TextureFetch("depth3", "temp", "1") +
12719
+ ShadowTextureFetch("depth3", "temp", "1") +
1172912720 "") +
1173012721 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1173112722 //"MOV params, material;" +
....@@ -12096,10 +13087,10 @@
1209613087 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1209713088 "") +
1209813089
12099
- // display shadow only (bump == 0)
13090
+ // display shadow only (fakedepth == 0)
1210013091 "SUB temp.x, half.x, shadow.x;" +
12101
- "MOV temp.y, -params6.x;" +
12102
- "SLT temp.z, temp.y, zero.x;" +
13092
+ "MOV temp.y, -params5.z;" + // params6.x;" +
13093
+ "SLT temp.z, temp.y, -c256i.x;" +
1210313094 "SUB temp.y, one.x, temp.z;" +
1210413095 "MUL temp.x, temp.x, temp.y;" +
1210513096 "KIL temp.x;" +
....@@ -12228,8 +13219,10 @@
1222813219 "MAX ndotl.x, ndotl.x, -ndotl.x;" +
1222913220
1223013221 "SUB temp.x, one.x, ndotl.x;" +
12231
- "ADD temp.x, temp.x, options2.z;" + // lightsheen
12232
- "ADD temp.y, one.y, options2.y;" + // sursurface
13222
+ // Tuning for default skin
13223
+ //"ADD temp.x, temp.x, options2.z;" + // lightsheen
13224
+ "MAD temp.x, options2.z, half.y, temp.x;" + // lightsheen
13225
+ "ADD temp.y, one.y, options2.y;" + // subsurface
1223313226 "MUL temp.x, temp.x, temp.y;" +
1223413227
1223513228 "MUL saturation, saturation, temp.xxxx;" +
....@@ -12428,8 +13421,19 @@
1242813421 //once = true;
1242913422 }
1243013423
12431
- System.out.print("Program #" + mode + "; length = " + program.length());
12432
- System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13424
+ String program = programmax;
13425
+
13426
+ if (Globals.MINSHADER)
13427
+ {
13428
+ program = programmin;
13429
+ }
13430
+
13431
+ if (Globals.DEBUG)
13432
+ {
13433
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13434
+ System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13435
+ }
13436
+
1243313437 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1243413438
1243513439 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -12476,7 +13480,8 @@
1247613480 "\n" +
1247713481 "END\n";
1247813482
12479
- System.out.println("Program shadow #" + 0 + "; length = " + program.length());
13483
+ if (Globals.DEBUG)
13484
+ System.out.println("Program shadow #" + 0 + "; length = " + program.length());
1248013485 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1248113486
1248213487 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -12521,25 +13526,26 @@
1252113526 return out;
1252213527 }
1252313528
12524
- String TextureFetch(String dest, String src, String unit)
13529
+ // Also does frustum culling
13530
+ String ShadowTextureFetch(String dest, String src, String unit)
1252513531 {
1252613532 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1252713533 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1252813534 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13535
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13536
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1252913537 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12530
- "SLT " + src + ".z, " + src + ".x, one.x;" +
12531
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12532
- "SLT " + src + ".z, " + src + ".y, one.x;" +
12533
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13538
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13539
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1253413540 //"SWZ buffer, temp, w,w,w,w;";
12535
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13541
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1253613542 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1253713543 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1253813544 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
12539
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13545
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1254013546
12541
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
12542
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13547
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13548
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1254313549 }
1254413550
1254513551 String Shadow(String depth, String shadow)
....@@ -12561,12 +13567,16 @@
1256113567
1256213568 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1256313569 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13570
+
13571
+ // Compare fragment depth in light space with shadowmap.
1256413572 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1256513573 "SGE temp.y, temp.x, zero.x;" +
12566
- "SUB " + shadow + ".y, one.x, temp.y;" +
13574
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13575
+
13576
+ // Reverse comparison
1256713577 "SUB temp.x, one.x, temp.x;" +
1256813578 "MUL " + shadow + ".x, temp.x, temp.y;" +
12569
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13579
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1257013580 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1257113581
1257213582 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -12580,6 +13590,10 @@
1258013590 // No shadow for backface
1258113591 "DP3 temp.x, normal, lightd;" +
1258213592 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13593
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13594
+
13595
+ // No shadow when out of frustum
13596
+ "SGE temp.x, " + depth + ".z, one.z;" +
1258313597 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1258413598 "";
1258513599 }
....@@ -12726,7 +13740,8 @@
1272613740 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1272713741 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1272813742 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
12729
- Object3D.cVector2[] vector2buffer;
13743
+
13744
+ //Object3D.cVector2[] vector2buffer;
1273013745
1273113746 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1273213747 // OUT : diff, spec
....@@ -12742,9 +13757,10 @@
1274213757 "DP3 " + dest + ".z," + "normals," + "eye;" +
1274313758 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1274413759 //"MOV " + dest + ".w," + "normal.z;" +
12745
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
12746
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
12747
- //"MOV " + dest + ".z," + "params2.w;" +
13760
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13761
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13762
+
13763
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1274813764 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1274913765 "RCP " + dest + ".w," + dest + ".w;" +
1275013766 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13138,7 +14154,7 @@
1313814154 public void mousePressed(MouseEvent e)
1313914155 {
1314014156 //System.out.println("mousePressed: " + e);
13141
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14157
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1314214158 }
1314314159
1314414160 static long prevtime = 0;
....@@ -13165,6 +14181,7 @@
1316514181
1316614182 //System.err.println("Dtime = " + Dtime + "; units = " + e.getUnitsToScroll() + "; ratio (units/ms) = " + ratio);
1316714183
14184
+ if (BUTTONLESSWHEEL)
1316814185 if (Math.abs(ratio) < 0.1 || Math.abs(Dtime) == 0) // < 30)
1316914186 {
1317014187 return;
....@@ -13173,7 +14190,7 @@
1317314190 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
1317414191
1317514192 // TIMER
13176
- if (!wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
14193
+ if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
1317714194 {
1317814195 keepboxmode = BOXMODE;
1317914196 keepsupport = SUPPORT;
....@@ -13213,8 +14230,8 @@
1321314230 // mode |= META;
1321414231 //}
1321514232
13216
- SetMouseMode(WHEEL | e.getModifiersEx());
13217
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14233
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14234
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1321814235 anchorX = ax;
1321914236 anchorY = ay;
1322014237 prevX = px;
....@@ -13248,6 +14265,7 @@
1324814265 else
1324914266 if (evt.getSource() == AAtimer)
1325014267 {
14268
+ Globals.TIMERRUNNING = false;
1325114269 if (mouseDown)
1325214270 {
1325314271 //new Exception().printStackTrace();
....@@ -13273,6 +14291,10 @@
1327314291 // LIVE = waslive;
1327414292 // wasliveok = true;
1327514293 // waslive = false;
14294
+
14295
+ // May 2019 Forget it:
14296
+ if (true)
14297
+ return;
1327614298
1327714299 // source == timer
1327814300 if (mouseDown)
....@@ -13303,7 +14325,7 @@
1330314325
1330414326 // fev 2014???
1330514327 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13306
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14328
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1330714329 pingthread.StepToTarget(true); // true);
1330814330 }
1330914331 // if (!LIVE)
....@@ -13312,12 +14334,13 @@
1331214334
1331314335 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1331414336
13315
- void clickStart(int x, int y, int modifiers)
14337
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1331614338 {
1331714339 if (!wasliveok)
1331814340 return;
1331914341
1332014342 AAtimer.restart(); //
14343
+ Globals.TIMERRUNNING = true;
1332114344
1332214345 // waslive = LIVE;
1332314346 // LIVE = false;
....@@ -13329,7 +14352,7 @@
1332914352 // touched = true; // main DL
1333014353 if (isRenderer)
1333114354 {
13332
- SetMouseMode(modifiers);
14355
+ SetMouseMode(modifiers, modifiersex);
1333314356 }
1333414357
1333514358 selectX = anchorX = x;
....@@ -13342,7 +14365,7 @@
1334214365 clicked = true;
1334314366 hold = false;
1334414367
13345
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14368
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1334614369 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1334714370 {
1334814371 // System.out.println("RESTART II " + modifiers);
....@@ -13367,14 +14390,15 @@
1336714390 drag = false;
1336814391 //System.out.println("Mouse DOWN");
1336914392 editObj = false;
13370
- ClickInfo info = new ClickInfo();
13371
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
13372
- info.pane = this;
13373
- info.camera = renderCamera;
13374
- info.x = x;
13375
- info.y = y;
13376
- info.modifiers = modifiers;
13377
- editObj = object.doEditClick(info, 0);
14393
+ //ClickInfo info = new ClickInfo();
14394
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14395
+ object.clickInfo.pane = this;
14396
+ object.clickInfo.camera = renderCamera;
14397
+ object.clickInfo.x = x;
14398
+ object.clickInfo.y = y;
14399
+ object.clickInfo.modifiers = modifiersex;
14400
+ editObj = object.doEditClick(//info,
14401
+ 0);
1337814402 if (!editObj)
1337914403 {
1338014404 hasMarquee = true;
....@@ -13390,11 +14414,14 @@
1339014414
1339114415 public void mouseDragged(MouseEvent e)
1339214416 {
14417
+ Globals.MOUSEDRAGGED = true;
14418
+
14419
+ //System.out.println("mouseDragged: " + e);
1339314420 if (isRenderer)
1339414421 movingcamera = true;
14422
+
1339514423 //if (drawing)
1339614424 //return;
13397
- //System.out.println("mouseDragged: " + e);
1339814425 if ((e.getModifiersEx() & CTRL) != 0
1339914426 || (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen())
1340014427 {
....@@ -13402,7 +14429,7 @@
1340214429 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1340314430 }
1340414431 else
13405
- drag(e.getX(), e.getY(), e.getModifiersEx());
14432
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1340614433
1340714434 //try { Thread.sleep(1); } catch (Exception ex) {}
1340814435 }
....@@ -13575,6 +14602,7 @@
1357514602
1357614603 public void run()
1357714604 {
14605
+ new Exception().printStackTrace();
1357814606 System.exit(0);
1357914607 for (;;)
1358014608 {
....@@ -13638,7 +14666,7 @@
1363814666 {
1363914667 Globals.lighttouched = true;
1364014668 }
13641
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14669
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1364214670 }
1364314671 //else
1364414672 }
....@@ -13652,12 +14680,18 @@
1365214680 void GoDown(int mod)
1365314681 {
1365414682 MODIFIERS |= COMMAND;
13655
- /*
14683
+ boolean isVR = (mouseMode&VR)!=0;
14684
+ /**/
1365614685 if((mod&SHIFT) == SHIFT)
13657
- manipCamera.RotatePosition(0, -speed);
14686
+ {
14687
+ if (isVR)
14688
+ manipCamera.RotateInterest(0, -speed);
14689
+ else
14690
+ manipCamera.RotatePosition(0, -speed);
14691
+ }
1365814692 else
13659
- manipCamera.BackForth(0, -speed*delta, getWidth());
13660
- */
14693
+ manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth());
14694
+ /**/
1366114695 if ((mod & SHIFT) == SHIFT)
1366214696 {
1366314697 mouseMode = mouseMode; // VR??
....@@ -13666,6 +14700,8 @@
1366614700 mouseMode |= BACKFORTH;
1366714701 }
1366814702
14703
+ targetLookAt.set(manipCamera.lookAt);
14704
+
1366914705 //prevX = X = anchorX;
1367014706 prevY = Y = anchorY - (int) (renderCamera.Distance());
1367114707 }
....@@ -13673,12 +14709,19 @@
1367314709 void GoUp(int mod)
1367414710 {
1367514711 MODIFIERS |= COMMAND;
13676
- /*
14712
+ /**/
14713
+ boolean isVR = (mouseMode&VR)!=0;
14714
+
1367714715 if((mod&SHIFT) == SHIFT)
13678
- manipCamera.RotatePosition(0, speed);
14716
+ {
14717
+ if (isVR)
14718
+ manipCamera.RotateInterest(0, speed);
14719
+ else
14720
+ manipCamera.RotatePosition(0, speed);
14721
+ }
1367914722 else
13680
- manipCamera.BackForth(0, speed*delta, getWidth());
13681
- */
14723
+ manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth());
14724
+ /**/
1368214725 if ((mod & SHIFT) == SHIFT)
1368314726 {
1368414727 mouseMode = mouseMode;
....@@ -13687,6 +14730,8 @@
1368714730 mouseMode |= BACKFORTH;
1368814731 }
1368914732
14733
+ targetLookAt.set(manipCamera.lookAt);
14734
+
1369014735 //prevX = X = anchorX;
1369114736 prevY = Y = anchorY + (int) (renderCamera.Distance());
1369214737 }
....@@ -13694,12 +14739,17 @@
1369414739 void GoLeft(int mod)
1369514740 {
1369614741 MODIFIERS |= COMMAND;
13697
- /*
14742
+ /**/
1369814743 if((mod&SHIFT) == SHIFT)
13699
- manipCamera.RotatePosition(speed, 0);
14744
+ manipCamera.Translate(speed*delta, 0, getWidth());
1370014745 else
13701
- manipCamera.Translate(speed*delta, 0, getWidth());
13702
- */
14746
+ {
14747
+ if ((mouseMode&VR)!=0)
14748
+ manipCamera.RotateInterest(-speed, 0);
14749
+ else
14750
+ manipCamera.RotatePosition(speed, 0);
14751
+ }
14752
+ /**/
1370314753 if ((mod & SHIFT) == SHIFT)
1370414754 {
1370514755 mouseMode = mouseMode;
....@@ -13708,6 +14758,8 @@
1370814758 mouseMode |= ROTATE;
1370914759 } // TRANSLATE;
1371014760
14761
+ targetLookAt.set(manipCamera.lookAt);
14762
+
1371114763 prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance());
1371214764 prevY = Y = anchorY;
1371314765 }
....@@ -13715,12 +14767,18 @@
1371514767 void GoRight(int mod)
1371614768 {
1371714769 MODIFIERS |= COMMAND;
13718
- /*
14770
+ /**/
1371914771 if((mod&SHIFT) == SHIFT)
13720
- manipCamera.RotatePosition(-speed, 0);
14772
+ manipCamera.Translate(-speed*delta, 0, getWidth());
1372114773 else
13722
- manipCamera.Translate(-speed*delta, 0, getWidth());
13723
- */
14774
+ {
14775
+ if ((mouseMode&VR)!=0)
14776
+ manipCamera.RotateInterest(speed, 0);
14777
+ else
14778
+ manipCamera.RotatePosition(-speed, 0);
14779
+ }
14780
+
14781
+ /**/
1372414782 if ((mod & SHIFT) == SHIFT)
1372514783 {
1372614784 mouseMode = mouseMode;
....@@ -13729,6 +14787,8 @@
1372914787 mouseMode |= ROTATE;
1373014788 } // TRANSLATE;
1373114789
14790
+ targetLookAt.set(manipCamera.lookAt);
14791
+
1373214792 prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance());
1373314793 prevY = Y = anchorY;
1373414794 }
....@@ -13738,7 +14798,7 @@
1373814798 int X, Y;
1373914799 boolean SX, SY;
1374014800
13741
- void drag(int x, int y, int modifiers)
14801
+ void drag(int x, int y, int modifiers, int modifiersex)
1374214802 {
1374314803 if (IsFrozen())
1374414804 {
....@@ -13747,17 +14807,17 @@
1374714807
1374814808 drag = true; // NEW
1374914809
13750
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14810
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1375114811
1375214812 X = x;
1375314813 Y = y;
1375414814 // floating state for animation
13755
- MODIFIERS = modifiers;
13756
- modifiers &= ~1024;
14815
+ MODIFIERS = modifiersex;
14816
+ modifiersex &= ~1024;
1375714817 if (false) // modifiers != 0)
1375814818 {
1375914819 //new Exception().printStackTrace();
13760
- System.out.println("mouseDragged: " + modifiers);
14820
+ System.out.println("mouseDragged: " + modifiersex);
1376114821 System.out.println("SHIFT = " + SHIFT);
1376214822 System.out.println("CONTROL = " + COMMAND);
1376314823 System.out.println("META = " + META);
....@@ -13770,14 +14830,16 @@
1377014830 if (editObj)
1377114831 {
1377214832 drag = true;
13773
- ClickInfo info = new ClickInfo();
13774
- info.bounds.setBounds(0, 0,
14833
+ //ClickInfo info = new ClickInfo();
14834
+ object.clickInfo.bounds.setBounds(0, 0,
1377514835 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
13776
- info.pane = this;
13777
- info.camera = renderCamera;
13778
- info.x = x;
13779
- info.y = y;
13780
- object.editWindow.copy.doEditDrag(info);
14836
+ object.clickInfo.pane = this;
14837
+ object.clickInfo.camera = renderCamera;
14838
+ object.clickInfo.x = x;
14839
+ object.clickInfo.y = y;
14840
+ object //.GetWindow().copy
14841
+ .doEditDrag(//info,
14842
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1378114843 } else
1378214844 {
1378314845 if (x < startX)
....@@ -13926,23 +14988,27 @@
1392614988 }
1392714989 }
1392814990
14991
+// ClickInfo clickInfo = new ClickInfo();
14992
+
1392914993 public void mouseMoved(MouseEvent e)
1393014994 {
1393114995 //System.out.println("mouseMoved: " + e);
13932
-
1393314996 if (isRenderer)
1393414997 return;
1393514998
13936
- ClickInfo ci = new ClickInfo();
13937
- ci.x = e.getX();
13938
- ci.y = e.getY();
13939
- ci.modifiers = e.getModifiersEx();
13940
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
13941
- ci.pane = this;
13942
- ci.camera = renderCamera;
14999
+ // Mouse cursor feedback
15000
+ object.clickInfo.x = e.getX();
15001
+ object.clickInfo.y = e.getY();
15002
+ object.clickInfo.modifiers = e.getModifiersEx();
15003
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
15004
+ object.clickInfo.pane = this;
15005
+ object.clickInfo.camera = renderCamera;
1394315006 if (!isRenderer)
1394415007 {
13945
- if (object.editWindow.copy.doEditClick(ci, 0))
15008
+ //ObjEditor editWindow = object.editWindow;
15009
+ //Object3D copy = editWindow.copy;
15010
+ if (object.doEditClick(//clickInfo,
15011
+ 0))
1394615012 {
1394715013 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1394815014 } else
....@@ -13954,7 +15020,11 @@
1395415020
1395515021 public void mouseReleased(MouseEvent e)
1395615022 {
15023
+ Globals.MOUSEDRAGGED = false;
15024
+
1395715025 movingcamera = false;
15026
+ X = 0; // getBounds().width/2;
15027
+ Y = 0; // getBounds().height/2;
1395815028 //System.out.println("mouseReleased: " + e);
1395915029 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1396015030 }
....@@ -13977,9 +15047,9 @@
1397715047 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1397815048 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1397915049
13980
- if (control || command || IsFrozen())
15050
+// No delay if (control || command || IsFrozen())
1398115051 timeout = true;
13982
- else
15052
+// ?? May 2019 else
1398315053 // timer.setDelay((modifiers & 128) != 0?0:350);
1398415054 mouseDown = false;
1398515055 if (!control && !command) // june 2013
....@@ -14089,7 +15159,7 @@
1408915159 System.out.println("keyReleased: " + e);
1409015160 }
1409115161
14092
- void SetMouseMode(int modifiers)
15162
+ void SetMouseMode(int modifiers, int modifiersex)
1409315163 {
1409415164 //System.out.println("SetMouseMode = " + modifiers);
1409515165 //modifiers &= ~1024;
....@@ -14101,25 +15171,25 @@
1410115171 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1410215172 // return;
1410315173 //System.out.println("SetMode = " + modifiers);
14104
- if ((modifiers & WHEEL) == WHEEL)
15174
+ if ((modifiersex & WHEEL) == WHEEL)
1410515175 {
1410615176 mouseMode |= ZOOM;
1410715177 }
1410815178
1410915179 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
14110
- if (capsLocked || (modifiers & META) == META)
15180
+ if (capsLocked) // || (modifiers & META) == META)
1411115181 {
1411215182 mouseMode |= VR; // BACKFORTH;
1411315183 }
14114
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
15184
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1411515185 {
1411615186 mouseMode |= SELECT;
1411715187 }
14118
- if ((modifiers & COMMAND) == COMMAND)
15188
+ if ((modifiersex & COMMAND) == COMMAND)
1411915189 {
1412015190 mouseMode |= SELECT;
1412115191 }
14122
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15192
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
1412315193 {
1412415194 mouseMode &= ~VR;
1412515195 mouseMode |= TRANSLATE;
....@@ -14148,7 +15218,7 @@
1414815218
1414915219 if (isRenderer) //
1415015220 {
14151
- SetMouseMode(modifiers);
15221
+ SetMouseMode(0, modifiers);
1415215222 }
1415315223
1415415224 Globals.theRenderer.keyPressed(key);
....@@ -14210,7 +15280,8 @@
1421015280 // break;
1421115281 case 'T':
1421215282 CACHETEXTURE ^= true;
14213
- textures.clear();
15283
+ texturepigment.clear();
15284
+ texturebump.clear();
1421415285 // repaint();
1421515286 break;
1421615287 case 'Y':
....@@ -14220,8 +15291,8 @@
1422015291 case 'K':
1422115292 KOMPACTTEXTURE ^= true;
1422215293 //textures.clear();
14223
- break;
14224
- case 'P': // Texture Projection macros
15294
+ // break;
15295
+ //case 'P': // Texture Projection macros
1422515296 // SAVETEXTURE ^= true;
1422615297 macromode = true;
1422715298 Udebug = Vdebug = NORMALdebug = false; programInitialized = false;
....@@ -14295,7 +15366,9 @@
1429515366 case 'E' : COMPACT ^= true;
1429615367 repaint();
1429715368 break;
14298
- case 'W' : DEBUGHSB ^= true;
15369
+ case 'W' : // Wide Window (fullscreen)
15370
+ //DEBUGHSB ^= true;
15371
+ ObjEditor.theFrame.ToggleFullScreen();
1429915372 repaint();
1430015373 break;
1430115374 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14320,8 +15393,8 @@
1432015393 RevertCamera();
1432115394 repaint();
1432215395 break;
14323
- case 'L':
1432415396 case 'l':
15397
+ //case 'L':
1432515398 if (lightMode)
1432615399 {
1432715400 lightMode = false;
....@@ -14340,7 +15413,7 @@
1434015413 targetLookAt.set(manipCamera.lookAt);
1434115414 repaint();
1434215415 break;
14343
- case 'p':
15416
+ case 'P': // p':
1434415417 // c'est quoi ca au juste? spherical ^= true;
1434515418 Skinshader ^= true; programInitialized = false;
1434615419 repaint();
....@@ -14385,20 +15458,24 @@
1438515458 OCCLUSION_CULLING ^= true;
1438615459 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1438715460 break;
14388
- case '0': envyoff ^= true; repaint(); break;
15461
+ //case '0': envyoff ^= true; repaint(); break;
1438915462 case '1':
1439015463 case '2':
1439115464 case '3':
1439215465 case '4':
1439315466 case '5':
14394
- newenvy = Character.getNumericValue(key);
14395
- repaint();
14396
- break;
1439715467 case '6':
1439815468 case '7':
1439915469 case '8':
1440015470 case '9':
14401
- BGcolor = (key - '6')/3.f;
15471
+ if (true) // envyoff)
15472
+ {
15473
+ BGcolor = (key - '1')/8.f;
15474
+ }
15475
+ else
15476
+ {
15477
+ //newenvy = Character.getNumericValue(key);
15478
+ }
1440215479 repaint();
1440315480 break;
1440415481 case '!':
....@@ -14464,9 +15541,9 @@
1446415541 case '_':
1446515542 kompactbit = 5;
1446615543 break;
14467
- case '+':
14468
- kompactbit = 6;
14469
- break;
15544
+// case '+':
15545
+// kompactbit = 6;
15546
+// break;
1447015547 case ' ':
1447115548 lightMode ^= true;
1447215549 Globals.lighttouched = true;
....@@ -14478,13 +15555,14 @@
1447815555 case ESC:
1447915556 RENDERPROGRAM += 1;
1448015557 RENDERPROGRAM %= 3;
15558
+
1448115559 repaint();
1448215560 break;
1448315561 case 'Z':
1448415562 //RESIZETEXTURE ^= true;
1448515563 //break;
1448615564 case 'z':
14487
- RENDERSHADOW ^= true;
15565
+ Globals.RENDERSHADOW ^= true;
1448815566 Globals.lighttouched = true;
1448915567 repaint();
1449015568 break;
....@@ -14517,8 +15595,9 @@
1451715595 case DELETE:
1451815596 ClearSelection();
1451915597 break;
14520
- /*
1452115598 case '+':
15599
+
15600
+ /*
1452215601 //fontsize += 1;
1452315602 bbzoom *= 2;
1452415603 repaint();
....@@ -14535,17 +15614,17 @@
1453515614 case '=':
1453615615 IncDepth();
1453715616 //fontsize += 1;
14538
- object.editWindow.refreshContents(true);
15617
+ object.GetWindow().refreshContents(true);
1453915618 maskbit = 6;
1454015619 break;
1454115620 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1454215621 DecDepth();
1454315622 maskbit = 5;
1454415623 //if(fontsize > 1) fontsize -= 1;
14545
- if (object.editWindow == null)
14546
- new Exception().printStackTrace();
14547
- else
14548
- object.editWindow.refreshContents(true);
15624
+// if (object.editWindow == null)
15625
+// new Exception().printStackTrace();
15626
+// else
15627
+ object.GetWindow().refreshContents(true);
1454915628 break;
1455015629 case '{':
1455115630 manipCamera.shaper_fovy /= 1.1;
....@@ -14608,7 +15687,7 @@
1460815687 //mode = ROTATE;
1460915688 if ((MODIFIERS & COMMAND) == 0) // VR??
1461015689 {
14611
- SetMouseMode(modifiers);
15690
+ SetMouseMode(0, modifiers);
1461215691 }
1461315692 }
1461415693
....@@ -14742,8 +15821,9 @@
1474215821
1474315822 protected void processMouseMotionEvent(MouseEvent e)
1474415823 {
14745
- //System.out.println("processMouseMotionEvent: " + mouseMode);
14746
- if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15824
+ //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
15825
+ //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15826
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1474715827 {
1474815828 mouseMoved(e);
1474915829 } else
....@@ -14768,11 +15848,12 @@
1476815848 }
1476915849 */
1477015850
14771
- object.editWindow.EditSelection();
15851
+ object.GetWindow().EditSelection(false);
1477215852 }
1477315853
1477415854 void SelectParent()
1477515855 {
15856
+ new Exception().printStackTrace();
1477615857 System.exit(0);
1477715858 Composite group = (Composite) object;
1477815859 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -14784,10 +15865,10 @@
1478415865 {
1478515866 //selectees.remove(i);
1478615867 System.out.println("select parent of " + elem);
14787
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15868
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1478815869 } else
1478915870 {
14790
- group.editWindow.Select(elem.GetTreePath(), first, true);
15871
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1479115872 }
1479215873
1479315874 first = false;
....@@ -14796,6 +15877,7 @@
1479615877
1479715878 void SelectChildren()
1479815879 {
15880
+ new Exception().printStackTrace();
1479915881 System.exit(0);
1480015882 /*
1480115883 Composite group = (Composite) object;
....@@ -14828,12 +15910,12 @@
1482815910 for (int j = 0; j < group.children.size(); j++)
1482915911 {
1483015912 elem = (Object3D) group.children.elementAt(j);
14831
- object.editWindow.Select(elem.GetTreePath(), first, true);
15913
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1483215914 first = false;
1483315915 }
1483415916 } else
1483515917 {
14836
- object.editWindow.Select(elem.GetTreePath(), first, true);
15918
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1483715919 }
1483815920
1483915921 first = false;
....@@ -14844,21 +15926,21 @@
1484415926 {
1484515927 //Composite group = (Composite) object;
1484615928 Object3D group = object;
14847
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15929
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1484815930 }
1484915931
1485015932 void ResetTransform(int mask)
1485115933 {
1485215934 //Composite group = (Composite) object;
1485315935 Object3D group = object;
14854
- group.editWindow.ResetTransform(mask);
15936
+ group.GetWindow().ResetTransform(mask);
1485515937 }
1485615938
1485715939 void FlipTransform()
1485815940 {
1485915941 //Composite group = (Composite) object;
1486015942 Object3D group = object;
14861
- group.editWindow.FlipTransform();
15943
+ group.GetWindow().FlipTransform();
1486215944 // group.editWindow.ReduceMesh(true);
1486315945 }
1486415946
....@@ -14866,7 +15948,7 @@
1486615948 {
1486715949 //Composite group = (Composite) object;
1486815950 Object3D group = object;
14869
- group.editWindow.PrintMemory();
15951
+ group.GetWindow().PrintMemory();
1487015952 // group.editWindow.ReduceMesh(true);
1487115953 }
1487215954
....@@ -14874,7 +15956,7 @@
1487415956 {
1487515957 //Composite group = (Composite) object;
1487615958 Object3D group = object;
14877
- group.editWindow.ResetCentroid();
15959
+ group.GetWindow().ResetCentroid();
1487815960 }
1487915961
1488015962 void IncDepth()
....@@ -14956,11 +16038,11 @@
1495616038
1495716039 int width = getBounds().width;
1495816040 int height = getBounds().height;
14959
- ClickInfo info = new ClickInfo();
14960
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1496116041 //Image img = CreateImage(width, height);
1496216042 //System.out.println("width = " + width + "; height = " + height + "\n");
16043
+
1496316044 Graphics gr = g; // img.getGraphics();
16045
+
1496416046 if (!hasMarquee)
1496516047 {
1496616048 if (Xmin < Xmax) // !locked)
....@@ -15032,44 +16114,92 @@
1503216114 }
1503316115 if (object != null && !hasMarquee)
1503416116 {
16117
+ if (object.clickInfo == null)
16118
+ object.clickInfo = new ClickInfo();
16119
+ ClickInfo info = object.clickInfo;
16120
+ //ClickInfo info = new ClickInfo();
16121
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16122
+
1503516123 if (isRenderer)
1503616124 {
15037
- info.flags++;
16125
+ object.clickInfo.flags++;
1503816126 double frameAspect = (double) width / (double) height;
1503916127 if (frameAspect > renderCamera.aspect)
1504016128 {
1504116129 int desired = (int) ((double) height * renderCamera.aspect);
15042
- info.bounds.width -= width - desired;
15043
- info.bounds.x += (width - desired) / 2;
16130
+ object.clickInfo.bounds.width -= width - desired;
16131
+ object.clickInfo.bounds.x += (width - desired) / 2;
1504416132 } else
1504516133 {
1504616134 int desired = (int) ((double) width / renderCamera.aspect);
15047
- info.bounds.height -= height - desired;
15048
- info.bounds.y += (height - desired) / 2;
16135
+ object.clickInfo.bounds.height -= height - desired;
16136
+ object.clickInfo.bounds.y += (height - desired) / 2;
1504916137 }
1505016138 }
15051
- info.g = gr;
15052
- info.camera = renderCamera;
16139
+
16140
+ object.clickInfo.g = gr;
16141
+ object.clickInfo.camera = renderCamera;
1505316142 /*
1505416143 // Memory intensive (brep.verticescopy)
1505516144 if (!(object instanceof Composite))
1505616145 object.draw(info, 0, false); // SLOW :
1505716146 */
15058
- if (!isRenderer)
16147
+ if (!isRenderer) // && drag)
1505916148 {
15060
- object.drawEditHandles(info, 0);
16149
+ Grafreed.Assert(object != null);
16150
+ Grafreed.Assert(object.selection != null);
16151
+ if (object.selection.Size() > 0)
16152
+ {
16153
+ int hitSomething = object.selection.get(0).hitSomething;
16154
+
16155
+ object.clickInfo.DX = 0;
16156
+ object.clickInfo.DY = 0;
16157
+ object.clickInfo.W = 1;
16158
+ if (hitSomething == Object3D.hitCenter)
16159
+ {
16160
+ info.DX = X;
16161
+ if (X != 0)
16162
+ info.DX -= info.bounds.width/2;
16163
+
16164
+ info.DY = Y;
16165
+ if (Y != 0)
16166
+ info.DY -= info.bounds.height/2;
16167
+ }
16168
+
16169
+ object.drawEditHandles(//info,
16170
+ 0);
16171
+
16172
+ if (drag && (X != 0 || Y != 0))
16173
+ {
16174
+ switch (hitSomething)
16175
+ {
16176
+ case Object3D.hitCenter: gr.setColor(Color.white);
16177
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16178
+ break;
16179
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16180
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16181
+ break;
16182
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16183
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16184
+ break;
16185
+ }
16186
+
16187
+ }
16188
+ }
1506116189 }
1506216190 }
16191
+
1506316192 if (isRenderer)
1506416193 {
1506516194 //gr.setColor(Color.black);
1506616195 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1506716196 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1506816197 }
16198
+
1506916199 if (hasMarquee)
1507016200 {
1507116201 gr.setXORMode(Color.white);
15072
- gr.setColor(Color.red);
16202
+ gr.setColor(Color.white);
1507316203 if (!firstime)
1507416204 {
1507516205 gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH);
....@@ -15178,6 +16308,7 @@
1517816308 public boolean mouseDown(Event evt, int x, int y)
1517916309 {
1518016310 System.out.println("mouseDown: " + evt);
16311
+ System.exit(0);
1518116312 /*
1518216313 locked = true;
1518316314 drag = false;
....@@ -15221,7 +16352,7 @@
1522116352 {
1522216353 keyPressed(0, modifiers);
1522316354 }
15224
- clickStart(x, y, modifiers);
16355
+ // clickStart(x, y, modifiers);
1522516356 return true;
1522616357 }
1522716358
....@@ -15339,7 +16470,7 @@
1533916470 {
1534016471 keyReleased(0, 0);
1534116472 }
15342
- drag(x, y, modifiers);
16473
+ drag(x, y, 0, modifiers);
1534316474 return true;
1534416475 }
1534516476
....@@ -15471,7 +16602,7 @@
1547116602 Object3D object;
1547216603 static Object3D trackedobject;
1547316604 Camera renderCamera; // Light or Eye (or Occlusion)
15474
- /*static*/ Camera manipCamera; // Light or Eye
16605
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1547516606 /*static*/ Camera eyeCamera;
1547616607 /*static*/ Camera lightCamera;
1547716608 int cameracount;
....@@ -15535,6 +16666,8 @@
1553516666 private /*static*/ boolean firstime;
1553616667 private /*static*/ cVector newView = new cVector();
1553716668 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16669
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16670
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1553816671 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1553916672 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1554016673 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -15547,29 +16680,67 @@
1554716680 {
1554816681 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1554916682
16683
+ int usedsuf = 0;
16684
+
1555016685 for (int i = 0; i < suffixes.length; i++)
1555116686 {
15552
- String resourceName = basename + suffixes[i] + "." + suffix;
15553
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
15554
- mipmapped,
15555
- FileUtil.getFileSuffix(resourceName));
15556
- if (data == null)
16687
+ String[] suffixe = suffixes;
16688
+ String[] fallback = suffixes2;
16689
+ String[] fallfallback = suffixes3;
16690
+
16691
+ for (int c=usedsuf; --c>=0;)
1555716692 {
15558
- throw new IOException("Unable to load texture " + resourceName);
16693
+// String[] temp = suffixe;
16694
+// suffixe = fallback;
16695
+// fallback = fallfallback;
16696
+// fallfallback = temp;
1555916697 }
16698
+
16699
+ String resourceName = basename + suffixe[i] + "." + suffix;
16700
+ TextureData data;
16701
+
16702
+ try
16703
+ {
16704
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16705
+ mipmapped,
16706
+ FileUtil.getFileSuffix(resourceName));
16707
+ }
16708
+ catch (Exception e)
16709
+ {
16710
+ try
16711
+ {
16712
+ resourceName = basename + fallback[i] + "." + suffix;
16713
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16714
+ mipmapped,
16715
+ FileUtil.getFileSuffix(resourceName));
16716
+ }
16717
+ catch (Exception e2)
16718
+ {
16719
+ resourceName = basename + fallfallback[i] + "." + suffix;
16720
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16721
+ mipmapped,
16722
+ FileUtil.getFileSuffix(resourceName));
16723
+ }
16724
+ }
16725
+
1556016726 //System.out.println("Target = " + targets[i]);
1556116727 cubemap.updateImage(data, targets[i]);
1556216728 }
1556316729
1556416730 return cubemap;
1556516731 }
16732
+
1556616733 int bigsphere = -1;
1556716734
1556816735 float BGcolor = 0.5f;
1556916736
15570
- private void DrawSkyBox(GL gl)
16737
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16738
+
16739
+ private void DrawSkyBox(GL gl, float ratio)
1557116740 {
15572
- if (envyoff || cubemap == null)
16741
+ if (//envyoff ||
16742
+ WIREFRAME ||
16743
+ cubemap == null)
1557316744 {
1557416745 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1557516746 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -15584,7 +16755,17 @@
1558416755 // Compensates for ExaminerViewer's modification of modelview matrix
1558516756 gl.glMatrixMode(GL.GL_MODELVIEW);
1558616757 gl.glLoadIdentity();
16758
+ gl.glScalef(1,ratio,1);
1558716759
16760
+// colorV[0] = 2;
16761
+// colorV[1] = 2;
16762
+// colorV[2] = 2;
16763
+// colorV[3] = 1;
16764
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16765
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16766
+//
16767
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16768
+
1558816769 //gl.glActiveTexture(GL.GL_TEXTURE1);
1558916770 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1559016771
....@@ -15616,6 +16797,7 @@
1561616797 {
1561716798 gl.glScalef(1.0f, -1.0f, 1.0f);
1561816799 }
16800
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1561916801 gl.glMultMatrixd(viewrot_1, 0);
1562016802 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1562116803 //viewer.updateInverseRotation(gl);
....@@ -15656,7 +16838,8 @@
1565616838 gl.glDisable(GL.GL_TEXTURE_GEN_R);
1565716839
1565816840 cubemap.disable();
15659
- ////cubemap.unbind();
16841
+ //cubemap.dispose();
16842
+
1566016843 if (CULLFACE)
1566116844 {
1566216845 gl.glEnable(gl.GL_CULL_FACE);
....@@ -15756,16 +16939,16 @@
1575616939 cStatic.objectstack[materialdepth++] = checker;
1575716940 //System.out.println("material " + material);
1575816941 //Applet3D.tracein(this, selected);
15759
- vector2buffer = checker.projectedVertices;
16942
+ //vector2buffer = checker.projectedVertices;
1576016943
1576116944 //checker.GetMaterial().Draw(this, false); // true);
15762
- DrawMaterial(checker.GetMaterial(), false); // true);
16945
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1576316946
1576416947 materialdepth -= 1;
1576516948 if (materialdepth > 0)
1576616949 {
15767
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
15768
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
16950
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16951
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1576916952 }
1577016953 //checker.GetMaterial().opacity = 1f;
1577116954 ////checker.GetMaterial().ambient = 1f;
....@@ -15851,6 +17034,14 @@
1585117034 }
1585217035 }
1585317036
17037
+ private Object3D GetFolder()
17038
+ {
17039
+ Object3D folder = object.GetWindow().copy;
17040
+ if (object.GetWindow().copy.selection.Size() > 0)
17041
+ folder = object.GetWindow().copy.selection.elementAt(0);
17042
+ return folder;
17043
+ }
17044
+
1585417045 class SelectBuffer implements GLEventListener
1585517046 {
1585617047
....@@ -15866,7 +17057,7 @@
1586617057 //new Exception().printStackTrace();
1586717058 System.out.println("select buffer init");
1586817059 // Use debug pipeline
15869
- drawable.setGL(new DebugGL(drawable.getGL()));
17060
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1587017061
1587117062 GL gl = drawable.getGL();
1587217063
....@@ -15909,6 +17100,7 @@
1590917100 {
1591017101 if (!selection)
1591117102 {
17103
+ new Exception().printStackTrace();
1591217104 System.exit(0);
1591317105 return;
1591417106 }
....@@ -15929,6 +17121,17 @@
1592917121
1593017122 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1593117123
17124
+ if (PAINTMODE)
17125
+ {
17126
+ if (object.GetWindow().copy.selection.Size() > 0)
17127
+ {
17128
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17129
+
17130
+ // Make what you paint not selectable.
17131
+ paintobj.ResetSelectable();
17132
+ }
17133
+ }
17134
+
1593217135 //int tmp = selection_view;
1593317136 //selection_view = -1;
1593417137 int temp = DrawMode();
....@@ -15940,6 +17143,17 @@
1594017143 // temp = DEFAULT; // patch for selection debug
1594117144 Globals.drawMode = temp; // WARNING
1594217145
17146
+ if (PAINTMODE)
17147
+ {
17148
+ if (object.GetWindow().copy.selection.Size() > 0)
17149
+ {
17150
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17151
+
17152
+ // Revert.
17153
+ paintobj.RestoreSelectable();
17154
+ }
17155
+ }
17156
+
1594317157 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1594417158
1594517159 // trying different ways of getting the depth info over
....@@ -15987,6 +17201,8 @@
1598717201 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1598817202 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1598917203 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
17204
+
17205
+ CreateSelectedPoint();
1599017206
1599117207 // Will fit the mesh !!!
1599217208 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16036,34 +17252,36 @@
1603617252 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]));
1603717253 }
1603817254
16039
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
17255
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1604017256 }
1604117257 }
1604217258
1604317259 if (!movingcamera && !PAINTMODE)
16044
- object.editWindow.ScreenFitPoint(); // fev 2014
17260
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1604517261
16046
- if (PAINTMODE && GrafreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17262
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1604717263 {
16048
- Object3D paintobj = GrafreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17264
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1604917265
16050
- Object3D group = new Object3D("inst" + paintcount++);
17266
+ if (object.GetWindow().copy.selection.Size() > 0)
17267
+ {
17268
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1605117269
16052
- group.CreateMaterial(); // use a void leaf to select instances
16053
-
16054
- group.add(paintobj); // link
16055
-
16056
- object.editWindow.SnapObject(group);
16057
-
16058
- Object3D folder = object.editWindow.copy;
16059
-
16060
- if (object.editWindow.copy.selection.Size() > 0)
16061
- folder = object.editWindow.copy.selection.elementAt(0);
16062
-
16063
- folder.add(group);
16064
-
16065
- object.editWindow.ResetModel();
16066
- object.editWindow.refreshContents();
17270
+ Object3D inst = new Object3D("inst" + paintcount++);
17271
+
17272
+ inst.CreateMaterial(); // use a void leaf to select instances
17273
+
17274
+ inst.add(paintobj); // link
17275
+
17276
+ object.GetWindow().SnapObject(inst);
17277
+
17278
+ Object3D folder = paintFolder; // GetFolder();
17279
+
17280
+ folder.add(inst);
17281
+
17282
+ object.GetWindow().ResetModel();
17283
+ object.GetWindow().refreshContents();
17284
+ }
1606717285 }
1606817286 else
1606917287 paintcount = 0;
....@@ -16102,6 +17320,11 @@
1610217320 //System.out.println("objects[color] = " + objects[color]);
1610317321 //objects[color].Select();
1610417322 indexcount = 0;
17323
+ ObjEditor window = object.GetWindow();
17324
+ if (window != null && deselect)
17325
+ {
17326
+ window.Select(null, deselect, true);
17327
+ }
1610517328 object.Select(color, deselect);
1610617329 }
1610717330
....@@ -16152,6 +17375,7 @@
1615217375
1615317376 public void init(GLAutoDrawable drawable)
1615417377 {
17378
+ if (Globals.DEBUG)
1615517379 System.out.println("shadow buffer init");
1615617380
1615717381 GL gl = drawable.getGL();
....@@ -16201,7 +17425,7 @@
1620117425 gl.glDisable(gl.GL_CULL_FACE);
1620217426 }
1620317427
16204
- if (!RENDERSHADOW)
17428
+ if (!Globals.RENDERSHADOW)
1620517429 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1620617430
1620717431 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -16211,7 +17435,7 @@
1621117435 //gl.glColorMask(false, false, false, false);
1621217436
1621317437 //render_scene_from_light_view(gl, drawable, 0, 0);
16214
- if (RENDERSHADOW && Globals.lighttouched && !movingcamera) // && !parent.IsFreezed())
17438
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1621517439 {
1621617440 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1621717441
....@@ -16380,10 +17604,14 @@
1638017604 gl.glFlush();
1638117605
1638217606 /**/
16383
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17607
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1638417608
16385
- float[] pixels = occlusionsizebuffer.array();
17609
+ float[] depths = occlusiondepthbuffer.array();
1638617610
17611
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17612
+
17613
+ int[] pixels = selectsizebuffer.array();
17614
+
1638717615 double r = 0, g = 0, b = 0;
1638817616
1638917617 double count = 0;
....@@ -16394,7 +17622,7 @@
1639417622
1639517623 double FACTOR = 1;
1639617624
16397
- for (int i = 0; i < pixels.length; i++)
17625
+ for (int i = 0; i < depths.length; i++)
1639817626 {
1639917627 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1640017628 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -16477,7 +17705,7 @@
1647717705
1647817706 double scale = ray.z; // 1; // cos
1647917707
16480
- float depth = pixels[newindex];
17708
+ float depth = depths[newindex];
1648117709
1648217710 /*
1648317711 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -16627,23 +17855,15 @@
1662717855 int AAbuffersize = 0;
1662817856
1662917857 //double[] selectedpoint = new double[3];
16630
- static Superellipsoid selectedpoint = new Superellipsoid();
17858
+ static Superellipsoid selectedpoint;
1663117859 static Sphere previousselectedpoint = null;
16632
- static Sphere debugpointG = new Sphere();
16633
- static Sphere debugpointP = new Sphere();
16634
- static Sphere debugpointC = new Sphere();
16635
- static Sphere debugpointR = new Sphere();
17860
+ static Sphere debugpointG;
17861
+ static Sphere debugpointP;
17862
+ static Sphere debugpointC;
17863
+ static Sphere debugpointR;
1663617864
1663717865 static Sphere debugpoints[] = new Sphere[8];
1663817866
16639
- static
16640
- {
16641
- for (int i=0; i<8; i++)
16642
- {
16643
- debugpoints[i] = new Sphere();
16644
- }
16645
- }
16646
-
1664717867 static void InitPoints(float radius)
1664817868 {
1664917869 for (int i=0; i<8; i++)
....@@ -16682,11 +17902,14 @@
1668217902 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1668317903 static IntBuffer bigAAbuffer;
1668417904 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
16685
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17905
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1668617906 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1668717907 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1668817908 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
16689
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17909
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17910
+
17911
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17912
+
1669017913 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1669117914 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1669217915 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();
....@@ -16695,10 +17918,11 @@
1669517918 static IntBuffer textbuffer = null; // IntBuffer.allocate(TEXT_WIDTH*8*8 * TEXT_HEIGHT);
1669617919 // Depth buffer format
1669717920 //private int depth_format;
16698
- static public void NextIndex(Object3D o, GL gl)
17921
+
17922
+ public void NextIndex()
1669917923 {
1670017924 indexcount+=16;
16701
- gl.glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
17925
+ GetGL().glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
1670217926 //objects[indexcount] = o;
1670317927 //System.out.println("indexcount = " + indexcount);
1670417928 }