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;
....@@ -61,7 +97,7 @@
6197 //boolean REDUCETEXTURE = true;
6298 boolean CACHETEXTURE = true;
6399 boolean CLEANCACHE = false; // true;
64
- boolean MIPMAP = false; // true;
100
+ boolean MIPMAP = false; // true; // never works...
65101 boolean COMPRESSTEXTURE = false;
66102 boolean KOMPACTTEXTURE = false; // true;
67103 boolean RESIZETEXTURE = false;
....@@ -74,7 +110,9 @@
74110 //private Mat4f spotlightTransform = new Mat4f();
75111 //private Mat4f spotlightInverseTransform = new Mat4f();
76112 static GLContext glcontext = null;
77
- /*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;
78116 boolean reverseUP = false;
79117 static boolean frozen = false;
80118 boolean enablebackspace = false; // patch for back buffer refresh
....@@ -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
....@@ -325,7 +379,7 @@
325379 cStatic.objectstack[materialdepth++] = obj;
326380 //System.out.println("material " + material);
327381 //Applet3D.tracein(this, selected);
328
- display.vector2buffer = obj.projectedVertices;
382
+ //display.vector2buffer = obj.projectedVertices;
329383 if (obj instanceof Camera)
330384 {
331385 display.options1[0] = material.shift;
....@@ -334,14 +388,28 @@
334388 display.options1[2] = material.shadowbias;
335389 display.options1[3] = material.aniso;
336390 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]);
337396 display.options2[0] = material.opacity;
338397 display.options2[1] = material.diffuse;
339398 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]);
340402
341403 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]);
342407 display.options4[0] = material.cameralight/0.2f;
343408 display.options4[1] = material.subsurface;
344409 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]);
345413
346414 // if (display.CURRENTANTIALIAS > 0)
347415 // display.options3[3] /= 4;
....@@ -357,7 +425,7 @@
357425 /**/
358426 } else
359427 {
360
- DrawMaterial(material, selected);
428
+ DrawMaterial(material, selected, obj.projectedVertices);
361429 }
362430 } else
363431 {
....@@ -381,8 +449,8 @@
381449 cStatic.objectstack[materialdepth++] = obj;
382450 //System.out.println("material " + material);
383451 //Applet3D.tracein("selected ", selected);
384
- display.vector2buffer = obj.projectedVertices;
385
- display.DrawMaterial(material, selected);
452
+ //display.vector2buffer = obj.projectedVertices;
453
+ display.DrawMaterial(material, selected, obj.projectedVertices);
386454 }
387455 }
388456
....@@ -399,8 +467,8 @@
399467 materialdepth -= 1;
400468 if (materialdepth > 0)
401469 {
402
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
403
- 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);
404472 }
405473 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
406474 } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
....@@ -420,8 +488,8 @@
420488 materialdepth -= 1;
421489 if (materialdepth > 0)
422490 {
423
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
424
- 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);
425493 }
426494 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
427495 //else
....@@ -462,10 +530,12 @@
462530 if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
463531 {
464532 //gl.glBegin(gl.GL_TRIANGLES);
465
- 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
+ ;
466536 if (!hasnorm)
467537 {
468
- // System.out.println("FUCK!!");
538
+ // System.out.println("Mesh normal");
469539 LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
470540 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
471541 LA.vecCross(obj.v0, obj.v1, obj.v2);
....@@ -1190,10 +1260,12 @@
11901260 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
11911261 }
11921262 }
1263
+
11931264 if (flipV)
11941265 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
11951266 else
11961267 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1268
+
11971269 //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
11981270 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
11991271
....@@ -1213,10 +1285,12 @@
12131285 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
12141286 }
12151287 }
1288
+
12161289 if (flipV)
12171290 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12181291 else
12191292 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1293
+
12201294 //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
12211295 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
12221296
....@@ -1244,8 +1318,10 @@
12441318 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12451319 else
12461320 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1321
+
12471322 //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
12481323 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1324
+
12491325 count2 += 2;
12501326 count3 += 3;
12511327 }
....@@ -1424,6 +1500,8 @@
14241500 gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
14251501 }
14261502
1503
+ float[] colorV = new float[4];
1504
+
14271505 void SetColor(Object3D obj, Vertex p0)
14281506 {
14291507 CameraPane display = this;
....@@ -1491,8 +1569,6 @@
14911569 {
14921570 return;
14931571 }
1494
-
1495
- float[] colorV = new float[3];
14961572
14971573 if (false) // marked)
14981574 {
....@@ -1601,7 +1677,7 @@
16011677 // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
16021678 }
16031679
1604
- void DrawMaterial(cMaterial material, boolean selected)
1680
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
16051681 {
16061682 CameraPane display = this;
16071683 //new Exception().printStackTrace();
....@@ -1628,7 +1704,7 @@
16281704
16291705 cColor.HSBtoRGB(display.color, display.saturation, 1, display.modelParams0);
16301706
1631
- float[] colorV = GrafreeD.colorV;
1707
+ float[] colorV = Grafreed.colorV;
16321708
16331709 /**/
16341710 if (display.DrawMode() == display.DEFAULT) // && display.RENDERPROGRAM == 0)
....@@ -1636,7 +1712,7 @@
16361712 colorV[0] = display.modelParams0[0] * material.diffuse;
16371713 colorV[1] = display.modelParams0[1] * material.diffuse;
16381714 colorV[2] = display.modelParams0[2] * material.diffuse;
1639
- colorV[3] = material.opacity;
1715
+ colorV[3] = 1; // material.opacity;
16401716
16411717 gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
16421718 //System.out.println("Opacity = " + opacity);
....@@ -1744,9 +1820,9 @@
17441820 display.modelParams7[2] = 0;
17451821 display.modelParams7[3] = 0;
17461822
1747
- display.modelParams6[0] = 100; // criss de bug de bump
1823
+ //display.modelParams6[0] = 100; // criss de bug de bump
17481824
1749
- Object3D.cVector2[] extparams = display.vector2buffer;
1825
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
17501826 if (extparams != null && extparams.length > 0 && extparams[0] != null)
17511827 {
17521828 display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
....@@ -1888,7 +1964,7 @@
18881964 void PushMatrix(double[][] matrix)
18891965 {
18901966 // GrafreeD.tracein(matrix);
1891
- PushMatrix(matrix,1);
1967
+ PushMatrix(matrix, 1);
18921968 }
18931969
18941970 void PushMatrix()
....@@ -2042,7 +2118,7 @@
20422118 //System.err.println("Oeil on");
20432119 OEIL = true;
20442120 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2045
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2121
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
20462122 //pingthread.StepToTarget(true);
20472123 }
20482124
....@@ -2140,7 +2216,7 @@
21402216 System.err.println("LIVE = " + Globals.isLIVE());
21412217
21422218 if (!Globals.isLIVE()) // save sound
2143
- GrafreeD.savesound = true; // wav.save();
2219
+ Grafreed.savesound = true; // wav.save();
21442220 // else
21452221 repaint(); // start loop // may 2013
21462222 }
....@@ -2257,7 +2333,7 @@
22572333
22582334 void ToggleDebug()
22592335 {
2260
- DEBUG ^= true;
2336
+ Globals.DEBUG ^= true;
22612337 }
22622338
22632339 void ToggleLookAt()
....@@ -2265,7 +2341,7 @@
22652341 LOOKAT ^= true;
22662342 }
22672343
2268
- void ToggleRandom()
2344
+ void ToggleSwitch()
22692345 {
22702346 SWITCH ^= true;
22712347 }
....@@ -2275,10 +2351,17 @@
22752351 HANDLES ^= true;
22762352 }
22772353
2354
+ Object3D paintFolder;
2355
+
22782356 void TogglePaint()
22792357 {
22802358 PAINTMODE ^= true;
22812359 paintcount = 0;
2360
+
2361
+ if (PAINTMODE)
2362
+ {
2363
+ paintFolder = GetFolder();
2364
+ }
22822365 }
22832366
22842367 void SwapCamera(int a, int b)
....@@ -2374,7 +2457,22 @@
23742457 {
23752458 return currentGL;
23762459 }
2377
-
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
+
23782476 /**/
23792477 class CacheTexture
23802478 {
....@@ -2383,28 +2481,31 @@
23832481
23842482 int resolution;
23852483
2386
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2484
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
23872485 {
2388
- texture = tex;
2486
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2487
+ texturedata = texdata;
23892488 resolution = res;
23902489 }
23912490 }
23922491 /**/
23932492
23942493 // TEXTURE static Texture texture;
2395
- static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures
2396
- = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>();
2397
- 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
+
23982499 int pigmentdepth = 0;
23992500 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
24002501 int bumpdepth = 0;
24012502 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
24022503 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
24032504 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2404
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2505
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
24052506 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
24062507
2407
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2508
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
24082509 {
24092510 TextureData texturedata = null;
24102511
....@@ -2423,13 +2524,34 @@
24232524 if (bump)
24242525 texturedata = ConvertBump(texturedata, false);
24252526
2426
- com.sun.opengl.util.texture.Texture texture =
2427
- 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);
24282529
2429
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2430
- 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);
24312532
2432
- 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;
24332555 }
24342556
24352557 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3502,6 +3624,8 @@
35023624
35033625 System.out.println("LOADING TEXTURE : " + name);
35043626
3627
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3628
+
35053629 //
35063630 if (false) // compressbit > 0)
35073631 {
....@@ -7900,7 +8024,7 @@
79008024 String pigment = Object3D.GetPigment(tex);
79018025 String bump = Object3D.GetBump(tex);
79028026
7903
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8027
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79048028 {
79058029 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79068030 // System.out.println("; bump = " + bump);
....@@ -7915,11 +8039,69 @@
79158039 pigment = null;
79168040 }
79178041
7918
- ReleaseTexture(bump, true);
7919
- ReleaseTexture(pigment, false);
8042
+ ReleaseTexture(tex, true);
8043
+ ReleaseTexture(tex, false);
79208044 }
79218045
7922
- 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)
79238105 {
79248106 if (// DrawMode() != 0 || /*tex == null ||*/
79258107 ambientOcclusion ) // || !textureon)
....@@ -7930,7 +8112,7 @@
79308112 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
79318113
79328114 if (tex != null)
7933
- texture = textures.get(tex);
8115
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
79348116
79358117 // //assert( texture != null );
79368118 // if (texture == null)
....@@ -8022,7 +8204,55 @@
80228204 }
80238205 }
80248206
8025
- /*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
80268256 {
80278257 if (// DrawMode() != 0 || /*tex == null ||*/
80288258 ambientOcclusion ) // || !textureon)
....@@ -8033,17 +8263,47 @@
80338263 if (tex == null)
80348264 {
80358265 BindTexture(null,false,resolution);
8036
- BindTexture(null,true,resolution);
80378266 return;
80388267 }
80398268
80408269 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
+
80418302 String bump = Object3D.GetBump(tex);
80428303
8043
- usedtextures.put(pigment, pigment);
8044
- usedtextures.put(bump, bump);
8304
+ usedtextures.add(tex);
80458305
8046
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8306
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
80478307 {
80488308 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
80498309 // System.out.println("; bump = " + bump);
....@@ -8053,43 +8313,94 @@
80538313 {
80548314 bump = null;
80558315 }
8056
- if (pigment.equals(""))
8057
- {
8058
- pigment = null;
8059
- }
80608316
8061
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8062
- BindTexture(pigment, false, resolution);
80638317 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8064
- BindTexture(bump, true, resolution);
8318
+ BindTexture(tex, true, resolution);
80658319 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8066
-
8067
- return; // true;
80688320 }
80698321
8070
- 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)
80718325 {
8072
- 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;
80738345
80748346 if (tex != null)
80758347 {
8076
- String texname = tex;
8348
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8349
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
80778350
8078
- String[] split = tex.split("Textures");
8079
- if (split.length > 1)
8080
- texname = "/Users/nbriere/Textures" + split[split.length-1];
8081
- else
8082
- if (!texname.startsWith("/"))
8083
- 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
+ }
80848368
80858369 if (CACHETEXTURE)
8086
- texture = textures.get(texname); // TEXTURE CACHE
8087
-
8088
- TextureData texturedata = null;
8089
-
8090
- if (texture == null || texture.resolution < resolution)
80918370 {
8092
- 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(""))
80938404 {
80948405 assert(!bump);
80958406 // if (bump)
....@@ -8100,19 +8411,23 @@
81008411 // }
81018412 // else
81028413 // {
8103
- texture = textures.get(tex);
8104
- if (texture == null)
8414
+ // texturecache = textures.get(texname); // suspicious
8415
+ if (texturecache == null)
81058416 {
8106
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8417
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
81078418 }
8419
+ else
8420
+ new Exception().printStackTrace();
81088421 // }
81098422 } else
8110
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8423
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
81118424 {
81128425 assert(bump);
8113
- texture = textures.get(tex);
8114
- if (texture == null)
8115
- 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();
81168431 } else
81178432 {
81188433 //if (tex.equals("IMMORTAL"))
....@@ -8120,11 +8435,22 @@
81208435 // texture = GetResourceTexture("default.png");
81218436 //} else
81228437 //{
8123
- if (tex.equals("WHITE_NOISE"))
8438
+ if (texname.endsWith("WHITE_NOISE"))
81248439 {
8125
- texture = textures.get(tex);
8126
- if (texture == null)
8127
- 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();
81288454 } else
81298455 {
81308456 if (textureon)
....@@ -8149,7 +8475,7 @@
81498475 }
81508476
81518477 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
8152
- if (!new File(cachename).exists())
8478
+ if (!FileExists(cachename))
81538479 cachename = texname;
81548480 else
81558481 processbump = false; // don't process bump map again
....@@ -8171,7 +8497,7 @@
81718497 }
81728498
81738499 cachename = texname.substring(0, texname.length()-4)+ext+".png";
8174
- if (!new File(cachename).exists())
8500
+ if (!FileExists(cachename))
81758501 cachename = texname;
81768502 else
81778503 processbump = false; // don't process bump map again
....@@ -8180,20 +8506,23 @@
81808506 texturedata = GetFileTexture(cachename, processbump, resolution);
81818507
81828508
8183
- if (texturedata != null)
8184
- 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);
81858513 //texture = GetTexture(tex, bump);
81868514 }
8515
+ }
81878516 }
81888517 //}
81898518 }
81908519
8191
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8520
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
81928521 {
81938522 //return false;
81948523
81958524 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8196
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8525
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
81978526 {
81988527 // String ext = "_highres";
81998528 // if (REDUCETEXTURE)
....@@ -8210,52 +8539,17 @@
82108539 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
82118540 if (!cachefile.exists())
82128541 {
8213
- // cache to disk
8214
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
8215
- //buffers[0].
8216
-
8217
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
8218
- int[] pixels = new int[bytebuf.capacity()/3];
8219
-
8220
- // squared size heuristic...
8221
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8542
+ //if (texturedata.getWidth() == texturedata.getHeight())
82228543 {
8223
- for (int i=pixels.length; --i>=0;)
8224
- {
8225
- int i3 = i*3;
8226
- pixels[i] = 0xFF;
8227
- pixels[i] <<= 8;
8228
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
8229
- pixels[i] <<= 8;
8230
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
8231
- pixels[i] <<= 8;
8232
- pixels[i] |= bytebuf.get(i3) & 0xFF;
8233
- }
8234
-
8235
- /*
8236
- int r=0,g=0,b=0,a=0;
8237
- for (int i=0; i<width; i++)
8238
- for (int j=0; j<height; j++)
8239
- {
8240
- int index = j*width+i;
8241
- int p = pixels[index];
8242
- a = ((p>>24) & 0xFF);
8243
- r = ((p>>16) & 0xFF);
8244
- g = ((p>>8) & 0xFF);
8245
- b = (p & 0xFF);
8246
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
8247
- }
8248
- /**/
8249
- int width = (int)Math.sqrt(pixels.length); // squared
8250
- int height = width;
8251
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
8252
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8544
+ BufferedImage rendImage = CreateBim(texturedata);
8545
+
82538546 ImageWriter writer = null;
82548547 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
82558548 if (iter.hasNext()) {
82568549 writer = (ImageWriter)iter.next();
82578550 }
8258
- float compressionQuality = 0.9f;
8551
+
8552
+ float compressionQuality = 0.85f;
82598553 try
82608554 {
82618555 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8272,18 +8566,20 @@
82728566 }
82738567 }
82748568 }
8275
-
8569
+
8570
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8571
+
82768572 //System.out.println("Texture = " + tex);
8277
- if (textures.containsKey(texname))
8573
+ if (textures.containsKey(tex))
82788574 {
8279
- CacheTexture thetex = textures.get(texname);
8575
+ CacheTexture thetex = textures.get(tex);
82808576 thetex.texture.disable();
82818577 thetex.texture.dispose();
8282
- textures.remove(texname);
8578
+ textures.remove(tex);
82838579 }
82848580
8285
- texture.texturedata = texturedata;
8286
- textures.put(texname, texture);
8581
+ //texture.texturedata = texturedata;
8582
+ textures.put(tex, texturecache);
82878583
82888584 // newtex = true;
82898585 }
....@@ -8299,10 +8595,44 @@
82998595 }
83008596 }
83018597
8302
- return texture;
8598
+ return texturecache;
83038599 }
83048600
8305
- 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
83068636 {
83078637 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
83088638
....@@ -8320,21 +8650,21 @@
83208650 return texture!=null?texture.texture:null;
83218651 }
83228652
8323
- 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
83248654 {
83258655 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
83268656
83278657 return texture!=null?texture.texturedata:null;
83288658 }
83298659
8330
- boolean BindTexture(String tex, boolean bump, int resolution)
8660
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
83318661 {
83328662 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
83338663 {
83348664 return false;
83358665 }
83368666
8337
- boolean newtex = false;
8667
+ //boolean newtex = false;
83388668
83398669 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
83408670
....@@ -8366,9 +8696,75 @@
83668696 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
83678697 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
83688698
8369
- return newtex;
8699
+ return true; // Warning: not used.
83708700 }
83718701
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
+
83728768 ShadowBuffer shadowPBuf;
83738769 AntialiasBuffer antialiasPBuf;
83748770 int MAXSTACK;
....@@ -8385,10 +8781,12 @@
83858781
83868782 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
83878783 MAXSTACK = temp[0];
8388
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8784
+ if (Globals.DEBUG)
8785
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
83898786 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
83908787 MAXSTACK = temp[0];
8391
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8788
+ if (Globals.DEBUG)
8789
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
83928790
83938791 // Use debug pipeline
83948792 //drawable.setGL(new DebugGL(gl)); //
....@@ -8396,7 +8794,8 @@
83968794 gl = drawable.getGL(); //
83978795
83988796 GL gl3 = getGL();
8399
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8797
+ if (Globals.DEBUG)
8798
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
84008799
84018800
84028801 //float pos[] = { 100, 100, 100, 0 };
....@@ -8561,7 +8960,7 @@
85618960
85628961 if (cubemap == null)
85638962 {
8564
- LoadEnvy(5);
8963
+ //LoadEnvy(1);
85658964 }
85668965
85678966 //cubemap.enable();
....@@ -8837,6 +9236,8 @@
88379236
88389237 void LoadEnvy(int which)
88399238 {
9239
+ assert(false);
9240
+
88409241 String name;
88419242 String ext;
88429243
....@@ -8848,37 +9249,58 @@
88489249 cubemap = null;
88499250 return;
88509251 case 1:
8851
- name = "cubemaps/box_";
8852
- ext = "png";
9252
+ name = "cubemaps/rgb/";
9253
+ ext = "jpg";
88539254 reverseUP = false;
88549255 break;
88559256 case 2:
8856
- name = "cubemaps/uffizi_";
8857
- ext = "png";
8858
- break; // reverseUP = true; break;
9257
+ name = "cubemaps/uffizi/";
9258
+ ext = "jpg";
9259
+ reverseUP = false;
9260
+ break;
88599261 case 3:
8860
- name = "cubemaps/CloudyHills_";
8861
- ext = "tga";
9262
+ name = "cubemaps/CloudyHills/";
9263
+ ext = "jpg";
88629264 reverseUP = false;
88639265 break;
88649266 case 4:
8865
- name = "cubemaps/cornell_";
9267
+ name = "cubemaps/cornell/";
88669268 ext = "png";
88679269 reverseUP = false;
88689270 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;
88699296 default:
8870
- name = "cubemaps/rgb_";
8871
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9297
+ name = "cubemaps/box/";
9298
+ ext = "png"; /*mipmap = true;*/
9299
+ reverseUP = false;
88729300 break;
88739301 }
8874
-
8875
- try
8876
- {
8877
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
8878
- } catch (IOException e)
8879
- {
8880
- throw new RuntimeException(e);
8881
- }
9302
+
9303
+ LoadSkybox(name, ext, mipmap);
88829304 }
88839305
88849306 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -8910,8 +9332,12 @@
89109332 static double[] model = new double[16];
89119333 double[] camera2light = new double[16];
89129334 double[] light2camera = new double[16];
8913
- int newenvy = -1;
8914
- boolean envyoff = true; // false;
9335
+
9336
+ //int newenvy = -1;
9337
+ //boolean envyoff = false;
9338
+
9339
+ String loadedskyboxname;
9340
+
89159341 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
89169342 //float[] light0 = { 0,0,0 };
89179343 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9204,11 +9630,35 @@
92049630 jy8[3] = 0.5f;
92059631 }
92069632
9207
- 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
92089634 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
92099635 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
92109636 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
92119637
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
+
92129662 static int imagecount = 0; // movie generation
92139663
92149664 static int jitter = 0;
....@@ -9304,8 +9754,8 @@
93049754 assert (parentcam != renderCamera);
93059755
93069756 if (renderCamera != lightCamera)
9307
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9308
- LA.matConcat(matrix, parentcam.toParent, matrix);
9757
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9758
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
93099759
93109760 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
93119761
....@@ -9320,8 +9770,8 @@
93209770 LA.matCopy(renderCamera.fromScreen, matrix);
93219771
93229772 if (renderCamera != lightCamera)
9323
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9324
- LA.matConcat(parentcam.fromParent, matrix, matrix);
9773
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9774
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
93259775
93269776 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
93279777
....@@ -9367,10 +9817,12 @@
93679817 rati = 1 / rati;
93689818 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
93699819 }
9370
- assert (newenvy == -1);
9820
+
9821
+ //assert (newenvy == -1);
9822
+
93719823 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
93729824 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9373
- DrawSkyBox(gl);
9825
+ DrawSkyBox(gl, (float)rati);
93749826 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
93759827 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
93769828 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -9538,7 +9990,7 @@
95389990
95399991 if (!BOXMODE)
95409992 {
9541
- 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) + ")");
95429994 }
95439995
95449996 if (!BOXMODE)
....@@ -9576,7 +10028,7 @@
957610028 ABORTED = false;
957710029 }
957810030 else
9579
- GrafreeD.wav.cursor += 735 * ACSIZE;
10031
+ Grafreed.wav.cursor += 735 * ACSIZE;
958010032
958110033 if (false)
958210034 {
....@@ -10239,11 +10691,11 @@
1023910691
1024010692 public void display(GLAutoDrawable drawable)
1024110693 {
10242
- if (GrafreeD.savesound && GrafreeD.hassound)
10694
+ if (Grafreed.savesound && Grafreed.hassound)
1024310695 {
10244
- GrafreeD.wav.save();
10245
- GrafreeD.savesound = false;
10246
- GrafreeD.hassound = false;
10696
+ Grafreed.wav.save();
10697
+ Grafreed.savesound = false;
10698
+ Grafreed.hassound = false;
1024710699 }
1024810700 // if (DEBUG_SELECTION)
1024910701 // {
....@@ -10319,6 +10771,7 @@
1031910771 ANTIALIAS = 0;
1032010772 //System.out.println("RESTART");
1032110773 AAtimer.restart();
10774
+ Globals.TIMERRUNNING = true;
1032210775 }
1032310776 }
1032410777 }
....@@ -10373,7 +10826,7 @@
1037310826 Object3D theobject = object;
1037410827 Object3D theparent = object.parent;
1037510828 object.parent = null;
10376
- object = (Object3D)GrafreeD.clone(object);
10829
+ object = (Object3D)Grafreed.clone(object);
1037710830 object.Stripify();
1037810831 if (theobject.selection == null || theobject.selection.Size() == 0)
1037910832 theobject.PreprocessOcclusion(this);
....@@ -10386,13 +10839,14 @@
1038610839 ambientOcclusion = false;
1038710840 }
1038810841
10389
- if (Globals.lighttouched && DrawMode() == DEFAULT && !lightMode) // && !FROZEN)
10842
+ if (//Globals.lighttouched &&
10843
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1039010844 {
1039110845 //if (RENDERSHADOW) // ?
1039210846 if (!IsFrozen())
1039310847 {
1039410848 // dec 2012
10395
- if (!ambientOcclusion && !(!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0))
10849
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
1039610850 {
1039710851 Globals.framecount++;
1039810852 shadowbuffer.display();
....@@ -10405,7 +10859,7 @@
1040510859
1040610860 if (wait)
1040710861 {
10408
- Sleep(500);
10862
+ Sleep(200); // blocks everything
1040910863
1041010864 wait = false;
1041110865 }
....@@ -10519,8 +10973,8 @@
1051910973
1052010974 // if (parentcam != renderCamera) // not a light
1052110975 if (cam != lightCamera)
10522
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10523
- LA.matConcat(matrix, parentcam.toParent, matrix);
10976
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10977
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1052410978
1052510979 for (int j = 0; j < 4; j++)
1052610980 {
....@@ -10534,8 +10988,8 @@
1053410988
1053510989 // if (parentcam != renderCamera) // not a light
1053610990 if (cam != lightCamera)
10537
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10538
- LA.matConcat(parentcam.fromParent, matrix, matrix);
10991
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10992
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1053910993
1054010994 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1054110995
....@@ -10621,13 +11075,41 @@
1062111075 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1062211076 }
1062311077
10624
- 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"))
1062511086 {
10626
- LoadEnvy(newenvy);
11087
+ if (cubemaprgb == null)
11088
+ {
11089
+ cubemaprgb = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11090
+ }
11091
+
11092
+ cubemap = cubemaprgb;
1062711093 }
10628
-
10629
- newenvy = -1;
10630
-
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
+
1063111113 ratio = ((double) getWidth()) / getHeight();
1063211114 //System.out.println("ratio = " + ratio);
1063311115
....@@ -10643,7 +11125,7 @@
1064311125
1064411126 if (!IsFrozen() && !ambientOcclusion)
1064511127 {
10646
- DrawSkyBox(gl);
11128
+ DrawSkyBox(gl, (float)ratio);
1064711129 }
1064811130
1064911131 //if (selection_view == -1)
....@@ -10794,7 +11276,16 @@
1079411276 // Bump noise
1079511277 gl.glActiveTexture(GL.GL_TEXTURE6);
1079611278 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
10797
- 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
+
1079811289
1079911290 gl.glActiveTexture(GL.GL_TEXTURE0);
1080011291 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -10817,9 +11308,9 @@
1081711308
1081811309 gl.glMatrixMode(GL.GL_MODELVIEW);
1081911310
10820
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10821
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10822
-//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);
1082311314 } else
1082411315 {
1082511316 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -10830,7 +11321,7 @@
1083011321 //System.out.println("BLENDING ON");
1083111322 gl.glEnable(GL.GL_BLEND);
1083211323 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
10833
-
11324
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1083411325 gl.glMatrixMode(gl.GL_PROJECTION);
1083511326 gl.glLoadIdentity();
1083611327
....@@ -10919,8 +11410,8 @@
1091911410 System.err.println("parentcam != renderCamera");
1092011411
1092111412 // if (cam != lightCamera)
10922
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10923
- 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
1092411415 }
1092511416
1092611417 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -10941,8 +11432,8 @@
1094111432 if (true) // TODO
1094211433 {
1094311434 if (cam != lightCamera)
10944
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10945
- 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
1094611437 }
1094711438
1094811439 LA.xformPos(light0, cam.toScreen, light0);
....@@ -11079,7 +11570,7 @@
1107911570 }
1108011571 }
1108111572
11082
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11573
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1108311574 {
1108411575 //gl.glDepthFunc(GL.GL_LEQUAL);
1108511576 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11087,24 +11578,21 @@
1108711578
1108811579 boolean texon = textureon;
1108911580
11090
- if (RENDERPROGRAM > 0)
11091
- {
11092
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11093
- textureon = false;
11094
- }
11581
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11582
+ textureon = false;
11583
+
1109511584 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1109611585 //System.out.println("ALLO");
1109711586 gl.glColorMask(false, false, false, false);
1109811587 DrawObject(gl);
11099
- if (RENDERPROGRAM > 0)
11100
- {
11101
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11102
- textureon = texon;
11103
- }
11588
+
11589
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11590
+ textureon = texon;
11591
+
1110411592 gl.glColorMask(true, true, true, true);
1110511593
1110611594 gl.glDepthFunc(GL.GL_EQUAL);
11107
- //gl.glDepthMask(false);
11595
+ gl.glDepthMask(false);
1110811596 }
1110911597
1111011598 if (false) // DrawMode() == SHADOW)
....@@ -11279,23 +11767,44 @@
1127911767 e.printStackTrace();
1128011768 }
1128111769
11282
- if (GrafreeD.RENDERME > 0)
11283
- GrafreeD.RENDERME--; // mechante magouille
11770
+ if (Grafreed.RENDERME > 0)
11771
+ Grafreed.RENDERME--; // mechante magouille
1128411772
1128511773 Globals.ONESTEP = false;
1128611774 }
1128711775
1128811776 static boolean zoomonce = false;
1128911777
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
+
1129011796 void DrawObject(GL gl, boolean draw)
1129111797 {
11798
+ // To clear camera values
11799
+ ResetOptions();
11800
+
1129211801 //System.out.println("DRAW OBJECT " + mouseDown);
1129311802 // DrawMode() = SELECTION;
1129411803 //GL gl = getGL();
1129511804 if ((TRACK || SHADOWTRACK) || zoomonce)
1129611805 {
1129711806 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11298
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11807
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1129911808 pingthread.StepToTarget(true); // true);
1130011809 // zoomonce = false;
1130111810 }
....@@ -11350,7 +11859,14 @@
1135011859
1135111860 usedtextures.clear();
1135211861
11353
- 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
+ }
1135411870 }
1135511871 //System.out.println("--> " + stackdepth);
1135611872 // GrafreeD.traceon();
....@@ -11360,8 +11876,9 @@
1136011876
1136111877 if (DrawMode() == DEFAULT)
1136211878 {
11363
- if (DEBUG)
11879
+ if (Globals.DEBUG)
1136411880 {
11881
+ CreateSelectedPoint();
1136511882 float radius = 0.05f;
1136611883 if (selectedpoint.radius != radius)
1136711884 {
....@@ -11415,20 +11932,32 @@
1141511932 ReleaseTextures(DEFAULT_TEXTURES);
1141611933
1141711934 if (CLEANCACHE)
11418
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11935
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1141911936 {
11420
- String tex = e.nextElement();
11937
+ cTexture tex = e.nextElement();
1142111938
1142211939 // System.out.println("Texture --------- " + tex);
1142311940
11424
- if (tex.equals("WHITE_NOISE"))
11941
+ if (tex.equals("WHITE_NOISE:"))
1142511942 continue;
1142611943
11427
- if (!usedtextures.containsKey(tex))
11944
+ if (!usedtextures.contains(tex))
1142811945 {
11946
+ CacheTexture gettex = texturepigment.get(tex);
1142911947 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11430
- textures.get(tex).texture.dispose();
11431
- 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
+ }
1143211961 }
1143311962 }
1143411963 }
....@@ -11441,7 +11970,14 @@
1144111970 if (checker != null && DrawMode() == DEFAULT)
1144211971 {
1144311972 //BindTexture(IMMORTAL_TEXTURE);
11444
- 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
+ }
1144511981 // NEAREST
1144611982 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
1144711983 DrawChecker(gl);
....@@ -11523,7 +12059,7 @@
1152312059 return;
1152412060 }
1152512061
11526
- String string = obj.GetToolTip();
12062
+ String string = obj.toString(); //.GetToolTip();
1152712063
1152812064 GL gl = GetGL();
1152912065
....@@ -11840,8 +12376,8 @@
1184012376 //obj.TransformToWorld(light, light);
1184112377 for (int i = tp.size(); --i >= 0;)
1184212378 {
11843
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
11844
- 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);
1184512381 }
1184612382
1184712383
....@@ -11858,8 +12394,8 @@
1185812394 parentcam = cameras[0];
1185912395 }
1186012396
11861
- for (int count = parentcam.GetTransformCount(); --count>=0;)
11862
- 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
1186312399
1186412400 LA.xformPos(light, renderCamera.toScreen, light);
1186512401
....@@ -11949,8 +12485,76 @@
1194912485
1195012486 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1195112487
11952
- String program =
12488
+ String programmin =
12489
+ // Min shader
1195312490 "!!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
+
1195412558 //"OPTION ARB_fragment_program_shadow;" +
1195512559 "PARAM light2cam0 = program.env[10];" +
1195612560 "PARAM light2cam1 = program.env[11];" +
....@@ -12065,8 +12669,7 @@
1206512669 "TEMP shininess;" +
1206612670 "\n" +
1206712671 "MOV texSamp, one;" +
12068
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12069
-
12672
+
1207012673 "MOV mapgrid.x, one2048th.x;" +
1207112674 "MOV temp, fragment.texcoord[1];" +
1207212675 /*
....@@ -12087,20 +12690,20 @@
1208712690 "MUL temp, floor, mapgrid.x;" +
1208812691 //"TEX depth0, temp, texture[1], 2D;" +
1208912692 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12090
- TextureFetch("depth0", "temp", "1") +
12693
+ ShadowTextureFetch("depth0", "temp", "1") +
1209112694 "") +
1209212695 "ADD temp.x, temp.x, mapgrid.x;" +
1209312696 //"TEX depth1, temp, texture[1], 2D;" +
1209412697 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12095
- TextureFetch("depth1", "temp", "1") +
12698
+ ShadowTextureFetch("depth1", "temp", "1") +
1209612699 "") +
1209712700 "ADD temp.y, temp.y, mapgrid.x;" +
1209812701 //"TEX depth2, temp, texture[1], 2D;" +
12099
- TextureFetch("depth2", "temp", "1") +
12702
+ ShadowTextureFetch("depth2", "temp", "1") +
1210012703 "SUB temp.x, temp.x, mapgrid.x;" +
1210112704 //"TEX depth3, temp, texture[1], 2D;" +
1210212705 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12103
- TextureFetch("depth3", "temp", "1") +
12706
+ ShadowTextureFetch("depth3", "temp", "1") +
1210412707 "") +
1210512708 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1210612709 //"MOV params, material;" +
....@@ -12471,10 +13074,10 @@
1247113074 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1247213075 "") +
1247313076
12474
- // display shadow only (bump == 0)
13077
+ // display shadow only (fakedepth == 0)
1247513078 "SUB temp.x, half.x, shadow.x;" +
12476
- "MOV temp.y, -params6.x;" +
12477
- "SLT temp.z, temp.y, zero.x;" +
13079
+ "MOV temp.y, -params5.z;" + // params6.x;" +
13080
+ "SLT temp.z, temp.y, -c256i.x;" +
1247813081 "SUB temp.y, one.x, temp.z;" +
1247913082 "MUL temp.x, temp.x, temp.y;" +
1248013083 "KIL temp.x;" +
....@@ -12754,7 +13357,7 @@
1275413357 "MUL final.y, fragment.texcoord[0].x, c256;" +
1275513358 "FLR final.x, final.y;" +
1275613359 "SUB final.y, final.y, final.x;" +
12757
- //"MUL final.x, final.x, c256i;" +
13360
+ "MUL final.x, final.x, c256i;" +
1275813361 "MOV final.z, zero.x;" +
1275913362 "MOV final.a, one.w;":""
1276013363 ) +
....@@ -12762,7 +13365,7 @@
1276213365 "MUL final.y, fragment.texcoord[0].y, c256;" +
1276313366 "FLR final.x, final.y;" +
1276413367 "SUB final.y, final.y, final.x;" +
12765
- //"MUL final.x, final.x, c256i;" +
13368
+ "MUL final.x, final.x, c256i;" +
1276613369 "MOV final.z, zero.x;" +
1276713370 "MOV final.a, one.w;":""
1276813371 ) +
....@@ -12805,7 +13408,14 @@
1280513408 //once = true;
1280613409 }
1280713410
12808
- 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());
1280913419 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1281013420 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1281113421
....@@ -12898,25 +13508,26 @@
1289813508 return out;
1289913509 }
1290013510
12901
- String TextureFetch(String dest, String src, String unit)
13511
+ // Also does frustum culling
13512
+ String ShadowTextureFetch(String dest, String src, String unit)
1290213513 {
1290313514 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1290413515 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1290513516 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13517
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13518
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1290613519 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12907
- "SLT " + src + ".z, " + src + ".x, one.x;" +
12908
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12909
- "SLT " + src + ".z, " + src + ".y, one.x;" +
12910
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13520
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13521
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1291113522 //"SWZ buffer, temp, w,w,w,w;";
12912
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13523
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1291313524 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1291413525 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1291513526 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
12916
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13527
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1291713528
12918
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
12919
- //"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;";
1292013531 }
1292113532
1292213533 String Shadow(String depth, String shadow)
....@@ -12938,12 +13549,16 @@
1293813549
1293913550 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1294013551 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13552
+
13553
+ // Compare fragment depth in light space with shadowmap.
1294113554 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1294213555 "SGE temp.y, temp.x, zero.x;" +
12943
- "SUB " + shadow + ".y, one.x, temp.y;" +
13556
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13557
+
13558
+ // Reverse comparison
1294413559 "SUB temp.x, one.x, temp.x;" +
1294513560 "MUL " + shadow + ".x, temp.x, temp.y;" +
12946
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13561
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1294713562 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1294813563
1294913564 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -12957,6 +13572,10 @@
1295713572 // No shadow for backface
1295813573 "DP3 temp.x, normal, lightd;" +
1295913574 "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;" +
1296013579 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1296113580 "";
1296213581 }
....@@ -13103,7 +13722,8 @@
1310313722 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1310413723 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1310513724 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13106
- Object3D.cVector2[] vector2buffer;
13725
+
13726
+ //Object3D.cVector2[] vector2buffer;
1310713727
1310813728 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1310913729 // OUT : diff, spec
....@@ -13119,9 +13739,10 @@
1311913739 "DP3 " + dest + ".z," + "normals," + "eye;" +
1312013740 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1312113741 //"MOV " + dest + ".w," + "normal.z;" +
13122
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
13123
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13124
- //"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
1312513746 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1312613747 "RCP " + dest + ".w," + dest + ".w;" +
1312713748 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13515,7 +14136,7 @@
1351514136 public void mousePressed(MouseEvent e)
1351614137 {
1351714138 //System.out.println("mousePressed: " + e);
13518
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14139
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1351914140 }
1352014141
1352114142 static long prevtime = 0;
....@@ -13591,8 +14212,8 @@
1359114212 // mode |= META;
1359214213 //}
1359314214
13594
- SetMouseMode(WHEEL | e.getModifiersEx());
13595
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14215
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14216
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1359614217 anchorX = ax;
1359714218 anchorY = ay;
1359814219 prevX = px;
....@@ -13626,6 +14247,7 @@
1362614247 else
1362714248 if (evt.getSource() == AAtimer)
1362814249 {
14250
+ Globals.TIMERRUNNING = false;
1362914251 if (mouseDown)
1363014252 {
1363114253 //new Exception().printStackTrace();
....@@ -13651,6 +14273,10 @@
1365114273 // LIVE = waslive;
1365214274 // wasliveok = true;
1365314275 // waslive = false;
14276
+
14277
+ // May 2019 Forget it:
14278
+ if (true)
14279
+ return;
1365414280
1365514281 // source == timer
1365614282 if (mouseDown)
....@@ -13681,7 +14307,7 @@
1368114307
1368214308 // fev 2014???
1368314309 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13684
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14310
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1368514311 pingthread.StepToTarget(true); // true);
1368614312 }
1368714313 // if (!LIVE)
....@@ -13690,12 +14316,13 @@
1369014316
1369114317 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1369214318
13693
- void clickStart(int x, int y, int modifiers)
14319
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1369414320 {
1369514321 if (!wasliveok)
1369614322 return;
1369714323
1369814324 AAtimer.restart(); //
14325
+ Globals.TIMERRUNNING = true;
1369914326
1370014327 // waslive = LIVE;
1370114328 // LIVE = false;
....@@ -13707,7 +14334,7 @@
1370714334 // touched = true; // main DL
1370814335 if (isRenderer)
1370914336 {
13710
- SetMouseMode(modifiers);
14337
+ SetMouseMode(modifiers, modifiersex);
1371114338 }
1371214339
1371314340 selectX = anchorX = x;
....@@ -13720,7 +14347,7 @@
1372014347 clicked = true;
1372114348 hold = false;
1372214349
13723
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14350
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1372414351 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1372514352 {
1372614353 // System.out.println("RESTART II " + modifiers);
....@@ -13745,14 +14372,15 @@
1374514372 drag = false;
1374614373 //System.out.println("Mouse DOWN");
1374714374 editObj = false;
13748
- ClickInfo info = new ClickInfo();
13749
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
13750
- info.pane = this;
13751
- info.camera = renderCamera;
13752
- info.x = x;
13753
- info.y = y;
13754
- info.modifiers = modifiers;
13755
- 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);
1375614384 if (!editObj)
1375714385 {
1375814386 hasMarquee = true;
....@@ -13768,9 +14396,12 @@
1376814396
1376914397 public void mouseDragged(MouseEvent e)
1377014398 {
14399
+ Globals.MOUSEDRAGGED = true;
14400
+
1377114401 //System.out.println("mouseDragged: " + e);
1377214402 if (isRenderer)
1377314403 movingcamera = true;
14404
+
1377414405 //if (drawing)
1377514406 //return;
1377614407 if ((e.getModifiersEx() & CTRL) != 0
....@@ -13780,7 +14411,7 @@
1378014411 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1378114412 }
1378214413 else
13783
- drag(e.getX(), e.getY(), e.getModifiersEx());
14414
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1378414415
1378514416 //try { Thread.sleep(1); } catch (Exception ex) {}
1378614417 }
....@@ -14017,7 +14648,7 @@
1401714648 {
1401814649 Globals.lighttouched = true;
1401914650 }
14020
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14651
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1402114652 }
1402214653 //else
1402314654 }
....@@ -14031,12 +14662,12 @@
1403114662 void GoDown(int mod)
1403214663 {
1403314664 MODIFIERS |= COMMAND;
14034
- /*
14665
+ /**/
1403514666 if((mod&SHIFT) == SHIFT)
14036
- manipCamera.RotatePosition(0, -speed);
14667
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
1403714668 else
14038
- manipCamera.BackForth(0, -speed*delta, getWidth());
14039
- */
14669
+ manipCamera.RotatePosition(0, -speed);
14670
+ /**/
1404014671 if ((mod & SHIFT) == SHIFT)
1404114672 {
1404214673 mouseMode = mouseMode; // VR??
....@@ -14052,12 +14683,12 @@
1405214683 void GoUp(int mod)
1405314684 {
1405414685 MODIFIERS |= COMMAND;
14055
- /*
14686
+ /**/
1405614687 if((mod&SHIFT) == SHIFT)
14057
- manipCamera.RotatePosition(0, speed);
14688
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
1405814689 else
14059
- manipCamera.BackForth(0, speed*delta, getWidth());
14060
- */
14690
+ manipCamera.RotatePosition(0, speed);
14691
+ /**/
1406114692 if ((mod & SHIFT) == SHIFT)
1406214693 {
1406314694 mouseMode = mouseMode;
....@@ -14073,12 +14704,12 @@
1407314704 void GoLeft(int mod)
1407414705 {
1407514706 MODIFIERS |= COMMAND;
14076
- /*
14707
+ /**/
1407714708 if((mod&SHIFT) == SHIFT)
14078
- manipCamera.RotatePosition(speed, 0);
14079
- else
1408014709 manipCamera.Translate(speed*delta, 0, getWidth());
14081
- */
14710
+ else
14711
+ manipCamera.RotatePosition(speed, 0);
14712
+ /**/
1408214713 if ((mod & SHIFT) == SHIFT)
1408314714 {
1408414715 mouseMode = mouseMode;
....@@ -14094,12 +14725,12 @@
1409414725 void GoRight(int mod)
1409514726 {
1409614727 MODIFIERS |= COMMAND;
14097
- /*
14728
+ /**/
1409814729 if((mod&SHIFT) == SHIFT)
14099
- manipCamera.RotatePosition(-speed, 0);
14100
- else
1410114730 manipCamera.Translate(-speed*delta, 0, getWidth());
14102
- */
14731
+ else
14732
+ manipCamera.RotatePosition(-speed, 0);
14733
+ /**/
1410314734 if ((mod & SHIFT) == SHIFT)
1410414735 {
1410514736 mouseMode = mouseMode;
....@@ -14117,7 +14748,7 @@
1411714748 int X, Y;
1411814749 boolean SX, SY;
1411914750
14120
- void drag(int x, int y, int modifiers)
14751
+ void drag(int x, int y, int modifiers, int modifiersex)
1412114752 {
1412214753 if (IsFrozen())
1412314754 {
....@@ -14126,17 +14757,17 @@
1412614757
1412714758 drag = true; // NEW
1412814759
14129
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14760
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1413014761
1413114762 X = x;
1413214763 Y = y;
1413314764 // floating state for animation
14134
- MODIFIERS = modifiers;
14135
- modifiers &= ~1024;
14765
+ MODIFIERS = modifiersex;
14766
+ modifiersex &= ~1024;
1413614767 if (false) // modifiers != 0)
1413714768 {
1413814769 //new Exception().printStackTrace();
14139
- System.out.println("mouseDragged: " + modifiers);
14770
+ System.out.println("mouseDragged: " + modifiersex);
1414014771 System.out.println("SHIFT = " + SHIFT);
1414114772 System.out.println("CONTROL = " + COMMAND);
1414214773 System.out.println("META = " + META);
....@@ -14149,14 +14780,16 @@
1414914780 if (editObj)
1415014781 {
1415114782 drag = true;
14152
- ClickInfo info = new ClickInfo();
14153
- info.bounds.setBounds(0, 0,
14783
+ //ClickInfo info = new ClickInfo();
14784
+ object.clickInfo.bounds.setBounds(0, 0,
1415414785 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14155
- info.pane = this;
14156
- info.camera = renderCamera;
14157
- info.x = x;
14158
- info.y = y;
14159
- 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);
1416014793 } else
1416114794 {
1416214795 if (x < startX)
....@@ -14305,22 +14938,27 @@
1430514938 }
1430614939 }
1430714940
14941
+// ClickInfo clickInfo = new ClickInfo();
14942
+
1430814943 public void mouseMoved(MouseEvent e)
1430914944 {
1431014945 //System.out.println("mouseMoved: " + e);
1431114946 if (isRenderer)
1431214947 return;
1431314948
14314
- ClickInfo ci = new ClickInfo();
14315
- ci.x = e.getX();
14316
- ci.y = e.getY();
14317
- ci.modifiers = e.getModifiersEx();
14318
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14319
- ci.pane = this;
14320
- 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;
1432114956 if (!isRenderer)
1432214957 {
14323
- if (object.editWindow.copy.doEditClick(ci, 0))
14958
+ //ObjEditor editWindow = object.editWindow;
14959
+ //Object3D copy = editWindow.copy;
14960
+ if (object.doEditClick(//clickInfo,
14961
+ 0))
1432414962 {
1432514963 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1432614964 } else
....@@ -14332,7 +14970,11 @@
1433214970
1433314971 public void mouseReleased(MouseEvent e)
1433414972 {
14973
+ Globals.MOUSEDRAGGED = false;
14974
+
1433514975 movingcamera = false;
14976
+ X = 0; // getBounds().width/2;
14977
+ Y = 0; // getBounds().height/2;
1433614978 //System.out.println("mouseReleased: " + e);
1433714979 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1433814980 }
....@@ -14355,9 +14997,9 @@
1435514997 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1435614998 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1435714999
14358
- if (control || command || IsFrozen())
15000
+// No delay if (control || command || IsFrozen())
1435915001 timeout = true;
14360
- else
15002
+// ?? May 2019 else
1436115003 // timer.setDelay((modifiers & 128) != 0?0:350);
1436215004 mouseDown = false;
1436315005 if (!control && !command) // june 2013
....@@ -14467,7 +15109,7 @@
1446715109 System.out.println("keyReleased: " + e);
1446815110 }
1446915111
14470
- void SetMouseMode(int modifiers)
15112
+ void SetMouseMode(int modifiers, int modifiersex)
1447115113 {
1447215114 //System.out.println("SetMouseMode = " + modifiers);
1447315115 //modifiers &= ~1024;
....@@ -14479,25 +15121,25 @@
1447915121 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1448015122 // return;
1448115123 //System.out.println("SetMode = " + modifiers);
14482
- if ((modifiers & WHEEL) == WHEEL)
15124
+ if ((modifiersex & WHEEL) == WHEEL)
1448315125 {
1448415126 mouseMode |= ZOOM;
1448515127 }
1448615128
1448715129 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
14488
- if (capsLocked || (modifiers & META) == META)
15130
+ if (capsLocked) // || (modifiers & META) == META)
1448915131 {
1449015132 mouseMode |= VR; // BACKFORTH;
1449115133 }
14492
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
15134
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1449315135 {
1449415136 mouseMode |= SELECT;
1449515137 }
14496
- if ((modifiers & COMMAND) == COMMAND)
15138
+ if ((modifiersex & COMMAND) == COMMAND)
1449715139 {
1449815140 mouseMode |= SELECT;
1449915141 }
14500
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15142
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
1450115143 {
1450215144 mouseMode &= ~VR;
1450315145 mouseMode |= TRANSLATE;
....@@ -14526,7 +15168,7 @@
1452615168
1452715169 if (isRenderer) //
1452815170 {
14529
- SetMouseMode(modifiers);
15171
+ SetMouseMode(0, modifiers);
1453015172 }
1453115173
1453215174 Globals.theRenderer.keyPressed(key);
....@@ -14588,7 +15230,8 @@
1458815230 // break;
1458915231 case 'T':
1459015232 CACHETEXTURE ^= true;
14591
- textures.clear();
15233
+ texturepigment.clear();
15234
+ texturebump.clear();
1459215235 // repaint();
1459315236 break;
1459415237 case 'Y':
....@@ -14673,7 +15316,9 @@
1467315316 case 'E' : COMPACT ^= true;
1467415317 repaint();
1467515318 break;
14676
- case 'W' : DEBUGHSB ^= true;
15319
+ case 'W' : // Wide Window (fullscreen)
15320
+ //DEBUGHSB ^= true;
15321
+ ObjEditor.theFrame.ToggleFullScreen();
1467715322 repaint();
1467815323 break;
1467915324 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14698,8 +15343,8 @@
1469815343 RevertCamera();
1469915344 repaint();
1470015345 break;
14701
- case 'L':
1470215346 case 'l':
15347
+ //case 'L':
1470315348 if (lightMode)
1470415349 {
1470515350 lightMode = false;
....@@ -14763,20 +15408,24 @@
1476315408 OCCLUSION_CULLING ^= true;
1476415409 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1476515410 break;
14766
- case '0': envyoff ^= true; repaint(); break;
15411
+ //case '0': envyoff ^= true; repaint(); break;
1476715412 case '1':
1476815413 case '2':
1476915414 case '3':
1477015415 case '4':
1477115416 case '5':
14772
- newenvy = Character.getNumericValue(key);
14773
- repaint();
14774
- break;
1477515417 case '6':
1477615418 case '7':
1477715419 case '8':
1477815420 case '9':
14779
- 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
+ }
1478015429 repaint();
1478115430 break;
1478215431 case '!':
....@@ -14842,9 +15491,9 @@
1484215491 case '_':
1484315492 kompactbit = 5;
1484415493 break;
14845
- case '+':
14846
- kompactbit = 6;
14847
- break;
15494
+// case '+':
15495
+// kompactbit = 6;
15496
+// break;
1484815497 case ' ':
1484915498 lightMode ^= true;
1485015499 Globals.lighttouched = true;
....@@ -14856,13 +15505,14 @@
1485615505 case ESC:
1485715506 RENDERPROGRAM += 1;
1485815507 RENDERPROGRAM %= 3;
15508
+
1485915509 repaint();
1486015510 break;
1486115511 case 'Z':
1486215512 //RESIZETEXTURE ^= true;
1486315513 //break;
1486415514 case 'z':
14865
- RENDERSHADOW ^= true;
15515
+ Globals.RENDERSHADOW ^= true;
1486615516 Globals.lighttouched = true;
1486715517 repaint();
1486815518 break;
....@@ -14895,8 +15545,9 @@
1489515545 case DELETE:
1489615546 ClearSelection();
1489715547 break;
14898
- /*
1489915548 case '+':
15549
+
15550
+ /*
1490015551 //fontsize += 1;
1490115552 bbzoom *= 2;
1490215553 repaint();
....@@ -14913,17 +15564,17 @@
1491315564 case '=':
1491415565 IncDepth();
1491515566 //fontsize += 1;
14916
- object.editWindow.refreshContents(true);
15567
+ object.GetWindow().refreshContents(true);
1491715568 maskbit = 6;
1491815569 break;
1491915570 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1492015571 DecDepth();
1492115572 maskbit = 5;
1492215573 //if(fontsize > 1) fontsize -= 1;
14923
- if (object.editWindow == null)
14924
- new Exception().printStackTrace();
14925
- else
14926
- object.editWindow.refreshContents(true);
15574
+// if (object.editWindow == null)
15575
+// new Exception().printStackTrace();
15576
+// else
15577
+ object.GetWindow().refreshContents(true);
1492715578 break;
1492815579 case '{':
1492915580 manipCamera.shaper_fovy /= 1.1;
....@@ -14986,7 +15637,7 @@
1498615637 //mode = ROTATE;
1498715638 if ((MODIFIERS & COMMAND) == 0) // VR??
1498815639 {
14989
- SetMouseMode(modifiers);
15640
+ SetMouseMode(0, modifiers);
1499015641 }
1499115642 }
1499215643
....@@ -15122,7 +15773,7 @@
1512215773 {
1512315774 //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
1512415775 //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15125
- if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (mouseMode & SELECT) == 0)
15776
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1512615777 {
1512715778 mouseMoved(e);
1512815779 } else
....@@ -15147,7 +15798,7 @@
1514715798 }
1514815799 */
1514915800
15150
- object.editWindow.EditSelection();
15801
+ object.GetWindow().EditSelection(false);
1515115802 }
1515215803
1515315804 void SelectParent()
....@@ -15164,10 +15815,10 @@
1516415815 {
1516515816 //selectees.remove(i);
1516615817 System.out.println("select parent of " + elem);
15167
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15818
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1516815819 } else
1516915820 {
15170
- group.editWindow.Select(elem.GetTreePath(), first, true);
15821
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1517115822 }
1517215823
1517315824 first = false;
....@@ -15209,12 +15860,12 @@
1520915860 for (int j = 0; j < group.children.size(); j++)
1521015861 {
1521115862 elem = (Object3D) group.children.elementAt(j);
15212
- object.editWindow.Select(elem.GetTreePath(), first, true);
15863
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1521315864 first = false;
1521415865 }
1521515866 } else
1521615867 {
15217
- object.editWindow.Select(elem.GetTreePath(), first, true);
15868
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1521815869 }
1521915870
1522015871 first = false;
....@@ -15225,21 +15876,21 @@
1522515876 {
1522615877 //Composite group = (Composite) object;
1522715878 Object3D group = object;
15228
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15879
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1522915880 }
1523015881
1523115882 void ResetTransform(int mask)
1523215883 {
1523315884 //Composite group = (Composite) object;
1523415885 Object3D group = object;
15235
- group.editWindow.ResetTransform(mask);
15886
+ group.GetWindow().ResetTransform(mask);
1523615887 }
1523715888
1523815889 void FlipTransform()
1523915890 {
1524015891 //Composite group = (Composite) object;
1524115892 Object3D group = object;
15242
- group.editWindow.FlipTransform();
15893
+ group.GetWindow().FlipTransform();
1524315894 // group.editWindow.ReduceMesh(true);
1524415895 }
1524515896
....@@ -15247,7 +15898,7 @@
1524715898 {
1524815899 //Composite group = (Composite) object;
1524915900 Object3D group = object;
15250
- group.editWindow.PrintMemory();
15901
+ group.GetWindow().PrintMemory();
1525115902 // group.editWindow.ReduceMesh(true);
1525215903 }
1525315904
....@@ -15255,7 +15906,7 @@
1525515906 {
1525615907 //Composite group = (Composite) object;
1525715908 Object3D group = object;
15258
- group.editWindow.ResetCentroid();
15909
+ group.GetWindow().ResetCentroid();
1525915910 }
1526015911
1526115912 void IncDepth()
....@@ -15337,11 +15988,11 @@
1533715988
1533815989 int width = getBounds().width;
1533915990 int height = getBounds().height;
15340
- ClickInfo info = new ClickInfo();
15341
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1534215991 //Image img = CreateImage(width, height);
1534315992 //System.out.println("width = " + width + "; height = " + height + "\n");
15993
+
1534415994 Graphics gr = g; // img.getGraphics();
15995
+
1534515996 if (!hasMarquee)
1534615997 {
1534715998 if (Xmin < Xmax) // !locked)
....@@ -15413,40 +16064,88 @@
1541316064 }
1541416065 if (object != null && !hasMarquee)
1541516066 {
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
+
1541616073 if (isRenderer)
1541716074 {
15418
- info.flags++;
16075
+ object.clickInfo.flags++;
1541916076 double frameAspect = (double) width / (double) height;
1542016077 if (frameAspect > renderCamera.aspect)
1542116078 {
1542216079 int desired = (int) ((double) height * renderCamera.aspect);
15423
- info.bounds.width -= width - desired;
15424
- info.bounds.x += (width - desired) / 2;
16080
+ object.clickInfo.bounds.width -= width - desired;
16081
+ object.clickInfo.bounds.x += (width - desired) / 2;
1542516082 } else
1542616083 {
1542716084 int desired = (int) ((double) width / renderCamera.aspect);
15428
- info.bounds.height -= height - desired;
15429
- info.bounds.y += (height - desired) / 2;
16085
+ object.clickInfo.bounds.height -= height - desired;
16086
+ object.clickInfo.bounds.y += (height - desired) / 2;
1543016087 }
1543116088 }
15432
- info.g = gr;
15433
- info.camera = renderCamera;
16089
+
16090
+ object.clickInfo.g = gr;
16091
+ object.clickInfo.camera = renderCamera;
1543416092 /*
1543516093 // Memory intensive (brep.verticescopy)
1543616094 if (!(object instanceof Composite))
1543716095 object.draw(info, 0, false); // SLOW :
1543816096 */
15439
- if (!isRenderer)
16097
+ if (!isRenderer) // && drag)
1544016098 {
15441
- 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
+ }
1544216139 }
1544316140 }
16141
+
1544416142 if (isRenderer)
1544516143 {
1544616144 //gr.setColor(Color.black);
1544716145 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1544816146 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1544916147 }
16148
+
1545016149 if (hasMarquee)
1545116150 {
1545216151 gr.setXORMode(Color.white);
....@@ -15559,6 +16258,7 @@
1555916258 public boolean mouseDown(Event evt, int x, int y)
1556016259 {
1556116260 System.out.println("mouseDown: " + evt);
16261
+ System.exit(0);
1556216262 /*
1556316263 locked = true;
1556416264 drag = false;
....@@ -15602,7 +16302,7 @@
1560216302 {
1560316303 keyPressed(0, modifiers);
1560416304 }
15605
- clickStart(x, y, modifiers);
16305
+ // clickStart(x, y, modifiers);
1560616306 return true;
1560716307 }
1560816308
....@@ -15720,7 +16420,7 @@
1572016420 {
1572116421 keyReleased(0, 0);
1572216422 }
15723
- drag(x, y, modifiers);
16423
+ drag(x, y, 0, modifiers);
1572416424 return true;
1572516425 }
1572616426
....@@ -15852,7 +16552,7 @@
1585216552 Object3D object;
1585316553 static Object3D trackedobject;
1585416554 Camera renderCamera; // Light or Eye (or Occlusion)
15855
- /*static*/ Camera manipCamera; // Light or Eye
16555
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1585616556 /*static*/ Camera eyeCamera;
1585716557 /*static*/ Camera lightCamera;
1585816558 int cameracount;
....@@ -15916,6 +16616,8 @@
1591616616 private /*static*/ boolean firstime;
1591716617 private /*static*/ cVector newView = new cVector();
1591816618 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"};
1591916621 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1592016622 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1592116623 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -15928,29 +16630,67 @@
1592816630 {
1592916631 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1593016632
16633
+ int usedsuf = 0;
16634
+
1593116635 for (int i = 0; i < suffixes.length; i++)
1593216636 {
15933
- String resourceName = basename + suffixes[i] + "." + suffix;
15934
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
15935
- mipmapped,
15936
- FileUtil.getFileSuffix(resourceName));
15937
- if (data == null)
16637
+ String[] suffixe = suffixes;
16638
+ String[] fallback = suffixes2;
16639
+ String[] fallfallback = suffixes3;
16640
+
16641
+ for (int c=usedsuf; --c>=0;)
1593816642 {
15939
- throw new IOException("Unable to load texture " + resourceName);
16643
+// String[] temp = suffixe;
16644
+// suffixe = fallback;
16645
+// fallback = fallfallback;
16646
+// fallfallback = temp;
1594016647 }
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
+
1594116676 //System.out.println("Target = " + targets[i]);
1594216677 cubemap.updateImage(data, targets[i]);
1594316678 }
1594416679
1594516680 return cubemap;
1594616681 }
16682
+
1594716683 int bigsphere = -1;
1594816684
1594916685 float BGcolor = 0.5f;
1595016686
15951
- private void DrawSkyBox(GL gl)
16687
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16688
+
16689
+ private void DrawSkyBox(GL gl, float ratio)
1595216690 {
15953
- if (envyoff || cubemap == null)
16691
+ if (//envyoff ||
16692
+ WIREFRAME ||
16693
+ cubemap == null)
1595416694 {
1595516695 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1595616696 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -15965,7 +16705,17 @@
1596516705 // Compensates for ExaminerViewer's modification of modelview matrix
1596616706 gl.glMatrixMode(GL.GL_MODELVIEW);
1596716707 gl.glLoadIdentity();
16708
+ gl.glScalef(1,ratio,1);
1596816709
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
+
1596916719 //gl.glActiveTexture(GL.GL_TEXTURE1);
1597016720 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1597116721
....@@ -15997,6 +16747,7 @@
1599716747 {
1599816748 gl.glScalef(1.0f, -1.0f, 1.0f);
1599916749 }
16750
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1600016751 gl.glMultMatrixd(viewrot_1, 0);
1600116752 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1600216753 //viewer.updateInverseRotation(gl);
....@@ -16137,16 +16888,16 @@
1613716888 cStatic.objectstack[materialdepth++] = checker;
1613816889 //System.out.println("material " + material);
1613916890 //Applet3D.tracein(this, selected);
16140
- vector2buffer = checker.projectedVertices;
16891
+ //vector2buffer = checker.projectedVertices;
1614116892
1614216893 //checker.GetMaterial().Draw(this, false); // true);
16143
- DrawMaterial(checker.GetMaterial(), false); // true);
16894
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1614416895
1614516896 materialdepth -= 1;
1614616897 if (materialdepth > 0)
1614716898 {
16148
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16149
- 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);
1615016901 }
1615116902 //checker.GetMaterial().opacity = 1f;
1615216903 ////checker.GetMaterial().ambient = 1f;
....@@ -16232,6 +16983,14 @@
1623216983 }
1623316984 }
1623416985
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
+
1623516994 class SelectBuffer implements GLEventListener
1623616995 {
1623716996
....@@ -16247,7 +17006,7 @@
1624717006 //new Exception().printStackTrace();
1624817007 System.out.println("select buffer init");
1624917008 // Use debug pipeline
16250
- drawable.setGL(new DebugGL(drawable.getGL()));
17009
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1625117010
1625217011 GL gl = drawable.getGL();
1625317012
....@@ -16311,6 +17070,17 @@
1631117070
1631217071 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1631317072
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
+
1631417084 //int tmp = selection_view;
1631517085 //selection_view = -1;
1631617086 int temp = DrawMode();
....@@ -16322,6 +17092,17 @@
1632217092 // temp = DEFAULT; // patch for selection debug
1632317093 Globals.drawMode = temp; // WARNING
1632417094
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
+
1632517106 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1632617107
1632717108 // trying different ways of getting the depth info over
....@@ -16369,6 +17150,8 @@
1636917150 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1637017151 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1637117152 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
17153
+
17154
+ CreateSelectedPoint();
1637217155
1637317156 // Will fit the mesh !!!
1637417157 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16418,34 +17201,36 @@
1641817201 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]));
1641917202 }
1642017203
16421
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
17204
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1642217205 }
1642317206 }
1642417207
1642517208 if (!movingcamera && !PAINTMODE)
16426
- object.editWindow.ScreenFitPoint(); // fev 2014
17209
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1642717210
16428
- 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)
1642917212 {
16430
- 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);
1643117214
16432
- Object3D group = new Object3D("inst" + paintcount++);
17215
+ if (object.GetWindow().copy.selection.Size() > 0)
17216
+ {
17217
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1643317218
16434
- group.CreateMaterial(); // use a void leaf to select instances
16435
-
16436
- group.add(paintobj); // link
16437
-
16438
- object.editWindow.SnapObject(group);
16439
-
16440
- Object3D folder = object.editWindow.copy;
16441
-
16442
- if (object.editWindow.copy.selection.Size() > 0)
16443
- folder = object.editWindow.copy.selection.elementAt(0);
16444
-
16445
- folder.add(group);
16446
-
16447
- object.editWindow.ResetModel();
16448
- 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
+ }
1644917234 }
1645017235 else
1645117236 paintcount = 0;
....@@ -16484,6 +17269,11 @@
1648417269 //System.out.println("objects[color] = " + objects[color]);
1648517270 //objects[color].Select();
1648617271 indexcount = 0;
17272
+ ObjEditor window = object.GetWindow();
17273
+ if (window != null && deselect)
17274
+ {
17275
+ window.Select(null, deselect, true);
17276
+ }
1648717277 object.Select(color, deselect);
1648817278 }
1648917279
....@@ -16583,7 +17373,7 @@
1658317373 gl.glDisable(gl.GL_CULL_FACE);
1658417374 }
1658517375
16586
- if (!RENDERSHADOW)
17376
+ if (!Globals.RENDERSHADOW)
1658717377 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1658817378
1658917379 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -16593,7 +17383,7 @@
1659317383 //gl.glColorMask(false, false, false, false);
1659417384
1659517385 //render_scene_from_light_view(gl, drawable, 0, 0);
16596
- if (RENDERSHADOW && Globals.lighttouched && !movingcamera) // && !parent.IsFreezed())
17386
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1659717387 {
1659817388 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1659917389
....@@ -16762,10 +17552,14 @@
1676217552 gl.glFlush();
1676317553
1676417554 /**/
16765
- 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);
1676617556
16767
- float[] pixels = occlusionsizebuffer.array();
17557
+ float[] depths = occlusiondepthbuffer.array();
1676817558
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
+
1676917563 double r = 0, g = 0, b = 0;
1677017564
1677117565 double count = 0;
....@@ -16776,7 +17570,7 @@
1677617570
1677717571 double FACTOR = 1;
1677817572
16779
- for (int i = 0; i < pixels.length; i++)
17573
+ for (int i = 0; i < depths.length; i++)
1678017574 {
1678117575 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1678217576 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -16859,7 +17653,7 @@
1685917653
1686017654 double scale = ray.z; // 1; // cos
1686117655
16862
- float depth = pixels[newindex];
17656
+ float depth = depths[newindex];
1686317657
1686417658 /*
1686517659 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -17009,23 +17803,15 @@
1700917803 int AAbuffersize = 0;
1701017804
1701117805 //double[] selectedpoint = new double[3];
17012
- static Superellipsoid selectedpoint = new Superellipsoid();
17806
+ static Superellipsoid selectedpoint;
1701317807 static Sphere previousselectedpoint = null;
17014
- static Sphere debugpointG = new Sphere();
17015
- static Sphere debugpointP = new Sphere();
17016
- static Sphere debugpointC = new Sphere();
17017
- static Sphere debugpointR = new Sphere();
17808
+ static Sphere debugpointG;
17809
+ static Sphere debugpointP;
17810
+ static Sphere debugpointC;
17811
+ static Sphere debugpointR;
1701817812
1701917813 static Sphere debugpoints[] = new Sphere[8];
1702017814
17021
- static
17022
- {
17023
- for (int i=0; i<8; i++)
17024
- {
17025
- debugpoints[i] = new Sphere();
17026
- }
17027
- }
17028
-
1702917815 static void InitPoints(float radius)
1703017816 {
1703117817 for (int i=0; i<8; i++)
....@@ -17064,11 +17850,14 @@
1706417850 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1706517851 static IntBuffer bigAAbuffer;
1706617852 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
17067
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17853
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1706817854 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1706917855 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1707017856 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17071
- 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
+
1707217861 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1707317862 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1707417863 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();