Normand Briere
2019-07-23 de4f66e0239a736bce24e09c9a0b49b5bb92d84b
CameraPane.java
....@@ -18,7 +18,10 @@
1818 import javax.imageio.ImageIO;
1919 import javax.imageio.ImageWriteParam;
2020 import javax.imageio.ImageWriter;
21
+import javax.imageio.ImageReadParam;
22
+import javax.imageio.ImageReader;
2123 import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
24
+import javax.imageio.stream.ImageInputStream;
2225 import javax.imageio.stream.ImageOutputStream;
2326 import javax.imageio.ImageWriteParam;
2427
....@@ -30,6 +33,7 @@
3033 import java.nio.*;
3134
3235 import gleem.linalg.Mat4f;
36
+import javax.imageio.ImageTypeSpecifier;
3337
3438 class CameraPane extends GLCanvas implements iCameraPane, Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener
3539 {
....@@ -37,7 +41,6 @@
3741 static boolean[] selectedstack = new boolean[65536];
3842 static int materialdepth = 0;
3943
40
- static boolean DEBUG = false;
4144 static boolean FRUSTUM = false; // still bogus true; // frustum culling
4245
4346 // camera change fix
....@@ -45,6 +48,39 @@
4548 static boolean ABORTED = false;
4649
4750 static int STEP = 1;
51
+
52
+ private static BufferedImage CreateBim(byte[] bytes, int width, int height)
53
+ {
54
+ int[] pixels = new int[bytes.length/3];
55
+ for (int i=pixels.length; --i>=0;)
56
+ {
57
+ int i3 = i*3;
58
+ pixels[i] = 0xFF;
59
+ pixels[i] <<= 8;
60
+ pixels[i] |= bytes[i3+2] & 0xFF;
61
+ pixels[i] <<= 8;
62
+ pixels[i] |= bytes[i3+1] & 0xFF;
63
+ pixels[i] <<= 8;
64
+ pixels[i] |= bytes[i3] & 0xFF;
65
+ }
66
+ /*
67
+ int r=0,g=0,b=0,a=0;
68
+ for (int i=0; i<width; i++)
69
+ for (int j=0; j<height; j++)
70
+ {
71
+ int index = j*width+i;
72
+ int p = pixels[index];
73
+ a = ((p>>24) & 0xFF);
74
+ r = ((p>>16) & 0xFF);
75
+ g = ((p>>8) & 0xFF);
76
+ b = (p & 0xFF);
77
+ pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
78
+ }
79
+ /**/
80
+ BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
81
+ rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
82
+ return rendImage;
83
+ }
4884
4985 /*static*/ private boolean CULLFACE = false; // true;
5086 /*static*/ boolean NEAREST = false; // true;
....@@ -56,14 +92,12 @@
5692 static int CURRENTANTIALIAS = 0; // 1;
5793 /*static*/ boolean RENDERSHADOW = true;
5894 /*static*/ int RENDERPROGRAM = 2; // 0 == none, 1 == fast, 2 == normal
59
- static boolean ANIMATION = false;
60
- static String filename;
6195
6296 boolean DISPLAYTEXT = false;
6397 //boolean REDUCETEXTURE = true;
6498 boolean CACHETEXTURE = true;
6599 boolean CLEANCACHE = false; // true;
66
- boolean MIPMAP = false; // true;
100
+ boolean MIPMAP = false; // true; // never works...
67101 boolean COMPRESSTEXTURE = false;
68102 boolean KOMPACTTEXTURE = false; // true;
69103 boolean RESIZETEXTURE = false;
....@@ -92,6 +126,8 @@
92126
93127 static int tickcount = 0; // slow pose issue
94128
129
+static boolean BUTTONLESSWHEEL = false;
130
+static boolean ZOOMBOXMODE = false;
95131 static boolean BOXMODE = false;
96132 static boolean IMAGEFLIP = false;
97133 static boolean SMOOTHFOCUS = false;
....@@ -106,7 +142,7 @@
106142 static boolean OEIL = true;
107143 static boolean OEILONCE = false; // do oeilon then oeiloff
108144 static boolean LOOKAT = true;
109
-static boolean RANDOM = true; // false;
145
+static boolean SWITCH = true; // false;
110146 static boolean HANDLES = false; // selection doesn't work!!
111147 static boolean PAINTMODE = false;
112148
....@@ -149,6 +185,8 @@
149185 defaultcaps.setAccumBlueBits(16);
150186 defaultcaps.setAccumAlphaBits(16);
151187 }
188
+
189
+ private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
152190
153191 void SetAsGLRenderer(boolean b)
154192 {
....@@ -223,6 +261,11 @@
223261 public boolean IsBoxMode()
224262 {
225263 return BOXMODE;
264
+ }
265
+
266
+ public boolean IsZoomBoxMode()
267
+ {
268
+ return ZOOMBOXMODE;
226269 }
227270
228271 public void ClearDepth()
....@@ -320,7 +363,7 @@
320363 cStatic.objectstack[materialdepth++] = obj;
321364 //System.out.println("material " + material);
322365 //Applet3D.tracein(this, selected);
323
- display.vector2buffer = obj.projectedVertices;
366
+ //display.vector2buffer = obj.projectedVertices;
324367 if (obj instanceof Camera)
325368 {
326369 display.options1[0] = material.shift;
....@@ -329,14 +372,28 @@
329372 display.options1[2] = material.shadowbias;
330373 display.options1[3] = material.aniso;
331374 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]);
332380 display.options2[0] = material.opacity;
333381 display.options2[1] = material.diffuse;
334382 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]);
335386
336387 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]);
337391 display.options4[0] = material.cameralight/0.2f;
338392 display.options4[1] = material.subsurface;
339393 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]);
340397
341398 // if (display.CURRENTANTIALIAS > 0)
342399 // display.options3[3] /= 4;
....@@ -352,7 +409,7 @@
352409 /**/
353410 } else
354411 {
355
- DrawMaterial(material, selected);
412
+ DrawMaterial(material, selected, obj.projectedVertices);
356413 }
357414 } else
358415 {
....@@ -376,8 +433,8 @@
376433 cStatic.objectstack[materialdepth++] = obj;
377434 //System.out.println("material " + material);
378435 //Applet3D.tracein("selected ", selected);
379
- display.vector2buffer = obj.projectedVertices;
380
- display.DrawMaterial(material, selected);
436
+ //display.vector2buffer = obj.projectedVertices;
437
+ display.DrawMaterial(material, selected, obj.projectedVertices);
381438 }
382439 }
383440
....@@ -394,8 +451,8 @@
394451 materialdepth -= 1;
395452 if (materialdepth > 0)
396453 {
397
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
398
- 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);
399456 }
400457 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
401458 } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
....@@ -415,8 +472,8 @@
415472 materialdepth -= 1;
416473 if (materialdepth > 0)
417474 {
418
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
419
- 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);
420477 }
421478 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
422479 //else
....@@ -457,10 +514,12 @@
457514 if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
458515 {
459516 //gl.glBegin(gl.GL_TRIANGLES);
460
- 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
+ ;
461520 if (!hasnorm)
462521 {
463
- // System.out.println("FUCK!!");
522
+ // System.out.println("Mesh normal");
464523 LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
465524 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
466525 LA.vecCross(obj.v0, obj.v1, obj.v2);
....@@ -1185,10 +1244,12 @@
11851244 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
11861245 }
11871246 }
1247
+
11881248 if (flipV)
11891249 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
11901250 else
11911251 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1252
+
11921253 //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
11931254 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
11941255
....@@ -1208,10 +1269,12 @@
12081269 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
12091270 }
12101271 }
1272
+
12111273 if (flipV)
12121274 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12131275 else
12141276 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1277
+
12151278 //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
12161279 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
12171280
....@@ -1239,8 +1302,10 @@
12391302 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12401303 else
12411304 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1305
+
12421306 //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
12431307 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1308
+
12441309 count2 += 2;
12451310 count3 += 3;
12461311 }
....@@ -1596,7 +1661,7 @@
15961661 // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
15971662 }
15981663
1599
- void DrawMaterial(cMaterial material, boolean selected)
1664
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
16001665 {
16011666 CameraPane display = this;
16021667 //new Exception().printStackTrace();
....@@ -1612,18 +1677,18 @@
16121677 //col.getColorComponents(ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB), CameraPane.modelParams0);
16131678 if (!material.multiply)
16141679 {
1615
- display.color = color;
1680
+ display.color = material.color;
16161681 display.saturation = material.modulation;
16171682 }
16181683 else
16191684 {
1620
- display.color *= color*2;
1685
+ display.color *= material.color*2;
16211686 display.saturation *= material.modulation*2;
16221687 }
16231688
16241689 cColor.HSBtoRGB(display.color, display.saturation, 1, display.modelParams0);
16251690
1626
- float[] colorV = GrafreeD.colorV;
1691
+ float[] colorV = Grafreed.colorV;
16271692
16281693 /**/
16291694 if (display.DrawMode() == display.DEFAULT) // && display.RENDERPROGRAM == 0)
....@@ -1631,7 +1696,7 @@
16311696 colorV[0] = display.modelParams0[0] * material.diffuse;
16321697 colorV[1] = display.modelParams0[1] * material.diffuse;
16331698 colorV[2] = display.modelParams0[2] * material.diffuse;
1634
- colorV[3] = material.opacity;
1699
+ colorV[3] = 1; // material.opacity;
16351700
16361701 gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
16371702 //System.out.println("Opacity = " + opacity);
....@@ -1739,9 +1804,9 @@
17391804 display.modelParams7[2] = 0;
17401805 display.modelParams7[3] = 0;
17411806
1742
- display.modelParams6[0] = 100; // criss de bug de bump
1807
+ //display.modelParams6[0] = 100; // criss de bug de bump
17431808
1744
- Object3D.cVector2[] extparams = display.vector2buffer;
1809
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
17451810 if (extparams != null && extparams.length > 0 && extparams[0] != null)
17461811 {
17471812 display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
....@@ -1883,7 +1948,7 @@
18831948 void PushMatrix(double[][] matrix)
18841949 {
18851950 // GrafreeD.tracein(matrix);
1886
- PushMatrix(matrix,1);
1951
+ PushMatrix(matrix, 1);
18871952 }
18881953
18891954 void PushMatrix()
....@@ -2037,7 +2102,7 @@
20372102 //System.err.println("Oeil on");
20382103 OEIL = true;
20392104 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2040
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2105
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
20412106 //pingthread.StepToTarget(true);
20422107 }
20432108
....@@ -2135,7 +2200,7 @@
21352200 System.err.println("LIVE = " + Globals.isLIVE());
21362201
21372202 if (!Globals.isLIVE()) // save sound
2138
- GrafreeD.savesound = true; // wav.save();
2203
+ Grafreed.savesound = true; // wav.save();
21392204 // else
21402205 repaint(); // start loop // may 2013
21412206 }
....@@ -2168,6 +2233,11 @@
21682233 public void ToggleBoxMode()
21692234 {
21702235 BOXMODE ^= true;
2236
+ }
2237
+
2238
+ public void ToggleZoomBoxMode()
2239
+ {
2240
+ ZOOMBOXMODE ^= true;
21712241 }
21722242
21732243 public void ToggleSmoothFocus()
....@@ -2247,7 +2317,7 @@
22472317
22482318 void ToggleDebug()
22492319 {
2250
- DEBUG ^= true;
2320
+ Globals.DEBUG ^= true;
22512321 }
22522322
22532323 void ToggleLookAt()
....@@ -2255,9 +2325,9 @@
22552325 LOOKAT ^= true;
22562326 }
22572327
2258
- void ToggleRandom()
2328
+ void ToggleSwitch()
22592329 {
2260
- RANDOM ^= true;
2330
+ SWITCH ^= true;
22612331 }
22622332
22632333 void ToggleHandles()
....@@ -2265,10 +2335,17 @@
22652335 HANDLES ^= true;
22662336 }
22672337
2338
+ Object3D paintFolder;
2339
+
22682340 void TogglePaint()
22692341 {
22702342 PAINTMODE ^= true;
22712343 paintcount = 0;
2344
+
2345
+ if (PAINTMODE)
2346
+ {
2347
+ paintFolder = GetFolder();
2348
+ }
22722349 }
22732350
22742351 void SwapCamera(int a, int b)
....@@ -2364,7 +2441,22 @@
23642441 {
23652442 return currentGL;
23662443 }
2367
-
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
+
23682460 /**/
23692461 class CacheTexture
23702462 {
....@@ -2373,28 +2465,31 @@
23732465
23742466 int resolution;
23752467
2376
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2468
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
23772469 {
2378
- texture = tex;
2470
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2471
+ texturedata = texdata;
23792472 resolution = res;
23802473 }
23812474 }
23822475 /**/
23832476
23842477 // TEXTURE static Texture texture;
2385
- static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures
2386
- = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>();
2387
- static public java.util.Hashtable<String, String> usedtextures = new java.util.Hashtable<String, String>();
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
+
23882483 int pigmentdepth = 0;
23892484 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
23902485 int bumpdepth = 0;
23912486 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
23922487 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
23932488 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2394
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2489
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
23952490 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
23962491
2397
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2492
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
23982493 {
23992494 TextureData texturedata = null;
24002495
....@@ -2413,13 +2508,34 @@
24132508 if (bump)
24142509 texturedata = ConvertBump(texturedata, false);
24152510
2416
- com.sun.opengl.util.texture.Texture texture =
2417
- 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);
24182513
2419
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2420
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
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);
24212516
2422
- 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;
24232539 }
24242540
24252541 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3492,6 +3608,8 @@
34923608
34933609 System.out.println("LOADING TEXTURE : " + name);
34943610
3611
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3612
+
34953613 //
34963614 if (false) // compressbit > 0)
34973615 {
....@@ -4196,6 +4314,7 @@
41964314
41974315 com.sun.opengl.util.texture.Texture CompressTexture2(String name)
41984316 {
4317
+ new Exception().printStackTrace();
41994318 System.exit(0);
42004319 com.sun.opengl.util.texture.Texture texture = null;
42014320
....@@ -7889,7 +8008,7 @@
78898008 String pigment = Object3D.GetPigment(tex);
78908009 String bump = Object3D.GetBump(tex);
78918010
7892
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8011
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
78938012 {
78948013 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
78958014 // System.out.println("; bump = " + bump);
....@@ -7904,11 +8023,69 @@
79048023 pigment = null;
79058024 }
79068025
7907
- ReleaseTexture(bump, true);
7908
- ReleaseTexture(pigment, false);
8026
+ ReleaseTexture(tex, true);
8027
+ ReleaseTexture(tex, false);
79098028 }
79108029
7911
- 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)
79128089 {
79138090 if (// DrawMode() != 0 || /*tex == null ||*/
79148091 ambientOcclusion ) // || !textureon)
....@@ -7919,7 +8096,7 @@
79198096 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
79208097
79218098 if (tex != null)
7922
- texture = textures.get(tex);
8099
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
79238100
79248101 // //assert( texture != null );
79258102 // if (texture == null)
....@@ -8011,7 +8188,55 @@
80118188 }
80128189 }
80138190
8014
- /*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
80158240 {
80168241 if (// DrawMode() != 0 || /*tex == null ||*/
80178242 ambientOcclusion ) // || !textureon)
....@@ -8022,17 +8247,47 @@
80228247 if (tex == null)
80238248 {
80248249 BindTexture(null,false,resolution);
8025
- BindTexture(null,true,resolution);
80268250 return;
80278251 }
80288252
80298253 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
+
80308286 String bump = Object3D.GetBump(tex);
80318287
8032
- usedtextures.put(pigment, pigment);
8033
- usedtextures.put(bump, bump);
8288
+ usedtextures.add(tex);
80348289
8035
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8290
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
80368291 {
80378292 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
80388293 // System.out.println("; bump = " + bump);
....@@ -8042,43 +8297,94 @@
80428297 {
80438298 bump = null;
80448299 }
8045
- if (pigment.equals(""))
8046
- {
8047
- pigment = null;
8048
- }
80498300
8050
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8051
- BindTexture(pigment, false, resolution);
80528301 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8053
- BindTexture(bump, true, resolution);
8302
+ BindTexture(tex, true, resolution);
80548303 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8055
-
8056
- return; // true;
80578304 }
80588305
8059
- 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)
80608309 {
8061
- 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;
80628329
80638330 if (tex != null)
80648331 {
8065
- String texname = tex;
8332
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8333
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
80668334
8067
- String[] split = tex.split("Textures");
8068
- if (split.length > 1)
8069
- texname = "/Users/nbriere/Textures" + split[split.length-1];
8070
- else
8071
- if (!texname.startsWith("/"))
8072
- texname = "/Users/nbriere/Textures/" + texname;
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
+ }
80738352
80748353 if (CACHETEXTURE)
8075
- texture = textures.get(texname); // TEXTURE CACHE
8076
-
8077
- TextureData texturedata = null;
8078
-
8079
- if (texture == null || texture.resolution < resolution)
80808354 {
8081
- 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(""))
80828388 {
80838389 assert(!bump);
80848390 // if (bump)
....@@ -8089,19 +8395,23 @@
80898395 // }
80908396 // else
80918397 // {
8092
- texture = textures.get(tex);
8093
- if (texture == null)
8398
+ // texturecache = textures.get(texname); // suspicious
8399
+ if (texturecache == null)
80948400 {
8095
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8401
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
80968402 }
8403
+ else
8404
+ new Exception().printStackTrace();
80978405 // }
80988406 } else
8099
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8407
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
81008408 {
81018409 assert(bump);
8102
- texture = textures.get(tex);
8103
- if (texture == null)
8104
- 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();
81058415 } else
81068416 {
81078417 //if (tex.equals("IMMORTAL"))
....@@ -8109,11 +8419,13 @@
81098419 // texture = GetResourceTexture("default.png");
81108420 //} else
81118421 //{
8112
- if (tex.equals("WHITE_NOISE"))
8422
+ if (texname.endsWith("WHITE_NOISE"))
81138423 {
8114
- texture = textures.get(tex);
8115
- if (texture == null)
8116
- 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();
81178429 } else
81188430 {
81198431 if (textureon)
....@@ -8138,7 +8450,7 @@
81388450 }
81398451
81408452 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
8141
- if (!new File(cachename).exists())
8453
+ if (!FileExists(cachename))
81428454 cachename = texname;
81438455 else
81448456 processbump = false; // don't process bump map again
....@@ -8160,7 +8472,7 @@
81608472 }
81618473
81628474 cachename = texname.substring(0, texname.length()-4)+ext+".png";
8163
- if (!new File(cachename).exists())
8475
+ if (!FileExists(cachename))
81648476 cachename = texname;
81658477 else
81668478 processbump = false; // don't process bump map again
....@@ -8169,20 +8481,22 @@
81698481 texturedata = GetFileTexture(cachename, processbump, resolution);
81708482
81718483
8172
- if (texturedata != null)
8173
- 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);
81748488 //texture = GetTexture(tex, bump);
81758489 }
81768490 }
81778491 //}
81788492 }
81798493
8180
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8494
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
81818495 {
81828496 //return false;
81838497
81848498 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8185
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8499
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
81868500 {
81878501 // String ext = "_highres";
81888502 // if (REDUCETEXTURE)
....@@ -8199,52 +8513,17 @@
81998513 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
82008514 if (!cachefile.exists())
82018515 {
8202
- // cache to disk
8203
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
8204
- //buffers[0].
8205
-
8206
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
8207
- int[] pixels = new int[bytebuf.capacity()/3];
8208
-
8209
- // squared size heuristic...
8210
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8516
+ //if (texturedata.getWidth() == texturedata.getHeight())
82118517 {
8212
- for (int i=pixels.length; --i>=0;)
8213
- {
8214
- int i3 = i*3;
8215
- pixels[i] = 0xFF;
8216
- pixels[i] <<= 8;
8217
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
8218
- pixels[i] <<= 8;
8219
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
8220
- pixels[i] <<= 8;
8221
- pixels[i] |= bytebuf.get(i3) & 0xFF;
8222
- }
8223
-
8224
- /*
8225
- int r=0,g=0,b=0,a=0;
8226
- for (int i=0; i<width; i++)
8227
- for (int j=0; j<height; j++)
8228
- {
8229
- int index = j*width+i;
8230
- int p = pixels[index];
8231
- a = ((p>>24) & 0xFF);
8232
- r = ((p>>16) & 0xFF);
8233
- g = ((p>>8) & 0xFF);
8234
- b = (p & 0xFF);
8235
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
8236
- }
8237
- /**/
8238
- int width = (int)Math.sqrt(pixels.length); // squared
8239
- int height = width;
8240
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
8241
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8518
+ BufferedImage rendImage = CreateBim(texturedata);
8519
+
82428520 ImageWriter writer = null;
82438521 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
82448522 if (iter.hasNext()) {
82458523 writer = (ImageWriter)iter.next();
82468524 }
8247
- float compressionQuality = 0.9f;
8525
+
8526
+ float compressionQuality = 0.85f;
82488527 try
82498528 {
82508529 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8261,18 +8540,20 @@
82618540 }
82628541 }
82638542 }
8264
-
8543
+
8544
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8545
+
82658546 //System.out.println("Texture = " + tex);
8266
- if (textures.containsKey(texname))
8547
+ if (textures.containsKey(tex))
82678548 {
8268
- CacheTexture thetex = textures.get(texname);
8549
+ CacheTexture thetex = textures.get(tex);
82698550 thetex.texture.disable();
82708551 thetex.texture.dispose();
8271
- textures.remove(texname);
8552
+ textures.remove(tex);
82728553 }
82738554
8274
- texture.texturedata = texturedata;
8275
- textures.put(texname, texture);
8555
+ //texture.texturedata = texturedata;
8556
+ textures.put(tex, texturecache);
82768557
82778558 // newtex = true;
82788559 }
....@@ -8288,10 +8569,44 @@
82888569 }
82898570 }
82908571
8291
- return texture;
8572
+ return texturecache;
82928573 }
82938574
8294
- 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
82958610 {
82968611 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
82978612
....@@ -8309,21 +8624,21 @@
83098624 return texture!=null?texture.texture:null;
83108625 }
83118626
8312
- 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
83138628 {
83148629 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
83158630
83168631 return texture!=null?texture.texturedata:null;
83178632 }
83188633
8319
- boolean BindTexture(String tex, boolean bump, int resolution)
8634
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
83208635 {
83218636 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
83228637 {
83238638 return false;
83248639 }
83258640
8326
- boolean newtex = false;
8641
+ //boolean newtex = false;
83278642
83288643 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
83298644
....@@ -8355,9 +8670,75 @@
83558670 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
83568671 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
83578672
8358
- return newtex;
8673
+ return true; // Warning: not used.
83598674 }
83608675
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
+
83618742 ShadowBuffer shadowPBuf;
83628743 AntialiasBuffer antialiasPBuf;
83638744 int MAXSTACK;
....@@ -9193,11 +9574,35 @@
91939574 jy8[3] = 0.5f;
91949575 }
91959576
9196
- 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
91979578 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
91989579 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
91999580 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
92009581
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
+
92019606 static int imagecount = 0; // movie generation
92029607
92039608 static int jitter = 0;
....@@ -9293,8 +9698,8 @@
92939698 assert (parentcam != renderCamera);
92949699
92959700 if (renderCamera != lightCamera)
9296
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9297
- LA.matConcat(matrix, parentcam.toParent, matrix);
9701
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9702
+ LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
92989703
92999704 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
93009705
....@@ -9309,8 +9714,8 @@
93099714 LA.matCopy(renderCamera.fromScreen, matrix);
93109715
93119716 if (renderCamera != lightCamera)
9312
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9313
- LA.matConcat(parentcam.fromParent, matrix, matrix);
9717
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9718
+ LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
93149719
93159720 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
93169721
....@@ -9382,7 +9787,7 @@
93829787 //gl.glFlush();
93839788 gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE);
93849789
9385
- if (ANIMATION && ABORTED)
9790
+ if (Globals.ANIMATION && ABORTED)
93869791 {
93879792 System.err.println(" ABORTED FRAME");
93889793 break;
....@@ -9412,7 +9817,7 @@
94129817 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
94139818
94149819 // save image
9415
- if (ANIMATION && !ABORTED)
9820
+ if (Globals.ANIMATION && !ABORTED)
94169821 {
94179822 VPwidth = viewport[2];
94189823 VPheight = viewport[3];
....@@ -9523,11 +9928,11 @@
95239928
95249929 // imagecount++;
95259930
9526
- 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;
95279932
95289933 if (!BOXMODE)
95299934 {
9530
- 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) + ")");
95319936 }
95329937
95339938 if (!BOXMODE)
....@@ -9565,7 +9970,7 @@
95659970 ABORTED = false;
95669971 }
95679972 else
9568
- GrafreeD.wav.cursor += 735 * ACSIZE;
9973
+ Grafreed.wav.cursor += 735 * ACSIZE;
95699974
95709975 if (false)
95719976 {
....@@ -10228,11 +10633,11 @@
1022810633
1022910634 public void display(GLAutoDrawable drawable)
1023010635 {
10231
- if (GrafreeD.savesound && GrafreeD.hassound)
10636
+ if (Grafreed.savesound && Grafreed.hassound)
1023210637 {
10233
- GrafreeD.wav.save();
10234
- GrafreeD.savesound = false;
10235
- GrafreeD.hassound = false;
10638
+ Grafreed.wav.save();
10639
+ Grafreed.savesound = false;
10640
+ Grafreed.hassound = false;
1023610641 }
1023710642 // if (DEBUG_SELECTION)
1023810643 // {
....@@ -10308,6 +10713,7 @@
1030810713 ANTIALIAS = 0;
1030910714 //System.out.println("RESTART");
1031010715 AAtimer.restart();
10716
+ Globals.TIMERRUNNING = true;
1031110717 }
1031210718 }
1031310719 }
....@@ -10362,7 +10768,7 @@
1036210768 Object3D theobject = object;
1036310769 Object3D theparent = object.parent;
1036410770 object.parent = null;
10365
- object = (Object3D)GrafreeD.clone(object);
10771
+ object = (Object3D)Grafreed.clone(object);
1036610772 object.Stripify();
1036710773 if (theobject.selection == null || theobject.selection.Size() == 0)
1036810774 theobject.PreprocessOcclusion(this);
....@@ -10375,13 +10781,14 @@
1037510781 ambientOcclusion = false;
1037610782 }
1037710783
10378
- if (Globals.lighttouched && DrawMode() == DEFAULT && !lightMode) // && !FROZEN)
10784
+ if (//Globals.lighttouched &&
10785
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1037910786 {
1038010787 //if (RENDERSHADOW) // ?
1038110788 if (!IsFrozen())
1038210789 {
1038310790 // dec 2012
10384
- if (!ambientOcclusion && !(!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0))
10791
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
1038510792 {
1038610793 Globals.framecount++;
1038710794 shadowbuffer.display();
....@@ -10508,8 +10915,8 @@
1050810915
1050910916 // if (parentcam != renderCamera) // not a light
1051010917 if (cam != lightCamera)
10511
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10512
- LA.matConcat(matrix, parentcam.toParent, matrix);
10918
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10919
+ LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
1051310920
1051410921 for (int j = 0; j < 4; j++)
1051510922 {
....@@ -10523,8 +10930,8 @@
1052310930
1052410931 // if (parentcam != renderCamera) // not a light
1052510932 if (cam != lightCamera)
10526
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10527
- LA.matConcat(parentcam.fromParent, matrix, matrix);
10933
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10934
+ LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
1052810935
1052910936 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1053010937
....@@ -10783,7 +11190,16 @@
1078311190 // Bump noise
1078411191 gl.glActiveTexture(GL.GL_TEXTURE6);
1078511192 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
10786
- 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
+
1078711203
1078811204 gl.glActiveTexture(GL.GL_TEXTURE0);
1078911205 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -10806,9 +11222,9 @@
1080611222
1080711223 gl.glMatrixMode(GL.GL_MODELVIEW);
1080811224
10809
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10810
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10811
-//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);
1081211228 } else
1081311229 {
1081411230 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -10819,7 +11235,7 @@
1081911235 //System.out.println("BLENDING ON");
1082011236 gl.glEnable(GL.GL_BLEND);
1082111237 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
10822
-
11238
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1082311239 gl.glMatrixMode(gl.GL_PROJECTION);
1082411240 gl.glLoadIdentity();
1082511241
....@@ -10908,8 +11324,8 @@
1090811324 System.err.println("parentcam != renderCamera");
1090911325
1091011326 // if (cam != lightCamera)
10911
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10912
- 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
1091311329 }
1091411330
1091511331 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -10930,8 +11346,8 @@
1093011346 if (true) // TODO
1093111347 {
1093211348 if (cam != lightCamera)
10933
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10934
- 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
1093511351 }
1093611352
1093711353 LA.xformPos(light0, cam.toScreen, light0);
....@@ -11068,7 +11484,7 @@
1106811484 }
1106911485 }
1107011486
11071
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11487
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1107211488 {
1107311489 //gl.glDepthFunc(GL.GL_LEQUAL);
1107411490 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11076,24 +11492,21 @@
1107611492
1107711493 boolean texon = textureon;
1107811494
11079
- if (RENDERPROGRAM > 0)
11080
- {
11081
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11082
- textureon = false;
11083
- }
11495
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11496
+ textureon = false;
11497
+
1108411498 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1108511499 //System.out.println("ALLO");
1108611500 gl.glColorMask(false, false, false, false);
1108711501 DrawObject(gl);
11088
- if (RENDERPROGRAM > 0)
11089
- {
11090
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11091
- textureon = texon;
11092
- }
11502
+
11503
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11504
+ textureon = texon;
11505
+
1109311506 gl.glColorMask(true, true, true, true);
1109411507
1109511508 gl.glDepthFunc(GL.GL_EQUAL);
11096
- //gl.glDepthMask(false);
11509
+ gl.glDepthMask(false);
1109711510 }
1109811511
1109911512 if (false) // DrawMode() == SHADOW)
....@@ -11247,8 +11660,14 @@
1124711660 {
1124811661 renderpass++;
1124911662 // System.out.println("Draw object... ");
11663
+ STEP = 1;
1125011664 if (FAST) // in case there is no script
11251
- STEP = 16;
11665
+ STEP = 8;
11666
+
11667
+ if (CURRENTANTIALIAS == 0 || ACSIZE == 1)
11668
+ {
11669
+ STEP *= 4;
11670
+ }
1125211671
1125311672 //object.FullInvariants();
1125411673
....@@ -11262,23 +11681,44 @@
1126211681 e.printStackTrace();
1126311682 }
1126411683
11265
- if (GrafreeD.RENDERME > 0)
11266
- GrafreeD.RENDERME--; // mechante magouille
11684
+ if (Grafreed.RENDERME > 0)
11685
+ Grafreed.RENDERME--; // mechante magouille
1126711686
1126811687 Globals.ONESTEP = false;
1126911688 }
1127011689
1127111690 static boolean zoomonce = false;
1127211691
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
+
1127311710 void DrawObject(GL gl, boolean draw)
1127411711 {
11712
+ // To clear camera values
11713
+ ResetOptions();
11714
+
1127511715 //System.out.println("DRAW OBJECT " + mouseDown);
1127611716 // DrawMode() = SELECTION;
1127711717 //GL gl = getGL();
1127811718 if ((TRACK || SHADOWTRACK) || zoomonce)
1127911719 {
1128011720 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11281
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11721
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1128211722 pingthread.StepToTarget(true); // true);
1128311723 // zoomonce = false;
1128411724 }
....@@ -11333,7 +11773,14 @@
1133311773
1133411774 usedtextures.clear();
1133511775
11336
- 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
+ }
1133711784 }
1133811785 //System.out.println("--> " + stackdepth);
1133911786 // GrafreeD.traceon();
....@@ -11343,8 +11790,9 @@
1134311790
1134411791 if (DrawMode() == DEFAULT)
1134511792 {
11346
- if (DEBUG)
11793
+ if (Globals.DEBUG)
1134711794 {
11795
+ CreateSelectedPoint();
1134811796 float radius = 0.05f;
1134911797 if (selectedpoint.radius != radius)
1135011798 {
....@@ -11398,20 +11846,32 @@
1139811846 ReleaseTextures(DEFAULT_TEXTURES);
1139911847
1140011848 if (CLEANCACHE)
11401
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11849
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1140211850 {
11403
- String tex = e.nextElement();
11851
+ cTexture tex = e.nextElement();
1140411852
1140511853 // System.out.println("Texture --------- " + tex);
1140611854
11407
- if (tex.equals("WHITE_NOISE"))
11855
+ if (tex.equals("WHITE_NOISE:"))
1140811856 continue;
1140911857
11410
- if (!usedtextures.containsKey(tex))
11858
+ if (!usedtextures.contains(tex))
1141111859 {
11860
+ CacheTexture gettex = texturepigment.get(tex);
1141211861 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11413
- textures.get(tex).texture.dispose();
11414
- 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
+ }
1141511875 }
1141611876 }
1141711877 }
....@@ -11424,7 +11884,14 @@
1142411884 if (checker != null && DrawMode() == DEFAULT)
1142511885 {
1142611886 //BindTexture(IMMORTAL_TEXTURE);
11427
- 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
+ }
1142811895 // NEAREST
1142911896 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
1143011897 DrawChecker(gl);
....@@ -11506,7 +11973,7 @@
1150611973 return;
1150711974 }
1150811975
11509
- String string = obj.GetToolTip();
11976
+ String string = obj.toString(); //.GetToolTip();
1151011977
1151111978 GL gl = GetGL();
1151211979
....@@ -11823,8 +12290,8 @@
1182312290 //obj.TransformToWorld(light, light);
1182412291 for (int i = tp.size(); --i >= 0;)
1182512292 {
11826
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
11827
- 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);
1182812295 }
1182912296
1183012297
....@@ -11841,8 +12308,8 @@
1184112308 parentcam = cameras[0];
1184212309 }
1184312310
11844
- for (int count = parentcam.GetTransformCount(); --count>=0;)
11845
- 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
1184612313
1184712314 LA.xformPos(light, renderCamera.toScreen, light);
1184812315
....@@ -11933,7 +12400,51 @@
1193312400 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1193412401
1193512402 String program =
12403
+ // Min shader
1193612404 "!!ARBfp1.0\n" +
12405
+ "PARAM zero123 = { 0.0, 1.0, 2.0, 3.0 };" +
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
+ "MUL temp, temp, ndotl.x;" +
12437
+
12438
+ "MUL temp, temp, zero123.z;" +
12439
+
12440
+ "MOV temp.w, zero123.y;" + // reset alpha
12441
+
12442
+ "MOV result.color, temp;" +
12443
+ "END";
12444
+
12445
+ String program2 =
12446
+ "!!ARBfp1.0\n" +
12447
+
1193712448 //"OPTION ARB_fragment_program_shadow;" +
1193812449 "PARAM light2cam0 = program.env[10];" +
1193912450 "PARAM light2cam1 = program.env[11];" +
....@@ -12048,8 +12559,7 @@
1204812559 "TEMP shininess;" +
1204912560 "\n" +
1205012561 "MOV texSamp, one;" +
12051
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12052
-
12562
+
1205312563 "MOV mapgrid.x, one2048th.x;" +
1205412564 "MOV temp, fragment.texcoord[1];" +
1205512565 /*
....@@ -12454,10 +12964,10 @@
1245412964 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1245512965 "") +
1245612966
12457
- // display shadow only (bump == 0)
12967
+ // display shadow only (fakedepth == 0)
1245812968 "SUB temp.x, half.x, shadow.x;" +
12459
- "MOV temp.y, -params6.x;" +
12460
- "SLT temp.z, temp.y, zero.x;" +
12969
+ "MOV temp.y, -params5.z;" + // params6.x;" +
12970
+ "SLT temp.z, temp.y, -one2048th.x;" +
1246112971 "SUB temp.y, one.x, temp.z;" +
1246212972 "MUL temp.x, temp.x, temp.y;" +
1246312973 "KIL temp.x;" +
....@@ -12586,8 +13096,10 @@
1258613096 "MAX ndotl.x, ndotl.x, -ndotl.x;" +
1258713097
1258813098 "SUB temp.x, one.x, ndotl.x;" +
12589
- "ADD temp.x, temp.x, options2.z;" + // lightsheen
12590
- "ADD temp.y, one.y, options2.y;" + // sursurface
13099
+ // Tuning for default skin
13100
+ //"ADD temp.x, temp.x, options2.z;" + // lightsheen
13101
+ "MAD temp.x, options2.z, half.y, temp.x;" + // lightsheen
13102
+ "ADD temp.y, one.y, options2.y;" + // subsurface
1259113103 "MUL temp.x, temp.x, temp.y;" +
1259213104
1259313105 "MUL saturation, saturation, temp.xxxx;" +
....@@ -12786,7 +13298,7 @@
1278613298 //once = true;
1278713299 }
1278813300
12789
- System.out.print("Program #" + mode + "; length = " + program.length());
13301
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1279013302 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1279113303 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1279213304
....@@ -12919,12 +13431,16 @@
1291913431
1292013432 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1292113433 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13434
+
13435
+ // Compare fragment depth in light space with shadowmap.
1292213436 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1292313437 "SGE temp.y, temp.x, zero.x;" +
12924
- "SUB " + shadow + ".y, one.x, temp.y;" +
13438
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13439
+
13440
+ // Reverse comparison
1292513441 "SUB temp.x, one.x, temp.x;" +
1292613442 "MUL " + shadow + ".x, temp.x, temp.y;" +
12927
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13443
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1292813444 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1292913445
1293013446 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -12938,6 +13454,10 @@
1293813454 // No shadow for backface
1293913455 "DP3 temp.x, normal, lightd;" +
1294013456 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13457
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13458
+
13459
+ // No shadow when out of frustum
13460
+ "SGE temp.x, " + depth + ".z, one.z;" +
1294113461 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1294213462 "";
1294313463 }
....@@ -13084,7 +13604,8 @@
1308413604 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1308513605 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1308613606 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13087
- Object3D.cVector2[] vector2buffer;
13607
+
13608
+ //Object3D.cVector2[] vector2buffer;
1308813609
1308913610 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1309013611 // OUT : diff, spec
....@@ -13100,9 +13621,10 @@
1310013621 "DP3 " + dest + ".z," + "normals," + "eye;" +
1310113622 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1310213623 //"MOV " + dest + ".w," + "normal.z;" +
13103
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
13104
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13105
- //"MOV " + dest + ".z," + "params2.w;" +
13624
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13625
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13626
+
13627
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1310613628 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1310713629 "RCP " + dest + ".w," + dest + ".w;" +
1310813630 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13496,7 +14018,7 @@
1349614018 public void mousePressed(MouseEvent e)
1349714019 {
1349814020 //System.out.println("mousePressed: " + e);
13499
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14021
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1350014022 }
1350114023
1350214024 static long prevtime = 0;
....@@ -13523,6 +14045,7 @@
1352314045
1352414046 //System.err.println("Dtime = " + Dtime + "; units = " + e.getUnitsToScroll() + "; ratio (units/ms) = " + ratio);
1352514047
14048
+ if (BUTTONLESSWHEEL)
1352614049 if (Math.abs(ratio) < 0.1 || Math.abs(Dtime) == 0) // < 30)
1352714050 {
1352814051 return;
....@@ -13531,7 +14054,7 @@
1353114054 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
1353214055
1353314056 // TIMER
13534
- if (!wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
14057
+ if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
1353514058 {
1353614059 keepboxmode = BOXMODE;
1353714060 keepsupport = SUPPORT;
....@@ -13571,8 +14094,8 @@
1357114094 // mode |= META;
1357214095 //}
1357314096
13574
- SetMouseMode(WHEEL | e.getModifiersEx());
13575
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14097
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14098
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1357614099 anchorX = ax;
1357714100 anchorY = ay;
1357814101 prevX = px;
....@@ -13606,6 +14129,7 @@
1360614129 else
1360714130 if (evt.getSource() == AAtimer)
1360814131 {
14132
+ Globals.TIMERRUNNING = false;
1360914133 if (mouseDown)
1361014134 {
1361114135 //new Exception().printStackTrace();
....@@ -13631,6 +14155,10 @@
1363114155 // LIVE = waslive;
1363214156 // wasliveok = true;
1363314157 // waslive = false;
14158
+
14159
+ // May 2019 Forget it:
14160
+ if (true)
14161
+ return;
1363414162
1363514163 // source == timer
1363614164 if (mouseDown)
....@@ -13661,7 +14189,7 @@
1366114189
1366214190 // fev 2014???
1366314191 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13664
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14192
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1366514193 pingthread.StepToTarget(true); // true);
1366614194 }
1366714195 // if (!LIVE)
....@@ -13670,12 +14198,13 @@
1367014198
1367114199 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1367214200
13673
- void clickStart(int x, int y, int modifiers)
14201
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1367414202 {
1367514203 if (!wasliveok)
1367614204 return;
1367714205
1367814206 AAtimer.restart(); //
14207
+ Globals.TIMERRUNNING = true;
1367914208
1368014209 // waslive = LIVE;
1368114210 // LIVE = false;
....@@ -13687,7 +14216,7 @@
1368714216 // touched = true; // main DL
1368814217 if (isRenderer)
1368914218 {
13690
- SetMouseMode(modifiers);
14219
+ SetMouseMode(modifiers, modifiersex);
1369114220 }
1369214221
1369314222 selectX = anchorX = x;
....@@ -13700,7 +14229,7 @@
1370014229 clicked = true;
1370114230 hold = false;
1370214231
13703
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14232
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1370414233 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1370514234 {
1370614235 // System.out.println("RESTART II " + modifiers);
....@@ -13731,7 +14260,7 @@
1373114260 info.camera = renderCamera;
1373214261 info.x = x;
1373314262 info.y = y;
13734
- info.modifiers = modifiers;
14263
+ info.modifiers = modifiersex;
1373514264 editObj = object.doEditClick(info, 0);
1373614265 if (!editObj)
1373714266 {
....@@ -13748,11 +14277,14 @@
1374814277
1374914278 public void mouseDragged(MouseEvent e)
1375014279 {
14280
+ Globals.MOUSEDRAGGED = true;
14281
+
14282
+ //System.out.println("mouseDragged: " + e);
1375114283 if (isRenderer)
1375214284 movingcamera = true;
14285
+
1375314286 //if (drawing)
1375414287 //return;
13755
- //System.out.println("mouseDragged: " + e);
1375614288 if ((e.getModifiersEx() & CTRL) != 0
1375714289 || (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen())
1375814290 {
....@@ -13760,7 +14292,7 @@
1376014292 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1376114293 }
1376214294 else
13763
- drag(e.getX(), e.getY(), e.getModifiersEx());
14295
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1376414296
1376514297 //try { Thread.sleep(1); } catch (Exception ex) {}
1376614298 }
....@@ -13933,6 +14465,7 @@
1393314465
1393414466 public void run()
1393514467 {
14468
+ new Exception().printStackTrace();
1393614469 System.exit(0);
1393714470 for (;;)
1393814471 {
....@@ -13996,7 +14529,7 @@
1399614529 {
1399714530 Globals.lighttouched = true;
1399814531 }
13999
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14532
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1400014533 }
1400114534 //else
1400214535 }
....@@ -14010,12 +14543,12 @@
1401014543 void GoDown(int mod)
1401114544 {
1401214545 MODIFIERS |= COMMAND;
14013
- /*
14546
+ /**/
1401414547 if((mod&SHIFT) == SHIFT)
1401514548 manipCamera.RotatePosition(0, -speed);
1401614549 else
14017
- manipCamera.BackForth(0, -speed*delta, getWidth());
14018
- */
14550
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14551
+ /**/
1401914552 if ((mod & SHIFT) == SHIFT)
1402014553 {
1402114554 mouseMode = mouseMode; // VR??
....@@ -14031,12 +14564,12 @@
1403114564 void GoUp(int mod)
1403214565 {
1403314566 MODIFIERS |= COMMAND;
14034
- /*
14567
+ /**/
1403514568 if((mod&SHIFT) == SHIFT)
1403614569 manipCamera.RotatePosition(0, speed);
1403714570 else
14038
- manipCamera.BackForth(0, speed*delta, getWidth());
14039
- */
14571
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14572
+ /**/
1404014573 if ((mod & SHIFT) == SHIFT)
1404114574 {
1404214575 mouseMode = mouseMode;
....@@ -14052,12 +14585,12 @@
1405214585 void GoLeft(int mod)
1405314586 {
1405414587 MODIFIERS |= COMMAND;
14055
- /*
14588
+ /**/
1405614589 if((mod&SHIFT) == SHIFT)
14057
- manipCamera.RotatePosition(speed, 0);
14058
- else
1405914590 manipCamera.Translate(speed*delta, 0, getWidth());
14060
- */
14591
+ else
14592
+ manipCamera.RotatePosition(speed, 0);
14593
+ /**/
1406114594 if ((mod & SHIFT) == SHIFT)
1406214595 {
1406314596 mouseMode = mouseMode;
....@@ -14073,12 +14606,12 @@
1407314606 void GoRight(int mod)
1407414607 {
1407514608 MODIFIERS |= COMMAND;
14076
- /*
14609
+ /**/
1407714610 if((mod&SHIFT) == SHIFT)
14078
- manipCamera.RotatePosition(-speed, 0);
14079
- else
1408014611 manipCamera.Translate(-speed*delta, 0, getWidth());
14081
- */
14612
+ else
14613
+ manipCamera.RotatePosition(-speed, 0);
14614
+ /**/
1408214615 if ((mod & SHIFT) == SHIFT)
1408314616 {
1408414617 mouseMode = mouseMode;
....@@ -14096,7 +14629,7 @@
1409614629 int X, Y;
1409714630 boolean SX, SY;
1409814631
14099
- void drag(int x, int y, int modifiers)
14632
+ void drag(int x, int y, int modifiers, int modifiersex)
1410014633 {
1410114634 if (IsFrozen())
1410214635 {
....@@ -14105,17 +14638,17 @@
1410514638
1410614639 drag = true; // NEW
1410714640
14108
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14641
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1410914642
1411014643 X = x;
1411114644 Y = y;
1411214645 // floating state for animation
14113
- MODIFIERS = modifiers;
14114
- modifiers &= ~1024;
14646
+ MODIFIERS = modifiersex;
14647
+ modifiersex &= ~1024;
1411514648 if (false) // modifiers != 0)
1411614649 {
1411714650 //new Exception().printStackTrace();
14118
- System.out.println("mouseDragged: " + modifiers);
14651
+ System.out.println("mouseDragged: " + modifiersex);
1411914652 System.out.println("SHIFT = " + SHIFT);
1412014653 System.out.println("CONTROL = " + COMMAND);
1412114654 System.out.println("META = " + META);
....@@ -14135,7 +14668,8 @@
1413514668 info.camera = renderCamera;
1413614669 info.x = x;
1413714670 info.y = y;
14138
- object.editWindow.copy.doEditDrag(info);
14671
+ object.GetWindow().copy
14672
+ .doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1413914673 } else
1414014674 {
1414114675 if (x < startX)
....@@ -14287,7 +14821,6 @@
1428714821 public void mouseMoved(MouseEvent e)
1428814822 {
1428914823 //System.out.println("mouseMoved: " + e);
14290
-
1429114824 if (isRenderer)
1429214825 return;
1429314826
....@@ -14300,7 +14833,9 @@
1430014833 ci.camera = renderCamera;
1430114834 if (!isRenderer)
1430214835 {
14303
- if (object.editWindow.copy.doEditClick(ci, 0))
14836
+ //ObjEditor editWindow = object.editWindow;
14837
+ //Object3D copy = editWindow.copy;
14838
+ if (object.doEditClick(ci, 0))
1430414839 {
1430514840 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1430614841 } else
....@@ -14312,7 +14847,11 @@
1431214847
1431314848 public void mouseReleased(MouseEvent e)
1431414849 {
14850
+ Globals.MOUSEDRAGGED = false;
14851
+
1431514852 movingcamera = false;
14853
+ X = 0; // getBounds().width/2;
14854
+ Y = 0; // getBounds().height/2;
1431614855 //System.out.println("mouseReleased: " + e);
1431714856 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1431814857 }
....@@ -14335,9 +14874,9 @@
1433514874 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1433614875 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1433714876
14338
- if (control || command || IsFrozen())
14877
+// No delay if (control || command || IsFrozen())
1433914878 timeout = true;
14340
- else
14879
+// ?? May 2019 else
1434114880 // timer.setDelay((modifiers & 128) != 0?0:350);
1434214881 mouseDown = false;
1434314882 if (!control && !command) // june 2013
....@@ -14447,7 +14986,7 @@
1444714986 System.out.println("keyReleased: " + e);
1444814987 }
1444914988
14450
- void SetMouseMode(int modifiers)
14989
+ void SetMouseMode(int modifiers, int modifiersex)
1445114990 {
1445214991 //System.out.println("SetMouseMode = " + modifiers);
1445314992 //modifiers &= ~1024;
....@@ -14459,25 +14998,25 @@
1445914998 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1446014999 // return;
1446115000 //System.out.println("SetMode = " + modifiers);
14462
- if ((modifiers & WHEEL) == WHEEL)
15001
+ if ((modifiersex & WHEEL) == WHEEL)
1446315002 {
1446415003 mouseMode |= ZOOM;
1446515004 }
1446615005
1446715006 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
14468
- if (capsLocked || (modifiers & META) == META)
15007
+ if (capsLocked) // || (modifiers & META) == META)
1446915008 {
1447015009 mouseMode |= VR; // BACKFORTH;
1447115010 }
14472
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
15011
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1447315012 {
1447415013 mouseMode |= SELECT;
1447515014 }
14476
- if ((modifiers & COMMAND) == COMMAND)
15015
+ if ((modifiersex & COMMAND) == COMMAND)
1447715016 {
1447815017 mouseMode |= SELECT;
1447915018 }
14480
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15019
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
1448115020 {
1448215021 mouseMode &= ~VR;
1448315022 mouseMode |= TRANSLATE;
....@@ -14506,7 +15045,7 @@
1450615045
1450715046 if (isRenderer) //
1450815047 {
14509
- SetMouseMode(modifiers);
15048
+ SetMouseMode(0, modifiers);
1451015049 }
1451115050
1451215051 Globals.theRenderer.keyPressed(key);
....@@ -14568,7 +15107,8 @@
1456815107 // break;
1456915108 case 'T':
1457015109 CACHETEXTURE ^= true;
14571
- textures.clear();
15110
+ texturepigment.clear();
15111
+ texturebump.clear();
1457215112 // repaint();
1457315113 break;
1457415114 case 'Y':
....@@ -14653,7 +15193,9 @@
1465315193 case 'E' : COMPACT ^= true;
1465415194 repaint();
1465515195 break;
14656
- case 'W' : DEBUGHSB ^= true;
15196
+ case 'W' : // Wide Window (fullscreen)
15197
+ //DEBUGHSB ^= true;
15198
+ ObjEditor.theFrame.ToggleFullScreen();
1465715199 repaint();
1465815200 break;
1465915201 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14678,8 +15220,8 @@
1467815220 RevertCamera();
1467915221 repaint();
1468015222 break;
14681
- case 'L':
1468215223 case 'l':
15224
+ //case 'L':
1468315225 if (lightMode)
1468415226 {
1468515227 lightMode = false;
....@@ -14822,9 +15364,9 @@
1482215364 case '_':
1482315365 kompactbit = 5;
1482415366 break;
14825
- case '+':
14826
- kompactbit = 6;
14827
- break;
15367
+// case '+':
15368
+// kompactbit = 6;
15369
+// break;
1482815370 case ' ':
1482915371 lightMode ^= true;
1483015372 Globals.lighttouched = true;
....@@ -14836,13 +15378,14 @@
1483615378 case ESC:
1483715379 RENDERPROGRAM += 1;
1483815380 RENDERPROGRAM %= 3;
15381
+
1483915382 repaint();
1484015383 break;
1484115384 case 'Z':
1484215385 //RESIZETEXTURE ^= true;
1484315386 //break;
1484415387 case 'z':
14845
- RENDERSHADOW ^= true;
15388
+ Globals.RENDERSHADOW ^= true;
1484615389 Globals.lighttouched = true;
1484715390 repaint();
1484815391 break;
....@@ -14875,8 +15418,9 @@
1487515418 case DELETE:
1487615419 ClearSelection();
1487715420 break;
14878
- /*
1487915421 case '+':
15422
+
15423
+ /*
1488015424 //fontsize += 1;
1488115425 bbzoom *= 2;
1488215426 repaint();
....@@ -14893,17 +15437,17 @@
1489315437 case '=':
1489415438 IncDepth();
1489515439 //fontsize += 1;
14896
- object.editWindow.refreshContents(true);
15440
+ object.GetWindow().refreshContents(true);
1489715441 maskbit = 6;
1489815442 break;
1489915443 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1490015444 DecDepth();
1490115445 maskbit = 5;
1490215446 //if(fontsize > 1) fontsize -= 1;
14903
- if (object.editWindow == null)
14904
- new Exception().printStackTrace();
14905
- else
14906
- object.editWindow.refreshContents(true);
15447
+// if (object.editWindow == null)
15448
+// new Exception().printStackTrace();
15449
+// else
15450
+ object.GetWindow().refreshContents(true);
1490715451 break;
1490815452 case '{':
1490915453 manipCamera.shaper_fovy /= 1.1;
....@@ -14966,7 +15510,7 @@
1496615510 //mode = ROTATE;
1496715511 if ((MODIFIERS & COMMAND) == 0) // VR??
1496815512 {
14969
- SetMouseMode(modifiers);
15513
+ SetMouseMode(0, modifiers);
1497015514 }
1497115515 }
1497215516
....@@ -15100,8 +15644,9 @@
1510015644
1510115645 protected void processMouseMotionEvent(MouseEvent e)
1510215646 {
15103
- //System.out.println("processMouseMotionEvent: " + mouseMode);
15104
- if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15647
+ //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
15648
+ //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15649
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1510515650 {
1510615651 mouseMoved(e);
1510715652 } else
....@@ -15126,11 +15671,12 @@
1512615671 }
1512715672 */
1512815673
15129
- object.editWindow.EditSelection();
15674
+ object.GetWindow().EditSelection(false);
1513015675 }
1513115676
1513215677 void SelectParent()
1513315678 {
15679
+ new Exception().printStackTrace();
1513415680 System.exit(0);
1513515681 Composite group = (Composite) object;
1513615682 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -15142,10 +15688,10 @@
1514215688 {
1514315689 //selectees.remove(i);
1514415690 System.out.println("select parent of " + elem);
15145
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15691
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1514615692 } else
1514715693 {
15148
- group.editWindow.Select(elem.GetTreePath(), first, true);
15694
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1514915695 }
1515015696
1515115697 first = false;
....@@ -15154,6 +15700,7 @@
1515415700
1515515701 void SelectChildren()
1515615702 {
15703
+ new Exception().printStackTrace();
1515715704 System.exit(0);
1515815705 /*
1515915706 Composite group = (Composite) object;
....@@ -15186,12 +15733,12 @@
1518615733 for (int j = 0; j < group.children.size(); j++)
1518715734 {
1518815735 elem = (Object3D) group.children.elementAt(j);
15189
- object.editWindow.Select(elem.GetTreePath(), first, true);
15736
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1519015737 first = false;
1519115738 }
1519215739 } else
1519315740 {
15194
- object.editWindow.Select(elem.GetTreePath(), first, true);
15741
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1519515742 }
1519615743
1519715744 first = false;
....@@ -15202,21 +15749,21 @@
1520215749 {
1520315750 //Composite group = (Composite) object;
1520415751 Object3D group = object;
15205
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15752
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1520615753 }
1520715754
1520815755 void ResetTransform(int mask)
1520915756 {
1521015757 //Composite group = (Composite) object;
1521115758 Object3D group = object;
15212
- group.editWindow.ResetTransform(mask);
15759
+ group.GetWindow().ResetTransform(mask);
1521315760 }
1521415761
1521515762 void FlipTransform()
1521615763 {
1521715764 //Composite group = (Composite) object;
1521815765 Object3D group = object;
15219
- group.editWindow.FlipTransform();
15766
+ group.GetWindow().FlipTransform();
1522015767 // group.editWindow.ReduceMesh(true);
1522115768 }
1522215769
....@@ -15224,7 +15771,7 @@
1522415771 {
1522515772 //Composite group = (Composite) object;
1522615773 Object3D group = object;
15227
- group.editWindow.PrintMemory();
15774
+ group.GetWindow().PrintMemory();
1522815775 // group.editWindow.ReduceMesh(true);
1522915776 }
1523015777
....@@ -15232,7 +15779,7 @@
1523215779 {
1523315780 //Composite group = (Composite) object;
1523415781 Object3D group = object;
15235
- group.editWindow.ResetCentroid();
15782
+ group.GetWindow().ResetCentroid();
1523615783 }
1523715784
1523815785 void IncDepth()
....@@ -15318,7 +15865,9 @@
1531815865 info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1531915866 //Image img = CreateImage(width, height);
1532015867 //System.out.println("width = " + width + "; height = " + height + "\n");
15868
+
1532115869 Graphics gr = g; // img.getGraphics();
15870
+
1532215871 if (!hasMarquee)
1532315872 {
1532415873 if (Xmin < Xmax) // !locked)
....@@ -15406,6 +15955,7 @@
1540615955 info.bounds.y += (height - desired) / 2;
1540715956 }
1540815957 }
15958
+
1540915959 info.g = gr;
1541015960 info.camera = renderCamera;
1541115961 /*
....@@ -15415,15 +15965,55 @@
1541515965 */
1541615966 if (!isRenderer)
1541715967 {
15418
- object.drawEditHandles(info, 0);
15968
+ Grafreed.Assert(object != null);
15969
+ Grafreed.Assert(object.selection != null);
15970
+ if (object.selection.Size() > 0)
15971
+ {
15972
+ int hitSomething = object.selection.get(0).hitSomething;
15973
+
15974
+ info.DX = 0;
15975
+ info.DY = 0;
15976
+ info.W = 1;
15977
+ if (hitSomething == Object3D.hitCenter)
15978
+ {
15979
+ info.DX = X;
15980
+ if (X != 0)
15981
+ info.DX -= info.bounds.width/2;
15982
+
15983
+ info.DY = Y;
15984
+ if (Y != 0)
15985
+ info.DY -= info.bounds.height/2;
15986
+ }
15987
+
15988
+ object.drawEditHandles(info, 0);
15989
+
15990
+ if (drag && (X != 0 || Y != 0))
15991
+ {
15992
+ switch (hitSomething)
15993
+ {
15994
+ case Object3D.hitCenter: gr.setColor(Color.pink);
15995
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15996
+ break;
15997
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
15998
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15999
+ break;
16000
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16001
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16002
+ break;
16003
+ }
16004
+
16005
+ }
16006
+ }
1541916007 }
1542016008 }
16009
+
1542116010 if (isRenderer)
1542216011 {
1542316012 //gr.setColor(Color.black);
1542416013 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1542516014 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1542616015 }
16016
+
1542716017 if (hasMarquee)
1542816018 {
1542916019 gr.setXORMode(Color.white);
....@@ -15536,6 +16126,7 @@
1553616126 public boolean mouseDown(Event evt, int x, int y)
1553716127 {
1553816128 System.out.println("mouseDown: " + evt);
16129
+ System.exit(0);
1553916130 /*
1554016131 locked = true;
1554116132 drag = false;
....@@ -15579,7 +16170,7 @@
1557916170 {
1558016171 keyPressed(0, modifiers);
1558116172 }
15582
- clickStart(x, y, modifiers);
16173
+ // clickStart(x, y, modifiers);
1558316174 return true;
1558416175 }
1558516176
....@@ -15697,7 +16288,7 @@
1569716288 {
1569816289 keyReleased(0, 0);
1569916290 }
15700
- drag(x, y, modifiers);
16291
+ drag(x, y, 0, modifiers);
1570116292 return true;
1570216293 }
1570316294
....@@ -15829,7 +16420,7 @@
1582916420 Object3D object;
1583016421 static Object3D trackedobject;
1583116422 Camera renderCamera; // Light or Eye (or Occlusion)
15832
- /*static*/ Camera manipCamera; // Light or Eye
16423
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1583316424 /*static*/ Camera eyeCamera;
1583416425 /*static*/ Camera lightCamera;
1583516426 int cameracount;
....@@ -16114,16 +16705,16 @@
1611416705 cStatic.objectstack[materialdepth++] = checker;
1611516706 //System.out.println("material " + material);
1611616707 //Applet3D.tracein(this, selected);
16117
- vector2buffer = checker.projectedVertices;
16708
+ //vector2buffer = checker.projectedVertices;
1611816709
1611916710 //checker.GetMaterial().Draw(this, false); // true);
16120
- DrawMaterial(checker.GetMaterial(), false); // true);
16711
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1612116712
1612216713 materialdepth -= 1;
1612316714 if (materialdepth > 0)
1612416715 {
16125
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16126
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
16716
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16717
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1612716718 }
1612816719 //checker.GetMaterial().opacity = 1f;
1612916720 ////checker.GetMaterial().ambient = 1f;
....@@ -16209,6 +16800,14 @@
1620916800 }
1621016801 }
1621116802
16803
+ private Object3D GetFolder()
16804
+ {
16805
+ Object3D folder = object.GetWindow().copy;
16806
+ if (object.GetWindow().copy.selection.Size() > 0)
16807
+ folder = object.GetWindow().copy.selection.elementAt(0);
16808
+ return folder;
16809
+ }
16810
+
1621216811 class SelectBuffer implements GLEventListener
1621316812 {
1621416813
....@@ -16267,6 +16866,7 @@
1626716866 {
1626816867 if (!selection)
1626916868 {
16869
+ new Exception().printStackTrace();
1627016870 System.exit(0);
1627116871 return;
1627216872 }
....@@ -16287,6 +16887,17 @@
1628716887
1628816888 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1628916889
16890
+ if (PAINTMODE)
16891
+ {
16892
+ if (object.GetWindow().copy.selection.Size() > 0)
16893
+ {
16894
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16895
+
16896
+ // Make what you paint not selectable.
16897
+ paintobj.ResetSelectable();
16898
+ }
16899
+ }
16900
+
1629016901 //int tmp = selection_view;
1629116902 //selection_view = -1;
1629216903 int temp = DrawMode();
....@@ -16298,6 +16909,17 @@
1629816909 // temp = DEFAULT; // patch for selection debug
1629916910 Globals.drawMode = temp; // WARNING
1630016911
16912
+ if (PAINTMODE)
16913
+ {
16914
+ if (object.GetWindow().copy.selection.Size() > 0)
16915
+ {
16916
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16917
+
16918
+ // Revert.
16919
+ paintobj.RestoreSelectable();
16920
+ }
16921
+ }
16922
+
1630116923 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1630216924
1630316925 // trying different ways of getting the depth info over
....@@ -16345,6 +16967,8 @@
1634516967 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1634616968 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1634716969 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
16970
+
16971
+ CreateSelectedPoint();
1634816972
1634916973 // Will fit the mesh !!!
1635016974 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16394,34 +17018,36 @@
1639417018 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]));
1639517019 }
1639617020
16397
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
17021
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1639817022 }
1639917023 }
1640017024
1640117025 if (!movingcamera && !PAINTMODE)
16402
- object.editWindow.ScreenFitPoint(); // fev 2014
17026
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1640317027
16404
- if (PAINTMODE && GrafreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17028
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1640517029 {
16406
- Object3D paintobj = GrafreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17030
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1640717031
16408
- Object3D group = new Object3D("inst" + paintcount++);
17032
+ if (object.GetWindow().copy.selection.Size() > 0)
17033
+ {
17034
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1640917035
16410
- group.CreateMaterial(); // use a void leaf to select instances
16411
-
16412
- group.add(paintobj); // link
16413
-
16414
- object.editWindow.SnapObject(group);
16415
-
16416
- Object3D folder = object.editWindow.copy;
16417
-
16418
- if (object.editWindow.copy.selection.Size() > 0)
16419
- folder = object.editWindow.copy.selection.elementAt(0);
16420
-
16421
- folder.add(group);
16422
-
16423
- object.editWindow.ResetModel();
16424
- object.editWindow.refreshContents();
17036
+ Object3D inst = new Object3D("inst" + paintcount++);
17037
+
17038
+ inst.CreateMaterial(); // use a void leaf to select instances
17039
+
17040
+ inst.add(paintobj); // link
17041
+
17042
+ object.GetWindow().SnapObject(inst);
17043
+
17044
+ Object3D folder = paintFolder; // GetFolder();
17045
+
17046
+ folder.add(inst);
17047
+
17048
+ object.GetWindow().ResetModel();
17049
+ object.GetWindow().refreshContents();
17050
+ }
1642517051 }
1642617052 else
1642717053 paintcount = 0;
....@@ -16460,6 +17086,11 @@
1646017086 //System.out.println("objects[color] = " + objects[color]);
1646117087 //objects[color].Select();
1646217088 indexcount = 0;
17089
+ ObjEditor window = object.GetWindow();
17090
+ if (window != null && deselect)
17091
+ {
17092
+ window.Select(null, deselect, true);
17093
+ }
1646317094 object.Select(color, deselect);
1646417095 }
1646517096
....@@ -16559,7 +17190,7 @@
1655917190 gl.glDisable(gl.GL_CULL_FACE);
1656017191 }
1656117192
16562
- if (!RENDERSHADOW)
17193
+ if (!Globals.RENDERSHADOW)
1656317194 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1656417195
1656517196 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -16569,7 +17200,7 @@
1656917200 //gl.glColorMask(false, false, false, false);
1657017201
1657117202 //render_scene_from_light_view(gl, drawable, 0, 0);
16572
- if (RENDERSHADOW && Globals.lighttouched && !movingcamera) // && !parent.IsFreezed())
17203
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1657317204 {
1657417205 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1657517206
....@@ -16985,23 +17616,15 @@
1698517616 int AAbuffersize = 0;
1698617617
1698717618 //double[] selectedpoint = new double[3];
16988
- static Superellipsoid selectedpoint = new Superellipsoid();
17619
+ static Superellipsoid selectedpoint;
1698917620 static Sphere previousselectedpoint = null;
16990
- static Sphere debugpointG = new Sphere();
16991
- static Sphere debugpointP = new Sphere();
16992
- static Sphere debugpointC = new Sphere();
16993
- static Sphere debugpointR = new Sphere();
17621
+ static Sphere debugpointG;
17622
+ static Sphere debugpointP;
17623
+ static Sphere debugpointC;
17624
+ static Sphere debugpointR;
1699417625
1699517626 static Sphere debugpoints[] = new Sphere[8];
1699617627
16997
- static
16998
- {
16999
- for (int i=0; i<8; i++)
17000
- {
17001
- debugpoints[i] = new Sphere();
17002
- }
17003
- }
17004
-
1700517628 static void InitPoints(float radius)
1700617629 {
1700717630 for (int i=0; i<8; i++)