Normand Briere
2019-07-23 5140c320d8addf4bd8dcaa7f350b6accdc4ffbaf
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
....@@ -151,6 +185,8 @@
151185 defaultcaps.setAccumBlueBits(16);
152186 defaultcaps.setAccumAlphaBits(16);
153187 }
188
+
189
+ private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
154190
155191 void SetAsGLRenderer(boolean b)
156192 {
....@@ -327,7 +363,7 @@
327363 cStatic.objectstack[materialdepth++] = obj;
328364 //System.out.println("material " + material);
329365 //Applet3D.tracein(this, selected);
330
- display.vector2buffer = obj.projectedVertices;
366
+ //display.vector2buffer = obj.projectedVertices;
331367 if (obj instanceof Camera)
332368 {
333369 display.options1[0] = material.shift;
....@@ -336,14 +372,28 @@
336372 display.options1[2] = material.shadowbias;
337373 display.options1[3] = material.aniso;
338374 display.options1[4] = material.anisoV;
375
+// System.out.println("display.options1[0] " + display.options1[0]);
376
+// System.out.println("display.options1[1] " + display.options1[1]);
377
+// System.out.println("display.options1[2] " + display.options1[2]);
378
+// System.out.println("display.options1[3] " + display.options1[3]);
379
+// System.out.println("display.options1[4] " + display.options1[4]);
339380 display.options2[0] = material.opacity;
340381 display.options2[1] = material.diffuse;
341382 display.options2[2] = material.factor;
383
+// System.out.println("display.options2[0] " + display.options2[0]);
384
+// System.out.println("display.options2[1] " + display.options2[1]);
385
+// System.out.println("display.options2[2] " + display.options2[2]);
342386
343387 cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
388
+// System.out.println("display.options3[0] " + display.options3[0]);
389
+// System.out.println("display.options3[1] " + display.options3[1]);
390
+// System.out.println("display.options3[2] " + display.options3[2]);
344391 display.options4[0] = material.cameralight/0.2f;
345392 display.options4[1] = material.subsurface;
346393 display.options4[2] = material.sheen;
394
+// System.out.println("display.options4[0] " + display.options4[0]);
395
+// System.out.println("display.options4[1] " + display.options4[1]);
396
+// System.out.println("display.options4[2] " + display.options4[2]);
347397
348398 // if (display.CURRENTANTIALIAS > 0)
349399 // display.options3[3] /= 4;
....@@ -359,7 +409,7 @@
359409 /**/
360410 } else
361411 {
362
- DrawMaterial(material, selected);
412
+ DrawMaterial(material, selected, obj.projectedVertices);
363413 }
364414 } else
365415 {
....@@ -383,8 +433,8 @@
383433 cStatic.objectstack[materialdepth++] = obj;
384434 //System.out.println("material " + material);
385435 //Applet3D.tracein("selected ", selected);
386
- display.vector2buffer = obj.projectedVertices;
387
- display.DrawMaterial(material, selected);
436
+ //display.vector2buffer = obj.projectedVertices;
437
+ display.DrawMaterial(material, selected, obj.projectedVertices);
388438 }
389439 }
390440
....@@ -401,8 +451,8 @@
401451 materialdepth -= 1;
402452 if (materialdepth > 0)
403453 {
404
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
405
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
454
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
455
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
406456 }
407457 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
408458 } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
....@@ -422,8 +472,8 @@
422472 materialdepth -= 1;
423473 if (materialdepth > 0)
424474 {
425
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
426
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
475
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
476
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
427477 }
428478 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
429479 //else
....@@ -464,10 +514,12 @@
464514 if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
465515 {
466516 //gl.glBegin(gl.GL_TRIANGLES);
467
- boolean hasnorm = pv.norm != null; // && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0);
517
+ boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0)
518
+ // TEST LIVE NORMALS && !obj.dontselect
519
+ ;
468520 if (!hasnorm)
469521 {
470
- // System.out.println("FUCK!!");
522
+ // System.out.println("Mesh normal");
471523 LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
472524 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
473525 LA.vecCross(obj.v0, obj.v1, obj.v2);
....@@ -1192,10 +1244,12 @@
11921244 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
11931245 }
11941246 }
1247
+
11951248 if (flipV)
11961249 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
11971250 else
11981251 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1252
+
11991253 //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
12001254 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
12011255
....@@ -1215,10 +1269,12 @@
12151269 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
12161270 }
12171271 }
1272
+
12181273 if (flipV)
12191274 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12201275 else
12211276 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1277
+
12221278 //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
12231279 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
12241280
....@@ -1246,8 +1302,10 @@
12461302 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12471303 else
12481304 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1305
+
12491306 //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
12501307 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1308
+
12511309 count2 += 2;
12521310 count3 += 3;
12531311 }
....@@ -1603,7 +1661,7 @@
16031661 // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
16041662 }
16051663
1606
- void DrawMaterial(cMaterial material, boolean selected)
1664
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
16071665 {
16081666 CameraPane display = this;
16091667 //new Exception().printStackTrace();
....@@ -1630,7 +1688,7 @@
16301688
16311689 cColor.HSBtoRGB(display.color, display.saturation, 1, display.modelParams0);
16321690
1633
- float[] colorV = GrafreeD.colorV;
1691
+ float[] colorV = Grafreed.colorV;
16341692
16351693 /**/
16361694 if (display.DrawMode() == display.DEFAULT) // && display.RENDERPROGRAM == 0)
....@@ -1638,7 +1696,7 @@
16381696 colorV[0] = display.modelParams0[0] * material.diffuse;
16391697 colorV[1] = display.modelParams0[1] * material.diffuse;
16401698 colorV[2] = display.modelParams0[2] * material.diffuse;
1641
- colorV[3] = material.opacity;
1699
+ colorV[3] = 1; // material.opacity;
16421700
16431701 gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
16441702 //System.out.println("Opacity = " + opacity);
....@@ -1746,9 +1804,9 @@
17461804 display.modelParams7[2] = 0;
17471805 display.modelParams7[3] = 0;
17481806
1749
- display.modelParams6[0] = 100; // criss de bug de bump
1807
+ //display.modelParams6[0] = 100; // criss de bug de bump
17501808
1751
- Object3D.cVector2[] extparams = display.vector2buffer;
1809
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
17521810 if (extparams != null && extparams.length > 0 && extparams[0] != null)
17531811 {
17541812 display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
....@@ -1890,7 +1948,7 @@
18901948 void PushMatrix(double[][] matrix)
18911949 {
18921950 // GrafreeD.tracein(matrix);
1893
- PushMatrix(matrix,1);
1951
+ PushMatrix(matrix, 1);
18941952 }
18951953
18961954 void PushMatrix()
....@@ -2044,7 +2102,7 @@
20442102 //System.err.println("Oeil on");
20452103 OEIL = true;
20462104 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2047
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2105
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
20482106 //pingthread.StepToTarget(true);
20492107 }
20502108
....@@ -2142,7 +2200,7 @@
21422200 System.err.println("LIVE = " + Globals.isLIVE());
21432201
21442202 if (!Globals.isLIVE()) // save sound
2145
- GrafreeD.savesound = true; // wav.save();
2203
+ Grafreed.savesound = true; // wav.save();
21462204 // else
21472205 repaint(); // start loop // may 2013
21482206 }
....@@ -2259,7 +2317,7 @@
22592317
22602318 void ToggleDebug()
22612319 {
2262
- DEBUG ^= true;
2320
+ Globals.DEBUG ^= true;
22632321 }
22642322
22652323 void ToggleLookAt()
....@@ -2267,9 +2325,9 @@
22672325 LOOKAT ^= true;
22682326 }
22692327
2270
- void ToggleRandom()
2328
+ void ToggleSwitch()
22712329 {
2272
- RANDOM ^= true;
2330
+ SWITCH ^= true;
22732331 }
22742332
22752333 void ToggleHandles()
....@@ -2277,10 +2335,17 @@
22772335 HANDLES ^= true;
22782336 }
22792337
2338
+ Object3D paintFolder;
2339
+
22802340 void TogglePaint()
22812341 {
22822342 PAINTMODE ^= true;
22832343 paintcount = 0;
2344
+
2345
+ if (PAINTMODE)
2346
+ {
2347
+ paintFolder = GetFolder();
2348
+ }
22842349 }
22852350
22862351 void SwapCamera(int a, int b)
....@@ -2376,7 +2441,22 @@
23762441 {
23772442 return currentGL;
23782443 }
2379
-
2444
+
2445
+ static private BufferedImage CreateBim(TextureData texturedata)
2446
+ {
2447
+ Grafreed.Assert(texturedata != null);
2448
+
2449
+ int width = texturedata.getWidth();
2450
+ int height = texturedata.getHeight();
2451
+
2452
+ Buffer buffer = texturedata.getBuffer();
2453
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2454
+
2455
+ byte[] bytes = bytebuf.array();
2456
+
2457
+ return CreateBim(bytes, width, height);
2458
+ }
2459
+
23802460 /**/
23812461 class CacheTexture
23822462 {
....@@ -2385,28 +2465,31 @@
23852465
23862466 int resolution;
23872467
2388
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2468
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
23892469 {
2390
- texture = tex;
2470
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2471
+ texturedata = texdata;
23912472 resolution = res;
23922473 }
23932474 }
23942475 /**/
23952476
23962477 // 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>();
2478
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2479
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2480
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2481
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2482
+
24002483 int pigmentdepth = 0;
24012484 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
24022485 int bumpdepth = 0;
24032486 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
24042487 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
24052488 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2406
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2489
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
24072490 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
24082491
2409
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2492
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
24102493 {
24112494 TextureData texturedata = null;
24122495
....@@ -2425,13 +2508,34 @@
24252508 if (bump)
24262509 texturedata = ConvertBump(texturedata, false);
24272510
2428
- com.sun.opengl.util.texture.Texture texture =
2429
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2511
+// com.sun.opengl.util.texture.Texture texture =
2512
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
24302513
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);
2514
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2515
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
24332516
2434
- return texture;
2517
+ return texturedata;
2518
+ }
2519
+
2520
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2521
+ {
2522
+ TextureData texturedata = null;
2523
+
2524
+ try
2525
+ {
2526
+ texturedata =
2527
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2528
+ bim,
2529
+ true);
2530
+ } catch (Exception e)
2531
+ {
2532
+ throw new javax.media.opengl.GLException(e);
2533
+ }
2534
+
2535
+ if (bump)
2536
+ texturedata = ConvertBump(texturedata, false);
2537
+
2538
+ return texturedata;
24352539 }
24362540
24372541 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3504,6 +3608,8 @@
35043608
35053609 System.out.println("LOADING TEXTURE : " + name);
35063610
3611
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3612
+
35073613 //
35083614 if (false) // compressbit > 0)
35093615 {
....@@ -4208,6 +4314,7 @@
42084314
42094315 com.sun.opengl.util.texture.Texture CompressTexture2(String name)
42104316 {
4317
+ new Exception().printStackTrace();
42114318 System.exit(0);
42124319 com.sun.opengl.util.texture.Texture texture = null;
42134320
....@@ -7901,7 +8008,7 @@
79018008 String pigment = Object3D.GetPigment(tex);
79028009 String bump = Object3D.GetBump(tex);
79038010
7904
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8011
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79058012 {
79068013 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79078014 // System.out.println("; bump = " + bump);
....@@ -7916,11 +8023,69 @@
79168023 pigment = null;
79178024 }
79188025
7919
- ReleaseTexture(bump, true);
7920
- ReleaseTexture(pigment, false);
8026
+ ReleaseTexture(tex, true);
8027
+ ReleaseTexture(tex, false);
79218028 }
79228029
7923
- void ReleaseTexture(String tex, boolean bump)
8030
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
8031
+ {
8032
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8033
+ {
8034
+ return;
8035
+ }
8036
+
8037
+ if (tex == null)
8038
+ {
8039
+ ReleaseTexture(null, false);
8040
+ return;
8041
+ }
8042
+
8043
+ String pigment = Object3D.GetPigment(tex);
8044
+
8045
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8046
+ {
8047
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8048
+ // System.out.println("; bump = " + bump);
8049
+ }
8050
+
8051
+ if (pigment.equals(""))
8052
+ {
8053
+ pigment = null;
8054
+ }
8055
+
8056
+ ReleaseTexture(tex, false);
8057
+ }
8058
+
8059
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
8060
+ {
8061
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8062
+ {
8063
+ return;
8064
+ }
8065
+
8066
+ if (tex == null)
8067
+ {
8068
+ ReleaseTexture(null, true);
8069
+ return;
8070
+ }
8071
+
8072
+ String bump = Object3D.GetBump(tex);
8073
+
8074
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8075
+ {
8076
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8077
+ // System.out.println("; bump = " + bump);
8078
+ }
8079
+
8080
+ if (bump.equals(""))
8081
+ {
8082
+ bump = null;
8083
+ }
8084
+
8085
+ ReleaseTexture(tex, true);
8086
+ }
8087
+
8088
+ void ReleaseTexture(cTexture tex, boolean bump)
79248089 {
79258090 if (// DrawMode() != 0 || /*tex == null ||*/
79268091 ambientOcclusion ) // || !textureon)
....@@ -7931,7 +8096,7 @@
79318096 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
79328097
79338098 if (tex != null)
7934
- texture = textures.get(tex);
8099
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
79358100
79368101 // //assert( texture != null );
79378102 // if (texture == null)
....@@ -8023,7 +8188,55 @@
80238188 }
80248189 }
80258190
8026
- /*boolean*/ public void BindTextures(cTexture tex, int resolution) // INTERFACE
8191
+ /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
8192
+ {
8193
+// if (// DrawMode() != 0 || /*tex == null ||*/
8194
+// ambientOcclusion ) // || !textureon)
8195
+// {
8196
+// return; // false;
8197
+// }
8198
+//
8199
+// if (tex == null)
8200
+// {
8201
+// BindTexture(null,false,resolution);
8202
+// BindTexture(null,true,resolution);
8203
+// return;
8204
+// }
8205
+//
8206
+// String pigment = Object3D.GetPigment(tex);
8207
+// String bump = Object3D.GetBump(tex);
8208
+//
8209
+// usedtextures.add(pigment);
8210
+// usedtextures.add(bump);
8211
+//
8212
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8213
+// {
8214
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8215
+// // System.out.println("; bump = " + bump);
8216
+// }
8217
+//
8218
+// if (bump.equals(""))
8219
+// {
8220
+// bump = null;
8221
+// }
8222
+// if (pigment.equals(""))
8223
+// {
8224
+// pigment = null;
8225
+// }
8226
+//
8227
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8228
+// BindTexture(pigment, false, resolution);
8229
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8230
+// BindTexture(bump, true, resolution);
8231
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8232
+//
8233
+// return; // true;
8234
+
8235
+ BindPigmentTexture(tex, resolution);
8236
+ BindBumpTexture(tex, resolution);
8237
+ }
8238
+
8239
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
80278240 {
80288241 if (// DrawMode() != 0 || /*tex == null ||*/
80298242 ambientOcclusion ) // || !textureon)
....@@ -8034,17 +8247,47 @@
80348247 if (tex == null)
80358248 {
80368249 BindTexture(null,false,resolution);
8037
- BindTexture(null,true,resolution);
80388250 return;
80398251 }
80408252
80418253 String pigment = Object3D.GetPigment(tex);
8254
+
8255
+ usedtextures.add(tex);
8256
+
8257
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8258
+ {
8259
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8260
+ // System.out.println("; bump = " + bump);
8261
+ }
8262
+
8263
+ if (pigment.equals(""))
8264
+ {
8265
+ pigment = null;
8266
+ }
8267
+
8268
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8269
+ BindTexture(tex, false, resolution);
8270
+ }
8271
+
8272
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8273
+ {
8274
+ if (// DrawMode() != 0 || /*tex == null ||*/
8275
+ ambientOcclusion ) // || !textureon)
8276
+ {
8277
+ return; // false;
8278
+ }
8279
+
8280
+ if (tex == null)
8281
+ {
8282
+ BindTexture(null,true,resolution);
8283
+ return;
8284
+ }
8285
+
80428286 String bump = Object3D.GetBump(tex);
80438287
8044
- usedtextures.put(pigment, pigment);
8045
- usedtextures.put(bump, bump);
8288
+ usedtextures.add(tex);
80468289
8047
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8290
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
80488291 {
80498292 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
80508293 // System.out.println("; bump = " + bump);
....@@ -8054,43 +8297,94 @@
80548297 {
80558298 bump = null;
80568299 }
8057
- if (pigment.equals(""))
8058
- {
8059
- pigment = null;
8060
- }
80618300
8062
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8063
- BindTexture(pigment, false, resolution);
80648301 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8065
- BindTexture(bump, true, resolution);
8302
+ BindTexture(tex, true, resolution);
80668303 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8067
-
8068
- return; // true;
80698304 }
80708305
8071
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution)
8306
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8307
+
8308
+ private boolean FileExists(String tex)
80728309 {
8073
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8310
+ if (missingTextures.contains(tex))
8311
+ {
8312
+ return false;
8313
+ }
8314
+
8315
+ boolean fileExists = new File(tex).exists();
8316
+
8317
+ if (!fileExists)
8318
+ {
8319
+ // If file exists, the "new File()" is not executed sgain
8320
+ missingTextures.add(tex);
8321
+ }
8322
+
8323
+ return fileExists;
8324
+ }
8325
+
8326
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
8327
+ {
8328
+ CacheTexture texturecache = null;
80748329
80758330 if (tex != null)
80768331 {
8077
- String texname = tex;
8332
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8333
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
80788334
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;
8335
+ if (texname.equals("") && texdata == null)
8336
+ {
8337
+ return null;
8338
+ }
8339
+
8340
+ String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
8341
+
8342
+// String[] split = tex.split("Textures");
8343
+// if (split.length > 1)
8344
+// texname = "/Users/nbriere/Textures" + split[split.length-1];
8345
+// else
8346
+// if (!texname.startsWith("/"))
8347
+// texname = "/Users/nbriere/Textures/" + texname;
8348
+ if (!FileExists(texname))
8349
+ {
8350
+ texname = fallbackTextureName;
8351
+ }
80858352
80868353 if (CACHETEXTURE)
8087
- texture = textures.get(texname); // TEXTURE CACHE
8088
-
8089
- TextureData texturedata = null;
8090
-
8091
- if (texture == null || texture.resolution < resolution)
80928354 {
8093
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8355
+ if (texdata == null)
8356
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8357
+ else
8358
+ texturecache = bimtextures.get(texdata);
8359
+ }
8360
+
8361
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8362
+ {
8363
+ TextureData texturedata = null;
8364
+
8365
+ if (texdata != null && textureon)
8366
+ {
8367
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8368
+
8369
+ try
8370
+ {
8371
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8372
+ }
8373
+ catch (Exception e)
8374
+ {
8375
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8376
+ }
8377
+
8378
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8379
+ bimtextures.put(texdata, texturecache);
8380
+
8381
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8382
+
8383
+ //Object bim2 = CreateBim(texturecache.texturedata);
8384
+ //bim2 = bim;
8385
+ }
8386
+ else
8387
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
80948388 {
80958389 assert(!bump);
80968390 // if (bump)
....@@ -8101,19 +8395,23 @@
81018395 // }
81028396 // else
81038397 // {
8104
- texture = textures.get(tex);
8105
- if (texture == null)
8398
+ // texturecache = textures.get(texname); // suspicious
8399
+ if (texturecache == null)
81068400 {
8107
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8401
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
81088402 }
8403
+ else
8404
+ new Exception().printStackTrace();
81098405 // }
81108406 } else
8111
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8407
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
81128408 {
81138409 assert(bump);
8114
- texture = textures.get(tex);
8115
- if (texture == null)
8116
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8410
+ // texturecache = textures.get(texname); // suspicious
8411
+ if (texturecache == null)
8412
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8413
+ else
8414
+ new Exception().printStackTrace();
81178415 } else
81188416 {
81198417 //if (tex.equals("IMMORTAL"))
....@@ -8121,11 +8419,13 @@
81218419 // texture = GetResourceTexture("default.png");
81228420 //} else
81238421 //{
8124
- if (tex.equals("WHITE_NOISE"))
8422
+ if (texname.endsWith("WHITE_NOISE"))
81258423 {
8126
- texture = textures.get(tex);
8127
- if (texture == null)
8128
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8424
+ // texturecache = textures.get(texname); // suspicious
8425
+ if (texturecache == null)
8426
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8427
+ else
8428
+ new Exception().printStackTrace();
81298429 } else
81308430 {
81318431 if (textureon)
....@@ -8150,7 +8450,7 @@
81508450 }
81518451
81528452 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
8153
- if (!new File(cachename).exists())
8453
+ if (!FileExists(cachename))
81548454 cachename = texname;
81558455 else
81568456 processbump = false; // don't process bump map again
....@@ -8172,7 +8472,7 @@
81728472 }
81738473
81748474 cachename = texname.substring(0, texname.length()-4)+ext+".png";
8175
- if (!new File(cachename).exists())
8475
+ if (!FileExists(cachename))
81768476 cachename = texname;
81778477 else
81788478 processbump = false; // don't process bump map again
....@@ -8181,20 +8481,22 @@
81818481 texturedata = GetFileTexture(cachename, processbump, resolution);
81828482
81838483
8184
- if (texturedata != null)
8185
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8484
+ if (texturedata == null)
8485
+ throw new Exception();
8486
+
8487
+ texturecache = new CacheTexture(texturedata,resolution);
81868488 //texture = GetTexture(tex, bump);
81878489 }
81888490 }
81898491 //}
81908492 }
81918493
8192
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8494
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
81938495 {
81948496 //return false;
81958497
81968498 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8197
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8499
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
81988500 {
81998501 // String ext = "_highres";
82008502 // if (REDUCETEXTURE)
....@@ -8211,52 +8513,17 @@
82118513 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
82128514 if (!cachefile.exists())
82138515 {
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))
8516
+ //if (texturedata.getWidth() == texturedata.getHeight())
82238517 {
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);
8518
+ BufferedImage rendImage = CreateBim(texturedata);
8519
+
82548520 ImageWriter writer = null;
82558521 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
82568522 if (iter.hasNext()) {
82578523 writer = (ImageWriter)iter.next();
82588524 }
8259
- float compressionQuality = 0.9f;
8525
+
8526
+ float compressionQuality = 0.85f;
82608527 try
82618528 {
82628529 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8273,18 +8540,20 @@
82738540 }
82748541 }
82758542 }
8276
-
8543
+
8544
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8545
+
82778546 //System.out.println("Texture = " + tex);
8278
- if (textures.containsKey(texname))
8547
+ if (textures.containsKey(tex))
82798548 {
8280
- CacheTexture thetex = textures.get(texname);
8549
+ CacheTexture thetex = textures.get(tex);
82818550 thetex.texture.disable();
82828551 thetex.texture.dispose();
8283
- textures.remove(texname);
8552
+ textures.remove(tex);
82848553 }
82858554
8286
- texture.texturedata = texturedata;
8287
- textures.put(texname, texture);
8555
+ //texture.texturedata = texturedata;
8556
+ textures.put(tex, texturecache);
82888557
82898558 // newtex = true;
82908559 }
....@@ -8300,10 +8569,44 @@
83008569 }
83018570 }
83028571
8303
- return texture;
8572
+ return texturecache;
83048573 }
83058574
8306
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution)
8575
+ static void EmbedTextures(cTexture tex)
8576
+ {
8577
+ if (tex.pigmentdata == null)
8578
+ {
8579
+ //String texname = Object3D.GetPigment(tex);
8580
+
8581
+ CacheTexture texturecache = texturepigment.get(tex);
8582
+
8583
+ if (texturecache != null)
8584
+ {
8585
+ tex.pw = texturecache.texturedata.getWidth();
8586
+ tex.ph = texturecache.texturedata.getHeight();
8587
+ tex.pigmentdata = //CompressJPEG(CreateBim
8588
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8589
+ ;
8590
+ //, tex.pw, tex.ph), 0.5f);
8591
+ }
8592
+ }
8593
+
8594
+ if (tex.bumpdata == null)
8595
+ {
8596
+ //String texname = Object3D.GetBump(tex);
8597
+
8598
+ CacheTexture texturecache = texturebump.get(tex);
8599
+
8600
+ if (texturecache != null)
8601
+ {
8602
+ tex.bw = texturecache.texturedata.getWidth();
8603
+ tex.bh = texturecache.texturedata.getHeight();
8604
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8605
+ }
8606
+ }
8607
+ }
8608
+
8609
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
83078610 {
83088611 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
83098612
....@@ -8321,21 +8624,21 @@
83218624 return texture!=null?texture.texture:null;
83228625 }
83238626
8324
- public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution)
8627
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
83258628 {
83268629 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
83278630
83288631 return texture!=null?texture.texturedata:null;
83298632 }
83308633
8331
- boolean BindTexture(String tex, boolean bump, int resolution)
8634
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
83328635 {
83338636 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
83348637 {
83358638 return false;
83368639 }
83378640
8338
- boolean newtex = false;
8641
+ //boolean newtex = false;
83398642
83408643 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
83418644
....@@ -8367,9 +8670,75 @@
83678670 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
83688671 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
83698672
8370
- return newtex;
8673
+ return true; // Warning: not used.
83718674 }
83728675
8676
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8677
+ {
8678
+ try
8679
+ {
8680
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8681
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8682
+ ImageWriter writer = writers.next();
8683
+
8684
+ ImageWriteParam param = writer.getDefaultWriteParam();
8685
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8686
+ param.setCompressionQuality(quality);
8687
+
8688
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8689
+ writer.setOutput(ios);
8690
+ writer.write(null, new IIOImage(image, null, null), param);
8691
+
8692
+ byte[] data = baos.toByteArray();
8693
+ writer.dispose();
8694
+ return data;
8695
+ }
8696
+ catch (Exception e)
8697
+ {
8698
+ e.printStackTrace();
8699
+ return null;
8700
+ }
8701
+ }
8702
+
8703
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8704
+ {
8705
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8706
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8707
+ ImageReader reader = writers.next();
8708
+
8709
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8710
+
8711
+ ImageReadParam param = reader.getDefaultReadParam();
8712
+ param.setDestination(bim);
8713
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8714
+
8715
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8716
+ reader.setInput(ios);
8717
+ BufferedImage bim2 = reader.read(0, param);
8718
+ reader.dispose();
8719
+
8720
+// WritableRaster raster = bim2.getRaster();
8721
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8722
+// byte[] bytes = data.getData();
8723
+//
8724
+// int[] pixels = new int[bytes.length/3];
8725
+// for (int i=pixels.length; --i>=0;)
8726
+// {
8727
+// int i3 = i*3;
8728
+// pixels[i] = 0xFF;
8729
+// pixels[i] <<= 8;
8730
+// pixels[i] |= bytes[i3+2] & 0xFF;
8731
+// pixels[i] <<= 8;
8732
+// pixels[i] |= bytes[i3+1] & 0xFF;
8733
+// pixels[i] <<= 8;
8734
+// pixels[i] |= bytes[i3] & 0xFF;
8735
+// }
8736
+//
8737
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8738
+
8739
+ return bim;
8740
+ }
8741
+
83738742 ShadowBuffer shadowPBuf;
83748743 AntialiasBuffer antialiasPBuf;
83758744 int MAXSTACK;
....@@ -9205,11 +9574,35 @@
92059574 jy8[3] = 0.5f;
92069575 }
92079576
9208
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9577
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
92099578 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
92109579 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
92119580 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
92129581
9582
+ void ResetOptions()
9583
+ {
9584
+ options1[0] = 100;
9585
+ options1[1] = 0.025f;
9586
+ options1[2] = 0.01f;
9587
+ options1[3] = 0;
9588
+ options1[4] = 0;
9589
+
9590
+ options2[0] = 0;
9591
+ options2[1] = 0.75f;
9592
+ options2[2] = 0;
9593
+ options2[3] = 0;
9594
+
9595
+ options3[0] = 1;
9596
+ options3[1] = 1;
9597
+ options3[2] = 1;
9598
+ options3[3] = 0;
9599
+
9600
+ options4[0] = 1;
9601
+ options4[1] = 0;
9602
+ options4[2] = 1;
9603
+ options4[3] = 0;
9604
+ }
9605
+
92139606 static int imagecount = 0; // movie generation
92149607
92159608 static int jitter = 0;
....@@ -9305,8 +9698,8 @@
93059698 assert (parentcam != renderCamera);
93069699
93079700 if (renderCamera != lightCamera)
9308
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9309
- LA.matConcat(matrix, parentcam.toParent, matrix);
9701
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9702
+ LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
93109703
93119704 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
93129705
....@@ -9321,8 +9714,8 @@
93219714 LA.matCopy(renderCamera.fromScreen, matrix);
93229715
93239716 if (renderCamera != lightCamera)
9324
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9325
- LA.matConcat(parentcam.fromParent, matrix, matrix);
9717
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9718
+ LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
93269719
93279720 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
93289721
....@@ -9394,7 +9787,7 @@
93949787 //gl.glFlush();
93959788 gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE);
93969789
9397
- if (ANIMATION && ABORTED)
9790
+ if (Globals.ANIMATION && ABORTED)
93989791 {
93999792 System.err.println(" ABORTED FRAME");
94009793 break;
....@@ -9424,7 +9817,7 @@
94249817 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
94259818
94269819 // save image
9427
- if (ANIMATION && !ABORTED)
9820
+ if (Globals.ANIMATION && !ABORTED)
94289821 {
94299822 VPwidth = viewport[2];
94309823 VPheight = viewport[3];
....@@ -9535,11 +9928,11 @@
95359928
95369929 // imagecount++;
95379930
9538
- String fullname = filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
9931
+ String fullname = Globals.filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
95399932
95409933 if (!BOXMODE)
95419934 {
9542
- System.out.println("image: " + fullname + " (wav cursor=" + (GrafreeD.wav.cursor / 735 / 4) + ")");
9935
+ System.out.println("image: " + fullname + " (wav cursor=" + (Grafreed.wav.cursor / 735 / 4) + ")");
95439936 }
95449937
95459938 if (!BOXMODE)
....@@ -9577,7 +9970,7 @@
95779970 ABORTED = false;
95789971 }
95799972 else
9580
- GrafreeD.wav.cursor += 735 * ACSIZE;
9973
+ Grafreed.wav.cursor += 735 * ACSIZE;
95819974
95829975 if (false)
95839976 {
....@@ -10240,11 +10633,11 @@
1024010633
1024110634 public void display(GLAutoDrawable drawable)
1024210635 {
10243
- if (GrafreeD.savesound && GrafreeD.hassound)
10636
+ if (Grafreed.savesound && Grafreed.hassound)
1024410637 {
10245
- GrafreeD.wav.save();
10246
- GrafreeD.savesound = false;
10247
- GrafreeD.hassound = false;
10638
+ Grafreed.wav.save();
10639
+ Grafreed.savesound = false;
10640
+ Grafreed.hassound = false;
1024810641 }
1024910642 // if (DEBUG_SELECTION)
1025010643 // {
....@@ -10320,6 +10713,7 @@
1032010713 ANTIALIAS = 0;
1032110714 //System.out.println("RESTART");
1032210715 AAtimer.restart();
10716
+ Globals.TIMERRUNNING = true;
1032310717 }
1032410718 }
1032510719 }
....@@ -10374,7 +10768,7 @@
1037410768 Object3D theobject = object;
1037510769 Object3D theparent = object.parent;
1037610770 object.parent = null;
10377
- object = (Object3D)GrafreeD.clone(object);
10771
+ object = (Object3D)Grafreed.clone(object);
1037810772 object.Stripify();
1037910773 if (theobject.selection == null || theobject.selection.Size() == 0)
1038010774 theobject.PreprocessOcclusion(this);
....@@ -10387,13 +10781,14 @@
1038710781 ambientOcclusion = false;
1038810782 }
1038910783
10390
- if (Globals.lighttouched && DrawMode() == DEFAULT && !lightMode) // && !FROZEN)
10784
+ if (//Globals.lighttouched &&
10785
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1039110786 {
1039210787 //if (RENDERSHADOW) // ?
1039310788 if (!IsFrozen())
1039410789 {
1039510790 // dec 2012
10396
- if (!ambientOcclusion && !(!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0))
10791
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
1039710792 {
1039810793 Globals.framecount++;
1039910794 shadowbuffer.display();
....@@ -10520,8 +10915,8 @@
1052010915
1052110916 // if (parentcam != renderCamera) // not a light
1052210917 if (cam != lightCamera)
10523
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10524
- LA.matConcat(matrix, parentcam.toParent, matrix);
10918
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10919
+ LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
1052510920
1052610921 for (int j = 0; j < 4; j++)
1052710922 {
....@@ -10535,8 +10930,8 @@
1053510930
1053610931 // if (parentcam != renderCamera) // not a light
1053710932 if (cam != lightCamera)
10538
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10539
- LA.matConcat(parentcam.fromParent, matrix, matrix);
10933
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10934
+ LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
1054010935
1054110936 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1054210937
....@@ -10795,7 +11190,16 @@
1079511190 // Bump noise
1079611191 gl.glActiveTexture(GL.GL_TEXTURE6);
1079711192 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
10798
- BindTexture(NOISE_TEXTURE, false, 2);
11193
+
11194
+ try
11195
+ {
11196
+ BindTexture(NOISE_TEXTURE, false, 2);
11197
+ }
11198
+ catch (Exception e)
11199
+ {
11200
+ System.err.println("FAILED: " + NOISE_TEXTURE);
11201
+ }
11202
+
1079911203
1080011204 gl.glActiveTexture(GL.GL_TEXTURE0);
1080111205 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -10818,9 +11222,9 @@
1081811222
1081911223 gl.glMatrixMode(GL.GL_MODELVIEW);
1082011224
10821
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10822
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10823
-//gl.glEnable(gl.GL_MULTISAMPLE);
11225
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11226
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11227
+gl.glEnable(gl.GL_MULTISAMPLE);
1082411228 } else
1082511229 {
1082611230 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -10831,7 +11235,7 @@
1083111235 //System.out.println("BLENDING ON");
1083211236 gl.glEnable(GL.GL_BLEND);
1083311237 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
10834
-
11238
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1083511239 gl.glMatrixMode(gl.GL_PROJECTION);
1083611240 gl.glLoadIdentity();
1083711241
....@@ -10920,8 +11324,8 @@
1092011324 System.err.println("parentcam != renderCamera");
1092111325
1092211326 // if (cam != lightCamera)
10923
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10924
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11327
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11328
+ LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
1092511329 }
1092611330
1092711331 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -10942,8 +11346,8 @@
1094211346 if (true) // TODO
1094311347 {
1094411348 if (cam != lightCamera)
10945
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10946
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11349
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11350
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
1094711351 }
1094811352
1094911353 LA.xformPos(light0, cam.toScreen, light0);
....@@ -11080,7 +11484,7 @@
1108011484 }
1108111485 }
1108211486
11083
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11487
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1108411488 {
1108511489 //gl.glDepthFunc(GL.GL_LEQUAL);
1108611490 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11088,24 +11492,21 @@
1108811492
1108911493 boolean texon = textureon;
1109011494
11091
- if (RENDERPROGRAM > 0)
11092
- {
11093
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11094
- textureon = false;
11095
- }
11495
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11496
+ textureon = false;
11497
+
1109611498 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1109711499 //System.out.println("ALLO");
1109811500 gl.glColorMask(false, false, false, false);
1109911501 DrawObject(gl);
11100
- if (RENDERPROGRAM > 0)
11101
- {
11102
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11103
- textureon = texon;
11104
- }
11502
+
11503
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11504
+ textureon = texon;
11505
+
1110511506 gl.glColorMask(true, true, true, true);
1110611507
1110711508 gl.glDepthFunc(GL.GL_EQUAL);
11108
- //gl.glDepthMask(false);
11509
+ gl.glDepthMask(false);
1110911510 }
1111011511
1111111512 if (false) // DrawMode() == SHADOW)
....@@ -11259,8 +11660,14 @@
1125911660 {
1126011661 renderpass++;
1126111662 // System.out.println("Draw object... ");
11663
+ STEP = 1;
1126211664 if (FAST) // in case there is no script
11263
- STEP = 16;
11665
+ STEP = 8;
11666
+
11667
+ if (CURRENTANTIALIAS == 0 || ACSIZE == 1)
11668
+ {
11669
+ STEP *= 4;
11670
+ }
1126411671
1126511672 //object.FullInvariants();
1126611673
....@@ -11274,23 +11681,44 @@
1127411681 e.printStackTrace();
1127511682 }
1127611683
11277
- if (GrafreeD.RENDERME > 0)
11278
- GrafreeD.RENDERME--; // mechante magouille
11684
+ if (Grafreed.RENDERME > 0)
11685
+ Grafreed.RENDERME--; // mechante magouille
1127911686
1128011687 Globals.ONESTEP = false;
1128111688 }
1128211689
1128311690 static boolean zoomonce = false;
1128411691
11692
+ static void CreateSelectedPoint()
11693
+ {
11694
+ if (selectedpoint == null)
11695
+ {
11696
+ debugpointG = new Sphere();
11697
+ debugpointP = new Sphere();
11698
+ debugpointC = new Sphere();
11699
+ debugpointR = new Sphere();
11700
+
11701
+ selectedpoint = new Superellipsoid();
11702
+
11703
+ for (int i=0; i<8; i++)
11704
+ {
11705
+ debugpoints[i] = new Sphere();
11706
+ }
11707
+ }
11708
+ }
11709
+
1128511710 void DrawObject(GL gl, boolean draw)
1128611711 {
11712
+ // To clear camera values
11713
+ ResetOptions();
11714
+
1128711715 //System.out.println("DRAW OBJECT " + mouseDown);
1128811716 // DrawMode() = SELECTION;
1128911717 //GL gl = getGL();
1129011718 if ((TRACK || SHADOWTRACK) || zoomonce)
1129111719 {
1129211720 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11293
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11721
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1129411722 pingthread.StepToTarget(true); // true);
1129511723 // zoomonce = false;
1129611724 }
....@@ -11345,7 +11773,14 @@
1134511773
1134611774 usedtextures.clear();
1134711775
11348
- BindTextures(DEFAULT_TEXTURES, 2);
11776
+ try
11777
+ {
11778
+ BindTextures(DEFAULT_TEXTURES, 2);
11779
+ }
11780
+ catch (Exception e)
11781
+ {
11782
+ System.err.println("FAILED: " + DEFAULT_TEXTURES);
11783
+ }
1134911784 }
1135011785 //System.out.println("--> " + stackdepth);
1135111786 // GrafreeD.traceon();
....@@ -11355,8 +11790,9 @@
1135511790
1135611791 if (DrawMode() == DEFAULT)
1135711792 {
11358
- if (DEBUG)
11793
+ if (Globals.DEBUG)
1135911794 {
11795
+ CreateSelectedPoint();
1136011796 float radius = 0.05f;
1136111797 if (selectedpoint.radius != radius)
1136211798 {
....@@ -11410,20 +11846,32 @@
1141011846 ReleaseTextures(DEFAULT_TEXTURES);
1141111847
1141211848 if (CLEANCACHE)
11413
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11849
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1141411850 {
11415
- String tex = e.nextElement();
11851
+ cTexture tex = e.nextElement();
1141611852
1141711853 // System.out.println("Texture --------- " + tex);
1141811854
11419
- if (tex.equals("WHITE_NOISE"))
11855
+ if (tex.equals("WHITE_NOISE:"))
1142011856 continue;
1142111857
11422
- if (!usedtextures.containsKey(tex))
11858
+ if (!usedtextures.contains(tex))
1142311859 {
11860
+ CacheTexture gettex = texturepigment.get(tex);
1142411861 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11425
- textures.get(tex).texture.dispose();
11426
- textures.remove(tex);
11862
+ if (gettex != null)
11863
+ {
11864
+ gettex.texture.dispose();
11865
+ texturepigment.remove(tex);
11866
+ }
11867
+
11868
+ gettex = texturebump.get(tex);
11869
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11870
+ if (gettex != null)
11871
+ {
11872
+ gettex.texture.dispose();
11873
+ texturebump.remove(tex);
11874
+ }
1142711875 }
1142811876 }
1142911877 }
....@@ -11436,7 +11884,14 @@
1143611884 if (checker != null && DrawMode() == DEFAULT)
1143711885 {
1143811886 //BindTexture(IMMORTAL_TEXTURE);
11439
- BindTextures(checker.GetTextures(), checker.texres);
11887
+ try
11888
+ {
11889
+ BindTextures(checker.GetTextures(), checker.texres);
11890
+ }
11891
+ catch (Exception e)
11892
+ {
11893
+ System.err.println("FAILED: " + checker.GetTextures());
11894
+ }
1144011895 // NEAREST
1144111896 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
1144211897 DrawChecker(gl);
....@@ -11518,7 +11973,7 @@
1151811973 return;
1151911974 }
1152011975
11521
- String string = obj.GetToolTip();
11976
+ String string = obj.toString(); //.GetToolTip();
1152211977
1152311978 GL gl = GetGL();
1152411979
....@@ -11835,8 +12290,8 @@
1183512290 //obj.TransformToWorld(light, light);
1183612291 for (int i = tp.size(); --i >= 0;)
1183712292 {
11838
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
11839
- LA.xformPos(light, tp.get(i).toParent, light);
12293
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12294
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1184012295 }
1184112296
1184212297
....@@ -11853,8 +12308,8 @@
1185312308 parentcam = cameras[0];
1185412309 }
1185512310
11856
- for (int count = parentcam.GetTransformCount(); --count>=0;)
11857
- LA.xformPos(light, parentcam.toParent, light); // may 2013
12311
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
12312
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1185812313
1185912314 LA.xformPos(light, renderCamera.toScreen, light);
1186012315
....@@ -11945,7 +12400,52 @@
1194512400 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1194612401
1194712402 String program =
12403
+ // Min shader
1194812404 "!!ARBfp1.0\n" +
12405
+ "PARAM zero123 = { 0.0, 1.0, 2.0, 1.25 };" +
12406
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12407
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12408
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12409
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12410
+ "TEMP temp;" +
12411
+ "TEMP light;" +
12412
+ "TEMP ndotl;" +
12413
+ "TEMP normal;" +
12414
+ "TEMP depth;" +
12415
+
12416
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12417
+
12418
+ "MOV light, state.light[0].position;" +
12419
+ "DP3 ndotl.x, light, normal;" +
12420
+
12421
+ // shadow
12422
+ "MOV temp, fragment.texcoord[1];" +
12423
+ TextureFetch("depth", "temp", "1") +
12424
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12425
+ "SLT temp.x, fragment.texcoord[1].z, depth.z;" +
12426
+
12427
+
12428
+ // No shadow when out of frustum
12429
+ //"SGE temp.y, depth.z, zero123.y;" +
12430
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12431
+
12432
+ "MUL ndotl.x, ndotl.x, temp.x;" +
12433
+ "MAX ndotl.x, ndotl.x, pow2.y;" +
12434
+
12435
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12436
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12437
+ "MUL temp, temp, ndotl.x;" +
12438
+
12439
+ "MUL temp, temp, zero123.z;" +
12440
+
12441
+ "MOV temp.w, zero123.y;" + // reset alpha
12442
+
12443
+ "MOV result.color, temp;" +
12444
+ "END";
12445
+
12446
+ String program2 =
12447
+ "!!ARBfp1.0\n" +
12448
+
1194912449 //"OPTION ARB_fragment_program_shadow;" +
1195012450 "PARAM light2cam0 = program.env[10];" +
1195112451 "PARAM light2cam1 = program.env[11];" +
....@@ -12060,8 +12560,7 @@
1206012560 "TEMP shininess;" +
1206112561 "\n" +
1206212562 "MOV texSamp, one;" +
12063
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12064
-
12563
+
1206512564 "MOV mapgrid.x, one2048th.x;" +
1206612565 "MOV temp, fragment.texcoord[1];" +
1206712566 /*
....@@ -12466,10 +12965,10 @@
1246612965 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1246712966 "") +
1246812967
12469
- // display shadow only (bump == 0)
12968
+ // display shadow only (fakedepth == 0)
1247012969 "SUB temp.x, half.x, shadow.x;" +
12471
- "MOV temp.y, -params6.x;" +
12472
- "SLT temp.z, temp.y, zero.x;" +
12970
+ "MOV temp.y, -params5.z;" + // params6.x;" +
12971
+ "SLT temp.z, temp.y, -one2048th.x;" +
1247312972 "SUB temp.y, one.x, temp.z;" +
1247412973 "MUL temp.x, temp.x, temp.y;" +
1247512974 "KIL temp.x;" +
....@@ -12598,8 +13097,10 @@
1259813097 "MAX ndotl.x, ndotl.x, -ndotl.x;" +
1259913098
1260013099 "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
13100
+ // Tuning for default skin
13101
+ //"ADD temp.x, temp.x, options2.z;" + // lightsheen
13102
+ "MAD temp.x, options2.z, half.y, temp.x;" + // lightsheen
13103
+ "ADD temp.y, one.y, options2.y;" + // subsurface
1260313104 "MUL temp.x, temp.x, temp.y;" +
1260413105
1260513106 "MUL saturation, saturation, temp.xxxx;" +
....@@ -12747,7 +13248,7 @@
1274713248 "MUL final.y, fragment.texcoord[0].x, c256;" +
1274813249 "FLR final.x, final.y;" +
1274913250 "SUB final.y, final.y, final.x;" +
12750
- //"MUL final.x, final.x, c256i;" +
13251
+ "MUL final.x, final.x, c256i;" +
1275113252 "MOV final.z, zero.x;" +
1275213253 "MOV final.a, one.w;":""
1275313254 ) +
....@@ -12755,7 +13256,7 @@
1275513256 "MUL final.y, fragment.texcoord[0].y, c256;" +
1275613257 "FLR final.x, final.y;" +
1275713258 "SUB final.y, final.y, final.x;" +
12758
- //"MUL final.x, final.x, c256i;" +
13259
+ "MUL final.x, final.x, c256i;" +
1275913260 "MOV final.z, zero.x;" +
1276013261 "MOV final.a, one.w;":""
1276113262 ) +
....@@ -12798,7 +13299,7 @@
1279813299 //once = true;
1279913300 }
1280013301
12801
- System.out.print("Program #" + mode + "; length = " + program.length());
13302
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1280213303 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1280313304 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1280413305
....@@ -12896,20 +13397,20 @@
1289613397 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1289713398 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1289813399 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13400
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13401
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1289913402 "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;" +
13403
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13404
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1290413405 //"SWZ buffer, temp, w,w,w,w;";
12905
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13406
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1290613407 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1290713408 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1290813409 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
12909
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13410
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1291013411
12911
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
12912
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13412
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13413
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1291313414 }
1291413415
1291513416 String Shadow(String depth, String shadow)
....@@ -12931,12 +13432,16 @@
1293113432
1293213433 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1293313434 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13435
+
13436
+ // Compare fragment depth in light space with shadowmap.
1293413437 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1293513438 "SGE temp.y, temp.x, zero.x;" +
12936
- "SUB " + shadow + ".y, one.x, temp.y;" +
13439
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13440
+
13441
+ // Reverse comparison
1293713442 "SUB temp.x, one.x, temp.x;" +
1293813443 "MUL " + shadow + ".x, temp.x, temp.y;" +
12939
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13444
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1294013445 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1294113446
1294213447 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -12950,6 +13455,10 @@
1295013455 // No shadow for backface
1295113456 "DP3 temp.x, normal, lightd;" +
1295213457 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13458
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13459
+
13460
+ // No shadow when out of frustum
13461
+ "SGE temp.x, " + depth + ".z, one.z;" +
1295313462 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1295413463 "";
1295513464 }
....@@ -13096,7 +13605,8 @@
1309613605 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1309713606 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1309813607 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13099
- Object3D.cVector2[] vector2buffer;
13608
+
13609
+ //Object3D.cVector2[] vector2buffer;
1310013610
1310113611 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1310213612 // OUT : diff, spec
....@@ -13112,9 +13622,10 @@
1311213622 "DP3 " + dest + ".z," + "normals," + "eye;" +
1311313623 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1311413624 //"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;" +
13625
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13626
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13627
+
13628
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1311813629 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1311913630 "RCP " + dest + ".w," + dest + ".w;" +
1312013631 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13508,7 +14019,7 @@
1350814019 public void mousePressed(MouseEvent e)
1350914020 {
1351014021 //System.out.println("mousePressed: " + e);
13511
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14022
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1351214023 }
1351314024
1351414025 static long prevtime = 0;
....@@ -13584,8 +14095,8 @@
1358414095 // mode |= META;
1358514096 //}
1358614097
13587
- SetMouseMode(WHEEL | e.getModifiersEx());
13588
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14098
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14099
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1358914100 anchorX = ax;
1359014101 anchorY = ay;
1359114102 prevX = px;
....@@ -13619,6 +14130,7 @@
1361914130 else
1362014131 if (evt.getSource() == AAtimer)
1362114132 {
14133
+ Globals.TIMERRUNNING = false;
1362214134 if (mouseDown)
1362314135 {
1362414136 //new Exception().printStackTrace();
....@@ -13644,6 +14156,10 @@
1364414156 // LIVE = waslive;
1364514157 // wasliveok = true;
1364614158 // waslive = false;
14159
+
14160
+ // May 2019 Forget it:
14161
+ if (true)
14162
+ return;
1364714163
1364814164 // source == timer
1364914165 if (mouseDown)
....@@ -13674,7 +14190,7 @@
1367414190
1367514191 // fev 2014???
1367614192 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13677
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14193
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1367814194 pingthread.StepToTarget(true); // true);
1367914195 }
1368014196 // if (!LIVE)
....@@ -13683,12 +14199,13 @@
1368314199
1368414200 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1368514201
13686
- void clickStart(int x, int y, int modifiers)
14202
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1368714203 {
1368814204 if (!wasliveok)
1368914205 return;
1369014206
1369114207 AAtimer.restart(); //
14208
+ Globals.TIMERRUNNING = true;
1369214209
1369314210 // waslive = LIVE;
1369414211 // LIVE = false;
....@@ -13700,7 +14217,7 @@
1370014217 // touched = true; // main DL
1370114218 if (isRenderer)
1370214219 {
13703
- SetMouseMode(modifiers);
14220
+ SetMouseMode(modifiers, modifiersex);
1370414221 }
1370514222
1370614223 selectX = anchorX = x;
....@@ -13713,7 +14230,7 @@
1371314230 clicked = true;
1371414231 hold = false;
1371514232
13716
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14233
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1371714234 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1371814235 {
1371914236 // System.out.println("RESTART II " + modifiers);
....@@ -13738,14 +14255,15 @@
1373814255 drag = false;
1373914256 //System.out.println("Mouse DOWN");
1374014257 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);
14258
+ //ClickInfo info = new ClickInfo();
14259
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14260
+ object.clickInfo.pane = this;
14261
+ object.clickInfo.camera = renderCamera;
14262
+ object.clickInfo.x = x;
14263
+ object.clickInfo.y = y;
14264
+ object.clickInfo.modifiers = modifiersex;
14265
+ editObj = object.doEditClick(//info,
14266
+ 0);
1374914267 if (!editObj)
1375014268 {
1375114269 hasMarquee = true;
....@@ -13761,9 +14279,12 @@
1376114279
1376214280 public void mouseDragged(MouseEvent e)
1376314281 {
14282
+ Globals.MOUSEDRAGGED = true;
14283
+
1376414284 //System.out.println("mouseDragged: " + e);
1376514285 if (isRenderer)
1376614286 movingcamera = true;
14287
+
1376714288 //if (drawing)
1376814289 //return;
1376914290 if ((e.getModifiersEx() & CTRL) != 0
....@@ -13773,7 +14294,7 @@
1377314294 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1377414295 }
1377514296 else
13776
- drag(e.getX(), e.getY(), e.getModifiersEx());
14297
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1377714298
1377814299 //try { Thread.sleep(1); } catch (Exception ex) {}
1377914300 }
....@@ -13946,6 +14467,7 @@
1394614467
1394714468 public void run()
1394814469 {
14470
+ new Exception().printStackTrace();
1394914471 System.exit(0);
1395014472 for (;;)
1395114473 {
....@@ -14009,7 +14531,7 @@
1400914531 {
1401014532 Globals.lighttouched = true;
1401114533 }
14012
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14534
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1401314535 }
1401414536 //else
1401514537 }
....@@ -14023,12 +14545,12 @@
1402314545 void GoDown(int mod)
1402414546 {
1402514547 MODIFIERS |= COMMAND;
14026
- /*
14548
+ /**/
1402714549 if((mod&SHIFT) == SHIFT)
1402814550 manipCamera.RotatePosition(0, -speed);
1402914551 else
14030
- manipCamera.BackForth(0, -speed*delta, getWidth());
14031
- */
14552
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14553
+ /**/
1403214554 if ((mod & SHIFT) == SHIFT)
1403314555 {
1403414556 mouseMode = mouseMode; // VR??
....@@ -14044,12 +14566,12 @@
1404414566 void GoUp(int mod)
1404514567 {
1404614568 MODIFIERS |= COMMAND;
14047
- /*
14569
+ /**/
1404814570 if((mod&SHIFT) == SHIFT)
1404914571 manipCamera.RotatePosition(0, speed);
1405014572 else
14051
- manipCamera.BackForth(0, speed*delta, getWidth());
14052
- */
14573
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14574
+ /**/
1405314575 if ((mod & SHIFT) == SHIFT)
1405414576 {
1405514577 mouseMode = mouseMode;
....@@ -14065,12 +14587,12 @@
1406514587 void GoLeft(int mod)
1406614588 {
1406714589 MODIFIERS |= COMMAND;
14068
- /*
14590
+ /**/
1406914591 if((mod&SHIFT) == SHIFT)
14070
- manipCamera.RotatePosition(speed, 0);
14071
- else
1407214592 manipCamera.Translate(speed*delta, 0, getWidth());
14073
- */
14593
+ else
14594
+ manipCamera.RotatePosition(speed, 0);
14595
+ /**/
1407414596 if ((mod & SHIFT) == SHIFT)
1407514597 {
1407614598 mouseMode = mouseMode;
....@@ -14086,12 +14608,12 @@
1408614608 void GoRight(int mod)
1408714609 {
1408814610 MODIFIERS |= COMMAND;
14089
- /*
14611
+ /**/
1409014612 if((mod&SHIFT) == SHIFT)
14091
- manipCamera.RotatePosition(-speed, 0);
14092
- else
1409314613 manipCamera.Translate(-speed*delta, 0, getWidth());
14094
- */
14614
+ else
14615
+ manipCamera.RotatePosition(-speed, 0);
14616
+ /**/
1409514617 if ((mod & SHIFT) == SHIFT)
1409614618 {
1409714619 mouseMode = mouseMode;
....@@ -14109,7 +14631,7 @@
1410914631 int X, Y;
1411014632 boolean SX, SY;
1411114633
14112
- void drag(int x, int y, int modifiers)
14634
+ void drag(int x, int y, int modifiers, int modifiersex)
1411314635 {
1411414636 if (IsFrozen())
1411514637 {
....@@ -14118,17 +14640,17 @@
1411814640
1411914641 drag = true; // NEW
1412014642
14121
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14643
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1412214644
1412314645 X = x;
1412414646 Y = y;
1412514647 // floating state for animation
14126
- MODIFIERS = modifiers;
14127
- modifiers &= ~1024;
14648
+ MODIFIERS = modifiersex;
14649
+ modifiersex &= ~1024;
1412814650 if (false) // modifiers != 0)
1412914651 {
1413014652 //new Exception().printStackTrace();
14131
- System.out.println("mouseDragged: " + modifiers);
14653
+ System.out.println("mouseDragged: " + modifiersex);
1413214654 System.out.println("SHIFT = " + SHIFT);
1413314655 System.out.println("CONTROL = " + COMMAND);
1413414656 System.out.println("META = " + META);
....@@ -14141,14 +14663,16 @@
1414114663 if (editObj)
1414214664 {
1414314665 drag = true;
14144
- ClickInfo info = new ClickInfo();
14145
- info.bounds.setBounds(0, 0,
14666
+ //ClickInfo info = new ClickInfo();
14667
+ object.clickInfo.bounds.setBounds(0, 0,
1414614668 (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);
14669
+ object.clickInfo.pane = this;
14670
+ object.clickInfo.camera = renderCamera;
14671
+ object.clickInfo.x = x;
14672
+ object.clickInfo.y = y;
14673
+ object //.GetWindow().copy
14674
+ .doEditDrag(//info,
14675
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1415214676 } else
1415314677 {
1415414678 if (x < startX)
....@@ -14297,22 +14821,27 @@
1429714821 }
1429814822 }
1429914823
14824
+// ClickInfo clickInfo = new ClickInfo();
14825
+
1430014826 public void mouseMoved(MouseEvent e)
1430114827 {
1430214828 //System.out.println("mouseMoved: " + e);
1430314829 if (isRenderer)
1430414830 return;
1430514831
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;
14832
+ // Mouse cursor feedback
14833
+ object.clickInfo.x = e.getX();
14834
+ object.clickInfo.y = e.getY();
14835
+ object.clickInfo.modifiers = e.getModifiersEx();
14836
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14837
+ object.clickInfo.pane = this;
14838
+ object.clickInfo.camera = renderCamera;
1431314839 if (!isRenderer)
1431414840 {
14315
- if (object.editWindow.copy.doEditClick(ci, 0))
14841
+ //ObjEditor editWindow = object.editWindow;
14842
+ //Object3D copy = editWindow.copy;
14843
+ if (object.doEditClick(//clickInfo,
14844
+ 0))
1431614845 {
1431714846 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1431814847 } else
....@@ -14324,7 +14853,11 @@
1432414853
1432514854 public void mouseReleased(MouseEvent e)
1432614855 {
14856
+ Globals.MOUSEDRAGGED = false;
14857
+
1432714858 movingcamera = false;
14859
+ X = 0; // getBounds().width/2;
14860
+ Y = 0; // getBounds().height/2;
1432814861 //System.out.println("mouseReleased: " + e);
1432914862 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1433014863 }
....@@ -14347,9 +14880,9 @@
1434714880 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1434814881 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1434914882
14350
- if (control || command || IsFrozen())
14883
+// No delay if (control || command || IsFrozen())
1435114884 timeout = true;
14352
- else
14885
+// ?? May 2019 else
1435314886 // timer.setDelay((modifiers & 128) != 0?0:350);
1435414887 mouseDown = false;
1435514888 if (!control && !command) // june 2013
....@@ -14459,7 +14992,7 @@
1445914992 System.out.println("keyReleased: " + e);
1446014993 }
1446114994
14462
- void SetMouseMode(int modifiers)
14995
+ void SetMouseMode(int modifiers, int modifiersex)
1446314996 {
1446414997 //System.out.println("SetMouseMode = " + modifiers);
1446514998 //modifiers &= ~1024;
....@@ -14471,25 +15004,25 @@
1447115004 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1447215005 // return;
1447315006 //System.out.println("SetMode = " + modifiers);
14474
- if ((modifiers & WHEEL) == WHEEL)
15007
+ if ((modifiersex & WHEEL) == WHEEL)
1447515008 {
1447615009 mouseMode |= ZOOM;
1447715010 }
1447815011
1447915012 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
14480
- if (capsLocked || (modifiers & META) == META)
15013
+ if (capsLocked) // || (modifiers & META) == META)
1448115014 {
1448215015 mouseMode |= VR; // BACKFORTH;
1448315016 }
14484
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
15017
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1448515018 {
1448615019 mouseMode |= SELECT;
1448715020 }
14488
- if ((modifiers & COMMAND) == COMMAND)
15021
+ if ((modifiersex & COMMAND) == COMMAND)
1448915022 {
1449015023 mouseMode |= SELECT;
1449115024 }
14492
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15025
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
1449315026 {
1449415027 mouseMode &= ~VR;
1449515028 mouseMode |= TRANSLATE;
....@@ -14518,7 +15051,7 @@
1451815051
1451915052 if (isRenderer) //
1452015053 {
14521
- SetMouseMode(modifiers);
15054
+ SetMouseMode(0, modifiers);
1452215055 }
1452315056
1452415057 Globals.theRenderer.keyPressed(key);
....@@ -14580,7 +15113,8 @@
1458015113 // break;
1458115114 case 'T':
1458215115 CACHETEXTURE ^= true;
14583
- textures.clear();
15116
+ texturepigment.clear();
15117
+ texturebump.clear();
1458415118 // repaint();
1458515119 break;
1458615120 case 'Y':
....@@ -14665,7 +15199,9 @@
1466515199 case 'E' : COMPACT ^= true;
1466615200 repaint();
1466715201 break;
14668
- case 'W' : DEBUGHSB ^= true;
15202
+ case 'W' : // Wide Window (fullscreen)
15203
+ //DEBUGHSB ^= true;
15204
+ ObjEditor.theFrame.ToggleFullScreen();
1466915205 repaint();
1467015206 break;
1467115207 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14690,8 +15226,8 @@
1469015226 RevertCamera();
1469115227 repaint();
1469215228 break;
14693
- case 'L':
1469415229 case 'l':
15230
+ //case 'L':
1469515231 if (lightMode)
1469615232 {
1469715233 lightMode = false;
....@@ -14834,9 +15370,9 @@
1483415370 case '_':
1483515371 kompactbit = 5;
1483615372 break;
14837
- case '+':
14838
- kompactbit = 6;
14839
- break;
15373
+// case '+':
15374
+// kompactbit = 6;
15375
+// break;
1484015376 case ' ':
1484115377 lightMode ^= true;
1484215378 Globals.lighttouched = true;
....@@ -14848,13 +15384,14 @@
1484815384 case ESC:
1484915385 RENDERPROGRAM += 1;
1485015386 RENDERPROGRAM %= 3;
15387
+
1485115388 repaint();
1485215389 break;
1485315390 case 'Z':
1485415391 //RESIZETEXTURE ^= true;
1485515392 //break;
1485615393 case 'z':
14857
- RENDERSHADOW ^= true;
15394
+ Globals.RENDERSHADOW ^= true;
1485815395 Globals.lighttouched = true;
1485915396 repaint();
1486015397 break;
....@@ -14887,8 +15424,9 @@
1488715424 case DELETE:
1488815425 ClearSelection();
1488915426 break;
14890
- /*
1489115427 case '+':
15428
+
15429
+ /*
1489215430 //fontsize += 1;
1489315431 bbzoom *= 2;
1489415432 repaint();
....@@ -14905,17 +15443,17 @@
1490515443 case '=':
1490615444 IncDepth();
1490715445 //fontsize += 1;
14908
- object.editWindow.refreshContents(true);
15446
+ object.GetWindow().refreshContents(true);
1490915447 maskbit = 6;
1491015448 break;
1491115449 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1491215450 DecDepth();
1491315451 maskbit = 5;
1491415452 //if(fontsize > 1) fontsize -= 1;
14915
- if (object.editWindow == null)
14916
- new Exception().printStackTrace();
14917
- else
14918
- object.editWindow.refreshContents(true);
15453
+// if (object.editWindow == null)
15454
+// new Exception().printStackTrace();
15455
+// else
15456
+ object.GetWindow().refreshContents(true);
1491915457 break;
1492015458 case '{':
1492115459 manipCamera.shaper_fovy /= 1.1;
....@@ -14978,7 +15516,7 @@
1497815516 //mode = ROTATE;
1497915517 if ((MODIFIERS & COMMAND) == 0) // VR??
1498015518 {
14981
- SetMouseMode(modifiers);
15519
+ SetMouseMode(0, modifiers);
1498215520 }
1498315521 }
1498415522
....@@ -15114,7 +15652,7 @@
1511415652 {
1511515653 //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
1511615654 //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15117
- if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (mouseMode & SELECT) == 0)
15655
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1511815656 {
1511915657 mouseMoved(e);
1512015658 } else
....@@ -15139,11 +15677,12 @@
1513915677 }
1514015678 */
1514115679
15142
- object.editWindow.EditSelection();
15680
+ object.GetWindow().EditSelection(false);
1514315681 }
1514415682
1514515683 void SelectParent()
1514615684 {
15685
+ new Exception().printStackTrace();
1514715686 System.exit(0);
1514815687 Composite group = (Composite) object;
1514915688 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -15155,10 +15694,10 @@
1515515694 {
1515615695 //selectees.remove(i);
1515715696 System.out.println("select parent of " + elem);
15158
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15697
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1515915698 } else
1516015699 {
15161
- group.editWindow.Select(elem.GetTreePath(), first, true);
15700
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1516215701 }
1516315702
1516415703 first = false;
....@@ -15167,6 +15706,7 @@
1516715706
1516815707 void SelectChildren()
1516915708 {
15709
+ new Exception().printStackTrace();
1517015710 System.exit(0);
1517115711 /*
1517215712 Composite group = (Composite) object;
....@@ -15199,12 +15739,12 @@
1519915739 for (int j = 0; j < group.children.size(); j++)
1520015740 {
1520115741 elem = (Object3D) group.children.elementAt(j);
15202
- object.editWindow.Select(elem.GetTreePath(), first, true);
15742
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1520315743 first = false;
1520415744 }
1520515745 } else
1520615746 {
15207
- object.editWindow.Select(elem.GetTreePath(), first, true);
15747
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1520815748 }
1520915749
1521015750 first = false;
....@@ -15215,21 +15755,21 @@
1521515755 {
1521615756 //Composite group = (Composite) object;
1521715757 Object3D group = object;
15218
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15758
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1521915759 }
1522015760
1522115761 void ResetTransform(int mask)
1522215762 {
1522315763 //Composite group = (Composite) object;
1522415764 Object3D group = object;
15225
- group.editWindow.ResetTransform(mask);
15765
+ group.GetWindow().ResetTransform(mask);
1522615766 }
1522715767
1522815768 void FlipTransform()
1522915769 {
1523015770 //Composite group = (Composite) object;
1523115771 Object3D group = object;
15232
- group.editWindow.FlipTransform();
15772
+ group.GetWindow().FlipTransform();
1523315773 // group.editWindow.ReduceMesh(true);
1523415774 }
1523515775
....@@ -15237,7 +15777,7 @@
1523715777 {
1523815778 //Composite group = (Composite) object;
1523915779 Object3D group = object;
15240
- group.editWindow.PrintMemory();
15780
+ group.GetWindow().PrintMemory();
1524115781 // group.editWindow.ReduceMesh(true);
1524215782 }
1524315783
....@@ -15245,7 +15785,7 @@
1524515785 {
1524615786 //Composite group = (Composite) object;
1524715787 Object3D group = object;
15248
- group.editWindow.ResetCentroid();
15788
+ group.GetWindow().ResetCentroid();
1524915789 }
1525015790
1525115791 void IncDepth()
....@@ -15327,11 +15867,11 @@
1532715867
1532815868 int width = getBounds().width;
1532915869 int height = getBounds().height;
15330
- ClickInfo info = new ClickInfo();
15331
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1533215870 //Image img = CreateImage(width, height);
1533315871 //System.out.println("width = " + width + "; height = " + height + "\n");
15872
+
1533415873 Graphics gr = g; // img.getGraphics();
15874
+
1533515875 if (!hasMarquee)
1533615876 {
1533715877 if (Xmin < Xmax) // !locked)
....@@ -15403,40 +15943,88 @@
1540315943 }
1540415944 if (object != null && !hasMarquee)
1540515945 {
15946
+ if (object.clickInfo == null)
15947
+ object.clickInfo = new ClickInfo();
15948
+ ClickInfo info = object.clickInfo;
15949
+ //ClickInfo info = new ClickInfo();
15950
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
15951
+
1540615952 if (isRenderer)
1540715953 {
15408
- info.flags++;
15954
+ object.clickInfo.flags++;
1540915955 double frameAspect = (double) width / (double) height;
1541015956 if (frameAspect > renderCamera.aspect)
1541115957 {
1541215958 int desired = (int) ((double) height * renderCamera.aspect);
15413
- info.bounds.width -= width - desired;
15414
- info.bounds.x += (width - desired) / 2;
15959
+ object.clickInfo.bounds.width -= width - desired;
15960
+ object.clickInfo.bounds.x += (width - desired) / 2;
1541515961 } else
1541615962 {
1541715963 int desired = (int) ((double) width / renderCamera.aspect);
15418
- info.bounds.height -= height - desired;
15419
- info.bounds.y += (height - desired) / 2;
15964
+ object.clickInfo.bounds.height -= height - desired;
15965
+ object.clickInfo.bounds.y += (height - desired) / 2;
1542015966 }
1542115967 }
15422
- info.g = gr;
15423
- info.camera = renderCamera;
15968
+
15969
+ object.clickInfo.g = gr;
15970
+ object.clickInfo.camera = renderCamera;
1542415971 /*
1542515972 // Memory intensive (brep.verticescopy)
1542615973 if (!(object instanceof Composite))
1542715974 object.draw(info, 0, false); // SLOW :
1542815975 */
15429
- if (!isRenderer)
15976
+ if (!isRenderer) // && drag)
1543015977 {
15431
- object.drawEditHandles(info, 0);
15978
+ Grafreed.Assert(object != null);
15979
+ Grafreed.Assert(object.selection != null);
15980
+ if (object.selection.Size() > 0)
15981
+ {
15982
+ int hitSomething = object.selection.get(0).hitSomething;
15983
+
15984
+ object.clickInfo.DX = 0;
15985
+ object.clickInfo.DY = 0;
15986
+ object.clickInfo.W = 1;
15987
+ if (hitSomething == Object3D.hitCenter)
15988
+ {
15989
+ info.DX = X;
15990
+ if (X != 0)
15991
+ info.DX -= info.bounds.width/2;
15992
+
15993
+ info.DY = Y;
15994
+ if (Y != 0)
15995
+ info.DY -= info.bounds.height/2;
15996
+ }
15997
+
15998
+ object.drawEditHandles(//info,
15999
+ 0);
16000
+
16001
+ if (drag && (X != 0 || Y != 0))
16002
+ {
16003
+ switch (hitSomething)
16004
+ {
16005
+ case Object3D.hitCenter: gr.setColor(Color.pink);
16006
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16007
+ break;
16008
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16009
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16010
+ break;
16011
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16012
+ gr.drawLine(X, Y, 0, 0);
16013
+ break;
16014
+ }
16015
+
16016
+ }
16017
+ }
1543216018 }
1543316019 }
16020
+
1543416021 if (isRenderer)
1543516022 {
1543616023 //gr.setColor(Color.black);
1543716024 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1543816025 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1543916026 }
16027
+
1544016028 if (hasMarquee)
1544116029 {
1544216030 gr.setXORMode(Color.white);
....@@ -15549,6 +16137,7 @@
1554916137 public boolean mouseDown(Event evt, int x, int y)
1555016138 {
1555116139 System.out.println("mouseDown: " + evt);
16140
+ System.exit(0);
1555216141 /*
1555316142 locked = true;
1555416143 drag = false;
....@@ -15592,7 +16181,7 @@
1559216181 {
1559316182 keyPressed(0, modifiers);
1559416183 }
15595
- clickStart(x, y, modifiers);
16184
+ // clickStart(x, y, modifiers);
1559616185 return true;
1559716186 }
1559816187
....@@ -15710,7 +16299,7 @@
1571016299 {
1571116300 keyReleased(0, 0);
1571216301 }
15713
- drag(x, y, modifiers);
16302
+ drag(x, y, 0, modifiers);
1571416303 return true;
1571516304 }
1571616305
....@@ -15842,7 +16431,7 @@
1584216431 Object3D object;
1584316432 static Object3D trackedobject;
1584416433 Camera renderCamera; // Light or Eye (or Occlusion)
15845
- /*static*/ Camera manipCamera; // Light or Eye
16434
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1584616435 /*static*/ Camera eyeCamera;
1584716436 /*static*/ Camera lightCamera;
1584816437 int cameracount;
....@@ -16127,16 +16716,16 @@
1612716716 cStatic.objectstack[materialdepth++] = checker;
1612816717 //System.out.println("material " + material);
1612916718 //Applet3D.tracein(this, selected);
16130
- vector2buffer = checker.projectedVertices;
16719
+ //vector2buffer = checker.projectedVertices;
1613116720
1613216721 //checker.GetMaterial().Draw(this, false); // true);
16133
- DrawMaterial(checker.GetMaterial(), false); // true);
16722
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1613416723
1613516724 materialdepth -= 1;
1613616725 if (materialdepth > 0)
1613716726 {
16138
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16139
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
16727
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16728
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1614016729 }
1614116730 //checker.GetMaterial().opacity = 1f;
1614216731 ////checker.GetMaterial().ambient = 1f;
....@@ -16222,6 +16811,14 @@
1622216811 }
1622316812 }
1622416813
16814
+ private Object3D GetFolder()
16815
+ {
16816
+ Object3D folder = object.GetWindow().copy;
16817
+ if (object.GetWindow().copy.selection.Size() > 0)
16818
+ folder = object.GetWindow().copy.selection.elementAt(0);
16819
+ return folder;
16820
+ }
16821
+
1622516822 class SelectBuffer implements GLEventListener
1622616823 {
1622716824
....@@ -16280,6 +16877,7 @@
1628016877 {
1628116878 if (!selection)
1628216879 {
16880
+ new Exception().printStackTrace();
1628316881 System.exit(0);
1628416882 return;
1628516883 }
....@@ -16300,6 +16898,17 @@
1630016898
1630116899 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1630216900
16901
+ if (PAINTMODE)
16902
+ {
16903
+ if (object.GetWindow().copy.selection.Size() > 0)
16904
+ {
16905
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16906
+
16907
+ // Make what you paint not selectable.
16908
+ paintobj.ResetSelectable();
16909
+ }
16910
+ }
16911
+
1630316912 //int tmp = selection_view;
1630416913 //selection_view = -1;
1630516914 int temp = DrawMode();
....@@ -16311,6 +16920,17 @@
1631116920 // temp = DEFAULT; // patch for selection debug
1631216921 Globals.drawMode = temp; // WARNING
1631316922
16923
+ if (PAINTMODE)
16924
+ {
16925
+ if (object.GetWindow().copy.selection.Size() > 0)
16926
+ {
16927
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16928
+
16929
+ // Revert.
16930
+ paintobj.RestoreSelectable();
16931
+ }
16932
+ }
16933
+
1631416934 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1631516935
1631616936 // trying different ways of getting the depth info over
....@@ -16358,6 +16978,8 @@
1635816978 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1635916979 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1636016980 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
16981
+
16982
+ CreateSelectedPoint();
1636116983
1636216984 // Will fit the mesh !!!
1636316985 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16407,34 +17029,36 @@
1640717029 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]));
1640817030 }
1640917031
16410
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
17032
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1641117033 }
1641217034 }
1641317035
1641417036 if (!movingcamera && !PAINTMODE)
16415
- object.editWindow.ScreenFitPoint(); // fev 2014
17037
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1641617038
16417
- if (PAINTMODE && GrafreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17039
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1641817040 {
16419
- Object3D paintobj = GrafreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17041
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1642017042
16421
- Object3D group = new Object3D("inst" + paintcount++);
17043
+ if (object.GetWindow().copy.selection.Size() > 0)
17044
+ {
17045
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1642217046
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();
17047
+ Object3D inst = new Object3D("inst" + paintcount++);
17048
+
17049
+ inst.CreateMaterial(); // use a void leaf to select instances
17050
+
17051
+ inst.add(paintobj); // link
17052
+
17053
+ object.GetWindow().SnapObject(inst);
17054
+
17055
+ Object3D folder = paintFolder; // GetFolder();
17056
+
17057
+ folder.add(inst);
17058
+
17059
+ object.GetWindow().ResetModel();
17060
+ object.GetWindow().refreshContents();
17061
+ }
1643817062 }
1643917063 else
1644017064 paintcount = 0;
....@@ -16473,6 +17097,11 @@
1647317097 //System.out.println("objects[color] = " + objects[color]);
1647417098 //objects[color].Select();
1647517099 indexcount = 0;
17100
+ ObjEditor window = object.GetWindow();
17101
+ if (window != null && deselect)
17102
+ {
17103
+ window.Select(null, deselect, true);
17104
+ }
1647617105 object.Select(color, deselect);
1647717106 }
1647817107
....@@ -16572,7 +17201,7 @@
1657217201 gl.glDisable(gl.GL_CULL_FACE);
1657317202 }
1657417203
16575
- if (!RENDERSHADOW)
17204
+ if (!Globals.RENDERSHADOW)
1657617205 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1657717206
1657817207 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -16582,7 +17211,7 @@
1658217211 //gl.glColorMask(false, false, false, false);
1658317212
1658417213 //render_scene_from_light_view(gl, drawable, 0, 0);
16585
- if (RENDERSHADOW && Globals.lighttouched && !movingcamera) // && !parent.IsFreezed())
17214
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1658617215 {
1658717216 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1658817217
....@@ -16998,23 +17627,15 @@
1699817627 int AAbuffersize = 0;
1699917628
1700017629 //double[] selectedpoint = new double[3];
17001
- static Superellipsoid selectedpoint = new Superellipsoid();
17630
+ static Superellipsoid selectedpoint;
1700217631 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();
17632
+ static Sphere debugpointG;
17633
+ static Sphere debugpointP;
17634
+ static Sphere debugpointC;
17635
+ static Sphere debugpointR;
1700717636
1700817637 static Sphere debugpoints[] = new Sphere[8];
1700917638
17010
- static
17011
- {
17012
- for (int i=0; i<8; i++)
17013
- {
17014
- debugpoints[i] = new Sphere();
17015
- }
17016
- }
17017
-
1701817639 static void InitPoints(float radius)
1701917640 {
1702017641 for (int i=0; i<8; i++)