Normand Briere
2019-07-28 d7fd07756f4095cb87dc25d89fcffcbda092e2cf
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;
....@@ -86,7 +120,7 @@
86120 static boolean FULLSCREEN = false;
87121 static boolean SUPPORT = true;
88122 static boolean INERTIA = true;
89
-static boolean FAST = true; // false;
123
+static boolean FAST = false;
90124 static boolean SLOWPOSE = false;
91125 static boolean FOOTCONTACT = true;
92126
....@@ -108,7 +142,7 @@
108142 static boolean OEIL = true;
109143 static boolean OEILONCE = false; // do oeilon then oeiloff
110144 static boolean LOOKAT = true;
111
-static boolean RANDOM = true; // false;
145
+static boolean SWITCH = true; // false;
112146 static boolean HANDLES = false; // selection doesn't work!!
113147 static boolean PAINTMODE = false;
114148
....@@ -152,6 +186,20 @@
152186 defaultcaps.setAccumAlphaBits(16);
153187 }
154188
189
+ private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
190
+
191
+ public void LoadSkybox(String name, String ext, boolean mipmap) throws GLException
192
+ {
193
+ try
194
+ {
195
+ cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
196
+ } catch (IOException e)
197
+ {
198
+ System.out.println("NAME = " + name);
199
+ e.printStackTrace(); // throw new RuntimeException(e);
200
+ }
201
+ }
202
+
155203 void SetAsGLRenderer(boolean b)
156204 {
157205 isRenderer = b;
....@@ -170,7 +218,8 @@
170218
171219 SetCamera(cam);
172220
173
- SetLight(new Camera(new cVector(10, 10, -20)));
221
+ // Warning: not used.
222
+ SetLight(new Camera(new cVector(15, 10, -20)));
174223
175224 object = o;
176225
....@@ -327,7 +376,7 @@
327376 cStatic.objectstack[materialdepth++] = obj;
328377 //System.out.println("material " + material);
329378 //Applet3D.tracein(this, selected);
330
- display.vector2buffer = obj.projectedVertices;
379
+ //display.vector2buffer = obj.projectedVertices;
331380 if (obj instanceof Camera)
332381 {
333382 display.options1[0] = material.shift;
....@@ -336,14 +385,28 @@
336385 display.options1[2] = material.shadowbias;
337386 display.options1[3] = material.aniso;
338387 display.options1[4] = material.anisoV;
388
+// System.out.println("display.options1[0] " + display.options1[0]);
389
+// System.out.println("display.options1[1] " + display.options1[1]);
390
+// System.out.println("display.options1[2] " + display.options1[2]);
391
+// System.out.println("display.options1[3] " + display.options1[3]);
392
+// System.out.println("display.options1[4] " + display.options1[4]);
339393 display.options2[0] = material.opacity;
340394 display.options2[1] = material.diffuse;
341395 display.options2[2] = material.factor;
396
+// System.out.println("display.options2[0] " + display.options2[0]);
397
+// System.out.println("display.options2[1] " + display.options2[1]);
398
+// System.out.println("display.options2[2] " + display.options2[2]);
342399
343400 cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
401
+// System.out.println("display.options3[0] " + display.options3[0]);
402
+// System.out.println("display.options3[1] " + display.options3[1]);
403
+// System.out.println("display.options3[2] " + display.options3[2]);
344404 display.options4[0] = material.cameralight/0.2f;
345405 display.options4[1] = material.subsurface;
346406 display.options4[2] = material.sheen;
407
+// System.out.println("display.options4[0] " + display.options4[0]);
408
+// System.out.println("display.options4[1] " + display.options4[1]);
409
+// System.out.println("display.options4[2] " + display.options4[2]);
347410
348411 // if (display.CURRENTANTIALIAS > 0)
349412 // display.options3[3] /= 4;
....@@ -359,7 +422,7 @@
359422 /**/
360423 } else
361424 {
362
- DrawMaterial(material, selected);
425
+ DrawMaterial(material, selected, obj.projectedVertices);
363426 }
364427 } else
365428 {
....@@ -383,8 +446,8 @@
383446 cStatic.objectstack[materialdepth++] = obj;
384447 //System.out.println("material " + material);
385448 //Applet3D.tracein("selected ", selected);
386
- display.vector2buffer = obj.projectedVertices;
387
- display.DrawMaterial(material, selected);
449
+ //display.vector2buffer = obj.projectedVertices;
450
+ display.DrawMaterial(material, selected, obj.projectedVertices);
388451 }
389452 }
390453
....@@ -401,8 +464,8 @@
401464 materialdepth -= 1;
402465 if (materialdepth > 0)
403466 {
404
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
405
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
467
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
468
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
406469 }
407470 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
408471 } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
....@@ -422,8 +485,8 @@
422485 materialdepth -= 1;
423486 if (materialdepth > 0)
424487 {
425
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
426
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
488
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
489
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
427490 }
428491 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
429492 //else
....@@ -464,10 +527,12 @@
464527 if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
465528 {
466529 //gl.glBegin(gl.GL_TRIANGLES);
467
- boolean hasnorm = pv.norm != null; // && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0);
530
+ boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0)
531
+ // TEST LIVE NORMALS && !obj.dontselect
532
+ ;
468533 if (!hasnorm)
469534 {
470
- // System.out.println("FUCK!!");
535
+ // System.out.println("Mesh normal");
471536 LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
472537 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
473538 LA.vecCross(obj.v0, obj.v1, obj.v2);
....@@ -1192,10 +1257,12 @@
11921257 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
11931258 }
11941259 }
1260
+
11951261 if (flipV)
11961262 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
11971263 else
11981264 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1265
+
11991266 //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
12001267 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
12011268
....@@ -1215,10 +1282,12 @@
12151282 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
12161283 }
12171284 }
1285
+
12181286 if (flipV)
12191287 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12201288 else
12211289 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1290
+
12221291 //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
12231292 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
12241293
....@@ -1246,8 +1315,10 @@
12461315 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12471316 else
12481317 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1318
+
12491319 //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
12501320 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1321
+
12511322 count2 += 2;
12521323 count3 += 3;
12531324 }
....@@ -1426,6 +1497,8 @@
14261497 gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
14271498 }
14281499
1500
+ float[] colorV = new float[4];
1501
+
14291502 void SetColor(Object3D obj, Vertex p0)
14301503 {
14311504 CameraPane display = this;
....@@ -1493,8 +1566,6 @@
14931566 {
14941567 return;
14951568 }
1496
-
1497
- float[] colorV = new float[3];
14981569
14991570 if (false) // marked)
15001571 {
....@@ -1603,7 +1674,7 @@
16031674 // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
16041675 }
16051676
1606
- void DrawMaterial(cMaterial material, boolean selected)
1677
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
16071678 {
16081679 CameraPane display = this;
16091680 //new Exception().printStackTrace();
....@@ -1630,7 +1701,7 @@
16301701
16311702 cColor.HSBtoRGB(display.color, display.saturation, 1, display.modelParams0);
16321703
1633
- float[] colorV = GrafreeD.colorV;
1704
+ float[] colorV = Grafreed.colorV;
16341705
16351706 /**/
16361707 if (display.DrawMode() == display.DEFAULT) // && display.RENDERPROGRAM == 0)
....@@ -1638,7 +1709,7 @@
16381709 colorV[0] = display.modelParams0[0] * material.diffuse;
16391710 colorV[1] = display.modelParams0[1] * material.diffuse;
16401711 colorV[2] = display.modelParams0[2] * material.diffuse;
1641
- colorV[3] = material.opacity;
1712
+ colorV[3] = 1; // material.opacity;
16421713
16431714 gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
16441715 //System.out.println("Opacity = " + opacity);
....@@ -1746,9 +1817,9 @@
17461817 display.modelParams7[2] = 0;
17471818 display.modelParams7[3] = 0;
17481819
1749
- display.modelParams6[0] = 100; // criss de bug de bump
1820
+ //display.modelParams6[0] = 100; // criss de bug de bump
17501821
1751
- Object3D.cVector2[] extparams = display.vector2buffer;
1822
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
17521823 if (extparams != null && extparams.length > 0 && extparams[0] != null)
17531824 {
17541825 display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
....@@ -1890,7 +1961,7 @@
18901961 void PushMatrix(double[][] matrix)
18911962 {
18921963 // GrafreeD.tracein(matrix);
1893
- PushMatrix(matrix,1);
1964
+ PushMatrix(matrix, 1);
18941965 }
18951966
18961967 void PushMatrix()
....@@ -2044,7 +2115,7 @@
20442115 //System.err.println("Oeil on");
20452116 OEIL = true;
20462117 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2047
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2118
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
20482119 //pingthread.StepToTarget(true);
20492120 }
20502121
....@@ -2142,7 +2213,7 @@
21422213 System.err.println("LIVE = " + Globals.isLIVE());
21432214
21442215 if (!Globals.isLIVE()) // save sound
2145
- GrafreeD.savesound = true; // wav.save();
2216
+ Grafreed.savesound = true; // wav.save();
21462217 // else
21472218 repaint(); // start loop // may 2013
21482219 }
....@@ -2259,7 +2330,7 @@
22592330
22602331 void ToggleDebug()
22612332 {
2262
- DEBUG ^= true;
2333
+ Globals.DEBUG ^= true;
22632334 }
22642335
22652336 void ToggleLookAt()
....@@ -2267,9 +2338,9 @@
22672338 LOOKAT ^= true;
22682339 }
22692340
2270
- void ToggleRandom()
2341
+ void ToggleSwitch()
22712342 {
2272
- RANDOM ^= true;
2343
+ SWITCH ^= true;
22732344 }
22742345
22752346 void ToggleHandles()
....@@ -2277,10 +2348,17 @@
22772348 HANDLES ^= true;
22782349 }
22792350
2351
+ Object3D paintFolder;
2352
+
22802353 void TogglePaint()
22812354 {
22822355 PAINTMODE ^= true;
22832356 paintcount = 0;
2357
+
2358
+ if (PAINTMODE)
2359
+ {
2360
+ paintFolder = GetFolder();
2361
+ }
22842362 }
22852363
22862364 void SwapCamera(int a, int b)
....@@ -2376,7 +2454,22 @@
23762454 {
23772455 return currentGL;
23782456 }
2379
-
2457
+
2458
+ static private BufferedImage CreateBim(TextureData texturedata)
2459
+ {
2460
+ Grafreed.Assert(texturedata != null);
2461
+
2462
+ int width = texturedata.getWidth();
2463
+ int height = texturedata.getHeight();
2464
+
2465
+ Buffer buffer = texturedata.getBuffer();
2466
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2467
+
2468
+ byte[] bytes = bytebuf.array();
2469
+
2470
+ return CreateBim(bytes, width, height);
2471
+ }
2472
+
23802473 /**/
23812474 class CacheTexture
23822475 {
....@@ -2385,28 +2478,31 @@
23852478
23862479 int resolution;
23872480
2388
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2481
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
23892482 {
2390
- texture = tex;
2483
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2484
+ texturedata = texdata;
23912485 resolution = res;
23922486 }
23932487 }
23942488 /**/
23952489
23962490 // 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>();
2491
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2492
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2493
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2494
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2495
+
24002496 int pigmentdepth = 0;
24012497 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
24022498 int bumpdepth = 0;
24032499 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
24042500 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
24052501 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2406
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2502
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
24072503 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
24082504
2409
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2505
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
24102506 {
24112507 TextureData texturedata = null;
24122508
....@@ -2425,13 +2521,34 @@
24252521 if (bump)
24262522 texturedata = ConvertBump(texturedata, false);
24272523
2428
- com.sun.opengl.util.texture.Texture texture =
2429
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2524
+// com.sun.opengl.util.texture.Texture texture =
2525
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
24302526
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);
2527
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2528
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
24332529
2434
- return texture;
2530
+ return texturedata;
2531
+ }
2532
+
2533
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2534
+ {
2535
+ TextureData texturedata = null;
2536
+
2537
+ try
2538
+ {
2539
+ texturedata =
2540
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2541
+ bim,
2542
+ true);
2543
+ } catch (Exception e)
2544
+ {
2545
+ throw new javax.media.opengl.GLException(e);
2546
+ }
2547
+
2548
+ if (bump)
2549
+ texturedata = ConvertBump(texturedata, false);
2550
+
2551
+ return texturedata;
24352552 }
24362553
24372554 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3504,6 +3621,8 @@
35043621
35053622 System.out.println("LOADING TEXTURE : " + name);
35063623
3624
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3625
+
35073626 //
35083627 if (false) // compressbit > 0)
35093628 {
....@@ -4208,6 +4327,7 @@
42084327
42094328 com.sun.opengl.util.texture.Texture CompressTexture2(String name)
42104329 {
4330
+ new Exception().printStackTrace();
42114331 System.exit(0);
42124332 com.sun.opengl.util.texture.Texture texture = null;
42134333
....@@ -7901,7 +8021,7 @@
79018021 String pigment = Object3D.GetPigment(tex);
79028022 String bump = Object3D.GetBump(tex);
79038023
7904
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8024
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79058025 {
79068026 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79078027 // System.out.println("; bump = " + bump);
....@@ -7916,11 +8036,69 @@
79168036 pigment = null;
79178037 }
79188038
7919
- ReleaseTexture(bump, true);
7920
- ReleaseTexture(pigment, false);
8039
+ ReleaseTexture(tex, true);
8040
+ ReleaseTexture(tex, false);
79218041 }
79228042
7923
- void ReleaseTexture(String tex, boolean bump)
8043
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
8044
+ {
8045
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8046
+ {
8047
+ return;
8048
+ }
8049
+
8050
+ if (tex == null)
8051
+ {
8052
+ ReleaseTexture(null, false);
8053
+ return;
8054
+ }
8055
+
8056
+ String pigment = Object3D.GetPigment(tex);
8057
+
8058
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8059
+ {
8060
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8061
+ // System.out.println("; bump = " + bump);
8062
+ }
8063
+
8064
+ if (pigment.equals(""))
8065
+ {
8066
+ pigment = null;
8067
+ }
8068
+
8069
+ ReleaseTexture(tex, false);
8070
+ }
8071
+
8072
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
8073
+ {
8074
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8075
+ {
8076
+ return;
8077
+ }
8078
+
8079
+ if (tex == null)
8080
+ {
8081
+ ReleaseTexture(null, true);
8082
+ return;
8083
+ }
8084
+
8085
+ String bump = Object3D.GetBump(tex);
8086
+
8087
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8088
+ {
8089
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8090
+ // System.out.println("; bump = " + bump);
8091
+ }
8092
+
8093
+ if (bump.equals(""))
8094
+ {
8095
+ bump = null;
8096
+ }
8097
+
8098
+ ReleaseTexture(tex, true);
8099
+ }
8100
+
8101
+ void ReleaseTexture(cTexture tex, boolean bump)
79248102 {
79258103 if (// DrawMode() != 0 || /*tex == null ||*/
79268104 ambientOcclusion ) // || !textureon)
....@@ -7931,7 +8109,7 @@
79318109 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
79328110
79338111 if (tex != null)
7934
- texture = textures.get(tex);
8112
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
79358113
79368114 // //assert( texture != null );
79378115 // if (texture == null)
....@@ -8023,7 +8201,55 @@
80238201 }
80248202 }
80258203
8026
- /*boolean*/ public void BindTextures(cTexture tex, int resolution) // INTERFACE
8204
+ /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
8205
+ {
8206
+// if (// DrawMode() != 0 || /*tex == null ||*/
8207
+// ambientOcclusion ) // || !textureon)
8208
+// {
8209
+// return; // false;
8210
+// }
8211
+//
8212
+// if (tex == null)
8213
+// {
8214
+// BindTexture(null,false,resolution);
8215
+// BindTexture(null,true,resolution);
8216
+// return;
8217
+// }
8218
+//
8219
+// String pigment = Object3D.GetPigment(tex);
8220
+// String bump = Object3D.GetBump(tex);
8221
+//
8222
+// usedtextures.add(pigment);
8223
+// usedtextures.add(bump);
8224
+//
8225
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8226
+// {
8227
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8228
+// // System.out.println("; bump = " + bump);
8229
+// }
8230
+//
8231
+// if (bump.equals(""))
8232
+// {
8233
+// bump = null;
8234
+// }
8235
+// if (pigment.equals(""))
8236
+// {
8237
+// pigment = null;
8238
+// }
8239
+//
8240
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8241
+// BindTexture(pigment, false, resolution);
8242
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8243
+// BindTexture(bump, true, resolution);
8244
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8245
+//
8246
+// return; // true;
8247
+
8248
+ BindPigmentTexture(tex, resolution);
8249
+ BindBumpTexture(tex, resolution);
8250
+ }
8251
+
8252
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
80278253 {
80288254 if (// DrawMode() != 0 || /*tex == null ||*/
80298255 ambientOcclusion ) // || !textureon)
....@@ -8034,17 +8260,47 @@
80348260 if (tex == null)
80358261 {
80368262 BindTexture(null,false,resolution);
8037
- BindTexture(null,true,resolution);
80388263 return;
80398264 }
80408265
80418266 String pigment = Object3D.GetPigment(tex);
8267
+
8268
+ usedtextures.add(tex);
8269
+
8270
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8271
+ {
8272
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8273
+ // System.out.println("; bump = " + bump);
8274
+ }
8275
+
8276
+ if (pigment.equals(""))
8277
+ {
8278
+ pigment = null;
8279
+ }
8280
+
8281
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8282
+ BindTexture(tex, false, resolution);
8283
+ }
8284
+
8285
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8286
+ {
8287
+ if (// DrawMode() != 0 || /*tex == null ||*/
8288
+ ambientOcclusion ) // || !textureon)
8289
+ {
8290
+ return; // false;
8291
+ }
8292
+
8293
+ if (tex == null)
8294
+ {
8295
+ BindTexture(null,true,resolution);
8296
+ return;
8297
+ }
8298
+
80428299 String bump = Object3D.GetBump(tex);
80438300
8044
- usedtextures.put(pigment, pigment);
8045
- usedtextures.put(bump, bump);
8301
+ usedtextures.add(tex);
80468302
8047
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8303
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
80488304 {
80498305 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
80508306 // System.out.println("; bump = " + bump);
....@@ -8054,43 +8310,94 @@
80548310 {
80558311 bump = null;
80568312 }
8057
- if (pigment.equals(""))
8058
- {
8059
- pigment = null;
8060
- }
80618313
8062
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8063
- BindTexture(pigment, false, resolution);
80648314 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8065
- BindTexture(bump, true, resolution);
8315
+ BindTexture(tex, true, resolution);
80668316 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8067
-
8068
- return; // true;
80698317 }
80708318
8071
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution)
8319
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8320
+
8321
+ private boolean FileExists(String tex)
80728322 {
8073
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8323
+ if (missingTextures.contains(tex))
8324
+ {
8325
+ return false;
8326
+ }
8327
+
8328
+ boolean fileExists = new File(tex).exists();
8329
+
8330
+ if (!fileExists)
8331
+ {
8332
+ // If file exists, the "new File()" is not executed sgain
8333
+ missingTextures.add(tex);
8334
+ }
8335
+
8336
+ return fileExists;
8337
+ }
8338
+
8339
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
8340
+ {
8341
+ CacheTexture texturecache = null;
80748342
80758343 if (tex != null)
80768344 {
8077
- String texname = tex;
8345
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8346
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
80788347
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;
8348
+ if (texname.equals("") && texdata == null)
8349
+ {
8350
+ return null;
8351
+ }
8352
+
8353
+ String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
8354
+
8355
+// String[] split = tex.split("Textures");
8356
+// if (split.length > 1)
8357
+// texname = "/Users/nbriere/Textures" + split[split.length-1];
8358
+// else
8359
+// if (!texname.startsWith("/"))
8360
+// texname = "/Users/nbriere/Textures/" + texname;
8361
+ if (!FileExists(texname))
8362
+ {
8363
+ texname = fallbackTextureName;
8364
+ }
80858365
80868366 if (CACHETEXTURE)
8087
- texture = textures.get(texname); // TEXTURE CACHE
8088
-
8089
- TextureData texturedata = null;
8090
-
8091
- if (texture == null || texture.resolution < resolution)
80928367 {
8093
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8368
+ if (texdata == null)
8369
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8370
+ else
8371
+ texturecache = bimtextures.get(texdata);
8372
+ }
8373
+
8374
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8375
+ {
8376
+ TextureData texturedata = null;
8377
+
8378
+ if (texdata != null && textureon)
8379
+ {
8380
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8381
+
8382
+ try
8383
+ {
8384
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8385
+ }
8386
+ catch (Exception e)
8387
+ {
8388
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8389
+ }
8390
+
8391
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8392
+ bimtextures.put(texdata, texturecache);
8393
+
8394
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8395
+
8396
+ //Object bim2 = CreateBim(texturecache.texturedata);
8397
+ //bim2 = bim;
8398
+ }
8399
+ else
8400
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
80948401 {
80958402 assert(!bump);
80968403 // if (bump)
....@@ -8101,19 +8408,23 @@
81018408 // }
81028409 // else
81038410 // {
8104
- texture = textures.get(tex);
8105
- if (texture == null)
8411
+ // texturecache = textures.get(texname); // suspicious
8412
+ if (texturecache == null)
81068413 {
8107
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8414
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
81088415 }
8416
+ else
8417
+ new Exception().printStackTrace();
81098418 // }
81108419 } else
8111
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8420
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
81128421 {
81138422 assert(bump);
8114
- texture = textures.get(tex);
8115
- if (texture == null)
8116
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8423
+ // texturecache = textures.get(texname); // suspicious
8424
+ if (texturecache == null)
8425
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8426
+ else
8427
+ new Exception().printStackTrace();
81178428 } else
81188429 {
81198430 //if (tex.equals("IMMORTAL"))
....@@ -8121,11 +8432,13 @@
81218432 // texture = GetResourceTexture("default.png");
81228433 //} else
81238434 //{
8124
- if (tex.equals("WHITE_NOISE"))
8435
+ if (texname.endsWith("WHITE_NOISE"))
81258436 {
8126
- texture = textures.get(tex);
8127
- if (texture == null)
8128
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8437
+ // texturecache = textures.get(texname); // suspicious
8438
+ if (texturecache == null)
8439
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8440
+ else
8441
+ new Exception().printStackTrace();
81298442 } else
81308443 {
81318444 if (textureon)
....@@ -8150,7 +8463,7 @@
81508463 }
81518464
81528465 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
8153
- if (!new File(cachename).exists())
8466
+ if (!FileExists(cachename))
81548467 cachename = texname;
81558468 else
81568469 processbump = false; // don't process bump map again
....@@ -8172,7 +8485,7 @@
81728485 }
81738486
81748487 cachename = texname.substring(0, texname.length()-4)+ext+".png";
8175
- if (!new File(cachename).exists())
8488
+ if (!FileExists(cachename))
81768489 cachename = texname;
81778490 else
81788491 processbump = false; // don't process bump map again
....@@ -8181,20 +8494,22 @@
81818494 texturedata = GetFileTexture(cachename, processbump, resolution);
81828495
81838496
8184
- if (texturedata != null)
8185
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8497
+ if (texturedata == null)
8498
+ throw new Exception();
8499
+
8500
+ texturecache = new CacheTexture(texturedata,resolution);
81868501 //texture = GetTexture(tex, bump);
81878502 }
81888503 }
81898504 //}
81908505 }
81918506
8192
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8507
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
81938508 {
81948509 //return false;
81958510
81968511 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8197
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8512
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
81988513 {
81998514 // String ext = "_highres";
82008515 // if (REDUCETEXTURE)
....@@ -8211,52 +8526,17 @@
82118526 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
82128527 if (!cachefile.exists())
82138528 {
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))
8529
+ //if (texturedata.getWidth() == texturedata.getHeight())
82238530 {
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);
8531
+ BufferedImage rendImage = CreateBim(texturedata);
8532
+
82548533 ImageWriter writer = null;
82558534 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
82568535 if (iter.hasNext()) {
82578536 writer = (ImageWriter)iter.next();
82588537 }
8259
- float compressionQuality = 0.9f;
8538
+
8539
+ float compressionQuality = 0.85f;
82608540 try
82618541 {
82628542 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8273,18 +8553,20 @@
82738553 }
82748554 }
82758555 }
8276
-
8556
+
8557
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8558
+
82778559 //System.out.println("Texture = " + tex);
8278
- if (textures.containsKey(texname))
8560
+ if (textures.containsKey(tex))
82798561 {
8280
- CacheTexture thetex = textures.get(texname);
8562
+ CacheTexture thetex = textures.get(tex);
82818563 thetex.texture.disable();
82828564 thetex.texture.dispose();
8283
- textures.remove(texname);
8565
+ textures.remove(tex);
82848566 }
82858567
8286
- texture.texturedata = texturedata;
8287
- textures.put(texname, texture);
8568
+ //texture.texturedata = texturedata;
8569
+ textures.put(tex, texturecache);
82888570
82898571 // newtex = true;
82908572 }
....@@ -8300,10 +8582,44 @@
83008582 }
83018583 }
83028584
8303
- return texture;
8585
+ return texturecache;
83048586 }
83058587
8306
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution)
8588
+ static void EmbedTextures(cTexture tex)
8589
+ {
8590
+ if (tex.pigmentdata == null)
8591
+ {
8592
+ //String texname = Object3D.GetPigment(tex);
8593
+
8594
+ CacheTexture texturecache = texturepigment.get(tex);
8595
+
8596
+ if (texturecache != null)
8597
+ {
8598
+ tex.pw = texturecache.texturedata.getWidth();
8599
+ tex.ph = texturecache.texturedata.getHeight();
8600
+ tex.pigmentdata = //CompressJPEG(CreateBim
8601
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8602
+ ;
8603
+ //, tex.pw, tex.ph), 0.5f);
8604
+ }
8605
+ }
8606
+
8607
+ if (tex.bumpdata == null)
8608
+ {
8609
+ //String texname = Object3D.GetBump(tex);
8610
+
8611
+ CacheTexture texturecache = texturebump.get(tex);
8612
+
8613
+ if (texturecache != null)
8614
+ {
8615
+ tex.bw = texturecache.texturedata.getWidth();
8616
+ tex.bh = texturecache.texturedata.getHeight();
8617
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8618
+ }
8619
+ }
8620
+ }
8621
+
8622
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
83078623 {
83088624 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
83098625
....@@ -8321,21 +8637,21 @@
83218637 return texture!=null?texture.texture:null;
83228638 }
83238639
8324
- public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution)
8640
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
83258641 {
83268642 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
83278643
83288644 return texture!=null?texture.texturedata:null;
83298645 }
83308646
8331
- boolean BindTexture(String tex, boolean bump, int resolution)
8647
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
83328648 {
83338649 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
83348650 {
83358651 return false;
83368652 }
83378653
8338
- boolean newtex = false;
8654
+ //boolean newtex = false;
83398655
83408656 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
83418657
....@@ -8367,9 +8683,75 @@
83678683 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
83688684 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
83698685
8370
- return newtex;
8686
+ return true; // Warning: not used.
83718687 }
83728688
8689
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8690
+ {
8691
+ try
8692
+ {
8693
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8694
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8695
+ ImageWriter writer = writers.next();
8696
+
8697
+ ImageWriteParam param = writer.getDefaultWriteParam();
8698
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8699
+ param.setCompressionQuality(quality);
8700
+
8701
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8702
+ writer.setOutput(ios);
8703
+ writer.write(null, new IIOImage(image, null, null), param);
8704
+
8705
+ byte[] data = baos.toByteArray();
8706
+ writer.dispose();
8707
+ return data;
8708
+ }
8709
+ catch (Exception e)
8710
+ {
8711
+ e.printStackTrace();
8712
+ return null;
8713
+ }
8714
+ }
8715
+
8716
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8717
+ {
8718
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8719
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8720
+ ImageReader reader = writers.next();
8721
+
8722
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8723
+
8724
+ ImageReadParam param = reader.getDefaultReadParam();
8725
+ param.setDestination(bim);
8726
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8727
+
8728
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8729
+ reader.setInput(ios);
8730
+ BufferedImage bim2 = reader.read(0, param);
8731
+ reader.dispose();
8732
+
8733
+// WritableRaster raster = bim2.getRaster();
8734
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8735
+// byte[] bytes = data.getData();
8736
+//
8737
+// int[] pixels = new int[bytes.length/3];
8738
+// for (int i=pixels.length; --i>=0;)
8739
+// {
8740
+// int i3 = i*3;
8741
+// pixels[i] = 0xFF;
8742
+// pixels[i] <<= 8;
8743
+// pixels[i] |= bytes[i3+2] & 0xFF;
8744
+// pixels[i] <<= 8;
8745
+// pixels[i] |= bytes[i3+1] & 0xFF;
8746
+// pixels[i] <<= 8;
8747
+// pixels[i] |= bytes[i3] & 0xFF;
8748
+// }
8749
+//
8750
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8751
+
8752
+ return bim;
8753
+ }
8754
+
83738755 ShadowBuffer shadowPBuf;
83748756 AntialiasBuffer antialiasPBuf;
83758757 int MAXSTACK;
....@@ -8562,7 +8944,7 @@
85628944
85638945 if (cubemap == null)
85648946 {
8565
- LoadEnvy(5);
8947
+ //LoadEnvy(1);
85668948 }
85678949
85688950 //cubemap.enable();
....@@ -8849,37 +9231,58 @@
88499231 cubemap = null;
88509232 return;
88519233 case 1:
8852
- name = "cubemaps/box_";
8853
- ext = "png";
9234
+ name = "cubemaps/rgb/";
9235
+ ext = "jpg";
88549236 reverseUP = false;
88559237 break;
88569238 case 2:
8857
- name = "cubemaps/uffizi_";
8858
- ext = "png";
8859
- break; // reverseUP = true; break;
9239
+ name = "cubemaps/uffizi/";
9240
+ ext = "jpg";
9241
+ reverseUP = false;
9242
+ break;
88609243 case 3:
8861
- name = "cubemaps/CloudyHills_";
8862
- ext = "tga";
9244
+ name = "cubemaps/CloudyHills/";
9245
+ ext = "jpg";
88639246 reverseUP = false;
88649247 break;
88659248 case 4:
8866
- name = "cubemaps/cornell_";
9249
+ name = "cubemaps/cornell/";
88679250 ext = "png";
88689251 reverseUP = false;
88699252 break;
9253
+ case 5:
9254
+ name = "cubemaps/skycube/";
9255
+ ext = "jpg";
9256
+ reverseUP = false;
9257
+ break;
9258
+ case 6:
9259
+ name = "cubemaps/SaintLazarusChurch3/";
9260
+ ext = "jpg";
9261
+ reverseUP = false;
9262
+ break;
9263
+ case 7:
9264
+ name = "cubemaps/Sodermalmsallen/";
9265
+ ext = "jpg";
9266
+ reverseUP = false;
9267
+ break;
9268
+ case 8:
9269
+ name = "cubemaps/Sodermalmsallen2/";
9270
+ ext = "jpg";
9271
+ reverseUP = false;
9272
+ break;
9273
+ case 9:
9274
+ name = "cubemaps/UnionSquare/";
9275
+ ext = "jpg";
9276
+ reverseUP = false;
9277
+ break;
88709278 default:
8871
- name = "cubemaps/rgb_";
8872
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9279
+ name = "cubemaps/box/";
9280
+ ext = "png"; /*mipmap = true;*/
9281
+ reverseUP = false;
88739282 break;
88749283 }
8875
-
8876
- try
8877
- {
8878
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
8879
- } catch (IOException e)
8880
- {
8881
- throw new RuntimeException(e);
8882
- }
9284
+
9285
+ LoadSkybox(name, ext, mipmap);
88839286 }
88849287
88859288 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -8911,8 +9314,13 @@
89119314 static double[] model = new double[16];
89129315 double[] camera2light = new double[16];
89139316 double[] light2camera = new double[16];
8914
- int newenvy = -1;
9317
+
9318
+ //int newenvy = -1;
89159319 boolean envyoff = true; // false;
9320
+ String skyboxname = "";
9321
+ String skyboxext;
9322
+ String loadedskyboxname = "";
9323
+
89169324 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
89179325 //float[] light0 = { 0,0,0 };
89189326 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9205,11 +9613,35 @@
92059613 jy8[3] = 0.5f;
92069614 }
92079615
9208
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9616
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
92099617 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
92109618 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
92119619 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
92129620
9621
+ void ResetOptions()
9622
+ {
9623
+ options1[0] = 100;
9624
+ options1[1] = 0.025f;
9625
+ options1[2] = 0.01f;
9626
+ options1[3] = 0;
9627
+ options1[4] = 0;
9628
+
9629
+ options2[0] = 0;
9630
+ options2[1] = 0.75f;
9631
+ options2[2] = 0;
9632
+ options2[3] = 0;
9633
+
9634
+ options3[0] = 1;
9635
+ options3[1] = 1;
9636
+ options3[2] = 1;
9637
+ options3[3] = 0;
9638
+
9639
+ options4[0] = 1;
9640
+ options4[1] = 0;
9641
+ options4[2] = 1;
9642
+ options4[3] = 0;
9643
+ }
9644
+
92139645 static int imagecount = 0; // movie generation
92149646
92159647 static int jitter = 0;
....@@ -9305,8 +9737,8 @@
93059737 assert (parentcam != renderCamera);
93069738
93079739 if (renderCamera != lightCamera)
9308
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9309
- LA.matConcat(matrix, parentcam.toParent, matrix);
9740
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9741
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
93109742
93119743 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
93129744
....@@ -9321,8 +9753,8 @@
93219753 LA.matCopy(renderCamera.fromScreen, matrix);
93229754
93239755 if (renderCamera != lightCamera)
9324
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9325
- LA.matConcat(parentcam.fromParent, matrix, matrix);
9756
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9757
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
93269758
93279759 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
93289760
....@@ -9368,10 +9800,12 @@
93689800 rati = 1 / rati;
93699801 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
93709802 }
9371
- assert (newenvy == -1);
9803
+
9804
+ //assert (newenvy == -1);
9805
+
93729806 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
93739807 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9374
- DrawSkyBox(gl);
9808
+ DrawSkyBox(gl, (float)rati);
93759809 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
93769810 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
93779811 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -9394,7 +9828,7 @@
93949828 //gl.glFlush();
93959829 gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE);
93969830
9397
- if (ANIMATION && ABORTED)
9831
+ if (Globals.ANIMATION && ABORTED)
93989832 {
93999833 System.err.println(" ABORTED FRAME");
94009834 break;
....@@ -9424,7 +9858,7 @@
94249858 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
94259859
94269860 // save image
9427
- if (ANIMATION && !ABORTED)
9861
+ if (Globals.ANIMATION && !ABORTED)
94289862 {
94299863 VPwidth = viewport[2];
94309864 VPheight = viewport[3];
....@@ -9535,11 +9969,11 @@
95359969
95369970 // imagecount++;
95379971
9538
- String fullname = filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
9972
+ String fullname = Globals.filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
95399973
95409974 if (!BOXMODE)
95419975 {
9542
- System.out.println("image: " + fullname + " (wav cursor=" + (GrafreeD.wav.cursor / 735 / 4) + ")");
9976
+ System.out.println("image: " + fullname + " (wav cursor=" + (Grafreed.wav.cursor / 735 / 4) + ")");
95439977 }
95449978
95459979 if (!BOXMODE)
....@@ -9577,7 +10011,7 @@
957710011 ABORTED = false;
957810012 }
957910013 else
9580
- GrafreeD.wav.cursor += 735 * ACSIZE;
10014
+ Grafreed.wav.cursor += 735 * ACSIZE;
958110015
958210016 if (false)
958310017 {
....@@ -10240,11 +10674,11 @@
1024010674
1024110675 public void display(GLAutoDrawable drawable)
1024210676 {
10243
- if (GrafreeD.savesound && GrafreeD.hassound)
10677
+ if (Grafreed.savesound && Grafreed.hassound)
1024410678 {
10245
- GrafreeD.wav.save();
10246
- GrafreeD.savesound = false;
10247
- GrafreeD.hassound = false;
10679
+ Grafreed.wav.save();
10680
+ Grafreed.savesound = false;
10681
+ Grafreed.hassound = false;
1024810682 }
1024910683 // if (DEBUG_SELECTION)
1025010684 // {
....@@ -10320,6 +10754,7 @@
1032010754 ANTIALIAS = 0;
1032110755 //System.out.println("RESTART");
1032210756 AAtimer.restart();
10757
+ Globals.TIMERRUNNING = true;
1032310758 }
1032410759 }
1032510760 }
....@@ -10374,7 +10809,7 @@
1037410809 Object3D theobject = object;
1037510810 Object3D theparent = object.parent;
1037610811 object.parent = null;
10377
- object = (Object3D)GrafreeD.clone(object);
10812
+ object = (Object3D)Grafreed.clone(object);
1037810813 object.Stripify();
1037910814 if (theobject.selection == null || theobject.selection.Size() == 0)
1038010815 theobject.PreprocessOcclusion(this);
....@@ -10387,13 +10822,14 @@
1038710822 ambientOcclusion = false;
1038810823 }
1038910824
10390
- if (Globals.lighttouched && DrawMode() == DEFAULT && !lightMode) // && !FROZEN)
10825
+ if (//Globals.lighttouched &&
10826
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1039110827 {
1039210828 //if (RENDERSHADOW) // ?
1039310829 if (!IsFrozen())
1039410830 {
1039510831 // dec 2012
10396
- if (!ambientOcclusion && !(!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0))
10832
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
1039710833 {
1039810834 Globals.framecount++;
1039910835 shadowbuffer.display();
....@@ -10520,8 +10956,8 @@
1052010956
1052110957 // if (parentcam != renderCamera) // not a light
1052210958 if (cam != lightCamera)
10523
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10524
- LA.matConcat(matrix, parentcam.toParent, matrix);
10959
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10960
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1052510961
1052610962 for (int j = 0; j < 4; j++)
1052710963 {
....@@ -10535,8 +10971,8 @@
1053510971
1053610972 // if (parentcam != renderCamera) // not a light
1053710973 if (cam != lightCamera)
10538
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10539
- LA.matConcat(parentcam.fromParent, matrix, matrix);
10974
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10975
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1054010976
1054110977 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1054210978
....@@ -10622,13 +11058,19 @@
1062211058 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1062311059 }
1062411060
10625
- if (newenvy > -1)
11061
+// if (newenvy > -1)
11062
+// {
11063
+// LoadEnvy(newenvy);
11064
+// }
11065
+//
11066
+// newenvy = -1;
11067
+
11068
+ if (!skyboxname.equals(this.loadedskyboxname))
1062611069 {
10627
- LoadEnvy(newenvy);
11070
+ LoadSkybox(skyboxname + "/", skyboxext, false);
11071
+ loadedskyboxname = skyboxname;
1062811072 }
10629
-
10630
- newenvy = -1;
10631
-
11073
+
1063211074 ratio = ((double) getWidth()) / getHeight();
1063311075 //System.out.println("ratio = " + ratio);
1063411076
....@@ -10644,7 +11086,7 @@
1064411086
1064511087 if (!IsFrozen() && !ambientOcclusion)
1064611088 {
10647
- DrawSkyBox(gl);
11089
+ DrawSkyBox(gl, (float)ratio);
1064811090 }
1064911091
1065011092 //if (selection_view == -1)
....@@ -10795,7 +11237,16 @@
1079511237 // Bump noise
1079611238 gl.glActiveTexture(GL.GL_TEXTURE6);
1079711239 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
10798
- BindTexture(NOISE_TEXTURE, false, 2);
11240
+
11241
+ try
11242
+ {
11243
+ BindTexture(NOISE_TEXTURE, false, 2);
11244
+ }
11245
+ catch (Exception e)
11246
+ {
11247
+ System.err.println("FAILED: " + NOISE_TEXTURE);
11248
+ }
11249
+
1079911250
1080011251 gl.glActiveTexture(GL.GL_TEXTURE0);
1080111252 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -10818,9 +11269,9 @@
1081811269
1081911270 gl.glMatrixMode(GL.GL_MODELVIEW);
1082011271
10821
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10822
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10823
-//gl.glEnable(gl.GL_MULTISAMPLE);
11272
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11273
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11274
+gl.glEnable(gl.GL_MULTISAMPLE);
1082411275 } else
1082511276 {
1082611277 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -10831,7 +11282,7 @@
1083111282 //System.out.println("BLENDING ON");
1083211283 gl.glEnable(GL.GL_BLEND);
1083311284 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
10834
-
11285
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1083511286 gl.glMatrixMode(gl.GL_PROJECTION);
1083611287 gl.glLoadIdentity();
1083711288
....@@ -10920,8 +11371,8 @@
1092011371 System.err.println("parentcam != renderCamera");
1092111372
1092211373 // if (cam != lightCamera)
10923
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10924
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11374
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11375
+ LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
1092511376 }
1092611377
1092711378 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -10942,8 +11393,8 @@
1094211393 if (true) // TODO
1094311394 {
1094411395 if (cam != lightCamera)
10945
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10946
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11396
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11397
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
1094711398 }
1094811399
1094911400 LA.xformPos(light0, cam.toScreen, light0);
....@@ -11080,7 +11531,7 @@
1108011531 }
1108111532 }
1108211533
11083
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11534
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1108411535 {
1108511536 //gl.glDepthFunc(GL.GL_LEQUAL);
1108611537 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11088,24 +11539,21 @@
1108811539
1108911540 boolean texon = textureon;
1109011541
11091
- if (RENDERPROGRAM > 0)
11092
- {
11093
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11094
- textureon = false;
11095
- }
11542
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11543
+ textureon = false;
11544
+
1109611545 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1109711546 //System.out.println("ALLO");
1109811547 gl.glColorMask(false, false, false, false);
1109911548 DrawObject(gl);
11100
- if (RENDERPROGRAM > 0)
11101
- {
11102
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11103
- textureon = texon;
11104
- }
11549
+
11550
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11551
+ textureon = texon;
11552
+
1110511553 gl.glColorMask(true, true, true, true);
1110611554
1110711555 gl.glDepthFunc(GL.GL_EQUAL);
11108
- //gl.glDepthMask(false);
11556
+ gl.glDepthMask(false);
1110911557 }
1111011558
1111111559 if (false) // DrawMode() == SHADOW)
....@@ -11259,8 +11707,14 @@
1125911707 {
1126011708 renderpass++;
1126111709 // System.out.println("Draw object... ");
11710
+ STEP = 1;
1126211711 if (FAST) // in case there is no script
11263
- STEP = 16;
11712
+ STEP = 8;
11713
+
11714
+ if (CURRENTANTIALIAS == 0 || ACSIZE == 1)
11715
+ {
11716
+ STEP *= 4;
11717
+ }
1126411718
1126511719 //object.FullInvariants();
1126611720
....@@ -11274,23 +11728,44 @@
1127411728 e.printStackTrace();
1127511729 }
1127611730
11277
- if (GrafreeD.RENDERME > 0)
11278
- GrafreeD.RENDERME--; // mechante magouille
11731
+ if (Grafreed.RENDERME > 0)
11732
+ Grafreed.RENDERME--; // mechante magouille
1127911733
1128011734 Globals.ONESTEP = false;
1128111735 }
1128211736
1128311737 static boolean zoomonce = false;
1128411738
11739
+ static void CreateSelectedPoint()
11740
+ {
11741
+ if (selectedpoint == null)
11742
+ {
11743
+ debugpointG = new Sphere();
11744
+ debugpointP = new Sphere();
11745
+ debugpointC = new Sphere();
11746
+ debugpointR = new Sphere();
11747
+
11748
+ selectedpoint = new Superellipsoid();
11749
+
11750
+ for (int i=0; i<8; i++)
11751
+ {
11752
+ debugpoints[i] = new Sphere();
11753
+ }
11754
+ }
11755
+ }
11756
+
1128511757 void DrawObject(GL gl, boolean draw)
1128611758 {
11759
+ // To clear camera values
11760
+ ResetOptions();
11761
+
1128711762 //System.out.println("DRAW OBJECT " + mouseDown);
1128811763 // DrawMode() = SELECTION;
1128911764 //GL gl = getGL();
1129011765 if ((TRACK || SHADOWTRACK) || zoomonce)
1129111766 {
1129211767 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11293
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11768
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1129411769 pingthread.StepToTarget(true); // true);
1129511770 // zoomonce = false;
1129611771 }
....@@ -11345,7 +11820,14 @@
1134511820
1134611821 usedtextures.clear();
1134711822
11348
- BindTextures(DEFAULT_TEXTURES, 2);
11823
+ try
11824
+ {
11825
+ BindTextures(DEFAULT_TEXTURES, 2);
11826
+ }
11827
+ catch (Exception e)
11828
+ {
11829
+ System.err.println("FAILED: " + DEFAULT_TEXTURES);
11830
+ }
1134911831 }
1135011832 //System.out.println("--> " + stackdepth);
1135111833 // GrafreeD.traceon();
....@@ -11355,8 +11837,9 @@
1135511837
1135611838 if (DrawMode() == DEFAULT)
1135711839 {
11358
- if (DEBUG)
11840
+ if (Globals.DEBUG)
1135911841 {
11842
+ CreateSelectedPoint();
1136011843 float radius = 0.05f;
1136111844 if (selectedpoint.radius != radius)
1136211845 {
....@@ -11410,20 +11893,32 @@
1141011893 ReleaseTextures(DEFAULT_TEXTURES);
1141111894
1141211895 if (CLEANCACHE)
11413
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11896
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1141411897 {
11415
- String tex = e.nextElement();
11898
+ cTexture tex = e.nextElement();
1141611899
1141711900 // System.out.println("Texture --------- " + tex);
1141811901
11419
- if (tex.equals("WHITE_NOISE"))
11902
+ if (tex.equals("WHITE_NOISE:"))
1142011903 continue;
1142111904
11422
- if (!usedtextures.containsKey(tex))
11905
+ if (!usedtextures.contains(tex))
1142311906 {
11907
+ CacheTexture gettex = texturepigment.get(tex);
1142411908 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11425
- textures.get(tex).texture.dispose();
11426
- textures.remove(tex);
11909
+ if (gettex != null)
11910
+ {
11911
+ gettex.texture.dispose();
11912
+ texturepigment.remove(tex);
11913
+ }
11914
+
11915
+ gettex = texturebump.get(tex);
11916
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11917
+ if (gettex != null)
11918
+ {
11919
+ gettex.texture.dispose();
11920
+ texturebump.remove(tex);
11921
+ }
1142711922 }
1142811923 }
1142911924 }
....@@ -11436,7 +11931,14 @@
1143611931 if (checker != null && DrawMode() == DEFAULT)
1143711932 {
1143811933 //BindTexture(IMMORTAL_TEXTURE);
11439
- BindTextures(checker.GetTextures(), checker.texres);
11934
+ try
11935
+ {
11936
+ BindTextures(checker.GetTextures(), checker.texres);
11937
+ }
11938
+ catch (Exception e)
11939
+ {
11940
+ System.err.println("FAILED: " + checker.GetTextures());
11941
+ }
1144011942 // NEAREST
1144111943 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
1144211944 DrawChecker(gl);
....@@ -11518,7 +12020,7 @@
1151812020 return;
1151912021 }
1152012022
11521
- String string = obj.GetToolTip();
12023
+ String string = obj.toString(); //.GetToolTip();
1152212024
1152312025 GL gl = GetGL();
1152412026
....@@ -11835,8 +12337,8 @@
1183512337 //obj.TransformToWorld(light, light);
1183612338 for (int i = tp.size(); --i >= 0;)
1183712339 {
11838
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
11839
- LA.xformPos(light, tp.get(i).toParent, light);
12340
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12341
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1184012342 }
1184112343
1184212344
....@@ -11853,8 +12355,8 @@
1185312355 parentcam = cameras[0];
1185412356 }
1185512357
11856
- for (int count = parentcam.GetTransformCount(); --count>=0;)
11857
- LA.xformPos(light, parentcam.toParent, light); // may 2013
12358
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
12359
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1185812360
1185912361 LA.xformPos(light, renderCamera.toScreen, light);
1186012362
....@@ -11944,8 +12446,76 @@
1194412446
1194512447 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1194612448
12449
+ String program0 =
12450
+ // Min shader
12451
+ "!!ARBfp1.0\n" +
12452
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12453
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12454
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12455
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12456
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12457
+ "PARAM light2cam0 = program.env[10];" +
12458
+ "PARAM light2cam1 = program.env[11];" +
12459
+ "PARAM light2cam2 = program.env[12];" +
12460
+ "TEMP temp;" +
12461
+ "TEMP light;" +
12462
+ "TEMP ndotl;" +
12463
+ "TEMP normal;" +
12464
+ "TEMP depth;" +
12465
+ "TEMP eye;" +
12466
+ "TEMP pos;" +
12467
+
12468
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12469
+ Normalize("normal") +
12470
+ "MOV light, state.light[0].position;" +
12471
+ "DP3 ndotl.x, light, normal;" +
12472
+
12473
+ // shadow
12474
+ "MOV pos, fragment.texcoord[1];" +
12475
+ "MOV temp, pos;" +
12476
+ ShadowTextureFetch("depth", "temp", "1") +
12477
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12478
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12479
+
12480
+ // No shadow when out of frustum
12481
+ //"SGE temp.y, depth.z, zero123.y;" +
12482
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12483
+
12484
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12485
+
12486
+ // Backlit
12487
+ "MOV pos.w, zero123.y;" +
12488
+ "DP4 eye.x, pos, light2cam0;" +
12489
+ "DP4 eye.y, pos, light2cam1;" +
12490
+ "DP4 eye.z, pos, light2cam2;" +
12491
+ Normalize("eye") +
12492
+
12493
+ "DP3 ndotl.y, -eye, normal;" +
12494
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12495
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12496
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12497
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12498
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12499
+
12500
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12501
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12502
+
12503
+ // Pigment
12504
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12505
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12506
+ "MUL temp, temp, ndotl.x;" +
12507
+
12508
+ "MUL temp, temp, zero123.z;" +
12509
+
12510
+ //"MUL temp, temp, ndotl.y;" +
12511
+
12512
+ "MOV temp.w, zero123.y;" + // reset alpha
12513
+ "MOV result.color, temp;" +
12514
+ "END";
12515
+
1194712516 String program =
1194812517 "!!ARBfp1.0\n" +
12518
+
1194912519 //"OPTION ARB_fragment_program_shadow;" +
1195012520 "PARAM light2cam0 = program.env[10];" +
1195112521 "PARAM light2cam1 = program.env[11];" +
....@@ -12060,8 +12630,7 @@
1206012630 "TEMP shininess;" +
1206112631 "\n" +
1206212632 "MOV texSamp, one;" +
12063
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12064
-
12633
+
1206512634 "MOV mapgrid.x, one2048th.x;" +
1206612635 "MOV temp, fragment.texcoord[1];" +
1206712636 /*
....@@ -12082,20 +12651,20 @@
1208212651 "MUL temp, floor, mapgrid.x;" +
1208312652 //"TEX depth0, temp, texture[1], 2D;" +
1208412653 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12085
- TextureFetch("depth0", "temp", "1") +
12654
+ ShadowTextureFetch("depth0", "temp", "1") +
1208612655 "") +
1208712656 "ADD temp.x, temp.x, mapgrid.x;" +
1208812657 //"TEX depth1, temp, texture[1], 2D;" +
1208912658 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12090
- TextureFetch("depth1", "temp", "1") +
12659
+ ShadowTextureFetch("depth1", "temp", "1") +
1209112660 "") +
1209212661 "ADD temp.y, temp.y, mapgrid.x;" +
1209312662 //"TEX depth2, temp, texture[1], 2D;" +
12094
- TextureFetch("depth2", "temp", "1") +
12663
+ ShadowTextureFetch("depth2", "temp", "1") +
1209512664 "SUB temp.x, temp.x, mapgrid.x;" +
1209612665 //"TEX depth3, temp, texture[1], 2D;" +
1209712666 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12098
- TextureFetch("depth3", "temp", "1") +
12667
+ ShadowTextureFetch("depth3", "temp", "1") +
1209912668 "") +
1210012669 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1210112670 //"MOV params, material;" +
....@@ -12466,10 +13035,10 @@
1246613035 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1246713036 "") +
1246813037
12469
- // display shadow only (bump == 0)
13038
+ // display shadow only (fakedepth == 0)
1247013039 "SUB temp.x, half.x, shadow.x;" +
12471
- "MOV temp.y, -params6.x;" +
12472
- "SLT temp.z, temp.y, zero.x;" +
13040
+ "MOV temp.y, -params5.z;" + // params6.x;" +
13041
+ "SLT temp.z, temp.y, -c256i.x;" +
1247313042 "SUB temp.y, one.x, temp.z;" +
1247413043 "MUL temp.x, temp.x, temp.y;" +
1247513044 "KIL temp.x;" +
....@@ -12598,8 +13167,10 @@
1259813167 "MAX ndotl.x, ndotl.x, -ndotl.x;" +
1259913168
1260013169 "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
13170
+ // Tuning for default skin
13171
+ //"ADD temp.x, temp.x, options2.z;" + // lightsheen
13172
+ "MAD temp.x, options2.z, half.y, temp.x;" + // lightsheen
13173
+ "ADD temp.y, one.y, options2.y;" + // subsurface
1260313174 "MUL temp.x, temp.x, temp.y;" +
1260413175
1260513176 "MUL saturation, saturation, temp.xxxx;" +
....@@ -12747,7 +13318,7 @@
1274713318 "MUL final.y, fragment.texcoord[0].x, c256;" +
1274813319 "FLR final.x, final.y;" +
1274913320 "SUB final.y, final.y, final.x;" +
12750
- //"MUL final.x, final.x, c256i;" +
13321
+ "MUL final.x, final.x, c256i;" +
1275113322 "MOV final.z, zero.x;" +
1275213323 "MOV final.a, one.w;":""
1275313324 ) +
....@@ -12755,7 +13326,7 @@
1275513326 "MUL final.y, fragment.texcoord[0].y, c256;" +
1275613327 "FLR final.x, final.y;" +
1275713328 "SUB final.y, final.y, final.x;" +
12758
- //"MUL final.x, final.x, c256i;" +
13329
+ "MUL final.x, final.x, c256i;" +
1275913330 "MOV final.z, zero.x;" +
1276013331 "MOV final.a, one.w;":""
1276113332 ) +
....@@ -12798,7 +13369,7 @@
1279813369 //once = true;
1279913370 }
1280013371
12801
- System.out.print("Program #" + mode + "; length = " + program.length());
13372
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1280213373 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1280313374 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1280413375
....@@ -12891,25 +13462,26 @@
1289113462 return out;
1289213463 }
1289313464
12894
- String TextureFetch(String dest, String src, String unit)
13465
+ // Also does frustum culling
13466
+ String ShadowTextureFetch(String dest, String src, String unit)
1289513467 {
1289613468 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1289713469 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1289813470 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13471
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13472
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1289913473 "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;" +
13474
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13475
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1290413476 //"SWZ buffer, temp, w,w,w,w;";
12905
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13477
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1290613478 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1290713479 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1290813480 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
12909
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13481
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1291013482
12911
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
12912
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13483
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13484
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1291313485 }
1291413486
1291513487 String Shadow(String depth, String shadow)
....@@ -12931,12 +13503,16 @@
1293113503
1293213504 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1293313505 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13506
+
13507
+ // Compare fragment depth in light space with shadowmap.
1293413508 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1293513509 "SGE temp.y, temp.x, zero.x;" +
12936
- "SUB " + shadow + ".y, one.x, temp.y;" +
13510
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13511
+
13512
+ // Reverse comparison
1293713513 "SUB temp.x, one.x, temp.x;" +
1293813514 "MUL " + shadow + ".x, temp.x, temp.y;" +
12939
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13515
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1294013516 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1294113517
1294213518 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -12950,6 +13526,10 @@
1295013526 // No shadow for backface
1295113527 "DP3 temp.x, normal, lightd;" +
1295213528 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13529
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13530
+
13531
+ // No shadow when out of frustum
13532
+ "SGE temp.x, " + depth + ".z, one.z;" +
1295313533 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1295413534 "";
1295513535 }
....@@ -13096,7 +13676,8 @@
1309613676 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1309713677 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1309813678 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13099
- Object3D.cVector2[] vector2buffer;
13679
+
13680
+ //Object3D.cVector2[] vector2buffer;
1310013681
1310113682 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1310213683 // OUT : diff, spec
....@@ -13112,9 +13693,10 @@
1311213693 "DP3 " + dest + ".z," + "normals," + "eye;" +
1311313694 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1311413695 //"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;" +
13696
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13697
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13698
+
13699
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1311813700 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1311913701 "RCP " + dest + ".w," + dest + ".w;" +
1312013702 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13508,7 +14090,7 @@
1350814090 public void mousePressed(MouseEvent e)
1350914091 {
1351014092 //System.out.println("mousePressed: " + e);
13511
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14093
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1351214094 }
1351314095
1351414096 static long prevtime = 0;
....@@ -13584,8 +14166,8 @@
1358414166 // mode |= META;
1358514167 //}
1358614168
13587
- SetMouseMode(WHEEL | e.getModifiersEx());
13588
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14169
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14170
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1358914171 anchorX = ax;
1359014172 anchorY = ay;
1359114173 prevX = px;
....@@ -13619,6 +14201,7 @@
1361914201 else
1362014202 if (evt.getSource() == AAtimer)
1362114203 {
14204
+ Globals.TIMERRUNNING = false;
1362214205 if (mouseDown)
1362314206 {
1362414207 //new Exception().printStackTrace();
....@@ -13644,6 +14227,10 @@
1364414227 // LIVE = waslive;
1364514228 // wasliveok = true;
1364614229 // waslive = false;
14230
+
14231
+ // May 2019 Forget it:
14232
+ if (true)
14233
+ return;
1364714234
1364814235 // source == timer
1364914236 if (mouseDown)
....@@ -13674,7 +14261,7 @@
1367414261
1367514262 // fev 2014???
1367614263 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13677
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14264
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1367814265 pingthread.StepToTarget(true); // true);
1367914266 }
1368014267 // if (!LIVE)
....@@ -13683,12 +14270,13 @@
1368314270
1368414271 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1368514272
13686
- void clickStart(int x, int y, int modifiers)
14273
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1368714274 {
1368814275 if (!wasliveok)
1368914276 return;
1369014277
1369114278 AAtimer.restart(); //
14279
+ Globals.TIMERRUNNING = true;
1369214280
1369314281 // waslive = LIVE;
1369414282 // LIVE = false;
....@@ -13700,7 +14288,7 @@
1370014288 // touched = true; // main DL
1370114289 if (isRenderer)
1370214290 {
13703
- SetMouseMode(modifiers);
14291
+ SetMouseMode(modifiers, modifiersex);
1370414292 }
1370514293
1370614294 selectX = anchorX = x;
....@@ -13713,7 +14301,7 @@
1371314301 clicked = true;
1371414302 hold = false;
1371514303
13716
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14304
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1371714305 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1371814306 {
1371914307 // System.out.println("RESTART II " + modifiers);
....@@ -13738,14 +14326,15 @@
1373814326 drag = false;
1373914327 //System.out.println("Mouse DOWN");
1374014328 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);
14329
+ //ClickInfo info = new ClickInfo();
14330
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14331
+ object.clickInfo.pane = this;
14332
+ object.clickInfo.camera = renderCamera;
14333
+ object.clickInfo.x = x;
14334
+ object.clickInfo.y = y;
14335
+ object.clickInfo.modifiers = modifiersex;
14336
+ editObj = object.doEditClick(//info,
14337
+ 0);
1374914338 if (!editObj)
1375014339 {
1375114340 hasMarquee = true;
....@@ -13761,9 +14350,12 @@
1376114350
1376214351 public void mouseDragged(MouseEvent e)
1376314352 {
14353
+ Globals.MOUSEDRAGGED = true;
14354
+
1376414355 //System.out.println("mouseDragged: " + e);
1376514356 if (isRenderer)
1376614357 movingcamera = true;
14358
+
1376714359 //if (drawing)
1376814360 //return;
1376914361 if ((e.getModifiersEx() & CTRL) != 0
....@@ -13773,7 +14365,7 @@
1377314365 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1377414366 }
1377514367 else
13776
- drag(e.getX(), e.getY(), e.getModifiersEx());
14368
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1377714369
1377814370 //try { Thread.sleep(1); } catch (Exception ex) {}
1377914371 }
....@@ -13946,6 +14538,7 @@
1394614538
1394714539 public void run()
1394814540 {
14541
+ new Exception().printStackTrace();
1394914542 System.exit(0);
1395014543 for (;;)
1395114544 {
....@@ -14009,7 +14602,7 @@
1400914602 {
1401014603 Globals.lighttouched = true;
1401114604 }
14012
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14605
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1401314606 }
1401414607 //else
1401514608 }
....@@ -14023,12 +14616,12 @@
1402314616 void GoDown(int mod)
1402414617 {
1402514618 MODIFIERS |= COMMAND;
14026
- /*
14619
+ /**/
1402714620 if((mod&SHIFT) == SHIFT)
1402814621 manipCamera.RotatePosition(0, -speed);
1402914622 else
14030
- manipCamera.BackForth(0, -speed*delta, getWidth());
14031
- */
14623
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14624
+ /**/
1403214625 if ((mod & SHIFT) == SHIFT)
1403314626 {
1403414627 mouseMode = mouseMode; // VR??
....@@ -14044,12 +14637,12 @@
1404414637 void GoUp(int mod)
1404514638 {
1404614639 MODIFIERS |= COMMAND;
14047
- /*
14640
+ /**/
1404814641 if((mod&SHIFT) == SHIFT)
1404914642 manipCamera.RotatePosition(0, speed);
1405014643 else
14051
- manipCamera.BackForth(0, speed*delta, getWidth());
14052
- */
14644
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14645
+ /**/
1405314646 if ((mod & SHIFT) == SHIFT)
1405414647 {
1405514648 mouseMode = mouseMode;
....@@ -14065,12 +14658,12 @@
1406514658 void GoLeft(int mod)
1406614659 {
1406714660 MODIFIERS |= COMMAND;
14068
- /*
14661
+ /**/
1406914662 if((mod&SHIFT) == SHIFT)
14070
- manipCamera.RotatePosition(speed, 0);
14071
- else
1407214663 manipCamera.Translate(speed*delta, 0, getWidth());
14073
- */
14664
+ else
14665
+ manipCamera.RotatePosition(speed, 0);
14666
+ /**/
1407414667 if ((mod & SHIFT) == SHIFT)
1407514668 {
1407614669 mouseMode = mouseMode;
....@@ -14086,12 +14679,12 @@
1408614679 void GoRight(int mod)
1408714680 {
1408814681 MODIFIERS |= COMMAND;
14089
- /*
14682
+ /**/
1409014683 if((mod&SHIFT) == SHIFT)
14091
- manipCamera.RotatePosition(-speed, 0);
14092
- else
1409314684 manipCamera.Translate(-speed*delta, 0, getWidth());
14094
- */
14685
+ else
14686
+ manipCamera.RotatePosition(-speed, 0);
14687
+ /**/
1409514688 if ((mod & SHIFT) == SHIFT)
1409614689 {
1409714690 mouseMode = mouseMode;
....@@ -14109,7 +14702,7 @@
1410914702 int X, Y;
1411014703 boolean SX, SY;
1411114704
14112
- void drag(int x, int y, int modifiers)
14705
+ void drag(int x, int y, int modifiers, int modifiersex)
1411314706 {
1411414707 if (IsFrozen())
1411514708 {
....@@ -14118,17 +14711,17 @@
1411814711
1411914712 drag = true; // NEW
1412014713
14121
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14714
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1412214715
1412314716 X = x;
1412414717 Y = y;
1412514718 // floating state for animation
14126
- MODIFIERS = modifiers;
14127
- modifiers &= ~1024;
14719
+ MODIFIERS = modifiersex;
14720
+ modifiersex &= ~1024;
1412814721 if (false) // modifiers != 0)
1412914722 {
1413014723 //new Exception().printStackTrace();
14131
- System.out.println("mouseDragged: " + modifiers);
14724
+ System.out.println("mouseDragged: " + modifiersex);
1413214725 System.out.println("SHIFT = " + SHIFT);
1413314726 System.out.println("CONTROL = " + COMMAND);
1413414727 System.out.println("META = " + META);
....@@ -14141,14 +14734,16 @@
1414114734 if (editObj)
1414214735 {
1414314736 drag = true;
14144
- ClickInfo info = new ClickInfo();
14145
- info.bounds.setBounds(0, 0,
14737
+ //ClickInfo info = new ClickInfo();
14738
+ object.clickInfo.bounds.setBounds(0, 0,
1414614739 (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);
14740
+ object.clickInfo.pane = this;
14741
+ object.clickInfo.camera = renderCamera;
14742
+ object.clickInfo.x = x;
14743
+ object.clickInfo.y = y;
14744
+ object //.GetWindow().copy
14745
+ .doEditDrag(//info,
14746
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1415214747 } else
1415314748 {
1415414749 if (x < startX)
....@@ -14297,22 +14892,27 @@
1429714892 }
1429814893 }
1429914894
14895
+// ClickInfo clickInfo = new ClickInfo();
14896
+
1430014897 public void mouseMoved(MouseEvent e)
1430114898 {
1430214899 //System.out.println("mouseMoved: " + e);
1430314900 if (isRenderer)
1430414901 return;
1430514902
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;
14903
+ // Mouse cursor feedback
14904
+ object.clickInfo.x = e.getX();
14905
+ object.clickInfo.y = e.getY();
14906
+ object.clickInfo.modifiers = e.getModifiersEx();
14907
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14908
+ object.clickInfo.pane = this;
14909
+ object.clickInfo.camera = renderCamera;
1431314910 if (!isRenderer)
1431414911 {
14315
- if (object.editWindow.copy.doEditClick(ci, 0))
14912
+ //ObjEditor editWindow = object.editWindow;
14913
+ //Object3D copy = editWindow.copy;
14914
+ if (object.doEditClick(//clickInfo,
14915
+ 0))
1431614916 {
1431714917 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1431814918 } else
....@@ -14324,7 +14924,11 @@
1432414924
1432514925 public void mouseReleased(MouseEvent e)
1432614926 {
14927
+ Globals.MOUSEDRAGGED = false;
14928
+
1432714929 movingcamera = false;
14930
+ X = 0; // getBounds().width/2;
14931
+ Y = 0; // getBounds().height/2;
1432814932 //System.out.println("mouseReleased: " + e);
1432914933 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1433014934 }
....@@ -14347,9 +14951,9 @@
1434714951 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1434814952 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1434914953
14350
- if (control || command || IsFrozen())
14954
+// No delay if (control || command || IsFrozen())
1435114955 timeout = true;
14352
- else
14956
+// ?? May 2019 else
1435314957 // timer.setDelay((modifiers & 128) != 0?0:350);
1435414958 mouseDown = false;
1435514959 if (!control && !command) // june 2013
....@@ -14459,7 +15063,7 @@
1445915063 System.out.println("keyReleased: " + e);
1446015064 }
1446115065
14462
- void SetMouseMode(int modifiers)
15066
+ void SetMouseMode(int modifiers, int modifiersex)
1446315067 {
1446415068 //System.out.println("SetMouseMode = " + modifiers);
1446515069 //modifiers &= ~1024;
....@@ -14471,25 +15075,25 @@
1447115075 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1447215076 // return;
1447315077 //System.out.println("SetMode = " + modifiers);
14474
- if ((modifiers & WHEEL) == WHEEL)
15078
+ if ((modifiersex & WHEEL) == WHEEL)
1447515079 {
1447615080 mouseMode |= ZOOM;
1447715081 }
1447815082
1447915083 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
14480
- if (capsLocked || (modifiers & META) == META)
15084
+ if (capsLocked) // || (modifiers & META) == META)
1448115085 {
1448215086 mouseMode |= VR; // BACKFORTH;
1448315087 }
14484
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
15088
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1448515089 {
1448615090 mouseMode |= SELECT;
1448715091 }
14488
- if ((modifiers & COMMAND) == COMMAND)
15092
+ if ((modifiersex & COMMAND) == COMMAND)
1448915093 {
1449015094 mouseMode |= SELECT;
1449115095 }
14492
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15096
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
1449315097 {
1449415098 mouseMode &= ~VR;
1449515099 mouseMode |= TRANSLATE;
....@@ -14518,7 +15122,7 @@
1451815122
1451915123 if (isRenderer) //
1452015124 {
14521
- SetMouseMode(modifiers);
15125
+ SetMouseMode(0, modifiers);
1452215126 }
1452315127
1452415128 Globals.theRenderer.keyPressed(key);
....@@ -14580,7 +15184,8 @@
1458015184 // break;
1458115185 case 'T':
1458215186 CACHETEXTURE ^= true;
14583
- textures.clear();
15187
+ texturepigment.clear();
15188
+ texturebump.clear();
1458415189 // repaint();
1458515190 break;
1458615191 case 'Y':
....@@ -14665,7 +15270,9 @@
1466515270 case 'E' : COMPACT ^= true;
1466615271 repaint();
1466715272 break;
14668
- case 'W' : DEBUGHSB ^= true;
15273
+ case 'W' : // Wide Window (fullscreen)
15274
+ //DEBUGHSB ^= true;
15275
+ ObjEditor.theFrame.ToggleFullScreen();
1466915276 repaint();
1467015277 break;
1467115278 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14690,8 +15297,8 @@
1469015297 RevertCamera();
1469115298 repaint();
1469215299 break;
14693
- case 'L':
1469415300 case 'l':
15301
+ //case 'L':
1469515302 if (lightMode)
1469615303 {
1469715304 lightMode = false;
....@@ -14761,14 +15368,18 @@
1476115368 case '3':
1476215369 case '4':
1476315370 case '5':
14764
- newenvy = Character.getNumericValue(key);
14765
- repaint();
14766
- break;
1476715371 case '6':
1476815372 case '7':
1476915373 case '8':
1477015374 case '9':
14771
- BGcolor = (key - '6')/3.f;
15375
+ if (envyoff)
15376
+ {
15377
+ BGcolor = (key - '1')/8.f;
15378
+ }
15379
+ else
15380
+ {
15381
+ //newenvy = Character.getNumericValue(key);
15382
+ }
1477215383 repaint();
1477315384 break;
1477415385 case '!':
....@@ -14834,9 +15445,9 @@
1483415445 case '_':
1483515446 kompactbit = 5;
1483615447 break;
14837
- case '+':
14838
- kompactbit = 6;
14839
- break;
15448
+// case '+':
15449
+// kompactbit = 6;
15450
+// break;
1484015451 case ' ':
1484115452 lightMode ^= true;
1484215453 Globals.lighttouched = true;
....@@ -14848,13 +15459,14 @@
1484815459 case ESC:
1484915460 RENDERPROGRAM += 1;
1485015461 RENDERPROGRAM %= 3;
15462
+
1485115463 repaint();
1485215464 break;
1485315465 case 'Z':
1485415466 //RESIZETEXTURE ^= true;
1485515467 //break;
1485615468 case 'z':
14857
- RENDERSHADOW ^= true;
15469
+ Globals.RENDERSHADOW ^= true;
1485815470 Globals.lighttouched = true;
1485915471 repaint();
1486015472 break;
....@@ -14887,8 +15499,9 @@
1488715499 case DELETE:
1488815500 ClearSelection();
1488915501 break;
14890
- /*
1489115502 case '+':
15503
+
15504
+ /*
1489215505 //fontsize += 1;
1489315506 bbzoom *= 2;
1489415507 repaint();
....@@ -14905,17 +15518,17 @@
1490515518 case '=':
1490615519 IncDepth();
1490715520 //fontsize += 1;
14908
- object.editWindow.refreshContents(true);
15521
+ object.GetWindow().refreshContents(true);
1490915522 maskbit = 6;
1491015523 break;
1491115524 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1491215525 DecDepth();
1491315526 maskbit = 5;
1491415527 //if(fontsize > 1) fontsize -= 1;
14915
- if (object.editWindow == null)
14916
- new Exception().printStackTrace();
14917
- else
14918
- object.editWindow.refreshContents(true);
15528
+// if (object.editWindow == null)
15529
+// new Exception().printStackTrace();
15530
+// else
15531
+ object.GetWindow().refreshContents(true);
1491915532 break;
1492015533 case '{':
1492115534 manipCamera.shaper_fovy /= 1.1;
....@@ -14978,7 +15591,7 @@
1497815591 //mode = ROTATE;
1497915592 if ((MODIFIERS & COMMAND) == 0) // VR??
1498015593 {
14981
- SetMouseMode(modifiers);
15594
+ SetMouseMode(0, modifiers);
1498215595 }
1498315596 }
1498415597
....@@ -15114,7 +15727,7 @@
1511415727 {
1511515728 //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
1511615729 //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15117
- if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (mouseMode & SELECT) == 0)
15730
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1511815731 {
1511915732 mouseMoved(e);
1512015733 } else
....@@ -15139,11 +15752,12 @@
1513915752 }
1514015753 */
1514115754
15142
- object.editWindow.EditSelection();
15755
+ object.GetWindow().EditSelection(false);
1514315756 }
1514415757
1514515758 void SelectParent()
1514615759 {
15760
+ new Exception().printStackTrace();
1514715761 System.exit(0);
1514815762 Composite group = (Composite) object;
1514915763 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -15155,10 +15769,10 @@
1515515769 {
1515615770 //selectees.remove(i);
1515715771 System.out.println("select parent of " + elem);
15158
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15772
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1515915773 } else
1516015774 {
15161
- group.editWindow.Select(elem.GetTreePath(), first, true);
15775
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1516215776 }
1516315777
1516415778 first = false;
....@@ -15167,6 +15781,7 @@
1516715781
1516815782 void SelectChildren()
1516915783 {
15784
+ new Exception().printStackTrace();
1517015785 System.exit(0);
1517115786 /*
1517215787 Composite group = (Composite) object;
....@@ -15199,12 +15814,12 @@
1519915814 for (int j = 0; j < group.children.size(); j++)
1520015815 {
1520115816 elem = (Object3D) group.children.elementAt(j);
15202
- object.editWindow.Select(elem.GetTreePath(), first, true);
15817
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1520315818 first = false;
1520415819 }
1520515820 } else
1520615821 {
15207
- object.editWindow.Select(elem.GetTreePath(), first, true);
15822
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1520815823 }
1520915824
1521015825 first = false;
....@@ -15215,21 +15830,21 @@
1521515830 {
1521615831 //Composite group = (Composite) object;
1521715832 Object3D group = object;
15218
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15833
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1521915834 }
1522015835
1522115836 void ResetTransform(int mask)
1522215837 {
1522315838 //Composite group = (Composite) object;
1522415839 Object3D group = object;
15225
- group.editWindow.ResetTransform(mask);
15840
+ group.GetWindow().ResetTransform(mask);
1522615841 }
1522715842
1522815843 void FlipTransform()
1522915844 {
1523015845 //Composite group = (Composite) object;
1523115846 Object3D group = object;
15232
- group.editWindow.FlipTransform();
15847
+ group.GetWindow().FlipTransform();
1523315848 // group.editWindow.ReduceMesh(true);
1523415849 }
1523515850
....@@ -15237,7 +15852,7 @@
1523715852 {
1523815853 //Composite group = (Composite) object;
1523915854 Object3D group = object;
15240
- group.editWindow.PrintMemory();
15855
+ group.GetWindow().PrintMemory();
1524115856 // group.editWindow.ReduceMesh(true);
1524215857 }
1524315858
....@@ -15245,7 +15860,7 @@
1524515860 {
1524615861 //Composite group = (Composite) object;
1524715862 Object3D group = object;
15248
- group.editWindow.ResetCentroid();
15863
+ group.GetWindow().ResetCentroid();
1524915864 }
1525015865
1525115866 void IncDepth()
....@@ -15327,11 +15942,11 @@
1532715942
1532815943 int width = getBounds().width;
1532915944 int height = getBounds().height;
15330
- ClickInfo info = new ClickInfo();
15331
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1533215945 //Image img = CreateImage(width, height);
1533315946 //System.out.println("width = " + width + "; height = " + height + "\n");
15947
+
1533415948 Graphics gr = g; // img.getGraphics();
15949
+
1533515950 if (!hasMarquee)
1533615951 {
1533715952 if (Xmin < Xmax) // !locked)
....@@ -15403,40 +16018,88 @@
1540316018 }
1540416019 if (object != null && !hasMarquee)
1540516020 {
16021
+ if (object.clickInfo == null)
16022
+ object.clickInfo = new ClickInfo();
16023
+ ClickInfo info = object.clickInfo;
16024
+ //ClickInfo info = new ClickInfo();
16025
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16026
+
1540616027 if (isRenderer)
1540716028 {
15408
- info.flags++;
16029
+ object.clickInfo.flags++;
1540916030 double frameAspect = (double) width / (double) height;
1541016031 if (frameAspect > renderCamera.aspect)
1541116032 {
1541216033 int desired = (int) ((double) height * renderCamera.aspect);
15413
- info.bounds.width -= width - desired;
15414
- info.bounds.x += (width - desired) / 2;
16034
+ object.clickInfo.bounds.width -= width - desired;
16035
+ object.clickInfo.bounds.x += (width - desired) / 2;
1541516036 } else
1541616037 {
1541716038 int desired = (int) ((double) width / renderCamera.aspect);
15418
- info.bounds.height -= height - desired;
15419
- info.bounds.y += (height - desired) / 2;
16039
+ object.clickInfo.bounds.height -= height - desired;
16040
+ object.clickInfo.bounds.y += (height - desired) / 2;
1542016041 }
1542116042 }
15422
- info.g = gr;
15423
- info.camera = renderCamera;
16043
+
16044
+ object.clickInfo.g = gr;
16045
+ object.clickInfo.camera = renderCamera;
1542416046 /*
1542516047 // Memory intensive (brep.verticescopy)
1542616048 if (!(object instanceof Composite))
1542716049 object.draw(info, 0, false); // SLOW :
1542816050 */
15429
- if (!isRenderer)
16051
+ if (!isRenderer) // && drag)
1543016052 {
15431
- object.drawEditHandles(info, 0);
16053
+ Grafreed.Assert(object != null);
16054
+ Grafreed.Assert(object.selection != null);
16055
+ if (object.selection.Size() > 0)
16056
+ {
16057
+ int hitSomething = object.selection.get(0).hitSomething;
16058
+
16059
+ object.clickInfo.DX = 0;
16060
+ object.clickInfo.DY = 0;
16061
+ object.clickInfo.W = 1;
16062
+ if (hitSomething == Object3D.hitCenter)
16063
+ {
16064
+ info.DX = X;
16065
+ if (X != 0)
16066
+ info.DX -= info.bounds.width/2;
16067
+
16068
+ info.DY = Y;
16069
+ if (Y != 0)
16070
+ info.DY -= info.bounds.height/2;
16071
+ }
16072
+
16073
+ object.drawEditHandles(//info,
16074
+ 0);
16075
+
16076
+ if (drag && (X != 0 || Y != 0))
16077
+ {
16078
+ switch (hitSomething)
16079
+ {
16080
+ case Object3D.hitCenter: gr.setColor(Color.pink);
16081
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16082
+ break;
16083
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16084
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16085
+ break;
16086
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16087
+ gr.drawLine(X, Y, 0, 0);
16088
+ break;
16089
+ }
16090
+
16091
+ }
16092
+ }
1543216093 }
1543316094 }
16095
+
1543416096 if (isRenderer)
1543516097 {
1543616098 //gr.setColor(Color.black);
1543716099 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1543816100 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1543916101 }
16102
+
1544016103 if (hasMarquee)
1544116104 {
1544216105 gr.setXORMode(Color.white);
....@@ -15549,6 +16212,7 @@
1554916212 public boolean mouseDown(Event evt, int x, int y)
1555016213 {
1555116214 System.out.println("mouseDown: " + evt);
16215
+ System.exit(0);
1555216216 /*
1555316217 locked = true;
1555416218 drag = false;
....@@ -15592,7 +16256,7 @@
1559216256 {
1559316257 keyPressed(0, modifiers);
1559416258 }
15595
- clickStart(x, y, modifiers);
16259
+ // clickStart(x, y, modifiers);
1559616260 return true;
1559716261 }
1559816262
....@@ -15710,7 +16374,7 @@
1571016374 {
1571116375 keyReleased(0, 0);
1571216376 }
15713
- drag(x, y, modifiers);
16377
+ drag(x, y, 0, modifiers);
1571416378 return true;
1571516379 }
1571616380
....@@ -15842,7 +16506,7 @@
1584216506 Object3D object;
1584316507 static Object3D trackedobject;
1584416508 Camera renderCamera; // Light or Eye (or Occlusion)
15845
- /*static*/ Camera manipCamera; // Light or Eye
16509
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1584616510 /*static*/ Camera eyeCamera;
1584716511 /*static*/ Camera lightCamera;
1584816512 int cameracount;
....@@ -15938,7 +16602,9 @@
1593816602
1593916603 float BGcolor = 0.5f;
1594016604
15941
- private void DrawSkyBox(GL gl)
16605
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16606
+
16607
+ private void DrawSkyBox(GL gl, float ratio)
1594216608 {
1594316609 if (envyoff || cubemap == null)
1594416610 {
....@@ -15955,7 +16621,17 @@
1595516621 // Compensates for ExaminerViewer's modification of modelview matrix
1595616622 gl.glMatrixMode(GL.GL_MODELVIEW);
1595716623 gl.glLoadIdentity();
16624
+ gl.glScalef(1,ratio,1);
1595816625
16626
+ colorV[0] = 2;
16627
+ colorV[1] = 2;
16628
+ colorV[2] = 2;
16629
+ colorV[3] = 1;
16630
+ gl.glDisable(gl.GL_COLOR_MATERIAL);
16631
+ gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16632
+
16633
+ gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16634
+
1595916635 //gl.glActiveTexture(GL.GL_TEXTURE1);
1596016636 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1596116637
....@@ -15968,7 +16644,7 @@
1596816644 // GL_NORMAL_MAP texgen mode. Temporarily enabling lighting
1596916645 // causes the normals to be sent down. Thanks to Ken Dyke.
1597016646 //gl.glEnable(GL.GL_LIGHTING);
15971
- gl.glDisable(GL.GL_LIGHTING);
16647
+ gl.glEnable(GL.GL_LIGHTING);
1597216648
1597316649 gl.glTexGeni(GL.GL_S, GL.GL_TEXTURE_GEN_MODE, GL.GL_NORMAL_MAP);
1597416650 gl.glTexGeni(GL.GL_T, GL.GL_TEXTURE_GEN_MODE, GL.GL_NORMAL_MAP);
....@@ -16127,16 +16803,16 @@
1612716803 cStatic.objectstack[materialdepth++] = checker;
1612816804 //System.out.println("material " + material);
1612916805 //Applet3D.tracein(this, selected);
16130
- vector2buffer = checker.projectedVertices;
16806
+ //vector2buffer = checker.projectedVertices;
1613116807
1613216808 //checker.GetMaterial().Draw(this, false); // true);
16133
- DrawMaterial(checker.GetMaterial(), false); // true);
16809
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1613416810
1613516811 materialdepth -= 1;
1613616812 if (materialdepth > 0)
1613716813 {
16138
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16139
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
16814
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16815
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1614016816 }
1614116817 //checker.GetMaterial().opacity = 1f;
1614216818 ////checker.GetMaterial().ambient = 1f;
....@@ -16222,6 +16898,14 @@
1622216898 }
1622316899 }
1622416900
16901
+ private Object3D GetFolder()
16902
+ {
16903
+ Object3D folder = object.GetWindow().copy;
16904
+ if (object.GetWindow().copy.selection.Size() > 0)
16905
+ folder = object.GetWindow().copy.selection.elementAt(0);
16906
+ return folder;
16907
+ }
16908
+
1622516909 class SelectBuffer implements GLEventListener
1622616910 {
1622716911
....@@ -16237,7 +16921,7 @@
1623716921 //new Exception().printStackTrace();
1623816922 System.out.println("select buffer init");
1623916923 // Use debug pipeline
16240
- drawable.setGL(new DebugGL(drawable.getGL()));
16924
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1624116925
1624216926 GL gl = drawable.getGL();
1624316927
....@@ -16280,6 +16964,7 @@
1628016964 {
1628116965 if (!selection)
1628216966 {
16967
+ new Exception().printStackTrace();
1628316968 System.exit(0);
1628416969 return;
1628516970 }
....@@ -16300,6 +16985,17 @@
1630016985
1630116986 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1630216987
16988
+ if (PAINTMODE)
16989
+ {
16990
+ if (object.GetWindow().copy.selection.Size() > 0)
16991
+ {
16992
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16993
+
16994
+ // Make what you paint not selectable.
16995
+ paintobj.ResetSelectable();
16996
+ }
16997
+ }
16998
+
1630316999 //int tmp = selection_view;
1630417000 //selection_view = -1;
1630517001 int temp = DrawMode();
....@@ -16311,6 +17007,17 @@
1631117007 // temp = DEFAULT; // patch for selection debug
1631217008 Globals.drawMode = temp; // WARNING
1631317009
17010
+ if (PAINTMODE)
17011
+ {
17012
+ if (object.GetWindow().copy.selection.Size() > 0)
17013
+ {
17014
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17015
+
17016
+ // Revert.
17017
+ paintobj.RestoreSelectable();
17018
+ }
17019
+ }
17020
+
1631417021 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1631517022
1631617023 // trying different ways of getting the depth info over
....@@ -16358,6 +17065,8 @@
1635817065 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1635917066 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1636017067 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
17068
+
17069
+ CreateSelectedPoint();
1636117070
1636217071 // Will fit the mesh !!!
1636317072 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16407,34 +17116,36 @@
1640717116 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]));
1640817117 }
1640917118
16410
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
17119
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1641117120 }
1641217121 }
1641317122
1641417123 if (!movingcamera && !PAINTMODE)
16415
- object.editWindow.ScreenFitPoint(); // fev 2014
17124
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1641617125
16417
- if (PAINTMODE && GrafreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17126
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1641817127 {
16419
- Object3D paintobj = GrafreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17128
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1642017129
16421
- Object3D group = new Object3D("inst" + paintcount++);
17130
+ if (object.GetWindow().copy.selection.Size() > 0)
17131
+ {
17132
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1642217133
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();
17134
+ Object3D inst = new Object3D("inst" + paintcount++);
17135
+
17136
+ inst.CreateMaterial(); // use a void leaf to select instances
17137
+
17138
+ inst.add(paintobj); // link
17139
+
17140
+ object.GetWindow().SnapObject(inst);
17141
+
17142
+ Object3D folder = paintFolder; // GetFolder();
17143
+
17144
+ folder.add(inst);
17145
+
17146
+ object.GetWindow().ResetModel();
17147
+ object.GetWindow().refreshContents();
17148
+ }
1643817149 }
1643917150 else
1644017151 paintcount = 0;
....@@ -16473,6 +17184,11 @@
1647317184 //System.out.println("objects[color] = " + objects[color]);
1647417185 //objects[color].Select();
1647517186 indexcount = 0;
17187
+ ObjEditor window = object.GetWindow();
17188
+ if (window != null && deselect)
17189
+ {
17190
+ window.Select(null, deselect, true);
17191
+ }
1647617192 object.Select(color, deselect);
1647717193 }
1647817194
....@@ -16572,7 +17288,7 @@
1657217288 gl.glDisable(gl.GL_CULL_FACE);
1657317289 }
1657417290
16575
- if (!RENDERSHADOW)
17291
+ if (!Globals.RENDERSHADOW)
1657617292 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1657717293
1657817294 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -16582,7 +17298,7 @@
1658217298 //gl.glColorMask(false, false, false, false);
1658317299
1658417300 //render_scene_from_light_view(gl, drawable, 0, 0);
16585
- if (RENDERSHADOW && Globals.lighttouched && !movingcamera) // && !parent.IsFreezed())
17301
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1658617302 {
1658717303 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1658817304
....@@ -16998,23 +17714,15 @@
1699817714 int AAbuffersize = 0;
1699917715
1700017716 //double[] selectedpoint = new double[3];
17001
- static Superellipsoid selectedpoint = new Superellipsoid();
17717
+ static Superellipsoid selectedpoint;
1700217718 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();
17719
+ static Sphere debugpointG;
17720
+ static Sphere debugpointP;
17721
+ static Sphere debugpointC;
17722
+ static Sphere debugpointR;
1700717723
1700817724 static Sphere debugpoints[] = new Sphere[8];
1700917725
17010
- static
17011
- {
17012
- for (int i=0; i<8; i++)
17013
- {
17014
- debugpoints[i] = new Sphere();
17015
- }
17016
- }
17017
-
1701817726 static void InitPoints(float radius)
1701917727 {
1702017728 for (int i=0; i<8; i++)