Normand Briere
2019-08-22 6a145f6c81dfcbe0653eda27d042efb48daa7512
CameraPane.java
....@@ -18,7 +18,10 @@
1818 import javax.imageio.ImageIO;
1919 import javax.imageio.ImageWriteParam;
2020 import javax.imageio.ImageWriter;
21
+import javax.imageio.ImageReadParam;
22
+import javax.imageio.ImageReader;
2123 import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
24
+import javax.imageio.stream.ImageInputStream;
2225 import javax.imageio.stream.ImageOutputStream;
2326 import javax.imageio.ImageWriteParam;
2427
....@@ -30,6 +33,7 @@
3033 import java.nio.*;
3134
3235 import gleem.linalg.Mat4f;
36
+import javax.imageio.ImageTypeSpecifier;
3337
3438 class CameraPane extends GLCanvas implements iCameraPane, Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener
3539 {
....@@ -37,7 +41,6 @@
3741 static boolean[] selectedstack = new boolean[65536];
3842 static int materialdepth = 0;
3943
40
- static boolean DEBUG = false;
4144 static boolean FRUSTUM = false; // still bogus true; // frustum culling
4245
4346 // camera change fix
....@@ -45,6 +48,39 @@
4548 static boolean ABORTED = false;
4649
4750 static int STEP = 1;
51
+
52
+ private static BufferedImage CreateBim(byte[] bytes, int width, int height)
53
+ {
54
+ int[] pixels = new int[bytes.length/3];
55
+ for (int i=pixels.length; --i>=0;)
56
+ {
57
+ int i3 = i*3;
58
+ pixels[i] = 0xFF;
59
+ pixels[i] <<= 8;
60
+ pixels[i] |= bytes[i3+2] & 0xFF;
61
+ pixels[i] <<= 8;
62
+ pixels[i] |= bytes[i3+1] & 0xFF;
63
+ pixels[i] <<= 8;
64
+ pixels[i] |= bytes[i3] & 0xFF;
65
+ }
66
+ /*
67
+ int r=0,g=0,b=0,a=0;
68
+ for (int i=0; i<width; i++)
69
+ for (int j=0; j<height; j++)
70
+ {
71
+ int index = j*width+i;
72
+ int p = pixels[index];
73
+ a = ((p>>24) & 0xFF);
74
+ r = ((p>>16) & 0xFF);
75
+ g = ((p>>8) & 0xFF);
76
+ b = (p & 0xFF);
77
+ pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
78
+ }
79
+ /**/
80
+ BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
81
+ rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
82
+ return rendImage;
83
+ }
4884
4985 /*static*/ private boolean CULLFACE = false; // true;
5086 /*static*/ boolean NEAREST = false; // true;
....@@ -56,14 +92,12 @@
5692 static int CURRENTANTIALIAS = 0; // 1;
5793 /*static*/ boolean RENDERSHADOW = true;
5894 /*static*/ int RENDERPROGRAM = 2; // 0 == none, 1 == fast, 2 == normal
59
- static boolean ANIMATION = false;
60
- static String filename;
6195
6296 boolean DISPLAYTEXT = false;
6397 //boolean REDUCETEXTURE = true;
6498 boolean CACHETEXTURE = true;
6599 boolean CLEANCACHE = false; // true;
66
- boolean MIPMAP = false; // true;
100
+ boolean MIPMAP = false; // true; // never works...
67101 boolean COMPRESSTEXTURE = false;
68102 boolean KOMPACTTEXTURE = false; // true;
69103 boolean RESIZETEXTURE = false;
....@@ -76,7 +110,11 @@
76110 //private Mat4f spotlightTransform = new Mat4f();
77111 //private Mat4f spotlightInverseTransform = new Mat4f();
78112 static GLContext glcontext = null;
79
- /*static*/ com.sun.opengl.util.texture.Texture cubemap;
113
+ /*static*/ com.sun.opengl.util.texture.Texture cubemap; // Either custom or rgb
114
+ /*static*/ com.sun.opengl.util.texture.Texture cubemapcustom;
115
+ /*static*/ com.sun.opengl.util.texture.Texture cubemaprgb;
116
+ boolean transformMode;
117
+
80118 boolean reverseUP = false;
81119 static boolean frozen = false;
82120 boolean enablebackspace = false; // patch for back buffer refresh
....@@ -92,6 +130,8 @@
92130
93131 static int tickcount = 0; // slow pose issue
94132
133
+static boolean BUTTONLESSWHEEL = false;
134
+static boolean ZOOMBOXMODE = false;
95135 static boolean BOXMODE = false;
96136 static boolean IMAGEFLIP = false;
97137 static boolean SMOOTHFOCUS = false;
....@@ -106,7 +146,7 @@
106146 static boolean OEIL = true;
107147 static boolean OEILONCE = false; // do oeilon then oeiloff
108148 static boolean LOOKAT = true;
109
-static boolean RANDOM = true; // false;
149
+static boolean SWITCH = true; // false;
110150 static boolean HANDLES = false; // selection doesn't work!!
111151 static boolean PAINTMODE = false;
112152
....@@ -128,7 +168,7 @@
128168
129169
130170 // OPTIONS
131
- boolean Skinshader = true;
171
+ boolean Skinshader = false; // true;
132172 boolean cameraLight = false;
133173 boolean UVdebug = false;
134174 boolean Udebug = false;
....@@ -137,7 +177,7 @@
137177 static boolean doublesided = false; // true; // reversed normals are awful for conformance
138178 boolean anisotropy = true;
139179 boolean softshadow = true; // slower but better false;
140
- boolean opacityhalo = false;
180
+ boolean opacityhalo = false; // reverse the halo effect (e.g. glass)
141181
142182 boolean macromode = false;
143183
....@@ -150,12 +190,25 @@
150190 defaultcaps.setAccumAlphaBits(16);
151191 }
152192
153
- static CameraPane theRenderer;
193
+ private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
194
+
195
+ public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException
196
+ {
197
+ try
198
+ {
199
+ return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
200
+ } catch (IOException e)
201
+ {
202
+ System.out.println("NAME = " + name);
203
+ e.printStackTrace(); // throw new RuntimeException(e);
204
+ return null;
205
+ }
206
+ }
154207
155208 void SetAsGLRenderer(boolean b)
156209 {
157210 isRenderer = b;
158
- theRenderer = this;
211
+ Globals.theRenderer = this;
159212 }
160213
161214 CameraPane(Object3D o, Camera cam, boolean withcontext)
....@@ -170,7 +223,8 @@
170223
171224 SetCamera(cam);
172225
173
- SetLight(new Camera(new cVector(10, 10, -20)));
226
+ // Warning: not used.
227
+ SetLight(new Camera(new cVector(15, 10, -20)));
174228
175229 object = o;
176230
....@@ -193,9 +247,43 @@
193247
194248 /// INTERFACE
195249
250
+ public javax.media.opengl.GL GetGL0()
251
+ {
252
+ return null;
253
+ }
254
+
255
+ public int GenList()
256
+ {
257
+ javax.media.opengl.GL gl = GetGL();
258
+ return gl.glGenLists(1);
259
+ }
260
+
261
+ public void NewList(int id)
262
+ {
263
+ javax.media.opengl.GL gl = GetGL();
264
+ gl.glNewList(id, gl.GL_COMPILE); //_AND_EXECUTE);
265
+ }
266
+
267
+ public void CallList(int id)
268
+ {
269
+ javax.media.opengl.GL gl = GetGL();
270
+ gl.glCallList(id);
271
+ }
272
+
273
+ public void EndList()
274
+ {
275
+ javax.media.opengl.GL gl = GetGL();
276
+ gl.glEndList();
277
+ }
278
+
196279 public boolean IsBoxMode()
197280 {
198281 return BOXMODE;
282
+ }
283
+
284
+ public boolean IsZoomBoxMode()
285
+ {
286
+ return ZOOMBOXMODE;
199287 }
200288
201289 public void ClearDepth()
....@@ -293,7 +381,7 @@
293381 cStatic.objectstack[materialdepth++] = obj;
294382 //System.out.println("material " + material);
295383 //Applet3D.tracein(this, selected);
296
- display.vector2buffer = obj.projectedVertices;
384
+ //display.vector2buffer = obj.projectedVertices;
297385 if (obj instanceof Camera)
298386 {
299387 display.options1[0] = material.shift;
....@@ -302,14 +390,28 @@
302390 display.options1[2] = material.shadowbias;
303391 display.options1[3] = material.aniso;
304392 display.options1[4] = material.anisoV;
393
+// System.out.println("display.options1[0] " + display.options1[0]);
394
+// System.out.println("display.options1[1] " + display.options1[1]);
395
+// System.out.println("display.options1[2] " + display.options1[2]);
396
+// System.out.println("display.options1[3] " + display.options1[3]);
397
+// System.out.println("display.options1[4] " + display.options1[4]);
305398 display.options2[0] = material.opacity;
306399 display.options2[1] = material.diffuse;
307400 display.options2[2] = material.factor;
401
+// System.out.println("display.options2[0] " + display.options2[0]);
402
+// System.out.println("display.options2[1] " + display.options2[1]);
403
+// System.out.println("display.options2[2] " + display.options2[2]);
308404
309405 cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
406
+// System.out.println("display.options3[0] " + display.options3[0]);
407
+// System.out.println("display.options3[1] " + display.options3[1]);
408
+// System.out.println("display.options3[2] " + display.options3[2]);
310409 display.options4[0] = material.cameralight/0.2f;
311410 display.options4[1] = material.subsurface;
312411 display.options4[2] = material.sheen;
412
+// System.out.println("display.options4[0] " + display.options4[0]);
413
+// System.out.println("display.options4[1] " + display.options4[1]);
414
+// System.out.println("display.options4[2] " + display.options4[2]);
313415
314416 // if (display.CURRENTANTIALIAS > 0)
315417 // display.options3[3] /= 4;
....@@ -325,7 +427,7 @@
325427 /**/
326428 } else
327429 {
328
- DrawMaterial(material, selected);
430
+ DrawMaterial(material, selected, obj.projectedVertices);
329431 }
330432 } else
331433 {
....@@ -349,8 +451,8 @@
349451 cStatic.objectstack[materialdepth++] = obj;
350452 //System.out.println("material " + material);
351453 //Applet3D.tracein("selected ", selected);
352
- display.vector2buffer = obj.projectedVertices;
353
- display.DrawMaterial(material, selected);
454
+ //display.vector2buffer = obj.projectedVertices;
455
+ display.DrawMaterial(material, selected, obj.projectedVertices);
354456 }
355457 }
356458
....@@ -367,8 +469,8 @@
367469 materialdepth -= 1;
368470 if (materialdepth > 0)
369471 {
370
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
371
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
472
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
473
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
372474 }
373475 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
374476 } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
....@@ -388,8 +490,8 @@
388490 materialdepth -= 1;
389491 if (materialdepth > 0)
390492 {
391
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
392
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
493
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
494
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
393495 }
394496 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
395497 //else
....@@ -430,15 +532,18 @@
430532 if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
431533 {
432534 //gl.glBegin(gl.GL_TRIANGLES);
433
- boolean hasnorm = pv.norm != null; // && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0);
535
+ boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0)
536
+ // TEST LIVE NORMALS && !obj.dontselect
537
+ ;
434538 if (!hasnorm)
435539 {
436
- // System.out.println("FUCK!!");
540
+ // System.out.println("Mesh normal");
437541 LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
438542 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
439543 LA.vecCross(obj.v0, obj.v1, obj.v2);
440544 LA.vecNormalize(obj.v2);
441
- gl.glNormal3f((float) obj.v2.x, (float) obj.v2.y, (float) obj.v2.z);
545
+
546
+ SetGLNormal(gl, (float) obj.v2.x, (float) obj.v2.y, (float) obj.v2.z);
442547 }
443548
444549 // P
....@@ -460,7 +565,7 @@
460565 y += ny * obj.NORMALPUSH;
461566 z += nz * obj.NORMALPUSH;
462567
463
- gl.glNormal3f(nx, ny, nz);
568
+ SetGLNormal(gl, nx, ny, nz);
464569 }
465570 gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
466571 SetColor(obj, pv);
....@@ -492,7 +597,7 @@
492597 y += ny * obj.NORMALPUSH;
493598 z += nz * obj.NORMALPUSH;
494599
495
- gl.glNormal3f(nx, ny, nz);
600
+ SetGLNormal(gl, nx, ny, nz);
496601 }
497602 //System.out.println("vertexq = " + qv.s + ", " + qv.t);
498603 // boolean locked = false;
....@@ -540,7 +645,7 @@
540645 y += ny * obj.NORMALPUSH;
541646 z += nz * obj.NORMALPUSH;
542647
543
- gl.glNormal3f(nx, ny, nz);
648
+ SetGLNormal(gl, nx, ny, nz);
544649 }
545650
546651 // if ((dot&4) == 0)
....@@ -816,7 +921,7 @@
816921
817922 if ((i % 100) == 0 && i != 0)
818923 {
819
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
924
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
820925 //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
821926 System.out.println((int) (100.0 * i / (br.positions.length / 3)) + "% (" + i + " of " + (br.positions.length / 3) + ")");
822927 }
....@@ -848,7 +953,7 @@
848953
849954 if ((i % 100) == 0 && i != 0)
850955 {
851
- CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
956
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
852957 //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
853958 System.out.println((int) (100.0 * i / br.VertexCount()) + "% (" + i + " of " + br.VertexCount() + ")");
854959 }
....@@ -1061,8 +1166,345 @@
10611166 gl.glMatrixMode(gl.GL_MODELVIEW);
10621167 }
10631168
1169
+ public void DrawBox(cVector min, cVector max)
1170
+ {
1171
+ javax.media.opengl.GL gl = GetGL();
1172
+ gl.glBegin(gl.GL_LINES);
1173
+
1174
+ gl.glVertex3d(min.x, min.y, min.z);
1175
+ gl.glVertex3d(min.x, min.y, max.z);
1176
+ gl.glVertex3d(min.x, min.y, min.z);
1177
+ gl.glVertex3d(min.x, max.y, min.z);
1178
+ gl.glVertex3d(min.x, min.y, min.z);
1179
+ gl.glVertex3d(max.x, min.y, min.z);
1180
+
1181
+ gl.glVertex3d(max.x, max.y, max.z);
1182
+ gl.glVertex3d(min.x, max.y, max.z);
1183
+ gl.glVertex3d(max.x, max.y, max.z);
1184
+ gl.glVertex3d(max.x, min.y, max.z);
1185
+ gl.glVertex3d(max.x, max.y, max.z);
1186
+ gl.glVertex3d(max.x, max.y, min.z);
1187
+
1188
+ gl.glEnd();
1189
+ }
1190
+
1191
+ public void DrawGeometry(BoundaryRep bRep, boolean flipV, boolean selectmode)
1192
+ {
1193
+ int[] strips = bRep.getRawIndices();
1194
+
1195
+ javax.media.opengl.GL gl = GetGL();
1196
+
1197
+ // TRIANGLE STRIP ARRAY
1198
+ if (bRep.trimmed)
1199
+ {
1200
+ float[] v = bRep.getRawVertices();
1201
+ float[] n = bRep.getRawNormals();
1202
+ float[] c = bRep.getRawColors();
1203
+ float[] uv = bRep.getRawUVMap();
1204
+
1205
+ int count2 = 0;
1206
+ int count3 = 0;
1207
+
1208
+ if (n.length > 0)
1209
+ {
1210
+ for (int i = 0; i < strips.length; i++)
1211
+ {
1212
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1213
+
1214
+ /*
1215
+ boolean locked = false;
1216
+ float eps = 0.1f;
1217
+ boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
1218
+
1219
+ int dot = 0;
1220
+
1221
+ if ((dot&1) == 0)
1222
+ dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
1223
+
1224
+ if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
1225
+ gl.glTexCoord2f((float) qv.s, (float) qv.t);
1226
+ else
1227
+ {
1228
+ locked = true;
1229
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1230
+ }
1231
+ //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
1232
+ gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
1233
+ if (hasnorm)
1234
+ {
1235
+ //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
1236
+ gl.glNormal3f((float) rv.norm.x, (float) rv.norm.y, (float) rv.norm.z);
1237
+ }
1238
+
1239
+ if ((dot&4) == 0)
1240
+ dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
1241
+
1242
+ if (wrap || !locked && (dot&8) != 0)
1243
+ gl.glTexCoord2f((float) rv.s, (float) rv.t);
1244
+ else
1245
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1246
+
1247
+ f.dot = dot;
1248
+ */
1249
+
1250
+ if (!selectmode)
1251
+ {
1252
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1253
+ {
1254
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
1255
+ } else
1256
+ {
1257
+ SetGLNormal(gl, 0, 0, 1);
1258
+ }
1259
+
1260
+ if (c != null)
1261
+ //System.out.println("glcolor = " + c[count3] + ", " + c[count3+1] + ", " + c[count3+2]);
1262
+ {
1263
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1264
+ }
1265
+ }
1266
+
1267
+ if (flipV)
1268
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1269
+ else
1270
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1271
+
1272
+ //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1273
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1274
+
1275
+ count2 += 2;
1276
+ count3 += 3;
1277
+ if (!selectmode)
1278
+ {
1279
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1280
+ {
1281
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
1282
+ } else
1283
+ {
1284
+ SetGLNormal(gl, 0, 0, 1);
1285
+ }
1286
+ if (c != null)
1287
+ {
1288
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1289
+ }
1290
+ }
1291
+
1292
+ if (flipV)
1293
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1294
+ else
1295
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1296
+
1297
+ //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1298
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1299
+
1300
+ count2 += 2;
1301
+ count3 += 3;
1302
+ for (int j = 0; j < strips[i] - 2; j++)
1303
+ {
1304
+ //gl.glTexCoord2d(...);
1305
+ if (!selectmode)
1306
+ {
1307
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1308
+ {
1309
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
1310
+ } else
1311
+ {
1312
+ SetGLNormal(gl, 0, 0, 1);
1313
+ }
1314
+ if (c != null)
1315
+ {
1316
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1317
+ }
1318
+ }
1319
+
1320
+ if (flipV)
1321
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1322
+ else
1323
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1324
+
1325
+ //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
1326
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1327
+
1328
+ count2 += 2;
1329
+ count3 += 3;
1330
+ }
1331
+
1332
+ gl.glEnd();
1333
+ }
1334
+ }
1335
+
1336
+ assert count3 == v.length;
1337
+ }
1338
+ else // !trimmed
1339
+ {
1340
+ int count = 0;
1341
+ for (int i = 0; i < strips.length; i++)
1342
+ {
1343
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1344
+
1345
+ Vertex p = bRep.GetVertex(bRep.indices[count++]);
1346
+ Vertex q = bRep.GetVertex(bRep.indices[count++]);
1347
+
1348
+ drawVertex(gl, p, flipV, selectmode);
1349
+ drawVertex(gl, q, flipV, selectmode);
1350
+
1351
+ for (int j = 0; j < strips[i] - 2; j++)
1352
+ {
1353
+ Vertex r = bRep.GetVertex(bRep.indices[count++]);
1354
+
1355
+ // if (j%2 == 0)
1356
+ // drawFace(p, q, r, display, null);
1357
+ // else
1358
+ // drawFace(p, r, q, display, null);
1359
+
1360
+ // p = q;
1361
+ // q = r;
1362
+ drawVertex(gl, r, flipV, selectmode);
1363
+ }
1364
+
1365
+ gl.glEnd();
1366
+ }
1367
+ }
1368
+ }
1369
+
1370
+ static cSpring.Point3D temp = new cSpring.Point3D();
1371
+ static cSpring.Point3D temp2 = new cSpring.Point3D();
1372
+ static cSpring.Point3D temp3 = new cSpring.Point3D();
1373
+
1374
+ public void DrawDynamicMesh(cMesh mesh)
1375
+ {
1376
+ GL gl = GetGL(); // getGL();
1377
+
1378
+ cSpring.PhysicsController3D Phys = mesh.Phys;
1379
+
1380
+ gl.glDisable(gl.GL_LIGHTING);
1381
+
1382
+ gl.glLineWidth(1);
1383
+ gl.glColor3f(1,1,1);
1384
+ gl.glBegin(gl.GL_LINES);
1385
+ double scale = 0;
1386
+ int count = 0;
1387
+ for (int s=0; s<Phys.allSprings.size(); s++)
1388
+ {
1389
+ cSpring.Spring spring = Phys.allSprings.get(s);
1390
+ if(s == 0)
1391
+ {
1392
+ //System.out.println(" spring : " + spring.a.position + "; " + spring.b.position);
1393
+ }
1394
+ if (mesh.showsprings)
1395
+ {
1396
+ temp.set(spring.a.position);
1397
+ temp.add(spring.b.position);
1398
+ temp.mul(0.5);
1399
+ temp2.set(spring.a.position);
1400
+ temp2.sub(spring.b.position);
1401
+ temp2.mul(spring.restLength/2);
1402
+ temp.sub(temp2);
1403
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1404
+ temp.add(temp2);
1405
+ temp.add(temp2);
1406
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1407
+ }
1408
+
1409
+ if (spring.isHandle)
1410
+ continue;
1411
+
1412
+ //if (scale < spring.restLength)
1413
+ scale += spring.restLength;
1414
+ count++;
1415
+ }
1416
+ gl.glEnd();
1417
+
1418
+ if (count == 0)
1419
+ scale = 0.01;
1420
+ else
1421
+ scale /= count * 3;
1422
+
1423
+ //scale = 0.25;
1424
+
1425
+ if (mesh.ShowInfo())
1426
+ {
1427
+ gl.glLineWidth(4);
1428
+ for (int s=0; s<Phys.allNodes.size(); s++)
1429
+ {
1430
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1431
+ if (node.mass == 0)
1432
+ continue;
1433
+
1434
+ int i = node.springs==null?-1:node.springs.size();
1435
+ gl.glColor3f((i>>2)&1,(i>>1)&1,i&1);
1436
+ //temp.set(node.springForce.x, node.springForce.y, node.springForce.z);
1437
+ //temp.normalize();
1438
+ //gl.glColor3d((temp.x+1)/2, (temp.y+1)/2, (temp.z+1)/2);
1439
+ gl.glBegin(gl.GL_LINES);
1440
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1441
+ //gl.glVertex3d(node.position.x + node.normal.x*scale, node.position.y + node.normal.y*scale, node.position.z + node.normal.z*scale);
1442
+ gl.glVertex3d(node.position.x + mesh.bRep.GetVertex(s).norm.x*scale,
1443
+ node.position.y + mesh.bRep.GetVertex(s).norm.y*scale,
1444
+ node.position.z + mesh.bRep.GetVertex(s).norm.z*scale);
1445
+ gl.glEnd();
1446
+ }
1447
+
1448
+ gl.glLineWidth(8);
1449
+ for (int s=0; s<Phys.allNodes.size(); s++)
1450
+ {
1451
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1452
+
1453
+ if (node.springs != null)
1454
+ {
1455
+ for (int i=0; i<node.springs.size(); i+=1)
1456
+ {
1457
+ cSpring.DynamicNode f = node.springs.get(i).GetOther(node);
1458
+
1459
+ int c = i+1;
1460
+ // c = node.springs.get(i).nbcopies;
1461
+
1462
+ gl.glColor3f((c>>2)&1,(c>>1)&1,c&1);
1463
+ gl.glBegin(gl.GL_LINES);
1464
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1465
+ gl.glVertex3d(f.position.x/3+node.position.x*2/3, f.position.y/3+node.position.y*2/3, f.position.z/3+node.position.z*2/3);
1466
+ gl.glEnd();
1467
+ }
1468
+ }
1469
+ }
1470
+
1471
+ gl.glLineWidth(1);
1472
+ }
1473
+
1474
+ gl.glEnable(gl.GL_LIGHTING);
1475
+ }
1476
+
10641477 /// INTERFACE
10651478
1479
+ public void StartTriangles()
1480
+ {
1481
+ javax.media.opengl.GL gl = GetGL();
1482
+ gl.glBegin(gl.GL_TRIANGLES);
1483
+ }
1484
+
1485
+ public void EndTriangles()
1486
+ {
1487
+ GetGL().glEnd();
1488
+ }
1489
+
1490
+ void drawVertex(javax.media.opengl.GL gl, Vertex pv, boolean flipV, boolean selectmode)
1491
+ {
1492
+ if (!selectmode)
1493
+ {
1494
+ SetGLNormal(gl, (float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
1495
+ gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
1496
+
1497
+ if (flipV)
1498
+ gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
1499
+ else
1500
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1501
+ }
1502
+
1503
+ gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
1504
+ }
1505
+
1506
+ float[] colorV = new float[4];
1507
+
10661508 void SetColor(Object3D obj, Vertex p0)
10671509 {
10681510 CameraPane display = this;
....@@ -1130,8 +1572,6 @@
11301572 {
11311573 return;
11321574 }
1133
-
1134
- float[] colorV = new float[3];
11351575
11361576 if (false) // marked)
11371577 {
....@@ -1240,7 +1680,7 @@
12401680 // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
12411681 }
12421682
1243
- void DrawMaterial(cMaterial material, boolean selected)
1683
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
12441684 {
12451685 CameraPane display = this;
12461686 //new Exception().printStackTrace();
....@@ -1256,18 +1696,18 @@
12561696 //col.getColorComponents(ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB), CameraPane.modelParams0);
12571697 if (!material.multiply)
12581698 {
1259
- display.color = color;
1699
+ display.color = material.color;
12601700 display.saturation = material.modulation;
12611701 }
12621702 else
12631703 {
1264
- display.color *= color*2;
1704
+ display.color *= material.color*2;
12651705 display.saturation *= material.modulation*2;
12661706 }
12671707
12681708 cColor.HSBtoRGB(display.color, display.saturation, 1, display.modelParams0);
12691709
1270
- float[] colorV = GrafreeD.colorV;
1710
+ float[] colorV = Grafreed.colorV;
12711711
12721712 /**/
12731713 if (display.DrawMode() == display.DEFAULT) // && display.RENDERPROGRAM == 0)
....@@ -1275,7 +1715,7 @@
12751715 colorV[0] = display.modelParams0[0] * material.diffuse;
12761716 colorV[1] = display.modelParams0[1] * material.diffuse;
12771717 colorV[2] = display.modelParams0[2] * material.diffuse;
1278
- colorV[3] = material.opacity;
1718
+ colorV[3] = 1; // material.opacity;
12791719
12801720 gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
12811721 //System.out.println("Opacity = " + opacity);
....@@ -1380,12 +1820,12 @@
13801820
13811821 display.modelParams7[0] = 0;
13821822 display.modelParams7[1] = 1000;
1383
- display.modelParams7[2] = 0;
1823
+ display.modelParams7[2] = material.parallax;
13841824 display.modelParams7[3] = 0;
13851825
1386
- display.modelParams6[0] = 100; // criss de bug de bump
1826
+ //display.modelParams6[0] = 100; // criss de bug de bump
13871827
1388
- Object3D.cVector2[] extparams = display.vector2buffer;
1828
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
13891829 if (extparams != null && extparams.length > 0 && extparams[0] != null)
13901830 {
13911831 display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
....@@ -1527,7 +1967,7 @@
15271967 void PushMatrix(double[][] matrix)
15281968 {
15291969 // GrafreeD.tracein(matrix);
1530
- PushMatrix(matrix,1);
1970
+ PushMatrix(matrix, 1);
15311971 }
15321972
15331973 void PushMatrix()
....@@ -1613,9 +2053,9 @@
16132053 switch(viewcode)
16142054 {
16152055 case 0: return "main";
1616
- case 1: return "one";
1617
- case 2: return "two";
1618
- case 3: return "three";
2056
+ case 1: return "Red";
2057
+ case 2: return "Green";
2058
+ case 3: return "Blue";
16192059 case 4: return "light";
16202060 }
16212061
....@@ -1624,7 +2064,7 @@
16242064
16252065 static int camerachangeframe;
16262066
1627
- boolean SetCamera(Camera cam)
2067
+ public boolean SetCamera(Camera cam)
16282068 {
16292069 // may 2014 if (cam == cameras[0] || cam == cameras[1])
16302070 // return false;
....@@ -1681,7 +2121,7 @@
16812121 //System.err.println("Oeil on");
16822122 OEIL = true;
16832123 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
1684
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2124
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
16852125 //pingthread.StepToTarget(true);
16862126 }
16872127
....@@ -1752,33 +2192,6 @@
17522192 mainDL ^= true;
17532193 }
17542194
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
-
17822195 void ToggleFullScreen()
17832196 {
17842197 FULLSCREEN ^= true;
....@@ -1789,72 +2202,94 @@
17892202 Globals.CROWD ^= true;
17902203 }
17912204
1792
- void ToggleInertia()
1793
- {
1794
- INERTIA ^= true;
1795
- }
1796
-
17972205 void ToggleLocal()
17982206 {
17992207 LOCALTRANSFORM ^= true;
18002208 }
18012209
1802
- void ToggleFast()
2210
+ public void ToggleTexture()
2211
+ {
2212
+ textureon ^= true;
2213
+ }
2214
+
2215
+ public void ToggleLive()
2216
+ {
2217
+ Globals.setLIVE(Globals.isLIVE() ^ true);
2218
+
2219
+ System.err.println("LIVE = " + Globals.isLIVE());
2220
+
2221
+ if (!Globals.isLIVE()) // save sound
2222
+ Grafreed.savesound = true; // wav.save();
2223
+ // else
2224
+ repaint(); // start loop // may 2013
2225
+ }
2226
+
2227
+ public void ToggleSupport()
2228
+ {
2229
+ SUPPORT ^= true;
2230
+ }
2231
+
2232
+ public void ToggleAbort()
2233
+ {
2234
+ ABORTMODE ^= true;
2235
+ }
2236
+
2237
+ public void ToggleInertia()
2238
+ {
2239
+ INERTIA ^= true;
2240
+ }
2241
+
2242
+ public void ToggleFast()
18032243 {
18042244 FAST ^= true;
18052245 }
18062246
1807
- void ToggleSlowPose()
2247
+ public void ToggleSlowPose()
18082248 {
18092249 SLOWPOSE ^= true;
18102250 }
18112251
1812
- void ToggleFootContact()
1813
- {
1814
- FOOTCONTACT ^= true;
1815
- }
1816
-
1817
- void ToggleBoxMode()
2252
+ public void ToggleBoxMode()
18182253 {
18192254 BOXMODE ^= true;
18202255 }
18212256
1822
- void ToggleSmoothFocus()
2257
+ public void ToggleZoomBoxMode()
2258
+ {
2259
+ ZOOMBOXMODE ^= true;
2260
+ }
2261
+
2262
+ public void ToggleSmoothFocus()
18232263 {
18242264 SMOOTHFOCUS ^= true;
18252265 }
18262266
1827
- void ToggleImageFlip()
2267
+ public void ToggleImageFlip()
18282268 {
18292269 IMAGEFLIP ^= true;
18302270 }
18312271
1832
- void ToggleSpeakerMocap()
2272
+ public void ToggleSpeakerMocap()
18332273 {
18342274 SPEAKERMOCAP ^= true;
18352275 }
18362276
1837
- void ToggleSpeakerCamera()
2277
+ public void ToggleSpeakerCamera()
18382278 {
18392279 SPEAKERCAMERA ^= true;
18402280 }
18412281
1842
- void ToggleSpeakerFocus()
2282
+ public void ToggleSpeakerFocus()
18432283 {
18442284 SPEAKERFOCUS ^= true;
18452285 }
18462286
1847
- void ToggleDebug()
1848
- {
1849
- DEBUG ^= true;
1850
- }
1851
-
1852
- void ToggleFrustum()
2287
+ public void ToggleFrustum()
18532288 {
18542289 FRUSTUM ^= true;
18552290 }
18562291
1857
- void ToggleTrack()
2292
+ public void ToggleTrack()
18582293 {
18592294 TRACK ^= true;
18602295 if (TRACK)
....@@ -1873,25 +2308,35 @@
18732308 repaint();
18742309 }
18752310
1876
- void ToggleTrackOnce()
2311
+ public void ToggleTrackOnce()
18772312 {
18782313 TRACKONCE ^= true;
18792314 }
18802315
1881
- void ToggleShadowTrack()
2316
+ public void ToggleShadowTrack()
18822317 {
18832318 SHADOWTRACK ^= true;
18842319 repaint();
18852320 }
18862321
1887
- void ToggleOeil()
2322
+ public void ToggleOeil()
18882323 {
18892324 OEIL ^= true;
18902325 }
18912326
1892
- void ToggleOeilOnce()
2327
+ public void ToggleOeilOnce()
18932328 {
18942329 OEILONCE ^= true;
2330
+ }
2331
+
2332
+ void ToggleFootContact()
2333
+ {
2334
+ FOOTCONTACT ^= true;
2335
+ }
2336
+
2337
+ void ToggleDebug()
2338
+ {
2339
+ Globals.DEBUG ^= true;
18952340 }
18962341
18972342 void ToggleLookAt()
....@@ -1899,9 +2344,9 @@
18992344 LOOKAT ^= true;
19002345 }
19012346
1902
- void ToggleRandom()
2347
+ void ToggleSwitch()
19032348 {
1904
- RANDOM ^= true;
2349
+ SWITCH ^= true;
19052350 }
19062351
19072352 void ToggleHandles()
....@@ -1909,10 +2354,17 @@
19092354 HANDLES ^= true;
19102355 }
19112356
2357
+ Object3D paintFolder;
2358
+
19122359 void TogglePaint()
19132360 {
19142361 PAINTMODE ^= true;
19152362 paintcount = 0;
2363
+
2364
+ if (PAINTMODE)
2365
+ {
2366
+ paintFolder = GetFolder();
2367
+ }
19162368 }
19172369
19182370 void SwapCamera(int a, int b)
....@@ -2008,7 +2460,34 @@
20082460 {
20092461 return currentGL;
20102462 }
2011
-
2463
+
2464
+ static private BufferedImage CreateBim(TextureData texturedata)
2465
+ {
2466
+ Grafreed.Assert(texturedata != null);
2467
+
2468
+ int width = texturedata.getWidth();
2469
+ int height = texturedata.getHeight();
2470
+
2471
+ Buffer buffer = texturedata.getBuffer();
2472
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2473
+
2474
+ byte[] bytes = bytebuf.array();
2475
+
2476
+ return CreateBim(bytes, width, height);
2477
+ }
2478
+
2479
+ private void SetGLNormal(javax.media.opengl.GL gl, float nx, float ny, float nz)
2480
+ {
2481
+ gl.glNormal3f(nx, ny, nz);
2482
+
2483
+ if (ny > 0.9 || ny < -0.9)
2484
+ // Ground or ceiling
2485
+ gl.glVertexAttrib3f(4, 1, 0, 0);
2486
+ else
2487
+ // Walls
2488
+ gl.glVertexAttrib3f(4, 0, 1, 0);
2489
+ }
2490
+
20122491 /**/
20132492 class CacheTexture
20142493 {
....@@ -2017,28 +2496,31 @@
20172496
20182497 int resolution;
20192498
2020
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2499
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
20212500 {
2022
- texture = tex;
2501
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2502
+ texturedata = texdata;
20232503 resolution = res;
20242504 }
20252505 }
20262506 /**/
20272507
20282508 // 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>();
2509
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2510
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2511
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2512
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2513
+
20322514 int pigmentdepth = 0;
20332515 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
20342516 int bumpdepth = 0;
20352517 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
20362518 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
20372519 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2038
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2520
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
20392521 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
20402522
2041
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2523
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
20422524 {
20432525 TextureData texturedata = null;
20442526
....@@ -2048,7 +2530,7 @@
20482530 com.sun.opengl.util.texture.TextureIO.newTextureData(
20492531 getClass().getClassLoader().getResourceAsStream(name),
20502532 true,
2051
- com.sun.opengl.util.texture.TextureIO.PNG);
2533
+ GetFormat(name)); // com.sun.opengl.util.texture.TextureIO.PNG);
20522534 } catch (java.io.IOException e)
20532535 {
20542536 throw new javax.media.opengl.GLException(e);
....@@ -2057,13 +2539,34 @@
20572539 if (bump)
20582540 texturedata = ConvertBump(texturedata, false);
20592541
2060
- com.sun.opengl.util.texture.Texture texture =
2061
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2542
+// com.sun.opengl.util.texture.Texture texture =
2543
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
20622544
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);
2545
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2546
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
20652547
2066
- return texture;
2548
+ return texturedata;
2549
+ }
2550
+
2551
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2552
+ {
2553
+ TextureData texturedata = null;
2554
+
2555
+ try
2556
+ {
2557
+ texturedata =
2558
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2559
+ bim,
2560
+ true);
2561
+ } catch (Exception e)
2562
+ {
2563
+ throw new javax.media.opengl.GLException(e);
2564
+ }
2565
+
2566
+ if (bump)
2567
+ texturedata = ConvertBump(texturedata, false);
2568
+
2569
+ return texturedata;
20672570 }
20682571
20692572 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3136,6 +3639,8 @@
31363639
31373640 System.out.println("LOADING TEXTURE : " + name);
31383641
3642
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3643
+
31393644 //
31403645 if (false) // compressbit > 0)
31413646 {
....@@ -3840,6 +4345,7 @@
38404345
38414346 com.sun.opengl.util.texture.Texture CompressTexture2(String name)
38424347 {
4348
+ new Exception().printStackTrace();
38434349 System.exit(0);
38444350 com.sun.opengl.util.texture.Texture texture = null;
38454351
....@@ -7533,7 +8039,7 @@
75338039 String pigment = Object3D.GetPigment(tex);
75348040 String bump = Object3D.GetBump(tex);
75358041
7536
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8042
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
75378043 {
75388044 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
75398045 // System.out.println("; bump = " + bump);
....@@ -7548,11 +8054,69 @@
75488054 pigment = null;
75498055 }
75508056
7551
- ReleaseTexture(bump, true);
7552
- ReleaseTexture(pigment, false);
8057
+ ReleaseTexture(tex, true);
8058
+ ReleaseTexture(tex, false);
75538059 }
75548060
7555
- void ReleaseTexture(String tex, boolean bump)
8061
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
8062
+ {
8063
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8064
+ {
8065
+ return;
8066
+ }
8067
+
8068
+ if (tex == null)
8069
+ {
8070
+ ReleaseTexture(null, false);
8071
+ return;
8072
+ }
8073
+
8074
+ String pigment = Object3D.GetPigment(tex);
8075
+
8076
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8077
+ {
8078
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8079
+ // System.out.println("; bump = " + bump);
8080
+ }
8081
+
8082
+ if (pigment.equals(""))
8083
+ {
8084
+ pigment = null;
8085
+ }
8086
+
8087
+ ReleaseTexture(tex, false);
8088
+ }
8089
+
8090
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
8091
+ {
8092
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8093
+ {
8094
+ return;
8095
+ }
8096
+
8097
+ if (tex == null)
8098
+ {
8099
+ ReleaseTexture(null, true);
8100
+ return;
8101
+ }
8102
+
8103
+ String bump = Object3D.GetBump(tex);
8104
+
8105
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8106
+ {
8107
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8108
+ // System.out.println("; bump = " + bump);
8109
+ }
8110
+
8111
+ if (bump.equals(""))
8112
+ {
8113
+ bump = null;
8114
+ }
8115
+
8116
+ ReleaseTexture(tex, true);
8117
+ }
8118
+
8119
+ void ReleaseTexture(cTexture tex, boolean bump)
75568120 {
75578121 if (// DrawMode() != 0 || /*tex == null ||*/
75588122 ambientOcclusion ) // || !textureon)
....@@ -7563,7 +8127,7 @@
75638127 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
75648128
75658129 if (tex != null)
7566
- texture = textures.get(tex);
8130
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
75678131
75688132 // //assert( texture != null );
75698133 // if (texture == null)
....@@ -7655,7 +8219,55 @@
76558219 }
76568220 }
76578221
7658
- /*boolean*/ public void BindTextures(cTexture tex, int resolution) // INTERFACE
8222
+ /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
8223
+ {
8224
+// if (// DrawMode() != 0 || /*tex == null ||*/
8225
+// ambientOcclusion ) // || !textureon)
8226
+// {
8227
+// return; // false;
8228
+// }
8229
+//
8230
+// if (tex == null)
8231
+// {
8232
+// BindTexture(null,false,resolution);
8233
+// BindTexture(null,true,resolution);
8234
+// return;
8235
+// }
8236
+//
8237
+// String pigment = Object3D.GetPigment(tex);
8238
+// String bump = Object3D.GetBump(tex);
8239
+//
8240
+// usedtextures.add(pigment);
8241
+// usedtextures.add(bump);
8242
+//
8243
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8244
+// {
8245
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8246
+// // System.out.println("; bump = " + bump);
8247
+// }
8248
+//
8249
+// if (bump.equals(""))
8250
+// {
8251
+// bump = null;
8252
+// }
8253
+// if (pigment.equals(""))
8254
+// {
8255
+// pigment = null;
8256
+// }
8257
+//
8258
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8259
+// BindTexture(pigment, false, resolution);
8260
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8261
+// BindTexture(bump, true, resolution);
8262
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8263
+//
8264
+// return; // true;
8265
+
8266
+ BindPigmentTexture(tex, resolution);
8267
+ BindBumpTexture(tex, resolution);
8268
+ }
8269
+
8270
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
76598271 {
76608272 if (// DrawMode() != 0 || /*tex == null ||*/
76618273 ambientOcclusion ) // || !textureon)
....@@ -7666,17 +8278,47 @@
76668278 if (tex == null)
76678279 {
76688280 BindTexture(null,false,resolution);
7669
- BindTexture(null,true,resolution);
76708281 return;
76718282 }
76728283
76738284 String pigment = Object3D.GetPigment(tex);
8285
+
8286
+ usedtextures.add(tex);
8287
+
8288
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8289
+ {
8290
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8291
+ // System.out.println("; bump = " + bump);
8292
+ }
8293
+
8294
+ if (pigment.equals(""))
8295
+ {
8296
+ pigment = null;
8297
+ }
8298
+
8299
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8300
+ BindTexture(tex, false, resolution);
8301
+ }
8302
+
8303
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8304
+ {
8305
+ if (// DrawMode() != 0 || /*tex == null ||*/
8306
+ ambientOcclusion ) // || !textureon)
8307
+ {
8308
+ return; // false;
8309
+ }
8310
+
8311
+ if (tex == null)
8312
+ {
8313
+ BindTexture(null,true,resolution);
8314
+ return;
8315
+ }
8316
+
76748317 String bump = Object3D.GetBump(tex);
76758318
7676
- usedtextures.put(pigment, pigment);
7677
- usedtextures.put(bump, bump);
8319
+ usedtextures.add(tex);
76788320
7679
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8321
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
76808322 {
76818323 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
76828324 // System.out.println("; bump = " + bump);
....@@ -7686,43 +8328,94 @@
76868328 {
76878329 bump = null;
76888330 }
7689
- if (pigment.equals(""))
7690
- {
7691
- pigment = null;
7692
- }
76938331
7694
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
7695
- BindTexture(pigment, false, resolution);
76968332 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
7697
- BindTexture(bump, true, resolution);
8333
+ BindTexture(tex, true, resolution);
76988334 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
7699
-
7700
- return; // true;
77018335 }
77028336
7703
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution)
8337
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8338
+
8339
+ private boolean FileExists(String tex)
77048340 {
7705
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8341
+ if (missingTextures.contains(tex))
8342
+ {
8343
+ return false;
8344
+ }
8345
+
8346
+ boolean fileExists = new File(tex).exists();
8347
+
8348
+ if (!fileExists)
8349
+ {
8350
+ // If file exists, the "new File()" is not executed sgain
8351
+ missingTextures.add(tex);
8352
+ }
8353
+
8354
+ return fileExists;
8355
+ }
8356
+
8357
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
8358
+ {
8359
+ CacheTexture texturecache = null;
77068360
77078361 if (tex != null)
77088362 {
7709
- String texname = tex;
8363
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8364
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
77108365
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;
8366
+ if (texname.equals("") && texdata == null)
8367
+ {
8368
+ return null;
8369
+ }
8370
+
8371
+ String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
8372
+
8373
+// String[] split = tex.split("Textures");
8374
+// if (split.length > 1)
8375
+// texname = "/Users/nbriere/Textures" + split[split.length-1];
8376
+// else
8377
+// if (!texname.startsWith("/"))
8378
+// texname = "/Users/nbriere/Textures/" + texname;
8379
+ if (!FileExists(texname) && !texname.startsWith("@"))
8380
+ {
8381
+ texname = fallbackTextureName;
8382
+ }
77178383
77188384 if (CACHETEXTURE)
7719
- texture = textures.get(texname); // TEXTURE CACHE
7720
-
7721
- TextureData texturedata = null;
7722
-
7723
- if (texture == null || texture.resolution < resolution)
77248385 {
7725
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8386
+ if (texdata == null)
8387
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8388
+ else
8389
+ texturecache = bimtextures.get(texdata);
8390
+ }
8391
+
8392
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8393
+ {
8394
+ TextureData texturedata = null;
8395
+
8396
+ if (texdata != null && textureon)
8397
+ {
8398
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8399
+
8400
+ try
8401
+ {
8402
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8403
+ }
8404
+ catch (Exception e)
8405
+ {
8406
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8407
+ }
8408
+
8409
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8410
+ bimtextures.put(texdata, texturecache);
8411
+
8412
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8413
+
8414
+ //Object bim2 = CreateBim(texturecache.texturedata);
8415
+ //bim2 = bim;
8416
+ }
8417
+ else
8418
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
77268419 {
77278420 assert(!bump);
77288421 // if (bump)
....@@ -7733,19 +8426,23 @@
77338426 // }
77348427 // else
77358428 // {
7736
- texture = textures.get(tex);
7737
- if (texture == null)
8429
+ // texturecache = textures.get(texname); // suspicious
8430
+ if (texturecache == null)
77388431 {
7739
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8432
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
77408433 }
8434
+ else
8435
+ new Exception().printStackTrace();
77418436 // }
77428437 } else
7743
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8438
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
77448439 {
77458440 assert(bump);
7746
- texture = textures.get(tex);
7747
- if (texture == null)
7748
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8441
+ // texturecache = textures.get(texname); // suspicious
8442
+ if (texturecache == null)
8443
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8444
+ else
8445
+ new Exception().printStackTrace();
77498446 } else
77508447 {
77518448 //if (tex.equals("IMMORTAL"))
....@@ -7753,11 +8450,22 @@
77538450 // texture = GetResourceTexture("default.png");
77548451 //} else
77558452 //{
7756
- if (tex.equals("WHITE_NOISE"))
8453
+ if (texname.endsWith("WHITE_NOISE"))
77578454 {
7758
- texture = textures.get(tex);
7759
- if (texture == null)
7760
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8455
+ // texturecache = textures.get(texname); // suspicious
8456
+ if (texturecache == null)
8457
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8458
+ else
8459
+ new Exception().printStackTrace();
8460
+ } else
8461
+ {
8462
+ if (texname.startsWith("@"))
8463
+ {
8464
+ // texturecache = textures.get(texname); // suspicious
8465
+ if (texturecache == null)
8466
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8467
+ else
8468
+ new Exception().printStackTrace();
77618469 } else
77628470 {
77638471 if (textureon)
....@@ -7782,7 +8490,7 @@
77828490 }
77838491
77848492 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
7785
- if (!new File(cachename).exists())
8493
+ if (!FileExists(cachename))
77868494 cachename = texname;
77878495 else
77888496 processbump = false; // don't process bump map again
....@@ -7804,7 +8512,7 @@
78048512 }
78058513
78068514 cachename = texname.substring(0, texname.length()-4)+ext+".png";
7807
- if (!new File(cachename).exists())
8515
+ if (!FileExists(cachename))
78088516 cachename = texname;
78098517 else
78108518 processbump = false; // don't process bump map again
....@@ -7813,20 +8521,23 @@
78138521 texturedata = GetFileTexture(cachename, processbump, resolution);
78148522
78158523
7816
- if (texturedata != null)
7817
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8524
+ if (texturedata == null)
8525
+ throw new Exception();
8526
+
8527
+ texturecache = new CacheTexture(texturedata,resolution);
78188528 //texture = GetTexture(tex, bump);
78198529 }
8530
+ }
78208531 }
78218532 //}
78228533 }
78238534
7824
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8535
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
78258536 {
78268537 //return false;
78278538
78288539 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
7829
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8540
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
78308541 {
78318542 // String ext = "_highres";
78328543 // if (REDUCETEXTURE)
....@@ -7843,52 +8554,17 @@
78438554 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
78448555 if (!cachefile.exists())
78458556 {
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))
8557
+ //if (texturedata.getWidth() == texturedata.getHeight())
78558558 {
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);
8559
+ BufferedImage rendImage = CreateBim(texturedata);
8560
+
78868561 ImageWriter writer = null;
78878562 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
78888563 if (iter.hasNext()) {
78898564 writer = (ImageWriter)iter.next();
78908565 }
7891
- float compressionQuality = 0.9f;
8566
+
8567
+ float compressionQuality = 0.85f;
78928568 try
78938569 {
78948570 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -7905,18 +8581,20 @@
79058581 }
79068582 }
79078583 }
7908
-
8584
+
8585
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8586
+
79098587 //System.out.println("Texture = " + tex);
7910
- if (textures.containsKey(texname))
8588
+ if (textures.containsKey(tex))
79118589 {
7912
- CacheTexture thetex = textures.get(texname);
8590
+ CacheTexture thetex = textures.get(tex);
79138591 thetex.texture.disable();
79148592 thetex.texture.dispose();
7915
- textures.remove(texname);
8593
+ textures.remove(tex);
79168594 }
79178595
7918
- texture.texturedata = texturedata;
7919
- textures.put(texname, texture);
8596
+ //texture.texturedata = texturedata;
8597
+ textures.put(tex, texturecache);
79208598
79218599 // newtex = true;
79228600 }
....@@ -7932,10 +8610,44 @@
79328610 }
79338611 }
79348612
7935
- return texture;
8613
+ return texturecache;
79368614 }
79378615
7938
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution)
8616
+ static void EmbedTextures(cTexture tex)
8617
+ {
8618
+ if (tex.pigmentdata == null)
8619
+ {
8620
+ //String texname = Object3D.GetPigment(tex);
8621
+
8622
+ CacheTexture texturecache = texturepigment.get(tex);
8623
+
8624
+ if (texturecache != null)
8625
+ {
8626
+ tex.pw = texturecache.texturedata.getWidth();
8627
+ tex.ph = texturecache.texturedata.getHeight();
8628
+ tex.pigmentdata = //CompressJPEG(CreateBim
8629
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8630
+ ;
8631
+ //, tex.pw, tex.ph), 0.5f);
8632
+ }
8633
+ }
8634
+
8635
+ if (tex.bumpdata == null)
8636
+ {
8637
+ //String texname = Object3D.GetBump(tex);
8638
+
8639
+ CacheTexture texturecache = texturebump.get(tex);
8640
+
8641
+ if (texturecache != null)
8642
+ {
8643
+ tex.bw = texturecache.texturedata.getWidth();
8644
+ tex.bh = texturecache.texturedata.getHeight();
8645
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8646
+ }
8647
+ }
8648
+ }
8649
+
8650
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
79398651 {
79408652 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
79418653
....@@ -7953,21 +8665,21 @@
79538665 return texture!=null?texture.texture:null;
79548666 }
79558667
7956
- com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution)
8668
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
79578669 {
79588670 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
79598671
79608672 return texture!=null?texture.texturedata:null;
79618673 }
79628674
7963
- boolean BindTexture(String tex, boolean bump, int resolution)
8675
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
79648676 {
79658677 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
79668678 {
79678679 return false;
79688680 }
79698681
7970
- boolean newtex = false;
8682
+ //boolean newtex = false;
79718683
79728684 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
79738685
....@@ -7999,9 +8711,75 @@
79998711 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
80008712 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
80018713
8002
- return newtex;
8714
+ return true; // Warning: not used.
80038715 }
80048716
8717
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8718
+ {
8719
+ try
8720
+ {
8721
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8722
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8723
+ ImageWriter writer = writers.next();
8724
+
8725
+ ImageWriteParam param = writer.getDefaultWriteParam();
8726
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8727
+ param.setCompressionQuality(quality);
8728
+
8729
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8730
+ writer.setOutput(ios);
8731
+ writer.write(null, new IIOImage(image, null, null), param);
8732
+
8733
+ byte[] data = baos.toByteArray();
8734
+ writer.dispose();
8735
+ return data;
8736
+ }
8737
+ catch (Exception e)
8738
+ {
8739
+ e.printStackTrace();
8740
+ return null;
8741
+ }
8742
+ }
8743
+
8744
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8745
+ {
8746
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8747
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8748
+ ImageReader reader = writers.next();
8749
+
8750
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8751
+
8752
+ ImageReadParam param = reader.getDefaultReadParam();
8753
+ param.setDestination(bim);
8754
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8755
+
8756
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8757
+ reader.setInput(ios);
8758
+ BufferedImage bim2 = reader.read(0, param);
8759
+ reader.dispose();
8760
+
8761
+// WritableRaster raster = bim2.getRaster();
8762
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8763
+// byte[] bytes = data.getData();
8764
+//
8765
+// int[] pixels = new int[bytes.length/3];
8766
+// for (int i=pixels.length; --i>=0;)
8767
+// {
8768
+// int i3 = i*3;
8769
+// pixels[i] = 0xFF;
8770
+// pixels[i] <<= 8;
8771
+// pixels[i] |= bytes[i3+2] & 0xFF;
8772
+// pixels[i] <<= 8;
8773
+// pixels[i] |= bytes[i3+1] & 0xFF;
8774
+// pixels[i] <<= 8;
8775
+// pixels[i] |= bytes[i3] & 0xFF;
8776
+// }
8777
+//
8778
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8779
+
8780
+ return bim;
8781
+ }
8782
+
80058783 ShadowBuffer shadowPBuf;
80068784 AntialiasBuffer antialiasPBuf;
80078785 int MAXSTACK;
....@@ -8018,10 +8796,12 @@
80188796
80198797 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
80208798 MAXSTACK = temp[0];
8021
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8799
+ if (Globals.DEBUG)
8800
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
80228801 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
80238802 MAXSTACK = temp[0];
8024
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8803
+ if (Globals.DEBUG)
8804
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
80258805
80268806 // Use debug pipeline
80278807 //drawable.setGL(new DebugGL(gl)); //
....@@ -8029,7 +8809,8 @@
80298809 gl = drawable.getGL(); //
80308810
80318811 GL gl3 = getGL();
8032
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8812
+ if (Globals.DEBUG)
8813
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
80338814
80348815
80358816 //float pos[] = { 100, 100, 100, 0 };
....@@ -8194,7 +8975,7 @@
81948975
81958976 if (cubemap == null)
81968977 {
8197
- LoadEnvy(5);
8978
+ //LoadEnvy(1);
81988979 }
81998980
82008981 //cubemap.enable();
....@@ -8470,6 +9251,8 @@
84709251
84719252 void LoadEnvy(int which)
84729253 {
9254
+ assert(false);
9255
+
84739256 String name;
84749257 String ext;
84759258
....@@ -8481,37 +9264,58 @@
84819264 cubemap = null;
84829265 return;
84839266 case 1:
8484
- name = "cubemaps/box_";
8485
- ext = "png";
9267
+ name = "cubemaps/rgb/";
9268
+ ext = "jpg";
84869269 reverseUP = false;
84879270 break;
84889271 case 2:
8489
- name = "cubemaps/uffizi_";
8490
- ext = "png";
8491
- break; // reverseUP = true; break;
9272
+ name = "cubemaps/uffizi/";
9273
+ ext = "jpg";
9274
+ reverseUP = false;
9275
+ break;
84929276 case 3:
8493
- name = "cubemaps/CloudyHills_";
8494
- ext = "tga";
9277
+ name = "cubemaps/CloudyHills/";
9278
+ ext = "jpg";
84959279 reverseUP = false;
84969280 break;
84979281 case 4:
8498
- name = "cubemaps/cornell_";
9282
+ name = "cubemaps/cornell/";
84999283 ext = "png";
85009284 reverseUP = false;
85019285 break;
9286
+ case 5:
9287
+ name = "cubemaps/skycube/";
9288
+ ext = "jpg";
9289
+ reverseUP = false;
9290
+ break;
9291
+ case 6:
9292
+ name = "cubemaps/SaintLazarusChurch3/";
9293
+ ext = "jpg";
9294
+ reverseUP = false;
9295
+ break;
9296
+ case 7:
9297
+ name = "cubemaps/Sodermalmsallen/";
9298
+ ext = "jpg";
9299
+ reverseUP = false;
9300
+ break;
9301
+ case 8:
9302
+ name = "cubemaps/Sodermalmsallen2/";
9303
+ ext = "jpg";
9304
+ reverseUP = false;
9305
+ break;
9306
+ case 9:
9307
+ name = "cubemaps/UnionSquare/";
9308
+ ext = "jpg";
9309
+ reverseUP = false;
9310
+ break;
85029311 default:
8503
- name = "cubemaps/rgb_";
8504
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9312
+ name = "cubemaps/box/";
9313
+ ext = "png"; /*mipmap = true;*/
9314
+ reverseUP = false;
85059315 break;
85069316 }
8507
-
8508
- try
8509
- {
8510
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
8511
- } catch (IOException e)
8512
- {
8513
- throw new RuntimeException(e);
8514
- }
9317
+
9318
+ LoadSkybox(name, ext, mipmap);
85159319 }
85169320
85179321 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -8543,8 +9347,12 @@
85439347 static double[] model = new double[16];
85449348 double[] camera2light = new double[16];
85459349 double[] light2camera = new double[16];
8546
- int newenvy = -1;
8547
- boolean envyoff = true; // false;
9350
+
9351
+ //int newenvy = -1;
9352
+ //boolean envyoff = false;
9353
+
9354
+ String loadedskyboxname;
9355
+
85489356 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
85499357 //float[] light0 = { 0,0,0 };
85509358 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -8837,11 +9645,35 @@
88379645 jy8[3] = 0.5f;
88389646 }
88399647
8840
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9648
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
88419649 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
88429650 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
88439651 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
88449652
9653
+ void ResetOptions()
9654
+ {
9655
+ options1[0] = 100;
9656
+ options1[1] = 0.025f;
9657
+ options1[2] = 0.01f;
9658
+ options1[3] = 0;
9659
+ options1[4] = 0;
9660
+
9661
+ options2[0] = 0;
9662
+ options2[1] = 0.75f;
9663
+ options2[2] = 0;
9664
+ options2[3] = 0;
9665
+
9666
+ options3[0] = 1;
9667
+ options3[1] = 1;
9668
+ options3[2] = 1;
9669
+ options3[3] = 0;
9670
+
9671
+ options4[0] = 1;
9672
+ options4[1] = 0;
9673
+ options4[2] = 1;
9674
+ options4[3] = 0;
9675
+ }
9676
+
88459677 static int imagecount = 0; // movie generation
88469678
88479679 static int jitter = 0;
....@@ -8937,8 +9769,8 @@
89379769 assert (parentcam != renderCamera);
89389770
89399771 if (renderCamera != lightCamera)
8940
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8941
- LA.matConcat(matrix, parentcam.toParent, matrix);
9772
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9773
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
89429774
89439775 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
89449776
....@@ -8953,8 +9785,8 @@
89539785 LA.matCopy(renderCamera.fromScreen, matrix);
89549786
89559787 if (renderCamera != lightCamera)
8956
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8957
- LA.matConcat(parentcam.fromParent, matrix, matrix);
9788
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9789
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
89589790
89599791 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
89609792
....@@ -9000,10 +9832,12 @@
90009832 rati = 1 / rati;
90019833 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
90029834 }
9003
- assert (newenvy == -1);
9835
+
9836
+ //assert (newenvy == -1);
9837
+
90049838 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
90059839 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9006
- DrawSkyBox(gl);
9840
+ DrawSkyBox(gl, (float)rati);
90079841 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
90089842 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
90099843 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -9026,7 +9860,7 @@
90269860 //gl.glFlush();
90279861 gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE);
90289862
9029
- if (ANIMATION && ABORTED)
9863
+ if (Globals.ANIMATION && ABORTED)
90309864 {
90319865 System.err.println(" ABORTED FRAME");
90329866 break;
....@@ -9056,7 +9890,7 @@
90569890 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
90579891
90589892 // save image
9059
- if (ANIMATION && !ABORTED)
9893
+ if (Globals.ANIMATION && !ABORTED)
90609894 {
90619895 VPwidth = viewport[2];
90629896 VPheight = viewport[3];
....@@ -9167,11 +10001,11 @@
916710001
916810002 // imagecount++;
916910003
9170
- String fullname = filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
10004
+ String fullname = Globals.filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
917110005
917210006 if (!BOXMODE)
917310007 {
9174
- System.out.println("image: " + fullname + " (wav cursor=" + (GrafreeD.wav.cursor / 735 / 4) + ")");
10008
+ System.out.println("image: " + fullname + " (wav cursor=" + (Grafreed.wav.cursor / 735 / 4) + ")");
917510009 }
917610010
917710011 if (!BOXMODE)
....@@ -9209,7 +10043,7 @@
920910043 ABORTED = false;
921010044 }
921110045 else
9212
- GrafreeD.wav.cursor += 735 * ACSIZE;
10046
+ Grafreed.wav.cursor += 735 * ACSIZE;
921310047
921410048 if (false)
921510049 {
....@@ -9869,14 +10703,23 @@
986910703 static boolean init = false;
987010704
987110705 double[][] matrix = LA.newMatrix();
10706
+
10707
+ // This is to refresh the UI of the material panel.
10708
+ ObjEditor patchMaterial;
987210709
987310710 public void display(GLAutoDrawable drawable)
987410711 {
9875
- if (GrafreeD.savesound && GrafreeD.hassound)
10712
+ if (patchMaterial.patchMaterial)
987610713 {
9877
- GrafreeD.wav.save();
9878
- GrafreeD.savesound = false;
9879
- GrafreeD.hassound = false;
10714
+ patchMaterial.patchMaterial = false;
10715
+ patchMaterial.objectPanel.setSelectedIndex(1);
10716
+ }
10717
+
10718
+ if (Grafreed.savesound && Grafreed.hassound)
10719
+ {
10720
+ Grafreed.wav.save();
10721
+ Grafreed.savesound = false;
10722
+ Grafreed.hassound = false;
988010723 }
988110724 // if (DEBUG_SELECTION)
988210725 // {
....@@ -9952,6 +10795,7 @@
995210795 ANTIALIAS = 0;
995310796 //System.out.println("RESTART");
995410797 AAtimer.restart();
10798
+ Globals.TIMERRUNNING = true;
995510799 }
995610800 }
995710801 }
....@@ -10006,7 +10850,7 @@
1000610850 Object3D theobject = object;
1000710851 Object3D theparent = object.parent;
1000810852 object.parent = null;
10009
- object = (Object3D)GrafreeD.clone(object);
10853
+ object = (Object3D)Grafreed.clone(object);
1001010854 object.Stripify();
1001110855 if (theobject.selection == null || theobject.selection.Size() == 0)
1001210856 theobject.PreprocessOcclusion(this);
....@@ -10019,13 +10863,14 @@
1001910863 ambientOcclusion = false;
1002010864 }
1002110865
10022
- if (Globals.lighttouched && DrawMode() == DEFAULT && !lightMode) // && !FROZEN)
10866
+ if (//Globals.lighttouched &&
10867
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1002310868 {
1002410869 //if (RENDERSHADOW) // ?
1002510870 if (!IsFrozen())
1002610871 {
1002710872 // dec 2012
10028
- if (!ambientOcclusion && !(!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0))
10873
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
1002910874 {
1003010875 Globals.framecount++;
1003110876 shadowbuffer.display();
....@@ -10038,7 +10883,7 @@
1003810883
1003910884 if (wait)
1004010885 {
10041
- Sleep(500);
10886
+ Sleep(200); // blocks everything
1004210887
1004310888 wait = false;
1004410889 }
....@@ -10152,8 +10997,8 @@
1015210997
1015310998 // if (parentcam != renderCamera) // not a light
1015410999 if (cam != lightCamera)
10155
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10156
- LA.matConcat(matrix, parentcam.toParent, matrix);
11000
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11001
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1015711002
1015811003 for (int j = 0; j < 4; j++)
1015911004 {
....@@ -10167,8 +11012,8 @@
1016711012
1016811013 // if (parentcam != renderCamera) // not a light
1016911014 if (cam != lightCamera)
10170
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10171
- LA.matConcat(parentcam.fromParent, matrix, matrix);
11015
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11016
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1017211017
1017311018 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1017411019
....@@ -10254,13 +11099,43 @@
1025411099 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1025511100 }
1025611101
10257
- if (newenvy > -1)
11102
+// if (newenvy > -1)
11103
+// {
11104
+// LoadEnvy(newenvy);
11105
+// }
11106
+//
11107
+// newenvy = -1;
11108
+
11109
+ if (transformMode) // object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
1025811110 {
10259
- LoadEnvy(newenvy);
11111
+ if (cubemaprgb == null)
11112
+ {
11113
+ cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb2" + "/", "jpg", false);
11114
+ }
11115
+
11116
+ cubemap = cubemaprgb;
1026011117 }
10261
-
10262
- newenvy = -1;
10263
-
11118
+ else
11119
+ {
11120
+ if (object.skyboxname != null)
11121
+ {
11122
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11123
+ {
11124
+ if (cubemap != null && cubemap != cubemaprgb)
11125
+ cubemap.dispose();
11126
+ cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11127
+ loadedskyboxname = object.skyboxname;
11128
+ }
11129
+ }
11130
+ else
11131
+ {
11132
+ cubemapcustom = null;
11133
+ loadedskyboxname = null;
11134
+ }
11135
+
11136
+ cubemap = cubemapcustom;
11137
+ }
11138
+
1026411139 ratio = ((double) getWidth()) / getHeight();
1026511140 //System.out.println("ratio = " + ratio);
1026611141
....@@ -10276,7 +11151,7 @@
1027611151
1027711152 if (!IsFrozen() && !ambientOcclusion)
1027811153 {
10279
- DrawSkyBox(gl);
11154
+ DrawSkyBox(gl, (float)ratio);
1028011155 }
1028111156
1028211157 //if (selection_view == -1)
....@@ -10427,7 +11302,16 @@
1042711302 // Bump noise
1042811303 gl.glActiveTexture(GL.GL_TEXTURE6);
1042911304 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
10430
- BindTexture(NOISE_TEXTURE, false, 2);
11305
+
11306
+ try
11307
+ {
11308
+ BindTexture(NOISE_TEXTURE, false, 2);
11309
+ }
11310
+ catch (Exception e)
11311
+ {
11312
+ System.err.println("FAILED: " + NOISE_TEXTURE);
11313
+ }
11314
+
1043111315
1043211316 gl.glActiveTexture(GL.GL_TEXTURE0);
1043311317 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -10450,9 +11334,9 @@
1045011334
1045111335 gl.glMatrixMode(GL.GL_MODELVIEW);
1045211336
10453
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10454
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10455
-//gl.glEnable(gl.GL_MULTISAMPLE);
11337
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11338
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11339
+gl.glEnable(gl.GL_MULTISAMPLE);
1045611340 } else
1045711341 {
1045811342 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -10463,7 +11347,7 @@
1046311347 //System.out.println("BLENDING ON");
1046411348 gl.glEnable(GL.GL_BLEND);
1046511349 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
10466
-
11350
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1046711351 gl.glMatrixMode(gl.GL_PROJECTION);
1046811352 gl.glLoadIdentity();
1046911353
....@@ -10552,8 +11436,8 @@
1055211436 System.err.println("parentcam != renderCamera");
1055311437
1055411438 // if (cam != lightCamera)
10555
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10556
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11439
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11440
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1055711441 }
1055811442
1055911443 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -10574,8 +11458,8 @@
1057411458 if (true) // TODO
1057511459 {
1057611460 if (cam != lightCamera)
10577
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10578
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11461
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11462
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
1057911463 }
1058011464
1058111465 LA.xformPos(light0, cam.toScreen, light0);
....@@ -10712,7 +11596,7 @@
1071211596 }
1071311597 }
1071411598
10715
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11599
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1071611600 {
1071711601 //gl.glDepthFunc(GL.GL_LEQUAL);
1071811602 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -10720,24 +11604,21 @@
1072011604
1072111605 boolean texon = textureon;
1072211606
10723
- if (RENDERPROGRAM > 0)
10724
- {
10725
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
10726
- textureon = false;
10727
- }
11607
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11608
+ textureon = false;
11609
+
1072811610 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1072911611 //System.out.println("ALLO");
1073011612 gl.glColorMask(false, false, false, false);
1073111613 DrawObject(gl);
10732
- if (RENDERPROGRAM > 0)
10733
- {
10734
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
10735
- textureon = texon;
10736
- }
11614
+
11615
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11616
+ textureon = texon;
11617
+
1073711618 gl.glColorMask(true, true, true, true);
1073811619
1073911620 gl.glDepthFunc(GL.GL_EQUAL);
10740
- //gl.glDepthMask(false);
11621
+ gl.glDepthMask(false);
1074111622 }
1074211623
1074311624 if (false) // DrawMode() == SHADOW)
....@@ -10891,8 +11772,14 @@
1089111772 {
1089211773 renderpass++;
1089311774 // System.out.println("Draw object... ");
11775
+ STEP = 1;
1089411776 if (FAST) // in case there is no script
10895
- STEP = 16;
11777
+ STEP = 8;
11778
+
11779
+ if (CURRENTANTIALIAS == 0 || ACSIZE == 1)
11780
+ {
11781
+ STEP *= 4;
11782
+ }
1089611783
1089711784 //object.FullInvariants();
1089811785
....@@ -10906,23 +11793,44 @@
1090611793 e.printStackTrace();
1090711794 }
1090811795
10909
- if (GrafreeD.RENDERME > 0)
10910
- GrafreeD.RENDERME--; // mechante magouille
11796
+ if (Grafreed.RENDERME > 0)
11797
+ Grafreed.RENDERME--; // mechante magouille
1091111798
1091211799 Globals.ONESTEP = false;
1091311800 }
1091411801
1091511802 static boolean zoomonce = false;
1091611803
11804
+ static void CreateSelectedPoint()
11805
+ {
11806
+ if (selectedpoint == null)
11807
+ {
11808
+ debugpointG = new Sphere();
11809
+ debugpointP = new Sphere();
11810
+ debugpointC = new Sphere();
11811
+ debugpointR = new Sphere();
11812
+
11813
+ selectedpoint = new Superellipsoid();
11814
+
11815
+ for (int i=0; i<8; i++)
11816
+ {
11817
+ debugpoints[i] = new Sphere();
11818
+ }
11819
+ }
11820
+ }
11821
+
1091711822 void DrawObject(GL gl, boolean draw)
1091811823 {
11824
+ // To clear camera values
11825
+ ResetOptions();
11826
+
1091911827 //System.out.println("DRAW OBJECT " + mouseDown);
1092011828 // DrawMode() = SELECTION;
1092111829 //GL gl = getGL();
1092211830 if ((TRACK || SHADOWTRACK) || zoomonce)
1092311831 {
1092411832 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
10925
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11833
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1092611834 pingthread.StepToTarget(true); // true);
1092711835 // zoomonce = false;
1092811836 }
....@@ -10977,7 +11885,14 @@
1097711885
1097811886 usedtextures.clear();
1097911887
10980
- BindTextures(DEFAULT_TEXTURES, 2);
11888
+ try
11889
+ {
11890
+ BindTextures(DEFAULT_TEXTURES, 2);
11891
+ }
11892
+ catch (Exception e)
11893
+ {
11894
+ System.err.println("FAILED: " + DEFAULT_TEXTURES);
11895
+ }
1098111896 }
1098211897 //System.out.println("--> " + stackdepth);
1098311898 // GrafreeD.traceon();
....@@ -10987,8 +11902,9 @@
1098711902
1098811903 if (DrawMode() == DEFAULT)
1098911904 {
10990
- if (DEBUG)
11905
+ if (Globals.DEBUG)
1099111906 {
11907
+ CreateSelectedPoint();
1099211908 float radius = 0.05f;
1099311909 if (selectedpoint.radius != radius)
1099411910 {
....@@ -11042,20 +11958,32 @@
1104211958 ReleaseTextures(DEFAULT_TEXTURES);
1104311959
1104411960 if (CLEANCACHE)
11045
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11961
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1104611962 {
11047
- String tex = e.nextElement();
11963
+ cTexture tex = e.nextElement();
1104811964
1104911965 // System.out.println("Texture --------- " + tex);
1105011966
11051
- if (tex.equals("WHITE_NOISE"))
11967
+ if (tex.equals("WHITE_NOISE:"))
1105211968 continue;
1105311969
11054
- if (!usedtextures.containsKey(tex))
11970
+ if (!usedtextures.contains(tex))
1105511971 {
11972
+ CacheTexture gettex = texturepigment.get(tex);
1105611973 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11057
- textures.get(tex).texture.dispose();
11058
- textures.remove(tex);
11974
+ if (gettex != null)
11975
+ {
11976
+ gettex.texture.dispose();
11977
+ texturepigment.remove(tex);
11978
+ }
11979
+
11980
+ gettex = texturebump.get(tex);
11981
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11982
+ if (gettex != null)
11983
+ {
11984
+ gettex.texture.dispose();
11985
+ texturebump.remove(tex);
11986
+ }
1105911987 }
1106011988 }
1106111989 }
....@@ -11068,7 +11996,14 @@
1106811996 if (checker != null && DrawMode() == DEFAULT)
1106911997 {
1107011998 //BindTexture(IMMORTAL_TEXTURE);
11071
- BindTextures(checker.GetTextures(), checker.texres);
11999
+ try
12000
+ {
12001
+ BindTextures(checker.GetTextures(), checker.texres);
12002
+ }
12003
+ catch (Exception e)
12004
+ {
12005
+ System.err.println("FAILED: " + checker.GetTextures());
12006
+ }
1107212007 // NEAREST
1107312008 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
1107412009 DrawChecker(gl);
....@@ -11150,7 +12085,7 @@
1115012085 return;
1115112086 }
1115212087
11153
- String string = obj.GetToolTip();
12088
+ String string = obj.toString(); //.GetToolTip();
1115412089
1115512090 GL gl = GetGL();
1115612091
....@@ -11467,8 +12402,8 @@
1146712402 //obj.TransformToWorld(light, light);
1146812403 for (int i = tp.size(); --i >= 0;)
1146912404 {
11470
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
11471
- LA.xformPos(light, tp.get(i).toParent, light);
12405
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12406
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1147212407 }
1147312408
1147412409
....@@ -11485,8 +12420,8 @@
1148512420 parentcam = cameras[0];
1148612421 }
1148712422
11488
- for (int count = parentcam.GetTransformCount(); --count>=0;)
11489
- LA.xformPos(light, parentcam.toParent, light); // may 2013
12423
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
12424
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1149012425
1149112426 LA.xformPos(light, renderCamera.toScreen, light);
1149212427
....@@ -11576,8 +12511,76 @@
1157612511
1157712512 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1157812513
11579
- String program =
12514
+ String programmin =
12515
+ // Min shader
1158012516 "!!ARBfp1.0\n" +
12517
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12518
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12519
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12520
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12521
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12522
+ "PARAM light2cam0 = program.env[10];" +
12523
+ "PARAM light2cam1 = program.env[11];" +
12524
+ "PARAM light2cam2 = program.env[12];" +
12525
+ "TEMP temp;" +
12526
+ "TEMP light;" +
12527
+ "TEMP ndotl;" +
12528
+ "TEMP normal;" +
12529
+ "TEMP depth;" +
12530
+ "TEMP eye;" +
12531
+ "TEMP pos;" +
12532
+
12533
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12534
+ Normalize("normal") +
12535
+ "MOV light, state.light[0].position;" +
12536
+ "DP3 ndotl.x, light, normal;" +
12537
+
12538
+ // shadow
12539
+ "MOV pos, fragment.texcoord[1];" +
12540
+ "MOV temp, pos;" +
12541
+ ShadowTextureFetch("depth", "temp", "1") +
12542
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12543
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12544
+
12545
+ // No shadow when out of frustum
12546
+ //"SGE temp.y, depth.z, zero123.y;" +
12547
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12548
+
12549
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12550
+
12551
+ // Backlit
12552
+ "MOV pos.w, zero123.y;" +
12553
+ "DP4 eye.x, pos, light2cam0;" +
12554
+ "DP4 eye.y, pos, light2cam1;" +
12555
+ "DP4 eye.z, pos, light2cam2;" +
12556
+ Normalize("eye") +
12557
+
12558
+ "DP3 ndotl.y, -eye, normal;" +
12559
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12560
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12561
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12562
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12563
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12564
+
12565
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12566
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12567
+
12568
+ // Pigment
12569
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12570
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12571
+ "MUL temp, temp, ndotl.x;" +
12572
+
12573
+ "MUL temp, temp, zero123.z;" +
12574
+
12575
+ //"MUL temp, temp, ndotl.y;" +
12576
+
12577
+ "MOV temp.w, zero123.y;" + // reset alpha
12578
+ "MOV result.color, temp;" +
12579
+ "END";
12580
+
12581
+ String programmax =
12582
+ "!!ARBfp1.0\n" +
12583
+
1158112584 //"OPTION ARB_fragment_program_shadow;" +
1158212585 "PARAM light2cam0 = program.env[10];" +
1158312586 "PARAM light2cam1 = program.env[11];" +
....@@ -11603,7 +12606,7 @@
1160312606 "PARAM params4 = program.env[4];" + // anisoV, cameralight, selfshadow, shadow
1160412607 "PARAM params5 = program.env[5];" + // texture, opacity, fakedepth, shadowbias
1160512608 "PARAM params6 = program.env[6];" + // bump, noise, borderfade, fog punchthrough
11606
- "PARAM params7 = program.env[7];" + // noise power, opacity power
12609
+ "PARAM params7 = program.env[7];" + // noise power, opacity power, parallax
1160712610 "PARAM options0 = program.env[63];" + // fog density, intensity, elevation
1160812611 "PARAM options1 = program.env[62];" + // fog rgb color
1160912612 "PARAM options2 = program.env[61];" + // image intensity, subsurface, lightsheen
....@@ -11692,8 +12695,7 @@
1169212695 "TEMP shininess;" +
1169312696 "\n" +
1169412697 "MOV texSamp, one;" +
11695
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
11696
-
12698
+
1169712699 "MOV mapgrid.x, one2048th.x;" +
1169812700 "MOV temp, fragment.texcoord[1];" +
1169912701 /*
....@@ -11714,20 +12716,20 @@
1171412716 "MUL temp, floor, mapgrid.x;" +
1171512717 //"TEX depth0, temp, texture[1], 2D;" +
1171612718 (((mode & FP_SOFTSHADOW) == 0) ? "" :
11717
- TextureFetch("depth0", "temp", "1") +
12719
+ ShadowTextureFetch("depth0", "temp", "1") +
1171812720 "") +
1171912721 "ADD temp.x, temp.x, mapgrid.x;" +
1172012722 //"TEX depth1, temp, texture[1], 2D;" +
1172112723 (((mode & FP_SOFTSHADOW) == 0) ? "" :
11722
- TextureFetch("depth1", "temp", "1") +
12724
+ ShadowTextureFetch("depth1", "temp", "1") +
1172312725 "") +
1172412726 "ADD temp.y, temp.y, mapgrid.x;" +
1172512727 //"TEX depth2, temp, texture[1], 2D;" +
11726
- TextureFetch("depth2", "temp", "1") +
12728
+ ShadowTextureFetch("depth2", "temp", "1") +
1172712729 "SUB temp.x, temp.x, mapgrid.x;" +
1172812730 //"TEX depth3, temp, texture[1], 2D;" +
1172912731 (((mode & FP_SOFTSHADOW) == 0) ? "" :
11730
- TextureFetch("depth3", "temp", "1") +
12732
+ ShadowTextureFetch("depth3", "temp", "1") +
1173112733 "") +
1173212734 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1173312735 //"MOV params, material;" +
....@@ -11849,7 +12851,7 @@
1184912851 "POW texSamp.a, texSamp.a, params6.w;" + // fog punch through shortcut
1185012852 // mar 2013 ??? "KIL alpha.a;" +
1185112853 "MOV alpha, texSamp.aaaa;" + // y;" +
11852
- "KIL alpha.a;" +
12854
+ "KIL alpha.a;" + // not sure with parallax mapping
1185312855 /*
1185412856 "MUL temp.xy, temp, two;" +
1185512857 "TXB bump, temp, texture[0], 2D;" +
....@@ -11935,11 +12937,6 @@
1193512937 "SUB bump0, bump0, half;" +
1193612938 "ADD bump, bump, bump0;" +
1193712939
11938
- "MOV temp.x, texSamp.a;" +
11939
- "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
11940
- //"LRP texSamp0, params5.x, texSamp0, one;" +
11941
- "MOV texSamp.a, temp.x;" +
11942
-
1194312940 // double-sided
1194412941 /**/
1194512942 (doublesided?"DP3 temp.z, normal, eye;" +
....@@ -11956,19 +12953,62 @@
1195612953 "MOV normald, normal;" +
1195712954 "MOV normals, normal;" +
1195812955
12956
+ "MOV temp, fragment.texcoord[4];" +
12957
+
1195912958 // UV base
1196012959 //"DP3 UP.x,state.matrix.modelview.row[0],Y;" +
1196112960 //"DP3 UP.y,state.matrix.modelview.row[1],Y;" +
1196212961 //"DP3 UP.z,state.matrix.modelview.row[2],Y;" +
11963
- "DP3 UP.x,state.matrix.texture[7].row[0],Y;" +
11964
- "DP3 UP.y,state.matrix.texture[7].row[1],Y;" +
11965
- "DP3 UP.z,state.matrix.texture[7].row[2],Y;" +
12962
+ "DP3 UP.x,state.matrix.texture[7].row[0],temp;" +
12963
+ "DP3 UP.y,state.matrix.texture[7].row[1],temp;" +
12964
+ "DP3 UP.z,state.matrix.texture[7].row[2],temp;" +
12965
+ Normalize("UP") +
12966
+
1196612967 "XPD V, normal, UP;" +
1196712968 Normalize("V") +
1196812969 "XPD U, V, normal;" +
1196912970 Normalize("U") +
1197012971
1197112972 // parallax mapping
12973
+
12974
+ "DP3 temp2.x, V, eye;" +
12975
+ "DP3 temp2.y, U, eye;" +
12976
+ "DP3 temp2.z, normal, eye;" +
12977
+ "RCP temp2.z, temp2.z;" +
12978
+
12979
+ "DP3 temp2.w, texSamp, texSamp;" + // Height
12980
+ "RSQ temp2.w, temp2.w;" +
12981
+ "RCP temp2.w, temp2.w;" +
12982
+
12983
+ "SUB temp2.w, temp2.w, half;" +
12984
+// "SGE temp.x, temp2.w, eps.x;" +
12985
+// "MUL temp2.w, temp2.w, temp.x;" +
12986
+
12987
+ //"MOV texSamp, U;" +
12988
+
12989
+ "MUL temp2.z, temp2.z, temp2.w;" +
12990
+ "MUL temp2.z, temp2.z, params7.z;" + // parallax
12991
+
12992
+ "MUL temp2, temp2, temp2.z;" +
12993
+
12994
+ "MOV temp, fragment.texcoord[0];" +
12995
+
12996
+ "SUB temp, temp, temp2;" +
12997
+
12998
+ "TEX temp, temp, texture[0], 2D;" +
12999
+ "POW temp.a, temp.a, params6.w;" + // punch through
13000
+
13001
+ "ADD texSamp, temp, texSamp;" +
13002
+ "MUL texSamp.xyz, half, texSamp;" +
13003
+
13004
+ "MOV alpha, texSamp.aaaa;" +
13005
+
13006
+// parallax mapping
13007
+
13008
+ "MOV temp.x, texSamp.a;" +
13009
+ "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
13010
+ //"LRP texSamp0, params5.x, texSamp0, one;" +
13011
+ "MOV texSamp.a, temp.x;" +
1197213012
1197313013 //"MOV temp, fragment.texcoord[0];" +
1197413014 //
....@@ -12098,10 +13138,10 @@
1209813138 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1209913139 "") +
1210013140
12101
- // display shadow only (bump == 0)
13141
+ // display shadow only (fakedepth == 0)
1210213142 "SUB temp.x, half.x, shadow.x;" +
12103
- "MOV temp.y, -params6.x;" +
12104
- "SLT temp.z, temp.y, zero.x;" +
13143
+ "MOV temp.y, -params5.z;" + // params6.x;" +
13144
+ "SLT temp.z, temp.y, -c256i.x;" +
1210513145 "SUB temp.y, one.x, temp.z;" +
1210613146 "MUL temp.x, temp.x, temp.y;" +
1210713147 "KIL temp.x;" +
....@@ -12230,8 +13270,10 @@
1223013270 "MAX ndotl.x, ndotl.x, -ndotl.x;" +
1223113271
1223213272 "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
13273
+ // Tuning for default skin
13274
+ //"ADD temp.x, temp.x, options2.z;" + // lightsheen
13275
+ "MAD temp.x, options2.z, half.y, temp.x;" + // lightsheen
13276
+ "ADD temp.y, one.y, options2.y;" + // subsurface
1223513277 "MUL temp.x, temp.x, temp.y;" +
1223613278
1223713279 "MUL saturation, saturation, temp.xxxx;" +
....@@ -12430,8 +13472,19 @@
1243013472 //once = true;
1243113473 }
1243213474
12433
- System.out.print("Program #" + mode + "; length = " + program.length());
12434
- System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13475
+ String program = programmax;
13476
+
13477
+ if (Globals.MINSHADER)
13478
+ {
13479
+ program = programmin;
13480
+ }
13481
+
13482
+ if (Globals.DEBUG)
13483
+ {
13484
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13485
+ System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13486
+ }
13487
+
1243513488 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1243613489
1243713490 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -12478,7 +13531,8 @@
1247813531 "\n" +
1247913532 "END\n";
1248013533
12481
- System.out.println("Program shadow #" + 0 + "; length = " + program.length());
13534
+ if (Globals.DEBUG)
13535
+ System.out.println("Program shadow #" + 0 + "; length = " + program.length());
1248213536 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1248313537
1248413538 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -12523,25 +13577,26 @@
1252313577 return out;
1252413578 }
1252513579
12526
- String TextureFetch(String dest, String src, String unit)
13580
+ // Also does frustum culling
13581
+ String ShadowTextureFetch(String dest, String src, String unit)
1252713582 {
1252813583 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1252913584 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1253013585 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13586
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13587
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1253113588 "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;" +
13589
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13590
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1253613591 //"SWZ buffer, temp, w,w,w,w;";
12537
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13592
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1253813593 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1253913594 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1254013595 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
12541
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13596
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1254213597
12543
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
12544
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13598
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13599
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1254513600 }
1254613601
1254713602 String Shadow(String depth, String shadow)
....@@ -12563,12 +13618,16 @@
1256313618
1256413619 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1256513620 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13621
+
13622
+ // Compare fragment depth in light space with shadowmap.
1256613623 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1256713624 "SGE temp.y, temp.x, zero.x;" +
12568
- "SUB " + shadow + ".y, one.x, temp.y;" +
13625
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13626
+
13627
+ // Reverse comparison
1256913628 "SUB temp.x, one.x, temp.x;" +
1257013629 "MUL " + shadow + ".x, temp.x, temp.y;" +
12571
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13630
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1257213631 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1257313632
1257413633 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -12582,6 +13641,10 @@
1258213641 // No shadow for backface
1258313642 "DP3 temp.x, normal, lightd;" +
1258413643 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13644
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13645
+
13646
+ // No shadow when out of frustum
13647
+ "SGE temp.x, " + depth + ".z, one.z;" +
1258513648 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1258613649 "";
1258713650 }
....@@ -12727,8 +13790,9 @@
1272713790 /*static*/ float[] modelParams4 = new float[]{0, 0, 0, 0}; // anisoV, cameralight, selfshadow, shadow
1272813791 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1272913792 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
12730
- /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
12731
- Object3D.cVector2[] vector2buffer;
13793
+ /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power, parallax
13794
+
13795
+ //Object3D.cVector2[] vector2buffer;
1273213796
1273313797 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1273413798 // OUT : diff, spec
....@@ -12744,9 +13808,10 @@
1274413808 "DP3 " + dest + ".z," + "normals," + "eye;" +
1274513809 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1274613810 //"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;" +
13811
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13812
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13813
+
13814
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1275013815 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1275113816 "RCP " + dest + ".w," + dest + ".w;" +
1275213817 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -12892,7 +13957,7 @@
1289213957 "PARAM p[4] = { state.matrix.projection }; # modelview projection matrix\n" +
1289313958 "PARAM zero = { 0.0, 0.0, 0.0, 1.0 };" +
1289413959 "PARAM half = { 0.5, 0.5, 0.5, 1.0 };" +
12895
- "PARAM one = { 1.0, 1.0, 1.0, 0.0 };" +
13960
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
1289613961 "PARAM two = { 2.0, 2.0, 2.0, 1.0 };" +
1289713962 "PARAM third = { 0.33333333333, 0.33333333333, 0.33333333333, 1.0 };" +
1289813963 //"PARAM v256 = { 256.0, 256.0, 256.0, 1.0 };" +
....@@ -12953,7 +14018,7 @@
1295314018 "DP4 temp.x,state.matrix.texture[0].inverse.row[0],vertex.texcoord;" +
1295414019 "DP4 temp.y,state.matrix.texture[0].inverse.row[1],vertex.texcoord;" +
1295514020 "DP4 temp.z,state.matrix.texture[0].inverse.row[2],vertex.texcoord;" +
12956
- //"MOV result.texcoord, vertex.texcoord;" +
14021
+ //"MOV result.texcoord, vertex.fogcoord;" +
1295714022 "MOV result.texcoord, temp;" +
1295814023 // border fade
1295914024 "MOV result.texcoord[3], vertex.texcoord;" +
....@@ -13000,7 +14065,9 @@
1300014065
1300114066 //"ADD temp.z, temp.z, one;" +
1300214067
13003
- "MOV result.color, temp;"
14068
+ "MOV result.texcoord[4], vertex.attrib[4];" + // U dir
14069
+
14070
+ "MOV result.color, temp;" // Normal
1300414071 : "MOV result.color, vertex.color;") +
1300514072 ((mode & VP_PROJECTION) != 0 ? "MOV result.color, zero;"
1300614073 : "") +
....@@ -13140,7 +14207,7 @@
1314014207 public void mousePressed(MouseEvent e)
1314114208 {
1314214209 //System.out.println("mousePressed: " + e);
13143
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14210
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1314414211 }
1314514212
1314614213 static long prevtime = 0;
....@@ -13167,6 +14234,7 @@
1316714234
1316814235 //System.err.println("Dtime = " + Dtime + "; units = " + e.getUnitsToScroll() + "; ratio (units/ms) = " + ratio);
1316914236
14237
+ if (BUTTONLESSWHEEL)
1317014238 if (Math.abs(ratio) < 0.1 || Math.abs(Dtime) == 0) // < 30)
1317114239 {
1317214240 return;
....@@ -13175,7 +14243,7 @@
1317514243 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
1317614244
1317714245 // TIMER
13178
- if (!wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
14246
+ if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
1317914247 {
1318014248 keepboxmode = BOXMODE;
1318114249 keepsupport = SUPPORT;
....@@ -13215,8 +14283,8 @@
1321514283 // mode |= META;
1321614284 //}
1321714285
13218
- SetMouseMode(WHEEL | e.getModifiersEx());
13219
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14286
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14287
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1322014288 anchorX = ax;
1322114289 anchorY = ay;
1322214290 prevX = px;
....@@ -13250,6 +14318,7 @@
1325014318 else
1325114319 if (evt.getSource() == AAtimer)
1325214320 {
14321
+ Globals.TIMERRUNNING = false;
1325314322 if (mouseDown)
1325414323 {
1325514324 //new Exception().printStackTrace();
....@@ -13275,6 +14344,10 @@
1327514344 // LIVE = waslive;
1327614345 // wasliveok = true;
1327714346 // waslive = false;
14347
+
14348
+ // May 2019 Forget it:
14349
+ if (true)
14350
+ return;
1327814351
1327914352 // source == timer
1328014353 if (mouseDown)
....@@ -13305,7 +14378,7 @@
1330514378
1330614379 // fev 2014???
1330714380 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13308
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14381
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1330914382 pingthread.StepToTarget(true); // true);
1331014383 }
1331114384 // if (!LIVE)
....@@ -13314,12 +14387,13 @@
1331414387
1331514388 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1331614389
13317
- void clickStart(int x, int y, int modifiers)
14390
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1331814391 {
1331914392 if (!wasliveok)
1332014393 return;
1332114394
1332214395 AAtimer.restart(); //
14396
+ Globals.TIMERRUNNING = true;
1332314397
1332414398 // waslive = LIVE;
1332514399 // LIVE = false;
....@@ -13331,7 +14405,7 @@
1333114405 // touched = true; // main DL
1333214406 if (isRenderer)
1333314407 {
13334
- SetMouseMode(modifiers);
14408
+ SetMouseMode(modifiers, modifiersex);
1333514409 }
1333614410
1333714411 selectX = anchorX = x;
....@@ -13344,7 +14418,7 @@
1334414418 clicked = true;
1334514419 hold = false;
1334614420
13347
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14421
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1334814422 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1334914423 {
1335014424 // System.out.println("RESTART II " + modifiers);
....@@ -13369,14 +14443,15 @@
1336914443 drag = false;
1337014444 //System.out.println("Mouse DOWN");
1337114445 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);
14446
+ //ClickInfo info = new ClickInfo();
14447
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14448
+ object.clickInfo.pane = this;
14449
+ object.clickInfo.camera = renderCamera;
14450
+ object.clickInfo.x = x;
14451
+ object.clickInfo.y = y;
14452
+ object.clickInfo.modifiers = modifiersex;
14453
+ editObj = object.doEditClick(//info,
14454
+ 0);
1338014455 if (!editObj)
1338114456 {
1338214457 hasMarquee = true;
....@@ -13392,11 +14467,14 @@
1339214467
1339314468 public void mouseDragged(MouseEvent e)
1339414469 {
14470
+ Globals.MOUSEDRAGGED = true;
14471
+
14472
+ //System.out.println("mouseDragged: " + e);
1339514473 if (isRenderer)
1339614474 movingcamera = true;
14475
+
1339714476 //if (drawing)
1339814477 //return;
13399
- //System.out.println("mouseDragged: " + e);
1340014478 if ((e.getModifiersEx() & CTRL) != 0
1340114479 || (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen())
1340214480 {
....@@ -13404,7 +14482,7 @@
1340414482 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1340514483 }
1340614484 else
13407
- drag(e.getX(), e.getY(), e.getModifiersEx());
14485
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1340814486
1340914487 //try { Thread.sleep(1); } catch (Exception ex) {}
1341014488 }
....@@ -13577,6 +14655,7 @@
1357714655
1357814656 public void run()
1357914657 {
14658
+ new Exception().printStackTrace();
1358014659 System.exit(0);
1358114660 for (;;)
1358214661 {
....@@ -13640,7 +14719,7 @@
1364014719 {
1364114720 Globals.lighttouched = true;
1364214721 }
13643
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14722
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1364414723 }
1364514724 //else
1364614725 }
....@@ -13654,12 +14733,18 @@
1365414733 void GoDown(int mod)
1365514734 {
1365614735 MODIFIERS |= COMMAND;
13657
- /*
14736
+ boolean isVR = (mouseMode&VR)!=0;
14737
+ /**/
1365814738 if((mod&SHIFT) == SHIFT)
13659
- manipCamera.RotatePosition(0, -speed);
14739
+ {
14740
+ if (isVR)
14741
+ manipCamera.RotateInterest(0, -speed);
14742
+ else
14743
+ manipCamera.RotatePosition(0, -speed);
14744
+ }
1366014745 else
13661
- manipCamera.BackForth(0, -speed*delta, getWidth());
13662
- */
14746
+ manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth());
14747
+ /**/
1366314748 if ((mod & SHIFT) == SHIFT)
1366414749 {
1366514750 mouseMode = mouseMode; // VR??
....@@ -13668,6 +14753,8 @@
1366814753 mouseMode |= BACKFORTH;
1366914754 }
1367014755
14756
+ targetLookAt.set(manipCamera.lookAt);
14757
+
1367114758 //prevX = X = anchorX;
1367214759 prevY = Y = anchorY - (int) (renderCamera.Distance());
1367314760 }
....@@ -13675,12 +14762,19 @@
1367514762 void GoUp(int mod)
1367614763 {
1367714764 MODIFIERS |= COMMAND;
13678
- /*
14765
+ /**/
14766
+ boolean isVR = (mouseMode&VR)!=0;
14767
+
1367914768 if((mod&SHIFT) == SHIFT)
13680
- manipCamera.RotatePosition(0, speed);
14769
+ {
14770
+ if (isVR)
14771
+ manipCamera.RotateInterest(0, speed);
14772
+ else
14773
+ manipCamera.RotatePosition(0, speed);
14774
+ }
1368114775 else
13682
- manipCamera.BackForth(0, speed*delta, getWidth());
13683
- */
14776
+ manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth());
14777
+ /**/
1368414778 if ((mod & SHIFT) == SHIFT)
1368514779 {
1368614780 mouseMode = mouseMode;
....@@ -13689,6 +14783,8 @@
1368914783 mouseMode |= BACKFORTH;
1369014784 }
1369114785
14786
+ targetLookAt.set(manipCamera.lookAt);
14787
+
1369214788 //prevX = X = anchorX;
1369314789 prevY = Y = anchorY + (int) (renderCamera.Distance());
1369414790 }
....@@ -13696,12 +14792,17 @@
1369614792 void GoLeft(int mod)
1369714793 {
1369814794 MODIFIERS |= COMMAND;
13699
- /*
14795
+ /**/
1370014796 if((mod&SHIFT) == SHIFT)
13701
- manipCamera.RotatePosition(speed, 0);
14797
+ manipCamera.Translate(speed*delta, 0, getWidth());
1370214798 else
13703
- manipCamera.Translate(speed*delta, 0, getWidth());
13704
- */
14799
+ {
14800
+ if ((mouseMode&VR)!=0)
14801
+ manipCamera.RotateInterest(-speed, 0);
14802
+ else
14803
+ manipCamera.RotatePosition(speed, 0);
14804
+ }
14805
+ /**/
1370514806 if ((mod & SHIFT) == SHIFT)
1370614807 {
1370714808 mouseMode = mouseMode;
....@@ -13710,6 +14811,8 @@
1371014811 mouseMode |= ROTATE;
1371114812 } // TRANSLATE;
1371214813
14814
+ targetLookAt.set(manipCamera.lookAt);
14815
+
1371314816 prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance());
1371414817 prevY = Y = anchorY;
1371514818 }
....@@ -13717,12 +14820,18 @@
1371714820 void GoRight(int mod)
1371814821 {
1371914822 MODIFIERS |= COMMAND;
13720
- /*
14823
+ /**/
1372114824 if((mod&SHIFT) == SHIFT)
13722
- manipCamera.RotatePosition(-speed, 0);
14825
+ manipCamera.Translate(-speed*delta, 0, getWidth());
1372314826 else
13724
- manipCamera.Translate(-speed*delta, 0, getWidth());
13725
- */
14827
+ {
14828
+ if ((mouseMode&VR)!=0)
14829
+ manipCamera.RotateInterest(speed, 0);
14830
+ else
14831
+ manipCamera.RotatePosition(-speed, 0);
14832
+ }
14833
+
14834
+ /**/
1372614835 if ((mod & SHIFT) == SHIFT)
1372714836 {
1372814837 mouseMode = mouseMode;
....@@ -13731,6 +14840,8 @@
1373114840 mouseMode |= ROTATE;
1373214841 } // TRANSLATE;
1373314842
14843
+ targetLookAt.set(manipCamera.lookAt);
14844
+
1373414845 prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance());
1373514846 prevY = Y = anchorY;
1373614847 }
....@@ -13740,7 +14851,7 @@
1374014851 int X, Y;
1374114852 boolean SX, SY;
1374214853
13743
- void drag(int x, int y, int modifiers)
14854
+ void drag(int x, int y, int modifiers, int modifiersex)
1374414855 {
1374514856 if (IsFrozen())
1374614857 {
....@@ -13749,17 +14860,17 @@
1374914860
1375014861 drag = true; // NEW
1375114862
13752
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14863
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1375314864
1375414865 X = x;
1375514866 Y = y;
1375614867 // floating state for animation
13757
- MODIFIERS = modifiers;
13758
- modifiers &= ~1024;
14868
+ MODIFIERS = modifiersex;
14869
+ modifiersex &= ~1024;
1375914870 if (false) // modifiers != 0)
1376014871 {
1376114872 //new Exception().printStackTrace();
13762
- System.out.println("mouseDragged: " + modifiers);
14873
+ System.out.println("mouseDragged: " + modifiersex);
1376314874 System.out.println("SHIFT = " + SHIFT);
1376414875 System.out.println("CONTROL = " + COMMAND);
1376514876 System.out.println("META = " + META);
....@@ -13772,14 +14883,16 @@
1377214883 if (editObj)
1377314884 {
1377414885 drag = true;
13775
- ClickInfo info = new ClickInfo();
13776
- info.bounds.setBounds(0, 0,
14886
+ //ClickInfo info = new ClickInfo();
14887
+ object.clickInfo.bounds.setBounds(0, 0,
1377714888 (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);
14889
+ object.clickInfo.pane = this;
14890
+ object.clickInfo.camera = renderCamera;
14891
+ object.clickInfo.x = x;
14892
+ object.clickInfo.y = y;
14893
+ object //.GetWindow().copy
14894
+ .doEditDrag(//info,
14895
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1378314896 } else
1378414897 {
1378514898 if (x < startX)
....@@ -13928,23 +15041,27 @@
1392815041 }
1392915042 }
1393015043
15044
+// ClickInfo clickInfo = new ClickInfo();
15045
+
1393115046 public void mouseMoved(MouseEvent e)
1393215047 {
1393315048 //System.out.println("mouseMoved: " + e);
13934
-
1393515049 if (isRenderer)
1393615050 return;
1393715051
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;
15052
+ // Mouse cursor feedback
15053
+ object.clickInfo.x = e.getX();
15054
+ object.clickInfo.y = e.getY();
15055
+ object.clickInfo.modifiers = e.getModifiersEx();
15056
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
15057
+ object.clickInfo.pane = this;
15058
+ object.clickInfo.camera = renderCamera;
1394515059 if (!isRenderer)
1394615060 {
13947
- if (object.editWindow.copy.doEditClick(ci, 0))
15061
+ //ObjEditor editWindow = object.editWindow;
15062
+ //Object3D copy = editWindow.copy;
15063
+ if (object.doEditClick(//clickInfo,
15064
+ 0))
1394815065 {
1394915066 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1395015067 } else
....@@ -13956,7 +15073,11 @@
1395615073
1395715074 public void mouseReleased(MouseEvent e)
1395815075 {
15076
+ Globals.MOUSEDRAGGED = false;
15077
+
1395915078 movingcamera = false;
15079
+ X = 0; // getBounds().width/2;
15080
+ Y = 0; // getBounds().height/2;
1396015081 //System.out.println("mouseReleased: " + e);
1396115082 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1396215083 }
....@@ -13979,9 +15100,9 @@
1397915100 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1398015101 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1398115102
13982
- if (control || command || IsFrozen())
15103
+// No delay if (control || command || IsFrozen())
1398315104 timeout = true;
13984
- else
15105
+// ?? May 2019 else
1398515106 // timer.setDelay((modifiers & 128) != 0?0:350);
1398615107 mouseDown = false;
1398715108 if (!control && !command) // june 2013
....@@ -14091,7 +15212,7 @@
1409115212 System.out.println("keyReleased: " + e);
1409215213 }
1409315214
14094
- void SetMouseMode(int modifiers)
15215
+ void SetMouseMode(int modifiers, int modifiersex)
1409515216 {
1409615217 //System.out.println("SetMouseMode = " + modifiers);
1409715218 //modifiers &= ~1024;
....@@ -14103,25 +15224,25 @@
1410315224 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1410415225 // return;
1410515226 //System.out.println("SetMode = " + modifiers);
14106
- if ((modifiers & WHEEL) == WHEEL)
15227
+ if ((modifiersex & WHEEL) == WHEEL)
1410715228 {
1410815229 mouseMode |= ZOOM;
1410915230 }
1411015231
1411115232 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
14112
- if (capsLocked || (modifiers & META) == META)
15233
+ if (capsLocked) // || (modifiers & META) == META)
1411315234 {
1411415235 mouseMode |= VR; // BACKFORTH;
1411515236 }
14116
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
15237
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1411715238 {
1411815239 mouseMode |= SELECT;
1411915240 }
14120
- if ((modifiers & COMMAND) == COMMAND)
15241
+ if ((modifiersex & COMMAND) == COMMAND)
1412115242 {
1412215243 mouseMode |= SELECT;
1412315244 }
14124
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15245
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
1412515246 {
1412615247 mouseMode &= ~VR;
1412715248 mouseMode |= TRANSLATE;
....@@ -14150,10 +15271,10 @@
1415015271
1415115272 if (isRenderer) //
1415215273 {
14153
- SetMouseMode(modifiers);
15274
+ SetMouseMode(0, modifiers);
1415415275 }
1415515276
14156
- theRenderer.keyPressed(key);
15277
+ Globals.theRenderer.keyPressed(key);
1415715278 }
1415815279
1415915280 int kompactbit = 4; // power bit
....@@ -14165,7 +15286,7 @@
1416515286 float SATPOW = 1; // 2; // 0.5f;
1416615287 float BRIPOW = 1; // 0.5f; // 0.5f;
1416715288
14168
- void keyPressed(int key)
15289
+ public void keyPressed(int key)
1416915290 {
1417015291 if (key >= '0' && key <= '5')
1417115292 clampbit = (key-'0');
....@@ -14212,7 +15333,8 @@
1421215333 // break;
1421315334 case 'T':
1421415335 CACHETEXTURE ^= true;
14215
- textures.clear();
15336
+ texturepigment.clear();
15337
+ texturebump.clear();
1421615338 // repaint();
1421715339 break;
1421815340 case 'Y':
....@@ -14222,8 +15344,8 @@
1422215344 case 'K':
1422315345 KOMPACTTEXTURE ^= true;
1422415346 //textures.clear();
14225
- break;
14226
- case 'P': // Texture Projection macros
15347
+ // break;
15348
+ //case 'P': // Texture Projection macros
1422715349 // SAVETEXTURE ^= true;
1422815350 macromode = true;
1422915351 Udebug = Vdebug = NORMALdebug = false; programInitialized = false;
....@@ -14297,7 +15419,9 @@
1429715419 case 'E' : COMPACT ^= true;
1429815420 repaint();
1429915421 break;
14300
- case 'W' : DEBUGHSB ^= true;
15422
+ case 'W' : // Wide Window (fullscreen)
15423
+ //DEBUGHSB ^= true;
15424
+ ObjEditor.theFrame.ToggleFullScreen();
1430115425 repaint();
1430215426 break;
1430315427 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14322,8 +15446,8 @@
1432215446 RevertCamera();
1432315447 repaint();
1432415448 break;
14325
- case 'L':
1432615449 case 'l':
15450
+ //case 'L':
1432715451 if (lightMode)
1432815452 {
1432915453 lightMode = false;
....@@ -14342,7 +15466,7 @@
1434215466 targetLookAt.set(manipCamera.lookAt);
1434315467 repaint();
1434415468 break;
14345
- case 'p':
15469
+ case 'P': // p':
1434615470 // c'est quoi ca au juste? spherical ^= true;
1434715471 Skinshader ^= true; programInitialized = false;
1434815472 repaint();
....@@ -14387,20 +15511,24 @@
1438715511 OCCLUSION_CULLING ^= true;
1438815512 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1438915513 break;
14390
- case '0': envyoff ^= true; repaint(); break;
15514
+ //case '0': envyoff ^= true; repaint(); break;
1439115515 case '1':
1439215516 case '2':
1439315517 case '3':
1439415518 case '4':
1439515519 case '5':
14396
- newenvy = Character.getNumericValue(key);
14397
- repaint();
14398
- break;
1439915520 case '6':
1440015521 case '7':
1440115522 case '8':
1440215523 case '9':
14403
- BGcolor = (key - '6')/3.f;
15524
+ if (true) // envyoff)
15525
+ {
15526
+ BGcolor = (key - '1')/8.f;
15527
+ }
15528
+ else
15529
+ {
15530
+ //newenvy = Character.getNumericValue(key);
15531
+ }
1440415532 repaint();
1440515533 break;
1440615534 case '!':
....@@ -14466,9 +15594,9 @@
1446615594 case '_':
1446715595 kompactbit = 5;
1446815596 break;
14469
- case '+':
14470
- kompactbit = 6;
14471
- break;
15597
+// case '+':
15598
+// kompactbit = 6;
15599
+// break;
1447215600 case ' ':
1447315601 lightMode ^= true;
1447415602 Globals.lighttouched = true;
....@@ -14480,13 +15608,14 @@
1448015608 case ESC:
1448115609 RENDERPROGRAM += 1;
1448215610 RENDERPROGRAM %= 3;
15611
+
1448315612 repaint();
1448415613 break;
1448515614 case 'Z':
1448615615 //RESIZETEXTURE ^= true;
1448715616 //break;
1448815617 case 'z':
14489
- RENDERSHADOW ^= true;
15618
+ Globals.RENDERSHADOW ^= true;
1449015619 Globals.lighttouched = true;
1449115620 repaint();
1449215621 break;
....@@ -14519,8 +15648,9 @@
1451915648 case DELETE:
1452015649 ClearSelection();
1452115650 break;
14522
- /*
1452315651 case '+':
15652
+
15653
+ /*
1452415654 //fontsize += 1;
1452515655 bbzoom *= 2;
1452615656 repaint();
....@@ -14537,17 +15667,17 @@
1453715667 case '=':
1453815668 IncDepth();
1453915669 //fontsize += 1;
14540
- object.editWindow.refreshContents(true);
15670
+ object.GetWindow().refreshContents(true);
1454115671 maskbit = 6;
1454215672 break;
1454315673 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1454415674 DecDepth();
1454515675 maskbit = 5;
1454615676 //if(fontsize > 1) fontsize -= 1;
14547
- if (object.editWindow == null)
14548
- new Exception().printStackTrace();
14549
- else
14550
- object.editWindow.refreshContents(true);
15677
+// if (object.editWindow == null)
15678
+// new Exception().printStackTrace();
15679
+// else
15680
+ object.GetWindow().refreshContents(true);
1455115681 break;
1455215682 case '{':
1455315683 manipCamera.shaper_fovy /= 1.1;
....@@ -14602,6 +15732,7 @@
1460215732 }
1460315733 //System.out.println("shaper_fovy = " + manipCamera.shaper_fovy);
1460415734 }
15735
+
1460515736 static double OCCLUSIONBOOST = 1; // 0.5;
1460615737
1460715738 void keyReleased(int key, int modifiers)
....@@ -14609,11 +15740,11 @@
1460915740 //mode = ROTATE;
1461015741 if ((MODIFIERS & COMMAND) == 0) // VR??
1461115742 {
14612
- SetMouseMode(modifiers);
15743
+ SetMouseMode(0, modifiers);
1461315744 }
1461415745 }
1461515746
14616
- protected void processKeyEvent(KeyEvent e)
15747
+ public void processKeyEvent(KeyEvent e)
1461715748 {
1461815749 switch (e.getID())
1461915750 {
....@@ -14743,8 +15874,9 @@
1474315874
1474415875 protected void processMouseMotionEvent(MouseEvent e)
1474515876 {
14746
- //System.out.println("processMouseMotionEvent: " + mouseMode);
14747
- if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15877
+ //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
15878
+ //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15879
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1474815880 {
1474915881 mouseMoved(e);
1475015882 } else
....@@ -14769,11 +15901,12 @@
1476915901 }
1477015902 */
1477115903
14772
- object.editWindow.EditSelection();
15904
+ object.GetWindow().EditSelection(false);
1477315905 }
1477415906
1477515907 void SelectParent()
1477615908 {
15909
+ new Exception().printStackTrace();
1477715910 System.exit(0);
1477815911 Composite group = (Composite) object;
1477915912 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -14785,10 +15918,10 @@
1478515918 {
1478615919 //selectees.remove(i);
1478715920 System.out.println("select parent of " + elem);
14788
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15921
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1478915922 } else
1479015923 {
14791
- group.editWindow.Select(elem.GetTreePath(), first, true);
15924
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1479215925 }
1479315926
1479415927 first = false;
....@@ -14797,6 +15930,7 @@
1479715930
1479815931 void SelectChildren()
1479915932 {
15933
+ new Exception().printStackTrace();
1480015934 System.exit(0);
1480115935 /*
1480215936 Composite group = (Composite) object;
....@@ -14829,12 +15963,12 @@
1482915963 for (int j = 0; j < group.children.size(); j++)
1483015964 {
1483115965 elem = (Object3D) group.children.elementAt(j);
14832
- object.editWindow.Select(elem.GetTreePath(), first, true);
15966
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1483315967 first = false;
1483415968 }
1483515969 } else
1483615970 {
14837
- object.editWindow.Select(elem.GetTreePath(), first, true);
15971
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1483815972 }
1483915973
1484015974 first = false;
....@@ -14845,21 +15979,21 @@
1484515979 {
1484615980 //Composite group = (Composite) object;
1484715981 Object3D group = object;
14848
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15982
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1484915983 }
1485015984
1485115985 void ResetTransform(int mask)
1485215986 {
1485315987 //Composite group = (Composite) object;
1485415988 Object3D group = object;
14855
- group.editWindow.ResetTransform(mask);
15989
+ group.GetWindow().ResetTransform(mask);
1485615990 }
1485715991
1485815992 void FlipTransform()
1485915993 {
1486015994 //Composite group = (Composite) object;
1486115995 Object3D group = object;
14862
- group.editWindow.FlipTransform();
15996
+ group.GetWindow().FlipTransform();
1486315997 // group.editWindow.ReduceMesh(true);
1486415998 }
1486515999
....@@ -14867,7 +16001,7 @@
1486716001 {
1486816002 //Composite group = (Composite) object;
1486916003 Object3D group = object;
14870
- group.editWindow.PrintMemory();
16004
+ group.GetWindow().PrintMemory();
1487116005 // group.editWindow.ReduceMesh(true);
1487216006 }
1487316007
....@@ -14875,7 +16009,7 @@
1487516009 {
1487616010 //Composite group = (Composite) object;
1487716011 Object3D group = object;
14878
- group.editWindow.ResetCentroid();
16012
+ group.GetWindow().ResetCentroid();
1487916013 }
1488016014
1488116015 void IncDepth()
....@@ -14957,11 +16091,11 @@
1495716091
1495816092 int width = getBounds().width;
1495916093 int height = getBounds().height;
14960
- ClickInfo info = new ClickInfo();
14961
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1496216094 //Image img = CreateImage(width, height);
1496316095 //System.out.println("width = " + width + "; height = " + height + "\n");
16096
+
1496416097 Graphics gr = g; // img.getGraphics();
16098
+
1496516099 if (!hasMarquee)
1496616100 {
1496716101 if (Xmin < Xmax) // !locked)
....@@ -15033,44 +16167,92 @@
1503316167 }
1503416168 if (object != null && !hasMarquee)
1503516169 {
16170
+ if (object.clickInfo == null)
16171
+ object.clickInfo = new ClickInfo();
16172
+ ClickInfo info = object.clickInfo;
16173
+ //ClickInfo info = new ClickInfo();
16174
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16175
+
1503616176 if (isRenderer)
1503716177 {
15038
- info.flags++;
16178
+ object.clickInfo.flags++;
1503916179 double frameAspect = (double) width / (double) height;
1504016180 if (frameAspect > renderCamera.aspect)
1504116181 {
1504216182 int desired = (int) ((double) height * renderCamera.aspect);
15043
- info.bounds.width -= width - desired;
15044
- info.bounds.x += (width - desired) / 2;
16183
+ object.clickInfo.bounds.width -= width - desired;
16184
+ object.clickInfo.bounds.x += (width - desired) / 2;
1504516185 } else
1504616186 {
1504716187 int desired = (int) ((double) width / renderCamera.aspect);
15048
- info.bounds.height -= height - desired;
15049
- info.bounds.y += (height - desired) / 2;
16188
+ object.clickInfo.bounds.height -= height - desired;
16189
+ object.clickInfo.bounds.y += (height - desired) / 2;
1505016190 }
1505116191 }
15052
- info.g = gr;
15053
- info.camera = renderCamera;
16192
+
16193
+ object.clickInfo.g = gr;
16194
+ object.clickInfo.camera = renderCamera;
1505416195 /*
1505516196 // Memory intensive (brep.verticescopy)
1505616197 if (!(object instanceof Composite))
1505716198 object.draw(info, 0, false); // SLOW :
1505816199 */
15059
- if (!isRenderer)
16200
+ if (!isRenderer) // && drag)
1506016201 {
15061
- object.drawEditHandles(info, 0);
16202
+ Grafreed.Assert(object != null);
16203
+ Grafreed.Assert(object.selection != null);
16204
+ if (object.selection.Size() > 0)
16205
+ {
16206
+ int hitSomething = object.selection.get(0).hitSomething;
16207
+
16208
+ object.clickInfo.DX = 0;
16209
+ object.clickInfo.DY = 0;
16210
+ object.clickInfo.W = 1;
16211
+ if (hitSomething == Object3D.hitCenter)
16212
+ {
16213
+ info.DX = X;
16214
+ if (X != 0)
16215
+ info.DX -= info.bounds.width/2;
16216
+
16217
+ info.DY = Y;
16218
+ if (Y != 0)
16219
+ info.DY -= info.bounds.height/2;
16220
+ }
16221
+
16222
+ object.drawEditHandles(//info,
16223
+ 0);
16224
+
16225
+ if (drag && (X != 0 || Y != 0))
16226
+ {
16227
+ switch (hitSomething)
16228
+ {
16229
+ case Object3D.hitCenter: gr.setColor(Color.white);
16230
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16231
+ break;
16232
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16233
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16234
+ break;
16235
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16236
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16237
+ break;
16238
+ }
16239
+
16240
+ }
16241
+ }
1506216242 }
1506316243 }
16244
+
1506416245 if (isRenderer)
1506516246 {
1506616247 //gr.setColor(Color.black);
1506716248 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1506816249 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1506916250 }
16251
+
1507016252 if (hasMarquee)
1507116253 {
1507216254 gr.setXORMode(Color.white);
15073
- gr.setColor(Color.red);
16255
+ gr.setColor(Color.white);
1507416256 if (!firstime)
1507516257 {
1507616258 gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH);
....@@ -15179,6 +16361,7 @@
1517916361 public boolean mouseDown(Event evt, int x, int y)
1518016362 {
1518116363 System.out.println("mouseDown: " + evt);
16364
+ System.exit(0);
1518216365 /*
1518316366 locked = true;
1518416367 drag = false;
....@@ -15222,7 +16405,7 @@
1522216405 {
1522316406 keyPressed(0, modifiers);
1522416407 }
15225
- clickStart(x, y, modifiers);
16408
+ // clickStart(x, y, modifiers);
1522616409 return true;
1522716410 }
1522816411
....@@ -15340,7 +16523,7 @@
1534016523 {
1534116524 keyReleased(0, 0);
1534216525 }
15343
- drag(x, y, modifiers);
16526
+ drag(x, y, 0, modifiers);
1534416527 return true;
1534516528 }
1534616529
....@@ -15472,7 +16655,7 @@
1547216655 Object3D object;
1547316656 static Object3D trackedobject;
1547416657 Camera renderCamera; // Light or Eye (or Occlusion)
15475
- /*static*/ Camera manipCamera; // Light or Eye
16658
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1547616659 /*static*/ Camera eyeCamera;
1547716660 /*static*/ Camera lightCamera;
1547816661 int cameracount;
....@@ -15536,6 +16719,8 @@
1553616719 private /*static*/ boolean firstime;
1553716720 private /*static*/ cVector newView = new cVector();
1553816721 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16722
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16723
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1553916724 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1554016725 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1554116726 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -15548,29 +16733,67 @@
1554816733 {
1554916734 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1555016735
16736
+ int usedsuf = 0;
16737
+
1555116738 for (int i = 0; i < suffixes.length; i++)
1555216739 {
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)
16740
+ String[] suffixe = suffixes;
16741
+ String[] fallback = suffixes2;
16742
+ String[] fallfallback = suffixes3;
16743
+
16744
+ for (int c=usedsuf; --c>=0;)
1555816745 {
15559
- throw new IOException("Unable to load texture " + resourceName);
16746
+// String[] temp = suffixe;
16747
+// suffixe = fallback;
16748
+// fallback = fallfallback;
16749
+// fallfallback = temp;
1556016750 }
16751
+
16752
+ String resourceName = basename + suffixe[i] + "." + suffix;
16753
+ TextureData data;
16754
+
16755
+ try
16756
+ {
16757
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16758
+ mipmapped,
16759
+ FileUtil.getFileSuffix(resourceName));
16760
+ }
16761
+ catch (Exception e)
16762
+ {
16763
+ try
16764
+ {
16765
+ resourceName = basename + fallback[i] + "." + suffix;
16766
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16767
+ mipmapped,
16768
+ FileUtil.getFileSuffix(resourceName));
16769
+ }
16770
+ catch (Exception e2)
16771
+ {
16772
+ resourceName = basename + fallfallback[i] + "." + suffix;
16773
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16774
+ mipmapped,
16775
+ FileUtil.getFileSuffix(resourceName));
16776
+ }
16777
+ }
16778
+
1556116779 //System.out.println("Target = " + targets[i]);
1556216780 cubemap.updateImage(data, targets[i]);
1556316781 }
1556416782
1556516783 return cubemap;
1556616784 }
16785
+
1556716786 int bigsphere = -1;
1556816787
1556916788 float BGcolor = 0.5f;
1557016789
15571
- private void DrawSkyBox(GL gl)
16790
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16791
+
16792
+ private void DrawSkyBox(GL gl, float ratio)
1557216793 {
15573
- if (envyoff || cubemap == null)
16794
+ if (//envyoff ||
16795
+ WIREFRAME ||
16796
+ cubemap == null)
1557416797 {
1557516798 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1557616799 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -15585,7 +16808,17 @@
1558516808 // Compensates for ExaminerViewer's modification of modelview matrix
1558616809 gl.glMatrixMode(GL.GL_MODELVIEW);
1558716810 gl.glLoadIdentity();
16811
+ gl.glScalef(1,ratio,1);
1558816812
16813
+// colorV[0] = 2;
16814
+// colorV[1] = 2;
16815
+// colorV[2] = 2;
16816
+// colorV[3] = 1;
16817
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16818
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16819
+//
16820
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16821
+
1558916822 //gl.glActiveTexture(GL.GL_TEXTURE1);
1559016823 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1559116824
....@@ -15617,6 +16850,7 @@
1561716850 {
1561816851 gl.glScalef(1.0f, -1.0f, 1.0f);
1561916852 }
16853
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1562016854 gl.glMultMatrixd(viewrot_1, 0);
1562116855 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1562216856 //viewer.updateInverseRotation(gl);
....@@ -15657,7 +16891,8 @@
1565716891 gl.glDisable(GL.GL_TEXTURE_GEN_R);
1565816892
1565916893 cubemap.disable();
15660
- ////cubemap.unbind();
16894
+ //cubemap.dispose();
16895
+
1566116896 if (CULLFACE)
1566216897 {
1566316898 gl.glEnable(gl.GL_CULL_FACE);
....@@ -15713,7 +16948,7 @@
1571316948 gl.glScalef(1.0f, -1.0f, 1.0f);
1571416949 }
1571516950
15716
- gl.glNormal3f(0.0f, 0.0f, 1.0f);
16951
+ SetGLNormal(gl, 0.0f, 0.0f, 1.0f);
1571716952
1571816953 float step = 2; // 0.1666f; //0.25f;
1571916954 float stepv = 2; // step * 1652 / 998;
....@@ -15757,16 +16992,16 @@
1575716992 cStatic.objectstack[materialdepth++] = checker;
1575816993 //System.out.println("material " + material);
1575916994 //Applet3D.tracein(this, selected);
15760
- vector2buffer = checker.projectedVertices;
16995
+ //vector2buffer = checker.projectedVertices;
1576116996
1576216997 //checker.GetMaterial().Draw(this, false); // true);
15763
- DrawMaterial(checker.GetMaterial(), false); // true);
16998
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1576416999
1576517000 materialdepth -= 1;
1576617001 if (materialdepth > 0)
1576717002 {
15768
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
15769
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
17003
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
17004
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1577017005 }
1577117006 //checker.GetMaterial().opacity = 1f;
1577217007 ////checker.GetMaterial().ambient = 1f;
....@@ -15852,6 +17087,14 @@
1585217087 }
1585317088 }
1585417089
17090
+ private Object3D GetFolder()
17091
+ {
17092
+ Object3D folder = object.GetWindow().copy;
17093
+ if (object.GetWindow().copy.selection.Size() > 0)
17094
+ folder = object.GetWindow().copy.selection.elementAt(0);
17095
+ return folder;
17096
+ }
17097
+
1585517098 class SelectBuffer implements GLEventListener
1585617099 {
1585717100
....@@ -15867,7 +17110,7 @@
1586717110 //new Exception().printStackTrace();
1586817111 System.out.println("select buffer init");
1586917112 // Use debug pipeline
15870
- drawable.setGL(new DebugGL(drawable.getGL()));
17113
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1587117114
1587217115 GL gl = drawable.getGL();
1587317116
....@@ -15910,6 +17153,7 @@
1591017153 {
1591117154 if (!selection)
1591217155 {
17156
+ new Exception().printStackTrace();
1591317157 System.exit(0);
1591417158 return;
1591517159 }
....@@ -15930,6 +17174,17 @@
1593017174
1593117175 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1593217176
17177
+ if (PAINTMODE)
17178
+ {
17179
+ if (object.GetWindow().copy.selection.Size() > 0)
17180
+ {
17181
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17182
+
17183
+ // Make what you paint not selectable.
17184
+ paintobj.ResetSelectable();
17185
+ }
17186
+ }
17187
+
1593317188 //int tmp = selection_view;
1593417189 //selection_view = -1;
1593517190 int temp = DrawMode();
....@@ -15941,6 +17196,17 @@
1594117196 // temp = DEFAULT; // patch for selection debug
1594217197 Globals.drawMode = temp; // WARNING
1594317198
17199
+ if (PAINTMODE)
17200
+ {
17201
+ if (object.GetWindow().copy.selection.Size() > 0)
17202
+ {
17203
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17204
+
17205
+ // Revert.
17206
+ paintobj.RestoreSelectable();
17207
+ }
17208
+ }
17209
+
1594417210 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1594517211
1594617212 // trying different ways of getting the depth info over
....@@ -15988,6 +17254,8 @@
1598817254 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1598917255 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1599017256 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
17257
+
17258
+ CreateSelectedPoint();
1599117259
1599217260 // Will fit the mesh !!!
1599317261 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16037,34 +17305,36 @@
1603717305 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]));
1603817306 }
1603917307
16040
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
17308
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1604117309 }
1604217310 }
1604317311
1604417312 if (!movingcamera && !PAINTMODE)
16045
- object.editWindow.ScreenFitPoint(); // fev 2014
17313
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1604617314
16047
- if (PAINTMODE && GrafreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17315
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1604817316 {
16049
- Object3D paintobj = GrafreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17317
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1605017318
16051
- Object3D group = new Object3D("inst" + paintcount++);
17319
+ if (object.GetWindow().copy.selection.Size() > 0)
17320
+ {
17321
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1605217322
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();
17323
+ Object3D inst = new Object3D("inst" + paintcount++);
17324
+
17325
+ inst.CreateMaterial(); // use a void leaf to select instances
17326
+
17327
+ inst.add(paintobj); // link
17328
+
17329
+ object.GetWindow().SnapObject(inst);
17330
+
17331
+ Object3D folder = paintFolder; // GetFolder();
17332
+
17333
+ folder.add(inst);
17334
+
17335
+ object.GetWindow().ResetModel();
17336
+ object.GetWindow().refreshContents();
17337
+ }
1606817338 }
1606917339 else
1607017340 paintcount = 0;
....@@ -16103,6 +17373,11 @@
1610317373 //System.out.println("objects[color] = " + objects[color]);
1610417374 //objects[color].Select();
1610517375 indexcount = 0;
17376
+ ObjEditor window = object.GetWindow();
17377
+ if (window != null && deselect)
17378
+ {
17379
+ window.Select(null, deselect, true);
17380
+ }
1610617381 object.Select(color, deselect);
1610717382 }
1610817383
....@@ -16153,6 +17428,7 @@
1615317428
1615417429 public void init(GLAutoDrawable drawable)
1615517430 {
17431
+ if (Globals.DEBUG)
1615617432 System.out.println("shadow buffer init");
1615717433
1615817434 GL gl = drawable.getGL();
....@@ -16202,7 +17478,7 @@
1620217478 gl.glDisable(gl.GL_CULL_FACE);
1620317479 }
1620417480
16205
- if (!RENDERSHADOW)
17481
+ if (!Globals.RENDERSHADOW)
1620617482 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1620717483
1620817484 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -16212,7 +17488,7 @@
1621217488 //gl.glColorMask(false, false, false, false);
1621317489
1621417490 //render_scene_from_light_view(gl, drawable, 0, 0);
16215
- if (RENDERSHADOW && Globals.lighttouched && !movingcamera) // && !parent.IsFreezed())
17491
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1621617492 {
1621717493 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1621817494
....@@ -16381,10 +17657,14 @@
1638117657 gl.glFlush();
1638217658
1638317659 /**/
16384
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17660
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1638517661
16386
- float[] pixels = occlusionsizebuffer.array();
17662
+ float[] depths = occlusiondepthbuffer.array();
1638717663
17664
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17665
+
17666
+ int[] pixels = selectsizebuffer.array();
17667
+
1638817668 double r = 0, g = 0, b = 0;
1638917669
1639017670 double count = 0;
....@@ -16395,7 +17675,7 @@
1639517675
1639617676 double FACTOR = 1;
1639717677
16398
- for (int i = 0; i < pixels.length; i++)
17678
+ for (int i = 0; i < depths.length; i++)
1639917679 {
1640017680 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1640117681 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -16478,7 +17758,7 @@
1647817758
1647917759 double scale = ray.z; // 1; // cos
1648017760
16481
- float depth = pixels[newindex];
17761
+ float depth = depths[newindex];
1648217762
1648317763 /*
1648417764 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -16628,23 +17908,15 @@
1662817908 int AAbuffersize = 0;
1662917909
1663017910 //double[] selectedpoint = new double[3];
16631
- static Superellipsoid selectedpoint = new Superellipsoid();
17911
+ static Superellipsoid selectedpoint;
1663217912 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();
17913
+ static Sphere debugpointG;
17914
+ static Sphere debugpointP;
17915
+ static Sphere debugpointC;
17916
+ static Sphere debugpointR;
1663717917
1663817918 static Sphere debugpoints[] = new Sphere[8];
1663917919
16640
- static
16641
- {
16642
- for (int i=0; i<8; i++)
16643
- {
16644
- debugpoints[i] = new Sphere();
16645
- }
16646
- }
16647
-
1664817920 static void InitPoints(float radius)
1664917921 {
1665017922 for (int i=0; i<8; i++)
....@@ -16683,11 +17955,14 @@
1668317955 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1668417956 static IntBuffer bigAAbuffer;
1668517957 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
16686
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17958
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1668717959 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1668817960 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1668917961 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
16690
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17962
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17963
+
17964
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17965
+
1669117966 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1669217967 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1669317968 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();
....@@ -16696,10 +17971,11 @@
1669617971 static IntBuffer textbuffer = null; // IntBuffer.allocate(TEXT_WIDTH*8*8 * TEXT_HEIGHT);
1669717972 // Depth buffer format
1669817973 //private int depth_format;
16699
- static public void NextIndex(Object3D o, GL gl)
17974
+
17975
+ public void NextIndex()
1670017976 {
1670117977 indexcount+=16;
16702
- gl.glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
17978
+ GetGL().glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
1670317979 //objects[indexcount] = o;
1670417980 //System.out.println("indexcount = " + indexcount);
1670517981 }