Normand Briere
2019-08-12 8f1afe25ea8fc8801aab66331c32a50859a758c2
CameraPane.java
....@@ -18,7 +18,10 @@
1818 import javax.imageio.ImageIO;
1919 import javax.imageio.ImageWriteParam;
2020 import javax.imageio.ImageWriter;
21
+import javax.imageio.ImageReadParam;
22
+import javax.imageio.ImageReader;
2123 import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
24
+import javax.imageio.stream.ImageInputStream;
2225 import javax.imageio.stream.ImageOutputStream;
2326 import javax.imageio.ImageWriteParam;
2427
....@@ -30,6 +33,7 @@
3033 import java.nio.*;
3134
3235 import gleem.linalg.Mat4f;
36
+import javax.imageio.ImageTypeSpecifier;
3337
3438 class CameraPane extends GLCanvas implements iCameraPane, Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener
3539 {
....@@ -37,7 +41,6 @@
3741 static boolean[] selectedstack = new boolean[65536];
3842 static int materialdepth = 0;
3943
40
- static boolean DEBUG = false;
4144 static boolean FRUSTUM = false; // still bogus true; // frustum culling
4245
4346 // camera change fix
....@@ -45,6 +48,39 @@
4548 static boolean ABORTED = false;
4649
4750 static int STEP = 1;
51
+
52
+ private static BufferedImage CreateBim(byte[] bytes, int width, int height)
53
+ {
54
+ int[] pixels = new int[bytes.length/3];
55
+ for (int i=pixels.length; --i>=0;)
56
+ {
57
+ int i3 = i*3;
58
+ pixels[i] = 0xFF;
59
+ pixels[i] <<= 8;
60
+ pixels[i] |= bytes[i3+2] & 0xFF;
61
+ pixels[i] <<= 8;
62
+ pixels[i] |= bytes[i3+1] & 0xFF;
63
+ pixels[i] <<= 8;
64
+ pixels[i] |= bytes[i3] & 0xFF;
65
+ }
66
+ /*
67
+ int r=0,g=0,b=0,a=0;
68
+ for (int i=0; i<width; i++)
69
+ for (int j=0; j<height; j++)
70
+ {
71
+ int index = j*width+i;
72
+ int p = pixels[index];
73
+ a = ((p>>24) & 0xFF);
74
+ r = ((p>>16) & 0xFF);
75
+ g = ((p>>8) & 0xFF);
76
+ b = (p & 0xFF);
77
+ pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
78
+ }
79
+ /**/
80
+ BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
81
+ rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
82
+ return rendImage;
83
+ }
4884
4985 /*static*/ private boolean CULLFACE = false; // true;
5086 /*static*/ boolean NEAREST = false; // true;
....@@ -56,14 +92,12 @@
5692 static int CURRENTANTIALIAS = 0; // 1;
5793 /*static*/ boolean RENDERSHADOW = true;
5894 /*static*/ int RENDERPROGRAM = 2; // 0 == none, 1 == fast, 2 == normal
59
- static boolean ANIMATION = false;
60
- static String filename;
6195
6296 boolean DISPLAYTEXT = false;
6397 //boolean REDUCETEXTURE = true;
6498 boolean CACHETEXTURE = true;
6599 boolean CLEANCACHE = false; // true;
66
- boolean MIPMAP = false; // true;
100
+ boolean MIPMAP = false; // true; // never works...
67101 boolean COMPRESSTEXTURE = false;
68102 boolean KOMPACTTEXTURE = false; // true;
69103 boolean RESIZETEXTURE = false;
....@@ -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;
....@@ -8374,10 +8778,12 @@
83748778
83758779 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
83768780 MAXSTACK = temp[0];
8377
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8781
+ if (Globals.DEBUG)
8782
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
83788783 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
83798784 MAXSTACK = temp[0];
8380
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8785
+ if (Globals.DEBUG)
8786
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
83818787
83828788 // Use debug pipeline
83838789 //drawable.setGL(new DebugGL(gl)); //
....@@ -8385,7 +8791,8 @@
83858791 gl = drawable.getGL(); //
83868792
83878793 GL gl3 = getGL();
8388
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8794
+ if (Globals.DEBUG)
8795
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
83898796
83908797
83918798 //float pos[] = { 100, 100, 100, 0 };
....@@ -8550,7 +8957,7 @@
85508957
85518958 if (cubemap == null)
85528959 {
8553
- LoadEnvy(5);
8960
+ //LoadEnvy(1);
85548961 }
85558962
85568963 //cubemap.enable();
....@@ -8837,37 +9244,58 @@
88379244 cubemap = null;
88389245 return;
88399246 case 1:
8840
- name = "cubemaps/box_";
8841
- ext = "png";
9247
+ name = "cubemaps/rgb/";
9248
+ ext = "jpg";
88429249 reverseUP = false;
88439250 break;
88449251 case 2:
8845
- name = "cubemaps/uffizi_";
8846
- ext = "png";
8847
- break; // reverseUP = true; break;
9252
+ name = "cubemaps/uffizi/";
9253
+ ext = "jpg";
9254
+ reverseUP = false;
9255
+ break;
88489256 case 3:
8849
- name = "cubemaps/CloudyHills_";
8850
- ext = "tga";
9257
+ name = "cubemaps/CloudyHills/";
9258
+ ext = "jpg";
88519259 reverseUP = false;
88529260 break;
88539261 case 4:
8854
- name = "cubemaps/cornell_";
9262
+ name = "cubemaps/cornell/";
88559263 ext = "png";
88569264 reverseUP = false;
88579265 break;
9266
+ case 5:
9267
+ name = "cubemaps/skycube/";
9268
+ ext = "jpg";
9269
+ reverseUP = false;
9270
+ break;
9271
+ case 6:
9272
+ name = "cubemaps/SaintLazarusChurch3/";
9273
+ ext = "jpg";
9274
+ reverseUP = false;
9275
+ break;
9276
+ case 7:
9277
+ name = "cubemaps/Sodermalmsallen/";
9278
+ ext = "jpg";
9279
+ reverseUP = false;
9280
+ break;
9281
+ case 8:
9282
+ name = "cubemaps/Sodermalmsallen2/";
9283
+ ext = "jpg";
9284
+ reverseUP = false;
9285
+ break;
9286
+ case 9:
9287
+ name = "cubemaps/UnionSquare/";
9288
+ ext = "jpg";
9289
+ reverseUP = false;
9290
+ break;
88589291 default:
8859
- name = "cubemaps/rgb_";
8860
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9292
+ name = "cubemaps/box/";
9293
+ ext = "png"; /*mipmap = true;*/
9294
+ reverseUP = false;
88619295 break;
88629296 }
8863
-
8864
- try
8865
- {
8866
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
8867
- } catch (IOException e)
8868
- {
8869
- throw new RuntimeException(e);
8870
- }
9297
+
9298
+ LoadSkybox(name, ext, mipmap);
88719299 }
88729300
88739301 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -8899,8 +9327,12 @@
88999327 static double[] model = new double[16];
89009328 double[] camera2light = new double[16];
89019329 double[] light2camera = new double[16];
8902
- int newenvy = -1;
8903
- boolean envyoff = true; // false;
9330
+
9331
+ //int newenvy = -1;
9332
+ //boolean envyoff = false;
9333
+
9334
+ String loadedskyboxname;
9335
+
89049336 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
89059337 //float[] light0 = { 0,0,0 };
89069338 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9193,11 +9625,35 @@
91939625 jy8[3] = 0.5f;
91949626 }
91959627
9196
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9628
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
91979629 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
91989630 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
91999631 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
92009632
9633
+ void ResetOptions()
9634
+ {
9635
+ options1[0] = 100;
9636
+ options1[1] = 0.025f;
9637
+ options1[2] = 0.01f;
9638
+ options1[3] = 0;
9639
+ options1[4] = 0;
9640
+
9641
+ options2[0] = 0;
9642
+ options2[1] = 0.75f;
9643
+ options2[2] = 0;
9644
+ options2[3] = 0;
9645
+
9646
+ options3[0] = 1;
9647
+ options3[1] = 1;
9648
+ options3[2] = 1;
9649
+ options3[3] = 0;
9650
+
9651
+ options4[0] = 1;
9652
+ options4[1] = 0;
9653
+ options4[2] = 1;
9654
+ options4[3] = 0;
9655
+ }
9656
+
92019657 static int imagecount = 0; // movie generation
92029658
92039659 static int jitter = 0;
....@@ -9293,8 +9749,8 @@
92939749 assert (parentcam != renderCamera);
92949750
92959751 if (renderCamera != lightCamera)
9296
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9297
- LA.matConcat(matrix, parentcam.toParent, matrix);
9752
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9753
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
92989754
92999755 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
93009756
....@@ -9309,8 +9765,8 @@
93099765 LA.matCopy(renderCamera.fromScreen, matrix);
93109766
93119767 if (renderCamera != lightCamera)
9312
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9313
- LA.matConcat(parentcam.fromParent, matrix, matrix);
9768
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9769
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
93149770
93159771 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
93169772
....@@ -9356,10 +9812,12 @@
93569812 rati = 1 / rati;
93579813 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
93589814 }
9359
- assert (newenvy == -1);
9815
+
9816
+ //assert (newenvy == -1);
9817
+
93609818 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
93619819 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9362
- DrawSkyBox(gl);
9820
+ DrawSkyBox(gl, (float)rati);
93639821 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
93649822 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
93659823 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -9382,7 +9840,7 @@
93829840 //gl.glFlush();
93839841 gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE);
93849842
9385
- if (ANIMATION && ABORTED)
9843
+ if (Globals.ANIMATION && ABORTED)
93869844 {
93879845 System.err.println(" ABORTED FRAME");
93889846 break;
....@@ -9412,7 +9870,7 @@
94129870 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
94139871
94149872 // save image
9415
- if (ANIMATION && !ABORTED)
9873
+ if (Globals.ANIMATION && !ABORTED)
94169874 {
94179875 VPwidth = viewport[2];
94189876 VPheight = viewport[3];
....@@ -9523,11 +9981,11 @@
95239981
95249982 // imagecount++;
95259983
9526
- String fullname = filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
9984
+ String fullname = Globals.filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
95279985
95289986 if (!BOXMODE)
95299987 {
9530
- System.out.println("image: " + fullname + " (wav cursor=" + (GrafreeD.wav.cursor / 735 / 4) + ")");
9988
+ System.out.println("image: " + fullname + " (wav cursor=" + (Grafreed.wav.cursor / 735 / 4) + ")");
95319989 }
95329990
95339991 if (!BOXMODE)
....@@ -9565,7 +10023,7 @@
956510023 ABORTED = false;
956610024 }
956710025 else
9568
- GrafreeD.wav.cursor += 735 * ACSIZE;
10026
+ Grafreed.wav.cursor += 735 * ACSIZE;
956910027
957010028 if (false)
957110029 {
....@@ -10228,11 +10686,11 @@
1022810686
1022910687 public void display(GLAutoDrawable drawable)
1023010688 {
10231
- if (GrafreeD.savesound && GrafreeD.hassound)
10689
+ if (Grafreed.savesound && Grafreed.hassound)
1023210690 {
10233
- GrafreeD.wav.save();
10234
- GrafreeD.savesound = false;
10235
- GrafreeD.hassound = false;
10691
+ Grafreed.wav.save();
10692
+ Grafreed.savesound = false;
10693
+ Grafreed.hassound = false;
1023610694 }
1023710695 // if (DEBUG_SELECTION)
1023810696 // {
....@@ -10308,6 +10766,7 @@
1030810766 ANTIALIAS = 0;
1030910767 //System.out.println("RESTART");
1031010768 AAtimer.restart();
10769
+ Globals.TIMERRUNNING = true;
1031110770 }
1031210771 }
1031310772 }
....@@ -10362,7 +10821,7 @@
1036210821 Object3D theobject = object;
1036310822 Object3D theparent = object.parent;
1036410823 object.parent = null;
10365
- object = (Object3D)GrafreeD.clone(object);
10824
+ object = (Object3D)Grafreed.clone(object);
1036610825 object.Stripify();
1036710826 if (theobject.selection == null || theobject.selection.Size() == 0)
1036810827 theobject.PreprocessOcclusion(this);
....@@ -10375,13 +10834,14 @@
1037510834 ambientOcclusion = false;
1037610835 }
1037710836
10378
- if (Globals.lighttouched && DrawMode() == DEFAULT && !lightMode) // && !FROZEN)
10837
+ if (//Globals.lighttouched &&
10838
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1037910839 {
1038010840 //if (RENDERSHADOW) // ?
1038110841 if (!IsFrozen())
1038210842 {
1038310843 // dec 2012
10384
- if (!ambientOcclusion && !(!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0))
10844
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
1038510845 {
1038610846 Globals.framecount++;
1038710847 shadowbuffer.display();
....@@ -10394,7 +10854,7 @@
1039410854
1039510855 if (wait)
1039610856 {
10397
- Sleep(500);
10857
+ Sleep(200); // blocks everything
1039810858
1039910859 wait = false;
1040010860 }
....@@ -10508,8 +10968,8 @@
1050810968
1050910969 // if (parentcam != renderCamera) // not a light
1051010970 if (cam != lightCamera)
10511
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10512
- LA.matConcat(matrix, parentcam.toParent, matrix);
10971
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10972
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1051310973
1051410974 for (int j = 0; j < 4; j++)
1051510975 {
....@@ -10523,8 +10983,8 @@
1052310983
1052410984 // if (parentcam != renderCamera) // not a light
1052510985 if (cam != lightCamera)
10526
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10527
- LA.matConcat(parentcam.fromParent, matrix, matrix);
10986
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10987
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1052810988
1052910989 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1053010990
....@@ -10610,13 +11070,27 @@
1061011070 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1061111071 }
1061211072
10613
- if (newenvy > -1)
11073
+// if (newenvy > -1)
11074
+// {
11075
+// LoadEnvy(newenvy);
11076
+// }
11077
+//
11078
+// newenvy = -1;
11079
+
11080
+ if (object.skyboxname != null)
1061411081 {
10615
- LoadEnvy(newenvy);
11082
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11083
+ {
11084
+ LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11085
+ loadedskyboxname = object.skyboxname;
11086
+ }
1061611087 }
10617
-
10618
- newenvy = -1;
10619
-
11088
+ else
11089
+ {
11090
+ cubemap = null;
11091
+ loadedskyboxname = null;
11092
+ }
11093
+
1062011094 ratio = ((double) getWidth()) / getHeight();
1062111095 //System.out.println("ratio = " + ratio);
1062211096
....@@ -10632,7 +11106,7 @@
1063211106
1063311107 if (!IsFrozen() && !ambientOcclusion)
1063411108 {
10635
- DrawSkyBox(gl);
11109
+ DrawSkyBox(gl, (float)ratio);
1063611110 }
1063711111
1063811112 //if (selection_view == -1)
....@@ -10783,7 +11257,16 @@
1078311257 // Bump noise
1078411258 gl.glActiveTexture(GL.GL_TEXTURE6);
1078511259 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
10786
- BindTexture(NOISE_TEXTURE, false, 2);
11260
+
11261
+ try
11262
+ {
11263
+ BindTexture(NOISE_TEXTURE, false, 2);
11264
+ }
11265
+ catch (Exception e)
11266
+ {
11267
+ System.err.println("FAILED: " + NOISE_TEXTURE);
11268
+ }
11269
+
1078711270
1078811271 gl.glActiveTexture(GL.GL_TEXTURE0);
1078911272 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -10806,9 +11289,9 @@
1080611289
1080711290 gl.glMatrixMode(GL.GL_MODELVIEW);
1080811291
10809
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10810
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10811
-//gl.glEnable(gl.GL_MULTISAMPLE);
11292
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11293
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11294
+gl.glEnable(gl.GL_MULTISAMPLE);
1081211295 } else
1081311296 {
1081411297 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -10819,7 +11302,7 @@
1081911302 //System.out.println("BLENDING ON");
1082011303 gl.glEnable(GL.GL_BLEND);
1082111304 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
10822
-
11305
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1082311306 gl.glMatrixMode(gl.GL_PROJECTION);
1082411307 gl.glLoadIdentity();
1082511308
....@@ -10908,8 +11391,8 @@
1090811391 System.err.println("parentcam != renderCamera");
1090911392
1091011393 // if (cam != lightCamera)
10911
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10912
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11394
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11395
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1091311396 }
1091411397
1091511398 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -10930,8 +11413,8 @@
1093011413 if (true) // TODO
1093111414 {
1093211415 if (cam != lightCamera)
10933
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10934
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11416
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11417
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
1093511418 }
1093611419
1093711420 LA.xformPos(light0, cam.toScreen, light0);
....@@ -11068,7 +11551,7 @@
1106811551 }
1106911552 }
1107011553
11071
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11554
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1107211555 {
1107311556 //gl.glDepthFunc(GL.GL_LEQUAL);
1107411557 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11076,24 +11559,21 @@
1107611559
1107711560 boolean texon = textureon;
1107811561
11079
- if (RENDERPROGRAM > 0)
11080
- {
11081
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11082
- textureon = false;
11083
- }
11562
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11563
+ textureon = false;
11564
+
1108411565 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1108511566 //System.out.println("ALLO");
1108611567 gl.glColorMask(false, false, false, false);
1108711568 DrawObject(gl);
11088
- if (RENDERPROGRAM > 0)
11089
- {
11090
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11091
- textureon = texon;
11092
- }
11569
+
11570
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11571
+ textureon = texon;
11572
+
1109311573 gl.glColorMask(true, true, true, true);
1109411574
1109511575 gl.glDepthFunc(GL.GL_EQUAL);
11096
- //gl.glDepthMask(false);
11576
+ gl.glDepthMask(false);
1109711577 }
1109811578
1109911579 if (false) // DrawMode() == SHADOW)
....@@ -11247,8 +11727,14 @@
1124711727 {
1124811728 renderpass++;
1124911729 // System.out.println("Draw object... ");
11730
+ STEP = 1;
1125011731 if (FAST) // in case there is no script
11251
- STEP = 16;
11732
+ STEP = 8;
11733
+
11734
+ if (CURRENTANTIALIAS == 0 || ACSIZE == 1)
11735
+ {
11736
+ STEP *= 4;
11737
+ }
1125211738
1125311739 //object.FullInvariants();
1125411740
....@@ -11262,23 +11748,44 @@
1126211748 e.printStackTrace();
1126311749 }
1126411750
11265
- if (GrafreeD.RENDERME > 0)
11266
- GrafreeD.RENDERME--; // mechante magouille
11751
+ if (Grafreed.RENDERME > 0)
11752
+ Grafreed.RENDERME--; // mechante magouille
1126711753
1126811754 Globals.ONESTEP = false;
1126911755 }
1127011756
1127111757 static boolean zoomonce = false;
1127211758
11759
+ static void CreateSelectedPoint()
11760
+ {
11761
+ if (selectedpoint == null)
11762
+ {
11763
+ debugpointG = new Sphere();
11764
+ debugpointP = new Sphere();
11765
+ debugpointC = new Sphere();
11766
+ debugpointR = new Sphere();
11767
+
11768
+ selectedpoint = new Superellipsoid();
11769
+
11770
+ for (int i=0; i<8; i++)
11771
+ {
11772
+ debugpoints[i] = new Sphere();
11773
+ }
11774
+ }
11775
+ }
11776
+
1127311777 void DrawObject(GL gl, boolean draw)
1127411778 {
11779
+ // To clear camera values
11780
+ ResetOptions();
11781
+
1127511782 //System.out.println("DRAW OBJECT " + mouseDown);
1127611783 // DrawMode() = SELECTION;
1127711784 //GL gl = getGL();
1127811785 if ((TRACK || SHADOWTRACK) || zoomonce)
1127911786 {
1128011787 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11281
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11788
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1128211789 pingthread.StepToTarget(true); // true);
1128311790 // zoomonce = false;
1128411791 }
....@@ -11333,7 +11840,14 @@
1133311840
1133411841 usedtextures.clear();
1133511842
11336
- BindTextures(DEFAULT_TEXTURES, 2);
11843
+ try
11844
+ {
11845
+ BindTextures(DEFAULT_TEXTURES, 2);
11846
+ }
11847
+ catch (Exception e)
11848
+ {
11849
+ System.err.println("FAILED: " + DEFAULT_TEXTURES);
11850
+ }
1133711851 }
1133811852 //System.out.println("--> " + stackdepth);
1133911853 // GrafreeD.traceon();
....@@ -11343,8 +11857,9 @@
1134311857
1134411858 if (DrawMode() == DEFAULT)
1134511859 {
11346
- if (DEBUG)
11860
+ if (Globals.DEBUG)
1134711861 {
11862
+ CreateSelectedPoint();
1134811863 float radius = 0.05f;
1134911864 if (selectedpoint.radius != radius)
1135011865 {
....@@ -11398,20 +11913,32 @@
1139811913 ReleaseTextures(DEFAULT_TEXTURES);
1139911914
1140011915 if (CLEANCACHE)
11401
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11916
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1140211917 {
11403
- String tex = e.nextElement();
11918
+ cTexture tex = e.nextElement();
1140411919
1140511920 // System.out.println("Texture --------- " + tex);
1140611921
11407
- if (tex.equals("WHITE_NOISE"))
11922
+ if (tex.equals("WHITE_NOISE:"))
1140811923 continue;
1140911924
11410
- if (!usedtextures.containsKey(tex))
11925
+ if (!usedtextures.contains(tex))
1141111926 {
11927
+ CacheTexture gettex = texturepigment.get(tex);
1141211928 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11413
- textures.get(tex).texture.dispose();
11414
- textures.remove(tex);
11929
+ if (gettex != null)
11930
+ {
11931
+ gettex.texture.dispose();
11932
+ texturepigment.remove(tex);
11933
+ }
11934
+
11935
+ gettex = texturebump.get(tex);
11936
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11937
+ if (gettex != null)
11938
+ {
11939
+ gettex.texture.dispose();
11940
+ texturebump.remove(tex);
11941
+ }
1141511942 }
1141611943 }
1141711944 }
....@@ -11424,7 +11951,14 @@
1142411951 if (checker != null && DrawMode() == DEFAULT)
1142511952 {
1142611953 //BindTexture(IMMORTAL_TEXTURE);
11427
- BindTextures(checker.GetTextures(), checker.texres);
11954
+ try
11955
+ {
11956
+ BindTextures(checker.GetTextures(), checker.texres);
11957
+ }
11958
+ catch (Exception e)
11959
+ {
11960
+ System.err.println("FAILED: " + checker.GetTextures());
11961
+ }
1142811962 // NEAREST
1142911963 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
1143011964 DrawChecker(gl);
....@@ -11506,7 +12040,7 @@
1150612040 return;
1150712041 }
1150812042
11509
- String string = obj.GetToolTip();
12043
+ String string = obj.toString(); //.GetToolTip();
1151012044
1151112045 GL gl = GetGL();
1151212046
....@@ -11823,8 +12357,8 @@
1182312357 //obj.TransformToWorld(light, light);
1182412358 for (int i = tp.size(); --i >= 0;)
1182512359 {
11826
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
11827
- LA.xformPos(light, tp.get(i).toParent, light);
12360
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12361
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1182812362 }
1182912363
1183012364
....@@ -11841,8 +12375,8 @@
1184112375 parentcam = cameras[0];
1184212376 }
1184312377
11844
- for (int count = parentcam.GetTransformCount(); --count>=0;)
11845
- LA.xformPos(light, parentcam.toParent, light); // may 2013
12378
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
12379
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1184612380
1184712381 LA.xformPos(light, renderCamera.toScreen, light);
1184812382
....@@ -11932,8 +12466,76 @@
1193212466
1193312467 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1193412468
11935
- String program =
12469
+ String programmin =
12470
+ // Min shader
1193612471 "!!ARBfp1.0\n" +
12472
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12473
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12474
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12475
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12476
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12477
+ "PARAM light2cam0 = program.env[10];" +
12478
+ "PARAM light2cam1 = program.env[11];" +
12479
+ "PARAM light2cam2 = program.env[12];" +
12480
+ "TEMP temp;" +
12481
+ "TEMP light;" +
12482
+ "TEMP ndotl;" +
12483
+ "TEMP normal;" +
12484
+ "TEMP depth;" +
12485
+ "TEMP eye;" +
12486
+ "TEMP pos;" +
12487
+
12488
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12489
+ Normalize("normal") +
12490
+ "MOV light, state.light[0].position;" +
12491
+ "DP3 ndotl.x, light, normal;" +
12492
+
12493
+ // shadow
12494
+ "MOV pos, fragment.texcoord[1];" +
12495
+ "MOV temp, pos;" +
12496
+ ShadowTextureFetch("depth", "temp", "1") +
12497
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12498
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12499
+
12500
+ // No shadow when out of frustum
12501
+ //"SGE temp.y, depth.z, zero123.y;" +
12502
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12503
+
12504
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12505
+
12506
+ // Backlit
12507
+ "MOV pos.w, zero123.y;" +
12508
+ "DP4 eye.x, pos, light2cam0;" +
12509
+ "DP4 eye.y, pos, light2cam1;" +
12510
+ "DP4 eye.z, pos, light2cam2;" +
12511
+ Normalize("eye") +
12512
+
12513
+ "DP3 ndotl.y, -eye, normal;" +
12514
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12515
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12516
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12517
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12518
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12519
+
12520
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12521
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12522
+
12523
+ // Pigment
12524
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12525
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12526
+ "MUL temp, temp, ndotl.x;" +
12527
+
12528
+ "MUL temp, temp, zero123.z;" +
12529
+
12530
+ //"MUL temp, temp, ndotl.y;" +
12531
+
12532
+ "MOV temp.w, zero123.y;" + // reset alpha
12533
+ "MOV result.color, temp;" +
12534
+ "END";
12535
+
12536
+ String programmax =
12537
+ "!!ARBfp1.0\n" +
12538
+
1193712539 //"OPTION ARB_fragment_program_shadow;" +
1193812540 "PARAM light2cam0 = program.env[10];" +
1193912541 "PARAM light2cam1 = program.env[11];" +
....@@ -12048,8 +12650,7 @@
1204812650 "TEMP shininess;" +
1204912651 "\n" +
1205012652 "MOV texSamp, one;" +
12051
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12052
-
12653
+
1205312654 "MOV mapgrid.x, one2048th.x;" +
1205412655 "MOV temp, fragment.texcoord[1];" +
1205512656 /*
....@@ -12070,20 +12671,20 @@
1207012671 "MUL temp, floor, mapgrid.x;" +
1207112672 //"TEX depth0, temp, texture[1], 2D;" +
1207212673 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12073
- TextureFetch("depth0", "temp", "1") +
12674
+ ShadowTextureFetch("depth0", "temp", "1") +
1207412675 "") +
1207512676 "ADD temp.x, temp.x, mapgrid.x;" +
1207612677 //"TEX depth1, temp, texture[1], 2D;" +
1207712678 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12078
- TextureFetch("depth1", "temp", "1") +
12679
+ ShadowTextureFetch("depth1", "temp", "1") +
1207912680 "") +
1208012681 "ADD temp.y, temp.y, mapgrid.x;" +
1208112682 //"TEX depth2, temp, texture[1], 2D;" +
12082
- TextureFetch("depth2", "temp", "1") +
12683
+ ShadowTextureFetch("depth2", "temp", "1") +
1208312684 "SUB temp.x, temp.x, mapgrid.x;" +
1208412685 //"TEX depth3, temp, texture[1], 2D;" +
1208512686 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12086
- TextureFetch("depth3", "temp", "1") +
12687
+ ShadowTextureFetch("depth3", "temp", "1") +
1208712688 "") +
1208812689 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1208912690 //"MOV params, material;" +
....@@ -12454,10 +13055,10 @@
1245413055 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1245513056 "") +
1245613057
12457
- // display shadow only (bump == 0)
13058
+ // display shadow only (fakedepth == 0)
1245813059 "SUB temp.x, half.x, shadow.x;" +
12459
- "MOV temp.y, -params6.x;" +
12460
- "SLT temp.z, temp.y, zero.x;" +
13060
+ "MOV temp.y, -params5.z;" + // params6.x;" +
13061
+ "SLT temp.z, temp.y, -c256i.x;" +
1246113062 "SUB temp.y, one.x, temp.z;" +
1246213063 "MUL temp.x, temp.x, temp.y;" +
1246313064 "KIL temp.x;" +
....@@ -12586,8 +13187,10 @@
1258613187 "MAX ndotl.x, ndotl.x, -ndotl.x;" +
1258713188
1258813189 "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
13190
+ // Tuning for default skin
13191
+ //"ADD temp.x, temp.x, options2.z;" + // lightsheen
13192
+ "MAD temp.x, options2.z, half.y, temp.x;" + // lightsheen
13193
+ "ADD temp.y, one.y, options2.y;" + // subsurface
1259113194 "MUL temp.x, temp.x, temp.y;" +
1259213195
1259313196 "MUL saturation, saturation, temp.xxxx;" +
....@@ -12786,7 +13389,14 @@
1278613389 //once = true;
1278713390 }
1278813391
12789
- System.out.print("Program #" + mode + "; length = " + program.length());
13392
+ String program = programmax;
13393
+
13394
+ if (Globals.MINSHADER)
13395
+ {
13396
+ program = programmin;
13397
+ }
13398
+
13399
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1279013400 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1279113401 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1279213402
....@@ -12879,25 +13489,26 @@
1287913489 return out;
1288013490 }
1288113491
12882
- String TextureFetch(String dest, String src, String unit)
13492
+ // Also does frustum culling
13493
+ String ShadowTextureFetch(String dest, String src, String unit)
1288313494 {
1288413495 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1288513496 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1288613497 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13498
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13499
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1288713500 "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;" +
13501
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13502
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1289213503 //"SWZ buffer, temp, w,w,w,w;";
12893
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13504
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1289413505 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1289513506 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1289613507 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
12897
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13508
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1289813509
12899
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
12900
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13510
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13511
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1290113512 }
1290213513
1290313514 String Shadow(String depth, String shadow)
....@@ -12919,12 +13530,16 @@
1291913530
1292013531 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1292113532 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13533
+
13534
+ // Compare fragment depth in light space with shadowmap.
1292213535 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1292313536 "SGE temp.y, temp.x, zero.x;" +
12924
- "SUB " + shadow + ".y, one.x, temp.y;" +
13537
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13538
+
13539
+ // Reverse comparison
1292513540 "SUB temp.x, one.x, temp.x;" +
1292613541 "MUL " + shadow + ".x, temp.x, temp.y;" +
12927
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13542
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1292813543 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1292913544
1293013545 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -12938,6 +13553,10 @@
1293813553 // No shadow for backface
1293913554 "DP3 temp.x, normal, lightd;" +
1294013555 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13556
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13557
+
13558
+ // No shadow when out of frustum
13559
+ "SGE temp.x, " + depth + ".z, one.z;" +
1294113560 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1294213561 "";
1294313562 }
....@@ -13084,7 +13703,8 @@
1308413703 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1308513704 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1308613705 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13087
- Object3D.cVector2[] vector2buffer;
13706
+
13707
+ //Object3D.cVector2[] vector2buffer;
1308813708
1308913709 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1309013710 // OUT : diff, spec
....@@ -13100,9 +13720,10 @@
1310013720 "DP3 " + dest + ".z," + "normals," + "eye;" +
1310113721 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1310213722 //"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;" +
13723
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13724
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13725
+
13726
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1310613727 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1310713728 "RCP " + dest + ".w," + dest + ".w;" +
1310813729 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13496,7 +14117,7 @@
1349614117 public void mousePressed(MouseEvent e)
1349714118 {
1349814119 //System.out.println("mousePressed: " + e);
13499
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14120
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1350014121 }
1350114122
1350214123 static long prevtime = 0;
....@@ -13523,6 +14144,7 @@
1352314144
1352414145 //System.err.println("Dtime = " + Dtime + "; units = " + e.getUnitsToScroll() + "; ratio (units/ms) = " + ratio);
1352514146
14147
+ if (BUTTONLESSWHEEL)
1352614148 if (Math.abs(ratio) < 0.1 || Math.abs(Dtime) == 0) // < 30)
1352714149 {
1352814150 return;
....@@ -13531,7 +14153,7 @@
1353114153 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
1353214154
1353314155 // TIMER
13534
- if (!wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
14156
+ if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
1353514157 {
1353614158 keepboxmode = BOXMODE;
1353714159 keepsupport = SUPPORT;
....@@ -13571,8 +14193,8 @@
1357114193 // mode |= META;
1357214194 //}
1357314195
13574
- SetMouseMode(WHEEL | e.getModifiersEx());
13575
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14196
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14197
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1357614198 anchorX = ax;
1357714199 anchorY = ay;
1357814200 prevX = px;
....@@ -13606,6 +14228,7 @@
1360614228 else
1360714229 if (evt.getSource() == AAtimer)
1360814230 {
14231
+ Globals.TIMERRUNNING = false;
1360914232 if (mouseDown)
1361014233 {
1361114234 //new Exception().printStackTrace();
....@@ -13631,6 +14254,10 @@
1363114254 // LIVE = waslive;
1363214255 // wasliveok = true;
1363314256 // waslive = false;
14257
+
14258
+ // May 2019 Forget it:
14259
+ if (true)
14260
+ return;
1363414261
1363514262 // source == timer
1363614263 if (mouseDown)
....@@ -13661,7 +14288,7 @@
1366114288
1366214289 // fev 2014???
1366314290 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13664
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14291
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1366514292 pingthread.StepToTarget(true); // true);
1366614293 }
1366714294 // if (!LIVE)
....@@ -13670,12 +14297,13 @@
1367014297
1367114298 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1367214299
13673
- void clickStart(int x, int y, int modifiers)
14300
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1367414301 {
1367514302 if (!wasliveok)
1367614303 return;
1367714304
1367814305 AAtimer.restart(); //
14306
+ Globals.TIMERRUNNING = true;
1367914307
1368014308 // waslive = LIVE;
1368114309 // LIVE = false;
....@@ -13687,7 +14315,7 @@
1368714315 // touched = true; // main DL
1368814316 if (isRenderer)
1368914317 {
13690
- SetMouseMode(modifiers);
14318
+ SetMouseMode(modifiers, modifiersex);
1369114319 }
1369214320
1369314321 selectX = anchorX = x;
....@@ -13700,7 +14328,7 @@
1370014328 clicked = true;
1370114329 hold = false;
1370214330
13703
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14331
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1370414332 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1370514333 {
1370614334 // System.out.println("RESTART II " + modifiers);
....@@ -13725,14 +14353,15 @@
1372514353 drag = false;
1372614354 //System.out.println("Mouse DOWN");
1372714355 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);
14356
+ //ClickInfo info = new ClickInfo();
14357
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14358
+ object.clickInfo.pane = this;
14359
+ object.clickInfo.camera = renderCamera;
14360
+ object.clickInfo.x = x;
14361
+ object.clickInfo.y = y;
14362
+ object.clickInfo.modifiers = modifiersex;
14363
+ editObj = object.doEditClick(//info,
14364
+ 0);
1373614365 if (!editObj)
1373714366 {
1373814367 hasMarquee = true;
....@@ -13748,11 +14377,14 @@
1374814377
1374914378 public void mouseDragged(MouseEvent e)
1375014379 {
14380
+ Globals.MOUSEDRAGGED = true;
14381
+
14382
+ //System.out.println("mouseDragged: " + e);
1375114383 if (isRenderer)
1375214384 movingcamera = true;
14385
+
1375314386 //if (drawing)
1375414387 //return;
13755
- //System.out.println("mouseDragged: " + e);
1375614388 if ((e.getModifiersEx() & CTRL) != 0
1375714389 || (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen())
1375814390 {
....@@ -13760,7 +14392,7 @@
1376014392 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1376114393 }
1376214394 else
13763
- drag(e.getX(), e.getY(), e.getModifiersEx());
14395
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1376414396
1376514397 //try { Thread.sleep(1); } catch (Exception ex) {}
1376614398 }
....@@ -13933,6 +14565,7 @@
1393314565
1393414566 public void run()
1393514567 {
14568
+ new Exception().printStackTrace();
1393614569 System.exit(0);
1393714570 for (;;)
1393814571 {
....@@ -13996,7 +14629,7 @@
1399614629 {
1399714630 Globals.lighttouched = true;
1399814631 }
13999
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14632
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1400014633 }
1400114634 //else
1400214635 }
....@@ -14010,12 +14643,12 @@
1401014643 void GoDown(int mod)
1401114644 {
1401214645 MODIFIERS |= COMMAND;
14013
- /*
14646
+ /**/
1401414647 if((mod&SHIFT) == SHIFT)
14015
- manipCamera.RotatePosition(0, -speed);
14648
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
1401614649 else
14017
- manipCamera.BackForth(0, -speed*delta, getWidth());
14018
- */
14650
+ manipCamera.RotatePosition(0, -speed);
14651
+ /**/
1401914652 if ((mod & SHIFT) == SHIFT)
1402014653 {
1402114654 mouseMode = mouseMode; // VR??
....@@ -14031,12 +14664,12 @@
1403114664 void GoUp(int mod)
1403214665 {
1403314666 MODIFIERS |= COMMAND;
14034
- /*
14667
+ /**/
1403514668 if((mod&SHIFT) == SHIFT)
14036
- manipCamera.RotatePosition(0, speed);
14669
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
1403714670 else
14038
- manipCamera.BackForth(0, speed*delta, getWidth());
14039
- */
14671
+ manipCamera.RotatePosition(0, speed);
14672
+ /**/
1404014673 if ((mod & SHIFT) == SHIFT)
1404114674 {
1404214675 mouseMode = mouseMode;
....@@ -14052,12 +14685,12 @@
1405214685 void GoLeft(int mod)
1405314686 {
1405414687 MODIFIERS |= COMMAND;
14055
- /*
14688
+ /**/
1405614689 if((mod&SHIFT) == SHIFT)
14057
- manipCamera.RotatePosition(speed, 0);
14058
- else
1405914690 manipCamera.Translate(speed*delta, 0, getWidth());
14060
- */
14691
+ else
14692
+ manipCamera.RotatePosition(speed, 0);
14693
+ /**/
1406114694 if ((mod & SHIFT) == SHIFT)
1406214695 {
1406314696 mouseMode = mouseMode;
....@@ -14073,12 +14706,12 @@
1407314706 void GoRight(int mod)
1407414707 {
1407514708 MODIFIERS |= COMMAND;
14076
- /*
14709
+ /**/
1407714710 if((mod&SHIFT) == SHIFT)
14078
- manipCamera.RotatePosition(-speed, 0);
14079
- else
1408014711 manipCamera.Translate(-speed*delta, 0, getWidth());
14081
- */
14712
+ else
14713
+ manipCamera.RotatePosition(-speed, 0);
14714
+ /**/
1408214715 if ((mod & SHIFT) == SHIFT)
1408314716 {
1408414717 mouseMode = mouseMode;
....@@ -14096,7 +14729,7 @@
1409614729 int X, Y;
1409714730 boolean SX, SY;
1409814731
14099
- void drag(int x, int y, int modifiers)
14732
+ void drag(int x, int y, int modifiers, int modifiersex)
1410014733 {
1410114734 if (IsFrozen())
1410214735 {
....@@ -14105,17 +14738,17 @@
1410514738
1410614739 drag = true; // NEW
1410714740
14108
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14741
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1410914742
1411014743 X = x;
1411114744 Y = y;
1411214745 // floating state for animation
14113
- MODIFIERS = modifiers;
14114
- modifiers &= ~1024;
14746
+ MODIFIERS = modifiersex;
14747
+ modifiersex &= ~1024;
1411514748 if (false) // modifiers != 0)
1411614749 {
1411714750 //new Exception().printStackTrace();
14118
- System.out.println("mouseDragged: " + modifiers);
14751
+ System.out.println("mouseDragged: " + modifiersex);
1411914752 System.out.println("SHIFT = " + SHIFT);
1412014753 System.out.println("CONTROL = " + COMMAND);
1412114754 System.out.println("META = " + META);
....@@ -14128,14 +14761,16 @@
1412814761 if (editObj)
1412914762 {
1413014763 drag = true;
14131
- ClickInfo info = new ClickInfo();
14132
- info.bounds.setBounds(0, 0,
14764
+ //ClickInfo info = new ClickInfo();
14765
+ object.clickInfo.bounds.setBounds(0, 0,
1413314766 (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);
14767
+ object.clickInfo.pane = this;
14768
+ object.clickInfo.camera = renderCamera;
14769
+ object.clickInfo.x = x;
14770
+ object.clickInfo.y = y;
14771
+ object //.GetWindow().copy
14772
+ .doEditDrag(//info,
14773
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1413914774 } else
1414014775 {
1414114776 if (x < startX)
....@@ -14284,23 +14919,27 @@
1428414919 }
1428514920 }
1428614921
14922
+// ClickInfo clickInfo = new ClickInfo();
14923
+
1428714924 public void mouseMoved(MouseEvent e)
1428814925 {
1428914926 //System.out.println("mouseMoved: " + e);
14290
-
1429114927 if (isRenderer)
1429214928 return;
1429314929
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;
14930
+ // Mouse cursor feedback
14931
+ object.clickInfo.x = e.getX();
14932
+ object.clickInfo.y = e.getY();
14933
+ object.clickInfo.modifiers = e.getModifiersEx();
14934
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14935
+ object.clickInfo.pane = this;
14936
+ object.clickInfo.camera = renderCamera;
1430114937 if (!isRenderer)
1430214938 {
14303
- if (object.editWindow.copy.doEditClick(ci, 0))
14939
+ //ObjEditor editWindow = object.editWindow;
14940
+ //Object3D copy = editWindow.copy;
14941
+ if (object.doEditClick(//clickInfo,
14942
+ 0))
1430414943 {
1430514944 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1430614945 } else
....@@ -14312,7 +14951,11 @@
1431214951
1431314952 public void mouseReleased(MouseEvent e)
1431414953 {
14954
+ Globals.MOUSEDRAGGED = false;
14955
+
1431514956 movingcamera = false;
14957
+ X = 0; // getBounds().width/2;
14958
+ Y = 0; // getBounds().height/2;
1431614959 //System.out.println("mouseReleased: " + e);
1431714960 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1431814961 }
....@@ -14335,9 +14978,9 @@
1433514978 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1433614979 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1433714980
14338
- if (control || command || IsFrozen())
14981
+// No delay if (control || command || IsFrozen())
1433914982 timeout = true;
14340
- else
14983
+// ?? May 2019 else
1434114984 // timer.setDelay((modifiers & 128) != 0?0:350);
1434214985 mouseDown = false;
1434314986 if (!control && !command) // june 2013
....@@ -14447,7 +15090,7 @@
1444715090 System.out.println("keyReleased: " + e);
1444815091 }
1444915092
14450
- void SetMouseMode(int modifiers)
15093
+ void SetMouseMode(int modifiers, int modifiersex)
1445115094 {
1445215095 //System.out.println("SetMouseMode = " + modifiers);
1445315096 //modifiers &= ~1024;
....@@ -14459,25 +15102,25 @@
1445915102 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1446015103 // return;
1446115104 //System.out.println("SetMode = " + modifiers);
14462
- if ((modifiers & WHEEL) == WHEEL)
15105
+ if ((modifiersex & WHEEL) == WHEEL)
1446315106 {
1446415107 mouseMode |= ZOOM;
1446515108 }
1446615109
1446715110 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
14468
- if (capsLocked || (modifiers & META) == META)
15111
+ if (capsLocked) // || (modifiers & META) == META)
1446915112 {
1447015113 mouseMode |= VR; // BACKFORTH;
1447115114 }
14472
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
15115
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1447315116 {
1447415117 mouseMode |= SELECT;
1447515118 }
14476
- if ((modifiers & COMMAND) == COMMAND)
15119
+ if ((modifiersex & COMMAND) == COMMAND)
1447715120 {
1447815121 mouseMode |= SELECT;
1447915122 }
14480
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15123
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
1448115124 {
1448215125 mouseMode &= ~VR;
1448315126 mouseMode |= TRANSLATE;
....@@ -14506,7 +15149,7 @@
1450615149
1450715150 if (isRenderer) //
1450815151 {
14509
- SetMouseMode(modifiers);
15152
+ SetMouseMode(0, modifiers);
1451015153 }
1451115154
1451215155 Globals.theRenderer.keyPressed(key);
....@@ -14568,7 +15211,8 @@
1456815211 // break;
1456915212 case 'T':
1457015213 CACHETEXTURE ^= true;
14571
- textures.clear();
15214
+ texturepigment.clear();
15215
+ texturebump.clear();
1457215216 // repaint();
1457315217 break;
1457415218 case 'Y':
....@@ -14653,7 +15297,9 @@
1465315297 case 'E' : COMPACT ^= true;
1465415298 repaint();
1465515299 break;
14656
- case 'W' : DEBUGHSB ^= true;
15300
+ case 'W' : // Wide Window (fullscreen)
15301
+ //DEBUGHSB ^= true;
15302
+ ObjEditor.theFrame.ToggleFullScreen();
1465715303 repaint();
1465815304 break;
1465915305 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14678,8 +15324,8 @@
1467815324 RevertCamera();
1467915325 repaint();
1468015326 break;
14681
- case 'L':
1468215327 case 'l':
15328
+ //case 'L':
1468315329 if (lightMode)
1468415330 {
1468515331 lightMode = false;
....@@ -14743,20 +15389,24 @@
1474315389 OCCLUSION_CULLING ^= true;
1474415390 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1474515391 break;
14746
- case '0': envyoff ^= true; repaint(); break;
15392
+ //case '0': envyoff ^= true; repaint(); break;
1474715393 case '1':
1474815394 case '2':
1474915395 case '3':
1475015396 case '4':
1475115397 case '5':
14752
- newenvy = Character.getNumericValue(key);
14753
- repaint();
14754
- break;
1475515398 case '6':
1475615399 case '7':
1475715400 case '8':
1475815401 case '9':
14759
- BGcolor = (key - '6')/3.f;
15402
+ if (true) // envyoff)
15403
+ {
15404
+ BGcolor = (key - '1')/8.f;
15405
+ }
15406
+ else
15407
+ {
15408
+ //newenvy = Character.getNumericValue(key);
15409
+ }
1476015410 repaint();
1476115411 break;
1476215412 case '!':
....@@ -14822,9 +15472,9 @@
1482215472 case '_':
1482315473 kompactbit = 5;
1482415474 break;
14825
- case '+':
14826
- kompactbit = 6;
14827
- break;
15475
+// case '+':
15476
+// kompactbit = 6;
15477
+// break;
1482815478 case ' ':
1482915479 lightMode ^= true;
1483015480 Globals.lighttouched = true;
....@@ -14836,13 +15486,14 @@
1483615486 case ESC:
1483715487 RENDERPROGRAM += 1;
1483815488 RENDERPROGRAM %= 3;
15489
+
1483915490 repaint();
1484015491 break;
1484115492 case 'Z':
1484215493 //RESIZETEXTURE ^= true;
1484315494 //break;
1484415495 case 'z':
14845
- RENDERSHADOW ^= true;
15496
+ Globals.RENDERSHADOW ^= true;
1484615497 Globals.lighttouched = true;
1484715498 repaint();
1484815499 break;
....@@ -14875,8 +15526,9 @@
1487515526 case DELETE:
1487615527 ClearSelection();
1487715528 break;
14878
- /*
1487915529 case '+':
15530
+
15531
+ /*
1488015532 //fontsize += 1;
1488115533 bbzoom *= 2;
1488215534 repaint();
....@@ -14893,17 +15545,17 @@
1489315545 case '=':
1489415546 IncDepth();
1489515547 //fontsize += 1;
14896
- object.editWindow.refreshContents(true);
15548
+ object.GetWindow().refreshContents(true);
1489715549 maskbit = 6;
1489815550 break;
1489915551 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1490015552 DecDepth();
1490115553 maskbit = 5;
1490215554 //if(fontsize > 1) fontsize -= 1;
14903
- if (object.editWindow == null)
14904
- new Exception().printStackTrace();
14905
- else
14906
- object.editWindow.refreshContents(true);
15555
+// if (object.editWindow == null)
15556
+// new Exception().printStackTrace();
15557
+// else
15558
+ object.GetWindow().refreshContents(true);
1490715559 break;
1490815560 case '{':
1490915561 manipCamera.shaper_fovy /= 1.1;
....@@ -14966,7 +15618,7 @@
1496615618 //mode = ROTATE;
1496715619 if ((MODIFIERS & COMMAND) == 0) // VR??
1496815620 {
14969
- SetMouseMode(modifiers);
15621
+ SetMouseMode(0, modifiers);
1497015622 }
1497115623 }
1497215624
....@@ -15100,8 +15752,9 @@
1510015752
1510115753 protected void processMouseMotionEvent(MouseEvent e)
1510215754 {
15103
- //System.out.println("processMouseMotionEvent: " + mouseMode);
15104
- if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15755
+ //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
15756
+ //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15757
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1510515758 {
1510615759 mouseMoved(e);
1510715760 } else
....@@ -15126,11 +15779,12 @@
1512615779 }
1512715780 */
1512815781
15129
- object.editWindow.EditSelection();
15782
+ object.GetWindow().EditSelection(false);
1513015783 }
1513115784
1513215785 void SelectParent()
1513315786 {
15787
+ new Exception().printStackTrace();
1513415788 System.exit(0);
1513515789 Composite group = (Composite) object;
1513615790 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -15142,10 +15796,10 @@
1514215796 {
1514315797 //selectees.remove(i);
1514415798 System.out.println("select parent of " + elem);
15145
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15799
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1514615800 } else
1514715801 {
15148
- group.editWindow.Select(elem.GetTreePath(), first, true);
15802
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1514915803 }
1515015804
1515115805 first = false;
....@@ -15154,6 +15808,7 @@
1515415808
1515515809 void SelectChildren()
1515615810 {
15811
+ new Exception().printStackTrace();
1515715812 System.exit(0);
1515815813 /*
1515915814 Composite group = (Composite) object;
....@@ -15186,12 +15841,12 @@
1518615841 for (int j = 0; j < group.children.size(); j++)
1518715842 {
1518815843 elem = (Object3D) group.children.elementAt(j);
15189
- object.editWindow.Select(elem.GetTreePath(), first, true);
15844
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1519015845 first = false;
1519115846 }
1519215847 } else
1519315848 {
15194
- object.editWindow.Select(elem.GetTreePath(), first, true);
15849
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1519515850 }
1519615851
1519715852 first = false;
....@@ -15202,21 +15857,21 @@
1520215857 {
1520315858 //Composite group = (Composite) object;
1520415859 Object3D group = object;
15205
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15860
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1520615861 }
1520715862
1520815863 void ResetTransform(int mask)
1520915864 {
1521015865 //Composite group = (Composite) object;
1521115866 Object3D group = object;
15212
- group.editWindow.ResetTransform(mask);
15867
+ group.GetWindow().ResetTransform(mask);
1521315868 }
1521415869
1521515870 void FlipTransform()
1521615871 {
1521715872 //Composite group = (Composite) object;
1521815873 Object3D group = object;
15219
- group.editWindow.FlipTransform();
15874
+ group.GetWindow().FlipTransform();
1522015875 // group.editWindow.ReduceMesh(true);
1522115876 }
1522215877
....@@ -15224,7 +15879,7 @@
1522415879 {
1522515880 //Composite group = (Composite) object;
1522615881 Object3D group = object;
15227
- group.editWindow.PrintMemory();
15882
+ group.GetWindow().PrintMemory();
1522815883 // group.editWindow.ReduceMesh(true);
1522915884 }
1523015885
....@@ -15232,7 +15887,7 @@
1523215887 {
1523315888 //Composite group = (Composite) object;
1523415889 Object3D group = object;
15235
- group.editWindow.ResetCentroid();
15890
+ group.GetWindow().ResetCentroid();
1523615891 }
1523715892
1523815893 void IncDepth()
....@@ -15314,11 +15969,11 @@
1531415969
1531515970 int width = getBounds().width;
1531615971 int height = getBounds().height;
15317
- ClickInfo info = new ClickInfo();
15318
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1531915972 //Image img = CreateImage(width, height);
1532015973 //System.out.println("width = " + width + "; height = " + height + "\n");
15974
+
1532115975 Graphics gr = g; // img.getGraphics();
15976
+
1532215977 if (!hasMarquee)
1532315978 {
1532415979 if (Xmin < Xmax) // !locked)
....@@ -15390,40 +16045,88 @@
1539016045 }
1539116046 if (object != null && !hasMarquee)
1539216047 {
16048
+ if (object.clickInfo == null)
16049
+ object.clickInfo = new ClickInfo();
16050
+ ClickInfo info = object.clickInfo;
16051
+ //ClickInfo info = new ClickInfo();
16052
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16053
+
1539316054 if (isRenderer)
1539416055 {
15395
- info.flags++;
16056
+ object.clickInfo.flags++;
1539616057 double frameAspect = (double) width / (double) height;
1539716058 if (frameAspect > renderCamera.aspect)
1539816059 {
1539916060 int desired = (int) ((double) height * renderCamera.aspect);
15400
- info.bounds.width -= width - desired;
15401
- info.bounds.x += (width - desired) / 2;
16061
+ object.clickInfo.bounds.width -= width - desired;
16062
+ object.clickInfo.bounds.x += (width - desired) / 2;
1540216063 } else
1540316064 {
1540416065 int desired = (int) ((double) width / renderCamera.aspect);
15405
- info.bounds.height -= height - desired;
15406
- info.bounds.y += (height - desired) / 2;
16066
+ object.clickInfo.bounds.height -= height - desired;
16067
+ object.clickInfo.bounds.y += (height - desired) / 2;
1540716068 }
1540816069 }
15409
- info.g = gr;
15410
- info.camera = renderCamera;
16070
+
16071
+ object.clickInfo.g = gr;
16072
+ object.clickInfo.camera = renderCamera;
1541116073 /*
1541216074 // Memory intensive (brep.verticescopy)
1541316075 if (!(object instanceof Composite))
1541416076 object.draw(info, 0, false); // SLOW :
1541516077 */
15416
- if (!isRenderer)
16078
+ if (!isRenderer) // && drag)
1541716079 {
15418
- object.drawEditHandles(info, 0);
16080
+ Grafreed.Assert(object != null);
16081
+ Grafreed.Assert(object.selection != null);
16082
+ if (object.selection.Size() > 0)
16083
+ {
16084
+ int hitSomething = object.selection.get(0).hitSomething;
16085
+
16086
+ object.clickInfo.DX = 0;
16087
+ object.clickInfo.DY = 0;
16088
+ object.clickInfo.W = 1;
16089
+ if (hitSomething == Object3D.hitCenter)
16090
+ {
16091
+ info.DX = X;
16092
+ if (X != 0)
16093
+ info.DX -= info.bounds.width/2;
16094
+
16095
+ info.DY = Y;
16096
+ if (Y != 0)
16097
+ info.DY -= info.bounds.height/2;
16098
+ }
16099
+
16100
+ object.drawEditHandles(//info,
16101
+ 0);
16102
+
16103
+ if (drag && (X != 0 || Y != 0))
16104
+ {
16105
+ switch (hitSomething)
16106
+ {
16107
+ case Object3D.hitCenter: gr.setColor(Color.pink);
16108
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16109
+ break;
16110
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16111
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16112
+ break;
16113
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16114
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16115
+ break;
16116
+ }
16117
+
16118
+ }
16119
+ }
1541916120 }
1542016121 }
16122
+
1542116123 if (isRenderer)
1542216124 {
1542316125 //gr.setColor(Color.black);
1542416126 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1542516127 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1542616128 }
16129
+
1542716130 if (hasMarquee)
1542816131 {
1542916132 gr.setXORMode(Color.white);
....@@ -15536,6 +16239,7 @@
1553616239 public boolean mouseDown(Event evt, int x, int y)
1553716240 {
1553816241 System.out.println("mouseDown: " + evt);
16242
+ System.exit(0);
1553916243 /*
1554016244 locked = true;
1554116245 drag = false;
....@@ -15579,7 +16283,7 @@
1557916283 {
1558016284 keyPressed(0, modifiers);
1558116285 }
15582
- clickStart(x, y, modifiers);
16286
+ // clickStart(x, y, modifiers);
1558316287 return true;
1558416288 }
1558516289
....@@ -15697,7 +16401,7 @@
1569716401 {
1569816402 keyReleased(0, 0);
1569916403 }
15700
- drag(x, y, modifiers);
16404
+ drag(x, y, 0, modifiers);
1570116405 return true;
1570216406 }
1570316407
....@@ -15829,7 +16533,7 @@
1582916533 Object3D object;
1583016534 static Object3D trackedobject;
1583116535 Camera renderCamera; // Light or Eye (or Occlusion)
15832
- /*static*/ Camera manipCamera; // Light or Eye
16536
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1583316537 /*static*/ Camera eyeCamera;
1583416538 /*static*/ Camera lightCamera;
1583516539 int cameracount;
....@@ -15893,6 +16597,8 @@
1589316597 private /*static*/ boolean firstime;
1589416598 private /*static*/ cVector newView = new cVector();
1589516599 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16600
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16601
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1589616602 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1589716603 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1589816604 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -15905,29 +16611,67 @@
1590516611 {
1590616612 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1590716613
16614
+ int usedsuf = 0;
16615
+
1590816616 for (int i = 0; i < suffixes.length; i++)
1590916617 {
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)
16618
+ String[] suffixe = suffixes;
16619
+ String[] fallback = suffixes2;
16620
+ String[] fallfallback = suffixes3;
16621
+
16622
+ for (int c=usedsuf; --c>=0;)
1591516623 {
15916
- throw new IOException("Unable to load texture " + resourceName);
16624
+// String[] temp = suffixe;
16625
+// suffixe = fallback;
16626
+// fallback = fallfallback;
16627
+// fallfallback = temp;
1591716628 }
16629
+
16630
+ String resourceName = basename + suffixe[i] + "." + suffix;
16631
+ TextureData data;
16632
+
16633
+ try
16634
+ {
16635
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16636
+ mipmapped,
16637
+ FileUtil.getFileSuffix(resourceName));
16638
+ }
16639
+ catch (Exception e)
16640
+ {
16641
+ try
16642
+ {
16643
+ resourceName = basename + fallback[i] + "." + suffix;
16644
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16645
+ mipmapped,
16646
+ FileUtil.getFileSuffix(resourceName));
16647
+ }
16648
+ catch (Exception e2)
16649
+ {
16650
+ resourceName = basename + fallfallback[i] + "." + suffix;
16651
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16652
+ mipmapped,
16653
+ FileUtil.getFileSuffix(resourceName));
16654
+ }
16655
+ }
16656
+
1591816657 //System.out.println("Target = " + targets[i]);
1591916658 cubemap.updateImage(data, targets[i]);
1592016659 }
1592116660
1592216661 return cubemap;
1592316662 }
16663
+
1592416664 int bigsphere = -1;
1592516665
1592616666 float BGcolor = 0.5f;
1592716667
15928
- private void DrawSkyBox(GL gl)
16668
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16669
+
16670
+ private void DrawSkyBox(GL gl, float ratio)
1592916671 {
15930
- if (envyoff || cubemap == null)
16672
+ if (//envyoff ||
16673
+ WIREFRAME ||
16674
+ cubemap == null)
1593116675 {
1593216676 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1593316677 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -15942,7 +16686,17 @@
1594216686 // Compensates for ExaminerViewer's modification of modelview matrix
1594316687 gl.glMatrixMode(GL.GL_MODELVIEW);
1594416688 gl.glLoadIdentity();
16689
+ gl.glScalef(1,ratio,1);
1594516690
16691
+// colorV[0] = 2;
16692
+// colorV[1] = 2;
16693
+// colorV[2] = 2;
16694
+// colorV[3] = 1;
16695
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16696
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16697
+//
16698
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16699
+
1594616700 //gl.glActiveTexture(GL.GL_TEXTURE1);
1594716701 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1594816702
....@@ -15974,6 +16728,7 @@
1597416728 {
1597516729 gl.glScalef(1.0f, -1.0f, 1.0f);
1597616730 }
16731
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1597716732 gl.glMultMatrixd(viewrot_1, 0);
1597816733 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1597916734 //viewer.updateInverseRotation(gl);
....@@ -16114,16 +16869,16 @@
1611416869 cStatic.objectstack[materialdepth++] = checker;
1611516870 //System.out.println("material " + material);
1611616871 //Applet3D.tracein(this, selected);
16117
- vector2buffer = checker.projectedVertices;
16872
+ //vector2buffer = checker.projectedVertices;
1611816873
1611916874 //checker.GetMaterial().Draw(this, false); // true);
16120
- DrawMaterial(checker.GetMaterial(), false); // true);
16875
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1612116876
1612216877 materialdepth -= 1;
1612316878 if (materialdepth > 0)
1612416879 {
16125
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16126
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
16880
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16881
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1612716882 }
1612816883 //checker.GetMaterial().opacity = 1f;
1612916884 ////checker.GetMaterial().ambient = 1f;
....@@ -16209,6 +16964,14 @@
1620916964 }
1621016965 }
1621116966
16967
+ private Object3D GetFolder()
16968
+ {
16969
+ Object3D folder = object.GetWindow().copy;
16970
+ if (object.GetWindow().copy.selection.Size() > 0)
16971
+ folder = object.GetWindow().copy.selection.elementAt(0);
16972
+ return folder;
16973
+ }
16974
+
1621216975 class SelectBuffer implements GLEventListener
1621316976 {
1621416977
....@@ -16224,7 +16987,7 @@
1622416987 //new Exception().printStackTrace();
1622516988 System.out.println("select buffer init");
1622616989 // Use debug pipeline
16227
- drawable.setGL(new DebugGL(drawable.getGL()));
16990
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1622816991
1622916992 GL gl = drawable.getGL();
1623016993
....@@ -16267,6 +17030,7 @@
1626717030 {
1626817031 if (!selection)
1626917032 {
17033
+ new Exception().printStackTrace();
1627017034 System.exit(0);
1627117035 return;
1627217036 }
....@@ -16287,6 +17051,17 @@
1628717051
1628817052 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1628917053
17054
+ if (PAINTMODE)
17055
+ {
17056
+ if (object.GetWindow().copy.selection.Size() > 0)
17057
+ {
17058
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17059
+
17060
+ // Make what you paint not selectable.
17061
+ paintobj.ResetSelectable();
17062
+ }
17063
+ }
17064
+
1629017065 //int tmp = selection_view;
1629117066 //selection_view = -1;
1629217067 int temp = DrawMode();
....@@ -16298,6 +17073,17 @@
1629817073 // temp = DEFAULT; // patch for selection debug
1629917074 Globals.drawMode = temp; // WARNING
1630017075
17076
+ if (PAINTMODE)
17077
+ {
17078
+ if (object.GetWindow().copy.selection.Size() > 0)
17079
+ {
17080
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17081
+
17082
+ // Revert.
17083
+ paintobj.RestoreSelectable();
17084
+ }
17085
+ }
17086
+
1630117087 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1630217088
1630317089 // trying different ways of getting the depth info over
....@@ -16345,6 +17131,8 @@
1634517131 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1634617132 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1634717133 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
17134
+
17135
+ CreateSelectedPoint();
1634817136
1634917137 // Will fit the mesh !!!
1635017138 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16394,34 +17182,36 @@
1639417182 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]));
1639517183 }
1639617184
16397
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
17185
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1639817186 }
1639917187 }
1640017188
1640117189 if (!movingcamera && !PAINTMODE)
16402
- object.editWindow.ScreenFitPoint(); // fev 2014
17190
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1640317191
16404
- if (PAINTMODE && GrafreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17192
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1640517193 {
16406
- Object3D paintobj = GrafreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17194
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1640717195
16408
- Object3D group = new Object3D("inst" + paintcount++);
17196
+ if (object.GetWindow().copy.selection.Size() > 0)
17197
+ {
17198
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1640917199
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();
17200
+ Object3D inst = new Object3D("inst" + paintcount++);
17201
+
17202
+ inst.CreateMaterial(); // use a void leaf to select instances
17203
+
17204
+ inst.add(paintobj); // link
17205
+
17206
+ object.GetWindow().SnapObject(inst);
17207
+
17208
+ Object3D folder = paintFolder; // GetFolder();
17209
+
17210
+ folder.add(inst);
17211
+
17212
+ object.GetWindow().ResetModel();
17213
+ object.GetWindow().refreshContents();
17214
+ }
1642517215 }
1642617216 else
1642717217 paintcount = 0;
....@@ -16460,6 +17250,11 @@
1646017250 //System.out.println("objects[color] = " + objects[color]);
1646117251 //objects[color].Select();
1646217252 indexcount = 0;
17253
+ ObjEditor window = object.GetWindow();
17254
+ if (window != null && deselect)
17255
+ {
17256
+ window.Select(null, deselect, true);
17257
+ }
1646317258 object.Select(color, deselect);
1646417259 }
1646517260
....@@ -16559,7 +17354,7 @@
1655917354 gl.glDisable(gl.GL_CULL_FACE);
1656017355 }
1656117356
16562
- if (!RENDERSHADOW)
17357
+ if (!Globals.RENDERSHADOW)
1656317358 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1656417359
1656517360 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -16569,7 +17364,7 @@
1656917364 //gl.glColorMask(false, false, false, false);
1657017365
1657117366 //render_scene_from_light_view(gl, drawable, 0, 0);
16572
- if (RENDERSHADOW && Globals.lighttouched && !movingcamera) // && !parent.IsFreezed())
17367
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1657317368 {
1657417369 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1657517370
....@@ -16985,23 +17780,15 @@
1698517780 int AAbuffersize = 0;
1698617781
1698717782 //double[] selectedpoint = new double[3];
16988
- static Superellipsoid selectedpoint = new Superellipsoid();
17783
+ static Superellipsoid selectedpoint;
1698917784 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();
17785
+ static Sphere debugpointG;
17786
+ static Sphere debugpointP;
17787
+ static Sphere debugpointC;
17788
+ static Sphere debugpointR;
1699417789
1699517790 static Sphere debugpoints[] = new Sphere[8];
1699617791
16997
- static
16998
- {
16999
- for (int i=0; i<8; i++)
17000
- {
17001
- debugpoints[i] = new Sphere();
17002
- }
17003
- }
17004
-
1700517792 static void InitPoints(float radius)
1700617793 {
1700717794 for (int i=0; i<8; i++)