Normand Briere
2019-08-26 6266c8a4b2485b29a7d5bcb217460d7aad3e1c4a
CameraPane.java
....@@ -18,7 +18,10 @@
1818 import javax.imageio.ImageIO;
1919 import javax.imageio.ImageWriteParam;
2020 import javax.imageio.ImageWriter;
21
+import javax.imageio.ImageReadParam;
22
+import javax.imageio.ImageReader;
2123 import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
24
+import javax.imageio.stream.ImageInputStream;
2225 import javax.imageio.stream.ImageOutputStream;
2326 import javax.imageio.ImageWriteParam;
2427
....@@ -30,6 +33,7 @@
3033 import java.nio.*;
3134
3235 import gleem.linalg.Mat4f;
36
+import javax.imageio.ImageTypeSpecifier;
3337
3438 class CameraPane extends GLCanvas implements iCameraPane, Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener
3539 {
....@@ -37,7 +41,6 @@
3741 static boolean[] selectedstack = new boolean[65536];
3842 static int materialdepth = 0;
3943
40
- static boolean DEBUG = false;
4144 static boolean FRUSTUM = false; // still bogus true; // frustum culling
4245
4346 // camera change fix
....@@ -45,6 +48,39 @@
4548 static boolean ABORTED = false;
4649
4750 static int STEP = 1;
51
+
52
+ private static BufferedImage CreateBim(byte[] bytes, int width, int height)
53
+ {
54
+ int[] pixels = new int[bytes.length/3];
55
+ for (int i=pixels.length; --i>=0;)
56
+ {
57
+ int i3 = i*3;
58
+ pixels[i] = 0xFF;
59
+ pixels[i] <<= 8;
60
+ pixels[i] |= bytes[i3+2] & 0xFF;
61
+ pixels[i] <<= 8;
62
+ pixels[i] |= bytes[i3+1] & 0xFF;
63
+ pixels[i] <<= 8;
64
+ pixels[i] |= bytes[i3] & 0xFF;
65
+ }
66
+ /*
67
+ int r=0,g=0,b=0,a=0;
68
+ for (int i=0; i<width; i++)
69
+ for (int j=0; j<height; j++)
70
+ {
71
+ int index = j*width+i;
72
+ int p = pixels[index];
73
+ a = ((p>>24) & 0xFF);
74
+ r = ((p>>16) & 0xFF);
75
+ g = ((p>>8) & 0xFF);
76
+ b = (p & 0xFF);
77
+ pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
78
+ }
79
+ /**/
80
+ BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
81
+ rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
82
+ return rendImage;
83
+ }
4884
4985 /*static*/ private boolean CULLFACE = false; // true;
5086 /*static*/ boolean NEAREST = false; // true;
....@@ -61,7 +97,7 @@
6197 //boolean REDUCETEXTURE = true;
6298 boolean CACHETEXTURE = true;
6399 boolean CLEANCACHE = false; // true;
64
- boolean MIPMAP = false; // true;
100
+ boolean MIPMAP = false; // true; // never works...
65101 boolean COMPRESSTEXTURE = false;
66102 boolean KOMPACTTEXTURE = false; // true;
67103 boolean RESIZETEXTURE = false;
....@@ -74,7 +110,11 @@
74110 //private Mat4f spotlightTransform = new Mat4f();
75111 //private Mat4f spotlightInverseTransform = new Mat4f();
76112 static GLContext glcontext = null;
77
- /*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
+
78118 boolean reverseUP = false;
79119 static boolean frozen = false;
80120 boolean enablebackspace = false; // patch for back buffer refresh
....@@ -106,7 +146,7 @@
106146 static boolean OEIL = true;
107147 static boolean OEILONCE = false; // do oeilon then oeiloff
108148 static boolean LOOKAT = true;
109
-static boolean RANDOM = true; // false;
149
+static boolean SWITCH = true; // false;
110150 static boolean HANDLES = false; // selection doesn't work!!
111151 static boolean PAINTMODE = false;
112152
....@@ -128,7 +168,7 @@
128168
129169
130170 // OPTIONS
131
- boolean Skinshader = true;
171
+ boolean Skinshader = false; // true;
132172 boolean cameraLight = false;
133173 boolean UVdebug = false;
134174 boolean Udebug = false;
....@@ -137,7 +177,7 @@
137177 static boolean doublesided = false; // true; // reversed normals are awful for conformance
138178 boolean anisotropy = true;
139179 boolean softshadow = true; // slower but better false;
140
- boolean opacityhalo = false;
180
+ boolean opacityhalo = false; // reverse the halo effect (e.g. glass)
141181
142182 boolean macromode = false;
143183
....@@ -148,6 +188,21 @@
148188 defaultcaps.setAccumGreenBits(16);
149189 defaultcaps.setAccumBlueBits(16);
150190 defaultcaps.setAccumAlphaBits(16);
191
+ }
192
+
193
+ private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
194
+
195
+ public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException
196
+ {
197
+ try
198
+ {
199
+ return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
200
+ } catch (IOException e)
201
+ {
202
+ System.out.println("NAME = " + name);
203
+ e.printStackTrace(); // throw new RuntimeException(e);
204
+ return null;
205
+ }
151206 }
152207
153208 void SetAsGLRenderer(boolean b)
....@@ -168,7 +223,8 @@
168223
169224 SetCamera(cam);
170225
171
- SetLight(new Camera(new cVector(10, 10, -20)));
226
+ // Warning: not used.
227
+ SetLight(new Camera(new cVector(15, 10, -20)));
172228
173229 object = o;
174230
....@@ -325,7 +381,7 @@
325381 cStatic.objectstack[materialdepth++] = obj;
326382 //System.out.println("material " + material);
327383 //Applet3D.tracein(this, selected);
328
- display.vector2buffer = obj.projectedVertices;
384
+ //display.vector2buffer = obj.projectedVertices;
329385 if (obj instanceof Camera)
330386 {
331387 display.options1[0] = material.shift;
....@@ -334,14 +390,28 @@
334390 display.options1[2] = material.shadowbias;
335391 display.options1[3] = material.aniso;
336392 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]);
337398 display.options2[0] = material.opacity;
338399 display.options2[1] = material.diffuse;
339400 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]);
340404
341405 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]);
342409 display.options4[0] = material.cameralight/0.2f;
343410 display.options4[1] = material.subsurface;
344411 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]);
345415
346416 // if (display.CURRENTANTIALIAS > 0)
347417 // display.options3[3] /= 4;
....@@ -357,7 +427,7 @@
357427 /**/
358428 } else
359429 {
360
- DrawMaterial(material, selected);
430
+ DrawMaterial(material, selected, obj.projectedVertices);
361431 }
362432 } else
363433 {
....@@ -381,8 +451,8 @@
381451 cStatic.objectstack[materialdepth++] = obj;
382452 //System.out.println("material " + material);
383453 //Applet3D.tracein("selected ", selected);
384
- display.vector2buffer = obj.projectedVertices;
385
- display.DrawMaterial(material, selected);
454
+ //display.vector2buffer = obj.projectedVertices;
455
+ display.DrawMaterial(material, selected, obj.projectedVertices);
386456 }
387457 }
388458
....@@ -399,8 +469,8 @@
399469 materialdepth -= 1;
400470 if (materialdepth > 0)
401471 {
402
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
403
- 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);
404474 }
405475 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
406476 } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
....@@ -420,8 +490,8 @@
420490 materialdepth -= 1;
421491 if (materialdepth > 0)
422492 {
423
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
424
- 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);
425495 }
426496 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
427497 //else
....@@ -462,15 +532,18 @@
462532 if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
463533 {
464534 //gl.glBegin(gl.GL_TRIANGLES);
465
- 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
+ ;
466538 if (!hasnorm)
467539 {
468
- // System.out.println("FUCK!!");
540
+ // System.out.println("Mesh normal");
469541 LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
470542 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
471543 LA.vecCross(obj.v0, obj.v1, obj.v2);
472544 LA.vecNormalize(obj.v2);
473
- 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);
474547 }
475548
476549 // P
....@@ -492,7 +565,7 @@
492565 y += ny * obj.NORMALPUSH;
493566 z += nz * obj.NORMALPUSH;
494567
495
- gl.glNormal3f(nx, ny, nz);
568
+ SetGLNormal(gl, nx, ny, nz);
496569 }
497570 gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
498571 SetColor(obj, pv);
....@@ -524,7 +597,7 @@
524597 y += ny * obj.NORMALPUSH;
525598 z += nz * obj.NORMALPUSH;
526599
527
- gl.glNormal3f(nx, ny, nz);
600
+ SetGLNormal(gl, nx, ny, nz);
528601 }
529602 //System.out.println("vertexq = " + qv.s + ", " + qv.t);
530603 // boolean locked = false;
....@@ -572,7 +645,7 @@
572645 y += ny * obj.NORMALPUSH;
573646 z += nz * obj.NORMALPUSH;
574647
575
- gl.glNormal3f(nx, ny, nz);
648
+ SetGLNormal(gl, nx, ny, nz);
576649 }
577650
578651 // if ((dot&4) == 0)
....@@ -808,7 +881,7 @@
808881 //// tris.postdraw(this);
809882 }
810883
811
- static Camera localcamera = new Camera();
884
+ static Camera localAOcamera = new Camera();
812885 static cVector from = new cVector();
813886 static cVector to = new cVector();
814887
....@@ -817,7 +890,7 @@
817890 CameraPane cp = this;
818891
819892 Camera keep = cp.RenderCamera();
820
- cp.renderCamera = localcamera;
893
+ cp.renderCamera = localAOcamera;
821894
822895 if (br.trimmed)
823896 {
....@@ -835,7 +908,7 @@
835908 br.positions[i3 + 2] + br.normals[i3 + 2]);
836909 LA.xformPos(from, transform, from);
837910 LA.xformPos(to, transform, to); // RIGID ONLY
838
- localcamera.setAim(from, to);
911
+ localAOcamera.setAim(from, to);
839912
840913 CameraPane.occlusionbuffer.display();
841914
....@@ -869,7 +942,7 @@
869942 to.set(v.x+v.norm.x, v.y+v.norm.y, v.z+v.norm.z);
870943 LA.xformPos(from, transform, from);
871944 LA.xformPos(to, transform, to); // RIGID ONLY
872
- localcamera.setAim(from, to);
945
+ localAOcamera.setAim(from, to);
873946
874947 CameraPane.occlusionbuffer.display();
875948
....@@ -1178,10 +1251,10 @@
11781251 {
11791252 if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
11801253 {
1181
- gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1254
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
11821255 } else
11831256 {
1184
- gl.glNormal3f(0, 0, 1);
1257
+ SetGLNormal(gl, 0, 0, 1);
11851258 }
11861259
11871260 if (c != null)
....@@ -1190,10 +1263,12 @@
11901263 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
11911264 }
11921265 }
1266
+
11931267 if (flipV)
11941268 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
11951269 else
11961270 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1271
+
11971272 //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
11981273 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
11991274
....@@ -1203,20 +1278,22 @@
12031278 {
12041279 if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
12051280 {
1206
- gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1281
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
12071282 } else
12081283 {
1209
- gl.glNormal3f(0, 0, 1);
1284
+ SetGLNormal(gl, 0, 0, 1);
12101285 }
12111286 if (c != null)
12121287 {
12131288 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
12141289 }
12151290 }
1291
+
12161292 if (flipV)
12171293 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12181294 else
12191295 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1296
+
12201297 //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
12211298 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
12221299
....@@ -1229,10 +1306,10 @@
12291306 {
12301307 if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
12311308 {
1232
- gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1309
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
12331310 } else
12341311 {
1235
- gl.glNormal3f(0, 0, 1);
1312
+ SetGLNormal(gl, 0, 0, 1);
12361313 }
12371314 if (c != null)
12381315 {
....@@ -1244,8 +1321,10 @@
12441321 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12451322 else
12461323 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1324
+
12471325 //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
12481326 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1327
+
12491328 count2 += 2;
12501329 count3 += 3;
12511330 }
....@@ -1412,7 +1491,7 @@
14121491 {
14131492 if (!selectmode)
14141493 {
1415
- 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);
14161495 gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
14171496
14181497 if (flipV)
....@@ -1424,6 +1503,8 @@
14241503 gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
14251504 }
14261505
1506
+ float[] colorV = new float[4];
1507
+
14271508 void SetColor(Object3D obj, Vertex p0)
14281509 {
14291510 CameraPane display = this;
....@@ -1491,8 +1572,6 @@
14911572 {
14921573 return;
14931574 }
1494
-
1495
- float[] colorV = new float[3];
14961575
14971576 if (false) // marked)
14981577 {
....@@ -1601,7 +1680,7 @@
16011680 // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
16021681 }
16031682
1604
- void DrawMaterial(cMaterial material, boolean selected)
1683
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
16051684 {
16061685 CameraPane display = this;
16071686 //new Exception().printStackTrace();
....@@ -1628,7 +1707,7 @@
16281707
16291708 cColor.HSBtoRGB(display.color, display.saturation, 1, display.modelParams0);
16301709
1631
- float[] colorV = GrafreeD.colorV;
1710
+ float[] colorV = Grafreed.colorV;
16321711
16331712 /**/
16341713 if (display.DrawMode() == display.DEFAULT) // && display.RENDERPROGRAM == 0)
....@@ -1636,7 +1715,7 @@
16361715 colorV[0] = display.modelParams0[0] * material.diffuse;
16371716 colorV[1] = display.modelParams0[1] * material.diffuse;
16381717 colorV[2] = display.modelParams0[2] * material.diffuse;
1639
- colorV[3] = material.opacity;
1718
+ colorV[3] = 1; // material.opacity;
16401719
16411720 gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
16421721 //System.out.println("Opacity = " + opacity);
....@@ -1741,12 +1820,12 @@
17411820
17421821 display.modelParams7[0] = 0;
17431822 display.modelParams7[1] = 1000;
1744
- display.modelParams7[2] = 0;
1823
+ display.modelParams7[2] = material.parallax;
17451824 display.modelParams7[3] = 0;
17461825
1747
- display.modelParams6[0] = 100; // criss de bug de bump
1826
+ //display.modelParams6[0] = 100; // criss de bug de bump
17481827
1749
- Object3D.cVector2[] extparams = display.vector2buffer;
1828
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
17501829 if (extparams != null && extparams.length > 0 && extparams[0] != null)
17511830 {
17521831 display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
....@@ -1888,7 +1967,7 @@
18881967 void PushMatrix(double[][] matrix)
18891968 {
18901969 // GrafreeD.tracein(matrix);
1891
- PushMatrix(matrix,1);
1970
+ PushMatrix(matrix, 1);
18921971 }
18931972
18941973 void PushMatrix()
....@@ -1974,9 +2053,9 @@
19742053 switch(viewcode)
19752054 {
19762055 case 0: return "main";
1977
- case 1: return "one";
1978
- case 2: return "two";
1979
- case 3: return "three";
2056
+ case 1: return "Red";
2057
+ case 2: return "Green";
2058
+ case 3: return "Blue";
19802059 case 4: return "light";
19812060 }
19822061
....@@ -2042,7 +2121,7 @@
20422121 //System.err.println("Oeil on");
20432122 OEIL = true;
20442123 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2045
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2124
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
20462125 //pingthread.StepToTarget(true);
20472126 }
20482127
....@@ -2140,7 +2219,7 @@
21402219 System.err.println("LIVE = " + Globals.isLIVE());
21412220
21422221 if (!Globals.isLIVE()) // save sound
2143
- GrafreeD.savesound = true; // wav.save();
2222
+ Grafreed.savesound = true; // wav.save();
21442223 // else
21452224 repaint(); // start loop // may 2013
21462225 }
....@@ -2257,7 +2336,7 @@
22572336
22582337 void ToggleDebug()
22592338 {
2260
- DEBUG ^= true;
2339
+ Globals.DEBUG ^= true;
22612340 }
22622341
22632342 void ToggleLookAt()
....@@ -2265,9 +2344,9 @@
22652344 LOOKAT ^= true;
22662345 }
22672346
2268
- void ToggleRandom()
2347
+ void ToggleSwitch()
22692348 {
2270
- RANDOM ^= true;
2349
+ SWITCH ^= true;
22712350 }
22722351
22732352 void ToggleHandles()
....@@ -2275,10 +2354,17 @@
22752354 HANDLES ^= true;
22762355 }
22772356
2357
+ Object3D paintFolder;
2358
+
22782359 void TogglePaint()
22792360 {
22802361 PAINTMODE ^= true;
22812362 paintcount = 0;
2363
+
2364
+ if (PAINTMODE)
2365
+ {
2366
+ paintFolder = GetFolder();
2367
+ }
22822368 }
22832369
22842370 void SwapCamera(int a, int b)
....@@ -2374,7 +2460,34 @@
23742460 {
23752461 return currentGL;
23762462 }
2377
-
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
+
23782491 /**/
23792492 class CacheTexture
23802493 {
....@@ -2383,28 +2496,31 @@
23832496
23842497 int resolution;
23852498
2386
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2499
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
23872500 {
2388
- texture = tex;
2501
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2502
+ texturedata = texdata;
23892503 resolution = res;
23902504 }
23912505 }
23922506 /**/
23932507
23942508 // TEXTURE static Texture texture;
2395
- static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures
2396
- = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>();
2397
- 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
+
23982514 int pigmentdepth = 0;
23992515 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
24002516 int bumpdepth = 0;
24012517 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
24022518 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
24032519 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2404
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2520
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
24052521 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
24062522
2407
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2523
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
24082524 {
24092525 TextureData texturedata = null;
24102526
....@@ -2414,7 +2530,7 @@
24142530 com.sun.opengl.util.texture.TextureIO.newTextureData(
24152531 getClass().getClassLoader().getResourceAsStream(name),
24162532 true,
2417
- com.sun.opengl.util.texture.TextureIO.PNG);
2533
+ GetFormat(name)); // com.sun.opengl.util.texture.TextureIO.PNG);
24182534 } catch (java.io.IOException e)
24192535 {
24202536 throw new javax.media.opengl.GLException(e);
....@@ -2423,13 +2539,34 @@
24232539 if (bump)
24242540 texturedata = ConvertBump(texturedata, false);
24252541
2426
- com.sun.opengl.util.texture.Texture texture =
2427
- 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);
24282544
2429
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2430
- 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);
24312547
2432
- 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;
24332570 }
24342571
24352572 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3502,6 +3639,8 @@
35023639
35033640 System.out.println("LOADING TEXTURE : " + name);
35043641
3642
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3643
+
35053644 //
35063645 if (false) // compressbit > 0)
35073646 {
....@@ -7900,7 +8039,7 @@
79008039 String pigment = Object3D.GetPigment(tex);
79018040 String bump = Object3D.GetBump(tex);
79028041
7903
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8042
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79048043 {
79058044 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79068045 // System.out.println("; bump = " + bump);
....@@ -7915,11 +8054,69 @@
79158054 pigment = null;
79168055 }
79178056
7918
- ReleaseTexture(bump, true);
7919
- ReleaseTexture(pigment, false);
8057
+ ReleaseTexture(tex, true);
8058
+ ReleaseTexture(tex, false);
79208059 }
79218060
7922
- 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)
79238120 {
79248121 if (// DrawMode() != 0 || /*tex == null ||*/
79258122 ambientOcclusion ) // || !textureon)
....@@ -7930,7 +8127,7 @@
79308127 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
79318128
79328129 if (tex != null)
7933
- texture = textures.get(tex);
8130
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
79348131
79358132 // //assert( texture != null );
79368133 // if (texture == null)
....@@ -8022,7 +8219,55 @@
80228219 }
80238220 }
80248221
8025
- /*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
80268271 {
80278272 if (// DrawMode() != 0 || /*tex == null ||*/
80288273 ambientOcclusion ) // || !textureon)
....@@ -8033,17 +8278,47 @@
80338278 if (tex == null)
80348279 {
80358280 BindTexture(null,false,resolution);
8036
- BindTexture(null,true,resolution);
80378281 return;
80388282 }
80398283
80408284 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
+
80418317 String bump = Object3D.GetBump(tex);
80428318
8043
- usedtextures.put(pigment, pigment);
8044
- usedtextures.put(bump, bump);
8319
+ usedtextures.add(tex);
80458320
8046
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8321
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
80478322 {
80488323 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
80498324 // System.out.println("; bump = " + bump);
....@@ -8053,43 +8328,94 @@
80538328 {
80548329 bump = null;
80558330 }
8056
- if (pigment.equals(""))
8057
- {
8058
- pigment = null;
8059
- }
80608331
8061
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8062
- BindTexture(pigment, false, resolution);
80638332 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8064
- BindTexture(bump, true, resolution);
8333
+ BindTexture(tex, true, resolution);
80658334 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8066
-
8067
- return; // true;
80688335 }
80698336
8070
- 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)
80718340 {
8072
- 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;
80738360
80748361 if (tex != null)
80758362 {
8076
- String texname = tex;
8363
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8364
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
80778365
8078
- String[] split = tex.split("Textures");
8079
- if (split.length > 1)
8080
- texname = "/Users/nbriere/Textures" + split[split.length-1];
8081
- else
8082
- if (!texname.startsWith("/"))
8083
- 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
+ }
80848383
80858384 if (CACHETEXTURE)
8086
- texture = textures.get(texname); // TEXTURE CACHE
8087
-
8088
- TextureData texturedata = null;
8089
-
8090
- if (texture == null || texture.resolution < resolution)
80918385 {
8092
- 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(""))
80938419 {
80948420 assert(!bump);
80958421 // if (bump)
....@@ -8100,19 +8426,23 @@
81008426 // }
81018427 // else
81028428 // {
8103
- texture = textures.get(tex);
8104
- if (texture == null)
8429
+ // texturecache = textures.get(texname); // suspicious
8430
+ if (texturecache == null)
81058431 {
8106
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8432
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
81078433 }
8434
+ else
8435
+ new Exception().printStackTrace();
81088436 // }
81098437 } else
8110
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8438
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
81118439 {
81128440 assert(bump);
8113
- texture = textures.get(tex);
8114
- if (texture == null)
8115
- 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();
81168446 } else
81178447 {
81188448 //if (tex.equals("IMMORTAL"))
....@@ -8120,11 +8450,22 @@
81208450 // texture = GetResourceTexture("default.png");
81218451 //} else
81228452 //{
8123
- if (tex.equals("WHITE_NOISE"))
8453
+ if (texname.endsWith("WHITE_NOISE"))
81248454 {
8125
- texture = textures.get(tex);
8126
- if (texture == null)
8127
- 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();
81288469 } else
81298470 {
81308471 if (textureon)
....@@ -8149,7 +8490,7 @@
81498490 }
81508491
81518492 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
8152
- if (!new File(cachename).exists())
8493
+ if (!FileExists(cachename))
81538494 cachename = texname;
81548495 else
81558496 processbump = false; // don't process bump map again
....@@ -8171,7 +8512,7 @@
81718512 }
81728513
81738514 cachename = texname.substring(0, texname.length()-4)+ext+".png";
8174
- if (!new File(cachename).exists())
8515
+ if (!FileExists(cachename))
81758516 cachename = texname;
81768517 else
81778518 processbump = false; // don't process bump map again
....@@ -8180,20 +8521,23 @@
81808521 texturedata = GetFileTexture(cachename, processbump, resolution);
81818522
81828523
8183
- if (texturedata != null)
8184
- 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);
81858528 //texture = GetTexture(tex, bump);
81868529 }
8530
+ }
81878531 }
81888532 //}
81898533 }
81908534
8191
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8535
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
81928536 {
81938537 //return false;
81948538
81958539 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8196
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8540
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
81978541 {
81988542 // String ext = "_highres";
81998543 // if (REDUCETEXTURE)
....@@ -8210,52 +8554,17 @@
82108554 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
82118555 if (!cachefile.exists())
82128556 {
8213
- // cache to disk
8214
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
8215
- //buffers[0].
8216
-
8217
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
8218
- int[] pixels = new int[bytebuf.capacity()/3];
8219
-
8220
- // squared size heuristic...
8221
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8557
+ //if (texturedata.getWidth() == texturedata.getHeight())
82228558 {
8223
- for (int i=pixels.length; --i>=0;)
8224
- {
8225
- int i3 = i*3;
8226
- pixels[i] = 0xFF;
8227
- pixels[i] <<= 8;
8228
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
8229
- pixels[i] <<= 8;
8230
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
8231
- pixels[i] <<= 8;
8232
- pixels[i] |= bytebuf.get(i3) & 0xFF;
8233
- }
8234
-
8235
- /*
8236
- int r=0,g=0,b=0,a=0;
8237
- for (int i=0; i<width; i++)
8238
- for (int j=0; j<height; j++)
8239
- {
8240
- int index = j*width+i;
8241
- int p = pixels[index];
8242
- a = ((p>>24) & 0xFF);
8243
- r = ((p>>16) & 0xFF);
8244
- g = ((p>>8) & 0xFF);
8245
- b = (p & 0xFF);
8246
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
8247
- }
8248
- /**/
8249
- int width = (int)Math.sqrt(pixels.length); // squared
8250
- int height = width;
8251
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
8252
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8559
+ BufferedImage rendImage = CreateBim(texturedata);
8560
+
82538561 ImageWriter writer = null;
82548562 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
82558563 if (iter.hasNext()) {
82568564 writer = (ImageWriter)iter.next();
82578565 }
8258
- float compressionQuality = 0.9f;
8566
+
8567
+ float compressionQuality = 0.85f;
82598568 try
82608569 {
82618570 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8272,18 +8581,20 @@
82728581 }
82738582 }
82748583 }
8275
-
8584
+
8585
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8586
+
82768587 //System.out.println("Texture = " + tex);
8277
- if (textures.containsKey(texname))
8588
+ if (textures.containsKey(tex))
82788589 {
8279
- CacheTexture thetex = textures.get(texname);
8590
+ CacheTexture thetex = textures.get(tex);
82808591 thetex.texture.disable();
82818592 thetex.texture.dispose();
8282
- textures.remove(texname);
8593
+ textures.remove(tex);
82838594 }
82848595
8285
- texture.texturedata = texturedata;
8286
- textures.put(texname, texture);
8596
+ //texture.texturedata = texturedata;
8597
+ textures.put(tex, texturecache);
82878598
82888599 // newtex = true;
82898600 }
....@@ -8299,10 +8610,44 @@
82998610 }
83008611 }
83018612
8302
- return texture;
8613
+ return texturecache;
83038614 }
83048615
8305
- 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
83068651 {
83078652 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
83088653
....@@ -8320,21 +8665,21 @@
83208665 return texture!=null?texture.texture:null;
83218666 }
83228667
8323
- 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
83248669 {
83258670 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
83268671
83278672 return texture!=null?texture.texturedata:null;
83288673 }
83298674
8330
- boolean BindTexture(String tex, boolean bump, int resolution)
8675
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
83318676 {
83328677 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
83338678 {
83348679 return false;
83358680 }
83368681
8337
- boolean newtex = false;
8682
+ //boolean newtex = false;
83388683
83398684 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
83408685
....@@ -8366,9 +8711,75 @@
83668711 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
83678712 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
83688713
8369
- return newtex;
8714
+ return true; // Warning: not used.
83708715 }
83718716
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
+
83728783 ShadowBuffer shadowPBuf;
83738784 AntialiasBuffer antialiasPBuf;
83748785 int MAXSTACK;
....@@ -8385,10 +8796,12 @@
83858796
83868797 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
83878798 MAXSTACK = temp[0];
8388
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8799
+ if (Globals.DEBUG)
8800
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
83898801 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
83908802 MAXSTACK = temp[0];
8391
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8803
+ if (Globals.DEBUG)
8804
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
83928805
83938806 // Use debug pipeline
83948807 //drawable.setGL(new DebugGL(gl)); //
....@@ -8396,7 +8809,8 @@
83968809 gl = drawable.getGL(); //
83978810
83988811 GL gl3 = getGL();
8399
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8812
+ if (Globals.DEBUG)
8813
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
84008814
84018815
84028816 //float pos[] = { 100, 100, 100, 0 };
....@@ -8561,7 +8975,7 @@
85618975
85628976 if (cubemap == null)
85638977 {
8564
- LoadEnvy(5);
8978
+ //LoadEnvy(1);
85658979 }
85668980
85678981 //cubemap.enable();
....@@ -8837,6 +9251,8 @@
88379251
88389252 void LoadEnvy(int which)
88399253 {
9254
+ assert(false);
9255
+
88409256 String name;
88419257 String ext;
88429258
....@@ -8848,37 +9264,58 @@
88489264 cubemap = null;
88499265 return;
88509266 case 1:
8851
- name = "cubemaps/box_";
8852
- ext = "png";
9267
+ name = "cubemaps/rgb/";
9268
+ ext = "jpg";
88539269 reverseUP = false;
88549270 break;
88559271 case 2:
8856
- name = "cubemaps/uffizi_";
8857
- ext = "png";
8858
- break; // reverseUP = true; break;
9272
+ name = "cubemaps/uffizi/";
9273
+ ext = "jpg";
9274
+ reverseUP = false;
9275
+ break;
88599276 case 3:
8860
- name = "cubemaps/CloudyHills_";
8861
- ext = "tga";
9277
+ name = "cubemaps/CloudyHills/";
9278
+ ext = "jpg";
88629279 reverseUP = false;
88639280 break;
88649281 case 4:
8865
- name = "cubemaps/cornell_";
9282
+ name = "cubemaps/cornell/";
88669283 ext = "png";
88679284 reverseUP = false;
88689285 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;
88699311 default:
8870
- name = "cubemaps/rgb_";
8871
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9312
+ name = "cubemaps/box/";
9313
+ ext = "png"; /*mipmap = true;*/
9314
+ reverseUP = false;
88729315 break;
88739316 }
8874
-
8875
- try
8876
- {
8877
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
8878
- } catch (IOException e)
8879
- {
8880
- throw new RuntimeException(e);
8881
- }
9317
+
9318
+ LoadSkybox(name, ext, mipmap);
88829319 }
88839320
88849321 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -8910,8 +9347,12 @@
89109347 static double[] model = new double[16];
89119348 double[] camera2light = new double[16];
89129349 double[] light2camera = new double[16];
8913
- int newenvy = -1;
8914
- boolean envyoff = true; // false;
9350
+
9351
+ //int newenvy = -1;
9352
+ //boolean envyoff = false;
9353
+
9354
+ String loadedskyboxname;
9355
+
89159356 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
89169357 //float[] light0 = { 0,0,0 };
89179358 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9204,11 +9645,35 @@
92049645 jy8[3] = 0.5f;
92059646 }
92069647
9207
- 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
92089649 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
92099650 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
92109651 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
92119652
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
+
92129677 static int imagecount = 0; // movie generation
92139678
92149679 static int jitter = 0;
....@@ -9304,8 +9769,8 @@
93049769 assert (parentcam != renderCamera);
93059770
93069771 if (renderCamera != lightCamera)
9307
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9308
- LA.matConcat(matrix, parentcam.toParent, matrix);
9772
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9773
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
93099774
93109775 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
93119776
....@@ -9320,8 +9785,8 @@
93209785 LA.matCopy(renderCamera.fromScreen, matrix);
93219786
93229787 if (renderCamera != lightCamera)
9323
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9324
- LA.matConcat(parentcam.fromParent, matrix, matrix);
9788
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9789
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
93259790
93269791 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
93279792
....@@ -9367,10 +9832,12 @@
93679832 rati = 1 / rati;
93689833 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
93699834 }
9370
- assert (newenvy == -1);
9835
+
9836
+ //assert (newenvy == -1);
9837
+
93719838 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
93729839 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9373
- DrawSkyBox(gl);
9840
+ DrawSkyBox(gl, (float)rati);
93749841 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
93759842 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
93769843 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -9538,7 +10005,7 @@
953810005
953910006 if (!BOXMODE)
954010007 {
9541
- 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) + ")");
954210009 }
954310010
954410011 if (!BOXMODE)
....@@ -9576,7 +10043,7 @@
957610043 ABORTED = false;
957710044 }
957810045 else
9579
- GrafreeD.wav.cursor += 735 * ACSIZE;
10046
+ Grafreed.wav.cursor += 735 * ACSIZE;
958010047
958110048 if (false)
958210049 {
....@@ -10236,14 +10703,23 @@
1023610703 static boolean init = false;
1023710704
1023810705 double[][] matrix = LA.newMatrix();
10706
+
10707
+ // This is to refresh the UI of the material panel.
10708
+ ObjEditor patchMaterial;
1023910709
1024010710 public void display(GLAutoDrawable drawable)
1024110711 {
10242
- if (GrafreeD.savesound && GrafreeD.hassound)
10712
+ if (patchMaterial.patchMaterial)
1024310713 {
10244
- GrafreeD.wav.save();
10245
- GrafreeD.savesound = false;
10246
- 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;
1024710723 }
1024810724 // if (DEBUG_SELECTION)
1024910725 // {
....@@ -10319,6 +10795,7 @@
1031910795 ANTIALIAS = 0;
1032010796 //System.out.println("RESTART");
1032110797 AAtimer.restart();
10798
+ Globals.TIMERRUNNING = true;
1032210799 }
1032310800 }
1032410801 }
....@@ -10373,7 +10850,7 @@
1037310850 Object3D theobject = object;
1037410851 Object3D theparent = object.parent;
1037510852 object.parent = null;
10376
- object = (Object3D)GrafreeD.clone(object);
10853
+ object = (Object3D)Grafreed.clone(object);
1037710854 object.Stripify();
1037810855 if (theobject.selection == null || theobject.selection.Size() == 0)
1037910856 theobject.PreprocessOcclusion(this);
....@@ -10386,13 +10863,14 @@
1038610863 ambientOcclusion = false;
1038710864 }
1038810865
10389
- if (Globals.lighttouched && DrawMode() == DEFAULT && !lightMode) // && !FROZEN)
10866
+ if (//Globals.lighttouched &&
10867
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1039010868 {
1039110869 //if (RENDERSHADOW) // ?
1039210870 if (!IsFrozen())
1039310871 {
1039410872 // dec 2012
10395
- if (!ambientOcclusion && !(!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0))
10873
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
1039610874 {
1039710875 Globals.framecount++;
1039810876 shadowbuffer.display();
....@@ -10405,7 +10883,7 @@
1040510883
1040610884 if (wait)
1040710885 {
10408
- Sleep(500);
10886
+ Sleep(200); // blocks everything
1040910887
1041010888 wait = false;
1041110889 }
....@@ -10519,8 +10997,8 @@
1051910997
1052010998 // if (parentcam != renderCamera) // not a light
1052110999 if (cam != lightCamera)
10522
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10523
- LA.matConcat(matrix, parentcam.toParent, matrix);
11000
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11001
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1052411002
1052511003 for (int j = 0; j < 4; j++)
1052611004 {
....@@ -10534,8 +11012,8 @@
1053411012
1053511013 // if (parentcam != renderCamera) // not a light
1053611014 if (cam != lightCamera)
10537
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10538
- LA.matConcat(parentcam.fromParent, matrix, matrix);
11015
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11016
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1053911017
1054011018 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1054111019
....@@ -10621,13 +11099,43 @@
1062111099 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1062211100 }
1062311101
10624
- 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"))
1062511110 {
10626
- LoadEnvy(newenvy);
11111
+ if (cubemaprgb == null)
11112
+ {
11113
+ cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb2" + "/", "jpg", false);
11114
+ }
11115
+
11116
+ cubemap = cubemaprgb;
1062711117 }
10628
-
10629
- newenvy = -1;
10630
-
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
+
1063111139 ratio = ((double) getWidth()) / getHeight();
1063211140 //System.out.println("ratio = " + ratio);
1063311141
....@@ -10643,7 +11151,7 @@
1064311151
1064411152 if (!IsFrozen() && !ambientOcclusion)
1064511153 {
10646
- DrawSkyBox(gl);
11154
+ DrawSkyBox(gl, (float)ratio);
1064711155 }
1064811156
1064911157 //if (selection_view == -1)
....@@ -10794,7 +11302,16 @@
1079411302 // Bump noise
1079511303 gl.glActiveTexture(GL.GL_TEXTURE6);
1079611304 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
10797
- 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
+
1079811315
1079911316 gl.glActiveTexture(GL.GL_TEXTURE0);
1080011317 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -10817,9 +11334,9 @@
1081711334
1081811335 gl.glMatrixMode(GL.GL_MODELVIEW);
1081911336
10820
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10821
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10822
-//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);
1082311340 } else
1082411341 {
1082511342 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -10830,7 +11347,7 @@
1083011347 //System.out.println("BLENDING ON");
1083111348 gl.glEnable(GL.GL_BLEND);
1083211349 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
10833
-
11350
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1083411351 gl.glMatrixMode(gl.GL_PROJECTION);
1083511352 gl.glLoadIdentity();
1083611353
....@@ -10919,8 +11436,8 @@
1091911436 System.err.println("parentcam != renderCamera");
1092011437
1092111438 // if (cam != lightCamera)
10922
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10923
- 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
1092411441 }
1092511442
1092611443 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -10941,8 +11458,8 @@
1094111458 if (true) // TODO
1094211459 {
1094311460 if (cam != lightCamera)
10944
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10945
- 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
1094611463 }
1094711464
1094811465 LA.xformPos(light0, cam.toScreen, light0);
....@@ -11079,7 +11596,7 @@
1107911596 }
1108011597 }
1108111598
11082
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11599
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1108311600 {
1108411601 //gl.glDepthFunc(GL.GL_LEQUAL);
1108511602 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11087,24 +11604,21 @@
1108711604
1108811605 boolean texon = textureon;
1108911606
11090
- if (RENDERPROGRAM > 0)
11091
- {
11092
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11093
- textureon = false;
11094
- }
11607
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11608
+ textureon = false;
11609
+
1109511610 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1109611611 //System.out.println("ALLO");
1109711612 gl.glColorMask(false, false, false, false);
1109811613 DrawObject(gl);
11099
- if (RENDERPROGRAM > 0)
11100
- {
11101
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11102
- textureon = texon;
11103
- }
11614
+
11615
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11616
+ textureon = texon;
11617
+
1110411618 gl.glColorMask(true, true, true, true);
1110511619
1110611620 gl.glDepthFunc(GL.GL_EQUAL);
11107
- //gl.glDepthMask(false);
11621
+ gl.glDepthMask(false);
1110811622 }
1110911623
1111011624 if (false) // DrawMode() == SHADOW)
....@@ -11279,23 +11793,44 @@
1127911793 e.printStackTrace();
1128011794 }
1128111795
11282
- if (GrafreeD.RENDERME > 0)
11283
- GrafreeD.RENDERME--; // mechante magouille
11796
+ if (Grafreed.RENDERME > 0)
11797
+ Grafreed.RENDERME--; // mechante magouille
1128411798
1128511799 Globals.ONESTEP = false;
1128611800 }
1128711801
1128811802 static boolean zoomonce = false;
1128911803
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
+
1129011822 void DrawObject(GL gl, boolean draw)
1129111823 {
11824
+ // To clear camera values
11825
+ ResetOptions();
11826
+
1129211827 //System.out.println("DRAW OBJECT " + mouseDown);
1129311828 // DrawMode() = SELECTION;
1129411829 //GL gl = getGL();
1129511830 if ((TRACK || SHADOWTRACK) || zoomonce)
1129611831 {
1129711832 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11298
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11833
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1129911834 pingthread.StepToTarget(true); // true);
1130011835 // zoomonce = false;
1130111836 }
....@@ -11350,7 +11885,14 @@
1135011885
1135111886 usedtextures.clear();
1135211887
11353
- 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
+ }
1135411896 }
1135511897 //System.out.println("--> " + stackdepth);
1135611898 // GrafreeD.traceon();
....@@ -11360,8 +11902,9 @@
1136011902
1136111903 if (DrawMode() == DEFAULT)
1136211904 {
11363
- if (DEBUG)
11905
+ if (Globals.DEBUG)
1136411906 {
11907
+ CreateSelectedPoint();
1136511908 float radius = 0.05f;
1136611909 if (selectedpoint.radius != radius)
1136711910 {
....@@ -11415,20 +11958,32 @@
1141511958 ReleaseTextures(DEFAULT_TEXTURES);
1141611959
1141711960 if (CLEANCACHE)
11418
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11961
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1141911962 {
11420
- String tex = e.nextElement();
11963
+ cTexture tex = e.nextElement();
1142111964
1142211965 // System.out.println("Texture --------- " + tex);
1142311966
11424
- if (tex.equals("WHITE_NOISE"))
11967
+ if (tex.equals("WHITE_NOISE:"))
1142511968 continue;
1142611969
11427
- if (!usedtextures.containsKey(tex))
11970
+ if (!usedtextures.contains(tex))
1142811971 {
11972
+ CacheTexture gettex = texturepigment.get(tex);
1142911973 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11430
- textures.get(tex).texture.dispose();
11431
- 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
+ }
1143211987 }
1143311988 }
1143411989 }
....@@ -11441,7 +11996,14 @@
1144111996 if (checker != null && DrawMode() == DEFAULT)
1144211997 {
1144311998 //BindTexture(IMMORTAL_TEXTURE);
11444
- 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
+ }
1144512007 // NEAREST
1144612008 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
1144712009 DrawChecker(gl);
....@@ -11523,7 +12085,7 @@
1152312085 return;
1152412086 }
1152512087
11526
- String string = obj.GetToolTip();
12088
+ String string = obj.toString(); //.GetToolTip();
1152712089
1152812090 GL gl = GetGL();
1152912091
....@@ -11840,8 +12402,8 @@
1184012402 //obj.TransformToWorld(light, light);
1184112403 for (int i = tp.size(); --i >= 0;)
1184212404 {
11843
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
11844
- 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);
1184512407 }
1184612408
1184712409
....@@ -11858,8 +12420,8 @@
1185812420 parentcam = cameras[0];
1185912421 }
1186012422
11861
- for (int count = parentcam.GetTransformCount(); --count>=0;)
11862
- 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
1186312425
1186412426 LA.xformPos(light, renderCamera.toScreen, light);
1186512427
....@@ -11949,8 +12511,82 @@
1194912511
1195012512 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1195112513
11952
- String program =
12514
+ String programmin =
12515
+ // Min shader
1195312516 "!!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
+
1195412590 //"OPTION ARB_fragment_program_shadow;" +
1195512591 "PARAM light2cam0 = program.env[10];" +
1195612592 "PARAM light2cam1 = program.env[11];" +
....@@ -11976,7 +12612,7 @@
1197612612 "PARAM params4 = program.env[4];" + // anisoV, cameralight, selfshadow, shadow
1197712613 "PARAM params5 = program.env[5];" + // texture, opacity, fakedepth, shadowbias
1197812614 "PARAM params6 = program.env[6];" + // bump, noise, borderfade, fog punchthrough
11979
- "PARAM params7 = program.env[7];" + // noise power, opacity power
12615
+ "PARAM params7 = program.env[7];" + // noise power, opacity power, parallax
1198012616 "PARAM options0 = program.env[63];" + // fog density, intensity, elevation
1198112617 "PARAM options1 = program.env[62];" + // fog rgb color
1198212618 "PARAM options2 = program.env[61];" + // image intensity, subsurface, lightsheen
....@@ -12065,8 +12701,7 @@
1206512701 "TEMP shininess;" +
1206612702 "\n" +
1206712703 "MOV texSamp, one;" +
12068
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12069
-
12704
+
1207012705 "MOV mapgrid.x, one2048th.x;" +
1207112706 "MOV temp, fragment.texcoord[1];" +
1207212707 /*
....@@ -12087,20 +12722,20 @@
1208712722 "MUL temp, floor, mapgrid.x;" +
1208812723 //"TEX depth0, temp, texture[1], 2D;" +
1208912724 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12090
- TextureFetch("depth0", "temp", "1") +
12725
+ ShadowTextureFetch("depth0", "temp", "1") +
1209112726 "") +
1209212727 "ADD temp.x, temp.x, mapgrid.x;" +
1209312728 //"TEX depth1, temp, texture[1], 2D;" +
1209412729 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12095
- TextureFetch("depth1", "temp", "1") +
12730
+ ShadowTextureFetch("depth1", "temp", "1") +
1209612731 "") +
1209712732 "ADD temp.y, temp.y, mapgrid.x;" +
1209812733 //"TEX depth2, temp, texture[1], 2D;" +
12099
- TextureFetch("depth2", "temp", "1") +
12734
+ ShadowTextureFetch("depth2", "temp", "1") +
1210012735 "SUB temp.x, temp.x, mapgrid.x;" +
1210112736 //"TEX depth3, temp, texture[1], 2D;" +
1210212737 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12103
- TextureFetch("depth3", "temp", "1") +
12738
+ ShadowTextureFetch("depth3", "temp", "1") +
1210412739 "") +
1210512740 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1210612741 //"MOV params, material;" +
....@@ -12222,7 +12857,7 @@
1222212857 "POW texSamp.a, texSamp.a, params6.w;" + // fog punch through shortcut
1222312858 // mar 2013 ??? "KIL alpha.a;" +
1222412859 "MOV alpha, texSamp.aaaa;" + // y;" +
12225
- "KIL alpha.a;" +
12860
+ "KIL alpha.a;" + // not sure with parallax mapping
1222612861 /*
1222712862 "MUL temp.xy, temp, two;" +
1222812863 "TXB bump, temp, texture[0], 2D;" +
....@@ -12308,11 +12943,6 @@
1230812943 "SUB bump0, bump0, half;" +
1230912944 "ADD bump, bump, bump0;" +
1231012945
12311
- "MOV temp.x, texSamp.a;" +
12312
- "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
12313
- //"LRP texSamp0, params5.x, texSamp0, one;" +
12314
- "MOV texSamp.a, temp.x;" +
12315
-
1231612946 // double-sided
1231712947 /**/
1231812948 (doublesided?"DP3 temp.z, normal, eye;" +
....@@ -12322,26 +12952,73 @@
1232212952 "ADD temp.x, temp.x, one.x;" +
1232312953 "MUL normal, normal, temp.xxxx;":""
1232412954 ) +
12325
- /**/
12326
-//// Normalize("normal") +
12327
-//// "MAX normal.z, eps.x, normal.z;" +
12328
-// Normalize("normal") +
12329
- "MOV normald, normal;" +
12330
- "MOV normals, normal;" +
12955
+ /**/
12956
+
12957
+ "MOV temp, fragment.texcoord[4];" +
1233112958
1233212959 // UV base
1233312960 //"DP3 UP.x,state.matrix.modelview.row[0],Y;" +
1233412961 //"DP3 UP.y,state.matrix.modelview.row[1],Y;" +
1233512962 //"DP3 UP.z,state.matrix.modelview.row[2],Y;" +
12336
- "DP3 UP.x,state.matrix.texture[7].row[0],Y;" +
12337
- "DP3 UP.y,state.matrix.texture[7].row[1],Y;" +
12338
- "DP3 UP.z,state.matrix.texture[7].row[2],Y;" +
12963
+ "DP3 UP.x,state.matrix.texture[7].row[0],temp;" +
12964
+ "DP3 UP.y,state.matrix.texture[7].row[1],temp;" +
12965
+ "DP3 UP.z,state.matrix.texture[7].row[2],temp;" +
12966
+ Normalize("UP") +
12967
+
1233912968 "XPD V, normal, UP;" +
1234012969 Normalize("V") +
1234112970 "XPD U, V, normal;" +
1234212971 Normalize("U") +
1234312972
12973
+ "MOV temp, fragment.texcoord[0];" +
12974
+
12975
+// "MAD normal, -temp.x, U, normal;" +
12976
+// "MAD normal, -temp.y, V, normal;" +
12977
+// Normalize("normal") +
12978
+
12979
+//// "MAX normal.z, eps.x, normal.z;" +
12980
+// Normalize("normal") +
12981
+ "MOV normald, normal;" +
12982
+ "MOV normals, normal;" +
12983
+
1234412984 // parallax mapping
12985
+
12986
+ "DP3 temp2.x, V, eye;" +
12987
+ "DP3 temp2.y, U, eye;" +
12988
+ "DP3 temp2.z, normal, eye;" +
12989
+ "RCP temp2.z, temp2.z;" +
12990
+
12991
+ "DP3 temp2.w, texSamp, texSamp;" + // Height
12992
+ "RSQ temp2.w, temp2.w;" +
12993
+ "RCP temp2.w, temp2.w;" +
12994
+
12995
+ "SUB temp2.w, temp2.w, half;" +
12996
+ // "SGE temp.x, temp2.w, eps.x;" +
12997
+ // "MUL temp2.w, temp2.w, temp.x;" +
12998
+
12999
+ // "MOV texSamp, U;" +
13000
+
13001
+ "MUL temp2.z, temp2.z, temp2.w;" +
13002
+ "MUL temp2.z, temp2.z, params7.z;" + // parallax
13003
+
13004
+ "MUL temp2, temp2, temp2.z;" +
13005
+
13006
+ "SUB temp, temp, temp2;" +
13007
+
13008
+ "TEX temp, temp, texture[0], 2D;" +
13009
+ "POW temp.a, temp.a, params6.w;" + // punch through
13010
+
13011
+ "ADD texSamp, temp, texSamp;" +
13012
+ "MUL texSamp.xyz, half, texSamp;" +
13013
+
13014
+ "MOV alpha, texSamp.aaaa;" +
13015
+
13016
+// parallax mapping
13017
+
13018
+ "MOV temp.x, texSamp.a;" +
13019
+ "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
13020
+ //"LRP texSamp0, params5.x, texSamp0, one;" +
13021
+ "MOV texSamp.a, temp.x;" +
1234513022
1234613023 //"MOV temp, fragment.texcoord[0];" +
1234713024 //
....@@ -12471,10 +13148,10 @@
1247113148 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1247213149 "") +
1247313150
12474
- // display shadow only (bump == 0)
13151
+ // display shadow only (fakedepth == 0)
1247513152 "SUB temp.x, half.x, shadow.x;" +
12476
- "MOV temp.y, -params6.x;" +
12477
- "SLT temp.z, temp.y, zero.x;" +
13153
+ "MOV temp.y, -params5.z;" + // params6.x;" +
13154
+ "SLT temp.z, temp.y, -c256i.x;" +
1247813155 "SUB temp.y, one.x, temp.z;" +
1247913156 "MUL temp.x, temp.x, temp.y;" +
1248013157 "KIL temp.x;" +
....@@ -12754,7 +13431,7 @@
1275413431 "MUL final.y, fragment.texcoord[0].x, c256;" +
1275513432 "FLR final.x, final.y;" +
1275613433 "SUB final.y, final.y, final.x;" +
12757
- //"MUL final.x, final.x, c256i;" +
13434
+ "MUL final.x, final.x, c256i;" +
1275813435 "MOV final.z, zero.x;" +
1275913436 "MOV final.a, one.w;":""
1276013437 ) +
....@@ -12762,7 +13439,7 @@
1276213439 "MUL final.y, fragment.texcoord[0].y, c256;" +
1276313440 "FLR final.x, final.y;" +
1276413441 "SUB final.y, final.y, final.x;" +
12765
- //"MUL final.x, final.x, c256i;" +
13442
+ "MUL final.x, final.x, c256i;" +
1276613443 "MOV final.z, zero.x;" +
1276713444 "MOV final.a, one.w;":""
1276813445 ) +
....@@ -12805,8 +13482,19 @@
1280513482 //once = true;
1280613483 }
1280713484
12808
- System.out.print("Program #" + mode + "; length = " + program.length());
12809
- System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13485
+ String program = programmax;
13486
+
13487
+ if (Globals.MINSHADER)
13488
+ {
13489
+ program = programmin;
13490
+ }
13491
+
13492
+ if (Globals.DEBUG)
13493
+ {
13494
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13495
+ System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13496
+ }
13497
+
1281013498 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1281113499
1281213500 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -12853,7 +13541,8 @@
1285313541 "\n" +
1285413542 "END\n";
1285513543
12856
- System.out.println("Program shadow #" + 0 + "; length = " + program.length());
13544
+ if (Globals.DEBUG)
13545
+ System.out.println("Program shadow #" + 0 + "; length = " + program.length());
1285713546 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1285813547
1285913548 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -12898,25 +13587,26 @@
1289813587 return out;
1289913588 }
1290013589
12901
- String TextureFetch(String dest, String src, String unit)
13590
+ // Also does frustum culling
13591
+ String ShadowTextureFetch(String dest, String src, String unit)
1290213592 {
1290313593 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1290413594 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1290513595 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13596
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13597
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1290613598 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12907
- "SLT " + src + ".z, " + src + ".x, one.x;" +
12908
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12909
- "SLT " + src + ".z, " + src + ".y, one.x;" +
12910
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13599
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13600
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1291113601 //"SWZ buffer, temp, w,w,w,w;";
12912
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13602
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1291313603 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1291413604 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1291513605 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
12916
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13606
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1291713607
12918
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
12919
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13608
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13609
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1292013610 }
1292113611
1292213612 String Shadow(String depth, String shadow)
....@@ -12938,12 +13628,16 @@
1293813628
1293913629 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1294013630 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13631
+
13632
+ // Compare fragment depth in light space with shadowmap.
1294113633 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1294213634 "SGE temp.y, temp.x, zero.x;" +
12943
- "SUB " + shadow + ".y, one.x, temp.y;" +
13635
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13636
+
13637
+ // Reverse comparison
1294413638 "SUB temp.x, one.x, temp.x;" +
1294513639 "MUL " + shadow + ".x, temp.x, temp.y;" +
12946
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13640
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1294713641 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1294813642
1294913643 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -12957,6 +13651,10 @@
1295713651 // No shadow for backface
1295813652 "DP3 temp.x, normal, lightd;" +
1295913653 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13654
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13655
+
13656
+ // No shadow when out of frustum
13657
+ "SGE temp.x, " + depth + ".z, one.z;" +
1296013658 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1296113659 "";
1296213660 }
....@@ -13102,8 +13800,9 @@
1310213800 /*static*/ float[] modelParams4 = new float[]{0, 0, 0, 0}; // anisoV, cameralight, selfshadow, shadow
1310313801 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1310413802 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
13105
- /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13106
- Object3D.cVector2[] vector2buffer;
13803
+ /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power, parallax
13804
+
13805
+ //Object3D.cVector2[] vector2buffer;
1310713806
1310813807 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1310913808 // OUT : diff, spec
....@@ -13119,9 +13818,10 @@
1311913818 "DP3 " + dest + ".z," + "normals," + "eye;" +
1312013819 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1312113820 //"MOV " + dest + ".w," + "normal.z;" +
13122
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
13123
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13124
- //"MOV " + dest + ".z," + "params2.w;" +
13821
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13822
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13823
+
13824
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1312513825 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1312613826 "RCP " + dest + ".w," + dest + ".w;" +
1312713827 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13267,7 +13967,7 @@
1326713967 "PARAM p[4] = { state.matrix.projection }; # modelview projection matrix\n" +
1326813968 "PARAM zero = { 0.0, 0.0, 0.0, 1.0 };" +
1326913969 "PARAM half = { 0.5, 0.5, 0.5, 1.0 };" +
13270
- "PARAM one = { 1.0, 1.0, 1.0, 0.0 };" +
13970
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
1327113971 "PARAM two = { 2.0, 2.0, 2.0, 1.0 };" +
1327213972 "PARAM third = { 0.33333333333, 0.33333333333, 0.33333333333, 1.0 };" +
1327313973 //"PARAM v256 = { 256.0, 256.0, 256.0, 1.0 };" +
....@@ -13328,7 +14028,7 @@
1332814028 "DP4 temp.x,state.matrix.texture[0].inverse.row[0],vertex.texcoord;" +
1332914029 "DP4 temp.y,state.matrix.texture[0].inverse.row[1],vertex.texcoord;" +
1333014030 "DP4 temp.z,state.matrix.texture[0].inverse.row[2],vertex.texcoord;" +
13331
- //"MOV result.texcoord, vertex.texcoord;" +
14031
+ //"MOV result.texcoord, vertex.fogcoord;" +
1333214032 "MOV result.texcoord, temp;" +
1333314033 // border fade
1333414034 "MOV result.texcoord[3], vertex.texcoord;" +
....@@ -13375,7 +14075,9 @@
1337514075
1337614076 //"ADD temp.z, temp.z, one;" +
1337714077
13378
- "MOV result.color, temp;"
14078
+ "MOV result.texcoord[4], vertex.attrib[4];" + // U dir
14079
+
14080
+ "MOV result.color, temp;" // Normal
1337914081 : "MOV result.color, vertex.color;") +
1338014082 ((mode & VP_PROJECTION) != 0 ? "MOV result.color, zero;"
1338114083 : "") +
....@@ -13515,7 +14217,7 @@
1351514217 public void mousePressed(MouseEvent e)
1351614218 {
1351714219 //System.out.println("mousePressed: " + e);
13518
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14220
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1351914221 }
1352014222
1352114223 static long prevtime = 0;
....@@ -13591,8 +14293,8 @@
1359114293 // mode |= META;
1359214294 //}
1359314295
13594
- SetMouseMode(WHEEL | e.getModifiersEx());
13595
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14296
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14297
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1359614298 anchorX = ax;
1359714299 anchorY = ay;
1359814300 prevX = px;
....@@ -13626,6 +14328,7 @@
1362614328 else
1362714329 if (evt.getSource() == AAtimer)
1362814330 {
14331
+ Globals.TIMERRUNNING = false;
1362914332 if (mouseDown)
1363014333 {
1363114334 //new Exception().printStackTrace();
....@@ -13651,6 +14354,10 @@
1365114354 // LIVE = waslive;
1365214355 // wasliveok = true;
1365314356 // waslive = false;
14357
+
14358
+ // May 2019 Forget it:
14359
+ if (true)
14360
+ return;
1365414361
1365514362 // source == timer
1365614363 if (mouseDown)
....@@ -13681,7 +14388,7 @@
1368114388
1368214389 // fev 2014???
1368314390 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13684
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14391
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1368514392 pingthread.StepToTarget(true); // true);
1368614393 }
1368714394 // if (!LIVE)
....@@ -13690,12 +14397,13 @@
1369014397
1369114398 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1369214399
13693
- void clickStart(int x, int y, int modifiers)
14400
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1369414401 {
1369514402 if (!wasliveok)
1369614403 return;
1369714404
1369814405 AAtimer.restart(); //
14406
+ Globals.TIMERRUNNING = true;
1369914407
1370014408 // waslive = LIVE;
1370114409 // LIVE = false;
....@@ -13707,7 +14415,7 @@
1370714415 // touched = true; // main DL
1370814416 if (isRenderer)
1370914417 {
13710
- SetMouseMode(modifiers);
14418
+ SetMouseMode(modifiers, modifiersex);
1371114419 }
1371214420
1371314421 selectX = anchorX = x;
....@@ -13720,7 +14428,7 @@
1372014428 clicked = true;
1372114429 hold = false;
1372214430
13723
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14431
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1372414432 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1372514433 {
1372614434 // System.out.println("RESTART II " + modifiers);
....@@ -13745,14 +14453,15 @@
1374514453 drag = false;
1374614454 //System.out.println("Mouse DOWN");
1374714455 editObj = false;
13748
- ClickInfo info = new ClickInfo();
13749
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
13750
- info.pane = this;
13751
- info.camera = renderCamera;
13752
- info.x = x;
13753
- info.y = y;
13754
- info.modifiers = modifiers;
13755
- editObj = object.doEditClick(info, 0);
14456
+ //ClickInfo info = new ClickInfo();
14457
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14458
+ object.clickInfo.pane = this;
14459
+ object.clickInfo.camera = renderCamera;
14460
+ object.clickInfo.x = x;
14461
+ object.clickInfo.y = y;
14462
+ object.clickInfo.modifiers = modifiersex;
14463
+ editObj = object.doEditClick(//info,
14464
+ 0);
1375614465 if (!editObj)
1375714466 {
1375814467 hasMarquee = true;
....@@ -13768,9 +14477,12 @@
1376814477
1376914478 public void mouseDragged(MouseEvent e)
1377014479 {
14480
+ Globals.MOUSEDRAGGED = true;
14481
+
1377114482 //System.out.println("mouseDragged: " + e);
1377214483 if (isRenderer)
1377314484 movingcamera = true;
14485
+
1377414486 //if (drawing)
1377514487 //return;
1377614488 if ((e.getModifiersEx() & CTRL) != 0
....@@ -13780,7 +14492,7 @@
1378014492 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1378114493 }
1378214494 else
13783
- drag(e.getX(), e.getY(), e.getModifiersEx());
14495
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1378414496
1378514497 //try { Thread.sleep(1); } catch (Exception ex) {}
1378614498 }
....@@ -14017,26 +14729,32 @@
1401714729 {
1401814730 Globals.lighttouched = true;
1401914731 }
14020
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14732
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1402114733 }
1402214734 //else
1402314735 }
1402414736 }
1402514737 }
1402614738 PingThread pingthread = new PingThread();
14027
- int delta = 5;
14028
- int speed = 5;
14739
+ int delta = 2;
14740
+ int speed = 10;
1402914741 boolean autorepeat = false;
1403014742
1403114743 void GoDown(int mod)
1403214744 {
1403314745 MODIFIERS |= COMMAND;
14034
- /*
14746
+ boolean isVR = (mouseMode&VR)!=0;
14747
+ /**/
1403514748 if((mod&SHIFT) == SHIFT)
14036
- manipCamera.RotatePosition(0, -speed);
14749
+ {
14750
+ if (isVR)
14751
+ manipCamera.RotateInterest(0, -speed);
14752
+ else
14753
+ manipCamera.RotatePosition(0, -speed);
14754
+ }
1403714755 else
14038
- manipCamera.BackForth(0, -speed*delta, getWidth());
14039
- */
14756
+ manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth());
14757
+ /**/
1404014758 if ((mod & SHIFT) == SHIFT)
1404114759 {
1404214760 mouseMode = mouseMode; // VR??
....@@ -14045,6 +14763,8 @@
1404514763 mouseMode |= BACKFORTH;
1404614764 }
1404714765
14766
+ targetLookAt.set(manipCamera.lookAt);
14767
+
1404814768 //prevX = X = anchorX;
1404914769 prevY = Y = anchorY - (int) (renderCamera.Distance());
1405014770 }
....@@ -14052,12 +14772,19 @@
1405214772 void GoUp(int mod)
1405314773 {
1405414774 MODIFIERS |= COMMAND;
14055
- /*
14775
+ /**/
14776
+ boolean isVR = (mouseMode&VR)!=0;
14777
+
1405614778 if((mod&SHIFT) == SHIFT)
14057
- manipCamera.RotatePosition(0, speed);
14779
+ {
14780
+ if (isVR)
14781
+ manipCamera.RotateInterest(0, speed);
14782
+ else
14783
+ manipCamera.RotatePosition(0, speed);
14784
+ }
1405814785 else
14059
- manipCamera.BackForth(0, speed*delta, getWidth());
14060
- */
14786
+ manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth());
14787
+ /**/
1406114788 if ((mod & SHIFT) == SHIFT)
1406214789 {
1406314790 mouseMode = mouseMode;
....@@ -14066,6 +14793,8 @@
1406614793 mouseMode |= BACKFORTH;
1406714794 }
1406814795
14796
+ targetLookAt.set(manipCamera.lookAt);
14797
+
1406914798 //prevX = X = anchorX;
1407014799 prevY = Y = anchorY + (int) (renderCamera.Distance());
1407114800 }
....@@ -14073,12 +14802,17 @@
1407314802 void GoLeft(int mod)
1407414803 {
1407514804 MODIFIERS |= COMMAND;
14076
- /*
14805
+ /**/
1407714806 if((mod&SHIFT) == SHIFT)
14078
- manipCamera.RotatePosition(speed, 0);
14807
+ manipCamera.Translate(speed*delta, 0, getWidth());
1407914808 else
14080
- manipCamera.Translate(speed*delta, 0, getWidth());
14081
- */
14809
+ {
14810
+ if ((mouseMode&VR)!=0)
14811
+ manipCamera.RotateInterest(-speed, 0);
14812
+ else
14813
+ manipCamera.RotatePosition(speed, 0);
14814
+ }
14815
+ /**/
1408214816 if ((mod & SHIFT) == SHIFT)
1408314817 {
1408414818 mouseMode = mouseMode;
....@@ -14087,6 +14821,8 @@
1408714821 mouseMode |= ROTATE;
1408814822 } // TRANSLATE;
1408914823
14824
+ targetLookAt.set(manipCamera.lookAt);
14825
+
1409014826 prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance());
1409114827 prevY = Y = anchorY;
1409214828 }
....@@ -14094,12 +14830,18 @@
1409414830 void GoRight(int mod)
1409514831 {
1409614832 MODIFIERS |= COMMAND;
14097
- /*
14833
+ /**/
1409814834 if((mod&SHIFT) == SHIFT)
14099
- manipCamera.RotatePosition(-speed, 0);
14835
+ manipCamera.Translate(-speed*delta, 0, getWidth());
1410014836 else
14101
- manipCamera.Translate(-speed*delta, 0, getWidth());
14102
- */
14837
+ {
14838
+ if ((mouseMode&VR)!=0)
14839
+ manipCamera.RotateInterest(speed, 0);
14840
+ else
14841
+ manipCamera.RotatePosition(-speed, 0);
14842
+ }
14843
+
14844
+ /**/
1410314845 if ((mod & SHIFT) == SHIFT)
1410414846 {
1410514847 mouseMode = mouseMode;
....@@ -14108,6 +14850,8 @@
1410814850 mouseMode |= ROTATE;
1410914851 } // TRANSLATE;
1411014852
14853
+ targetLookAt.set(manipCamera.lookAt);
14854
+
1411114855 prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance());
1411214856 prevY = Y = anchorY;
1411314857 }
....@@ -14117,7 +14861,7 @@
1411714861 int X, Y;
1411814862 boolean SX, SY;
1411914863
14120
- void drag(int x, int y, int modifiers)
14864
+ void drag(int x, int y, int modifiers, int modifiersex)
1412114865 {
1412214866 if (IsFrozen())
1412314867 {
....@@ -14126,17 +14870,17 @@
1412614870
1412714871 drag = true; // NEW
1412814872
14129
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14873
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1413014874
1413114875 X = x;
1413214876 Y = y;
1413314877 // floating state for animation
14134
- MODIFIERS = modifiers;
14135
- modifiers &= ~1024;
14878
+ MODIFIERS = modifiersex;
14879
+ modifiersex &= ~1024;
1413614880 if (false) // modifiers != 0)
1413714881 {
1413814882 //new Exception().printStackTrace();
14139
- System.out.println("mouseDragged: " + modifiers);
14883
+ System.out.println("mouseDragged: " + modifiersex);
1414014884 System.out.println("SHIFT = " + SHIFT);
1414114885 System.out.println("CONTROL = " + COMMAND);
1414214886 System.out.println("META = " + META);
....@@ -14149,14 +14893,16 @@
1414914893 if (editObj)
1415014894 {
1415114895 drag = true;
14152
- ClickInfo info = new ClickInfo();
14153
- info.bounds.setBounds(0, 0,
14896
+ //ClickInfo info = new ClickInfo();
14897
+ object.clickInfo.bounds.setBounds(0, 0,
1415414898 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14155
- info.pane = this;
14156
- info.camera = renderCamera;
14157
- info.x = x;
14158
- info.y = y;
14159
- object.editWindow.copy.doEditDrag(info);
14899
+ object.clickInfo.pane = this;
14900
+ object.clickInfo.camera = renderCamera;
14901
+ object.clickInfo.x = x;
14902
+ object.clickInfo.y = y;
14903
+ object //.GetWindow().copy
14904
+ .doEditDrag(//info,
14905
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1416014906 } else
1416114907 {
1416214908 if (x < startX)
....@@ -14305,22 +15051,27 @@
1430515051 }
1430615052 }
1430715053
15054
+// ClickInfo clickInfo = new ClickInfo();
15055
+
1430815056 public void mouseMoved(MouseEvent e)
1430915057 {
1431015058 //System.out.println("mouseMoved: " + e);
1431115059 if (isRenderer)
1431215060 return;
1431315061
14314
- ClickInfo ci = new ClickInfo();
14315
- ci.x = e.getX();
14316
- ci.y = e.getY();
14317
- ci.modifiers = e.getModifiersEx();
14318
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14319
- ci.pane = this;
14320
- ci.camera = renderCamera;
15062
+ // Mouse cursor feedback
15063
+ object.clickInfo.x = e.getX();
15064
+ object.clickInfo.y = e.getY();
15065
+ object.clickInfo.modifiers = e.getModifiersEx();
15066
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
15067
+ object.clickInfo.pane = this;
15068
+ object.clickInfo.camera = renderCamera;
1432115069 if (!isRenderer)
1432215070 {
14323
- if (object.editWindow.copy.doEditClick(ci, 0))
15071
+ //ObjEditor editWindow = object.editWindow;
15072
+ //Object3D copy = editWindow.copy;
15073
+ if (object.doEditClick(//clickInfo,
15074
+ 0))
1432415075 {
1432515076 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1432615077 } else
....@@ -14332,7 +15083,11 @@
1433215083
1433315084 public void mouseReleased(MouseEvent e)
1433415085 {
15086
+ Globals.MOUSEDRAGGED = false;
15087
+
1433515088 movingcamera = false;
15089
+ X = 0; // getBounds().width/2;
15090
+ Y = 0; // getBounds().height/2;
1433615091 //System.out.println("mouseReleased: " + e);
1433715092 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1433815093 }
....@@ -14355,9 +15110,9 @@
1435515110 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1435615111 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1435715112
14358
- if (control || command || IsFrozen())
15113
+// No delay if (control || command || IsFrozen())
1435915114 timeout = true;
14360
- else
15115
+// ?? May 2019 else
1436115116 // timer.setDelay((modifiers & 128) != 0?0:350);
1436215117 mouseDown = false;
1436315118 if (!control && !command) // june 2013
....@@ -14467,7 +15222,7 @@
1446715222 System.out.println("keyReleased: " + e);
1446815223 }
1446915224
14470
- void SetMouseMode(int modifiers)
15225
+ void SetMouseMode(int modifiers, int modifiersex)
1447115226 {
1447215227 //System.out.println("SetMouseMode = " + modifiers);
1447315228 //modifiers &= ~1024;
....@@ -14479,25 +15234,25 @@
1447915234 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1448015235 // return;
1448115236 //System.out.println("SetMode = " + modifiers);
14482
- if ((modifiers & WHEEL) == WHEEL)
15237
+ if ((modifiersex & WHEEL) == WHEEL)
1448315238 {
1448415239 mouseMode |= ZOOM;
1448515240 }
1448615241
1448715242 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
14488
- if (capsLocked || (modifiers & META) == META)
15243
+ if (capsLocked) // || (modifiers & META) == META)
1448915244 {
1449015245 mouseMode |= VR; // BACKFORTH;
1449115246 }
14492
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
15247
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1449315248 {
1449415249 mouseMode |= SELECT;
1449515250 }
14496
- if ((modifiers & COMMAND) == COMMAND)
15251
+ if ((modifiersex & COMMAND) == COMMAND)
1449715252 {
1449815253 mouseMode |= SELECT;
1449915254 }
14500
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15255
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
1450115256 {
1450215257 mouseMode &= ~VR;
1450315258 mouseMode |= TRANSLATE;
....@@ -14526,7 +15281,7 @@
1452615281
1452715282 if (isRenderer) //
1452815283 {
14529
- SetMouseMode(modifiers);
15284
+ SetMouseMode(0, modifiers);
1453015285 }
1453115286
1453215287 Globals.theRenderer.keyPressed(key);
....@@ -14588,7 +15343,8 @@
1458815343 // break;
1458915344 case 'T':
1459015345 CACHETEXTURE ^= true;
14591
- textures.clear();
15346
+ texturepigment.clear();
15347
+ texturebump.clear();
1459215348 // repaint();
1459315349 break;
1459415350 case 'Y':
....@@ -14598,8 +15354,8 @@
1459815354 case 'K':
1459915355 KOMPACTTEXTURE ^= true;
1460015356 //textures.clear();
14601
- break;
14602
- case 'P': // Texture Projection macros
15357
+ // break;
15358
+ //case 'P': // Texture Projection macros
1460315359 // SAVETEXTURE ^= true;
1460415360 macromode = true;
1460515361 Udebug = Vdebug = NORMALdebug = false; programInitialized = false;
....@@ -14673,7 +15429,9 @@
1467315429 case 'E' : COMPACT ^= true;
1467415430 repaint();
1467515431 break;
14676
- case 'W' : DEBUGHSB ^= true;
15432
+ case 'W' : // Wide Window (fullscreen)
15433
+ //DEBUGHSB ^= true;
15434
+ ObjEditor.theFrame.ToggleFullScreen();
1467715435 repaint();
1467815436 break;
1467915437 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14698,8 +15456,8 @@
1469815456 RevertCamera();
1469915457 repaint();
1470015458 break;
14701
- case 'L':
1470215459 case 'l':
15460
+ //case 'L':
1470315461 if (lightMode)
1470415462 {
1470515463 lightMode = false;
....@@ -14718,7 +15476,7 @@
1471815476 targetLookAt.set(manipCamera.lookAt);
1471915477 repaint();
1472015478 break;
14721
- case 'p':
15479
+ case 'P': // p':
1472215480 // c'est quoi ca au juste? spherical ^= true;
1472315481 Skinshader ^= true; programInitialized = false;
1472415482 repaint();
....@@ -14756,27 +15514,31 @@
1475615514 repaint();
1475715515 break;
1475815516 case 'O':
14759
- Globals.drawMode = OCCLUSION; // WARNING
15517
+ // Too dangerous. Use menu. Globals.drawMode = OCCLUSION; // WARNING
1476015518 repaint();
1476115519 break;
1476215520 case 'o':
1476315521 OCCLUSION_CULLING ^= true;
1476415522 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1476515523 break;
14766
- case '0': envyoff ^= true; repaint(); break;
15524
+ //case '0': envyoff ^= true; repaint(); break;
1476715525 case '1':
1476815526 case '2':
1476915527 case '3':
1477015528 case '4':
1477115529 case '5':
14772
- newenvy = Character.getNumericValue(key);
14773
- repaint();
14774
- break;
1477515530 case '6':
1477615531 case '7':
1477715532 case '8':
1477815533 case '9':
14779
- BGcolor = (key - '6')/3.f;
15534
+ if (true) // envyoff)
15535
+ {
15536
+ BGcolor = (key - '1')/8.f;
15537
+ }
15538
+ else
15539
+ {
15540
+ //newenvy = Character.getNumericValue(key);
15541
+ }
1478015542 repaint();
1478115543 break;
1478215544 case '!':
....@@ -14842,9 +15604,9 @@
1484215604 case '_':
1484315605 kompactbit = 5;
1484415606 break;
14845
- case '+':
14846
- kompactbit = 6;
14847
- break;
15607
+// case '+':
15608
+// kompactbit = 6;
15609
+// break;
1484815610 case ' ':
1484915611 lightMode ^= true;
1485015612 Globals.lighttouched = true;
....@@ -14856,13 +15618,14 @@
1485615618 case ESC:
1485715619 RENDERPROGRAM += 1;
1485815620 RENDERPROGRAM %= 3;
15621
+
1485915622 repaint();
1486015623 break;
1486115624 case 'Z':
1486215625 //RESIZETEXTURE ^= true;
1486315626 //break;
1486415627 case 'z':
14865
- RENDERSHADOW ^= true;
15628
+ Globals.RENDERSHADOW ^= true;
1486615629 Globals.lighttouched = true;
1486715630 repaint();
1486815631 break;
....@@ -14895,8 +15658,9 @@
1489515658 case DELETE:
1489615659 ClearSelection();
1489715660 break;
14898
- /*
1489915661 case '+':
15662
+
15663
+ /*
1490015664 //fontsize += 1;
1490115665 bbzoom *= 2;
1490215666 repaint();
....@@ -14913,17 +15677,17 @@
1491315677 case '=':
1491415678 IncDepth();
1491515679 //fontsize += 1;
14916
- object.editWindow.refreshContents(true);
15680
+ object.GetWindow().refreshContents(true);
1491715681 maskbit = 6;
1491815682 break;
1491915683 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1492015684 DecDepth();
1492115685 maskbit = 5;
1492215686 //if(fontsize > 1) fontsize -= 1;
14923
- if (object.editWindow == null)
14924
- new Exception().printStackTrace();
14925
- else
14926
- object.editWindow.refreshContents(true);
15687
+// if (object.editWindow == null)
15688
+// new Exception().printStackTrace();
15689
+// else
15690
+ object.GetWindow().refreshContents(true);
1492715691 break;
1492815692 case '{':
1492915693 manipCamera.shaper_fovy /= 1.1;
....@@ -14986,7 +15750,7 @@
1498615750 //mode = ROTATE;
1498715751 if ((MODIFIERS & COMMAND) == 0) // VR??
1498815752 {
14989
- SetMouseMode(modifiers);
15753
+ SetMouseMode(0, modifiers);
1499015754 }
1499115755 }
1499215756
....@@ -15122,7 +15886,7 @@
1512215886 {
1512315887 //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
1512415888 //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15125
- if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (mouseMode & SELECT) == 0)
15889
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1512615890 {
1512715891 mouseMoved(e);
1512815892 } else
....@@ -15147,7 +15911,7 @@
1514715911 }
1514815912 */
1514915913
15150
- object.editWindow.EditSelection();
15914
+ object.GetWindow().EditSelection(false);
1515115915 }
1515215916
1515315917 void SelectParent()
....@@ -15164,10 +15928,10 @@
1516415928 {
1516515929 //selectees.remove(i);
1516615930 System.out.println("select parent of " + elem);
15167
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15931
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1516815932 } else
1516915933 {
15170
- group.editWindow.Select(elem.GetTreePath(), first, true);
15934
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1517115935 }
1517215936
1517315937 first = false;
....@@ -15209,12 +15973,12 @@
1520915973 for (int j = 0; j < group.children.size(); j++)
1521015974 {
1521115975 elem = (Object3D) group.children.elementAt(j);
15212
- object.editWindow.Select(elem.GetTreePath(), first, true);
15976
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1521315977 first = false;
1521415978 }
1521515979 } else
1521615980 {
15217
- object.editWindow.Select(elem.GetTreePath(), first, true);
15981
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1521815982 }
1521915983
1522015984 first = false;
....@@ -15225,21 +15989,21 @@
1522515989 {
1522615990 //Composite group = (Composite) object;
1522715991 Object3D group = object;
15228
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15992
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1522915993 }
1523015994
1523115995 void ResetTransform(int mask)
1523215996 {
1523315997 //Composite group = (Composite) object;
1523415998 Object3D group = object;
15235
- group.editWindow.ResetTransform(mask);
15999
+ group.GetWindow().ResetTransform(mask);
1523616000 }
1523716001
1523816002 void FlipTransform()
1523916003 {
1524016004 //Composite group = (Composite) object;
1524116005 Object3D group = object;
15242
- group.editWindow.FlipTransform();
16006
+ group.GetWindow().FlipTransform();
1524316007 // group.editWindow.ReduceMesh(true);
1524416008 }
1524516009
....@@ -15247,7 +16011,7 @@
1524716011 {
1524816012 //Composite group = (Composite) object;
1524916013 Object3D group = object;
15250
- group.editWindow.PrintMemory();
16014
+ group.GetWindow().PrintMemory();
1525116015 // group.editWindow.ReduceMesh(true);
1525216016 }
1525316017
....@@ -15255,7 +16019,7 @@
1525516019 {
1525616020 //Composite group = (Composite) object;
1525716021 Object3D group = object;
15258
- group.editWindow.ResetCentroid();
16022
+ group.GetWindow().ResetCentroid();
1525916023 }
1526016024
1526116025 void IncDepth()
....@@ -15337,11 +16101,11 @@
1533716101
1533816102 int width = getBounds().width;
1533916103 int height = getBounds().height;
15340
- ClickInfo info = new ClickInfo();
15341
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1534216104 //Image img = CreateImage(width, height);
1534316105 //System.out.println("width = " + width + "; height = " + height + "\n");
16106
+
1534416107 Graphics gr = g; // img.getGraphics();
16108
+
1534516109 if (!hasMarquee)
1534616110 {
1534716111 if (Xmin < Xmax) // !locked)
....@@ -15413,44 +16177,92 @@
1541316177 }
1541416178 if (object != null && !hasMarquee)
1541516179 {
16180
+ if (object.clickInfo == null)
16181
+ object.clickInfo = new ClickInfo();
16182
+ ClickInfo info = object.clickInfo;
16183
+ //ClickInfo info = new ClickInfo();
16184
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16185
+
1541616186 if (isRenderer)
1541716187 {
15418
- info.flags++;
16188
+ object.clickInfo.flags++;
1541916189 double frameAspect = (double) width / (double) height;
1542016190 if (frameAspect > renderCamera.aspect)
1542116191 {
1542216192 int desired = (int) ((double) height * renderCamera.aspect);
15423
- info.bounds.width -= width - desired;
15424
- info.bounds.x += (width - desired) / 2;
16193
+ object.clickInfo.bounds.width -= width - desired;
16194
+ object.clickInfo.bounds.x += (width - desired) / 2;
1542516195 } else
1542616196 {
1542716197 int desired = (int) ((double) width / renderCamera.aspect);
15428
- info.bounds.height -= height - desired;
15429
- info.bounds.y += (height - desired) / 2;
16198
+ object.clickInfo.bounds.height -= height - desired;
16199
+ object.clickInfo.bounds.y += (height - desired) / 2;
1543016200 }
1543116201 }
15432
- info.g = gr;
15433
- info.camera = renderCamera;
16202
+
16203
+ object.clickInfo.g = gr;
16204
+ object.clickInfo.camera = renderCamera;
1543416205 /*
1543516206 // Memory intensive (brep.verticescopy)
1543616207 if (!(object instanceof Composite))
1543716208 object.draw(info, 0, false); // SLOW :
1543816209 */
15439
- if (!isRenderer)
16210
+ if (!isRenderer) // && drag)
1544016211 {
15441
- object.drawEditHandles(info, 0);
16212
+ Grafreed.Assert(object != null);
16213
+ Grafreed.Assert(object.selection != null);
16214
+ if (object.selection.Size() > 0)
16215
+ {
16216
+ int hitSomething = object.selection.get(0).hitSomething;
16217
+
16218
+ object.clickInfo.DX = 0;
16219
+ object.clickInfo.DY = 0;
16220
+ object.clickInfo.W = 1;
16221
+ if (hitSomething == Object3D.hitCenter)
16222
+ {
16223
+ info.DX = X;
16224
+ if (X != 0)
16225
+ info.DX -= info.bounds.width/2;
16226
+
16227
+ info.DY = Y;
16228
+ if (Y != 0)
16229
+ info.DY -= info.bounds.height/2;
16230
+ }
16231
+
16232
+ object.drawEditHandles(//info,
16233
+ 0);
16234
+
16235
+ if (drag && (X != 0 || Y != 0))
16236
+ {
16237
+ switch (hitSomething)
16238
+ {
16239
+ case Object3D.hitCenter: gr.setColor(Color.white);
16240
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16241
+ break;
16242
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16243
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16244
+ break;
16245
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16246
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16247
+ break;
16248
+ }
16249
+
16250
+ }
16251
+ }
1544216252 }
1544316253 }
16254
+
1544416255 if (isRenderer)
1544516256 {
1544616257 //gr.setColor(Color.black);
1544716258 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1544816259 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1544916260 }
16261
+
1545016262 if (hasMarquee)
1545116263 {
1545216264 gr.setXORMode(Color.white);
15453
- gr.setColor(Color.red);
16265
+ gr.setColor(Color.white);
1545416266 if (!firstime)
1545516267 {
1545616268 gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH);
....@@ -15559,6 +16371,7 @@
1555916371 public boolean mouseDown(Event evt, int x, int y)
1556016372 {
1556116373 System.out.println("mouseDown: " + evt);
16374
+ System.exit(0);
1556216375 /*
1556316376 locked = true;
1556416377 drag = false;
....@@ -15602,7 +16415,7 @@
1560216415 {
1560316416 keyPressed(0, modifiers);
1560416417 }
15605
- clickStart(x, y, modifiers);
16418
+ // clickStart(x, y, modifiers);
1560616419 return true;
1560716420 }
1560816421
....@@ -15720,7 +16533,7 @@
1572016533 {
1572116534 keyReleased(0, 0);
1572216535 }
15723
- drag(x, y, modifiers);
16536
+ drag(x, y, 0, modifiers);
1572416537 return true;
1572516538 }
1572616539
....@@ -15852,7 +16665,7 @@
1585216665 Object3D object;
1585316666 static Object3D trackedobject;
1585416667 Camera renderCamera; // Light or Eye (or Occlusion)
15855
- /*static*/ Camera manipCamera; // Light or Eye
16668
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1585616669 /*static*/ Camera eyeCamera;
1585716670 /*static*/ Camera lightCamera;
1585816671 int cameracount;
....@@ -15916,6 +16729,8 @@
1591616729 private /*static*/ boolean firstime;
1591716730 private /*static*/ cVector newView = new cVector();
1591816731 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16732
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16733
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1591916734 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1592016735 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1592116736 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -15928,29 +16743,67 @@
1592816743 {
1592916744 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1593016745
16746
+ int usedsuf = 0;
16747
+
1593116748 for (int i = 0; i < suffixes.length; i++)
1593216749 {
15933
- String resourceName = basename + suffixes[i] + "." + suffix;
15934
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
15935
- mipmapped,
15936
- FileUtil.getFileSuffix(resourceName));
15937
- if (data == null)
16750
+ String[] suffixe = suffixes;
16751
+ String[] fallback = suffixes2;
16752
+ String[] fallfallback = suffixes3;
16753
+
16754
+ for (int c=usedsuf; --c>=0;)
1593816755 {
15939
- throw new IOException("Unable to load texture " + resourceName);
16756
+// String[] temp = suffixe;
16757
+// suffixe = fallback;
16758
+// fallback = fallfallback;
16759
+// fallfallback = temp;
1594016760 }
16761
+
16762
+ String resourceName = basename + suffixe[i] + "." + suffix;
16763
+ TextureData data;
16764
+
16765
+ try
16766
+ {
16767
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16768
+ mipmapped,
16769
+ FileUtil.getFileSuffix(resourceName));
16770
+ }
16771
+ catch (Exception e)
16772
+ {
16773
+ try
16774
+ {
16775
+ resourceName = basename + fallback[i] + "." + suffix;
16776
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16777
+ mipmapped,
16778
+ FileUtil.getFileSuffix(resourceName));
16779
+ }
16780
+ catch (Exception e2)
16781
+ {
16782
+ resourceName = basename + fallfallback[i] + "." + suffix;
16783
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16784
+ mipmapped,
16785
+ FileUtil.getFileSuffix(resourceName));
16786
+ }
16787
+ }
16788
+
1594116789 //System.out.println("Target = " + targets[i]);
1594216790 cubemap.updateImage(data, targets[i]);
1594316791 }
1594416792
1594516793 return cubemap;
1594616794 }
16795
+
1594716796 int bigsphere = -1;
1594816797
1594916798 float BGcolor = 0.5f;
1595016799
15951
- private void DrawSkyBox(GL gl)
16800
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16801
+
16802
+ private void DrawSkyBox(GL gl, float ratio)
1595216803 {
15953
- if (envyoff || cubemap == null)
16804
+ if (//envyoff ||
16805
+ WIREFRAME ||
16806
+ cubemap == null)
1595416807 {
1595516808 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1595616809 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -15965,7 +16818,17 @@
1596516818 // Compensates for ExaminerViewer's modification of modelview matrix
1596616819 gl.glMatrixMode(GL.GL_MODELVIEW);
1596716820 gl.glLoadIdentity();
16821
+ gl.glScalef(1,ratio,1);
1596816822
16823
+// colorV[0] = 2;
16824
+// colorV[1] = 2;
16825
+// colorV[2] = 2;
16826
+// colorV[3] = 1;
16827
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16828
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16829
+//
16830
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16831
+
1596916832 //gl.glActiveTexture(GL.GL_TEXTURE1);
1597016833 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1597116834
....@@ -15997,6 +16860,7 @@
1599716860 {
1599816861 gl.glScalef(1.0f, -1.0f, 1.0f);
1599916862 }
16863
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1600016864 gl.glMultMatrixd(viewrot_1, 0);
1600116865 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1600216866 //viewer.updateInverseRotation(gl);
....@@ -16037,7 +16901,8 @@
1603716901 gl.glDisable(GL.GL_TEXTURE_GEN_R);
1603816902
1603916903 cubemap.disable();
16040
- ////cubemap.unbind();
16904
+ //cubemap.dispose();
16905
+
1604116906 if (CULLFACE)
1604216907 {
1604316908 gl.glEnable(gl.GL_CULL_FACE);
....@@ -16093,7 +16958,7 @@
1609316958 gl.glScalef(1.0f, -1.0f, 1.0f);
1609416959 }
1609516960
16096
- gl.glNormal3f(0.0f, 0.0f, 1.0f);
16961
+ SetGLNormal(gl, 0.0f, 0.0f, 1.0f);
1609716962
1609816963 float step = 2; // 0.1666f; //0.25f;
1609916964 float stepv = 2; // step * 1652 / 998;
....@@ -16137,16 +17002,16 @@
1613717002 cStatic.objectstack[materialdepth++] = checker;
1613817003 //System.out.println("material " + material);
1613917004 //Applet3D.tracein(this, selected);
16140
- vector2buffer = checker.projectedVertices;
17005
+ //vector2buffer = checker.projectedVertices;
1614117006
1614217007 //checker.GetMaterial().Draw(this, false); // true);
16143
- DrawMaterial(checker.GetMaterial(), false); // true);
17008
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1614417009
1614517010 materialdepth -= 1;
1614617011 if (materialdepth > 0)
1614717012 {
16148
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16149
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
17013
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
17014
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1615017015 }
1615117016 //checker.GetMaterial().opacity = 1f;
1615217017 ////checker.GetMaterial().ambient = 1f;
....@@ -16232,6 +17097,14 @@
1623217097 }
1623317098 }
1623417099
17100
+ private Object3D GetFolder()
17101
+ {
17102
+ Object3D folder = object.GetWindow().copy;
17103
+ if (object.GetWindow().copy.selection.Size() > 0)
17104
+ folder = object.GetWindow().copy.selection.elementAt(0);
17105
+ return folder;
17106
+ }
17107
+
1623517108 class SelectBuffer implements GLEventListener
1623617109 {
1623717110
....@@ -16247,7 +17120,7 @@
1624717120 //new Exception().printStackTrace();
1624817121 System.out.println("select buffer init");
1624917122 // Use debug pipeline
16250
- drawable.setGL(new DebugGL(drawable.getGL()));
17123
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1625117124
1625217125 GL gl = drawable.getGL();
1625317126
....@@ -16311,6 +17184,17 @@
1631117184
1631217185 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1631317186
17187
+ if (PAINTMODE)
17188
+ {
17189
+ if (object.GetWindow().copy.selection.Size() > 0)
17190
+ {
17191
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17192
+
17193
+ // Make what you paint not selectable.
17194
+ paintobj.ResetSelectable();
17195
+ }
17196
+ }
17197
+
1631417198 //int tmp = selection_view;
1631517199 //selection_view = -1;
1631617200 int temp = DrawMode();
....@@ -16322,6 +17206,17 @@
1632217206 // temp = DEFAULT; // patch for selection debug
1632317207 Globals.drawMode = temp; // WARNING
1632417208
17209
+ if (PAINTMODE)
17210
+ {
17211
+ if (object.GetWindow().copy.selection.Size() > 0)
17212
+ {
17213
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17214
+
17215
+ // Revert.
17216
+ paintobj.RestoreSelectable();
17217
+ }
17218
+ }
17219
+
1632517220 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1632617221
1632717222 // trying different ways of getting the depth info over
....@@ -16369,6 +17264,8 @@
1636917264 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1637017265 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1637117266 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
17267
+
17268
+ CreateSelectedPoint();
1637217269
1637317270 // Will fit the mesh !!!
1637417271 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16418,34 +17315,36 @@
1641817315 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]));
1641917316 }
1642017317
16421
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
17318
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1642217319 }
1642317320 }
1642417321
1642517322 if (!movingcamera && !PAINTMODE)
16426
- object.editWindow.ScreenFitPoint(); // fev 2014
17323
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1642717324
16428
- if (PAINTMODE && GrafreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17325
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1642917326 {
16430
- Object3D paintobj = GrafreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17327
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1643117328
16432
- Object3D group = new Object3D("inst" + paintcount++);
17329
+ if (object.GetWindow().copy.selection.Size() > 0)
17330
+ {
17331
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1643317332
16434
- group.CreateMaterial(); // use a void leaf to select instances
16435
-
16436
- group.add(paintobj); // link
16437
-
16438
- object.editWindow.SnapObject(group);
16439
-
16440
- Object3D folder = object.editWindow.copy;
16441
-
16442
- if (object.editWindow.copy.selection.Size() > 0)
16443
- folder = object.editWindow.copy.selection.elementAt(0);
16444
-
16445
- folder.add(group);
16446
-
16447
- object.editWindow.ResetModel();
16448
- object.editWindow.refreshContents();
17333
+ Object3D inst = new Object3D("inst" + paintcount++);
17334
+
17335
+ inst.CreateMaterial(); // use a void leaf to select instances
17336
+
17337
+ inst.add(paintobj); // link
17338
+
17339
+ object.GetWindow().SnapObject(inst);
17340
+
17341
+ Object3D folder = paintFolder; // GetFolder();
17342
+
17343
+ folder.add(inst);
17344
+
17345
+ object.GetWindow().ResetModel();
17346
+ object.GetWindow().refreshContents();
17347
+ }
1644917348 }
1645017349 else
1645117350 paintcount = 0;
....@@ -16484,6 +17383,11 @@
1648417383 //System.out.println("objects[color] = " + objects[color]);
1648517384 //objects[color].Select();
1648617385 indexcount = 0;
17386
+ ObjEditor window = object.GetWindow();
17387
+ if (window != null && deselect)
17388
+ {
17389
+ window.Select(null, deselect, true);
17390
+ }
1648717391 object.Select(color, deselect);
1648817392 }
1648917393
....@@ -16534,6 +17438,7 @@
1653417438
1653517439 public void init(GLAutoDrawable drawable)
1653617440 {
17441
+ if (Globals.DEBUG)
1653717442 System.out.println("shadow buffer init");
1653817443
1653917444 GL gl = drawable.getGL();
....@@ -16583,7 +17488,7 @@
1658317488 gl.glDisable(gl.GL_CULL_FACE);
1658417489 }
1658517490
16586
- if (!RENDERSHADOW)
17491
+ if (!Globals.RENDERSHADOW)
1658717492 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1658817493
1658917494 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -16593,7 +17498,7 @@
1659317498 //gl.glColorMask(false, false, false, false);
1659417499
1659517500 //render_scene_from_light_view(gl, drawable, 0, 0);
16596
- if (RENDERSHADOW && Globals.lighttouched && !movingcamera) // && !parent.IsFreezed())
17501
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1659717502 {
1659817503 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1659917504
....@@ -16762,10 +17667,14 @@
1676217667 gl.glFlush();
1676317668
1676417669 /**/
16765
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17670
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1676617671
16767
- float[] pixels = occlusionsizebuffer.array();
17672
+ float[] depths = occlusiondepthbuffer.array();
1676817673
17674
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17675
+
17676
+ int[] pixels = selectsizebuffer.array();
17677
+
1676917678 double r = 0, g = 0, b = 0;
1677017679
1677117680 double count = 0;
....@@ -16776,7 +17685,7 @@
1677617685
1677717686 double FACTOR = 1;
1677817687
16779
- for (int i = 0; i < pixels.length; i++)
17688
+ for (int i = 0; i < depths.length; i++)
1678017689 {
1678117690 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1678217691 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -16859,7 +17768,7 @@
1685917768
1686017769 double scale = ray.z; // 1; // cos
1686117770
16862
- float depth = pixels[newindex];
17771
+ float depth = depths[newindex];
1686317772
1686417773 /*
1686517774 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -17009,23 +17918,15 @@
1700917918 int AAbuffersize = 0;
1701017919
1701117920 //double[] selectedpoint = new double[3];
17012
- static Superellipsoid selectedpoint = new Superellipsoid();
17921
+ static Superellipsoid selectedpoint;
1701317922 static Sphere previousselectedpoint = null;
17014
- static Sphere debugpointG = new Sphere();
17015
- static Sphere debugpointP = new Sphere();
17016
- static Sphere debugpointC = new Sphere();
17017
- static Sphere debugpointR = new Sphere();
17923
+ static Sphere debugpointG;
17924
+ static Sphere debugpointP;
17925
+ static Sphere debugpointC;
17926
+ static Sphere debugpointR;
1701817927
1701917928 static Sphere debugpoints[] = new Sphere[8];
1702017929
17021
- static
17022
- {
17023
- for (int i=0; i<8; i++)
17024
- {
17025
- debugpoints[i] = new Sphere();
17026
- }
17027
- }
17028
-
1702917930 static void InitPoints(float radius)
1703017931 {
1703117932 for (int i=0; i<8; i++)
....@@ -17064,11 +17965,14 @@
1706417965 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1706517966 static IntBuffer bigAAbuffer;
1706617967 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
17067
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17968
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1706817969 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1706917970 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1707017971 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17071
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17972
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17973
+
17974
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17975
+
1707217976 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1707317977 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1707417978 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();