Normand Briere
2019-08-22 6a145f6c81dfcbe0653eda27d042efb48daa7512
CameraPane.java
....@@ -18,7 +18,10 @@
1818 import javax.imageio.ImageIO;
1919 import javax.imageio.ImageWriteParam;
2020 import javax.imageio.ImageWriter;
21
+import javax.imageio.ImageReadParam;
22
+import javax.imageio.ImageReader;
2123 import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
24
+import javax.imageio.stream.ImageInputStream;
2225 import javax.imageio.stream.ImageOutputStream;
2326 import javax.imageio.ImageWriteParam;
2427
....@@ -30,6 +33,7 @@
3033 import java.nio.*;
3134
3235 import gleem.linalg.Mat4f;
36
+import javax.imageio.ImageTypeSpecifier;
3337
3438 class CameraPane extends GLCanvas implements iCameraPane, Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener
3539 {
....@@ -37,7 +41,6 @@
3741 static boolean[] selectedstack = new boolean[65536];
3842 static int materialdepth = 0;
3943
40
- static boolean DEBUG = false;
4144 static boolean FRUSTUM = false; // still bogus true; // frustum culling
4245
4346 // camera change fix
....@@ -45,6 +48,39 @@
4548 static boolean ABORTED = false;
4649
4750 static int STEP = 1;
51
+
52
+ private static BufferedImage CreateBim(byte[] bytes, int width, int height)
53
+ {
54
+ int[] pixels = new int[bytes.length/3];
55
+ for (int i=pixels.length; --i>=0;)
56
+ {
57
+ int i3 = i*3;
58
+ pixels[i] = 0xFF;
59
+ pixels[i] <<= 8;
60
+ pixels[i] |= bytes[i3+2] & 0xFF;
61
+ pixels[i] <<= 8;
62
+ pixels[i] |= bytes[i3+1] & 0xFF;
63
+ pixels[i] <<= 8;
64
+ pixels[i] |= bytes[i3] & 0xFF;
65
+ }
66
+ /*
67
+ int r=0,g=0,b=0,a=0;
68
+ for (int i=0; i<width; i++)
69
+ for (int j=0; j<height; j++)
70
+ {
71
+ int index = j*width+i;
72
+ int p = pixels[index];
73
+ a = ((p>>24) & 0xFF);
74
+ r = ((p>>16) & 0xFF);
75
+ g = ((p>>8) & 0xFF);
76
+ b = (p & 0xFF);
77
+ pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
78
+ }
79
+ /**/
80
+ BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
81
+ rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
82
+ return rendImage;
83
+ }
4884
4985 /*static*/ private boolean CULLFACE = false; // true;
5086 /*static*/ boolean NEAREST = false; // true;
....@@ -61,7 +97,7 @@
6197 //boolean REDUCETEXTURE = true;
6298 boolean CACHETEXTURE = true;
6399 boolean CLEANCACHE = false; // true;
64
- boolean MIPMAP = false; // true;
100
+ boolean MIPMAP = false; // true; // never works...
65101 boolean COMPRESSTEXTURE = false;
66102 boolean KOMPACTTEXTURE = false; // true;
67103 boolean RESIZETEXTURE = false;
....@@ -74,7 +110,11 @@
74110 //private Mat4f spotlightTransform = new Mat4f();
75111 //private Mat4f spotlightInverseTransform = new Mat4f();
76112 static GLContext glcontext = null;
77
- /*static*/ com.sun.opengl.util.texture.Texture cubemap;
113
+ /*static*/ com.sun.opengl.util.texture.Texture cubemap; // Either custom or rgb
114
+ /*static*/ com.sun.opengl.util.texture.Texture cubemapcustom;
115
+ /*static*/ com.sun.opengl.util.texture.Texture cubemaprgb;
116
+ boolean transformMode;
117
+
78118 boolean reverseUP = false;
79119 static boolean frozen = false;
80120 boolean enablebackspace = false; // patch for back buffer refresh
....@@ -128,7 +168,7 @@
128168
129169
130170 // OPTIONS
131
- boolean Skinshader = true;
171
+ boolean Skinshader = false; // true;
132172 boolean cameraLight = false;
133173 boolean UVdebug = false;
134174 boolean Udebug = false;
....@@ -137,7 +177,7 @@
137177 static boolean doublesided = false; // true; // reversed normals are awful for conformance
138178 boolean anisotropy = true;
139179 boolean softshadow = true; // slower but better false;
140
- boolean opacityhalo = false;
180
+ boolean opacityhalo = false; // reverse the halo effect (e.g. glass)
141181
142182 boolean macromode = false;
143183
....@@ -148,6 +188,21 @@
148188 defaultcaps.setAccumGreenBits(16);
149189 defaultcaps.setAccumBlueBits(16);
150190 defaultcaps.setAccumAlphaBits(16);
191
+ }
192
+
193
+ private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
194
+
195
+ public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException
196
+ {
197
+ try
198
+ {
199
+ return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
200
+ } catch (IOException e)
201
+ {
202
+ System.out.println("NAME = " + name);
203
+ e.printStackTrace(); // throw new RuntimeException(e);
204
+ return null;
205
+ }
151206 }
152207
153208 void SetAsGLRenderer(boolean b)
....@@ -168,7 +223,8 @@
168223
169224 SetCamera(cam);
170225
171
- SetLight(new Camera(new cVector(10, 10, -20)));
226
+ // Warning: not used.
227
+ SetLight(new Camera(new cVector(15, 10, -20)));
172228
173229 object = o;
174230
....@@ -325,7 +381,7 @@
325381 cStatic.objectstack[materialdepth++] = obj;
326382 //System.out.println("material " + material);
327383 //Applet3D.tracein(this, selected);
328
- display.vector2buffer = obj.projectedVertices;
384
+ //display.vector2buffer = obj.projectedVertices;
329385 if (obj instanceof Camera)
330386 {
331387 display.options1[0] = material.shift;
....@@ -334,14 +390,28 @@
334390 display.options1[2] = material.shadowbias;
335391 display.options1[3] = material.aniso;
336392 display.options1[4] = material.anisoV;
393
+// System.out.println("display.options1[0] " + display.options1[0]);
394
+// System.out.println("display.options1[1] " + display.options1[1]);
395
+// System.out.println("display.options1[2] " + display.options1[2]);
396
+// System.out.println("display.options1[3] " + display.options1[3]);
397
+// System.out.println("display.options1[4] " + display.options1[4]);
337398 display.options2[0] = material.opacity;
338399 display.options2[1] = material.diffuse;
339400 display.options2[2] = material.factor;
401
+// System.out.println("display.options2[0] " + display.options2[0]);
402
+// System.out.println("display.options2[1] " + display.options2[1]);
403
+// System.out.println("display.options2[2] " + display.options2[2]);
340404
341405 cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
406
+// System.out.println("display.options3[0] " + display.options3[0]);
407
+// System.out.println("display.options3[1] " + display.options3[1]);
408
+// System.out.println("display.options3[2] " + display.options3[2]);
342409 display.options4[0] = material.cameralight/0.2f;
343410 display.options4[1] = material.subsurface;
344411 display.options4[2] = material.sheen;
412
+// System.out.println("display.options4[0] " + display.options4[0]);
413
+// System.out.println("display.options4[1] " + display.options4[1]);
414
+// System.out.println("display.options4[2] " + display.options4[2]);
345415
346416 // if (display.CURRENTANTIALIAS > 0)
347417 // display.options3[3] /= 4;
....@@ -357,7 +427,7 @@
357427 /**/
358428 } else
359429 {
360
- DrawMaterial(material, selected);
430
+ DrawMaterial(material, selected, obj.projectedVertices);
361431 }
362432 } else
363433 {
....@@ -381,8 +451,8 @@
381451 cStatic.objectstack[materialdepth++] = obj;
382452 //System.out.println("material " + material);
383453 //Applet3D.tracein("selected ", selected);
384
- display.vector2buffer = obj.projectedVertices;
385
- display.DrawMaterial(material, selected);
454
+ //display.vector2buffer = obj.projectedVertices;
455
+ display.DrawMaterial(material, selected, obj.projectedVertices);
386456 }
387457 }
388458
....@@ -399,8 +469,8 @@
399469 materialdepth -= 1;
400470 if (materialdepth > 0)
401471 {
402
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
403
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
472
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
473
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
404474 }
405475 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
406476 } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
....@@ -420,8 +490,8 @@
420490 materialdepth -= 1;
421491 if (materialdepth > 0)
422492 {
423
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
424
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
493
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
494
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
425495 }
426496 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
427497 //else
....@@ -462,15 +532,18 @@
462532 if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
463533 {
464534 //gl.glBegin(gl.GL_TRIANGLES);
465
- boolean hasnorm = pv.norm != null; // && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0);
535
+ boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0)
536
+ // TEST LIVE NORMALS && !obj.dontselect
537
+ ;
466538 if (!hasnorm)
467539 {
468
- // System.out.println("FUCK!!");
540
+ // System.out.println("Mesh normal");
469541 LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
470542 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
471543 LA.vecCross(obj.v0, obj.v1, obj.v2);
472544 LA.vecNormalize(obj.v2);
473
- gl.glNormal3f((float) obj.v2.x, (float) obj.v2.y, (float) obj.v2.z);
545
+
546
+ SetGLNormal(gl, (float) obj.v2.x, (float) obj.v2.y, (float) obj.v2.z);
474547 }
475548
476549 // P
....@@ -492,7 +565,7 @@
492565 y += ny * obj.NORMALPUSH;
493566 z += nz * obj.NORMALPUSH;
494567
495
- gl.glNormal3f(nx, ny, nz);
568
+ SetGLNormal(gl, nx, ny, nz);
496569 }
497570 gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
498571 SetColor(obj, pv);
....@@ -524,7 +597,7 @@
524597 y += ny * obj.NORMALPUSH;
525598 z += nz * obj.NORMALPUSH;
526599
527
- gl.glNormal3f(nx, ny, nz);
600
+ SetGLNormal(gl, nx, ny, nz);
528601 }
529602 //System.out.println("vertexq = " + qv.s + ", " + qv.t);
530603 // boolean locked = false;
....@@ -572,7 +645,7 @@
572645 y += ny * obj.NORMALPUSH;
573646 z += nz * obj.NORMALPUSH;
574647
575
- gl.glNormal3f(nx, ny, nz);
648
+ SetGLNormal(gl, nx, ny, nz);
576649 }
577650
578651 // if ((dot&4) == 0)
....@@ -1178,10 +1251,10 @@
11781251 {
11791252 if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
11801253 {
1181
- gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1254
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
11821255 } else
11831256 {
1184
- gl.glNormal3f(0, 0, 1);
1257
+ SetGLNormal(gl, 0, 0, 1);
11851258 }
11861259
11871260 if (c != null)
....@@ -1190,10 +1263,12 @@
11901263 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
11911264 }
11921265 }
1266
+
11931267 if (flipV)
11941268 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
11951269 else
11961270 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1271
+
11971272 //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
11981273 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
11991274
....@@ -1203,20 +1278,22 @@
12031278 {
12041279 if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
12051280 {
1206
- gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1281
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
12071282 } else
12081283 {
1209
- gl.glNormal3f(0, 0, 1);
1284
+ SetGLNormal(gl, 0, 0, 1);
12101285 }
12111286 if (c != null)
12121287 {
12131288 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
12141289 }
12151290 }
1291
+
12161292 if (flipV)
12171293 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12181294 else
12191295 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1296
+
12201297 //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
12211298 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
12221299
....@@ -1229,10 +1306,10 @@
12291306 {
12301307 if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
12311308 {
1232
- gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1309
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
12331310 } else
12341311 {
1235
- gl.glNormal3f(0, 0, 1);
1312
+ SetGLNormal(gl, 0, 0, 1);
12361313 }
12371314 if (c != null)
12381315 {
....@@ -1244,8 +1321,10 @@
12441321 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12451322 else
12461323 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1324
+
12471325 //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
12481326 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1327
+
12491328 count2 += 2;
12501329 count3 += 3;
12511330 }
....@@ -1412,7 +1491,7 @@
14121491 {
14131492 if (!selectmode)
14141493 {
1415
- gl.glNormal3f((float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
1494
+ SetGLNormal(gl, (float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
14161495 gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
14171496
14181497 if (flipV)
....@@ -1424,6 +1503,8 @@
14241503 gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
14251504 }
14261505
1506
+ float[] colorV = new float[4];
1507
+
14271508 void SetColor(Object3D obj, Vertex p0)
14281509 {
14291510 CameraPane display = this;
....@@ -1491,8 +1572,6 @@
14911572 {
14921573 return;
14931574 }
1494
-
1495
- float[] colorV = new float[3];
14961575
14971576 if (false) // marked)
14981577 {
....@@ -1601,7 +1680,7 @@
16011680 // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
16021681 }
16031682
1604
- void DrawMaterial(cMaterial material, boolean selected)
1683
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
16051684 {
16061685 CameraPane display = this;
16071686 //new Exception().printStackTrace();
....@@ -1636,7 +1715,7 @@
16361715 colorV[0] = display.modelParams0[0] * material.diffuse;
16371716 colorV[1] = display.modelParams0[1] * material.diffuse;
16381717 colorV[2] = display.modelParams0[2] * material.diffuse;
1639
- colorV[3] = material.opacity;
1718
+ colorV[3] = 1; // material.opacity;
16401719
16411720 gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
16421721 //System.out.println("Opacity = " + opacity);
....@@ -1741,12 +1820,12 @@
17411820
17421821 display.modelParams7[0] = 0;
17431822 display.modelParams7[1] = 1000;
1744
- display.modelParams7[2] = 0;
1823
+ display.modelParams7[2] = material.parallax;
17451824 display.modelParams7[3] = 0;
17461825
1747
- display.modelParams6[0] = 100; // criss de bug de bump
1826
+ //display.modelParams6[0] = 100; // criss de bug de bump
17481827
1749
- Object3D.cVector2[] extparams = display.vector2buffer;
1828
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
17501829 if (extparams != null && extparams.length > 0 && extparams[0] != null)
17511830 {
17521831 display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
....@@ -1888,7 +1967,7 @@
18881967 void PushMatrix(double[][] matrix)
18891968 {
18901969 // GrafreeD.tracein(matrix);
1891
- PushMatrix(matrix,1);
1970
+ PushMatrix(matrix, 1);
18921971 }
18931972
18941973 void PushMatrix()
....@@ -1974,9 +2053,9 @@
19742053 switch(viewcode)
19752054 {
19762055 case 0: return "main";
1977
- case 1: return "one";
1978
- case 2: return "two";
1979
- case 3: return "three";
2056
+ case 1: return "Red";
2057
+ case 2: return "Green";
2058
+ case 3: return "Blue";
19802059 case 4: return "light";
19812060 }
19822061
....@@ -2042,7 +2121,7 @@
20422121 //System.err.println("Oeil on");
20432122 OEIL = true;
20442123 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2045
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2124
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
20462125 //pingthread.StepToTarget(true);
20472126 }
20482127
....@@ -2257,7 +2336,7 @@
22572336
22582337 void ToggleDebug()
22592338 {
2260
- DEBUG ^= true;
2339
+ Globals.DEBUG ^= true;
22612340 }
22622341
22632342 void ToggleLookAt()
....@@ -2265,7 +2344,7 @@
22652344 LOOKAT ^= true;
22662345 }
22672346
2268
- void ToggleRandom()
2347
+ void ToggleSwitch()
22692348 {
22702349 SWITCH ^= true;
22712350 }
....@@ -2275,10 +2354,17 @@
22752354 HANDLES ^= true;
22762355 }
22772356
2357
+ Object3D paintFolder;
2358
+
22782359 void TogglePaint()
22792360 {
22802361 PAINTMODE ^= true;
22812362 paintcount = 0;
2363
+
2364
+ if (PAINTMODE)
2365
+ {
2366
+ paintFolder = GetFolder();
2367
+ }
22822368 }
22832369
22842370 void SwapCamera(int a, int b)
....@@ -2374,7 +2460,34 @@
23742460 {
23752461 return currentGL;
23762462 }
2377
-
2463
+
2464
+ static private BufferedImage CreateBim(TextureData texturedata)
2465
+ {
2466
+ Grafreed.Assert(texturedata != null);
2467
+
2468
+ int width = texturedata.getWidth();
2469
+ int height = texturedata.getHeight();
2470
+
2471
+ Buffer buffer = texturedata.getBuffer();
2472
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2473
+
2474
+ byte[] bytes = bytebuf.array();
2475
+
2476
+ return CreateBim(bytes, width, height);
2477
+ }
2478
+
2479
+ private void SetGLNormal(javax.media.opengl.GL gl, float nx, float ny, float nz)
2480
+ {
2481
+ gl.glNormal3f(nx, ny, nz);
2482
+
2483
+ if (ny > 0.9 || ny < -0.9)
2484
+ // Ground or ceiling
2485
+ gl.glVertexAttrib3f(4, 1, 0, 0);
2486
+ else
2487
+ // Walls
2488
+ gl.glVertexAttrib3f(4, 0, 1, 0);
2489
+ }
2490
+
23782491 /**/
23792492 class CacheTexture
23802493 {
....@@ -2383,28 +2496,31 @@
23832496
23842497 int resolution;
23852498
2386
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2499
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
23872500 {
2388
- texture = tex;
2501
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2502
+ texturedata = texdata;
23892503 resolution = res;
23902504 }
23912505 }
23922506 /**/
23932507
23942508 // TEXTURE static Texture texture;
2395
- static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures
2396
- = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>();
2397
- static public java.util.Hashtable<String, String> usedtextures = new java.util.Hashtable<String, String>();
2509
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2510
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2511
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2512
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2513
+
23982514 int pigmentdepth = 0;
23992515 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
24002516 int bumpdepth = 0;
24012517 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
24022518 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
24032519 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2404
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2520
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
24052521 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
24062522
2407
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2523
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
24082524 {
24092525 TextureData texturedata = null;
24102526
....@@ -2414,7 +2530,7 @@
24142530 com.sun.opengl.util.texture.TextureIO.newTextureData(
24152531 getClass().getClassLoader().getResourceAsStream(name),
24162532 true,
2417
- com.sun.opengl.util.texture.TextureIO.PNG);
2533
+ GetFormat(name)); // com.sun.opengl.util.texture.TextureIO.PNG);
24182534 } catch (java.io.IOException e)
24192535 {
24202536 throw new javax.media.opengl.GLException(e);
....@@ -2423,13 +2539,34 @@
24232539 if (bump)
24242540 texturedata = ConvertBump(texturedata, false);
24252541
2426
- com.sun.opengl.util.texture.Texture texture =
2427
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2542
+// com.sun.opengl.util.texture.Texture texture =
2543
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
24282544
2429
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2430
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
2545
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2546
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
24312547
2432
- return texture;
2548
+ return texturedata;
2549
+ }
2550
+
2551
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2552
+ {
2553
+ TextureData texturedata = null;
2554
+
2555
+ try
2556
+ {
2557
+ texturedata =
2558
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2559
+ bim,
2560
+ true);
2561
+ } catch (Exception e)
2562
+ {
2563
+ throw new javax.media.opengl.GLException(e);
2564
+ }
2565
+
2566
+ if (bump)
2567
+ texturedata = ConvertBump(texturedata, false);
2568
+
2569
+ return texturedata;
24332570 }
24342571
24352572 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3502,6 +3639,8 @@
35023639
35033640 System.out.println("LOADING TEXTURE : " + name);
35043641
3642
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3643
+
35053644 //
35063645 if (false) // compressbit > 0)
35073646 {
....@@ -7900,7 +8039,7 @@
79008039 String pigment = Object3D.GetPigment(tex);
79018040 String bump = Object3D.GetBump(tex);
79028041
7903
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8042
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79048043 {
79058044 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79068045 // System.out.println("; bump = " + bump);
....@@ -7915,11 +8054,69 @@
79158054 pigment = null;
79168055 }
79178056
7918
- ReleaseTexture(bump, true);
7919
- ReleaseTexture(pigment, false);
8057
+ ReleaseTexture(tex, true);
8058
+ ReleaseTexture(tex, false);
79208059 }
79218060
7922
- void ReleaseTexture(String tex, boolean bump)
8061
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
8062
+ {
8063
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8064
+ {
8065
+ return;
8066
+ }
8067
+
8068
+ if (tex == null)
8069
+ {
8070
+ ReleaseTexture(null, false);
8071
+ return;
8072
+ }
8073
+
8074
+ String pigment = Object3D.GetPigment(tex);
8075
+
8076
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8077
+ {
8078
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8079
+ // System.out.println("; bump = " + bump);
8080
+ }
8081
+
8082
+ if (pigment.equals(""))
8083
+ {
8084
+ pigment = null;
8085
+ }
8086
+
8087
+ ReleaseTexture(tex, false);
8088
+ }
8089
+
8090
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
8091
+ {
8092
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8093
+ {
8094
+ return;
8095
+ }
8096
+
8097
+ if (tex == null)
8098
+ {
8099
+ ReleaseTexture(null, true);
8100
+ return;
8101
+ }
8102
+
8103
+ String bump = Object3D.GetBump(tex);
8104
+
8105
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8106
+ {
8107
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8108
+ // System.out.println("; bump = " + bump);
8109
+ }
8110
+
8111
+ if (bump.equals(""))
8112
+ {
8113
+ bump = null;
8114
+ }
8115
+
8116
+ ReleaseTexture(tex, true);
8117
+ }
8118
+
8119
+ void ReleaseTexture(cTexture tex, boolean bump)
79238120 {
79248121 if (// DrawMode() != 0 || /*tex == null ||*/
79258122 ambientOcclusion ) // || !textureon)
....@@ -7930,7 +8127,7 @@
79308127 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
79318128
79328129 if (tex != null)
7933
- texture = textures.get(tex);
8130
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
79348131
79358132 // //assert( texture != null );
79368133 // if (texture == null)
....@@ -8024,6 +8221,54 @@
80248221
80258222 /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
80268223 {
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
+ {
80278272 if (// DrawMode() != 0 || /*tex == null ||*/
80288273 ambientOcclusion ) // || !textureon)
80298274 {
....@@ -8033,17 +8278,47 @@
80338278 if (tex == null)
80348279 {
80358280 BindTexture(null,false,resolution);
8036
- BindTexture(null,true,resolution);
80378281 return;
80388282 }
80398283
80408284 String pigment = Object3D.GetPigment(tex);
8285
+
8286
+ usedtextures.add(tex);
8287
+
8288
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8289
+ {
8290
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8291
+ // System.out.println("; bump = " + bump);
8292
+ }
8293
+
8294
+ if (pigment.equals(""))
8295
+ {
8296
+ pigment = null;
8297
+ }
8298
+
8299
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8300
+ BindTexture(tex, false, resolution);
8301
+ }
8302
+
8303
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8304
+ {
8305
+ if (// DrawMode() != 0 || /*tex == null ||*/
8306
+ ambientOcclusion ) // || !textureon)
8307
+ {
8308
+ return; // false;
8309
+ }
8310
+
8311
+ if (tex == null)
8312
+ {
8313
+ BindTexture(null,true,resolution);
8314
+ return;
8315
+ }
8316
+
80418317 String bump = Object3D.GetBump(tex);
80428318
8043
- usedtextures.put(pigment, pigment);
8044
- usedtextures.put(bump, bump);
8319
+ usedtextures.add(tex);
80458320
8046
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8321
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
80478322 {
80488323 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
80498324 // System.out.println("; bump = " + bump);
....@@ -8053,47 +8328,94 @@
80538328 {
80548329 bump = null;
80558330 }
8056
- if (pigment.equals(""))
8057
- {
8058
- pigment = null;
8059
- }
80608331
8061
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8062
- BindTexture(pigment, false, resolution);
80638332 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8064
- BindTexture(bump, true, resolution);
8333
+ BindTexture(tex, true, resolution);
80658334 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8066
-
8067
- return; // true;
80688335 }
80698336
8070
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception
8337
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8338
+
8339
+ private boolean FileExists(String tex)
80718340 {
8072
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8341
+ if (missingTextures.contains(tex))
8342
+ {
8343
+ return false;
8344
+ }
8345
+
8346
+ boolean fileExists = new File(tex).exists();
8347
+
8348
+ if (!fileExists)
8349
+ {
8350
+ // If file exists, the "new File()" is not executed sgain
8351
+ missingTextures.add(tex);
8352
+ }
8353
+
8354
+ return fileExists;
8355
+ }
8356
+
8357
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
8358
+ {
8359
+ CacheTexture texturecache = null;
80738360
80748361 if (tex != null)
80758362 {
8076
- String texname = tex;
8363
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8364
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
80778365
8366
+ if (texname.equals("") && texdata == null)
8367
+ {
8368
+ return null;
8369
+ }
8370
+
8371
+ String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
8372
+
80788373 // String[] split = tex.split("Textures");
80798374 // if (split.length > 1)
80808375 // texname = "/Users/nbriere/Textures" + split[split.length-1];
80818376 // else
80828377 // if (!texname.startsWith("/"))
80838378 // texname = "/Users/nbriere/Textures/" + texname;
8084
- if (!new File(tex).exists())
8379
+ if (!FileExists(texname) && !texname.startsWith("@"))
80858380 {
8086
- texname = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory() + "/Textures/" + texname;
8381
+ texname = fallbackTextureName;
80878382 }
80888383
80898384 if (CACHETEXTURE)
8090
- texture = textures.get(texname); // TEXTURE CACHE
8091
-
8092
- TextureData texturedata = null;
8093
-
8094
- if (texture == null || texture.resolution < resolution)
80958385 {
8096
- 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(""))
80978419 {
80988420 assert(!bump);
80998421 // if (bump)
....@@ -8104,19 +8426,23 @@
81048426 // }
81058427 // else
81068428 // {
8107
- texture = textures.get(tex);
8108
- if (texture == null)
8429
+ // texturecache = textures.get(texname); // suspicious
8430
+ if (texturecache == null)
81098431 {
8110
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8432
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
81118433 }
8434
+ else
8435
+ new Exception().printStackTrace();
81128436 // }
81138437 } else
8114
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8438
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
81158439 {
81168440 assert(bump);
8117
- texture = textures.get(tex);
8118
- if (texture == null)
8119
- 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();
81208446 } else
81218447 {
81228448 //if (tex.equals("IMMORTAL"))
....@@ -8124,11 +8450,22 @@
81248450 // texture = GetResourceTexture("default.png");
81258451 //} else
81268452 //{
8127
- if (tex.equals("WHITE_NOISE"))
8453
+ if (texname.endsWith("WHITE_NOISE"))
81288454 {
8129
- texture = textures.get(tex);
8130
- if (texture == null)
8131
- 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();
81328469 } else
81338470 {
81348471 if (textureon)
....@@ -8153,7 +8490,7 @@
81538490 }
81548491
81558492 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
8156
- if (!new File(cachename).exists())
8493
+ if (!FileExists(cachename))
81578494 cachename = texname;
81588495 else
81598496 processbump = false; // don't process bump map again
....@@ -8175,7 +8512,7 @@
81758512 }
81768513
81778514 cachename = texname.substring(0, texname.length()-4)+ext+".png";
8178
- if (!new File(cachename).exists())
8515
+ if (!FileExists(cachename))
81798516 cachename = texname;
81808517 else
81818518 processbump = false; // don't process bump map again
....@@ -8187,19 +8524,20 @@
81878524 if (texturedata == null)
81888525 throw new Exception();
81898526
8190
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8527
+ texturecache = new CacheTexture(texturedata,resolution);
81918528 //texture = GetTexture(tex, bump);
81928529 }
8530
+ }
81938531 }
81948532 //}
81958533 }
81968534
8197
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8535
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
81988536 {
81998537 //return false;
82008538
82018539 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8202
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8540
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
82038541 {
82048542 // String ext = "_highres";
82058543 // if (REDUCETEXTURE)
....@@ -8216,52 +8554,17 @@
82168554 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
82178555 if (!cachefile.exists())
82188556 {
8219
- // cache to disk
8220
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
8221
- //buffers[0].
8222
-
8223
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
8224
- int[] pixels = new int[bytebuf.capacity()/3];
8225
-
8226
- // squared size heuristic...
8227
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8557
+ //if (texturedata.getWidth() == texturedata.getHeight())
82288558 {
8229
- for (int i=pixels.length; --i>=0;)
8230
- {
8231
- int i3 = i*3;
8232
- pixels[i] = 0xFF;
8233
- pixels[i] <<= 8;
8234
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
8235
- pixels[i] <<= 8;
8236
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
8237
- pixels[i] <<= 8;
8238
- pixels[i] |= bytebuf.get(i3) & 0xFF;
8239
- }
8240
-
8241
- /*
8242
- int r=0,g=0,b=0,a=0;
8243
- for (int i=0; i<width; i++)
8244
- for (int j=0; j<height; j++)
8245
- {
8246
- int index = j*width+i;
8247
- int p = pixels[index];
8248
- a = ((p>>24) & 0xFF);
8249
- r = ((p>>16) & 0xFF);
8250
- g = ((p>>8) & 0xFF);
8251
- b = (p & 0xFF);
8252
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
8253
- }
8254
- /**/
8255
- int width = (int)Math.sqrt(pixels.length); // squared
8256
- int height = width;
8257
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
8258
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8559
+ BufferedImage rendImage = CreateBim(texturedata);
8560
+
82598561 ImageWriter writer = null;
82608562 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
82618563 if (iter.hasNext()) {
82628564 writer = (ImageWriter)iter.next();
82638565 }
8264
- float compressionQuality = 0.9f;
8566
+
8567
+ float compressionQuality = 0.85f;
82658568 try
82668569 {
82678570 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8278,18 +8581,20 @@
82788581 }
82798582 }
82808583 }
8281
-
8584
+
8585
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8586
+
82828587 //System.out.println("Texture = " + tex);
8283
- if (textures.containsKey(texname))
8588
+ if (textures.containsKey(tex))
82848589 {
8285
- CacheTexture thetex = textures.get(texname);
8590
+ CacheTexture thetex = textures.get(tex);
82868591 thetex.texture.disable();
82878592 thetex.texture.dispose();
8288
- textures.remove(texname);
8593
+ textures.remove(tex);
82898594 }
82908595
8291
- texture.texturedata = texturedata;
8292
- textures.put(texname, texture);
8596
+ //texture.texturedata = texturedata;
8597
+ textures.put(tex, texturecache);
82938598
82948599 // newtex = true;
82958600 }
....@@ -8305,10 +8610,44 @@
83058610 }
83068611 }
83078612
8308
- return texture;
8613
+ return texturecache;
83098614 }
83108615
8311
- 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
83128651 {
83138652 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
83148653
....@@ -8326,21 +8665,21 @@
83268665 return texture!=null?texture.texture:null;
83278666 }
83288667
8329
- 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
83308669 {
83318670 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
83328671
83338672 return texture!=null?texture.texturedata:null;
83348673 }
83358674
8336
- boolean BindTexture(String tex, boolean bump, int resolution) throws Exception
8675
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
83378676 {
83388677 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
83398678 {
83408679 return false;
83418680 }
83428681
8343
- boolean newtex = false;
8682
+ //boolean newtex = false;
83448683
83458684 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
83468685
....@@ -8372,9 +8711,75 @@
83728711 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
83738712 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
83748713
8375
- return newtex;
8714
+ return true; // Warning: not used.
83768715 }
83778716
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
+
83788783 ShadowBuffer shadowPBuf;
83798784 AntialiasBuffer antialiasPBuf;
83808785 int MAXSTACK;
....@@ -8391,10 +8796,12 @@
83918796
83928797 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
83938798 MAXSTACK = temp[0];
8394
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8799
+ if (Globals.DEBUG)
8800
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
83958801 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
83968802 MAXSTACK = temp[0];
8397
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8803
+ if (Globals.DEBUG)
8804
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
83988805
83998806 // Use debug pipeline
84008807 //drawable.setGL(new DebugGL(gl)); //
....@@ -8402,7 +8809,8 @@
84028809 gl = drawable.getGL(); //
84038810
84048811 GL gl3 = getGL();
8405
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8812
+ if (Globals.DEBUG)
8813
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
84068814
84078815
84088816 //float pos[] = { 100, 100, 100, 0 };
....@@ -8567,7 +8975,7 @@
85678975
85688976 if (cubemap == null)
85698977 {
8570
- LoadEnvy(5);
8978
+ //LoadEnvy(1);
85718979 }
85728980
85738981 //cubemap.enable();
....@@ -8843,6 +9251,8 @@
88439251
88449252 void LoadEnvy(int which)
88459253 {
9254
+ assert(false);
9255
+
88469256 String name;
88479257 String ext;
88489258
....@@ -8854,37 +9264,58 @@
88549264 cubemap = null;
88559265 return;
88569266 case 1:
8857
- name = "cubemaps/box_";
8858
- ext = "png";
9267
+ name = "cubemaps/rgb/";
9268
+ ext = "jpg";
88599269 reverseUP = false;
88609270 break;
88619271 case 2:
8862
- name = "cubemaps/uffizi_";
8863
- ext = "png";
8864
- break; // reverseUP = true; break;
9272
+ name = "cubemaps/uffizi/";
9273
+ ext = "jpg";
9274
+ reverseUP = false;
9275
+ break;
88659276 case 3:
8866
- name = "cubemaps/CloudyHills_";
8867
- ext = "tga";
9277
+ name = "cubemaps/CloudyHills/";
9278
+ ext = "jpg";
88689279 reverseUP = false;
88699280 break;
88709281 case 4:
8871
- name = "cubemaps/cornell_";
9282
+ name = "cubemaps/cornell/";
88729283 ext = "png";
88739284 reverseUP = false;
88749285 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;
88759311 default:
8876
- name = "cubemaps/rgb_";
8877
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9312
+ name = "cubemaps/box/";
9313
+ ext = "png"; /*mipmap = true;*/
9314
+ reverseUP = false;
88789315 break;
88799316 }
8880
-
8881
- try
8882
- {
8883
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
8884
- } catch (IOException e)
8885
- {
8886
- throw new RuntimeException(e);
8887
- }
9317
+
9318
+ LoadSkybox(name, ext, mipmap);
88889319 }
88899320
88909321 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -8916,8 +9347,12 @@
89169347 static double[] model = new double[16];
89179348 double[] camera2light = new double[16];
89189349 double[] light2camera = new double[16];
8919
- int newenvy = -1;
8920
- boolean envyoff = true; // false;
9350
+
9351
+ //int newenvy = -1;
9352
+ //boolean envyoff = false;
9353
+
9354
+ String loadedskyboxname;
9355
+
89219356 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
89229357 //float[] light0 = { 0,0,0 };
89239358 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9210,11 +9645,35 @@
92109645 jy8[3] = 0.5f;
92119646 }
92129647
9213
- 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
92149649 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
92159650 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
92169651 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
92179652
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
+
92189677 static int imagecount = 0; // movie generation
92199678
92209679 static int jitter = 0;
....@@ -9310,8 +9769,8 @@
93109769 assert (parentcam != renderCamera);
93119770
93129771 if (renderCamera != lightCamera)
9313
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9314
- LA.matConcat(matrix, parentcam.toParent, matrix);
9772
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9773
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
93159774
93169775 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
93179776
....@@ -9326,8 +9785,8 @@
93269785 LA.matCopy(renderCamera.fromScreen, matrix);
93279786
93289787 if (renderCamera != lightCamera)
9329
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9330
- LA.matConcat(parentcam.fromParent, matrix, matrix);
9788
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9789
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
93319790
93329791 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
93339792
....@@ -9373,10 +9832,12 @@
93739832 rati = 1 / rati;
93749833 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
93759834 }
9376
- assert (newenvy == -1);
9835
+
9836
+ //assert (newenvy == -1);
9837
+
93779838 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
93789839 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9379
- DrawSkyBox(gl);
9840
+ DrawSkyBox(gl, (float)rati);
93809841 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
93819842 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
93829843 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10242,9 +10703,18 @@
1024210703 static boolean init = false;
1024310704
1024410705 double[][] matrix = LA.newMatrix();
10706
+
10707
+ // This is to refresh the UI of the material panel.
10708
+ ObjEditor patchMaterial;
1024510709
1024610710 public void display(GLAutoDrawable drawable)
1024710711 {
10712
+ if (patchMaterial.patchMaterial)
10713
+ {
10714
+ patchMaterial.patchMaterial = false;
10715
+ patchMaterial.objectPanel.setSelectedIndex(1);
10716
+ }
10717
+
1024810718 if (Grafreed.savesound && Grafreed.hassound)
1024910719 {
1025010720 Grafreed.wav.save();
....@@ -10325,6 +10795,7 @@
1032510795 ANTIALIAS = 0;
1032610796 //System.out.println("RESTART");
1032710797 AAtimer.restart();
10798
+ Globals.TIMERRUNNING = true;
1032810799 }
1032910800 }
1033010801 }
....@@ -10392,13 +10863,14 @@
1039210863 ambientOcclusion = false;
1039310864 }
1039410865
10395
- if (Globals.lighttouched && DrawMode() == DEFAULT && !lightMode) // && !FROZEN)
10866
+ if (//Globals.lighttouched &&
10867
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1039610868 {
1039710869 //if (RENDERSHADOW) // ?
1039810870 if (!IsFrozen())
1039910871 {
1040010872 // dec 2012
10401
- if (!ambientOcclusion && !(!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0))
10873
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
1040210874 {
1040310875 Globals.framecount++;
1040410876 shadowbuffer.display();
....@@ -10411,7 +10883,7 @@
1041110883
1041210884 if (wait)
1041310885 {
10414
- Sleep(500);
10886
+ Sleep(200); // blocks everything
1041510887
1041610888 wait = false;
1041710889 }
....@@ -10525,8 +10997,8 @@
1052510997
1052610998 // if (parentcam != renderCamera) // not a light
1052710999 if (cam != lightCamera)
10528
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10529
- LA.matConcat(matrix, parentcam.toParent, matrix);
11000
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11001
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1053011002
1053111003 for (int j = 0; j < 4; j++)
1053211004 {
....@@ -10540,8 +11012,8 @@
1054011012
1054111013 // if (parentcam != renderCamera) // not a light
1054211014 if (cam != lightCamera)
10543
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10544
- LA.matConcat(parentcam.fromParent, matrix, matrix);
11015
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11016
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1054511017
1054611018 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1054711019
....@@ -10627,13 +11099,43 @@
1062711099 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1062811100 }
1062911101
10630
- 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"))
1063111110 {
10632
- LoadEnvy(newenvy);
11111
+ if (cubemaprgb == null)
11112
+ {
11113
+ cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb2" + "/", "jpg", false);
11114
+ }
11115
+
11116
+ cubemap = cubemaprgb;
1063311117 }
10634
-
10635
- newenvy = -1;
10636
-
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
+
1063711139 ratio = ((double) getWidth()) / getHeight();
1063811140 //System.out.println("ratio = " + ratio);
1063911141
....@@ -10649,7 +11151,7 @@
1064911151
1065011152 if (!IsFrozen() && !ambientOcclusion)
1065111153 {
10652
- DrawSkyBox(gl);
11154
+ DrawSkyBox(gl, (float)ratio);
1065311155 }
1065411156
1065511157 //if (selection_view == -1)
....@@ -10832,9 +11334,9 @@
1083211334
1083311335 gl.glMatrixMode(GL.GL_MODELVIEW);
1083411336
10835
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10836
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10837
-//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);
1083811340 } else
1083911341 {
1084011342 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -10845,7 +11347,7 @@
1084511347 //System.out.println("BLENDING ON");
1084611348 gl.glEnable(GL.GL_BLEND);
1084711349 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
10848
-
11350
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1084911351 gl.glMatrixMode(gl.GL_PROJECTION);
1085011352 gl.glLoadIdentity();
1085111353
....@@ -10934,8 +11436,8 @@
1093411436 System.err.println("parentcam != renderCamera");
1093511437
1093611438 // if (cam != lightCamera)
10937
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10938
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11439
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11440
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1093911441 }
1094011442
1094111443 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -10956,8 +11458,8 @@
1095611458 if (true) // TODO
1095711459 {
1095811460 if (cam != lightCamera)
10959
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10960
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11461
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11462
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
1096111463 }
1096211464
1096311465 LA.xformPos(light0, cam.toScreen, light0);
....@@ -11094,7 +11596,7 @@
1109411596 }
1109511597 }
1109611598
11097
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11599
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1109811600 {
1109911601 //gl.glDepthFunc(GL.GL_LEQUAL);
1110011602 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11102,24 +11604,21 @@
1110211604
1110311605 boolean texon = textureon;
1110411606
11105
- if (RENDERPROGRAM > 0)
11106
- {
11107
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11108
- textureon = false;
11109
- }
11607
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11608
+ textureon = false;
11609
+
1111011610 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1111111611 //System.out.println("ALLO");
1111211612 gl.glColorMask(false, false, false, false);
1111311613 DrawObject(gl);
11114
- if (RENDERPROGRAM > 0)
11115
- {
11116
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11117
- textureon = texon;
11118
- }
11614
+
11615
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11616
+ textureon = texon;
11617
+
1111911618 gl.glColorMask(true, true, true, true);
1112011619
1112111620 gl.glDepthFunc(GL.GL_EQUAL);
11122
- //gl.glDepthMask(false);
11621
+ gl.glDepthMask(false);
1112311622 }
1112411623
1112511624 if (false) // DrawMode() == SHADOW)
....@@ -11302,15 +11801,36 @@
1130211801
1130311802 static boolean zoomonce = false;
1130411803
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
+
1130511822 void DrawObject(GL gl, boolean draw)
1130611823 {
11824
+ // To clear camera values
11825
+ ResetOptions();
11826
+
1130711827 //System.out.println("DRAW OBJECT " + mouseDown);
1130811828 // DrawMode() = SELECTION;
1130911829 //GL gl = getGL();
1131011830 if ((TRACK || SHADOWTRACK) || zoomonce)
1131111831 {
1131211832 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11313
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11833
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1131411834 pingthread.StepToTarget(true); // true);
1131511835 // zoomonce = false;
1131611836 }
....@@ -11382,8 +11902,9 @@
1138211902
1138311903 if (DrawMode() == DEFAULT)
1138411904 {
11385
- if (DEBUG)
11905
+ if (Globals.DEBUG)
1138611906 {
11907
+ CreateSelectedPoint();
1138711908 float radius = 0.05f;
1138811909 if (selectedpoint.radius != radius)
1138911910 {
....@@ -11437,20 +11958,32 @@
1143711958 ReleaseTextures(DEFAULT_TEXTURES);
1143811959
1143911960 if (CLEANCACHE)
11440
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11961
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1144111962 {
11442
- String tex = e.nextElement();
11963
+ cTexture tex = e.nextElement();
1144311964
1144411965 // System.out.println("Texture --------- " + tex);
1144511966
11446
- if (tex.equals("WHITE_NOISE"))
11967
+ if (tex.equals("WHITE_NOISE:"))
1144711968 continue;
1144811969
11449
- if (!usedtextures.containsKey(tex))
11970
+ if (!usedtextures.contains(tex))
1145011971 {
11972
+ CacheTexture gettex = texturepigment.get(tex);
1145111973 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11452
- textures.get(tex).texture.dispose();
11453
- 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
+ }
1145411987 }
1145511988 }
1145611989 }
....@@ -11552,7 +12085,7 @@
1155212085 return;
1155312086 }
1155412087
11555
- String string = obj.GetToolTip();
12088
+ String string = obj.toString(); //.GetToolTip();
1155612089
1155712090 GL gl = GetGL();
1155812091
....@@ -11869,8 +12402,8 @@
1186912402 //obj.TransformToWorld(light, light);
1187012403 for (int i = tp.size(); --i >= 0;)
1187112404 {
11872
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
11873
- LA.xformPos(light, tp.get(i).toParent, light);
12405
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12406
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1187412407 }
1187512408
1187612409
....@@ -11887,8 +12420,8 @@
1188712420 parentcam = cameras[0];
1188812421 }
1188912422
11890
- for (int count = parentcam.GetTransformCount(); --count>=0;)
11891
- LA.xformPos(light, parentcam.toParent, light); // may 2013
12423
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
12424
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1189212425
1189312426 LA.xformPos(light, renderCamera.toScreen, light);
1189412427
....@@ -11978,8 +12511,76 @@
1197812511
1197912512 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1198012513
11981
- String program =
12514
+ String programmin =
12515
+ // Min shader
1198212516 "!!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
+
1198312584 //"OPTION ARB_fragment_program_shadow;" +
1198412585 "PARAM light2cam0 = program.env[10];" +
1198512586 "PARAM light2cam1 = program.env[11];" +
....@@ -12005,7 +12606,7 @@
1200512606 "PARAM params4 = program.env[4];" + // anisoV, cameralight, selfshadow, shadow
1200612607 "PARAM params5 = program.env[5];" + // texture, opacity, fakedepth, shadowbias
1200712608 "PARAM params6 = program.env[6];" + // bump, noise, borderfade, fog punchthrough
12008
- "PARAM params7 = program.env[7];" + // noise power, opacity power
12609
+ "PARAM params7 = program.env[7];" + // noise power, opacity power, parallax
1200912610 "PARAM options0 = program.env[63];" + // fog density, intensity, elevation
1201012611 "PARAM options1 = program.env[62];" + // fog rgb color
1201112612 "PARAM options2 = program.env[61];" + // image intensity, subsurface, lightsheen
....@@ -12094,8 +12695,7 @@
1209412695 "TEMP shininess;" +
1209512696 "\n" +
1209612697 "MOV texSamp, one;" +
12097
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12098
-
12698
+
1209912699 "MOV mapgrid.x, one2048th.x;" +
1210012700 "MOV temp, fragment.texcoord[1];" +
1210112701 /*
....@@ -12116,20 +12716,20 @@
1211612716 "MUL temp, floor, mapgrid.x;" +
1211712717 //"TEX depth0, temp, texture[1], 2D;" +
1211812718 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12119
- TextureFetch("depth0", "temp", "1") +
12719
+ ShadowTextureFetch("depth0", "temp", "1") +
1212012720 "") +
1212112721 "ADD temp.x, temp.x, mapgrid.x;" +
1212212722 //"TEX depth1, temp, texture[1], 2D;" +
1212312723 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12124
- TextureFetch("depth1", "temp", "1") +
12724
+ ShadowTextureFetch("depth1", "temp", "1") +
1212512725 "") +
1212612726 "ADD temp.y, temp.y, mapgrid.x;" +
1212712727 //"TEX depth2, temp, texture[1], 2D;" +
12128
- TextureFetch("depth2", "temp", "1") +
12728
+ ShadowTextureFetch("depth2", "temp", "1") +
1212912729 "SUB temp.x, temp.x, mapgrid.x;" +
1213012730 //"TEX depth3, temp, texture[1], 2D;" +
1213112731 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12132
- TextureFetch("depth3", "temp", "1") +
12732
+ ShadowTextureFetch("depth3", "temp", "1") +
1213312733 "") +
1213412734 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1213512735 //"MOV params, material;" +
....@@ -12251,7 +12851,7 @@
1225112851 "POW texSamp.a, texSamp.a, params6.w;" + // fog punch through shortcut
1225212852 // mar 2013 ??? "KIL alpha.a;" +
1225312853 "MOV alpha, texSamp.aaaa;" + // y;" +
12254
- "KIL alpha.a;" +
12854
+ "KIL alpha.a;" + // not sure with parallax mapping
1225512855 /*
1225612856 "MUL temp.xy, temp, two;" +
1225712857 "TXB bump, temp, texture[0], 2D;" +
....@@ -12337,11 +12937,6 @@
1233712937 "SUB bump0, bump0, half;" +
1233812938 "ADD bump, bump, bump0;" +
1233912939
12340
- "MOV temp.x, texSamp.a;" +
12341
- "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
12342
- //"LRP texSamp0, params5.x, texSamp0, one;" +
12343
- "MOV texSamp.a, temp.x;" +
12344
-
1234512940 // double-sided
1234612941 /**/
1234712942 (doublesided?"DP3 temp.z, normal, eye;" +
....@@ -12358,19 +12953,62 @@
1235812953 "MOV normald, normal;" +
1235912954 "MOV normals, normal;" +
1236012955
12956
+ "MOV temp, fragment.texcoord[4];" +
12957
+
1236112958 // UV base
1236212959 //"DP3 UP.x,state.matrix.modelview.row[0],Y;" +
1236312960 //"DP3 UP.y,state.matrix.modelview.row[1],Y;" +
1236412961 //"DP3 UP.z,state.matrix.modelview.row[2],Y;" +
12365
- "DP3 UP.x,state.matrix.texture[7].row[0],Y;" +
12366
- "DP3 UP.y,state.matrix.texture[7].row[1],Y;" +
12367
- "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
+
1236812967 "XPD V, normal, UP;" +
1236912968 Normalize("V") +
1237012969 "XPD U, V, normal;" +
1237112970 Normalize("U") +
1237212971
1237312972 // parallax mapping
12973
+
12974
+ "DP3 temp2.x, V, eye;" +
12975
+ "DP3 temp2.y, U, eye;" +
12976
+ "DP3 temp2.z, normal, eye;" +
12977
+ "RCP temp2.z, temp2.z;" +
12978
+
12979
+ "DP3 temp2.w, texSamp, texSamp;" + // Height
12980
+ "RSQ temp2.w, temp2.w;" +
12981
+ "RCP temp2.w, temp2.w;" +
12982
+
12983
+ "SUB temp2.w, temp2.w, half;" +
12984
+// "SGE temp.x, temp2.w, eps.x;" +
12985
+// "MUL temp2.w, temp2.w, temp.x;" +
12986
+
12987
+ //"MOV texSamp, U;" +
12988
+
12989
+ "MUL temp2.z, temp2.z, temp2.w;" +
12990
+ "MUL temp2.z, temp2.z, params7.z;" + // parallax
12991
+
12992
+ "MUL temp2, temp2, temp2.z;" +
12993
+
12994
+ "MOV temp, fragment.texcoord[0];" +
12995
+
12996
+ "SUB temp, temp, temp2;" +
12997
+
12998
+ "TEX temp, temp, texture[0], 2D;" +
12999
+ "POW temp.a, temp.a, params6.w;" + // punch through
13000
+
13001
+ "ADD texSamp, temp, texSamp;" +
13002
+ "MUL texSamp.xyz, half, texSamp;" +
13003
+
13004
+ "MOV alpha, texSamp.aaaa;" +
13005
+
13006
+// parallax mapping
13007
+
13008
+ "MOV temp.x, texSamp.a;" +
13009
+ "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
13010
+ //"LRP texSamp0, params5.x, texSamp0, one;" +
13011
+ "MOV texSamp.a, temp.x;" +
1237413012
1237513013 //"MOV temp, fragment.texcoord[0];" +
1237613014 //
....@@ -12500,10 +13138,10 @@
1250013138 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1250113139 "") +
1250213140
12503
- // display shadow only (bump == 0)
13141
+ // display shadow only (fakedepth == 0)
1250413142 "SUB temp.x, half.x, shadow.x;" +
1250513143 "MOV temp.y, -params5.z;" + // params6.x;" +
12506
- "SLT temp.z, temp.y, -one2048th.x;" +
13144
+ "SLT temp.z, temp.y, -c256i.x;" +
1250713145 "SUB temp.y, one.x, temp.z;" +
1250813146 "MUL temp.x, temp.x, temp.y;" +
1250913147 "KIL temp.x;" +
....@@ -12834,8 +13472,19 @@
1283413472 //once = true;
1283513473 }
1283613474
12837
- System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
12838
- 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
+
1283913488 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1284013489
1284113490 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -12882,7 +13531,8 @@
1288213531 "\n" +
1288313532 "END\n";
1288413533
12885
- System.out.println("Program shadow #" + 0 + "; length = " + program.length());
13534
+ if (Globals.DEBUG)
13535
+ System.out.println("Program shadow #" + 0 + "; length = " + program.length());
1288613536 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1288713537
1288813538 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -12927,25 +13577,26 @@
1292713577 return out;
1292813578 }
1292913579
12930
- String TextureFetch(String dest, String src, String unit)
13580
+ // Also does frustum culling
13581
+ String ShadowTextureFetch(String dest, String src, String unit)
1293113582 {
1293213583 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1293313584 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1293413585 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13586
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13587
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1293513588 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12936
- "SLT " + src + ".z, " + src + ".x, one.x;" +
12937
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12938
- "SLT " + src + ".z, " + src + ".y, one.x;" +
12939
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13589
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13590
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1294013591 //"SWZ buffer, temp, w,w,w,w;";
12941
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13592
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1294213593 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1294313594 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1294413595 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
12945
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13596
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1294613597
12947
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
12948
- //"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;";
1294913600 }
1295013601
1295113602 String Shadow(String depth, String shadow)
....@@ -12992,7 +13643,7 @@
1299213643 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1299313644 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1299413645
12995
- // No shadow when out of frustrum
13646
+ // No shadow when out of frustum
1299613647 "SGE temp.x, " + depth + ".z, one.z;" +
1299713648 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1299813649 "";
....@@ -13139,8 +13790,9 @@
1313913790 /*static*/ float[] modelParams4 = new float[]{0, 0, 0, 0}; // anisoV, cameralight, selfshadow, shadow
1314013791 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1314113792 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
13142
- /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13143
- Object3D.cVector2[] vector2buffer;
13793
+ /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power, parallax
13794
+
13795
+ //Object3D.cVector2[] vector2buffer;
1314413796
1314513797 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1314613798 // OUT : diff, spec
....@@ -13156,9 +13808,10 @@
1315613808 "DP3 " + dest + ".z," + "normals," + "eye;" +
1315713809 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1315813810 //"MOV " + dest + ".w," + "normal.z;" +
13159
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
13160
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13161
- //"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
1316213815 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1316313816 "RCP " + dest + ".w," + dest + ".w;" +
1316413817 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13304,7 +13957,7 @@
1330413957 "PARAM p[4] = { state.matrix.projection }; # modelview projection matrix\n" +
1330513958 "PARAM zero = { 0.0, 0.0, 0.0, 1.0 };" +
1330613959 "PARAM half = { 0.5, 0.5, 0.5, 1.0 };" +
13307
- "PARAM one = { 1.0, 1.0, 1.0, 0.0 };" +
13960
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
1330813961 "PARAM two = { 2.0, 2.0, 2.0, 1.0 };" +
1330913962 "PARAM third = { 0.33333333333, 0.33333333333, 0.33333333333, 1.0 };" +
1331013963 //"PARAM v256 = { 256.0, 256.0, 256.0, 1.0 };" +
....@@ -13365,7 +14018,7 @@
1336514018 "DP4 temp.x,state.matrix.texture[0].inverse.row[0],vertex.texcoord;" +
1336614019 "DP4 temp.y,state.matrix.texture[0].inverse.row[1],vertex.texcoord;" +
1336714020 "DP4 temp.z,state.matrix.texture[0].inverse.row[2],vertex.texcoord;" +
13368
- //"MOV result.texcoord, vertex.texcoord;" +
14021
+ //"MOV result.texcoord, vertex.fogcoord;" +
1336914022 "MOV result.texcoord, temp;" +
1337014023 // border fade
1337114024 "MOV result.texcoord[3], vertex.texcoord;" +
....@@ -13412,7 +14065,9 @@
1341214065
1341314066 //"ADD temp.z, temp.z, one;" +
1341414067
13415
- "MOV result.color, temp;"
14068
+ "MOV result.texcoord[4], vertex.attrib[4];" + // U dir
14069
+
14070
+ "MOV result.color, temp;" // Normal
1341614071 : "MOV result.color, vertex.color;") +
1341714072 ((mode & VP_PROJECTION) != 0 ? "MOV result.color, zero;"
1341814073 : "") +
....@@ -13663,6 +14318,7 @@
1366314318 else
1366414319 if (evt.getSource() == AAtimer)
1366514320 {
14321
+ Globals.TIMERRUNNING = false;
1366614322 if (mouseDown)
1366714323 {
1366814324 //new Exception().printStackTrace();
....@@ -13722,7 +14378,7 @@
1372214378
1372314379 // fev 2014???
1372414380 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13725
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14381
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1372614382 pingthread.StepToTarget(true); // true);
1372714383 }
1372814384 // if (!LIVE)
....@@ -13737,6 +14393,7 @@
1373714393 return;
1373814394
1373914395 AAtimer.restart(); //
14396
+ Globals.TIMERRUNNING = true;
1374014397
1374114398 // waslive = LIVE;
1374214399 // LIVE = false;
....@@ -13786,14 +14443,15 @@
1378614443 drag = false;
1378714444 //System.out.println("Mouse DOWN");
1378814445 editObj = false;
13789
- ClickInfo info = new ClickInfo();
13790
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
13791
- info.pane = this;
13792
- info.camera = renderCamera;
13793
- info.x = x;
13794
- info.y = y;
13795
- info.modifiers = modifiersex;
13796
- 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);
1379714455 if (!editObj)
1379814456 {
1379914457 hasMarquee = true;
....@@ -13809,9 +14467,12 @@
1380914467
1381014468 public void mouseDragged(MouseEvent e)
1381114469 {
14470
+ Globals.MOUSEDRAGGED = true;
14471
+
1381214472 //System.out.println("mouseDragged: " + e);
1381314473 if (isRenderer)
1381414474 movingcamera = true;
14475
+
1381514476 //if (drawing)
1381614477 //return;
1381714478 if ((e.getModifiersEx() & CTRL) != 0
....@@ -14072,12 +14733,18 @@
1407214733 void GoDown(int mod)
1407314734 {
1407414735 MODIFIERS |= COMMAND;
14075
- /*
14736
+ boolean isVR = (mouseMode&VR)!=0;
14737
+ /**/
1407614738 if((mod&SHIFT) == SHIFT)
14077
- manipCamera.RotatePosition(0, -speed);
14739
+ {
14740
+ if (isVR)
14741
+ manipCamera.RotateInterest(0, -speed);
14742
+ else
14743
+ manipCamera.RotatePosition(0, -speed);
14744
+ }
1407814745 else
14079
- manipCamera.BackForth(0, -speed*delta, getWidth());
14080
- */
14746
+ manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth());
14747
+ /**/
1408114748 if ((mod & SHIFT) == SHIFT)
1408214749 {
1408314750 mouseMode = mouseMode; // VR??
....@@ -14086,6 +14753,8 @@
1408614753 mouseMode |= BACKFORTH;
1408714754 }
1408814755
14756
+ targetLookAt.set(manipCamera.lookAt);
14757
+
1408914758 //prevX = X = anchorX;
1409014759 prevY = Y = anchorY - (int) (renderCamera.Distance());
1409114760 }
....@@ -14093,12 +14762,19 @@
1409314762 void GoUp(int mod)
1409414763 {
1409514764 MODIFIERS |= COMMAND;
14096
- /*
14765
+ /**/
14766
+ boolean isVR = (mouseMode&VR)!=0;
14767
+
1409714768 if((mod&SHIFT) == SHIFT)
14098
- manipCamera.RotatePosition(0, speed);
14769
+ {
14770
+ if (isVR)
14771
+ manipCamera.RotateInterest(0, speed);
14772
+ else
14773
+ manipCamera.RotatePosition(0, speed);
14774
+ }
1409914775 else
14100
- manipCamera.BackForth(0, speed*delta, getWidth());
14101
- */
14776
+ manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth());
14777
+ /**/
1410214778 if ((mod & SHIFT) == SHIFT)
1410314779 {
1410414780 mouseMode = mouseMode;
....@@ -14107,6 +14783,8 @@
1410714783 mouseMode |= BACKFORTH;
1410814784 }
1410914785
14786
+ targetLookAt.set(manipCamera.lookAt);
14787
+
1411014788 //prevX = X = anchorX;
1411114789 prevY = Y = anchorY + (int) (renderCamera.Distance());
1411214790 }
....@@ -14114,12 +14792,17 @@
1411414792 void GoLeft(int mod)
1411514793 {
1411614794 MODIFIERS |= COMMAND;
14117
- /*
14795
+ /**/
1411814796 if((mod&SHIFT) == SHIFT)
14119
- manipCamera.RotatePosition(speed, 0);
14797
+ manipCamera.Translate(speed*delta, 0, getWidth());
1412014798 else
14121
- manipCamera.Translate(speed*delta, 0, getWidth());
14122
- */
14799
+ {
14800
+ if ((mouseMode&VR)!=0)
14801
+ manipCamera.RotateInterest(-speed, 0);
14802
+ else
14803
+ manipCamera.RotatePosition(speed, 0);
14804
+ }
14805
+ /**/
1412314806 if ((mod & SHIFT) == SHIFT)
1412414807 {
1412514808 mouseMode = mouseMode;
....@@ -14128,6 +14811,8 @@
1412814811 mouseMode |= ROTATE;
1412914812 } // TRANSLATE;
1413014813
14814
+ targetLookAt.set(manipCamera.lookAt);
14815
+
1413114816 prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance());
1413214817 prevY = Y = anchorY;
1413314818 }
....@@ -14135,12 +14820,18 @@
1413514820 void GoRight(int mod)
1413614821 {
1413714822 MODIFIERS |= COMMAND;
14138
- /*
14823
+ /**/
1413914824 if((mod&SHIFT) == SHIFT)
14140
- manipCamera.RotatePosition(-speed, 0);
14825
+ manipCamera.Translate(-speed*delta, 0, getWidth());
1414114826 else
14142
- manipCamera.Translate(-speed*delta, 0, getWidth());
14143
- */
14827
+ {
14828
+ if ((mouseMode&VR)!=0)
14829
+ manipCamera.RotateInterest(speed, 0);
14830
+ else
14831
+ manipCamera.RotatePosition(-speed, 0);
14832
+ }
14833
+
14834
+ /**/
1414414835 if ((mod & SHIFT) == SHIFT)
1414514836 {
1414614837 mouseMode = mouseMode;
....@@ -14149,6 +14840,8 @@
1414914840 mouseMode |= ROTATE;
1415014841 } // TRANSLATE;
1415114842
14843
+ targetLookAt.set(manipCamera.lookAt);
14844
+
1415214845 prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance());
1415314846 prevY = Y = anchorY;
1415414847 }
....@@ -14190,14 +14883,16 @@
1419014883 if (editObj)
1419114884 {
1419214885 drag = true;
14193
- ClickInfo info = new ClickInfo();
14194
- info.bounds.setBounds(0, 0,
14886
+ //ClickInfo info = new ClickInfo();
14887
+ object.clickInfo.bounds.setBounds(0, 0,
1419514888 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14196
- info.pane = this;
14197
- info.camera = renderCamera;
14198
- info.x = x;
14199
- info.y = y;
14200
- 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);
1420114896 } else
1420214897 {
1420314898 if (x < startX)
....@@ -14346,22 +15041,27 @@
1434615041 }
1434715042 }
1434815043
15044
+// ClickInfo clickInfo = new ClickInfo();
15045
+
1434915046 public void mouseMoved(MouseEvent e)
1435015047 {
1435115048 //System.out.println("mouseMoved: " + e);
1435215049 if (isRenderer)
1435315050 return;
1435415051
14355
- ClickInfo ci = new ClickInfo();
14356
- ci.x = e.getX();
14357
- ci.y = e.getY();
14358
- ci.modifiers = e.getModifiersEx();
14359
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14360
- ci.pane = this;
14361
- 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;
1436215059 if (!isRenderer)
1436315060 {
14364
- if (object.editWindow.copy.doEditClick(ci, 0))
15061
+ //ObjEditor editWindow = object.editWindow;
15062
+ //Object3D copy = editWindow.copy;
15063
+ if (object.doEditClick(//clickInfo,
15064
+ 0))
1436515065 {
1436615066 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1436715067 } else
....@@ -14373,8 +15073,11 @@
1437315073
1437415074 public void mouseReleased(MouseEvent e)
1437515075 {
15076
+ Globals.MOUSEDRAGGED = false;
15077
+
1437615078 movingcamera = false;
14377
- X = Y = 0;
15079
+ X = 0; // getBounds().width/2;
15080
+ Y = 0; // getBounds().height/2;
1437815081 //System.out.println("mouseReleased: " + e);
1437915082 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1438015083 }
....@@ -14630,7 +15333,8 @@
1463015333 // break;
1463115334 case 'T':
1463215335 CACHETEXTURE ^= true;
14633
- textures.clear();
15336
+ texturepigment.clear();
15337
+ texturebump.clear();
1463415338 // repaint();
1463515339 break;
1463615340 case 'Y':
....@@ -14640,8 +15344,8 @@
1464015344 case 'K':
1464115345 KOMPACTTEXTURE ^= true;
1464215346 //textures.clear();
14643
- break;
14644
- case 'P': // Texture Projection macros
15347
+ // break;
15348
+ //case 'P': // Texture Projection macros
1464515349 // SAVETEXTURE ^= true;
1464615350 macromode = true;
1464715351 Udebug = Vdebug = NORMALdebug = false; programInitialized = false;
....@@ -14715,7 +15419,9 @@
1471515419 case 'E' : COMPACT ^= true;
1471615420 repaint();
1471715421 break;
14718
- case 'W' : DEBUGHSB ^= true;
15422
+ case 'W' : // Wide Window (fullscreen)
15423
+ //DEBUGHSB ^= true;
15424
+ ObjEditor.theFrame.ToggleFullScreen();
1471915425 repaint();
1472015426 break;
1472115427 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14740,8 +15446,8 @@
1474015446 RevertCamera();
1474115447 repaint();
1474215448 break;
14743
- case 'L':
1474415449 case 'l':
15450
+ //case 'L':
1474515451 if (lightMode)
1474615452 {
1474715453 lightMode = false;
....@@ -14760,7 +15466,7 @@
1476015466 targetLookAt.set(manipCamera.lookAt);
1476115467 repaint();
1476215468 break;
14763
- case 'p':
15469
+ case 'P': // p':
1476415470 // c'est quoi ca au juste? spherical ^= true;
1476515471 Skinshader ^= true; programInitialized = false;
1476615472 repaint();
....@@ -14805,20 +15511,24 @@
1480515511 OCCLUSION_CULLING ^= true;
1480615512 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1480715513 break;
14808
- case '0': envyoff ^= true; repaint(); break;
15514
+ //case '0': envyoff ^= true; repaint(); break;
1480915515 case '1':
1481015516 case '2':
1481115517 case '3':
1481215518 case '4':
1481315519 case '5':
14814
- newenvy = Character.getNumericValue(key);
14815
- repaint();
14816
- break;
1481715520 case '6':
1481815521 case '7':
1481915522 case '8':
1482015523 case '9':
14821
- 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
+ }
1482215532 repaint();
1482315533 break;
1482415534 case '!':
....@@ -14884,9 +15594,9 @@
1488415594 case '_':
1488515595 kompactbit = 5;
1488615596 break;
14887
- case '+':
14888
- kompactbit = 6;
14889
- break;
15597
+// case '+':
15598
+// kompactbit = 6;
15599
+// break;
1489015600 case ' ':
1489115601 lightMode ^= true;
1489215602 Globals.lighttouched = true;
....@@ -14898,6 +15608,7 @@
1489815608 case ESC:
1489915609 RENDERPROGRAM += 1;
1490015610 RENDERPROGRAM %= 3;
15611
+
1490115612 repaint();
1490215613 break;
1490315614 case 'Z':
....@@ -14937,8 +15648,9 @@
1493715648 case DELETE:
1493815649 ClearSelection();
1493915650 break;
14940
- /*
1494115651 case '+':
15652
+
15653
+ /*
1494215654 //fontsize += 1;
1494315655 bbzoom *= 2;
1494415656 repaint();
....@@ -14955,17 +15667,17 @@
1495515667 case '=':
1495615668 IncDepth();
1495715669 //fontsize += 1;
14958
- object.editWindow.refreshContents(true);
15670
+ object.GetWindow().refreshContents(true);
1495915671 maskbit = 6;
1496015672 break;
1496115673 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1496215674 DecDepth();
1496315675 maskbit = 5;
1496415676 //if(fontsize > 1) fontsize -= 1;
14965
- if (object.editWindow == null)
14966
- new Exception().printStackTrace();
14967
- else
14968
- object.editWindow.refreshContents(true);
15677
+// if (object.editWindow == null)
15678
+// new Exception().printStackTrace();
15679
+// else
15680
+ object.GetWindow().refreshContents(true);
1496915681 break;
1497015682 case '{':
1497115683 manipCamera.shaper_fovy /= 1.1;
....@@ -15189,7 +15901,7 @@
1518915901 }
1519015902 */
1519115903
15192
- object.editWindow.EditSelection();
15904
+ object.GetWindow().EditSelection(false);
1519315905 }
1519415906
1519515907 void SelectParent()
....@@ -15206,10 +15918,10 @@
1520615918 {
1520715919 //selectees.remove(i);
1520815920 System.out.println("select parent of " + elem);
15209
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15921
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1521015922 } else
1521115923 {
15212
- group.editWindow.Select(elem.GetTreePath(), first, true);
15924
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1521315925 }
1521415926
1521515927 first = false;
....@@ -15251,12 +15963,12 @@
1525115963 for (int j = 0; j < group.children.size(); j++)
1525215964 {
1525315965 elem = (Object3D) group.children.elementAt(j);
15254
- object.editWindow.Select(elem.GetTreePath(), first, true);
15966
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1525515967 first = false;
1525615968 }
1525715969 } else
1525815970 {
15259
- object.editWindow.Select(elem.GetTreePath(), first, true);
15971
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1526015972 }
1526115973
1526215974 first = false;
....@@ -15267,21 +15979,21 @@
1526715979 {
1526815980 //Composite group = (Composite) object;
1526915981 Object3D group = object;
15270
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15982
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1527115983 }
1527215984
1527315985 void ResetTransform(int mask)
1527415986 {
1527515987 //Composite group = (Composite) object;
1527615988 Object3D group = object;
15277
- group.editWindow.ResetTransform(mask);
15989
+ group.GetWindow().ResetTransform(mask);
1527815990 }
1527915991
1528015992 void FlipTransform()
1528115993 {
1528215994 //Composite group = (Composite) object;
1528315995 Object3D group = object;
15284
- group.editWindow.FlipTransform();
15996
+ group.GetWindow().FlipTransform();
1528515997 // group.editWindow.ReduceMesh(true);
1528615998 }
1528715999
....@@ -15289,7 +16001,7 @@
1528916001 {
1529016002 //Composite group = (Composite) object;
1529116003 Object3D group = object;
15292
- group.editWindow.PrintMemory();
16004
+ group.GetWindow().PrintMemory();
1529316005 // group.editWindow.ReduceMesh(true);
1529416006 }
1529516007
....@@ -15297,7 +16009,7 @@
1529716009 {
1529816010 //Composite group = (Composite) object;
1529916011 Object3D group = object;
15300
- group.editWindow.ResetCentroid();
16012
+ group.GetWindow().ResetCentroid();
1530116013 }
1530216014
1530316015 void IncDepth()
....@@ -15379,8 +16091,6 @@
1537916091
1538016092 int width = getBounds().width;
1538116093 int height = getBounds().height;
15382
- ClickInfo info = new ClickInfo();
15383
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1538416094 //Image img = CreateImage(width, height);
1538516095 //System.out.println("width = " + width + "; height = " + height + "\n");
1538616096
....@@ -15457,43 +16167,77 @@
1545716167 }
1545816168 if (object != null && !hasMarquee)
1545916169 {
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
+
1546016176 if (isRenderer)
1546116177 {
15462
- info.flags++;
16178
+ object.clickInfo.flags++;
1546316179 double frameAspect = (double) width / (double) height;
1546416180 if (frameAspect > renderCamera.aspect)
1546516181 {
1546616182 int desired = (int) ((double) height * renderCamera.aspect);
15467
- info.bounds.width -= width - desired;
15468
- info.bounds.x += (width - desired) / 2;
16183
+ object.clickInfo.bounds.width -= width - desired;
16184
+ object.clickInfo.bounds.x += (width - desired) / 2;
1546916185 } else
1547016186 {
1547116187 int desired = (int) ((double) width / renderCamera.aspect);
15472
- info.bounds.height -= height - desired;
15473
- info.bounds.y += (height - desired) / 2;
16188
+ object.clickInfo.bounds.height -= height - desired;
16189
+ object.clickInfo.bounds.y += (height - desired) / 2;
1547416190 }
1547516191 }
15476
- info.g = gr;
15477
- info.camera = renderCamera;
16192
+
16193
+ object.clickInfo.g = gr;
16194
+ object.clickInfo.camera = renderCamera;
1547816195 /*
1547916196 // Memory intensive (brep.verticescopy)
1548016197 if (!(object instanceof Composite))
1548116198 object.draw(info, 0, false); // SLOW :
1548216199 */
15483
- if (!isRenderer)
16200
+ if (!isRenderer) // && drag)
1548416201 {
15485
- object.drawEditHandles(info, 0);
15486
-
15487
- 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)
1548816205 {
15489
- 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)
1549016212 {
15491
- case Object3D.hitCenter: gr.setColor(Color.pink); break;
15492
- case Object3D.hitRotate: gr.setColor(Color.green); break;
15493
- 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;
1549416220 }
15495
-
15496
- 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
+ }
1549716241 }
1549816242 }
1549916243 }
....@@ -15508,7 +16252,7 @@
1550816252 if (hasMarquee)
1550916253 {
1551016254 gr.setXORMode(Color.white);
15511
- gr.setColor(Color.red);
16255
+ gr.setColor(Color.white);
1551216256 if (!firstime)
1551316257 {
1551416258 gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH);
....@@ -15911,7 +16655,7 @@
1591116655 Object3D object;
1591216656 static Object3D trackedobject;
1591316657 Camera renderCamera; // Light or Eye (or Occlusion)
15914
- /*static*/ Camera manipCamera; // Light or Eye
16658
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1591516659 /*static*/ Camera eyeCamera;
1591616660 /*static*/ Camera lightCamera;
1591716661 int cameracount;
....@@ -15975,6 +16719,8 @@
1597516719 private /*static*/ boolean firstime;
1597616720 private /*static*/ cVector newView = new cVector();
1597716721 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"};
1597816724 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1597916725 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1598016726 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -15987,29 +16733,67 @@
1598716733 {
1598816734 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1598916735
16736
+ int usedsuf = 0;
16737
+
1599016738 for (int i = 0; i < suffixes.length; i++)
1599116739 {
15992
- String resourceName = basename + suffixes[i] + "." + suffix;
15993
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
15994
- mipmapped,
15995
- FileUtil.getFileSuffix(resourceName));
15996
- if (data == null)
16740
+ String[] suffixe = suffixes;
16741
+ String[] fallback = suffixes2;
16742
+ String[] fallfallback = suffixes3;
16743
+
16744
+ for (int c=usedsuf; --c>=0;)
1599716745 {
15998
- throw new IOException("Unable to load texture " + resourceName);
16746
+// String[] temp = suffixe;
16747
+// suffixe = fallback;
16748
+// fallback = fallfallback;
16749
+// fallfallback = temp;
1599916750 }
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
+
1600016779 //System.out.println("Target = " + targets[i]);
1600116780 cubemap.updateImage(data, targets[i]);
1600216781 }
1600316782
1600416783 return cubemap;
1600516784 }
16785
+
1600616786 int bigsphere = -1;
1600716787
1600816788 float BGcolor = 0.5f;
1600916789
16010
- private void DrawSkyBox(GL gl)
16790
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16791
+
16792
+ private void DrawSkyBox(GL gl, float ratio)
1601116793 {
16012
- if (envyoff || cubemap == null)
16794
+ if (//envyoff ||
16795
+ WIREFRAME ||
16796
+ cubemap == null)
1601316797 {
1601416798 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1601516799 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16024,7 +16808,17 @@
1602416808 // Compensates for ExaminerViewer's modification of modelview matrix
1602516809 gl.glMatrixMode(GL.GL_MODELVIEW);
1602616810 gl.glLoadIdentity();
16811
+ gl.glScalef(1,ratio,1);
1602716812
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
+
1602816822 //gl.glActiveTexture(GL.GL_TEXTURE1);
1602916823 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1603016824
....@@ -16056,6 +16850,7 @@
1605616850 {
1605716851 gl.glScalef(1.0f, -1.0f, 1.0f);
1605816852 }
16853
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1605916854 gl.glMultMatrixd(viewrot_1, 0);
1606016855 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1606116856 //viewer.updateInverseRotation(gl);
....@@ -16096,7 +16891,8 @@
1609616891 gl.glDisable(GL.GL_TEXTURE_GEN_R);
1609716892
1609816893 cubemap.disable();
16099
- ////cubemap.unbind();
16894
+ //cubemap.dispose();
16895
+
1610016896 if (CULLFACE)
1610116897 {
1610216898 gl.glEnable(gl.GL_CULL_FACE);
....@@ -16152,7 +16948,7 @@
1615216948 gl.glScalef(1.0f, -1.0f, 1.0f);
1615316949 }
1615416950
16155
- gl.glNormal3f(0.0f, 0.0f, 1.0f);
16951
+ SetGLNormal(gl, 0.0f, 0.0f, 1.0f);
1615616952
1615716953 float step = 2; // 0.1666f; //0.25f;
1615816954 float stepv = 2; // step * 1652 / 998;
....@@ -16196,16 +16992,16 @@
1619616992 cStatic.objectstack[materialdepth++] = checker;
1619716993 //System.out.println("material " + material);
1619816994 //Applet3D.tracein(this, selected);
16199
- vector2buffer = checker.projectedVertices;
16995
+ //vector2buffer = checker.projectedVertices;
1620016996
1620116997 //checker.GetMaterial().Draw(this, false); // true);
16202
- DrawMaterial(checker.GetMaterial(), false); // true);
16998
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1620316999
1620417000 materialdepth -= 1;
1620517001 if (materialdepth > 0)
1620617002 {
16207
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16208
- 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);
1620917005 }
1621017006 //checker.GetMaterial().opacity = 1f;
1621117007 ////checker.GetMaterial().ambient = 1f;
....@@ -16291,6 +17087,14 @@
1629117087 }
1629217088 }
1629317089
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
+
1629417098 class SelectBuffer implements GLEventListener
1629517099 {
1629617100
....@@ -16306,7 +17110,7 @@
1630617110 //new Exception().printStackTrace();
1630717111 System.out.println("select buffer init");
1630817112 // Use debug pipeline
16309
- drawable.setGL(new DebugGL(drawable.getGL()));
17113
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1631017114
1631117115 GL gl = drawable.getGL();
1631217116
....@@ -16370,6 +17174,17 @@
1637017174
1637117175 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1637217176
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
+
1637317188 //int tmp = selection_view;
1637417189 //selection_view = -1;
1637517190 int temp = DrawMode();
....@@ -16381,6 +17196,17 @@
1638117196 // temp = DEFAULT; // patch for selection debug
1638217197 Globals.drawMode = temp; // WARNING
1638317198
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
+
1638417210 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1638517211
1638617212 // trying different ways of getting the depth info over
....@@ -16428,6 +17254,8 @@
1642817254 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1642917255 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1643017256 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
17257
+
17258
+ CreateSelectedPoint();
1643117259
1643217260 // Will fit the mesh !!!
1643317261 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16482,29 +17310,31 @@
1648217310 }
1648317311
1648417312 if (!movingcamera && !PAINTMODE)
16485
- object.editWindow.ScreenFitPoint(); // fev 2014
17313
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1648617314
16487
- 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)
1648817316 {
16489
- 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);
1649017318
16491
- Object3D group = new Object3D("inst" + paintcount++);
17319
+ if (object.GetWindow().copy.selection.Size() > 0)
17320
+ {
17321
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1649217322
16493
- group.CreateMaterial(); // use a void leaf to select instances
16494
-
16495
- group.add(paintobj); // link
16496
-
16497
- object.editWindow.SnapObject(group);
16498
-
16499
- Object3D folder = object.editWindow.copy;
16500
-
16501
- if (object.editWindow.copy.selection.Size() > 0)
16502
- folder = object.editWindow.copy.selection.elementAt(0);
16503
-
16504
- folder.add(group);
16505
-
16506
- object.editWindow.ResetModel();
16507
- 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
+ }
1650817338 }
1650917339 else
1651017340 paintcount = 0;
....@@ -16543,6 +17373,11 @@
1654317373 //System.out.println("objects[color] = " + objects[color]);
1654417374 //objects[color].Select();
1654517375 indexcount = 0;
17376
+ ObjEditor window = object.GetWindow();
17377
+ if (window != null && deselect)
17378
+ {
17379
+ window.Select(null, deselect, true);
17380
+ }
1654617381 object.Select(color, deselect);
1654717382 }
1654817383
....@@ -16593,6 +17428,7 @@
1659317428
1659417429 public void init(GLAutoDrawable drawable)
1659517430 {
17431
+ if (Globals.DEBUG)
1659617432 System.out.println("shadow buffer init");
1659717433
1659817434 GL gl = drawable.getGL();
....@@ -16821,10 +17657,14 @@
1682117657 gl.glFlush();
1682217658
1682317659 /**/
16824
- 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);
1682517661
16826
- float[] pixels = occlusionsizebuffer.array();
17662
+ float[] depths = occlusiondepthbuffer.array();
1682717663
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
+
1682817668 double r = 0, g = 0, b = 0;
1682917669
1683017670 double count = 0;
....@@ -16835,7 +17675,7 @@
1683517675
1683617676 double FACTOR = 1;
1683717677
16838
- for (int i = 0; i < pixels.length; i++)
17678
+ for (int i = 0; i < depths.length; i++)
1683917679 {
1684017680 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1684117681 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -16918,7 +17758,7 @@
1691817758
1691917759 double scale = ray.z; // 1; // cos
1692017760
16921
- float depth = pixels[newindex];
17761
+ float depth = depths[newindex];
1692217762
1692317763 /*
1692417764 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -17068,23 +17908,15 @@
1706817908 int AAbuffersize = 0;
1706917909
1707017910 //double[] selectedpoint = new double[3];
17071
- static Superellipsoid selectedpoint = new Superellipsoid();
17911
+ static Superellipsoid selectedpoint;
1707217912 static Sphere previousselectedpoint = null;
17073
- static Sphere debugpointG = new Sphere();
17074
- static Sphere debugpointP = new Sphere();
17075
- static Sphere debugpointC = new Sphere();
17076
- static Sphere debugpointR = new Sphere();
17913
+ static Sphere debugpointG;
17914
+ static Sphere debugpointP;
17915
+ static Sphere debugpointC;
17916
+ static Sphere debugpointR;
1707717917
1707817918 static Sphere debugpoints[] = new Sphere[8];
1707917919
17080
- static
17081
- {
17082
- for (int i=0; i<8; i++)
17083
- {
17084
- debugpoints[i] = new Sphere();
17085
- }
17086
- }
17087
-
1708817920 static void InitPoints(float radius)
1708917921 {
1709017922 for (int i=0; i<8; i++)
....@@ -17123,11 +17955,14 @@
1712317955 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1712417956 static IntBuffer bigAAbuffer;
1712517957 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
17126
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17958
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1712717959 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1712817960 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1712917961 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17130
- 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
+
1713117966 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1713217967 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1713317968 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();