Normand Briere
2019-08-15 24a2a946b35279605e645349bd6b82e9e60aac88
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
....@@ -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,
....@@ -10607,7 +10861,7 @@
1060710861
1060810862 if (wait)
1060910863 {
10610
- Sleep(500);
10864
+ Sleep(200); // blocks everything
1061110865
1061210866 wait = false;
1061310867 }
....@@ -10722,7 +10976,7 @@
1072210976 // if (parentcam != renderCamera) // not a light
1072310977 if (cam != lightCamera)
1072410978 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10725
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
10979
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1072610980
1072710981 for (int j = 0; j < 4; j++)
1072810982 {
....@@ -10737,7 +10991,7 @@
1073710991 // if (parentcam != renderCamera) // not a light
1073810992 if (cam != lightCamera)
1073910993 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10740
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
10994
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1074110995
1074210996 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1074310997
....@@ -10823,13 +11077,43 @@
1082311077 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1082411078 }
1082511079
10826
- if (newenvy > -1)
11080
+// if (newenvy > -1)
11081
+// {
11082
+// LoadEnvy(newenvy);
11083
+// }
11084
+//
11085
+// newenvy = -1;
11086
+
11087
+ if (transformMode) // object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
1082711088 {
10828
- LoadEnvy(newenvy);
11089
+ if (cubemaprgb == null)
11090
+ {
11091
+ cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb" + "/", "jpg", false);
11092
+ }
11093
+
11094
+ cubemap = cubemaprgb;
1082911095 }
10830
-
10831
- newenvy = -1;
10832
-
11096
+ else
11097
+ {
11098
+ if (object.skyboxname != null)
11099
+ {
11100
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11101
+ {
11102
+ if (cubemap != null && cubemap != cubemaprgb)
11103
+ cubemap.dispose();
11104
+ cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11105
+ loadedskyboxname = object.skyboxname;
11106
+ }
11107
+ }
11108
+ else
11109
+ {
11110
+ cubemapcustom = null;
11111
+ loadedskyboxname = null;
11112
+ }
11113
+
11114
+ cubemap = cubemapcustom;
11115
+ }
11116
+
1083311117 ratio = ((double) getWidth()) / getHeight();
1083411118 //System.out.println("ratio = " + ratio);
1083511119
....@@ -10845,7 +11129,7 @@
1084511129
1084611130 if (!IsFrozen() && !ambientOcclusion)
1084711131 {
10848
- DrawSkyBox(gl);
11132
+ DrawSkyBox(gl, (float)ratio);
1084911133 }
1085011134
1085111135 //if (selection_view == -1)
....@@ -11028,9 +11312,9 @@
1102811312
1102911313 gl.glMatrixMode(GL.GL_MODELVIEW);
1103011314
11031
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11032
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
11033
-//gl.glEnable(gl.GL_MULTISAMPLE);
11315
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11316
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11317
+gl.glEnable(gl.GL_MULTISAMPLE);
1103411318 } else
1103511319 {
1103611320 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -11041,7 +11325,7 @@
1104111325 //System.out.println("BLENDING ON");
1104211326 gl.glEnable(GL.GL_BLEND);
1104311327 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
11044
-
11328
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1104511329 gl.glMatrixMode(gl.GL_PROJECTION);
1104611330 gl.glLoadIdentity();
1104711331
....@@ -11131,7 +11415,7 @@
1113111415
1113211416 // if (cam != lightCamera)
1113311417 //for (int count = parentcam.GetTransformCount(); --count>=0;)
11134
- LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
11418
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1113511419 }
1113611420
1113711421 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -11290,7 +11574,7 @@
1129011574 }
1129111575 }
1129211576
11293
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11577
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1129411578 {
1129511579 //gl.glDepthFunc(GL.GL_LEQUAL);
1129611580 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11298,24 +11582,21 @@
1129811582
1129911583 boolean texon = textureon;
1130011584
11301
- if (RENDERPROGRAM > 0)
11302
- {
11303
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11304
- textureon = false;
11305
- }
11585
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11586
+ textureon = false;
11587
+
1130611588 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1130711589 //System.out.println("ALLO");
1130811590 gl.glColorMask(false, false, false, false);
1130911591 DrawObject(gl);
11310
- if (RENDERPROGRAM > 0)
11311
- {
11312
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11313
- textureon = texon;
11314
- }
11592
+
11593
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11594
+ textureon = texon;
11595
+
1131511596 gl.glColorMask(true, true, true, true);
1131611597
1131711598 gl.glDepthFunc(GL.GL_EQUAL);
11318
- //gl.glDepthMask(false);
11599
+ gl.glDepthMask(false);
1131911600 }
1132011601
1132111602 if (false) // DrawMode() == SHADOW)
....@@ -11655,20 +11936,32 @@
1165511936 ReleaseTextures(DEFAULT_TEXTURES);
1165611937
1165711938 if (CLEANCACHE)
11658
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11939
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1165911940 {
11660
- String tex = e.nextElement();
11941
+ cTexture tex = e.nextElement();
1166111942
1166211943 // System.out.println("Texture --------- " + tex);
1166311944
11664
- if (tex.equals("WHITE_NOISE"))
11945
+ if (tex.equals("WHITE_NOISE:"))
1166511946 continue;
1166611947
11667
- if (!usedtextures.containsKey(tex))
11948
+ if (!usedtextures.contains(tex))
1166811949 {
11950
+ CacheTexture gettex = texturepigment.get(tex);
1166911951 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11670
- textures.get(tex).texture.dispose();
11671
- textures.remove(tex);
11952
+ if (gettex != null)
11953
+ {
11954
+ gettex.texture.dispose();
11955
+ texturepigment.remove(tex);
11956
+ }
11957
+
11958
+ gettex = texturebump.get(tex);
11959
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11960
+ if (gettex != null)
11961
+ {
11962
+ gettex.texture.dispose();
11963
+ texturebump.remove(tex);
11964
+ }
1167211965 }
1167311966 }
1167411967 }
....@@ -12196,8 +12489,76 @@
1219612489
1219712490 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1219812491
12199
- String program =
12492
+ String programmin =
12493
+ // Min shader
1220012494 "!!ARBfp1.0\n" +
12495
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12496
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12497
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12498
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12499
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12500
+ "PARAM light2cam0 = program.env[10];" +
12501
+ "PARAM light2cam1 = program.env[11];" +
12502
+ "PARAM light2cam2 = program.env[12];" +
12503
+ "TEMP temp;" +
12504
+ "TEMP light;" +
12505
+ "TEMP ndotl;" +
12506
+ "TEMP normal;" +
12507
+ "TEMP depth;" +
12508
+ "TEMP eye;" +
12509
+ "TEMP pos;" +
12510
+
12511
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12512
+ Normalize("normal") +
12513
+ "MOV light, state.light[0].position;" +
12514
+ "DP3 ndotl.x, light, normal;" +
12515
+
12516
+ // shadow
12517
+ "MOV pos, fragment.texcoord[1];" +
12518
+ "MOV temp, pos;" +
12519
+ ShadowTextureFetch("depth", "temp", "1") +
12520
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12521
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12522
+
12523
+ // No shadow when out of frustum
12524
+ //"SGE temp.y, depth.z, zero123.y;" +
12525
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12526
+
12527
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12528
+
12529
+ // Backlit
12530
+ "MOV pos.w, zero123.y;" +
12531
+ "DP4 eye.x, pos, light2cam0;" +
12532
+ "DP4 eye.y, pos, light2cam1;" +
12533
+ "DP4 eye.z, pos, light2cam2;" +
12534
+ Normalize("eye") +
12535
+
12536
+ "DP3 ndotl.y, -eye, normal;" +
12537
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12538
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12539
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12540
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12541
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12542
+
12543
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12544
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12545
+
12546
+ // Pigment
12547
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12548
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12549
+ "MUL temp, temp, ndotl.x;" +
12550
+
12551
+ "MUL temp, temp, zero123.z;" +
12552
+
12553
+ //"MUL temp, temp, ndotl.y;" +
12554
+
12555
+ "MOV temp.w, zero123.y;" + // reset alpha
12556
+ "MOV result.color, temp;" +
12557
+ "END";
12558
+
12559
+ String programmax =
12560
+ "!!ARBfp1.0\n" +
12561
+
1220112562 //"OPTION ARB_fragment_program_shadow;" +
1220212563 "PARAM light2cam0 = program.env[10];" +
1220312564 "PARAM light2cam1 = program.env[11];" +
....@@ -12312,8 +12673,7 @@
1231212673 "TEMP shininess;" +
1231312674 "\n" +
1231412675 "MOV texSamp, one;" +
12315
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12316
-
12676
+
1231712677 "MOV mapgrid.x, one2048th.x;" +
1231812678 "MOV temp, fragment.texcoord[1];" +
1231912679 /*
....@@ -12334,20 +12694,20 @@
1233412694 "MUL temp, floor, mapgrid.x;" +
1233512695 //"TEX depth0, temp, texture[1], 2D;" +
1233612696 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12337
- TextureFetch("depth0", "temp", "1") +
12697
+ ShadowTextureFetch("depth0", "temp", "1") +
1233812698 "") +
1233912699 "ADD temp.x, temp.x, mapgrid.x;" +
1234012700 //"TEX depth1, temp, texture[1], 2D;" +
1234112701 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12342
- TextureFetch("depth1", "temp", "1") +
12702
+ ShadowTextureFetch("depth1", "temp", "1") +
1234312703 "") +
1234412704 "ADD temp.y, temp.y, mapgrid.x;" +
1234512705 //"TEX depth2, temp, texture[1], 2D;" +
12346
- TextureFetch("depth2", "temp", "1") +
12706
+ ShadowTextureFetch("depth2", "temp", "1") +
1234712707 "SUB temp.x, temp.x, mapgrid.x;" +
1234812708 //"TEX depth3, temp, texture[1], 2D;" +
1234912709 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12350
- TextureFetch("depth3", "temp", "1") +
12710
+ ShadowTextureFetch("depth3", "temp", "1") +
1235112711 "") +
1235212712 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1235312713 //"MOV params, material;" +
....@@ -12718,10 +13078,10 @@
1271813078 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1271913079 "") +
1272013080
12721
- // display shadow only (bump == 0)
13081
+ // display shadow only (fakedepth == 0)
1272213082 "SUB temp.x, half.x, shadow.x;" +
1272313083 "MOV temp.y, -params5.z;" + // params6.x;" +
12724
- "SLT temp.z, temp.y, -one2048th.x;" +
13084
+ "SLT temp.z, temp.y, -c256i.x;" +
1272513085 "SUB temp.y, one.x, temp.z;" +
1272613086 "MUL temp.x, temp.x, temp.y;" +
1272713087 "KIL temp.x;" +
....@@ -13052,6 +13412,13 @@
1305213412 //once = true;
1305313413 }
1305413414
13415
+ String program = programmax;
13416
+
13417
+ if (Globals.MINSHADER)
13418
+ {
13419
+ program = programmin;
13420
+ }
13421
+
1305513422 System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1305613423 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1305713424 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
....@@ -13145,25 +13512,26 @@
1314513512 return out;
1314613513 }
1314713514
13148
- String TextureFetch(String dest, String src, String unit)
13515
+ // Also does frustum culling
13516
+ String ShadowTextureFetch(String dest, String src, String unit)
1314913517 {
1315013518 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1315113519 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1315213520 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13521
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13522
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1315313523 "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;" +
13524
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13525
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1315813526 //"SWZ buffer, temp, w,w,w,w;";
13159
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13527
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1316013528 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1316113529 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1316213530 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13163
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13531
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1316413532
13165
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13166
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13533
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13534
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1316713535 }
1316813536
1316913537 String Shadow(String depth, String shadow)
....@@ -13210,7 +13578,7 @@
1321013578 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1321113579 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1321213580
13213
- // No shadow when out of frustrum
13581
+ // No shadow when out of frustum
1321413582 "SGE temp.x, " + depth + ".z, one.z;" +
1321513583 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1321613584 "";
....@@ -14008,14 +14376,15 @@
1400814376 drag = false;
1400914377 //System.out.println("Mouse DOWN");
1401014378 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);
14379
+ //ClickInfo info = new ClickInfo();
14380
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14381
+ object.clickInfo.pane = this;
14382
+ object.clickInfo.camera = renderCamera;
14383
+ object.clickInfo.x = x;
14384
+ object.clickInfo.y = y;
14385
+ object.clickInfo.modifiers = modifiersex;
14386
+ editObj = object.doEditClick(//info,
14387
+ 0);
1401914388 if (!editObj)
1402014389 {
1402114390 hasMarquee = true;
....@@ -14297,12 +14666,12 @@
1429714666 void GoDown(int mod)
1429814667 {
1429914668 MODIFIERS |= COMMAND;
14300
- /*
14669
+ /**/
1430114670 if((mod&SHIFT) == SHIFT)
14302
- manipCamera.RotatePosition(0, -speed);
14671
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
1430314672 else
14304
- manipCamera.BackForth(0, -speed*delta, getWidth());
14305
- */
14673
+ manipCamera.RotatePosition(0, -speed);
14674
+ /**/
1430614675 if ((mod & SHIFT) == SHIFT)
1430714676 {
1430814677 mouseMode = mouseMode; // VR??
....@@ -14318,12 +14687,12 @@
1431814687 void GoUp(int mod)
1431914688 {
1432014689 MODIFIERS |= COMMAND;
14321
- /*
14690
+ /**/
1432214691 if((mod&SHIFT) == SHIFT)
14323
- manipCamera.RotatePosition(0, speed);
14692
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
1432414693 else
14325
- manipCamera.BackForth(0, speed*delta, getWidth());
14326
- */
14694
+ manipCamera.RotatePosition(0, speed);
14695
+ /**/
1432714696 if ((mod & SHIFT) == SHIFT)
1432814697 {
1432914698 mouseMode = mouseMode;
....@@ -14339,12 +14708,12 @@
1433914708 void GoLeft(int mod)
1434014709 {
1434114710 MODIFIERS |= COMMAND;
14342
- /*
14711
+ /**/
1434314712 if((mod&SHIFT) == SHIFT)
14344
- manipCamera.RotatePosition(speed, 0);
14345
- else
1434614713 manipCamera.Translate(speed*delta, 0, getWidth());
14347
- */
14714
+ else
14715
+ manipCamera.RotatePosition(speed, 0);
14716
+ /**/
1434814717 if ((mod & SHIFT) == SHIFT)
1434914718 {
1435014719 mouseMode = mouseMode;
....@@ -14360,12 +14729,12 @@
1436014729 void GoRight(int mod)
1436114730 {
1436214731 MODIFIERS |= COMMAND;
14363
- /*
14732
+ /**/
1436414733 if((mod&SHIFT) == SHIFT)
14365
- manipCamera.RotatePosition(-speed, 0);
14366
- else
1436714734 manipCamera.Translate(-speed*delta, 0, getWidth());
14368
- */
14735
+ else
14736
+ manipCamera.RotatePosition(-speed, 0);
14737
+ /**/
1436914738 if ((mod & SHIFT) == SHIFT)
1437014739 {
1437114740 mouseMode = mouseMode;
....@@ -14415,15 +14784,16 @@
1441514784 if (editObj)
1441614785 {
1441714786 drag = true;
14418
- ClickInfo info = new ClickInfo();
14419
- info.bounds.setBounds(0, 0,
14787
+ //ClickInfo info = new ClickInfo();
14788
+ object.clickInfo.bounds.setBounds(0, 0,
1442014789 (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);
14790
+ object.clickInfo.pane = this;
14791
+ object.clickInfo.camera = renderCamera;
14792
+ object.clickInfo.x = x;
14793
+ object.clickInfo.y = y;
14794
+ object //.GetWindow().copy
14795
+ .doEditDrag(//info,
14796
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1442714797 } else
1442814798 {
1442914799 if (x < startX)
....@@ -14572,24 +14942,27 @@
1457214942 }
1457314943 }
1457414944
14945
+// ClickInfo clickInfo = new ClickInfo();
14946
+
1457514947 public void mouseMoved(MouseEvent e)
1457614948 {
1457714949 //System.out.println("mouseMoved: " + e);
1457814950 if (isRenderer)
1457914951 return;
1458014952
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;
14953
+ // Mouse cursor feedback
14954
+ object.clickInfo.x = e.getX();
14955
+ object.clickInfo.y = e.getY();
14956
+ object.clickInfo.modifiers = e.getModifiersEx();
14957
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14958
+ object.clickInfo.pane = this;
14959
+ object.clickInfo.camera = renderCamera;
1458814960 if (!isRenderer)
1458914961 {
1459014962 //ObjEditor editWindow = object.editWindow;
1459114963 //Object3D copy = editWindow.copy;
14592
- if (object.doEditClick(ci, 0))
14964
+ if (object.doEditClick(//clickInfo,
14965
+ 0))
1459314966 {
1459414967 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1459514968 } else
....@@ -14861,7 +15234,8 @@
1486115234 // break;
1486215235 case 'T':
1486315236 CACHETEXTURE ^= true;
14864
- textures.clear();
15237
+ texturepigment.clear();
15238
+ texturebump.clear();
1486515239 // repaint();
1486615240 break;
1486715241 case 'Y':
....@@ -14946,7 +15320,9 @@
1494615320 case 'E' : COMPACT ^= true;
1494715321 repaint();
1494815322 break;
14949
- case 'W' : DEBUGHSB ^= true;
15323
+ case 'W' : // Wide Window (fullscreen)
15324
+ //DEBUGHSB ^= true;
15325
+ ObjEditor.theFrame.ToggleFullScreen();
1495015326 repaint();
1495115327 break;
1495215328 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14972,13 +15348,7 @@
1497215348 repaint();
1497315349 break;
1497415350 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':
15351
+ //case 'L':
1498215352 if (lightMode)
1498315353 {
1498415354 lightMode = false;
....@@ -15042,20 +15412,24 @@
1504215412 OCCLUSION_CULLING ^= true;
1504315413 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1504415414 break;
15045
- case '0': envyoff ^= true; repaint(); break;
15415
+ //case '0': envyoff ^= true; repaint(); break;
1504615416 case '1':
1504715417 case '2':
1504815418 case '3':
1504915419 case '4':
1505015420 case '5':
15051
- newenvy = Character.getNumericValue(key);
15052
- repaint();
15053
- break;
1505415421 case '6':
1505515422 case '7':
1505615423 case '8':
1505715424 case '9':
15058
- BGcolor = (key - '6')/3.f;
15425
+ if (true) // envyoff)
15426
+ {
15427
+ BGcolor = (key - '1')/8.f;
15428
+ }
15429
+ else
15430
+ {
15431
+ //newenvy = Character.getNumericValue(key);
15432
+ }
1505915433 repaint();
1506015434 break;
1506115435 case '!':
....@@ -15125,7 +15499,10 @@
1512515499 // kompactbit = 6;
1512615500 // break;
1512715501 case ' ':
15128
- ObjEditor.theFrame.ToggleFullScreen();
15502
+ lightMode ^= true;
15503
+ Globals.lighttouched = true;
15504
+ manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
15505
+ targetLookAt.set(manipCamera.lookAt);
1512915506 repaint();
1513015507 break;
1513115508 //case '`' :
....@@ -15615,8 +15992,6 @@
1561515992
1561615993 int width = getBounds().width;
1561715994 int height = getBounds().height;
15618
- ClickInfo info = new ClickInfo();
15619
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1562015995 //Image img = CreateImage(width, height);
1562115996 //System.out.println("width = " + width + "; height = " + height + "\n");
1562215997
....@@ -15693,38 +16068,47 @@
1569316068 }
1569416069 if (object != null && !hasMarquee)
1569516070 {
16071
+ if (object.clickInfo == null)
16072
+ object.clickInfo = new ClickInfo();
16073
+ ClickInfo info = object.clickInfo;
16074
+ //ClickInfo info = new ClickInfo();
16075
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16076
+
1569616077 if (isRenderer)
1569716078 {
15698
- info.flags++;
16079
+ object.clickInfo.flags++;
1569916080 double frameAspect = (double) width / (double) height;
1570016081 if (frameAspect > renderCamera.aspect)
1570116082 {
1570216083 int desired = (int) ((double) height * renderCamera.aspect);
15703
- info.bounds.width -= width - desired;
15704
- info.bounds.x += (width - desired) / 2;
16084
+ object.clickInfo.bounds.width -= width - desired;
16085
+ object.clickInfo.bounds.x += (width - desired) / 2;
1570516086 } else
1570616087 {
1570716088 int desired = (int) ((double) width / renderCamera.aspect);
15708
- info.bounds.height -= height - desired;
15709
- info.bounds.y += (height - desired) / 2;
16089
+ object.clickInfo.bounds.height -= height - desired;
16090
+ object.clickInfo.bounds.y += (height - desired) / 2;
1571016091 }
1571116092 }
15712
- info.g = gr;
15713
- info.camera = renderCamera;
16093
+
16094
+ object.clickInfo.g = gr;
16095
+ object.clickInfo.camera = renderCamera;
1571416096 /*
1571516097 // Memory intensive (brep.verticescopy)
1571616098 if (!(object instanceof Composite))
1571716099 object.draw(info, 0, false); // SLOW :
1571816100 */
15719
- if (!isRenderer)
16101
+ if (!isRenderer) // && drag)
1572016102 {
16103
+ Grafreed.Assert(object != null);
16104
+ Grafreed.Assert(object.selection != null);
1572116105 if (object.selection.Size() > 0)
1572216106 {
1572316107 int hitSomething = object.selection.get(0).hitSomething;
1572416108
15725
- info.DX = 0;
15726
- info.DY = 0;
15727
- info.W = 1;
16109
+ object.clickInfo.DX = 0;
16110
+ object.clickInfo.DY = 0;
16111
+ object.clickInfo.W = 1;
1572816112 if (hitSomething == Object3D.hitCenter)
1572916113 {
1573016114 info.DX = X;
....@@ -15736,7 +16120,8 @@
1573616120 info.DY -= info.bounds.height/2;
1573716121 }
1573816122
15739
- object.drawEditHandles(info, 0);
16123
+ object.drawEditHandles(//info,
16124
+ 0);
1574016125
1574116126 if (drag && (X != 0 || Y != 0))
1574216127 {
....@@ -16235,6 +16620,8 @@
1623516620 private /*static*/ boolean firstime;
1623616621 private /*static*/ cVector newView = new cVector();
1623716622 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16623
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16624
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1623816625 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1623916626 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1624016627 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16247,29 +16634,67 @@
1624716634 {
1624816635 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1624916636
16637
+ int usedsuf = 0;
16638
+
1625016639 for (int i = 0; i < suffixes.length; i++)
1625116640 {
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)
16641
+ String[] suffixe = suffixes;
16642
+ String[] fallback = suffixes2;
16643
+ String[] fallfallback = suffixes3;
16644
+
16645
+ for (int c=usedsuf; --c>=0;)
1625716646 {
16258
- throw new IOException("Unable to load texture " + resourceName);
16647
+// String[] temp = suffixe;
16648
+// suffixe = fallback;
16649
+// fallback = fallfallback;
16650
+// fallfallback = temp;
1625916651 }
16652
+
16653
+ String resourceName = basename + suffixe[i] + "." + suffix;
16654
+ TextureData data;
16655
+
16656
+ try
16657
+ {
16658
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16659
+ mipmapped,
16660
+ FileUtil.getFileSuffix(resourceName));
16661
+ }
16662
+ catch (Exception e)
16663
+ {
16664
+ try
16665
+ {
16666
+ resourceName = basename + fallback[i] + "." + suffix;
16667
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16668
+ mipmapped,
16669
+ FileUtil.getFileSuffix(resourceName));
16670
+ }
16671
+ catch (Exception e2)
16672
+ {
16673
+ resourceName = basename + fallfallback[i] + "." + suffix;
16674
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16675
+ mipmapped,
16676
+ FileUtil.getFileSuffix(resourceName));
16677
+ }
16678
+ }
16679
+
1626016680 //System.out.println("Target = " + targets[i]);
1626116681 cubemap.updateImage(data, targets[i]);
1626216682 }
1626316683
1626416684 return cubemap;
1626516685 }
16686
+
1626616687 int bigsphere = -1;
1626716688
1626816689 float BGcolor = 0.5f;
1626916690
16270
- private void DrawSkyBox(GL gl)
16691
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16692
+
16693
+ private void DrawSkyBox(GL gl, float ratio)
1627116694 {
16272
- if (envyoff || cubemap == null)
16695
+ if (//envyoff ||
16696
+ WIREFRAME ||
16697
+ cubemap == null)
1627316698 {
1627416699 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1627516700 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16284,7 +16709,17 @@
1628416709 // Compensates for ExaminerViewer's modification of modelview matrix
1628516710 gl.glMatrixMode(GL.GL_MODELVIEW);
1628616711 gl.glLoadIdentity();
16712
+ gl.glScalef(1,ratio,1);
1628716713
16714
+// colorV[0] = 2;
16715
+// colorV[1] = 2;
16716
+// colorV[2] = 2;
16717
+// colorV[3] = 1;
16718
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16719
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16720
+//
16721
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16722
+
1628816723 //gl.glActiveTexture(GL.GL_TEXTURE1);
1628916724 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1629016725
....@@ -16316,6 +16751,7 @@
1631616751 {
1631716752 gl.glScalef(1.0f, -1.0f, 1.0f);
1631816753 }
16754
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1631916755 gl.glMultMatrixd(viewrot_1, 0);
1632016756 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1632116757 //viewer.updateInverseRotation(gl);
....@@ -16356,7 +16792,8 @@
1635616792 gl.glDisable(GL.GL_TEXTURE_GEN_R);
1635716793
1635816794 cubemap.disable();
16359
- ////cubemap.unbind();
16795
+ //cubemap.dispose();
16796
+
1636016797 if (CULLFACE)
1636116798 {
1636216799 gl.glEnable(gl.GL_CULL_FACE);
....@@ -16551,6 +16988,14 @@
1655116988 }
1655216989 }
1655316990
16991
+ private Object3D GetFolder()
16992
+ {
16993
+ Object3D folder = object.GetWindow().copy;
16994
+ if (object.GetWindow().copy.selection.Size() > 0)
16995
+ folder = object.GetWindow().copy.selection.elementAt(0);
16996
+ return folder;
16997
+ }
16998
+
1655416999 class SelectBuffer implements GLEventListener
1655517000 {
1655617001
....@@ -16566,7 +17011,7 @@
1656617011 //new Exception().printStackTrace();
1656717012 System.out.println("select buffer init");
1656817013 // Use debug pipeline
16569
- drawable.setGL(new DebugGL(drawable.getGL()));
17014
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1657017015
1657117016 GL gl = drawable.getGL();
1657217017
....@@ -16630,6 +17075,17 @@
1663017075
1663117076 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1663217077
17078
+ if (PAINTMODE)
17079
+ {
17080
+ if (object.GetWindow().copy.selection.Size() > 0)
17081
+ {
17082
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17083
+
17084
+ // Make what you paint not selectable.
17085
+ paintobj.ResetSelectable();
17086
+ }
17087
+ }
17088
+
1663317089 //int tmp = selection_view;
1663417090 //selection_view = -1;
1663517091 int temp = DrawMode();
....@@ -16641,6 +17097,17 @@
1664117097 // temp = DEFAULT; // patch for selection debug
1664217098 Globals.drawMode = temp; // WARNING
1664317099
17100
+ if (PAINTMODE)
17101
+ {
17102
+ if (object.GetWindow().copy.selection.Size() > 0)
17103
+ {
17104
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17105
+
17106
+ // Revert.
17107
+ paintobj.RestoreSelectable();
17108
+ }
17109
+ }
17110
+
1664417111 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1664517112
1664617113 // trying different ways of getting the depth info over
....@@ -16746,27 +17213,29 @@
1674617213 if (!movingcamera && !PAINTMODE)
1674717214 object.GetWindow().ScreenFitPoint(); // fev 2014
1674817215
16749
- if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17216
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1675017217 {
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;
17218
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1676217219
1676317220 if (object.GetWindow().copy.selection.Size() > 0)
16764
- folder = object.GetWindow().copy.selection.elementAt(0);
17221
+ {
17222
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1676517223
16766
- folder.add(group);
16767
-
16768
- object.GetWindow().ResetModel();
16769
- object.GetWindow().refreshContents();
17224
+ Object3D inst = new Object3D("inst" + paintcount++);
17225
+
17226
+ inst.CreateMaterial(); // use a void leaf to select instances
17227
+
17228
+ inst.add(paintobj); // link
17229
+
17230
+ object.GetWindow().SnapObject(inst);
17231
+
17232
+ Object3D folder = paintFolder; // GetFolder();
17233
+
17234
+ folder.add(inst);
17235
+
17236
+ object.GetWindow().ResetModel();
17237
+ object.GetWindow().refreshContents();
17238
+ }
1677017239 }
1677117240 else
1677217241 paintcount = 0;
....@@ -17088,10 +17557,14 @@
1708817557 gl.glFlush();
1708917558
1709017559 /**/
17091
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17560
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1709217561
17093
- float[] pixels = occlusionsizebuffer.array();
17562
+ float[] depths = occlusiondepthbuffer.array();
1709417563
17564
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17565
+
17566
+ int[] pixels = selectsizebuffer.array();
17567
+
1709517568 double r = 0, g = 0, b = 0;
1709617569
1709717570 double count = 0;
....@@ -17102,7 +17575,7 @@
1710217575
1710317576 double FACTOR = 1;
1710417577
17105
- for (int i = 0; i < pixels.length; i++)
17578
+ for (int i = 0; i < depths.length; i++)
1710617579 {
1710717580 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1710817581 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -17185,7 +17658,7 @@
1718517658
1718617659 double scale = ray.z; // 1; // cos
1718717660
17188
- float depth = pixels[newindex];
17661
+ float depth = depths[newindex];
1718917662
1719017663 /*
1719117664 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -17382,11 +17855,14 @@
1738217855 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1738317856 static IntBuffer bigAAbuffer;
1738417857 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
17385
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17858
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1738617859 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1738717860 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1738817861 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17389
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17862
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17863
+
17864
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17865
+
1739017866 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1739117867 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1739217868 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();