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,47 +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
8351
+ if (texname.equals("") && texdata == null)
8352
+ {
8353
+ return null;
8354
+ }
8355
+
8356
+ String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
8357
+
80788358 // String[] split = tex.split("Textures");
80798359 // if (split.length > 1)
80808360 // texname = "/Users/nbriere/Textures" + split[split.length-1];
80818361 // else
80828362 // if (!texname.startsWith("/"))
80838363 // texname = "/Users/nbriere/Textures/" + texname;
8084
- if (!new File(tex).exists())
8364
+ if (!FileExists(texname) && !texname.startsWith("@"))
80858365 {
8086
- texname = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory() + "/Textures/" + texname;
8366
+ texname = fallbackTextureName;
80878367 }
80888368
80898369 if (CACHETEXTURE)
8090
- texture = textures.get(texname); // TEXTURE CACHE
8091
-
8092
- TextureData texturedata = null;
8093
-
8094
- if (texture == null || texture.resolution < resolution)
80958370 {
8096
- 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(""))
80978404 {
80988405 assert(!bump);
80998406 // if (bump)
....@@ -8104,19 +8411,23 @@
81048411 // }
81058412 // else
81068413 // {
8107
- texture = textures.get(tex);
8108
- if (texture == null)
8414
+ // texturecache = textures.get(texname); // suspicious
8415
+ if (texturecache == null)
81098416 {
8110
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8417
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
81118418 }
8419
+ else
8420
+ new Exception().printStackTrace();
81128421 // }
81138422 } else
8114
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8423
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
81158424 {
81168425 assert(bump);
8117
- texture = textures.get(tex);
8118
- if (texture == null)
8119
- 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();
81208431 } else
81218432 {
81228433 //if (tex.equals("IMMORTAL"))
....@@ -8124,11 +8435,22 @@
81248435 // texture = GetResourceTexture("default.png");
81258436 //} else
81268437 //{
8127
- if (tex.equals("WHITE_NOISE"))
8438
+ if (texname.endsWith("WHITE_NOISE"))
81288439 {
8129
- texture = textures.get(tex);
8130
- if (texture == null)
8131
- 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();
81328454 } else
81338455 {
81348456 if (textureon)
....@@ -8153,7 +8475,7 @@
81538475 }
81548476
81558477 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
8156
- if (!new File(cachename).exists())
8478
+ if (!FileExists(cachename))
81578479 cachename = texname;
81588480 else
81598481 processbump = false; // don't process bump map again
....@@ -8175,7 +8497,7 @@
81758497 }
81768498
81778499 cachename = texname.substring(0, texname.length()-4)+ext+".png";
8178
- if (!new File(cachename).exists())
8500
+ if (!FileExists(cachename))
81798501 cachename = texname;
81808502 else
81818503 processbump = false; // don't process bump map again
....@@ -8184,20 +8506,23 @@
81848506 texturedata = GetFileTexture(cachename, processbump, resolution);
81858507
81868508
8187
- if (texturedata != null)
8188
- 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);
81898513 //texture = GetTexture(tex, bump);
81908514 }
8515
+ }
81918516 }
81928517 //}
81938518 }
81948519
8195
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8520
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
81968521 {
81978522 //return false;
81988523
81998524 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8200
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8525
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
82018526 {
82028527 // String ext = "_highres";
82038528 // if (REDUCETEXTURE)
....@@ -8214,52 +8539,17 @@
82148539 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
82158540 if (!cachefile.exists())
82168541 {
8217
- // cache to disk
8218
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
8219
- //buffers[0].
8220
-
8221
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
8222
- int[] pixels = new int[bytebuf.capacity()/3];
8223
-
8224
- // squared size heuristic...
8225
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8542
+ //if (texturedata.getWidth() == texturedata.getHeight())
82268543 {
8227
- for (int i=pixels.length; --i>=0;)
8228
- {
8229
- int i3 = i*3;
8230
- pixels[i] = 0xFF;
8231
- pixels[i] <<= 8;
8232
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
8233
- pixels[i] <<= 8;
8234
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
8235
- pixels[i] <<= 8;
8236
- pixels[i] |= bytebuf.get(i3) & 0xFF;
8237
- }
8238
-
8239
- /*
8240
- int r=0,g=0,b=0,a=0;
8241
- for (int i=0; i<width; i++)
8242
- for (int j=0; j<height; j++)
8243
- {
8244
- int index = j*width+i;
8245
- int p = pixels[index];
8246
- a = ((p>>24) & 0xFF);
8247
- r = ((p>>16) & 0xFF);
8248
- g = ((p>>8) & 0xFF);
8249
- b = (p & 0xFF);
8250
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
8251
- }
8252
- /**/
8253
- int width = (int)Math.sqrt(pixels.length); // squared
8254
- int height = width;
8255
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
8256
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8544
+ BufferedImage rendImage = CreateBim(texturedata);
8545
+
82578546 ImageWriter writer = null;
82588547 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
82598548 if (iter.hasNext()) {
82608549 writer = (ImageWriter)iter.next();
82618550 }
8262
- float compressionQuality = 0.9f;
8551
+
8552
+ float compressionQuality = 0.85f;
82638553 try
82648554 {
82658555 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8276,18 +8566,20 @@
82768566 }
82778567 }
82788568 }
8279
-
8569
+
8570
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8571
+
82808572 //System.out.println("Texture = " + tex);
8281
- if (textures.containsKey(texname))
8573
+ if (textures.containsKey(tex))
82828574 {
8283
- CacheTexture thetex = textures.get(texname);
8575
+ CacheTexture thetex = textures.get(tex);
82848576 thetex.texture.disable();
82858577 thetex.texture.dispose();
8286
- textures.remove(texname);
8578
+ textures.remove(tex);
82878579 }
82888580
8289
- texture.texturedata = texturedata;
8290
- textures.put(texname, texture);
8581
+ //texture.texturedata = texturedata;
8582
+ textures.put(tex, texturecache);
82918583
82928584 // newtex = true;
82938585 }
....@@ -8303,10 +8595,44 @@
83038595 }
83048596 }
83058597
8306
- return texture;
8598
+ return texturecache;
83078599 }
83088600
8309
- 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
83108636 {
83118637 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
83128638
....@@ -8324,21 +8650,21 @@
83248650 return texture!=null?texture.texture:null;
83258651 }
83268652
8327
- 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
83288654 {
83298655 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
83308656
83318657 return texture!=null?texture.texturedata:null;
83328658 }
83338659
8334
- boolean BindTexture(String tex, boolean bump, int resolution)
8660
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
83358661 {
83368662 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
83378663 {
83388664 return false;
83398665 }
83408666
8341
- boolean newtex = false;
8667
+ //boolean newtex = false;
83428668
83438669 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
83448670
....@@ -8370,9 +8696,75 @@
83708696 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
83718697 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
83728698
8373
- return newtex;
8699
+ return true; // Warning: not used.
83748700 }
83758701
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
+
83768768 ShadowBuffer shadowPBuf;
83778769 AntialiasBuffer antialiasPBuf;
83788770 int MAXSTACK;
....@@ -8389,10 +8781,12 @@
83898781
83908782 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
83918783 MAXSTACK = temp[0];
8392
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8784
+ if (Globals.DEBUG)
8785
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
83938786 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
83948787 MAXSTACK = temp[0];
8395
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8788
+ if (Globals.DEBUG)
8789
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
83968790
83978791 // Use debug pipeline
83988792 //drawable.setGL(new DebugGL(gl)); //
....@@ -8400,7 +8794,8 @@
84008794 gl = drawable.getGL(); //
84018795
84028796 GL gl3 = getGL();
8403
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8797
+ if (Globals.DEBUG)
8798
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
84048799
84058800
84068801 //float pos[] = { 100, 100, 100, 0 };
....@@ -8565,7 +8960,7 @@
85658960
85668961 if (cubemap == null)
85678962 {
8568
- LoadEnvy(5);
8963
+ //LoadEnvy(1);
85698964 }
85708965
85718966 //cubemap.enable();
....@@ -8841,6 +9236,8 @@
88419236
88429237 void LoadEnvy(int which)
88439238 {
9239
+ assert(false);
9240
+
88449241 String name;
88459242 String ext;
88469243
....@@ -8852,37 +9249,58 @@
88529249 cubemap = null;
88539250 return;
88549251 case 1:
8855
- name = "cubemaps/box_";
8856
- ext = "png";
9252
+ name = "cubemaps/rgb/";
9253
+ ext = "jpg";
88579254 reverseUP = false;
88589255 break;
88599256 case 2:
8860
- name = "cubemaps/uffizi_";
8861
- ext = "png";
8862
- break; // reverseUP = true; break;
9257
+ name = "cubemaps/uffizi/";
9258
+ ext = "jpg";
9259
+ reverseUP = false;
9260
+ break;
88639261 case 3:
8864
- name = "cubemaps/CloudyHills_";
8865
- ext = "tga";
9262
+ name = "cubemaps/CloudyHills/";
9263
+ ext = "jpg";
88669264 reverseUP = false;
88679265 break;
88689266 case 4:
8869
- name = "cubemaps/cornell_";
9267
+ name = "cubemaps/cornell/";
88709268 ext = "png";
88719269 reverseUP = false;
88729270 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;
88739296 default:
8874
- name = "cubemaps/rgb_";
8875
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9297
+ name = "cubemaps/box/";
9298
+ ext = "png"; /*mipmap = true;*/
9299
+ reverseUP = false;
88769300 break;
88779301 }
8878
-
8879
- try
8880
- {
8881
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
8882
- } catch (IOException e)
8883
- {
8884
- throw new RuntimeException(e);
8885
- }
9302
+
9303
+ LoadSkybox(name, ext, mipmap);
88869304 }
88879305
88889306 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -8914,8 +9332,12 @@
89149332 static double[] model = new double[16];
89159333 double[] camera2light = new double[16];
89169334 double[] light2camera = new double[16];
8917
- int newenvy = -1;
8918
- boolean envyoff = true; // false;
9335
+
9336
+ //int newenvy = -1;
9337
+ //boolean envyoff = false;
9338
+
9339
+ String loadedskyboxname;
9340
+
89199341 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
89209342 //float[] light0 = { 0,0,0 };
89219343 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9208,11 +9630,35 @@
92089630 jy8[3] = 0.5f;
92099631 }
92109632
9211
- 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
92129634 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
92139635 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
92149636 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
92159637
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
+
92169662 static int imagecount = 0; // movie generation
92179663
92189664 static int jitter = 0;
....@@ -9308,8 +9754,8 @@
93089754 assert (parentcam != renderCamera);
93099755
93109756 if (renderCamera != lightCamera)
9311
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9312
- LA.matConcat(matrix, parentcam.toParent, matrix);
9757
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9758
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
93139759
93149760 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
93159761
....@@ -9324,8 +9770,8 @@
93249770 LA.matCopy(renderCamera.fromScreen, matrix);
93259771
93269772 if (renderCamera != lightCamera)
9327
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9328
- LA.matConcat(parentcam.fromParent, matrix, matrix);
9773
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9774
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
93299775
93309776 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
93319777
....@@ -9371,10 +9817,12 @@
93719817 rati = 1 / rati;
93729818 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
93739819 }
9374
- assert (newenvy == -1);
9820
+
9821
+ //assert (newenvy == -1);
9822
+
93759823 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
93769824 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9377
- DrawSkyBox(gl);
9825
+ DrawSkyBox(gl, (float)rati);
93789826 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
93799827 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
93809828 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -9542,7 +9990,7 @@
95429990
95439991 if (!BOXMODE)
95449992 {
9545
- 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) + ")");
95469994 }
95479995
95489996 if (!BOXMODE)
....@@ -9580,7 +10028,7 @@
958010028 ABORTED = false;
958110029 }
958210030 else
9583
- GrafreeD.wav.cursor += 735 * ACSIZE;
10031
+ Grafreed.wav.cursor += 735 * ACSIZE;
958410032
958510033 if (false)
958610034 {
....@@ -10243,11 +10691,11 @@
1024310691
1024410692 public void display(GLAutoDrawable drawable)
1024510693 {
10246
- if (GrafreeD.savesound && GrafreeD.hassound)
10694
+ if (Grafreed.savesound && Grafreed.hassound)
1024710695 {
10248
- GrafreeD.wav.save();
10249
- GrafreeD.savesound = false;
10250
- GrafreeD.hassound = false;
10696
+ Grafreed.wav.save();
10697
+ Grafreed.savesound = false;
10698
+ Grafreed.hassound = false;
1025110699 }
1025210700 // if (DEBUG_SELECTION)
1025310701 // {
....@@ -10323,6 +10771,7 @@
1032310771 ANTIALIAS = 0;
1032410772 //System.out.println("RESTART");
1032510773 AAtimer.restart();
10774
+ Globals.TIMERRUNNING = true;
1032610775 }
1032710776 }
1032810777 }
....@@ -10377,7 +10826,7 @@
1037710826 Object3D theobject = object;
1037810827 Object3D theparent = object.parent;
1037910828 object.parent = null;
10380
- object = (Object3D)GrafreeD.clone(object);
10829
+ object = (Object3D)Grafreed.clone(object);
1038110830 object.Stripify();
1038210831 if (theobject.selection == null || theobject.selection.Size() == 0)
1038310832 theobject.PreprocessOcclusion(this);
....@@ -10390,13 +10839,14 @@
1039010839 ambientOcclusion = false;
1039110840 }
1039210841
10393
- if (Globals.lighttouched && DrawMode() == DEFAULT && !lightMode) // && !FROZEN)
10842
+ if (//Globals.lighttouched &&
10843
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1039410844 {
1039510845 //if (RENDERSHADOW) // ?
1039610846 if (!IsFrozen())
1039710847 {
1039810848 // dec 2012
10399
- if (!ambientOcclusion && !(!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0))
10849
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
1040010850 {
1040110851 Globals.framecount++;
1040210852 shadowbuffer.display();
....@@ -10409,7 +10859,7 @@
1040910859
1041010860 if (wait)
1041110861 {
10412
- Sleep(500);
10862
+ Sleep(200); // blocks everything
1041310863
1041410864 wait = false;
1041510865 }
....@@ -10523,8 +10973,8 @@
1052310973
1052410974 // if (parentcam != renderCamera) // not a light
1052510975 if (cam != lightCamera)
10526
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10527
- LA.matConcat(matrix, parentcam.toParent, matrix);
10976
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10977
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1052810978
1052910979 for (int j = 0; j < 4; j++)
1053010980 {
....@@ -10538,8 +10988,8 @@
1053810988
1053910989 // if (parentcam != renderCamera) // not a light
1054010990 if (cam != lightCamera)
10541
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10542
- LA.matConcat(parentcam.fromParent, matrix, matrix);
10991
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10992
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1054310993
1054410994 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1054510995
....@@ -10625,13 +11075,41 @@
1062511075 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1062611076 }
1062711077
10628
- 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"))
1062911086 {
10630
- LoadEnvy(newenvy);
11087
+ if (cubemaprgb == null)
11088
+ {
11089
+ cubemaprgb = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11090
+ }
11091
+
11092
+ cubemap = cubemaprgb;
1063111093 }
10632
-
10633
- newenvy = -1;
10634
-
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
+
1063511113 ratio = ((double) getWidth()) / getHeight();
1063611114 //System.out.println("ratio = " + ratio);
1063711115
....@@ -10647,7 +11125,7 @@
1064711125
1064811126 if (!IsFrozen() && !ambientOcclusion)
1064911127 {
10650
- DrawSkyBox(gl);
11128
+ DrawSkyBox(gl, (float)ratio);
1065111129 }
1065211130
1065311131 //if (selection_view == -1)
....@@ -10798,7 +11276,16 @@
1079811276 // Bump noise
1079911277 gl.glActiveTexture(GL.GL_TEXTURE6);
1080011278 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
10801
- 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
+
1080211289
1080311290 gl.glActiveTexture(GL.GL_TEXTURE0);
1080411291 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -10821,9 +11308,9 @@
1082111308
1082211309 gl.glMatrixMode(GL.GL_MODELVIEW);
1082311310
10824
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10825
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10826
-//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);
1082711314 } else
1082811315 {
1082911316 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -10834,7 +11321,7 @@
1083411321 //System.out.println("BLENDING ON");
1083511322 gl.glEnable(GL.GL_BLEND);
1083611323 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
10837
-
11324
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1083811325 gl.glMatrixMode(gl.GL_PROJECTION);
1083911326 gl.glLoadIdentity();
1084011327
....@@ -10923,8 +11410,8 @@
1092311410 System.err.println("parentcam != renderCamera");
1092411411
1092511412 // if (cam != lightCamera)
10926
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10927
- 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
1092811415 }
1092911416
1093011417 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -10945,8 +11432,8 @@
1094511432 if (true) // TODO
1094611433 {
1094711434 if (cam != lightCamera)
10948
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10949
- 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
1095011437 }
1095111438
1095211439 LA.xformPos(light0, cam.toScreen, light0);
....@@ -11083,7 +11570,7 @@
1108311570 }
1108411571 }
1108511572
11086
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11573
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1108711574 {
1108811575 //gl.glDepthFunc(GL.GL_LEQUAL);
1108911576 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11091,24 +11578,21 @@
1109111578
1109211579 boolean texon = textureon;
1109311580
11094
- if (RENDERPROGRAM > 0)
11095
- {
11096
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11097
- textureon = false;
11098
- }
11581
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11582
+ textureon = false;
11583
+
1109911584 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1110011585 //System.out.println("ALLO");
1110111586 gl.glColorMask(false, false, false, false);
1110211587 DrawObject(gl);
11103
- if (RENDERPROGRAM > 0)
11104
- {
11105
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11106
- textureon = texon;
11107
- }
11588
+
11589
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11590
+ textureon = texon;
11591
+
1110811592 gl.glColorMask(true, true, true, true);
1110911593
1111011594 gl.glDepthFunc(GL.GL_EQUAL);
11111
- //gl.glDepthMask(false);
11595
+ gl.glDepthMask(false);
1111211596 }
1111311597
1111411598 if (false) // DrawMode() == SHADOW)
....@@ -11283,23 +11767,44 @@
1128311767 e.printStackTrace();
1128411768 }
1128511769
11286
- if (GrafreeD.RENDERME > 0)
11287
- GrafreeD.RENDERME--; // mechante magouille
11770
+ if (Grafreed.RENDERME > 0)
11771
+ Grafreed.RENDERME--; // mechante magouille
1128811772
1128911773 Globals.ONESTEP = false;
1129011774 }
1129111775
1129211776 static boolean zoomonce = false;
1129311777
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
+
1129411796 void DrawObject(GL gl, boolean draw)
1129511797 {
11798
+ // To clear camera values
11799
+ ResetOptions();
11800
+
1129611801 //System.out.println("DRAW OBJECT " + mouseDown);
1129711802 // DrawMode() = SELECTION;
1129811803 //GL gl = getGL();
1129911804 if ((TRACK || SHADOWTRACK) || zoomonce)
1130011805 {
1130111806 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11302
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11807
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1130311808 pingthread.StepToTarget(true); // true);
1130411809 // zoomonce = false;
1130511810 }
....@@ -11354,7 +11859,14 @@
1135411859
1135511860 usedtextures.clear();
1135611861
11357
- 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
+ }
1135811870 }
1135911871 //System.out.println("--> " + stackdepth);
1136011872 // GrafreeD.traceon();
....@@ -11364,8 +11876,9 @@
1136411876
1136511877 if (DrawMode() == DEFAULT)
1136611878 {
11367
- if (DEBUG)
11879
+ if (Globals.DEBUG)
1136811880 {
11881
+ CreateSelectedPoint();
1136911882 float radius = 0.05f;
1137011883 if (selectedpoint.radius != radius)
1137111884 {
....@@ -11419,20 +11932,32 @@
1141911932 ReleaseTextures(DEFAULT_TEXTURES);
1142011933
1142111934 if (CLEANCACHE)
11422
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11935
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1142311936 {
11424
- String tex = e.nextElement();
11937
+ cTexture tex = e.nextElement();
1142511938
1142611939 // System.out.println("Texture --------- " + tex);
1142711940
11428
- if (tex.equals("WHITE_NOISE"))
11941
+ if (tex.equals("WHITE_NOISE:"))
1142911942 continue;
1143011943
11431
- if (!usedtextures.containsKey(tex))
11944
+ if (!usedtextures.contains(tex))
1143211945 {
11946
+ CacheTexture gettex = texturepigment.get(tex);
1143311947 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11434
- textures.get(tex).texture.dispose();
11435
- 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
+ }
1143611961 }
1143711962 }
1143811963 }
....@@ -11445,7 +11970,14 @@
1144511970 if (checker != null && DrawMode() == DEFAULT)
1144611971 {
1144711972 //BindTexture(IMMORTAL_TEXTURE);
11448
- 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
+ }
1144911981 // NEAREST
1145011982 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
1145111983 DrawChecker(gl);
....@@ -11527,7 +12059,7 @@
1152712059 return;
1152812060 }
1152912061
11530
- String string = obj.GetToolTip();
12062
+ String string = obj.toString(); //.GetToolTip();
1153112063
1153212064 GL gl = GetGL();
1153312065
....@@ -11844,8 +12376,8 @@
1184412376 //obj.TransformToWorld(light, light);
1184512377 for (int i = tp.size(); --i >= 0;)
1184612378 {
11847
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
11848
- 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);
1184912381 }
1185012382
1185112383
....@@ -11862,8 +12394,8 @@
1186212394 parentcam = cameras[0];
1186312395 }
1186412396
11865
- for (int count = parentcam.GetTransformCount(); --count>=0;)
11866
- 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
1186712399
1186812400 LA.xformPos(light, renderCamera.toScreen, light);
1186912401
....@@ -11953,8 +12485,76 @@
1195312485
1195412486 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1195512487
11956
- String program =
12488
+ String programmin =
12489
+ // Min shader
1195712490 "!!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
+
1195812558 //"OPTION ARB_fragment_program_shadow;" +
1195912559 "PARAM light2cam0 = program.env[10];" +
1196012560 "PARAM light2cam1 = program.env[11];" +
....@@ -12069,8 +12669,7 @@
1206912669 "TEMP shininess;" +
1207012670 "\n" +
1207112671 "MOV texSamp, one;" +
12072
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12073
-
12672
+
1207412673 "MOV mapgrid.x, one2048th.x;" +
1207512674 "MOV temp, fragment.texcoord[1];" +
1207612675 /*
....@@ -12091,20 +12690,20 @@
1209112690 "MUL temp, floor, mapgrid.x;" +
1209212691 //"TEX depth0, temp, texture[1], 2D;" +
1209312692 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12094
- TextureFetch("depth0", "temp", "1") +
12693
+ ShadowTextureFetch("depth0", "temp", "1") +
1209512694 "") +
1209612695 "ADD temp.x, temp.x, mapgrid.x;" +
1209712696 //"TEX depth1, temp, texture[1], 2D;" +
1209812697 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12099
- TextureFetch("depth1", "temp", "1") +
12698
+ ShadowTextureFetch("depth1", "temp", "1") +
1210012699 "") +
1210112700 "ADD temp.y, temp.y, mapgrid.x;" +
1210212701 //"TEX depth2, temp, texture[1], 2D;" +
12103
- TextureFetch("depth2", "temp", "1") +
12702
+ ShadowTextureFetch("depth2", "temp", "1") +
1210412703 "SUB temp.x, temp.x, mapgrid.x;" +
1210512704 //"TEX depth3, temp, texture[1], 2D;" +
1210612705 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12107
- TextureFetch("depth3", "temp", "1") +
12706
+ ShadowTextureFetch("depth3", "temp", "1") +
1210812707 "") +
1210912708 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1211012709 //"MOV params, material;" +
....@@ -12475,10 +13074,10 @@
1247513074 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1247613075 "") +
1247713076
12478
- // display shadow only (bump == 0)
13077
+ // display shadow only (fakedepth == 0)
1247913078 "SUB temp.x, half.x, shadow.x;" +
12480
- "MOV temp.y, -params6.x;" +
12481
- "SLT temp.z, temp.y, zero.x;" +
13079
+ "MOV temp.y, -params5.z;" + // params6.x;" +
13080
+ "SLT temp.z, temp.y, -c256i.x;" +
1248213081 "SUB temp.y, one.x, temp.z;" +
1248313082 "MUL temp.x, temp.x, temp.y;" +
1248413083 "KIL temp.x;" +
....@@ -12809,7 +13408,14 @@
1280913408 //once = true;
1281013409 }
1281113410
12812
- 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());
1281313419 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1281413420 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1281513421
....@@ -12902,25 +13508,26 @@
1290213508 return out;
1290313509 }
1290413510
12905
- String TextureFetch(String dest, String src, String unit)
13511
+ // Also does frustum culling
13512
+ String ShadowTextureFetch(String dest, String src, String unit)
1290613513 {
1290713514 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1290813515 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1290913516 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13517
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13518
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1291013519 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12911
- "SLT " + src + ".z, " + src + ".x, one.x;" +
12912
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12913
- "SLT " + src + ".z, " + src + ".y, one.x;" +
12914
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13520
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13521
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1291513522 //"SWZ buffer, temp, w,w,w,w;";
12916
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13523
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1291713524 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1291813525 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1291913526 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
12920
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13527
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1292113528
12922
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
12923
- //"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;";
1292413531 }
1292513532
1292613533 String Shadow(String depth, String shadow)
....@@ -12942,12 +13549,16 @@
1294213549
1294313550 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1294413551 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13552
+
13553
+ // Compare fragment depth in light space with shadowmap.
1294513554 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1294613555 "SGE temp.y, temp.x, zero.x;" +
12947
- "SUB " + shadow + ".y, one.x, temp.y;" +
13556
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13557
+
13558
+ // Reverse comparison
1294813559 "SUB temp.x, one.x, temp.x;" +
1294913560 "MUL " + shadow + ".x, temp.x, temp.y;" +
12950
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13561
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1295113562 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1295213563
1295313564 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -12961,6 +13572,10 @@
1296113572 // No shadow for backface
1296213573 "DP3 temp.x, normal, lightd;" +
1296313574 "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;" +
1296413579 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1296513580 "";
1296613581 }
....@@ -13107,7 +13722,8 @@
1310713722 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1310813723 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1310913724 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13110
- Object3D.cVector2[] vector2buffer;
13725
+
13726
+ //Object3D.cVector2[] vector2buffer;
1311113727
1311213728 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1311313729 // OUT : diff, spec
....@@ -13123,9 +13739,10 @@
1312313739 "DP3 " + dest + ".z," + "normals," + "eye;" +
1312413740 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1312513741 //"MOV " + dest + ".w," + "normal.z;" +
13126
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
13127
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13128
- //"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
1312913746 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1313013747 "RCP " + dest + ".w," + dest + ".w;" +
1313113748 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13630,6 +14247,7 @@
1363014247 else
1363114248 if (evt.getSource() == AAtimer)
1363214249 {
14250
+ Globals.TIMERRUNNING = false;
1363314251 if (mouseDown)
1363414252 {
1363514253 //new Exception().printStackTrace();
....@@ -13689,7 +14307,7 @@
1368914307
1369014308 // fev 2014???
1369114309 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13692
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14310
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1369314311 pingthread.StepToTarget(true); // true);
1369414312 }
1369514313 // if (!LIVE)
....@@ -13704,6 +14322,7 @@
1370414322 return;
1370514323
1370614324 AAtimer.restart(); //
14325
+ Globals.TIMERRUNNING = true;
1370714326
1370814327 // waslive = LIVE;
1370914328 // LIVE = false;
....@@ -13753,14 +14372,15 @@
1375314372 drag = false;
1375414373 //System.out.println("Mouse DOWN");
1375514374 editObj = false;
13756
- ClickInfo info = new ClickInfo();
13757
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
13758
- info.pane = this;
13759
- info.camera = renderCamera;
13760
- info.x = x;
13761
- info.y = y;
13762
- info.modifiers = modifiersex;
13763
- 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);
1376414384 if (!editObj)
1376514385 {
1376614386 hasMarquee = true;
....@@ -13776,9 +14396,12 @@
1377614396
1377714397 public void mouseDragged(MouseEvent e)
1377814398 {
14399
+ Globals.MOUSEDRAGGED = true;
14400
+
1377914401 //System.out.println("mouseDragged: " + e);
1378014402 if (isRenderer)
1378114403 movingcamera = true;
14404
+
1378214405 //if (drawing)
1378314406 //return;
1378414407 if ((e.getModifiersEx() & CTRL) != 0
....@@ -14039,12 +14662,12 @@
1403914662 void GoDown(int mod)
1404014663 {
1404114664 MODIFIERS |= COMMAND;
14042
- /*
14665
+ /**/
1404314666 if((mod&SHIFT) == SHIFT)
14044
- manipCamera.RotatePosition(0, -speed);
14667
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
1404514668 else
14046
- manipCamera.BackForth(0, -speed*delta, getWidth());
14047
- */
14669
+ manipCamera.RotatePosition(0, -speed);
14670
+ /**/
1404814671 if ((mod & SHIFT) == SHIFT)
1404914672 {
1405014673 mouseMode = mouseMode; // VR??
....@@ -14060,12 +14683,12 @@
1406014683 void GoUp(int mod)
1406114684 {
1406214685 MODIFIERS |= COMMAND;
14063
- /*
14686
+ /**/
1406414687 if((mod&SHIFT) == SHIFT)
14065
- manipCamera.RotatePosition(0, speed);
14688
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
1406614689 else
14067
- manipCamera.BackForth(0, speed*delta, getWidth());
14068
- */
14690
+ manipCamera.RotatePosition(0, speed);
14691
+ /**/
1406914692 if ((mod & SHIFT) == SHIFT)
1407014693 {
1407114694 mouseMode = mouseMode;
....@@ -14081,12 +14704,12 @@
1408114704 void GoLeft(int mod)
1408214705 {
1408314706 MODIFIERS |= COMMAND;
14084
- /*
14707
+ /**/
1408514708 if((mod&SHIFT) == SHIFT)
14086
- manipCamera.RotatePosition(speed, 0);
14087
- else
1408814709 manipCamera.Translate(speed*delta, 0, getWidth());
14089
- */
14710
+ else
14711
+ manipCamera.RotatePosition(speed, 0);
14712
+ /**/
1409014713 if ((mod & SHIFT) == SHIFT)
1409114714 {
1409214715 mouseMode = mouseMode;
....@@ -14102,12 +14725,12 @@
1410214725 void GoRight(int mod)
1410314726 {
1410414727 MODIFIERS |= COMMAND;
14105
- /*
14728
+ /**/
1410614729 if((mod&SHIFT) == SHIFT)
14107
- manipCamera.RotatePosition(-speed, 0);
14108
- else
1410914730 manipCamera.Translate(-speed*delta, 0, getWidth());
14110
- */
14731
+ else
14732
+ manipCamera.RotatePosition(-speed, 0);
14733
+ /**/
1411114734 if ((mod & SHIFT) == SHIFT)
1411214735 {
1411314736 mouseMode = mouseMode;
....@@ -14157,14 +14780,16 @@
1415714780 if (editObj)
1415814781 {
1415914782 drag = true;
14160
- ClickInfo info = new ClickInfo();
14161
- info.bounds.setBounds(0, 0,
14783
+ //ClickInfo info = new ClickInfo();
14784
+ object.clickInfo.bounds.setBounds(0, 0,
1416214785 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14163
- info.pane = this;
14164
- info.camera = renderCamera;
14165
- info.x = x;
14166
- info.y = y;
14167
- object.editWindow.copy.doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
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);
1416814793 } else
1416914794 {
1417014795 if (x < startX)
....@@ -14313,22 +14938,27 @@
1431314938 }
1431414939 }
1431514940
14941
+// ClickInfo clickInfo = new ClickInfo();
14942
+
1431614943 public void mouseMoved(MouseEvent e)
1431714944 {
1431814945 //System.out.println("mouseMoved: " + e);
1431914946 if (isRenderer)
1432014947 return;
1432114948
14322
- ClickInfo ci = new ClickInfo();
14323
- ci.x = e.getX();
14324
- ci.y = e.getY();
14325
- ci.modifiers = e.getModifiersEx();
14326
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14327
- ci.pane = this;
14328
- 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;
1432914956 if (!isRenderer)
1433014957 {
14331
- if (object.editWindow.copy.doEditClick(ci, 0))
14958
+ //ObjEditor editWindow = object.editWindow;
14959
+ //Object3D copy = editWindow.copy;
14960
+ if (object.doEditClick(//clickInfo,
14961
+ 0))
1433214962 {
1433314963 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1433414964 } else
....@@ -14340,7 +14970,11 @@
1434014970
1434114971 public void mouseReleased(MouseEvent e)
1434214972 {
14973
+ Globals.MOUSEDRAGGED = false;
14974
+
1434314975 movingcamera = false;
14976
+ X = 0; // getBounds().width/2;
14977
+ Y = 0; // getBounds().height/2;
1434414978 //System.out.println("mouseReleased: " + e);
1434514979 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1434614980 }
....@@ -14596,7 +15230,8 @@
1459615230 // break;
1459715231 case 'T':
1459815232 CACHETEXTURE ^= true;
14599
- textures.clear();
15233
+ texturepigment.clear();
15234
+ texturebump.clear();
1460015235 // repaint();
1460115236 break;
1460215237 case 'Y':
....@@ -14681,7 +15316,9 @@
1468115316 case 'E' : COMPACT ^= true;
1468215317 repaint();
1468315318 break;
14684
- case 'W' : DEBUGHSB ^= true;
15319
+ case 'W' : // Wide Window (fullscreen)
15320
+ //DEBUGHSB ^= true;
15321
+ ObjEditor.theFrame.ToggleFullScreen();
1468515322 repaint();
1468615323 break;
1468715324 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14706,8 +15343,8 @@
1470615343 RevertCamera();
1470715344 repaint();
1470815345 break;
14709
- case 'L':
1471015346 case 'l':
15347
+ //case 'L':
1471115348 if (lightMode)
1471215349 {
1471315350 lightMode = false;
....@@ -14771,20 +15408,24 @@
1477115408 OCCLUSION_CULLING ^= true;
1477215409 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1477315410 break;
14774
- case '0': envyoff ^= true; repaint(); break;
15411
+ //case '0': envyoff ^= true; repaint(); break;
1477515412 case '1':
1477615413 case '2':
1477715414 case '3':
1477815415 case '4':
1477915416 case '5':
14780
- newenvy = Character.getNumericValue(key);
14781
- repaint();
14782
- break;
1478315417 case '6':
1478415418 case '7':
1478515419 case '8':
1478615420 case '9':
14787
- 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
+ }
1478815429 repaint();
1478915430 break;
1479015431 case '!':
....@@ -14850,9 +15491,9 @@
1485015491 case '_':
1485115492 kompactbit = 5;
1485215493 break;
14853
- case '+':
14854
- kompactbit = 6;
14855
- break;
15494
+// case '+':
15495
+// kompactbit = 6;
15496
+// break;
1485615497 case ' ':
1485715498 lightMode ^= true;
1485815499 Globals.lighttouched = true;
....@@ -14864,13 +15505,14 @@
1486415505 case ESC:
1486515506 RENDERPROGRAM += 1;
1486615507 RENDERPROGRAM %= 3;
15508
+
1486715509 repaint();
1486815510 break;
1486915511 case 'Z':
1487015512 //RESIZETEXTURE ^= true;
1487115513 //break;
1487215514 case 'z':
14873
- RENDERSHADOW ^= true;
15515
+ Globals.RENDERSHADOW ^= true;
1487415516 Globals.lighttouched = true;
1487515517 repaint();
1487615518 break;
....@@ -14903,8 +15545,9 @@
1490315545 case DELETE:
1490415546 ClearSelection();
1490515547 break;
14906
- /*
1490715548 case '+':
15549
+
15550
+ /*
1490815551 //fontsize += 1;
1490915552 bbzoom *= 2;
1491015553 repaint();
....@@ -14921,17 +15564,17 @@
1492115564 case '=':
1492215565 IncDepth();
1492315566 //fontsize += 1;
14924
- object.editWindow.refreshContents(true);
15567
+ object.GetWindow().refreshContents(true);
1492515568 maskbit = 6;
1492615569 break;
1492715570 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1492815571 DecDepth();
1492915572 maskbit = 5;
1493015573 //if(fontsize > 1) fontsize -= 1;
14931
- if (object.editWindow == null)
14932
- new Exception().printStackTrace();
14933
- else
14934
- object.editWindow.refreshContents(true);
15574
+// if (object.editWindow == null)
15575
+// new Exception().printStackTrace();
15576
+// else
15577
+ object.GetWindow().refreshContents(true);
1493515578 break;
1493615579 case '{':
1493715580 manipCamera.shaper_fovy /= 1.1;
....@@ -15155,7 +15798,7 @@
1515515798 }
1515615799 */
1515715800
15158
- object.editWindow.EditSelection();
15801
+ object.GetWindow().EditSelection(false);
1515915802 }
1516015803
1516115804 void SelectParent()
....@@ -15172,10 +15815,10 @@
1517215815 {
1517315816 //selectees.remove(i);
1517415817 System.out.println("select parent of " + elem);
15175
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15818
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1517615819 } else
1517715820 {
15178
- group.editWindow.Select(elem.GetTreePath(), first, true);
15821
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1517915822 }
1518015823
1518115824 first = false;
....@@ -15217,12 +15860,12 @@
1521715860 for (int j = 0; j < group.children.size(); j++)
1521815861 {
1521915862 elem = (Object3D) group.children.elementAt(j);
15220
- object.editWindow.Select(elem.GetTreePath(), first, true);
15863
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1522115864 first = false;
1522215865 }
1522315866 } else
1522415867 {
15225
- object.editWindow.Select(elem.GetTreePath(), first, true);
15868
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1522615869 }
1522715870
1522815871 first = false;
....@@ -15233,21 +15876,21 @@
1523315876 {
1523415877 //Composite group = (Composite) object;
1523515878 Object3D group = object;
15236
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15879
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1523715880 }
1523815881
1523915882 void ResetTransform(int mask)
1524015883 {
1524115884 //Composite group = (Composite) object;
1524215885 Object3D group = object;
15243
- group.editWindow.ResetTransform(mask);
15886
+ group.GetWindow().ResetTransform(mask);
1524415887 }
1524515888
1524615889 void FlipTransform()
1524715890 {
1524815891 //Composite group = (Composite) object;
1524915892 Object3D group = object;
15250
- group.editWindow.FlipTransform();
15893
+ group.GetWindow().FlipTransform();
1525115894 // group.editWindow.ReduceMesh(true);
1525215895 }
1525315896
....@@ -15255,7 +15898,7 @@
1525515898 {
1525615899 //Composite group = (Composite) object;
1525715900 Object3D group = object;
15258
- group.editWindow.PrintMemory();
15901
+ group.GetWindow().PrintMemory();
1525915902 // group.editWindow.ReduceMesh(true);
1526015903 }
1526115904
....@@ -15263,7 +15906,7 @@
1526315906 {
1526415907 //Composite group = (Composite) object;
1526515908 Object3D group = object;
15266
- group.editWindow.ResetCentroid();
15909
+ group.GetWindow().ResetCentroid();
1526715910 }
1526815911
1526915912 void IncDepth()
....@@ -15345,11 +15988,11 @@
1534515988
1534615989 int width = getBounds().width;
1534715990 int height = getBounds().height;
15348
- ClickInfo info = new ClickInfo();
15349
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1535015991 //Image img = CreateImage(width, height);
1535115992 //System.out.println("width = " + width + "; height = " + height + "\n");
15993
+
1535215994 Graphics gr = g; // img.getGraphics();
15995
+
1535315996 if (!hasMarquee)
1535415997 {
1535515998 if (Xmin < Xmax) // !locked)
....@@ -15421,40 +16064,88 @@
1542116064 }
1542216065 if (object != null && !hasMarquee)
1542316066 {
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
+
1542416073 if (isRenderer)
1542516074 {
15426
- info.flags++;
16075
+ object.clickInfo.flags++;
1542716076 double frameAspect = (double) width / (double) height;
1542816077 if (frameAspect > renderCamera.aspect)
1542916078 {
1543016079 int desired = (int) ((double) height * renderCamera.aspect);
15431
- info.bounds.width -= width - desired;
15432
- info.bounds.x += (width - desired) / 2;
16080
+ object.clickInfo.bounds.width -= width - desired;
16081
+ object.clickInfo.bounds.x += (width - desired) / 2;
1543316082 } else
1543416083 {
1543516084 int desired = (int) ((double) width / renderCamera.aspect);
15436
- info.bounds.height -= height - desired;
15437
- info.bounds.y += (height - desired) / 2;
16085
+ object.clickInfo.bounds.height -= height - desired;
16086
+ object.clickInfo.bounds.y += (height - desired) / 2;
1543816087 }
1543916088 }
15440
- info.g = gr;
15441
- info.camera = renderCamera;
16089
+
16090
+ object.clickInfo.g = gr;
16091
+ object.clickInfo.camera = renderCamera;
1544216092 /*
1544316093 // Memory intensive (brep.verticescopy)
1544416094 if (!(object instanceof Composite))
1544516095 object.draw(info, 0, false); // SLOW :
1544616096 */
15447
- if (!isRenderer)
16097
+ if (!isRenderer) // && drag)
1544816098 {
15449
- 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
+ }
1545016139 }
1545116140 }
16141
+
1545216142 if (isRenderer)
1545316143 {
1545416144 //gr.setColor(Color.black);
1545516145 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1545616146 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1545716147 }
16148
+
1545816149 if (hasMarquee)
1545916150 {
1546016151 gr.setXORMode(Color.white);
....@@ -15861,7 +16552,7 @@
1586116552 Object3D object;
1586216553 static Object3D trackedobject;
1586316554 Camera renderCamera; // Light or Eye (or Occlusion)
15864
- /*static*/ Camera manipCamera; // Light or Eye
16555
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1586516556 /*static*/ Camera eyeCamera;
1586616557 /*static*/ Camera lightCamera;
1586716558 int cameracount;
....@@ -15925,6 +16616,8 @@
1592516616 private /*static*/ boolean firstime;
1592616617 private /*static*/ cVector newView = new cVector();
1592716618 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"};
1592816621 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1592916622 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1593016623 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -15937,29 +16630,67 @@
1593716630 {
1593816631 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1593916632
16633
+ int usedsuf = 0;
16634
+
1594016635 for (int i = 0; i < suffixes.length; i++)
1594116636 {
15942
- String resourceName = basename + suffixes[i] + "." + suffix;
15943
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
15944
- mipmapped,
15945
- FileUtil.getFileSuffix(resourceName));
15946
- if (data == null)
16637
+ String[] suffixe = suffixes;
16638
+ String[] fallback = suffixes2;
16639
+ String[] fallfallback = suffixes3;
16640
+
16641
+ for (int c=usedsuf; --c>=0;)
1594716642 {
15948
- throw new IOException("Unable to load texture " + resourceName);
16643
+// String[] temp = suffixe;
16644
+// suffixe = fallback;
16645
+// fallback = fallfallback;
16646
+// fallfallback = temp;
1594916647 }
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
+
1595016676 //System.out.println("Target = " + targets[i]);
1595116677 cubemap.updateImage(data, targets[i]);
1595216678 }
1595316679
1595416680 return cubemap;
1595516681 }
16682
+
1595616683 int bigsphere = -1;
1595716684
1595816685 float BGcolor = 0.5f;
1595916686
15960
- private void DrawSkyBox(GL gl)
16687
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16688
+
16689
+ private void DrawSkyBox(GL gl, float ratio)
1596116690 {
15962
- if (envyoff || cubemap == null)
16691
+ if (//envyoff ||
16692
+ WIREFRAME ||
16693
+ cubemap == null)
1596316694 {
1596416695 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1596516696 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -15974,7 +16705,17 @@
1597416705 // Compensates for ExaminerViewer's modification of modelview matrix
1597516706 gl.glMatrixMode(GL.GL_MODELVIEW);
1597616707 gl.glLoadIdentity();
16708
+ gl.glScalef(1,ratio,1);
1597716709
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
+
1597816719 //gl.glActiveTexture(GL.GL_TEXTURE1);
1597916720 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1598016721
....@@ -16006,6 +16747,7 @@
1600616747 {
1600716748 gl.glScalef(1.0f, -1.0f, 1.0f);
1600816749 }
16750
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1600916751 gl.glMultMatrixd(viewrot_1, 0);
1601016752 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1601116753 //viewer.updateInverseRotation(gl);
....@@ -16146,16 +16888,16 @@
1614616888 cStatic.objectstack[materialdepth++] = checker;
1614716889 //System.out.println("material " + material);
1614816890 //Applet3D.tracein(this, selected);
16149
- vector2buffer = checker.projectedVertices;
16891
+ //vector2buffer = checker.projectedVertices;
1615016892
1615116893 //checker.GetMaterial().Draw(this, false); // true);
16152
- DrawMaterial(checker.GetMaterial(), false); // true);
16894
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1615316895
1615416896 materialdepth -= 1;
1615516897 if (materialdepth > 0)
1615616898 {
16157
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16158
- 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);
1615916901 }
1616016902 //checker.GetMaterial().opacity = 1f;
1616116903 ////checker.GetMaterial().ambient = 1f;
....@@ -16241,6 +16983,14 @@
1624116983 }
1624216984 }
1624316985
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
+
1624416994 class SelectBuffer implements GLEventListener
1624516995 {
1624616996
....@@ -16256,7 +17006,7 @@
1625617006 //new Exception().printStackTrace();
1625717007 System.out.println("select buffer init");
1625817008 // Use debug pipeline
16259
- drawable.setGL(new DebugGL(drawable.getGL()));
17009
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1626017010
1626117011 GL gl = drawable.getGL();
1626217012
....@@ -16320,6 +17070,17 @@
1632017070
1632117071 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1632217072
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
+
1632317084 //int tmp = selection_view;
1632417085 //selection_view = -1;
1632517086 int temp = DrawMode();
....@@ -16331,6 +17092,17 @@
1633117092 // temp = DEFAULT; // patch for selection debug
1633217093 Globals.drawMode = temp; // WARNING
1633317094
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
+
1633417106 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1633517107
1633617108 // trying different ways of getting the depth info over
....@@ -16378,6 +17150,8 @@
1637817150 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1637917151 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1638017152 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
17153
+
17154
+ CreateSelectedPoint();
1638117155
1638217156 // Will fit the mesh !!!
1638317157 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16427,34 +17201,36 @@
1642717201 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]));
1642817202 }
1642917203
16430
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
17204
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1643117205 }
1643217206 }
1643317207
1643417208 if (!movingcamera && !PAINTMODE)
16435
- object.editWindow.ScreenFitPoint(); // fev 2014
17209
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1643617210
16437
- 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)
1643817212 {
16439
- 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);
1644017214
16441
- Object3D group = new Object3D("inst" + paintcount++);
17215
+ if (object.GetWindow().copy.selection.Size() > 0)
17216
+ {
17217
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1644217218
16443
- group.CreateMaterial(); // use a void leaf to select instances
16444
-
16445
- group.add(paintobj); // link
16446
-
16447
- object.editWindow.SnapObject(group);
16448
-
16449
- Object3D folder = object.editWindow.copy;
16450
-
16451
- if (object.editWindow.copy.selection.Size() > 0)
16452
- folder = object.editWindow.copy.selection.elementAt(0);
16453
-
16454
- folder.add(group);
16455
-
16456
- object.editWindow.ResetModel();
16457
- 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
+ }
1645817234 }
1645917235 else
1646017236 paintcount = 0;
....@@ -16493,6 +17269,11 @@
1649317269 //System.out.println("objects[color] = " + objects[color]);
1649417270 //objects[color].Select();
1649517271 indexcount = 0;
17272
+ ObjEditor window = object.GetWindow();
17273
+ if (window != null && deselect)
17274
+ {
17275
+ window.Select(null, deselect, true);
17276
+ }
1649617277 object.Select(color, deselect);
1649717278 }
1649817279
....@@ -16592,7 +17373,7 @@
1659217373 gl.glDisable(gl.GL_CULL_FACE);
1659317374 }
1659417375
16595
- if (!RENDERSHADOW)
17376
+ if (!Globals.RENDERSHADOW)
1659617377 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1659717378
1659817379 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -16602,7 +17383,7 @@
1660217383 //gl.glColorMask(false, false, false, false);
1660317384
1660417385 //render_scene_from_light_view(gl, drawable, 0, 0);
16605
- if (RENDERSHADOW && Globals.lighttouched && !movingcamera) // && !parent.IsFreezed())
17386
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1660617387 {
1660717388 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1660817389
....@@ -16771,10 +17552,14 @@
1677117552 gl.glFlush();
1677217553
1677317554 /**/
16774
- 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);
1677517556
16776
- float[] pixels = occlusionsizebuffer.array();
17557
+ float[] depths = occlusiondepthbuffer.array();
1677717558
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
+
1677817563 double r = 0, g = 0, b = 0;
1677917564
1678017565 double count = 0;
....@@ -16785,7 +17570,7 @@
1678517570
1678617571 double FACTOR = 1;
1678717572
16788
- for (int i = 0; i < pixels.length; i++)
17573
+ for (int i = 0; i < depths.length; i++)
1678917574 {
1679017575 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1679117576 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -16868,7 +17653,7 @@
1686817653
1686917654 double scale = ray.z; // 1; // cos
1687017655
16871
- float depth = pixels[newindex];
17656
+ float depth = depths[newindex];
1687217657
1687317658 /*
1687417659 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -17018,23 +17803,15 @@
1701817803 int AAbuffersize = 0;
1701917804
1702017805 //double[] selectedpoint = new double[3];
17021
- static Superellipsoid selectedpoint = new Superellipsoid();
17806
+ static Superellipsoid selectedpoint;
1702217807 static Sphere previousselectedpoint = null;
17023
- static Sphere debugpointG = new Sphere();
17024
- static Sphere debugpointP = new Sphere();
17025
- static Sphere debugpointC = new Sphere();
17026
- static Sphere debugpointR = new Sphere();
17808
+ static Sphere debugpointG;
17809
+ static Sphere debugpointP;
17810
+ static Sphere debugpointC;
17811
+ static Sphere debugpointR;
1702717812
1702817813 static Sphere debugpoints[] = new Sphere[8];
1702917814
17030
- static
17031
- {
17032
- for (int i=0; i<8; i++)
17033
- {
17034
- debugpoints[i] = new Sphere();
17035
- }
17036
- }
17037
-
1703817815 static void InitPoints(float radius)
1703917816 {
1704017817 for (int i=0; i<8; i++)
....@@ -17073,11 +17850,14 @@
1707317850 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1707417851 static IntBuffer bigAAbuffer;
1707517852 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
17076
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17853
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1707717854 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1707817855 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1707917856 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17080
- 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
+
1708117861 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1708217862 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1708317863 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();