Normand Briere
2019-08-13 c67de8aca04d988179191ccb52461af00125920e
CameraPane.java
....@@ -18,7 +18,10 @@
1818 import javax.imageio.ImageIO;
1919 import javax.imageio.ImageWriteParam;
2020 import javax.imageio.ImageWriter;
21
+import javax.imageio.ImageReadParam;
22
+import javax.imageio.ImageReader;
2123 import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
24
+import javax.imageio.stream.ImageInputStream;
2225 import javax.imageio.stream.ImageOutputStream;
2326 import javax.imageio.ImageWriteParam;
2427
....@@ -30,6 +33,7 @@
3033 import java.nio.*;
3134
3235 import gleem.linalg.Mat4f;
36
+import javax.imageio.ImageTypeSpecifier;
3337
3438 class CameraPane extends GLCanvas implements iCameraPane, Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener
3539 {
....@@ -37,7 +41,6 @@
3741 static boolean[] selectedstack = new boolean[65536];
3842 static int materialdepth = 0;
3943
40
- static boolean DEBUG = false;
4144 static boolean FRUSTUM = false; // still bogus true; // frustum culling
4245
4346 // camera change fix
....@@ -45,6 +48,39 @@
4548 static boolean ABORTED = false;
4649
4750 static int STEP = 1;
51
+
52
+ private static BufferedImage CreateBim(byte[] bytes, int width, int height)
53
+ {
54
+ int[] pixels = new int[bytes.length/3];
55
+ for (int i=pixels.length; --i>=0;)
56
+ {
57
+ int i3 = i*3;
58
+ pixels[i] = 0xFF;
59
+ pixels[i] <<= 8;
60
+ pixels[i] |= bytes[i3+2] & 0xFF;
61
+ pixels[i] <<= 8;
62
+ pixels[i] |= bytes[i3+1] & 0xFF;
63
+ pixels[i] <<= 8;
64
+ pixels[i] |= bytes[i3] & 0xFF;
65
+ }
66
+ /*
67
+ int r=0,g=0,b=0,a=0;
68
+ for (int i=0; i<width; i++)
69
+ for (int j=0; j<height; j++)
70
+ {
71
+ int index = j*width+i;
72
+ int p = pixels[index];
73
+ a = ((p>>24) & 0xFF);
74
+ r = ((p>>16) & 0xFF);
75
+ g = ((p>>8) & 0xFF);
76
+ b = (p & 0xFF);
77
+ pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
78
+ }
79
+ /**/
80
+ BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
81
+ rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
82
+ return rendImage;
83
+ }
4884
4985 /*static*/ private boolean CULLFACE = false; // true;
5086 /*static*/ boolean NEAREST = false; // true;
....@@ -56,14 +92,12 @@
5692 static int CURRENTANTIALIAS = 0; // 1;
5793 /*static*/ boolean RENDERSHADOW = true;
5894 /*static*/ int RENDERPROGRAM = 2; // 0 == none, 1 == fast, 2 == normal
59
- static boolean ANIMATION = false;
60
- static String filename;
6195
6296 boolean DISPLAYTEXT = false;
6397 //boolean REDUCETEXTURE = true;
6498 boolean CACHETEXTURE = true;
6599 boolean CLEANCACHE = false; // true;
66
- boolean MIPMAP = false; // true;
100
+ boolean MIPMAP = false; // true; // never works...
67101 boolean COMPRESSTEXTURE = false;
68102 boolean KOMPACTTEXTURE = false; // true;
69103 boolean RESIZETEXTURE = false;
....@@ -76,7 +110,9 @@
76110 //private Mat4f spotlightTransform = new Mat4f();
77111 //private Mat4f spotlightInverseTransform = new Mat4f();
78112 static GLContext glcontext = null;
79
- /*static*/ com.sun.opengl.util.texture.Texture cubemap;
113
+ /*static*/ com.sun.opengl.util.texture.Texture cubemap; // Either custom or rgb
114
+ /*static*/ com.sun.opengl.util.texture.Texture cubemapcustom;
115
+ /*static*/ com.sun.opengl.util.texture.Texture cubemaprgb;
80116 boolean reverseUP = false;
81117 static boolean frozen = false;
82118 boolean enablebackspace = false; // patch for back buffer refresh
....@@ -92,6 +128,8 @@
92128
93129 static int tickcount = 0; // slow pose issue
94130
131
+static boolean BUTTONLESSWHEEL = false;
132
+static boolean ZOOMBOXMODE = false;
95133 static boolean BOXMODE = false;
96134 static boolean IMAGEFLIP = false;
97135 static boolean SMOOTHFOCUS = false;
....@@ -106,7 +144,7 @@
106144 static boolean OEIL = true;
107145 static boolean OEILONCE = false; // do oeilon then oeiloff
108146 static boolean LOOKAT = true;
109
-static boolean RANDOM = true; // false;
147
+static boolean SWITCH = true; // false;
110148 static boolean HANDLES = false; // selection doesn't work!!
111149 static boolean PAINTMODE = false;
112150
....@@ -137,7 +175,7 @@
137175 static boolean doublesided = false; // true; // reversed normals are awful for conformance
138176 boolean anisotropy = true;
139177 boolean softshadow = true; // slower but better false;
140
- boolean opacityhalo = false;
178
+ boolean opacityhalo = false; // reverse the halo effect (e.g. glass)
141179
142180 boolean macromode = false;
143181
....@@ -150,12 +188,25 @@
150188 defaultcaps.setAccumAlphaBits(16);
151189 }
152190
153
- static CameraPane theRenderer;
191
+ private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
192
+
193
+ public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException
194
+ {
195
+ try
196
+ {
197
+ return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
198
+ } catch (IOException e)
199
+ {
200
+ System.out.println("NAME = " + name);
201
+ e.printStackTrace(); // throw new RuntimeException(e);
202
+ return null;
203
+ }
204
+ }
154205
155206 void SetAsGLRenderer(boolean b)
156207 {
157208 isRenderer = b;
158
- theRenderer = this;
209
+ Globals.theRenderer = this;
159210 }
160211
161212 CameraPane(Object3D o, Camera cam, boolean withcontext)
....@@ -170,7 +221,8 @@
170221
171222 SetCamera(cam);
172223
173
- SetLight(new Camera(new cVector(10, 10, -20)));
224
+ // Warning: not used.
225
+ SetLight(new Camera(new cVector(15, 10, -20)));
174226
175227 object = o;
176228
....@@ -193,9 +245,43 @@
193245
194246 /// INTERFACE
195247
248
+ public javax.media.opengl.GL GetGL0()
249
+ {
250
+ return null;
251
+ }
252
+
253
+ public int GenList()
254
+ {
255
+ javax.media.opengl.GL gl = GetGL();
256
+ return gl.glGenLists(1);
257
+ }
258
+
259
+ public void NewList(int id)
260
+ {
261
+ javax.media.opengl.GL gl = GetGL();
262
+ gl.glNewList(id, gl.GL_COMPILE); //_AND_EXECUTE);
263
+ }
264
+
265
+ public void CallList(int id)
266
+ {
267
+ javax.media.opengl.GL gl = GetGL();
268
+ gl.glCallList(id);
269
+ }
270
+
271
+ public void EndList()
272
+ {
273
+ javax.media.opengl.GL gl = GetGL();
274
+ gl.glEndList();
275
+ }
276
+
196277 public boolean IsBoxMode()
197278 {
198279 return BOXMODE;
280
+ }
281
+
282
+ public boolean IsZoomBoxMode()
283
+ {
284
+ return ZOOMBOXMODE;
199285 }
200286
201287 public void ClearDepth()
....@@ -293,7 +379,7 @@
293379 cStatic.objectstack[materialdepth++] = obj;
294380 //System.out.println("material " + material);
295381 //Applet3D.tracein(this, selected);
296
- display.vector2buffer = obj.projectedVertices;
382
+ //display.vector2buffer = obj.projectedVertices;
297383 if (obj instanceof Camera)
298384 {
299385 display.options1[0] = material.shift;
....@@ -302,14 +388,28 @@
302388 display.options1[2] = material.shadowbias;
303389 display.options1[3] = material.aniso;
304390 display.options1[4] = material.anisoV;
391
+// System.out.println("display.options1[0] " + display.options1[0]);
392
+// System.out.println("display.options1[1] " + display.options1[1]);
393
+// System.out.println("display.options1[2] " + display.options1[2]);
394
+// System.out.println("display.options1[3] " + display.options1[3]);
395
+// System.out.println("display.options1[4] " + display.options1[4]);
305396 display.options2[0] = material.opacity;
306397 display.options2[1] = material.diffuse;
307398 display.options2[2] = material.factor;
399
+// System.out.println("display.options2[0] " + display.options2[0]);
400
+// System.out.println("display.options2[1] " + display.options2[1]);
401
+// System.out.println("display.options2[2] " + display.options2[2]);
308402
309403 cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
404
+// System.out.println("display.options3[0] " + display.options3[0]);
405
+// System.out.println("display.options3[1] " + display.options3[1]);
406
+// System.out.println("display.options3[2] " + display.options3[2]);
310407 display.options4[0] = material.cameralight/0.2f;
311408 display.options4[1] = material.subsurface;
312409 display.options4[2] = material.sheen;
410
+// System.out.println("display.options4[0] " + display.options4[0]);
411
+// System.out.println("display.options4[1] " + display.options4[1]);
412
+// System.out.println("display.options4[2] " + display.options4[2]);
313413
314414 // if (display.CURRENTANTIALIAS > 0)
315415 // display.options3[3] /= 4;
....@@ -325,7 +425,7 @@
325425 /**/
326426 } else
327427 {
328
- DrawMaterial(material, selected);
428
+ DrawMaterial(material, selected, obj.projectedVertices);
329429 }
330430 } else
331431 {
....@@ -349,8 +449,8 @@
349449 cStatic.objectstack[materialdepth++] = obj;
350450 //System.out.println("material " + material);
351451 //Applet3D.tracein("selected ", selected);
352
- display.vector2buffer = obj.projectedVertices;
353
- display.DrawMaterial(material, selected);
452
+ //display.vector2buffer = obj.projectedVertices;
453
+ display.DrawMaterial(material, selected, obj.projectedVertices);
354454 }
355455 }
356456
....@@ -367,8 +467,8 @@
367467 materialdepth -= 1;
368468 if (materialdepth > 0)
369469 {
370
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
371
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
470
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
471
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
372472 }
373473 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
374474 } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
....@@ -388,8 +488,8 @@
388488 materialdepth -= 1;
389489 if (materialdepth > 0)
390490 {
391
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
392
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
491
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
492
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
393493 }
394494 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
395495 //else
....@@ -430,10 +530,12 @@
430530 if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
431531 {
432532 //gl.glBegin(gl.GL_TRIANGLES);
433
- boolean hasnorm = pv.norm != null; // && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0);
533
+ boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0)
534
+ // TEST LIVE NORMALS && !obj.dontselect
535
+ ;
434536 if (!hasnorm)
435537 {
436
- // System.out.println("FUCK!!");
538
+ // System.out.println("Mesh normal");
437539 LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
438540 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
439541 LA.vecCross(obj.v0, obj.v1, obj.v2);
....@@ -816,7 +918,7 @@
816918
817919 if ((i % 100) == 0 && i != 0)
818920 {
819
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
921
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
820922 //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
821923 System.out.println((int) (100.0 * i / (br.positions.length / 3)) + "% (" + i + " of " + (br.positions.length / 3) + ")");
822924 }
....@@ -848,7 +950,7 @@
848950
849951 if ((i % 100) == 0 && i != 0)
850952 {
851
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
953
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
852954 //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
853955 System.out.println((int) (100.0 * i / br.VertexCount()) + "% (" + i + " of " + br.VertexCount() + ")");
854956 }
....@@ -1061,8 +1163,345 @@
10611163 gl.glMatrixMode(gl.GL_MODELVIEW);
10621164 }
10631165
1166
+ public void DrawBox(cVector min, cVector max)
1167
+ {
1168
+ javax.media.opengl.GL gl = GetGL();
1169
+ gl.glBegin(gl.GL_LINES);
1170
+
1171
+ gl.glVertex3d(min.x, min.y, min.z);
1172
+ gl.glVertex3d(min.x, min.y, max.z);
1173
+ gl.glVertex3d(min.x, min.y, min.z);
1174
+ gl.glVertex3d(min.x, max.y, min.z);
1175
+ gl.glVertex3d(min.x, min.y, min.z);
1176
+ gl.glVertex3d(max.x, min.y, min.z);
1177
+
1178
+ gl.glVertex3d(max.x, max.y, max.z);
1179
+ gl.glVertex3d(min.x, max.y, max.z);
1180
+ gl.glVertex3d(max.x, max.y, max.z);
1181
+ gl.glVertex3d(max.x, min.y, max.z);
1182
+ gl.glVertex3d(max.x, max.y, max.z);
1183
+ gl.glVertex3d(max.x, max.y, min.z);
1184
+
1185
+ gl.glEnd();
1186
+ }
1187
+
1188
+ public void DrawGeometry(BoundaryRep bRep, boolean flipV, boolean selectmode)
1189
+ {
1190
+ int[] strips = bRep.getRawIndices();
1191
+
1192
+ javax.media.opengl.GL gl = GetGL();
1193
+
1194
+ // TRIANGLE STRIP ARRAY
1195
+ if (bRep.trimmed)
1196
+ {
1197
+ float[] v = bRep.getRawVertices();
1198
+ float[] n = bRep.getRawNormals();
1199
+ float[] c = bRep.getRawColors();
1200
+ float[] uv = bRep.getRawUVMap();
1201
+
1202
+ int count2 = 0;
1203
+ int count3 = 0;
1204
+
1205
+ if (n.length > 0)
1206
+ {
1207
+ for (int i = 0; i < strips.length; i++)
1208
+ {
1209
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1210
+
1211
+ /*
1212
+ boolean locked = false;
1213
+ float eps = 0.1f;
1214
+ boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
1215
+
1216
+ int dot = 0;
1217
+
1218
+ if ((dot&1) == 0)
1219
+ dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
1220
+
1221
+ if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
1222
+ gl.glTexCoord2f((float) qv.s, (float) qv.t);
1223
+ else
1224
+ {
1225
+ locked = true;
1226
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1227
+ }
1228
+ //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
1229
+ gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
1230
+ if (hasnorm)
1231
+ {
1232
+ //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
1233
+ gl.glNormal3f((float) rv.norm.x, (float) rv.norm.y, (float) rv.norm.z);
1234
+ }
1235
+
1236
+ if ((dot&4) == 0)
1237
+ dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
1238
+
1239
+ if (wrap || !locked && (dot&8) != 0)
1240
+ gl.glTexCoord2f((float) rv.s, (float) rv.t);
1241
+ else
1242
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1243
+
1244
+ f.dot = dot;
1245
+ */
1246
+
1247
+ if (!selectmode)
1248
+ {
1249
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1250
+ {
1251
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1252
+ } else
1253
+ {
1254
+ gl.glNormal3f(0, 0, 1);
1255
+ }
1256
+
1257
+ if (c != null)
1258
+ //System.out.println("glcolor = " + c[count3] + ", " + c[count3+1] + ", " + c[count3+2]);
1259
+ {
1260
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1261
+ }
1262
+ }
1263
+
1264
+ if (flipV)
1265
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1266
+ else
1267
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1268
+
1269
+ //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1270
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1271
+
1272
+ count2 += 2;
1273
+ count3 += 3;
1274
+ if (!selectmode)
1275
+ {
1276
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1277
+ {
1278
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1279
+ } else
1280
+ {
1281
+ gl.glNormal3f(0, 0, 1);
1282
+ }
1283
+ if (c != null)
1284
+ {
1285
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1286
+ }
1287
+ }
1288
+
1289
+ if (flipV)
1290
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1291
+ else
1292
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1293
+
1294
+ //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1295
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1296
+
1297
+ count2 += 2;
1298
+ count3 += 3;
1299
+ for (int j = 0; j < strips[i] - 2; j++)
1300
+ {
1301
+ //gl.glTexCoord2d(...);
1302
+ if (!selectmode)
1303
+ {
1304
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1305
+ {
1306
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1307
+ } else
1308
+ {
1309
+ gl.glNormal3f(0, 0, 1);
1310
+ }
1311
+ if (c != null)
1312
+ {
1313
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1314
+ }
1315
+ }
1316
+
1317
+ if (flipV)
1318
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1319
+ else
1320
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1321
+
1322
+ //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
1323
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1324
+
1325
+ count2 += 2;
1326
+ count3 += 3;
1327
+ }
1328
+
1329
+ gl.glEnd();
1330
+ }
1331
+ }
1332
+
1333
+ assert count3 == v.length;
1334
+ }
1335
+ else // !trimmed
1336
+ {
1337
+ int count = 0;
1338
+ for (int i = 0; i < strips.length; i++)
1339
+ {
1340
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1341
+
1342
+ Vertex p = bRep.GetVertex(bRep.indices[count++]);
1343
+ Vertex q = bRep.GetVertex(bRep.indices[count++]);
1344
+
1345
+ drawVertex(gl, p, flipV, selectmode);
1346
+ drawVertex(gl, q, flipV, selectmode);
1347
+
1348
+ for (int j = 0; j < strips[i] - 2; j++)
1349
+ {
1350
+ Vertex r = bRep.GetVertex(bRep.indices[count++]);
1351
+
1352
+ // if (j%2 == 0)
1353
+ // drawFace(p, q, r, display, null);
1354
+ // else
1355
+ // drawFace(p, r, q, display, null);
1356
+
1357
+ // p = q;
1358
+ // q = r;
1359
+ drawVertex(gl, r, flipV, selectmode);
1360
+ }
1361
+
1362
+ gl.glEnd();
1363
+ }
1364
+ }
1365
+ }
1366
+
1367
+ static cSpring.Point3D temp = new cSpring.Point3D();
1368
+ static cSpring.Point3D temp2 = new cSpring.Point3D();
1369
+ static cSpring.Point3D temp3 = new cSpring.Point3D();
1370
+
1371
+ public void DrawDynamicMesh(cMesh mesh)
1372
+ {
1373
+ GL gl = GetGL(); // getGL();
1374
+
1375
+ cSpring.PhysicsController3D Phys = mesh.Phys;
1376
+
1377
+ gl.glDisable(gl.GL_LIGHTING);
1378
+
1379
+ gl.glLineWidth(1);
1380
+ gl.glColor3f(1,1,1);
1381
+ gl.glBegin(gl.GL_LINES);
1382
+ double scale = 0;
1383
+ int count = 0;
1384
+ for (int s=0; s<Phys.allSprings.size(); s++)
1385
+ {
1386
+ cSpring.Spring spring = Phys.allSprings.get(s);
1387
+ if(s == 0)
1388
+ {
1389
+ //System.out.println(" spring : " + spring.a.position + "; " + spring.b.position);
1390
+ }
1391
+ if (mesh.showsprings)
1392
+ {
1393
+ temp.set(spring.a.position);
1394
+ temp.add(spring.b.position);
1395
+ temp.mul(0.5);
1396
+ temp2.set(spring.a.position);
1397
+ temp2.sub(spring.b.position);
1398
+ temp2.mul(spring.restLength/2);
1399
+ temp.sub(temp2);
1400
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1401
+ temp.add(temp2);
1402
+ temp.add(temp2);
1403
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1404
+ }
1405
+
1406
+ if (spring.isHandle)
1407
+ continue;
1408
+
1409
+ //if (scale < spring.restLength)
1410
+ scale += spring.restLength;
1411
+ count++;
1412
+ }
1413
+ gl.glEnd();
1414
+
1415
+ if (count == 0)
1416
+ scale = 0.01;
1417
+ else
1418
+ scale /= count * 3;
1419
+
1420
+ //scale = 0.25;
1421
+
1422
+ if (mesh.ShowInfo())
1423
+ {
1424
+ gl.glLineWidth(4);
1425
+ for (int s=0; s<Phys.allNodes.size(); s++)
1426
+ {
1427
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1428
+ if (node.mass == 0)
1429
+ continue;
1430
+
1431
+ int i = node.springs==null?-1:node.springs.size();
1432
+ gl.glColor3f((i>>2)&1,(i>>1)&1,i&1);
1433
+ //temp.set(node.springForce.x, node.springForce.y, node.springForce.z);
1434
+ //temp.normalize();
1435
+ //gl.glColor3d((temp.x+1)/2, (temp.y+1)/2, (temp.z+1)/2);
1436
+ gl.glBegin(gl.GL_LINES);
1437
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1438
+ //gl.glVertex3d(node.position.x + node.normal.x*scale, node.position.y + node.normal.y*scale, node.position.z + node.normal.z*scale);
1439
+ gl.glVertex3d(node.position.x + mesh.bRep.GetVertex(s).norm.x*scale,
1440
+ node.position.y + mesh.bRep.GetVertex(s).norm.y*scale,
1441
+ node.position.z + mesh.bRep.GetVertex(s).norm.z*scale);
1442
+ gl.glEnd();
1443
+ }
1444
+
1445
+ gl.glLineWidth(8);
1446
+ for (int s=0; s<Phys.allNodes.size(); s++)
1447
+ {
1448
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1449
+
1450
+ if (node.springs != null)
1451
+ {
1452
+ for (int i=0; i<node.springs.size(); i+=1)
1453
+ {
1454
+ cSpring.DynamicNode f = node.springs.get(i).GetOther(node);
1455
+
1456
+ int c = i+1;
1457
+ // c = node.springs.get(i).nbcopies;
1458
+
1459
+ gl.glColor3f((c>>2)&1,(c>>1)&1,c&1);
1460
+ gl.glBegin(gl.GL_LINES);
1461
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1462
+ gl.glVertex3d(f.position.x/3+node.position.x*2/3, f.position.y/3+node.position.y*2/3, f.position.z/3+node.position.z*2/3);
1463
+ gl.glEnd();
1464
+ }
1465
+ }
1466
+ }
1467
+
1468
+ gl.glLineWidth(1);
1469
+ }
1470
+
1471
+ gl.glEnable(gl.GL_LIGHTING);
1472
+ }
1473
+
10641474 /// INTERFACE
10651475
1476
+ public void StartTriangles()
1477
+ {
1478
+ javax.media.opengl.GL gl = GetGL();
1479
+ gl.glBegin(gl.GL_TRIANGLES);
1480
+ }
1481
+
1482
+ public void EndTriangles()
1483
+ {
1484
+ GetGL().glEnd();
1485
+ }
1486
+
1487
+ void drawVertex(javax.media.opengl.GL gl, Vertex pv, boolean flipV, boolean selectmode)
1488
+ {
1489
+ if (!selectmode)
1490
+ {
1491
+ gl.glNormal3f((float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
1492
+ gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
1493
+
1494
+ if (flipV)
1495
+ gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
1496
+ else
1497
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1498
+ }
1499
+
1500
+ gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
1501
+ }
1502
+
1503
+ float[] colorV = new float[4];
1504
+
10661505 void SetColor(Object3D obj, Vertex p0)
10671506 {
10681507 CameraPane display = this;
....@@ -1130,8 +1569,6 @@
11301569 {
11311570 return;
11321571 }
1133
-
1134
- float[] colorV = new float[3];
11351572
11361573 if (false) // marked)
11371574 {
....@@ -1240,7 +1677,7 @@
12401677 // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
12411678 }
12421679
1243
- void DrawMaterial(cMaterial material, boolean selected)
1680
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
12441681 {
12451682 CameraPane display = this;
12461683 //new Exception().printStackTrace();
....@@ -1256,18 +1693,18 @@
12561693 //col.getColorComponents(ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB), CameraPane.modelParams0);
12571694 if (!material.multiply)
12581695 {
1259
- display.color = color;
1696
+ display.color = material.color;
12601697 display.saturation = material.modulation;
12611698 }
12621699 else
12631700 {
1264
- display.color *= color*2;
1701
+ display.color *= material.color*2;
12651702 display.saturation *= material.modulation*2;
12661703 }
12671704
12681705 cColor.HSBtoRGB(display.color, display.saturation, 1, display.modelParams0);
12691706
1270
- float[] colorV = GrafreeD.colorV;
1707
+ float[] colorV = Grafreed.colorV;
12711708
12721709 /**/
12731710 if (display.DrawMode() == display.DEFAULT) // && display.RENDERPROGRAM == 0)
....@@ -1275,7 +1712,7 @@
12751712 colorV[0] = display.modelParams0[0] * material.diffuse;
12761713 colorV[1] = display.modelParams0[1] * material.diffuse;
12771714 colorV[2] = display.modelParams0[2] * material.diffuse;
1278
- colorV[3] = material.opacity;
1715
+ colorV[3] = 1; // material.opacity;
12791716
12801717 gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
12811718 //System.out.println("Opacity = " + opacity);
....@@ -1383,9 +1820,9 @@
13831820 display.modelParams7[2] = 0;
13841821 display.modelParams7[3] = 0;
13851822
1386
- display.modelParams6[0] = 100; // criss de bug de bump
1823
+ //display.modelParams6[0] = 100; // criss de bug de bump
13871824
1388
- Object3D.cVector2[] extparams = display.vector2buffer;
1825
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
13891826 if (extparams != null && extparams.length > 0 && extparams[0] != null)
13901827 {
13911828 display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
....@@ -1527,7 +1964,7 @@
15271964 void PushMatrix(double[][] matrix)
15281965 {
15291966 // GrafreeD.tracein(matrix);
1530
- PushMatrix(matrix,1);
1967
+ PushMatrix(matrix, 1);
15311968 }
15321969
15331970 void PushMatrix()
....@@ -1624,7 +2061,7 @@
16242061
16252062 static int camerachangeframe;
16262063
1627
- boolean SetCamera(Camera cam)
2064
+ public boolean SetCamera(Camera cam)
16282065 {
16292066 // may 2014 if (cam == cameras[0] || cam == cameras[1])
16302067 // return false;
....@@ -1681,7 +2118,7 @@
16812118 //System.err.println("Oeil on");
16822119 OEIL = true;
16832120 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
1684
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2121
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
16852122 //pingthread.StepToTarget(true);
16862123 }
16872124
....@@ -1752,33 +2189,6 @@
17522189 mainDL ^= true;
17532190 }
17542191
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
-
17822192 void ToggleFullScreen()
17832193 {
17842194 FULLSCREEN ^= true;
....@@ -1789,72 +2199,94 @@
17892199 Globals.CROWD ^= true;
17902200 }
17912201
1792
- void ToggleInertia()
1793
- {
1794
- INERTIA ^= true;
1795
- }
1796
-
17972202 void ToggleLocal()
17982203 {
17992204 LOCALTRANSFORM ^= true;
18002205 }
18012206
1802
- void ToggleFast()
2207
+ public void ToggleTexture()
2208
+ {
2209
+ textureon ^= true;
2210
+ }
2211
+
2212
+ public void ToggleLive()
2213
+ {
2214
+ Globals.setLIVE(Globals.isLIVE() ^ true);
2215
+
2216
+ System.err.println("LIVE = " + Globals.isLIVE());
2217
+
2218
+ if (!Globals.isLIVE()) // save sound
2219
+ Grafreed.savesound = true; // wav.save();
2220
+ // else
2221
+ repaint(); // start loop // may 2013
2222
+ }
2223
+
2224
+ public void ToggleSupport()
2225
+ {
2226
+ SUPPORT ^= true;
2227
+ }
2228
+
2229
+ public void ToggleAbort()
2230
+ {
2231
+ ABORTMODE ^= true;
2232
+ }
2233
+
2234
+ public void ToggleInertia()
2235
+ {
2236
+ INERTIA ^= true;
2237
+ }
2238
+
2239
+ public void ToggleFast()
18032240 {
18042241 FAST ^= true;
18052242 }
18062243
1807
- void ToggleSlowPose()
2244
+ public void ToggleSlowPose()
18082245 {
18092246 SLOWPOSE ^= true;
18102247 }
18112248
1812
- void ToggleFootContact()
1813
- {
1814
- FOOTCONTACT ^= true;
1815
- }
1816
-
1817
- void ToggleBoxMode()
2249
+ public void ToggleBoxMode()
18182250 {
18192251 BOXMODE ^= true;
18202252 }
18212253
1822
- void ToggleSmoothFocus()
2254
+ public void ToggleZoomBoxMode()
2255
+ {
2256
+ ZOOMBOXMODE ^= true;
2257
+ }
2258
+
2259
+ public void ToggleSmoothFocus()
18232260 {
18242261 SMOOTHFOCUS ^= true;
18252262 }
18262263
1827
- void ToggleImageFlip()
2264
+ public void ToggleImageFlip()
18282265 {
18292266 IMAGEFLIP ^= true;
18302267 }
18312268
1832
- void ToggleSpeakerMocap()
2269
+ public void ToggleSpeakerMocap()
18332270 {
18342271 SPEAKERMOCAP ^= true;
18352272 }
18362273
1837
- void ToggleSpeakerCamera()
2274
+ public void ToggleSpeakerCamera()
18382275 {
18392276 SPEAKERCAMERA ^= true;
18402277 }
18412278
1842
- void ToggleSpeakerFocus()
2279
+ public void ToggleSpeakerFocus()
18432280 {
18442281 SPEAKERFOCUS ^= true;
18452282 }
18462283
1847
- void ToggleDebug()
1848
- {
1849
- DEBUG ^= true;
1850
- }
1851
-
1852
- void ToggleFrustum()
2284
+ public void ToggleFrustum()
18532285 {
18542286 FRUSTUM ^= true;
18552287 }
18562288
1857
- void ToggleTrack()
2289
+ public void ToggleTrack()
18582290 {
18592291 TRACK ^= true;
18602292 if (TRACK)
....@@ -1873,25 +2305,35 @@
18732305 repaint();
18742306 }
18752307
1876
- void ToggleTrackOnce()
2308
+ public void ToggleTrackOnce()
18772309 {
18782310 TRACKONCE ^= true;
18792311 }
18802312
1881
- void ToggleShadowTrack()
2313
+ public void ToggleShadowTrack()
18822314 {
18832315 SHADOWTRACK ^= true;
18842316 repaint();
18852317 }
18862318
1887
- void ToggleOeil()
2319
+ public void ToggleOeil()
18882320 {
18892321 OEIL ^= true;
18902322 }
18912323
1892
- void ToggleOeilOnce()
2324
+ public void ToggleOeilOnce()
18932325 {
18942326 OEILONCE ^= true;
2327
+ }
2328
+
2329
+ void ToggleFootContact()
2330
+ {
2331
+ FOOTCONTACT ^= true;
2332
+ }
2333
+
2334
+ void ToggleDebug()
2335
+ {
2336
+ Globals.DEBUG ^= true;
18952337 }
18962338
18972339 void ToggleLookAt()
....@@ -1899,9 +2341,9 @@
18992341 LOOKAT ^= true;
19002342 }
19012343
1902
- void ToggleRandom()
2344
+ void ToggleSwitch()
19032345 {
1904
- RANDOM ^= true;
2346
+ SWITCH ^= true;
19052347 }
19062348
19072349 void ToggleHandles()
....@@ -1909,10 +2351,17 @@
19092351 HANDLES ^= true;
19102352 }
19112353
2354
+ Object3D paintFolder;
2355
+
19122356 void TogglePaint()
19132357 {
19142358 PAINTMODE ^= true;
19152359 paintcount = 0;
2360
+
2361
+ if (PAINTMODE)
2362
+ {
2363
+ paintFolder = GetFolder();
2364
+ }
19162365 }
19172366
19182367 void SwapCamera(int a, int b)
....@@ -2008,7 +2457,22 @@
20082457 {
20092458 return currentGL;
20102459 }
2011
-
2460
+
2461
+ static private BufferedImage CreateBim(TextureData texturedata)
2462
+ {
2463
+ Grafreed.Assert(texturedata != null);
2464
+
2465
+ int width = texturedata.getWidth();
2466
+ int height = texturedata.getHeight();
2467
+
2468
+ Buffer buffer = texturedata.getBuffer();
2469
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2470
+
2471
+ byte[] bytes = bytebuf.array();
2472
+
2473
+ return CreateBim(bytes, width, height);
2474
+ }
2475
+
20122476 /**/
20132477 class CacheTexture
20142478 {
....@@ -2017,28 +2481,31 @@
20172481
20182482 int resolution;
20192483
2020
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2484
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
20212485 {
2022
- texture = tex;
2486
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2487
+ texturedata = texdata;
20232488 resolution = res;
20242489 }
20252490 }
20262491 /**/
20272492
20282493 // 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>();
2494
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2495
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2496
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2497
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2498
+
20322499 int pigmentdepth = 0;
20332500 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
20342501 int bumpdepth = 0;
20352502 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
20362503 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
20372504 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2038
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2505
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
20392506 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
20402507
2041
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2508
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
20422509 {
20432510 TextureData texturedata = null;
20442511
....@@ -2057,13 +2524,34 @@
20572524 if (bump)
20582525 texturedata = ConvertBump(texturedata, false);
20592526
2060
- com.sun.opengl.util.texture.Texture texture =
2061
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2527
+// com.sun.opengl.util.texture.Texture texture =
2528
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
20622529
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);
2530
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2531
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
20652532
2066
- return texture;
2533
+ return texturedata;
2534
+ }
2535
+
2536
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2537
+ {
2538
+ TextureData texturedata = null;
2539
+
2540
+ try
2541
+ {
2542
+ texturedata =
2543
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2544
+ bim,
2545
+ true);
2546
+ } catch (Exception e)
2547
+ {
2548
+ throw new javax.media.opengl.GLException(e);
2549
+ }
2550
+
2551
+ if (bump)
2552
+ texturedata = ConvertBump(texturedata, false);
2553
+
2554
+ return texturedata;
20672555 }
20682556
20692557 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3136,6 +3624,8 @@
31363624
31373625 System.out.println("LOADING TEXTURE : " + name);
31383626
3627
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3628
+
31393629 //
31403630 if (false) // compressbit > 0)
31413631 {
....@@ -3840,6 +4330,7 @@
38404330
38414331 com.sun.opengl.util.texture.Texture CompressTexture2(String name)
38424332 {
4333
+ new Exception().printStackTrace();
38434334 System.exit(0);
38444335 com.sun.opengl.util.texture.Texture texture = null;
38454336
....@@ -7533,7 +8024,7 @@
75338024 String pigment = Object3D.GetPigment(tex);
75348025 String bump = Object3D.GetBump(tex);
75358026
7536
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8027
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
75378028 {
75388029 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
75398030 // System.out.println("; bump = " + bump);
....@@ -7548,11 +8039,69 @@
75488039 pigment = null;
75498040 }
75508041
7551
- ReleaseTexture(bump, true);
7552
- ReleaseTexture(pigment, false);
8042
+ ReleaseTexture(tex, true);
8043
+ ReleaseTexture(tex, false);
75538044 }
75548045
7555
- void ReleaseTexture(String tex, boolean bump)
8046
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
8047
+ {
8048
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8049
+ {
8050
+ return;
8051
+ }
8052
+
8053
+ if (tex == null)
8054
+ {
8055
+ ReleaseTexture(null, false);
8056
+ return;
8057
+ }
8058
+
8059
+ String pigment = Object3D.GetPigment(tex);
8060
+
8061
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8062
+ {
8063
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8064
+ // System.out.println("; bump = " + bump);
8065
+ }
8066
+
8067
+ if (pigment.equals(""))
8068
+ {
8069
+ pigment = null;
8070
+ }
8071
+
8072
+ ReleaseTexture(tex, false);
8073
+ }
8074
+
8075
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
8076
+ {
8077
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8078
+ {
8079
+ return;
8080
+ }
8081
+
8082
+ if (tex == null)
8083
+ {
8084
+ ReleaseTexture(null, true);
8085
+ return;
8086
+ }
8087
+
8088
+ String bump = Object3D.GetBump(tex);
8089
+
8090
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8091
+ {
8092
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8093
+ // System.out.println("; bump = " + bump);
8094
+ }
8095
+
8096
+ if (bump.equals(""))
8097
+ {
8098
+ bump = null;
8099
+ }
8100
+
8101
+ ReleaseTexture(tex, true);
8102
+ }
8103
+
8104
+ void ReleaseTexture(cTexture tex, boolean bump)
75568105 {
75578106 if (// DrawMode() != 0 || /*tex == null ||*/
75588107 ambientOcclusion ) // || !textureon)
....@@ -7563,7 +8112,7 @@
75638112 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
75648113
75658114 if (tex != null)
7566
- texture = textures.get(tex);
8115
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
75678116
75688117 // //assert( texture != null );
75698118 // if (texture == null)
....@@ -7655,7 +8204,55 @@
76558204 }
76568205 }
76578206
7658
- /*boolean*/ public void BindTextures(cTexture tex, int resolution) // INTERFACE
8207
+ /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
8208
+ {
8209
+// if (// DrawMode() != 0 || /*tex == null ||*/
8210
+// ambientOcclusion ) // || !textureon)
8211
+// {
8212
+// return; // false;
8213
+// }
8214
+//
8215
+// if (tex == null)
8216
+// {
8217
+// BindTexture(null,false,resolution);
8218
+// BindTexture(null,true,resolution);
8219
+// return;
8220
+// }
8221
+//
8222
+// String pigment = Object3D.GetPigment(tex);
8223
+// String bump = Object3D.GetBump(tex);
8224
+//
8225
+// usedtextures.add(pigment);
8226
+// usedtextures.add(bump);
8227
+//
8228
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8229
+// {
8230
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8231
+// // System.out.println("; bump = " + bump);
8232
+// }
8233
+//
8234
+// if (bump.equals(""))
8235
+// {
8236
+// bump = null;
8237
+// }
8238
+// if (pigment.equals(""))
8239
+// {
8240
+// pigment = null;
8241
+// }
8242
+//
8243
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8244
+// BindTexture(pigment, false, resolution);
8245
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8246
+// BindTexture(bump, true, resolution);
8247
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8248
+//
8249
+// return; // true;
8250
+
8251
+ BindPigmentTexture(tex, resolution);
8252
+ BindBumpTexture(tex, resolution);
8253
+ }
8254
+
8255
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
76598256 {
76608257 if (// DrawMode() != 0 || /*tex == null ||*/
76618258 ambientOcclusion ) // || !textureon)
....@@ -7666,17 +8263,47 @@
76668263 if (tex == null)
76678264 {
76688265 BindTexture(null,false,resolution);
7669
- BindTexture(null,true,resolution);
76708266 return;
76718267 }
76728268
76738269 String pigment = Object3D.GetPigment(tex);
8270
+
8271
+ usedtextures.add(tex);
8272
+
8273
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8274
+ {
8275
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8276
+ // System.out.println("; bump = " + bump);
8277
+ }
8278
+
8279
+ if (pigment.equals(""))
8280
+ {
8281
+ pigment = null;
8282
+ }
8283
+
8284
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8285
+ BindTexture(tex, false, resolution);
8286
+ }
8287
+
8288
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8289
+ {
8290
+ if (// DrawMode() != 0 || /*tex == null ||*/
8291
+ ambientOcclusion ) // || !textureon)
8292
+ {
8293
+ return; // false;
8294
+ }
8295
+
8296
+ if (tex == null)
8297
+ {
8298
+ BindTexture(null,true,resolution);
8299
+ return;
8300
+ }
8301
+
76748302 String bump = Object3D.GetBump(tex);
76758303
7676
- usedtextures.put(pigment, pigment);
7677
- usedtextures.put(bump, bump);
8304
+ usedtextures.add(tex);
76788305
7679
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8306
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
76808307 {
76818308 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
76828309 // System.out.println("; bump = " + bump);
....@@ -7686,43 +8313,94 @@
76868313 {
76878314 bump = null;
76888315 }
7689
- if (pigment.equals(""))
7690
- {
7691
- pigment = null;
7692
- }
76938316
7694
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
7695
- BindTexture(pigment, false, resolution);
76968317 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
7697
- BindTexture(bump, true, resolution);
8318
+ BindTexture(tex, true, resolution);
76988319 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
7699
-
7700
- return; // true;
77018320 }
77028321
7703
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution)
8322
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8323
+
8324
+ private boolean FileExists(String tex)
77048325 {
7705
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8326
+ if (missingTextures.contains(tex))
8327
+ {
8328
+ return false;
8329
+ }
8330
+
8331
+ boolean fileExists = new File(tex).exists();
8332
+
8333
+ if (!fileExists)
8334
+ {
8335
+ // If file exists, the "new File()" is not executed sgain
8336
+ missingTextures.add(tex);
8337
+ }
8338
+
8339
+ return fileExists;
8340
+ }
8341
+
8342
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
8343
+ {
8344
+ CacheTexture texturecache = null;
77068345
77078346 if (tex != null)
77088347 {
7709
- String texname = tex;
8348
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8349
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
77108350
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;
8351
+ if (texname.equals("") && texdata == null)
8352
+ {
8353
+ return null;
8354
+ }
8355
+
8356
+ String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
8357
+
8358
+// String[] split = tex.split("Textures");
8359
+// if (split.length > 1)
8360
+// texname = "/Users/nbriere/Textures" + split[split.length-1];
8361
+// else
8362
+// if (!texname.startsWith("/"))
8363
+// texname = "/Users/nbriere/Textures/" + texname;
8364
+ if (!FileExists(texname) && !texname.startsWith("@"))
8365
+ {
8366
+ texname = fallbackTextureName;
8367
+ }
77178368
77188369 if (CACHETEXTURE)
7719
- texture = textures.get(texname); // TEXTURE CACHE
7720
-
7721
- TextureData texturedata = null;
7722
-
7723
- if (texture == null || texture.resolution < resolution)
77248370 {
7725
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8371
+ if (texdata == null)
8372
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8373
+ else
8374
+ texturecache = bimtextures.get(texdata);
8375
+ }
8376
+
8377
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8378
+ {
8379
+ TextureData texturedata = null;
8380
+
8381
+ if (texdata != null && textureon)
8382
+ {
8383
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8384
+
8385
+ try
8386
+ {
8387
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8388
+ }
8389
+ catch (Exception e)
8390
+ {
8391
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8392
+ }
8393
+
8394
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8395
+ bimtextures.put(texdata, texturecache);
8396
+
8397
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8398
+
8399
+ //Object bim2 = CreateBim(texturecache.texturedata);
8400
+ //bim2 = bim;
8401
+ }
8402
+ else
8403
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
77268404 {
77278405 assert(!bump);
77288406 // if (bump)
....@@ -7733,19 +8411,23 @@
77338411 // }
77348412 // else
77358413 // {
7736
- texture = textures.get(tex);
7737
- if (texture == null)
8414
+ // texturecache = textures.get(texname); // suspicious
8415
+ if (texturecache == null)
77388416 {
7739
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8417
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
77408418 }
8419
+ else
8420
+ new Exception().printStackTrace();
77418421 // }
77428422 } else
7743
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8423
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
77448424 {
77458425 assert(bump);
7746
- texture = textures.get(tex);
7747
- if (texture == null)
7748
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8426
+ // texturecache = textures.get(texname); // suspicious
8427
+ if (texturecache == null)
8428
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8429
+ else
8430
+ new Exception().printStackTrace();
77498431 } else
77508432 {
77518433 //if (tex.equals("IMMORTAL"))
....@@ -7753,11 +8435,22 @@
77538435 // texture = GetResourceTexture("default.png");
77548436 //} else
77558437 //{
7756
- if (tex.equals("WHITE_NOISE"))
8438
+ if (texname.endsWith("WHITE_NOISE"))
77578439 {
7758
- texture = textures.get(tex);
7759
- if (texture == null)
7760
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8440
+ // texturecache = textures.get(texname); // suspicious
8441
+ if (texturecache == null)
8442
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8443
+ else
8444
+ new Exception().printStackTrace();
8445
+ } else
8446
+ {
8447
+ if (texname.startsWith("@"))
8448
+ {
8449
+ // texturecache = textures.get(texname); // suspicious
8450
+ if (texturecache == null)
8451
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8452
+ else
8453
+ new Exception().printStackTrace();
77618454 } else
77628455 {
77638456 if (textureon)
....@@ -7782,7 +8475,7 @@
77828475 }
77838476
77848477 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
7785
- if (!new File(cachename).exists())
8478
+ if (!FileExists(cachename))
77868479 cachename = texname;
77878480 else
77888481 processbump = false; // don't process bump map again
....@@ -7804,7 +8497,7 @@
78048497 }
78058498
78068499 cachename = texname.substring(0, texname.length()-4)+ext+".png";
7807
- if (!new File(cachename).exists())
8500
+ if (!FileExists(cachename))
78088501 cachename = texname;
78098502 else
78108503 processbump = false; // don't process bump map again
....@@ -7813,20 +8506,23 @@
78138506 texturedata = GetFileTexture(cachename, processbump, resolution);
78148507
78158508
7816
- if (texturedata != null)
7817
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8509
+ if (texturedata == null)
8510
+ throw new Exception();
8511
+
8512
+ texturecache = new CacheTexture(texturedata,resolution);
78188513 //texture = GetTexture(tex, bump);
78198514 }
8515
+ }
78208516 }
78218517 //}
78228518 }
78238519
7824
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8520
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
78258521 {
78268522 //return false;
78278523
78288524 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
7829
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8525
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
78308526 {
78318527 // String ext = "_highres";
78328528 // if (REDUCETEXTURE)
....@@ -7843,52 +8539,17 @@
78438539 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
78448540 if (!cachefile.exists())
78458541 {
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))
8542
+ //if (texturedata.getWidth() == texturedata.getHeight())
78558543 {
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);
8544
+ BufferedImage rendImage = CreateBim(texturedata);
8545
+
78868546 ImageWriter writer = null;
78878547 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
78888548 if (iter.hasNext()) {
78898549 writer = (ImageWriter)iter.next();
78908550 }
7891
- float compressionQuality = 0.9f;
8551
+
8552
+ float compressionQuality = 0.85f;
78928553 try
78938554 {
78948555 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -7905,18 +8566,20 @@
79058566 }
79068567 }
79078568 }
7908
-
8569
+
8570
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8571
+
79098572 //System.out.println("Texture = " + tex);
7910
- if (textures.containsKey(texname))
8573
+ if (textures.containsKey(tex))
79118574 {
7912
- CacheTexture thetex = textures.get(texname);
8575
+ CacheTexture thetex = textures.get(tex);
79138576 thetex.texture.disable();
79148577 thetex.texture.dispose();
7915
- textures.remove(texname);
8578
+ textures.remove(tex);
79168579 }
79178580
7918
- texture.texturedata = texturedata;
7919
- textures.put(texname, texture);
8581
+ //texture.texturedata = texturedata;
8582
+ textures.put(tex, texturecache);
79208583
79218584 // newtex = true;
79228585 }
....@@ -7932,10 +8595,44 @@
79328595 }
79338596 }
79348597
7935
- return texture;
8598
+ return texturecache;
79368599 }
79378600
7938
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution)
8601
+ static void EmbedTextures(cTexture tex)
8602
+ {
8603
+ if (tex.pigmentdata == null)
8604
+ {
8605
+ //String texname = Object3D.GetPigment(tex);
8606
+
8607
+ CacheTexture texturecache = texturepigment.get(tex);
8608
+
8609
+ if (texturecache != null)
8610
+ {
8611
+ tex.pw = texturecache.texturedata.getWidth();
8612
+ tex.ph = texturecache.texturedata.getHeight();
8613
+ tex.pigmentdata = //CompressJPEG(CreateBim
8614
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8615
+ ;
8616
+ //, tex.pw, tex.ph), 0.5f);
8617
+ }
8618
+ }
8619
+
8620
+ if (tex.bumpdata == null)
8621
+ {
8622
+ //String texname = Object3D.GetBump(tex);
8623
+
8624
+ CacheTexture texturecache = texturebump.get(tex);
8625
+
8626
+ if (texturecache != null)
8627
+ {
8628
+ tex.bw = texturecache.texturedata.getWidth();
8629
+ tex.bh = texturecache.texturedata.getHeight();
8630
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8631
+ }
8632
+ }
8633
+ }
8634
+
8635
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
79398636 {
79408637 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
79418638
....@@ -7953,21 +8650,21 @@
79538650 return texture!=null?texture.texture:null;
79548651 }
79558652
7956
- com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution)
8653
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
79578654 {
79588655 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
79598656
79608657 return texture!=null?texture.texturedata:null;
79618658 }
79628659
7963
- boolean BindTexture(String tex, boolean bump, int resolution)
8660
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
79648661 {
79658662 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
79668663 {
79678664 return false;
79688665 }
79698666
7970
- boolean newtex = false;
8667
+ //boolean newtex = false;
79718668
79728669 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
79738670
....@@ -7999,9 +8696,75 @@
79998696 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
80008697 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
80018698
8002
- return newtex;
8699
+ return true; // Warning: not used.
80038700 }
80048701
8702
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8703
+ {
8704
+ try
8705
+ {
8706
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8707
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8708
+ ImageWriter writer = writers.next();
8709
+
8710
+ ImageWriteParam param = writer.getDefaultWriteParam();
8711
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8712
+ param.setCompressionQuality(quality);
8713
+
8714
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8715
+ writer.setOutput(ios);
8716
+ writer.write(null, new IIOImage(image, null, null), param);
8717
+
8718
+ byte[] data = baos.toByteArray();
8719
+ writer.dispose();
8720
+ return data;
8721
+ }
8722
+ catch (Exception e)
8723
+ {
8724
+ e.printStackTrace();
8725
+ return null;
8726
+ }
8727
+ }
8728
+
8729
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8730
+ {
8731
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8732
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8733
+ ImageReader reader = writers.next();
8734
+
8735
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8736
+
8737
+ ImageReadParam param = reader.getDefaultReadParam();
8738
+ param.setDestination(bim);
8739
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8740
+
8741
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8742
+ reader.setInput(ios);
8743
+ BufferedImage bim2 = reader.read(0, param);
8744
+ reader.dispose();
8745
+
8746
+// WritableRaster raster = bim2.getRaster();
8747
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8748
+// byte[] bytes = data.getData();
8749
+//
8750
+// int[] pixels = new int[bytes.length/3];
8751
+// for (int i=pixels.length; --i>=0;)
8752
+// {
8753
+// int i3 = i*3;
8754
+// pixels[i] = 0xFF;
8755
+// pixels[i] <<= 8;
8756
+// pixels[i] |= bytes[i3+2] & 0xFF;
8757
+// pixels[i] <<= 8;
8758
+// pixels[i] |= bytes[i3+1] & 0xFF;
8759
+// pixels[i] <<= 8;
8760
+// pixels[i] |= bytes[i3] & 0xFF;
8761
+// }
8762
+//
8763
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8764
+
8765
+ return bim;
8766
+ }
8767
+
80058768 ShadowBuffer shadowPBuf;
80068769 AntialiasBuffer antialiasPBuf;
80078770 int MAXSTACK;
....@@ -8018,10 +8781,12 @@
80188781
80198782 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
80208783 MAXSTACK = temp[0];
8021
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8784
+ if (Globals.DEBUG)
8785
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
80228786 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
80238787 MAXSTACK = temp[0];
8024
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8788
+ if (Globals.DEBUG)
8789
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
80258790
80268791 // Use debug pipeline
80278792 //drawable.setGL(new DebugGL(gl)); //
....@@ -8029,7 +8794,8 @@
80298794 gl = drawable.getGL(); //
80308795
80318796 GL gl3 = getGL();
8032
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8797
+ if (Globals.DEBUG)
8798
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
80338799
80348800
80358801 //float pos[] = { 100, 100, 100, 0 };
....@@ -8194,7 +8960,7 @@
81948960
81958961 if (cubemap == null)
81968962 {
8197
- LoadEnvy(5);
8963
+ //LoadEnvy(1);
81988964 }
81998965
82008966 //cubemap.enable();
....@@ -8470,6 +9236,8 @@
84709236
84719237 void LoadEnvy(int which)
84729238 {
9239
+ assert(false);
9240
+
84739241 String name;
84749242 String ext;
84759243
....@@ -8481,37 +9249,58 @@
84819249 cubemap = null;
84829250 return;
84839251 case 1:
8484
- name = "cubemaps/box_";
8485
- ext = "png";
9252
+ name = "cubemaps/rgb/";
9253
+ ext = "jpg";
84869254 reverseUP = false;
84879255 break;
84889256 case 2:
8489
- name = "cubemaps/uffizi_";
8490
- ext = "png";
8491
- break; // reverseUP = true; break;
9257
+ name = "cubemaps/uffizi/";
9258
+ ext = "jpg";
9259
+ reverseUP = false;
9260
+ break;
84929261 case 3:
8493
- name = "cubemaps/CloudyHills_";
8494
- ext = "tga";
9262
+ name = "cubemaps/CloudyHills/";
9263
+ ext = "jpg";
84959264 reverseUP = false;
84969265 break;
84979266 case 4:
8498
- name = "cubemaps/cornell_";
9267
+ name = "cubemaps/cornell/";
84999268 ext = "png";
85009269 reverseUP = false;
85019270 break;
9271
+ case 5:
9272
+ name = "cubemaps/skycube/";
9273
+ ext = "jpg";
9274
+ reverseUP = false;
9275
+ break;
9276
+ case 6:
9277
+ name = "cubemaps/SaintLazarusChurch3/";
9278
+ ext = "jpg";
9279
+ reverseUP = false;
9280
+ break;
9281
+ case 7:
9282
+ name = "cubemaps/Sodermalmsallen/";
9283
+ ext = "jpg";
9284
+ reverseUP = false;
9285
+ break;
9286
+ case 8:
9287
+ name = "cubemaps/Sodermalmsallen2/";
9288
+ ext = "jpg";
9289
+ reverseUP = false;
9290
+ break;
9291
+ case 9:
9292
+ name = "cubemaps/UnionSquare/";
9293
+ ext = "jpg";
9294
+ reverseUP = false;
9295
+ break;
85029296 default:
8503
- name = "cubemaps/rgb_";
8504
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9297
+ name = "cubemaps/box/";
9298
+ ext = "png"; /*mipmap = true;*/
9299
+ reverseUP = false;
85059300 break;
85069301 }
8507
-
8508
- try
8509
- {
8510
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
8511
- } catch (IOException e)
8512
- {
8513
- throw new RuntimeException(e);
8514
- }
9302
+
9303
+ LoadSkybox(name, ext, mipmap);
85159304 }
85169305
85179306 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -8543,8 +9332,12 @@
85439332 static double[] model = new double[16];
85449333 double[] camera2light = new double[16];
85459334 double[] light2camera = new double[16];
8546
- int newenvy = -1;
8547
- boolean envyoff = true; // false;
9335
+
9336
+ //int newenvy = -1;
9337
+ //boolean envyoff = false;
9338
+
9339
+ String loadedskyboxname;
9340
+
85489341 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
85499342 //float[] light0 = { 0,0,0 };
85509343 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -8837,11 +9630,35 @@
88379630 jy8[3] = 0.5f;
88389631 }
88399632
8840
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9633
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
88419634 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
88429635 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
88439636 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
88449637
9638
+ void ResetOptions()
9639
+ {
9640
+ options1[0] = 100;
9641
+ options1[1] = 0.025f;
9642
+ options1[2] = 0.01f;
9643
+ options1[3] = 0;
9644
+ options1[4] = 0;
9645
+
9646
+ options2[0] = 0;
9647
+ options2[1] = 0.75f;
9648
+ options2[2] = 0;
9649
+ options2[3] = 0;
9650
+
9651
+ options3[0] = 1;
9652
+ options3[1] = 1;
9653
+ options3[2] = 1;
9654
+ options3[3] = 0;
9655
+
9656
+ options4[0] = 1;
9657
+ options4[1] = 0;
9658
+ options4[2] = 1;
9659
+ options4[3] = 0;
9660
+ }
9661
+
88459662 static int imagecount = 0; // movie generation
88469663
88479664 static int jitter = 0;
....@@ -8937,8 +9754,8 @@
89379754 assert (parentcam != renderCamera);
89389755
89399756 if (renderCamera != lightCamera)
8940
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8941
- LA.matConcat(matrix, parentcam.toParent, matrix);
9757
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9758
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
89429759
89439760 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
89449761
....@@ -8953,8 +9770,8 @@
89539770 LA.matCopy(renderCamera.fromScreen, matrix);
89549771
89559772 if (renderCamera != lightCamera)
8956
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8957
- LA.matConcat(parentcam.fromParent, matrix, matrix);
9773
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9774
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
89589775
89599776 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
89609777
....@@ -9000,10 +9817,12 @@
90009817 rati = 1 / rati;
90019818 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
90029819 }
9003
- assert (newenvy == -1);
9820
+
9821
+ //assert (newenvy == -1);
9822
+
90049823 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
90059824 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9006
- DrawSkyBox(gl);
9825
+ DrawSkyBox(gl, (float)rati);
90079826 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
90089827 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
90099828 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -9026,7 +9845,7 @@
90269845 //gl.glFlush();
90279846 gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE);
90289847
9029
- if (ANIMATION && ABORTED)
9848
+ if (Globals.ANIMATION && ABORTED)
90309849 {
90319850 System.err.println(" ABORTED FRAME");
90329851 break;
....@@ -9056,7 +9875,7 @@
90569875 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
90579876
90589877 // save image
9059
- if (ANIMATION && !ABORTED)
9878
+ if (Globals.ANIMATION && !ABORTED)
90609879 {
90619880 VPwidth = viewport[2];
90629881 VPheight = viewport[3];
....@@ -9167,11 +9986,11 @@
91679986
91689987 // imagecount++;
91699988
9170
- String fullname = filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
9989
+ String fullname = Globals.filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
91719990
91729991 if (!BOXMODE)
91739992 {
9174
- System.out.println("image: " + fullname + " (wav cursor=" + (GrafreeD.wav.cursor / 735 / 4) + ")");
9993
+ System.out.println("image: " + fullname + " (wav cursor=" + (Grafreed.wav.cursor / 735 / 4) + ")");
91759994 }
91769995
91779996 if (!BOXMODE)
....@@ -9209,7 +10028,7 @@
920910028 ABORTED = false;
921010029 }
921110030 else
9212
- GrafreeD.wav.cursor += 735 * ACSIZE;
10031
+ Grafreed.wav.cursor += 735 * ACSIZE;
921310032
921410033 if (false)
921510034 {
....@@ -9872,11 +10691,11 @@
987210691
987310692 public void display(GLAutoDrawable drawable)
987410693 {
9875
- if (GrafreeD.savesound && GrafreeD.hassound)
10694
+ if (Grafreed.savesound && Grafreed.hassound)
987610695 {
9877
- GrafreeD.wav.save();
9878
- GrafreeD.savesound = false;
9879
- GrafreeD.hassound = false;
10696
+ Grafreed.wav.save();
10697
+ Grafreed.savesound = false;
10698
+ Grafreed.hassound = false;
988010699 }
988110700 // if (DEBUG_SELECTION)
988210701 // {
....@@ -9952,6 +10771,7 @@
995210771 ANTIALIAS = 0;
995310772 //System.out.println("RESTART");
995410773 AAtimer.restart();
10774
+ Globals.TIMERRUNNING = true;
995510775 }
995610776 }
995710777 }
....@@ -10006,7 +10826,7 @@
1000610826 Object3D theobject = object;
1000710827 Object3D theparent = object.parent;
1000810828 object.parent = null;
10009
- object = (Object3D)GrafreeD.clone(object);
10829
+ object = (Object3D)Grafreed.clone(object);
1001010830 object.Stripify();
1001110831 if (theobject.selection == null || theobject.selection.Size() == 0)
1001210832 theobject.PreprocessOcclusion(this);
....@@ -10019,13 +10839,14 @@
1001910839 ambientOcclusion = false;
1002010840 }
1002110841
10022
- if (Globals.lighttouched && DrawMode() == DEFAULT && !lightMode) // && !FROZEN)
10842
+ if (//Globals.lighttouched &&
10843
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1002310844 {
1002410845 //if (RENDERSHADOW) // ?
1002510846 if (!IsFrozen())
1002610847 {
1002710848 // dec 2012
10028
- if (!ambientOcclusion && !(!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0))
10849
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
1002910850 {
1003010851 Globals.framecount++;
1003110852 shadowbuffer.display();
....@@ -10038,7 +10859,7 @@
1003810859
1003910860 if (wait)
1004010861 {
10041
- Sleep(500);
10862
+ Sleep(200); // blocks everything
1004210863
1004310864 wait = false;
1004410865 }
....@@ -10152,8 +10973,8 @@
1015210973
1015310974 // if (parentcam != renderCamera) // not a light
1015410975 if (cam != lightCamera)
10155
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10156
- LA.matConcat(matrix, parentcam.toParent, matrix);
10976
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10977
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1015710978
1015810979 for (int j = 0; j < 4; j++)
1015910980 {
....@@ -10167,8 +10988,8 @@
1016710988
1016810989 // if (parentcam != renderCamera) // not a light
1016910990 if (cam != lightCamera)
10170
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10171
- LA.matConcat(parentcam.fromParent, matrix, matrix);
10991
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10992
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1017210993
1017310994 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1017410995
....@@ -10254,13 +11075,41 @@
1025411075 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1025511076 }
1025611077
10257
- if (newenvy > -1)
11078
+// if (newenvy > -1)
11079
+// {
11080
+// LoadEnvy(newenvy);
11081
+// }
11082
+//
11083
+// newenvy = -1;
11084
+
11085
+ if (object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
1025811086 {
10259
- LoadEnvy(newenvy);
11087
+ if (cubemaprgb == null)
11088
+ {
11089
+ cubemaprgb = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11090
+ }
11091
+
11092
+ cubemap = cubemaprgb;
1026011093 }
10261
-
10262
- newenvy = -1;
10263
-
11094
+ else
11095
+ {
11096
+ if (object.skyboxname != null)
11097
+ {
11098
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11099
+ {
11100
+ cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11101
+ loadedskyboxname = object.skyboxname;
11102
+ }
11103
+ }
11104
+ else
11105
+ {
11106
+ cubemapcustom = null;
11107
+ loadedskyboxname = null;
11108
+ }
11109
+
11110
+ cubemap = cubemapcustom;
11111
+ }
11112
+
1026411113 ratio = ((double) getWidth()) / getHeight();
1026511114 //System.out.println("ratio = " + ratio);
1026611115
....@@ -10276,7 +11125,7 @@
1027611125
1027711126 if (!IsFrozen() && !ambientOcclusion)
1027811127 {
10279
- DrawSkyBox(gl);
11128
+ DrawSkyBox(gl, (float)ratio);
1028011129 }
1028111130
1028211131 //if (selection_view == -1)
....@@ -10427,7 +11276,16 @@
1042711276 // Bump noise
1042811277 gl.glActiveTexture(GL.GL_TEXTURE6);
1042911278 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
10430
- BindTexture(NOISE_TEXTURE, false, 2);
11279
+
11280
+ try
11281
+ {
11282
+ BindTexture(NOISE_TEXTURE, false, 2);
11283
+ }
11284
+ catch (Exception e)
11285
+ {
11286
+ System.err.println("FAILED: " + NOISE_TEXTURE);
11287
+ }
11288
+
1043111289
1043211290 gl.glActiveTexture(GL.GL_TEXTURE0);
1043311291 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -10450,9 +11308,9 @@
1045011308
1045111309 gl.glMatrixMode(GL.GL_MODELVIEW);
1045211310
10453
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10454
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10455
-//gl.glEnable(gl.GL_MULTISAMPLE);
11311
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11312
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11313
+gl.glEnable(gl.GL_MULTISAMPLE);
1045611314 } else
1045711315 {
1045811316 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -10463,7 +11321,7 @@
1046311321 //System.out.println("BLENDING ON");
1046411322 gl.glEnable(GL.GL_BLEND);
1046511323 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
10466
-
11324
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1046711325 gl.glMatrixMode(gl.GL_PROJECTION);
1046811326 gl.glLoadIdentity();
1046911327
....@@ -10552,8 +11410,8 @@
1055211410 System.err.println("parentcam != renderCamera");
1055311411
1055411412 // if (cam != lightCamera)
10555
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10556
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11413
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11414
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1055711415 }
1055811416
1055911417 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -10574,8 +11432,8 @@
1057411432 if (true) // TODO
1057511433 {
1057611434 if (cam != lightCamera)
10577
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10578
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11435
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11436
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
1057911437 }
1058011438
1058111439 LA.xformPos(light0, cam.toScreen, light0);
....@@ -10712,7 +11570,7 @@
1071211570 }
1071311571 }
1071411572
10715
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11573
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1071611574 {
1071711575 //gl.glDepthFunc(GL.GL_LEQUAL);
1071811576 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -10720,24 +11578,21 @@
1072011578
1072111579 boolean texon = textureon;
1072211580
10723
- if (RENDERPROGRAM > 0)
10724
- {
10725
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
10726
- textureon = false;
10727
- }
11581
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11582
+ textureon = false;
11583
+
1072811584 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1072911585 //System.out.println("ALLO");
1073011586 gl.glColorMask(false, false, false, false);
1073111587 DrawObject(gl);
10732
- if (RENDERPROGRAM > 0)
10733
- {
10734
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
10735
- textureon = texon;
10736
- }
11588
+
11589
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11590
+ textureon = texon;
11591
+
1073711592 gl.glColorMask(true, true, true, true);
1073811593
1073911594 gl.glDepthFunc(GL.GL_EQUAL);
10740
- //gl.glDepthMask(false);
11595
+ gl.glDepthMask(false);
1074111596 }
1074211597
1074311598 if (false) // DrawMode() == SHADOW)
....@@ -10891,8 +11746,14 @@
1089111746 {
1089211747 renderpass++;
1089311748 // System.out.println("Draw object... ");
11749
+ STEP = 1;
1089411750 if (FAST) // in case there is no script
10895
- STEP = 16;
11751
+ STEP = 8;
11752
+
11753
+ if (CURRENTANTIALIAS == 0 || ACSIZE == 1)
11754
+ {
11755
+ STEP *= 4;
11756
+ }
1089611757
1089711758 //object.FullInvariants();
1089811759
....@@ -10906,23 +11767,44 @@
1090611767 e.printStackTrace();
1090711768 }
1090811769
10909
- if (GrafreeD.RENDERME > 0)
10910
- GrafreeD.RENDERME--; // mechante magouille
11770
+ if (Grafreed.RENDERME > 0)
11771
+ Grafreed.RENDERME--; // mechante magouille
1091111772
1091211773 Globals.ONESTEP = false;
1091311774 }
1091411775
1091511776 static boolean zoomonce = false;
1091611777
11778
+ static void CreateSelectedPoint()
11779
+ {
11780
+ if (selectedpoint == null)
11781
+ {
11782
+ debugpointG = new Sphere();
11783
+ debugpointP = new Sphere();
11784
+ debugpointC = new Sphere();
11785
+ debugpointR = new Sphere();
11786
+
11787
+ selectedpoint = new Superellipsoid();
11788
+
11789
+ for (int i=0; i<8; i++)
11790
+ {
11791
+ debugpoints[i] = new Sphere();
11792
+ }
11793
+ }
11794
+ }
11795
+
1091711796 void DrawObject(GL gl, boolean draw)
1091811797 {
11798
+ // To clear camera values
11799
+ ResetOptions();
11800
+
1091911801 //System.out.println("DRAW OBJECT " + mouseDown);
1092011802 // DrawMode() = SELECTION;
1092111803 //GL gl = getGL();
1092211804 if ((TRACK || SHADOWTRACK) || zoomonce)
1092311805 {
1092411806 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
10925
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11807
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1092611808 pingthread.StepToTarget(true); // true);
1092711809 // zoomonce = false;
1092811810 }
....@@ -10977,7 +11859,14 @@
1097711859
1097811860 usedtextures.clear();
1097911861
10980
- BindTextures(DEFAULT_TEXTURES, 2);
11862
+ try
11863
+ {
11864
+ BindTextures(DEFAULT_TEXTURES, 2);
11865
+ }
11866
+ catch (Exception e)
11867
+ {
11868
+ System.err.println("FAILED: " + DEFAULT_TEXTURES);
11869
+ }
1098111870 }
1098211871 //System.out.println("--> " + stackdepth);
1098311872 // GrafreeD.traceon();
....@@ -10987,8 +11876,9 @@
1098711876
1098811877 if (DrawMode() == DEFAULT)
1098911878 {
10990
- if (DEBUG)
11879
+ if (Globals.DEBUG)
1099111880 {
11881
+ CreateSelectedPoint();
1099211882 float radius = 0.05f;
1099311883 if (selectedpoint.radius != radius)
1099411884 {
....@@ -11042,20 +11932,32 @@
1104211932 ReleaseTextures(DEFAULT_TEXTURES);
1104311933
1104411934 if (CLEANCACHE)
11045
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11935
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1104611936 {
11047
- String tex = e.nextElement();
11937
+ cTexture tex = e.nextElement();
1104811938
1104911939 // System.out.println("Texture --------- " + tex);
1105011940
11051
- if (tex.equals("WHITE_NOISE"))
11941
+ if (tex.equals("WHITE_NOISE:"))
1105211942 continue;
1105311943
11054
- if (!usedtextures.containsKey(tex))
11944
+ if (!usedtextures.contains(tex))
1105511945 {
11946
+ CacheTexture gettex = texturepigment.get(tex);
1105611947 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11057
- textures.get(tex).texture.dispose();
11058
- textures.remove(tex);
11948
+ if (gettex != null)
11949
+ {
11950
+ gettex.texture.dispose();
11951
+ texturepigment.remove(tex);
11952
+ }
11953
+
11954
+ gettex = texturebump.get(tex);
11955
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11956
+ if (gettex != null)
11957
+ {
11958
+ gettex.texture.dispose();
11959
+ texturebump.remove(tex);
11960
+ }
1105911961 }
1106011962 }
1106111963 }
....@@ -11068,7 +11970,14 @@
1106811970 if (checker != null && DrawMode() == DEFAULT)
1106911971 {
1107011972 //BindTexture(IMMORTAL_TEXTURE);
11071
- BindTextures(checker.GetTextures(), checker.texres);
11973
+ try
11974
+ {
11975
+ BindTextures(checker.GetTextures(), checker.texres);
11976
+ }
11977
+ catch (Exception e)
11978
+ {
11979
+ System.err.println("FAILED: " + checker.GetTextures());
11980
+ }
1107211981 // NEAREST
1107311982 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
1107411983 DrawChecker(gl);
....@@ -11150,7 +12059,7 @@
1115012059 return;
1115112060 }
1115212061
11153
- String string = obj.GetToolTip();
12062
+ String string = obj.toString(); //.GetToolTip();
1115412063
1115512064 GL gl = GetGL();
1115612065
....@@ -11467,8 +12376,8 @@
1146712376 //obj.TransformToWorld(light, light);
1146812377 for (int i = tp.size(); --i >= 0;)
1146912378 {
11470
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
11471
- LA.xformPos(light, tp.get(i).toParent, light);
12379
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12380
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1147212381 }
1147312382
1147412383
....@@ -11485,8 +12394,8 @@
1148512394 parentcam = cameras[0];
1148612395 }
1148712396
11488
- for (int count = parentcam.GetTransformCount(); --count>=0;)
11489
- LA.xformPos(light, parentcam.toParent, light); // may 2013
12397
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
12398
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1149012399
1149112400 LA.xformPos(light, renderCamera.toScreen, light);
1149212401
....@@ -11576,8 +12485,76 @@
1157612485
1157712486 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1157812487
11579
- String program =
12488
+ String programmin =
12489
+ // Min shader
1158012490 "!!ARBfp1.0\n" +
12491
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12492
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12493
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12494
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12495
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12496
+ "PARAM light2cam0 = program.env[10];" +
12497
+ "PARAM light2cam1 = program.env[11];" +
12498
+ "PARAM light2cam2 = program.env[12];" +
12499
+ "TEMP temp;" +
12500
+ "TEMP light;" +
12501
+ "TEMP ndotl;" +
12502
+ "TEMP normal;" +
12503
+ "TEMP depth;" +
12504
+ "TEMP eye;" +
12505
+ "TEMP pos;" +
12506
+
12507
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12508
+ Normalize("normal") +
12509
+ "MOV light, state.light[0].position;" +
12510
+ "DP3 ndotl.x, light, normal;" +
12511
+
12512
+ // shadow
12513
+ "MOV pos, fragment.texcoord[1];" +
12514
+ "MOV temp, pos;" +
12515
+ ShadowTextureFetch("depth", "temp", "1") +
12516
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12517
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12518
+
12519
+ // No shadow when out of frustum
12520
+ //"SGE temp.y, depth.z, zero123.y;" +
12521
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12522
+
12523
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12524
+
12525
+ // Backlit
12526
+ "MOV pos.w, zero123.y;" +
12527
+ "DP4 eye.x, pos, light2cam0;" +
12528
+ "DP4 eye.y, pos, light2cam1;" +
12529
+ "DP4 eye.z, pos, light2cam2;" +
12530
+ Normalize("eye") +
12531
+
12532
+ "DP3 ndotl.y, -eye, normal;" +
12533
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12534
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12535
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12536
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12537
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12538
+
12539
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12540
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12541
+
12542
+ // Pigment
12543
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12544
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12545
+ "MUL temp, temp, ndotl.x;" +
12546
+
12547
+ "MUL temp, temp, zero123.z;" +
12548
+
12549
+ //"MUL temp, temp, ndotl.y;" +
12550
+
12551
+ "MOV temp.w, zero123.y;" + // reset alpha
12552
+ "MOV result.color, temp;" +
12553
+ "END";
12554
+
12555
+ String programmax =
12556
+ "!!ARBfp1.0\n" +
12557
+
1158112558 //"OPTION ARB_fragment_program_shadow;" +
1158212559 "PARAM light2cam0 = program.env[10];" +
1158312560 "PARAM light2cam1 = program.env[11];" +
....@@ -11692,8 +12669,7 @@
1169212669 "TEMP shininess;" +
1169312670 "\n" +
1169412671 "MOV texSamp, one;" +
11695
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
11696
-
12672
+
1169712673 "MOV mapgrid.x, one2048th.x;" +
1169812674 "MOV temp, fragment.texcoord[1];" +
1169912675 /*
....@@ -11714,20 +12690,20 @@
1171412690 "MUL temp, floor, mapgrid.x;" +
1171512691 //"TEX depth0, temp, texture[1], 2D;" +
1171612692 (((mode & FP_SOFTSHADOW) == 0) ? "" :
11717
- TextureFetch("depth0", "temp", "1") +
12693
+ ShadowTextureFetch("depth0", "temp", "1") +
1171812694 "") +
1171912695 "ADD temp.x, temp.x, mapgrid.x;" +
1172012696 //"TEX depth1, temp, texture[1], 2D;" +
1172112697 (((mode & FP_SOFTSHADOW) == 0) ? "" :
11722
- TextureFetch("depth1", "temp", "1") +
12698
+ ShadowTextureFetch("depth1", "temp", "1") +
1172312699 "") +
1172412700 "ADD temp.y, temp.y, mapgrid.x;" +
1172512701 //"TEX depth2, temp, texture[1], 2D;" +
11726
- TextureFetch("depth2", "temp", "1") +
12702
+ ShadowTextureFetch("depth2", "temp", "1") +
1172712703 "SUB temp.x, temp.x, mapgrid.x;" +
1172812704 //"TEX depth3, temp, texture[1], 2D;" +
1172912705 (((mode & FP_SOFTSHADOW) == 0) ? "" :
11730
- TextureFetch("depth3", "temp", "1") +
12706
+ ShadowTextureFetch("depth3", "temp", "1") +
1173112707 "") +
1173212708 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1173312709 //"MOV params, material;" +
....@@ -12098,10 +13074,10 @@
1209813074 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1209913075 "") +
1210013076
12101
- // display shadow only (bump == 0)
13077
+ // display shadow only (fakedepth == 0)
1210213078 "SUB temp.x, half.x, shadow.x;" +
12103
- "MOV temp.y, -params6.x;" +
12104
- "SLT temp.z, temp.y, zero.x;" +
13079
+ "MOV temp.y, -params5.z;" + // params6.x;" +
13080
+ "SLT temp.z, temp.y, -c256i.x;" +
1210513081 "SUB temp.y, one.x, temp.z;" +
1210613082 "MUL temp.x, temp.x, temp.y;" +
1210713083 "KIL temp.x;" +
....@@ -12230,8 +13206,10 @@
1223013206 "MAX ndotl.x, ndotl.x, -ndotl.x;" +
1223113207
1223213208 "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
13209
+ // Tuning for default skin
13210
+ //"ADD temp.x, temp.x, options2.z;" + // lightsheen
13211
+ "MAD temp.x, options2.z, half.y, temp.x;" + // lightsheen
13212
+ "ADD temp.y, one.y, options2.y;" + // subsurface
1223513213 "MUL temp.x, temp.x, temp.y;" +
1223613214
1223713215 "MUL saturation, saturation, temp.xxxx;" +
....@@ -12430,7 +13408,14 @@
1243013408 //once = true;
1243113409 }
1243213410
12433
- System.out.print("Program #" + mode + "; length = " + program.length());
13411
+ String program = programmax;
13412
+
13413
+ if (Globals.MINSHADER)
13414
+ {
13415
+ program = programmin;
13416
+ }
13417
+
13418
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1243413419 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1243513420 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1243613421
....@@ -12523,25 +13508,26 @@
1252313508 return out;
1252413509 }
1252513510
12526
- String TextureFetch(String dest, String src, String unit)
13511
+ // Also does frustum culling
13512
+ String ShadowTextureFetch(String dest, String src, String unit)
1252713513 {
1252813514 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1252913515 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1253013516 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13517
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13518
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1253113519 "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;" +
13520
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13521
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1253613522 //"SWZ buffer, temp, w,w,w,w;";
12537
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13523
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1253813524 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1253913525 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1254013526 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
12541
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13527
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1254213528
12543
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
12544
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13529
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13530
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1254513531 }
1254613532
1254713533 String Shadow(String depth, String shadow)
....@@ -12563,12 +13549,16 @@
1256313549
1256413550 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1256513551 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13552
+
13553
+ // Compare fragment depth in light space with shadowmap.
1256613554 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1256713555 "SGE temp.y, temp.x, zero.x;" +
12568
- "SUB " + shadow + ".y, one.x, temp.y;" +
13556
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13557
+
13558
+ // Reverse comparison
1256913559 "SUB temp.x, one.x, temp.x;" +
1257013560 "MUL " + shadow + ".x, temp.x, temp.y;" +
12571
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13561
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1257213562 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1257313563
1257413564 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -12582,6 +13572,10 @@
1258213572 // No shadow for backface
1258313573 "DP3 temp.x, normal, lightd;" +
1258413574 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13575
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13576
+
13577
+ // No shadow when out of frustum
13578
+ "SGE temp.x, " + depth + ".z, one.z;" +
1258513579 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1258613580 "";
1258713581 }
....@@ -12728,7 +13722,8 @@
1272813722 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1272913723 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1273013724 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
12731
- Object3D.cVector2[] vector2buffer;
13725
+
13726
+ //Object3D.cVector2[] vector2buffer;
1273213727
1273313728 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1273413729 // OUT : diff, spec
....@@ -12744,9 +13739,10 @@
1274413739 "DP3 " + dest + ".z," + "normals," + "eye;" +
1274513740 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1274613741 //"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;" +
13742
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13743
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13744
+
13745
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1275013746 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1275113747 "RCP " + dest + ".w," + dest + ".w;" +
1275213748 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13140,7 +14136,7 @@
1314014136 public void mousePressed(MouseEvent e)
1314114137 {
1314214138 //System.out.println("mousePressed: " + e);
13143
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14139
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1314414140 }
1314514141
1314614142 static long prevtime = 0;
....@@ -13167,6 +14163,7 @@
1316714163
1316814164 //System.err.println("Dtime = " + Dtime + "; units = " + e.getUnitsToScroll() + "; ratio (units/ms) = " + ratio);
1316914165
14166
+ if (BUTTONLESSWHEEL)
1317014167 if (Math.abs(ratio) < 0.1 || Math.abs(Dtime) == 0) // < 30)
1317114168 {
1317214169 return;
....@@ -13175,7 +14172,7 @@
1317514172 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
1317614173
1317714174 // TIMER
13178
- if (!wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
14175
+ if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
1317914176 {
1318014177 keepboxmode = BOXMODE;
1318114178 keepsupport = SUPPORT;
....@@ -13215,8 +14212,8 @@
1321514212 // mode |= META;
1321614213 //}
1321714214
13218
- SetMouseMode(WHEEL | e.getModifiersEx());
13219
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14215
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14216
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1322014217 anchorX = ax;
1322114218 anchorY = ay;
1322214219 prevX = px;
....@@ -13250,6 +14247,7 @@
1325014247 else
1325114248 if (evt.getSource() == AAtimer)
1325214249 {
14250
+ Globals.TIMERRUNNING = false;
1325314251 if (mouseDown)
1325414252 {
1325514253 //new Exception().printStackTrace();
....@@ -13275,6 +14273,10 @@
1327514273 // LIVE = waslive;
1327614274 // wasliveok = true;
1327714275 // waslive = false;
14276
+
14277
+ // May 2019 Forget it:
14278
+ if (true)
14279
+ return;
1327814280
1327914281 // source == timer
1328014282 if (mouseDown)
....@@ -13305,7 +14307,7 @@
1330514307
1330614308 // fev 2014???
1330714309 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13308
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14310
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1330914311 pingthread.StepToTarget(true); // true);
1331014312 }
1331114313 // if (!LIVE)
....@@ -13314,12 +14316,13 @@
1331414316
1331514317 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1331614318
13317
- void clickStart(int x, int y, int modifiers)
14319
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1331814320 {
1331914321 if (!wasliveok)
1332014322 return;
1332114323
1332214324 AAtimer.restart(); //
14325
+ Globals.TIMERRUNNING = true;
1332314326
1332414327 // waslive = LIVE;
1332514328 // LIVE = false;
....@@ -13331,7 +14334,7 @@
1333114334 // touched = true; // main DL
1333214335 if (isRenderer)
1333314336 {
13334
- SetMouseMode(modifiers);
14337
+ SetMouseMode(modifiers, modifiersex);
1333514338 }
1333614339
1333714340 selectX = anchorX = x;
....@@ -13344,7 +14347,7 @@
1334414347 clicked = true;
1334514348 hold = false;
1334614349
13347
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14350
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1334814351 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1334914352 {
1335014353 // System.out.println("RESTART II " + modifiers);
....@@ -13369,14 +14372,15 @@
1336914372 drag = false;
1337014373 //System.out.println("Mouse DOWN");
1337114374 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);
14375
+ //ClickInfo info = new ClickInfo();
14376
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14377
+ object.clickInfo.pane = this;
14378
+ object.clickInfo.camera = renderCamera;
14379
+ object.clickInfo.x = x;
14380
+ object.clickInfo.y = y;
14381
+ object.clickInfo.modifiers = modifiersex;
14382
+ editObj = object.doEditClick(//info,
14383
+ 0);
1338014384 if (!editObj)
1338114385 {
1338214386 hasMarquee = true;
....@@ -13392,11 +14396,14 @@
1339214396
1339314397 public void mouseDragged(MouseEvent e)
1339414398 {
14399
+ Globals.MOUSEDRAGGED = true;
14400
+
14401
+ //System.out.println("mouseDragged: " + e);
1339514402 if (isRenderer)
1339614403 movingcamera = true;
14404
+
1339714405 //if (drawing)
1339814406 //return;
13399
- //System.out.println("mouseDragged: " + e);
1340014407 if ((e.getModifiersEx() & CTRL) != 0
1340114408 || (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen())
1340214409 {
....@@ -13404,7 +14411,7 @@
1340414411 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1340514412 }
1340614413 else
13407
- drag(e.getX(), e.getY(), e.getModifiersEx());
14414
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1340814415
1340914416 //try { Thread.sleep(1); } catch (Exception ex) {}
1341014417 }
....@@ -13577,6 +14584,7 @@
1357714584
1357814585 public void run()
1357914586 {
14587
+ new Exception().printStackTrace();
1358014588 System.exit(0);
1358114589 for (;;)
1358214590 {
....@@ -13640,7 +14648,7 @@
1364014648 {
1364114649 Globals.lighttouched = true;
1364214650 }
13643
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14651
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1364414652 }
1364514653 //else
1364614654 }
....@@ -13654,12 +14662,12 @@
1365414662 void GoDown(int mod)
1365514663 {
1365614664 MODIFIERS |= COMMAND;
13657
- /*
14665
+ /**/
1365814666 if((mod&SHIFT) == SHIFT)
13659
- manipCamera.RotatePosition(0, -speed);
14667
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
1366014668 else
13661
- manipCamera.BackForth(0, -speed*delta, getWidth());
13662
- */
14669
+ manipCamera.RotatePosition(0, -speed);
14670
+ /**/
1366314671 if ((mod & SHIFT) == SHIFT)
1366414672 {
1366514673 mouseMode = mouseMode; // VR??
....@@ -13675,12 +14683,12 @@
1367514683 void GoUp(int mod)
1367614684 {
1367714685 MODIFIERS |= COMMAND;
13678
- /*
14686
+ /**/
1367914687 if((mod&SHIFT) == SHIFT)
13680
- manipCamera.RotatePosition(0, speed);
14688
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
1368114689 else
13682
- manipCamera.BackForth(0, speed*delta, getWidth());
13683
- */
14690
+ manipCamera.RotatePosition(0, speed);
14691
+ /**/
1368414692 if ((mod & SHIFT) == SHIFT)
1368514693 {
1368614694 mouseMode = mouseMode;
....@@ -13696,12 +14704,12 @@
1369614704 void GoLeft(int mod)
1369714705 {
1369814706 MODIFIERS |= COMMAND;
13699
- /*
14707
+ /**/
1370014708 if((mod&SHIFT) == SHIFT)
13701
- manipCamera.RotatePosition(speed, 0);
13702
- else
1370314709 manipCamera.Translate(speed*delta, 0, getWidth());
13704
- */
14710
+ else
14711
+ manipCamera.RotatePosition(speed, 0);
14712
+ /**/
1370514713 if ((mod & SHIFT) == SHIFT)
1370614714 {
1370714715 mouseMode = mouseMode;
....@@ -13717,12 +14725,12 @@
1371714725 void GoRight(int mod)
1371814726 {
1371914727 MODIFIERS |= COMMAND;
13720
- /*
14728
+ /**/
1372114729 if((mod&SHIFT) == SHIFT)
13722
- manipCamera.RotatePosition(-speed, 0);
13723
- else
1372414730 manipCamera.Translate(-speed*delta, 0, getWidth());
13725
- */
14731
+ else
14732
+ manipCamera.RotatePosition(-speed, 0);
14733
+ /**/
1372614734 if ((mod & SHIFT) == SHIFT)
1372714735 {
1372814736 mouseMode = mouseMode;
....@@ -13740,7 +14748,7 @@
1374014748 int X, Y;
1374114749 boolean SX, SY;
1374214750
13743
- void drag(int x, int y, int modifiers)
14751
+ void drag(int x, int y, int modifiers, int modifiersex)
1374414752 {
1374514753 if (IsFrozen())
1374614754 {
....@@ -13749,17 +14757,17 @@
1374914757
1375014758 drag = true; // NEW
1375114759
13752
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14760
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1375314761
1375414762 X = x;
1375514763 Y = y;
1375614764 // floating state for animation
13757
- MODIFIERS = modifiers;
13758
- modifiers &= ~1024;
14765
+ MODIFIERS = modifiersex;
14766
+ modifiersex &= ~1024;
1375914767 if (false) // modifiers != 0)
1376014768 {
1376114769 //new Exception().printStackTrace();
13762
- System.out.println("mouseDragged: " + modifiers);
14770
+ System.out.println("mouseDragged: " + modifiersex);
1376314771 System.out.println("SHIFT = " + SHIFT);
1376414772 System.out.println("CONTROL = " + COMMAND);
1376514773 System.out.println("META = " + META);
....@@ -13772,14 +14780,16 @@
1377214780 if (editObj)
1377314781 {
1377414782 drag = true;
13775
- ClickInfo info = new ClickInfo();
13776
- info.bounds.setBounds(0, 0,
14783
+ //ClickInfo info = new ClickInfo();
14784
+ object.clickInfo.bounds.setBounds(0, 0,
1377714785 (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);
14786
+ object.clickInfo.pane = this;
14787
+ object.clickInfo.camera = renderCamera;
14788
+ object.clickInfo.x = x;
14789
+ object.clickInfo.y = y;
14790
+ object //.GetWindow().copy
14791
+ .doEditDrag(//info,
14792
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1378314793 } else
1378414794 {
1378514795 if (x < startX)
....@@ -13928,23 +14938,27 @@
1392814938 }
1392914939 }
1393014940
14941
+// ClickInfo clickInfo = new ClickInfo();
14942
+
1393114943 public void mouseMoved(MouseEvent e)
1393214944 {
1393314945 //System.out.println("mouseMoved: " + e);
13934
-
1393514946 if (isRenderer)
1393614947 return;
1393714948
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;
14949
+ // Mouse cursor feedback
14950
+ object.clickInfo.x = e.getX();
14951
+ object.clickInfo.y = e.getY();
14952
+ object.clickInfo.modifiers = e.getModifiersEx();
14953
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14954
+ object.clickInfo.pane = this;
14955
+ object.clickInfo.camera = renderCamera;
1394514956 if (!isRenderer)
1394614957 {
13947
- if (object.editWindow.copy.doEditClick(ci, 0))
14958
+ //ObjEditor editWindow = object.editWindow;
14959
+ //Object3D copy = editWindow.copy;
14960
+ if (object.doEditClick(//clickInfo,
14961
+ 0))
1394814962 {
1394914963 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1395014964 } else
....@@ -13956,7 +14970,11 @@
1395614970
1395714971 public void mouseReleased(MouseEvent e)
1395814972 {
14973
+ Globals.MOUSEDRAGGED = false;
14974
+
1395914975 movingcamera = false;
14976
+ X = 0; // getBounds().width/2;
14977
+ Y = 0; // getBounds().height/2;
1396014978 //System.out.println("mouseReleased: " + e);
1396114979 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1396214980 }
....@@ -13979,9 +14997,9 @@
1397914997 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1398014998 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1398114999
13982
- if (control || command || IsFrozen())
15000
+// No delay if (control || command || IsFrozen())
1398315001 timeout = true;
13984
- else
15002
+// ?? May 2019 else
1398515003 // timer.setDelay((modifiers & 128) != 0?0:350);
1398615004 mouseDown = false;
1398715005 if (!control && !command) // june 2013
....@@ -14091,7 +15109,7 @@
1409115109 System.out.println("keyReleased: " + e);
1409215110 }
1409315111
14094
- void SetMouseMode(int modifiers)
15112
+ void SetMouseMode(int modifiers, int modifiersex)
1409515113 {
1409615114 //System.out.println("SetMouseMode = " + modifiers);
1409715115 //modifiers &= ~1024;
....@@ -14103,25 +15121,25 @@
1410315121 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1410415122 // return;
1410515123 //System.out.println("SetMode = " + modifiers);
14106
- if ((modifiers & WHEEL) == WHEEL)
15124
+ if ((modifiersex & WHEEL) == WHEEL)
1410715125 {
1410815126 mouseMode |= ZOOM;
1410915127 }
1411015128
1411115129 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
14112
- if (capsLocked || (modifiers & META) == META)
15130
+ if (capsLocked) // || (modifiers & META) == META)
1411315131 {
1411415132 mouseMode |= VR; // BACKFORTH;
1411515133 }
14116
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
15134
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1411715135 {
1411815136 mouseMode |= SELECT;
1411915137 }
14120
- if ((modifiers & COMMAND) == COMMAND)
15138
+ if ((modifiersex & COMMAND) == COMMAND)
1412115139 {
1412215140 mouseMode |= SELECT;
1412315141 }
14124
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15142
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
1412515143 {
1412615144 mouseMode &= ~VR;
1412715145 mouseMode |= TRANSLATE;
....@@ -14150,10 +15168,10 @@
1415015168
1415115169 if (isRenderer) //
1415215170 {
14153
- SetMouseMode(modifiers);
15171
+ SetMouseMode(0, modifiers);
1415415172 }
1415515173
14156
- theRenderer.keyPressed(key);
15174
+ Globals.theRenderer.keyPressed(key);
1415715175 }
1415815176
1415915177 int kompactbit = 4; // power bit
....@@ -14165,7 +15183,7 @@
1416515183 float SATPOW = 1; // 2; // 0.5f;
1416615184 float BRIPOW = 1; // 0.5f; // 0.5f;
1416715185
14168
- void keyPressed(int key)
15186
+ public void keyPressed(int key)
1416915187 {
1417015188 if (key >= '0' && key <= '5')
1417115189 clampbit = (key-'0');
....@@ -14212,7 +15230,8 @@
1421215230 // break;
1421315231 case 'T':
1421415232 CACHETEXTURE ^= true;
14215
- textures.clear();
15233
+ texturepigment.clear();
15234
+ texturebump.clear();
1421615235 // repaint();
1421715236 break;
1421815237 case 'Y':
....@@ -14297,7 +15316,9 @@
1429715316 case 'E' : COMPACT ^= true;
1429815317 repaint();
1429915318 break;
14300
- case 'W' : DEBUGHSB ^= true;
15319
+ case 'W' : // Wide Window (fullscreen)
15320
+ //DEBUGHSB ^= true;
15321
+ ObjEditor.theFrame.ToggleFullScreen();
1430115322 repaint();
1430215323 break;
1430315324 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14322,8 +15343,8 @@
1432215343 RevertCamera();
1432315344 repaint();
1432415345 break;
14325
- case 'L':
1432615346 case 'l':
15347
+ //case 'L':
1432715348 if (lightMode)
1432815349 {
1432915350 lightMode = false;
....@@ -14387,20 +15408,24 @@
1438715408 OCCLUSION_CULLING ^= true;
1438815409 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1438915410 break;
14390
- case '0': envyoff ^= true; repaint(); break;
15411
+ //case '0': envyoff ^= true; repaint(); break;
1439115412 case '1':
1439215413 case '2':
1439315414 case '3':
1439415415 case '4':
1439515416 case '5':
14396
- newenvy = Character.getNumericValue(key);
14397
- repaint();
14398
- break;
1439915417 case '6':
1440015418 case '7':
1440115419 case '8':
1440215420 case '9':
14403
- BGcolor = (key - '6')/3.f;
15421
+ if (true) // envyoff)
15422
+ {
15423
+ BGcolor = (key - '1')/8.f;
15424
+ }
15425
+ else
15426
+ {
15427
+ //newenvy = Character.getNumericValue(key);
15428
+ }
1440415429 repaint();
1440515430 break;
1440615431 case '!':
....@@ -14466,9 +15491,9 @@
1446615491 case '_':
1446715492 kompactbit = 5;
1446815493 break;
14469
- case '+':
14470
- kompactbit = 6;
14471
- break;
15494
+// case '+':
15495
+// kompactbit = 6;
15496
+// break;
1447215497 case ' ':
1447315498 lightMode ^= true;
1447415499 Globals.lighttouched = true;
....@@ -14480,13 +15505,14 @@
1448015505 case ESC:
1448115506 RENDERPROGRAM += 1;
1448215507 RENDERPROGRAM %= 3;
15508
+
1448315509 repaint();
1448415510 break;
1448515511 case 'Z':
1448615512 //RESIZETEXTURE ^= true;
1448715513 //break;
1448815514 case 'z':
14489
- RENDERSHADOW ^= true;
15515
+ Globals.RENDERSHADOW ^= true;
1449015516 Globals.lighttouched = true;
1449115517 repaint();
1449215518 break;
....@@ -14519,8 +15545,9 @@
1451915545 case DELETE:
1452015546 ClearSelection();
1452115547 break;
14522
- /*
1452315548 case '+':
15549
+
15550
+ /*
1452415551 //fontsize += 1;
1452515552 bbzoom *= 2;
1452615553 repaint();
....@@ -14537,17 +15564,17 @@
1453715564 case '=':
1453815565 IncDepth();
1453915566 //fontsize += 1;
14540
- object.editWindow.refreshContents(true);
15567
+ object.GetWindow().refreshContents(true);
1454115568 maskbit = 6;
1454215569 break;
1454315570 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1454415571 DecDepth();
1454515572 maskbit = 5;
1454615573 //if(fontsize > 1) fontsize -= 1;
14547
- if (object.editWindow == null)
14548
- new Exception().printStackTrace();
14549
- else
14550
- object.editWindow.refreshContents(true);
15574
+// if (object.editWindow == null)
15575
+// new Exception().printStackTrace();
15576
+// else
15577
+ object.GetWindow().refreshContents(true);
1455115578 break;
1455215579 case '{':
1455315580 manipCamera.shaper_fovy /= 1.1;
....@@ -14602,6 +15629,7 @@
1460215629 }
1460315630 //System.out.println("shaper_fovy = " + manipCamera.shaper_fovy);
1460415631 }
15632
+
1460515633 static double OCCLUSIONBOOST = 1; // 0.5;
1460615634
1460715635 void keyReleased(int key, int modifiers)
....@@ -14609,11 +15637,11 @@
1460915637 //mode = ROTATE;
1461015638 if ((MODIFIERS & COMMAND) == 0) // VR??
1461115639 {
14612
- SetMouseMode(modifiers);
15640
+ SetMouseMode(0, modifiers);
1461315641 }
1461415642 }
1461515643
14616
- protected void processKeyEvent(KeyEvent e)
15644
+ public void processKeyEvent(KeyEvent e)
1461715645 {
1461815646 switch (e.getID())
1461915647 {
....@@ -14743,8 +15771,9 @@
1474315771
1474415772 protected void processMouseMotionEvent(MouseEvent e)
1474515773 {
14746
- //System.out.println("processMouseMotionEvent: " + mouseMode);
14747
- if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15774
+ //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
15775
+ //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15776
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1474815777 {
1474915778 mouseMoved(e);
1475015779 } else
....@@ -14769,11 +15798,12 @@
1476915798 }
1477015799 */
1477115800
14772
- object.editWindow.EditSelection();
15801
+ object.GetWindow().EditSelection(false);
1477315802 }
1477415803
1477515804 void SelectParent()
1477615805 {
15806
+ new Exception().printStackTrace();
1477715807 System.exit(0);
1477815808 Composite group = (Composite) object;
1477915809 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -14785,10 +15815,10 @@
1478515815 {
1478615816 //selectees.remove(i);
1478715817 System.out.println("select parent of " + elem);
14788
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15818
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1478915819 } else
1479015820 {
14791
- group.editWindow.Select(elem.GetTreePath(), first, true);
15821
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1479215822 }
1479315823
1479415824 first = false;
....@@ -14797,6 +15827,7 @@
1479715827
1479815828 void SelectChildren()
1479915829 {
15830
+ new Exception().printStackTrace();
1480015831 System.exit(0);
1480115832 /*
1480215833 Composite group = (Composite) object;
....@@ -14829,12 +15860,12 @@
1482915860 for (int j = 0; j < group.children.size(); j++)
1483015861 {
1483115862 elem = (Object3D) group.children.elementAt(j);
14832
- object.editWindow.Select(elem.GetTreePath(), first, true);
15863
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1483315864 first = false;
1483415865 }
1483515866 } else
1483615867 {
14837
- object.editWindow.Select(elem.GetTreePath(), first, true);
15868
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1483815869 }
1483915870
1484015871 first = false;
....@@ -14845,21 +15876,21 @@
1484515876 {
1484615877 //Composite group = (Composite) object;
1484715878 Object3D group = object;
14848
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15879
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1484915880 }
1485015881
1485115882 void ResetTransform(int mask)
1485215883 {
1485315884 //Composite group = (Composite) object;
1485415885 Object3D group = object;
14855
- group.editWindow.ResetTransform(mask);
15886
+ group.GetWindow().ResetTransform(mask);
1485615887 }
1485715888
1485815889 void FlipTransform()
1485915890 {
1486015891 //Composite group = (Composite) object;
1486115892 Object3D group = object;
14862
- group.editWindow.FlipTransform();
15893
+ group.GetWindow().FlipTransform();
1486315894 // group.editWindow.ReduceMesh(true);
1486415895 }
1486515896
....@@ -14867,7 +15898,7 @@
1486715898 {
1486815899 //Composite group = (Composite) object;
1486915900 Object3D group = object;
14870
- group.editWindow.PrintMemory();
15901
+ group.GetWindow().PrintMemory();
1487115902 // group.editWindow.ReduceMesh(true);
1487215903 }
1487315904
....@@ -14875,7 +15906,7 @@
1487515906 {
1487615907 //Composite group = (Composite) object;
1487715908 Object3D group = object;
14878
- group.editWindow.ResetCentroid();
15909
+ group.GetWindow().ResetCentroid();
1487915910 }
1488015911
1488115912 void IncDepth()
....@@ -14957,11 +15988,11 @@
1495715988
1495815989 int width = getBounds().width;
1495915990 int height = getBounds().height;
14960
- ClickInfo info = new ClickInfo();
14961
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1496215991 //Image img = CreateImage(width, height);
1496315992 //System.out.println("width = " + width + "; height = " + height + "\n");
15993
+
1496415994 Graphics gr = g; // img.getGraphics();
15995
+
1496515996 if (!hasMarquee)
1496615997 {
1496715998 if (Xmin < Xmax) // !locked)
....@@ -15033,40 +16064,88 @@
1503316064 }
1503416065 if (object != null && !hasMarquee)
1503516066 {
16067
+ if (object.clickInfo == null)
16068
+ object.clickInfo = new ClickInfo();
16069
+ ClickInfo info = object.clickInfo;
16070
+ //ClickInfo info = new ClickInfo();
16071
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16072
+
1503616073 if (isRenderer)
1503716074 {
15038
- info.flags++;
16075
+ object.clickInfo.flags++;
1503916076 double frameAspect = (double) width / (double) height;
1504016077 if (frameAspect > renderCamera.aspect)
1504116078 {
1504216079 int desired = (int) ((double) height * renderCamera.aspect);
15043
- info.bounds.width -= width - desired;
15044
- info.bounds.x += (width - desired) / 2;
16080
+ object.clickInfo.bounds.width -= width - desired;
16081
+ object.clickInfo.bounds.x += (width - desired) / 2;
1504516082 } else
1504616083 {
1504716084 int desired = (int) ((double) width / renderCamera.aspect);
15048
- info.bounds.height -= height - desired;
15049
- info.bounds.y += (height - desired) / 2;
16085
+ object.clickInfo.bounds.height -= height - desired;
16086
+ object.clickInfo.bounds.y += (height - desired) / 2;
1505016087 }
1505116088 }
15052
- info.g = gr;
15053
- info.camera = renderCamera;
16089
+
16090
+ object.clickInfo.g = gr;
16091
+ object.clickInfo.camera = renderCamera;
1505416092 /*
1505516093 // Memory intensive (brep.verticescopy)
1505616094 if (!(object instanceof Composite))
1505716095 object.draw(info, 0, false); // SLOW :
1505816096 */
15059
- if (!isRenderer)
16097
+ if (!isRenderer) // && drag)
1506016098 {
15061
- object.drawEditHandles(info, 0);
16099
+ Grafreed.Assert(object != null);
16100
+ Grafreed.Assert(object.selection != null);
16101
+ if (object.selection.Size() > 0)
16102
+ {
16103
+ int hitSomething = object.selection.get(0).hitSomething;
16104
+
16105
+ object.clickInfo.DX = 0;
16106
+ object.clickInfo.DY = 0;
16107
+ object.clickInfo.W = 1;
16108
+ if (hitSomething == Object3D.hitCenter)
16109
+ {
16110
+ info.DX = X;
16111
+ if (X != 0)
16112
+ info.DX -= info.bounds.width/2;
16113
+
16114
+ info.DY = Y;
16115
+ if (Y != 0)
16116
+ info.DY -= info.bounds.height/2;
16117
+ }
16118
+
16119
+ object.drawEditHandles(//info,
16120
+ 0);
16121
+
16122
+ if (drag && (X != 0 || Y != 0))
16123
+ {
16124
+ switch (hitSomething)
16125
+ {
16126
+ case Object3D.hitCenter: gr.setColor(Color.pink);
16127
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16128
+ break;
16129
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16130
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16131
+ break;
16132
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16133
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16134
+ break;
16135
+ }
16136
+
16137
+ }
16138
+ }
1506216139 }
1506316140 }
16141
+
1506416142 if (isRenderer)
1506516143 {
1506616144 //gr.setColor(Color.black);
1506716145 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1506816146 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1506916147 }
16148
+
1507016149 if (hasMarquee)
1507116150 {
1507216151 gr.setXORMode(Color.white);
....@@ -15179,6 +16258,7 @@
1517916258 public boolean mouseDown(Event evt, int x, int y)
1518016259 {
1518116260 System.out.println("mouseDown: " + evt);
16261
+ System.exit(0);
1518216262 /*
1518316263 locked = true;
1518416264 drag = false;
....@@ -15222,7 +16302,7 @@
1522216302 {
1522316303 keyPressed(0, modifiers);
1522416304 }
15225
- clickStart(x, y, modifiers);
16305
+ // clickStart(x, y, modifiers);
1522616306 return true;
1522716307 }
1522816308
....@@ -15340,7 +16420,7 @@
1534016420 {
1534116421 keyReleased(0, 0);
1534216422 }
15343
- drag(x, y, modifiers);
16423
+ drag(x, y, 0, modifiers);
1534416424 return true;
1534516425 }
1534616426
....@@ -15472,7 +16552,7 @@
1547216552 Object3D object;
1547316553 static Object3D trackedobject;
1547416554 Camera renderCamera; // Light or Eye (or Occlusion)
15475
- /*static*/ Camera manipCamera; // Light or Eye
16555
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1547616556 /*static*/ Camera eyeCamera;
1547716557 /*static*/ Camera lightCamera;
1547816558 int cameracount;
....@@ -15536,6 +16616,8 @@
1553616616 private /*static*/ boolean firstime;
1553716617 private /*static*/ cVector newView = new cVector();
1553816618 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16619
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16620
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1553916621 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1554016622 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1554116623 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -15548,29 +16630,67 @@
1554816630 {
1554916631 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1555016632
16633
+ int usedsuf = 0;
16634
+
1555116635 for (int i = 0; i < suffixes.length; i++)
1555216636 {
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)
16637
+ String[] suffixe = suffixes;
16638
+ String[] fallback = suffixes2;
16639
+ String[] fallfallback = suffixes3;
16640
+
16641
+ for (int c=usedsuf; --c>=0;)
1555816642 {
15559
- throw new IOException("Unable to load texture " + resourceName);
16643
+// String[] temp = suffixe;
16644
+// suffixe = fallback;
16645
+// fallback = fallfallback;
16646
+// fallfallback = temp;
1556016647 }
16648
+
16649
+ String resourceName = basename + suffixe[i] + "." + suffix;
16650
+ TextureData data;
16651
+
16652
+ try
16653
+ {
16654
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16655
+ mipmapped,
16656
+ FileUtil.getFileSuffix(resourceName));
16657
+ }
16658
+ catch (Exception e)
16659
+ {
16660
+ try
16661
+ {
16662
+ resourceName = basename + fallback[i] + "." + suffix;
16663
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16664
+ mipmapped,
16665
+ FileUtil.getFileSuffix(resourceName));
16666
+ }
16667
+ catch (Exception e2)
16668
+ {
16669
+ resourceName = basename + fallfallback[i] + "." + suffix;
16670
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16671
+ mipmapped,
16672
+ FileUtil.getFileSuffix(resourceName));
16673
+ }
16674
+ }
16675
+
1556116676 //System.out.println("Target = " + targets[i]);
1556216677 cubemap.updateImage(data, targets[i]);
1556316678 }
1556416679
1556516680 return cubemap;
1556616681 }
16682
+
1556716683 int bigsphere = -1;
1556816684
1556916685 float BGcolor = 0.5f;
1557016686
15571
- private void DrawSkyBox(GL gl)
16687
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16688
+
16689
+ private void DrawSkyBox(GL gl, float ratio)
1557216690 {
15573
- if (envyoff || cubemap == null)
16691
+ if (//envyoff ||
16692
+ WIREFRAME ||
16693
+ cubemap == null)
1557416694 {
1557516695 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1557616696 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -15585,7 +16705,17 @@
1558516705 // Compensates for ExaminerViewer's modification of modelview matrix
1558616706 gl.glMatrixMode(GL.GL_MODELVIEW);
1558716707 gl.glLoadIdentity();
16708
+ gl.glScalef(1,ratio,1);
1558816709
16710
+// colorV[0] = 2;
16711
+// colorV[1] = 2;
16712
+// colorV[2] = 2;
16713
+// colorV[3] = 1;
16714
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16715
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16716
+//
16717
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16718
+
1558916719 //gl.glActiveTexture(GL.GL_TEXTURE1);
1559016720 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1559116721
....@@ -15617,6 +16747,7 @@
1561716747 {
1561816748 gl.glScalef(1.0f, -1.0f, 1.0f);
1561916749 }
16750
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1562016751 gl.glMultMatrixd(viewrot_1, 0);
1562116752 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1562216753 //viewer.updateInverseRotation(gl);
....@@ -15757,16 +16888,16 @@
1575716888 cStatic.objectstack[materialdepth++] = checker;
1575816889 //System.out.println("material " + material);
1575916890 //Applet3D.tracein(this, selected);
15760
- vector2buffer = checker.projectedVertices;
16891
+ //vector2buffer = checker.projectedVertices;
1576116892
1576216893 //checker.GetMaterial().Draw(this, false); // true);
15763
- DrawMaterial(checker.GetMaterial(), false); // true);
16894
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1576416895
1576516896 materialdepth -= 1;
1576616897 if (materialdepth > 0)
1576716898 {
15768
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
15769
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
16899
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16900
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1577016901 }
1577116902 //checker.GetMaterial().opacity = 1f;
1577216903 ////checker.GetMaterial().ambient = 1f;
....@@ -15852,6 +16983,14 @@
1585216983 }
1585316984 }
1585416985
16986
+ private Object3D GetFolder()
16987
+ {
16988
+ Object3D folder = object.GetWindow().copy;
16989
+ if (object.GetWindow().copy.selection.Size() > 0)
16990
+ folder = object.GetWindow().copy.selection.elementAt(0);
16991
+ return folder;
16992
+ }
16993
+
1585516994 class SelectBuffer implements GLEventListener
1585616995 {
1585716996
....@@ -15867,7 +17006,7 @@
1586717006 //new Exception().printStackTrace();
1586817007 System.out.println("select buffer init");
1586917008 // Use debug pipeline
15870
- drawable.setGL(new DebugGL(drawable.getGL()));
17009
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1587117010
1587217011 GL gl = drawable.getGL();
1587317012
....@@ -15910,6 +17049,7 @@
1591017049 {
1591117050 if (!selection)
1591217051 {
17052
+ new Exception().printStackTrace();
1591317053 System.exit(0);
1591417054 return;
1591517055 }
....@@ -15930,6 +17070,17 @@
1593017070
1593117071 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1593217072
17073
+ if (PAINTMODE)
17074
+ {
17075
+ if (object.GetWindow().copy.selection.Size() > 0)
17076
+ {
17077
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17078
+
17079
+ // Make what you paint not selectable.
17080
+ paintobj.ResetSelectable();
17081
+ }
17082
+ }
17083
+
1593317084 //int tmp = selection_view;
1593417085 //selection_view = -1;
1593517086 int temp = DrawMode();
....@@ -15941,6 +17092,17 @@
1594117092 // temp = DEFAULT; // patch for selection debug
1594217093 Globals.drawMode = temp; // WARNING
1594317094
17095
+ if (PAINTMODE)
17096
+ {
17097
+ if (object.GetWindow().copy.selection.Size() > 0)
17098
+ {
17099
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17100
+
17101
+ // Revert.
17102
+ paintobj.RestoreSelectable();
17103
+ }
17104
+ }
17105
+
1594417106 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1594517107
1594617108 // trying different ways of getting the depth info over
....@@ -15988,6 +17150,8 @@
1598817150 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1598917151 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1599017152 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
17153
+
17154
+ CreateSelectedPoint();
1599117155
1599217156 // Will fit the mesh !!!
1599317157 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16037,34 +17201,36 @@
1603717201 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]));
1603817202 }
1603917203
16040
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
17204
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1604117205 }
1604217206 }
1604317207
1604417208 if (!movingcamera && !PAINTMODE)
16045
- object.editWindow.ScreenFitPoint(); // fev 2014
17209
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1604617210
16047
- if (PAINTMODE && GrafreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17211
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1604817212 {
16049
- Object3D paintobj = GrafreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17213
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1605017214
16051
- Object3D group = new Object3D("inst" + paintcount++);
17215
+ if (object.GetWindow().copy.selection.Size() > 0)
17216
+ {
17217
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1605217218
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();
17219
+ Object3D inst = new Object3D("inst" + paintcount++);
17220
+
17221
+ inst.CreateMaterial(); // use a void leaf to select instances
17222
+
17223
+ inst.add(paintobj); // link
17224
+
17225
+ object.GetWindow().SnapObject(inst);
17226
+
17227
+ Object3D folder = paintFolder; // GetFolder();
17228
+
17229
+ folder.add(inst);
17230
+
17231
+ object.GetWindow().ResetModel();
17232
+ object.GetWindow().refreshContents();
17233
+ }
1606817234 }
1606917235 else
1607017236 paintcount = 0;
....@@ -16103,6 +17269,11 @@
1610317269 //System.out.println("objects[color] = " + objects[color]);
1610417270 //objects[color].Select();
1610517271 indexcount = 0;
17272
+ ObjEditor window = object.GetWindow();
17273
+ if (window != null && deselect)
17274
+ {
17275
+ window.Select(null, deselect, true);
17276
+ }
1610617277 object.Select(color, deselect);
1610717278 }
1610817279
....@@ -16202,7 +17373,7 @@
1620217373 gl.glDisable(gl.GL_CULL_FACE);
1620317374 }
1620417375
16205
- if (!RENDERSHADOW)
17376
+ if (!Globals.RENDERSHADOW)
1620617377 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1620717378
1620817379 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -16212,7 +17383,7 @@
1621217383 //gl.glColorMask(false, false, false, false);
1621317384
1621417385 //render_scene_from_light_view(gl, drawable, 0, 0);
16215
- if (RENDERSHADOW && Globals.lighttouched && !movingcamera) // && !parent.IsFreezed())
17386
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1621617387 {
1621717388 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1621817389
....@@ -16381,10 +17552,14 @@
1638117552 gl.glFlush();
1638217553
1638317554 /**/
16384
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17555
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1638517556
16386
- float[] pixels = occlusionsizebuffer.array();
17557
+ float[] depths = occlusiondepthbuffer.array();
1638717558
17559
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17560
+
17561
+ int[] pixels = selectsizebuffer.array();
17562
+
1638817563 double r = 0, g = 0, b = 0;
1638917564
1639017565 double count = 0;
....@@ -16395,7 +17570,7 @@
1639517570
1639617571 double FACTOR = 1;
1639717572
16398
- for (int i = 0; i < pixels.length; i++)
17573
+ for (int i = 0; i < depths.length; i++)
1639917574 {
1640017575 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1640117576 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -16478,7 +17653,7 @@
1647817653
1647917654 double scale = ray.z; // 1; // cos
1648017655
16481
- float depth = pixels[newindex];
17656
+ float depth = depths[newindex];
1648217657
1648317658 /*
1648417659 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -16628,23 +17803,15 @@
1662817803 int AAbuffersize = 0;
1662917804
1663017805 //double[] selectedpoint = new double[3];
16631
- static Superellipsoid selectedpoint = new Superellipsoid();
17806
+ static Superellipsoid selectedpoint;
1663217807 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();
17808
+ static Sphere debugpointG;
17809
+ static Sphere debugpointP;
17810
+ static Sphere debugpointC;
17811
+ static Sphere debugpointR;
1663717812
1663817813 static Sphere debugpoints[] = new Sphere[8];
1663917814
16640
- static
16641
- {
16642
- for (int i=0; i<8; i++)
16643
- {
16644
- debugpoints[i] = new Sphere();
16645
- }
16646
- }
16647
-
1664817815 static void InitPoints(float radius)
1664917816 {
1665017817 for (int i=0; i<8; i++)
....@@ -16683,11 +17850,14 @@
1668317850 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1668417851 static IntBuffer bigAAbuffer;
1668517852 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
16686
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17853
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1668717854 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1668817855 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1668917856 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
16690
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17857
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17858
+
17859
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17860
+
1669117861 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1669217862 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1669317863 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();
....@@ -16696,10 +17866,11 @@
1669617866 static IntBuffer textbuffer = null; // IntBuffer.allocate(TEXT_WIDTH*8*8 * TEXT_HEIGHT);
1669717867 // Depth buffer format
1669817868 //private int depth_format;
16699
- static public void NextIndex(Object3D o, GL gl)
17869
+
17870
+ public void NextIndex()
1670017871 {
1670117872 indexcount+=16;
16702
- gl.glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
17873
+ GetGL().glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
1670317874 //objects[indexcount] = o;
1670417875 //System.out.println("indexcount = " + indexcount);
1670517876 }