Normand Briere
2019-07-27 1af7d3700724834e40ad8636bc9a56cdc3b19b15
CameraPane.java
....@@ -18,7 +18,10 @@
1818 import javax.imageio.ImageIO;
1919 import javax.imageio.ImageWriteParam;
2020 import javax.imageio.ImageWriter;
21
+import javax.imageio.ImageReadParam;
22
+import javax.imageio.ImageReader;
2123 import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
24
+import javax.imageio.stream.ImageInputStream;
2225 import javax.imageio.stream.ImageOutputStream;
2326 import javax.imageio.ImageWriteParam;
2427
....@@ -30,6 +33,7 @@
3033 import java.nio.*;
3134
3235 import gleem.linalg.Mat4f;
36
+import javax.imageio.ImageTypeSpecifier;
3337
3438 class CameraPane extends GLCanvas implements iCameraPane, Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener
3539 {
....@@ -37,7 +41,6 @@
3741 static boolean[] selectedstack = new boolean[65536];
3842 static int materialdepth = 0;
3943
40
- static boolean DEBUG = false;
4144 static boolean FRUSTUM = false; // still bogus true; // frustum culling
4245
4346 // camera change fix
....@@ -45,6 +48,39 @@
4548 static boolean ABORTED = false;
4649
4750 static int STEP = 1;
51
+
52
+ private static BufferedImage CreateBim(byte[] bytes, int width, int height)
53
+ {
54
+ int[] pixels = new int[bytes.length/3];
55
+ for (int i=pixels.length; --i>=0;)
56
+ {
57
+ int i3 = i*3;
58
+ pixels[i] = 0xFF;
59
+ pixels[i] <<= 8;
60
+ pixels[i] |= bytes[i3+2] & 0xFF;
61
+ pixels[i] <<= 8;
62
+ pixels[i] |= bytes[i3+1] & 0xFF;
63
+ pixels[i] <<= 8;
64
+ pixels[i] |= bytes[i3] & 0xFF;
65
+ }
66
+ /*
67
+ int r=0,g=0,b=0,a=0;
68
+ for (int i=0; i<width; i++)
69
+ for (int j=0; j<height; j++)
70
+ {
71
+ int index = j*width+i;
72
+ int p = pixels[index];
73
+ a = ((p>>24) & 0xFF);
74
+ r = ((p>>16) & 0xFF);
75
+ g = ((p>>8) & 0xFF);
76
+ b = (p & 0xFF);
77
+ pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
78
+ }
79
+ /**/
80
+ BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
81
+ rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
82
+ return rendImage;
83
+ }
4884
4985 /*static*/ private boolean CULLFACE = false; // true;
5086 /*static*/ boolean NEAREST = false; // true;
....@@ -56,14 +92,12 @@
5692 static int CURRENTANTIALIAS = 0; // 1;
5793 /*static*/ boolean RENDERSHADOW = true;
5894 /*static*/ int RENDERPROGRAM = 2; // 0 == none, 1 == fast, 2 == normal
59
- static boolean ANIMATION = false;
60
- static String filename;
6195
6296 boolean DISPLAYTEXT = false;
6397 //boolean REDUCETEXTURE = true;
6498 boolean CACHETEXTURE = true;
6599 boolean CLEANCACHE = false; // true;
66
- boolean MIPMAP = false; // true;
100
+ boolean MIPMAP = false; // true; // never works...
67101 boolean COMPRESSTEXTURE = false;
68102 boolean KOMPACTTEXTURE = false; // true;
69103 boolean RESIZETEXTURE = false;
....@@ -86,7 +120,7 @@
86120 static boolean FULLSCREEN = false;
87121 static boolean SUPPORT = true;
88122 static boolean INERTIA = true;
89
-static boolean FAST = true; // false;
123
+static boolean FAST = false;
90124 static boolean SLOWPOSE = false;
91125 static boolean FOOTCONTACT = true;
92126
....@@ -108,7 +142,7 @@
108142 static boolean OEIL = true;
109143 static boolean OEILONCE = false; // do oeilon then oeiloff
110144 static boolean LOOKAT = true;
111
-static boolean RANDOM = true; // false;
145
+static boolean SWITCH = true; // false;
112146 static boolean HANDLES = false; // selection doesn't work!!
113147 static boolean PAINTMODE = false;
114148
....@@ -152,6 +186,8 @@
152186 defaultcaps.setAccumAlphaBits(16);
153187 }
154188
189
+ private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
190
+
155191 void SetAsGLRenderer(boolean b)
156192 {
157193 isRenderer = b;
....@@ -170,7 +206,8 @@
170206
171207 SetCamera(cam);
172208
173
- SetLight(new Camera(new cVector(10, 10, -20)));
209
+ // Warning: not used.
210
+ SetLight(new Camera(new cVector(15, 10, -20)));
174211
175212 object = o;
176213
....@@ -327,7 +364,7 @@
327364 cStatic.objectstack[materialdepth++] = obj;
328365 //System.out.println("material " + material);
329366 //Applet3D.tracein(this, selected);
330
- display.vector2buffer = obj.projectedVertices;
367
+ //display.vector2buffer = obj.projectedVertices;
331368 if (obj instanceof Camera)
332369 {
333370 display.options1[0] = material.shift;
....@@ -336,14 +373,28 @@
336373 display.options1[2] = material.shadowbias;
337374 display.options1[3] = material.aniso;
338375 display.options1[4] = material.anisoV;
376
+// System.out.println("display.options1[0] " + display.options1[0]);
377
+// System.out.println("display.options1[1] " + display.options1[1]);
378
+// System.out.println("display.options1[2] " + display.options1[2]);
379
+// System.out.println("display.options1[3] " + display.options1[3]);
380
+// System.out.println("display.options1[4] " + display.options1[4]);
339381 display.options2[0] = material.opacity;
340382 display.options2[1] = material.diffuse;
341383 display.options2[2] = material.factor;
384
+// System.out.println("display.options2[0] " + display.options2[0]);
385
+// System.out.println("display.options2[1] " + display.options2[1]);
386
+// System.out.println("display.options2[2] " + display.options2[2]);
342387
343388 cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
389
+// System.out.println("display.options3[0] " + display.options3[0]);
390
+// System.out.println("display.options3[1] " + display.options3[1]);
391
+// System.out.println("display.options3[2] " + display.options3[2]);
344392 display.options4[0] = material.cameralight/0.2f;
345393 display.options4[1] = material.subsurface;
346394 display.options4[2] = material.sheen;
395
+// System.out.println("display.options4[0] " + display.options4[0]);
396
+// System.out.println("display.options4[1] " + display.options4[1]);
397
+// System.out.println("display.options4[2] " + display.options4[2]);
347398
348399 // if (display.CURRENTANTIALIAS > 0)
349400 // display.options3[3] /= 4;
....@@ -359,7 +410,7 @@
359410 /**/
360411 } else
361412 {
362
- DrawMaterial(material, selected);
413
+ DrawMaterial(material, selected, obj.projectedVertices);
363414 }
364415 } else
365416 {
....@@ -383,8 +434,8 @@
383434 cStatic.objectstack[materialdepth++] = obj;
384435 //System.out.println("material " + material);
385436 //Applet3D.tracein("selected ", selected);
386
- display.vector2buffer = obj.projectedVertices;
387
- display.DrawMaterial(material, selected);
437
+ //display.vector2buffer = obj.projectedVertices;
438
+ display.DrawMaterial(material, selected, obj.projectedVertices);
388439 }
389440 }
390441
....@@ -401,8 +452,8 @@
401452 materialdepth -= 1;
402453 if (materialdepth > 0)
403454 {
404
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
405
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
455
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
456
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
406457 }
407458 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
408459 } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
....@@ -422,8 +473,8 @@
422473 materialdepth -= 1;
423474 if (materialdepth > 0)
424475 {
425
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
426
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
476
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
477
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
427478 }
428479 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
429480 //else
....@@ -464,10 +515,12 @@
464515 if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
465516 {
466517 //gl.glBegin(gl.GL_TRIANGLES);
467
- boolean hasnorm = pv.norm != null; // && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0);
518
+ boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0)
519
+ // TEST LIVE NORMALS && !obj.dontselect
520
+ ;
468521 if (!hasnorm)
469522 {
470
- // System.out.println("FUCK!!");
523
+ // System.out.println("Mesh normal");
471524 LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
472525 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
473526 LA.vecCross(obj.v0, obj.v1, obj.v2);
....@@ -1192,10 +1245,12 @@
11921245 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
11931246 }
11941247 }
1248
+
11951249 if (flipV)
11961250 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
11971251 else
11981252 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1253
+
11991254 //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
12001255 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
12011256
....@@ -1215,10 +1270,12 @@
12151270 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
12161271 }
12171272 }
1273
+
12181274 if (flipV)
12191275 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12201276 else
12211277 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1278
+
12221279 //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
12231280 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
12241281
....@@ -1246,8 +1303,10 @@
12461303 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12471304 else
12481305 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1306
+
12491307 //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
12501308 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1309
+
12511310 count2 += 2;
12521311 count3 += 3;
12531312 }
....@@ -1603,7 +1662,7 @@
16031662 // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
16041663 }
16051664
1606
- void DrawMaterial(cMaterial material, boolean selected)
1665
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
16071666 {
16081667 CameraPane display = this;
16091668 //new Exception().printStackTrace();
....@@ -1630,7 +1689,7 @@
16301689
16311690 cColor.HSBtoRGB(display.color, display.saturation, 1, display.modelParams0);
16321691
1633
- float[] colorV = GrafreeD.colorV;
1692
+ float[] colorV = Grafreed.colorV;
16341693
16351694 /**/
16361695 if (display.DrawMode() == display.DEFAULT) // && display.RENDERPROGRAM == 0)
....@@ -1638,7 +1697,7 @@
16381697 colorV[0] = display.modelParams0[0] * material.diffuse;
16391698 colorV[1] = display.modelParams0[1] * material.diffuse;
16401699 colorV[2] = display.modelParams0[2] * material.diffuse;
1641
- colorV[3] = material.opacity;
1700
+ colorV[3] = 1; // material.opacity;
16421701
16431702 gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
16441703 //System.out.println("Opacity = " + opacity);
....@@ -1746,9 +1805,9 @@
17461805 display.modelParams7[2] = 0;
17471806 display.modelParams7[3] = 0;
17481807
1749
- display.modelParams6[0] = 100; // criss de bug de bump
1808
+ //display.modelParams6[0] = 100; // criss de bug de bump
17501809
1751
- Object3D.cVector2[] extparams = display.vector2buffer;
1810
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
17521811 if (extparams != null && extparams.length > 0 && extparams[0] != null)
17531812 {
17541813 display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
....@@ -1890,7 +1949,7 @@
18901949 void PushMatrix(double[][] matrix)
18911950 {
18921951 // GrafreeD.tracein(matrix);
1893
- PushMatrix(matrix,1);
1952
+ PushMatrix(matrix, 1);
18941953 }
18951954
18961955 void PushMatrix()
....@@ -2044,7 +2103,7 @@
20442103 //System.err.println("Oeil on");
20452104 OEIL = true;
20462105 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2047
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2106
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
20482107 //pingthread.StepToTarget(true);
20492108 }
20502109
....@@ -2142,7 +2201,7 @@
21422201 System.err.println("LIVE = " + Globals.isLIVE());
21432202
21442203 if (!Globals.isLIVE()) // save sound
2145
- GrafreeD.savesound = true; // wav.save();
2204
+ Grafreed.savesound = true; // wav.save();
21462205 // else
21472206 repaint(); // start loop // may 2013
21482207 }
....@@ -2259,7 +2318,7 @@
22592318
22602319 void ToggleDebug()
22612320 {
2262
- DEBUG ^= true;
2321
+ Globals.DEBUG ^= true;
22632322 }
22642323
22652324 void ToggleLookAt()
....@@ -2267,9 +2326,9 @@
22672326 LOOKAT ^= true;
22682327 }
22692328
2270
- void ToggleRandom()
2329
+ void ToggleSwitch()
22712330 {
2272
- RANDOM ^= true;
2331
+ SWITCH ^= true;
22732332 }
22742333
22752334 void ToggleHandles()
....@@ -2277,10 +2336,17 @@
22772336 HANDLES ^= true;
22782337 }
22792338
2339
+ Object3D paintFolder;
2340
+
22802341 void TogglePaint()
22812342 {
22822343 PAINTMODE ^= true;
22832344 paintcount = 0;
2345
+
2346
+ if (PAINTMODE)
2347
+ {
2348
+ paintFolder = GetFolder();
2349
+ }
22842350 }
22852351
22862352 void SwapCamera(int a, int b)
....@@ -2376,7 +2442,22 @@
23762442 {
23772443 return currentGL;
23782444 }
2379
-
2445
+
2446
+ static private BufferedImage CreateBim(TextureData texturedata)
2447
+ {
2448
+ Grafreed.Assert(texturedata != null);
2449
+
2450
+ int width = texturedata.getWidth();
2451
+ int height = texturedata.getHeight();
2452
+
2453
+ Buffer buffer = texturedata.getBuffer();
2454
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2455
+
2456
+ byte[] bytes = bytebuf.array();
2457
+
2458
+ return CreateBim(bytes, width, height);
2459
+ }
2460
+
23802461 /**/
23812462 class CacheTexture
23822463 {
....@@ -2385,28 +2466,31 @@
23852466
23862467 int resolution;
23872468
2388
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2469
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
23892470 {
2390
- texture = tex;
2471
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2472
+ texturedata = texdata;
23912473 resolution = res;
23922474 }
23932475 }
23942476 /**/
23952477
23962478 // TEXTURE static Texture texture;
2397
- static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures
2398
- = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>();
2399
- static public java.util.Hashtable<String, String> usedtextures = new java.util.Hashtable<String, String>();
2479
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2480
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2481
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2482
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2483
+
24002484 int pigmentdepth = 0;
24012485 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
24022486 int bumpdepth = 0;
24032487 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
24042488 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
24052489 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2406
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2490
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
24072491 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
24082492
2409
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2493
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
24102494 {
24112495 TextureData texturedata = null;
24122496
....@@ -2425,13 +2509,34 @@
24252509 if (bump)
24262510 texturedata = ConvertBump(texturedata, false);
24272511
2428
- com.sun.opengl.util.texture.Texture texture =
2429
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2512
+// com.sun.opengl.util.texture.Texture texture =
2513
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
24302514
2431
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2432
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
2515
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2516
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
24332517
2434
- return texture;
2518
+ return texturedata;
2519
+ }
2520
+
2521
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2522
+ {
2523
+ TextureData texturedata = null;
2524
+
2525
+ try
2526
+ {
2527
+ texturedata =
2528
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2529
+ bim,
2530
+ true);
2531
+ } catch (Exception e)
2532
+ {
2533
+ throw new javax.media.opengl.GLException(e);
2534
+ }
2535
+
2536
+ if (bump)
2537
+ texturedata = ConvertBump(texturedata, false);
2538
+
2539
+ return texturedata;
24352540 }
24362541
24372542 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3504,6 +3609,8 @@
35043609
35053610 System.out.println("LOADING TEXTURE : " + name);
35063611
3612
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3613
+
35073614 //
35083615 if (false) // compressbit > 0)
35093616 {
....@@ -4208,6 +4315,7 @@
42084315
42094316 com.sun.opengl.util.texture.Texture CompressTexture2(String name)
42104317 {
4318
+ new Exception().printStackTrace();
42114319 System.exit(0);
42124320 com.sun.opengl.util.texture.Texture texture = null;
42134321
....@@ -7901,7 +8009,7 @@
79018009 String pigment = Object3D.GetPigment(tex);
79028010 String bump = Object3D.GetBump(tex);
79038011
7904
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8012
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79058013 {
79068014 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79078015 // System.out.println("; bump = " + bump);
....@@ -7916,11 +8024,69 @@
79168024 pigment = null;
79178025 }
79188026
7919
- ReleaseTexture(bump, true);
7920
- ReleaseTexture(pigment, false);
8027
+ ReleaseTexture(tex, true);
8028
+ ReleaseTexture(tex, false);
79218029 }
79228030
7923
- void ReleaseTexture(String tex, boolean bump)
8031
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
8032
+ {
8033
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8034
+ {
8035
+ return;
8036
+ }
8037
+
8038
+ if (tex == null)
8039
+ {
8040
+ ReleaseTexture(null, false);
8041
+ return;
8042
+ }
8043
+
8044
+ String pigment = Object3D.GetPigment(tex);
8045
+
8046
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8047
+ {
8048
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8049
+ // System.out.println("; bump = " + bump);
8050
+ }
8051
+
8052
+ if (pigment.equals(""))
8053
+ {
8054
+ pigment = null;
8055
+ }
8056
+
8057
+ ReleaseTexture(tex, false);
8058
+ }
8059
+
8060
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
8061
+ {
8062
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8063
+ {
8064
+ return;
8065
+ }
8066
+
8067
+ if (tex == null)
8068
+ {
8069
+ ReleaseTexture(null, true);
8070
+ return;
8071
+ }
8072
+
8073
+ String bump = Object3D.GetBump(tex);
8074
+
8075
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8076
+ {
8077
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8078
+ // System.out.println("; bump = " + bump);
8079
+ }
8080
+
8081
+ if (bump.equals(""))
8082
+ {
8083
+ bump = null;
8084
+ }
8085
+
8086
+ ReleaseTexture(tex, true);
8087
+ }
8088
+
8089
+ void ReleaseTexture(cTexture tex, boolean bump)
79248090 {
79258091 if (// DrawMode() != 0 || /*tex == null ||*/
79268092 ambientOcclusion ) // || !textureon)
....@@ -7931,7 +8097,7 @@
79318097 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
79328098
79338099 if (tex != null)
7934
- texture = textures.get(tex);
8100
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
79358101
79368102 // //assert( texture != null );
79378103 // if (texture == null)
....@@ -8023,7 +8189,55 @@
80238189 }
80248190 }
80258191
8026
- /*boolean*/ public void BindTextures(cTexture tex, int resolution) // INTERFACE
8192
+ /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
8193
+ {
8194
+// if (// DrawMode() != 0 || /*tex == null ||*/
8195
+// ambientOcclusion ) // || !textureon)
8196
+// {
8197
+// return; // false;
8198
+// }
8199
+//
8200
+// if (tex == null)
8201
+// {
8202
+// BindTexture(null,false,resolution);
8203
+// BindTexture(null,true,resolution);
8204
+// return;
8205
+// }
8206
+//
8207
+// String pigment = Object3D.GetPigment(tex);
8208
+// String bump = Object3D.GetBump(tex);
8209
+//
8210
+// usedtextures.add(pigment);
8211
+// usedtextures.add(bump);
8212
+//
8213
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8214
+// {
8215
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8216
+// // System.out.println("; bump = " + bump);
8217
+// }
8218
+//
8219
+// if (bump.equals(""))
8220
+// {
8221
+// bump = null;
8222
+// }
8223
+// if (pigment.equals(""))
8224
+// {
8225
+// pigment = null;
8226
+// }
8227
+//
8228
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8229
+// BindTexture(pigment, false, resolution);
8230
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8231
+// BindTexture(bump, true, resolution);
8232
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8233
+//
8234
+// return; // true;
8235
+
8236
+ BindPigmentTexture(tex, resolution);
8237
+ BindBumpTexture(tex, resolution);
8238
+ }
8239
+
8240
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
80278241 {
80288242 if (// DrawMode() != 0 || /*tex == null ||*/
80298243 ambientOcclusion ) // || !textureon)
....@@ -8034,17 +8248,47 @@
80348248 if (tex == null)
80358249 {
80368250 BindTexture(null,false,resolution);
8037
- BindTexture(null,true,resolution);
80388251 return;
80398252 }
80408253
80418254 String pigment = Object3D.GetPigment(tex);
8255
+
8256
+ usedtextures.add(tex);
8257
+
8258
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8259
+ {
8260
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8261
+ // System.out.println("; bump = " + bump);
8262
+ }
8263
+
8264
+ if (pigment.equals(""))
8265
+ {
8266
+ pigment = null;
8267
+ }
8268
+
8269
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8270
+ BindTexture(tex, false, resolution);
8271
+ }
8272
+
8273
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8274
+ {
8275
+ if (// DrawMode() != 0 || /*tex == null ||*/
8276
+ ambientOcclusion ) // || !textureon)
8277
+ {
8278
+ return; // false;
8279
+ }
8280
+
8281
+ if (tex == null)
8282
+ {
8283
+ BindTexture(null,true,resolution);
8284
+ return;
8285
+ }
8286
+
80428287 String bump = Object3D.GetBump(tex);
80438288
8044
- usedtextures.put(pigment, pigment);
8045
- usedtextures.put(bump, bump);
8289
+ usedtextures.add(tex);
80468290
8047
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8291
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
80488292 {
80498293 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
80508294 // System.out.println("; bump = " + bump);
....@@ -8054,43 +8298,94 @@
80548298 {
80558299 bump = null;
80568300 }
8057
- if (pigment.equals(""))
8058
- {
8059
- pigment = null;
8060
- }
80618301
8062
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8063
- BindTexture(pigment, false, resolution);
80648302 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8065
- BindTexture(bump, true, resolution);
8303
+ BindTexture(tex, true, resolution);
80668304 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8067
-
8068
- return; // true;
80698305 }
80708306
8071
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution)
8307
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8308
+
8309
+ private boolean FileExists(String tex)
80728310 {
8073
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8311
+ if (missingTextures.contains(tex))
8312
+ {
8313
+ return false;
8314
+ }
8315
+
8316
+ boolean fileExists = new File(tex).exists();
8317
+
8318
+ if (!fileExists)
8319
+ {
8320
+ // If file exists, the "new File()" is not executed sgain
8321
+ missingTextures.add(tex);
8322
+ }
8323
+
8324
+ return fileExists;
8325
+ }
8326
+
8327
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
8328
+ {
8329
+ CacheTexture texturecache = null;
80748330
80758331 if (tex != null)
80768332 {
8077
- String texname = tex;
8333
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8334
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
80788335
8079
- String[] split = tex.split("Textures");
8080
- if (split.length > 1)
8081
- texname = "/Users/nbriere/Textures" + split[split.length-1];
8082
- else
8083
- if (!texname.startsWith("/"))
8084
- texname = "/Users/nbriere/Textures/" + texname;
8336
+ if (texname.equals("") && texdata == null)
8337
+ {
8338
+ return null;
8339
+ }
8340
+
8341
+ String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
8342
+
8343
+// String[] split = tex.split("Textures");
8344
+// if (split.length > 1)
8345
+// texname = "/Users/nbriere/Textures" + split[split.length-1];
8346
+// else
8347
+// if (!texname.startsWith("/"))
8348
+// texname = "/Users/nbriere/Textures/" + texname;
8349
+ if (!FileExists(texname))
8350
+ {
8351
+ texname = fallbackTextureName;
8352
+ }
80858353
80868354 if (CACHETEXTURE)
8087
- texture = textures.get(texname); // TEXTURE CACHE
8088
-
8089
- TextureData texturedata = null;
8090
-
8091
- if (texture == null || texture.resolution < resolution)
80928355 {
8093
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8356
+ if (texdata == null)
8357
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8358
+ else
8359
+ texturecache = bimtextures.get(texdata);
8360
+ }
8361
+
8362
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8363
+ {
8364
+ TextureData texturedata = null;
8365
+
8366
+ if (texdata != null && textureon)
8367
+ {
8368
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8369
+
8370
+ try
8371
+ {
8372
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8373
+ }
8374
+ catch (Exception e)
8375
+ {
8376
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8377
+ }
8378
+
8379
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8380
+ bimtextures.put(texdata, texturecache);
8381
+
8382
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8383
+
8384
+ //Object bim2 = CreateBim(texturecache.texturedata);
8385
+ //bim2 = bim;
8386
+ }
8387
+ else
8388
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
80948389 {
80958390 assert(!bump);
80968391 // if (bump)
....@@ -8101,19 +8396,23 @@
81018396 // }
81028397 // else
81038398 // {
8104
- texture = textures.get(tex);
8105
- if (texture == null)
8399
+ // texturecache = textures.get(texname); // suspicious
8400
+ if (texturecache == null)
81068401 {
8107
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8402
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
81088403 }
8404
+ else
8405
+ new Exception().printStackTrace();
81098406 // }
81108407 } else
8111
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8408
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
81128409 {
81138410 assert(bump);
8114
- texture = textures.get(tex);
8115
- if (texture == null)
8116
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8411
+ // texturecache = textures.get(texname); // suspicious
8412
+ if (texturecache == null)
8413
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8414
+ else
8415
+ new Exception().printStackTrace();
81178416 } else
81188417 {
81198418 //if (tex.equals("IMMORTAL"))
....@@ -8121,11 +8420,13 @@
81218420 // texture = GetResourceTexture("default.png");
81228421 //} else
81238422 //{
8124
- if (tex.equals("WHITE_NOISE"))
8423
+ if (texname.endsWith("WHITE_NOISE"))
81258424 {
8126
- texture = textures.get(tex);
8127
- if (texture == null)
8128
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8425
+ // texturecache = textures.get(texname); // suspicious
8426
+ if (texturecache == null)
8427
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8428
+ else
8429
+ new Exception().printStackTrace();
81298430 } else
81308431 {
81318432 if (textureon)
....@@ -8150,7 +8451,7 @@
81508451 }
81518452
81528453 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
8153
- if (!new File(cachename).exists())
8454
+ if (!FileExists(cachename))
81548455 cachename = texname;
81558456 else
81568457 processbump = false; // don't process bump map again
....@@ -8172,7 +8473,7 @@
81728473 }
81738474
81748475 cachename = texname.substring(0, texname.length()-4)+ext+".png";
8175
- if (!new File(cachename).exists())
8476
+ if (!FileExists(cachename))
81768477 cachename = texname;
81778478 else
81788479 processbump = false; // don't process bump map again
....@@ -8181,20 +8482,22 @@
81818482 texturedata = GetFileTexture(cachename, processbump, resolution);
81828483
81838484
8184
- if (texturedata != null)
8185
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8485
+ if (texturedata == null)
8486
+ throw new Exception();
8487
+
8488
+ texturecache = new CacheTexture(texturedata,resolution);
81868489 //texture = GetTexture(tex, bump);
81878490 }
81888491 }
81898492 //}
81908493 }
81918494
8192
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8495
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
81938496 {
81948497 //return false;
81958498
81968499 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8197
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8500
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
81988501 {
81998502 // String ext = "_highres";
82008503 // if (REDUCETEXTURE)
....@@ -8211,52 +8514,17 @@
82118514 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
82128515 if (!cachefile.exists())
82138516 {
8214
- // cache to disk
8215
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
8216
- //buffers[0].
8217
-
8218
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
8219
- int[] pixels = new int[bytebuf.capacity()/3];
8220
-
8221
- // squared size heuristic...
8222
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8517
+ //if (texturedata.getWidth() == texturedata.getHeight())
82238518 {
8224
- for (int i=pixels.length; --i>=0;)
8225
- {
8226
- int i3 = i*3;
8227
- pixels[i] = 0xFF;
8228
- pixels[i] <<= 8;
8229
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
8230
- pixels[i] <<= 8;
8231
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
8232
- pixels[i] <<= 8;
8233
- pixels[i] |= bytebuf.get(i3) & 0xFF;
8234
- }
8235
-
8236
- /*
8237
- int r=0,g=0,b=0,a=0;
8238
- for (int i=0; i<width; i++)
8239
- for (int j=0; j<height; j++)
8240
- {
8241
- int index = j*width+i;
8242
- int p = pixels[index];
8243
- a = ((p>>24) & 0xFF);
8244
- r = ((p>>16) & 0xFF);
8245
- g = ((p>>8) & 0xFF);
8246
- b = (p & 0xFF);
8247
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
8248
- }
8249
- /**/
8250
- int width = (int)Math.sqrt(pixels.length); // squared
8251
- int height = width;
8252
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
8253
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8519
+ BufferedImage rendImage = CreateBim(texturedata);
8520
+
82548521 ImageWriter writer = null;
82558522 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
82568523 if (iter.hasNext()) {
82578524 writer = (ImageWriter)iter.next();
82588525 }
8259
- float compressionQuality = 0.9f;
8526
+
8527
+ float compressionQuality = 0.85f;
82608528 try
82618529 {
82628530 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8273,18 +8541,20 @@
82738541 }
82748542 }
82758543 }
8276
-
8544
+
8545
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8546
+
82778547 //System.out.println("Texture = " + tex);
8278
- if (textures.containsKey(texname))
8548
+ if (textures.containsKey(tex))
82798549 {
8280
- CacheTexture thetex = textures.get(texname);
8550
+ CacheTexture thetex = textures.get(tex);
82818551 thetex.texture.disable();
82828552 thetex.texture.dispose();
8283
- textures.remove(texname);
8553
+ textures.remove(tex);
82848554 }
82858555
8286
- texture.texturedata = texturedata;
8287
- textures.put(texname, texture);
8556
+ //texture.texturedata = texturedata;
8557
+ textures.put(tex, texturecache);
82888558
82898559 // newtex = true;
82908560 }
....@@ -8300,10 +8570,44 @@
83008570 }
83018571 }
83028572
8303
- return texture;
8573
+ return texturecache;
83048574 }
83058575
8306
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution)
8576
+ static void EmbedTextures(cTexture tex)
8577
+ {
8578
+ if (tex.pigmentdata == null)
8579
+ {
8580
+ //String texname = Object3D.GetPigment(tex);
8581
+
8582
+ CacheTexture texturecache = texturepigment.get(tex);
8583
+
8584
+ if (texturecache != null)
8585
+ {
8586
+ tex.pw = texturecache.texturedata.getWidth();
8587
+ tex.ph = texturecache.texturedata.getHeight();
8588
+ tex.pigmentdata = //CompressJPEG(CreateBim
8589
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8590
+ ;
8591
+ //, tex.pw, tex.ph), 0.5f);
8592
+ }
8593
+ }
8594
+
8595
+ if (tex.bumpdata == null)
8596
+ {
8597
+ //String texname = Object3D.GetBump(tex);
8598
+
8599
+ CacheTexture texturecache = texturebump.get(tex);
8600
+
8601
+ if (texturecache != null)
8602
+ {
8603
+ tex.bw = texturecache.texturedata.getWidth();
8604
+ tex.bh = texturecache.texturedata.getHeight();
8605
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8606
+ }
8607
+ }
8608
+ }
8609
+
8610
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
83078611 {
83088612 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
83098613
....@@ -8321,21 +8625,21 @@
83218625 return texture!=null?texture.texture:null;
83228626 }
83238627
8324
- public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution)
8628
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
83258629 {
83268630 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
83278631
83288632 return texture!=null?texture.texturedata:null;
83298633 }
83308634
8331
- boolean BindTexture(String tex, boolean bump, int resolution)
8635
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
83328636 {
83338637 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
83348638 {
83358639 return false;
83368640 }
83378641
8338
- boolean newtex = false;
8642
+ //boolean newtex = false;
83398643
83408644 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
83418645
....@@ -8367,9 +8671,75 @@
83678671 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
83688672 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
83698673
8370
- return newtex;
8674
+ return true; // Warning: not used.
83718675 }
83728676
8677
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8678
+ {
8679
+ try
8680
+ {
8681
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8682
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8683
+ ImageWriter writer = writers.next();
8684
+
8685
+ ImageWriteParam param = writer.getDefaultWriteParam();
8686
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8687
+ param.setCompressionQuality(quality);
8688
+
8689
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8690
+ writer.setOutput(ios);
8691
+ writer.write(null, new IIOImage(image, null, null), param);
8692
+
8693
+ byte[] data = baos.toByteArray();
8694
+ writer.dispose();
8695
+ return data;
8696
+ }
8697
+ catch (Exception e)
8698
+ {
8699
+ e.printStackTrace();
8700
+ return null;
8701
+ }
8702
+ }
8703
+
8704
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8705
+ {
8706
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8707
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8708
+ ImageReader reader = writers.next();
8709
+
8710
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8711
+
8712
+ ImageReadParam param = reader.getDefaultReadParam();
8713
+ param.setDestination(bim);
8714
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8715
+
8716
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8717
+ reader.setInput(ios);
8718
+ BufferedImage bim2 = reader.read(0, param);
8719
+ reader.dispose();
8720
+
8721
+// WritableRaster raster = bim2.getRaster();
8722
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8723
+// byte[] bytes = data.getData();
8724
+//
8725
+// int[] pixels = new int[bytes.length/3];
8726
+// for (int i=pixels.length; --i>=0;)
8727
+// {
8728
+// int i3 = i*3;
8729
+// pixels[i] = 0xFF;
8730
+// pixels[i] <<= 8;
8731
+// pixels[i] |= bytes[i3+2] & 0xFF;
8732
+// pixels[i] <<= 8;
8733
+// pixels[i] |= bytes[i3+1] & 0xFF;
8734
+// pixels[i] <<= 8;
8735
+// pixels[i] |= bytes[i3] & 0xFF;
8736
+// }
8737
+//
8738
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8739
+
8740
+ return bim;
8741
+ }
8742
+
83738743 ShadowBuffer shadowPBuf;
83748744 AntialiasBuffer antialiasPBuf;
83758745 int MAXSTACK;
....@@ -9205,11 +9575,35 @@
92059575 jy8[3] = 0.5f;
92069576 }
92079577
9208
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9578
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
92099579 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
92109580 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
92119581 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
92129582
9583
+ void ResetOptions()
9584
+ {
9585
+ options1[0] = 100;
9586
+ options1[1] = 0.025f;
9587
+ options1[2] = 0.01f;
9588
+ options1[3] = 0;
9589
+ options1[4] = 0;
9590
+
9591
+ options2[0] = 0;
9592
+ options2[1] = 0.75f;
9593
+ options2[2] = 0;
9594
+ options2[3] = 0;
9595
+
9596
+ options3[0] = 1;
9597
+ options3[1] = 1;
9598
+ options3[2] = 1;
9599
+ options3[3] = 0;
9600
+
9601
+ options4[0] = 1;
9602
+ options4[1] = 0;
9603
+ options4[2] = 1;
9604
+ options4[3] = 0;
9605
+ }
9606
+
92139607 static int imagecount = 0; // movie generation
92149608
92159609 static int jitter = 0;
....@@ -9305,8 +9699,8 @@
93059699 assert (parentcam != renderCamera);
93069700
93079701 if (renderCamera != lightCamera)
9308
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9309
- LA.matConcat(matrix, parentcam.toParent, matrix);
9702
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9703
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
93109704
93119705 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
93129706
....@@ -9321,8 +9715,8 @@
93219715 LA.matCopy(renderCamera.fromScreen, matrix);
93229716
93239717 if (renderCamera != lightCamera)
9324
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9325
- LA.matConcat(parentcam.fromParent, matrix, matrix);
9718
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9719
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
93269720
93279721 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
93289722
....@@ -9394,7 +9788,7 @@
93949788 //gl.glFlush();
93959789 gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE);
93969790
9397
- if (ANIMATION && ABORTED)
9791
+ if (Globals.ANIMATION && ABORTED)
93989792 {
93999793 System.err.println(" ABORTED FRAME");
94009794 break;
....@@ -9424,7 +9818,7 @@
94249818 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
94259819
94269820 // save image
9427
- if (ANIMATION && !ABORTED)
9821
+ if (Globals.ANIMATION && !ABORTED)
94289822 {
94299823 VPwidth = viewport[2];
94309824 VPheight = viewport[3];
....@@ -9535,11 +9929,11 @@
95359929
95369930 // imagecount++;
95379931
9538
- String fullname = filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
9932
+ String fullname = Globals.filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
95399933
95409934 if (!BOXMODE)
95419935 {
9542
- System.out.println("image: " + fullname + " (wav cursor=" + (GrafreeD.wav.cursor / 735 / 4) + ")");
9936
+ System.out.println("image: " + fullname + " (wav cursor=" + (Grafreed.wav.cursor / 735 / 4) + ")");
95439937 }
95449938
95459939 if (!BOXMODE)
....@@ -9577,7 +9971,7 @@
95779971 ABORTED = false;
95789972 }
95799973 else
9580
- GrafreeD.wav.cursor += 735 * ACSIZE;
9974
+ Grafreed.wav.cursor += 735 * ACSIZE;
95819975
95829976 if (false)
95839977 {
....@@ -10240,11 +10634,11 @@
1024010634
1024110635 public void display(GLAutoDrawable drawable)
1024210636 {
10243
- if (GrafreeD.savesound && GrafreeD.hassound)
10637
+ if (Grafreed.savesound && Grafreed.hassound)
1024410638 {
10245
- GrafreeD.wav.save();
10246
- GrafreeD.savesound = false;
10247
- GrafreeD.hassound = false;
10639
+ Grafreed.wav.save();
10640
+ Grafreed.savesound = false;
10641
+ Grafreed.hassound = false;
1024810642 }
1024910643 // if (DEBUG_SELECTION)
1025010644 // {
....@@ -10320,6 +10714,7 @@
1032010714 ANTIALIAS = 0;
1032110715 //System.out.println("RESTART");
1032210716 AAtimer.restart();
10717
+ Globals.TIMERRUNNING = true;
1032310718 }
1032410719 }
1032510720 }
....@@ -10374,7 +10769,7 @@
1037410769 Object3D theobject = object;
1037510770 Object3D theparent = object.parent;
1037610771 object.parent = null;
10377
- object = (Object3D)GrafreeD.clone(object);
10772
+ object = (Object3D)Grafreed.clone(object);
1037810773 object.Stripify();
1037910774 if (theobject.selection == null || theobject.selection.Size() == 0)
1038010775 theobject.PreprocessOcclusion(this);
....@@ -10387,13 +10782,14 @@
1038710782 ambientOcclusion = false;
1038810783 }
1038910784
10390
- if (Globals.lighttouched && DrawMode() == DEFAULT && !lightMode) // && !FROZEN)
10785
+ if (//Globals.lighttouched &&
10786
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1039110787 {
1039210788 //if (RENDERSHADOW) // ?
1039310789 if (!IsFrozen())
1039410790 {
1039510791 // dec 2012
10396
- if (!ambientOcclusion && !(!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0))
10792
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
1039710793 {
1039810794 Globals.framecount++;
1039910795 shadowbuffer.display();
....@@ -10520,8 +10916,8 @@
1052010916
1052110917 // if (parentcam != renderCamera) // not a light
1052210918 if (cam != lightCamera)
10523
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10524
- LA.matConcat(matrix, parentcam.toParent, matrix);
10919
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10920
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1052510921
1052610922 for (int j = 0; j < 4; j++)
1052710923 {
....@@ -10535,8 +10931,8 @@
1053510931
1053610932 // if (parentcam != renderCamera) // not a light
1053710933 if (cam != lightCamera)
10538
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10539
- LA.matConcat(parentcam.fromParent, matrix, matrix);
10934
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10935
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1054010936
1054110937 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1054210938
....@@ -10795,7 +11191,16 @@
1079511191 // Bump noise
1079611192 gl.glActiveTexture(GL.GL_TEXTURE6);
1079711193 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
10798
- BindTexture(NOISE_TEXTURE, false, 2);
11194
+
11195
+ try
11196
+ {
11197
+ BindTexture(NOISE_TEXTURE, false, 2);
11198
+ }
11199
+ catch (Exception e)
11200
+ {
11201
+ System.err.println("FAILED: " + NOISE_TEXTURE);
11202
+ }
11203
+
1079911204
1080011205 gl.glActiveTexture(GL.GL_TEXTURE0);
1080111206 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -10818,9 +11223,9 @@
1081811223
1081911224 gl.glMatrixMode(GL.GL_MODELVIEW);
1082011225
10821
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10822
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10823
-//gl.glEnable(gl.GL_MULTISAMPLE);
11226
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11227
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11228
+gl.glEnable(gl.GL_MULTISAMPLE);
1082411229 } else
1082511230 {
1082611231 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -10831,7 +11236,7 @@
1083111236 //System.out.println("BLENDING ON");
1083211237 gl.glEnable(GL.GL_BLEND);
1083311238 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
10834
-
11239
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1083511240 gl.glMatrixMode(gl.GL_PROJECTION);
1083611241 gl.glLoadIdentity();
1083711242
....@@ -10920,8 +11325,8 @@
1092011325 System.err.println("parentcam != renderCamera");
1092111326
1092211327 // if (cam != lightCamera)
10923
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10924
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11328
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11329
+ LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
1092511330 }
1092611331
1092711332 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -10942,8 +11347,8 @@
1094211347 if (true) // TODO
1094311348 {
1094411349 if (cam != lightCamera)
10945
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10946
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11350
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11351
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
1094711352 }
1094811353
1094911354 LA.xformPos(light0, cam.toScreen, light0);
....@@ -11080,7 +11485,7 @@
1108011485 }
1108111486 }
1108211487
11083
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11488
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1108411489 {
1108511490 //gl.glDepthFunc(GL.GL_LEQUAL);
1108611491 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11088,24 +11493,21 @@
1108811493
1108911494 boolean texon = textureon;
1109011495
11091
- if (RENDERPROGRAM > 0)
11092
- {
11093
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11094
- textureon = false;
11095
- }
11496
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11497
+ textureon = false;
11498
+
1109611499 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1109711500 //System.out.println("ALLO");
1109811501 gl.glColorMask(false, false, false, false);
1109911502 DrawObject(gl);
11100
- if (RENDERPROGRAM > 0)
11101
- {
11102
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11103
- textureon = texon;
11104
- }
11503
+
11504
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11505
+ textureon = texon;
11506
+
1110511507 gl.glColorMask(true, true, true, true);
1110611508
1110711509 gl.glDepthFunc(GL.GL_EQUAL);
11108
- //gl.glDepthMask(false);
11510
+ gl.glDepthMask(false);
1110911511 }
1111011512
1111111513 if (false) // DrawMode() == SHADOW)
....@@ -11259,8 +11661,14 @@
1125911661 {
1126011662 renderpass++;
1126111663 // System.out.println("Draw object... ");
11664
+ STEP = 1;
1126211665 if (FAST) // in case there is no script
11263
- STEP = 16;
11666
+ STEP = 8;
11667
+
11668
+ if (CURRENTANTIALIAS == 0 || ACSIZE == 1)
11669
+ {
11670
+ STEP *= 4;
11671
+ }
1126411672
1126511673 //object.FullInvariants();
1126611674
....@@ -11274,23 +11682,44 @@
1127411682 e.printStackTrace();
1127511683 }
1127611684
11277
- if (GrafreeD.RENDERME > 0)
11278
- GrafreeD.RENDERME--; // mechante magouille
11685
+ if (Grafreed.RENDERME > 0)
11686
+ Grafreed.RENDERME--; // mechante magouille
1127911687
1128011688 Globals.ONESTEP = false;
1128111689 }
1128211690
1128311691 static boolean zoomonce = false;
1128411692
11693
+ static void CreateSelectedPoint()
11694
+ {
11695
+ if (selectedpoint == null)
11696
+ {
11697
+ debugpointG = new Sphere();
11698
+ debugpointP = new Sphere();
11699
+ debugpointC = new Sphere();
11700
+ debugpointR = new Sphere();
11701
+
11702
+ selectedpoint = new Superellipsoid();
11703
+
11704
+ for (int i=0; i<8; i++)
11705
+ {
11706
+ debugpoints[i] = new Sphere();
11707
+ }
11708
+ }
11709
+ }
11710
+
1128511711 void DrawObject(GL gl, boolean draw)
1128611712 {
11713
+ // To clear camera values
11714
+ ResetOptions();
11715
+
1128711716 //System.out.println("DRAW OBJECT " + mouseDown);
1128811717 // DrawMode() = SELECTION;
1128911718 //GL gl = getGL();
1129011719 if ((TRACK || SHADOWTRACK) || zoomonce)
1129111720 {
1129211721 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11293
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11722
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1129411723 pingthread.StepToTarget(true); // true);
1129511724 // zoomonce = false;
1129611725 }
....@@ -11345,7 +11774,14 @@
1134511774
1134611775 usedtextures.clear();
1134711776
11348
- BindTextures(DEFAULT_TEXTURES, 2);
11777
+ try
11778
+ {
11779
+ BindTextures(DEFAULT_TEXTURES, 2);
11780
+ }
11781
+ catch (Exception e)
11782
+ {
11783
+ System.err.println("FAILED: " + DEFAULT_TEXTURES);
11784
+ }
1134911785 }
1135011786 //System.out.println("--> " + stackdepth);
1135111787 // GrafreeD.traceon();
....@@ -11355,8 +11791,9 @@
1135511791
1135611792 if (DrawMode() == DEFAULT)
1135711793 {
11358
- if (DEBUG)
11794
+ if (Globals.DEBUG)
1135911795 {
11796
+ CreateSelectedPoint();
1136011797 float radius = 0.05f;
1136111798 if (selectedpoint.radius != radius)
1136211799 {
....@@ -11410,20 +11847,32 @@
1141011847 ReleaseTextures(DEFAULT_TEXTURES);
1141111848
1141211849 if (CLEANCACHE)
11413
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11850
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1141411851 {
11415
- String tex = e.nextElement();
11852
+ cTexture tex = e.nextElement();
1141611853
1141711854 // System.out.println("Texture --------- " + tex);
1141811855
11419
- if (tex.equals("WHITE_NOISE"))
11856
+ if (tex.equals("WHITE_NOISE:"))
1142011857 continue;
1142111858
11422
- if (!usedtextures.containsKey(tex))
11859
+ if (!usedtextures.contains(tex))
1142311860 {
11861
+ CacheTexture gettex = texturepigment.get(tex);
1142411862 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11425
- textures.get(tex).texture.dispose();
11426
- textures.remove(tex);
11863
+ if (gettex != null)
11864
+ {
11865
+ gettex.texture.dispose();
11866
+ texturepigment.remove(tex);
11867
+ }
11868
+
11869
+ gettex = texturebump.get(tex);
11870
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11871
+ if (gettex != null)
11872
+ {
11873
+ gettex.texture.dispose();
11874
+ texturebump.remove(tex);
11875
+ }
1142711876 }
1142811877 }
1142911878 }
....@@ -11436,7 +11885,14 @@
1143611885 if (checker != null && DrawMode() == DEFAULT)
1143711886 {
1143811887 //BindTexture(IMMORTAL_TEXTURE);
11439
- BindTextures(checker.GetTextures(), checker.texres);
11888
+ try
11889
+ {
11890
+ BindTextures(checker.GetTextures(), checker.texres);
11891
+ }
11892
+ catch (Exception e)
11893
+ {
11894
+ System.err.println("FAILED: " + checker.GetTextures());
11895
+ }
1144011896 // NEAREST
1144111897 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
1144211898 DrawChecker(gl);
....@@ -11518,7 +11974,7 @@
1151811974 return;
1151911975 }
1152011976
11521
- String string = obj.GetToolTip();
11977
+ String string = obj.toString(); //.GetToolTip();
1152211978
1152311979 GL gl = GetGL();
1152411980
....@@ -11835,8 +12291,8 @@
1183512291 //obj.TransformToWorld(light, light);
1183612292 for (int i = tp.size(); --i >= 0;)
1183712293 {
11838
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
11839
- LA.xformPos(light, tp.get(i).toParent, light);
12294
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12295
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1184012296 }
1184112297
1184212298
....@@ -11853,8 +12309,8 @@
1185312309 parentcam = cameras[0];
1185412310 }
1185512311
11856
- for (int count = parentcam.GetTransformCount(); --count>=0;)
11857
- LA.xformPos(light, parentcam.toParent, light); // may 2013
12312
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
12313
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1185812314
1185912315 LA.xformPos(light, renderCamera.toScreen, light);
1186012316
....@@ -11945,7 +12401,74 @@
1194512401 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1194612402
1194712403 String program =
12404
+ // Min shader
1194812405 "!!ARBfp1.0\n" +
12406
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12407
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12408
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12409
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12410
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12411
+ "PARAM light2cam0 = program.env[10];" +
12412
+ "PARAM light2cam1 = program.env[11];" +
12413
+ "PARAM light2cam2 = program.env[12];" +
12414
+ "TEMP temp;" +
12415
+ "TEMP light;" +
12416
+ "TEMP ndotl;" +
12417
+ "TEMP normal;" +
12418
+ "TEMP depth;" +
12419
+ "TEMP eye;" +
12420
+ "TEMP pos;" +
12421
+
12422
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12423
+ Normalize("normal") +
12424
+ "MOV light, state.light[0].position;" +
12425
+ "DP3 ndotl.x, light, normal;" +
12426
+
12427
+ // shadow
12428
+ "MOV pos, fragment.texcoord[1];" +
12429
+ "MOV temp, pos;" +
12430
+ ShadowTextureFetch("depth", "temp", "1") +
12431
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12432
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12433
+
12434
+ // No shadow when out of frustum
12435
+ //"SGE temp.y, depth.z, zero123.y;" +
12436
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12437
+
12438
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12439
+
12440
+ // Backlit
12441
+ "MOV pos.w, zero123.y;" +
12442
+ "DP4 eye.x, pos, light2cam0;" +
12443
+ "DP4 eye.y, pos, light2cam1;" +
12444
+ "DP4 eye.z, pos, light2cam2;" +
12445
+ Normalize("eye") +
12446
+
12447
+ "DP3 ndotl.y, -eye, normal;" +
12448
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12449
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12450
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12451
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12452
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12453
+
12454
+ "MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12455
+
12456
+ // Pigment
12457
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12458
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12459
+ "MUL temp, temp, ndotl.x;" +
12460
+
12461
+ "MUL temp, temp, zero123.z;" +
12462
+
12463
+ //"MUL temp, temp, ndotl.y;" +
12464
+
12465
+ "MOV temp.w, zero123.y;" + // reset alpha
12466
+ "MOV result.color, temp;" +
12467
+ "END";
12468
+
12469
+ String program2 =
12470
+ "!!ARBfp1.0\n" +
12471
+
1194912472 //"OPTION ARB_fragment_program_shadow;" +
1195012473 "PARAM light2cam0 = program.env[10];" +
1195112474 "PARAM light2cam1 = program.env[11];" +
....@@ -12060,8 +12583,7 @@
1206012583 "TEMP shininess;" +
1206112584 "\n" +
1206212585 "MOV texSamp, one;" +
12063
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12064
-
12586
+
1206512587 "MOV mapgrid.x, one2048th.x;" +
1206612588 "MOV temp, fragment.texcoord[1];" +
1206712589 /*
....@@ -12082,20 +12604,20 @@
1208212604 "MUL temp, floor, mapgrid.x;" +
1208312605 //"TEX depth0, temp, texture[1], 2D;" +
1208412606 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12085
- TextureFetch("depth0", "temp", "1") +
12607
+ ShadowTextureFetch("depth0", "temp", "1") +
1208612608 "") +
1208712609 "ADD temp.x, temp.x, mapgrid.x;" +
1208812610 //"TEX depth1, temp, texture[1], 2D;" +
1208912611 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12090
- TextureFetch("depth1", "temp", "1") +
12612
+ ShadowTextureFetch("depth1", "temp", "1") +
1209112613 "") +
1209212614 "ADD temp.y, temp.y, mapgrid.x;" +
1209312615 //"TEX depth2, temp, texture[1], 2D;" +
12094
- TextureFetch("depth2", "temp", "1") +
12616
+ ShadowTextureFetch("depth2", "temp", "1") +
1209512617 "SUB temp.x, temp.x, mapgrid.x;" +
1209612618 //"TEX depth3, temp, texture[1], 2D;" +
1209712619 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12098
- TextureFetch("depth3", "temp", "1") +
12620
+ ShadowTextureFetch("depth3", "temp", "1") +
1209912621 "") +
1210012622 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1210112623 //"MOV params, material;" +
....@@ -12466,10 +12988,10 @@
1246612988 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1246712989 "") +
1246812990
12469
- // display shadow only (bump == 0)
12991
+ // display shadow only (fakedepth == 0)
1247012992 "SUB temp.x, half.x, shadow.x;" +
12471
- "MOV temp.y, -params6.x;" +
12472
- "SLT temp.z, temp.y, zero.x;" +
12993
+ "MOV temp.y, -params5.z;" + // params6.x;" +
12994
+ "SLT temp.z, temp.y, -one2048th.x;" +
1247312995 "SUB temp.y, one.x, temp.z;" +
1247412996 "MUL temp.x, temp.x, temp.y;" +
1247512997 "KIL temp.x;" +
....@@ -12598,8 +13120,10 @@
1259813120 "MAX ndotl.x, ndotl.x, -ndotl.x;" +
1259913121
1260013122 "SUB temp.x, one.x, ndotl.x;" +
12601
- "ADD temp.x, temp.x, options2.z;" + // lightsheen
12602
- "ADD temp.y, one.y, options2.y;" + // sursurface
13123
+ // Tuning for default skin
13124
+ //"ADD temp.x, temp.x, options2.z;" + // lightsheen
13125
+ "MAD temp.x, options2.z, half.y, temp.x;" + // lightsheen
13126
+ "ADD temp.y, one.y, options2.y;" + // subsurface
1260313127 "MUL temp.x, temp.x, temp.y;" +
1260413128
1260513129 "MUL saturation, saturation, temp.xxxx;" +
....@@ -12747,7 +13271,7 @@
1274713271 "MUL final.y, fragment.texcoord[0].x, c256;" +
1274813272 "FLR final.x, final.y;" +
1274913273 "SUB final.y, final.y, final.x;" +
12750
- //"MUL final.x, final.x, c256i;" +
13274
+ "MUL final.x, final.x, c256i;" +
1275113275 "MOV final.z, zero.x;" +
1275213276 "MOV final.a, one.w;":""
1275313277 ) +
....@@ -12755,7 +13279,7 @@
1275513279 "MUL final.y, fragment.texcoord[0].y, c256;" +
1275613280 "FLR final.x, final.y;" +
1275713281 "SUB final.y, final.y, final.x;" +
12758
- //"MUL final.x, final.x, c256i;" +
13282
+ "MUL final.x, final.x, c256i;" +
1275913283 "MOV final.z, zero.x;" +
1276013284 "MOV final.a, one.w;":""
1276113285 ) +
....@@ -12798,7 +13322,7 @@
1279813322 //once = true;
1279913323 }
1280013324
12801
- System.out.print("Program #" + mode + "; length = " + program.length());
13325
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1280213326 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1280313327 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1280413328
....@@ -12891,25 +13415,26 @@
1289113415 return out;
1289213416 }
1289313417
12894
- String TextureFetch(String dest, String src, String unit)
13418
+ // Also does frustum culling
13419
+ String ShadowTextureFetch(String dest, String src, String unit)
1289513420 {
1289613421 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1289713422 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1289813423 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13424
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13425
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1289913426 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12900
- "SLT " + src + ".z, " + src + ".x, one.x;" +
12901
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12902
- "SLT " + src + ".z, " + src + ".y, one.x;" +
12903
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13427
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13428
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1290413429 //"SWZ buffer, temp, w,w,w,w;";
12905
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13430
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1290613431 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1290713432 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1290813433 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
12909
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13434
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1291013435
12911
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
12912
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13436
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13437
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1291313438 }
1291413439
1291513440 String Shadow(String depth, String shadow)
....@@ -12931,12 +13456,16 @@
1293113456
1293213457 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1293313458 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13459
+
13460
+ // Compare fragment depth in light space with shadowmap.
1293413461 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1293513462 "SGE temp.y, temp.x, zero.x;" +
12936
- "SUB " + shadow + ".y, one.x, temp.y;" +
13463
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13464
+
13465
+ // Reverse comparison
1293713466 "SUB temp.x, one.x, temp.x;" +
1293813467 "MUL " + shadow + ".x, temp.x, temp.y;" +
12939
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13468
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1294013469 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1294113470
1294213471 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -12950,6 +13479,10 @@
1295013479 // No shadow for backface
1295113480 "DP3 temp.x, normal, lightd;" +
1295213481 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13482
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13483
+
13484
+ // No shadow when out of frustum
13485
+ "SGE temp.x, " + depth + ".z, one.z;" +
1295313486 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1295413487 "";
1295513488 }
....@@ -13096,7 +13629,8 @@
1309613629 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1309713630 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1309813631 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13099
- Object3D.cVector2[] vector2buffer;
13632
+
13633
+ //Object3D.cVector2[] vector2buffer;
1310013634
1310113635 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1310213636 // OUT : diff, spec
....@@ -13112,9 +13646,10 @@
1311213646 "DP3 " + dest + ".z," + "normals," + "eye;" +
1311313647 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1311413648 //"MOV " + dest + ".w," + "normal.z;" +
13115
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
13116
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13117
- //"MOV " + dest + ".z," + "params2.w;" +
13649
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13650
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13651
+
13652
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1311813653 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1311913654 "RCP " + dest + ".w," + dest + ".w;" +
1312013655 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13508,7 +14043,7 @@
1350814043 public void mousePressed(MouseEvent e)
1350914044 {
1351014045 //System.out.println("mousePressed: " + e);
13511
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14046
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1351214047 }
1351314048
1351414049 static long prevtime = 0;
....@@ -13584,8 +14119,8 @@
1358414119 // mode |= META;
1358514120 //}
1358614121
13587
- SetMouseMode(WHEEL | e.getModifiersEx());
13588
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14122
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14123
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1358914124 anchorX = ax;
1359014125 anchorY = ay;
1359114126 prevX = px;
....@@ -13619,6 +14154,7 @@
1361914154 else
1362014155 if (evt.getSource() == AAtimer)
1362114156 {
14157
+ Globals.TIMERRUNNING = false;
1362214158 if (mouseDown)
1362314159 {
1362414160 //new Exception().printStackTrace();
....@@ -13644,6 +14180,10 @@
1364414180 // LIVE = waslive;
1364514181 // wasliveok = true;
1364614182 // waslive = false;
14183
+
14184
+ // May 2019 Forget it:
14185
+ if (true)
14186
+ return;
1364714187
1364814188 // source == timer
1364914189 if (mouseDown)
....@@ -13674,7 +14214,7 @@
1367414214
1367514215 // fev 2014???
1367614216 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13677
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14217
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1367814218 pingthread.StepToTarget(true); // true);
1367914219 }
1368014220 // if (!LIVE)
....@@ -13683,12 +14223,13 @@
1368314223
1368414224 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1368514225
13686
- void clickStart(int x, int y, int modifiers)
14226
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1368714227 {
1368814228 if (!wasliveok)
1368914229 return;
1369014230
1369114231 AAtimer.restart(); //
14232
+ Globals.TIMERRUNNING = true;
1369214233
1369314234 // waslive = LIVE;
1369414235 // LIVE = false;
....@@ -13700,7 +14241,7 @@
1370014241 // touched = true; // main DL
1370114242 if (isRenderer)
1370214243 {
13703
- SetMouseMode(modifiers);
14244
+ SetMouseMode(modifiers, modifiersex);
1370414245 }
1370514246
1370614247 selectX = anchorX = x;
....@@ -13713,7 +14254,7 @@
1371314254 clicked = true;
1371414255 hold = false;
1371514256
13716
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14257
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1371714258 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1371814259 {
1371914260 // System.out.println("RESTART II " + modifiers);
....@@ -13738,14 +14279,15 @@
1373814279 drag = false;
1373914280 //System.out.println("Mouse DOWN");
1374014281 editObj = false;
13741
- ClickInfo info = new ClickInfo();
13742
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
13743
- info.pane = this;
13744
- info.camera = renderCamera;
13745
- info.x = x;
13746
- info.y = y;
13747
- info.modifiers = modifiers;
13748
- editObj = object.doEditClick(info, 0);
14282
+ //ClickInfo info = new ClickInfo();
14283
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14284
+ object.clickInfo.pane = this;
14285
+ object.clickInfo.camera = renderCamera;
14286
+ object.clickInfo.x = x;
14287
+ object.clickInfo.y = y;
14288
+ object.clickInfo.modifiers = modifiersex;
14289
+ editObj = object.doEditClick(//info,
14290
+ 0);
1374914291 if (!editObj)
1375014292 {
1375114293 hasMarquee = true;
....@@ -13761,9 +14303,12 @@
1376114303
1376214304 public void mouseDragged(MouseEvent e)
1376314305 {
14306
+ Globals.MOUSEDRAGGED = true;
14307
+
1376414308 //System.out.println("mouseDragged: " + e);
1376514309 if (isRenderer)
1376614310 movingcamera = true;
14311
+
1376714312 //if (drawing)
1376814313 //return;
1376914314 if ((e.getModifiersEx() & CTRL) != 0
....@@ -13773,7 +14318,7 @@
1377314318 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1377414319 }
1377514320 else
13776
- drag(e.getX(), e.getY(), e.getModifiersEx());
14321
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1377714322
1377814323 //try { Thread.sleep(1); } catch (Exception ex) {}
1377914324 }
....@@ -13946,6 +14491,7 @@
1394614491
1394714492 public void run()
1394814493 {
14494
+ new Exception().printStackTrace();
1394914495 System.exit(0);
1395014496 for (;;)
1395114497 {
....@@ -14009,7 +14555,7 @@
1400914555 {
1401014556 Globals.lighttouched = true;
1401114557 }
14012
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14558
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1401314559 }
1401414560 //else
1401514561 }
....@@ -14023,12 +14569,12 @@
1402314569 void GoDown(int mod)
1402414570 {
1402514571 MODIFIERS |= COMMAND;
14026
- /*
14572
+ /**/
1402714573 if((mod&SHIFT) == SHIFT)
1402814574 manipCamera.RotatePosition(0, -speed);
1402914575 else
14030
- manipCamera.BackForth(0, -speed*delta, getWidth());
14031
- */
14576
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14577
+ /**/
1403214578 if ((mod & SHIFT) == SHIFT)
1403314579 {
1403414580 mouseMode = mouseMode; // VR??
....@@ -14044,12 +14590,12 @@
1404414590 void GoUp(int mod)
1404514591 {
1404614592 MODIFIERS |= COMMAND;
14047
- /*
14593
+ /**/
1404814594 if((mod&SHIFT) == SHIFT)
1404914595 manipCamera.RotatePosition(0, speed);
1405014596 else
14051
- manipCamera.BackForth(0, speed*delta, getWidth());
14052
- */
14597
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14598
+ /**/
1405314599 if ((mod & SHIFT) == SHIFT)
1405414600 {
1405514601 mouseMode = mouseMode;
....@@ -14065,12 +14611,12 @@
1406514611 void GoLeft(int mod)
1406614612 {
1406714613 MODIFIERS |= COMMAND;
14068
- /*
14614
+ /**/
1406914615 if((mod&SHIFT) == SHIFT)
14070
- manipCamera.RotatePosition(speed, 0);
14071
- else
1407214616 manipCamera.Translate(speed*delta, 0, getWidth());
14073
- */
14617
+ else
14618
+ manipCamera.RotatePosition(speed, 0);
14619
+ /**/
1407414620 if ((mod & SHIFT) == SHIFT)
1407514621 {
1407614622 mouseMode = mouseMode;
....@@ -14086,12 +14632,12 @@
1408614632 void GoRight(int mod)
1408714633 {
1408814634 MODIFIERS |= COMMAND;
14089
- /*
14635
+ /**/
1409014636 if((mod&SHIFT) == SHIFT)
14091
- manipCamera.RotatePosition(-speed, 0);
14092
- else
1409314637 manipCamera.Translate(-speed*delta, 0, getWidth());
14094
- */
14638
+ else
14639
+ manipCamera.RotatePosition(-speed, 0);
14640
+ /**/
1409514641 if ((mod & SHIFT) == SHIFT)
1409614642 {
1409714643 mouseMode = mouseMode;
....@@ -14109,7 +14655,7 @@
1410914655 int X, Y;
1411014656 boolean SX, SY;
1411114657
14112
- void drag(int x, int y, int modifiers)
14658
+ void drag(int x, int y, int modifiers, int modifiersex)
1411314659 {
1411414660 if (IsFrozen())
1411514661 {
....@@ -14118,17 +14664,17 @@
1411814664
1411914665 drag = true; // NEW
1412014666
14121
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14667
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1412214668
1412314669 X = x;
1412414670 Y = y;
1412514671 // floating state for animation
14126
- MODIFIERS = modifiers;
14127
- modifiers &= ~1024;
14672
+ MODIFIERS = modifiersex;
14673
+ modifiersex &= ~1024;
1412814674 if (false) // modifiers != 0)
1412914675 {
1413014676 //new Exception().printStackTrace();
14131
- System.out.println("mouseDragged: " + modifiers);
14677
+ System.out.println("mouseDragged: " + modifiersex);
1413214678 System.out.println("SHIFT = " + SHIFT);
1413314679 System.out.println("CONTROL = " + COMMAND);
1413414680 System.out.println("META = " + META);
....@@ -14141,14 +14687,16 @@
1414114687 if (editObj)
1414214688 {
1414314689 drag = true;
14144
- ClickInfo info = new ClickInfo();
14145
- info.bounds.setBounds(0, 0,
14690
+ //ClickInfo info = new ClickInfo();
14691
+ object.clickInfo.bounds.setBounds(0, 0,
1414614692 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14147
- info.pane = this;
14148
- info.camera = renderCamera;
14149
- info.x = x;
14150
- info.y = y;
14151
- object.editWindow.copy.doEditDrag(info);
14693
+ object.clickInfo.pane = this;
14694
+ object.clickInfo.camera = renderCamera;
14695
+ object.clickInfo.x = x;
14696
+ object.clickInfo.y = y;
14697
+ object //.GetWindow().copy
14698
+ .doEditDrag(//info,
14699
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1415214700 } else
1415314701 {
1415414702 if (x < startX)
....@@ -14297,22 +14845,27 @@
1429714845 }
1429814846 }
1429914847
14848
+// ClickInfo clickInfo = new ClickInfo();
14849
+
1430014850 public void mouseMoved(MouseEvent e)
1430114851 {
1430214852 //System.out.println("mouseMoved: " + e);
1430314853 if (isRenderer)
1430414854 return;
1430514855
14306
- ClickInfo ci = new ClickInfo();
14307
- ci.x = e.getX();
14308
- ci.y = e.getY();
14309
- ci.modifiers = e.getModifiersEx();
14310
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14311
- ci.pane = this;
14312
- ci.camera = renderCamera;
14856
+ // Mouse cursor feedback
14857
+ object.clickInfo.x = e.getX();
14858
+ object.clickInfo.y = e.getY();
14859
+ object.clickInfo.modifiers = e.getModifiersEx();
14860
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14861
+ object.clickInfo.pane = this;
14862
+ object.clickInfo.camera = renderCamera;
1431314863 if (!isRenderer)
1431414864 {
14315
- if (object.editWindow.copy.doEditClick(ci, 0))
14865
+ //ObjEditor editWindow = object.editWindow;
14866
+ //Object3D copy = editWindow.copy;
14867
+ if (object.doEditClick(//clickInfo,
14868
+ 0))
1431614869 {
1431714870 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1431814871 } else
....@@ -14324,7 +14877,11 @@
1432414877
1432514878 public void mouseReleased(MouseEvent e)
1432614879 {
14880
+ Globals.MOUSEDRAGGED = false;
14881
+
1432714882 movingcamera = false;
14883
+ X = 0; // getBounds().width/2;
14884
+ Y = 0; // getBounds().height/2;
1432814885 //System.out.println("mouseReleased: " + e);
1432914886 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1433014887 }
....@@ -14347,9 +14904,9 @@
1434714904 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1434814905 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1434914906
14350
- if (control || command || IsFrozen())
14907
+// No delay if (control || command || IsFrozen())
1435114908 timeout = true;
14352
- else
14909
+// ?? May 2019 else
1435314910 // timer.setDelay((modifiers & 128) != 0?0:350);
1435414911 mouseDown = false;
1435514912 if (!control && !command) // june 2013
....@@ -14459,7 +15016,7 @@
1445915016 System.out.println("keyReleased: " + e);
1446015017 }
1446115018
14462
- void SetMouseMode(int modifiers)
15019
+ void SetMouseMode(int modifiers, int modifiersex)
1446315020 {
1446415021 //System.out.println("SetMouseMode = " + modifiers);
1446515022 //modifiers &= ~1024;
....@@ -14471,25 +15028,25 @@
1447115028 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1447215029 // return;
1447315030 //System.out.println("SetMode = " + modifiers);
14474
- if ((modifiers & WHEEL) == WHEEL)
15031
+ if ((modifiersex & WHEEL) == WHEEL)
1447515032 {
1447615033 mouseMode |= ZOOM;
1447715034 }
1447815035
1447915036 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
14480
- if (capsLocked || (modifiers & META) == META)
15037
+ if (capsLocked) // || (modifiers & META) == META)
1448115038 {
1448215039 mouseMode |= VR; // BACKFORTH;
1448315040 }
14484
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
15041
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1448515042 {
1448615043 mouseMode |= SELECT;
1448715044 }
14488
- if ((modifiers & COMMAND) == COMMAND)
15045
+ if ((modifiersex & COMMAND) == COMMAND)
1448915046 {
1449015047 mouseMode |= SELECT;
1449115048 }
14492
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15049
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
1449315050 {
1449415051 mouseMode &= ~VR;
1449515052 mouseMode |= TRANSLATE;
....@@ -14518,7 +15075,7 @@
1451815075
1451915076 if (isRenderer) //
1452015077 {
14521
- SetMouseMode(modifiers);
15078
+ SetMouseMode(0, modifiers);
1452215079 }
1452315080
1452415081 Globals.theRenderer.keyPressed(key);
....@@ -14580,7 +15137,8 @@
1458015137 // break;
1458115138 case 'T':
1458215139 CACHETEXTURE ^= true;
14583
- textures.clear();
15140
+ texturepigment.clear();
15141
+ texturebump.clear();
1458415142 // repaint();
1458515143 break;
1458615144 case 'Y':
....@@ -14665,7 +15223,9 @@
1466515223 case 'E' : COMPACT ^= true;
1466615224 repaint();
1466715225 break;
14668
- case 'W' : DEBUGHSB ^= true;
15226
+ case 'W' : // Wide Window (fullscreen)
15227
+ //DEBUGHSB ^= true;
15228
+ ObjEditor.theFrame.ToggleFullScreen();
1466915229 repaint();
1467015230 break;
1467115231 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14690,8 +15250,8 @@
1469015250 RevertCamera();
1469115251 repaint();
1469215252 break;
14693
- case 'L':
1469415253 case 'l':
15254
+ //case 'L':
1469515255 if (lightMode)
1469615256 {
1469715257 lightMode = false;
....@@ -14834,9 +15394,9 @@
1483415394 case '_':
1483515395 kompactbit = 5;
1483615396 break;
14837
- case '+':
14838
- kompactbit = 6;
14839
- break;
15397
+// case '+':
15398
+// kompactbit = 6;
15399
+// break;
1484015400 case ' ':
1484115401 lightMode ^= true;
1484215402 Globals.lighttouched = true;
....@@ -14848,13 +15408,14 @@
1484815408 case ESC:
1484915409 RENDERPROGRAM += 1;
1485015410 RENDERPROGRAM %= 3;
15411
+
1485115412 repaint();
1485215413 break;
1485315414 case 'Z':
1485415415 //RESIZETEXTURE ^= true;
1485515416 //break;
1485615417 case 'z':
14857
- RENDERSHADOW ^= true;
15418
+ Globals.RENDERSHADOW ^= true;
1485815419 Globals.lighttouched = true;
1485915420 repaint();
1486015421 break;
....@@ -14887,8 +15448,9 @@
1488715448 case DELETE:
1488815449 ClearSelection();
1488915450 break;
14890
- /*
1489115451 case '+':
15452
+
15453
+ /*
1489215454 //fontsize += 1;
1489315455 bbzoom *= 2;
1489415456 repaint();
....@@ -14905,17 +15467,17 @@
1490515467 case '=':
1490615468 IncDepth();
1490715469 //fontsize += 1;
14908
- object.editWindow.refreshContents(true);
15470
+ object.GetWindow().refreshContents(true);
1490915471 maskbit = 6;
1491015472 break;
1491115473 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1491215474 DecDepth();
1491315475 maskbit = 5;
1491415476 //if(fontsize > 1) fontsize -= 1;
14915
- if (object.editWindow == null)
14916
- new Exception().printStackTrace();
14917
- else
14918
- object.editWindow.refreshContents(true);
15477
+// if (object.editWindow == null)
15478
+// new Exception().printStackTrace();
15479
+// else
15480
+ object.GetWindow().refreshContents(true);
1491915481 break;
1492015482 case '{':
1492115483 manipCamera.shaper_fovy /= 1.1;
....@@ -14978,7 +15540,7 @@
1497815540 //mode = ROTATE;
1497915541 if ((MODIFIERS & COMMAND) == 0) // VR??
1498015542 {
14981
- SetMouseMode(modifiers);
15543
+ SetMouseMode(0, modifiers);
1498215544 }
1498315545 }
1498415546
....@@ -15114,7 +15676,7 @@
1511415676 {
1511515677 //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
1511615678 //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15117
- if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (mouseMode & SELECT) == 0)
15679
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1511815680 {
1511915681 mouseMoved(e);
1512015682 } else
....@@ -15139,11 +15701,12 @@
1513915701 }
1514015702 */
1514115703
15142
- object.editWindow.EditSelection();
15704
+ object.GetWindow().EditSelection(false);
1514315705 }
1514415706
1514515707 void SelectParent()
1514615708 {
15709
+ new Exception().printStackTrace();
1514715710 System.exit(0);
1514815711 Composite group = (Composite) object;
1514915712 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -15155,10 +15718,10 @@
1515515718 {
1515615719 //selectees.remove(i);
1515715720 System.out.println("select parent of " + elem);
15158
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15721
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1515915722 } else
1516015723 {
15161
- group.editWindow.Select(elem.GetTreePath(), first, true);
15724
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1516215725 }
1516315726
1516415727 first = false;
....@@ -15167,6 +15730,7 @@
1516715730
1516815731 void SelectChildren()
1516915732 {
15733
+ new Exception().printStackTrace();
1517015734 System.exit(0);
1517115735 /*
1517215736 Composite group = (Composite) object;
....@@ -15199,12 +15763,12 @@
1519915763 for (int j = 0; j < group.children.size(); j++)
1520015764 {
1520115765 elem = (Object3D) group.children.elementAt(j);
15202
- object.editWindow.Select(elem.GetTreePath(), first, true);
15766
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1520315767 first = false;
1520415768 }
1520515769 } else
1520615770 {
15207
- object.editWindow.Select(elem.GetTreePath(), first, true);
15771
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1520815772 }
1520915773
1521015774 first = false;
....@@ -15215,21 +15779,21 @@
1521515779 {
1521615780 //Composite group = (Composite) object;
1521715781 Object3D group = object;
15218
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15782
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1521915783 }
1522015784
1522115785 void ResetTransform(int mask)
1522215786 {
1522315787 //Composite group = (Composite) object;
1522415788 Object3D group = object;
15225
- group.editWindow.ResetTransform(mask);
15789
+ group.GetWindow().ResetTransform(mask);
1522615790 }
1522715791
1522815792 void FlipTransform()
1522915793 {
1523015794 //Composite group = (Composite) object;
1523115795 Object3D group = object;
15232
- group.editWindow.FlipTransform();
15796
+ group.GetWindow().FlipTransform();
1523315797 // group.editWindow.ReduceMesh(true);
1523415798 }
1523515799
....@@ -15237,7 +15801,7 @@
1523715801 {
1523815802 //Composite group = (Composite) object;
1523915803 Object3D group = object;
15240
- group.editWindow.PrintMemory();
15804
+ group.GetWindow().PrintMemory();
1524115805 // group.editWindow.ReduceMesh(true);
1524215806 }
1524315807
....@@ -15245,7 +15809,7 @@
1524515809 {
1524615810 //Composite group = (Composite) object;
1524715811 Object3D group = object;
15248
- group.editWindow.ResetCentroid();
15812
+ group.GetWindow().ResetCentroid();
1524915813 }
1525015814
1525115815 void IncDepth()
....@@ -15327,11 +15891,11 @@
1532715891
1532815892 int width = getBounds().width;
1532915893 int height = getBounds().height;
15330
- ClickInfo info = new ClickInfo();
15331
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1533215894 //Image img = CreateImage(width, height);
1533315895 //System.out.println("width = " + width + "; height = " + height + "\n");
15896
+
1533415897 Graphics gr = g; // img.getGraphics();
15898
+
1533515899 if (!hasMarquee)
1533615900 {
1533715901 if (Xmin < Xmax) // !locked)
....@@ -15403,40 +15967,88 @@
1540315967 }
1540415968 if (object != null && !hasMarquee)
1540515969 {
15970
+ if (object.clickInfo == null)
15971
+ object.clickInfo = new ClickInfo();
15972
+ ClickInfo info = object.clickInfo;
15973
+ //ClickInfo info = new ClickInfo();
15974
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
15975
+
1540615976 if (isRenderer)
1540715977 {
15408
- info.flags++;
15978
+ object.clickInfo.flags++;
1540915979 double frameAspect = (double) width / (double) height;
1541015980 if (frameAspect > renderCamera.aspect)
1541115981 {
1541215982 int desired = (int) ((double) height * renderCamera.aspect);
15413
- info.bounds.width -= width - desired;
15414
- info.bounds.x += (width - desired) / 2;
15983
+ object.clickInfo.bounds.width -= width - desired;
15984
+ object.clickInfo.bounds.x += (width - desired) / 2;
1541515985 } else
1541615986 {
1541715987 int desired = (int) ((double) width / renderCamera.aspect);
15418
- info.bounds.height -= height - desired;
15419
- info.bounds.y += (height - desired) / 2;
15988
+ object.clickInfo.bounds.height -= height - desired;
15989
+ object.clickInfo.bounds.y += (height - desired) / 2;
1542015990 }
1542115991 }
15422
- info.g = gr;
15423
- info.camera = renderCamera;
15992
+
15993
+ object.clickInfo.g = gr;
15994
+ object.clickInfo.camera = renderCamera;
1542415995 /*
1542515996 // Memory intensive (brep.verticescopy)
1542615997 if (!(object instanceof Composite))
1542715998 object.draw(info, 0, false); // SLOW :
1542815999 */
15429
- if (!isRenderer)
16000
+ if (!isRenderer) // && drag)
1543016001 {
15431
- object.drawEditHandles(info, 0);
16002
+ Grafreed.Assert(object != null);
16003
+ Grafreed.Assert(object.selection != null);
16004
+ if (object.selection.Size() > 0)
16005
+ {
16006
+ int hitSomething = object.selection.get(0).hitSomething;
16007
+
16008
+ object.clickInfo.DX = 0;
16009
+ object.clickInfo.DY = 0;
16010
+ object.clickInfo.W = 1;
16011
+ if (hitSomething == Object3D.hitCenter)
16012
+ {
16013
+ info.DX = X;
16014
+ if (X != 0)
16015
+ info.DX -= info.bounds.width/2;
16016
+
16017
+ info.DY = Y;
16018
+ if (Y != 0)
16019
+ info.DY -= info.bounds.height/2;
16020
+ }
16021
+
16022
+ object.drawEditHandles(//info,
16023
+ 0);
16024
+
16025
+ if (drag && (X != 0 || Y != 0))
16026
+ {
16027
+ switch (hitSomething)
16028
+ {
16029
+ case Object3D.hitCenter: gr.setColor(Color.pink);
16030
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16031
+ break;
16032
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16033
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16034
+ break;
16035
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16036
+ gr.drawLine(X, Y, 0, 0);
16037
+ break;
16038
+ }
16039
+
16040
+ }
16041
+ }
1543216042 }
1543316043 }
16044
+
1543416045 if (isRenderer)
1543516046 {
1543616047 //gr.setColor(Color.black);
1543716048 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1543816049 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1543916050 }
16051
+
1544016052 if (hasMarquee)
1544116053 {
1544216054 gr.setXORMode(Color.white);
....@@ -15549,6 +16161,7 @@
1554916161 public boolean mouseDown(Event evt, int x, int y)
1555016162 {
1555116163 System.out.println("mouseDown: " + evt);
16164
+ System.exit(0);
1555216165 /*
1555316166 locked = true;
1555416167 drag = false;
....@@ -15592,7 +16205,7 @@
1559216205 {
1559316206 keyPressed(0, modifiers);
1559416207 }
15595
- clickStart(x, y, modifiers);
16208
+ // clickStart(x, y, modifiers);
1559616209 return true;
1559716210 }
1559816211
....@@ -15710,7 +16323,7 @@
1571016323 {
1571116324 keyReleased(0, 0);
1571216325 }
15713
- drag(x, y, modifiers);
16326
+ drag(x, y, 0, modifiers);
1571416327 return true;
1571516328 }
1571616329
....@@ -15842,7 +16455,7 @@
1584216455 Object3D object;
1584316456 static Object3D trackedobject;
1584416457 Camera renderCamera; // Light or Eye (or Occlusion)
15845
- /*static*/ Camera manipCamera; // Light or Eye
16458
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1584616459 /*static*/ Camera eyeCamera;
1584716460 /*static*/ Camera lightCamera;
1584816461 int cameracount;
....@@ -16127,16 +16740,16 @@
1612716740 cStatic.objectstack[materialdepth++] = checker;
1612816741 //System.out.println("material " + material);
1612916742 //Applet3D.tracein(this, selected);
16130
- vector2buffer = checker.projectedVertices;
16743
+ //vector2buffer = checker.projectedVertices;
1613116744
1613216745 //checker.GetMaterial().Draw(this, false); // true);
16133
- DrawMaterial(checker.GetMaterial(), false); // true);
16746
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1613416747
1613516748 materialdepth -= 1;
1613616749 if (materialdepth > 0)
1613716750 {
16138
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16139
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
16751
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16752
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1614016753 }
1614116754 //checker.GetMaterial().opacity = 1f;
1614216755 ////checker.GetMaterial().ambient = 1f;
....@@ -16222,6 +16835,14 @@
1622216835 }
1622316836 }
1622416837
16838
+ private Object3D GetFolder()
16839
+ {
16840
+ Object3D folder = object.GetWindow().copy;
16841
+ if (object.GetWindow().copy.selection.Size() > 0)
16842
+ folder = object.GetWindow().copy.selection.elementAt(0);
16843
+ return folder;
16844
+ }
16845
+
1622516846 class SelectBuffer implements GLEventListener
1622616847 {
1622716848
....@@ -16280,6 +16901,7 @@
1628016901 {
1628116902 if (!selection)
1628216903 {
16904
+ new Exception().printStackTrace();
1628316905 System.exit(0);
1628416906 return;
1628516907 }
....@@ -16300,6 +16922,17 @@
1630016922
1630116923 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1630216924
16925
+ if (PAINTMODE)
16926
+ {
16927
+ if (object.GetWindow().copy.selection.Size() > 0)
16928
+ {
16929
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16930
+
16931
+ // Make what you paint not selectable.
16932
+ paintobj.ResetSelectable();
16933
+ }
16934
+ }
16935
+
1630316936 //int tmp = selection_view;
1630416937 //selection_view = -1;
1630516938 int temp = DrawMode();
....@@ -16311,6 +16944,17 @@
1631116944 // temp = DEFAULT; // patch for selection debug
1631216945 Globals.drawMode = temp; // WARNING
1631316946
16947
+ if (PAINTMODE)
16948
+ {
16949
+ if (object.GetWindow().copy.selection.Size() > 0)
16950
+ {
16951
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16952
+
16953
+ // Revert.
16954
+ paintobj.RestoreSelectable();
16955
+ }
16956
+ }
16957
+
1631416958 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1631516959
1631616960 // trying different ways of getting the depth info over
....@@ -16358,6 +17002,8 @@
1635817002 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1635917003 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1636017004 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
17005
+
17006
+ CreateSelectedPoint();
1636117007
1636217008 // Will fit the mesh !!!
1636317009 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16407,34 +17053,36 @@
1640717053 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]));
1640817054 }
1640917055
16410
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
17056
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1641117057 }
1641217058 }
1641317059
1641417060 if (!movingcamera && !PAINTMODE)
16415
- object.editWindow.ScreenFitPoint(); // fev 2014
17061
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1641617062
16417
- if (PAINTMODE && GrafreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17063
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1641817064 {
16419
- Object3D paintobj = GrafreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17065
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1642017066
16421
- Object3D group = new Object3D("inst" + paintcount++);
17067
+ if (object.GetWindow().copy.selection.Size() > 0)
17068
+ {
17069
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1642217070
16423
- group.CreateMaterial(); // use a void leaf to select instances
16424
-
16425
- group.add(paintobj); // link
16426
-
16427
- object.editWindow.SnapObject(group);
16428
-
16429
- Object3D folder = object.editWindow.copy;
16430
-
16431
- if (object.editWindow.copy.selection.Size() > 0)
16432
- folder = object.editWindow.copy.selection.elementAt(0);
16433
-
16434
- folder.add(group);
16435
-
16436
- object.editWindow.ResetModel();
16437
- object.editWindow.refreshContents();
17071
+ Object3D inst = new Object3D("inst" + paintcount++);
17072
+
17073
+ inst.CreateMaterial(); // use a void leaf to select instances
17074
+
17075
+ inst.add(paintobj); // link
17076
+
17077
+ object.GetWindow().SnapObject(inst);
17078
+
17079
+ Object3D folder = paintFolder; // GetFolder();
17080
+
17081
+ folder.add(inst);
17082
+
17083
+ object.GetWindow().ResetModel();
17084
+ object.GetWindow().refreshContents();
17085
+ }
1643817086 }
1643917087 else
1644017088 paintcount = 0;
....@@ -16473,6 +17121,11 @@
1647317121 //System.out.println("objects[color] = " + objects[color]);
1647417122 //objects[color].Select();
1647517123 indexcount = 0;
17124
+ ObjEditor window = object.GetWindow();
17125
+ if (window != null && deselect)
17126
+ {
17127
+ window.Select(null, deselect, true);
17128
+ }
1647617129 object.Select(color, deselect);
1647717130 }
1647817131
....@@ -16572,7 +17225,7 @@
1657217225 gl.glDisable(gl.GL_CULL_FACE);
1657317226 }
1657417227
16575
- if (!RENDERSHADOW)
17228
+ if (!Globals.RENDERSHADOW)
1657617229 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1657717230
1657817231 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -16582,7 +17235,7 @@
1658217235 //gl.glColorMask(false, false, false, false);
1658317236
1658417237 //render_scene_from_light_view(gl, drawable, 0, 0);
16585
- if (RENDERSHADOW && Globals.lighttouched && !movingcamera) // && !parent.IsFreezed())
17238
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1658617239 {
1658717240 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1658817241
....@@ -16998,23 +17651,15 @@
1699817651 int AAbuffersize = 0;
1699917652
1700017653 //double[] selectedpoint = new double[3];
17001
- static Superellipsoid selectedpoint = new Superellipsoid();
17654
+ static Superellipsoid selectedpoint;
1700217655 static Sphere previousselectedpoint = null;
17003
- static Sphere debugpointG = new Sphere();
17004
- static Sphere debugpointP = new Sphere();
17005
- static Sphere debugpointC = new Sphere();
17006
- static Sphere debugpointR = new Sphere();
17656
+ static Sphere debugpointG;
17657
+ static Sphere debugpointP;
17658
+ static Sphere debugpointC;
17659
+ static Sphere debugpointR;
1700717660
1700817661 static Sphere debugpoints[] = new Sphere[8];
1700917662
17010
- static
17011
- {
17012
- for (int i=0; i<8; i++)
17013
- {
17014
- debugpoints[i] = new Sphere();
17015
- }
17016
- }
17017
-
1701817663 static void InitPoints(float radius)
1701917664 {
1702017665 for (int i=0; i<8; i++)