Normand Briere
2019-07-23 cf7cfa1c792eebba606a48aa648893f6e4873263
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
....@@ -12456,8 +12923,8 @@
1245612923
1245712924 // display shadow only (bump == 0)
1245812925 "SUB temp.x, half.x, shadow.x;" +
12459
- "MOV temp.y, -params6.x;" +
12460
- "SLT temp.z, temp.y, zero.x;" +
12926
+ "MOV temp.y, -params5.z;" + // params6.x;" +
12927
+ "SLT temp.z, temp.y, -one2048th.x;" +
1246112928 "SUB temp.y, one.x, temp.z;" +
1246212929 "MUL temp.x, temp.x, temp.y;" +
1246312930 "KIL temp.x;" +
....@@ -12586,8 +13053,10 @@
1258613053 "MAX ndotl.x, ndotl.x, -ndotl.x;" +
1258713054
1258813055 "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
13056
+ // Tuning for default skin
13057
+ //"ADD temp.x, temp.x, options2.z;" + // lightsheen
13058
+ "MAD temp.x, options2.z, half.y, temp.x;" + // lightsheen
13059
+ "ADD temp.y, one.y, options2.y;" + // subsurface
1259113060 "MUL temp.x, temp.x, temp.y;" +
1259213061
1259313062 "MUL saturation, saturation, temp.xxxx;" +
....@@ -12786,7 +13255,7 @@
1278613255 //once = true;
1278713256 }
1278813257
12789
- System.out.print("Program #" + mode + "; length = " + program.length());
13258
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1279013259 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1279113260 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1279213261
....@@ -12919,12 +13388,16 @@
1291913388
1292013389 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1292113390 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13391
+
13392
+ // Compare fragment depth in light space with shadowmap.
1292213393 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1292313394 "SGE temp.y, temp.x, zero.x;" +
12924
- "SUB " + shadow + ".y, one.x, temp.y;" +
13395
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13396
+
13397
+ // Reverse comparison
1292513398 "SUB temp.x, one.x, temp.x;" +
1292613399 "MUL " + shadow + ".x, temp.x, temp.y;" +
12927
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13400
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1292813401 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1292913402
1293013403 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -12938,6 +13411,10 @@
1293813411 // No shadow for backface
1293913412 "DP3 temp.x, normal, lightd;" +
1294013413 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13414
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13415
+
13416
+ // No shadow when out of frustrum
13417
+ "SGE temp.x, " + depth + ".z, one.z;" +
1294113418 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1294213419 "";
1294313420 }
....@@ -13084,7 +13561,8 @@
1308413561 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1308513562 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1308613563 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13087
- Object3D.cVector2[] vector2buffer;
13564
+
13565
+ //Object3D.cVector2[] vector2buffer;
1308813566
1308913567 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1309013568 // OUT : diff, spec
....@@ -13100,9 +13578,10 @@
1310013578 "DP3 " + dest + ".z," + "normals," + "eye;" +
1310113579 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1310213580 //"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;" +
13581
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13582
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13583
+
13584
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1310613585 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1310713586 "RCP " + dest + ".w," + dest + ".w;" +
1310813587 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13496,7 +13975,7 @@
1349613975 public void mousePressed(MouseEvent e)
1349713976 {
1349813977 //System.out.println("mousePressed: " + e);
13499
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
13978
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1350013979 }
1350113980
1350213981 static long prevtime = 0;
....@@ -13523,6 +14002,7 @@
1352314002
1352414003 //System.err.println("Dtime = " + Dtime + "; units = " + e.getUnitsToScroll() + "; ratio (units/ms) = " + ratio);
1352514004
14005
+ if (BUTTONLESSWHEEL)
1352614006 if (Math.abs(ratio) < 0.1 || Math.abs(Dtime) == 0) // < 30)
1352714007 {
1352814008 return;
....@@ -13531,7 +14011,7 @@
1353114011 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
1353214012
1353314013 // TIMER
13534
- if (!wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
14014
+ if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
1353514015 {
1353614016 keepboxmode = BOXMODE;
1353714017 keepsupport = SUPPORT;
....@@ -13571,8 +14051,8 @@
1357114051 // mode |= META;
1357214052 //}
1357314053
13574
- SetMouseMode(WHEEL | e.getModifiersEx());
13575
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14054
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14055
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1357614056 anchorX = ax;
1357714057 anchorY = ay;
1357814058 prevX = px;
....@@ -13606,6 +14086,7 @@
1360614086 else
1360714087 if (evt.getSource() == AAtimer)
1360814088 {
14089
+ Globals.TIMERRUNNING = false;
1360914090 if (mouseDown)
1361014091 {
1361114092 //new Exception().printStackTrace();
....@@ -13631,6 +14112,10 @@
1363114112 // LIVE = waslive;
1363214113 // wasliveok = true;
1363314114 // waslive = false;
14115
+
14116
+ // May 2019 Forget it:
14117
+ if (true)
14118
+ return;
1363414119
1363514120 // source == timer
1363614121 if (mouseDown)
....@@ -13661,7 +14146,7 @@
1366114146
1366214147 // fev 2014???
1366314148 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13664
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14149
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1366514150 pingthread.StepToTarget(true); // true);
1366614151 }
1366714152 // if (!LIVE)
....@@ -13670,12 +14155,13 @@
1367014155
1367114156 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1367214157
13673
- void clickStart(int x, int y, int modifiers)
14158
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1367414159 {
1367514160 if (!wasliveok)
1367614161 return;
1367714162
1367814163 AAtimer.restart(); //
14164
+ Globals.TIMERRUNNING = true;
1367914165
1368014166 // waslive = LIVE;
1368114167 // LIVE = false;
....@@ -13687,7 +14173,7 @@
1368714173 // touched = true; // main DL
1368814174 if (isRenderer)
1368914175 {
13690
- SetMouseMode(modifiers);
14176
+ SetMouseMode(modifiers, modifiersex);
1369114177 }
1369214178
1369314179 selectX = anchorX = x;
....@@ -13700,7 +14186,7 @@
1370014186 clicked = true;
1370114187 hold = false;
1370214188
13703
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14189
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1370414190 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1370514191 {
1370614192 // System.out.println("RESTART II " + modifiers);
....@@ -13731,7 +14217,7 @@
1373114217 info.camera = renderCamera;
1373214218 info.x = x;
1373314219 info.y = y;
13734
- info.modifiers = modifiers;
14220
+ info.modifiers = modifiersex;
1373514221 editObj = object.doEditClick(info, 0);
1373614222 if (!editObj)
1373714223 {
....@@ -13748,11 +14234,14 @@
1374814234
1374914235 public void mouseDragged(MouseEvent e)
1375014236 {
14237
+ Globals.MOUSEDRAGGED = true;
14238
+
14239
+ //System.out.println("mouseDragged: " + e);
1375114240 if (isRenderer)
1375214241 movingcamera = true;
14242
+
1375314243 //if (drawing)
1375414244 //return;
13755
- //System.out.println("mouseDragged: " + e);
1375614245 if ((e.getModifiersEx() & CTRL) != 0
1375714246 || (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen())
1375814247 {
....@@ -13760,7 +14249,7 @@
1376014249 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1376114250 }
1376214251 else
13763
- drag(e.getX(), e.getY(), e.getModifiersEx());
14252
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1376414253
1376514254 //try { Thread.sleep(1); } catch (Exception ex) {}
1376614255 }
....@@ -13933,6 +14422,7 @@
1393314422
1393414423 public void run()
1393514424 {
14425
+ new Exception().printStackTrace();
1393614426 System.exit(0);
1393714427 for (;;)
1393814428 {
....@@ -13996,7 +14486,7 @@
1399614486 {
1399714487 Globals.lighttouched = true;
1399814488 }
13999
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14489
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1400014490 }
1400114491 //else
1400214492 }
....@@ -14010,12 +14500,12 @@
1401014500 void GoDown(int mod)
1401114501 {
1401214502 MODIFIERS |= COMMAND;
14013
- /*
14503
+ /**/
1401414504 if((mod&SHIFT) == SHIFT)
1401514505 manipCamera.RotatePosition(0, -speed);
1401614506 else
14017
- manipCamera.BackForth(0, -speed*delta, getWidth());
14018
- */
14507
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14508
+ /**/
1401914509 if ((mod & SHIFT) == SHIFT)
1402014510 {
1402114511 mouseMode = mouseMode; // VR??
....@@ -14031,12 +14521,12 @@
1403114521 void GoUp(int mod)
1403214522 {
1403314523 MODIFIERS |= COMMAND;
14034
- /*
14524
+ /**/
1403514525 if((mod&SHIFT) == SHIFT)
1403614526 manipCamera.RotatePosition(0, speed);
1403714527 else
14038
- manipCamera.BackForth(0, speed*delta, getWidth());
14039
- */
14528
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14529
+ /**/
1404014530 if ((mod & SHIFT) == SHIFT)
1404114531 {
1404214532 mouseMode = mouseMode;
....@@ -14052,12 +14542,12 @@
1405214542 void GoLeft(int mod)
1405314543 {
1405414544 MODIFIERS |= COMMAND;
14055
- /*
14545
+ /**/
1405614546 if((mod&SHIFT) == SHIFT)
14057
- manipCamera.RotatePosition(speed, 0);
14058
- else
1405914547 manipCamera.Translate(speed*delta, 0, getWidth());
14060
- */
14548
+ else
14549
+ manipCamera.RotatePosition(speed, 0);
14550
+ /**/
1406114551 if ((mod & SHIFT) == SHIFT)
1406214552 {
1406314553 mouseMode = mouseMode;
....@@ -14073,12 +14563,12 @@
1407314563 void GoRight(int mod)
1407414564 {
1407514565 MODIFIERS |= COMMAND;
14076
- /*
14566
+ /**/
1407714567 if((mod&SHIFT) == SHIFT)
14078
- manipCamera.RotatePosition(-speed, 0);
14079
- else
1408014568 manipCamera.Translate(-speed*delta, 0, getWidth());
14081
- */
14569
+ else
14570
+ manipCamera.RotatePosition(-speed, 0);
14571
+ /**/
1408214572 if ((mod & SHIFT) == SHIFT)
1408314573 {
1408414574 mouseMode = mouseMode;
....@@ -14096,7 +14586,7 @@
1409614586 int X, Y;
1409714587 boolean SX, SY;
1409814588
14099
- void drag(int x, int y, int modifiers)
14589
+ void drag(int x, int y, int modifiers, int modifiersex)
1410014590 {
1410114591 if (IsFrozen())
1410214592 {
....@@ -14105,17 +14595,17 @@
1410514595
1410614596 drag = true; // NEW
1410714597
14108
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14598
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1410914599
1411014600 X = x;
1411114601 Y = y;
1411214602 // floating state for animation
14113
- MODIFIERS = modifiers;
14114
- modifiers &= ~1024;
14603
+ MODIFIERS = modifiersex;
14604
+ modifiersex &= ~1024;
1411514605 if (false) // modifiers != 0)
1411614606 {
1411714607 //new Exception().printStackTrace();
14118
- System.out.println("mouseDragged: " + modifiers);
14608
+ System.out.println("mouseDragged: " + modifiersex);
1411914609 System.out.println("SHIFT = " + SHIFT);
1412014610 System.out.println("CONTROL = " + COMMAND);
1412114611 System.out.println("META = " + META);
....@@ -14135,7 +14625,8 @@
1413514625 info.camera = renderCamera;
1413614626 info.x = x;
1413714627 info.y = y;
14138
- object.editWindow.copy.doEditDrag(info);
14628
+ object.GetWindow().copy
14629
+ .doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1413914630 } else
1414014631 {
1414114632 if (x < startX)
....@@ -14287,7 +14778,6 @@
1428714778 public void mouseMoved(MouseEvent e)
1428814779 {
1428914780 //System.out.println("mouseMoved: " + e);
14290
-
1429114781 if (isRenderer)
1429214782 return;
1429314783
....@@ -14300,7 +14790,9 @@
1430014790 ci.camera = renderCamera;
1430114791 if (!isRenderer)
1430214792 {
14303
- if (object.editWindow.copy.doEditClick(ci, 0))
14793
+ //ObjEditor editWindow = object.editWindow;
14794
+ //Object3D copy = editWindow.copy;
14795
+ if (object.doEditClick(ci, 0))
1430414796 {
1430514797 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1430614798 } else
....@@ -14312,7 +14804,11 @@
1431214804
1431314805 public void mouseReleased(MouseEvent e)
1431414806 {
14807
+ Globals.MOUSEDRAGGED = false;
14808
+
1431514809 movingcamera = false;
14810
+ X = 0; // getBounds().width/2;
14811
+ Y = 0; // getBounds().height/2;
1431614812 //System.out.println("mouseReleased: " + e);
1431714813 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1431814814 }
....@@ -14335,9 +14831,9 @@
1433514831 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1433614832 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1433714833
14338
- if (control || command || IsFrozen())
14834
+// No delay if (control || command || IsFrozen())
1433914835 timeout = true;
14340
- else
14836
+// ?? May 2019 else
1434114837 // timer.setDelay((modifiers & 128) != 0?0:350);
1434214838 mouseDown = false;
1434314839 if (!control && !command) // june 2013
....@@ -14447,7 +14943,7 @@
1444714943 System.out.println("keyReleased: " + e);
1444814944 }
1444914945
14450
- void SetMouseMode(int modifiers)
14946
+ void SetMouseMode(int modifiers, int modifiersex)
1445114947 {
1445214948 //System.out.println("SetMouseMode = " + modifiers);
1445314949 //modifiers &= ~1024;
....@@ -14459,25 +14955,25 @@
1445914955 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1446014956 // return;
1446114957 //System.out.println("SetMode = " + modifiers);
14462
- if ((modifiers & WHEEL) == WHEEL)
14958
+ if ((modifiersex & WHEEL) == WHEEL)
1446314959 {
1446414960 mouseMode |= ZOOM;
1446514961 }
1446614962
1446714963 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
14468
- if (capsLocked || (modifiers & META) == META)
14964
+ if (capsLocked) // || (modifiers & META) == META)
1446914965 {
1447014966 mouseMode |= VR; // BACKFORTH;
1447114967 }
14472
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
14968
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1447314969 {
1447414970 mouseMode |= SELECT;
1447514971 }
14476
- if ((modifiers & COMMAND) == COMMAND)
14972
+ if ((modifiersex & COMMAND) == COMMAND)
1447714973 {
1447814974 mouseMode |= SELECT;
1447914975 }
14480
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
14976
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
1448114977 {
1448214978 mouseMode &= ~VR;
1448314979 mouseMode |= TRANSLATE;
....@@ -14506,7 +15002,7 @@
1450615002
1450715003 if (isRenderer) //
1450815004 {
14509
- SetMouseMode(modifiers);
15005
+ SetMouseMode(0, modifiers);
1451015006 }
1451115007
1451215008 Globals.theRenderer.keyPressed(key);
....@@ -14568,7 +15064,8 @@
1456815064 // break;
1456915065 case 'T':
1457015066 CACHETEXTURE ^= true;
14571
- textures.clear();
15067
+ texturepigment.clear();
15068
+ texturebump.clear();
1457215069 // repaint();
1457315070 break;
1457415071 case 'Y':
....@@ -14653,7 +15150,9 @@
1465315150 case 'E' : COMPACT ^= true;
1465415151 repaint();
1465515152 break;
14656
- case 'W' : DEBUGHSB ^= true;
15153
+ case 'W' : // Wide Window (fullscreen)
15154
+ //DEBUGHSB ^= true;
15155
+ ObjEditor.theFrame.ToggleFullScreen();
1465715156 repaint();
1465815157 break;
1465915158 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14678,8 +15177,8 @@
1467815177 RevertCamera();
1467915178 repaint();
1468015179 break;
14681
- case 'L':
1468215180 case 'l':
15181
+ //case 'L':
1468315182 if (lightMode)
1468415183 {
1468515184 lightMode = false;
....@@ -14822,9 +15321,9 @@
1482215321 case '_':
1482315322 kompactbit = 5;
1482415323 break;
14825
- case '+':
14826
- kompactbit = 6;
14827
- break;
15324
+// case '+':
15325
+// kompactbit = 6;
15326
+// break;
1482815327 case ' ':
1482915328 lightMode ^= true;
1483015329 Globals.lighttouched = true;
....@@ -14836,13 +15335,14 @@
1483615335 case ESC:
1483715336 RENDERPROGRAM += 1;
1483815337 RENDERPROGRAM %= 3;
15338
+
1483915339 repaint();
1484015340 break;
1484115341 case 'Z':
1484215342 //RESIZETEXTURE ^= true;
1484315343 //break;
1484415344 case 'z':
14845
- RENDERSHADOW ^= true;
15345
+ Globals.RENDERSHADOW ^= true;
1484615346 Globals.lighttouched = true;
1484715347 repaint();
1484815348 break;
....@@ -14875,8 +15375,9 @@
1487515375 case DELETE:
1487615376 ClearSelection();
1487715377 break;
14878
- /*
1487915378 case '+':
15379
+
15380
+ /*
1488015381 //fontsize += 1;
1488115382 bbzoom *= 2;
1488215383 repaint();
....@@ -14893,17 +15394,17 @@
1489315394 case '=':
1489415395 IncDepth();
1489515396 //fontsize += 1;
14896
- object.editWindow.refreshContents(true);
15397
+ object.GetWindow().refreshContents(true);
1489715398 maskbit = 6;
1489815399 break;
1489915400 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1490015401 DecDepth();
1490115402 maskbit = 5;
1490215403 //if(fontsize > 1) fontsize -= 1;
14903
- if (object.editWindow == null)
14904
- new Exception().printStackTrace();
14905
- else
14906
- object.editWindow.refreshContents(true);
15404
+// if (object.editWindow == null)
15405
+// new Exception().printStackTrace();
15406
+// else
15407
+ object.GetWindow().refreshContents(true);
1490715408 break;
1490815409 case '{':
1490915410 manipCamera.shaper_fovy /= 1.1;
....@@ -14966,7 +15467,7 @@
1496615467 //mode = ROTATE;
1496715468 if ((MODIFIERS & COMMAND) == 0) // VR??
1496815469 {
14969
- SetMouseMode(modifiers);
15470
+ SetMouseMode(0, modifiers);
1497015471 }
1497115472 }
1497215473
....@@ -15100,8 +15601,9 @@
1510015601
1510115602 protected void processMouseMotionEvent(MouseEvent e)
1510215603 {
15103
- //System.out.println("processMouseMotionEvent: " + mouseMode);
15104
- if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15604
+ //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
15605
+ //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15606
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1510515607 {
1510615608 mouseMoved(e);
1510715609 } else
....@@ -15126,11 +15628,12 @@
1512615628 }
1512715629 */
1512815630
15129
- object.editWindow.EditSelection();
15631
+ object.GetWindow().EditSelection(false);
1513015632 }
1513115633
1513215634 void SelectParent()
1513315635 {
15636
+ new Exception().printStackTrace();
1513415637 System.exit(0);
1513515638 Composite group = (Composite) object;
1513615639 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -15142,10 +15645,10 @@
1514215645 {
1514315646 //selectees.remove(i);
1514415647 System.out.println("select parent of " + elem);
15145
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15648
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1514615649 } else
1514715650 {
15148
- group.editWindow.Select(elem.GetTreePath(), first, true);
15651
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1514915652 }
1515015653
1515115654 first = false;
....@@ -15154,6 +15657,7 @@
1515415657
1515515658 void SelectChildren()
1515615659 {
15660
+ new Exception().printStackTrace();
1515715661 System.exit(0);
1515815662 /*
1515915663 Composite group = (Composite) object;
....@@ -15186,12 +15690,12 @@
1518615690 for (int j = 0; j < group.children.size(); j++)
1518715691 {
1518815692 elem = (Object3D) group.children.elementAt(j);
15189
- object.editWindow.Select(elem.GetTreePath(), first, true);
15693
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1519015694 first = false;
1519115695 }
1519215696 } else
1519315697 {
15194
- object.editWindow.Select(elem.GetTreePath(), first, true);
15698
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1519515699 }
1519615700
1519715701 first = false;
....@@ -15202,21 +15706,21 @@
1520215706 {
1520315707 //Composite group = (Composite) object;
1520415708 Object3D group = object;
15205
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15709
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1520615710 }
1520715711
1520815712 void ResetTransform(int mask)
1520915713 {
1521015714 //Composite group = (Composite) object;
1521115715 Object3D group = object;
15212
- group.editWindow.ResetTransform(mask);
15716
+ group.GetWindow().ResetTransform(mask);
1521315717 }
1521415718
1521515719 void FlipTransform()
1521615720 {
1521715721 //Composite group = (Composite) object;
1521815722 Object3D group = object;
15219
- group.editWindow.FlipTransform();
15723
+ group.GetWindow().FlipTransform();
1522015724 // group.editWindow.ReduceMesh(true);
1522115725 }
1522215726
....@@ -15224,7 +15728,7 @@
1522415728 {
1522515729 //Composite group = (Composite) object;
1522615730 Object3D group = object;
15227
- group.editWindow.PrintMemory();
15731
+ group.GetWindow().PrintMemory();
1522815732 // group.editWindow.ReduceMesh(true);
1522915733 }
1523015734
....@@ -15232,7 +15736,7 @@
1523215736 {
1523315737 //Composite group = (Composite) object;
1523415738 Object3D group = object;
15235
- group.editWindow.ResetCentroid();
15739
+ group.GetWindow().ResetCentroid();
1523615740 }
1523715741
1523815742 void IncDepth()
....@@ -15318,7 +15822,9 @@
1531815822 info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1531915823 //Image img = CreateImage(width, height);
1532015824 //System.out.println("width = " + width + "; height = " + height + "\n");
15825
+
1532115826 Graphics gr = g; // img.getGraphics();
15827
+
1532215828 if (!hasMarquee)
1532315829 {
1532415830 if (Xmin < Xmax) // !locked)
....@@ -15406,6 +15912,7 @@
1540615912 info.bounds.y += (height - desired) / 2;
1540715913 }
1540815914 }
15915
+
1540915916 info.g = gr;
1541015917 info.camera = renderCamera;
1541115918 /*
....@@ -15415,15 +15922,55 @@
1541515922 */
1541615923 if (!isRenderer)
1541715924 {
15418
- object.drawEditHandles(info, 0);
15925
+ Grafreed.Assert(object != null);
15926
+ Grafreed.Assert(object.selection != null);
15927
+ if (object.selection.Size() > 0)
15928
+ {
15929
+ int hitSomething = object.selection.get(0).hitSomething;
15930
+
15931
+ info.DX = 0;
15932
+ info.DY = 0;
15933
+ info.W = 1;
15934
+ if (hitSomething == Object3D.hitCenter)
15935
+ {
15936
+ info.DX = X;
15937
+ if (X != 0)
15938
+ info.DX -= info.bounds.width/2;
15939
+
15940
+ info.DY = Y;
15941
+ if (Y != 0)
15942
+ info.DY -= info.bounds.height/2;
15943
+ }
15944
+
15945
+ object.drawEditHandles(info, 0);
15946
+
15947
+ if (drag && (X != 0 || Y != 0))
15948
+ {
15949
+ switch (hitSomething)
15950
+ {
15951
+ case Object3D.hitCenter: gr.setColor(Color.pink);
15952
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15953
+ break;
15954
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
15955
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15956
+ break;
15957
+ case Object3D.hitScale: gr.setColor(Color.cyan);
15958
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15959
+ break;
15960
+ }
15961
+
15962
+ }
15963
+ }
1541915964 }
1542015965 }
15966
+
1542115967 if (isRenderer)
1542215968 {
1542315969 //gr.setColor(Color.black);
1542415970 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1542515971 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1542615972 }
15973
+
1542715974 if (hasMarquee)
1542815975 {
1542915976 gr.setXORMode(Color.white);
....@@ -15536,6 +16083,7 @@
1553616083 public boolean mouseDown(Event evt, int x, int y)
1553716084 {
1553816085 System.out.println("mouseDown: " + evt);
16086
+ System.exit(0);
1553916087 /*
1554016088 locked = true;
1554116089 drag = false;
....@@ -15579,7 +16127,7 @@
1557916127 {
1558016128 keyPressed(0, modifiers);
1558116129 }
15582
- clickStart(x, y, modifiers);
16130
+ // clickStart(x, y, modifiers);
1558316131 return true;
1558416132 }
1558516133
....@@ -15697,7 +16245,7 @@
1569716245 {
1569816246 keyReleased(0, 0);
1569916247 }
15700
- drag(x, y, modifiers);
16248
+ drag(x, y, 0, modifiers);
1570116249 return true;
1570216250 }
1570316251
....@@ -15829,7 +16377,7 @@
1582916377 Object3D object;
1583016378 static Object3D trackedobject;
1583116379 Camera renderCamera; // Light or Eye (or Occlusion)
15832
- /*static*/ Camera manipCamera; // Light or Eye
16380
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1583316381 /*static*/ Camera eyeCamera;
1583416382 /*static*/ Camera lightCamera;
1583516383 int cameracount;
....@@ -16114,16 +16662,16 @@
1611416662 cStatic.objectstack[materialdepth++] = checker;
1611516663 //System.out.println("material " + material);
1611616664 //Applet3D.tracein(this, selected);
16117
- vector2buffer = checker.projectedVertices;
16665
+ //vector2buffer = checker.projectedVertices;
1611816666
1611916667 //checker.GetMaterial().Draw(this, false); // true);
16120
- DrawMaterial(checker.GetMaterial(), false); // true);
16668
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1612116669
1612216670 materialdepth -= 1;
1612316671 if (materialdepth > 0)
1612416672 {
16125
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16126
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
16673
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16674
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1612716675 }
1612816676 //checker.GetMaterial().opacity = 1f;
1612916677 ////checker.GetMaterial().ambient = 1f;
....@@ -16209,6 +16757,14 @@
1620916757 }
1621016758 }
1621116759
16760
+ private Object3D GetFolder()
16761
+ {
16762
+ Object3D folder = object.GetWindow().copy;
16763
+ if (object.GetWindow().copy.selection.Size() > 0)
16764
+ folder = object.GetWindow().copy.selection.elementAt(0);
16765
+ return folder;
16766
+ }
16767
+
1621216768 class SelectBuffer implements GLEventListener
1621316769 {
1621416770
....@@ -16267,6 +16823,7 @@
1626716823 {
1626816824 if (!selection)
1626916825 {
16826
+ new Exception().printStackTrace();
1627016827 System.exit(0);
1627116828 return;
1627216829 }
....@@ -16287,6 +16844,17 @@
1628716844
1628816845 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1628916846
16847
+ if (PAINTMODE)
16848
+ {
16849
+ if (object.GetWindow().copy.selection.Size() > 0)
16850
+ {
16851
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16852
+
16853
+ // Make what you paint not selectable.
16854
+ paintobj.ResetSelectable();
16855
+ }
16856
+ }
16857
+
1629016858 //int tmp = selection_view;
1629116859 //selection_view = -1;
1629216860 int temp = DrawMode();
....@@ -16298,6 +16866,17 @@
1629816866 // temp = DEFAULT; // patch for selection debug
1629916867 Globals.drawMode = temp; // WARNING
1630016868
16869
+ if (PAINTMODE)
16870
+ {
16871
+ if (object.GetWindow().copy.selection.Size() > 0)
16872
+ {
16873
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16874
+
16875
+ // Revert.
16876
+ paintobj.RestoreSelectable();
16877
+ }
16878
+ }
16879
+
1630116880 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1630216881
1630316882 // trying different ways of getting the depth info over
....@@ -16345,6 +16924,8 @@
1634516924 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1634616925 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1634716926 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
16927
+
16928
+ CreateSelectedPoint();
1634816929
1634916930 // Will fit the mesh !!!
1635016931 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16394,34 +16975,36 @@
1639416975 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]));
1639516976 }
1639616977
16397
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
16978
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1639816979 }
1639916980 }
1640016981
1640116982 if (!movingcamera && !PAINTMODE)
16402
- object.editWindow.ScreenFitPoint(); // fev 2014
16983
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1640316984
16404
- if (PAINTMODE && GrafreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
16985
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1640516986 {
16406
- Object3D paintobj = GrafreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
16987
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1640716988
16408
- Object3D group = new Object3D("inst" + paintcount++);
16989
+ if (object.GetWindow().copy.selection.Size() > 0)
16990
+ {
16991
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1640916992
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();
16993
+ Object3D inst = new Object3D("inst" + paintcount++);
16994
+
16995
+ inst.CreateMaterial(); // use a void leaf to select instances
16996
+
16997
+ inst.add(paintobj); // link
16998
+
16999
+ object.GetWindow().SnapObject(inst);
17000
+
17001
+ Object3D folder = paintFolder; // GetFolder();
17002
+
17003
+ folder.add(inst);
17004
+
17005
+ object.GetWindow().ResetModel();
17006
+ object.GetWindow().refreshContents();
17007
+ }
1642517008 }
1642617009 else
1642717010 paintcount = 0;
....@@ -16460,6 +17043,11 @@
1646017043 //System.out.println("objects[color] = " + objects[color]);
1646117044 //objects[color].Select();
1646217045 indexcount = 0;
17046
+ ObjEditor window = object.GetWindow();
17047
+ if (window != null && deselect)
17048
+ {
17049
+ window.Select(null, deselect, true);
17050
+ }
1646317051 object.Select(color, deselect);
1646417052 }
1646517053
....@@ -16559,7 +17147,7 @@
1655917147 gl.glDisable(gl.GL_CULL_FACE);
1656017148 }
1656117149
16562
- if (!RENDERSHADOW)
17150
+ if (!Globals.RENDERSHADOW)
1656317151 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1656417152
1656517153 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -16569,7 +17157,7 @@
1656917157 //gl.glColorMask(false, false, false, false);
1657017158
1657117159 //render_scene_from_light_view(gl, drawable, 0, 0);
16572
- if (RENDERSHADOW && Globals.lighttouched && !movingcamera) // && !parent.IsFreezed())
17160
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1657317161 {
1657417162 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1657517163
....@@ -16985,23 +17573,15 @@
1698517573 int AAbuffersize = 0;
1698617574
1698717575 //double[] selectedpoint = new double[3];
16988
- static Superellipsoid selectedpoint = new Superellipsoid();
17576
+ static Superellipsoid selectedpoint;
1698917577 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();
17578
+ static Sphere debugpointG;
17579
+ static Sphere debugpointP;
17580
+ static Sphere debugpointC;
17581
+ static Sphere debugpointR;
1699417582
1699517583 static Sphere debugpoints[] = new Sphere[8];
1699617584
16997
- static
16998
- {
16999
- for (int i=0; i<8; i++)
17000
- {
17001
- debugpoints[i] = new Sphere();
17002
- }
17003
- }
17004
-
1700517585 static void InitPoints(float radius)
1700617586 {
1700717587 for (int i=0; i<8; i++)