Normand Briere
2019-08-13 c67de8aca04d988179191ccb52461af00125920e
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,9 @@
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;
80116 boolean reverseUP = false;
81117 static boolean frozen = false;
82118 boolean enablebackspace = false; // patch for back buffer refresh
....@@ -92,6 +128,8 @@
92128
93129 static int tickcount = 0; // slow pose issue
94130
131
+static boolean BUTTONLESSWHEEL = false;
132
+static boolean ZOOMBOXMODE = false;
95133 static boolean BOXMODE = false;
96134 static boolean IMAGEFLIP = false;
97135 static boolean SMOOTHFOCUS = false;
....@@ -106,7 +144,7 @@
106144 static boolean OEIL = true;
107145 static boolean OEILONCE = false; // do oeilon then oeiloff
108146 static boolean LOOKAT = true;
109
-static boolean RANDOM = true; // false;
147
+static boolean SWITCH = true; // false;
110148 static boolean HANDLES = false; // selection doesn't work!!
111149 static boolean PAINTMODE = false;
112150
....@@ -137,7 +175,7 @@
137175 static boolean doublesided = false; // true; // reversed normals are awful for conformance
138176 boolean anisotropy = true;
139177 boolean softshadow = true; // slower but better false;
140
- boolean opacityhalo = false;
178
+ boolean opacityhalo = false; // reverse the halo effect (e.g. glass)
141179
142180 boolean macromode = false;
143181
....@@ -148,6 +186,21 @@
148186 defaultcaps.setAccumGreenBits(16);
149187 defaultcaps.setAccumBlueBits(16);
150188 defaultcaps.setAccumAlphaBits(16);
189
+ }
190
+
191
+ private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
192
+
193
+ public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException
194
+ {
195
+ try
196
+ {
197
+ return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
198
+ } catch (IOException e)
199
+ {
200
+ System.out.println("NAME = " + name);
201
+ e.printStackTrace(); // throw new RuntimeException(e);
202
+ return null;
203
+ }
151204 }
152205
153206 void SetAsGLRenderer(boolean b)
....@@ -168,7 +221,8 @@
168221
169222 SetCamera(cam);
170223
171
- SetLight(new Camera(new cVector(10, 10, -20)));
224
+ // Warning: not used.
225
+ SetLight(new Camera(new cVector(15, 10, -20)));
172226
173227 object = o;
174228
....@@ -191,9 +245,43 @@
191245
192246 /// INTERFACE
193247
248
+ public javax.media.opengl.GL GetGL0()
249
+ {
250
+ return null;
251
+ }
252
+
253
+ public int GenList()
254
+ {
255
+ javax.media.opengl.GL gl = GetGL();
256
+ return gl.glGenLists(1);
257
+ }
258
+
259
+ public void NewList(int id)
260
+ {
261
+ javax.media.opengl.GL gl = GetGL();
262
+ gl.glNewList(id, gl.GL_COMPILE); //_AND_EXECUTE);
263
+ }
264
+
265
+ public void CallList(int id)
266
+ {
267
+ javax.media.opengl.GL gl = GetGL();
268
+ gl.glCallList(id);
269
+ }
270
+
271
+ public void EndList()
272
+ {
273
+ javax.media.opengl.GL gl = GetGL();
274
+ gl.glEndList();
275
+ }
276
+
194277 public boolean IsBoxMode()
195278 {
196279 return BOXMODE;
280
+ }
281
+
282
+ public boolean IsZoomBoxMode()
283
+ {
284
+ return ZOOMBOXMODE;
197285 }
198286
199287 public void ClearDepth()
....@@ -291,7 +379,7 @@
291379 cStatic.objectstack[materialdepth++] = obj;
292380 //System.out.println("material " + material);
293381 //Applet3D.tracein(this, selected);
294
- display.vector2buffer = obj.projectedVertices;
382
+ //display.vector2buffer = obj.projectedVertices;
295383 if (obj instanceof Camera)
296384 {
297385 display.options1[0] = material.shift;
....@@ -300,14 +388,28 @@
300388 display.options1[2] = material.shadowbias;
301389 display.options1[3] = material.aniso;
302390 display.options1[4] = material.anisoV;
391
+// System.out.println("display.options1[0] " + display.options1[0]);
392
+// System.out.println("display.options1[1] " + display.options1[1]);
393
+// System.out.println("display.options1[2] " + display.options1[2]);
394
+// System.out.println("display.options1[3] " + display.options1[3]);
395
+// System.out.println("display.options1[4] " + display.options1[4]);
303396 display.options2[0] = material.opacity;
304397 display.options2[1] = material.diffuse;
305398 display.options2[2] = material.factor;
399
+// System.out.println("display.options2[0] " + display.options2[0]);
400
+// System.out.println("display.options2[1] " + display.options2[1]);
401
+// System.out.println("display.options2[2] " + display.options2[2]);
306402
307403 cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
404
+// System.out.println("display.options3[0] " + display.options3[0]);
405
+// System.out.println("display.options3[1] " + display.options3[1]);
406
+// System.out.println("display.options3[2] " + display.options3[2]);
308407 display.options4[0] = material.cameralight/0.2f;
309408 display.options4[1] = material.subsurface;
310409 display.options4[2] = material.sheen;
410
+// System.out.println("display.options4[0] " + display.options4[0]);
411
+// System.out.println("display.options4[1] " + display.options4[1]);
412
+// System.out.println("display.options4[2] " + display.options4[2]);
311413
312414 // if (display.CURRENTANTIALIAS > 0)
313415 // display.options3[3] /= 4;
....@@ -323,7 +425,7 @@
323425 /**/
324426 } else
325427 {
326
- DrawMaterial(material, selected);
428
+ DrawMaterial(material, selected, obj.projectedVertices);
327429 }
328430 } else
329431 {
....@@ -347,8 +449,8 @@
347449 cStatic.objectstack[materialdepth++] = obj;
348450 //System.out.println("material " + material);
349451 //Applet3D.tracein("selected ", selected);
350
- display.vector2buffer = obj.projectedVertices;
351
- display.DrawMaterial(material, selected);
452
+ //display.vector2buffer = obj.projectedVertices;
453
+ display.DrawMaterial(material, selected, obj.projectedVertices);
352454 }
353455 }
354456
....@@ -365,8 +467,8 @@
365467 materialdepth -= 1;
366468 if (materialdepth > 0)
367469 {
368
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
369
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
470
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
471
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
370472 }
371473 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
372474 } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
....@@ -386,8 +488,8 @@
386488 materialdepth -= 1;
387489 if (materialdepth > 0)
388490 {
389
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
390
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
491
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
492
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
391493 }
392494 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
393495 //else
....@@ -428,10 +530,12 @@
428530 if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
429531 {
430532 //gl.glBegin(gl.GL_TRIANGLES);
431
- boolean hasnorm = pv.norm != null; // && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0);
533
+ boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0)
534
+ // TEST LIVE NORMALS && !obj.dontselect
535
+ ;
432536 if (!hasnorm)
433537 {
434
- // System.out.println("FUCK!!");
538
+ // System.out.println("Mesh normal");
435539 LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
436540 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
437541 LA.vecCross(obj.v0, obj.v1, obj.v2);
....@@ -1059,8 +1163,345 @@
10591163 gl.glMatrixMode(gl.GL_MODELVIEW);
10601164 }
10611165
1166
+ public void DrawBox(cVector min, cVector max)
1167
+ {
1168
+ javax.media.opengl.GL gl = GetGL();
1169
+ gl.glBegin(gl.GL_LINES);
1170
+
1171
+ gl.glVertex3d(min.x, min.y, min.z);
1172
+ gl.glVertex3d(min.x, min.y, max.z);
1173
+ gl.glVertex3d(min.x, min.y, min.z);
1174
+ gl.glVertex3d(min.x, max.y, min.z);
1175
+ gl.glVertex3d(min.x, min.y, min.z);
1176
+ gl.glVertex3d(max.x, min.y, min.z);
1177
+
1178
+ gl.glVertex3d(max.x, max.y, max.z);
1179
+ gl.glVertex3d(min.x, max.y, max.z);
1180
+ gl.glVertex3d(max.x, max.y, max.z);
1181
+ gl.glVertex3d(max.x, min.y, max.z);
1182
+ gl.glVertex3d(max.x, max.y, max.z);
1183
+ gl.glVertex3d(max.x, max.y, min.z);
1184
+
1185
+ gl.glEnd();
1186
+ }
1187
+
1188
+ public void DrawGeometry(BoundaryRep bRep, boolean flipV, boolean selectmode)
1189
+ {
1190
+ int[] strips = bRep.getRawIndices();
1191
+
1192
+ javax.media.opengl.GL gl = GetGL();
1193
+
1194
+ // TRIANGLE STRIP ARRAY
1195
+ if (bRep.trimmed)
1196
+ {
1197
+ float[] v = bRep.getRawVertices();
1198
+ float[] n = bRep.getRawNormals();
1199
+ float[] c = bRep.getRawColors();
1200
+ float[] uv = bRep.getRawUVMap();
1201
+
1202
+ int count2 = 0;
1203
+ int count3 = 0;
1204
+
1205
+ if (n.length > 0)
1206
+ {
1207
+ for (int i = 0; i < strips.length; i++)
1208
+ {
1209
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1210
+
1211
+ /*
1212
+ boolean locked = false;
1213
+ float eps = 0.1f;
1214
+ boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
1215
+
1216
+ int dot = 0;
1217
+
1218
+ if ((dot&1) == 0)
1219
+ dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
1220
+
1221
+ if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
1222
+ gl.glTexCoord2f((float) qv.s, (float) qv.t);
1223
+ else
1224
+ {
1225
+ locked = true;
1226
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1227
+ }
1228
+ //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
1229
+ gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
1230
+ if (hasnorm)
1231
+ {
1232
+ //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
1233
+ gl.glNormal3f((float) rv.norm.x, (float) rv.norm.y, (float) rv.norm.z);
1234
+ }
1235
+
1236
+ if ((dot&4) == 0)
1237
+ dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
1238
+
1239
+ if (wrap || !locked && (dot&8) != 0)
1240
+ gl.glTexCoord2f((float) rv.s, (float) rv.t);
1241
+ else
1242
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1243
+
1244
+ f.dot = dot;
1245
+ */
1246
+
1247
+ if (!selectmode)
1248
+ {
1249
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1250
+ {
1251
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1252
+ } else
1253
+ {
1254
+ gl.glNormal3f(0, 0, 1);
1255
+ }
1256
+
1257
+ if (c != null)
1258
+ //System.out.println("glcolor = " + c[count3] + ", " + c[count3+1] + ", " + c[count3+2]);
1259
+ {
1260
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1261
+ }
1262
+ }
1263
+
1264
+ if (flipV)
1265
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1266
+ else
1267
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1268
+
1269
+ //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1270
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1271
+
1272
+ count2 += 2;
1273
+ count3 += 3;
1274
+ if (!selectmode)
1275
+ {
1276
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1277
+ {
1278
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1279
+ } else
1280
+ {
1281
+ gl.glNormal3f(0, 0, 1);
1282
+ }
1283
+ if (c != null)
1284
+ {
1285
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1286
+ }
1287
+ }
1288
+
1289
+ if (flipV)
1290
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1291
+ else
1292
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1293
+
1294
+ //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1295
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1296
+
1297
+ count2 += 2;
1298
+ count3 += 3;
1299
+ for (int j = 0; j < strips[i] - 2; j++)
1300
+ {
1301
+ //gl.glTexCoord2d(...);
1302
+ if (!selectmode)
1303
+ {
1304
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1305
+ {
1306
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1307
+ } else
1308
+ {
1309
+ gl.glNormal3f(0, 0, 1);
1310
+ }
1311
+ if (c != null)
1312
+ {
1313
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1314
+ }
1315
+ }
1316
+
1317
+ if (flipV)
1318
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1319
+ else
1320
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1321
+
1322
+ //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
1323
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1324
+
1325
+ count2 += 2;
1326
+ count3 += 3;
1327
+ }
1328
+
1329
+ gl.glEnd();
1330
+ }
1331
+ }
1332
+
1333
+ assert count3 == v.length;
1334
+ }
1335
+ else // !trimmed
1336
+ {
1337
+ int count = 0;
1338
+ for (int i = 0; i < strips.length; i++)
1339
+ {
1340
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1341
+
1342
+ Vertex p = bRep.GetVertex(bRep.indices[count++]);
1343
+ Vertex q = bRep.GetVertex(bRep.indices[count++]);
1344
+
1345
+ drawVertex(gl, p, flipV, selectmode);
1346
+ drawVertex(gl, q, flipV, selectmode);
1347
+
1348
+ for (int j = 0; j < strips[i] - 2; j++)
1349
+ {
1350
+ Vertex r = bRep.GetVertex(bRep.indices[count++]);
1351
+
1352
+ // if (j%2 == 0)
1353
+ // drawFace(p, q, r, display, null);
1354
+ // else
1355
+ // drawFace(p, r, q, display, null);
1356
+
1357
+ // p = q;
1358
+ // q = r;
1359
+ drawVertex(gl, r, flipV, selectmode);
1360
+ }
1361
+
1362
+ gl.glEnd();
1363
+ }
1364
+ }
1365
+ }
1366
+
1367
+ static cSpring.Point3D temp = new cSpring.Point3D();
1368
+ static cSpring.Point3D temp2 = new cSpring.Point3D();
1369
+ static cSpring.Point3D temp3 = new cSpring.Point3D();
1370
+
1371
+ public void DrawDynamicMesh(cMesh mesh)
1372
+ {
1373
+ GL gl = GetGL(); // getGL();
1374
+
1375
+ cSpring.PhysicsController3D Phys = mesh.Phys;
1376
+
1377
+ gl.glDisable(gl.GL_LIGHTING);
1378
+
1379
+ gl.glLineWidth(1);
1380
+ gl.glColor3f(1,1,1);
1381
+ gl.glBegin(gl.GL_LINES);
1382
+ double scale = 0;
1383
+ int count = 0;
1384
+ for (int s=0; s<Phys.allSprings.size(); s++)
1385
+ {
1386
+ cSpring.Spring spring = Phys.allSprings.get(s);
1387
+ if(s == 0)
1388
+ {
1389
+ //System.out.println(" spring : " + spring.a.position + "; " + spring.b.position);
1390
+ }
1391
+ if (mesh.showsprings)
1392
+ {
1393
+ temp.set(spring.a.position);
1394
+ temp.add(spring.b.position);
1395
+ temp.mul(0.5);
1396
+ temp2.set(spring.a.position);
1397
+ temp2.sub(spring.b.position);
1398
+ temp2.mul(spring.restLength/2);
1399
+ temp.sub(temp2);
1400
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1401
+ temp.add(temp2);
1402
+ temp.add(temp2);
1403
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1404
+ }
1405
+
1406
+ if (spring.isHandle)
1407
+ continue;
1408
+
1409
+ //if (scale < spring.restLength)
1410
+ scale += spring.restLength;
1411
+ count++;
1412
+ }
1413
+ gl.glEnd();
1414
+
1415
+ if (count == 0)
1416
+ scale = 0.01;
1417
+ else
1418
+ scale /= count * 3;
1419
+
1420
+ //scale = 0.25;
1421
+
1422
+ if (mesh.ShowInfo())
1423
+ {
1424
+ gl.glLineWidth(4);
1425
+ for (int s=0; s<Phys.allNodes.size(); s++)
1426
+ {
1427
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1428
+ if (node.mass == 0)
1429
+ continue;
1430
+
1431
+ int i = node.springs==null?-1:node.springs.size();
1432
+ gl.glColor3f((i>>2)&1,(i>>1)&1,i&1);
1433
+ //temp.set(node.springForce.x, node.springForce.y, node.springForce.z);
1434
+ //temp.normalize();
1435
+ //gl.glColor3d((temp.x+1)/2, (temp.y+1)/2, (temp.z+1)/2);
1436
+ gl.glBegin(gl.GL_LINES);
1437
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1438
+ //gl.glVertex3d(node.position.x + node.normal.x*scale, node.position.y + node.normal.y*scale, node.position.z + node.normal.z*scale);
1439
+ gl.glVertex3d(node.position.x + mesh.bRep.GetVertex(s).norm.x*scale,
1440
+ node.position.y + mesh.bRep.GetVertex(s).norm.y*scale,
1441
+ node.position.z + mesh.bRep.GetVertex(s).norm.z*scale);
1442
+ gl.glEnd();
1443
+ }
1444
+
1445
+ gl.glLineWidth(8);
1446
+ for (int s=0; s<Phys.allNodes.size(); s++)
1447
+ {
1448
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1449
+
1450
+ if (node.springs != null)
1451
+ {
1452
+ for (int i=0; i<node.springs.size(); i+=1)
1453
+ {
1454
+ cSpring.DynamicNode f = node.springs.get(i).GetOther(node);
1455
+
1456
+ int c = i+1;
1457
+ // c = node.springs.get(i).nbcopies;
1458
+
1459
+ gl.glColor3f((c>>2)&1,(c>>1)&1,c&1);
1460
+ gl.glBegin(gl.GL_LINES);
1461
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1462
+ 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);
1463
+ gl.glEnd();
1464
+ }
1465
+ }
1466
+ }
1467
+
1468
+ gl.glLineWidth(1);
1469
+ }
1470
+
1471
+ gl.glEnable(gl.GL_LIGHTING);
1472
+ }
1473
+
10621474 /// INTERFACE
10631475
1476
+ public void StartTriangles()
1477
+ {
1478
+ javax.media.opengl.GL gl = GetGL();
1479
+ gl.glBegin(gl.GL_TRIANGLES);
1480
+ }
1481
+
1482
+ public void EndTriangles()
1483
+ {
1484
+ GetGL().glEnd();
1485
+ }
1486
+
1487
+ void drawVertex(javax.media.opengl.GL gl, Vertex pv, boolean flipV, boolean selectmode)
1488
+ {
1489
+ if (!selectmode)
1490
+ {
1491
+ gl.glNormal3f((float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
1492
+ gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
1493
+
1494
+ if (flipV)
1495
+ gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
1496
+ else
1497
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1498
+ }
1499
+
1500
+ gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
1501
+ }
1502
+
1503
+ float[] colorV = new float[4];
1504
+
10641505 void SetColor(Object3D obj, Vertex p0)
10651506 {
10661507 CameraPane display = this;
....@@ -1128,8 +1569,6 @@
11281569 {
11291570 return;
11301571 }
1131
-
1132
- float[] colorV = new float[3];
11331572
11341573 if (false) // marked)
11351574 {
....@@ -1238,7 +1677,7 @@
12381677 // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
12391678 }
12401679
1241
- void DrawMaterial(cMaterial material, boolean selected)
1680
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
12421681 {
12431682 CameraPane display = this;
12441683 //new Exception().printStackTrace();
....@@ -1254,18 +1693,18 @@
12541693 //col.getColorComponents(ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB), CameraPane.modelParams0);
12551694 if (!material.multiply)
12561695 {
1257
- display.color = color;
1696
+ display.color = material.color;
12581697 display.saturation = material.modulation;
12591698 }
12601699 else
12611700 {
1262
- display.color *= color*2;
1701
+ display.color *= material.color*2;
12631702 display.saturation *= material.modulation*2;
12641703 }
12651704
12661705 cColor.HSBtoRGB(display.color, display.saturation, 1, display.modelParams0);
12671706
1268
- float[] colorV = GrafreeD.colorV;
1707
+ float[] colorV = Grafreed.colorV;
12691708
12701709 /**/
12711710 if (display.DrawMode() == display.DEFAULT) // && display.RENDERPROGRAM == 0)
....@@ -1273,7 +1712,7 @@
12731712 colorV[0] = display.modelParams0[0] * material.diffuse;
12741713 colorV[1] = display.modelParams0[1] * material.diffuse;
12751714 colorV[2] = display.modelParams0[2] * material.diffuse;
1276
- colorV[3] = material.opacity;
1715
+ colorV[3] = 1; // material.opacity;
12771716
12781717 gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
12791718 //System.out.println("Opacity = " + opacity);
....@@ -1381,9 +1820,9 @@
13811820 display.modelParams7[2] = 0;
13821821 display.modelParams7[3] = 0;
13831822
1384
- display.modelParams6[0] = 100; // criss de bug de bump
1823
+ //display.modelParams6[0] = 100; // criss de bug de bump
13851824
1386
- Object3D.cVector2[] extparams = display.vector2buffer;
1825
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
13871826 if (extparams != null && extparams.length > 0 && extparams[0] != null)
13881827 {
13891828 display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
....@@ -1525,7 +1964,7 @@
15251964 void PushMatrix(double[][] matrix)
15261965 {
15271966 // GrafreeD.tracein(matrix);
1528
- PushMatrix(matrix,1);
1967
+ PushMatrix(matrix, 1);
15291968 }
15301969
15311970 void PushMatrix()
....@@ -1679,7 +2118,7 @@
16792118 //System.err.println("Oeil on");
16802119 OEIL = true;
16812120 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
1682
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2121
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
16832122 //pingthread.StepToTarget(true);
16842123 }
16852124
....@@ -1777,7 +2216,7 @@
17772216 System.err.println("LIVE = " + Globals.isLIVE());
17782217
17792218 if (!Globals.isLIVE()) // save sound
1780
- GrafreeD.savesound = true; // wav.save();
2219
+ Grafreed.savesound = true; // wav.save();
17812220 // else
17822221 repaint(); // start loop // may 2013
17832222 }
....@@ -1810,6 +2249,11 @@
18102249 public void ToggleBoxMode()
18112250 {
18122251 BOXMODE ^= true;
2252
+ }
2253
+
2254
+ public void ToggleZoomBoxMode()
2255
+ {
2256
+ ZOOMBOXMODE ^= true;
18132257 }
18142258
18152259 public void ToggleSmoothFocus()
....@@ -1889,7 +2333,7 @@
18892333
18902334 void ToggleDebug()
18912335 {
1892
- DEBUG ^= true;
2336
+ Globals.DEBUG ^= true;
18932337 }
18942338
18952339 void ToggleLookAt()
....@@ -1897,9 +2341,9 @@
18972341 LOOKAT ^= true;
18982342 }
18992343
1900
- void ToggleRandom()
2344
+ void ToggleSwitch()
19012345 {
1902
- RANDOM ^= true;
2346
+ SWITCH ^= true;
19032347 }
19042348
19052349 void ToggleHandles()
....@@ -1907,10 +2351,17 @@
19072351 HANDLES ^= true;
19082352 }
19092353
2354
+ Object3D paintFolder;
2355
+
19102356 void TogglePaint()
19112357 {
19122358 PAINTMODE ^= true;
19132359 paintcount = 0;
2360
+
2361
+ if (PAINTMODE)
2362
+ {
2363
+ paintFolder = GetFolder();
2364
+ }
19142365 }
19152366
19162367 void SwapCamera(int a, int b)
....@@ -2006,7 +2457,22 @@
20062457 {
20072458 return currentGL;
20082459 }
2009
-
2460
+
2461
+ static private BufferedImage CreateBim(TextureData texturedata)
2462
+ {
2463
+ Grafreed.Assert(texturedata != null);
2464
+
2465
+ int width = texturedata.getWidth();
2466
+ int height = texturedata.getHeight();
2467
+
2468
+ Buffer buffer = texturedata.getBuffer();
2469
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2470
+
2471
+ byte[] bytes = bytebuf.array();
2472
+
2473
+ return CreateBim(bytes, width, height);
2474
+ }
2475
+
20102476 /**/
20112477 class CacheTexture
20122478 {
....@@ -2015,28 +2481,31 @@
20152481
20162482 int resolution;
20172483
2018
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2484
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
20192485 {
2020
- texture = tex;
2486
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2487
+ texturedata = texdata;
20212488 resolution = res;
20222489 }
20232490 }
20242491 /**/
20252492
20262493 // 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>();
2494
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2495
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2496
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2497
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2498
+
20302499 int pigmentdepth = 0;
20312500 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
20322501 int bumpdepth = 0;
20332502 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
20342503 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
20352504 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2036
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2505
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
20372506 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
20382507
2039
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2508
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
20402509 {
20412510 TextureData texturedata = null;
20422511
....@@ -2055,13 +2524,34 @@
20552524 if (bump)
20562525 texturedata = ConvertBump(texturedata, false);
20572526
2058
- com.sun.opengl.util.texture.Texture texture =
2059
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2527
+// com.sun.opengl.util.texture.Texture texture =
2528
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
20602529
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);
2530
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2531
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
20632532
2064
- return texture;
2533
+ return texturedata;
2534
+ }
2535
+
2536
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2537
+ {
2538
+ TextureData texturedata = null;
2539
+
2540
+ try
2541
+ {
2542
+ texturedata =
2543
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2544
+ bim,
2545
+ true);
2546
+ } catch (Exception e)
2547
+ {
2548
+ throw new javax.media.opengl.GLException(e);
2549
+ }
2550
+
2551
+ if (bump)
2552
+ texturedata = ConvertBump(texturedata, false);
2553
+
2554
+ return texturedata;
20652555 }
20662556
20672557 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3134,6 +3624,8 @@
31343624
31353625 System.out.println("LOADING TEXTURE : " + name);
31363626
3627
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3628
+
31373629 //
31383630 if (false) // compressbit > 0)
31393631 {
....@@ -3838,6 +4330,7 @@
38384330
38394331 com.sun.opengl.util.texture.Texture CompressTexture2(String name)
38404332 {
4333
+ new Exception().printStackTrace();
38414334 System.exit(0);
38424335 com.sun.opengl.util.texture.Texture texture = null;
38434336
....@@ -7531,7 +8024,7 @@
75318024 String pigment = Object3D.GetPigment(tex);
75328025 String bump = Object3D.GetBump(tex);
75338026
7534
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8027
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
75358028 {
75368029 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
75378030 // System.out.println("; bump = " + bump);
....@@ -7546,11 +8039,69 @@
75468039 pigment = null;
75478040 }
75488041
7549
- ReleaseTexture(bump, true);
7550
- ReleaseTexture(pigment, false);
8042
+ ReleaseTexture(tex, true);
8043
+ ReleaseTexture(tex, false);
75518044 }
75528045
7553
- void ReleaseTexture(String tex, boolean bump)
8046
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
8047
+ {
8048
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8049
+ {
8050
+ return;
8051
+ }
8052
+
8053
+ if (tex == null)
8054
+ {
8055
+ ReleaseTexture(null, false);
8056
+ return;
8057
+ }
8058
+
8059
+ String pigment = Object3D.GetPigment(tex);
8060
+
8061
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8062
+ {
8063
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8064
+ // System.out.println("; bump = " + bump);
8065
+ }
8066
+
8067
+ if (pigment.equals(""))
8068
+ {
8069
+ pigment = null;
8070
+ }
8071
+
8072
+ ReleaseTexture(tex, false);
8073
+ }
8074
+
8075
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
8076
+ {
8077
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8078
+ {
8079
+ return;
8080
+ }
8081
+
8082
+ if (tex == null)
8083
+ {
8084
+ ReleaseTexture(null, true);
8085
+ return;
8086
+ }
8087
+
8088
+ String bump = Object3D.GetBump(tex);
8089
+
8090
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8091
+ {
8092
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8093
+ // System.out.println("; bump = " + bump);
8094
+ }
8095
+
8096
+ if (bump.equals(""))
8097
+ {
8098
+ bump = null;
8099
+ }
8100
+
8101
+ ReleaseTexture(tex, true);
8102
+ }
8103
+
8104
+ void ReleaseTexture(cTexture tex, boolean bump)
75548105 {
75558106 if (// DrawMode() != 0 || /*tex == null ||*/
75568107 ambientOcclusion ) // || !textureon)
....@@ -7561,7 +8112,7 @@
75618112 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
75628113
75638114 if (tex != null)
7564
- texture = textures.get(tex);
8115
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
75658116
75668117 // //assert( texture != null );
75678118 // if (texture == null)
....@@ -7653,7 +8204,55 @@
76538204 }
76548205 }
76558206
7656
- /*boolean*/ public void BindTextures(cTexture tex, int resolution) // INTERFACE
8207
+ /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
8208
+ {
8209
+// if (// DrawMode() != 0 || /*tex == null ||*/
8210
+// ambientOcclusion ) // || !textureon)
8211
+// {
8212
+// return; // false;
8213
+// }
8214
+//
8215
+// if (tex == null)
8216
+// {
8217
+// BindTexture(null,false,resolution);
8218
+// BindTexture(null,true,resolution);
8219
+// return;
8220
+// }
8221
+//
8222
+// String pigment = Object3D.GetPigment(tex);
8223
+// String bump = Object3D.GetBump(tex);
8224
+//
8225
+// usedtextures.add(pigment);
8226
+// usedtextures.add(bump);
8227
+//
8228
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8229
+// {
8230
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8231
+// // System.out.println("; bump = " + bump);
8232
+// }
8233
+//
8234
+// if (bump.equals(""))
8235
+// {
8236
+// bump = null;
8237
+// }
8238
+// if (pigment.equals(""))
8239
+// {
8240
+// pigment = null;
8241
+// }
8242
+//
8243
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8244
+// BindTexture(pigment, false, resolution);
8245
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8246
+// BindTexture(bump, true, resolution);
8247
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8248
+//
8249
+// return; // true;
8250
+
8251
+ BindPigmentTexture(tex, resolution);
8252
+ BindBumpTexture(tex, resolution);
8253
+ }
8254
+
8255
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
76578256 {
76588257 if (// DrawMode() != 0 || /*tex == null ||*/
76598258 ambientOcclusion ) // || !textureon)
....@@ -7664,17 +8263,47 @@
76648263 if (tex == null)
76658264 {
76668265 BindTexture(null,false,resolution);
7667
- BindTexture(null,true,resolution);
76688266 return;
76698267 }
76708268
76718269 String pigment = Object3D.GetPigment(tex);
8270
+
8271
+ usedtextures.add(tex);
8272
+
8273
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8274
+ {
8275
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8276
+ // System.out.println("; bump = " + bump);
8277
+ }
8278
+
8279
+ if (pigment.equals(""))
8280
+ {
8281
+ pigment = null;
8282
+ }
8283
+
8284
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8285
+ BindTexture(tex, false, resolution);
8286
+ }
8287
+
8288
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8289
+ {
8290
+ if (// DrawMode() != 0 || /*tex == null ||*/
8291
+ ambientOcclusion ) // || !textureon)
8292
+ {
8293
+ return; // false;
8294
+ }
8295
+
8296
+ if (tex == null)
8297
+ {
8298
+ BindTexture(null,true,resolution);
8299
+ return;
8300
+ }
8301
+
76728302 String bump = Object3D.GetBump(tex);
76738303
7674
- usedtextures.put(pigment, pigment);
7675
- usedtextures.put(bump, bump);
8304
+ usedtextures.add(tex);
76768305
7677
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8306
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
76788307 {
76798308 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
76808309 // System.out.println("; bump = " + bump);
....@@ -7684,43 +8313,94 @@
76848313 {
76858314 bump = null;
76868315 }
7687
- if (pigment.equals(""))
7688
- {
7689
- pigment = null;
7690
- }
76918316
7692
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
7693
- BindTexture(pigment, false, resolution);
76948317 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
7695
- BindTexture(bump, true, resolution);
8318
+ BindTexture(tex, true, resolution);
76968319 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
7697
-
7698
- return; // true;
76998320 }
77008321
7701
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution)
8322
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8323
+
8324
+ private boolean FileExists(String tex)
77028325 {
7703
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8326
+ if (missingTextures.contains(tex))
8327
+ {
8328
+ return false;
8329
+ }
8330
+
8331
+ boolean fileExists = new File(tex).exists();
8332
+
8333
+ if (!fileExists)
8334
+ {
8335
+ // If file exists, the "new File()" is not executed sgain
8336
+ missingTextures.add(tex);
8337
+ }
8338
+
8339
+ return fileExists;
8340
+ }
8341
+
8342
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
8343
+ {
8344
+ CacheTexture texturecache = null;
77048345
77058346 if (tex != null)
77068347 {
7707
- String texname = tex;
8348
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8349
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
77088350
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;
8351
+ if (texname.equals("") && texdata == null)
8352
+ {
8353
+ return null;
8354
+ }
8355
+
8356
+ String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
8357
+
8358
+// String[] split = tex.split("Textures");
8359
+// if (split.length > 1)
8360
+// texname = "/Users/nbriere/Textures" + split[split.length-1];
8361
+// else
8362
+// if (!texname.startsWith("/"))
8363
+// texname = "/Users/nbriere/Textures/" + texname;
8364
+ if (!FileExists(texname) && !texname.startsWith("@"))
8365
+ {
8366
+ texname = fallbackTextureName;
8367
+ }
77158368
77168369 if (CACHETEXTURE)
7717
- texture = textures.get(texname); // TEXTURE CACHE
7718
-
7719
- TextureData texturedata = null;
7720
-
7721
- if (texture == null || texture.resolution < resolution)
77228370 {
7723
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8371
+ if (texdata == null)
8372
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8373
+ else
8374
+ texturecache = bimtextures.get(texdata);
8375
+ }
8376
+
8377
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8378
+ {
8379
+ TextureData texturedata = null;
8380
+
8381
+ if (texdata != null && textureon)
8382
+ {
8383
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8384
+
8385
+ try
8386
+ {
8387
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8388
+ }
8389
+ catch (Exception e)
8390
+ {
8391
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8392
+ }
8393
+
8394
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8395
+ bimtextures.put(texdata, texturecache);
8396
+
8397
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8398
+
8399
+ //Object bim2 = CreateBim(texturecache.texturedata);
8400
+ //bim2 = bim;
8401
+ }
8402
+ else
8403
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
77248404 {
77258405 assert(!bump);
77268406 // if (bump)
....@@ -7731,19 +8411,23 @@
77318411 // }
77328412 // else
77338413 // {
7734
- texture = textures.get(tex);
7735
- if (texture == null)
8414
+ // texturecache = textures.get(texname); // suspicious
8415
+ if (texturecache == null)
77368416 {
7737
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8417
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
77388418 }
8419
+ else
8420
+ new Exception().printStackTrace();
77398421 // }
77408422 } else
7741
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8423
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
77428424 {
77438425 assert(bump);
7744
- texture = textures.get(tex);
7745
- if (texture == null)
7746
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8426
+ // texturecache = textures.get(texname); // suspicious
8427
+ if (texturecache == null)
8428
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8429
+ else
8430
+ new Exception().printStackTrace();
77478431 } else
77488432 {
77498433 //if (tex.equals("IMMORTAL"))
....@@ -7751,11 +8435,22 @@
77518435 // texture = GetResourceTexture("default.png");
77528436 //} else
77538437 //{
7754
- if (tex.equals("WHITE_NOISE"))
8438
+ if (texname.endsWith("WHITE_NOISE"))
77558439 {
7756
- texture = textures.get(tex);
7757
- if (texture == null)
7758
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8440
+ // texturecache = textures.get(texname); // suspicious
8441
+ if (texturecache == null)
8442
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8443
+ else
8444
+ new Exception().printStackTrace();
8445
+ } else
8446
+ {
8447
+ if (texname.startsWith("@"))
8448
+ {
8449
+ // texturecache = textures.get(texname); // suspicious
8450
+ if (texturecache == null)
8451
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8452
+ else
8453
+ new Exception().printStackTrace();
77598454 } else
77608455 {
77618456 if (textureon)
....@@ -7780,7 +8475,7 @@
77808475 }
77818476
77828477 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
7783
- if (!new File(cachename).exists())
8478
+ if (!FileExists(cachename))
77848479 cachename = texname;
77858480 else
77868481 processbump = false; // don't process bump map again
....@@ -7802,7 +8497,7 @@
78028497 }
78038498
78048499 cachename = texname.substring(0, texname.length()-4)+ext+".png";
7805
- if (!new File(cachename).exists())
8500
+ if (!FileExists(cachename))
78068501 cachename = texname;
78078502 else
78088503 processbump = false; // don't process bump map again
....@@ -7811,20 +8506,23 @@
78118506 texturedata = GetFileTexture(cachename, processbump, resolution);
78128507
78138508
7814
- if (texturedata != null)
7815
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8509
+ if (texturedata == null)
8510
+ throw new Exception();
8511
+
8512
+ texturecache = new CacheTexture(texturedata,resolution);
78168513 //texture = GetTexture(tex, bump);
78178514 }
8515
+ }
78188516 }
78198517 //}
78208518 }
78218519
7822
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8520
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
78238521 {
78248522 //return false;
78258523
78268524 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
7827
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8525
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
78288526 {
78298527 // String ext = "_highres";
78308528 // if (REDUCETEXTURE)
....@@ -7841,52 +8539,17 @@
78418539 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
78428540 if (!cachefile.exists())
78438541 {
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))
8542
+ //if (texturedata.getWidth() == texturedata.getHeight())
78538543 {
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);
8544
+ BufferedImage rendImage = CreateBim(texturedata);
8545
+
78848546 ImageWriter writer = null;
78858547 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
78868548 if (iter.hasNext()) {
78878549 writer = (ImageWriter)iter.next();
78888550 }
7889
- float compressionQuality = 0.9f;
8551
+
8552
+ float compressionQuality = 0.85f;
78908553 try
78918554 {
78928555 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -7903,18 +8566,20 @@
79038566 }
79048567 }
79058568 }
7906
-
8569
+
8570
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8571
+
79078572 //System.out.println("Texture = " + tex);
7908
- if (textures.containsKey(texname))
8573
+ if (textures.containsKey(tex))
79098574 {
7910
- CacheTexture thetex = textures.get(texname);
8575
+ CacheTexture thetex = textures.get(tex);
79118576 thetex.texture.disable();
79128577 thetex.texture.dispose();
7913
- textures.remove(texname);
8578
+ textures.remove(tex);
79148579 }
79158580
7916
- texture.texturedata = texturedata;
7917
- textures.put(texname, texture);
8581
+ //texture.texturedata = texturedata;
8582
+ textures.put(tex, texturecache);
79188583
79198584 // newtex = true;
79208585 }
....@@ -7930,10 +8595,44 @@
79308595 }
79318596 }
79328597
7933
- return texture;
8598
+ return texturecache;
79348599 }
79358600
7936
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution)
8601
+ static void EmbedTextures(cTexture tex)
8602
+ {
8603
+ if (tex.pigmentdata == null)
8604
+ {
8605
+ //String texname = Object3D.GetPigment(tex);
8606
+
8607
+ CacheTexture texturecache = texturepigment.get(tex);
8608
+
8609
+ if (texturecache != null)
8610
+ {
8611
+ tex.pw = texturecache.texturedata.getWidth();
8612
+ tex.ph = texturecache.texturedata.getHeight();
8613
+ tex.pigmentdata = //CompressJPEG(CreateBim
8614
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8615
+ ;
8616
+ //, tex.pw, tex.ph), 0.5f);
8617
+ }
8618
+ }
8619
+
8620
+ if (tex.bumpdata == null)
8621
+ {
8622
+ //String texname = Object3D.GetBump(tex);
8623
+
8624
+ CacheTexture texturecache = texturebump.get(tex);
8625
+
8626
+ if (texturecache != null)
8627
+ {
8628
+ tex.bw = texturecache.texturedata.getWidth();
8629
+ tex.bh = texturecache.texturedata.getHeight();
8630
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8631
+ }
8632
+ }
8633
+ }
8634
+
8635
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
79378636 {
79388637 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
79398638
....@@ -7951,21 +8650,21 @@
79518650 return texture!=null?texture.texture:null;
79528651 }
79538652
7954
- public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution)
8653
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
79558654 {
79568655 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
79578656
79588657 return texture!=null?texture.texturedata:null;
79598658 }
79608659
7961
- boolean BindTexture(String tex, boolean bump, int resolution)
8660
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
79628661 {
79638662 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
79648663 {
79658664 return false;
79668665 }
79678666
7968
- boolean newtex = false;
8667
+ //boolean newtex = false;
79698668
79708669 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
79718670
....@@ -7997,9 +8696,75 @@
79978696 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
79988697 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
79998698
8000
- return newtex;
8699
+ return true; // Warning: not used.
80018700 }
80028701
8702
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8703
+ {
8704
+ try
8705
+ {
8706
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8707
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8708
+ ImageWriter writer = writers.next();
8709
+
8710
+ ImageWriteParam param = writer.getDefaultWriteParam();
8711
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8712
+ param.setCompressionQuality(quality);
8713
+
8714
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8715
+ writer.setOutput(ios);
8716
+ writer.write(null, new IIOImage(image, null, null), param);
8717
+
8718
+ byte[] data = baos.toByteArray();
8719
+ writer.dispose();
8720
+ return data;
8721
+ }
8722
+ catch (Exception e)
8723
+ {
8724
+ e.printStackTrace();
8725
+ return null;
8726
+ }
8727
+ }
8728
+
8729
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8730
+ {
8731
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8732
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8733
+ ImageReader reader = writers.next();
8734
+
8735
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8736
+
8737
+ ImageReadParam param = reader.getDefaultReadParam();
8738
+ param.setDestination(bim);
8739
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8740
+
8741
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8742
+ reader.setInput(ios);
8743
+ BufferedImage bim2 = reader.read(0, param);
8744
+ reader.dispose();
8745
+
8746
+// WritableRaster raster = bim2.getRaster();
8747
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8748
+// byte[] bytes = data.getData();
8749
+//
8750
+// int[] pixels = new int[bytes.length/3];
8751
+// for (int i=pixels.length; --i>=0;)
8752
+// {
8753
+// int i3 = i*3;
8754
+// pixels[i] = 0xFF;
8755
+// pixels[i] <<= 8;
8756
+// pixels[i] |= bytes[i3+2] & 0xFF;
8757
+// pixels[i] <<= 8;
8758
+// pixels[i] |= bytes[i3+1] & 0xFF;
8759
+// pixels[i] <<= 8;
8760
+// pixels[i] |= bytes[i3] & 0xFF;
8761
+// }
8762
+//
8763
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8764
+
8765
+ return bim;
8766
+ }
8767
+
80038768 ShadowBuffer shadowPBuf;
80048769 AntialiasBuffer antialiasPBuf;
80058770 int MAXSTACK;
....@@ -8016,10 +8781,12 @@
80168781
80178782 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
80188783 MAXSTACK = temp[0];
8019
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8784
+ if (Globals.DEBUG)
8785
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
80208786 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
80218787 MAXSTACK = temp[0];
8022
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8788
+ if (Globals.DEBUG)
8789
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
80238790
80248791 // Use debug pipeline
80258792 //drawable.setGL(new DebugGL(gl)); //
....@@ -8027,7 +8794,8 @@
80278794 gl = drawable.getGL(); //
80288795
80298796 GL gl3 = getGL();
8030
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8797
+ if (Globals.DEBUG)
8798
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
80318799
80328800
80338801 //float pos[] = { 100, 100, 100, 0 };
....@@ -8192,7 +8960,7 @@
81928960
81938961 if (cubemap == null)
81948962 {
8195
- LoadEnvy(5);
8963
+ //LoadEnvy(1);
81968964 }
81978965
81988966 //cubemap.enable();
....@@ -8468,6 +9236,8 @@
84689236
84699237 void LoadEnvy(int which)
84709238 {
9239
+ assert(false);
9240
+
84719241 String name;
84729242 String ext;
84739243
....@@ -8479,37 +9249,58 @@
84799249 cubemap = null;
84809250 return;
84819251 case 1:
8482
- name = "cubemaps/box_";
8483
- ext = "png";
9252
+ name = "cubemaps/rgb/";
9253
+ ext = "jpg";
84849254 reverseUP = false;
84859255 break;
84869256 case 2:
8487
- name = "cubemaps/uffizi_";
8488
- ext = "png";
8489
- break; // reverseUP = true; break;
9257
+ name = "cubemaps/uffizi/";
9258
+ ext = "jpg";
9259
+ reverseUP = false;
9260
+ break;
84909261 case 3:
8491
- name = "cubemaps/CloudyHills_";
8492
- ext = "tga";
9262
+ name = "cubemaps/CloudyHills/";
9263
+ ext = "jpg";
84939264 reverseUP = false;
84949265 break;
84959266 case 4:
8496
- name = "cubemaps/cornell_";
9267
+ name = "cubemaps/cornell/";
84979268 ext = "png";
84989269 reverseUP = false;
84999270 break;
9271
+ case 5:
9272
+ name = "cubemaps/skycube/";
9273
+ ext = "jpg";
9274
+ reverseUP = false;
9275
+ break;
9276
+ case 6:
9277
+ name = "cubemaps/SaintLazarusChurch3/";
9278
+ ext = "jpg";
9279
+ reverseUP = false;
9280
+ break;
9281
+ case 7:
9282
+ name = "cubemaps/Sodermalmsallen/";
9283
+ ext = "jpg";
9284
+ reverseUP = false;
9285
+ break;
9286
+ case 8:
9287
+ name = "cubemaps/Sodermalmsallen2/";
9288
+ ext = "jpg";
9289
+ reverseUP = false;
9290
+ break;
9291
+ case 9:
9292
+ name = "cubemaps/UnionSquare/";
9293
+ ext = "jpg";
9294
+ reverseUP = false;
9295
+ break;
85009296 default:
8501
- name = "cubemaps/rgb_";
8502
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9297
+ name = "cubemaps/box/";
9298
+ ext = "png"; /*mipmap = true;*/
9299
+ reverseUP = false;
85039300 break;
85049301 }
8505
-
8506
- try
8507
- {
8508
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
8509
- } catch (IOException e)
8510
- {
8511
- throw new RuntimeException(e);
8512
- }
9302
+
9303
+ LoadSkybox(name, ext, mipmap);
85139304 }
85149305
85159306 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -8541,8 +9332,12 @@
85419332 static double[] model = new double[16];
85429333 double[] camera2light = new double[16];
85439334 double[] light2camera = new double[16];
8544
- int newenvy = -1;
8545
- boolean envyoff = true; // false;
9335
+
9336
+ //int newenvy = -1;
9337
+ //boolean envyoff = false;
9338
+
9339
+ String loadedskyboxname;
9340
+
85469341 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
85479342 //float[] light0 = { 0,0,0 };
85489343 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -8835,11 +9630,35 @@
88359630 jy8[3] = 0.5f;
88369631 }
88379632
8838
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9633
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
88399634 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
88409635 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
88419636 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
88429637
9638
+ void ResetOptions()
9639
+ {
9640
+ options1[0] = 100;
9641
+ options1[1] = 0.025f;
9642
+ options1[2] = 0.01f;
9643
+ options1[3] = 0;
9644
+ options1[4] = 0;
9645
+
9646
+ options2[0] = 0;
9647
+ options2[1] = 0.75f;
9648
+ options2[2] = 0;
9649
+ options2[3] = 0;
9650
+
9651
+ options3[0] = 1;
9652
+ options3[1] = 1;
9653
+ options3[2] = 1;
9654
+ options3[3] = 0;
9655
+
9656
+ options4[0] = 1;
9657
+ options4[1] = 0;
9658
+ options4[2] = 1;
9659
+ options4[3] = 0;
9660
+ }
9661
+
88439662 static int imagecount = 0; // movie generation
88449663
88459664 static int jitter = 0;
....@@ -8935,8 +9754,8 @@
89359754 assert (parentcam != renderCamera);
89369755
89379756 if (renderCamera != lightCamera)
8938
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8939
- LA.matConcat(matrix, parentcam.toParent, matrix);
9757
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9758
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
89409759
89419760 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
89429761
....@@ -8951,8 +9770,8 @@
89519770 LA.matCopy(renderCamera.fromScreen, matrix);
89529771
89539772 if (renderCamera != lightCamera)
8954
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8955
- LA.matConcat(parentcam.fromParent, matrix, matrix);
9773
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9774
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
89569775
89579776 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
89589777
....@@ -8998,10 +9817,12 @@
89989817 rati = 1 / rati;
89999818 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
90009819 }
9001
- assert (newenvy == -1);
9820
+
9821
+ //assert (newenvy == -1);
9822
+
90029823 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
90039824 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9004
- DrawSkyBox(gl);
9825
+ DrawSkyBox(gl, (float)rati);
90059826 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
90069827 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
90079828 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -9024,7 +9845,7 @@
90249845 //gl.glFlush();
90259846 gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE);
90269847
9027
- if (ANIMATION && ABORTED)
9848
+ if (Globals.ANIMATION && ABORTED)
90289849 {
90299850 System.err.println(" ABORTED FRAME");
90309851 break;
....@@ -9054,7 +9875,7 @@
90549875 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
90559876
90569877 // save image
9057
- if (ANIMATION && !ABORTED)
9878
+ if (Globals.ANIMATION && !ABORTED)
90589879 {
90599880 VPwidth = viewport[2];
90609881 VPheight = viewport[3];
....@@ -9165,11 +9986,11 @@
91659986
91669987 // imagecount++;
91679988
9168
- String fullname = filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
9989
+ String fullname = Globals.filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
91699990
91709991 if (!BOXMODE)
91719992 {
9172
- System.out.println("image: " + fullname + " (wav cursor=" + (GrafreeD.wav.cursor / 735 / 4) + ")");
9993
+ System.out.println("image: " + fullname + " (wav cursor=" + (Grafreed.wav.cursor / 735 / 4) + ")");
91739994 }
91749995
91759996 if (!BOXMODE)
....@@ -9207,7 +10028,7 @@
920710028 ABORTED = false;
920810029 }
920910030 else
9210
- GrafreeD.wav.cursor += 735 * ACSIZE;
10031
+ Grafreed.wav.cursor += 735 * ACSIZE;
921110032
921210033 if (false)
921310034 {
....@@ -9870,11 +10691,11 @@
987010691
987110692 public void display(GLAutoDrawable drawable)
987210693 {
9873
- if (GrafreeD.savesound && GrafreeD.hassound)
10694
+ if (Grafreed.savesound && Grafreed.hassound)
987410695 {
9875
- GrafreeD.wav.save();
9876
- GrafreeD.savesound = false;
9877
- GrafreeD.hassound = false;
10696
+ Grafreed.wav.save();
10697
+ Grafreed.savesound = false;
10698
+ Grafreed.hassound = false;
987810699 }
987910700 // if (DEBUG_SELECTION)
988010701 // {
....@@ -9950,6 +10771,7 @@
995010771 ANTIALIAS = 0;
995110772 //System.out.println("RESTART");
995210773 AAtimer.restart();
10774
+ Globals.TIMERRUNNING = true;
995310775 }
995410776 }
995510777 }
....@@ -10004,7 +10826,7 @@
1000410826 Object3D theobject = object;
1000510827 Object3D theparent = object.parent;
1000610828 object.parent = null;
10007
- object = (Object3D)GrafreeD.clone(object);
10829
+ object = (Object3D)Grafreed.clone(object);
1000810830 object.Stripify();
1000910831 if (theobject.selection == null || theobject.selection.Size() == 0)
1001010832 theobject.PreprocessOcclusion(this);
....@@ -10017,13 +10839,14 @@
1001710839 ambientOcclusion = false;
1001810840 }
1001910841
10020
- if (Globals.lighttouched && DrawMode() == DEFAULT && !lightMode) // && !FROZEN)
10842
+ if (//Globals.lighttouched &&
10843
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1002110844 {
1002210845 //if (RENDERSHADOW) // ?
1002310846 if (!IsFrozen())
1002410847 {
1002510848 // dec 2012
10026
- if (!ambientOcclusion && !(!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0))
10849
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
1002710850 {
1002810851 Globals.framecount++;
1002910852 shadowbuffer.display();
....@@ -10036,7 +10859,7 @@
1003610859
1003710860 if (wait)
1003810861 {
10039
- Sleep(500);
10862
+ Sleep(200); // blocks everything
1004010863
1004110864 wait = false;
1004210865 }
....@@ -10150,8 +10973,8 @@
1015010973
1015110974 // if (parentcam != renderCamera) // not a light
1015210975 if (cam != lightCamera)
10153
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10154
- LA.matConcat(matrix, parentcam.toParent, matrix);
10976
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10977
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1015510978
1015610979 for (int j = 0; j < 4; j++)
1015710980 {
....@@ -10165,8 +10988,8 @@
1016510988
1016610989 // if (parentcam != renderCamera) // not a light
1016710990 if (cam != lightCamera)
10168
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10169
- LA.matConcat(parentcam.fromParent, matrix, matrix);
10991
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10992
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1017010993
1017110994 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1017210995
....@@ -10252,13 +11075,41 @@
1025211075 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1025311076 }
1025411077
10255
- if (newenvy > -1)
11078
+// if (newenvy > -1)
11079
+// {
11080
+// LoadEnvy(newenvy);
11081
+// }
11082
+//
11083
+// newenvy = -1;
11084
+
11085
+ if (object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
1025611086 {
10257
- LoadEnvy(newenvy);
11087
+ if (cubemaprgb == null)
11088
+ {
11089
+ cubemaprgb = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11090
+ }
11091
+
11092
+ cubemap = cubemaprgb;
1025811093 }
10259
-
10260
- newenvy = -1;
10261
-
11094
+ else
11095
+ {
11096
+ if (object.skyboxname != null)
11097
+ {
11098
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11099
+ {
11100
+ cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11101
+ loadedskyboxname = object.skyboxname;
11102
+ }
11103
+ }
11104
+ else
11105
+ {
11106
+ cubemapcustom = null;
11107
+ loadedskyboxname = null;
11108
+ }
11109
+
11110
+ cubemap = cubemapcustom;
11111
+ }
11112
+
1026211113 ratio = ((double) getWidth()) / getHeight();
1026311114 //System.out.println("ratio = " + ratio);
1026411115
....@@ -10274,7 +11125,7 @@
1027411125
1027511126 if (!IsFrozen() && !ambientOcclusion)
1027611127 {
10277
- DrawSkyBox(gl);
11128
+ DrawSkyBox(gl, (float)ratio);
1027811129 }
1027911130
1028011131 //if (selection_view == -1)
....@@ -10425,7 +11276,16 @@
1042511276 // Bump noise
1042611277 gl.glActiveTexture(GL.GL_TEXTURE6);
1042711278 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
10428
- BindTexture(NOISE_TEXTURE, false, 2);
11279
+
11280
+ try
11281
+ {
11282
+ BindTexture(NOISE_TEXTURE, false, 2);
11283
+ }
11284
+ catch (Exception e)
11285
+ {
11286
+ System.err.println("FAILED: " + NOISE_TEXTURE);
11287
+ }
11288
+
1042911289
1043011290 gl.glActiveTexture(GL.GL_TEXTURE0);
1043111291 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -10448,9 +11308,9 @@
1044811308
1044911309 gl.glMatrixMode(GL.GL_MODELVIEW);
1045011310
10451
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10452
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10453
-//gl.glEnable(gl.GL_MULTISAMPLE);
11311
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11312
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11313
+gl.glEnable(gl.GL_MULTISAMPLE);
1045411314 } else
1045511315 {
1045611316 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -10461,7 +11321,7 @@
1046111321 //System.out.println("BLENDING ON");
1046211322 gl.glEnable(GL.GL_BLEND);
1046311323 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
10464
-
11324
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1046511325 gl.glMatrixMode(gl.GL_PROJECTION);
1046611326 gl.glLoadIdentity();
1046711327
....@@ -10550,8 +11410,8 @@
1055011410 System.err.println("parentcam != renderCamera");
1055111411
1055211412 // if (cam != lightCamera)
10553
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10554
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11413
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11414
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1055511415 }
1055611416
1055711417 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -10572,8 +11432,8 @@
1057211432 if (true) // TODO
1057311433 {
1057411434 if (cam != lightCamera)
10575
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10576
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11435
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11436
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
1057711437 }
1057811438
1057911439 LA.xformPos(light0, cam.toScreen, light0);
....@@ -10710,7 +11570,7 @@
1071011570 }
1071111571 }
1071211572
10713
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11573
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1071411574 {
1071511575 //gl.glDepthFunc(GL.GL_LEQUAL);
1071611576 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -10718,24 +11578,21 @@
1071811578
1071911579 boolean texon = textureon;
1072011580
10721
- if (RENDERPROGRAM > 0)
10722
- {
10723
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
10724
- textureon = false;
10725
- }
11581
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11582
+ textureon = false;
11583
+
1072611584 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1072711585 //System.out.println("ALLO");
1072811586 gl.glColorMask(false, false, false, false);
1072911587 DrawObject(gl);
10730
- if (RENDERPROGRAM > 0)
10731
- {
10732
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
10733
- textureon = texon;
10734
- }
11588
+
11589
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11590
+ textureon = texon;
11591
+
1073511592 gl.glColorMask(true, true, true, true);
1073611593
1073711594 gl.glDepthFunc(GL.GL_EQUAL);
10738
- //gl.glDepthMask(false);
11595
+ gl.glDepthMask(false);
1073911596 }
1074011597
1074111598 if (false) // DrawMode() == SHADOW)
....@@ -10889,8 +11746,14 @@
1088911746 {
1089011747 renderpass++;
1089111748 // System.out.println("Draw object... ");
11749
+ STEP = 1;
1089211750 if (FAST) // in case there is no script
10893
- STEP = 16;
11751
+ STEP = 8;
11752
+
11753
+ if (CURRENTANTIALIAS == 0 || ACSIZE == 1)
11754
+ {
11755
+ STEP *= 4;
11756
+ }
1089411757
1089511758 //object.FullInvariants();
1089611759
....@@ -10904,23 +11767,44 @@
1090411767 e.printStackTrace();
1090511768 }
1090611769
10907
- if (GrafreeD.RENDERME > 0)
10908
- GrafreeD.RENDERME--; // mechante magouille
11770
+ if (Grafreed.RENDERME > 0)
11771
+ Grafreed.RENDERME--; // mechante magouille
1090911772
1091011773 Globals.ONESTEP = false;
1091111774 }
1091211775
1091311776 static boolean zoomonce = false;
1091411777
11778
+ static void CreateSelectedPoint()
11779
+ {
11780
+ if (selectedpoint == null)
11781
+ {
11782
+ debugpointG = new Sphere();
11783
+ debugpointP = new Sphere();
11784
+ debugpointC = new Sphere();
11785
+ debugpointR = new Sphere();
11786
+
11787
+ selectedpoint = new Superellipsoid();
11788
+
11789
+ for (int i=0; i<8; i++)
11790
+ {
11791
+ debugpoints[i] = new Sphere();
11792
+ }
11793
+ }
11794
+ }
11795
+
1091511796 void DrawObject(GL gl, boolean draw)
1091611797 {
11798
+ // To clear camera values
11799
+ ResetOptions();
11800
+
1091711801 //System.out.println("DRAW OBJECT " + mouseDown);
1091811802 // DrawMode() = SELECTION;
1091911803 //GL gl = getGL();
1092011804 if ((TRACK || SHADOWTRACK) || zoomonce)
1092111805 {
1092211806 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
10923
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11807
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1092411808 pingthread.StepToTarget(true); // true);
1092511809 // zoomonce = false;
1092611810 }
....@@ -10975,7 +11859,14 @@
1097511859
1097611860 usedtextures.clear();
1097711861
10978
- BindTextures(DEFAULT_TEXTURES, 2);
11862
+ try
11863
+ {
11864
+ BindTextures(DEFAULT_TEXTURES, 2);
11865
+ }
11866
+ catch (Exception e)
11867
+ {
11868
+ System.err.println("FAILED: " + DEFAULT_TEXTURES);
11869
+ }
1097911870 }
1098011871 //System.out.println("--> " + stackdepth);
1098111872 // GrafreeD.traceon();
....@@ -10985,8 +11876,9 @@
1098511876
1098611877 if (DrawMode() == DEFAULT)
1098711878 {
10988
- if (DEBUG)
11879
+ if (Globals.DEBUG)
1098911880 {
11881
+ CreateSelectedPoint();
1099011882 float radius = 0.05f;
1099111883 if (selectedpoint.radius != radius)
1099211884 {
....@@ -11040,20 +11932,32 @@
1104011932 ReleaseTextures(DEFAULT_TEXTURES);
1104111933
1104211934 if (CLEANCACHE)
11043
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11935
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1104411936 {
11045
- String tex = e.nextElement();
11937
+ cTexture tex = e.nextElement();
1104611938
1104711939 // System.out.println("Texture --------- " + tex);
1104811940
11049
- if (tex.equals("WHITE_NOISE"))
11941
+ if (tex.equals("WHITE_NOISE:"))
1105011942 continue;
1105111943
11052
- if (!usedtextures.containsKey(tex))
11944
+ if (!usedtextures.contains(tex))
1105311945 {
11946
+ CacheTexture gettex = texturepigment.get(tex);
1105411947 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11055
- textures.get(tex).texture.dispose();
11056
- textures.remove(tex);
11948
+ if (gettex != null)
11949
+ {
11950
+ gettex.texture.dispose();
11951
+ texturepigment.remove(tex);
11952
+ }
11953
+
11954
+ gettex = texturebump.get(tex);
11955
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11956
+ if (gettex != null)
11957
+ {
11958
+ gettex.texture.dispose();
11959
+ texturebump.remove(tex);
11960
+ }
1105711961 }
1105811962 }
1105911963 }
....@@ -11066,7 +11970,14 @@
1106611970 if (checker != null && DrawMode() == DEFAULT)
1106711971 {
1106811972 //BindTexture(IMMORTAL_TEXTURE);
11069
- BindTextures(checker.GetTextures(), checker.texres);
11973
+ try
11974
+ {
11975
+ BindTextures(checker.GetTextures(), checker.texres);
11976
+ }
11977
+ catch (Exception e)
11978
+ {
11979
+ System.err.println("FAILED: " + checker.GetTextures());
11980
+ }
1107011981 // NEAREST
1107111982 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
1107211983 DrawChecker(gl);
....@@ -11148,7 +12059,7 @@
1114812059 return;
1114912060 }
1115012061
11151
- String string = obj.GetToolTip();
12062
+ String string = obj.toString(); //.GetToolTip();
1115212063
1115312064 GL gl = GetGL();
1115412065
....@@ -11465,8 +12376,8 @@
1146512376 //obj.TransformToWorld(light, light);
1146612377 for (int i = tp.size(); --i >= 0;)
1146712378 {
11468
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
11469
- LA.xformPos(light, tp.get(i).toParent, light);
12379
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12380
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1147012381 }
1147112382
1147212383
....@@ -11483,8 +12394,8 @@
1148312394 parentcam = cameras[0];
1148412395 }
1148512396
11486
- for (int count = parentcam.GetTransformCount(); --count>=0;)
11487
- LA.xformPos(light, parentcam.toParent, light); // may 2013
12397
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
12398
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1148812399
1148912400 LA.xformPos(light, renderCamera.toScreen, light);
1149012401
....@@ -11574,8 +12485,76 @@
1157412485
1157512486 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1157612487
11577
- String program =
12488
+ String programmin =
12489
+ // Min shader
1157812490 "!!ARBfp1.0\n" +
12491
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12492
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12493
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12494
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12495
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12496
+ "PARAM light2cam0 = program.env[10];" +
12497
+ "PARAM light2cam1 = program.env[11];" +
12498
+ "PARAM light2cam2 = program.env[12];" +
12499
+ "TEMP temp;" +
12500
+ "TEMP light;" +
12501
+ "TEMP ndotl;" +
12502
+ "TEMP normal;" +
12503
+ "TEMP depth;" +
12504
+ "TEMP eye;" +
12505
+ "TEMP pos;" +
12506
+
12507
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12508
+ Normalize("normal") +
12509
+ "MOV light, state.light[0].position;" +
12510
+ "DP3 ndotl.x, light, normal;" +
12511
+
12512
+ // shadow
12513
+ "MOV pos, fragment.texcoord[1];" +
12514
+ "MOV temp, pos;" +
12515
+ ShadowTextureFetch("depth", "temp", "1") +
12516
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12517
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12518
+
12519
+ // No shadow when out of frustum
12520
+ //"SGE temp.y, depth.z, zero123.y;" +
12521
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12522
+
12523
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12524
+
12525
+ // Backlit
12526
+ "MOV pos.w, zero123.y;" +
12527
+ "DP4 eye.x, pos, light2cam0;" +
12528
+ "DP4 eye.y, pos, light2cam1;" +
12529
+ "DP4 eye.z, pos, light2cam2;" +
12530
+ Normalize("eye") +
12531
+
12532
+ "DP3 ndotl.y, -eye, normal;" +
12533
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12534
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12535
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12536
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12537
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12538
+
12539
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12540
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12541
+
12542
+ // Pigment
12543
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12544
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12545
+ "MUL temp, temp, ndotl.x;" +
12546
+
12547
+ "MUL temp, temp, zero123.z;" +
12548
+
12549
+ //"MUL temp, temp, ndotl.y;" +
12550
+
12551
+ "MOV temp.w, zero123.y;" + // reset alpha
12552
+ "MOV result.color, temp;" +
12553
+ "END";
12554
+
12555
+ String programmax =
12556
+ "!!ARBfp1.0\n" +
12557
+
1157912558 //"OPTION ARB_fragment_program_shadow;" +
1158012559 "PARAM light2cam0 = program.env[10];" +
1158112560 "PARAM light2cam1 = program.env[11];" +
....@@ -11690,8 +12669,7 @@
1169012669 "TEMP shininess;" +
1169112670 "\n" +
1169212671 "MOV texSamp, one;" +
11693
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
11694
-
12672
+
1169512673 "MOV mapgrid.x, one2048th.x;" +
1169612674 "MOV temp, fragment.texcoord[1];" +
1169712675 /*
....@@ -11712,20 +12690,20 @@
1171212690 "MUL temp, floor, mapgrid.x;" +
1171312691 //"TEX depth0, temp, texture[1], 2D;" +
1171412692 (((mode & FP_SOFTSHADOW) == 0) ? "" :
11715
- TextureFetch("depth0", "temp", "1") +
12693
+ ShadowTextureFetch("depth0", "temp", "1") +
1171612694 "") +
1171712695 "ADD temp.x, temp.x, mapgrid.x;" +
1171812696 //"TEX depth1, temp, texture[1], 2D;" +
1171912697 (((mode & FP_SOFTSHADOW) == 0) ? "" :
11720
- TextureFetch("depth1", "temp", "1") +
12698
+ ShadowTextureFetch("depth1", "temp", "1") +
1172112699 "") +
1172212700 "ADD temp.y, temp.y, mapgrid.x;" +
1172312701 //"TEX depth2, temp, texture[1], 2D;" +
11724
- TextureFetch("depth2", "temp", "1") +
12702
+ ShadowTextureFetch("depth2", "temp", "1") +
1172512703 "SUB temp.x, temp.x, mapgrid.x;" +
1172612704 //"TEX depth3, temp, texture[1], 2D;" +
1172712705 (((mode & FP_SOFTSHADOW) == 0) ? "" :
11728
- TextureFetch("depth3", "temp", "1") +
12706
+ ShadowTextureFetch("depth3", "temp", "1") +
1172912707 "") +
1173012708 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1173112709 //"MOV params, material;" +
....@@ -12096,10 +13074,10 @@
1209613074 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1209713075 "") +
1209813076
12099
- // display shadow only (bump == 0)
13077
+ // display shadow only (fakedepth == 0)
1210013078 "SUB temp.x, half.x, shadow.x;" +
12101
- "MOV temp.y, -params6.x;" +
12102
- "SLT temp.z, temp.y, zero.x;" +
13079
+ "MOV temp.y, -params5.z;" + // params6.x;" +
13080
+ "SLT temp.z, temp.y, -c256i.x;" +
1210313081 "SUB temp.y, one.x, temp.z;" +
1210413082 "MUL temp.x, temp.x, temp.y;" +
1210513083 "KIL temp.x;" +
....@@ -12228,8 +13206,10 @@
1222813206 "MAX ndotl.x, ndotl.x, -ndotl.x;" +
1222913207
1223013208 "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
13209
+ // Tuning for default skin
13210
+ //"ADD temp.x, temp.x, options2.z;" + // lightsheen
13211
+ "MAD temp.x, options2.z, half.y, temp.x;" + // lightsheen
13212
+ "ADD temp.y, one.y, options2.y;" + // subsurface
1223313213 "MUL temp.x, temp.x, temp.y;" +
1223413214
1223513215 "MUL saturation, saturation, temp.xxxx;" +
....@@ -12428,7 +13408,14 @@
1242813408 //once = true;
1242913409 }
1243013410
12431
- System.out.print("Program #" + mode + "; length = " + program.length());
13411
+ String program = programmax;
13412
+
13413
+ if (Globals.MINSHADER)
13414
+ {
13415
+ program = programmin;
13416
+ }
13417
+
13418
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1243213419 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1243313420 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1243413421
....@@ -12521,25 +13508,26 @@
1252113508 return out;
1252213509 }
1252313510
12524
- String TextureFetch(String dest, String src, String unit)
13511
+ // Also does frustum culling
13512
+ String ShadowTextureFetch(String dest, String src, String unit)
1252513513 {
1252613514 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1252713515 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1252813516 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13517
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13518
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1252913519 "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;" +
13520
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13521
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1253413522 //"SWZ buffer, temp, w,w,w,w;";
12535
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13523
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1253613524 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1253713525 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1253813526 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
12539
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13527
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1254013528
12541
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
12542
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13529
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13530
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1254313531 }
1254413532
1254513533 String Shadow(String depth, String shadow)
....@@ -12561,12 +13549,16 @@
1256113549
1256213550 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1256313551 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13552
+
13553
+ // Compare fragment depth in light space with shadowmap.
1256413554 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1256513555 "SGE temp.y, temp.x, zero.x;" +
12566
- "SUB " + shadow + ".y, one.x, temp.y;" +
13556
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13557
+
13558
+ // Reverse comparison
1256713559 "SUB temp.x, one.x, temp.x;" +
1256813560 "MUL " + shadow + ".x, temp.x, temp.y;" +
12569
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13561
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1257013562 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1257113563
1257213564 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -12580,6 +13572,10 @@
1258013572 // No shadow for backface
1258113573 "DP3 temp.x, normal, lightd;" +
1258213574 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13575
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13576
+
13577
+ // No shadow when out of frustum
13578
+ "SGE temp.x, " + depth + ".z, one.z;" +
1258313579 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1258413580 "";
1258513581 }
....@@ -12726,7 +13722,8 @@
1272613722 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1272713723 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1272813724 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
12729
- Object3D.cVector2[] vector2buffer;
13725
+
13726
+ //Object3D.cVector2[] vector2buffer;
1273013727
1273113728 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1273213729 // OUT : diff, spec
....@@ -12742,9 +13739,10 @@
1274213739 "DP3 " + dest + ".z," + "normals," + "eye;" +
1274313740 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1274413741 //"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;" +
13742
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13743
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13744
+
13745
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1274813746 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1274913747 "RCP " + dest + ".w," + dest + ".w;" +
1275013748 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13138,7 +14136,7 @@
1313814136 public void mousePressed(MouseEvent e)
1313914137 {
1314014138 //System.out.println("mousePressed: " + e);
13141
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14139
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1314214140 }
1314314141
1314414142 static long prevtime = 0;
....@@ -13165,6 +14163,7 @@
1316514163
1316614164 //System.err.println("Dtime = " + Dtime + "; units = " + e.getUnitsToScroll() + "; ratio (units/ms) = " + ratio);
1316714165
14166
+ if (BUTTONLESSWHEEL)
1316814167 if (Math.abs(ratio) < 0.1 || Math.abs(Dtime) == 0) // < 30)
1316914168 {
1317014169 return;
....@@ -13173,7 +14172,7 @@
1317314172 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
1317414173
1317514174 // TIMER
13176
- if (!wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
14175
+ if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
1317714176 {
1317814177 keepboxmode = BOXMODE;
1317914178 keepsupport = SUPPORT;
....@@ -13213,8 +14212,8 @@
1321314212 // mode |= META;
1321414213 //}
1321514214
13216
- SetMouseMode(WHEEL | e.getModifiersEx());
13217
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14215
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14216
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1321814217 anchorX = ax;
1321914218 anchorY = ay;
1322014219 prevX = px;
....@@ -13248,6 +14247,7 @@
1324814247 else
1324914248 if (evt.getSource() == AAtimer)
1325014249 {
14250
+ Globals.TIMERRUNNING = false;
1325114251 if (mouseDown)
1325214252 {
1325314253 //new Exception().printStackTrace();
....@@ -13273,6 +14273,10 @@
1327314273 // LIVE = waslive;
1327414274 // wasliveok = true;
1327514275 // waslive = false;
14276
+
14277
+ // May 2019 Forget it:
14278
+ if (true)
14279
+ return;
1327614280
1327714281 // source == timer
1327814282 if (mouseDown)
....@@ -13303,7 +14307,7 @@
1330314307
1330414308 // fev 2014???
1330514309 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13306
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14310
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1330714311 pingthread.StepToTarget(true); // true);
1330814312 }
1330914313 // if (!LIVE)
....@@ -13312,12 +14316,13 @@
1331214316
1331314317 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1331414318
13315
- void clickStart(int x, int y, int modifiers)
14319
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1331614320 {
1331714321 if (!wasliveok)
1331814322 return;
1331914323
1332014324 AAtimer.restart(); //
14325
+ Globals.TIMERRUNNING = true;
1332114326
1332214327 // waslive = LIVE;
1332314328 // LIVE = false;
....@@ -13329,7 +14334,7 @@
1332914334 // touched = true; // main DL
1333014335 if (isRenderer)
1333114336 {
13332
- SetMouseMode(modifiers);
14337
+ SetMouseMode(modifiers, modifiersex);
1333314338 }
1333414339
1333514340 selectX = anchorX = x;
....@@ -13342,7 +14347,7 @@
1334214347 clicked = true;
1334314348 hold = false;
1334414349
13345
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14350
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1334614351 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1334714352 {
1334814353 // System.out.println("RESTART II " + modifiers);
....@@ -13367,14 +14372,15 @@
1336714372 drag = false;
1336814373 //System.out.println("Mouse DOWN");
1336914374 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);
14375
+ //ClickInfo info = new ClickInfo();
14376
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14377
+ object.clickInfo.pane = this;
14378
+ object.clickInfo.camera = renderCamera;
14379
+ object.clickInfo.x = x;
14380
+ object.clickInfo.y = y;
14381
+ object.clickInfo.modifiers = modifiersex;
14382
+ editObj = object.doEditClick(//info,
14383
+ 0);
1337814384 if (!editObj)
1337914385 {
1338014386 hasMarquee = true;
....@@ -13390,11 +14396,14 @@
1339014396
1339114397 public void mouseDragged(MouseEvent e)
1339214398 {
14399
+ Globals.MOUSEDRAGGED = true;
14400
+
14401
+ //System.out.println("mouseDragged: " + e);
1339314402 if (isRenderer)
1339414403 movingcamera = true;
14404
+
1339514405 //if (drawing)
1339614406 //return;
13397
- //System.out.println("mouseDragged: " + e);
1339814407 if ((e.getModifiersEx() & CTRL) != 0
1339914408 || (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen())
1340014409 {
....@@ -13402,7 +14411,7 @@
1340214411 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1340314412 }
1340414413 else
13405
- drag(e.getX(), e.getY(), e.getModifiersEx());
14414
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1340614415
1340714416 //try { Thread.sleep(1); } catch (Exception ex) {}
1340814417 }
....@@ -13575,6 +14584,7 @@
1357514584
1357614585 public void run()
1357714586 {
14587
+ new Exception().printStackTrace();
1357814588 System.exit(0);
1357914589 for (;;)
1358014590 {
....@@ -13638,7 +14648,7 @@
1363814648 {
1363914649 Globals.lighttouched = true;
1364014650 }
13641
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14651
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1364214652 }
1364314653 //else
1364414654 }
....@@ -13652,12 +14662,12 @@
1365214662 void GoDown(int mod)
1365314663 {
1365414664 MODIFIERS |= COMMAND;
13655
- /*
14665
+ /**/
1365614666 if((mod&SHIFT) == SHIFT)
13657
- manipCamera.RotatePosition(0, -speed);
14667
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
1365814668 else
13659
- manipCamera.BackForth(0, -speed*delta, getWidth());
13660
- */
14669
+ manipCamera.RotatePosition(0, -speed);
14670
+ /**/
1366114671 if ((mod & SHIFT) == SHIFT)
1366214672 {
1366314673 mouseMode = mouseMode; // VR??
....@@ -13673,12 +14683,12 @@
1367314683 void GoUp(int mod)
1367414684 {
1367514685 MODIFIERS |= COMMAND;
13676
- /*
14686
+ /**/
1367714687 if((mod&SHIFT) == SHIFT)
13678
- manipCamera.RotatePosition(0, speed);
14688
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
1367914689 else
13680
- manipCamera.BackForth(0, speed*delta, getWidth());
13681
- */
14690
+ manipCamera.RotatePosition(0, speed);
14691
+ /**/
1368214692 if ((mod & SHIFT) == SHIFT)
1368314693 {
1368414694 mouseMode = mouseMode;
....@@ -13694,12 +14704,12 @@
1369414704 void GoLeft(int mod)
1369514705 {
1369614706 MODIFIERS |= COMMAND;
13697
- /*
14707
+ /**/
1369814708 if((mod&SHIFT) == SHIFT)
13699
- manipCamera.RotatePosition(speed, 0);
13700
- else
1370114709 manipCamera.Translate(speed*delta, 0, getWidth());
13702
- */
14710
+ else
14711
+ manipCamera.RotatePosition(speed, 0);
14712
+ /**/
1370314713 if ((mod & SHIFT) == SHIFT)
1370414714 {
1370514715 mouseMode = mouseMode;
....@@ -13715,12 +14725,12 @@
1371514725 void GoRight(int mod)
1371614726 {
1371714727 MODIFIERS |= COMMAND;
13718
- /*
14728
+ /**/
1371914729 if((mod&SHIFT) == SHIFT)
13720
- manipCamera.RotatePosition(-speed, 0);
13721
- else
1372214730 manipCamera.Translate(-speed*delta, 0, getWidth());
13723
- */
14731
+ else
14732
+ manipCamera.RotatePosition(-speed, 0);
14733
+ /**/
1372414734 if ((mod & SHIFT) == SHIFT)
1372514735 {
1372614736 mouseMode = mouseMode;
....@@ -13738,7 +14748,7 @@
1373814748 int X, Y;
1373914749 boolean SX, SY;
1374014750
13741
- void drag(int x, int y, int modifiers)
14751
+ void drag(int x, int y, int modifiers, int modifiersex)
1374214752 {
1374314753 if (IsFrozen())
1374414754 {
....@@ -13747,17 +14757,17 @@
1374714757
1374814758 drag = true; // NEW
1374914759
13750
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14760
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1375114761
1375214762 X = x;
1375314763 Y = y;
1375414764 // floating state for animation
13755
- MODIFIERS = modifiers;
13756
- modifiers &= ~1024;
14765
+ MODIFIERS = modifiersex;
14766
+ modifiersex &= ~1024;
1375714767 if (false) // modifiers != 0)
1375814768 {
1375914769 //new Exception().printStackTrace();
13760
- System.out.println("mouseDragged: " + modifiers);
14770
+ System.out.println("mouseDragged: " + modifiersex);
1376114771 System.out.println("SHIFT = " + SHIFT);
1376214772 System.out.println("CONTROL = " + COMMAND);
1376314773 System.out.println("META = " + META);
....@@ -13770,14 +14780,16 @@
1377014780 if (editObj)
1377114781 {
1377214782 drag = true;
13773
- ClickInfo info = new ClickInfo();
13774
- info.bounds.setBounds(0, 0,
14783
+ //ClickInfo info = new ClickInfo();
14784
+ object.clickInfo.bounds.setBounds(0, 0,
1377514785 (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);
14786
+ object.clickInfo.pane = this;
14787
+ object.clickInfo.camera = renderCamera;
14788
+ object.clickInfo.x = x;
14789
+ object.clickInfo.y = y;
14790
+ object //.GetWindow().copy
14791
+ .doEditDrag(//info,
14792
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1378114793 } else
1378214794 {
1378314795 if (x < startX)
....@@ -13926,23 +14938,27 @@
1392614938 }
1392714939 }
1392814940
14941
+// ClickInfo clickInfo = new ClickInfo();
14942
+
1392914943 public void mouseMoved(MouseEvent e)
1393014944 {
1393114945 //System.out.println("mouseMoved: " + e);
13932
-
1393314946 if (isRenderer)
1393414947 return;
1393514948
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;
14949
+ // Mouse cursor feedback
14950
+ object.clickInfo.x = e.getX();
14951
+ object.clickInfo.y = e.getY();
14952
+ object.clickInfo.modifiers = e.getModifiersEx();
14953
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14954
+ object.clickInfo.pane = this;
14955
+ object.clickInfo.camera = renderCamera;
1394314956 if (!isRenderer)
1394414957 {
13945
- if (object.editWindow.copy.doEditClick(ci, 0))
14958
+ //ObjEditor editWindow = object.editWindow;
14959
+ //Object3D copy = editWindow.copy;
14960
+ if (object.doEditClick(//clickInfo,
14961
+ 0))
1394614962 {
1394714963 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1394814964 } else
....@@ -13954,7 +14970,11 @@
1395414970
1395514971 public void mouseReleased(MouseEvent e)
1395614972 {
14973
+ Globals.MOUSEDRAGGED = false;
14974
+
1395714975 movingcamera = false;
14976
+ X = 0; // getBounds().width/2;
14977
+ Y = 0; // getBounds().height/2;
1395814978 //System.out.println("mouseReleased: " + e);
1395914979 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1396014980 }
....@@ -13977,9 +14997,9 @@
1397714997 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1397814998 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1397914999
13980
- if (control || command || IsFrozen())
15000
+// No delay if (control || command || IsFrozen())
1398115001 timeout = true;
13982
- else
15002
+// ?? May 2019 else
1398315003 // timer.setDelay((modifiers & 128) != 0?0:350);
1398415004 mouseDown = false;
1398515005 if (!control && !command) // june 2013
....@@ -14089,7 +15109,7 @@
1408915109 System.out.println("keyReleased: " + e);
1409015110 }
1409115111
14092
- void SetMouseMode(int modifiers)
15112
+ void SetMouseMode(int modifiers, int modifiersex)
1409315113 {
1409415114 //System.out.println("SetMouseMode = " + modifiers);
1409515115 //modifiers &= ~1024;
....@@ -14101,25 +15121,25 @@
1410115121 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1410215122 // return;
1410315123 //System.out.println("SetMode = " + modifiers);
14104
- if ((modifiers & WHEEL) == WHEEL)
15124
+ if ((modifiersex & WHEEL) == WHEEL)
1410515125 {
1410615126 mouseMode |= ZOOM;
1410715127 }
1410815128
1410915129 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
14110
- if (capsLocked || (modifiers & META) == META)
15130
+ if (capsLocked) // || (modifiers & META) == META)
1411115131 {
1411215132 mouseMode |= VR; // BACKFORTH;
1411315133 }
14114
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
15134
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1411515135 {
1411615136 mouseMode |= SELECT;
1411715137 }
14118
- if ((modifiers & COMMAND) == COMMAND)
15138
+ if ((modifiersex & COMMAND) == COMMAND)
1411915139 {
1412015140 mouseMode |= SELECT;
1412115141 }
14122
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15142
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
1412315143 {
1412415144 mouseMode &= ~VR;
1412515145 mouseMode |= TRANSLATE;
....@@ -14148,7 +15168,7 @@
1414815168
1414915169 if (isRenderer) //
1415015170 {
14151
- SetMouseMode(modifiers);
15171
+ SetMouseMode(0, modifiers);
1415215172 }
1415315173
1415415174 Globals.theRenderer.keyPressed(key);
....@@ -14210,7 +15230,8 @@
1421015230 // break;
1421115231 case 'T':
1421215232 CACHETEXTURE ^= true;
14213
- textures.clear();
15233
+ texturepigment.clear();
15234
+ texturebump.clear();
1421415235 // repaint();
1421515236 break;
1421615237 case 'Y':
....@@ -14295,7 +15316,9 @@
1429515316 case 'E' : COMPACT ^= true;
1429615317 repaint();
1429715318 break;
14298
- case 'W' : DEBUGHSB ^= true;
15319
+ case 'W' : // Wide Window (fullscreen)
15320
+ //DEBUGHSB ^= true;
15321
+ ObjEditor.theFrame.ToggleFullScreen();
1429915322 repaint();
1430015323 break;
1430115324 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14320,8 +15343,8 @@
1432015343 RevertCamera();
1432115344 repaint();
1432215345 break;
14323
- case 'L':
1432415346 case 'l':
15347
+ //case 'L':
1432515348 if (lightMode)
1432615349 {
1432715350 lightMode = false;
....@@ -14385,20 +15408,24 @@
1438515408 OCCLUSION_CULLING ^= true;
1438615409 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1438715410 break;
14388
- case '0': envyoff ^= true; repaint(); break;
15411
+ //case '0': envyoff ^= true; repaint(); break;
1438915412 case '1':
1439015413 case '2':
1439115414 case '3':
1439215415 case '4':
1439315416 case '5':
14394
- newenvy = Character.getNumericValue(key);
14395
- repaint();
14396
- break;
1439715417 case '6':
1439815418 case '7':
1439915419 case '8':
1440015420 case '9':
14401
- BGcolor = (key - '6')/3.f;
15421
+ if (true) // envyoff)
15422
+ {
15423
+ BGcolor = (key - '1')/8.f;
15424
+ }
15425
+ else
15426
+ {
15427
+ //newenvy = Character.getNumericValue(key);
15428
+ }
1440215429 repaint();
1440315430 break;
1440415431 case '!':
....@@ -14464,9 +15491,9 @@
1446415491 case '_':
1446515492 kompactbit = 5;
1446615493 break;
14467
- case '+':
14468
- kompactbit = 6;
14469
- break;
15494
+// case '+':
15495
+// kompactbit = 6;
15496
+// break;
1447015497 case ' ':
1447115498 lightMode ^= true;
1447215499 Globals.lighttouched = true;
....@@ -14478,13 +15505,14 @@
1447815505 case ESC:
1447915506 RENDERPROGRAM += 1;
1448015507 RENDERPROGRAM %= 3;
15508
+
1448115509 repaint();
1448215510 break;
1448315511 case 'Z':
1448415512 //RESIZETEXTURE ^= true;
1448515513 //break;
1448615514 case 'z':
14487
- RENDERSHADOW ^= true;
15515
+ Globals.RENDERSHADOW ^= true;
1448815516 Globals.lighttouched = true;
1448915517 repaint();
1449015518 break;
....@@ -14517,8 +15545,9 @@
1451715545 case DELETE:
1451815546 ClearSelection();
1451915547 break;
14520
- /*
1452115548 case '+':
15549
+
15550
+ /*
1452215551 //fontsize += 1;
1452315552 bbzoom *= 2;
1452415553 repaint();
....@@ -14535,17 +15564,17 @@
1453515564 case '=':
1453615565 IncDepth();
1453715566 //fontsize += 1;
14538
- object.editWindow.refreshContents(true);
15567
+ object.GetWindow().refreshContents(true);
1453915568 maskbit = 6;
1454015569 break;
1454115570 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1454215571 DecDepth();
1454315572 maskbit = 5;
1454415573 //if(fontsize > 1) fontsize -= 1;
14545
- if (object.editWindow == null)
14546
- new Exception().printStackTrace();
14547
- else
14548
- object.editWindow.refreshContents(true);
15574
+// if (object.editWindow == null)
15575
+// new Exception().printStackTrace();
15576
+// else
15577
+ object.GetWindow().refreshContents(true);
1454915578 break;
1455015579 case '{':
1455115580 manipCamera.shaper_fovy /= 1.1;
....@@ -14608,7 +15637,7 @@
1460815637 //mode = ROTATE;
1460915638 if ((MODIFIERS & COMMAND) == 0) // VR??
1461015639 {
14611
- SetMouseMode(modifiers);
15640
+ SetMouseMode(0, modifiers);
1461215641 }
1461315642 }
1461415643
....@@ -14742,8 +15771,9 @@
1474215771
1474315772 protected void processMouseMotionEvent(MouseEvent e)
1474415773 {
14745
- //System.out.println("processMouseMotionEvent: " + mouseMode);
14746
- if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15774
+ //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
15775
+ //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15776
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1474715777 {
1474815778 mouseMoved(e);
1474915779 } else
....@@ -14768,11 +15798,12 @@
1476815798 }
1476915799 */
1477015800
14771
- object.editWindow.EditSelection();
15801
+ object.GetWindow().EditSelection(false);
1477215802 }
1477315803
1477415804 void SelectParent()
1477515805 {
15806
+ new Exception().printStackTrace();
1477615807 System.exit(0);
1477715808 Composite group = (Composite) object;
1477815809 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -14784,10 +15815,10 @@
1478415815 {
1478515816 //selectees.remove(i);
1478615817 System.out.println("select parent of " + elem);
14787
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15818
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1478815819 } else
1478915820 {
14790
- group.editWindow.Select(elem.GetTreePath(), first, true);
15821
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1479115822 }
1479215823
1479315824 first = false;
....@@ -14796,6 +15827,7 @@
1479615827
1479715828 void SelectChildren()
1479815829 {
15830
+ new Exception().printStackTrace();
1479915831 System.exit(0);
1480015832 /*
1480115833 Composite group = (Composite) object;
....@@ -14828,12 +15860,12 @@
1482815860 for (int j = 0; j < group.children.size(); j++)
1482915861 {
1483015862 elem = (Object3D) group.children.elementAt(j);
14831
- object.editWindow.Select(elem.GetTreePath(), first, true);
15863
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1483215864 first = false;
1483315865 }
1483415866 } else
1483515867 {
14836
- object.editWindow.Select(elem.GetTreePath(), first, true);
15868
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1483715869 }
1483815870
1483915871 first = false;
....@@ -14844,21 +15876,21 @@
1484415876 {
1484515877 //Composite group = (Composite) object;
1484615878 Object3D group = object;
14847
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15879
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1484815880 }
1484915881
1485015882 void ResetTransform(int mask)
1485115883 {
1485215884 //Composite group = (Composite) object;
1485315885 Object3D group = object;
14854
- group.editWindow.ResetTransform(mask);
15886
+ group.GetWindow().ResetTransform(mask);
1485515887 }
1485615888
1485715889 void FlipTransform()
1485815890 {
1485915891 //Composite group = (Composite) object;
1486015892 Object3D group = object;
14861
- group.editWindow.FlipTransform();
15893
+ group.GetWindow().FlipTransform();
1486215894 // group.editWindow.ReduceMesh(true);
1486315895 }
1486415896
....@@ -14866,7 +15898,7 @@
1486615898 {
1486715899 //Composite group = (Composite) object;
1486815900 Object3D group = object;
14869
- group.editWindow.PrintMemory();
15901
+ group.GetWindow().PrintMemory();
1487015902 // group.editWindow.ReduceMesh(true);
1487115903 }
1487215904
....@@ -14874,7 +15906,7 @@
1487415906 {
1487515907 //Composite group = (Composite) object;
1487615908 Object3D group = object;
14877
- group.editWindow.ResetCentroid();
15909
+ group.GetWindow().ResetCentroid();
1487815910 }
1487915911
1488015912 void IncDepth()
....@@ -14956,11 +15988,11 @@
1495615988
1495715989 int width = getBounds().width;
1495815990 int height = getBounds().height;
14959
- ClickInfo info = new ClickInfo();
14960
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1496115991 //Image img = CreateImage(width, height);
1496215992 //System.out.println("width = " + width + "; height = " + height + "\n");
15993
+
1496315994 Graphics gr = g; // img.getGraphics();
15995
+
1496415996 if (!hasMarquee)
1496515997 {
1496615998 if (Xmin < Xmax) // !locked)
....@@ -15032,40 +16064,88 @@
1503216064 }
1503316065 if (object != null && !hasMarquee)
1503416066 {
16067
+ if (object.clickInfo == null)
16068
+ object.clickInfo = new ClickInfo();
16069
+ ClickInfo info = object.clickInfo;
16070
+ //ClickInfo info = new ClickInfo();
16071
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16072
+
1503516073 if (isRenderer)
1503616074 {
15037
- info.flags++;
16075
+ object.clickInfo.flags++;
1503816076 double frameAspect = (double) width / (double) height;
1503916077 if (frameAspect > renderCamera.aspect)
1504016078 {
1504116079 int desired = (int) ((double) height * renderCamera.aspect);
15042
- info.bounds.width -= width - desired;
15043
- info.bounds.x += (width - desired) / 2;
16080
+ object.clickInfo.bounds.width -= width - desired;
16081
+ object.clickInfo.bounds.x += (width - desired) / 2;
1504416082 } else
1504516083 {
1504616084 int desired = (int) ((double) width / renderCamera.aspect);
15047
- info.bounds.height -= height - desired;
15048
- info.bounds.y += (height - desired) / 2;
16085
+ object.clickInfo.bounds.height -= height - desired;
16086
+ object.clickInfo.bounds.y += (height - desired) / 2;
1504916087 }
1505016088 }
15051
- info.g = gr;
15052
- info.camera = renderCamera;
16089
+
16090
+ object.clickInfo.g = gr;
16091
+ object.clickInfo.camera = renderCamera;
1505316092 /*
1505416093 // Memory intensive (brep.verticescopy)
1505516094 if (!(object instanceof Composite))
1505616095 object.draw(info, 0, false); // SLOW :
1505716096 */
15058
- if (!isRenderer)
16097
+ if (!isRenderer) // && drag)
1505916098 {
15060
- object.drawEditHandles(info, 0);
16099
+ Grafreed.Assert(object != null);
16100
+ Grafreed.Assert(object.selection != null);
16101
+ if (object.selection.Size() > 0)
16102
+ {
16103
+ int hitSomething = object.selection.get(0).hitSomething;
16104
+
16105
+ object.clickInfo.DX = 0;
16106
+ object.clickInfo.DY = 0;
16107
+ object.clickInfo.W = 1;
16108
+ if (hitSomething == Object3D.hitCenter)
16109
+ {
16110
+ info.DX = X;
16111
+ if (X != 0)
16112
+ info.DX -= info.bounds.width/2;
16113
+
16114
+ info.DY = Y;
16115
+ if (Y != 0)
16116
+ info.DY -= info.bounds.height/2;
16117
+ }
16118
+
16119
+ object.drawEditHandles(//info,
16120
+ 0);
16121
+
16122
+ if (drag && (X != 0 || Y != 0))
16123
+ {
16124
+ switch (hitSomething)
16125
+ {
16126
+ case Object3D.hitCenter: gr.setColor(Color.pink);
16127
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16128
+ break;
16129
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16130
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16131
+ break;
16132
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16133
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16134
+ break;
16135
+ }
16136
+
16137
+ }
16138
+ }
1506116139 }
1506216140 }
16141
+
1506316142 if (isRenderer)
1506416143 {
1506516144 //gr.setColor(Color.black);
1506616145 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1506716146 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1506816147 }
16148
+
1506916149 if (hasMarquee)
1507016150 {
1507116151 gr.setXORMode(Color.white);
....@@ -15178,6 +16258,7 @@
1517816258 public boolean mouseDown(Event evt, int x, int y)
1517916259 {
1518016260 System.out.println("mouseDown: " + evt);
16261
+ System.exit(0);
1518116262 /*
1518216263 locked = true;
1518316264 drag = false;
....@@ -15221,7 +16302,7 @@
1522116302 {
1522216303 keyPressed(0, modifiers);
1522316304 }
15224
- clickStart(x, y, modifiers);
16305
+ // clickStart(x, y, modifiers);
1522516306 return true;
1522616307 }
1522716308
....@@ -15339,7 +16420,7 @@
1533916420 {
1534016421 keyReleased(0, 0);
1534116422 }
15342
- drag(x, y, modifiers);
16423
+ drag(x, y, 0, modifiers);
1534316424 return true;
1534416425 }
1534516426
....@@ -15471,7 +16552,7 @@
1547116552 Object3D object;
1547216553 static Object3D trackedobject;
1547316554 Camera renderCamera; // Light or Eye (or Occlusion)
15474
- /*static*/ Camera manipCamera; // Light or Eye
16555
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1547516556 /*static*/ Camera eyeCamera;
1547616557 /*static*/ Camera lightCamera;
1547716558 int cameracount;
....@@ -15535,6 +16616,8 @@
1553516616 private /*static*/ boolean firstime;
1553616617 private /*static*/ cVector newView = new cVector();
1553716618 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16619
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16620
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1553816621 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1553916622 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1554016623 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -15547,29 +16630,67 @@
1554716630 {
1554816631 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1554916632
16633
+ int usedsuf = 0;
16634
+
1555016635 for (int i = 0; i < suffixes.length; i++)
1555116636 {
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)
16637
+ String[] suffixe = suffixes;
16638
+ String[] fallback = suffixes2;
16639
+ String[] fallfallback = suffixes3;
16640
+
16641
+ for (int c=usedsuf; --c>=0;)
1555716642 {
15558
- throw new IOException("Unable to load texture " + resourceName);
16643
+// String[] temp = suffixe;
16644
+// suffixe = fallback;
16645
+// fallback = fallfallback;
16646
+// fallfallback = temp;
1555916647 }
16648
+
16649
+ String resourceName = basename + suffixe[i] + "." + suffix;
16650
+ TextureData data;
16651
+
16652
+ try
16653
+ {
16654
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16655
+ mipmapped,
16656
+ FileUtil.getFileSuffix(resourceName));
16657
+ }
16658
+ catch (Exception e)
16659
+ {
16660
+ try
16661
+ {
16662
+ resourceName = basename + fallback[i] + "." + suffix;
16663
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16664
+ mipmapped,
16665
+ FileUtil.getFileSuffix(resourceName));
16666
+ }
16667
+ catch (Exception e2)
16668
+ {
16669
+ resourceName = basename + fallfallback[i] + "." + suffix;
16670
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16671
+ mipmapped,
16672
+ FileUtil.getFileSuffix(resourceName));
16673
+ }
16674
+ }
16675
+
1556016676 //System.out.println("Target = " + targets[i]);
1556116677 cubemap.updateImage(data, targets[i]);
1556216678 }
1556316679
1556416680 return cubemap;
1556516681 }
16682
+
1556616683 int bigsphere = -1;
1556716684
1556816685 float BGcolor = 0.5f;
1556916686
15570
- private void DrawSkyBox(GL gl)
16687
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16688
+
16689
+ private void DrawSkyBox(GL gl, float ratio)
1557116690 {
15572
- if (envyoff || cubemap == null)
16691
+ if (//envyoff ||
16692
+ WIREFRAME ||
16693
+ cubemap == null)
1557316694 {
1557416695 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1557516696 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -15584,7 +16705,17 @@
1558416705 // Compensates for ExaminerViewer's modification of modelview matrix
1558516706 gl.glMatrixMode(GL.GL_MODELVIEW);
1558616707 gl.glLoadIdentity();
16708
+ gl.glScalef(1,ratio,1);
1558716709
16710
+// colorV[0] = 2;
16711
+// colorV[1] = 2;
16712
+// colorV[2] = 2;
16713
+// colorV[3] = 1;
16714
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16715
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16716
+//
16717
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16718
+
1558816719 //gl.glActiveTexture(GL.GL_TEXTURE1);
1558916720 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1559016721
....@@ -15616,6 +16747,7 @@
1561616747 {
1561716748 gl.glScalef(1.0f, -1.0f, 1.0f);
1561816749 }
16750
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1561916751 gl.glMultMatrixd(viewrot_1, 0);
1562016752 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1562116753 //viewer.updateInverseRotation(gl);
....@@ -15756,16 +16888,16 @@
1575616888 cStatic.objectstack[materialdepth++] = checker;
1575716889 //System.out.println("material " + material);
1575816890 //Applet3D.tracein(this, selected);
15759
- vector2buffer = checker.projectedVertices;
16891
+ //vector2buffer = checker.projectedVertices;
1576016892
1576116893 //checker.GetMaterial().Draw(this, false); // true);
15762
- DrawMaterial(checker.GetMaterial(), false); // true);
16894
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1576316895
1576416896 materialdepth -= 1;
1576516897 if (materialdepth > 0)
1576616898 {
15767
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
15768
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
16899
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16900
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1576916901 }
1577016902 //checker.GetMaterial().opacity = 1f;
1577116903 ////checker.GetMaterial().ambient = 1f;
....@@ -15851,6 +16983,14 @@
1585116983 }
1585216984 }
1585316985
16986
+ private Object3D GetFolder()
16987
+ {
16988
+ Object3D folder = object.GetWindow().copy;
16989
+ if (object.GetWindow().copy.selection.Size() > 0)
16990
+ folder = object.GetWindow().copy.selection.elementAt(0);
16991
+ return folder;
16992
+ }
16993
+
1585416994 class SelectBuffer implements GLEventListener
1585516995 {
1585616996
....@@ -15866,7 +17006,7 @@
1586617006 //new Exception().printStackTrace();
1586717007 System.out.println("select buffer init");
1586817008 // Use debug pipeline
15869
- drawable.setGL(new DebugGL(drawable.getGL()));
17009
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1587017010
1587117011 GL gl = drawable.getGL();
1587217012
....@@ -15909,6 +17049,7 @@
1590917049 {
1591017050 if (!selection)
1591117051 {
17052
+ new Exception().printStackTrace();
1591217053 System.exit(0);
1591317054 return;
1591417055 }
....@@ -15929,6 +17070,17 @@
1592917070
1593017071 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1593117072
17073
+ if (PAINTMODE)
17074
+ {
17075
+ if (object.GetWindow().copy.selection.Size() > 0)
17076
+ {
17077
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17078
+
17079
+ // Make what you paint not selectable.
17080
+ paintobj.ResetSelectable();
17081
+ }
17082
+ }
17083
+
1593217084 //int tmp = selection_view;
1593317085 //selection_view = -1;
1593417086 int temp = DrawMode();
....@@ -15940,6 +17092,17 @@
1594017092 // temp = DEFAULT; // patch for selection debug
1594117093 Globals.drawMode = temp; // WARNING
1594217094
17095
+ if (PAINTMODE)
17096
+ {
17097
+ if (object.GetWindow().copy.selection.Size() > 0)
17098
+ {
17099
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17100
+
17101
+ // Revert.
17102
+ paintobj.RestoreSelectable();
17103
+ }
17104
+ }
17105
+
1594317106 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1594417107
1594517108 // trying different ways of getting the depth info over
....@@ -15987,6 +17150,8 @@
1598717150 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1598817151 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1598917152 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
17153
+
17154
+ CreateSelectedPoint();
1599017155
1599117156 // Will fit the mesh !!!
1599217157 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16036,34 +17201,36 @@
1603617201 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]));
1603717202 }
1603817203
16039
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
17204
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1604017205 }
1604117206 }
1604217207
1604317208 if (!movingcamera && !PAINTMODE)
16044
- object.editWindow.ScreenFitPoint(); // fev 2014
17209
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1604517210
16046
- if (PAINTMODE && GrafreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17211
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1604717212 {
16048
- Object3D paintobj = GrafreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17213
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1604917214
16050
- Object3D group = new Object3D("inst" + paintcount++);
17215
+ if (object.GetWindow().copy.selection.Size() > 0)
17216
+ {
17217
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1605117218
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();
17219
+ Object3D inst = new Object3D("inst" + paintcount++);
17220
+
17221
+ inst.CreateMaterial(); // use a void leaf to select instances
17222
+
17223
+ inst.add(paintobj); // link
17224
+
17225
+ object.GetWindow().SnapObject(inst);
17226
+
17227
+ Object3D folder = paintFolder; // GetFolder();
17228
+
17229
+ folder.add(inst);
17230
+
17231
+ object.GetWindow().ResetModel();
17232
+ object.GetWindow().refreshContents();
17233
+ }
1606717234 }
1606817235 else
1606917236 paintcount = 0;
....@@ -16102,6 +17269,11 @@
1610217269 //System.out.println("objects[color] = " + objects[color]);
1610317270 //objects[color].Select();
1610417271 indexcount = 0;
17272
+ ObjEditor window = object.GetWindow();
17273
+ if (window != null && deselect)
17274
+ {
17275
+ window.Select(null, deselect, true);
17276
+ }
1610517277 object.Select(color, deselect);
1610617278 }
1610717279
....@@ -16201,7 +17373,7 @@
1620117373 gl.glDisable(gl.GL_CULL_FACE);
1620217374 }
1620317375
16204
- if (!RENDERSHADOW)
17376
+ if (!Globals.RENDERSHADOW)
1620517377 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1620617378
1620717379 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -16211,7 +17383,7 @@
1621117383 //gl.glColorMask(false, false, false, false);
1621217384
1621317385 //render_scene_from_light_view(gl, drawable, 0, 0);
16214
- if (RENDERSHADOW && Globals.lighttouched && !movingcamera) // && !parent.IsFreezed())
17386
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1621517387 {
1621617388 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1621717389
....@@ -16380,10 +17552,14 @@
1638017552 gl.glFlush();
1638117553
1638217554 /**/
16383
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17555
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1638417556
16385
- float[] pixels = occlusionsizebuffer.array();
17557
+ float[] depths = occlusiondepthbuffer.array();
1638617558
17559
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17560
+
17561
+ int[] pixels = selectsizebuffer.array();
17562
+
1638717563 double r = 0, g = 0, b = 0;
1638817564
1638917565 double count = 0;
....@@ -16394,7 +17570,7 @@
1639417570
1639517571 double FACTOR = 1;
1639617572
16397
- for (int i = 0; i < pixels.length; i++)
17573
+ for (int i = 0; i < depths.length; i++)
1639817574 {
1639917575 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1640017576 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -16477,7 +17653,7 @@
1647717653
1647817654 double scale = ray.z; // 1; // cos
1647917655
16480
- float depth = pixels[newindex];
17656
+ float depth = depths[newindex];
1648117657
1648217658 /*
1648317659 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -16627,23 +17803,15 @@
1662717803 int AAbuffersize = 0;
1662817804
1662917805 //double[] selectedpoint = new double[3];
16630
- static Superellipsoid selectedpoint = new Superellipsoid();
17806
+ static Superellipsoid selectedpoint;
1663117807 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();
17808
+ static Sphere debugpointG;
17809
+ static Sphere debugpointP;
17810
+ static Sphere debugpointC;
17811
+ static Sphere debugpointR;
1663617812
1663717813 static Sphere debugpoints[] = new Sphere[8];
1663817814
16639
- static
16640
- {
16641
- for (int i=0; i<8; i++)
16642
- {
16643
- debugpoints[i] = new Sphere();
16644
- }
16645
- }
16646
-
1664717815 static void InitPoints(float radius)
1664817816 {
1664917817 for (int i=0; i<8; i++)
....@@ -16682,11 +17850,14 @@
1668217850 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1668317851 static IntBuffer bigAAbuffer;
1668417852 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
16685
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17853
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1668617854 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1668717855 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1668817856 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
16689
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17857
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17858
+
17859
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17860
+
1669017861 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1669117862 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1669217863 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();
....@@ -16695,10 +17866,11 @@
1669517866 static IntBuffer textbuffer = null; // IntBuffer.allocate(TEXT_WIDTH*8*8 * TEXT_HEIGHT);
1669617867 // Depth buffer format
1669717868 //private int depth_format;
16698
- static public void NextIndex(Object3D o, GL gl)
17869
+
17870
+ public void NextIndex()
1669917871 {
1670017872 indexcount+=16;
16701
- gl.glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
17873
+ GetGL().glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
1670217874 //objects[indexcount] = o;
1670317875 //System.out.println("indexcount = " + indexcount);
1670417876 }