Normand Briere
2019-08-26 6266c8a4b2485b29a7d5bcb217460d7aad3e1c4a
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 = true; // 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
....@@ -487,7 +542,8 @@
487542 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
488543 LA.vecCross(obj.v0, obj.v1, obj.v2);
489544 LA.vecNormalize(obj.v2);
490
- 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);
491547 }
492548
493549 // P
....@@ -509,7 +565,7 @@
509565 y += ny * obj.NORMALPUSH;
510566 z += nz * obj.NORMALPUSH;
511567
512
- gl.glNormal3f(nx, ny, nz);
568
+ SetGLNormal(gl, nx, ny, nz);
513569 }
514570 gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
515571 SetColor(obj, pv);
....@@ -541,7 +597,7 @@
541597 y += ny * obj.NORMALPUSH;
542598 z += nz * obj.NORMALPUSH;
543599
544
- gl.glNormal3f(nx, ny, nz);
600
+ SetGLNormal(gl, nx, ny, nz);
545601 }
546602 //System.out.println("vertexq = " + qv.s + ", " + qv.t);
547603 // boolean locked = false;
....@@ -589,7 +645,7 @@
589645 y += ny * obj.NORMALPUSH;
590646 z += nz * obj.NORMALPUSH;
591647
592
- gl.glNormal3f(nx, ny, nz);
648
+ SetGLNormal(gl, nx, ny, nz);
593649 }
594650
595651 // if ((dot&4) == 0)
....@@ -825,7 +881,7 @@
825881 //// tris.postdraw(this);
826882 }
827883
828
- static Camera localcamera = new Camera();
884
+ static Camera localAOcamera = new Camera();
829885 static cVector from = new cVector();
830886 static cVector to = new cVector();
831887
....@@ -834,7 +890,7 @@
834890 CameraPane cp = this;
835891
836892 Camera keep = cp.RenderCamera();
837
- cp.renderCamera = localcamera;
893
+ cp.renderCamera = localAOcamera;
838894
839895 if (br.trimmed)
840896 {
....@@ -852,7 +908,7 @@
852908 br.positions[i3 + 2] + br.normals[i3 + 2]);
853909 LA.xformPos(from, transform, from);
854910 LA.xformPos(to, transform, to); // RIGID ONLY
855
- localcamera.setAim(from, to);
911
+ localAOcamera.setAim(from, to);
856912
857913 CameraPane.occlusionbuffer.display();
858914
....@@ -886,7 +942,7 @@
886942 to.set(v.x+v.norm.x, v.y+v.norm.y, v.z+v.norm.z);
887943 LA.xformPos(from, transform, from);
888944 LA.xformPos(to, transform, to); // RIGID ONLY
889
- localcamera.setAim(from, to);
945
+ localAOcamera.setAim(from, to);
890946
891947 CameraPane.occlusionbuffer.display();
892948
....@@ -1195,10 +1251,10 @@
11951251 {
11961252 if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
11971253 {
1198
- gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1254
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
11991255 } else
12001256 {
1201
- gl.glNormal3f(0, 0, 1);
1257
+ SetGLNormal(gl, 0, 0, 1);
12021258 }
12031259
12041260 if (c != null)
....@@ -1222,10 +1278,10 @@
12221278 {
12231279 if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
12241280 {
1225
- gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1281
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
12261282 } else
12271283 {
1228
- gl.glNormal3f(0, 0, 1);
1284
+ SetGLNormal(gl, 0, 0, 1);
12291285 }
12301286 if (c != null)
12311287 {
....@@ -1250,10 +1306,10 @@
12501306 {
12511307 if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
12521308 {
1253
- gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1309
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
12541310 } else
12551311 {
1256
- gl.glNormal3f(0, 0, 1);
1312
+ SetGLNormal(gl, 0, 0, 1);
12571313 }
12581314 if (c != null)
12591315 {
....@@ -1435,7 +1491,7 @@
14351491 {
14361492 if (!selectmode)
14371493 {
1438
- 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);
14391495 gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
14401496
14411497 if (flipV)
....@@ -1447,6 +1503,8 @@
14471503 gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
14481504 }
14491505
1506
+ float[] colorV = new float[4];
1507
+
14501508 void SetColor(Object3D obj, Vertex p0)
14511509 {
14521510 CameraPane display = this;
....@@ -1514,8 +1572,6 @@
15141572 {
15151573 return;
15161574 }
1517
-
1518
- float[] colorV = new float[3];
15191575
15201576 if (false) // marked)
15211577 {
....@@ -1764,7 +1820,7 @@
17641820
17651821 display.modelParams7[0] = 0;
17661822 display.modelParams7[1] = 1000;
1767
- display.modelParams7[2] = 0;
1823
+ display.modelParams7[2] = material.parallax;
17681824 display.modelParams7[3] = 0;
17691825
17701826 //display.modelParams6[0] = 100; // criss de bug de bump
....@@ -1997,9 +2053,9 @@
19972053 switch(viewcode)
19982054 {
19992055 case 0: return "main";
2000
- case 1: return "one";
2001
- case 2: return "two";
2002
- case 3: return "three";
2056
+ case 1: return "Red";
2057
+ case 2: return "Green";
2058
+ case 3: return "Blue";
20032059 case 4: return "light";
20042060 }
20052061
....@@ -2405,43 +2461,31 @@
24052461 return currentGL;
24062462 }
24072463
2408
- private BufferedImage CreateBim(TextureData texturedata)
2464
+ static private BufferedImage CreateBim(TextureData texturedata)
24092465 {
2410
- // cache to disk
2411
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
2412
- //buffers[0].
2413
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
2414
- int[] pixels = new int[bytebuf.capacity()/3];
2415
- int width = texturedata.getWidth(); //(int)Math.sqrt(pixels.length); // squared
2416
- int height = width;
2417
- for (int i=pixels.length; --i>=0;)
2418
- {
2419
- int i3 = i*3;
2420
- pixels[i] = 0xFF;
2421
- pixels[i] <<= 8;
2422
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
2423
- pixels[i] <<= 8;
2424
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
2425
- pixels[i] <<= 8;
2426
- pixels[i] |= bytebuf.get(i3) & 0xFF;
2427
- }
2428
- /*
2429
- int r=0,g=0,b=0,a=0;
2430
- for (int i=0; i<width; i++)
2431
- for (int j=0; j<height; j++)
2432
- {
2433
- int index = j*width+i;
2434
- int p = pixels[index];
2435
- a = ((p>>24) & 0xFF);
2436
- r = ((p>>16) & 0xFF);
2437
- g = ((p>>8) & 0xFF);
2438
- b = (p & 0xFF);
2439
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
2440
- }
2441
- /**/
2442
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
2443
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
2444
- return rendImage;
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);
24452489 }
24462490
24472491 /**/
....@@ -2452,18 +2496,20 @@
24522496
24532497 int resolution;
24542498
2455
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2499
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
24562500 {
2457
- texture = tex;
2501
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2502
+ texturedata = texdata;
24582503 resolution = res;
24592504 }
24602505 }
24612506 /**/
24622507
24632508 // TEXTURE static Texture texture;
2464
- static public java.util.Hashtable<String, CacheTexture> textures = new java.util.Hashtable<String, CacheTexture>();
2465
- static public java.util.Hashtable<BufferedImage, CacheTexture> bimtextures = new java.util.Hashtable<BufferedImage, CacheTexture>();
2466
- static public java.util.HashSet<String> usedtextures = new java.util.HashSet<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>();
24672513
24682514 int pigmentdepth = 0;
24692515 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
....@@ -2471,10 +2517,10 @@
24712517 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
24722518 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
24732519 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2474
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2520
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
24752521 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
24762522
2477
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2523
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
24782524 {
24792525 TextureData texturedata = null;
24802526
....@@ -2484,7 +2530,7 @@
24842530 com.sun.opengl.util.texture.TextureIO.newTextureData(
24852531 getClass().getClassLoader().getResourceAsStream(name),
24862532 true,
2487
- com.sun.opengl.util.texture.TextureIO.PNG);
2533
+ GetFormat(name)); // com.sun.opengl.util.texture.TextureIO.PNG);
24882534 } catch (java.io.IOException e)
24892535 {
24902536 throw new javax.media.opengl.GLException(e);
....@@ -2493,16 +2539,16 @@
24932539 if (bump)
24942540 texturedata = ConvertBump(texturedata, false);
24952541
2496
- com.sun.opengl.util.texture.Texture texture =
2497
- 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);
24982544
2499
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2500
- 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);
25012547
2502
- return texture;
2548
+ return texturedata;
25032549 }
25042550
2505
- com.sun.opengl.util.texture.Texture GetBimTexture(BufferedImage name, boolean bump)
2551
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
25062552 {
25072553 TextureData texturedata = null;
25082554
....@@ -2510,7 +2556,7 @@
25102556 {
25112557 texturedata =
25122558 com.sun.opengl.util.texture.TextureIO.newTextureData(
2513
- name,
2559
+ bim,
25142560 true);
25152561 } catch (Exception e)
25162562 {
....@@ -2519,14 +2565,8 @@
25192565
25202566 if (bump)
25212567 texturedata = ConvertBump(texturedata, false);
2522
-
2523
- com.sun.opengl.util.texture.Texture texture =
2524
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2525
-
2526
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2527
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
2528
-
2529
- return texture;
2568
+
2569
+ return texturedata;
25302570 }
25312571
25322572 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -8014,8 +8054,8 @@
80148054 pigment = null;
80158055 }
80168056
8017
- ReleaseTexture(bump, true);
8018
- ReleaseTexture(pigment, false);
8057
+ ReleaseTexture(tex, true);
8058
+ ReleaseTexture(tex, false);
80198059 }
80208060
80218061 public void ReleasePigmentTexture(cTexture tex) // INTERFACE
....@@ -8044,7 +8084,7 @@
80448084 pigment = null;
80458085 }
80468086
8047
- ReleaseTexture(pigment, false);
8087
+ ReleaseTexture(tex, false);
80488088 }
80498089
80508090 public void ReleaseBumpTexture(cTexture tex) // INTERFACE
....@@ -8073,10 +8113,10 @@
80738113 bump = null;
80748114 }
80758115
8076
- ReleaseTexture(bump, true);
8116
+ ReleaseTexture(tex, true);
80778117 }
80788118
8079
- void ReleaseTexture(String tex, boolean bump)
8119
+ void ReleaseTexture(cTexture tex, boolean bump)
80808120 {
80818121 if (// DrawMode() != 0 || /*tex == null ||*/
80828122 ambientOcclusion ) // || !textureon)
....@@ -8087,7 +8127,7 @@
80878127 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
80888128
80898129 if (tex != null)
8090
- texture = textures.get(tex);
8130
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
80918131
80928132 // //assert( texture != null );
80938133 // if (texture == null)
....@@ -8237,13 +8277,13 @@
82378277
82388278 if (tex == null)
82398279 {
8240
- BindTexture(null, null,false,resolution);
8280
+ BindTexture(null,false,resolution);
82418281 return;
82428282 }
82438283
82448284 String pigment = Object3D.GetPigment(tex);
82458285
8246
- usedtextures.add(pigment);
8286
+ usedtextures.add(tex);
82478287
82488288 //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
82498289 {
....@@ -8257,7 +8297,7 @@
82578297 }
82588298
82598299 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8260
- BindTexture(tex.pigmenttexture, pigment, false, resolution);
8300
+ BindTexture(tex, false, resolution);
82618301 }
82628302
82638303 /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8270,13 +8310,13 @@
82708310
82718311 if (tex == null)
82728312 {
8273
- BindTexture(null, null,true,resolution);
8313
+ BindTexture(null,true,resolution);
82748314 return;
82758315 }
82768316
82778317 String bump = Object3D.GetBump(tex);
82788318
8279
- usedtextures.add(bump);
8319
+ usedtextures.add(tex);
82808320
82818321 //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
82828322 {
....@@ -8290,7 +8330,7 @@
82908330 }
82918331
82928332 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8293
- BindTexture(tex.bumptexture, bump, true, resolution);
8333
+ BindTexture(tex, true, resolution);
82948334 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
82958335 }
82968336
....@@ -8314,13 +8354,19 @@
83148354 return fileExists;
83158355 }
83168356
8317
- CacheTexture GetCacheTexture(java.awt.image.BufferedImage bim, String tex, boolean bump, int resolution) throws Exception
8357
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
83188358 {
83198359 CacheTexture texturecache = null;
83208360
83218361 if (tex != null)
83228362 {
8323
- 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
+ }
83248370
83258371 String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
83268372
....@@ -8330,29 +8376,46 @@
83308376 // else
83318377 // if (!texname.startsWith("/"))
83328378 // texname = "/Users/nbriere/Textures/" + texname;
8333
- if (!FileExists(tex))
8379
+ if (!FileExists(texname) && !texname.startsWith("@"))
83348380 {
83358381 texname = fallbackTextureName;
83368382 }
83378383
83388384 if (CACHETEXTURE)
83398385 {
8340
- if (bim == null)
8341
- texturecache = textures.get(texname); // TEXTURE CACHE
8386
+ if (texdata == null)
8387
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
83428388 else
8343
- texturecache = bimtextures.get(bim); // TEXTURE CACHE
8389
+ texturecache = bimtextures.get(texdata);
83448390 }
83458391
8346
- if (texturecache == null || texturecache.resolution < resolution)
8392
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
83478393 {
83488394 TextureData texturedata = null;
83498395
8350
- if (bim != null)
8396
+ if (texdata != null && textureon)
83518397 {
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
+
83528409 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;
83538416 }
83548417 else
8355
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8418
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
83568419 {
83578420 assert(!bump);
83588421 // if (bump)
....@@ -8363,7 +8426,7 @@
83638426 // }
83648427 // else
83658428 // {
8366
- texturecache = textures.get(tex);
8429
+ // texturecache = textures.get(texname); // suspicious
83678430 if (texturecache == null)
83688431 {
83698432 texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
....@@ -8372,10 +8435,10 @@
83728435 new Exception().printStackTrace();
83738436 // }
83748437 } else
8375
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8438
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
83768439 {
83778440 assert(bump);
8378
- texturecache = textures.get(tex);
8441
+ // texturecache = textures.get(texname); // suspicious
83798442 if (texturecache == null)
83808443 texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
83818444 else
....@@ -8387,11 +8450,20 @@
83878450 // texture = GetResourceTexture("default.png");
83888451 //} else
83898452 //{
8390
- if (tex.equals("WHITE_NOISE"))
8453
+ if (texname.endsWith("WHITE_NOISE"))
83918454 {
8392
- texturecache = textures.get(tex);
8455
+ // texturecache = textures.get(texname); // suspicious
83938456 if (texturecache == null)
83948457 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);
83958467 else
83968468 new Exception().printStackTrace();
83978469 } else
....@@ -8452,17 +8524,17 @@
84528524 if (texturedata == null)
84538525 throw new Exception();
84548526
8455
- texturecache = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8527
+ texturecache = new CacheTexture(texturedata,resolution);
84568528 //texture = GetTexture(tex, bump);
84578529 }
8530
+ }
84588531 }
84598532 //}
84608533 }
84618534
8462
- if (/*CACHETEXTURE &&*/ texturecache != null && textureon)
8535
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
84638536 {
84648537 //return false;
8465
- assert(bim == null);
84668538
84678539 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
84688540 if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
....@@ -8509,18 +8581,20 @@
85098581 }
85108582 }
85118583 }
8512
-
8584
+
8585
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8586
+
85138587 //System.out.println("Texture = " + tex);
8514
- if (textures.containsKey(texname))
8588
+ if (textures.containsKey(tex))
85158589 {
8516
- CacheTexture thetex = textures.get(texname);
8590
+ CacheTexture thetex = textures.get(tex);
85178591 thetex.texture.disable();
85188592 thetex.texture.dispose();
8519
- textures.remove(texname);
8593
+ textures.remove(tex);
85208594 }
85218595
85228596 //texture.texturedata = texturedata;
8523
- textures.put(texname, texturecache);
8597
+ textures.put(tex, texturecache);
85248598
85258599 // newtex = true;
85268600 }
....@@ -8541,12 +8615,41 @@
85418615
85428616 static void EmbedTextures(cTexture tex)
85438617 {
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
+ }
85448634
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
+ }
85458648 }
85468649
8547
- com.sun.opengl.util.texture.Texture GetTexture(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception
8650
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
85488651 {
8549
- CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution);
8652
+ CacheTexture texture = GetCacheTexture(tex, bump, resolution);
85508653
85518654 if (bump)
85528655 {
....@@ -8562,14 +8665,14 @@
85628665 return texture!=null?texture.texture:null;
85638666 }
85648667
8565
- public com.sun.opengl.util.texture.TextureData GetTextureData(java.awt.image.BufferedImage stream, 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
85668669 {
8567
- CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution);
8670
+ CacheTexture texture = GetCacheTexture(tex, bump, resolution);
85688671
85698672 return texture!=null?texture.texturedata:null;
85708673 }
85718674
8572
- boolean BindTexture(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception
8675
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
85738676 {
85748677 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
85758678 {
....@@ -8578,7 +8681,7 @@
85788681
85798682 //boolean newtex = false;
85808683
8581
- com.sun.opengl.util.texture.Texture texture = GetTexture(stream, tex, bump, resolution);
8684
+ com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
85828685
85838686 if (texture == null)
85848687 return false;
....@@ -8611,6 +8714,72 @@
86118714 return true; // Warning: not used.
86128715 }
86138716
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
+
86148783 ShadowBuffer shadowPBuf;
86158784 AntialiasBuffer antialiasPBuf;
86168785 int MAXSTACK;
....@@ -8627,10 +8796,12 @@
86278796
86288797 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
86298798 MAXSTACK = temp[0];
8630
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8799
+ if (Globals.DEBUG)
8800
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
86318801 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
86328802 MAXSTACK = temp[0];
8633
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8803
+ if (Globals.DEBUG)
8804
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
86348805
86358806 // Use debug pipeline
86368807 //drawable.setGL(new DebugGL(gl)); //
....@@ -8638,7 +8809,8 @@
86388809 gl = drawable.getGL(); //
86398810
86408811 GL gl3 = getGL();
8641
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8812
+ if (Globals.DEBUG)
8813
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
86428814
86438815
86448816 //float pos[] = { 100, 100, 100, 0 };
....@@ -8803,7 +8975,7 @@
88038975
88048976 if (cubemap == null)
88058977 {
8806
- LoadEnvy(5);
8978
+ //LoadEnvy(1);
88078979 }
88088980
88098981 //cubemap.enable();
....@@ -9079,6 +9251,8 @@
90799251
90809252 void LoadEnvy(int which)
90819253 {
9254
+ assert(false);
9255
+
90829256 String name;
90839257 String ext;
90849258
....@@ -9090,37 +9264,58 @@
90909264 cubemap = null;
90919265 return;
90929266 case 1:
9093
- name = "cubemaps/box_";
9094
- ext = "png";
9267
+ name = "cubemaps/rgb/";
9268
+ ext = "jpg";
90959269 reverseUP = false;
90969270 break;
90979271 case 2:
9098
- name = "cubemaps/uffizi_";
9099
- ext = "png";
9100
- break; // reverseUP = true; break;
9272
+ name = "cubemaps/uffizi/";
9273
+ ext = "jpg";
9274
+ reverseUP = false;
9275
+ break;
91019276 case 3:
9102
- name = "cubemaps/CloudyHills_";
9103
- ext = "tga";
9277
+ name = "cubemaps/CloudyHills/";
9278
+ ext = "jpg";
91049279 reverseUP = false;
91059280 break;
91069281 case 4:
9107
- name = "cubemaps/cornell_";
9282
+ name = "cubemaps/cornell/";
91089283 ext = "png";
91099284 reverseUP = false;
91109285 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;
91119311 default:
9112
- name = "cubemaps/rgb_";
9113
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9312
+ name = "cubemaps/box/";
9313
+ ext = "png"; /*mipmap = true;*/
9314
+ reverseUP = false;
91149315 break;
91159316 }
9116
-
9117
- try
9118
- {
9119
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
9120
- } catch (IOException e)
9121
- {
9122
- throw new RuntimeException(e);
9123
- }
9317
+
9318
+ LoadSkybox(name, ext, mipmap);
91249319 }
91259320
91269321 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -9152,8 +9347,12 @@
91529347 static double[] model = new double[16];
91539348 double[] camera2light = new double[16];
91549349 double[] light2camera = new double[16];
9155
- int newenvy = -1;
9156
- boolean envyoff = true; // false;
9350
+
9351
+ //int newenvy = -1;
9352
+ //boolean envyoff = false;
9353
+
9354
+ String loadedskyboxname;
9355
+
91579356 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
91589357 //float[] light0 = { 0,0,0 };
91599358 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9571,7 +9770,7 @@
95719770
95729771 if (renderCamera != lightCamera)
95739772 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9574
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
9773
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
95759774
95769775 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
95779776
....@@ -9587,7 +9786,7 @@
95879786
95889787 if (renderCamera != lightCamera)
95899788 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9590
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
9789
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
95919790
95929791 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
95939792
....@@ -9633,10 +9832,12 @@
96339832 rati = 1 / rati;
96349833 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
96359834 }
9636
- assert (newenvy == -1);
9835
+
9836
+ //assert (newenvy == -1);
9837
+
96379838 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
96389839 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9639
- DrawSkyBox(gl);
9840
+ DrawSkyBox(gl, (float)rati);
96409841 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
96419842 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
96429843 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10502,9 +10703,18 @@
1050210703 static boolean init = false;
1050310704
1050410705 double[][] matrix = LA.newMatrix();
10706
+
10707
+ // This is to refresh the UI of the material panel.
10708
+ ObjEditor patchMaterial;
1050510709
1050610710 public void display(GLAutoDrawable drawable)
1050710711 {
10712
+ if (patchMaterial.patchMaterial)
10713
+ {
10714
+ patchMaterial.patchMaterial = false;
10715
+ patchMaterial.objectPanel.setSelectedIndex(1);
10716
+ }
10717
+
1050810718 if (Grafreed.savesound && Grafreed.hassound)
1050910719 {
1051010720 Grafreed.wav.save();
....@@ -10673,7 +10883,7 @@
1067310883
1067410884 if (wait)
1067510885 {
10676
- Sleep(500);
10886
+ Sleep(200); // blocks everything
1067710887
1067810888 wait = false;
1067910889 }
....@@ -10788,7 +10998,7 @@
1078810998 // if (parentcam != renderCamera) // not a light
1078910999 if (cam != lightCamera)
1079011000 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10791
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
11001
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1079211002
1079311003 for (int j = 0; j < 4; j++)
1079411004 {
....@@ -10803,7 +11013,7 @@
1080311013 // if (parentcam != renderCamera) // not a light
1080411014 if (cam != lightCamera)
1080511015 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10806
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
11016
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1080711017
1080811018 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1080911019
....@@ -10889,13 +11099,43 @@
1088911099 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1089011100 }
1089111101
10892
- 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"))
1089311110 {
10894
- LoadEnvy(newenvy);
11111
+ if (cubemaprgb == null)
11112
+ {
11113
+ cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb2" + "/", "jpg", false);
11114
+ }
11115
+
11116
+ cubemap = cubemaprgb;
1089511117 }
10896
-
10897
- newenvy = -1;
10898
-
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
+
1089911139 ratio = ((double) getWidth()) / getHeight();
1090011140 //System.out.println("ratio = " + ratio);
1090111141
....@@ -10911,7 +11151,7 @@
1091111151
1091211152 if (!IsFrozen() && !ambientOcclusion)
1091311153 {
10914
- DrawSkyBox(gl);
11154
+ DrawSkyBox(gl, (float)ratio);
1091511155 }
1091611156
1091711157 //if (selection_view == -1)
....@@ -11065,7 +11305,7 @@
1106511305
1106611306 try
1106711307 {
11068
- BindTexture(null, NOISE_TEXTURE, false, 2);
11308
+ BindTexture(NOISE_TEXTURE, false, 2);
1106911309 }
1107011310 catch (Exception e)
1107111311 {
....@@ -11197,7 +11437,7 @@
1119711437
1119811438 // if (cam != lightCamera)
1119911439 //for (int count = parentcam.GetTransformCount(); --count>=0;)
11200
- LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
11440
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1120111441 }
1120211442
1120311443 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -11356,7 +11596,7 @@
1135611596 }
1135711597 }
1135811598
11359
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11599
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1136011600 {
1136111601 //gl.glDepthFunc(GL.GL_LEQUAL);
1136211602 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11364,24 +11604,21 @@
1136411604
1136511605 boolean texon = textureon;
1136611606
11367
- if (RENDERPROGRAM > 0)
11368
- {
11369
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11370
- textureon = false;
11371
- }
11607
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11608
+ textureon = false;
11609
+
1137211610 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1137311611 //System.out.println("ALLO");
1137411612 gl.glColorMask(false, false, false, false);
1137511613 DrawObject(gl);
11376
- if (RENDERPROGRAM > 0)
11377
- {
11378
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11379
- textureon = texon;
11380
- }
11614
+
11615
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11616
+ textureon = texon;
11617
+
1138111618 gl.glColorMask(true, true, true, true);
1138211619
1138311620 gl.glDepthFunc(GL.GL_EQUAL);
11384
- //gl.glDepthMask(false);
11621
+ gl.glDepthMask(false);
1138511622 }
1138611623
1138711624 if (false) // DrawMode() == SHADOW)
....@@ -11721,20 +11958,32 @@
1172111958 ReleaseTextures(DEFAULT_TEXTURES);
1172211959
1172311960 if (CLEANCACHE)
11724
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11961
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1172511962 {
11726
- String tex = e.nextElement();
11963
+ cTexture tex = e.nextElement();
1172711964
1172811965 // System.out.println("Texture --------- " + tex);
1172911966
11730
- if (tex.equals("WHITE_NOISE"))
11967
+ if (tex.equals("WHITE_NOISE:"))
1173111968 continue;
1173211969
1173311970 if (!usedtextures.contains(tex))
1173411971 {
11972
+ CacheTexture gettex = texturepigment.get(tex);
1173511973 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11736
- textures.get(tex).texture.dispose();
11737
- 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
+ }
1173811987 }
1173911988 }
1174011989 }
....@@ -12262,8 +12511,82 @@
1226212511
1226312512 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1226412513
12265
- String program =
12514
+ String programmin =
12515
+ // Min shader
1226612516 "!!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
+
1226712590 //"OPTION ARB_fragment_program_shadow;" +
1226812591 "PARAM light2cam0 = program.env[10];" +
1226912592 "PARAM light2cam1 = program.env[11];" +
....@@ -12289,7 +12612,7 @@
1228912612 "PARAM params4 = program.env[4];" + // anisoV, cameralight, selfshadow, shadow
1229012613 "PARAM params5 = program.env[5];" + // texture, opacity, fakedepth, shadowbias
1229112614 "PARAM params6 = program.env[6];" + // bump, noise, borderfade, fog punchthrough
12292
- "PARAM params7 = program.env[7];" + // noise power, opacity power
12615
+ "PARAM params7 = program.env[7];" + // noise power, opacity power, parallax
1229312616 "PARAM options0 = program.env[63];" + // fog density, intensity, elevation
1229412617 "PARAM options1 = program.env[62];" + // fog rgb color
1229512618 "PARAM options2 = program.env[61];" + // image intensity, subsurface, lightsheen
....@@ -12378,8 +12701,7 @@
1237812701 "TEMP shininess;" +
1237912702 "\n" +
1238012703 "MOV texSamp, one;" +
12381
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12382
-
12704
+
1238312705 "MOV mapgrid.x, one2048th.x;" +
1238412706 "MOV temp, fragment.texcoord[1];" +
1238512707 /*
....@@ -12400,20 +12722,20 @@
1240012722 "MUL temp, floor, mapgrid.x;" +
1240112723 //"TEX depth0, temp, texture[1], 2D;" +
1240212724 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12403
- TextureFetch("depth0", "temp", "1") +
12725
+ ShadowTextureFetch("depth0", "temp", "1") +
1240412726 "") +
1240512727 "ADD temp.x, temp.x, mapgrid.x;" +
1240612728 //"TEX depth1, temp, texture[1], 2D;" +
1240712729 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12408
- TextureFetch("depth1", "temp", "1") +
12730
+ ShadowTextureFetch("depth1", "temp", "1") +
1240912731 "") +
1241012732 "ADD temp.y, temp.y, mapgrid.x;" +
1241112733 //"TEX depth2, temp, texture[1], 2D;" +
12412
- TextureFetch("depth2", "temp", "1") +
12734
+ ShadowTextureFetch("depth2", "temp", "1") +
1241312735 "SUB temp.x, temp.x, mapgrid.x;" +
1241412736 //"TEX depth3, temp, texture[1], 2D;" +
1241512737 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12416
- TextureFetch("depth3", "temp", "1") +
12738
+ ShadowTextureFetch("depth3", "temp", "1") +
1241712739 "") +
1241812740 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1241912741 //"MOV params, material;" +
....@@ -12535,7 +12857,7 @@
1253512857 "POW texSamp.a, texSamp.a, params6.w;" + // fog punch through shortcut
1253612858 // mar 2013 ??? "KIL alpha.a;" +
1253712859 "MOV alpha, texSamp.aaaa;" + // y;" +
12538
- "KIL alpha.a;" +
12860
+ "KIL alpha.a;" + // not sure with parallax mapping
1253912861 /*
1254012862 "MUL temp.xy, temp, two;" +
1254112863 "TXB bump, temp, texture[0], 2D;" +
....@@ -12621,11 +12943,6 @@
1262112943 "SUB bump0, bump0, half;" +
1262212944 "ADD bump, bump, bump0;" +
1262312945
12624
- "MOV temp.x, texSamp.a;" +
12625
- "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
12626
- //"LRP texSamp0, params5.x, texSamp0, one;" +
12627
- "MOV texSamp.a, temp.x;" +
12628
-
1262912946 // double-sided
1263012947 /**/
1263112948 (doublesided?"DP3 temp.z, normal, eye;" +
....@@ -12635,26 +12952,73 @@
1263512952 "ADD temp.x, temp.x, one.x;" +
1263612953 "MUL normal, normal, temp.xxxx;":""
1263712954 ) +
12638
- /**/
12639
-//// Normalize("normal") +
12640
-//// "MAX normal.z, eps.x, normal.z;" +
12641
-// Normalize("normal") +
12642
- "MOV normald, normal;" +
12643
- "MOV normals, normal;" +
12955
+ /**/
12956
+
12957
+ "MOV temp, fragment.texcoord[4];" +
1264412958
1264512959 // UV base
1264612960 //"DP3 UP.x,state.matrix.modelview.row[0],Y;" +
1264712961 //"DP3 UP.y,state.matrix.modelview.row[1],Y;" +
1264812962 //"DP3 UP.z,state.matrix.modelview.row[2],Y;" +
12649
- "DP3 UP.x,state.matrix.texture[7].row[0],Y;" +
12650
- "DP3 UP.y,state.matrix.texture[7].row[1],Y;" +
12651
- "DP3 UP.z,state.matrix.texture[7].row[2],Y;" +
12963
+ "DP3 UP.x,state.matrix.texture[7].row[0],temp;" +
12964
+ "DP3 UP.y,state.matrix.texture[7].row[1],temp;" +
12965
+ "DP3 UP.z,state.matrix.texture[7].row[2],temp;" +
12966
+ Normalize("UP") +
12967
+
1265212968 "XPD V, normal, UP;" +
1265312969 Normalize("V") +
1265412970 "XPD U, V, normal;" +
1265512971 Normalize("U") +
1265612972
12973
+ "MOV temp, fragment.texcoord[0];" +
12974
+
12975
+// "MAD normal, -temp.x, U, normal;" +
12976
+// "MAD normal, -temp.y, V, normal;" +
12977
+// Normalize("normal") +
12978
+
12979
+//// "MAX normal.z, eps.x, normal.z;" +
12980
+// Normalize("normal") +
12981
+ "MOV normald, normal;" +
12982
+ "MOV normals, normal;" +
12983
+
1265712984 // parallax mapping
12985
+
12986
+ "DP3 temp2.x, V, eye;" +
12987
+ "DP3 temp2.y, U, eye;" +
12988
+ "DP3 temp2.z, normal, eye;" +
12989
+ "RCP temp2.z, temp2.z;" +
12990
+
12991
+ "DP3 temp2.w, texSamp, texSamp;" + // Height
12992
+ "RSQ temp2.w, temp2.w;" +
12993
+ "RCP temp2.w, temp2.w;" +
12994
+
12995
+ "SUB temp2.w, temp2.w, half;" +
12996
+ // "SGE temp.x, temp2.w, eps.x;" +
12997
+ // "MUL temp2.w, temp2.w, temp.x;" +
12998
+
12999
+ // "MOV texSamp, U;" +
13000
+
13001
+ "MUL temp2.z, temp2.z, temp2.w;" +
13002
+ "MUL temp2.z, temp2.z, params7.z;" + // parallax
13003
+
13004
+ "MUL temp2, temp2, temp2.z;" +
13005
+
13006
+ "SUB temp, temp, temp2;" +
13007
+
13008
+ "TEX temp, temp, texture[0], 2D;" +
13009
+ "POW temp.a, temp.a, params6.w;" + // punch through
13010
+
13011
+ "ADD texSamp, temp, texSamp;" +
13012
+ "MUL texSamp.xyz, half, texSamp;" +
13013
+
13014
+ "MOV alpha, texSamp.aaaa;" +
13015
+
13016
+// parallax mapping
13017
+
13018
+ "MOV temp.x, texSamp.a;" +
13019
+ "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
13020
+ //"LRP texSamp0, params5.x, texSamp0, one;" +
13021
+ "MOV texSamp.a, temp.x;" +
1265813022
1265913023 //"MOV temp, fragment.texcoord[0];" +
1266013024 //
....@@ -12784,10 +13148,10 @@
1278413148 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1278513149 "") +
1278613150
12787
- // display shadow only (bump == 0)
13151
+ // display shadow only (fakedepth == 0)
1278813152 "SUB temp.x, half.x, shadow.x;" +
1278913153 "MOV temp.y, -params5.z;" + // params6.x;" +
12790
- "SLT temp.z, temp.y, -one2048th.x;" +
13154
+ "SLT temp.z, temp.y, -c256i.x;" +
1279113155 "SUB temp.y, one.x, temp.z;" +
1279213156 "MUL temp.x, temp.x, temp.y;" +
1279313157 "KIL temp.x;" +
....@@ -13118,8 +13482,19 @@
1311813482 //once = true;
1311913483 }
1312013484
13121
- System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13122
- System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13485
+ String program = programmax;
13486
+
13487
+ if (Globals.MINSHADER)
13488
+ {
13489
+ program = programmin;
13490
+ }
13491
+
13492
+ if (Globals.DEBUG)
13493
+ {
13494
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13495
+ System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13496
+ }
13497
+
1312313498 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1312413499
1312513500 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -13166,7 +13541,8 @@
1316613541 "\n" +
1316713542 "END\n";
1316813543
13169
- System.out.println("Program shadow #" + 0 + "; length = " + program.length());
13544
+ if (Globals.DEBUG)
13545
+ System.out.println("Program shadow #" + 0 + "; length = " + program.length());
1317013546 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1317113547
1317213548 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -13211,25 +13587,26 @@
1321113587 return out;
1321213588 }
1321313589
13214
- String TextureFetch(String dest, String src, String unit)
13590
+ // Also does frustum culling
13591
+ String ShadowTextureFetch(String dest, String src, String unit)
1321513592 {
1321613593 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1321713594 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1321813595 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13596
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13597
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1321913598 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13220
- "SLT " + src + ".z, " + src + ".x, one.x;" +
13221
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13222
- "SLT " + src + ".z, " + src + ".y, one.x;" +
13223
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13599
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13600
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1322413601 //"SWZ buffer, temp, w,w,w,w;";
13225
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13602
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1322613603 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1322713604 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1322813605 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13229
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13606
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1323013607
13231
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13232
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13608
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13609
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1323313610 }
1323413611
1323513612 String Shadow(String depth, String shadow)
....@@ -13276,7 +13653,7 @@
1327613653 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1327713654 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1327813655
13279
- // No shadow when out of frustrum
13656
+ // No shadow when out of frustum
1328013657 "SGE temp.x, " + depth + ".z, one.z;" +
1328113658 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1328213659 "";
....@@ -13423,7 +13800,7 @@
1342313800 /*static*/ float[] modelParams4 = new float[]{0, 0, 0, 0}; // anisoV, cameralight, selfshadow, shadow
1342413801 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1342513802 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
13426
- /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13803
+ /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power, parallax
1342713804
1342813805 //Object3D.cVector2[] vector2buffer;
1342913806
....@@ -13590,7 +13967,7 @@
1359013967 "PARAM p[4] = { state.matrix.projection }; # modelview projection matrix\n" +
1359113968 "PARAM zero = { 0.0, 0.0, 0.0, 1.0 };" +
1359213969 "PARAM half = { 0.5, 0.5, 0.5, 1.0 };" +
13593
- "PARAM one = { 1.0, 1.0, 1.0, 0.0 };" +
13970
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
1359413971 "PARAM two = { 2.0, 2.0, 2.0, 1.0 };" +
1359513972 "PARAM third = { 0.33333333333, 0.33333333333, 0.33333333333, 1.0 };" +
1359613973 //"PARAM v256 = { 256.0, 256.0, 256.0, 1.0 };" +
....@@ -13651,7 +14028,7 @@
1365114028 "DP4 temp.x,state.matrix.texture[0].inverse.row[0],vertex.texcoord;" +
1365214029 "DP4 temp.y,state.matrix.texture[0].inverse.row[1],vertex.texcoord;" +
1365314030 "DP4 temp.z,state.matrix.texture[0].inverse.row[2],vertex.texcoord;" +
13654
- //"MOV result.texcoord, vertex.texcoord;" +
14031
+ //"MOV result.texcoord, vertex.fogcoord;" +
1365514032 "MOV result.texcoord, temp;" +
1365614033 // border fade
1365714034 "MOV result.texcoord[3], vertex.texcoord;" +
....@@ -13698,7 +14075,9 @@
1369814075
1369914076 //"ADD temp.z, temp.z, one;" +
1370014077
13701
- "MOV result.color, temp;"
14078
+ "MOV result.texcoord[4], vertex.attrib[4];" + // U dir
14079
+
14080
+ "MOV result.color, temp;" // Normal
1370214081 : "MOV result.color, vertex.color;") +
1370314082 ((mode & VP_PROJECTION) != 0 ? "MOV result.color, zero;"
1370414083 : "") +
....@@ -14074,14 +14453,15 @@
1407414453 drag = false;
1407514454 //System.out.println("Mouse DOWN");
1407614455 editObj = false;
14077
- ClickInfo info = new ClickInfo();
14078
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14079
- info.pane = this;
14080
- info.camera = renderCamera;
14081
- info.x = x;
14082
- info.y = y;
14083
- info.modifiers = modifiersex;
14084
- editObj = object.doEditClick(info, 0);
14456
+ //ClickInfo info = new ClickInfo();
14457
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14458
+ object.clickInfo.pane = this;
14459
+ object.clickInfo.camera = renderCamera;
14460
+ object.clickInfo.x = x;
14461
+ object.clickInfo.y = y;
14462
+ object.clickInfo.modifiers = modifiersex;
14463
+ editObj = object.doEditClick(//info,
14464
+ 0);
1408514465 if (!editObj)
1408614466 {
1408714467 hasMarquee = true;
....@@ -14356,18 +14736,24 @@
1435614736 }
1435714737 }
1435814738 PingThread pingthread = new PingThread();
14359
- int delta = 5;
14360
- int speed = 5;
14739
+ int delta = 2;
14740
+ int speed = 10;
1436114741 boolean autorepeat = false;
1436214742
1436314743 void GoDown(int mod)
1436414744 {
1436514745 MODIFIERS |= COMMAND;
14746
+ boolean isVR = (mouseMode&VR)!=0;
1436614747 /**/
1436714748 if((mod&SHIFT) == SHIFT)
14368
- manipCamera.RotatePosition(0, -speed);
14749
+ {
14750
+ if (isVR)
14751
+ manipCamera.RotateInterest(0, -speed);
14752
+ else
14753
+ manipCamera.RotatePosition(0, -speed);
14754
+ }
1436914755 else
14370
- manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14756
+ manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth());
1437114757 /**/
1437214758 if ((mod & SHIFT) == SHIFT)
1437314759 {
....@@ -14377,6 +14763,8 @@
1437714763 mouseMode |= BACKFORTH;
1437814764 }
1437914765
14766
+ targetLookAt.set(manipCamera.lookAt);
14767
+
1438014768 //prevX = X = anchorX;
1438114769 prevY = Y = anchorY - (int) (renderCamera.Distance());
1438214770 }
....@@ -14385,10 +14773,17 @@
1438514773 {
1438614774 MODIFIERS |= COMMAND;
1438714775 /**/
14776
+ boolean isVR = (mouseMode&VR)!=0;
14777
+
1438814778 if((mod&SHIFT) == SHIFT)
14389
- manipCamera.RotatePosition(0, speed);
14779
+ {
14780
+ if (isVR)
14781
+ manipCamera.RotateInterest(0, speed);
14782
+ else
14783
+ manipCamera.RotatePosition(0, speed);
14784
+ }
1439014785 else
14391
- manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14786
+ manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth());
1439214787 /**/
1439314788 if ((mod & SHIFT) == SHIFT)
1439414789 {
....@@ -14398,6 +14793,8 @@
1439814793 mouseMode |= BACKFORTH;
1439914794 }
1440014795
14796
+ targetLookAt.set(manipCamera.lookAt);
14797
+
1440114798 //prevX = X = anchorX;
1440214799 prevY = Y = anchorY + (int) (renderCamera.Distance());
1440314800 }
....@@ -14407,9 +14804,14 @@
1440714804 MODIFIERS |= COMMAND;
1440814805 /**/
1440914806 if((mod&SHIFT) == SHIFT)
14410
- manipCamera.Translate(speed*delta, 0, getWidth());
14807
+ manipCamera.Translate(speed*delta, 0, getWidth());
1441114808 else
14412
- manipCamera.RotatePosition(speed, 0);
14809
+ {
14810
+ if ((mouseMode&VR)!=0)
14811
+ manipCamera.RotateInterest(-speed, 0);
14812
+ else
14813
+ manipCamera.RotatePosition(speed, 0);
14814
+ }
1441314815 /**/
1441414816 if ((mod & SHIFT) == SHIFT)
1441514817 {
....@@ -14419,6 +14821,8 @@
1441914821 mouseMode |= ROTATE;
1442014822 } // TRANSLATE;
1442114823
14824
+ targetLookAt.set(manipCamera.lookAt);
14825
+
1442214826 prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance());
1442314827 prevY = Y = anchorY;
1442414828 }
....@@ -14428,9 +14832,15 @@
1442814832 MODIFIERS |= COMMAND;
1442914833 /**/
1443014834 if((mod&SHIFT) == SHIFT)
14431
- manipCamera.Translate(-speed*delta, 0, getWidth());
14835
+ manipCamera.Translate(-speed*delta, 0, getWidth());
1443214836 else
14433
- manipCamera.RotatePosition(-speed, 0);
14837
+ {
14838
+ if ((mouseMode&VR)!=0)
14839
+ manipCamera.RotateInterest(speed, 0);
14840
+ else
14841
+ manipCamera.RotatePosition(-speed, 0);
14842
+ }
14843
+
1443414844 /**/
1443514845 if ((mod & SHIFT) == SHIFT)
1443614846 {
....@@ -14440,6 +14850,8 @@
1444014850 mouseMode |= ROTATE;
1444114851 } // TRANSLATE;
1444214852
14853
+ targetLookAt.set(manipCamera.lookAt);
14854
+
1444314855 prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance());
1444414856 prevY = Y = anchorY;
1444514857 }
....@@ -14481,15 +14893,16 @@
1448114893 if (editObj)
1448214894 {
1448314895 drag = true;
14484
- ClickInfo info = new ClickInfo();
14485
- info.bounds.setBounds(0, 0,
14896
+ //ClickInfo info = new ClickInfo();
14897
+ object.clickInfo.bounds.setBounds(0, 0,
1448614898 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14487
- info.pane = this;
14488
- info.camera = renderCamera;
14489
- info.x = x;
14490
- info.y = y;
14491
- object.GetWindow().copy
14492
- .doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
14899
+ object.clickInfo.pane = this;
14900
+ object.clickInfo.camera = renderCamera;
14901
+ object.clickInfo.x = x;
14902
+ object.clickInfo.y = y;
14903
+ object //.GetWindow().copy
14904
+ .doEditDrag(//info,
14905
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1449314906 } else
1449414907 {
1449514908 if (x < startX)
....@@ -14638,24 +15051,27 @@
1463815051 }
1463915052 }
1464015053
15054
+// ClickInfo clickInfo = new ClickInfo();
15055
+
1464115056 public void mouseMoved(MouseEvent e)
1464215057 {
1464315058 //System.out.println("mouseMoved: " + e);
1464415059 if (isRenderer)
1464515060 return;
1464615061
14647
- ClickInfo ci = new ClickInfo();
14648
- ci.x = e.getX();
14649
- ci.y = e.getY();
14650
- ci.modifiers = e.getModifiersEx();
14651
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14652
- ci.pane = this;
14653
- ci.camera = renderCamera;
15062
+ // Mouse cursor feedback
15063
+ object.clickInfo.x = e.getX();
15064
+ object.clickInfo.y = e.getY();
15065
+ object.clickInfo.modifiers = e.getModifiersEx();
15066
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
15067
+ object.clickInfo.pane = this;
15068
+ object.clickInfo.camera = renderCamera;
1465415069 if (!isRenderer)
1465515070 {
1465615071 //ObjEditor editWindow = object.editWindow;
1465715072 //Object3D copy = editWindow.copy;
14658
- if (object.doEditClick(ci, 0))
15073
+ if (object.doEditClick(//clickInfo,
15074
+ 0))
1465915075 {
1466015076 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1466115077 } else
....@@ -14927,7 +15343,8 @@
1492715343 // break;
1492815344 case 'T':
1492915345 CACHETEXTURE ^= true;
14930
- textures.clear();
15346
+ texturepigment.clear();
15347
+ texturebump.clear();
1493115348 // repaint();
1493215349 break;
1493315350 case 'Y':
....@@ -14937,8 +15354,8 @@
1493715354 case 'K':
1493815355 KOMPACTTEXTURE ^= true;
1493915356 //textures.clear();
14940
- break;
14941
- case 'P': // Texture Projection macros
15357
+ // break;
15358
+ //case 'P': // Texture Projection macros
1494215359 // SAVETEXTURE ^= true;
1494315360 macromode = true;
1494415361 Udebug = Vdebug = NORMALdebug = false; programInitialized = false;
....@@ -15059,7 +15476,7 @@
1505915476 targetLookAt.set(manipCamera.lookAt);
1506015477 repaint();
1506115478 break;
15062
- case 'p':
15479
+ case 'P': // p':
1506315480 // c'est quoi ca au juste? spherical ^= true;
1506415481 Skinshader ^= true; programInitialized = false;
1506515482 repaint();
....@@ -15097,27 +15514,31 @@
1509715514 repaint();
1509815515 break;
1509915516 case 'O':
15100
- Globals.drawMode = OCCLUSION; // WARNING
15517
+ // Too dangerous. Use menu. Globals.drawMode = OCCLUSION; // WARNING
1510115518 repaint();
1510215519 break;
1510315520 case 'o':
1510415521 OCCLUSION_CULLING ^= true;
1510515522 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1510615523 break;
15107
- case '0': envyoff ^= true; repaint(); break;
15524
+ //case '0': envyoff ^= true; repaint(); break;
1510815525 case '1':
1510915526 case '2':
1511015527 case '3':
1511115528 case '4':
1511215529 case '5':
15113
- newenvy = Character.getNumericValue(key);
15114
- repaint();
15115
- break;
1511615530 case '6':
1511715531 case '7':
1511815532 case '8':
1511915533 case '9':
15120
- BGcolor = (key - '6')/3.f;
15534
+ if (true) // envyoff)
15535
+ {
15536
+ BGcolor = (key - '1')/8.f;
15537
+ }
15538
+ else
15539
+ {
15540
+ //newenvy = Character.getNumericValue(key);
15541
+ }
1512115542 repaint();
1512215543 break;
1512315544 case '!':
....@@ -15680,8 +16101,6 @@
1568016101
1568116102 int width = getBounds().width;
1568216103 int height = getBounds().height;
15683
- ClickInfo info = new ClickInfo();
15684
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1568516104 //Image img = CreateImage(width, height);
1568616105 //System.out.println("width = " + width + "; height = " + height + "\n");
1568716106
....@@ -15758,31 +16177,37 @@
1575816177 }
1575916178 if (object != null && !hasMarquee)
1576016179 {
16180
+ if (object.clickInfo == null)
16181
+ object.clickInfo = new ClickInfo();
16182
+ ClickInfo info = object.clickInfo;
16183
+ //ClickInfo info = new ClickInfo();
16184
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16185
+
1576116186 if (isRenderer)
1576216187 {
15763
- info.flags++;
16188
+ object.clickInfo.flags++;
1576416189 double frameAspect = (double) width / (double) height;
1576516190 if (frameAspect > renderCamera.aspect)
1576616191 {
1576716192 int desired = (int) ((double) height * renderCamera.aspect);
15768
- info.bounds.width -= width - desired;
15769
- info.bounds.x += (width - desired) / 2;
16193
+ object.clickInfo.bounds.width -= width - desired;
16194
+ object.clickInfo.bounds.x += (width - desired) / 2;
1577016195 } else
1577116196 {
1577216197 int desired = (int) ((double) width / renderCamera.aspect);
15773
- info.bounds.height -= height - desired;
15774
- info.bounds.y += (height - desired) / 2;
16198
+ object.clickInfo.bounds.height -= height - desired;
16199
+ object.clickInfo.bounds.y += (height - desired) / 2;
1577516200 }
1577616201 }
1577716202
15778
- info.g = gr;
15779
- info.camera = renderCamera;
16203
+ object.clickInfo.g = gr;
16204
+ object.clickInfo.camera = renderCamera;
1578016205 /*
1578116206 // Memory intensive (brep.verticescopy)
1578216207 if (!(object instanceof Composite))
1578316208 object.draw(info, 0, false); // SLOW :
1578416209 */
15785
- if (!isRenderer)
16210
+ if (!isRenderer) // && drag)
1578616211 {
1578716212 Grafreed.Assert(object != null);
1578816213 Grafreed.Assert(object.selection != null);
....@@ -15790,9 +16215,9 @@
1579016215 {
1579116216 int hitSomething = object.selection.get(0).hitSomething;
1579216217
15793
- info.DX = 0;
15794
- info.DY = 0;
15795
- info.W = 1;
16218
+ object.clickInfo.DX = 0;
16219
+ object.clickInfo.DY = 0;
16220
+ object.clickInfo.W = 1;
1579616221 if (hitSomething == Object3D.hitCenter)
1579716222 {
1579816223 info.DX = X;
....@@ -15804,13 +16229,14 @@
1580416229 info.DY -= info.bounds.height/2;
1580516230 }
1580616231
15807
- object.drawEditHandles(info, 0);
16232
+ object.drawEditHandles(//info,
16233
+ 0);
1580816234
1580916235 if (drag && (X != 0 || Y != 0))
1581016236 {
1581116237 switch (hitSomething)
1581216238 {
15813
- case Object3D.hitCenter: gr.setColor(Color.pink);
16239
+ case Object3D.hitCenter: gr.setColor(Color.white);
1581416240 gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
1581516241 break;
1581616242 case Object3D.hitRotate: gr.setColor(Color.yellow);
....@@ -15836,7 +16262,7 @@
1583616262 if (hasMarquee)
1583716263 {
1583816264 gr.setXORMode(Color.white);
15839
- gr.setColor(Color.red);
16265
+ gr.setColor(Color.white);
1584016266 if (!firstime)
1584116267 {
1584216268 gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH);
....@@ -16303,6 +16729,8 @@
1630316729 private /*static*/ boolean firstime;
1630416730 private /*static*/ cVector newView = new cVector();
1630516731 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16732
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16733
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1630616734 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1630716735 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1630816736 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16315,29 +16743,67 @@
1631516743 {
1631616744 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1631716745
16746
+ int usedsuf = 0;
16747
+
1631816748 for (int i = 0; i < suffixes.length; i++)
1631916749 {
16320
- String resourceName = basename + suffixes[i] + "." + suffix;
16321
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16322
- mipmapped,
16323
- FileUtil.getFileSuffix(resourceName));
16324
- if (data == null)
16750
+ String[] suffixe = suffixes;
16751
+ String[] fallback = suffixes2;
16752
+ String[] fallfallback = suffixes3;
16753
+
16754
+ for (int c=usedsuf; --c>=0;)
1632516755 {
16326
- throw new IOException("Unable to load texture " + resourceName);
16756
+// String[] temp = suffixe;
16757
+// suffixe = fallback;
16758
+// fallback = fallfallback;
16759
+// fallfallback = temp;
1632716760 }
16761
+
16762
+ String resourceName = basename + suffixe[i] + "." + suffix;
16763
+ TextureData data;
16764
+
16765
+ try
16766
+ {
16767
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16768
+ mipmapped,
16769
+ FileUtil.getFileSuffix(resourceName));
16770
+ }
16771
+ catch (Exception e)
16772
+ {
16773
+ try
16774
+ {
16775
+ resourceName = basename + fallback[i] + "." + suffix;
16776
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16777
+ mipmapped,
16778
+ FileUtil.getFileSuffix(resourceName));
16779
+ }
16780
+ catch (Exception e2)
16781
+ {
16782
+ resourceName = basename + fallfallback[i] + "." + suffix;
16783
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16784
+ mipmapped,
16785
+ FileUtil.getFileSuffix(resourceName));
16786
+ }
16787
+ }
16788
+
1632816789 //System.out.println("Target = " + targets[i]);
1632916790 cubemap.updateImage(data, targets[i]);
1633016791 }
1633116792
1633216793 return cubemap;
1633316794 }
16795
+
1633416796 int bigsphere = -1;
1633516797
1633616798 float BGcolor = 0.5f;
1633716799
16338
- private void DrawSkyBox(GL gl)
16800
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16801
+
16802
+ private void DrawSkyBox(GL gl, float ratio)
1633916803 {
16340
- if (envyoff || cubemap == null)
16804
+ if (//envyoff ||
16805
+ WIREFRAME ||
16806
+ cubemap == null)
1634116807 {
1634216808 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1634316809 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16352,7 +16818,17 @@
1635216818 // Compensates for ExaminerViewer's modification of modelview matrix
1635316819 gl.glMatrixMode(GL.GL_MODELVIEW);
1635416820 gl.glLoadIdentity();
16821
+ gl.glScalef(1,ratio,1);
1635516822
16823
+// colorV[0] = 2;
16824
+// colorV[1] = 2;
16825
+// colorV[2] = 2;
16826
+// colorV[3] = 1;
16827
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16828
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16829
+//
16830
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16831
+
1635616832 //gl.glActiveTexture(GL.GL_TEXTURE1);
1635716833 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1635816834
....@@ -16384,6 +16860,7 @@
1638416860 {
1638516861 gl.glScalef(1.0f, -1.0f, 1.0f);
1638616862 }
16863
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1638716864 gl.glMultMatrixd(viewrot_1, 0);
1638816865 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1638916866 //viewer.updateInverseRotation(gl);
....@@ -16424,7 +16901,8 @@
1642416901 gl.glDisable(GL.GL_TEXTURE_GEN_R);
1642516902
1642616903 cubemap.disable();
16427
- ////cubemap.unbind();
16904
+ //cubemap.dispose();
16905
+
1642816906 if (CULLFACE)
1642916907 {
1643016908 gl.glEnable(gl.GL_CULL_FACE);
....@@ -16480,7 +16958,7 @@
1648016958 gl.glScalef(1.0f, -1.0f, 1.0f);
1648116959 }
1648216960
16483
- gl.glNormal3f(0.0f, 0.0f, 1.0f);
16961
+ SetGLNormal(gl, 0.0f, 0.0f, 1.0f);
1648416962
1648516963 float step = 2; // 0.1666f; //0.25f;
1648616964 float stepv = 2; // step * 1652 / 998;
....@@ -16642,7 +17120,7 @@
1664217120 //new Exception().printStackTrace();
1664317121 System.out.println("select buffer init");
1664417122 // Use debug pipeline
16645
- drawable.setGL(new DebugGL(drawable.getGL()));
17123
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1664617124
1664717125 GL gl = drawable.getGL();
1664817126
....@@ -16960,6 +17438,7 @@
1696017438
1696117439 public void init(GLAutoDrawable drawable)
1696217440 {
17441
+ if (Globals.DEBUG)
1696317442 System.out.println("shadow buffer init");
1696417443
1696517444 GL gl = drawable.getGL();
....@@ -17188,10 +17667,14 @@
1718817667 gl.glFlush();
1718917668
1719017669 /**/
17191
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17670
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1719217671
17193
- float[] pixels = occlusionsizebuffer.array();
17672
+ float[] depths = occlusiondepthbuffer.array();
1719417673
17674
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17675
+
17676
+ int[] pixels = selectsizebuffer.array();
17677
+
1719517678 double r = 0, g = 0, b = 0;
1719617679
1719717680 double count = 0;
....@@ -17202,7 +17685,7 @@
1720217685
1720317686 double FACTOR = 1;
1720417687
17205
- for (int i = 0; i < pixels.length; i++)
17688
+ for (int i = 0; i < depths.length; i++)
1720617689 {
1720717690 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1720817691 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -17285,7 +17768,7 @@
1728517768
1728617769 double scale = ray.z; // 1; // cos
1728717770
17288
- float depth = pixels[newindex];
17771
+ float depth = depths[newindex];
1728917772
1729017773 /*
1729117774 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -17482,11 +17965,14 @@
1748217965 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1748317966 static IntBuffer bigAAbuffer;
1748417967 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
17485
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17968
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1748617969 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1748717970 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1748817971 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17489
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17972
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17973
+
17974
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17975
+
1749017976 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1749117977 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1749217978 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();