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();
....@@ -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
....@@ -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)
....@@ -8024,6 +8206,54 @@
80248206
80258207 /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
80268208 {
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
8256
+ {
80278257 if (// DrawMode() != 0 || /*tex == null ||*/
80288258 ambientOcclusion ) // || !textureon)
80298259 {
....@@ -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) throws Exception
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
....@@ -8187,19 +8509,20 @@
81878509 if (texturedata == null)
81888510 throw new Exception();
81898511
8190
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8512
+ texturecache = new CacheTexture(texturedata,resolution);
81918513 //texture = GetTexture(tex, bump);
81928514 }
8515
+ }
81938516 }
81948517 //}
81958518 }
81968519
8197
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8520
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
81988521 {
81998522 //return false;
82008523
82018524 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8202
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8525
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
82038526 {
82048527 // String ext = "_highres";
82058528 // if (REDUCETEXTURE)
....@@ -8216,52 +8539,17 @@
82168539 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
82178540 if (!cachefile.exists())
82188541 {
8219
- // cache to disk
8220
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
8221
- //buffers[0].
8222
-
8223
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
8224
- int[] pixels = new int[bytebuf.capacity()/3];
8225
-
8226
- // squared size heuristic...
8227
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8542
+ //if (texturedata.getWidth() == texturedata.getHeight())
82288543 {
8229
- for (int i=pixels.length; --i>=0;)
8230
- {
8231
- int i3 = i*3;
8232
- pixels[i] = 0xFF;
8233
- pixels[i] <<= 8;
8234
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
8235
- pixels[i] <<= 8;
8236
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
8237
- pixels[i] <<= 8;
8238
- pixels[i] |= bytebuf.get(i3) & 0xFF;
8239
- }
8240
-
8241
- /*
8242
- int r=0,g=0,b=0,a=0;
8243
- for (int i=0; i<width; i++)
8244
- for (int j=0; j<height; j++)
8245
- {
8246
- int index = j*width+i;
8247
- int p = pixels[index];
8248
- a = ((p>>24) & 0xFF);
8249
- r = ((p>>16) & 0xFF);
8250
- g = ((p>>8) & 0xFF);
8251
- b = (p & 0xFF);
8252
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
8253
- }
8254
- /**/
8255
- int width = (int)Math.sqrt(pixels.length); // squared
8256
- int height = width;
8257
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
8258
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8544
+ BufferedImage rendImage = CreateBim(texturedata);
8545
+
82598546 ImageWriter writer = null;
82608547 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
82618548 if (iter.hasNext()) {
82628549 writer = (ImageWriter)iter.next();
82638550 }
8264
- float compressionQuality = 0.9f;
8551
+
8552
+ float compressionQuality = 0.85f;
82658553 try
82668554 {
82678555 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8278,18 +8566,20 @@
82788566 }
82798567 }
82808568 }
8281
-
8569
+
8570
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8571
+
82828572 //System.out.println("Texture = " + tex);
8283
- if (textures.containsKey(texname))
8573
+ if (textures.containsKey(tex))
82848574 {
8285
- CacheTexture thetex = textures.get(texname);
8575
+ CacheTexture thetex = textures.get(tex);
82868576 thetex.texture.disable();
82878577 thetex.texture.dispose();
8288
- textures.remove(texname);
8578
+ textures.remove(tex);
82898579 }
82908580
8291
- texture.texturedata = texturedata;
8292
- textures.put(texname, texture);
8581
+ //texture.texturedata = texturedata;
8582
+ textures.put(tex, texturecache);
82938583
82948584 // newtex = true;
82958585 }
....@@ -8305,10 +8595,44 @@
83058595 }
83068596 }
83078597
8308
- return texture;
8598
+ return texturecache;
83098599 }
83108600
8311
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution) throws Exception
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
83128636 {
83138637 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
83148638
....@@ -8326,21 +8650,21 @@
83268650 return texture!=null?texture.texture:null;
83278651 }
83288652
8329
- public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution) throws Exception
8653
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
83308654 {
83318655 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
83328656
83338657 return texture!=null?texture.texturedata:null;
83348658 }
83358659
8336
- boolean BindTexture(String tex, boolean bump, int resolution) throws Exception
8660
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
83378661 {
83388662 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
83398663 {
83408664 return false;
83418665 }
83428666
8343
- boolean newtex = false;
8667
+ //boolean newtex = false;
83448668
83458669 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
83468670
....@@ -8372,9 +8696,75 @@
83728696 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
83738697 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
83748698
8375
- return newtex;
8699
+ return true; // Warning: not used.
83768700 }
83778701
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
+
83788768 ShadowBuffer shadowPBuf;
83798769 AntialiasBuffer antialiasPBuf;
83808770 int MAXSTACK;
....@@ -8391,10 +8781,12 @@
83918781
83928782 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
83938783 MAXSTACK = temp[0];
8394
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8784
+ if (Globals.DEBUG)
8785
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
83958786 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
83968787 MAXSTACK = temp[0];
8397
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8788
+ if (Globals.DEBUG)
8789
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
83988790
83998791 // Use debug pipeline
84008792 //drawable.setGL(new DebugGL(gl)); //
....@@ -8402,7 +8794,8 @@
84028794 gl = drawable.getGL(); //
84038795
84048796 GL gl3 = getGL();
8405
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8797
+ if (Globals.DEBUG)
8798
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
84068799
84078800
84088801 //float pos[] = { 100, 100, 100, 0 };
....@@ -8567,7 +8960,7 @@
85678960
85688961 if (cubemap == null)
85698962 {
8570
- LoadEnvy(5);
8963
+ //LoadEnvy(1);
85718964 }
85728965
85738966 //cubemap.enable();
....@@ -8843,6 +9236,8 @@
88439236
88449237 void LoadEnvy(int which)
88459238 {
9239
+ assert(false);
9240
+
88469241 String name;
88479242 String ext;
88489243
....@@ -8854,37 +9249,58 @@
88549249 cubemap = null;
88559250 return;
88569251 case 1:
8857
- name = "cubemaps/box_";
8858
- ext = "png";
9252
+ name = "cubemaps/rgb/";
9253
+ ext = "jpg";
88599254 reverseUP = false;
88609255 break;
88619256 case 2:
8862
- name = "cubemaps/uffizi_";
8863
- ext = "png";
8864
- break; // reverseUP = true; break;
9257
+ name = "cubemaps/uffizi/";
9258
+ ext = "jpg";
9259
+ reverseUP = false;
9260
+ break;
88659261 case 3:
8866
- name = "cubemaps/CloudyHills_";
8867
- ext = "tga";
9262
+ name = "cubemaps/CloudyHills/";
9263
+ ext = "jpg";
88689264 reverseUP = false;
88699265 break;
88709266 case 4:
8871
- name = "cubemaps/cornell_";
9267
+ name = "cubemaps/cornell/";
88729268 ext = "png";
88739269 reverseUP = false;
88749270 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;
88759296 default:
8876
- name = "cubemaps/rgb_";
8877
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9297
+ name = "cubemaps/box/";
9298
+ ext = "png"; /*mipmap = true;*/
9299
+ reverseUP = false;
88789300 break;
88799301 }
8880
-
8881
- try
8882
- {
8883
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
8884
- } catch (IOException e)
8885
- {
8886
- throw new RuntimeException(e);
8887
- }
9302
+
9303
+ LoadSkybox(name, ext, mipmap);
88889304 }
88899305
88909306 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -8916,8 +9332,12 @@
89169332 static double[] model = new double[16];
89179333 double[] camera2light = new double[16];
89189334 double[] light2camera = new double[16];
8919
- int newenvy = -1;
8920
- boolean envyoff = true; // false;
9335
+
9336
+ //int newenvy = -1;
9337
+ //boolean envyoff = false;
9338
+
9339
+ String loadedskyboxname;
9340
+
89219341 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
89229342 //float[] light0 = { 0,0,0 };
89239343 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9210,11 +9630,35 @@
92109630 jy8[3] = 0.5f;
92119631 }
92129632
9213
- 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
92149634 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
92159635 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
92169636 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
92179637
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
+
92189662 static int imagecount = 0; // movie generation
92199663
92209664 static int jitter = 0;
....@@ -9310,8 +9754,8 @@
93109754 assert (parentcam != renderCamera);
93119755
93129756 if (renderCamera != lightCamera)
9313
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9314
- LA.matConcat(matrix, parentcam.toParent, matrix);
9757
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9758
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
93159759
93169760 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
93179761
....@@ -9326,8 +9770,8 @@
93269770 LA.matCopy(renderCamera.fromScreen, matrix);
93279771
93289772 if (renderCamera != lightCamera)
9329
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9330
- LA.matConcat(parentcam.fromParent, matrix, matrix);
9773
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9774
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
93319775
93329776 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
93339777
....@@ -9373,10 +9817,12 @@
93739817 rati = 1 / rati;
93749818 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
93759819 }
9376
- assert (newenvy == -1);
9820
+
9821
+ //assert (newenvy == -1);
9822
+
93779823 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
93789824 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9379
- DrawSkyBox(gl);
9825
+ DrawSkyBox(gl, (float)rati);
93809826 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
93819827 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
93829828 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10325,6 +10771,7 @@
1032510771 ANTIALIAS = 0;
1032610772 //System.out.println("RESTART");
1032710773 AAtimer.restart();
10774
+ Globals.TIMERRUNNING = true;
1032810775 }
1032910776 }
1033010777 }
....@@ -10392,13 +10839,14 @@
1039210839 ambientOcclusion = false;
1039310840 }
1039410841
10395
- if (Globals.lighttouched && DrawMode() == DEFAULT && !lightMode) // && !FROZEN)
10842
+ if (//Globals.lighttouched &&
10843
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1039610844 {
1039710845 //if (RENDERSHADOW) // ?
1039810846 if (!IsFrozen())
1039910847 {
1040010848 // dec 2012
10401
- if (!ambientOcclusion && !(!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0))
10849
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
1040210850 {
1040310851 Globals.framecount++;
1040410852 shadowbuffer.display();
....@@ -10411,7 +10859,7 @@
1041110859
1041210860 if (wait)
1041310861 {
10414
- Sleep(500);
10862
+ Sleep(200); // blocks everything
1041510863
1041610864 wait = false;
1041710865 }
....@@ -10525,8 +10973,8 @@
1052510973
1052610974 // if (parentcam != renderCamera) // not a light
1052710975 if (cam != lightCamera)
10528
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10529
- LA.matConcat(matrix, parentcam.toParent, matrix);
10976
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10977
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1053010978
1053110979 for (int j = 0; j < 4; j++)
1053210980 {
....@@ -10540,8 +10988,8 @@
1054010988
1054110989 // if (parentcam != renderCamera) // not a light
1054210990 if (cam != lightCamera)
10543
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10544
- LA.matConcat(parentcam.fromParent, matrix, matrix);
10991
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10992
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1054510993
1054610994 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1054710995
....@@ -10627,13 +11075,41 @@
1062711075 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1062811076 }
1062911077
10630
- 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"))
1063111086 {
10632
- LoadEnvy(newenvy);
11087
+ if (cubemaprgb == null)
11088
+ {
11089
+ cubemaprgb = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11090
+ }
11091
+
11092
+ cubemap = cubemaprgb;
1063311093 }
10634
-
10635
- newenvy = -1;
10636
-
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
+
1063711113 ratio = ((double) getWidth()) / getHeight();
1063811114 //System.out.println("ratio = " + ratio);
1063911115
....@@ -10649,7 +11125,7 @@
1064911125
1065011126 if (!IsFrozen() && !ambientOcclusion)
1065111127 {
10652
- DrawSkyBox(gl);
11128
+ DrawSkyBox(gl, (float)ratio);
1065311129 }
1065411130
1065511131 //if (selection_view == -1)
....@@ -10832,9 +11308,9 @@
1083211308
1083311309 gl.glMatrixMode(GL.GL_MODELVIEW);
1083411310
10835
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10836
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10837
-//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);
1083811314 } else
1083911315 {
1084011316 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -10845,7 +11321,7 @@
1084511321 //System.out.println("BLENDING ON");
1084611322 gl.glEnable(GL.GL_BLEND);
1084711323 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
10848
-
11324
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1084911325 gl.glMatrixMode(gl.GL_PROJECTION);
1085011326 gl.glLoadIdentity();
1085111327
....@@ -10934,8 +11410,8 @@
1093411410 System.err.println("parentcam != renderCamera");
1093511411
1093611412 // if (cam != lightCamera)
10937
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10938
- 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
1093911415 }
1094011416
1094111417 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -10956,8 +11432,8 @@
1095611432 if (true) // TODO
1095711433 {
1095811434 if (cam != lightCamera)
10959
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10960
- 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
1096111437 }
1096211438
1096311439 LA.xformPos(light0, cam.toScreen, light0);
....@@ -11094,7 +11570,7 @@
1109411570 }
1109511571 }
1109611572
11097
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11573
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1109811574 {
1109911575 //gl.glDepthFunc(GL.GL_LEQUAL);
1110011576 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11102,24 +11578,21 @@
1110211578
1110311579 boolean texon = textureon;
1110411580
11105
- if (RENDERPROGRAM > 0)
11106
- {
11107
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11108
- textureon = false;
11109
- }
11581
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11582
+ textureon = false;
11583
+
1111011584 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1111111585 //System.out.println("ALLO");
1111211586 gl.glColorMask(false, false, false, false);
1111311587 DrawObject(gl);
11114
- if (RENDERPROGRAM > 0)
11115
- {
11116
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11117
- textureon = texon;
11118
- }
11588
+
11589
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11590
+ textureon = texon;
11591
+
1111911592 gl.glColorMask(true, true, true, true);
1112011593
1112111594 gl.glDepthFunc(GL.GL_EQUAL);
11122
- //gl.glDepthMask(false);
11595
+ gl.glDepthMask(false);
1112311596 }
1112411597
1112511598 if (false) // DrawMode() == SHADOW)
....@@ -11302,15 +11775,36 @@
1130211775
1130311776 static boolean zoomonce = false;
1130411777
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
+
1130511796 void DrawObject(GL gl, boolean draw)
1130611797 {
11798
+ // To clear camera values
11799
+ ResetOptions();
11800
+
1130711801 //System.out.println("DRAW OBJECT " + mouseDown);
1130811802 // DrawMode() = SELECTION;
1130911803 //GL gl = getGL();
1131011804 if ((TRACK || SHADOWTRACK) || zoomonce)
1131111805 {
1131211806 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11313
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11807
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1131411808 pingthread.StepToTarget(true); // true);
1131511809 // zoomonce = false;
1131611810 }
....@@ -11382,8 +11876,9 @@
1138211876
1138311877 if (DrawMode() == DEFAULT)
1138411878 {
11385
- if (DEBUG)
11879
+ if (Globals.DEBUG)
1138611880 {
11881
+ CreateSelectedPoint();
1138711882 float radius = 0.05f;
1138811883 if (selectedpoint.radius != radius)
1138911884 {
....@@ -11437,20 +11932,32 @@
1143711932 ReleaseTextures(DEFAULT_TEXTURES);
1143811933
1143911934 if (CLEANCACHE)
11440
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11935
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1144111936 {
11442
- String tex = e.nextElement();
11937
+ cTexture tex = e.nextElement();
1144311938
1144411939 // System.out.println("Texture --------- " + tex);
1144511940
11446
- if (tex.equals("WHITE_NOISE"))
11941
+ if (tex.equals("WHITE_NOISE:"))
1144711942 continue;
1144811943
11449
- if (!usedtextures.containsKey(tex))
11944
+ if (!usedtextures.contains(tex))
1145011945 {
11946
+ CacheTexture gettex = texturepigment.get(tex);
1145111947 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11452
- textures.get(tex).texture.dispose();
11453
- 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
+ }
1145411961 }
1145511962 }
1145611963 }
....@@ -11869,8 +12376,8 @@
1186912376 //obj.TransformToWorld(light, light);
1187012377 for (int i = tp.size(); --i >= 0;)
1187112378 {
11872
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
11873
- 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);
1187412381 }
1187512382
1187612383
....@@ -11887,8 +12394,8 @@
1188712394 parentcam = cameras[0];
1188812395 }
1188912396
11890
- for (int count = parentcam.GetTransformCount(); --count>=0;)
11891
- 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
1189212399
1189312400 LA.xformPos(light, renderCamera.toScreen, light);
1189412401
....@@ -11978,8 +12485,76 @@
1197812485
1197912486 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1198012487
11981
- String program =
12488
+ String programmin =
12489
+ // Min shader
1198212490 "!!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
+
1198312558 //"OPTION ARB_fragment_program_shadow;" +
1198412559 "PARAM light2cam0 = program.env[10];" +
1198512560 "PARAM light2cam1 = program.env[11];" +
....@@ -12094,8 +12669,7 @@
1209412669 "TEMP shininess;" +
1209512670 "\n" +
1209612671 "MOV texSamp, one;" +
12097
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12098
-
12672
+
1209912673 "MOV mapgrid.x, one2048th.x;" +
1210012674 "MOV temp, fragment.texcoord[1];" +
1210112675 /*
....@@ -12116,20 +12690,20 @@
1211612690 "MUL temp, floor, mapgrid.x;" +
1211712691 //"TEX depth0, temp, texture[1], 2D;" +
1211812692 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12119
- TextureFetch("depth0", "temp", "1") +
12693
+ ShadowTextureFetch("depth0", "temp", "1") +
1212012694 "") +
1212112695 "ADD temp.x, temp.x, mapgrid.x;" +
1212212696 //"TEX depth1, temp, texture[1], 2D;" +
1212312697 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12124
- TextureFetch("depth1", "temp", "1") +
12698
+ ShadowTextureFetch("depth1", "temp", "1") +
1212512699 "") +
1212612700 "ADD temp.y, temp.y, mapgrid.x;" +
1212712701 //"TEX depth2, temp, texture[1], 2D;" +
12128
- TextureFetch("depth2", "temp", "1") +
12702
+ ShadowTextureFetch("depth2", "temp", "1") +
1212912703 "SUB temp.x, temp.x, mapgrid.x;" +
1213012704 //"TEX depth3, temp, texture[1], 2D;" +
1213112705 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12132
- TextureFetch("depth3", "temp", "1") +
12706
+ ShadowTextureFetch("depth3", "temp", "1") +
1213312707 "") +
1213412708 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1213512709 //"MOV params, material;" +
....@@ -12500,10 +13074,10 @@
1250013074 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1250113075 "") +
1250213076
12503
- // display shadow only (bump == 0)
13077
+ // display shadow only (fakedepth == 0)
1250413078 "SUB temp.x, half.x, shadow.x;" +
1250513079 "MOV temp.y, -params5.z;" + // params6.x;" +
12506
- "SLT temp.z, temp.y, -one2048th.x;" +
13080
+ "SLT temp.z, temp.y, -c256i.x;" +
1250713081 "SUB temp.y, one.x, temp.z;" +
1250813082 "MUL temp.x, temp.x, temp.y;" +
1250913083 "KIL temp.x;" +
....@@ -12834,6 +13408,13 @@
1283413408 //once = true;
1283513409 }
1283613410
13411
+ String program = programmax;
13412
+
13413
+ if (Globals.MINSHADER)
13414
+ {
13415
+ program = programmin;
13416
+ }
13417
+
1283713418 System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1283813419 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1283913420 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
....@@ -12927,25 +13508,26 @@
1292713508 return out;
1292813509 }
1292913510
12930
- String TextureFetch(String dest, String src, String unit)
13511
+ // Also does frustum culling
13512
+ String ShadowTextureFetch(String dest, String src, String unit)
1293113513 {
1293213514 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1293313515 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1293413516 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13517
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13518
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1293513519 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12936
- "SLT " + src + ".z, " + src + ".x, one.x;" +
12937
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12938
- "SLT " + src + ".z, " + src + ".y, one.x;" +
12939
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13520
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13521
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1294013522 //"SWZ buffer, temp, w,w,w,w;";
12941
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13523
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1294213524 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1294313525 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1294413526 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
12945
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13527
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1294613528
12947
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
12948
- //"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;";
1294913531 }
1295013532
1295113533 String Shadow(String depth, String shadow)
....@@ -12992,7 +13574,7 @@
1299213574 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1299313575 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1299413576
12995
- // No shadow when out of frustrum
13577
+ // No shadow when out of frustum
1299613578 "SGE temp.x, " + depth + ".z, one.z;" +
1299713579 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1299813580 "";
....@@ -13140,7 +13722,8 @@
1314013722 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1314113723 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1314213724 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13143
- Object3D.cVector2[] vector2buffer;
13725
+
13726
+ //Object3D.cVector2[] vector2buffer;
1314413727
1314513728 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1314613729 // OUT : diff, spec
....@@ -13156,9 +13739,10 @@
1315613739 "DP3 " + dest + ".z," + "normals," + "eye;" +
1315713740 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1315813741 //"MOV " + dest + ".w," + "normal.z;" +
13159
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
13160
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13161
- //"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
1316213746 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1316313747 "RCP " + dest + ".w," + dest + ".w;" +
1316413748 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13663,6 +14247,7 @@
1366314247 else
1366414248 if (evt.getSource() == AAtimer)
1366514249 {
14250
+ Globals.TIMERRUNNING = false;
1366614251 if (mouseDown)
1366714252 {
1366814253 //new Exception().printStackTrace();
....@@ -13722,7 +14307,7 @@
1372214307
1372314308 // fev 2014???
1372414309 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13725
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14310
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1372614311 pingthread.StepToTarget(true); // true);
1372714312 }
1372814313 // if (!LIVE)
....@@ -13737,6 +14322,7 @@
1373714322 return;
1373814323
1373914324 AAtimer.restart(); //
14325
+ Globals.TIMERRUNNING = true;
1374014326
1374114327 // waslive = LIVE;
1374214328 // LIVE = false;
....@@ -13786,14 +14372,15 @@
1378614372 drag = false;
1378714373 //System.out.println("Mouse DOWN");
1378814374 editObj = false;
13789
- ClickInfo info = new ClickInfo();
13790
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
13791
- info.pane = this;
13792
- info.camera = renderCamera;
13793
- info.x = x;
13794
- info.y = y;
13795
- info.modifiers = modifiersex;
13796
- 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);
1379714384 if (!editObj)
1379814385 {
1379914386 hasMarquee = true;
....@@ -13809,9 +14396,12 @@
1380914396
1381014397 public void mouseDragged(MouseEvent e)
1381114398 {
14399
+ Globals.MOUSEDRAGGED = true;
14400
+
1381214401 //System.out.println("mouseDragged: " + e);
1381314402 if (isRenderer)
1381414403 movingcamera = true;
14404
+
1381514405 //if (drawing)
1381614406 //return;
1381714407 if ((e.getModifiersEx() & CTRL) != 0
....@@ -14072,12 +14662,12 @@
1407214662 void GoDown(int mod)
1407314663 {
1407414664 MODIFIERS |= COMMAND;
14075
- /*
14665
+ /**/
1407614666 if((mod&SHIFT) == SHIFT)
14077
- manipCamera.RotatePosition(0, -speed);
14667
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
1407814668 else
14079
- manipCamera.BackForth(0, -speed*delta, getWidth());
14080
- */
14669
+ manipCamera.RotatePosition(0, -speed);
14670
+ /**/
1408114671 if ((mod & SHIFT) == SHIFT)
1408214672 {
1408314673 mouseMode = mouseMode; // VR??
....@@ -14093,12 +14683,12 @@
1409314683 void GoUp(int mod)
1409414684 {
1409514685 MODIFIERS |= COMMAND;
14096
- /*
14686
+ /**/
1409714687 if((mod&SHIFT) == SHIFT)
14098
- manipCamera.RotatePosition(0, speed);
14688
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
1409914689 else
14100
- manipCamera.BackForth(0, speed*delta, getWidth());
14101
- */
14690
+ manipCamera.RotatePosition(0, speed);
14691
+ /**/
1410214692 if ((mod & SHIFT) == SHIFT)
1410314693 {
1410414694 mouseMode = mouseMode;
....@@ -14114,12 +14704,12 @@
1411414704 void GoLeft(int mod)
1411514705 {
1411614706 MODIFIERS |= COMMAND;
14117
- /*
14707
+ /**/
1411814708 if((mod&SHIFT) == SHIFT)
14119
- manipCamera.RotatePosition(speed, 0);
14120
- else
1412114709 manipCamera.Translate(speed*delta, 0, getWidth());
14122
- */
14710
+ else
14711
+ manipCamera.RotatePosition(speed, 0);
14712
+ /**/
1412314713 if ((mod & SHIFT) == SHIFT)
1412414714 {
1412514715 mouseMode = mouseMode;
....@@ -14135,12 +14725,12 @@
1413514725 void GoRight(int mod)
1413614726 {
1413714727 MODIFIERS |= COMMAND;
14138
- /*
14728
+ /**/
1413914729 if((mod&SHIFT) == SHIFT)
14140
- manipCamera.RotatePosition(-speed, 0);
14141
- else
1414214730 manipCamera.Translate(-speed*delta, 0, getWidth());
14143
- */
14731
+ else
14732
+ manipCamera.RotatePosition(-speed, 0);
14733
+ /**/
1414414734 if ((mod & SHIFT) == SHIFT)
1414514735 {
1414614736 mouseMode = mouseMode;
....@@ -14190,14 +14780,16 @@
1419014780 if (editObj)
1419114781 {
1419214782 drag = true;
14193
- ClickInfo info = new ClickInfo();
14194
- info.bounds.setBounds(0, 0,
14783
+ //ClickInfo info = new ClickInfo();
14784
+ object.clickInfo.bounds.setBounds(0, 0,
1419514785 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14196
- info.pane = this;
14197
- info.camera = renderCamera;
14198
- info.x = x;
14199
- info.y = y;
14200
- 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);
1420114793 } else
1420214794 {
1420314795 if (x < startX)
....@@ -14346,22 +14938,27 @@
1434614938 }
1434714939 }
1434814940
14941
+// ClickInfo clickInfo = new ClickInfo();
14942
+
1434914943 public void mouseMoved(MouseEvent e)
1435014944 {
1435114945 //System.out.println("mouseMoved: " + e);
1435214946 if (isRenderer)
1435314947 return;
1435414948
14355
- ClickInfo ci = new ClickInfo();
14356
- ci.x = e.getX();
14357
- ci.y = e.getY();
14358
- ci.modifiers = e.getModifiersEx();
14359
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14360
- ci.pane = this;
14361
- 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;
1436214956 if (!isRenderer)
1436314957 {
14364
- if (object.editWindow.copy.doEditClick(ci, 0))
14958
+ //ObjEditor editWindow = object.editWindow;
14959
+ //Object3D copy = editWindow.copy;
14960
+ if (object.doEditClick(//clickInfo,
14961
+ 0))
1436514962 {
1436614963 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1436714964 } else
....@@ -14373,8 +14970,11 @@
1437314970
1437414971 public void mouseReleased(MouseEvent e)
1437514972 {
14973
+ Globals.MOUSEDRAGGED = false;
14974
+
1437614975 movingcamera = false;
14377
- X = Y = 0;
14976
+ X = 0; // getBounds().width/2;
14977
+ Y = 0; // getBounds().height/2;
1437814978 //System.out.println("mouseReleased: " + e);
1437914979 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1438014980 }
....@@ -14630,7 +15230,8 @@
1463015230 // break;
1463115231 case 'T':
1463215232 CACHETEXTURE ^= true;
14633
- textures.clear();
15233
+ texturepigment.clear();
15234
+ texturebump.clear();
1463415235 // repaint();
1463515236 break;
1463615237 case 'Y':
....@@ -14715,7 +15316,9 @@
1471515316 case 'E' : COMPACT ^= true;
1471615317 repaint();
1471715318 break;
14718
- case 'W' : DEBUGHSB ^= true;
15319
+ case 'W' : // Wide Window (fullscreen)
15320
+ //DEBUGHSB ^= true;
15321
+ ObjEditor.theFrame.ToggleFullScreen();
1471915322 repaint();
1472015323 break;
1472115324 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14740,8 +15343,8 @@
1474015343 RevertCamera();
1474115344 repaint();
1474215345 break;
14743
- case 'L':
1474415346 case 'l':
15347
+ //case 'L':
1474515348 if (lightMode)
1474615349 {
1474715350 lightMode = false;
....@@ -14805,20 +15408,24 @@
1480515408 OCCLUSION_CULLING ^= true;
1480615409 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1480715410 break;
14808
- case '0': envyoff ^= true; repaint(); break;
15411
+ //case '0': envyoff ^= true; repaint(); break;
1480915412 case '1':
1481015413 case '2':
1481115414 case '3':
1481215415 case '4':
1481315416 case '5':
14814
- newenvy = Character.getNumericValue(key);
14815
- repaint();
14816
- break;
1481715417 case '6':
1481815418 case '7':
1481915419 case '8':
1482015420 case '9':
14821
- 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
+ }
1482215429 repaint();
1482315430 break;
1482415431 case '!':
....@@ -14884,9 +15491,9 @@
1488415491 case '_':
1488515492 kompactbit = 5;
1488615493 break;
14887
- case '+':
14888
- kompactbit = 6;
14889
- break;
15494
+// case '+':
15495
+// kompactbit = 6;
15496
+// break;
1489015497 case ' ':
1489115498 lightMode ^= true;
1489215499 Globals.lighttouched = true;
....@@ -14898,6 +15505,7 @@
1489815505 case ESC:
1489915506 RENDERPROGRAM += 1;
1490015507 RENDERPROGRAM %= 3;
15508
+
1490115509 repaint();
1490215510 break;
1490315511 case 'Z':
....@@ -14937,8 +15545,9 @@
1493715545 case DELETE:
1493815546 ClearSelection();
1493915547 break;
14940
- /*
1494115548 case '+':
15549
+
15550
+ /*
1494215551 //fontsize += 1;
1494315552 bbzoom *= 2;
1494415553 repaint();
....@@ -14955,17 +15564,17 @@
1495515564 case '=':
1495615565 IncDepth();
1495715566 //fontsize += 1;
14958
- object.editWindow.refreshContents(true);
15567
+ object.GetWindow().refreshContents(true);
1495915568 maskbit = 6;
1496015569 break;
1496115570 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1496215571 DecDepth();
1496315572 maskbit = 5;
1496415573 //if(fontsize > 1) fontsize -= 1;
14965
- if (object.editWindow == null)
14966
- new Exception().printStackTrace();
14967
- else
14968
- object.editWindow.refreshContents(true);
15574
+// if (object.editWindow == null)
15575
+// new Exception().printStackTrace();
15576
+// else
15577
+ object.GetWindow().refreshContents(true);
1496915578 break;
1497015579 case '{':
1497115580 manipCamera.shaper_fovy /= 1.1;
....@@ -15189,7 +15798,7 @@
1518915798 }
1519015799 */
1519115800
15192
- object.editWindow.EditSelection();
15801
+ object.GetWindow().EditSelection(false);
1519315802 }
1519415803
1519515804 void SelectParent()
....@@ -15206,10 +15815,10 @@
1520615815 {
1520715816 //selectees.remove(i);
1520815817 System.out.println("select parent of " + elem);
15209
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15818
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1521015819 } else
1521115820 {
15212
- group.editWindow.Select(elem.GetTreePath(), first, true);
15821
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1521315822 }
1521415823
1521515824 first = false;
....@@ -15251,12 +15860,12 @@
1525115860 for (int j = 0; j < group.children.size(); j++)
1525215861 {
1525315862 elem = (Object3D) group.children.elementAt(j);
15254
- object.editWindow.Select(elem.GetTreePath(), first, true);
15863
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1525515864 first = false;
1525615865 }
1525715866 } else
1525815867 {
15259
- object.editWindow.Select(elem.GetTreePath(), first, true);
15868
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1526015869 }
1526115870
1526215871 first = false;
....@@ -15267,21 +15876,21 @@
1526715876 {
1526815877 //Composite group = (Composite) object;
1526915878 Object3D group = object;
15270
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15879
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1527115880 }
1527215881
1527315882 void ResetTransform(int mask)
1527415883 {
1527515884 //Composite group = (Composite) object;
1527615885 Object3D group = object;
15277
- group.editWindow.ResetTransform(mask);
15886
+ group.GetWindow().ResetTransform(mask);
1527815887 }
1527915888
1528015889 void FlipTransform()
1528115890 {
1528215891 //Composite group = (Composite) object;
1528315892 Object3D group = object;
15284
- group.editWindow.FlipTransform();
15893
+ group.GetWindow().FlipTransform();
1528515894 // group.editWindow.ReduceMesh(true);
1528615895 }
1528715896
....@@ -15289,7 +15898,7 @@
1528915898 {
1529015899 //Composite group = (Composite) object;
1529115900 Object3D group = object;
15292
- group.editWindow.PrintMemory();
15901
+ group.GetWindow().PrintMemory();
1529315902 // group.editWindow.ReduceMesh(true);
1529415903 }
1529515904
....@@ -15297,7 +15906,7 @@
1529715906 {
1529815907 //Composite group = (Composite) object;
1529915908 Object3D group = object;
15300
- group.editWindow.ResetCentroid();
15909
+ group.GetWindow().ResetCentroid();
1530115910 }
1530215911
1530315912 void IncDepth()
....@@ -15379,8 +15988,6 @@
1537915988
1538015989 int width = getBounds().width;
1538115990 int height = getBounds().height;
15382
- ClickInfo info = new ClickInfo();
15383
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1538415991 //Image img = CreateImage(width, height);
1538515992 //System.out.println("width = " + width + "; height = " + height + "\n");
1538615993
....@@ -15457,43 +16064,77 @@
1545716064 }
1545816065 if (object != null && !hasMarquee)
1545916066 {
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
+
1546016073 if (isRenderer)
1546116074 {
15462
- info.flags++;
16075
+ object.clickInfo.flags++;
1546316076 double frameAspect = (double) width / (double) height;
1546416077 if (frameAspect > renderCamera.aspect)
1546516078 {
1546616079 int desired = (int) ((double) height * renderCamera.aspect);
15467
- info.bounds.width -= width - desired;
15468
- info.bounds.x += (width - desired) / 2;
16080
+ object.clickInfo.bounds.width -= width - desired;
16081
+ object.clickInfo.bounds.x += (width - desired) / 2;
1546916082 } else
1547016083 {
1547116084 int desired = (int) ((double) width / renderCamera.aspect);
15472
- info.bounds.height -= height - desired;
15473
- info.bounds.y += (height - desired) / 2;
16085
+ object.clickInfo.bounds.height -= height - desired;
16086
+ object.clickInfo.bounds.y += (height - desired) / 2;
1547416087 }
1547516088 }
15476
- info.g = gr;
15477
- info.camera = renderCamera;
16089
+
16090
+ object.clickInfo.g = gr;
16091
+ object.clickInfo.camera = renderCamera;
1547816092 /*
1547916093 // Memory intensive (brep.verticescopy)
1548016094 if (!(object instanceof Composite))
1548116095 object.draw(info, 0, false); // SLOW :
1548216096 */
15483
- if (!isRenderer)
16097
+ if (!isRenderer) // && drag)
1548416098 {
15485
- object.drawEditHandles(info, 0);
15486
-
15487
- if (drag && (X != 0 || Y != 0) && object.selection.Size() > 0)
16099
+ Grafreed.Assert(object != null);
16100
+ Grafreed.Assert(object.selection != null);
16101
+ if (object.selection.Size() > 0)
1548816102 {
15489
- switch (object.selection.get(0).hitSomething)
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)
1549016109 {
15491
- case Object3D.hitCenter: gr.setColor(Color.pink); break;
15492
- case Object3D.hitRotate: gr.setColor(Color.green); break;
15493
- case Object3D.hitScale: gr.setColor(Color.cyan); break;
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;
1549416117 }
15495
-
15496
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
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
+ }
1549716138 }
1549816139 }
1549916140 }
....@@ -15911,7 +16552,7 @@
1591116552 Object3D object;
1591216553 static Object3D trackedobject;
1591316554 Camera renderCamera; // Light or Eye (or Occlusion)
15914
- /*static*/ Camera manipCamera; // Light or Eye
16555
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1591516556 /*static*/ Camera eyeCamera;
1591616557 /*static*/ Camera lightCamera;
1591716558 int cameracount;
....@@ -15975,6 +16616,8 @@
1597516616 private /*static*/ boolean firstime;
1597616617 private /*static*/ cVector newView = new cVector();
1597716618 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"};
1597816621 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1597916622 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1598016623 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -15987,29 +16630,67 @@
1598716630 {
1598816631 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1598916632
16633
+ int usedsuf = 0;
16634
+
1599016635 for (int i = 0; i < suffixes.length; i++)
1599116636 {
15992
- String resourceName = basename + suffixes[i] + "." + suffix;
15993
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
15994
- mipmapped,
15995
- FileUtil.getFileSuffix(resourceName));
15996
- if (data == null)
16637
+ String[] suffixe = suffixes;
16638
+ String[] fallback = suffixes2;
16639
+ String[] fallfallback = suffixes3;
16640
+
16641
+ for (int c=usedsuf; --c>=0;)
1599716642 {
15998
- throw new IOException("Unable to load texture " + resourceName);
16643
+// String[] temp = suffixe;
16644
+// suffixe = fallback;
16645
+// fallback = fallfallback;
16646
+// fallfallback = temp;
1599916647 }
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
+
1600016676 //System.out.println("Target = " + targets[i]);
1600116677 cubemap.updateImage(data, targets[i]);
1600216678 }
1600316679
1600416680 return cubemap;
1600516681 }
16682
+
1600616683 int bigsphere = -1;
1600716684
1600816685 float BGcolor = 0.5f;
1600916686
16010
- private void DrawSkyBox(GL gl)
16687
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16688
+
16689
+ private void DrawSkyBox(GL gl, float ratio)
1601116690 {
16012
- if (envyoff || cubemap == null)
16691
+ if (//envyoff ||
16692
+ WIREFRAME ||
16693
+ cubemap == null)
1601316694 {
1601416695 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1601516696 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16024,7 +16705,17 @@
1602416705 // Compensates for ExaminerViewer's modification of modelview matrix
1602516706 gl.glMatrixMode(GL.GL_MODELVIEW);
1602616707 gl.glLoadIdentity();
16708
+ gl.glScalef(1,ratio,1);
1602716709
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
+
1602816719 //gl.glActiveTexture(GL.GL_TEXTURE1);
1602916720 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1603016721
....@@ -16056,6 +16747,7 @@
1605616747 {
1605716748 gl.glScalef(1.0f, -1.0f, 1.0f);
1605816749 }
16750
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1605916751 gl.glMultMatrixd(viewrot_1, 0);
1606016752 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1606116753 //viewer.updateInverseRotation(gl);
....@@ -16196,16 +16888,16 @@
1619616888 cStatic.objectstack[materialdepth++] = checker;
1619716889 //System.out.println("material " + material);
1619816890 //Applet3D.tracein(this, selected);
16199
- vector2buffer = checker.projectedVertices;
16891
+ //vector2buffer = checker.projectedVertices;
1620016892
1620116893 //checker.GetMaterial().Draw(this, false); // true);
16202
- DrawMaterial(checker.GetMaterial(), false); // true);
16894
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1620316895
1620416896 materialdepth -= 1;
1620516897 if (materialdepth > 0)
1620616898 {
16207
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16208
- 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);
1620916901 }
1621016902 //checker.GetMaterial().opacity = 1f;
1621116903 ////checker.GetMaterial().ambient = 1f;
....@@ -16291,6 +16983,14 @@
1629116983 }
1629216984 }
1629316985
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
+
1629416994 class SelectBuffer implements GLEventListener
1629516995 {
1629616996
....@@ -16306,7 +17006,7 @@
1630617006 //new Exception().printStackTrace();
1630717007 System.out.println("select buffer init");
1630817008 // Use debug pipeline
16309
- drawable.setGL(new DebugGL(drawable.getGL()));
17009
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1631017010
1631117011 GL gl = drawable.getGL();
1631217012
....@@ -16370,6 +17070,17 @@
1637017070
1637117071 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1637217072
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
+
1637317084 //int tmp = selection_view;
1637417085 //selection_view = -1;
1637517086 int temp = DrawMode();
....@@ -16381,6 +17092,17 @@
1638117092 // temp = DEFAULT; // patch for selection debug
1638217093 Globals.drawMode = temp; // WARNING
1638317094
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
+
1638417106 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1638517107
1638617108 // trying different ways of getting the depth info over
....@@ -16428,6 +17150,8 @@
1642817150 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1642917151 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1643017152 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
17153
+
17154
+ CreateSelectedPoint();
1643117155
1643217156 // Will fit the mesh !!!
1643317157 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16482,29 +17206,31 @@
1648217206 }
1648317207
1648417208 if (!movingcamera && !PAINTMODE)
16485
- object.editWindow.ScreenFitPoint(); // fev 2014
17209
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1648617210
16487
- 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)
1648817212 {
16489
- 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);
1649017214
16491
- Object3D group = new Object3D("inst" + paintcount++);
17215
+ if (object.GetWindow().copy.selection.Size() > 0)
17216
+ {
17217
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1649217218
16493
- group.CreateMaterial(); // use a void leaf to select instances
16494
-
16495
- group.add(paintobj); // link
16496
-
16497
- object.editWindow.SnapObject(group);
16498
-
16499
- Object3D folder = object.editWindow.copy;
16500
-
16501
- if (object.editWindow.copy.selection.Size() > 0)
16502
- folder = object.editWindow.copy.selection.elementAt(0);
16503
-
16504
- folder.add(group);
16505
-
16506
- object.editWindow.ResetModel();
16507
- 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
+ }
1650817234 }
1650917235 else
1651017236 paintcount = 0;
....@@ -16543,6 +17269,11 @@
1654317269 //System.out.println("objects[color] = " + objects[color]);
1654417270 //objects[color].Select();
1654517271 indexcount = 0;
17272
+ ObjEditor window = object.GetWindow();
17273
+ if (window != null && deselect)
17274
+ {
17275
+ window.Select(null, deselect, true);
17276
+ }
1654617277 object.Select(color, deselect);
1654717278 }
1654817279
....@@ -16821,10 +17552,14 @@
1682117552 gl.glFlush();
1682217553
1682317554 /**/
16824
- 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);
1682517556
16826
- float[] pixels = occlusionsizebuffer.array();
17557
+ float[] depths = occlusiondepthbuffer.array();
1682717558
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
+
1682817563 double r = 0, g = 0, b = 0;
1682917564
1683017565 double count = 0;
....@@ -16835,7 +17570,7 @@
1683517570
1683617571 double FACTOR = 1;
1683717572
16838
- for (int i = 0; i < pixels.length; i++)
17573
+ for (int i = 0; i < depths.length; i++)
1683917574 {
1684017575 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1684117576 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -16918,7 +17653,7 @@
1691817653
1691917654 double scale = ray.z; // 1; // cos
1692017655
16921
- float depth = pixels[newindex];
17656
+ float depth = depths[newindex];
1692217657
1692317658 /*
1692417659 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -17068,23 +17803,15 @@
1706817803 int AAbuffersize = 0;
1706917804
1707017805 //double[] selectedpoint = new double[3];
17071
- static Superellipsoid selectedpoint = new Superellipsoid();
17806
+ static Superellipsoid selectedpoint;
1707217807 static Sphere previousselectedpoint = null;
17073
- static Sphere debugpointG = new Sphere();
17074
- static Sphere debugpointP = new Sphere();
17075
- static Sphere debugpointC = new Sphere();
17076
- static Sphere debugpointR = new Sphere();
17808
+ static Sphere debugpointG;
17809
+ static Sphere debugpointP;
17810
+ static Sphere debugpointC;
17811
+ static Sphere debugpointR;
1707717812
1707817813 static Sphere debugpoints[] = new Sphere[8];
1707917814
17080
- static
17081
- {
17082
- for (int i=0; i<8; i++)
17083
- {
17084
- debugpoints[i] = new Sphere();
17085
- }
17086
- }
17087
-
1708817815 static void InitPoints(float radius)
1708917816 {
1709017817 for (int i=0; i<8; i++)
....@@ -17123,11 +17850,14 @@
1712317850 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1712417851 static IntBuffer bigAAbuffer;
1712517852 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
17126
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17853
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1712717854 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1712817855 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1712917856 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17130
- 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
+
1713117861 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1713217862 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1713317863 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();