Normand Briere
2019-07-28 d7fd07756f4095cb87dc25d89fcffcbda092e2cf
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,13 @@
91529314 static double[] model = new double[16];
91539315 double[] camera2light = new double[16];
91549316 double[] light2camera = new double[16];
9155
- int newenvy = -1;
9317
+
9318
+ //int newenvy = -1;
91569319 boolean envyoff = true; // false;
9320
+ String skyboxname = "";
9321
+ String skyboxext;
9322
+ String loadedskyboxname = "";
9323
+
91579324 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
91589325 //float[] light0 = { 0,0,0 };
91599326 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9571,7 +9738,7 @@
95719738
95729739 if (renderCamera != lightCamera)
95739740 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9574
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
9741
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
95759742
95769743 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
95779744
....@@ -9587,7 +9754,7 @@
95879754
95889755 if (renderCamera != lightCamera)
95899756 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9590
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
9757
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
95919758
95929759 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
95939760
....@@ -9633,10 +9800,12 @@
96339800 rati = 1 / rati;
96349801 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
96359802 }
9636
- assert (newenvy == -1);
9803
+
9804
+ //assert (newenvy == -1);
9805
+
96379806 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
96389807 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9639
- DrawSkyBox(gl);
9808
+ DrawSkyBox(gl, (float)rati);
96409809 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
96419810 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
96429811 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10788,7 +10957,7 @@
1078810957 // if (parentcam != renderCamera) // not a light
1078910958 if (cam != lightCamera)
1079010959 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10791
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
10960
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1079210961
1079310962 for (int j = 0; j < 4; j++)
1079410963 {
....@@ -10803,7 +10972,7 @@
1080310972 // if (parentcam != renderCamera) // not a light
1080410973 if (cam != lightCamera)
1080510974 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10806
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
10975
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1080710976
1080810977 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1080910978
....@@ -10889,13 +11058,19 @@
1088911058 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1089011059 }
1089111060
10892
- if (newenvy > -1)
11061
+// if (newenvy > -1)
11062
+// {
11063
+// LoadEnvy(newenvy);
11064
+// }
11065
+//
11066
+// newenvy = -1;
11067
+
11068
+ if (!skyboxname.equals(this.loadedskyboxname))
1089311069 {
10894
- LoadEnvy(newenvy);
11070
+ LoadSkybox(skyboxname + "/", skyboxext, false);
11071
+ loadedskyboxname = skyboxname;
1089511072 }
10896
-
10897
- newenvy = -1;
10898
-
11073
+
1089911074 ratio = ((double) getWidth()) / getHeight();
1090011075 //System.out.println("ratio = " + ratio);
1090111076
....@@ -10911,7 +11086,7 @@
1091111086
1091211087 if (!IsFrozen() && !ambientOcclusion)
1091311088 {
10914
- DrawSkyBox(gl);
11089
+ DrawSkyBox(gl, (float)ratio);
1091511090 }
1091611091
1091711092 //if (selection_view == -1)
....@@ -11065,7 +11240,7 @@
1106511240
1106611241 try
1106711242 {
11068
- BindTexture(null, NOISE_TEXTURE, false, 2);
11243
+ BindTexture(NOISE_TEXTURE, false, 2);
1106911244 }
1107011245 catch (Exception e)
1107111246 {
....@@ -11356,7 +11531,7 @@
1135611531 }
1135711532 }
1135811533
11359
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11534
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1136011535 {
1136111536 //gl.glDepthFunc(GL.GL_LEQUAL);
1136211537 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11364,24 +11539,21 @@
1136411539
1136511540 boolean texon = textureon;
1136611541
11367
- if (RENDERPROGRAM > 0)
11368
- {
11369
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11370
- textureon = false;
11371
- }
11542
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11543
+ textureon = false;
11544
+
1137211545 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1137311546 //System.out.println("ALLO");
1137411547 gl.glColorMask(false, false, false, false);
1137511548 DrawObject(gl);
11376
- if (RENDERPROGRAM > 0)
11377
- {
11378
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11379
- textureon = texon;
11380
- }
11549
+
11550
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11551
+ textureon = texon;
11552
+
1138111553 gl.glColorMask(true, true, true, true);
1138211554
1138311555 gl.glDepthFunc(GL.GL_EQUAL);
11384
- //gl.glDepthMask(false);
11556
+ gl.glDepthMask(false);
1138511557 }
1138611558
1138711559 if (false) // DrawMode() == SHADOW)
....@@ -11721,20 +11893,32 @@
1172111893 ReleaseTextures(DEFAULT_TEXTURES);
1172211894
1172311895 if (CLEANCACHE)
11724
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11896
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1172511897 {
11726
- String tex = e.nextElement();
11898
+ cTexture tex = e.nextElement();
1172711899
1172811900 // System.out.println("Texture --------- " + tex);
1172911901
11730
- if (tex.equals("WHITE_NOISE"))
11902
+ if (tex.equals("WHITE_NOISE:"))
1173111903 continue;
1173211904
1173311905 if (!usedtextures.contains(tex))
1173411906 {
11907
+ CacheTexture gettex = texturepigment.get(tex);
1173511908 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11736
- textures.get(tex).texture.dispose();
11737
- textures.remove(tex);
11909
+ if (gettex != null)
11910
+ {
11911
+ gettex.texture.dispose();
11912
+ texturepigment.remove(tex);
11913
+ }
11914
+
11915
+ gettex = texturebump.get(tex);
11916
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11917
+ if (gettex != null)
11918
+ {
11919
+ gettex.texture.dispose();
11920
+ texturebump.remove(tex);
11921
+ }
1173811922 }
1173911923 }
1174011924 }
....@@ -12262,8 +12446,76 @@
1226212446
1226312447 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1226412448
12449
+ String program0 =
12450
+ // Min shader
12451
+ "!!ARBfp1.0\n" +
12452
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12453
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12454
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12455
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12456
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12457
+ "PARAM light2cam0 = program.env[10];" +
12458
+ "PARAM light2cam1 = program.env[11];" +
12459
+ "PARAM light2cam2 = program.env[12];" +
12460
+ "TEMP temp;" +
12461
+ "TEMP light;" +
12462
+ "TEMP ndotl;" +
12463
+ "TEMP normal;" +
12464
+ "TEMP depth;" +
12465
+ "TEMP eye;" +
12466
+ "TEMP pos;" +
12467
+
12468
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12469
+ Normalize("normal") +
12470
+ "MOV light, state.light[0].position;" +
12471
+ "DP3 ndotl.x, light, normal;" +
12472
+
12473
+ // shadow
12474
+ "MOV pos, fragment.texcoord[1];" +
12475
+ "MOV temp, pos;" +
12476
+ ShadowTextureFetch("depth", "temp", "1") +
12477
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12478
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12479
+
12480
+ // No shadow when out of frustum
12481
+ //"SGE temp.y, depth.z, zero123.y;" +
12482
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12483
+
12484
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12485
+
12486
+ // Backlit
12487
+ "MOV pos.w, zero123.y;" +
12488
+ "DP4 eye.x, pos, light2cam0;" +
12489
+ "DP4 eye.y, pos, light2cam1;" +
12490
+ "DP4 eye.z, pos, light2cam2;" +
12491
+ Normalize("eye") +
12492
+
12493
+ "DP3 ndotl.y, -eye, normal;" +
12494
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12495
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12496
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12497
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12498
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12499
+
12500
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12501
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12502
+
12503
+ // Pigment
12504
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12505
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12506
+ "MUL temp, temp, ndotl.x;" +
12507
+
12508
+ "MUL temp, temp, zero123.z;" +
12509
+
12510
+ //"MUL temp, temp, ndotl.y;" +
12511
+
12512
+ "MOV temp.w, zero123.y;" + // reset alpha
12513
+ "MOV result.color, temp;" +
12514
+ "END";
12515
+
1226512516 String program =
1226612517 "!!ARBfp1.0\n" +
12518
+
1226712519 //"OPTION ARB_fragment_program_shadow;" +
1226812520 "PARAM light2cam0 = program.env[10];" +
1226912521 "PARAM light2cam1 = program.env[11];" +
....@@ -12378,8 +12630,7 @@
1237812630 "TEMP shininess;" +
1237912631 "\n" +
1238012632 "MOV texSamp, one;" +
12381
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12382
-
12633
+
1238312634 "MOV mapgrid.x, one2048th.x;" +
1238412635 "MOV temp, fragment.texcoord[1];" +
1238512636 /*
....@@ -12400,20 +12651,20 @@
1240012651 "MUL temp, floor, mapgrid.x;" +
1240112652 //"TEX depth0, temp, texture[1], 2D;" +
1240212653 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12403
- TextureFetch("depth0", "temp", "1") +
12654
+ ShadowTextureFetch("depth0", "temp", "1") +
1240412655 "") +
1240512656 "ADD temp.x, temp.x, mapgrid.x;" +
1240612657 //"TEX depth1, temp, texture[1], 2D;" +
1240712658 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12408
- TextureFetch("depth1", "temp", "1") +
12659
+ ShadowTextureFetch("depth1", "temp", "1") +
1240912660 "") +
1241012661 "ADD temp.y, temp.y, mapgrid.x;" +
1241112662 //"TEX depth2, temp, texture[1], 2D;" +
12412
- TextureFetch("depth2", "temp", "1") +
12663
+ ShadowTextureFetch("depth2", "temp", "1") +
1241312664 "SUB temp.x, temp.x, mapgrid.x;" +
1241412665 //"TEX depth3, temp, texture[1], 2D;" +
1241512666 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12416
- TextureFetch("depth3", "temp", "1") +
12667
+ ShadowTextureFetch("depth3", "temp", "1") +
1241712668 "") +
1241812669 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1241912670 //"MOV params, material;" +
....@@ -12784,10 +13035,10 @@
1278413035 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1278513036 "") +
1278613037
12787
- // display shadow only (bump == 0)
13038
+ // display shadow only (fakedepth == 0)
1278813039 "SUB temp.x, half.x, shadow.x;" +
1278913040 "MOV temp.y, -params5.z;" + // params6.x;" +
12790
- "SLT temp.z, temp.y, -one2048th.x;" +
13041
+ "SLT temp.z, temp.y, -c256i.x;" +
1279113042 "SUB temp.y, one.x, temp.z;" +
1279213043 "MUL temp.x, temp.x, temp.y;" +
1279313044 "KIL temp.x;" +
....@@ -13211,25 +13462,26 @@
1321113462 return out;
1321213463 }
1321313464
13214
- String TextureFetch(String dest, String src, String unit)
13465
+ // Also does frustum culling
13466
+ String ShadowTextureFetch(String dest, String src, String unit)
1321513467 {
1321613468 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1321713469 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1321813470 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13471
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13472
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1321913473 "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;" +
13474
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13475
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1322413476 //"SWZ buffer, temp, w,w,w,w;";
13225
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13477
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1322613478 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1322713479 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1322813480 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13229
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13481
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1323013482
13231
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13232
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13483
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13484
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1323313485 }
1323413486
1323513487 String Shadow(String depth, String shadow)
....@@ -13276,7 +13528,7 @@
1327613528 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1327713529 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1327813530
13279
- // No shadow when out of frustrum
13531
+ // No shadow when out of frustum
1328013532 "SGE temp.x, " + depth + ".z, one.z;" +
1328113533 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1328213534 "";
....@@ -14074,14 +14326,15 @@
1407414326 drag = false;
1407514327 //System.out.println("Mouse DOWN");
1407614328 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);
14329
+ //ClickInfo info = new ClickInfo();
14330
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14331
+ object.clickInfo.pane = this;
14332
+ object.clickInfo.camera = renderCamera;
14333
+ object.clickInfo.x = x;
14334
+ object.clickInfo.y = y;
14335
+ object.clickInfo.modifiers = modifiersex;
14336
+ editObj = object.doEditClick(//info,
14337
+ 0);
1408514338 if (!editObj)
1408614339 {
1408714340 hasMarquee = true;
....@@ -14481,15 +14734,16 @@
1448114734 if (editObj)
1448214735 {
1448314736 drag = true;
14484
- ClickInfo info = new ClickInfo();
14485
- info.bounds.setBounds(0, 0,
14737
+ //ClickInfo info = new ClickInfo();
14738
+ object.clickInfo.bounds.setBounds(0, 0,
1448614739 (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);
14740
+ object.clickInfo.pane = this;
14741
+ object.clickInfo.camera = renderCamera;
14742
+ object.clickInfo.x = x;
14743
+ object.clickInfo.y = y;
14744
+ object //.GetWindow().copy
14745
+ .doEditDrag(//info,
14746
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1449314747 } else
1449414748 {
1449514749 if (x < startX)
....@@ -14638,24 +14892,27 @@
1463814892 }
1463914893 }
1464014894
14895
+// ClickInfo clickInfo = new ClickInfo();
14896
+
1464114897 public void mouseMoved(MouseEvent e)
1464214898 {
1464314899 //System.out.println("mouseMoved: " + e);
1464414900 if (isRenderer)
1464514901 return;
1464614902
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;
14903
+ // Mouse cursor feedback
14904
+ object.clickInfo.x = e.getX();
14905
+ object.clickInfo.y = e.getY();
14906
+ object.clickInfo.modifiers = e.getModifiersEx();
14907
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14908
+ object.clickInfo.pane = this;
14909
+ object.clickInfo.camera = renderCamera;
1465414910 if (!isRenderer)
1465514911 {
1465614912 //ObjEditor editWindow = object.editWindow;
1465714913 //Object3D copy = editWindow.copy;
14658
- if (object.doEditClick(ci, 0))
14914
+ if (object.doEditClick(//clickInfo,
14915
+ 0))
1465914916 {
1466014917 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1466114918 } else
....@@ -14927,7 +15184,8 @@
1492715184 // break;
1492815185 case 'T':
1492915186 CACHETEXTURE ^= true;
14930
- textures.clear();
15187
+ texturepigment.clear();
15188
+ texturebump.clear();
1493115189 // repaint();
1493215190 break;
1493315191 case 'Y':
....@@ -15110,14 +15368,18 @@
1511015368 case '3':
1511115369 case '4':
1511215370 case '5':
15113
- newenvy = Character.getNumericValue(key);
15114
- repaint();
15115
- break;
1511615371 case '6':
1511715372 case '7':
1511815373 case '8':
1511915374 case '9':
15120
- BGcolor = (key - '6')/3.f;
15375
+ if (envyoff)
15376
+ {
15377
+ BGcolor = (key - '1')/8.f;
15378
+ }
15379
+ else
15380
+ {
15381
+ //newenvy = Character.getNumericValue(key);
15382
+ }
1512115383 repaint();
1512215384 break;
1512315385 case '!':
....@@ -15680,8 +15942,6 @@
1568015942
1568115943 int width = getBounds().width;
1568215944 int height = getBounds().height;
15683
- ClickInfo info = new ClickInfo();
15684
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1568515945 //Image img = CreateImage(width, height);
1568615946 //System.out.println("width = " + width + "; height = " + height + "\n");
1568715947
....@@ -15758,31 +16018,37 @@
1575816018 }
1575916019 if (object != null && !hasMarquee)
1576016020 {
16021
+ if (object.clickInfo == null)
16022
+ object.clickInfo = new ClickInfo();
16023
+ ClickInfo info = object.clickInfo;
16024
+ //ClickInfo info = new ClickInfo();
16025
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16026
+
1576116027 if (isRenderer)
1576216028 {
15763
- info.flags++;
16029
+ object.clickInfo.flags++;
1576416030 double frameAspect = (double) width / (double) height;
1576516031 if (frameAspect > renderCamera.aspect)
1576616032 {
1576716033 int desired = (int) ((double) height * renderCamera.aspect);
15768
- info.bounds.width -= width - desired;
15769
- info.bounds.x += (width - desired) / 2;
16034
+ object.clickInfo.bounds.width -= width - desired;
16035
+ object.clickInfo.bounds.x += (width - desired) / 2;
1577016036 } else
1577116037 {
1577216038 int desired = (int) ((double) width / renderCamera.aspect);
15773
- info.bounds.height -= height - desired;
15774
- info.bounds.y += (height - desired) / 2;
16039
+ object.clickInfo.bounds.height -= height - desired;
16040
+ object.clickInfo.bounds.y += (height - desired) / 2;
1577516041 }
1577616042 }
1577716043
15778
- info.g = gr;
15779
- info.camera = renderCamera;
16044
+ object.clickInfo.g = gr;
16045
+ object.clickInfo.camera = renderCamera;
1578016046 /*
1578116047 // Memory intensive (brep.verticescopy)
1578216048 if (!(object instanceof Composite))
1578316049 object.draw(info, 0, false); // SLOW :
1578416050 */
15785
- if (!isRenderer)
16051
+ if (!isRenderer) // && drag)
1578616052 {
1578716053 Grafreed.Assert(object != null);
1578816054 Grafreed.Assert(object.selection != null);
....@@ -15790,9 +16056,9 @@
1579016056 {
1579116057 int hitSomething = object.selection.get(0).hitSomething;
1579216058
15793
- info.DX = 0;
15794
- info.DY = 0;
15795
- info.W = 1;
16059
+ object.clickInfo.DX = 0;
16060
+ object.clickInfo.DY = 0;
16061
+ object.clickInfo.W = 1;
1579616062 if (hitSomething == Object3D.hitCenter)
1579716063 {
1579816064 info.DX = X;
....@@ -15804,7 +16070,8 @@
1580416070 info.DY -= info.bounds.height/2;
1580516071 }
1580616072
15807
- object.drawEditHandles(info, 0);
16073
+ object.drawEditHandles(//info,
16074
+ 0);
1580816075
1580916076 if (drag && (X != 0 || Y != 0))
1581016077 {
....@@ -15817,7 +16084,7 @@
1581716084 gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
1581816085 break;
1581916086 case Object3D.hitScale: gr.setColor(Color.cyan);
15820
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16087
+ gr.drawLine(X, Y, 0, 0);
1582116088 break;
1582216089 }
1582316090
....@@ -16335,7 +16602,9 @@
1633516602
1633616603 float BGcolor = 0.5f;
1633716604
16338
- private void DrawSkyBox(GL gl)
16605
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16606
+
16607
+ private void DrawSkyBox(GL gl, float ratio)
1633916608 {
1634016609 if (envyoff || cubemap == null)
1634116610 {
....@@ -16352,7 +16621,17 @@
1635216621 // Compensates for ExaminerViewer's modification of modelview matrix
1635316622 gl.glMatrixMode(GL.GL_MODELVIEW);
1635416623 gl.glLoadIdentity();
16624
+ gl.glScalef(1,ratio,1);
1635516625
16626
+ colorV[0] = 2;
16627
+ colorV[1] = 2;
16628
+ colorV[2] = 2;
16629
+ colorV[3] = 1;
16630
+ gl.glDisable(gl.GL_COLOR_MATERIAL);
16631
+ gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16632
+
16633
+ gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16634
+
1635616635 //gl.glActiveTexture(GL.GL_TEXTURE1);
1635716636 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1635816637
....@@ -16365,7 +16644,7 @@
1636516644 // GL_NORMAL_MAP texgen mode. Temporarily enabling lighting
1636616645 // causes the normals to be sent down. Thanks to Ken Dyke.
1636716646 //gl.glEnable(GL.GL_LIGHTING);
16368
- gl.glDisable(GL.GL_LIGHTING);
16647
+ gl.glEnable(GL.GL_LIGHTING);
1636916648
1637016649 gl.glTexGeni(GL.GL_S, GL.GL_TEXTURE_GEN_MODE, GL.GL_NORMAL_MAP);
1637116650 gl.glTexGeni(GL.GL_T, GL.GL_TEXTURE_GEN_MODE, GL.GL_NORMAL_MAP);
....@@ -16642,7 +16921,7 @@
1664216921 //new Exception().printStackTrace();
1664316922 System.out.println("select buffer init");
1664416923 // Use debug pipeline
16645
- drawable.setGL(new DebugGL(drawable.getGL()));
16924
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1664616925
1664716926 GL gl = drawable.getGL();
1664816927