Normand Briere
2019-08-12 b1d79b74514041a059b454a9f6fc3970773c0cb8
CameraPane.java
....@@ -18,7 +18,10 @@
1818 import javax.imageio.ImageIO;
1919 import javax.imageio.ImageWriteParam;
2020 import javax.imageio.ImageWriter;
21
+import javax.imageio.ImageReadParam;
22
+import javax.imageio.ImageReader;
2123 import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
24
+import javax.imageio.stream.ImageInputStream;
2225 import javax.imageio.stream.ImageOutputStream;
2326 import javax.imageio.ImageWriteParam;
2427
....@@ -30,6 +33,7 @@
3033 import java.nio.*;
3134
3235 import gleem.linalg.Mat4f;
36
+import javax.imageio.ImageTypeSpecifier;
3337
3438 class CameraPane extends GLCanvas implements iCameraPane, Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener
3539 {
....@@ -37,7 +41,6 @@
3741 static boolean[] selectedstack = new boolean[65536];
3842 static int materialdepth = 0;
3943
40
- static boolean DEBUG = false;
4144 static boolean FRUSTUM = false; // still bogus true; // frustum culling
4245
4346 // camera change fix
....@@ -45,6 +48,39 @@
4548 static boolean ABORTED = false;
4649
4750 static int STEP = 1;
51
+
52
+ private static BufferedImage CreateBim(byte[] bytes, int width, int height)
53
+ {
54
+ int[] pixels = new int[bytes.length/3];
55
+ for (int i=pixels.length; --i>=0;)
56
+ {
57
+ int i3 = i*3;
58
+ pixels[i] = 0xFF;
59
+ pixels[i] <<= 8;
60
+ pixels[i] |= bytes[i3+2] & 0xFF;
61
+ pixels[i] <<= 8;
62
+ pixels[i] |= bytes[i3+1] & 0xFF;
63
+ pixels[i] <<= 8;
64
+ pixels[i] |= bytes[i3] & 0xFF;
65
+ }
66
+ /*
67
+ int r=0,g=0,b=0,a=0;
68
+ for (int i=0; i<width; i++)
69
+ for (int j=0; j<height; j++)
70
+ {
71
+ int index = j*width+i;
72
+ int p = pixels[index];
73
+ a = ((p>>24) & 0xFF);
74
+ r = ((p>>16) & 0xFF);
75
+ g = ((p>>8) & 0xFF);
76
+ b = (p & 0xFF);
77
+ pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
78
+ }
79
+ /**/
80
+ BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
81
+ rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
82
+ return rendImage;
83
+ }
4884
4985 /*static*/ private boolean CULLFACE = false; // true;
5086 /*static*/ boolean NEAREST = false; // true;
....@@ -56,14 +92,12 @@
5692 static int CURRENTANTIALIAS = 0; // 1;
5793 /*static*/ boolean RENDERSHADOW = true;
5894 /*static*/ int RENDERPROGRAM = 2; // 0 == none, 1 == fast, 2 == normal
59
- static boolean ANIMATION = false;
60
- static String filename;
6195
6296 boolean DISPLAYTEXT = false;
6397 //boolean REDUCETEXTURE = true;
6498 boolean CACHETEXTURE = true;
6599 boolean CLEANCACHE = false; // true;
66
- boolean MIPMAP = false; // true;
100
+ boolean MIPMAP = false; // true; // never works...
67101 boolean COMPRESSTEXTURE = false;
68102 boolean KOMPACTTEXTURE = false; // true;
69103 boolean RESIZETEXTURE = false;
....@@ -86,7 +120,7 @@
86120 static boolean FULLSCREEN = false;
87121 static boolean SUPPORT = true;
88122 static boolean INERTIA = true;
89
-static boolean FAST = true; // false;
123
+static boolean FAST = false;
90124 static boolean SLOWPOSE = false;
91125 static boolean FOOTCONTACT = true;
92126
....@@ -108,7 +142,7 @@
108142 static boolean OEIL = true;
109143 static boolean OEILONCE = false; // do oeilon then oeiloff
110144 static boolean LOOKAT = true;
111
-static boolean RANDOM = true; // false;
145
+static boolean SWITCH = true; // false;
112146 static boolean HANDLES = false; // selection doesn't work!!
113147 static boolean PAINTMODE = false;
114148
....@@ -152,6 +186,20 @@
152186 defaultcaps.setAccumAlphaBits(16);
153187 }
154188
189
+ private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
190
+
191
+ public void LoadSkybox(String name, String ext, boolean mipmap) throws GLException
192
+ {
193
+ try
194
+ {
195
+ cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
196
+ } catch (IOException e)
197
+ {
198
+ System.out.println("NAME = " + name);
199
+ e.printStackTrace(); // throw new RuntimeException(e);
200
+ }
201
+ }
202
+
155203 void SetAsGLRenderer(boolean b)
156204 {
157205 isRenderer = b;
....@@ -170,7 +218,8 @@
170218
171219 SetCamera(cam);
172220
173
- SetLight(new Camera(new cVector(10, 10, -20)));
221
+ // Warning: not used.
222
+ SetLight(new Camera(new cVector(15, 10, -20)));
174223
175224 object = o;
176225
....@@ -327,7 +376,7 @@
327376 cStatic.objectstack[materialdepth++] = obj;
328377 //System.out.println("material " + material);
329378 //Applet3D.tracein(this, selected);
330
- display.vector2buffer = obj.projectedVertices;
379
+ //display.vector2buffer = obj.projectedVertices;
331380 if (obj instanceof Camera)
332381 {
333382 display.options1[0] = material.shift;
....@@ -336,14 +385,28 @@
336385 display.options1[2] = material.shadowbias;
337386 display.options1[3] = material.aniso;
338387 display.options1[4] = material.anisoV;
388
+// System.out.println("display.options1[0] " + display.options1[0]);
389
+// System.out.println("display.options1[1] " + display.options1[1]);
390
+// System.out.println("display.options1[2] " + display.options1[2]);
391
+// System.out.println("display.options1[3] " + display.options1[3]);
392
+// System.out.println("display.options1[4] " + display.options1[4]);
339393 display.options2[0] = material.opacity;
340394 display.options2[1] = material.diffuse;
341395 display.options2[2] = material.factor;
396
+// System.out.println("display.options2[0] " + display.options2[0]);
397
+// System.out.println("display.options2[1] " + display.options2[1]);
398
+// System.out.println("display.options2[2] " + display.options2[2]);
342399
343400 cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
401
+// System.out.println("display.options3[0] " + display.options3[0]);
402
+// System.out.println("display.options3[1] " + display.options3[1]);
403
+// System.out.println("display.options3[2] " + display.options3[2]);
344404 display.options4[0] = material.cameralight/0.2f;
345405 display.options4[1] = material.subsurface;
346406 display.options4[2] = material.sheen;
407
+// System.out.println("display.options4[0] " + display.options4[0]);
408
+// System.out.println("display.options4[1] " + display.options4[1]);
409
+// System.out.println("display.options4[2] " + display.options4[2]);
347410
348411 // if (display.CURRENTANTIALIAS > 0)
349412 // display.options3[3] /= 4;
....@@ -359,7 +422,7 @@
359422 /**/
360423 } else
361424 {
362
- DrawMaterial(material, selected);
425
+ DrawMaterial(material, selected, obj.projectedVertices);
363426 }
364427 } else
365428 {
....@@ -383,8 +446,8 @@
383446 cStatic.objectstack[materialdepth++] = obj;
384447 //System.out.println("material " + material);
385448 //Applet3D.tracein("selected ", selected);
386
- display.vector2buffer = obj.projectedVertices;
387
- display.DrawMaterial(material, selected);
449
+ //display.vector2buffer = obj.projectedVertices;
450
+ display.DrawMaterial(material, selected, obj.projectedVertices);
388451 }
389452 }
390453
....@@ -401,8 +464,8 @@
401464 materialdepth -= 1;
402465 if (materialdepth > 0)
403466 {
404
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
405
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
467
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
468
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
406469 }
407470 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
408471 } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
....@@ -422,8 +485,8 @@
422485 materialdepth -= 1;
423486 if (materialdepth > 0)
424487 {
425
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
426
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
488
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
489
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
427490 }
428491 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
429492 //else
....@@ -464,10 +527,12 @@
464527 if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
465528 {
466529 //gl.glBegin(gl.GL_TRIANGLES);
467
- boolean hasnorm = pv.norm != null; // && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0);
530
+ boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0)
531
+ // TEST LIVE NORMALS && !obj.dontselect
532
+ ;
468533 if (!hasnorm)
469534 {
470
- // System.out.println("FUCK!!");
535
+ // System.out.println("Mesh normal");
471536 LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
472537 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
473538 LA.vecCross(obj.v0, obj.v1, obj.v2);
....@@ -1192,10 +1257,12 @@
11921257 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
11931258 }
11941259 }
1260
+
11951261 if (flipV)
11961262 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
11971263 else
11981264 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1265
+
11991266 //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
12001267 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
12011268
....@@ -1215,10 +1282,12 @@
12151282 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
12161283 }
12171284 }
1285
+
12181286 if (flipV)
12191287 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12201288 else
12211289 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1290
+
12221291 //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
12231292 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
12241293
....@@ -1246,8 +1315,10 @@
12461315 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12471316 else
12481317 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1318
+
12491319 //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
12501320 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1321
+
12511322 count2 += 2;
12521323 count3 += 3;
12531324 }
....@@ -1426,6 +1497,8 @@
14261497 gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
14271498 }
14281499
1500
+ float[] colorV = new float[4];
1501
+
14291502 void SetColor(Object3D obj, Vertex p0)
14301503 {
14311504 CameraPane display = this;
....@@ -1493,8 +1566,6 @@
14931566 {
14941567 return;
14951568 }
1496
-
1497
- float[] colorV = new float[3];
14981569
14991570 if (false) // marked)
15001571 {
....@@ -1603,7 +1674,7 @@
16031674 // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
16041675 }
16051676
1606
- void DrawMaterial(cMaterial material, boolean selected)
1677
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
16071678 {
16081679 CameraPane display = this;
16091680 //new Exception().printStackTrace();
....@@ -1630,7 +1701,7 @@
16301701
16311702 cColor.HSBtoRGB(display.color, display.saturation, 1, display.modelParams0);
16321703
1633
- float[] colorV = GrafreeD.colorV;
1704
+ float[] colorV = Grafreed.colorV;
16341705
16351706 /**/
16361707 if (display.DrawMode() == display.DEFAULT) // && display.RENDERPROGRAM == 0)
....@@ -1638,7 +1709,7 @@
16381709 colorV[0] = display.modelParams0[0] * material.diffuse;
16391710 colorV[1] = display.modelParams0[1] * material.diffuse;
16401711 colorV[2] = display.modelParams0[2] * material.diffuse;
1641
- colorV[3] = material.opacity;
1712
+ colorV[3] = 1; // material.opacity;
16421713
16431714 gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
16441715 //System.out.println("Opacity = " + opacity);
....@@ -1746,9 +1817,9 @@
17461817 display.modelParams7[2] = 0;
17471818 display.modelParams7[3] = 0;
17481819
1749
- display.modelParams6[0] = 100; // criss de bug de bump
1820
+ //display.modelParams6[0] = 100; // criss de bug de bump
17501821
1751
- Object3D.cVector2[] extparams = display.vector2buffer;
1822
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
17521823 if (extparams != null && extparams.length > 0 && extparams[0] != null)
17531824 {
17541825 display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
....@@ -1890,7 +1961,7 @@
18901961 void PushMatrix(double[][] matrix)
18911962 {
18921963 // GrafreeD.tracein(matrix);
1893
- PushMatrix(matrix,1);
1964
+ PushMatrix(matrix, 1);
18941965 }
18951966
18961967 void PushMatrix()
....@@ -2044,7 +2115,7 @@
20442115 //System.err.println("Oeil on");
20452116 OEIL = true;
20462117 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2047
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2118
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
20482119 //pingthread.StepToTarget(true);
20492120 }
20502121
....@@ -2142,7 +2213,7 @@
21422213 System.err.println("LIVE = " + Globals.isLIVE());
21432214
21442215 if (!Globals.isLIVE()) // save sound
2145
- GrafreeD.savesound = true; // wav.save();
2216
+ Grafreed.savesound = true; // wav.save();
21462217 // else
21472218 repaint(); // start loop // may 2013
21482219 }
....@@ -2259,7 +2330,7 @@
22592330
22602331 void ToggleDebug()
22612332 {
2262
- DEBUG ^= true;
2333
+ Globals.DEBUG ^= true;
22632334 }
22642335
22652336 void ToggleLookAt()
....@@ -2267,9 +2338,9 @@
22672338 LOOKAT ^= true;
22682339 }
22692340
2270
- void ToggleRandom()
2341
+ void ToggleSwitch()
22712342 {
2272
- RANDOM ^= true;
2343
+ SWITCH ^= true;
22732344 }
22742345
22752346 void ToggleHandles()
....@@ -2277,10 +2348,17 @@
22772348 HANDLES ^= true;
22782349 }
22792350
2351
+ Object3D paintFolder;
2352
+
22802353 void TogglePaint()
22812354 {
22822355 PAINTMODE ^= true;
22832356 paintcount = 0;
2357
+
2358
+ if (PAINTMODE)
2359
+ {
2360
+ paintFolder = GetFolder();
2361
+ }
22842362 }
22852363
22862364 void SwapCamera(int a, int b)
....@@ -2376,7 +2454,22 @@
23762454 {
23772455 return currentGL;
23782456 }
2379
-
2457
+
2458
+ static private BufferedImage CreateBim(TextureData texturedata)
2459
+ {
2460
+ Grafreed.Assert(texturedata != null);
2461
+
2462
+ int width = texturedata.getWidth();
2463
+ int height = texturedata.getHeight();
2464
+
2465
+ Buffer buffer = texturedata.getBuffer();
2466
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2467
+
2468
+ byte[] bytes = bytebuf.array();
2469
+
2470
+ return CreateBim(bytes, width, height);
2471
+ }
2472
+
23802473 /**/
23812474 class CacheTexture
23822475 {
....@@ -2385,28 +2478,31 @@
23852478
23862479 int resolution;
23872480
2388
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2481
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
23892482 {
2390
- texture = tex;
2483
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2484
+ texturedata = texdata;
23912485 resolution = res;
23922486 }
23932487 }
23942488 /**/
23952489
23962490 // TEXTURE static Texture texture;
2397
- static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures
2398
- = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>();
2399
- static public java.util.Hashtable<String, String> usedtextures = new java.util.Hashtable<String, String>();
2491
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2492
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2493
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2494
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2495
+
24002496 int pigmentdepth = 0;
24012497 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
24022498 int bumpdepth = 0;
24032499 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
24042500 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
24052501 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2406
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2502
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
24072503 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
24082504
2409
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2505
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
24102506 {
24112507 TextureData texturedata = null;
24122508
....@@ -2425,13 +2521,34 @@
24252521 if (bump)
24262522 texturedata = ConvertBump(texturedata, false);
24272523
2428
- com.sun.opengl.util.texture.Texture texture =
2429
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2524
+// com.sun.opengl.util.texture.Texture texture =
2525
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
24302526
2431
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2432
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
2527
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2528
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
24332529
2434
- return texture;
2530
+ return texturedata;
2531
+ }
2532
+
2533
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2534
+ {
2535
+ TextureData texturedata = null;
2536
+
2537
+ try
2538
+ {
2539
+ texturedata =
2540
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2541
+ bim,
2542
+ true);
2543
+ } catch (Exception e)
2544
+ {
2545
+ throw new javax.media.opengl.GLException(e);
2546
+ }
2547
+
2548
+ if (bump)
2549
+ texturedata = ConvertBump(texturedata, false);
2550
+
2551
+ return texturedata;
24352552 }
24362553
24372554 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3504,6 +3621,8 @@
35043621
35053622 System.out.println("LOADING TEXTURE : " + name);
35063623
3624
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3625
+
35073626 //
35083627 if (false) // compressbit > 0)
35093628 {
....@@ -4208,6 +4327,7 @@
42084327
42094328 com.sun.opengl.util.texture.Texture CompressTexture2(String name)
42104329 {
4330
+ new Exception().printStackTrace();
42114331 System.exit(0);
42124332 com.sun.opengl.util.texture.Texture texture = null;
42134333
....@@ -7901,7 +8021,7 @@
79018021 String pigment = Object3D.GetPigment(tex);
79028022 String bump = Object3D.GetBump(tex);
79038023
7904
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8024
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79058025 {
79068026 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79078027 // System.out.println("; bump = " + bump);
....@@ -7916,11 +8036,69 @@
79168036 pigment = null;
79178037 }
79188038
7919
- ReleaseTexture(bump, true);
7920
- ReleaseTexture(pigment, false);
8039
+ ReleaseTexture(tex, true);
8040
+ ReleaseTexture(tex, false);
79218041 }
79228042
7923
- void ReleaseTexture(String tex, boolean bump)
8043
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
8044
+ {
8045
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8046
+ {
8047
+ return;
8048
+ }
8049
+
8050
+ if (tex == null)
8051
+ {
8052
+ ReleaseTexture(null, false);
8053
+ return;
8054
+ }
8055
+
8056
+ String pigment = Object3D.GetPigment(tex);
8057
+
8058
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8059
+ {
8060
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8061
+ // System.out.println("; bump = " + bump);
8062
+ }
8063
+
8064
+ if (pigment.equals(""))
8065
+ {
8066
+ pigment = null;
8067
+ }
8068
+
8069
+ ReleaseTexture(tex, false);
8070
+ }
8071
+
8072
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
8073
+ {
8074
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8075
+ {
8076
+ return;
8077
+ }
8078
+
8079
+ if (tex == null)
8080
+ {
8081
+ ReleaseTexture(null, true);
8082
+ return;
8083
+ }
8084
+
8085
+ String bump = Object3D.GetBump(tex);
8086
+
8087
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8088
+ {
8089
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8090
+ // System.out.println("; bump = " + bump);
8091
+ }
8092
+
8093
+ if (bump.equals(""))
8094
+ {
8095
+ bump = null;
8096
+ }
8097
+
8098
+ ReleaseTexture(tex, true);
8099
+ }
8100
+
8101
+ void ReleaseTexture(cTexture tex, boolean bump)
79248102 {
79258103 if (// DrawMode() != 0 || /*tex == null ||*/
79268104 ambientOcclusion ) // || !textureon)
....@@ -7931,7 +8109,7 @@
79318109 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
79328110
79338111 if (tex != null)
7934
- texture = textures.get(tex);
8112
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
79358113
79368114 // //assert( texture != null );
79378115 // if (texture == null)
....@@ -8023,7 +8201,55 @@
80238201 }
80248202 }
80258203
8026
- /*boolean*/ public void BindTextures(cTexture tex, int resolution) // INTERFACE
8204
+ /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
8205
+ {
8206
+// if (// DrawMode() != 0 || /*tex == null ||*/
8207
+// ambientOcclusion ) // || !textureon)
8208
+// {
8209
+// return; // false;
8210
+// }
8211
+//
8212
+// if (tex == null)
8213
+// {
8214
+// BindTexture(null,false,resolution);
8215
+// BindTexture(null,true,resolution);
8216
+// return;
8217
+// }
8218
+//
8219
+// String pigment = Object3D.GetPigment(tex);
8220
+// String bump = Object3D.GetBump(tex);
8221
+//
8222
+// usedtextures.add(pigment);
8223
+// usedtextures.add(bump);
8224
+//
8225
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8226
+// {
8227
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8228
+// // System.out.println("; bump = " + bump);
8229
+// }
8230
+//
8231
+// if (bump.equals(""))
8232
+// {
8233
+// bump = null;
8234
+// }
8235
+// if (pigment.equals(""))
8236
+// {
8237
+// pigment = null;
8238
+// }
8239
+//
8240
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8241
+// BindTexture(pigment, false, resolution);
8242
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8243
+// BindTexture(bump, true, resolution);
8244
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8245
+//
8246
+// return; // true;
8247
+
8248
+ BindPigmentTexture(tex, resolution);
8249
+ BindBumpTexture(tex, resolution);
8250
+ }
8251
+
8252
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
80278253 {
80288254 if (// DrawMode() != 0 || /*tex == null ||*/
80298255 ambientOcclusion ) // || !textureon)
....@@ -8034,17 +8260,47 @@
80348260 if (tex == null)
80358261 {
80368262 BindTexture(null,false,resolution);
8037
- BindTexture(null,true,resolution);
80388263 return;
80398264 }
80408265
80418266 String pigment = Object3D.GetPigment(tex);
8267
+
8268
+ usedtextures.add(tex);
8269
+
8270
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8271
+ {
8272
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8273
+ // System.out.println("; bump = " + bump);
8274
+ }
8275
+
8276
+ if (pigment.equals(""))
8277
+ {
8278
+ pigment = null;
8279
+ }
8280
+
8281
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8282
+ BindTexture(tex, false, resolution);
8283
+ }
8284
+
8285
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8286
+ {
8287
+ if (// DrawMode() != 0 || /*tex == null ||*/
8288
+ ambientOcclusion ) // || !textureon)
8289
+ {
8290
+ return; // false;
8291
+ }
8292
+
8293
+ if (tex == null)
8294
+ {
8295
+ BindTexture(null,true,resolution);
8296
+ return;
8297
+ }
8298
+
80428299 String bump = Object3D.GetBump(tex);
80438300
8044
- usedtextures.put(pigment, pigment);
8045
- usedtextures.put(bump, bump);
8301
+ usedtextures.add(tex);
80468302
8047
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8303
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
80488304 {
80498305 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
80508306 // System.out.println("; bump = " + bump);
....@@ -8054,43 +8310,94 @@
80548310 {
80558311 bump = null;
80568312 }
8057
- if (pigment.equals(""))
8058
- {
8059
- pigment = null;
8060
- }
80618313
8062
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8063
- BindTexture(pigment, false, resolution);
80648314 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8065
- BindTexture(bump, true, resolution);
8315
+ BindTexture(tex, true, resolution);
80668316 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8067
-
8068
- return; // true;
80698317 }
80708318
8071
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution)
8319
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8320
+
8321
+ private boolean FileExists(String tex)
80728322 {
8073
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8323
+ if (missingTextures.contains(tex))
8324
+ {
8325
+ return false;
8326
+ }
8327
+
8328
+ boolean fileExists = new File(tex).exists();
8329
+
8330
+ if (!fileExists)
8331
+ {
8332
+ // If file exists, the "new File()" is not executed sgain
8333
+ missingTextures.add(tex);
8334
+ }
8335
+
8336
+ return fileExists;
8337
+ }
8338
+
8339
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
8340
+ {
8341
+ CacheTexture texturecache = null;
80748342
80758343 if (tex != null)
80768344 {
8077
- String texname = tex;
8345
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8346
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
80788347
8079
- String[] split = tex.split("Textures");
8080
- if (split.length > 1)
8081
- texname = "/Users/nbriere/Textures" + split[split.length-1];
8082
- else
8083
- if (!texname.startsWith("/"))
8084
- texname = "/Users/nbriere/Textures/" + texname;
8348
+ if (texname.equals("") && texdata == null)
8349
+ {
8350
+ return null;
8351
+ }
8352
+
8353
+ String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
8354
+
8355
+// String[] split = tex.split("Textures");
8356
+// if (split.length > 1)
8357
+// texname = "/Users/nbriere/Textures" + split[split.length-1];
8358
+// else
8359
+// if (!texname.startsWith("/"))
8360
+// texname = "/Users/nbriere/Textures/" + texname;
8361
+ if (!FileExists(texname) && !texname.startsWith("@"))
8362
+ {
8363
+ texname = fallbackTextureName;
8364
+ }
80858365
80868366 if (CACHETEXTURE)
8087
- texture = textures.get(texname); // TEXTURE CACHE
8088
-
8089
- TextureData texturedata = null;
8090
-
8091
- if (texture == null || texture.resolution < resolution)
80928367 {
8093
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8368
+ if (texdata == null)
8369
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8370
+ else
8371
+ texturecache = bimtextures.get(texdata);
8372
+ }
8373
+
8374
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8375
+ {
8376
+ TextureData texturedata = null;
8377
+
8378
+ if (texdata != null && textureon)
8379
+ {
8380
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8381
+
8382
+ try
8383
+ {
8384
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8385
+ }
8386
+ catch (Exception e)
8387
+ {
8388
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8389
+ }
8390
+
8391
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8392
+ bimtextures.put(texdata, texturecache);
8393
+
8394
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8395
+
8396
+ //Object bim2 = CreateBim(texturecache.texturedata);
8397
+ //bim2 = bim;
8398
+ }
8399
+ else
8400
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
80948401 {
80958402 assert(!bump);
80968403 // if (bump)
....@@ -8101,19 +8408,23 @@
81018408 // }
81028409 // else
81038410 // {
8104
- texture = textures.get(tex);
8105
- if (texture == null)
8411
+ // texturecache = textures.get(texname); // suspicious
8412
+ if (texturecache == null)
81068413 {
8107
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8414
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
81088415 }
8416
+ else
8417
+ new Exception().printStackTrace();
81098418 // }
81108419 } else
8111
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8420
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
81128421 {
81138422 assert(bump);
8114
- texture = textures.get(tex);
8115
- if (texture == null)
8116
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8423
+ // texturecache = textures.get(texname); // suspicious
8424
+ if (texturecache == null)
8425
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8426
+ else
8427
+ new Exception().printStackTrace();
81178428 } else
81188429 {
81198430 //if (tex.equals("IMMORTAL"))
....@@ -8121,11 +8432,22 @@
81218432 // texture = GetResourceTexture("default.png");
81228433 //} else
81238434 //{
8124
- if (tex.equals("WHITE_NOISE"))
8435
+ if (texname.endsWith("WHITE_NOISE"))
81258436 {
8126
- texture = textures.get(tex);
8127
- if (texture == null)
8128
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8437
+ // texturecache = textures.get(texname); // suspicious
8438
+ if (texturecache == null)
8439
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8440
+ else
8441
+ new Exception().printStackTrace();
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();
81298451 } else
81308452 {
81318453 if (textureon)
....@@ -8150,7 +8472,7 @@
81508472 }
81518473
81528474 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
8153
- if (!new File(cachename).exists())
8475
+ if (!FileExists(cachename))
81548476 cachename = texname;
81558477 else
81568478 processbump = false; // don't process bump map again
....@@ -8172,7 +8494,7 @@
81728494 }
81738495
81748496 cachename = texname.substring(0, texname.length()-4)+ext+".png";
8175
- if (!new File(cachename).exists())
8497
+ if (!FileExists(cachename))
81768498 cachename = texname;
81778499 else
81788500 processbump = false; // don't process bump map again
....@@ -8181,20 +8503,23 @@
81818503 texturedata = GetFileTexture(cachename, processbump, resolution);
81828504
81838505
8184
- if (texturedata != null)
8185
- 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);
81868510 //texture = GetTexture(tex, bump);
81878511 }
8512
+ }
81888513 }
81898514 //}
81908515 }
81918516
8192
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8517
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
81938518 {
81948519 //return false;
81958520
81968521 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8197
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8522
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
81988523 {
81998524 // String ext = "_highres";
82008525 // if (REDUCETEXTURE)
....@@ -8211,52 +8536,17 @@
82118536 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
82128537 if (!cachefile.exists())
82138538 {
8214
- // cache to disk
8215
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
8216
- //buffers[0].
8217
-
8218
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
8219
- int[] pixels = new int[bytebuf.capacity()/3];
8220
-
8221
- // squared size heuristic...
8222
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8539
+ //if (texturedata.getWidth() == texturedata.getHeight())
82238540 {
8224
- for (int i=pixels.length; --i>=0;)
8225
- {
8226
- int i3 = i*3;
8227
- pixels[i] = 0xFF;
8228
- pixels[i] <<= 8;
8229
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
8230
- pixels[i] <<= 8;
8231
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
8232
- pixels[i] <<= 8;
8233
- pixels[i] |= bytebuf.get(i3) & 0xFF;
8234
- }
8235
-
8236
- /*
8237
- int r=0,g=0,b=0,a=0;
8238
- for (int i=0; i<width; i++)
8239
- for (int j=0; j<height; j++)
8240
- {
8241
- int index = j*width+i;
8242
- int p = pixels[index];
8243
- a = ((p>>24) & 0xFF);
8244
- r = ((p>>16) & 0xFF);
8245
- g = ((p>>8) & 0xFF);
8246
- b = (p & 0xFF);
8247
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
8248
- }
8249
- /**/
8250
- int width = (int)Math.sqrt(pixels.length); // squared
8251
- int height = width;
8252
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
8253
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8541
+ BufferedImage rendImage = CreateBim(texturedata);
8542
+
82548543 ImageWriter writer = null;
82558544 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
82568545 if (iter.hasNext()) {
82578546 writer = (ImageWriter)iter.next();
82588547 }
8259
- float compressionQuality = 0.9f;
8548
+
8549
+ float compressionQuality = 0.85f;
82608550 try
82618551 {
82628552 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8273,18 +8563,20 @@
82738563 }
82748564 }
82758565 }
8276
-
8566
+
8567
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8568
+
82778569 //System.out.println("Texture = " + tex);
8278
- if (textures.containsKey(texname))
8570
+ if (textures.containsKey(tex))
82798571 {
8280
- CacheTexture thetex = textures.get(texname);
8572
+ CacheTexture thetex = textures.get(tex);
82818573 thetex.texture.disable();
82828574 thetex.texture.dispose();
8283
- textures.remove(texname);
8575
+ textures.remove(tex);
82848576 }
82858577
8286
- texture.texturedata = texturedata;
8287
- textures.put(texname, texture);
8578
+ //texture.texturedata = texturedata;
8579
+ textures.put(tex, texturecache);
82888580
82898581 // newtex = true;
82908582 }
....@@ -8300,10 +8592,44 @@
83008592 }
83018593 }
83028594
8303
- return texture;
8595
+ return texturecache;
83048596 }
83058597
8306
- 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
83078633 {
83088634 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
83098635
....@@ -8321,21 +8647,21 @@
83218647 return texture!=null?texture.texture:null;
83228648 }
83238649
8324
- 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
83258651 {
83268652 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
83278653
83288654 return texture!=null?texture.texturedata:null;
83298655 }
83308656
8331
- boolean BindTexture(String tex, boolean bump, int resolution)
8657
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
83328658 {
83338659 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
83348660 {
83358661 return false;
83368662 }
83378663
8338
- boolean newtex = false;
8664
+ //boolean newtex = false;
83398665
83408666 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
83418667
....@@ -8367,9 +8693,75 @@
83678693 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
83688694 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
83698695
8370
- return newtex;
8696
+ return true; // Warning: not used.
83718697 }
83728698
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
+
83738765 ShadowBuffer shadowPBuf;
83748766 AntialiasBuffer antialiasPBuf;
83758767 int MAXSTACK;
....@@ -8562,7 +8954,7 @@
85628954
85638955 if (cubemap == null)
85648956 {
8565
- LoadEnvy(5);
8957
+ //LoadEnvy(1);
85668958 }
85678959
85688960 //cubemap.enable();
....@@ -8849,37 +9241,58 @@
88499241 cubemap = null;
88509242 return;
88519243 case 1:
8852
- name = "cubemaps/box_";
8853
- ext = "png";
9244
+ name = "cubemaps/rgb/";
9245
+ ext = "jpg";
88549246 reverseUP = false;
88559247 break;
88569248 case 2:
8857
- name = "cubemaps/uffizi_";
8858
- ext = "png";
8859
- break; // reverseUP = true; break;
9249
+ name = "cubemaps/uffizi/";
9250
+ ext = "jpg";
9251
+ reverseUP = false;
9252
+ break;
88609253 case 3:
8861
- name = "cubemaps/CloudyHills_";
8862
- ext = "tga";
9254
+ name = "cubemaps/CloudyHills/";
9255
+ ext = "jpg";
88639256 reverseUP = false;
88649257 break;
88659258 case 4:
8866
- name = "cubemaps/cornell_";
9259
+ name = "cubemaps/cornell/";
88679260 ext = "png";
88689261 reverseUP = false;
88699262 break;
9263
+ case 5:
9264
+ name = "cubemaps/skycube/";
9265
+ ext = "jpg";
9266
+ reverseUP = false;
9267
+ break;
9268
+ case 6:
9269
+ name = "cubemaps/SaintLazarusChurch3/";
9270
+ ext = "jpg";
9271
+ reverseUP = false;
9272
+ break;
9273
+ case 7:
9274
+ name = "cubemaps/Sodermalmsallen/";
9275
+ ext = "jpg";
9276
+ reverseUP = false;
9277
+ break;
9278
+ case 8:
9279
+ name = "cubemaps/Sodermalmsallen2/";
9280
+ ext = "jpg";
9281
+ reverseUP = false;
9282
+ break;
9283
+ case 9:
9284
+ name = "cubemaps/UnionSquare/";
9285
+ ext = "jpg";
9286
+ reverseUP = false;
9287
+ break;
88709288 default:
8871
- name = "cubemaps/rgb_";
8872
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9289
+ name = "cubemaps/box/";
9290
+ ext = "png"; /*mipmap = true;*/
9291
+ reverseUP = false;
88739292 break;
88749293 }
8875
-
8876
- try
8877
- {
8878
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
8879
- } catch (IOException e)
8880
- {
8881
- throw new RuntimeException(e);
8882
- }
9294
+
9295
+ LoadSkybox(name, ext, mipmap);
88839296 }
88849297
88859298 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -8911,8 +9324,12 @@
89119324 static double[] model = new double[16];
89129325 double[] camera2light = new double[16];
89139326 double[] light2camera = new double[16];
8914
- int newenvy = -1;
8915
- boolean envyoff = true; // false;
9327
+
9328
+ //int newenvy = -1;
9329
+ //boolean envyoff = false;
9330
+
9331
+ String loadedskyboxname;
9332
+
89169333 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
89179334 //float[] light0 = { 0,0,0 };
89189335 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9205,11 +9622,35 @@
92059622 jy8[3] = 0.5f;
92069623 }
92079624
9208
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9625
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
92099626 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
92109627 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
92119628 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
92129629
9630
+ void ResetOptions()
9631
+ {
9632
+ options1[0] = 100;
9633
+ options1[1] = 0.025f;
9634
+ options1[2] = 0.01f;
9635
+ options1[3] = 0;
9636
+ options1[4] = 0;
9637
+
9638
+ options2[0] = 0;
9639
+ options2[1] = 0.75f;
9640
+ options2[2] = 0;
9641
+ options2[3] = 0;
9642
+
9643
+ options3[0] = 1;
9644
+ options3[1] = 1;
9645
+ options3[2] = 1;
9646
+ options3[3] = 0;
9647
+
9648
+ options4[0] = 1;
9649
+ options4[1] = 0;
9650
+ options4[2] = 1;
9651
+ options4[3] = 0;
9652
+ }
9653
+
92139654 static int imagecount = 0; // movie generation
92149655
92159656 static int jitter = 0;
....@@ -9305,8 +9746,8 @@
93059746 assert (parentcam != renderCamera);
93069747
93079748 if (renderCamera != lightCamera)
9308
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9309
- LA.matConcat(matrix, parentcam.toParent, matrix);
9749
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9750
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
93109751
93119752 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
93129753
....@@ -9321,8 +9762,8 @@
93219762 LA.matCopy(renderCamera.fromScreen, matrix);
93229763
93239764 if (renderCamera != lightCamera)
9324
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9325
- LA.matConcat(parentcam.fromParent, matrix, matrix);
9765
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9766
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
93269767
93279768 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
93289769
....@@ -9368,10 +9809,12 @@
93689809 rati = 1 / rati;
93699810 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
93709811 }
9371
- assert (newenvy == -1);
9812
+
9813
+ //assert (newenvy == -1);
9814
+
93729815 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
93739816 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9374
- DrawSkyBox(gl);
9817
+ DrawSkyBox(gl, (float)rati);
93759818 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
93769819 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
93779820 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -9394,7 +9837,7 @@
93949837 //gl.glFlush();
93959838 gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE);
93969839
9397
- if (ANIMATION && ABORTED)
9840
+ if (Globals.ANIMATION && ABORTED)
93989841 {
93999842 System.err.println(" ABORTED FRAME");
94009843 break;
....@@ -9424,7 +9867,7 @@
94249867 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
94259868
94269869 // save image
9427
- if (ANIMATION && !ABORTED)
9870
+ if (Globals.ANIMATION && !ABORTED)
94289871 {
94299872 VPwidth = viewport[2];
94309873 VPheight = viewport[3];
....@@ -9535,11 +9978,11 @@
95359978
95369979 // imagecount++;
95379980
9538
- String fullname = filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
9981
+ String fullname = Globals.filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
95399982
95409983 if (!BOXMODE)
95419984 {
9542
- System.out.println("image: " + fullname + " (wav cursor=" + (GrafreeD.wav.cursor / 735 / 4) + ")");
9985
+ System.out.println("image: " + fullname + " (wav cursor=" + (Grafreed.wav.cursor / 735 / 4) + ")");
95439986 }
95449987
95459988 if (!BOXMODE)
....@@ -9577,7 +10020,7 @@
957710020 ABORTED = false;
957810021 }
957910022 else
9580
- GrafreeD.wav.cursor += 735 * ACSIZE;
10023
+ Grafreed.wav.cursor += 735 * ACSIZE;
958110024
958210025 if (false)
958310026 {
....@@ -10240,11 +10683,11 @@
1024010683
1024110684 public void display(GLAutoDrawable drawable)
1024210685 {
10243
- if (GrafreeD.savesound && GrafreeD.hassound)
10686
+ if (Grafreed.savesound && Grafreed.hassound)
1024410687 {
10245
- GrafreeD.wav.save();
10246
- GrafreeD.savesound = false;
10247
- GrafreeD.hassound = false;
10688
+ Grafreed.wav.save();
10689
+ Grafreed.savesound = false;
10690
+ Grafreed.hassound = false;
1024810691 }
1024910692 // if (DEBUG_SELECTION)
1025010693 // {
....@@ -10320,6 +10763,7 @@
1032010763 ANTIALIAS = 0;
1032110764 //System.out.println("RESTART");
1032210765 AAtimer.restart();
10766
+ Globals.TIMERRUNNING = true;
1032310767 }
1032410768 }
1032510769 }
....@@ -10374,7 +10818,7 @@
1037410818 Object3D theobject = object;
1037510819 Object3D theparent = object.parent;
1037610820 object.parent = null;
10377
- object = (Object3D)GrafreeD.clone(object);
10821
+ object = (Object3D)Grafreed.clone(object);
1037810822 object.Stripify();
1037910823 if (theobject.selection == null || theobject.selection.Size() == 0)
1038010824 theobject.PreprocessOcclusion(this);
....@@ -10387,13 +10831,14 @@
1038710831 ambientOcclusion = false;
1038810832 }
1038910833
10390
- if (Globals.lighttouched && DrawMode() == DEFAULT && !lightMode) // && !FROZEN)
10834
+ if (//Globals.lighttouched &&
10835
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1039110836 {
1039210837 //if (RENDERSHADOW) // ?
1039310838 if (!IsFrozen())
1039410839 {
1039510840 // dec 2012
10396
- if (!ambientOcclusion && !(!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0))
10841
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
1039710842 {
1039810843 Globals.framecount++;
1039910844 shadowbuffer.display();
....@@ -10406,7 +10851,7 @@
1040610851
1040710852 if (wait)
1040810853 {
10409
- Sleep(500);
10854
+ Sleep(200); // blocks everything
1041010855
1041110856 wait = false;
1041210857 }
....@@ -10520,8 +10965,8 @@
1052010965
1052110966 // if (parentcam != renderCamera) // not a light
1052210967 if (cam != lightCamera)
10523
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10524
- LA.matConcat(matrix, parentcam.toParent, matrix);
10968
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10969
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1052510970
1052610971 for (int j = 0; j < 4; j++)
1052710972 {
....@@ -10535,8 +10980,8 @@
1053510980
1053610981 // if (parentcam != renderCamera) // not a light
1053710982 if (cam != lightCamera)
10538
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10539
- LA.matConcat(parentcam.fromParent, matrix, matrix);
10983
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10984
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1054010985
1054110986 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1054210987
....@@ -10622,13 +11067,27 @@
1062211067 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1062311068 }
1062411069
10625
- if (newenvy > -1)
11070
+// if (newenvy > -1)
11071
+// {
11072
+// LoadEnvy(newenvy);
11073
+// }
11074
+//
11075
+// newenvy = -1;
11076
+
11077
+ if (object.skyboxname != null)
1062611078 {
10627
- LoadEnvy(newenvy);
11079
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11080
+ {
11081
+ LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11082
+ loadedskyboxname = object.skyboxname;
11083
+ }
1062811084 }
10629
-
10630
- newenvy = -1;
10631
-
11085
+ else
11086
+ {
11087
+ cubemap = null;
11088
+ loadedskyboxname = null;
11089
+ }
11090
+
1063211091 ratio = ((double) getWidth()) / getHeight();
1063311092 //System.out.println("ratio = " + ratio);
1063411093
....@@ -10644,7 +11103,7 @@
1064411103
1064511104 if (!IsFrozen() && !ambientOcclusion)
1064611105 {
10647
- DrawSkyBox(gl);
11106
+ DrawSkyBox(gl, (float)ratio);
1064811107 }
1064911108
1065011109 //if (selection_view == -1)
....@@ -10795,7 +11254,16 @@
1079511254 // Bump noise
1079611255 gl.glActiveTexture(GL.GL_TEXTURE6);
1079711256 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
10798
- BindTexture(NOISE_TEXTURE, false, 2);
11257
+
11258
+ try
11259
+ {
11260
+ BindTexture(NOISE_TEXTURE, false, 2);
11261
+ }
11262
+ catch (Exception e)
11263
+ {
11264
+ System.err.println("FAILED: " + NOISE_TEXTURE);
11265
+ }
11266
+
1079911267
1080011268 gl.glActiveTexture(GL.GL_TEXTURE0);
1080111269 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -10818,9 +11286,9 @@
1081811286
1081911287 gl.glMatrixMode(GL.GL_MODELVIEW);
1082011288
10821
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10822
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10823
-//gl.glEnable(gl.GL_MULTISAMPLE);
11289
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11290
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11291
+gl.glEnable(gl.GL_MULTISAMPLE);
1082411292 } else
1082511293 {
1082611294 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -10831,7 +11299,7 @@
1083111299 //System.out.println("BLENDING ON");
1083211300 gl.glEnable(GL.GL_BLEND);
1083311301 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
10834
-
11302
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1083511303 gl.glMatrixMode(gl.GL_PROJECTION);
1083611304 gl.glLoadIdentity();
1083711305
....@@ -10920,8 +11388,8 @@
1092011388 System.err.println("parentcam != renderCamera");
1092111389
1092211390 // if (cam != lightCamera)
10923
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10924
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11391
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11392
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1092511393 }
1092611394
1092711395 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -10942,8 +11410,8 @@
1094211410 if (true) // TODO
1094311411 {
1094411412 if (cam != lightCamera)
10945
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10946
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11413
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11414
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
1094711415 }
1094811416
1094911417 LA.xformPos(light0, cam.toScreen, light0);
....@@ -11080,7 +11548,7 @@
1108011548 }
1108111549 }
1108211550
11083
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11551
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1108411552 {
1108511553 //gl.glDepthFunc(GL.GL_LEQUAL);
1108611554 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11088,24 +11556,21 @@
1108811556
1108911557 boolean texon = textureon;
1109011558
11091
- if (RENDERPROGRAM > 0)
11092
- {
11093
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11094
- textureon = false;
11095
- }
11559
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11560
+ textureon = false;
11561
+
1109611562 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1109711563 //System.out.println("ALLO");
1109811564 gl.glColorMask(false, false, false, false);
1109911565 DrawObject(gl);
11100
- if (RENDERPROGRAM > 0)
11101
- {
11102
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11103
- textureon = texon;
11104
- }
11566
+
11567
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11568
+ textureon = texon;
11569
+
1110511570 gl.glColorMask(true, true, true, true);
1110611571
1110711572 gl.glDepthFunc(GL.GL_EQUAL);
11108
- //gl.glDepthMask(false);
11573
+ gl.glDepthMask(false);
1110911574 }
1111011575
1111111576 if (false) // DrawMode() == SHADOW)
....@@ -11259,8 +11724,14 @@
1125911724 {
1126011725 renderpass++;
1126111726 // System.out.println("Draw object... ");
11727
+ STEP = 1;
1126211728 if (FAST) // in case there is no script
11263
- STEP = 16;
11729
+ STEP = 8;
11730
+
11731
+ if (CURRENTANTIALIAS == 0 || ACSIZE == 1)
11732
+ {
11733
+ STEP *= 4;
11734
+ }
1126411735
1126511736 //object.FullInvariants();
1126611737
....@@ -11274,23 +11745,44 @@
1127411745 e.printStackTrace();
1127511746 }
1127611747
11277
- if (GrafreeD.RENDERME > 0)
11278
- GrafreeD.RENDERME--; // mechante magouille
11748
+ if (Grafreed.RENDERME > 0)
11749
+ Grafreed.RENDERME--; // mechante magouille
1127911750
1128011751 Globals.ONESTEP = false;
1128111752 }
1128211753
1128311754 static boolean zoomonce = false;
1128411755
11756
+ static void CreateSelectedPoint()
11757
+ {
11758
+ if (selectedpoint == null)
11759
+ {
11760
+ debugpointG = new Sphere();
11761
+ debugpointP = new Sphere();
11762
+ debugpointC = new Sphere();
11763
+ debugpointR = new Sphere();
11764
+
11765
+ selectedpoint = new Superellipsoid();
11766
+
11767
+ for (int i=0; i<8; i++)
11768
+ {
11769
+ debugpoints[i] = new Sphere();
11770
+ }
11771
+ }
11772
+ }
11773
+
1128511774 void DrawObject(GL gl, boolean draw)
1128611775 {
11776
+ // To clear camera values
11777
+ ResetOptions();
11778
+
1128711779 //System.out.println("DRAW OBJECT " + mouseDown);
1128811780 // DrawMode() = SELECTION;
1128911781 //GL gl = getGL();
1129011782 if ((TRACK || SHADOWTRACK) || zoomonce)
1129111783 {
1129211784 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11293
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11785
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1129411786 pingthread.StepToTarget(true); // true);
1129511787 // zoomonce = false;
1129611788 }
....@@ -11345,7 +11837,14 @@
1134511837
1134611838 usedtextures.clear();
1134711839
11348
- BindTextures(DEFAULT_TEXTURES, 2);
11840
+ try
11841
+ {
11842
+ BindTextures(DEFAULT_TEXTURES, 2);
11843
+ }
11844
+ catch (Exception e)
11845
+ {
11846
+ System.err.println("FAILED: " + DEFAULT_TEXTURES);
11847
+ }
1134911848 }
1135011849 //System.out.println("--> " + stackdepth);
1135111850 // GrafreeD.traceon();
....@@ -11355,8 +11854,9 @@
1135511854
1135611855 if (DrawMode() == DEFAULT)
1135711856 {
11358
- if (DEBUG)
11857
+ if (Globals.DEBUG)
1135911858 {
11859
+ CreateSelectedPoint();
1136011860 float radius = 0.05f;
1136111861 if (selectedpoint.radius != radius)
1136211862 {
....@@ -11410,20 +11910,32 @@
1141011910 ReleaseTextures(DEFAULT_TEXTURES);
1141111911
1141211912 if (CLEANCACHE)
11413
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11913
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1141411914 {
11415
- String tex = e.nextElement();
11915
+ cTexture tex = e.nextElement();
1141611916
1141711917 // System.out.println("Texture --------- " + tex);
1141811918
11419
- if (tex.equals("WHITE_NOISE"))
11919
+ if (tex.equals("WHITE_NOISE:"))
1142011920 continue;
1142111921
11422
- if (!usedtextures.containsKey(tex))
11922
+ if (!usedtextures.contains(tex))
1142311923 {
11924
+ CacheTexture gettex = texturepigment.get(tex);
1142411925 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11425
- textures.get(tex).texture.dispose();
11426
- textures.remove(tex);
11926
+ if (gettex != null)
11927
+ {
11928
+ gettex.texture.dispose();
11929
+ texturepigment.remove(tex);
11930
+ }
11931
+
11932
+ gettex = texturebump.get(tex);
11933
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11934
+ if (gettex != null)
11935
+ {
11936
+ gettex.texture.dispose();
11937
+ texturebump.remove(tex);
11938
+ }
1142711939 }
1142811940 }
1142911941 }
....@@ -11436,7 +11948,14 @@
1143611948 if (checker != null && DrawMode() == DEFAULT)
1143711949 {
1143811950 //BindTexture(IMMORTAL_TEXTURE);
11439
- BindTextures(checker.GetTextures(), checker.texres);
11951
+ try
11952
+ {
11953
+ BindTextures(checker.GetTextures(), checker.texres);
11954
+ }
11955
+ catch (Exception e)
11956
+ {
11957
+ System.err.println("FAILED: " + checker.GetTextures());
11958
+ }
1144011959 // NEAREST
1144111960 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
1144211961 DrawChecker(gl);
....@@ -11518,7 +12037,7 @@
1151812037 return;
1151912038 }
1152012039
11521
- String string = obj.GetToolTip();
12040
+ String string = obj.toString(); //.GetToolTip();
1152212041
1152312042 GL gl = GetGL();
1152412043
....@@ -11835,8 +12354,8 @@
1183512354 //obj.TransformToWorld(light, light);
1183612355 for (int i = tp.size(); --i >= 0;)
1183712356 {
11838
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
11839
- LA.xformPos(light, tp.get(i).toParent, light);
12357
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12358
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1184012359 }
1184112360
1184212361
....@@ -11853,8 +12372,8 @@
1185312372 parentcam = cameras[0];
1185412373 }
1185512374
11856
- for (int count = parentcam.GetTransformCount(); --count>=0;)
11857
- LA.xformPos(light, parentcam.toParent, light); // may 2013
12375
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
12376
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1185812377
1185912378 LA.xformPos(light, renderCamera.toScreen, light);
1186012379
....@@ -11944,8 +12463,76 @@
1194412463
1194512464 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1194612465
11947
- String program =
12466
+ String programmin =
12467
+ // Min shader
1194812468 "!!ARBfp1.0\n" +
12469
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12470
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12471
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12472
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12473
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12474
+ "PARAM light2cam0 = program.env[10];" +
12475
+ "PARAM light2cam1 = program.env[11];" +
12476
+ "PARAM light2cam2 = program.env[12];" +
12477
+ "TEMP temp;" +
12478
+ "TEMP light;" +
12479
+ "TEMP ndotl;" +
12480
+ "TEMP normal;" +
12481
+ "TEMP depth;" +
12482
+ "TEMP eye;" +
12483
+ "TEMP pos;" +
12484
+
12485
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12486
+ Normalize("normal") +
12487
+ "MOV light, state.light[0].position;" +
12488
+ "DP3 ndotl.x, light, normal;" +
12489
+
12490
+ // shadow
12491
+ "MOV pos, fragment.texcoord[1];" +
12492
+ "MOV temp, pos;" +
12493
+ ShadowTextureFetch("depth", "temp", "1") +
12494
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12495
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12496
+
12497
+ // No shadow when out of frustum
12498
+ //"SGE temp.y, depth.z, zero123.y;" +
12499
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12500
+
12501
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12502
+
12503
+ // Backlit
12504
+ "MOV pos.w, zero123.y;" +
12505
+ "DP4 eye.x, pos, light2cam0;" +
12506
+ "DP4 eye.y, pos, light2cam1;" +
12507
+ "DP4 eye.z, pos, light2cam2;" +
12508
+ Normalize("eye") +
12509
+
12510
+ "DP3 ndotl.y, -eye, normal;" +
12511
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12512
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12513
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12514
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12515
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12516
+
12517
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12518
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12519
+
12520
+ // Pigment
12521
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12522
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12523
+ "MUL temp, temp, ndotl.x;" +
12524
+
12525
+ "MUL temp, temp, zero123.z;" +
12526
+
12527
+ //"MUL temp, temp, ndotl.y;" +
12528
+
12529
+ "MOV temp.w, zero123.y;" + // reset alpha
12530
+ "MOV result.color, temp;" +
12531
+ "END";
12532
+
12533
+ String programmax =
12534
+ "!!ARBfp1.0\n" +
12535
+
1194912536 //"OPTION ARB_fragment_program_shadow;" +
1195012537 "PARAM light2cam0 = program.env[10];" +
1195112538 "PARAM light2cam1 = program.env[11];" +
....@@ -12060,8 +12647,7 @@
1206012647 "TEMP shininess;" +
1206112648 "\n" +
1206212649 "MOV texSamp, one;" +
12063
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12064
-
12650
+
1206512651 "MOV mapgrid.x, one2048th.x;" +
1206612652 "MOV temp, fragment.texcoord[1];" +
1206712653 /*
....@@ -12082,20 +12668,20 @@
1208212668 "MUL temp, floor, mapgrid.x;" +
1208312669 //"TEX depth0, temp, texture[1], 2D;" +
1208412670 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12085
- TextureFetch("depth0", "temp", "1") +
12671
+ ShadowTextureFetch("depth0", "temp", "1") +
1208612672 "") +
1208712673 "ADD temp.x, temp.x, mapgrid.x;" +
1208812674 //"TEX depth1, temp, texture[1], 2D;" +
1208912675 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12090
- TextureFetch("depth1", "temp", "1") +
12676
+ ShadowTextureFetch("depth1", "temp", "1") +
1209112677 "") +
1209212678 "ADD temp.y, temp.y, mapgrid.x;" +
1209312679 //"TEX depth2, temp, texture[1], 2D;" +
12094
- TextureFetch("depth2", "temp", "1") +
12680
+ ShadowTextureFetch("depth2", "temp", "1") +
1209512681 "SUB temp.x, temp.x, mapgrid.x;" +
1209612682 //"TEX depth3, temp, texture[1], 2D;" +
1209712683 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12098
- TextureFetch("depth3", "temp", "1") +
12684
+ ShadowTextureFetch("depth3", "temp", "1") +
1209912685 "") +
1210012686 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1210112687 //"MOV params, material;" +
....@@ -12466,10 +13052,10 @@
1246613052 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1246713053 "") +
1246813054
12469
- // display shadow only (bump == 0)
13055
+ // display shadow only (fakedepth == 0)
1247013056 "SUB temp.x, half.x, shadow.x;" +
12471
- "MOV temp.y, -params6.x;" +
12472
- "SLT temp.z, temp.y, zero.x;" +
13057
+ "MOV temp.y, -params5.z;" + // params6.x;" +
13058
+ "SLT temp.z, temp.y, -c256i.x;" +
1247313059 "SUB temp.y, one.x, temp.z;" +
1247413060 "MUL temp.x, temp.x, temp.y;" +
1247513061 "KIL temp.x;" +
....@@ -12598,8 +13184,10 @@
1259813184 "MAX ndotl.x, ndotl.x, -ndotl.x;" +
1259913185
1260013186 "SUB temp.x, one.x, ndotl.x;" +
12601
- "ADD temp.x, temp.x, options2.z;" + // lightsheen
12602
- "ADD temp.y, one.y, options2.y;" + // sursurface
13187
+ // Tuning for default skin
13188
+ //"ADD temp.x, temp.x, options2.z;" + // lightsheen
13189
+ "MAD temp.x, options2.z, half.y, temp.x;" + // lightsheen
13190
+ "ADD temp.y, one.y, options2.y;" + // subsurface
1260313191 "MUL temp.x, temp.x, temp.y;" +
1260413192
1260513193 "MUL saturation, saturation, temp.xxxx;" +
....@@ -12747,7 +13335,7 @@
1274713335 "MUL final.y, fragment.texcoord[0].x, c256;" +
1274813336 "FLR final.x, final.y;" +
1274913337 "SUB final.y, final.y, final.x;" +
12750
- //"MUL final.x, final.x, c256i;" +
13338
+ "MUL final.x, final.x, c256i;" +
1275113339 "MOV final.z, zero.x;" +
1275213340 "MOV final.a, one.w;":""
1275313341 ) +
....@@ -12755,7 +13343,7 @@
1275513343 "MUL final.y, fragment.texcoord[0].y, c256;" +
1275613344 "FLR final.x, final.y;" +
1275713345 "SUB final.y, final.y, final.x;" +
12758
- //"MUL final.x, final.x, c256i;" +
13346
+ "MUL final.x, final.x, c256i;" +
1275913347 "MOV final.z, zero.x;" +
1276013348 "MOV final.a, one.w;":""
1276113349 ) +
....@@ -12798,7 +13386,14 @@
1279813386 //once = true;
1279913387 }
1280013388
12801
- System.out.print("Program #" + mode + "; length = " + program.length());
13389
+ String program = programmax;
13390
+
13391
+ if (Globals.MINSHADER)
13392
+ {
13393
+ program = programmin;
13394
+ }
13395
+
13396
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1280213397 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1280313398 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1280413399
....@@ -12891,25 +13486,26 @@
1289113486 return out;
1289213487 }
1289313488
12894
- String TextureFetch(String dest, String src, String unit)
13489
+ // Also does frustum culling
13490
+ String ShadowTextureFetch(String dest, String src, String unit)
1289513491 {
1289613492 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1289713493 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1289813494 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13495
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13496
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1289913497 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12900
- "SLT " + src + ".z, " + src + ".x, one.x;" +
12901
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12902
- "SLT " + src + ".z, " + src + ".y, one.x;" +
12903
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13498
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13499
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1290413500 //"SWZ buffer, temp, w,w,w,w;";
12905
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13501
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1290613502 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1290713503 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1290813504 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
12909
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13505
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1291013506
12911
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
12912
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13507
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13508
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1291313509 }
1291413510
1291513511 String Shadow(String depth, String shadow)
....@@ -12931,12 +13527,16 @@
1293113527
1293213528 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1293313529 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13530
+
13531
+ // Compare fragment depth in light space with shadowmap.
1293413532 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1293513533 "SGE temp.y, temp.x, zero.x;" +
12936
- "SUB " + shadow + ".y, one.x, temp.y;" +
13534
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13535
+
13536
+ // Reverse comparison
1293713537 "SUB temp.x, one.x, temp.x;" +
1293813538 "MUL " + shadow + ".x, temp.x, temp.y;" +
12939
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13539
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1294013540 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1294113541
1294213542 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -12950,6 +13550,10 @@
1295013550 // No shadow for backface
1295113551 "DP3 temp.x, normal, lightd;" +
1295213552 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13553
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13554
+
13555
+ // No shadow when out of frustum
13556
+ "SGE temp.x, " + depth + ".z, one.z;" +
1295313557 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1295413558 "";
1295513559 }
....@@ -13096,7 +13700,8 @@
1309613700 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1309713701 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1309813702 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13099
- Object3D.cVector2[] vector2buffer;
13703
+
13704
+ //Object3D.cVector2[] vector2buffer;
1310013705
1310113706 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1310213707 // OUT : diff, spec
....@@ -13112,9 +13717,10 @@
1311213717 "DP3 " + dest + ".z," + "normals," + "eye;" +
1311313718 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1311413719 //"MOV " + dest + ".w," + "normal.z;" +
13115
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
13116
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13117
- //"MOV " + dest + ".z," + "params2.w;" +
13720
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13721
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13722
+
13723
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1311813724 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1311913725 "RCP " + dest + ".w," + dest + ".w;" +
1312013726 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13508,7 +14114,7 @@
1350814114 public void mousePressed(MouseEvent e)
1350914115 {
1351014116 //System.out.println("mousePressed: " + e);
13511
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14117
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1351214118 }
1351314119
1351414120 static long prevtime = 0;
....@@ -13584,8 +14190,8 @@
1358414190 // mode |= META;
1358514191 //}
1358614192
13587
- SetMouseMode(WHEEL | e.getModifiersEx());
13588
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14193
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14194
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1358914195 anchorX = ax;
1359014196 anchorY = ay;
1359114197 prevX = px;
....@@ -13619,6 +14225,7 @@
1361914225 else
1362014226 if (evt.getSource() == AAtimer)
1362114227 {
14228
+ Globals.TIMERRUNNING = false;
1362214229 if (mouseDown)
1362314230 {
1362414231 //new Exception().printStackTrace();
....@@ -13644,6 +14251,10 @@
1364414251 // LIVE = waslive;
1364514252 // wasliveok = true;
1364614253 // waslive = false;
14254
+
14255
+ // May 2019 Forget it:
14256
+ if (true)
14257
+ return;
1364714258
1364814259 // source == timer
1364914260 if (mouseDown)
....@@ -13674,7 +14285,7 @@
1367414285
1367514286 // fev 2014???
1367614287 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13677
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14288
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1367814289 pingthread.StepToTarget(true); // true);
1367914290 }
1368014291 // if (!LIVE)
....@@ -13683,12 +14294,13 @@
1368314294
1368414295 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1368514296
13686
- void clickStart(int x, int y, int modifiers)
14297
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1368714298 {
1368814299 if (!wasliveok)
1368914300 return;
1369014301
1369114302 AAtimer.restart(); //
14303
+ Globals.TIMERRUNNING = true;
1369214304
1369314305 // waslive = LIVE;
1369414306 // LIVE = false;
....@@ -13700,7 +14312,7 @@
1370014312 // touched = true; // main DL
1370114313 if (isRenderer)
1370214314 {
13703
- SetMouseMode(modifiers);
14315
+ SetMouseMode(modifiers, modifiersex);
1370414316 }
1370514317
1370614318 selectX = anchorX = x;
....@@ -13713,7 +14325,7 @@
1371314325 clicked = true;
1371414326 hold = false;
1371514327
13716
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14328
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1371714329 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1371814330 {
1371914331 // System.out.println("RESTART II " + modifiers);
....@@ -13738,14 +14350,15 @@
1373814350 drag = false;
1373914351 //System.out.println("Mouse DOWN");
1374014352 editObj = false;
13741
- ClickInfo info = new ClickInfo();
13742
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
13743
- info.pane = this;
13744
- info.camera = renderCamera;
13745
- info.x = x;
13746
- info.y = y;
13747
- info.modifiers = modifiers;
13748
- editObj = object.doEditClick(info, 0);
14353
+ //ClickInfo info = new ClickInfo();
14354
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14355
+ object.clickInfo.pane = this;
14356
+ object.clickInfo.camera = renderCamera;
14357
+ object.clickInfo.x = x;
14358
+ object.clickInfo.y = y;
14359
+ object.clickInfo.modifiers = modifiersex;
14360
+ editObj = object.doEditClick(//info,
14361
+ 0);
1374914362 if (!editObj)
1375014363 {
1375114364 hasMarquee = true;
....@@ -13761,9 +14374,12 @@
1376114374
1376214375 public void mouseDragged(MouseEvent e)
1376314376 {
14377
+ Globals.MOUSEDRAGGED = true;
14378
+
1376414379 //System.out.println("mouseDragged: " + e);
1376514380 if (isRenderer)
1376614381 movingcamera = true;
14382
+
1376714383 //if (drawing)
1376814384 //return;
1376914385 if ((e.getModifiersEx() & CTRL) != 0
....@@ -13773,7 +14389,7 @@
1377314389 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1377414390 }
1377514391 else
13776
- drag(e.getX(), e.getY(), e.getModifiersEx());
14392
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1377714393
1377814394 //try { Thread.sleep(1); } catch (Exception ex) {}
1377914395 }
....@@ -13946,6 +14562,7 @@
1394614562
1394714563 public void run()
1394814564 {
14565
+ new Exception().printStackTrace();
1394914566 System.exit(0);
1395014567 for (;;)
1395114568 {
....@@ -14009,7 +14626,7 @@
1400914626 {
1401014627 Globals.lighttouched = true;
1401114628 }
14012
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14629
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1401314630 }
1401414631 //else
1401514632 }
....@@ -14023,12 +14640,12 @@
1402314640 void GoDown(int mod)
1402414641 {
1402514642 MODIFIERS |= COMMAND;
14026
- /*
14643
+ /**/
1402714644 if((mod&SHIFT) == SHIFT)
14028
- manipCamera.RotatePosition(0, -speed);
14645
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
1402914646 else
14030
- manipCamera.BackForth(0, -speed*delta, getWidth());
14031
- */
14647
+ manipCamera.RotatePosition(0, -speed);
14648
+ /**/
1403214649 if ((mod & SHIFT) == SHIFT)
1403314650 {
1403414651 mouseMode = mouseMode; // VR??
....@@ -14044,12 +14661,12 @@
1404414661 void GoUp(int mod)
1404514662 {
1404614663 MODIFIERS |= COMMAND;
14047
- /*
14664
+ /**/
1404814665 if((mod&SHIFT) == SHIFT)
14049
- manipCamera.RotatePosition(0, speed);
14666
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
1405014667 else
14051
- manipCamera.BackForth(0, speed*delta, getWidth());
14052
- */
14668
+ manipCamera.RotatePosition(0, speed);
14669
+ /**/
1405314670 if ((mod & SHIFT) == SHIFT)
1405414671 {
1405514672 mouseMode = mouseMode;
....@@ -14065,12 +14682,12 @@
1406514682 void GoLeft(int mod)
1406614683 {
1406714684 MODIFIERS |= COMMAND;
14068
- /*
14685
+ /**/
1406914686 if((mod&SHIFT) == SHIFT)
14070
- manipCamera.RotatePosition(speed, 0);
14071
- else
1407214687 manipCamera.Translate(speed*delta, 0, getWidth());
14073
- */
14688
+ else
14689
+ manipCamera.RotatePosition(speed, 0);
14690
+ /**/
1407414691 if ((mod & SHIFT) == SHIFT)
1407514692 {
1407614693 mouseMode = mouseMode;
....@@ -14086,12 +14703,12 @@
1408614703 void GoRight(int mod)
1408714704 {
1408814705 MODIFIERS |= COMMAND;
14089
- /*
14706
+ /**/
1409014707 if((mod&SHIFT) == SHIFT)
14091
- manipCamera.RotatePosition(-speed, 0);
14092
- else
1409314708 manipCamera.Translate(-speed*delta, 0, getWidth());
14094
- */
14709
+ else
14710
+ manipCamera.RotatePosition(-speed, 0);
14711
+ /**/
1409514712 if ((mod & SHIFT) == SHIFT)
1409614713 {
1409714714 mouseMode = mouseMode;
....@@ -14109,7 +14726,7 @@
1410914726 int X, Y;
1411014727 boolean SX, SY;
1411114728
14112
- void drag(int x, int y, int modifiers)
14729
+ void drag(int x, int y, int modifiers, int modifiersex)
1411314730 {
1411414731 if (IsFrozen())
1411514732 {
....@@ -14118,17 +14735,17 @@
1411814735
1411914736 drag = true; // NEW
1412014737
14121
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14738
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1412214739
1412314740 X = x;
1412414741 Y = y;
1412514742 // floating state for animation
14126
- MODIFIERS = modifiers;
14127
- modifiers &= ~1024;
14743
+ MODIFIERS = modifiersex;
14744
+ modifiersex &= ~1024;
1412814745 if (false) // modifiers != 0)
1412914746 {
1413014747 //new Exception().printStackTrace();
14131
- System.out.println("mouseDragged: " + modifiers);
14748
+ System.out.println("mouseDragged: " + modifiersex);
1413214749 System.out.println("SHIFT = " + SHIFT);
1413314750 System.out.println("CONTROL = " + COMMAND);
1413414751 System.out.println("META = " + META);
....@@ -14141,14 +14758,16 @@
1414114758 if (editObj)
1414214759 {
1414314760 drag = true;
14144
- ClickInfo info = new ClickInfo();
14145
- info.bounds.setBounds(0, 0,
14761
+ //ClickInfo info = new ClickInfo();
14762
+ object.clickInfo.bounds.setBounds(0, 0,
1414614763 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14147
- info.pane = this;
14148
- info.camera = renderCamera;
14149
- info.x = x;
14150
- info.y = y;
14151
- object.editWindow.copy.doEditDrag(info);
14764
+ object.clickInfo.pane = this;
14765
+ object.clickInfo.camera = renderCamera;
14766
+ object.clickInfo.x = x;
14767
+ object.clickInfo.y = y;
14768
+ object //.GetWindow().copy
14769
+ .doEditDrag(//info,
14770
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1415214771 } else
1415314772 {
1415414773 if (x < startX)
....@@ -14297,22 +14916,27 @@
1429714916 }
1429814917 }
1429914918
14919
+// ClickInfo clickInfo = new ClickInfo();
14920
+
1430014921 public void mouseMoved(MouseEvent e)
1430114922 {
1430214923 //System.out.println("mouseMoved: " + e);
1430314924 if (isRenderer)
1430414925 return;
1430514926
14306
- ClickInfo ci = new ClickInfo();
14307
- ci.x = e.getX();
14308
- ci.y = e.getY();
14309
- ci.modifiers = e.getModifiersEx();
14310
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14311
- ci.pane = this;
14312
- ci.camera = renderCamera;
14927
+ // Mouse cursor feedback
14928
+ object.clickInfo.x = e.getX();
14929
+ object.clickInfo.y = e.getY();
14930
+ object.clickInfo.modifiers = e.getModifiersEx();
14931
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14932
+ object.clickInfo.pane = this;
14933
+ object.clickInfo.camera = renderCamera;
1431314934 if (!isRenderer)
1431414935 {
14315
- if (object.editWindow.copy.doEditClick(ci, 0))
14936
+ //ObjEditor editWindow = object.editWindow;
14937
+ //Object3D copy = editWindow.copy;
14938
+ if (object.doEditClick(//clickInfo,
14939
+ 0))
1431614940 {
1431714941 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1431814942 } else
....@@ -14324,7 +14948,11 @@
1432414948
1432514949 public void mouseReleased(MouseEvent e)
1432614950 {
14951
+ Globals.MOUSEDRAGGED = false;
14952
+
1432714953 movingcamera = false;
14954
+ X = 0; // getBounds().width/2;
14955
+ Y = 0; // getBounds().height/2;
1432814956 //System.out.println("mouseReleased: " + e);
1432914957 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1433014958 }
....@@ -14347,9 +14975,9 @@
1434714975 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1434814976 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1434914977
14350
- if (control || command || IsFrozen())
14978
+// No delay if (control || command || IsFrozen())
1435114979 timeout = true;
14352
- else
14980
+// ?? May 2019 else
1435314981 // timer.setDelay((modifiers & 128) != 0?0:350);
1435414982 mouseDown = false;
1435514983 if (!control && !command) // june 2013
....@@ -14459,7 +15087,7 @@
1445915087 System.out.println("keyReleased: " + e);
1446015088 }
1446115089
14462
- void SetMouseMode(int modifiers)
15090
+ void SetMouseMode(int modifiers, int modifiersex)
1446315091 {
1446415092 //System.out.println("SetMouseMode = " + modifiers);
1446515093 //modifiers &= ~1024;
....@@ -14471,25 +15099,25 @@
1447115099 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1447215100 // return;
1447315101 //System.out.println("SetMode = " + modifiers);
14474
- if ((modifiers & WHEEL) == WHEEL)
15102
+ if ((modifiersex & WHEEL) == WHEEL)
1447515103 {
1447615104 mouseMode |= ZOOM;
1447715105 }
1447815106
1447915107 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
14480
- if (capsLocked || (modifiers & META) == META)
15108
+ if (capsLocked) // || (modifiers & META) == META)
1448115109 {
1448215110 mouseMode |= VR; // BACKFORTH;
1448315111 }
14484
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
15112
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1448515113 {
1448615114 mouseMode |= SELECT;
1448715115 }
14488
- if ((modifiers & COMMAND) == COMMAND)
15116
+ if ((modifiersex & COMMAND) == COMMAND)
1448915117 {
1449015118 mouseMode |= SELECT;
1449115119 }
14492
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15120
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
1449315121 {
1449415122 mouseMode &= ~VR;
1449515123 mouseMode |= TRANSLATE;
....@@ -14518,7 +15146,7 @@
1451815146
1451915147 if (isRenderer) //
1452015148 {
14521
- SetMouseMode(modifiers);
15149
+ SetMouseMode(0, modifiers);
1452215150 }
1452315151
1452415152 Globals.theRenderer.keyPressed(key);
....@@ -14580,7 +15208,8 @@
1458015208 // break;
1458115209 case 'T':
1458215210 CACHETEXTURE ^= true;
14583
- textures.clear();
15211
+ texturepigment.clear();
15212
+ texturebump.clear();
1458415213 // repaint();
1458515214 break;
1458615215 case 'Y':
....@@ -14665,7 +15294,9 @@
1466515294 case 'E' : COMPACT ^= true;
1466615295 repaint();
1466715296 break;
14668
- case 'W' : DEBUGHSB ^= true;
15297
+ case 'W' : // Wide Window (fullscreen)
15298
+ //DEBUGHSB ^= true;
15299
+ ObjEditor.theFrame.ToggleFullScreen();
1466915300 repaint();
1467015301 break;
1467115302 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14690,8 +15321,8 @@
1469015321 RevertCamera();
1469115322 repaint();
1469215323 break;
14693
- case 'L':
1469415324 case 'l':
15325
+ //case 'L':
1469515326 if (lightMode)
1469615327 {
1469715328 lightMode = false;
....@@ -14755,20 +15386,24 @@
1475515386 OCCLUSION_CULLING ^= true;
1475615387 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1475715388 break;
14758
- case '0': envyoff ^= true; repaint(); break;
15389
+ //case '0': envyoff ^= true; repaint(); break;
1475915390 case '1':
1476015391 case '2':
1476115392 case '3':
1476215393 case '4':
1476315394 case '5':
14764
- newenvy = Character.getNumericValue(key);
14765
- repaint();
14766
- break;
1476715395 case '6':
1476815396 case '7':
1476915397 case '8':
1477015398 case '9':
14771
- BGcolor = (key - '6')/3.f;
15399
+ if (true) // envyoff)
15400
+ {
15401
+ BGcolor = (key - '1')/8.f;
15402
+ }
15403
+ else
15404
+ {
15405
+ //newenvy = Character.getNumericValue(key);
15406
+ }
1477215407 repaint();
1477315408 break;
1477415409 case '!':
....@@ -14834,9 +15469,9 @@
1483415469 case '_':
1483515470 kompactbit = 5;
1483615471 break;
14837
- case '+':
14838
- kompactbit = 6;
14839
- break;
15472
+// case '+':
15473
+// kompactbit = 6;
15474
+// break;
1484015475 case ' ':
1484115476 lightMode ^= true;
1484215477 Globals.lighttouched = true;
....@@ -14848,13 +15483,14 @@
1484815483 case ESC:
1484915484 RENDERPROGRAM += 1;
1485015485 RENDERPROGRAM %= 3;
15486
+
1485115487 repaint();
1485215488 break;
1485315489 case 'Z':
1485415490 //RESIZETEXTURE ^= true;
1485515491 //break;
1485615492 case 'z':
14857
- RENDERSHADOW ^= true;
15493
+ Globals.RENDERSHADOW ^= true;
1485815494 Globals.lighttouched = true;
1485915495 repaint();
1486015496 break;
....@@ -14887,8 +15523,9 @@
1488715523 case DELETE:
1488815524 ClearSelection();
1488915525 break;
14890
- /*
1489115526 case '+':
15527
+
15528
+ /*
1489215529 //fontsize += 1;
1489315530 bbzoom *= 2;
1489415531 repaint();
....@@ -14905,17 +15542,17 @@
1490515542 case '=':
1490615543 IncDepth();
1490715544 //fontsize += 1;
14908
- object.editWindow.refreshContents(true);
15545
+ object.GetWindow().refreshContents(true);
1490915546 maskbit = 6;
1491015547 break;
1491115548 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1491215549 DecDepth();
1491315550 maskbit = 5;
1491415551 //if(fontsize > 1) fontsize -= 1;
14915
- if (object.editWindow == null)
14916
- new Exception().printStackTrace();
14917
- else
14918
- object.editWindow.refreshContents(true);
15552
+// if (object.editWindow == null)
15553
+// new Exception().printStackTrace();
15554
+// else
15555
+ object.GetWindow().refreshContents(true);
1491915556 break;
1492015557 case '{':
1492115558 manipCamera.shaper_fovy /= 1.1;
....@@ -14978,7 +15615,7 @@
1497815615 //mode = ROTATE;
1497915616 if ((MODIFIERS & COMMAND) == 0) // VR??
1498015617 {
14981
- SetMouseMode(modifiers);
15618
+ SetMouseMode(0, modifiers);
1498215619 }
1498315620 }
1498415621
....@@ -15114,7 +15751,7 @@
1511415751 {
1511515752 //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
1511615753 //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15117
- if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (mouseMode & SELECT) == 0)
15754
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1511815755 {
1511915756 mouseMoved(e);
1512015757 } else
....@@ -15139,11 +15776,12 @@
1513915776 }
1514015777 */
1514115778
15142
- object.editWindow.EditSelection();
15779
+ object.GetWindow().EditSelection(false);
1514315780 }
1514415781
1514515782 void SelectParent()
1514615783 {
15784
+ new Exception().printStackTrace();
1514715785 System.exit(0);
1514815786 Composite group = (Composite) object;
1514915787 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -15155,10 +15793,10 @@
1515515793 {
1515615794 //selectees.remove(i);
1515715795 System.out.println("select parent of " + elem);
15158
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15796
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1515915797 } else
1516015798 {
15161
- group.editWindow.Select(elem.GetTreePath(), first, true);
15799
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1516215800 }
1516315801
1516415802 first = false;
....@@ -15167,6 +15805,7 @@
1516715805
1516815806 void SelectChildren()
1516915807 {
15808
+ new Exception().printStackTrace();
1517015809 System.exit(0);
1517115810 /*
1517215811 Composite group = (Composite) object;
....@@ -15199,12 +15838,12 @@
1519915838 for (int j = 0; j < group.children.size(); j++)
1520015839 {
1520115840 elem = (Object3D) group.children.elementAt(j);
15202
- object.editWindow.Select(elem.GetTreePath(), first, true);
15841
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1520315842 first = false;
1520415843 }
1520515844 } else
1520615845 {
15207
- object.editWindow.Select(elem.GetTreePath(), first, true);
15846
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1520815847 }
1520915848
1521015849 first = false;
....@@ -15215,21 +15854,21 @@
1521515854 {
1521615855 //Composite group = (Composite) object;
1521715856 Object3D group = object;
15218
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15857
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1521915858 }
1522015859
1522115860 void ResetTransform(int mask)
1522215861 {
1522315862 //Composite group = (Composite) object;
1522415863 Object3D group = object;
15225
- group.editWindow.ResetTransform(mask);
15864
+ group.GetWindow().ResetTransform(mask);
1522615865 }
1522715866
1522815867 void FlipTransform()
1522915868 {
1523015869 //Composite group = (Composite) object;
1523115870 Object3D group = object;
15232
- group.editWindow.FlipTransform();
15871
+ group.GetWindow().FlipTransform();
1523315872 // group.editWindow.ReduceMesh(true);
1523415873 }
1523515874
....@@ -15237,7 +15876,7 @@
1523715876 {
1523815877 //Composite group = (Composite) object;
1523915878 Object3D group = object;
15240
- group.editWindow.PrintMemory();
15879
+ group.GetWindow().PrintMemory();
1524115880 // group.editWindow.ReduceMesh(true);
1524215881 }
1524315882
....@@ -15245,7 +15884,7 @@
1524515884 {
1524615885 //Composite group = (Composite) object;
1524715886 Object3D group = object;
15248
- group.editWindow.ResetCentroid();
15887
+ group.GetWindow().ResetCentroid();
1524915888 }
1525015889
1525115890 void IncDepth()
....@@ -15327,11 +15966,11 @@
1532715966
1532815967 int width = getBounds().width;
1532915968 int height = getBounds().height;
15330
- ClickInfo info = new ClickInfo();
15331
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1533215969 //Image img = CreateImage(width, height);
1533315970 //System.out.println("width = " + width + "; height = " + height + "\n");
15971
+
1533415972 Graphics gr = g; // img.getGraphics();
15973
+
1533515974 if (!hasMarquee)
1533615975 {
1533715976 if (Xmin < Xmax) // !locked)
....@@ -15403,40 +16042,88 @@
1540316042 }
1540416043 if (object != null && !hasMarquee)
1540516044 {
16045
+ if (object.clickInfo == null)
16046
+ object.clickInfo = new ClickInfo();
16047
+ ClickInfo info = object.clickInfo;
16048
+ //ClickInfo info = new ClickInfo();
16049
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16050
+
1540616051 if (isRenderer)
1540716052 {
15408
- info.flags++;
16053
+ object.clickInfo.flags++;
1540916054 double frameAspect = (double) width / (double) height;
1541016055 if (frameAspect > renderCamera.aspect)
1541116056 {
1541216057 int desired = (int) ((double) height * renderCamera.aspect);
15413
- info.bounds.width -= width - desired;
15414
- info.bounds.x += (width - desired) / 2;
16058
+ object.clickInfo.bounds.width -= width - desired;
16059
+ object.clickInfo.bounds.x += (width - desired) / 2;
1541516060 } else
1541616061 {
1541716062 int desired = (int) ((double) width / renderCamera.aspect);
15418
- info.bounds.height -= height - desired;
15419
- info.bounds.y += (height - desired) / 2;
16063
+ object.clickInfo.bounds.height -= height - desired;
16064
+ object.clickInfo.bounds.y += (height - desired) / 2;
1542016065 }
1542116066 }
15422
- info.g = gr;
15423
- info.camera = renderCamera;
16067
+
16068
+ object.clickInfo.g = gr;
16069
+ object.clickInfo.camera = renderCamera;
1542416070 /*
1542516071 // Memory intensive (brep.verticescopy)
1542616072 if (!(object instanceof Composite))
1542716073 object.draw(info, 0, false); // SLOW :
1542816074 */
15429
- if (!isRenderer)
16075
+ if (!isRenderer) // && drag)
1543016076 {
15431
- object.drawEditHandles(info, 0);
16077
+ Grafreed.Assert(object != null);
16078
+ Grafreed.Assert(object.selection != null);
16079
+ if (object.selection.Size() > 0)
16080
+ {
16081
+ int hitSomething = object.selection.get(0).hitSomething;
16082
+
16083
+ object.clickInfo.DX = 0;
16084
+ object.clickInfo.DY = 0;
16085
+ object.clickInfo.W = 1;
16086
+ if (hitSomething == Object3D.hitCenter)
16087
+ {
16088
+ info.DX = X;
16089
+ if (X != 0)
16090
+ info.DX -= info.bounds.width/2;
16091
+
16092
+ info.DY = Y;
16093
+ if (Y != 0)
16094
+ info.DY -= info.bounds.height/2;
16095
+ }
16096
+
16097
+ object.drawEditHandles(//info,
16098
+ 0);
16099
+
16100
+ if (drag && (X != 0 || Y != 0))
16101
+ {
16102
+ switch (hitSomething)
16103
+ {
16104
+ case Object3D.hitCenter: gr.setColor(Color.pink);
16105
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16106
+ break;
16107
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16108
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16109
+ break;
16110
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16111
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16112
+ break;
16113
+ }
16114
+
16115
+ }
16116
+ }
1543216117 }
1543316118 }
16119
+
1543416120 if (isRenderer)
1543516121 {
1543616122 //gr.setColor(Color.black);
1543716123 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1543816124 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1543916125 }
16126
+
1544016127 if (hasMarquee)
1544116128 {
1544216129 gr.setXORMode(Color.white);
....@@ -15549,6 +16236,7 @@
1554916236 public boolean mouseDown(Event evt, int x, int y)
1555016237 {
1555116238 System.out.println("mouseDown: " + evt);
16239
+ System.exit(0);
1555216240 /*
1555316241 locked = true;
1555416242 drag = false;
....@@ -15592,7 +16280,7 @@
1559216280 {
1559316281 keyPressed(0, modifiers);
1559416282 }
15595
- clickStart(x, y, modifiers);
16283
+ // clickStart(x, y, modifiers);
1559616284 return true;
1559716285 }
1559816286
....@@ -15710,7 +16398,7 @@
1571016398 {
1571116399 keyReleased(0, 0);
1571216400 }
15713
- drag(x, y, modifiers);
16401
+ drag(x, y, 0, modifiers);
1571416402 return true;
1571516403 }
1571616404
....@@ -15842,7 +16530,7 @@
1584216530 Object3D object;
1584316531 static Object3D trackedobject;
1584416532 Camera renderCamera; // Light or Eye (or Occlusion)
15845
- /*static*/ Camera manipCamera; // Light or Eye
16533
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1584616534 /*static*/ Camera eyeCamera;
1584716535 /*static*/ Camera lightCamera;
1584816536 int cameracount;
....@@ -15906,6 +16594,8 @@
1590616594 private /*static*/ boolean firstime;
1590716595 private /*static*/ cVector newView = new cVector();
1590816596 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16597
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16598
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1590916599 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1591016600 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1591116601 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -15918,29 +16608,67 @@
1591816608 {
1591916609 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1592016610
16611
+ int usedsuf = 0;
16612
+
1592116613 for (int i = 0; i < suffixes.length; i++)
1592216614 {
15923
- String resourceName = basename + suffixes[i] + "." + suffix;
15924
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
15925
- mipmapped,
15926
- FileUtil.getFileSuffix(resourceName));
15927
- if (data == null)
16615
+ String[] suffixe = suffixes;
16616
+ String[] fallback = suffixes2;
16617
+ String[] fallfallback = suffixes3;
16618
+
16619
+ for (int c=usedsuf; --c>=0;)
1592816620 {
15929
- throw new IOException("Unable to load texture " + resourceName);
16621
+// String[] temp = suffixe;
16622
+// suffixe = fallback;
16623
+// fallback = fallfallback;
16624
+// fallfallback = temp;
1593016625 }
16626
+
16627
+ String resourceName = basename + suffixe[i] + "." + suffix;
16628
+ TextureData data;
16629
+
16630
+ try
16631
+ {
16632
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16633
+ mipmapped,
16634
+ FileUtil.getFileSuffix(resourceName));
16635
+ }
16636
+ catch (Exception e)
16637
+ {
16638
+ try
16639
+ {
16640
+ resourceName = basename + fallback[i] + "." + suffix;
16641
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16642
+ mipmapped,
16643
+ FileUtil.getFileSuffix(resourceName));
16644
+ }
16645
+ catch (Exception e2)
16646
+ {
16647
+ resourceName = basename + fallfallback[i] + "." + suffix;
16648
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16649
+ mipmapped,
16650
+ FileUtil.getFileSuffix(resourceName));
16651
+ }
16652
+ }
16653
+
1593116654 //System.out.println("Target = " + targets[i]);
1593216655 cubemap.updateImage(data, targets[i]);
1593316656 }
1593416657
1593516658 return cubemap;
1593616659 }
16660
+
1593716661 int bigsphere = -1;
1593816662
1593916663 float BGcolor = 0.5f;
1594016664
15941
- private void DrawSkyBox(GL gl)
16665
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16666
+
16667
+ private void DrawSkyBox(GL gl, float ratio)
1594216668 {
15943
- if (envyoff || cubemap == null)
16669
+ if (//envyoff ||
16670
+ WIREFRAME ||
16671
+ cubemap == null)
1594416672 {
1594516673 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1594616674 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -15955,7 +16683,17 @@
1595516683 // Compensates for ExaminerViewer's modification of modelview matrix
1595616684 gl.glMatrixMode(GL.GL_MODELVIEW);
1595716685 gl.glLoadIdentity();
16686
+ gl.glScalef(1,ratio,1);
1595816687
16688
+// colorV[0] = 2;
16689
+// colorV[1] = 2;
16690
+// colorV[2] = 2;
16691
+// colorV[3] = 1;
16692
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16693
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16694
+//
16695
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16696
+
1595916697 //gl.glActiveTexture(GL.GL_TEXTURE1);
1596016698 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1596116699
....@@ -15987,6 +16725,7 @@
1598716725 {
1598816726 gl.glScalef(1.0f, -1.0f, 1.0f);
1598916727 }
16728
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1599016729 gl.glMultMatrixd(viewrot_1, 0);
1599116730 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1599216731 //viewer.updateInverseRotation(gl);
....@@ -16127,16 +16866,16 @@
1612716866 cStatic.objectstack[materialdepth++] = checker;
1612816867 //System.out.println("material " + material);
1612916868 //Applet3D.tracein(this, selected);
16130
- vector2buffer = checker.projectedVertices;
16869
+ //vector2buffer = checker.projectedVertices;
1613116870
1613216871 //checker.GetMaterial().Draw(this, false); // true);
16133
- DrawMaterial(checker.GetMaterial(), false); // true);
16872
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1613416873
1613516874 materialdepth -= 1;
1613616875 if (materialdepth > 0)
1613716876 {
16138
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16139
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
16877
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16878
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1614016879 }
1614116880 //checker.GetMaterial().opacity = 1f;
1614216881 ////checker.GetMaterial().ambient = 1f;
....@@ -16222,6 +16961,14 @@
1622216961 }
1622316962 }
1622416963
16964
+ private Object3D GetFolder()
16965
+ {
16966
+ Object3D folder = object.GetWindow().copy;
16967
+ if (object.GetWindow().copy.selection.Size() > 0)
16968
+ folder = object.GetWindow().copy.selection.elementAt(0);
16969
+ return folder;
16970
+ }
16971
+
1622516972 class SelectBuffer implements GLEventListener
1622616973 {
1622716974
....@@ -16237,7 +16984,7 @@
1623716984 //new Exception().printStackTrace();
1623816985 System.out.println("select buffer init");
1623916986 // Use debug pipeline
16240
- drawable.setGL(new DebugGL(drawable.getGL()));
16987
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1624116988
1624216989 GL gl = drawable.getGL();
1624316990
....@@ -16280,6 +17027,7 @@
1628017027 {
1628117028 if (!selection)
1628217029 {
17030
+ new Exception().printStackTrace();
1628317031 System.exit(0);
1628417032 return;
1628517033 }
....@@ -16300,6 +17048,17 @@
1630017048
1630117049 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1630217050
17051
+ if (PAINTMODE)
17052
+ {
17053
+ if (object.GetWindow().copy.selection.Size() > 0)
17054
+ {
17055
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17056
+
17057
+ // Make what you paint not selectable.
17058
+ paintobj.ResetSelectable();
17059
+ }
17060
+ }
17061
+
1630317062 //int tmp = selection_view;
1630417063 //selection_view = -1;
1630517064 int temp = DrawMode();
....@@ -16311,6 +17070,17 @@
1631117070 // temp = DEFAULT; // patch for selection debug
1631217071 Globals.drawMode = temp; // WARNING
1631317072
17073
+ if (PAINTMODE)
17074
+ {
17075
+ if (object.GetWindow().copy.selection.Size() > 0)
17076
+ {
17077
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17078
+
17079
+ // Revert.
17080
+ paintobj.RestoreSelectable();
17081
+ }
17082
+ }
17083
+
1631417084 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1631517085
1631617086 // trying different ways of getting the depth info over
....@@ -16358,6 +17128,8 @@
1635817128 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1635917129 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1636017130 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
17131
+
17132
+ CreateSelectedPoint();
1636117133
1636217134 // Will fit the mesh !!!
1636317135 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16407,34 +17179,36 @@
1640717179 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]));
1640817180 }
1640917181
16410
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
17182
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1641117183 }
1641217184 }
1641317185
1641417186 if (!movingcamera && !PAINTMODE)
16415
- object.editWindow.ScreenFitPoint(); // fev 2014
17187
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1641617188
16417
- if (PAINTMODE && GrafreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17189
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1641817190 {
16419
- Object3D paintobj = GrafreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17191
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1642017192
16421
- Object3D group = new Object3D("inst" + paintcount++);
17193
+ if (object.GetWindow().copy.selection.Size() > 0)
17194
+ {
17195
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1642217196
16423
- group.CreateMaterial(); // use a void leaf to select instances
16424
-
16425
- group.add(paintobj); // link
16426
-
16427
- object.editWindow.SnapObject(group);
16428
-
16429
- Object3D folder = object.editWindow.copy;
16430
-
16431
- if (object.editWindow.copy.selection.Size() > 0)
16432
- folder = object.editWindow.copy.selection.elementAt(0);
16433
-
16434
- folder.add(group);
16435
-
16436
- object.editWindow.ResetModel();
16437
- object.editWindow.refreshContents();
17197
+ Object3D inst = new Object3D("inst" + paintcount++);
17198
+
17199
+ inst.CreateMaterial(); // use a void leaf to select instances
17200
+
17201
+ inst.add(paintobj); // link
17202
+
17203
+ object.GetWindow().SnapObject(inst);
17204
+
17205
+ Object3D folder = paintFolder; // GetFolder();
17206
+
17207
+ folder.add(inst);
17208
+
17209
+ object.GetWindow().ResetModel();
17210
+ object.GetWindow().refreshContents();
17211
+ }
1643817212 }
1643917213 else
1644017214 paintcount = 0;
....@@ -16473,6 +17247,11 @@
1647317247 //System.out.println("objects[color] = " + objects[color]);
1647417248 //objects[color].Select();
1647517249 indexcount = 0;
17250
+ ObjEditor window = object.GetWindow();
17251
+ if (window != null && deselect)
17252
+ {
17253
+ window.Select(null, deselect, true);
17254
+ }
1647617255 object.Select(color, deselect);
1647717256 }
1647817257
....@@ -16572,7 +17351,7 @@
1657217351 gl.glDisable(gl.GL_CULL_FACE);
1657317352 }
1657417353
16575
- if (!RENDERSHADOW)
17354
+ if (!Globals.RENDERSHADOW)
1657617355 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1657717356
1657817357 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -16582,7 +17361,7 @@
1658217361 //gl.glColorMask(false, false, false, false);
1658317362
1658417363 //render_scene_from_light_view(gl, drawable, 0, 0);
16585
- if (RENDERSHADOW && Globals.lighttouched && !movingcamera) // && !parent.IsFreezed())
17364
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1658617365 {
1658717366 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1658817367
....@@ -16998,23 +17777,15 @@
1699817777 int AAbuffersize = 0;
1699917778
1700017779 //double[] selectedpoint = new double[3];
17001
- static Superellipsoid selectedpoint = new Superellipsoid();
17780
+ static Superellipsoid selectedpoint;
1700217781 static Sphere previousselectedpoint = null;
17003
- static Sphere debugpointG = new Sphere();
17004
- static Sphere debugpointP = new Sphere();
17005
- static Sphere debugpointC = new Sphere();
17006
- static Sphere debugpointR = new Sphere();
17782
+ static Sphere debugpointG;
17783
+ static Sphere debugpointP;
17784
+ static Sphere debugpointC;
17785
+ static Sphere debugpointR;
1700717786
1700817787 static Sphere debugpoints[] = new Sphere[8];
1700917788
17010
- static
17011
- {
17012
- for (int i=0; i<8; i++)
17013
- {
17014
- debugpoints[i] = new Sphere();
17015
- }
17016
- }
17017
-
1701817789 static void InitPoints(float radius)
1701917790 {
1702017791 for (int i=0; i<8; i++)