Normand Briere
2019-08-13 c67de8aca04d988179191ccb52461af00125920e
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;
....@@ -76,7 +110,9 @@
76110 //private Mat4f spotlightTransform = new Mat4f();
77111 //private Mat4f spotlightInverseTransform = new Mat4f();
78112 static GLContext glcontext = null;
79
- /*static*/ com.sun.opengl.util.texture.Texture cubemap;
113
+ /*static*/ com.sun.opengl.util.texture.Texture cubemap; // Either custom or rgb
114
+ /*static*/ com.sun.opengl.util.texture.Texture cubemapcustom;
115
+ /*static*/ com.sun.opengl.util.texture.Texture cubemaprgb;
80116 boolean reverseUP = false;
81117 static boolean frozen = false;
82118 boolean enablebackspace = false; // patch for back buffer refresh
....@@ -92,6 +128,8 @@
92128
93129 static int tickcount = 0; // slow pose issue
94130
131
+static boolean BUTTONLESSWHEEL = false;
132
+static boolean ZOOMBOXMODE = false;
95133 static boolean BOXMODE = false;
96134 static boolean IMAGEFLIP = false;
97135 static boolean SMOOTHFOCUS = false;
....@@ -106,7 +144,7 @@
106144 static boolean OEIL = true;
107145 static boolean OEILONCE = false; // do oeilon then oeiloff
108146 static boolean LOOKAT = true;
109
-static boolean RANDOM = true; // false;
147
+static boolean SWITCH = true; // false;
110148 static boolean HANDLES = false; // selection doesn't work!!
111149 static boolean PAINTMODE = false;
112150
....@@ -137,7 +175,7 @@
137175 static boolean doublesided = false; // true; // reversed normals are awful for conformance
138176 boolean anisotropy = true;
139177 boolean softshadow = true; // slower but better false;
140
- boolean opacityhalo = false;
178
+ boolean opacityhalo = false; // reverse the halo effect (e.g. glass)
141179
142180 boolean macromode = false;
143181
....@@ -148,6 +186,21 @@
148186 defaultcaps.setAccumGreenBits(16);
149187 defaultcaps.setAccumBlueBits(16);
150188 defaultcaps.setAccumAlphaBits(16);
189
+ }
190
+
191
+ private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
192
+
193
+ public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException
194
+ {
195
+ try
196
+ {
197
+ return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
198
+ } catch (IOException e)
199
+ {
200
+ System.out.println("NAME = " + name);
201
+ e.printStackTrace(); // throw new RuntimeException(e);
202
+ return null;
203
+ }
151204 }
152205
153206 void SetAsGLRenderer(boolean b)
....@@ -168,7 +221,8 @@
168221
169222 SetCamera(cam);
170223
171
- SetLight(new Camera(new cVector(10, 10, -20)));
224
+ // Warning: not used.
225
+ SetLight(new Camera(new cVector(15, 10, -20)));
172226
173227 object = o;
174228
....@@ -223,6 +277,11 @@
223277 public boolean IsBoxMode()
224278 {
225279 return BOXMODE;
280
+ }
281
+
282
+ public boolean IsZoomBoxMode()
283
+ {
284
+ return ZOOMBOXMODE;
226285 }
227286
228287 public void ClearDepth()
....@@ -320,7 +379,7 @@
320379 cStatic.objectstack[materialdepth++] = obj;
321380 //System.out.println("material " + material);
322381 //Applet3D.tracein(this, selected);
323
- display.vector2buffer = obj.projectedVertices;
382
+ //display.vector2buffer = obj.projectedVertices;
324383 if (obj instanceof Camera)
325384 {
326385 display.options1[0] = material.shift;
....@@ -329,14 +388,28 @@
329388 display.options1[2] = material.shadowbias;
330389 display.options1[3] = material.aniso;
331390 display.options1[4] = material.anisoV;
391
+// System.out.println("display.options1[0] " + display.options1[0]);
392
+// System.out.println("display.options1[1] " + display.options1[1]);
393
+// System.out.println("display.options1[2] " + display.options1[2]);
394
+// System.out.println("display.options1[3] " + display.options1[3]);
395
+// System.out.println("display.options1[4] " + display.options1[4]);
332396 display.options2[0] = material.opacity;
333397 display.options2[1] = material.diffuse;
334398 display.options2[2] = material.factor;
399
+// System.out.println("display.options2[0] " + display.options2[0]);
400
+// System.out.println("display.options2[1] " + display.options2[1]);
401
+// System.out.println("display.options2[2] " + display.options2[2]);
335402
336403 cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
404
+// System.out.println("display.options3[0] " + display.options3[0]);
405
+// System.out.println("display.options3[1] " + display.options3[1]);
406
+// System.out.println("display.options3[2] " + display.options3[2]);
337407 display.options4[0] = material.cameralight/0.2f;
338408 display.options4[1] = material.subsurface;
339409 display.options4[2] = material.sheen;
410
+// System.out.println("display.options4[0] " + display.options4[0]);
411
+// System.out.println("display.options4[1] " + display.options4[1]);
412
+// System.out.println("display.options4[2] " + display.options4[2]);
340413
341414 // if (display.CURRENTANTIALIAS > 0)
342415 // display.options3[3] /= 4;
....@@ -352,7 +425,7 @@
352425 /**/
353426 } else
354427 {
355
- DrawMaterial(material, selected);
428
+ DrawMaterial(material, selected, obj.projectedVertices);
356429 }
357430 } else
358431 {
....@@ -376,8 +449,8 @@
376449 cStatic.objectstack[materialdepth++] = obj;
377450 //System.out.println("material " + material);
378451 //Applet3D.tracein("selected ", selected);
379
- display.vector2buffer = obj.projectedVertices;
380
- display.DrawMaterial(material, selected);
452
+ //display.vector2buffer = obj.projectedVertices;
453
+ display.DrawMaterial(material, selected, obj.projectedVertices);
381454 }
382455 }
383456
....@@ -394,8 +467,8 @@
394467 materialdepth -= 1;
395468 if (materialdepth > 0)
396469 {
397
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
398
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
470
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
471
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
399472 }
400473 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
401474 } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
....@@ -415,8 +488,8 @@
415488 materialdepth -= 1;
416489 if (materialdepth > 0)
417490 {
418
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
419
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
491
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
492
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
420493 }
421494 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
422495 //else
....@@ -457,10 +530,12 @@
457530 if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
458531 {
459532 //gl.glBegin(gl.GL_TRIANGLES);
460
- boolean hasnorm = pv.norm != null; // && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0);
533
+ boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0)
534
+ // TEST LIVE NORMALS && !obj.dontselect
535
+ ;
461536 if (!hasnorm)
462537 {
463
- // System.out.println("FUCK!!");
538
+ // System.out.println("Mesh normal");
464539 LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
465540 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
466541 LA.vecCross(obj.v0, obj.v1, obj.v2);
....@@ -1185,10 +1260,12 @@
11851260 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
11861261 }
11871262 }
1263
+
11881264 if (flipV)
11891265 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
11901266 else
11911267 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1268
+
11921269 //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
11931270 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
11941271
....@@ -1208,10 +1285,12 @@
12081285 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
12091286 }
12101287 }
1288
+
12111289 if (flipV)
12121290 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12131291 else
12141292 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1293
+
12151294 //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
12161295 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
12171296
....@@ -1239,8 +1318,10 @@
12391318 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12401319 else
12411320 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1321
+
12421322 //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
12431323 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1324
+
12441325 count2 += 2;
12451326 count3 += 3;
12461327 }
....@@ -1419,6 +1500,8 @@
14191500 gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
14201501 }
14211502
1503
+ float[] colorV = new float[4];
1504
+
14221505 void SetColor(Object3D obj, Vertex p0)
14231506 {
14241507 CameraPane display = this;
....@@ -1486,8 +1569,6 @@
14861569 {
14871570 return;
14881571 }
1489
-
1490
- float[] colorV = new float[3];
14911572
14921573 if (false) // marked)
14931574 {
....@@ -1596,7 +1677,7 @@
15961677 // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
15971678 }
15981679
1599
- void DrawMaterial(cMaterial material, boolean selected)
1680
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
16001681 {
16011682 CameraPane display = this;
16021683 //new Exception().printStackTrace();
....@@ -1612,18 +1693,18 @@
16121693 //col.getColorComponents(ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB), CameraPane.modelParams0);
16131694 if (!material.multiply)
16141695 {
1615
- display.color = color;
1696
+ display.color = material.color;
16161697 display.saturation = material.modulation;
16171698 }
16181699 else
16191700 {
1620
- display.color *= color*2;
1701
+ display.color *= material.color*2;
16211702 display.saturation *= material.modulation*2;
16221703 }
16231704
16241705 cColor.HSBtoRGB(display.color, display.saturation, 1, display.modelParams0);
16251706
1626
- float[] colorV = GrafreeD.colorV;
1707
+ float[] colorV = Grafreed.colorV;
16271708
16281709 /**/
16291710 if (display.DrawMode() == display.DEFAULT) // && display.RENDERPROGRAM == 0)
....@@ -1631,7 +1712,7 @@
16311712 colorV[0] = display.modelParams0[0] * material.diffuse;
16321713 colorV[1] = display.modelParams0[1] * material.diffuse;
16331714 colorV[2] = display.modelParams0[2] * material.diffuse;
1634
- colorV[3] = material.opacity;
1715
+ colorV[3] = 1; // material.opacity;
16351716
16361717 gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
16371718 //System.out.println("Opacity = " + opacity);
....@@ -1739,9 +1820,9 @@
17391820 display.modelParams7[2] = 0;
17401821 display.modelParams7[3] = 0;
17411822
1742
- display.modelParams6[0] = 100; // criss de bug de bump
1823
+ //display.modelParams6[0] = 100; // criss de bug de bump
17431824
1744
- Object3D.cVector2[] extparams = display.vector2buffer;
1825
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
17451826 if (extparams != null && extparams.length > 0 && extparams[0] != null)
17461827 {
17471828 display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
....@@ -1883,7 +1964,7 @@
18831964 void PushMatrix(double[][] matrix)
18841965 {
18851966 // GrafreeD.tracein(matrix);
1886
- PushMatrix(matrix,1);
1967
+ PushMatrix(matrix, 1);
18871968 }
18881969
18891970 void PushMatrix()
....@@ -2037,7 +2118,7 @@
20372118 //System.err.println("Oeil on");
20382119 OEIL = true;
20392120 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2040
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2121
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
20412122 //pingthread.StepToTarget(true);
20422123 }
20432124
....@@ -2135,7 +2216,7 @@
21352216 System.err.println("LIVE = " + Globals.isLIVE());
21362217
21372218 if (!Globals.isLIVE()) // save sound
2138
- GrafreeD.savesound = true; // wav.save();
2219
+ Grafreed.savesound = true; // wav.save();
21392220 // else
21402221 repaint(); // start loop // may 2013
21412222 }
....@@ -2168,6 +2249,11 @@
21682249 public void ToggleBoxMode()
21692250 {
21702251 BOXMODE ^= true;
2252
+ }
2253
+
2254
+ public void ToggleZoomBoxMode()
2255
+ {
2256
+ ZOOMBOXMODE ^= true;
21712257 }
21722258
21732259 public void ToggleSmoothFocus()
....@@ -2247,7 +2333,7 @@
22472333
22482334 void ToggleDebug()
22492335 {
2250
- DEBUG ^= true;
2336
+ Globals.DEBUG ^= true;
22512337 }
22522338
22532339 void ToggleLookAt()
....@@ -2255,9 +2341,9 @@
22552341 LOOKAT ^= true;
22562342 }
22572343
2258
- void ToggleRandom()
2344
+ void ToggleSwitch()
22592345 {
2260
- RANDOM ^= true;
2346
+ SWITCH ^= true;
22612347 }
22622348
22632349 void ToggleHandles()
....@@ -2265,10 +2351,17 @@
22652351 HANDLES ^= true;
22662352 }
22672353
2354
+ Object3D paintFolder;
2355
+
22682356 void TogglePaint()
22692357 {
22702358 PAINTMODE ^= true;
22712359 paintcount = 0;
2360
+
2361
+ if (PAINTMODE)
2362
+ {
2363
+ paintFolder = GetFolder();
2364
+ }
22722365 }
22732366
22742367 void SwapCamera(int a, int b)
....@@ -2364,7 +2457,22 @@
23642457 {
23652458 return currentGL;
23662459 }
2367
-
2460
+
2461
+ static private BufferedImage CreateBim(TextureData texturedata)
2462
+ {
2463
+ Grafreed.Assert(texturedata != null);
2464
+
2465
+ int width = texturedata.getWidth();
2466
+ int height = texturedata.getHeight();
2467
+
2468
+ Buffer buffer = texturedata.getBuffer();
2469
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2470
+
2471
+ byte[] bytes = bytebuf.array();
2472
+
2473
+ return CreateBim(bytes, width, height);
2474
+ }
2475
+
23682476 /**/
23692477 class CacheTexture
23702478 {
....@@ -2373,28 +2481,31 @@
23732481
23742482 int resolution;
23752483
2376
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2484
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
23772485 {
2378
- texture = tex;
2486
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2487
+ texturedata = texdata;
23792488 resolution = res;
23802489 }
23812490 }
23822491 /**/
23832492
23842493 // 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>();
2494
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2495
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2496
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2497
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2498
+
23882499 int pigmentdepth = 0;
23892500 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
23902501 int bumpdepth = 0;
23912502 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
23922503 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
23932504 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2394
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2505
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
23952506 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
23962507
2397
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2508
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
23982509 {
23992510 TextureData texturedata = null;
24002511
....@@ -2413,13 +2524,34 @@
24132524 if (bump)
24142525 texturedata = ConvertBump(texturedata, false);
24152526
2416
- com.sun.opengl.util.texture.Texture texture =
2417
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2527
+// com.sun.opengl.util.texture.Texture texture =
2528
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
24182529
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);
2530
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2531
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
24212532
2422
- return texture;
2533
+ return texturedata;
2534
+ }
2535
+
2536
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2537
+ {
2538
+ TextureData texturedata = null;
2539
+
2540
+ try
2541
+ {
2542
+ texturedata =
2543
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2544
+ bim,
2545
+ true);
2546
+ } catch (Exception e)
2547
+ {
2548
+ throw new javax.media.opengl.GLException(e);
2549
+ }
2550
+
2551
+ if (bump)
2552
+ texturedata = ConvertBump(texturedata, false);
2553
+
2554
+ return texturedata;
24232555 }
24242556
24252557 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3492,6 +3624,8 @@
34923624
34933625 System.out.println("LOADING TEXTURE : " + name);
34943626
3627
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3628
+
34953629 //
34963630 if (false) // compressbit > 0)
34973631 {
....@@ -4196,6 +4330,7 @@
41964330
41974331 com.sun.opengl.util.texture.Texture CompressTexture2(String name)
41984332 {
4333
+ new Exception().printStackTrace();
41994334 System.exit(0);
42004335 com.sun.opengl.util.texture.Texture texture = null;
42014336
....@@ -7889,7 +8024,7 @@
78898024 String pigment = Object3D.GetPigment(tex);
78908025 String bump = Object3D.GetBump(tex);
78918026
7892
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8027
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
78938028 {
78948029 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
78958030 // System.out.println("; bump = " + bump);
....@@ -7904,11 +8039,69 @@
79048039 pigment = null;
79058040 }
79068041
7907
- ReleaseTexture(bump, true);
7908
- ReleaseTexture(pigment, false);
8042
+ ReleaseTexture(tex, true);
8043
+ ReleaseTexture(tex, false);
79098044 }
79108045
7911
- void ReleaseTexture(String tex, boolean bump)
8046
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
8047
+ {
8048
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8049
+ {
8050
+ return;
8051
+ }
8052
+
8053
+ if (tex == null)
8054
+ {
8055
+ ReleaseTexture(null, false);
8056
+ return;
8057
+ }
8058
+
8059
+ String pigment = Object3D.GetPigment(tex);
8060
+
8061
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8062
+ {
8063
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8064
+ // System.out.println("; bump = " + bump);
8065
+ }
8066
+
8067
+ if (pigment.equals(""))
8068
+ {
8069
+ pigment = null;
8070
+ }
8071
+
8072
+ ReleaseTexture(tex, false);
8073
+ }
8074
+
8075
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
8076
+ {
8077
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8078
+ {
8079
+ return;
8080
+ }
8081
+
8082
+ if (tex == null)
8083
+ {
8084
+ ReleaseTexture(null, true);
8085
+ return;
8086
+ }
8087
+
8088
+ String bump = Object3D.GetBump(tex);
8089
+
8090
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8091
+ {
8092
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8093
+ // System.out.println("; bump = " + bump);
8094
+ }
8095
+
8096
+ if (bump.equals(""))
8097
+ {
8098
+ bump = null;
8099
+ }
8100
+
8101
+ ReleaseTexture(tex, true);
8102
+ }
8103
+
8104
+ void ReleaseTexture(cTexture tex, boolean bump)
79128105 {
79138106 if (// DrawMode() != 0 || /*tex == null ||*/
79148107 ambientOcclusion ) // || !textureon)
....@@ -7919,7 +8112,7 @@
79198112 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
79208113
79218114 if (tex != null)
7922
- texture = textures.get(tex);
8115
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
79238116
79248117 // //assert( texture != null );
79258118 // if (texture == null)
....@@ -8011,7 +8204,55 @@
80118204 }
80128205 }
80138206
8014
- /*boolean*/ public void BindTextures(cTexture tex, int resolution) // INTERFACE
8207
+ /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
8208
+ {
8209
+// if (// DrawMode() != 0 || /*tex == null ||*/
8210
+// ambientOcclusion ) // || !textureon)
8211
+// {
8212
+// return; // false;
8213
+// }
8214
+//
8215
+// if (tex == null)
8216
+// {
8217
+// BindTexture(null,false,resolution);
8218
+// BindTexture(null,true,resolution);
8219
+// return;
8220
+// }
8221
+//
8222
+// String pigment = Object3D.GetPigment(tex);
8223
+// String bump = Object3D.GetBump(tex);
8224
+//
8225
+// usedtextures.add(pigment);
8226
+// usedtextures.add(bump);
8227
+//
8228
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8229
+// {
8230
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8231
+// // System.out.println("; bump = " + bump);
8232
+// }
8233
+//
8234
+// if (bump.equals(""))
8235
+// {
8236
+// bump = null;
8237
+// }
8238
+// if (pigment.equals(""))
8239
+// {
8240
+// pigment = null;
8241
+// }
8242
+//
8243
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8244
+// BindTexture(pigment, false, resolution);
8245
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8246
+// BindTexture(bump, true, resolution);
8247
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8248
+//
8249
+// return; // true;
8250
+
8251
+ BindPigmentTexture(tex, resolution);
8252
+ BindBumpTexture(tex, resolution);
8253
+ }
8254
+
8255
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
80158256 {
80168257 if (// DrawMode() != 0 || /*tex == null ||*/
80178258 ambientOcclusion ) // || !textureon)
....@@ -8022,17 +8263,47 @@
80228263 if (tex == null)
80238264 {
80248265 BindTexture(null,false,resolution);
8025
- BindTexture(null,true,resolution);
80268266 return;
80278267 }
80288268
80298269 String pigment = Object3D.GetPigment(tex);
8270
+
8271
+ usedtextures.add(tex);
8272
+
8273
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8274
+ {
8275
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8276
+ // System.out.println("; bump = " + bump);
8277
+ }
8278
+
8279
+ if (pigment.equals(""))
8280
+ {
8281
+ pigment = null;
8282
+ }
8283
+
8284
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8285
+ BindTexture(tex, false, resolution);
8286
+ }
8287
+
8288
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8289
+ {
8290
+ if (// DrawMode() != 0 || /*tex == null ||*/
8291
+ ambientOcclusion ) // || !textureon)
8292
+ {
8293
+ return; // false;
8294
+ }
8295
+
8296
+ if (tex == null)
8297
+ {
8298
+ BindTexture(null,true,resolution);
8299
+ return;
8300
+ }
8301
+
80308302 String bump = Object3D.GetBump(tex);
80318303
8032
- usedtextures.put(pigment, pigment);
8033
- usedtextures.put(bump, bump);
8304
+ usedtextures.add(tex);
80348305
8035
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8306
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
80368307 {
80378308 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
80388309 // System.out.println("; bump = " + bump);
....@@ -8042,43 +8313,94 @@
80428313 {
80438314 bump = null;
80448315 }
8045
- if (pigment.equals(""))
8046
- {
8047
- pigment = null;
8048
- }
80498316
8050
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8051
- BindTexture(pigment, false, resolution);
80528317 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8053
- BindTexture(bump, true, resolution);
8318
+ BindTexture(tex, true, resolution);
80548319 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8055
-
8056
- return; // true;
80578320 }
80588321
8059
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution)
8322
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8323
+
8324
+ private boolean FileExists(String tex)
80608325 {
8061
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8326
+ if (missingTextures.contains(tex))
8327
+ {
8328
+ return false;
8329
+ }
8330
+
8331
+ boolean fileExists = new File(tex).exists();
8332
+
8333
+ if (!fileExists)
8334
+ {
8335
+ // If file exists, the "new File()" is not executed sgain
8336
+ missingTextures.add(tex);
8337
+ }
8338
+
8339
+ return fileExists;
8340
+ }
8341
+
8342
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
8343
+ {
8344
+ CacheTexture texturecache = null;
80628345
80638346 if (tex != null)
80648347 {
8065
- String texname = tex;
8348
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8349
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
80668350
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;
8351
+ if (texname.equals("") && texdata == null)
8352
+ {
8353
+ return null;
8354
+ }
8355
+
8356
+ String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
8357
+
8358
+// String[] split = tex.split("Textures");
8359
+// if (split.length > 1)
8360
+// texname = "/Users/nbriere/Textures" + split[split.length-1];
8361
+// else
8362
+// if (!texname.startsWith("/"))
8363
+// texname = "/Users/nbriere/Textures/" + texname;
8364
+ if (!FileExists(texname) && !texname.startsWith("@"))
8365
+ {
8366
+ texname = fallbackTextureName;
8367
+ }
80738368
80748369 if (CACHETEXTURE)
8075
- texture = textures.get(texname); // TEXTURE CACHE
8076
-
8077
- TextureData texturedata = null;
8078
-
8079
- if (texture == null || texture.resolution < resolution)
80808370 {
8081
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8371
+ if (texdata == null)
8372
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8373
+ else
8374
+ texturecache = bimtextures.get(texdata);
8375
+ }
8376
+
8377
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8378
+ {
8379
+ TextureData texturedata = null;
8380
+
8381
+ if (texdata != null && textureon)
8382
+ {
8383
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8384
+
8385
+ try
8386
+ {
8387
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8388
+ }
8389
+ catch (Exception e)
8390
+ {
8391
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8392
+ }
8393
+
8394
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8395
+ bimtextures.put(texdata, texturecache);
8396
+
8397
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8398
+
8399
+ //Object bim2 = CreateBim(texturecache.texturedata);
8400
+ //bim2 = bim;
8401
+ }
8402
+ else
8403
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
80828404 {
80838405 assert(!bump);
80848406 // if (bump)
....@@ -8089,19 +8411,23 @@
80898411 // }
80908412 // else
80918413 // {
8092
- texture = textures.get(tex);
8093
- if (texture == null)
8414
+ // texturecache = textures.get(texname); // suspicious
8415
+ if (texturecache == null)
80948416 {
8095
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8417
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
80968418 }
8419
+ else
8420
+ new Exception().printStackTrace();
80978421 // }
80988422 } else
8099
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8423
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
81008424 {
81018425 assert(bump);
8102
- texture = textures.get(tex);
8103
- if (texture == null)
8104
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8426
+ // texturecache = textures.get(texname); // suspicious
8427
+ if (texturecache == null)
8428
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8429
+ else
8430
+ new Exception().printStackTrace();
81058431 } else
81068432 {
81078433 //if (tex.equals("IMMORTAL"))
....@@ -8109,11 +8435,22 @@
81098435 // texture = GetResourceTexture("default.png");
81108436 //} else
81118437 //{
8112
- if (tex.equals("WHITE_NOISE"))
8438
+ if (texname.endsWith("WHITE_NOISE"))
81138439 {
8114
- texture = textures.get(tex);
8115
- if (texture == null)
8116
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8440
+ // texturecache = textures.get(texname); // suspicious
8441
+ if (texturecache == null)
8442
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8443
+ else
8444
+ new Exception().printStackTrace();
8445
+ } else
8446
+ {
8447
+ if (texname.startsWith("@"))
8448
+ {
8449
+ // texturecache = textures.get(texname); // suspicious
8450
+ if (texturecache == null)
8451
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8452
+ else
8453
+ new Exception().printStackTrace();
81178454 } else
81188455 {
81198456 if (textureon)
....@@ -8138,7 +8475,7 @@
81388475 }
81398476
81408477 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
8141
- if (!new File(cachename).exists())
8478
+ if (!FileExists(cachename))
81428479 cachename = texname;
81438480 else
81448481 processbump = false; // don't process bump map again
....@@ -8160,7 +8497,7 @@
81608497 }
81618498
81628499 cachename = texname.substring(0, texname.length()-4)+ext+".png";
8163
- if (!new File(cachename).exists())
8500
+ if (!FileExists(cachename))
81648501 cachename = texname;
81658502 else
81668503 processbump = false; // don't process bump map again
....@@ -8169,20 +8506,23 @@
81698506 texturedata = GetFileTexture(cachename, processbump, resolution);
81708507
81718508
8172
- if (texturedata != null)
8173
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8509
+ if (texturedata == null)
8510
+ throw new Exception();
8511
+
8512
+ texturecache = new CacheTexture(texturedata,resolution);
81748513 //texture = GetTexture(tex, bump);
81758514 }
8515
+ }
81768516 }
81778517 //}
81788518 }
81798519
8180
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8520
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
81818521 {
81828522 //return false;
81838523
81848524 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8185
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8525
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
81868526 {
81878527 // String ext = "_highres";
81888528 // if (REDUCETEXTURE)
....@@ -8199,52 +8539,17 @@
81998539 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
82008540 if (!cachefile.exists())
82018541 {
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))
8542
+ //if (texturedata.getWidth() == texturedata.getHeight())
82118543 {
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);
8544
+ BufferedImage rendImage = CreateBim(texturedata);
8545
+
82428546 ImageWriter writer = null;
82438547 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
82448548 if (iter.hasNext()) {
82458549 writer = (ImageWriter)iter.next();
82468550 }
8247
- float compressionQuality = 0.9f;
8551
+
8552
+ float compressionQuality = 0.85f;
82488553 try
82498554 {
82508555 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8261,18 +8566,20 @@
82618566 }
82628567 }
82638568 }
8264
-
8569
+
8570
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8571
+
82658572 //System.out.println("Texture = " + tex);
8266
- if (textures.containsKey(texname))
8573
+ if (textures.containsKey(tex))
82678574 {
8268
- CacheTexture thetex = textures.get(texname);
8575
+ CacheTexture thetex = textures.get(tex);
82698576 thetex.texture.disable();
82708577 thetex.texture.dispose();
8271
- textures.remove(texname);
8578
+ textures.remove(tex);
82728579 }
82738580
8274
- texture.texturedata = texturedata;
8275
- textures.put(texname, texture);
8581
+ //texture.texturedata = texturedata;
8582
+ textures.put(tex, texturecache);
82768583
82778584 // newtex = true;
82788585 }
....@@ -8288,10 +8595,44 @@
82888595 }
82898596 }
82908597
8291
- return texture;
8598
+ return texturecache;
82928599 }
82938600
8294
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution)
8601
+ static void EmbedTextures(cTexture tex)
8602
+ {
8603
+ if (tex.pigmentdata == null)
8604
+ {
8605
+ //String texname = Object3D.GetPigment(tex);
8606
+
8607
+ CacheTexture texturecache = texturepigment.get(tex);
8608
+
8609
+ if (texturecache != null)
8610
+ {
8611
+ tex.pw = texturecache.texturedata.getWidth();
8612
+ tex.ph = texturecache.texturedata.getHeight();
8613
+ tex.pigmentdata = //CompressJPEG(CreateBim
8614
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8615
+ ;
8616
+ //, tex.pw, tex.ph), 0.5f);
8617
+ }
8618
+ }
8619
+
8620
+ if (tex.bumpdata == null)
8621
+ {
8622
+ //String texname = Object3D.GetBump(tex);
8623
+
8624
+ CacheTexture texturecache = texturebump.get(tex);
8625
+
8626
+ if (texturecache != null)
8627
+ {
8628
+ tex.bw = texturecache.texturedata.getWidth();
8629
+ tex.bh = texturecache.texturedata.getHeight();
8630
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8631
+ }
8632
+ }
8633
+ }
8634
+
8635
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
82958636 {
82968637 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
82978638
....@@ -8309,21 +8650,21 @@
83098650 return texture!=null?texture.texture:null;
83108651 }
83118652
8312
- public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution)
8653
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
83138654 {
83148655 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
83158656
83168657 return texture!=null?texture.texturedata:null;
83178658 }
83188659
8319
- boolean BindTexture(String tex, boolean bump, int resolution)
8660
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
83208661 {
83218662 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
83228663 {
83238664 return false;
83248665 }
83258666
8326
- boolean newtex = false;
8667
+ //boolean newtex = false;
83278668
83288669 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
83298670
....@@ -8355,9 +8696,75 @@
83558696 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
83568697 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
83578698
8358
- return newtex;
8699
+ return true; // Warning: not used.
83598700 }
83608701
8702
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8703
+ {
8704
+ try
8705
+ {
8706
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8707
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8708
+ ImageWriter writer = writers.next();
8709
+
8710
+ ImageWriteParam param = writer.getDefaultWriteParam();
8711
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8712
+ param.setCompressionQuality(quality);
8713
+
8714
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8715
+ writer.setOutput(ios);
8716
+ writer.write(null, new IIOImage(image, null, null), param);
8717
+
8718
+ byte[] data = baos.toByteArray();
8719
+ writer.dispose();
8720
+ return data;
8721
+ }
8722
+ catch (Exception e)
8723
+ {
8724
+ e.printStackTrace();
8725
+ return null;
8726
+ }
8727
+ }
8728
+
8729
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8730
+ {
8731
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8732
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8733
+ ImageReader reader = writers.next();
8734
+
8735
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8736
+
8737
+ ImageReadParam param = reader.getDefaultReadParam();
8738
+ param.setDestination(bim);
8739
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8740
+
8741
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8742
+ reader.setInput(ios);
8743
+ BufferedImage bim2 = reader.read(0, param);
8744
+ reader.dispose();
8745
+
8746
+// WritableRaster raster = bim2.getRaster();
8747
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8748
+// byte[] bytes = data.getData();
8749
+//
8750
+// int[] pixels = new int[bytes.length/3];
8751
+// for (int i=pixels.length; --i>=0;)
8752
+// {
8753
+// int i3 = i*3;
8754
+// pixels[i] = 0xFF;
8755
+// pixels[i] <<= 8;
8756
+// pixels[i] |= bytes[i3+2] & 0xFF;
8757
+// pixels[i] <<= 8;
8758
+// pixels[i] |= bytes[i3+1] & 0xFF;
8759
+// pixels[i] <<= 8;
8760
+// pixels[i] |= bytes[i3] & 0xFF;
8761
+// }
8762
+//
8763
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8764
+
8765
+ return bim;
8766
+ }
8767
+
83618768 ShadowBuffer shadowPBuf;
83628769 AntialiasBuffer antialiasPBuf;
83638770 int MAXSTACK;
....@@ -8374,10 +8781,12 @@
83748781
83758782 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
83768783 MAXSTACK = temp[0];
8377
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8784
+ if (Globals.DEBUG)
8785
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
83788786 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
83798787 MAXSTACK = temp[0];
8380
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8788
+ if (Globals.DEBUG)
8789
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
83818790
83828791 // Use debug pipeline
83838792 //drawable.setGL(new DebugGL(gl)); //
....@@ -8385,7 +8794,8 @@
83858794 gl = drawable.getGL(); //
83868795
83878796 GL gl3 = getGL();
8388
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8797
+ if (Globals.DEBUG)
8798
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
83898799
83908800
83918801 //float pos[] = { 100, 100, 100, 0 };
....@@ -8550,7 +8960,7 @@
85508960
85518961 if (cubemap == null)
85528962 {
8553
- LoadEnvy(5);
8963
+ //LoadEnvy(1);
85548964 }
85558965
85568966 //cubemap.enable();
....@@ -8826,6 +9236,8 @@
88269236
88279237 void LoadEnvy(int which)
88289238 {
9239
+ assert(false);
9240
+
88299241 String name;
88309242 String ext;
88319243
....@@ -8837,37 +9249,58 @@
88379249 cubemap = null;
88389250 return;
88399251 case 1:
8840
- name = "cubemaps/box_";
8841
- ext = "png";
9252
+ name = "cubemaps/rgb/";
9253
+ ext = "jpg";
88429254 reverseUP = false;
88439255 break;
88449256 case 2:
8845
- name = "cubemaps/uffizi_";
8846
- ext = "png";
8847
- break; // reverseUP = true; break;
9257
+ name = "cubemaps/uffizi/";
9258
+ ext = "jpg";
9259
+ reverseUP = false;
9260
+ break;
88489261 case 3:
8849
- name = "cubemaps/CloudyHills_";
8850
- ext = "tga";
9262
+ name = "cubemaps/CloudyHills/";
9263
+ ext = "jpg";
88519264 reverseUP = false;
88529265 break;
88539266 case 4:
8854
- name = "cubemaps/cornell_";
9267
+ name = "cubemaps/cornell/";
88559268 ext = "png";
88569269 reverseUP = false;
88579270 break;
9271
+ case 5:
9272
+ name = "cubemaps/skycube/";
9273
+ ext = "jpg";
9274
+ reverseUP = false;
9275
+ break;
9276
+ case 6:
9277
+ name = "cubemaps/SaintLazarusChurch3/";
9278
+ ext = "jpg";
9279
+ reverseUP = false;
9280
+ break;
9281
+ case 7:
9282
+ name = "cubemaps/Sodermalmsallen/";
9283
+ ext = "jpg";
9284
+ reverseUP = false;
9285
+ break;
9286
+ case 8:
9287
+ name = "cubemaps/Sodermalmsallen2/";
9288
+ ext = "jpg";
9289
+ reverseUP = false;
9290
+ break;
9291
+ case 9:
9292
+ name = "cubemaps/UnionSquare/";
9293
+ ext = "jpg";
9294
+ reverseUP = false;
9295
+ break;
88589296 default:
8859
- name = "cubemaps/rgb_";
8860
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9297
+ name = "cubemaps/box/";
9298
+ ext = "png"; /*mipmap = true;*/
9299
+ reverseUP = false;
88619300 break;
88629301 }
8863
-
8864
- try
8865
- {
8866
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
8867
- } catch (IOException e)
8868
- {
8869
- throw new RuntimeException(e);
8870
- }
9302
+
9303
+ LoadSkybox(name, ext, mipmap);
88719304 }
88729305
88739306 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -8899,8 +9332,12 @@
88999332 static double[] model = new double[16];
89009333 double[] camera2light = new double[16];
89019334 double[] light2camera = new double[16];
8902
- int newenvy = -1;
8903
- boolean envyoff = true; // false;
9335
+
9336
+ //int newenvy = -1;
9337
+ //boolean envyoff = false;
9338
+
9339
+ String loadedskyboxname;
9340
+
89049341 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
89059342 //float[] light0 = { 0,0,0 };
89069343 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9193,11 +9630,35 @@
91939630 jy8[3] = 0.5f;
91949631 }
91959632
9196
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9633
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
91979634 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
91989635 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
91999636 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
92009637
9638
+ void ResetOptions()
9639
+ {
9640
+ options1[0] = 100;
9641
+ options1[1] = 0.025f;
9642
+ options1[2] = 0.01f;
9643
+ options1[3] = 0;
9644
+ options1[4] = 0;
9645
+
9646
+ options2[0] = 0;
9647
+ options2[1] = 0.75f;
9648
+ options2[2] = 0;
9649
+ options2[3] = 0;
9650
+
9651
+ options3[0] = 1;
9652
+ options3[1] = 1;
9653
+ options3[2] = 1;
9654
+ options3[3] = 0;
9655
+
9656
+ options4[0] = 1;
9657
+ options4[1] = 0;
9658
+ options4[2] = 1;
9659
+ options4[3] = 0;
9660
+ }
9661
+
92019662 static int imagecount = 0; // movie generation
92029663
92039664 static int jitter = 0;
....@@ -9293,8 +9754,8 @@
92939754 assert (parentcam != renderCamera);
92949755
92959756 if (renderCamera != lightCamera)
9296
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9297
- LA.matConcat(matrix, parentcam.toParent, matrix);
9757
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9758
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
92989759
92999760 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
93009761
....@@ -9309,8 +9770,8 @@
93099770 LA.matCopy(renderCamera.fromScreen, matrix);
93109771
93119772 if (renderCamera != lightCamera)
9312
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9313
- LA.matConcat(parentcam.fromParent, matrix, matrix);
9773
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9774
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
93149775
93159776 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
93169777
....@@ -9356,10 +9817,12 @@
93569817 rati = 1 / rati;
93579818 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
93589819 }
9359
- assert (newenvy == -1);
9820
+
9821
+ //assert (newenvy == -1);
9822
+
93609823 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
93619824 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9362
- DrawSkyBox(gl);
9825
+ DrawSkyBox(gl, (float)rati);
93639826 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
93649827 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
93659828 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -9382,7 +9845,7 @@
93829845 //gl.glFlush();
93839846 gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE);
93849847
9385
- if (ANIMATION && ABORTED)
9848
+ if (Globals.ANIMATION && ABORTED)
93869849 {
93879850 System.err.println(" ABORTED FRAME");
93889851 break;
....@@ -9412,7 +9875,7 @@
94129875 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
94139876
94149877 // save image
9415
- if (ANIMATION && !ABORTED)
9878
+ if (Globals.ANIMATION && !ABORTED)
94169879 {
94179880 VPwidth = viewport[2];
94189881 VPheight = viewport[3];
....@@ -9523,11 +9986,11 @@
95239986
95249987 // imagecount++;
95259988
9526
- String fullname = filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
9989
+ String fullname = Globals.filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
95279990
95289991 if (!BOXMODE)
95299992 {
9530
- System.out.println("image: " + fullname + " (wav cursor=" + (GrafreeD.wav.cursor / 735 / 4) + ")");
9993
+ System.out.println("image: " + fullname + " (wav cursor=" + (Grafreed.wav.cursor / 735 / 4) + ")");
95319994 }
95329995
95339996 if (!BOXMODE)
....@@ -9565,7 +10028,7 @@
956510028 ABORTED = false;
956610029 }
956710030 else
9568
- GrafreeD.wav.cursor += 735 * ACSIZE;
10031
+ Grafreed.wav.cursor += 735 * ACSIZE;
956910032
957010033 if (false)
957110034 {
....@@ -10228,11 +10691,11 @@
1022810691
1022910692 public void display(GLAutoDrawable drawable)
1023010693 {
10231
- if (GrafreeD.savesound && GrafreeD.hassound)
10694
+ if (Grafreed.savesound && Grafreed.hassound)
1023210695 {
10233
- GrafreeD.wav.save();
10234
- GrafreeD.savesound = false;
10235
- GrafreeD.hassound = false;
10696
+ Grafreed.wav.save();
10697
+ Grafreed.savesound = false;
10698
+ Grafreed.hassound = false;
1023610699 }
1023710700 // if (DEBUG_SELECTION)
1023810701 // {
....@@ -10308,6 +10771,7 @@
1030810771 ANTIALIAS = 0;
1030910772 //System.out.println("RESTART");
1031010773 AAtimer.restart();
10774
+ Globals.TIMERRUNNING = true;
1031110775 }
1031210776 }
1031310777 }
....@@ -10362,7 +10826,7 @@
1036210826 Object3D theobject = object;
1036310827 Object3D theparent = object.parent;
1036410828 object.parent = null;
10365
- object = (Object3D)GrafreeD.clone(object);
10829
+ object = (Object3D)Grafreed.clone(object);
1036610830 object.Stripify();
1036710831 if (theobject.selection == null || theobject.selection.Size() == 0)
1036810832 theobject.PreprocessOcclusion(this);
....@@ -10375,13 +10839,14 @@
1037510839 ambientOcclusion = false;
1037610840 }
1037710841
10378
- if (Globals.lighttouched && DrawMode() == DEFAULT && !lightMode) // && !FROZEN)
10842
+ if (//Globals.lighttouched &&
10843
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1037910844 {
1038010845 //if (RENDERSHADOW) // ?
1038110846 if (!IsFrozen())
1038210847 {
1038310848 // dec 2012
10384
- if (!ambientOcclusion && !(!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0))
10849
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
1038510850 {
1038610851 Globals.framecount++;
1038710852 shadowbuffer.display();
....@@ -10394,7 +10859,7 @@
1039410859
1039510860 if (wait)
1039610861 {
10397
- Sleep(500);
10862
+ Sleep(200); // blocks everything
1039810863
1039910864 wait = false;
1040010865 }
....@@ -10508,8 +10973,8 @@
1050810973
1050910974 // if (parentcam != renderCamera) // not a light
1051010975 if (cam != lightCamera)
10511
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10512
- LA.matConcat(matrix, parentcam.toParent, matrix);
10976
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10977
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1051310978
1051410979 for (int j = 0; j < 4; j++)
1051510980 {
....@@ -10523,8 +10988,8 @@
1052310988
1052410989 // if (parentcam != renderCamera) // not a light
1052510990 if (cam != lightCamera)
10526
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10527
- LA.matConcat(parentcam.fromParent, matrix, matrix);
10991
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10992
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1052810993
1052910994 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1053010995
....@@ -10610,13 +11075,41 @@
1061011075 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1061111076 }
1061211077
10613
- if (newenvy > -1)
11078
+// if (newenvy > -1)
11079
+// {
11080
+// LoadEnvy(newenvy);
11081
+// }
11082
+//
11083
+// newenvy = -1;
11084
+
11085
+ if (object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
1061411086 {
10615
- LoadEnvy(newenvy);
11087
+ if (cubemaprgb == null)
11088
+ {
11089
+ cubemaprgb = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11090
+ }
11091
+
11092
+ cubemap = cubemaprgb;
1061611093 }
10617
-
10618
- newenvy = -1;
10619
-
11094
+ else
11095
+ {
11096
+ if (object.skyboxname != null)
11097
+ {
11098
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11099
+ {
11100
+ cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11101
+ loadedskyboxname = object.skyboxname;
11102
+ }
11103
+ }
11104
+ else
11105
+ {
11106
+ cubemapcustom = null;
11107
+ loadedskyboxname = null;
11108
+ }
11109
+
11110
+ cubemap = cubemapcustom;
11111
+ }
11112
+
1062011113 ratio = ((double) getWidth()) / getHeight();
1062111114 //System.out.println("ratio = " + ratio);
1062211115
....@@ -10632,7 +11125,7 @@
1063211125
1063311126 if (!IsFrozen() && !ambientOcclusion)
1063411127 {
10635
- DrawSkyBox(gl);
11128
+ DrawSkyBox(gl, (float)ratio);
1063611129 }
1063711130
1063811131 //if (selection_view == -1)
....@@ -10783,7 +11276,16 @@
1078311276 // Bump noise
1078411277 gl.glActiveTexture(GL.GL_TEXTURE6);
1078511278 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
10786
- BindTexture(NOISE_TEXTURE, false, 2);
11279
+
11280
+ try
11281
+ {
11282
+ BindTexture(NOISE_TEXTURE, false, 2);
11283
+ }
11284
+ catch (Exception e)
11285
+ {
11286
+ System.err.println("FAILED: " + NOISE_TEXTURE);
11287
+ }
11288
+
1078711289
1078811290 gl.glActiveTexture(GL.GL_TEXTURE0);
1078911291 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -10806,9 +11308,9 @@
1080611308
1080711309 gl.glMatrixMode(GL.GL_MODELVIEW);
1080811310
10809
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10810
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10811
-//gl.glEnable(gl.GL_MULTISAMPLE);
11311
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11312
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11313
+gl.glEnable(gl.GL_MULTISAMPLE);
1081211314 } else
1081311315 {
1081411316 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -10819,7 +11321,7 @@
1081911321 //System.out.println("BLENDING ON");
1082011322 gl.glEnable(GL.GL_BLEND);
1082111323 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
10822
-
11324
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1082311325 gl.glMatrixMode(gl.GL_PROJECTION);
1082411326 gl.glLoadIdentity();
1082511327
....@@ -10908,8 +11410,8 @@
1090811410 System.err.println("parentcam != renderCamera");
1090911411
1091011412 // if (cam != lightCamera)
10911
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10912
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11413
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11414
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1091311415 }
1091411416
1091511417 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -10930,8 +11432,8 @@
1093011432 if (true) // TODO
1093111433 {
1093211434 if (cam != lightCamera)
10933
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10934
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11435
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11436
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
1093511437 }
1093611438
1093711439 LA.xformPos(light0, cam.toScreen, light0);
....@@ -11068,7 +11570,7 @@
1106811570 }
1106911571 }
1107011572
11071
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11573
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1107211574 {
1107311575 //gl.glDepthFunc(GL.GL_LEQUAL);
1107411576 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11076,24 +11578,21 @@
1107611578
1107711579 boolean texon = textureon;
1107811580
11079
- if (RENDERPROGRAM > 0)
11080
- {
11081
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11082
- textureon = false;
11083
- }
11581
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11582
+ textureon = false;
11583
+
1108411584 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1108511585 //System.out.println("ALLO");
1108611586 gl.glColorMask(false, false, false, false);
1108711587 DrawObject(gl);
11088
- if (RENDERPROGRAM > 0)
11089
- {
11090
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11091
- textureon = texon;
11092
- }
11588
+
11589
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11590
+ textureon = texon;
11591
+
1109311592 gl.glColorMask(true, true, true, true);
1109411593
1109511594 gl.glDepthFunc(GL.GL_EQUAL);
11096
- //gl.glDepthMask(false);
11595
+ gl.glDepthMask(false);
1109711596 }
1109811597
1109911598 if (false) // DrawMode() == SHADOW)
....@@ -11247,8 +11746,14 @@
1124711746 {
1124811747 renderpass++;
1124911748 // System.out.println("Draw object... ");
11749
+ STEP = 1;
1125011750 if (FAST) // in case there is no script
11251
- STEP = 16;
11751
+ STEP = 8;
11752
+
11753
+ if (CURRENTANTIALIAS == 0 || ACSIZE == 1)
11754
+ {
11755
+ STEP *= 4;
11756
+ }
1125211757
1125311758 //object.FullInvariants();
1125411759
....@@ -11262,23 +11767,44 @@
1126211767 e.printStackTrace();
1126311768 }
1126411769
11265
- if (GrafreeD.RENDERME > 0)
11266
- GrafreeD.RENDERME--; // mechante magouille
11770
+ if (Grafreed.RENDERME > 0)
11771
+ Grafreed.RENDERME--; // mechante magouille
1126711772
1126811773 Globals.ONESTEP = false;
1126911774 }
1127011775
1127111776 static boolean zoomonce = false;
1127211777
11778
+ static void CreateSelectedPoint()
11779
+ {
11780
+ if (selectedpoint == null)
11781
+ {
11782
+ debugpointG = new Sphere();
11783
+ debugpointP = new Sphere();
11784
+ debugpointC = new Sphere();
11785
+ debugpointR = new Sphere();
11786
+
11787
+ selectedpoint = new Superellipsoid();
11788
+
11789
+ for (int i=0; i<8; i++)
11790
+ {
11791
+ debugpoints[i] = new Sphere();
11792
+ }
11793
+ }
11794
+ }
11795
+
1127311796 void DrawObject(GL gl, boolean draw)
1127411797 {
11798
+ // To clear camera values
11799
+ ResetOptions();
11800
+
1127511801 //System.out.println("DRAW OBJECT " + mouseDown);
1127611802 // DrawMode() = SELECTION;
1127711803 //GL gl = getGL();
1127811804 if ((TRACK || SHADOWTRACK) || zoomonce)
1127911805 {
1128011806 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11281
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11807
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1128211808 pingthread.StepToTarget(true); // true);
1128311809 // zoomonce = false;
1128411810 }
....@@ -11333,7 +11859,14 @@
1133311859
1133411860 usedtextures.clear();
1133511861
11336
- BindTextures(DEFAULT_TEXTURES, 2);
11862
+ try
11863
+ {
11864
+ BindTextures(DEFAULT_TEXTURES, 2);
11865
+ }
11866
+ catch (Exception e)
11867
+ {
11868
+ System.err.println("FAILED: " + DEFAULT_TEXTURES);
11869
+ }
1133711870 }
1133811871 //System.out.println("--> " + stackdepth);
1133911872 // GrafreeD.traceon();
....@@ -11343,8 +11876,9 @@
1134311876
1134411877 if (DrawMode() == DEFAULT)
1134511878 {
11346
- if (DEBUG)
11879
+ if (Globals.DEBUG)
1134711880 {
11881
+ CreateSelectedPoint();
1134811882 float radius = 0.05f;
1134911883 if (selectedpoint.radius != radius)
1135011884 {
....@@ -11398,20 +11932,32 @@
1139811932 ReleaseTextures(DEFAULT_TEXTURES);
1139911933
1140011934 if (CLEANCACHE)
11401
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11935
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1140211936 {
11403
- String tex = e.nextElement();
11937
+ cTexture tex = e.nextElement();
1140411938
1140511939 // System.out.println("Texture --------- " + tex);
1140611940
11407
- if (tex.equals("WHITE_NOISE"))
11941
+ if (tex.equals("WHITE_NOISE:"))
1140811942 continue;
1140911943
11410
- if (!usedtextures.containsKey(tex))
11944
+ if (!usedtextures.contains(tex))
1141111945 {
11946
+ CacheTexture gettex = texturepigment.get(tex);
1141211947 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11413
- textures.get(tex).texture.dispose();
11414
- textures.remove(tex);
11948
+ if (gettex != null)
11949
+ {
11950
+ gettex.texture.dispose();
11951
+ texturepigment.remove(tex);
11952
+ }
11953
+
11954
+ gettex = texturebump.get(tex);
11955
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11956
+ if (gettex != null)
11957
+ {
11958
+ gettex.texture.dispose();
11959
+ texturebump.remove(tex);
11960
+ }
1141511961 }
1141611962 }
1141711963 }
....@@ -11424,7 +11970,14 @@
1142411970 if (checker != null && DrawMode() == DEFAULT)
1142511971 {
1142611972 //BindTexture(IMMORTAL_TEXTURE);
11427
- BindTextures(checker.GetTextures(), checker.texres);
11973
+ try
11974
+ {
11975
+ BindTextures(checker.GetTextures(), checker.texres);
11976
+ }
11977
+ catch (Exception e)
11978
+ {
11979
+ System.err.println("FAILED: " + checker.GetTextures());
11980
+ }
1142811981 // NEAREST
1142911982 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
1143011983 DrawChecker(gl);
....@@ -11506,7 +12059,7 @@
1150612059 return;
1150712060 }
1150812061
11509
- String string = obj.GetToolTip();
12062
+ String string = obj.toString(); //.GetToolTip();
1151012063
1151112064 GL gl = GetGL();
1151212065
....@@ -11823,8 +12376,8 @@
1182312376 //obj.TransformToWorld(light, light);
1182412377 for (int i = tp.size(); --i >= 0;)
1182512378 {
11826
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
11827
- LA.xformPos(light, tp.get(i).toParent, light);
12379
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12380
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1182812381 }
1182912382
1183012383
....@@ -11841,8 +12394,8 @@
1184112394 parentcam = cameras[0];
1184212395 }
1184312396
11844
- for (int count = parentcam.GetTransformCount(); --count>=0;)
11845
- LA.xformPos(light, parentcam.toParent, light); // may 2013
12397
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
12398
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1184612399
1184712400 LA.xformPos(light, renderCamera.toScreen, light);
1184812401
....@@ -11932,8 +12485,76 @@
1193212485
1193312486 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1193412487
11935
- String program =
12488
+ String programmin =
12489
+ // Min shader
1193612490 "!!ARBfp1.0\n" +
12491
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12492
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12493
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12494
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12495
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12496
+ "PARAM light2cam0 = program.env[10];" +
12497
+ "PARAM light2cam1 = program.env[11];" +
12498
+ "PARAM light2cam2 = program.env[12];" +
12499
+ "TEMP temp;" +
12500
+ "TEMP light;" +
12501
+ "TEMP ndotl;" +
12502
+ "TEMP normal;" +
12503
+ "TEMP depth;" +
12504
+ "TEMP eye;" +
12505
+ "TEMP pos;" +
12506
+
12507
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12508
+ Normalize("normal") +
12509
+ "MOV light, state.light[0].position;" +
12510
+ "DP3 ndotl.x, light, normal;" +
12511
+
12512
+ // shadow
12513
+ "MOV pos, fragment.texcoord[1];" +
12514
+ "MOV temp, pos;" +
12515
+ ShadowTextureFetch("depth", "temp", "1") +
12516
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12517
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12518
+
12519
+ // No shadow when out of frustum
12520
+ //"SGE temp.y, depth.z, zero123.y;" +
12521
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12522
+
12523
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12524
+
12525
+ // Backlit
12526
+ "MOV pos.w, zero123.y;" +
12527
+ "DP4 eye.x, pos, light2cam0;" +
12528
+ "DP4 eye.y, pos, light2cam1;" +
12529
+ "DP4 eye.z, pos, light2cam2;" +
12530
+ Normalize("eye") +
12531
+
12532
+ "DP3 ndotl.y, -eye, normal;" +
12533
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12534
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12535
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12536
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12537
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12538
+
12539
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12540
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12541
+
12542
+ // Pigment
12543
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12544
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12545
+ "MUL temp, temp, ndotl.x;" +
12546
+
12547
+ "MUL temp, temp, zero123.z;" +
12548
+
12549
+ //"MUL temp, temp, ndotl.y;" +
12550
+
12551
+ "MOV temp.w, zero123.y;" + // reset alpha
12552
+ "MOV result.color, temp;" +
12553
+ "END";
12554
+
12555
+ String programmax =
12556
+ "!!ARBfp1.0\n" +
12557
+
1193712558 //"OPTION ARB_fragment_program_shadow;" +
1193812559 "PARAM light2cam0 = program.env[10];" +
1193912560 "PARAM light2cam1 = program.env[11];" +
....@@ -12048,8 +12669,7 @@
1204812669 "TEMP shininess;" +
1204912670 "\n" +
1205012671 "MOV texSamp, one;" +
12051
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12052
-
12672
+
1205312673 "MOV mapgrid.x, one2048th.x;" +
1205412674 "MOV temp, fragment.texcoord[1];" +
1205512675 /*
....@@ -12070,20 +12690,20 @@
1207012690 "MUL temp, floor, mapgrid.x;" +
1207112691 //"TEX depth0, temp, texture[1], 2D;" +
1207212692 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12073
- TextureFetch("depth0", "temp", "1") +
12693
+ ShadowTextureFetch("depth0", "temp", "1") +
1207412694 "") +
1207512695 "ADD temp.x, temp.x, mapgrid.x;" +
1207612696 //"TEX depth1, temp, texture[1], 2D;" +
1207712697 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12078
- TextureFetch("depth1", "temp", "1") +
12698
+ ShadowTextureFetch("depth1", "temp", "1") +
1207912699 "") +
1208012700 "ADD temp.y, temp.y, mapgrid.x;" +
1208112701 //"TEX depth2, temp, texture[1], 2D;" +
12082
- TextureFetch("depth2", "temp", "1") +
12702
+ ShadowTextureFetch("depth2", "temp", "1") +
1208312703 "SUB temp.x, temp.x, mapgrid.x;" +
1208412704 //"TEX depth3, temp, texture[1], 2D;" +
1208512705 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12086
- TextureFetch("depth3", "temp", "1") +
12706
+ ShadowTextureFetch("depth3", "temp", "1") +
1208712707 "") +
1208812708 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1208912709 //"MOV params, material;" +
....@@ -12454,10 +13074,10 @@
1245413074 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1245513075 "") +
1245613076
12457
- // display shadow only (bump == 0)
13077
+ // display shadow only (fakedepth == 0)
1245813078 "SUB temp.x, half.x, shadow.x;" +
12459
- "MOV temp.y, -params6.x;" +
12460
- "SLT temp.z, temp.y, zero.x;" +
13079
+ "MOV temp.y, -params5.z;" + // params6.x;" +
13080
+ "SLT temp.z, temp.y, -c256i.x;" +
1246113081 "SUB temp.y, one.x, temp.z;" +
1246213082 "MUL temp.x, temp.x, temp.y;" +
1246313083 "KIL temp.x;" +
....@@ -12586,8 +13206,10 @@
1258613206 "MAX ndotl.x, ndotl.x, -ndotl.x;" +
1258713207
1258813208 "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
13209
+ // Tuning for default skin
13210
+ //"ADD temp.x, temp.x, options2.z;" + // lightsheen
13211
+ "MAD temp.x, options2.z, half.y, temp.x;" + // lightsheen
13212
+ "ADD temp.y, one.y, options2.y;" + // subsurface
1259113213 "MUL temp.x, temp.x, temp.y;" +
1259213214
1259313215 "MUL saturation, saturation, temp.xxxx;" +
....@@ -12786,7 +13408,14 @@
1278613408 //once = true;
1278713409 }
1278813410
12789
- System.out.print("Program #" + mode + "; length = " + program.length());
13411
+ String program = programmax;
13412
+
13413
+ if (Globals.MINSHADER)
13414
+ {
13415
+ program = programmin;
13416
+ }
13417
+
13418
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1279013419 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1279113420 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1279213421
....@@ -12879,25 +13508,26 @@
1287913508 return out;
1288013509 }
1288113510
12882
- String TextureFetch(String dest, String src, String unit)
13511
+ // Also does frustum culling
13512
+ String ShadowTextureFetch(String dest, String src, String unit)
1288313513 {
1288413514 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1288513515 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1288613516 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13517
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13518
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1288713519 "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;" +
13520
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13521
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1289213522 //"SWZ buffer, temp, w,w,w,w;";
12893
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13523
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1289413524 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1289513525 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1289613526 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
12897
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13527
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1289813528
12899
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
12900
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13529
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13530
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1290113531 }
1290213532
1290313533 String Shadow(String depth, String shadow)
....@@ -12919,12 +13549,16 @@
1291913549
1292013550 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1292113551 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13552
+
13553
+ // Compare fragment depth in light space with shadowmap.
1292213554 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1292313555 "SGE temp.y, temp.x, zero.x;" +
12924
- "SUB " + shadow + ".y, one.x, temp.y;" +
13556
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13557
+
13558
+ // Reverse comparison
1292513559 "SUB temp.x, one.x, temp.x;" +
1292613560 "MUL " + shadow + ".x, temp.x, temp.y;" +
12927
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13561
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1292813562 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1292913563
1293013564 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -12938,6 +13572,10 @@
1293813572 // No shadow for backface
1293913573 "DP3 temp.x, normal, lightd;" +
1294013574 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13575
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13576
+
13577
+ // No shadow when out of frustum
13578
+ "SGE temp.x, " + depth + ".z, one.z;" +
1294113579 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1294213580 "";
1294313581 }
....@@ -13084,7 +13722,8 @@
1308413722 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1308513723 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1308613724 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13087
- Object3D.cVector2[] vector2buffer;
13725
+
13726
+ //Object3D.cVector2[] vector2buffer;
1308813727
1308913728 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1309013729 // OUT : diff, spec
....@@ -13100,9 +13739,10 @@
1310013739 "DP3 " + dest + ".z," + "normals," + "eye;" +
1310113740 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1310213741 //"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;" +
13742
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13743
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13744
+
13745
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1310613746 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1310713747 "RCP " + dest + ".w," + dest + ".w;" +
1310813748 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13496,7 +14136,7 @@
1349614136 public void mousePressed(MouseEvent e)
1349714137 {
1349814138 //System.out.println("mousePressed: " + e);
13499
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14139
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1350014140 }
1350114141
1350214142 static long prevtime = 0;
....@@ -13523,6 +14163,7 @@
1352314163
1352414164 //System.err.println("Dtime = " + Dtime + "; units = " + e.getUnitsToScroll() + "; ratio (units/ms) = " + ratio);
1352514165
14166
+ if (BUTTONLESSWHEEL)
1352614167 if (Math.abs(ratio) < 0.1 || Math.abs(Dtime) == 0) // < 30)
1352714168 {
1352814169 return;
....@@ -13531,7 +14172,7 @@
1353114172 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
1353214173
1353314174 // TIMER
13534
- if (!wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
14175
+ if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
1353514176 {
1353614177 keepboxmode = BOXMODE;
1353714178 keepsupport = SUPPORT;
....@@ -13571,8 +14212,8 @@
1357114212 // mode |= META;
1357214213 //}
1357314214
13574
- SetMouseMode(WHEEL | e.getModifiersEx());
13575
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14215
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14216
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1357614217 anchorX = ax;
1357714218 anchorY = ay;
1357814219 prevX = px;
....@@ -13606,6 +14247,7 @@
1360614247 else
1360714248 if (evt.getSource() == AAtimer)
1360814249 {
14250
+ Globals.TIMERRUNNING = false;
1360914251 if (mouseDown)
1361014252 {
1361114253 //new Exception().printStackTrace();
....@@ -13631,6 +14273,10 @@
1363114273 // LIVE = waslive;
1363214274 // wasliveok = true;
1363314275 // waslive = false;
14276
+
14277
+ // May 2019 Forget it:
14278
+ if (true)
14279
+ return;
1363414280
1363514281 // source == timer
1363614282 if (mouseDown)
....@@ -13661,7 +14307,7 @@
1366114307
1366214308 // fev 2014???
1366314309 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13664
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14310
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1366514311 pingthread.StepToTarget(true); // true);
1366614312 }
1366714313 // if (!LIVE)
....@@ -13670,12 +14316,13 @@
1367014316
1367114317 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1367214318
13673
- void clickStart(int x, int y, int modifiers)
14319
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1367414320 {
1367514321 if (!wasliveok)
1367614322 return;
1367714323
1367814324 AAtimer.restart(); //
14325
+ Globals.TIMERRUNNING = true;
1367914326
1368014327 // waslive = LIVE;
1368114328 // LIVE = false;
....@@ -13687,7 +14334,7 @@
1368714334 // touched = true; // main DL
1368814335 if (isRenderer)
1368914336 {
13690
- SetMouseMode(modifiers);
14337
+ SetMouseMode(modifiers, modifiersex);
1369114338 }
1369214339
1369314340 selectX = anchorX = x;
....@@ -13700,7 +14347,7 @@
1370014347 clicked = true;
1370114348 hold = false;
1370214349
13703
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14350
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1370414351 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1370514352 {
1370614353 // System.out.println("RESTART II " + modifiers);
....@@ -13725,14 +14372,15 @@
1372514372 drag = false;
1372614373 //System.out.println("Mouse DOWN");
1372714374 editObj = false;
13728
- ClickInfo info = new ClickInfo();
13729
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
13730
- info.pane = this;
13731
- info.camera = renderCamera;
13732
- info.x = x;
13733
- info.y = y;
13734
- info.modifiers = modifiers;
13735
- editObj = object.doEditClick(info, 0);
14375
+ //ClickInfo info = new ClickInfo();
14376
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14377
+ object.clickInfo.pane = this;
14378
+ object.clickInfo.camera = renderCamera;
14379
+ object.clickInfo.x = x;
14380
+ object.clickInfo.y = y;
14381
+ object.clickInfo.modifiers = modifiersex;
14382
+ editObj = object.doEditClick(//info,
14383
+ 0);
1373614384 if (!editObj)
1373714385 {
1373814386 hasMarquee = true;
....@@ -13748,11 +14396,14 @@
1374814396
1374914397 public void mouseDragged(MouseEvent e)
1375014398 {
14399
+ Globals.MOUSEDRAGGED = true;
14400
+
14401
+ //System.out.println("mouseDragged: " + e);
1375114402 if (isRenderer)
1375214403 movingcamera = true;
14404
+
1375314405 //if (drawing)
1375414406 //return;
13755
- //System.out.println("mouseDragged: " + e);
1375614407 if ((e.getModifiersEx() & CTRL) != 0
1375714408 || (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen())
1375814409 {
....@@ -13760,7 +14411,7 @@
1376014411 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1376114412 }
1376214413 else
13763
- drag(e.getX(), e.getY(), e.getModifiersEx());
14414
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1376414415
1376514416 //try { Thread.sleep(1); } catch (Exception ex) {}
1376614417 }
....@@ -13933,6 +14584,7 @@
1393314584
1393414585 public void run()
1393514586 {
14587
+ new Exception().printStackTrace();
1393614588 System.exit(0);
1393714589 for (;;)
1393814590 {
....@@ -13996,7 +14648,7 @@
1399614648 {
1399714649 Globals.lighttouched = true;
1399814650 }
13999
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14651
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1400014652 }
1400114653 //else
1400214654 }
....@@ -14010,12 +14662,12 @@
1401014662 void GoDown(int mod)
1401114663 {
1401214664 MODIFIERS |= COMMAND;
14013
- /*
14665
+ /**/
1401414666 if((mod&SHIFT) == SHIFT)
14015
- manipCamera.RotatePosition(0, -speed);
14667
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
1401614668 else
14017
- manipCamera.BackForth(0, -speed*delta, getWidth());
14018
- */
14669
+ manipCamera.RotatePosition(0, -speed);
14670
+ /**/
1401914671 if ((mod & SHIFT) == SHIFT)
1402014672 {
1402114673 mouseMode = mouseMode; // VR??
....@@ -14031,12 +14683,12 @@
1403114683 void GoUp(int mod)
1403214684 {
1403314685 MODIFIERS |= COMMAND;
14034
- /*
14686
+ /**/
1403514687 if((mod&SHIFT) == SHIFT)
14036
- manipCamera.RotatePosition(0, speed);
14688
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
1403714689 else
14038
- manipCamera.BackForth(0, speed*delta, getWidth());
14039
- */
14690
+ manipCamera.RotatePosition(0, speed);
14691
+ /**/
1404014692 if ((mod & SHIFT) == SHIFT)
1404114693 {
1404214694 mouseMode = mouseMode;
....@@ -14052,12 +14704,12 @@
1405214704 void GoLeft(int mod)
1405314705 {
1405414706 MODIFIERS |= COMMAND;
14055
- /*
14707
+ /**/
1405614708 if((mod&SHIFT) == SHIFT)
14057
- manipCamera.RotatePosition(speed, 0);
14058
- else
1405914709 manipCamera.Translate(speed*delta, 0, getWidth());
14060
- */
14710
+ else
14711
+ manipCamera.RotatePosition(speed, 0);
14712
+ /**/
1406114713 if ((mod & SHIFT) == SHIFT)
1406214714 {
1406314715 mouseMode = mouseMode;
....@@ -14073,12 +14725,12 @@
1407314725 void GoRight(int mod)
1407414726 {
1407514727 MODIFIERS |= COMMAND;
14076
- /*
14728
+ /**/
1407714729 if((mod&SHIFT) == SHIFT)
14078
- manipCamera.RotatePosition(-speed, 0);
14079
- else
1408014730 manipCamera.Translate(-speed*delta, 0, getWidth());
14081
- */
14731
+ else
14732
+ manipCamera.RotatePosition(-speed, 0);
14733
+ /**/
1408214734 if ((mod & SHIFT) == SHIFT)
1408314735 {
1408414736 mouseMode = mouseMode;
....@@ -14096,7 +14748,7 @@
1409614748 int X, Y;
1409714749 boolean SX, SY;
1409814750
14099
- void drag(int x, int y, int modifiers)
14751
+ void drag(int x, int y, int modifiers, int modifiersex)
1410014752 {
1410114753 if (IsFrozen())
1410214754 {
....@@ -14105,17 +14757,17 @@
1410514757
1410614758 drag = true; // NEW
1410714759
14108
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14760
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1410914761
1411014762 X = x;
1411114763 Y = y;
1411214764 // floating state for animation
14113
- MODIFIERS = modifiers;
14114
- modifiers &= ~1024;
14765
+ MODIFIERS = modifiersex;
14766
+ modifiersex &= ~1024;
1411514767 if (false) // modifiers != 0)
1411614768 {
1411714769 //new Exception().printStackTrace();
14118
- System.out.println("mouseDragged: " + modifiers);
14770
+ System.out.println("mouseDragged: " + modifiersex);
1411914771 System.out.println("SHIFT = " + SHIFT);
1412014772 System.out.println("CONTROL = " + COMMAND);
1412114773 System.out.println("META = " + META);
....@@ -14128,14 +14780,16 @@
1412814780 if (editObj)
1412914781 {
1413014782 drag = true;
14131
- ClickInfo info = new ClickInfo();
14132
- info.bounds.setBounds(0, 0,
14783
+ //ClickInfo info = new ClickInfo();
14784
+ object.clickInfo.bounds.setBounds(0, 0,
1413314785 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14134
- info.pane = this;
14135
- info.camera = renderCamera;
14136
- info.x = x;
14137
- info.y = y;
14138
- object.editWindow.copy.doEditDrag(info);
14786
+ object.clickInfo.pane = this;
14787
+ object.clickInfo.camera = renderCamera;
14788
+ object.clickInfo.x = x;
14789
+ object.clickInfo.y = y;
14790
+ object //.GetWindow().copy
14791
+ .doEditDrag(//info,
14792
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1413914793 } else
1414014794 {
1414114795 if (x < startX)
....@@ -14284,23 +14938,27 @@
1428414938 }
1428514939 }
1428614940
14941
+// ClickInfo clickInfo = new ClickInfo();
14942
+
1428714943 public void mouseMoved(MouseEvent e)
1428814944 {
1428914945 //System.out.println("mouseMoved: " + e);
14290
-
1429114946 if (isRenderer)
1429214947 return;
1429314948
14294
- ClickInfo ci = new ClickInfo();
14295
- ci.x = e.getX();
14296
- ci.y = e.getY();
14297
- ci.modifiers = e.getModifiersEx();
14298
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14299
- ci.pane = this;
14300
- ci.camera = renderCamera;
14949
+ // Mouse cursor feedback
14950
+ object.clickInfo.x = e.getX();
14951
+ object.clickInfo.y = e.getY();
14952
+ object.clickInfo.modifiers = e.getModifiersEx();
14953
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14954
+ object.clickInfo.pane = this;
14955
+ object.clickInfo.camera = renderCamera;
1430114956 if (!isRenderer)
1430214957 {
14303
- if (object.editWindow.copy.doEditClick(ci, 0))
14958
+ //ObjEditor editWindow = object.editWindow;
14959
+ //Object3D copy = editWindow.copy;
14960
+ if (object.doEditClick(//clickInfo,
14961
+ 0))
1430414962 {
1430514963 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1430614964 } else
....@@ -14312,7 +14970,11 @@
1431214970
1431314971 public void mouseReleased(MouseEvent e)
1431414972 {
14973
+ Globals.MOUSEDRAGGED = false;
14974
+
1431514975 movingcamera = false;
14976
+ X = 0; // getBounds().width/2;
14977
+ Y = 0; // getBounds().height/2;
1431614978 //System.out.println("mouseReleased: " + e);
1431714979 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1431814980 }
....@@ -14335,9 +14997,9 @@
1433514997 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1433614998 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1433714999
14338
- if (control || command || IsFrozen())
15000
+// No delay if (control || command || IsFrozen())
1433915001 timeout = true;
14340
- else
15002
+// ?? May 2019 else
1434115003 // timer.setDelay((modifiers & 128) != 0?0:350);
1434215004 mouseDown = false;
1434315005 if (!control && !command) // june 2013
....@@ -14447,7 +15109,7 @@
1444715109 System.out.println("keyReleased: " + e);
1444815110 }
1444915111
14450
- void SetMouseMode(int modifiers)
15112
+ void SetMouseMode(int modifiers, int modifiersex)
1445115113 {
1445215114 //System.out.println("SetMouseMode = " + modifiers);
1445315115 //modifiers &= ~1024;
....@@ -14459,25 +15121,25 @@
1445915121 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1446015122 // return;
1446115123 //System.out.println("SetMode = " + modifiers);
14462
- if ((modifiers & WHEEL) == WHEEL)
15124
+ if ((modifiersex & WHEEL) == WHEEL)
1446315125 {
1446415126 mouseMode |= ZOOM;
1446515127 }
1446615128
1446715129 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
14468
- if (capsLocked || (modifiers & META) == META)
15130
+ if (capsLocked) // || (modifiers & META) == META)
1446915131 {
1447015132 mouseMode |= VR; // BACKFORTH;
1447115133 }
14472
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
15134
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1447315135 {
1447415136 mouseMode |= SELECT;
1447515137 }
14476
- if ((modifiers & COMMAND) == COMMAND)
15138
+ if ((modifiersex & COMMAND) == COMMAND)
1447715139 {
1447815140 mouseMode |= SELECT;
1447915141 }
14480
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15142
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
1448115143 {
1448215144 mouseMode &= ~VR;
1448315145 mouseMode |= TRANSLATE;
....@@ -14506,7 +15168,7 @@
1450615168
1450715169 if (isRenderer) //
1450815170 {
14509
- SetMouseMode(modifiers);
15171
+ SetMouseMode(0, modifiers);
1451015172 }
1451115173
1451215174 Globals.theRenderer.keyPressed(key);
....@@ -14568,7 +15230,8 @@
1456815230 // break;
1456915231 case 'T':
1457015232 CACHETEXTURE ^= true;
14571
- textures.clear();
15233
+ texturepigment.clear();
15234
+ texturebump.clear();
1457215235 // repaint();
1457315236 break;
1457415237 case 'Y':
....@@ -14653,7 +15316,9 @@
1465315316 case 'E' : COMPACT ^= true;
1465415317 repaint();
1465515318 break;
14656
- case 'W' : DEBUGHSB ^= true;
15319
+ case 'W' : // Wide Window (fullscreen)
15320
+ //DEBUGHSB ^= true;
15321
+ ObjEditor.theFrame.ToggleFullScreen();
1465715322 repaint();
1465815323 break;
1465915324 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14678,8 +15343,8 @@
1467815343 RevertCamera();
1467915344 repaint();
1468015345 break;
14681
- case 'L':
1468215346 case 'l':
15347
+ //case 'L':
1468315348 if (lightMode)
1468415349 {
1468515350 lightMode = false;
....@@ -14743,20 +15408,24 @@
1474315408 OCCLUSION_CULLING ^= true;
1474415409 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1474515410 break;
14746
- case '0': envyoff ^= true; repaint(); break;
15411
+ //case '0': envyoff ^= true; repaint(); break;
1474715412 case '1':
1474815413 case '2':
1474915414 case '3':
1475015415 case '4':
1475115416 case '5':
14752
- newenvy = Character.getNumericValue(key);
14753
- repaint();
14754
- break;
1475515417 case '6':
1475615418 case '7':
1475715419 case '8':
1475815420 case '9':
14759
- BGcolor = (key - '6')/3.f;
15421
+ if (true) // envyoff)
15422
+ {
15423
+ BGcolor = (key - '1')/8.f;
15424
+ }
15425
+ else
15426
+ {
15427
+ //newenvy = Character.getNumericValue(key);
15428
+ }
1476015429 repaint();
1476115430 break;
1476215431 case '!':
....@@ -14822,9 +15491,9 @@
1482215491 case '_':
1482315492 kompactbit = 5;
1482415493 break;
14825
- case '+':
14826
- kompactbit = 6;
14827
- break;
15494
+// case '+':
15495
+// kompactbit = 6;
15496
+// break;
1482815497 case ' ':
1482915498 lightMode ^= true;
1483015499 Globals.lighttouched = true;
....@@ -14836,13 +15505,14 @@
1483615505 case ESC:
1483715506 RENDERPROGRAM += 1;
1483815507 RENDERPROGRAM %= 3;
15508
+
1483915509 repaint();
1484015510 break;
1484115511 case 'Z':
1484215512 //RESIZETEXTURE ^= true;
1484315513 //break;
1484415514 case 'z':
14845
- RENDERSHADOW ^= true;
15515
+ Globals.RENDERSHADOW ^= true;
1484615516 Globals.lighttouched = true;
1484715517 repaint();
1484815518 break;
....@@ -14875,8 +15545,9 @@
1487515545 case DELETE:
1487615546 ClearSelection();
1487715547 break;
14878
- /*
1487915548 case '+':
15549
+
15550
+ /*
1488015551 //fontsize += 1;
1488115552 bbzoom *= 2;
1488215553 repaint();
....@@ -14893,17 +15564,17 @@
1489315564 case '=':
1489415565 IncDepth();
1489515566 //fontsize += 1;
14896
- object.editWindow.refreshContents(true);
15567
+ object.GetWindow().refreshContents(true);
1489715568 maskbit = 6;
1489815569 break;
1489915570 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1490015571 DecDepth();
1490115572 maskbit = 5;
1490215573 //if(fontsize > 1) fontsize -= 1;
14903
- if (object.editWindow == null)
14904
- new Exception().printStackTrace();
14905
- else
14906
- object.editWindow.refreshContents(true);
15574
+// if (object.editWindow == null)
15575
+// new Exception().printStackTrace();
15576
+// else
15577
+ object.GetWindow().refreshContents(true);
1490715578 break;
1490815579 case '{':
1490915580 manipCamera.shaper_fovy /= 1.1;
....@@ -14966,7 +15637,7 @@
1496615637 //mode = ROTATE;
1496715638 if ((MODIFIERS & COMMAND) == 0) // VR??
1496815639 {
14969
- SetMouseMode(modifiers);
15640
+ SetMouseMode(0, modifiers);
1497015641 }
1497115642 }
1497215643
....@@ -15100,8 +15771,9 @@
1510015771
1510115772 protected void processMouseMotionEvent(MouseEvent e)
1510215773 {
15103
- //System.out.println("processMouseMotionEvent: " + mouseMode);
15104
- if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15774
+ //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
15775
+ //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15776
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1510515777 {
1510615778 mouseMoved(e);
1510715779 } else
....@@ -15126,11 +15798,12 @@
1512615798 }
1512715799 */
1512815800
15129
- object.editWindow.EditSelection();
15801
+ object.GetWindow().EditSelection(false);
1513015802 }
1513115803
1513215804 void SelectParent()
1513315805 {
15806
+ new Exception().printStackTrace();
1513415807 System.exit(0);
1513515808 Composite group = (Composite) object;
1513615809 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -15142,10 +15815,10 @@
1514215815 {
1514315816 //selectees.remove(i);
1514415817 System.out.println("select parent of " + elem);
15145
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15818
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1514615819 } else
1514715820 {
15148
- group.editWindow.Select(elem.GetTreePath(), first, true);
15821
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1514915822 }
1515015823
1515115824 first = false;
....@@ -15154,6 +15827,7 @@
1515415827
1515515828 void SelectChildren()
1515615829 {
15830
+ new Exception().printStackTrace();
1515715831 System.exit(0);
1515815832 /*
1515915833 Composite group = (Composite) object;
....@@ -15186,12 +15860,12 @@
1518615860 for (int j = 0; j < group.children.size(); j++)
1518715861 {
1518815862 elem = (Object3D) group.children.elementAt(j);
15189
- object.editWindow.Select(elem.GetTreePath(), first, true);
15863
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1519015864 first = false;
1519115865 }
1519215866 } else
1519315867 {
15194
- object.editWindow.Select(elem.GetTreePath(), first, true);
15868
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1519515869 }
1519615870
1519715871 first = false;
....@@ -15202,21 +15876,21 @@
1520215876 {
1520315877 //Composite group = (Composite) object;
1520415878 Object3D group = object;
15205
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15879
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1520615880 }
1520715881
1520815882 void ResetTransform(int mask)
1520915883 {
1521015884 //Composite group = (Composite) object;
1521115885 Object3D group = object;
15212
- group.editWindow.ResetTransform(mask);
15886
+ group.GetWindow().ResetTransform(mask);
1521315887 }
1521415888
1521515889 void FlipTransform()
1521615890 {
1521715891 //Composite group = (Composite) object;
1521815892 Object3D group = object;
15219
- group.editWindow.FlipTransform();
15893
+ group.GetWindow().FlipTransform();
1522015894 // group.editWindow.ReduceMesh(true);
1522115895 }
1522215896
....@@ -15224,7 +15898,7 @@
1522415898 {
1522515899 //Composite group = (Composite) object;
1522615900 Object3D group = object;
15227
- group.editWindow.PrintMemory();
15901
+ group.GetWindow().PrintMemory();
1522815902 // group.editWindow.ReduceMesh(true);
1522915903 }
1523015904
....@@ -15232,7 +15906,7 @@
1523215906 {
1523315907 //Composite group = (Composite) object;
1523415908 Object3D group = object;
15235
- group.editWindow.ResetCentroid();
15909
+ group.GetWindow().ResetCentroid();
1523615910 }
1523715911
1523815912 void IncDepth()
....@@ -15314,11 +15988,11 @@
1531415988
1531515989 int width = getBounds().width;
1531615990 int height = getBounds().height;
15317
- ClickInfo info = new ClickInfo();
15318
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1531915991 //Image img = CreateImage(width, height);
1532015992 //System.out.println("width = " + width + "; height = " + height + "\n");
15993
+
1532115994 Graphics gr = g; // img.getGraphics();
15995
+
1532215996 if (!hasMarquee)
1532315997 {
1532415998 if (Xmin < Xmax) // !locked)
....@@ -15390,40 +16064,88 @@
1539016064 }
1539116065 if (object != null && !hasMarquee)
1539216066 {
16067
+ if (object.clickInfo == null)
16068
+ object.clickInfo = new ClickInfo();
16069
+ ClickInfo info = object.clickInfo;
16070
+ //ClickInfo info = new ClickInfo();
16071
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16072
+
1539316073 if (isRenderer)
1539416074 {
15395
- info.flags++;
16075
+ object.clickInfo.flags++;
1539616076 double frameAspect = (double) width / (double) height;
1539716077 if (frameAspect > renderCamera.aspect)
1539816078 {
1539916079 int desired = (int) ((double) height * renderCamera.aspect);
15400
- info.bounds.width -= width - desired;
15401
- info.bounds.x += (width - desired) / 2;
16080
+ object.clickInfo.bounds.width -= width - desired;
16081
+ object.clickInfo.bounds.x += (width - desired) / 2;
1540216082 } else
1540316083 {
1540416084 int desired = (int) ((double) width / renderCamera.aspect);
15405
- info.bounds.height -= height - desired;
15406
- info.bounds.y += (height - desired) / 2;
16085
+ object.clickInfo.bounds.height -= height - desired;
16086
+ object.clickInfo.bounds.y += (height - desired) / 2;
1540716087 }
1540816088 }
15409
- info.g = gr;
15410
- info.camera = renderCamera;
16089
+
16090
+ object.clickInfo.g = gr;
16091
+ object.clickInfo.camera = renderCamera;
1541116092 /*
1541216093 // Memory intensive (brep.verticescopy)
1541316094 if (!(object instanceof Composite))
1541416095 object.draw(info, 0, false); // SLOW :
1541516096 */
15416
- if (!isRenderer)
16097
+ if (!isRenderer) // && drag)
1541716098 {
15418
- object.drawEditHandles(info, 0);
16099
+ Grafreed.Assert(object != null);
16100
+ Grafreed.Assert(object.selection != null);
16101
+ if (object.selection.Size() > 0)
16102
+ {
16103
+ int hitSomething = object.selection.get(0).hitSomething;
16104
+
16105
+ object.clickInfo.DX = 0;
16106
+ object.clickInfo.DY = 0;
16107
+ object.clickInfo.W = 1;
16108
+ if (hitSomething == Object3D.hitCenter)
16109
+ {
16110
+ info.DX = X;
16111
+ if (X != 0)
16112
+ info.DX -= info.bounds.width/2;
16113
+
16114
+ info.DY = Y;
16115
+ if (Y != 0)
16116
+ info.DY -= info.bounds.height/2;
16117
+ }
16118
+
16119
+ object.drawEditHandles(//info,
16120
+ 0);
16121
+
16122
+ if (drag && (X != 0 || Y != 0))
16123
+ {
16124
+ switch (hitSomething)
16125
+ {
16126
+ case Object3D.hitCenter: gr.setColor(Color.pink);
16127
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16128
+ break;
16129
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16130
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16131
+ break;
16132
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16133
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16134
+ break;
16135
+ }
16136
+
16137
+ }
16138
+ }
1541916139 }
1542016140 }
16141
+
1542116142 if (isRenderer)
1542216143 {
1542316144 //gr.setColor(Color.black);
1542416145 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1542516146 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1542616147 }
16148
+
1542716149 if (hasMarquee)
1542816150 {
1542916151 gr.setXORMode(Color.white);
....@@ -15536,6 +16258,7 @@
1553616258 public boolean mouseDown(Event evt, int x, int y)
1553716259 {
1553816260 System.out.println("mouseDown: " + evt);
16261
+ System.exit(0);
1553916262 /*
1554016263 locked = true;
1554116264 drag = false;
....@@ -15579,7 +16302,7 @@
1557916302 {
1558016303 keyPressed(0, modifiers);
1558116304 }
15582
- clickStart(x, y, modifiers);
16305
+ // clickStart(x, y, modifiers);
1558316306 return true;
1558416307 }
1558516308
....@@ -15697,7 +16420,7 @@
1569716420 {
1569816421 keyReleased(0, 0);
1569916422 }
15700
- drag(x, y, modifiers);
16423
+ drag(x, y, 0, modifiers);
1570116424 return true;
1570216425 }
1570316426
....@@ -15829,7 +16552,7 @@
1582916552 Object3D object;
1583016553 static Object3D trackedobject;
1583116554 Camera renderCamera; // Light or Eye (or Occlusion)
15832
- /*static*/ Camera manipCamera; // Light or Eye
16555
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1583316556 /*static*/ Camera eyeCamera;
1583416557 /*static*/ Camera lightCamera;
1583516558 int cameracount;
....@@ -15893,6 +16616,8 @@
1589316616 private /*static*/ boolean firstime;
1589416617 private /*static*/ cVector newView = new cVector();
1589516618 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16619
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16620
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1589616621 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1589716622 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1589816623 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -15905,29 +16630,67 @@
1590516630 {
1590616631 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1590716632
16633
+ int usedsuf = 0;
16634
+
1590816635 for (int i = 0; i < suffixes.length; i++)
1590916636 {
15910
- String resourceName = basename + suffixes[i] + "." + suffix;
15911
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
15912
- mipmapped,
15913
- FileUtil.getFileSuffix(resourceName));
15914
- if (data == null)
16637
+ String[] suffixe = suffixes;
16638
+ String[] fallback = suffixes2;
16639
+ String[] fallfallback = suffixes3;
16640
+
16641
+ for (int c=usedsuf; --c>=0;)
1591516642 {
15916
- throw new IOException("Unable to load texture " + resourceName);
16643
+// String[] temp = suffixe;
16644
+// suffixe = fallback;
16645
+// fallback = fallfallback;
16646
+// fallfallback = temp;
1591716647 }
16648
+
16649
+ String resourceName = basename + suffixe[i] + "." + suffix;
16650
+ TextureData data;
16651
+
16652
+ try
16653
+ {
16654
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16655
+ mipmapped,
16656
+ FileUtil.getFileSuffix(resourceName));
16657
+ }
16658
+ catch (Exception e)
16659
+ {
16660
+ try
16661
+ {
16662
+ resourceName = basename + fallback[i] + "." + suffix;
16663
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16664
+ mipmapped,
16665
+ FileUtil.getFileSuffix(resourceName));
16666
+ }
16667
+ catch (Exception e2)
16668
+ {
16669
+ resourceName = basename + fallfallback[i] + "." + suffix;
16670
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16671
+ mipmapped,
16672
+ FileUtil.getFileSuffix(resourceName));
16673
+ }
16674
+ }
16675
+
1591816676 //System.out.println("Target = " + targets[i]);
1591916677 cubemap.updateImage(data, targets[i]);
1592016678 }
1592116679
1592216680 return cubemap;
1592316681 }
16682
+
1592416683 int bigsphere = -1;
1592516684
1592616685 float BGcolor = 0.5f;
1592716686
15928
- private void DrawSkyBox(GL gl)
16687
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16688
+
16689
+ private void DrawSkyBox(GL gl, float ratio)
1592916690 {
15930
- if (envyoff || cubemap == null)
16691
+ if (//envyoff ||
16692
+ WIREFRAME ||
16693
+ cubemap == null)
1593116694 {
1593216695 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1593316696 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -15942,7 +16705,17 @@
1594216705 // Compensates for ExaminerViewer's modification of modelview matrix
1594316706 gl.glMatrixMode(GL.GL_MODELVIEW);
1594416707 gl.glLoadIdentity();
16708
+ gl.glScalef(1,ratio,1);
1594516709
16710
+// colorV[0] = 2;
16711
+// colorV[1] = 2;
16712
+// colorV[2] = 2;
16713
+// colorV[3] = 1;
16714
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16715
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16716
+//
16717
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16718
+
1594616719 //gl.glActiveTexture(GL.GL_TEXTURE1);
1594716720 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1594816721
....@@ -15974,6 +16747,7 @@
1597416747 {
1597516748 gl.glScalef(1.0f, -1.0f, 1.0f);
1597616749 }
16750
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1597716751 gl.glMultMatrixd(viewrot_1, 0);
1597816752 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1597916753 //viewer.updateInverseRotation(gl);
....@@ -16114,16 +16888,16 @@
1611416888 cStatic.objectstack[materialdepth++] = checker;
1611516889 //System.out.println("material " + material);
1611616890 //Applet3D.tracein(this, selected);
16117
- vector2buffer = checker.projectedVertices;
16891
+ //vector2buffer = checker.projectedVertices;
1611816892
1611916893 //checker.GetMaterial().Draw(this, false); // true);
16120
- DrawMaterial(checker.GetMaterial(), false); // true);
16894
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1612116895
1612216896 materialdepth -= 1;
1612316897 if (materialdepth > 0)
1612416898 {
16125
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16126
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
16899
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16900
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1612716901 }
1612816902 //checker.GetMaterial().opacity = 1f;
1612916903 ////checker.GetMaterial().ambient = 1f;
....@@ -16209,6 +16983,14 @@
1620916983 }
1621016984 }
1621116985
16986
+ private Object3D GetFolder()
16987
+ {
16988
+ Object3D folder = object.GetWindow().copy;
16989
+ if (object.GetWindow().copy.selection.Size() > 0)
16990
+ folder = object.GetWindow().copy.selection.elementAt(0);
16991
+ return folder;
16992
+ }
16993
+
1621216994 class SelectBuffer implements GLEventListener
1621316995 {
1621416996
....@@ -16224,7 +17006,7 @@
1622417006 //new Exception().printStackTrace();
1622517007 System.out.println("select buffer init");
1622617008 // Use debug pipeline
16227
- drawable.setGL(new DebugGL(drawable.getGL()));
17009
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1622817010
1622917011 GL gl = drawable.getGL();
1623017012
....@@ -16267,6 +17049,7 @@
1626717049 {
1626817050 if (!selection)
1626917051 {
17052
+ new Exception().printStackTrace();
1627017053 System.exit(0);
1627117054 return;
1627217055 }
....@@ -16287,6 +17070,17 @@
1628717070
1628817071 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1628917072
17073
+ if (PAINTMODE)
17074
+ {
17075
+ if (object.GetWindow().copy.selection.Size() > 0)
17076
+ {
17077
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17078
+
17079
+ // Make what you paint not selectable.
17080
+ paintobj.ResetSelectable();
17081
+ }
17082
+ }
17083
+
1629017084 //int tmp = selection_view;
1629117085 //selection_view = -1;
1629217086 int temp = DrawMode();
....@@ -16298,6 +17092,17 @@
1629817092 // temp = DEFAULT; // patch for selection debug
1629917093 Globals.drawMode = temp; // WARNING
1630017094
17095
+ if (PAINTMODE)
17096
+ {
17097
+ if (object.GetWindow().copy.selection.Size() > 0)
17098
+ {
17099
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17100
+
17101
+ // Revert.
17102
+ paintobj.RestoreSelectable();
17103
+ }
17104
+ }
17105
+
1630117106 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1630217107
1630317108 // trying different ways of getting the depth info over
....@@ -16345,6 +17150,8 @@
1634517150 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1634617151 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1634717152 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
17153
+
17154
+ CreateSelectedPoint();
1634817155
1634917156 // Will fit the mesh !!!
1635017157 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16394,34 +17201,36 @@
1639417201 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]));
1639517202 }
1639617203
16397
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
17204
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1639817205 }
1639917206 }
1640017207
1640117208 if (!movingcamera && !PAINTMODE)
16402
- object.editWindow.ScreenFitPoint(); // fev 2014
17209
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1640317210
16404
- if (PAINTMODE && GrafreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17211
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1640517212 {
16406
- Object3D paintobj = GrafreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17213
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1640717214
16408
- Object3D group = new Object3D("inst" + paintcount++);
17215
+ if (object.GetWindow().copy.selection.Size() > 0)
17216
+ {
17217
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1640917218
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();
17219
+ Object3D inst = new Object3D("inst" + paintcount++);
17220
+
17221
+ inst.CreateMaterial(); // use a void leaf to select instances
17222
+
17223
+ inst.add(paintobj); // link
17224
+
17225
+ object.GetWindow().SnapObject(inst);
17226
+
17227
+ Object3D folder = paintFolder; // GetFolder();
17228
+
17229
+ folder.add(inst);
17230
+
17231
+ object.GetWindow().ResetModel();
17232
+ object.GetWindow().refreshContents();
17233
+ }
1642517234 }
1642617235 else
1642717236 paintcount = 0;
....@@ -16460,6 +17269,11 @@
1646017269 //System.out.println("objects[color] = " + objects[color]);
1646117270 //objects[color].Select();
1646217271 indexcount = 0;
17272
+ ObjEditor window = object.GetWindow();
17273
+ if (window != null && deselect)
17274
+ {
17275
+ window.Select(null, deselect, true);
17276
+ }
1646317277 object.Select(color, deselect);
1646417278 }
1646517279
....@@ -16559,7 +17373,7 @@
1655917373 gl.glDisable(gl.GL_CULL_FACE);
1656017374 }
1656117375
16562
- if (!RENDERSHADOW)
17376
+ if (!Globals.RENDERSHADOW)
1656317377 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1656417378
1656517379 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -16569,7 +17383,7 @@
1656917383 //gl.glColorMask(false, false, false, false);
1657017384
1657117385 //render_scene_from_light_view(gl, drawable, 0, 0);
16572
- if (RENDERSHADOW && Globals.lighttouched && !movingcamera) // && !parent.IsFreezed())
17386
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1657317387 {
1657417388 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1657517389
....@@ -16738,10 +17552,14 @@
1673817552 gl.glFlush();
1673917553
1674017554 /**/
16741
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17555
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1674217556
16743
- float[] pixels = occlusionsizebuffer.array();
17557
+ float[] depths = occlusiondepthbuffer.array();
1674417558
17559
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17560
+
17561
+ int[] pixels = selectsizebuffer.array();
17562
+
1674517563 double r = 0, g = 0, b = 0;
1674617564
1674717565 double count = 0;
....@@ -16752,7 +17570,7 @@
1675217570
1675317571 double FACTOR = 1;
1675417572
16755
- for (int i = 0; i < pixels.length; i++)
17573
+ for (int i = 0; i < depths.length; i++)
1675617574 {
1675717575 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1675817576 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -16835,7 +17653,7 @@
1683517653
1683617654 double scale = ray.z; // 1; // cos
1683717655
16838
- float depth = pixels[newindex];
17656
+ float depth = depths[newindex];
1683917657
1684017658 /*
1684117659 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -16985,23 +17803,15 @@
1698517803 int AAbuffersize = 0;
1698617804
1698717805 //double[] selectedpoint = new double[3];
16988
- static Superellipsoid selectedpoint = new Superellipsoid();
17806
+ static Superellipsoid selectedpoint;
1698917807 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();
17808
+ static Sphere debugpointG;
17809
+ static Sphere debugpointP;
17810
+ static Sphere debugpointC;
17811
+ static Sphere debugpointR;
1699417812
1699517813 static Sphere debugpoints[] = new Sphere[8];
1699617814
16997
- static
16998
- {
16999
- for (int i=0; i<8; i++)
17000
- {
17001
- debugpoints[i] = new Sphere();
17002
- }
17003
- }
17004
-
1700517815 static void InitPoints(float radius)
1700617816 {
1700717817 for (int i=0; i<8; i++)
....@@ -17040,11 +17850,14 @@
1704017850 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1704117851 static IntBuffer bigAAbuffer;
1704217852 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
17043
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17853
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1704417854 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1704517855 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1704617856 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17047
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17857
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17858
+
17859
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17860
+
1704817861 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1704917862 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1705017863 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();