Normand Briere
2019-08-23 60cec91731a350fe67e9b5ffe7a00d70e9026314
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 {
....@@ -44,6 +48,39 @@
4448 static boolean ABORTED = false;
4549
4650 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
+ }
4784
4885 /*static*/ private boolean CULLFACE = false; // true;
4986 /*static*/ boolean NEAREST = false; // true;
....@@ -60,7 +97,7 @@
6097 //boolean REDUCETEXTURE = true;
6198 boolean CACHETEXTURE = true;
6299 boolean CLEANCACHE = false; // true;
63
- boolean MIPMAP = false; // true;
100
+ boolean MIPMAP = false; // true; // never works...
64101 boolean COMPRESSTEXTURE = false;
65102 boolean KOMPACTTEXTURE = false; // true;
66103 boolean RESIZETEXTURE = false;
....@@ -73,7 +110,11 @@
73110 //private Mat4f spotlightTransform = new Mat4f();
74111 //private Mat4f spotlightInverseTransform = new Mat4f();
75112 static GLContext glcontext = null;
76
- /*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;
116
+ boolean transformMode;
117
+
77118 boolean reverseUP = false;
78119 static boolean frozen = false;
79120 boolean enablebackspace = false; // patch for back buffer refresh
....@@ -127,7 +168,7 @@
127168
128169
129170 // OPTIONS
130
- boolean Skinshader = true;
171
+ boolean Skinshader = false; // true;
131172 boolean cameraLight = false;
132173 boolean UVdebug = false;
133174 boolean Udebug = false;
....@@ -136,7 +177,7 @@
136177 static boolean doublesided = false; // true; // reversed normals are awful for conformance
137178 boolean anisotropy = true;
138179 boolean softshadow = true; // slower but better false;
139
- boolean opacityhalo = false;
180
+ boolean opacityhalo = false; // reverse the halo effect (e.g. glass)
140181
141182 boolean macromode = false;
142183
....@@ -150,6 +191,19 @@
150191 }
151192
152193 private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
194
+
195
+ public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException
196
+ {
197
+ try
198
+ {
199
+ return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
200
+ } catch (IOException e)
201
+ {
202
+ System.out.println("NAME = " + name);
203
+ e.printStackTrace(); // throw new RuntimeException(e);
204
+ return null;
205
+ }
206
+ }
153207
154208 void SetAsGLRenderer(boolean b)
155209 {
....@@ -169,7 +223,8 @@
169223
170224 SetCamera(cam);
171225
172
- SetLight(new Camera(new cVector(10, 10, -20)));
226
+ // Warning: not used.
227
+ SetLight(new Camera(new cVector(15, 10, -20)));
173228
174229 object = o;
175230
....@@ -335,14 +390,28 @@
335390 display.options1[2] = material.shadowbias;
336391 display.options1[3] = material.aniso;
337392 display.options1[4] = material.anisoV;
393
+// System.out.println("display.options1[0] " + display.options1[0]);
394
+// System.out.println("display.options1[1] " + display.options1[1]);
395
+// System.out.println("display.options1[2] " + display.options1[2]);
396
+// System.out.println("display.options1[3] " + display.options1[3]);
397
+// System.out.println("display.options1[4] " + display.options1[4]);
338398 display.options2[0] = material.opacity;
339399 display.options2[1] = material.diffuse;
340400 display.options2[2] = material.factor;
401
+// System.out.println("display.options2[0] " + display.options2[0]);
402
+// System.out.println("display.options2[1] " + display.options2[1]);
403
+// System.out.println("display.options2[2] " + display.options2[2]);
341404
342405 cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
406
+// System.out.println("display.options3[0] " + display.options3[0]);
407
+// System.out.println("display.options3[1] " + display.options3[1]);
408
+// System.out.println("display.options3[2] " + display.options3[2]);
343409 display.options4[0] = material.cameralight/0.2f;
344410 display.options4[1] = material.subsurface;
345411 display.options4[2] = material.sheen;
412
+// System.out.println("display.options4[0] " + display.options4[0]);
413
+// System.out.println("display.options4[1] " + display.options4[1]);
414
+// System.out.println("display.options4[2] " + display.options4[2]);
346415
347416 // if (display.CURRENTANTIALIAS > 0)
348417 // display.options3[3] /= 4;
....@@ -473,7 +542,8 @@
473542 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
474543 LA.vecCross(obj.v0, obj.v1, obj.v2);
475544 LA.vecNormalize(obj.v2);
476
- gl.glNormal3f((float) obj.v2.x, (float) obj.v2.y, (float) obj.v2.z);
545
+
546
+ SetGLNormal(gl, (float) obj.v2.x, (float) obj.v2.y, (float) obj.v2.z);
477547 }
478548
479549 // P
....@@ -495,7 +565,7 @@
495565 y += ny * obj.NORMALPUSH;
496566 z += nz * obj.NORMALPUSH;
497567
498
- gl.glNormal3f(nx, ny, nz);
568
+ SetGLNormal(gl, nx, ny, nz);
499569 }
500570 gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
501571 SetColor(obj, pv);
....@@ -527,7 +597,7 @@
527597 y += ny * obj.NORMALPUSH;
528598 z += nz * obj.NORMALPUSH;
529599
530
- gl.glNormal3f(nx, ny, nz);
600
+ SetGLNormal(gl, nx, ny, nz);
531601 }
532602 //System.out.println("vertexq = " + qv.s + ", " + qv.t);
533603 // boolean locked = false;
....@@ -575,7 +645,7 @@
575645 y += ny * obj.NORMALPUSH;
576646 z += nz * obj.NORMALPUSH;
577647
578
- gl.glNormal3f(nx, ny, nz);
648
+ SetGLNormal(gl, nx, ny, nz);
579649 }
580650
581651 // if ((dot&4) == 0)
....@@ -811,7 +881,7 @@
811881 //// tris.postdraw(this);
812882 }
813883
814
- static Camera localcamera = new Camera();
884
+ static Camera localAOcamera = new Camera();
815885 static cVector from = new cVector();
816886 static cVector to = new cVector();
817887
....@@ -820,7 +890,7 @@
820890 CameraPane cp = this;
821891
822892 Camera keep = cp.RenderCamera();
823
- cp.renderCamera = localcamera;
893
+ cp.renderCamera = localAOcamera;
824894
825895 if (br.trimmed)
826896 {
....@@ -838,7 +908,7 @@
838908 br.positions[i3 + 2] + br.normals[i3 + 2]);
839909 LA.xformPos(from, transform, from);
840910 LA.xformPos(to, transform, to); // RIGID ONLY
841
- localcamera.setAim(from, to);
911
+ localAOcamera.setAim(from, to);
842912
843913 CameraPane.occlusionbuffer.display();
844914
....@@ -872,7 +942,7 @@
872942 to.set(v.x+v.norm.x, v.y+v.norm.y, v.z+v.norm.z);
873943 LA.xformPos(from, transform, from);
874944 LA.xformPos(to, transform, to); // RIGID ONLY
875
- localcamera.setAim(from, to);
945
+ localAOcamera.setAim(from, to);
876946
877947 CameraPane.occlusionbuffer.display();
878948
....@@ -1181,10 +1251,10 @@
11811251 {
11821252 if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
11831253 {
1184
- gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1254
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
11851255 } else
11861256 {
1187
- gl.glNormal3f(0, 0, 1);
1257
+ SetGLNormal(gl, 0, 0, 1);
11881258 }
11891259
11901260 if (c != null)
....@@ -1208,10 +1278,10 @@
12081278 {
12091279 if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
12101280 {
1211
- gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1281
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
12121282 } else
12131283 {
1214
- gl.glNormal3f(0, 0, 1);
1284
+ SetGLNormal(gl, 0, 0, 1);
12151285 }
12161286 if (c != null)
12171287 {
....@@ -1236,10 +1306,10 @@
12361306 {
12371307 if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
12381308 {
1239
- gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1309
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
12401310 } else
12411311 {
1242
- gl.glNormal3f(0, 0, 1);
1312
+ SetGLNormal(gl, 0, 0, 1);
12431313 }
12441314 if (c != null)
12451315 {
....@@ -1421,7 +1491,7 @@
14211491 {
14221492 if (!selectmode)
14231493 {
1424
- gl.glNormal3f((float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
1494
+ SetGLNormal(gl, (float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
14251495 gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
14261496
14271497 if (flipV)
....@@ -1433,6 +1503,8 @@
14331503 gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
14341504 }
14351505
1506
+ float[] colorV = new float[4];
1507
+
14361508 void SetColor(Object3D obj, Vertex p0)
14371509 {
14381510 CameraPane display = this;
....@@ -1500,8 +1572,6 @@
15001572 {
15011573 return;
15021574 }
1503
-
1504
- float[] colorV = new float[3];
15051575
15061576 if (false) // marked)
15071577 {
....@@ -1750,7 +1820,7 @@
17501820
17511821 display.modelParams7[0] = 0;
17521822 display.modelParams7[1] = 1000;
1753
- display.modelParams7[2] = 0;
1823
+ display.modelParams7[2] = material.parallax;
17541824 display.modelParams7[3] = 0;
17551825
17561826 //display.modelParams6[0] = 100; // criss de bug de bump
....@@ -1983,9 +2053,9 @@
19832053 switch(viewcode)
19842054 {
19852055 case 0: return "main";
1986
- case 1: return "one";
1987
- case 2: return "two";
1988
- case 3: return "three";
2056
+ case 1: return "Red";
2057
+ case 2: return "Green";
2058
+ case 3: return "Blue";
19892059 case 4: return "light";
19902060 }
19912061
....@@ -2051,7 +2121,7 @@
20512121 //System.err.println("Oeil on");
20522122 OEIL = true;
20532123 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2054
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2124
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
20552125 //pingthread.StepToTarget(true);
20562126 }
20572127
....@@ -2284,10 +2354,17 @@
22842354 HANDLES ^= true;
22852355 }
22862356
2357
+ Object3D paintFolder;
2358
+
22872359 void TogglePaint()
22882360 {
22892361 PAINTMODE ^= true;
22902362 paintcount = 0;
2363
+
2364
+ if (PAINTMODE)
2365
+ {
2366
+ paintFolder = GetFolder();
2367
+ }
22912368 }
22922369
22932370 void SwapCamera(int a, int b)
....@@ -2384,6 +2461,33 @@
23842461 return currentGL;
23852462 }
23862463
2464
+ static private BufferedImage CreateBim(TextureData texturedata)
2465
+ {
2466
+ Grafreed.Assert(texturedata != null);
2467
+
2468
+ int width = texturedata.getWidth();
2469
+ int height = texturedata.getHeight();
2470
+
2471
+ Buffer buffer = texturedata.getBuffer();
2472
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2473
+
2474
+ byte[] bytes = bytebuf.array();
2475
+
2476
+ return CreateBim(bytes, width, height);
2477
+ }
2478
+
2479
+ private void SetGLNormal(javax.media.opengl.GL gl, float nx, float ny, float nz)
2480
+ {
2481
+ gl.glNormal3f(nx, ny, nz);
2482
+
2483
+ if (ny > 0.9 || ny < -0.9)
2484
+ // Ground or ceiling
2485
+ gl.glVertexAttrib3f(4, 1, 0, 0);
2486
+ else
2487
+ // Walls
2488
+ gl.glVertexAttrib3f(4, 0, 1, 0);
2489
+ }
2490
+
23872491 /**/
23882492 class CacheTexture
23892493 {
....@@ -2392,28 +2496,31 @@
23922496
23932497 int resolution;
23942498
2395
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2499
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
23962500 {
2397
- texture = tex;
2501
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2502
+ texturedata = texdata;
23982503 resolution = res;
23992504 }
24002505 }
24012506 /**/
24022507
24032508 // TEXTURE static Texture texture;
2404
- static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures
2405
- = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>();
2406
- static public java.util.Hashtable<String, String> usedtextures = new java.util.Hashtable<String, String>();
2509
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2510
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2511
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2512
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2513
+
24072514 int pigmentdepth = 0;
24082515 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
24092516 int bumpdepth = 0;
24102517 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
24112518 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
24122519 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2413
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2520
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
24142521 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
24152522
2416
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2523
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
24172524 {
24182525 TextureData texturedata = null;
24192526
....@@ -2423,7 +2530,7 @@
24232530 com.sun.opengl.util.texture.TextureIO.newTextureData(
24242531 getClass().getClassLoader().getResourceAsStream(name),
24252532 true,
2426
- com.sun.opengl.util.texture.TextureIO.PNG);
2533
+ GetFormat(name)); // com.sun.opengl.util.texture.TextureIO.PNG);
24272534 } catch (java.io.IOException e)
24282535 {
24292536 throw new javax.media.opengl.GLException(e);
....@@ -2432,13 +2539,34 @@
24322539 if (bump)
24332540 texturedata = ConvertBump(texturedata, false);
24342541
2435
- com.sun.opengl.util.texture.Texture texture =
2436
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2542
+// com.sun.opengl.util.texture.Texture texture =
2543
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
24372544
2438
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2439
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
2545
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2546
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
24402547
2441
- return texture;
2548
+ return texturedata;
2549
+ }
2550
+
2551
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2552
+ {
2553
+ TextureData texturedata = null;
2554
+
2555
+ try
2556
+ {
2557
+ texturedata =
2558
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2559
+ bim,
2560
+ true);
2561
+ } catch (Exception e)
2562
+ {
2563
+ throw new javax.media.opengl.GLException(e);
2564
+ }
2565
+
2566
+ if (bump)
2567
+ texturedata = ConvertBump(texturedata, false);
2568
+
2569
+ return texturedata;
24422570 }
24432571
24442572 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3511,6 +3639,8 @@
35113639
35123640 System.out.println("LOADING TEXTURE : " + name);
35133641
3642
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3643
+
35143644 //
35153645 if (false) // compressbit > 0)
35163646 {
....@@ -7909,7 +8039,7 @@
79098039 String pigment = Object3D.GetPigment(tex);
79108040 String bump = Object3D.GetBump(tex);
79118041
7912
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8042
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79138043 {
79148044 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79158045 // System.out.println("; bump = " + bump);
....@@ -7924,8 +8054,8 @@
79248054 pigment = null;
79258055 }
79268056
7927
- ReleaseTexture(bump, true);
7928
- ReleaseTexture(pigment, false);
8057
+ ReleaseTexture(tex, true);
8058
+ ReleaseTexture(tex, false);
79298059 }
79308060
79318061 public void ReleasePigmentTexture(cTexture tex) // INTERFACE
....@@ -7943,7 +8073,7 @@
79438073
79448074 String pigment = Object3D.GetPigment(tex);
79458075
7946
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8076
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79478077 {
79488078 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79498079 // System.out.println("; bump = " + bump);
....@@ -7954,7 +8084,7 @@
79548084 pigment = null;
79558085 }
79568086
7957
- ReleaseTexture(pigment, false);
8087
+ ReleaseTexture(tex, false);
79588088 }
79598089
79608090 public void ReleaseBumpTexture(cTexture tex) // INTERFACE
....@@ -7972,7 +8102,7 @@
79728102
79738103 String bump = Object3D.GetBump(tex);
79748104
7975
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8105
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79768106 {
79778107 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79788108 // System.out.println("; bump = " + bump);
....@@ -7983,10 +8113,10 @@
79838113 bump = null;
79848114 }
79858115
7986
- ReleaseTexture(bump, true);
8116
+ ReleaseTexture(tex, true);
79878117 }
79888118
7989
- void ReleaseTexture(String tex, boolean bump)
8119
+ void ReleaseTexture(cTexture tex, boolean bump)
79908120 {
79918121 if (// DrawMode() != 0 || /*tex == null ||*/
79928122 ambientOcclusion ) // || !textureon)
....@@ -7997,7 +8127,7 @@
79978127 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
79988128
79998129 if (tex != null)
8000
- texture = textures.get(tex);
8130
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
80018131
80028132 // //assert( texture != null );
80038133 // if (texture == null)
....@@ -8091,47 +8221,50 @@
80918221
80928222 /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
80938223 {
8094
- if (// DrawMode() != 0 || /*tex == null ||*/
8095
- ambientOcclusion ) // || !textureon)
8096
- {
8097
- return; // false;
8098
- }
8099
-
8100
- if (tex == null)
8101
- {
8102
- BindTexture(null,false,resolution);
8103
- BindTexture(null,true,resolution);
8104
- return;
8105
- }
8224
+// if (// DrawMode() != 0 || /*tex == null ||*/
8225
+// ambientOcclusion ) // || !textureon)
8226
+// {
8227
+// return; // false;
8228
+// }
8229
+//
8230
+// if (tex == null)
8231
+// {
8232
+// BindTexture(null,false,resolution);
8233
+// BindTexture(null,true,resolution);
8234
+// return;
8235
+// }
8236
+//
8237
+// String pigment = Object3D.GetPigment(tex);
8238
+// String bump = Object3D.GetBump(tex);
8239
+//
8240
+// usedtextures.add(pigment);
8241
+// usedtextures.add(bump);
8242
+//
8243
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8244
+// {
8245
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8246
+// // System.out.println("; bump = " + bump);
8247
+// }
8248
+//
8249
+// if (bump.equals(""))
8250
+// {
8251
+// bump = null;
8252
+// }
8253
+// if (pigment.equals(""))
8254
+// {
8255
+// pigment = null;
8256
+// }
8257
+//
8258
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8259
+// BindTexture(pigment, false, resolution);
8260
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8261
+// BindTexture(bump, true, resolution);
8262
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8263
+//
8264
+// return; // true;
81068265
8107
- String pigment = Object3D.GetPigment(tex);
8108
- String bump = Object3D.GetBump(tex);
8109
-
8110
- usedtextures.put(pigment, pigment);
8111
- usedtextures.put(bump, bump);
8112
-
8113
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8114
- {
8115
- // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8116
- // System.out.println("; bump = " + bump);
8117
- }
8118
-
8119
- if (bump.equals(""))
8120
- {
8121
- bump = null;
8122
- }
8123
- if (pigment.equals(""))
8124
- {
8125
- pigment = null;
8126
- }
8127
-
8128
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8129
- BindTexture(pigment, false, resolution);
8130
- GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8131
- BindTexture(bump, true, resolution);
8132
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8133
-
8134
- return; // true;
8266
+ BindPigmentTexture(tex, resolution);
8267
+ BindBumpTexture(tex, resolution);
81358268 }
81368269
81378270 /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8150,9 +8283,9 @@
81508283
81518284 String pigment = Object3D.GetPigment(tex);
81528285
8153
- usedtextures.put(pigment, pigment);
8286
+ usedtextures.add(tex);
81548287
8155
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8288
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
81568289 {
81578290 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
81588291 // System.out.println("; bump = " + bump);
....@@ -8164,7 +8297,7 @@
81648297 }
81658298
81668299 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8167
- BindTexture(pigment, false, resolution);
8300
+ BindTexture(tex, false, resolution);
81688301 }
81698302
81708303 /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8183,9 +8316,9 @@
81838316
81848317 String bump = Object3D.GetBump(tex);
81858318
8186
- usedtextures.put(bump, bump);
8319
+ usedtextures.add(tex);
81878320
8188
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8321
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
81898322 {
81908323 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
81918324 // System.out.println("; bump = " + bump);
....@@ -8197,7 +8330,7 @@
81978330 }
81988331
81998332 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8200
- BindTexture(bump, true, resolution);
8333
+ BindTexture(tex, true, resolution);
82018334 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
82028335 }
82038336
....@@ -8221,13 +8354,19 @@
82218354 return fileExists;
82228355 }
82238356
8224
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception
8357
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
82258358 {
8226
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8359
+ CacheTexture texturecache = null;
82278360
82288361 if (tex != null)
82298362 {
8230
- String texname = tex;
8363
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8364
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
8365
+
8366
+ if (texname.equals("") && texdata == null)
8367
+ {
8368
+ return null;
8369
+ }
82318370
82328371 String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
82338372
....@@ -8237,19 +8376,46 @@
82378376 // else
82388377 // if (!texname.startsWith("/"))
82398378 // texname = "/Users/nbriere/Textures/" + texname;
8240
- if (!FileExists(tex))
8379
+ if (!FileExists(texname) && !texname.startsWith("@"))
82418380 {
82428381 texname = fallbackTextureName;
82438382 }
82448383
82458384 if (CACHETEXTURE)
8246
- texture = textures.get(texname); // TEXTURE CACHE
8247
-
8248
- TextureData texturedata = null;
8249
-
8250
- if (texture == null || texture.resolution < resolution)
82518385 {
8252
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8386
+ if (texdata == null)
8387
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8388
+ else
8389
+ texturecache = bimtextures.get(texdata);
8390
+ }
8391
+
8392
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8393
+ {
8394
+ TextureData texturedata = null;
8395
+
8396
+ if (texdata != null && textureon)
8397
+ {
8398
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8399
+
8400
+ try
8401
+ {
8402
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8403
+ }
8404
+ catch (Exception e)
8405
+ {
8406
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8407
+ }
8408
+
8409
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8410
+ bimtextures.put(texdata, texturecache);
8411
+
8412
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8413
+
8414
+ //Object bim2 = CreateBim(texturecache.texturedata);
8415
+ //bim2 = bim;
8416
+ }
8417
+ else
8418
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
82538419 {
82548420 assert(!bump);
82558421 // if (bump)
....@@ -8260,19 +8426,23 @@
82608426 // }
82618427 // else
82628428 // {
8263
- texture = textures.get(tex);
8264
- if (texture == null)
8429
+ // texturecache = textures.get(texname); // suspicious
8430
+ if (texturecache == null)
82658431 {
8266
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8432
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
82678433 }
8434
+ else
8435
+ new Exception().printStackTrace();
82688436 // }
82698437 } else
8270
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8438
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
82718439 {
82728440 assert(bump);
8273
- texture = textures.get(tex);
8274
- if (texture == null)
8275
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8441
+ // texturecache = textures.get(texname); // suspicious
8442
+ if (texturecache == null)
8443
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8444
+ else
8445
+ new Exception().printStackTrace();
82768446 } else
82778447 {
82788448 //if (tex.equals("IMMORTAL"))
....@@ -8280,11 +8450,22 @@
82808450 // texture = GetResourceTexture("default.png");
82818451 //} else
82828452 //{
8283
- if (tex.equals("WHITE_NOISE"))
8453
+ if (texname.endsWith("WHITE_NOISE"))
82848454 {
8285
- texture = textures.get(tex);
8286
- if (texture == null)
8287
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8455
+ // texturecache = textures.get(texname); // suspicious
8456
+ if (texturecache == null)
8457
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8458
+ else
8459
+ new Exception().printStackTrace();
8460
+ } else
8461
+ {
8462
+ if (texname.startsWith("@"))
8463
+ {
8464
+ // texturecache = textures.get(texname); // suspicious
8465
+ if (texturecache == null)
8466
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8467
+ else
8468
+ new Exception().printStackTrace();
82888469 } else
82898470 {
82908471 if (textureon)
....@@ -8343,19 +8524,20 @@
83438524 if (texturedata == null)
83448525 throw new Exception();
83458526
8346
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8527
+ texturecache = new CacheTexture(texturedata,resolution);
83478528 //texture = GetTexture(tex, bump);
83488529 }
8530
+ }
83498531 }
83508532 //}
83518533 }
83528534
8353
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8535
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
83548536 {
83558537 //return false;
83568538
83578539 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8358
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8540
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
83598541 {
83608542 // String ext = "_highres";
83618543 // if (REDUCETEXTURE)
....@@ -8372,52 +8554,17 @@
83728554 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
83738555 if (!cachefile.exists())
83748556 {
8375
- // cache to disk
8376
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
8377
- //buffers[0].
8378
-
8379
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
8380
- int[] pixels = new int[bytebuf.capacity()/3];
8381
-
8382
- // squared size heuristic...
8383
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8557
+ //if (texturedata.getWidth() == texturedata.getHeight())
83848558 {
8385
- for (int i=pixels.length; --i>=0;)
8386
- {
8387
- int i3 = i*3;
8388
- pixels[i] = 0xFF;
8389
- pixels[i] <<= 8;
8390
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
8391
- pixels[i] <<= 8;
8392
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
8393
- pixels[i] <<= 8;
8394
- pixels[i] |= bytebuf.get(i3) & 0xFF;
8395
- }
8396
-
8397
- /*
8398
- int r=0,g=0,b=0,a=0;
8399
- for (int i=0; i<width; i++)
8400
- for (int j=0; j<height; j++)
8401
- {
8402
- int index = j*width+i;
8403
- int p = pixels[index];
8404
- a = ((p>>24) & 0xFF);
8405
- r = ((p>>16) & 0xFF);
8406
- g = ((p>>8) & 0xFF);
8407
- b = (p & 0xFF);
8408
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
8409
- }
8410
- /**/
8411
- int width = (int)Math.sqrt(pixels.length); // squared
8412
- int height = width;
8413
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
8414
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8559
+ BufferedImage rendImage = CreateBim(texturedata);
8560
+
84158561 ImageWriter writer = null;
84168562 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
84178563 if (iter.hasNext()) {
84188564 writer = (ImageWriter)iter.next();
84198565 }
8420
- float compressionQuality = 0.9f;
8566
+
8567
+ float compressionQuality = 0.85f;
84218568 try
84228569 {
84238570 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8434,18 +8581,20 @@
84348581 }
84358582 }
84368583 }
8437
-
8584
+
8585
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8586
+
84388587 //System.out.println("Texture = " + tex);
8439
- if (textures.containsKey(texname))
8588
+ if (textures.containsKey(tex))
84408589 {
8441
- CacheTexture thetex = textures.get(texname);
8590
+ CacheTexture thetex = textures.get(tex);
84428591 thetex.texture.disable();
84438592 thetex.texture.dispose();
8444
- textures.remove(texname);
8593
+ textures.remove(tex);
84458594 }
84468595
8447
- texture.texturedata = texturedata;
8448
- textures.put(texname, texture);
8596
+ //texture.texturedata = texturedata;
8597
+ textures.put(tex, texturecache);
84498598
84508599 // newtex = true;
84518600 }
....@@ -8461,10 +8610,44 @@
84618610 }
84628611 }
84638612
8464
- return texture;
8613
+ return texturecache;
84658614 }
84668615
8467
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution) throws Exception
8616
+ static void EmbedTextures(cTexture tex)
8617
+ {
8618
+ if (tex.pigmentdata == null)
8619
+ {
8620
+ //String texname = Object3D.GetPigment(tex);
8621
+
8622
+ CacheTexture texturecache = texturepigment.get(tex);
8623
+
8624
+ if (texturecache != null)
8625
+ {
8626
+ tex.pw = texturecache.texturedata.getWidth();
8627
+ tex.ph = texturecache.texturedata.getHeight();
8628
+ tex.pigmentdata = //CompressJPEG(CreateBim
8629
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8630
+ ;
8631
+ //, tex.pw, tex.ph), 0.5f);
8632
+ }
8633
+ }
8634
+
8635
+ if (tex.bumpdata == null)
8636
+ {
8637
+ //String texname = Object3D.GetBump(tex);
8638
+
8639
+ CacheTexture texturecache = texturebump.get(tex);
8640
+
8641
+ if (texturecache != null)
8642
+ {
8643
+ tex.bw = texturecache.texturedata.getWidth();
8644
+ tex.bh = texturecache.texturedata.getHeight();
8645
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8646
+ }
8647
+ }
8648
+ }
8649
+
8650
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
84688651 {
84698652 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
84708653
....@@ -8482,21 +8665,21 @@
84828665 return texture!=null?texture.texture:null;
84838666 }
84848667
8485
- public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution) throws Exception
8668
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
84868669 {
84878670 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
84888671
84898672 return texture!=null?texture.texturedata:null;
84908673 }
84918674
8492
- boolean BindTexture(String tex, boolean bump, int resolution) throws Exception
8675
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
84938676 {
84948677 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
84958678 {
84968679 return false;
84978680 }
84988681
8499
- boolean newtex = false;
8682
+ //boolean newtex = false;
85008683
85018684 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
85028685
....@@ -8528,9 +8711,75 @@
85288711 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
85298712 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
85308713
8531
- return newtex;
8714
+ return true; // Warning: not used.
85328715 }
85338716
8717
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8718
+ {
8719
+ try
8720
+ {
8721
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8722
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8723
+ ImageWriter writer = writers.next();
8724
+
8725
+ ImageWriteParam param = writer.getDefaultWriteParam();
8726
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8727
+ param.setCompressionQuality(quality);
8728
+
8729
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8730
+ writer.setOutput(ios);
8731
+ writer.write(null, new IIOImage(image, null, null), param);
8732
+
8733
+ byte[] data = baos.toByteArray();
8734
+ writer.dispose();
8735
+ return data;
8736
+ }
8737
+ catch (Exception e)
8738
+ {
8739
+ e.printStackTrace();
8740
+ return null;
8741
+ }
8742
+ }
8743
+
8744
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8745
+ {
8746
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8747
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8748
+ ImageReader reader = writers.next();
8749
+
8750
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8751
+
8752
+ ImageReadParam param = reader.getDefaultReadParam();
8753
+ param.setDestination(bim);
8754
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8755
+
8756
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8757
+ reader.setInput(ios);
8758
+ BufferedImage bim2 = reader.read(0, param);
8759
+ reader.dispose();
8760
+
8761
+// WritableRaster raster = bim2.getRaster();
8762
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8763
+// byte[] bytes = data.getData();
8764
+//
8765
+// int[] pixels = new int[bytes.length/3];
8766
+// for (int i=pixels.length; --i>=0;)
8767
+// {
8768
+// int i3 = i*3;
8769
+// pixels[i] = 0xFF;
8770
+// pixels[i] <<= 8;
8771
+// pixels[i] |= bytes[i3+2] & 0xFF;
8772
+// pixels[i] <<= 8;
8773
+// pixels[i] |= bytes[i3+1] & 0xFF;
8774
+// pixels[i] <<= 8;
8775
+// pixels[i] |= bytes[i3] & 0xFF;
8776
+// }
8777
+//
8778
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8779
+
8780
+ return bim;
8781
+ }
8782
+
85348783 ShadowBuffer shadowPBuf;
85358784 AntialiasBuffer antialiasPBuf;
85368785 int MAXSTACK;
....@@ -8547,10 +8796,12 @@
85478796
85488797 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
85498798 MAXSTACK = temp[0];
8550
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8799
+ if (Globals.DEBUG)
8800
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
85518801 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
85528802 MAXSTACK = temp[0];
8553
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8803
+ if (Globals.DEBUG)
8804
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
85548805
85558806 // Use debug pipeline
85568807 //drawable.setGL(new DebugGL(gl)); //
....@@ -8558,7 +8809,8 @@
85588809 gl = drawable.getGL(); //
85598810
85608811 GL gl3 = getGL();
8561
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8812
+ if (Globals.DEBUG)
8813
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
85628814
85638815
85648816 //float pos[] = { 100, 100, 100, 0 };
....@@ -8723,7 +8975,7 @@
87238975
87248976 if (cubemap == null)
87258977 {
8726
- LoadEnvy(5);
8978
+ //LoadEnvy(1);
87278979 }
87288980
87298981 //cubemap.enable();
....@@ -8999,6 +9251,8 @@
89999251
90009252 void LoadEnvy(int which)
90019253 {
9254
+ assert(false);
9255
+
90029256 String name;
90039257 String ext;
90049258
....@@ -9010,37 +9264,58 @@
90109264 cubemap = null;
90119265 return;
90129266 case 1:
9013
- name = "cubemaps/box_";
9014
- ext = "png";
9267
+ name = "cubemaps/rgb/";
9268
+ ext = "jpg";
90159269 reverseUP = false;
90169270 break;
90179271 case 2:
9018
- name = "cubemaps/uffizi_";
9019
- ext = "png";
9020
- break; // reverseUP = true; break;
9272
+ name = "cubemaps/uffizi/";
9273
+ ext = "jpg";
9274
+ reverseUP = false;
9275
+ break;
90219276 case 3:
9022
- name = "cubemaps/CloudyHills_";
9023
- ext = "tga";
9277
+ name = "cubemaps/CloudyHills/";
9278
+ ext = "jpg";
90249279 reverseUP = false;
90259280 break;
90269281 case 4:
9027
- name = "cubemaps/cornell_";
9282
+ name = "cubemaps/cornell/";
90289283 ext = "png";
90299284 reverseUP = false;
90309285 break;
9286
+ case 5:
9287
+ name = "cubemaps/skycube/";
9288
+ ext = "jpg";
9289
+ reverseUP = false;
9290
+ break;
9291
+ case 6:
9292
+ name = "cubemaps/SaintLazarusChurch3/";
9293
+ ext = "jpg";
9294
+ reverseUP = false;
9295
+ break;
9296
+ case 7:
9297
+ name = "cubemaps/Sodermalmsallen/";
9298
+ ext = "jpg";
9299
+ reverseUP = false;
9300
+ break;
9301
+ case 8:
9302
+ name = "cubemaps/Sodermalmsallen2/";
9303
+ ext = "jpg";
9304
+ reverseUP = false;
9305
+ break;
9306
+ case 9:
9307
+ name = "cubemaps/UnionSquare/";
9308
+ ext = "jpg";
9309
+ reverseUP = false;
9310
+ break;
90319311 default:
9032
- name = "cubemaps/rgb_";
9033
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9312
+ name = "cubemaps/box/";
9313
+ ext = "png"; /*mipmap = true;*/
9314
+ reverseUP = false;
90349315 break;
90359316 }
9036
-
9037
- try
9038
- {
9039
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
9040
- } catch (IOException e)
9041
- {
9042
- throw new RuntimeException(e);
9043
- }
9317
+
9318
+ LoadSkybox(name, ext, mipmap);
90449319 }
90459320
90469321 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -9072,8 +9347,12 @@
90729347 static double[] model = new double[16];
90739348 double[] camera2light = new double[16];
90749349 double[] light2camera = new double[16];
9075
- int newenvy = -1;
9076
- boolean envyoff = true; // false;
9350
+
9351
+ //int newenvy = -1;
9352
+ //boolean envyoff = false;
9353
+
9354
+ String loadedskyboxname;
9355
+
90779356 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
90789357 //float[] light0 = { 0,0,0 };
90799358 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9374,13 +9653,13 @@
93749653 void ResetOptions()
93759654 {
93769655 options1[0] = 100;
9377
- options1[1] = 0.00001f;
9378
- options1[2] = 20;
9656
+ options1[1] = 0.025f;
9657
+ options1[2] = 0.01f;
93799658 options1[3] = 0;
93809659 options1[4] = 0;
93819660
93829661 options2[0] = 0;
9383
- options2[1] = 1;
9662
+ options2[1] = 0.75f;
93849663 options2[2] = 0;
93859664 options2[3] = 0;
93869665
....@@ -9491,7 +9770,7 @@
94919770
94929771 if (renderCamera != lightCamera)
94939772 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9494
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
9773
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
94959774
94969775 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
94979776
....@@ -9507,7 +9786,7 @@
95079786
95089787 if (renderCamera != lightCamera)
95099788 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9510
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
9789
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
95119790
95129791 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
95139792
....@@ -9553,10 +9832,12 @@
95539832 rati = 1 / rati;
95549833 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
95559834 }
9556
- assert (newenvy == -1);
9835
+
9836
+ //assert (newenvy == -1);
9837
+
95579838 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
95589839 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9559
- DrawSkyBox(gl);
9840
+ DrawSkyBox(gl, (float)rati);
95609841 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
95619842 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
95629843 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10422,9 +10703,18 @@
1042210703 static boolean init = false;
1042310704
1042410705 double[][] matrix = LA.newMatrix();
10706
+
10707
+ // This is to refresh the UI of the material panel.
10708
+ ObjEditor patchMaterial;
1042510709
1042610710 public void display(GLAutoDrawable drawable)
1042710711 {
10712
+ if (patchMaterial.patchMaterial)
10713
+ {
10714
+ patchMaterial.patchMaterial = false;
10715
+ patchMaterial.objectPanel.setSelectedIndex(1);
10716
+ }
10717
+
1042810718 if (Grafreed.savesound && Grafreed.hassound)
1042910719 {
1043010720 Grafreed.wav.save();
....@@ -10593,7 +10883,7 @@
1059310883
1059410884 if (wait)
1059510885 {
10596
- Sleep(500);
10886
+ Sleep(200); // blocks everything
1059710887
1059810888 wait = false;
1059910889 }
....@@ -10708,7 +10998,7 @@
1070810998 // if (parentcam != renderCamera) // not a light
1070910999 if (cam != lightCamera)
1071011000 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10711
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
11001
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1071211002
1071311003 for (int j = 0; j < 4; j++)
1071411004 {
....@@ -10723,7 +11013,7 @@
1072311013 // if (parentcam != renderCamera) // not a light
1072411014 if (cam != lightCamera)
1072511015 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10726
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
11016
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1072711017
1072811018 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1072911019
....@@ -10809,13 +11099,43 @@
1080911099 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1081011100 }
1081111101
10812
- if (newenvy > -1)
11102
+// if (newenvy > -1)
11103
+// {
11104
+// LoadEnvy(newenvy);
11105
+// }
11106
+//
11107
+// newenvy = -1;
11108
+
11109
+ if (transformMode) // object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
1081311110 {
10814
- LoadEnvy(newenvy);
11111
+ if (cubemaprgb == null)
11112
+ {
11113
+ cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb2" + "/", "jpg", false);
11114
+ }
11115
+
11116
+ cubemap = cubemaprgb;
1081511117 }
10816
-
10817
- newenvy = -1;
10818
-
11118
+ else
11119
+ {
11120
+ if (object.skyboxname != null)
11121
+ {
11122
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11123
+ {
11124
+ if (cubemap != null && cubemap != cubemaprgb)
11125
+ cubemap.dispose();
11126
+ cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11127
+ loadedskyboxname = object.skyboxname;
11128
+ }
11129
+ }
11130
+ else
11131
+ {
11132
+ cubemapcustom = null;
11133
+ loadedskyboxname = null;
11134
+ }
11135
+
11136
+ cubemap = cubemapcustom;
11137
+ }
11138
+
1081911139 ratio = ((double) getWidth()) / getHeight();
1082011140 //System.out.println("ratio = " + ratio);
1082111141
....@@ -10831,7 +11151,7 @@
1083111151
1083211152 if (!IsFrozen() && !ambientOcclusion)
1083311153 {
10834
- DrawSkyBox(gl);
11154
+ DrawSkyBox(gl, (float)ratio);
1083511155 }
1083611156
1083711157 //if (selection_view == -1)
....@@ -11014,9 +11334,9 @@
1101411334
1101511335 gl.glMatrixMode(GL.GL_MODELVIEW);
1101611336
11017
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11018
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
11019
-//gl.glEnable(gl.GL_MULTISAMPLE);
11337
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11338
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11339
+gl.glEnable(gl.GL_MULTISAMPLE);
1102011340 } else
1102111341 {
1102211342 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -11027,7 +11347,7 @@
1102711347 //System.out.println("BLENDING ON");
1102811348 gl.glEnable(GL.GL_BLEND);
1102911349 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
11030
-
11350
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1103111351 gl.glMatrixMode(gl.GL_PROJECTION);
1103211352 gl.glLoadIdentity();
1103311353
....@@ -11117,7 +11437,7 @@
1111711437
1111811438 // if (cam != lightCamera)
1111911439 //for (int count = parentcam.GetTransformCount(); --count>=0;)
11120
- LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
11440
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1112111441 }
1112211442
1112311443 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -11276,7 +11596,7 @@
1127611596 }
1127711597 }
1127811598
11279
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11599
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1128011600 {
1128111601 //gl.glDepthFunc(GL.GL_LEQUAL);
1128211602 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11284,24 +11604,21 @@
1128411604
1128511605 boolean texon = textureon;
1128611606
11287
- if (RENDERPROGRAM > 0)
11288
- {
11289
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11290
- textureon = false;
11291
- }
11607
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11608
+ textureon = false;
11609
+
1129211610 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1129311611 //System.out.println("ALLO");
1129411612 gl.glColorMask(false, false, false, false);
1129511613 DrawObject(gl);
11296
- if (RENDERPROGRAM > 0)
11297
- {
11298
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11299
- textureon = texon;
11300
- }
11614
+
11615
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11616
+ textureon = texon;
11617
+
1130111618 gl.glColorMask(true, true, true, true);
1130211619
1130311620 gl.glDepthFunc(GL.GL_EQUAL);
11304
- //gl.glDepthMask(false);
11621
+ gl.glDepthMask(false);
1130511622 }
1130611623
1130711624 if (false) // DrawMode() == SHADOW)
....@@ -11513,7 +11830,7 @@
1151311830 if ((TRACK || SHADOWTRACK) || zoomonce)
1151411831 {
1151511832 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11516
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11833
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1151711834 pingthread.StepToTarget(true); // true);
1151811835 // zoomonce = false;
1151911836 }
....@@ -11641,20 +11958,32 @@
1164111958 ReleaseTextures(DEFAULT_TEXTURES);
1164211959
1164311960 if (CLEANCACHE)
11644
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11961
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1164511962 {
11646
- String tex = e.nextElement();
11963
+ cTexture tex = e.nextElement();
1164711964
1164811965 // System.out.println("Texture --------- " + tex);
1164911966
11650
- if (tex.equals("WHITE_NOISE"))
11967
+ if (tex.equals("WHITE_NOISE:"))
1165111968 continue;
1165211969
11653
- if (!usedtextures.containsKey(tex))
11970
+ if (!usedtextures.contains(tex))
1165411971 {
11972
+ CacheTexture gettex = texturepigment.get(tex);
1165511973 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11656
- textures.get(tex).texture.dispose();
11657
- textures.remove(tex);
11974
+ if (gettex != null)
11975
+ {
11976
+ gettex.texture.dispose();
11977
+ texturepigment.remove(tex);
11978
+ }
11979
+
11980
+ gettex = texturebump.get(tex);
11981
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11982
+ if (gettex != null)
11983
+ {
11984
+ gettex.texture.dispose();
11985
+ texturebump.remove(tex);
11986
+ }
1165811987 }
1165911988 }
1166011989 }
....@@ -12182,8 +12511,82 @@
1218212511
1218312512 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1218412513
12185
- String program =
12514
+ String programmin =
12515
+ // Min shader
1218612516 "!!ARBfp1.0\n" +
12517
+ "PARAM zero12t = { 0.0, 1.0, 2, 1.25 };" +
12518
+ "PARAM pow_2 = { 0.5, 0.25, 0.125, 0.0 };" +
12519
+ "PARAM pow2 = { 2, 4, 8, 0.0 };" +
12520
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12521
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12522
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12523
+ "PARAM light2cam0 = program.env[10];" +
12524
+ "PARAM light2cam1 = program.env[11];" +
12525
+ "PARAM light2cam2 = program.env[12];" +
12526
+ "TEMP temp;" +
12527
+ "TEMP light;" +
12528
+ "TEMP ndotl;" +
12529
+ "TEMP normal;" +
12530
+ "TEMP depth;" +
12531
+ "TEMP eye;" +
12532
+ "TEMP pos;" +
12533
+
12534
+ "MAD normal, fragment.color, zero12t.z, -zero12t.y;" +
12535
+ Normalize("normal") +
12536
+ "MOV light, state.light[0].position;" +
12537
+ "DP3 ndotl.x, light, normal;" +
12538
+ "MAX ndotl.x, ndotl.x, zero12t.x;" +
12539
+
12540
+ // shadow
12541
+ "MOV pos, fragment.texcoord[1];" +
12542
+ "MOV temp, pos;" +
12543
+ ShadowTextureFetch("depth", "temp", "1") +
12544
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12545
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12546
+
12547
+ // No shadow when out of frustum
12548
+ //"SGE temp.y, depth.z, zero123.y;" +
12549
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12550
+
12551
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12552
+
12553
+ // Backlit
12554
+ "MOV pos.w, zero12t.y;" + // one
12555
+ "DP4 eye.x, pos, light2cam0;" +
12556
+ "DP4 eye.y, pos, light2cam1;" +
12557
+ "DP4 eye.z, pos, light2cam2;" +
12558
+ Normalize("eye") +
12559
+
12560
+ "DP3 ndotl.y, -eye, normal;" +
12561
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12562
+ "POW ndotl.y, ndotl.y, pow2.x;" + // backlit
12563
+ "SUB ndotl.y, zero12t.y, ndotl.y;" + // 1 - y
12564
+ //"POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12565
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12566
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12567
+ "ADD ndotl.y, ndotl.y, one.x;" +
12568
+ "MUL ndotl.y, ndotl.y, pow_2.x;" +
12569
+
12570
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12571
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12572
+
12573
+ // Pigment
12574
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12575
+ "LRP temp, zero12t.w, temp, one;" + // texture proportion
12576
+ "MUL temp, temp, zero12t.w;" + // Times x
12577
+
12578
+ //"MUL temp, temp, ndotl.y;" +
12579
+ "MAD ndotl.x, pow_2.xxxx, ndotl.yyyy, ndotl.x;" +
12580
+
12581
+ "MUL temp, temp, ndotl.x;" + // lambert
12582
+
12583
+ "MOV temp.w, zero12t.y;" + // reset alpha
12584
+ "MOV result.color, temp;" +
12585
+ "END";
12586
+
12587
+ String programmax =
12588
+ "!!ARBfp1.0\n" +
12589
+
1218712590 //"OPTION ARB_fragment_program_shadow;" +
1218812591 "PARAM light2cam0 = program.env[10];" +
1218912592 "PARAM light2cam1 = program.env[11];" +
....@@ -12209,7 +12612,7 @@
1220912612 "PARAM params4 = program.env[4];" + // anisoV, cameralight, selfshadow, shadow
1221012613 "PARAM params5 = program.env[5];" + // texture, opacity, fakedepth, shadowbias
1221112614 "PARAM params6 = program.env[6];" + // bump, noise, borderfade, fog punchthrough
12212
- "PARAM params7 = program.env[7];" + // noise power, opacity power
12615
+ "PARAM params7 = program.env[7];" + // noise power, opacity power, parallax
1221312616 "PARAM options0 = program.env[63];" + // fog density, intensity, elevation
1221412617 "PARAM options1 = program.env[62];" + // fog rgb color
1221512618 "PARAM options2 = program.env[61];" + // image intensity, subsurface, lightsheen
....@@ -12298,8 +12701,7 @@
1229812701 "TEMP shininess;" +
1229912702 "\n" +
1230012703 "MOV texSamp, one;" +
12301
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12302
-
12704
+
1230312705 "MOV mapgrid.x, one2048th.x;" +
1230412706 "MOV temp, fragment.texcoord[1];" +
1230512707 /*
....@@ -12320,20 +12722,20 @@
1232012722 "MUL temp, floor, mapgrid.x;" +
1232112723 //"TEX depth0, temp, texture[1], 2D;" +
1232212724 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12323
- TextureFetch("depth0", "temp", "1") +
12725
+ ShadowTextureFetch("depth0", "temp", "1") +
1232412726 "") +
1232512727 "ADD temp.x, temp.x, mapgrid.x;" +
1232612728 //"TEX depth1, temp, texture[1], 2D;" +
1232712729 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12328
- TextureFetch("depth1", "temp", "1") +
12730
+ ShadowTextureFetch("depth1", "temp", "1") +
1232912731 "") +
1233012732 "ADD temp.y, temp.y, mapgrid.x;" +
1233112733 //"TEX depth2, temp, texture[1], 2D;" +
12332
- TextureFetch("depth2", "temp", "1") +
12734
+ ShadowTextureFetch("depth2", "temp", "1") +
1233312735 "SUB temp.x, temp.x, mapgrid.x;" +
1233412736 //"TEX depth3, temp, texture[1], 2D;" +
1233512737 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12336
- TextureFetch("depth3", "temp", "1") +
12738
+ ShadowTextureFetch("depth3", "temp", "1") +
1233712739 "") +
1233812740 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1233912741 //"MOV params, material;" +
....@@ -12455,7 +12857,7 @@
1245512857 "POW texSamp.a, texSamp.a, params6.w;" + // fog punch through shortcut
1245612858 // mar 2013 ??? "KIL alpha.a;" +
1245712859 "MOV alpha, texSamp.aaaa;" + // y;" +
12458
- "KIL alpha.a;" +
12860
+ "KIL alpha.a;" + // not sure with parallax mapping
1245912861 /*
1246012862 "MUL temp.xy, temp, two;" +
1246112863 "TXB bump, temp, texture[0], 2D;" +
....@@ -12541,11 +12943,6 @@
1254112943 "SUB bump0, bump0, half;" +
1254212944 "ADD bump, bump, bump0;" +
1254312945
12544
- "MOV temp.x, texSamp.a;" +
12545
- "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
12546
- //"LRP texSamp0, params5.x, texSamp0, one;" +
12547
- "MOV texSamp.a, temp.x;" +
12548
-
1254912946 // double-sided
1255012947 /**/
1255112948 (doublesided?"DP3 temp.z, normal, eye;" +
....@@ -12562,19 +12959,62 @@
1256212959 "MOV normald, normal;" +
1256312960 "MOV normals, normal;" +
1256412961
12962
+ "MOV temp, fragment.texcoord[4];" +
12963
+
1256512964 // UV base
1256612965 //"DP3 UP.x,state.matrix.modelview.row[0],Y;" +
1256712966 //"DP3 UP.y,state.matrix.modelview.row[1],Y;" +
1256812967 //"DP3 UP.z,state.matrix.modelview.row[2],Y;" +
12569
- "DP3 UP.x,state.matrix.texture[7].row[0],Y;" +
12570
- "DP3 UP.y,state.matrix.texture[7].row[1],Y;" +
12571
- "DP3 UP.z,state.matrix.texture[7].row[2],Y;" +
12968
+ "DP3 UP.x,state.matrix.texture[7].row[0],temp;" +
12969
+ "DP3 UP.y,state.matrix.texture[7].row[1],temp;" +
12970
+ "DP3 UP.z,state.matrix.texture[7].row[2],temp;" +
12971
+ Normalize("UP") +
12972
+
1257212973 "XPD V, normal, UP;" +
1257312974 Normalize("V") +
1257412975 "XPD U, V, normal;" +
1257512976 Normalize("U") +
1257612977
1257712978 // parallax mapping
12979
+
12980
+ "DP3 temp2.x, V, eye;" +
12981
+ "DP3 temp2.y, U, eye;" +
12982
+ "DP3 temp2.z, normal, eye;" +
12983
+ "RCP temp2.z, temp2.z;" +
12984
+
12985
+ "DP3 temp2.w, texSamp, texSamp;" + // Height
12986
+ "RSQ temp2.w, temp2.w;" +
12987
+ "RCP temp2.w, temp2.w;" +
12988
+
12989
+ "SUB temp2.w, temp2.w, half;" +
12990
+// "SGE temp.x, temp2.w, eps.x;" +
12991
+// "MUL temp2.w, temp2.w, temp.x;" +
12992
+
12993
+ //"MOV texSamp, U;" +
12994
+
12995
+ "MUL temp2.z, temp2.z, temp2.w;" +
12996
+ "MUL temp2.z, temp2.z, params7.z;" + // parallax
12997
+
12998
+ "MUL temp2, temp2, temp2.z;" +
12999
+
13000
+ "MOV temp, fragment.texcoord[0];" +
13001
+
13002
+ "SUB temp, temp, temp2;" +
13003
+
13004
+ "TEX temp, temp, texture[0], 2D;" +
13005
+ "POW temp.a, temp.a, params6.w;" + // punch through
13006
+
13007
+ "ADD texSamp, temp, texSamp;" +
13008
+ "MUL texSamp.xyz, half, texSamp;" +
13009
+
13010
+ "MOV alpha, texSamp.aaaa;" +
13011
+
13012
+// parallax mapping
13013
+
13014
+ "MOV temp.x, texSamp.a;" +
13015
+ "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
13016
+ //"LRP texSamp0, params5.x, texSamp0, one;" +
13017
+ "MOV texSamp.a, temp.x;" +
1257813018
1257913019 //"MOV temp, fragment.texcoord[0];" +
1258013020 //
....@@ -12704,10 +13144,10 @@
1270413144 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1270513145 "") +
1270613146
12707
- // display shadow only (bump == 0)
13147
+ // display shadow only (fakedepth == 0)
1270813148 "SUB temp.x, half.x, shadow.x;" +
1270913149 "MOV temp.y, -params5.z;" + // params6.x;" +
12710
- "SLT temp.z, temp.y, -one2048th.x;" +
13150
+ "SLT temp.z, temp.y, -c256i.x;" +
1271113151 "SUB temp.y, one.x, temp.z;" +
1271213152 "MUL temp.x, temp.x, temp.y;" +
1271313153 "KIL temp.x;" +
....@@ -13038,8 +13478,19 @@
1303813478 //once = true;
1303913479 }
1304013480
13041
- System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13042
- System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13481
+ String program = programmax;
13482
+
13483
+ if (Globals.MINSHADER)
13484
+ {
13485
+ program = programmin;
13486
+ }
13487
+
13488
+ if (Globals.DEBUG)
13489
+ {
13490
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13491
+ System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13492
+ }
13493
+
1304313494 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1304413495
1304513496 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -13086,7 +13537,8 @@
1308613537 "\n" +
1308713538 "END\n";
1308813539
13089
- System.out.println("Program shadow #" + 0 + "; length = " + program.length());
13540
+ if (Globals.DEBUG)
13541
+ System.out.println("Program shadow #" + 0 + "; length = " + program.length());
1309013542 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1309113543
1309213544 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -13131,25 +13583,26 @@
1313113583 return out;
1313213584 }
1313313585
13134
- String TextureFetch(String dest, String src, String unit)
13586
+ // Also does frustum culling
13587
+ String ShadowTextureFetch(String dest, String src, String unit)
1313513588 {
1313613589 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1313713590 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1313813591 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13592
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13593
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1313913594 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13140
- "SLT " + src + ".z, " + src + ".x, one.x;" +
13141
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13142
- "SLT " + src + ".z, " + src + ".y, one.x;" +
13143
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13595
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13596
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1314413597 //"SWZ buffer, temp, w,w,w,w;";
13145
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13598
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1314613599 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1314713600 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1314813601 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13149
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13602
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1315013603
13151
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13152
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13604
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13605
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1315313606 }
1315413607
1315513608 String Shadow(String depth, String shadow)
....@@ -13196,7 +13649,7 @@
1319613649 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1319713650 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1319813651
13199
- // No shadow when out of frustrum
13652
+ // No shadow when out of frustum
1320013653 "SGE temp.x, " + depth + ".z, one.z;" +
1320113654 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1320213655 "";
....@@ -13343,7 +13796,7 @@
1334313796 /*static*/ float[] modelParams4 = new float[]{0, 0, 0, 0}; // anisoV, cameralight, selfshadow, shadow
1334413797 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1334513798 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
13346
- /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13799
+ /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power, parallax
1334713800
1334813801 //Object3D.cVector2[] vector2buffer;
1334913802
....@@ -13361,9 +13814,10 @@
1336113814 "DP3 " + dest + ".z," + "normals," + "eye;" +
1336213815 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1336313816 //"MOV " + dest + ".w," + "normal.z;" +
13364
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
13365
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13366
- //"MOV " + dest + ".z," + "params2.w;" +
13817
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13818
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13819
+
13820
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1336713821 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1336813822 "RCP " + dest + ".w," + dest + ".w;" +
1336913823 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13509,7 +13963,7 @@
1350913963 "PARAM p[4] = { state.matrix.projection }; # modelview projection matrix\n" +
1351013964 "PARAM zero = { 0.0, 0.0, 0.0, 1.0 };" +
1351113965 "PARAM half = { 0.5, 0.5, 0.5, 1.0 };" +
13512
- "PARAM one = { 1.0, 1.0, 1.0, 0.0 };" +
13966
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
1351313967 "PARAM two = { 2.0, 2.0, 2.0, 1.0 };" +
1351413968 "PARAM third = { 0.33333333333, 0.33333333333, 0.33333333333, 1.0 };" +
1351513969 //"PARAM v256 = { 256.0, 256.0, 256.0, 1.0 };" +
....@@ -13570,7 +14024,7 @@
1357014024 "DP4 temp.x,state.matrix.texture[0].inverse.row[0],vertex.texcoord;" +
1357114025 "DP4 temp.y,state.matrix.texture[0].inverse.row[1],vertex.texcoord;" +
1357214026 "DP4 temp.z,state.matrix.texture[0].inverse.row[2],vertex.texcoord;" +
13573
- //"MOV result.texcoord, vertex.texcoord;" +
14027
+ //"MOV result.texcoord, vertex.fogcoord;" +
1357414028 "MOV result.texcoord, temp;" +
1357514029 // border fade
1357614030 "MOV result.texcoord[3], vertex.texcoord;" +
....@@ -13617,7 +14071,9 @@
1361714071
1361814072 //"ADD temp.z, temp.z, one;" +
1361914073
13620
- "MOV result.color, temp;"
14074
+ "MOV result.texcoord[4], vertex.attrib[4];" + // U dir
14075
+
14076
+ "MOV result.color, temp;" // Normal
1362114077 : "MOV result.color, vertex.color;") +
1362214078 ((mode & VP_PROJECTION) != 0 ? "MOV result.color, zero;"
1362314079 : "") +
....@@ -13928,7 +14384,7 @@
1392814384
1392914385 // fev 2014???
1393014386 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13931
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14387
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1393214388 pingthread.StepToTarget(true); // true);
1393314389 }
1393414390 // if (!LIVE)
....@@ -13993,14 +14449,15 @@
1399314449 drag = false;
1399414450 //System.out.println("Mouse DOWN");
1399514451 editObj = false;
13996
- ClickInfo info = new ClickInfo();
13997
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
13998
- info.pane = this;
13999
- info.camera = renderCamera;
14000
- info.x = x;
14001
- info.y = y;
14002
- info.modifiers = modifiersex;
14003
- editObj = object.doEditClick(info, 0);
14452
+ //ClickInfo info = new ClickInfo();
14453
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14454
+ object.clickInfo.pane = this;
14455
+ object.clickInfo.camera = renderCamera;
14456
+ object.clickInfo.x = x;
14457
+ object.clickInfo.y = y;
14458
+ object.clickInfo.modifiers = modifiersex;
14459
+ editObj = object.doEditClick(//info,
14460
+ 0);
1400414461 if (!editObj)
1400514462 {
1400614463 hasMarquee = true;
....@@ -14282,12 +14739,18 @@
1428214739 void GoDown(int mod)
1428314740 {
1428414741 MODIFIERS |= COMMAND;
14285
- /*
14742
+ boolean isVR = (mouseMode&VR)!=0;
14743
+ /**/
1428614744 if((mod&SHIFT) == SHIFT)
14287
- manipCamera.RotatePosition(0, -speed);
14745
+ {
14746
+ if (isVR)
14747
+ manipCamera.RotateInterest(0, -speed);
14748
+ else
14749
+ manipCamera.RotatePosition(0, -speed);
14750
+ }
1428814751 else
14289
- manipCamera.BackForth(0, -speed*delta, getWidth());
14290
- */
14752
+ manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth());
14753
+ /**/
1429114754 if ((mod & SHIFT) == SHIFT)
1429214755 {
1429314756 mouseMode = mouseMode; // VR??
....@@ -14296,6 +14759,8 @@
1429614759 mouseMode |= BACKFORTH;
1429714760 }
1429814761
14762
+ targetLookAt.set(manipCamera.lookAt);
14763
+
1429914764 //prevX = X = anchorX;
1430014765 prevY = Y = anchorY - (int) (renderCamera.Distance());
1430114766 }
....@@ -14303,12 +14768,19 @@
1430314768 void GoUp(int mod)
1430414769 {
1430514770 MODIFIERS |= COMMAND;
14306
- /*
14771
+ /**/
14772
+ boolean isVR = (mouseMode&VR)!=0;
14773
+
1430714774 if((mod&SHIFT) == SHIFT)
14308
- manipCamera.RotatePosition(0, speed);
14775
+ {
14776
+ if (isVR)
14777
+ manipCamera.RotateInterest(0, speed);
14778
+ else
14779
+ manipCamera.RotatePosition(0, speed);
14780
+ }
1430914781 else
14310
- manipCamera.BackForth(0, speed*delta, getWidth());
14311
- */
14782
+ manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth());
14783
+ /**/
1431214784 if ((mod & SHIFT) == SHIFT)
1431314785 {
1431414786 mouseMode = mouseMode;
....@@ -14317,6 +14789,8 @@
1431714789 mouseMode |= BACKFORTH;
1431814790 }
1431914791
14792
+ targetLookAt.set(manipCamera.lookAt);
14793
+
1432014794 //prevX = X = anchorX;
1432114795 prevY = Y = anchorY + (int) (renderCamera.Distance());
1432214796 }
....@@ -14324,12 +14798,17 @@
1432414798 void GoLeft(int mod)
1432514799 {
1432614800 MODIFIERS |= COMMAND;
14327
- /*
14801
+ /**/
1432814802 if((mod&SHIFT) == SHIFT)
14329
- manipCamera.RotatePosition(speed, 0);
14803
+ manipCamera.Translate(speed*delta, 0, getWidth());
1433014804 else
14331
- manipCamera.Translate(speed*delta, 0, getWidth());
14332
- */
14805
+ {
14806
+ if ((mouseMode&VR)!=0)
14807
+ manipCamera.RotateInterest(-speed, 0);
14808
+ else
14809
+ manipCamera.RotatePosition(speed, 0);
14810
+ }
14811
+ /**/
1433314812 if ((mod & SHIFT) == SHIFT)
1433414813 {
1433514814 mouseMode = mouseMode;
....@@ -14338,6 +14817,8 @@
1433814817 mouseMode |= ROTATE;
1433914818 } // TRANSLATE;
1434014819
14820
+ targetLookAt.set(manipCamera.lookAt);
14821
+
1434114822 prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance());
1434214823 prevY = Y = anchorY;
1434314824 }
....@@ -14345,12 +14826,18 @@
1434514826 void GoRight(int mod)
1434614827 {
1434714828 MODIFIERS |= COMMAND;
14348
- /*
14829
+ /**/
1434914830 if((mod&SHIFT) == SHIFT)
14350
- manipCamera.RotatePosition(-speed, 0);
14831
+ manipCamera.Translate(-speed*delta, 0, getWidth());
1435114832 else
14352
- manipCamera.Translate(-speed*delta, 0, getWidth());
14353
- */
14833
+ {
14834
+ if ((mouseMode&VR)!=0)
14835
+ manipCamera.RotateInterest(speed, 0);
14836
+ else
14837
+ manipCamera.RotatePosition(-speed, 0);
14838
+ }
14839
+
14840
+ /**/
1435414841 if ((mod & SHIFT) == SHIFT)
1435514842 {
1435614843 mouseMode = mouseMode;
....@@ -14359,6 +14846,8 @@
1435914846 mouseMode |= ROTATE;
1436014847 } // TRANSLATE;
1436114848
14849
+ targetLookAt.set(manipCamera.lookAt);
14850
+
1436214851 prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance());
1436314852 prevY = Y = anchorY;
1436414853 }
....@@ -14400,15 +14889,16 @@
1440014889 if (editObj)
1440114890 {
1440214891 drag = true;
14403
- ClickInfo info = new ClickInfo();
14404
- info.bounds.setBounds(0, 0,
14892
+ //ClickInfo info = new ClickInfo();
14893
+ object.clickInfo.bounds.setBounds(0, 0,
1440514894 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14406
- info.pane = this;
14407
- info.camera = renderCamera;
14408
- info.x = x;
14409
- info.y = y;
14410
- object.GetWindow().copy
14411
- .doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
14895
+ object.clickInfo.pane = this;
14896
+ object.clickInfo.camera = renderCamera;
14897
+ object.clickInfo.x = x;
14898
+ object.clickInfo.y = y;
14899
+ object //.GetWindow().copy
14900
+ .doEditDrag(//info,
14901
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1441214902 } else
1441314903 {
1441414904 if (x < startX)
....@@ -14557,24 +15047,27 @@
1455715047 }
1455815048 }
1455915049
15050
+// ClickInfo clickInfo = new ClickInfo();
15051
+
1456015052 public void mouseMoved(MouseEvent e)
1456115053 {
1456215054 //System.out.println("mouseMoved: " + e);
1456315055 if (isRenderer)
1456415056 return;
1456515057
14566
- ClickInfo ci = new ClickInfo();
14567
- ci.x = e.getX();
14568
- ci.y = e.getY();
14569
- ci.modifiers = e.getModifiersEx();
14570
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14571
- ci.pane = this;
14572
- ci.camera = renderCamera;
15058
+ // Mouse cursor feedback
15059
+ object.clickInfo.x = e.getX();
15060
+ object.clickInfo.y = e.getY();
15061
+ object.clickInfo.modifiers = e.getModifiersEx();
15062
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
15063
+ object.clickInfo.pane = this;
15064
+ object.clickInfo.camera = renderCamera;
1457315065 if (!isRenderer)
1457415066 {
1457515067 //ObjEditor editWindow = object.editWindow;
1457615068 //Object3D copy = editWindow.copy;
14577
- if (object.doEditClick(ci, 0))
15069
+ if (object.doEditClick(//clickInfo,
15070
+ 0))
1457815071 {
1457915072 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1458015073 } else
....@@ -14589,7 +15082,8 @@
1458915082 Globals.MOUSEDRAGGED = false;
1459015083
1459115084 movingcamera = false;
14592
- X = Y = 0;
15085
+ X = 0; // getBounds().width/2;
15086
+ Y = 0; // getBounds().height/2;
1459315087 //System.out.println("mouseReleased: " + e);
1459415088 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1459515089 }
....@@ -14845,7 +15339,8 @@
1484515339 // break;
1484615340 case 'T':
1484715341 CACHETEXTURE ^= true;
14848
- textures.clear();
15342
+ texturepigment.clear();
15343
+ texturebump.clear();
1484915344 // repaint();
1485015345 break;
1485115346 case 'Y':
....@@ -14855,8 +15350,8 @@
1485515350 case 'K':
1485615351 KOMPACTTEXTURE ^= true;
1485715352 //textures.clear();
14858
- break;
14859
- case 'P': // Texture Projection macros
15353
+ // break;
15354
+ //case 'P': // Texture Projection macros
1486015355 // SAVETEXTURE ^= true;
1486115356 macromode = true;
1486215357 Udebug = Vdebug = NORMALdebug = false; programInitialized = false;
....@@ -14930,7 +15425,9 @@
1493015425 case 'E' : COMPACT ^= true;
1493115426 repaint();
1493215427 break;
14933
- case 'W' : DEBUGHSB ^= true;
15428
+ case 'W' : // Wide Window (fullscreen)
15429
+ //DEBUGHSB ^= true;
15430
+ ObjEditor.theFrame.ToggleFullScreen();
1493415431 repaint();
1493515432 break;
1493615433 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14956,13 +15453,7 @@
1495615453 repaint();
1495715454 break;
1495815455 case 'l':
14959
- lightMode ^= true;
14960
- Globals.lighttouched = true;
14961
- manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
14962
- targetLookAt.set(manipCamera.lookAt);
14963
- repaint();
14964
- break;
14965
- case 'L':
15456
+ //case 'L':
1496615457 if (lightMode)
1496715458 {
1496815459 lightMode = false;
....@@ -14981,7 +15472,7 @@
1498115472 targetLookAt.set(manipCamera.lookAt);
1498215473 repaint();
1498315474 break;
14984
- case 'p':
15475
+ case 'P': // p':
1498515476 // c'est quoi ca au juste? spherical ^= true;
1498615477 Skinshader ^= true; programInitialized = false;
1498715478 repaint();
....@@ -15019,27 +15510,31 @@
1501915510 repaint();
1502015511 break;
1502115512 case 'O':
15022
- Globals.drawMode = OCCLUSION; // WARNING
15513
+ // Too dangerous. Use menu. Globals.drawMode = OCCLUSION; // WARNING
1502315514 repaint();
1502415515 break;
1502515516 case 'o':
1502615517 OCCLUSION_CULLING ^= true;
1502715518 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1502815519 break;
15029
- case '0': envyoff ^= true; repaint(); break;
15520
+ //case '0': envyoff ^= true; repaint(); break;
1503015521 case '1':
1503115522 case '2':
1503215523 case '3':
1503315524 case '4':
1503415525 case '5':
15035
- newenvy = Character.getNumericValue(key);
15036
- repaint();
15037
- break;
1503815526 case '6':
1503915527 case '7':
1504015528 case '8':
1504115529 case '9':
15042
- BGcolor = (key - '6')/3.f;
15530
+ if (true) // envyoff)
15531
+ {
15532
+ BGcolor = (key - '1')/8.f;
15533
+ }
15534
+ else
15535
+ {
15536
+ //newenvy = Character.getNumericValue(key);
15537
+ }
1504315538 repaint();
1504415539 break;
1504515540 case '!':
....@@ -15105,11 +15600,14 @@
1510515600 case '_':
1510615601 kompactbit = 5;
1510715602 break;
15108
- case '+':
15109
- kompactbit = 6;
15110
- break;
15603
+// case '+':
15604
+// kompactbit = 6;
15605
+// break;
1511115606 case ' ':
15112
- ObjEditor.theFrame.ToggleFullScreen();
15607
+ lightMode ^= true;
15608
+ Globals.lighttouched = true;
15609
+ manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
15610
+ targetLookAt.set(manipCamera.lookAt);
1511315611 repaint();
1511415612 break;
1511515613 //case '`' :
....@@ -15156,8 +15654,9 @@
1515615654 case DELETE:
1515715655 ClearSelection();
1515815656 break;
15159
- /*
1516015657 case '+':
15658
+
15659
+ /*
1516115660 //fontsize += 1;
1516215661 bbzoom *= 2;
1516315662 repaint();
....@@ -15174,17 +15673,17 @@
1517415673 case '=':
1517515674 IncDepth();
1517615675 //fontsize += 1;
15177
- object.editWindow.refreshContents(true);
15676
+ object.GetWindow().refreshContents(true);
1517815677 maskbit = 6;
1517915678 break;
1518015679 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1518115680 DecDepth();
1518215681 maskbit = 5;
1518315682 //if(fontsize > 1) fontsize -= 1;
15184
- if (object.editWindow == null)
15185
- new Exception().printStackTrace();
15186
- else
15187
- object.editWindow.refreshContents(true);
15683
+// if (object.editWindow == null)
15684
+// new Exception().printStackTrace();
15685
+// else
15686
+ object.GetWindow().refreshContents(true);
1518815687 break;
1518915688 case '{':
1519015689 manipCamera.shaper_fovy /= 1.1;
....@@ -15408,7 +15907,7 @@
1540815907 }
1540915908 */
1541015909
15411
- object.editWindow.EditSelection(false);
15910
+ object.GetWindow().EditSelection(false);
1541215911 }
1541315912
1541415913 void SelectParent()
....@@ -15425,10 +15924,10 @@
1542515924 {
1542615925 //selectees.remove(i);
1542715926 System.out.println("select parent of " + elem);
15428
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15927
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1542915928 } else
1543015929 {
15431
- group.editWindow.Select(elem.GetTreePath(), first, true);
15930
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1543215931 }
1543315932
1543415933 first = false;
....@@ -15470,12 +15969,12 @@
1547015969 for (int j = 0; j < group.children.size(); j++)
1547115970 {
1547215971 elem = (Object3D) group.children.elementAt(j);
15473
- object.editWindow.Select(elem.GetTreePath(), first, true);
15972
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1547415973 first = false;
1547515974 }
1547615975 } else
1547715976 {
15478
- object.editWindow.Select(elem.GetTreePath(), first, true);
15977
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1547915978 }
1548015979
1548115980 first = false;
....@@ -15486,21 +15985,21 @@
1548615985 {
1548715986 //Composite group = (Composite) object;
1548815987 Object3D group = object;
15489
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15988
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1549015989 }
1549115990
1549215991 void ResetTransform(int mask)
1549315992 {
1549415993 //Composite group = (Composite) object;
1549515994 Object3D group = object;
15496
- group.editWindow.ResetTransform(mask);
15995
+ group.GetWindow().ResetTransform(mask);
1549715996 }
1549815997
1549915998 void FlipTransform()
1550015999 {
1550116000 //Composite group = (Composite) object;
1550216001 Object3D group = object;
15503
- group.editWindow.FlipTransform();
16002
+ group.GetWindow().FlipTransform();
1550416003 // group.editWindow.ReduceMesh(true);
1550516004 }
1550616005
....@@ -15508,7 +16007,7 @@
1550816007 {
1550916008 //Composite group = (Composite) object;
1551016009 Object3D group = object;
15511
- group.editWindow.PrintMemory();
16010
+ group.GetWindow().PrintMemory();
1551216011 // group.editWindow.ReduceMesh(true);
1551316012 }
1551416013
....@@ -15516,7 +16015,7 @@
1551616015 {
1551716016 //Composite group = (Composite) object;
1551816017 Object3D group = object;
15519
- group.editWindow.ResetCentroid();
16018
+ group.GetWindow().ResetCentroid();
1552016019 }
1552116020
1552216021 void IncDepth()
....@@ -15598,8 +16097,6 @@
1559816097
1559916098 int width = getBounds().width;
1560016099 int height = getBounds().height;
15601
- ClickInfo info = new ClickInfo();
15602
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1560316100 //Image img = CreateImage(width, height);
1560416101 //System.out.println("width = " + width + "; height = " + height + "\n");
1560516102
....@@ -15676,48 +16173,77 @@
1567616173 }
1567716174 if (object != null && !hasMarquee)
1567816175 {
16176
+ if (object.clickInfo == null)
16177
+ object.clickInfo = new ClickInfo();
16178
+ ClickInfo info = object.clickInfo;
16179
+ //ClickInfo info = new ClickInfo();
16180
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16181
+
1567916182 if (isRenderer)
1568016183 {
15681
- info.flags++;
16184
+ object.clickInfo.flags++;
1568216185 double frameAspect = (double) width / (double) height;
1568316186 if (frameAspect > renderCamera.aspect)
1568416187 {
1568516188 int desired = (int) ((double) height * renderCamera.aspect);
15686
- info.bounds.width -= width - desired;
15687
- info.bounds.x += (width - desired) / 2;
16189
+ object.clickInfo.bounds.width -= width - desired;
16190
+ object.clickInfo.bounds.x += (width - desired) / 2;
1568816191 } else
1568916192 {
1569016193 int desired = (int) ((double) width / renderCamera.aspect);
15691
- info.bounds.height -= height - desired;
15692
- info.bounds.y += (height - desired) / 2;
16194
+ object.clickInfo.bounds.height -= height - desired;
16195
+ object.clickInfo.bounds.y += (height - desired) / 2;
1569316196 }
1569416197 }
15695
- info.g = gr;
15696
- info.camera = renderCamera;
16198
+
16199
+ object.clickInfo.g = gr;
16200
+ object.clickInfo.camera = renderCamera;
1569716201 /*
1569816202 // Memory intensive (brep.verticescopy)
1569916203 if (!(object instanceof Composite))
1570016204 object.draw(info, 0, false); // SLOW :
1570116205 */
15702
- if (!isRenderer)
16206
+ if (!isRenderer) // && drag)
1570316207 {
15704
- object.drawEditHandles(info, 0);
15705
-
15706
- if (drag && (X != 0 || Y != 0) && object.selection.Size() > 0)
16208
+ Grafreed.Assert(object != null);
16209
+ Grafreed.Assert(object.selection != null);
16210
+ if (object.selection.Size() > 0)
1570716211 {
15708
- switch (object.selection.get(0).hitSomething)
16212
+ int hitSomething = object.selection.get(0).hitSomething;
16213
+
16214
+ object.clickInfo.DX = 0;
16215
+ object.clickInfo.DY = 0;
16216
+ object.clickInfo.W = 1;
16217
+ if (hitSomething == Object3D.hitCenter)
1570916218 {
15710
- case Object3D.hitCenter: gr.setColor(Color.pink);
15711
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15712
- break;
15713
- case Object3D.hitRotate: gr.setColor(Color.yellow);
15714
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15715
- break;
15716
- case Object3D.hitScale: gr.setColor(Color.cyan);
15717
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15718
- break;
16219
+ info.DX = X;
16220
+ if (X != 0)
16221
+ info.DX -= info.bounds.width/2;
16222
+
16223
+ info.DY = Y;
16224
+ if (Y != 0)
16225
+ info.DY -= info.bounds.height/2;
1571916226 }
15720
-
16227
+
16228
+ object.drawEditHandles(//info,
16229
+ 0);
16230
+
16231
+ if (drag && (X != 0 || Y != 0))
16232
+ {
16233
+ switch (hitSomething)
16234
+ {
16235
+ case Object3D.hitCenter: gr.setColor(Color.white);
16236
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16237
+ break;
16238
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16239
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16240
+ break;
16241
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16242
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16243
+ break;
16244
+ }
16245
+
16246
+ }
1572116247 }
1572216248 }
1572316249 }
....@@ -15732,7 +16258,7 @@
1573216258 if (hasMarquee)
1573316259 {
1573416260 gr.setXORMode(Color.white);
15735
- gr.setColor(Color.red);
16261
+ gr.setColor(Color.white);
1573616262 if (!firstime)
1573716263 {
1573816264 gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH);
....@@ -16199,6 +16725,8 @@
1619916725 private /*static*/ boolean firstime;
1620016726 private /*static*/ cVector newView = new cVector();
1620116727 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16728
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16729
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1620216730 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1620316731 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1620416732 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16211,29 +16739,67 @@
1621116739 {
1621216740 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1621316741
16742
+ int usedsuf = 0;
16743
+
1621416744 for (int i = 0; i < suffixes.length; i++)
1621516745 {
16216
- String resourceName = basename + suffixes[i] + "." + suffix;
16217
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16218
- mipmapped,
16219
- FileUtil.getFileSuffix(resourceName));
16220
- if (data == null)
16746
+ String[] suffixe = suffixes;
16747
+ String[] fallback = suffixes2;
16748
+ String[] fallfallback = suffixes3;
16749
+
16750
+ for (int c=usedsuf; --c>=0;)
1622116751 {
16222
- throw new IOException("Unable to load texture " + resourceName);
16752
+// String[] temp = suffixe;
16753
+// suffixe = fallback;
16754
+// fallback = fallfallback;
16755
+// fallfallback = temp;
1622316756 }
16757
+
16758
+ String resourceName = basename + suffixe[i] + "." + suffix;
16759
+ TextureData data;
16760
+
16761
+ try
16762
+ {
16763
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16764
+ mipmapped,
16765
+ FileUtil.getFileSuffix(resourceName));
16766
+ }
16767
+ catch (Exception e)
16768
+ {
16769
+ try
16770
+ {
16771
+ resourceName = basename + fallback[i] + "." + suffix;
16772
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16773
+ mipmapped,
16774
+ FileUtil.getFileSuffix(resourceName));
16775
+ }
16776
+ catch (Exception e2)
16777
+ {
16778
+ resourceName = basename + fallfallback[i] + "." + suffix;
16779
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16780
+ mipmapped,
16781
+ FileUtil.getFileSuffix(resourceName));
16782
+ }
16783
+ }
16784
+
1622416785 //System.out.println("Target = " + targets[i]);
1622516786 cubemap.updateImage(data, targets[i]);
1622616787 }
1622716788
1622816789 return cubemap;
1622916790 }
16791
+
1623016792 int bigsphere = -1;
1623116793
1623216794 float BGcolor = 0.5f;
1623316795
16234
- private void DrawSkyBox(GL gl)
16796
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16797
+
16798
+ private void DrawSkyBox(GL gl, float ratio)
1623516799 {
16236
- if (envyoff || cubemap == null)
16800
+ if (//envyoff ||
16801
+ WIREFRAME ||
16802
+ cubemap == null)
1623716803 {
1623816804 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1623916805 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16248,7 +16814,17 @@
1624816814 // Compensates for ExaminerViewer's modification of modelview matrix
1624916815 gl.glMatrixMode(GL.GL_MODELVIEW);
1625016816 gl.glLoadIdentity();
16817
+ gl.glScalef(1,ratio,1);
1625116818
16819
+// colorV[0] = 2;
16820
+// colorV[1] = 2;
16821
+// colorV[2] = 2;
16822
+// colorV[3] = 1;
16823
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16824
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16825
+//
16826
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16827
+
1625216828 //gl.glActiveTexture(GL.GL_TEXTURE1);
1625316829 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1625416830
....@@ -16280,6 +16856,7 @@
1628016856 {
1628116857 gl.glScalef(1.0f, -1.0f, 1.0f);
1628216858 }
16859
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1628316860 gl.glMultMatrixd(viewrot_1, 0);
1628416861 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1628516862 //viewer.updateInverseRotation(gl);
....@@ -16320,7 +16897,8 @@
1632016897 gl.glDisable(GL.GL_TEXTURE_GEN_R);
1632116898
1632216899 cubemap.disable();
16323
- ////cubemap.unbind();
16900
+ //cubemap.dispose();
16901
+
1632416902 if (CULLFACE)
1632516903 {
1632616904 gl.glEnable(gl.GL_CULL_FACE);
....@@ -16376,7 +16954,7 @@
1637616954 gl.glScalef(1.0f, -1.0f, 1.0f);
1637716955 }
1637816956
16379
- gl.glNormal3f(0.0f, 0.0f, 1.0f);
16957
+ SetGLNormal(gl, 0.0f, 0.0f, 1.0f);
1638016958
1638116959 float step = 2; // 0.1666f; //0.25f;
1638216960 float stepv = 2; // step * 1652 / 998;
....@@ -16515,6 +17093,14 @@
1651517093 }
1651617094 }
1651717095
17096
+ private Object3D GetFolder()
17097
+ {
17098
+ Object3D folder = object.GetWindow().copy;
17099
+ if (object.GetWindow().copy.selection.Size() > 0)
17100
+ folder = object.GetWindow().copy.selection.elementAt(0);
17101
+ return folder;
17102
+ }
17103
+
1651817104 class SelectBuffer implements GLEventListener
1651917105 {
1652017106
....@@ -16530,7 +17116,7 @@
1653017116 //new Exception().printStackTrace();
1653117117 System.out.println("select buffer init");
1653217118 // Use debug pipeline
16533
- drawable.setGL(new DebugGL(drawable.getGL()));
17119
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1653417120
1653517121 GL gl = drawable.getGL();
1653617122
....@@ -16594,6 +17180,17 @@
1659417180
1659517181 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1659617182
17183
+ if (PAINTMODE)
17184
+ {
17185
+ if (object.GetWindow().copy.selection.Size() > 0)
17186
+ {
17187
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17188
+
17189
+ // Make what you paint not selectable.
17190
+ paintobj.ResetSelectable();
17191
+ }
17192
+ }
17193
+
1659717194 //int tmp = selection_view;
1659817195 //selection_view = -1;
1659917196 int temp = DrawMode();
....@@ -16605,6 +17202,17 @@
1660517202 // temp = DEFAULT; // patch for selection debug
1660617203 Globals.drawMode = temp; // WARNING
1660717204
17205
+ if (PAINTMODE)
17206
+ {
17207
+ if (object.GetWindow().copy.selection.Size() > 0)
17208
+ {
17209
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17210
+
17211
+ // Revert.
17212
+ paintobj.RestoreSelectable();
17213
+ }
17214
+ }
17215
+
1660817216 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1660917217
1661017218 // trying different ways of getting the depth info over
....@@ -16708,29 +17316,31 @@
1670817316 }
1670917317
1671017318 if (!movingcamera && !PAINTMODE)
16711
- object.editWindow.ScreenFitPoint(); // fev 2014
17319
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1671217320
16713
- if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17321
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1671417322 {
16715
- Object3D paintobj = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17323
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1671617324
16717
- Object3D group = new Object3D("inst" + paintcount++);
17325
+ if (object.GetWindow().copy.selection.Size() > 0)
17326
+ {
17327
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1671817328
16719
- group.CreateMaterial(); // use a void leaf to select instances
16720
-
16721
- group.add(paintobj); // link
16722
-
16723
- object.editWindow.SnapObject(group);
16724
-
16725
- Object3D folder = object.editWindow.copy;
16726
-
16727
- if (object.editWindow.copy.selection.Size() > 0)
16728
- folder = object.editWindow.copy.selection.elementAt(0);
16729
-
16730
- folder.add(group);
16731
-
16732
- object.editWindow.ResetModel();
16733
- object.editWindow.refreshContents();
17329
+ Object3D inst = new Object3D("inst" + paintcount++);
17330
+
17331
+ inst.CreateMaterial(); // use a void leaf to select instances
17332
+
17333
+ inst.add(paintobj); // link
17334
+
17335
+ object.GetWindow().SnapObject(inst);
17336
+
17337
+ Object3D folder = paintFolder; // GetFolder();
17338
+
17339
+ folder.add(inst);
17340
+
17341
+ object.GetWindow().ResetModel();
17342
+ object.GetWindow().refreshContents();
17343
+ }
1673417344 }
1673517345 else
1673617346 paintcount = 0;
....@@ -16769,6 +17379,11 @@
1676917379 //System.out.println("objects[color] = " + objects[color]);
1677017380 //objects[color].Select();
1677117381 indexcount = 0;
17382
+ ObjEditor window = object.GetWindow();
17383
+ if (window != null && deselect)
17384
+ {
17385
+ window.Select(null, deselect, true);
17386
+ }
1677217387 object.Select(color, deselect);
1677317388 }
1677417389
....@@ -16819,6 +17434,7 @@
1681917434
1682017435 public void init(GLAutoDrawable drawable)
1682117436 {
17437
+ if (Globals.DEBUG)
1682217438 System.out.println("shadow buffer init");
1682317439
1682417440 GL gl = drawable.getGL();
....@@ -17047,10 +17663,14 @@
1704717663 gl.glFlush();
1704817664
1704917665 /**/
17050
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17666
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1705117667
17052
- float[] pixels = occlusionsizebuffer.array();
17668
+ float[] depths = occlusiondepthbuffer.array();
1705317669
17670
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17671
+
17672
+ int[] pixels = selectsizebuffer.array();
17673
+
1705417674 double r = 0, g = 0, b = 0;
1705517675
1705617676 double count = 0;
....@@ -17061,7 +17681,7 @@
1706117681
1706217682 double FACTOR = 1;
1706317683
17064
- for (int i = 0; i < pixels.length; i++)
17684
+ for (int i = 0; i < depths.length; i++)
1706517685 {
1706617686 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1706717687 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -17144,7 +17764,7 @@
1714417764
1714517765 double scale = ray.z; // 1; // cos
1714617766
17147
- float depth = pixels[newindex];
17767
+ float depth = depths[newindex];
1714817768
1714917769 /*
1715017770 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -17341,11 +17961,14 @@
1734117961 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1734217962 static IntBuffer bigAAbuffer;
1734317963 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
17344
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17964
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1734517965 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1734617966 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1734717967 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17348
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17968
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17969
+
17970
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17971
+
1734917972 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1735017973 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1735117974 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();