Normand Briere
2019-08-13 0cdf3fb57ddea3226f094ba45c836c7e9b123e3a
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;
....@@ -136,7 +173,7 @@
136173 static boolean doublesided = false; // true; // reversed normals are awful for conformance
137174 boolean anisotropy = true;
138175 boolean softshadow = true; // slower but better false;
139
- boolean opacityhalo = false;
176
+ boolean opacityhalo = false; // reverse the halo effect (e.g. glass)
140177
141178 boolean macromode = false;
142179
....@@ -150,6 +187,18 @@
150187 }
151188
152189 private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
190
+
191
+ public void LoadSkybox(String name, String ext, boolean mipmap) throws GLException
192
+ {
193
+ try
194
+ {
195
+ cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
196
+ } catch (IOException e)
197
+ {
198
+ System.out.println("NAME = " + name);
199
+ e.printStackTrace(); // throw new RuntimeException(e);
200
+ }
201
+ }
153202
154203 void SetAsGLRenderer(boolean b)
155204 {
....@@ -169,7 +218,8 @@
169218
170219 SetCamera(cam);
171220
172
- SetLight(new Camera(new cVector(10, 10, -20)));
221
+ // Warning: not used.
222
+ SetLight(new Camera(new cVector(15, 10, -20)));
173223
174224 object = o;
175225
....@@ -1447,6 +1497,8 @@
14471497 gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
14481498 }
14491499
1500
+ float[] colorV = new float[4];
1501
+
14501502 void SetColor(Object3D obj, Vertex p0)
14511503 {
14521504 CameraPane display = this;
....@@ -1514,8 +1566,6 @@
15141566 {
15151567 return;
15161568 }
1517
-
1518
- float[] colorV = new float[3];
15191569
15201570 if (false) // marked)
15211571 {
....@@ -2298,10 +2348,17 @@
22982348 HANDLES ^= true;
22992349 }
23002350
2351
+ Object3D paintFolder;
2352
+
23012353 void TogglePaint()
23022354 {
23032355 PAINTMODE ^= true;
23042356 paintcount = 0;
2357
+
2358
+ if (PAINTMODE)
2359
+ {
2360
+ paintFolder = GetFolder();
2361
+ }
23052362 }
23062363
23072364 void SwapCamera(int a, int b)
....@@ -2398,6 +2455,21 @@
23982455 return currentGL;
23992456 }
24002457
2458
+ static private BufferedImage CreateBim(TextureData texturedata)
2459
+ {
2460
+ Grafreed.Assert(texturedata != null);
2461
+
2462
+ int width = texturedata.getWidth();
2463
+ int height = texturedata.getHeight();
2464
+
2465
+ Buffer buffer = texturedata.getBuffer();
2466
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2467
+
2468
+ byte[] bytes = bytebuf.array();
2469
+
2470
+ return CreateBim(bytes, width, height);
2471
+ }
2472
+
24012473 /**/
24022474 class CacheTexture
24032475 {
....@@ -2406,28 +2478,31 @@
24062478
24072479 int resolution;
24082480
2409
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2481
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
24102482 {
2411
- texture = tex;
2483
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2484
+ texturedata = texdata;
24122485 resolution = res;
24132486 }
24142487 }
24152488 /**/
24162489
24172490 // 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>();
2491
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2492
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2493
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2494
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2495
+
24212496 int pigmentdepth = 0;
24222497 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
24232498 int bumpdepth = 0;
24242499 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
24252500 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
24262501 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2427
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2502
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
24282503 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
24292504
2430
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2505
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
24312506 {
24322507 TextureData texturedata = null;
24332508
....@@ -2446,13 +2521,34 @@
24462521 if (bump)
24472522 texturedata = ConvertBump(texturedata, false);
24482523
2449
- com.sun.opengl.util.texture.Texture texture =
2450
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2524
+// com.sun.opengl.util.texture.Texture texture =
2525
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
24512526
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);
2527
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2528
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
24542529
2455
- return texture;
2530
+ return texturedata;
2531
+ }
2532
+
2533
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2534
+ {
2535
+ TextureData texturedata = null;
2536
+
2537
+ try
2538
+ {
2539
+ texturedata =
2540
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2541
+ bim,
2542
+ true);
2543
+ } catch (Exception e)
2544
+ {
2545
+ throw new javax.media.opengl.GLException(e);
2546
+ }
2547
+
2548
+ if (bump)
2549
+ texturedata = ConvertBump(texturedata, false);
2550
+
2551
+ return texturedata;
24562552 }
24572553
24582554 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3525,6 +3621,8 @@
35253621
35263622 System.out.println("LOADING TEXTURE : " + name);
35273623
3624
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3625
+
35283626 //
35293627 if (false) // compressbit > 0)
35303628 {
....@@ -7923,7 +8021,7 @@
79238021 String pigment = Object3D.GetPigment(tex);
79248022 String bump = Object3D.GetBump(tex);
79258023
7926
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8024
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79278025 {
79288026 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79298027 // System.out.println("; bump = " + bump);
....@@ -7938,8 +8036,8 @@
79388036 pigment = null;
79398037 }
79408038
7941
- ReleaseTexture(bump, true);
7942
- ReleaseTexture(pigment, false);
8039
+ ReleaseTexture(tex, true);
8040
+ ReleaseTexture(tex, false);
79438041 }
79448042
79458043 public void ReleasePigmentTexture(cTexture tex) // INTERFACE
....@@ -7957,7 +8055,7 @@
79578055
79588056 String pigment = Object3D.GetPigment(tex);
79598057
7960
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8058
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79618059 {
79628060 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79638061 // System.out.println("; bump = " + bump);
....@@ -7968,7 +8066,7 @@
79688066 pigment = null;
79698067 }
79708068
7971
- ReleaseTexture(pigment, false);
8069
+ ReleaseTexture(tex, false);
79728070 }
79738071
79748072 public void ReleaseBumpTexture(cTexture tex) // INTERFACE
....@@ -7986,7 +8084,7 @@
79868084
79878085 String bump = Object3D.GetBump(tex);
79888086
7989
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8087
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79908088 {
79918089 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79928090 // System.out.println("; bump = " + bump);
....@@ -7997,10 +8095,10 @@
79978095 bump = null;
79988096 }
79998097
8000
- ReleaseTexture(bump, true);
8098
+ ReleaseTexture(tex, true);
80018099 }
80028100
8003
- void ReleaseTexture(String tex, boolean bump)
8101
+ void ReleaseTexture(cTexture tex, boolean bump)
80048102 {
80058103 if (// DrawMode() != 0 || /*tex == null ||*/
80068104 ambientOcclusion ) // || !textureon)
....@@ -8011,7 +8109,7 @@
80118109 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
80128110
80138111 if (tex != null)
8014
- texture = textures.get(tex);
8112
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
80158113
80168114 // //assert( texture != null );
80178115 // if (texture == null)
....@@ -8105,47 +8203,50 @@
81058203
81068204 /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
81078205 {
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
- }
8206
+// if (// DrawMode() != 0 || /*tex == null ||*/
8207
+// ambientOcclusion ) // || !textureon)
8208
+// {
8209
+// return; // false;
8210
+// }
8211
+//
8212
+// if (tex == null)
8213
+// {
8214
+// BindTexture(null,false,resolution);
8215
+// BindTexture(null,true,resolution);
8216
+// return;
8217
+// }
8218
+//
8219
+// String pigment = Object3D.GetPigment(tex);
8220
+// String bump = Object3D.GetBump(tex);
8221
+//
8222
+// usedtextures.add(pigment);
8223
+// usedtextures.add(bump);
8224
+//
8225
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8226
+// {
8227
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8228
+// // System.out.println("; bump = " + bump);
8229
+// }
8230
+//
8231
+// if (bump.equals(""))
8232
+// {
8233
+// bump = null;
8234
+// }
8235
+// if (pigment.equals(""))
8236
+// {
8237
+// pigment = null;
8238
+// }
8239
+//
8240
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8241
+// BindTexture(pigment, false, resolution);
8242
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8243
+// BindTexture(bump, true, resolution);
8244
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8245
+//
8246
+// return; // true;
81208247
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;
8248
+ BindPigmentTexture(tex, resolution);
8249
+ BindBumpTexture(tex, resolution);
81498250 }
81508251
81518252 /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8164,9 +8265,9 @@
81648265
81658266 String pigment = Object3D.GetPigment(tex);
81668267
8167
- usedtextures.put(pigment, pigment);
8268
+ usedtextures.add(tex);
81688269
8169
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8270
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
81708271 {
81718272 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
81728273 // System.out.println("; bump = " + bump);
....@@ -8178,7 +8279,7 @@
81788279 }
81798280
81808281 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8181
- BindTexture(pigment, false, resolution);
8282
+ BindTexture(tex, false, resolution);
81828283 }
81838284
81848285 /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8197,9 +8298,9 @@
81978298
81988299 String bump = Object3D.GetBump(tex);
81998300
8200
- usedtextures.put(bump, bump);
8301
+ usedtextures.add(tex);
82018302
8202
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8303
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
82038304 {
82048305 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
82058306 // System.out.println("; bump = " + bump);
....@@ -8211,7 +8312,7 @@
82118312 }
82128313
82138314 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8214
- BindTexture(bump, true, resolution);
8315
+ BindTexture(tex, true, resolution);
82158316 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
82168317 }
82178318
....@@ -8235,13 +8336,19 @@
82358336 return fileExists;
82368337 }
82378338
8238
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception
8339
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
82398340 {
8240
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8341
+ CacheTexture texturecache = null;
82418342
82428343 if (tex != null)
82438344 {
8244
- String texname = tex;
8345
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8346
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
8347
+
8348
+ if (texname.equals("") && texdata == null)
8349
+ {
8350
+ return null;
8351
+ }
82458352
82468353 String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
82478354
....@@ -8251,19 +8358,46 @@
82518358 // else
82528359 // if (!texname.startsWith("/"))
82538360 // texname = "/Users/nbriere/Textures/" + texname;
8254
- if (!FileExists(tex))
8361
+ if (!FileExists(texname) && !texname.startsWith("@"))
82558362 {
82568363 texname = fallbackTextureName;
82578364 }
82588365
82598366 if (CACHETEXTURE)
8260
- texture = textures.get(texname); // TEXTURE CACHE
8261
-
8262
- TextureData texturedata = null;
8263
-
8264
- if (texture == null || texture.resolution < resolution)
82658367 {
8266
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8368
+ if (texdata == null)
8369
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8370
+ else
8371
+ texturecache = bimtextures.get(texdata);
8372
+ }
8373
+
8374
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8375
+ {
8376
+ TextureData texturedata = null;
8377
+
8378
+ if (texdata != null && textureon)
8379
+ {
8380
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8381
+
8382
+ try
8383
+ {
8384
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8385
+ }
8386
+ catch (Exception e)
8387
+ {
8388
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8389
+ }
8390
+
8391
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8392
+ bimtextures.put(texdata, texturecache);
8393
+
8394
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8395
+
8396
+ //Object bim2 = CreateBim(texturecache.texturedata);
8397
+ //bim2 = bim;
8398
+ }
8399
+ else
8400
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
82678401 {
82688402 assert(!bump);
82698403 // if (bump)
....@@ -8274,19 +8408,23 @@
82748408 // }
82758409 // else
82768410 // {
8277
- texture = textures.get(tex);
8278
- if (texture == null)
8411
+ // texturecache = textures.get(texname); // suspicious
8412
+ if (texturecache == null)
82798413 {
8280
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8414
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
82818415 }
8416
+ else
8417
+ new Exception().printStackTrace();
82828418 // }
82838419 } else
8284
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8420
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
82858421 {
82868422 assert(bump);
8287
- texture = textures.get(tex);
8288
- if (texture == null)
8289
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8423
+ // texturecache = textures.get(texname); // suspicious
8424
+ if (texturecache == null)
8425
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8426
+ else
8427
+ new Exception().printStackTrace();
82908428 } else
82918429 {
82928430 //if (tex.equals("IMMORTAL"))
....@@ -8294,11 +8432,22 @@
82948432 // texture = GetResourceTexture("default.png");
82958433 //} else
82968434 //{
8297
- if (tex.equals("WHITE_NOISE"))
8435
+ if (texname.endsWith("WHITE_NOISE"))
82988436 {
8299
- texture = textures.get(tex);
8300
- if (texture == null)
8301
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8437
+ // texturecache = textures.get(texname); // suspicious
8438
+ if (texturecache == null)
8439
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8440
+ else
8441
+ new Exception().printStackTrace();
8442
+ } else
8443
+ {
8444
+ if (texname.startsWith("@"))
8445
+ {
8446
+ // texturecache = textures.get(texname); // suspicious
8447
+ if (texturecache == null)
8448
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8449
+ else
8450
+ new Exception().printStackTrace();
83028451 } else
83038452 {
83048453 if (textureon)
....@@ -8357,19 +8506,20 @@
83578506 if (texturedata == null)
83588507 throw new Exception();
83598508
8360
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8509
+ texturecache = new CacheTexture(texturedata,resolution);
83618510 //texture = GetTexture(tex, bump);
83628511 }
8512
+ }
83638513 }
83648514 //}
83658515 }
83668516
8367
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8517
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
83688518 {
83698519 //return false;
83708520
83718521 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8372
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8522
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
83738523 {
83748524 // String ext = "_highres";
83758525 // if (REDUCETEXTURE)
....@@ -8386,52 +8536,17 @@
83868536 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
83878537 if (!cachefile.exists())
83888538 {
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))
8539
+ //if (texturedata.getWidth() == texturedata.getHeight())
83988540 {
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);
8541
+ BufferedImage rendImage = CreateBim(texturedata);
8542
+
84298543 ImageWriter writer = null;
84308544 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
84318545 if (iter.hasNext()) {
84328546 writer = (ImageWriter)iter.next();
84338547 }
8434
- float compressionQuality = 0.9f;
8548
+
8549
+ float compressionQuality = 0.85f;
84358550 try
84368551 {
84378552 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8448,18 +8563,20 @@
84488563 }
84498564 }
84508565 }
8451
-
8566
+
8567
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8568
+
84528569 //System.out.println("Texture = " + tex);
8453
- if (textures.containsKey(texname))
8570
+ if (textures.containsKey(tex))
84548571 {
8455
- CacheTexture thetex = textures.get(texname);
8572
+ CacheTexture thetex = textures.get(tex);
84568573 thetex.texture.disable();
84578574 thetex.texture.dispose();
8458
- textures.remove(texname);
8575
+ textures.remove(tex);
84598576 }
84608577
8461
- texture.texturedata = texturedata;
8462
- textures.put(texname, texture);
8578
+ //texture.texturedata = texturedata;
8579
+ textures.put(tex, texturecache);
84638580
84648581 // newtex = true;
84658582 }
....@@ -8475,10 +8592,44 @@
84758592 }
84768593 }
84778594
8478
- return texture;
8595
+ return texturecache;
84798596 }
84808597
8481
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution) throws Exception
8598
+ static void EmbedTextures(cTexture tex)
8599
+ {
8600
+ if (tex.pigmentdata == null)
8601
+ {
8602
+ //String texname = Object3D.GetPigment(tex);
8603
+
8604
+ CacheTexture texturecache = texturepigment.get(tex);
8605
+
8606
+ if (texturecache != null)
8607
+ {
8608
+ tex.pw = texturecache.texturedata.getWidth();
8609
+ tex.ph = texturecache.texturedata.getHeight();
8610
+ tex.pigmentdata = //CompressJPEG(CreateBim
8611
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8612
+ ;
8613
+ //, tex.pw, tex.ph), 0.5f);
8614
+ }
8615
+ }
8616
+
8617
+ if (tex.bumpdata == null)
8618
+ {
8619
+ //String texname = Object3D.GetBump(tex);
8620
+
8621
+ CacheTexture texturecache = texturebump.get(tex);
8622
+
8623
+ if (texturecache != null)
8624
+ {
8625
+ tex.bw = texturecache.texturedata.getWidth();
8626
+ tex.bh = texturecache.texturedata.getHeight();
8627
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8628
+ }
8629
+ }
8630
+ }
8631
+
8632
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
84828633 {
84838634 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
84848635
....@@ -8496,21 +8647,21 @@
84968647 return texture!=null?texture.texture:null;
84978648 }
84988649
8499
- public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution) throws Exception
8650
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
85008651 {
85018652 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
85028653
85038654 return texture!=null?texture.texturedata:null;
85048655 }
85058656
8506
- boolean BindTexture(String tex, boolean bump, int resolution) throws Exception
8657
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
85078658 {
85088659 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
85098660 {
85108661 return false;
85118662 }
85128663
8513
- boolean newtex = false;
8664
+ //boolean newtex = false;
85148665
85158666 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
85168667
....@@ -8542,9 +8693,75 @@
85428693 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
85438694 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
85448695
8545
- return newtex;
8696
+ return true; // Warning: not used.
85468697 }
85478698
8699
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8700
+ {
8701
+ try
8702
+ {
8703
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8704
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8705
+ ImageWriter writer = writers.next();
8706
+
8707
+ ImageWriteParam param = writer.getDefaultWriteParam();
8708
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8709
+ param.setCompressionQuality(quality);
8710
+
8711
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8712
+ writer.setOutput(ios);
8713
+ writer.write(null, new IIOImage(image, null, null), param);
8714
+
8715
+ byte[] data = baos.toByteArray();
8716
+ writer.dispose();
8717
+ return data;
8718
+ }
8719
+ catch (Exception e)
8720
+ {
8721
+ e.printStackTrace();
8722
+ return null;
8723
+ }
8724
+ }
8725
+
8726
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8727
+ {
8728
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8729
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8730
+ ImageReader reader = writers.next();
8731
+
8732
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8733
+
8734
+ ImageReadParam param = reader.getDefaultReadParam();
8735
+ param.setDestination(bim);
8736
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8737
+
8738
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8739
+ reader.setInput(ios);
8740
+ BufferedImage bim2 = reader.read(0, param);
8741
+ reader.dispose();
8742
+
8743
+// WritableRaster raster = bim2.getRaster();
8744
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8745
+// byte[] bytes = data.getData();
8746
+//
8747
+// int[] pixels = new int[bytes.length/3];
8748
+// for (int i=pixels.length; --i>=0;)
8749
+// {
8750
+// int i3 = i*3;
8751
+// pixels[i] = 0xFF;
8752
+// pixels[i] <<= 8;
8753
+// pixels[i] |= bytes[i3+2] & 0xFF;
8754
+// pixels[i] <<= 8;
8755
+// pixels[i] |= bytes[i3+1] & 0xFF;
8756
+// pixels[i] <<= 8;
8757
+// pixels[i] |= bytes[i3] & 0xFF;
8758
+// }
8759
+//
8760
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8761
+
8762
+ return bim;
8763
+ }
8764
+
85488765 ShadowBuffer shadowPBuf;
85498766 AntialiasBuffer antialiasPBuf;
85508767 int MAXSTACK;
....@@ -8561,10 +8778,12 @@
85618778
85628779 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
85638780 MAXSTACK = temp[0];
8564
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8781
+ if (Globals.DEBUG)
8782
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
85658783 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
85668784 MAXSTACK = temp[0];
8567
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8785
+ if (Globals.DEBUG)
8786
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
85688787
85698788 // Use debug pipeline
85708789 //drawable.setGL(new DebugGL(gl)); //
....@@ -8572,7 +8791,8 @@
85728791 gl = drawable.getGL(); //
85738792
85748793 GL gl3 = getGL();
8575
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8794
+ if (Globals.DEBUG)
8795
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
85768796
85778797
85788798 //float pos[] = { 100, 100, 100, 0 };
....@@ -8737,7 +8957,7 @@
87378957
87388958 if (cubemap == null)
87398959 {
8740
- LoadEnvy(5);
8960
+ //LoadEnvy(1);
87418961 }
87428962
87438963 //cubemap.enable();
....@@ -9024,37 +9244,58 @@
90249244 cubemap = null;
90259245 return;
90269246 case 1:
9027
- name = "cubemaps/box_";
9028
- ext = "png";
9247
+ name = "cubemaps/rgb/";
9248
+ ext = "jpg";
90299249 reverseUP = false;
90309250 break;
90319251 case 2:
9032
- name = "cubemaps/uffizi_";
9033
- ext = "png";
9034
- break; // reverseUP = true; break;
9252
+ name = "cubemaps/uffizi/";
9253
+ ext = "jpg";
9254
+ reverseUP = false;
9255
+ break;
90359256 case 3:
9036
- name = "cubemaps/CloudyHills_";
9037
- ext = "tga";
9257
+ name = "cubemaps/CloudyHills/";
9258
+ ext = "jpg";
90389259 reverseUP = false;
90399260 break;
90409261 case 4:
9041
- name = "cubemaps/cornell_";
9262
+ name = "cubemaps/cornell/";
90429263 ext = "png";
90439264 reverseUP = false;
90449265 break;
9266
+ case 5:
9267
+ name = "cubemaps/skycube/";
9268
+ ext = "jpg";
9269
+ reverseUP = false;
9270
+ break;
9271
+ case 6:
9272
+ name = "cubemaps/SaintLazarusChurch3/";
9273
+ ext = "jpg";
9274
+ reverseUP = false;
9275
+ break;
9276
+ case 7:
9277
+ name = "cubemaps/Sodermalmsallen/";
9278
+ ext = "jpg";
9279
+ reverseUP = false;
9280
+ break;
9281
+ case 8:
9282
+ name = "cubemaps/Sodermalmsallen2/";
9283
+ ext = "jpg";
9284
+ reverseUP = false;
9285
+ break;
9286
+ case 9:
9287
+ name = "cubemaps/UnionSquare/";
9288
+ ext = "jpg";
9289
+ reverseUP = false;
9290
+ break;
90459291 default:
9046
- name = "cubemaps/rgb_";
9047
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9292
+ name = "cubemaps/box/";
9293
+ ext = "png"; /*mipmap = true;*/
9294
+ reverseUP = false;
90489295 break;
90499296 }
9050
-
9051
- try
9052
- {
9053
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
9054
- } catch (IOException e)
9055
- {
9056
- throw new RuntimeException(e);
9057
- }
9297
+
9298
+ LoadSkybox(name, ext, mipmap);
90589299 }
90599300
90609301 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -9086,8 +9327,12 @@
90869327 static double[] model = new double[16];
90879328 double[] camera2light = new double[16];
90889329 double[] light2camera = new double[16];
9089
- int newenvy = -1;
9090
- boolean envyoff = true; // false;
9330
+
9331
+ //int newenvy = -1;
9332
+ //boolean envyoff = false;
9333
+
9334
+ String loadedskyboxname;
9335
+
90919336 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
90929337 //float[] light0 = { 0,0,0 };
90939338 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9505,7 +9750,7 @@
95059750
95069751 if (renderCamera != lightCamera)
95079752 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9508
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
9753
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
95099754
95109755 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
95119756
....@@ -9521,7 +9766,7 @@
95219766
95229767 if (renderCamera != lightCamera)
95239768 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9524
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
9769
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
95259770
95269771 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
95279772
....@@ -9567,10 +9812,12 @@
95679812 rati = 1 / rati;
95689813 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
95699814 }
9570
- assert (newenvy == -1);
9815
+
9816
+ //assert (newenvy == -1);
9817
+
95719818 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
95729819 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9573
- DrawSkyBox(gl);
9820
+ DrawSkyBox(gl, (float)rati);
95749821 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
95759822 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
95769823 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10607,7 +10854,7 @@
1060710854
1060810855 if (wait)
1060910856 {
10610
- Sleep(500);
10857
+ Sleep(200); // blocks everything
1061110858
1061210859 wait = false;
1061310860 }
....@@ -10722,7 +10969,7 @@
1072210969 // if (parentcam != renderCamera) // not a light
1072310970 if (cam != lightCamera)
1072410971 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10725
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
10972
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1072610973
1072710974 for (int j = 0; j < 4; j++)
1072810975 {
....@@ -10737,7 +10984,7 @@
1073710984 // if (parentcam != renderCamera) // not a light
1073810985 if (cam != lightCamera)
1073910986 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10740
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
10987
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1074110988
1074210989 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1074310990
....@@ -10823,13 +11070,27 @@
1082311070 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1082411071 }
1082511072
10826
- if (newenvy > -1)
11073
+// if (newenvy > -1)
11074
+// {
11075
+// LoadEnvy(newenvy);
11076
+// }
11077
+//
11078
+// newenvy = -1;
11079
+
11080
+ if (object.skyboxname != null)
1082711081 {
10828
- LoadEnvy(newenvy);
11082
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11083
+ {
11084
+ LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11085
+ loadedskyboxname = object.skyboxname;
11086
+ }
1082911087 }
10830
-
10831
- newenvy = -1;
10832
-
11088
+ else
11089
+ {
11090
+ cubemap = null;
11091
+ loadedskyboxname = null;
11092
+ }
11093
+
1083311094 ratio = ((double) getWidth()) / getHeight();
1083411095 //System.out.println("ratio = " + ratio);
1083511096
....@@ -10845,7 +11106,7 @@
1084511106
1084611107 if (!IsFrozen() && !ambientOcclusion)
1084711108 {
10848
- DrawSkyBox(gl);
11109
+ DrawSkyBox(gl, (float)ratio);
1084911110 }
1085011111
1085111112 //if (selection_view == -1)
....@@ -11028,9 +11289,9 @@
1102811289
1102911290 gl.glMatrixMode(GL.GL_MODELVIEW);
1103011291
11031
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11032
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
11033
-//gl.glEnable(gl.GL_MULTISAMPLE);
11292
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11293
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11294
+gl.glEnable(gl.GL_MULTISAMPLE);
1103411295 } else
1103511296 {
1103611297 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -11041,7 +11302,7 @@
1104111302 //System.out.println("BLENDING ON");
1104211303 gl.glEnable(GL.GL_BLEND);
1104311304 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
11044
-
11305
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1104511306 gl.glMatrixMode(gl.GL_PROJECTION);
1104611307 gl.glLoadIdentity();
1104711308
....@@ -11131,7 +11392,7 @@
1113111392
1113211393 // if (cam != lightCamera)
1113311394 //for (int count = parentcam.GetTransformCount(); --count>=0;)
11134
- LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
11395
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1113511396 }
1113611397
1113711398 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -11290,7 +11551,7 @@
1129011551 }
1129111552 }
1129211553
11293
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11554
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1129411555 {
1129511556 //gl.glDepthFunc(GL.GL_LEQUAL);
1129611557 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11298,24 +11559,21 @@
1129811559
1129911560 boolean texon = textureon;
1130011561
11301
- if (RENDERPROGRAM > 0)
11302
- {
11303
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11304
- textureon = false;
11305
- }
11562
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11563
+ textureon = false;
11564
+
1130611565 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1130711566 //System.out.println("ALLO");
1130811567 gl.glColorMask(false, false, false, false);
1130911568 DrawObject(gl);
11310
- if (RENDERPROGRAM > 0)
11311
- {
11312
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11313
- textureon = texon;
11314
- }
11569
+
11570
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11571
+ textureon = texon;
11572
+
1131511573 gl.glColorMask(true, true, true, true);
1131611574
1131711575 gl.glDepthFunc(GL.GL_EQUAL);
11318
- //gl.glDepthMask(false);
11576
+ gl.glDepthMask(false);
1131911577 }
1132011578
1132111579 if (false) // DrawMode() == SHADOW)
....@@ -11655,20 +11913,32 @@
1165511913 ReleaseTextures(DEFAULT_TEXTURES);
1165611914
1165711915 if (CLEANCACHE)
11658
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11916
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1165911917 {
11660
- String tex = e.nextElement();
11918
+ cTexture tex = e.nextElement();
1166111919
1166211920 // System.out.println("Texture --------- " + tex);
1166311921
11664
- if (tex.equals("WHITE_NOISE"))
11922
+ if (tex.equals("WHITE_NOISE:"))
1166511923 continue;
1166611924
11667
- if (!usedtextures.containsKey(tex))
11925
+ if (!usedtextures.contains(tex))
1166811926 {
11927
+ CacheTexture gettex = texturepigment.get(tex);
1166911928 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11670
- textures.get(tex).texture.dispose();
11671
- textures.remove(tex);
11929
+ if (gettex != null)
11930
+ {
11931
+ gettex.texture.dispose();
11932
+ texturepigment.remove(tex);
11933
+ }
11934
+
11935
+ gettex = texturebump.get(tex);
11936
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11937
+ if (gettex != null)
11938
+ {
11939
+ gettex.texture.dispose();
11940
+ texturebump.remove(tex);
11941
+ }
1167211942 }
1167311943 }
1167411944 }
....@@ -12196,8 +12466,76 @@
1219612466
1219712467 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1219812468
12199
- String program =
12469
+ String programmin =
12470
+ // Min shader
1220012471 "!!ARBfp1.0\n" +
12472
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12473
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12474
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12475
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12476
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12477
+ "PARAM light2cam0 = program.env[10];" +
12478
+ "PARAM light2cam1 = program.env[11];" +
12479
+ "PARAM light2cam2 = program.env[12];" +
12480
+ "TEMP temp;" +
12481
+ "TEMP light;" +
12482
+ "TEMP ndotl;" +
12483
+ "TEMP normal;" +
12484
+ "TEMP depth;" +
12485
+ "TEMP eye;" +
12486
+ "TEMP pos;" +
12487
+
12488
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12489
+ Normalize("normal") +
12490
+ "MOV light, state.light[0].position;" +
12491
+ "DP3 ndotl.x, light, normal;" +
12492
+
12493
+ // shadow
12494
+ "MOV pos, fragment.texcoord[1];" +
12495
+ "MOV temp, pos;" +
12496
+ ShadowTextureFetch("depth", "temp", "1") +
12497
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12498
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12499
+
12500
+ // No shadow when out of frustum
12501
+ //"SGE temp.y, depth.z, zero123.y;" +
12502
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12503
+
12504
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12505
+
12506
+ // Backlit
12507
+ "MOV pos.w, zero123.y;" +
12508
+ "DP4 eye.x, pos, light2cam0;" +
12509
+ "DP4 eye.y, pos, light2cam1;" +
12510
+ "DP4 eye.z, pos, light2cam2;" +
12511
+ Normalize("eye") +
12512
+
12513
+ "DP3 ndotl.y, -eye, normal;" +
12514
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12515
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12516
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12517
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12518
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12519
+
12520
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12521
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12522
+
12523
+ // Pigment
12524
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12525
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12526
+ "MUL temp, temp, ndotl.x;" +
12527
+
12528
+ "MUL temp, temp, zero123.z;" +
12529
+
12530
+ //"MUL temp, temp, ndotl.y;" +
12531
+
12532
+ "MOV temp.w, zero123.y;" + // reset alpha
12533
+ "MOV result.color, temp;" +
12534
+ "END";
12535
+
12536
+ String programmax =
12537
+ "!!ARBfp1.0\n" +
12538
+
1220112539 //"OPTION ARB_fragment_program_shadow;" +
1220212540 "PARAM light2cam0 = program.env[10];" +
1220312541 "PARAM light2cam1 = program.env[11];" +
....@@ -12312,8 +12650,7 @@
1231212650 "TEMP shininess;" +
1231312651 "\n" +
1231412652 "MOV texSamp, one;" +
12315
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12316
-
12653
+
1231712654 "MOV mapgrid.x, one2048th.x;" +
1231812655 "MOV temp, fragment.texcoord[1];" +
1231912656 /*
....@@ -12334,20 +12671,20 @@
1233412671 "MUL temp, floor, mapgrid.x;" +
1233512672 //"TEX depth0, temp, texture[1], 2D;" +
1233612673 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12337
- TextureFetch("depth0", "temp", "1") +
12674
+ ShadowTextureFetch("depth0", "temp", "1") +
1233812675 "") +
1233912676 "ADD temp.x, temp.x, mapgrid.x;" +
1234012677 //"TEX depth1, temp, texture[1], 2D;" +
1234112678 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12342
- TextureFetch("depth1", "temp", "1") +
12679
+ ShadowTextureFetch("depth1", "temp", "1") +
1234312680 "") +
1234412681 "ADD temp.y, temp.y, mapgrid.x;" +
1234512682 //"TEX depth2, temp, texture[1], 2D;" +
12346
- TextureFetch("depth2", "temp", "1") +
12683
+ ShadowTextureFetch("depth2", "temp", "1") +
1234712684 "SUB temp.x, temp.x, mapgrid.x;" +
1234812685 //"TEX depth3, temp, texture[1], 2D;" +
1234912686 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12350
- TextureFetch("depth3", "temp", "1") +
12687
+ ShadowTextureFetch("depth3", "temp", "1") +
1235112688 "") +
1235212689 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1235312690 //"MOV params, material;" +
....@@ -12718,10 +13055,10 @@
1271813055 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1271913056 "") +
1272013057
12721
- // display shadow only (bump == 0)
13058
+ // display shadow only (fakedepth == 0)
1272213059 "SUB temp.x, half.x, shadow.x;" +
1272313060 "MOV temp.y, -params5.z;" + // params6.x;" +
12724
- "SLT temp.z, temp.y, -one2048th.x;" +
13061
+ "SLT temp.z, temp.y, -c256i.x;" +
1272513062 "SUB temp.y, one.x, temp.z;" +
1272613063 "MUL temp.x, temp.x, temp.y;" +
1272713064 "KIL temp.x;" +
....@@ -13052,6 +13389,13 @@
1305213389 //once = true;
1305313390 }
1305413391
13392
+ String program = programmax;
13393
+
13394
+ if (Globals.MINSHADER)
13395
+ {
13396
+ program = programmin;
13397
+ }
13398
+
1305513399 System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1305613400 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1305713401 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
....@@ -13145,25 +13489,26 @@
1314513489 return out;
1314613490 }
1314713491
13148
- String TextureFetch(String dest, String src, String unit)
13492
+ // Also does frustum culling
13493
+ String ShadowTextureFetch(String dest, String src, String unit)
1314913494 {
1315013495 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1315113496 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1315213497 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13498
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13499
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1315313500 "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;" +
13501
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13502
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1315813503 //"SWZ buffer, temp, w,w,w,w;";
13159
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13504
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1316013505 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1316113506 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1316213507 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13163
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13508
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1316413509
13165
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13166
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13510
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13511
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1316713512 }
1316813513
1316913514 String Shadow(String depth, String shadow)
....@@ -13210,7 +13555,7 @@
1321013555 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1321113556 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1321213557
13213
- // No shadow when out of frustrum
13558
+ // No shadow when out of frustum
1321413559 "SGE temp.x, " + depth + ".z, one.z;" +
1321513560 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1321613561 "";
....@@ -14008,14 +14353,15 @@
1400814353 drag = false;
1400914354 //System.out.println("Mouse DOWN");
1401014355 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);
14356
+ //ClickInfo info = new ClickInfo();
14357
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14358
+ object.clickInfo.pane = this;
14359
+ object.clickInfo.camera = renderCamera;
14360
+ object.clickInfo.x = x;
14361
+ object.clickInfo.y = y;
14362
+ object.clickInfo.modifiers = modifiersex;
14363
+ editObj = object.doEditClick(//info,
14364
+ 0);
1401914365 if (!editObj)
1402014366 {
1402114367 hasMarquee = true;
....@@ -14297,12 +14643,12 @@
1429714643 void GoDown(int mod)
1429814644 {
1429914645 MODIFIERS |= COMMAND;
14300
- /*
14646
+ /**/
1430114647 if((mod&SHIFT) == SHIFT)
14302
- manipCamera.RotatePosition(0, -speed);
14648
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
1430314649 else
14304
- manipCamera.BackForth(0, -speed*delta, getWidth());
14305
- */
14650
+ manipCamera.RotatePosition(0, -speed);
14651
+ /**/
1430614652 if ((mod & SHIFT) == SHIFT)
1430714653 {
1430814654 mouseMode = mouseMode; // VR??
....@@ -14318,12 +14664,12 @@
1431814664 void GoUp(int mod)
1431914665 {
1432014666 MODIFIERS |= COMMAND;
14321
- /*
14667
+ /**/
1432214668 if((mod&SHIFT) == SHIFT)
14323
- manipCamera.RotatePosition(0, speed);
14669
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
1432414670 else
14325
- manipCamera.BackForth(0, speed*delta, getWidth());
14326
- */
14671
+ manipCamera.RotatePosition(0, speed);
14672
+ /**/
1432714673 if ((mod & SHIFT) == SHIFT)
1432814674 {
1432914675 mouseMode = mouseMode;
....@@ -14339,12 +14685,12 @@
1433914685 void GoLeft(int mod)
1434014686 {
1434114687 MODIFIERS |= COMMAND;
14342
- /*
14688
+ /**/
1434314689 if((mod&SHIFT) == SHIFT)
14344
- manipCamera.RotatePosition(speed, 0);
14345
- else
1434614690 manipCamera.Translate(speed*delta, 0, getWidth());
14347
- */
14691
+ else
14692
+ manipCamera.RotatePosition(speed, 0);
14693
+ /**/
1434814694 if ((mod & SHIFT) == SHIFT)
1434914695 {
1435014696 mouseMode = mouseMode;
....@@ -14360,12 +14706,12 @@
1436014706 void GoRight(int mod)
1436114707 {
1436214708 MODIFIERS |= COMMAND;
14363
- /*
14709
+ /**/
1436414710 if((mod&SHIFT) == SHIFT)
14365
- manipCamera.RotatePosition(-speed, 0);
14366
- else
1436714711 manipCamera.Translate(-speed*delta, 0, getWidth());
14368
- */
14712
+ else
14713
+ manipCamera.RotatePosition(-speed, 0);
14714
+ /**/
1436914715 if ((mod & SHIFT) == SHIFT)
1437014716 {
1437114717 mouseMode = mouseMode;
....@@ -14415,15 +14761,16 @@
1441514761 if (editObj)
1441614762 {
1441714763 drag = true;
14418
- ClickInfo info = new ClickInfo();
14419
- info.bounds.setBounds(0, 0,
14764
+ //ClickInfo info = new ClickInfo();
14765
+ object.clickInfo.bounds.setBounds(0, 0,
1442014766 (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);
14767
+ object.clickInfo.pane = this;
14768
+ object.clickInfo.camera = renderCamera;
14769
+ object.clickInfo.x = x;
14770
+ object.clickInfo.y = y;
14771
+ object //.GetWindow().copy
14772
+ .doEditDrag(//info,
14773
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1442714774 } else
1442814775 {
1442914776 if (x < startX)
....@@ -14572,24 +14919,27 @@
1457214919 }
1457314920 }
1457414921
14922
+// ClickInfo clickInfo = new ClickInfo();
14923
+
1457514924 public void mouseMoved(MouseEvent e)
1457614925 {
1457714926 //System.out.println("mouseMoved: " + e);
1457814927 if (isRenderer)
1457914928 return;
1458014929
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;
14930
+ // Mouse cursor feedback
14931
+ object.clickInfo.x = e.getX();
14932
+ object.clickInfo.y = e.getY();
14933
+ object.clickInfo.modifiers = e.getModifiersEx();
14934
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14935
+ object.clickInfo.pane = this;
14936
+ object.clickInfo.camera = renderCamera;
1458814937 if (!isRenderer)
1458914938 {
1459014939 //ObjEditor editWindow = object.editWindow;
1459114940 //Object3D copy = editWindow.copy;
14592
- if (object.doEditClick(ci, 0))
14941
+ if (object.doEditClick(//clickInfo,
14942
+ 0))
1459314943 {
1459414944 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1459514945 } else
....@@ -14861,7 +15211,8 @@
1486115211 // break;
1486215212 case 'T':
1486315213 CACHETEXTURE ^= true;
14864
- textures.clear();
15214
+ texturepigment.clear();
15215
+ texturebump.clear();
1486515216 // repaint();
1486615217 break;
1486715218 case 'Y':
....@@ -14946,7 +15297,9 @@
1494615297 case 'E' : COMPACT ^= true;
1494715298 repaint();
1494815299 break;
14949
- case 'W' : DEBUGHSB ^= true;
15300
+ case 'W' : // Wide Window (fullscreen)
15301
+ //DEBUGHSB ^= true;
15302
+ ObjEditor.theFrame.ToggleFullScreen();
1495015303 repaint();
1495115304 break;
1495215305 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14972,13 +15325,7 @@
1497215325 repaint();
1497315326 break;
1497415327 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':
15328
+ //case 'L':
1498215329 if (lightMode)
1498315330 {
1498415331 lightMode = false;
....@@ -15042,20 +15389,24 @@
1504215389 OCCLUSION_CULLING ^= true;
1504315390 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1504415391 break;
15045
- case '0': envyoff ^= true; repaint(); break;
15392
+ //case '0': envyoff ^= true; repaint(); break;
1504615393 case '1':
1504715394 case '2':
1504815395 case '3':
1504915396 case '4':
1505015397 case '5':
15051
- newenvy = Character.getNumericValue(key);
15052
- repaint();
15053
- break;
1505415398 case '6':
1505515399 case '7':
1505615400 case '8':
1505715401 case '9':
15058
- BGcolor = (key - '6')/3.f;
15402
+ if (true) // envyoff)
15403
+ {
15404
+ BGcolor = (key - '1')/8.f;
15405
+ }
15406
+ else
15407
+ {
15408
+ //newenvy = Character.getNumericValue(key);
15409
+ }
1505915410 repaint();
1506015411 break;
1506115412 case '!':
....@@ -15125,7 +15476,10 @@
1512515476 // kompactbit = 6;
1512615477 // break;
1512715478 case ' ':
15128
- ObjEditor.theFrame.ToggleFullScreen();
15479
+ lightMode ^= true;
15480
+ Globals.lighttouched = true;
15481
+ manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
15482
+ targetLookAt.set(manipCamera.lookAt);
1512915483 repaint();
1513015484 break;
1513115485 //case '`' :
....@@ -15615,8 +15969,6 @@
1561515969
1561615970 int width = getBounds().width;
1561715971 int height = getBounds().height;
15618
- ClickInfo info = new ClickInfo();
15619
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1562015972 //Image img = CreateImage(width, height);
1562115973 //System.out.println("width = " + width + "; height = " + height + "\n");
1562215974
....@@ -15693,38 +16045,47 @@
1569316045 }
1569416046 if (object != null && !hasMarquee)
1569516047 {
16048
+ if (object.clickInfo == null)
16049
+ object.clickInfo = new ClickInfo();
16050
+ ClickInfo info = object.clickInfo;
16051
+ //ClickInfo info = new ClickInfo();
16052
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16053
+
1569616054 if (isRenderer)
1569716055 {
15698
- info.flags++;
16056
+ object.clickInfo.flags++;
1569916057 double frameAspect = (double) width / (double) height;
1570016058 if (frameAspect > renderCamera.aspect)
1570116059 {
1570216060 int desired = (int) ((double) height * renderCamera.aspect);
15703
- info.bounds.width -= width - desired;
15704
- info.bounds.x += (width - desired) / 2;
16061
+ object.clickInfo.bounds.width -= width - desired;
16062
+ object.clickInfo.bounds.x += (width - desired) / 2;
1570516063 } else
1570616064 {
1570716065 int desired = (int) ((double) width / renderCamera.aspect);
15708
- info.bounds.height -= height - desired;
15709
- info.bounds.y += (height - desired) / 2;
16066
+ object.clickInfo.bounds.height -= height - desired;
16067
+ object.clickInfo.bounds.y += (height - desired) / 2;
1571016068 }
1571116069 }
15712
- info.g = gr;
15713
- info.camera = renderCamera;
16070
+
16071
+ object.clickInfo.g = gr;
16072
+ object.clickInfo.camera = renderCamera;
1571416073 /*
1571516074 // Memory intensive (brep.verticescopy)
1571616075 if (!(object instanceof Composite))
1571716076 object.draw(info, 0, false); // SLOW :
1571816077 */
15719
- if (!isRenderer)
16078
+ if (!isRenderer) // && drag)
1572016079 {
16080
+ Grafreed.Assert(object != null);
16081
+ Grafreed.Assert(object.selection != null);
1572116082 if (object.selection.Size() > 0)
1572216083 {
1572316084 int hitSomething = object.selection.get(0).hitSomething;
1572416085
15725
- info.DX = 0;
15726
- info.DY = 0;
15727
- info.W = 1;
16086
+ object.clickInfo.DX = 0;
16087
+ object.clickInfo.DY = 0;
16088
+ object.clickInfo.W = 1;
1572816089 if (hitSomething == Object3D.hitCenter)
1572916090 {
1573016091 info.DX = X;
....@@ -15736,7 +16097,8 @@
1573616097 info.DY -= info.bounds.height/2;
1573716098 }
1573816099
15739
- object.drawEditHandles(info, 0);
16100
+ object.drawEditHandles(//info,
16101
+ 0);
1574016102
1574116103 if (drag && (X != 0 || Y != 0))
1574216104 {
....@@ -16235,6 +16597,8 @@
1623516597 private /*static*/ boolean firstime;
1623616598 private /*static*/ cVector newView = new cVector();
1623716599 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16600
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16601
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1623816602 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1623916603 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1624016604 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16247,29 +16611,67 @@
1624716611 {
1624816612 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1624916613
16614
+ int usedsuf = 0;
16615
+
1625016616 for (int i = 0; i < suffixes.length; i++)
1625116617 {
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)
16618
+ String[] suffixe = suffixes;
16619
+ String[] fallback = suffixes2;
16620
+ String[] fallfallback = suffixes3;
16621
+
16622
+ for (int c=usedsuf; --c>=0;)
1625716623 {
16258
- throw new IOException("Unable to load texture " + resourceName);
16624
+// String[] temp = suffixe;
16625
+// suffixe = fallback;
16626
+// fallback = fallfallback;
16627
+// fallfallback = temp;
1625916628 }
16629
+
16630
+ String resourceName = basename + suffixe[i] + "." + suffix;
16631
+ TextureData data;
16632
+
16633
+ try
16634
+ {
16635
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16636
+ mipmapped,
16637
+ FileUtil.getFileSuffix(resourceName));
16638
+ }
16639
+ catch (Exception e)
16640
+ {
16641
+ try
16642
+ {
16643
+ resourceName = basename + fallback[i] + "." + suffix;
16644
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16645
+ mipmapped,
16646
+ FileUtil.getFileSuffix(resourceName));
16647
+ }
16648
+ catch (Exception e2)
16649
+ {
16650
+ resourceName = basename + fallfallback[i] + "." + suffix;
16651
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16652
+ mipmapped,
16653
+ FileUtil.getFileSuffix(resourceName));
16654
+ }
16655
+ }
16656
+
1626016657 //System.out.println("Target = " + targets[i]);
1626116658 cubemap.updateImage(data, targets[i]);
1626216659 }
1626316660
1626416661 return cubemap;
1626516662 }
16663
+
1626616664 int bigsphere = -1;
1626716665
1626816666 float BGcolor = 0.5f;
1626916667
16270
- private void DrawSkyBox(GL gl)
16668
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16669
+
16670
+ private void DrawSkyBox(GL gl, float ratio)
1627116671 {
16272
- if (envyoff || cubemap == null)
16672
+ if (//envyoff ||
16673
+ WIREFRAME ||
16674
+ cubemap == null)
1627316675 {
1627416676 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1627516677 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16284,7 +16686,17 @@
1628416686 // Compensates for ExaminerViewer's modification of modelview matrix
1628516687 gl.glMatrixMode(GL.GL_MODELVIEW);
1628616688 gl.glLoadIdentity();
16689
+ gl.glScalef(1,ratio,1);
1628716690
16691
+// colorV[0] = 2;
16692
+// colorV[1] = 2;
16693
+// colorV[2] = 2;
16694
+// colorV[3] = 1;
16695
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16696
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16697
+//
16698
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16699
+
1628816700 //gl.glActiveTexture(GL.GL_TEXTURE1);
1628916701 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1629016702
....@@ -16316,6 +16728,7 @@
1631616728 {
1631716729 gl.glScalef(1.0f, -1.0f, 1.0f);
1631816730 }
16731
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1631916732 gl.glMultMatrixd(viewrot_1, 0);
1632016733 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1632116734 //viewer.updateInverseRotation(gl);
....@@ -16551,6 +16964,14 @@
1655116964 }
1655216965 }
1655316966
16967
+ private Object3D GetFolder()
16968
+ {
16969
+ Object3D folder = object.GetWindow().copy;
16970
+ if (object.GetWindow().copy.selection.Size() > 0)
16971
+ folder = object.GetWindow().copy.selection.elementAt(0);
16972
+ return folder;
16973
+ }
16974
+
1655416975 class SelectBuffer implements GLEventListener
1655516976 {
1655616977
....@@ -16566,7 +16987,7 @@
1656616987 //new Exception().printStackTrace();
1656716988 System.out.println("select buffer init");
1656816989 // Use debug pipeline
16569
- drawable.setGL(new DebugGL(drawable.getGL()));
16990
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1657016991
1657116992 GL gl = drawable.getGL();
1657216993
....@@ -16630,6 +17051,17 @@
1663017051
1663117052 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1663217053
17054
+ if (PAINTMODE)
17055
+ {
17056
+ if (object.GetWindow().copy.selection.Size() > 0)
17057
+ {
17058
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17059
+
17060
+ // Make what you paint not selectable.
17061
+ paintobj.ResetSelectable();
17062
+ }
17063
+ }
17064
+
1663317065 //int tmp = selection_view;
1663417066 //selection_view = -1;
1663517067 int temp = DrawMode();
....@@ -16641,6 +17073,17 @@
1664117073 // temp = DEFAULT; // patch for selection debug
1664217074 Globals.drawMode = temp; // WARNING
1664317075
17076
+ if (PAINTMODE)
17077
+ {
17078
+ if (object.GetWindow().copy.selection.Size() > 0)
17079
+ {
17080
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17081
+
17082
+ // Revert.
17083
+ paintobj.RestoreSelectable();
17084
+ }
17085
+ }
17086
+
1664417087 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1664517088
1664617089 // trying different ways of getting the depth info over
....@@ -16746,27 +17189,29 @@
1674617189 if (!movingcamera && !PAINTMODE)
1674717190 object.GetWindow().ScreenFitPoint(); // fev 2014
1674817191
16749
- if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17192
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1675017193 {
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;
17194
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1676217195
1676317196 if (object.GetWindow().copy.selection.Size() > 0)
16764
- folder = object.GetWindow().copy.selection.elementAt(0);
17197
+ {
17198
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1676517199
16766
- folder.add(group);
16767
-
16768
- object.GetWindow().ResetModel();
16769
- object.GetWindow().refreshContents();
17200
+ Object3D inst = new Object3D("inst" + paintcount++);
17201
+
17202
+ inst.CreateMaterial(); // use a void leaf to select instances
17203
+
17204
+ inst.add(paintobj); // link
17205
+
17206
+ object.GetWindow().SnapObject(inst);
17207
+
17208
+ Object3D folder = paintFolder; // GetFolder();
17209
+
17210
+ folder.add(inst);
17211
+
17212
+ object.GetWindow().ResetModel();
17213
+ object.GetWindow().refreshContents();
17214
+ }
1677017215 }
1677117216 else
1677217217 paintcount = 0;
....@@ -17088,10 +17533,14 @@
1708817533 gl.glFlush();
1708917534
1709017535 /**/
17091
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17536
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1709217537
17093
- float[] pixels = occlusionsizebuffer.array();
17538
+ float[] depths = occlusiondepthbuffer.array();
1709417539
17540
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17541
+
17542
+ int[] pixels = selectsizebuffer.array();
17543
+
1709517544 double r = 0, g = 0, b = 0;
1709617545
1709717546 double count = 0;
....@@ -17102,7 +17551,7 @@
1710217551
1710317552 double FACTOR = 1;
1710417553
17105
- for (int i = 0; i < pixels.length; i++)
17554
+ for (int i = 0; i < depths.length; i++)
1710617555 {
1710717556 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1710817557 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -17185,7 +17634,7 @@
1718517634
1718617635 double scale = ray.z; // 1; // cos
1718717636
17188
- float depth = pixels[newindex];
17637
+ float depth = depths[newindex];
1718917638
1719017639 /*
1719117640 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -17382,11 +17831,14 @@
1738217831 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1738317832 static IntBuffer bigAAbuffer;
1738417833 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
17385
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17834
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1738617835 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1738717836 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1738817837 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17389
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17838
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17839
+
17840
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17841
+
1739017842 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1739117843 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1739217844 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();