Normand Briere
2019-08-21 7ac1b01c591ed65743676b1181d60eb17c5cb69d
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
....@@ -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
....@@ -151,6 +191,19 @@
151191 }
152192
153193 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
+ }
206
+ }
154207
155208 void SetAsGLRenderer(boolean b)
156209 {
....@@ -170,7 +223,8 @@
170223
171224 SetCamera(cam);
172225
173
- SetLight(new Camera(new cVector(10, 10, -20)));
226
+ // Warning: not used.
227
+ SetLight(new Camera(new cVector(15, 10, -20)));
174228
175229 object = o;
176230
....@@ -327,7 +381,7 @@
327381 cStatic.objectstack[materialdepth++] = obj;
328382 //System.out.println("material " + material);
329383 //Applet3D.tracein(this, selected);
330
- display.vector2buffer = obj.projectedVertices;
384
+ //display.vector2buffer = obj.projectedVertices;
331385 if (obj instanceof Camera)
332386 {
333387 display.options1[0] = material.shift;
....@@ -336,14 +390,28 @@
336390 display.options1[2] = material.shadowbias;
337391 display.options1[3] = material.aniso;
338392 display.options1[4] = material.anisoV;
393
+// System.out.println("display.options1[0] " + display.options1[0]);
394
+// System.out.println("display.options1[1] " + display.options1[1]);
395
+// System.out.println("display.options1[2] " + display.options1[2]);
396
+// System.out.println("display.options1[3] " + display.options1[3]);
397
+// System.out.println("display.options1[4] " + display.options1[4]);
339398 display.options2[0] = material.opacity;
340399 display.options2[1] = material.diffuse;
341400 display.options2[2] = material.factor;
401
+// System.out.println("display.options2[0] " + display.options2[0]);
402
+// System.out.println("display.options2[1] " + display.options2[1]);
403
+// System.out.println("display.options2[2] " + display.options2[2]);
342404
343405 cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
406
+// System.out.println("display.options3[0] " + display.options3[0]);
407
+// System.out.println("display.options3[1] " + display.options3[1]);
408
+// System.out.println("display.options3[2] " + display.options3[2]);
344409 display.options4[0] = material.cameralight/0.2f;
345410 display.options4[1] = material.subsurface;
346411 display.options4[2] = material.sheen;
412
+// System.out.println("display.options4[0] " + display.options4[0]);
413
+// System.out.println("display.options4[1] " + display.options4[1]);
414
+// System.out.println("display.options4[2] " + display.options4[2]);
347415
348416 // if (display.CURRENTANTIALIAS > 0)
349417 // display.options3[3] /= 4;
....@@ -359,7 +427,7 @@
359427 /**/
360428 } else
361429 {
362
- DrawMaterial(material, selected);
430
+ DrawMaterial(material, selected, obj.projectedVertices);
363431 }
364432 } else
365433 {
....@@ -383,8 +451,8 @@
383451 cStatic.objectstack[materialdepth++] = obj;
384452 //System.out.println("material " + material);
385453 //Applet3D.tracein("selected ", selected);
386
- display.vector2buffer = obj.projectedVertices;
387
- display.DrawMaterial(material, selected);
454
+ //display.vector2buffer = obj.projectedVertices;
455
+ display.DrawMaterial(material, selected, obj.projectedVertices);
388456 }
389457 }
390458
....@@ -401,8 +469,8 @@
401469 materialdepth -= 1;
402470 if (materialdepth > 0)
403471 {
404
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
405
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
472
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
473
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
406474 }
407475 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
408476 } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
....@@ -422,8 +490,8 @@
422490 materialdepth -= 1;
423491 if (materialdepth > 0)
424492 {
425
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
426
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
493
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
494
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
427495 }
428496 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
429497 //else
....@@ -464,15 +532,18 @@
464532 if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
465533 {
466534 //gl.glBegin(gl.GL_TRIANGLES);
467
- boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0);
535
+ boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0)
536
+ // TEST LIVE NORMALS && !obj.dontselect
537
+ ;
468538 if (!hasnorm)
469539 {
470
- // System.out.println("FUCK!!");
540
+ // System.out.println("Mesh normal");
471541 LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
472542 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
473543 LA.vecCross(obj.v0, obj.v1, obj.v2);
474544 LA.vecNormalize(obj.v2);
475
- gl.glNormal3f((float) obj.v2.x, (float) obj.v2.y, (float) obj.v2.z);
545
+
546
+ SetGLNormal(gl, (float) obj.v2.x, (float) obj.v2.y, (float) obj.v2.z);
476547 }
477548
478549 // P
....@@ -494,7 +565,7 @@
494565 y += ny * obj.NORMALPUSH;
495566 z += nz * obj.NORMALPUSH;
496567
497
- gl.glNormal3f(nx, ny, nz);
568
+ SetGLNormal(gl, nx, ny, nz);
498569 }
499570 gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
500571 SetColor(obj, pv);
....@@ -526,7 +597,7 @@
526597 y += ny * obj.NORMALPUSH;
527598 z += nz * obj.NORMALPUSH;
528599
529
- gl.glNormal3f(nx, ny, nz);
600
+ SetGLNormal(gl, nx, ny, nz);
530601 }
531602 //System.out.println("vertexq = " + qv.s + ", " + qv.t);
532603 // boolean locked = false;
....@@ -574,7 +645,7 @@
574645 y += ny * obj.NORMALPUSH;
575646 z += nz * obj.NORMALPUSH;
576647
577
- gl.glNormal3f(nx, ny, nz);
648
+ SetGLNormal(gl, nx, ny, nz);
578649 }
579650
580651 // if ((dot&4) == 0)
....@@ -1180,10 +1251,10 @@
11801251 {
11811252 if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
11821253 {
1183
- gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1254
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
11841255 } else
11851256 {
1186
- gl.glNormal3f(0, 0, 1);
1257
+ SetGLNormal(gl, 0, 0, 1);
11871258 }
11881259
11891260 if (c != null)
....@@ -1192,10 +1263,12 @@
11921263 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
11931264 }
11941265 }
1266
+
11951267 if (flipV)
11961268 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
11971269 else
11981270 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1271
+
11991272 //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
12001273 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
12011274
....@@ -1205,20 +1278,22 @@
12051278 {
12061279 if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
12071280 {
1208
- gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1281
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
12091282 } else
12101283 {
1211
- gl.glNormal3f(0, 0, 1);
1284
+ SetGLNormal(gl, 0, 0, 1);
12121285 }
12131286 if (c != null)
12141287 {
12151288 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
12161289 }
12171290 }
1291
+
12181292 if (flipV)
12191293 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12201294 else
12211295 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1296
+
12221297 //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
12231298 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
12241299
....@@ -1231,10 +1306,10 @@
12311306 {
12321307 if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
12331308 {
1234
- gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1309
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
12351310 } else
12361311 {
1237
- gl.glNormal3f(0, 0, 1);
1312
+ SetGLNormal(gl, 0, 0, 1);
12381313 }
12391314 if (c != null)
12401315 {
....@@ -1246,8 +1321,10 @@
12461321 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12471322 else
12481323 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1324
+
12491325 //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
12501326 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1327
+
12511328 count2 += 2;
12521329 count3 += 3;
12531330 }
....@@ -1414,7 +1491,7 @@
14141491 {
14151492 if (!selectmode)
14161493 {
1417
- gl.glNormal3f((float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
1494
+ SetGLNormal(gl, (float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
14181495 gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
14191496
14201497 if (flipV)
....@@ -1426,6 +1503,8 @@
14261503 gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
14271504 }
14281505
1506
+ float[] colorV = new float[4];
1507
+
14291508 void SetColor(Object3D obj, Vertex p0)
14301509 {
14311510 CameraPane display = this;
....@@ -1493,8 +1572,6 @@
14931572 {
14941573 return;
14951574 }
1496
-
1497
- float[] colorV = new float[3];
14981575
14991576 if (false) // marked)
15001577 {
....@@ -1603,7 +1680,7 @@
16031680 // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
16041681 }
16051682
1606
- void DrawMaterial(cMaterial material, boolean selected)
1683
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
16071684 {
16081685 CameraPane display = this;
16091686 //new Exception().printStackTrace();
....@@ -1638,7 +1715,7 @@
16381715 colorV[0] = display.modelParams0[0] * material.diffuse;
16391716 colorV[1] = display.modelParams0[1] * material.diffuse;
16401717 colorV[2] = display.modelParams0[2] * material.diffuse;
1641
- colorV[3] = material.opacity;
1718
+ colorV[3] = 1; // material.opacity;
16421719
16431720 gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
16441721 //System.out.println("Opacity = " + opacity);
....@@ -1743,12 +1820,12 @@
17431820
17441821 display.modelParams7[0] = 0;
17451822 display.modelParams7[1] = 1000;
1746
- display.modelParams7[2] = 0;
1823
+ display.modelParams7[2] = material.parallax;
17471824 display.modelParams7[3] = 0;
17481825
1749
- display.modelParams6[0] = 100; // criss de bug de bump
1826
+ //display.modelParams6[0] = 100; // criss de bug de bump
17501827
1751
- Object3D.cVector2[] extparams = display.vector2buffer;
1828
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
17521829 if (extparams != null && extparams.length > 0 && extparams[0] != null)
17531830 {
17541831 display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
....@@ -1890,7 +1967,7 @@
18901967 void PushMatrix(double[][] matrix)
18911968 {
18921969 // GrafreeD.tracein(matrix);
1893
- PushMatrix(matrix,1);
1970
+ PushMatrix(matrix, 1);
18941971 }
18951972
18961973 void PushMatrix()
....@@ -1976,9 +2053,9 @@
19762053 switch(viewcode)
19772054 {
19782055 case 0: return "main";
1979
- case 1: return "one";
1980
- case 2: return "two";
1981
- case 3: return "three";
2056
+ case 1: return "Red";
2057
+ case 2: return "Green";
2058
+ case 3: return "Blue";
19822059 case 4: return "light";
19832060 }
19842061
....@@ -2044,7 +2121,7 @@
20442121 //System.err.println("Oeil on");
20452122 OEIL = true;
20462123 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2047
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2124
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
20482125 //pingthread.StepToTarget(true);
20492126 }
20502127
....@@ -2259,7 +2336,7 @@
22592336
22602337 void ToggleDebug()
22612338 {
2262
- DEBUG ^= true;
2339
+ Globals.DEBUG ^= true;
22632340 }
22642341
22652342 void ToggleLookAt()
....@@ -2277,10 +2354,17 @@
22772354 HANDLES ^= true;
22782355 }
22792356
2357
+ Object3D paintFolder;
2358
+
22802359 void TogglePaint()
22812360 {
22822361 PAINTMODE ^= true;
22832362 paintcount = 0;
2363
+
2364
+ if (PAINTMODE)
2365
+ {
2366
+ paintFolder = GetFolder();
2367
+ }
22842368 }
22852369
22862370 void SwapCamera(int a, int b)
....@@ -2377,6 +2461,33 @@
23772461 return currentGL;
23782462 }
23792463
2464
+ static private BufferedImage CreateBim(TextureData texturedata)
2465
+ {
2466
+ Grafreed.Assert(texturedata != null);
2467
+
2468
+ int width = texturedata.getWidth();
2469
+ int height = texturedata.getHeight();
2470
+
2471
+ Buffer buffer = texturedata.getBuffer();
2472
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2473
+
2474
+ byte[] bytes = bytebuf.array();
2475
+
2476
+ return CreateBim(bytes, width, height);
2477
+ }
2478
+
2479
+ private void SetGLNormal(javax.media.opengl.GL gl, float nx, float ny, float nz)
2480
+ {
2481
+ gl.glNormal3f(nx, ny, nz);
2482
+
2483
+ if (ny > 0.9 || ny < -0.9)
2484
+ // Ground or ceiling
2485
+ gl.glVertexAttrib3f(4, 1, 0, 0);
2486
+ else
2487
+ // Walls
2488
+ gl.glVertexAttrib3f(4, 0, 1, 0);
2489
+ }
2490
+
23802491 /**/
23812492 class CacheTexture
23822493 {
....@@ -2385,28 +2496,31 @@
23852496
23862497 int resolution;
23872498
2388
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2499
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
23892500 {
2390
- texture = tex;
2501
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2502
+ texturedata = texdata;
23912503 resolution = res;
23922504 }
23932505 }
23942506 /**/
23952507
23962508 // TEXTURE static Texture texture;
2397
- static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures
2398
- = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>();
2399
- static public java.util.Hashtable<String, String> usedtextures = new java.util.Hashtable<String, String>();
2509
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2510
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2511
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2512
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2513
+
24002514 int pigmentdepth = 0;
24012515 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
24022516 int bumpdepth = 0;
24032517 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
24042518 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
24052519 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2406
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2520
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
24072521 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
24082522
2409
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2523
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
24102524 {
24112525 TextureData texturedata = null;
24122526
....@@ -2416,7 +2530,7 @@
24162530 com.sun.opengl.util.texture.TextureIO.newTextureData(
24172531 getClass().getClassLoader().getResourceAsStream(name),
24182532 true,
2419
- com.sun.opengl.util.texture.TextureIO.PNG);
2533
+ GetFormat(name)); // com.sun.opengl.util.texture.TextureIO.PNG);
24202534 } catch (java.io.IOException e)
24212535 {
24222536 throw new javax.media.opengl.GLException(e);
....@@ -2425,13 +2539,34 @@
24252539 if (bump)
24262540 texturedata = ConvertBump(texturedata, false);
24272541
2428
- com.sun.opengl.util.texture.Texture texture =
2429
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2542
+// com.sun.opengl.util.texture.Texture texture =
2543
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
24302544
2431
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2432
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
2545
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2546
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
24332547
2434
- return texture;
2548
+ return texturedata;
2549
+ }
2550
+
2551
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2552
+ {
2553
+ TextureData texturedata = null;
2554
+
2555
+ try
2556
+ {
2557
+ texturedata =
2558
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2559
+ bim,
2560
+ true);
2561
+ } catch (Exception e)
2562
+ {
2563
+ throw new javax.media.opengl.GLException(e);
2564
+ }
2565
+
2566
+ if (bump)
2567
+ texturedata = ConvertBump(texturedata, false);
2568
+
2569
+ return texturedata;
24352570 }
24362571
24372572 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3504,6 +3639,8 @@
35043639
35053640 System.out.println("LOADING TEXTURE : " + name);
35063641
3642
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3643
+
35073644 //
35083645 if (false) // compressbit > 0)
35093646 {
....@@ -7902,7 +8039,7 @@
79028039 String pigment = Object3D.GetPigment(tex);
79038040 String bump = Object3D.GetBump(tex);
79048041
7905
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8042
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79068043 {
79078044 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79088045 // System.out.println("; bump = " + bump);
....@@ -7917,11 +8054,69 @@
79178054 pigment = null;
79188055 }
79198056
7920
- ReleaseTexture(bump, true);
7921
- ReleaseTexture(pigment, false);
8057
+ ReleaseTexture(tex, true);
8058
+ ReleaseTexture(tex, false);
79228059 }
79238060
7924
- void ReleaseTexture(String tex, boolean bump)
8061
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
8062
+ {
8063
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8064
+ {
8065
+ return;
8066
+ }
8067
+
8068
+ if (tex == null)
8069
+ {
8070
+ ReleaseTexture(null, false);
8071
+ return;
8072
+ }
8073
+
8074
+ String pigment = Object3D.GetPigment(tex);
8075
+
8076
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8077
+ {
8078
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8079
+ // System.out.println("; bump = " + bump);
8080
+ }
8081
+
8082
+ if (pigment.equals(""))
8083
+ {
8084
+ pigment = null;
8085
+ }
8086
+
8087
+ ReleaseTexture(tex, false);
8088
+ }
8089
+
8090
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
8091
+ {
8092
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8093
+ {
8094
+ return;
8095
+ }
8096
+
8097
+ if (tex == null)
8098
+ {
8099
+ ReleaseTexture(null, true);
8100
+ return;
8101
+ }
8102
+
8103
+ String bump = Object3D.GetBump(tex);
8104
+
8105
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8106
+ {
8107
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8108
+ // System.out.println("; bump = " + bump);
8109
+ }
8110
+
8111
+ if (bump.equals(""))
8112
+ {
8113
+ bump = null;
8114
+ }
8115
+
8116
+ ReleaseTexture(tex, true);
8117
+ }
8118
+
8119
+ void ReleaseTexture(cTexture tex, boolean bump)
79258120 {
79268121 if (// DrawMode() != 0 || /*tex == null ||*/
79278122 ambientOcclusion ) // || !textureon)
....@@ -7932,7 +8127,7 @@
79328127 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
79338128
79348129 if (tex != null)
7935
- texture = textures.get(tex);
8130
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
79368131
79378132 // //assert( texture != null );
79388133 // if (texture == null)
....@@ -8026,6 +8221,54 @@
80268221
80278222 /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
80288223 {
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
8271
+ {
80298272 if (// DrawMode() != 0 || /*tex == null ||*/
80308273 ambientOcclusion ) // || !textureon)
80318274 {
....@@ -8035,17 +8278,47 @@
80358278 if (tex == null)
80368279 {
80378280 BindTexture(null,false,resolution);
8038
- BindTexture(null,true,resolution);
80398281 return;
80408282 }
80418283
80428284 String pigment = Object3D.GetPigment(tex);
8285
+
8286
+ usedtextures.add(tex);
8287
+
8288
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8289
+ {
8290
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8291
+ // System.out.println("; bump = " + bump);
8292
+ }
8293
+
8294
+ if (pigment.equals(""))
8295
+ {
8296
+ pigment = null;
8297
+ }
8298
+
8299
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8300
+ BindTexture(tex, false, resolution);
8301
+ }
8302
+
8303
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8304
+ {
8305
+ if (// DrawMode() != 0 || /*tex == null ||*/
8306
+ ambientOcclusion ) // || !textureon)
8307
+ {
8308
+ return; // false;
8309
+ }
8310
+
8311
+ if (tex == null)
8312
+ {
8313
+ BindTexture(null,true,resolution);
8314
+ return;
8315
+ }
8316
+
80438317 String bump = Object3D.GetBump(tex);
80448318
8045
- usedtextures.put(pigment, pigment);
8046
- usedtextures.put(bump, bump);
8319
+ usedtextures.add(tex);
80478320
8048
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8321
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
80498322 {
80508323 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
80518324 // System.out.println("; bump = " + bump);
....@@ -8055,18 +8328,10 @@
80558328 {
80568329 bump = null;
80578330 }
8058
- if (pigment.equals(""))
8059
- {
8060
- pigment = null;
8061
- }
80628331
8063
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8064
- BindTexture(pigment, false, resolution);
80658332 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8066
- BindTexture(bump, true, resolution);
8333
+ BindTexture(tex, true, resolution);
80678334 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8068
-
8069
- return; // true;
80708335 }
80718336
80728337 java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
....@@ -8089,13 +8354,19 @@
80898354 return fileExists;
80908355 }
80918356
8092
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception
8357
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
80938358 {
8094
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8359
+ CacheTexture texturecache = null;
80958360
80968361 if (tex != null)
80978362 {
8098
- String texname = tex;
8363
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8364
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
8365
+
8366
+ if (texname.equals("") && texdata == null)
8367
+ {
8368
+ return null;
8369
+ }
80998370
81008371 String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
81018372
....@@ -8105,19 +8376,46 @@
81058376 // else
81068377 // if (!texname.startsWith("/"))
81078378 // texname = "/Users/nbriere/Textures/" + texname;
8108
- if (!FileExists(tex))
8379
+ if (!FileExists(texname) && !texname.startsWith("@"))
81098380 {
81108381 texname = fallbackTextureName;
81118382 }
81128383
81138384 if (CACHETEXTURE)
8114
- texture = textures.get(texname); // TEXTURE CACHE
8115
-
8116
- TextureData texturedata = null;
8117
-
8118
- if (texture == null || texture.resolution < resolution)
81198385 {
8120
- 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(""))
81218419 {
81228420 assert(!bump);
81238421 // if (bump)
....@@ -8128,19 +8426,23 @@
81288426 // }
81298427 // else
81308428 // {
8131
- texture = textures.get(tex);
8132
- if (texture == null)
8429
+ // texturecache = textures.get(texname); // suspicious
8430
+ if (texturecache == null)
81338431 {
8134
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8432
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
81358433 }
8434
+ else
8435
+ new Exception().printStackTrace();
81368436 // }
81378437 } else
8138
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8438
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
81398439 {
81408440 assert(bump);
8141
- texture = textures.get(tex);
8142
- if (texture == null)
8143
- 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();
81448446 } else
81458447 {
81468448 //if (tex.equals("IMMORTAL"))
....@@ -8148,11 +8450,22 @@
81488450 // texture = GetResourceTexture("default.png");
81498451 //} else
81508452 //{
8151
- if (tex.equals("WHITE_NOISE"))
8453
+ if (texname.endsWith("WHITE_NOISE"))
81528454 {
8153
- texture = textures.get(tex);
8154
- if (texture == null)
8155
- 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();
81568469 } else
81578470 {
81588471 if (textureon)
....@@ -8211,19 +8524,20 @@
82118524 if (texturedata == null)
82128525 throw new Exception();
82138526
8214
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8527
+ texturecache = new CacheTexture(texturedata,resolution);
82158528 //texture = GetTexture(tex, bump);
82168529 }
8530
+ }
82178531 }
82188532 //}
82198533 }
82208534
8221
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8535
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
82228536 {
82238537 //return false;
82248538
82258539 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8226
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8540
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
82278541 {
82288542 // String ext = "_highres";
82298543 // if (REDUCETEXTURE)
....@@ -8240,52 +8554,17 @@
82408554 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
82418555 if (!cachefile.exists())
82428556 {
8243
- // cache to disk
8244
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
8245
- //buffers[0].
8246
-
8247
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
8248
- int[] pixels = new int[bytebuf.capacity()/3];
8249
-
8250
- // squared size heuristic...
8251
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8557
+ //if (texturedata.getWidth() == texturedata.getHeight())
82528558 {
8253
- for (int i=pixels.length; --i>=0;)
8254
- {
8255
- int i3 = i*3;
8256
- pixels[i] = 0xFF;
8257
- pixels[i] <<= 8;
8258
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
8259
- pixels[i] <<= 8;
8260
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
8261
- pixels[i] <<= 8;
8262
- pixels[i] |= bytebuf.get(i3) & 0xFF;
8263
- }
8264
-
8265
- /*
8266
- int r=0,g=0,b=0,a=0;
8267
- for (int i=0; i<width; i++)
8268
- for (int j=0; j<height; j++)
8269
- {
8270
- int index = j*width+i;
8271
- int p = pixels[index];
8272
- a = ((p>>24) & 0xFF);
8273
- r = ((p>>16) & 0xFF);
8274
- g = ((p>>8) & 0xFF);
8275
- b = (p & 0xFF);
8276
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
8277
- }
8278
- /**/
8279
- int width = (int)Math.sqrt(pixels.length); // squared
8280
- int height = width;
8281
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
8282
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8559
+ BufferedImage rendImage = CreateBim(texturedata);
8560
+
82838561 ImageWriter writer = null;
82848562 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
82858563 if (iter.hasNext()) {
82868564 writer = (ImageWriter)iter.next();
82878565 }
8288
- float compressionQuality = 0.9f;
8566
+
8567
+ float compressionQuality = 0.85f;
82898568 try
82908569 {
82918570 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8302,18 +8581,20 @@
83028581 }
83038582 }
83048583 }
8305
-
8584
+
8585
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8586
+
83068587 //System.out.println("Texture = " + tex);
8307
- if (textures.containsKey(texname))
8588
+ if (textures.containsKey(tex))
83088589 {
8309
- CacheTexture thetex = textures.get(texname);
8590
+ CacheTexture thetex = textures.get(tex);
83108591 thetex.texture.disable();
83118592 thetex.texture.dispose();
8312
- textures.remove(texname);
8593
+ textures.remove(tex);
83138594 }
83148595
8315
- texture.texturedata = texturedata;
8316
- textures.put(texname, texture);
8596
+ //texture.texturedata = texturedata;
8597
+ textures.put(tex, texturecache);
83178598
83188599 // newtex = true;
83198600 }
....@@ -8329,10 +8610,44 @@
83298610 }
83308611 }
83318612
8332
- return texture;
8613
+ return texturecache;
83338614 }
83348615
8335
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution) throws Exception
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
83368651 {
83378652 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
83388653
....@@ -8350,21 +8665,21 @@
83508665 return texture!=null?texture.texture:null;
83518666 }
83528667
8353
- public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution) throws Exception
8668
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
83548669 {
83558670 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
83568671
83578672 return texture!=null?texture.texturedata:null;
83588673 }
83598674
8360
- boolean BindTexture(String tex, boolean bump, int resolution) throws Exception
8675
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
83618676 {
83628677 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
83638678 {
83648679 return false;
83658680 }
83668681
8367
- boolean newtex = false;
8682
+ //boolean newtex = false;
83688683
83698684 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
83708685
....@@ -8396,9 +8711,75 @@
83968711 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
83978712 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
83988713
8399
- return newtex;
8714
+ return true; // Warning: not used.
84008715 }
84018716
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
+
84028783 ShadowBuffer shadowPBuf;
84038784 AntialiasBuffer antialiasPBuf;
84048785 int MAXSTACK;
....@@ -8415,10 +8796,12 @@
84158796
84168797 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
84178798 MAXSTACK = temp[0];
8418
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8799
+ if (Globals.DEBUG)
8800
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
84198801 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
84208802 MAXSTACK = temp[0];
8421
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8803
+ if (Globals.DEBUG)
8804
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
84228805
84238806 // Use debug pipeline
84248807 //drawable.setGL(new DebugGL(gl)); //
....@@ -8426,7 +8809,8 @@
84268809 gl = drawable.getGL(); //
84278810
84288811 GL gl3 = getGL();
8429
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8812
+ if (Globals.DEBUG)
8813
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
84308814
84318815
84328816 //float pos[] = { 100, 100, 100, 0 };
....@@ -8591,7 +8975,7 @@
85918975
85928976 if (cubemap == null)
85938977 {
8594
- LoadEnvy(5);
8978
+ //LoadEnvy(1);
85958979 }
85968980
85978981 //cubemap.enable();
....@@ -8867,6 +9251,8 @@
88679251
88689252 void LoadEnvy(int which)
88699253 {
9254
+ assert(false);
9255
+
88709256 String name;
88719257 String ext;
88729258
....@@ -8878,37 +9264,58 @@
88789264 cubemap = null;
88799265 return;
88809266 case 1:
8881
- name = "cubemaps/box_";
8882
- ext = "png";
9267
+ name = "cubemaps/rgb/";
9268
+ ext = "jpg";
88839269 reverseUP = false;
88849270 break;
88859271 case 2:
8886
- name = "cubemaps/uffizi_";
8887
- ext = "png";
8888
- break; // reverseUP = true; break;
9272
+ name = "cubemaps/uffizi/";
9273
+ ext = "jpg";
9274
+ reverseUP = false;
9275
+ break;
88899276 case 3:
8890
- name = "cubemaps/CloudyHills_";
8891
- ext = "tga";
9277
+ name = "cubemaps/CloudyHills/";
9278
+ ext = "jpg";
88929279 reverseUP = false;
88939280 break;
88949281 case 4:
8895
- name = "cubemaps/cornell_";
9282
+ name = "cubemaps/cornell/";
88969283 ext = "png";
88979284 reverseUP = false;
88989285 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;
88999311 default:
8900
- name = "cubemaps/rgb_";
8901
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9312
+ name = "cubemaps/box/";
9313
+ ext = "png"; /*mipmap = true;*/
9314
+ reverseUP = false;
89029315 break;
89039316 }
8904
-
8905
- try
8906
- {
8907
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
8908
- } catch (IOException e)
8909
- {
8910
- throw new RuntimeException(e);
8911
- }
9317
+
9318
+ LoadSkybox(name, ext, mipmap);
89129319 }
89139320
89149321 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -8940,8 +9347,12 @@
89409347 static double[] model = new double[16];
89419348 double[] camera2light = new double[16];
89429349 double[] light2camera = new double[16];
8943
- int newenvy = -1;
8944
- boolean envyoff = true; // false;
9350
+
9351
+ //int newenvy = -1;
9352
+ //boolean envyoff = false;
9353
+
9354
+ String loadedskyboxname;
9355
+
89459356 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
89469357 //float[] light0 = { 0,0,0 };
89479358 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9234,11 +9645,35 @@
92349645 jy8[3] = 0.5f;
92359646 }
92369647
9237
- 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
92389649 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
92399650 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
92409651 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
92419652
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
+
92429677 static int imagecount = 0; // movie generation
92439678
92449679 static int jitter = 0;
....@@ -9397,10 +9832,12 @@
93979832 rati = 1 / rati;
93989833 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
93999834 }
9400
- assert (newenvy == -1);
9835
+
9836
+ //assert (newenvy == -1);
9837
+
94019838 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
94029839 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9403
- DrawSkyBox(gl);
9840
+ DrawSkyBox(gl, (float)rati);
94049841 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
94059842 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
94069843 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10266,9 +10703,18 @@
1026610703 static boolean init = false;
1026710704
1026810705 double[][] matrix = LA.newMatrix();
10706
+
10707
+ // This is to refresh the UI of the material panel.
10708
+ ObjEditor patchMaterial;
1026910709
1027010710 public void display(GLAutoDrawable drawable)
1027110711 {
10712
+ if (patchMaterial.patchMaterial)
10713
+ {
10714
+ patchMaterial.patchMaterial = false;
10715
+ patchMaterial.objectPanel.setSelectedIndex(1);
10716
+ }
10717
+
1027210718 if (Grafreed.savesound && Grafreed.hassound)
1027310719 {
1027410720 Grafreed.wav.save();
....@@ -10349,6 +10795,7 @@
1034910795 ANTIALIAS = 0;
1035010796 //System.out.println("RESTART");
1035110797 AAtimer.restart();
10798
+ Globals.TIMERRUNNING = true;
1035210799 }
1035310800 }
1035410801 }
....@@ -10416,7 +10863,8 @@
1041610863 ambientOcclusion = false;
1041710864 }
1041810865
10419
- if (Globals.lighttouched && DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
10866
+ if (//Globals.lighttouched &&
10867
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1042010868 {
1042110869 //if (RENDERSHADOW) // ?
1042210870 if (!IsFrozen())
....@@ -10435,7 +10883,7 @@
1043510883
1043610884 if (wait)
1043710885 {
10438
- Sleep(500);
10886
+ Sleep(200); // blocks everything
1043910887
1044010888 wait = false;
1044110889 }
....@@ -10651,13 +11099,43 @@
1065111099 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1065211100 }
1065311101
10654
- 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"))
1065511110 {
10656
- LoadEnvy(newenvy);
11111
+ if (cubemaprgb == null)
11112
+ {
11113
+ cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb2" + "/", "jpg", false);
11114
+ }
11115
+
11116
+ cubemap = cubemaprgb;
1065711117 }
10658
-
10659
- newenvy = -1;
10660
-
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
+
1066111139 ratio = ((double) getWidth()) / getHeight();
1066211140 //System.out.println("ratio = " + ratio);
1066311141
....@@ -10673,7 +11151,7 @@
1067311151
1067411152 if (!IsFrozen() && !ambientOcclusion)
1067511153 {
10676
- DrawSkyBox(gl);
11154
+ DrawSkyBox(gl, (float)ratio);
1067711155 }
1067811156
1067911157 //if (selection_view == -1)
....@@ -10856,9 +11334,9 @@
1085611334
1085711335 gl.glMatrixMode(GL.GL_MODELVIEW);
1085811336
10859
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10860
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10861
-//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);
1086211340 } else
1086311341 {
1086411342 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -10869,7 +11347,7 @@
1086911347 //System.out.println("BLENDING ON");
1087011348 gl.glEnable(GL.GL_BLEND);
1087111349 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
10872
-
11350
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1087311351 gl.glMatrixMode(gl.GL_PROJECTION);
1087411352 gl.glLoadIdentity();
1087511353
....@@ -10981,7 +11459,7 @@
1098111459 {
1098211460 if (cam != lightCamera)
1098311461 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10984
- LA.xformDir(light0, parentcam.GlobalTransformInv(), light0); // may 2013
11462
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
1098511463 }
1098611464
1098711465 LA.xformPos(light0, cam.toScreen, light0);
....@@ -11118,7 +11596,7 @@
1111811596 }
1111911597 }
1112011598
11121
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11599
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1112211600 {
1112311601 //gl.glDepthFunc(GL.GL_LEQUAL);
1112411602 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11126,24 +11604,21 @@
1112611604
1112711605 boolean texon = textureon;
1112811606
11129
- if (RENDERPROGRAM > 0)
11130
- {
11131
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11132
- textureon = false;
11133
- }
11607
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11608
+ textureon = false;
11609
+
1113411610 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1113511611 //System.out.println("ALLO");
1113611612 gl.glColorMask(false, false, false, false);
1113711613 DrawObject(gl);
11138
- if (RENDERPROGRAM > 0)
11139
- {
11140
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11141
- textureon = texon;
11142
- }
11614
+
11615
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11616
+ textureon = texon;
11617
+
1114311618 gl.glColorMask(true, true, true, true);
1114411619
1114511620 gl.glDepthFunc(GL.GL_EQUAL);
11146
- //gl.glDepthMask(false);
11621
+ gl.glDepthMask(false);
1114711622 }
1114811623
1114911624 if (false) // DrawMode() == SHADOW)
....@@ -11326,15 +11801,36 @@
1132611801
1132711802 static boolean zoomonce = false;
1132811803
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
+
1132911822 void DrawObject(GL gl, boolean draw)
1133011823 {
11824
+ // To clear camera values
11825
+ ResetOptions();
11826
+
1133111827 //System.out.println("DRAW OBJECT " + mouseDown);
1133211828 // DrawMode() = SELECTION;
1133311829 //GL gl = getGL();
1133411830 if ((TRACK || SHADOWTRACK) || zoomonce)
1133511831 {
1133611832 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11337
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11833
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1133811834 pingthread.StepToTarget(true); // true);
1133911835 // zoomonce = false;
1134011836 }
....@@ -11406,8 +11902,9 @@
1140611902
1140711903 if (DrawMode() == DEFAULT)
1140811904 {
11409
- if (DEBUG)
11905
+ if (Globals.DEBUG)
1141011906 {
11907
+ CreateSelectedPoint();
1141111908 float radius = 0.05f;
1141211909 if (selectedpoint.radius != radius)
1141311910 {
....@@ -11461,20 +11958,32 @@
1146111958 ReleaseTextures(DEFAULT_TEXTURES);
1146211959
1146311960 if (CLEANCACHE)
11464
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11961
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1146511962 {
11466
- String tex = e.nextElement();
11963
+ cTexture tex = e.nextElement();
1146711964
1146811965 // System.out.println("Texture --------- " + tex);
1146911966
11470
- if (tex.equals("WHITE_NOISE"))
11967
+ if (tex.equals("WHITE_NOISE:"))
1147111968 continue;
1147211969
11473
- if (!usedtextures.containsKey(tex))
11970
+ if (!usedtextures.contains(tex))
1147411971 {
11972
+ CacheTexture gettex = texturepigment.get(tex);
1147511973 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11476
- textures.get(tex).texture.dispose();
11477
- 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
+ }
1147811987 }
1147911988 }
1148011989 }
....@@ -11912,7 +12421,7 @@
1191212421 }
1191312422
1191412423 //for (int count = parentcam.GetTransformCount(); --count>=0;)
11915
- LA.xformPos(light, parentcam.GlobalTransformInv(), light); // may 2013
12424
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1191612425
1191712426 LA.xformPos(light, renderCamera.toScreen, light);
1191812427
....@@ -12002,8 +12511,76 @@
1200212511
1200312512 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1200412513
12005
- String program =
12514
+ String programmin =
12515
+ // Min shader
1200612516 "!!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
+
1200712584 //"OPTION ARB_fragment_program_shadow;" +
1200812585 "PARAM light2cam0 = program.env[10];" +
1200912586 "PARAM light2cam1 = program.env[11];" +
....@@ -12029,7 +12606,7 @@
1202912606 "PARAM params4 = program.env[4];" + // anisoV, cameralight, selfshadow, shadow
1203012607 "PARAM params5 = program.env[5];" + // texture, opacity, fakedepth, shadowbias
1203112608 "PARAM params6 = program.env[6];" + // bump, noise, borderfade, fog punchthrough
12032
- "PARAM params7 = program.env[7];" + // noise power, opacity power
12609
+ "PARAM params7 = program.env[7];" + // noise power, opacity power, parallax
1203312610 "PARAM options0 = program.env[63];" + // fog density, intensity, elevation
1203412611 "PARAM options1 = program.env[62];" + // fog rgb color
1203512612 "PARAM options2 = program.env[61];" + // image intensity, subsurface, lightsheen
....@@ -12118,8 +12695,7 @@
1211812695 "TEMP shininess;" +
1211912696 "\n" +
1212012697 "MOV texSamp, one;" +
12121
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12122
-
12698
+
1212312699 "MOV mapgrid.x, one2048th.x;" +
1212412700 "MOV temp, fragment.texcoord[1];" +
1212512701 /*
....@@ -12140,20 +12716,20 @@
1214012716 "MUL temp, floor, mapgrid.x;" +
1214112717 //"TEX depth0, temp, texture[1], 2D;" +
1214212718 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12143
- TextureFetch("depth0", "temp", "1") +
12719
+ ShadowTextureFetch("depth0", "temp", "1") +
1214412720 "") +
1214512721 "ADD temp.x, temp.x, mapgrid.x;" +
1214612722 //"TEX depth1, temp, texture[1], 2D;" +
1214712723 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12148
- TextureFetch("depth1", "temp", "1") +
12724
+ ShadowTextureFetch("depth1", "temp", "1") +
1214912725 "") +
1215012726 "ADD temp.y, temp.y, mapgrid.x;" +
1215112727 //"TEX depth2, temp, texture[1], 2D;" +
12152
- TextureFetch("depth2", "temp", "1") +
12728
+ ShadowTextureFetch("depth2", "temp", "1") +
1215312729 "SUB temp.x, temp.x, mapgrid.x;" +
1215412730 //"TEX depth3, temp, texture[1], 2D;" +
1215512731 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12156
- TextureFetch("depth3", "temp", "1") +
12732
+ ShadowTextureFetch("depth3", "temp", "1") +
1215712733 "") +
1215812734 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1215912735 //"MOV params, material;" +
....@@ -12275,7 +12851,7 @@
1227512851 "POW texSamp.a, texSamp.a, params6.w;" + // fog punch through shortcut
1227612852 // mar 2013 ??? "KIL alpha.a;" +
1227712853 "MOV alpha, texSamp.aaaa;" + // y;" +
12278
- "KIL alpha.a;" +
12854
+ "KIL alpha.a;" + // not sure with parallax mapping
1227912855 /*
1228012856 "MUL temp.xy, temp, two;" +
1228112857 "TXB bump, temp, texture[0], 2D;" +
....@@ -12361,11 +12937,6 @@
1236112937 "SUB bump0, bump0, half;" +
1236212938 "ADD bump, bump, bump0;" +
1236312939
12364
- "MOV temp.x, texSamp.a;" +
12365
- "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
12366
- //"LRP texSamp0, params5.x, texSamp0, one;" +
12367
- "MOV texSamp.a, temp.x;" +
12368
-
1236912940 // double-sided
1237012941 /**/
1237112942 (doublesided?"DP3 temp.z, normal, eye;" +
....@@ -12382,19 +12953,62 @@
1238212953 "MOV normald, normal;" +
1238312954 "MOV normals, normal;" +
1238412955
12956
+ "MOV temp, fragment.texcoord[4];" +
12957
+
1238512958 // UV base
1238612959 //"DP3 UP.x,state.matrix.modelview.row[0],Y;" +
1238712960 //"DP3 UP.y,state.matrix.modelview.row[1],Y;" +
1238812961 //"DP3 UP.z,state.matrix.modelview.row[2],Y;" +
12389
- "DP3 UP.x,state.matrix.texture[7].row[0],Y;" +
12390
- "DP3 UP.y,state.matrix.texture[7].row[1],Y;" +
12391
- "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
+
1239212967 "XPD V, normal, UP;" +
1239312968 Normalize("V") +
1239412969 "XPD U, V, normal;" +
1239512970 Normalize("U") +
1239612971
1239712972 // 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 temp.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;" +
1239813012
1239913013 //"MOV temp, fragment.texcoord[0];" +
1240013014 //
....@@ -12524,10 +13138,10 @@
1252413138 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1252513139 "") +
1252613140
12527
- // display shadow only (bump == 0)
13141
+ // display shadow only (fakedepth == 0)
1252813142 "SUB temp.x, half.x, shadow.x;" +
1252913143 "MOV temp.y, -params5.z;" + // params6.x;" +
12530
- "SLT temp.z, temp.y, -one2048th.x;" +
13144
+ "SLT temp.z, temp.y, -c256i.x;" +
1253113145 "SUB temp.y, one.x, temp.z;" +
1253213146 "MUL temp.x, temp.x, temp.y;" +
1253313147 "KIL temp.x;" +
....@@ -12858,8 +13472,19 @@
1285813472 //once = true;
1285913473 }
1286013474
12861
- System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
12862
- 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
+
1286313488 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1286413489
1286513490 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -12906,7 +13531,8 @@
1290613531 "\n" +
1290713532 "END\n";
1290813533
12909
- System.out.println("Program shadow #" + 0 + "; length = " + program.length());
13534
+ if (Globals.DEBUG)
13535
+ System.out.println("Program shadow #" + 0 + "; length = " + program.length());
1291013536 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1291113537
1291213538 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -12951,25 +13577,26 @@
1295113577 return out;
1295213578 }
1295313579
12954
- String TextureFetch(String dest, String src, String unit)
13580
+ // Also does frustum culling
13581
+ String ShadowTextureFetch(String dest, String src, String unit)
1295513582 {
1295613583 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1295713584 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1295813585 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13586
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13587
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1295913588 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12960
- "SLT " + src + ".z, " + src + ".x, one.x;" +
12961
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12962
- "SLT " + src + ".z, " + src + ".y, one.x;" +
12963
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13589
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13590
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1296413591 //"SWZ buffer, temp, w,w,w,w;";
12965
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13592
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1296613593 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1296713594 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1296813595 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
12969
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13596
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1297013597
12971
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
12972
- //"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;";
1297313600 }
1297413601
1297513602 String Shadow(String depth, String shadow)
....@@ -13016,7 +13643,7 @@
1301613643 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1301713644 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1301813645
13019
- // No shadow when out of frustrum
13646
+ // No shadow when out of frustum
1302013647 "SGE temp.x, " + depth + ".z, one.z;" +
1302113648 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1302213649 "";
....@@ -13163,8 +13790,9 @@
1316313790 /*static*/ float[] modelParams4 = new float[]{0, 0, 0, 0}; // anisoV, cameralight, selfshadow, shadow
1316413791 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1316513792 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
13166
- /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13167
- Object3D.cVector2[] vector2buffer;
13793
+ /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power, parallax
13794
+
13795
+ //Object3D.cVector2[] vector2buffer;
1316813796
1316913797 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1317013798 // OUT : diff, spec
....@@ -13180,9 +13808,10 @@
1318013808 "DP3 " + dest + ".z," + "normals," + "eye;" +
1318113809 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1318213810 //"MOV " + dest + ".w," + "normal.z;" +
13183
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
13184
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13185
- //"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
1318613815 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1318713816 "RCP " + dest + ".w," + dest + ".w;" +
1318813817 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13328,7 +13957,7 @@
1332813957 "PARAM p[4] = { state.matrix.projection }; # modelview projection matrix\n" +
1332913958 "PARAM zero = { 0.0, 0.0, 0.0, 1.0 };" +
1333013959 "PARAM half = { 0.5, 0.5, 0.5, 1.0 };" +
13331
- "PARAM one = { 1.0, 1.0, 1.0, 0.0 };" +
13960
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
1333213961 "PARAM two = { 2.0, 2.0, 2.0, 1.0 };" +
1333313962 "PARAM third = { 0.33333333333, 0.33333333333, 0.33333333333, 1.0 };" +
1333413963 //"PARAM v256 = { 256.0, 256.0, 256.0, 1.0 };" +
....@@ -13389,7 +14018,7 @@
1338914018 "DP4 temp.x,state.matrix.texture[0].inverse.row[0],vertex.texcoord;" +
1339014019 "DP4 temp.y,state.matrix.texture[0].inverse.row[1],vertex.texcoord;" +
1339114020 "DP4 temp.z,state.matrix.texture[0].inverse.row[2],vertex.texcoord;" +
13392
- //"MOV result.texcoord, vertex.texcoord;" +
14021
+ //"MOV result.texcoord, vertex.fogcoord;" +
1339314022 "MOV result.texcoord, temp;" +
1339414023 // border fade
1339514024 "MOV result.texcoord[3], vertex.texcoord;" +
....@@ -13436,7 +14065,9 @@
1343614065
1343714066 //"ADD temp.z, temp.z, one;" +
1343814067
13439
- "MOV result.color, temp;"
14068
+ "MOV result.texcoord[4], vertex.attrib[4];" + // U dir
14069
+
14070
+ "MOV result.color, temp;" // Normal
1344014071 : "MOV result.color, vertex.color;") +
1344114072 ((mode & VP_PROJECTION) != 0 ? "MOV result.color, zero;"
1344214073 : "") +
....@@ -13687,6 +14318,7 @@
1368714318 else
1368814319 if (evt.getSource() == AAtimer)
1368914320 {
14321
+ Globals.TIMERRUNNING = false;
1369014322 if (mouseDown)
1369114323 {
1369214324 //new Exception().printStackTrace();
....@@ -13746,7 +14378,7 @@
1374614378
1374714379 // fev 2014???
1374814380 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13749
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14381
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1375014382 pingthread.StepToTarget(true); // true);
1375114383 }
1375214384 // if (!LIVE)
....@@ -13761,6 +14393,7 @@
1376114393 return;
1376214394
1376314395 AAtimer.restart(); //
14396
+ Globals.TIMERRUNNING = true;
1376414397
1376514398 // waslive = LIVE;
1376614399 // LIVE = false;
....@@ -13810,14 +14443,15 @@
1381014443 drag = false;
1381114444 //System.out.println("Mouse DOWN");
1381214445 editObj = false;
13813
- ClickInfo info = new ClickInfo();
13814
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
13815
- info.pane = this;
13816
- info.camera = renderCamera;
13817
- info.x = x;
13818
- info.y = y;
13819
- info.modifiers = modifiersex;
13820
- 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);
1382114455 if (!editObj)
1382214456 {
1382314457 hasMarquee = true;
....@@ -13833,6 +14467,8 @@
1383314467
1383414468 public void mouseDragged(MouseEvent e)
1383514469 {
14470
+ Globals.MOUSEDRAGGED = true;
14471
+
1383614472 //System.out.println("mouseDragged: " + e);
1383714473 if (isRenderer)
1383814474 movingcamera = true;
....@@ -14097,12 +14733,18 @@
1409714733 void GoDown(int mod)
1409814734 {
1409914735 MODIFIERS |= COMMAND;
14100
- /*
14736
+ boolean isVR = (mouseMode&VR)!=0;
14737
+ /**/
1410114738 if((mod&SHIFT) == SHIFT)
14102
- manipCamera.RotatePosition(0, -speed);
14739
+ {
14740
+ if (isVR)
14741
+ manipCamera.RotateInterest(0, -speed);
14742
+ else
14743
+ manipCamera.RotatePosition(0, -speed);
14744
+ }
1410314745 else
14104
- manipCamera.BackForth(0, -speed*delta, getWidth());
14105
- */
14746
+ manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth());
14747
+ /**/
1410614748 if ((mod & SHIFT) == SHIFT)
1410714749 {
1410814750 mouseMode = mouseMode; // VR??
....@@ -14111,6 +14753,8 @@
1411114753 mouseMode |= BACKFORTH;
1411214754 }
1411314755
14756
+ targetLookAt.set(manipCamera.lookAt);
14757
+
1411414758 //prevX = X = anchorX;
1411514759 prevY = Y = anchorY - (int) (renderCamera.Distance());
1411614760 }
....@@ -14118,12 +14762,19 @@
1411814762 void GoUp(int mod)
1411914763 {
1412014764 MODIFIERS |= COMMAND;
14121
- /*
14765
+ /**/
14766
+ boolean isVR = (mouseMode&VR)!=0;
14767
+
1412214768 if((mod&SHIFT) == SHIFT)
14123
- manipCamera.RotatePosition(0, speed);
14769
+ {
14770
+ if (isVR)
14771
+ manipCamera.RotateInterest(0, speed);
14772
+ else
14773
+ manipCamera.RotatePosition(0, speed);
14774
+ }
1412414775 else
14125
- manipCamera.BackForth(0, speed*delta, getWidth());
14126
- */
14776
+ manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth());
14777
+ /**/
1412714778 if ((mod & SHIFT) == SHIFT)
1412814779 {
1412914780 mouseMode = mouseMode;
....@@ -14132,6 +14783,8 @@
1413214783 mouseMode |= BACKFORTH;
1413314784 }
1413414785
14786
+ targetLookAt.set(manipCamera.lookAt);
14787
+
1413514788 //prevX = X = anchorX;
1413614789 prevY = Y = anchorY + (int) (renderCamera.Distance());
1413714790 }
....@@ -14139,12 +14792,17 @@
1413914792 void GoLeft(int mod)
1414014793 {
1414114794 MODIFIERS |= COMMAND;
14142
- /*
14795
+ /**/
1414314796 if((mod&SHIFT) == SHIFT)
14144
- manipCamera.RotatePosition(speed, 0);
14797
+ manipCamera.Translate(speed*delta, 0, getWidth());
1414514798 else
14146
- manipCamera.Translate(speed*delta, 0, getWidth());
14147
- */
14799
+ {
14800
+ if ((mouseMode&VR)!=0)
14801
+ manipCamera.RotateInterest(-speed, 0);
14802
+ else
14803
+ manipCamera.RotatePosition(speed, 0);
14804
+ }
14805
+ /**/
1414814806 if ((mod & SHIFT) == SHIFT)
1414914807 {
1415014808 mouseMode = mouseMode;
....@@ -14153,6 +14811,8 @@
1415314811 mouseMode |= ROTATE;
1415414812 } // TRANSLATE;
1415514813
14814
+ targetLookAt.set(manipCamera.lookAt);
14815
+
1415614816 prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance());
1415714817 prevY = Y = anchorY;
1415814818 }
....@@ -14160,12 +14820,18 @@
1416014820 void GoRight(int mod)
1416114821 {
1416214822 MODIFIERS |= COMMAND;
14163
- /*
14823
+ /**/
1416414824 if((mod&SHIFT) == SHIFT)
14165
- manipCamera.RotatePosition(-speed, 0);
14825
+ manipCamera.Translate(-speed*delta, 0, getWidth());
1416614826 else
14167
- manipCamera.Translate(-speed*delta, 0, getWidth());
14168
- */
14827
+ {
14828
+ if ((mouseMode&VR)!=0)
14829
+ manipCamera.RotateInterest(speed, 0);
14830
+ else
14831
+ manipCamera.RotatePosition(-speed, 0);
14832
+ }
14833
+
14834
+ /**/
1416914835 if ((mod & SHIFT) == SHIFT)
1417014836 {
1417114837 mouseMode = mouseMode;
....@@ -14174,6 +14840,8 @@
1417414840 mouseMode |= ROTATE;
1417514841 } // TRANSLATE;
1417614842
14843
+ targetLookAt.set(manipCamera.lookAt);
14844
+
1417714845 prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance());
1417814846 prevY = Y = anchorY;
1417914847 }
....@@ -14215,14 +14883,16 @@
1421514883 if (editObj)
1421614884 {
1421714885 drag = true;
14218
- ClickInfo info = new ClickInfo();
14219
- info.bounds.setBounds(0, 0,
14886
+ //ClickInfo info = new ClickInfo();
14887
+ object.clickInfo.bounds.setBounds(0, 0,
1422014888 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14221
- info.pane = this;
14222
- info.camera = renderCamera;
14223
- info.x = x;
14224
- info.y = y;
14225
- object.editWindow.copy.doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
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);
1422614896 } else
1422714897 {
1422814898 if (x < startX)
....@@ -14371,22 +15041,27 @@
1437115041 }
1437215042 }
1437315043
15044
+// ClickInfo clickInfo = new ClickInfo();
15045
+
1437415046 public void mouseMoved(MouseEvent e)
1437515047 {
1437615048 //System.out.println("mouseMoved: " + e);
1437715049 if (isRenderer)
1437815050 return;
1437915051
14380
- ClickInfo ci = new ClickInfo();
14381
- ci.x = e.getX();
14382
- ci.y = e.getY();
14383
- ci.modifiers = e.getModifiersEx();
14384
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14385
- ci.pane = this;
14386
- 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;
1438715059 if (!isRenderer)
1438815060 {
14389
- if (object.editWindow.copy.doEditClick(ci, 0))
15061
+ //ObjEditor editWindow = object.editWindow;
15062
+ //Object3D copy = editWindow.copy;
15063
+ if (object.doEditClick(//clickInfo,
15064
+ 0))
1439015065 {
1439115066 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1439215067 } else
....@@ -14398,8 +15073,11 @@
1439815073
1439915074 public void mouseReleased(MouseEvent e)
1440015075 {
15076
+ Globals.MOUSEDRAGGED = false;
15077
+
1440115078 movingcamera = false;
14402
- X = Y = 0;
15079
+ X = 0; // getBounds().width/2;
15080
+ Y = 0; // getBounds().height/2;
1440315081 //System.out.println("mouseReleased: " + e);
1440415082 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1440515083 }
....@@ -14655,7 +15333,8 @@
1465515333 // break;
1465615334 case 'T':
1465715335 CACHETEXTURE ^= true;
14658
- textures.clear();
15336
+ texturepigment.clear();
15337
+ texturebump.clear();
1465915338 // repaint();
1466015339 break;
1466115340 case 'Y':
....@@ -14665,8 +15344,8 @@
1466515344 case 'K':
1466615345 KOMPACTTEXTURE ^= true;
1466715346 //textures.clear();
14668
- break;
14669
- case 'P': // Texture Projection macros
15347
+ // break;
15348
+ //case 'P': // Texture Projection macros
1467015349 // SAVETEXTURE ^= true;
1467115350 macromode = true;
1467215351 Udebug = Vdebug = NORMALdebug = false; programInitialized = false;
....@@ -14740,7 +15419,9 @@
1474015419 case 'E' : COMPACT ^= true;
1474115420 repaint();
1474215421 break;
14743
- case 'W' : DEBUGHSB ^= true;
15422
+ case 'W' : // Wide Window (fullscreen)
15423
+ //DEBUGHSB ^= true;
15424
+ ObjEditor.theFrame.ToggleFullScreen();
1474415425 repaint();
1474515426 break;
1474615427 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14765,8 +15446,8 @@
1476515446 RevertCamera();
1476615447 repaint();
1476715448 break;
14768
- case 'L':
1476915449 case 'l':
15450
+ //case 'L':
1477015451 if (lightMode)
1477115452 {
1477215453 lightMode = false;
....@@ -14785,7 +15466,7 @@
1478515466 targetLookAt.set(manipCamera.lookAt);
1478615467 repaint();
1478715468 break;
14788
- case 'p':
15469
+ case 'P': // p':
1478915470 // c'est quoi ca au juste? spherical ^= true;
1479015471 Skinshader ^= true; programInitialized = false;
1479115472 repaint();
....@@ -14830,20 +15511,24 @@
1483015511 OCCLUSION_CULLING ^= true;
1483115512 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1483215513 break;
14833
- case '0': envyoff ^= true; repaint(); break;
15514
+ //case '0': envyoff ^= true; repaint(); break;
1483415515 case '1':
1483515516 case '2':
1483615517 case '3':
1483715518 case '4':
1483815519 case '5':
14839
- newenvy = Character.getNumericValue(key);
14840
- repaint();
14841
- break;
1484215520 case '6':
1484315521 case '7':
1484415522 case '8':
1484515523 case '9':
14846
- 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
+ }
1484715532 repaint();
1484815533 break;
1484915534 case '!':
....@@ -14909,9 +15594,9 @@
1490915594 case '_':
1491015595 kompactbit = 5;
1491115596 break;
14912
- case '+':
14913
- kompactbit = 6;
14914
- break;
15597
+// case '+':
15598
+// kompactbit = 6;
15599
+// break;
1491515600 case ' ':
1491615601 lightMode ^= true;
1491715602 Globals.lighttouched = true;
....@@ -14923,6 +15608,7 @@
1492315608 case ESC:
1492415609 RENDERPROGRAM += 1;
1492515610 RENDERPROGRAM %= 3;
15611
+
1492615612 repaint();
1492715613 break;
1492815614 case 'Z':
....@@ -14962,8 +15648,9 @@
1496215648 case DELETE:
1496315649 ClearSelection();
1496415650 break;
14965
- /*
1496615651 case '+':
15652
+
15653
+ /*
1496715654 //fontsize += 1;
1496815655 bbzoom *= 2;
1496915656 repaint();
....@@ -14980,17 +15667,17 @@
1498015667 case '=':
1498115668 IncDepth();
1498215669 //fontsize += 1;
14983
- object.editWindow.refreshContents(true);
15670
+ object.GetWindow().refreshContents(true);
1498415671 maskbit = 6;
1498515672 break;
1498615673 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1498715674 DecDepth();
1498815675 maskbit = 5;
1498915676 //if(fontsize > 1) fontsize -= 1;
14990
- if (object.editWindow == null)
14991
- new Exception().printStackTrace();
14992
- else
14993
- object.editWindow.refreshContents(true);
15677
+// if (object.editWindow == null)
15678
+// new Exception().printStackTrace();
15679
+// else
15680
+ object.GetWindow().refreshContents(true);
1499415681 break;
1499515682 case '{':
1499615683 manipCamera.shaper_fovy /= 1.1;
....@@ -15214,7 +15901,7 @@
1521415901 }
1521515902 */
1521615903
15217
- object.editWindow.EditSelection();
15904
+ object.GetWindow().EditSelection(false);
1521815905 }
1521915906
1522015907 void SelectParent()
....@@ -15231,10 +15918,10 @@
1523115918 {
1523215919 //selectees.remove(i);
1523315920 System.out.println("select parent of " + elem);
15234
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15921
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1523515922 } else
1523615923 {
15237
- group.editWindow.Select(elem.GetTreePath(), first, true);
15924
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1523815925 }
1523915926
1524015927 first = false;
....@@ -15276,12 +15963,12 @@
1527615963 for (int j = 0; j < group.children.size(); j++)
1527715964 {
1527815965 elem = (Object3D) group.children.elementAt(j);
15279
- object.editWindow.Select(elem.GetTreePath(), first, true);
15966
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1528015967 first = false;
1528115968 }
1528215969 } else
1528315970 {
15284
- object.editWindow.Select(elem.GetTreePath(), first, true);
15971
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1528515972 }
1528615973
1528715974 first = false;
....@@ -15292,21 +15979,21 @@
1529215979 {
1529315980 //Composite group = (Composite) object;
1529415981 Object3D group = object;
15295
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15982
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1529615983 }
1529715984
1529815985 void ResetTransform(int mask)
1529915986 {
1530015987 //Composite group = (Composite) object;
1530115988 Object3D group = object;
15302
- group.editWindow.ResetTransform(mask);
15989
+ group.GetWindow().ResetTransform(mask);
1530315990 }
1530415991
1530515992 void FlipTransform()
1530615993 {
1530715994 //Composite group = (Composite) object;
1530815995 Object3D group = object;
15309
- group.editWindow.FlipTransform();
15996
+ group.GetWindow().FlipTransform();
1531015997 // group.editWindow.ReduceMesh(true);
1531115998 }
1531215999
....@@ -15314,7 +16001,7 @@
1531416001 {
1531516002 //Composite group = (Composite) object;
1531616003 Object3D group = object;
15317
- group.editWindow.PrintMemory();
16004
+ group.GetWindow().PrintMemory();
1531816005 // group.editWindow.ReduceMesh(true);
1531916006 }
1532016007
....@@ -15322,7 +16009,7 @@
1532216009 {
1532316010 //Composite group = (Composite) object;
1532416011 Object3D group = object;
15325
- group.editWindow.ResetCentroid();
16012
+ group.GetWindow().ResetCentroid();
1532616013 }
1532716014
1532816015 void IncDepth()
....@@ -15404,8 +16091,6 @@
1540416091
1540516092 int width = getBounds().width;
1540616093 int height = getBounds().height;
15407
- ClickInfo info = new ClickInfo();
15408
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1540916094 //Image img = CreateImage(width, height);
1541016095 //System.out.println("width = " + width + "; height = " + height + "\n");
1541116096
....@@ -15482,43 +16167,77 @@
1548216167 }
1548316168 if (object != null && !hasMarquee)
1548416169 {
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
+
1548516176 if (isRenderer)
1548616177 {
15487
- info.flags++;
16178
+ object.clickInfo.flags++;
1548816179 double frameAspect = (double) width / (double) height;
1548916180 if (frameAspect > renderCamera.aspect)
1549016181 {
1549116182 int desired = (int) ((double) height * renderCamera.aspect);
15492
- info.bounds.width -= width - desired;
15493
- info.bounds.x += (width - desired) / 2;
16183
+ object.clickInfo.bounds.width -= width - desired;
16184
+ object.clickInfo.bounds.x += (width - desired) / 2;
1549416185 } else
1549516186 {
1549616187 int desired = (int) ((double) width / renderCamera.aspect);
15497
- info.bounds.height -= height - desired;
15498
- info.bounds.y += (height - desired) / 2;
16188
+ object.clickInfo.bounds.height -= height - desired;
16189
+ object.clickInfo.bounds.y += (height - desired) / 2;
1549916190 }
1550016191 }
15501
- info.g = gr;
15502
- info.camera = renderCamera;
16192
+
16193
+ object.clickInfo.g = gr;
16194
+ object.clickInfo.camera = renderCamera;
1550316195 /*
1550416196 // Memory intensive (brep.verticescopy)
1550516197 if (!(object instanceof Composite))
1550616198 object.draw(info, 0, false); // SLOW :
1550716199 */
15508
- if (!isRenderer)
16200
+ if (!isRenderer) // && drag)
1550916201 {
15510
- object.drawEditHandles(info, 0);
15511
-
15512
- if (drag && (X != 0 || Y != 0) && object.selection.Size() > 0)
16202
+ Grafreed.Assert(object != null);
16203
+ Grafreed.Assert(object.selection != null);
16204
+ if (object.selection.Size() > 0)
1551316205 {
15514
- switch (object.selection.get(0).hitSomething)
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)
1551516212 {
15516
- case Object3D.hitCenter: gr.setColor(Color.pink); break;
15517
- case Object3D.hitRotate: gr.setColor(Color.green); break;
15518
- case Object3D.hitScale: gr.setColor(Color.cyan); break;
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;
1551916220 }
15520
-
15521
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
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
+ }
1552216241 }
1552316242 }
1552416243 }
....@@ -15533,7 +16252,7 @@
1553316252 if (hasMarquee)
1553416253 {
1553516254 gr.setXORMode(Color.white);
15536
- gr.setColor(Color.red);
16255
+ gr.setColor(Color.white);
1553716256 if (!firstime)
1553816257 {
1553916258 gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH);
....@@ -16000,6 +16719,8 @@
1600016719 private /*static*/ boolean firstime;
1600116720 private /*static*/ cVector newView = new cVector();
1600216721 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"};
1600316724 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1600416725 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1600516726 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16012,29 +16733,67 @@
1601216733 {
1601316734 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1601416735
16736
+ int usedsuf = 0;
16737
+
1601516738 for (int i = 0; i < suffixes.length; i++)
1601616739 {
16017
- String resourceName = basename + suffixes[i] + "." + suffix;
16018
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16019
- mipmapped,
16020
- FileUtil.getFileSuffix(resourceName));
16021
- if (data == null)
16740
+ String[] suffixe = suffixes;
16741
+ String[] fallback = suffixes2;
16742
+ String[] fallfallback = suffixes3;
16743
+
16744
+ for (int c=usedsuf; --c>=0;)
1602216745 {
16023
- throw new IOException("Unable to load texture " + resourceName);
16746
+// String[] temp = suffixe;
16747
+// suffixe = fallback;
16748
+// fallback = fallfallback;
16749
+// fallfallback = temp;
1602416750 }
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
+
1602516779 //System.out.println("Target = " + targets[i]);
1602616780 cubemap.updateImage(data, targets[i]);
1602716781 }
1602816782
1602916783 return cubemap;
1603016784 }
16785
+
1603116786 int bigsphere = -1;
1603216787
1603316788 float BGcolor = 0.5f;
1603416789
16035
- private void DrawSkyBox(GL gl)
16790
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16791
+
16792
+ private void DrawSkyBox(GL gl, float ratio)
1603616793 {
16037
- if (envyoff || cubemap == null)
16794
+ if (//envyoff ||
16795
+ WIREFRAME ||
16796
+ cubemap == null)
1603816797 {
1603916798 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1604016799 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16049,7 +16808,17 @@
1604916808 // Compensates for ExaminerViewer's modification of modelview matrix
1605016809 gl.glMatrixMode(GL.GL_MODELVIEW);
1605116810 gl.glLoadIdentity();
16811
+ gl.glScalef(1,ratio,1);
1605216812
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
+
1605316822 //gl.glActiveTexture(GL.GL_TEXTURE1);
1605416823 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1605516824
....@@ -16081,6 +16850,7 @@
1608116850 {
1608216851 gl.glScalef(1.0f, -1.0f, 1.0f);
1608316852 }
16853
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1608416854 gl.glMultMatrixd(viewrot_1, 0);
1608516855 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1608616856 //viewer.updateInverseRotation(gl);
....@@ -16121,7 +16891,8 @@
1612116891 gl.glDisable(GL.GL_TEXTURE_GEN_R);
1612216892
1612316893 cubemap.disable();
16124
- ////cubemap.unbind();
16894
+ //cubemap.dispose();
16895
+
1612516896 if (CULLFACE)
1612616897 {
1612716898 gl.glEnable(gl.GL_CULL_FACE);
....@@ -16177,7 +16948,7 @@
1617716948 gl.glScalef(1.0f, -1.0f, 1.0f);
1617816949 }
1617916950
16180
- gl.glNormal3f(0.0f, 0.0f, 1.0f);
16951
+ SetGLNormal(gl, 0.0f, 0.0f, 1.0f);
1618116952
1618216953 float step = 2; // 0.1666f; //0.25f;
1618316954 float stepv = 2; // step * 1652 / 998;
....@@ -16221,16 +16992,16 @@
1622116992 cStatic.objectstack[materialdepth++] = checker;
1622216993 //System.out.println("material " + material);
1622316994 //Applet3D.tracein(this, selected);
16224
- vector2buffer = checker.projectedVertices;
16995
+ //vector2buffer = checker.projectedVertices;
1622516996
1622616997 //checker.GetMaterial().Draw(this, false); // true);
16227
- DrawMaterial(checker.GetMaterial(), false); // true);
16998
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1622816999
1622917000 materialdepth -= 1;
1623017001 if (materialdepth > 0)
1623117002 {
16232
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16233
- 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);
1623417005 }
1623517006 //checker.GetMaterial().opacity = 1f;
1623617007 ////checker.GetMaterial().ambient = 1f;
....@@ -16316,6 +17087,14 @@
1631617087 }
1631717088 }
1631817089
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
+
1631917098 class SelectBuffer implements GLEventListener
1632017099 {
1632117100
....@@ -16331,7 +17110,7 @@
1633117110 //new Exception().printStackTrace();
1633217111 System.out.println("select buffer init");
1633317112 // Use debug pipeline
16334
- drawable.setGL(new DebugGL(drawable.getGL()));
17113
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1633517114
1633617115 GL gl = drawable.getGL();
1633717116
....@@ -16395,6 +17174,17 @@
1639517174
1639617175 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1639717176
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
+
1639817188 //int tmp = selection_view;
1639917189 //selection_view = -1;
1640017190 int temp = DrawMode();
....@@ -16406,6 +17196,17 @@
1640617196 // temp = DEFAULT; // patch for selection debug
1640717197 Globals.drawMode = temp; // WARNING
1640817198
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
+
1640917210 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1641017211
1641117212 // trying different ways of getting the depth info over
....@@ -16453,6 +17254,8 @@
1645317254 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1645417255 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1645517256 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
17257
+
17258
+ CreateSelectedPoint();
1645617259
1645717260 // Will fit the mesh !!!
1645817261 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16507,29 +17310,31 @@
1650717310 }
1650817311
1650917312 if (!movingcamera && !PAINTMODE)
16510
- object.editWindow.ScreenFitPoint(); // fev 2014
17313
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1651117314
16512
- 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)
1651317316 {
16514
- 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);
1651517318
16516
- Object3D group = new Object3D("inst" + paintcount++);
17319
+ if (object.GetWindow().copy.selection.Size() > 0)
17320
+ {
17321
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1651717322
16518
- group.CreateMaterial(); // use a void leaf to select instances
16519
-
16520
- group.add(paintobj); // link
16521
-
16522
- object.editWindow.SnapObject(group);
16523
-
16524
- Object3D folder = object.editWindow.copy;
16525
-
16526
- if (object.editWindow.copy.selection.Size() > 0)
16527
- folder = object.editWindow.copy.selection.elementAt(0);
16528
-
16529
- folder.add(group);
16530
-
16531
- object.editWindow.ResetModel();
16532
- 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
+ }
1653317338 }
1653417339 else
1653517340 paintcount = 0;
....@@ -16568,6 +17373,11 @@
1656817373 //System.out.println("objects[color] = " + objects[color]);
1656917374 //objects[color].Select();
1657017375 indexcount = 0;
17376
+ ObjEditor window = object.GetWindow();
17377
+ if (window != null && deselect)
17378
+ {
17379
+ window.Select(null, deselect, true);
17380
+ }
1657117381 object.Select(color, deselect);
1657217382 }
1657317383
....@@ -16618,6 +17428,7 @@
1661817428
1661917429 public void init(GLAutoDrawable drawable)
1662017430 {
17431
+ if (Globals.DEBUG)
1662117432 System.out.println("shadow buffer init");
1662217433
1662317434 GL gl = drawable.getGL();
....@@ -16846,10 +17657,14 @@
1684617657 gl.glFlush();
1684717658
1684817659 /**/
16849
- 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);
1685017661
16851
- float[] pixels = occlusionsizebuffer.array();
17662
+ float[] depths = occlusiondepthbuffer.array();
1685217663
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
+
1685317668 double r = 0, g = 0, b = 0;
1685417669
1685517670 double count = 0;
....@@ -16860,7 +17675,7 @@
1686017675
1686117676 double FACTOR = 1;
1686217677
16863
- for (int i = 0; i < pixels.length; i++)
17678
+ for (int i = 0; i < depths.length; i++)
1686417679 {
1686517680 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1686617681 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -16943,7 +17758,7 @@
1694317758
1694417759 double scale = ray.z; // 1; // cos
1694517760
16946
- float depth = pixels[newindex];
17761
+ float depth = depths[newindex];
1694717762
1694817763 /*
1694917764 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -17093,23 +17908,15 @@
1709317908 int AAbuffersize = 0;
1709417909
1709517910 //double[] selectedpoint = new double[3];
17096
- static Superellipsoid selectedpoint = new Superellipsoid();
17911
+ static Superellipsoid selectedpoint;
1709717912 static Sphere previousselectedpoint = null;
17098
- static Sphere debugpointG = new Sphere();
17099
- static Sphere debugpointP = new Sphere();
17100
- static Sphere debugpointC = new Sphere();
17101
- static Sphere debugpointR = new Sphere();
17913
+ static Sphere debugpointG;
17914
+ static Sphere debugpointP;
17915
+ static Sphere debugpointC;
17916
+ static Sphere debugpointR;
1710217917
1710317918 static Sphere debugpoints[] = new Sphere[8];
1710417919
17105
- static
17106
- {
17107
- for (int i=0; i<8; i++)
17108
- {
17109
- debugpoints[i] = new Sphere();
17110
- }
17111
- }
17112
-
1711317920 static void InitPoints(float radius)
1711417921 {
1711517922 for (int i=0; i<8; i++)
....@@ -17148,11 +17955,14 @@
1714817955 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1714917956 static IntBuffer bigAAbuffer;
1715017957 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
17151
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17958
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1715217959 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1715317960 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1715417961 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17155
- 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
+
1715617966 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1715717967 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1715817968 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();