Normand Briere
2019-08-22 6a145f6c81dfcbe0653eda27d042efb48daa7512
CameraPane.java
....@@ -18,7 +18,10 @@
1818 import javax.imageio.ImageIO;
1919 import javax.imageio.ImageWriteParam;
2020 import javax.imageio.ImageWriter;
21
+import javax.imageio.ImageReadParam;
22
+import javax.imageio.ImageReader;
2123 import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
24
+import javax.imageio.stream.ImageInputStream;
2225 import javax.imageio.stream.ImageOutputStream;
2326 import javax.imageio.ImageWriteParam;
2427
....@@ -30,6 +33,7 @@
3033 import java.nio.*;
3134
3235 import gleem.linalg.Mat4f;
36
+import javax.imageio.ImageTypeSpecifier;
3337
3438 class CameraPane extends GLCanvas implements iCameraPane, Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener
3539 {
....@@ -37,7 +41,6 @@
3741 static boolean[] selectedstack = new boolean[65536];
3842 static int materialdepth = 0;
3943
40
- static boolean DEBUG = false;
4144 static boolean FRUSTUM = false; // still bogus true; // frustum culling
4245
4346 // camera change fix
....@@ -45,6 +48,39 @@
4548 static boolean ABORTED = false;
4649
4750 static int STEP = 1;
51
+
52
+ private static BufferedImage CreateBim(byte[] bytes, int width, int height)
53
+ {
54
+ int[] pixels = new int[bytes.length/3];
55
+ for (int i=pixels.length; --i>=0;)
56
+ {
57
+ int i3 = i*3;
58
+ pixels[i] = 0xFF;
59
+ pixels[i] <<= 8;
60
+ pixels[i] |= bytes[i3+2] & 0xFF;
61
+ pixels[i] <<= 8;
62
+ pixels[i] |= bytes[i3+1] & 0xFF;
63
+ pixels[i] <<= 8;
64
+ pixels[i] |= bytes[i3] & 0xFF;
65
+ }
66
+ /*
67
+ int r=0,g=0,b=0,a=0;
68
+ for (int i=0; i<width; i++)
69
+ for (int j=0; j<height; j++)
70
+ {
71
+ int index = j*width+i;
72
+ int p = pixels[index];
73
+ a = ((p>>24) & 0xFF);
74
+ r = ((p>>16) & 0xFF);
75
+ g = ((p>>8) & 0xFF);
76
+ b = (p & 0xFF);
77
+ pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
78
+ }
79
+ /**/
80
+ BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
81
+ rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
82
+ return rendImage;
83
+ }
4884
4985 /*static*/ private boolean CULLFACE = false; // true;
5086 /*static*/ boolean NEAREST = false; // true;
....@@ -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)
....@@ -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,76 @@
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 zero123 = { 0.0, 1.0, 2, 1.25 };" +
12518
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12519
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12520
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12521
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12522
+ "PARAM light2cam0 = program.env[10];" +
12523
+ "PARAM light2cam1 = program.env[11];" +
12524
+ "PARAM light2cam2 = program.env[12];" +
12525
+ "TEMP temp;" +
12526
+ "TEMP light;" +
12527
+ "TEMP ndotl;" +
12528
+ "TEMP normal;" +
12529
+ "TEMP depth;" +
12530
+ "TEMP eye;" +
12531
+ "TEMP pos;" +
12532
+
12533
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12534
+ Normalize("normal") +
12535
+ "MOV light, state.light[0].position;" +
12536
+ "DP3 ndotl.x, light, normal;" +
12537
+
12538
+ // shadow
12539
+ "MOV pos, fragment.texcoord[1];" +
12540
+ "MOV temp, pos;" +
12541
+ ShadowTextureFetch("depth", "temp", "1") +
12542
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12543
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12544
+
12545
+ // No shadow when out of frustum
12546
+ //"SGE temp.y, depth.z, zero123.y;" +
12547
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12548
+
12549
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12550
+
12551
+ // Backlit
12552
+ "MOV pos.w, zero123.y;" +
12553
+ "DP4 eye.x, pos, light2cam0;" +
12554
+ "DP4 eye.y, pos, light2cam1;" +
12555
+ "DP4 eye.z, pos, light2cam2;" +
12556
+ Normalize("eye") +
12557
+
12558
+ "DP3 ndotl.y, -eye, normal;" +
12559
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12560
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12561
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12562
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12563
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12564
+
12565
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12566
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12567
+
12568
+ // Pigment
12569
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12570
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12571
+ "MUL temp, temp, ndotl.x;" +
12572
+
12573
+ "MUL temp, temp, zero123.z;" +
12574
+
12575
+ //"MUL temp, temp, ndotl.y;" +
12576
+
12577
+ "MOV temp.w, zero123.y;" + // reset alpha
12578
+ "MOV result.color, temp;" +
12579
+ "END";
12580
+
12581
+ String programmax =
12582
+ "!!ARBfp1.0\n" +
12583
+
1195412584 //"OPTION ARB_fragment_program_shadow;" +
1195512585 "PARAM light2cam0 = program.env[10];" +
1195612586 "PARAM light2cam1 = program.env[11];" +
....@@ -11976,7 +12606,7 @@
1197612606 "PARAM params4 = program.env[4];" + // anisoV, cameralight, selfshadow, shadow
1197712607 "PARAM params5 = program.env[5];" + // texture, opacity, fakedepth, shadowbias
1197812608 "PARAM params6 = program.env[6];" + // bump, noise, borderfade, fog punchthrough
11979
- "PARAM params7 = program.env[7];" + // noise power, opacity power
12609
+ "PARAM params7 = program.env[7];" + // noise power, opacity power, parallax
1198012610 "PARAM options0 = program.env[63];" + // fog density, intensity, elevation
1198112611 "PARAM options1 = program.env[62];" + // fog rgb color
1198212612 "PARAM options2 = program.env[61];" + // image intensity, subsurface, lightsheen
....@@ -12065,8 +12695,7 @@
1206512695 "TEMP shininess;" +
1206612696 "\n" +
1206712697 "MOV texSamp, one;" +
12068
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12069
-
12698
+
1207012699 "MOV mapgrid.x, one2048th.x;" +
1207112700 "MOV temp, fragment.texcoord[1];" +
1207212701 /*
....@@ -12087,20 +12716,20 @@
1208712716 "MUL temp, floor, mapgrid.x;" +
1208812717 //"TEX depth0, temp, texture[1], 2D;" +
1208912718 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12090
- TextureFetch("depth0", "temp", "1") +
12719
+ ShadowTextureFetch("depth0", "temp", "1") +
1209112720 "") +
1209212721 "ADD temp.x, temp.x, mapgrid.x;" +
1209312722 //"TEX depth1, temp, texture[1], 2D;" +
1209412723 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12095
- TextureFetch("depth1", "temp", "1") +
12724
+ ShadowTextureFetch("depth1", "temp", "1") +
1209612725 "") +
1209712726 "ADD temp.y, temp.y, mapgrid.x;" +
1209812727 //"TEX depth2, temp, texture[1], 2D;" +
12099
- TextureFetch("depth2", "temp", "1") +
12728
+ ShadowTextureFetch("depth2", "temp", "1") +
1210012729 "SUB temp.x, temp.x, mapgrid.x;" +
1210112730 //"TEX depth3, temp, texture[1], 2D;" +
1210212731 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12103
- TextureFetch("depth3", "temp", "1") +
12732
+ ShadowTextureFetch("depth3", "temp", "1") +
1210412733 "") +
1210512734 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1210612735 //"MOV params, material;" +
....@@ -12222,7 +12851,7 @@
1222212851 "POW texSamp.a, texSamp.a, params6.w;" + // fog punch through shortcut
1222312852 // mar 2013 ??? "KIL alpha.a;" +
1222412853 "MOV alpha, texSamp.aaaa;" + // y;" +
12225
- "KIL alpha.a;" +
12854
+ "KIL alpha.a;" + // not sure with parallax mapping
1222612855 /*
1222712856 "MUL temp.xy, temp, two;" +
1222812857 "TXB bump, temp, texture[0], 2D;" +
....@@ -12308,11 +12937,6 @@
1230812937 "SUB bump0, bump0, half;" +
1230912938 "ADD bump, bump, bump0;" +
1231012939
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
-
1231612940 // double-sided
1231712941 /**/
1231812942 (doublesided?"DP3 temp.z, normal, eye;" +
....@@ -12329,19 +12953,62 @@
1232912953 "MOV normald, normal;" +
1233012954 "MOV normals, normal;" +
1233112955
12956
+ "MOV temp, fragment.texcoord[4];" +
12957
+
1233212958 // UV base
1233312959 //"DP3 UP.x,state.matrix.modelview.row[0],Y;" +
1233412960 //"DP3 UP.y,state.matrix.modelview.row[1],Y;" +
1233512961 //"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;" +
12962
+ "DP3 UP.x,state.matrix.texture[7].row[0],temp;" +
12963
+ "DP3 UP.y,state.matrix.texture[7].row[1],temp;" +
12964
+ "DP3 UP.z,state.matrix.texture[7].row[2],temp;" +
12965
+ Normalize("UP") +
12966
+
1233912967 "XPD V, normal, UP;" +
1234012968 Normalize("V") +
1234112969 "XPD U, V, normal;" +
1234212970 Normalize("U") +
1234312971
1234412972 // parallax mapping
12973
+
12974
+ "DP3 temp2.x, V, eye;" +
12975
+ "DP3 temp2.y, U, eye;" +
12976
+ "DP3 temp2.z, normal, eye;" +
12977
+ "RCP temp2.z, temp2.z;" +
12978
+
12979
+ "DP3 temp2.w, texSamp, texSamp;" + // Height
12980
+ "RSQ temp2.w, temp2.w;" +
12981
+ "RCP temp2.w, temp2.w;" +
12982
+
12983
+ "SUB temp2.w, temp2.w, half;" +
12984
+// "SGE temp.x, temp2.w, eps.x;" +
12985
+// "MUL temp2.w, temp2.w, temp.x;" +
12986
+
12987
+ //"MOV texSamp, U;" +
12988
+
12989
+ "MUL temp2.z, temp2.z, temp2.w;" +
12990
+ "MUL temp2.z, temp2.z, params7.z;" + // parallax
12991
+
12992
+ "MUL temp2, temp2, temp2.z;" +
12993
+
12994
+ "MOV temp, fragment.texcoord[0];" +
12995
+
12996
+ "SUB temp, temp, temp2;" +
12997
+
12998
+ "TEX temp, temp, texture[0], 2D;" +
12999
+ "POW temp.a, temp.a, params6.w;" + // punch through
13000
+
13001
+ "ADD texSamp, temp, texSamp;" +
13002
+ "MUL texSamp.xyz, half, texSamp;" +
13003
+
13004
+ "MOV alpha, texSamp.aaaa;" +
13005
+
13006
+// parallax mapping
13007
+
13008
+ "MOV temp.x, texSamp.a;" +
13009
+ "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
13010
+ //"LRP texSamp0, params5.x, texSamp0, one;" +
13011
+ "MOV texSamp.a, temp.x;" +
1234513012
1234613013 //"MOV temp, fragment.texcoord[0];" +
1234713014 //
....@@ -12471,10 +13138,10 @@
1247113138 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1247213139 "") +
1247313140
12474
- // display shadow only (bump == 0)
13141
+ // display shadow only (fakedepth == 0)
1247513142 "SUB temp.x, half.x, shadow.x;" +
12476
- "MOV temp.y, -params6.x;" +
12477
- "SLT temp.z, temp.y, zero.x;" +
13143
+ "MOV temp.y, -params5.z;" + // params6.x;" +
13144
+ "SLT temp.z, temp.y, -c256i.x;" +
1247813145 "SUB temp.y, one.x, temp.z;" +
1247913146 "MUL temp.x, temp.x, temp.y;" +
1248013147 "KIL temp.x;" +
....@@ -12603,8 +13270,10 @@
1260313270 "MAX ndotl.x, ndotl.x, -ndotl.x;" +
1260413271
1260513272 "SUB temp.x, one.x, ndotl.x;" +
12606
- "ADD temp.x, temp.x, options2.z;" + // lightsheen
12607
- "ADD temp.y, one.y, options2.y;" + // sursurface
13273
+ // Tuning for default skin
13274
+ //"ADD temp.x, temp.x, options2.z;" + // lightsheen
13275
+ "MAD temp.x, options2.z, half.y, temp.x;" + // lightsheen
13276
+ "ADD temp.y, one.y, options2.y;" + // subsurface
1260813277 "MUL temp.x, temp.x, temp.y;" +
1260913278
1261013279 "MUL saturation, saturation, temp.xxxx;" +
....@@ -12752,7 +13421,7 @@
1275213421 "MUL final.y, fragment.texcoord[0].x, c256;" +
1275313422 "FLR final.x, final.y;" +
1275413423 "SUB final.y, final.y, final.x;" +
12755
- //"MUL final.x, final.x, c256i;" +
13424
+ "MUL final.x, final.x, c256i;" +
1275613425 "MOV final.z, zero.x;" +
1275713426 "MOV final.a, one.w;":""
1275813427 ) +
....@@ -12760,7 +13429,7 @@
1276013429 "MUL final.y, fragment.texcoord[0].y, c256;" +
1276113430 "FLR final.x, final.y;" +
1276213431 "SUB final.y, final.y, final.x;" +
12763
- //"MUL final.x, final.x, c256i;" +
13432
+ "MUL final.x, final.x, c256i;" +
1276413433 "MOV final.z, zero.x;" +
1276513434 "MOV final.a, one.w;":""
1276613435 ) +
....@@ -12803,8 +13472,19 @@
1280313472 //once = true;
1280413473 }
1280513474
12806
- System.out.print("Program #" + mode + "; length = " + program.length());
12807
- System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13475
+ String program = programmax;
13476
+
13477
+ if (Globals.MINSHADER)
13478
+ {
13479
+ program = programmin;
13480
+ }
13481
+
13482
+ if (Globals.DEBUG)
13483
+ {
13484
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13485
+ System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13486
+ }
13487
+
1280813488 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1280913489
1281013490 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -12851,7 +13531,8 @@
1285113531 "\n" +
1285213532 "END\n";
1285313533
12854
- System.out.println("Program shadow #" + 0 + "; length = " + program.length());
13534
+ if (Globals.DEBUG)
13535
+ System.out.println("Program shadow #" + 0 + "; length = " + program.length());
1285513536 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1285613537
1285713538 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -12896,25 +13577,26 @@
1289613577 return out;
1289713578 }
1289813579
12899
- String TextureFetch(String dest, String src, String unit)
13580
+ // Also does frustum culling
13581
+ String ShadowTextureFetch(String dest, String src, String unit)
1290013582 {
1290113583 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1290213584 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1290313585 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13586
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13587
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1290413588 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12905
- "SLT " + src + ".z, " + src + ".x, one.x;" +
12906
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12907
- "SLT " + src + ".z, " + src + ".y, one.x;" +
12908
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13589
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13590
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1290913591 //"SWZ buffer, temp, w,w,w,w;";
12910
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13592
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1291113593 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1291213594 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1291313595 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
12914
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13596
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1291513597
12916
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
12917
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13598
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13599
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1291813600 }
1291913601
1292013602 String Shadow(String depth, String shadow)
....@@ -12936,12 +13618,16 @@
1293613618
1293713619 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1293813620 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13621
+
13622
+ // Compare fragment depth in light space with shadowmap.
1293913623 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1294013624 "SGE temp.y, temp.x, zero.x;" +
12941
- "SUB " + shadow + ".y, one.x, temp.y;" +
13625
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13626
+
13627
+ // Reverse comparison
1294213628 "SUB temp.x, one.x, temp.x;" +
1294313629 "MUL " + shadow + ".x, temp.x, temp.y;" +
12944
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13630
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1294513631 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1294613632
1294713633 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -12955,6 +13641,10 @@
1295513641 // No shadow for backface
1295613642 "DP3 temp.x, normal, lightd;" +
1295713643 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13644
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13645
+
13646
+ // No shadow when out of frustum
13647
+ "SGE temp.x, " + depth + ".z, one.z;" +
1295813648 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1295913649 "";
1296013650 }
....@@ -13100,8 +13790,9 @@
1310013790 /*static*/ float[] modelParams4 = new float[]{0, 0, 0, 0}; // anisoV, cameralight, selfshadow, shadow
1310113791 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1310213792 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
13103
- /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13104
- Object3D.cVector2[] vector2buffer;
13793
+ /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power, parallax
13794
+
13795
+ //Object3D.cVector2[] vector2buffer;
1310513796
1310613797 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1310713798 // OUT : diff, spec
....@@ -13117,9 +13808,10 @@
1311713808 "DP3 " + dest + ".z," + "normals," + "eye;" +
1311813809 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1311913810 //"MOV " + dest + ".w," + "normal.z;" +
13120
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
13121
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13122
- //"MOV " + dest + ".z," + "params2.w;" +
13811
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13812
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13813
+
13814
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1312313815 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1312413816 "RCP " + dest + ".w," + dest + ".w;" +
1312513817 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13265,7 +13957,7 @@
1326513957 "PARAM p[4] = { state.matrix.projection }; # modelview projection matrix\n" +
1326613958 "PARAM zero = { 0.0, 0.0, 0.0, 1.0 };" +
1326713959 "PARAM half = { 0.5, 0.5, 0.5, 1.0 };" +
13268
- "PARAM one = { 1.0, 1.0, 1.0, 0.0 };" +
13960
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
1326913961 "PARAM two = { 2.0, 2.0, 2.0, 1.0 };" +
1327013962 "PARAM third = { 0.33333333333, 0.33333333333, 0.33333333333, 1.0 };" +
1327113963 //"PARAM v256 = { 256.0, 256.0, 256.0, 1.0 };" +
....@@ -13326,7 +14018,7 @@
1332614018 "DP4 temp.x,state.matrix.texture[0].inverse.row[0],vertex.texcoord;" +
1332714019 "DP4 temp.y,state.matrix.texture[0].inverse.row[1],vertex.texcoord;" +
1332814020 "DP4 temp.z,state.matrix.texture[0].inverse.row[2],vertex.texcoord;" +
13329
- //"MOV result.texcoord, vertex.texcoord;" +
14021
+ //"MOV result.texcoord, vertex.fogcoord;" +
1333014022 "MOV result.texcoord, temp;" +
1333114023 // border fade
1333214024 "MOV result.texcoord[3], vertex.texcoord;" +
....@@ -13373,7 +14065,9 @@
1337314065
1337414066 //"ADD temp.z, temp.z, one;" +
1337514067
13376
- "MOV result.color, temp;"
14068
+ "MOV result.texcoord[4], vertex.attrib[4];" + // U dir
14069
+
14070
+ "MOV result.color, temp;" // Normal
1337714071 : "MOV result.color, vertex.color;") +
1337814072 ((mode & VP_PROJECTION) != 0 ? "MOV result.color, zero;"
1337914073 : "") +
....@@ -13513,7 +14207,7 @@
1351314207 public void mousePressed(MouseEvent e)
1351414208 {
1351514209 //System.out.println("mousePressed: " + e);
13516
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14210
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1351714211 }
1351814212
1351914213 static long prevtime = 0;
....@@ -13589,8 +14283,8 @@
1358914283 // mode |= META;
1359014284 //}
1359114285
13592
- SetMouseMode(WHEEL | e.getModifiersEx());
13593
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14286
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14287
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1359414288 anchorX = ax;
1359514289 anchorY = ay;
1359614290 prevX = px;
....@@ -13624,6 +14318,7 @@
1362414318 else
1362514319 if (evt.getSource() == AAtimer)
1362614320 {
14321
+ Globals.TIMERRUNNING = false;
1362714322 if (mouseDown)
1362814323 {
1362914324 //new Exception().printStackTrace();
....@@ -13649,6 +14344,10 @@
1364914344 // LIVE = waslive;
1365014345 // wasliveok = true;
1365114346 // waslive = false;
14347
+
14348
+ // May 2019 Forget it:
14349
+ if (true)
14350
+ return;
1365214351
1365314352 // source == timer
1365414353 if (mouseDown)
....@@ -13679,7 +14378,7 @@
1367914378
1368014379 // fev 2014???
1368114380 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13682
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14381
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1368314382 pingthread.StepToTarget(true); // true);
1368414383 }
1368514384 // if (!LIVE)
....@@ -13688,12 +14387,13 @@
1368814387
1368914388 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1369014389
13691
- void clickStart(int x, int y, int modifiers)
14390
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1369214391 {
1369314392 if (!wasliveok)
1369414393 return;
1369514394
1369614395 AAtimer.restart(); //
14396
+ Globals.TIMERRUNNING = true;
1369714397
1369814398 // waslive = LIVE;
1369914399 // LIVE = false;
....@@ -13705,7 +14405,7 @@
1370514405 // touched = true; // main DL
1370614406 if (isRenderer)
1370714407 {
13708
- SetMouseMode(modifiers);
14408
+ SetMouseMode(modifiers, modifiersex);
1370914409 }
1371014410
1371114411 selectX = anchorX = x;
....@@ -13718,7 +14418,7 @@
1371814418 clicked = true;
1371914419 hold = false;
1372014420
13721
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14421
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1372214422 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1372314423 {
1372414424 // System.out.println("RESTART II " + modifiers);
....@@ -13743,14 +14443,15 @@
1374314443 drag = false;
1374414444 //System.out.println("Mouse DOWN");
1374514445 editObj = false;
13746
- ClickInfo info = new ClickInfo();
13747
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
13748
- info.pane = this;
13749
- info.camera = renderCamera;
13750
- info.x = x;
13751
- info.y = y;
13752
- info.modifiers = modifiers;
13753
- editObj = object.doEditClick(info, 0);
14446
+ //ClickInfo info = new ClickInfo();
14447
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14448
+ object.clickInfo.pane = this;
14449
+ object.clickInfo.camera = renderCamera;
14450
+ object.clickInfo.x = x;
14451
+ object.clickInfo.y = y;
14452
+ object.clickInfo.modifiers = modifiersex;
14453
+ editObj = object.doEditClick(//info,
14454
+ 0);
1375414455 if (!editObj)
1375514456 {
1375614457 hasMarquee = true;
....@@ -13766,9 +14467,12 @@
1376614467
1376714468 public void mouseDragged(MouseEvent e)
1376814469 {
14470
+ Globals.MOUSEDRAGGED = true;
14471
+
1376914472 //System.out.println("mouseDragged: " + e);
1377014473 if (isRenderer)
1377114474 movingcamera = true;
14475
+
1377214476 //if (drawing)
1377314477 //return;
1377414478 if ((e.getModifiersEx() & CTRL) != 0
....@@ -13778,7 +14482,7 @@
1377814482 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1377914483 }
1378014484 else
13781
- drag(e.getX(), e.getY(), e.getModifiersEx());
14485
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1378214486
1378314487 //try { Thread.sleep(1); } catch (Exception ex) {}
1378414488 }
....@@ -14015,7 +14719,7 @@
1401514719 {
1401614720 Globals.lighttouched = true;
1401714721 }
14018
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14722
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1401914723 }
1402014724 //else
1402114725 }
....@@ -14029,12 +14733,18 @@
1402914733 void GoDown(int mod)
1403014734 {
1403114735 MODIFIERS |= COMMAND;
14032
- /*
14736
+ boolean isVR = (mouseMode&VR)!=0;
14737
+ /**/
1403314738 if((mod&SHIFT) == SHIFT)
14034
- manipCamera.RotatePosition(0, -speed);
14739
+ {
14740
+ if (isVR)
14741
+ manipCamera.RotateInterest(0, -speed);
14742
+ else
14743
+ manipCamera.RotatePosition(0, -speed);
14744
+ }
1403514745 else
14036
- manipCamera.BackForth(0, -speed*delta, getWidth());
14037
- */
14746
+ manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth());
14747
+ /**/
1403814748 if ((mod & SHIFT) == SHIFT)
1403914749 {
1404014750 mouseMode = mouseMode; // VR??
....@@ -14043,6 +14753,8 @@
1404314753 mouseMode |= BACKFORTH;
1404414754 }
1404514755
14756
+ targetLookAt.set(manipCamera.lookAt);
14757
+
1404614758 //prevX = X = anchorX;
1404714759 prevY = Y = anchorY - (int) (renderCamera.Distance());
1404814760 }
....@@ -14050,12 +14762,19 @@
1405014762 void GoUp(int mod)
1405114763 {
1405214764 MODIFIERS |= COMMAND;
14053
- /*
14765
+ /**/
14766
+ boolean isVR = (mouseMode&VR)!=0;
14767
+
1405414768 if((mod&SHIFT) == SHIFT)
14055
- manipCamera.RotatePosition(0, speed);
14769
+ {
14770
+ if (isVR)
14771
+ manipCamera.RotateInterest(0, speed);
14772
+ else
14773
+ manipCamera.RotatePosition(0, speed);
14774
+ }
1405614775 else
14057
- manipCamera.BackForth(0, speed*delta, getWidth());
14058
- */
14776
+ manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth());
14777
+ /**/
1405914778 if ((mod & SHIFT) == SHIFT)
1406014779 {
1406114780 mouseMode = mouseMode;
....@@ -14064,6 +14783,8 @@
1406414783 mouseMode |= BACKFORTH;
1406514784 }
1406614785
14786
+ targetLookAt.set(manipCamera.lookAt);
14787
+
1406714788 //prevX = X = anchorX;
1406814789 prevY = Y = anchorY + (int) (renderCamera.Distance());
1406914790 }
....@@ -14071,12 +14792,17 @@
1407114792 void GoLeft(int mod)
1407214793 {
1407314794 MODIFIERS |= COMMAND;
14074
- /*
14795
+ /**/
1407514796 if((mod&SHIFT) == SHIFT)
14076
- manipCamera.RotatePosition(speed, 0);
14797
+ manipCamera.Translate(speed*delta, 0, getWidth());
1407714798 else
14078
- manipCamera.Translate(speed*delta, 0, getWidth());
14079
- */
14799
+ {
14800
+ if ((mouseMode&VR)!=0)
14801
+ manipCamera.RotateInterest(-speed, 0);
14802
+ else
14803
+ manipCamera.RotatePosition(speed, 0);
14804
+ }
14805
+ /**/
1408014806 if ((mod & SHIFT) == SHIFT)
1408114807 {
1408214808 mouseMode = mouseMode;
....@@ -14085,6 +14811,8 @@
1408514811 mouseMode |= ROTATE;
1408614812 } // TRANSLATE;
1408714813
14814
+ targetLookAt.set(manipCamera.lookAt);
14815
+
1408814816 prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance());
1408914817 prevY = Y = anchorY;
1409014818 }
....@@ -14092,12 +14820,18 @@
1409214820 void GoRight(int mod)
1409314821 {
1409414822 MODIFIERS |= COMMAND;
14095
- /*
14823
+ /**/
1409614824 if((mod&SHIFT) == SHIFT)
14097
- manipCamera.RotatePosition(-speed, 0);
14825
+ manipCamera.Translate(-speed*delta, 0, getWidth());
1409814826 else
14099
- manipCamera.Translate(-speed*delta, 0, getWidth());
14100
- */
14827
+ {
14828
+ if ((mouseMode&VR)!=0)
14829
+ manipCamera.RotateInterest(speed, 0);
14830
+ else
14831
+ manipCamera.RotatePosition(-speed, 0);
14832
+ }
14833
+
14834
+ /**/
1410114835 if ((mod & SHIFT) == SHIFT)
1410214836 {
1410314837 mouseMode = mouseMode;
....@@ -14106,6 +14840,8 @@
1410614840 mouseMode |= ROTATE;
1410714841 } // TRANSLATE;
1410814842
14843
+ targetLookAt.set(manipCamera.lookAt);
14844
+
1410914845 prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance());
1411014846 prevY = Y = anchorY;
1411114847 }
....@@ -14115,7 +14851,7 @@
1411514851 int X, Y;
1411614852 boolean SX, SY;
1411714853
14118
- void drag(int x, int y, int modifiers)
14854
+ void drag(int x, int y, int modifiers, int modifiersex)
1411914855 {
1412014856 if (IsFrozen())
1412114857 {
....@@ -14124,17 +14860,17 @@
1412414860
1412514861 drag = true; // NEW
1412614862
14127
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14863
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1412814864
1412914865 X = x;
1413014866 Y = y;
1413114867 // floating state for animation
14132
- MODIFIERS = modifiers;
14133
- modifiers &= ~1024;
14868
+ MODIFIERS = modifiersex;
14869
+ modifiersex &= ~1024;
1413414870 if (false) // modifiers != 0)
1413514871 {
1413614872 //new Exception().printStackTrace();
14137
- System.out.println("mouseDragged: " + modifiers);
14873
+ System.out.println("mouseDragged: " + modifiersex);
1413814874 System.out.println("SHIFT = " + SHIFT);
1413914875 System.out.println("CONTROL = " + COMMAND);
1414014876 System.out.println("META = " + META);
....@@ -14147,14 +14883,16 @@
1414714883 if (editObj)
1414814884 {
1414914885 drag = true;
14150
- ClickInfo info = new ClickInfo();
14151
- info.bounds.setBounds(0, 0,
14886
+ //ClickInfo info = new ClickInfo();
14887
+ object.clickInfo.bounds.setBounds(0, 0,
1415214888 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14153
- info.pane = this;
14154
- info.camera = renderCamera;
14155
- info.x = x;
14156
- info.y = y;
14157
- object.editWindow.copy.doEditDrag(info);
14889
+ object.clickInfo.pane = this;
14890
+ object.clickInfo.camera = renderCamera;
14891
+ object.clickInfo.x = x;
14892
+ object.clickInfo.y = y;
14893
+ object //.GetWindow().copy
14894
+ .doEditDrag(//info,
14895
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1415814896 } else
1415914897 {
1416014898 if (x < startX)
....@@ -14303,22 +15041,27 @@
1430315041 }
1430415042 }
1430515043
15044
+// ClickInfo clickInfo = new ClickInfo();
15045
+
1430615046 public void mouseMoved(MouseEvent e)
1430715047 {
1430815048 //System.out.println("mouseMoved: " + e);
1430915049 if (isRenderer)
1431015050 return;
1431115051
14312
- ClickInfo ci = new ClickInfo();
14313
- ci.x = e.getX();
14314
- ci.y = e.getY();
14315
- ci.modifiers = e.getModifiersEx();
14316
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14317
- ci.pane = this;
14318
- ci.camera = renderCamera;
15052
+ // Mouse cursor feedback
15053
+ object.clickInfo.x = e.getX();
15054
+ object.clickInfo.y = e.getY();
15055
+ object.clickInfo.modifiers = e.getModifiersEx();
15056
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
15057
+ object.clickInfo.pane = this;
15058
+ object.clickInfo.camera = renderCamera;
1431915059 if (!isRenderer)
1432015060 {
14321
- if (object.editWindow.copy.doEditClick(ci, 0))
15061
+ //ObjEditor editWindow = object.editWindow;
15062
+ //Object3D copy = editWindow.copy;
15063
+ if (object.doEditClick(//clickInfo,
15064
+ 0))
1432215065 {
1432315066 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1432415067 } else
....@@ -14330,7 +15073,11 @@
1433015073
1433115074 public void mouseReleased(MouseEvent e)
1433215075 {
15076
+ Globals.MOUSEDRAGGED = false;
15077
+
1433315078 movingcamera = false;
15079
+ X = 0; // getBounds().width/2;
15080
+ Y = 0; // getBounds().height/2;
1433415081 //System.out.println("mouseReleased: " + e);
1433515082 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1433615083 }
....@@ -14353,9 +15100,9 @@
1435315100 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1435415101 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1435515102
14356
- if (control || command || IsFrozen())
15103
+// No delay if (control || command || IsFrozen())
1435715104 timeout = true;
14358
- else
15105
+// ?? May 2019 else
1435915106 // timer.setDelay((modifiers & 128) != 0?0:350);
1436015107 mouseDown = false;
1436115108 if (!control && !command) // june 2013
....@@ -14465,7 +15212,7 @@
1446515212 System.out.println("keyReleased: " + e);
1446615213 }
1446715214
14468
- void SetMouseMode(int modifiers)
15215
+ void SetMouseMode(int modifiers, int modifiersex)
1446915216 {
1447015217 //System.out.println("SetMouseMode = " + modifiers);
1447115218 //modifiers &= ~1024;
....@@ -14477,25 +15224,25 @@
1447715224 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1447815225 // return;
1447915226 //System.out.println("SetMode = " + modifiers);
14480
- if ((modifiers & WHEEL) == WHEEL)
15227
+ if ((modifiersex & WHEEL) == WHEEL)
1448115228 {
1448215229 mouseMode |= ZOOM;
1448315230 }
1448415231
1448515232 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
14486
- if (capsLocked || (modifiers & META) == META)
15233
+ if (capsLocked) // || (modifiers & META) == META)
1448715234 {
1448815235 mouseMode |= VR; // BACKFORTH;
1448915236 }
14490
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
15237
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1449115238 {
1449215239 mouseMode |= SELECT;
1449315240 }
14494
- if ((modifiers & COMMAND) == COMMAND)
15241
+ if ((modifiersex & COMMAND) == COMMAND)
1449515242 {
1449615243 mouseMode |= SELECT;
1449715244 }
14498
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15245
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
1449915246 {
1450015247 mouseMode &= ~VR;
1450115248 mouseMode |= TRANSLATE;
....@@ -14524,7 +15271,7 @@
1452415271
1452515272 if (isRenderer) //
1452615273 {
14527
- SetMouseMode(modifiers);
15274
+ SetMouseMode(0, modifiers);
1452815275 }
1452915276
1453015277 Globals.theRenderer.keyPressed(key);
....@@ -14586,7 +15333,8 @@
1458615333 // break;
1458715334 case 'T':
1458815335 CACHETEXTURE ^= true;
14589
- textures.clear();
15336
+ texturepigment.clear();
15337
+ texturebump.clear();
1459015338 // repaint();
1459115339 break;
1459215340 case 'Y':
....@@ -14596,8 +15344,8 @@
1459615344 case 'K':
1459715345 KOMPACTTEXTURE ^= true;
1459815346 //textures.clear();
14599
- break;
14600
- case 'P': // Texture Projection macros
15347
+ // break;
15348
+ //case 'P': // Texture Projection macros
1460115349 // SAVETEXTURE ^= true;
1460215350 macromode = true;
1460315351 Udebug = Vdebug = NORMALdebug = false; programInitialized = false;
....@@ -14671,7 +15419,9 @@
1467115419 case 'E' : COMPACT ^= true;
1467215420 repaint();
1467315421 break;
14674
- case 'W' : DEBUGHSB ^= true;
15422
+ case 'W' : // Wide Window (fullscreen)
15423
+ //DEBUGHSB ^= true;
15424
+ ObjEditor.theFrame.ToggleFullScreen();
1467515425 repaint();
1467615426 break;
1467715427 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14696,8 +15446,8 @@
1469615446 RevertCamera();
1469715447 repaint();
1469815448 break;
14699
- case 'L':
1470015449 case 'l':
15450
+ //case 'L':
1470115451 if (lightMode)
1470215452 {
1470315453 lightMode = false;
....@@ -14716,7 +15466,7 @@
1471615466 targetLookAt.set(manipCamera.lookAt);
1471715467 repaint();
1471815468 break;
14719
- case 'p':
15469
+ case 'P': // p':
1472015470 // c'est quoi ca au juste? spherical ^= true;
1472115471 Skinshader ^= true; programInitialized = false;
1472215472 repaint();
....@@ -14761,20 +15511,24 @@
1476115511 OCCLUSION_CULLING ^= true;
1476215512 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1476315513 break;
14764
- case '0': envyoff ^= true; repaint(); break;
15514
+ //case '0': envyoff ^= true; repaint(); break;
1476515515 case '1':
1476615516 case '2':
1476715517 case '3':
1476815518 case '4':
1476915519 case '5':
14770
- newenvy = Character.getNumericValue(key);
14771
- repaint();
14772
- break;
1477315520 case '6':
1477415521 case '7':
1477515522 case '8':
1477615523 case '9':
14777
- BGcolor = (key - '6')/3.f;
15524
+ if (true) // envyoff)
15525
+ {
15526
+ BGcolor = (key - '1')/8.f;
15527
+ }
15528
+ else
15529
+ {
15530
+ //newenvy = Character.getNumericValue(key);
15531
+ }
1477815532 repaint();
1477915533 break;
1478015534 case '!':
....@@ -14840,9 +15594,9 @@
1484015594 case '_':
1484115595 kompactbit = 5;
1484215596 break;
14843
- case '+':
14844
- kompactbit = 6;
14845
- break;
15597
+// case '+':
15598
+// kompactbit = 6;
15599
+// break;
1484615600 case ' ':
1484715601 lightMode ^= true;
1484815602 Globals.lighttouched = true;
....@@ -14854,13 +15608,14 @@
1485415608 case ESC:
1485515609 RENDERPROGRAM += 1;
1485615610 RENDERPROGRAM %= 3;
15611
+
1485715612 repaint();
1485815613 break;
1485915614 case 'Z':
1486015615 //RESIZETEXTURE ^= true;
1486115616 //break;
1486215617 case 'z':
14863
- RENDERSHADOW ^= true;
15618
+ Globals.RENDERSHADOW ^= true;
1486415619 Globals.lighttouched = true;
1486515620 repaint();
1486615621 break;
....@@ -14893,8 +15648,9 @@
1489315648 case DELETE:
1489415649 ClearSelection();
1489515650 break;
14896
- /*
1489715651 case '+':
15652
+
15653
+ /*
1489815654 //fontsize += 1;
1489915655 bbzoom *= 2;
1490015656 repaint();
....@@ -14911,17 +15667,17 @@
1491115667 case '=':
1491215668 IncDepth();
1491315669 //fontsize += 1;
14914
- object.editWindow.refreshContents(true);
15670
+ object.GetWindow().refreshContents(true);
1491515671 maskbit = 6;
1491615672 break;
1491715673 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1491815674 DecDepth();
1491915675 maskbit = 5;
1492015676 //if(fontsize > 1) fontsize -= 1;
14921
- if (object.editWindow == null)
14922
- new Exception().printStackTrace();
14923
- else
14924
- object.editWindow.refreshContents(true);
15677
+// if (object.editWindow == null)
15678
+// new Exception().printStackTrace();
15679
+// else
15680
+ object.GetWindow().refreshContents(true);
1492515681 break;
1492615682 case '{':
1492715683 manipCamera.shaper_fovy /= 1.1;
....@@ -14984,7 +15740,7 @@
1498415740 //mode = ROTATE;
1498515741 if ((MODIFIERS & COMMAND) == 0) // VR??
1498615742 {
14987
- SetMouseMode(modifiers);
15743
+ SetMouseMode(0, modifiers);
1498815744 }
1498915745 }
1499015746
....@@ -15120,7 +15876,7 @@
1512015876 {
1512115877 //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
1512215878 //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15123
- if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (mouseMode & SELECT) == 0)
15879
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1512415880 {
1512515881 mouseMoved(e);
1512615882 } else
....@@ -15145,7 +15901,7 @@
1514515901 }
1514615902 */
1514715903
15148
- object.editWindow.EditSelection();
15904
+ object.GetWindow().EditSelection(false);
1514915905 }
1515015906
1515115907 void SelectParent()
....@@ -15162,10 +15918,10 @@
1516215918 {
1516315919 //selectees.remove(i);
1516415920 System.out.println("select parent of " + elem);
15165
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15921
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1516615922 } else
1516715923 {
15168
- group.editWindow.Select(elem.GetTreePath(), first, true);
15924
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1516915925 }
1517015926
1517115927 first = false;
....@@ -15207,12 +15963,12 @@
1520715963 for (int j = 0; j < group.children.size(); j++)
1520815964 {
1520915965 elem = (Object3D) group.children.elementAt(j);
15210
- object.editWindow.Select(elem.GetTreePath(), first, true);
15966
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1521115967 first = false;
1521215968 }
1521315969 } else
1521415970 {
15215
- object.editWindow.Select(elem.GetTreePath(), first, true);
15971
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1521615972 }
1521715973
1521815974 first = false;
....@@ -15223,21 +15979,21 @@
1522315979 {
1522415980 //Composite group = (Composite) object;
1522515981 Object3D group = object;
15226
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15982
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1522715983 }
1522815984
1522915985 void ResetTransform(int mask)
1523015986 {
1523115987 //Composite group = (Composite) object;
1523215988 Object3D group = object;
15233
- group.editWindow.ResetTransform(mask);
15989
+ group.GetWindow().ResetTransform(mask);
1523415990 }
1523515991
1523615992 void FlipTransform()
1523715993 {
1523815994 //Composite group = (Composite) object;
1523915995 Object3D group = object;
15240
- group.editWindow.FlipTransform();
15996
+ group.GetWindow().FlipTransform();
1524115997 // group.editWindow.ReduceMesh(true);
1524215998 }
1524315999
....@@ -15245,7 +16001,7 @@
1524516001 {
1524616002 //Composite group = (Composite) object;
1524716003 Object3D group = object;
15248
- group.editWindow.PrintMemory();
16004
+ group.GetWindow().PrintMemory();
1524916005 // group.editWindow.ReduceMesh(true);
1525016006 }
1525116007
....@@ -15253,7 +16009,7 @@
1525316009 {
1525416010 //Composite group = (Composite) object;
1525516011 Object3D group = object;
15256
- group.editWindow.ResetCentroid();
16012
+ group.GetWindow().ResetCentroid();
1525716013 }
1525816014
1525916015 void IncDepth()
....@@ -15335,11 +16091,11 @@
1533516091
1533616092 int width = getBounds().width;
1533716093 int height = getBounds().height;
15338
- ClickInfo info = new ClickInfo();
15339
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1534016094 //Image img = CreateImage(width, height);
1534116095 //System.out.println("width = " + width + "; height = " + height + "\n");
16096
+
1534216097 Graphics gr = g; // img.getGraphics();
16098
+
1534316099 if (!hasMarquee)
1534416100 {
1534516101 if (Xmin < Xmax) // !locked)
....@@ -15411,44 +16167,92 @@
1541116167 }
1541216168 if (object != null && !hasMarquee)
1541316169 {
16170
+ if (object.clickInfo == null)
16171
+ object.clickInfo = new ClickInfo();
16172
+ ClickInfo info = object.clickInfo;
16173
+ //ClickInfo info = new ClickInfo();
16174
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16175
+
1541416176 if (isRenderer)
1541516177 {
15416
- info.flags++;
16178
+ object.clickInfo.flags++;
1541716179 double frameAspect = (double) width / (double) height;
1541816180 if (frameAspect > renderCamera.aspect)
1541916181 {
1542016182 int desired = (int) ((double) height * renderCamera.aspect);
15421
- info.bounds.width -= width - desired;
15422
- info.bounds.x += (width - desired) / 2;
16183
+ object.clickInfo.bounds.width -= width - desired;
16184
+ object.clickInfo.bounds.x += (width - desired) / 2;
1542316185 } else
1542416186 {
1542516187 int desired = (int) ((double) width / renderCamera.aspect);
15426
- info.bounds.height -= height - desired;
15427
- info.bounds.y += (height - desired) / 2;
16188
+ object.clickInfo.bounds.height -= height - desired;
16189
+ object.clickInfo.bounds.y += (height - desired) / 2;
1542816190 }
1542916191 }
15430
- info.g = gr;
15431
- info.camera = renderCamera;
16192
+
16193
+ object.clickInfo.g = gr;
16194
+ object.clickInfo.camera = renderCamera;
1543216195 /*
1543316196 // Memory intensive (brep.verticescopy)
1543416197 if (!(object instanceof Composite))
1543516198 object.draw(info, 0, false); // SLOW :
1543616199 */
15437
- if (!isRenderer)
16200
+ if (!isRenderer) // && drag)
1543816201 {
15439
- object.drawEditHandles(info, 0);
16202
+ Grafreed.Assert(object != null);
16203
+ Grafreed.Assert(object.selection != null);
16204
+ if (object.selection.Size() > 0)
16205
+ {
16206
+ int hitSomething = object.selection.get(0).hitSomething;
16207
+
16208
+ object.clickInfo.DX = 0;
16209
+ object.clickInfo.DY = 0;
16210
+ object.clickInfo.W = 1;
16211
+ if (hitSomething == Object3D.hitCenter)
16212
+ {
16213
+ info.DX = X;
16214
+ if (X != 0)
16215
+ info.DX -= info.bounds.width/2;
16216
+
16217
+ info.DY = Y;
16218
+ if (Y != 0)
16219
+ info.DY -= info.bounds.height/2;
16220
+ }
16221
+
16222
+ object.drawEditHandles(//info,
16223
+ 0);
16224
+
16225
+ if (drag && (X != 0 || Y != 0))
16226
+ {
16227
+ switch (hitSomething)
16228
+ {
16229
+ case Object3D.hitCenter: gr.setColor(Color.white);
16230
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16231
+ break;
16232
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16233
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16234
+ break;
16235
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16236
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16237
+ break;
16238
+ }
16239
+
16240
+ }
16241
+ }
1544016242 }
1544116243 }
16244
+
1544216245 if (isRenderer)
1544316246 {
1544416247 //gr.setColor(Color.black);
1544516248 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1544616249 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1544716250 }
16251
+
1544816252 if (hasMarquee)
1544916253 {
1545016254 gr.setXORMode(Color.white);
15451
- gr.setColor(Color.red);
16255
+ gr.setColor(Color.white);
1545216256 if (!firstime)
1545316257 {
1545416258 gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH);
....@@ -15557,6 +16361,7 @@
1555716361 public boolean mouseDown(Event evt, int x, int y)
1555816362 {
1555916363 System.out.println("mouseDown: " + evt);
16364
+ System.exit(0);
1556016365 /*
1556116366 locked = true;
1556216367 drag = false;
....@@ -15600,7 +16405,7 @@
1560016405 {
1560116406 keyPressed(0, modifiers);
1560216407 }
15603
- clickStart(x, y, modifiers);
16408
+ // clickStart(x, y, modifiers);
1560416409 return true;
1560516410 }
1560616411
....@@ -15718,7 +16523,7 @@
1571816523 {
1571916524 keyReleased(0, 0);
1572016525 }
15721
- drag(x, y, modifiers);
16526
+ drag(x, y, 0, modifiers);
1572216527 return true;
1572316528 }
1572416529
....@@ -15850,7 +16655,7 @@
1585016655 Object3D object;
1585116656 static Object3D trackedobject;
1585216657 Camera renderCamera; // Light or Eye (or Occlusion)
15853
- /*static*/ Camera manipCamera; // Light or Eye
16658
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1585416659 /*static*/ Camera eyeCamera;
1585516660 /*static*/ Camera lightCamera;
1585616661 int cameracount;
....@@ -15914,6 +16719,8 @@
1591416719 private /*static*/ boolean firstime;
1591516720 private /*static*/ cVector newView = new cVector();
1591616721 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16722
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16723
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1591716724 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1591816725 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1591916726 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -15926,29 +16733,67 @@
1592616733 {
1592716734 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1592816735
16736
+ int usedsuf = 0;
16737
+
1592916738 for (int i = 0; i < suffixes.length; i++)
1593016739 {
15931
- String resourceName = basename + suffixes[i] + "." + suffix;
15932
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
15933
- mipmapped,
15934
- FileUtil.getFileSuffix(resourceName));
15935
- if (data == null)
16740
+ String[] suffixe = suffixes;
16741
+ String[] fallback = suffixes2;
16742
+ String[] fallfallback = suffixes3;
16743
+
16744
+ for (int c=usedsuf; --c>=0;)
1593616745 {
15937
- throw new IOException("Unable to load texture " + resourceName);
16746
+// String[] temp = suffixe;
16747
+// suffixe = fallback;
16748
+// fallback = fallfallback;
16749
+// fallfallback = temp;
1593816750 }
16751
+
16752
+ String resourceName = basename + suffixe[i] + "." + suffix;
16753
+ TextureData data;
16754
+
16755
+ try
16756
+ {
16757
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16758
+ mipmapped,
16759
+ FileUtil.getFileSuffix(resourceName));
16760
+ }
16761
+ catch (Exception e)
16762
+ {
16763
+ try
16764
+ {
16765
+ resourceName = basename + fallback[i] + "." + suffix;
16766
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16767
+ mipmapped,
16768
+ FileUtil.getFileSuffix(resourceName));
16769
+ }
16770
+ catch (Exception e2)
16771
+ {
16772
+ resourceName = basename + fallfallback[i] + "." + suffix;
16773
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16774
+ mipmapped,
16775
+ FileUtil.getFileSuffix(resourceName));
16776
+ }
16777
+ }
16778
+
1593916779 //System.out.println("Target = " + targets[i]);
1594016780 cubemap.updateImage(data, targets[i]);
1594116781 }
1594216782
1594316783 return cubemap;
1594416784 }
16785
+
1594516786 int bigsphere = -1;
1594616787
1594716788 float BGcolor = 0.5f;
1594816789
15949
- private void DrawSkyBox(GL gl)
16790
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16791
+
16792
+ private void DrawSkyBox(GL gl, float ratio)
1595016793 {
15951
- if (envyoff || cubemap == null)
16794
+ if (//envyoff ||
16795
+ WIREFRAME ||
16796
+ cubemap == null)
1595216797 {
1595316798 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1595416799 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -15963,7 +16808,17 @@
1596316808 // Compensates for ExaminerViewer's modification of modelview matrix
1596416809 gl.glMatrixMode(GL.GL_MODELVIEW);
1596516810 gl.glLoadIdentity();
16811
+ gl.glScalef(1,ratio,1);
1596616812
16813
+// colorV[0] = 2;
16814
+// colorV[1] = 2;
16815
+// colorV[2] = 2;
16816
+// colorV[3] = 1;
16817
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16818
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16819
+//
16820
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16821
+
1596716822 //gl.glActiveTexture(GL.GL_TEXTURE1);
1596816823 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1596916824
....@@ -15995,6 +16850,7 @@
1599516850 {
1599616851 gl.glScalef(1.0f, -1.0f, 1.0f);
1599716852 }
16853
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1599816854 gl.glMultMatrixd(viewrot_1, 0);
1599916855 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1600016856 //viewer.updateInverseRotation(gl);
....@@ -16035,7 +16891,8 @@
1603516891 gl.glDisable(GL.GL_TEXTURE_GEN_R);
1603616892
1603716893 cubemap.disable();
16038
- ////cubemap.unbind();
16894
+ //cubemap.dispose();
16895
+
1603916896 if (CULLFACE)
1604016897 {
1604116898 gl.glEnable(gl.GL_CULL_FACE);
....@@ -16091,7 +16948,7 @@
1609116948 gl.glScalef(1.0f, -1.0f, 1.0f);
1609216949 }
1609316950
16094
- gl.glNormal3f(0.0f, 0.0f, 1.0f);
16951
+ SetGLNormal(gl, 0.0f, 0.0f, 1.0f);
1609516952
1609616953 float step = 2; // 0.1666f; //0.25f;
1609716954 float stepv = 2; // step * 1652 / 998;
....@@ -16135,16 +16992,16 @@
1613516992 cStatic.objectstack[materialdepth++] = checker;
1613616993 //System.out.println("material " + material);
1613716994 //Applet3D.tracein(this, selected);
16138
- vector2buffer = checker.projectedVertices;
16995
+ //vector2buffer = checker.projectedVertices;
1613916996
1614016997 //checker.GetMaterial().Draw(this, false); // true);
16141
- DrawMaterial(checker.GetMaterial(), false); // true);
16998
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1614216999
1614317000 materialdepth -= 1;
1614417001 if (materialdepth > 0)
1614517002 {
16146
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16147
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
17003
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
17004
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1614817005 }
1614917006 //checker.GetMaterial().opacity = 1f;
1615017007 ////checker.GetMaterial().ambient = 1f;
....@@ -16230,6 +17087,14 @@
1623017087 }
1623117088 }
1623217089
17090
+ private Object3D GetFolder()
17091
+ {
17092
+ Object3D folder = object.GetWindow().copy;
17093
+ if (object.GetWindow().copy.selection.Size() > 0)
17094
+ folder = object.GetWindow().copy.selection.elementAt(0);
17095
+ return folder;
17096
+ }
17097
+
1623317098 class SelectBuffer implements GLEventListener
1623417099 {
1623517100
....@@ -16245,7 +17110,7 @@
1624517110 //new Exception().printStackTrace();
1624617111 System.out.println("select buffer init");
1624717112 // Use debug pipeline
16248
- drawable.setGL(new DebugGL(drawable.getGL()));
17113
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1624917114
1625017115 GL gl = drawable.getGL();
1625117116
....@@ -16309,6 +17174,17 @@
1630917174
1631017175 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1631117176
17177
+ if (PAINTMODE)
17178
+ {
17179
+ if (object.GetWindow().copy.selection.Size() > 0)
17180
+ {
17181
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17182
+
17183
+ // Make what you paint not selectable.
17184
+ paintobj.ResetSelectable();
17185
+ }
17186
+ }
17187
+
1631217188 //int tmp = selection_view;
1631317189 //selection_view = -1;
1631417190 int temp = DrawMode();
....@@ -16320,6 +17196,17 @@
1632017196 // temp = DEFAULT; // patch for selection debug
1632117197 Globals.drawMode = temp; // WARNING
1632217198
17199
+ if (PAINTMODE)
17200
+ {
17201
+ if (object.GetWindow().copy.selection.Size() > 0)
17202
+ {
17203
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17204
+
17205
+ // Revert.
17206
+ paintobj.RestoreSelectable();
17207
+ }
17208
+ }
17209
+
1632317210 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1632417211
1632517212 // trying different ways of getting the depth info over
....@@ -16367,6 +17254,8 @@
1636717254 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1636817255 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1636917256 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
17257
+
17258
+ CreateSelectedPoint();
1637017259
1637117260 // Will fit the mesh !!!
1637217261 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16416,34 +17305,36 @@
1641617305 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]));
1641717306 }
1641817307
16419
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
17308
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1642017309 }
1642117310 }
1642217311
1642317312 if (!movingcamera && !PAINTMODE)
16424
- object.editWindow.ScreenFitPoint(); // fev 2014
17313
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1642517314
16426
- if (PAINTMODE && GrafreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17315
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1642717316 {
16428
- Object3D paintobj = GrafreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17317
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1642917318
16430
- Object3D group = new Object3D("inst" + paintcount++);
17319
+ if (object.GetWindow().copy.selection.Size() > 0)
17320
+ {
17321
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1643117322
16432
- group.CreateMaterial(); // use a void leaf to select instances
16433
-
16434
- group.add(paintobj); // link
16435
-
16436
- object.editWindow.SnapObject(group);
16437
-
16438
- Object3D folder = object.editWindow.copy;
16439
-
16440
- if (object.editWindow.copy.selection.Size() > 0)
16441
- folder = object.editWindow.copy.selection.elementAt(0);
16442
-
16443
- folder.add(group);
16444
-
16445
- object.editWindow.ResetModel();
16446
- object.editWindow.refreshContents();
17323
+ Object3D inst = new Object3D("inst" + paintcount++);
17324
+
17325
+ inst.CreateMaterial(); // use a void leaf to select instances
17326
+
17327
+ inst.add(paintobj); // link
17328
+
17329
+ object.GetWindow().SnapObject(inst);
17330
+
17331
+ Object3D folder = paintFolder; // GetFolder();
17332
+
17333
+ folder.add(inst);
17334
+
17335
+ object.GetWindow().ResetModel();
17336
+ object.GetWindow().refreshContents();
17337
+ }
1644717338 }
1644817339 else
1644917340 paintcount = 0;
....@@ -16482,6 +17373,11 @@
1648217373 //System.out.println("objects[color] = " + objects[color]);
1648317374 //objects[color].Select();
1648417375 indexcount = 0;
17376
+ ObjEditor window = object.GetWindow();
17377
+ if (window != null && deselect)
17378
+ {
17379
+ window.Select(null, deselect, true);
17380
+ }
1648517381 object.Select(color, deselect);
1648617382 }
1648717383
....@@ -16532,6 +17428,7 @@
1653217428
1653317429 public void init(GLAutoDrawable drawable)
1653417430 {
17431
+ if (Globals.DEBUG)
1653517432 System.out.println("shadow buffer init");
1653617433
1653717434 GL gl = drawable.getGL();
....@@ -16581,7 +17478,7 @@
1658117478 gl.glDisable(gl.GL_CULL_FACE);
1658217479 }
1658317480
16584
- if (!RENDERSHADOW)
17481
+ if (!Globals.RENDERSHADOW)
1658517482 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1658617483
1658717484 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -16591,7 +17488,7 @@
1659117488 //gl.glColorMask(false, false, false, false);
1659217489
1659317490 //render_scene_from_light_view(gl, drawable, 0, 0);
16594
- if (RENDERSHADOW && Globals.lighttouched && !movingcamera) // && !parent.IsFreezed())
17491
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1659517492 {
1659617493 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1659717494
....@@ -16760,10 +17657,14 @@
1676017657 gl.glFlush();
1676117658
1676217659 /**/
16763
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17660
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1676417661
16765
- float[] pixels = occlusionsizebuffer.array();
17662
+ float[] depths = occlusiondepthbuffer.array();
1676617663
17664
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17665
+
17666
+ int[] pixels = selectsizebuffer.array();
17667
+
1676717668 double r = 0, g = 0, b = 0;
1676817669
1676917670 double count = 0;
....@@ -16774,7 +17675,7 @@
1677417675
1677517676 double FACTOR = 1;
1677617677
16777
- for (int i = 0; i < pixels.length; i++)
17678
+ for (int i = 0; i < depths.length; i++)
1677817679 {
1677917680 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1678017681 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -16857,7 +17758,7 @@
1685717758
1685817759 double scale = ray.z; // 1; // cos
1685917760
16860
- float depth = pixels[newindex];
17761
+ float depth = depths[newindex];
1686117762
1686217763 /*
1686317764 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -17007,23 +17908,15 @@
1700717908 int AAbuffersize = 0;
1700817909
1700917910 //double[] selectedpoint = new double[3];
17010
- static Superellipsoid selectedpoint = new Superellipsoid();
17911
+ static Superellipsoid selectedpoint;
1701117912 static Sphere previousselectedpoint = null;
17012
- static Sphere debugpointG = new Sphere();
17013
- static Sphere debugpointP = new Sphere();
17014
- static Sphere debugpointC = new Sphere();
17015
- static Sphere debugpointR = new Sphere();
17913
+ static Sphere debugpointG;
17914
+ static Sphere debugpointP;
17915
+ static Sphere debugpointC;
17916
+ static Sphere debugpointR;
1701617917
1701717918 static Sphere debugpoints[] = new Sphere[8];
1701817919
17019
- static
17020
- {
17021
- for (int i=0; i<8; i++)
17022
- {
17023
- debugpoints[i] = new Sphere();
17024
- }
17025
- }
17026
-
1702717920 static void InitPoints(float radius)
1702817921 {
1702917922 for (int i=0; i<8; i++)
....@@ -17062,11 +17955,14 @@
1706217955 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1706317956 static IntBuffer bigAAbuffer;
1706417957 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
17065
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17958
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1706617959 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1706717960 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1706817961 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17069
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17962
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17963
+
17964
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17965
+
1707017966 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1707117967 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1707217968 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();