Normand Briere
2019-08-23 60cec91731a350fe67e9b5ffe7a00d70e9026314
CameraPane.java
....@@ -18,7 +18,10 @@
1818 import javax.imageio.ImageIO;
1919 import javax.imageio.ImageWriteParam;
2020 import javax.imageio.ImageWriter;
21
+import javax.imageio.ImageReadParam;
22
+import javax.imageio.ImageReader;
2123 import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
24
+import javax.imageio.stream.ImageInputStream;
2225 import javax.imageio.stream.ImageOutputStream;
2326 import javax.imageio.ImageWriteParam;
2427
....@@ -30,6 +33,7 @@
3033 import java.nio.*;
3134
3235 import gleem.linalg.Mat4f;
36
+import javax.imageio.ImageTypeSpecifier;
3337
3438 class CameraPane extends GLCanvas implements iCameraPane, Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener
3539 {
....@@ -37,7 +41,6 @@
3741 static boolean[] selectedstack = new boolean[65536];
3842 static int materialdepth = 0;
3943
40
- static boolean DEBUG = false;
4144 static boolean FRUSTUM = false; // still bogus true; // frustum culling
4245
4346 // camera change fix
....@@ -45,6 +48,39 @@
4548 static boolean ABORTED = false;
4649
4750 static int STEP = 1;
51
+
52
+ private static BufferedImage CreateBim(byte[] bytes, int width, int height)
53
+ {
54
+ int[] pixels = new int[bytes.length/3];
55
+ for (int i=pixels.length; --i>=0;)
56
+ {
57
+ int i3 = i*3;
58
+ pixels[i] = 0xFF;
59
+ pixels[i] <<= 8;
60
+ pixels[i] |= bytes[i3+2] & 0xFF;
61
+ pixels[i] <<= 8;
62
+ pixels[i] |= bytes[i3+1] & 0xFF;
63
+ pixels[i] <<= 8;
64
+ pixels[i] |= bytes[i3] & 0xFF;
65
+ }
66
+ /*
67
+ int r=0,g=0,b=0,a=0;
68
+ for (int i=0; i<width; i++)
69
+ for (int j=0; j<height; j++)
70
+ {
71
+ int index = j*width+i;
72
+ int p = pixels[index];
73
+ a = ((p>>24) & 0xFF);
74
+ r = ((p>>16) & 0xFF);
75
+ g = ((p>>8) & 0xFF);
76
+ b = (p & 0xFF);
77
+ pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
78
+ }
79
+ /**/
80
+ BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
81
+ rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
82
+ return rendImage;
83
+ }
4884
4985 /*static*/ private boolean CULLFACE = false; // true;
5086 /*static*/ boolean NEAREST = false; // true;
....@@ -56,14 +92,12 @@
5692 static int CURRENTANTIALIAS = 0; // 1;
5793 /*static*/ boolean RENDERSHADOW = true;
5894 /*static*/ int RENDERPROGRAM = 2; // 0 == none, 1 == fast, 2 == normal
59
- static boolean ANIMATION = false;
60
- static String filename;
6195
6296 boolean DISPLAYTEXT = false;
6397 //boolean REDUCETEXTURE = true;
6498 boolean CACHETEXTURE = true;
6599 boolean CLEANCACHE = false; // true;
66
- boolean MIPMAP = false; // true;
100
+ boolean MIPMAP = false; // true; // never works...
67101 boolean COMPRESSTEXTURE = false;
68102 boolean KOMPACTTEXTURE = false; // true;
69103 boolean RESIZETEXTURE = false;
....@@ -76,7 +110,11 @@
76110 //private Mat4f spotlightTransform = new Mat4f();
77111 //private Mat4f spotlightInverseTransform = new Mat4f();
78112 static GLContext glcontext = null;
79
- /*static*/ com.sun.opengl.util.texture.Texture cubemap;
113
+ /*static*/ com.sun.opengl.util.texture.Texture cubemap; // Either custom or rgb
114
+ /*static*/ com.sun.opengl.util.texture.Texture cubemapcustom;
115
+ /*static*/ com.sun.opengl.util.texture.Texture cubemaprgb;
116
+ boolean transformMode;
117
+
80118 boolean reverseUP = false;
81119 static boolean frozen = false;
82120 boolean enablebackspace = false; // patch for back buffer refresh
....@@ -92,6 +130,8 @@
92130
93131 static int tickcount = 0; // slow pose issue
94132
133
+static boolean BUTTONLESSWHEEL = false;
134
+static boolean ZOOMBOXMODE = false;
95135 static boolean BOXMODE = false;
96136 static boolean IMAGEFLIP = false;
97137 static boolean SMOOTHFOCUS = false;
....@@ -106,7 +146,7 @@
106146 static boolean OEIL = true;
107147 static boolean OEILONCE = false; // do oeilon then oeiloff
108148 static boolean LOOKAT = true;
109
-static boolean RANDOM = true; // false;
149
+static boolean SWITCH = true; // false;
110150 static boolean HANDLES = false; // selection doesn't work!!
111151 static boolean PAINTMODE = false;
112152
....@@ -128,7 +168,7 @@
128168
129169
130170 // OPTIONS
131
- boolean Skinshader = true;
171
+ boolean Skinshader = false; // true;
132172 boolean cameraLight = false;
133173 boolean UVdebug = false;
134174 boolean Udebug = false;
....@@ -137,7 +177,7 @@
137177 static boolean doublesided = false; // true; // reversed normals are awful for conformance
138178 boolean anisotropy = true;
139179 boolean softshadow = true; // slower but better false;
140
- boolean opacityhalo = false;
180
+ boolean opacityhalo = false; // reverse the halo effect (e.g. glass)
141181
142182 boolean macromode = false;
143183
....@@ -148,6 +188,21 @@
148188 defaultcaps.setAccumGreenBits(16);
149189 defaultcaps.setAccumBlueBits(16);
150190 defaultcaps.setAccumAlphaBits(16);
191
+ }
192
+
193
+ private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
194
+
195
+ public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException
196
+ {
197
+ try
198
+ {
199
+ return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
200
+ } catch (IOException e)
201
+ {
202
+ System.out.println("NAME = " + name);
203
+ e.printStackTrace(); // throw new RuntimeException(e);
204
+ return null;
205
+ }
151206 }
152207
153208 void SetAsGLRenderer(boolean b)
....@@ -168,7 +223,8 @@
168223
169224 SetCamera(cam);
170225
171
- SetLight(new Camera(new cVector(10, 10, -20)));
226
+ // Warning: not used.
227
+ SetLight(new Camera(new cVector(15, 10, -20)));
172228
173229 object = o;
174230
....@@ -191,9 +247,43 @@
191247
192248 /// INTERFACE
193249
250
+ public javax.media.opengl.GL GetGL0()
251
+ {
252
+ return null;
253
+ }
254
+
255
+ public int GenList()
256
+ {
257
+ javax.media.opengl.GL gl = GetGL();
258
+ return gl.glGenLists(1);
259
+ }
260
+
261
+ public void NewList(int id)
262
+ {
263
+ javax.media.opengl.GL gl = GetGL();
264
+ gl.glNewList(id, gl.GL_COMPILE); //_AND_EXECUTE);
265
+ }
266
+
267
+ public void CallList(int id)
268
+ {
269
+ javax.media.opengl.GL gl = GetGL();
270
+ gl.glCallList(id);
271
+ }
272
+
273
+ public void EndList()
274
+ {
275
+ javax.media.opengl.GL gl = GetGL();
276
+ gl.glEndList();
277
+ }
278
+
194279 public boolean IsBoxMode()
195280 {
196281 return BOXMODE;
282
+ }
283
+
284
+ public boolean IsZoomBoxMode()
285
+ {
286
+ return ZOOMBOXMODE;
197287 }
198288
199289 public void ClearDepth()
....@@ -291,7 +381,7 @@
291381 cStatic.objectstack[materialdepth++] = obj;
292382 //System.out.println("material " + material);
293383 //Applet3D.tracein(this, selected);
294
- display.vector2buffer = obj.projectedVertices;
384
+ //display.vector2buffer = obj.projectedVertices;
295385 if (obj instanceof Camera)
296386 {
297387 display.options1[0] = material.shift;
....@@ -300,14 +390,28 @@
300390 display.options1[2] = material.shadowbias;
301391 display.options1[3] = material.aniso;
302392 display.options1[4] = material.anisoV;
393
+// System.out.println("display.options1[0] " + display.options1[0]);
394
+// System.out.println("display.options1[1] " + display.options1[1]);
395
+// System.out.println("display.options1[2] " + display.options1[2]);
396
+// System.out.println("display.options1[3] " + display.options1[3]);
397
+// System.out.println("display.options1[4] " + display.options1[4]);
303398 display.options2[0] = material.opacity;
304399 display.options2[1] = material.diffuse;
305400 display.options2[2] = material.factor;
401
+// System.out.println("display.options2[0] " + display.options2[0]);
402
+// System.out.println("display.options2[1] " + display.options2[1]);
403
+// System.out.println("display.options2[2] " + display.options2[2]);
306404
307405 cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
406
+// System.out.println("display.options3[0] " + display.options3[0]);
407
+// System.out.println("display.options3[1] " + display.options3[1]);
408
+// System.out.println("display.options3[2] " + display.options3[2]);
308409 display.options4[0] = material.cameralight/0.2f;
309410 display.options4[1] = material.subsurface;
310411 display.options4[2] = material.sheen;
412
+// System.out.println("display.options4[0] " + display.options4[0]);
413
+// System.out.println("display.options4[1] " + display.options4[1]);
414
+// System.out.println("display.options4[2] " + display.options4[2]);
311415
312416 // if (display.CURRENTANTIALIAS > 0)
313417 // display.options3[3] /= 4;
....@@ -323,7 +427,7 @@
323427 /**/
324428 } else
325429 {
326
- DrawMaterial(material, selected);
430
+ DrawMaterial(material, selected, obj.projectedVertices);
327431 }
328432 } else
329433 {
....@@ -347,8 +451,8 @@
347451 cStatic.objectstack[materialdepth++] = obj;
348452 //System.out.println("material " + material);
349453 //Applet3D.tracein("selected ", selected);
350
- display.vector2buffer = obj.projectedVertices;
351
- display.DrawMaterial(material, selected);
454
+ //display.vector2buffer = obj.projectedVertices;
455
+ display.DrawMaterial(material, selected, obj.projectedVertices);
352456 }
353457 }
354458
....@@ -365,8 +469,8 @@
365469 materialdepth -= 1;
366470 if (materialdepth > 0)
367471 {
368
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
369
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
472
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
473
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
370474 }
371475 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
372476 } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
....@@ -386,8 +490,8 @@
386490 materialdepth -= 1;
387491 if (materialdepth > 0)
388492 {
389
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
390
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
493
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
494
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
391495 }
392496 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
393497 //else
....@@ -428,15 +532,18 @@
428532 if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
429533 {
430534 //gl.glBegin(gl.GL_TRIANGLES);
431
- boolean hasnorm = pv.norm != null; // && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0);
535
+ boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0)
536
+ // TEST LIVE NORMALS && !obj.dontselect
537
+ ;
432538 if (!hasnorm)
433539 {
434
- // System.out.println("FUCK!!");
540
+ // System.out.println("Mesh normal");
435541 LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
436542 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
437543 LA.vecCross(obj.v0, obj.v1, obj.v2);
438544 LA.vecNormalize(obj.v2);
439
- gl.glNormal3f((float) obj.v2.x, (float) obj.v2.y, (float) obj.v2.z);
545
+
546
+ SetGLNormal(gl, (float) obj.v2.x, (float) obj.v2.y, (float) obj.v2.z);
440547 }
441548
442549 // P
....@@ -458,7 +565,7 @@
458565 y += ny * obj.NORMALPUSH;
459566 z += nz * obj.NORMALPUSH;
460567
461
- gl.glNormal3f(nx, ny, nz);
568
+ SetGLNormal(gl, nx, ny, nz);
462569 }
463570 gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
464571 SetColor(obj, pv);
....@@ -490,7 +597,7 @@
490597 y += ny * obj.NORMALPUSH;
491598 z += nz * obj.NORMALPUSH;
492599
493
- gl.glNormal3f(nx, ny, nz);
600
+ SetGLNormal(gl, nx, ny, nz);
494601 }
495602 //System.out.println("vertexq = " + qv.s + ", " + qv.t);
496603 // boolean locked = false;
....@@ -538,7 +645,7 @@
538645 y += ny * obj.NORMALPUSH;
539646 z += nz * obj.NORMALPUSH;
540647
541
- gl.glNormal3f(nx, ny, nz);
648
+ SetGLNormal(gl, nx, ny, nz);
542649 }
543650
544651 // if ((dot&4) == 0)
....@@ -774,7 +881,7 @@
774881 //// tris.postdraw(this);
775882 }
776883
777
- static Camera localcamera = new Camera();
884
+ static Camera localAOcamera = new Camera();
778885 static cVector from = new cVector();
779886 static cVector to = new cVector();
780887
....@@ -783,7 +890,7 @@
783890 CameraPane cp = this;
784891
785892 Camera keep = cp.RenderCamera();
786
- cp.renderCamera = localcamera;
893
+ cp.renderCamera = localAOcamera;
787894
788895 if (br.trimmed)
789896 {
....@@ -801,7 +908,7 @@
801908 br.positions[i3 + 2] + br.normals[i3 + 2]);
802909 LA.xformPos(from, transform, from);
803910 LA.xformPos(to, transform, to); // RIGID ONLY
804
- localcamera.setAim(from, to);
911
+ localAOcamera.setAim(from, to);
805912
806913 CameraPane.occlusionbuffer.display();
807914
....@@ -835,7 +942,7 @@
835942 to.set(v.x+v.norm.x, v.y+v.norm.y, v.z+v.norm.z);
836943 LA.xformPos(from, transform, from);
837944 LA.xformPos(to, transform, to); // RIGID ONLY
838
- localcamera.setAim(from, to);
945
+ localAOcamera.setAim(from, to);
839946
840947 CameraPane.occlusionbuffer.display();
841948
....@@ -1059,8 +1166,345 @@
10591166 gl.glMatrixMode(gl.GL_MODELVIEW);
10601167 }
10611168
1169
+ public void DrawBox(cVector min, cVector max)
1170
+ {
1171
+ javax.media.opengl.GL gl = GetGL();
1172
+ gl.glBegin(gl.GL_LINES);
1173
+
1174
+ gl.glVertex3d(min.x, min.y, min.z);
1175
+ gl.glVertex3d(min.x, min.y, max.z);
1176
+ gl.glVertex3d(min.x, min.y, min.z);
1177
+ gl.glVertex3d(min.x, max.y, min.z);
1178
+ gl.glVertex3d(min.x, min.y, min.z);
1179
+ gl.glVertex3d(max.x, min.y, min.z);
1180
+
1181
+ gl.glVertex3d(max.x, max.y, max.z);
1182
+ gl.glVertex3d(min.x, max.y, max.z);
1183
+ gl.glVertex3d(max.x, max.y, max.z);
1184
+ gl.glVertex3d(max.x, min.y, max.z);
1185
+ gl.glVertex3d(max.x, max.y, max.z);
1186
+ gl.glVertex3d(max.x, max.y, min.z);
1187
+
1188
+ gl.glEnd();
1189
+ }
1190
+
1191
+ public void DrawGeometry(BoundaryRep bRep, boolean flipV, boolean selectmode)
1192
+ {
1193
+ int[] strips = bRep.getRawIndices();
1194
+
1195
+ javax.media.opengl.GL gl = GetGL();
1196
+
1197
+ // TRIANGLE STRIP ARRAY
1198
+ if (bRep.trimmed)
1199
+ {
1200
+ float[] v = bRep.getRawVertices();
1201
+ float[] n = bRep.getRawNormals();
1202
+ float[] c = bRep.getRawColors();
1203
+ float[] uv = bRep.getRawUVMap();
1204
+
1205
+ int count2 = 0;
1206
+ int count3 = 0;
1207
+
1208
+ if (n.length > 0)
1209
+ {
1210
+ for (int i = 0; i < strips.length; i++)
1211
+ {
1212
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1213
+
1214
+ /*
1215
+ boolean locked = false;
1216
+ float eps = 0.1f;
1217
+ boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
1218
+
1219
+ int dot = 0;
1220
+
1221
+ if ((dot&1) == 0)
1222
+ dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
1223
+
1224
+ if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
1225
+ gl.glTexCoord2f((float) qv.s, (float) qv.t);
1226
+ else
1227
+ {
1228
+ locked = true;
1229
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1230
+ }
1231
+ //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
1232
+ gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
1233
+ if (hasnorm)
1234
+ {
1235
+ //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
1236
+ gl.glNormal3f((float) rv.norm.x, (float) rv.norm.y, (float) rv.norm.z);
1237
+ }
1238
+
1239
+ if ((dot&4) == 0)
1240
+ dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
1241
+
1242
+ if (wrap || !locked && (dot&8) != 0)
1243
+ gl.glTexCoord2f((float) rv.s, (float) rv.t);
1244
+ else
1245
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1246
+
1247
+ f.dot = dot;
1248
+ */
1249
+
1250
+ if (!selectmode)
1251
+ {
1252
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1253
+ {
1254
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
1255
+ } else
1256
+ {
1257
+ SetGLNormal(gl, 0, 0, 1);
1258
+ }
1259
+
1260
+ if (c != null)
1261
+ //System.out.println("glcolor = " + c[count3] + ", " + c[count3+1] + ", " + c[count3+2]);
1262
+ {
1263
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1264
+ }
1265
+ }
1266
+
1267
+ if (flipV)
1268
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1269
+ else
1270
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1271
+
1272
+ //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1273
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1274
+
1275
+ count2 += 2;
1276
+ count3 += 3;
1277
+ if (!selectmode)
1278
+ {
1279
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1280
+ {
1281
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
1282
+ } else
1283
+ {
1284
+ SetGLNormal(gl, 0, 0, 1);
1285
+ }
1286
+ if (c != null)
1287
+ {
1288
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1289
+ }
1290
+ }
1291
+
1292
+ if (flipV)
1293
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1294
+ else
1295
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1296
+
1297
+ //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1298
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1299
+
1300
+ count2 += 2;
1301
+ count3 += 3;
1302
+ for (int j = 0; j < strips[i] - 2; j++)
1303
+ {
1304
+ //gl.glTexCoord2d(...);
1305
+ if (!selectmode)
1306
+ {
1307
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1308
+ {
1309
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
1310
+ } else
1311
+ {
1312
+ SetGLNormal(gl, 0, 0, 1);
1313
+ }
1314
+ if (c != null)
1315
+ {
1316
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1317
+ }
1318
+ }
1319
+
1320
+ if (flipV)
1321
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1322
+ else
1323
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1324
+
1325
+ //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
1326
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1327
+
1328
+ count2 += 2;
1329
+ count3 += 3;
1330
+ }
1331
+
1332
+ gl.glEnd();
1333
+ }
1334
+ }
1335
+
1336
+ assert count3 == v.length;
1337
+ }
1338
+ else // !trimmed
1339
+ {
1340
+ int count = 0;
1341
+ for (int i = 0; i < strips.length; i++)
1342
+ {
1343
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1344
+
1345
+ Vertex p = bRep.GetVertex(bRep.indices[count++]);
1346
+ Vertex q = bRep.GetVertex(bRep.indices[count++]);
1347
+
1348
+ drawVertex(gl, p, flipV, selectmode);
1349
+ drawVertex(gl, q, flipV, selectmode);
1350
+
1351
+ for (int j = 0; j < strips[i] - 2; j++)
1352
+ {
1353
+ Vertex r = bRep.GetVertex(bRep.indices[count++]);
1354
+
1355
+ // if (j%2 == 0)
1356
+ // drawFace(p, q, r, display, null);
1357
+ // else
1358
+ // drawFace(p, r, q, display, null);
1359
+
1360
+ // p = q;
1361
+ // q = r;
1362
+ drawVertex(gl, r, flipV, selectmode);
1363
+ }
1364
+
1365
+ gl.glEnd();
1366
+ }
1367
+ }
1368
+ }
1369
+
1370
+ static cSpring.Point3D temp = new cSpring.Point3D();
1371
+ static cSpring.Point3D temp2 = new cSpring.Point3D();
1372
+ static cSpring.Point3D temp3 = new cSpring.Point3D();
1373
+
1374
+ public void DrawDynamicMesh(cMesh mesh)
1375
+ {
1376
+ GL gl = GetGL(); // getGL();
1377
+
1378
+ cSpring.PhysicsController3D Phys = mesh.Phys;
1379
+
1380
+ gl.glDisable(gl.GL_LIGHTING);
1381
+
1382
+ gl.glLineWidth(1);
1383
+ gl.glColor3f(1,1,1);
1384
+ gl.glBegin(gl.GL_LINES);
1385
+ double scale = 0;
1386
+ int count = 0;
1387
+ for (int s=0; s<Phys.allSprings.size(); s++)
1388
+ {
1389
+ cSpring.Spring spring = Phys.allSprings.get(s);
1390
+ if(s == 0)
1391
+ {
1392
+ //System.out.println(" spring : " + spring.a.position + "; " + spring.b.position);
1393
+ }
1394
+ if (mesh.showsprings)
1395
+ {
1396
+ temp.set(spring.a.position);
1397
+ temp.add(spring.b.position);
1398
+ temp.mul(0.5);
1399
+ temp2.set(spring.a.position);
1400
+ temp2.sub(spring.b.position);
1401
+ temp2.mul(spring.restLength/2);
1402
+ temp.sub(temp2);
1403
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1404
+ temp.add(temp2);
1405
+ temp.add(temp2);
1406
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1407
+ }
1408
+
1409
+ if (spring.isHandle)
1410
+ continue;
1411
+
1412
+ //if (scale < spring.restLength)
1413
+ scale += spring.restLength;
1414
+ count++;
1415
+ }
1416
+ gl.glEnd();
1417
+
1418
+ if (count == 0)
1419
+ scale = 0.01;
1420
+ else
1421
+ scale /= count * 3;
1422
+
1423
+ //scale = 0.25;
1424
+
1425
+ if (mesh.ShowInfo())
1426
+ {
1427
+ gl.glLineWidth(4);
1428
+ for (int s=0; s<Phys.allNodes.size(); s++)
1429
+ {
1430
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1431
+ if (node.mass == 0)
1432
+ continue;
1433
+
1434
+ int i = node.springs==null?-1:node.springs.size();
1435
+ gl.glColor3f((i>>2)&1,(i>>1)&1,i&1);
1436
+ //temp.set(node.springForce.x, node.springForce.y, node.springForce.z);
1437
+ //temp.normalize();
1438
+ //gl.glColor3d((temp.x+1)/2, (temp.y+1)/2, (temp.z+1)/2);
1439
+ gl.glBegin(gl.GL_LINES);
1440
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1441
+ //gl.glVertex3d(node.position.x + node.normal.x*scale, node.position.y + node.normal.y*scale, node.position.z + node.normal.z*scale);
1442
+ gl.glVertex3d(node.position.x + mesh.bRep.GetVertex(s).norm.x*scale,
1443
+ node.position.y + mesh.bRep.GetVertex(s).norm.y*scale,
1444
+ node.position.z + mesh.bRep.GetVertex(s).norm.z*scale);
1445
+ gl.glEnd();
1446
+ }
1447
+
1448
+ gl.glLineWidth(8);
1449
+ for (int s=0; s<Phys.allNodes.size(); s++)
1450
+ {
1451
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1452
+
1453
+ if (node.springs != null)
1454
+ {
1455
+ for (int i=0; i<node.springs.size(); i+=1)
1456
+ {
1457
+ cSpring.DynamicNode f = node.springs.get(i).GetOther(node);
1458
+
1459
+ int c = i+1;
1460
+ // c = node.springs.get(i).nbcopies;
1461
+
1462
+ gl.glColor3f((c>>2)&1,(c>>1)&1,c&1);
1463
+ gl.glBegin(gl.GL_LINES);
1464
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1465
+ 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);
1466
+ gl.glEnd();
1467
+ }
1468
+ }
1469
+ }
1470
+
1471
+ gl.glLineWidth(1);
1472
+ }
1473
+
1474
+ gl.glEnable(gl.GL_LIGHTING);
1475
+ }
1476
+
10621477 /// INTERFACE
10631478
1479
+ public void StartTriangles()
1480
+ {
1481
+ javax.media.opengl.GL gl = GetGL();
1482
+ gl.glBegin(gl.GL_TRIANGLES);
1483
+ }
1484
+
1485
+ public void EndTriangles()
1486
+ {
1487
+ GetGL().glEnd();
1488
+ }
1489
+
1490
+ void drawVertex(javax.media.opengl.GL gl, Vertex pv, boolean flipV, boolean selectmode)
1491
+ {
1492
+ if (!selectmode)
1493
+ {
1494
+ SetGLNormal(gl, (float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
1495
+ gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
1496
+
1497
+ if (flipV)
1498
+ gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
1499
+ else
1500
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1501
+ }
1502
+
1503
+ gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
1504
+ }
1505
+
1506
+ float[] colorV = new float[4];
1507
+
10641508 void SetColor(Object3D obj, Vertex p0)
10651509 {
10661510 CameraPane display = this;
....@@ -1128,8 +1572,6 @@
11281572 {
11291573 return;
11301574 }
1131
-
1132
- float[] colorV = new float[3];
11331575
11341576 if (false) // marked)
11351577 {
....@@ -1238,7 +1680,7 @@
12381680 // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
12391681 }
12401682
1241
- void DrawMaterial(cMaterial material, boolean selected)
1683
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
12421684 {
12431685 CameraPane display = this;
12441686 //new Exception().printStackTrace();
....@@ -1254,18 +1696,18 @@
12541696 //col.getColorComponents(ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB), CameraPane.modelParams0);
12551697 if (!material.multiply)
12561698 {
1257
- display.color = color;
1699
+ display.color = material.color;
12581700 display.saturation = material.modulation;
12591701 }
12601702 else
12611703 {
1262
- display.color *= color*2;
1704
+ display.color *= material.color*2;
12631705 display.saturation *= material.modulation*2;
12641706 }
12651707
12661708 cColor.HSBtoRGB(display.color, display.saturation, 1, display.modelParams0);
12671709
1268
- float[] colorV = GrafreeD.colorV;
1710
+ float[] colorV = Grafreed.colorV;
12691711
12701712 /**/
12711713 if (display.DrawMode() == display.DEFAULT) // && display.RENDERPROGRAM == 0)
....@@ -1273,7 +1715,7 @@
12731715 colorV[0] = display.modelParams0[0] * material.diffuse;
12741716 colorV[1] = display.modelParams0[1] * material.diffuse;
12751717 colorV[2] = display.modelParams0[2] * material.diffuse;
1276
- colorV[3] = material.opacity;
1718
+ colorV[3] = 1; // material.opacity;
12771719
12781720 gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
12791721 //System.out.println("Opacity = " + opacity);
....@@ -1378,12 +1820,12 @@
13781820
13791821 display.modelParams7[0] = 0;
13801822 display.modelParams7[1] = 1000;
1381
- display.modelParams7[2] = 0;
1823
+ display.modelParams7[2] = material.parallax;
13821824 display.modelParams7[3] = 0;
13831825
1384
- display.modelParams6[0] = 100; // criss de bug de bump
1826
+ //display.modelParams6[0] = 100; // criss de bug de bump
13851827
1386
- Object3D.cVector2[] extparams = display.vector2buffer;
1828
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
13871829 if (extparams != null && extparams.length > 0 && extparams[0] != null)
13881830 {
13891831 display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
....@@ -1525,7 +1967,7 @@
15251967 void PushMatrix(double[][] matrix)
15261968 {
15271969 // GrafreeD.tracein(matrix);
1528
- PushMatrix(matrix,1);
1970
+ PushMatrix(matrix, 1);
15291971 }
15301972
15311973 void PushMatrix()
....@@ -1611,9 +2053,9 @@
16112053 switch(viewcode)
16122054 {
16132055 case 0: return "main";
1614
- case 1: return "one";
1615
- case 2: return "two";
1616
- case 3: return "three";
2056
+ case 1: return "Red";
2057
+ case 2: return "Green";
2058
+ case 3: return "Blue";
16172059 case 4: return "light";
16182060 }
16192061
....@@ -1679,7 +2121,7 @@
16792121 //System.err.println("Oeil on");
16802122 OEIL = true;
16812123 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
1682
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2124
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
16832125 //pingthread.StepToTarget(true);
16842126 }
16852127
....@@ -1777,7 +2219,7 @@
17772219 System.err.println("LIVE = " + Globals.isLIVE());
17782220
17792221 if (!Globals.isLIVE()) // save sound
1780
- GrafreeD.savesound = true; // wav.save();
2222
+ Grafreed.savesound = true; // wav.save();
17812223 // else
17822224 repaint(); // start loop // may 2013
17832225 }
....@@ -1810,6 +2252,11 @@
18102252 public void ToggleBoxMode()
18112253 {
18122254 BOXMODE ^= true;
2255
+ }
2256
+
2257
+ public void ToggleZoomBoxMode()
2258
+ {
2259
+ ZOOMBOXMODE ^= true;
18132260 }
18142261
18152262 public void ToggleSmoothFocus()
....@@ -1889,7 +2336,7 @@
18892336
18902337 void ToggleDebug()
18912338 {
1892
- DEBUG ^= true;
2339
+ Globals.DEBUG ^= true;
18932340 }
18942341
18952342 void ToggleLookAt()
....@@ -1897,9 +2344,9 @@
18972344 LOOKAT ^= true;
18982345 }
18992346
1900
- void ToggleRandom()
2347
+ void ToggleSwitch()
19012348 {
1902
- RANDOM ^= true;
2349
+ SWITCH ^= true;
19032350 }
19042351
19052352 void ToggleHandles()
....@@ -1907,10 +2354,17 @@
19072354 HANDLES ^= true;
19082355 }
19092356
2357
+ Object3D paintFolder;
2358
+
19102359 void TogglePaint()
19112360 {
19122361 PAINTMODE ^= true;
19132362 paintcount = 0;
2363
+
2364
+ if (PAINTMODE)
2365
+ {
2366
+ paintFolder = GetFolder();
2367
+ }
19142368 }
19152369
19162370 void SwapCamera(int a, int b)
....@@ -2006,7 +2460,34 @@
20062460 {
20072461 return currentGL;
20082462 }
2009
-
2463
+
2464
+ static private BufferedImage CreateBim(TextureData texturedata)
2465
+ {
2466
+ Grafreed.Assert(texturedata != null);
2467
+
2468
+ int width = texturedata.getWidth();
2469
+ int height = texturedata.getHeight();
2470
+
2471
+ Buffer buffer = texturedata.getBuffer();
2472
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2473
+
2474
+ byte[] bytes = bytebuf.array();
2475
+
2476
+ return CreateBim(bytes, width, height);
2477
+ }
2478
+
2479
+ private void SetGLNormal(javax.media.opengl.GL gl, float nx, float ny, float nz)
2480
+ {
2481
+ gl.glNormal3f(nx, ny, nz);
2482
+
2483
+ if (ny > 0.9 || ny < -0.9)
2484
+ // Ground or ceiling
2485
+ gl.glVertexAttrib3f(4, 1, 0, 0);
2486
+ else
2487
+ // Walls
2488
+ gl.glVertexAttrib3f(4, 0, 1, 0);
2489
+ }
2490
+
20102491 /**/
20112492 class CacheTexture
20122493 {
....@@ -2015,28 +2496,31 @@
20152496
20162497 int resolution;
20172498
2018
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2499
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
20192500 {
2020
- texture = tex;
2501
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2502
+ texturedata = texdata;
20212503 resolution = res;
20222504 }
20232505 }
20242506 /**/
20252507
20262508 // 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>();
2509
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2510
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2511
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2512
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2513
+
20302514 int pigmentdepth = 0;
20312515 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
20322516 int bumpdepth = 0;
20332517 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
20342518 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
20352519 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2036
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2520
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
20372521 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
20382522
2039
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2523
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
20402524 {
20412525 TextureData texturedata = null;
20422526
....@@ -2046,7 +2530,7 @@
20462530 com.sun.opengl.util.texture.TextureIO.newTextureData(
20472531 getClass().getClassLoader().getResourceAsStream(name),
20482532 true,
2049
- com.sun.opengl.util.texture.TextureIO.PNG);
2533
+ GetFormat(name)); // com.sun.opengl.util.texture.TextureIO.PNG);
20502534 } catch (java.io.IOException e)
20512535 {
20522536 throw new javax.media.opengl.GLException(e);
....@@ -2055,13 +2539,34 @@
20552539 if (bump)
20562540 texturedata = ConvertBump(texturedata, false);
20572541
2058
- com.sun.opengl.util.texture.Texture texture =
2059
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2542
+// com.sun.opengl.util.texture.Texture texture =
2543
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
20602544
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);
2545
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2546
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
20632547
2064
- return texture;
2548
+ return texturedata;
2549
+ }
2550
+
2551
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2552
+ {
2553
+ TextureData texturedata = null;
2554
+
2555
+ try
2556
+ {
2557
+ texturedata =
2558
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2559
+ bim,
2560
+ true);
2561
+ } catch (Exception e)
2562
+ {
2563
+ throw new javax.media.opengl.GLException(e);
2564
+ }
2565
+
2566
+ if (bump)
2567
+ texturedata = ConvertBump(texturedata, false);
2568
+
2569
+ return texturedata;
20652570 }
20662571
20672572 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3134,6 +3639,8 @@
31343639
31353640 System.out.println("LOADING TEXTURE : " + name);
31363641
3642
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3643
+
31373644 //
31383645 if (false) // compressbit > 0)
31393646 {
....@@ -3838,6 +4345,7 @@
38384345
38394346 com.sun.opengl.util.texture.Texture CompressTexture2(String name)
38404347 {
4348
+ new Exception().printStackTrace();
38414349 System.exit(0);
38424350 com.sun.opengl.util.texture.Texture texture = null;
38434351
....@@ -7531,7 +8039,7 @@
75318039 String pigment = Object3D.GetPigment(tex);
75328040 String bump = Object3D.GetBump(tex);
75338041
7534
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8042
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
75358043 {
75368044 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
75378045 // System.out.println("; bump = " + bump);
....@@ -7546,11 +8054,69 @@
75468054 pigment = null;
75478055 }
75488056
7549
- ReleaseTexture(bump, true);
7550
- ReleaseTexture(pigment, false);
8057
+ ReleaseTexture(tex, true);
8058
+ ReleaseTexture(tex, false);
75518059 }
75528060
7553
- void ReleaseTexture(String tex, boolean bump)
8061
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
8062
+ {
8063
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8064
+ {
8065
+ return;
8066
+ }
8067
+
8068
+ if (tex == null)
8069
+ {
8070
+ ReleaseTexture(null, false);
8071
+ return;
8072
+ }
8073
+
8074
+ String pigment = Object3D.GetPigment(tex);
8075
+
8076
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8077
+ {
8078
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8079
+ // System.out.println("; bump = " + bump);
8080
+ }
8081
+
8082
+ if (pigment.equals(""))
8083
+ {
8084
+ pigment = null;
8085
+ }
8086
+
8087
+ ReleaseTexture(tex, false);
8088
+ }
8089
+
8090
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
8091
+ {
8092
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8093
+ {
8094
+ return;
8095
+ }
8096
+
8097
+ if (tex == null)
8098
+ {
8099
+ ReleaseTexture(null, true);
8100
+ return;
8101
+ }
8102
+
8103
+ String bump = Object3D.GetBump(tex);
8104
+
8105
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8106
+ {
8107
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8108
+ // System.out.println("; bump = " + bump);
8109
+ }
8110
+
8111
+ if (bump.equals(""))
8112
+ {
8113
+ bump = null;
8114
+ }
8115
+
8116
+ ReleaseTexture(tex, true);
8117
+ }
8118
+
8119
+ void ReleaseTexture(cTexture tex, boolean bump)
75548120 {
75558121 if (// DrawMode() != 0 || /*tex == null ||*/
75568122 ambientOcclusion ) // || !textureon)
....@@ -7561,7 +8127,7 @@
75618127 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
75628128
75638129 if (tex != null)
7564
- texture = textures.get(tex);
8130
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
75658131
75668132 // //assert( texture != null );
75678133 // if (texture == null)
....@@ -7653,7 +8219,55 @@
76538219 }
76548220 }
76558221
7656
- /*boolean*/ public void BindTextures(cTexture tex, int resolution) // INTERFACE
8222
+ /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
8223
+ {
8224
+// if (// DrawMode() != 0 || /*tex == null ||*/
8225
+// ambientOcclusion ) // || !textureon)
8226
+// {
8227
+// return; // false;
8228
+// }
8229
+//
8230
+// if (tex == null)
8231
+// {
8232
+// BindTexture(null,false,resolution);
8233
+// BindTexture(null,true,resolution);
8234
+// return;
8235
+// }
8236
+//
8237
+// String pigment = Object3D.GetPigment(tex);
8238
+// String bump = Object3D.GetBump(tex);
8239
+//
8240
+// usedtextures.add(pigment);
8241
+// usedtextures.add(bump);
8242
+//
8243
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8244
+// {
8245
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8246
+// // System.out.println("; bump = " + bump);
8247
+// }
8248
+//
8249
+// if (bump.equals(""))
8250
+// {
8251
+// bump = null;
8252
+// }
8253
+// if (pigment.equals(""))
8254
+// {
8255
+// pigment = null;
8256
+// }
8257
+//
8258
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8259
+// BindTexture(pigment, false, resolution);
8260
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8261
+// BindTexture(bump, true, resolution);
8262
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8263
+//
8264
+// return; // true;
8265
+
8266
+ BindPigmentTexture(tex, resolution);
8267
+ BindBumpTexture(tex, resolution);
8268
+ }
8269
+
8270
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
76578271 {
76588272 if (// DrawMode() != 0 || /*tex == null ||*/
76598273 ambientOcclusion ) // || !textureon)
....@@ -7664,17 +8278,47 @@
76648278 if (tex == null)
76658279 {
76668280 BindTexture(null,false,resolution);
7667
- BindTexture(null,true,resolution);
76688281 return;
76698282 }
76708283
76718284 String pigment = Object3D.GetPigment(tex);
8285
+
8286
+ usedtextures.add(tex);
8287
+
8288
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8289
+ {
8290
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8291
+ // System.out.println("; bump = " + bump);
8292
+ }
8293
+
8294
+ if (pigment.equals(""))
8295
+ {
8296
+ pigment = null;
8297
+ }
8298
+
8299
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8300
+ BindTexture(tex, false, resolution);
8301
+ }
8302
+
8303
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8304
+ {
8305
+ if (// DrawMode() != 0 || /*tex == null ||*/
8306
+ ambientOcclusion ) // || !textureon)
8307
+ {
8308
+ return; // false;
8309
+ }
8310
+
8311
+ if (tex == null)
8312
+ {
8313
+ BindTexture(null,true,resolution);
8314
+ return;
8315
+ }
8316
+
76728317 String bump = Object3D.GetBump(tex);
76738318
7674
- usedtextures.put(pigment, pigment);
7675
- usedtextures.put(bump, bump);
8319
+ usedtextures.add(tex);
76768320
7677
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8321
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
76788322 {
76798323 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
76808324 // System.out.println("; bump = " + bump);
....@@ -7684,43 +8328,94 @@
76848328 {
76858329 bump = null;
76868330 }
7687
- if (pigment.equals(""))
7688
- {
7689
- pigment = null;
7690
- }
76918331
7692
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
7693
- BindTexture(pigment, false, resolution);
76948332 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
7695
- BindTexture(bump, true, resolution);
8333
+ BindTexture(tex, true, resolution);
76968334 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
7697
-
7698
- return; // true;
76998335 }
77008336
7701
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution)
8337
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8338
+
8339
+ private boolean FileExists(String tex)
77028340 {
7703
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8341
+ if (missingTextures.contains(tex))
8342
+ {
8343
+ return false;
8344
+ }
8345
+
8346
+ boolean fileExists = new File(tex).exists();
8347
+
8348
+ if (!fileExists)
8349
+ {
8350
+ // If file exists, the "new File()" is not executed sgain
8351
+ missingTextures.add(tex);
8352
+ }
8353
+
8354
+ return fileExists;
8355
+ }
8356
+
8357
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
8358
+ {
8359
+ CacheTexture texturecache = null;
77048360
77058361 if (tex != null)
77068362 {
7707
- String texname = tex;
8363
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8364
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
77088365
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;
8366
+ if (texname.equals("") && texdata == null)
8367
+ {
8368
+ return null;
8369
+ }
8370
+
8371
+ String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
8372
+
8373
+// String[] split = tex.split("Textures");
8374
+// if (split.length > 1)
8375
+// texname = "/Users/nbriere/Textures" + split[split.length-1];
8376
+// else
8377
+// if (!texname.startsWith("/"))
8378
+// texname = "/Users/nbriere/Textures/" + texname;
8379
+ if (!FileExists(texname) && !texname.startsWith("@"))
8380
+ {
8381
+ texname = fallbackTextureName;
8382
+ }
77158383
77168384 if (CACHETEXTURE)
7717
- texture = textures.get(texname); // TEXTURE CACHE
7718
-
7719
- TextureData texturedata = null;
7720
-
7721
- if (texture == null || texture.resolution < resolution)
77228385 {
7723
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8386
+ if (texdata == null)
8387
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8388
+ else
8389
+ texturecache = bimtextures.get(texdata);
8390
+ }
8391
+
8392
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8393
+ {
8394
+ TextureData texturedata = null;
8395
+
8396
+ if (texdata != null && textureon)
8397
+ {
8398
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8399
+
8400
+ try
8401
+ {
8402
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8403
+ }
8404
+ catch (Exception e)
8405
+ {
8406
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8407
+ }
8408
+
8409
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8410
+ bimtextures.put(texdata, texturecache);
8411
+
8412
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8413
+
8414
+ //Object bim2 = CreateBim(texturecache.texturedata);
8415
+ //bim2 = bim;
8416
+ }
8417
+ else
8418
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
77248419 {
77258420 assert(!bump);
77268421 // if (bump)
....@@ -7731,19 +8426,23 @@
77318426 // }
77328427 // else
77338428 // {
7734
- texture = textures.get(tex);
7735
- if (texture == null)
8429
+ // texturecache = textures.get(texname); // suspicious
8430
+ if (texturecache == null)
77368431 {
7737
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8432
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
77388433 }
8434
+ else
8435
+ new Exception().printStackTrace();
77398436 // }
77408437 } else
7741
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8438
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
77428439 {
77438440 assert(bump);
7744
- texture = textures.get(tex);
7745
- if (texture == null)
7746
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8441
+ // texturecache = textures.get(texname); // suspicious
8442
+ if (texturecache == null)
8443
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8444
+ else
8445
+ new Exception().printStackTrace();
77478446 } else
77488447 {
77498448 //if (tex.equals("IMMORTAL"))
....@@ -7751,11 +8450,22 @@
77518450 // texture = GetResourceTexture("default.png");
77528451 //} else
77538452 //{
7754
- if (tex.equals("WHITE_NOISE"))
8453
+ if (texname.endsWith("WHITE_NOISE"))
77558454 {
7756
- texture = textures.get(tex);
7757
- if (texture == null)
7758
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8455
+ // texturecache = textures.get(texname); // suspicious
8456
+ if (texturecache == null)
8457
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8458
+ else
8459
+ new Exception().printStackTrace();
8460
+ } else
8461
+ {
8462
+ if (texname.startsWith("@"))
8463
+ {
8464
+ // texturecache = textures.get(texname); // suspicious
8465
+ if (texturecache == null)
8466
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8467
+ else
8468
+ new Exception().printStackTrace();
77598469 } else
77608470 {
77618471 if (textureon)
....@@ -7780,7 +8490,7 @@
77808490 }
77818491
77828492 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
7783
- if (!new File(cachename).exists())
8493
+ if (!FileExists(cachename))
77848494 cachename = texname;
77858495 else
77868496 processbump = false; // don't process bump map again
....@@ -7802,7 +8512,7 @@
78028512 }
78038513
78048514 cachename = texname.substring(0, texname.length()-4)+ext+".png";
7805
- if (!new File(cachename).exists())
8515
+ if (!FileExists(cachename))
78068516 cachename = texname;
78078517 else
78088518 processbump = false; // don't process bump map again
....@@ -7811,20 +8521,23 @@
78118521 texturedata = GetFileTexture(cachename, processbump, resolution);
78128522
78138523
7814
- if (texturedata != null)
7815
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8524
+ if (texturedata == null)
8525
+ throw new Exception();
8526
+
8527
+ texturecache = new CacheTexture(texturedata,resolution);
78168528 //texture = GetTexture(tex, bump);
78178529 }
8530
+ }
78188531 }
78198532 //}
78208533 }
78218534
7822
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8535
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
78238536 {
78248537 //return false;
78258538
78268539 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
7827
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8540
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
78288541 {
78298542 // String ext = "_highres";
78308543 // if (REDUCETEXTURE)
....@@ -7841,52 +8554,17 @@
78418554 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
78428555 if (!cachefile.exists())
78438556 {
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))
8557
+ //if (texturedata.getWidth() == texturedata.getHeight())
78538558 {
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);
8559
+ BufferedImage rendImage = CreateBim(texturedata);
8560
+
78848561 ImageWriter writer = null;
78858562 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
78868563 if (iter.hasNext()) {
78878564 writer = (ImageWriter)iter.next();
78888565 }
7889
- float compressionQuality = 0.9f;
8566
+
8567
+ float compressionQuality = 0.85f;
78908568 try
78918569 {
78928570 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -7903,18 +8581,20 @@
79038581 }
79048582 }
79058583 }
7906
-
8584
+
8585
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8586
+
79078587 //System.out.println("Texture = " + tex);
7908
- if (textures.containsKey(texname))
8588
+ if (textures.containsKey(tex))
79098589 {
7910
- CacheTexture thetex = textures.get(texname);
8590
+ CacheTexture thetex = textures.get(tex);
79118591 thetex.texture.disable();
79128592 thetex.texture.dispose();
7913
- textures.remove(texname);
8593
+ textures.remove(tex);
79148594 }
79158595
7916
- texture.texturedata = texturedata;
7917
- textures.put(texname, texture);
8596
+ //texture.texturedata = texturedata;
8597
+ textures.put(tex, texturecache);
79188598
79198599 // newtex = true;
79208600 }
....@@ -7930,10 +8610,44 @@
79308610 }
79318611 }
79328612
7933
- return texture;
8613
+ return texturecache;
79348614 }
79358615
7936
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution)
8616
+ static void EmbedTextures(cTexture tex)
8617
+ {
8618
+ if (tex.pigmentdata == null)
8619
+ {
8620
+ //String texname = Object3D.GetPigment(tex);
8621
+
8622
+ CacheTexture texturecache = texturepigment.get(tex);
8623
+
8624
+ if (texturecache != null)
8625
+ {
8626
+ tex.pw = texturecache.texturedata.getWidth();
8627
+ tex.ph = texturecache.texturedata.getHeight();
8628
+ tex.pigmentdata = //CompressJPEG(CreateBim
8629
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8630
+ ;
8631
+ //, tex.pw, tex.ph), 0.5f);
8632
+ }
8633
+ }
8634
+
8635
+ if (tex.bumpdata == null)
8636
+ {
8637
+ //String texname = Object3D.GetBump(tex);
8638
+
8639
+ CacheTexture texturecache = texturebump.get(tex);
8640
+
8641
+ if (texturecache != null)
8642
+ {
8643
+ tex.bw = texturecache.texturedata.getWidth();
8644
+ tex.bh = texturecache.texturedata.getHeight();
8645
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8646
+ }
8647
+ }
8648
+ }
8649
+
8650
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
79378651 {
79388652 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
79398653
....@@ -7951,21 +8665,21 @@
79518665 return texture!=null?texture.texture:null;
79528666 }
79538667
7954
- public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution)
8668
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
79558669 {
79568670 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
79578671
79588672 return texture!=null?texture.texturedata:null;
79598673 }
79608674
7961
- boolean BindTexture(String tex, boolean bump, int resolution)
8675
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
79628676 {
79638677 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
79648678 {
79658679 return false;
79668680 }
79678681
7968
- boolean newtex = false;
8682
+ //boolean newtex = false;
79698683
79708684 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
79718685
....@@ -7997,9 +8711,75 @@
79978711 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
79988712 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
79998713
8000
- return newtex;
8714
+ return true; // Warning: not used.
80018715 }
80028716
8717
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8718
+ {
8719
+ try
8720
+ {
8721
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8722
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8723
+ ImageWriter writer = writers.next();
8724
+
8725
+ ImageWriteParam param = writer.getDefaultWriteParam();
8726
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8727
+ param.setCompressionQuality(quality);
8728
+
8729
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8730
+ writer.setOutput(ios);
8731
+ writer.write(null, new IIOImage(image, null, null), param);
8732
+
8733
+ byte[] data = baos.toByteArray();
8734
+ writer.dispose();
8735
+ return data;
8736
+ }
8737
+ catch (Exception e)
8738
+ {
8739
+ e.printStackTrace();
8740
+ return null;
8741
+ }
8742
+ }
8743
+
8744
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8745
+ {
8746
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8747
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8748
+ ImageReader reader = writers.next();
8749
+
8750
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8751
+
8752
+ ImageReadParam param = reader.getDefaultReadParam();
8753
+ param.setDestination(bim);
8754
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8755
+
8756
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8757
+ reader.setInput(ios);
8758
+ BufferedImage bim2 = reader.read(0, param);
8759
+ reader.dispose();
8760
+
8761
+// WritableRaster raster = bim2.getRaster();
8762
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8763
+// byte[] bytes = data.getData();
8764
+//
8765
+// int[] pixels = new int[bytes.length/3];
8766
+// for (int i=pixels.length; --i>=0;)
8767
+// {
8768
+// int i3 = i*3;
8769
+// pixels[i] = 0xFF;
8770
+// pixels[i] <<= 8;
8771
+// pixels[i] |= bytes[i3+2] & 0xFF;
8772
+// pixels[i] <<= 8;
8773
+// pixels[i] |= bytes[i3+1] & 0xFF;
8774
+// pixels[i] <<= 8;
8775
+// pixels[i] |= bytes[i3] & 0xFF;
8776
+// }
8777
+//
8778
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8779
+
8780
+ return bim;
8781
+ }
8782
+
80038783 ShadowBuffer shadowPBuf;
80048784 AntialiasBuffer antialiasPBuf;
80058785 int MAXSTACK;
....@@ -8016,10 +8796,12 @@
80168796
80178797 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
80188798 MAXSTACK = temp[0];
8019
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8799
+ if (Globals.DEBUG)
8800
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
80208801 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
80218802 MAXSTACK = temp[0];
8022
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8803
+ if (Globals.DEBUG)
8804
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
80238805
80248806 // Use debug pipeline
80258807 //drawable.setGL(new DebugGL(gl)); //
....@@ -8027,7 +8809,8 @@
80278809 gl = drawable.getGL(); //
80288810
80298811 GL gl3 = getGL();
8030
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8812
+ if (Globals.DEBUG)
8813
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
80318814
80328815
80338816 //float pos[] = { 100, 100, 100, 0 };
....@@ -8192,7 +8975,7 @@
81928975
81938976 if (cubemap == null)
81948977 {
8195
- LoadEnvy(5);
8978
+ //LoadEnvy(1);
81968979 }
81978980
81988981 //cubemap.enable();
....@@ -8468,6 +9251,8 @@
84689251
84699252 void LoadEnvy(int which)
84709253 {
9254
+ assert(false);
9255
+
84719256 String name;
84729257 String ext;
84739258
....@@ -8479,37 +9264,58 @@
84799264 cubemap = null;
84809265 return;
84819266 case 1:
8482
- name = "cubemaps/box_";
8483
- ext = "png";
9267
+ name = "cubemaps/rgb/";
9268
+ ext = "jpg";
84849269 reverseUP = false;
84859270 break;
84869271 case 2:
8487
- name = "cubemaps/uffizi_";
8488
- ext = "png";
8489
- break; // reverseUP = true; break;
9272
+ name = "cubemaps/uffizi/";
9273
+ ext = "jpg";
9274
+ reverseUP = false;
9275
+ break;
84909276 case 3:
8491
- name = "cubemaps/CloudyHills_";
8492
- ext = "tga";
9277
+ name = "cubemaps/CloudyHills/";
9278
+ ext = "jpg";
84939279 reverseUP = false;
84949280 break;
84959281 case 4:
8496
- name = "cubemaps/cornell_";
9282
+ name = "cubemaps/cornell/";
84979283 ext = "png";
84989284 reverseUP = false;
84999285 break;
9286
+ case 5:
9287
+ name = "cubemaps/skycube/";
9288
+ ext = "jpg";
9289
+ reverseUP = false;
9290
+ break;
9291
+ case 6:
9292
+ name = "cubemaps/SaintLazarusChurch3/";
9293
+ ext = "jpg";
9294
+ reverseUP = false;
9295
+ break;
9296
+ case 7:
9297
+ name = "cubemaps/Sodermalmsallen/";
9298
+ ext = "jpg";
9299
+ reverseUP = false;
9300
+ break;
9301
+ case 8:
9302
+ name = "cubemaps/Sodermalmsallen2/";
9303
+ ext = "jpg";
9304
+ reverseUP = false;
9305
+ break;
9306
+ case 9:
9307
+ name = "cubemaps/UnionSquare/";
9308
+ ext = "jpg";
9309
+ reverseUP = false;
9310
+ break;
85009311 default:
8501
- name = "cubemaps/rgb_";
8502
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9312
+ name = "cubemaps/box/";
9313
+ ext = "png"; /*mipmap = true;*/
9314
+ reverseUP = false;
85039315 break;
85049316 }
8505
-
8506
- try
8507
- {
8508
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
8509
- } catch (IOException e)
8510
- {
8511
- throw new RuntimeException(e);
8512
- }
9317
+
9318
+ LoadSkybox(name, ext, mipmap);
85139319 }
85149320
85159321 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -8541,8 +9347,12 @@
85419347 static double[] model = new double[16];
85429348 double[] camera2light = new double[16];
85439349 double[] light2camera = new double[16];
8544
- int newenvy = -1;
8545
- boolean envyoff = true; // false;
9350
+
9351
+ //int newenvy = -1;
9352
+ //boolean envyoff = false;
9353
+
9354
+ String loadedskyboxname;
9355
+
85469356 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
85479357 //float[] light0 = { 0,0,0 };
85489358 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -8835,11 +9645,35 @@
88359645 jy8[3] = 0.5f;
88369646 }
88379647
8838
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9648
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
88399649 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
88409650 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
88419651 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
88429652
9653
+ void ResetOptions()
9654
+ {
9655
+ options1[0] = 100;
9656
+ options1[1] = 0.025f;
9657
+ options1[2] = 0.01f;
9658
+ options1[3] = 0;
9659
+ options1[4] = 0;
9660
+
9661
+ options2[0] = 0;
9662
+ options2[1] = 0.75f;
9663
+ options2[2] = 0;
9664
+ options2[3] = 0;
9665
+
9666
+ options3[0] = 1;
9667
+ options3[1] = 1;
9668
+ options3[2] = 1;
9669
+ options3[3] = 0;
9670
+
9671
+ options4[0] = 1;
9672
+ options4[1] = 0;
9673
+ options4[2] = 1;
9674
+ options4[3] = 0;
9675
+ }
9676
+
88439677 static int imagecount = 0; // movie generation
88449678
88459679 static int jitter = 0;
....@@ -8935,8 +9769,8 @@
89359769 assert (parentcam != renderCamera);
89369770
89379771 if (renderCamera != lightCamera)
8938
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8939
- LA.matConcat(matrix, parentcam.toParent, matrix);
9772
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9773
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
89409774
89419775 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
89429776
....@@ -8951,8 +9785,8 @@
89519785 LA.matCopy(renderCamera.fromScreen, matrix);
89529786
89539787 if (renderCamera != lightCamera)
8954
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8955
- LA.matConcat(parentcam.fromParent, matrix, matrix);
9788
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9789
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
89569790
89579791 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
89589792
....@@ -8998,10 +9832,12 @@
89989832 rati = 1 / rati;
89999833 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
90009834 }
9001
- assert (newenvy == -1);
9835
+
9836
+ //assert (newenvy == -1);
9837
+
90029838 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
90039839 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9004
- DrawSkyBox(gl);
9840
+ DrawSkyBox(gl, (float)rati);
90059841 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
90069842 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
90079843 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -9024,7 +9860,7 @@
90249860 //gl.glFlush();
90259861 gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE);
90269862
9027
- if (ANIMATION && ABORTED)
9863
+ if (Globals.ANIMATION && ABORTED)
90289864 {
90299865 System.err.println(" ABORTED FRAME");
90309866 break;
....@@ -9054,7 +9890,7 @@
90549890 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
90559891
90569892 // save image
9057
- if (ANIMATION && !ABORTED)
9893
+ if (Globals.ANIMATION && !ABORTED)
90589894 {
90599895 VPwidth = viewport[2];
90609896 VPheight = viewport[3];
....@@ -9165,11 +10001,11 @@
916510001
916610002 // imagecount++;
916710003
9168
- String fullname = filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
10004
+ String fullname = Globals.filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
916910005
917010006 if (!BOXMODE)
917110007 {
9172
- System.out.println("image: " + fullname + " (wav cursor=" + (GrafreeD.wav.cursor / 735 / 4) + ")");
10008
+ System.out.println("image: " + fullname + " (wav cursor=" + (Grafreed.wav.cursor / 735 / 4) + ")");
917310009 }
917410010
917510011 if (!BOXMODE)
....@@ -9207,7 +10043,7 @@
920710043 ABORTED = false;
920810044 }
920910045 else
9210
- GrafreeD.wav.cursor += 735 * ACSIZE;
10046
+ Grafreed.wav.cursor += 735 * ACSIZE;
921110047
921210048 if (false)
921310049 {
....@@ -9867,14 +10703,23 @@
986710703 static boolean init = false;
986810704
986910705 double[][] matrix = LA.newMatrix();
10706
+
10707
+ // This is to refresh the UI of the material panel.
10708
+ ObjEditor patchMaterial;
987010709
987110710 public void display(GLAutoDrawable drawable)
987210711 {
9873
- if (GrafreeD.savesound && GrafreeD.hassound)
10712
+ if (patchMaterial.patchMaterial)
987410713 {
9875
- GrafreeD.wav.save();
9876
- GrafreeD.savesound = false;
9877
- GrafreeD.hassound = false;
10714
+ patchMaterial.patchMaterial = false;
10715
+ patchMaterial.objectPanel.setSelectedIndex(1);
10716
+ }
10717
+
10718
+ if (Grafreed.savesound && Grafreed.hassound)
10719
+ {
10720
+ Grafreed.wav.save();
10721
+ Grafreed.savesound = false;
10722
+ Grafreed.hassound = false;
987810723 }
987910724 // if (DEBUG_SELECTION)
988010725 // {
....@@ -9950,6 +10795,7 @@
995010795 ANTIALIAS = 0;
995110796 //System.out.println("RESTART");
995210797 AAtimer.restart();
10798
+ Globals.TIMERRUNNING = true;
995310799 }
995410800 }
995510801 }
....@@ -10004,7 +10850,7 @@
1000410850 Object3D theobject = object;
1000510851 Object3D theparent = object.parent;
1000610852 object.parent = null;
10007
- object = (Object3D)GrafreeD.clone(object);
10853
+ object = (Object3D)Grafreed.clone(object);
1000810854 object.Stripify();
1000910855 if (theobject.selection == null || theobject.selection.Size() == 0)
1001010856 theobject.PreprocessOcclusion(this);
....@@ -10017,13 +10863,14 @@
1001710863 ambientOcclusion = false;
1001810864 }
1001910865
10020
- if (Globals.lighttouched && DrawMode() == DEFAULT && !lightMode) // && !FROZEN)
10866
+ if (//Globals.lighttouched &&
10867
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1002110868 {
1002210869 //if (RENDERSHADOW) // ?
1002310870 if (!IsFrozen())
1002410871 {
1002510872 // dec 2012
10026
- if (!ambientOcclusion && !(!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0))
10873
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
1002710874 {
1002810875 Globals.framecount++;
1002910876 shadowbuffer.display();
....@@ -10036,7 +10883,7 @@
1003610883
1003710884 if (wait)
1003810885 {
10039
- Sleep(500);
10886
+ Sleep(200); // blocks everything
1004010887
1004110888 wait = false;
1004210889 }
....@@ -10150,8 +10997,8 @@
1015010997
1015110998 // if (parentcam != renderCamera) // not a light
1015210999 if (cam != lightCamera)
10153
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10154
- LA.matConcat(matrix, parentcam.toParent, matrix);
11000
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11001
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1015511002
1015611003 for (int j = 0; j < 4; j++)
1015711004 {
....@@ -10165,8 +11012,8 @@
1016511012
1016611013 // if (parentcam != renderCamera) // not a light
1016711014 if (cam != lightCamera)
10168
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10169
- LA.matConcat(parentcam.fromParent, matrix, matrix);
11015
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11016
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1017011017
1017111018 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1017211019
....@@ -10252,13 +11099,43 @@
1025211099 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1025311100 }
1025411101
10255
- if (newenvy > -1)
11102
+// if (newenvy > -1)
11103
+// {
11104
+// LoadEnvy(newenvy);
11105
+// }
11106
+//
11107
+// newenvy = -1;
11108
+
11109
+ if (transformMode) // object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
1025611110 {
10257
- LoadEnvy(newenvy);
11111
+ if (cubemaprgb == null)
11112
+ {
11113
+ cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb2" + "/", "jpg", false);
11114
+ }
11115
+
11116
+ cubemap = cubemaprgb;
1025811117 }
10259
-
10260
- newenvy = -1;
10261
-
11118
+ else
11119
+ {
11120
+ if (object.skyboxname != null)
11121
+ {
11122
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11123
+ {
11124
+ if (cubemap != null && cubemap != cubemaprgb)
11125
+ cubemap.dispose();
11126
+ cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11127
+ loadedskyboxname = object.skyboxname;
11128
+ }
11129
+ }
11130
+ else
11131
+ {
11132
+ cubemapcustom = null;
11133
+ loadedskyboxname = null;
11134
+ }
11135
+
11136
+ cubemap = cubemapcustom;
11137
+ }
11138
+
1026211139 ratio = ((double) getWidth()) / getHeight();
1026311140 //System.out.println("ratio = " + ratio);
1026411141
....@@ -10274,7 +11151,7 @@
1027411151
1027511152 if (!IsFrozen() && !ambientOcclusion)
1027611153 {
10277
- DrawSkyBox(gl);
11154
+ DrawSkyBox(gl, (float)ratio);
1027811155 }
1027911156
1028011157 //if (selection_view == -1)
....@@ -10425,7 +11302,16 @@
1042511302 // Bump noise
1042611303 gl.glActiveTexture(GL.GL_TEXTURE6);
1042711304 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
10428
- BindTexture(NOISE_TEXTURE, false, 2);
11305
+
11306
+ try
11307
+ {
11308
+ BindTexture(NOISE_TEXTURE, false, 2);
11309
+ }
11310
+ catch (Exception e)
11311
+ {
11312
+ System.err.println("FAILED: " + NOISE_TEXTURE);
11313
+ }
11314
+
1042911315
1043011316 gl.glActiveTexture(GL.GL_TEXTURE0);
1043111317 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -10448,9 +11334,9 @@
1044811334
1044911335 gl.glMatrixMode(GL.GL_MODELVIEW);
1045011336
10451
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10452
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10453
-//gl.glEnable(gl.GL_MULTISAMPLE);
11337
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11338
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11339
+gl.glEnable(gl.GL_MULTISAMPLE);
1045411340 } else
1045511341 {
1045611342 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -10461,7 +11347,7 @@
1046111347 //System.out.println("BLENDING ON");
1046211348 gl.glEnable(GL.GL_BLEND);
1046311349 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
10464
-
11350
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1046511351 gl.glMatrixMode(gl.GL_PROJECTION);
1046611352 gl.glLoadIdentity();
1046711353
....@@ -10550,8 +11436,8 @@
1055011436 System.err.println("parentcam != renderCamera");
1055111437
1055211438 // if (cam != lightCamera)
10553
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10554
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11439
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11440
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1055511441 }
1055611442
1055711443 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -10572,8 +11458,8 @@
1057211458 if (true) // TODO
1057311459 {
1057411460 if (cam != lightCamera)
10575
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10576
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11461
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11462
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
1057711463 }
1057811464
1057911465 LA.xformPos(light0, cam.toScreen, light0);
....@@ -10710,7 +11596,7 @@
1071011596 }
1071111597 }
1071211598
10713
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11599
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1071411600 {
1071511601 //gl.glDepthFunc(GL.GL_LEQUAL);
1071611602 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -10718,24 +11604,21 @@
1071811604
1071911605 boolean texon = textureon;
1072011606
10721
- if (RENDERPROGRAM > 0)
10722
- {
10723
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
10724
- textureon = false;
10725
- }
11607
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11608
+ textureon = false;
11609
+
1072611610 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1072711611 //System.out.println("ALLO");
1072811612 gl.glColorMask(false, false, false, false);
1072911613 DrawObject(gl);
10730
- if (RENDERPROGRAM > 0)
10731
- {
10732
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
10733
- textureon = texon;
10734
- }
11614
+
11615
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11616
+ textureon = texon;
11617
+
1073511618 gl.glColorMask(true, true, true, true);
1073611619
1073711620 gl.glDepthFunc(GL.GL_EQUAL);
10738
- //gl.glDepthMask(false);
11621
+ gl.glDepthMask(false);
1073911622 }
1074011623
1074111624 if (false) // DrawMode() == SHADOW)
....@@ -10889,8 +11772,14 @@
1088911772 {
1089011773 renderpass++;
1089111774 // System.out.println("Draw object... ");
11775
+ STEP = 1;
1089211776 if (FAST) // in case there is no script
10893
- STEP = 16;
11777
+ STEP = 8;
11778
+
11779
+ if (CURRENTANTIALIAS == 0 || ACSIZE == 1)
11780
+ {
11781
+ STEP *= 4;
11782
+ }
1089411783
1089511784 //object.FullInvariants();
1089611785
....@@ -10904,23 +11793,44 @@
1090411793 e.printStackTrace();
1090511794 }
1090611795
10907
- if (GrafreeD.RENDERME > 0)
10908
- GrafreeD.RENDERME--; // mechante magouille
11796
+ if (Grafreed.RENDERME > 0)
11797
+ Grafreed.RENDERME--; // mechante magouille
1090911798
1091011799 Globals.ONESTEP = false;
1091111800 }
1091211801
1091311802 static boolean zoomonce = false;
1091411803
11804
+ static void CreateSelectedPoint()
11805
+ {
11806
+ if (selectedpoint == null)
11807
+ {
11808
+ debugpointG = new Sphere();
11809
+ debugpointP = new Sphere();
11810
+ debugpointC = new Sphere();
11811
+ debugpointR = new Sphere();
11812
+
11813
+ selectedpoint = new Superellipsoid();
11814
+
11815
+ for (int i=0; i<8; i++)
11816
+ {
11817
+ debugpoints[i] = new Sphere();
11818
+ }
11819
+ }
11820
+ }
11821
+
1091511822 void DrawObject(GL gl, boolean draw)
1091611823 {
11824
+ // To clear camera values
11825
+ ResetOptions();
11826
+
1091711827 //System.out.println("DRAW OBJECT " + mouseDown);
1091811828 // DrawMode() = SELECTION;
1091911829 //GL gl = getGL();
1092011830 if ((TRACK || SHADOWTRACK) || zoomonce)
1092111831 {
1092211832 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
10923
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11833
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1092411834 pingthread.StepToTarget(true); // true);
1092511835 // zoomonce = false;
1092611836 }
....@@ -10975,7 +11885,14 @@
1097511885
1097611886 usedtextures.clear();
1097711887
10978
- BindTextures(DEFAULT_TEXTURES, 2);
11888
+ try
11889
+ {
11890
+ BindTextures(DEFAULT_TEXTURES, 2);
11891
+ }
11892
+ catch (Exception e)
11893
+ {
11894
+ System.err.println("FAILED: " + DEFAULT_TEXTURES);
11895
+ }
1097911896 }
1098011897 //System.out.println("--> " + stackdepth);
1098111898 // GrafreeD.traceon();
....@@ -10985,8 +11902,9 @@
1098511902
1098611903 if (DrawMode() == DEFAULT)
1098711904 {
10988
- if (DEBUG)
11905
+ if (Globals.DEBUG)
1098911906 {
11907
+ CreateSelectedPoint();
1099011908 float radius = 0.05f;
1099111909 if (selectedpoint.radius != radius)
1099211910 {
....@@ -11040,20 +11958,32 @@
1104011958 ReleaseTextures(DEFAULT_TEXTURES);
1104111959
1104211960 if (CLEANCACHE)
11043
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11961
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1104411962 {
11045
- String tex = e.nextElement();
11963
+ cTexture tex = e.nextElement();
1104611964
1104711965 // System.out.println("Texture --------- " + tex);
1104811966
11049
- if (tex.equals("WHITE_NOISE"))
11967
+ if (tex.equals("WHITE_NOISE:"))
1105011968 continue;
1105111969
11052
- if (!usedtextures.containsKey(tex))
11970
+ if (!usedtextures.contains(tex))
1105311971 {
11972
+ CacheTexture gettex = texturepigment.get(tex);
1105411973 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11055
- textures.get(tex).texture.dispose();
11056
- textures.remove(tex);
11974
+ if (gettex != null)
11975
+ {
11976
+ gettex.texture.dispose();
11977
+ texturepigment.remove(tex);
11978
+ }
11979
+
11980
+ gettex = texturebump.get(tex);
11981
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11982
+ if (gettex != null)
11983
+ {
11984
+ gettex.texture.dispose();
11985
+ texturebump.remove(tex);
11986
+ }
1105711987 }
1105811988 }
1105911989 }
....@@ -11066,7 +11996,14 @@
1106611996 if (checker != null && DrawMode() == DEFAULT)
1106711997 {
1106811998 //BindTexture(IMMORTAL_TEXTURE);
11069
- BindTextures(checker.GetTextures(), checker.texres);
11999
+ try
12000
+ {
12001
+ BindTextures(checker.GetTextures(), checker.texres);
12002
+ }
12003
+ catch (Exception e)
12004
+ {
12005
+ System.err.println("FAILED: " + checker.GetTextures());
12006
+ }
1107012007 // NEAREST
1107112008 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
1107212009 DrawChecker(gl);
....@@ -11148,7 +12085,7 @@
1114812085 return;
1114912086 }
1115012087
11151
- String string = obj.GetToolTip();
12088
+ String string = obj.toString(); //.GetToolTip();
1115212089
1115312090 GL gl = GetGL();
1115412091
....@@ -11465,8 +12402,8 @@
1146512402 //obj.TransformToWorld(light, light);
1146612403 for (int i = tp.size(); --i >= 0;)
1146712404 {
11468
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
11469
- LA.xformPos(light, tp.get(i).toParent, light);
12405
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12406
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1147012407 }
1147112408
1147212409
....@@ -11483,8 +12420,8 @@
1148312420 parentcam = cameras[0];
1148412421 }
1148512422
11486
- for (int count = parentcam.GetTransformCount(); --count>=0;)
11487
- LA.xformPos(light, parentcam.toParent, light); // may 2013
12423
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
12424
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1148812425
1148912426 LA.xformPos(light, renderCamera.toScreen, light);
1149012427
....@@ -11574,8 +12511,82 @@
1157412511
1157512512 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1157612513
11577
- String program =
12514
+ String programmin =
12515
+ // Min shader
1157812516 "!!ARBfp1.0\n" +
12517
+ "PARAM zero12t = { 0.0, 1.0, 2, 1.25 };" +
12518
+ "PARAM pow_2 = { 0.5, 0.25, 0.125, 0.0 };" +
12519
+ "PARAM pow2 = { 2, 4, 8, 0.0 };" +
12520
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12521
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12522
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12523
+ "PARAM light2cam0 = program.env[10];" +
12524
+ "PARAM light2cam1 = program.env[11];" +
12525
+ "PARAM light2cam2 = program.env[12];" +
12526
+ "TEMP temp;" +
12527
+ "TEMP light;" +
12528
+ "TEMP ndotl;" +
12529
+ "TEMP normal;" +
12530
+ "TEMP depth;" +
12531
+ "TEMP eye;" +
12532
+ "TEMP pos;" +
12533
+
12534
+ "MAD normal, fragment.color, zero12t.z, -zero12t.y;" +
12535
+ Normalize("normal") +
12536
+ "MOV light, state.light[0].position;" +
12537
+ "DP3 ndotl.x, light, normal;" +
12538
+ "MAX ndotl.x, ndotl.x, zero12t.x;" +
12539
+
12540
+ // shadow
12541
+ "MOV pos, fragment.texcoord[1];" +
12542
+ "MOV temp, pos;" +
12543
+ ShadowTextureFetch("depth", "temp", "1") +
12544
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12545
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12546
+
12547
+ // No shadow when out of frustum
12548
+ //"SGE temp.y, depth.z, zero123.y;" +
12549
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12550
+
12551
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12552
+
12553
+ // Backlit
12554
+ "MOV pos.w, zero12t.y;" + // one
12555
+ "DP4 eye.x, pos, light2cam0;" +
12556
+ "DP4 eye.y, pos, light2cam1;" +
12557
+ "DP4 eye.z, pos, light2cam2;" +
12558
+ Normalize("eye") +
12559
+
12560
+ "DP3 ndotl.y, -eye, normal;" +
12561
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12562
+ "POW ndotl.y, ndotl.y, pow2.x;" + // backlit
12563
+ "SUB ndotl.y, zero12t.y, ndotl.y;" + // 1 - y
12564
+ //"POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12565
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12566
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12567
+ "ADD ndotl.y, ndotl.y, one.x;" +
12568
+ "MUL ndotl.y, ndotl.y, pow_2.x;" +
12569
+
12570
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12571
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12572
+
12573
+ // Pigment
12574
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12575
+ "LRP temp, zero12t.w, temp, one;" + // texture proportion
12576
+ "MUL temp, temp, zero12t.w;" + // Times x
12577
+
12578
+ //"MUL temp, temp, ndotl.y;" +
12579
+ "MAD ndotl.x, pow_2.xxxx, ndotl.yyyy, ndotl.x;" +
12580
+
12581
+ "MUL temp, temp, ndotl.x;" + // lambert
12582
+
12583
+ "MOV temp.w, zero12t.y;" + // reset alpha
12584
+ "MOV result.color, temp;" +
12585
+ "END";
12586
+
12587
+ String programmax =
12588
+ "!!ARBfp1.0\n" +
12589
+
1157912590 //"OPTION ARB_fragment_program_shadow;" +
1158012591 "PARAM light2cam0 = program.env[10];" +
1158112592 "PARAM light2cam1 = program.env[11];" +
....@@ -11601,7 +12612,7 @@
1160112612 "PARAM params4 = program.env[4];" + // anisoV, cameralight, selfshadow, shadow
1160212613 "PARAM params5 = program.env[5];" + // texture, opacity, fakedepth, shadowbias
1160312614 "PARAM params6 = program.env[6];" + // bump, noise, borderfade, fog punchthrough
11604
- "PARAM params7 = program.env[7];" + // noise power, opacity power
12615
+ "PARAM params7 = program.env[7];" + // noise power, opacity power, parallax
1160512616 "PARAM options0 = program.env[63];" + // fog density, intensity, elevation
1160612617 "PARAM options1 = program.env[62];" + // fog rgb color
1160712618 "PARAM options2 = program.env[61];" + // image intensity, subsurface, lightsheen
....@@ -11690,8 +12701,7 @@
1169012701 "TEMP shininess;" +
1169112702 "\n" +
1169212703 "MOV texSamp, one;" +
11693
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
11694
-
12704
+
1169512705 "MOV mapgrid.x, one2048th.x;" +
1169612706 "MOV temp, fragment.texcoord[1];" +
1169712707 /*
....@@ -11712,20 +12722,20 @@
1171212722 "MUL temp, floor, mapgrid.x;" +
1171312723 //"TEX depth0, temp, texture[1], 2D;" +
1171412724 (((mode & FP_SOFTSHADOW) == 0) ? "" :
11715
- TextureFetch("depth0", "temp", "1") +
12725
+ ShadowTextureFetch("depth0", "temp", "1") +
1171612726 "") +
1171712727 "ADD temp.x, temp.x, mapgrid.x;" +
1171812728 //"TEX depth1, temp, texture[1], 2D;" +
1171912729 (((mode & FP_SOFTSHADOW) == 0) ? "" :
11720
- TextureFetch("depth1", "temp", "1") +
12730
+ ShadowTextureFetch("depth1", "temp", "1") +
1172112731 "") +
1172212732 "ADD temp.y, temp.y, mapgrid.x;" +
1172312733 //"TEX depth2, temp, texture[1], 2D;" +
11724
- TextureFetch("depth2", "temp", "1") +
12734
+ ShadowTextureFetch("depth2", "temp", "1") +
1172512735 "SUB temp.x, temp.x, mapgrid.x;" +
1172612736 //"TEX depth3, temp, texture[1], 2D;" +
1172712737 (((mode & FP_SOFTSHADOW) == 0) ? "" :
11728
- TextureFetch("depth3", "temp", "1") +
12738
+ ShadowTextureFetch("depth3", "temp", "1") +
1172912739 "") +
1173012740 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1173112741 //"MOV params, material;" +
....@@ -11847,7 +12857,7 @@
1184712857 "POW texSamp.a, texSamp.a, params6.w;" + // fog punch through shortcut
1184812858 // mar 2013 ??? "KIL alpha.a;" +
1184912859 "MOV alpha, texSamp.aaaa;" + // y;" +
11850
- "KIL alpha.a;" +
12860
+ "KIL alpha.a;" + // not sure with parallax mapping
1185112861 /*
1185212862 "MUL temp.xy, temp, two;" +
1185312863 "TXB bump, temp, texture[0], 2D;" +
....@@ -11933,11 +12943,6 @@
1193312943 "SUB bump0, bump0, half;" +
1193412944 "ADD bump, bump, bump0;" +
1193512945
11936
- "MOV temp.x, texSamp.a;" +
11937
- "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
11938
- //"LRP texSamp0, params5.x, texSamp0, one;" +
11939
- "MOV texSamp.a, temp.x;" +
11940
-
1194112946 // double-sided
1194212947 /**/
1194312948 (doublesided?"DP3 temp.z, normal, eye;" +
....@@ -11954,19 +12959,62 @@
1195412959 "MOV normald, normal;" +
1195512960 "MOV normals, normal;" +
1195612961
12962
+ "MOV temp, fragment.texcoord[4];" +
12963
+
1195712964 // UV base
1195812965 //"DP3 UP.x,state.matrix.modelview.row[0],Y;" +
1195912966 //"DP3 UP.y,state.matrix.modelview.row[1],Y;" +
1196012967 //"DP3 UP.z,state.matrix.modelview.row[2],Y;" +
11961
- "DP3 UP.x,state.matrix.texture[7].row[0],Y;" +
11962
- "DP3 UP.y,state.matrix.texture[7].row[1],Y;" +
11963
- "DP3 UP.z,state.matrix.texture[7].row[2],Y;" +
12968
+ "DP3 UP.x,state.matrix.texture[7].row[0],temp;" +
12969
+ "DP3 UP.y,state.matrix.texture[7].row[1],temp;" +
12970
+ "DP3 UP.z,state.matrix.texture[7].row[2],temp;" +
12971
+ Normalize("UP") +
12972
+
1196412973 "XPD V, normal, UP;" +
1196512974 Normalize("V") +
1196612975 "XPD U, V, normal;" +
1196712976 Normalize("U") +
1196812977
1196912978 // parallax mapping
12979
+
12980
+ "DP3 temp2.x, V, eye;" +
12981
+ "DP3 temp2.y, U, eye;" +
12982
+ "DP3 temp2.z, normal, eye;" +
12983
+ "RCP temp2.z, temp2.z;" +
12984
+
12985
+ "DP3 temp2.w, texSamp, texSamp;" + // Height
12986
+ "RSQ temp2.w, temp2.w;" +
12987
+ "RCP temp2.w, temp2.w;" +
12988
+
12989
+ "SUB temp2.w, temp2.w, half;" +
12990
+// "SGE temp.x, temp2.w, eps.x;" +
12991
+// "MUL temp2.w, temp2.w, temp.x;" +
12992
+
12993
+ //"MOV texSamp, U;" +
12994
+
12995
+ "MUL temp2.z, temp2.z, temp2.w;" +
12996
+ "MUL temp2.z, temp2.z, params7.z;" + // parallax
12997
+
12998
+ "MUL temp2, temp2, temp2.z;" +
12999
+
13000
+ "MOV temp, fragment.texcoord[0];" +
13001
+
13002
+ "SUB temp, temp, temp2;" +
13003
+
13004
+ "TEX temp, temp, texture[0], 2D;" +
13005
+ "POW temp.a, temp.a, params6.w;" + // punch through
13006
+
13007
+ "ADD texSamp, temp, texSamp;" +
13008
+ "MUL texSamp.xyz, half, texSamp;" +
13009
+
13010
+ "MOV alpha, texSamp.aaaa;" +
13011
+
13012
+// parallax mapping
13013
+
13014
+ "MOV temp.x, texSamp.a;" +
13015
+ "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
13016
+ //"LRP texSamp0, params5.x, texSamp0, one;" +
13017
+ "MOV texSamp.a, temp.x;" +
1197013018
1197113019 //"MOV temp, fragment.texcoord[0];" +
1197213020 //
....@@ -12096,10 +13144,10 @@
1209613144 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1209713145 "") +
1209813146
12099
- // display shadow only (bump == 0)
13147
+ // display shadow only (fakedepth == 0)
1210013148 "SUB temp.x, half.x, shadow.x;" +
12101
- "MOV temp.y, -params6.x;" +
12102
- "SLT temp.z, temp.y, zero.x;" +
13149
+ "MOV temp.y, -params5.z;" + // params6.x;" +
13150
+ "SLT temp.z, temp.y, -c256i.x;" +
1210313151 "SUB temp.y, one.x, temp.z;" +
1210413152 "MUL temp.x, temp.x, temp.y;" +
1210513153 "KIL temp.x;" +
....@@ -12228,8 +13276,10 @@
1222813276 "MAX ndotl.x, ndotl.x, -ndotl.x;" +
1222913277
1223013278 "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
13279
+ // Tuning for default skin
13280
+ //"ADD temp.x, temp.x, options2.z;" + // lightsheen
13281
+ "MAD temp.x, options2.z, half.y, temp.x;" + // lightsheen
13282
+ "ADD temp.y, one.y, options2.y;" + // subsurface
1223313283 "MUL temp.x, temp.x, temp.y;" +
1223413284
1223513285 "MUL saturation, saturation, temp.xxxx;" +
....@@ -12428,8 +13478,19 @@
1242813478 //once = true;
1242913479 }
1243013480
12431
- System.out.print("Program #" + mode + "; length = " + program.length());
12432
- System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13481
+ String program = programmax;
13482
+
13483
+ if (Globals.MINSHADER)
13484
+ {
13485
+ program = programmin;
13486
+ }
13487
+
13488
+ if (Globals.DEBUG)
13489
+ {
13490
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13491
+ System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13492
+ }
13493
+
1243313494 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1243413495
1243513496 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -12476,7 +13537,8 @@
1247613537 "\n" +
1247713538 "END\n";
1247813539
12479
- System.out.println("Program shadow #" + 0 + "; length = " + program.length());
13540
+ if (Globals.DEBUG)
13541
+ System.out.println("Program shadow #" + 0 + "; length = " + program.length());
1248013542 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1248113543
1248213544 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -12521,25 +13583,26 @@
1252113583 return out;
1252213584 }
1252313585
12524
- String TextureFetch(String dest, String src, String unit)
13586
+ // Also does frustum culling
13587
+ String ShadowTextureFetch(String dest, String src, String unit)
1252513588 {
1252613589 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1252713590 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1252813591 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13592
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13593
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1252913594 "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;" +
13595
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13596
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1253413597 //"SWZ buffer, temp, w,w,w,w;";
12535
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13598
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1253613599 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1253713600 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1253813601 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
12539
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13602
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1254013603
12541
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
12542
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13604
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13605
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1254313606 }
1254413607
1254513608 String Shadow(String depth, String shadow)
....@@ -12561,12 +13624,16 @@
1256113624
1256213625 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1256313626 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13627
+
13628
+ // Compare fragment depth in light space with shadowmap.
1256413629 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1256513630 "SGE temp.y, temp.x, zero.x;" +
12566
- "SUB " + shadow + ".y, one.x, temp.y;" +
13631
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13632
+
13633
+ // Reverse comparison
1256713634 "SUB temp.x, one.x, temp.x;" +
1256813635 "MUL " + shadow + ".x, temp.x, temp.y;" +
12569
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13636
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1257013637 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1257113638
1257213639 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -12580,6 +13647,10 @@
1258013647 // No shadow for backface
1258113648 "DP3 temp.x, normal, lightd;" +
1258213649 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13650
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13651
+
13652
+ // No shadow when out of frustum
13653
+ "SGE temp.x, " + depth + ".z, one.z;" +
1258313654 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1258413655 "";
1258513656 }
....@@ -12725,8 +13796,9 @@
1272513796 /*static*/ float[] modelParams4 = new float[]{0, 0, 0, 0}; // anisoV, cameralight, selfshadow, shadow
1272613797 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1272713798 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
12728
- /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
12729
- Object3D.cVector2[] vector2buffer;
13799
+ /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power, parallax
13800
+
13801
+ //Object3D.cVector2[] vector2buffer;
1273013802
1273113803 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1273213804 // OUT : diff, spec
....@@ -12742,9 +13814,10 @@
1274213814 "DP3 " + dest + ".z," + "normals," + "eye;" +
1274313815 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1274413816 //"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;" +
13817
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13818
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13819
+
13820
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1274813821 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1274913822 "RCP " + dest + ".w," + dest + ".w;" +
1275013823 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -12890,7 +13963,7 @@
1289013963 "PARAM p[4] = { state.matrix.projection }; # modelview projection matrix\n" +
1289113964 "PARAM zero = { 0.0, 0.0, 0.0, 1.0 };" +
1289213965 "PARAM half = { 0.5, 0.5, 0.5, 1.0 };" +
12893
- "PARAM one = { 1.0, 1.0, 1.0, 0.0 };" +
13966
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
1289413967 "PARAM two = { 2.0, 2.0, 2.0, 1.0 };" +
1289513968 "PARAM third = { 0.33333333333, 0.33333333333, 0.33333333333, 1.0 };" +
1289613969 //"PARAM v256 = { 256.0, 256.0, 256.0, 1.0 };" +
....@@ -12951,7 +14024,7 @@
1295114024 "DP4 temp.x,state.matrix.texture[0].inverse.row[0],vertex.texcoord;" +
1295214025 "DP4 temp.y,state.matrix.texture[0].inverse.row[1],vertex.texcoord;" +
1295314026 "DP4 temp.z,state.matrix.texture[0].inverse.row[2],vertex.texcoord;" +
12954
- //"MOV result.texcoord, vertex.texcoord;" +
14027
+ //"MOV result.texcoord, vertex.fogcoord;" +
1295514028 "MOV result.texcoord, temp;" +
1295614029 // border fade
1295714030 "MOV result.texcoord[3], vertex.texcoord;" +
....@@ -12998,7 +14071,9 @@
1299814071
1299914072 //"ADD temp.z, temp.z, one;" +
1300014073
13001
- "MOV result.color, temp;"
14074
+ "MOV result.texcoord[4], vertex.attrib[4];" + // U dir
14075
+
14076
+ "MOV result.color, temp;" // Normal
1300214077 : "MOV result.color, vertex.color;") +
1300314078 ((mode & VP_PROJECTION) != 0 ? "MOV result.color, zero;"
1300414079 : "") +
....@@ -13138,7 +14213,7 @@
1313814213 public void mousePressed(MouseEvent e)
1313914214 {
1314014215 //System.out.println("mousePressed: " + e);
13141
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14216
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1314214217 }
1314314218
1314414219 static long prevtime = 0;
....@@ -13165,6 +14240,7 @@
1316514240
1316614241 //System.err.println("Dtime = " + Dtime + "; units = " + e.getUnitsToScroll() + "; ratio (units/ms) = " + ratio);
1316714242
14243
+ if (BUTTONLESSWHEEL)
1316814244 if (Math.abs(ratio) < 0.1 || Math.abs(Dtime) == 0) // < 30)
1316914245 {
1317014246 return;
....@@ -13173,7 +14249,7 @@
1317314249 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
1317414250
1317514251 // TIMER
13176
- if (!wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
14252
+ if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
1317714253 {
1317814254 keepboxmode = BOXMODE;
1317914255 keepsupport = SUPPORT;
....@@ -13213,8 +14289,8 @@
1321314289 // mode |= META;
1321414290 //}
1321514291
13216
- SetMouseMode(WHEEL | e.getModifiersEx());
13217
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14292
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14293
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1321814294 anchorX = ax;
1321914295 anchorY = ay;
1322014296 prevX = px;
....@@ -13248,6 +14324,7 @@
1324814324 else
1324914325 if (evt.getSource() == AAtimer)
1325014326 {
14327
+ Globals.TIMERRUNNING = false;
1325114328 if (mouseDown)
1325214329 {
1325314330 //new Exception().printStackTrace();
....@@ -13273,6 +14350,10 @@
1327314350 // LIVE = waslive;
1327414351 // wasliveok = true;
1327514352 // waslive = false;
14353
+
14354
+ // May 2019 Forget it:
14355
+ if (true)
14356
+ return;
1327614357
1327714358 // source == timer
1327814359 if (mouseDown)
....@@ -13303,7 +14384,7 @@
1330314384
1330414385 // fev 2014???
1330514386 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13306
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14387
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1330714388 pingthread.StepToTarget(true); // true);
1330814389 }
1330914390 // if (!LIVE)
....@@ -13312,12 +14393,13 @@
1331214393
1331314394 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1331414395
13315
- void clickStart(int x, int y, int modifiers)
14396
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1331614397 {
1331714398 if (!wasliveok)
1331814399 return;
1331914400
1332014401 AAtimer.restart(); //
14402
+ Globals.TIMERRUNNING = true;
1332114403
1332214404 // waslive = LIVE;
1332314405 // LIVE = false;
....@@ -13329,7 +14411,7 @@
1332914411 // touched = true; // main DL
1333014412 if (isRenderer)
1333114413 {
13332
- SetMouseMode(modifiers);
14414
+ SetMouseMode(modifiers, modifiersex);
1333314415 }
1333414416
1333514417 selectX = anchorX = x;
....@@ -13342,7 +14424,7 @@
1334214424 clicked = true;
1334314425 hold = false;
1334414426
13345
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14427
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1334614428 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1334714429 {
1334814430 // System.out.println("RESTART II " + modifiers);
....@@ -13367,14 +14449,15 @@
1336714449 drag = false;
1336814450 //System.out.println("Mouse DOWN");
1336914451 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);
14452
+ //ClickInfo info = new ClickInfo();
14453
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14454
+ object.clickInfo.pane = this;
14455
+ object.clickInfo.camera = renderCamera;
14456
+ object.clickInfo.x = x;
14457
+ object.clickInfo.y = y;
14458
+ object.clickInfo.modifiers = modifiersex;
14459
+ editObj = object.doEditClick(//info,
14460
+ 0);
1337814461 if (!editObj)
1337914462 {
1338014463 hasMarquee = true;
....@@ -13390,11 +14473,14 @@
1339014473
1339114474 public void mouseDragged(MouseEvent e)
1339214475 {
14476
+ Globals.MOUSEDRAGGED = true;
14477
+
14478
+ //System.out.println("mouseDragged: " + e);
1339314479 if (isRenderer)
1339414480 movingcamera = true;
14481
+
1339514482 //if (drawing)
1339614483 //return;
13397
- //System.out.println("mouseDragged: " + e);
1339814484 if ((e.getModifiersEx() & CTRL) != 0
1339914485 || (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen())
1340014486 {
....@@ -13402,7 +14488,7 @@
1340214488 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1340314489 }
1340414490 else
13405
- drag(e.getX(), e.getY(), e.getModifiersEx());
14491
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1340614492
1340714493 //try { Thread.sleep(1); } catch (Exception ex) {}
1340814494 }
....@@ -13575,6 +14661,7 @@
1357514661
1357614662 public void run()
1357714663 {
14664
+ new Exception().printStackTrace();
1357814665 System.exit(0);
1357914666 for (;;)
1358014667 {
....@@ -13638,7 +14725,7 @@
1363814725 {
1363914726 Globals.lighttouched = true;
1364014727 }
13641
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14728
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1364214729 }
1364314730 //else
1364414731 }
....@@ -13652,12 +14739,18 @@
1365214739 void GoDown(int mod)
1365314740 {
1365414741 MODIFIERS |= COMMAND;
13655
- /*
14742
+ boolean isVR = (mouseMode&VR)!=0;
14743
+ /**/
1365614744 if((mod&SHIFT) == SHIFT)
13657
- manipCamera.RotatePosition(0, -speed);
14745
+ {
14746
+ if (isVR)
14747
+ manipCamera.RotateInterest(0, -speed);
14748
+ else
14749
+ manipCamera.RotatePosition(0, -speed);
14750
+ }
1365814751 else
13659
- manipCamera.BackForth(0, -speed*delta, getWidth());
13660
- */
14752
+ manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth());
14753
+ /**/
1366114754 if ((mod & SHIFT) == SHIFT)
1366214755 {
1366314756 mouseMode = mouseMode; // VR??
....@@ -13666,6 +14759,8 @@
1366614759 mouseMode |= BACKFORTH;
1366714760 }
1366814761
14762
+ targetLookAt.set(manipCamera.lookAt);
14763
+
1366914764 //prevX = X = anchorX;
1367014765 prevY = Y = anchorY - (int) (renderCamera.Distance());
1367114766 }
....@@ -13673,12 +14768,19 @@
1367314768 void GoUp(int mod)
1367414769 {
1367514770 MODIFIERS |= COMMAND;
13676
- /*
14771
+ /**/
14772
+ boolean isVR = (mouseMode&VR)!=0;
14773
+
1367714774 if((mod&SHIFT) == SHIFT)
13678
- manipCamera.RotatePosition(0, speed);
14775
+ {
14776
+ if (isVR)
14777
+ manipCamera.RotateInterest(0, speed);
14778
+ else
14779
+ manipCamera.RotatePosition(0, speed);
14780
+ }
1367914781 else
13680
- manipCamera.BackForth(0, speed*delta, getWidth());
13681
- */
14782
+ manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth());
14783
+ /**/
1368214784 if ((mod & SHIFT) == SHIFT)
1368314785 {
1368414786 mouseMode = mouseMode;
....@@ -13687,6 +14789,8 @@
1368714789 mouseMode |= BACKFORTH;
1368814790 }
1368914791
14792
+ targetLookAt.set(manipCamera.lookAt);
14793
+
1369014794 //prevX = X = anchorX;
1369114795 prevY = Y = anchorY + (int) (renderCamera.Distance());
1369214796 }
....@@ -13694,12 +14798,17 @@
1369414798 void GoLeft(int mod)
1369514799 {
1369614800 MODIFIERS |= COMMAND;
13697
- /*
14801
+ /**/
1369814802 if((mod&SHIFT) == SHIFT)
13699
- manipCamera.RotatePosition(speed, 0);
14803
+ manipCamera.Translate(speed*delta, 0, getWidth());
1370014804 else
13701
- manipCamera.Translate(speed*delta, 0, getWidth());
13702
- */
14805
+ {
14806
+ if ((mouseMode&VR)!=0)
14807
+ manipCamera.RotateInterest(-speed, 0);
14808
+ else
14809
+ manipCamera.RotatePosition(speed, 0);
14810
+ }
14811
+ /**/
1370314812 if ((mod & SHIFT) == SHIFT)
1370414813 {
1370514814 mouseMode = mouseMode;
....@@ -13708,6 +14817,8 @@
1370814817 mouseMode |= ROTATE;
1370914818 } // TRANSLATE;
1371014819
14820
+ targetLookAt.set(manipCamera.lookAt);
14821
+
1371114822 prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance());
1371214823 prevY = Y = anchorY;
1371314824 }
....@@ -13715,12 +14826,18 @@
1371514826 void GoRight(int mod)
1371614827 {
1371714828 MODIFIERS |= COMMAND;
13718
- /*
14829
+ /**/
1371914830 if((mod&SHIFT) == SHIFT)
13720
- manipCamera.RotatePosition(-speed, 0);
14831
+ manipCamera.Translate(-speed*delta, 0, getWidth());
1372114832 else
13722
- manipCamera.Translate(-speed*delta, 0, getWidth());
13723
- */
14833
+ {
14834
+ if ((mouseMode&VR)!=0)
14835
+ manipCamera.RotateInterest(speed, 0);
14836
+ else
14837
+ manipCamera.RotatePosition(-speed, 0);
14838
+ }
14839
+
14840
+ /**/
1372414841 if ((mod & SHIFT) == SHIFT)
1372514842 {
1372614843 mouseMode = mouseMode;
....@@ -13729,6 +14846,8 @@
1372914846 mouseMode |= ROTATE;
1373014847 } // TRANSLATE;
1373114848
14849
+ targetLookAt.set(manipCamera.lookAt);
14850
+
1373214851 prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance());
1373314852 prevY = Y = anchorY;
1373414853 }
....@@ -13738,7 +14857,7 @@
1373814857 int X, Y;
1373914858 boolean SX, SY;
1374014859
13741
- void drag(int x, int y, int modifiers)
14860
+ void drag(int x, int y, int modifiers, int modifiersex)
1374214861 {
1374314862 if (IsFrozen())
1374414863 {
....@@ -13747,17 +14866,17 @@
1374714866
1374814867 drag = true; // NEW
1374914868
13750
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14869
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1375114870
1375214871 X = x;
1375314872 Y = y;
1375414873 // floating state for animation
13755
- MODIFIERS = modifiers;
13756
- modifiers &= ~1024;
14874
+ MODIFIERS = modifiersex;
14875
+ modifiersex &= ~1024;
1375714876 if (false) // modifiers != 0)
1375814877 {
1375914878 //new Exception().printStackTrace();
13760
- System.out.println("mouseDragged: " + modifiers);
14879
+ System.out.println("mouseDragged: " + modifiersex);
1376114880 System.out.println("SHIFT = " + SHIFT);
1376214881 System.out.println("CONTROL = " + COMMAND);
1376314882 System.out.println("META = " + META);
....@@ -13770,14 +14889,16 @@
1377014889 if (editObj)
1377114890 {
1377214891 drag = true;
13773
- ClickInfo info = new ClickInfo();
13774
- info.bounds.setBounds(0, 0,
14892
+ //ClickInfo info = new ClickInfo();
14893
+ object.clickInfo.bounds.setBounds(0, 0,
1377514894 (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);
14895
+ object.clickInfo.pane = this;
14896
+ object.clickInfo.camera = renderCamera;
14897
+ object.clickInfo.x = x;
14898
+ object.clickInfo.y = y;
14899
+ object //.GetWindow().copy
14900
+ .doEditDrag(//info,
14901
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1378114902 } else
1378214903 {
1378314904 if (x < startX)
....@@ -13926,23 +15047,27 @@
1392615047 }
1392715048 }
1392815049
15050
+// ClickInfo clickInfo = new ClickInfo();
15051
+
1392915052 public void mouseMoved(MouseEvent e)
1393015053 {
1393115054 //System.out.println("mouseMoved: " + e);
13932
-
1393315055 if (isRenderer)
1393415056 return;
1393515057
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;
15058
+ // Mouse cursor feedback
15059
+ object.clickInfo.x = e.getX();
15060
+ object.clickInfo.y = e.getY();
15061
+ object.clickInfo.modifiers = e.getModifiersEx();
15062
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
15063
+ object.clickInfo.pane = this;
15064
+ object.clickInfo.camera = renderCamera;
1394315065 if (!isRenderer)
1394415066 {
13945
- if (object.editWindow.copy.doEditClick(ci, 0))
15067
+ //ObjEditor editWindow = object.editWindow;
15068
+ //Object3D copy = editWindow.copy;
15069
+ if (object.doEditClick(//clickInfo,
15070
+ 0))
1394615071 {
1394715072 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1394815073 } else
....@@ -13954,7 +15079,11 @@
1395415079
1395515080 public void mouseReleased(MouseEvent e)
1395615081 {
15082
+ Globals.MOUSEDRAGGED = false;
15083
+
1395715084 movingcamera = false;
15085
+ X = 0; // getBounds().width/2;
15086
+ Y = 0; // getBounds().height/2;
1395815087 //System.out.println("mouseReleased: " + e);
1395915088 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1396015089 }
....@@ -13977,9 +15106,9 @@
1397715106 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1397815107 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1397915108
13980
- if (control || command || IsFrozen())
15109
+// No delay if (control || command || IsFrozen())
1398115110 timeout = true;
13982
- else
15111
+// ?? May 2019 else
1398315112 // timer.setDelay((modifiers & 128) != 0?0:350);
1398415113 mouseDown = false;
1398515114 if (!control && !command) // june 2013
....@@ -14089,7 +15218,7 @@
1408915218 System.out.println("keyReleased: " + e);
1409015219 }
1409115220
14092
- void SetMouseMode(int modifiers)
15221
+ void SetMouseMode(int modifiers, int modifiersex)
1409315222 {
1409415223 //System.out.println("SetMouseMode = " + modifiers);
1409515224 //modifiers &= ~1024;
....@@ -14101,25 +15230,25 @@
1410115230 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1410215231 // return;
1410315232 //System.out.println("SetMode = " + modifiers);
14104
- if ((modifiers & WHEEL) == WHEEL)
15233
+ if ((modifiersex & WHEEL) == WHEEL)
1410515234 {
1410615235 mouseMode |= ZOOM;
1410715236 }
1410815237
1410915238 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
14110
- if (capsLocked || (modifiers & META) == META)
15239
+ if (capsLocked) // || (modifiers & META) == META)
1411115240 {
1411215241 mouseMode |= VR; // BACKFORTH;
1411315242 }
14114
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
15243
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1411515244 {
1411615245 mouseMode |= SELECT;
1411715246 }
14118
- if ((modifiers & COMMAND) == COMMAND)
15247
+ if ((modifiersex & COMMAND) == COMMAND)
1411915248 {
1412015249 mouseMode |= SELECT;
1412115250 }
14122
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15251
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
1412315252 {
1412415253 mouseMode &= ~VR;
1412515254 mouseMode |= TRANSLATE;
....@@ -14148,7 +15277,7 @@
1414815277
1414915278 if (isRenderer) //
1415015279 {
14151
- SetMouseMode(modifiers);
15280
+ SetMouseMode(0, modifiers);
1415215281 }
1415315282
1415415283 Globals.theRenderer.keyPressed(key);
....@@ -14210,7 +15339,8 @@
1421015339 // break;
1421115340 case 'T':
1421215341 CACHETEXTURE ^= true;
14213
- textures.clear();
15342
+ texturepigment.clear();
15343
+ texturebump.clear();
1421415344 // repaint();
1421515345 break;
1421615346 case 'Y':
....@@ -14220,8 +15350,8 @@
1422015350 case 'K':
1422115351 KOMPACTTEXTURE ^= true;
1422215352 //textures.clear();
14223
- break;
14224
- case 'P': // Texture Projection macros
15353
+ // break;
15354
+ //case 'P': // Texture Projection macros
1422515355 // SAVETEXTURE ^= true;
1422615356 macromode = true;
1422715357 Udebug = Vdebug = NORMALdebug = false; programInitialized = false;
....@@ -14295,7 +15425,9 @@
1429515425 case 'E' : COMPACT ^= true;
1429615426 repaint();
1429715427 break;
14298
- case 'W' : DEBUGHSB ^= true;
15428
+ case 'W' : // Wide Window (fullscreen)
15429
+ //DEBUGHSB ^= true;
15430
+ ObjEditor.theFrame.ToggleFullScreen();
1429915431 repaint();
1430015432 break;
1430115433 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14320,8 +15452,8 @@
1432015452 RevertCamera();
1432115453 repaint();
1432215454 break;
14323
- case 'L':
1432415455 case 'l':
15456
+ //case 'L':
1432515457 if (lightMode)
1432615458 {
1432715459 lightMode = false;
....@@ -14340,7 +15472,7 @@
1434015472 targetLookAt.set(manipCamera.lookAt);
1434115473 repaint();
1434215474 break;
14343
- case 'p':
15475
+ case 'P': // p':
1434415476 // c'est quoi ca au juste? spherical ^= true;
1434515477 Skinshader ^= true; programInitialized = false;
1434615478 repaint();
....@@ -14378,27 +15510,31 @@
1437815510 repaint();
1437915511 break;
1438015512 case 'O':
14381
- Globals.drawMode = OCCLUSION; // WARNING
15513
+ // Too dangerous. Use menu. Globals.drawMode = OCCLUSION; // WARNING
1438215514 repaint();
1438315515 break;
1438415516 case 'o':
1438515517 OCCLUSION_CULLING ^= true;
1438615518 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1438715519 break;
14388
- case '0': envyoff ^= true; repaint(); break;
15520
+ //case '0': envyoff ^= true; repaint(); break;
1438915521 case '1':
1439015522 case '2':
1439115523 case '3':
1439215524 case '4':
1439315525 case '5':
14394
- newenvy = Character.getNumericValue(key);
14395
- repaint();
14396
- break;
1439715526 case '6':
1439815527 case '7':
1439915528 case '8':
1440015529 case '9':
14401
- BGcolor = (key - '6')/3.f;
15530
+ if (true) // envyoff)
15531
+ {
15532
+ BGcolor = (key - '1')/8.f;
15533
+ }
15534
+ else
15535
+ {
15536
+ //newenvy = Character.getNumericValue(key);
15537
+ }
1440215538 repaint();
1440315539 break;
1440415540 case '!':
....@@ -14464,9 +15600,9 @@
1446415600 case '_':
1446515601 kompactbit = 5;
1446615602 break;
14467
- case '+':
14468
- kompactbit = 6;
14469
- break;
15603
+// case '+':
15604
+// kompactbit = 6;
15605
+// break;
1447015606 case ' ':
1447115607 lightMode ^= true;
1447215608 Globals.lighttouched = true;
....@@ -14478,13 +15614,14 @@
1447815614 case ESC:
1447915615 RENDERPROGRAM += 1;
1448015616 RENDERPROGRAM %= 3;
15617
+
1448115618 repaint();
1448215619 break;
1448315620 case 'Z':
1448415621 //RESIZETEXTURE ^= true;
1448515622 //break;
1448615623 case 'z':
14487
- RENDERSHADOW ^= true;
15624
+ Globals.RENDERSHADOW ^= true;
1448815625 Globals.lighttouched = true;
1448915626 repaint();
1449015627 break;
....@@ -14517,8 +15654,9 @@
1451715654 case DELETE:
1451815655 ClearSelection();
1451915656 break;
14520
- /*
1452115657 case '+':
15658
+
15659
+ /*
1452215660 //fontsize += 1;
1452315661 bbzoom *= 2;
1452415662 repaint();
....@@ -14535,17 +15673,17 @@
1453515673 case '=':
1453615674 IncDepth();
1453715675 //fontsize += 1;
14538
- object.editWindow.refreshContents(true);
15676
+ object.GetWindow().refreshContents(true);
1453915677 maskbit = 6;
1454015678 break;
1454115679 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1454215680 DecDepth();
1454315681 maskbit = 5;
1454415682 //if(fontsize > 1) fontsize -= 1;
14545
- if (object.editWindow == null)
14546
- new Exception().printStackTrace();
14547
- else
14548
- object.editWindow.refreshContents(true);
15683
+// if (object.editWindow == null)
15684
+// new Exception().printStackTrace();
15685
+// else
15686
+ object.GetWindow().refreshContents(true);
1454915687 break;
1455015688 case '{':
1455115689 manipCamera.shaper_fovy /= 1.1;
....@@ -14608,7 +15746,7 @@
1460815746 //mode = ROTATE;
1460915747 if ((MODIFIERS & COMMAND) == 0) // VR??
1461015748 {
14611
- SetMouseMode(modifiers);
15749
+ SetMouseMode(0, modifiers);
1461215750 }
1461315751 }
1461415752
....@@ -14742,8 +15880,9 @@
1474215880
1474315881 protected void processMouseMotionEvent(MouseEvent e)
1474415882 {
14745
- //System.out.println("processMouseMotionEvent: " + mouseMode);
14746
- if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15883
+ //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
15884
+ //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15885
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1474715886 {
1474815887 mouseMoved(e);
1474915888 } else
....@@ -14768,11 +15907,12 @@
1476815907 }
1476915908 */
1477015909
14771
- object.editWindow.EditSelection();
15910
+ object.GetWindow().EditSelection(false);
1477215911 }
1477315912
1477415913 void SelectParent()
1477515914 {
15915
+ new Exception().printStackTrace();
1477615916 System.exit(0);
1477715917 Composite group = (Composite) object;
1477815918 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -14784,10 +15924,10 @@
1478415924 {
1478515925 //selectees.remove(i);
1478615926 System.out.println("select parent of " + elem);
14787
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15927
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1478815928 } else
1478915929 {
14790
- group.editWindow.Select(elem.GetTreePath(), first, true);
15930
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1479115931 }
1479215932
1479315933 first = false;
....@@ -14796,6 +15936,7 @@
1479615936
1479715937 void SelectChildren()
1479815938 {
15939
+ new Exception().printStackTrace();
1479915940 System.exit(0);
1480015941 /*
1480115942 Composite group = (Composite) object;
....@@ -14828,12 +15969,12 @@
1482815969 for (int j = 0; j < group.children.size(); j++)
1482915970 {
1483015971 elem = (Object3D) group.children.elementAt(j);
14831
- object.editWindow.Select(elem.GetTreePath(), first, true);
15972
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1483215973 first = false;
1483315974 }
1483415975 } else
1483515976 {
14836
- object.editWindow.Select(elem.GetTreePath(), first, true);
15977
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1483715978 }
1483815979
1483915980 first = false;
....@@ -14844,21 +15985,21 @@
1484415985 {
1484515986 //Composite group = (Composite) object;
1484615987 Object3D group = object;
14847
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15988
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1484815989 }
1484915990
1485015991 void ResetTransform(int mask)
1485115992 {
1485215993 //Composite group = (Composite) object;
1485315994 Object3D group = object;
14854
- group.editWindow.ResetTransform(mask);
15995
+ group.GetWindow().ResetTransform(mask);
1485515996 }
1485615997
1485715998 void FlipTransform()
1485815999 {
1485916000 //Composite group = (Composite) object;
1486016001 Object3D group = object;
14861
- group.editWindow.FlipTransform();
16002
+ group.GetWindow().FlipTransform();
1486216003 // group.editWindow.ReduceMesh(true);
1486316004 }
1486416005
....@@ -14866,7 +16007,7 @@
1486616007 {
1486716008 //Composite group = (Composite) object;
1486816009 Object3D group = object;
14869
- group.editWindow.PrintMemory();
16010
+ group.GetWindow().PrintMemory();
1487016011 // group.editWindow.ReduceMesh(true);
1487116012 }
1487216013
....@@ -14874,7 +16015,7 @@
1487416015 {
1487516016 //Composite group = (Composite) object;
1487616017 Object3D group = object;
14877
- group.editWindow.ResetCentroid();
16018
+ group.GetWindow().ResetCentroid();
1487816019 }
1487916020
1488016021 void IncDepth()
....@@ -14956,11 +16097,11 @@
1495616097
1495716098 int width = getBounds().width;
1495816099 int height = getBounds().height;
14959
- ClickInfo info = new ClickInfo();
14960
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1496116100 //Image img = CreateImage(width, height);
1496216101 //System.out.println("width = " + width + "; height = " + height + "\n");
16102
+
1496316103 Graphics gr = g; // img.getGraphics();
16104
+
1496416105 if (!hasMarquee)
1496516106 {
1496616107 if (Xmin < Xmax) // !locked)
....@@ -15032,44 +16173,92 @@
1503216173 }
1503316174 if (object != null && !hasMarquee)
1503416175 {
16176
+ if (object.clickInfo == null)
16177
+ object.clickInfo = new ClickInfo();
16178
+ ClickInfo info = object.clickInfo;
16179
+ //ClickInfo info = new ClickInfo();
16180
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16181
+
1503516182 if (isRenderer)
1503616183 {
15037
- info.flags++;
16184
+ object.clickInfo.flags++;
1503816185 double frameAspect = (double) width / (double) height;
1503916186 if (frameAspect > renderCamera.aspect)
1504016187 {
1504116188 int desired = (int) ((double) height * renderCamera.aspect);
15042
- info.bounds.width -= width - desired;
15043
- info.bounds.x += (width - desired) / 2;
16189
+ object.clickInfo.bounds.width -= width - desired;
16190
+ object.clickInfo.bounds.x += (width - desired) / 2;
1504416191 } else
1504516192 {
1504616193 int desired = (int) ((double) width / renderCamera.aspect);
15047
- info.bounds.height -= height - desired;
15048
- info.bounds.y += (height - desired) / 2;
16194
+ object.clickInfo.bounds.height -= height - desired;
16195
+ object.clickInfo.bounds.y += (height - desired) / 2;
1504916196 }
1505016197 }
15051
- info.g = gr;
15052
- info.camera = renderCamera;
16198
+
16199
+ object.clickInfo.g = gr;
16200
+ object.clickInfo.camera = renderCamera;
1505316201 /*
1505416202 // Memory intensive (brep.verticescopy)
1505516203 if (!(object instanceof Composite))
1505616204 object.draw(info, 0, false); // SLOW :
1505716205 */
15058
- if (!isRenderer)
16206
+ if (!isRenderer) // && drag)
1505916207 {
15060
- object.drawEditHandles(info, 0);
16208
+ Grafreed.Assert(object != null);
16209
+ Grafreed.Assert(object.selection != null);
16210
+ if (object.selection.Size() > 0)
16211
+ {
16212
+ int hitSomething = object.selection.get(0).hitSomething;
16213
+
16214
+ object.clickInfo.DX = 0;
16215
+ object.clickInfo.DY = 0;
16216
+ object.clickInfo.W = 1;
16217
+ if (hitSomething == Object3D.hitCenter)
16218
+ {
16219
+ info.DX = X;
16220
+ if (X != 0)
16221
+ info.DX -= info.bounds.width/2;
16222
+
16223
+ info.DY = Y;
16224
+ if (Y != 0)
16225
+ info.DY -= info.bounds.height/2;
16226
+ }
16227
+
16228
+ object.drawEditHandles(//info,
16229
+ 0);
16230
+
16231
+ if (drag && (X != 0 || Y != 0))
16232
+ {
16233
+ switch (hitSomething)
16234
+ {
16235
+ case Object3D.hitCenter: gr.setColor(Color.white);
16236
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16237
+ break;
16238
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16239
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16240
+ break;
16241
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16242
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16243
+ break;
16244
+ }
16245
+
16246
+ }
16247
+ }
1506116248 }
1506216249 }
16250
+
1506316251 if (isRenderer)
1506416252 {
1506516253 //gr.setColor(Color.black);
1506616254 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1506716255 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1506816256 }
16257
+
1506916258 if (hasMarquee)
1507016259 {
1507116260 gr.setXORMode(Color.white);
15072
- gr.setColor(Color.red);
16261
+ gr.setColor(Color.white);
1507316262 if (!firstime)
1507416263 {
1507516264 gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH);
....@@ -15178,6 +16367,7 @@
1517816367 public boolean mouseDown(Event evt, int x, int y)
1517916368 {
1518016369 System.out.println("mouseDown: " + evt);
16370
+ System.exit(0);
1518116371 /*
1518216372 locked = true;
1518316373 drag = false;
....@@ -15221,7 +16411,7 @@
1522116411 {
1522216412 keyPressed(0, modifiers);
1522316413 }
15224
- clickStart(x, y, modifiers);
16414
+ // clickStart(x, y, modifiers);
1522516415 return true;
1522616416 }
1522716417
....@@ -15339,7 +16529,7 @@
1533916529 {
1534016530 keyReleased(0, 0);
1534116531 }
15342
- drag(x, y, modifiers);
16532
+ drag(x, y, 0, modifiers);
1534316533 return true;
1534416534 }
1534516535
....@@ -15471,7 +16661,7 @@
1547116661 Object3D object;
1547216662 static Object3D trackedobject;
1547316663 Camera renderCamera; // Light or Eye (or Occlusion)
15474
- /*static*/ Camera manipCamera; // Light or Eye
16664
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1547516665 /*static*/ Camera eyeCamera;
1547616666 /*static*/ Camera lightCamera;
1547716667 int cameracount;
....@@ -15535,6 +16725,8 @@
1553516725 private /*static*/ boolean firstime;
1553616726 private /*static*/ cVector newView = new cVector();
1553716727 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16728
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16729
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1553816730 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1553916731 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1554016732 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -15547,29 +16739,67 @@
1554716739 {
1554816740 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1554916741
16742
+ int usedsuf = 0;
16743
+
1555016744 for (int i = 0; i < suffixes.length; i++)
1555116745 {
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)
16746
+ String[] suffixe = suffixes;
16747
+ String[] fallback = suffixes2;
16748
+ String[] fallfallback = suffixes3;
16749
+
16750
+ for (int c=usedsuf; --c>=0;)
1555716751 {
15558
- throw new IOException("Unable to load texture " + resourceName);
16752
+// String[] temp = suffixe;
16753
+// suffixe = fallback;
16754
+// fallback = fallfallback;
16755
+// fallfallback = temp;
1555916756 }
16757
+
16758
+ String resourceName = basename + suffixe[i] + "." + suffix;
16759
+ TextureData data;
16760
+
16761
+ try
16762
+ {
16763
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16764
+ mipmapped,
16765
+ FileUtil.getFileSuffix(resourceName));
16766
+ }
16767
+ catch (Exception e)
16768
+ {
16769
+ try
16770
+ {
16771
+ resourceName = basename + fallback[i] + "." + suffix;
16772
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16773
+ mipmapped,
16774
+ FileUtil.getFileSuffix(resourceName));
16775
+ }
16776
+ catch (Exception e2)
16777
+ {
16778
+ resourceName = basename + fallfallback[i] + "." + suffix;
16779
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16780
+ mipmapped,
16781
+ FileUtil.getFileSuffix(resourceName));
16782
+ }
16783
+ }
16784
+
1556016785 //System.out.println("Target = " + targets[i]);
1556116786 cubemap.updateImage(data, targets[i]);
1556216787 }
1556316788
1556416789 return cubemap;
1556516790 }
16791
+
1556616792 int bigsphere = -1;
1556716793
1556816794 float BGcolor = 0.5f;
1556916795
15570
- private void DrawSkyBox(GL gl)
16796
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16797
+
16798
+ private void DrawSkyBox(GL gl, float ratio)
1557116799 {
15572
- if (envyoff || cubemap == null)
16800
+ if (//envyoff ||
16801
+ WIREFRAME ||
16802
+ cubemap == null)
1557316803 {
1557416804 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1557516805 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -15584,7 +16814,17 @@
1558416814 // Compensates for ExaminerViewer's modification of modelview matrix
1558516815 gl.glMatrixMode(GL.GL_MODELVIEW);
1558616816 gl.glLoadIdentity();
16817
+ gl.glScalef(1,ratio,1);
1558716818
16819
+// colorV[0] = 2;
16820
+// colorV[1] = 2;
16821
+// colorV[2] = 2;
16822
+// colorV[3] = 1;
16823
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16824
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16825
+//
16826
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16827
+
1558816828 //gl.glActiveTexture(GL.GL_TEXTURE1);
1558916829 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1559016830
....@@ -15616,6 +16856,7 @@
1561616856 {
1561716857 gl.glScalef(1.0f, -1.0f, 1.0f);
1561816858 }
16859
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1561916860 gl.glMultMatrixd(viewrot_1, 0);
1562016861 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1562116862 //viewer.updateInverseRotation(gl);
....@@ -15656,7 +16897,8 @@
1565616897 gl.glDisable(GL.GL_TEXTURE_GEN_R);
1565716898
1565816899 cubemap.disable();
15659
- ////cubemap.unbind();
16900
+ //cubemap.dispose();
16901
+
1566016902 if (CULLFACE)
1566116903 {
1566216904 gl.glEnable(gl.GL_CULL_FACE);
....@@ -15712,7 +16954,7 @@
1571216954 gl.glScalef(1.0f, -1.0f, 1.0f);
1571316955 }
1571416956
15715
- gl.glNormal3f(0.0f, 0.0f, 1.0f);
16957
+ SetGLNormal(gl, 0.0f, 0.0f, 1.0f);
1571616958
1571716959 float step = 2; // 0.1666f; //0.25f;
1571816960 float stepv = 2; // step * 1652 / 998;
....@@ -15756,16 +16998,16 @@
1575616998 cStatic.objectstack[materialdepth++] = checker;
1575716999 //System.out.println("material " + material);
1575817000 //Applet3D.tracein(this, selected);
15759
- vector2buffer = checker.projectedVertices;
17001
+ //vector2buffer = checker.projectedVertices;
1576017002
1576117003 //checker.GetMaterial().Draw(this, false); // true);
15762
- DrawMaterial(checker.GetMaterial(), false); // true);
17004
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1576317005
1576417006 materialdepth -= 1;
1576517007 if (materialdepth > 0)
1576617008 {
15767
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
15768
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
17009
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
17010
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1576917011 }
1577017012 //checker.GetMaterial().opacity = 1f;
1577117013 ////checker.GetMaterial().ambient = 1f;
....@@ -15851,6 +17093,14 @@
1585117093 }
1585217094 }
1585317095
17096
+ private Object3D GetFolder()
17097
+ {
17098
+ Object3D folder = object.GetWindow().copy;
17099
+ if (object.GetWindow().copy.selection.Size() > 0)
17100
+ folder = object.GetWindow().copy.selection.elementAt(0);
17101
+ return folder;
17102
+ }
17103
+
1585417104 class SelectBuffer implements GLEventListener
1585517105 {
1585617106
....@@ -15866,7 +17116,7 @@
1586617116 //new Exception().printStackTrace();
1586717117 System.out.println("select buffer init");
1586817118 // Use debug pipeline
15869
- drawable.setGL(new DebugGL(drawable.getGL()));
17119
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1587017120
1587117121 GL gl = drawable.getGL();
1587217122
....@@ -15909,6 +17159,7 @@
1590917159 {
1591017160 if (!selection)
1591117161 {
17162
+ new Exception().printStackTrace();
1591217163 System.exit(0);
1591317164 return;
1591417165 }
....@@ -15929,6 +17180,17 @@
1592917180
1593017181 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1593117182
17183
+ if (PAINTMODE)
17184
+ {
17185
+ if (object.GetWindow().copy.selection.Size() > 0)
17186
+ {
17187
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17188
+
17189
+ // Make what you paint not selectable.
17190
+ paintobj.ResetSelectable();
17191
+ }
17192
+ }
17193
+
1593217194 //int tmp = selection_view;
1593317195 //selection_view = -1;
1593417196 int temp = DrawMode();
....@@ -15940,6 +17202,17 @@
1594017202 // temp = DEFAULT; // patch for selection debug
1594117203 Globals.drawMode = temp; // WARNING
1594217204
17205
+ if (PAINTMODE)
17206
+ {
17207
+ if (object.GetWindow().copy.selection.Size() > 0)
17208
+ {
17209
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17210
+
17211
+ // Revert.
17212
+ paintobj.RestoreSelectable();
17213
+ }
17214
+ }
17215
+
1594317216 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1594417217
1594517218 // trying different ways of getting the depth info over
....@@ -15987,6 +17260,8 @@
1598717260 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1598817261 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1598917262 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
17263
+
17264
+ CreateSelectedPoint();
1599017265
1599117266 // Will fit the mesh !!!
1599217267 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16036,34 +17311,36 @@
1603617311 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]));
1603717312 }
1603817313
16039
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
17314
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1604017315 }
1604117316 }
1604217317
1604317318 if (!movingcamera && !PAINTMODE)
16044
- object.editWindow.ScreenFitPoint(); // fev 2014
17319
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1604517320
16046
- if (PAINTMODE && GrafreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17321
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1604717322 {
16048
- Object3D paintobj = GrafreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17323
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1604917324
16050
- Object3D group = new Object3D("inst" + paintcount++);
17325
+ if (object.GetWindow().copy.selection.Size() > 0)
17326
+ {
17327
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1605117328
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();
17329
+ Object3D inst = new Object3D("inst" + paintcount++);
17330
+
17331
+ inst.CreateMaterial(); // use a void leaf to select instances
17332
+
17333
+ inst.add(paintobj); // link
17334
+
17335
+ object.GetWindow().SnapObject(inst);
17336
+
17337
+ Object3D folder = paintFolder; // GetFolder();
17338
+
17339
+ folder.add(inst);
17340
+
17341
+ object.GetWindow().ResetModel();
17342
+ object.GetWindow().refreshContents();
17343
+ }
1606717344 }
1606817345 else
1606917346 paintcount = 0;
....@@ -16102,6 +17379,11 @@
1610217379 //System.out.println("objects[color] = " + objects[color]);
1610317380 //objects[color].Select();
1610417381 indexcount = 0;
17382
+ ObjEditor window = object.GetWindow();
17383
+ if (window != null && deselect)
17384
+ {
17385
+ window.Select(null, deselect, true);
17386
+ }
1610517387 object.Select(color, deselect);
1610617388 }
1610717389
....@@ -16152,6 +17434,7 @@
1615217434
1615317435 public void init(GLAutoDrawable drawable)
1615417436 {
17437
+ if (Globals.DEBUG)
1615517438 System.out.println("shadow buffer init");
1615617439
1615717440 GL gl = drawable.getGL();
....@@ -16201,7 +17484,7 @@
1620117484 gl.glDisable(gl.GL_CULL_FACE);
1620217485 }
1620317486
16204
- if (!RENDERSHADOW)
17487
+ if (!Globals.RENDERSHADOW)
1620517488 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1620617489
1620717490 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -16211,7 +17494,7 @@
1621117494 //gl.glColorMask(false, false, false, false);
1621217495
1621317496 //render_scene_from_light_view(gl, drawable, 0, 0);
16214
- if (RENDERSHADOW && Globals.lighttouched && !movingcamera) // && !parent.IsFreezed())
17497
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1621517498 {
1621617499 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1621717500
....@@ -16380,10 +17663,14 @@
1638017663 gl.glFlush();
1638117664
1638217665 /**/
16383
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17666
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1638417667
16385
- float[] pixels = occlusionsizebuffer.array();
17668
+ float[] depths = occlusiondepthbuffer.array();
1638617669
17670
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17671
+
17672
+ int[] pixels = selectsizebuffer.array();
17673
+
1638717674 double r = 0, g = 0, b = 0;
1638817675
1638917676 double count = 0;
....@@ -16394,7 +17681,7 @@
1639417681
1639517682 double FACTOR = 1;
1639617683
16397
- for (int i = 0; i < pixels.length; i++)
17684
+ for (int i = 0; i < depths.length; i++)
1639817685 {
1639917686 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1640017687 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -16477,7 +17764,7 @@
1647717764
1647817765 double scale = ray.z; // 1; // cos
1647917766
16480
- float depth = pixels[newindex];
17767
+ float depth = depths[newindex];
1648117768
1648217769 /*
1648317770 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -16627,23 +17914,15 @@
1662717914 int AAbuffersize = 0;
1662817915
1662917916 //double[] selectedpoint = new double[3];
16630
- static Superellipsoid selectedpoint = new Superellipsoid();
17917
+ static Superellipsoid selectedpoint;
1663117918 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();
17919
+ static Sphere debugpointG;
17920
+ static Sphere debugpointP;
17921
+ static Sphere debugpointC;
17922
+ static Sphere debugpointR;
1663617923
1663717924 static Sphere debugpoints[] = new Sphere[8];
1663817925
16639
- static
16640
- {
16641
- for (int i=0; i<8; i++)
16642
- {
16643
- debugpoints[i] = new Sphere();
16644
- }
16645
- }
16646
-
1664717926 static void InitPoints(float radius)
1664817927 {
1664917928 for (int i=0; i<8; i++)
....@@ -16682,11 +17961,14 @@
1668217961 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1668317962 static IntBuffer bigAAbuffer;
1668417963 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
16685
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17964
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1668617965 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1668717966 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1668817967 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
16689
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17968
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17969
+
17970
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17971
+
1669017972 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1669117973 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1669217974 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();
....@@ -16695,10 +17977,11 @@
1669517977 static IntBuffer textbuffer = null; // IntBuffer.allocate(TEXT_WIDTH*8*8 * TEXT_HEIGHT);
1669617978 // Depth buffer format
1669717979 //private int depth_format;
16698
- static public void NextIndex(Object3D o, GL gl)
17980
+
17981
+ public void NextIndex()
1669917982 {
1670017983 indexcount+=16;
16701
- gl.glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
17984
+ GetGL().glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
1670217985 //objects[indexcount] = o;
1670317986 //System.out.println("indexcount = " + indexcount);
1670417987 }