Normand Briere
2019-08-22 0c7b833be7d86598a6813cd1c6db0ca9e1b17966
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)
....@@ -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,6 +2461,33 @@
24052461 return currentGL;
24062462 }
24072463
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
+
24082491 /**/
24092492 class CacheTexture
24102493 {
....@@ -2413,18 +2496,20 @@
24132496
24142497 int resolution;
24152498
2416
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2499
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
24172500 {
2418
- texture = tex;
2501
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2502
+ texturedata = texdata;
24192503 resolution = res;
24202504 }
24212505 }
24222506 /**/
24232507
24242508 // TEXTURE static Texture texture;
2425
- static public java.util.Hashtable<String, CacheTexture> textures = new java.util.Hashtable<String, CacheTexture>();
2426
- static public java.util.Hashtable<BufferedImage, CacheTexture> bimtextures = new java.util.Hashtable<BufferedImage, CacheTexture>();
2427
- 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>();
24282513
24292514 int pigmentdepth = 0;
24302515 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
....@@ -2432,10 +2517,10 @@
24322517 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
24332518 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
24342519 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2435
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2520
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
24362521 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
24372522
2438
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2523
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
24392524 {
24402525 TextureData texturedata = null;
24412526
....@@ -2445,7 +2530,7 @@
24452530 com.sun.opengl.util.texture.TextureIO.newTextureData(
24462531 getClass().getClassLoader().getResourceAsStream(name),
24472532 true,
2448
- com.sun.opengl.util.texture.TextureIO.PNG);
2533
+ GetFormat(name)); // com.sun.opengl.util.texture.TextureIO.PNG);
24492534 } catch (java.io.IOException e)
24502535 {
24512536 throw new javax.media.opengl.GLException(e);
....@@ -2454,16 +2539,16 @@
24542539 if (bump)
24552540 texturedata = ConvertBump(texturedata, false);
24562541
2457
- com.sun.opengl.util.texture.Texture texture =
2458
- 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);
24592544
2460
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2461
- 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);
24622547
2463
- return texture;
2548
+ return texturedata;
24642549 }
24652550
2466
- com.sun.opengl.util.texture.Texture GetBimTexture(BufferedImage name, boolean bump)
2551
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
24672552 {
24682553 TextureData texturedata = null;
24692554
....@@ -2471,7 +2556,7 @@
24712556 {
24722557 texturedata =
24732558 com.sun.opengl.util.texture.TextureIO.newTextureData(
2474
- name,
2559
+ bim,
24752560 true);
24762561 } catch (Exception e)
24772562 {
....@@ -2480,14 +2565,8 @@
24802565
24812566 if (bump)
24822567 texturedata = ConvertBump(texturedata, false);
2483
-
2484
- com.sun.opengl.util.texture.Texture texture =
2485
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2486
-
2487
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2488
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
2489
-
2490
- return texture;
2568
+
2569
+ return texturedata;
24912570 }
24922571
24932572 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -7975,8 +8054,8 @@
79758054 pigment = null;
79768055 }
79778056
7978
- ReleaseTexture(bump, true);
7979
- ReleaseTexture(pigment, false);
8057
+ ReleaseTexture(tex, true);
8058
+ ReleaseTexture(tex, false);
79808059 }
79818060
79828061 public void ReleasePigmentTexture(cTexture tex) // INTERFACE
....@@ -8005,7 +8084,7 @@
80058084 pigment = null;
80068085 }
80078086
8008
- ReleaseTexture(pigment, false);
8087
+ ReleaseTexture(tex, false);
80098088 }
80108089
80118090 public void ReleaseBumpTexture(cTexture tex) // INTERFACE
....@@ -8034,10 +8113,10 @@
80348113 bump = null;
80358114 }
80368115
8037
- ReleaseTexture(bump, true);
8116
+ ReleaseTexture(tex, true);
80388117 }
80398118
8040
- void ReleaseTexture(String tex, boolean bump)
8119
+ void ReleaseTexture(cTexture tex, boolean bump)
80418120 {
80428121 if (// DrawMode() != 0 || /*tex == null ||*/
80438122 ambientOcclusion ) // || !textureon)
....@@ -8048,7 +8127,7 @@
80488127 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
80498128
80508129 if (tex != null)
8051
- texture = textures.get(tex);
8130
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
80528131
80538132 // //assert( texture != null );
80548133 // if (texture == null)
....@@ -8198,13 +8277,13 @@
81988277
81998278 if (tex == null)
82008279 {
8201
- BindTexture(null, null,false,resolution);
8280
+ BindTexture(null,false,resolution);
82028281 return;
82038282 }
82048283
82058284 String pigment = Object3D.GetPigment(tex);
82068285
8207
- usedtextures.add(pigment);
8286
+ usedtextures.add(tex);
82088287
82098288 //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
82108289 {
....@@ -8218,7 +8297,7 @@
82188297 }
82198298
82208299 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8221
- BindTexture(tex.pigmenttexture, pigment, false, resolution);
8300
+ BindTexture(tex, false, resolution);
82228301 }
82238302
82248303 /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8231,13 +8310,13 @@
82318310
82328311 if (tex == null)
82338312 {
8234
- BindTexture(null, null,true,resolution);
8313
+ BindTexture(null,true,resolution);
82358314 return;
82368315 }
82378316
82388317 String bump = Object3D.GetBump(tex);
82398318
8240
- usedtextures.add(bump);
8319
+ usedtextures.add(tex);
82418320
82428321 //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
82438322 {
....@@ -8251,7 +8330,7 @@
82518330 }
82528331
82538332 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8254
- BindTexture(tex.bumptexture, bump, true, resolution);
8333
+ BindTexture(tex, true, resolution);
82558334 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
82568335 }
82578336
....@@ -8275,13 +8354,19 @@
82758354 return fileExists;
82768355 }
82778356
8278
- 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
82798358 {
82808359 CacheTexture texturecache = null;
82818360
82828361 if (tex != null)
82838362 {
8284
- 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
+ }
82858370
82868371 String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
82878372
....@@ -8291,29 +8376,46 @@
82918376 // else
82928377 // if (!texname.startsWith("/"))
82938378 // texname = "/Users/nbriere/Textures/" + texname;
8294
- if (!FileExists(tex))
8379
+ if (!FileExists(texname) && !texname.startsWith("@"))
82958380 {
82968381 texname = fallbackTextureName;
82978382 }
82988383
82998384 if (CACHETEXTURE)
83008385 {
8301
- if (bim == null)
8302
- texturecache = textures.get(texname); // TEXTURE CACHE
8386
+ if (texdata == null)
8387
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
83038388 else
8304
- texturecache = bimtextures.get(bim); // TEXTURE CACHE
8389
+ texturecache = bimtextures.get(texdata);
83058390 }
83068391
8307
- if (texturecache == null || texturecache.resolution < resolution)
8392
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
83088393 {
83098394 TextureData texturedata = null;
83108395
8311
- if (bim == null)
8396
+ if (texdata != null && textureon)
83128397 {
8398
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
83138399
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;
83148416 }
83158417 else
8316
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8418
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
83178419 {
83188420 assert(!bump);
83198421 // if (bump)
....@@ -8324,19 +8426,23 @@
83248426 // }
83258427 // else
83268428 // {
8327
- texturecache = textures.get(tex);
8429
+ // texturecache = textures.get(texname); // suspicious
83288430 if (texturecache == null)
83298431 {
83308432 texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
83318433 }
8434
+ else
8435
+ new Exception().printStackTrace();
83328436 // }
83338437 } else
8334
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8438
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
83358439 {
83368440 assert(bump);
8337
- texturecache = textures.get(tex);
8441
+ // texturecache = textures.get(texname); // suspicious
83388442 if (texturecache == null)
83398443 texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8444
+ else
8445
+ new Exception().printStackTrace();
83408446 } else
83418447 {
83428448 //if (tex.equals("IMMORTAL"))
....@@ -8344,11 +8450,22 @@
83448450 // texture = GetResourceTexture("default.png");
83458451 //} else
83468452 //{
8347
- if (tex.equals("WHITE_NOISE"))
8453
+ if (texname.endsWith("WHITE_NOISE"))
83488454 {
8349
- texturecache = textures.get(tex);
8455
+ // texturecache = textures.get(texname); // suspicious
83508456 if (texturecache == null)
83518457 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();
83528469 } else
83538470 {
83548471 if (textureon)
....@@ -8407,14 +8524,15 @@
84078524 if (texturedata == null)
84088525 throw new Exception();
84098526
8410
- texturecache = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8527
+ texturecache = new CacheTexture(texturedata,resolution);
84118528 //texture = GetTexture(tex, bump);
84128529 }
8530
+ }
84138531 }
84148532 //}
84158533 }
84168534
8417
- if (/*CACHETEXTURE &&*/ texturecache != null && textureon)
8535
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
84188536 {
84198537 //return false;
84208538
....@@ -8436,52 +8554,17 @@
84368554 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
84378555 if (!cachefile.exists())
84388556 {
8439
- // cache to disk
8440
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
8441
- //buffers[0].
8442
-
8443
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
8444
- int[] pixels = new int[bytebuf.capacity()/3];
8445
-
8446
- // squared size heuristic...
8447
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8557
+ //if (texturedata.getWidth() == texturedata.getHeight())
84488558 {
8449
- for (int i=pixels.length; --i>=0;)
8450
- {
8451
- int i3 = i*3;
8452
- pixels[i] = 0xFF;
8453
- pixels[i] <<= 8;
8454
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
8455
- pixels[i] <<= 8;
8456
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
8457
- pixels[i] <<= 8;
8458
- pixels[i] |= bytebuf.get(i3) & 0xFF;
8459
- }
8460
-
8461
- /*
8462
- int r=0,g=0,b=0,a=0;
8463
- for (int i=0; i<width; i++)
8464
- for (int j=0; j<height; j++)
8465
- {
8466
- int index = j*width+i;
8467
- int p = pixels[index];
8468
- a = ((p>>24) & 0xFF);
8469
- r = ((p>>16) & 0xFF);
8470
- g = ((p>>8) & 0xFF);
8471
- b = (p & 0xFF);
8472
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
8473
- }
8474
- /**/
8475
- int width = (int)Math.sqrt(pixels.length); // squared
8476
- int height = width;
8477
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
8478
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8559
+ BufferedImage rendImage = CreateBim(texturedata);
8560
+
84798561 ImageWriter writer = null;
84808562 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
84818563 if (iter.hasNext()) {
84828564 writer = (ImageWriter)iter.next();
84838565 }
8484
- float compressionQuality = 0.9f;
8566
+
8567
+ float compressionQuality = 0.85f;
84858568 try
84868569 {
84878570 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8498,18 +8581,20 @@
84988581 }
84998582 }
85008583 }
8501
-
8584
+
8585
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8586
+
85028587 //System.out.println("Texture = " + tex);
8503
- if (textures.containsKey(texname))
8588
+ if (textures.containsKey(tex))
85048589 {
8505
- CacheTexture thetex = textures.get(texname);
8590
+ CacheTexture thetex = textures.get(tex);
85068591 thetex.texture.disable();
85078592 thetex.texture.dispose();
8508
- textures.remove(texname);
8593
+ textures.remove(tex);
85098594 }
85108595
85118596 //texture.texturedata = texturedata;
8512
- textures.put(texname, texturecache);
8597
+ textures.put(tex, texturecache);
85138598
85148599 // newtex = true;
85158600 }
....@@ -8528,9 +8613,43 @@
85288613 return texturecache;
85298614 }
85308615
8531
- com.sun.opengl.util.texture.Texture GetTexture(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception
8616
+ static void EmbedTextures(cTexture tex)
85328617 {
8533
- CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution);
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
8651
+ {
8652
+ CacheTexture texture = GetCacheTexture(tex, bump, resolution);
85348653
85358654 if (bump)
85368655 {
....@@ -8546,14 +8665,14 @@
85468665 return texture!=null?texture.texture:null;
85478666 }
85488667
8549
- 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
85508669 {
8551
- CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution);
8670
+ CacheTexture texture = GetCacheTexture(tex, bump, resolution);
85528671
85538672 return texture!=null?texture.texturedata:null;
85548673 }
85558674
8556
- 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
85578676 {
85588677 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
85598678 {
....@@ -8562,7 +8681,7 @@
85628681
85638682 //boolean newtex = false;
85648683
8565
- com.sun.opengl.util.texture.Texture texture = GetTexture(stream, tex, bump, resolution);
8684
+ com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
85668685
85678686 if (texture == null)
85688687 return false;
....@@ -8595,6 +8714,72 @@
85958714 return true; // Warning: not used.
85968715 }
85978716
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
+
85988783 ShadowBuffer shadowPBuf;
85998784 AntialiasBuffer antialiasPBuf;
86008785 int MAXSTACK;
....@@ -8611,10 +8796,12 @@
86118796
86128797 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
86138798 MAXSTACK = temp[0];
8614
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8799
+ if (Globals.DEBUG)
8800
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
86158801 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
86168802 MAXSTACK = temp[0];
8617
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8803
+ if (Globals.DEBUG)
8804
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
86188805
86198806 // Use debug pipeline
86208807 //drawable.setGL(new DebugGL(gl)); //
....@@ -8622,7 +8809,8 @@
86228809 gl = drawable.getGL(); //
86238810
86248811 GL gl3 = getGL();
8625
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8812
+ if (Globals.DEBUG)
8813
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
86268814
86278815
86288816 //float pos[] = { 100, 100, 100, 0 };
....@@ -8787,7 +8975,7 @@
87878975
87888976 if (cubemap == null)
87898977 {
8790
- LoadEnvy(5);
8978
+ //LoadEnvy(1);
87918979 }
87928980
87938981 //cubemap.enable();
....@@ -9063,6 +9251,8 @@
90639251
90649252 void LoadEnvy(int which)
90659253 {
9254
+ assert(false);
9255
+
90669256 String name;
90679257 String ext;
90689258
....@@ -9074,37 +9264,58 @@
90749264 cubemap = null;
90759265 return;
90769266 case 1:
9077
- name = "cubemaps/box_";
9078
- ext = "png";
9267
+ name = "cubemaps/rgb/";
9268
+ ext = "jpg";
90799269 reverseUP = false;
90809270 break;
90819271 case 2:
9082
- name = "cubemaps/uffizi_";
9083
- ext = "png";
9084
- break; // reverseUP = true; break;
9272
+ name = "cubemaps/uffizi/";
9273
+ ext = "jpg";
9274
+ reverseUP = false;
9275
+ break;
90859276 case 3:
9086
- name = "cubemaps/CloudyHills_";
9087
- ext = "tga";
9277
+ name = "cubemaps/CloudyHills/";
9278
+ ext = "jpg";
90889279 reverseUP = false;
90899280 break;
90909281 case 4:
9091
- name = "cubemaps/cornell_";
9282
+ name = "cubemaps/cornell/";
90929283 ext = "png";
90939284 reverseUP = false;
90949285 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;
90959311 default:
9096
- name = "cubemaps/rgb_";
9097
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9312
+ name = "cubemaps/box/";
9313
+ ext = "png"; /*mipmap = true;*/
9314
+ reverseUP = false;
90989315 break;
90999316 }
9100
-
9101
- try
9102
- {
9103
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
9104
- } catch (IOException e)
9105
- {
9106
- throw new RuntimeException(e);
9107
- }
9317
+
9318
+ LoadSkybox(name, ext, mipmap);
91089319 }
91099320
91109321 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -9136,8 +9347,12 @@
91369347 static double[] model = new double[16];
91379348 double[] camera2light = new double[16];
91389349 double[] light2camera = new double[16];
9139
- int newenvy = -1;
9140
- boolean envyoff = true; // false;
9350
+
9351
+ //int newenvy = -1;
9352
+ //boolean envyoff = false;
9353
+
9354
+ String loadedskyboxname;
9355
+
91419356 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
91429357 //float[] light0 = { 0,0,0 };
91439358 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9555,7 +9770,7 @@
95559770
95569771 if (renderCamera != lightCamera)
95579772 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9558
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
9773
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
95599774
95609775 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
95619776
....@@ -9571,7 +9786,7 @@
95719786
95729787 if (renderCamera != lightCamera)
95739788 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9574
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
9789
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
95759790
95769791 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
95779792
....@@ -9617,10 +9832,12 @@
96179832 rati = 1 / rati;
96189833 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
96199834 }
9620
- assert (newenvy == -1);
9835
+
9836
+ //assert (newenvy == -1);
9837
+
96219838 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
96229839 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9623
- DrawSkyBox(gl);
9840
+ DrawSkyBox(gl, (float)rati);
96249841 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
96259842 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
96269843 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10486,9 +10703,18 @@
1048610703 static boolean init = false;
1048710704
1048810705 double[][] matrix = LA.newMatrix();
10706
+
10707
+ // This is to refresh the UI of the material panel.
10708
+ ObjEditor patchMaterial;
1048910709
1049010710 public void display(GLAutoDrawable drawable)
1049110711 {
10712
+ if (patchMaterial.patchMaterial)
10713
+ {
10714
+ patchMaterial.patchMaterial = false;
10715
+ patchMaterial.objectPanel.setSelectedIndex(1);
10716
+ }
10717
+
1049210718 if (Grafreed.savesound && Grafreed.hassound)
1049310719 {
1049410720 Grafreed.wav.save();
....@@ -10657,7 +10883,7 @@
1065710883
1065810884 if (wait)
1065910885 {
10660
- Sleep(500);
10886
+ Sleep(200); // blocks everything
1066110887
1066210888 wait = false;
1066310889 }
....@@ -10772,7 +10998,7 @@
1077210998 // if (parentcam != renderCamera) // not a light
1077310999 if (cam != lightCamera)
1077411000 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10775
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
11001
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1077611002
1077711003 for (int j = 0; j < 4; j++)
1077811004 {
....@@ -10787,7 +11013,7 @@
1078711013 // if (parentcam != renderCamera) // not a light
1078811014 if (cam != lightCamera)
1078911015 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10790
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
11016
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1079111017
1079211018 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1079311019
....@@ -10873,13 +11099,43 @@
1087311099 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1087411100 }
1087511101
10876
- 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"))
1087711110 {
10878
- LoadEnvy(newenvy);
11111
+ if (cubemaprgb == null)
11112
+ {
11113
+ cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb2" + "/", "jpg", false);
11114
+ }
11115
+
11116
+ cubemap = cubemaprgb;
1087911117 }
10880
-
10881
- newenvy = -1;
10882
-
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
+
1088311139 ratio = ((double) getWidth()) / getHeight();
1088411140 //System.out.println("ratio = " + ratio);
1088511141
....@@ -10895,7 +11151,7 @@
1089511151
1089611152 if (!IsFrozen() && !ambientOcclusion)
1089711153 {
10898
- DrawSkyBox(gl);
11154
+ DrawSkyBox(gl, (float)ratio);
1089911155 }
1090011156
1090111157 //if (selection_view == -1)
....@@ -11049,7 +11305,7 @@
1104911305
1105011306 try
1105111307 {
11052
- BindTexture(null, NOISE_TEXTURE, false, 2);
11308
+ BindTexture(NOISE_TEXTURE, false, 2);
1105311309 }
1105411310 catch (Exception e)
1105511311 {
....@@ -11181,7 +11437,7 @@
1118111437
1118211438 // if (cam != lightCamera)
1118311439 //for (int count = parentcam.GetTransformCount(); --count>=0;)
11184
- LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
11440
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1118511441 }
1118611442
1118711443 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -11340,7 +11596,7 @@
1134011596 }
1134111597 }
1134211598
11343
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11599
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1134411600 {
1134511601 //gl.glDepthFunc(GL.GL_LEQUAL);
1134611602 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11348,24 +11604,21 @@
1134811604
1134911605 boolean texon = textureon;
1135011606
11351
- if (RENDERPROGRAM > 0)
11352
- {
11353
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11354
- textureon = false;
11355
- }
11607
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11608
+ textureon = false;
11609
+
1135611610 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1135711611 //System.out.println("ALLO");
1135811612 gl.glColorMask(false, false, false, false);
1135911613 DrawObject(gl);
11360
- if (RENDERPROGRAM > 0)
11361
- {
11362
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11363
- textureon = texon;
11364
- }
11614
+
11615
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11616
+ textureon = texon;
11617
+
1136511618 gl.glColorMask(true, true, true, true);
1136611619
1136711620 gl.glDepthFunc(GL.GL_EQUAL);
11368
- //gl.glDepthMask(false);
11621
+ gl.glDepthMask(false);
1136911622 }
1137011623
1137111624 if (false) // DrawMode() == SHADOW)
....@@ -11705,20 +11958,32 @@
1170511958 ReleaseTextures(DEFAULT_TEXTURES);
1170611959
1170711960 if (CLEANCACHE)
11708
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11961
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1170911962 {
11710
- String tex = e.nextElement();
11963
+ cTexture tex = e.nextElement();
1171111964
1171211965 // System.out.println("Texture --------- " + tex);
1171311966
11714
- if (tex.equals("WHITE_NOISE"))
11967
+ if (tex.equals("WHITE_NOISE:"))
1171511968 continue;
1171611969
1171711970 if (!usedtextures.contains(tex))
1171811971 {
11972
+ CacheTexture gettex = texturepigment.get(tex);
1171911973 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11720
- textures.get(tex).texture.dispose();
11721
- 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
+ }
1172211987 }
1172311988 }
1172411989 }
....@@ -12246,8 +12511,76 @@
1224612511
1224712512 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1224812513
12249
- String program =
12514
+ String programmin =
12515
+ // Min shader
1225012516 "!!ARBfp1.0\n" +
12517
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12518
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12519
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12520
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12521
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12522
+ "PARAM light2cam0 = program.env[10];" +
12523
+ "PARAM light2cam1 = program.env[11];" +
12524
+ "PARAM light2cam2 = program.env[12];" +
12525
+ "TEMP temp;" +
12526
+ "TEMP light;" +
12527
+ "TEMP ndotl;" +
12528
+ "TEMP normal;" +
12529
+ "TEMP depth;" +
12530
+ "TEMP eye;" +
12531
+ "TEMP pos;" +
12532
+
12533
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12534
+ Normalize("normal") +
12535
+ "MOV light, state.light[0].position;" +
12536
+ "DP3 ndotl.x, light, normal;" +
12537
+
12538
+ // shadow
12539
+ "MOV pos, fragment.texcoord[1];" +
12540
+ "MOV temp, pos;" +
12541
+ ShadowTextureFetch("depth", "temp", "1") +
12542
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12543
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12544
+
12545
+ // No shadow when out of frustum
12546
+ //"SGE temp.y, depth.z, zero123.y;" +
12547
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12548
+
12549
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12550
+
12551
+ // Backlit
12552
+ "MOV pos.w, zero123.y;" +
12553
+ "DP4 eye.x, pos, light2cam0;" +
12554
+ "DP4 eye.y, pos, light2cam1;" +
12555
+ "DP4 eye.z, pos, light2cam2;" +
12556
+ Normalize("eye") +
12557
+
12558
+ "DP3 ndotl.y, -eye, normal;" +
12559
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12560
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12561
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12562
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12563
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12564
+
12565
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12566
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12567
+
12568
+ // Pigment
12569
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12570
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12571
+ "MUL temp, temp, ndotl.x;" +
12572
+
12573
+ "MUL temp, temp, zero123.z;" +
12574
+
12575
+ //"MUL temp, temp, ndotl.y;" +
12576
+
12577
+ "MOV temp.w, zero123.y;" + // reset alpha
12578
+ "MOV result.color, temp;" +
12579
+ "END";
12580
+
12581
+ String programmax =
12582
+ "!!ARBfp1.0\n" +
12583
+
1225112584 //"OPTION ARB_fragment_program_shadow;" +
1225212585 "PARAM light2cam0 = program.env[10];" +
1225312586 "PARAM light2cam1 = program.env[11];" +
....@@ -12273,7 +12606,7 @@
1227312606 "PARAM params4 = program.env[4];" + // anisoV, cameralight, selfshadow, shadow
1227412607 "PARAM params5 = program.env[5];" + // texture, opacity, fakedepth, shadowbias
1227512608 "PARAM params6 = program.env[6];" + // bump, noise, borderfade, fog punchthrough
12276
- "PARAM params7 = program.env[7];" + // noise power, opacity power
12609
+ "PARAM params7 = program.env[7];" + // noise power, opacity power, parallax
1227712610 "PARAM options0 = program.env[63];" + // fog density, intensity, elevation
1227812611 "PARAM options1 = program.env[62];" + // fog rgb color
1227912612 "PARAM options2 = program.env[61];" + // image intensity, subsurface, lightsheen
....@@ -12362,8 +12695,7 @@
1236212695 "TEMP shininess;" +
1236312696 "\n" +
1236412697 "MOV texSamp, one;" +
12365
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12366
-
12698
+
1236712699 "MOV mapgrid.x, one2048th.x;" +
1236812700 "MOV temp, fragment.texcoord[1];" +
1236912701 /*
....@@ -12384,20 +12716,20 @@
1238412716 "MUL temp, floor, mapgrid.x;" +
1238512717 //"TEX depth0, temp, texture[1], 2D;" +
1238612718 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12387
- TextureFetch("depth0", "temp", "1") +
12719
+ ShadowTextureFetch("depth0", "temp", "1") +
1238812720 "") +
1238912721 "ADD temp.x, temp.x, mapgrid.x;" +
1239012722 //"TEX depth1, temp, texture[1], 2D;" +
1239112723 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12392
- TextureFetch("depth1", "temp", "1") +
12724
+ ShadowTextureFetch("depth1", "temp", "1") +
1239312725 "") +
1239412726 "ADD temp.y, temp.y, mapgrid.x;" +
1239512727 //"TEX depth2, temp, texture[1], 2D;" +
12396
- TextureFetch("depth2", "temp", "1") +
12728
+ ShadowTextureFetch("depth2", "temp", "1") +
1239712729 "SUB temp.x, temp.x, mapgrid.x;" +
1239812730 //"TEX depth3, temp, texture[1], 2D;" +
1239912731 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12400
- TextureFetch("depth3", "temp", "1") +
12732
+ ShadowTextureFetch("depth3", "temp", "1") +
1240112733 "") +
1240212734 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1240312735 //"MOV params, material;" +
....@@ -12519,7 +12851,7 @@
1251912851 "POW texSamp.a, texSamp.a, params6.w;" + // fog punch through shortcut
1252012852 // mar 2013 ??? "KIL alpha.a;" +
1252112853 "MOV alpha, texSamp.aaaa;" + // y;" +
12522
- "KIL alpha.a;" +
12854
+ "KIL alpha.a;" + // not sure with parallax mapping
1252312855 /*
1252412856 "MUL temp.xy, temp, two;" +
1252512857 "TXB bump, temp, texture[0], 2D;" +
....@@ -12605,11 +12937,6 @@
1260512937 "SUB bump0, bump0, half;" +
1260612938 "ADD bump, bump, bump0;" +
1260712939
12608
- "MOV temp.x, texSamp.a;" +
12609
- "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
12610
- //"LRP texSamp0, params5.x, texSamp0, one;" +
12611
- "MOV texSamp.a, temp.x;" +
12612
-
1261312940 // double-sided
1261412941 /**/
1261512942 (doublesided?"DP3 temp.z, normal, eye;" +
....@@ -12626,19 +12953,62 @@
1262612953 "MOV normald, normal;" +
1262712954 "MOV normals, normal;" +
1262812955
12956
+ "MOV temp, fragment.texcoord[4];" +
12957
+
1262912958 // UV base
1263012959 //"DP3 UP.x,state.matrix.modelview.row[0],Y;" +
1263112960 //"DP3 UP.y,state.matrix.modelview.row[1],Y;" +
1263212961 //"DP3 UP.z,state.matrix.modelview.row[2],Y;" +
12633
- "DP3 UP.x,state.matrix.texture[7].row[0],Y;" +
12634
- "DP3 UP.y,state.matrix.texture[7].row[1],Y;" +
12635
- "DP3 UP.z,state.matrix.texture[7].row[2],Y;" +
12962
+ "DP3 UP.x,state.matrix.texture[7].row[0],temp;" +
12963
+ "DP3 UP.y,state.matrix.texture[7].row[1],temp;" +
12964
+ "DP3 UP.z,state.matrix.texture[7].row[2],temp;" +
12965
+ Normalize("UP") +
12966
+
1263612967 "XPD V, normal, UP;" +
1263712968 Normalize("V") +
1263812969 "XPD U, V, normal;" +
1263912970 Normalize("U") +
1264012971
1264112972 // parallax mapping
12973
+
12974
+ "DP3 temp2.x, V, eye;" +
12975
+ "DP3 temp2.y, U, eye;" +
12976
+ "DP3 temp2.z, normal, eye;" +
12977
+ "RCP temp2.z, temp2.z;" +
12978
+
12979
+ "DP3 temp2.w, texSamp, texSamp;" + // Height
12980
+ "RSQ temp2.w, temp2.w;" +
12981
+ "RCP temp2.w, temp2.w;" +
12982
+
12983
+ "SUB temp2.w, temp2.w, half;" +
12984
+// "SGE temp.x, temp2.w, eps.x;" +
12985
+// "MUL temp2.w, temp2.w, temp.x;" +
12986
+
12987
+ //"MOV texSamp, U;" +
12988
+
12989
+ "MUL temp2.z, temp2.z, temp2.w;" +
12990
+ "MUL temp2.z, temp2.z, params7.z;" + // parallax
12991
+
12992
+ "MUL temp2, temp2, temp2.z;" +
12993
+
12994
+ "MOV temp, fragment.texcoord[0];" +
12995
+
12996
+ "SUB temp, temp, temp2;" +
12997
+
12998
+ "TEX temp, temp, texture[0], 2D;" +
12999
+ "POW temp.a, temp.a, params6.w;" + // punch through
13000
+
13001
+ "ADD texSamp, temp, texSamp;" +
13002
+ "MUL texSamp.xyz, half, texSamp;" +
13003
+
13004
+ "MOV alpha, texSamp.aaaa;" +
13005
+
13006
+// parallax mapping
13007
+
13008
+ "MOV temp.x, texSamp.a;" +
13009
+ "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
13010
+ //"LRP texSamp0, params5.x, texSamp0, one;" +
13011
+ "MOV texSamp.a, temp.x;" +
1264213012
1264313013 //"MOV temp, fragment.texcoord[0];" +
1264413014 //
....@@ -12768,10 +13138,10 @@
1276813138 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1276913139 "") +
1277013140
12771
- // display shadow only (bump == 0)
13141
+ // display shadow only (fakedepth == 0)
1277213142 "SUB temp.x, half.x, shadow.x;" +
1277313143 "MOV temp.y, -params5.z;" + // params6.x;" +
12774
- "SLT temp.z, temp.y, -one2048th.x;" +
13144
+ "SLT temp.z, temp.y, -c256i.x;" +
1277513145 "SUB temp.y, one.x, temp.z;" +
1277613146 "MUL temp.x, temp.x, temp.y;" +
1277713147 "KIL temp.x;" +
....@@ -13102,8 +13472,19 @@
1310213472 //once = true;
1310313473 }
1310413474
13105
- System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13106
- System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13475
+ String program = programmax;
13476
+
13477
+ if (Globals.MINSHADER)
13478
+ {
13479
+ program = programmin;
13480
+ }
13481
+
13482
+ if (Globals.DEBUG)
13483
+ {
13484
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13485
+ System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13486
+ }
13487
+
1310713488 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1310813489
1310913490 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -13150,7 +13531,8 @@
1315013531 "\n" +
1315113532 "END\n";
1315213533
13153
- System.out.println("Program shadow #" + 0 + "; length = " + program.length());
13534
+ if (Globals.DEBUG)
13535
+ System.out.println("Program shadow #" + 0 + "; length = " + program.length());
1315413536 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1315513537
1315613538 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -13195,25 +13577,26 @@
1319513577 return out;
1319613578 }
1319713579
13198
- String TextureFetch(String dest, String src, String unit)
13580
+ // Also does frustum culling
13581
+ String ShadowTextureFetch(String dest, String src, String unit)
1319913582 {
1320013583 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1320113584 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1320213585 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13586
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13587
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1320313588 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13204
- "SLT " + src + ".z, " + src + ".x, one.x;" +
13205
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13206
- "SLT " + src + ".z, " + src + ".y, one.x;" +
13207
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13589
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13590
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1320813591 //"SWZ buffer, temp, w,w,w,w;";
13209
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13592
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1321013593 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1321113594 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1321213595 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13213
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13596
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1321413597
13215
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13216
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13598
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13599
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1321713600 }
1321813601
1321913602 String Shadow(String depth, String shadow)
....@@ -13260,7 +13643,7 @@
1326013643 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1326113644 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1326213645
13263
- // No shadow when out of frustrum
13646
+ // No shadow when out of frustum
1326413647 "SGE temp.x, " + depth + ".z, one.z;" +
1326513648 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1326613649 "";
....@@ -13407,7 +13790,7 @@
1340713790 /*static*/ float[] modelParams4 = new float[]{0, 0, 0, 0}; // anisoV, cameralight, selfshadow, shadow
1340813791 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1340913792 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
13410
- /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13793
+ /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power, parallax
1341113794
1341213795 //Object3D.cVector2[] vector2buffer;
1341313796
....@@ -13574,7 +13957,7 @@
1357413957 "PARAM p[4] = { state.matrix.projection }; # modelview projection matrix\n" +
1357513958 "PARAM zero = { 0.0, 0.0, 0.0, 1.0 };" +
1357613959 "PARAM half = { 0.5, 0.5, 0.5, 1.0 };" +
13577
- "PARAM one = { 1.0, 1.0, 1.0, 0.0 };" +
13960
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
1357813961 "PARAM two = { 2.0, 2.0, 2.0, 1.0 };" +
1357913962 "PARAM third = { 0.33333333333, 0.33333333333, 0.33333333333, 1.0 };" +
1358013963 //"PARAM v256 = { 256.0, 256.0, 256.0, 1.0 };" +
....@@ -13635,7 +14018,7 @@
1363514018 "DP4 temp.x,state.matrix.texture[0].inverse.row[0],vertex.texcoord;" +
1363614019 "DP4 temp.y,state.matrix.texture[0].inverse.row[1],vertex.texcoord;" +
1363714020 "DP4 temp.z,state.matrix.texture[0].inverse.row[2],vertex.texcoord;" +
13638
- //"MOV result.texcoord, vertex.texcoord;" +
14021
+ //"MOV result.texcoord, vertex.fogcoord;" +
1363914022 "MOV result.texcoord, temp;" +
1364014023 // border fade
1364114024 "MOV result.texcoord[3], vertex.texcoord;" +
....@@ -13682,7 +14065,9 @@
1368214065
1368314066 //"ADD temp.z, temp.z, one;" +
1368414067
13685
- "MOV result.color, temp;"
14068
+ "MOV result.texcoord[4], vertex.attrib[4];" + // U dir
14069
+
14070
+ "MOV result.color, temp;" // Normal
1368614071 : "MOV result.color, vertex.color;") +
1368714072 ((mode & VP_PROJECTION) != 0 ? "MOV result.color, zero;"
1368814073 : "") +
....@@ -14058,14 +14443,15 @@
1405814443 drag = false;
1405914444 //System.out.println("Mouse DOWN");
1406014445 editObj = false;
14061
- ClickInfo info = new ClickInfo();
14062
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14063
- info.pane = this;
14064
- info.camera = renderCamera;
14065
- info.x = x;
14066
- info.y = y;
14067
- info.modifiers = modifiersex;
14068
- editObj = object.doEditClick(info, 0);
14446
+ //ClickInfo info = new ClickInfo();
14447
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14448
+ object.clickInfo.pane = this;
14449
+ object.clickInfo.camera = renderCamera;
14450
+ object.clickInfo.x = x;
14451
+ object.clickInfo.y = y;
14452
+ object.clickInfo.modifiers = modifiersex;
14453
+ editObj = object.doEditClick(//info,
14454
+ 0);
1406914455 if (!editObj)
1407014456 {
1407114457 hasMarquee = true;
....@@ -14347,11 +14733,17 @@
1434714733 void GoDown(int mod)
1434814734 {
1434914735 MODIFIERS |= COMMAND;
14736
+ boolean isVR = (mouseMode&VR)!=0;
1435014737 /**/
1435114738 if((mod&SHIFT) == SHIFT)
14352
- manipCamera.RotatePosition(0, -speed);
14739
+ {
14740
+ if (isVR)
14741
+ manipCamera.RotateInterest(0, -speed);
14742
+ else
14743
+ manipCamera.RotatePosition(0, -speed);
14744
+ }
1435314745 else
14354
- manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14746
+ manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth());
1435514747 /**/
1435614748 if ((mod & SHIFT) == SHIFT)
1435714749 {
....@@ -14361,6 +14753,8 @@
1436114753 mouseMode |= BACKFORTH;
1436214754 }
1436314755
14756
+ targetLookAt.set(manipCamera.lookAt);
14757
+
1436414758 //prevX = X = anchorX;
1436514759 prevY = Y = anchorY - (int) (renderCamera.Distance());
1436614760 }
....@@ -14369,10 +14763,17 @@
1436914763 {
1437014764 MODIFIERS |= COMMAND;
1437114765 /**/
14766
+ boolean isVR = (mouseMode&VR)!=0;
14767
+
1437214768 if((mod&SHIFT) == SHIFT)
14373
- manipCamera.RotatePosition(0, speed);
14769
+ {
14770
+ if (isVR)
14771
+ manipCamera.RotateInterest(0, speed);
14772
+ else
14773
+ manipCamera.RotatePosition(0, speed);
14774
+ }
1437414775 else
14375
- manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14776
+ manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth());
1437614777 /**/
1437714778 if ((mod & SHIFT) == SHIFT)
1437814779 {
....@@ -14382,6 +14783,8 @@
1438214783 mouseMode |= BACKFORTH;
1438314784 }
1438414785
14786
+ targetLookAt.set(manipCamera.lookAt);
14787
+
1438514788 //prevX = X = anchorX;
1438614789 prevY = Y = anchorY + (int) (renderCamera.Distance());
1438714790 }
....@@ -14391,9 +14794,14 @@
1439114794 MODIFIERS |= COMMAND;
1439214795 /**/
1439314796 if((mod&SHIFT) == SHIFT)
14394
- manipCamera.Translate(speed*delta, 0, getWidth());
14797
+ manipCamera.Translate(speed*delta, 0, getWidth());
1439514798 else
14396
- manipCamera.RotatePosition(speed, 0);
14799
+ {
14800
+ if ((mouseMode&VR)!=0)
14801
+ manipCamera.RotateInterest(-speed, 0);
14802
+ else
14803
+ manipCamera.RotatePosition(speed, 0);
14804
+ }
1439714805 /**/
1439814806 if ((mod & SHIFT) == SHIFT)
1439914807 {
....@@ -14403,6 +14811,8 @@
1440314811 mouseMode |= ROTATE;
1440414812 } // TRANSLATE;
1440514813
14814
+ targetLookAt.set(manipCamera.lookAt);
14815
+
1440614816 prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance());
1440714817 prevY = Y = anchorY;
1440814818 }
....@@ -14412,9 +14822,15 @@
1441214822 MODIFIERS |= COMMAND;
1441314823 /**/
1441414824 if((mod&SHIFT) == SHIFT)
14415
- manipCamera.Translate(-speed*delta, 0, getWidth());
14825
+ manipCamera.Translate(-speed*delta, 0, getWidth());
1441614826 else
14417
- manipCamera.RotatePosition(-speed, 0);
14827
+ {
14828
+ if ((mouseMode&VR)!=0)
14829
+ manipCamera.RotateInterest(speed, 0);
14830
+ else
14831
+ manipCamera.RotatePosition(-speed, 0);
14832
+ }
14833
+
1441814834 /**/
1441914835 if ((mod & SHIFT) == SHIFT)
1442014836 {
....@@ -14424,6 +14840,8 @@
1442414840 mouseMode |= ROTATE;
1442514841 } // TRANSLATE;
1442614842
14843
+ targetLookAt.set(manipCamera.lookAt);
14844
+
1442714845 prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance());
1442814846 prevY = Y = anchorY;
1442914847 }
....@@ -14465,15 +14883,16 @@
1446514883 if (editObj)
1446614884 {
1446714885 drag = true;
14468
- ClickInfo info = new ClickInfo();
14469
- info.bounds.setBounds(0, 0,
14886
+ //ClickInfo info = new ClickInfo();
14887
+ object.clickInfo.bounds.setBounds(0, 0,
1447014888 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14471
- info.pane = this;
14472
- info.camera = renderCamera;
14473
- info.x = x;
14474
- info.y = y;
14475
- object.GetWindow().copy
14476
- .doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
14889
+ object.clickInfo.pane = this;
14890
+ object.clickInfo.camera = renderCamera;
14891
+ object.clickInfo.x = x;
14892
+ object.clickInfo.y = y;
14893
+ object //.GetWindow().copy
14894
+ .doEditDrag(//info,
14895
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1447714896 } else
1447814897 {
1447914898 if (x < startX)
....@@ -14622,24 +15041,27 @@
1462215041 }
1462315042 }
1462415043
15044
+// ClickInfo clickInfo = new ClickInfo();
15045
+
1462515046 public void mouseMoved(MouseEvent e)
1462615047 {
1462715048 //System.out.println("mouseMoved: " + e);
1462815049 if (isRenderer)
1462915050 return;
1463015051
14631
- ClickInfo ci = new ClickInfo();
14632
- ci.x = e.getX();
14633
- ci.y = e.getY();
14634
- ci.modifiers = e.getModifiersEx();
14635
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14636
- ci.pane = this;
14637
- ci.camera = renderCamera;
15052
+ // Mouse cursor feedback
15053
+ object.clickInfo.x = e.getX();
15054
+ object.clickInfo.y = e.getY();
15055
+ object.clickInfo.modifiers = e.getModifiersEx();
15056
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
15057
+ object.clickInfo.pane = this;
15058
+ object.clickInfo.camera = renderCamera;
1463815059 if (!isRenderer)
1463915060 {
1464015061 //ObjEditor editWindow = object.editWindow;
1464115062 //Object3D copy = editWindow.copy;
14642
- if (object.doEditClick(ci, 0))
15063
+ if (object.doEditClick(//clickInfo,
15064
+ 0))
1464315065 {
1464415066 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1464515067 } else
....@@ -14911,7 +15333,8 @@
1491115333 // break;
1491215334 case 'T':
1491315335 CACHETEXTURE ^= true;
14914
- textures.clear();
15336
+ texturepigment.clear();
15337
+ texturebump.clear();
1491515338 // repaint();
1491615339 break;
1491715340 case 'Y':
....@@ -14921,8 +15344,8 @@
1492115344 case 'K':
1492215345 KOMPACTTEXTURE ^= true;
1492315346 //textures.clear();
14924
- break;
14925
- case 'P': // Texture Projection macros
15347
+ // break;
15348
+ //case 'P': // Texture Projection macros
1492615349 // SAVETEXTURE ^= true;
1492715350 macromode = true;
1492815351 Udebug = Vdebug = NORMALdebug = false; programInitialized = false;
....@@ -15043,7 +15466,7 @@
1504315466 targetLookAt.set(manipCamera.lookAt);
1504415467 repaint();
1504515468 break;
15046
- case 'p':
15469
+ case 'P': // p':
1504715470 // c'est quoi ca au juste? spherical ^= true;
1504815471 Skinshader ^= true; programInitialized = false;
1504915472 repaint();
....@@ -15081,27 +15504,31 @@
1508115504 repaint();
1508215505 break;
1508315506 case 'O':
15084
- Globals.drawMode = OCCLUSION; // WARNING
15507
+ // Too dangerous. Use menu. Globals.drawMode = OCCLUSION; // WARNING
1508515508 repaint();
1508615509 break;
1508715510 case 'o':
1508815511 OCCLUSION_CULLING ^= true;
1508915512 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1509015513 break;
15091
- case '0': envyoff ^= true; repaint(); break;
15514
+ //case '0': envyoff ^= true; repaint(); break;
1509215515 case '1':
1509315516 case '2':
1509415517 case '3':
1509515518 case '4':
1509615519 case '5':
15097
- newenvy = Character.getNumericValue(key);
15098
- repaint();
15099
- break;
1510015520 case '6':
1510115521 case '7':
1510215522 case '8':
1510315523 case '9':
15104
- BGcolor = (key - '6')/3.f;
15524
+ if (true) // envyoff)
15525
+ {
15526
+ BGcolor = (key - '1')/8.f;
15527
+ }
15528
+ else
15529
+ {
15530
+ //newenvy = Character.getNumericValue(key);
15531
+ }
1510515532 repaint();
1510615533 break;
1510715534 case '!':
....@@ -15664,8 +16091,6 @@
1566416091
1566516092 int width = getBounds().width;
1566616093 int height = getBounds().height;
15667
- ClickInfo info = new ClickInfo();
15668
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1566916094 //Image img = CreateImage(width, height);
1567016095 //System.out.println("width = " + width + "; height = " + height + "\n");
1567116096
....@@ -15742,31 +16167,37 @@
1574216167 }
1574316168 if (object != null && !hasMarquee)
1574416169 {
16170
+ if (object.clickInfo == null)
16171
+ object.clickInfo = new ClickInfo();
16172
+ ClickInfo info = object.clickInfo;
16173
+ //ClickInfo info = new ClickInfo();
16174
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16175
+
1574516176 if (isRenderer)
1574616177 {
15747
- info.flags++;
16178
+ object.clickInfo.flags++;
1574816179 double frameAspect = (double) width / (double) height;
1574916180 if (frameAspect > renderCamera.aspect)
1575016181 {
1575116182 int desired = (int) ((double) height * renderCamera.aspect);
15752
- info.bounds.width -= width - desired;
15753
- info.bounds.x += (width - desired) / 2;
16183
+ object.clickInfo.bounds.width -= width - desired;
16184
+ object.clickInfo.bounds.x += (width - desired) / 2;
1575416185 } else
1575516186 {
1575616187 int desired = (int) ((double) width / renderCamera.aspect);
15757
- info.bounds.height -= height - desired;
15758
- info.bounds.y += (height - desired) / 2;
16188
+ object.clickInfo.bounds.height -= height - desired;
16189
+ object.clickInfo.bounds.y += (height - desired) / 2;
1575916190 }
1576016191 }
1576116192
15762
- info.g = gr;
15763
- info.camera = renderCamera;
16193
+ object.clickInfo.g = gr;
16194
+ object.clickInfo.camera = renderCamera;
1576416195 /*
1576516196 // Memory intensive (brep.verticescopy)
1576616197 if (!(object instanceof Composite))
1576716198 object.draw(info, 0, false); // SLOW :
1576816199 */
15769
- if (!isRenderer)
16200
+ if (!isRenderer) // && drag)
1577016201 {
1577116202 Grafreed.Assert(object != null);
1577216203 Grafreed.Assert(object.selection != null);
....@@ -15774,9 +16205,9 @@
1577416205 {
1577516206 int hitSomething = object.selection.get(0).hitSomething;
1577616207
15777
- info.DX = 0;
15778
- info.DY = 0;
15779
- info.W = 1;
16208
+ object.clickInfo.DX = 0;
16209
+ object.clickInfo.DY = 0;
16210
+ object.clickInfo.W = 1;
1578016211 if (hitSomething == Object3D.hitCenter)
1578116212 {
1578216213 info.DX = X;
....@@ -15788,13 +16219,14 @@
1578816219 info.DY -= info.bounds.height/2;
1578916220 }
1579016221
15791
- object.drawEditHandles(info, 0);
16222
+ object.drawEditHandles(//info,
16223
+ 0);
1579216224
1579316225 if (drag && (X != 0 || Y != 0))
1579416226 {
1579516227 switch (hitSomething)
1579616228 {
15797
- case Object3D.hitCenter: gr.setColor(Color.pink);
16229
+ case Object3D.hitCenter: gr.setColor(Color.white);
1579816230 gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
1579916231 break;
1580016232 case Object3D.hitRotate: gr.setColor(Color.yellow);
....@@ -15820,7 +16252,7 @@
1582016252 if (hasMarquee)
1582116253 {
1582216254 gr.setXORMode(Color.white);
15823
- gr.setColor(Color.red);
16255
+ gr.setColor(Color.white);
1582416256 if (!firstime)
1582516257 {
1582616258 gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH);
....@@ -16287,6 +16719,8 @@
1628716719 private /*static*/ boolean firstime;
1628816720 private /*static*/ cVector newView = new cVector();
1628916721 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16722
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16723
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1629016724 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1629116725 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1629216726 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16299,29 +16733,67 @@
1629916733 {
1630016734 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1630116735
16736
+ int usedsuf = 0;
16737
+
1630216738 for (int i = 0; i < suffixes.length; i++)
1630316739 {
16304
- String resourceName = basename + suffixes[i] + "." + suffix;
16305
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16306
- mipmapped,
16307
- FileUtil.getFileSuffix(resourceName));
16308
- if (data == null)
16740
+ String[] suffixe = suffixes;
16741
+ String[] fallback = suffixes2;
16742
+ String[] fallfallback = suffixes3;
16743
+
16744
+ for (int c=usedsuf; --c>=0;)
1630916745 {
16310
- throw new IOException("Unable to load texture " + resourceName);
16746
+// String[] temp = suffixe;
16747
+// suffixe = fallback;
16748
+// fallback = fallfallback;
16749
+// fallfallback = temp;
1631116750 }
16751
+
16752
+ String resourceName = basename + suffixe[i] + "." + suffix;
16753
+ TextureData data;
16754
+
16755
+ try
16756
+ {
16757
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16758
+ mipmapped,
16759
+ FileUtil.getFileSuffix(resourceName));
16760
+ }
16761
+ catch (Exception e)
16762
+ {
16763
+ try
16764
+ {
16765
+ resourceName = basename + fallback[i] + "." + suffix;
16766
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16767
+ mipmapped,
16768
+ FileUtil.getFileSuffix(resourceName));
16769
+ }
16770
+ catch (Exception e2)
16771
+ {
16772
+ resourceName = basename + fallfallback[i] + "." + suffix;
16773
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16774
+ mipmapped,
16775
+ FileUtil.getFileSuffix(resourceName));
16776
+ }
16777
+ }
16778
+
1631216779 //System.out.println("Target = " + targets[i]);
1631316780 cubemap.updateImage(data, targets[i]);
1631416781 }
1631516782
1631616783 return cubemap;
1631716784 }
16785
+
1631816786 int bigsphere = -1;
1631916787
1632016788 float BGcolor = 0.5f;
1632116789
16322
- private void DrawSkyBox(GL gl)
16790
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16791
+
16792
+ private void DrawSkyBox(GL gl, float ratio)
1632316793 {
16324
- if (envyoff || cubemap == null)
16794
+ if (//envyoff ||
16795
+ WIREFRAME ||
16796
+ cubemap == null)
1632516797 {
1632616798 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1632716799 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16336,7 +16808,17 @@
1633616808 // Compensates for ExaminerViewer's modification of modelview matrix
1633716809 gl.glMatrixMode(GL.GL_MODELVIEW);
1633816810 gl.glLoadIdentity();
16811
+ gl.glScalef(1,ratio,1);
1633916812
16813
+// colorV[0] = 2;
16814
+// colorV[1] = 2;
16815
+// colorV[2] = 2;
16816
+// colorV[3] = 1;
16817
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16818
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16819
+//
16820
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16821
+
1634016822 //gl.glActiveTexture(GL.GL_TEXTURE1);
1634116823 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1634216824
....@@ -16368,6 +16850,7 @@
1636816850 {
1636916851 gl.glScalef(1.0f, -1.0f, 1.0f);
1637016852 }
16853
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1637116854 gl.glMultMatrixd(viewrot_1, 0);
1637216855 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1637316856 //viewer.updateInverseRotation(gl);
....@@ -16408,7 +16891,8 @@
1640816891 gl.glDisable(GL.GL_TEXTURE_GEN_R);
1640916892
1641016893 cubemap.disable();
16411
- ////cubemap.unbind();
16894
+ //cubemap.dispose();
16895
+
1641216896 if (CULLFACE)
1641316897 {
1641416898 gl.glEnable(gl.GL_CULL_FACE);
....@@ -16464,7 +16948,7 @@
1646416948 gl.glScalef(1.0f, -1.0f, 1.0f);
1646516949 }
1646616950
16467
- gl.glNormal3f(0.0f, 0.0f, 1.0f);
16951
+ SetGLNormal(gl, 0.0f, 0.0f, 1.0f);
1646816952
1646916953 float step = 2; // 0.1666f; //0.25f;
1647016954 float stepv = 2; // step * 1652 / 998;
....@@ -16626,7 +17110,7 @@
1662617110 //new Exception().printStackTrace();
1662717111 System.out.println("select buffer init");
1662817112 // Use debug pipeline
16629
- drawable.setGL(new DebugGL(drawable.getGL()));
17113
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1663017114
1663117115 GL gl = drawable.getGL();
1663217116
....@@ -16944,6 +17428,7 @@
1694417428
1694517429 public void init(GLAutoDrawable drawable)
1694617430 {
17431
+ if (Globals.DEBUG)
1694717432 System.out.println("shadow buffer init");
1694817433
1694917434 GL gl = drawable.getGL();
....@@ -17172,10 +17657,14 @@
1717217657 gl.glFlush();
1717317658
1717417659 /**/
17175
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17660
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1717617661
17177
- float[] pixels = occlusionsizebuffer.array();
17662
+ float[] depths = occlusiondepthbuffer.array();
1717817663
17664
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17665
+
17666
+ int[] pixels = selectsizebuffer.array();
17667
+
1717917668 double r = 0, g = 0, b = 0;
1718017669
1718117670 double count = 0;
....@@ -17186,7 +17675,7 @@
1718617675
1718717676 double FACTOR = 1;
1718817677
17189
- for (int i = 0; i < pixels.length; i++)
17678
+ for (int i = 0; i < depths.length; i++)
1719017679 {
1719117680 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1719217681 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -17269,7 +17758,7 @@
1726917758
1727017759 double scale = ray.z; // 1; // cos
1727117760
17272
- float depth = pixels[newindex];
17761
+ float depth = depths[newindex];
1727317762
1727417763 /*
1727517764 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -17466,11 +17955,14 @@
1746617955 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1746717956 static IntBuffer bigAAbuffer;
1746817957 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
17469
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17958
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1747017959 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1747117960 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1747217961 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17473
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17962
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17963
+
17964
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17965
+
1747417966 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1747517967 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1747617968 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();