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
....@@ -86,7 +124,7 @@
86124 static boolean FULLSCREEN = false;
87125 static boolean SUPPORT = true;
88126 static boolean INERTIA = true;
89
-static boolean FAST = true; // false;
127
+static boolean FAST = false;
90128 static boolean SLOWPOSE = false;
91129 static boolean FOOTCONTACT = true;
92130
....@@ -108,7 +146,7 @@
108146 static boolean OEIL = true;
109147 static boolean OEILONCE = false; // do oeilon then oeiloff
110148 static boolean LOOKAT = true;
111
-static boolean RANDOM = true; // false;
149
+static boolean SWITCH = true; // false;
112150 static boolean HANDLES = false; // selection doesn't work!!
113151 static boolean PAINTMODE = false;
114152
....@@ -130,7 +168,7 @@
130168
131169
132170 // OPTIONS
133
- boolean Skinshader = true;
171
+ boolean Skinshader = false; // true;
134172 boolean cameraLight = false;
135173 boolean UVdebug = false;
136174 boolean Udebug = false;
....@@ -139,7 +177,7 @@
139177 static boolean doublesided = false; // true; // reversed normals are awful for conformance
140178 boolean anisotropy = true;
141179 boolean softshadow = true; // slower but better false;
142
- boolean opacityhalo = false;
180
+ boolean opacityhalo = false; // reverse the halo effect (e.g. glass)
143181
144182 boolean macromode = false;
145183
....@@ -150,6 +188,21 @@
150188 defaultcaps.setAccumGreenBits(16);
151189 defaultcaps.setAccumBlueBits(16);
152190 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
+ }
153206 }
154207
155208 void SetAsGLRenderer(boolean b)
....@@ -170,7 +223,8 @@
170223
171224 SetCamera(cam);
172225
173
- SetLight(new Camera(new cVector(10, 10, -20)));
226
+ // Warning: not used.
227
+ SetLight(new Camera(new cVector(15, 10, -20)));
174228
175229 object = o;
176230
....@@ -327,7 +381,7 @@
327381 cStatic.objectstack[materialdepth++] = obj;
328382 //System.out.println("material " + material);
329383 //Applet3D.tracein(this, selected);
330
- display.vector2buffer = obj.projectedVertices;
384
+ //display.vector2buffer = obj.projectedVertices;
331385 if (obj instanceof Camera)
332386 {
333387 display.options1[0] = material.shift;
....@@ -336,14 +390,28 @@
336390 display.options1[2] = material.shadowbias;
337391 display.options1[3] = material.aniso;
338392 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]);
339398 display.options2[0] = material.opacity;
340399 display.options2[1] = material.diffuse;
341400 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]);
342404
343405 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]);
344409 display.options4[0] = material.cameralight/0.2f;
345410 display.options4[1] = material.subsurface;
346411 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]);
347415
348416 // if (display.CURRENTANTIALIAS > 0)
349417 // display.options3[3] /= 4;
....@@ -359,7 +427,7 @@
359427 /**/
360428 } else
361429 {
362
- DrawMaterial(material, selected);
430
+ DrawMaterial(material, selected, obj.projectedVertices);
363431 }
364432 } else
365433 {
....@@ -383,8 +451,8 @@
383451 cStatic.objectstack[materialdepth++] = obj;
384452 //System.out.println("material " + material);
385453 //Applet3D.tracein("selected ", selected);
386
- display.vector2buffer = obj.projectedVertices;
387
- display.DrawMaterial(material, selected);
454
+ //display.vector2buffer = obj.projectedVertices;
455
+ display.DrawMaterial(material, selected, obj.projectedVertices);
388456 }
389457 }
390458
....@@ -401,8 +469,8 @@
401469 materialdepth -= 1;
402470 if (materialdepth > 0)
403471 {
404
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
405
- 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);
406474 }
407475 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
408476 } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
....@@ -422,8 +490,8 @@
422490 materialdepth -= 1;
423491 if (materialdepth > 0)
424492 {
425
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
426
- 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);
427495 }
428496 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
429497 //else
....@@ -464,15 +532,18 @@
464532 if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
465533 {
466534 //gl.glBegin(gl.GL_TRIANGLES);
467
- 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
+ ;
468538 if (!hasnorm)
469539 {
470
- // System.out.println("FUCK!!");
540
+ // System.out.println("Mesh normal");
471541 LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
472542 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
473543 LA.vecCross(obj.v0, obj.v1, obj.v2);
474544 LA.vecNormalize(obj.v2);
475
- 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);
476547 }
477548
478549 // P
....@@ -494,7 +565,7 @@
494565 y += ny * obj.NORMALPUSH;
495566 z += nz * obj.NORMALPUSH;
496567
497
- gl.glNormal3f(nx, ny, nz);
568
+ SetGLNormal(gl, nx, ny, nz);
498569 }
499570 gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
500571 SetColor(obj, pv);
....@@ -526,7 +597,7 @@
526597 y += ny * obj.NORMALPUSH;
527598 z += nz * obj.NORMALPUSH;
528599
529
- gl.glNormal3f(nx, ny, nz);
600
+ SetGLNormal(gl, nx, ny, nz);
530601 }
531602 //System.out.println("vertexq = " + qv.s + ", " + qv.t);
532603 // boolean locked = false;
....@@ -574,7 +645,7 @@
574645 y += ny * obj.NORMALPUSH;
575646 z += nz * obj.NORMALPUSH;
576647
577
- gl.glNormal3f(nx, ny, nz);
648
+ SetGLNormal(gl, nx, ny, nz);
578649 }
579650
580651 // if ((dot&4) == 0)
....@@ -1180,10 +1251,10 @@
11801251 {
11811252 if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
11821253 {
1183
- gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1254
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
11841255 } else
11851256 {
1186
- gl.glNormal3f(0, 0, 1);
1257
+ SetGLNormal(gl, 0, 0, 1);
11871258 }
11881259
11891260 if (c != null)
....@@ -1192,10 +1263,12 @@
11921263 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
11931264 }
11941265 }
1266
+
11951267 if (flipV)
11961268 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
11971269 else
11981270 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1271
+
11991272 //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
12001273 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
12011274
....@@ -1205,20 +1278,22 @@
12051278 {
12061279 if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
12071280 {
1208
- gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1281
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
12091282 } else
12101283 {
1211
- gl.glNormal3f(0, 0, 1);
1284
+ SetGLNormal(gl, 0, 0, 1);
12121285 }
12131286 if (c != null)
12141287 {
12151288 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
12161289 }
12171290 }
1291
+
12181292 if (flipV)
12191293 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12201294 else
12211295 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1296
+
12221297 //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
12231298 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
12241299
....@@ -1231,10 +1306,10 @@
12311306 {
12321307 if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
12331308 {
1234
- gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1309
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
12351310 } else
12361311 {
1237
- gl.glNormal3f(0, 0, 1);
1312
+ SetGLNormal(gl, 0, 0, 1);
12381313 }
12391314 if (c != null)
12401315 {
....@@ -1246,8 +1321,10 @@
12461321 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12471322 else
12481323 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1324
+
12491325 //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
12501326 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1327
+
12511328 count2 += 2;
12521329 count3 += 3;
12531330 }
....@@ -1414,7 +1491,7 @@
14141491 {
14151492 if (!selectmode)
14161493 {
1417
- 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);
14181495 gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
14191496
14201497 if (flipV)
....@@ -1426,6 +1503,8 @@
14261503 gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
14271504 }
14281505
1506
+ float[] colorV = new float[4];
1507
+
14291508 void SetColor(Object3D obj, Vertex p0)
14301509 {
14311510 CameraPane display = this;
....@@ -1493,8 +1572,6 @@
14931572 {
14941573 return;
14951574 }
1496
-
1497
- float[] colorV = new float[3];
14981575
14991576 if (false) // marked)
15001577 {
....@@ -1603,7 +1680,7 @@
16031680 // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
16041681 }
16051682
1606
- void DrawMaterial(cMaterial material, boolean selected)
1683
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
16071684 {
16081685 CameraPane display = this;
16091686 //new Exception().printStackTrace();
....@@ -1630,7 +1707,7 @@
16301707
16311708 cColor.HSBtoRGB(display.color, display.saturation, 1, display.modelParams0);
16321709
1633
- float[] colorV = GrafreeD.colorV;
1710
+ float[] colorV = Grafreed.colorV;
16341711
16351712 /**/
16361713 if (display.DrawMode() == display.DEFAULT) // && display.RENDERPROGRAM == 0)
....@@ -1638,7 +1715,7 @@
16381715 colorV[0] = display.modelParams0[0] * material.diffuse;
16391716 colorV[1] = display.modelParams0[1] * material.diffuse;
16401717 colorV[2] = display.modelParams0[2] * material.diffuse;
1641
- colorV[3] = material.opacity;
1718
+ colorV[3] = 1; // material.opacity;
16421719
16431720 gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
16441721 //System.out.println("Opacity = " + opacity);
....@@ -1743,12 +1820,12 @@
17431820
17441821 display.modelParams7[0] = 0;
17451822 display.modelParams7[1] = 1000;
1746
- display.modelParams7[2] = 0;
1823
+ display.modelParams7[2] = material.parallax;
17471824 display.modelParams7[3] = 0;
17481825
1749
- display.modelParams6[0] = 100; // criss de bug de bump
1826
+ //display.modelParams6[0] = 100; // criss de bug de bump
17501827
1751
- Object3D.cVector2[] extparams = display.vector2buffer;
1828
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
17521829 if (extparams != null && extparams.length > 0 && extparams[0] != null)
17531830 {
17541831 display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
....@@ -1890,7 +1967,7 @@
18901967 void PushMatrix(double[][] matrix)
18911968 {
18921969 // GrafreeD.tracein(matrix);
1893
- PushMatrix(matrix,1);
1970
+ PushMatrix(matrix, 1);
18941971 }
18951972
18961973 void PushMatrix()
....@@ -1976,9 +2053,9 @@
19762053 switch(viewcode)
19772054 {
19782055 case 0: return "main";
1979
- case 1: return "one";
1980
- case 2: return "two";
1981
- case 3: return "three";
2056
+ case 1: return "Red";
2057
+ case 2: return "Green";
2058
+ case 3: return "Blue";
19822059 case 4: return "light";
19832060 }
19842061
....@@ -2044,7 +2121,7 @@
20442121 //System.err.println("Oeil on");
20452122 OEIL = true;
20462123 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2047
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2124
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
20482125 //pingthread.StepToTarget(true);
20492126 }
20502127
....@@ -2142,7 +2219,7 @@
21422219 System.err.println("LIVE = " + Globals.isLIVE());
21432220
21442221 if (!Globals.isLIVE()) // save sound
2145
- GrafreeD.savesound = true; // wav.save();
2222
+ Grafreed.savesound = true; // wav.save();
21462223 // else
21472224 repaint(); // start loop // may 2013
21482225 }
....@@ -2259,7 +2336,7 @@
22592336
22602337 void ToggleDebug()
22612338 {
2262
- DEBUG ^= true;
2339
+ Globals.DEBUG ^= true;
22632340 }
22642341
22652342 void ToggleLookAt()
....@@ -2267,9 +2344,9 @@
22672344 LOOKAT ^= true;
22682345 }
22692346
2270
- void ToggleRandom()
2347
+ void ToggleSwitch()
22712348 {
2272
- RANDOM ^= true;
2349
+ SWITCH ^= true;
22732350 }
22742351
22752352 void ToggleHandles()
....@@ -2277,10 +2354,17 @@
22772354 HANDLES ^= true;
22782355 }
22792356
2357
+ Object3D paintFolder;
2358
+
22802359 void TogglePaint()
22812360 {
22822361 PAINTMODE ^= true;
22832362 paintcount = 0;
2363
+
2364
+ if (PAINTMODE)
2365
+ {
2366
+ paintFolder = GetFolder();
2367
+ }
22842368 }
22852369
22862370 void SwapCamera(int a, int b)
....@@ -2376,7 +2460,34 @@
23762460 {
23772461 return currentGL;
23782462 }
2379
-
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
+
23802491 /**/
23812492 class CacheTexture
23822493 {
....@@ -2385,28 +2496,31 @@
23852496
23862497 int resolution;
23872498
2388
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2499
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
23892500 {
2390
- texture = tex;
2501
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2502
+ texturedata = texdata;
23912503 resolution = res;
23922504 }
23932505 }
23942506 /**/
23952507
23962508 // TEXTURE static Texture texture;
2397
- static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures
2398
- = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>();
2399
- 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
+
24002514 int pigmentdepth = 0;
24012515 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
24022516 int bumpdepth = 0;
24032517 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
24042518 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
24052519 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2406
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2520
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
24072521 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
24082522
2409
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2523
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
24102524 {
24112525 TextureData texturedata = null;
24122526
....@@ -2416,7 +2530,7 @@
24162530 com.sun.opengl.util.texture.TextureIO.newTextureData(
24172531 getClass().getClassLoader().getResourceAsStream(name),
24182532 true,
2419
- com.sun.opengl.util.texture.TextureIO.PNG);
2533
+ GetFormat(name)); // com.sun.opengl.util.texture.TextureIO.PNG);
24202534 } catch (java.io.IOException e)
24212535 {
24222536 throw new javax.media.opengl.GLException(e);
....@@ -2425,13 +2539,34 @@
24252539 if (bump)
24262540 texturedata = ConvertBump(texturedata, false);
24272541
2428
- com.sun.opengl.util.texture.Texture texture =
2429
- 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);
24302544
2431
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2432
- 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);
24332547
2434
- 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;
24352570 }
24362571
24372572 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3504,6 +3639,8 @@
35043639
35053640 System.out.println("LOADING TEXTURE : " + name);
35063641
3642
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3643
+
35073644 //
35083645 if (false) // compressbit > 0)
35093646 {
....@@ -4208,6 +4345,7 @@
42084345
42094346 com.sun.opengl.util.texture.Texture CompressTexture2(String name)
42104347 {
4348
+ new Exception().printStackTrace();
42114349 System.exit(0);
42124350 com.sun.opengl.util.texture.Texture texture = null;
42134351
....@@ -7901,7 +8039,7 @@
79018039 String pigment = Object3D.GetPigment(tex);
79028040 String bump = Object3D.GetBump(tex);
79038041
7904
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8042
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79058043 {
79068044 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79078045 // System.out.println("; bump = " + bump);
....@@ -7916,11 +8054,69 @@
79168054 pigment = null;
79178055 }
79188056
7919
- ReleaseTexture(bump, true);
7920
- ReleaseTexture(pigment, false);
8057
+ ReleaseTexture(tex, true);
8058
+ ReleaseTexture(tex, false);
79218059 }
79228060
7923
- 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)
79248120 {
79258121 if (// DrawMode() != 0 || /*tex == null ||*/
79268122 ambientOcclusion ) // || !textureon)
....@@ -7931,7 +8127,7 @@
79318127 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
79328128
79338129 if (tex != null)
7934
- texture = textures.get(tex);
8130
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
79358131
79368132 // //assert( texture != null );
79378133 // if (texture == null)
....@@ -8023,7 +8219,55 @@
80238219 }
80248220 }
80258221
8026
- /*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
80278271 {
80288272 if (// DrawMode() != 0 || /*tex == null ||*/
80298273 ambientOcclusion ) // || !textureon)
....@@ -8034,17 +8278,47 @@
80348278 if (tex == null)
80358279 {
80368280 BindTexture(null,false,resolution);
8037
- BindTexture(null,true,resolution);
80388281 return;
80398282 }
80408283
80418284 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
+
80428317 String bump = Object3D.GetBump(tex);
80438318
8044
- usedtextures.put(pigment, pigment);
8045
- usedtextures.put(bump, bump);
8319
+ usedtextures.add(tex);
80468320
8047
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8321
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
80488322 {
80498323 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
80508324 // System.out.println("; bump = " + bump);
....@@ -8054,43 +8328,94 @@
80548328 {
80558329 bump = null;
80568330 }
8057
- if (pigment.equals(""))
8058
- {
8059
- pigment = null;
8060
- }
80618331
8062
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8063
- BindTexture(pigment, false, resolution);
80648332 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8065
- BindTexture(bump, true, resolution);
8333
+ BindTexture(tex, true, resolution);
80668334 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8067
-
8068
- return; // true;
80698335 }
80708336
8071
- 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)
80728340 {
8073
- 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;
80748360
80758361 if (tex != null)
80768362 {
8077
- String texname = tex;
8363
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8364
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
80788365
8079
- String[] split = tex.split("Textures");
8080
- if (split.length > 1)
8081
- texname = "/Users/nbriere/Textures" + split[split.length-1];
8082
- else
8083
- if (!texname.startsWith("/"))
8084
- 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
+ }
80858383
80868384 if (CACHETEXTURE)
8087
- texture = textures.get(texname); // TEXTURE CACHE
8088
-
8089
- TextureData texturedata = null;
8090
-
8091
- if (texture == null || texture.resolution < resolution)
80928385 {
8093
- 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(""))
80948419 {
80958420 assert(!bump);
80968421 // if (bump)
....@@ -8101,19 +8426,23 @@
81018426 // }
81028427 // else
81038428 // {
8104
- texture = textures.get(tex);
8105
- if (texture == null)
8429
+ // texturecache = textures.get(texname); // suspicious
8430
+ if (texturecache == null)
81068431 {
8107
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8432
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
81088433 }
8434
+ else
8435
+ new Exception().printStackTrace();
81098436 // }
81108437 } else
8111
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8438
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
81128439 {
81138440 assert(bump);
8114
- texture = textures.get(tex);
8115
- if (texture == null)
8116
- 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();
81178446 } else
81188447 {
81198448 //if (tex.equals("IMMORTAL"))
....@@ -8121,11 +8450,22 @@
81218450 // texture = GetResourceTexture("default.png");
81228451 //} else
81238452 //{
8124
- if (tex.equals("WHITE_NOISE"))
8453
+ if (texname.endsWith("WHITE_NOISE"))
81258454 {
8126
- texture = textures.get(tex);
8127
- if (texture == null)
8128
- 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();
81298469 } else
81308470 {
81318471 if (textureon)
....@@ -8150,7 +8490,7 @@
81508490 }
81518491
81528492 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
8153
- if (!new File(cachename).exists())
8493
+ if (!FileExists(cachename))
81548494 cachename = texname;
81558495 else
81568496 processbump = false; // don't process bump map again
....@@ -8172,7 +8512,7 @@
81728512 }
81738513
81748514 cachename = texname.substring(0, texname.length()-4)+ext+".png";
8175
- if (!new File(cachename).exists())
8515
+ if (!FileExists(cachename))
81768516 cachename = texname;
81778517 else
81788518 processbump = false; // don't process bump map again
....@@ -8181,20 +8521,23 @@
81818521 texturedata = GetFileTexture(cachename, processbump, resolution);
81828522
81838523
8184
- if (texturedata != null)
8185
- 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);
81868528 //texture = GetTexture(tex, bump);
81878529 }
8530
+ }
81888531 }
81898532 //}
81908533 }
81918534
8192
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8535
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
81938536 {
81948537 //return false;
81958538
81968539 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8197
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8540
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
81988541 {
81998542 // String ext = "_highres";
82008543 // if (REDUCETEXTURE)
....@@ -8211,52 +8554,17 @@
82118554 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
82128555 if (!cachefile.exists())
82138556 {
8214
- // cache to disk
8215
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
8216
- //buffers[0].
8217
-
8218
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
8219
- int[] pixels = new int[bytebuf.capacity()/3];
8220
-
8221
- // squared size heuristic...
8222
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8557
+ //if (texturedata.getWidth() == texturedata.getHeight())
82238558 {
8224
- for (int i=pixels.length; --i>=0;)
8225
- {
8226
- int i3 = i*3;
8227
- pixels[i] = 0xFF;
8228
- pixels[i] <<= 8;
8229
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
8230
- pixels[i] <<= 8;
8231
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
8232
- pixels[i] <<= 8;
8233
- pixels[i] |= bytebuf.get(i3) & 0xFF;
8234
- }
8235
-
8236
- /*
8237
- int r=0,g=0,b=0,a=0;
8238
- for (int i=0; i<width; i++)
8239
- for (int j=0; j<height; j++)
8240
- {
8241
- int index = j*width+i;
8242
- int p = pixels[index];
8243
- a = ((p>>24) & 0xFF);
8244
- r = ((p>>16) & 0xFF);
8245
- g = ((p>>8) & 0xFF);
8246
- b = (p & 0xFF);
8247
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
8248
- }
8249
- /**/
8250
- int width = (int)Math.sqrt(pixels.length); // squared
8251
- int height = width;
8252
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
8253
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8559
+ BufferedImage rendImage = CreateBim(texturedata);
8560
+
82548561 ImageWriter writer = null;
82558562 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
82568563 if (iter.hasNext()) {
82578564 writer = (ImageWriter)iter.next();
82588565 }
8259
- float compressionQuality = 0.9f;
8566
+
8567
+ float compressionQuality = 0.85f;
82608568 try
82618569 {
82628570 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8273,18 +8581,20 @@
82738581 }
82748582 }
82758583 }
8276
-
8584
+
8585
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8586
+
82778587 //System.out.println("Texture = " + tex);
8278
- if (textures.containsKey(texname))
8588
+ if (textures.containsKey(tex))
82798589 {
8280
- CacheTexture thetex = textures.get(texname);
8590
+ CacheTexture thetex = textures.get(tex);
82818591 thetex.texture.disable();
82828592 thetex.texture.dispose();
8283
- textures.remove(texname);
8593
+ textures.remove(tex);
82848594 }
82858595
8286
- texture.texturedata = texturedata;
8287
- textures.put(texname, texture);
8596
+ //texture.texturedata = texturedata;
8597
+ textures.put(tex, texturecache);
82888598
82898599 // newtex = true;
82908600 }
....@@ -8300,10 +8610,44 @@
83008610 }
83018611 }
83028612
8303
- return texture;
8613
+ return texturecache;
83048614 }
83058615
8306
- 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
83078651 {
83088652 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
83098653
....@@ -8321,21 +8665,21 @@
83218665 return texture!=null?texture.texture:null;
83228666 }
83238667
8324
- 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
83258669 {
83268670 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
83278671
83288672 return texture!=null?texture.texturedata:null;
83298673 }
83308674
8331
- boolean BindTexture(String tex, boolean bump, int resolution)
8675
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
83328676 {
83338677 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
83348678 {
83358679 return false;
83368680 }
83378681
8338
- boolean newtex = false;
8682
+ //boolean newtex = false;
83398683
83408684 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
83418685
....@@ -8367,9 +8711,75 @@
83678711 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
83688712 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
83698713
8370
- return newtex;
8714
+ return true; // Warning: not used.
83718715 }
83728716
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
+
83738783 ShadowBuffer shadowPBuf;
83748784 AntialiasBuffer antialiasPBuf;
83758785 int MAXSTACK;
....@@ -8386,10 +8796,12 @@
83868796
83878797 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
83888798 MAXSTACK = temp[0];
8389
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8799
+ if (Globals.DEBUG)
8800
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
83908801 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
83918802 MAXSTACK = temp[0];
8392
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8803
+ if (Globals.DEBUG)
8804
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
83938805
83948806 // Use debug pipeline
83958807 //drawable.setGL(new DebugGL(gl)); //
....@@ -8397,7 +8809,8 @@
83978809 gl = drawable.getGL(); //
83988810
83998811 GL gl3 = getGL();
8400
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8812
+ if (Globals.DEBUG)
8813
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
84018814
84028815
84038816 //float pos[] = { 100, 100, 100, 0 };
....@@ -8562,7 +8975,7 @@
85628975
85638976 if (cubemap == null)
85648977 {
8565
- LoadEnvy(5);
8978
+ //LoadEnvy(1);
85668979 }
85678980
85688981 //cubemap.enable();
....@@ -8838,6 +9251,8 @@
88389251
88399252 void LoadEnvy(int which)
88409253 {
9254
+ assert(false);
9255
+
88419256 String name;
88429257 String ext;
88439258
....@@ -8849,37 +9264,58 @@
88499264 cubemap = null;
88509265 return;
88519266 case 1:
8852
- name = "cubemaps/box_";
8853
- ext = "png";
9267
+ name = "cubemaps/rgb/";
9268
+ ext = "jpg";
88549269 reverseUP = false;
88559270 break;
88569271 case 2:
8857
- name = "cubemaps/uffizi_";
8858
- ext = "png";
8859
- break; // reverseUP = true; break;
9272
+ name = "cubemaps/uffizi/";
9273
+ ext = "jpg";
9274
+ reverseUP = false;
9275
+ break;
88609276 case 3:
8861
- name = "cubemaps/CloudyHills_";
8862
- ext = "tga";
9277
+ name = "cubemaps/CloudyHills/";
9278
+ ext = "jpg";
88639279 reverseUP = false;
88649280 break;
88659281 case 4:
8866
- name = "cubemaps/cornell_";
9282
+ name = "cubemaps/cornell/";
88679283 ext = "png";
88689284 reverseUP = false;
88699285 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;
88709311 default:
8871
- name = "cubemaps/rgb_";
8872
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9312
+ name = "cubemaps/box/";
9313
+ ext = "png"; /*mipmap = true;*/
9314
+ reverseUP = false;
88739315 break;
88749316 }
8875
-
8876
- try
8877
- {
8878
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
8879
- } catch (IOException e)
8880
- {
8881
- throw new RuntimeException(e);
8882
- }
9317
+
9318
+ LoadSkybox(name, ext, mipmap);
88839319 }
88849320
88859321 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -8911,8 +9347,12 @@
89119347 static double[] model = new double[16];
89129348 double[] camera2light = new double[16];
89139349 double[] light2camera = new double[16];
8914
- int newenvy = -1;
8915
- boolean envyoff = true; // false;
9350
+
9351
+ //int newenvy = -1;
9352
+ //boolean envyoff = false;
9353
+
9354
+ String loadedskyboxname;
9355
+
89169356 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
89179357 //float[] light0 = { 0,0,0 };
89189358 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9205,11 +9645,35 @@
92059645 jy8[3] = 0.5f;
92069646 }
92079647
9208
- 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
92099649 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
92109650 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
92119651 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
92129652
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
+
92139677 static int imagecount = 0; // movie generation
92149678
92159679 static int jitter = 0;
....@@ -9305,8 +9769,8 @@
93059769 assert (parentcam != renderCamera);
93069770
93079771 if (renderCamera != lightCamera)
9308
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9309
- LA.matConcat(matrix, parentcam.toParent, matrix);
9772
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9773
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
93109774
93119775 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
93129776
....@@ -9321,8 +9785,8 @@
93219785 LA.matCopy(renderCamera.fromScreen, matrix);
93229786
93239787 if (renderCamera != lightCamera)
9324
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9325
- LA.matConcat(parentcam.fromParent, matrix, matrix);
9788
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9789
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
93269790
93279791 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
93289792
....@@ -9368,10 +9832,12 @@
93689832 rati = 1 / rati;
93699833 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
93709834 }
9371
- assert (newenvy == -1);
9835
+
9836
+ //assert (newenvy == -1);
9837
+
93729838 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
93739839 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9374
- DrawSkyBox(gl);
9840
+ DrawSkyBox(gl, (float)rati);
93759841 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
93769842 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
93779843 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -9394,7 +9860,7 @@
93949860 //gl.glFlush();
93959861 gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE);
93969862
9397
- if (ANIMATION && ABORTED)
9863
+ if (Globals.ANIMATION && ABORTED)
93989864 {
93999865 System.err.println(" ABORTED FRAME");
94009866 break;
....@@ -9424,7 +9890,7 @@
94249890 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
94259891
94269892 // save image
9427
- if (ANIMATION && !ABORTED)
9893
+ if (Globals.ANIMATION && !ABORTED)
94289894 {
94299895 VPwidth = viewport[2];
94309896 VPheight = viewport[3];
....@@ -9535,11 +10001,11 @@
953510001
953610002 // imagecount++;
953710003
9538
- 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;
953910005
954010006 if (!BOXMODE)
954110007 {
9542
- 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) + ")");
954310009 }
954410010
954510011 if (!BOXMODE)
....@@ -9577,7 +10043,7 @@
957710043 ABORTED = false;
957810044 }
957910045 else
9580
- GrafreeD.wav.cursor += 735 * ACSIZE;
10046
+ Grafreed.wav.cursor += 735 * ACSIZE;
958110047
958210048 if (false)
958310049 {
....@@ -10237,14 +10703,23 @@
1023710703 static boolean init = false;
1023810704
1023910705 double[][] matrix = LA.newMatrix();
10706
+
10707
+ // This is to refresh the UI of the material panel.
10708
+ ObjEditor patchMaterial;
1024010709
1024110710 public void display(GLAutoDrawable drawable)
1024210711 {
10243
- if (GrafreeD.savesound && GrafreeD.hassound)
10712
+ if (patchMaterial.patchMaterial)
1024410713 {
10245
- GrafreeD.wav.save();
10246
- GrafreeD.savesound = false;
10247
- 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;
1024810723 }
1024910724 // if (DEBUG_SELECTION)
1025010725 // {
....@@ -10320,6 +10795,7 @@
1032010795 ANTIALIAS = 0;
1032110796 //System.out.println("RESTART");
1032210797 AAtimer.restart();
10798
+ Globals.TIMERRUNNING = true;
1032310799 }
1032410800 }
1032510801 }
....@@ -10374,7 +10850,7 @@
1037410850 Object3D theobject = object;
1037510851 Object3D theparent = object.parent;
1037610852 object.parent = null;
10377
- object = (Object3D)GrafreeD.clone(object);
10853
+ object = (Object3D)Grafreed.clone(object);
1037810854 object.Stripify();
1037910855 if (theobject.selection == null || theobject.selection.Size() == 0)
1038010856 theobject.PreprocessOcclusion(this);
....@@ -10387,13 +10863,14 @@
1038710863 ambientOcclusion = false;
1038810864 }
1038910865
10390
- if (Globals.lighttouched && DrawMode() == DEFAULT && !lightMode) // && !FROZEN)
10866
+ if (//Globals.lighttouched &&
10867
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1039110868 {
1039210869 //if (RENDERSHADOW) // ?
1039310870 if (!IsFrozen())
1039410871 {
1039510872 // dec 2012
10396
- if (!ambientOcclusion && !(!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0))
10873
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
1039710874 {
1039810875 Globals.framecount++;
1039910876 shadowbuffer.display();
....@@ -10406,7 +10883,7 @@
1040610883
1040710884 if (wait)
1040810885 {
10409
- Sleep(500);
10886
+ Sleep(200); // blocks everything
1041010887
1041110888 wait = false;
1041210889 }
....@@ -10520,8 +10997,8 @@
1052010997
1052110998 // if (parentcam != renderCamera) // not a light
1052210999 if (cam != lightCamera)
10523
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10524
- LA.matConcat(matrix, parentcam.toParent, matrix);
11000
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11001
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1052511002
1052611003 for (int j = 0; j < 4; j++)
1052711004 {
....@@ -10535,8 +11012,8 @@
1053511012
1053611013 // if (parentcam != renderCamera) // not a light
1053711014 if (cam != lightCamera)
10538
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10539
- LA.matConcat(parentcam.fromParent, matrix, matrix);
11015
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11016
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1054011017
1054111018 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1054211019
....@@ -10622,13 +11099,43 @@
1062211099 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1062311100 }
1062411101
10625
- 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"))
1062611110 {
10627
- LoadEnvy(newenvy);
11111
+ if (cubemaprgb == null)
11112
+ {
11113
+ cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb2" + "/", "jpg", false);
11114
+ }
11115
+
11116
+ cubemap = cubemaprgb;
1062811117 }
10629
-
10630
- newenvy = -1;
10631
-
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
+
1063211139 ratio = ((double) getWidth()) / getHeight();
1063311140 //System.out.println("ratio = " + ratio);
1063411141
....@@ -10644,7 +11151,7 @@
1064411151
1064511152 if (!IsFrozen() && !ambientOcclusion)
1064611153 {
10647
- DrawSkyBox(gl);
11154
+ DrawSkyBox(gl, (float)ratio);
1064811155 }
1064911156
1065011157 //if (selection_view == -1)
....@@ -10795,7 +11302,16 @@
1079511302 // Bump noise
1079611303 gl.glActiveTexture(GL.GL_TEXTURE6);
1079711304 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
10798
- 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
+
1079911315
1080011316 gl.glActiveTexture(GL.GL_TEXTURE0);
1080111317 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -10818,9 +11334,9 @@
1081811334
1081911335 gl.glMatrixMode(GL.GL_MODELVIEW);
1082011336
10821
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10822
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10823
-//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);
1082411340 } else
1082511341 {
1082611342 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -10831,7 +11347,7 @@
1083111347 //System.out.println("BLENDING ON");
1083211348 gl.glEnable(GL.GL_BLEND);
1083311349 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
10834
-
11350
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1083511351 gl.glMatrixMode(gl.GL_PROJECTION);
1083611352 gl.glLoadIdentity();
1083711353
....@@ -10920,8 +11436,8 @@
1092011436 System.err.println("parentcam != renderCamera");
1092111437
1092211438 // if (cam != lightCamera)
10923
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10924
- 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
1092511441 }
1092611442
1092711443 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -10942,8 +11458,8 @@
1094211458 if (true) // TODO
1094311459 {
1094411460 if (cam != lightCamera)
10945
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10946
- 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
1094711463 }
1094811464
1094911465 LA.xformPos(light0, cam.toScreen, light0);
....@@ -11080,7 +11596,7 @@
1108011596 }
1108111597 }
1108211598
11083
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11599
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1108411600 {
1108511601 //gl.glDepthFunc(GL.GL_LEQUAL);
1108611602 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11088,24 +11604,21 @@
1108811604
1108911605 boolean texon = textureon;
1109011606
11091
- if (RENDERPROGRAM > 0)
11092
- {
11093
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11094
- textureon = false;
11095
- }
11607
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11608
+ textureon = false;
11609
+
1109611610 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1109711611 //System.out.println("ALLO");
1109811612 gl.glColorMask(false, false, false, false);
1109911613 DrawObject(gl);
11100
- if (RENDERPROGRAM > 0)
11101
- {
11102
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11103
- textureon = texon;
11104
- }
11614
+
11615
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11616
+ textureon = texon;
11617
+
1110511618 gl.glColorMask(true, true, true, true);
1110611619
1110711620 gl.glDepthFunc(GL.GL_EQUAL);
11108
- //gl.glDepthMask(false);
11621
+ gl.glDepthMask(false);
1110911622 }
1111011623
1111111624 if (false) // DrawMode() == SHADOW)
....@@ -11259,8 +11772,14 @@
1125911772 {
1126011773 renderpass++;
1126111774 // System.out.println("Draw object... ");
11775
+ STEP = 1;
1126211776 if (FAST) // in case there is no script
11263
- STEP = 16;
11777
+ STEP = 8;
11778
+
11779
+ if (CURRENTANTIALIAS == 0 || ACSIZE == 1)
11780
+ {
11781
+ STEP *= 4;
11782
+ }
1126411783
1126511784 //object.FullInvariants();
1126611785
....@@ -11274,23 +11793,44 @@
1127411793 e.printStackTrace();
1127511794 }
1127611795
11277
- if (GrafreeD.RENDERME > 0)
11278
- GrafreeD.RENDERME--; // mechante magouille
11796
+ if (Grafreed.RENDERME > 0)
11797
+ Grafreed.RENDERME--; // mechante magouille
1127911798
1128011799 Globals.ONESTEP = false;
1128111800 }
1128211801
1128311802 static boolean zoomonce = false;
1128411803
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
+
1128511822 void DrawObject(GL gl, boolean draw)
1128611823 {
11824
+ // To clear camera values
11825
+ ResetOptions();
11826
+
1128711827 //System.out.println("DRAW OBJECT " + mouseDown);
1128811828 // DrawMode() = SELECTION;
1128911829 //GL gl = getGL();
1129011830 if ((TRACK || SHADOWTRACK) || zoomonce)
1129111831 {
1129211832 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11293
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11833
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1129411834 pingthread.StepToTarget(true); // true);
1129511835 // zoomonce = false;
1129611836 }
....@@ -11345,7 +11885,14 @@
1134511885
1134611886 usedtextures.clear();
1134711887
11348
- 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
+ }
1134911896 }
1135011897 //System.out.println("--> " + stackdepth);
1135111898 // GrafreeD.traceon();
....@@ -11355,8 +11902,9 @@
1135511902
1135611903 if (DrawMode() == DEFAULT)
1135711904 {
11358
- if (DEBUG)
11905
+ if (Globals.DEBUG)
1135911906 {
11907
+ CreateSelectedPoint();
1136011908 float radius = 0.05f;
1136111909 if (selectedpoint.radius != radius)
1136211910 {
....@@ -11410,20 +11958,32 @@
1141011958 ReleaseTextures(DEFAULT_TEXTURES);
1141111959
1141211960 if (CLEANCACHE)
11413
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11961
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1141411962 {
11415
- String tex = e.nextElement();
11963
+ cTexture tex = e.nextElement();
1141611964
1141711965 // System.out.println("Texture --------- " + tex);
1141811966
11419
- if (tex.equals("WHITE_NOISE"))
11967
+ if (tex.equals("WHITE_NOISE:"))
1142011968 continue;
1142111969
11422
- if (!usedtextures.containsKey(tex))
11970
+ if (!usedtextures.contains(tex))
1142311971 {
11972
+ CacheTexture gettex = texturepigment.get(tex);
1142411973 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11425
- textures.get(tex).texture.dispose();
11426
- 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
+ }
1142711987 }
1142811988 }
1142911989 }
....@@ -11436,7 +11996,14 @@
1143611996 if (checker != null && DrawMode() == DEFAULT)
1143711997 {
1143811998 //BindTexture(IMMORTAL_TEXTURE);
11439
- 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
+ }
1144012007 // NEAREST
1144112008 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
1144212009 DrawChecker(gl);
....@@ -11518,7 +12085,7 @@
1151812085 return;
1151912086 }
1152012087
11521
- String string = obj.GetToolTip();
12088
+ String string = obj.toString(); //.GetToolTip();
1152212089
1152312090 GL gl = GetGL();
1152412091
....@@ -11835,8 +12402,8 @@
1183512402 //obj.TransformToWorld(light, light);
1183612403 for (int i = tp.size(); --i >= 0;)
1183712404 {
11838
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
11839
- 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);
1184012407 }
1184112408
1184212409
....@@ -11853,8 +12420,8 @@
1185312420 parentcam = cameras[0];
1185412421 }
1185512422
11856
- for (int count = parentcam.GetTransformCount(); --count>=0;)
11857
- 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
1185812425
1185912426 LA.xformPos(light, renderCamera.toScreen, light);
1186012427
....@@ -11944,8 +12511,76 @@
1194412511
1194512512 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1194612513
11947
- String program =
12514
+ String programmin =
12515
+ // Min shader
1194812516 "!!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
+
1194912584 //"OPTION ARB_fragment_program_shadow;" +
1195012585 "PARAM light2cam0 = program.env[10];" +
1195112586 "PARAM light2cam1 = program.env[11];" +
....@@ -11971,7 +12606,7 @@
1197112606 "PARAM params4 = program.env[4];" + // anisoV, cameralight, selfshadow, shadow
1197212607 "PARAM params5 = program.env[5];" + // texture, opacity, fakedepth, shadowbias
1197312608 "PARAM params6 = program.env[6];" + // bump, noise, borderfade, fog punchthrough
11974
- "PARAM params7 = program.env[7];" + // noise power, opacity power
12609
+ "PARAM params7 = program.env[7];" + // noise power, opacity power, parallax
1197512610 "PARAM options0 = program.env[63];" + // fog density, intensity, elevation
1197612611 "PARAM options1 = program.env[62];" + // fog rgb color
1197712612 "PARAM options2 = program.env[61];" + // image intensity, subsurface, lightsheen
....@@ -12060,8 +12695,7 @@
1206012695 "TEMP shininess;" +
1206112696 "\n" +
1206212697 "MOV texSamp, one;" +
12063
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12064
-
12698
+
1206512699 "MOV mapgrid.x, one2048th.x;" +
1206612700 "MOV temp, fragment.texcoord[1];" +
1206712701 /*
....@@ -12082,20 +12716,20 @@
1208212716 "MUL temp, floor, mapgrid.x;" +
1208312717 //"TEX depth0, temp, texture[1], 2D;" +
1208412718 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12085
- TextureFetch("depth0", "temp", "1") +
12719
+ ShadowTextureFetch("depth0", "temp", "1") +
1208612720 "") +
1208712721 "ADD temp.x, temp.x, mapgrid.x;" +
1208812722 //"TEX depth1, temp, texture[1], 2D;" +
1208912723 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12090
- TextureFetch("depth1", "temp", "1") +
12724
+ ShadowTextureFetch("depth1", "temp", "1") +
1209112725 "") +
1209212726 "ADD temp.y, temp.y, mapgrid.x;" +
1209312727 //"TEX depth2, temp, texture[1], 2D;" +
12094
- TextureFetch("depth2", "temp", "1") +
12728
+ ShadowTextureFetch("depth2", "temp", "1") +
1209512729 "SUB temp.x, temp.x, mapgrid.x;" +
1209612730 //"TEX depth3, temp, texture[1], 2D;" +
1209712731 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12098
- TextureFetch("depth3", "temp", "1") +
12732
+ ShadowTextureFetch("depth3", "temp", "1") +
1209912733 "") +
1210012734 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1210112735 //"MOV params, material;" +
....@@ -12217,7 +12851,7 @@
1221712851 "POW texSamp.a, texSamp.a, params6.w;" + // fog punch through shortcut
1221812852 // mar 2013 ??? "KIL alpha.a;" +
1221912853 "MOV alpha, texSamp.aaaa;" + // y;" +
12220
- "KIL alpha.a;" +
12854
+ "KIL alpha.a;" + // not sure with parallax mapping
1222112855 /*
1222212856 "MUL temp.xy, temp, two;" +
1222312857 "TXB bump, temp, texture[0], 2D;" +
....@@ -12303,11 +12937,6 @@
1230312937 "SUB bump0, bump0, half;" +
1230412938 "ADD bump, bump, bump0;" +
1230512939
12306
- "MOV temp.x, texSamp.a;" +
12307
- "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
12308
- //"LRP texSamp0, params5.x, texSamp0, one;" +
12309
- "MOV texSamp.a, temp.x;" +
12310
-
1231112940 // double-sided
1231212941 /**/
1231312942 (doublesided?"DP3 temp.z, normal, eye;" +
....@@ -12324,19 +12953,62 @@
1232412953 "MOV normald, normal;" +
1232512954 "MOV normals, normal;" +
1232612955
12956
+ "MOV temp, fragment.texcoord[4];" +
12957
+
1232712958 // UV base
1232812959 //"DP3 UP.x,state.matrix.modelview.row[0],Y;" +
1232912960 //"DP3 UP.y,state.matrix.modelview.row[1],Y;" +
1233012961 //"DP3 UP.z,state.matrix.modelview.row[2],Y;" +
12331
- "DP3 UP.x,state.matrix.texture[7].row[0],Y;" +
12332
- "DP3 UP.y,state.matrix.texture[7].row[1],Y;" +
12333
- "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
+
1233412967 "XPD V, normal, UP;" +
1233512968 Normalize("V") +
1233612969 "XPD U, V, normal;" +
1233712970 Normalize("U") +
1233812971
1233912972 // 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;" +
1234013012
1234113013 //"MOV temp, fragment.texcoord[0];" +
1234213014 //
....@@ -12466,10 +13138,10 @@
1246613138 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1246713139 "") +
1246813140
12469
- // display shadow only (bump == 0)
13141
+ // display shadow only (fakedepth == 0)
1247013142 "SUB temp.x, half.x, shadow.x;" +
12471
- "MOV temp.y, -params6.x;" +
12472
- "SLT temp.z, temp.y, zero.x;" +
13143
+ "MOV temp.y, -params5.z;" + // params6.x;" +
13144
+ "SLT temp.z, temp.y, -c256i.x;" +
1247313145 "SUB temp.y, one.x, temp.z;" +
1247413146 "MUL temp.x, temp.x, temp.y;" +
1247513147 "KIL temp.x;" +
....@@ -12598,8 +13270,10 @@
1259813270 "MAX ndotl.x, ndotl.x, -ndotl.x;" +
1259913271
1260013272 "SUB temp.x, one.x, ndotl.x;" +
12601
- "ADD temp.x, temp.x, options2.z;" + // lightsheen
12602
- "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
1260313277 "MUL temp.x, temp.x, temp.y;" +
1260413278
1260513279 "MUL saturation, saturation, temp.xxxx;" +
....@@ -12798,8 +13472,19 @@
1279813472 //once = true;
1279913473 }
1280013474
12801
- System.out.print("Program #" + mode + "; length = " + program.length());
12802
- 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
+
1280313488 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1280413489
1280513490 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -12846,7 +13531,8 @@
1284613531 "\n" +
1284713532 "END\n";
1284813533
12849
- System.out.println("Program shadow #" + 0 + "; length = " + program.length());
13534
+ if (Globals.DEBUG)
13535
+ System.out.println("Program shadow #" + 0 + "; length = " + program.length());
1285013536 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1285113537
1285213538 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -12891,25 +13577,26 @@
1289113577 return out;
1289213578 }
1289313579
12894
- String TextureFetch(String dest, String src, String unit)
13580
+ // Also does frustum culling
13581
+ String ShadowTextureFetch(String dest, String src, String unit)
1289513582 {
1289613583 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1289713584 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1289813585 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13586
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13587
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1289913588 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12900
- "SLT " + src + ".z, " + src + ".x, one.x;" +
12901
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12902
- "SLT " + src + ".z, " + src + ".y, one.x;" +
12903
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13589
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13590
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1290413591 //"SWZ buffer, temp, w,w,w,w;";
12905
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13592
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1290613593 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1290713594 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1290813595 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
12909
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13596
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1291013597
12911
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
12912
- //"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;";
1291313600 }
1291413601
1291513602 String Shadow(String depth, String shadow)
....@@ -12931,12 +13618,16 @@
1293113618
1293213619 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1293313620 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13621
+
13622
+ // Compare fragment depth in light space with shadowmap.
1293413623 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1293513624 "SGE temp.y, temp.x, zero.x;" +
12936
- "SUB " + shadow + ".y, one.x, temp.y;" +
13625
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13626
+
13627
+ // Reverse comparison
1293713628 "SUB temp.x, one.x, temp.x;" +
1293813629 "MUL " + shadow + ".x, temp.x, temp.y;" +
12939
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13630
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1294013631 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1294113632
1294213633 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -12950,6 +13641,10 @@
1295013641 // No shadow for backface
1295113642 "DP3 temp.x, normal, lightd;" +
1295213643 "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;" +
1295313648 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1295413649 "";
1295513650 }
....@@ -13095,8 +13790,9 @@
1309513790 /*static*/ float[] modelParams4 = new float[]{0, 0, 0, 0}; // anisoV, cameralight, selfshadow, shadow
1309613791 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1309713792 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
13098
- /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13099
- Object3D.cVector2[] vector2buffer;
13793
+ /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power, parallax
13794
+
13795
+ //Object3D.cVector2[] vector2buffer;
1310013796
1310113797 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1310213798 // OUT : diff, spec
....@@ -13112,9 +13808,10 @@
1311213808 "DP3 " + dest + ".z," + "normals," + "eye;" +
1311313809 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1311413810 //"MOV " + dest + ".w," + "normal.z;" +
13115
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
13116
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13117
- //"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
1311813815 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1311913816 "RCP " + dest + ".w," + dest + ".w;" +
1312013817 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13260,7 +13957,7 @@
1326013957 "PARAM p[4] = { state.matrix.projection }; # modelview projection matrix\n" +
1326113958 "PARAM zero = { 0.0, 0.0, 0.0, 1.0 };" +
1326213959 "PARAM half = { 0.5, 0.5, 0.5, 1.0 };" +
13263
- "PARAM one = { 1.0, 1.0, 1.0, 0.0 };" +
13960
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
1326413961 "PARAM two = { 2.0, 2.0, 2.0, 1.0 };" +
1326513962 "PARAM third = { 0.33333333333, 0.33333333333, 0.33333333333, 1.0 };" +
1326613963 //"PARAM v256 = { 256.0, 256.0, 256.0, 1.0 };" +
....@@ -13321,7 +14018,7 @@
1332114018 "DP4 temp.x,state.matrix.texture[0].inverse.row[0],vertex.texcoord;" +
1332214019 "DP4 temp.y,state.matrix.texture[0].inverse.row[1],vertex.texcoord;" +
1332314020 "DP4 temp.z,state.matrix.texture[0].inverse.row[2],vertex.texcoord;" +
13324
- //"MOV result.texcoord, vertex.texcoord;" +
14021
+ //"MOV result.texcoord, vertex.fogcoord;" +
1332514022 "MOV result.texcoord, temp;" +
1332614023 // border fade
1332714024 "MOV result.texcoord[3], vertex.texcoord;" +
....@@ -13368,7 +14065,9 @@
1336814065
1336914066 //"ADD temp.z, temp.z, one;" +
1337014067
13371
- "MOV result.color, temp;"
14068
+ "MOV result.texcoord[4], vertex.attrib[4];" + // U dir
14069
+
14070
+ "MOV result.color, temp;" // Normal
1337214071 : "MOV result.color, vertex.color;") +
1337314072 ((mode & VP_PROJECTION) != 0 ? "MOV result.color, zero;"
1337414073 : "") +
....@@ -13508,7 +14207,7 @@
1350814207 public void mousePressed(MouseEvent e)
1350914208 {
1351014209 //System.out.println("mousePressed: " + e);
13511
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14210
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1351214211 }
1351314212
1351414213 static long prevtime = 0;
....@@ -13584,8 +14283,8 @@
1358414283 // mode |= META;
1358514284 //}
1358614285
13587
- SetMouseMode(WHEEL | e.getModifiersEx());
13588
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14286
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14287
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1358914288 anchorX = ax;
1359014289 anchorY = ay;
1359114290 prevX = px;
....@@ -13619,6 +14318,7 @@
1361914318 else
1362014319 if (evt.getSource() == AAtimer)
1362114320 {
14321
+ Globals.TIMERRUNNING = false;
1362214322 if (mouseDown)
1362314323 {
1362414324 //new Exception().printStackTrace();
....@@ -13644,6 +14344,10 @@
1364414344 // LIVE = waslive;
1364514345 // wasliveok = true;
1364614346 // waslive = false;
14347
+
14348
+ // May 2019 Forget it:
14349
+ if (true)
14350
+ return;
1364714351
1364814352 // source == timer
1364914353 if (mouseDown)
....@@ -13674,7 +14378,7 @@
1367414378
1367514379 // fev 2014???
1367614380 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13677
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14381
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1367814382 pingthread.StepToTarget(true); // true);
1367914383 }
1368014384 // if (!LIVE)
....@@ -13683,12 +14387,13 @@
1368314387
1368414388 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1368514389
13686
- void clickStart(int x, int y, int modifiers)
14390
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1368714391 {
1368814392 if (!wasliveok)
1368914393 return;
1369014394
1369114395 AAtimer.restart(); //
14396
+ Globals.TIMERRUNNING = true;
1369214397
1369314398 // waslive = LIVE;
1369414399 // LIVE = false;
....@@ -13700,7 +14405,7 @@
1370014405 // touched = true; // main DL
1370114406 if (isRenderer)
1370214407 {
13703
- SetMouseMode(modifiers);
14408
+ SetMouseMode(modifiers, modifiersex);
1370414409 }
1370514410
1370614411 selectX = anchorX = x;
....@@ -13713,7 +14418,7 @@
1371314418 clicked = true;
1371414419 hold = false;
1371514420
13716
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14421
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1371714422 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1371814423 {
1371914424 // System.out.println("RESTART II " + modifiers);
....@@ -13738,14 +14443,15 @@
1373814443 drag = false;
1373914444 //System.out.println("Mouse DOWN");
1374014445 editObj = false;
13741
- ClickInfo info = new ClickInfo();
13742
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
13743
- info.pane = this;
13744
- info.camera = renderCamera;
13745
- info.x = x;
13746
- info.y = y;
13747
- info.modifiers = modifiers;
13748
- 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);
1374914455 if (!editObj)
1375014456 {
1375114457 hasMarquee = true;
....@@ -13761,9 +14467,12 @@
1376114467
1376214468 public void mouseDragged(MouseEvent e)
1376314469 {
14470
+ Globals.MOUSEDRAGGED = true;
14471
+
1376414472 //System.out.println("mouseDragged: " + e);
1376514473 if (isRenderer)
1376614474 movingcamera = true;
14475
+
1376714476 //if (drawing)
1376814477 //return;
1376914478 if ((e.getModifiersEx() & CTRL) != 0
....@@ -13773,7 +14482,7 @@
1377314482 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1377414483 }
1377514484 else
13776
- drag(e.getX(), e.getY(), e.getModifiersEx());
14485
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1377714486
1377814487 //try { Thread.sleep(1); } catch (Exception ex) {}
1377914488 }
....@@ -13946,6 +14655,7 @@
1394614655
1394714656 public void run()
1394814657 {
14658
+ new Exception().printStackTrace();
1394914659 System.exit(0);
1395014660 for (;;)
1395114661 {
....@@ -14009,7 +14719,7 @@
1400914719 {
1401014720 Globals.lighttouched = true;
1401114721 }
14012
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14722
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1401314723 }
1401414724 //else
1401514725 }
....@@ -14023,12 +14733,18 @@
1402314733 void GoDown(int mod)
1402414734 {
1402514735 MODIFIERS |= COMMAND;
14026
- /*
14736
+ boolean isVR = (mouseMode&VR)!=0;
14737
+ /**/
1402714738 if((mod&SHIFT) == SHIFT)
14028
- manipCamera.RotatePosition(0, -speed);
14739
+ {
14740
+ if (isVR)
14741
+ manipCamera.RotateInterest(0, -speed);
14742
+ else
14743
+ manipCamera.RotatePosition(0, -speed);
14744
+ }
1402914745 else
14030
- manipCamera.BackForth(0, -speed*delta, getWidth());
14031
- */
14746
+ manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth());
14747
+ /**/
1403214748 if ((mod & SHIFT) == SHIFT)
1403314749 {
1403414750 mouseMode = mouseMode; // VR??
....@@ -14037,6 +14753,8 @@
1403714753 mouseMode |= BACKFORTH;
1403814754 }
1403914755
14756
+ targetLookAt.set(manipCamera.lookAt);
14757
+
1404014758 //prevX = X = anchorX;
1404114759 prevY = Y = anchorY - (int) (renderCamera.Distance());
1404214760 }
....@@ -14044,12 +14762,19 @@
1404414762 void GoUp(int mod)
1404514763 {
1404614764 MODIFIERS |= COMMAND;
14047
- /*
14765
+ /**/
14766
+ boolean isVR = (mouseMode&VR)!=0;
14767
+
1404814768 if((mod&SHIFT) == SHIFT)
14049
- manipCamera.RotatePosition(0, speed);
14769
+ {
14770
+ if (isVR)
14771
+ manipCamera.RotateInterest(0, speed);
14772
+ else
14773
+ manipCamera.RotatePosition(0, speed);
14774
+ }
1405014775 else
14051
- manipCamera.BackForth(0, speed*delta, getWidth());
14052
- */
14776
+ manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth());
14777
+ /**/
1405314778 if ((mod & SHIFT) == SHIFT)
1405414779 {
1405514780 mouseMode = mouseMode;
....@@ -14058,6 +14783,8 @@
1405814783 mouseMode |= BACKFORTH;
1405914784 }
1406014785
14786
+ targetLookAt.set(manipCamera.lookAt);
14787
+
1406114788 //prevX = X = anchorX;
1406214789 prevY = Y = anchorY + (int) (renderCamera.Distance());
1406314790 }
....@@ -14065,12 +14792,17 @@
1406514792 void GoLeft(int mod)
1406614793 {
1406714794 MODIFIERS |= COMMAND;
14068
- /*
14795
+ /**/
1406914796 if((mod&SHIFT) == SHIFT)
14070
- manipCamera.RotatePosition(speed, 0);
14797
+ manipCamera.Translate(speed*delta, 0, getWidth());
1407114798 else
14072
- manipCamera.Translate(speed*delta, 0, getWidth());
14073
- */
14799
+ {
14800
+ if ((mouseMode&VR)!=0)
14801
+ manipCamera.RotateInterest(-speed, 0);
14802
+ else
14803
+ manipCamera.RotatePosition(speed, 0);
14804
+ }
14805
+ /**/
1407414806 if ((mod & SHIFT) == SHIFT)
1407514807 {
1407614808 mouseMode = mouseMode;
....@@ -14079,6 +14811,8 @@
1407914811 mouseMode |= ROTATE;
1408014812 } // TRANSLATE;
1408114813
14814
+ targetLookAt.set(manipCamera.lookAt);
14815
+
1408214816 prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance());
1408314817 prevY = Y = anchorY;
1408414818 }
....@@ -14086,12 +14820,18 @@
1408614820 void GoRight(int mod)
1408714821 {
1408814822 MODIFIERS |= COMMAND;
14089
- /*
14823
+ /**/
1409014824 if((mod&SHIFT) == SHIFT)
14091
- manipCamera.RotatePosition(-speed, 0);
14825
+ manipCamera.Translate(-speed*delta, 0, getWidth());
1409214826 else
14093
- manipCamera.Translate(-speed*delta, 0, getWidth());
14094
- */
14827
+ {
14828
+ if ((mouseMode&VR)!=0)
14829
+ manipCamera.RotateInterest(speed, 0);
14830
+ else
14831
+ manipCamera.RotatePosition(-speed, 0);
14832
+ }
14833
+
14834
+ /**/
1409514835 if ((mod & SHIFT) == SHIFT)
1409614836 {
1409714837 mouseMode = mouseMode;
....@@ -14100,6 +14840,8 @@
1410014840 mouseMode |= ROTATE;
1410114841 } // TRANSLATE;
1410214842
14843
+ targetLookAt.set(manipCamera.lookAt);
14844
+
1410314845 prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance());
1410414846 prevY = Y = anchorY;
1410514847 }
....@@ -14109,7 +14851,7 @@
1410914851 int X, Y;
1411014852 boolean SX, SY;
1411114853
14112
- void drag(int x, int y, int modifiers)
14854
+ void drag(int x, int y, int modifiers, int modifiersex)
1411314855 {
1411414856 if (IsFrozen())
1411514857 {
....@@ -14118,17 +14860,17 @@
1411814860
1411914861 drag = true; // NEW
1412014862
14121
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14863
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1412214864
1412314865 X = x;
1412414866 Y = y;
1412514867 // floating state for animation
14126
- MODIFIERS = modifiers;
14127
- modifiers &= ~1024;
14868
+ MODIFIERS = modifiersex;
14869
+ modifiersex &= ~1024;
1412814870 if (false) // modifiers != 0)
1412914871 {
1413014872 //new Exception().printStackTrace();
14131
- System.out.println("mouseDragged: " + modifiers);
14873
+ System.out.println("mouseDragged: " + modifiersex);
1413214874 System.out.println("SHIFT = " + SHIFT);
1413314875 System.out.println("CONTROL = " + COMMAND);
1413414876 System.out.println("META = " + META);
....@@ -14141,14 +14883,16 @@
1414114883 if (editObj)
1414214884 {
1414314885 drag = true;
14144
- ClickInfo info = new ClickInfo();
14145
- info.bounds.setBounds(0, 0,
14886
+ //ClickInfo info = new ClickInfo();
14887
+ object.clickInfo.bounds.setBounds(0, 0,
1414614888 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14147
- info.pane = this;
14148
- info.camera = renderCamera;
14149
- info.x = x;
14150
- info.y = y;
14151
- 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);
1415214896 } else
1415314897 {
1415414898 if (x < startX)
....@@ -14297,22 +15041,27 @@
1429715041 }
1429815042 }
1429915043
15044
+// ClickInfo clickInfo = new ClickInfo();
15045
+
1430015046 public void mouseMoved(MouseEvent e)
1430115047 {
1430215048 //System.out.println("mouseMoved: " + e);
1430315049 if (isRenderer)
1430415050 return;
1430515051
14306
- ClickInfo ci = new ClickInfo();
14307
- ci.x = e.getX();
14308
- ci.y = e.getY();
14309
- ci.modifiers = e.getModifiersEx();
14310
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14311
- ci.pane = this;
14312
- 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;
1431315059 if (!isRenderer)
1431415060 {
14315
- if (object.editWindow.copy.doEditClick(ci, 0))
15061
+ //ObjEditor editWindow = object.editWindow;
15062
+ //Object3D copy = editWindow.copy;
15063
+ if (object.doEditClick(//clickInfo,
15064
+ 0))
1431615065 {
1431715066 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1431815067 } else
....@@ -14324,7 +15073,11 @@
1432415073
1432515074 public void mouseReleased(MouseEvent e)
1432615075 {
15076
+ Globals.MOUSEDRAGGED = false;
15077
+
1432715078 movingcamera = false;
15079
+ X = 0; // getBounds().width/2;
15080
+ Y = 0; // getBounds().height/2;
1432815081 //System.out.println("mouseReleased: " + e);
1432915082 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1433015083 }
....@@ -14347,9 +15100,9 @@
1434715100 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1434815101 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1434915102
14350
- if (control || command || IsFrozen())
15103
+// No delay if (control || command || IsFrozen())
1435115104 timeout = true;
14352
- else
15105
+// ?? May 2019 else
1435315106 // timer.setDelay((modifiers & 128) != 0?0:350);
1435415107 mouseDown = false;
1435515108 if (!control && !command) // june 2013
....@@ -14459,7 +15212,7 @@
1445915212 System.out.println("keyReleased: " + e);
1446015213 }
1446115214
14462
- void SetMouseMode(int modifiers)
15215
+ void SetMouseMode(int modifiers, int modifiersex)
1446315216 {
1446415217 //System.out.println("SetMouseMode = " + modifiers);
1446515218 //modifiers &= ~1024;
....@@ -14471,25 +15224,25 @@
1447115224 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1447215225 // return;
1447315226 //System.out.println("SetMode = " + modifiers);
14474
- if ((modifiers & WHEEL) == WHEEL)
15227
+ if ((modifiersex & WHEEL) == WHEEL)
1447515228 {
1447615229 mouseMode |= ZOOM;
1447715230 }
1447815231
1447915232 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
14480
- if (capsLocked || (modifiers & META) == META)
15233
+ if (capsLocked) // || (modifiers & META) == META)
1448115234 {
1448215235 mouseMode |= VR; // BACKFORTH;
1448315236 }
14484
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
15237
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1448515238 {
1448615239 mouseMode |= SELECT;
1448715240 }
14488
- if ((modifiers & COMMAND) == COMMAND)
15241
+ if ((modifiersex & COMMAND) == COMMAND)
1448915242 {
1449015243 mouseMode |= SELECT;
1449115244 }
14492
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15245
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
1449315246 {
1449415247 mouseMode &= ~VR;
1449515248 mouseMode |= TRANSLATE;
....@@ -14518,7 +15271,7 @@
1451815271
1451915272 if (isRenderer) //
1452015273 {
14521
- SetMouseMode(modifiers);
15274
+ SetMouseMode(0, modifiers);
1452215275 }
1452315276
1452415277 Globals.theRenderer.keyPressed(key);
....@@ -14580,7 +15333,8 @@
1458015333 // break;
1458115334 case 'T':
1458215335 CACHETEXTURE ^= true;
14583
- textures.clear();
15336
+ texturepigment.clear();
15337
+ texturebump.clear();
1458415338 // repaint();
1458515339 break;
1458615340 case 'Y':
....@@ -14590,8 +15344,8 @@
1459015344 case 'K':
1459115345 KOMPACTTEXTURE ^= true;
1459215346 //textures.clear();
14593
- break;
14594
- case 'P': // Texture Projection macros
15347
+ // break;
15348
+ //case 'P': // Texture Projection macros
1459515349 // SAVETEXTURE ^= true;
1459615350 macromode = true;
1459715351 Udebug = Vdebug = NORMALdebug = false; programInitialized = false;
....@@ -14665,7 +15419,9 @@
1466515419 case 'E' : COMPACT ^= true;
1466615420 repaint();
1466715421 break;
14668
- case 'W' : DEBUGHSB ^= true;
15422
+ case 'W' : // Wide Window (fullscreen)
15423
+ //DEBUGHSB ^= true;
15424
+ ObjEditor.theFrame.ToggleFullScreen();
1466915425 repaint();
1467015426 break;
1467115427 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14690,8 +15446,8 @@
1469015446 RevertCamera();
1469115447 repaint();
1469215448 break;
14693
- case 'L':
1469415449 case 'l':
15450
+ //case 'L':
1469515451 if (lightMode)
1469615452 {
1469715453 lightMode = false;
....@@ -14710,7 +15466,7 @@
1471015466 targetLookAt.set(manipCamera.lookAt);
1471115467 repaint();
1471215468 break;
14713
- case 'p':
15469
+ case 'P': // p':
1471415470 // c'est quoi ca au juste? spherical ^= true;
1471515471 Skinshader ^= true; programInitialized = false;
1471615472 repaint();
....@@ -14755,20 +15511,24 @@
1475515511 OCCLUSION_CULLING ^= true;
1475615512 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1475715513 break;
14758
- case '0': envyoff ^= true; repaint(); break;
15514
+ //case '0': envyoff ^= true; repaint(); break;
1475915515 case '1':
1476015516 case '2':
1476115517 case '3':
1476215518 case '4':
1476315519 case '5':
14764
- newenvy = Character.getNumericValue(key);
14765
- repaint();
14766
- break;
1476715520 case '6':
1476815521 case '7':
1476915522 case '8':
1477015523 case '9':
14771
- 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
+ }
1477215532 repaint();
1477315533 break;
1477415534 case '!':
....@@ -14834,9 +15594,9 @@
1483415594 case '_':
1483515595 kompactbit = 5;
1483615596 break;
14837
- case '+':
14838
- kompactbit = 6;
14839
- break;
15597
+// case '+':
15598
+// kompactbit = 6;
15599
+// break;
1484015600 case ' ':
1484115601 lightMode ^= true;
1484215602 Globals.lighttouched = true;
....@@ -14848,13 +15608,14 @@
1484815608 case ESC:
1484915609 RENDERPROGRAM += 1;
1485015610 RENDERPROGRAM %= 3;
15611
+
1485115612 repaint();
1485215613 break;
1485315614 case 'Z':
1485415615 //RESIZETEXTURE ^= true;
1485515616 //break;
1485615617 case 'z':
14857
- RENDERSHADOW ^= true;
15618
+ Globals.RENDERSHADOW ^= true;
1485815619 Globals.lighttouched = true;
1485915620 repaint();
1486015621 break;
....@@ -14887,8 +15648,9 @@
1488715648 case DELETE:
1488815649 ClearSelection();
1488915650 break;
14890
- /*
1489115651 case '+':
15652
+
15653
+ /*
1489215654 //fontsize += 1;
1489315655 bbzoom *= 2;
1489415656 repaint();
....@@ -14905,17 +15667,17 @@
1490515667 case '=':
1490615668 IncDepth();
1490715669 //fontsize += 1;
14908
- object.editWindow.refreshContents(true);
15670
+ object.GetWindow().refreshContents(true);
1490915671 maskbit = 6;
1491015672 break;
1491115673 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1491215674 DecDepth();
1491315675 maskbit = 5;
1491415676 //if(fontsize > 1) fontsize -= 1;
14915
- if (object.editWindow == null)
14916
- new Exception().printStackTrace();
14917
- else
14918
- object.editWindow.refreshContents(true);
15677
+// if (object.editWindow == null)
15678
+// new Exception().printStackTrace();
15679
+// else
15680
+ object.GetWindow().refreshContents(true);
1491915681 break;
1492015682 case '{':
1492115683 manipCamera.shaper_fovy /= 1.1;
....@@ -14978,7 +15740,7 @@
1497815740 //mode = ROTATE;
1497915741 if ((MODIFIERS & COMMAND) == 0) // VR??
1498015742 {
14981
- SetMouseMode(modifiers);
15743
+ SetMouseMode(0, modifiers);
1498215744 }
1498315745 }
1498415746
....@@ -15114,7 +15876,7 @@
1511415876 {
1511515877 //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
1511615878 //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15117
- if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (mouseMode & SELECT) == 0)
15879
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1511815880 {
1511915881 mouseMoved(e);
1512015882 } else
....@@ -15139,11 +15901,12 @@
1513915901 }
1514015902 */
1514115903
15142
- object.editWindow.EditSelection();
15904
+ object.GetWindow().EditSelection(false);
1514315905 }
1514415906
1514515907 void SelectParent()
1514615908 {
15909
+ new Exception().printStackTrace();
1514715910 System.exit(0);
1514815911 Composite group = (Composite) object;
1514915912 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -15155,10 +15918,10 @@
1515515918 {
1515615919 //selectees.remove(i);
1515715920 System.out.println("select parent of " + elem);
15158
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15921
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1515915922 } else
1516015923 {
15161
- group.editWindow.Select(elem.GetTreePath(), first, true);
15924
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1516215925 }
1516315926
1516415927 first = false;
....@@ -15167,6 +15930,7 @@
1516715930
1516815931 void SelectChildren()
1516915932 {
15933
+ new Exception().printStackTrace();
1517015934 System.exit(0);
1517115935 /*
1517215936 Composite group = (Composite) object;
....@@ -15199,12 +15963,12 @@
1519915963 for (int j = 0; j < group.children.size(); j++)
1520015964 {
1520115965 elem = (Object3D) group.children.elementAt(j);
15202
- object.editWindow.Select(elem.GetTreePath(), first, true);
15966
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1520315967 first = false;
1520415968 }
1520515969 } else
1520615970 {
15207
- object.editWindow.Select(elem.GetTreePath(), first, true);
15971
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1520815972 }
1520915973
1521015974 first = false;
....@@ -15215,21 +15979,21 @@
1521515979 {
1521615980 //Composite group = (Composite) object;
1521715981 Object3D group = object;
15218
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15982
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1521915983 }
1522015984
1522115985 void ResetTransform(int mask)
1522215986 {
1522315987 //Composite group = (Composite) object;
1522415988 Object3D group = object;
15225
- group.editWindow.ResetTransform(mask);
15989
+ group.GetWindow().ResetTransform(mask);
1522615990 }
1522715991
1522815992 void FlipTransform()
1522915993 {
1523015994 //Composite group = (Composite) object;
1523115995 Object3D group = object;
15232
- group.editWindow.FlipTransform();
15996
+ group.GetWindow().FlipTransform();
1523315997 // group.editWindow.ReduceMesh(true);
1523415998 }
1523515999
....@@ -15237,7 +16001,7 @@
1523716001 {
1523816002 //Composite group = (Composite) object;
1523916003 Object3D group = object;
15240
- group.editWindow.PrintMemory();
16004
+ group.GetWindow().PrintMemory();
1524116005 // group.editWindow.ReduceMesh(true);
1524216006 }
1524316007
....@@ -15245,7 +16009,7 @@
1524516009 {
1524616010 //Composite group = (Composite) object;
1524716011 Object3D group = object;
15248
- group.editWindow.ResetCentroid();
16012
+ group.GetWindow().ResetCentroid();
1524916013 }
1525016014
1525116015 void IncDepth()
....@@ -15327,11 +16091,11 @@
1532716091
1532816092 int width = getBounds().width;
1532916093 int height = getBounds().height;
15330
- ClickInfo info = new ClickInfo();
15331
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1533216094 //Image img = CreateImage(width, height);
1533316095 //System.out.println("width = " + width + "; height = " + height + "\n");
16096
+
1533416097 Graphics gr = g; // img.getGraphics();
16098
+
1533516099 if (!hasMarquee)
1533616100 {
1533716101 if (Xmin < Xmax) // !locked)
....@@ -15403,44 +16167,92 @@
1540316167 }
1540416168 if (object != null && !hasMarquee)
1540516169 {
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
+
1540616176 if (isRenderer)
1540716177 {
15408
- info.flags++;
16178
+ object.clickInfo.flags++;
1540916179 double frameAspect = (double) width / (double) height;
1541016180 if (frameAspect > renderCamera.aspect)
1541116181 {
1541216182 int desired = (int) ((double) height * renderCamera.aspect);
15413
- info.bounds.width -= width - desired;
15414
- info.bounds.x += (width - desired) / 2;
16183
+ object.clickInfo.bounds.width -= width - desired;
16184
+ object.clickInfo.bounds.x += (width - desired) / 2;
1541516185 } else
1541616186 {
1541716187 int desired = (int) ((double) width / renderCamera.aspect);
15418
- info.bounds.height -= height - desired;
15419
- info.bounds.y += (height - desired) / 2;
16188
+ object.clickInfo.bounds.height -= height - desired;
16189
+ object.clickInfo.bounds.y += (height - desired) / 2;
1542016190 }
1542116191 }
15422
- info.g = gr;
15423
- info.camera = renderCamera;
16192
+
16193
+ object.clickInfo.g = gr;
16194
+ object.clickInfo.camera = renderCamera;
1542416195 /*
1542516196 // Memory intensive (brep.verticescopy)
1542616197 if (!(object instanceof Composite))
1542716198 object.draw(info, 0, false); // SLOW :
1542816199 */
15429
- if (!isRenderer)
16200
+ if (!isRenderer) // && drag)
1543016201 {
15431
- 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
+ }
1543216242 }
1543316243 }
16244
+
1543416245 if (isRenderer)
1543516246 {
1543616247 //gr.setColor(Color.black);
1543716248 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1543816249 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1543916250 }
16251
+
1544016252 if (hasMarquee)
1544116253 {
1544216254 gr.setXORMode(Color.white);
15443
- gr.setColor(Color.red);
16255
+ gr.setColor(Color.white);
1544416256 if (!firstime)
1544516257 {
1544616258 gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH);
....@@ -15549,6 +16361,7 @@
1554916361 public boolean mouseDown(Event evt, int x, int y)
1555016362 {
1555116363 System.out.println("mouseDown: " + evt);
16364
+ System.exit(0);
1555216365 /*
1555316366 locked = true;
1555416367 drag = false;
....@@ -15592,7 +16405,7 @@
1559216405 {
1559316406 keyPressed(0, modifiers);
1559416407 }
15595
- clickStart(x, y, modifiers);
16408
+ // clickStart(x, y, modifiers);
1559616409 return true;
1559716410 }
1559816411
....@@ -15710,7 +16523,7 @@
1571016523 {
1571116524 keyReleased(0, 0);
1571216525 }
15713
- drag(x, y, modifiers);
16526
+ drag(x, y, 0, modifiers);
1571416527 return true;
1571516528 }
1571616529
....@@ -15842,7 +16655,7 @@
1584216655 Object3D object;
1584316656 static Object3D trackedobject;
1584416657 Camera renderCamera; // Light or Eye (or Occlusion)
15845
- /*static*/ Camera manipCamera; // Light or Eye
16658
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1584616659 /*static*/ Camera eyeCamera;
1584716660 /*static*/ Camera lightCamera;
1584816661 int cameracount;
....@@ -15906,6 +16719,8 @@
1590616719 private /*static*/ boolean firstime;
1590716720 private /*static*/ cVector newView = new cVector();
1590816721 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"};
1590916724 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1591016725 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1591116726 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -15918,29 +16733,67 @@
1591816733 {
1591916734 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1592016735
16736
+ int usedsuf = 0;
16737
+
1592116738 for (int i = 0; i < suffixes.length; i++)
1592216739 {
15923
- String resourceName = basename + suffixes[i] + "." + suffix;
15924
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
15925
- mipmapped,
15926
- FileUtil.getFileSuffix(resourceName));
15927
- if (data == null)
16740
+ String[] suffixe = suffixes;
16741
+ String[] fallback = suffixes2;
16742
+ String[] fallfallback = suffixes3;
16743
+
16744
+ for (int c=usedsuf; --c>=0;)
1592816745 {
15929
- throw new IOException("Unable to load texture " + resourceName);
16746
+// String[] temp = suffixe;
16747
+// suffixe = fallback;
16748
+// fallback = fallfallback;
16749
+// fallfallback = temp;
1593016750 }
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
+
1593116779 //System.out.println("Target = " + targets[i]);
1593216780 cubemap.updateImage(data, targets[i]);
1593316781 }
1593416782
1593516783 return cubemap;
1593616784 }
16785
+
1593716786 int bigsphere = -1;
1593816787
1593916788 float BGcolor = 0.5f;
1594016789
15941
- private void DrawSkyBox(GL gl)
16790
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16791
+
16792
+ private void DrawSkyBox(GL gl, float ratio)
1594216793 {
15943
- if (envyoff || cubemap == null)
16794
+ if (//envyoff ||
16795
+ WIREFRAME ||
16796
+ cubemap == null)
1594416797 {
1594516798 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1594616799 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -15955,7 +16808,17 @@
1595516808 // Compensates for ExaminerViewer's modification of modelview matrix
1595616809 gl.glMatrixMode(GL.GL_MODELVIEW);
1595716810 gl.glLoadIdentity();
16811
+ gl.glScalef(1,ratio,1);
1595816812
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
+
1595916822 //gl.glActiveTexture(GL.GL_TEXTURE1);
1596016823 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1596116824
....@@ -15987,6 +16850,7 @@
1598716850 {
1598816851 gl.glScalef(1.0f, -1.0f, 1.0f);
1598916852 }
16853
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1599016854 gl.glMultMatrixd(viewrot_1, 0);
1599116855 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1599216856 //viewer.updateInverseRotation(gl);
....@@ -16027,7 +16891,8 @@
1602716891 gl.glDisable(GL.GL_TEXTURE_GEN_R);
1602816892
1602916893 cubemap.disable();
16030
- ////cubemap.unbind();
16894
+ //cubemap.dispose();
16895
+
1603116896 if (CULLFACE)
1603216897 {
1603316898 gl.glEnable(gl.GL_CULL_FACE);
....@@ -16083,7 +16948,7 @@
1608316948 gl.glScalef(1.0f, -1.0f, 1.0f);
1608416949 }
1608516950
16086
- gl.glNormal3f(0.0f, 0.0f, 1.0f);
16951
+ SetGLNormal(gl, 0.0f, 0.0f, 1.0f);
1608716952
1608816953 float step = 2; // 0.1666f; //0.25f;
1608916954 float stepv = 2; // step * 1652 / 998;
....@@ -16127,16 +16992,16 @@
1612716992 cStatic.objectstack[materialdepth++] = checker;
1612816993 //System.out.println("material " + material);
1612916994 //Applet3D.tracein(this, selected);
16130
- vector2buffer = checker.projectedVertices;
16995
+ //vector2buffer = checker.projectedVertices;
1613116996
1613216997 //checker.GetMaterial().Draw(this, false); // true);
16133
- DrawMaterial(checker.GetMaterial(), false); // true);
16998
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1613416999
1613517000 materialdepth -= 1;
1613617001 if (materialdepth > 0)
1613717002 {
16138
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16139
- 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);
1614017005 }
1614117006 //checker.GetMaterial().opacity = 1f;
1614217007 ////checker.GetMaterial().ambient = 1f;
....@@ -16222,6 +17087,14 @@
1622217087 }
1622317088 }
1622417089
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
+
1622517098 class SelectBuffer implements GLEventListener
1622617099 {
1622717100
....@@ -16237,7 +17110,7 @@
1623717110 //new Exception().printStackTrace();
1623817111 System.out.println("select buffer init");
1623917112 // Use debug pipeline
16240
- drawable.setGL(new DebugGL(drawable.getGL()));
17113
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1624117114
1624217115 GL gl = drawable.getGL();
1624317116
....@@ -16280,6 +17153,7 @@
1628017153 {
1628117154 if (!selection)
1628217155 {
17156
+ new Exception().printStackTrace();
1628317157 System.exit(0);
1628417158 return;
1628517159 }
....@@ -16300,6 +17174,17 @@
1630017174
1630117175 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1630217176
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
+
1630317188 //int tmp = selection_view;
1630417189 //selection_view = -1;
1630517190 int temp = DrawMode();
....@@ -16311,6 +17196,17 @@
1631117196 // temp = DEFAULT; // patch for selection debug
1631217197 Globals.drawMode = temp; // WARNING
1631317198
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
+
1631417210 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1631517211
1631617212 // trying different ways of getting the depth info over
....@@ -16358,6 +17254,8 @@
1635817254 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1635917255 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1636017256 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
17257
+
17258
+ CreateSelectedPoint();
1636117259
1636217260 // Will fit the mesh !!!
1636317261 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16407,34 +17305,36 @@
1640717305 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]));
1640817306 }
1640917307
16410
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
17308
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1641117309 }
1641217310 }
1641317311
1641417312 if (!movingcamera && !PAINTMODE)
16415
- object.editWindow.ScreenFitPoint(); // fev 2014
17313
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1641617314
16417
- 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)
1641817316 {
16419
- 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);
1642017318
16421
- Object3D group = new Object3D("inst" + paintcount++);
17319
+ if (object.GetWindow().copy.selection.Size() > 0)
17320
+ {
17321
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1642217322
16423
- group.CreateMaterial(); // use a void leaf to select instances
16424
-
16425
- group.add(paintobj); // link
16426
-
16427
- object.editWindow.SnapObject(group);
16428
-
16429
- Object3D folder = object.editWindow.copy;
16430
-
16431
- if (object.editWindow.copy.selection.Size() > 0)
16432
- folder = object.editWindow.copy.selection.elementAt(0);
16433
-
16434
- folder.add(group);
16435
-
16436
- object.editWindow.ResetModel();
16437
- 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
+ }
1643817338 }
1643917339 else
1644017340 paintcount = 0;
....@@ -16473,6 +17373,11 @@
1647317373 //System.out.println("objects[color] = " + objects[color]);
1647417374 //objects[color].Select();
1647517375 indexcount = 0;
17376
+ ObjEditor window = object.GetWindow();
17377
+ if (window != null && deselect)
17378
+ {
17379
+ window.Select(null, deselect, true);
17380
+ }
1647617381 object.Select(color, deselect);
1647717382 }
1647817383
....@@ -16523,6 +17428,7 @@
1652317428
1652417429 public void init(GLAutoDrawable drawable)
1652517430 {
17431
+ if (Globals.DEBUG)
1652617432 System.out.println("shadow buffer init");
1652717433
1652817434 GL gl = drawable.getGL();
....@@ -16572,7 +17478,7 @@
1657217478 gl.glDisable(gl.GL_CULL_FACE);
1657317479 }
1657417480
16575
- if (!RENDERSHADOW)
17481
+ if (!Globals.RENDERSHADOW)
1657617482 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1657717483
1657817484 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -16582,7 +17488,7 @@
1658217488 //gl.glColorMask(false, false, false, false);
1658317489
1658417490 //render_scene_from_light_view(gl, drawable, 0, 0);
16585
- if (RENDERSHADOW && Globals.lighttouched && !movingcamera) // && !parent.IsFreezed())
17491
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1658617492 {
1658717493 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1658817494
....@@ -16751,10 +17657,14 @@
1675117657 gl.glFlush();
1675217658
1675317659 /**/
16754
- 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);
1675517661
16756
- float[] pixels = occlusionsizebuffer.array();
17662
+ float[] depths = occlusiondepthbuffer.array();
1675717663
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
+
1675817668 double r = 0, g = 0, b = 0;
1675917669
1676017670 double count = 0;
....@@ -16765,7 +17675,7 @@
1676517675
1676617676 double FACTOR = 1;
1676717677
16768
- for (int i = 0; i < pixels.length; i++)
17678
+ for (int i = 0; i < depths.length; i++)
1676917679 {
1677017680 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1677117681 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -16848,7 +17758,7 @@
1684817758
1684917759 double scale = ray.z; // 1; // cos
1685017760
16851
- float depth = pixels[newindex];
17761
+ float depth = depths[newindex];
1685217762
1685317763 /*
1685417764 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -16998,23 +17908,15 @@
1699817908 int AAbuffersize = 0;
1699917909
1700017910 //double[] selectedpoint = new double[3];
17001
- static Superellipsoid selectedpoint = new Superellipsoid();
17911
+ static Superellipsoid selectedpoint;
1700217912 static Sphere previousselectedpoint = null;
17003
- static Sphere debugpointG = new Sphere();
17004
- static Sphere debugpointP = new Sphere();
17005
- static Sphere debugpointC = new Sphere();
17006
- static Sphere debugpointR = new Sphere();
17913
+ static Sphere debugpointG;
17914
+ static Sphere debugpointP;
17915
+ static Sphere debugpointC;
17916
+ static Sphere debugpointR;
1700717917
1700817918 static Sphere debugpoints[] = new Sphere[8];
1700917919
17010
- static
17011
- {
17012
- for (int i=0; i<8; i++)
17013
- {
17014
- debugpoints[i] = new Sphere();
17015
- }
17016
- }
17017
-
1701817920 static void InitPoints(float radius)
1701917921 {
1702017922 for (int i=0; i<8; i++)
....@@ -17053,11 +17955,14 @@
1705317955 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1705417956 static IntBuffer bigAAbuffer;
1705517957 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
17056
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17958
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1705717959 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1705817960 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1705917961 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17060
- 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
+
1706117966 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1706217967 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1706317968 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();