Normand Briere
2019-08-12 8f1afe25ea8fc8801aab66331c32a50859a758c2
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 {
....@@ -7902,7 +8021,7 @@
79028021 String pigment = Object3D.GetPigment(tex);
79038022 String bump = Object3D.GetBump(tex);
79048023
7905
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8024
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79068025 {
79078026 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79088027 // System.out.println("; bump = " + bump);
....@@ -7917,11 +8036,69 @@
79178036 pigment = null;
79188037 }
79198038
7920
- ReleaseTexture(bump, true);
7921
- ReleaseTexture(pigment, false);
8039
+ ReleaseTexture(tex, true);
8040
+ ReleaseTexture(tex, false);
79228041 }
79238042
7924
- 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)
79258102 {
79268103 if (// DrawMode() != 0 || /*tex == null ||*/
79278104 ambientOcclusion ) // || !textureon)
....@@ -7932,7 +8109,7 @@
79328109 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
79338110
79348111 if (tex != null)
7935
- texture = textures.get(tex);
8112
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
79368113
79378114 // //assert( texture != null );
79388115 // if (texture == null)
....@@ -8024,7 +8201,55 @@
80248201 }
80258202 }
80268203
8027
- /*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
80288253 {
80298254 if (// DrawMode() != 0 || /*tex == null ||*/
80308255 ambientOcclusion ) // || !textureon)
....@@ -8035,17 +8260,47 @@
80358260 if (tex == null)
80368261 {
80378262 BindTexture(null,false,resolution);
8038
- BindTexture(null,true,resolution);
80398263 return;
80408264 }
80418265
80428266 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
+
80438299 String bump = Object3D.GetBump(tex);
80448300
8045
- usedtextures.put(pigment, pigment);
8046
- usedtextures.put(bump, bump);
8301
+ usedtextures.add(tex);
80478302
8048
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8303
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
80498304 {
80508305 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
80518306 // System.out.println("; bump = " + bump);
....@@ -8055,43 +8310,94 @@
80558310 {
80568311 bump = null;
80578312 }
8058
- if (pigment.equals(""))
8059
- {
8060
- pigment = null;
8061
- }
80628313
8063
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8064
- BindTexture(pigment, false, resolution);
80658314 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8066
- BindTexture(bump, true, resolution);
8315
+ BindTexture(tex, true, resolution);
80678316 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8068
-
8069
- return; // true;
80708317 }
80718318
8072
- 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)
80738322 {
8074
- 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;
80758342
80768343 if (tex != null)
80778344 {
8078
- String texname = tex;
8345
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8346
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
80798347
8080
- String[] split = tex.split("Textures");
8081
- if (split.length > 1)
8082
- texname = "/Users/nbriere/Textures" + split[split.length-1];
8083
- else
8084
- if (!texname.startsWith("/"))
8085
- 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) && !texname.startsWith("@"))
8362
+ {
8363
+ texname = fallbackTextureName;
8364
+ }
80868365
80878366 if (CACHETEXTURE)
8088
- texture = textures.get(texname); // TEXTURE CACHE
8089
-
8090
- TextureData texturedata = null;
8091
-
8092
- if (texture == null || texture.resolution < resolution)
80938367 {
8094
- 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(""))
80958401 {
80968402 assert(!bump);
80978403 // if (bump)
....@@ -8102,19 +8408,23 @@
81028408 // }
81038409 // else
81048410 // {
8105
- texture = textures.get(tex);
8106
- if (texture == null)
8411
+ // texturecache = textures.get(texname); // suspicious
8412
+ if (texturecache == null)
81078413 {
8108
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8414
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
81098415 }
8416
+ else
8417
+ new Exception().printStackTrace();
81108418 // }
81118419 } else
8112
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8420
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
81138421 {
81148422 assert(bump);
8115
- texture = textures.get(tex);
8116
- if (texture == null)
8117
- 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();
81188428 } else
81198429 {
81208430 //if (tex.equals("IMMORTAL"))
....@@ -8122,11 +8432,22 @@
81228432 // texture = GetResourceTexture("default.png");
81238433 //} else
81248434 //{
8125
- if (tex.equals("WHITE_NOISE"))
8435
+ if (texname.endsWith("WHITE_NOISE"))
81268436 {
8127
- texture = textures.get(tex);
8128
- if (texture == null)
8129
- 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();
8442
+ } else
8443
+ {
8444
+ if (texname.startsWith("@"))
8445
+ {
8446
+ // texturecache = textures.get(texname); // suspicious
8447
+ if (texturecache == null)
8448
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8449
+ else
8450
+ new Exception().printStackTrace();
81308451 } else
81318452 {
81328453 if (textureon)
....@@ -8151,7 +8472,7 @@
81518472 }
81528473
81538474 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
8154
- if (!new File(cachename).exists())
8475
+ if (!FileExists(cachename))
81558476 cachename = texname;
81568477 else
81578478 processbump = false; // don't process bump map again
....@@ -8173,7 +8494,7 @@
81738494 }
81748495
81758496 cachename = texname.substring(0, texname.length()-4)+ext+".png";
8176
- if (!new File(cachename).exists())
8497
+ if (!FileExists(cachename))
81778498 cachename = texname;
81788499 else
81798500 processbump = false; // don't process bump map again
....@@ -8182,20 +8503,23 @@
81828503 texturedata = GetFileTexture(cachename, processbump, resolution);
81838504
81848505
8185
- if (texturedata != null)
8186
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8506
+ if (texturedata == null)
8507
+ throw new Exception();
8508
+
8509
+ texturecache = new CacheTexture(texturedata,resolution);
81878510 //texture = GetTexture(tex, bump);
81888511 }
8512
+ }
81898513 }
81908514 //}
81918515 }
81928516
8193
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8517
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
81948518 {
81958519 //return false;
81968520
81978521 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8198
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8522
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
81998523 {
82008524 // String ext = "_highres";
82018525 // if (REDUCETEXTURE)
....@@ -8212,52 +8536,17 @@
82128536 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
82138537 if (!cachefile.exists())
82148538 {
8215
- // cache to disk
8216
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
8217
- //buffers[0].
8218
-
8219
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
8220
- int[] pixels = new int[bytebuf.capacity()/3];
8221
-
8222
- // squared size heuristic...
8223
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8539
+ //if (texturedata.getWidth() == texturedata.getHeight())
82248540 {
8225
- for (int i=pixels.length; --i>=0;)
8226
- {
8227
- int i3 = i*3;
8228
- pixels[i] = 0xFF;
8229
- pixels[i] <<= 8;
8230
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
8231
- pixels[i] <<= 8;
8232
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
8233
- pixels[i] <<= 8;
8234
- pixels[i] |= bytebuf.get(i3) & 0xFF;
8235
- }
8236
-
8237
- /*
8238
- int r=0,g=0,b=0,a=0;
8239
- for (int i=0; i<width; i++)
8240
- for (int j=0; j<height; j++)
8241
- {
8242
- int index = j*width+i;
8243
- int p = pixels[index];
8244
- a = ((p>>24) & 0xFF);
8245
- r = ((p>>16) & 0xFF);
8246
- g = ((p>>8) & 0xFF);
8247
- b = (p & 0xFF);
8248
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
8249
- }
8250
- /**/
8251
- int width = (int)Math.sqrt(pixels.length); // squared
8252
- int height = width;
8253
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
8254
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8541
+ BufferedImage rendImage = CreateBim(texturedata);
8542
+
82558543 ImageWriter writer = null;
82568544 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
82578545 if (iter.hasNext()) {
82588546 writer = (ImageWriter)iter.next();
82598547 }
8260
- float compressionQuality = 0.9f;
8548
+
8549
+ float compressionQuality = 0.85f;
82618550 try
82628551 {
82638552 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8274,18 +8563,20 @@
82748563 }
82758564 }
82768565 }
8277
-
8566
+
8567
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8568
+
82788569 //System.out.println("Texture = " + tex);
8279
- if (textures.containsKey(texname))
8570
+ if (textures.containsKey(tex))
82808571 {
8281
- CacheTexture thetex = textures.get(texname);
8572
+ CacheTexture thetex = textures.get(tex);
82828573 thetex.texture.disable();
82838574 thetex.texture.dispose();
8284
- textures.remove(texname);
8575
+ textures.remove(tex);
82858576 }
82868577
8287
- texture.texturedata = texturedata;
8288
- textures.put(texname, texture);
8578
+ //texture.texturedata = texturedata;
8579
+ textures.put(tex, texturecache);
82898580
82908581 // newtex = true;
82918582 }
....@@ -8301,10 +8592,44 @@
83018592 }
83028593 }
83038594
8304
- return texture;
8595
+ return texturecache;
83058596 }
83068597
8307
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution)
8598
+ static void EmbedTextures(cTexture tex)
8599
+ {
8600
+ if (tex.pigmentdata == null)
8601
+ {
8602
+ //String texname = Object3D.GetPigment(tex);
8603
+
8604
+ CacheTexture texturecache = texturepigment.get(tex);
8605
+
8606
+ if (texturecache != null)
8607
+ {
8608
+ tex.pw = texturecache.texturedata.getWidth();
8609
+ tex.ph = texturecache.texturedata.getHeight();
8610
+ tex.pigmentdata = //CompressJPEG(CreateBim
8611
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8612
+ ;
8613
+ //, tex.pw, tex.ph), 0.5f);
8614
+ }
8615
+ }
8616
+
8617
+ if (tex.bumpdata == null)
8618
+ {
8619
+ //String texname = Object3D.GetBump(tex);
8620
+
8621
+ CacheTexture texturecache = texturebump.get(tex);
8622
+
8623
+ if (texturecache != null)
8624
+ {
8625
+ tex.bw = texturecache.texturedata.getWidth();
8626
+ tex.bh = texturecache.texturedata.getHeight();
8627
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8628
+ }
8629
+ }
8630
+ }
8631
+
8632
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
83088633 {
83098634 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
83108635
....@@ -8322,21 +8647,21 @@
83228647 return texture!=null?texture.texture:null;
83238648 }
83248649
8325
- public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution)
8650
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
83268651 {
83278652 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
83288653
83298654 return texture!=null?texture.texturedata:null;
83308655 }
83318656
8332
- boolean BindTexture(String tex, boolean bump, int resolution)
8657
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
83338658 {
83348659 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
83358660 {
83368661 return false;
83378662 }
83388663
8339
- boolean newtex = false;
8664
+ //boolean newtex = false;
83408665
83418666 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
83428667
....@@ -8368,9 +8693,75 @@
83688693 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
83698694 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
83708695
8371
- return newtex;
8696
+ return true; // Warning: not used.
83728697 }
83738698
8699
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8700
+ {
8701
+ try
8702
+ {
8703
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8704
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8705
+ ImageWriter writer = writers.next();
8706
+
8707
+ ImageWriteParam param = writer.getDefaultWriteParam();
8708
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8709
+ param.setCompressionQuality(quality);
8710
+
8711
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8712
+ writer.setOutput(ios);
8713
+ writer.write(null, new IIOImage(image, null, null), param);
8714
+
8715
+ byte[] data = baos.toByteArray();
8716
+ writer.dispose();
8717
+ return data;
8718
+ }
8719
+ catch (Exception e)
8720
+ {
8721
+ e.printStackTrace();
8722
+ return null;
8723
+ }
8724
+ }
8725
+
8726
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8727
+ {
8728
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8729
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8730
+ ImageReader reader = writers.next();
8731
+
8732
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8733
+
8734
+ ImageReadParam param = reader.getDefaultReadParam();
8735
+ param.setDestination(bim);
8736
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8737
+
8738
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8739
+ reader.setInput(ios);
8740
+ BufferedImage bim2 = reader.read(0, param);
8741
+ reader.dispose();
8742
+
8743
+// WritableRaster raster = bim2.getRaster();
8744
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8745
+// byte[] bytes = data.getData();
8746
+//
8747
+// int[] pixels = new int[bytes.length/3];
8748
+// for (int i=pixels.length; --i>=0;)
8749
+// {
8750
+// int i3 = i*3;
8751
+// pixels[i] = 0xFF;
8752
+// pixels[i] <<= 8;
8753
+// pixels[i] |= bytes[i3+2] & 0xFF;
8754
+// pixels[i] <<= 8;
8755
+// pixels[i] |= bytes[i3+1] & 0xFF;
8756
+// pixels[i] <<= 8;
8757
+// pixels[i] |= bytes[i3] & 0xFF;
8758
+// }
8759
+//
8760
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8761
+
8762
+ return bim;
8763
+ }
8764
+
83748765 ShadowBuffer shadowPBuf;
83758766 AntialiasBuffer antialiasPBuf;
83768767 int MAXSTACK;
....@@ -8387,10 +8778,12 @@
83878778
83888779 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
83898780 MAXSTACK = temp[0];
8390
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8781
+ if (Globals.DEBUG)
8782
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
83918783 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
83928784 MAXSTACK = temp[0];
8393
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8785
+ if (Globals.DEBUG)
8786
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
83948787
83958788 // Use debug pipeline
83968789 //drawable.setGL(new DebugGL(gl)); //
....@@ -8398,7 +8791,8 @@
83988791 gl = drawable.getGL(); //
83998792
84008793 GL gl3 = getGL();
8401
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8794
+ if (Globals.DEBUG)
8795
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
84028796
84038797
84048798 //float pos[] = { 100, 100, 100, 0 };
....@@ -8563,7 +8957,7 @@
85638957
85648958 if (cubemap == null)
85658959 {
8566
- LoadEnvy(5);
8960
+ //LoadEnvy(1);
85678961 }
85688962
85698963 //cubemap.enable();
....@@ -8850,37 +9244,58 @@
88509244 cubemap = null;
88519245 return;
88529246 case 1:
8853
- name = "cubemaps/box_";
8854
- ext = "png";
9247
+ name = "cubemaps/rgb/";
9248
+ ext = "jpg";
88559249 reverseUP = false;
88569250 break;
88579251 case 2:
8858
- name = "cubemaps/uffizi_";
8859
- ext = "png";
8860
- break; // reverseUP = true; break;
9252
+ name = "cubemaps/uffizi/";
9253
+ ext = "jpg";
9254
+ reverseUP = false;
9255
+ break;
88619256 case 3:
8862
- name = "cubemaps/CloudyHills_";
8863
- ext = "tga";
9257
+ name = "cubemaps/CloudyHills/";
9258
+ ext = "jpg";
88649259 reverseUP = false;
88659260 break;
88669261 case 4:
8867
- name = "cubemaps/cornell_";
9262
+ name = "cubemaps/cornell/";
88689263 ext = "png";
88699264 reverseUP = false;
88709265 break;
9266
+ case 5:
9267
+ name = "cubemaps/skycube/";
9268
+ ext = "jpg";
9269
+ reverseUP = false;
9270
+ break;
9271
+ case 6:
9272
+ name = "cubemaps/SaintLazarusChurch3/";
9273
+ ext = "jpg";
9274
+ reverseUP = false;
9275
+ break;
9276
+ case 7:
9277
+ name = "cubemaps/Sodermalmsallen/";
9278
+ ext = "jpg";
9279
+ reverseUP = false;
9280
+ break;
9281
+ case 8:
9282
+ name = "cubemaps/Sodermalmsallen2/";
9283
+ ext = "jpg";
9284
+ reverseUP = false;
9285
+ break;
9286
+ case 9:
9287
+ name = "cubemaps/UnionSquare/";
9288
+ ext = "jpg";
9289
+ reverseUP = false;
9290
+ break;
88719291 default:
8872
- name = "cubemaps/rgb_";
8873
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9292
+ name = "cubemaps/box/";
9293
+ ext = "png"; /*mipmap = true;*/
9294
+ reverseUP = false;
88749295 break;
88759296 }
8876
-
8877
- try
8878
- {
8879
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
8880
- } catch (IOException e)
8881
- {
8882
- throw new RuntimeException(e);
8883
- }
9297
+
9298
+ LoadSkybox(name, ext, mipmap);
88849299 }
88859300
88869301 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -8912,8 +9327,12 @@
89129327 static double[] model = new double[16];
89139328 double[] camera2light = new double[16];
89149329 double[] light2camera = new double[16];
8915
- int newenvy = -1;
8916
- boolean envyoff = true; // false;
9330
+
9331
+ //int newenvy = -1;
9332
+ //boolean envyoff = false;
9333
+
9334
+ String loadedskyboxname;
9335
+
89179336 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
89189337 //float[] light0 = { 0,0,0 };
89199338 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9206,11 +9625,35 @@
92069625 jy8[3] = 0.5f;
92079626 }
92089627
9209
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9628
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
92109629 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
92119630 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
92129631 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
92139632
9633
+ void ResetOptions()
9634
+ {
9635
+ options1[0] = 100;
9636
+ options1[1] = 0.025f;
9637
+ options1[2] = 0.01f;
9638
+ options1[3] = 0;
9639
+ options1[4] = 0;
9640
+
9641
+ options2[0] = 0;
9642
+ options2[1] = 0.75f;
9643
+ options2[2] = 0;
9644
+ options2[3] = 0;
9645
+
9646
+ options3[0] = 1;
9647
+ options3[1] = 1;
9648
+ options3[2] = 1;
9649
+ options3[3] = 0;
9650
+
9651
+ options4[0] = 1;
9652
+ options4[1] = 0;
9653
+ options4[2] = 1;
9654
+ options4[3] = 0;
9655
+ }
9656
+
92149657 static int imagecount = 0; // movie generation
92159658
92169659 static int jitter = 0;
....@@ -9306,8 +9749,8 @@
93069749 assert (parentcam != renderCamera);
93079750
93089751 if (renderCamera != lightCamera)
9309
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9310
- LA.matConcat(matrix, parentcam.toParent, matrix);
9752
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9753
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
93119754
93129755 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
93139756
....@@ -9322,8 +9765,8 @@
93229765 LA.matCopy(renderCamera.fromScreen, matrix);
93239766
93249767 if (renderCamera != lightCamera)
9325
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9326
- LA.matConcat(parentcam.fromParent, matrix, matrix);
9768
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9769
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
93279770
93289771 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
93299772
....@@ -9369,10 +9812,12 @@
93699812 rati = 1 / rati;
93709813 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
93719814 }
9372
- assert (newenvy == -1);
9815
+
9816
+ //assert (newenvy == -1);
9817
+
93739818 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
93749819 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9375
- DrawSkyBox(gl);
9820
+ DrawSkyBox(gl, (float)rati);
93769821 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
93779822 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
93789823 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -9395,7 +9840,7 @@
93959840 //gl.glFlush();
93969841 gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE);
93979842
9398
- if (ANIMATION && ABORTED)
9843
+ if (Globals.ANIMATION && ABORTED)
93999844 {
94009845 System.err.println(" ABORTED FRAME");
94019846 break;
....@@ -9425,7 +9870,7 @@
94259870 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
94269871
94279872 // save image
9428
- if (ANIMATION && !ABORTED)
9873
+ if (Globals.ANIMATION && !ABORTED)
94299874 {
94309875 VPwidth = viewport[2];
94319876 VPheight = viewport[3];
....@@ -9536,11 +9981,11 @@
95369981
95379982 // imagecount++;
95389983
9539
- String fullname = filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
9984
+ String fullname = Globals.filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
95409985
95419986 if (!BOXMODE)
95429987 {
9543
- System.out.println("image: " + fullname + " (wav cursor=" + (GrafreeD.wav.cursor / 735 / 4) + ")");
9988
+ System.out.println("image: " + fullname + " (wav cursor=" + (Grafreed.wav.cursor / 735 / 4) + ")");
95449989 }
95459990
95469991 if (!BOXMODE)
....@@ -9578,7 +10023,7 @@
957810023 ABORTED = false;
957910024 }
958010025 else
9581
- GrafreeD.wav.cursor += 735 * ACSIZE;
10026
+ Grafreed.wav.cursor += 735 * ACSIZE;
958210027
958310028 if (false)
958410029 {
....@@ -10241,11 +10686,11 @@
1024110686
1024210687 public void display(GLAutoDrawable drawable)
1024310688 {
10244
- if (GrafreeD.savesound && GrafreeD.hassound)
10689
+ if (Grafreed.savesound && Grafreed.hassound)
1024510690 {
10246
- GrafreeD.wav.save();
10247
- GrafreeD.savesound = false;
10248
- GrafreeD.hassound = false;
10691
+ Grafreed.wav.save();
10692
+ Grafreed.savesound = false;
10693
+ Grafreed.hassound = false;
1024910694 }
1025010695 // if (DEBUG_SELECTION)
1025110696 // {
....@@ -10321,6 +10766,7 @@
1032110766 ANTIALIAS = 0;
1032210767 //System.out.println("RESTART");
1032310768 AAtimer.restart();
10769
+ Globals.TIMERRUNNING = true;
1032410770 }
1032510771 }
1032610772 }
....@@ -10375,7 +10821,7 @@
1037510821 Object3D theobject = object;
1037610822 Object3D theparent = object.parent;
1037710823 object.parent = null;
10378
- object = (Object3D)GrafreeD.clone(object);
10824
+ object = (Object3D)Grafreed.clone(object);
1037910825 object.Stripify();
1038010826 if (theobject.selection == null || theobject.selection.Size() == 0)
1038110827 theobject.PreprocessOcclusion(this);
....@@ -10388,13 +10834,14 @@
1038810834 ambientOcclusion = false;
1038910835 }
1039010836
10391
- if (Globals.lighttouched && DrawMode() == DEFAULT && !lightMode) // && !FROZEN)
10837
+ if (//Globals.lighttouched &&
10838
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1039210839 {
1039310840 //if (RENDERSHADOW) // ?
1039410841 if (!IsFrozen())
1039510842 {
1039610843 // dec 2012
10397
- if (!ambientOcclusion && !(!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0))
10844
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
1039810845 {
1039910846 Globals.framecount++;
1040010847 shadowbuffer.display();
....@@ -10407,7 +10854,7 @@
1040710854
1040810855 if (wait)
1040910856 {
10410
- Sleep(500);
10857
+ Sleep(200); // blocks everything
1041110858
1041210859 wait = false;
1041310860 }
....@@ -10521,8 +10968,8 @@
1052110968
1052210969 // if (parentcam != renderCamera) // not a light
1052310970 if (cam != lightCamera)
10524
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10525
- LA.matConcat(matrix, parentcam.toParent, matrix);
10971
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10972
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1052610973
1052710974 for (int j = 0; j < 4; j++)
1052810975 {
....@@ -10536,8 +10983,8 @@
1053610983
1053710984 // if (parentcam != renderCamera) // not a light
1053810985 if (cam != lightCamera)
10539
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10540
- LA.matConcat(parentcam.fromParent, matrix, matrix);
10986
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10987
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1054110988
1054210989 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1054310990
....@@ -10623,13 +11070,27 @@
1062311070 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1062411071 }
1062511072
10626
- if (newenvy > -1)
11073
+// if (newenvy > -1)
11074
+// {
11075
+// LoadEnvy(newenvy);
11076
+// }
11077
+//
11078
+// newenvy = -1;
11079
+
11080
+ if (object.skyboxname != null)
1062711081 {
10628
- LoadEnvy(newenvy);
11082
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11083
+ {
11084
+ LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11085
+ loadedskyboxname = object.skyboxname;
11086
+ }
1062911087 }
10630
-
10631
- newenvy = -1;
10632
-
11088
+ else
11089
+ {
11090
+ cubemap = null;
11091
+ loadedskyboxname = null;
11092
+ }
11093
+
1063311094 ratio = ((double) getWidth()) / getHeight();
1063411095 //System.out.println("ratio = " + ratio);
1063511096
....@@ -10645,7 +11106,7 @@
1064511106
1064611107 if (!IsFrozen() && !ambientOcclusion)
1064711108 {
10648
- DrawSkyBox(gl);
11109
+ DrawSkyBox(gl, (float)ratio);
1064911110 }
1065011111
1065111112 //if (selection_view == -1)
....@@ -10796,7 +11257,16 @@
1079611257 // Bump noise
1079711258 gl.glActiveTexture(GL.GL_TEXTURE6);
1079811259 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
10799
- BindTexture(NOISE_TEXTURE, false, 2);
11260
+
11261
+ try
11262
+ {
11263
+ BindTexture(NOISE_TEXTURE, false, 2);
11264
+ }
11265
+ catch (Exception e)
11266
+ {
11267
+ System.err.println("FAILED: " + NOISE_TEXTURE);
11268
+ }
11269
+
1080011270
1080111271 gl.glActiveTexture(GL.GL_TEXTURE0);
1080211272 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -10819,9 +11289,9 @@
1081911289
1082011290 gl.glMatrixMode(GL.GL_MODELVIEW);
1082111291
10822
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10823
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10824
-//gl.glEnable(gl.GL_MULTISAMPLE);
11292
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11293
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11294
+gl.glEnable(gl.GL_MULTISAMPLE);
1082511295 } else
1082611296 {
1082711297 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -10832,7 +11302,7 @@
1083211302 //System.out.println("BLENDING ON");
1083311303 gl.glEnable(GL.GL_BLEND);
1083411304 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
10835
-
11305
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1083611306 gl.glMatrixMode(gl.GL_PROJECTION);
1083711307 gl.glLoadIdentity();
1083811308
....@@ -10921,8 +11391,8 @@
1092111391 System.err.println("parentcam != renderCamera");
1092211392
1092311393 // if (cam != lightCamera)
10924
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10925
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11394
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11395
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1092611396 }
1092711397
1092811398 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -10943,8 +11413,8 @@
1094311413 if (true) // TODO
1094411414 {
1094511415 if (cam != lightCamera)
10946
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10947
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11416
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11417
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
1094811418 }
1094911419
1095011420 LA.xformPos(light0, cam.toScreen, light0);
....@@ -11081,7 +11551,7 @@
1108111551 }
1108211552 }
1108311553
11084
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11554
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1108511555 {
1108611556 //gl.glDepthFunc(GL.GL_LEQUAL);
1108711557 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11089,24 +11559,21 @@
1108911559
1109011560 boolean texon = textureon;
1109111561
11092
- if (RENDERPROGRAM > 0)
11093
- {
11094
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11095
- textureon = false;
11096
- }
11562
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11563
+ textureon = false;
11564
+
1109711565 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1109811566 //System.out.println("ALLO");
1109911567 gl.glColorMask(false, false, false, false);
1110011568 DrawObject(gl);
11101
- if (RENDERPROGRAM > 0)
11102
- {
11103
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11104
- textureon = texon;
11105
- }
11569
+
11570
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11571
+ textureon = texon;
11572
+
1110611573 gl.glColorMask(true, true, true, true);
1110711574
1110811575 gl.glDepthFunc(GL.GL_EQUAL);
11109
- //gl.glDepthMask(false);
11576
+ gl.glDepthMask(false);
1111011577 }
1111111578
1111211579 if (false) // DrawMode() == SHADOW)
....@@ -11260,8 +11727,14 @@
1126011727 {
1126111728 renderpass++;
1126211729 // System.out.println("Draw object... ");
11730
+ STEP = 1;
1126311731 if (FAST) // in case there is no script
11264
- STEP = 16;
11732
+ STEP = 8;
11733
+
11734
+ if (CURRENTANTIALIAS == 0 || ACSIZE == 1)
11735
+ {
11736
+ STEP *= 4;
11737
+ }
1126511738
1126611739 //object.FullInvariants();
1126711740
....@@ -11275,23 +11748,44 @@
1127511748 e.printStackTrace();
1127611749 }
1127711750
11278
- if (GrafreeD.RENDERME > 0)
11279
- GrafreeD.RENDERME--; // mechante magouille
11751
+ if (Grafreed.RENDERME > 0)
11752
+ Grafreed.RENDERME--; // mechante magouille
1128011753
1128111754 Globals.ONESTEP = false;
1128211755 }
1128311756
1128411757 static boolean zoomonce = false;
1128511758
11759
+ static void CreateSelectedPoint()
11760
+ {
11761
+ if (selectedpoint == null)
11762
+ {
11763
+ debugpointG = new Sphere();
11764
+ debugpointP = new Sphere();
11765
+ debugpointC = new Sphere();
11766
+ debugpointR = new Sphere();
11767
+
11768
+ selectedpoint = new Superellipsoid();
11769
+
11770
+ for (int i=0; i<8; i++)
11771
+ {
11772
+ debugpoints[i] = new Sphere();
11773
+ }
11774
+ }
11775
+ }
11776
+
1128611777 void DrawObject(GL gl, boolean draw)
1128711778 {
11779
+ // To clear camera values
11780
+ ResetOptions();
11781
+
1128811782 //System.out.println("DRAW OBJECT " + mouseDown);
1128911783 // DrawMode() = SELECTION;
1129011784 //GL gl = getGL();
1129111785 if ((TRACK || SHADOWTRACK) || zoomonce)
1129211786 {
1129311787 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11294
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11788
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1129511789 pingthread.StepToTarget(true); // true);
1129611790 // zoomonce = false;
1129711791 }
....@@ -11346,7 +11840,14 @@
1134611840
1134711841 usedtextures.clear();
1134811842
11349
- BindTextures(DEFAULT_TEXTURES, 2);
11843
+ try
11844
+ {
11845
+ BindTextures(DEFAULT_TEXTURES, 2);
11846
+ }
11847
+ catch (Exception e)
11848
+ {
11849
+ System.err.println("FAILED: " + DEFAULT_TEXTURES);
11850
+ }
1135011851 }
1135111852 //System.out.println("--> " + stackdepth);
1135211853 // GrafreeD.traceon();
....@@ -11356,8 +11857,9 @@
1135611857
1135711858 if (DrawMode() == DEFAULT)
1135811859 {
11359
- if (DEBUG)
11860
+ if (Globals.DEBUG)
1136011861 {
11862
+ CreateSelectedPoint();
1136111863 float radius = 0.05f;
1136211864 if (selectedpoint.radius != radius)
1136311865 {
....@@ -11411,20 +11913,32 @@
1141111913 ReleaseTextures(DEFAULT_TEXTURES);
1141211914
1141311915 if (CLEANCACHE)
11414
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11916
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1141511917 {
11416
- String tex = e.nextElement();
11918
+ cTexture tex = e.nextElement();
1141711919
1141811920 // System.out.println("Texture --------- " + tex);
1141911921
11420
- if (tex.equals("WHITE_NOISE"))
11922
+ if (tex.equals("WHITE_NOISE:"))
1142111923 continue;
1142211924
11423
- if (!usedtextures.containsKey(tex))
11925
+ if (!usedtextures.contains(tex))
1142411926 {
11927
+ CacheTexture gettex = texturepigment.get(tex);
1142511928 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11426
- textures.get(tex).texture.dispose();
11427
- textures.remove(tex);
11929
+ if (gettex != null)
11930
+ {
11931
+ gettex.texture.dispose();
11932
+ texturepigment.remove(tex);
11933
+ }
11934
+
11935
+ gettex = texturebump.get(tex);
11936
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11937
+ if (gettex != null)
11938
+ {
11939
+ gettex.texture.dispose();
11940
+ texturebump.remove(tex);
11941
+ }
1142811942 }
1142911943 }
1143011944 }
....@@ -11437,7 +11951,14 @@
1143711951 if (checker != null && DrawMode() == DEFAULT)
1143811952 {
1143911953 //BindTexture(IMMORTAL_TEXTURE);
11440
- BindTextures(checker.GetTextures(), checker.texres);
11954
+ try
11955
+ {
11956
+ BindTextures(checker.GetTextures(), checker.texres);
11957
+ }
11958
+ catch (Exception e)
11959
+ {
11960
+ System.err.println("FAILED: " + checker.GetTextures());
11961
+ }
1144111962 // NEAREST
1144211963 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
1144311964 DrawChecker(gl);
....@@ -11519,7 +12040,7 @@
1151912040 return;
1152012041 }
1152112042
11522
- String string = obj.GetToolTip();
12043
+ String string = obj.toString(); //.GetToolTip();
1152312044
1152412045 GL gl = GetGL();
1152512046
....@@ -11836,8 +12357,8 @@
1183612357 //obj.TransformToWorld(light, light);
1183712358 for (int i = tp.size(); --i >= 0;)
1183812359 {
11839
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
11840
- LA.xformPos(light, tp.get(i).toParent, light);
12360
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12361
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1184112362 }
1184212363
1184312364
....@@ -11854,8 +12375,8 @@
1185412375 parentcam = cameras[0];
1185512376 }
1185612377
11857
- for (int count = parentcam.GetTransformCount(); --count>=0;)
11858
- LA.xformPos(light, parentcam.toParent, light); // may 2013
12378
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
12379
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1185912380
1186012381 LA.xformPos(light, renderCamera.toScreen, light);
1186112382
....@@ -11945,8 +12466,76 @@
1194512466
1194612467 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1194712468
11948
- String program =
12469
+ String programmin =
12470
+ // Min shader
1194912471 "!!ARBfp1.0\n" +
12472
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12473
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12474
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12475
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12476
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12477
+ "PARAM light2cam0 = program.env[10];" +
12478
+ "PARAM light2cam1 = program.env[11];" +
12479
+ "PARAM light2cam2 = program.env[12];" +
12480
+ "TEMP temp;" +
12481
+ "TEMP light;" +
12482
+ "TEMP ndotl;" +
12483
+ "TEMP normal;" +
12484
+ "TEMP depth;" +
12485
+ "TEMP eye;" +
12486
+ "TEMP pos;" +
12487
+
12488
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12489
+ Normalize("normal") +
12490
+ "MOV light, state.light[0].position;" +
12491
+ "DP3 ndotl.x, light, normal;" +
12492
+
12493
+ // shadow
12494
+ "MOV pos, fragment.texcoord[1];" +
12495
+ "MOV temp, pos;" +
12496
+ ShadowTextureFetch("depth", "temp", "1") +
12497
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12498
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12499
+
12500
+ // No shadow when out of frustum
12501
+ //"SGE temp.y, depth.z, zero123.y;" +
12502
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12503
+
12504
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12505
+
12506
+ // Backlit
12507
+ "MOV pos.w, zero123.y;" +
12508
+ "DP4 eye.x, pos, light2cam0;" +
12509
+ "DP4 eye.y, pos, light2cam1;" +
12510
+ "DP4 eye.z, pos, light2cam2;" +
12511
+ Normalize("eye") +
12512
+
12513
+ "DP3 ndotl.y, -eye, normal;" +
12514
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12515
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12516
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12517
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12518
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12519
+
12520
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12521
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12522
+
12523
+ // Pigment
12524
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12525
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12526
+ "MUL temp, temp, ndotl.x;" +
12527
+
12528
+ "MUL temp, temp, zero123.z;" +
12529
+
12530
+ //"MUL temp, temp, ndotl.y;" +
12531
+
12532
+ "MOV temp.w, zero123.y;" + // reset alpha
12533
+ "MOV result.color, temp;" +
12534
+ "END";
12535
+
12536
+ String programmax =
12537
+ "!!ARBfp1.0\n" +
12538
+
1195012539 //"OPTION ARB_fragment_program_shadow;" +
1195112540 "PARAM light2cam0 = program.env[10];" +
1195212541 "PARAM light2cam1 = program.env[11];" +
....@@ -12061,8 +12650,7 @@
1206112650 "TEMP shininess;" +
1206212651 "\n" +
1206312652 "MOV texSamp, one;" +
12064
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12065
-
12653
+
1206612654 "MOV mapgrid.x, one2048th.x;" +
1206712655 "MOV temp, fragment.texcoord[1];" +
1206812656 /*
....@@ -12083,20 +12671,20 @@
1208312671 "MUL temp, floor, mapgrid.x;" +
1208412672 //"TEX depth0, temp, texture[1], 2D;" +
1208512673 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12086
- TextureFetch("depth0", "temp", "1") +
12674
+ ShadowTextureFetch("depth0", "temp", "1") +
1208712675 "") +
1208812676 "ADD temp.x, temp.x, mapgrid.x;" +
1208912677 //"TEX depth1, temp, texture[1], 2D;" +
1209012678 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12091
- TextureFetch("depth1", "temp", "1") +
12679
+ ShadowTextureFetch("depth1", "temp", "1") +
1209212680 "") +
1209312681 "ADD temp.y, temp.y, mapgrid.x;" +
1209412682 //"TEX depth2, temp, texture[1], 2D;" +
12095
- TextureFetch("depth2", "temp", "1") +
12683
+ ShadowTextureFetch("depth2", "temp", "1") +
1209612684 "SUB temp.x, temp.x, mapgrid.x;" +
1209712685 //"TEX depth3, temp, texture[1], 2D;" +
1209812686 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12099
- TextureFetch("depth3", "temp", "1") +
12687
+ ShadowTextureFetch("depth3", "temp", "1") +
1210012688 "") +
1210112689 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1210212690 //"MOV params, material;" +
....@@ -12467,10 +13055,10 @@
1246713055 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1246813056 "") +
1246913057
12470
- // display shadow only (bump == 0)
13058
+ // display shadow only (fakedepth == 0)
1247113059 "SUB temp.x, half.x, shadow.x;" +
12472
- "MOV temp.y, -params6.x;" +
12473
- "SLT temp.z, temp.y, zero.x;" +
13060
+ "MOV temp.y, -params5.z;" + // params6.x;" +
13061
+ "SLT temp.z, temp.y, -c256i.x;" +
1247413062 "SUB temp.y, one.x, temp.z;" +
1247513063 "MUL temp.x, temp.x, temp.y;" +
1247613064 "KIL temp.x;" +
....@@ -12599,8 +13187,10 @@
1259913187 "MAX ndotl.x, ndotl.x, -ndotl.x;" +
1260013188
1260113189 "SUB temp.x, one.x, ndotl.x;" +
12602
- "ADD temp.x, temp.x, options2.z;" + // lightsheen
12603
- "ADD temp.y, one.y, options2.y;" + // sursurface
13190
+ // Tuning for default skin
13191
+ //"ADD temp.x, temp.x, options2.z;" + // lightsheen
13192
+ "MAD temp.x, options2.z, half.y, temp.x;" + // lightsheen
13193
+ "ADD temp.y, one.y, options2.y;" + // subsurface
1260413194 "MUL temp.x, temp.x, temp.y;" +
1260513195
1260613196 "MUL saturation, saturation, temp.xxxx;" +
....@@ -12748,7 +13338,7 @@
1274813338 "MUL final.y, fragment.texcoord[0].x, c256;" +
1274913339 "FLR final.x, final.y;" +
1275013340 "SUB final.y, final.y, final.x;" +
12751
- //"MUL final.x, final.x, c256i;" +
13341
+ "MUL final.x, final.x, c256i;" +
1275213342 "MOV final.z, zero.x;" +
1275313343 "MOV final.a, one.w;":""
1275413344 ) +
....@@ -12756,7 +13346,7 @@
1275613346 "MUL final.y, fragment.texcoord[0].y, c256;" +
1275713347 "FLR final.x, final.y;" +
1275813348 "SUB final.y, final.y, final.x;" +
12759
- //"MUL final.x, final.x, c256i;" +
13349
+ "MUL final.x, final.x, c256i;" +
1276013350 "MOV final.z, zero.x;" +
1276113351 "MOV final.a, one.w;":""
1276213352 ) +
....@@ -12799,7 +13389,14 @@
1279913389 //once = true;
1280013390 }
1280113391
12802
- System.out.print("Program #" + mode + "; length = " + program.length());
13392
+ String program = programmax;
13393
+
13394
+ if (Globals.MINSHADER)
13395
+ {
13396
+ program = programmin;
13397
+ }
13398
+
13399
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1280313400 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1280413401 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1280513402
....@@ -12892,25 +13489,26 @@
1289213489 return out;
1289313490 }
1289413491
12895
- String TextureFetch(String dest, String src, String unit)
13492
+ // Also does frustum culling
13493
+ String ShadowTextureFetch(String dest, String src, String unit)
1289613494 {
1289713495 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1289813496 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1289913497 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13498
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13499
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1290013500 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12901
- "SLT " + src + ".z, " + src + ".x, one.x;" +
12902
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12903
- "SLT " + src + ".z, " + src + ".y, one.x;" +
12904
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13501
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13502
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1290513503 //"SWZ buffer, temp, w,w,w,w;";
12906
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13504
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1290713505 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1290813506 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1290913507 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
12910
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13508
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1291113509
12912
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
12913
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13510
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13511
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1291413512 }
1291513513
1291613514 String Shadow(String depth, String shadow)
....@@ -12932,12 +13530,16 @@
1293213530
1293313531 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1293413532 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13533
+
13534
+ // Compare fragment depth in light space with shadowmap.
1293513535 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1293613536 "SGE temp.y, temp.x, zero.x;" +
12937
- "SUB " + shadow + ".y, one.x, temp.y;" +
13537
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13538
+
13539
+ // Reverse comparison
1293813540 "SUB temp.x, one.x, temp.x;" +
1293913541 "MUL " + shadow + ".x, temp.x, temp.y;" +
12940
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13542
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1294113543 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1294213544
1294313545 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -12951,6 +13553,10 @@
1295113553 // No shadow for backface
1295213554 "DP3 temp.x, normal, lightd;" +
1295313555 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13556
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13557
+
13558
+ // No shadow when out of frustum
13559
+ "SGE temp.x, " + depth + ".z, one.z;" +
1295413560 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1295513561 "";
1295613562 }
....@@ -13097,7 +13703,8 @@
1309713703 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1309813704 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1309913705 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13100
- Object3D.cVector2[] vector2buffer;
13706
+
13707
+ //Object3D.cVector2[] vector2buffer;
1310113708
1310213709 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1310313710 // OUT : diff, spec
....@@ -13113,9 +13720,10 @@
1311313720 "DP3 " + dest + ".z," + "normals," + "eye;" +
1311413721 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1311513722 //"MOV " + dest + ".w," + "normal.z;" +
13116
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
13117
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13118
- //"MOV " + dest + ".z," + "params2.w;" +
13723
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13724
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13725
+
13726
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1311913727 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1312013728 "RCP " + dest + ".w," + dest + ".w;" +
1312113729 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13509,7 +14117,7 @@
1350914117 public void mousePressed(MouseEvent e)
1351014118 {
1351114119 //System.out.println("mousePressed: " + e);
13512
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14120
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1351314121 }
1351414122
1351514123 static long prevtime = 0;
....@@ -13585,8 +14193,8 @@
1358514193 // mode |= META;
1358614194 //}
1358714195
13588
- SetMouseMode(WHEEL | e.getModifiersEx());
13589
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14196
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14197
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1359014198 anchorX = ax;
1359114199 anchorY = ay;
1359214200 prevX = px;
....@@ -13620,6 +14228,7 @@
1362014228 else
1362114229 if (evt.getSource() == AAtimer)
1362214230 {
14231
+ Globals.TIMERRUNNING = false;
1362314232 if (mouseDown)
1362414233 {
1362514234 //new Exception().printStackTrace();
....@@ -13645,6 +14254,10 @@
1364514254 // LIVE = waslive;
1364614255 // wasliveok = true;
1364714256 // waslive = false;
14257
+
14258
+ // May 2019 Forget it:
14259
+ if (true)
14260
+ return;
1364814261
1364914262 // source == timer
1365014263 if (mouseDown)
....@@ -13675,7 +14288,7 @@
1367514288
1367614289 // fev 2014???
1367714290 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13678
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14291
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1367914292 pingthread.StepToTarget(true); // true);
1368014293 }
1368114294 // if (!LIVE)
....@@ -13684,12 +14297,13 @@
1368414297
1368514298 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1368614299
13687
- void clickStart(int x, int y, int modifiers)
14300
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1368814301 {
1368914302 if (!wasliveok)
1369014303 return;
1369114304
1369214305 AAtimer.restart(); //
14306
+ Globals.TIMERRUNNING = true;
1369314307
1369414308 // waslive = LIVE;
1369514309 // LIVE = false;
....@@ -13701,7 +14315,7 @@
1370114315 // touched = true; // main DL
1370214316 if (isRenderer)
1370314317 {
13704
- SetMouseMode(modifiers);
14318
+ SetMouseMode(modifiers, modifiersex);
1370514319 }
1370614320
1370714321 selectX = anchorX = x;
....@@ -13714,7 +14328,7 @@
1371414328 clicked = true;
1371514329 hold = false;
1371614330
13717
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14331
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1371814332 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1371914333 {
1372014334 // System.out.println("RESTART II " + modifiers);
....@@ -13739,14 +14353,15 @@
1373914353 drag = false;
1374014354 //System.out.println("Mouse DOWN");
1374114355 editObj = false;
13742
- ClickInfo info = new ClickInfo();
13743
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
13744
- info.pane = this;
13745
- info.camera = renderCamera;
13746
- info.x = x;
13747
- info.y = y;
13748
- info.modifiers = modifiers;
13749
- editObj = object.doEditClick(info, 0);
14356
+ //ClickInfo info = new ClickInfo();
14357
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14358
+ object.clickInfo.pane = this;
14359
+ object.clickInfo.camera = renderCamera;
14360
+ object.clickInfo.x = x;
14361
+ object.clickInfo.y = y;
14362
+ object.clickInfo.modifiers = modifiersex;
14363
+ editObj = object.doEditClick(//info,
14364
+ 0);
1375014365 if (!editObj)
1375114366 {
1375214367 hasMarquee = true;
....@@ -13762,9 +14377,12 @@
1376214377
1376314378 public void mouseDragged(MouseEvent e)
1376414379 {
14380
+ Globals.MOUSEDRAGGED = true;
14381
+
1376514382 //System.out.println("mouseDragged: " + e);
1376614383 if (isRenderer)
1376714384 movingcamera = true;
14385
+
1376814386 //if (drawing)
1376914387 //return;
1377014388 if ((e.getModifiersEx() & CTRL) != 0
....@@ -13774,7 +14392,7 @@
1377414392 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1377514393 }
1377614394 else
13777
- drag(e.getX(), e.getY(), e.getModifiersEx());
14395
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1377814396
1377914397 //try { Thread.sleep(1); } catch (Exception ex) {}
1378014398 }
....@@ -14011,7 +14629,7 @@
1401114629 {
1401214630 Globals.lighttouched = true;
1401314631 }
14014
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14632
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1401514633 }
1401614634 //else
1401714635 }
....@@ -14025,12 +14643,12 @@
1402514643 void GoDown(int mod)
1402614644 {
1402714645 MODIFIERS |= COMMAND;
14028
- /*
14646
+ /**/
1402914647 if((mod&SHIFT) == SHIFT)
14030
- manipCamera.RotatePosition(0, -speed);
14648
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
1403114649 else
14032
- manipCamera.BackForth(0, -speed*delta, getWidth());
14033
- */
14650
+ manipCamera.RotatePosition(0, -speed);
14651
+ /**/
1403414652 if ((mod & SHIFT) == SHIFT)
1403514653 {
1403614654 mouseMode = mouseMode; // VR??
....@@ -14046,12 +14664,12 @@
1404614664 void GoUp(int mod)
1404714665 {
1404814666 MODIFIERS |= COMMAND;
14049
- /*
14667
+ /**/
1405014668 if((mod&SHIFT) == SHIFT)
14051
- manipCamera.RotatePosition(0, speed);
14669
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
1405214670 else
14053
- manipCamera.BackForth(0, speed*delta, getWidth());
14054
- */
14671
+ manipCamera.RotatePosition(0, speed);
14672
+ /**/
1405514673 if ((mod & SHIFT) == SHIFT)
1405614674 {
1405714675 mouseMode = mouseMode;
....@@ -14067,12 +14685,12 @@
1406714685 void GoLeft(int mod)
1406814686 {
1406914687 MODIFIERS |= COMMAND;
14070
- /*
14688
+ /**/
1407114689 if((mod&SHIFT) == SHIFT)
14072
- manipCamera.RotatePosition(speed, 0);
14073
- else
1407414690 manipCamera.Translate(speed*delta, 0, getWidth());
14075
- */
14691
+ else
14692
+ manipCamera.RotatePosition(speed, 0);
14693
+ /**/
1407614694 if ((mod & SHIFT) == SHIFT)
1407714695 {
1407814696 mouseMode = mouseMode;
....@@ -14088,12 +14706,12 @@
1408814706 void GoRight(int mod)
1408914707 {
1409014708 MODIFIERS |= COMMAND;
14091
- /*
14709
+ /**/
1409214710 if((mod&SHIFT) == SHIFT)
14093
- manipCamera.RotatePosition(-speed, 0);
14094
- else
1409514711 manipCamera.Translate(-speed*delta, 0, getWidth());
14096
- */
14712
+ else
14713
+ manipCamera.RotatePosition(-speed, 0);
14714
+ /**/
1409714715 if ((mod & SHIFT) == SHIFT)
1409814716 {
1409914717 mouseMode = mouseMode;
....@@ -14111,7 +14729,7 @@
1411114729 int X, Y;
1411214730 boolean SX, SY;
1411314731
14114
- void drag(int x, int y, int modifiers)
14732
+ void drag(int x, int y, int modifiers, int modifiersex)
1411514733 {
1411614734 if (IsFrozen())
1411714735 {
....@@ -14120,17 +14738,17 @@
1412014738
1412114739 drag = true; // NEW
1412214740
14123
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14741
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1412414742
1412514743 X = x;
1412614744 Y = y;
1412714745 // floating state for animation
14128
- MODIFIERS = modifiers;
14129
- modifiers &= ~1024;
14746
+ MODIFIERS = modifiersex;
14747
+ modifiersex &= ~1024;
1413014748 if (false) // modifiers != 0)
1413114749 {
1413214750 //new Exception().printStackTrace();
14133
- System.out.println("mouseDragged: " + modifiers);
14751
+ System.out.println("mouseDragged: " + modifiersex);
1413414752 System.out.println("SHIFT = " + SHIFT);
1413514753 System.out.println("CONTROL = " + COMMAND);
1413614754 System.out.println("META = " + META);
....@@ -14143,14 +14761,16 @@
1414314761 if (editObj)
1414414762 {
1414514763 drag = true;
14146
- ClickInfo info = new ClickInfo();
14147
- info.bounds.setBounds(0, 0,
14764
+ //ClickInfo info = new ClickInfo();
14765
+ object.clickInfo.bounds.setBounds(0, 0,
1414814766 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14149
- info.pane = this;
14150
- info.camera = renderCamera;
14151
- info.x = x;
14152
- info.y = y;
14153
- object.editWindow.copy.doEditDrag(info);
14767
+ object.clickInfo.pane = this;
14768
+ object.clickInfo.camera = renderCamera;
14769
+ object.clickInfo.x = x;
14770
+ object.clickInfo.y = y;
14771
+ object //.GetWindow().copy
14772
+ .doEditDrag(//info,
14773
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1415414774 } else
1415514775 {
1415614776 if (x < startX)
....@@ -14299,22 +14919,27 @@
1429914919 }
1430014920 }
1430114921
14922
+// ClickInfo clickInfo = new ClickInfo();
14923
+
1430214924 public void mouseMoved(MouseEvent e)
1430314925 {
1430414926 //System.out.println("mouseMoved: " + e);
1430514927 if (isRenderer)
1430614928 return;
1430714929
14308
- ClickInfo ci = new ClickInfo();
14309
- ci.x = e.getX();
14310
- ci.y = e.getY();
14311
- ci.modifiers = e.getModifiersEx();
14312
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14313
- ci.pane = this;
14314
- ci.camera = renderCamera;
14930
+ // Mouse cursor feedback
14931
+ object.clickInfo.x = e.getX();
14932
+ object.clickInfo.y = e.getY();
14933
+ object.clickInfo.modifiers = e.getModifiersEx();
14934
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14935
+ object.clickInfo.pane = this;
14936
+ object.clickInfo.camera = renderCamera;
1431514937 if (!isRenderer)
1431614938 {
14317
- if (object.editWindow.copy.doEditClick(ci, 0))
14939
+ //ObjEditor editWindow = object.editWindow;
14940
+ //Object3D copy = editWindow.copy;
14941
+ if (object.doEditClick(//clickInfo,
14942
+ 0))
1431814943 {
1431914944 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1432014945 } else
....@@ -14326,7 +14951,11 @@
1432614951
1432714952 public void mouseReleased(MouseEvent e)
1432814953 {
14954
+ Globals.MOUSEDRAGGED = false;
14955
+
1432914956 movingcamera = false;
14957
+ X = 0; // getBounds().width/2;
14958
+ Y = 0; // getBounds().height/2;
1433014959 //System.out.println("mouseReleased: " + e);
1433114960 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1433214961 }
....@@ -14349,9 +14978,9 @@
1434914978 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1435014979 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1435114980
14352
- if (control || command || IsFrozen())
14981
+// No delay if (control || command || IsFrozen())
1435314982 timeout = true;
14354
- else
14983
+// ?? May 2019 else
1435514984 // timer.setDelay((modifiers & 128) != 0?0:350);
1435614985 mouseDown = false;
1435714986 if (!control && !command) // june 2013
....@@ -14461,7 +15090,7 @@
1446115090 System.out.println("keyReleased: " + e);
1446215091 }
1446315092
14464
- void SetMouseMode(int modifiers)
15093
+ void SetMouseMode(int modifiers, int modifiersex)
1446515094 {
1446615095 //System.out.println("SetMouseMode = " + modifiers);
1446715096 //modifiers &= ~1024;
....@@ -14473,25 +15102,25 @@
1447315102 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1447415103 // return;
1447515104 //System.out.println("SetMode = " + modifiers);
14476
- if ((modifiers & WHEEL) == WHEEL)
15105
+ if ((modifiersex & WHEEL) == WHEEL)
1447715106 {
1447815107 mouseMode |= ZOOM;
1447915108 }
1448015109
1448115110 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
14482
- if (capsLocked || (modifiers & META) == META)
15111
+ if (capsLocked) // || (modifiers & META) == META)
1448315112 {
1448415113 mouseMode |= VR; // BACKFORTH;
1448515114 }
14486
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
15115
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1448715116 {
1448815117 mouseMode |= SELECT;
1448915118 }
14490
- if ((modifiers & COMMAND) == COMMAND)
15119
+ if ((modifiersex & COMMAND) == COMMAND)
1449115120 {
1449215121 mouseMode |= SELECT;
1449315122 }
14494
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15123
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
1449515124 {
1449615125 mouseMode &= ~VR;
1449715126 mouseMode |= TRANSLATE;
....@@ -14520,7 +15149,7 @@
1452015149
1452115150 if (isRenderer) //
1452215151 {
14523
- SetMouseMode(modifiers);
15152
+ SetMouseMode(0, modifiers);
1452415153 }
1452515154
1452615155 Globals.theRenderer.keyPressed(key);
....@@ -14582,7 +15211,8 @@
1458215211 // break;
1458315212 case 'T':
1458415213 CACHETEXTURE ^= true;
14585
- textures.clear();
15214
+ texturepigment.clear();
15215
+ texturebump.clear();
1458615216 // repaint();
1458715217 break;
1458815218 case 'Y':
....@@ -14667,7 +15297,9 @@
1466715297 case 'E' : COMPACT ^= true;
1466815298 repaint();
1466915299 break;
14670
- case 'W' : DEBUGHSB ^= true;
15300
+ case 'W' : // Wide Window (fullscreen)
15301
+ //DEBUGHSB ^= true;
15302
+ ObjEditor.theFrame.ToggleFullScreen();
1467115303 repaint();
1467215304 break;
1467315305 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14692,8 +15324,8 @@
1469215324 RevertCamera();
1469315325 repaint();
1469415326 break;
14695
- case 'L':
1469615327 case 'l':
15328
+ //case 'L':
1469715329 if (lightMode)
1469815330 {
1469915331 lightMode = false;
....@@ -14757,20 +15389,24 @@
1475715389 OCCLUSION_CULLING ^= true;
1475815390 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1475915391 break;
14760
- case '0': envyoff ^= true; repaint(); break;
15392
+ //case '0': envyoff ^= true; repaint(); break;
1476115393 case '1':
1476215394 case '2':
1476315395 case '3':
1476415396 case '4':
1476515397 case '5':
14766
- newenvy = Character.getNumericValue(key);
14767
- repaint();
14768
- break;
1476915398 case '6':
1477015399 case '7':
1477115400 case '8':
1477215401 case '9':
14773
- BGcolor = (key - '6')/3.f;
15402
+ if (true) // envyoff)
15403
+ {
15404
+ BGcolor = (key - '1')/8.f;
15405
+ }
15406
+ else
15407
+ {
15408
+ //newenvy = Character.getNumericValue(key);
15409
+ }
1477415410 repaint();
1477515411 break;
1477615412 case '!':
....@@ -14836,9 +15472,9 @@
1483615472 case '_':
1483715473 kompactbit = 5;
1483815474 break;
14839
- case '+':
14840
- kompactbit = 6;
14841
- break;
15475
+// case '+':
15476
+// kompactbit = 6;
15477
+// break;
1484215478 case ' ':
1484315479 lightMode ^= true;
1484415480 Globals.lighttouched = true;
....@@ -14850,13 +15486,14 @@
1485015486 case ESC:
1485115487 RENDERPROGRAM += 1;
1485215488 RENDERPROGRAM %= 3;
15489
+
1485315490 repaint();
1485415491 break;
1485515492 case 'Z':
1485615493 //RESIZETEXTURE ^= true;
1485715494 //break;
1485815495 case 'z':
14859
- RENDERSHADOW ^= true;
15496
+ Globals.RENDERSHADOW ^= true;
1486015497 Globals.lighttouched = true;
1486115498 repaint();
1486215499 break;
....@@ -14889,8 +15526,9 @@
1488915526 case DELETE:
1489015527 ClearSelection();
1489115528 break;
14892
- /*
1489315529 case '+':
15530
+
15531
+ /*
1489415532 //fontsize += 1;
1489515533 bbzoom *= 2;
1489615534 repaint();
....@@ -14907,17 +15545,17 @@
1490715545 case '=':
1490815546 IncDepth();
1490915547 //fontsize += 1;
14910
- object.editWindow.refreshContents(true);
15548
+ object.GetWindow().refreshContents(true);
1491115549 maskbit = 6;
1491215550 break;
1491315551 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1491415552 DecDepth();
1491515553 maskbit = 5;
1491615554 //if(fontsize > 1) fontsize -= 1;
14917
- if (object.editWindow == null)
14918
- new Exception().printStackTrace();
14919
- else
14920
- object.editWindow.refreshContents(true);
15555
+// if (object.editWindow == null)
15556
+// new Exception().printStackTrace();
15557
+// else
15558
+ object.GetWindow().refreshContents(true);
1492115559 break;
1492215560 case '{':
1492315561 manipCamera.shaper_fovy /= 1.1;
....@@ -14980,7 +15618,7 @@
1498015618 //mode = ROTATE;
1498115619 if ((MODIFIERS & COMMAND) == 0) // VR??
1498215620 {
14983
- SetMouseMode(modifiers);
15621
+ SetMouseMode(0, modifiers);
1498415622 }
1498515623 }
1498615624
....@@ -15116,7 +15754,7 @@
1511615754 {
1511715755 //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
1511815756 //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15119
- if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (mouseMode & SELECT) == 0)
15757
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1512015758 {
1512115759 mouseMoved(e);
1512215760 } else
....@@ -15141,7 +15779,7 @@
1514115779 }
1514215780 */
1514315781
15144
- object.editWindow.EditSelection();
15782
+ object.GetWindow().EditSelection(false);
1514515783 }
1514615784
1514715785 void SelectParent()
....@@ -15158,10 +15796,10 @@
1515815796 {
1515915797 //selectees.remove(i);
1516015798 System.out.println("select parent of " + elem);
15161
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15799
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1516215800 } else
1516315801 {
15164
- group.editWindow.Select(elem.GetTreePath(), first, true);
15802
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1516515803 }
1516615804
1516715805 first = false;
....@@ -15203,12 +15841,12 @@
1520315841 for (int j = 0; j < group.children.size(); j++)
1520415842 {
1520515843 elem = (Object3D) group.children.elementAt(j);
15206
- object.editWindow.Select(elem.GetTreePath(), first, true);
15844
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1520715845 first = false;
1520815846 }
1520915847 } else
1521015848 {
15211
- object.editWindow.Select(elem.GetTreePath(), first, true);
15849
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1521215850 }
1521315851
1521415852 first = false;
....@@ -15219,21 +15857,21 @@
1521915857 {
1522015858 //Composite group = (Composite) object;
1522115859 Object3D group = object;
15222
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15860
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1522315861 }
1522415862
1522515863 void ResetTransform(int mask)
1522615864 {
1522715865 //Composite group = (Composite) object;
1522815866 Object3D group = object;
15229
- group.editWindow.ResetTransform(mask);
15867
+ group.GetWindow().ResetTransform(mask);
1523015868 }
1523115869
1523215870 void FlipTransform()
1523315871 {
1523415872 //Composite group = (Composite) object;
1523515873 Object3D group = object;
15236
- group.editWindow.FlipTransform();
15874
+ group.GetWindow().FlipTransform();
1523715875 // group.editWindow.ReduceMesh(true);
1523815876 }
1523915877
....@@ -15241,7 +15879,7 @@
1524115879 {
1524215880 //Composite group = (Composite) object;
1524315881 Object3D group = object;
15244
- group.editWindow.PrintMemory();
15882
+ group.GetWindow().PrintMemory();
1524515883 // group.editWindow.ReduceMesh(true);
1524615884 }
1524715885
....@@ -15249,7 +15887,7 @@
1524915887 {
1525015888 //Composite group = (Composite) object;
1525115889 Object3D group = object;
15252
- group.editWindow.ResetCentroid();
15890
+ group.GetWindow().ResetCentroid();
1525315891 }
1525415892
1525515893 void IncDepth()
....@@ -15331,11 +15969,11 @@
1533115969
1533215970 int width = getBounds().width;
1533315971 int height = getBounds().height;
15334
- ClickInfo info = new ClickInfo();
15335
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1533615972 //Image img = CreateImage(width, height);
1533715973 //System.out.println("width = " + width + "; height = " + height + "\n");
15974
+
1533815975 Graphics gr = g; // img.getGraphics();
15976
+
1533915977 if (!hasMarquee)
1534015978 {
1534115979 if (Xmin < Xmax) // !locked)
....@@ -15407,40 +16045,88 @@
1540716045 }
1540816046 if (object != null && !hasMarquee)
1540916047 {
16048
+ if (object.clickInfo == null)
16049
+ object.clickInfo = new ClickInfo();
16050
+ ClickInfo info = object.clickInfo;
16051
+ //ClickInfo info = new ClickInfo();
16052
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16053
+
1541016054 if (isRenderer)
1541116055 {
15412
- info.flags++;
16056
+ object.clickInfo.flags++;
1541316057 double frameAspect = (double) width / (double) height;
1541416058 if (frameAspect > renderCamera.aspect)
1541516059 {
1541616060 int desired = (int) ((double) height * renderCamera.aspect);
15417
- info.bounds.width -= width - desired;
15418
- info.bounds.x += (width - desired) / 2;
16061
+ object.clickInfo.bounds.width -= width - desired;
16062
+ object.clickInfo.bounds.x += (width - desired) / 2;
1541916063 } else
1542016064 {
1542116065 int desired = (int) ((double) width / renderCamera.aspect);
15422
- info.bounds.height -= height - desired;
15423
- info.bounds.y += (height - desired) / 2;
16066
+ object.clickInfo.bounds.height -= height - desired;
16067
+ object.clickInfo.bounds.y += (height - desired) / 2;
1542416068 }
1542516069 }
15426
- info.g = gr;
15427
- info.camera = renderCamera;
16070
+
16071
+ object.clickInfo.g = gr;
16072
+ object.clickInfo.camera = renderCamera;
1542816073 /*
1542916074 // Memory intensive (brep.verticescopy)
1543016075 if (!(object instanceof Composite))
1543116076 object.draw(info, 0, false); // SLOW :
1543216077 */
15433
- if (!isRenderer)
16078
+ if (!isRenderer) // && drag)
1543416079 {
15435
- object.drawEditHandles(info, 0);
16080
+ Grafreed.Assert(object != null);
16081
+ Grafreed.Assert(object.selection != null);
16082
+ if (object.selection.Size() > 0)
16083
+ {
16084
+ int hitSomething = object.selection.get(0).hitSomething;
16085
+
16086
+ object.clickInfo.DX = 0;
16087
+ object.clickInfo.DY = 0;
16088
+ object.clickInfo.W = 1;
16089
+ if (hitSomething == Object3D.hitCenter)
16090
+ {
16091
+ info.DX = X;
16092
+ if (X != 0)
16093
+ info.DX -= info.bounds.width/2;
16094
+
16095
+ info.DY = Y;
16096
+ if (Y != 0)
16097
+ info.DY -= info.bounds.height/2;
16098
+ }
16099
+
16100
+ object.drawEditHandles(//info,
16101
+ 0);
16102
+
16103
+ if (drag && (X != 0 || Y != 0))
16104
+ {
16105
+ switch (hitSomething)
16106
+ {
16107
+ case Object3D.hitCenter: gr.setColor(Color.pink);
16108
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16109
+ break;
16110
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16111
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16112
+ break;
16113
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16114
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16115
+ break;
16116
+ }
16117
+
16118
+ }
16119
+ }
1543616120 }
1543716121 }
16122
+
1543816123 if (isRenderer)
1543916124 {
1544016125 //gr.setColor(Color.black);
1544116126 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1544216127 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1544316128 }
16129
+
1544416130 if (hasMarquee)
1544516131 {
1544616132 gr.setXORMode(Color.white);
....@@ -15553,6 +16239,7 @@
1555316239 public boolean mouseDown(Event evt, int x, int y)
1555416240 {
1555516241 System.out.println("mouseDown: " + evt);
16242
+ System.exit(0);
1555616243 /*
1555716244 locked = true;
1555816245 drag = false;
....@@ -15596,7 +16283,7 @@
1559616283 {
1559716284 keyPressed(0, modifiers);
1559816285 }
15599
- clickStart(x, y, modifiers);
16286
+ // clickStart(x, y, modifiers);
1560016287 return true;
1560116288 }
1560216289
....@@ -15714,7 +16401,7 @@
1571416401 {
1571516402 keyReleased(0, 0);
1571616403 }
15717
- drag(x, y, modifiers);
16404
+ drag(x, y, 0, modifiers);
1571816405 return true;
1571916406 }
1572016407
....@@ -15846,7 +16533,7 @@
1584616533 Object3D object;
1584716534 static Object3D trackedobject;
1584816535 Camera renderCamera; // Light or Eye (or Occlusion)
15849
- /*static*/ Camera manipCamera; // Light or Eye
16536
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1585016537 /*static*/ Camera eyeCamera;
1585116538 /*static*/ Camera lightCamera;
1585216539 int cameracount;
....@@ -15910,6 +16597,8 @@
1591016597 private /*static*/ boolean firstime;
1591116598 private /*static*/ cVector newView = new cVector();
1591216599 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16600
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16601
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1591316602 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1591416603 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1591516604 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -15922,29 +16611,67 @@
1592216611 {
1592316612 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1592416613
16614
+ int usedsuf = 0;
16615
+
1592516616 for (int i = 0; i < suffixes.length; i++)
1592616617 {
15927
- String resourceName = basename + suffixes[i] + "." + suffix;
15928
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
15929
- mipmapped,
15930
- FileUtil.getFileSuffix(resourceName));
15931
- if (data == null)
16618
+ String[] suffixe = suffixes;
16619
+ String[] fallback = suffixes2;
16620
+ String[] fallfallback = suffixes3;
16621
+
16622
+ for (int c=usedsuf; --c>=0;)
1593216623 {
15933
- throw new IOException("Unable to load texture " + resourceName);
16624
+// String[] temp = suffixe;
16625
+// suffixe = fallback;
16626
+// fallback = fallfallback;
16627
+// fallfallback = temp;
1593416628 }
16629
+
16630
+ String resourceName = basename + suffixe[i] + "." + suffix;
16631
+ TextureData data;
16632
+
16633
+ try
16634
+ {
16635
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16636
+ mipmapped,
16637
+ FileUtil.getFileSuffix(resourceName));
16638
+ }
16639
+ catch (Exception e)
16640
+ {
16641
+ try
16642
+ {
16643
+ resourceName = basename + fallback[i] + "." + suffix;
16644
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16645
+ mipmapped,
16646
+ FileUtil.getFileSuffix(resourceName));
16647
+ }
16648
+ catch (Exception e2)
16649
+ {
16650
+ resourceName = basename + fallfallback[i] + "." + suffix;
16651
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16652
+ mipmapped,
16653
+ FileUtil.getFileSuffix(resourceName));
16654
+ }
16655
+ }
16656
+
1593516657 //System.out.println("Target = " + targets[i]);
1593616658 cubemap.updateImage(data, targets[i]);
1593716659 }
1593816660
1593916661 return cubemap;
1594016662 }
16663
+
1594116664 int bigsphere = -1;
1594216665
1594316666 float BGcolor = 0.5f;
1594416667
15945
- private void DrawSkyBox(GL gl)
16668
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16669
+
16670
+ private void DrawSkyBox(GL gl, float ratio)
1594616671 {
15947
- if (envyoff || cubemap == null)
16672
+ if (//envyoff ||
16673
+ WIREFRAME ||
16674
+ cubemap == null)
1594816675 {
1594916676 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1595016677 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -15959,7 +16686,17 @@
1595916686 // Compensates for ExaminerViewer's modification of modelview matrix
1596016687 gl.glMatrixMode(GL.GL_MODELVIEW);
1596116688 gl.glLoadIdentity();
16689
+ gl.glScalef(1,ratio,1);
1596216690
16691
+// colorV[0] = 2;
16692
+// colorV[1] = 2;
16693
+// colorV[2] = 2;
16694
+// colorV[3] = 1;
16695
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16696
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16697
+//
16698
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16699
+
1596316700 //gl.glActiveTexture(GL.GL_TEXTURE1);
1596416701 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1596516702
....@@ -15991,6 +16728,7 @@
1599116728 {
1599216729 gl.glScalef(1.0f, -1.0f, 1.0f);
1599316730 }
16731
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1599416732 gl.glMultMatrixd(viewrot_1, 0);
1599516733 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1599616734 //viewer.updateInverseRotation(gl);
....@@ -16131,16 +16869,16 @@
1613116869 cStatic.objectstack[materialdepth++] = checker;
1613216870 //System.out.println("material " + material);
1613316871 //Applet3D.tracein(this, selected);
16134
- vector2buffer = checker.projectedVertices;
16872
+ //vector2buffer = checker.projectedVertices;
1613516873
1613616874 //checker.GetMaterial().Draw(this, false); // true);
16137
- DrawMaterial(checker.GetMaterial(), false); // true);
16875
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1613816876
1613916877 materialdepth -= 1;
1614016878 if (materialdepth > 0)
1614116879 {
16142
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16143
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
16880
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16881
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1614416882 }
1614516883 //checker.GetMaterial().opacity = 1f;
1614616884 ////checker.GetMaterial().ambient = 1f;
....@@ -16226,6 +16964,14 @@
1622616964 }
1622716965 }
1622816966
16967
+ private Object3D GetFolder()
16968
+ {
16969
+ Object3D folder = object.GetWindow().copy;
16970
+ if (object.GetWindow().copy.selection.Size() > 0)
16971
+ folder = object.GetWindow().copy.selection.elementAt(0);
16972
+ return folder;
16973
+ }
16974
+
1622916975 class SelectBuffer implements GLEventListener
1623016976 {
1623116977
....@@ -16241,7 +16987,7 @@
1624116987 //new Exception().printStackTrace();
1624216988 System.out.println("select buffer init");
1624316989 // Use debug pipeline
16244
- drawable.setGL(new DebugGL(drawable.getGL()));
16990
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1624516991
1624616992 GL gl = drawable.getGL();
1624716993
....@@ -16305,6 +17051,17 @@
1630517051
1630617052 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1630717053
17054
+ if (PAINTMODE)
17055
+ {
17056
+ if (object.GetWindow().copy.selection.Size() > 0)
17057
+ {
17058
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17059
+
17060
+ // Make what you paint not selectable.
17061
+ paintobj.ResetSelectable();
17062
+ }
17063
+ }
17064
+
1630817065 //int tmp = selection_view;
1630917066 //selection_view = -1;
1631017067 int temp = DrawMode();
....@@ -16316,6 +17073,17 @@
1631617073 // temp = DEFAULT; // patch for selection debug
1631717074 Globals.drawMode = temp; // WARNING
1631817075
17076
+ if (PAINTMODE)
17077
+ {
17078
+ if (object.GetWindow().copy.selection.Size() > 0)
17079
+ {
17080
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17081
+
17082
+ // Revert.
17083
+ paintobj.RestoreSelectable();
17084
+ }
17085
+ }
17086
+
1631917087 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1632017088
1632117089 // trying different ways of getting the depth info over
....@@ -16363,6 +17131,8 @@
1636317131 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1636417132 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1636517133 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
17134
+
17135
+ CreateSelectedPoint();
1636617136
1636717137 // Will fit the mesh !!!
1636817138 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16412,34 +17182,36 @@
1641217182 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]));
1641317183 }
1641417184
16415
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
17185
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1641617186 }
1641717187 }
1641817188
1641917189 if (!movingcamera && !PAINTMODE)
16420
- object.editWindow.ScreenFitPoint(); // fev 2014
17190
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1642117191
16422
- if (PAINTMODE && GrafreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17192
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1642317193 {
16424
- Object3D paintobj = GrafreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17194
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1642517195
16426
- Object3D group = new Object3D("inst" + paintcount++);
17196
+ if (object.GetWindow().copy.selection.Size() > 0)
17197
+ {
17198
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1642717199
16428
- group.CreateMaterial(); // use a void leaf to select instances
16429
-
16430
- group.add(paintobj); // link
16431
-
16432
- object.editWindow.SnapObject(group);
16433
-
16434
- Object3D folder = object.editWindow.copy;
16435
-
16436
- if (object.editWindow.copy.selection.Size() > 0)
16437
- folder = object.editWindow.copy.selection.elementAt(0);
16438
-
16439
- folder.add(group);
16440
-
16441
- object.editWindow.ResetModel();
16442
- object.editWindow.refreshContents();
17200
+ Object3D inst = new Object3D("inst" + paintcount++);
17201
+
17202
+ inst.CreateMaterial(); // use a void leaf to select instances
17203
+
17204
+ inst.add(paintobj); // link
17205
+
17206
+ object.GetWindow().SnapObject(inst);
17207
+
17208
+ Object3D folder = paintFolder; // GetFolder();
17209
+
17210
+ folder.add(inst);
17211
+
17212
+ object.GetWindow().ResetModel();
17213
+ object.GetWindow().refreshContents();
17214
+ }
1644317215 }
1644417216 else
1644517217 paintcount = 0;
....@@ -16478,6 +17250,11 @@
1647817250 //System.out.println("objects[color] = " + objects[color]);
1647917251 //objects[color].Select();
1648017252 indexcount = 0;
17253
+ ObjEditor window = object.GetWindow();
17254
+ if (window != null && deselect)
17255
+ {
17256
+ window.Select(null, deselect, true);
17257
+ }
1648117258 object.Select(color, deselect);
1648217259 }
1648317260
....@@ -16577,7 +17354,7 @@
1657717354 gl.glDisable(gl.GL_CULL_FACE);
1657817355 }
1657917356
16580
- if (!RENDERSHADOW)
17357
+ if (!Globals.RENDERSHADOW)
1658117358 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1658217359
1658317360 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -16587,7 +17364,7 @@
1658717364 //gl.glColorMask(false, false, false, false);
1658817365
1658917366 //render_scene_from_light_view(gl, drawable, 0, 0);
16590
- if (RENDERSHADOW && Globals.lighttouched && !movingcamera) // && !parent.IsFreezed())
17367
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1659117368 {
1659217369 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1659317370
....@@ -17003,23 +17780,15 @@
1700317780 int AAbuffersize = 0;
1700417781
1700517782 //double[] selectedpoint = new double[3];
17006
- static Superellipsoid selectedpoint = new Superellipsoid();
17783
+ static Superellipsoid selectedpoint;
1700717784 static Sphere previousselectedpoint = null;
17008
- static Sphere debugpointG = new Sphere();
17009
- static Sphere debugpointP = new Sphere();
17010
- static Sphere debugpointC = new Sphere();
17011
- static Sphere debugpointR = new Sphere();
17785
+ static Sphere debugpointG;
17786
+ static Sphere debugpointP;
17787
+ static Sphere debugpointC;
17788
+ static Sphere debugpointR;
1701217789
1701317790 static Sphere debugpoints[] = new Sphere[8];
1701417791
17015
- static
17016
- {
17017
- for (int i=0; i<8; i++)
17018
- {
17019
- debugpoints[i] = new Sphere();
17020
- }
17021
- }
17022
-
1702317792 static void InitPoints(float radius)
1702417793 {
1702517794 for (int i=0; i<8; i++)