Normand Briere
2019-08-23 60cec91731a350fe67e9b5ffe7a00d70e9026314
CameraPane.java
....@@ -18,7 +18,10 @@
1818 import javax.imageio.ImageIO;
1919 import javax.imageio.ImageWriteParam;
2020 import javax.imageio.ImageWriter;
21
+import javax.imageio.ImageReadParam;
22
+import javax.imageio.ImageReader;
2123 import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
24
+import javax.imageio.stream.ImageInputStream;
2225 import javax.imageio.stream.ImageOutputStream;
2326 import javax.imageio.ImageWriteParam;
2427
....@@ -30,6 +33,7 @@
3033 import java.nio.*;
3134
3235 import gleem.linalg.Mat4f;
36
+import javax.imageio.ImageTypeSpecifier;
3337
3438 class CameraPane extends GLCanvas implements iCameraPane, Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener
3539 {
....@@ -44,6 +48,39 @@
4448 static boolean ABORTED = false;
4549
4650 static int STEP = 1;
51
+
52
+ private static BufferedImage CreateBim(byte[] bytes, int width, int height)
53
+ {
54
+ int[] pixels = new int[bytes.length/3];
55
+ for (int i=pixels.length; --i>=0;)
56
+ {
57
+ int i3 = i*3;
58
+ pixels[i] = 0xFF;
59
+ pixels[i] <<= 8;
60
+ pixels[i] |= bytes[i3+2] & 0xFF;
61
+ pixels[i] <<= 8;
62
+ pixels[i] |= bytes[i3+1] & 0xFF;
63
+ pixels[i] <<= 8;
64
+ pixels[i] |= bytes[i3] & 0xFF;
65
+ }
66
+ /*
67
+ int r=0,g=0,b=0,a=0;
68
+ for (int i=0; i<width; i++)
69
+ for (int j=0; j<height; j++)
70
+ {
71
+ int index = j*width+i;
72
+ int p = pixels[index];
73
+ a = ((p>>24) & 0xFF);
74
+ r = ((p>>16) & 0xFF);
75
+ g = ((p>>8) & 0xFF);
76
+ b = (p & 0xFF);
77
+ pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
78
+ }
79
+ /**/
80
+ BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
81
+ rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
82
+ return rendImage;
83
+ }
4784
4885 /*static*/ private boolean CULLFACE = false; // true;
4986 /*static*/ boolean NEAREST = false; // true;
....@@ -60,7 +97,7 @@
6097 //boolean REDUCETEXTURE = true;
6198 boolean CACHETEXTURE = true;
6299 boolean CLEANCACHE = false; // true;
63
- boolean MIPMAP = false; // true;
100
+ boolean MIPMAP = false; // true; // never works...
64101 boolean COMPRESSTEXTURE = false;
65102 boolean KOMPACTTEXTURE = false; // true;
66103 boolean RESIZETEXTURE = false;
....@@ -73,7 +110,11 @@
73110 //private Mat4f spotlightTransform = new Mat4f();
74111 //private Mat4f spotlightInverseTransform = new Mat4f();
75112 static GLContext glcontext = null;
76
- /*static*/ com.sun.opengl.util.texture.Texture cubemap;
113
+ /*static*/ com.sun.opengl.util.texture.Texture cubemap; // Either custom or rgb
114
+ /*static*/ com.sun.opengl.util.texture.Texture cubemapcustom;
115
+ /*static*/ com.sun.opengl.util.texture.Texture cubemaprgb;
116
+ boolean transformMode;
117
+
77118 boolean reverseUP = false;
78119 static boolean frozen = false;
79120 boolean enablebackspace = false; // patch for back buffer refresh
....@@ -127,7 +168,7 @@
127168
128169
129170 // OPTIONS
130
- boolean Skinshader = true;
171
+ boolean Skinshader = false; // true;
131172 boolean cameraLight = false;
132173 boolean UVdebug = false;
133174 boolean Udebug = false;
....@@ -136,7 +177,7 @@
136177 static boolean doublesided = false; // true; // reversed normals are awful for conformance
137178 boolean anisotropy = true;
138179 boolean softshadow = true; // slower but better false;
139
- boolean opacityhalo = false;
180
+ boolean opacityhalo = false; // reverse the halo effect (e.g. glass)
140181
141182 boolean macromode = false;
142183
....@@ -150,6 +191,19 @@
150191 }
151192
152193 private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
194
+
195
+ public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException
196
+ {
197
+ try
198
+ {
199
+ return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
200
+ } catch (IOException e)
201
+ {
202
+ System.out.println("NAME = " + name);
203
+ e.printStackTrace(); // throw new RuntimeException(e);
204
+ return null;
205
+ }
206
+ }
153207
154208 void SetAsGLRenderer(boolean b)
155209 {
....@@ -169,7 +223,8 @@
169223
170224 SetCamera(cam);
171225
172
- SetLight(new Camera(new cVector(10, 10, -20)));
226
+ // Warning: not used.
227
+ SetLight(new Camera(new cVector(15, 10, -20)));
173228
174229 object = o;
175230
....@@ -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
....@@ -2298,10 +2354,17 @@
22982354 HANDLES ^= true;
22992355 }
23002356
2357
+ Object3D paintFolder;
2358
+
23012359 void TogglePaint()
23022360 {
23032361 PAINTMODE ^= true;
23042362 paintcount = 0;
2363
+
2364
+ if (PAINTMODE)
2365
+ {
2366
+ paintFolder = GetFolder();
2367
+ }
23052368 }
23062369
23072370 void SwapCamera(int a, int b)
....@@ -2398,6 +2461,33 @@
23982461 return currentGL;
23992462 }
24002463
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
+
24012491 /**/
24022492 class CacheTexture
24032493 {
....@@ -2406,28 +2496,31 @@
24062496
24072497 int resolution;
24082498
2409
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2499
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
24102500 {
2411
- texture = tex;
2501
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2502
+ texturedata = texdata;
24122503 resolution = res;
24132504 }
24142505 }
24152506 /**/
24162507
24172508 // TEXTURE static Texture texture;
2418
- static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures
2419
- = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>();
2420
- static public java.util.Hashtable<String, String> usedtextures = new java.util.Hashtable<String, String>();
2509
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2510
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2511
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2512
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2513
+
24212514 int pigmentdepth = 0;
24222515 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
24232516 int bumpdepth = 0;
24242517 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
24252518 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
24262519 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2427
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2520
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
24282521 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
24292522
2430
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2523
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
24312524 {
24322525 TextureData texturedata = null;
24332526
....@@ -2437,7 +2530,7 @@
24372530 com.sun.opengl.util.texture.TextureIO.newTextureData(
24382531 getClass().getClassLoader().getResourceAsStream(name),
24392532 true,
2440
- com.sun.opengl.util.texture.TextureIO.PNG);
2533
+ GetFormat(name)); // com.sun.opengl.util.texture.TextureIO.PNG);
24412534 } catch (java.io.IOException e)
24422535 {
24432536 throw new javax.media.opengl.GLException(e);
....@@ -2446,13 +2539,34 @@
24462539 if (bump)
24472540 texturedata = ConvertBump(texturedata, false);
24482541
2449
- com.sun.opengl.util.texture.Texture texture =
2450
- 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);
24512544
2452
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2453
- 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);
24542547
2455
- return texture;
2548
+ return texturedata;
2549
+ }
2550
+
2551
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2552
+ {
2553
+ TextureData texturedata = null;
2554
+
2555
+ try
2556
+ {
2557
+ texturedata =
2558
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2559
+ bim,
2560
+ true);
2561
+ } catch (Exception e)
2562
+ {
2563
+ throw new javax.media.opengl.GLException(e);
2564
+ }
2565
+
2566
+ if (bump)
2567
+ texturedata = ConvertBump(texturedata, false);
2568
+
2569
+ return texturedata;
24562570 }
24572571
24582572 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3525,6 +3639,8 @@
35253639
35263640 System.out.println("LOADING TEXTURE : " + name);
35273641
3642
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3643
+
35283644 //
35293645 if (false) // compressbit > 0)
35303646 {
....@@ -7923,7 +8039,7 @@
79238039 String pigment = Object3D.GetPigment(tex);
79248040 String bump = Object3D.GetBump(tex);
79258041
7926
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8042
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79278043 {
79288044 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79298045 // System.out.println("; bump = " + bump);
....@@ -7938,8 +8054,8 @@
79388054 pigment = null;
79398055 }
79408056
7941
- ReleaseTexture(bump, true);
7942
- ReleaseTexture(pigment, false);
8057
+ ReleaseTexture(tex, true);
8058
+ ReleaseTexture(tex, false);
79438059 }
79448060
79458061 public void ReleasePigmentTexture(cTexture tex) // INTERFACE
....@@ -7957,7 +8073,7 @@
79578073
79588074 String pigment = Object3D.GetPigment(tex);
79598075
7960
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8076
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79618077 {
79628078 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79638079 // System.out.println("; bump = " + bump);
....@@ -7968,7 +8084,7 @@
79688084 pigment = null;
79698085 }
79708086
7971
- ReleaseTexture(pigment, false);
8087
+ ReleaseTexture(tex, false);
79728088 }
79738089
79748090 public void ReleaseBumpTexture(cTexture tex) // INTERFACE
....@@ -7986,7 +8102,7 @@
79868102
79878103 String bump = Object3D.GetBump(tex);
79888104
7989
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8105
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79908106 {
79918107 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79928108 // System.out.println("; bump = " + bump);
....@@ -7997,10 +8113,10 @@
79978113 bump = null;
79988114 }
79998115
8000
- ReleaseTexture(bump, true);
8116
+ ReleaseTexture(tex, true);
80018117 }
80028118
8003
- void ReleaseTexture(String tex, boolean bump)
8119
+ void ReleaseTexture(cTexture tex, boolean bump)
80048120 {
80058121 if (// DrawMode() != 0 || /*tex == null ||*/
80068122 ambientOcclusion ) // || !textureon)
....@@ -8011,7 +8127,7 @@
80118127 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
80128128
80138129 if (tex != null)
8014
- texture = textures.get(tex);
8130
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
80158131
80168132 // //assert( texture != null );
80178133 // if (texture == null)
....@@ -8105,47 +8221,50 @@
81058221
81068222 /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
81078223 {
8108
- if (// DrawMode() != 0 || /*tex == null ||*/
8109
- ambientOcclusion ) // || !textureon)
8110
- {
8111
- return; // false;
8112
- }
8113
-
8114
- if (tex == null)
8115
- {
8116
- BindTexture(null,false,resolution);
8117
- BindTexture(null,true,resolution);
8118
- return;
8119
- }
8224
+// if (// DrawMode() != 0 || /*tex == null ||*/
8225
+// ambientOcclusion ) // || !textureon)
8226
+// {
8227
+// return; // false;
8228
+// }
8229
+//
8230
+// if (tex == null)
8231
+// {
8232
+// BindTexture(null,false,resolution);
8233
+// BindTexture(null,true,resolution);
8234
+// return;
8235
+// }
8236
+//
8237
+// String pigment = Object3D.GetPigment(tex);
8238
+// String bump = Object3D.GetBump(tex);
8239
+//
8240
+// usedtextures.add(pigment);
8241
+// usedtextures.add(bump);
8242
+//
8243
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8244
+// {
8245
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8246
+// // System.out.println("; bump = " + bump);
8247
+// }
8248
+//
8249
+// if (bump.equals(""))
8250
+// {
8251
+// bump = null;
8252
+// }
8253
+// if (pigment.equals(""))
8254
+// {
8255
+// pigment = null;
8256
+// }
8257
+//
8258
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8259
+// BindTexture(pigment, false, resolution);
8260
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8261
+// BindTexture(bump, true, resolution);
8262
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8263
+//
8264
+// return; // true;
81208265
8121
- String pigment = Object3D.GetPigment(tex);
8122
- String bump = Object3D.GetBump(tex);
8123
-
8124
- usedtextures.put(pigment, pigment);
8125
- usedtextures.put(bump, bump);
8126
-
8127
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8128
- {
8129
- // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8130
- // System.out.println("; bump = " + bump);
8131
- }
8132
-
8133
- if (bump.equals(""))
8134
- {
8135
- bump = null;
8136
- }
8137
- if (pigment.equals(""))
8138
- {
8139
- pigment = null;
8140
- }
8141
-
8142
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8143
- BindTexture(pigment, false, resolution);
8144
- GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8145
- BindTexture(bump, true, resolution);
8146
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8147
-
8148
- return; // true;
8266
+ BindPigmentTexture(tex, resolution);
8267
+ BindBumpTexture(tex, resolution);
81498268 }
81508269
81518270 /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8164,9 +8283,9 @@
81648283
81658284 String pigment = Object3D.GetPigment(tex);
81668285
8167
- usedtextures.put(pigment, pigment);
8286
+ usedtextures.add(tex);
81688287
8169
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8288
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
81708289 {
81718290 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
81728291 // System.out.println("; bump = " + bump);
....@@ -8178,7 +8297,7 @@
81788297 }
81798298
81808299 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8181
- BindTexture(pigment, false, resolution);
8300
+ BindTexture(tex, false, resolution);
81828301 }
81838302
81848303 /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8197,9 +8316,9 @@
81978316
81988317 String bump = Object3D.GetBump(tex);
81998318
8200
- usedtextures.put(bump, bump);
8319
+ usedtextures.add(tex);
82018320
8202
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8321
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
82038322 {
82048323 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
82058324 // System.out.println("; bump = " + bump);
....@@ -8211,7 +8330,7 @@
82118330 }
82128331
82138332 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8214
- BindTexture(bump, true, resolution);
8333
+ BindTexture(tex, true, resolution);
82158334 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
82168335 }
82178336
....@@ -8235,13 +8354,19 @@
82358354 return fileExists;
82368355 }
82378356
8238
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception
8357
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
82398358 {
8240
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8359
+ CacheTexture texturecache = null;
82418360
82428361 if (tex != null)
82438362 {
8244
- 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
+ }
82458370
82468371 String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
82478372
....@@ -8251,19 +8376,46 @@
82518376 // else
82528377 // if (!texname.startsWith("/"))
82538378 // texname = "/Users/nbriere/Textures/" + texname;
8254
- if (!FileExists(tex))
8379
+ if (!FileExists(texname) && !texname.startsWith("@"))
82558380 {
82568381 texname = fallbackTextureName;
82578382 }
82588383
82598384 if (CACHETEXTURE)
8260
- texture = textures.get(texname); // TEXTURE CACHE
8261
-
8262
- TextureData texturedata = null;
8263
-
8264
- if (texture == null || texture.resolution < resolution)
82658385 {
8266
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8386
+ if (texdata == null)
8387
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8388
+ else
8389
+ texturecache = bimtextures.get(texdata);
8390
+ }
8391
+
8392
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8393
+ {
8394
+ TextureData texturedata = null;
8395
+
8396
+ if (texdata != null && textureon)
8397
+ {
8398
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8399
+
8400
+ try
8401
+ {
8402
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8403
+ }
8404
+ catch (Exception e)
8405
+ {
8406
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8407
+ }
8408
+
8409
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8410
+ bimtextures.put(texdata, texturecache);
8411
+
8412
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8413
+
8414
+ //Object bim2 = CreateBim(texturecache.texturedata);
8415
+ //bim2 = bim;
8416
+ }
8417
+ else
8418
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
82678419 {
82688420 assert(!bump);
82698421 // if (bump)
....@@ -8274,19 +8426,23 @@
82748426 // }
82758427 // else
82768428 // {
8277
- texture = textures.get(tex);
8278
- if (texture == null)
8429
+ // texturecache = textures.get(texname); // suspicious
8430
+ if (texturecache == null)
82798431 {
8280
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8432
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
82818433 }
8434
+ else
8435
+ new Exception().printStackTrace();
82828436 // }
82838437 } else
8284
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8438
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
82858439 {
82868440 assert(bump);
8287
- texture = textures.get(tex);
8288
- if (texture == null)
8289
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8441
+ // texturecache = textures.get(texname); // suspicious
8442
+ if (texturecache == null)
8443
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8444
+ else
8445
+ new Exception().printStackTrace();
82908446 } else
82918447 {
82928448 //if (tex.equals("IMMORTAL"))
....@@ -8294,11 +8450,22 @@
82948450 // texture = GetResourceTexture("default.png");
82958451 //} else
82968452 //{
8297
- if (tex.equals("WHITE_NOISE"))
8453
+ if (texname.endsWith("WHITE_NOISE"))
82988454 {
8299
- texture = textures.get(tex);
8300
- if (texture == null)
8301
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8455
+ // texturecache = textures.get(texname); // suspicious
8456
+ if (texturecache == null)
8457
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8458
+ else
8459
+ new Exception().printStackTrace();
8460
+ } else
8461
+ {
8462
+ if (texname.startsWith("@"))
8463
+ {
8464
+ // texturecache = textures.get(texname); // suspicious
8465
+ if (texturecache == null)
8466
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8467
+ else
8468
+ new Exception().printStackTrace();
83028469 } else
83038470 {
83048471 if (textureon)
....@@ -8357,19 +8524,20 @@
83578524 if (texturedata == null)
83588525 throw new Exception();
83598526
8360
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8527
+ texturecache = new CacheTexture(texturedata,resolution);
83618528 //texture = GetTexture(tex, bump);
83628529 }
8530
+ }
83638531 }
83648532 //}
83658533 }
83668534
8367
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8535
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
83688536 {
83698537 //return false;
83708538
83718539 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8372
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8540
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
83738541 {
83748542 // String ext = "_highres";
83758543 // if (REDUCETEXTURE)
....@@ -8386,52 +8554,17 @@
83868554 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
83878555 if (!cachefile.exists())
83888556 {
8389
- // cache to disk
8390
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
8391
- //buffers[0].
8392
-
8393
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
8394
- int[] pixels = new int[bytebuf.capacity()/3];
8395
-
8396
- // squared size heuristic...
8397
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8557
+ //if (texturedata.getWidth() == texturedata.getHeight())
83988558 {
8399
- for (int i=pixels.length; --i>=0;)
8400
- {
8401
- int i3 = i*3;
8402
- pixels[i] = 0xFF;
8403
- pixels[i] <<= 8;
8404
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
8405
- pixels[i] <<= 8;
8406
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
8407
- pixels[i] <<= 8;
8408
- pixels[i] |= bytebuf.get(i3) & 0xFF;
8409
- }
8410
-
8411
- /*
8412
- int r=0,g=0,b=0,a=0;
8413
- for (int i=0; i<width; i++)
8414
- for (int j=0; j<height; j++)
8415
- {
8416
- int index = j*width+i;
8417
- int p = pixels[index];
8418
- a = ((p>>24) & 0xFF);
8419
- r = ((p>>16) & 0xFF);
8420
- g = ((p>>8) & 0xFF);
8421
- b = (p & 0xFF);
8422
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
8423
- }
8424
- /**/
8425
- int width = (int)Math.sqrt(pixels.length); // squared
8426
- int height = width;
8427
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
8428
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8559
+ BufferedImage rendImage = CreateBim(texturedata);
8560
+
84298561 ImageWriter writer = null;
84308562 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
84318563 if (iter.hasNext()) {
84328564 writer = (ImageWriter)iter.next();
84338565 }
8434
- float compressionQuality = 0.9f;
8566
+
8567
+ float compressionQuality = 0.85f;
84358568 try
84368569 {
84378570 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8448,18 +8581,20 @@
84488581 }
84498582 }
84508583 }
8451
-
8584
+
8585
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8586
+
84528587 //System.out.println("Texture = " + tex);
8453
- if (textures.containsKey(texname))
8588
+ if (textures.containsKey(tex))
84548589 {
8455
- CacheTexture thetex = textures.get(texname);
8590
+ CacheTexture thetex = textures.get(tex);
84568591 thetex.texture.disable();
84578592 thetex.texture.dispose();
8458
- textures.remove(texname);
8593
+ textures.remove(tex);
84598594 }
84608595
8461
- texture.texturedata = texturedata;
8462
- textures.put(texname, texture);
8596
+ //texture.texturedata = texturedata;
8597
+ textures.put(tex, texturecache);
84638598
84648599 // newtex = true;
84658600 }
....@@ -8475,10 +8610,44 @@
84758610 }
84768611 }
84778612
8478
- return texture;
8613
+ return texturecache;
84798614 }
84808615
8481
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution) throws Exception
8616
+ static void EmbedTextures(cTexture tex)
8617
+ {
8618
+ if (tex.pigmentdata == null)
8619
+ {
8620
+ //String texname = Object3D.GetPigment(tex);
8621
+
8622
+ CacheTexture texturecache = texturepigment.get(tex);
8623
+
8624
+ if (texturecache != null)
8625
+ {
8626
+ tex.pw = texturecache.texturedata.getWidth();
8627
+ tex.ph = texturecache.texturedata.getHeight();
8628
+ tex.pigmentdata = //CompressJPEG(CreateBim
8629
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8630
+ ;
8631
+ //, tex.pw, tex.ph), 0.5f);
8632
+ }
8633
+ }
8634
+
8635
+ if (tex.bumpdata == null)
8636
+ {
8637
+ //String texname = Object3D.GetBump(tex);
8638
+
8639
+ CacheTexture texturecache = texturebump.get(tex);
8640
+
8641
+ if (texturecache != null)
8642
+ {
8643
+ tex.bw = texturecache.texturedata.getWidth();
8644
+ tex.bh = texturecache.texturedata.getHeight();
8645
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8646
+ }
8647
+ }
8648
+ }
8649
+
8650
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
84828651 {
84838652 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
84848653
....@@ -8496,21 +8665,21 @@
84968665 return texture!=null?texture.texture:null;
84978666 }
84988667
8499
- public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution) throws Exception
8668
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
85008669 {
85018670 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
85028671
85038672 return texture!=null?texture.texturedata:null;
85048673 }
85058674
8506
- boolean BindTexture(String tex, boolean bump, int resolution) throws Exception
8675
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
85078676 {
85088677 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
85098678 {
85108679 return false;
85118680 }
85128681
8513
- boolean newtex = false;
8682
+ //boolean newtex = false;
85148683
85158684 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
85168685
....@@ -8542,9 +8711,75 @@
85428711 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
85438712 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
85448713
8545
- return newtex;
8714
+ return true; // Warning: not used.
85468715 }
85478716
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
+
85488783 ShadowBuffer shadowPBuf;
85498784 AntialiasBuffer antialiasPBuf;
85508785 int MAXSTACK;
....@@ -8561,10 +8796,12 @@
85618796
85628797 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
85638798 MAXSTACK = temp[0];
8564
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8799
+ if (Globals.DEBUG)
8800
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
85658801 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
85668802 MAXSTACK = temp[0];
8567
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8803
+ if (Globals.DEBUG)
8804
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
85688805
85698806 // Use debug pipeline
85708807 //drawable.setGL(new DebugGL(gl)); //
....@@ -8572,7 +8809,8 @@
85728809 gl = drawable.getGL(); //
85738810
85748811 GL gl3 = getGL();
8575
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8812
+ if (Globals.DEBUG)
8813
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
85768814
85778815
85788816 //float pos[] = { 100, 100, 100, 0 };
....@@ -8737,7 +8975,7 @@
87378975
87388976 if (cubemap == null)
87398977 {
8740
- LoadEnvy(5);
8978
+ //LoadEnvy(1);
87418979 }
87428980
87438981 //cubemap.enable();
....@@ -9013,6 +9251,8 @@
90139251
90149252 void LoadEnvy(int which)
90159253 {
9254
+ assert(false);
9255
+
90169256 String name;
90179257 String ext;
90189258
....@@ -9024,37 +9264,58 @@
90249264 cubemap = null;
90259265 return;
90269266 case 1:
9027
- name = "cubemaps/box_";
9028
- ext = "png";
9267
+ name = "cubemaps/rgb/";
9268
+ ext = "jpg";
90299269 reverseUP = false;
90309270 break;
90319271 case 2:
9032
- name = "cubemaps/uffizi_";
9033
- ext = "png";
9034
- break; // reverseUP = true; break;
9272
+ name = "cubemaps/uffizi/";
9273
+ ext = "jpg";
9274
+ reverseUP = false;
9275
+ break;
90359276 case 3:
9036
- name = "cubemaps/CloudyHills_";
9037
- ext = "tga";
9277
+ name = "cubemaps/CloudyHills/";
9278
+ ext = "jpg";
90389279 reverseUP = false;
90399280 break;
90409281 case 4:
9041
- name = "cubemaps/cornell_";
9282
+ name = "cubemaps/cornell/";
90429283 ext = "png";
90439284 reverseUP = false;
90449285 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;
90459311 default:
9046
- name = "cubemaps/rgb_";
9047
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9312
+ name = "cubemaps/box/";
9313
+ ext = "png"; /*mipmap = true;*/
9314
+ reverseUP = false;
90489315 break;
90499316 }
9050
-
9051
- try
9052
- {
9053
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
9054
- } catch (IOException e)
9055
- {
9056
- throw new RuntimeException(e);
9057
- }
9317
+
9318
+ LoadSkybox(name, ext, mipmap);
90589319 }
90599320
90609321 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -9086,8 +9347,12 @@
90869347 static double[] model = new double[16];
90879348 double[] camera2light = new double[16];
90889349 double[] light2camera = new double[16];
9089
- int newenvy = -1;
9090
- boolean envyoff = true; // false;
9350
+
9351
+ //int newenvy = -1;
9352
+ //boolean envyoff = false;
9353
+
9354
+ String loadedskyboxname;
9355
+
90919356 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
90929357 //float[] light0 = { 0,0,0 };
90939358 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9505,7 +9770,7 @@
95059770
95069771 if (renderCamera != lightCamera)
95079772 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9508
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
9773
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
95099774
95109775 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
95119776
....@@ -9521,7 +9786,7 @@
95219786
95229787 if (renderCamera != lightCamera)
95239788 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9524
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
9789
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
95259790
95269791 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
95279792
....@@ -9567,10 +9832,12 @@
95679832 rati = 1 / rati;
95689833 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
95699834 }
9570
- assert (newenvy == -1);
9835
+
9836
+ //assert (newenvy == -1);
9837
+
95719838 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
95729839 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9573
- DrawSkyBox(gl);
9840
+ DrawSkyBox(gl, (float)rati);
95749841 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
95759842 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
95769843 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10436,9 +10703,18 @@
1043610703 static boolean init = false;
1043710704
1043810705 double[][] matrix = LA.newMatrix();
10706
+
10707
+ // This is to refresh the UI of the material panel.
10708
+ ObjEditor patchMaterial;
1043910709
1044010710 public void display(GLAutoDrawable drawable)
1044110711 {
10712
+ if (patchMaterial.patchMaterial)
10713
+ {
10714
+ patchMaterial.patchMaterial = false;
10715
+ patchMaterial.objectPanel.setSelectedIndex(1);
10716
+ }
10717
+
1044210718 if (Grafreed.savesound && Grafreed.hassound)
1044310719 {
1044410720 Grafreed.wav.save();
....@@ -10607,7 +10883,7 @@
1060710883
1060810884 if (wait)
1060910885 {
10610
- Sleep(500);
10886
+ Sleep(200); // blocks everything
1061110887
1061210888 wait = false;
1061310889 }
....@@ -10722,7 +10998,7 @@
1072210998 // if (parentcam != renderCamera) // not a light
1072310999 if (cam != lightCamera)
1072411000 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10725
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
11001
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1072611002
1072711003 for (int j = 0; j < 4; j++)
1072811004 {
....@@ -10737,7 +11013,7 @@
1073711013 // if (parentcam != renderCamera) // not a light
1073811014 if (cam != lightCamera)
1073911015 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10740
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
11016
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1074111017
1074211018 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1074311019
....@@ -10823,13 +11099,43 @@
1082311099 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1082411100 }
1082511101
10826
- 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"))
1082711110 {
10828
- LoadEnvy(newenvy);
11111
+ if (cubemaprgb == null)
11112
+ {
11113
+ cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb2" + "/", "jpg", false);
11114
+ }
11115
+
11116
+ cubemap = cubemaprgb;
1082911117 }
10830
-
10831
- newenvy = -1;
10832
-
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
+
1083311139 ratio = ((double) getWidth()) / getHeight();
1083411140 //System.out.println("ratio = " + ratio);
1083511141
....@@ -10845,7 +11151,7 @@
1084511151
1084611152 if (!IsFrozen() && !ambientOcclusion)
1084711153 {
10848
- DrawSkyBox(gl);
11154
+ DrawSkyBox(gl, (float)ratio);
1084911155 }
1085011156
1085111157 //if (selection_view == -1)
....@@ -11028,9 +11334,9 @@
1102811334
1102911335 gl.glMatrixMode(GL.GL_MODELVIEW);
1103011336
11031
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11032
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
11033
-//gl.glEnable(gl.GL_MULTISAMPLE);
11337
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11338
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11339
+gl.glEnable(gl.GL_MULTISAMPLE);
1103411340 } else
1103511341 {
1103611342 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -11041,7 +11347,7 @@
1104111347 //System.out.println("BLENDING ON");
1104211348 gl.glEnable(GL.GL_BLEND);
1104311349 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
11044
-
11350
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1104511351 gl.glMatrixMode(gl.GL_PROJECTION);
1104611352 gl.glLoadIdentity();
1104711353
....@@ -11131,7 +11437,7 @@
1113111437
1113211438 // if (cam != lightCamera)
1113311439 //for (int count = parentcam.GetTransformCount(); --count>=0;)
11134
- LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
11440
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1113511441 }
1113611442
1113711443 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -11290,7 +11596,7 @@
1129011596 }
1129111597 }
1129211598
11293
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11599
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1129411600 {
1129511601 //gl.glDepthFunc(GL.GL_LEQUAL);
1129611602 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11298,24 +11604,21 @@
1129811604
1129911605 boolean texon = textureon;
1130011606
11301
- if (RENDERPROGRAM > 0)
11302
- {
11303
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11304
- textureon = false;
11305
- }
11607
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11608
+ textureon = false;
11609
+
1130611610 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1130711611 //System.out.println("ALLO");
1130811612 gl.glColorMask(false, false, false, false);
1130911613 DrawObject(gl);
11310
- if (RENDERPROGRAM > 0)
11311
- {
11312
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11313
- textureon = texon;
11314
- }
11614
+
11615
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11616
+ textureon = texon;
11617
+
1131511618 gl.glColorMask(true, true, true, true);
1131611619
1131711620 gl.glDepthFunc(GL.GL_EQUAL);
11318
- //gl.glDepthMask(false);
11621
+ gl.glDepthMask(false);
1131911622 }
1132011623
1132111624 if (false) // DrawMode() == SHADOW)
....@@ -11655,20 +11958,32 @@
1165511958 ReleaseTextures(DEFAULT_TEXTURES);
1165611959
1165711960 if (CLEANCACHE)
11658
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11961
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1165911962 {
11660
- String tex = e.nextElement();
11963
+ cTexture tex = e.nextElement();
1166111964
1166211965 // System.out.println("Texture --------- " + tex);
1166311966
11664
- if (tex.equals("WHITE_NOISE"))
11967
+ if (tex.equals("WHITE_NOISE:"))
1166511968 continue;
1166611969
11667
- if (!usedtextures.containsKey(tex))
11970
+ if (!usedtextures.contains(tex))
1166811971 {
11972
+ CacheTexture gettex = texturepigment.get(tex);
1166911973 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11670
- textures.get(tex).texture.dispose();
11671
- 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
+ }
1167211987 }
1167311988 }
1167411989 }
....@@ -12196,8 +12511,82 @@
1219612511
1219712512 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1219812513
12199
- String program =
12514
+ String programmin =
12515
+ // Min shader
1220012516 "!!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
+
1220112590 //"OPTION ARB_fragment_program_shadow;" +
1220212591 "PARAM light2cam0 = program.env[10];" +
1220312592 "PARAM light2cam1 = program.env[11];" +
....@@ -12223,7 +12612,7 @@
1222312612 "PARAM params4 = program.env[4];" + // anisoV, cameralight, selfshadow, shadow
1222412613 "PARAM params5 = program.env[5];" + // texture, opacity, fakedepth, shadowbias
1222512614 "PARAM params6 = program.env[6];" + // bump, noise, borderfade, fog punchthrough
12226
- "PARAM params7 = program.env[7];" + // noise power, opacity power
12615
+ "PARAM params7 = program.env[7];" + // noise power, opacity power, parallax
1222712616 "PARAM options0 = program.env[63];" + // fog density, intensity, elevation
1222812617 "PARAM options1 = program.env[62];" + // fog rgb color
1222912618 "PARAM options2 = program.env[61];" + // image intensity, subsurface, lightsheen
....@@ -12312,8 +12701,7 @@
1231212701 "TEMP shininess;" +
1231312702 "\n" +
1231412703 "MOV texSamp, one;" +
12315
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12316
-
12704
+
1231712705 "MOV mapgrid.x, one2048th.x;" +
1231812706 "MOV temp, fragment.texcoord[1];" +
1231912707 /*
....@@ -12334,20 +12722,20 @@
1233412722 "MUL temp, floor, mapgrid.x;" +
1233512723 //"TEX depth0, temp, texture[1], 2D;" +
1233612724 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12337
- TextureFetch("depth0", "temp", "1") +
12725
+ ShadowTextureFetch("depth0", "temp", "1") +
1233812726 "") +
1233912727 "ADD temp.x, temp.x, mapgrid.x;" +
1234012728 //"TEX depth1, temp, texture[1], 2D;" +
1234112729 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12342
- TextureFetch("depth1", "temp", "1") +
12730
+ ShadowTextureFetch("depth1", "temp", "1") +
1234312731 "") +
1234412732 "ADD temp.y, temp.y, mapgrid.x;" +
1234512733 //"TEX depth2, temp, texture[1], 2D;" +
12346
- TextureFetch("depth2", "temp", "1") +
12734
+ ShadowTextureFetch("depth2", "temp", "1") +
1234712735 "SUB temp.x, temp.x, mapgrid.x;" +
1234812736 //"TEX depth3, temp, texture[1], 2D;" +
1234912737 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12350
- TextureFetch("depth3", "temp", "1") +
12738
+ ShadowTextureFetch("depth3", "temp", "1") +
1235112739 "") +
1235212740 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1235312741 //"MOV params, material;" +
....@@ -12469,7 +12857,7 @@
1246912857 "POW texSamp.a, texSamp.a, params6.w;" + // fog punch through shortcut
1247012858 // mar 2013 ??? "KIL alpha.a;" +
1247112859 "MOV alpha, texSamp.aaaa;" + // y;" +
12472
- "KIL alpha.a;" +
12860
+ "KIL alpha.a;" + // not sure with parallax mapping
1247312861 /*
1247412862 "MUL temp.xy, temp, two;" +
1247512863 "TXB bump, temp, texture[0], 2D;" +
....@@ -12555,11 +12943,6 @@
1255512943 "SUB bump0, bump0, half;" +
1255612944 "ADD bump, bump, bump0;" +
1255712945
12558
- "MOV temp.x, texSamp.a;" +
12559
- "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
12560
- //"LRP texSamp0, params5.x, texSamp0, one;" +
12561
- "MOV texSamp.a, temp.x;" +
12562
-
1256312946 // double-sided
1256412947 /**/
1256512948 (doublesided?"DP3 temp.z, normal, eye;" +
....@@ -12576,19 +12959,62 @@
1257612959 "MOV normald, normal;" +
1257712960 "MOV normals, normal;" +
1257812961
12962
+ "MOV temp, fragment.texcoord[4];" +
12963
+
1257912964 // UV base
1258012965 //"DP3 UP.x,state.matrix.modelview.row[0],Y;" +
1258112966 //"DP3 UP.y,state.matrix.modelview.row[1],Y;" +
1258212967 //"DP3 UP.z,state.matrix.modelview.row[2],Y;" +
12583
- "DP3 UP.x,state.matrix.texture[7].row[0],Y;" +
12584
- "DP3 UP.y,state.matrix.texture[7].row[1],Y;" +
12585
- "DP3 UP.z,state.matrix.texture[7].row[2],Y;" +
12968
+ "DP3 UP.x,state.matrix.texture[7].row[0],temp;" +
12969
+ "DP3 UP.y,state.matrix.texture[7].row[1],temp;" +
12970
+ "DP3 UP.z,state.matrix.texture[7].row[2],temp;" +
12971
+ Normalize("UP") +
12972
+
1258612973 "XPD V, normal, UP;" +
1258712974 Normalize("V") +
1258812975 "XPD U, V, normal;" +
1258912976 Normalize("U") +
1259012977
1259112978 // parallax mapping
12979
+
12980
+ "DP3 temp2.x, V, eye;" +
12981
+ "DP3 temp2.y, U, eye;" +
12982
+ "DP3 temp2.z, normal, eye;" +
12983
+ "RCP temp2.z, temp2.z;" +
12984
+
12985
+ "DP3 temp2.w, texSamp, texSamp;" + // Height
12986
+ "RSQ temp2.w, temp2.w;" +
12987
+ "RCP temp2.w, temp2.w;" +
12988
+
12989
+ "SUB temp2.w, temp2.w, half;" +
12990
+// "SGE temp.x, temp2.w, eps.x;" +
12991
+// "MUL temp2.w, temp2.w, temp.x;" +
12992
+
12993
+ //"MOV texSamp, U;" +
12994
+
12995
+ "MUL temp2.z, temp2.z, temp2.w;" +
12996
+ "MUL temp2.z, temp2.z, params7.z;" + // parallax
12997
+
12998
+ "MUL temp2, temp2, temp2.z;" +
12999
+
13000
+ "MOV temp, fragment.texcoord[0];" +
13001
+
13002
+ "SUB temp, temp, temp2;" +
13003
+
13004
+ "TEX temp, temp, texture[0], 2D;" +
13005
+ "POW temp.a, temp.a, params6.w;" + // punch through
13006
+
13007
+ "ADD texSamp, temp, texSamp;" +
13008
+ "MUL texSamp.xyz, half, texSamp;" +
13009
+
13010
+ "MOV alpha, texSamp.aaaa;" +
13011
+
13012
+// parallax mapping
13013
+
13014
+ "MOV temp.x, texSamp.a;" +
13015
+ "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
13016
+ //"LRP texSamp0, params5.x, texSamp0, one;" +
13017
+ "MOV texSamp.a, temp.x;" +
1259213018
1259313019 //"MOV temp, fragment.texcoord[0];" +
1259413020 //
....@@ -12718,10 +13144,10 @@
1271813144 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1271913145 "") +
1272013146
12721
- // display shadow only (bump == 0)
13147
+ // display shadow only (fakedepth == 0)
1272213148 "SUB temp.x, half.x, shadow.x;" +
1272313149 "MOV temp.y, -params5.z;" + // params6.x;" +
12724
- "SLT temp.z, temp.y, -one2048th.x;" +
13150
+ "SLT temp.z, temp.y, -c256i.x;" +
1272513151 "SUB temp.y, one.x, temp.z;" +
1272613152 "MUL temp.x, temp.x, temp.y;" +
1272713153 "KIL temp.x;" +
....@@ -13052,8 +13478,19 @@
1305213478 //once = true;
1305313479 }
1305413480
13055
- System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13056
- System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13481
+ String program = programmax;
13482
+
13483
+ if (Globals.MINSHADER)
13484
+ {
13485
+ program = programmin;
13486
+ }
13487
+
13488
+ if (Globals.DEBUG)
13489
+ {
13490
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13491
+ System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13492
+ }
13493
+
1305713494 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1305813495
1305913496 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -13100,7 +13537,8 @@
1310013537 "\n" +
1310113538 "END\n";
1310213539
13103
- System.out.println("Program shadow #" + 0 + "; length = " + program.length());
13540
+ if (Globals.DEBUG)
13541
+ System.out.println("Program shadow #" + 0 + "; length = " + program.length());
1310413542 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1310513543
1310613544 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -13145,25 +13583,26 @@
1314513583 return out;
1314613584 }
1314713585
13148
- String TextureFetch(String dest, String src, String unit)
13586
+ // Also does frustum culling
13587
+ String ShadowTextureFetch(String dest, String src, String unit)
1314913588 {
1315013589 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1315113590 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1315213591 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13592
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13593
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1315313594 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13154
- "SLT " + src + ".z, " + src + ".x, one.x;" +
13155
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13156
- "SLT " + src + ".z, " + src + ".y, one.x;" +
13157
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13595
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13596
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1315813597 //"SWZ buffer, temp, w,w,w,w;";
13159
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13598
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1316013599 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1316113600 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1316213601 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13163
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13602
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1316413603
13165
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13166
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13604
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13605
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1316713606 }
1316813607
1316913608 String Shadow(String depth, String shadow)
....@@ -13210,7 +13649,7 @@
1321013649 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1321113650 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1321213651
13213
- // No shadow when out of frustrum
13652
+ // No shadow when out of frustum
1321413653 "SGE temp.x, " + depth + ".z, one.z;" +
1321513654 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1321613655 "";
....@@ -13357,7 +13796,7 @@
1335713796 /*static*/ float[] modelParams4 = new float[]{0, 0, 0, 0}; // anisoV, cameralight, selfshadow, shadow
1335813797 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1335913798 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
13360
- /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13799
+ /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power, parallax
1336113800
1336213801 //Object3D.cVector2[] vector2buffer;
1336313802
....@@ -13524,7 +13963,7 @@
1352413963 "PARAM p[4] = { state.matrix.projection }; # modelview projection matrix\n" +
1352513964 "PARAM zero = { 0.0, 0.0, 0.0, 1.0 };" +
1352613965 "PARAM half = { 0.5, 0.5, 0.5, 1.0 };" +
13527
- "PARAM one = { 1.0, 1.0, 1.0, 0.0 };" +
13966
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
1352813967 "PARAM two = { 2.0, 2.0, 2.0, 1.0 };" +
1352913968 "PARAM third = { 0.33333333333, 0.33333333333, 0.33333333333, 1.0 };" +
1353013969 //"PARAM v256 = { 256.0, 256.0, 256.0, 1.0 };" +
....@@ -13585,7 +14024,7 @@
1358514024 "DP4 temp.x,state.matrix.texture[0].inverse.row[0],vertex.texcoord;" +
1358614025 "DP4 temp.y,state.matrix.texture[0].inverse.row[1],vertex.texcoord;" +
1358714026 "DP4 temp.z,state.matrix.texture[0].inverse.row[2],vertex.texcoord;" +
13588
- //"MOV result.texcoord, vertex.texcoord;" +
14027
+ //"MOV result.texcoord, vertex.fogcoord;" +
1358914028 "MOV result.texcoord, temp;" +
1359014029 // border fade
1359114030 "MOV result.texcoord[3], vertex.texcoord;" +
....@@ -13632,7 +14071,9 @@
1363214071
1363314072 //"ADD temp.z, temp.z, one;" +
1363414073
13635
- "MOV result.color, temp;"
14074
+ "MOV result.texcoord[4], vertex.attrib[4];" + // U dir
14075
+
14076
+ "MOV result.color, temp;" // Normal
1363614077 : "MOV result.color, vertex.color;") +
1363714078 ((mode & VP_PROJECTION) != 0 ? "MOV result.color, zero;"
1363814079 : "") +
....@@ -14008,14 +14449,15 @@
1400814449 drag = false;
1400914450 //System.out.println("Mouse DOWN");
1401014451 editObj = false;
14011
- ClickInfo info = new ClickInfo();
14012
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14013
- info.pane = this;
14014
- info.camera = renderCamera;
14015
- info.x = x;
14016
- info.y = y;
14017
- info.modifiers = modifiersex;
14018
- editObj = object.doEditClick(info, 0);
14452
+ //ClickInfo info = new ClickInfo();
14453
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14454
+ object.clickInfo.pane = this;
14455
+ object.clickInfo.camera = renderCamera;
14456
+ object.clickInfo.x = x;
14457
+ object.clickInfo.y = y;
14458
+ object.clickInfo.modifiers = modifiersex;
14459
+ editObj = object.doEditClick(//info,
14460
+ 0);
1401914461 if (!editObj)
1402014462 {
1402114463 hasMarquee = true;
....@@ -14297,12 +14739,18 @@
1429714739 void GoDown(int mod)
1429814740 {
1429914741 MODIFIERS |= COMMAND;
14300
- /*
14742
+ boolean isVR = (mouseMode&VR)!=0;
14743
+ /**/
1430114744 if((mod&SHIFT) == SHIFT)
14302
- manipCamera.RotatePosition(0, -speed);
14745
+ {
14746
+ if (isVR)
14747
+ manipCamera.RotateInterest(0, -speed);
14748
+ else
14749
+ manipCamera.RotatePosition(0, -speed);
14750
+ }
1430314751 else
14304
- manipCamera.BackForth(0, -speed*delta, getWidth());
14305
- */
14752
+ manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth());
14753
+ /**/
1430614754 if ((mod & SHIFT) == SHIFT)
1430714755 {
1430814756 mouseMode = mouseMode; // VR??
....@@ -14311,6 +14759,8 @@
1431114759 mouseMode |= BACKFORTH;
1431214760 }
1431314761
14762
+ targetLookAt.set(manipCamera.lookAt);
14763
+
1431414764 //prevX = X = anchorX;
1431514765 prevY = Y = anchorY - (int) (renderCamera.Distance());
1431614766 }
....@@ -14318,12 +14768,19 @@
1431814768 void GoUp(int mod)
1431914769 {
1432014770 MODIFIERS |= COMMAND;
14321
- /*
14771
+ /**/
14772
+ boolean isVR = (mouseMode&VR)!=0;
14773
+
1432214774 if((mod&SHIFT) == SHIFT)
14323
- manipCamera.RotatePosition(0, speed);
14775
+ {
14776
+ if (isVR)
14777
+ manipCamera.RotateInterest(0, speed);
14778
+ else
14779
+ manipCamera.RotatePosition(0, speed);
14780
+ }
1432414781 else
14325
- manipCamera.BackForth(0, speed*delta, getWidth());
14326
- */
14782
+ manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth());
14783
+ /**/
1432714784 if ((mod & SHIFT) == SHIFT)
1432814785 {
1432914786 mouseMode = mouseMode;
....@@ -14332,6 +14789,8 @@
1433214789 mouseMode |= BACKFORTH;
1433314790 }
1433414791
14792
+ targetLookAt.set(manipCamera.lookAt);
14793
+
1433514794 //prevX = X = anchorX;
1433614795 prevY = Y = anchorY + (int) (renderCamera.Distance());
1433714796 }
....@@ -14339,12 +14798,17 @@
1433914798 void GoLeft(int mod)
1434014799 {
1434114800 MODIFIERS |= COMMAND;
14342
- /*
14801
+ /**/
1434314802 if((mod&SHIFT) == SHIFT)
14344
- manipCamera.RotatePosition(speed, 0);
14803
+ manipCamera.Translate(speed*delta, 0, getWidth());
1434514804 else
14346
- manipCamera.Translate(speed*delta, 0, getWidth());
14347
- */
14805
+ {
14806
+ if ((mouseMode&VR)!=0)
14807
+ manipCamera.RotateInterest(-speed, 0);
14808
+ else
14809
+ manipCamera.RotatePosition(speed, 0);
14810
+ }
14811
+ /**/
1434814812 if ((mod & SHIFT) == SHIFT)
1434914813 {
1435014814 mouseMode = mouseMode;
....@@ -14353,6 +14817,8 @@
1435314817 mouseMode |= ROTATE;
1435414818 } // TRANSLATE;
1435514819
14820
+ targetLookAt.set(manipCamera.lookAt);
14821
+
1435614822 prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance());
1435714823 prevY = Y = anchorY;
1435814824 }
....@@ -14360,12 +14826,18 @@
1436014826 void GoRight(int mod)
1436114827 {
1436214828 MODIFIERS |= COMMAND;
14363
- /*
14829
+ /**/
1436414830 if((mod&SHIFT) == SHIFT)
14365
- manipCamera.RotatePosition(-speed, 0);
14831
+ manipCamera.Translate(-speed*delta, 0, getWidth());
1436614832 else
14367
- manipCamera.Translate(-speed*delta, 0, getWidth());
14368
- */
14833
+ {
14834
+ if ((mouseMode&VR)!=0)
14835
+ manipCamera.RotateInterest(speed, 0);
14836
+ else
14837
+ manipCamera.RotatePosition(-speed, 0);
14838
+ }
14839
+
14840
+ /**/
1436914841 if ((mod & SHIFT) == SHIFT)
1437014842 {
1437114843 mouseMode = mouseMode;
....@@ -14374,6 +14846,8 @@
1437414846 mouseMode |= ROTATE;
1437514847 } // TRANSLATE;
1437614848
14849
+ targetLookAt.set(manipCamera.lookAt);
14850
+
1437714851 prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance());
1437814852 prevY = Y = anchorY;
1437914853 }
....@@ -14415,15 +14889,16 @@
1441514889 if (editObj)
1441614890 {
1441714891 drag = true;
14418
- ClickInfo info = new ClickInfo();
14419
- info.bounds.setBounds(0, 0,
14892
+ //ClickInfo info = new ClickInfo();
14893
+ object.clickInfo.bounds.setBounds(0, 0,
1442014894 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14421
- info.pane = this;
14422
- info.camera = renderCamera;
14423
- info.x = x;
14424
- info.y = y;
14425
- object.GetWindow().copy
14426
- .doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
14895
+ object.clickInfo.pane = this;
14896
+ object.clickInfo.camera = renderCamera;
14897
+ object.clickInfo.x = x;
14898
+ object.clickInfo.y = y;
14899
+ object //.GetWindow().copy
14900
+ .doEditDrag(//info,
14901
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1442714902 } else
1442814903 {
1442914904 if (x < startX)
....@@ -14572,24 +15047,27 @@
1457215047 }
1457315048 }
1457415049
15050
+// ClickInfo clickInfo = new ClickInfo();
15051
+
1457515052 public void mouseMoved(MouseEvent e)
1457615053 {
1457715054 //System.out.println("mouseMoved: " + e);
1457815055 if (isRenderer)
1457915056 return;
1458015057
14581
- ClickInfo ci = new ClickInfo();
14582
- ci.x = e.getX();
14583
- ci.y = e.getY();
14584
- ci.modifiers = e.getModifiersEx();
14585
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14586
- ci.pane = this;
14587
- ci.camera = renderCamera;
15058
+ // Mouse cursor feedback
15059
+ object.clickInfo.x = e.getX();
15060
+ object.clickInfo.y = e.getY();
15061
+ object.clickInfo.modifiers = e.getModifiersEx();
15062
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
15063
+ object.clickInfo.pane = this;
15064
+ object.clickInfo.camera = renderCamera;
1458815065 if (!isRenderer)
1458915066 {
1459015067 //ObjEditor editWindow = object.editWindow;
1459115068 //Object3D copy = editWindow.copy;
14592
- if (object.doEditClick(ci, 0))
15069
+ if (object.doEditClick(//clickInfo,
15070
+ 0))
1459315071 {
1459415072 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1459515073 } else
....@@ -14861,7 +15339,8 @@
1486115339 // break;
1486215340 case 'T':
1486315341 CACHETEXTURE ^= true;
14864
- textures.clear();
15342
+ texturepigment.clear();
15343
+ texturebump.clear();
1486515344 // repaint();
1486615345 break;
1486715346 case 'Y':
....@@ -14871,8 +15350,8 @@
1487115350 case 'K':
1487215351 KOMPACTTEXTURE ^= true;
1487315352 //textures.clear();
14874
- break;
14875
- case 'P': // Texture Projection macros
15353
+ // break;
15354
+ //case 'P': // Texture Projection macros
1487615355 // SAVETEXTURE ^= true;
1487715356 macromode = true;
1487815357 Udebug = Vdebug = NORMALdebug = false; programInitialized = false;
....@@ -14946,7 +15425,9 @@
1494615425 case 'E' : COMPACT ^= true;
1494715426 repaint();
1494815427 break;
14949
- case 'W' : DEBUGHSB ^= true;
15428
+ case 'W' : // Wide Window (fullscreen)
15429
+ //DEBUGHSB ^= true;
15430
+ ObjEditor.theFrame.ToggleFullScreen();
1495015431 repaint();
1495115432 break;
1495215433 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14972,13 +15453,7 @@
1497215453 repaint();
1497315454 break;
1497415455 case 'l':
14975
- lightMode ^= true;
14976
- Globals.lighttouched = true;
14977
- manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
14978
- targetLookAt.set(manipCamera.lookAt);
14979
- repaint();
14980
- break;
14981
- case 'L':
15456
+ //case 'L':
1498215457 if (lightMode)
1498315458 {
1498415459 lightMode = false;
....@@ -14997,7 +15472,7 @@
1499715472 targetLookAt.set(manipCamera.lookAt);
1499815473 repaint();
1499915474 break;
15000
- case 'p':
15475
+ case 'P': // p':
1500115476 // c'est quoi ca au juste? spherical ^= true;
1500215477 Skinshader ^= true; programInitialized = false;
1500315478 repaint();
....@@ -15035,27 +15510,31 @@
1503515510 repaint();
1503615511 break;
1503715512 case 'O':
15038
- Globals.drawMode = OCCLUSION; // WARNING
15513
+ // Too dangerous. Use menu. Globals.drawMode = OCCLUSION; // WARNING
1503915514 repaint();
1504015515 break;
1504115516 case 'o':
1504215517 OCCLUSION_CULLING ^= true;
1504315518 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1504415519 break;
15045
- case '0': envyoff ^= true; repaint(); break;
15520
+ //case '0': envyoff ^= true; repaint(); break;
1504615521 case '1':
1504715522 case '2':
1504815523 case '3':
1504915524 case '4':
1505015525 case '5':
15051
- newenvy = Character.getNumericValue(key);
15052
- repaint();
15053
- break;
1505415526 case '6':
1505515527 case '7':
1505615528 case '8':
1505715529 case '9':
15058
- BGcolor = (key - '6')/3.f;
15530
+ if (true) // envyoff)
15531
+ {
15532
+ BGcolor = (key - '1')/8.f;
15533
+ }
15534
+ else
15535
+ {
15536
+ //newenvy = Character.getNumericValue(key);
15537
+ }
1505915538 repaint();
1506015539 break;
1506115540 case '!':
....@@ -15125,7 +15604,10 @@
1512515604 // kompactbit = 6;
1512615605 // break;
1512715606 case ' ':
15128
- ObjEditor.theFrame.ToggleFullScreen();
15607
+ lightMode ^= true;
15608
+ Globals.lighttouched = true;
15609
+ manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
15610
+ targetLookAt.set(manipCamera.lookAt);
1512915611 repaint();
1513015612 break;
1513115613 //case '`' :
....@@ -15615,8 +16097,6 @@
1561516097
1561616098 int width = getBounds().width;
1561716099 int height = getBounds().height;
15618
- ClickInfo info = new ClickInfo();
15619
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1562016100 //Image img = CreateImage(width, height);
1562116101 //System.out.println("width = " + width + "; height = " + height + "\n");
1562216102
....@@ -15693,38 +16173,47 @@
1569316173 }
1569416174 if (object != null && !hasMarquee)
1569516175 {
16176
+ if (object.clickInfo == null)
16177
+ object.clickInfo = new ClickInfo();
16178
+ ClickInfo info = object.clickInfo;
16179
+ //ClickInfo info = new ClickInfo();
16180
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16181
+
1569616182 if (isRenderer)
1569716183 {
15698
- info.flags++;
16184
+ object.clickInfo.flags++;
1569916185 double frameAspect = (double) width / (double) height;
1570016186 if (frameAspect > renderCamera.aspect)
1570116187 {
1570216188 int desired = (int) ((double) height * renderCamera.aspect);
15703
- info.bounds.width -= width - desired;
15704
- info.bounds.x += (width - desired) / 2;
16189
+ object.clickInfo.bounds.width -= width - desired;
16190
+ object.clickInfo.bounds.x += (width - desired) / 2;
1570516191 } else
1570616192 {
1570716193 int desired = (int) ((double) width / renderCamera.aspect);
15708
- info.bounds.height -= height - desired;
15709
- info.bounds.y += (height - desired) / 2;
16194
+ object.clickInfo.bounds.height -= height - desired;
16195
+ object.clickInfo.bounds.y += (height - desired) / 2;
1571016196 }
1571116197 }
15712
- info.g = gr;
15713
- info.camera = renderCamera;
16198
+
16199
+ object.clickInfo.g = gr;
16200
+ object.clickInfo.camera = renderCamera;
1571416201 /*
1571516202 // Memory intensive (brep.verticescopy)
1571616203 if (!(object instanceof Composite))
1571716204 object.draw(info, 0, false); // SLOW :
1571816205 */
15719
- if (!isRenderer)
16206
+ if (!isRenderer) // && drag)
1572016207 {
16208
+ Grafreed.Assert(object != null);
16209
+ Grafreed.Assert(object.selection != null);
1572116210 if (object.selection.Size() > 0)
1572216211 {
1572316212 int hitSomething = object.selection.get(0).hitSomething;
1572416213
15725
- info.DX = 0;
15726
- info.DY = 0;
15727
- info.W = 1;
16214
+ object.clickInfo.DX = 0;
16215
+ object.clickInfo.DY = 0;
16216
+ object.clickInfo.W = 1;
1572816217 if (hitSomething == Object3D.hitCenter)
1572916218 {
1573016219 info.DX = X;
....@@ -15736,13 +16225,14 @@
1573616225 info.DY -= info.bounds.height/2;
1573716226 }
1573816227
15739
- object.drawEditHandles(info, 0);
16228
+ object.drawEditHandles(//info,
16229
+ 0);
1574016230
1574116231 if (drag && (X != 0 || Y != 0))
1574216232 {
1574316233 switch (hitSomething)
1574416234 {
15745
- case Object3D.hitCenter: gr.setColor(Color.pink);
16235
+ case Object3D.hitCenter: gr.setColor(Color.white);
1574616236 gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
1574716237 break;
1574816238 case Object3D.hitRotate: gr.setColor(Color.yellow);
....@@ -15768,7 +16258,7 @@
1576816258 if (hasMarquee)
1576916259 {
1577016260 gr.setXORMode(Color.white);
15771
- gr.setColor(Color.red);
16261
+ gr.setColor(Color.white);
1577216262 if (!firstime)
1577316263 {
1577416264 gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH);
....@@ -16235,6 +16725,8 @@
1623516725 private /*static*/ boolean firstime;
1623616726 private /*static*/ cVector newView = new cVector();
1623716727 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16728
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16729
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1623816730 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1623916731 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1624016732 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16247,29 +16739,67 @@
1624716739 {
1624816740 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1624916741
16742
+ int usedsuf = 0;
16743
+
1625016744 for (int i = 0; i < suffixes.length; i++)
1625116745 {
16252
- String resourceName = basename + suffixes[i] + "." + suffix;
16253
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16254
- mipmapped,
16255
- FileUtil.getFileSuffix(resourceName));
16256
- if (data == null)
16746
+ String[] suffixe = suffixes;
16747
+ String[] fallback = suffixes2;
16748
+ String[] fallfallback = suffixes3;
16749
+
16750
+ for (int c=usedsuf; --c>=0;)
1625716751 {
16258
- throw new IOException("Unable to load texture " + resourceName);
16752
+// String[] temp = suffixe;
16753
+// suffixe = fallback;
16754
+// fallback = fallfallback;
16755
+// fallfallback = temp;
1625916756 }
16757
+
16758
+ String resourceName = basename + suffixe[i] + "." + suffix;
16759
+ TextureData data;
16760
+
16761
+ try
16762
+ {
16763
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16764
+ mipmapped,
16765
+ FileUtil.getFileSuffix(resourceName));
16766
+ }
16767
+ catch (Exception e)
16768
+ {
16769
+ try
16770
+ {
16771
+ resourceName = basename + fallback[i] + "." + suffix;
16772
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16773
+ mipmapped,
16774
+ FileUtil.getFileSuffix(resourceName));
16775
+ }
16776
+ catch (Exception e2)
16777
+ {
16778
+ resourceName = basename + fallfallback[i] + "." + suffix;
16779
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16780
+ mipmapped,
16781
+ FileUtil.getFileSuffix(resourceName));
16782
+ }
16783
+ }
16784
+
1626016785 //System.out.println("Target = " + targets[i]);
1626116786 cubemap.updateImage(data, targets[i]);
1626216787 }
1626316788
1626416789 return cubemap;
1626516790 }
16791
+
1626616792 int bigsphere = -1;
1626716793
1626816794 float BGcolor = 0.5f;
1626916795
16270
- private void DrawSkyBox(GL gl)
16796
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16797
+
16798
+ private void DrawSkyBox(GL gl, float ratio)
1627116799 {
16272
- if (envyoff || cubemap == null)
16800
+ if (//envyoff ||
16801
+ WIREFRAME ||
16802
+ cubemap == null)
1627316803 {
1627416804 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1627516805 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16284,7 +16814,17 @@
1628416814 // Compensates for ExaminerViewer's modification of modelview matrix
1628516815 gl.glMatrixMode(GL.GL_MODELVIEW);
1628616816 gl.glLoadIdentity();
16817
+ gl.glScalef(1,ratio,1);
1628716818
16819
+// colorV[0] = 2;
16820
+// colorV[1] = 2;
16821
+// colorV[2] = 2;
16822
+// colorV[3] = 1;
16823
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16824
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16825
+//
16826
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16827
+
1628816828 //gl.glActiveTexture(GL.GL_TEXTURE1);
1628916829 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1629016830
....@@ -16316,6 +16856,7 @@
1631616856 {
1631716857 gl.glScalef(1.0f, -1.0f, 1.0f);
1631816858 }
16859
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1631916860 gl.glMultMatrixd(viewrot_1, 0);
1632016861 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1632116862 //viewer.updateInverseRotation(gl);
....@@ -16356,7 +16897,8 @@
1635616897 gl.glDisable(GL.GL_TEXTURE_GEN_R);
1635716898
1635816899 cubemap.disable();
16359
- ////cubemap.unbind();
16900
+ //cubemap.dispose();
16901
+
1636016902 if (CULLFACE)
1636116903 {
1636216904 gl.glEnable(gl.GL_CULL_FACE);
....@@ -16412,7 +16954,7 @@
1641216954 gl.glScalef(1.0f, -1.0f, 1.0f);
1641316955 }
1641416956
16415
- gl.glNormal3f(0.0f, 0.0f, 1.0f);
16957
+ SetGLNormal(gl, 0.0f, 0.0f, 1.0f);
1641616958
1641716959 float step = 2; // 0.1666f; //0.25f;
1641816960 float stepv = 2; // step * 1652 / 998;
....@@ -16551,6 +17093,14 @@
1655117093 }
1655217094 }
1655317095
17096
+ private Object3D GetFolder()
17097
+ {
17098
+ Object3D folder = object.GetWindow().copy;
17099
+ if (object.GetWindow().copy.selection.Size() > 0)
17100
+ folder = object.GetWindow().copy.selection.elementAt(0);
17101
+ return folder;
17102
+ }
17103
+
1655417104 class SelectBuffer implements GLEventListener
1655517105 {
1655617106
....@@ -16566,7 +17116,7 @@
1656617116 //new Exception().printStackTrace();
1656717117 System.out.println("select buffer init");
1656817118 // Use debug pipeline
16569
- drawable.setGL(new DebugGL(drawable.getGL()));
17119
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1657017120
1657117121 GL gl = drawable.getGL();
1657217122
....@@ -16630,6 +17180,17 @@
1663017180
1663117181 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1663217182
17183
+ if (PAINTMODE)
17184
+ {
17185
+ if (object.GetWindow().copy.selection.Size() > 0)
17186
+ {
17187
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17188
+
17189
+ // Make what you paint not selectable.
17190
+ paintobj.ResetSelectable();
17191
+ }
17192
+ }
17193
+
1663317194 //int tmp = selection_view;
1663417195 //selection_view = -1;
1663517196 int temp = DrawMode();
....@@ -16641,6 +17202,17 @@
1664117202 // temp = DEFAULT; // patch for selection debug
1664217203 Globals.drawMode = temp; // WARNING
1664317204
17205
+ if (PAINTMODE)
17206
+ {
17207
+ if (object.GetWindow().copy.selection.Size() > 0)
17208
+ {
17209
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17210
+
17211
+ // Revert.
17212
+ paintobj.RestoreSelectable();
17213
+ }
17214
+ }
17215
+
1664417216 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1664517217
1664617218 // trying different ways of getting the depth info over
....@@ -16746,27 +17318,29 @@
1674617318 if (!movingcamera && !PAINTMODE)
1674717319 object.GetWindow().ScreenFitPoint(); // fev 2014
1674817320
16749
- if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17321
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1675017322 {
16751
- Object3D paintobj = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
16752
-
16753
- Object3D group = new Object3D("inst" + paintcount++);
16754
-
16755
- group.CreateMaterial(); // use a void leaf to select instances
16756
-
16757
- group.add(paintobj); // link
16758
-
16759
- object.GetWindow().SnapObject(group);
16760
-
16761
- Object3D folder = object.GetWindow().copy;
17323
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1676217324
1676317325 if (object.GetWindow().copy.selection.Size() > 0)
16764
- folder = object.GetWindow().copy.selection.elementAt(0);
17326
+ {
17327
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1676517328
16766
- folder.add(group);
16767
-
16768
- object.GetWindow().ResetModel();
16769
- object.GetWindow().refreshContents();
17329
+ Object3D inst = new Object3D("inst" + paintcount++);
17330
+
17331
+ inst.CreateMaterial(); // use a void leaf to select instances
17332
+
17333
+ inst.add(paintobj); // link
17334
+
17335
+ object.GetWindow().SnapObject(inst);
17336
+
17337
+ Object3D folder = paintFolder; // GetFolder();
17338
+
17339
+ folder.add(inst);
17340
+
17341
+ object.GetWindow().ResetModel();
17342
+ object.GetWindow().refreshContents();
17343
+ }
1677017344 }
1677117345 else
1677217346 paintcount = 0;
....@@ -16860,6 +17434,7 @@
1686017434
1686117435 public void init(GLAutoDrawable drawable)
1686217436 {
17437
+ if (Globals.DEBUG)
1686317438 System.out.println("shadow buffer init");
1686417439
1686517440 GL gl = drawable.getGL();
....@@ -17088,10 +17663,14 @@
1708817663 gl.glFlush();
1708917664
1709017665 /**/
17091
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17666
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1709217667
17093
- float[] pixels = occlusionsizebuffer.array();
17668
+ float[] depths = occlusiondepthbuffer.array();
1709417669
17670
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17671
+
17672
+ int[] pixels = selectsizebuffer.array();
17673
+
1709517674 double r = 0, g = 0, b = 0;
1709617675
1709717676 double count = 0;
....@@ -17102,7 +17681,7 @@
1710217681
1710317682 double FACTOR = 1;
1710417683
17105
- for (int i = 0; i < pixels.length; i++)
17684
+ for (int i = 0; i < depths.length; i++)
1710617685 {
1710717686 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1710817687 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -17185,7 +17764,7 @@
1718517764
1718617765 double scale = ray.z; // 1; // cos
1718717766
17188
- float depth = pixels[newindex];
17767
+ float depth = depths[newindex];
1718917768
1719017769 /*
1719117770 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -17382,11 +17961,14 @@
1738217961 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1738317962 static IntBuffer bigAAbuffer;
1738417963 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
17385
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17964
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1738617965 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1738717966 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1738817967 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17389
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17968
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17969
+
17970
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17971
+
1739017972 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1739117973 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1739217974 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();