Normand Briere
2019-08-26 6266c8a4b2485b29a7d5bcb217460d7aad3e1c4a
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)
....@@ -776,7 +881,7 @@
776881 //// tris.postdraw(this);
777882 }
778883
779
- static Camera localcamera = new Camera();
884
+ static Camera localAOcamera = new Camera();
780885 static cVector from = new cVector();
781886 static cVector to = new cVector();
782887
....@@ -785,7 +890,7 @@
785890 CameraPane cp = this;
786891
787892 Camera keep = cp.RenderCamera();
788
- cp.renderCamera = localcamera;
893
+ cp.renderCamera = localAOcamera;
789894
790895 if (br.trimmed)
791896 {
....@@ -803,7 +908,7 @@
803908 br.positions[i3 + 2] + br.normals[i3 + 2]);
804909 LA.xformPos(from, transform, from);
805910 LA.xformPos(to, transform, to); // RIGID ONLY
806
- localcamera.setAim(from, to);
911
+ localAOcamera.setAim(from, to);
807912
808913 CameraPane.occlusionbuffer.display();
809914
....@@ -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 }
....@@ -837,7 +942,7 @@
837942 to.set(v.x+v.norm.x, v.y+v.norm.y, v.z+v.norm.z);
838943 LA.xformPos(from, transform, from);
839944 LA.xformPos(to, transform, to); // RIGID ONLY
840
- localcamera.setAim(from, to);
945
+ localAOcamera.setAim(from, to);
841946
842947 CameraPane.occlusionbuffer.display();
843948
....@@ -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,82 @@
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 zero12t = { 0.0, 1.0, 2, 1.25 };" +
12518
+ "PARAM pow_2 = { 0.5, 0.25, 0.125, 0.0 };" +
12519
+ "PARAM pow2 = { 2, 4, 8, 0.0 };" +
12520
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12521
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12522
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12523
+ "PARAM light2cam0 = program.env[10];" +
12524
+ "PARAM light2cam1 = program.env[11];" +
12525
+ "PARAM light2cam2 = program.env[12];" +
12526
+ "TEMP temp;" +
12527
+ "TEMP light;" +
12528
+ "TEMP ndotl;" +
12529
+ "TEMP normal;" +
12530
+ "TEMP depth;" +
12531
+ "TEMP eye;" +
12532
+ "TEMP pos;" +
12533
+
12534
+ "MAD normal, fragment.color, zero12t.z, -zero12t.y;" +
12535
+ Normalize("normal") +
12536
+ "MOV light, state.light[0].position;" +
12537
+ "DP3 ndotl.x, light, normal;" +
12538
+ "MAX ndotl.x, ndotl.x, zero12t.x;" +
12539
+
12540
+ // shadow
12541
+ "MOV pos, fragment.texcoord[1];" +
12542
+ "MOV temp, pos;" +
12543
+ ShadowTextureFetch("depth", "temp", "1") +
12544
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12545
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12546
+
12547
+ // No shadow when out of frustum
12548
+ //"SGE temp.y, depth.z, zero123.y;" +
12549
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12550
+
12551
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12552
+
12553
+ // Backlit
12554
+ "MOV pos.w, zero12t.y;" + // one
12555
+ "DP4 eye.x, pos, light2cam0;" +
12556
+ "DP4 eye.y, pos, light2cam1;" +
12557
+ "DP4 eye.z, pos, light2cam2;" +
12558
+ Normalize("eye") +
12559
+
12560
+ "DP3 ndotl.y, -eye, normal;" +
12561
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12562
+ "POW ndotl.y, ndotl.y, pow2.x;" + // backlit
12563
+ "SUB ndotl.y, zero12t.y, ndotl.y;" + // 1 - y
12564
+ //"POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12565
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12566
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12567
+ "ADD ndotl.y, ndotl.y, one.x;" +
12568
+ "MUL ndotl.y, ndotl.y, pow_2.x;" +
12569
+
12570
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12571
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12572
+
12573
+ // Pigment
12574
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12575
+ "LRP temp, zero12t.w, temp, one;" + // texture proportion
12576
+ "MUL temp, temp, zero12t.w;" + // Times x
12577
+
12578
+ //"MUL temp, temp, ndotl.y;" +
12579
+ "MAD ndotl.x, pow_2.xxxx, ndotl.yyyy, ndotl.x;" +
12580
+
12581
+ "MUL temp, temp, ndotl.x;" + // lambert
12582
+
12583
+ "MOV temp.w, zero12t.y;" + // reset alpha
12584
+ "MOV result.color, temp;" +
12585
+ "END";
12586
+
12587
+ String programmax =
12588
+ "!!ARBfp1.0\n" +
12589
+
1158112590 //"OPTION ARB_fragment_program_shadow;" +
1158212591 "PARAM light2cam0 = program.env[10];" +
1158312592 "PARAM light2cam1 = program.env[11];" +
....@@ -11603,7 +12612,7 @@
1160312612 "PARAM params4 = program.env[4];" + // anisoV, cameralight, selfshadow, shadow
1160412613 "PARAM params5 = program.env[5];" + // texture, opacity, fakedepth, shadowbias
1160512614 "PARAM params6 = program.env[6];" + // bump, noise, borderfade, fog punchthrough
11606
- "PARAM params7 = program.env[7];" + // noise power, opacity power
12615
+ "PARAM params7 = program.env[7];" + // noise power, opacity power, parallax
1160712616 "PARAM options0 = program.env[63];" + // fog density, intensity, elevation
1160812617 "PARAM options1 = program.env[62];" + // fog rgb color
1160912618 "PARAM options2 = program.env[61];" + // image intensity, subsurface, lightsheen
....@@ -11692,8 +12701,7 @@
1169212701 "TEMP shininess;" +
1169312702 "\n" +
1169412703 "MOV texSamp, one;" +
11695
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
11696
-
12704
+
1169712705 "MOV mapgrid.x, one2048th.x;" +
1169812706 "MOV temp, fragment.texcoord[1];" +
1169912707 /*
....@@ -11714,20 +12722,20 @@
1171412722 "MUL temp, floor, mapgrid.x;" +
1171512723 //"TEX depth0, temp, texture[1], 2D;" +
1171612724 (((mode & FP_SOFTSHADOW) == 0) ? "" :
11717
- TextureFetch("depth0", "temp", "1") +
12725
+ ShadowTextureFetch("depth0", "temp", "1") +
1171812726 "") +
1171912727 "ADD temp.x, temp.x, mapgrid.x;" +
1172012728 //"TEX depth1, temp, texture[1], 2D;" +
1172112729 (((mode & FP_SOFTSHADOW) == 0) ? "" :
11722
- TextureFetch("depth1", "temp", "1") +
12730
+ ShadowTextureFetch("depth1", "temp", "1") +
1172312731 "") +
1172412732 "ADD temp.y, temp.y, mapgrid.x;" +
1172512733 //"TEX depth2, temp, texture[1], 2D;" +
11726
- TextureFetch("depth2", "temp", "1") +
12734
+ ShadowTextureFetch("depth2", "temp", "1") +
1172712735 "SUB temp.x, temp.x, mapgrid.x;" +
1172812736 //"TEX depth3, temp, texture[1], 2D;" +
1172912737 (((mode & FP_SOFTSHADOW) == 0) ? "" :
11730
- TextureFetch("depth3", "temp", "1") +
12738
+ ShadowTextureFetch("depth3", "temp", "1") +
1173112739 "") +
1173212740 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1173312741 //"MOV params, material;" +
....@@ -11849,7 +12857,7 @@
1184912857 "POW texSamp.a, texSamp.a, params6.w;" + // fog punch through shortcut
1185012858 // mar 2013 ??? "KIL alpha.a;" +
1185112859 "MOV alpha, texSamp.aaaa;" + // y;" +
11852
- "KIL alpha.a;" +
12860
+ "KIL alpha.a;" + // not sure with parallax mapping
1185312861 /*
1185412862 "MUL temp.xy, temp, two;" +
1185512863 "TXB bump, temp, texture[0], 2D;" +
....@@ -11935,11 +12943,6 @@
1193512943 "SUB bump0, bump0, half;" +
1193612944 "ADD bump, bump, bump0;" +
1193712945
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
-
1194312946 // double-sided
1194412947 /**/
1194512948 (doublesided?"DP3 temp.z, normal, eye;" +
....@@ -11949,26 +12952,73 @@
1194912952 "ADD temp.x, temp.x, one.x;" +
1195012953 "MUL normal, normal, temp.xxxx;":""
1195112954 ) +
11952
- /**/
11953
-//// Normalize("normal") +
11954
-//// "MAX normal.z, eps.x, normal.z;" +
11955
-// Normalize("normal") +
11956
- "MOV normald, normal;" +
11957
- "MOV normals, normal;" +
12955
+ /**/
12956
+
12957
+ "MOV temp, fragment.texcoord[4];" +
1195812958
1195912959 // UV base
1196012960 //"DP3 UP.x,state.matrix.modelview.row[0],Y;" +
1196112961 //"DP3 UP.y,state.matrix.modelview.row[1],Y;" +
1196212962 //"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;" +
12963
+ "DP3 UP.x,state.matrix.texture[7].row[0],temp;" +
12964
+ "DP3 UP.y,state.matrix.texture[7].row[1],temp;" +
12965
+ "DP3 UP.z,state.matrix.texture[7].row[2],temp;" +
12966
+ Normalize("UP") +
12967
+
1196612968 "XPD V, normal, UP;" +
1196712969 Normalize("V") +
1196812970 "XPD U, V, normal;" +
1196912971 Normalize("U") +
1197012972
12973
+ "MOV temp, fragment.texcoord[0];" +
12974
+
12975
+// "MAD normal, -temp.x, U, normal;" +
12976
+// "MAD normal, -temp.y, V, normal;" +
12977
+// Normalize("normal") +
12978
+
12979
+//// "MAX normal.z, eps.x, normal.z;" +
12980
+// Normalize("normal") +
12981
+ "MOV normald, normal;" +
12982
+ "MOV normals, normal;" +
12983
+
1197112984 // parallax mapping
12985
+
12986
+ "DP3 temp2.x, V, eye;" +
12987
+ "DP3 temp2.y, U, eye;" +
12988
+ "DP3 temp2.z, normal, eye;" +
12989
+ "RCP temp2.z, temp2.z;" +
12990
+
12991
+ "DP3 temp2.w, texSamp, texSamp;" + // Height
12992
+ "RSQ temp2.w, temp2.w;" +
12993
+ "RCP temp2.w, temp2.w;" +
12994
+
12995
+ "SUB temp2.w, temp2.w, half;" +
12996
+ // "SGE temp.x, temp2.w, eps.x;" +
12997
+ // "MUL temp2.w, temp2.w, temp.x;" +
12998
+
12999
+ // "MOV texSamp, U;" +
13000
+
13001
+ "MUL temp2.z, temp2.z, temp2.w;" +
13002
+ "MUL temp2.z, temp2.z, params7.z;" + // parallax
13003
+
13004
+ "MUL temp2, temp2, temp2.z;" +
13005
+
13006
+ "SUB temp, temp, temp2;" +
13007
+
13008
+ "TEX temp, temp, texture[0], 2D;" +
13009
+ "POW temp.a, temp.a, params6.w;" + // punch through
13010
+
13011
+ "ADD texSamp, temp, texSamp;" +
13012
+ "MUL texSamp.xyz, half, texSamp;" +
13013
+
13014
+ "MOV alpha, texSamp.aaaa;" +
13015
+
13016
+// parallax mapping
13017
+
13018
+ "MOV temp.x, texSamp.a;" +
13019
+ "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
13020
+ //"LRP texSamp0, params5.x, texSamp0, one;" +
13021
+ "MOV texSamp.a, temp.x;" +
1197213022
1197313023 //"MOV temp, fragment.texcoord[0];" +
1197413024 //
....@@ -12098,10 +13148,10 @@
1209813148 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1209913149 "") +
1210013150
12101
- // display shadow only (bump == 0)
13151
+ // display shadow only (fakedepth == 0)
1210213152 "SUB temp.x, half.x, shadow.x;" +
12103
- "MOV temp.y, -params6.x;" +
12104
- "SLT temp.z, temp.y, zero.x;" +
13153
+ "MOV temp.y, -params5.z;" + // params6.x;" +
13154
+ "SLT temp.z, temp.y, -c256i.x;" +
1210513155 "SUB temp.y, one.x, temp.z;" +
1210613156 "MUL temp.x, temp.x, temp.y;" +
1210713157 "KIL temp.x;" +
....@@ -12230,8 +13280,10 @@
1223013280 "MAX ndotl.x, ndotl.x, -ndotl.x;" +
1223113281
1223213282 "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
13283
+ // Tuning for default skin
13284
+ //"ADD temp.x, temp.x, options2.z;" + // lightsheen
13285
+ "MAD temp.x, options2.z, half.y, temp.x;" + // lightsheen
13286
+ "ADD temp.y, one.y, options2.y;" + // subsurface
1223513287 "MUL temp.x, temp.x, temp.y;" +
1223613288
1223713289 "MUL saturation, saturation, temp.xxxx;" +
....@@ -12430,8 +13482,19 @@
1243013482 //once = true;
1243113483 }
1243213484
12433
- System.out.print("Program #" + mode + "; length = " + program.length());
12434
- System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13485
+ String program = programmax;
13486
+
13487
+ if (Globals.MINSHADER)
13488
+ {
13489
+ program = programmin;
13490
+ }
13491
+
13492
+ if (Globals.DEBUG)
13493
+ {
13494
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13495
+ System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13496
+ }
13497
+
1243513498 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1243613499
1243713500 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -12478,7 +13541,8 @@
1247813541 "\n" +
1247913542 "END\n";
1248013543
12481
- System.out.println("Program shadow #" + 0 + "; length = " + program.length());
13544
+ if (Globals.DEBUG)
13545
+ System.out.println("Program shadow #" + 0 + "; length = " + program.length());
1248213546 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1248313547
1248413548 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -12523,25 +13587,26 @@
1252313587 return out;
1252413588 }
1252513589
12526
- String TextureFetch(String dest, String src, String unit)
13590
+ // Also does frustum culling
13591
+ String ShadowTextureFetch(String dest, String src, String unit)
1252713592 {
1252813593 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1252913594 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1253013595 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13596
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13597
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1253113598 "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;" +
13599
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13600
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1253613601 //"SWZ buffer, temp, w,w,w,w;";
12537
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13602
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1253813603 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1253913604 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1254013605 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
12541
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13606
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1254213607
12543
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
12544
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13608
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13609
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1254513610 }
1254613611
1254713612 String Shadow(String depth, String shadow)
....@@ -12563,12 +13628,16 @@
1256313628
1256413629 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1256513630 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13631
+
13632
+ // Compare fragment depth in light space with shadowmap.
1256613633 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1256713634 "SGE temp.y, temp.x, zero.x;" +
12568
- "SUB " + shadow + ".y, one.x, temp.y;" +
13635
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13636
+
13637
+ // Reverse comparison
1256913638 "SUB temp.x, one.x, temp.x;" +
1257013639 "MUL " + shadow + ".x, temp.x, temp.y;" +
12571
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13640
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1257213641 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1257313642
1257413643 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -12582,6 +13651,10 @@
1258213651 // No shadow for backface
1258313652 "DP3 temp.x, normal, lightd;" +
1258413653 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13654
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13655
+
13656
+ // No shadow when out of frustum
13657
+ "SGE temp.x, " + depth + ".z, one.z;" +
1258513658 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1258613659 "";
1258713660 }
....@@ -12727,8 +13800,9 @@
1272713800 /*static*/ float[] modelParams4 = new float[]{0, 0, 0, 0}; // anisoV, cameralight, selfshadow, shadow
1272813801 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1272913802 /*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;
13803
+ /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power, parallax
13804
+
13805
+ //Object3D.cVector2[] vector2buffer;
1273213806
1273313807 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1273413808 // OUT : diff, spec
....@@ -12744,9 +13818,10 @@
1274413818 "DP3 " + dest + ".z," + "normals," + "eye;" +
1274513819 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1274613820 //"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;" +
13821
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13822
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13823
+
13824
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1275013825 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1275113826 "RCP " + dest + ".w," + dest + ".w;" +
1275213827 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -12892,7 +13967,7 @@
1289213967 "PARAM p[4] = { state.matrix.projection }; # modelview projection matrix\n" +
1289313968 "PARAM zero = { 0.0, 0.0, 0.0, 1.0 };" +
1289413969 "PARAM half = { 0.5, 0.5, 0.5, 1.0 };" +
12895
- "PARAM one = { 1.0, 1.0, 1.0, 0.0 };" +
13970
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
1289613971 "PARAM two = { 2.0, 2.0, 2.0, 1.0 };" +
1289713972 "PARAM third = { 0.33333333333, 0.33333333333, 0.33333333333, 1.0 };" +
1289813973 //"PARAM v256 = { 256.0, 256.0, 256.0, 1.0 };" +
....@@ -12953,7 +14028,7 @@
1295314028 "DP4 temp.x,state.matrix.texture[0].inverse.row[0],vertex.texcoord;" +
1295414029 "DP4 temp.y,state.matrix.texture[0].inverse.row[1],vertex.texcoord;" +
1295514030 "DP4 temp.z,state.matrix.texture[0].inverse.row[2],vertex.texcoord;" +
12956
- //"MOV result.texcoord, vertex.texcoord;" +
14031
+ //"MOV result.texcoord, vertex.fogcoord;" +
1295714032 "MOV result.texcoord, temp;" +
1295814033 // border fade
1295914034 "MOV result.texcoord[3], vertex.texcoord;" +
....@@ -13000,7 +14075,9 @@
1300014075
1300114076 //"ADD temp.z, temp.z, one;" +
1300214077
13003
- "MOV result.color, temp;"
14078
+ "MOV result.texcoord[4], vertex.attrib[4];" + // U dir
14079
+
14080
+ "MOV result.color, temp;" // Normal
1300414081 : "MOV result.color, vertex.color;") +
1300514082 ((mode & VP_PROJECTION) != 0 ? "MOV result.color, zero;"
1300614083 : "") +
....@@ -13140,7 +14217,7 @@
1314014217 public void mousePressed(MouseEvent e)
1314114218 {
1314214219 //System.out.println("mousePressed: " + e);
13143
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14220
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1314414221 }
1314514222
1314614223 static long prevtime = 0;
....@@ -13167,6 +14244,7 @@
1316714244
1316814245 //System.err.println("Dtime = " + Dtime + "; units = " + e.getUnitsToScroll() + "; ratio (units/ms) = " + ratio);
1316914246
14247
+ if (BUTTONLESSWHEEL)
1317014248 if (Math.abs(ratio) < 0.1 || Math.abs(Dtime) == 0) // < 30)
1317114249 {
1317214250 return;
....@@ -13175,7 +14253,7 @@
1317514253 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
1317614254
1317714255 // TIMER
13178
- if (!wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
14256
+ if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
1317914257 {
1318014258 keepboxmode = BOXMODE;
1318114259 keepsupport = SUPPORT;
....@@ -13215,8 +14293,8 @@
1321514293 // mode |= META;
1321614294 //}
1321714295
13218
- SetMouseMode(WHEEL | e.getModifiersEx());
13219
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14296
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14297
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1322014298 anchorX = ax;
1322114299 anchorY = ay;
1322214300 prevX = px;
....@@ -13250,6 +14328,7 @@
1325014328 else
1325114329 if (evt.getSource() == AAtimer)
1325214330 {
14331
+ Globals.TIMERRUNNING = false;
1325314332 if (mouseDown)
1325414333 {
1325514334 //new Exception().printStackTrace();
....@@ -13275,6 +14354,10 @@
1327514354 // LIVE = waslive;
1327614355 // wasliveok = true;
1327714356 // waslive = false;
14357
+
14358
+ // May 2019 Forget it:
14359
+ if (true)
14360
+ return;
1327814361
1327914362 // source == timer
1328014363 if (mouseDown)
....@@ -13305,7 +14388,7 @@
1330514388
1330614389 // fev 2014???
1330714390 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13308
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14391
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1330914392 pingthread.StepToTarget(true); // true);
1331014393 }
1331114394 // if (!LIVE)
....@@ -13314,12 +14397,13 @@
1331414397
1331514398 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1331614399
13317
- void clickStart(int x, int y, int modifiers)
14400
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1331814401 {
1331914402 if (!wasliveok)
1332014403 return;
1332114404
1332214405 AAtimer.restart(); //
14406
+ Globals.TIMERRUNNING = true;
1332314407
1332414408 // waslive = LIVE;
1332514409 // LIVE = false;
....@@ -13331,7 +14415,7 @@
1333114415 // touched = true; // main DL
1333214416 if (isRenderer)
1333314417 {
13334
- SetMouseMode(modifiers);
14418
+ SetMouseMode(modifiers, modifiersex);
1333514419 }
1333614420
1333714421 selectX = anchorX = x;
....@@ -13344,7 +14428,7 @@
1334414428 clicked = true;
1334514429 hold = false;
1334614430
13347
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14431
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1334814432 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1334914433 {
1335014434 // System.out.println("RESTART II " + modifiers);
....@@ -13369,14 +14453,15 @@
1336914453 drag = false;
1337014454 //System.out.println("Mouse DOWN");
1337114455 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);
14456
+ //ClickInfo info = new ClickInfo();
14457
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14458
+ object.clickInfo.pane = this;
14459
+ object.clickInfo.camera = renderCamera;
14460
+ object.clickInfo.x = x;
14461
+ object.clickInfo.y = y;
14462
+ object.clickInfo.modifiers = modifiersex;
14463
+ editObj = object.doEditClick(//info,
14464
+ 0);
1338014465 if (!editObj)
1338114466 {
1338214467 hasMarquee = true;
....@@ -13392,11 +14477,14 @@
1339214477
1339314478 public void mouseDragged(MouseEvent e)
1339414479 {
14480
+ Globals.MOUSEDRAGGED = true;
14481
+
14482
+ //System.out.println("mouseDragged: " + e);
1339514483 if (isRenderer)
1339614484 movingcamera = true;
14485
+
1339714486 //if (drawing)
1339814487 //return;
13399
- //System.out.println("mouseDragged: " + e);
1340014488 if ((e.getModifiersEx() & CTRL) != 0
1340114489 || (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen())
1340214490 {
....@@ -13404,7 +14492,7 @@
1340414492 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1340514493 }
1340614494 else
13407
- drag(e.getX(), e.getY(), e.getModifiersEx());
14495
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1340814496
1340914497 //try { Thread.sleep(1); } catch (Exception ex) {}
1341014498 }
....@@ -13577,6 +14665,7 @@
1357714665
1357814666 public void run()
1357914667 {
14668
+ new Exception().printStackTrace();
1358014669 System.exit(0);
1358114670 for (;;)
1358214671 {
....@@ -13640,26 +14729,32 @@
1364014729 {
1364114730 Globals.lighttouched = true;
1364214731 }
13643
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14732
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1364414733 }
1364514734 //else
1364614735 }
1364714736 }
1364814737 }
1364914738 PingThread pingthread = new PingThread();
13650
- int delta = 5;
13651
- int speed = 5;
14739
+ int delta = 2;
14740
+ int speed = 10;
1365214741 boolean autorepeat = false;
1365314742
1365414743 void GoDown(int mod)
1365514744 {
1365614745 MODIFIERS |= COMMAND;
13657
- /*
14746
+ boolean isVR = (mouseMode&VR)!=0;
14747
+ /**/
1365814748 if((mod&SHIFT) == SHIFT)
13659
- manipCamera.RotatePosition(0, -speed);
14749
+ {
14750
+ if (isVR)
14751
+ manipCamera.RotateInterest(0, -speed);
14752
+ else
14753
+ manipCamera.RotatePosition(0, -speed);
14754
+ }
1366014755 else
13661
- manipCamera.BackForth(0, -speed*delta, getWidth());
13662
- */
14756
+ manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth());
14757
+ /**/
1366314758 if ((mod & SHIFT) == SHIFT)
1366414759 {
1366514760 mouseMode = mouseMode; // VR??
....@@ -13668,6 +14763,8 @@
1366814763 mouseMode |= BACKFORTH;
1366914764 }
1367014765
14766
+ targetLookAt.set(manipCamera.lookAt);
14767
+
1367114768 //prevX = X = anchorX;
1367214769 prevY = Y = anchorY - (int) (renderCamera.Distance());
1367314770 }
....@@ -13675,12 +14772,19 @@
1367514772 void GoUp(int mod)
1367614773 {
1367714774 MODIFIERS |= COMMAND;
13678
- /*
14775
+ /**/
14776
+ boolean isVR = (mouseMode&VR)!=0;
14777
+
1367914778 if((mod&SHIFT) == SHIFT)
13680
- manipCamera.RotatePosition(0, speed);
14779
+ {
14780
+ if (isVR)
14781
+ manipCamera.RotateInterest(0, speed);
14782
+ else
14783
+ manipCamera.RotatePosition(0, speed);
14784
+ }
1368114785 else
13682
- manipCamera.BackForth(0, speed*delta, getWidth());
13683
- */
14786
+ manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth());
14787
+ /**/
1368414788 if ((mod & SHIFT) == SHIFT)
1368514789 {
1368614790 mouseMode = mouseMode;
....@@ -13689,6 +14793,8 @@
1368914793 mouseMode |= BACKFORTH;
1369014794 }
1369114795
14796
+ targetLookAt.set(manipCamera.lookAt);
14797
+
1369214798 //prevX = X = anchorX;
1369314799 prevY = Y = anchorY + (int) (renderCamera.Distance());
1369414800 }
....@@ -13696,12 +14802,17 @@
1369614802 void GoLeft(int mod)
1369714803 {
1369814804 MODIFIERS |= COMMAND;
13699
- /*
14805
+ /**/
1370014806 if((mod&SHIFT) == SHIFT)
13701
- manipCamera.RotatePosition(speed, 0);
14807
+ manipCamera.Translate(speed*delta, 0, getWidth());
1370214808 else
13703
- manipCamera.Translate(speed*delta, 0, getWidth());
13704
- */
14809
+ {
14810
+ if ((mouseMode&VR)!=0)
14811
+ manipCamera.RotateInterest(-speed, 0);
14812
+ else
14813
+ manipCamera.RotatePosition(speed, 0);
14814
+ }
14815
+ /**/
1370514816 if ((mod & SHIFT) == SHIFT)
1370614817 {
1370714818 mouseMode = mouseMode;
....@@ -13710,6 +14821,8 @@
1371014821 mouseMode |= ROTATE;
1371114822 } // TRANSLATE;
1371214823
14824
+ targetLookAt.set(manipCamera.lookAt);
14825
+
1371314826 prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance());
1371414827 prevY = Y = anchorY;
1371514828 }
....@@ -13717,12 +14830,18 @@
1371714830 void GoRight(int mod)
1371814831 {
1371914832 MODIFIERS |= COMMAND;
13720
- /*
14833
+ /**/
1372114834 if((mod&SHIFT) == SHIFT)
13722
- manipCamera.RotatePosition(-speed, 0);
14835
+ manipCamera.Translate(-speed*delta, 0, getWidth());
1372314836 else
13724
- manipCamera.Translate(-speed*delta, 0, getWidth());
13725
- */
14837
+ {
14838
+ if ((mouseMode&VR)!=0)
14839
+ manipCamera.RotateInterest(speed, 0);
14840
+ else
14841
+ manipCamera.RotatePosition(-speed, 0);
14842
+ }
14843
+
14844
+ /**/
1372614845 if ((mod & SHIFT) == SHIFT)
1372714846 {
1372814847 mouseMode = mouseMode;
....@@ -13731,6 +14850,8 @@
1373114850 mouseMode |= ROTATE;
1373214851 } // TRANSLATE;
1373314852
14853
+ targetLookAt.set(manipCamera.lookAt);
14854
+
1373414855 prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance());
1373514856 prevY = Y = anchorY;
1373614857 }
....@@ -13740,7 +14861,7 @@
1374014861 int X, Y;
1374114862 boolean SX, SY;
1374214863
13743
- void drag(int x, int y, int modifiers)
14864
+ void drag(int x, int y, int modifiers, int modifiersex)
1374414865 {
1374514866 if (IsFrozen())
1374614867 {
....@@ -13749,17 +14870,17 @@
1374914870
1375014871 drag = true; // NEW
1375114872
13752
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14873
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1375314874
1375414875 X = x;
1375514876 Y = y;
1375614877 // floating state for animation
13757
- MODIFIERS = modifiers;
13758
- modifiers &= ~1024;
14878
+ MODIFIERS = modifiersex;
14879
+ modifiersex &= ~1024;
1375914880 if (false) // modifiers != 0)
1376014881 {
1376114882 //new Exception().printStackTrace();
13762
- System.out.println("mouseDragged: " + modifiers);
14883
+ System.out.println("mouseDragged: " + modifiersex);
1376314884 System.out.println("SHIFT = " + SHIFT);
1376414885 System.out.println("CONTROL = " + COMMAND);
1376514886 System.out.println("META = " + META);
....@@ -13772,14 +14893,16 @@
1377214893 if (editObj)
1377314894 {
1377414895 drag = true;
13775
- ClickInfo info = new ClickInfo();
13776
- info.bounds.setBounds(0, 0,
14896
+ //ClickInfo info = new ClickInfo();
14897
+ object.clickInfo.bounds.setBounds(0, 0,
1377714898 (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);
14899
+ object.clickInfo.pane = this;
14900
+ object.clickInfo.camera = renderCamera;
14901
+ object.clickInfo.x = x;
14902
+ object.clickInfo.y = y;
14903
+ object //.GetWindow().copy
14904
+ .doEditDrag(//info,
14905
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1378314906 } else
1378414907 {
1378514908 if (x < startX)
....@@ -13928,23 +15051,27 @@
1392815051 }
1392915052 }
1393015053
15054
+// ClickInfo clickInfo = new ClickInfo();
15055
+
1393115056 public void mouseMoved(MouseEvent e)
1393215057 {
1393315058 //System.out.println("mouseMoved: " + e);
13934
-
1393515059 if (isRenderer)
1393615060 return;
1393715061
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;
15062
+ // Mouse cursor feedback
15063
+ object.clickInfo.x = e.getX();
15064
+ object.clickInfo.y = e.getY();
15065
+ object.clickInfo.modifiers = e.getModifiersEx();
15066
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
15067
+ object.clickInfo.pane = this;
15068
+ object.clickInfo.camera = renderCamera;
1394515069 if (!isRenderer)
1394615070 {
13947
- if (object.editWindow.copy.doEditClick(ci, 0))
15071
+ //ObjEditor editWindow = object.editWindow;
15072
+ //Object3D copy = editWindow.copy;
15073
+ if (object.doEditClick(//clickInfo,
15074
+ 0))
1394815075 {
1394915076 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1395015077 } else
....@@ -13956,7 +15083,11 @@
1395615083
1395715084 public void mouseReleased(MouseEvent e)
1395815085 {
15086
+ Globals.MOUSEDRAGGED = false;
15087
+
1395915088 movingcamera = false;
15089
+ X = 0; // getBounds().width/2;
15090
+ Y = 0; // getBounds().height/2;
1396015091 //System.out.println("mouseReleased: " + e);
1396115092 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1396215093 }
....@@ -13979,9 +15110,9 @@
1397915110 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1398015111 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1398115112
13982
- if (control || command || IsFrozen())
15113
+// No delay if (control || command || IsFrozen())
1398315114 timeout = true;
13984
- else
15115
+// ?? May 2019 else
1398515116 // timer.setDelay((modifiers & 128) != 0?0:350);
1398615117 mouseDown = false;
1398715118 if (!control && !command) // june 2013
....@@ -14091,7 +15222,7 @@
1409115222 System.out.println("keyReleased: " + e);
1409215223 }
1409315224
14094
- void SetMouseMode(int modifiers)
15225
+ void SetMouseMode(int modifiers, int modifiersex)
1409515226 {
1409615227 //System.out.println("SetMouseMode = " + modifiers);
1409715228 //modifiers &= ~1024;
....@@ -14103,25 +15234,25 @@
1410315234 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1410415235 // return;
1410515236 //System.out.println("SetMode = " + modifiers);
14106
- if ((modifiers & WHEEL) == WHEEL)
15237
+ if ((modifiersex & WHEEL) == WHEEL)
1410715238 {
1410815239 mouseMode |= ZOOM;
1410915240 }
1411015241
1411115242 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
14112
- if (capsLocked || (modifiers & META) == META)
15243
+ if (capsLocked) // || (modifiers & META) == META)
1411315244 {
1411415245 mouseMode |= VR; // BACKFORTH;
1411515246 }
14116
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
15247
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1411715248 {
1411815249 mouseMode |= SELECT;
1411915250 }
14120
- if ((modifiers & COMMAND) == COMMAND)
15251
+ if ((modifiersex & COMMAND) == COMMAND)
1412115252 {
1412215253 mouseMode |= SELECT;
1412315254 }
14124
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15255
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
1412515256 {
1412615257 mouseMode &= ~VR;
1412715258 mouseMode |= TRANSLATE;
....@@ -14150,10 +15281,10 @@
1415015281
1415115282 if (isRenderer) //
1415215283 {
14153
- SetMouseMode(modifiers);
15284
+ SetMouseMode(0, modifiers);
1415415285 }
1415515286
14156
- theRenderer.keyPressed(key);
15287
+ Globals.theRenderer.keyPressed(key);
1415715288 }
1415815289
1415915290 int kompactbit = 4; // power bit
....@@ -14165,7 +15296,7 @@
1416515296 float SATPOW = 1; // 2; // 0.5f;
1416615297 float BRIPOW = 1; // 0.5f; // 0.5f;
1416715298
14168
- void keyPressed(int key)
15299
+ public void keyPressed(int key)
1416915300 {
1417015301 if (key >= '0' && key <= '5')
1417115302 clampbit = (key-'0');
....@@ -14212,7 +15343,8 @@
1421215343 // break;
1421315344 case 'T':
1421415345 CACHETEXTURE ^= true;
14215
- textures.clear();
15346
+ texturepigment.clear();
15347
+ texturebump.clear();
1421615348 // repaint();
1421715349 break;
1421815350 case 'Y':
....@@ -14222,8 +15354,8 @@
1422215354 case 'K':
1422315355 KOMPACTTEXTURE ^= true;
1422415356 //textures.clear();
14225
- break;
14226
- case 'P': // Texture Projection macros
15357
+ // break;
15358
+ //case 'P': // Texture Projection macros
1422715359 // SAVETEXTURE ^= true;
1422815360 macromode = true;
1422915361 Udebug = Vdebug = NORMALdebug = false; programInitialized = false;
....@@ -14297,7 +15429,9 @@
1429715429 case 'E' : COMPACT ^= true;
1429815430 repaint();
1429915431 break;
14300
- case 'W' : DEBUGHSB ^= true;
15432
+ case 'W' : // Wide Window (fullscreen)
15433
+ //DEBUGHSB ^= true;
15434
+ ObjEditor.theFrame.ToggleFullScreen();
1430115435 repaint();
1430215436 break;
1430315437 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14322,8 +15456,8 @@
1432215456 RevertCamera();
1432315457 repaint();
1432415458 break;
14325
- case 'L':
1432615459 case 'l':
15460
+ //case 'L':
1432715461 if (lightMode)
1432815462 {
1432915463 lightMode = false;
....@@ -14342,7 +15476,7 @@
1434215476 targetLookAt.set(manipCamera.lookAt);
1434315477 repaint();
1434415478 break;
14345
- case 'p':
15479
+ case 'P': // p':
1434615480 // c'est quoi ca au juste? spherical ^= true;
1434715481 Skinshader ^= true; programInitialized = false;
1434815482 repaint();
....@@ -14380,27 +15514,31 @@
1438015514 repaint();
1438115515 break;
1438215516 case 'O':
14383
- Globals.drawMode = OCCLUSION; // WARNING
15517
+ // Too dangerous. Use menu. Globals.drawMode = OCCLUSION; // WARNING
1438415518 repaint();
1438515519 break;
1438615520 case 'o':
1438715521 OCCLUSION_CULLING ^= true;
1438815522 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1438915523 break;
14390
- case '0': envyoff ^= true; repaint(); break;
15524
+ //case '0': envyoff ^= true; repaint(); break;
1439115525 case '1':
1439215526 case '2':
1439315527 case '3':
1439415528 case '4':
1439515529 case '5':
14396
- newenvy = Character.getNumericValue(key);
14397
- repaint();
14398
- break;
1439915530 case '6':
1440015531 case '7':
1440115532 case '8':
1440215533 case '9':
14403
- BGcolor = (key - '6')/3.f;
15534
+ if (true) // envyoff)
15535
+ {
15536
+ BGcolor = (key - '1')/8.f;
15537
+ }
15538
+ else
15539
+ {
15540
+ //newenvy = Character.getNumericValue(key);
15541
+ }
1440415542 repaint();
1440515543 break;
1440615544 case '!':
....@@ -14466,9 +15604,9 @@
1446615604 case '_':
1446715605 kompactbit = 5;
1446815606 break;
14469
- case '+':
14470
- kompactbit = 6;
14471
- break;
15607
+// case '+':
15608
+// kompactbit = 6;
15609
+// break;
1447215610 case ' ':
1447315611 lightMode ^= true;
1447415612 Globals.lighttouched = true;
....@@ -14480,13 +15618,14 @@
1448015618 case ESC:
1448115619 RENDERPROGRAM += 1;
1448215620 RENDERPROGRAM %= 3;
15621
+
1448315622 repaint();
1448415623 break;
1448515624 case 'Z':
1448615625 //RESIZETEXTURE ^= true;
1448715626 //break;
1448815627 case 'z':
14489
- RENDERSHADOW ^= true;
15628
+ Globals.RENDERSHADOW ^= true;
1449015629 Globals.lighttouched = true;
1449115630 repaint();
1449215631 break;
....@@ -14519,8 +15658,9 @@
1451915658 case DELETE:
1452015659 ClearSelection();
1452115660 break;
14522
- /*
1452315661 case '+':
15662
+
15663
+ /*
1452415664 //fontsize += 1;
1452515665 bbzoom *= 2;
1452615666 repaint();
....@@ -14537,17 +15677,17 @@
1453715677 case '=':
1453815678 IncDepth();
1453915679 //fontsize += 1;
14540
- object.editWindow.refreshContents(true);
15680
+ object.GetWindow().refreshContents(true);
1454115681 maskbit = 6;
1454215682 break;
1454315683 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1454415684 DecDepth();
1454515685 maskbit = 5;
1454615686 //if(fontsize > 1) fontsize -= 1;
14547
- if (object.editWindow == null)
14548
- new Exception().printStackTrace();
14549
- else
14550
- object.editWindow.refreshContents(true);
15687
+// if (object.editWindow == null)
15688
+// new Exception().printStackTrace();
15689
+// else
15690
+ object.GetWindow().refreshContents(true);
1455115691 break;
1455215692 case '{':
1455315693 manipCamera.shaper_fovy /= 1.1;
....@@ -14602,6 +15742,7 @@
1460215742 }
1460315743 //System.out.println("shaper_fovy = " + manipCamera.shaper_fovy);
1460415744 }
15745
+
1460515746 static double OCCLUSIONBOOST = 1; // 0.5;
1460615747
1460715748 void keyReleased(int key, int modifiers)
....@@ -14609,11 +15750,11 @@
1460915750 //mode = ROTATE;
1461015751 if ((MODIFIERS & COMMAND) == 0) // VR??
1461115752 {
14612
- SetMouseMode(modifiers);
15753
+ SetMouseMode(0, modifiers);
1461315754 }
1461415755 }
1461515756
14616
- protected void processKeyEvent(KeyEvent e)
15757
+ public void processKeyEvent(KeyEvent e)
1461715758 {
1461815759 switch (e.getID())
1461915760 {
....@@ -14743,8 +15884,9 @@
1474315884
1474415885 protected void processMouseMotionEvent(MouseEvent e)
1474515886 {
14746
- //System.out.println("processMouseMotionEvent: " + mouseMode);
14747
- if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15887
+ //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
15888
+ //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15889
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1474815890 {
1474915891 mouseMoved(e);
1475015892 } else
....@@ -14769,11 +15911,12 @@
1476915911 }
1477015912 */
1477115913
14772
- object.editWindow.EditSelection();
15914
+ object.GetWindow().EditSelection(false);
1477315915 }
1477415916
1477515917 void SelectParent()
1477615918 {
15919
+ new Exception().printStackTrace();
1477715920 System.exit(0);
1477815921 Composite group = (Composite) object;
1477915922 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -14785,10 +15928,10 @@
1478515928 {
1478615929 //selectees.remove(i);
1478715930 System.out.println("select parent of " + elem);
14788
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15931
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1478915932 } else
1479015933 {
14791
- group.editWindow.Select(elem.GetTreePath(), first, true);
15934
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1479215935 }
1479315936
1479415937 first = false;
....@@ -14797,6 +15940,7 @@
1479715940
1479815941 void SelectChildren()
1479915942 {
15943
+ new Exception().printStackTrace();
1480015944 System.exit(0);
1480115945 /*
1480215946 Composite group = (Composite) object;
....@@ -14829,12 +15973,12 @@
1482915973 for (int j = 0; j < group.children.size(); j++)
1483015974 {
1483115975 elem = (Object3D) group.children.elementAt(j);
14832
- object.editWindow.Select(elem.GetTreePath(), first, true);
15976
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1483315977 first = false;
1483415978 }
1483515979 } else
1483615980 {
14837
- object.editWindow.Select(elem.GetTreePath(), first, true);
15981
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1483815982 }
1483915983
1484015984 first = false;
....@@ -14845,21 +15989,21 @@
1484515989 {
1484615990 //Composite group = (Composite) object;
1484715991 Object3D group = object;
14848
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15992
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1484915993 }
1485015994
1485115995 void ResetTransform(int mask)
1485215996 {
1485315997 //Composite group = (Composite) object;
1485415998 Object3D group = object;
14855
- group.editWindow.ResetTransform(mask);
15999
+ group.GetWindow().ResetTransform(mask);
1485616000 }
1485716001
1485816002 void FlipTransform()
1485916003 {
1486016004 //Composite group = (Composite) object;
1486116005 Object3D group = object;
14862
- group.editWindow.FlipTransform();
16006
+ group.GetWindow().FlipTransform();
1486316007 // group.editWindow.ReduceMesh(true);
1486416008 }
1486516009
....@@ -14867,7 +16011,7 @@
1486716011 {
1486816012 //Composite group = (Composite) object;
1486916013 Object3D group = object;
14870
- group.editWindow.PrintMemory();
16014
+ group.GetWindow().PrintMemory();
1487116015 // group.editWindow.ReduceMesh(true);
1487216016 }
1487316017
....@@ -14875,7 +16019,7 @@
1487516019 {
1487616020 //Composite group = (Composite) object;
1487716021 Object3D group = object;
14878
- group.editWindow.ResetCentroid();
16022
+ group.GetWindow().ResetCentroid();
1487916023 }
1488016024
1488116025 void IncDepth()
....@@ -14957,11 +16101,11 @@
1495716101
1495816102 int width = getBounds().width;
1495916103 int height = getBounds().height;
14960
- ClickInfo info = new ClickInfo();
14961
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1496216104 //Image img = CreateImage(width, height);
1496316105 //System.out.println("width = " + width + "; height = " + height + "\n");
16106
+
1496416107 Graphics gr = g; // img.getGraphics();
16108
+
1496516109 if (!hasMarquee)
1496616110 {
1496716111 if (Xmin < Xmax) // !locked)
....@@ -15033,44 +16177,92 @@
1503316177 }
1503416178 if (object != null && !hasMarquee)
1503516179 {
16180
+ if (object.clickInfo == null)
16181
+ object.clickInfo = new ClickInfo();
16182
+ ClickInfo info = object.clickInfo;
16183
+ //ClickInfo info = new ClickInfo();
16184
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16185
+
1503616186 if (isRenderer)
1503716187 {
15038
- info.flags++;
16188
+ object.clickInfo.flags++;
1503916189 double frameAspect = (double) width / (double) height;
1504016190 if (frameAspect > renderCamera.aspect)
1504116191 {
1504216192 int desired = (int) ((double) height * renderCamera.aspect);
15043
- info.bounds.width -= width - desired;
15044
- info.bounds.x += (width - desired) / 2;
16193
+ object.clickInfo.bounds.width -= width - desired;
16194
+ object.clickInfo.bounds.x += (width - desired) / 2;
1504516195 } else
1504616196 {
1504716197 int desired = (int) ((double) width / renderCamera.aspect);
15048
- info.bounds.height -= height - desired;
15049
- info.bounds.y += (height - desired) / 2;
16198
+ object.clickInfo.bounds.height -= height - desired;
16199
+ object.clickInfo.bounds.y += (height - desired) / 2;
1505016200 }
1505116201 }
15052
- info.g = gr;
15053
- info.camera = renderCamera;
16202
+
16203
+ object.clickInfo.g = gr;
16204
+ object.clickInfo.camera = renderCamera;
1505416205 /*
1505516206 // Memory intensive (brep.verticescopy)
1505616207 if (!(object instanceof Composite))
1505716208 object.draw(info, 0, false); // SLOW :
1505816209 */
15059
- if (!isRenderer)
16210
+ if (!isRenderer) // && drag)
1506016211 {
15061
- object.drawEditHandles(info, 0);
16212
+ Grafreed.Assert(object != null);
16213
+ Grafreed.Assert(object.selection != null);
16214
+ if (object.selection.Size() > 0)
16215
+ {
16216
+ int hitSomething = object.selection.get(0).hitSomething;
16217
+
16218
+ object.clickInfo.DX = 0;
16219
+ object.clickInfo.DY = 0;
16220
+ object.clickInfo.W = 1;
16221
+ if (hitSomething == Object3D.hitCenter)
16222
+ {
16223
+ info.DX = X;
16224
+ if (X != 0)
16225
+ info.DX -= info.bounds.width/2;
16226
+
16227
+ info.DY = Y;
16228
+ if (Y != 0)
16229
+ info.DY -= info.bounds.height/2;
16230
+ }
16231
+
16232
+ object.drawEditHandles(//info,
16233
+ 0);
16234
+
16235
+ if (drag && (X != 0 || Y != 0))
16236
+ {
16237
+ switch (hitSomething)
16238
+ {
16239
+ case Object3D.hitCenter: gr.setColor(Color.white);
16240
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16241
+ break;
16242
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16243
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16244
+ break;
16245
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16246
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16247
+ break;
16248
+ }
16249
+
16250
+ }
16251
+ }
1506216252 }
1506316253 }
16254
+
1506416255 if (isRenderer)
1506516256 {
1506616257 //gr.setColor(Color.black);
1506716258 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1506816259 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1506916260 }
16261
+
1507016262 if (hasMarquee)
1507116263 {
1507216264 gr.setXORMode(Color.white);
15073
- gr.setColor(Color.red);
16265
+ gr.setColor(Color.white);
1507416266 if (!firstime)
1507516267 {
1507616268 gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH);
....@@ -15179,6 +16371,7 @@
1517916371 public boolean mouseDown(Event evt, int x, int y)
1518016372 {
1518116373 System.out.println("mouseDown: " + evt);
16374
+ System.exit(0);
1518216375 /*
1518316376 locked = true;
1518416377 drag = false;
....@@ -15222,7 +16415,7 @@
1522216415 {
1522316416 keyPressed(0, modifiers);
1522416417 }
15225
- clickStart(x, y, modifiers);
16418
+ // clickStart(x, y, modifiers);
1522616419 return true;
1522716420 }
1522816421
....@@ -15340,7 +16533,7 @@
1534016533 {
1534116534 keyReleased(0, 0);
1534216535 }
15343
- drag(x, y, modifiers);
16536
+ drag(x, y, 0, modifiers);
1534416537 return true;
1534516538 }
1534616539
....@@ -15472,7 +16665,7 @@
1547216665 Object3D object;
1547316666 static Object3D trackedobject;
1547416667 Camera renderCamera; // Light or Eye (or Occlusion)
15475
- /*static*/ Camera manipCamera; // Light or Eye
16668
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1547616669 /*static*/ Camera eyeCamera;
1547716670 /*static*/ Camera lightCamera;
1547816671 int cameracount;
....@@ -15536,6 +16729,8 @@
1553616729 private /*static*/ boolean firstime;
1553716730 private /*static*/ cVector newView = new cVector();
1553816731 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16732
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16733
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1553916734 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1554016735 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1554116736 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -15548,29 +16743,67 @@
1554816743 {
1554916744 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1555016745
16746
+ int usedsuf = 0;
16747
+
1555116748 for (int i = 0; i < suffixes.length; i++)
1555216749 {
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)
16750
+ String[] suffixe = suffixes;
16751
+ String[] fallback = suffixes2;
16752
+ String[] fallfallback = suffixes3;
16753
+
16754
+ for (int c=usedsuf; --c>=0;)
1555816755 {
15559
- throw new IOException("Unable to load texture " + resourceName);
16756
+// String[] temp = suffixe;
16757
+// suffixe = fallback;
16758
+// fallback = fallfallback;
16759
+// fallfallback = temp;
1556016760 }
16761
+
16762
+ String resourceName = basename + suffixe[i] + "." + suffix;
16763
+ TextureData data;
16764
+
16765
+ try
16766
+ {
16767
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16768
+ mipmapped,
16769
+ FileUtil.getFileSuffix(resourceName));
16770
+ }
16771
+ catch (Exception e)
16772
+ {
16773
+ try
16774
+ {
16775
+ resourceName = basename + fallback[i] + "." + suffix;
16776
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16777
+ mipmapped,
16778
+ FileUtil.getFileSuffix(resourceName));
16779
+ }
16780
+ catch (Exception e2)
16781
+ {
16782
+ resourceName = basename + fallfallback[i] + "." + suffix;
16783
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16784
+ mipmapped,
16785
+ FileUtil.getFileSuffix(resourceName));
16786
+ }
16787
+ }
16788
+
1556116789 //System.out.println("Target = " + targets[i]);
1556216790 cubemap.updateImage(data, targets[i]);
1556316791 }
1556416792
1556516793 return cubemap;
1556616794 }
16795
+
1556716796 int bigsphere = -1;
1556816797
1556916798 float BGcolor = 0.5f;
1557016799
15571
- private void DrawSkyBox(GL gl)
16800
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16801
+
16802
+ private void DrawSkyBox(GL gl, float ratio)
1557216803 {
15573
- if (envyoff || cubemap == null)
16804
+ if (//envyoff ||
16805
+ WIREFRAME ||
16806
+ cubemap == null)
1557416807 {
1557516808 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1557616809 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -15585,7 +16818,17 @@
1558516818 // Compensates for ExaminerViewer's modification of modelview matrix
1558616819 gl.glMatrixMode(GL.GL_MODELVIEW);
1558716820 gl.glLoadIdentity();
16821
+ gl.glScalef(1,ratio,1);
1558816822
16823
+// colorV[0] = 2;
16824
+// colorV[1] = 2;
16825
+// colorV[2] = 2;
16826
+// colorV[3] = 1;
16827
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16828
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16829
+//
16830
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16831
+
1558916832 //gl.glActiveTexture(GL.GL_TEXTURE1);
1559016833 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1559116834
....@@ -15617,6 +16860,7 @@
1561716860 {
1561816861 gl.glScalef(1.0f, -1.0f, 1.0f);
1561916862 }
16863
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1562016864 gl.glMultMatrixd(viewrot_1, 0);
1562116865 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1562216866 //viewer.updateInverseRotation(gl);
....@@ -15657,7 +16901,8 @@
1565716901 gl.glDisable(GL.GL_TEXTURE_GEN_R);
1565816902
1565916903 cubemap.disable();
15660
- ////cubemap.unbind();
16904
+ //cubemap.dispose();
16905
+
1566116906 if (CULLFACE)
1566216907 {
1566316908 gl.glEnable(gl.GL_CULL_FACE);
....@@ -15713,7 +16958,7 @@
1571316958 gl.glScalef(1.0f, -1.0f, 1.0f);
1571416959 }
1571516960
15716
- gl.glNormal3f(0.0f, 0.0f, 1.0f);
16961
+ SetGLNormal(gl, 0.0f, 0.0f, 1.0f);
1571716962
1571816963 float step = 2; // 0.1666f; //0.25f;
1571916964 float stepv = 2; // step * 1652 / 998;
....@@ -15757,16 +17002,16 @@
1575717002 cStatic.objectstack[materialdepth++] = checker;
1575817003 //System.out.println("material " + material);
1575917004 //Applet3D.tracein(this, selected);
15760
- vector2buffer = checker.projectedVertices;
17005
+ //vector2buffer = checker.projectedVertices;
1576117006
1576217007 //checker.GetMaterial().Draw(this, false); // true);
15763
- DrawMaterial(checker.GetMaterial(), false); // true);
17008
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1576417009
1576517010 materialdepth -= 1;
1576617011 if (materialdepth > 0)
1576717012 {
15768
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
15769
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
17013
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
17014
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1577017015 }
1577117016 //checker.GetMaterial().opacity = 1f;
1577217017 ////checker.GetMaterial().ambient = 1f;
....@@ -15852,6 +17097,14 @@
1585217097 }
1585317098 }
1585417099
17100
+ private Object3D GetFolder()
17101
+ {
17102
+ Object3D folder = object.GetWindow().copy;
17103
+ if (object.GetWindow().copy.selection.Size() > 0)
17104
+ folder = object.GetWindow().copy.selection.elementAt(0);
17105
+ return folder;
17106
+ }
17107
+
1585517108 class SelectBuffer implements GLEventListener
1585617109 {
1585717110
....@@ -15867,7 +17120,7 @@
1586717120 //new Exception().printStackTrace();
1586817121 System.out.println("select buffer init");
1586917122 // Use debug pipeline
15870
- drawable.setGL(new DebugGL(drawable.getGL()));
17123
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1587117124
1587217125 GL gl = drawable.getGL();
1587317126
....@@ -15910,6 +17163,7 @@
1591017163 {
1591117164 if (!selection)
1591217165 {
17166
+ new Exception().printStackTrace();
1591317167 System.exit(0);
1591417168 return;
1591517169 }
....@@ -15930,6 +17184,17 @@
1593017184
1593117185 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1593217186
17187
+ if (PAINTMODE)
17188
+ {
17189
+ if (object.GetWindow().copy.selection.Size() > 0)
17190
+ {
17191
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17192
+
17193
+ // Make what you paint not selectable.
17194
+ paintobj.ResetSelectable();
17195
+ }
17196
+ }
17197
+
1593317198 //int tmp = selection_view;
1593417199 //selection_view = -1;
1593517200 int temp = DrawMode();
....@@ -15941,6 +17206,17 @@
1594117206 // temp = DEFAULT; // patch for selection debug
1594217207 Globals.drawMode = temp; // WARNING
1594317208
17209
+ if (PAINTMODE)
17210
+ {
17211
+ if (object.GetWindow().copy.selection.Size() > 0)
17212
+ {
17213
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17214
+
17215
+ // Revert.
17216
+ paintobj.RestoreSelectable();
17217
+ }
17218
+ }
17219
+
1594417220 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1594517221
1594617222 // trying different ways of getting the depth info over
....@@ -15988,6 +17264,8 @@
1598817264 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1598917265 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1599017266 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
17267
+
17268
+ CreateSelectedPoint();
1599117269
1599217270 // Will fit the mesh !!!
1599317271 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16037,34 +17315,36 @@
1603717315 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]));
1603817316 }
1603917317
16040
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
17318
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1604117319 }
1604217320 }
1604317321
1604417322 if (!movingcamera && !PAINTMODE)
16045
- object.editWindow.ScreenFitPoint(); // fev 2014
17323
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1604617324
16047
- if (PAINTMODE && GrafreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17325
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1604817326 {
16049
- Object3D paintobj = GrafreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17327
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1605017328
16051
- Object3D group = new Object3D("inst" + paintcount++);
17329
+ if (object.GetWindow().copy.selection.Size() > 0)
17330
+ {
17331
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1605217332
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();
17333
+ Object3D inst = new Object3D("inst" + paintcount++);
17334
+
17335
+ inst.CreateMaterial(); // use a void leaf to select instances
17336
+
17337
+ inst.add(paintobj); // link
17338
+
17339
+ object.GetWindow().SnapObject(inst);
17340
+
17341
+ Object3D folder = paintFolder; // GetFolder();
17342
+
17343
+ folder.add(inst);
17344
+
17345
+ object.GetWindow().ResetModel();
17346
+ object.GetWindow().refreshContents();
17347
+ }
1606817348 }
1606917349 else
1607017350 paintcount = 0;
....@@ -16103,6 +17383,11 @@
1610317383 //System.out.println("objects[color] = " + objects[color]);
1610417384 //objects[color].Select();
1610517385 indexcount = 0;
17386
+ ObjEditor window = object.GetWindow();
17387
+ if (window != null && deselect)
17388
+ {
17389
+ window.Select(null, deselect, true);
17390
+ }
1610617391 object.Select(color, deselect);
1610717392 }
1610817393
....@@ -16153,6 +17438,7 @@
1615317438
1615417439 public void init(GLAutoDrawable drawable)
1615517440 {
17441
+ if (Globals.DEBUG)
1615617442 System.out.println("shadow buffer init");
1615717443
1615817444 GL gl = drawable.getGL();
....@@ -16202,7 +17488,7 @@
1620217488 gl.glDisable(gl.GL_CULL_FACE);
1620317489 }
1620417490
16205
- if (!RENDERSHADOW)
17491
+ if (!Globals.RENDERSHADOW)
1620617492 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1620717493
1620817494 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -16212,7 +17498,7 @@
1621217498 //gl.glColorMask(false, false, false, false);
1621317499
1621417500 //render_scene_from_light_view(gl, drawable, 0, 0);
16215
- if (RENDERSHADOW && Globals.lighttouched && !movingcamera) // && !parent.IsFreezed())
17501
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1621617502 {
1621717503 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1621817504
....@@ -16381,10 +17667,14 @@
1638117667 gl.glFlush();
1638217668
1638317669 /**/
16384
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17670
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1638517671
16386
- float[] pixels = occlusionsizebuffer.array();
17672
+ float[] depths = occlusiondepthbuffer.array();
1638717673
17674
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17675
+
17676
+ int[] pixels = selectsizebuffer.array();
17677
+
1638817678 double r = 0, g = 0, b = 0;
1638917679
1639017680 double count = 0;
....@@ -16395,7 +17685,7 @@
1639517685
1639617686 double FACTOR = 1;
1639717687
16398
- for (int i = 0; i < pixels.length; i++)
17688
+ for (int i = 0; i < depths.length; i++)
1639917689 {
1640017690 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1640117691 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -16478,7 +17768,7 @@
1647817768
1647917769 double scale = ray.z; // 1; // cos
1648017770
16481
- float depth = pixels[newindex];
17771
+ float depth = depths[newindex];
1648217772
1648317773 /*
1648417774 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -16628,23 +17918,15 @@
1662817918 int AAbuffersize = 0;
1662917919
1663017920 //double[] selectedpoint = new double[3];
16631
- static Superellipsoid selectedpoint = new Superellipsoid();
17921
+ static Superellipsoid selectedpoint;
1663217922 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();
17923
+ static Sphere debugpointG;
17924
+ static Sphere debugpointP;
17925
+ static Sphere debugpointC;
17926
+ static Sphere debugpointR;
1663717927
1663817928 static Sphere debugpoints[] = new Sphere[8];
1663917929
16640
- static
16641
- {
16642
- for (int i=0; i<8; i++)
16643
- {
16644
- debugpoints[i] = new Sphere();
16645
- }
16646
- }
16647
-
1664817930 static void InitPoints(float radius)
1664917931 {
1665017932 for (int i=0; i<8; i++)
....@@ -16683,11 +17965,14 @@
1668317965 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1668417966 static IntBuffer bigAAbuffer;
1668517967 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
16686
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17968
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1668717969 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1668817970 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1668917971 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
16690
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17972
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17973
+
17974
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17975
+
1669117976 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1669217977 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1669317978 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();
....@@ -16696,10 +17981,11 @@
1669617981 static IntBuffer textbuffer = null; // IntBuffer.allocate(TEXT_WIDTH*8*8 * TEXT_HEIGHT);
1669717982 // Depth buffer format
1669817983 //private int depth_format;
16699
- static public void NextIndex(Object3D o, GL gl)
17984
+
17985
+ public void NextIndex()
1670017986 {
1670117987 indexcount+=16;
16702
- gl.glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
17988
+ GetGL().glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
1670317989 //objects[indexcount] = o;
1670417990 //System.out.println("indexcount = " + indexcount);
1670517991 }