Normand Briere
2019-08-20 564f4d12d93813b5d680fc24d4f118c3886d96ed
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
....@@ -150,12 +190,25 @@
150190 defaultcaps.setAccumAlphaBits(16);
151191 }
152192
153
- static CameraPane theRenderer;
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
+ }
206
+ }
154207
155208 void SetAsGLRenderer(boolean b)
156209 {
157210 isRenderer = b;
158
- theRenderer = this;
211
+ Globals.theRenderer = this;
159212 }
160213
161214 CameraPane(Object3D o, Camera cam, boolean withcontext)
....@@ -170,7 +223,8 @@
170223
171224 SetCamera(cam);
172225
173
- SetLight(new Camera(new cVector(10, 10, -20)));
226
+ // Warning: not used.
227
+ SetLight(new Camera(new cVector(15, 10, -20)));
174228
175229 object = o;
176230
....@@ -193,9 +247,43 @@
193247
194248 /// INTERFACE
195249
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
+
196279 public boolean IsBoxMode()
197280 {
198281 return BOXMODE;
282
+ }
283
+
284
+ public boolean IsZoomBoxMode()
285
+ {
286
+ return ZOOMBOXMODE;
199287 }
200288
201289 public void ClearDepth()
....@@ -293,7 +381,7 @@
293381 cStatic.objectstack[materialdepth++] = obj;
294382 //System.out.println("material " + material);
295383 //Applet3D.tracein(this, selected);
296
- display.vector2buffer = obj.projectedVertices;
384
+ //display.vector2buffer = obj.projectedVertices;
297385 if (obj instanceof Camera)
298386 {
299387 display.options1[0] = material.shift;
....@@ -302,14 +390,28 @@
302390 display.options1[2] = material.shadowbias;
303391 display.options1[3] = material.aniso;
304392 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]);
305398 display.options2[0] = material.opacity;
306399 display.options2[1] = material.diffuse;
307400 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]);
308404
309405 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]);
310409 display.options4[0] = material.cameralight/0.2f;
311410 display.options4[1] = material.subsurface;
312411 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]);
313415
314416 // if (display.CURRENTANTIALIAS > 0)
315417 // display.options3[3] /= 4;
....@@ -325,7 +427,7 @@
325427 /**/
326428 } else
327429 {
328
- DrawMaterial(material, selected);
430
+ DrawMaterial(material, selected, obj.projectedVertices);
329431 }
330432 } else
331433 {
....@@ -349,8 +451,8 @@
349451 cStatic.objectstack[materialdepth++] = obj;
350452 //System.out.println("material " + material);
351453 //Applet3D.tracein("selected ", selected);
352
- display.vector2buffer = obj.projectedVertices;
353
- display.DrawMaterial(material, selected);
454
+ //display.vector2buffer = obj.projectedVertices;
455
+ display.DrawMaterial(material, selected, obj.projectedVertices);
354456 }
355457 }
356458
....@@ -367,8 +469,8 @@
367469 materialdepth -= 1;
368470 if (materialdepth > 0)
369471 {
370
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
371
- 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);
372474 }
373475 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
374476 } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
....@@ -388,8 +490,8 @@
388490 materialdepth -= 1;
389491 if (materialdepth > 0)
390492 {
391
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
392
- 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);
393495 }
394496 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
395497 //else
....@@ -430,10 +532,12 @@
430532 if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
431533 {
432534 //gl.glBegin(gl.GL_TRIANGLES);
433
- 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
+ ;
434538 if (!hasnorm)
435539 {
436
- // System.out.println("FUCK!!");
540
+ // System.out.println("Mesh normal");
437541 LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
438542 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
439543 LA.vecCross(obj.v0, obj.v1, obj.v2);
....@@ -816,7 +920,7 @@
816920
817921 if ((i % 100) == 0 && i != 0)
818922 {
819
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
923
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
820924 //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
821925 System.out.println((int) (100.0 * i / (br.positions.length / 3)) + "% (" + i + " of " + (br.positions.length / 3) + ")");
822926 }
....@@ -848,7 +952,7 @@
848952
849953 if ((i % 100) == 0 && i != 0)
850954 {
851
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
955
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
852956 //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
853957 System.out.println((int) (100.0 * i / br.VertexCount()) + "% (" + i + " of " + br.VertexCount() + ")");
854958 }
....@@ -1061,8 +1165,345 @@
10611165 gl.glMatrixMode(gl.GL_MODELVIEW);
10621166 }
10631167
1168
+ public void DrawBox(cVector min, cVector max)
1169
+ {
1170
+ javax.media.opengl.GL gl = GetGL();
1171
+ gl.glBegin(gl.GL_LINES);
1172
+
1173
+ gl.glVertex3d(min.x, min.y, min.z);
1174
+ gl.glVertex3d(min.x, min.y, max.z);
1175
+ gl.glVertex3d(min.x, min.y, min.z);
1176
+ gl.glVertex3d(min.x, max.y, min.z);
1177
+ gl.glVertex3d(min.x, min.y, min.z);
1178
+ gl.glVertex3d(max.x, min.y, min.z);
1179
+
1180
+ gl.glVertex3d(max.x, max.y, max.z);
1181
+ gl.glVertex3d(min.x, max.y, max.z);
1182
+ gl.glVertex3d(max.x, max.y, max.z);
1183
+ gl.glVertex3d(max.x, min.y, max.z);
1184
+ gl.glVertex3d(max.x, max.y, max.z);
1185
+ gl.glVertex3d(max.x, max.y, min.z);
1186
+
1187
+ gl.glEnd();
1188
+ }
1189
+
1190
+ public void DrawGeometry(BoundaryRep bRep, boolean flipV, boolean selectmode)
1191
+ {
1192
+ int[] strips = bRep.getRawIndices();
1193
+
1194
+ javax.media.opengl.GL gl = GetGL();
1195
+
1196
+ // TRIANGLE STRIP ARRAY
1197
+ if (bRep.trimmed)
1198
+ {
1199
+ float[] v = bRep.getRawVertices();
1200
+ float[] n = bRep.getRawNormals();
1201
+ float[] c = bRep.getRawColors();
1202
+ float[] uv = bRep.getRawUVMap();
1203
+
1204
+ int count2 = 0;
1205
+ int count3 = 0;
1206
+
1207
+ if (n.length > 0)
1208
+ {
1209
+ for (int i = 0; i < strips.length; i++)
1210
+ {
1211
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1212
+
1213
+ /*
1214
+ boolean locked = false;
1215
+ float eps = 0.1f;
1216
+ boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
1217
+
1218
+ int dot = 0;
1219
+
1220
+ if ((dot&1) == 0)
1221
+ dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
1222
+
1223
+ if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
1224
+ gl.glTexCoord2f((float) qv.s, (float) qv.t);
1225
+ else
1226
+ {
1227
+ locked = true;
1228
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1229
+ }
1230
+ //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
1231
+ gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
1232
+ if (hasnorm)
1233
+ {
1234
+ //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
1235
+ gl.glNormal3f((float) rv.norm.x, (float) rv.norm.y, (float) rv.norm.z);
1236
+ }
1237
+
1238
+ if ((dot&4) == 0)
1239
+ dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
1240
+
1241
+ if (wrap || !locked && (dot&8) != 0)
1242
+ gl.glTexCoord2f((float) rv.s, (float) rv.t);
1243
+ else
1244
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1245
+
1246
+ f.dot = dot;
1247
+ */
1248
+
1249
+ if (!selectmode)
1250
+ {
1251
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1252
+ {
1253
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1254
+ } else
1255
+ {
1256
+ gl.glNormal3f(0, 0, 1);
1257
+ }
1258
+
1259
+ if (c != null)
1260
+ //System.out.println("glcolor = " + c[count3] + ", " + c[count3+1] + ", " + c[count3+2]);
1261
+ {
1262
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1263
+ }
1264
+ }
1265
+
1266
+ if (flipV)
1267
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1268
+ else
1269
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1270
+
1271
+ //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1272
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1273
+
1274
+ count2 += 2;
1275
+ count3 += 3;
1276
+ if (!selectmode)
1277
+ {
1278
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1279
+ {
1280
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1281
+ } else
1282
+ {
1283
+ gl.glNormal3f(0, 0, 1);
1284
+ }
1285
+ if (c != null)
1286
+ {
1287
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1288
+ }
1289
+ }
1290
+
1291
+ if (flipV)
1292
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1293
+ else
1294
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1295
+
1296
+ //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1297
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1298
+
1299
+ count2 += 2;
1300
+ count3 += 3;
1301
+ for (int j = 0; j < strips[i] - 2; j++)
1302
+ {
1303
+ //gl.glTexCoord2d(...);
1304
+ if (!selectmode)
1305
+ {
1306
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1307
+ {
1308
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1309
+ } else
1310
+ {
1311
+ gl.glNormal3f(0, 0, 1);
1312
+ }
1313
+ if (c != null)
1314
+ {
1315
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1316
+ }
1317
+ }
1318
+
1319
+ if (flipV)
1320
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1321
+ else
1322
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1323
+
1324
+ //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
1325
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1326
+
1327
+ count2 += 2;
1328
+ count3 += 3;
1329
+ }
1330
+
1331
+ gl.glEnd();
1332
+ }
1333
+ }
1334
+
1335
+ assert count3 == v.length;
1336
+ }
1337
+ else // !trimmed
1338
+ {
1339
+ int count = 0;
1340
+ for (int i = 0; i < strips.length; i++)
1341
+ {
1342
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1343
+
1344
+ Vertex p = bRep.GetVertex(bRep.indices[count++]);
1345
+ Vertex q = bRep.GetVertex(bRep.indices[count++]);
1346
+
1347
+ drawVertex(gl, p, flipV, selectmode);
1348
+ drawVertex(gl, q, flipV, selectmode);
1349
+
1350
+ for (int j = 0; j < strips[i] - 2; j++)
1351
+ {
1352
+ Vertex r = bRep.GetVertex(bRep.indices[count++]);
1353
+
1354
+ // if (j%2 == 0)
1355
+ // drawFace(p, q, r, display, null);
1356
+ // else
1357
+ // drawFace(p, r, q, display, null);
1358
+
1359
+ // p = q;
1360
+ // q = r;
1361
+ drawVertex(gl, r, flipV, selectmode);
1362
+ }
1363
+
1364
+ gl.glEnd();
1365
+ }
1366
+ }
1367
+ }
1368
+
1369
+ static cSpring.Point3D temp = new cSpring.Point3D();
1370
+ static cSpring.Point3D temp2 = new cSpring.Point3D();
1371
+ static cSpring.Point3D temp3 = new cSpring.Point3D();
1372
+
1373
+ public void DrawDynamicMesh(cMesh mesh)
1374
+ {
1375
+ GL gl = GetGL(); // getGL();
1376
+
1377
+ cSpring.PhysicsController3D Phys = mesh.Phys;
1378
+
1379
+ gl.glDisable(gl.GL_LIGHTING);
1380
+
1381
+ gl.glLineWidth(1);
1382
+ gl.glColor3f(1,1,1);
1383
+ gl.glBegin(gl.GL_LINES);
1384
+ double scale = 0;
1385
+ int count = 0;
1386
+ for (int s=0; s<Phys.allSprings.size(); s++)
1387
+ {
1388
+ cSpring.Spring spring = Phys.allSprings.get(s);
1389
+ if(s == 0)
1390
+ {
1391
+ //System.out.println(" spring : " + spring.a.position + "; " + spring.b.position);
1392
+ }
1393
+ if (mesh.showsprings)
1394
+ {
1395
+ temp.set(spring.a.position);
1396
+ temp.add(spring.b.position);
1397
+ temp.mul(0.5);
1398
+ temp2.set(spring.a.position);
1399
+ temp2.sub(spring.b.position);
1400
+ temp2.mul(spring.restLength/2);
1401
+ temp.sub(temp2);
1402
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1403
+ temp.add(temp2);
1404
+ temp.add(temp2);
1405
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1406
+ }
1407
+
1408
+ if (spring.isHandle)
1409
+ continue;
1410
+
1411
+ //if (scale < spring.restLength)
1412
+ scale += spring.restLength;
1413
+ count++;
1414
+ }
1415
+ gl.glEnd();
1416
+
1417
+ if (count == 0)
1418
+ scale = 0.01;
1419
+ else
1420
+ scale /= count * 3;
1421
+
1422
+ //scale = 0.25;
1423
+
1424
+ if (mesh.ShowInfo())
1425
+ {
1426
+ gl.glLineWidth(4);
1427
+ for (int s=0; s<Phys.allNodes.size(); s++)
1428
+ {
1429
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1430
+ if (node.mass == 0)
1431
+ continue;
1432
+
1433
+ int i = node.springs==null?-1:node.springs.size();
1434
+ gl.glColor3f((i>>2)&1,(i>>1)&1,i&1);
1435
+ //temp.set(node.springForce.x, node.springForce.y, node.springForce.z);
1436
+ //temp.normalize();
1437
+ //gl.glColor3d((temp.x+1)/2, (temp.y+1)/2, (temp.z+1)/2);
1438
+ gl.glBegin(gl.GL_LINES);
1439
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1440
+ //gl.glVertex3d(node.position.x + node.normal.x*scale, node.position.y + node.normal.y*scale, node.position.z + node.normal.z*scale);
1441
+ gl.glVertex3d(node.position.x + mesh.bRep.GetVertex(s).norm.x*scale,
1442
+ node.position.y + mesh.bRep.GetVertex(s).norm.y*scale,
1443
+ node.position.z + mesh.bRep.GetVertex(s).norm.z*scale);
1444
+ gl.glEnd();
1445
+ }
1446
+
1447
+ gl.glLineWidth(8);
1448
+ for (int s=0; s<Phys.allNodes.size(); s++)
1449
+ {
1450
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1451
+
1452
+ if (node.springs != null)
1453
+ {
1454
+ for (int i=0; i<node.springs.size(); i+=1)
1455
+ {
1456
+ cSpring.DynamicNode f = node.springs.get(i).GetOther(node);
1457
+
1458
+ int c = i+1;
1459
+ // c = node.springs.get(i).nbcopies;
1460
+
1461
+ gl.glColor3f((c>>2)&1,(c>>1)&1,c&1);
1462
+ gl.glBegin(gl.GL_LINES);
1463
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1464
+ gl.glVertex3d(f.position.x/3+node.position.x*2/3, f.position.y/3+node.position.y*2/3, f.position.z/3+node.position.z*2/3);
1465
+ gl.glEnd();
1466
+ }
1467
+ }
1468
+ }
1469
+
1470
+ gl.glLineWidth(1);
1471
+ }
1472
+
1473
+ gl.glEnable(gl.GL_LIGHTING);
1474
+ }
1475
+
10641476 /// INTERFACE
10651477
1478
+ public void StartTriangles()
1479
+ {
1480
+ javax.media.opengl.GL gl = GetGL();
1481
+ gl.glBegin(gl.GL_TRIANGLES);
1482
+ }
1483
+
1484
+ public void EndTriangles()
1485
+ {
1486
+ GetGL().glEnd();
1487
+ }
1488
+
1489
+ void drawVertex(javax.media.opengl.GL gl, Vertex pv, boolean flipV, boolean selectmode)
1490
+ {
1491
+ if (!selectmode)
1492
+ {
1493
+ gl.glNormal3f((float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
1494
+ gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
1495
+
1496
+ if (flipV)
1497
+ gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
1498
+ else
1499
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1500
+ }
1501
+
1502
+ gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
1503
+ }
1504
+
1505
+ float[] colorV = new float[4];
1506
+
10661507 void SetColor(Object3D obj, Vertex p0)
10671508 {
10681509 CameraPane display = this;
....@@ -1130,8 +1571,6 @@
11301571 {
11311572 return;
11321573 }
1133
-
1134
- float[] colorV = new float[3];
11351574
11361575 if (false) // marked)
11371576 {
....@@ -1240,7 +1679,7 @@
12401679 // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
12411680 }
12421681
1243
- void DrawMaterial(cMaterial material, boolean selected)
1682
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
12441683 {
12451684 CameraPane display = this;
12461685 //new Exception().printStackTrace();
....@@ -1256,18 +1695,18 @@
12561695 //col.getColorComponents(ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB), CameraPane.modelParams0);
12571696 if (!material.multiply)
12581697 {
1259
- display.color = color;
1698
+ display.color = material.color;
12601699 display.saturation = material.modulation;
12611700 }
12621701 else
12631702 {
1264
- display.color *= color*2;
1703
+ display.color *= material.color*2;
12651704 display.saturation *= material.modulation*2;
12661705 }
12671706
12681707 cColor.HSBtoRGB(display.color, display.saturation, 1, display.modelParams0);
12691708
1270
- float[] colorV = GrafreeD.colorV;
1709
+ float[] colorV = Grafreed.colorV;
12711710
12721711 /**/
12731712 if (display.DrawMode() == display.DEFAULT) // && display.RENDERPROGRAM == 0)
....@@ -1275,7 +1714,7 @@
12751714 colorV[0] = display.modelParams0[0] * material.diffuse;
12761715 colorV[1] = display.modelParams0[1] * material.diffuse;
12771716 colorV[2] = display.modelParams0[2] * material.diffuse;
1278
- colorV[3] = material.opacity;
1717
+ colorV[3] = 1; // material.opacity;
12791718
12801719 gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
12811720 //System.out.println("Opacity = " + opacity);
....@@ -1380,12 +1819,12 @@
13801819
13811820 display.modelParams7[0] = 0;
13821821 display.modelParams7[1] = 1000;
1383
- display.modelParams7[2] = 0;
1822
+ display.modelParams7[2] = material.parallax;
13841823 display.modelParams7[3] = 0;
13851824
1386
- display.modelParams6[0] = 100; // criss de bug de bump
1825
+ //display.modelParams6[0] = 100; // criss de bug de bump
13871826
1388
- Object3D.cVector2[] extparams = display.vector2buffer;
1827
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
13891828 if (extparams != null && extparams.length > 0 && extparams[0] != null)
13901829 {
13911830 display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
....@@ -1527,7 +1966,7 @@
15271966 void PushMatrix(double[][] matrix)
15281967 {
15291968 // GrafreeD.tracein(matrix);
1530
- PushMatrix(matrix,1);
1969
+ PushMatrix(matrix, 1);
15311970 }
15321971
15331972 void PushMatrix()
....@@ -1613,9 +2052,9 @@
16132052 switch(viewcode)
16142053 {
16152054 case 0: return "main";
1616
- case 1: return "one";
1617
- case 2: return "two";
1618
- case 3: return "three";
2055
+ case 1: return "Red";
2056
+ case 2: return "Green";
2057
+ case 3: return "Blue";
16192058 case 4: return "light";
16202059 }
16212060
....@@ -1624,7 +2063,7 @@
16242063
16252064 static int camerachangeframe;
16262065
1627
- boolean SetCamera(Camera cam)
2066
+ public boolean SetCamera(Camera cam)
16282067 {
16292068 // may 2014 if (cam == cameras[0] || cam == cameras[1])
16302069 // return false;
....@@ -1681,7 +2120,7 @@
16812120 //System.err.println("Oeil on");
16822121 OEIL = true;
16832122 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
1684
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2123
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
16852124 //pingthread.StepToTarget(true);
16862125 }
16872126
....@@ -1752,33 +2191,6 @@
17522191 mainDL ^= true;
17532192 }
17542193
1755
- void ToggleTexture()
1756
- {
1757
- textureon ^= true;
1758
- }
1759
-
1760
- void ToggleLive()
1761
- {
1762
- Globals.setLIVE(Globals.isLIVE() ^ true);
1763
-
1764
- System.err.println("LIVE = " + Globals.isLIVE());
1765
-
1766
- if (!Globals.isLIVE()) // save sound
1767
- GrafreeD.savesound = true; // wav.save();
1768
- // else
1769
- repaint(); // start loop // may 2013
1770
- }
1771
-
1772
- void ToggleSupport()
1773
- {
1774
- SUPPORT ^= true;
1775
- }
1776
-
1777
- void ToggleAbort()
1778
- {
1779
- ABORTMODE ^= true;
1780
- }
1781
-
17822194 void ToggleFullScreen()
17832195 {
17842196 FULLSCREEN ^= true;
....@@ -1789,72 +2201,94 @@
17892201 Globals.CROWD ^= true;
17902202 }
17912203
1792
- void ToggleInertia()
1793
- {
1794
- INERTIA ^= true;
1795
- }
1796
-
17972204 void ToggleLocal()
17982205 {
17992206 LOCALTRANSFORM ^= true;
18002207 }
18012208
1802
- void ToggleFast()
2209
+ public void ToggleTexture()
2210
+ {
2211
+ textureon ^= true;
2212
+ }
2213
+
2214
+ public void ToggleLive()
2215
+ {
2216
+ Globals.setLIVE(Globals.isLIVE() ^ true);
2217
+
2218
+ System.err.println("LIVE = " + Globals.isLIVE());
2219
+
2220
+ if (!Globals.isLIVE()) // save sound
2221
+ Grafreed.savesound = true; // wav.save();
2222
+ // else
2223
+ repaint(); // start loop // may 2013
2224
+ }
2225
+
2226
+ public void ToggleSupport()
2227
+ {
2228
+ SUPPORT ^= true;
2229
+ }
2230
+
2231
+ public void ToggleAbort()
2232
+ {
2233
+ ABORTMODE ^= true;
2234
+ }
2235
+
2236
+ public void ToggleInertia()
2237
+ {
2238
+ INERTIA ^= true;
2239
+ }
2240
+
2241
+ public void ToggleFast()
18032242 {
18042243 FAST ^= true;
18052244 }
18062245
1807
- void ToggleSlowPose()
2246
+ public void ToggleSlowPose()
18082247 {
18092248 SLOWPOSE ^= true;
18102249 }
18112250
1812
- void ToggleFootContact()
1813
- {
1814
- FOOTCONTACT ^= true;
1815
- }
1816
-
1817
- void ToggleBoxMode()
2251
+ public void ToggleBoxMode()
18182252 {
18192253 BOXMODE ^= true;
18202254 }
18212255
1822
- void ToggleSmoothFocus()
2256
+ public void ToggleZoomBoxMode()
2257
+ {
2258
+ ZOOMBOXMODE ^= true;
2259
+ }
2260
+
2261
+ public void ToggleSmoothFocus()
18232262 {
18242263 SMOOTHFOCUS ^= true;
18252264 }
18262265
1827
- void ToggleImageFlip()
2266
+ public void ToggleImageFlip()
18282267 {
18292268 IMAGEFLIP ^= true;
18302269 }
18312270
1832
- void ToggleSpeakerMocap()
2271
+ public void ToggleSpeakerMocap()
18332272 {
18342273 SPEAKERMOCAP ^= true;
18352274 }
18362275
1837
- void ToggleSpeakerCamera()
2276
+ public void ToggleSpeakerCamera()
18382277 {
18392278 SPEAKERCAMERA ^= true;
18402279 }
18412280
1842
- void ToggleSpeakerFocus()
2281
+ public void ToggleSpeakerFocus()
18432282 {
18442283 SPEAKERFOCUS ^= true;
18452284 }
18462285
1847
- void ToggleDebug()
1848
- {
1849
- DEBUG ^= true;
1850
- }
1851
-
1852
- void ToggleFrustum()
2286
+ public void ToggleFrustum()
18532287 {
18542288 FRUSTUM ^= true;
18552289 }
18562290
1857
- void ToggleTrack()
2291
+ public void ToggleTrack()
18582292 {
18592293 TRACK ^= true;
18602294 if (TRACK)
....@@ -1873,25 +2307,35 @@
18732307 repaint();
18742308 }
18752309
1876
- void ToggleTrackOnce()
2310
+ public void ToggleTrackOnce()
18772311 {
18782312 TRACKONCE ^= true;
18792313 }
18802314
1881
- void ToggleShadowTrack()
2315
+ public void ToggleShadowTrack()
18822316 {
18832317 SHADOWTRACK ^= true;
18842318 repaint();
18852319 }
18862320
1887
- void ToggleOeil()
2321
+ public void ToggleOeil()
18882322 {
18892323 OEIL ^= true;
18902324 }
18912325
1892
- void ToggleOeilOnce()
2326
+ public void ToggleOeilOnce()
18932327 {
18942328 OEILONCE ^= true;
2329
+ }
2330
+
2331
+ void ToggleFootContact()
2332
+ {
2333
+ FOOTCONTACT ^= true;
2334
+ }
2335
+
2336
+ void ToggleDebug()
2337
+ {
2338
+ Globals.DEBUG ^= true;
18952339 }
18962340
18972341 void ToggleLookAt()
....@@ -1899,9 +2343,9 @@
18992343 LOOKAT ^= true;
19002344 }
19012345
1902
- void ToggleRandom()
2346
+ void ToggleSwitch()
19032347 {
1904
- RANDOM ^= true;
2348
+ SWITCH ^= true;
19052349 }
19062350
19072351 void ToggleHandles()
....@@ -1909,10 +2353,17 @@
19092353 HANDLES ^= true;
19102354 }
19112355
2356
+ Object3D paintFolder;
2357
+
19122358 void TogglePaint()
19132359 {
19142360 PAINTMODE ^= true;
19152361 paintcount = 0;
2362
+
2363
+ if (PAINTMODE)
2364
+ {
2365
+ paintFolder = GetFolder();
2366
+ }
19162367 }
19172368
19182369 void SwapCamera(int a, int b)
....@@ -2008,7 +2459,22 @@
20082459 {
20092460 return currentGL;
20102461 }
2011
-
2462
+
2463
+ static private BufferedImage CreateBim(TextureData texturedata)
2464
+ {
2465
+ Grafreed.Assert(texturedata != null);
2466
+
2467
+ int width = texturedata.getWidth();
2468
+ int height = texturedata.getHeight();
2469
+
2470
+ Buffer buffer = texturedata.getBuffer();
2471
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2472
+
2473
+ byte[] bytes = bytebuf.array();
2474
+
2475
+ return CreateBim(bytes, width, height);
2476
+ }
2477
+
20122478 /**/
20132479 class CacheTexture
20142480 {
....@@ -2017,28 +2483,31 @@
20172483
20182484 int resolution;
20192485
2020
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2486
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
20212487 {
2022
- texture = tex;
2488
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2489
+ texturedata = texdata;
20232490 resolution = res;
20242491 }
20252492 }
20262493 /**/
20272494
20282495 // TEXTURE static Texture texture;
2029
- static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures
2030
- = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>();
2031
- static public java.util.Hashtable<String, String> usedtextures = new java.util.Hashtable<String, String>();
2496
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2497
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2498
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2499
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2500
+
20322501 int pigmentdepth = 0;
20332502 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
20342503 int bumpdepth = 0;
20352504 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
20362505 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
20372506 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2038
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2507
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
20392508 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
20402509
2041
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2510
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
20422511 {
20432512 TextureData texturedata = null;
20442513
....@@ -2048,7 +2517,7 @@
20482517 com.sun.opengl.util.texture.TextureIO.newTextureData(
20492518 getClass().getClassLoader().getResourceAsStream(name),
20502519 true,
2051
- com.sun.opengl.util.texture.TextureIO.PNG);
2520
+ GetFormat(name)); // com.sun.opengl.util.texture.TextureIO.PNG);
20522521 } catch (java.io.IOException e)
20532522 {
20542523 throw new javax.media.opengl.GLException(e);
....@@ -2057,13 +2526,34 @@
20572526 if (bump)
20582527 texturedata = ConvertBump(texturedata, false);
20592528
2060
- com.sun.opengl.util.texture.Texture texture =
2061
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2529
+// com.sun.opengl.util.texture.Texture texture =
2530
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
20622531
2063
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2064
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
2532
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2533
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
20652534
2066
- return texture;
2535
+ return texturedata;
2536
+ }
2537
+
2538
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2539
+ {
2540
+ TextureData texturedata = null;
2541
+
2542
+ try
2543
+ {
2544
+ texturedata =
2545
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2546
+ bim,
2547
+ true);
2548
+ } catch (Exception e)
2549
+ {
2550
+ throw new javax.media.opengl.GLException(e);
2551
+ }
2552
+
2553
+ if (bump)
2554
+ texturedata = ConvertBump(texturedata, false);
2555
+
2556
+ return texturedata;
20672557 }
20682558
20692559 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3136,6 +3626,8 @@
31363626
31373627 System.out.println("LOADING TEXTURE : " + name);
31383628
3629
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3630
+
31393631 //
31403632 if (false) // compressbit > 0)
31413633 {
....@@ -3840,6 +4332,7 @@
38404332
38414333 com.sun.opengl.util.texture.Texture CompressTexture2(String name)
38424334 {
4335
+ new Exception().printStackTrace();
38434336 System.exit(0);
38444337 com.sun.opengl.util.texture.Texture texture = null;
38454338
....@@ -7533,7 +8026,7 @@
75338026 String pigment = Object3D.GetPigment(tex);
75348027 String bump = Object3D.GetBump(tex);
75358028
7536
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8029
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
75378030 {
75388031 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
75398032 // System.out.println("; bump = " + bump);
....@@ -7548,11 +8041,69 @@
75488041 pigment = null;
75498042 }
75508043
7551
- ReleaseTexture(bump, true);
7552
- ReleaseTexture(pigment, false);
8044
+ ReleaseTexture(tex, true);
8045
+ ReleaseTexture(tex, false);
75538046 }
75548047
7555
- void ReleaseTexture(String tex, boolean bump)
8048
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
8049
+ {
8050
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8051
+ {
8052
+ return;
8053
+ }
8054
+
8055
+ if (tex == null)
8056
+ {
8057
+ ReleaseTexture(null, false);
8058
+ return;
8059
+ }
8060
+
8061
+ String pigment = Object3D.GetPigment(tex);
8062
+
8063
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8064
+ {
8065
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8066
+ // System.out.println("; bump = " + bump);
8067
+ }
8068
+
8069
+ if (pigment.equals(""))
8070
+ {
8071
+ pigment = null;
8072
+ }
8073
+
8074
+ ReleaseTexture(tex, false);
8075
+ }
8076
+
8077
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
8078
+ {
8079
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8080
+ {
8081
+ return;
8082
+ }
8083
+
8084
+ if (tex == null)
8085
+ {
8086
+ ReleaseTexture(null, true);
8087
+ return;
8088
+ }
8089
+
8090
+ String bump = Object3D.GetBump(tex);
8091
+
8092
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8093
+ {
8094
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8095
+ // System.out.println("; bump = " + bump);
8096
+ }
8097
+
8098
+ if (bump.equals(""))
8099
+ {
8100
+ bump = null;
8101
+ }
8102
+
8103
+ ReleaseTexture(tex, true);
8104
+ }
8105
+
8106
+ void ReleaseTexture(cTexture tex, boolean bump)
75568107 {
75578108 if (// DrawMode() != 0 || /*tex == null ||*/
75588109 ambientOcclusion ) // || !textureon)
....@@ -7563,7 +8114,7 @@
75638114 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
75648115
75658116 if (tex != null)
7566
- texture = textures.get(tex);
8117
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
75678118
75688119 // //assert( texture != null );
75698120 // if (texture == null)
....@@ -7655,7 +8206,55 @@
76558206 }
76568207 }
76578208
7658
- /*boolean*/ public void BindTextures(cTexture tex, int resolution) // INTERFACE
8209
+ /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
8210
+ {
8211
+// if (// DrawMode() != 0 || /*tex == null ||*/
8212
+// ambientOcclusion ) // || !textureon)
8213
+// {
8214
+// return; // false;
8215
+// }
8216
+//
8217
+// if (tex == null)
8218
+// {
8219
+// BindTexture(null,false,resolution);
8220
+// BindTexture(null,true,resolution);
8221
+// return;
8222
+// }
8223
+//
8224
+// String pigment = Object3D.GetPigment(tex);
8225
+// String bump = Object3D.GetBump(tex);
8226
+//
8227
+// usedtextures.add(pigment);
8228
+// usedtextures.add(bump);
8229
+//
8230
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8231
+// {
8232
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8233
+// // System.out.println("; bump = " + bump);
8234
+// }
8235
+//
8236
+// if (bump.equals(""))
8237
+// {
8238
+// bump = null;
8239
+// }
8240
+// if (pigment.equals(""))
8241
+// {
8242
+// pigment = null;
8243
+// }
8244
+//
8245
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8246
+// BindTexture(pigment, false, resolution);
8247
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8248
+// BindTexture(bump, true, resolution);
8249
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8250
+//
8251
+// return; // true;
8252
+
8253
+ BindPigmentTexture(tex, resolution);
8254
+ BindBumpTexture(tex, resolution);
8255
+ }
8256
+
8257
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
76598258 {
76608259 if (// DrawMode() != 0 || /*tex == null ||*/
76618260 ambientOcclusion ) // || !textureon)
....@@ -7666,17 +8265,47 @@
76668265 if (tex == null)
76678266 {
76688267 BindTexture(null,false,resolution);
7669
- BindTexture(null,true,resolution);
76708268 return;
76718269 }
76728270
76738271 String pigment = Object3D.GetPigment(tex);
8272
+
8273
+ usedtextures.add(tex);
8274
+
8275
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8276
+ {
8277
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8278
+ // System.out.println("; bump = " + bump);
8279
+ }
8280
+
8281
+ if (pigment.equals(""))
8282
+ {
8283
+ pigment = null;
8284
+ }
8285
+
8286
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8287
+ BindTexture(tex, false, resolution);
8288
+ }
8289
+
8290
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8291
+ {
8292
+ if (// DrawMode() != 0 || /*tex == null ||*/
8293
+ ambientOcclusion ) // || !textureon)
8294
+ {
8295
+ return; // false;
8296
+ }
8297
+
8298
+ if (tex == null)
8299
+ {
8300
+ BindTexture(null,true,resolution);
8301
+ return;
8302
+ }
8303
+
76748304 String bump = Object3D.GetBump(tex);
76758305
7676
- usedtextures.put(pigment, pigment);
7677
- usedtextures.put(bump, bump);
8306
+ usedtextures.add(tex);
76788307
7679
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8308
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
76808309 {
76818310 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
76828311 // System.out.println("; bump = " + bump);
....@@ -7686,43 +8315,94 @@
76868315 {
76878316 bump = null;
76888317 }
7689
- if (pigment.equals(""))
7690
- {
7691
- pigment = null;
7692
- }
76938318
7694
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
7695
- BindTexture(pigment, false, resolution);
76968319 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
7697
- BindTexture(bump, true, resolution);
8320
+ BindTexture(tex, true, resolution);
76988321 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
7699
-
7700
- return; // true;
77018322 }
77028323
7703
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution)
8324
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8325
+
8326
+ private boolean FileExists(String tex)
77048327 {
7705
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8328
+ if (missingTextures.contains(tex))
8329
+ {
8330
+ return false;
8331
+ }
8332
+
8333
+ boolean fileExists = new File(tex).exists();
8334
+
8335
+ if (!fileExists)
8336
+ {
8337
+ // If file exists, the "new File()" is not executed sgain
8338
+ missingTextures.add(tex);
8339
+ }
8340
+
8341
+ return fileExists;
8342
+ }
8343
+
8344
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
8345
+ {
8346
+ CacheTexture texturecache = null;
77068347
77078348 if (tex != null)
77088349 {
7709
- String texname = tex;
8350
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8351
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
77108352
7711
- String[] split = tex.split("Textures");
7712
- if (split.length > 1)
7713
- texname = "/Users/nbriere/Textures" + split[split.length-1];
7714
- else
7715
- if (!texname.startsWith("/"))
7716
- texname = "/Users/nbriere/Textures/" + texname;
8353
+ if (texname.equals("") && texdata == null)
8354
+ {
8355
+ return null;
8356
+ }
8357
+
8358
+ String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
8359
+
8360
+// String[] split = tex.split("Textures");
8361
+// if (split.length > 1)
8362
+// texname = "/Users/nbriere/Textures" + split[split.length-1];
8363
+// else
8364
+// if (!texname.startsWith("/"))
8365
+// texname = "/Users/nbriere/Textures/" + texname;
8366
+ if (!FileExists(texname) && !texname.startsWith("@"))
8367
+ {
8368
+ texname = fallbackTextureName;
8369
+ }
77178370
77188371 if (CACHETEXTURE)
7719
- texture = textures.get(texname); // TEXTURE CACHE
7720
-
7721
- TextureData texturedata = null;
7722
-
7723
- if (texture == null || texture.resolution < resolution)
77248372 {
7725
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8373
+ if (texdata == null)
8374
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8375
+ else
8376
+ texturecache = bimtextures.get(texdata);
8377
+ }
8378
+
8379
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8380
+ {
8381
+ TextureData texturedata = null;
8382
+
8383
+ if (texdata != null && textureon)
8384
+ {
8385
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8386
+
8387
+ try
8388
+ {
8389
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8390
+ }
8391
+ catch (Exception e)
8392
+ {
8393
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8394
+ }
8395
+
8396
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8397
+ bimtextures.put(texdata, texturecache);
8398
+
8399
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8400
+
8401
+ //Object bim2 = CreateBim(texturecache.texturedata);
8402
+ //bim2 = bim;
8403
+ }
8404
+ else
8405
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
77268406 {
77278407 assert(!bump);
77288408 // if (bump)
....@@ -7733,19 +8413,23 @@
77338413 // }
77348414 // else
77358415 // {
7736
- texture = textures.get(tex);
7737
- if (texture == null)
8416
+ // texturecache = textures.get(texname); // suspicious
8417
+ if (texturecache == null)
77388418 {
7739
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8419
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
77408420 }
8421
+ else
8422
+ new Exception().printStackTrace();
77418423 // }
77428424 } else
7743
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8425
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
77448426 {
77458427 assert(bump);
7746
- texture = textures.get(tex);
7747
- if (texture == null)
7748
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8428
+ // texturecache = textures.get(texname); // suspicious
8429
+ if (texturecache == null)
8430
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8431
+ else
8432
+ new Exception().printStackTrace();
77498433 } else
77508434 {
77518435 //if (tex.equals("IMMORTAL"))
....@@ -7753,11 +8437,22 @@
77538437 // texture = GetResourceTexture("default.png");
77548438 //} else
77558439 //{
7756
- if (tex.equals("WHITE_NOISE"))
8440
+ if (texname.endsWith("WHITE_NOISE"))
77578441 {
7758
- texture = textures.get(tex);
7759
- if (texture == null)
7760
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8442
+ // texturecache = textures.get(texname); // suspicious
8443
+ if (texturecache == null)
8444
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8445
+ else
8446
+ new Exception().printStackTrace();
8447
+ } else
8448
+ {
8449
+ if (texname.startsWith("@"))
8450
+ {
8451
+ // texturecache = textures.get(texname); // suspicious
8452
+ if (texturecache == null)
8453
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8454
+ else
8455
+ new Exception().printStackTrace();
77618456 } else
77628457 {
77638458 if (textureon)
....@@ -7782,7 +8477,7 @@
77828477 }
77838478
77848479 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
7785
- if (!new File(cachename).exists())
8480
+ if (!FileExists(cachename))
77868481 cachename = texname;
77878482 else
77888483 processbump = false; // don't process bump map again
....@@ -7804,7 +8499,7 @@
78048499 }
78058500
78068501 cachename = texname.substring(0, texname.length()-4)+ext+".png";
7807
- if (!new File(cachename).exists())
8502
+ if (!FileExists(cachename))
78088503 cachename = texname;
78098504 else
78108505 processbump = false; // don't process bump map again
....@@ -7813,20 +8508,23 @@
78138508 texturedata = GetFileTexture(cachename, processbump, resolution);
78148509
78158510
7816
- if (texturedata != null)
7817
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8511
+ if (texturedata == null)
8512
+ throw new Exception();
8513
+
8514
+ texturecache = new CacheTexture(texturedata,resolution);
78188515 //texture = GetTexture(tex, bump);
78198516 }
8517
+ }
78208518 }
78218519 //}
78228520 }
78238521
7824
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8522
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
78258523 {
78268524 //return false;
78278525
78288526 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
7829
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8527
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
78308528 {
78318529 // String ext = "_highres";
78328530 // if (REDUCETEXTURE)
....@@ -7843,52 +8541,17 @@
78438541 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
78448542 if (!cachefile.exists())
78458543 {
7846
- // cache to disk
7847
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
7848
- //buffers[0].
7849
-
7850
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
7851
- int[] pixels = new int[bytebuf.capacity()/3];
7852
-
7853
- // squared size heuristic...
7854
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8544
+ //if (texturedata.getWidth() == texturedata.getHeight())
78558545 {
7856
- for (int i=pixels.length; --i>=0;)
7857
- {
7858
- int i3 = i*3;
7859
- pixels[i] = 0xFF;
7860
- pixels[i] <<= 8;
7861
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
7862
- pixels[i] <<= 8;
7863
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
7864
- pixels[i] <<= 8;
7865
- pixels[i] |= bytebuf.get(i3) & 0xFF;
7866
- }
7867
-
7868
- /*
7869
- int r=0,g=0,b=0,a=0;
7870
- for (int i=0; i<width; i++)
7871
- for (int j=0; j<height; j++)
7872
- {
7873
- int index = j*width+i;
7874
- int p = pixels[index];
7875
- a = ((p>>24) & 0xFF);
7876
- r = ((p>>16) & 0xFF);
7877
- g = ((p>>8) & 0xFF);
7878
- b = (p & 0xFF);
7879
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
7880
- }
7881
- /**/
7882
- int width = (int)Math.sqrt(pixels.length); // squared
7883
- int height = width;
7884
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
7885
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8546
+ BufferedImage rendImage = CreateBim(texturedata);
8547
+
78868548 ImageWriter writer = null;
78878549 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
78888550 if (iter.hasNext()) {
78898551 writer = (ImageWriter)iter.next();
78908552 }
7891
- float compressionQuality = 0.9f;
8553
+
8554
+ float compressionQuality = 0.85f;
78928555 try
78938556 {
78948557 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -7905,18 +8568,20 @@
79058568 }
79068569 }
79078570 }
7908
-
8571
+
8572
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8573
+
79098574 //System.out.println("Texture = " + tex);
7910
- if (textures.containsKey(texname))
8575
+ if (textures.containsKey(tex))
79118576 {
7912
- CacheTexture thetex = textures.get(texname);
8577
+ CacheTexture thetex = textures.get(tex);
79138578 thetex.texture.disable();
79148579 thetex.texture.dispose();
7915
- textures.remove(texname);
8580
+ textures.remove(tex);
79168581 }
79178582
7918
- texture.texturedata = texturedata;
7919
- textures.put(texname, texture);
8583
+ //texture.texturedata = texturedata;
8584
+ textures.put(tex, texturecache);
79208585
79218586 // newtex = true;
79228587 }
....@@ -7932,10 +8597,44 @@
79328597 }
79338598 }
79348599
7935
- return texture;
8600
+ return texturecache;
79368601 }
79378602
7938
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution)
8603
+ static void EmbedTextures(cTexture tex)
8604
+ {
8605
+ if (tex.pigmentdata == null)
8606
+ {
8607
+ //String texname = Object3D.GetPigment(tex);
8608
+
8609
+ CacheTexture texturecache = texturepigment.get(tex);
8610
+
8611
+ if (texturecache != null)
8612
+ {
8613
+ tex.pw = texturecache.texturedata.getWidth();
8614
+ tex.ph = texturecache.texturedata.getHeight();
8615
+ tex.pigmentdata = //CompressJPEG(CreateBim
8616
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8617
+ ;
8618
+ //, tex.pw, tex.ph), 0.5f);
8619
+ }
8620
+ }
8621
+
8622
+ if (tex.bumpdata == null)
8623
+ {
8624
+ //String texname = Object3D.GetBump(tex);
8625
+
8626
+ CacheTexture texturecache = texturebump.get(tex);
8627
+
8628
+ if (texturecache != null)
8629
+ {
8630
+ tex.bw = texturecache.texturedata.getWidth();
8631
+ tex.bh = texturecache.texturedata.getHeight();
8632
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8633
+ }
8634
+ }
8635
+ }
8636
+
8637
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
79398638 {
79408639 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
79418640
....@@ -7953,21 +8652,21 @@
79538652 return texture!=null?texture.texture:null;
79548653 }
79558654
7956
- com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution)
8655
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
79578656 {
79588657 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
79598658
79608659 return texture!=null?texture.texturedata:null;
79618660 }
79628661
7963
- boolean BindTexture(String tex, boolean bump, int resolution)
8662
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
79648663 {
79658664 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
79668665 {
79678666 return false;
79688667 }
79698668
7970
- boolean newtex = false;
8669
+ //boolean newtex = false;
79718670
79728671 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
79738672
....@@ -7999,9 +8698,75 @@
79998698 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
80008699 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
80018700
8002
- return newtex;
8701
+ return true; // Warning: not used.
80038702 }
80048703
8704
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8705
+ {
8706
+ try
8707
+ {
8708
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8709
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8710
+ ImageWriter writer = writers.next();
8711
+
8712
+ ImageWriteParam param = writer.getDefaultWriteParam();
8713
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8714
+ param.setCompressionQuality(quality);
8715
+
8716
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8717
+ writer.setOutput(ios);
8718
+ writer.write(null, new IIOImage(image, null, null), param);
8719
+
8720
+ byte[] data = baos.toByteArray();
8721
+ writer.dispose();
8722
+ return data;
8723
+ }
8724
+ catch (Exception e)
8725
+ {
8726
+ e.printStackTrace();
8727
+ return null;
8728
+ }
8729
+ }
8730
+
8731
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8732
+ {
8733
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8734
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8735
+ ImageReader reader = writers.next();
8736
+
8737
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8738
+
8739
+ ImageReadParam param = reader.getDefaultReadParam();
8740
+ param.setDestination(bim);
8741
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8742
+
8743
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8744
+ reader.setInput(ios);
8745
+ BufferedImage bim2 = reader.read(0, param);
8746
+ reader.dispose();
8747
+
8748
+// WritableRaster raster = bim2.getRaster();
8749
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8750
+// byte[] bytes = data.getData();
8751
+//
8752
+// int[] pixels = new int[bytes.length/3];
8753
+// for (int i=pixels.length; --i>=0;)
8754
+// {
8755
+// int i3 = i*3;
8756
+// pixels[i] = 0xFF;
8757
+// pixels[i] <<= 8;
8758
+// pixels[i] |= bytes[i3+2] & 0xFF;
8759
+// pixels[i] <<= 8;
8760
+// pixels[i] |= bytes[i3+1] & 0xFF;
8761
+// pixels[i] <<= 8;
8762
+// pixels[i] |= bytes[i3] & 0xFF;
8763
+// }
8764
+//
8765
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8766
+
8767
+ return bim;
8768
+ }
8769
+
80058770 ShadowBuffer shadowPBuf;
80068771 AntialiasBuffer antialiasPBuf;
80078772 int MAXSTACK;
....@@ -8018,10 +8783,12 @@
80188783
80198784 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
80208785 MAXSTACK = temp[0];
8021
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8786
+ if (Globals.DEBUG)
8787
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
80228788 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
80238789 MAXSTACK = temp[0];
8024
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8790
+ if (Globals.DEBUG)
8791
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
80258792
80268793 // Use debug pipeline
80278794 //drawable.setGL(new DebugGL(gl)); //
....@@ -8029,7 +8796,8 @@
80298796 gl = drawable.getGL(); //
80308797
80318798 GL gl3 = getGL();
8032
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8799
+ if (Globals.DEBUG)
8800
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
80338801
80348802
80358803 //float pos[] = { 100, 100, 100, 0 };
....@@ -8194,7 +8962,7 @@
81948962
81958963 if (cubemap == null)
81968964 {
8197
- LoadEnvy(5);
8965
+ //LoadEnvy(1);
81988966 }
81998967
82008968 //cubemap.enable();
....@@ -8470,6 +9238,8 @@
84709238
84719239 void LoadEnvy(int which)
84729240 {
9241
+ assert(false);
9242
+
84739243 String name;
84749244 String ext;
84759245
....@@ -8481,37 +9251,58 @@
84819251 cubemap = null;
84829252 return;
84839253 case 1:
8484
- name = "cubemaps/box_";
8485
- ext = "png";
9254
+ name = "cubemaps/rgb/";
9255
+ ext = "jpg";
84869256 reverseUP = false;
84879257 break;
84889258 case 2:
8489
- name = "cubemaps/uffizi_";
8490
- ext = "png";
8491
- break; // reverseUP = true; break;
9259
+ name = "cubemaps/uffizi/";
9260
+ ext = "jpg";
9261
+ reverseUP = false;
9262
+ break;
84929263 case 3:
8493
- name = "cubemaps/CloudyHills_";
8494
- ext = "tga";
9264
+ name = "cubemaps/CloudyHills/";
9265
+ ext = "jpg";
84959266 reverseUP = false;
84969267 break;
84979268 case 4:
8498
- name = "cubemaps/cornell_";
9269
+ name = "cubemaps/cornell/";
84999270 ext = "png";
85009271 reverseUP = false;
85019272 break;
9273
+ case 5:
9274
+ name = "cubemaps/skycube/";
9275
+ ext = "jpg";
9276
+ reverseUP = false;
9277
+ break;
9278
+ case 6:
9279
+ name = "cubemaps/SaintLazarusChurch3/";
9280
+ ext = "jpg";
9281
+ reverseUP = false;
9282
+ break;
9283
+ case 7:
9284
+ name = "cubemaps/Sodermalmsallen/";
9285
+ ext = "jpg";
9286
+ reverseUP = false;
9287
+ break;
9288
+ case 8:
9289
+ name = "cubemaps/Sodermalmsallen2/";
9290
+ ext = "jpg";
9291
+ reverseUP = false;
9292
+ break;
9293
+ case 9:
9294
+ name = "cubemaps/UnionSquare/";
9295
+ ext = "jpg";
9296
+ reverseUP = false;
9297
+ break;
85029298 default:
8503
- name = "cubemaps/rgb_";
8504
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9299
+ name = "cubemaps/box/";
9300
+ ext = "png"; /*mipmap = true;*/
9301
+ reverseUP = false;
85059302 break;
85069303 }
8507
-
8508
- try
8509
- {
8510
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
8511
- } catch (IOException e)
8512
- {
8513
- throw new RuntimeException(e);
8514
- }
9304
+
9305
+ LoadSkybox(name, ext, mipmap);
85159306 }
85169307
85179308 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -8543,8 +9334,12 @@
85439334 static double[] model = new double[16];
85449335 double[] camera2light = new double[16];
85459336 double[] light2camera = new double[16];
8546
- int newenvy = -1;
8547
- boolean envyoff = true; // false;
9337
+
9338
+ //int newenvy = -1;
9339
+ //boolean envyoff = false;
9340
+
9341
+ String loadedskyboxname;
9342
+
85489343 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
85499344 //float[] light0 = { 0,0,0 };
85509345 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -8837,11 +9632,35 @@
88379632 jy8[3] = 0.5f;
88389633 }
88399634
8840
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9635
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
88419636 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
88429637 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
88439638 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
88449639
9640
+ void ResetOptions()
9641
+ {
9642
+ options1[0] = 100;
9643
+ options1[1] = 0.025f;
9644
+ options1[2] = 0.01f;
9645
+ options1[3] = 0;
9646
+ options1[4] = 0;
9647
+
9648
+ options2[0] = 0;
9649
+ options2[1] = 0.75f;
9650
+ options2[2] = 0;
9651
+ options2[3] = 0;
9652
+
9653
+ options3[0] = 1;
9654
+ options3[1] = 1;
9655
+ options3[2] = 1;
9656
+ options3[3] = 0;
9657
+
9658
+ options4[0] = 1;
9659
+ options4[1] = 0;
9660
+ options4[2] = 1;
9661
+ options4[3] = 0;
9662
+ }
9663
+
88459664 static int imagecount = 0; // movie generation
88469665
88479666 static int jitter = 0;
....@@ -8937,8 +9756,8 @@
89379756 assert (parentcam != renderCamera);
89389757
89399758 if (renderCamera != lightCamera)
8940
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8941
- LA.matConcat(matrix, parentcam.toParent, matrix);
9759
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9760
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
89429761
89439762 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
89449763
....@@ -8953,8 +9772,8 @@
89539772 LA.matCopy(renderCamera.fromScreen, matrix);
89549773
89559774 if (renderCamera != lightCamera)
8956
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8957
- LA.matConcat(parentcam.fromParent, matrix, matrix);
9775
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9776
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
89589777
89599778 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
89609779
....@@ -9000,10 +9819,12 @@
90009819 rati = 1 / rati;
90019820 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
90029821 }
9003
- assert (newenvy == -1);
9822
+
9823
+ //assert (newenvy == -1);
9824
+
90049825 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
90059826 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9006
- DrawSkyBox(gl);
9827
+ DrawSkyBox(gl, (float)rati);
90079828 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
90089829 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
90099830 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -9026,7 +9847,7 @@
90269847 //gl.glFlush();
90279848 gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE);
90289849
9029
- if (ANIMATION && ABORTED)
9850
+ if (Globals.ANIMATION && ABORTED)
90309851 {
90319852 System.err.println(" ABORTED FRAME");
90329853 break;
....@@ -9056,7 +9877,7 @@
90569877 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
90579878
90589879 // save image
9059
- if (ANIMATION && !ABORTED)
9880
+ if (Globals.ANIMATION && !ABORTED)
90609881 {
90619882 VPwidth = viewport[2];
90629883 VPheight = viewport[3];
....@@ -9167,11 +9988,11 @@
91679988
91689989 // imagecount++;
91699990
9170
- String fullname = filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
9991
+ String fullname = Globals.filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
91719992
91729993 if (!BOXMODE)
91739994 {
9174
- System.out.println("image: " + fullname + " (wav cursor=" + (GrafreeD.wav.cursor / 735 / 4) + ")");
9995
+ System.out.println("image: " + fullname + " (wav cursor=" + (Grafreed.wav.cursor / 735 / 4) + ")");
91759996 }
91769997
91779998 if (!BOXMODE)
....@@ -9209,7 +10030,7 @@
920910030 ABORTED = false;
921010031 }
921110032 else
9212
- GrafreeD.wav.cursor += 735 * ACSIZE;
10033
+ Grafreed.wav.cursor += 735 * ACSIZE;
921310034
921410035 if (false)
921510036 {
....@@ -9869,14 +10690,23 @@
986910690 static boolean init = false;
987010691
987110692 double[][] matrix = LA.newMatrix();
10693
+
10694
+ // This is to refresh the UI of the material panel.
10695
+ ObjEditor patchMaterial;
987210696
987310697 public void display(GLAutoDrawable drawable)
987410698 {
9875
- if (GrafreeD.savesound && GrafreeD.hassound)
10699
+ if (patchMaterial.patchMaterial)
987610700 {
9877
- GrafreeD.wav.save();
9878
- GrafreeD.savesound = false;
9879
- GrafreeD.hassound = false;
10701
+ patchMaterial.patchMaterial = false;
10702
+ patchMaterial.objectPanel.setSelectedIndex(1);
10703
+ }
10704
+
10705
+ if (Grafreed.savesound && Grafreed.hassound)
10706
+ {
10707
+ Grafreed.wav.save();
10708
+ Grafreed.savesound = false;
10709
+ Grafreed.hassound = false;
988010710 }
988110711 // if (DEBUG_SELECTION)
988210712 // {
....@@ -9952,6 +10782,7 @@
995210782 ANTIALIAS = 0;
995310783 //System.out.println("RESTART");
995410784 AAtimer.restart();
10785
+ Globals.TIMERRUNNING = true;
995510786 }
995610787 }
995710788 }
....@@ -10006,7 +10837,7 @@
1000610837 Object3D theobject = object;
1000710838 Object3D theparent = object.parent;
1000810839 object.parent = null;
10009
- object = (Object3D)GrafreeD.clone(object);
10840
+ object = (Object3D)Grafreed.clone(object);
1001010841 object.Stripify();
1001110842 if (theobject.selection == null || theobject.selection.Size() == 0)
1001210843 theobject.PreprocessOcclusion(this);
....@@ -10019,13 +10850,14 @@
1001910850 ambientOcclusion = false;
1002010851 }
1002110852
10022
- if (Globals.lighttouched && DrawMode() == DEFAULT && !lightMode) // && !FROZEN)
10853
+ if (//Globals.lighttouched &&
10854
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1002310855 {
1002410856 //if (RENDERSHADOW) // ?
1002510857 if (!IsFrozen())
1002610858 {
1002710859 // dec 2012
10028
- if (!ambientOcclusion && !(!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0))
10860
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
1002910861 {
1003010862 Globals.framecount++;
1003110863 shadowbuffer.display();
....@@ -10038,7 +10870,7 @@
1003810870
1003910871 if (wait)
1004010872 {
10041
- Sleep(500);
10873
+ Sleep(200); // blocks everything
1004210874
1004310875 wait = false;
1004410876 }
....@@ -10152,8 +10984,8 @@
1015210984
1015310985 // if (parentcam != renderCamera) // not a light
1015410986 if (cam != lightCamera)
10155
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10156
- LA.matConcat(matrix, parentcam.toParent, matrix);
10987
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10988
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1015710989
1015810990 for (int j = 0; j < 4; j++)
1015910991 {
....@@ -10167,8 +10999,8 @@
1016710999
1016811000 // if (parentcam != renderCamera) // not a light
1016911001 if (cam != lightCamera)
10170
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10171
- LA.matConcat(parentcam.fromParent, matrix, matrix);
11002
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11003
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1017211004
1017311005 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1017411006
....@@ -10254,13 +11086,43 @@
1025411086 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1025511087 }
1025611088
10257
- if (newenvy > -1)
11089
+// if (newenvy > -1)
11090
+// {
11091
+// LoadEnvy(newenvy);
11092
+// }
11093
+//
11094
+// newenvy = -1;
11095
+
11096
+ if (transformMode) // object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
1025811097 {
10259
- LoadEnvy(newenvy);
11098
+ if (cubemaprgb == null)
11099
+ {
11100
+ cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb2" + "/", "jpg", false);
11101
+ }
11102
+
11103
+ cubemap = cubemaprgb;
1026011104 }
10261
-
10262
- newenvy = -1;
10263
-
11105
+ else
11106
+ {
11107
+ if (object.skyboxname != null)
11108
+ {
11109
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11110
+ {
11111
+ if (cubemap != null && cubemap != cubemaprgb)
11112
+ cubemap.dispose();
11113
+ cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11114
+ loadedskyboxname = object.skyboxname;
11115
+ }
11116
+ }
11117
+ else
11118
+ {
11119
+ cubemapcustom = null;
11120
+ loadedskyboxname = null;
11121
+ }
11122
+
11123
+ cubemap = cubemapcustom;
11124
+ }
11125
+
1026411126 ratio = ((double) getWidth()) / getHeight();
1026511127 //System.out.println("ratio = " + ratio);
1026611128
....@@ -10276,7 +11138,7 @@
1027611138
1027711139 if (!IsFrozen() && !ambientOcclusion)
1027811140 {
10279
- DrawSkyBox(gl);
11141
+ DrawSkyBox(gl, (float)ratio);
1028011142 }
1028111143
1028211144 //if (selection_view == -1)
....@@ -10427,7 +11289,16 @@
1042711289 // Bump noise
1042811290 gl.glActiveTexture(GL.GL_TEXTURE6);
1042911291 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
10430
- BindTexture(NOISE_TEXTURE, false, 2);
11292
+
11293
+ try
11294
+ {
11295
+ BindTexture(NOISE_TEXTURE, false, 2);
11296
+ }
11297
+ catch (Exception e)
11298
+ {
11299
+ System.err.println("FAILED: " + NOISE_TEXTURE);
11300
+ }
11301
+
1043111302
1043211303 gl.glActiveTexture(GL.GL_TEXTURE0);
1043311304 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -10450,9 +11321,9 @@
1045011321
1045111322 gl.glMatrixMode(GL.GL_MODELVIEW);
1045211323
10453
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10454
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10455
-//gl.glEnable(gl.GL_MULTISAMPLE);
11324
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11325
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11326
+gl.glEnable(gl.GL_MULTISAMPLE);
1045611327 } else
1045711328 {
1045811329 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -10463,7 +11334,7 @@
1046311334 //System.out.println("BLENDING ON");
1046411335 gl.glEnable(GL.GL_BLEND);
1046511336 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
10466
-
11337
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1046711338 gl.glMatrixMode(gl.GL_PROJECTION);
1046811339 gl.glLoadIdentity();
1046911340
....@@ -10552,8 +11423,8 @@
1055211423 System.err.println("parentcam != renderCamera");
1055311424
1055411425 // if (cam != lightCamera)
10555
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10556
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11426
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11427
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1055711428 }
1055811429
1055911430 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -10574,8 +11445,8 @@
1057411445 if (true) // TODO
1057511446 {
1057611447 if (cam != lightCamera)
10577
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10578
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11448
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11449
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
1057911450 }
1058011451
1058111452 LA.xformPos(light0, cam.toScreen, light0);
....@@ -10712,7 +11583,7 @@
1071211583 }
1071311584 }
1071411585
10715
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11586
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1071611587 {
1071711588 //gl.glDepthFunc(GL.GL_LEQUAL);
1071811589 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -10720,24 +11591,21 @@
1072011591
1072111592 boolean texon = textureon;
1072211593
10723
- if (RENDERPROGRAM > 0)
10724
- {
10725
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
10726
- textureon = false;
10727
- }
11594
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11595
+ textureon = false;
11596
+
1072811597 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1072911598 //System.out.println("ALLO");
1073011599 gl.glColorMask(false, false, false, false);
1073111600 DrawObject(gl);
10732
- if (RENDERPROGRAM > 0)
10733
- {
10734
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
10735
- textureon = texon;
10736
- }
11601
+
11602
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11603
+ textureon = texon;
11604
+
1073711605 gl.glColorMask(true, true, true, true);
1073811606
1073911607 gl.glDepthFunc(GL.GL_EQUAL);
10740
- //gl.glDepthMask(false);
11608
+ gl.glDepthMask(false);
1074111609 }
1074211610
1074311611 if (false) // DrawMode() == SHADOW)
....@@ -10891,8 +11759,14 @@
1089111759 {
1089211760 renderpass++;
1089311761 // System.out.println("Draw object... ");
11762
+ STEP = 1;
1089411763 if (FAST) // in case there is no script
10895
- STEP = 16;
11764
+ STEP = 8;
11765
+
11766
+ if (CURRENTANTIALIAS == 0 || ACSIZE == 1)
11767
+ {
11768
+ STEP *= 4;
11769
+ }
1089611770
1089711771 //object.FullInvariants();
1089811772
....@@ -10906,23 +11780,44 @@
1090611780 e.printStackTrace();
1090711781 }
1090811782
10909
- if (GrafreeD.RENDERME > 0)
10910
- GrafreeD.RENDERME--; // mechante magouille
11783
+ if (Grafreed.RENDERME > 0)
11784
+ Grafreed.RENDERME--; // mechante magouille
1091111785
1091211786 Globals.ONESTEP = false;
1091311787 }
1091411788
1091511789 static boolean zoomonce = false;
1091611790
11791
+ static void CreateSelectedPoint()
11792
+ {
11793
+ if (selectedpoint == null)
11794
+ {
11795
+ debugpointG = new Sphere();
11796
+ debugpointP = new Sphere();
11797
+ debugpointC = new Sphere();
11798
+ debugpointR = new Sphere();
11799
+
11800
+ selectedpoint = new Superellipsoid();
11801
+
11802
+ for (int i=0; i<8; i++)
11803
+ {
11804
+ debugpoints[i] = new Sphere();
11805
+ }
11806
+ }
11807
+ }
11808
+
1091711809 void DrawObject(GL gl, boolean draw)
1091811810 {
11811
+ // To clear camera values
11812
+ ResetOptions();
11813
+
1091911814 //System.out.println("DRAW OBJECT " + mouseDown);
1092011815 // DrawMode() = SELECTION;
1092111816 //GL gl = getGL();
1092211817 if ((TRACK || SHADOWTRACK) || zoomonce)
1092311818 {
1092411819 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
10925
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11820
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1092611821 pingthread.StepToTarget(true); // true);
1092711822 // zoomonce = false;
1092811823 }
....@@ -10977,7 +11872,14 @@
1097711872
1097811873 usedtextures.clear();
1097911874
10980
- BindTextures(DEFAULT_TEXTURES, 2);
11875
+ try
11876
+ {
11877
+ BindTextures(DEFAULT_TEXTURES, 2);
11878
+ }
11879
+ catch (Exception e)
11880
+ {
11881
+ System.err.println("FAILED: " + DEFAULT_TEXTURES);
11882
+ }
1098111883 }
1098211884 //System.out.println("--> " + stackdepth);
1098311885 // GrafreeD.traceon();
....@@ -10987,8 +11889,9 @@
1098711889
1098811890 if (DrawMode() == DEFAULT)
1098911891 {
10990
- if (DEBUG)
11892
+ if (Globals.DEBUG)
1099111893 {
11894
+ CreateSelectedPoint();
1099211895 float radius = 0.05f;
1099311896 if (selectedpoint.radius != radius)
1099411897 {
....@@ -11042,20 +11945,32 @@
1104211945 ReleaseTextures(DEFAULT_TEXTURES);
1104311946
1104411947 if (CLEANCACHE)
11045
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11948
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1104611949 {
11047
- String tex = e.nextElement();
11950
+ cTexture tex = e.nextElement();
1104811951
1104911952 // System.out.println("Texture --------- " + tex);
1105011953
11051
- if (tex.equals("WHITE_NOISE"))
11954
+ if (tex.equals("WHITE_NOISE:"))
1105211955 continue;
1105311956
11054
- if (!usedtextures.containsKey(tex))
11957
+ if (!usedtextures.contains(tex))
1105511958 {
11959
+ CacheTexture gettex = texturepigment.get(tex);
1105611960 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11057
- textures.get(tex).texture.dispose();
11058
- textures.remove(tex);
11961
+ if (gettex != null)
11962
+ {
11963
+ gettex.texture.dispose();
11964
+ texturepigment.remove(tex);
11965
+ }
11966
+
11967
+ gettex = texturebump.get(tex);
11968
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11969
+ if (gettex != null)
11970
+ {
11971
+ gettex.texture.dispose();
11972
+ texturebump.remove(tex);
11973
+ }
1105911974 }
1106011975 }
1106111976 }
....@@ -11068,7 +11983,14 @@
1106811983 if (checker != null && DrawMode() == DEFAULT)
1106911984 {
1107011985 //BindTexture(IMMORTAL_TEXTURE);
11071
- BindTextures(checker.GetTextures(), checker.texres);
11986
+ try
11987
+ {
11988
+ BindTextures(checker.GetTextures(), checker.texres);
11989
+ }
11990
+ catch (Exception e)
11991
+ {
11992
+ System.err.println("FAILED: " + checker.GetTextures());
11993
+ }
1107211994 // NEAREST
1107311995 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
1107411996 DrawChecker(gl);
....@@ -11150,7 +12072,7 @@
1115012072 return;
1115112073 }
1115212074
11153
- String string = obj.GetToolTip();
12075
+ String string = obj.toString(); //.GetToolTip();
1115412076
1115512077 GL gl = GetGL();
1115612078
....@@ -11467,8 +12389,8 @@
1146712389 //obj.TransformToWorld(light, light);
1146812390 for (int i = tp.size(); --i >= 0;)
1146912391 {
11470
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
11471
- LA.xformPos(light, tp.get(i).toParent, light);
12392
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12393
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1147212394 }
1147312395
1147412396
....@@ -11485,8 +12407,8 @@
1148512407 parentcam = cameras[0];
1148612408 }
1148712409
11488
- for (int count = parentcam.GetTransformCount(); --count>=0;)
11489
- LA.xformPos(light, parentcam.toParent, light); // may 2013
12410
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
12411
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1149012412
1149112413 LA.xformPos(light, renderCamera.toScreen, light);
1149212414
....@@ -11576,8 +12498,76 @@
1157612498
1157712499 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1157812500
11579
- String program =
12501
+ String programmin =
12502
+ // Min shader
1158012503 "!!ARBfp1.0\n" +
12504
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12505
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12506
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12507
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12508
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12509
+ "PARAM light2cam0 = program.env[10];" +
12510
+ "PARAM light2cam1 = program.env[11];" +
12511
+ "PARAM light2cam2 = program.env[12];" +
12512
+ "TEMP temp;" +
12513
+ "TEMP light;" +
12514
+ "TEMP ndotl;" +
12515
+ "TEMP normal;" +
12516
+ "TEMP depth;" +
12517
+ "TEMP eye;" +
12518
+ "TEMP pos;" +
12519
+
12520
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12521
+ Normalize("normal") +
12522
+ "MOV light, state.light[0].position;" +
12523
+ "DP3 ndotl.x, light, normal;" +
12524
+
12525
+ // shadow
12526
+ "MOV pos, fragment.texcoord[1];" +
12527
+ "MOV temp, pos;" +
12528
+ ShadowTextureFetch("depth", "temp", "1") +
12529
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12530
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12531
+
12532
+ // No shadow when out of frustum
12533
+ //"SGE temp.y, depth.z, zero123.y;" +
12534
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12535
+
12536
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12537
+
12538
+ // Backlit
12539
+ "MOV pos.w, zero123.y;" +
12540
+ "DP4 eye.x, pos, light2cam0;" +
12541
+ "DP4 eye.y, pos, light2cam1;" +
12542
+ "DP4 eye.z, pos, light2cam2;" +
12543
+ Normalize("eye") +
12544
+
12545
+ "DP3 ndotl.y, -eye, normal;" +
12546
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12547
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12548
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12549
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12550
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12551
+
12552
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12553
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12554
+
12555
+ // Pigment
12556
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12557
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12558
+ "MUL temp, temp, ndotl.x;" +
12559
+
12560
+ "MUL temp, temp, zero123.z;" +
12561
+
12562
+ //"MUL temp, temp, ndotl.y;" +
12563
+
12564
+ "MOV temp.w, zero123.y;" + // reset alpha
12565
+ "MOV result.color, temp;" +
12566
+ "END";
12567
+
12568
+ String programmax =
12569
+ "!!ARBfp1.0\n" +
12570
+
1158112571 //"OPTION ARB_fragment_program_shadow;" +
1158212572 "PARAM light2cam0 = program.env[10];" +
1158312573 "PARAM light2cam1 = program.env[11];" +
....@@ -11603,7 +12593,7 @@
1160312593 "PARAM params4 = program.env[4];" + // anisoV, cameralight, selfshadow, shadow
1160412594 "PARAM params5 = program.env[5];" + // texture, opacity, fakedepth, shadowbias
1160512595 "PARAM params6 = program.env[6];" + // bump, noise, borderfade, fog punchthrough
11606
- "PARAM params7 = program.env[7];" + // noise power, opacity power
12596
+ "PARAM params7 = program.env[7];" + // noise power, opacity power, parallax
1160712597 "PARAM options0 = program.env[63];" + // fog density, intensity, elevation
1160812598 "PARAM options1 = program.env[62];" + // fog rgb color
1160912599 "PARAM options2 = program.env[61];" + // image intensity, subsurface, lightsheen
....@@ -11692,8 +12682,7 @@
1169212682 "TEMP shininess;" +
1169312683 "\n" +
1169412684 "MOV texSamp, one;" +
11695
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
11696
-
12685
+
1169712686 "MOV mapgrid.x, one2048th.x;" +
1169812687 "MOV temp, fragment.texcoord[1];" +
1169912688 /*
....@@ -11714,20 +12703,20 @@
1171412703 "MUL temp, floor, mapgrid.x;" +
1171512704 //"TEX depth0, temp, texture[1], 2D;" +
1171612705 (((mode & FP_SOFTSHADOW) == 0) ? "" :
11717
- TextureFetch("depth0", "temp", "1") +
12706
+ ShadowTextureFetch("depth0", "temp", "1") +
1171812707 "") +
1171912708 "ADD temp.x, temp.x, mapgrid.x;" +
1172012709 //"TEX depth1, temp, texture[1], 2D;" +
1172112710 (((mode & FP_SOFTSHADOW) == 0) ? "" :
11722
- TextureFetch("depth1", "temp", "1") +
12711
+ ShadowTextureFetch("depth1", "temp", "1") +
1172312712 "") +
1172412713 "ADD temp.y, temp.y, mapgrid.x;" +
1172512714 //"TEX depth2, temp, texture[1], 2D;" +
11726
- TextureFetch("depth2", "temp", "1") +
12715
+ ShadowTextureFetch("depth2", "temp", "1") +
1172712716 "SUB temp.x, temp.x, mapgrid.x;" +
1172812717 //"TEX depth3, temp, texture[1], 2D;" +
1172912718 (((mode & FP_SOFTSHADOW) == 0) ? "" :
11730
- TextureFetch("depth3", "temp", "1") +
12719
+ ShadowTextureFetch("depth3", "temp", "1") +
1173112720 "") +
1173212721 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1173312722 //"MOV params, material;" +
....@@ -11849,7 +12838,7 @@
1184912838 "POW texSamp.a, texSamp.a, params6.w;" + // fog punch through shortcut
1185012839 // mar 2013 ??? "KIL alpha.a;" +
1185112840 "MOV alpha, texSamp.aaaa;" + // y;" +
11852
- "KIL alpha.a;" +
12841
+ "KIL alpha.a;" + // not sure with parallax mapping
1185312842 /*
1185412843 "MUL temp.xy, temp, two;" +
1185512844 "TXB bump, temp, texture[0], 2D;" +
....@@ -11935,11 +12924,6 @@
1193512924 "SUB bump0, bump0, half;" +
1193612925 "ADD bump, bump, bump0;" +
1193712926
11938
- "MOV temp.x, texSamp.a;" +
11939
- "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
11940
- //"LRP texSamp0, params5.x, texSamp0, one;" +
11941
- "MOV texSamp.a, temp.x;" +
11942
-
1194312927 // double-sided
1194412928 /**/
1194512929 (doublesided?"DP3 temp.z, normal, eye;" +
....@@ -11969,6 +12953,41 @@
1196912953 Normalize("U") +
1197012954
1197112955 // parallax mapping
12956
+
12957
+ "DP3 temp2.x, V, eye;" +
12958
+ "DP3 temp2.y, U, eye;" +
12959
+ "DP3 temp2.z, normal, eye;" +
12960
+ "RCP temp2.z, temp2.z;" +
12961
+
12962
+ "DP3 temp2.w, texSamp, texSamp;" + // Height
12963
+ "RSQ temp2.w, temp2.w;" +
12964
+ "RCP temp2.w, temp2.w;" +
12965
+
12966
+ "SUB temp2.w, temp2.w, half;" +
12967
+// "SGE temp.x, temp2.w, eps.x;" +
12968
+// "MUL temp2.w, temp2.w, temp.x;" +
12969
+
12970
+ //"MOV texSamp, U;" +
12971
+
12972
+ "MUL temp2.z, temp2.z, temp2.w;" +
12973
+ "MUL temp2.z, temp2.z, params7.z;" + // parallax
12974
+
12975
+ "MUL temp2, temp2, temp2.z;" +
12976
+
12977
+ "MOV temp, fragment.texcoord[0];" +
12978
+
12979
+ "SUB temp, temp, temp2;" +
12980
+
12981
+ "TEX texSamp, temp, texture[0], 2D;" +
12982
+ "POW texSamp.a, texSamp.a, params6.w;" + // punch through
12983
+ "MOV alpha, texSamp.aaaa;" +
12984
+
12985
+// parallax mapping
12986
+
12987
+ "MOV temp.x, texSamp.a;" +
12988
+ "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
12989
+ //"LRP texSamp0, params5.x, texSamp0, one;" +
12990
+ "MOV texSamp.a, temp.x;" +
1197212991
1197312992 //"MOV temp, fragment.texcoord[0];" +
1197412993 //
....@@ -12098,10 +13117,10 @@
1209813117 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1209913118 "") +
1210013119
12101
- // display shadow only (bump == 0)
13120
+ // display shadow only (fakedepth == 0)
1210213121 "SUB temp.x, half.x, shadow.x;" +
12103
- "MOV temp.y, -params6.x;" +
12104
- "SLT temp.z, temp.y, zero.x;" +
13122
+ "MOV temp.y, -params5.z;" + // params6.x;" +
13123
+ "SLT temp.z, temp.y, -c256i.x;" +
1210513124 "SUB temp.y, one.x, temp.z;" +
1210613125 "MUL temp.x, temp.x, temp.y;" +
1210713126 "KIL temp.x;" +
....@@ -12230,8 +13249,10 @@
1223013249 "MAX ndotl.x, ndotl.x, -ndotl.x;" +
1223113250
1223213251 "SUB temp.x, one.x, ndotl.x;" +
12233
- "ADD temp.x, temp.x, options2.z;" + // lightsheen
12234
- "ADD temp.y, one.y, options2.y;" + // sursurface
13252
+ // Tuning for default skin
13253
+ //"ADD temp.x, temp.x, options2.z;" + // lightsheen
13254
+ "MAD temp.x, options2.z, half.y, temp.x;" + // lightsheen
13255
+ "ADD temp.y, one.y, options2.y;" + // subsurface
1223513256 "MUL temp.x, temp.x, temp.y;" +
1223613257
1223713258 "MUL saturation, saturation, temp.xxxx;" +
....@@ -12430,8 +13451,19 @@
1243013451 //once = true;
1243113452 }
1243213453
12433
- System.out.print("Program #" + mode + "; length = " + program.length());
12434
- System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13454
+ String program = programmax;
13455
+
13456
+ if (Globals.MINSHADER)
13457
+ {
13458
+ program = programmin;
13459
+ }
13460
+
13461
+ if (Globals.DEBUG)
13462
+ {
13463
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13464
+ System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13465
+ }
13466
+
1243513467 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1243613468
1243713469 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -12478,7 +13510,8 @@
1247813510 "\n" +
1247913511 "END\n";
1248013512
12481
- System.out.println("Program shadow #" + 0 + "; length = " + program.length());
13513
+ if (Globals.DEBUG)
13514
+ System.out.println("Program shadow #" + 0 + "; length = " + program.length());
1248213515 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1248313516
1248413517 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -12523,25 +13556,26 @@
1252313556 return out;
1252413557 }
1252513558
12526
- String TextureFetch(String dest, String src, String unit)
13559
+ // Also does frustum culling
13560
+ String ShadowTextureFetch(String dest, String src, String unit)
1252713561 {
1252813562 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1252913563 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1253013564 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13565
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13566
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1253113567 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12532
- "SLT " + src + ".z, " + src + ".x, one.x;" +
12533
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12534
- "SLT " + src + ".z, " + src + ".y, one.x;" +
12535
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13568
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13569
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1253613570 //"SWZ buffer, temp, w,w,w,w;";
12537
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13571
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1253813572 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1253913573 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1254013574 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
12541
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13575
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1254213576
12543
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
12544
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13577
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13578
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1254513579 }
1254613580
1254713581 String Shadow(String depth, String shadow)
....@@ -12563,12 +13597,16 @@
1256313597
1256413598 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1256513599 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13600
+
13601
+ // Compare fragment depth in light space with shadowmap.
1256613602 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1256713603 "SGE temp.y, temp.x, zero.x;" +
12568
- "SUB " + shadow + ".y, one.x, temp.y;" +
13604
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13605
+
13606
+ // Reverse comparison
1256913607 "SUB temp.x, one.x, temp.x;" +
1257013608 "MUL " + shadow + ".x, temp.x, temp.y;" +
12571
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13609
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1257213610 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1257313611
1257413612 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -12582,6 +13620,10 @@
1258213620 // No shadow for backface
1258313621 "DP3 temp.x, normal, lightd;" +
1258413622 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13623
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13624
+
13625
+ // No shadow when out of frustum
13626
+ "SGE temp.x, " + depth + ".z, one.z;" +
1258513627 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1258613628 "";
1258713629 }
....@@ -12727,8 +13769,9 @@
1272713769 /*static*/ float[] modelParams4 = new float[]{0, 0, 0, 0}; // anisoV, cameralight, selfshadow, shadow
1272813770 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1272913771 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
12730
- /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
12731
- Object3D.cVector2[] vector2buffer;
13772
+ /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power, parallax
13773
+
13774
+ //Object3D.cVector2[] vector2buffer;
1273213775
1273313776 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1273413777 // OUT : diff, spec
....@@ -12744,9 +13787,10 @@
1274413787 "DP3 " + dest + ".z," + "normals," + "eye;" +
1274513788 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1274613789 //"MOV " + dest + ".w," + "normal.z;" +
12747
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
12748
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
12749
- //"MOV " + dest + ".z," + "params2.w;" +
13790
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13791
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13792
+
13793
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1275013794 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1275113795 "RCP " + dest + ".w," + dest + ".w;" +
1275213796 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13140,7 +14184,7 @@
1314014184 public void mousePressed(MouseEvent e)
1314114185 {
1314214186 //System.out.println("mousePressed: " + e);
13143
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14187
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1314414188 }
1314514189
1314614190 static long prevtime = 0;
....@@ -13167,6 +14211,7 @@
1316714211
1316814212 //System.err.println("Dtime = " + Dtime + "; units = " + e.getUnitsToScroll() + "; ratio (units/ms) = " + ratio);
1316914213
14214
+ if (BUTTONLESSWHEEL)
1317014215 if (Math.abs(ratio) < 0.1 || Math.abs(Dtime) == 0) // < 30)
1317114216 {
1317214217 return;
....@@ -13175,7 +14220,7 @@
1317514220 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
1317614221
1317714222 // TIMER
13178
- if (!wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
14223
+ if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
1317914224 {
1318014225 keepboxmode = BOXMODE;
1318114226 keepsupport = SUPPORT;
....@@ -13215,8 +14260,8 @@
1321514260 // mode |= META;
1321614261 //}
1321714262
13218
- SetMouseMode(WHEEL | e.getModifiersEx());
13219
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14263
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14264
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1322014265 anchorX = ax;
1322114266 anchorY = ay;
1322214267 prevX = px;
....@@ -13250,6 +14295,7 @@
1325014295 else
1325114296 if (evt.getSource() == AAtimer)
1325214297 {
14298
+ Globals.TIMERRUNNING = false;
1325314299 if (mouseDown)
1325414300 {
1325514301 //new Exception().printStackTrace();
....@@ -13275,6 +14321,10 @@
1327514321 // LIVE = waslive;
1327614322 // wasliveok = true;
1327714323 // waslive = false;
14324
+
14325
+ // May 2019 Forget it:
14326
+ if (true)
14327
+ return;
1327814328
1327914329 // source == timer
1328014330 if (mouseDown)
....@@ -13305,7 +14355,7 @@
1330514355
1330614356 // fev 2014???
1330714357 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13308
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14358
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1330914359 pingthread.StepToTarget(true); // true);
1331014360 }
1331114361 // if (!LIVE)
....@@ -13314,12 +14364,13 @@
1331414364
1331514365 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1331614366
13317
- void clickStart(int x, int y, int modifiers)
14367
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1331814368 {
1331914369 if (!wasliveok)
1332014370 return;
1332114371
1332214372 AAtimer.restart(); //
14373
+ Globals.TIMERRUNNING = true;
1332314374
1332414375 // waslive = LIVE;
1332514376 // LIVE = false;
....@@ -13331,7 +14382,7 @@
1333114382 // touched = true; // main DL
1333214383 if (isRenderer)
1333314384 {
13334
- SetMouseMode(modifiers);
14385
+ SetMouseMode(modifiers, modifiersex);
1333514386 }
1333614387
1333714388 selectX = anchorX = x;
....@@ -13344,7 +14395,7 @@
1334414395 clicked = true;
1334514396 hold = false;
1334614397
13347
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14398
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1334814399 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1334914400 {
1335014401 // System.out.println("RESTART II " + modifiers);
....@@ -13369,14 +14420,15 @@
1336914420 drag = false;
1337014421 //System.out.println("Mouse DOWN");
1337114422 editObj = false;
13372
- ClickInfo info = new ClickInfo();
13373
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
13374
- info.pane = this;
13375
- info.camera = renderCamera;
13376
- info.x = x;
13377
- info.y = y;
13378
- info.modifiers = modifiers;
13379
- editObj = object.doEditClick(info, 0);
14423
+ //ClickInfo info = new ClickInfo();
14424
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14425
+ object.clickInfo.pane = this;
14426
+ object.clickInfo.camera = renderCamera;
14427
+ object.clickInfo.x = x;
14428
+ object.clickInfo.y = y;
14429
+ object.clickInfo.modifiers = modifiersex;
14430
+ editObj = object.doEditClick(//info,
14431
+ 0);
1338014432 if (!editObj)
1338114433 {
1338214434 hasMarquee = true;
....@@ -13392,11 +14444,14 @@
1339214444
1339314445 public void mouseDragged(MouseEvent e)
1339414446 {
14447
+ Globals.MOUSEDRAGGED = true;
14448
+
14449
+ //System.out.println("mouseDragged: " + e);
1339514450 if (isRenderer)
1339614451 movingcamera = true;
14452
+
1339714453 //if (drawing)
1339814454 //return;
13399
- //System.out.println("mouseDragged: " + e);
1340014455 if ((e.getModifiersEx() & CTRL) != 0
1340114456 || (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen())
1340214457 {
....@@ -13404,7 +14459,7 @@
1340414459 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1340514460 }
1340614461 else
13407
- drag(e.getX(), e.getY(), e.getModifiersEx());
14462
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1340814463
1340914464 //try { Thread.sleep(1); } catch (Exception ex) {}
1341014465 }
....@@ -13577,6 +14632,7 @@
1357714632
1357814633 public void run()
1357914634 {
14635
+ new Exception().printStackTrace();
1358014636 System.exit(0);
1358114637 for (;;)
1358214638 {
....@@ -13640,7 +14696,7 @@
1364014696 {
1364114697 Globals.lighttouched = true;
1364214698 }
13643
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14699
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1364414700 }
1364514701 //else
1364614702 }
....@@ -13654,12 +14710,18 @@
1365414710 void GoDown(int mod)
1365514711 {
1365614712 MODIFIERS |= COMMAND;
13657
- /*
14713
+ boolean isVR = (mouseMode&VR)!=0;
14714
+ /**/
1365814715 if((mod&SHIFT) == SHIFT)
13659
- manipCamera.RotatePosition(0, -speed);
14716
+ {
14717
+ if (isVR)
14718
+ manipCamera.RotateInterest(0, -speed);
14719
+ else
14720
+ manipCamera.RotatePosition(0, -speed);
14721
+ }
1366014722 else
13661
- manipCamera.BackForth(0, -speed*delta, getWidth());
13662
- */
14723
+ manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth());
14724
+ /**/
1366314725 if ((mod & SHIFT) == SHIFT)
1366414726 {
1366514727 mouseMode = mouseMode; // VR??
....@@ -13668,6 +14730,8 @@
1366814730 mouseMode |= BACKFORTH;
1366914731 }
1367014732
14733
+ targetLookAt.set(manipCamera.lookAt);
14734
+
1367114735 //prevX = X = anchorX;
1367214736 prevY = Y = anchorY - (int) (renderCamera.Distance());
1367314737 }
....@@ -13675,12 +14739,19 @@
1367514739 void GoUp(int mod)
1367614740 {
1367714741 MODIFIERS |= COMMAND;
13678
- /*
14742
+ /**/
14743
+ boolean isVR = (mouseMode&VR)!=0;
14744
+
1367914745 if((mod&SHIFT) == SHIFT)
13680
- manipCamera.RotatePosition(0, speed);
14746
+ {
14747
+ if (isVR)
14748
+ manipCamera.RotateInterest(0, speed);
14749
+ else
14750
+ manipCamera.RotatePosition(0, speed);
14751
+ }
1368114752 else
13682
- manipCamera.BackForth(0, speed*delta, getWidth());
13683
- */
14753
+ manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth());
14754
+ /**/
1368414755 if ((mod & SHIFT) == SHIFT)
1368514756 {
1368614757 mouseMode = mouseMode;
....@@ -13689,6 +14760,8 @@
1368914760 mouseMode |= BACKFORTH;
1369014761 }
1369114762
14763
+ targetLookAt.set(manipCamera.lookAt);
14764
+
1369214765 //prevX = X = anchorX;
1369314766 prevY = Y = anchorY + (int) (renderCamera.Distance());
1369414767 }
....@@ -13696,12 +14769,17 @@
1369614769 void GoLeft(int mod)
1369714770 {
1369814771 MODIFIERS |= COMMAND;
13699
- /*
14772
+ /**/
1370014773 if((mod&SHIFT) == SHIFT)
13701
- manipCamera.RotatePosition(speed, 0);
14774
+ manipCamera.Translate(speed*delta, 0, getWidth());
1370214775 else
13703
- manipCamera.Translate(speed*delta, 0, getWidth());
13704
- */
14776
+ {
14777
+ if ((mouseMode&VR)!=0)
14778
+ manipCamera.RotateInterest(-speed, 0);
14779
+ else
14780
+ manipCamera.RotatePosition(speed, 0);
14781
+ }
14782
+ /**/
1370514783 if ((mod & SHIFT) == SHIFT)
1370614784 {
1370714785 mouseMode = mouseMode;
....@@ -13710,6 +14788,8 @@
1371014788 mouseMode |= ROTATE;
1371114789 } // TRANSLATE;
1371214790
14791
+ targetLookAt.set(manipCamera.lookAt);
14792
+
1371314793 prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance());
1371414794 prevY = Y = anchorY;
1371514795 }
....@@ -13717,12 +14797,18 @@
1371714797 void GoRight(int mod)
1371814798 {
1371914799 MODIFIERS |= COMMAND;
13720
- /*
14800
+ /**/
1372114801 if((mod&SHIFT) == SHIFT)
13722
- manipCamera.RotatePosition(-speed, 0);
14802
+ manipCamera.Translate(-speed*delta, 0, getWidth());
1372314803 else
13724
- manipCamera.Translate(-speed*delta, 0, getWidth());
13725
- */
14804
+ {
14805
+ if ((mouseMode&VR)!=0)
14806
+ manipCamera.RotateInterest(speed, 0);
14807
+ else
14808
+ manipCamera.RotatePosition(-speed, 0);
14809
+ }
14810
+
14811
+ /**/
1372614812 if ((mod & SHIFT) == SHIFT)
1372714813 {
1372814814 mouseMode = mouseMode;
....@@ -13731,6 +14817,8 @@
1373114817 mouseMode |= ROTATE;
1373214818 } // TRANSLATE;
1373314819
14820
+ targetLookAt.set(manipCamera.lookAt);
14821
+
1373414822 prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance());
1373514823 prevY = Y = anchorY;
1373614824 }
....@@ -13740,7 +14828,7 @@
1374014828 int X, Y;
1374114829 boolean SX, SY;
1374214830
13743
- void drag(int x, int y, int modifiers)
14831
+ void drag(int x, int y, int modifiers, int modifiersex)
1374414832 {
1374514833 if (IsFrozen())
1374614834 {
....@@ -13749,17 +14837,17 @@
1374914837
1375014838 drag = true; // NEW
1375114839
13752
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14840
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1375314841
1375414842 X = x;
1375514843 Y = y;
1375614844 // floating state for animation
13757
- MODIFIERS = modifiers;
13758
- modifiers &= ~1024;
14845
+ MODIFIERS = modifiersex;
14846
+ modifiersex &= ~1024;
1375914847 if (false) // modifiers != 0)
1376014848 {
1376114849 //new Exception().printStackTrace();
13762
- System.out.println("mouseDragged: " + modifiers);
14850
+ System.out.println("mouseDragged: " + modifiersex);
1376314851 System.out.println("SHIFT = " + SHIFT);
1376414852 System.out.println("CONTROL = " + COMMAND);
1376514853 System.out.println("META = " + META);
....@@ -13772,14 +14860,16 @@
1377214860 if (editObj)
1377314861 {
1377414862 drag = true;
13775
- ClickInfo info = new ClickInfo();
13776
- info.bounds.setBounds(0, 0,
14863
+ //ClickInfo info = new ClickInfo();
14864
+ object.clickInfo.bounds.setBounds(0, 0,
1377714865 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
13778
- info.pane = this;
13779
- info.camera = renderCamera;
13780
- info.x = x;
13781
- info.y = y;
13782
- object.editWindow.copy.doEditDrag(info);
14866
+ object.clickInfo.pane = this;
14867
+ object.clickInfo.camera = renderCamera;
14868
+ object.clickInfo.x = x;
14869
+ object.clickInfo.y = y;
14870
+ object //.GetWindow().copy
14871
+ .doEditDrag(//info,
14872
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1378314873 } else
1378414874 {
1378514875 if (x < startX)
....@@ -13928,23 +15018,27 @@
1392815018 }
1392915019 }
1393015020
15021
+// ClickInfo clickInfo = new ClickInfo();
15022
+
1393115023 public void mouseMoved(MouseEvent e)
1393215024 {
1393315025 //System.out.println("mouseMoved: " + e);
13934
-
1393515026 if (isRenderer)
1393615027 return;
1393715028
13938
- ClickInfo ci = new ClickInfo();
13939
- ci.x = e.getX();
13940
- ci.y = e.getY();
13941
- ci.modifiers = e.getModifiersEx();
13942
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
13943
- ci.pane = this;
13944
- ci.camera = renderCamera;
15029
+ // Mouse cursor feedback
15030
+ object.clickInfo.x = e.getX();
15031
+ object.clickInfo.y = e.getY();
15032
+ object.clickInfo.modifiers = e.getModifiersEx();
15033
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
15034
+ object.clickInfo.pane = this;
15035
+ object.clickInfo.camera = renderCamera;
1394515036 if (!isRenderer)
1394615037 {
13947
- if (object.editWindow.copy.doEditClick(ci, 0))
15038
+ //ObjEditor editWindow = object.editWindow;
15039
+ //Object3D copy = editWindow.copy;
15040
+ if (object.doEditClick(//clickInfo,
15041
+ 0))
1394815042 {
1394915043 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1395015044 } else
....@@ -13956,7 +15050,11 @@
1395615050
1395715051 public void mouseReleased(MouseEvent e)
1395815052 {
15053
+ Globals.MOUSEDRAGGED = false;
15054
+
1395915055 movingcamera = false;
15056
+ X = 0; // getBounds().width/2;
15057
+ Y = 0; // getBounds().height/2;
1396015058 //System.out.println("mouseReleased: " + e);
1396115059 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1396215060 }
....@@ -13979,9 +15077,9 @@
1397915077 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1398015078 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1398115079
13982
- if (control || command || IsFrozen())
15080
+// No delay if (control || command || IsFrozen())
1398315081 timeout = true;
13984
- else
15082
+// ?? May 2019 else
1398515083 // timer.setDelay((modifiers & 128) != 0?0:350);
1398615084 mouseDown = false;
1398715085 if (!control && !command) // june 2013
....@@ -14091,7 +15189,7 @@
1409115189 System.out.println("keyReleased: " + e);
1409215190 }
1409315191
14094
- void SetMouseMode(int modifiers)
15192
+ void SetMouseMode(int modifiers, int modifiersex)
1409515193 {
1409615194 //System.out.println("SetMouseMode = " + modifiers);
1409715195 //modifiers &= ~1024;
....@@ -14103,25 +15201,25 @@
1410315201 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1410415202 // return;
1410515203 //System.out.println("SetMode = " + modifiers);
14106
- if ((modifiers & WHEEL) == WHEEL)
15204
+ if ((modifiersex & WHEEL) == WHEEL)
1410715205 {
1410815206 mouseMode |= ZOOM;
1410915207 }
1411015208
1411115209 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
14112
- if (capsLocked || (modifiers & META) == META)
15210
+ if (capsLocked) // || (modifiers & META) == META)
1411315211 {
1411415212 mouseMode |= VR; // BACKFORTH;
1411515213 }
14116
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
15214
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1411715215 {
1411815216 mouseMode |= SELECT;
1411915217 }
14120
- if ((modifiers & COMMAND) == COMMAND)
15218
+ if ((modifiersex & COMMAND) == COMMAND)
1412115219 {
1412215220 mouseMode |= SELECT;
1412315221 }
14124
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15222
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
1412515223 {
1412615224 mouseMode &= ~VR;
1412715225 mouseMode |= TRANSLATE;
....@@ -14150,10 +15248,10 @@
1415015248
1415115249 if (isRenderer) //
1415215250 {
14153
- SetMouseMode(modifiers);
15251
+ SetMouseMode(0, modifiers);
1415415252 }
1415515253
14156
- theRenderer.keyPressed(key);
15254
+ Globals.theRenderer.keyPressed(key);
1415715255 }
1415815256
1415915257 int kompactbit = 4; // power bit
....@@ -14165,7 +15263,7 @@
1416515263 float SATPOW = 1; // 2; // 0.5f;
1416615264 float BRIPOW = 1; // 0.5f; // 0.5f;
1416715265
14168
- void keyPressed(int key)
15266
+ public void keyPressed(int key)
1416915267 {
1417015268 if (key >= '0' && key <= '5')
1417115269 clampbit = (key-'0');
....@@ -14212,7 +15310,8 @@
1421215310 // break;
1421315311 case 'T':
1421415312 CACHETEXTURE ^= true;
14215
- textures.clear();
15313
+ texturepigment.clear();
15314
+ texturebump.clear();
1421615315 // repaint();
1421715316 break;
1421815317 case 'Y':
....@@ -14222,8 +15321,8 @@
1422215321 case 'K':
1422315322 KOMPACTTEXTURE ^= true;
1422415323 //textures.clear();
14225
- break;
14226
- case 'P': // Texture Projection macros
15324
+ // break;
15325
+ //case 'P': // Texture Projection macros
1422715326 // SAVETEXTURE ^= true;
1422815327 macromode = true;
1422915328 Udebug = Vdebug = NORMALdebug = false; programInitialized = false;
....@@ -14297,7 +15396,9 @@
1429715396 case 'E' : COMPACT ^= true;
1429815397 repaint();
1429915398 break;
14300
- case 'W' : DEBUGHSB ^= true;
15399
+ case 'W' : // Wide Window (fullscreen)
15400
+ //DEBUGHSB ^= true;
15401
+ ObjEditor.theFrame.ToggleFullScreen();
1430115402 repaint();
1430215403 break;
1430315404 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14322,8 +15423,8 @@
1432215423 RevertCamera();
1432315424 repaint();
1432415425 break;
14325
- case 'L':
1432615426 case 'l':
15427
+ //case 'L':
1432715428 if (lightMode)
1432815429 {
1432915430 lightMode = false;
....@@ -14342,7 +15443,7 @@
1434215443 targetLookAt.set(manipCamera.lookAt);
1434315444 repaint();
1434415445 break;
14345
- case 'p':
15446
+ case 'P': // p':
1434615447 // c'est quoi ca au juste? spherical ^= true;
1434715448 Skinshader ^= true; programInitialized = false;
1434815449 repaint();
....@@ -14387,20 +15488,24 @@
1438715488 OCCLUSION_CULLING ^= true;
1438815489 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1438915490 break;
14390
- case '0': envyoff ^= true; repaint(); break;
15491
+ //case '0': envyoff ^= true; repaint(); break;
1439115492 case '1':
1439215493 case '2':
1439315494 case '3':
1439415495 case '4':
1439515496 case '5':
14396
- newenvy = Character.getNumericValue(key);
14397
- repaint();
14398
- break;
1439915497 case '6':
1440015498 case '7':
1440115499 case '8':
1440215500 case '9':
14403
- BGcolor = (key - '6')/3.f;
15501
+ if (true) // envyoff)
15502
+ {
15503
+ BGcolor = (key - '1')/8.f;
15504
+ }
15505
+ else
15506
+ {
15507
+ //newenvy = Character.getNumericValue(key);
15508
+ }
1440415509 repaint();
1440515510 break;
1440615511 case '!':
....@@ -14466,9 +15571,9 @@
1446615571 case '_':
1446715572 kompactbit = 5;
1446815573 break;
14469
- case '+':
14470
- kompactbit = 6;
14471
- break;
15574
+// case '+':
15575
+// kompactbit = 6;
15576
+// break;
1447215577 case ' ':
1447315578 lightMode ^= true;
1447415579 Globals.lighttouched = true;
....@@ -14480,13 +15585,14 @@
1448015585 case ESC:
1448115586 RENDERPROGRAM += 1;
1448215587 RENDERPROGRAM %= 3;
15588
+
1448315589 repaint();
1448415590 break;
1448515591 case 'Z':
1448615592 //RESIZETEXTURE ^= true;
1448715593 //break;
1448815594 case 'z':
14489
- RENDERSHADOW ^= true;
15595
+ Globals.RENDERSHADOW ^= true;
1449015596 Globals.lighttouched = true;
1449115597 repaint();
1449215598 break;
....@@ -14519,8 +15625,9 @@
1451915625 case DELETE:
1452015626 ClearSelection();
1452115627 break;
14522
- /*
1452315628 case '+':
15629
+
15630
+ /*
1452415631 //fontsize += 1;
1452515632 bbzoom *= 2;
1452615633 repaint();
....@@ -14537,17 +15644,17 @@
1453715644 case '=':
1453815645 IncDepth();
1453915646 //fontsize += 1;
14540
- object.editWindow.refreshContents(true);
15647
+ object.GetWindow().refreshContents(true);
1454115648 maskbit = 6;
1454215649 break;
1454315650 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1454415651 DecDepth();
1454515652 maskbit = 5;
1454615653 //if(fontsize > 1) fontsize -= 1;
14547
- if (object.editWindow == null)
14548
- new Exception().printStackTrace();
14549
- else
14550
- object.editWindow.refreshContents(true);
15654
+// if (object.editWindow == null)
15655
+// new Exception().printStackTrace();
15656
+// else
15657
+ object.GetWindow().refreshContents(true);
1455115658 break;
1455215659 case '{':
1455315660 manipCamera.shaper_fovy /= 1.1;
....@@ -14602,6 +15709,7 @@
1460215709 }
1460315710 //System.out.println("shaper_fovy = " + manipCamera.shaper_fovy);
1460415711 }
15712
+
1460515713 static double OCCLUSIONBOOST = 1; // 0.5;
1460615714
1460715715 void keyReleased(int key, int modifiers)
....@@ -14609,11 +15717,11 @@
1460915717 //mode = ROTATE;
1461015718 if ((MODIFIERS & COMMAND) == 0) // VR??
1461115719 {
14612
- SetMouseMode(modifiers);
15720
+ SetMouseMode(0, modifiers);
1461315721 }
1461415722 }
1461515723
14616
- protected void processKeyEvent(KeyEvent e)
15724
+ public void processKeyEvent(KeyEvent e)
1461715725 {
1461815726 switch (e.getID())
1461915727 {
....@@ -14743,8 +15851,9 @@
1474315851
1474415852 protected void processMouseMotionEvent(MouseEvent e)
1474515853 {
14746
- //System.out.println("processMouseMotionEvent: " + mouseMode);
14747
- if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15854
+ //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
15855
+ //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15856
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1474815857 {
1474915858 mouseMoved(e);
1475015859 } else
....@@ -14769,11 +15878,12 @@
1476915878 }
1477015879 */
1477115880
14772
- object.editWindow.EditSelection();
15881
+ object.GetWindow().EditSelection(false);
1477315882 }
1477415883
1477515884 void SelectParent()
1477615885 {
15886
+ new Exception().printStackTrace();
1477715887 System.exit(0);
1477815888 Composite group = (Composite) object;
1477915889 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -14785,10 +15895,10 @@
1478515895 {
1478615896 //selectees.remove(i);
1478715897 System.out.println("select parent of " + elem);
14788
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15898
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1478915899 } else
1479015900 {
14791
- group.editWindow.Select(elem.GetTreePath(), first, true);
15901
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1479215902 }
1479315903
1479415904 first = false;
....@@ -14797,6 +15907,7 @@
1479715907
1479815908 void SelectChildren()
1479915909 {
15910
+ new Exception().printStackTrace();
1480015911 System.exit(0);
1480115912 /*
1480215913 Composite group = (Composite) object;
....@@ -14829,12 +15940,12 @@
1482915940 for (int j = 0; j < group.children.size(); j++)
1483015941 {
1483115942 elem = (Object3D) group.children.elementAt(j);
14832
- object.editWindow.Select(elem.GetTreePath(), first, true);
15943
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1483315944 first = false;
1483415945 }
1483515946 } else
1483615947 {
14837
- object.editWindow.Select(elem.GetTreePath(), first, true);
15948
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1483815949 }
1483915950
1484015951 first = false;
....@@ -14845,21 +15956,21 @@
1484515956 {
1484615957 //Composite group = (Composite) object;
1484715958 Object3D group = object;
14848
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15959
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1484915960 }
1485015961
1485115962 void ResetTransform(int mask)
1485215963 {
1485315964 //Composite group = (Composite) object;
1485415965 Object3D group = object;
14855
- group.editWindow.ResetTransform(mask);
15966
+ group.GetWindow().ResetTransform(mask);
1485615967 }
1485715968
1485815969 void FlipTransform()
1485915970 {
1486015971 //Composite group = (Composite) object;
1486115972 Object3D group = object;
14862
- group.editWindow.FlipTransform();
15973
+ group.GetWindow().FlipTransform();
1486315974 // group.editWindow.ReduceMesh(true);
1486415975 }
1486515976
....@@ -14867,7 +15978,7 @@
1486715978 {
1486815979 //Composite group = (Composite) object;
1486915980 Object3D group = object;
14870
- group.editWindow.PrintMemory();
15981
+ group.GetWindow().PrintMemory();
1487115982 // group.editWindow.ReduceMesh(true);
1487215983 }
1487315984
....@@ -14875,7 +15986,7 @@
1487515986 {
1487615987 //Composite group = (Composite) object;
1487715988 Object3D group = object;
14878
- group.editWindow.ResetCentroid();
15989
+ group.GetWindow().ResetCentroid();
1487915990 }
1488015991
1488115992 void IncDepth()
....@@ -14957,11 +16068,11 @@
1495716068
1495816069 int width = getBounds().width;
1495916070 int height = getBounds().height;
14960
- ClickInfo info = new ClickInfo();
14961
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1496216071 //Image img = CreateImage(width, height);
1496316072 //System.out.println("width = " + width + "; height = " + height + "\n");
16073
+
1496416074 Graphics gr = g; // img.getGraphics();
16075
+
1496516076 if (!hasMarquee)
1496616077 {
1496716078 if (Xmin < Xmax) // !locked)
....@@ -15033,44 +16144,92 @@
1503316144 }
1503416145 if (object != null && !hasMarquee)
1503516146 {
16147
+ if (object.clickInfo == null)
16148
+ object.clickInfo = new ClickInfo();
16149
+ ClickInfo info = object.clickInfo;
16150
+ //ClickInfo info = new ClickInfo();
16151
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16152
+
1503616153 if (isRenderer)
1503716154 {
15038
- info.flags++;
16155
+ object.clickInfo.flags++;
1503916156 double frameAspect = (double) width / (double) height;
1504016157 if (frameAspect > renderCamera.aspect)
1504116158 {
1504216159 int desired = (int) ((double) height * renderCamera.aspect);
15043
- info.bounds.width -= width - desired;
15044
- info.bounds.x += (width - desired) / 2;
16160
+ object.clickInfo.bounds.width -= width - desired;
16161
+ object.clickInfo.bounds.x += (width - desired) / 2;
1504516162 } else
1504616163 {
1504716164 int desired = (int) ((double) width / renderCamera.aspect);
15048
- info.bounds.height -= height - desired;
15049
- info.bounds.y += (height - desired) / 2;
16165
+ object.clickInfo.bounds.height -= height - desired;
16166
+ object.clickInfo.bounds.y += (height - desired) / 2;
1505016167 }
1505116168 }
15052
- info.g = gr;
15053
- info.camera = renderCamera;
16169
+
16170
+ object.clickInfo.g = gr;
16171
+ object.clickInfo.camera = renderCamera;
1505416172 /*
1505516173 // Memory intensive (brep.verticescopy)
1505616174 if (!(object instanceof Composite))
1505716175 object.draw(info, 0, false); // SLOW :
1505816176 */
15059
- if (!isRenderer)
16177
+ if (!isRenderer) // && drag)
1506016178 {
15061
- object.drawEditHandles(info, 0);
16179
+ Grafreed.Assert(object != null);
16180
+ Grafreed.Assert(object.selection != null);
16181
+ if (object.selection.Size() > 0)
16182
+ {
16183
+ int hitSomething = object.selection.get(0).hitSomething;
16184
+
16185
+ object.clickInfo.DX = 0;
16186
+ object.clickInfo.DY = 0;
16187
+ object.clickInfo.W = 1;
16188
+ if (hitSomething == Object3D.hitCenter)
16189
+ {
16190
+ info.DX = X;
16191
+ if (X != 0)
16192
+ info.DX -= info.bounds.width/2;
16193
+
16194
+ info.DY = Y;
16195
+ if (Y != 0)
16196
+ info.DY -= info.bounds.height/2;
16197
+ }
16198
+
16199
+ object.drawEditHandles(//info,
16200
+ 0);
16201
+
16202
+ if (drag && (X != 0 || Y != 0))
16203
+ {
16204
+ switch (hitSomething)
16205
+ {
16206
+ case Object3D.hitCenter: gr.setColor(Color.white);
16207
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16208
+ break;
16209
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16210
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16211
+ break;
16212
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16213
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16214
+ break;
16215
+ }
16216
+
16217
+ }
16218
+ }
1506216219 }
1506316220 }
16221
+
1506416222 if (isRenderer)
1506516223 {
1506616224 //gr.setColor(Color.black);
1506716225 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1506816226 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1506916227 }
16228
+
1507016229 if (hasMarquee)
1507116230 {
1507216231 gr.setXORMode(Color.white);
15073
- gr.setColor(Color.red);
16232
+ gr.setColor(Color.white);
1507416233 if (!firstime)
1507516234 {
1507616235 gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH);
....@@ -15179,6 +16338,7 @@
1517916338 public boolean mouseDown(Event evt, int x, int y)
1518016339 {
1518116340 System.out.println("mouseDown: " + evt);
16341
+ System.exit(0);
1518216342 /*
1518316343 locked = true;
1518416344 drag = false;
....@@ -15222,7 +16382,7 @@
1522216382 {
1522316383 keyPressed(0, modifiers);
1522416384 }
15225
- clickStart(x, y, modifiers);
16385
+ // clickStart(x, y, modifiers);
1522616386 return true;
1522716387 }
1522816388
....@@ -15340,7 +16500,7 @@
1534016500 {
1534116501 keyReleased(0, 0);
1534216502 }
15343
- drag(x, y, modifiers);
16503
+ drag(x, y, 0, modifiers);
1534416504 return true;
1534516505 }
1534616506
....@@ -15472,7 +16632,7 @@
1547216632 Object3D object;
1547316633 static Object3D trackedobject;
1547416634 Camera renderCamera; // Light or Eye (or Occlusion)
15475
- /*static*/ Camera manipCamera; // Light or Eye
16635
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1547616636 /*static*/ Camera eyeCamera;
1547716637 /*static*/ Camera lightCamera;
1547816638 int cameracount;
....@@ -15536,6 +16696,8 @@
1553616696 private /*static*/ boolean firstime;
1553716697 private /*static*/ cVector newView = new cVector();
1553816698 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16699
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16700
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1553916701 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1554016702 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1554116703 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -15548,29 +16710,67 @@
1554816710 {
1554916711 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1555016712
16713
+ int usedsuf = 0;
16714
+
1555116715 for (int i = 0; i < suffixes.length; i++)
1555216716 {
15553
- String resourceName = basename + suffixes[i] + "." + suffix;
15554
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
15555
- mipmapped,
15556
- FileUtil.getFileSuffix(resourceName));
15557
- if (data == null)
16717
+ String[] suffixe = suffixes;
16718
+ String[] fallback = suffixes2;
16719
+ String[] fallfallback = suffixes3;
16720
+
16721
+ for (int c=usedsuf; --c>=0;)
1555816722 {
15559
- throw new IOException("Unable to load texture " + resourceName);
16723
+// String[] temp = suffixe;
16724
+// suffixe = fallback;
16725
+// fallback = fallfallback;
16726
+// fallfallback = temp;
1556016727 }
16728
+
16729
+ String resourceName = basename + suffixe[i] + "." + suffix;
16730
+ TextureData data;
16731
+
16732
+ try
16733
+ {
16734
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16735
+ mipmapped,
16736
+ FileUtil.getFileSuffix(resourceName));
16737
+ }
16738
+ catch (Exception e)
16739
+ {
16740
+ try
16741
+ {
16742
+ resourceName = basename + fallback[i] + "." + suffix;
16743
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16744
+ mipmapped,
16745
+ FileUtil.getFileSuffix(resourceName));
16746
+ }
16747
+ catch (Exception e2)
16748
+ {
16749
+ resourceName = basename + fallfallback[i] + "." + suffix;
16750
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16751
+ mipmapped,
16752
+ FileUtil.getFileSuffix(resourceName));
16753
+ }
16754
+ }
16755
+
1556116756 //System.out.println("Target = " + targets[i]);
1556216757 cubemap.updateImage(data, targets[i]);
1556316758 }
1556416759
1556516760 return cubemap;
1556616761 }
16762
+
1556716763 int bigsphere = -1;
1556816764
1556916765 float BGcolor = 0.5f;
1557016766
15571
- private void DrawSkyBox(GL gl)
16767
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16768
+
16769
+ private void DrawSkyBox(GL gl, float ratio)
1557216770 {
15573
- if (envyoff || cubemap == null)
16771
+ if (//envyoff ||
16772
+ WIREFRAME ||
16773
+ cubemap == null)
1557416774 {
1557516775 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1557616776 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -15585,7 +16785,17 @@
1558516785 // Compensates for ExaminerViewer's modification of modelview matrix
1558616786 gl.glMatrixMode(GL.GL_MODELVIEW);
1558716787 gl.glLoadIdentity();
16788
+ gl.glScalef(1,ratio,1);
1558816789
16790
+// colorV[0] = 2;
16791
+// colorV[1] = 2;
16792
+// colorV[2] = 2;
16793
+// colorV[3] = 1;
16794
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16795
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16796
+//
16797
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16798
+
1558916799 //gl.glActiveTexture(GL.GL_TEXTURE1);
1559016800 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1559116801
....@@ -15617,6 +16827,7 @@
1561716827 {
1561816828 gl.glScalef(1.0f, -1.0f, 1.0f);
1561916829 }
16830
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1562016831 gl.glMultMatrixd(viewrot_1, 0);
1562116832 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1562216833 //viewer.updateInverseRotation(gl);
....@@ -15657,7 +16868,8 @@
1565716868 gl.glDisable(GL.GL_TEXTURE_GEN_R);
1565816869
1565916870 cubemap.disable();
15660
- ////cubemap.unbind();
16871
+ //cubemap.dispose();
16872
+
1566116873 if (CULLFACE)
1566216874 {
1566316875 gl.glEnable(gl.GL_CULL_FACE);
....@@ -15757,16 +16969,16 @@
1575716969 cStatic.objectstack[materialdepth++] = checker;
1575816970 //System.out.println("material " + material);
1575916971 //Applet3D.tracein(this, selected);
15760
- vector2buffer = checker.projectedVertices;
16972
+ //vector2buffer = checker.projectedVertices;
1576116973
1576216974 //checker.GetMaterial().Draw(this, false); // true);
15763
- DrawMaterial(checker.GetMaterial(), false); // true);
16975
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1576416976
1576516977 materialdepth -= 1;
1576616978 if (materialdepth > 0)
1576716979 {
15768
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
15769
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
16980
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16981
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1577016982 }
1577116983 //checker.GetMaterial().opacity = 1f;
1577216984 ////checker.GetMaterial().ambient = 1f;
....@@ -15852,6 +17064,14 @@
1585217064 }
1585317065 }
1585417066
17067
+ private Object3D GetFolder()
17068
+ {
17069
+ Object3D folder = object.GetWindow().copy;
17070
+ if (object.GetWindow().copy.selection.Size() > 0)
17071
+ folder = object.GetWindow().copy.selection.elementAt(0);
17072
+ return folder;
17073
+ }
17074
+
1585517075 class SelectBuffer implements GLEventListener
1585617076 {
1585717077
....@@ -15867,7 +17087,7 @@
1586717087 //new Exception().printStackTrace();
1586817088 System.out.println("select buffer init");
1586917089 // Use debug pipeline
15870
- drawable.setGL(new DebugGL(drawable.getGL()));
17090
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1587117091
1587217092 GL gl = drawable.getGL();
1587317093
....@@ -15910,6 +17130,7 @@
1591017130 {
1591117131 if (!selection)
1591217132 {
17133
+ new Exception().printStackTrace();
1591317134 System.exit(0);
1591417135 return;
1591517136 }
....@@ -15930,6 +17151,17 @@
1593017151
1593117152 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1593217153
17154
+ if (PAINTMODE)
17155
+ {
17156
+ if (object.GetWindow().copy.selection.Size() > 0)
17157
+ {
17158
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17159
+
17160
+ // Make what you paint not selectable.
17161
+ paintobj.ResetSelectable();
17162
+ }
17163
+ }
17164
+
1593317165 //int tmp = selection_view;
1593417166 //selection_view = -1;
1593517167 int temp = DrawMode();
....@@ -15941,6 +17173,17 @@
1594117173 // temp = DEFAULT; // patch for selection debug
1594217174 Globals.drawMode = temp; // WARNING
1594317175
17176
+ if (PAINTMODE)
17177
+ {
17178
+ if (object.GetWindow().copy.selection.Size() > 0)
17179
+ {
17180
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17181
+
17182
+ // Revert.
17183
+ paintobj.RestoreSelectable();
17184
+ }
17185
+ }
17186
+
1594417187 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1594517188
1594617189 // trying different ways of getting the depth info over
....@@ -15988,6 +17231,8 @@
1598817231 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1598917232 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1599017233 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
17234
+
17235
+ CreateSelectedPoint();
1599117236
1599217237 // Will fit the mesh !!!
1599317238 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16037,34 +17282,36 @@
1603717282 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]));
1603817283 }
1603917284
16040
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
17285
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1604117286 }
1604217287 }
1604317288
1604417289 if (!movingcamera && !PAINTMODE)
16045
- object.editWindow.ScreenFitPoint(); // fev 2014
17290
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1604617291
16047
- if (PAINTMODE && GrafreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17292
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1604817293 {
16049
- Object3D paintobj = GrafreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17294
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1605017295
16051
- Object3D group = new Object3D("inst" + paintcount++);
17296
+ if (object.GetWindow().copy.selection.Size() > 0)
17297
+ {
17298
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1605217299
16053
- group.CreateMaterial(); // use a void leaf to select instances
16054
-
16055
- group.add(paintobj); // link
16056
-
16057
- object.editWindow.SnapObject(group);
16058
-
16059
- Object3D folder = object.editWindow.copy;
16060
-
16061
- if (object.editWindow.copy.selection.Size() > 0)
16062
- folder = object.editWindow.copy.selection.elementAt(0);
16063
-
16064
- folder.add(group);
16065
-
16066
- object.editWindow.ResetModel();
16067
- object.editWindow.refreshContents();
17300
+ Object3D inst = new Object3D("inst" + paintcount++);
17301
+
17302
+ inst.CreateMaterial(); // use a void leaf to select instances
17303
+
17304
+ inst.add(paintobj); // link
17305
+
17306
+ object.GetWindow().SnapObject(inst);
17307
+
17308
+ Object3D folder = paintFolder; // GetFolder();
17309
+
17310
+ folder.add(inst);
17311
+
17312
+ object.GetWindow().ResetModel();
17313
+ object.GetWindow().refreshContents();
17314
+ }
1606817315 }
1606917316 else
1607017317 paintcount = 0;
....@@ -16103,6 +17350,11 @@
1610317350 //System.out.println("objects[color] = " + objects[color]);
1610417351 //objects[color].Select();
1610517352 indexcount = 0;
17353
+ ObjEditor window = object.GetWindow();
17354
+ if (window != null && deselect)
17355
+ {
17356
+ window.Select(null, deselect, true);
17357
+ }
1610617358 object.Select(color, deselect);
1610717359 }
1610817360
....@@ -16153,6 +17405,7 @@
1615317405
1615417406 public void init(GLAutoDrawable drawable)
1615517407 {
17408
+ if (Globals.DEBUG)
1615617409 System.out.println("shadow buffer init");
1615717410
1615817411 GL gl = drawable.getGL();
....@@ -16202,7 +17455,7 @@
1620217455 gl.glDisable(gl.GL_CULL_FACE);
1620317456 }
1620417457
16205
- if (!RENDERSHADOW)
17458
+ if (!Globals.RENDERSHADOW)
1620617459 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1620717460
1620817461 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -16212,7 +17465,7 @@
1621217465 //gl.glColorMask(false, false, false, false);
1621317466
1621417467 //render_scene_from_light_view(gl, drawable, 0, 0);
16215
- if (RENDERSHADOW && Globals.lighttouched && !movingcamera) // && !parent.IsFreezed())
17468
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1621617469 {
1621717470 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1621817471
....@@ -16381,10 +17634,14 @@
1638117634 gl.glFlush();
1638217635
1638317636 /**/
16384
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17637
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1638517638
16386
- float[] pixels = occlusionsizebuffer.array();
17639
+ float[] depths = occlusiondepthbuffer.array();
1638717640
17641
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17642
+
17643
+ int[] pixels = selectsizebuffer.array();
17644
+
1638817645 double r = 0, g = 0, b = 0;
1638917646
1639017647 double count = 0;
....@@ -16395,7 +17652,7 @@
1639517652
1639617653 double FACTOR = 1;
1639717654
16398
- for (int i = 0; i < pixels.length; i++)
17655
+ for (int i = 0; i < depths.length; i++)
1639917656 {
1640017657 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1640117658 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -16478,7 +17735,7 @@
1647817735
1647917736 double scale = ray.z; // 1; // cos
1648017737
16481
- float depth = pixels[newindex];
17738
+ float depth = depths[newindex];
1648217739
1648317740 /*
1648417741 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -16628,23 +17885,15 @@
1662817885 int AAbuffersize = 0;
1662917886
1663017887 //double[] selectedpoint = new double[3];
16631
- static Superellipsoid selectedpoint = new Superellipsoid();
17888
+ static Superellipsoid selectedpoint;
1663217889 static Sphere previousselectedpoint = null;
16633
- static Sphere debugpointG = new Sphere();
16634
- static Sphere debugpointP = new Sphere();
16635
- static Sphere debugpointC = new Sphere();
16636
- static Sphere debugpointR = new Sphere();
17890
+ static Sphere debugpointG;
17891
+ static Sphere debugpointP;
17892
+ static Sphere debugpointC;
17893
+ static Sphere debugpointR;
1663717894
1663817895 static Sphere debugpoints[] = new Sphere[8];
1663917896
16640
- static
16641
- {
16642
- for (int i=0; i<8; i++)
16643
- {
16644
- debugpoints[i] = new Sphere();
16645
- }
16646
- }
16647
-
1664817897 static void InitPoints(float radius)
1664917898 {
1665017899 for (int i=0; i<8; i++)
....@@ -16683,11 +17932,14 @@
1668317932 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1668417933 static IntBuffer bigAAbuffer;
1668517934 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
16686
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17935
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1668717936 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1668817937 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1668917938 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
16690
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17939
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17940
+
17941
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17942
+
1669117943 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1669217944 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1669317945 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();
....@@ -16696,10 +17948,11 @@
1669617948 static IntBuffer textbuffer = null; // IntBuffer.allocate(TEXT_WIDTH*8*8 * TEXT_HEIGHT);
1669717949 // Depth buffer format
1669817950 //private int depth_format;
16699
- static public void NextIndex(Object3D o, GL gl)
17951
+
17952
+ public void NextIndex()
1670017953 {
1670117954 indexcount+=16;
16702
- gl.glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
17955
+ GetGL().glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
1670317956 //objects[indexcount] = o;
1670417957 //System.out.println("indexcount = " + indexcount);
1670517958 }