Normand Briere
2019-08-22 6a145f6c81dfcbe0653eda27d042efb48daa7512
CameraPane.java
....@@ -18,7 +18,10 @@
1818 import javax.imageio.ImageIO;
1919 import javax.imageio.ImageWriteParam;
2020 import javax.imageio.ImageWriter;
21
+import javax.imageio.ImageReadParam;
22
+import javax.imageio.ImageReader;
2123 import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
24
+import javax.imageio.stream.ImageInputStream;
2225 import javax.imageio.stream.ImageOutputStream;
2326 import javax.imageio.ImageWriteParam;
2427
....@@ -30,6 +33,7 @@
3033 import java.nio.*;
3134
3235 import gleem.linalg.Mat4f;
36
+import javax.imageio.ImageTypeSpecifier;
3337
3438 class CameraPane extends GLCanvas implements iCameraPane, Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener
3539 {
....@@ -37,7 +41,6 @@
3741 static boolean[] selectedstack = new boolean[65536];
3842 static int materialdepth = 0;
3943
40
- static boolean DEBUG = false;
4144 static boolean FRUSTUM = false; // still bogus true; // frustum culling
4245
4346 // camera change fix
....@@ -45,6 +48,39 @@
4548 static boolean ABORTED = false;
4649
4750 static int STEP = 1;
51
+
52
+ private static BufferedImage CreateBim(byte[] bytes, int width, int height)
53
+ {
54
+ int[] pixels = new int[bytes.length/3];
55
+ for (int i=pixels.length; --i>=0;)
56
+ {
57
+ int i3 = i*3;
58
+ pixels[i] = 0xFF;
59
+ pixels[i] <<= 8;
60
+ pixels[i] |= bytes[i3+2] & 0xFF;
61
+ pixels[i] <<= 8;
62
+ pixels[i] |= bytes[i3+1] & 0xFF;
63
+ pixels[i] <<= 8;
64
+ pixels[i] |= bytes[i3] & 0xFF;
65
+ }
66
+ /*
67
+ int r=0,g=0,b=0,a=0;
68
+ for (int i=0; i<width; i++)
69
+ for (int j=0; j<height; j++)
70
+ {
71
+ int index = j*width+i;
72
+ int p = pixels[index];
73
+ a = ((p>>24) & 0xFF);
74
+ r = ((p>>16) & 0xFF);
75
+ g = ((p>>8) & 0xFF);
76
+ b = (p & 0xFF);
77
+ pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
78
+ }
79
+ /**/
80
+ BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
81
+ rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
82
+ return rendImage;
83
+ }
4884
4985 /*static*/ private boolean CULLFACE = false; // true;
5086 /*static*/ boolean NEAREST = false; // true;
....@@ -56,14 +92,12 @@
5692 static int CURRENTANTIALIAS = 0; // 1;
5793 /*static*/ boolean RENDERSHADOW = true;
5894 /*static*/ int RENDERPROGRAM = 2; // 0 == none, 1 == fast, 2 == normal
59
- static boolean ANIMATION = false;
60
- static String filename;
6195
6296 boolean DISPLAYTEXT = false;
6397 //boolean REDUCETEXTURE = true;
6498 boolean CACHETEXTURE = true;
6599 boolean CLEANCACHE = false; // true;
66
- boolean MIPMAP = false; // true;
100
+ boolean MIPMAP = false; // true; // never works...
67101 boolean COMPRESSTEXTURE = false;
68102 boolean KOMPACTTEXTURE = false; // true;
69103 boolean RESIZETEXTURE = false;
....@@ -76,7 +110,11 @@
76110 //private Mat4f spotlightTransform = new Mat4f();
77111 //private Mat4f spotlightInverseTransform = new Mat4f();
78112 static GLContext glcontext = null;
79
- /*static*/ com.sun.opengl.util.texture.Texture cubemap;
113
+ /*static*/ com.sun.opengl.util.texture.Texture cubemap; // Either custom or rgb
114
+ /*static*/ com.sun.opengl.util.texture.Texture cubemapcustom;
115
+ /*static*/ com.sun.opengl.util.texture.Texture cubemaprgb;
116
+ boolean transformMode;
117
+
80118 boolean reverseUP = false;
81119 static boolean frozen = false;
82120 boolean enablebackspace = false; // patch for back buffer refresh
....@@ -92,6 +130,8 @@
92130
93131 static int tickcount = 0; // slow pose issue
94132
133
+static boolean BUTTONLESSWHEEL = false;
134
+static boolean ZOOMBOXMODE = false;
95135 static boolean BOXMODE = false;
96136 static boolean IMAGEFLIP = false;
97137 static boolean SMOOTHFOCUS = false;
....@@ -106,7 +146,7 @@
106146 static boolean OEIL = true;
107147 static boolean OEILONCE = false; // do oeilon then oeiloff
108148 static boolean LOOKAT = true;
109
-static boolean RANDOM = true; // false;
149
+static boolean SWITCH = true; // false;
110150 static boolean HANDLES = false; // selection doesn't work!!
111151 static boolean PAINTMODE = false;
112152
....@@ -128,7 +168,7 @@
128168
129169
130170 // OPTIONS
131
- boolean Skinshader = true;
171
+ boolean Skinshader = false; // true;
132172 boolean cameraLight = false;
133173 boolean UVdebug = false;
134174 boolean Udebug = false;
....@@ -137,7 +177,7 @@
137177 static boolean doublesided = false; // true; // reversed normals are awful for conformance
138178 boolean anisotropy = true;
139179 boolean softshadow = true; // slower but better false;
140
- boolean opacityhalo = false;
180
+ boolean opacityhalo = false; // reverse the halo effect (e.g. glass)
141181
142182 boolean macromode = false;
143183
....@@ -148,6 +188,21 @@
148188 defaultcaps.setAccumGreenBits(16);
149189 defaultcaps.setAccumBlueBits(16);
150190 defaultcaps.setAccumAlphaBits(16);
191
+ }
192
+
193
+ private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
194
+
195
+ public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException
196
+ {
197
+ try
198
+ {
199
+ return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
200
+ } catch (IOException e)
201
+ {
202
+ System.out.println("NAME = " + name);
203
+ e.printStackTrace(); // throw new RuntimeException(e);
204
+ return null;
205
+ }
151206 }
152207
153208 void SetAsGLRenderer(boolean b)
....@@ -168,7 +223,8 @@
168223
169224 SetCamera(cam);
170225
171
- SetLight(new Camera(new cVector(10, 10, -20)));
226
+ // Warning: not used.
227
+ SetLight(new Camera(new cVector(15, 10, -20)));
172228
173229 object = o;
174230
....@@ -223,6 +279,11 @@
223279 public boolean IsBoxMode()
224280 {
225281 return BOXMODE;
282
+ }
283
+
284
+ public boolean IsZoomBoxMode()
285
+ {
286
+ return ZOOMBOXMODE;
226287 }
227288
228289 public void ClearDepth()
....@@ -320,7 +381,7 @@
320381 cStatic.objectstack[materialdepth++] = obj;
321382 //System.out.println("material " + material);
322383 //Applet3D.tracein(this, selected);
323
- display.vector2buffer = obj.projectedVertices;
384
+ //display.vector2buffer = obj.projectedVertices;
324385 if (obj instanceof Camera)
325386 {
326387 display.options1[0] = material.shift;
....@@ -329,14 +390,28 @@
329390 display.options1[2] = material.shadowbias;
330391 display.options1[3] = material.aniso;
331392 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]);
332398 display.options2[0] = material.opacity;
333399 display.options2[1] = material.diffuse;
334400 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]);
335404
336405 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]);
337409 display.options4[0] = material.cameralight/0.2f;
338410 display.options4[1] = material.subsurface;
339411 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]);
340415
341416 // if (display.CURRENTANTIALIAS > 0)
342417 // display.options3[3] /= 4;
....@@ -352,7 +427,7 @@
352427 /**/
353428 } else
354429 {
355
- DrawMaterial(material, selected);
430
+ DrawMaterial(material, selected, obj.projectedVertices);
356431 }
357432 } else
358433 {
....@@ -376,8 +451,8 @@
376451 cStatic.objectstack[materialdepth++] = obj;
377452 //System.out.println("material " + material);
378453 //Applet3D.tracein("selected ", selected);
379
- display.vector2buffer = obj.projectedVertices;
380
- display.DrawMaterial(material, selected);
454
+ //display.vector2buffer = obj.projectedVertices;
455
+ display.DrawMaterial(material, selected, obj.projectedVertices);
381456 }
382457 }
383458
....@@ -394,8 +469,8 @@
394469 materialdepth -= 1;
395470 if (materialdepth > 0)
396471 {
397
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
398
- 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);
399474 }
400475 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
401476 } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
....@@ -415,8 +490,8 @@
415490 materialdepth -= 1;
416491 if (materialdepth > 0)
417492 {
418
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
419
- 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);
420495 }
421496 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
422497 //else
....@@ -457,15 +532,18 @@
457532 if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
458533 {
459534 //gl.glBegin(gl.GL_TRIANGLES);
460
- 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
+ ;
461538 if (!hasnorm)
462539 {
463
- // System.out.println("FUCK!!");
540
+ // System.out.println("Mesh normal");
464541 LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
465542 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
466543 LA.vecCross(obj.v0, obj.v1, obj.v2);
467544 LA.vecNormalize(obj.v2);
468
- 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);
469547 }
470548
471549 // P
....@@ -487,7 +565,7 @@
487565 y += ny * obj.NORMALPUSH;
488566 z += nz * obj.NORMALPUSH;
489567
490
- gl.glNormal3f(nx, ny, nz);
568
+ SetGLNormal(gl, nx, ny, nz);
491569 }
492570 gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
493571 SetColor(obj, pv);
....@@ -519,7 +597,7 @@
519597 y += ny * obj.NORMALPUSH;
520598 z += nz * obj.NORMALPUSH;
521599
522
- gl.glNormal3f(nx, ny, nz);
600
+ SetGLNormal(gl, nx, ny, nz);
523601 }
524602 //System.out.println("vertexq = " + qv.s + ", " + qv.t);
525603 // boolean locked = false;
....@@ -567,7 +645,7 @@
567645 y += ny * obj.NORMALPUSH;
568646 z += nz * obj.NORMALPUSH;
569647
570
- gl.glNormal3f(nx, ny, nz);
648
+ SetGLNormal(gl, nx, ny, nz);
571649 }
572650
573651 // if ((dot&4) == 0)
....@@ -1173,10 +1251,10 @@
11731251 {
11741252 if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
11751253 {
1176
- gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1254
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
11771255 } else
11781256 {
1179
- gl.glNormal3f(0, 0, 1);
1257
+ SetGLNormal(gl, 0, 0, 1);
11801258 }
11811259
11821260 if (c != null)
....@@ -1185,10 +1263,12 @@
11851263 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
11861264 }
11871265 }
1266
+
11881267 if (flipV)
11891268 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
11901269 else
11911270 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1271
+
11921272 //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
11931273 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
11941274
....@@ -1198,20 +1278,22 @@
11981278 {
11991279 if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
12001280 {
1201
- gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1281
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
12021282 } else
12031283 {
1204
- gl.glNormal3f(0, 0, 1);
1284
+ SetGLNormal(gl, 0, 0, 1);
12051285 }
12061286 if (c != null)
12071287 {
12081288 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
12091289 }
12101290 }
1291
+
12111292 if (flipV)
12121293 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12131294 else
12141295 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1296
+
12151297 //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
12161298 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
12171299
....@@ -1224,10 +1306,10 @@
12241306 {
12251307 if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
12261308 {
1227
- gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1309
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
12281310 } else
12291311 {
1230
- gl.glNormal3f(0, 0, 1);
1312
+ SetGLNormal(gl, 0, 0, 1);
12311313 }
12321314 if (c != null)
12331315 {
....@@ -1239,8 +1321,10 @@
12391321 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12401322 else
12411323 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1324
+
12421325 //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
12431326 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1327
+
12441328 count2 += 2;
12451329 count3 += 3;
12461330 }
....@@ -1407,7 +1491,7 @@
14071491 {
14081492 if (!selectmode)
14091493 {
1410
- gl.glNormal3f((float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
1494
+ SetGLNormal(gl, (float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
14111495 gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
14121496
14131497 if (flipV)
....@@ -1419,6 +1503,8 @@
14191503 gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
14201504 }
14211505
1506
+ float[] colorV = new float[4];
1507
+
14221508 void SetColor(Object3D obj, Vertex p0)
14231509 {
14241510 CameraPane display = this;
....@@ -1486,8 +1572,6 @@
14861572 {
14871573 return;
14881574 }
1489
-
1490
- float[] colorV = new float[3];
14911575
14921576 if (false) // marked)
14931577 {
....@@ -1596,7 +1680,7 @@
15961680 // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
15971681 }
15981682
1599
- void DrawMaterial(cMaterial material, boolean selected)
1683
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
16001684 {
16011685 CameraPane display = this;
16021686 //new Exception().printStackTrace();
....@@ -1612,18 +1696,18 @@
16121696 //col.getColorComponents(ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB), CameraPane.modelParams0);
16131697 if (!material.multiply)
16141698 {
1615
- display.color = color;
1699
+ display.color = material.color;
16161700 display.saturation = material.modulation;
16171701 }
16181702 else
16191703 {
1620
- display.color *= color*2;
1704
+ display.color *= material.color*2;
16211705 display.saturation *= material.modulation*2;
16221706 }
16231707
16241708 cColor.HSBtoRGB(display.color, display.saturation, 1, display.modelParams0);
16251709
1626
- float[] colorV = GrafreeD.colorV;
1710
+ float[] colorV = Grafreed.colorV;
16271711
16281712 /**/
16291713 if (display.DrawMode() == display.DEFAULT) // && display.RENDERPROGRAM == 0)
....@@ -1631,7 +1715,7 @@
16311715 colorV[0] = display.modelParams0[0] * material.diffuse;
16321716 colorV[1] = display.modelParams0[1] * material.diffuse;
16331717 colorV[2] = display.modelParams0[2] * material.diffuse;
1634
- colorV[3] = material.opacity;
1718
+ colorV[3] = 1; // material.opacity;
16351719
16361720 gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
16371721 //System.out.println("Opacity = " + opacity);
....@@ -1736,12 +1820,12 @@
17361820
17371821 display.modelParams7[0] = 0;
17381822 display.modelParams7[1] = 1000;
1739
- display.modelParams7[2] = 0;
1823
+ display.modelParams7[2] = material.parallax;
17401824 display.modelParams7[3] = 0;
17411825
1742
- display.modelParams6[0] = 100; // criss de bug de bump
1826
+ //display.modelParams6[0] = 100; // criss de bug de bump
17431827
1744
- Object3D.cVector2[] extparams = display.vector2buffer;
1828
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
17451829 if (extparams != null && extparams.length > 0 && extparams[0] != null)
17461830 {
17471831 display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
....@@ -1883,7 +1967,7 @@
18831967 void PushMatrix(double[][] matrix)
18841968 {
18851969 // GrafreeD.tracein(matrix);
1886
- PushMatrix(matrix,1);
1970
+ PushMatrix(matrix, 1);
18871971 }
18881972
18891973 void PushMatrix()
....@@ -1969,9 +2053,9 @@
19692053 switch(viewcode)
19702054 {
19712055 case 0: return "main";
1972
- case 1: return "one";
1973
- case 2: return "two";
1974
- case 3: return "three";
2056
+ case 1: return "Red";
2057
+ case 2: return "Green";
2058
+ case 3: return "Blue";
19752059 case 4: return "light";
19762060 }
19772061
....@@ -2037,7 +2121,7 @@
20372121 //System.err.println("Oeil on");
20382122 OEIL = true;
20392123 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2040
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2124
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
20412125 //pingthread.StepToTarget(true);
20422126 }
20432127
....@@ -2135,7 +2219,7 @@
21352219 System.err.println("LIVE = " + Globals.isLIVE());
21362220
21372221 if (!Globals.isLIVE()) // save sound
2138
- GrafreeD.savesound = true; // wav.save();
2222
+ Grafreed.savesound = true; // wav.save();
21392223 // else
21402224 repaint(); // start loop // may 2013
21412225 }
....@@ -2168,6 +2252,11 @@
21682252 public void ToggleBoxMode()
21692253 {
21702254 BOXMODE ^= true;
2255
+ }
2256
+
2257
+ public void ToggleZoomBoxMode()
2258
+ {
2259
+ ZOOMBOXMODE ^= true;
21712260 }
21722261
21732262 public void ToggleSmoothFocus()
....@@ -2247,7 +2336,7 @@
22472336
22482337 void ToggleDebug()
22492338 {
2250
- DEBUG ^= true;
2339
+ Globals.DEBUG ^= true;
22512340 }
22522341
22532342 void ToggleLookAt()
....@@ -2255,9 +2344,9 @@
22552344 LOOKAT ^= true;
22562345 }
22572346
2258
- void ToggleRandom()
2347
+ void ToggleSwitch()
22592348 {
2260
- RANDOM ^= true;
2349
+ SWITCH ^= true;
22612350 }
22622351
22632352 void ToggleHandles()
....@@ -2265,10 +2354,17 @@
22652354 HANDLES ^= true;
22662355 }
22672356
2357
+ Object3D paintFolder;
2358
+
22682359 void TogglePaint()
22692360 {
22702361 PAINTMODE ^= true;
22712362 paintcount = 0;
2363
+
2364
+ if (PAINTMODE)
2365
+ {
2366
+ paintFolder = GetFolder();
2367
+ }
22722368 }
22732369
22742370 void SwapCamera(int a, int b)
....@@ -2364,7 +2460,34 @@
23642460 {
23652461 return currentGL;
23662462 }
2367
-
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
+
23682491 /**/
23692492 class CacheTexture
23702493 {
....@@ -2373,28 +2496,31 @@
23732496
23742497 int resolution;
23752498
2376
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2499
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
23772500 {
2378
- texture = tex;
2501
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2502
+ texturedata = texdata;
23792503 resolution = res;
23802504 }
23812505 }
23822506 /**/
23832507
23842508 // TEXTURE static Texture texture;
2385
- static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures
2386
- = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>();
2387
- 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
+
23882514 int pigmentdepth = 0;
23892515 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
23902516 int bumpdepth = 0;
23912517 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
23922518 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
23932519 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2394
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2520
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
23952521 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
23962522
2397
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2523
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
23982524 {
23992525 TextureData texturedata = null;
24002526
....@@ -2404,7 +2530,7 @@
24042530 com.sun.opengl.util.texture.TextureIO.newTextureData(
24052531 getClass().getClassLoader().getResourceAsStream(name),
24062532 true,
2407
- com.sun.opengl.util.texture.TextureIO.PNG);
2533
+ GetFormat(name)); // com.sun.opengl.util.texture.TextureIO.PNG);
24082534 } catch (java.io.IOException e)
24092535 {
24102536 throw new javax.media.opengl.GLException(e);
....@@ -2413,13 +2539,34 @@
24132539 if (bump)
24142540 texturedata = ConvertBump(texturedata, false);
24152541
2416
- com.sun.opengl.util.texture.Texture texture =
2417
- 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);
24182544
2419
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2420
- 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);
24212547
2422
- 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;
24232570 }
24242571
24252572 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3492,6 +3639,8 @@
34923639
34933640 System.out.println("LOADING TEXTURE : " + name);
34943641
3642
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3643
+
34953644 //
34963645 if (false) // compressbit > 0)
34973646 {
....@@ -4196,6 +4345,7 @@
41964345
41974346 com.sun.opengl.util.texture.Texture CompressTexture2(String name)
41984347 {
4348
+ new Exception().printStackTrace();
41994349 System.exit(0);
42004350 com.sun.opengl.util.texture.Texture texture = null;
42014351
....@@ -7889,7 +8039,7 @@
78898039 String pigment = Object3D.GetPigment(tex);
78908040 String bump = Object3D.GetBump(tex);
78918041
7892
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8042
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
78938043 {
78948044 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
78958045 // System.out.println("; bump = " + bump);
....@@ -7904,11 +8054,69 @@
79048054 pigment = null;
79058055 }
79068056
7907
- ReleaseTexture(bump, true);
7908
- ReleaseTexture(pigment, false);
8057
+ ReleaseTexture(tex, true);
8058
+ ReleaseTexture(tex, false);
79098059 }
79108060
7911
- 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)
79128120 {
79138121 if (// DrawMode() != 0 || /*tex == null ||*/
79148122 ambientOcclusion ) // || !textureon)
....@@ -7919,7 +8127,7 @@
79198127 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
79208128
79218129 if (tex != null)
7922
- texture = textures.get(tex);
8130
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
79238131
79248132 // //assert( texture != null );
79258133 // if (texture == null)
....@@ -8011,7 +8219,55 @@
80118219 }
80128220 }
80138221
8014
- /*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
80158271 {
80168272 if (// DrawMode() != 0 || /*tex == null ||*/
80178273 ambientOcclusion ) // || !textureon)
....@@ -8022,17 +8278,47 @@
80228278 if (tex == null)
80238279 {
80248280 BindTexture(null,false,resolution);
8025
- BindTexture(null,true,resolution);
80268281 return;
80278282 }
80288283
80298284 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
+
80308317 String bump = Object3D.GetBump(tex);
80318318
8032
- usedtextures.put(pigment, pigment);
8033
- usedtextures.put(bump, bump);
8319
+ usedtextures.add(tex);
80348320
8035
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8321
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
80368322 {
80378323 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
80388324 // System.out.println("; bump = " + bump);
....@@ -8042,43 +8328,94 @@
80428328 {
80438329 bump = null;
80448330 }
8045
- if (pigment.equals(""))
8046
- {
8047
- pigment = null;
8048
- }
80498331
8050
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8051
- BindTexture(pigment, false, resolution);
80528332 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8053
- BindTexture(bump, true, resolution);
8333
+ BindTexture(tex, true, resolution);
80548334 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8055
-
8056
- return; // true;
80578335 }
80588336
8059
- 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)
80608340 {
8061
- 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;
80628360
80638361 if (tex != null)
80648362 {
8065
- String texname = tex;
8363
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8364
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
80668365
8067
- String[] split = tex.split("Textures");
8068
- if (split.length > 1)
8069
- texname = "/Users/nbriere/Textures" + split[split.length-1];
8070
- else
8071
- if (!texname.startsWith("/"))
8072
- 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
+ }
80738383
80748384 if (CACHETEXTURE)
8075
- texture = textures.get(texname); // TEXTURE CACHE
8076
-
8077
- TextureData texturedata = null;
8078
-
8079
- if (texture == null || texture.resolution < resolution)
80808385 {
8081
- 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(""))
80828419 {
80838420 assert(!bump);
80848421 // if (bump)
....@@ -8089,19 +8426,23 @@
80898426 // }
80908427 // else
80918428 // {
8092
- texture = textures.get(tex);
8093
- if (texture == null)
8429
+ // texturecache = textures.get(texname); // suspicious
8430
+ if (texturecache == null)
80948431 {
8095
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8432
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
80968433 }
8434
+ else
8435
+ new Exception().printStackTrace();
80978436 // }
80988437 } else
8099
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8438
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
81008439 {
81018440 assert(bump);
8102
- texture = textures.get(tex);
8103
- if (texture == null)
8104
- 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();
81058446 } else
81068447 {
81078448 //if (tex.equals("IMMORTAL"))
....@@ -8109,11 +8450,22 @@
81098450 // texture = GetResourceTexture("default.png");
81108451 //} else
81118452 //{
8112
- if (tex.equals("WHITE_NOISE"))
8453
+ if (texname.endsWith("WHITE_NOISE"))
81138454 {
8114
- texture = textures.get(tex);
8115
- if (texture == null)
8116
- 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();
81178469 } else
81188470 {
81198471 if (textureon)
....@@ -8138,7 +8490,7 @@
81388490 }
81398491
81408492 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
8141
- if (!new File(cachename).exists())
8493
+ if (!FileExists(cachename))
81428494 cachename = texname;
81438495 else
81448496 processbump = false; // don't process bump map again
....@@ -8160,7 +8512,7 @@
81608512 }
81618513
81628514 cachename = texname.substring(0, texname.length()-4)+ext+".png";
8163
- if (!new File(cachename).exists())
8515
+ if (!FileExists(cachename))
81648516 cachename = texname;
81658517 else
81668518 processbump = false; // don't process bump map again
....@@ -8169,20 +8521,23 @@
81698521 texturedata = GetFileTexture(cachename, processbump, resolution);
81708522
81718523
8172
- if (texturedata != null)
8173
- 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);
81748528 //texture = GetTexture(tex, bump);
81758529 }
8530
+ }
81768531 }
81778532 //}
81788533 }
81798534
8180
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8535
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
81818536 {
81828537 //return false;
81838538
81848539 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8185
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8540
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
81868541 {
81878542 // String ext = "_highres";
81888543 // if (REDUCETEXTURE)
....@@ -8199,52 +8554,17 @@
81998554 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
82008555 if (!cachefile.exists())
82018556 {
8202
- // cache to disk
8203
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
8204
- //buffers[0].
8205
-
8206
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
8207
- int[] pixels = new int[bytebuf.capacity()/3];
8208
-
8209
- // squared size heuristic...
8210
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8557
+ //if (texturedata.getWidth() == texturedata.getHeight())
82118558 {
8212
- for (int i=pixels.length; --i>=0;)
8213
- {
8214
- int i3 = i*3;
8215
- pixels[i] = 0xFF;
8216
- pixels[i] <<= 8;
8217
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
8218
- pixels[i] <<= 8;
8219
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
8220
- pixels[i] <<= 8;
8221
- pixels[i] |= bytebuf.get(i3) & 0xFF;
8222
- }
8223
-
8224
- /*
8225
- int r=0,g=0,b=0,a=0;
8226
- for (int i=0; i<width; i++)
8227
- for (int j=0; j<height; j++)
8228
- {
8229
- int index = j*width+i;
8230
- int p = pixels[index];
8231
- a = ((p>>24) & 0xFF);
8232
- r = ((p>>16) & 0xFF);
8233
- g = ((p>>8) & 0xFF);
8234
- b = (p & 0xFF);
8235
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
8236
- }
8237
- /**/
8238
- int width = (int)Math.sqrt(pixels.length); // squared
8239
- int height = width;
8240
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
8241
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8559
+ BufferedImage rendImage = CreateBim(texturedata);
8560
+
82428561 ImageWriter writer = null;
82438562 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
82448563 if (iter.hasNext()) {
82458564 writer = (ImageWriter)iter.next();
82468565 }
8247
- float compressionQuality = 0.9f;
8566
+
8567
+ float compressionQuality = 0.85f;
82488568 try
82498569 {
82508570 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8261,18 +8581,20 @@
82618581 }
82628582 }
82638583 }
8264
-
8584
+
8585
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8586
+
82658587 //System.out.println("Texture = " + tex);
8266
- if (textures.containsKey(texname))
8588
+ if (textures.containsKey(tex))
82678589 {
8268
- CacheTexture thetex = textures.get(texname);
8590
+ CacheTexture thetex = textures.get(tex);
82698591 thetex.texture.disable();
82708592 thetex.texture.dispose();
8271
- textures.remove(texname);
8593
+ textures.remove(tex);
82728594 }
82738595
8274
- texture.texturedata = texturedata;
8275
- textures.put(texname, texture);
8596
+ //texture.texturedata = texturedata;
8597
+ textures.put(tex, texturecache);
82768598
82778599 // newtex = true;
82788600 }
....@@ -8288,10 +8610,44 @@
82888610 }
82898611 }
82908612
8291
- return texture;
8613
+ return texturecache;
82928614 }
82938615
8294
- 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
82958651 {
82968652 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
82978653
....@@ -8309,21 +8665,21 @@
83098665 return texture!=null?texture.texture:null;
83108666 }
83118667
8312
- public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution)
8668
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
83138669 {
83148670 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
83158671
83168672 return texture!=null?texture.texturedata:null;
83178673 }
83188674
8319
- boolean BindTexture(String tex, boolean bump, int resolution)
8675
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
83208676 {
83218677 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
83228678 {
83238679 return false;
83248680 }
83258681
8326
- boolean newtex = false;
8682
+ //boolean newtex = false;
83278683
83288684 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
83298685
....@@ -8355,9 +8711,75 @@
83558711 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
83568712 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
83578713
8358
- return newtex;
8714
+ return true; // Warning: not used.
83598715 }
83608716
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
+
83618783 ShadowBuffer shadowPBuf;
83628784 AntialiasBuffer antialiasPBuf;
83638785 int MAXSTACK;
....@@ -8374,10 +8796,12 @@
83748796
83758797 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
83768798 MAXSTACK = temp[0];
8377
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8799
+ if (Globals.DEBUG)
8800
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
83788801 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
83798802 MAXSTACK = temp[0];
8380
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8803
+ if (Globals.DEBUG)
8804
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
83818805
83828806 // Use debug pipeline
83838807 //drawable.setGL(new DebugGL(gl)); //
....@@ -8385,7 +8809,8 @@
83858809 gl = drawable.getGL(); //
83868810
83878811 GL gl3 = getGL();
8388
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8812
+ if (Globals.DEBUG)
8813
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
83898814
83908815
83918816 //float pos[] = { 100, 100, 100, 0 };
....@@ -8550,7 +8975,7 @@
85508975
85518976 if (cubemap == null)
85528977 {
8553
- LoadEnvy(5);
8978
+ //LoadEnvy(1);
85548979 }
85558980
85568981 //cubemap.enable();
....@@ -8826,6 +9251,8 @@
88269251
88279252 void LoadEnvy(int which)
88289253 {
9254
+ assert(false);
9255
+
88299256 String name;
88309257 String ext;
88319258
....@@ -8837,37 +9264,58 @@
88379264 cubemap = null;
88389265 return;
88399266 case 1:
8840
- name = "cubemaps/box_";
8841
- ext = "png";
9267
+ name = "cubemaps/rgb/";
9268
+ ext = "jpg";
88429269 reverseUP = false;
88439270 break;
88449271 case 2:
8845
- name = "cubemaps/uffizi_";
8846
- ext = "png";
8847
- break; // reverseUP = true; break;
9272
+ name = "cubemaps/uffizi/";
9273
+ ext = "jpg";
9274
+ reverseUP = false;
9275
+ break;
88489276 case 3:
8849
- name = "cubemaps/CloudyHills_";
8850
- ext = "tga";
9277
+ name = "cubemaps/CloudyHills/";
9278
+ ext = "jpg";
88519279 reverseUP = false;
88529280 break;
88539281 case 4:
8854
- name = "cubemaps/cornell_";
9282
+ name = "cubemaps/cornell/";
88559283 ext = "png";
88569284 reverseUP = false;
88579285 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;
88589311 default:
8859
- name = "cubemaps/rgb_";
8860
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9312
+ name = "cubemaps/box/";
9313
+ ext = "png"; /*mipmap = true;*/
9314
+ reverseUP = false;
88619315 break;
88629316 }
8863
-
8864
- try
8865
- {
8866
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
8867
- } catch (IOException e)
8868
- {
8869
- throw new RuntimeException(e);
8870
- }
9317
+
9318
+ LoadSkybox(name, ext, mipmap);
88719319 }
88729320
88739321 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -8899,8 +9347,12 @@
88999347 static double[] model = new double[16];
89009348 double[] camera2light = new double[16];
89019349 double[] light2camera = new double[16];
8902
- int newenvy = -1;
8903
- boolean envyoff = true; // false;
9350
+
9351
+ //int newenvy = -1;
9352
+ //boolean envyoff = false;
9353
+
9354
+ String loadedskyboxname;
9355
+
89049356 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
89059357 //float[] light0 = { 0,0,0 };
89069358 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9193,11 +9645,35 @@
91939645 jy8[3] = 0.5f;
91949646 }
91959647
9196
- 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
91979649 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
91989650 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
91999651 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
92009652
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
+
92019677 static int imagecount = 0; // movie generation
92029678
92039679 static int jitter = 0;
....@@ -9293,8 +9769,8 @@
92939769 assert (parentcam != renderCamera);
92949770
92959771 if (renderCamera != lightCamera)
9296
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9297
- LA.matConcat(matrix, parentcam.toParent, matrix);
9772
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9773
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
92989774
92999775 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
93009776
....@@ -9309,8 +9785,8 @@
93099785 LA.matCopy(renderCamera.fromScreen, matrix);
93109786
93119787 if (renderCamera != lightCamera)
9312
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9313
- LA.matConcat(parentcam.fromParent, matrix, matrix);
9788
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9789
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
93149790
93159791 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
93169792
....@@ -9356,10 +9832,12 @@
93569832 rati = 1 / rati;
93579833 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
93589834 }
9359
- assert (newenvy == -1);
9835
+
9836
+ //assert (newenvy == -1);
9837
+
93609838 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
93619839 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9362
- DrawSkyBox(gl);
9840
+ DrawSkyBox(gl, (float)rati);
93639841 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
93649842 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
93659843 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -9382,7 +9860,7 @@
93829860 //gl.glFlush();
93839861 gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE);
93849862
9385
- if (ANIMATION && ABORTED)
9863
+ if (Globals.ANIMATION && ABORTED)
93869864 {
93879865 System.err.println(" ABORTED FRAME");
93889866 break;
....@@ -9412,7 +9890,7 @@
94129890 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
94139891
94149892 // save image
9415
- if (ANIMATION && !ABORTED)
9893
+ if (Globals.ANIMATION && !ABORTED)
94169894 {
94179895 VPwidth = viewport[2];
94189896 VPheight = viewport[3];
....@@ -9523,11 +10001,11 @@
952310001
952410002 // imagecount++;
952510003
9526
- 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;
952710005
952810006 if (!BOXMODE)
952910007 {
9530
- 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) + ")");
953110009 }
953210010
953310011 if (!BOXMODE)
....@@ -9565,7 +10043,7 @@
956510043 ABORTED = false;
956610044 }
956710045 else
9568
- GrafreeD.wav.cursor += 735 * ACSIZE;
10046
+ Grafreed.wav.cursor += 735 * ACSIZE;
956910047
957010048 if (false)
957110049 {
....@@ -10225,14 +10703,23 @@
1022510703 static boolean init = false;
1022610704
1022710705 double[][] matrix = LA.newMatrix();
10706
+
10707
+ // This is to refresh the UI of the material panel.
10708
+ ObjEditor patchMaterial;
1022810709
1022910710 public void display(GLAutoDrawable drawable)
1023010711 {
10231
- if (GrafreeD.savesound && GrafreeD.hassound)
10712
+ if (patchMaterial.patchMaterial)
1023210713 {
10233
- GrafreeD.wav.save();
10234
- GrafreeD.savesound = false;
10235
- 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;
1023610723 }
1023710724 // if (DEBUG_SELECTION)
1023810725 // {
....@@ -10308,6 +10795,7 @@
1030810795 ANTIALIAS = 0;
1030910796 //System.out.println("RESTART");
1031010797 AAtimer.restart();
10798
+ Globals.TIMERRUNNING = true;
1031110799 }
1031210800 }
1031310801 }
....@@ -10362,7 +10850,7 @@
1036210850 Object3D theobject = object;
1036310851 Object3D theparent = object.parent;
1036410852 object.parent = null;
10365
- object = (Object3D)GrafreeD.clone(object);
10853
+ object = (Object3D)Grafreed.clone(object);
1036610854 object.Stripify();
1036710855 if (theobject.selection == null || theobject.selection.Size() == 0)
1036810856 theobject.PreprocessOcclusion(this);
....@@ -10375,13 +10863,14 @@
1037510863 ambientOcclusion = false;
1037610864 }
1037710865
10378
- if (Globals.lighttouched && DrawMode() == DEFAULT && !lightMode) // && !FROZEN)
10866
+ if (//Globals.lighttouched &&
10867
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1037910868 {
1038010869 //if (RENDERSHADOW) // ?
1038110870 if (!IsFrozen())
1038210871 {
1038310872 // dec 2012
10384
- if (!ambientOcclusion && !(!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0))
10873
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
1038510874 {
1038610875 Globals.framecount++;
1038710876 shadowbuffer.display();
....@@ -10394,7 +10883,7 @@
1039410883
1039510884 if (wait)
1039610885 {
10397
- Sleep(500);
10886
+ Sleep(200); // blocks everything
1039810887
1039910888 wait = false;
1040010889 }
....@@ -10508,8 +10997,8 @@
1050810997
1050910998 // if (parentcam != renderCamera) // not a light
1051010999 if (cam != lightCamera)
10511
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10512
- LA.matConcat(matrix, parentcam.toParent, matrix);
11000
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11001
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1051311002
1051411003 for (int j = 0; j < 4; j++)
1051511004 {
....@@ -10523,8 +11012,8 @@
1052311012
1052411013 // if (parentcam != renderCamera) // not a light
1052511014 if (cam != lightCamera)
10526
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10527
- LA.matConcat(parentcam.fromParent, matrix, matrix);
11015
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11016
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1052811017
1052911018 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1053011019
....@@ -10610,13 +11099,43 @@
1061011099 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1061111100 }
1061211101
10613
- 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"))
1061411110 {
10615
- LoadEnvy(newenvy);
11111
+ if (cubemaprgb == null)
11112
+ {
11113
+ cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb2" + "/", "jpg", false);
11114
+ }
11115
+
11116
+ cubemap = cubemaprgb;
1061611117 }
10617
-
10618
- newenvy = -1;
10619
-
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
+
1062011139 ratio = ((double) getWidth()) / getHeight();
1062111140 //System.out.println("ratio = " + ratio);
1062211141
....@@ -10632,7 +11151,7 @@
1063211151
1063311152 if (!IsFrozen() && !ambientOcclusion)
1063411153 {
10635
- DrawSkyBox(gl);
11154
+ DrawSkyBox(gl, (float)ratio);
1063611155 }
1063711156
1063811157 //if (selection_view == -1)
....@@ -10783,7 +11302,16 @@
1078311302 // Bump noise
1078411303 gl.glActiveTexture(GL.GL_TEXTURE6);
1078511304 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
10786
- 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
+
1078711315
1078811316 gl.glActiveTexture(GL.GL_TEXTURE0);
1078911317 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -10806,9 +11334,9 @@
1080611334
1080711335 gl.glMatrixMode(GL.GL_MODELVIEW);
1080811336
10809
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10810
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10811
-//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);
1081211340 } else
1081311341 {
1081411342 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -10819,7 +11347,7 @@
1081911347 //System.out.println("BLENDING ON");
1082011348 gl.glEnable(GL.GL_BLEND);
1082111349 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
10822
-
11350
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1082311351 gl.glMatrixMode(gl.GL_PROJECTION);
1082411352 gl.glLoadIdentity();
1082511353
....@@ -10908,8 +11436,8 @@
1090811436 System.err.println("parentcam != renderCamera");
1090911437
1091011438 // if (cam != lightCamera)
10911
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10912
- 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
1091311441 }
1091411442
1091511443 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -10930,8 +11458,8 @@
1093011458 if (true) // TODO
1093111459 {
1093211460 if (cam != lightCamera)
10933
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10934
- 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
1093511463 }
1093611464
1093711465 LA.xformPos(light0, cam.toScreen, light0);
....@@ -11068,7 +11596,7 @@
1106811596 }
1106911597 }
1107011598
11071
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11599
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1107211600 {
1107311601 //gl.glDepthFunc(GL.GL_LEQUAL);
1107411602 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11076,24 +11604,21 @@
1107611604
1107711605 boolean texon = textureon;
1107811606
11079
- if (RENDERPROGRAM > 0)
11080
- {
11081
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11082
- textureon = false;
11083
- }
11607
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11608
+ textureon = false;
11609
+
1108411610 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1108511611 //System.out.println("ALLO");
1108611612 gl.glColorMask(false, false, false, false);
1108711613 DrawObject(gl);
11088
- if (RENDERPROGRAM > 0)
11089
- {
11090
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11091
- textureon = texon;
11092
- }
11614
+
11615
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11616
+ textureon = texon;
11617
+
1109311618 gl.glColorMask(true, true, true, true);
1109411619
1109511620 gl.glDepthFunc(GL.GL_EQUAL);
11096
- //gl.glDepthMask(false);
11621
+ gl.glDepthMask(false);
1109711622 }
1109811623
1109911624 if (false) // DrawMode() == SHADOW)
....@@ -11247,8 +11772,14 @@
1124711772 {
1124811773 renderpass++;
1124911774 // System.out.println("Draw object... ");
11775
+ STEP = 1;
1125011776 if (FAST) // in case there is no script
11251
- STEP = 16;
11777
+ STEP = 8;
11778
+
11779
+ if (CURRENTANTIALIAS == 0 || ACSIZE == 1)
11780
+ {
11781
+ STEP *= 4;
11782
+ }
1125211783
1125311784 //object.FullInvariants();
1125411785
....@@ -11262,23 +11793,44 @@
1126211793 e.printStackTrace();
1126311794 }
1126411795
11265
- if (GrafreeD.RENDERME > 0)
11266
- GrafreeD.RENDERME--; // mechante magouille
11796
+ if (Grafreed.RENDERME > 0)
11797
+ Grafreed.RENDERME--; // mechante magouille
1126711798
1126811799 Globals.ONESTEP = false;
1126911800 }
1127011801
1127111802 static boolean zoomonce = false;
1127211803
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
+
1127311822 void DrawObject(GL gl, boolean draw)
1127411823 {
11824
+ // To clear camera values
11825
+ ResetOptions();
11826
+
1127511827 //System.out.println("DRAW OBJECT " + mouseDown);
1127611828 // DrawMode() = SELECTION;
1127711829 //GL gl = getGL();
1127811830 if ((TRACK || SHADOWTRACK) || zoomonce)
1127911831 {
1128011832 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11281
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11833
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1128211834 pingthread.StepToTarget(true); // true);
1128311835 // zoomonce = false;
1128411836 }
....@@ -11333,7 +11885,14 @@
1133311885
1133411886 usedtextures.clear();
1133511887
11336
- 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
+ }
1133711896 }
1133811897 //System.out.println("--> " + stackdepth);
1133911898 // GrafreeD.traceon();
....@@ -11343,8 +11902,9 @@
1134311902
1134411903 if (DrawMode() == DEFAULT)
1134511904 {
11346
- if (DEBUG)
11905
+ if (Globals.DEBUG)
1134711906 {
11907
+ CreateSelectedPoint();
1134811908 float radius = 0.05f;
1134911909 if (selectedpoint.radius != radius)
1135011910 {
....@@ -11398,20 +11958,32 @@
1139811958 ReleaseTextures(DEFAULT_TEXTURES);
1139911959
1140011960 if (CLEANCACHE)
11401
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11961
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1140211962 {
11403
- String tex = e.nextElement();
11963
+ cTexture tex = e.nextElement();
1140411964
1140511965 // System.out.println("Texture --------- " + tex);
1140611966
11407
- if (tex.equals("WHITE_NOISE"))
11967
+ if (tex.equals("WHITE_NOISE:"))
1140811968 continue;
1140911969
11410
- if (!usedtextures.containsKey(tex))
11970
+ if (!usedtextures.contains(tex))
1141111971 {
11972
+ CacheTexture gettex = texturepigment.get(tex);
1141211973 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11413
- textures.get(tex).texture.dispose();
11414
- 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
+ }
1141511987 }
1141611988 }
1141711989 }
....@@ -11424,7 +11996,14 @@
1142411996 if (checker != null && DrawMode() == DEFAULT)
1142511997 {
1142611998 //BindTexture(IMMORTAL_TEXTURE);
11427
- 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
+ }
1142812007 // NEAREST
1142912008 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
1143012009 DrawChecker(gl);
....@@ -11506,7 +12085,7 @@
1150612085 return;
1150712086 }
1150812087
11509
- String string = obj.GetToolTip();
12088
+ String string = obj.toString(); //.GetToolTip();
1151012089
1151112090 GL gl = GetGL();
1151212091
....@@ -11823,8 +12402,8 @@
1182312402 //obj.TransformToWorld(light, light);
1182412403 for (int i = tp.size(); --i >= 0;)
1182512404 {
11826
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
11827
- 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);
1182812407 }
1182912408
1183012409
....@@ -11841,8 +12420,8 @@
1184112420 parentcam = cameras[0];
1184212421 }
1184312422
11844
- for (int count = parentcam.GetTransformCount(); --count>=0;)
11845
- 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
1184612425
1184712426 LA.xformPos(light, renderCamera.toScreen, light);
1184812427
....@@ -11932,8 +12511,76 @@
1193212511
1193312512 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1193412513
11935
- String program =
12514
+ String programmin =
12515
+ // Min shader
1193612516 "!!ARBfp1.0\n" +
12517
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12518
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12519
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12520
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12521
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12522
+ "PARAM light2cam0 = program.env[10];" +
12523
+ "PARAM light2cam1 = program.env[11];" +
12524
+ "PARAM light2cam2 = program.env[12];" +
12525
+ "TEMP temp;" +
12526
+ "TEMP light;" +
12527
+ "TEMP ndotl;" +
12528
+ "TEMP normal;" +
12529
+ "TEMP depth;" +
12530
+ "TEMP eye;" +
12531
+ "TEMP pos;" +
12532
+
12533
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12534
+ Normalize("normal") +
12535
+ "MOV light, state.light[0].position;" +
12536
+ "DP3 ndotl.x, light, normal;" +
12537
+
12538
+ // shadow
12539
+ "MOV pos, fragment.texcoord[1];" +
12540
+ "MOV temp, pos;" +
12541
+ ShadowTextureFetch("depth", "temp", "1") +
12542
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12543
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12544
+
12545
+ // No shadow when out of frustum
12546
+ //"SGE temp.y, depth.z, zero123.y;" +
12547
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12548
+
12549
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12550
+
12551
+ // Backlit
12552
+ "MOV pos.w, zero123.y;" +
12553
+ "DP4 eye.x, pos, light2cam0;" +
12554
+ "DP4 eye.y, pos, light2cam1;" +
12555
+ "DP4 eye.z, pos, light2cam2;" +
12556
+ Normalize("eye") +
12557
+
12558
+ "DP3 ndotl.y, -eye, normal;" +
12559
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12560
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12561
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12562
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12563
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12564
+
12565
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12566
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12567
+
12568
+ // Pigment
12569
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12570
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12571
+ "MUL temp, temp, ndotl.x;" +
12572
+
12573
+ "MUL temp, temp, zero123.z;" +
12574
+
12575
+ //"MUL temp, temp, ndotl.y;" +
12576
+
12577
+ "MOV temp.w, zero123.y;" + // reset alpha
12578
+ "MOV result.color, temp;" +
12579
+ "END";
12580
+
12581
+ String programmax =
12582
+ "!!ARBfp1.0\n" +
12583
+
1193712584 //"OPTION ARB_fragment_program_shadow;" +
1193812585 "PARAM light2cam0 = program.env[10];" +
1193912586 "PARAM light2cam1 = program.env[11];" +
....@@ -11959,7 +12606,7 @@
1195912606 "PARAM params4 = program.env[4];" + // anisoV, cameralight, selfshadow, shadow
1196012607 "PARAM params5 = program.env[5];" + // texture, opacity, fakedepth, shadowbias
1196112608 "PARAM params6 = program.env[6];" + // bump, noise, borderfade, fog punchthrough
11962
- "PARAM params7 = program.env[7];" + // noise power, opacity power
12609
+ "PARAM params7 = program.env[7];" + // noise power, opacity power, parallax
1196312610 "PARAM options0 = program.env[63];" + // fog density, intensity, elevation
1196412611 "PARAM options1 = program.env[62];" + // fog rgb color
1196512612 "PARAM options2 = program.env[61];" + // image intensity, subsurface, lightsheen
....@@ -12048,8 +12695,7 @@
1204812695 "TEMP shininess;" +
1204912696 "\n" +
1205012697 "MOV texSamp, one;" +
12051
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12052
-
12698
+
1205312699 "MOV mapgrid.x, one2048th.x;" +
1205412700 "MOV temp, fragment.texcoord[1];" +
1205512701 /*
....@@ -12070,20 +12716,20 @@
1207012716 "MUL temp, floor, mapgrid.x;" +
1207112717 //"TEX depth0, temp, texture[1], 2D;" +
1207212718 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12073
- TextureFetch("depth0", "temp", "1") +
12719
+ ShadowTextureFetch("depth0", "temp", "1") +
1207412720 "") +
1207512721 "ADD temp.x, temp.x, mapgrid.x;" +
1207612722 //"TEX depth1, temp, texture[1], 2D;" +
1207712723 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12078
- TextureFetch("depth1", "temp", "1") +
12724
+ ShadowTextureFetch("depth1", "temp", "1") +
1207912725 "") +
1208012726 "ADD temp.y, temp.y, mapgrid.x;" +
1208112727 //"TEX depth2, temp, texture[1], 2D;" +
12082
- TextureFetch("depth2", "temp", "1") +
12728
+ ShadowTextureFetch("depth2", "temp", "1") +
1208312729 "SUB temp.x, temp.x, mapgrid.x;" +
1208412730 //"TEX depth3, temp, texture[1], 2D;" +
1208512731 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12086
- TextureFetch("depth3", "temp", "1") +
12732
+ ShadowTextureFetch("depth3", "temp", "1") +
1208712733 "") +
1208812734 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1208912735 //"MOV params, material;" +
....@@ -12205,7 +12851,7 @@
1220512851 "POW texSamp.a, texSamp.a, params6.w;" + // fog punch through shortcut
1220612852 // mar 2013 ??? "KIL alpha.a;" +
1220712853 "MOV alpha, texSamp.aaaa;" + // y;" +
12208
- "KIL alpha.a;" +
12854
+ "KIL alpha.a;" + // not sure with parallax mapping
1220912855 /*
1221012856 "MUL temp.xy, temp, two;" +
1221112857 "TXB bump, temp, texture[0], 2D;" +
....@@ -12291,11 +12937,6 @@
1229112937 "SUB bump0, bump0, half;" +
1229212938 "ADD bump, bump, bump0;" +
1229312939
12294
- "MOV temp.x, texSamp.a;" +
12295
- "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
12296
- //"LRP texSamp0, params5.x, texSamp0, one;" +
12297
- "MOV texSamp.a, temp.x;" +
12298
-
1229912940 // double-sided
1230012941 /**/
1230112942 (doublesided?"DP3 temp.z, normal, eye;" +
....@@ -12312,19 +12953,62 @@
1231212953 "MOV normald, normal;" +
1231312954 "MOV normals, normal;" +
1231412955
12956
+ "MOV temp, fragment.texcoord[4];" +
12957
+
1231512958 // UV base
1231612959 //"DP3 UP.x,state.matrix.modelview.row[0],Y;" +
1231712960 //"DP3 UP.y,state.matrix.modelview.row[1],Y;" +
1231812961 //"DP3 UP.z,state.matrix.modelview.row[2],Y;" +
12319
- "DP3 UP.x,state.matrix.texture[7].row[0],Y;" +
12320
- "DP3 UP.y,state.matrix.texture[7].row[1],Y;" +
12321
- "DP3 UP.z,state.matrix.texture[7].row[2],Y;" +
12962
+ "DP3 UP.x,state.matrix.texture[7].row[0],temp;" +
12963
+ "DP3 UP.y,state.matrix.texture[7].row[1],temp;" +
12964
+ "DP3 UP.z,state.matrix.texture[7].row[2],temp;" +
12965
+ Normalize("UP") +
12966
+
1232212967 "XPD V, normal, UP;" +
1232312968 Normalize("V") +
1232412969 "XPD U, V, normal;" +
1232512970 Normalize("U") +
1232612971
1232712972 // parallax mapping
12973
+
12974
+ "DP3 temp2.x, V, eye;" +
12975
+ "DP3 temp2.y, U, eye;" +
12976
+ "DP3 temp2.z, normal, eye;" +
12977
+ "RCP temp2.z, temp2.z;" +
12978
+
12979
+ "DP3 temp2.w, texSamp, texSamp;" + // Height
12980
+ "RSQ temp2.w, temp2.w;" +
12981
+ "RCP temp2.w, temp2.w;" +
12982
+
12983
+ "SUB temp2.w, temp2.w, half;" +
12984
+// "SGE temp.x, temp2.w, eps.x;" +
12985
+// "MUL temp2.w, temp2.w, temp.x;" +
12986
+
12987
+ //"MOV texSamp, U;" +
12988
+
12989
+ "MUL temp2.z, temp2.z, temp2.w;" +
12990
+ "MUL temp2.z, temp2.z, params7.z;" + // parallax
12991
+
12992
+ "MUL temp2, temp2, temp2.z;" +
12993
+
12994
+ "MOV temp, fragment.texcoord[0];" +
12995
+
12996
+ "SUB temp, temp, temp2;" +
12997
+
12998
+ "TEX temp, temp, texture[0], 2D;" +
12999
+ "POW temp.a, temp.a, params6.w;" + // punch through
13000
+
13001
+ "ADD texSamp, temp, texSamp;" +
13002
+ "MUL texSamp.xyz, half, texSamp;" +
13003
+
13004
+ "MOV alpha, texSamp.aaaa;" +
13005
+
13006
+// parallax mapping
13007
+
13008
+ "MOV temp.x, texSamp.a;" +
13009
+ "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
13010
+ //"LRP texSamp0, params5.x, texSamp0, one;" +
13011
+ "MOV texSamp.a, temp.x;" +
1232813012
1232913013 //"MOV temp, fragment.texcoord[0];" +
1233013014 //
....@@ -12454,10 +13138,10 @@
1245413138 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1245513139 "") +
1245613140
12457
- // display shadow only (bump == 0)
13141
+ // display shadow only (fakedepth == 0)
1245813142 "SUB temp.x, half.x, shadow.x;" +
12459
- "MOV temp.y, -params6.x;" +
12460
- "SLT temp.z, temp.y, zero.x;" +
13143
+ "MOV temp.y, -params5.z;" + // params6.x;" +
13144
+ "SLT temp.z, temp.y, -c256i.x;" +
1246113145 "SUB temp.y, one.x, temp.z;" +
1246213146 "MUL temp.x, temp.x, temp.y;" +
1246313147 "KIL temp.x;" +
....@@ -12586,8 +13270,10 @@
1258613270 "MAX ndotl.x, ndotl.x, -ndotl.x;" +
1258713271
1258813272 "SUB temp.x, one.x, ndotl.x;" +
12589
- "ADD temp.x, temp.x, options2.z;" + // lightsheen
12590
- "ADD temp.y, one.y, options2.y;" + // sursurface
13273
+ // Tuning for default skin
13274
+ //"ADD temp.x, temp.x, options2.z;" + // lightsheen
13275
+ "MAD temp.x, options2.z, half.y, temp.x;" + // lightsheen
13276
+ "ADD temp.y, one.y, options2.y;" + // subsurface
1259113277 "MUL temp.x, temp.x, temp.y;" +
1259213278
1259313279 "MUL saturation, saturation, temp.xxxx;" +
....@@ -12786,8 +13472,19 @@
1278613472 //once = true;
1278713473 }
1278813474
12789
- System.out.print("Program #" + mode + "; length = " + program.length());
12790
- System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13475
+ String program = programmax;
13476
+
13477
+ if (Globals.MINSHADER)
13478
+ {
13479
+ program = programmin;
13480
+ }
13481
+
13482
+ if (Globals.DEBUG)
13483
+ {
13484
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13485
+ System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13486
+ }
13487
+
1279113488 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1279213489
1279313490 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -12834,7 +13531,8 @@
1283413531 "\n" +
1283513532 "END\n";
1283613533
12837
- System.out.println("Program shadow #" + 0 + "; length = " + program.length());
13534
+ if (Globals.DEBUG)
13535
+ System.out.println("Program shadow #" + 0 + "; length = " + program.length());
1283813536 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1283913537
1284013538 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -12879,25 +13577,26 @@
1287913577 return out;
1288013578 }
1288113579
12882
- String TextureFetch(String dest, String src, String unit)
13580
+ // Also does frustum culling
13581
+ String ShadowTextureFetch(String dest, String src, String unit)
1288313582 {
1288413583 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1288513584 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1288613585 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13586
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13587
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1288713588 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12888
- "SLT " + src + ".z, " + src + ".x, one.x;" +
12889
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12890
- "SLT " + src + ".z, " + src + ".y, one.x;" +
12891
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13589
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13590
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1289213591 //"SWZ buffer, temp, w,w,w,w;";
12893
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13592
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1289413593 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1289513594 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1289613595 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
12897
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13596
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1289813597
12899
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
12900
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13598
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13599
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1290113600 }
1290213601
1290313602 String Shadow(String depth, String shadow)
....@@ -12919,12 +13618,16 @@
1291913618
1292013619 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1292113620 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13621
+
13622
+ // Compare fragment depth in light space with shadowmap.
1292213623 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1292313624 "SGE temp.y, temp.x, zero.x;" +
12924
- "SUB " + shadow + ".y, one.x, temp.y;" +
13625
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13626
+
13627
+ // Reverse comparison
1292513628 "SUB temp.x, one.x, temp.x;" +
1292613629 "MUL " + shadow + ".x, temp.x, temp.y;" +
12927
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13630
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1292813631 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1292913632
1293013633 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -12938,6 +13641,10 @@
1293813641 // No shadow for backface
1293913642 "DP3 temp.x, normal, lightd;" +
1294013643 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13644
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13645
+
13646
+ // No shadow when out of frustum
13647
+ "SGE temp.x, " + depth + ".z, one.z;" +
1294113648 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1294213649 "";
1294313650 }
....@@ -13083,8 +13790,9 @@
1308313790 /*static*/ float[] modelParams4 = new float[]{0, 0, 0, 0}; // anisoV, cameralight, selfshadow, shadow
1308413791 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1308513792 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
13086
- /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13087
- Object3D.cVector2[] vector2buffer;
13793
+ /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power, parallax
13794
+
13795
+ //Object3D.cVector2[] vector2buffer;
1308813796
1308913797 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1309013798 // OUT : diff, spec
....@@ -13100,9 +13808,10 @@
1310013808 "DP3 " + dest + ".z," + "normals," + "eye;" +
1310113809 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1310213810 //"MOV " + dest + ".w," + "normal.z;" +
13103
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
13104
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13105
- //"MOV " + dest + ".z," + "params2.w;" +
13811
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13812
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13813
+
13814
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1310613815 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1310713816 "RCP " + dest + ".w," + dest + ".w;" +
1310813817 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13248,7 +13957,7 @@
1324813957 "PARAM p[4] = { state.matrix.projection }; # modelview projection matrix\n" +
1324913958 "PARAM zero = { 0.0, 0.0, 0.0, 1.0 };" +
1325013959 "PARAM half = { 0.5, 0.5, 0.5, 1.0 };" +
13251
- "PARAM one = { 1.0, 1.0, 1.0, 0.0 };" +
13960
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
1325213961 "PARAM two = { 2.0, 2.0, 2.0, 1.0 };" +
1325313962 "PARAM third = { 0.33333333333, 0.33333333333, 0.33333333333, 1.0 };" +
1325413963 //"PARAM v256 = { 256.0, 256.0, 256.0, 1.0 };" +
....@@ -13309,7 +14018,7 @@
1330914018 "DP4 temp.x,state.matrix.texture[0].inverse.row[0],vertex.texcoord;" +
1331014019 "DP4 temp.y,state.matrix.texture[0].inverse.row[1],vertex.texcoord;" +
1331114020 "DP4 temp.z,state.matrix.texture[0].inverse.row[2],vertex.texcoord;" +
13312
- //"MOV result.texcoord, vertex.texcoord;" +
14021
+ //"MOV result.texcoord, vertex.fogcoord;" +
1331314022 "MOV result.texcoord, temp;" +
1331414023 // border fade
1331514024 "MOV result.texcoord[3], vertex.texcoord;" +
....@@ -13356,7 +14065,9 @@
1335614065
1335714066 //"ADD temp.z, temp.z, one;" +
1335814067
13359
- "MOV result.color, temp;"
14068
+ "MOV result.texcoord[4], vertex.attrib[4];" + // U dir
14069
+
14070
+ "MOV result.color, temp;" // Normal
1336014071 : "MOV result.color, vertex.color;") +
1336114072 ((mode & VP_PROJECTION) != 0 ? "MOV result.color, zero;"
1336214073 : "") +
....@@ -13496,7 +14207,7 @@
1349614207 public void mousePressed(MouseEvent e)
1349714208 {
1349814209 //System.out.println("mousePressed: " + e);
13499
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14210
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1350014211 }
1350114212
1350214213 static long prevtime = 0;
....@@ -13523,6 +14234,7 @@
1352314234
1352414235 //System.err.println("Dtime = " + Dtime + "; units = " + e.getUnitsToScroll() + "; ratio (units/ms) = " + ratio);
1352514236
14237
+ if (BUTTONLESSWHEEL)
1352614238 if (Math.abs(ratio) < 0.1 || Math.abs(Dtime) == 0) // < 30)
1352714239 {
1352814240 return;
....@@ -13531,7 +14243,7 @@
1353114243 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
1353214244
1353314245 // TIMER
13534
- if (!wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
14246
+ if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
1353514247 {
1353614248 keepboxmode = BOXMODE;
1353714249 keepsupport = SUPPORT;
....@@ -13571,8 +14283,8 @@
1357114283 // mode |= META;
1357214284 //}
1357314285
13574
- SetMouseMode(WHEEL | e.getModifiersEx());
13575
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14286
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14287
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1357614288 anchorX = ax;
1357714289 anchorY = ay;
1357814290 prevX = px;
....@@ -13606,6 +14318,7 @@
1360614318 else
1360714319 if (evt.getSource() == AAtimer)
1360814320 {
14321
+ Globals.TIMERRUNNING = false;
1360914322 if (mouseDown)
1361014323 {
1361114324 //new Exception().printStackTrace();
....@@ -13631,6 +14344,10 @@
1363114344 // LIVE = waslive;
1363214345 // wasliveok = true;
1363314346 // waslive = false;
14347
+
14348
+ // May 2019 Forget it:
14349
+ if (true)
14350
+ return;
1363414351
1363514352 // source == timer
1363614353 if (mouseDown)
....@@ -13661,7 +14378,7 @@
1366114378
1366214379 // fev 2014???
1366314380 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13664
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14381
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1366514382 pingthread.StepToTarget(true); // true);
1366614383 }
1366714384 // if (!LIVE)
....@@ -13670,12 +14387,13 @@
1367014387
1367114388 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1367214389
13673
- void clickStart(int x, int y, int modifiers)
14390
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1367414391 {
1367514392 if (!wasliveok)
1367614393 return;
1367714394
1367814395 AAtimer.restart(); //
14396
+ Globals.TIMERRUNNING = true;
1367914397
1368014398 // waslive = LIVE;
1368114399 // LIVE = false;
....@@ -13687,7 +14405,7 @@
1368714405 // touched = true; // main DL
1368814406 if (isRenderer)
1368914407 {
13690
- SetMouseMode(modifiers);
14408
+ SetMouseMode(modifiers, modifiersex);
1369114409 }
1369214410
1369314411 selectX = anchorX = x;
....@@ -13700,7 +14418,7 @@
1370014418 clicked = true;
1370114419 hold = false;
1370214420
13703
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14421
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1370414422 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1370514423 {
1370614424 // System.out.println("RESTART II " + modifiers);
....@@ -13725,14 +14443,15 @@
1372514443 drag = false;
1372614444 //System.out.println("Mouse DOWN");
1372714445 editObj = false;
13728
- ClickInfo info = new ClickInfo();
13729
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
13730
- info.pane = this;
13731
- info.camera = renderCamera;
13732
- info.x = x;
13733
- info.y = y;
13734
- info.modifiers = modifiers;
13735
- editObj = object.doEditClick(info, 0);
14446
+ //ClickInfo info = new ClickInfo();
14447
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14448
+ object.clickInfo.pane = this;
14449
+ object.clickInfo.camera = renderCamera;
14450
+ object.clickInfo.x = x;
14451
+ object.clickInfo.y = y;
14452
+ object.clickInfo.modifiers = modifiersex;
14453
+ editObj = object.doEditClick(//info,
14454
+ 0);
1373614455 if (!editObj)
1373714456 {
1373814457 hasMarquee = true;
....@@ -13748,11 +14467,14 @@
1374814467
1374914468 public void mouseDragged(MouseEvent e)
1375014469 {
14470
+ Globals.MOUSEDRAGGED = true;
14471
+
14472
+ //System.out.println("mouseDragged: " + e);
1375114473 if (isRenderer)
1375214474 movingcamera = true;
14475
+
1375314476 //if (drawing)
1375414477 //return;
13755
- //System.out.println("mouseDragged: " + e);
1375614478 if ((e.getModifiersEx() & CTRL) != 0
1375714479 || (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen())
1375814480 {
....@@ -13760,7 +14482,7 @@
1376014482 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1376114483 }
1376214484 else
13763
- drag(e.getX(), e.getY(), e.getModifiersEx());
14485
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1376414486
1376514487 //try { Thread.sleep(1); } catch (Exception ex) {}
1376614488 }
....@@ -13933,6 +14655,7 @@
1393314655
1393414656 public void run()
1393514657 {
14658
+ new Exception().printStackTrace();
1393614659 System.exit(0);
1393714660 for (;;)
1393814661 {
....@@ -13996,7 +14719,7 @@
1399614719 {
1399714720 Globals.lighttouched = true;
1399814721 }
13999
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14722
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1400014723 }
1400114724 //else
1400214725 }
....@@ -14010,12 +14733,18 @@
1401014733 void GoDown(int mod)
1401114734 {
1401214735 MODIFIERS |= COMMAND;
14013
- /*
14736
+ boolean isVR = (mouseMode&VR)!=0;
14737
+ /**/
1401414738 if((mod&SHIFT) == SHIFT)
14015
- manipCamera.RotatePosition(0, -speed);
14739
+ {
14740
+ if (isVR)
14741
+ manipCamera.RotateInterest(0, -speed);
14742
+ else
14743
+ manipCamera.RotatePosition(0, -speed);
14744
+ }
1401614745 else
14017
- manipCamera.BackForth(0, -speed*delta, getWidth());
14018
- */
14746
+ manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth());
14747
+ /**/
1401914748 if ((mod & SHIFT) == SHIFT)
1402014749 {
1402114750 mouseMode = mouseMode; // VR??
....@@ -14024,6 +14753,8 @@
1402414753 mouseMode |= BACKFORTH;
1402514754 }
1402614755
14756
+ targetLookAt.set(manipCamera.lookAt);
14757
+
1402714758 //prevX = X = anchorX;
1402814759 prevY = Y = anchorY - (int) (renderCamera.Distance());
1402914760 }
....@@ -14031,12 +14762,19 @@
1403114762 void GoUp(int mod)
1403214763 {
1403314764 MODIFIERS |= COMMAND;
14034
- /*
14765
+ /**/
14766
+ boolean isVR = (mouseMode&VR)!=0;
14767
+
1403514768 if((mod&SHIFT) == SHIFT)
14036
- manipCamera.RotatePosition(0, speed);
14769
+ {
14770
+ if (isVR)
14771
+ manipCamera.RotateInterest(0, speed);
14772
+ else
14773
+ manipCamera.RotatePosition(0, speed);
14774
+ }
1403714775 else
14038
- manipCamera.BackForth(0, speed*delta, getWidth());
14039
- */
14776
+ manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth());
14777
+ /**/
1404014778 if ((mod & SHIFT) == SHIFT)
1404114779 {
1404214780 mouseMode = mouseMode;
....@@ -14045,6 +14783,8 @@
1404514783 mouseMode |= BACKFORTH;
1404614784 }
1404714785
14786
+ targetLookAt.set(manipCamera.lookAt);
14787
+
1404814788 //prevX = X = anchorX;
1404914789 prevY = Y = anchorY + (int) (renderCamera.Distance());
1405014790 }
....@@ -14052,12 +14792,17 @@
1405214792 void GoLeft(int mod)
1405314793 {
1405414794 MODIFIERS |= COMMAND;
14055
- /*
14795
+ /**/
1405614796 if((mod&SHIFT) == SHIFT)
14057
- manipCamera.RotatePosition(speed, 0);
14797
+ manipCamera.Translate(speed*delta, 0, getWidth());
1405814798 else
14059
- manipCamera.Translate(speed*delta, 0, getWidth());
14060
- */
14799
+ {
14800
+ if ((mouseMode&VR)!=0)
14801
+ manipCamera.RotateInterest(-speed, 0);
14802
+ else
14803
+ manipCamera.RotatePosition(speed, 0);
14804
+ }
14805
+ /**/
1406114806 if ((mod & SHIFT) == SHIFT)
1406214807 {
1406314808 mouseMode = mouseMode;
....@@ -14066,6 +14811,8 @@
1406614811 mouseMode |= ROTATE;
1406714812 } // TRANSLATE;
1406814813
14814
+ targetLookAt.set(manipCamera.lookAt);
14815
+
1406914816 prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance());
1407014817 prevY = Y = anchorY;
1407114818 }
....@@ -14073,12 +14820,18 @@
1407314820 void GoRight(int mod)
1407414821 {
1407514822 MODIFIERS |= COMMAND;
14076
- /*
14823
+ /**/
1407714824 if((mod&SHIFT) == SHIFT)
14078
- manipCamera.RotatePosition(-speed, 0);
14825
+ manipCamera.Translate(-speed*delta, 0, getWidth());
1407914826 else
14080
- manipCamera.Translate(-speed*delta, 0, getWidth());
14081
- */
14827
+ {
14828
+ if ((mouseMode&VR)!=0)
14829
+ manipCamera.RotateInterest(speed, 0);
14830
+ else
14831
+ manipCamera.RotatePosition(-speed, 0);
14832
+ }
14833
+
14834
+ /**/
1408214835 if ((mod & SHIFT) == SHIFT)
1408314836 {
1408414837 mouseMode = mouseMode;
....@@ -14087,6 +14840,8 @@
1408714840 mouseMode |= ROTATE;
1408814841 } // TRANSLATE;
1408914842
14843
+ targetLookAt.set(manipCamera.lookAt);
14844
+
1409014845 prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance());
1409114846 prevY = Y = anchorY;
1409214847 }
....@@ -14096,7 +14851,7 @@
1409614851 int X, Y;
1409714852 boolean SX, SY;
1409814853
14099
- void drag(int x, int y, int modifiers)
14854
+ void drag(int x, int y, int modifiers, int modifiersex)
1410014855 {
1410114856 if (IsFrozen())
1410214857 {
....@@ -14105,17 +14860,17 @@
1410514860
1410614861 drag = true; // NEW
1410714862
14108
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14863
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1410914864
1411014865 X = x;
1411114866 Y = y;
1411214867 // floating state for animation
14113
- MODIFIERS = modifiers;
14114
- modifiers &= ~1024;
14868
+ MODIFIERS = modifiersex;
14869
+ modifiersex &= ~1024;
1411514870 if (false) // modifiers != 0)
1411614871 {
1411714872 //new Exception().printStackTrace();
14118
- System.out.println("mouseDragged: " + modifiers);
14873
+ System.out.println("mouseDragged: " + modifiersex);
1411914874 System.out.println("SHIFT = " + SHIFT);
1412014875 System.out.println("CONTROL = " + COMMAND);
1412114876 System.out.println("META = " + META);
....@@ -14128,14 +14883,16 @@
1412814883 if (editObj)
1412914884 {
1413014885 drag = true;
14131
- ClickInfo info = new ClickInfo();
14132
- info.bounds.setBounds(0, 0,
14886
+ //ClickInfo info = new ClickInfo();
14887
+ object.clickInfo.bounds.setBounds(0, 0,
1413314888 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14134
- info.pane = this;
14135
- info.camera = renderCamera;
14136
- info.x = x;
14137
- info.y = y;
14138
- object.editWindow.copy.doEditDrag(info);
14889
+ object.clickInfo.pane = this;
14890
+ object.clickInfo.camera = renderCamera;
14891
+ object.clickInfo.x = x;
14892
+ object.clickInfo.y = y;
14893
+ object //.GetWindow().copy
14894
+ .doEditDrag(//info,
14895
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1413914896 } else
1414014897 {
1414114898 if (x < startX)
....@@ -14284,23 +15041,27 @@
1428415041 }
1428515042 }
1428615043
15044
+// ClickInfo clickInfo = new ClickInfo();
15045
+
1428715046 public void mouseMoved(MouseEvent e)
1428815047 {
1428915048 //System.out.println("mouseMoved: " + e);
14290
-
1429115049 if (isRenderer)
1429215050 return;
1429315051
14294
- ClickInfo ci = new ClickInfo();
14295
- ci.x = e.getX();
14296
- ci.y = e.getY();
14297
- ci.modifiers = e.getModifiersEx();
14298
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14299
- ci.pane = this;
14300
- ci.camera = renderCamera;
15052
+ // Mouse cursor feedback
15053
+ object.clickInfo.x = e.getX();
15054
+ object.clickInfo.y = e.getY();
15055
+ object.clickInfo.modifiers = e.getModifiersEx();
15056
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
15057
+ object.clickInfo.pane = this;
15058
+ object.clickInfo.camera = renderCamera;
1430115059 if (!isRenderer)
1430215060 {
14303
- if (object.editWindow.copy.doEditClick(ci, 0))
15061
+ //ObjEditor editWindow = object.editWindow;
15062
+ //Object3D copy = editWindow.copy;
15063
+ if (object.doEditClick(//clickInfo,
15064
+ 0))
1430415065 {
1430515066 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1430615067 } else
....@@ -14312,7 +15073,11 @@
1431215073
1431315074 public void mouseReleased(MouseEvent e)
1431415075 {
15076
+ Globals.MOUSEDRAGGED = false;
15077
+
1431515078 movingcamera = false;
15079
+ X = 0; // getBounds().width/2;
15080
+ Y = 0; // getBounds().height/2;
1431615081 //System.out.println("mouseReleased: " + e);
1431715082 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1431815083 }
....@@ -14335,9 +15100,9 @@
1433515100 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1433615101 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1433715102
14338
- if (control || command || IsFrozen())
15103
+// No delay if (control || command || IsFrozen())
1433915104 timeout = true;
14340
- else
15105
+// ?? May 2019 else
1434115106 // timer.setDelay((modifiers & 128) != 0?0:350);
1434215107 mouseDown = false;
1434315108 if (!control && !command) // june 2013
....@@ -14447,7 +15212,7 @@
1444715212 System.out.println("keyReleased: " + e);
1444815213 }
1444915214
14450
- void SetMouseMode(int modifiers)
15215
+ void SetMouseMode(int modifiers, int modifiersex)
1445115216 {
1445215217 //System.out.println("SetMouseMode = " + modifiers);
1445315218 //modifiers &= ~1024;
....@@ -14459,25 +15224,25 @@
1445915224 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1446015225 // return;
1446115226 //System.out.println("SetMode = " + modifiers);
14462
- if ((modifiers & WHEEL) == WHEEL)
15227
+ if ((modifiersex & WHEEL) == WHEEL)
1446315228 {
1446415229 mouseMode |= ZOOM;
1446515230 }
1446615231
1446715232 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
14468
- if (capsLocked || (modifiers & META) == META)
15233
+ if (capsLocked) // || (modifiers & META) == META)
1446915234 {
1447015235 mouseMode |= VR; // BACKFORTH;
1447115236 }
14472
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
15237
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1447315238 {
1447415239 mouseMode |= SELECT;
1447515240 }
14476
- if ((modifiers & COMMAND) == COMMAND)
15241
+ if ((modifiersex & COMMAND) == COMMAND)
1447715242 {
1447815243 mouseMode |= SELECT;
1447915244 }
14480
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15245
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
1448115246 {
1448215247 mouseMode &= ~VR;
1448315248 mouseMode |= TRANSLATE;
....@@ -14506,7 +15271,7 @@
1450615271
1450715272 if (isRenderer) //
1450815273 {
14509
- SetMouseMode(modifiers);
15274
+ SetMouseMode(0, modifiers);
1451015275 }
1451115276
1451215277 Globals.theRenderer.keyPressed(key);
....@@ -14568,7 +15333,8 @@
1456815333 // break;
1456915334 case 'T':
1457015335 CACHETEXTURE ^= true;
14571
- textures.clear();
15336
+ texturepigment.clear();
15337
+ texturebump.clear();
1457215338 // repaint();
1457315339 break;
1457415340 case 'Y':
....@@ -14578,8 +15344,8 @@
1457815344 case 'K':
1457915345 KOMPACTTEXTURE ^= true;
1458015346 //textures.clear();
14581
- break;
14582
- case 'P': // Texture Projection macros
15347
+ // break;
15348
+ //case 'P': // Texture Projection macros
1458315349 // SAVETEXTURE ^= true;
1458415350 macromode = true;
1458515351 Udebug = Vdebug = NORMALdebug = false; programInitialized = false;
....@@ -14653,7 +15419,9 @@
1465315419 case 'E' : COMPACT ^= true;
1465415420 repaint();
1465515421 break;
14656
- case 'W' : DEBUGHSB ^= true;
15422
+ case 'W' : // Wide Window (fullscreen)
15423
+ //DEBUGHSB ^= true;
15424
+ ObjEditor.theFrame.ToggleFullScreen();
1465715425 repaint();
1465815426 break;
1465915427 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14678,8 +15446,8 @@
1467815446 RevertCamera();
1467915447 repaint();
1468015448 break;
14681
- case 'L':
1468215449 case 'l':
15450
+ //case 'L':
1468315451 if (lightMode)
1468415452 {
1468515453 lightMode = false;
....@@ -14698,7 +15466,7 @@
1469815466 targetLookAt.set(manipCamera.lookAt);
1469915467 repaint();
1470015468 break;
14701
- case 'p':
15469
+ case 'P': // p':
1470215470 // c'est quoi ca au juste? spherical ^= true;
1470315471 Skinshader ^= true; programInitialized = false;
1470415472 repaint();
....@@ -14743,20 +15511,24 @@
1474315511 OCCLUSION_CULLING ^= true;
1474415512 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1474515513 break;
14746
- case '0': envyoff ^= true; repaint(); break;
15514
+ //case '0': envyoff ^= true; repaint(); break;
1474715515 case '1':
1474815516 case '2':
1474915517 case '3':
1475015518 case '4':
1475115519 case '5':
14752
- newenvy = Character.getNumericValue(key);
14753
- repaint();
14754
- break;
1475515520 case '6':
1475615521 case '7':
1475715522 case '8':
1475815523 case '9':
14759
- BGcolor = (key - '6')/3.f;
15524
+ if (true) // envyoff)
15525
+ {
15526
+ BGcolor = (key - '1')/8.f;
15527
+ }
15528
+ else
15529
+ {
15530
+ //newenvy = Character.getNumericValue(key);
15531
+ }
1476015532 repaint();
1476115533 break;
1476215534 case '!':
....@@ -14822,9 +15594,9 @@
1482215594 case '_':
1482315595 kompactbit = 5;
1482415596 break;
14825
- case '+':
14826
- kompactbit = 6;
14827
- break;
15597
+// case '+':
15598
+// kompactbit = 6;
15599
+// break;
1482815600 case ' ':
1482915601 lightMode ^= true;
1483015602 Globals.lighttouched = true;
....@@ -14836,13 +15608,14 @@
1483615608 case ESC:
1483715609 RENDERPROGRAM += 1;
1483815610 RENDERPROGRAM %= 3;
15611
+
1483915612 repaint();
1484015613 break;
1484115614 case 'Z':
1484215615 //RESIZETEXTURE ^= true;
1484315616 //break;
1484415617 case 'z':
14845
- RENDERSHADOW ^= true;
15618
+ Globals.RENDERSHADOW ^= true;
1484615619 Globals.lighttouched = true;
1484715620 repaint();
1484815621 break;
....@@ -14875,8 +15648,9 @@
1487515648 case DELETE:
1487615649 ClearSelection();
1487715650 break;
14878
- /*
1487915651 case '+':
15652
+
15653
+ /*
1488015654 //fontsize += 1;
1488115655 bbzoom *= 2;
1488215656 repaint();
....@@ -14893,17 +15667,17 @@
1489315667 case '=':
1489415668 IncDepth();
1489515669 //fontsize += 1;
14896
- object.editWindow.refreshContents(true);
15670
+ object.GetWindow().refreshContents(true);
1489715671 maskbit = 6;
1489815672 break;
1489915673 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1490015674 DecDepth();
1490115675 maskbit = 5;
1490215676 //if(fontsize > 1) fontsize -= 1;
14903
- if (object.editWindow == null)
14904
- new Exception().printStackTrace();
14905
- else
14906
- object.editWindow.refreshContents(true);
15677
+// if (object.editWindow == null)
15678
+// new Exception().printStackTrace();
15679
+// else
15680
+ object.GetWindow().refreshContents(true);
1490715681 break;
1490815682 case '{':
1490915683 manipCamera.shaper_fovy /= 1.1;
....@@ -14966,7 +15740,7 @@
1496615740 //mode = ROTATE;
1496715741 if ((MODIFIERS & COMMAND) == 0) // VR??
1496815742 {
14969
- SetMouseMode(modifiers);
15743
+ SetMouseMode(0, modifiers);
1497015744 }
1497115745 }
1497215746
....@@ -15100,8 +15874,9 @@
1510015874
1510115875 protected void processMouseMotionEvent(MouseEvent e)
1510215876 {
15103
- //System.out.println("processMouseMotionEvent: " + mouseMode);
15104
- if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15877
+ //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
15878
+ //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15879
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1510515880 {
1510615881 mouseMoved(e);
1510715882 } else
....@@ -15126,11 +15901,12 @@
1512615901 }
1512715902 */
1512815903
15129
- object.editWindow.EditSelection();
15904
+ object.GetWindow().EditSelection(false);
1513015905 }
1513115906
1513215907 void SelectParent()
1513315908 {
15909
+ new Exception().printStackTrace();
1513415910 System.exit(0);
1513515911 Composite group = (Composite) object;
1513615912 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -15142,10 +15918,10 @@
1514215918 {
1514315919 //selectees.remove(i);
1514415920 System.out.println("select parent of " + elem);
15145
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15921
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1514615922 } else
1514715923 {
15148
- group.editWindow.Select(elem.GetTreePath(), first, true);
15924
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1514915925 }
1515015926
1515115927 first = false;
....@@ -15154,6 +15930,7 @@
1515415930
1515515931 void SelectChildren()
1515615932 {
15933
+ new Exception().printStackTrace();
1515715934 System.exit(0);
1515815935 /*
1515915936 Composite group = (Composite) object;
....@@ -15186,12 +15963,12 @@
1518615963 for (int j = 0; j < group.children.size(); j++)
1518715964 {
1518815965 elem = (Object3D) group.children.elementAt(j);
15189
- object.editWindow.Select(elem.GetTreePath(), first, true);
15966
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1519015967 first = false;
1519115968 }
1519215969 } else
1519315970 {
15194
- object.editWindow.Select(elem.GetTreePath(), first, true);
15971
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1519515972 }
1519615973
1519715974 first = false;
....@@ -15202,21 +15979,21 @@
1520215979 {
1520315980 //Composite group = (Composite) object;
1520415981 Object3D group = object;
15205
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15982
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1520615983 }
1520715984
1520815985 void ResetTransform(int mask)
1520915986 {
1521015987 //Composite group = (Composite) object;
1521115988 Object3D group = object;
15212
- group.editWindow.ResetTransform(mask);
15989
+ group.GetWindow().ResetTransform(mask);
1521315990 }
1521415991
1521515992 void FlipTransform()
1521615993 {
1521715994 //Composite group = (Composite) object;
1521815995 Object3D group = object;
15219
- group.editWindow.FlipTransform();
15996
+ group.GetWindow().FlipTransform();
1522015997 // group.editWindow.ReduceMesh(true);
1522115998 }
1522215999
....@@ -15224,7 +16001,7 @@
1522416001 {
1522516002 //Composite group = (Composite) object;
1522616003 Object3D group = object;
15227
- group.editWindow.PrintMemory();
16004
+ group.GetWindow().PrintMemory();
1522816005 // group.editWindow.ReduceMesh(true);
1522916006 }
1523016007
....@@ -15232,7 +16009,7 @@
1523216009 {
1523316010 //Composite group = (Composite) object;
1523416011 Object3D group = object;
15235
- group.editWindow.ResetCentroid();
16012
+ group.GetWindow().ResetCentroid();
1523616013 }
1523716014
1523816015 void IncDepth()
....@@ -15314,11 +16091,11 @@
1531416091
1531516092 int width = getBounds().width;
1531616093 int height = getBounds().height;
15317
- ClickInfo info = new ClickInfo();
15318
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1531916094 //Image img = CreateImage(width, height);
1532016095 //System.out.println("width = " + width + "; height = " + height + "\n");
16096
+
1532116097 Graphics gr = g; // img.getGraphics();
16098
+
1532216099 if (!hasMarquee)
1532316100 {
1532416101 if (Xmin < Xmax) // !locked)
....@@ -15390,44 +16167,92 @@
1539016167 }
1539116168 if (object != null && !hasMarquee)
1539216169 {
16170
+ if (object.clickInfo == null)
16171
+ object.clickInfo = new ClickInfo();
16172
+ ClickInfo info = object.clickInfo;
16173
+ //ClickInfo info = new ClickInfo();
16174
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16175
+
1539316176 if (isRenderer)
1539416177 {
15395
- info.flags++;
16178
+ object.clickInfo.flags++;
1539616179 double frameAspect = (double) width / (double) height;
1539716180 if (frameAspect > renderCamera.aspect)
1539816181 {
1539916182 int desired = (int) ((double) height * renderCamera.aspect);
15400
- info.bounds.width -= width - desired;
15401
- info.bounds.x += (width - desired) / 2;
16183
+ object.clickInfo.bounds.width -= width - desired;
16184
+ object.clickInfo.bounds.x += (width - desired) / 2;
1540216185 } else
1540316186 {
1540416187 int desired = (int) ((double) width / renderCamera.aspect);
15405
- info.bounds.height -= height - desired;
15406
- info.bounds.y += (height - desired) / 2;
16188
+ object.clickInfo.bounds.height -= height - desired;
16189
+ object.clickInfo.bounds.y += (height - desired) / 2;
1540716190 }
1540816191 }
15409
- info.g = gr;
15410
- info.camera = renderCamera;
16192
+
16193
+ object.clickInfo.g = gr;
16194
+ object.clickInfo.camera = renderCamera;
1541116195 /*
1541216196 // Memory intensive (brep.verticescopy)
1541316197 if (!(object instanceof Composite))
1541416198 object.draw(info, 0, false); // SLOW :
1541516199 */
15416
- if (!isRenderer)
16200
+ if (!isRenderer) // && drag)
1541716201 {
15418
- object.drawEditHandles(info, 0);
16202
+ Grafreed.Assert(object != null);
16203
+ Grafreed.Assert(object.selection != null);
16204
+ if (object.selection.Size() > 0)
16205
+ {
16206
+ int hitSomething = object.selection.get(0).hitSomething;
16207
+
16208
+ object.clickInfo.DX = 0;
16209
+ object.clickInfo.DY = 0;
16210
+ object.clickInfo.W = 1;
16211
+ if (hitSomething == Object3D.hitCenter)
16212
+ {
16213
+ info.DX = X;
16214
+ if (X != 0)
16215
+ info.DX -= info.bounds.width/2;
16216
+
16217
+ info.DY = Y;
16218
+ if (Y != 0)
16219
+ info.DY -= info.bounds.height/2;
16220
+ }
16221
+
16222
+ object.drawEditHandles(//info,
16223
+ 0);
16224
+
16225
+ if (drag && (X != 0 || Y != 0))
16226
+ {
16227
+ switch (hitSomething)
16228
+ {
16229
+ case Object3D.hitCenter: gr.setColor(Color.white);
16230
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16231
+ break;
16232
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16233
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16234
+ break;
16235
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16236
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16237
+ break;
16238
+ }
16239
+
16240
+ }
16241
+ }
1541916242 }
1542016243 }
16244
+
1542116245 if (isRenderer)
1542216246 {
1542316247 //gr.setColor(Color.black);
1542416248 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1542516249 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1542616250 }
16251
+
1542716252 if (hasMarquee)
1542816253 {
1542916254 gr.setXORMode(Color.white);
15430
- gr.setColor(Color.red);
16255
+ gr.setColor(Color.white);
1543116256 if (!firstime)
1543216257 {
1543316258 gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH);
....@@ -15536,6 +16361,7 @@
1553616361 public boolean mouseDown(Event evt, int x, int y)
1553716362 {
1553816363 System.out.println("mouseDown: " + evt);
16364
+ System.exit(0);
1553916365 /*
1554016366 locked = true;
1554116367 drag = false;
....@@ -15579,7 +16405,7 @@
1557916405 {
1558016406 keyPressed(0, modifiers);
1558116407 }
15582
- clickStart(x, y, modifiers);
16408
+ // clickStart(x, y, modifiers);
1558316409 return true;
1558416410 }
1558516411
....@@ -15697,7 +16523,7 @@
1569716523 {
1569816524 keyReleased(0, 0);
1569916525 }
15700
- drag(x, y, modifiers);
16526
+ drag(x, y, 0, modifiers);
1570116527 return true;
1570216528 }
1570316529
....@@ -15829,7 +16655,7 @@
1582916655 Object3D object;
1583016656 static Object3D trackedobject;
1583116657 Camera renderCamera; // Light or Eye (or Occlusion)
15832
- /*static*/ Camera manipCamera; // Light or Eye
16658
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1583316659 /*static*/ Camera eyeCamera;
1583416660 /*static*/ Camera lightCamera;
1583516661 int cameracount;
....@@ -15893,6 +16719,8 @@
1589316719 private /*static*/ boolean firstime;
1589416720 private /*static*/ cVector newView = new cVector();
1589516721 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16722
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16723
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1589616724 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1589716725 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1589816726 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -15905,29 +16733,67 @@
1590516733 {
1590616734 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1590716735
16736
+ int usedsuf = 0;
16737
+
1590816738 for (int i = 0; i < suffixes.length; i++)
1590916739 {
15910
- String resourceName = basename + suffixes[i] + "." + suffix;
15911
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
15912
- mipmapped,
15913
- FileUtil.getFileSuffix(resourceName));
15914
- if (data == null)
16740
+ String[] suffixe = suffixes;
16741
+ String[] fallback = suffixes2;
16742
+ String[] fallfallback = suffixes3;
16743
+
16744
+ for (int c=usedsuf; --c>=0;)
1591516745 {
15916
- throw new IOException("Unable to load texture " + resourceName);
16746
+// String[] temp = suffixe;
16747
+// suffixe = fallback;
16748
+// fallback = fallfallback;
16749
+// fallfallback = temp;
1591716750 }
16751
+
16752
+ String resourceName = basename + suffixe[i] + "." + suffix;
16753
+ TextureData data;
16754
+
16755
+ try
16756
+ {
16757
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16758
+ mipmapped,
16759
+ FileUtil.getFileSuffix(resourceName));
16760
+ }
16761
+ catch (Exception e)
16762
+ {
16763
+ try
16764
+ {
16765
+ resourceName = basename + fallback[i] + "." + suffix;
16766
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16767
+ mipmapped,
16768
+ FileUtil.getFileSuffix(resourceName));
16769
+ }
16770
+ catch (Exception e2)
16771
+ {
16772
+ resourceName = basename + fallfallback[i] + "." + suffix;
16773
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16774
+ mipmapped,
16775
+ FileUtil.getFileSuffix(resourceName));
16776
+ }
16777
+ }
16778
+
1591816779 //System.out.println("Target = " + targets[i]);
1591916780 cubemap.updateImage(data, targets[i]);
1592016781 }
1592116782
1592216783 return cubemap;
1592316784 }
16785
+
1592416786 int bigsphere = -1;
1592516787
1592616788 float BGcolor = 0.5f;
1592716789
15928
- private void DrawSkyBox(GL gl)
16790
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16791
+
16792
+ private void DrawSkyBox(GL gl, float ratio)
1592916793 {
15930
- if (envyoff || cubemap == null)
16794
+ if (//envyoff ||
16795
+ WIREFRAME ||
16796
+ cubemap == null)
1593116797 {
1593216798 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1593316799 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -15942,7 +16808,17 @@
1594216808 // Compensates for ExaminerViewer's modification of modelview matrix
1594316809 gl.glMatrixMode(GL.GL_MODELVIEW);
1594416810 gl.glLoadIdentity();
16811
+ gl.glScalef(1,ratio,1);
1594516812
16813
+// colorV[0] = 2;
16814
+// colorV[1] = 2;
16815
+// colorV[2] = 2;
16816
+// colorV[3] = 1;
16817
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16818
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16819
+//
16820
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16821
+
1594616822 //gl.glActiveTexture(GL.GL_TEXTURE1);
1594716823 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1594816824
....@@ -15974,6 +16850,7 @@
1597416850 {
1597516851 gl.glScalef(1.0f, -1.0f, 1.0f);
1597616852 }
16853
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1597716854 gl.glMultMatrixd(viewrot_1, 0);
1597816855 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1597916856 //viewer.updateInverseRotation(gl);
....@@ -16014,7 +16891,8 @@
1601416891 gl.glDisable(GL.GL_TEXTURE_GEN_R);
1601516892
1601616893 cubemap.disable();
16017
- ////cubemap.unbind();
16894
+ //cubemap.dispose();
16895
+
1601816896 if (CULLFACE)
1601916897 {
1602016898 gl.glEnable(gl.GL_CULL_FACE);
....@@ -16070,7 +16948,7 @@
1607016948 gl.glScalef(1.0f, -1.0f, 1.0f);
1607116949 }
1607216950
16073
- gl.glNormal3f(0.0f, 0.0f, 1.0f);
16951
+ SetGLNormal(gl, 0.0f, 0.0f, 1.0f);
1607416952
1607516953 float step = 2; // 0.1666f; //0.25f;
1607616954 float stepv = 2; // step * 1652 / 998;
....@@ -16114,16 +16992,16 @@
1611416992 cStatic.objectstack[materialdepth++] = checker;
1611516993 //System.out.println("material " + material);
1611616994 //Applet3D.tracein(this, selected);
16117
- vector2buffer = checker.projectedVertices;
16995
+ //vector2buffer = checker.projectedVertices;
1611816996
1611916997 //checker.GetMaterial().Draw(this, false); // true);
16120
- DrawMaterial(checker.GetMaterial(), false); // true);
16998
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1612116999
1612217000 materialdepth -= 1;
1612317001 if (materialdepth > 0)
1612417002 {
16125
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16126
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
17003
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
17004
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1612717005 }
1612817006 //checker.GetMaterial().opacity = 1f;
1612917007 ////checker.GetMaterial().ambient = 1f;
....@@ -16209,6 +17087,14 @@
1620917087 }
1621017088 }
1621117089
17090
+ private Object3D GetFolder()
17091
+ {
17092
+ Object3D folder = object.GetWindow().copy;
17093
+ if (object.GetWindow().copy.selection.Size() > 0)
17094
+ folder = object.GetWindow().copy.selection.elementAt(0);
17095
+ return folder;
17096
+ }
17097
+
1621217098 class SelectBuffer implements GLEventListener
1621317099 {
1621417100
....@@ -16224,7 +17110,7 @@
1622417110 //new Exception().printStackTrace();
1622517111 System.out.println("select buffer init");
1622617112 // Use debug pipeline
16227
- drawable.setGL(new DebugGL(drawable.getGL()));
17113
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1622817114
1622917115 GL gl = drawable.getGL();
1623017116
....@@ -16267,6 +17153,7 @@
1626717153 {
1626817154 if (!selection)
1626917155 {
17156
+ new Exception().printStackTrace();
1627017157 System.exit(0);
1627117158 return;
1627217159 }
....@@ -16287,6 +17174,17 @@
1628717174
1628817175 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1628917176
17177
+ if (PAINTMODE)
17178
+ {
17179
+ if (object.GetWindow().copy.selection.Size() > 0)
17180
+ {
17181
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17182
+
17183
+ // Make what you paint not selectable.
17184
+ paintobj.ResetSelectable();
17185
+ }
17186
+ }
17187
+
1629017188 //int tmp = selection_view;
1629117189 //selection_view = -1;
1629217190 int temp = DrawMode();
....@@ -16298,6 +17196,17 @@
1629817196 // temp = DEFAULT; // patch for selection debug
1629917197 Globals.drawMode = temp; // WARNING
1630017198
17199
+ if (PAINTMODE)
17200
+ {
17201
+ if (object.GetWindow().copy.selection.Size() > 0)
17202
+ {
17203
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17204
+
17205
+ // Revert.
17206
+ paintobj.RestoreSelectable();
17207
+ }
17208
+ }
17209
+
1630117210 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1630217211
1630317212 // trying different ways of getting the depth info over
....@@ -16345,6 +17254,8 @@
1634517254 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1634617255 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1634717256 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
17257
+
17258
+ CreateSelectedPoint();
1634817259
1634917260 // Will fit the mesh !!!
1635017261 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16394,34 +17305,36 @@
1639417305 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]));
1639517306 }
1639617307
16397
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
17308
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1639817309 }
1639917310 }
1640017311
1640117312 if (!movingcamera && !PAINTMODE)
16402
- object.editWindow.ScreenFitPoint(); // fev 2014
17313
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1640317314
16404
- if (PAINTMODE && GrafreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17315
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1640517316 {
16406
- Object3D paintobj = GrafreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17317
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1640717318
16408
- Object3D group = new Object3D("inst" + paintcount++);
17319
+ if (object.GetWindow().copy.selection.Size() > 0)
17320
+ {
17321
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1640917322
16410
- group.CreateMaterial(); // use a void leaf to select instances
16411
-
16412
- group.add(paintobj); // link
16413
-
16414
- object.editWindow.SnapObject(group);
16415
-
16416
- Object3D folder = object.editWindow.copy;
16417
-
16418
- if (object.editWindow.copy.selection.Size() > 0)
16419
- folder = object.editWindow.copy.selection.elementAt(0);
16420
-
16421
- folder.add(group);
16422
-
16423
- object.editWindow.ResetModel();
16424
- object.editWindow.refreshContents();
17323
+ Object3D inst = new Object3D("inst" + paintcount++);
17324
+
17325
+ inst.CreateMaterial(); // use a void leaf to select instances
17326
+
17327
+ inst.add(paintobj); // link
17328
+
17329
+ object.GetWindow().SnapObject(inst);
17330
+
17331
+ Object3D folder = paintFolder; // GetFolder();
17332
+
17333
+ folder.add(inst);
17334
+
17335
+ object.GetWindow().ResetModel();
17336
+ object.GetWindow().refreshContents();
17337
+ }
1642517338 }
1642617339 else
1642717340 paintcount = 0;
....@@ -16460,6 +17373,11 @@
1646017373 //System.out.println("objects[color] = " + objects[color]);
1646117374 //objects[color].Select();
1646217375 indexcount = 0;
17376
+ ObjEditor window = object.GetWindow();
17377
+ if (window != null && deselect)
17378
+ {
17379
+ window.Select(null, deselect, true);
17380
+ }
1646317381 object.Select(color, deselect);
1646417382 }
1646517383
....@@ -16510,6 +17428,7 @@
1651017428
1651117429 public void init(GLAutoDrawable drawable)
1651217430 {
17431
+ if (Globals.DEBUG)
1651317432 System.out.println("shadow buffer init");
1651417433
1651517434 GL gl = drawable.getGL();
....@@ -16559,7 +17478,7 @@
1655917478 gl.glDisable(gl.GL_CULL_FACE);
1656017479 }
1656117480
16562
- if (!RENDERSHADOW)
17481
+ if (!Globals.RENDERSHADOW)
1656317482 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1656417483
1656517484 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -16569,7 +17488,7 @@
1656917488 //gl.glColorMask(false, false, false, false);
1657017489
1657117490 //render_scene_from_light_view(gl, drawable, 0, 0);
16572
- if (RENDERSHADOW && Globals.lighttouched && !movingcamera) // && !parent.IsFreezed())
17491
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1657317492 {
1657417493 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1657517494
....@@ -16738,10 +17657,14 @@
1673817657 gl.glFlush();
1673917658
1674017659 /**/
16741
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17660
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1674217661
16743
- float[] pixels = occlusionsizebuffer.array();
17662
+ float[] depths = occlusiondepthbuffer.array();
1674417663
17664
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17665
+
17666
+ int[] pixels = selectsizebuffer.array();
17667
+
1674517668 double r = 0, g = 0, b = 0;
1674617669
1674717670 double count = 0;
....@@ -16752,7 +17675,7 @@
1675217675
1675317676 double FACTOR = 1;
1675417677
16755
- for (int i = 0; i < pixels.length; i++)
17678
+ for (int i = 0; i < depths.length; i++)
1675617679 {
1675717680 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1675817681 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -16835,7 +17758,7 @@
1683517758
1683617759 double scale = ray.z; // 1; // cos
1683717760
16838
- float depth = pixels[newindex];
17761
+ float depth = depths[newindex];
1683917762
1684017763 /*
1684117764 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -16985,23 +17908,15 @@
1698517908 int AAbuffersize = 0;
1698617909
1698717910 //double[] selectedpoint = new double[3];
16988
- static Superellipsoid selectedpoint = new Superellipsoid();
17911
+ static Superellipsoid selectedpoint;
1698917912 static Sphere previousselectedpoint = null;
16990
- static Sphere debugpointG = new Sphere();
16991
- static Sphere debugpointP = new Sphere();
16992
- static Sphere debugpointC = new Sphere();
16993
- static Sphere debugpointR = new Sphere();
17913
+ static Sphere debugpointG;
17914
+ static Sphere debugpointP;
17915
+ static Sphere debugpointC;
17916
+ static Sphere debugpointR;
1699417917
1699517918 static Sphere debugpoints[] = new Sphere[8];
1699617919
16997
- static
16998
- {
16999
- for (int i=0; i<8; i++)
17000
- {
17001
- debugpoints[i] = new Sphere();
17002
- }
17003
- }
17004
-
1700517920 static void InitPoints(float radius)
1700617921 {
1700717922 for (int i=0; i<8; i++)
....@@ -17040,11 +17955,14 @@
1704017955 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1704117956 static IntBuffer bigAAbuffer;
1704217957 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
17043
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17958
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1704417959 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1704517960 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1704617961 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17047
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17962
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17963
+
17964
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17965
+
1704817966 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1704917967 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1705017968 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();