Normand Briere
2019-08-13 c67de8aca04d988179191ccb52461af00125920e
CameraPane.java
....@@ -18,7 +18,10 @@
1818 import javax.imageio.ImageIO;
1919 import javax.imageio.ImageWriteParam;
2020 import javax.imageio.ImageWriter;
21
+import javax.imageio.ImageReadParam;
22
+import javax.imageio.ImageReader;
2123 import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
24
+import javax.imageio.stream.ImageInputStream;
2225 import javax.imageio.stream.ImageOutputStream;
2326 import javax.imageio.ImageWriteParam;
2427
....@@ -30,6 +33,7 @@
3033 import java.nio.*;
3134
3235 import gleem.linalg.Mat4f;
36
+import javax.imageio.ImageTypeSpecifier;
3337
3438 class CameraPane extends GLCanvas implements iCameraPane, Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener
3539 {
....@@ -37,7 +41,6 @@
3741 static boolean[] selectedstack = new boolean[65536];
3842 static int materialdepth = 0;
3943
40
- static boolean DEBUG = false;
4144 static boolean FRUSTUM = false; // still bogus true; // frustum culling
4245
4346 // camera change fix
....@@ -45,6 +48,39 @@
4548 static boolean ABORTED = false;
4649
4750 static int STEP = 1;
51
+
52
+ private static BufferedImage CreateBim(byte[] bytes, int width, int height)
53
+ {
54
+ int[] pixels = new int[bytes.length/3];
55
+ for (int i=pixels.length; --i>=0;)
56
+ {
57
+ int i3 = i*3;
58
+ pixels[i] = 0xFF;
59
+ pixels[i] <<= 8;
60
+ pixels[i] |= bytes[i3+2] & 0xFF;
61
+ pixels[i] <<= 8;
62
+ pixels[i] |= bytes[i3+1] & 0xFF;
63
+ pixels[i] <<= 8;
64
+ pixels[i] |= bytes[i3] & 0xFF;
65
+ }
66
+ /*
67
+ int r=0,g=0,b=0,a=0;
68
+ for (int i=0; i<width; i++)
69
+ for (int j=0; j<height; j++)
70
+ {
71
+ int index = j*width+i;
72
+ int p = pixels[index];
73
+ a = ((p>>24) & 0xFF);
74
+ r = ((p>>16) & 0xFF);
75
+ g = ((p>>8) & 0xFF);
76
+ b = (p & 0xFF);
77
+ pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
78
+ }
79
+ /**/
80
+ BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
81
+ rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
82
+ return rendImage;
83
+ }
4884
4985 /*static*/ private boolean CULLFACE = false; // true;
5086 /*static*/ boolean NEAREST = false; // true;
....@@ -56,14 +92,12 @@
5692 static int CURRENTANTIALIAS = 0; // 1;
5793 /*static*/ boolean RENDERSHADOW = true;
5894 /*static*/ int RENDERPROGRAM = 2; // 0 == none, 1 == fast, 2 == normal
59
- static boolean ANIMATION = false;
60
- static String filename;
6195
6296 boolean DISPLAYTEXT = false;
6397 //boolean REDUCETEXTURE = true;
6498 boolean CACHETEXTURE = true;
6599 boolean CLEANCACHE = false; // true;
66
- boolean MIPMAP = false; // true;
100
+ boolean MIPMAP = false; // true; // never works...
67101 boolean COMPRESSTEXTURE = false;
68102 boolean KOMPACTTEXTURE = false; // true;
69103 boolean RESIZETEXTURE = false;
....@@ -76,7 +110,9 @@
76110 //private Mat4f spotlightTransform = new Mat4f();
77111 //private Mat4f spotlightInverseTransform = new Mat4f();
78112 static GLContext glcontext = null;
79
- /*static*/ com.sun.opengl.util.texture.Texture cubemap;
113
+ /*static*/ com.sun.opengl.util.texture.Texture cubemap; // Either custom or rgb
114
+ /*static*/ com.sun.opengl.util.texture.Texture cubemapcustom;
115
+ /*static*/ com.sun.opengl.util.texture.Texture cubemaprgb;
80116 boolean reverseUP = false;
81117 static boolean frozen = false;
82118 boolean enablebackspace = false; // patch for back buffer refresh
....@@ -86,7 +122,7 @@
86122 static boolean FULLSCREEN = false;
87123 static boolean SUPPORT = true;
88124 static boolean INERTIA = true;
89
-static boolean FAST = true; // false;
125
+static boolean FAST = false;
90126 static boolean SLOWPOSE = false;
91127 static boolean FOOTCONTACT = true;
92128
....@@ -108,7 +144,7 @@
108144 static boolean OEIL = true;
109145 static boolean OEILONCE = false; // do oeilon then oeiloff
110146 static boolean LOOKAT = true;
111
-static boolean RANDOM = true; // false;
147
+static boolean SWITCH = true; // false;
112148 static boolean HANDLES = false; // selection doesn't work!!
113149 static boolean PAINTMODE = false;
114150
....@@ -139,7 +175,7 @@
139175 static boolean doublesided = false; // true; // reversed normals are awful for conformance
140176 boolean anisotropy = true;
141177 boolean softshadow = true; // slower but better false;
142
- boolean opacityhalo = false;
178
+ boolean opacityhalo = false; // reverse the halo effect (e.g. glass)
143179
144180 boolean macromode = false;
145181
....@@ -150,6 +186,21 @@
150186 defaultcaps.setAccumGreenBits(16);
151187 defaultcaps.setAccumBlueBits(16);
152188 defaultcaps.setAccumAlphaBits(16);
189
+ }
190
+
191
+ private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
192
+
193
+ public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException
194
+ {
195
+ try
196
+ {
197
+ return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
198
+ } catch (IOException e)
199
+ {
200
+ System.out.println("NAME = " + name);
201
+ e.printStackTrace(); // throw new RuntimeException(e);
202
+ return null;
203
+ }
153204 }
154205
155206 void SetAsGLRenderer(boolean b)
....@@ -170,7 +221,8 @@
170221
171222 SetCamera(cam);
172223
173
- SetLight(new Camera(new cVector(10, 10, -20)));
224
+ // Warning: not used.
225
+ SetLight(new Camera(new cVector(15, 10, -20)));
174226
175227 object = o;
176228
....@@ -327,7 +379,7 @@
327379 cStatic.objectstack[materialdepth++] = obj;
328380 //System.out.println("material " + material);
329381 //Applet3D.tracein(this, selected);
330
- display.vector2buffer = obj.projectedVertices;
382
+ //display.vector2buffer = obj.projectedVertices;
331383 if (obj instanceof Camera)
332384 {
333385 display.options1[0] = material.shift;
....@@ -336,14 +388,28 @@
336388 display.options1[2] = material.shadowbias;
337389 display.options1[3] = material.aniso;
338390 display.options1[4] = material.anisoV;
391
+// System.out.println("display.options1[0] " + display.options1[0]);
392
+// System.out.println("display.options1[1] " + display.options1[1]);
393
+// System.out.println("display.options1[2] " + display.options1[2]);
394
+// System.out.println("display.options1[3] " + display.options1[3]);
395
+// System.out.println("display.options1[4] " + display.options1[4]);
339396 display.options2[0] = material.opacity;
340397 display.options2[1] = material.diffuse;
341398 display.options2[2] = material.factor;
399
+// System.out.println("display.options2[0] " + display.options2[0]);
400
+// System.out.println("display.options2[1] " + display.options2[1]);
401
+// System.out.println("display.options2[2] " + display.options2[2]);
342402
343403 cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
404
+// System.out.println("display.options3[0] " + display.options3[0]);
405
+// System.out.println("display.options3[1] " + display.options3[1]);
406
+// System.out.println("display.options3[2] " + display.options3[2]);
344407 display.options4[0] = material.cameralight/0.2f;
345408 display.options4[1] = material.subsurface;
346409 display.options4[2] = material.sheen;
410
+// System.out.println("display.options4[0] " + display.options4[0]);
411
+// System.out.println("display.options4[1] " + display.options4[1]);
412
+// System.out.println("display.options4[2] " + display.options4[2]);
347413
348414 // if (display.CURRENTANTIALIAS > 0)
349415 // display.options3[3] /= 4;
....@@ -359,7 +425,7 @@
359425 /**/
360426 } else
361427 {
362
- DrawMaterial(material, selected);
428
+ DrawMaterial(material, selected, obj.projectedVertices);
363429 }
364430 } else
365431 {
....@@ -383,8 +449,8 @@
383449 cStatic.objectstack[materialdepth++] = obj;
384450 //System.out.println("material " + material);
385451 //Applet3D.tracein("selected ", selected);
386
- display.vector2buffer = obj.projectedVertices;
387
- display.DrawMaterial(material, selected);
452
+ //display.vector2buffer = obj.projectedVertices;
453
+ display.DrawMaterial(material, selected, obj.projectedVertices);
388454 }
389455 }
390456
....@@ -401,8 +467,8 @@
401467 materialdepth -= 1;
402468 if (materialdepth > 0)
403469 {
404
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
405
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
470
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
471
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
406472 }
407473 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
408474 } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
....@@ -422,8 +488,8 @@
422488 materialdepth -= 1;
423489 if (materialdepth > 0)
424490 {
425
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
426
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
491
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
492
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
427493 }
428494 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
429495 //else
....@@ -464,10 +530,12 @@
464530 if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
465531 {
466532 //gl.glBegin(gl.GL_TRIANGLES);
467
- boolean hasnorm = pv.norm != null; // && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0);
533
+ boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0)
534
+ // TEST LIVE NORMALS && !obj.dontselect
535
+ ;
468536 if (!hasnorm)
469537 {
470
- // System.out.println("FUCK!!");
538
+ // System.out.println("Mesh normal");
471539 LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
472540 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
473541 LA.vecCross(obj.v0, obj.v1, obj.v2);
....@@ -1192,10 +1260,12 @@
11921260 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
11931261 }
11941262 }
1263
+
11951264 if (flipV)
11961265 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
11971266 else
11981267 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1268
+
11991269 //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
12001270 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
12011271
....@@ -1215,10 +1285,12 @@
12151285 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
12161286 }
12171287 }
1288
+
12181289 if (flipV)
12191290 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12201291 else
12211292 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1293
+
12221294 //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
12231295 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
12241296
....@@ -1246,8 +1318,10 @@
12461318 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12471319 else
12481320 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1321
+
12491322 //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
12501323 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1324
+
12511325 count2 += 2;
12521326 count3 += 3;
12531327 }
....@@ -1426,6 +1500,8 @@
14261500 gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
14271501 }
14281502
1503
+ float[] colorV = new float[4];
1504
+
14291505 void SetColor(Object3D obj, Vertex p0)
14301506 {
14311507 CameraPane display = this;
....@@ -1493,8 +1569,6 @@
14931569 {
14941570 return;
14951571 }
1496
-
1497
- float[] colorV = new float[3];
14981572
14991573 if (false) // marked)
15001574 {
....@@ -1603,7 +1677,7 @@
16031677 // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
16041678 }
16051679
1606
- void DrawMaterial(cMaterial material, boolean selected)
1680
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
16071681 {
16081682 CameraPane display = this;
16091683 //new Exception().printStackTrace();
....@@ -1630,7 +1704,7 @@
16301704
16311705 cColor.HSBtoRGB(display.color, display.saturation, 1, display.modelParams0);
16321706
1633
- float[] colorV = GrafreeD.colorV;
1707
+ float[] colorV = Grafreed.colorV;
16341708
16351709 /**/
16361710 if (display.DrawMode() == display.DEFAULT) // && display.RENDERPROGRAM == 0)
....@@ -1638,7 +1712,7 @@
16381712 colorV[0] = display.modelParams0[0] * material.diffuse;
16391713 colorV[1] = display.modelParams0[1] * material.diffuse;
16401714 colorV[2] = display.modelParams0[2] * material.diffuse;
1641
- colorV[3] = material.opacity;
1715
+ colorV[3] = 1; // material.opacity;
16421716
16431717 gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
16441718 //System.out.println("Opacity = " + opacity);
....@@ -1746,9 +1820,9 @@
17461820 display.modelParams7[2] = 0;
17471821 display.modelParams7[3] = 0;
17481822
1749
- display.modelParams6[0] = 100; // criss de bug de bump
1823
+ //display.modelParams6[0] = 100; // criss de bug de bump
17501824
1751
- Object3D.cVector2[] extparams = display.vector2buffer;
1825
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
17521826 if (extparams != null && extparams.length > 0 && extparams[0] != null)
17531827 {
17541828 display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
....@@ -1890,7 +1964,7 @@
18901964 void PushMatrix(double[][] matrix)
18911965 {
18921966 // GrafreeD.tracein(matrix);
1893
- PushMatrix(matrix,1);
1967
+ PushMatrix(matrix, 1);
18941968 }
18951969
18961970 void PushMatrix()
....@@ -2044,7 +2118,7 @@
20442118 //System.err.println("Oeil on");
20452119 OEIL = true;
20462120 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2047
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2121
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
20482122 //pingthread.StepToTarget(true);
20492123 }
20502124
....@@ -2142,7 +2216,7 @@
21422216 System.err.println("LIVE = " + Globals.isLIVE());
21432217
21442218 if (!Globals.isLIVE()) // save sound
2145
- GrafreeD.savesound = true; // wav.save();
2219
+ Grafreed.savesound = true; // wav.save();
21462220 // else
21472221 repaint(); // start loop // may 2013
21482222 }
....@@ -2259,7 +2333,7 @@
22592333
22602334 void ToggleDebug()
22612335 {
2262
- DEBUG ^= true;
2336
+ Globals.DEBUG ^= true;
22632337 }
22642338
22652339 void ToggleLookAt()
....@@ -2267,9 +2341,9 @@
22672341 LOOKAT ^= true;
22682342 }
22692343
2270
- void ToggleRandom()
2344
+ void ToggleSwitch()
22712345 {
2272
- RANDOM ^= true;
2346
+ SWITCH ^= true;
22732347 }
22742348
22752349 void ToggleHandles()
....@@ -2277,10 +2351,17 @@
22772351 HANDLES ^= true;
22782352 }
22792353
2354
+ Object3D paintFolder;
2355
+
22802356 void TogglePaint()
22812357 {
22822358 PAINTMODE ^= true;
22832359 paintcount = 0;
2360
+
2361
+ if (PAINTMODE)
2362
+ {
2363
+ paintFolder = GetFolder();
2364
+ }
22842365 }
22852366
22862367 void SwapCamera(int a, int b)
....@@ -2376,7 +2457,22 @@
23762457 {
23772458 return currentGL;
23782459 }
2379
-
2460
+
2461
+ static private BufferedImage CreateBim(TextureData texturedata)
2462
+ {
2463
+ Grafreed.Assert(texturedata != null);
2464
+
2465
+ int width = texturedata.getWidth();
2466
+ int height = texturedata.getHeight();
2467
+
2468
+ Buffer buffer = texturedata.getBuffer();
2469
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2470
+
2471
+ byte[] bytes = bytebuf.array();
2472
+
2473
+ return CreateBim(bytes, width, height);
2474
+ }
2475
+
23802476 /**/
23812477 class CacheTexture
23822478 {
....@@ -2385,28 +2481,31 @@
23852481
23862482 int resolution;
23872483
2388
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2484
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
23892485 {
2390
- texture = tex;
2486
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2487
+ texturedata = texdata;
23912488 resolution = res;
23922489 }
23932490 }
23942491 /**/
23952492
23962493 // TEXTURE static Texture texture;
2397
- static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures
2398
- = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>();
2399
- static public java.util.Hashtable<String, String> usedtextures = new java.util.Hashtable<String, String>();
2494
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2495
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2496
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2497
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2498
+
24002499 int pigmentdepth = 0;
24012500 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
24022501 int bumpdepth = 0;
24032502 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
24042503 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
24052504 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2406
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2505
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
24072506 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
24082507
2409
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2508
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
24102509 {
24112510 TextureData texturedata = null;
24122511
....@@ -2425,13 +2524,34 @@
24252524 if (bump)
24262525 texturedata = ConvertBump(texturedata, false);
24272526
2428
- com.sun.opengl.util.texture.Texture texture =
2429
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2527
+// com.sun.opengl.util.texture.Texture texture =
2528
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
24302529
2431
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2432
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
2530
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2531
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
24332532
2434
- return texture;
2533
+ return texturedata;
2534
+ }
2535
+
2536
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2537
+ {
2538
+ TextureData texturedata = null;
2539
+
2540
+ try
2541
+ {
2542
+ texturedata =
2543
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2544
+ bim,
2545
+ true);
2546
+ } catch (Exception e)
2547
+ {
2548
+ throw new javax.media.opengl.GLException(e);
2549
+ }
2550
+
2551
+ if (bump)
2552
+ texturedata = ConvertBump(texturedata, false);
2553
+
2554
+ return texturedata;
24352555 }
24362556
24372557 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3504,6 +3624,8 @@
35043624
35053625 System.out.println("LOADING TEXTURE : " + name);
35063626
3627
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3628
+
35073629 //
35083630 if (false) // compressbit > 0)
35093631 {
....@@ -4208,6 +4330,7 @@
42084330
42094331 com.sun.opengl.util.texture.Texture CompressTexture2(String name)
42104332 {
4333
+ new Exception().printStackTrace();
42114334 System.exit(0);
42124335 com.sun.opengl.util.texture.Texture texture = null;
42134336
....@@ -7901,7 +8024,7 @@
79018024 String pigment = Object3D.GetPigment(tex);
79028025 String bump = Object3D.GetBump(tex);
79038026
7904
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8027
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79058028 {
79068029 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79078030 // System.out.println("; bump = " + bump);
....@@ -7916,11 +8039,69 @@
79168039 pigment = null;
79178040 }
79188041
7919
- ReleaseTexture(bump, true);
7920
- ReleaseTexture(pigment, false);
8042
+ ReleaseTexture(tex, true);
8043
+ ReleaseTexture(tex, false);
79218044 }
79228045
7923
- void ReleaseTexture(String tex, boolean bump)
8046
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
8047
+ {
8048
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8049
+ {
8050
+ return;
8051
+ }
8052
+
8053
+ if (tex == null)
8054
+ {
8055
+ ReleaseTexture(null, false);
8056
+ return;
8057
+ }
8058
+
8059
+ String pigment = Object3D.GetPigment(tex);
8060
+
8061
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8062
+ {
8063
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8064
+ // System.out.println("; bump = " + bump);
8065
+ }
8066
+
8067
+ if (pigment.equals(""))
8068
+ {
8069
+ pigment = null;
8070
+ }
8071
+
8072
+ ReleaseTexture(tex, false);
8073
+ }
8074
+
8075
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
8076
+ {
8077
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8078
+ {
8079
+ return;
8080
+ }
8081
+
8082
+ if (tex == null)
8083
+ {
8084
+ ReleaseTexture(null, true);
8085
+ return;
8086
+ }
8087
+
8088
+ String bump = Object3D.GetBump(tex);
8089
+
8090
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8091
+ {
8092
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8093
+ // System.out.println("; bump = " + bump);
8094
+ }
8095
+
8096
+ if (bump.equals(""))
8097
+ {
8098
+ bump = null;
8099
+ }
8100
+
8101
+ ReleaseTexture(tex, true);
8102
+ }
8103
+
8104
+ void ReleaseTexture(cTexture tex, boolean bump)
79248105 {
79258106 if (// DrawMode() != 0 || /*tex == null ||*/
79268107 ambientOcclusion ) // || !textureon)
....@@ -7931,7 +8112,7 @@
79318112 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
79328113
79338114 if (tex != null)
7934
- texture = textures.get(tex);
8115
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
79358116
79368117 // //assert( texture != null );
79378118 // if (texture == null)
....@@ -8023,7 +8204,55 @@
80238204 }
80248205 }
80258206
8026
- /*boolean*/ public void BindTextures(cTexture tex, int resolution) // INTERFACE
8207
+ /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
8208
+ {
8209
+// if (// DrawMode() != 0 || /*tex == null ||*/
8210
+// ambientOcclusion ) // || !textureon)
8211
+// {
8212
+// return; // false;
8213
+// }
8214
+//
8215
+// if (tex == null)
8216
+// {
8217
+// BindTexture(null,false,resolution);
8218
+// BindTexture(null,true,resolution);
8219
+// return;
8220
+// }
8221
+//
8222
+// String pigment = Object3D.GetPigment(tex);
8223
+// String bump = Object3D.GetBump(tex);
8224
+//
8225
+// usedtextures.add(pigment);
8226
+// usedtextures.add(bump);
8227
+//
8228
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8229
+// {
8230
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8231
+// // System.out.println("; bump = " + bump);
8232
+// }
8233
+//
8234
+// if (bump.equals(""))
8235
+// {
8236
+// bump = null;
8237
+// }
8238
+// if (pigment.equals(""))
8239
+// {
8240
+// pigment = null;
8241
+// }
8242
+//
8243
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8244
+// BindTexture(pigment, false, resolution);
8245
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8246
+// BindTexture(bump, true, resolution);
8247
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8248
+//
8249
+// return; // true;
8250
+
8251
+ BindPigmentTexture(tex, resolution);
8252
+ BindBumpTexture(tex, resolution);
8253
+ }
8254
+
8255
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
80278256 {
80288257 if (// DrawMode() != 0 || /*tex == null ||*/
80298258 ambientOcclusion ) // || !textureon)
....@@ -8034,17 +8263,47 @@
80348263 if (tex == null)
80358264 {
80368265 BindTexture(null,false,resolution);
8037
- BindTexture(null,true,resolution);
80388266 return;
80398267 }
80408268
80418269 String pigment = Object3D.GetPigment(tex);
8270
+
8271
+ usedtextures.add(tex);
8272
+
8273
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8274
+ {
8275
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8276
+ // System.out.println("; bump = " + bump);
8277
+ }
8278
+
8279
+ if (pigment.equals(""))
8280
+ {
8281
+ pigment = null;
8282
+ }
8283
+
8284
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8285
+ BindTexture(tex, false, resolution);
8286
+ }
8287
+
8288
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8289
+ {
8290
+ if (// DrawMode() != 0 || /*tex == null ||*/
8291
+ ambientOcclusion ) // || !textureon)
8292
+ {
8293
+ return; // false;
8294
+ }
8295
+
8296
+ if (tex == null)
8297
+ {
8298
+ BindTexture(null,true,resolution);
8299
+ return;
8300
+ }
8301
+
80428302 String bump = Object3D.GetBump(tex);
80438303
8044
- usedtextures.put(pigment, pigment);
8045
- usedtextures.put(bump, bump);
8304
+ usedtextures.add(tex);
80468305
8047
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8306
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
80488307 {
80498308 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
80508309 // System.out.println("; bump = " + bump);
....@@ -8054,43 +8313,94 @@
80548313 {
80558314 bump = null;
80568315 }
8057
- if (pigment.equals(""))
8058
- {
8059
- pigment = null;
8060
- }
80618316
8062
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8063
- BindTexture(pigment, false, resolution);
80648317 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8065
- BindTexture(bump, true, resolution);
8318
+ BindTexture(tex, true, resolution);
80668319 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8067
-
8068
- return; // true;
80698320 }
80708321
8071
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution)
8322
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8323
+
8324
+ private boolean FileExists(String tex)
80728325 {
8073
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8326
+ if (missingTextures.contains(tex))
8327
+ {
8328
+ return false;
8329
+ }
8330
+
8331
+ boolean fileExists = new File(tex).exists();
8332
+
8333
+ if (!fileExists)
8334
+ {
8335
+ // If file exists, the "new File()" is not executed sgain
8336
+ missingTextures.add(tex);
8337
+ }
8338
+
8339
+ return fileExists;
8340
+ }
8341
+
8342
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
8343
+ {
8344
+ CacheTexture texturecache = null;
80748345
80758346 if (tex != null)
80768347 {
8077
- String texname = tex;
8348
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8349
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
80788350
8079
- String[] split = tex.split("Textures");
8080
- if (split.length > 1)
8081
- texname = "/Users/nbriere/Textures" + split[split.length-1];
8082
- else
8083
- if (!texname.startsWith("/"))
8084
- texname = "/Users/nbriere/Textures/" + texname;
8351
+ if (texname.equals("") && texdata == null)
8352
+ {
8353
+ return null;
8354
+ }
8355
+
8356
+ String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
8357
+
8358
+// String[] split = tex.split("Textures");
8359
+// if (split.length > 1)
8360
+// texname = "/Users/nbriere/Textures" + split[split.length-1];
8361
+// else
8362
+// if (!texname.startsWith("/"))
8363
+// texname = "/Users/nbriere/Textures/" + texname;
8364
+ if (!FileExists(texname) && !texname.startsWith("@"))
8365
+ {
8366
+ texname = fallbackTextureName;
8367
+ }
80858368
80868369 if (CACHETEXTURE)
8087
- texture = textures.get(texname); // TEXTURE CACHE
8088
-
8089
- TextureData texturedata = null;
8090
-
8091
- if (texture == null || texture.resolution < resolution)
80928370 {
8093
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8371
+ if (texdata == null)
8372
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8373
+ else
8374
+ texturecache = bimtextures.get(texdata);
8375
+ }
8376
+
8377
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8378
+ {
8379
+ TextureData texturedata = null;
8380
+
8381
+ if (texdata != null && textureon)
8382
+ {
8383
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8384
+
8385
+ try
8386
+ {
8387
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8388
+ }
8389
+ catch (Exception e)
8390
+ {
8391
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8392
+ }
8393
+
8394
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8395
+ bimtextures.put(texdata, texturecache);
8396
+
8397
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8398
+
8399
+ //Object bim2 = CreateBim(texturecache.texturedata);
8400
+ //bim2 = bim;
8401
+ }
8402
+ else
8403
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
80948404 {
80958405 assert(!bump);
80968406 // if (bump)
....@@ -8101,19 +8411,23 @@
81018411 // }
81028412 // else
81038413 // {
8104
- texture = textures.get(tex);
8105
- if (texture == null)
8414
+ // texturecache = textures.get(texname); // suspicious
8415
+ if (texturecache == null)
81068416 {
8107
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8417
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
81088418 }
8419
+ else
8420
+ new Exception().printStackTrace();
81098421 // }
81108422 } else
8111
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8423
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
81128424 {
81138425 assert(bump);
8114
- texture = textures.get(tex);
8115
- if (texture == null)
8116
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8426
+ // texturecache = textures.get(texname); // suspicious
8427
+ if (texturecache == null)
8428
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8429
+ else
8430
+ new Exception().printStackTrace();
81178431 } else
81188432 {
81198433 //if (tex.equals("IMMORTAL"))
....@@ -8121,11 +8435,22 @@
81218435 // texture = GetResourceTexture("default.png");
81228436 //} else
81238437 //{
8124
- if (tex.equals("WHITE_NOISE"))
8438
+ if (texname.endsWith("WHITE_NOISE"))
81258439 {
8126
- texture = textures.get(tex);
8127
- if (texture == null)
8128
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8440
+ // texturecache = textures.get(texname); // suspicious
8441
+ if (texturecache == null)
8442
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8443
+ else
8444
+ new Exception().printStackTrace();
8445
+ } else
8446
+ {
8447
+ if (texname.startsWith("@"))
8448
+ {
8449
+ // texturecache = textures.get(texname); // suspicious
8450
+ if (texturecache == null)
8451
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8452
+ else
8453
+ new Exception().printStackTrace();
81298454 } else
81308455 {
81318456 if (textureon)
....@@ -8150,7 +8475,7 @@
81508475 }
81518476
81528477 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
8153
- if (!new File(cachename).exists())
8478
+ if (!FileExists(cachename))
81548479 cachename = texname;
81558480 else
81568481 processbump = false; // don't process bump map again
....@@ -8172,7 +8497,7 @@
81728497 }
81738498
81748499 cachename = texname.substring(0, texname.length()-4)+ext+".png";
8175
- if (!new File(cachename).exists())
8500
+ if (!FileExists(cachename))
81768501 cachename = texname;
81778502 else
81788503 processbump = false; // don't process bump map again
....@@ -8181,20 +8506,23 @@
81818506 texturedata = GetFileTexture(cachename, processbump, resolution);
81828507
81838508
8184
- if (texturedata != null)
8185
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8509
+ if (texturedata == null)
8510
+ throw new Exception();
8511
+
8512
+ texturecache = new CacheTexture(texturedata,resolution);
81868513 //texture = GetTexture(tex, bump);
81878514 }
8515
+ }
81888516 }
81898517 //}
81908518 }
81918519
8192
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8520
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
81938521 {
81948522 //return false;
81958523
81968524 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8197
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8525
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
81988526 {
81998527 // String ext = "_highres";
82008528 // if (REDUCETEXTURE)
....@@ -8211,52 +8539,17 @@
82118539 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
82128540 if (!cachefile.exists())
82138541 {
8214
- // cache to disk
8215
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
8216
- //buffers[0].
8217
-
8218
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
8219
- int[] pixels = new int[bytebuf.capacity()/3];
8220
-
8221
- // squared size heuristic...
8222
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8542
+ //if (texturedata.getWidth() == texturedata.getHeight())
82238543 {
8224
- for (int i=pixels.length; --i>=0;)
8225
- {
8226
- int i3 = i*3;
8227
- pixels[i] = 0xFF;
8228
- pixels[i] <<= 8;
8229
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
8230
- pixels[i] <<= 8;
8231
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
8232
- pixels[i] <<= 8;
8233
- pixels[i] |= bytebuf.get(i3) & 0xFF;
8234
- }
8235
-
8236
- /*
8237
- int r=0,g=0,b=0,a=0;
8238
- for (int i=0; i<width; i++)
8239
- for (int j=0; j<height; j++)
8240
- {
8241
- int index = j*width+i;
8242
- int p = pixels[index];
8243
- a = ((p>>24) & 0xFF);
8244
- r = ((p>>16) & 0xFF);
8245
- g = ((p>>8) & 0xFF);
8246
- b = (p & 0xFF);
8247
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
8248
- }
8249
- /**/
8250
- int width = (int)Math.sqrt(pixels.length); // squared
8251
- int height = width;
8252
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
8253
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8544
+ BufferedImage rendImage = CreateBim(texturedata);
8545
+
82548546 ImageWriter writer = null;
82558547 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
82568548 if (iter.hasNext()) {
82578549 writer = (ImageWriter)iter.next();
82588550 }
8259
- float compressionQuality = 0.9f;
8551
+
8552
+ float compressionQuality = 0.85f;
82608553 try
82618554 {
82628555 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8273,18 +8566,20 @@
82738566 }
82748567 }
82758568 }
8276
-
8569
+
8570
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8571
+
82778572 //System.out.println("Texture = " + tex);
8278
- if (textures.containsKey(texname))
8573
+ if (textures.containsKey(tex))
82798574 {
8280
- CacheTexture thetex = textures.get(texname);
8575
+ CacheTexture thetex = textures.get(tex);
82818576 thetex.texture.disable();
82828577 thetex.texture.dispose();
8283
- textures.remove(texname);
8578
+ textures.remove(tex);
82848579 }
82858580
8286
- texture.texturedata = texturedata;
8287
- textures.put(texname, texture);
8581
+ //texture.texturedata = texturedata;
8582
+ textures.put(tex, texturecache);
82888583
82898584 // newtex = true;
82908585 }
....@@ -8300,10 +8595,44 @@
83008595 }
83018596 }
83028597
8303
- return texture;
8598
+ return texturecache;
83048599 }
83058600
8306
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution)
8601
+ static void EmbedTextures(cTexture tex)
8602
+ {
8603
+ if (tex.pigmentdata == null)
8604
+ {
8605
+ //String texname = Object3D.GetPigment(tex);
8606
+
8607
+ CacheTexture texturecache = texturepigment.get(tex);
8608
+
8609
+ if (texturecache != null)
8610
+ {
8611
+ tex.pw = texturecache.texturedata.getWidth();
8612
+ tex.ph = texturecache.texturedata.getHeight();
8613
+ tex.pigmentdata = //CompressJPEG(CreateBim
8614
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8615
+ ;
8616
+ //, tex.pw, tex.ph), 0.5f);
8617
+ }
8618
+ }
8619
+
8620
+ if (tex.bumpdata == null)
8621
+ {
8622
+ //String texname = Object3D.GetBump(tex);
8623
+
8624
+ CacheTexture texturecache = texturebump.get(tex);
8625
+
8626
+ if (texturecache != null)
8627
+ {
8628
+ tex.bw = texturecache.texturedata.getWidth();
8629
+ tex.bh = texturecache.texturedata.getHeight();
8630
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8631
+ }
8632
+ }
8633
+ }
8634
+
8635
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
83078636 {
83088637 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
83098638
....@@ -8321,21 +8650,21 @@
83218650 return texture!=null?texture.texture:null;
83228651 }
83238652
8324
- public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution)
8653
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
83258654 {
83268655 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
83278656
83288657 return texture!=null?texture.texturedata:null;
83298658 }
83308659
8331
- boolean BindTexture(String tex, boolean bump, int resolution)
8660
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
83328661 {
83338662 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
83348663 {
83358664 return false;
83368665 }
83378666
8338
- boolean newtex = false;
8667
+ //boolean newtex = false;
83398668
83408669 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
83418670
....@@ -8367,9 +8696,75 @@
83678696 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
83688697 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
83698698
8370
- return newtex;
8699
+ return true; // Warning: not used.
83718700 }
83728701
8702
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8703
+ {
8704
+ try
8705
+ {
8706
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8707
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8708
+ ImageWriter writer = writers.next();
8709
+
8710
+ ImageWriteParam param = writer.getDefaultWriteParam();
8711
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8712
+ param.setCompressionQuality(quality);
8713
+
8714
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8715
+ writer.setOutput(ios);
8716
+ writer.write(null, new IIOImage(image, null, null), param);
8717
+
8718
+ byte[] data = baos.toByteArray();
8719
+ writer.dispose();
8720
+ return data;
8721
+ }
8722
+ catch (Exception e)
8723
+ {
8724
+ e.printStackTrace();
8725
+ return null;
8726
+ }
8727
+ }
8728
+
8729
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8730
+ {
8731
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8732
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8733
+ ImageReader reader = writers.next();
8734
+
8735
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8736
+
8737
+ ImageReadParam param = reader.getDefaultReadParam();
8738
+ param.setDestination(bim);
8739
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8740
+
8741
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8742
+ reader.setInput(ios);
8743
+ BufferedImage bim2 = reader.read(0, param);
8744
+ reader.dispose();
8745
+
8746
+// WritableRaster raster = bim2.getRaster();
8747
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8748
+// byte[] bytes = data.getData();
8749
+//
8750
+// int[] pixels = new int[bytes.length/3];
8751
+// for (int i=pixels.length; --i>=0;)
8752
+// {
8753
+// int i3 = i*3;
8754
+// pixels[i] = 0xFF;
8755
+// pixels[i] <<= 8;
8756
+// pixels[i] |= bytes[i3+2] & 0xFF;
8757
+// pixels[i] <<= 8;
8758
+// pixels[i] |= bytes[i3+1] & 0xFF;
8759
+// pixels[i] <<= 8;
8760
+// pixels[i] |= bytes[i3] & 0xFF;
8761
+// }
8762
+//
8763
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8764
+
8765
+ return bim;
8766
+ }
8767
+
83738768 ShadowBuffer shadowPBuf;
83748769 AntialiasBuffer antialiasPBuf;
83758770 int MAXSTACK;
....@@ -8386,10 +8781,12 @@
83868781
83878782 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
83888783 MAXSTACK = temp[0];
8389
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8784
+ if (Globals.DEBUG)
8785
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
83908786 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
83918787 MAXSTACK = temp[0];
8392
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8788
+ if (Globals.DEBUG)
8789
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
83938790
83948791 // Use debug pipeline
83958792 //drawable.setGL(new DebugGL(gl)); //
....@@ -8397,7 +8794,8 @@
83978794 gl = drawable.getGL(); //
83988795
83998796 GL gl3 = getGL();
8400
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8797
+ if (Globals.DEBUG)
8798
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
84018799
84028800
84038801 //float pos[] = { 100, 100, 100, 0 };
....@@ -8562,7 +8960,7 @@
85628960
85638961 if (cubemap == null)
85648962 {
8565
- LoadEnvy(5);
8963
+ //LoadEnvy(1);
85668964 }
85678965
85688966 //cubemap.enable();
....@@ -8838,6 +9236,8 @@
88389236
88399237 void LoadEnvy(int which)
88409238 {
9239
+ assert(false);
9240
+
88419241 String name;
88429242 String ext;
88439243
....@@ -8849,37 +9249,58 @@
88499249 cubemap = null;
88509250 return;
88519251 case 1:
8852
- name = "cubemaps/box_";
8853
- ext = "png";
9252
+ name = "cubemaps/rgb/";
9253
+ ext = "jpg";
88549254 reverseUP = false;
88559255 break;
88569256 case 2:
8857
- name = "cubemaps/uffizi_";
8858
- ext = "png";
8859
- break; // reverseUP = true; break;
9257
+ name = "cubemaps/uffizi/";
9258
+ ext = "jpg";
9259
+ reverseUP = false;
9260
+ break;
88609261 case 3:
8861
- name = "cubemaps/CloudyHills_";
8862
- ext = "tga";
9262
+ name = "cubemaps/CloudyHills/";
9263
+ ext = "jpg";
88639264 reverseUP = false;
88649265 break;
88659266 case 4:
8866
- name = "cubemaps/cornell_";
9267
+ name = "cubemaps/cornell/";
88679268 ext = "png";
88689269 reverseUP = false;
88699270 break;
9271
+ case 5:
9272
+ name = "cubemaps/skycube/";
9273
+ ext = "jpg";
9274
+ reverseUP = false;
9275
+ break;
9276
+ case 6:
9277
+ name = "cubemaps/SaintLazarusChurch3/";
9278
+ ext = "jpg";
9279
+ reverseUP = false;
9280
+ break;
9281
+ case 7:
9282
+ name = "cubemaps/Sodermalmsallen/";
9283
+ ext = "jpg";
9284
+ reverseUP = false;
9285
+ break;
9286
+ case 8:
9287
+ name = "cubemaps/Sodermalmsallen2/";
9288
+ ext = "jpg";
9289
+ reverseUP = false;
9290
+ break;
9291
+ case 9:
9292
+ name = "cubemaps/UnionSquare/";
9293
+ ext = "jpg";
9294
+ reverseUP = false;
9295
+ break;
88709296 default:
8871
- name = "cubemaps/rgb_";
8872
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9297
+ name = "cubemaps/box/";
9298
+ ext = "png"; /*mipmap = true;*/
9299
+ reverseUP = false;
88739300 break;
88749301 }
8875
-
8876
- try
8877
- {
8878
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
8879
- } catch (IOException e)
8880
- {
8881
- throw new RuntimeException(e);
8882
- }
9302
+
9303
+ LoadSkybox(name, ext, mipmap);
88839304 }
88849305
88859306 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -8911,8 +9332,12 @@
89119332 static double[] model = new double[16];
89129333 double[] camera2light = new double[16];
89139334 double[] light2camera = new double[16];
8914
- int newenvy = -1;
8915
- boolean envyoff = true; // false;
9335
+
9336
+ //int newenvy = -1;
9337
+ //boolean envyoff = false;
9338
+
9339
+ String loadedskyboxname;
9340
+
89169341 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
89179342 //float[] light0 = { 0,0,0 };
89189343 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9205,11 +9630,35 @@
92059630 jy8[3] = 0.5f;
92069631 }
92079632
9208
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9633
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
92099634 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
92109635 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
92119636 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
92129637
9638
+ void ResetOptions()
9639
+ {
9640
+ options1[0] = 100;
9641
+ options1[1] = 0.025f;
9642
+ options1[2] = 0.01f;
9643
+ options1[3] = 0;
9644
+ options1[4] = 0;
9645
+
9646
+ options2[0] = 0;
9647
+ options2[1] = 0.75f;
9648
+ options2[2] = 0;
9649
+ options2[3] = 0;
9650
+
9651
+ options3[0] = 1;
9652
+ options3[1] = 1;
9653
+ options3[2] = 1;
9654
+ options3[3] = 0;
9655
+
9656
+ options4[0] = 1;
9657
+ options4[1] = 0;
9658
+ options4[2] = 1;
9659
+ options4[3] = 0;
9660
+ }
9661
+
92139662 static int imagecount = 0; // movie generation
92149663
92159664 static int jitter = 0;
....@@ -9305,8 +9754,8 @@
93059754 assert (parentcam != renderCamera);
93069755
93079756 if (renderCamera != lightCamera)
9308
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9309
- LA.matConcat(matrix, parentcam.toParent, matrix);
9757
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9758
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
93109759
93119760 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
93129761
....@@ -9321,8 +9770,8 @@
93219770 LA.matCopy(renderCamera.fromScreen, matrix);
93229771
93239772 if (renderCamera != lightCamera)
9324
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9325
- LA.matConcat(parentcam.fromParent, matrix, matrix);
9773
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9774
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
93269775
93279776 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
93289777
....@@ -9368,10 +9817,12 @@
93689817 rati = 1 / rati;
93699818 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
93709819 }
9371
- assert (newenvy == -1);
9820
+
9821
+ //assert (newenvy == -1);
9822
+
93729823 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
93739824 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9374
- DrawSkyBox(gl);
9825
+ DrawSkyBox(gl, (float)rati);
93759826 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
93769827 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
93779828 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -9394,7 +9845,7 @@
93949845 //gl.glFlush();
93959846 gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE);
93969847
9397
- if (ANIMATION && ABORTED)
9848
+ if (Globals.ANIMATION && ABORTED)
93989849 {
93999850 System.err.println(" ABORTED FRAME");
94009851 break;
....@@ -9424,7 +9875,7 @@
94249875 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
94259876
94269877 // save image
9427
- if (ANIMATION && !ABORTED)
9878
+ if (Globals.ANIMATION && !ABORTED)
94289879 {
94299880 VPwidth = viewport[2];
94309881 VPheight = viewport[3];
....@@ -9535,11 +9986,11 @@
95359986
95369987 // imagecount++;
95379988
9538
- String fullname = filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
9989
+ String fullname = Globals.filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
95399990
95409991 if (!BOXMODE)
95419992 {
9542
- System.out.println("image: " + fullname + " (wav cursor=" + (GrafreeD.wav.cursor / 735 / 4) + ")");
9993
+ System.out.println("image: " + fullname + " (wav cursor=" + (Grafreed.wav.cursor / 735 / 4) + ")");
95439994 }
95449995
95459996 if (!BOXMODE)
....@@ -9577,7 +10028,7 @@
957710028 ABORTED = false;
957810029 }
957910030 else
9580
- GrafreeD.wav.cursor += 735 * ACSIZE;
10031
+ Grafreed.wav.cursor += 735 * ACSIZE;
958110032
958210033 if (false)
958310034 {
....@@ -10240,11 +10691,11 @@
1024010691
1024110692 public void display(GLAutoDrawable drawable)
1024210693 {
10243
- if (GrafreeD.savesound && GrafreeD.hassound)
10694
+ if (Grafreed.savesound && Grafreed.hassound)
1024410695 {
10245
- GrafreeD.wav.save();
10246
- GrafreeD.savesound = false;
10247
- GrafreeD.hassound = false;
10696
+ Grafreed.wav.save();
10697
+ Grafreed.savesound = false;
10698
+ Grafreed.hassound = false;
1024810699 }
1024910700 // if (DEBUG_SELECTION)
1025010701 // {
....@@ -10320,6 +10771,7 @@
1032010771 ANTIALIAS = 0;
1032110772 //System.out.println("RESTART");
1032210773 AAtimer.restart();
10774
+ Globals.TIMERRUNNING = true;
1032310775 }
1032410776 }
1032510777 }
....@@ -10374,7 +10826,7 @@
1037410826 Object3D theobject = object;
1037510827 Object3D theparent = object.parent;
1037610828 object.parent = null;
10377
- object = (Object3D)GrafreeD.clone(object);
10829
+ object = (Object3D)Grafreed.clone(object);
1037810830 object.Stripify();
1037910831 if (theobject.selection == null || theobject.selection.Size() == 0)
1038010832 theobject.PreprocessOcclusion(this);
....@@ -10387,13 +10839,14 @@
1038710839 ambientOcclusion = false;
1038810840 }
1038910841
10390
- if (Globals.lighttouched && DrawMode() == DEFAULT && !lightMode) // && !FROZEN)
10842
+ if (//Globals.lighttouched &&
10843
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1039110844 {
1039210845 //if (RENDERSHADOW) // ?
1039310846 if (!IsFrozen())
1039410847 {
1039510848 // dec 2012
10396
- if (!ambientOcclusion && !(!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0))
10849
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
1039710850 {
1039810851 Globals.framecount++;
1039910852 shadowbuffer.display();
....@@ -10406,7 +10859,7 @@
1040610859
1040710860 if (wait)
1040810861 {
10409
- Sleep(500);
10862
+ Sleep(200); // blocks everything
1041010863
1041110864 wait = false;
1041210865 }
....@@ -10520,8 +10973,8 @@
1052010973
1052110974 // if (parentcam != renderCamera) // not a light
1052210975 if (cam != lightCamera)
10523
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10524
- LA.matConcat(matrix, parentcam.toParent, matrix);
10976
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10977
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1052510978
1052610979 for (int j = 0; j < 4; j++)
1052710980 {
....@@ -10535,8 +10988,8 @@
1053510988
1053610989 // if (parentcam != renderCamera) // not a light
1053710990 if (cam != lightCamera)
10538
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10539
- LA.matConcat(parentcam.fromParent, matrix, matrix);
10991
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10992
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1054010993
1054110994 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1054210995
....@@ -10622,13 +11075,41 @@
1062211075 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1062311076 }
1062411077
10625
- if (newenvy > -1)
11078
+// if (newenvy > -1)
11079
+// {
11080
+// LoadEnvy(newenvy);
11081
+// }
11082
+//
11083
+// newenvy = -1;
11084
+
11085
+ if (object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
1062611086 {
10627
- LoadEnvy(newenvy);
11087
+ if (cubemaprgb == null)
11088
+ {
11089
+ cubemaprgb = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11090
+ }
11091
+
11092
+ cubemap = cubemaprgb;
1062811093 }
10629
-
10630
- newenvy = -1;
10631
-
11094
+ else
11095
+ {
11096
+ if (object.skyboxname != null)
11097
+ {
11098
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11099
+ {
11100
+ cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11101
+ loadedskyboxname = object.skyboxname;
11102
+ }
11103
+ }
11104
+ else
11105
+ {
11106
+ cubemapcustom = null;
11107
+ loadedskyboxname = null;
11108
+ }
11109
+
11110
+ cubemap = cubemapcustom;
11111
+ }
11112
+
1063211113 ratio = ((double) getWidth()) / getHeight();
1063311114 //System.out.println("ratio = " + ratio);
1063411115
....@@ -10644,7 +11125,7 @@
1064411125
1064511126 if (!IsFrozen() && !ambientOcclusion)
1064611127 {
10647
- DrawSkyBox(gl);
11128
+ DrawSkyBox(gl, (float)ratio);
1064811129 }
1064911130
1065011131 //if (selection_view == -1)
....@@ -10795,7 +11276,16 @@
1079511276 // Bump noise
1079611277 gl.glActiveTexture(GL.GL_TEXTURE6);
1079711278 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
10798
- BindTexture(NOISE_TEXTURE, false, 2);
11279
+
11280
+ try
11281
+ {
11282
+ BindTexture(NOISE_TEXTURE, false, 2);
11283
+ }
11284
+ catch (Exception e)
11285
+ {
11286
+ System.err.println("FAILED: " + NOISE_TEXTURE);
11287
+ }
11288
+
1079911289
1080011290 gl.glActiveTexture(GL.GL_TEXTURE0);
1080111291 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -10818,9 +11308,9 @@
1081811308
1081911309 gl.glMatrixMode(GL.GL_MODELVIEW);
1082011310
10821
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10822
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10823
-//gl.glEnable(gl.GL_MULTISAMPLE);
11311
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11312
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11313
+gl.glEnable(gl.GL_MULTISAMPLE);
1082411314 } else
1082511315 {
1082611316 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -10831,7 +11321,7 @@
1083111321 //System.out.println("BLENDING ON");
1083211322 gl.glEnable(GL.GL_BLEND);
1083311323 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
10834
-
11324
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1083511325 gl.glMatrixMode(gl.GL_PROJECTION);
1083611326 gl.glLoadIdentity();
1083711327
....@@ -10920,8 +11410,8 @@
1092011410 System.err.println("parentcam != renderCamera");
1092111411
1092211412 // if (cam != lightCamera)
10923
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10924
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11413
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11414
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1092511415 }
1092611416
1092711417 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -10942,8 +11432,8 @@
1094211432 if (true) // TODO
1094311433 {
1094411434 if (cam != lightCamera)
10945
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10946
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11435
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11436
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
1094711437 }
1094811438
1094911439 LA.xformPos(light0, cam.toScreen, light0);
....@@ -11080,7 +11570,7 @@
1108011570 }
1108111571 }
1108211572
11083
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11573
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1108411574 {
1108511575 //gl.glDepthFunc(GL.GL_LEQUAL);
1108611576 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11088,24 +11578,21 @@
1108811578
1108911579 boolean texon = textureon;
1109011580
11091
- if (RENDERPROGRAM > 0)
11092
- {
11093
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11094
- textureon = false;
11095
- }
11581
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11582
+ textureon = false;
11583
+
1109611584 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1109711585 //System.out.println("ALLO");
1109811586 gl.glColorMask(false, false, false, false);
1109911587 DrawObject(gl);
11100
- if (RENDERPROGRAM > 0)
11101
- {
11102
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11103
- textureon = texon;
11104
- }
11588
+
11589
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11590
+ textureon = texon;
11591
+
1110511592 gl.glColorMask(true, true, true, true);
1110611593
1110711594 gl.glDepthFunc(GL.GL_EQUAL);
11108
- //gl.glDepthMask(false);
11595
+ gl.glDepthMask(false);
1110911596 }
1111011597
1111111598 if (false) // DrawMode() == SHADOW)
....@@ -11259,8 +11746,14 @@
1125911746 {
1126011747 renderpass++;
1126111748 // System.out.println("Draw object... ");
11749
+ STEP = 1;
1126211750 if (FAST) // in case there is no script
11263
- STEP = 16;
11751
+ STEP = 8;
11752
+
11753
+ if (CURRENTANTIALIAS == 0 || ACSIZE == 1)
11754
+ {
11755
+ STEP *= 4;
11756
+ }
1126411757
1126511758 //object.FullInvariants();
1126611759
....@@ -11274,23 +11767,44 @@
1127411767 e.printStackTrace();
1127511768 }
1127611769
11277
- if (GrafreeD.RENDERME > 0)
11278
- GrafreeD.RENDERME--; // mechante magouille
11770
+ if (Grafreed.RENDERME > 0)
11771
+ Grafreed.RENDERME--; // mechante magouille
1127911772
1128011773 Globals.ONESTEP = false;
1128111774 }
1128211775
1128311776 static boolean zoomonce = false;
1128411777
11778
+ static void CreateSelectedPoint()
11779
+ {
11780
+ if (selectedpoint == null)
11781
+ {
11782
+ debugpointG = new Sphere();
11783
+ debugpointP = new Sphere();
11784
+ debugpointC = new Sphere();
11785
+ debugpointR = new Sphere();
11786
+
11787
+ selectedpoint = new Superellipsoid();
11788
+
11789
+ for (int i=0; i<8; i++)
11790
+ {
11791
+ debugpoints[i] = new Sphere();
11792
+ }
11793
+ }
11794
+ }
11795
+
1128511796 void DrawObject(GL gl, boolean draw)
1128611797 {
11798
+ // To clear camera values
11799
+ ResetOptions();
11800
+
1128711801 //System.out.println("DRAW OBJECT " + mouseDown);
1128811802 // DrawMode() = SELECTION;
1128911803 //GL gl = getGL();
1129011804 if ((TRACK || SHADOWTRACK) || zoomonce)
1129111805 {
1129211806 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11293
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11807
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1129411808 pingthread.StepToTarget(true); // true);
1129511809 // zoomonce = false;
1129611810 }
....@@ -11345,7 +11859,14 @@
1134511859
1134611860 usedtextures.clear();
1134711861
11348
- BindTextures(DEFAULT_TEXTURES, 2);
11862
+ try
11863
+ {
11864
+ BindTextures(DEFAULT_TEXTURES, 2);
11865
+ }
11866
+ catch (Exception e)
11867
+ {
11868
+ System.err.println("FAILED: " + DEFAULT_TEXTURES);
11869
+ }
1134911870 }
1135011871 //System.out.println("--> " + stackdepth);
1135111872 // GrafreeD.traceon();
....@@ -11355,8 +11876,9 @@
1135511876
1135611877 if (DrawMode() == DEFAULT)
1135711878 {
11358
- if (DEBUG)
11879
+ if (Globals.DEBUG)
1135911880 {
11881
+ CreateSelectedPoint();
1136011882 float radius = 0.05f;
1136111883 if (selectedpoint.radius != radius)
1136211884 {
....@@ -11410,20 +11932,32 @@
1141011932 ReleaseTextures(DEFAULT_TEXTURES);
1141111933
1141211934 if (CLEANCACHE)
11413
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11935
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1141411936 {
11415
- String tex = e.nextElement();
11937
+ cTexture tex = e.nextElement();
1141611938
1141711939 // System.out.println("Texture --------- " + tex);
1141811940
11419
- if (tex.equals("WHITE_NOISE"))
11941
+ if (tex.equals("WHITE_NOISE:"))
1142011942 continue;
1142111943
11422
- if (!usedtextures.containsKey(tex))
11944
+ if (!usedtextures.contains(tex))
1142311945 {
11946
+ CacheTexture gettex = texturepigment.get(tex);
1142411947 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11425
- textures.get(tex).texture.dispose();
11426
- textures.remove(tex);
11948
+ if (gettex != null)
11949
+ {
11950
+ gettex.texture.dispose();
11951
+ texturepigment.remove(tex);
11952
+ }
11953
+
11954
+ gettex = texturebump.get(tex);
11955
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11956
+ if (gettex != null)
11957
+ {
11958
+ gettex.texture.dispose();
11959
+ texturebump.remove(tex);
11960
+ }
1142711961 }
1142811962 }
1142911963 }
....@@ -11436,7 +11970,14 @@
1143611970 if (checker != null && DrawMode() == DEFAULT)
1143711971 {
1143811972 //BindTexture(IMMORTAL_TEXTURE);
11439
- BindTextures(checker.GetTextures(), checker.texres);
11973
+ try
11974
+ {
11975
+ BindTextures(checker.GetTextures(), checker.texres);
11976
+ }
11977
+ catch (Exception e)
11978
+ {
11979
+ System.err.println("FAILED: " + checker.GetTextures());
11980
+ }
1144011981 // NEAREST
1144111982 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
1144211983 DrawChecker(gl);
....@@ -11518,7 +12059,7 @@
1151812059 return;
1151912060 }
1152012061
11521
- String string = obj.GetToolTip();
12062
+ String string = obj.toString(); //.GetToolTip();
1152212063
1152312064 GL gl = GetGL();
1152412065
....@@ -11835,8 +12376,8 @@
1183512376 //obj.TransformToWorld(light, light);
1183612377 for (int i = tp.size(); --i >= 0;)
1183712378 {
11838
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
11839
- LA.xformPos(light, tp.get(i).toParent, light);
12379
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12380
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1184012381 }
1184112382
1184212383
....@@ -11853,8 +12394,8 @@
1185312394 parentcam = cameras[0];
1185412395 }
1185512396
11856
- for (int count = parentcam.GetTransformCount(); --count>=0;)
11857
- LA.xformPos(light, parentcam.toParent, light); // may 2013
12397
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
12398
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1185812399
1185912400 LA.xformPos(light, renderCamera.toScreen, light);
1186012401
....@@ -11944,8 +12485,76 @@
1194412485
1194512486 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1194612487
11947
- String program =
12488
+ String programmin =
12489
+ // Min shader
1194812490 "!!ARBfp1.0\n" +
12491
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12492
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12493
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12494
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12495
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12496
+ "PARAM light2cam0 = program.env[10];" +
12497
+ "PARAM light2cam1 = program.env[11];" +
12498
+ "PARAM light2cam2 = program.env[12];" +
12499
+ "TEMP temp;" +
12500
+ "TEMP light;" +
12501
+ "TEMP ndotl;" +
12502
+ "TEMP normal;" +
12503
+ "TEMP depth;" +
12504
+ "TEMP eye;" +
12505
+ "TEMP pos;" +
12506
+
12507
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12508
+ Normalize("normal") +
12509
+ "MOV light, state.light[0].position;" +
12510
+ "DP3 ndotl.x, light, normal;" +
12511
+
12512
+ // shadow
12513
+ "MOV pos, fragment.texcoord[1];" +
12514
+ "MOV temp, pos;" +
12515
+ ShadowTextureFetch("depth", "temp", "1") +
12516
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12517
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12518
+
12519
+ // No shadow when out of frustum
12520
+ //"SGE temp.y, depth.z, zero123.y;" +
12521
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12522
+
12523
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12524
+
12525
+ // Backlit
12526
+ "MOV pos.w, zero123.y;" +
12527
+ "DP4 eye.x, pos, light2cam0;" +
12528
+ "DP4 eye.y, pos, light2cam1;" +
12529
+ "DP4 eye.z, pos, light2cam2;" +
12530
+ Normalize("eye") +
12531
+
12532
+ "DP3 ndotl.y, -eye, normal;" +
12533
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12534
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12535
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12536
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12537
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12538
+
12539
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12540
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12541
+
12542
+ // Pigment
12543
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12544
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12545
+ "MUL temp, temp, ndotl.x;" +
12546
+
12547
+ "MUL temp, temp, zero123.z;" +
12548
+
12549
+ //"MUL temp, temp, ndotl.y;" +
12550
+
12551
+ "MOV temp.w, zero123.y;" + // reset alpha
12552
+ "MOV result.color, temp;" +
12553
+ "END";
12554
+
12555
+ String programmax =
12556
+ "!!ARBfp1.0\n" +
12557
+
1194912558 //"OPTION ARB_fragment_program_shadow;" +
1195012559 "PARAM light2cam0 = program.env[10];" +
1195112560 "PARAM light2cam1 = program.env[11];" +
....@@ -12060,8 +12669,7 @@
1206012669 "TEMP shininess;" +
1206112670 "\n" +
1206212671 "MOV texSamp, one;" +
12063
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12064
-
12672
+
1206512673 "MOV mapgrid.x, one2048th.x;" +
1206612674 "MOV temp, fragment.texcoord[1];" +
1206712675 /*
....@@ -12082,20 +12690,20 @@
1208212690 "MUL temp, floor, mapgrid.x;" +
1208312691 //"TEX depth0, temp, texture[1], 2D;" +
1208412692 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12085
- TextureFetch("depth0", "temp", "1") +
12693
+ ShadowTextureFetch("depth0", "temp", "1") +
1208612694 "") +
1208712695 "ADD temp.x, temp.x, mapgrid.x;" +
1208812696 //"TEX depth1, temp, texture[1], 2D;" +
1208912697 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12090
- TextureFetch("depth1", "temp", "1") +
12698
+ ShadowTextureFetch("depth1", "temp", "1") +
1209112699 "") +
1209212700 "ADD temp.y, temp.y, mapgrid.x;" +
1209312701 //"TEX depth2, temp, texture[1], 2D;" +
12094
- TextureFetch("depth2", "temp", "1") +
12702
+ ShadowTextureFetch("depth2", "temp", "1") +
1209512703 "SUB temp.x, temp.x, mapgrid.x;" +
1209612704 //"TEX depth3, temp, texture[1], 2D;" +
1209712705 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12098
- TextureFetch("depth3", "temp", "1") +
12706
+ ShadowTextureFetch("depth3", "temp", "1") +
1209912707 "") +
1210012708 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1210112709 //"MOV params, material;" +
....@@ -12466,10 +13074,10 @@
1246613074 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1246713075 "") +
1246813076
12469
- // display shadow only (bump == 0)
13077
+ // display shadow only (fakedepth == 0)
1247013078 "SUB temp.x, half.x, shadow.x;" +
12471
- "MOV temp.y, -params6.x;" +
12472
- "SLT temp.z, temp.y, zero.x;" +
13079
+ "MOV temp.y, -params5.z;" + // params6.x;" +
13080
+ "SLT temp.z, temp.y, -c256i.x;" +
1247313081 "SUB temp.y, one.x, temp.z;" +
1247413082 "MUL temp.x, temp.x, temp.y;" +
1247513083 "KIL temp.x;" +
....@@ -12598,8 +13206,10 @@
1259813206 "MAX ndotl.x, ndotl.x, -ndotl.x;" +
1259913207
1260013208 "SUB temp.x, one.x, ndotl.x;" +
12601
- "ADD temp.x, temp.x, options2.z;" + // lightsheen
12602
- "ADD temp.y, one.y, options2.y;" + // sursurface
13209
+ // Tuning for default skin
13210
+ //"ADD temp.x, temp.x, options2.z;" + // lightsheen
13211
+ "MAD temp.x, options2.z, half.y, temp.x;" + // lightsheen
13212
+ "ADD temp.y, one.y, options2.y;" + // subsurface
1260313213 "MUL temp.x, temp.x, temp.y;" +
1260413214
1260513215 "MUL saturation, saturation, temp.xxxx;" +
....@@ -12747,7 +13357,7 @@
1274713357 "MUL final.y, fragment.texcoord[0].x, c256;" +
1274813358 "FLR final.x, final.y;" +
1274913359 "SUB final.y, final.y, final.x;" +
12750
- //"MUL final.x, final.x, c256i;" +
13360
+ "MUL final.x, final.x, c256i;" +
1275113361 "MOV final.z, zero.x;" +
1275213362 "MOV final.a, one.w;":""
1275313363 ) +
....@@ -12755,7 +13365,7 @@
1275513365 "MUL final.y, fragment.texcoord[0].y, c256;" +
1275613366 "FLR final.x, final.y;" +
1275713367 "SUB final.y, final.y, final.x;" +
12758
- //"MUL final.x, final.x, c256i;" +
13368
+ "MUL final.x, final.x, c256i;" +
1275913369 "MOV final.z, zero.x;" +
1276013370 "MOV final.a, one.w;":""
1276113371 ) +
....@@ -12798,7 +13408,14 @@
1279813408 //once = true;
1279913409 }
1280013410
12801
- System.out.print("Program #" + mode + "; length = " + program.length());
13411
+ String program = programmax;
13412
+
13413
+ if (Globals.MINSHADER)
13414
+ {
13415
+ program = programmin;
13416
+ }
13417
+
13418
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1280213419 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1280313420 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1280413421
....@@ -12891,25 +13508,26 @@
1289113508 return out;
1289213509 }
1289313510
12894
- String TextureFetch(String dest, String src, String unit)
13511
+ // Also does frustum culling
13512
+ String ShadowTextureFetch(String dest, String src, String unit)
1289513513 {
1289613514 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1289713515 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1289813516 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13517
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13518
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1289913519 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12900
- "SLT " + src + ".z, " + src + ".x, one.x;" +
12901
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12902
- "SLT " + src + ".z, " + src + ".y, one.x;" +
12903
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13520
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13521
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1290413522 //"SWZ buffer, temp, w,w,w,w;";
12905
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13523
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1290613524 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1290713525 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1290813526 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
12909
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13527
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1291013528
12911
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
12912
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13529
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13530
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1291313531 }
1291413532
1291513533 String Shadow(String depth, String shadow)
....@@ -12931,12 +13549,16 @@
1293113549
1293213550 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1293313551 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13552
+
13553
+ // Compare fragment depth in light space with shadowmap.
1293413554 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1293513555 "SGE temp.y, temp.x, zero.x;" +
12936
- "SUB " + shadow + ".y, one.x, temp.y;" +
13556
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13557
+
13558
+ // Reverse comparison
1293713559 "SUB temp.x, one.x, temp.x;" +
1293813560 "MUL " + shadow + ".x, temp.x, temp.y;" +
12939
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13561
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1294013562 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1294113563
1294213564 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -12950,6 +13572,10 @@
1295013572 // No shadow for backface
1295113573 "DP3 temp.x, normal, lightd;" +
1295213574 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13575
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13576
+
13577
+ // No shadow when out of frustum
13578
+ "SGE temp.x, " + depth + ".z, one.z;" +
1295313579 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1295413580 "";
1295513581 }
....@@ -13096,7 +13722,8 @@
1309613722 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1309713723 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1309813724 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13099
- Object3D.cVector2[] vector2buffer;
13725
+
13726
+ //Object3D.cVector2[] vector2buffer;
1310013727
1310113728 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1310213729 // OUT : diff, spec
....@@ -13112,9 +13739,10 @@
1311213739 "DP3 " + dest + ".z," + "normals," + "eye;" +
1311313740 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1311413741 //"MOV " + dest + ".w," + "normal.z;" +
13115
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
13116
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13117
- //"MOV " + dest + ".z," + "params2.w;" +
13742
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13743
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13744
+
13745
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1311813746 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1311913747 "RCP " + dest + ".w," + dest + ".w;" +
1312013748 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13508,7 +14136,7 @@
1350814136 public void mousePressed(MouseEvent e)
1350914137 {
1351014138 //System.out.println("mousePressed: " + e);
13511
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14139
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1351214140 }
1351314141
1351414142 static long prevtime = 0;
....@@ -13584,8 +14212,8 @@
1358414212 // mode |= META;
1358514213 //}
1358614214
13587
- SetMouseMode(WHEEL | e.getModifiersEx());
13588
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14215
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14216
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1358914217 anchorX = ax;
1359014218 anchorY = ay;
1359114219 prevX = px;
....@@ -13619,6 +14247,7 @@
1361914247 else
1362014248 if (evt.getSource() == AAtimer)
1362114249 {
14250
+ Globals.TIMERRUNNING = false;
1362214251 if (mouseDown)
1362314252 {
1362414253 //new Exception().printStackTrace();
....@@ -13644,6 +14273,10 @@
1364414273 // LIVE = waslive;
1364514274 // wasliveok = true;
1364614275 // waslive = false;
14276
+
14277
+ // May 2019 Forget it:
14278
+ if (true)
14279
+ return;
1364714280
1364814281 // source == timer
1364914282 if (mouseDown)
....@@ -13674,7 +14307,7 @@
1367414307
1367514308 // fev 2014???
1367614309 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13677
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14310
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1367814311 pingthread.StepToTarget(true); // true);
1367914312 }
1368014313 // if (!LIVE)
....@@ -13683,12 +14316,13 @@
1368314316
1368414317 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1368514318
13686
- void clickStart(int x, int y, int modifiers)
14319
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1368714320 {
1368814321 if (!wasliveok)
1368914322 return;
1369014323
1369114324 AAtimer.restart(); //
14325
+ Globals.TIMERRUNNING = true;
1369214326
1369314327 // waslive = LIVE;
1369414328 // LIVE = false;
....@@ -13700,7 +14334,7 @@
1370014334 // touched = true; // main DL
1370114335 if (isRenderer)
1370214336 {
13703
- SetMouseMode(modifiers);
14337
+ SetMouseMode(modifiers, modifiersex);
1370414338 }
1370514339
1370614340 selectX = anchorX = x;
....@@ -13713,7 +14347,7 @@
1371314347 clicked = true;
1371414348 hold = false;
1371514349
13716
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14350
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1371714351 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1371814352 {
1371914353 // System.out.println("RESTART II " + modifiers);
....@@ -13738,14 +14372,15 @@
1373814372 drag = false;
1373914373 //System.out.println("Mouse DOWN");
1374014374 editObj = false;
13741
- ClickInfo info = new ClickInfo();
13742
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
13743
- info.pane = this;
13744
- info.camera = renderCamera;
13745
- info.x = x;
13746
- info.y = y;
13747
- info.modifiers = modifiers;
13748
- editObj = object.doEditClick(info, 0);
14375
+ //ClickInfo info = new ClickInfo();
14376
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14377
+ object.clickInfo.pane = this;
14378
+ object.clickInfo.camera = renderCamera;
14379
+ object.clickInfo.x = x;
14380
+ object.clickInfo.y = y;
14381
+ object.clickInfo.modifiers = modifiersex;
14382
+ editObj = object.doEditClick(//info,
14383
+ 0);
1374914384 if (!editObj)
1375014385 {
1375114386 hasMarquee = true;
....@@ -13761,9 +14396,12 @@
1376114396
1376214397 public void mouseDragged(MouseEvent e)
1376314398 {
14399
+ Globals.MOUSEDRAGGED = true;
14400
+
1376414401 //System.out.println("mouseDragged: " + e);
1376514402 if (isRenderer)
1376614403 movingcamera = true;
14404
+
1376714405 //if (drawing)
1376814406 //return;
1376914407 if ((e.getModifiersEx() & CTRL) != 0
....@@ -13773,7 +14411,7 @@
1377314411 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1377414412 }
1377514413 else
13776
- drag(e.getX(), e.getY(), e.getModifiersEx());
14414
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1377714415
1377814416 //try { Thread.sleep(1); } catch (Exception ex) {}
1377914417 }
....@@ -13946,6 +14584,7 @@
1394614584
1394714585 public void run()
1394814586 {
14587
+ new Exception().printStackTrace();
1394914588 System.exit(0);
1395014589 for (;;)
1395114590 {
....@@ -14009,7 +14648,7 @@
1400914648 {
1401014649 Globals.lighttouched = true;
1401114650 }
14012
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14651
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1401314652 }
1401414653 //else
1401514654 }
....@@ -14023,12 +14662,12 @@
1402314662 void GoDown(int mod)
1402414663 {
1402514664 MODIFIERS |= COMMAND;
14026
- /*
14665
+ /**/
1402714666 if((mod&SHIFT) == SHIFT)
14028
- manipCamera.RotatePosition(0, -speed);
14667
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
1402914668 else
14030
- manipCamera.BackForth(0, -speed*delta, getWidth());
14031
- */
14669
+ manipCamera.RotatePosition(0, -speed);
14670
+ /**/
1403214671 if ((mod & SHIFT) == SHIFT)
1403314672 {
1403414673 mouseMode = mouseMode; // VR??
....@@ -14044,12 +14683,12 @@
1404414683 void GoUp(int mod)
1404514684 {
1404614685 MODIFIERS |= COMMAND;
14047
- /*
14686
+ /**/
1404814687 if((mod&SHIFT) == SHIFT)
14049
- manipCamera.RotatePosition(0, speed);
14688
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
1405014689 else
14051
- manipCamera.BackForth(0, speed*delta, getWidth());
14052
- */
14690
+ manipCamera.RotatePosition(0, speed);
14691
+ /**/
1405314692 if ((mod & SHIFT) == SHIFT)
1405414693 {
1405514694 mouseMode = mouseMode;
....@@ -14065,12 +14704,12 @@
1406514704 void GoLeft(int mod)
1406614705 {
1406714706 MODIFIERS |= COMMAND;
14068
- /*
14707
+ /**/
1406914708 if((mod&SHIFT) == SHIFT)
14070
- manipCamera.RotatePosition(speed, 0);
14071
- else
1407214709 manipCamera.Translate(speed*delta, 0, getWidth());
14073
- */
14710
+ else
14711
+ manipCamera.RotatePosition(speed, 0);
14712
+ /**/
1407414713 if ((mod & SHIFT) == SHIFT)
1407514714 {
1407614715 mouseMode = mouseMode;
....@@ -14086,12 +14725,12 @@
1408614725 void GoRight(int mod)
1408714726 {
1408814727 MODIFIERS |= COMMAND;
14089
- /*
14728
+ /**/
1409014729 if((mod&SHIFT) == SHIFT)
14091
- manipCamera.RotatePosition(-speed, 0);
14092
- else
1409314730 manipCamera.Translate(-speed*delta, 0, getWidth());
14094
- */
14731
+ else
14732
+ manipCamera.RotatePosition(-speed, 0);
14733
+ /**/
1409514734 if ((mod & SHIFT) == SHIFT)
1409614735 {
1409714736 mouseMode = mouseMode;
....@@ -14109,7 +14748,7 @@
1410914748 int X, Y;
1411014749 boolean SX, SY;
1411114750
14112
- void drag(int x, int y, int modifiers)
14751
+ void drag(int x, int y, int modifiers, int modifiersex)
1411314752 {
1411414753 if (IsFrozen())
1411514754 {
....@@ -14118,17 +14757,17 @@
1411814757
1411914758 drag = true; // NEW
1412014759
14121
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14760
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1412214761
1412314762 X = x;
1412414763 Y = y;
1412514764 // floating state for animation
14126
- MODIFIERS = modifiers;
14127
- modifiers &= ~1024;
14765
+ MODIFIERS = modifiersex;
14766
+ modifiersex &= ~1024;
1412814767 if (false) // modifiers != 0)
1412914768 {
1413014769 //new Exception().printStackTrace();
14131
- System.out.println("mouseDragged: " + modifiers);
14770
+ System.out.println("mouseDragged: " + modifiersex);
1413214771 System.out.println("SHIFT = " + SHIFT);
1413314772 System.out.println("CONTROL = " + COMMAND);
1413414773 System.out.println("META = " + META);
....@@ -14141,14 +14780,16 @@
1414114780 if (editObj)
1414214781 {
1414314782 drag = true;
14144
- ClickInfo info = new ClickInfo();
14145
- info.bounds.setBounds(0, 0,
14783
+ //ClickInfo info = new ClickInfo();
14784
+ object.clickInfo.bounds.setBounds(0, 0,
1414614785 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14147
- info.pane = this;
14148
- info.camera = renderCamera;
14149
- info.x = x;
14150
- info.y = y;
14151
- object.editWindow.copy.doEditDrag(info);
14786
+ object.clickInfo.pane = this;
14787
+ object.clickInfo.camera = renderCamera;
14788
+ object.clickInfo.x = x;
14789
+ object.clickInfo.y = y;
14790
+ object //.GetWindow().copy
14791
+ .doEditDrag(//info,
14792
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1415214793 } else
1415314794 {
1415414795 if (x < startX)
....@@ -14297,22 +14938,27 @@
1429714938 }
1429814939 }
1429914940
14941
+// ClickInfo clickInfo = new ClickInfo();
14942
+
1430014943 public void mouseMoved(MouseEvent e)
1430114944 {
1430214945 //System.out.println("mouseMoved: " + e);
1430314946 if (isRenderer)
1430414947 return;
1430514948
14306
- ClickInfo ci = new ClickInfo();
14307
- ci.x = e.getX();
14308
- ci.y = e.getY();
14309
- ci.modifiers = e.getModifiersEx();
14310
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14311
- ci.pane = this;
14312
- ci.camera = renderCamera;
14949
+ // Mouse cursor feedback
14950
+ object.clickInfo.x = e.getX();
14951
+ object.clickInfo.y = e.getY();
14952
+ object.clickInfo.modifiers = e.getModifiersEx();
14953
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14954
+ object.clickInfo.pane = this;
14955
+ object.clickInfo.camera = renderCamera;
1431314956 if (!isRenderer)
1431414957 {
14315
- if (object.editWindow.copy.doEditClick(ci, 0))
14958
+ //ObjEditor editWindow = object.editWindow;
14959
+ //Object3D copy = editWindow.copy;
14960
+ if (object.doEditClick(//clickInfo,
14961
+ 0))
1431614962 {
1431714963 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1431814964 } else
....@@ -14324,7 +14970,11 @@
1432414970
1432514971 public void mouseReleased(MouseEvent e)
1432614972 {
14973
+ Globals.MOUSEDRAGGED = false;
14974
+
1432714975 movingcamera = false;
14976
+ X = 0; // getBounds().width/2;
14977
+ Y = 0; // getBounds().height/2;
1432814978 //System.out.println("mouseReleased: " + e);
1432914979 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1433014980 }
....@@ -14347,9 +14997,9 @@
1434714997 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1434814998 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1434914999
14350
- if (control || command || IsFrozen())
15000
+// No delay if (control || command || IsFrozen())
1435115001 timeout = true;
14352
- else
15002
+// ?? May 2019 else
1435315003 // timer.setDelay((modifiers & 128) != 0?0:350);
1435415004 mouseDown = false;
1435515005 if (!control && !command) // june 2013
....@@ -14459,7 +15109,7 @@
1445915109 System.out.println("keyReleased: " + e);
1446015110 }
1446115111
14462
- void SetMouseMode(int modifiers)
15112
+ void SetMouseMode(int modifiers, int modifiersex)
1446315113 {
1446415114 //System.out.println("SetMouseMode = " + modifiers);
1446515115 //modifiers &= ~1024;
....@@ -14471,25 +15121,25 @@
1447115121 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1447215122 // return;
1447315123 //System.out.println("SetMode = " + modifiers);
14474
- if ((modifiers & WHEEL) == WHEEL)
15124
+ if ((modifiersex & WHEEL) == WHEEL)
1447515125 {
1447615126 mouseMode |= ZOOM;
1447715127 }
1447815128
1447915129 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
14480
- if (capsLocked || (modifiers & META) == META)
15130
+ if (capsLocked) // || (modifiers & META) == META)
1448115131 {
1448215132 mouseMode |= VR; // BACKFORTH;
1448315133 }
14484
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
15134
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1448515135 {
1448615136 mouseMode |= SELECT;
1448715137 }
14488
- if ((modifiers & COMMAND) == COMMAND)
15138
+ if ((modifiersex & COMMAND) == COMMAND)
1448915139 {
1449015140 mouseMode |= SELECT;
1449115141 }
14492
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15142
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
1449315143 {
1449415144 mouseMode &= ~VR;
1449515145 mouseMode |= TRANSLATE;
....@@ -14518,7 +15168,7 @@
1451815168
1451915169 if (isRenderer) //
1452015170 {
14521
- SetMouseMode(modifiers);
15171
+ SetMouseMode(0, modifiers);
1452215172 }
1452315173
1452415174 Globals.theRenderer.keyPressed(key);
....@@ -14580,7 +15230,8 @@
1458015230 // break;
1458115231 case 'T':
1458215232 CACHETEXTURE ^= true;
14583
- textures.clear();
15233
+ texturepigment.clear();
15234
+ texturebump.clear();
1458415235 // repaint();
1458515236 break;
1458615237 case 'Y':
....@@ -14665,7 +15316,9 @@
1466515316 case 'E' : COMPACT ^= true;
1466615317 repaint();
1466715318 break;
14668
- case 'W' : DEBUGHSB ^= true;
15319
+ case 'W' : // Wide Window (fullscreen)
15320
+ //DEBUGHSB ^= true;
15321
+ ObjEditor.theFrame.ToggleFullScreen();
1466915322 repaint();
1467015323 break;
1467115324 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14690,8 +15343,8 @@
1469015343 RevertCamera();
1469115344 repaint();
1469215345 break;
14693
- case 'L':
1469415346 case 'l':
15347
+ //case 'L':
1469515348 if (lightMode)
1469615349 {
1469715350 lightMode = false;
....@@ -14755,20 +15408,24 @@
1475515408 OCCLUSION_CULLING ^= true;
1475615409 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1475715410 break;
14758
- case '0': envyoff ^= true; repaint(); break;
15411
+ //case '0': envyoff ^= true; repaint(); break;
1475915412 case '1':
1476015413 case '2':
1476115414 case '3':
1476215415 case '4':
1476315416 case '5':
14764
- newenvy = Character.getNumericValue(key);
14765
- repaint();
14766
- break;
1476715417 case '6':
1476815418 case '7':
1476915419 case '8':
1477015420 case '9':
14771
- BGcolor = (key - '6')/3.f;
15421
+ if (true) // envyoff)
15422
+ {
15423
+ BGcolor = (key - '1')/8.f;
15424
+ }
15425
+ else
15426
+ {
15427
+ //newenvy = Character.getNumericValue(key);
15428
+ }
1477215429 repaint();
1477315430 break;
1477415431 case '!':
....@@ -14834,9 +15491,9 @@
1483415491 case '_':
1483515492 kompactbit = 5;
1483615493 break;
14837
- case '+':
14838
- kompactbit = 6;
14839
- break;
15494
+// case '+':
15495
+// kompactbit = 6;
15496
+// break;
1484015497 case ' ':
1484115498 lightMode ^= true;
1484215499 Globals.lighttouched = true;
....@@ -14848,13 +15505,14 @@
1484815505 case ESC:
1484915506 RENDERPROGRAM += 1;
1485015507 RENDERPROGRAM %= 3;
15508
+
1485115509 repaint();
1485215510 break;
1485315511 case 'Z':
1485415512 //RESIZETEXTURE ^= true;
1485515513 //break;
1485615514 case 'z':
14857
- RENDERSHADOW ^= true;
15515
+ Globals.RENDERSHADOW ^= true;
1485815516 Globals.lighttouched = true;
1485915517 repaint();
1486015518 break;
....@@ -14887,8 +15545,9 @@
1488715545 case DELETE:
1488815546 ClearSelection();
1488915547 break;
14890
- /*
1489115548 case '+':
15549
+
15550
+ /*
1489215551 //fontsize += 1;
1489315552 bbzoom *= 2;
1489415553 repaint();
....@@ -14905,17 +15564,17 @@
1490515564 case '=':
1490615565 IncDepth();
1490715566 //fontsize += 1;
14908
- object.editWindow.refreshContents(true);
15567
+ object.GetWindow().refreshContents(true);
1490915568 maskbit = 6;
1491015569 break;
1491115570 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1491215571 DecDepth();
1491315572 maskbit = 5;
1491415573 //if(fontsize > 1) fontsize -= 1;
14915
- if (object.editWindow == null)
14916
- new Exception().printStackTrace();
14917
- else
14918
- object.editWindow.refreshContents(true);
15574
+// if (object.editWindow == null)
15575
+// new Exception().printStackTrace();
15576
+// else
15577
+ object.GetWindow().refreshContents(true);
1491915578 break;
1492015579 case '{':
1492115580 manipCamera.shaper_fovy /= 1.1;
....@@ -14978,7 +15637,7 @@
1497815637 //mode = ROTATE;
1497915638 if ((MODIFIERS & COMMAND) == 0) // VR??
1498015639 {
14981
- SetMouseMode(modifiers);
15640
+ SetMouseMode(0, modifiers);
1498215641 }
1498315642 }
1498415643
....@@ -15114,7 +15773,7 @@
1511415773 {
1511515774 //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
1511615775 //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15117
- if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (mouseMode & SELECT) == 0)
15776
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1511815777 {
1511915778 mouseMoved(e);
1512015779 } else
....@@ -15139,11 +15798,12 @@
1513915798 }
1514015799 */
1514115800
15142
- object.editWindow.EditSelection();
15801
+ object.GetWindow().EditSelection(false);
1514315802 }
1514415803
1514515804 void SelectParent()
1514615805 {
15806
+ new Exception().printStackTrace();
1514715807 System.exit(0);
1514815808 Composite group = (Composite) object;
1514915809 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -15155,10 +15815,10 @@
1515515815 {
1515615816 //selectees.remove(i);
1515715817 System.out.println("select parent of " + elem);
15158
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15818
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1515915819 } else
1516015820 {
15161
- group.editWindow.Select(elem.GetTreePath(), first, true);
15821
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1516215822 }
1516315823
1516415824 first = false;
....@@ -15167,6 +15827,7 @@
1516715827
1516815828 void SelectChildren()
1516915829 {
15830
+ new Exception().printStackTrace();
1517015831 System.exit(0);
1517115832 /*
1517215833 Composite group = (Composite) object;
....@@ -15199,12 +15860,12 @@
1519915860 for (int j = 0; j < group.children.size(); j++)
1520015861 {
1520115862 elem = (Object3D) group.children.elementAt(j);
15202
- object.editWindow.Select(elem.GetTreePath(), first, true);
15863
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1520315864 first = false;
1520415865 }
1520515866 } else
1520615867 {
15207
- object.editWindow.Select(elem.GetTreePath(), first, true);
15868
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1520815869 }
1520915870
1521015871 first = false;
....@@ -15215,21 +15876,21 @@
1521515876 {
1521615877 //Composite group = (Composite) object;
1521715878 Object3D group = object;
15218
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15879
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1521915880 }
1522015881
1522115882 void ResetTransform(int mask)
1522215883 {
1522315884 //Composite group = (Composite) object;
1522415885 Object3D group = object;
15225
- group.editWindow.ResetTransform(mask);
15886
+ group.GetWindow().ResetTransform(mask);
1522615887 }
1522715888
1522815889 void FlipTransform()
1522915890 {
1523015891 //Composite group = (Composite) object;
1523115892 Object3D group = object;
15232
- group.editWindow.FlipTransform();
15893
+ group.GetWindow().FlipTransform();
1523315894 // group.editWindow.ReduceMesh(true);
1523415895 }
1523515896
....@@ -15237,7 +15898,7 @@
1523715898 {
1523815899 //Composite group = (Composite) object;
1523915900 Object3D group = object;
15240
- group.editWindow.PrintMemory();
15901
+ group.GetWindow().PrintMemory();
1524115902 // group.editWindow.ReduceMesh(true);
1524215903 }
1524315904
....@@ -15245,7 +15906,7 @@
1524515906 {
1524615907 //Composite group = (Composite) object;
1524715908 Object3D group = object;
15248
- group.editWindow.ResetCentroid();
15909
+ group.GetWindow().ResetCentroid();
1524915910 }
1525015911
1525115912 void IncDepth()
....@@ -15327,11 +15988,11 @@
1532715988
1532815989 int width = getBounds().width;
1532915990 int height = getBounds().height;
15330
- ClickInfo info = new ClickInfo();
15331
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1533215991 //Image img = CreateImage(width, height);
1533315992 //System.out.println("width = " + width + "; height = " + height + "\n");
15993
+
1533415994 Graphics gr = g; // img.getGraphics();
15995
+
1533515996 if (!hasMarquee)
1533615997 {
1533715998 if (Xmin < Xmax) // !locked)
....@@ -15403,40 +16064,88 @@
1540316064 }
1540416065 if (object != null && !hasMarquee)
1540516066 {
16067
+ if (object.clickInfo == null)
16068
+ object.clickInfo = new ClickInfo();
16069
+ ClickInfo info = object.clickInfo;
16070
+ //ClickInfo info = new ClickInfo();
16071
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16072
+
1540616073 if (isRenderer)
1540716074 {
15408
- info.flags++;
16075
+ object.clickInfo.flags++;
1540916076 double frameAspect = (double) width / (double) height;
1541016077 if (frameAspect > renderCamera.aspect)
1541116078 {
1541216079 int desired = (int) ((double) height * renderCamera.aspect);
15413
- info.bounds.width -= width - desired;
15414
- info.bounds.x += (width - desired) / 2;
16080
+ object.clickInfo.bounds.width -= width - desired;
16081
+ object.clickInfo.bounds.x += (width - desired) / 2;
1541516082 } else
1541616083 {
1541716084 int desired = (int) ((double) width / renderCamera.aspect);
15418
- info.bounds.height -= height - desired;
15419
- info.bounds.y += (height - desired) / 2;
16085
+ object.clickInfo.bounds.height -= height - desired;
16086
+ object.clickInfo.bounds.y += (height - desired) / 2;
1542016087 }
1542116088 }
15422
- info.g = gr;
15423
- info.camera = renderCamera;
16089
+
16090
+ object.clickInfo.g = gr;
16091
+ object.clickInfo.camera = renderCamera;
1542416092 /*
1542516093 // Memory intensive (brep.verticescopy)
1542616094 if (!(object instanceof Composite))
1542716095 object.draw(info, 0, false); // SLOW :
1542816096 */
15429
- if (!isRenderer)
16097
+ if (!isRenderer) // && drag)
1543016098 {
15431
- object.drawEditHandles(info, 0);
16099
+ Grafreed.Assert(object != null);
16100
+ Grafreed.Assert(object.selection != null);
16101
+ if (object.selection.Size() > 0)
16102
+ {
16103
+ int hitSomething = object.selection.get(0).hitSomething;
16104
+
16105
+ object.clickInfo.DX = 0;
16106
+ object.clickInfo.DY = 0;
16107
+ object.clickInfo.W = 1;
16108
+ if (hitSomething == Object3D.hitCenter)
16109
+ {
16110
+ info.DX = X;
16111
+ if (X != 0)
16112
+ info.DX -= info.bounds.width/2;
16113
+
16114
+ info.DY = Y;
16115
+ if (Y != 0)
16116
+ info.DY -= info.bounds.height/2;
16117
+ }
16118
+
16119
+ object.drawEditHandles(//info,
16120
+ 0);
16121
+
16122
+ if (drag && (X != 0 || Y != 0))
16123
+ {
16124
+ switch (hitSomething)
16125
+ {
16126
+ case Object3D.hitCenter: gr.setColor(Color.pink);
16127
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16128
+ break;
16129
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16130
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16131
+ break;
16132
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16133
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16134
+ break;
16135
+ }
16136
+
16137
+ }
16138
+ }
1543216139 }
1543316140 }
16141
+
1543416142 if (isRenderer)
1543516143 {
1543616144 //gr.setColor(Color.black);
1543716145 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1543816146 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1543916147 }
16148
+
1544016149 if (hasMarquee)
1544116150 {
1544216151 gr.setXORMode(Color.white);
....@@ -15549,6 +16258,7 @@
1554916258 public boolean mouseDown(Event evt, int x, int y)
1555016259 {
1555116260 System.out.println("mouseDown: " + evt);
16261
+ System.exit(0);
1555216262 /*
1555316263 locked = true;
1555416264 drag = false;
....@@ -15592,7 +16302,7 @@
1559216302 {
1559316303 keyPressed(0, modifiers);
1559416304 }
15595
- clickStart(x, y, modifiers);
16305
+ // clickStart(x, y, modifiers);
1559616306 return true;
1559716307 }
1559816308
....@@ -15710,7 +16420,7 @@
1571016420 {
1571116421 keyReleased(0, 0);
1571216422 }
15713
- drag(x, y, modifiers);
16423
+ drag(x, y, 0, modifiers);
1571416424 return true;
1571516425 }
1571616426
....@@ -15842,7 +16552,7 @@
1584216552 Object3D object;
1584316553 static Object3D trackedobject;
1584416554 Camera renderCamera; // Light or Eye (or Occlusion)
15845
- /*static*/ Camera manipCamera; // Light or Eye
16555
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1584616556 /*static*/ Camera eyeCamera;
1584716557 /*static*/ Camera lightCamera;
1584816558 int cameracount;
....@@ -15906,6 +16616,8 @@
1590616616 private /*static*/ boolean firstime;
1590716617 private /*static*/ cVector newView = new cVector();
1590816618 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16619
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16620
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1590916621 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1591016622 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1591116623 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -15918,29 +16630,67 @@
1591816630 {
1591916631 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1592016632
16633
+ int usedsuf = 0;
16634
+
1592116635 for (int i = 0; i < suffixes.length; i++)
1592216636 {
15923
- String resourceName = basename + suffixes[i] + "." + suffix;
15924
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
15925
- mipmapped,
15926
- FileUtil.getFileSuffix(resourceName));
15927
- if (data == null)
16637
+ String[] suffixe = suffixes;
16638
+ String[] fallback = suffixes2;
16639
+ String[] fallfallback = suffixes3;
16640
+
16641
+ for (int c=usedsuf; --c>=0;)
1592816642 {
15929
- throw new IOException("Unable to load texture " + resourceName);
16643
+// String[] temp = suffixe;
16644
+// suffixe = fallback;
16645
+// fallback = fallfallback;
16646
+// fallfallback = temp;
1593016647 }
16648
+
16649
+ String resourceName = basename + suffixe[i] + "." + suffix;
16650
+ TextureData data;
16651
+
16652
+ try
16653
+ {
16654
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16655
+ mipmapped,
16656
+ FileUtil.getFileSuffix(resourceName));
16657
+ }
16658
+ catch (Exception e)
16659
+ {
16660
+ try
16661
+ {
16662
+ resourceName = basename + fallback[i] + "." + suffix;
16663
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16664
+ mipmapped,
16665
+ FileUtil.getFileSuffix(resourceName));
16666
+ }
16667
+ catch (Exception e2)
16668
+ {
16669
+ resourceName = basename + fallfallback[i] + "." + suffix;
16670
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16671
+ mipmapped,
16672
+ FileUtil.getFileSuffix(resourceName));
16673
+ }
16674
+ }
16675
+
1593116676 //System.out.println("Target = " + targets[i]);
1593216677 cubemap.updateImage(data, targets[i]);
1593316678 }
1593416679
1593516680 return cubemap;
1593616681 }
16682
+
1593716683 int bigsphere = -1;
1593816684
1593916685 float BGcolor = 0.5f;
1594016686
15941
- private void DrawSkyBox(GL gl)
16687
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16688
+
16689
+ private void DrawSkyBox(GL gl, float ratio)
1594216690 {
15943
- if (envyoff || cubemap == null)
16691
+ if (//envyoff ||
16692
+ WIREFRAME ||
16693
+ cubemap == null)
1594416694 {
1594516695 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1594616696 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -15955,7 +16705,17 @@
1595516705 // Compensates for ExaminerViewer's modification of modelview matrix
1595616706 gl.glMatrixMode(GL.GL_MODELVIEW);
1595716707 gl.glLoadIdentity();
16708
+ gl.glScalef(1,ratio,1);
1595816709
16710
+// colorV[0] = 2;
16711
+// colorV[1] = 2;
16712
+// colorV[2] = 2;
16713
+// colorV[3] = 1;
16714
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16715
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16716
+//
16717
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16718
+
1595916719 //gl.glActiveTexture(GL.GL_TEXTURE1);
1596016720 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1596116721
....@@ -15987,6 +16747,7 @@
1598716747 {
1598816748 gl.glScalef(1.0f, -1.0f, 1.0f);
1598916749 }
16750
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1599016751 gl.glMultMatrixd(viewrot_1, 0);
1599116752 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1599216753 //viewer.updateInverseRotation(gl);
....@@ -16127,16 +16888,16 @@
1612716888 cStatic.objectstack[materialdepth++] = checker;
1612816889 //System.out.println("material " + material);
1612916890 //Applet3D.tracein(this, selected);
16130
- vector2buffer = checker.projectedVertices;
16891
+ //vector2buffer = checker.projectedVertices;
1613116892
1613216893 //checker.GetMaterial().Draw(this, false); // true);
16133
- DrawMaterial(checker.GetMaterial(), false); // true);
16894
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1613416895
1613516896 materialdepth -= 1;
1613616897 if (materialdepth > 0)
1613716898 {
16138
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16139
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
16899
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16900
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1614016901 }
1614116902 //checker.GetMaterial().opacity = 1f;
1614216903 ////checker.GetMaterial().ambient = 1f;
....@@ -16222,6 +16983,14 @@
1622216983 }
1622316984 }
1622416985
16986
+ private Object3D GetFolder()
16987
+ {
16988
+ Object3D folder = object.GetWindow().copy;
16989
+ if (object.GetWindow().copy.selection.Size() > 0)
16990
+ folder = object.GetWindow().copy.selection.elementAt(0);
16991
+ return folder;
16992
+ }
16993
+
1622516994 class SelectBuffer implements GLEventListener
1622616995 {
1622716996
....@@ -16237,7 +17006,7 @@
1623717006 //new Exception().printStackTrace();
1623817007 System.out.println("select buffer init");
1623917008 // Use debug pipeline
16240
- drawable.setGL(new DebugGL(drawable.getGL()));
17009
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1624117010
1624217011 GL gl = drawable.getGL();
1624317012
....@@ -16280,6 +17049,7 @@
1628017049 {
1628117050 if (!selection)
1628217051 {
17052
+ new Exception().printStackTrace();
1628317053 System.exit(0);
1628417054 return;
1628517055 }
....@@ -16300,6 +17070,17 @@
1630017070
1630117071 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1630217072
17073
+ if (PAINTMODE)
17074
+ {
17075
+ if (object.GetWindow().copy.selection.Size() > 0)
17076
+ {
17077
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17078
+
17079
+ // Make what you paint not selectable.
17080
+ paintobj.ResetSelectable();
17081
+ }
17082
+ }
17083
+
1630317084 //int tmp = selection_view;
1630417085 //selection_view = -1;
1630517086 int temp = DrawMode();
....@@ -16311,6 +17092,17 @@
1631117092 // temp = DEFAULT; // patch for selection debug
1631217093 Globals.drawMode = temp; // WARNING
1631317094
17095
+ if (PAINTMODE)
17096
+ {
17097
+ if (object.GetWindow().copy.selection.Size() > 0)
17098
+ {
17099
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17100
+
17101
+ // Revert.
17102
+ paintobj.RestoreSelectable();
17103
+ }
17104
+ }
17105
+
1631417106 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1631517107
1631617108 // trying different ways of getting the depth info over
....@@ -16358,6 +17150,8 @@
1635817150 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1635917151 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1636017152 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
17153
+
17154
+ CreateSelectedPoint();
1636117155
1636217156 // Will fit the mesh !!!
1636317157 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16407,34 +17201,36 @@
1640717201 System.out.println("; fromto " + sel + " " + Trunk(previousselectedpoint.toParent[3][0]) + " " + Trunk(previousselectedpoint.toParent[3][2]) + " " + Trunk(selectedpoint.toParent[3][0]) + " " + Trunk(selectedpoint.toParent[3][2]));
1640817202 }
1640917203
16410
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
17204
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1641117205 }
1641217206 }
1641317207
1641417208 if (!movingcamera && !PAINTMODE)
16415
- object.editWindow.ScreenFitPoint(); // fev 2014
17209
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1641617210
16417
- if (PAINTMODE && GrafreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17211
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1641817212 {
16419
- Object3D paintobj = GrafreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17213
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1642017214
16421
- Object3D group = new Object3D("inst" + paintcount++);
17215
+ if (object.GetWindow().copy.selection.Size() > 0)
17216
+ {
17217
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1642217218
16423
- group.CreateMaterial(); // use a void leaf to select instances
16424
-
16425
- group.add(paintobj); // link
16426
-
16427
- object.editWindow.SnapObject(group);
16428
-
16429
- Object3D folder = object.editWindow.copy;
16430
-
16431
- if (object.editWindow.copy.selection.Size() > 0)
16432
- folder = object.editWindow.copy.selection.elementAt(0);
16433
-
16434
- folder.add(group);
16435
-
16436
- object.editWindow.ResetModel();
16437
- object.editWindow.refreshContents();
17219
+ Object3D inst = new Object3D("inst" + paintcount++);
17220
+
17221
+ inst.CreateMaterial(); // use a void leaf to select instances
17222
+
17223
+ inst.add(paintobj); // link
17224
+
17225
+ object.GetWindow().SnapObject(inst);
17226
+
17227
+ Object3D folder = paintFolder; // GetFolder();
17228
+
17229
+ folder.add(inst);
17230
+
17231
+ object.GetWindow().ResetModel();
17232
+ object.GetWindow().refreshContents();
17233
+ }
1643817234 }
1643917235 else
1644017236 paintcount = 0;
....@@ -16473,6 +17269,11 @@
1647317269 //System.out.println("objects[color] = " + objects[color]);
1647417270 //objects[color].Select();
1647517271 indexcount = 0;
17272
+ ObjEditor window = object.GetWindow();
17273
+ if (window != null && deselect)
17274
+ {
17275
+ window.Select(null, deselect, true);
17276
+ }
1647617277 object.Select(color, deselect);
1647717278 }
1647817279
....@@ -16572,7 +17373,7 @@
1657217373 gl.glDisable(gl.GL_CULL_FACE);
1657317374 }
1657417375
16575
- if (!RENDERSHADOW)
17376
+ if (!Globals.RENDERSHADOW)
1657617377 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1657717378
1657817379 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -16582,7 +17383,7 @@
1658217383 //gl.glColorMask(false, false, false, false);
1658317384
1658417385 //render_scene_from_light_view(gl, drawable, 0, 0);
16585
- if (RENDERSHADOW && Globals.lighttouched && !movingcamera) // && !parent.IsFreezed())
17386
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1658617387 {
1658717388 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1658817389
....@@ -16751,10 +17552,14 @@
1675117552 gl.glFlush();
1675217553
1675317554 /**/
16754
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17555
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1675517556
16756
- float[] pixels = occlusionsizebuffer.array();
17557
+ float[] depths = occlusiondepthbuffer.array();
1675717558
17559
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17560
+
17561
+ int[] pixels = selectsizebuffer.array();
17562
+
1675817563 double r = 0, g = 0, b = 0;
1675917564
1676017565 double count = 0;
....@@ -16765,7 +17570,7 @@
1676517570
1676617571 double FACTOR = 1;
1676717572
16768
- for (int i = 0; i < pixels.length; i++)
17573
+ for (int i = 0; i < depths.length; i++)
1676917574 {
1677017575 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1677117576 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -16848,7 +17653,7 @@
1684817653
1684917654 double scale = ray.z; // 1; // cos
1685017655
16851
- float depth = pixels[newindex];
17656
+ float depth = depths[newindex];
1685217657
1685317658 /*
1685417659 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -16998,23 +17803,15 @@
1699817803 int AAbuffersize = 0;
1699917804
1700017805 //double[] selectedpoint = new double[3];
17001
- static Superellipsoid selectedpoint = new Superellipsoid();
17806
+ static Superellipsoid selectedpoint;
1700217807 static Sphere previousselectedpoint = null;
17003
- static Sphere debugpointG = new Sphere();
17004
- static Sphere debugpointP = new Sphere();
17005
- static Sphere debugpointC = new Sphere();
17006
- static Sphere debugpointR = new Sphere();
17808
+ static Sphere debugpointG;
17809
+ static Sphere debugpointP;
17810
+ static Sphere debugpointC;
17811
+ static Sphere debugpointR;
1700717812
1700817813 static Sphere debugpoints[] = new Sphere[8];
1700917814
17010
- static
17011
- {
17012
- for (int i=0; i<8; i++)
17013
- {
17014
- debugpoints[i] = new Sphere();
17015
- }
17016
- }
17017
-
1701817815 static void InitPoints(float radius)
1701917816 {
1702017817 for (int i=0; i<8; i++)
....@@ -17053,11 +17850,14 @@
1705317850 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1705417851 static IntBuffer bigAAbuffer;
1705517852 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
17056
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17853
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1705717854 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1705817855 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1705917856 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17060
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17857
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17858
+
17859
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17860
+
1706117861 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1706217862 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1706317863 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();