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;
....@@ -92,6 +126,8 @@
92126
93127 static int tickcount = 0; // slow pose issue
94128
129
+static boolean BUTTONLESSWHEEL = false;
130
+static boolean ZOOMBOXMODE = false;
95131 static boolean BOXMODE = false;
96132 static boolean IMAGEFLIP = false;
97133 static boolean SMOOTHFOCUS = false;
....@@ -106,7 +142,7 @@
106142 static boolean OEIL = true;
107143 static boolean OEILONCE = false; // do oeilon then oeiloff
108144 static boolean LOOKAT = true;
109
-static boolean RANDOM = true; // false;
145
+static boolean SWITCH = true; // false;
110146 static boolean HANDLES = false; // selection doesn't work!!
111147 static boolean PAINTMODE = false;
112148
....@@ -150,6 +186,20 @@
150186 defaultcaps.setAccumAlphaBits(16);
151187 }
152188
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
+
153203 void SetAsGLRenderer(boolean b)
154204 {
155205 isRenderer = b;
....@@ -168,7 +218,8 @@
168218
169219 SetCamera(cam);
170220
171
- SetLight(new Camera(new cVector(10, 10, -20)));
221
+ // Warning: not used.
222
+ SetLight(new Camera(new cVector(15, 10, -20)));
172223
173224 object = o;
174225
....@@ -223,6 +274,11 @@
223274 public boolean IsBoxMode()
224275 {
225276 return BOXMODE;
277
+ }
278
+
279
+ public boolean IsZoomBoxMode()
280
+ {
281
+ return ZOOMBOXMODE;
226282 }
227283
228284 public void ClearDepth()
....@@ -320,7 +376,7 @@
320376 cStatic.objectstack[materialdepth++] = obj;
321377 //System.out.println("material " + material);
322378 //Applet3D.tracein(this, selected);
323
- display.vector2buffer = obj.projectedVertices;
379
+ //display.vector2buffer = obj.projectedVertices;
324380 if (obj instanceof Camera)
325381 {
326382 display.options1[0] = material.shift;
....@@ -329,14 +385,28 @@
329385 display.options1[2] = material.shadowbias;
330386 display.options1[3] = material.aniso;
331387 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]);
332393 display.options2[0] = material.opacity;
333394 display.options2[1] = material.diffuse;
334395 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]);
335399
336400 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]);
337404 display.options4[0] = material.cameralight/0.2f;
338405 display.options4[1] = material.subsurface;
339406 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]);
340410
341411 // if (display.CURRENTANTIALIAS > 0)
342412 // display.options3[3] /= 4;
....@@ -352,7 +422,7 @@
352422 /**/
353423 } else
354424 {
355
- DrawMaterial(material, selected);
425
+ DrawMaterial(material, selected, obj.projectedVertices);
356426 }
357427 } else
358428 {
....@@ -376,8 +446,8 @@
376446 cStatic.objectstack[materialdepth++] = obj;
377447 //System.out.println("material " + material);
378448 //Applet3D.tracein("selected ", selected);
379
- display.vector2buffer = obj.projectedVertices;
380
- display.DrawMaterial(material, selected);
449
+ //display.vector2buffer = obj.projectedVertices;
450
+ display.DrawMaterial(material, selected, obj.projectedVertices);
381451 }
382452 }
383453
....@@ -394,8 +464,8 @@
394464 materialdepth -= 1;
395465 if (materialdepth > 0)
396466 {
397
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
398
- 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);
399469 }
400470 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
401471 } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
....@@ -415,8 +485,8 @@
415485 materialdepth -= 1;
416486 if (materialdepth > 0)
417487 {
418
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
419
- 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);
420490 }
421491 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
422492 //else
....@@ -457,10 +527,12 @@
457527 if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
458528 {
459529 //gl.glBegin(gl.GL_TRIANGLES);
460
- 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
+ ;
461533 if (!hasnorm)
462534 {
463
- // System.out.println("FUCK!!");
535
+ // System.out.println("Mesh normal");
464536 LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
465537 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
466538 LA.vecCross(obj.v0, obj.v1, obj.v2);
....@@ -1185,10 +1257,12 @@
11851257 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
11861258 }
11871259 }
1260
+
11881261 if (flipV)
11891262 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
11901263 else
11911264 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1265
+
11921266 //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
11931267 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
11941268
....@@ -1208,10 +1282,12 @@
12081282 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
12091283 }
12101284 }
1285
+
12111286 if (flipV)
12121287 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12131288 else
12141289 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1290
+
12151291 //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
12161292 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
12171293
....@@ -1239,8 +1315,10 @@
12391315 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12401316 else
12411317 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1318
+
12421319 //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
12431320 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1321
+
12441322 count2 += 2;
12451323 count3 += 3;
12461324 }
....@@ -1419,6 +1497,8 @@
14191497 gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
14201498 }
14211499
1500
+ float[] colorV = new float[4];
1501
+
14221502 void SetColor(Object3D obj, Vertex p0)
14231503 {
14241504 CameraPane display = this;
....@@ -1486,8 +1566,6 @@
14861566 {
14871567 return;
14881568 }
1489
-
1490
- float[] colorV = new float[3];
14911569
14921570 if (false) // marked)
14931571 {
....@@ -1596,7 +1674,7 @@
15961674 // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
15971675 }
15981676
1599
- void DrawMaterial(cMaterial material, boolean selected)
1677
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
16001678 {
16011679 CameraPane display = this;
16021680 //new Exception().printStackTrace();
....@@ -1612,18 +1690,18 @@
16121690 //col.getColorComponents(ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB), CameraPane.modelParams0);
16131691 if (!material.multiply)
16141692 {
1615
- display.color = color;
1693
+ display.color = material.color;
16161694 display.saturation = material.modulation;
16171695 }
16181696 else
16191697 {
1620
- display.color *= color*2;
1698
+ display.color *= material.color*2;
16211699 display.saturation *= material.modulation*2;
16221700 }
16231701
16241702 cColor.HSBtoRGB(display.color, display.saturation, 1, display.modelParams0);
16251703
1626
- float[] colorV = GrafreeD.colorV;
1704
+ float[] colorV = Grafreed.colorV;
16271705
16281706 /**/
16291707 if (display.DrawMode() == display.DEFAULT) // && display.RENDERPROGRAM == 0)
....@@ -1631,7 +1709,7 @@
16311709 colorV[0] = display.modelParams0[0] * material.diffuse;
16321710 colorV[1] = display.modelParams0[1] * material.diffuse;
16331711 colorV[2] = display.modelParams0[2] * material.diffuse;
1634
- colorV[3] = material.opacity;
1712
+ colorV[3] = 1; // material.opacity;
16351713
16361714 gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
16371715 //System.out.println("Opacity = " + opacity);
....@@ -1739,9 +1817,9 @@
17391817 display.modelParams7[2] = 0;
17401818 display.modelParams7[3] = 0;
17411819
1742
- display.modelParams6[0] = 100; // criss de bug de bump
1820
+ //display.modelParams6[0] = 100; // criss de bug de bump
17431821
1744
- Object3D.cVector2[] extparams = display.vector2buffer;
1822
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
17451823 if (extparams != null && extparams.length > 0 && extparams[0] != null)
17461824 {
17471825 display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
....@@ -1883,7 +1961,7 @@
18831961 void PushMatrix(double[][] matrix)
18841962 {
18851963 // GrafreeD.tracein(matrix);
1886
- PushMatrix(matrix,1);
1964
+ PushMatrix(matrix, 1);
18871965 }
18881966
18891967 void PushMatrix()
....@@ -2037,7 +2115,7 @@
20372115 //System.err.println("Oeil on");
20382116 OEIL = true;
20392117 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2040
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2118
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
20412119 //pingthread.StepToTarget(true);
20422120 }
20432121
....@@ -2135,7 +2213,7 @@
21352213 System.err.println("LIVE = " + Globals.isLIVE());
21362214
21372215 if (!Globals.isLIVE()) // save sound
2138
- GrafreeD.savesound = true; // wav.save();
2216
+ Grafreed.savesound = true; // wav.save();
21392217 // else
21402218 repaint(); // start loop // may 2013
21412219 }
....@@ -2168,6 +2246,11 @@
21682246 public void ToggleBoxMode()
21692247 {
21702248 BOXMODE ^= true;
2249
+ }
2250
+
2251
+ public void ToggleZoomBoxMode()
2252
+ {
2253
+ ZOOMBOXMODE ^= true;
21712254 }
21722255
21732256 public void ToggleSmoothFocus()
....@@ -2247,7 +2330,7 @@
22472330
22482331 void ToggleDebug()
22492332 {
2250
- DEBUG ^= true;
2333
+ Globals.DEBUG ^= true;
22512334 }
22522335
22532336 void ToggleLookAt()
....@@ -2255,9 +2338,9 @@
22552338 LOOKAT ^= true;
22562339 }
22572340
2258
- void ToggleRandom()
2341
+ void ToggleSwitch()
22592342 {
2260
- RANDOM ^= true;
2343
+ SWITCH ^= true;
22612344 }
22622345
22632346 void ToggleHandles()
....@@ -2265,10 +2348,17 @@
22652348 HANDLES ^= true;
22662349 }
22672350
2351
+ Object3D paintFolder;
2352
+
22682353 void TogglePaint()
22692354 {
22702355 PAINTMODE ^= true;
22712356 paintcount = 0;
2357
+
2358
+ if (PAINTMODE)
2359
+ {
2360
+ paintFolder = GetFolder();
2361
+ }
22722362 }
22732363
22742364 void SwapCamera(int a, int b)
....@@ -2364,7 +2454,22 @@
23642454 {
23652455 return currentGL;
23662456 }
2367
-
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
+
23682473 /**/
23692474 class CacheTexture
23702475 {
....@@ -2373,28 +2478,31 @@
23732478
23742479 int resolution;
23752480
2376
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2481
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
23772482 {
2378
- texture = tex;
2483
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2484
+ texturedata = texdata;
23792485 resolution = res;
23802486 }
23812487 }
23822488 /**/
23832489
23842490 // TEXTURE static Texture texture;
2385
- static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures
2386
- = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>();
2387
- 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
+
23882496 int pigmentdepth = 0;
23892497 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
23902498 int bumpdepth = 0;
23912499 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
23922500 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
23932501 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2394
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2502
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
23952503 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
23962504
2397
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2505
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
23982506 {
23992507 TextureData texturedata = null;
24002508
....@@ -2413,13 +2521,34 @@
24132521 if (bump)
24142522 texturedata = ConvertBump(texturedata, false);
24152523
2416
- com.sun.opengl.util.texture.Texture texture =
2417
- 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);
24182526
2419
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2420
- 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);
24212529
2422
- 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;
24232552 }
24242553
24252554 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3492,6 +3621,8 @@
34923621
34933622 System.out.println("LOADING TEXTURE : " + name);
34943623
3624
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3625
+
34953626 //
34963627 if (false) // compressbit > 0)
34973628 {
....@@ -4196,6 +4327,7 @@
41964327
41974328 com.sun.opengl.util.texture.Texture CompressTexture2(String name)
41984329 {
4330
+ new Exception().printStackTrace();
41994331 System.exit(0);
42004332 com.sun.opengl.util.texture.Texture texture = null;
42014333
....@@ -7889,7 +8021,7 @@
78898021 String pigment = Object3D.GetPigment(tex);
78908022 String bump = Object3D.GetBump(tex);
78918023
7892
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8024
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
78938025 {
78948026 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
78958027 // System.out.println("; bump = " + bump);
....@@ -7904,11 +8036,69 @@
79048036 pigment = null;
79058037 }
79068038
7907
- ReleaseTexture(bump, true);
7908
- ReleaseTexture(pigment, false);
8039
+ ReleaseTexture(tex, true);
8040
+ ReleaseTexture(tex, false);
79098041 }
79108042
7911
- 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)
79128102 {
79138103 if (// DrawMode() != 0 || /*tex == null ||*/
79148104 ambientOcclusion ) // || !textureon)
....@@ -7919,7 +8109,7 @@
79198109 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
79208110
79218111 if (tex != null)
7922
- texture = textures.get(tex);
8112
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
79238113
79248114 // //assert( texture != null );
79258115 // if (texture == null)
....@@ -8011,7 +8201,55 @@
80118201 }
80128202 }
80138203
8014
- /*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
80158253 {
80168254 if (// DrawMode() != 0 || /*tex == null ||*/
80178255 ambientOcclusion ) // || !textureon)
....@@ -8022,17 +8260,47 @@
80228260 if (tex == null)
80238261 {
80248262 BindTexture(null,false,resolution);
8025
- BindTexture(null,true,resolution);
80268263 return;
80278264 }
80288265
80298266 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
+
80308299 String bump = Object3D.GetBump(tex);
80318300
8032
- usedtextures.put(pigment, pigment);
8033
- usedtextures.put(bump, bump);
8301
+ usedtextures.add(tex);
80348302
8035
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8303
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
80368304 {
80378305 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
80388306 // System.out.println("; bump = " + bump);
....@@ -8042,43 +8310,94 @@
80428310 {
80438311 bump = null;
80448312 }
8045
- if (pigment.equals(""))
8046
- {
8047
- pigment = null;
8048
- }
80498313
8050
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8051
- BindTexture(pigment, false, resolution);
80528314 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8053
- BindTexture(bump, true, resolution);
8315
+ BindTexture(tex, true, resolution);
80548316 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8055
-
8056
- return; // true;
80578317 }
80588318
8059
- 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)
80608322 {
8061
- 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;
80628342
80638343 if (tex != null)
80648344 {
8065
- String texname = tex;
8345
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8346
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
80668347
8067
- String[] split = tex.split("Textures");
8068
- if (split.length > 1)
8069
- texname = "/Users/nbriere/Textures" + split[split.length-1];
8070
- else
8071
- if (!texname.startsWith("/"))
8072
- 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
+ }
80738365
80748366 if (CACHETEXTURE)
8075
- texture = textures.get(texname); // TEXTURE CACHE
8076
-
8077
- TextureData texturedata = null;
8078
-
8079
- if (texture == null || texture.resolution < resolution)
80808367 {
8081
- 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(""))
80828401 {
80838402 assert(!bump);
80848403 // if (bump)
....@@ -8089,19 +8408,23 @@
80898408 // }
80908409 // else
80918410 // {
8092
- texture = textures.get(tex);
8093
- if (texture == null)
8411
+ // texturecache = textures.get(texname); // suspicious
8412
+ if (texturecache == null)
80948413 {
8095
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8414
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
80968415 }
8416
+ else
8417
+ new Exception().printStackTrace();
80978418 // }
80988419 } else
8099
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8420
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
81008421 {
81018422 assert(bump);
8102
- texture = textures.get(tex);
8103
- if (texture == null)
8104
- 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();
81058428 } else
81068429 {
81078430 //if (tex.equals("IMMORTAL"))
....@@ -8109,11 +8432,22 @@
81098432 // texture = GetResourceTexture("default.png");
81108433 //} else
81118434 //{
8112
- if (tex.equals("WHITE_NOISE"))
8435
+ if (texname.endsWith("WHITE_NOISE"))
81138436 {
8114
- texture = textures.get(tex);
8115
- if (texture == null)
8116
- 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();
81178451 } else
81188452 {
81198453 if (textureon)
....@@ -8138,7 +8472,7 @@
81388472 }
81398473
81408474 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
8141
- if (!new File(cachename).exists())
8475
+ if (!FileExists(cachename))
81428476 cachename = texname;
81438477 else
81448478 processbump = false; // don't process bump map again
....@@ -8160,7 +8494,7 @@
81608494 }
81618495
81628496 cachename = texname.substring(0, texname.length()-4)+ext+".png";
8163
- if (!new File(cachename).exists())
8497
+ if (!FileExists(cachename))
81648498 cachename = texname;
81658499 else
81668500 processbump = false; // don't process bump map again
....@@ -8169,20 +8503,23 @@
81698503 texturedata = GetFileTexture(cachename, processbump, resolution);
81708504
81718505
8172
- if (texturedata != null)
8173
- 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);
81748510 //texture = GetTexture(tex, bump);
81758511 }
8512
+ }
81768513 }
81778514 //}
81788515 }
81798516
8180
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8517
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
81818518 {
81828519 //return false;
81838520
81848521 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8185
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8522
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
81868523 {
81878524 // String ext = "_highres";
81888525 // if (REDUCETEXTURE)
....@@ -8199,52 +8536,17 @@
81998536 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
82008537 if (!cachefile.exists())
82018538 {
8202
- // cache to disk
8203
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
8204
- //buffers[0].
8205
-
8206
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
8207
- int[] pixels = new int[bytebuf.capacity()/3];
8208
-
8209
- // squared size heuristic...
8210
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8539
+ //if (texturedata.getWidth() == texturedata.getHeight())
82118540 {
8212
- for (int i=pixels.length; --i>=0;)
8213
- {
8214
- int i3 = i*3;
8215
- pixels[i] = 0xFF;
8216
- pixels[i] <<= 8;
8217
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
8218
- pixels[i] <<= 8;
8219
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
8220
- pixels[i] <<= 8;
8221
- pixels[i] |= bytebuf.get(i3) & 0xFF;
8222
- }
8223
-
8224
- /*
8225
- int r=0,g=0,b=0,a=0;
8226
- for (int i=0; i<width; i++)
8227
- for (int j=0; j<height; j++)
8228
- {
8229
- int index = j*width+i;
8230
- int p = pixels[index];
8231
- a = ((p>>24) & 0xFF);
8232
- r = ((p>>16) & 0xFF);
8233
- g = ((p>>8) & 0xFF);
8234
- b = (p & 0xFF);
8235
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
8236
- }
8237
- /**/
8238
- int width = (int)Math.sqrt(pixels.length); // squared
8239
- int height = width;
8240
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
8241
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8541
+ BufferedImage rendImage = CreateBim(texturedata);
8542
+
82428543 ImageWriter writer = null;
82438544 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
82448545 if (iter.hasNext()) {
82458546 writer = (ImageWriter)iter.next();
82468547 }
8247
- float compressionQuality = 0.9f;
8548
+
8549
+ float compressionQuality = 0.85f;
82488550 try
82498551 {
82508552 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8261,18 +8563,20 @@
82618563 }
82628564 }
82638565 }
8264
-
8566
+
8567
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8568
+
82658569 //System.out.println("Texture = " + tex);
8266
- if (textures.containsKey(texname))
8570
+ if (textures.containsKey(tex))
82678571 {
8268
- CacheTexture thetex = textures.get(texname);
8572
+ CacheTexture thetex = textures.get(tex);
82698573 thetex.texture.disable();
82708574 thetex.texture.dispose();
8271
- textures.remove(texname);
8575
+ textures.remove(tex);
82728576 }
82738577
8274
- texture.texturedata = texturedata;
8275
- textures.put(texname, texture);
8578
+ //texture.texturedata = texturedata;
8579
+ textures.put(tex, texturecache);
82768580
82778581 // newtex = true;
82788582 }
....@@ -8288,10 +8592,44 @@
82888592 }
82898593 }
82908594
8291
- return texture;
8595
+ return texturecache;
82928596 }
82938597
8294
- 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
82958633 {
82968634 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
82978635
....@@ -8309,21 +8647,21 @@
83098647 return texture!=null?texture.texture:null;
83108648 }
83118649
8312
- 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
83138651 {
83148652 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
83158653
83168654 return texture!=null?texture.texturedata:null;
83178655 }
83188656
8319
- boolean BindTexture(String tex, boolean bump, int resolution)
8657
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
83208658 {
83218659 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
83228660 {
83238661 return false;
83248662 }
83258663
8326
- boolean newtex = false;
8664
+ //boolean newtex = false;
83278665
83288666 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
83298667
....@@ -8355,9 +8693,75 @@
83558693 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
83568694 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
83578695
8358
- return newtex;
8696
+ return true; // Warning: not used.
83598697 }
83608698
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
+
83618765 ShadowBuffer shadowPBuf;
83628766 AntialiasBuffer antialiasPBuf;
83638767 int MAXSTACK;
....@@ -8550,7 +8954,7 @@
85508954
85518955 if (cubemap == null)
85528956 {
8553
- LoadEnvy(5);
8957
+ //LoadEnvy(1);
85548958 }
85558959
85568960 //cubemap.enable();
....@@ -8837,37 +9241,58 @@
88379241 cubemap = null;
88389242 return;
88399243 case 1:
8840
- name = "cubemaps/box_";
8841
- ext = "png";
9244
+ name = "cubemaps/rgb/";
9245
+ ext = "jpg";
88429246 reverseUP = false;
88439247 break;
88449248 case 2:
8845
- name = "cubemaps/uffizi_";
8846
- ext = "png";
8847
- break; // reverseUP = true; break;
9249
+ name = "cubemaps/uffizi/";
9250
+ ext = "jpg";
9251
+ reverseUP = false;
9252
+ break;
88489253 case 3:
8849
- name = "cubemaps/CloudyHills_";
8850
- ext = "tga";
9254
+ name = "cubemaps/CloudyHills/";
9255
+ ext = "jpg";
88519256 reverseUP = false;
88529257 break;
88539258 case 4:
8854
- name = "cubemaps/cornell_";
9259
+ name = "cubemaps/cornell/";
88559260 ext = "png";
88569261 reverseUP = false;
88579262 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;
88589288 default:
8859
- name = "cubemaps/rgb_";
8860
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9289
+ name = "cubemaps/box/";
9290
+ ext = "png"; /*mipmap = true;*/
9291
+ reverseUP = false;
88619292 break;
88629293 }
8863
-
8864
- try
8865
- {
8866
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
8867
- } catch (IOException e)
8868
- {
8869
- throw new RuntimeException(e);
8870
- }
9294
+
9295
+ LoadSkybox(name, ext, mipmap);
88719296 }
88729297
88739298 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -8899,8 +9324,12 @@
88999324 static double[] model = new double[16];
89009325 double[] camera2light = new double[16];
89019326 double[] light2camera = new double[16];
8902
- int newenvy = -1;
8903
- boolean envyoff = true; // false;
9327
+
9328
+ //int newenvy = -1;
9329
+ //boolean envyoff = false;
9330
+
9331
+ String loadedskyboxname;
9332
+
89049333 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
89059334 //float[] light0 = { 0,0,0 };
89069335 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9193,11 +9622,35 @@
91939622 jy8[3] = 0.5f;
91949623 }
91959624
9196
- 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
91979626 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
91989627 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
91999628 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
92009629
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
+
92019654 static int imagecount = 0; // movie generation
92029655
92039656 static int jitter = 0;
....@@ -9293,8 +9746,8 @@
92939746 assert (parentcam != renderCamera);
92949747
92959748 if (renderCamera != lightCamera)
9296
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9297
- LA.matConcat(matrix, parentcam.toParent, matrix);
9749
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9750
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
92989751
92999752 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
93009753
....@@ -9309,8 +9762,8 @@
93099762 LA.matCopy(renderCamera.fromScreen, matrix);
93109763
93119764 if (renderCamera != lightCamera)
9312
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9313
- LA.matConcat(parentcam.fromParent, matrix, matrix);
9765
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9766
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
93149767
93159768 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
93169769
....@@ -9356,10 +9809,12 @@
93569809 rati = 1 / rati;
93579810 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
93589811 }
9359
- assert (newenvy == -1);
9812
+
9813
+ //assert (newenvy == -1);
9814
+
93609815 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
93619816 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9362
- DrawSkyBox(gl);
9817
+ DrawSkyBox(gl, (float)rati);
93639818 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
93649819 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
93659820 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -9382,7 +9837,7 @@
93829837 //gl.glFlush();
93839838 gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE);
93849839
9385
- if (ANIMATION && ABORTED)
9840
+ if (Globals.ANIMATION && ABORTED)
93869841 {
93879842 System.err.println(" ABORTED FRAME");
93889843 break;
....@@ -9412,7 +9867,7 @@
94129867 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
94139868
94149869 // save image
9415
- if (ANIMATION && !ABORTED)
9870
+ if (Globals.ANIMATION && !ABORTED)
94169871 {
94179872 VPwidth = viewport[2];
94189873 VPheight = viewport[3];
....@@ -9523,11 +9978,11 @@
95239978
95249979 // imagecount++;
95259980
9526
- 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;
95279982
95289983 if (!BOXMODE)
95299984 {
9530
- 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) + ")");
95319986 }
95329987
95339988 if (!BOXMODE)
....@@ -9565,7 +10020,7 @@
956510020 ABORTED = false;
956610021 }
956710022 else
9568
- GrafreeD.wav.cursor += 735 * ACSIZE;
10023
+ Grafreed.wav.cursor += 735 * ACSIZE;
956910024
957010025 if (false)
957110026 {
....@@ -10228,11 +10683,11 @@
1022810683
1022910684 public void display(GLAutoDrawable drawable)
1023010685 {
10231
- if (GrafreeD.savesound && GrafreeD.hassound)
10686
+ if (Grafreed.savesound && Grafreed.hassound)
1023210687 {
10233
- GrafreeD.wav.save();
10234
- GrafreeD.savesound = false;
10235
- GrafreeD.hassound = false;
10688
+ Grafreed.wav.save();
10689
+ Grafreed.savesound = false;
10690
+ Grafreed.hassound = false;
1023610691 }
1023710692 // if (DEBUG_SELECTION)
1023810693 // {
....@@ -10308,6 +10763,7 @@
1030810763 ANTIALIAS = 0;
1030910764 //System.out.println("RESTART");
1031010765 AAtimer.restart();
10766
+ Globals.TIMERRUNNING = true;
1031110767 }
1031210768 }
1031310769 }
....@@ -10362,7 +10818,7 @@
1036210818 Object3D theobject = object;
1036310819 Object3D theparent = object.parent;
1036410820 object.parent = null;
10365
- object = (Object3D)GrafreeD.clone(object);
10821
+ object = (Object3D)Grafreed.clone(object);
1036610822 object.Stripify();
1036710823 if (theobject.selection == null || theobject.selection.Size() == 0)
1036810824 theobject.PreprocessOcclusion(this);
....@@ -10375,13 +10831,14 @@
1037510831 ambientOcclusion = false;
1037610832 }
1037710833
10378
- if (Globals.lighttouched && DrawMode() == DEFAULT && !lightMode) // && !FROZEN)
10834
+ if (//Globals.lighttouched &&
10835
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1037910836 {
1038010837 //if (RENDERSHADOW) // ?
1038110838 if (!IsFrozen())
1038210839 {
1038310840 // dec 2012
10384
- if (!ambientOcclusion && !(!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0))
10841
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
1038510842 {
1038610843 Globals.framecount++;
1038710844 shadowbuffer.display();
....@@ -10394,7 +10851,7 @@
1039410851
1039510852 if (wait)
1039610853 {
10397
- Sleep(500);
10854
+ Sleep(200); // blocks everything
1039810855
1039910856 wait = false;
1040010857 }
....@@ -10508,8 +10965,8 @@
1050810965
1050910966 // if (parentcam != renderCamera) // not a light
1051010967 if (cam != lightCamera)
10511
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10512
- LA.matConcat(matrix, parentcam.toParent, matrix);
10968
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10969
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1051310970
1051410971 for (int j = 0; j < 4; j++)
1051510972 {
....@@ -10523,8 +10980,8 @@
1052310980
1052410981 // if (parentcam != renderCamera) // not a light
1052510982 if (cam != lightCamera)
10526
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10527
- LA.matConcat(parentcam.fromParent, matrix, matrix);
10983
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10984
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1052810985
1052910986 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1053010987
....@@ -10610,13 +11067,27 @@
1061011067 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1061111068 }
1061211069
10613
- if (newenvy > -1)
11070
+// if (newenvy > -1)
11071
+// {
11072
+// LoadEnvy(newenvy);
11073
+// }
11074
+//
11075
+// newenvy = -1;
11076
+
11077
+ if (object.skyboxname != null)
1061411078 {
10615
- LoadEnvy(newenvy);
11079
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11080
+ {
11081
+ LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11082
+ loadedskyboxname = object.skyboxname;
11083
+ }
1061611084 }
10617
-
10618
- newenvy = -1;
10619
-
11085
+ else
11086
+ {
11087
+ cubemap = null;
11088
+ loadedskyboxname = null;
11089
+ }
11090
+
1062011091 ratio = ((double) getWidth()) / getHeight();
1062111092 //System.out.println("ratio = " + ratio);
1062211093
....@@ -10632,7 +11103,7 @@
1063211103
1063311104 if (!IsFrozen() && !ambientOcclusion)
1063411105 {
10635
- DrawSkyBox(gl);
11106
+ DrawSkyBox(gl, (float)ratio);
1063611107 }
1063711108
1063811109 //if (selection_view == -1)
....@@ -10783,7 +11254,16 @@
1078311254 // Bump noise
1078411255 gl.glActiveTexture(GL.GL_TEXTURE6);
1078511256 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
10786
- 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
+
1078711267
1078811268 gl.glActiveTexture(GL.GL_TEXTURE0);
1078911269 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -10806,9 +11286,9 @@
1080611286
1080711287 gl.glMatrixMode(GL.GL_MODELVIEW);
1080811288
10809
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10810
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10811
-//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);
1081211292 } else
1081311293 {
1081411294 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -10819,7 +11299,7 @@
1081911299 //System.out.println("BLENDING ON");
1082011300 gl.glEnable(GL.GL_BLEND);
1082111301 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
10822
-
11302
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1082311303 gl.glMatrixMode(gl.GL_PROJECTION);
1082411304 gl.glLoadIdentity();
1082511305
....@@ -10908,8 +11388,8 @@
1090811388 System.err.println("parentcam != renderCamera");
1090911389
1091011390 // if (cam != lightCamera)
10911
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10912
- 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
1091311393 }
1091411394
1091511395 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -10930,8 +11410,8 @@
1093011410 if (true) // TODO
1093111411 {
1093211412 if (cam != lightCamera)
10933
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10934
- 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
1093511415 }
1093611416
1093711417 LA.xformPos(light0, cam.toScreen, light0);
....@@ -11068,7 +11548,7 @@
1106811548 }
1106911549 }
1107011550
11071
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11551
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1107211552 {
1107311553 //gl.glDepthFunc(GL.GL_LEQUAL);
1107411554 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11076,24 +11556,21 @@
1107611556
1107711557 boolean texon = textureon;
1107811558
11079
- if (RENDERPROGRAM > 0)
11080
- {
11081
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11082
- textureon = false;
11083
- }
11559
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11560
+ textureon = false;
11561
+
1108411562 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1108511563 //System.out.println("ALLO");
1108611564 gl.glColorMask(false, false, false, false);
1108711565 DrawObject(gl);
11088
- if (RENDERPROGRAM > 0)
11089
- {
11090
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11091
- textureon = texon;
11092
- }
11566
+
11567
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11568
+ textureon = texon;
11569
+
1109311570 gl.glColorMask(true, true, true, true);
1109411571
1109511572 gl.glDepthFunc(GL.GL_EQUAL);
11096
- //gl.glDepthMask(false);
11573
+ gl.glDepthMask(false);
1109711574 }
1109811575
1109911576 if (false) // DrawMode() == SHADOW)
....@@ -11247,8 +11724,14 @@
1124711724 {
1124811725 renderpass++;
1124911726 // System.out.println("Draw object... ");
11727
+ STEP = 1;
1125011728 if (FAST) // in case there is no script
11251
- STEP = 16;
11729
+ STEP = 8;
11730
+
11731
+ if (CURRENTANTIALIAS == 0 || ACSIZE == 1)
11732
+ {
11733
+ STEP *= 4;
11734
+ }
1125211735
1125311736 //object.FullInvariants();
1125411737
....@@ -11262,23 +11745,44 @@
1126211745 e.printStackTrace();
1126311746 }
1126411747
11265
- if (GrafreeD.RENDERME > 0)
11266
- GrafreeD.RENDERME--; // mechante magouille
11748
+ if (Grafreed.RENDERME > 0)
11749
+ Grafreed.RENDERME--; // mechante magouille
1126711750
1126811751 Globals.ONESTEP = false;
1126911752 }
1127011753
1127111754 static boolean zoomonce = false;
1127211755
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
+
1127311774 void DrawObject(GL gl, boolean draw)
1127411775 {
11776
+ // To clear camera values
11777
+ ResetOptions();
11778
+
1127511779 //System.out.println("DRAW OBJECT " + mouseDown);
1127611780 // DrawMode() = SELECTION;
1127711781 //GL gl = getGL();
1127811782 if ((TRACK || SHADOWTRACK) || zoomonce)
1127911783 {
1128011784 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11281
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11785
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1128211786 pingthread.StepToTarget(true); // true);
1128311787 // zoomonce = false;
1128411788 }
....@@ -11333,7 +11837,14 @@
1133311837
1133411838 usedtextures.clear();
1133511839
11336
- 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
+ }
1133711848 }
1133811849 //System.out.println("--> " + stackdepth);
1133911850 // GrafreeD.traceon();
....@@ -11343,8 +11854,9 @@
1134311854
1134411855 if (DrawMode() == DEFAULT)
1134511856 {
11346
- if (DEBUG)
11857
+ if (Globals.DEBUG)
1134711858 {
11859
+ CreateSelectedPoint();
1134811860 float radius = 0.05f;
1134911861 if (selectedpoint.radius != radius)
1135011862 {
....@@ -11398,20 +11910,32 @@
1139811910 ReleaseTextures(DEFAULT_TEXTURES);
1139911911
1140011912 if (CLEANCACHE)
11401
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11913
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1140211914 {
11403
- String tex = e.nextElement();
11915
+ cTexture tex = e.nextElement();
1140411916
1140511917 // System.out.println("Texture --------- " + tex);
1140611918
11407
- if (tex.equals("WHITE_NOISE"))
11919
+ if (tex.equals("WHITE_NOISE:"))
1140811920 continue;
1140911921
11410
- if (!usedtextures.containsKey(tex))
11922
+ if (!usedtextures.contains(tex))
1141111923 {
11924
+ CacheTexture gettex = texturepigment.get(tex);
1141211925 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11413
- textures.get(tex).texture.dispose();
11414
- 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
+ }
1141511939 }
1141611940 }
1141711941 }
....@@ -11424,7 +11948,14 @@
1142411948 if (checker != null && DrawMode() == DEFAULT)
1142511949 {
1142611950 //BindTexture(IMMORTAL_TEXTURE);
11427
- 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
+ }
1142811959 // NEAREST
1142911960 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
1143011961 DrawChecker(gl);
....@@ -11506,7 +12037,7 @@
1150612037 return;
1150712038 }
1150812039
11509
- String string = obj.GetToolTip();
12040
+ String string = obj.toString(); //.GetToolTip();
1151012041
1151112042 GL gl = GetGL();
1151212043
....@@ -11823,8 +12354,8 @@
1182312354 //obj.TransformToWorld(light, light);
1182412355 for (int i = tp.size(); --i >= 0;)
1182512356 {
11826
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
11827
- 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);
1182812359 }
1182912360
1183012361
....@@ -11841,8 +12372,8 @@
1184112372 parentcam = cameras[0];
1184212373 }
1184312374
11844
- for (int count = parentcam.GetTransformCount(); --count>=0;)
11845
- 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
1184612377
1184712378 LA.xformPos(light, renderCamera.toScreen, light);
1184812379
....@@ -11932,8 +12463,76 @@
1193212463
1193312464 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1193412465
11935
- String program =
12466
+ String programmin =
12467
+ // Min shader
1193612468 "!!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
+
1193712536 //"OPTION ARB_fragment_program_shadow;" +
1193812537 "PARAM light2cam0 = program.env[10];" +
1193912538 "PARAM light2cam1 = program.env[11];" +
....@@ -12048,8 +12647,7 @@
1204812647 "TEMP shininess;" +
1204912648 "\n" +
1205012649 "MOV texSamp, one;" +
12051
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12052
-
12650
+
1205312651 "MOV mapgrid.x, one2048th.x;" +
1205412652 "MOV temp, fragment.texcoord[1];" +
1205512653 /*
....@@ -12070,20 +12668,20 @@
1207012668 "MUL temp, floor, mapgrid.x;" +
1207112669 //"TEX depth0, temp, texture[1], 2D;" +
1207212670 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12073
- TextureFetch("depth0", "temp", "1") +
12671
+ ShadowTextureFetch("depth0", "temp", "1") +
1207412672 "") +
1207512673 "ADD temp.x, temp.x, mapgrid.x;" +
1207612674 //"TEX depth1, temp, texture[1], 2D;" +
1207712675 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12078
- TextureFetch("depth1", "temp", "1") +
12676
+ ShadowTextureFetch("depth1", "temp", "1") +
1207912677 "") +
1208012678 "ADD temp.y, temp.y, mapgrid.x;" +
1208112679 //"TEX depth2, temp, texture[1], 2D;" +
12082
- TextureFetch("depth2", "temp", "1") +
12680
+ ShadowTextureFetch("depth2", "temp", "1") +
1208312681 "SUB temp.x, temp.x, mapgrid.x;" +
1208412682 //"TEX depth3, temp, texture[1], 2D;" +
1208512683 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12086
- TextureFetch("depth3", "temp", "1") +
12684
+ ShadowTextureFetch("depth3", "temp", "1") +
1208712685 "") +
1208812686 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1208912687 //"MOV params, material;" +
....@@ -12454,10 +13052,10 @@
1245413052 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1245513053 "") +
1245613054
12457
- // display shadow only (bump == 0)
13055
+ // display shadow only (fakedepth == 0)
1245813056 "SUB temp.x, half.x, shadow.x;" +
12459
- "MOV temp.y, -params6.x;" +
12460
- "SLT temp.z, temp.y, zero.x;" +
13057
+ "MOV temp.y, -params5.z;" + // params6.x;" +
13058
+ "SLT temp.z, temp.y, -c256i.x;" +
1246113059 "SUB temp.y, one.x, temp.z;" +
1246213060 "MUL temp.x, temp.x, temp.y;" +
1246313061 "KIL temp.x;" +
....@@ -12586,8 +13184,10 @@
1258613184 "MAX ndotl.x, ndotl.x, -ndotl.x;" +
1258713185
1258813186 "SUB temp.x, one.x, ndotl.x;" +
12589
- "ADD temp.x, temp.x, options2.z;" + // lightsheen
12590
- "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
1259113191 "MUL temp.x, temp.x, temp.y;" +
1259213192
1259313193 "MUL saturation, saturation, temp.xxxx;" +
....@@ -12786,7 +13386,14 @@
1278613386 //once = true;
1278713387 }
1278813388
12789
- 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());
1279013397 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1279113398 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1279213399
....@@ -12879,25 +13486,26 @@
1287913486 return out;
1288013487 }
1288113488
12882
- String TextureFetch(String dest, String src, String unit)
13489
+ // Also does frustum culling
13490
+ String ShadowTextureFetch(String dest, String src, String unit)
1288313491 {
1288413492 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1288513493 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1288613494 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13495
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13496
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1288713497 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12888
- "SLT " + src + ".z, " + src + ".x, one.x;" +
12889
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12890
- "SLT " + src + ".z, " + src + ".y, one.x;" +
12891
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13498
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13499
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1289213500 //"SWZ buffer, temp, w,w,w,w;";
12893
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13501
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1289413502 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1289513503 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1289613504 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
12897
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13505
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1289813506
12899
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
12900
- //"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;";
1290113509 }
1290213510
1290313511 String Shadow(String depth, String shadow)
....@@ -12919,12 +13527,16 @@
1291913527
1292013528 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1292113529 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13530
+
13531
+ // Compare fragment depth in light space with shadowmap.
1292213532 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1292313533 "SGE temp.y, temp.x, zero.x;" +
12924
- "SUB " + shadow + ".y, one.x, temp.y;" +
13534
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13535
+
13536
+ // Reverse comparison
1292513537 "SUB temp.x, one.x, temp.x;" +
1292613538 "MUL " + shadow + ".x, temp.x, temp.y;" +
12927
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13539
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1292813540 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1292913541
1293013542 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -12938,6 +13550,10 @@
1293813550 // No shadow for backface
1293913551 "DP3 temp.x, normal, lightd;" +
1294013552 "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;" +
1294113557 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1294213558 "";
1294313559 }
....@@ -13084,7 +13700,8 @@
1308413700 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1308513701 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1308613702 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13087
- Object3D.cVector2[] vector2buffer;
13703
+
13704
+ //Object3D.cVector2[] vector2buffer;
1308813705
1308913706 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1309013707 // OUT : diff, spec
....@@ -13100,9 +13717,10 @@
1310013717 "DP3 " + dest + ".z," + "normals," + "eye;" +
1310113718 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1310213719 //"MOV " + dest + ".w," + "normal.z;" +
13103
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
13104
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13105
- //"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
1310613724 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1310713725 "RCP " + dest + ".w," + dest + ".w;" +
1310813726 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13496,7 +14114,7 @@
1349614114 public void mousePressed(MouseEvent e)
1349714115 {
1349814116 //System.out.println("mousePressed: " + e);
13499
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14117
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1350014118 }
1350114119
1350214120 static long prevtime = 0;
....@@ -13523,6 +14141,7 @@
1352314141
1352414142 //System.err.println("Dtime = " + Dtime + "; units = " + e.getUnitsToScroll() + "; ratio (units/ms) = " + ratio);
1352514143
14144
+ if (BUTTONLESSWHEEL)
1352614145 if (Math.abs(ratio) < 0.1 || Math.abs(Dtime) == 0) // < 30)
1352714146 {
1352814147 return;
....@@ -13531,7 +14150,7 @@
1353114150 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
1353214151
1353314152 // TIMER
13534
- if (!wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
14153
+ if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
1353514154 {
1353614155 keepboxmode = BOXMODE;
1353714156 keepsupport = SUPPORT;
....@@ -13571,8 +14190,8 @@
1357114190 // mode |= META;
1357214191 //}
1357314192
13574
- SetMouseMode(WHEEL | e.getModifiersEx());
13575
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14193
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14194
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1357614195 anchorX = ax;
1357714196 anchorY = ay;
1357814197 prevX = px;
....@@ -13606,6 +14225,7 @@
1360614225 else
1360714226 if (evt.getSource() == AAtimer)
1360814227 {
14228
+ Globals.TIMERRUNNING = false;
1360914229 if (mouseDown)
1361014230 {
1361114231 //new Exception().printStackTrace();
....@@ -13631,6 +14251,10 @@
1363114251 // LIVE = waslive;
1363214252 // wasliveok = true;
1363314253 // waslive = false;
14254
+
14255
+ // May 2019 Forget it:
14256
+ if (true)
14257
+ return;
1363414258
1363514259 // source == timer
1363614260 if (mouseDown)
....@@ -13661,7 +14285,7 @@
1366114285
1366214286 // fev 2014???
1366314287 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13664
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14288
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1366514289 pingthread.StepToTarget(true); // true);
1366614290 }
1366714291 // if (!LIVE)
....@@ -13670,12 +14294,13 @@
1367014294
1367114295 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1367214296
13673
- void clickStart(int x, int y, int modifiers)
14297
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1367414298 {
1367514299 if (!wasliveok)
1367614300 return;
1367714301
1367814302 AAtimer.restart(); //
14303
+ Globals.TIMERRUNNING = true;
1367914304
1368014305 // waslive = LIVE;
1368114306 // LIVE = false;
....@@ -13687,7 +14312,7 @@
1368714312 // touched = true; // main DL
1368814313 if (isRenderer)
1368914314 {
13690
- SetMouseMode(modifiers);
14315
+ SetMouseMode(modifiers, modifiersex);
1369114316 }
1369214317
1369314318 selectX = anchorX = x;
....@@ -13700,7 +14325,7 @@
1370014325 clicked = true;
1370114326 hold = false;
1370214327
13703
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14328
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1370414329 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1370514330 {
1370614331 // System.out.println("RESTART II " + modifiers);
....@@ -13725,14 +14350,15 @@
1372514350 drag = false;
1372614351 //System.out.println("Mouse DOWN");
1372714352 editObj = false;
13728
- ClickInfo info = new ClickInfo();
13729
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
13730
- info.pane = this;
13731
- info.camera = renderCamera;
13732
- info.x = x;
13733
- info.y = y;
13734
- info.modifiers = modifiers;
13735
- 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);
1373614362 if (!editObj)
1373714363 {
1373814364 hasMarquee = true;
....@@ -13748,11 +14374,14 @@
1374814374
1374914375 public void mouseDragged(MouseEvent e)
1375014376 {
14377
+ Globals.MOUSEDRAGGED = true;
14378
+
14379
+ //System.out.println("mouseDragged: " + e);
1375114380 if (isRenderer)
1375214381 movingcamera = true;
14382
+
1375314383 //if (drawing)
1375414384 //return;
13755
- //System.out.println("mouseDragged: " + e);
1375614385 if ((e.getModifiersEx() & CTRL) != 0
1375714386 || (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen())
1375814387 {
....@@ -13760,7 +14389,7 @@
1376014389 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1376114390 }
1376214391 else
13763
- drag(e.getX(), e.getY(), e.getModifiersEx());
14392
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1376414393
1376514394 //try { Thread.sleep(1); } catch (Exception ex) {}
1376614395 }
....@@ -13933,6 +14562,7 @@
1393314562
1393414563 public void run()
1393514564 {
14565
+ new Exception().printStackTrace();
1393614566 System.exit(0);
1393714567 for (;;)
1393814568 {
....@@ -13996,7 +14626,7 @@
1399614626 {
1399714627 Globals.lighttouched = true;
1399814628 }
13999
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14629
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1400014630 }
1400114631 //else
1400214632 }
....@@ -14010,12 +14640,12 @@
1401014640 void GoDown(int mod)
1401114641 {
1401214642 MODIFIERS |= COMMAND;
14013
- /*
14643
+ /**/
1401414644 if((mod&SHIFT) == SHIFT)
14015
- manipCamera.RotatePosition(0, -speed);
14645
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
1401614646 else
14017
- manipCamera.BackForth(0, -speed*delta, getWidth());
14018
- */
14647
+ manipCamera.RotatePosition(0, -speed);
14648
+ /**/
1401914649 if ((mod & SHIFT) == SHIFT)
1402014650 {
1402114651 mouseMode = mouseMode; // VR??
....@@ -14031,12 +14661,12 @@
1403114661 void GoUp(int mod)
1403214662 {
1403314663 MODIFIERS |= COMMAND;
14034
- /*
14664
+ /**/
1403514665 if((mod&SHIFT) == SHIFT)
14036
- manipCamera.RotatePosition(0, speed);
14666
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
1403714667 else
14038
- manipCamera.BackForth(0, speed*delta, getWidth());
14039
- */
14668
+ manipCamera.RotatePosition(0, speed);
14669
+ /**/
1404014670 if ((mod & SHIFT) == SHIFT)
1404114671 {
1404214672 mouseMode = mouseMode;
....@@ -14052,12 +14682,12 @@
1405214682 void GoLeft(int mod)
1405314683 {
1405414684 MODIFIERS |= COMMAND;
14055
- /*
14685
+ /**/
1405614686 if((mod&SHIFT) == SHIFT)
14057
- manipCamera.RotatePosition(speed, 0);
14058
- else
1405914687 manipCamera.Translate(speed*delta, 0, getWidth());
14060
- */
14688
+ else
14689
+ manipCamera.RotatePosition(speed, 0);
14690
+ /**/
1406114691 if ((mod & SHIFT) == SHIFT)
1406214692 {
1406314693 mouseMode = mouseMode;
....@@ -14073,12 +14703,12 @@
1407314703 void GoRight(int mod)
1407414704 {
1407514705 MODIFIERS |= COMMAND;
14076
- /*
14706
+ /**/
1407714707 if((mod&SHIFT) == SHIFT)
14078
- manipCamera.RotatePosition(-speed, 0);
14079
- else
1408014708 manipCamera.Translate(-speed*delta, 0, getWidth());
14081
- */
14709
+ else
14710
+ manipCamera.RotatePosition(-speed, 0);
14711
+ /**/
1408214712 if ((mod & SHIFT) == SHIFT)
1408314713 {
1408414714 mouseMode = mouseMode;
....@@ -14096,7 +14726,7 @@
1409614726 int X, Y;
1409714727 boolean SX, SY;
1409814728
14099
- void drag(int x, int y, int modifiers)
14729
+ void drag(int x, int y, int modifiers, int modifiersex)
1410014730 {
1410114731 if (IsFrozen())
1410214732 {
....@@ -14105,17 +14735,17 @@
1410514735
1410614736 drag = true; // NEW
1410714737
14108
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14738
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1410914739
1411014740 X = x;
1411114741 Y = y;
1411214742 // floating state for animation
14113
- MODIFIERS = modifiers;
14114
- modifiers &= ~1024;
14743
+ MODIFIERS = modifiersex;
14744
+ modifiersex &= ~1024;
1411514745 if (false) // modifiers != 0)
1411614746 {
1411714747 //new Exception().printStackTrace();
14118
- System.out.println("mouseDragged: " + modifiers);
14748
+ System.out.println("mouseDragged: " + modifiersex);
1411914749 System.out.println("SHIFT = " + SHIFT);
1412014750 System.out.println("CONTROL = " + COMMAND);
1412114751 System.out.println("META = " + META);
....@@ -14128,14 +14758,16 @@
1412814758 if (editObj)
1412914759 {
1413014760 drag = true;
14131
- ClickInfo info = new ClickInfo();
14132
- info.bounds.setBounds(0, 0,
14761
+ //ClickInfo info = new ClickInfo();
14762
+ object.clickInfo.bounds.setBounds(0, 0,
1413314763 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14134
- info.pane = this;
14135
- info.camera = renderCamera;
14136
- info.x = x;
14137
- info.y = y;
14138
- 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);
1413914771 } else
1414014772 {
1414114773 if (x < startX)
....@@ -14284,23 +14916,27 @@
1428414916 }
1428514917 }
1428614918
14919
+// ClickInfo clickInfo = new ClickInfo();
14920
+
1428714921 public void mouseMoved(MouseEvent e)
1428814922 {
1428914923 //System.out.println("mouseMoved: " + e);
14290
-
1429114924 if (isRenderer)
1429214925 return;
1429314926
14294
- ClickInfo ci = new ClickInfo();
14295
- ci.x = e.getX();
14296
- ci.y = e.getY();
14297
- ci.modifiers = e.getModifiersEx();
14298
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14299
- ci.pane = this;
14300
- 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;
1430114934 if (!isRenderer)
1430214935 {
14303
- if (object.editWindow.copy.doEditClick(ci, 0))
14936
+ //ObjEditor editWindow = object.editWindow;
14937
+ //Object3D copy = editWindow.copy;
14938
+ if (object.doEditClick(//clickInfo,
14939
+ 0))
1430414940 {
1430514941 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1430614942 } else
....@@ -14312,7 +14948,11 @@
1431214948
1431314949 public void mouseReleased(MouseEvent e)
1431414950 {
14951
+ Globals.MOUSEDRAGGED = false;
14952
+
1431514953 movingcamera = false;
14954
+ X = 0; // getBounds().width/2;
14955
+ Y = 0; // getBounds().height/2;
1431614956 //System.out.println("mouseReleased: " + e);
1431714957 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1431814958 }
....@@ -14335,9 +14975,9 @@
1433514975 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1433614976 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1433714977
14338
- if (control || command || IsFrozen())
14978
+// No delay if (control || command || IsFrozen())
1433914979 timeout = true;
14340
- else
14980
+// ?? May 2019 else
1434114981 // timer.setDelay((modifiers & 128) != 0?0:350);
1434214982 mouseDown = false;
1434314983 if (!control && !command) // june 2013
....@@ -14447,7 +15087,7 @@
1444715087 System.out.println("keyReleased: " + e);
1444815088 }
1444915089
14450
- void SetMouseMode(int modifiers)
15090
+ void SetMouseMode(int modifiers, int modifiersex)
1445115091 {
1445215092 //System.out.println("SetMouseMode = " + modifiers);
1445315093 //modifiers &= ~1024;
....@@ -14459,25 +15099,25 @@
1445915099 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1446015100 // return;
1446115101 //System.out.println("SetMode = " + modifiers);
14462
- if ((modifiers & WHEEL) == WHEEL)
15102
+ if ((modifiersex & WHEEL) == WHEEL)
1446315103 {
1446415104 mouseMode |= ZOOM;
1446515105 }
1446615106
1446715107 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
14468
- if (capsLocked || (modifiers & META) == META)
15108
+ if (capsLocked) // || (modifiers & META) == META)
1446915109 {
1447015110 mouseMode |= VR; // BACKFORTH;
1447115111 }
14472
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
15112
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1447315113 {
1447415114 mouseMode |= SELECT;
1447515115 }
14476
- if ((modifiers & COMMAND) == COMMAND)
15116
+ if ((modifiersex & COMMAND) == COMMAND)
1447715117 {
1447815118 mouseMode |= SELECT;
1447915119 }
14480
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15120
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
1448115121 {
1448215122 mouseMode &= ~VR;
1448315123 mouseMode |= TRANSLATE;
....@@ -14506,7 +15146,7 @@
1450615146
1450715147 if (isRenderer) //
1450815148 {
14509
- SetMouseMode(modifiers);
15149
+ SetMouseMode(0, modifiers);
1451015150 }
1451115151
1451215152 Globals.theRenderer.keyPressed(key);
....@@ -14568,7 +15208,8 @@
1456815208 // break;
1456915209 case 'T':
1457015210 CACHETEXTURE ^= true;
14571
- textures.clear();
15211
+ texturepigment.clear();
15212
+ texturebump.clear();
1457215213 // repaint();
1457315214 break;
1457415215 case 'Y':
....@@ -14653,7 +15294,9 @@
1465315294 case 'E' : COMPACT ^= true;
1465415295 repaint();
1465515296 break;
14656
- case 'W' : DEBUGHSB ^= true;
15297
+ case 'W' : // Wide Window (fullscreen)
15298
+ //DEBUGHSB ^= true;
15299
+ ObjEditor.theFrame.ToggleFullScreen();
1465715300 repaint();
1465815301 break;
1465915302 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14678,8 +15321,8 @@
1467815321 RevertCamera();
1467915322 repaint();
1468015323 break;
14681
- case 'L':
1468215324 case 'l':
15325
+ //case 'L':
1468315326 if (lightMode)
1468415327 {
1468515328 lightMode = false;
....@@ -14743,20 +15386,24 @@
1474315386 OCCLUSION_CULLING ^= true;
1474415387 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1474515388 break;
14746
- case '0': envyoff ^= true; repaint(); break;
15389
+ //case '0': envyoff ^= true; repaint(); break;
1474715390 case '1':
1474815391 case '2':
1474915392 case '3':
1475015393 case '4':
1475115394 case '5':
14752
- newenvy = Character.getNumericValue(key);
14753
- repaint();
14754
- break;
1475515395 case '6':
1475615396 case '7':
1475715397 case '8':
1475815398 case '9':
14759
- 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
+ }
1476015407 repaint();
1476115408 break;
1476215409 case '!':
....@@ -14822,9 +15469,9 @@
1482215469 case '_':
1482315470 kompactbit = 5;
1482415471 break;
14825
- case '+':
14826
- kompactbit = 6;
14827
- break;
15472
+// case '+':
15473
+// kompactbit = 6;
15474
+// break;
1482815475 case ' ':
1482915476 lightMode ^= true;
1483015477 Globals.lighttouched = true;
....@@ -14836,13 +15483,14 @@
1483615483 case ESC:
1483715484 RENDERPROGRAM += 1;
1483815485 RENDERPROGRAM %= 3;
15486
+
1483915487 repaint();
1484015488 break;
1484115489 case 'Z':
1484215490 //RESIZETEXTURE ^= true;
1484315491 //break;
1484415492 case 'z':
14845
- RENDERSHADOW ^= true;
15493
+ Globals.RENDERSHADOW ^= true;
1484615494 Globals.lighttouched = true;
1484715495 repaint();
1484815496 break;
....@@ -14875,8 +15523,9 @@
1487515523 case DELETE:
1487615524 ClearSelection();
1487715525 break;
14878
- /*
1487915526 case '+':
15527
+
15528
+ /*
1488015529 //fontsize += 1;
1488115530 bbzoom *= 2;
1488215531 repaint();
....@@ -14893,17 +15542,17 @@
1489315542 case '=':
1489415543 IncDepth();
1489515544 //fontsize += 1;
14896
- object.editWindow.refreshContents(true);
15545
+ object.GetWindow().refreshContents(true);
1489715546 maskbit = 6;
1489815547 break;
1489915548 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1490015549 DecDepth();
1490115550 maskbit = 5;
1490215551 //if(fontsize > 1) fontsize -= 1;
14903
- if (object.editWindow == null)
14904
- new Exception().printStackTrace();
14905
- else
14906
- object.editWindow.refreshContents(true);
15552
+// if (object.editWindow == null)
15553
+// new Exception().printStackTrace();
15554
+// else
15555
+ object.GetWindow().refreshContents(true);
1490715556 break;
1490815557 case '{':
1490915558 manipCamera.shaper_fovy /= 1.1;
....@@ -14966,7 +15615,7 @@
1496615615 //mode = ROTATE;
1496715616 if ((MODIFIERS & COMMAND) == 0) // VR??
1496815617 {
14969
- SetMouseMode(modifiers);
15618
+ SetMouseMode(0, modifiers);
1497015619 }
1497115620 }
1497215621
....@@ -15100,8 +15749,9 @@
1510015749
1510115750 protected void processMouseMotionEvent(MouseEvent e)
1510215751 {
15103
- //System.out.println("processMouseMotionEvent: " + mouseMode);
15104
- if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15752
+ //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
15753
+ //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15754
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1510515755 {
1510615756 mouseMoved(e);
1510715757 } else
....@@ -15126,11 +15776,12 @@
1512615776 }
1512715777 */
1512815778
15129
- object.editWindow.EditSelection();
15779
+ object.GetWindow().EditSelection(false);
1513015780 }
1513115781
1513215782 void SelectParent()
1513315783 {
15784
+ new Exception().printStackTrace();
1513415785 System.exit(0);
1513515786 Composite group = (Composite) object;
1513615787 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -15142,10 +15793,10 @@
1514215793 {
1514315794 //selectees.remove(i);
1514415795 System.out.println("select parent of " + elem);
15145
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15796
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1514615797 } else
1514715798 {
15148
- group.editWindow.Select(elem.GetTreePath(), first, true);
15799
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1514915800 }
1515015801
1515115802 first = false;
....@@ -15154,6 +15805,7 @@
1515415805
1515515806 void SelectChildren()
1515615807 {
15808
+ new Exception().printStackTrace();
1515715809 System.exit(0);
1515815810 /*
1515915811 Composite group = (Composite) object;
....@@ -15186,12 +15838,12 @@
1518615838 for (int j = 0; j < group.children.size(); j++)
1518715839 {
1518815840 elem = (Object3D) group.children.elementAt(j);
15189
- object.editWindow.Select(elem.GetTreePath(), first, true);
15841
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1519015842 first = false;
1519115843 }
1519215844 } else
1519315845 {
15194
- object.editWindow.Select(elem.GetTreePath(), first, true);
15846
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1519515847 }
1519615848
1519715849 first = false;
....@@ -15202,21 +15854,21 @@
1520215854 {
1520315855 //Composite group = (Composite) object;
1520415856 Object3D group = object;
15205
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15857
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1520615858 }
1520715859
1520815860 void ResetTransform(int mask)
1520915861 {
1521015862 //Composite group = (Composite) object;
1521115863 Object3D group = object;
15212
- group.editWindow.ResetTransform(mask);
15864
+ group.GetWindow().ResetTransform(mask);
1521315865 }
1521415866
1521515867 void FlipTransform()
1521615868 {
1521715869 //Composite group = (Composite) object;
1521815870 Object3D group = object;
15219
- group.editWindow.FlipTransform();
15871
+ group.GetWindow().FlipTransform();
1522015872 // group.editWindow.ReduceMesh(true);
1522115873 }
1522215874
....@@ -15224,7 +15876,7 @@
1522415876 {
1522515877 //Composite group = (Composite) object;
1522615878 Object3D group = object;
15227
- group.editWindow.PrintMemory();
15879
+ group.GetWindow().PrintMemory();
1522815880 // group.editWindow.ReduceMesh(true);
1522915881 }
1523015882
....@@ -15232,7 +15884,7 @@
1523215884 {
1523315885 //Composite group = (Composite) object;
1523415886 Object3D group = object;
15235
- group.editWindow.ResetCentroid();
15887
+ group.GetWindow().ResetCentroid();
1523615888 }
1523715889
1523815890 void IncDepth()
....@@ -15314,11 +15966,11 @@
1531415966
1531515967 int width = getBounds().width;
1531615968 int height = getBounds().height;
15317
- ClickInfo info = new ClickInfo();
15318
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1531915969 //Image img = CreateImage(width, height);
1532015970 //System.out.println("width = " + width + "; height = " + height + "\n");
15971
+
1532115972 Graphics gr = g; // img.getGraphics();
15973
+
1532215974 if (!hasMarquee)
1532315975 {
1532415976 if (Xmin < Xmax) // !locked)
....@@ -15390,40 +16042,88 @@
1539016042 }
1539116043 if (object != null && !hasMarquee)
1539216044 {
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
+
1539316051 if (isRenderer)
1539416052 {
15395
- info.flags++;
16053
+ object.clickInfo.flags++;
1539616054 double frameAspect = (double) width / (double) height;
1539716055 if (frameAspect > renderCamera.aspect)
1539816056 {
1539916057 int desired = (int) ((double) height * renderCamera.aspect);
15400
- info.bounds.width -= width - desired;
15401
- info.bounds.x += (width - desired) / 2;
16058
+ object.clickInfo.bounds.width -= width - desired;
16059
+ object.clickInfo.bounds.x += (width - desired) / 2;
1540216060 } else
1540316061 {
1540416062 int desired = (int) ((double) width / renderCamera.aspect);
15405
- info.bounds.height -= height - desired;
15406
- info.bounds.y += (height - desired) / 2;
16063
+ object.clickInfo.bounds.height -= height - desired;
16064
+ object.clickInfo.bounds.y += (height - desired) / 2;
1540716065 }
1540816066 }
15409
- info.g = gr;
15410
- info.camera = renderCamera;
16067
+
16068
+ object.clickInfo.g = gr;
16069
+ object.clickInfo.camera = renderCamera;
1541116070 /*
1541216071 // Memory intensive (brep.verticescopy)
1541316072 if (!(object instanceof Composite))
1541416073 object.draw(info, 0, false); // SLOW :
1541516074 */
15416
- if (!isRenderer)
16075
+ if (!isRenderer) // && drag)
1541716076 {
15418
- 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
+ }
1541916117 }
1542016118 }
16119
+
1542116120 if (isRenderer)
1542216121 {
1542316122 //gr.setColor(Color.black);
1542416123 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1542516124 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1542616125 }
16126
+
1542716127 if (hasMarquee)
1542816128 {
1542916129 gr.setXORMode(Color.white);
....@@ -15536,6 +16236,7 @@
1553616236 public boolean mouseDown(Event evt, int x, int y)
1553716237 {
1553816238 System.out.println("mouseDown: " + evt);
16239
+ System.exit(0);
1553916240 /*
1554016241 locked = true;
1554116242 drag = false;
....@@ -15579,7 +16280,7 @@
1557916280 {
1558016281 keyPressed(0, modifiers);
1558116282 }
15582
- clickStart(x, y, modifiers);
16283
+ // clickStart(x, y, modifiers);
1558316284 return true;
1558416285 }
1558516286
....@@ -15697,7 +16398,7 @@
1569716398 {
1569816399 keyReleased(0, 0);
1569916400 }
15700
- drag(x, y, modifiers);
16401
+ drag(x, y, 0, modifiers);
1570116402 return true;
1570216403 }
1570316404
....@@ -15829,7 +16530,7 @@
1582916530 Object3D object;
1583016531 static Object3D trackedobject;
1583116532 Camera renderCamera; // Light or Eye (or Occlusion)
15832
- /*static*/ Camera manipCamera; // Light or Eye
16533
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1583316534 /*static*/ Camera eyeCamera;
1583416535 /*static*/ Camera lightCamera;
1583516536 int cameracount;
....@@ -15893,6 +16594,8 @@
1589316594 private /*static*/ boolean firstime;
1589416595 private /*static*/ cVector newView = new cVector();
1589516596 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"};
1589616599 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1589716600 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1589816601 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -15905,29 +16608,67 @@
1590516608 {
1590616609 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1590716610
16611
+ int usedsuf = 0;
16612
+
1590816613 for (int i = 0; i < suffixes.length; i++)
1590916614 {
15910
- String resourceName = basename + suffixes[i] + "." + suffix;
15911
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
15912
- mipmapped,
15913
- FileUtil.getFileSuffix(resourceName));
15914
- if (data == null)
16615
+ String[] suffixe = suffixes;
16616
+ String[] fallback = suffixes2;
16617
+ String[] fallfallback = suffixes3;
16618
+
16619
+ for (int c=usedsuf; --c>=0;)
1591516620 {
15916
- throw new IOException("Unable to load texture " + resourceName);
16621
+// String[] temp = suffixe;
16622
+// suffixe = fallback;
16623
+// fallback = fallfallback;
16624
+// fallfallback = temp;
1591716625 }
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
+
1591816654 //System.out.println("Target = " + targets[i]);
1591916655 cubemap.updateImage(data, targets[i]);
1592016656 }
1592116657
1592216658 return cubemap;
1592316659 }
16660
+
1592416661 int bigsphere = -1;
1592516662
1592616663 float BGcolor = 0.5f;
1592716664
15928
- private void DrawSkyBox(GL gl)
16665
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16666
+
16667
+ private void DrawSkyBox(GL gl, float ratio)
1592916668 {
15930
- if (envyoff || cubemap == null)
16669
+ if (//envyoff ||
16670
+ WIREFRAME ||
16671
+ cubemap == null)
1593116672 {
1593216673 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1593316674 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -15942,7 +16683,17 @@
1594216683 // Compensates for ExaminerViewer's modification of modelview matrix
1594316684 gl.glMatrixMode(GL.GL_MODELVIEW);
1594416685 gl.glLoadIdentity();
16686
+ gl.glScalef(1,ratio,1);
1594516687
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
+
1594616697 //gl.glActiveTexture(GL.GL_TEXTURE1);
1594716698 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1594816699
....@@ -15974,6 +16725,7 @@
1597416725 {
1597516726 gl.glScalef(1.0f, -1.0f, 1.0f);
1597616727 }
16728
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1597716729 gl.glMultMatrixd(viewrot_1, 0);
1597816730 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1597916731 //viewer.updateInverseRotation(gl);
....@@ -16114,16 +16866,16 @@
1611416866 cStatic.objectstack[materialdepth++] = checker;
1611516867 //System.out.println("material " + material);
1611616868 //Applet3D.tracein(this, selected);
16117
- vector2buffer = checker.projectedVertices;
16869
+ //vector2buffer = checker.projectedVertices;
1611816870
1611916871 //checker.GetMaterial().Draw(this, false); // true);
16120
- DrawMaterial(checker.GetMaterial(), false); // true);
16872
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1612116873
1612216874 materialdepth -= 1;
1612316875 if (materialdepth > 0)
1612416876 {
16125
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16126
- 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);
1612716879 }
1612816880 //checker.GetMaterial().opacity = 1f;
1612916881 ////checker.GetMaterial().ambient = 1f;
....@@ -16209,6 +16961,14 @@
1620916961 }
1621016962 }
1621116963
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
+
1621216972 class SelectBuffer implements GLEventListener
1621316973 {
1621416974
....@@ -16224,7 +16984,7 @@
1622416984 //new Exception().printStackTrace();
1622516985 System.out.println("select buffer init");
1622616986 // Use debug pipeline
16227
- drawable.setGL(new DebugGL(drawable.getGL()));
16987
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1622816988
1622916989 GL gl = drawable.getGL();
1623016990
....@@ -16267,6 +17027,7 @@
1626717027 {
1626817028 if (!selection)
1626917029 {
17030
+ new Exception().printStackTrace();
1627017031 System.exit(0);
1627117032 return;
1627217033 }
....@@ -16287,6 +17048,17 @@
1628717048
1628817049 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1628917050
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
+
1629017062 //int tmp = selection_view;
1629117063 //selection_view = -1;
1629217064 int temp = DrawMode();
....@@ -16298,6 +17070,17 @@
1629817070 // temp = DEFAULT; // patch for selection debug
1629917071 Globals.drawMode = temp; // WARNING
1630017072
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
+
1630117084 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1630217085
1630317086 // trying different ways of getting the depth info over
....@@ -16345,6 +17128,8 @@
1634517128 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1634617129 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1634717130 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
17131
+
17132
+ CreateSelectedPoint();
1634817133
1634917134 // Will fit the mesh !!!
1635017135 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16394,34 +17179,36 @@
1639417179 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]));
1639517180 }
1639617181
16397
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
17182
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1639817183 }
1639917184 }
1640017185
1640117186 if (!movingcamera && !PAINTMODE)
16402
- object.editWindow.ScreenFitPoint(); // fev 2014
17187
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1640317188
16404
- 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)
1640517190 {
16406
- 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);
1640717192
16408
- Object3D group = new Object3D("inst" + paintcount++);
17193
+ if (object.GetWindow().copy.selection.Size() > 0)
17194
+ {
17195
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1640917196
16410
- group.CreateMaterial(); // use a void leaf to select instances
16411
-
16412
- group.add(paintobj); // link
16413
-
16414
- object.editWindow.SnapObject(group);
16415
-
16416
- Object3D folder = object.editWindow.copy;
16417
-
16418
- if (object.editWindow.copy.selection.Size() > 0)
16419
- folder = object.editWindow.copy.selection.elementAt(0);
16420
-
16421
- folder.add(group);
16422
-
16423
- object.editWindow.ResetModel();
16424
- 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
+ }
1642517212 }
1642617213 else
1642717214 paintcount = 0;
....@@ -16460,6 +17247,11 @@
1646017247 //System.out.println("objects[color] = " + objects[color]);
1646117248 //objects[color].Select();
1646217249 indexcount = 0;
17250
+ ObjEditor window = object.GetWindow();
17251
+ if (window != null && deselect)
17252
+ {
17253
+ window.Select(null, deselect, true);
17254
+ }
1646317255 object.Select(color, deselect);
1646417256 }
1646517257
....@@ -16559,7 +17351,7 @@
1655917351 gl.glDisable(gl.GL_CULL_FACE);
1656017352 }
1656117353
16562
- if (!RENDERSHADOW)
17354
+ if (!Globals.RENDERSHADOW)
1656317355 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1656417356
1656517357 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -16569,7 +17361,7 @@
1656917361 //gl.glColorMask(false, false, false, false);
1657017362
1657117363 //render_scene_from_light_view(gl, drawable, 0, 0);
16572
- if (RENDERSHADOW && Globals.lighttouched && !movingcamera) // && !parent.IsFreezed())
17364
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1657317365 {
1657417366 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1657517367
....@@ -16985,23 +17777,15 @@
1698517777 int AAbuffersize = 0;
1698617778
1698717779 //double[] selectedpoint = new double[3];
16988
- static Superellipsoid selectedpoint = new Superellipsoid();
17780
+ static Superellipsoid selectedpoint;
1698917781 static Sphere previousselectedpoint = null;
16990
- static Sphere debugpointG = new Sphere();
16991
- static Sphere debugpointP = new Sphere();
16992
- static Sphere debugpointC = new Sphere();
16993
- static Sphere debugpointR = new Sphere();
17782
+ static Sphere debugpointG;
17783
+ static Sphere debugpointP;
17784
+ static Sphere debugpointC;
17785
+ static Sphere debugpointR;
1699417786
1699517787 static Sphere debugpoints[] = new Sphere[8];
1699617788
16997
- static
16998
- {
16999
- for (int i=0; i<8; i++)
17000
- {
17001
- debugpoints[i] = new Sphere();
17002
- }
17003
- }
17004
-
1700517789 static void InitPoints(float radius)
1700617790 {
1700717791 for (int i=0; i<8; i++)