Normand Briere
2019-08-17 d5d6485126da83b06645e90e3e4ce66659a56009
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
....@@ -1447,6 +1502,8 @@
14471502 gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
14481503 }
14491504
1505
+ float[] colorV = new float[4];
1506
+
14501507 void SetColor(Object3D obj, Vertex p0)
14511508 {
14521509 CameraPane display = this;
....@@ -1514,8 +1571,6 @@
15141571 {
15151572 return;
15161573 }
1517
-
1518
- float[] colorV = new float[3];
15191574
15201575 if (false) // marked)
15211576 {
....@@ -2298,10 +2353,17 @@
22982353 HANDLES ^= true;
22992354 }
23002355
2356
+ Object3D paintFolder;
2357
+
23012358 void TogglePaint()
23022359 {
23032360 PAINTMODE ^= true;
23042361 paintcount = 0;
2362
+
2363
+ if (PAINTMODE)
2364
+ {
2365
+ paintFolder = GetFolder();
2366
+ }
23052367 }
23062368
23072369 void SwapCamera(int a, int b)
....@@ -2398,6 +2460,21 @@
23982460 return currentGL;
23992461 }
24002462
2463
+ static private BufferedImage CreateBim(TextureData texturedata)
2464
+ {
2465
+ Grafreed.Assert(texturedata != null);
2466
+
2467
+ int width = texturedata.getWidth();
2468
+ int height = texturedata.getHeight();
2469
+
2470
+ Buffer buffer = texturedata.getBuffer();
2471
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2472
+
2473
+ byte[] bytes = bytebuf.array();
2474
+
2475
+ return CreateBim(bytes, width, height);
2476
+ }
2477
+
24012478 /**/
24022479 class CacheTexture
24032480 {
....@@ -2406,28 +2483,31 @@
24062483
24072484 int resolution;
24082485
2409
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2486
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
24102487 {
2411
- texture = tex;
2488
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2489
+ texturedata = texdata;
24122490 resolution = res;
24132491 }
24142492 }
24152493 /**/
24162494
24172495 // 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>();
2496
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2497
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2498
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2499
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2500
+
24212501 int pigmentdepth = 0;
24222502 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
24232503 int bumpdepth = 0;
24242504 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
24252505 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
24262506 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2427
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2507
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
24282508 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
24292509
2430
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2510
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
24312511 {
24322512 TextureData texturedata = null;
24332513
....@@ -2437,7 +2517,7 @@
24372517 com.sun.opengl.util.texture.TextureIO.newTextureData(
24382518 getClass().getClassLoader().getResourceAsStream(name),
24392519 true,
2440
- com.sun.opengl.util.texture.TextureIO.PNG);
2520
+ GetFormat(name)); // com.sun.opengl.util.texture.TextureIO.PNG);
24412521 } catch (java.io.IOException e)
24422522 {
24432523 throw new javax.media.opengl.GLException(e);
....@@ -2446,13 +2526,34 @@
24462526 if (bump)
24472527 texturedata = ConvertBump(texturedata, false);
24482528
2449
- com.sun.opengl.util.texture.Texture texture =
2450
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2529
+// com.sun.opengl.util.texture.Texture texture =
2530
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
24512531
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);
2532
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2533
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
24542534
2455
- return texture;
2535
+ return texturedata;
2536
+ }
2537
+
2538
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2539
+ {
2540
+ TextureData texturedata = null;
2541
+
2542
+ try
2543
+ {
2544
+ texturedata =
2545
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2546
+ bim,
2547
+ true);
2548
+ } catch (Exception e)
2549
+ {
2550
+ throw new javax.media.opengl.GLException(e);
2551
+ }
2552
+
2553
+ if (bump)
2554
+ texturedata = ConvertBump(texturedata, false);
2555
+
2556
+ return texturedata;
24562557 }
24572558
24582559 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3525,6 +3626,8 @@
35253626
35263627 System.out.println("LOADING TEXTURE : " + name);
35273628
3629
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3630
+
35283631 //
35293632 if (false) // compressbit > 0)
35303633 {
....@@ -7923,7 +8026,7 @@
79238026 String pigment = Object3D.GetPigment(tex);
79248027 String bump = Object3D.GetBump(tex);
79258028
7926
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8029
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79278030 {
79288031 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79298032 // System.out.println("; bump = " + bump);
....@@ -7938,8 +8041,8 @@
79388041 pigment = null;
79398042 }
79408043
7941
- ReleaseTexture(bump, true);
7942
- ReleaseTexture(pigment, false);
8044
+ ReleaseTexture(tex, true);
8045
+ ReleaseTexture(tex, false);
79438046 }
79448047
79458048 public void ReleasePigmentTexture(cTexture tex) // INTERFACE
....@@ -7957,7 +8060,7 @@
79578060
79588061 String pigment = Object3D.GetPigment(tex);
79598062
7960
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8063
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79618064 {
79628065 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79638066 // System.out.println("; bump = " + bump);
....@@ -7968,7 +8071,7 @@
79688071 pigment = null;
79698072 }
79708073
7971
- ReleaseTexture(pigment, false);
8074
+ ReleaseTexture(tex, false);
79728075 }
79738076
79748077 public void ReleaseBumpTexture(cTexture tex) // INTERFACE
....@@ -7986,7 +8089,7 @@
79868089
79878090 String bump = Object3D.GetBump(tex);
79888091
7989
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8092
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79908093 {
79918094 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79928095 // System.out.println("; bump = " + bump);
....@@ -7997,10 +8100,10 @@
79978100 bump = null;
79988101 }
79998102
8000
- ReleaseTexture(bump, true);
8103
+ ReleaseTexture(tex, true);
80018104 }
80028105
8003
- void ReleaseTexture(String tex, boolean bump)
8106
+ void ReleaseTexture(cTexture tex, boolean bump)
80048107 {
80058108 if (// DrawMode() != 0 || /*tex == null ||*/
80068109 ambientOcclusion ) // || !textureon)
....@@ -8011,7 +8114,7 @@
80118114 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
80128115
80138116 if (tex != null)
8014
- texture = textures.get(tex);
8117
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
80158118
80168119 // //assert( texture != null );
80178120 // if (texture == null)
....@@ -8105,47 +8208,50 @@
81058208
81068209 /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
81078210 {
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
- }
8211
+// if (// DrawMode() != 0 || /*tex == null ||*/
8212
+// ambientOcclusion ) // || !textureon)
8213
+// {
8214
+// return; // false;
8215
+// }
8216
+//
8217
+// if (tex == null)
8218
+// {
8219
+// BindTexture(null,false,resolution);
8220
+// BindTexture(null,true,resolution);
8221
+// return;
8222
+// }
8223
+//
8224
+// String pigment = Object3D.GetPigment(tex);
8225
+// String bump = Object3D.GetBump(tex);
8226
+//
8227
+// usedtextures.add(pigment);
8228
+// usedtextures.add(bump);
8229
+//
8230
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8231
+// {
8232
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8233
+// // System.out.println("; bump = " + bump);
8234
+// }
8235
+//
8236
+// if (bump.equals(""))
8237
+// {
8238
+// bump = null;
8239
+// }
8240
+// if (pigment.equals(""))
8241
+// {
8242
+// pigment = null;
8243
+// }
8244
+//
8245
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8246
+// BindTexture(pigment, false, resolution);
8247
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8248
+// BindTexture(bump, true, resolution);
8249
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8250
+//
8251
+// return; // true;
81208252
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;
8253
+ BindPigmentTexture(tex, resolution);
8254
+ BindBumpTexture(tex, resolution);
81498255 }
81508256
81518257 /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8164,9 +8270,9 @@
81648270
81658271 String pigment = Object3D.GetPigment(tex);
81668272
8167
- usedtextures.put(pigment, pigment);
8273
+ usedtextures.add(tex);
81688274
8169
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8275
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
81708276 {
81718277 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
81728278 // System.out.println("; bump = " + bump);
....@@ -8178,7 +8284,7 @@
81788284 }
81798285
81808286 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8181
- BindTexture(pigment, false, resolution);
8287
+ BindTexture(tex, false, resolution);
81828288 }
81838289
81848290 /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8197,9 +8303,9 @@
81978303
81988304 String bump = Object3D.GetBump(tex);
81998305
8200
- usedtextures.put(bump, bump);
8306
+ usedtextures.add(tex);
82018307
8202
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8308
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
82038309 {
82048310 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
82058311 // System.out.println("; bump = " + bump);
....@@ -8211,7 +8317,7 @@
82118317 }
82128318
82138319 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8214
- BindTexture(bump, true, resolution);
8320
+ BindTexture(tex, true, resolution);
82158321 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
82168322 }
82178323
....@@ -8235,13 +8341,19 @@
82358341 return fileExists;
82368342 }
82378343
8238
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception
8344
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
82398345 {
8240
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8346
+ CacheTexture texturecache = null;
82418347
82428348 if (tex != null)
82438349 {
8244
- String texname = tex;
8350
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8351
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
8352
+
8353
+ if (texname.equals("") && texdata == null)
8354
+ {
8355
+ return null;
8356
+ }
82458357
82468358 String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
82478359
....@@ -8251,19 +8363,46 @@
82518363 // else
82528364 // if (!texname.startsWith("/"))
82538365 // texname = "/Users/nbriere/Textures/" + texname;
8254
- if (!FileExists(tex))
8366
+ if (!FileExists(texname) && !texname.startsWith("@"))
82558367 {
82568368 texname = fallbackTextureName;
82578369 }
82588370
82598371 if (CACHETEXTURE)
8260
- texture = textures.get(texname); // TEXTURE CACHE
8261
-
8262
- TextureData texturedata = null;
8263
-
8264
- if (texture == null || texture.resolution < resolution)
82658372 {
8266
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8373
+ if (texdata == null)
8374
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8375
+ else
8376
+ texturecache = bimtextures.get(texdata);
8377
+ }
8378
+
8379
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8380
+ {
8381
+ TextureData texturedata = null;
8382
+
8383
+ if (texdata != null && textureon)
8384
+ {
8385
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8386
+
8387
+ try
8388
+ {
8389
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8390
+ }
8391
+ catch (Exception e)
8392
+ {
8393
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8394
+ }
8395
+
8396
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8397
+ bimtextures.put(texdata, texturecache);
8398
+
8399
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8400
+
8401
+ //Object bim2 = CreateBim(texturecache.texturedata);
8402
+ //bim2 = bim;
8403
+ }
8404
+ else
8405
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
82678406 {
82688407 assert(!bump);
82698408 // if (bump)
....@@ -8274,19 +8413,23 @@
82748413 // }
82758414 // else
82768415 // {
8277
- texture = textures.get(tex);
8278
- if (texture == null)
8416
+ // texturecache = textures.get(texname); // suspicious
8417
+ if (texturecache == null)
82798418 {
8280
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8419
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
82818420 }
8421
+ else
8422
+ new Exception().printStackTrace();
82828423 // }
82838424 } else
8284
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8425
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
82858426 {
82868427 assert(bump);
8287
- texture = textures.get(tex);
8288
- if (texture == null)
8289
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8428
+ // texturecache = textures.get(texname); // suspicious
8429
+ if (texturecache == null)
8430
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8431
+ else
8432
+ new Exception().printStackTrace();
82908433 } else
82918434 {
82928435 //if (tex.equals("IMMORTAL"))
....@@ -8294,11 +8437,22 @@
82948437 // texture = GetResourceTexture("default.png");
82958438 //} else
82968439 //{
8297
- if (tex.equals("WHITE_NOISE"))
8440
+ if (texname.endsWith("WHITE_NOISE"))
82988441 {
8299
- texture = textures.get(tex);
8300
- if (texture == null)
8301
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8442
+ // texturecache = textures.get(texname); // suspicious
8443
+ if (texturecache == null)
8444
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8445
+ else
8446
+ new Exception().printStackTrace();
8447
+ } else
8448
+ {
8449
+ if (texname.startsWith("@"))
8450
+ {
8451
+ // texturecache = textures.get(texname); // suspicious
8452
+ if (texturecache == null)
8453
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8454
+ else
8455
+ new Exception().printStackTrace();
83028456 } else
83038457 {
83048458 if (textureon)
....@@ -8357,19 +8511,20 @@
83578511 if (texturedata == null)
83588512 throw new Exception();
83598513
8360
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8514
+ texturecache = new CacheTexture(texturedata,resolution);
83618515 //texture = GetTexture(tex, bump);
83628516 }
8517
+ }
83638518 }
83648519 //}
83658520 }
83668521
8367
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8522
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
83688523 {
83698524 //return false;
83708525
83718526 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8372
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8527
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
83738528 {
83748529 // String ext = "_highres";
83758530 // if (REDUCETEXTURE)
....@@ -8386,52 +8541,17 @@
83868541 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
83878542 if (!cachefile.exists())
83888543 {
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))
8544
+ //if (texturedata.getWidth() == texturedata.getHeight())
83988545 {
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);
8546
+ BufferedImage rendImage = CreateBim(texturedata);
8547
+
84298548 ImageWriter writer = null;
84308549 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
84318550 if (iter.hasNext()) {
84328551 writer = (ImageWriter)iter.next();
84338552 }
8434
- float compressionQuality = 0.9f;
8553
+
8554
+ float compressionQuality = 0.85f;
84358555 try
84368556 {
84378557 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8448,18 +8568,20 @@
84488568 }
84498569 }
84508570 }
8451
-
8571
+
8572
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8573
+
84528574 //System.out.println("Texture = " + tex);
8453
- if (textures.containsKey(texname))
8575
+ if (textures.containsKey(tex))
84548576 {
8455
- CacheTexture thetex = textures.get(texname);
8577
+ CacheTexture thetex = textures.get(tex);
84568578 thetex.texture.disable();
84578579 thetex.texture.dispose();
8458
- textures.remove(texname);
8580
+ textures.remove(tex);
84598581 }
84608582
8461
- texture.texturedata = texturedata;
8462
- textures.put(texname, texture);
8583
+ //texture.texturedata = texturedata;
8584
+ textures.put(tex, texturecache);
84638585
84648586 // newtex = true;
84658587 }
....@@ -8475,10 +8597,44 @@
84758597 }
84768598 }
84778599
8478
- return texture;
8600
+ return texturecache;
84798601 }
84808602
8481
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution) throws Exception
8603
+ static void EmbedTextures(cTexture tex)
8604
+ {
8605
+ if (tex.pigmentdata == null)
8606
+ {
8607
+ //String texname = Object3D.GetPigment(tex);
8608
+
8609
+ CacheTexture texturecache = texturepigment.get(tex);
8610
+
8611
+ if (texturecache != null)
8612
+ {
8613
+ tex.pw = texturecache.texturedata.getWidth();
8614
+ tex.ph = texturecache.texturedata.getHeight();
8615
+ tex.pigmentdata = //CompressJPEG(CreateBim
8616
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8617
+ ;
8618
+ //, tex.pw, tex.ph), 0.5f);
8619
+ }
8620
+ }
8621
+
8622
+ if (tex.bumpdata == null)
8623
+ {
8624
+ //String texname = Object3D.GetBump(tex);
8625
+
8626
+ CacheTexture texturecache = texturebump.get(tex);
8627
+
8628
+ if (texturecache != null)
8629
+ {
8630
+ tex.bw = texturecache.texturedata.getWidth();
8631
+ tex.bh = texturecache.texturedata.getHeight();
8632
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8633
+ }
8634
+ }
8635
+ }
8636
+
8637
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
84828638 {
84838639 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
84848640
....@@ -8496,21 +8652,21 @@
84968652 return texture!=null?texture.texture:null;
84978653 }
84988654
8499
- public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution) throws Exception
8655
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
85008656 {
85018657 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
85028658
85038659 return texture!=null?texture.texturedata:null;
85048660 }
85058661
8506
- boolean BindTexture(String tex, boolean bump, int resolution) throws Exception
8662
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
85078663 {
85088664 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
85098665 {
85108666 return false;
85118667 }
85128668
8513
- boolean newtex = false;
8669
+ //boolean newtex = false;
85148670
85158671 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
85168672
....@@ -8542,9 +8698,75 @@
85428698 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
85438699 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
85448700
8545
- return newtex;
8701
+ return true; // Warning: not used.
85468702 }
85478703
8704
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8705
+ {
8706
+ try
8707
+ {
8708
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8709
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8710
+ ImageWriter writer = writers.next();
8711
+
8712
+ ImageWriteParam param = writer.getDefaultWriteParam();
8713
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8714
+ param.setCompressionQuality(quality);
8715
+
8716
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8717
+ writer.setOutput(ios);
8718
+ writer.write(null, new IIOImage(image, null, null), param);
8719
+
8720
+ byte[] data = baos.toByteArray();
8721
+ writer.dispose();
8722
+ return data;
8723
+ }
8724
+ catch (Exception e)
8725
+ {
8726
+ e.printStackTrace();
8727
+ return null;
8728
+ }
8729
+ }
8730
+
8731
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8732
+ {
8733
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8734
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8735
+ ImageReader reader = writers.next();
8736
+
8737
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8738
+
8739
+ ImageReadParam param = reader.getDefaultReadParam();
8740
+ param.setDestination(bim);
8741
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8742
+
8743
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8744
+ reader.setInput(ios);
8745
+ BufferedImage bim2 = reader.read(0, param);
8746
+ reader.dispose();
8747
+
8748
+// WritableRaster raster = bim2.getRaster();
8749
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8750
+// byte[] bytes = data.getData();
8751
+//
8752
+// int[] pixels = new int[bytes.length/3];
8753
+// for (int i=pixels.length; --i>=0;)
8754
+// {
8755
+// int i3 = i*3;
8756
+// pixels[i] = 0xFF;
8757
+// pixels[i] <<= 8;
8758
+// pixels[i] |= bytes[i3+2] & 0xFF;
8759
+// pixels[i] <<= 8;
8760
+// pixels[i] |= bytes[i3+1] & 0xFF;
8761
+// pixels[i] <<= 8;
8762
+// pixels[i] |= bytes[i3] & 0xFF;
8763
+// }
8764
+//
8765
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8766
+
8767
+ return bim;
8768
+ }
8769
+
85488770 ShadowBuffer shadowPBuf;
85498771 AntialiasBuffer antialiasPBuf;
85508772 int MAXSTACK;
....@@ -8561,10 +8783,12 @@
85618783
85628784 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
85638785 MAXSTACK = temp[0];
8564
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8786
+ if (Globals.DEBUG)
8787
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
85658788 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
85668789 MAXSTACK = temp[0];
8567
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8790
+ if (Globals.DEBUG)
8791
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
85688792
85698793 // Use debug pipeline
85708794 //drawable.setGL(new DebugGL(gl)); //
....@@ -8572,7 +8796,8 @@
85728796 gl = drawable.getGL(); //
85738797
85748798 GL gl3 = getGL();
8575
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8799
+ if (Globals.DEBUG)
8800
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
85768801
85778802
85788803 //float pos[] = { 100, 100, 100, 0 };
....@@ -8737,7 +8962,7 @@
87378962
87388963 if (cubemap == null)
87398964 {
8740
- LoadEnvy(5);
8965
+ //LoadEnvy(1);
87418966 }
87428967
87438968 //cubemap.enable();
....@@ -9013,6 +9238,8 @@
90139238
90149239 void LoadEnvy(int which)
90159240 {
9241
+ assert(false);
9242
+
90169243 String name;
90179244 String ext;
90189245
....@@ -9024,37 +9251,58 @@
90249251 cubemap = null;
90259252 return;
90269253 case 1:
9027
- name = "cubemaps/box_";
9028
- ext = "png";
9254
+ name = "cubemaps/rgb/";
9255
+ ext = "jpg";
90299256 reverseUP = false;
90309257 break;
90319258 case 2:
9032
- name = "cubemaps/uffizi_";
9033
- ext = "png";
9034
- break; // reverseUP = true; break;
9259
+ name = "cubemaps/uffizi/";
9260
+ ext = "jpg";
9261
+ reverseUP = false;
9262
+ break;
90359263 case 3:
9036
- name = "cubemaps/CloudyHills_";
9037
- ext = "tga";
9264
+ name = "cubemaps/CloudyHills/";
9265
+ ext = "jpg";
90389266 reverseUP = false;
90399267 break;
90409268 case 4:
9041
- name = "cubemaps/cornell_";
9269
+ name = "cubemaps/cornell/";
90429270 ext = "png";
90439271 reverseUP = false;
90449272 break;
9273
+ case 5:
9274
+ name = "cubemaps/skycube/";
9275
+ ext = "jpg";
9276
+ reverseUP = false;
9277
+ break;
9278
+ case 6:
9279
+ name = "cubemaps/SaintLazarusChurch3/";
9280
+ ext = "jpg";
9281
+ reverseUP = false;
9282
+ break;
9283
+ case 7:
9284
+ name = "cubemaps/Sodermalmsallen/";
9285
+ ext = "jpg";
9286
+ reverseUP = false;
9287
+ break;
9288
+ case 8:
9289
+ name = "cubemaps/Sodermalmsallen2/";
9290
+ ext = "jpg";
9291
+ reverseUP = false;
9292
+ break;
9293
+ case 9:
9294
+ name = "cubemaps/UnionSquare/";
9295
+ ext = "jpg";
9296
+ reverseUP = false;
9297
+ break;
90459298 default:
9046
- name = "cubemaps/rgb_";
9047
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9299
+ name = "cubemaps/box/";
9300
+ ext = "png"; /*mipmap = true;*/
9301
+ reverseUP = false;
90489302 break;
90499303 }
9050
-
9051
- try
9052
- {
9053
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
9054
- } catch (IOException e)
9055
- {
9056
- throw new RuntimeException(e);
9057
- }
9304
+
9305
+ LoadSkybox(name, ext, mipmap);
90589306 }
90599307
90609308 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -9086,8 +9334,12 @@
90869334 static double[] model = new double[16];
90879335 double[] camera2light = new double[16];
90889336 double[] light2camera = new double[16];
9089
- int newenvy = -1;
9090
- boolean envyoff = true; // false;
9337
+
9338
+ //int newenvy = -1;
9339
+ //boolean envyoff = false;
9340
+
9341
+ String loadedskyboxname;
9342
+
90919343 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
90929344 //float[] light0 = { 0,0,0 };
90939345 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9505,7 +9757,7 @@
95059757
95069758 if (renderCamera != lightCamera)
95079759 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9508
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
9760
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
95099761
95109762 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
95119763
....@@ -9521,7 +9773,7 @@
95219773
95229774 if (renderCamera != lightCamera)
95239775 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9524
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
9776
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
95259777
95269778 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
95279779
....@@ -9567,10 +9819,12 @@
95679819 rati = 1 / rati;
95689820 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
95699821 }
9570
- assert (newenvy == -1);
9822
+
9823
+ //assert (newenvy == -1);
9824
+
95719825 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
95729826 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9573
- DrawSkyBox(gl);
9827
+ DrawSkyBox(gl, (float)rati);
95749828 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
95759829 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
95769830 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10436,9 +10690,18 @@
1043610690 static boolean init = false;
1043710691
1043810692 double[][] matrix = LA.newMatrix();
10693
+
10694
+ // This is to refresh the UI of the material panel.
10695
+ ObjEditor patchMaterial;
1043910696
1044010697 public void display(GLAutoDrawable drawable)
1044110698 {
10699
+ if (patchMaterial.patchMaterial)
10700
+ {
10701
+ patchMaterial.patchMaterial = false;
10702
+ patchMaterial.objectPanel.setSelectedIndex(0);
10703
+ }
10704
+
1044210705 if (Grafreed.savesound && Grafreed.hassound)
1044310706 {
1044410707 Grafreed.wav.save();
....@@ -10607,7 +10870,7 @@
1060710870
1060810871 if (wait)
1060910872 {
10610
- Sleep(500);
10873
+ Sleep(200); // blocks everything
1061110874
1061210875 wait = false;
1061310876 }
....@@ -10722,7 +10985,7 @@
1072210985 // if (parentcam != renderCamera) // not a light
1072310986 if (cam != lightCamera)
1072410987 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10725
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
10988
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1072610989
1072710990 for (int j = 0; j < 4; j++)
1072810991 {
....@@ -10737,7 +11000,7 @@
1073711000 // if (parentcam != renderCamera) // not a light
1073811001 if (cam != lightCamera)
1073911002 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10740
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
11003
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1074111004
1074211005 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1074311006
....@@ -10823,13 +11086,43 @@
1082311086 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1082411087 }
1082511088
10826
- if (newenvy > -1)
11089
+// if (newenvy > -1)
11090
+// {
11091
+// LoadEnvy(newenvy);
11092
+// }
11093
+//
11094
+// newenvy = -1;
11095
+
11096
+ if (transformMode) // object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
1082711097 {
10828
- LoadEnvy(newenvy);
11098
+ if (cubemaprgb == null)
11099
+ {
11100
+ cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb2" + "/", "jpg", false);
11101
+ }
11102
+
11103
+ cubemap = cubemaprgb;
1082911104 }
10830
-
10831
- newenvy = -1;
10832
-
11105
+ else
11106
+ {
11107
+ if (object.skyboxname != null)
11108
+ {
11109
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11110
+ {
11111
+ if (cubemap != null && cubemap != cubemaprgb)
11112
+ cubemap.dispose();
11113
+ cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11114
+ loadedskyboxname = object.skyboxname;
11115
+ }
11116
+ }
11117
+ else
11118
+ {
11119
+ cubemapcustom = null;
11120
+ loadedskyboxname = null;
11121
+ }
11122
+
11123
+ cubemap = cubemapcustom;
11124
+ }
11125
+
1083311126 ratio = ((double) getWidth()) / getHeight();
1083411127 //System.out.println("ratio = " + ratio);
1083511128
....@@ -10845,7 +11138,7 @@
1084511138
1084611139 if (!IsFrozen() && !ambientOcclusion)
1084711140 {
10848
- DrawSkyBox(gl);
11141
+ DrawSkyBox(gl, (float)ratio);
1084911142 }
1085011143
1085111144 //if (selection_view == -1)
....@@ -11131,7 +11424,7 @@
1113111424
1113211425 // if (cam != lightCamera)
1113311426 //for (int count = parentcam.GetTransformCount(); --count>=0;)
11134
- LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
11427
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1113511428 }
1113611429
1113711430 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -11290,7 +11583,7 @@
1129011583 }
1129111584 }
1129211585
11293
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11586
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1129411587 {
1129511588 //gl.glDepthFunc(GL.GL_LEQUAL);
1129611589 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11298,24 +11591,21 @@
1129811591
1129911592 boolean texon = textureon;
1130011593
11301
- if (RENDERPROGRAM > 0)
11302
- {
11303
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11304
- textureon = false;
11305
- }
11594
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11595
+ textureon = false;
11596
+
1130611597 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1130711598 //System.out.println("ALLO");
1130811599 gl.glColorMask(false, false, false, false);
1130911600 DrawObject(gl);
11310
- if (RENDERPROGRAM > 0)
11311
- {
11312
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11313
- textureon = texon;
11314
- }
11601
+
11602
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11603
+ textureon = texon;
11604
+
1131511605 gl.glColorMask(true, true, true, true);
1131611606
1131711607 gl.glDepthFunc(GL.GL_EQUAL);
11318
- //gl.glDepthMask(false);
11608
+ gl.glDepthMask(false);
1131911609 }
1132011610
1132111611 if (false) // DrawMode() == SHADOW)
....@@ -11655,20 +11945,32 @@
1165511945 ReleaseTextures(DEFAULT_TEXTURES);
1165611946
1165711947 if (CLEANCACHE)
11658
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11948
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1165911949 {
11660
- String tex = e.nextElement();
11950
+ cTexture tex = e.nextElement();
1166111951
1166211952 // System.out.println("Texture --------- " + tex);
1166311953
11664
- if (tex.equals("WHITE_NOISE"))
11954
+ if (tex.equals("WHITE_NOISE:"))
1166511955 continue;
1166611956
11667
- if (!usedtextures.containsKey(tex))
11957
+ if (!usedtextures.contains(tex))
1166811958 {
11959
+ CacheTexture gettex = texturepigment.get(tex);
1166911960 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11670
- textures.get(tex).texture.dispose();
11671
- textures.remove(tex);
11961
+ if (gettex != null)
11962
+ {
11963
+ gettex.texture.dispose();
11964
+ texturepigment.remove(tex);
11965
+ }
11966
+
11967
+ gettex = texturebump.get(tex);
11968
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11969
+ if (gettex != null)
11970
+ {
11971
+ gettex.texture.dispose();
11972
+ texturebump.remove(tex);
11973
+ }
1167211974 }
1167311975 }
1167411976 }
....@@ -12196,8 +12498,76 @@
1219612498
1219712499 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1219812500
12199
- String program =
12501
+ String programmin =
12502
+ // Min shader
1220012503 "!!ARBfp1.0\n" +
12504
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12505
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12506
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12507
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12508
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12509
+ "PARAM light2cam0 = program.env[10];" +
12510
+ "PARAM light2cam1 = program.env[11];" +
12511
+ "PARAM light2cam2 = program.env[12];" +
12512
+ "TEMP temp;" +
12513
+ "TEMP light;" +
12514
+ "TEMP ndotl;" +
12515
+ "TEMP normal;" +
12516
+ "TEMP depth;" +
12517
+ "TEMP eye;" +
12518
+ "TEMP pos;" +
12519
+
12520
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12521
+ Normalize("normal") +
12522
+ "MOV light, state.light[0].position;" +
12523
+ "DP3 ndotl.x, light, normal;" +
12524
+
12525
+ // shadow
12526
+ "MOV pos, fragment.texcoord[1];" +
12527
+ "MOV temp, pos;" +
12528
+ ShadowTextureFetch("depth", "temp", "1") +
12529
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12530
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12531
+
12532
+ // No shadow when out of frustum
12533
+ //"SGE temp.y, depth.z, zero123.y;" +
12534
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12535
+
12536
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12537
+
12538
+ // Backlit
12539
+ "MOV pos.w, zero123.y;" +
12540
+ "DP4 eye.x, pos, light2cam0;" +
12541
+ "DP4 eye.y, pos, light2cam1;" +
12542
+ "DP4 eye.z, pos, light2cam2;" +
12543
+ Normalize("eye") +
12544
+
12545
+ "DP3 ndotl.y, -eye, normal;" +
12546
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12547
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12548
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12549
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12550
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12551
+
12552
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12553
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12554
+
12555
+ // Pigment
12556
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12557
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12558
+ "MUL temp, temp, ndotl.x;" +
12559
+
12560
+ "MUL temp, temp, zero123.z;" +
12561
+
12562
+ //"MUL temp, temp, ndotl.y;" +
12563
+
12564
+ "MOV temp.w, zero123.y;" + // reset alpha
12565
+ "MOV result.color, temp;" +
12566
+ "END";
12567
+
12568
+ String programmax =
12569
+ "!!ARBfp1.0\n" +
12570
+
1220112571 //"OPTION ARB_fragment_program_shadow;" +
1220212572 "PARAM light2cam0 = program.env[10];" +
1220312573 "PARAM light2cam1 = program.env[11];" +
....@@ -12312,8 +12682,7 @@
1231212682 "TEMP shininess;" +
1231312683 "\n" +
1231412684 "MOV texSamp, one;" +
12315
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12316
-
12685
+
1231712686 "MOV mapgrid.x, one2048th.x;" +
1231812687 "MOV temp, fragment.texcoord[1];" +
1231912688 /*
....@@ -12334,20 +12703,20 @@
1233412703 "MUL temp, floor, mapgrid.x;" +
1233512704 //"TEX depth0, temp, texture[1], 2D;" +
1233612705 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12337
- TextureFetch("depth0", "temp", "1") +
12706
+ ShadowTextureFetch("depth0", "temp", "1") +
1233812707 "") +
1233912708 "ADD temp.x, temp.x, mapgrid.x;" +
1234012709 //"TEX depth1, temp, texture[1], 2D;" +
1234112710 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12342
- TextureFetch("depth1", "temp", "1") +
12711
+ ShadowTextureFetch("depth1", "temp", "1") +
1234312712 "") +
1234412713 "ADD temp.y, temp.y, mapgrid.x;" +
1234512714 //"TEX depth2, temp, texture[1], 2D;" +
12346
- TextureFetch("depth2", "temp", "1") +
12715
+ ShadowTextureFetch("depth2", "temp", "1") +
1234712716 "SUB temp.x, temp.x, mapgrid.x;" +
1234812717 //"TEX depth3, temp, texture[1], 2D;" +
1234912718 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12350
- TextureFetch("depth3", "temp", "1") +
12719
+ ShadowTextureFetch("depth3", "temp", "1") +
1235112720 "") +
1235212721 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1235312722 //"MOV params, material;" +
....@@ -12718,10 +13087,10 @@
1271813087 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1271913088 "") +
1272013089
12721
- // display shadow only (bump == 0)
13090
+ // display shadow only (fakedepth == 0)
1272213091 "SUB temp.x, half.x, shadow.x;" +
1272313092 "MOV temp.y, -params5.z;" + // params6.x;" +
12724
- "SLT temp.z, temp.y, -one2048th.x;" +
13093
+ "SLT temp.z, temp.y, -c256i.x;" +
1272513094 "SUB temp.y, one.x, temp.z;" +
1272613095 "MUL temp.x, temp.x, temp.y;" +
1272713096 "KIL temp.x;" +
....@@ -13052,8 +13421,19 @@
1305213421 //once = true;
1305313422 }
1305413423
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 " : ""));
13424
+ String program = programmax;
13425
+
13426
+ if (Globals.MINSHADER)
13427
+ {
13428
+ program = programmin;
13429
+ }
13430
+
13431
+ if (Globals.DEBUG)
13432
+ {
13433
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13434
+ System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13435
+ }
13436
+
1305713437 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1305813438
1305913439 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -13100,7 +13480,8 @@
1310013480 "\n" +
1310113481 "END\n";
1310213482
13103
- System.out.println("Program shadow #" + 0 + "; length = " + program.length());
13483
+ if (Globals.DEBUG)
13484
+ System.out.println("Program shadow #" + 0 + "; length = " + program.length());
1310413485 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1310513486
1310613487 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -13145,25 +13526,26 @@
1314513526 return out;
1314613527 }
1314713528
13148
- String TextureFetch(String dest, String src, String unit)
13529
+ // Also does frustum culling
13530
+ String ShadowTextureFetch(String dest, String src, String unit)
1314913531 {
1315013532 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1315113533 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1315213534 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13535
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13536
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1315313537 "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;" +
13538
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13539
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1315813540 //"SWZ buffer, temp, w,w,w,w;";
13159
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13541
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1316013542 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1316113543 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1316213544 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13163
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13545
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1316413546
13165
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13166
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13547
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13548
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1316713549 }
1316813550
1316913551 String Shadow(String depth, String shadow)
....@@ -13210,7 +13592,7 @@
1321013592 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1321113593 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1321213594
13213
- // No shadow when out of frustrum
13595
+ // No shadow when out of frustum
1321413596 "SGE temp.x, " + depth + ".z, one.z;" +
1321513597 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1321613598 "";
....@@ -14008,14 +14390,15 @@
1400814390 drag = false;
1400914391 //System.out.println("Mouse DOWN");
1401014392 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);
14393
+ //ClickInfo info = new ClickInfo();
14394
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14395
+ object.clickInfo.pane = this;
14396
+ object.clickInfo.camera = renderCamera;
14397
+ object.clickInfo.x = x;
14398
+ object.clickInfo.y = y;
14399
+ object.clickInfo.modifiers = modifiersex;
14400
+ editObj = object.doEditClick(//info,
14401
+ 0);
1401914402 if (!editObj)
1402014403 {
1402114404 hasMarquee = true;
....@@ -14297,11 +14680,17 @@
1429714680 void GoDown(int mod)
1429814681 {
1429914682 MODIFIERS |= COMMAND;
14683
+ boolean isVR = (mouseMode&VR)!=0;
1430014684 /**/
1430114685 if((mod&SHIFT) == SHIFT)
14302
- manipCamera.RotatePosition(0, -speed);
14686
+ {
14687
+ if (isVR)
14688
+ manipCamera.RotateInterest(0, -speed);
14689
+ else
14690
+ manipCamera.RotatePosition(0, -speed);
14691
+ }
1430314692 else
14304
- manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14693
+ manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth());
1430514694 /**/
1430614695 if ((mod & SHIFT) == SHIFT)
1430714696 {
....@@ -14311,6 +14700,8 @@
1431114700 mouseMode |= BACKFORTH;
1431214701 }
1431314702
14703
+ targetLookAt.set(manipCamera.lookAt);
14704
+
1431414705 //prevX = X = anchorX;
1431514706 prevY = Y = anchorY - (int) (renderCamera.Distance());
1431614707 }
....@@ -14319,10 +14710,17 @@
1431914710 {
1432014711 MODIFIERS |= COMMAND;
1432114712 /**/
14713
+ boolean isVR = (mouseMode&VR)!=0;
14714
+
1432214715 if((mod&SHIFT) == SHIFT)
14323
- manipCamera.RotatePosition(0, speed);
14716
+ {
14717
+ if (isVR)
14718
+ manipCamera.RotateInterest(0, speed);
14719
+ else
14720
+ manipCamera.RotatePosition(0, speed);
14721
+ }
1432414722 else
14325
- manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14723
+ manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth());
1432614724 /**/
1432714725 if ((mod & SHIFT) == SHIFT)
1432814726 {
....@@ -14332,6 +14730,8 @@
1433214730 mouseMode |= BACKFORTH;
1433314731 }
1433414732
14733
+ targetLookAt.set(manipCamera.lookAt);
14734
+
1433514735 //prevX = X = anchorX;
1433614736 prevY = Y = anchorY + (int) (renderCamera.Distance());
1433714737 }
....@@ -14341,9 +14741,14 @@
1434114741 MODIFIERS |= COMMAND;
1434214742 /**/
1434314743 if((mod&SHIFT) == SHIFT)
14344
- manipCamera.Translate(speed*delta, 0, getWidth());
14744
+ manipCamera.Translate(speed*delta, 0, getWidth());
1434514745 else
14346
- manipCamera.RotatePosition(speed, 0);
14746
+ {
14747
+ if ((mouseMode&VR)!=0)
14748
+ manipCamera.RotateInterest(-speed, 0);
14749
+ else
14750
+ manipCamera.RotatePosition(speed, 0);
14751
+ }
1434714752 /**/
1434814753 if ((mod & SHIFT) == SHIFT)
1434914754 {
....@@ -14353,6 +14758,8 @@
1435314758 mouseMode |= ROTATE;
1435414759 } // TRANSLATE;
1435514760
14761
+ targetLookAt.set(manipCamera.lookAt);
14762
+
1435614763 prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance());
1435714764 prevY = Y = anchorY;
1435814765 }
....@@ -14362,9 +14769,15 @@
1436214769 MODIFIERS |= COMMAND;
1436314770 /**/
1436414771 if((mod&SHIFT) == SHIFT)
14365
- manipCamera.Translate(-speed*delta, 0, getWidth());
14772
+ manipCamera.Translate(-speed*delta, 0, getWidth());
1436614773 else
14367
- manipCamera.RotatePosition(-speed, 0);
14774
+ {
14775
+ if ((mouseMode&VR)!=0)
14776
+ manipCamera.RotateInterest(speed, 0);
14777
+ else
14778
+ manipCamera.RotatePosition(-speed, 0);
14779
+ }
14780
+
1436814781 /**/
1436914782 if ((mod & SHIFT) == SHIFT)
1437014783 {
....@@ -14374,6 +14787,8 @@
1437414787 mouseMode |= ROTATE;
1437514788 } // TRANSLATE;
1437614789
14790
+ targetLookAt.set(manipCamera.lookAt);
14791
+
1437714792 prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance());
1437814793 prevY = Y = anchorY;
1437914794 }
....@@ -14415,15 +14830,16 @@
1441514830 if (editObj)
1441614831 {
1441714832 drag = true;
14418
- ClickInfo info = new ClickInfo();
14419
- info.bounds.setBounds(0, 0,
14833
+ //ClickInfo info = new ClickInfo();
14834
+ object.clickInfo.bounds.setBounds(0, 0,
1442014835 (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);
14836
+ object.clickInfo.pane = this;
14837
+ object.clickInfo.camera = renderCamera;
14838
+ object.clickInfo.x = x;
14839
+ object.clickInfo.y = y;
14840
+ object //.GetWindow().copy
14841
+ .doEditDrag(//info,
14842
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1442714843 } else
1442814844 {
1442914845 if (x < startX)
....@@ -14572,24 +14988,27 @@
1457214988 }
1457314989 }
1457414990
14991
+// ClickInfo clickInfo = new ClickInfo();
14992
+
1457514993 public void mouseMoved(MouseEvent e)
1457614994 {
1457714995 //System.out.println("mouseMoved: " + e);
1457814996 if (isRenderer)
1457914997 return;
1458014998
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;
14999
+ // Mouse cursor feedback
15000
+ object.clickInfo.x = e.getX();
15001
+ object.clickInfo.y = e.getY();
15002
+ object.clickInfo.modifiers = e.getModifiersEx();
15003
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
15004
+ object.clickInfo.pane = this;
15005
+ object.clickInfo.camera = renderCamera;
1458815006 if (!isRenderer)
1458915007 {
1459015008 //ObjEditor editWindow = object.editWindow;
1459115009 //Object3D copy = editWindow.copy;
14592
- if (object.doEditClick(ci, 0))
15010
+ if (object.doEditClick(//clickInfo,
15011
+ 0))
1459315012 {
1459415013 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1459515014 } else
....@@ -14861,7 +15280,8 @@
1486115280 // break;
1486215281 case 'T':
1486315282 CACHETEXTURE ^= true;
14864
- textures.clear();
15283
+ texturepigment.clear();
15284
+ texturebump.clear();
1486515285 // repaint();
1486615286 break;
1486715287 case 'Y':
....@@ -14871,8 +15291,8 @@
1487115291 case 'K':
1487215292 KOMPACTTEXTURE ^= true;
1487315293 //textures.clear();
14874
- break;
14875
- case 'P': // Texture Projection macros
15294
+ // break;
15295
+ //case 'P': // Texture Projection macros
1487615296 // SAVETEXTURE ^= true;
1487715297 macromode = true;
1487815298 Udebug = Vdebug = NORMALdebug = false; programInitialized = false;
....@@ -14993,7 +15413,7 @@
1499315413 targetLookAt.set(manipCamera.lookAt);
1499415414 repaint();
1499515415 break;
14996
- case 'p':
15416
+ case 'P': // p':
1499715417 // c'est quoi ca au juste? spherical ^= true;
1499815418 Skinshader ^= true; programInitialized = false;
1499915419 repaint();
....@@ -15038,20 +15458,24 @@
1503815458 OCCLUSION_CULLING ^= true;
1503915459 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1504015460 break;
15041
- case '0': envyoff ^= true; repaint(); break;
15461
+ //case '0': envyoff ^= true; repaint(); break;
1504215462 case '1':
1504315463 case '2':
1504415464 case '3':
1504515465 case '4':
1504615466 case '5':
15047
- newenvy = Character.getNumericValue(key);
15048
- repaint();
15049
- break;
1505015467 case '6':
1505115468 case '7':
1505215469 case '8':
1505315470 case '9':
15054
- BGcolor = (key - '6')/3.f;
15471
+ if (true) // envyoff)
15472
+ {
15473
+ BGcolor = (key - '1')/8.f;
15474
+ }
15475
+ else
15476
+ {
15477
+ //newenvy = Character.getNumericValue(key);
15478
+ }
1505515479 repaint();
1505615480 break;
1505715481 case '!':
....@@ -15614,8 +16038,6 @@
1561416038
1561516039 int width = getBounds().width;
1561616040 int height = getBounds().height;
15617
- ClickInfo info = new ClickInfo();
15618
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1561916041 //Image img = CreateImage(width, height);
1562016042 //System.out.println("width = " + width + "; height = " + height + "\n");
1562116043
....@@ -15692,31 +16114,37 @@
1569216114 }
1569316115 if (object != null && !hasMarquee)
1569416116 {
16117
+ if (object.clickInfo == null)
16118
+ object.clickInfo = new ClickInfo();
16119
+ ClickInfo info = object.clickInfo;
16120
+ //ClickInfo info = new ClickInfo();
16121
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16122
+
1569516123 if (isRenderer)
1569616124 {
15697
- info.flags++;
16125
+ object.clickInfo.flags++;
1569816126 double frameAspect = (double) width / (double) height;
1569916127 if (frameAspect > renderCamera.aspect)
1570016128 {
1570116129 int desired = (int) ((double) height * renderCamera.aspect);
15702
- info.bounds.width -= width - desired;
15703
- info.bounds.x += (width - desired) / 2;
16130
+ object.clickInfo.bounds.width -= width - desired;
16131
+ object.clickInfo.bounds.x += (width - desired) / 2;
1570416132 } else
1570516133 {
1570616134 int desired = (int) ((double) width / renderCamera.aspect);
15707
- info.bounds.height -= height - desired;
15708
- info.bounds.y += (height - desired) / 2;
16135
+ object.clickInfo.bounds.height -= height - desired;
16136
+ object.clickInfo.bounds.y += (height - desired) / 2;
1570916137 }
1571016138 }
1571116139
15712
- info.g = gr;
15713
- info.camera = renderCamera;
16140
+ object.clickInfo.g = gr;
16141
+ object.clickInfo.camera = renderCamera;
1571416142 /*
1571516143 // Memory intensive (brep.verticescopy)
1571616144 if (!(object instanceof Composite))
1571716145 object.draw(info, 0, false); // SLOW :
1571816146 */
15719
- if (!isRenderer)
16147
+ if (!isRenderer) // && drag)
1572016148 {
1572116149 Grafreed.Assert(object != null);
1572216150 Grafreed.Assert(object.selection != null);
....@@ -15724,9 +16152,9 @@
1572416152 {
1572516153 int hitSomething = object.selection.get(0).hitSomething;
1572616154
15727
- info.DX = 0;
15728
- info.DY = 0;
15729
- info.W = 1;
16155
+ object.clickInfo.DX = 0;
16156
+ object.clickInfo.DY = 0;
16157
+ object.clickInfo.W = 1;
1573016158 if (hitSomething == Object3D.hitCenter)
1573116159 {
1573216160 info.DX = X;
....@@ -15738,13 +16166,14 @@
1573816166 info.DY -= info.bounds.height/2;
1573916167 }
1574016168
15741
- object.drawEditHandles(info, 0);
16169
+ object.drawEditHandles(//info,
16170
+ 0);
1574216171
1574316172 if (drag && (X != 0 || Y != 0))
1574416173 {
1574516174 switch (hitSomething)
1574616175 {
15747
- case Object3D.hitCenter: gr.setColor(Color.pink);
16176
+ case Object3D.hitCenter: gr.setColor(Color.white);
1574816177 gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
1574916178 break;
1575016179 case Object3D.hitRotate: gr.setColor(Color.yellow);
....@@ -15770,7 +16199,7 @@
1577016199 if (hasMarquee)
1577116200 {
1577216201 gr.setXORMode(Color.white);
15773
- gr.setColor(Color.red);
16202
+ gr.setColor(Color.white);
1577416203 if (!firstime)
1577516204 {
1577616205 gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH);
....@@ -16237,6 +16666,8 @@
1623716666 private /*static*/ boolean firstime;
1623816667 private /*static*/ cVector newView = new cVector();
1623916668 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16669
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16670
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1624016671 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1624116672 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1624216673 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16249,29 +16680,67 @@
1624916680 {
1625016681 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1625116682
16683
+ int usedsuf = 0;
16684
+
1625216685 for (int i = 0; i < suffixes.length; i++)
1625316686 {
16254
- String resourceName = basename + suffixes[i] + "." + suffix;
16255
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16256
- mipmapped,
16257
- FileUtil.getFileSuffix(resourceName));
16258
- if (data == null)
16687
+ String[] suffixe = suffixes;
16688
+ String[] fallback = suffixes2;
16689
+ String[] fallfallback = suffixes3;
16690
+
16691
+ for (int c=usedsuf; --c>=0;)
1625916692 {
16260
- throw new IOException("Unable to load texture " + resourceName);
16693
+// String[] temp = suffixe;
16694
+// suffixe = fallback;
16695
+// fallback = fallfallback;
16696
+// fallfallback = temp;
1626116697 }
16698
+
16699
+ String resourceName = basename + suffixe[i] + "." + suffix;
16700
+ TextureData data;
16701
+
16702
+ try
16703
+ {
16704
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16705
+ mipmapped,
16706
+ FileUtil.getFileSuffix(resourceName));
16707
+ }
16708
+ catch (Exception e)
16709
+ {
16710
+ try
16711
+ {
16712
+ resourceName = basename + fallback[i] + "." + suffix;
16713
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16714
+ mipmapped,
16715
+ FileUtil.getFileSuffix(resourceName));
16716
+ }
16717
+ catch (Exception e2)
16718
+ {
16719
+ resourceName = basename + fallfallback[i] + "." + suffix;
16720
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16721
+ mipmapped,
16722
+ FileUtil.getFileSuffix(resourceName));
16723
+ }
16724
+ }
16725
+
1626216726 //System.out.println("Target = " + targets[i]);
1626316727 cubemap.updateImage(data, targets[i]);
1626416728 }
1626516729
1626616730 return cubemap;
1626716731 }
16732
+
1626816733 int bigsphere = -1;
1626916734
1627016735 float BGcolor = 0.5f;
1627116736
16272
- private void DrawSkyBox(GL gl)
16737
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16738
+
16739
+ private void DrawSkyBox(GL gl, float ratio)
1627316740 {
16274
- if (envyoff || cubemap == null)
16741
+ if (//envyoff ||
16742
+ WIREFRAME ||
16743
+ cubemap == null)
1627516744 {
1627616745 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1627716746 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16286,7 +16755,17 @@
1628616755 // Compensates for ExaminerViewer's modification of modelview matrix
1628716756 gl.glMatrixMode(GL.GL_MODELVIEW);
1628816757 gl.glLoadIdentity();
16758
+ gl.glScalef(1,ratio,1);
1628916759
16760
+// colorV[0] = 2;
16761
+// colorV[1] = 2;
16762
+// colorV[2] = 2;
16763
+// colorV[3] = 1;
16764
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16765
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16766
+//
16767
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16768
+
1629016769 //gl.glActiveTexture(GL.GL_TEXTURE1);
1629116770 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1629216771
....@@ -16318,6 +16797,7 @@
1631816797 {
1631916798 gl.glScalef(1.0f, -1.0f, 1.0f);
1632016799 }
16800
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1632116801 gl.glMultMatrixd(viewrot_1, 0);
1632216802 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1632316803 //viewer.updateInverseRotation(gl);
....@@ -16358,7 +16838,8 @@
1635816838 gl.glDisable(GL.GL_TEXTURE_GEN_R);
1635916839
1636016840 cubemap.disable();
16361
- ////cubemap.unbind();
16841
+ //cubemap.dispose();
16842
+
1636216843 if (CULLFACE)
1636316844 {
1636416845 gl.glEnable(gl.GL_CULL_FACE);
....@@ -16553,6 +17034,14 @@
1655317034 }
1655417035 }
1655517036
17037
+ private Object3D GetFolder()
17038
+ {
17039
+ Object3D folder = object.GetWindow().copy;
17040
+ if (object.GetWindow().copy.selection.Size() > 0)
17041
+ folder = object.GetWindow().copy.selection.elementAt(0);
17042
+ return folder;
17043
+ }
17044
+
1655617045 class SelectBuffer implements GLEventListener
1655717046 {
1655817047
....@@ -16568,7 +17057,7 @@
1656817057 //new Exception().printStackTrace();
1656917058 System.out.println("select buffer init");
1657017059 // Use debug pipeline
16571
- drawable.setGL(new DebugGL(drawable.getGL()));
17060
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1657217061
1657317062 GL gl = drawable.getGL();
1657417063
....@@ -16632,6 +17121,17 @@
1663217121
1663317122 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1663417123
17124
+ if (PAINTMODE)
17125
+ {
17126
+ if (object.GetWindow().copy.selection.Size() > 0)
17127
+ {
17128
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17129
+
17130
+ // Make what you paint not selectable.
17131
+ paintobj.ResetSelectable();
17132
+ }
17133
+ }
17134
+
1663517135 //int tmp = selection_view;
1663617136 //selection_view = -1;
1663717137 int temp = DrawMode();
....@@ -16643,6 +17143,17 @@
1664317143 // temp = DEFAULT; // patch for selection debug
1664417144 Globals.drawMode = temp; // WARNING
1664517145
17146
+ if (PAINTMODE)
17147
+ {
17148
+ if (object.GetWindow().copy.selection.Size() > 0)
17149
+ {
17150
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17151
+
17152
+ // Revert.
17153
+ paintobj.RestoreSelectable();
17154
+ }
17155
+ }
17156
+
1664617157 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1664717158
1664817159 // trying different ways of getting the depth info over
....@@ -16748,27 +17259,29 @@
1674817259 if (!movingcamera && !PAINTMODE)
1674917260 object.GetWindow().ScreenFitPoint(); // fev 2014
1675017261
16751
- if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17262
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1675217263 {
16753
- Object3D paintobj = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
16754
-
16755
- Object3D group = new Object3D("inst" + paintcount++);
16756
-
16757
- group.CreateMaterial(); // use a void leaf to select instances
16758
-
16759
- group.add(paintobj); // link
16760
-
16761
- object.GetWindow().SnapObject(group);
16762
-
16763
- Object3D folder = object.GetWindow().copy;
17264
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1676417265
1676517266 if (object.GetWindow().copy.selection.Size() > 0)
16766
- folder = object.GetWindow().copy.selection.elementAt(0);
17267
+ {
17268
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1676717269
16768
- folder.add(group);
16769
-
16770
- object.GetWindow().ResetModel();
16771
- object.GetWindow().refreshContents();
17270
+ Object3D inst = new Object3D("inst" + paintcount++);
17271
+
17272
+ inst.CreateMaterial(); // use a void leaf to select instances
17273
+
17274
+ inst.add(paintobj); // link
17275
+
17276
+ object.GetWindow().SnapObject(inst);
17277
+
17278
+ Object3D folder = paintFolder; // GetFolder();
17279
+
17280
+ folder.add(inst);
17281
+
17282
+ object.GetWindow().ResetModel();
17283
+ object.GetWindow().refreshContents();
17284
+ }
1677217285 }
1677317286 else
1677417287 paintcount = 0;
....@@ -16862,6 +17375,7 @@
1686217375
1686317376 public void init(GLAutoDrawable drawable)
1686417377 {
17378
+ if (Globals.DEBUG)
1686517379 System.out.println("shadow buffer init");
1686617380
1686717381 GL gl = drawable.getGL();
....@@ -17090,10 +17604,14 @@
1709017604 gl.glFlush();
1709117605
1709217606 /**/
17093
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17607
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1709417608
17095
- float[] pixels = occlusionsizebuffer.array();
17609
+ float[] depths = occlusiondepthbuffer.array();
1709617610
17611
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17612
+
17613
+ int[] pixels = selectsizebuffer.array();
17614
+
1709717615 double r = 0, g = 0, b = 0;
1709817616
1709917617 double count = 0;
....@@ -17104,7 +17622,7 @@
1710417622
1710517623 double FACTOR = 1;
1710617624
17107
- for (int i = 0; i < pixels.length; i++)
17625
+ for (int i = 0; i < depths.length; i++)
1710817626 {
1710917627 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1711017628 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -17187,7 +17705,7 @@
1718717705
1718817706 double scale = ray.z; // 1; // cos
1718917707
17190
- float depth = pixels[newindex];
17708
+ float depth = depths[newindex];
1719117709
1719217710 /*
1719317711 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -17384,11 +17902,14 @@
1738417902 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1738517903 static IntBuffer bigAAbuffer;
1738617904 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
17387
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17905
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1738817906 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1738917907 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1739017908 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17391
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17909
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17910
+
17911
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17912
+
1739217913 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1739317914 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1739417915 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();