Normand Briere
2019-07-23 0f4fa9dc4191aaee9661c1e6d73725436ae64ac2
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,52 @@
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, 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
+
1193712449 //"OPTION ARB_fragment_program_shadow;" +
1193812450 "PARAM light2cam0 = program.env[10];" +
1193912451 "PARAM light2cam1 = program.env[11];" +
....@@ -12048,8 +12560,7 @@
1204812560 "TEMP shininess;" +
1204912561 "\n" +
1205012562 "MOV texSamp, one;" +
12051
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12052
-
12563
+
1205312564 "MOV mapgrid.x, one2048th.x;" +
1205412565 "MOV temp, fragment.texcoord[1];" +
1205512566 /*
....@@ -12454,10 +12965,10 @@
1245412965 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1245512966 "") +
1245612967
12457
- // display shadow only (bump == 0)
12968
+ // display shadow only (fakedepth == 0)
1245812969 "SUB temp.x, half.x, shadow.x;" +
12459
- "MOV temp.y, -params6.x;" +
12460
- "SLT temp.z, temp.y, zero.x;" +
12970
+ "MOV temp.y, -params5.z;" + // params6.x;" +
12971
+ "SLT temp.z, temp.y, -one2048th.x;" +
1246112972 "SUB temp.y, one.x, temp.z;" +
1246212973 "MUL temp.x, temp.x, temp.y;" +
1246312974 "KIL temp.x;" +
....@@ -12586,8 +13097,10 @@
1258613097 "MAX ndotl.x, ndotl.x, -ndotl.x;" +
1258713098
1258813099 "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
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
1259113104 "MUL temp.x, temp.x, temp.y;" +
1259213105
1259313106 "MUL saturation, saturation, temp.xxxx;" +
....@@ -12786,7 +13299,7 @@
1278613299 //once = true;
1278713300 }
1278813301
12789
- System.out.print("Program #" + mode + "; length = " + program.length());
13302
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1279013303 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1279113304 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1279213305
....@@ -12884,20 +13397,20 @@
1288413397 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1288513398 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1288613399 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13400
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13401
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1288713402 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12888
- "SLT " + src + ".z, " + src + ".x, one.x;" +
12889
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12890
- "SLT " + src + ".z, " + src + ".y, one.x;" +
12891
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13403
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13404
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1289213405 //"SWZ buffer, temp, w,w,w,w;";
12893
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13406
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1289413407 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1289513408 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1289613409 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
12897
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13410
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1289813411
12899
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
12900
- //"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;";
1290113414 }
1290213415
1290313416 String Shadow(String depth, String shadow)
....@@ -12919,12 +13432,16 @@
1291913432
1292013433 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1292113434 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13435
+
13436
+ // Compare fragment depth in light space with shadowmap.
1292213437 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1292313438 "SGE temp.y, temp.x, zero.x;" +
12924
- "SUB " + shadow + ".y, one.x, temp.y;" +
13439
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13440
+
13441
+ // Reverse comparison
1292513442 "SUB temp.x, one.x, temp.x;" +
1292613443 "MUL " + shadow + ".x, temp.x, temp.y;" +
12927
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13444
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1292813445 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1292913446
1293013447 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -12938,6 +13455,10 @@
1293813455 // No shadow for backface
1293913456 "DP3 temp.x, normal, lightd;" +
1294013457 "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;" +
1294113462 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1294213463 "";
1294313464 }
....@@ -13084,7 +13605,8 @@
1308413605 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1308513606 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1308613607 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13087
- Object3D.cVector2[] vector2buffer;
13608
+
13609
+ //Object3D.cVector2[] vector2buffer;
1308813610
1308913611 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1309013612 // OUT : diff, spec
....@@ -13100,9 +13622,10 @@
1310013622 "DP3 " + dest + ".z," + "normals," + "eye;" +
1310113623 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1310213624 //"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;" +
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
1310613629 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1310713630 "RCP " + dest + ".w," + dest + ".w;" +
1310813631 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13496,7 +14019,7 @@
1349614019 public void mousePressed(MouseEvent e)
1349714020 {
1349814021 //System.out.println("mousePressed: " + e);
13499
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14022
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1350014023 }
1350114024
1350214025 static long prevtime = 0;
....@@ -13523,6 +14046,7 @@
1352314046
1352414047 //System.err.println("Dtime = " + Dtime + "; units = " + e.getUnitsToScroll() + "; ratio (units/ms) = " + ratio);
1352514048
14049
+ if (BUTTONLESSWHEEL)
1352614050 if (Math.abs(ratio) < 0.1 || Math.abs(Dtime) == 0) // < 30)
1352714051 {
1352814052 return;
....@@ -13531,7 +14055,7 @@
1353114055 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
1353214056
1353314057 // TIMER
13534
- if (!wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
14058
+ if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
1353514059 {
1353614060 keepboxmode = BOXMODE;
1353714061 keepsupport = SUPPORT;
....@@ -13571,8 +14095,8 @@
1357114095 // mode |= META;
1357214096 //}
1357314097
13574
- SetMouseMode(WHEEL | e.getModifiersEx());
13575
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14098
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14099
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1357614100 anchorX = ax;
1357714101 anchorY = ay;
1357814102 prevX = px;
....@@ -13606,6 +14130,7 @@
1360614130 else
1360714131 if (evt.getSource() == AAtimer)
1360814132 {
14133
+ Globals.TIMERRUNNING = false;
1360914134 if (mouseDown)
1361014135 {
1361114136 //new Exception().printStackTrace();
....@@ -13631,6 +14156,10 @@
1363114156 // LIVE = waslive;
1363214157 // wasliveok = true;
1363314158 // waslive = false;
14159
+
14160
+ // May 2019 Forget it:
14161
+ if (true)
14162
+ return;
1363414163
1363514164 // source == timer
1363614165 if (mouseDown)
....@@ -13661,7 +14190,7 @@
1366114190
1366214191 // fev 2014???
1366314192 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13664
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14193
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1366514194 pingthread.StepToTarget(true); // true);
1366614195 }
1366714196 // if (!LIVE)
....@@ -13670,12 +14199,13 @@
1367014199
1367114200 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1367214201
13673
- void clickStart(int x, int y, int modifiers)
14202
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1367414203 {
1367514204 if (!wasliveok)
1367614205 return;
1367714206
1367814207 AAtimer.restart(); //
14208
+ Globals.TIMERRUNNING = true;
1367914209
1368014210 // waslive = LIVE;
1368114211 // LIVE = false;
....@@ -13687,7 +14217,7 @@
1368714217 // touched = true; // main DL
1368814218 if (isRenderer)
1368914219 {
13690
- SetMouseMode(modifiers);
14220
+ SetMouseMode(modifiers, modifiersex);
1369114221 }
1369214222
1369314223 selectX = anchorX = x;
....@@ -13700,7 +14230,7 @@
1370014230 clicked = true;
1370114231 hold = false;
1370214232
13703
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14233
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1370414234 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1370514235 {
1370614236 // System.out.println("RESTART II " + modifiers);
....@@ -13731,7 +14261,7 @@
1373114261 info.camera = renderCamera;
1373214262 info.x = x;
1373314263 info.y = y;
13734
- info.modifiers = modifiers;
14264
+ info.modifiers = modifiersex;
1373514265 editObj = object.doEditClick(info, 0);
1373614266 if (!editObj)
1373714267 {
....@@ -13748,11 +14278,14 @@
1374814278
1374914279 public void mouseDragged(MouseEvent e)
1375014280 {
14281
+ Globals.MOUSEDRAGGED = true;
14282
+
14283
+ //System.out.println("mouseDragged: " + e);
1375114284 if (isRenderer)
1375214285 movingcamera = true;
14286
+
1375314287 //if (drawing)
1375414288 //return;
13755
- //System.out.println("mouseDragged: " + e);
1375614289 if ((e.getModifiersEx() & CTRL) != 0
1375714290 || (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen())
1375814291 {
....@@ -13760,7 +14293,7 @@
1376014293 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1376114294 }
1376214295 else
13763
- drag(e.getX(), e.getY(), e.getModifiersEx());
14296
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1376414297
1376514298 //try { Thread.sleep(1); } catch (Exception ex) {}
1376614299 }
....@@ -13933,6 +14466,7 @@
1393314466
1393414467 public void run()
1393514468 {
14469
+ new Exception().printStackTrace();
1393614470 System.exit(0);
1393714471 for (;;)
1393814472 {
....@@ -13996,7 +14530,7 @@
1399614530 {
1399714531 Globals.lighttouched = true;
1399814532 }
13999
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14533
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1400014534 }
1400114535 //else
1400214536 }
....@@ -14010,12 +14544,12 @@
1401014544 void GoDown(int mod)
1401114545 {
1401214546 MODIFIERS |= COMMAND;
14013
- /*
14547
+ /**/
1401414548 if((mod&SHIFT) == SHIFT)
1401514549 manipCamera.RotatePosition(0, -speed);
1401614550 else
14017
- manipCamera.BackForth(0, -speed*delta, getWidth());
14018
- */
14551
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14552
+ /**/
1401914553 if ((mod & SHIFT) == SHIFT)
1402014554 {
1402114555 mouseMode = mouseMode; // VR??
....@@ -14031,12 +14565,12 @@
1403114565 void GoUp(int mod)
1403214566 {
1403314567 MODIFIERS |= COMMAND;
14034
- /*
14568
+ /**/
1403514569 if((mod&SHIFT) == SHIFT)
1403614570 manipCamera.RotatePosition(0, speed);
1403714571 else
14038
- manipCamera.BackForth(0, speed*delta, getWidth());
14039
- */
14572
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14573
+ /**/
1404014574 if ((mod & SHIFT) == SHIFT)
1404114575 {
1404214576 mouseMode = mouseMode;
....@@ -14052,12 +14586,12 @@
1405214586 void GoLeft(int mod)
1405314587 {
1405414588 MODIFIERS |= COMMAND;
14055
- /*
14589
+ /**/
1405614590 if((mod&SHIFT) == SHIFT)
14057
- manipCamera.RotatePosition(speed, 0);
14058
- else
1405914591 manipCamera.Translate(speed*delta, 0, getWidth());
14060
- */
14592
+ else
14593
+ manipCamera.RotatePosition(speed, 0);
14594
+ /**/
1406114595 if ((mod & SHIFT) == SHIFT)
1406214596 {
1406314597 mouseMode = mouseMode;
....@@ -14073,12 +14607,12 @@
1407314607 void GoRight(int mod)
1407414608 {
1407514609 MODIFIERS |= COMMAND;
14076
- /*
14610
+ /**/
1407714611 if((mod&SHIFT) == SHIFT)
14078
- manipCamera.RotatePosition(-speed, 0);
14079
- else
1408014612 manipCamera.Translate(-speed*delta, 0, getWidth());
14081
- */
14613
+ else
14614
+ manipCamera.RotatePosition(-speed, 0);
14615
+ /**/
1408214616 if ((mod & SHIFT) == SHIFT)
1408314617 {
1408414618 mouseMode = mouseMode;
....@@ -14096,7 +14630,7 @@
1409614630 int X, Y;
1409714631 boolean SX, SY;
1409814632
14099
- void drag(int x, int y, int modifiers)
14633
+ void drag(int x, int y, int modifiers, int modifiersex)
1410014634 {
1410114635 if (IsFrozen())
1410214636 {
....@@ -14105,17 +14639,17 @@
1410514639
1410614640 drag = true; // NEW
1410714641
14108
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14642
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1410914643
1411014644 X = x;
1411114645 Y = y;
1411214646 // floating state for animation
14113
- MODIFIERS = modifiers;
14114
- modifiers &= ~1024;
14647
+ MODIFIERS = modifiersex;
14648
+ modifiersex &= ~1024;
1411514649 if (false) // modifiers != 0)
1411614650 {
1411714651 //new Exception().printStackTrace();
14118
- System.out.println("mouseDragged: " + modifiers);
14652
+ System.out.println("mouseDragged: " + modifiersex);
1411914653 System.out.println("SHIFT = " + SHIFT);
1412014654 System.out.println("CONTROL = " + COMMAND);
1412114655 System.out.println("META = " + META);
....@@ -14135,7 +14669,8 @@
1413514669 info.camera = renderCamera;
1413614670 info.x = x;
1413714671 info.y = y;
14138
- object.editWindow.copy.doEditDrag(info);
14672
+ object.GetWindow().copy
14673
+ .doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1413914674 } else
1414014675 {
1414114676 if (x < startX)
....@@ -14287,7 +14822,6 @@
1428714822 public void mouseMoved(MouseEvent e)
1428814823 {
1428914824 //System.out.println("mouseMoved: " + e);
14290
-
1429114825 if (isRenderer)
1429214826 return;
1429314827
....@@ -14300,7 +14834,9 @@
1430014834 ci.camera = renderCamera;
1430114835 if (!isRenderer)
1430214836 {
14303
- if (object.editWindow.copy.doEditClick(ci, 0))
14837
+ //ObjEditor editWindow = object.editWindow;
14838
+ //Object3D copy = editWindow.copy;
14839
+ if (object.doEditClick(ci, 0))
1430414840 {
1430514841 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1430614842 } else
....@@ -14312,7 +14848,11 @@
1431214848
1431314849 public void mouseReleased(MouseEvent e)
1431414850 {
14851
+ Globals.MOUSEDRAGGED = false;
14852
+
1431514853 movingcamera = false;
14854
+ X = 0; // getBounds().width/2;
14855
+ Y = 0; // getBounds().height/2;
1431614856 //System.out.println("mouseReleased: " + e);
1431714857 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1431814858 }
....@@ -14335,9 +14875,9 @@
1433514875 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1433614876 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1433714877
14338
- if (control || command || IsFrozen())
14878
+// No delay if (control || command || IsFrozen())
1433914879 timeout = true;
14340
- else
14880
+// ?? May 2019 else
1434114881 // timer.setDelay((modifiers & 128) != 0?0:350);
1434214882 mouseDown = false;
1434314883 if (!control && !command) // june 2013
....@@ -14447,7 +14987,7 @@
1444714987 System.out.println("keyReleased: " + e);
1444814988 }
1444914989
14450
- void SetMouseMode(int modifiers)
14990
+ void SetMouseMode(int modifiers, int modifiersex)
1445114991 {
1445214992 //System.out.println("SetMouseMode = " + modifiers);
1445314993 //modifiers &= ~1024;
....@@ -14459,25 +14999,25 @@
1445914999 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1446015000 // return;
1446115001 //System.out.println("SetMode = " + modifiers);
14462
- if ((modifiers & WHEEL) == WHEEL)
15002
+ if ((modifiersex & WHEEL) == WHEEL)
1446315003 {
1446415004 mouseMode |= ZOOM;
1446515005 }
1446615006
1446715007 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
14468
- if (capsLocked || (modifiers & META) == META)
15008
+ if (capsLocked) // || (modifiers & META) == META)
1446915009 {
1447015010 mouseMode |= VR; // BACKFORTH;
1447115011 }
14472
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
15012
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1447315013 {
1447415014 mouseMode |= SELECT;
1447515015 }
14476
- if ((modifiers & COMMAND) == COMMAND)
15016
+ if ((modifiersex & COMMAND) == COMMAND)
1447715017 {
1447815018 mouseMode |= SELECT;
1447915019 }
14480
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15020
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
1448115021 {
1448215022 mouseMode &= ~VR;
1448315023 mouseMode |= TRANSLATE;
....@@ -14506,7 +15046,7 @@
1450615046
1450715047 if (isRenderer) //
1450815048 {
14509
- SetMouseMode(modifiers);
15049
+ SetMouseMode(0, modifiers);
1451015050 }
1451115051
1451215052 Globals.theRenderer.keyPressed(key);
....@@ -14568,7 +15108,8 @@
1456815108 // break;
1456915109 case 'T':
1457015110 CACHETEXTURE ^= true;
14571
- textures.clear();
15111
+ texturepigment.clear();
15112
+ texturebump.clear();
1457215113 // repaint();
1457315114 break;
1457415115 case 'Y':
....@@ -14653,7 +15194,9 @@
1465315194 case 'E' : COMPACT ^= true;
1465415195 repaint();
1465515196 break;
14656
- case 'W' : DEBUGHSB ^= true;
15197
+ case 'W' : // Wide Window (fullscreen)
15198
+ //DEBUGHSB ^= true;
15199
+ ObjEditor.theFrame.ToggleFullScreen();
1465715200 repaint();
1465815201 break;
1465915202 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14678,8 +15221,8 @@
1467815221 RevertCamera();
1467915222 repaint();
1468015223 break;
14681
- case 'L':
1468215224 case 'l':
15225
+ //case 'L':
1468315226 if (lightMode)
1468415227 {
1468515228 lightMode = false;
....@@ -14822,9 +15365,9 @@
1482215365 case '_':
1482315366 kompactbit = 5;
1482415367 break;
14825
- case '+':
14826
- kompactbit = 6;
14827
- break;
15368
+// case '+':
15369
+// kompactbit = 6;
15370
+// break;
1482815371 case ' ':
1482915372 lightMode ^= true;
1483015373 Globals.lighttouched = true;
....@@ -14836,13 +15379,14 @@
1483615379 case ESC:
1483715380 RENDERPROGRAM += 1;
1483815381 RENDERPROGRAM %= 3;
15382
+
1483915383 repaint();
1484015384 break;
1484115385 case 'Z':
1484215386 //RESIZETEXTURE ^= true;
1484315387 //break;
1484415388 case 'z':
14845
- RENDERSHADOW ^= true;
15389
+ Globals.RENDERSHADOW ^= true;
1484615390 Globals.lighttouched = true;
1484715391 repaint();
1484815392 break;
....@@ -14875,8 +15419,9 @@
1487515419 case DELETE:
1487615420 ClearSelection();
1487715421 break;
14878
- /*
1487915422 case '+':
15423
+
15424
+ /*
1488015425 //fontsize += 1;
1488115426 bbzoom *= 2;
1488215427 repaint();
....@@ -14893,17 +15438,17 @@
1489315438 case '=':
1489415439 IncDepth();
1489515440 //fontsize += 1;
14896
- object.editWindow.refreshContents(true);
15441
+ object.GetWindow().refreshContents(true);
1489715442 maskbit = 6;
1489815443 break;
1489915444 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1490015445 DecDepth();
1490115446 maskbit = 5;
1490215447 //if(fontsize > 1) fontsize -= 1;
14903
- if (object.editWindow == null)
14904
- new Exception().printStackTrace();
14905
- else
14906
- object.editWindow.refreshContents(true);
15448
+// if (object.editWindow == null)
15449
+// new Exception().printStackTrace();
15450
+// else
15451
+ object.GetWindow().refreshContents(true);
1490715452 break;
1490815453 case '{':
1490915454 manipCamera.shaper_fovy /= 1.1;
....@@ -14966,7 +15511,7 @@
1496615511 //mode = ROTATE;
1496715512 if ((MODIFIERS & COMMAND) == 0) // VR??
1496815513 {
14969
- SetMouseMode(modifiers);
15514
+ SetMouseMode(0, modifiers);
1497015515 }
1497115516 }
1497215517
....@@ -15100,8 +15645,9 @@
1510015645
1510115646 protected void processMouseMotionEvent(MouseEvent e)
1510215647 {
15103
- //System.out.println("processMouseMotionEvent: " + mouseMode);
15104
- if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15648
+ //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
15649
+ //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15650
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1510515651 {
1510615652 mouseMoved(e);
1510715653 } else
....@@ -15126,11 +15672,12 @@
1512615672 }
1512715673 */
1512815674
15129
- object.editWindow.EditSelection();
15675
+ object.GetWindow().EditSelection(false);
1513015676 }
1513115677
1513215678 void SelectParent()
1513315679 {
15680
+ new Exception().printStackTrace();
1513415681 System.exit(0);
1513515682 Composite group = (Composite) object;
1513615683 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -15142,10 +15689,10 @@
1514215689 {
1514315690 //selectees.remove(i);
1514415691 System.out.println("select parent of " + elem);
15145
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15692
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1514615693 } else
1514715694 {
15148
- group.editWindow.Select(elem.GetTreePath(), first, true);
15695
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1514915696 }
1515015697
1515115698 first = false;
....@@ -15154,6 +15701,7 @@
1515415701
1515515702 void SelectChildren()
1515615703 {
15704
+ new Exception().printStackTrace();
1515715705 System.exit(0);
1515815706 /*
1515915707 Composite group = (Composite) object;
....@@ -15186,12 +15734,12 @@
1518615734 for (int j = 0; j < group.children.size(); j++)
1518715735 {
1518815736 elem = (Object3D) group.children.elementAt(j);
15189
- object.editWindow.Select(elem.GetTreePath(), first, true);
15737
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1519015738 first = false;
1519115739 }
1519215740 } else
1519315741 {
15194
- object.editWindow.Select(elem.GetTreePath(), first, true);
15742
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1519515743 }
1519615744
1519715745 first = false;
....@@ -15202,21 +15750,21 @@
1520215750 {
1520315751 //Composite group = (Composite) object;
1520415752 Object3D group = object;
15205
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15753
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1520615754 }
1520715755
1520815756 void ResetTransform(int mask)
1520915757 {
1521015758 //Composite group = (Composite) object;
1521115759 Object3D group = object;
15212
- group.editWindow.ResetTransform(mask);
15760
+ group.GetWindow().ResetTransform(mask);
1521315761 }
1521415762
1521515763 void FlipTransform()
1521615764 {
1521715765 //Composite group = (Composite) object;
1521815766 Object3D group = object;
15219
- group.editWindow.FlipTransform();
15767
+ group.GetWindow().FlipTransform();
1522015768 // group.editWindow.ReduceMesh(true);
1522115769 }
1522215770
....@@ -15224,7 +15772,7 @@
1522415772 {
1522515773 //Composite group = (Composite) object;
1522615774 Object3D group = object;
15227
- group.editWindow.PrintMemory();
15775
+ group.GetWindow().PrintMemory();
1522815776 // group.editWindow.ReduceMesh(true);
1522915777 }
1523015778
....@@ -15232,7 +15780,7 @@
1523215780 {
1523315781 //Composite group = (Composite) object;
1523415782 Object3D group = object;
15235
- group.editWindow.ResetCentroid();
15783
+ group.GetWindow().ResetCentroid();
1523615784 }
1523715785
1523815786 void IncDepth()
....@@ -15318,7 +15866,9 @@
1531815866 info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1531915867 //Image img = CreateImage(width, height);
1532015868 //System.out.println("width = " + width + "; height = " + height + "\n");
15869
+
1532115870 Graphics gr = g; // img.getGraphics();
15871
+
1532215872 if (!hasMarquee)
1532315873 {
1532415874 if (Xmin < Xmax) // !locked)
....@@ -15406,6 +15956,7 @@
1540615956 info.bounds.y += (height - desired) / 2;
1540715957 }
1540815958 }
15959
+
1540915960 info.g = gr;
1541015961 info.camera = renderCamera;
1541115962 /*
....@@ -15415,15 +15966,55 @@
1541515966 */
1541615967 if (!isRenderer)
1541715968 {
15418
- object.drawEditHandles(info, 0);
15969
+ Grafreed.Assert(object != null);
15970
+ Grafreed.Assert(object.selection != null);
15971
+ if (object.selection.Size() > 0)
15972
+ {
15973
+ int hitSomething = object.selection.get(0).hitSomething;
15974
+
15975
+ info.DX = 0;
15976
+ info.DY = 0;
15977
+ info.W = 1;
15978
+ if (hitSomething == Object3D.hitCenter)
15979
+ {
15980
+ info.DX = X;
15981
+ if (X != 0)
15982
+ info.DX -= info.bounds.width/2;
15983
+
15984
+ info.DY = Y;
15985
+ if (Y != 0)
15986
+ info.DY -= info.bounds.height/2;
15987
+ }
15988
+
15989
+ object.drawEditHandles(info, 0);
15990
+
15991
+ if (drag && (X != 0 || Y != 0))
15992
+ {
15993
+ switch (hitSomething)
15994
+ {
15995
+ case Object3D.hitCenter: gr.setColor(Color.pink);
15996
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15997
+ break;
15998
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
15999
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16000
+ break;
16001
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16002
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16003
+ break;
16004
+ }
16005
+
16006
+ }
16007
+ }
1541916008 }
1542016009 }
16010
+
1542116011 if (isRenderer)
1542216012 {
1542316013 //gr.setColor(Color.black);
1542416014 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1542516015 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1542616016 }
16017
+
1542716018 if (hasMarquee)
1542816019 {
1542916020 gr.setXORMode(Color.white);
....@@ -15536,6 +16127,7 @@
1553616127 public boolean mouseDown(Event evt, int x, int y)
1553716128 {
1553816129 System.out.println("mouseDown: " + evt);
16130
+ System.exit(0);
1553916131 /*
1554016132 locked = true;
1554116133 drag = false;
....@@ -15579,7 +16171,7 @@
1557916171 {
1558016172 keyPressed(0, modifiers);
1558116173 }
15582
- clickStart(x, y, modifiers);
16174
+ // clickStart(x, y, modifiers);
1558316175 return true;
1558416176 }
1558516177
....@@ -15697,7 +16289,7 @@
1569716289 {
1569816290 keyReleased(0, 0);
1569916291 }
15700
- drag(x, y, modifiers);
16292
+ drag(x, y, 0, modifiers);
1570116293 return true;
1570216294 }
1570316295
....@@ -15829,7 +16421,7 @@
1582916421 Object3D object;
1583016422 static Object3D trackedobject;
1583116423 Camera renderCamera; // Light or Eye (or Occlusion)
15832
- /*static*/ Camera manipCamera; // Light or Eye
16424
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1583316425 /*static*/ Camera eyeCamera;
1583416426 /*static*/ Camera lightCamera;
1583516427 int cameracount;
....@@ -16114,16 +16706,16 @@
1611416706 cStatic.objectstack[materialdepth++] = checker;
1611516707 //System.out.println("material " + material);
1611616708 //Applet3D.tracein(this, selected);
16117
- vector2buffer = checker.projectedVertices;
16709
+ //vector2buffer = checker.projectedVertices;
1611816710
1611916711 //checker.GetMaterial().Draw(this, false); // true);
16120
- DrawMaterial(checker.GetMaterial(), false); // true);
16712
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1612116713
1612216714 materialdepth -= 1;
1612316715 if (materialdepth > 0)
1612416716 {
16125
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16126
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
16717
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16718
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1612716719 }
1612816720 //checker.GetMaterial().opacity = 1f;
1612916721 ////checker.GetMaterial().ambient = 1f;
....@@ -16209,6 +16801,14 @@
1620916801 }
1621016802 }
1621116803
16804
+ private Object3D GetFolder()
16805
+ {
16806
+ Object3D folder = object.GetWindow().copy;
16807
+ if (object.GetWindow().copy.selection.Size() > 0)
16808
+ folder = object.GetWindow().copy.selection.elementAt(0);
16809
+ return folder;
16810
+ }
16811
+
1621216812 class SelectBuffer implements GLEventListener
1621316813 {
1621416814
....@@ -16267,6 +16867,7 @@
1626716867 {
1626816868 if (!selection)
1626916869 {
16870
+ new Exception().printStackTrace();
1627016871 System.exit(0);
1627116872 return;
1627216873 }
....@@ -16287,6 +16888,17 @@
1628716888
1628816889 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1628916890
16891
+ if (PAINTMODE)
16892
+ {
16893
+ if (object.GetWindow().copy.selection.Size() > 0)
16894
+ {
16895
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16896
+
16897
+ // Make what you paint not selectable.
16898
+ paintobj.ResetSelectable();
16899
+ }
16900
+ }
16901
+
1629016902 //int tmp = selection_view;
1629116903 //selection_view = -1;
1629216904 int temp = DrawMode();
....@@ -16298,6 +16910,17 @@
1629816910 // temp = DEFAULT; // patch for selection debug
1629916911 Globals.drawMode = temp; // WARNING
1630016912
16913
+ if (PAINTMODE)
16914
+ {
16915
+ if (object.GetWindow().copy.selection.Size() > 0)
16916
+ {
16917
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16918
+
16919
+ // Revert.
16920
+ paintobj.RestoreSelectable();
16921
+ }
16922
+ }
16923
+
1630116924 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1630216925
1630316926 // trying different ways of getting the depth info over
....@@ -16345,6 +16968,8 @@
1634516968 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1634616969 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1634716970 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
16971
+
16972
+ CreateSelectedPoint();
1634816973
1634916974 // Will fit the mesh !!!
1635016975 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16394,34 +17019,36 @@
1639417019 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]));
1639517020 }
1639617021
16397
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
17022
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1639817023 }
1639917024 }
1640017025
1640117026 if (!movingcamera && !PAINTMODE)
16402
- object.editWindow.ScreenFitPoint(); // fev 2014
17027
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1640317028
16404
- if (PAINTMODE && GrafreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17029
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1640517030 {
16406
- Object3D paintobj = GrafreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17031
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1640717032
16408
- Object3D group = new Object3D("inst" + paintcount++);
17033
+ if (object.GetWindow().copy.selection.Size() > 0)
17034
+ {
17035
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1640917036
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();
17037
+ Object3D inst = new Object3D("inst" + paintcount++);
17038
+
17039
+ inst.CreateMaterial(); // use a void leaf to select instances
17040
+
17041
+ inst.add(paintobj); // link
17042
+
17043
+ object.GetWindow().SnapObject(inst);
17044
+
17045
+ Object3D folder = paintFolder; // GetFolder();
17046
+
17047
+ folder.add(inst);
17048
+
17049
+ object.GetWindow().ResetModel();
17050
+ object.GetWindow().refreshContents();
17051
+ }
1642517052 }
1642617053 else
1642717054 paintcount = 0;
....@@ -16460,6 +17087,11 @@
1646017087 //System.out.println("objects[color] = " + objects[color]);
1646117088 //objects[color].Select();
1646217089 indexcount = 0;
17090
+ ObjEditor window = object.GetWindow();
17091
+ if (window != null && deselect)
17092
+ {
17093
+ window.Select(null, deselect, true);
17094
+ }
1646317095 object.Select(color, deselect);
1646417096 }
1646517097
....@@ -16559,7 +17191,7 @@
1655917191 gl.glDisable(gl.GL_CULL_FACE);
1656017192 }
1656117193
16562
- if (!RENDERSHADOW)
17194
+ if (!Globals.RENDERSHADOW)
1656317195 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1656417196
1656517197 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -16569,7 +17201,7 @@
1656917201 //gl.glColorMask(false, false, false, false);
1657017202
1657117203 //render_scene_from_light_view(gl, drawable, 0, 0);
16572
- if (RENDERSHADOW && Globals.lighttouched && !movingcamera) // && !parent.IsFreezed())
17204
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1657317205 {
1657417206 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1657517207
....@@ -16985,23 +17617,15 @@
1698517617 int AAbuffersize = 0;
1698617618
1698717619 //double[] selectedpoint = new double[3];
16988
- static Superellipsoid selectedpoint = new Superellipsoid();
17620
+ static Superellipsoid selectedpoint;
1698917621 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();
17622
+ static Sphere debugpointG;
17623
+ static Sphere debugpointP;
17624
+ static Sphere debugpointC;
17625
+ static Sphere debugpointR;
1699417626
1699517627 static Sphere debugpoints[] = new Sphere[8];
1699617628
16997
- static
16998
- {
16999
- for (int i=0; i<8; i++)
17000
- {
17001
- debugpoints[i] = new Sphere();
17002
- }
17003
- }
17004
-
1700517629 static void InitPoints(float radius)
1700617630 {
1700717631 for (int i=0; i<8; i++)