Normand Briere
2019-08-23 60cec91731a350fe67e9b5ffe7a00d70e9026314
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)
....@@ -810,7 +881,7 @@
810881 //// tris.postdraw(this);
811882 }
812883
813
- static Camera localcamera = new Camera();
884
+ static Camera localAOcamera = new Camera();
814885 static cVector from = new cVector();
815886 static cVector to = new cVector();
816887
....@@ -819,7 +890,7 @@
819890 CameraPane cp = this;
820891
821892 Camera keep = cp.RenderCamera();
822
- cp.renderCamera = localcamera;
893
+ cp.renderCamera = localAOcamera;
823894
824895 if (br.trimmed)
825896 {
....@@ -837,7 +908,7 @@
837908 br.positions[i3 + 2] + br.normals[i3 + 2]);
838909 LA.xformPos(from, transform, from);
839910 LA.xformPos(to, transform, to); // RIGID ONLY
840
- localcamera.setAim(from, to);
911
+ localAOcamera.setAim(from, to);
841912
842913 CameraPane.occlusionbuffer.display();
843914
....@@ -871,7 +942,7 @@
871942 to.set(v.x+v.norm.x, v.y+v.norm.y, v.z+v.norm.z);
872943 LA.xformPos(from, transform, from);
873944 LA.xformPos(to, transform, to); // RIGID ONLY
874
- localcamera.setAim(from, to);
945
+ localAOcamera.setAim(from, to);
875946
876947 CameraPane.occlusionbuffer.display();
877948
....@@ -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 {
....@@ -7902,7 +8039,7 @@
79028039 String pigment = Object3D.GetPigment(tex);
79038040 String bump = Object3D.GetBump(tex);
79048041
7905
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8042
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79068043 {
79078044 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79088045 // System.out.println("; bump = " + bump);
....@@ -7917,11 +8054,69 @@
79178054 pigment = null;
79188055 }
79198056
7920
- ReleaseTexture(bump, true);
7921
- ReleaseTexture(pigment, false);
8057
+ ReleaseTexture(tex, true);
8058
+ ReleaseTexture(tex, false);
79228059 }
79238060
7924
- 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)
79258120 {
79268121 if (// DrawMode() != 0 || /*tex == null ||*/
79278122 ambientOcclusion ) // || !textureon)
....@@ -7932,7 +8127,7 @@
79328127 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
79338128
79348129 if (tex != null)
7935
- texture = textures.get(tex);
8130
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
79368131
79378132 // //assert( texture != null );
79388133 // if (texture == null)
....@@ -8024,7 +8219,55 @@
80248219 }
80258220 }
80268221
8027
- /*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
80288271 {
80298272 if (// DrawMode() != 0 || /*tex == null ||*/
80308273 ambientOcclusion ) // || !textureon)
....@@ -8035,17 +8278,47 @@
80358278 if (tex == null)
80368279 {
80378280 BindTexture(null,false,resolution);
8038
- BindTexture(null,true,resolution);
80398281 return;
80408282 }
80418283
80428284 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
+
80438317 String bump = Object3D.GetBump(tex);
80448318
8045
- usedtextures.put(pigment, pigment);
8046
- usedtextures.put(bump, bump);
8319
+ usedtextures.add(tex);
80478320
8048
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8321
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
80498322 {
80508323 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
80518324 // System.out.println("; bump = " + bump);
....@@ -8055,43 +8328,94 @@
80558328 {
80568329 bump = null;
80578330 }
8058
- if (pigment.equals(""))
8059
- {
8060
- pigment = null;
8061
- }
80628331
8063
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8064
- BindTexture(pigment, false, resolution);
80658332 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8066
- BindTexture(bump, true, resolution);
8333
+ BindTexture(tex, true, resolution);
80678334 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8068
-
8069
- return; // true;
80708335 }
80718336
8072
- 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)
80738340 {
8074
- 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;
80758360
80768361 if (tex != null)
80778362 {
8078
- String texname = tex;
8363
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8364
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
80798365
8080
- String[] split = tex.split("Textures");
8081
- if (split.length > 1)
8082
- texname = "/Users/nbriere/Textures" + split[split.length-1];
8083
- else
8084
- if (!texname.startsWith("/"))
8085
- 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
+ }
80868383
80878384 if (CACHETEXTURE)
8088
- texture = textures.get(texname); // TEXTURE CACHE
8089
-
8090
- TextureData texturedata = null;
8091
-
8092
- if (texture == null || texture.resolution < resolution)
80938385 {
8094
- 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(""))
80958419 {
80968420 assert(!bump);
80978421 // if (bump)
....@@ -8102,19 +8426,23 @@
81028426 // }
81038427 // else
81048428 // {
8105
- texture = textures.get(tex);
8106
- if (texture == null)
8429
+ // texturecache = textures.get(texname); // suspicious
8430
+ if (texturecache == null)
81078431 {
8108
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8432
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
81098433 }
8434
+ else
8435
+ new Exception().printStackTrace();
81108436 // }
81118437 } else
8112
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8438
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
81138439 {
81148440 assert(bump);
8115
- texture = textures.get(tex);
8116
- if (texture == null)
8117
- 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();
81188446 } else
81198447 {
81208448 //if (tex.equals("IMMORTAL"))
....@@ -8122,11 +8450,22 @@
81228450 // texture = GetResourceTexture("default.png");
81238451 //} else
81248452 //{
8125
- if (tex.equals("WHITE_NOISE"))
8453
+ if (texname.endsWith("WHITE_NOISE"))
81268454 {
8127
- texture = textures.get(tex);
8128
- if (texture == null)
8129
- 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();
81308469 } else
81318470 {
81328471 if (textureon)
....@@ -8151,7 +8490,7 @@
81518490 }
81528491
81538492 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
8154
- if (!new File(cachename).exists())
8493
+ if (!FileExists(cachename))
81558494 cachename = texname;
81568495 else
81578496 processbump = false; // don't process bump map again
....@@ -8173,7 +8512,7 @@
81738512 }
81748513
81758514 cachename = texname.substring(0, texname.length()-4)+ext+".png";
8176
- if (!new File(cachename).exists())
8515
+ if (!FileExists(cachename))
81778516 cachename = texname;
81788517 else
81798518 processbump = false; // don't process bump map again
....@@ -8182,20 +8521,23 @@
81828521 texturedata = GetFileTexture(cachename, processbump, resolution);
81838522
81848523
8185
- if (texturedata != null)
8186
- 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);
81878528 //texture = GetTexture(tex, bump);
81888529 }
8530
+ }
81898531 }
81908532 //}
81918533 }
81928534
8193
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8535
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
81948536 {
81958537 //return false;
81968538
81978539 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8198
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8540
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
81998541 {
82008542 // String ext = "_highres";
82018543 // if (REDUCETEXTURE)
....@@ -8212,52 +8554,17 @@
82128554 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
82138555 if (!cachefile.exists())
82148556 {
8215
- // cache to disk
8216
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
8217
- //buffers[0].
8218
-
8219
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
8220
- int[] pixels = new int[bytebuf.capacity()/3];
8221
-
8222
- // squared size heuristic...
8223
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8557
+ //if (texturedata.getWidth() == texturedata.getHeight())
82248558 {
8225
- for (int i=pixels.length; --i>=0;)
8226
- {
8227
- int i3 = i*3;
8228
- pixels[i] = 0xFF;
8229
- pixels[i] <<= 8;
8230
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
8231
- pixels[i] <<= 8;
8232
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
8233
- pixels[i] <<= 8;
8234
- pixels[i] |= bytebuf.get(i3) & 0xFF;
8235
- }
8236
-
8237
- /*
8238
- int r=0,g=0,b=0,a=0;
8239
- for (int i=0; i<width; i++)
8240
- for (int j=0; j<height; j++)
8241
- {
8242
- int index = j*width+i;
8243
- int p = pixels[index];
8244
- a = ((p>>24) & 0xFF);
8245
- r = ((p>>16) & 0xFF);
8246
- g = ((p>>8) & 0xFF);
8247
- b = (p & 0xFF);
8248
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
8249
- }
8250
- /**/
8251
- int width = (int)Math.sqrt(pixels.length); // squared
8252
- int height = width;
8253
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
8254
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8559
+ BufferedImage rendImage = CreateBim(texturedata);
8560
+
82558561 ImageWriter writer = null;
82568562 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
82578563 if (iter.hasNext()) {
82588564 writer = (ImageWriter)iter.next();
82598565 }
8260
- float compressionQuality = 0.9f;
8566
+
8567
+ float compressionQuality = 0.85f;
82618568 try
82628569 {
82638570 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8274,18 +8581,20 @@
82748581 }
82758582 }
82768583 }
8277
-
8584
+
8585
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8586
+
82788587 //System.out.println("Texture = " + tex);
8279
- if (textures.containsKey(texname))
8588
+ if (textures.containsKey(tex))
82808589 {
8281
- CacheTexture thetex = textures.get(texname);
8590
+ CacheTexture thetex = textures.get(tex);
82828591 thetex.texture.disable();
82838592 thetex.texture.dispose();
8284
- textures.remove(texname);
8593
+ textures.remove(tex);
82858594 }
82868595
8287
- texture.texturedata = texturedata;
8288
- textures.put(texname, texture);
8596
+ //texture.texturedata = texturedata;
8597
+ textures.put(tex, texturecache);
82898598
82908599 // newtex = true;
82918600 }
....@@ -8301,10 +8610,44 @@
83018610 }
83028611 }
83038612
8304
- return texture;
8613
+ return texturecache;
83058614 }
83068615
8307
- 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
83088651 {
83098652 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
83108653
....@@ -8322,21 +8665,21 @@
83228665 return texture!=null?texture.texture:null;
83238666 }
83248667
8325
- 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
83268669 {
83278670 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
83288671
83298672 return texture!=null?texture.texturedata:null;
83308673 }
83318674
8332
- boolean BindTexture(String tex, boolean bump, int resolution)
8675
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
83338676 {
83348677 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
83358678 {
83368679 return false;
83378680 }
83388681
8339
- boolean newtex = false;
8682
+ //boolean newtex = false;
83408683
83418684 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
83428685
....@@ -8368,9 +8711,75 @@
83688711 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
83698712 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
83708713
8371
- return newtex;
8714
+ return true; // Warning: not used.
83728715 }
83738716
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
+
83748783 ShadowBuffer shadowPBuf;
83758784 AntialiasBuffer antialiasPBuf;
83768785 int MAXSTACK;
....@@ -8387,10 +8796,12 @@
83878796
83888797 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
83898798 MAXSTACK = temp[0];
8390
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8799
+ if (Globals.DEBUG)
8800
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
83918801 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
83928802 MAXSTACK = temp[0];
8393
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8803
+ if (Globals.DEBUG)
8804
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
83948805
83958806 // Use debug pipeline
83968807 //drawable.setGL(new DebugGL(gl)); //
....@@ -8398,7 +8809,8 @@
83988809 gl = drawable.getGL(); //
83998810
84008811 GL gl3 = getGL();
8401
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8812
+ if (Globals.DEBUG)
8813
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
84028814
84038815
84048816 //float pos[] = { 100, 100, 100, 0 };
....@@ -8563,7 +8975,7 @@
85638975
85648976 if (cubemap == null)
85658977 {
8566
- LoadEnvy(5);
8978
+ //LoadEnvy(1);
85678979 }
85688980
85698981 //cubemap.enable();
....@@ -8839,6 +9251,8 @@
88399251
88409252 void LoadEnvy(int which)
88419253 {
9254
+ assert(false);
9255
+
88429256 String name;
88439257 String ext;
88449258
....@@ -8850,37 +9264,58 @@
88509264 cubemap = null;
88519265 return;
88529266 case 1:
8853
- name = "cubemaps/box_";
8854
- ext = "png";
9267
+ name = "cubemaps/rgb/";
9268
+ ext = "jpg";
88559269 reverseUP = false;
88569270 break;
88579271 case 2:
8858
- name = "cubemaps/uffizi_";
8859
- ext = "png";
8860
- break; // reverseUP = true; break;
9272
+ name = "cubemaps/uffizi/";
9273
+ ext = "jpg";
9274
+ reverseUP = false;
9275
+ break;
88619276 case 3:
8862
- name = "cubemaps/CloudyHills_";
8863
- ext = "tga";
9277
+ name = "cubemaps/CloudyHills/";
9278
+ ext = "jpg";
88649279 reverseUP = false;
88659280 break;
88669281 case 4:
8867
- name = "cubemaps/cornell_";
9282
+ name = "cubemaps/cornell/";
88689283 ext = "png";
88699284 reverseUP = false;
88709285 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;
88719311 default:
8872
- name = "cubemaps/rgb_";
8873
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9312
+ name = "cubemaps/box/";
9313
+ ext = "png"; /*mipmap = true;*/
9314
+ reverseUP = false;
88749315 break;
88759316 }
8876
-
8877
- try
8878
- {
8879
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
8880
- } catch (IOException e)
8881
- {
8882
- throw new RuntimeException(e);
8883
- }
9317
+
9318
+ LoadSkybox(name, ext, mipmap);
88849319 }
88859320
88869321 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -8912,8 +9347,12 @@
89129347 static double[] model = new double[16];
89139348 double[] camera2light = new double[16];
89149349 double[] light2camera = new double[16];
8915
- int newenvy = -1;
8916
- boolean envyoff = true; // false;
9350
+
9351
+ //int newenvy = -1;
9352
+ //boolean envyoff = false;
9353
+
9354
+ String loadedskyboxname;
9355
+
89179356 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
89189357 //float[] light0 = { 0,0,0 };
89199358 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9206,11 +9645,35 @@
92069645 jy8[3] = 0.5f;
92079646 }
92089647
9209
- 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
92109649 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
92119650 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
92129651 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
92139652
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
+
92149677 static int imagecount = 0; // movie generation
92159678
92169679 static int jitter = 0;
....@@ -9306,8 +9769,8 @@
93069769 assert (parentcam != renderCamera);
93079770
93089771 if (renderCamera != lightCamera)
9309
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9310
- LA.matConcat(matrix, parentcam.toParent, matrix);
9772
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9773
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
93119774
93129775 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
93139776
....@@ -9322,8 +9785,8 @@
93229785 LA.matCopy(renderCamera.fromScreen, matrix);
93239786
93249787 if (renderCamera != lightCamera)
9325
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9326
- LA.matConcat(parentcam.fromParent, matrix, matrix);
9788
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9789
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
93279790
93289791 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
93299792
....@@ -9369,10 +9832,12 @@
93699832 rati = 1 / rati;
93709833 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
93719834 }
9372
- assert (newenvy == -1);
9835
+
9836
+ //assert (newenvy == -1);
9837
+
93739838 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
93749839 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9375
- DrawSkyBox(gl);
9840
+ DrawSkyBox(gl, (float)rati);
93769841 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
93779842 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
93789843 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -9395,7 +9860,7 @@
93959860 //gl.glFlush();
93969861 gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE);
93979862
9398
- if (ANIMATION && ABORTED)
9863
+ if (Globals.ANIMATION && ABORTED)
93999864 {
94009865 System.err.println(" ABORTED FRAME");
94019866 break;
....@@ -9425,7 +9890,7 @@
94259890 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
94269891
94279892 // save image
9428
- if (ANIMATION && !ABORTED)
9893
+ if (Globals.ANIMATION && !ABORTED)
94299894 {
94309895 VPwidth = viewport[2];
94319896 VPheight = viewport[3];
....@@ -9536,11 +10001,11 @@
953610001
953710002 // imagecount++;
953810003
9539
- 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;
954010005
954110006 if (!BOXMODE)
954210007 {
9543
- 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) + ")");
954410009 }
954510010
954610011 if (!BOXMODE)
....@@ -9578,7 +10043,7 @@
957810043 ABORTED = false;
957910044 }
958010045 else
9581
- GrafreeD.wav.cursor += 735 * ACSIZE;
10046
+ Grafreed.wav.cursor += 735 * ACSIZE;
958210047
958310048 if (false)
958410049 {
....@@ -10238,14 +10703,23 @@
1023810703 static boolean init = false;
1023910704
1024010705 double[][] matrix = LA.newMatrix();
10706
+
10707
+ // This is to refresh the UI of the material panel.
10708
+ ObjEditor patchMaterial;
1024110709
1024210710 public void display(GLAutoDrawable drawable)
1024310711 {
10244
- if (GrafreeD.savesound && GrafreeD.hassound)
10712
+ if (patchMaterial.patchMaterial)
1024510713 {
10246
- GrafreeD.wav.save();
10247
- GrafreeD.savesound = false;
10248
- 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;
1024910723 }
1025010724 // if (DEBUG_SELECTION)
1025110725 // {
....@@ -10321,6 +10795,7 @@
1032110795 ANTIALIAS = 0;
1032210796 //System.out.println("RESTART");
1032310797 AAtimer.restart();
10798
+ Globals.TIMERRUNNING = true;
1032410799 }
1032510800 }
1032610801 }
....@@ -10375,7 +10850,7 @@
1037510850 Object3D theobject = object;
1037610851 Object3D theparent = object.parent;
1037710852 object.parent = null;
10378
- object = (Object3D)GrafreeD.clone(object);
10853
+ object = (Object3D)Grafreed.clone(object);
1037910854 object.Stripify();
1038010855 if (theobject.selection == null || theobject.selection.Size() == 0)
1038110856 theobject.PreprocessOcclusion(this);
....@@ -10388,13 +10863,14 @@
1038810863 ambientOcclusion = false;
1038910864 }
1039010865
10391
- if (Globals.lighttouched && DrawMode() == DEFAULT && !lightMode) // && !FROZEN)
10866
+ if (//Globals.lighttouched &&
10867
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1039210868 {
1039310869 //if (RENDERSHADOW) // ?
1039410870 if (!IsFrozen())
1039510871 {
1039610872 // dec 2012
10397
- if (!ambientOcclusion && !(!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0))
10873
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
1039810874 {
1039910875 Globals.framecount++;
1040010876 shadowbuffer.display();
....@@ -10407,7 +10883,7 @@
1040710883
1040810884 if (wait)
1040910885 {
10410
- Sleep(500);
10886
+ Sleep(200); // blocks everything
1041110887
1041210888 wait = false;
1041310889 }
....@@ -10521,8 +10997,8 @@
1052110997
1052210998 // if (parentcam != renderCamera) // not a light
1052310999 if (cam != lightCamera)
10524
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10525
- LA.matConcat(matrix, parentcam.toParent, matrix);
11000
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11001
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1052611002
1052711003 for (int j = 0; j < 4; j++)
1052811004 {
....@@ -10536,8 +11012,8 @@
1053611012
1053711013 // if (parentcam != renderCamera) // not a light
1053811014 if (cam != lightCamera)
10539
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10540
- LA.matConcat(parentcam.fromParent, matrix, matrix);
11015
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11016
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1054111017
1054211018 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1054311019
....@@ -10623,13 +11099,43 @@
1062311099 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1062411100 }
1062511101
10626
- 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"))
1062711110 {
10628
- LoadEnvy(newenvy);
11111
+ if (cubemaprgb == null)
11112
+ {
11113
+ cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb2" + "/", "jpg", false);
11114
+ }
11115
+
11116
+ cubemap = cubemaprgb;
1062911117 }
10630
-
10631
- newenvy = -1;
10632
-
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
+
1063311139 ratio = ((double) getWidth()) / getHeight();
1063411140 //System.out.println("ratio = " + ratio);
1063511141
....@@ -10645,7 +11151,7 @@
1064511151
1064611152 if (!IsFrozen() && !ambientOcclusion)
1064711153 {
10648
- DrawSkyBox(gl);
11154
+ DrawSkyBox(gl, (float)ratio);
1064911155 }
1065011156
1065111157 //if (selection_view == -1)
....@@ -10796,7 +11302,16 @@
1079611302 // Bump noise
1079711303 gl.glActiveTexture(GL.GL_TEXTURE6);
1079811304 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
10799
- 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
+
1080011315
1080111316 gl.glActiveTexture(GL.GL_TEXTURE0);
1080211317 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -10819,9 +11334,9 @@
1081911334
1082011335 gl.glMatrixMode(GL.GL_MODELVIEW);
1082111336
10822
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10823
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10824
-//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);
1082511340 } else
1082611341 {
1082711342 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -10832,7 +11347,7 @@
1083211347 //System.out.println("BLENDING ON");
1083311348 gl.glEnable(GL.GL_BLEND);
1083411349 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
10835
-
11350
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1083611351 gl.glMatrixMode(gl.GL_PROJECTION);
1083711352 gl.glLoadIdentity();
1083811353
....@@ -10921,8 +11436,8 @@
1092111436 System.err.println("parentcam != renderCamera");
1092211437
1092311438 // if (cam != lightCamera)
10924
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10925
- 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
1092611441 }
1092711442
1092811443 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -10943,8 +11458,8 @@
1094311458 if (true) // TODO
1094411459 {
1094511460 if (cam != lightCamera)
10946
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10947
- 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
1094811463 }
1094911464
1095011465 LA.xformPos(light0, cam.toScreen, light0);
....@@ -11081,7 +11596,7 @@
1108111596 }
1108211597 }
1108311598
11084
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11599
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1108511600 {
1108611601 //gl.glDepthFunc(GL.GL_LEQUAL);
1108711602 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11089,24 +11604,21 @@
1108911604
1109011605 boolean texon = textureon;
1109111606
11092
- if (RENDERPROGRAM > 0)
11093
- {
11094
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11095
- textureon = false;
11096
- }
11607
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11608
+ textureon = false;
11609
+
1109711610 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1109811611 //System.out.println("ALLO");
1109911612 gl.glColorMask(false, false, false, false);
1110011613 DrawObject(gl);
11101
- if (RENDERPROGRAM > 0)
11102
- {
11103
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11104
- textureon = texon;
11105
- }
11614
+
11615
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11616
+ textureon = texon;
11617
+
1110611618 gl.glColorMask(true, true, true, true);
1110711619
1110811620 gl.glDepthFunc(GL.GL_EQUAL);
11109
- //gl.glDepthMask(false);
11621
+ gl.glDepthMask(false);
1111011622 }
1111111623
1111211624 if (false) // DrawMode() == SHADOW)
....@@ -11260,8 +11772,14 @@
1126011772 {
1126111773 renderpass++;
1126211774 // System.out.println("Draw object... ");
11775
+ STEP = 1;
1126311776 if (FAST) // in case there is no script
11264
- STEP = 16;
11777
+ STEP = 8;
11778
+
11779
+ if (CURRENTANTIALIAS == 0 || ACSIZE == 1)
11780
+ {
11781
+ STEP *= 4;
11782
+ }
1126511783
1126611784 //object.FullInvariants();
1126711785
....@@ -11275,23 +11793,44 @@
1127511793 e.printStackTrace();
1127611794 }
1127711795
11278
- if (GrafreeD.RENDERME > 0)
11279
- GrafreeD.RENDERME--; // mechante magouille
11796
+ if (Grafreed.RENDERME > 0)
11797
+ Grafreed.RENDERME--; // mechante magouille
1128011798
1128111799 Globals.ONESTEP = false;
1128211800 }
1128311801
1128411802 static boolean zoomonce = false;
1128511803
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
+
1128611822 void DrawObject(GL gl, boolean draw)
1128711823 {
11824
+ // To clear camera values
11825
+ ResetOptions();
11826
+
1128811827 //System.out.println("DRAW OBJECT " + mouseDown);
1128911828 // DrawMode() = SELECTION;
1129011829 //GL gl = getGL();
1129111830 if ((TRACK || SHADOWTRACK) || zoomonce)
1129211831 {
1129311832 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11294
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11833
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1129511834 pingthread.StepToTarget(true); // true);
1129611835 // zoomonce = false;
1129711836 }
....@@ -11346,7 +11885,14 @@
1134611885
1134711886 usedtextures.clear();
1134811887
11349
- 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
+ }
1135011896 }
1135111897 //System.out.println("--> " + stackdepth);
1135211898 // GrafreeD.traceon();
....@@ -11356,8 +11902,9 @@
1135611902
1135711903 if (DrawMode() == DEFAULT)
1135811904 {
11359
- if (DEBUG)
11905
+ if (Globals.DEBUG)
1136011906 {
11907
+ CreateSelectedPoint();
1136111908 float radius = 0.05f;
1136211909 if (selectedpoint.radius != radius)
1136311910 {
....@@ -11411,20 +11958,32 @@
1141111958 ReleaseTextures(DEFAULT_TEXTURES);
1141211959
1141311960 if (CLEANCACHE)
11414
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11961
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1141511962 {
11416
- String tex = e.nextElement();
11963
+ cTexture tex = e.nextElement();
1141711964
1141811965 // System.out.println("Texture --------- " + tex);
1141911966
11420
- if (tex.equals("WHITE_NOISE"))
11967
+ if (tex.equals("WHITE_NOISE:"))
1142111968 continue;
1142211969
11423
- if (!usedtextures.containsKey(tex))
11970
+ if (!usedtextures.contains(tex))
1142411971 {
11972
+ CacheTexture gettex = texturepigment.get(tex);
1142511973 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11426
- textures.get(tex).texture.dispose();
11427
- 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
+ }
1142811987 }
1142911988 }
1143011989 }
....@@ -11437,7 +11996,14 @@
1143711996 if (checker != null && DrawMode() == DEFAULT)
1143811997 {
1143911998 //BindTexture(IMMORTAL_TEXTURE);
11440
- 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
+ }
1144112007 // NEAREST
1144212008 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
1144312009 DrawChecker(gl);
....@@ -11519,7 +12085,7 @@
1151912085 return;
1152012086 }
1152112087
11522
- String string = obj.GetToolTip();
12088
+ String string = obj.toString(); //.GetToolTip();
1152312089
1152412090 GL gl = GetGL();
1152512091
....@@ -11836,8 +12402,8 @@
1183612402 //obj.TransformToWorld(light, light);
1183712403 for (int i = tp.size(); --i >= 0;)
1183812404 {
11839
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
11840
- 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);
1184112407 }
1184212408
1184312409
....@@ -11854,8 +12420,8 @@
1185412420 parentcam = cameras[0];
1185512421 }
1185612422
11857
- for (int count = parentcam.GetTransformCount(); --count>=0;)
11858
- 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
1185912425
1186012426 LA.xformPos(light, renderCamera.toScreen, light);
1186112427
....@@ -11945,8 +12511,82 @@
1194512511
1194612512 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1194712513
11948
- String program =
12514
+ String programmin =
12515
+ // Min shader
1194912516 "!!ARBfp1.0\n" +
12517
+ "PARAM zero12t = { 0.0, 1.0, 2, 1.25 };" +
12518
+ "PARAM pow_2 = { 0.5, 0.25, 0.125, 0.0 };" +
12519
+ "PARAM pow2 = { 2, 4, 8, 0.0 };" +
12520
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12521
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12522
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12523
+ "PARAM light2cam0 = program.env[10];" +
12524
+ "PARAM light2cam1 = program.env[11];" +
12525
+ "PARAM light2cam2 = program.env[12];" +
12526
+ "TEMP temp;" +
12527
+ "TEMP light;" +
12528
+ "TEMP ndotl;" +
12529
+ "TEMP normal;" +
12530
+ "TEMP depth;" +
12531
+ "TEMP eye;" +
12532
+ "TEMP pos;" +
12533
+
12534
+ "MAD normal, fragment.color, zero12t.z, -zero12t.y;" +
12535
+ Normalize("normal") +
12536
+ "MOV light, state.light[0].position;" +
12537
+ "DP3 ndotl.x, light, normal;" +
12538
+ "MAX ndotl.x, ndotl.x, zero12t.x;" +
12539
+
12540
+ // shadow
12541
+ "MOV pos, fragment.texcoord[1];" +
12542
+ "MOV temp, pos;" +
12543
+ ShadowTextureFetch("depth", "temp", "1") +
12544
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12545
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12546
+
12547
+ // No shadow when out of frustum
12548
+ //"SGE temp.y, depth.z, zero123.y;" +
12549
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12550
+
12551
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12552
+
12553
+ // Backlit
12554
+ "MOV pos.w, zero12t.y;" + // one
12555
+ "DP4 eye.x, pos, light2cam0;" +
12556
+ "DP4 eye.y, pos, light2cam1;" +
12557
+ "DP4 eye.z, pos, light2cam2;" +
12558
+ Normalize("eye") +
12559
+
12560
+ "DP3 ndotl.y, -eye, normal;" +
12561
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12562
+ "POW ndotl.y, ndotl.y, pow2.x;" + // backlit
12563
+ "SUB ndotl.y, zero12t.y, ndotl.y;" + // 1 - y
12564
+ //"POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12565
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12566
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12567
+ "ADD ndotl.y, ndotl.y, one.x;" +
12568
+ "MUL ndotl.y, ndotl.y, pow_2.x;" +
12569
+
12570
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12571
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12572
+
12573
+ // Pigment
12574
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12575
+ "LRP temp, zero12t.w, temp, one;" + // texture proportion
12576
+ "MUL temp, temp, zero12t.w;" + // Times x
12577
+
12578
+ //"MUL temp, temp, ndotl.y;" +
12579
+ "MAD ndotl.x, pow_2.xxxx, ndotl.yyyy, ndotl.x;" +
12580
+
12581
+ "MUL temp, temp, ndotl.x;" + // lambert
12582
+
12583
+ "MOV temp.w, zero12t.y;" + // reset alpha
12584
+ "MOV result.color, temp;" +
12585
+ "END";
12586
+
12587
+ String programmax =
12588
+ "!!ARBfp1.0\n" +
12589
+
1195012590 //"OPTION ARB_fragment_program_shadow;" +
1195112591 "PARAM light2cam0 = program.env[10];" +
1195212592 "PARAM light2cam1 = program.env[11];" +
....@@ -11972,7 +12612,7 @@
1197212612 "PARAM params4 = program.env[4];" + // anisoV, cameralight, selfshadow, shadow
1197312613 "PARAM params5 = program.env[5];" + // texture, opacity, fakedepth, shadowbias
1197412614 "PARAM params6 = program.env[6];" + // bump, noise, borderfade, fog punchthrough
11975
- "PARAM params7 = program.env[7];" + // noise power, opacity power
12615
+ "PARAM params7 = program.env[7];" + // noise power, opacity power, parallax
1197612616 "PARAM options0 = program.env[63];" + // fog density, intensity, elevation
1197712617 "PARAM options1 = program.env[62];" + // fog rgb color
1197812618 "PARAM options2 = program.env[61];" + // image intensity, subsurface, lightsheen
....@@ -12061,8 +12701,7 @@
1206112701 "TEMP shininess;" +
1206212702 "\n" +
1206312703 "MOV texSamp, one;" +
12064
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12065
-
12704
+
1206612705 "MOV mapgrid.x, one2048th.x;" +
1206712706 "MOV temp, fragment.texcoord[1];" +
1206812707 /*
....@@ -12083,20 +12722,20 @@
1208312722 "MUL temp, floor, mapgrid.x;" +
1208412723 //"TEX depth0, temp, texture[1], 2D;" +
1208512724 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12086
- TextureFetch("depth0", "temp", "1") +
12725
+ ShadowTextureFetch("depth0", "temp", "1") +
1208712726 "") +
1208812727 "ADD temp.x, temp.x, mapgrid.x;" +
1208912728 //"TEX depth1, temp, texture[1], 2D;" +
1209012729 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12091
- TextureFetch("depth1", "temp", "1") +
12730
+ ShadowTextureFetch("depth1", "temp", "1") +
1209212731 "") +
1209312732 "ADD temp.y, temp.y, mapgrid.x;" +
1209412733 //"TEX depth2, temp, texture[1], 2D;" +
12095
- TextureFetch("depth2", "temp", "1") +
12734
+ ShadowTextureFetch("depth2", "temp", "1") +
1209612735 "SUB temp.x, temp.x, mapgrid.x;" +
1209712736 //"TEX depth3, temp, texture[1], 2D;" +
1209812737 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12099
- TextureFetch("depth3", "temp", "1") +
12738
+ ShadowTextureFetch("depth3", "temp", "1") +
1210012739 "") +
1210112740 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1210212741 //"MOV params, material;" +
....@@ -12218,7 +12857,7 @@
1221812857 "POW texSamp.a, texSamp.a, params6.w;" + // fog punch through shortcut
1221912858 // mar 2013 ??? "KIL alpha.a;" +
1222012859 "MOV alpha, texSamp.aaaa;" + // y;" +
12221
- "KIL alpha.a;" +
12860
+ "KIL alpha.a;" + // not sure with parallax mapping
1222212861 /*
1222312862 "MUL temp.xy, temp, two;" +
1222412863 "TXB bump, temp, texture[0], 2D;" +
....@@ -12304,11 +12943,6 @@
1230412943 "SUB bump0, bump0, half;" +
1230512944 "ADD bump, bump, bump0;" +
1230612945
12307
- "MOV temp.x, texSamp.a;" +
12308
- "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
12309
- //"LRP texSamp0, params5.x, texSamp0, one;" +
12310
- "MOV texSamp.a, temp.x;" +
12311
-
1231212946 // double-sided
1231312947 /**/
1231412948 (doublesided?"DP3 temp.z, normal, eye;" +
....@@ -12325,19 +12959,62 @@
1232512959 "MOV normald, normal;" +
1232612960 "MOV normals, normal;" +
1232712961
12962
+ "MOV temp, fragment.texcoord[4];" +
12963
+
1232812964 // UV base
1232912965 //"DP3 UP.x,state.matrix.modelview.row[0],Y;" +
1233012966 //"DP3 UP.y,state.matrix.modelview.row[1],Y;" +
1233112967 //"DP3 UP.z,state.matrix.modelview.row[2],Y;" +
12332
- "DP3 UP.x,state.matrix.texture[7].row[0],Y;" +
12333
- "DP3 UP.y,state.matrix.texture[7].row[1],Y;" +
12334
- "DP3 UP.z,state.matrix.texture[7].row[2],Y;" +
12968
+ "DP3 UP.x,state.matrix.texture[7].row[0],temp;" +
12969
+ "DP3 UP.y,state.matrix.texture[7].row[1],temp;" +
12970
+ "DP3 UP.z,state.matrix.texture[7].row[2],temp;" +
12971
+ Normalize("UP") +
12972
+
1233512973 "XPD V, normal, UP;" +
1233612974 Normalize("V") +
1233712975 "XPD U, V, normal;" +
1233812976 Normalize("U") +
1233912977
1234012978 // parallax mapping
12979
+
12980
+ "DP3 temp2.x, V, eye;" +
12981
+ "DP3 temp2.y, U, eye;" +
12982
+ "DP3 temp2.z, normal, eye;" +
12983
+ "RCP temp2.z, temp2.z;" +
12984
+
12985
+ "DP3 temp2.w, texSamp, texSamp;" + // Height
12986
+ "RSQ temp2.w, temp2.w;" +
12987
+ "RCP temp2.w, temp2.w;" +
12988
+
12989
+ "SUB temp2.w, temp2.w, half;" +
12990
+// "SGE temp.x, temp2.w, eps.x;" +
12991
+// "MUL temp2.w, temp2.w, temp.x;" +
12992
+
12993
+ //"MOV texSamp, U;" +
12994
+
12995
+ "MUL temp2.z, temp2.z, temp2.w;" +
12996
+ "MUL temp2.z, temp2.z, params7.z;" + // parallax
12997
+
12998
+ "MUL temp2, temp2, temp2.z;" +
12999
+
13000
+ "MOV temp, fragment.texcoord[0];" +
13001
+
13002
+ "SUB temp, temp, temp2;" +
13003
+
13004
+ "TEX temp, temp, texture[0], 2D;" +
13005
+ "POW temp.a, temp.a, params6.w;" + // punch through
13006
+
13007
+ "ADD texSamp, temp, texSamp;" +
13008
+ "MUL texSamp.xyz, half, texSamp;" +
13009
+
13010
+ "MOV alpha, texSamp.aaaa;" +
13011
+
13012
+// parallax mapping
13013
+
13014
+ "MOV temp.x, texSamp.a;" +
13015
+ "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
13016
+ //"LRP texSamp0, params5.x, texSamp0, one;" +
13017
+ "MOV texSamp.a, temp.x;" +
1234113018
1234213019 //"MOV temp, fragment.texcoord[0];" +
1234313020 //
....@@ -12467,10 +13144,10 @@
1246713144 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1246813145 "") +
1246913146
12470
- // display shadow only (bump == 0)
13147
+ // display shadow only (fakedepth == 0)
1247113148 "SUB temp.x, half.x, shadow.x;" +
12472
- "MOV temp.y, -params6.x;" +
12473
- "SLT temp.z, temp.y, zero.x;" +
13149
+ "MOV temp.y, -params5.z;" + // params6.x;" +
13150
+ "SLT temp.z, temp.y, -c256i.x;" +
1247413151 "SUB temp.y, one.x, temp.z;" +
1247513152 "MUL temp.x, temp.x, temp.y;" +
1247613153 "KIL temp.x;" +
....@@ -12599,8 +13276,10 @@
1259913276 "MAX ndotl.x, ndotl.x, -ndotl.x;" +
1260013277
1260113278 "SUB temp.x, one.x, ndotl.x;" +
12602
- "ADD temp.x, temp.x, options2.z;" + // lightsheen
12603
- "ADD temp.y, one.y, options2.y;" + // sursurface
13279
+ // Tuning for default skin
13280
+ //"ADD temp.x, temp.x, options2.z;" + // lightsheen
13281
+ "MAD temp.x, options2.z, half.y, temp.x;" + // lightsheen
13282
+ "ADD temp.y, one.y, options2.y;" + // subsurface
1260413283 "MUL temp.x, temp.x, temp.y;" +
1260513284
1260613285 "MUL saturation, saturation, temp.xxxx;" +
....@@ -12748,7 +13427,7 @@
1274813427 "MUL final.y, fragment.texcoord[0].x, c256;" +
1274913428 "FLR final.x, final.y;" +
1275013429 "SUB final.y, final.y, final.x;" +
12751
- //"MUL final.x, final.x, c256i;" +
13430
+ "MUL final.x, final.x, c256i;" +
1275213431 "MOV final.z, zero.x;" +
1275313432 "MOV final.a, one.w;":""
1275413433 ) +
....@@ -12756,7 +13435,7 @@
1275613435 "MUL final.y, fragment.texcoord[0].y, c256;" +
1275713436 "FLR final.x, final.y;" +
1275813437 "SUB final.y, final.y, final.x;" +
12759
- //"MUL final.x, final.x, c256i;" +
13438
+ "MUL final.x, final.x, c256i;" +
1276013439 "MOV final.z, zero.x;" +
1276113440 "MOV final.a, one.w;":""
1276213441 ) +
....@@ -12799,8 +13478,19 @@
1279913478 //once = true;
1280013479 }
1280113480
12802
- System.out.print("Program #" + mode + "; length = " + program.length());
12803
- System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13481
+ String program = programmax;
13482
+
13483
+ if (Globals.MINSHADER)
13484
+ {
13485
+ program = programmin;
13486
+ }
13487
+
13488
+ if (Globals.DEBUG)
13489
+ {
13490
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13491
+ System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13492
+ }
13493
+
1280413494 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1280513495
1280613496 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -12847,7 +13537,8 @@
1284713537 "\n" +
1284813538 "END\n";
1284913539
12850
- System.out.println("Program shadow #" + 0 + "; length = " + program.length());
13540
+ if (Globals.DEBUG)
13541
+ System.out.println("Program shadow #" + 0 + "; length = " + program.length());
1285113542 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1285213543
1285313544 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -12892,25 +13583,26 @@
1289213583 return out;
1289313584 }
1289413585
12895
- String TextureFetch(String dest, String src, String unit)
13586
+ // Also does frustum culling
13587
+ String ShadowTextureFetch(String dest, String src, String unit)
1289613588 {
1289713589 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1289813590 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1289913591 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13592
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13593
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1290013594 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12901
- "SLT " + src + ".z, " + src + ".x, one.x;" +
12902
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12903
- "SLT " + src + ".z, " + src + ".y, one.x;" +
12904
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13595
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13596
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1290513597 //"SWZ buffer, temp, w,w,w,w;";
12906
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13598
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1290713599 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1290813600 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1290913601 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
12910
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13602
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1291113603
12912
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
12913
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13604
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13605
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1291413606 }
1291513607
1291613608 String Shadow(String depth, String shadow)
....@@ -12932,12 +13624,16 @@
1293213624
1293313625 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1293413626 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13627
+
13628
+ // Compare fragment depth in light space with shadowmap.
1293513629 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1293613630 "SGE temp.y, temp.x, zero.x;" +
12937
- "SUB " + shadow + ".y, one.x, temp.y;" +
13631
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13632
+
13633
+ // Reverse comparison
1293813634 "SUB temp.x, one.x, temp.x;" +
1293913635 "MUL " + shadow + ".x, temp.x, temp.y;" +
12940
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13636
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1294113637 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1294213638
1294313639 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -12951,6 +13647,10 @@
1295113647 // No shadow for backface
1295213648 "DP3 temp.x, normal, lightd;" +
1295313649 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13650
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13651
+
13652
+ // No shadow when out of frustum
13653
+ "SGE temp.x, " + depth + ".z, one.z;" +
1295413654 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1295513655 "";
1295613656 }
....@@ -13096,8 +13796,9 @@
1309613796 /*static*/ float[] modelParams4 = new float[]{0, 0, 0, 0}; // anisoV, cameralight, selfshadow, shadow
1309713797 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1309813798 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
13099
- /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13100
- Object3D.cVector2[] vector2buffer;
13799
+ /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power, parallax
13800
+
13801
+ //Object3D.cVector2[] vector2buffer;
1310113802
1310213803 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1310313804 // OUT : diff, spec
....@@ -13113,9 +13814,10 @@
1311313814 "DP3 " + dest + ".z," + "normals," + "eye;" +
1311413815 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1311513816 //"MOV " + dest + ".w," + "normal.z;" +
13116
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
13117
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13118
- //"MOV " + dest + ".z," + "params2.w;" +
13817
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13818
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13819
+
13820
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1311913821 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1312013822 "RCP " + dest + ".w," + dest + ".w;" +
1312113823 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13261,7 +13963,7 @@
1326113963 "PARAM p[4] = { state.matrix.projection }; # modelview projection matrix\n" +
1326213964 "PARAM zero = { 0.0, 0.0, 0.0, 1.0 };" +
1326313965 "PARAM half = { 0.5, 0.5, 0.5, 1.0 };" +
13264
- "PARAM one = { 1.0, 1.0, 1.0, 0.0 };" +
13966
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
1326513967 "PARAM two = { 2.0, 2.0, 2.0, 1.0 };" +
1326613968 "PARAM third = { 0.33333333333, 0.33333333333, 0.33333333333, 1.0 };" +
1326713969 //"PARAM v256 = { 256.0, 256.0, 256.0, 1.0 };" +
....@@ -13322,7 +14024,7 @@
1332214024 "DP4 temp.x,state.matrix.texture[0].inverse.row[0],vertex.texcoord;" +
1332314025 "DP4 temp.y,state.matrix.texture[0].inverse.row[1],vertex.texcoord;" +
1332414026 "DP4 temp.z,state.matrix.texture[0].inverse.row[2],vertex.texcoord;" +
13325
- //"MOV result.texcoord, vertex.texcoord;" +
14027
+ //"MOV result.texcoord, vertex.fogcoord;" +
1332614028 "MOV result.texcoord, temp;" +
1332714029 // border fade
1332814030 "MOV result.texcoord[3], vertex.texcoord;" +
....@@ -13369,7 +14071,9 @@
1336914071
1337014072 //"ADD temp.z, temp.z, one;" +
1337114073
13372
- "MOV result.color, temp;"
14074
+ "MOV result.texcoord[4], vertex.attrib[4];" + // U dir
14075
+
14076
+ "MOV result.color, temp;" // Normal
1337314077 : "MOV result.color, vertex.color;") +
1337414078 ((mode & VP_PROJECTION) != 0 ? "MOV result.color, zero;"
1337514079 : "") +
....@@ -13509,7 +14213,7 @@
1350914213 public void mousePressed(MouseEvent e)
1351014214 {
1351114215 //System.out.println("mousePressed: " + e);
13512
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14216
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1351314217 }
1351414218
1351514219 static long prevtime = 0;
....@@ -13585,8 +14289,8 @@
1358514289 // mode |= META;
1358614290 //}
1358714291
13588
- SetMouseMode(WHEEL | e.getModifiersEx());
13589
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14292
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14293
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1359014294 anchorX = ax;
1359114295 anchorY = ay;
1359214296 prevX = px;
....@@ -13620,6 +14324,7 @@
1362014324 else
1362114325 if (evt.getSource() == AAtimer)
1362214326 {
14327
+ Globals.TIMERRUNNING = false;
1362314328 if (mouseDown)
1362414329 {
1362514330 //new Exception().printStackTrace();
....@@ -13645,6 +14350,10 @@
1364514350 // LIVE = waslive;
1364614351 // wasliveok = true;
1364714352 // waslive = false;
14353
+
14354
+ // May 2019 Forget it:
14355
+ if (true)
14356
+ return;
1364814357
1364914358 // source == timer
1365014359 if (mouseDown)
....@@ -13675,7 +14384,7 @@
1367514384
1367614385 // fev 2014???
1367714386 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13678
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14387
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1367914388 pingthread.StepToTarget(true); // true);
1368014389 }
1368114390 // if (!LIVE)
....@@ -13684,12 +14393,13 @@
1368414393
1368514394 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1368614395
13687
- void clickStart(int x, int y, int modifiers)
14396
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1368814397 {
1368914398 if (!wasliveok)
1369014399 return;
1369114400
1369214401 AAtimer.restart(); //
14402
+ Globals.TIMERRUNNING = true;
1369314403
1369414404 // waslive = LIVE;
1369514405 // LIVE = false;
....@@ -13701,7 +14411,7 @@
1370114411 // touched = true; // main DL
1370214412 if (isRenderer)
1370314413 {
13704
- SetMouseMode(modifiers);
14414
+ SetMouseMode(modifiers, modifiersex);
1370514415 }
1370614416
1370714417 selectX = anchorX = x;
....@@ -13714,7 +14424,7 @@
1371414424 clicked = true;
1371514425 hold = false;
1371614426
13717
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14427
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1371814428 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1371914429 {
1372014430 // System.out.println("RESTART II " + modifiers);
....@@ -13739,14 +14449,15 @@
1373914449 drag = false;
1374014450 //System.out.println("Mouse DOWN");
1374114451 editObj = false;
13742
- ClickInfo info = new ClickInfo();
13743
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
13744
- info.pane = this;
13745
- info.camera = renderCamera;
13746
- info.x = x;
13747
- info.y = y;
13748
- info.modifiers = modifiers;
13749
- editObj = object.doEditClick(info, 0);
14452
+ //ClickInfo info = new ClickInfo();
14453
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14454
+ object.clickInfo.pane = this;
14455
+ object.clickInfo.camera = renderCamera;
14456
+ object.clickInfo.x = x;
14457
+ object.clickInfo.y = y;
14458
+ object.clickInfo.modifiers = modifiersex;
14459
+ editObj = object.doEditClick(//info,
14460
+ 0);
1375014461 if (!editObj)
1375114462 {
1375214463 hasMarquee = true;
....@@ -13762,9 +14473,12 @@
1376214473
1376314474 public void mouseDragged(MouseEvent e)
1376414475 {
14476
+ Globals.MOUSEDRAGGED = true;
14477
+
1376514478 //System.out.println("mouseDragged: " + e);
1376614479 if (isRenderer)
1376714480 movingcamera = true;
14481
+
1376814482 //if (drawing)
1376914483 //return;
1377014484 if ((e.getModifiersEx() & CTRL) != 0
....@@ -13774,7 +14488,7 @@
1377414488 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1377514489 }
1377614490 else
13777
- drag(e.getX(), e.getY(), e.getModifiersEx());
14491
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1377814492
1377914493 //try { Thread.sleep(1); } catch (Exception ex) {}
1378014494 }
....@@ -14011,7 +14725,7 @@
1401114725 {
1401214726 Globals.lighttouched = true;
1401314727 }
14014
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14728
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1401514729 }
1401614730 //else
1401714731 }
....@@ -14025,12 +14739,18 @@
1402514739 void GoDown(int mod)
1402614740 {
1402714741 MODIFIERS |= COMMAND;
14028
- /*
14742
+ boolean isVR = (mouseMode&VR)!=0;
14743
+ /**/
1402914744 if((mod&SHIFT) == SHIFT)
14030
- manipCamera.RotatePosition(0, -speed);
14745
+ {
14746
+ if (isVR)
14747
+ manipCamera.RotateInterest(0, -speed);
14748
+ else
14749
+ manipCamera.RotatePosition(0, -speed);
14750
+ }
1403114751 else
14032
- manipCamera.BackForth(0, -speed*delta, getWidth());
14033
- */
14752
+ manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth());
14753
+ /**/
1403414754 if ((mod & SHIFT) == SHIFT)
1403514755 {
1403614756 mouseMode = mouseMode; // VR??
....@@ -14039,6 +14759,8 @@
1403914759 mouseMode |= BACKFORTH;
1404014760 }
1404114761
14762
+ targetLookAt.set(manipCamera.lookAt);
14763
+
1404214764 //prevX = X = anchorX;
1404314765 prevY = Y = anchorY - (int) (renderCamera.Distance());
1404414766 }
....@@ -14046,12 +14768,19 @@
1404614768 void GoUp(int mod)
1404714769 {
1404814770 MODIFIERS |= COMMAND;
14049
- /*
14771
+ /**/
14772
+ boolean isVR = (mouseMode&VR)!=0;
14773
+
1405014774 if((mod&SHIFT) == SHIFT)
14051
- manipCamera.RotatePosition(0, speed);
14775
+ {
14776
+ if (isVR)
14777
+ manipCamera.RotateInterest(0, speed);
14778
+ else
14779
+ manipCamera.RotatePosition(0, speed);
14780
+ }
1405214781 else
14053
- manipCamera.BackForth(0, speed*delta, getWidth());
14054
- */
14782
+ manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth());
14783
+ /**/
1405514784 if ((mod & SHIFT) == SHIFT)
1405614785 {
1405714786 mouseMode = mouseMode;
....@@ -14060,6 +14789,8 @@
1406014789 mouseMode |= BACKFORTH;
1406114790 }
1406214791
14792
+ targetLookAt.set(manipCamera.lookAt);
14793
+
1406314794 //prevX = X = anchorX;
1406414795 prevY = Y = anchorY + (int) (renderCamera.Distance());
1406514796 }
....@@ -14067,12 +14798,17 @@
1406714798 void GoLeft(int mod)
1406814799 {
1406914800 MODIFIERS |= COMMAND;
14070
- /*
14801
+ /**/
1407114802 if((mod&SHIFT) == SHIFT)
14072
- manipCamera.RotatePosition(speed, 0);
14803
+ manipCamera.Translate(speed*delta, 0, getWidth());
1407314804 else
14074
- manipCamera.Translate(speed*delta, 0, getWidth());
14075
- */
14805
+ {
14806
+ if ((mouseMode&VR)!=0)
14807
+ manipCamera.RotateInterest(-speed, 0);
14808
+ else
14809
+ manipCamera.RotatePosition(speed, 0);
14810
+ }
14811
+ /**/
1407614812 if ((mod & SHIFT) == SHIFT)
1407714813 {
1407814814 mouseMode = mouseMode;
....@@ -14081,6 +14817,8 @@
1408114817 mouseMode |= ROTATE;
1408214818 } // TRANSLATE;
1408314819
14820
+ targetLookAt.set(manipCamera.lookAt);
14821
+
1408414822 prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance());
1408514823 prevY = Y = anchorY;
1408614824 }
....@@ -14088,12 +14826,18 @@
1408814826 void GoRight(int mod)
1408914827 {
1409014828 MODIFIERS |= COMMAND;
14091
- /*
14829
+ /**/
1409214830 if((mod&SHIFT) == SHIFT)
14093
- manipCamera.RotatePosition(-speed, 0);
14831
+ manipCamera.Translate(-speed*delta, 0, getWidth());
1409414832 else
14095
- manipCamera.Translate(-speed*delta, 0, getWidth());
14096
- */
14833
+ {
14834
+ if ((mouseMode&VR)!=0)
14835
+ manipCamera.RotateInterest(speed, 0);
14836
+ else
14837
+ manipCamera.RotatePosition(-speed, 0);
14838
+ }
14839
+
14840
+ /**/
1409714841 if ((mod & SHIFT) == SHIFT)
1409814842 {
1409914843 mouseMode = mouseMode;
....@@ -14102,6 +14846,8 @@
1410214846 mouseMode |= ROTATE;
1410314847 } // TRANSLATE;
1410414848
14849
+ targetLookAt.set(manipCamera.lookAt);
14850
+
1410514851 prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance());
1410614852 prevY = Y = anchorY;
1410714853 }
....@@ -14111,7 +14857,7 @@
1411114857 int X, Y;
1411214858 boolean SX, SY;
1411314859
14114
- void drag(int x, int y, int modifiers)
14860
+ void drag(int x, int y, int modifiers, int modifiersex)
1411514861 {
1411614862 if (IsFrozen())
1411714863 {
....@@ -14120,17 +14866,17 @@
1412014866
1412114867 drag = true; // NEW
1412214868
14123
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14869
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1412414870
1412514871 X = x;
1412614872 Y = y;
1412714873 // floating state for animation
14128
- MODIFIERS = modifiers;
14129
- modifiers &= ~1024;
14874
+ MODIFIERS = modifiersex;
14875
+ modifiersex &= ~1024;
1413014876 if (false) // modifiers != 0)
1413114877 {
1413214878 //new Exception().printStackTrace();
14133
- System.out.println("mouseDragged: " + modifiers);
14879
+ System.out.println("mouseDragged: " + modifiersex);
1413414880 System.out.println("SHIFT = " + SHIFT);
1413514881 System.out.println("CONTROL = " + COMMAND);
1413614882 System.out.println("META = " + META);
....@@ -14143,14 +14889,16 @@
1414314889 if (editObj)
1414414890 {
1414514891 drag = true;
14146
- ClickInfo info = new ClickInfo();
14147
- info.bounds.setBounds(0, 0,
14892
+ //ClickInfo info = new ClickInfo();
14893
+ object.clickInfo.bounds.setBounds(0, 0,
1414814894 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14149
- info.pane = this;
14150
- info.camera = renderCamera;
14151
- info.x = x;
14152
- info.y = y;
14153
- object.editWindow.copy.doEditDrag(info);
14895
+ object.clickInfo.pane = this;
14896
+ object.clickInfo.camera = renderCamera;
14897
+ object.clickInfo.x = x;
14898
+ object.clickInfo.y = y;
14899
+ object //.GetWindow().copy
14900
+ .doEditDrag(//info,
14901
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1415414902 } else
1415514903 {
1415614904 if (x < startX)
....@@ -14299,22 +15047,27 @@
1429915047 }
1430015048 }
1430115049
15050
+// ClickInfo clickInfo = new ClickInfo();
15051
+
1430215052 public void mouseMoved(MouseEvent e)
1430315053 {
1430415054 //System.out.println("mouseMoved: " + e);
1430515055 if (isRenderer)
1430615056 return;
1430715057
14308
- ClickInfo ci = new ClickInfo();
14309
- ci.x = e.getX();
14310
- ci.y = e.getY();
14311
- ci.modifiers = e.getModifiersEx();
14312
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14313
- ci.pane = this;
14314
- ci.camera = renderCamera;
15058
+ // Mouse cursor feedback
15059
+ object.clickInfo.x = e.getX();
15060
+ object.clickInfo.y = e.getY();
15061
+ object.clickInfo.modifiers = e.getModifiersEx();
15062
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
15063
+ object.clickInfo.pane = this;
15064
+ object.clickInfo.camera = renderCamera;
1431515065 if (!isRenderer)
1431615066 {
14317
- if (object.editWindow.copy.doEditClick(ci, 0))
15067
+ //ObjEditor editWindow = object.editWindow;
15068
+ //Object3D copy = editWindow.copy;
15069
+ if (object.doEditClick(//clickInfo,
15070
+ 0))
1431815071 {
1431915072 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1432015073 } else
....@@ -14326,7 +15079,11 @@
1432615079
1432715080 public void mouseReleased(MouseEvent e)
1432815081 {
15082
+ Globals.MOUSEDRAGGED = false;
15083
+
1432915084 movingcamera = false;
15085
+ X = 0; // getBounds().width/2;
15086
+ Y = 0; // getBounds().height/2;
1433015087 //System.out.println("mouseReleased: " + e);
1433115088 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1433215089 }
....@@ -14349,9 +15106,9 @@
1434915106 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1435015107 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1435115108
14352
- if (control || command || IsFrozen())
15109
+// No delay if (control || command || IsFrozen())
1435315110 timeout = true;
14354
- else
15111
+// ?? May 2019 else
1435515112 // timer.setDelay((modifiers & 128) != 0?0:350);
1435615113 mouseDown = false;
1435715114 if (!control && !command) // june 2013
....@@ -14461,7 +15218,7 @@
1446115218 System.out.println("keyReleased: " + e);
1446215219 }
1446315220
14464
- void SetMouseMode(int modifiers)
15221
+ void SetMouseMode(int modifiers, int modifiersex)
1446515222 {
1446615223 //System.out.println("SetMouseMode = " + modifiers);
1446715224 //modifiers &= ~1024;
....@@ -14473,25 +15230,25 @@
1447315230 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1447415231 // return;
1447515232 //System.out.println("SetMode = " + modifiers);
14476
- if ((modifiers & WHEEL) == WHEEL)
15233
+ if ((modifiersex & WHEEL) == WHEEL)
1447715234 {
1447815235 mouseMode |= ZOOM;
1447915236 }
1448015237
1448115238 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
14482
- if (capsLocked || (modifiers & META) == META)
15239
+ if (capsLocked) // || (modifiers & META) == META)
1448315240 {
1448415241 mouseMode |= VR; // BACKFORTH;
1448515242 }
14486
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
15243
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1448715244 {
1448815245 mouseMode |= SELECT;
1448915246 }
14490
- if ((modifiers & COMMAND) == COMMAND)
15247
+ if ((modifiersex & COMMAND) == COMMAND)
1449115248 {
1449215249 mouseMode |= SELECT;
1449315250 }
14494
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15251
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
1449515252 {
1449615253 mouseMode &= ~VR;
1449715254 mouseMode |= TRANSLATE;
....@@ -14520,7 +15277,7 @@
1452015277
1452115278 if (isRenderer) //
1452215279 {
14523
- SetMouseMode(modifiers);
15280
+ SetMouseMode(0, modifiers);
1452415281 }
1452515282
1452615283 Globals.theRenderer.keyPressed(key);
....@@ -14582,7 +15339,8 @@
1458215339 // break;
1458315340 case 'T':
1458415341 CACHETEXTURE ^= true;
14585
- textures.clear();
15342
+ texturepigment.clear();
15343
+ texturebump.clear();
1458615344 // repaint();
1458715345 break;
1458815346 case 'Y':
....@@ -14592,8 +15350,8 @@
1459215350 case 'K':
1459315351 KOMPACTTEXTURE ^= true;
1459415352 //textures.clear();
14595
- break;
14596
- case 'P': // Texture Projection macros
15353
+ // break;
15354
+ //case 'P': // Texture Projection macros
1459715355 // SAVETEXTURE ^= true;
1459815356 macromode = true;
1459915357 Udebug = Vdebug = NORMALdebug = false; programInitialized = false;
....@@ -14667,7 +15425,9 @@
1466715425 case 'E' : COMPACT ^= true;
1466815426 repaint();
1466915427 break;
14670
- case 'W' : DEBUGHSB ^= true;
15428
+ case 'W' : // Wide Window (fullscreen)
15429
+ //DEBUGHSB ^= true;
15430
+ ObjEditor.theFrame.ToggleFullScreen();
1467115431 repaint();
1467215432 break;
1467315433 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14692,8 +15452,8 @@
1469215452 RevertCamera();
1469315453 repaint();
1469415454 break;
14695
- case 'L':
1469615455 case 'l':
15456
+ //case 'L':
1469715457 if (lightMode)
1469815458 {
1469915459 lightMode = false;
....@@ -14712,7 +15472,7 @@
1471215472 targetLookAt.set(manipCamera.lookAt);
1471315473 repaint();
1471415474 break;
14715
- case 'p':
15475
+ case 'P': // p':
1471615476 // c'est quoi ca au juste? spherical ^= true;
1471715477 Skinshader ^= true; programInitialized = false;
1471815478 repaint();
....@@ -14750,27 +15510,31 @@
1475015510 repaint();
1475115511 break;
1475215512 case 'O':
14753
- Globals.drawMode = OCCLUSION; // WARNING
15513
+ // Too dangerous. Use menu. Globals.drawMode = OCCLUSION; // WARNING
1475415514 repaint();
1475515515 break;
1475615516 case 'o':
1475715517 OCCLUSION_CULLING ^= true;
1475815518 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1475915519 break;
14760
- case '0': envyoff ^= true; repaint(); break;
15520
+ //case '0': envyoff ^= true; repaint(); break;
1476115521 case '1':
1476215522 case '2':
1476315523 case '3':
1476415524 case '4':
1476515525 case '5':
14766
- newenvy = Character.getNumericValue(key);
14767
- repaint();
14768
- break;
1476915526 case '6':
1477015527 case '7':
1477115528 case '8':
1477215529 case '9':
14773
- BGcolor = (key - '6')/3.f;
15530
+ if (true) // envyoff)
15531
+ {
15532
+ BGcolor = (key - '1')/8.f;
15533
+ }
15534
+ else
15535
+ {
15536
+ //newenvy = Character.getNumericValue(key);
15537
+ }
1477415538 repaint();
1477515539 break;
1477615540 case '!':
....@@ -14836,9 +15600,9 @@
1483615600 case '_':
1483715601 kompactbit = 5;
1483815602 break;
14839
- case '+':
14840
- kompactbit = 6;
14841
- break;
15603
+// case '+':
15604
+// kompactbit = 6;
15605
+// break;
1484215606 case ' ':
1484315607 lightMode ^= true;
1484415608 Globals.lighttouched = true;
....@@ -14850,13 +15614,14 @@
1485015614 case ESC:
1485115615 RENDERPROGRAM += 1;
1485215616 RENDERPROGRAM %= 3;
15617
+
1485315618 repaint();
1485415619 break;
1485515620 case 'Z':
1485615621 //RESIZETEXTURE ^= true;
1485715622 //break;
1485815623 case 'z':
14859
- RENDERSHADOW ^= true;
15624
+ Globals.RENDERSHADOW ^= true;
1486015625 Globals.lighttouched = true;
1486115626 repaint();
1486215627 break;
....@@ -14889,8 +15654,9 @@
1488915654 case DELETE:
1489015655 ClearSelection();
1489115656 break;
14892
- /*
1489315657 case '+':
15658
+
15659
+ /*
1489415660 //fontsize += 1;
1489515661 bbzoom *= 2;
1489615662 repaint();
....@@ -14907,17 +15673,17 @@
1490715673 case '=':
1490815674 IncDepth();
1490915675 //fontsize += 1;
14910
- object.editWindow.refreshContents(true);
15676
+ object.GetWindow().refreshContents(true);
1491115677 maskbit = 6;
1491215678 break;
1491315679 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1491415680 DecDepth();
1491515681 maskbit = 5;
1491615682 //if(fontsize > 1) fontsize -= 1;
14917
- if (object.editWindow == null)
14918
- new Exception().printStackTrace();
14919
- else
14920
- object.editWindow.refreshContents(true);
15683
+// if (object.editWindow == null)
15684
+// new Exception().printStackTrace();
15685
+// else
15686
+ object.GetWindow().refreshContents(true);
1492115687 break;
1492215688 case '{':
1492315689 manipCamera.shaper_fovy /= 1.1;
....@@ -14980,7 +15746,7 @@
1498015746 //mode = ROTATE;
1498115747 if ((MODIFIERS & COMMAND) == 0) // VR??
1498215748 {
14983
- SetMouseMode(modifiers);
15749
+ SetMouseMode(0, modifiers);
1498415750 }
1498515751 }
1498615752
....@@ -15116,7 +15882,7 @@
1511615882 {
1511715883 //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
1511815884 //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15119
- if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (mouseMode & SELECT) == 0)
15885
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1512015886 {
1512115887 mouseMoved(e);
1512215888 } else
....@@ -15141,7 +15907,7 @@
1514115907 }
1514215908 */
1514315909
15144
- object.editWindow.EditSelection();
15910
+ object.GetWindow().EditSelection(false);
1514515911 }
1514615912
1514715913 void SelectParent()
....@@ -15158,10 +15924,10 @@
1515815924 {
1515915925 //selectees.remove(i);
1516015926 System.out.println("select parent of " + elem);
15161
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15927
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1516215928 } else
1516315929 {
15164
- group.editWindow.Select(elem.GetTreePath(), first, true);
15930
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1516515931 }
1516615932
1516715933 first = false;
....@@ -15203,12 +15969,12 @@
1520315969 for (int j = 0; j < group.children.size(); j++)
1520415970 {
1520515971 elem = (Object3D) group.children.elementAt(j);
15206
- object.editWindow.Select(elem.GetTreePath(), first, true);
15972
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1520715973 first = false;
1520815974 }
1520915975 } else
1521015976 {
15211
- object.editWindow.Select(elem.GetTreePath(), first, true);
15977
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1521215978 }
1521315979
1521415980 first = false;
....@@ -15219,21 +15985,21 @@
1521915985 {
1522015986 //Composite group = (Composite) object;
1522115987 Object3D group = object;
15222
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15988
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1522315989 }
1522415990
1522515991 void ResetTransform(int mask)
1522615992 {
1522715993 //Composite group = (Composite) object;
1522815994 Object3D group = object;
15229
- group.editWindow.ResetTransform(mask);
15995
+ group.GetWindow().ResetTransform(mask);
1523015996 }
1523115997
1523215998 void FlipTransform()
1523315999 {
1523416000 //Composite group = (Composite) object;
1523516001 Object3D group = object;
15236
- group.editWindow.FlipTransform();
16002
+ group.GetWindow().FlipTransform();
1523716003 // group.editWindow.ReduceMesh(true);
1523816004 }
1523916005
....@@ -15241,7 +16007,7 @@
1524116007 {
1524216008 //Composite group = (Composite) object;
1524316009 Object3D group = object;
15244
- group.editWindow.PrintMemory();
16010
+ group.GetWindow().PrintMemory();
1524516011 // group.editWindow.ReduceMesh(true);
1524616012 }
1524716013
....@@ -15249,7 +16015,7 @@
1524916015 {
1525016016 //Composite group = (Composite) object;
1525116017 Object3D group = object;
15252
- group.editWindow.ResetCentroid();
16018
+ group.GetWindow().ResetCentroid();
1525316019 }
1525416020
1525516021 void IncDepth()
....@@ -15331,11 +16097,11 @@
1533116097
1533216098 int width = getBounds().width;
1533316099 int height = getBounds().height;
15334
- ClickInfo info = new ClickInfo();
15335
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1533616100 //Image img = CreateImage(width, height);
1533716101 //System.out.println("width = " + width + "; height = " + height + "\n");
16102
+
1533816103 Graphics gr = g; // img.getGraphics();
16104
+
1533916105 if (!hasMarquee)
1534016106 {
1534116107 if (Xmin < Xmax) // !locked)
....@@ -15407,44 +16173,92 @@
1540716173 }
1540816174 if (object != null && !hasMarquee)
1540916175 {
16176
+ if (object.clickInfo == null)
16177
+ object.clickInfo = new ClickInfo();
16178
+ ClickInfo info = object.clickInfo;
16179
+ //ClickInfo info = new ClickInfo();
16180
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16181
+
1541016182 if (isRenderer)
1541116183 {
15412
- info.flags++;
16184
+ object.clickInfo.flags++;
1541316185 double frameAspect = (double) width / (double) height;
1541416186 if (frameAspect > renderCamera.aspect)
1541516187 {
1541616188 int desired = (int) ((double) height * renderCamera.aspect);
15417
- info.bounds.width -= width - desired;
15418
- info.bounds.x += (width - desired) / 2;
16189
+ object.clickInfo.bounds.width -= width - desired;
16190
+ object.clickInfo.bounds.x += (width - desired) / 2;
1541916191 } else
1542016192 {
1542116193 int desired = (int) ((double) width / renderCamera.aspect);
15422
- info.bounds.height -= height - desired;
15423
- info.bounds.y += (height - desired) / 2;
16194
+ object.clickInfo.bounds.height -= height - desired;
16195
+ object.clickInfo.bounds.y += (height - desired) / 2;
1542416196 }
1542516197 }
15426
- info.g = gr;
15427
- info.camera = renderCamera;
16198
+
16199
+ object.clickInfo.g = gr;
16200
+ object.clickInfo.camera = renderCamera;
1542816201 /*
1542916202 // Memory intensive (brep.verticescopy)
1543016203 if (!(object instanceof Composite))
1543116204 object.draw(info, 0, false); // SLOW :
1543216205 */
15433
- if (!isRenderer)
16206
+ if (!isRenderer) // && drag)
1543416207 {
15435
- object.drawEditHandles(info, 0);
16208
+ Grafreed.Assert(object != null);
16209
+ Grafreed.Assert(object.selection != null);
16210
+ if (object.selection.Size() > 0)
16211
+ {
16212
+ int hitSomething = object.selection.get(0).hitSomething;
16213
+
16214
+ object.clickInfo.DX = 0;
16215
+ object.clickInfo.DY = 0;
16216
+ object.clickInfo.W = 1;
16217
+ if (hitSomething == Object3D.hitCenter)
16218
+ {
16219
+ info.DX = X;
16220
+ if (X != 0)
16221
+ info.DX -= info.bounds.width/2;
16222
+
16223
+ info.DY = Y;
16224
+ if (Y != 0)
16225
+ info.DY -= info.bounds.height/2;
16226
+ }
16227
+
16228
+ object.drawEditHandles(//info,
16229
+ 0);
16230
+
16231
+ if (drag && (X != 0 || Y != 0))
16232
+ {
16233
+ switch (hitSomething)
16234
+ {
16235
+ case Object3D.hitCenter: gr.setColor(Color.white);
16236
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16237
+ break;
16238
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16239
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16240
+ break;
16241
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16242
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16243
+ break;
16244
+ }
16245
+
16246
+ }
16247
+ }
1543616248 }
1543716249 }
16250
+
1543816251 if (isRenderer)
1543916252 {
1544016253 //gr.setColor(Color.black);
1544116254 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1544216255 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1544316256 }
16257
+
1544416258 if (hasMarquee)
1544516259 {
1544616260 gr.setXORMode(Color.white);
15447
- gr.setColor(Color.red);
16261
+ gr.setColor(Color.white);
1544816262 if (!firstime)
1544916263 {
1545016264 gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH);
....@@ -15553,6 +16367,7 @@
1555316367 public boolean mouseDown(Event evt, int x, int y)
1555416368 {
1555516369 System.out.println("mouseDown: " + evt);
16370
+ System.exit(0);
1555616371 /*
1555716372 locked = true;
1555816373 drag = false;
....@@ -15596,7 +16411,7 @@
1559616411 {
1559716412 keyPressed(0, modifiers);
1559816413 }
15599
- clickStart(x, y, modifiers);
16414
+ // clickStart(x, y, modifiers);
1560016415 return true;
1560116416 }
1560216417
....@@ -15714,7 +16529,7 @@
1571416529 {
1571516530 keyReleased(0, 0);
1571616531 }
15717
- drag(x, y, modifiers);
16532
+ drag(x, y, 0, modifiers);
1571816533 return true;
1571916534 }
1572016535
....@@ -15846,7 +16661,7 @@
1584616661 Object3D object;
1584716662 static Object3D trackedobject;
1584816663 Camera renderCamera; // Light or Eye (or Occlusion)
15849
- /*static*/ Camera manipCamera; // Light or Eye
16664
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1585016665 /*static*/ Camera eyeCamera;
1585116666 /*static*/ Camera lightCamera;
1585216667 int cameracount;
....@@ -15910,6 +16725,8 @@
1591016725 private /*static*/ boolean firstime;
1591116726 private /*static*/ cVector newView = new cVector();
1591216727 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16728
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16729
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1591316730 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1591416731 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1591516732 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -15922,29 +16739,67 @@
1592216739 {
1592316740 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1592416741
16742
+ int usedsuf = 0;
16743
+
1592516744 for (int i = 0; i < suffixes.length; i++)
1592616745 {
15927
- String resourceName = basename + suffixes[i] + "." + suffix;
15928
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
15929
- mipmapped,
15930
- FileUtil.getFileSuffix(resourceName));
15931
- if (data == null)
16746
+ String[] suffixe = suffixes;
16747
+ String[] fallback = suffixes2;
16748
+ String[] fallfallback = suffixes3;
16749
+
16750
+ for (int c=usedsuf; --c>=0;)
1593216751 {
15933
- throw new IOException("Unable to load texture " + resourceName);
16752
+// String[] temp = suffixe;
16753
+// suffixe = fallback;
16754
+// fallback = fallfallback;
16755
+// fallfallback = temp;
1593416756 }
16757
+
16758
+ String resourceName = basename + suffixe[i] + "." + suffix;
16759
+ TextureData data;
16760
+
16761
+ try
16762
+ {
16763
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16764
+ mipmapped,
16765
+ FileUtil.getFileSuffix(resourceName));
16766
+ }
16767
+ catch (Exception e)
16768
+ {
16769
+ try
16770
+ {
16771
+ resourceName = basename + fallback[i] + "." + suffix;
16772
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16773
+ mipmapped,
16774
+ FileUtil.getFileSuffix(resourceName));
16775
+ }
16776
+ catch (Exception e2)
16777
+ {
16778
+ resourceName = basename + fallfallback[i] + "." + suffix;
16779
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16780
+ mipmapped,
16781
+ FileUtil.getFileSuffix(resourceName));
16782
+ }
16783
+ }
16784
+
1593516785 //System.out.println("Target = " + targets[i]);
1593616786 cubemap.updateImage(data, targets[i]);
1593716787 }
1593816788
1593916789 return cubemap;
1594016790 }
16791
+
1594116792 int bigsphere = -1;
1594216793
1594316794 float BGcolor = 0.5f;
1594416795
15945
- private void DrawSkyBox(GL gl)
16796
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16797
+
16798
+ private void DrawSkyBox(GL gl, float ratio)
1594616799 {
15947
- if (envyoff || cubemap == null)
16800
+ if (//envyoff ||
16801
+ WIREFRAME ||
16802
+ cubemap == null)
1594816803 {
1594916804 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1595016805 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -15959,7 +16814,17 @@
1595916814 // Compensates for ExaminerViewer's modification of modelview matrix
1596016815 gl.glMatrixMode(GL.GL_MODELVIEW);
1596116816 gl.glLoadIdentity();
16817
+ gl.glScalef(1,ratio,1);
1596216818
16819
+// colorV[0] = 2;
16820
+// colorV[1] = 2;
16821
+// colorV[2] = 2;
16822
+// colorV[3] = 1;
16823
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16824
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16825
+//
16826
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16827
+
1596316828 //gl.glActiveTexture(GL.GL_TEXTURE1);
1596416829 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1596516830
....@@ -15991,6 +16856,7 @@
1599116856 {
1599216857 gl.glScalef(1.0f, -1.0f, 1.0f);
1599316858 }
16859
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1599416860 gl.glMultMatrixd(viewrot_1, 0);
1599516861 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1599616862 //viewer.updateInverseRotation(gl);
....@@ -16031,7 +16897,8 @@
1603116897 gl.glDisable(GL.GL_TEXTURE_GEN_R);
1603216898
1603316899 cubemap.disable();
16034
- ////cubemap.unbind();
16900
+ //cubemap.dispose();
16901
+
1603516902 if (CULLFACE)
1603616903 {
1603716904 gl.glEnable(gl.GL_CULL_FACE);
....@@ -16087,7 +16954,7 @@
1608716954 gl.glScalef(1.0f, -1.0f, 1.0f);
1608816955 }
1608916956
16090
- gl.glNormal3f(0.0f, 0.0f, 1.0f);
16957
+ SetGLNormal(gl, 0.0f, 0.0f, 1.0f);
1609116958
1609216959 float step = 2; // 0.1666f; //0.25f;
1609316960 float stepv = 2; // step * 1652 / 998;
....@@ -16131,16 +16998,16 @@
1613116998 cStatic.objectstack[materialdepth++] = checker;
1613216999 //System.out.println("material " + material);
1613317000 //Applet3D.tracein(this, selected);
16134
- vector2buffer = checker.projectedVertices;
17001
+ //vector2buffer = checker.projectedVertices;
1613517002
1613617003 //checker.GetMaterial().Draw(this, false); // true);
16137
- DrawMaterial(checker.GetMaterial(), false); // true);
17004
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1613817005
1613917006 materialdepth -= 1;
1614017007 if (materialdepth > 0)
1614117008 {
16142
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16143
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
17009
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
17010
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1614417011 }
1614517012 //checker.GetMaterial().opacity = 1f;
1614617013 ////checker.GetMaterial().ambient = 1f;
....@@ -16226,6 +17093,14 @@
1622617093 }
1622717094 }
1622817095
17096
+ private Object3D GetFolder()
17097
+ {
17098
+ Object3D folder = object.GetWindow().copy;
17099
+ if (object.GetWindow().copy.selection.Size() > 0)
17100
+ folder = object.GetWindow().copy.selection.elementAt(0);
17101
+ return folder;
17102
+ }
17103
+
1622917104 class SelectBuffer implements GLEventListener
1623017105 {
1623117106
....@@ -16241,7 +17116,7 @@
1624117116 //new Exception().printStackTrace();
1624217117 System.out.println("select buffer init");
1624317118 // Use debug pipeline
16244
- drawable.setGL(new DebugGL(drawable.getGL()));
17119
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1624517120
1624617121 GL gl = drawable.getGL();
1624717122
....@@ -16305,6 +17180,17 @@
1630517180
1630617181 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1630717182
17183
+ if (PAINTMODE)
17184
+ {
17185
+ if (object.GetWindow().copy.selection.Size() > 0)
17186
+ {
17187
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17188
+
17189
+ // Make what you paint not selectable.
17190
+ paintobj.ResetSelectable();
17191
+ }
17192
+ }
17193
+
1630817194 //int tmp = selection_view;
1630917195 //selection_view = -1;
1631017196 int temp = DrawMode();
....@@ -16316,6 +17202,17 @@
1631617202 // temp = DEFAULT; // patch for selection debug
1631717203 Globals.drawMode = temp; // WARNING
1631817204
17205
+ if (PAINTMODE)
17206
+ {
17207
+ if (object.GetWindow().copy.selection.Size() > 0)
17208
+ {
17209
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17210
+
17211
+ // Revert.
17212
+ paintobj.RestoreSelectable();
17213
+ }
17214
+ }
17215
+
1631917216 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1632017217
1632117218 // trying different ways of getting the depth info over
....@@ -16363,6 +17260,8 @@
1636317260 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1636417261 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1636517262 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
17263
+
17264
+ CreateSelectedPoint();
1636617265
1636717266 // Will fit the mesh !!!
1636817267 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16412,34 +17311,36 @@
1641217311 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]));
1641317312 }
1641417313
16415
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
17314
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1641617315 }
1641717316 }
1641817317
1641917318 if (!movingcamera && !PAINTMODE)
16420
- object.editWindow.ScreenFitPoint(); // fev 2014
17319
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1642117320
16422
- if (PAINTMODE && GrafreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17321
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1642317322 {
16424
- Object3D paintobj = GrafreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17323
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1642517324
16426
- Object3D group = new Object3D("inst" + paintcount++);
17325
+ if (object.GetWindow().copy.selection.Size() > 0)
17326
+ {
17327
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1642717328
16428
- group.CreateMaterial(); // use a void leaf to select instances
16429
-
16430
- group.add(paintobj); // link
16431
-
16432
- object.editWindow.SnapObject(group);
16433
-
16434
- Object3D folder = object.editWindow.copy;
16435
-
16436
- if (object.editWindow.copy.selection.Size() > 0)
16437
- folder = object.editWindow.copy.selection.elementAt(0);
16438
-
16439
- folder.add(group);
16440
-
16441
- object.editWindow.ResetModel();
16442
- object.editWindow.refreshContents();
17329
+ Object3D inst = new Object3D("inst" + paintcount++);
17330
+
17331
+ inst.CreateMaterial(); // use a void leaf to select instances
17332
+
17333
+ inst.add(paintobj); // link
17334
+
17335
+ object.GetWindow().SnapObject(inst);
17336
+
17337
+ Object3D folder = paintFolder; // GetFolder();
17338
+
17339
+ folder.add(inst);
17340
+
17341
+ object.GetWindow().ResetModel();
17342
+ object.GetWindow().refreshContents();
17343
+ }
1644317344 }
1644417345 else
1644517346 paintcount = 0;
....@@ -16478,6 +17379,11 @@
1647817379 //System.out.println("objects[color] = " + objects[color]);
1647917380 //objects[color].Select();
1648017381 indexcount = 0;
17382
+ ObjEditor window = object.GetWindow();
17383
+ if (window != null && deselect)
17384
+ {
17385
+ window.Select(null, deselect, true);
17386
+ }
1648117387 object.Select(color, deselect);
1648217388 }
1648317389
....@@ -16528,6 +17434,7 @@
1652817434
1652917435 public void init(GLAutoDrawable drawable)
1653017436 {
17437
+ if (Globals.DEBUG)
1653117438 System.out.println("shadow buffer init");
1653217439
1653317440 GL gl = drawable.getGL();
....@@ -16577,7 +17484,7 @@
1657717484 gl.glDisable(gl.GL_CULL_FACE);
1657817485 }
1657917486
16580
- if (!RENDERSHADOW)
17487
+ if (!Globals.RENDERSHADOW)
1658117488 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1658217489
1658317490 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -16587,7 +17494,7 @@
1658717494 //gl.glColorMask(false, false, false, false);
1658817495
1658917496 //render_scene_from_light_view(gl, drawable, 0, 0);
16590
- if (RENDERSHADOW && Globals.lighttouched && !movingcamera) // && !parent.IsFreezed())
17497
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1659117498 {
1659217499 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1659317500
....@@ -16756,10 +17663,14 @@
1675617663 gl.glFlush();
1675717664
1675817665 /**/
16759
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17666
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1676017667
16761
- float[] pixels = occlusionsizebuffer.array();
17668
+ float[] depths = occlusiondepthbuffer.array();
1676217669
17670
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17671
+
17672
+ int[] pixels = selectsizebuffer.array();
17673
+
1676317674 double r = 0, g = 0, b = 0;
1676417675
1676517676 double count = 0;
....@@ -16770,7 +17681,7 @@
1677017681
1677117682 double FACTOR = 1;
1677217683
16773
- for (int i = 0; i < pixels.length; i++)
17684
+ for (int i = 0; i < depths.length; i++)
1677417685 {
1677517686 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1677617687 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -16853,7 +17764,7 @@
1685317764
1685417765 double scale = ray.z; // 1; // cos
1685517766
16856
- float depth = pixels[newindex];
17767
+ float depth = depths[newindex];
1685717768
1685817769 /*
1685917770 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -17003,23 +17914,15 @@
1700317914 int AAbuffersize = 0;
1700417915
1700517916 //double[] selectedpoint = new double[3];
17006
- static Superellipsoid selectedpoint = new Superellipsoid();
17917
+ static Superellipsoid selectedpoint;
1700717918 static Sphere previousselectedpoint = null;
17008
- static Sphere debugpointG = new Sphere();
17009
- static Sphere debugpointP = new Sphere();
17010
- static Sphere debugpointC = new Sphere();
17011
- static Sphere debugpointR = new Sphere();
17919
+ static Sphere debugpointG;
17920
+ static Sphere debugpointP;
17921
+ static Sphere debugpointC;
17922
+ static Sphere debugpointR;
1701217923
1701317924 static Sphere debugpoints[] = new Sphere[8];
1701417925
17015
- static
17016
- {
17017
- for (int i=0; i<8; i++)
17018
- {
17019
- debugpoints[i] = new Sphere();
17020
- }
17021
- }
17022
-
1702317926 static void InitPoints(float radius)
1702417927 {
1702517928 for (int i=0; i<8; i++)
....@@ -17058,11 +17961,14 @@
1705817961 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1705917962 static IntBuffer bigAAbuffer;
1706017963 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
17061
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17964
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1706217965 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1706317966 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1706417967 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17065
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17968
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17969
+
17970
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17971
+
1706617972 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1706717973 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1706817974 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();