Normand Briere
2019-07-30 475f8cbdbd96fdbf8f5b216ffebb31a51f25c2f9
CameraPane.java
....@@ -18,7 +18,10 @@
1818 import javax.imageio.ImageIO;
1919 import javax.imageio.ImageWriteParam;
2020 import javax.imageio.ImageWriter;
21
+import javax.imageio.ImageReadParam;
22
+import javax.imageio.ImageReader;
2123 import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
24
+import javax.imageio.stream.ImageInputStream;
2225 import javax.imageio.stream.ImageOutputStream;
2326 import javax.imageio.ImageWriteParam;
2427
....@@ -30,6 +33,7 @@
3033 import java.nio.*;
3134
3235 import gleem.linalg.Mat4f;
36
+import javax.imageio.ImageTypeSpecifier;
3337
3438 class CameraPane extends GLCanvas implements iCameraPane, Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener
3539 {
....@@ -44,6 +48,39 @@
4448 static boolean ABORTED = false;
4549
4650 static int STEP = 1;
51
+
52
+ private static BufferedImage CreateBim(byte[] bytes, int width, int height)
53
+ {
54
+ int[] pixels = new int[bytes.length/3];
55
+ for (int i=pixels.length; --i>=0;)
56
+ {
57
+ int i3 = i*3;
58
+ pixels[i] = 0xFF;
59
+ pixels[i] <<= 8;
60
+ pixels[i] |= bytes[i3+2] & 0xFF;
61
+ pixels[i] <<= 8;
62
+ pixels[i] |= bytes[i3+1] & 0xFF;
63
+ pixels[i] <<= 8;
64
+ pixels[i] |= bytes[i3] & 0xFF;
65
+ }
66
+ /*
67
+ int r=0,g=0,b=0,a=0;
68
+ for (int i=0; i<width; i++)
69
+ for (int j=0; j<height; j++)
70
+ {
71
+ int index = j*width+i;
72
+ int p = pixels[index];
73
+ a = ((p>>24) & 0xFF);
74
+ r = ((p>>16) & 0xFF);
75
+ g = ((p>>8) & 0xFF);
76
+ b = (p & 0xFF);
77
+ pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
78
+ }
79
+ /**/
80
+ BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
81
+ rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
82
+ return rendImage;
83
+ }
4784
4885 /*static*/ private boolean CULLFACE = false; // true;
4986 /*static*/ boolean NEAREST = false; // true;
....@@ -60,7 +97,7 @@
6097 //boolean REDUCETEXTURE = true;
6198 boolean CACHETEXTURE = true;
6299 boolean CLEANCACHE = false; // true;
63
- boolean MIPMAP = true; // false; // true;
100
+ boolean MIPMAP = false; // true; // never works...
64101 boolean COMPRESSTEXTURE = false;
65102 boolean KOMPACTTEXTURE = false; // true;
66103 boolean RESIZETEXTURE = false;
....@@ -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 {
....@@ -2405,43 +2455,19 @@
24052455 return currentGL;
24062456 }
24072457
2408
- private BufferedImage CreateBim(TextureData texturedata)
2458
+ static private BufferedImage CreateBim(TextureData texturedata)
24092459 {
2410
- // cache to disk
2411
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
2412
- //buffers[0].
2413
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
2414
- int[] pixels = new int[bytebuf.capacity()/3];
2415
- int width = texturedata.getWidth(); //(int)Math.sqrt(pixels.length); // squared
2416
- int height = width;
2417
- for (int i=pixels.length; --i>=0;)
2418
- {
2419
- int i3 = i*3;
2420
- pixels[i] = 0xFF;
2421
- pixels[i] <<= 8;
2422
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
2423
- pixels[i] <<= 8;
2424
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
2425
- pixels[i] <<= 8;
2426
- pixels[i] |= bytebuf.get(i3) & 0xFF;
2427
- }
2428
- /*
2429
- int r=0,g=0,b=0,a=0;
2430
- for (int i=0; i<width; i++)
2431
- for (int j=0; j<height; j++)
2432
- {
2433
- int index = j*width+i;
2434
- int p = pixels[index];
2435
- a = ((p>>24) & 0xFF);
2436
- r = ((p>>16) & 0xFF);
2437
- g = ((p>>8) & 0xFF);
2438
- b = (p & 0xFF);
2439
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
2440
- }
2441
- /**/
2442
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
2443
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
2444
- return rendImage;
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);
24452471 }
24462472
24472473 /**/
....@@ -2452,18 +2478,20 @@
24522478
24532479 int resolution;
24542480
2455
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2481
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
24562482 {
2457
- texture = tex;
2483
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2484
+ texturedata = texdata;
24582485 resolution = res;
24592486 }
24602487 }
24612488 /**/
24622489
24632490 // TEXTURE static Texture texture;
2464
- static public java.util.Hashtable<String, CacheTexture> textures = new java.util.Hashtable<String, CacheTexture>();
2465
- static public java.util.Hashtable<BufferedImage, CacheTexture> bimtextures = new java.util.Hashtable<BufferedImage, CacheTexture>();
2466
- static public java.util.HashSet<String> usedtextures = new java.util.HashSet<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>();
24672495
24682496 int pigmentdepth = 0;
24692497 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
....@@ -2471,10 +2499,10 @@
24712499 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
24722500 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
24732501 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2474
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2502
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
24752503 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
24762504
2477
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2505
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
24782506 {
24792507 TextureData texturedata = null;
24802508
....@@ -2493,16 +2521,16 @@
24932521 if (bump)
24942522 texturedata = ConvertBump(texturedata, false);
24952523
2496
- com.sun.opengl.util.texture.Texture texture =
2497
- 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);
24982526
2499
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2500
- 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);
25012529
2502
- return texture;
2530
+ return texturedata;
25032531 }
25042532
2505
- com.sun.opengl.util.texture.Texture GetBimTexture(BufferedImage name, boolean bump)
2533
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
25062534 {
25072535 TextureData texturedata = null;
25082536
....@@ -2510,7 +2538,7 @@
25102538 {
25112539 texturedata =
25122540 com.sun.opengl.util.texture.TextureIO.newTextureData(
2513
- name,
2541
+ bim,
25142542 true);
25152543 } catch (Exception e)
25162544 {
....@@ -2519,14 +2547,8 @@
25192547
25202548 if (bump)
25212549 texturedata = ConvertBump(texturedata, false);
2522
-
2523
- com.sun.opengl.util.texture.Texture texture =
2524
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2525
-
2526
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2527
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
2528
-
2529
- return texture;
2550
+
2551
+ return texturedata;
25302552 }
25312553
25322554 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -8014,8 +8036,8 @@
80148036 pigment = null;
80158037 }
80168038
8017
- ReleaseTexture(bump, true);
8018
- ReleaseTexture(pigment, false);
8039
+ ReleaseTexture(tex, true);
8040
+ ReleaseTexture(tex, false);
80198041 }
80208042
80218043 public void ReleasePigmentTexture(cTexture tex) // INTERFACE
....@@ -8044,7 +8066,7 @@
80448066 pigment = null;
80458067 }
80468068
8047
- ReleaseTexture(pigment, false);
8069
+ ReleaseTexture(tex, false);
80488070 }
80498071
80508072 public void ReleaseBumpTexture(cTexture tex) // INTERFACE
....@@ -8073,10 +8095,10 @@
80738095 bump = null;
80748096 }
80758097
8076
- ReleaseTexture(bump, true);
8098
+ ReleaseTexture(tex, true);
80778099 }
80788100
8079
- void ReleaseTexture(String tex, boolean bump)
8101
+ void ReleaseTexture(cTexture tex, boolean bump)
80808102 {
80818103 if (// DrawMode() != 0 || /*tex == null ||*/
80828104 ambientOcclusion ) // || !textureon)
....@@ -8087,7 +8109,7 @@
80878109 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
80888110
80898111 if (tex != null)
8090
- texture = textures.get(tex);
8112
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
80918113
80928114 // //assert( texture != null );
80938115 // if (texture == null)
....@@ -8237,13 +8259,13 @@
82378259
82388260 if (tex == null)
82398261 {
8240
- BindTexture(null, null,false,resolution);
8262
+ BindTexture(null,false,resolution);
82418263 return;
82428264 }
82438265
82448266 String pigment = Object3D.GetPigment(tex);
82458267
8246
- usedtextures.add(pigment);
8268
+ usedtextures.add(tex);
82478269
82488270 //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
82498271 {
....@@ -8257,7 +8279,7 @@
82578279 }
82588280
82598281 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8260
- BindTexture(tex.pigmenttexture, pigment, false, resolution);
8282
+ BindTexture(tex, false, resolution);
82618283 }
82628284
82638285 /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8270,13 +8292,13 @@
82708292
82718293 if (tex == null)
82728294 {
8273
- BindTexture(null, null,true,resolution);
8295
+ BindTexture(null,true,resolution);
82748296 return;
82758297 }
82768298
82778299 String bump = Object3D.GetBump(tex);
82788300
8279
- usedtextures.add(bump);
8301
+ usedtextures.add(tex);
82808302
82818303 //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
82828304 {
....@@ -8290,7 +8312,7 @@
82908312 }
82918313
82928314 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8293
- BindTexture(tex.bumptexture, bump, true, resolution);
8315
+ BindTexture(tex, true, resolution);
82948316 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
82958317 }
82968318
....@@ -8314,13 +8336,19 @@
83148336 return fileExists;
83158337 }
83168338
8317
- CacheTexture GetCacheTexture(java.awt.image.BufferedImage bim, String tex, boolean bump, int resolution) throws Exception
8339
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
83188340 {
83198341 CacheTexture texturecache = null;
83208342
83218343 if (tex != null)
83228344 {
8323
- 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
+ }
83248352
83258353 String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
83268354
....@@ -8330,29 +8358,46 @@
83308358 // else
83318359 // if (!texname.startsWith("/"))
83328360 // texname = "/Users/nbriere/Textures/" + texname;
8333
- if (!FileExists(tex))
8361
+ if (!FileExists(texname))
83348362 {
83358363 texname = fallbackTextureName;
83368364 }
83378365
83388366 if (CACHETEXTURE)
83398367 {
8340
- if (bim == null)
8341
- texturecache = textures.get(texname); // TEXTURE CACHE
8368
+ if (texdata == null)
8369
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
83428370 else
8343
- texturecache = bimtextures.get(bim); // TEXTURE CACHE
8371
+ texturecache = bimtextures.get(texdata);
83448372 }
83458373
8346
- if (texturecache == null || texturecache.resolution < resolution)
8374
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
83478375 {
83488376 TextureData texturedata = null;
83498377
8350
- if (bim != null)
8378
+ if (texdata != null && textureon)
83518379 {
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
+
83528391 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;
83538398 }
83548399 else
8355
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8400
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
83568401 {
83578402 assert(!bump);
83588403 // if (bump)
....@@ -8363,7 +8408,7 @@
83638408 // }
83648409 // else
83658410 // {
8366
- texturecache = textures.get(tex);
8411
+ // texturecache = textures.get(texname); // suspicious
83678412 if (texturecache == null)
83688413 {
83698414 texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
....@@ -8372,10 +8417,10 @@
83728417 new Exception().printStackTrace();
83738418 // }
83748419 } else
8375
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8420
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
83768421 {
83778422 assert(bump);
8378
- texturecache = textures.get(tex);
8423
+ // texturecache = textures.get(texname); // suspicious
83798424 if (texturecache == null)
83808425 texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
83818426 else
....@@ -8387,9 +8432,9 @@
83878432 // texture = GetResourceTexture("default.png");
83888433 //} else
83898434 //{
8390
- if (tex.equals("WHITE_NOISE"))
8435
+ if (texname.endsWith("WHITE_NOISE"))
83918436 {
8392
- texturecache = textures.get(tex);
8437
+ // texturecache = textures.get(texname); // suspicious
83938438 if (texturecache == null)
83948439 texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
83958440 else
....@@ -8452,17 +8497,16 @@
84528497 if (texturedata == null)
84538498 throw new Exception();
84548499
8455
- texturecache = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8500
+ texturecache = new CacheTexture(texturedata,resolution);
84568501 //texture = GetTexture(tex, bump);
84578502 }
84588503 }
84598504 //}
84608505 }
84618506
8462
- if (/*CACHETEXTURE &&*/ texturecache != null && textureon)
8507
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
84638508 {
84648509 //return false;
8465
- assert(bim == null);
84668510
84678511 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
84688512 if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
....@@ -8509,18 +8553,20 @@
85098553 }
85108554 }
85118555 }
8512
-
8556
+
8557
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8558
+
85138559 //System.out.println("Texture = " + tex);
8514
- if (textures.containsKey(texname))
8560
+ if (textures.containsKey(tex))
85158561 {
8516
- CacheTexture thetex = textures.get(texname);
8562
+ CacheTexture thetex = textures.get(tex);
85178563 thetex.texture.disable();
85188564 thetex.texture.dispose();
8519
- textures.remove(texname);
8565
+ textures.remove(tex);
85208566 }
85218567
85228568 //texture.texturedata = texturedata;
8523
- textures.put(texname, texturecache);
8569
+ textures.put(tex, texturecache);
85248570
85258571 // newtex = true;
85268572 }
....@@ -8541,12 +8587,41 @@
85418587
85428588 static void EmbedTextures(cTexture tex)
85438589 {
8590
+ if (tex.pigmentdata == null)
8591
+ {
8592
+ //String texname = Object3D.GetPigment(tex);
8593
+
8594
+ CacheTexture texturecache = texturepigment.get(tex);
8595
+
8596
+ if (texturecache != null)
8597
+ {
8598
+ tex.pw = texturecache.texturedata.getWidth();
8599
+ tex.ph = texturecache.texturedata.getHeight();
8600
+ tex.pigmentdata = //CompressJPEG(CreateBim
8601
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8602
+ ;
8603
+ //, tex.pw, tex.ph), 0.5f);
8604
+ }
8605
+ }
85448606
8607
+ if (tex.bumpdata == null)
8608
+ {
8609
+ //String texname = Object3D.GetBump(tex);
8610
+
8611
+ CacheTexture texturecache = texturebump.get(tex);
8612
+
8613
+ if (texturecache != null)
8614
+ {
8615
+ tex.bw = texturecache.texturedata.getWidth();
8616
+ tex.bh = texturecache.texturedata.getHeight();
8617
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8618
+ }
8619
+ }
85458620 }
85468621
8547
- com.sun.opengl.util.texture.Texture GetTexture(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception
8622
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
85488623 {
8549
- CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution);
8624
+ CacheTexture texture = GetCacheTexture(tex, bump, resolution);
85508625
85518626 if (bump)
85528627 {
....@@ -8562,14 +8637,14 @@
85628637 return texture!=null?texture.texture:null;
85638638 }
85648639
8565
- public com.sun.opengl.util.texture.TextureData GetTextureData(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception
8640
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
85668641 {
8567
- CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution);
8642
+ CacheTexture texture = GetCacheTexture(tex, bump, resolution);
85688643
85698644 return texture!=null?texture.texturedata:null;
85708645 }
85718646
8572
- boolean BindTexture(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception
8647
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
85738648 {
85748649 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
85758650 {
....@@ -8578,7 +8653,7 @@
85788653
85798654 //boolean newtex = false;
85808655
8581
- com.sun.opengl.util.texture.Texture texture = GetTexture(stream, tex, bump, resolution);
8656
+ com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
85828657
85838658 if (texture == null)
85848659 return false;
....@@ -8611,6 +8686,72 @@
86118686 return true; // Warning: not used.
86128687 }
86138688
8689
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8690
+ {
8691
+ try
8692
+ {
8693
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8694
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8695
+ ImageWriter writer = writers.next();
8696
+
8697
+ ImageWriteParam param = writer.getDefaultWriteParam();
8698
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8699
+ param.setCompressionQuality(quality);
8700
+
8701
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8702
+ writer.setOutput(ios);
8703
+ writer.write(null, new IIOImage(image, null, null), param);
8704
+
8705
+ byte[] data = baos.toByteArray();
8706
+ writer.dispose();
8707
+ return data;
8708
+ }
8709
+ catch (Exception e)
8710
+ {
8711
+ e.printStackTrace();
8712
+ return null;
8713
+ }
8714
+ }
8715
+
8716
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8717
+ {
8718
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8719
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8720
+ ImageReader reader = writers.next();
8721
+
8722
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8723
+
8724
+ ImageReadParam param = reader.getDefaultReadParam();
8725
+ param.setDestination(bim);
8726
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8727
+
8728
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8729
+ reader.setInput(ios);
8730
+ BufferedImage bim2 = reader.read(0, param);
8731
+ reader.dispose();
8732
+
8733
+// WritableRaster raster = bim2.getRaster();
8734
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8735
+// byte[] bytes = data.getData();
8736
+//
8737
+// int[] pixels = new int[bytes.length/3];
8738
+// for (int i=pixels.length; --i>=0;)
8739
+// {
8740
+// int i3 = i*3;
8741
+// pixels[i] = 0xFF;
8742
+// pixels[i] <<= 8;
8743
+// pixels[i] |= bytes[i3+2] & 0xFF;
8744
+// pixels[i] <<= 8;
8745
+// pixels[i] |= bytes[i3+1] & 0xFF;
8746
+// pixels[i] <<= 8;
8747
+// pixels[i] |= bytes[i3] & 0xFF;
8748
+// }
8749
+//
8750
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8751
+
8752
+ return bim;
8753
+ }
8754
+
86148755 ShadowBuffer shadowPBuf;
86158756 AntialiasBuffer antialiasPBuf;
86168757 int MAXSTACK;
....@@ -8803,7 +8944,7 @@
88038944
88048945 if (cubemap == null)
88058946 {
8806
- LoadEnvy(5);
8947
+ //LoadEnvy(1);
88078948 }
88088949
88098950 //cubemap.enable();
....@@ -9090,37 +9231,58 @@
90909231 cubemap = null;
90919232 return;
90929233 case 1:
9093
- name = "cubemaps/box_";
9094
- ext = "png";
9234
+ name = "cubemaps/rgb/";
9235
+ ext = "jpg";
90959236 reverseUP = false;
90969237 break;
90979238 case 2:
9098
- name = "cubemaps/uffizi_";
9099
- ext = "png";
9100
- break; // reverseUP = true; break;
9239
+ name = "cubemaps/uffizi/";
9240
+ ext = "jpg";
9241
+ reverseUP = false;
9242
+ break;
91019243 case 3:
9102
- name = "cubemaps/CloudyHills_";
9103
- ext = "tga";
9244
+ name = "cubemaps/CloudyHills/";
9245
+ ext = "jpg";
91049246 reverseUP = false;
91059247 break;
91069248 case 4:
9107
- name = "cubemaps/cornell_";
9249
+ name = "cubemaps/cornell/";
91089250 ext = "png";
91099251 reverseUP = false;
91109252 break;
9253
+ case 5:
9254
+ name = "cubemaps/skycube/";
9255
+ ext = "jpg";
9256
+ reverseUP = false;
9257
+ break;
9258
+ case 6:
9259
+ name = "cubemaps/SaintLazarusChurch3/";
9260
+ ext = "jpg";
9261
+ reverseUP = false;
9262
+ break;
9263
+ case 7:
9264
+ name = "cubemaps/Sodermalmsallen/";
9265
+ ext = "jpg";
9266
+ reverseUP = false;
9267
+ break;
9268
+ case 8:
9269
+ name = "cubemaps/Sodermalmsallen2/";
9270
+ ext = "jpg";
9271
+ reverseUP = false;
9272
+ break;
9273
+ case 9:
9274
+ name = "cubemaps/UnionSquare/";
9275
+ ext = "jpg";
9276
+ reverseUP = false;
9277
+ break;
91119278 default:
9112
- name = "cubemaps/rgb_";
9113
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9279
+ name = "cubemaps/box/";
9280
+ ext = "png"; /*mipmap = true;*/
9281
+ reverseUP = false;
91149282 break;
91159283 }
9116
-
9117
- try
9118
- {
9119
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
9120
- } catch (IOException e)
9121
- {
9122
- throw new RuntimeException(e);
9123
- }
9284
+
9285
+ LoadSkybox(name, ext, mipmap);
91249286 }
91259287
91269288 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -9152,8 +9314,12 @@
91529314 static double[] model = new double[16];
91539315 double[] camera2light = new double[16];
91549316 double[] light2camera = new double[16];
9155
- int newenvy = -1;
9156
- boolean envyoff = true; // false;
9317
+
9318
+ //int newenvy = -1;
9319
+ //boolean envyoff = false;
9320
+
9321
+ String loadedskyboxname;
9322
+
91579323 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
91589324 //float[] light0 = { 0,0,0 };
91599325 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9571,7 +9737,7 @@
95719737
95729738 if (renderCamera != lightCamera)
95739739 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9574
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
9740
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
95759741
95769742 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
95779743
....@@ -9587,7 +9753,7 @@
95879753
95889754 if (renderCamera != lightCamera)
95899755 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9590
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
9756
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
95919757
95929758 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
95939759
....@@ -9633,10 +9799,12 @@
96339799 rati = 1 / rati;
96349800 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
96359801 }
9636
- assert (newenvy == -1);
9802
+
9803
+ //assert (newenvy == -1);
9804
+
96379805 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
96389806 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9639
- DrawSkyBox(gl);
9807
+ DrawSkyBox(gl, (float)rati);
96409808 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
96419809 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
96429810 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10788,7 +10956,7 @@
1078810956 // if (parentcam != renderCamera) // not a light
1078910957 if (cam != lightCamera)
1079010958 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10791
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
10959
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1079210960
1079310961 for (int j = 0; j < 4; j++)
1079410962 {
....@@ -10803,7 +10971,7 @@
1080310971 // if (parentcam != renderCamera) // not a light
1080410972 if (cam != lightCamera)
1080510973 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10806
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
10974
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1080710975
1080810976 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1080910977
....@@ -10889,13 +11057,27 @@
1088911057 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1089011058 }
1089111059
10892
- if (newenvy > -1)
11060
+// if (newenvy > -1)
11061
+// {
11062
+// LoadEnvy(newenvy);
11063
+// }
11064
+//
11065
+// newenvy = -1;
11066
+
11067
+ if (object.skyboxname != null)
1089311068 {
10894
- LoadEnvy(newenvy);
11069
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11070
+ {
11071
+ LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11072
+ loadedskyboxname = object.skyboxname;
11073
+ }
1089511074 }
10896
-
10897
- newenvy = -1;
10898
-
11075
+ else
11076
+ {
11077
+ cubemap = null;
11078
+ loadedskyboxname = null;
11079
+ }
11080
+
1089911081 ratio = ((double) getWidth()) / getHeight();
1090011082 //System.out.println("ratio = " + ratio);
1090111083
....@@ -10911,7 +11093,7 @@
1091111093
1091211094 if (!IsFrozen() && !ambientOcclusion)
1091311095 {
10914
- DrawSkyBox(gl);
11096
+ DrawSkyBox(gl, (float)ratio);
1091511097 }
1091611098
1091711099 //if (selection_view == -1)
....@@ -11065,7 +11247,7 @@
1106511247
1106611248 try
1106711249 {
11068
- BindTexture(null, NOISE_TEXTURE, false, 2);
11250
+ BindTexture(NOISE_TEXTURE, false, 2);
1106911251 }
1107011252 catch (Exception e)
1107111253 {
....@@ -11356,7 +11538,7 @@
1135611538 }
1135711539 }
1135811540
11359
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11541
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1136011542 {
1136111543 //gl.glDepthFunc(GL.GL_LEQUAL);
1136211544 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11364,24 +11546,21 @@
1136411546
1136511547 boolean texon = textureon;
1136611548
11367
- if (RENDERPROGRAM > 0)
11368
- {
11369
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11370
- textureon = false;
11371
- }
11549
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11550
+ textureon = false;
11551
+
1137211552 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1137311553 //System.out.println("ALLO");
1137411554 gl.glColorMask(false, false, false, false);
1137511555 DrawObject(gl);
11376
- if (RENDERPROGRAM > 0)
11377
- {
11378
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11379
- textureon = texon;
11380
- }
11556
+
11557
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11558
+ textureon = texon;
11559
+
1138111560 gl.glColorMask(true, true, true, true);
1138211561
1138311562 gl.glDepthFunc(GL.GL_EQUAL);
11384
- //gl.glDepthMask(false);
11563
+ gl.glDepthMask(false);
1138511564 }
1138611565
1138711566 if (false) // DrawMode() == SHADOW)
....@@ -11721,20 +11900,32 @@
1172111900 ReleaseTextures(DEFAULT_TEXTURES);
1172211901
1172311902 if (CLEANCACHE)
11724
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11903
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1172511904 {
11726
- String tex = e.nextElement();
11905
+ cTexture tex = e.nextElement();
1172711906
1172811907 // System.out.println("Texture --------- " + tex);
1172911908
11730
- if (tex.equals("WHITE_NOISE"))
11909
+ if (tex.equals("WHITE_NOISE:"))
1173111910 continue;
1173211911
1173311912 if (!usedtextures.contains(tex))
1173411913 {
11914
+ CacheTexture gettex = texturepigment.get(tex);
1173511915 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11736
- textures.get(tex).texture.dispose();
11737
- textures.remove(tex);
11916
+ if (gettex != null)
11917
+ {
11918
+ gettex.texture.dispose();
11919
+ texturepigment.remove(tex);
11920
+ }
11921
+
11922
+ gettex = texturebump.get(tex);
11923
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11924
+ if (gettex != null)
11925
+ {
11926
+ gettex.texture.dispose();
11927
+ texturebump.remove(tex);
11928
+ }
1173811929 }
1173911930 }
1174011931 }
....@@ -12262,8 +12453,76 @@
1226212453
1226312454 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1226412455
12456
+ String program0 =
12457
+ // Min shader
12458
+ "!!ARBfp1.0\n" +
12459
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12460
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12461
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12462
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12463
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12464
+ "PARAM light2cam0 = program.env[10];" +
12465
+ "PARAM light2cam1 = program.env[11];" +
12466
+ "PARAM light2cam2 = program.env[12];" +
12467
+ "TEMP temp;" +
12468
+ "TEMP light;" +
12469
+ "TEMP ndotl;" +
12470
+ "TEMP normal;" +
12471
+ "TEMP depth;" +
12472
+ "TEMP eye;" +
12473
+ "TEMP pos;" +
12474
+
12475
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12476
+ Normalize("normal") +
12477
+ "MOV light, state.light[0].position;" +
12478
+ "DP3 ndotl.x, light, normal;" +
12479
+
12480
+ // shadow
12481
+ "MOV pos, fragment.texcoord[1];" +
12482
+ "MOV temp, pos;" +
12483
+ ShadowTextureFetch("depth", "temp", "1") +
12484
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12485
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12486
+
12487
+ // No shadow when out of frustum
12488
+ //"SGE temp.y, depth.z, zero123.y;" +
12489
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12490
+
12491
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12492
+
12493
+ // Backlit
12494
+ "MOV pos.w, zero123.y;" +
12495
+ "DP4 eye.x, pos, light2cam0;" +
12496
+ "DP4 eye.y, pos, light2cam1;" +
12497
+ "DP4 eye.z, pos, light2cam2;" +
12498
+ Normalize("eye") +
12499
+
12500
+ "DP3 ndotl.y, -eye, normal;" +
12501
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12502
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12503
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12504
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12505
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12506
+
12507
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12508
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12509
+
12510
+ // Pigment
12511
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12512
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12513
+ "MUL temp, temp, ndotl.x;" +
12514
+
12515
+ "MUL temp, temp, zero123.z;" +
12516
+
12517
+ //"MUL temp, temp, ndotl.y;" +
12518
+
12519
+ "MOV temp.w, zero123.y;" + // reset alpha
12520
+ "MOV result.color, temp;" +
12521
+ "END";
12522
+
1226512523 String program =
1226612524 "!!ARBfp1.0\n" +
12525
+
1226712526 //"OPTION ARB_fragment_program_shadow;" +
1226812527 "PARAM light2cam0 = program.env[10];" +
1226912528 "PARAM light2cam1 = program.env[11];" +
....@@ -12378,8 +12637,7 @@
1237812637 "TEMP shininess;" +
1237912638 "\n" +
1238012639 "MOV texSamp, one;" +
12381
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12382
-
12640
+
1238312641 "MOV mapgrid.x, one2048th.x;" +
1238412642 "MOV temp, fragment.texcoord[1];" +
1238512643 /*
....@@ -12400,20 +12658,20 @@
1240012658 "MUL temp, floor, mapgrid.x;" +
1240112659 //"TEX depth0, temp, texture[1], 2D;" +
1240212660 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12403
- TextureFetch("depth0", "temp", "1") +
12661
+ ShadowTextureFetch("depth0", "temp", "1") +
1240412662 "") +
1240512663 "ADD temp.x, temp.x, mapgrid.x;" +
1240612664 //"TEX depth1, temp, texture[1], 2D;" +
1240712665 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12408
- TextureFetch("depth1", "temp", "1") +
12666
+ ShadowTextureFetch("depth1", "temp", "1") +
1240912667 "") +
1241012668 "ADD temp.y, temp.y, mapgrid.x;" +
1241112669 //"TEX depth2, temp, texture[1], 2D;" +
12412
- TextureFetch("depth2", "temp", "1") +
12670
+ ShadowTextureFetch("depth2", "temp", "1") +
1241312671 "SUB temp.x, temp.x, mapgrid.x;" +
1241412672 //"TEX depth3, temp, texture[1], 2D;" +
1241512673 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12416
- TextureFetch("depth3", "temp", "1") +
12674
+ ShadowTextureFetch("depth3", "temp", "1") +
1241712675 "") +
1241812676 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1241912677 //"MOV params, material;" +
....@@ -12784,10 +13042,10 @@
1278413042 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1278513043 "") +
1278613044
12787
- // display shadow only (bump == 0)
13045
+ // display shadow only (fakedepth == 0)
1278813046 "SUB temp.x, half.x, shadow.x;" +
1278913047 "MOV temp.y, -params5.z;" + // params6.x;" +
12790
- "SLT temp.z, temp.y, -one2048th.x;" +
13048
+ "SLT temp.z, temp.y, -c256i.x;" +
1279113049 "SUB temp.y, one.x, temp.z;" +
1279213050 "MUL temp.x, temp.x, temp.y;" +
1279313051 "KIL temp.x;" +
....@@ -13211,25 +13469,26 @@
1321113469 return out;
1321213470 }
1321313471
13214
- String TextureFetch(String dest, String src, String unit)
13472
+ // Also does frustum culling
13473
+ String ShadowTextureFetch(String dest, String src, String unit)
1321513474 {
1321613475 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1321713476 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1321813477 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13478
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13479
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1321913480 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13220
- "SLT " + src + ".z, " + src + ".x, one.x;" +
13221
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13222
- "SLT " + src + ".z, " + src + ".y, one.x;" +
13223
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13481
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13482
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1322413483 //"SWZ buffer, temp, w,w,w,w;";
13225
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13484
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1322613485 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1322713486 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1322813487 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13229
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13488
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1323013489
13231
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13232
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13490
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13491
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1323313492 }
1323413493
1323513494 String Shadow(String depth, String shadow)
....@@ -13276,7 +13535,7 @@
1327613535 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1327713536 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1327813537
13279
- // No shadow when out of frustrum
13538
+ // No shadow when out of frustum
1328013539 "SGE temp.x, " + depth + ".z, one.z;" +
1328113540 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1328213541 "";
....@@ -14074,14 +14333,15 @@
1407414333 drag = false;
1407514334 //System.out.println("Mouse DOWN");
1407614335 editObj = false;
14077
- ClickInfo info = new ClickInfo();
14078
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14079
- info.pane = this;
14080
- info.camera = renderCamera;
14081
- info.x = x;
14082
- info.y = y;
14083
- info.modifiers = modifiersex;
14084
- editObj = object.doEditClick(info, 0);
14336
+ //ClickInfo info = new ClickInfo();
14337
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14338
+ object.clickInfo.pane = this;
14339
+ object.clickInfo.camera = renderCamera;
14340
+ object.clickInfo.x = x;
14341
+ object.clickInfo.y = y;
14342
+ object.clickInfo.modifiers = modifiersex;
14343
+ editObj = object.doEditClick(//info,
14344
+ 0);
1408514345 if (!editObj)
1408614346 {
1408714347 hasMarquee = true;
....@@ -14481,15 +14741,16 @@
1448114741 if (editObj)
1448214742 {
1448314743 drag = true;
14484
- ClickInfo info = new ClickInfo();
14485
- info.bounds.setBounds(0, 0,
14744
+ //ClickInfo info = new ClickInfo();
14745
+ object.clickInfo.bounds.setBounds(0, 0,
1448614746 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14487
- info.pane = this;
14488
- info.camera = renderCamera;
14489
- info.x = x;
14490
- info.y = y;
14491
- object.GetWindow().copy
14492
- .doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
14747
+ object.clickInfo.pane = this;
14748
+ object.clickInfo.camera = renderCamera;
14749
+ object.clickInfo.x = x;
14750
+ object.clickInfo.y = y;
14751
+ object //.GetWindow().copy
14752
+ .doEditDrag(//info,
14753
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1449314754 } else
1449414755 {
1449514756 if (x < startX)
....@@ -14638,24 +14899,27 @@
1463814899 }
1463914900 }
1464014901
14902
+// ClickInfo clickInfo = new ClickInfo();
14903
+
1464114904 public void mouseMoved(MouseEvent e)
1464214905 {
1464314906 //System.out.println("mouseMoved: " + e);
1464414907 if (isRenderer)
1464514908 return;
1464614909
14647
- ClickInfo ci = new ClickInfo();
14648
- ci.x = e.getX();
14649
- ci.y = e.getY();
14650
- ci.modifiers = e.getModifiersEx();
14651
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14652
- ci.pane = this;
14653
- ci.camera = renderCamera;
14910
+ // Mouse cursor feedback
14911
+ object.clickInfo.x = e.getX();
14912
+ object.clickInfo.y = e.getY();
14913
+ object.clickInfo.modifiers = e.getModifiersEx();
14914
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14915
+ object.clickInfo.pane = this;
14916
+ object.clickInfo.camera = renderCamera;
1465414917 if (!isRenderer)
1465514918 {
1465614919 //ObjEditor editWindow = object.editWindow;
1465714920 //Object3D copy = editWindow.copy;
14658
- if (object.doEditClick(ci, 0))
14921
+ if (object.doEditClick(//clickInfo,
14922
+ 0))
1465914923 {
1466014924 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1466114925 } else
....@@ -14927,7 +15191,8 @@
1492715191 // break;
1492815192 case 'T':
1492915193 CACHETEXTURE ^= true;
14930
- textures.clear();
15194
+ texturepigment.clear();
15195
+ texturebump.clear();
1493115196 // repaint();
1493215197 break;
1493315198 case 'Y':
....@@ -15104,20 +15369,24 @@
1510415369 OCCLUSION_CULLING ^= true;
1510515370 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1510615371 break;
15107
- case '0': envyoff ^= true; repaint(); break;
15372
+ //case '0': envyoff ^= true; repaint(); break;
1510815373 case '1':
1510915374 case '2':
1511015375 case '3':
1511115376 case '4':
1511215377 case '5':
15113
- newenvy = Character.getNumericValue(key);
15114
- repaint();
15115
- break;
1511615378 case '6':
1511715379 case '7':
1511815380 case '8':
1511915381 case '9':
15120
- BGcolor = (key - '6')/3.f;
15382
+ if (true) // envyoff)
15383
+ {
15384
+ BGcolor = (key - '1')/8.f;
15385
+ }
15386
+ else
15387
+ {
15388
+ //newenvy = Character.getNumericValue(key);
15389
+ }
1512115390 repaint();
1512215391 break;
1512315392 case '!':
....@@ -15680,8 +15949,6 @@
1568015949
1568115950 int width = getBounds().width;
1568215951 int height = getBounds().height;
15683
- ClickInfo info = new ClickInfo();
15684
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1568515952 //Image img = CreateImage(width, height);
1568615953 //System.out.println("width = " + width + "; height = " + height + "\n");
1568715954
....@@ -15758,31 +16025,37 @@
1575816025 }
1575916026 if (object != null && !hasMarquee)
1576016027 {
16028
+ if (object.clickInfo == null)
16029
+ object.clickInfo = new ClickInfo();
16030
+ ClickInfo info = object.clickInfo;
16031
+ //ClickInfo info = new ClickInfo();
16032
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16033
+
1576116034 if (isRenderer)
1576216035 {
15763
- info.flags++;
16036
+ object.clickInfo.flags++;
1576416037 double frameAspect = (double) width / (double) height;
1576516038 if (frameAspect > renderCamera.aspect)
1576616039 {
1576716040 int desired = (int) ((double) height * renderCamera.aspect);
15768
- info.bounds.width -= width - desired;
15769
- info.bounds.x += (width - desired) / 2;
16041
+ object.clickInfo.bounds.width -= width - desired;
16042
+ object.clickInfo.bounds.x += (width - desired) / 2;
1577016043 } else
1577116044 {
1577216045 int desired = (int) ((double) width / renderCamera.aspect);
15773
- info.bounds.height -= height - desired;
15774
- info.bounds.y += (height - desired) / 2;
16046
+ object.clickInfo.bounds.height -= height - desired;
16047
+ object.clickInfo.bounds.y += (height - desired) / 2;
1577516048 }
1577616049 }
1577716050
15778
- info.g = gr;
15779
- info.camera = renderCamera;
16051
+ object.clickInfo.g = gr;
16052
+ object.clickInfo.camera = renderCamera;
1578016053 /*
1578116054 // Memory intensive (brep.verticescopy)
1578216055 if (!(object instanceof Composite))
1578316056 object.draw(info, 0, false); // SLOW :
1578416057 */
15785
- if (!isRenderer)
16058
+ if (!isRenderer) // && drag)
1578616059 {
1578716060 Grafreed.Assert(object != null);
1578816061 Grafreed.Assert(object.selection != null);
....@@ -15790,9 +16063,9 @@
1579016063 {
1579116064 int hitSomething = object.selection.get(0).hitSomething;
1579216065
15793
- info.DX = 0;
15794
- info.DY = 0;
15795
- info.W = 1;
16066
+ object.clickInfo.DX = 0;
16067
+ object.clickInfo.DY = 0;
16068
+ object.clickInfo.W = 1;
1579616069 if (hitSomething == Object3D.hitCenter)
1579716070 {
1579816071 info.DX = X;
....@@ -15804,7 +16077,8 @@
1580416077 info.DY -= info.bounds.height/2;
1580516078 }
1580616079
15807
- object.drawEditHandles(info, 0);
16080
+ object.drawEditHandles(//info,
16081
+ 0);
1580816082
1580916083 if (drag && (X != 0 || Y != 0))
1581016084 {
....@@ -15817,7 +16091,7 @@
1581716091 gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
1581816092 break;
1581916093 case Object3D.hitScale: gr.setColor(Color.cyan);
15820
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16094
+ gr.drawLine(X, Y, 0, 0);
1582116095 break;
1582216096 }
1582316097
....@@ -16303,6 +16577,8 @@
1630316577 private /*static*/ boolean firstime;
1630416578 private /*static*/ cVector newView = new cVector();
1630516579 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16580
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16581
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1630616582 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1630716583 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1630816584 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16315,29 +16591,66 @@
1631516591 {
1631616592 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1631716593
16594
+ int usedsuf = 0;
16595
+
1631816596 for (int i = 0; i < suffixes.length; i++)
1631916597 {
16320
- String resourceName = basename + suffixes[i] + "." + suffix;
16321
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16322
- mipmapped,
16323
- FileUtil.getFileSuffix(resourceName));
16324
- if (data == null)
16598
+ String[] suffixe = suffixes;
16599
+ String[] fallback = suffixes2;
16600
+ String[] fallfallback = suffixes3;
16601
+
16602
+ for (int c=usedsuf; --c>=0;)
1632516603 {
16326
- throw new IOException("Unable to load texture " + resourceName);
16604
+// String[] temp = suffixe;
16605
+// suffixe = fallback;
16606
+// fallback = fallfallback;
16607
+// fallfallback = temp;
1632716608 }
16609
+
16610
+ String resourceName = basename + suffixe[i] + "." + suffix;
16611
+ TextureData data;
16612
+
16613
+ try
16614
+ {
16615
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16616
+ mipmapped,
16617
+ FileUtil.getFileSuffix(resourceName));
16618
+ }
16619
+ catch (Exception e)
16620
+ {
16621
+ try
16622
+ {
16623
+ resourceName = basename + fallback[i] + "." + suffix;
16624
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16625
+ mipmapped,
16626
+ FileUtil.getFileSuffix(resourceName));
16627
+ }
16628
+ catch (Exception e2)
16629
+ {
16630
+ resourceName = basename + fallfallback[i] + "." + suffix;
16631
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16632
+ mipmapped,
16633
+ FileUtil.getFileSuffix(resourceName));
16634
+ }
16635
+ }
16636
+
1632816637 //System.out.println("Target = " + targets[i]);
1632916638 cubemap.updateImage(data, targets[i]);
1633016639 }
1633116640
1633216641 return cubemap;
1633316642 }
16643
+
1633416644 int bigsphere = -1;
1633516645
1633616646 float BGcolor = 0.5f;
1633716647
16338
- private void DrawSkyBox(GL gl)
16648
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16649
+
16650
+ private void DrawSkyBox(GL gl, float ratio)
1633916651 {
16340
- if (envyoff || cubemap == null)
16652
+ if (//envyoff ||
16653
+ cubemap == null)
1634116654 {
1634216655 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1634316656 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16352,7 +16665,17 @@
1635216665 // Compensates for ExaminerViewer's modification of modelview matrix
1635316666 gl.glMatrixMode(GL.GL_MODELVIEW);
1635416667 gl.glLoadIdentity();
16668
+ gl.glScalef(1,ratio,1);
1635516669
16670
+ colorV[0] = 2;
16671
+ colorV[1] = 2;
16672
+ colorV[2] = 2;
16673
+ colorV[3] = 1;
16674
+ gl.glDisable(gl.GL_COLOR_MATERIAL);
16675
+ gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16676
+
16677
+ gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16678
+
1635616679 //gl.glActiveTexture(GL.GL_TEXTURE1);
1635716680 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1635816681
....@@ -16365,7 +16688,7 @@
1636516688 // GL_NORMAL_MAP texgen mode. Temporarily enabling lighting
1636616689 // causes the normals to be sent down. Thanks to Ken Dyke.
1636716690 //gl.glEnable(GL.GL_LIGHTING);
16368
- gl.glDisable(GL.GL_LIGHTING);
16691
+ gl.glEnable(GL.GL_LIGHTING);
1636916692
1637016693 gl.glTexGeni(GL.GL_S, GL.GL_TEXTURE_GEN_MODE, GL.GL_NORMAL_MAP);
1637116694 gl.glTexGeni(GL.GL_T, GL.GL_TEXTURE_GEN_MODE, GL.GL_NORMAL_MAP);
....@@ -16384,6 +16707,7 @@
1638416707 {
1638516708 gl.glScalef(1.0f, -1.0f, 1.0f);
1638616709 }
16710
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1638716711 gl.glMultMatrixd(viewrot_1, 0);
1638816712 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1638916713 //viewer.updateInverseRotation(gl);
....@@ -16642,7 +16966,7 @@
1664216966 //new Exception().printStackTrace();
1664316967 System.out.println("select buffer init");
1664416968 // Use debug pipeline
16645
- drawable.setGL(new DebugGL(drawable.getGL()));
16969
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1664616970
1664716971 GL gl = drawable.getGL();
1664816972