Normand Briere
2019-08-20 564f4d12d93813b5d680fc24d4f118c3886d96ed
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;
....@@ -73,7 +110,11 @@
73110 //private Mat4f spotlightTransform = new Mat4f();
74111 //private Mat4f spotlightInverseTransform = new Mat4f();
75112 static GLContext glcontext = null;
76
- /*static*/ com.sun.opengl.util.texture.Texture cubemap;
113
+ /*static*/ com.sun.opengl.util.texture.Texture cubemap; // Either custom or rgb
114
+ /*static*/ com.sun.opengl.util.texture.Texture cubemapcustom;
115
+ /*static*/ com.sun.opengl.util.texture.Texture cubemaprgb;
116
+ boolean transformMode;
117
+
77118 boolean reverseUP = false;
78119 static boolean frozen = false;
79120 boolean enablebackspace = false; // patch for back buffer refresh
....@@ -127,7 +168,7 @@
127168
128169
129170 // OPTIONS
130
- boolean Skinshader = true;
171
+ boolean Skinshader = false; // true;
131172 boolean cameraLight = false;
132173 boolean UVdebug = false;
133174 boolean Udebug = false;
....@@ -136,7 +177,7 @@
136177 static boolean doublesided = false; // true; // reversed normals are awful for conformance
137178 boolean anisotropy = true;
138179 boolean softshadow = true; // slower but better false;
139
- boolean opacityhalo = false;
180
+ boolean opacityhalo = false; // reverse the halo effect (e.g. glass)
140181
141182 boolean macromode = false;
142183
....@@ -150,6 +191,19 @@
150191 }
151192
152193 private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
194
+
195
+ public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException
196
+ {
197
+ try
198
+ {
199
+ return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
200
+ } catch (IOException e)
201
+ {
202
+ System.out.println("NAME = " + name);
203
+ e.printStackTrace(); // throw new RuntimeException(e);
204
+ return null;
205
+ }
206
+ }
153207
154208 void SetAsGLRenderer(boolean b)
155209 {
....@@ -169,7 +223,8 @@
169223
170224 SetCamera(cam);
171225
172
- SetLight(new Camera(new cVector(10, 10, -20)));
226
+ // Warning: not used.
227
+ SetLight(new Camera(new cVector(15, 10, -20)));
173228
174229 object = o;
175230
....@@ -1447,6 +1502,8 @@
14471502 gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
14481503 }
14491504
1505
+ float[] colorV = new float[4];
1506
+
14501507 void SetColor(Object3D obj, Vertex p0)
14511508 {
14521509 CameraPane display = this;
....@@ -1514,8 +1571,6 @@
15141571 {
15151572 return;
15161573 }
1517
-
1518
- float[] colorV = new float[3];
15191574
15201575 if (false) // marked)
15211576 {
....@@ -1764,7 +1819,7 @@
17641819
17651820 display.modelParams7[0] = 0;
17661821 display.modelParams7[1] = 1000;
1767
- display.modelParams7[2] = 0;
1822
+ display.modelParams7[2] = material.parallax;
17681823 display.modelParams7[3] = 0;
17691824
17701825 //display.modelParams6[0] = 100; // criss de bug de bump
....@@ -1997,9 +2052,9 @@
19972052 switch(viewcode)
19982053 {
19992054 case 0: return "main";
2000
- case 1: return "one";
2001
- case 2: return "two";
2002
- case 3: return "three";
2055
+ case 1: return "Red";
2056
+ case 2: return "Green";
2057
+ case 3: return "Blue";
20032058 case 4: return "light";
20042059 }
20052060
....@@ -2405,6 +2460,21 @@
24052460 return currentGL;
24062461 }
24072462
2463
+ static private BufferedImage CreateBim(TextureData texturedata)
2464
+ {
2465
+ Grafreed.Assert(texturedata != null);
2466
+
2467
+ int width = texturedata.getWidth();
2468
+ int height = texturedata.getHeight();
2469
+
2470
+ Buffer buffer = texturedata.getBuffer();
2471
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2472
+
2473
+ byte[] bytes = bytebuf.array();
2474
+
2475
+ return CreateBim(bytes, width, height);
2476
+ }
2477
+
24082478 /**/
24092479 class CacheTexture
24102480 {
....@@ -2413,18 +2483,20 @@
24132483
24142484 int resolution;
24152485
2416
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2486
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
24172487 {
2418
- texture = tex;
2488
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2489
+ texturedata = texdata;
24192490 resolution = res;
24202491 }
24212492 }
24222493 /**/
24232494
24242495 // TEXTURE static Texture texture;
2425
- static public java.util.Hashtable<String, CacheTexture> textures = new java.util.Hashtable<String, CacheTexture>();
2426
- static public java.util.Hashtable<BufferedImage, CacheTexture> bimtextures = new java.util.Hashtable<BufferedImage, CacheTexture>();
2427
- static public java.util.HashSet<String> usedtextures = new java.util.HashSet<String>();
2496
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2497
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2498
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2499
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
24282500
24292501 int pigmentdepth = 0;
24302502 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
....@@ -2432,10 +2504,10 @@
24322504 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
24332505 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
24342506 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2435
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2507
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
24362508 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
24372509
2438
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2510
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
24392511 {
24402512 TextureData texturedata = null;
24412513
....@@ -2445,7 +2517,7 @@
24452517 com.sun.opengl.util.texture.TextureIO.newTextureData(
24462518 getClass().getClassLoader().getResourceAsStream(name),
24472519 true,
2448
- com.sun.opengl.util.texture.TextureIO.PNG);
2520
+ GetFormat(name)); // com.sun.opengl.util.texture.TextureIO.PNG);
24492521 } catch (java.io.IOException e)
24502522 {
24512523 throw new javax.media.opengl.GLException(e);
....@@ -2454,16 +2526,16 @@
24542526 if (bump)
24552527 texturedata = ConvertBump(texturedata, false);
24562528
2457
- com.sun.opengl.util.texture.Texture texture =
2458
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2529
+// com.sun.opengl.util.texture.Texture texture =
2530
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
24592531
2460
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2461
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
2532
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2533
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
24622534
2463
- return texture;
2535
+ return texturedata;
24642536 }
24652537
2466
- com.sun.opengl.util.texture.Texture GetBimTexture(BufferedImage name, boolean bump)
2538
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
24672539 {
24682540 TextureData texturedata = null;
24692541
....@@ -2471,7 +2543,7 @@
24712543 {
24722544 texturedata =
24732545 com.sun.opengl.util.texture.TextureIO.newTextureData(
2474
- name,
2546
+ bim,
24752547 true);
24762548 } catch (Exception e)
24772549 {
....@@ -2480,14 +2552,8 @@
24802552
24812553 if (bump)
24822554 texturedata = ConvertBump(texturedata, false);
2483
-
2484
- com.sun.opengl.util.texture.Texture texture =
2485
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2486
-
2487
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2488
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
2489
-
2490
- return texture;
2555
+
2556
+ return texturedata;
24912557 }
24922558
24932559 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -7975,8 +8041,8 @@
79758041 pigment = null;
79768042 }
79778043
7978
- ReleaseTexture(bump, true);
7979
- ReleaseTexture(pigment, false);
8044
+ ReleaseTexture(tex, true);
8045
+ ReleaseTexture(tex, false);
79808046 }
79818047
79828048 public void ReleasePigmentTexture(cTexture tex) // INTERFACE
....@@ -8005,7 +8071,7 @@
80058071 pigment = null;
80068072 }
80078073
8008
- ReleaseTexture(pigment, false);
8074
+ ReleaseTexture(tex, false);
80098075 }
80108076
80118077 public void ReleaseBumpTexture(cTexture tex) // INTERFACE
....@@ -8034,10 +8100,10 @@
80348100 bump = null;
80358101 }
80368102
8037
- ReleaseTexture(bump, true);
8103
+ ReleaseTexture(tex, true);
80388104 }
80398105
8040
- void ReleaseTexture(String tex, boolean bump)
8106
+ void ReleaseTexture(cTexture tex, boolean bump)
80418107 {
80428108 if (// DrawMode() != 0 || /*tex == null ||*/
80438109 ambientOcclusion ) // || !textureon)
....@@ -8048,7 +8114,7 @@
80488114 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
80498115
80508116 if (tex != null)
8051
- texture = textures.get(tex);
8117
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
80528118
80538119 // //assert( texture != null );
80548120 // if (texture == null)
....@@ -8198,13 +8264,13 @@
81988264
81998265 if (tex == null)
82008266 {
8201
- BindTexture(null, null,false,resolution);
8267
+ BindTexture(null,false,resolution);
82028268 return;
82038269 }
82048270
82058271 String pigment = Object3D.GetPigment(tex);
82068272
8207
- usedtextures.add(pigment);
8273
+ usedtextures.add(tex);
82088274
82098275 //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
82108276 {
....@@ -8218,7 +8284,7 @@
82188284 }
82198285
82208286 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8221
- BindTexture(tex.pigmenttexture, pigment, false, resolution);
8287
+ BindTexture(tex, false, resolution);
82228288 }
82238289
82248290 /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8231,13 +8297,13 @@
82318297
82328298 if (tex == null)
82338299 {
8234
- BindTexture(null, null,true,resolution);
8300
+ BindTexture(null,true,resolution);
82358301 return;
82368302 }
82378303
82388304 String bump = Object3D.GetBump(tex);
82398305
8240
- usedtextures.add(bump);
8306
+ usedtextures.add(tex);
82418307
82428308 //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
82438309 {
....@@ -8251,7 +8317,7 @@
82518317 }
82528318
82538319 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8254
- BindTexture(tex.bumptexture, bump, true, resolution);
8320
+ BindTexture(tex, true, resolution);
82558321 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
82568322 }
82578323
....@@ -8275,13 +8341,19 @@
82758341 return fileExists;
82768342 }
82778343
8278
- CacheTexture GetCacheTexture(java.awt.image.BufferedImage bim, String tex, boolean bump, int resolution) throws Exception
8344
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
82798345 {
82808346 CacheTexture texturecache = null;
82818347
82828348 if (tex != null)
82838349 {
8284
- String texname = tex;
8350
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8351
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
8352
+
8353
+ if (texname.equals("") && texdata == null)
8354
+ {
8355
+ return null;
8356
+ }
82858357
82868358 String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
82878359
....@@ -8291,29 +8363,46 @@
82918363 // else
82928364 // if (!texname.startsWith("/"))
82938365 // texname = "/Users/nbriere/Textures/" + texname;
8294
- if (!FileExists(tex))
8366
+ if (!FileExists(texname) && !texname.startsWith("@"))
82958367 {
82968368 texname = fallbackTextureName;
82978369 }
82988370
82998371 if (CACHETEXTURE)
83008372 {
8301
- if (bim == null)
8302
- texturecache = textures.get(texname); // TEXTURE CACHE
8373
+ if (texdata == null)
8374
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
83038375 else
8304
- texturecache = bimtextures.get(bim); // TEXTURE CACHE
8376
+ texturecache = bimtextures.get(texdata);
83058377 }
83068378
8307
- if (texturecache == null || texturecache.resolution < resolution)
8379
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
83088380 {
83098381 TextureData texturedata = null;
83108382
8311
- if (bim == null)
8383
+ if (texdata != null && textureon)
83128384 {
8385
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
83138386
8387
+ try
8388
+ {
8389
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8390
+ }
8391
+ catch (Exception e)
8392
+ {
8393
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8394
+ }
8395
+
8396
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8397
+ bimtextures.put(texdata, texturecache);
8398
+
8399
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8400
+
8401
+ //Object bim2 = CreateBim(texturecache.texturedata);
8402
+ //bim2 = bim;
83148403 }
83158404 else
8316
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8405
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
83178406 {
83188407 assert(!bump);
83198408 // if (bump)
....@@ -8324,19 +8413,23 @@
83248413 // }
83258414 // else
83268415 // {
8327
- texturecache = textures.get(tex);
8416
+ // texturecache = textures.get(texname); // suspicious
83288417 if (texturecache == null)
83298418 {
83308419 texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
83318420 }
8421
+ else
8422
+ new Exception().printStackTrace();
83328423 // }
83338424 } else
8334
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8425
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
83358426 {
83368427 assert(bump);
8337
- texturecache = textures.get(tex);
8428
+ // texturecache = textures.get(texname); // suspicious
83388429 if (texturecache == null)
83398430 texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8431
+ else
8432
+ new Exception().printStackTrace();
83408433 } else
83418434 {
83428435 //if (tex.equals("IMMORTAL"))
....@@ -8344,11 +8437,22 @@
83448437 // texture = GetResourceTexture("default.png");
83458438 //} else
83468439 //{
8347
- if (tex.equals("WHITE_NOISE"))
8440
+ if (texname.endsWith("WHITE_NOISE"))
83488441 {
8349
- texturecache = textures.get(tex);
8442
+ // texturecache = textures.get(texname); // suspicious
83508443 if (texturecache == null)
83518444 texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8445
+ else
8446
+ new Exception().printStackTrace();
8447
+ } else
8448
+ {
8449
+ if (texname.startsWith("@"))
8450
+ {
8451
+ // texturecache = textures.get(texname); // suspicious
8452
+ if (texturecache == null)
8453
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8454
+ else
8455
+ new Exception().printStackTrace();
83528456 } else
83538457 {
83548458 if (textureon)
....@@ -8407,14 +8511,15 @@
84078511 if (texturedata == null)
84088512 throw new Exception();
84098513
8410
- texturecache = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8514
+ texturecache = new CacheTexture(texturedata,resolution);
84118515 //texture = GetTexture(tex, bump);
84128516 }
8517
+ }
84138518 }
84148519 //}
84158520 }
84168521
8417
- if (/*CACHETEXTURE &&*/ texturecache != null && textureon)
8522
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
84188523 {
84198524 //return false;
84208525
....@@ -8436,52 +8541,17 @@
84368541 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
84378542 if (!cachefile.exists())
84388543 {
8439
- // cache to disk
8440
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
8441
- //buffers[0].
8442
-
8443
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
8444
- int[] pixels = new int[bytebuf.capacity()/3];
8445
-
8446
- // squared size heuristic...
8447
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8544
+ //if (texturedata.getWidth() == texturedata.getHeight())
84488545 {
8449
- for (int i=pixels.length; --i>=0;)
8450
- {
8451
- int i3 = i*3;
8452
- pixels[i] = 0xFF;
8453
- pixels[i] <<= 8;
8454
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
8455
- pixels[i] <<= 8;
8456
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
8457
- pixels[i] <<= 8;
8458
- pixels[i] |= bytebuf.get(i3) & 0xFF;
8459
- }
8460
-
8461
- /*
8462
- int r=0,g=0,b=0,a=0;
8463
- for (int i=0; i<width; i++)
8464
- for (int j=0; j<height; j++)
8465
- {
8466
- int index = j*width+i;
8467
- int p = pixels[index];
8468
- a = ((p>>24) & 0xFF);
8469
- r = ((p>>16) & 0xFF);
8470
- g = ((p>>8) & 0xFF);
8471
- b = (p & 0xFF);
8472
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
8473
- }
8474
- /**/
8475
- int width = (int)Math.sqrt(pixels.length); // squared
8476
- int height = width;
8477
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
8478
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8546
+ BufferedImage rendImage = CreateBim(texturedata);
8547
+
84798548 ImageWriter writer = null;
84808549 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
84818550 if (iter.hasNext()) {
84828551 writer = (ImageWriter)iter.next();
84838552 }
8484
- float compressionQuality = 0.9f;
8553
+
8554
+ float compressionQuality = 0.85f;
84858555 try
84868556 {
84878557 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8498,18 +8568,20 @@
84988568 }
84998569 }
85008570 }
8501
-
8571
+
8572
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8573
+
85028574 //System.out.println("Texture = " + tex);
8503
- if (textures.containsKey(texname))
8575
+ if (textures.containsKey(tex))
85048576 {
8505
- CacheTexture thetex = textures.get(texname);
8577
+ CacheTexture thetex = textures.get(tex);
85068578 thetex.texture.disable();
85078579 thetex.texture.dispose();
8508
- textures.remove(texname);
8580
+ textures.remove(tex);
85098581 }
85108582
85118583 //texture.texturedata = texturedata;
8512
- textures.put(texname, texturecache);
8584
+ textures.put(tex, texturecache);
85138585
85148586 // newtex = true;
85158587 }
....@@ -8528,9 +8600,43 @@
85288600 return texturecache;
85298601 }
85308602
8531
- com.sun.opengl.util.texture.Texture GetTexture(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception
8603
+ static void EmbedTextures(cTexture tex)
85328604 {
8533
- CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution);
8605
+ if (tex.pigmentdata == null)
8606
+ {
8607
+ //String texname = Object3D.GetPigment(tex);
8608
+
8609
+ CacheTexture texturecache = texturepigment.get(tex);
8610
+
8611
+ if (texturecache != null)
8612
+ {
8613
+ tex.pw = texturecache.texturedata.getWidth();
8614
+ tex.ph = texturecache.texturedata.getHeight();
8615
+ tex.pigmentdata = //CompressJPEG(CreateBim
8616
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8617
+ ;
8618
+ //, tex.pw, tex.ph), 0.5f);
8619
+ }
8620
+ }
8621
+
8622
+ if (tex.bumpdata == null)
8623
+ {
8624
+ //String texname = Object3D.GetBump(tex);
8625
+
8626
+ CacheTexture texturecache = texturebump.get(tex);
8627
+
8628
+ if (texturecache != null)
8629
+ {
8630
+ tex.bw = texturecache.texturedata.getWidth();
8631
+ tex.bh = texturecache.texturedata.getHeight();
8632
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8633
+ }
8634
+ }
8635
+ }
8636
+
8637
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
8638
+ {
8639
+ CacheTexture texture = GetCacheTexture(tex, bump, resolution);
85348640
85358641 if (bump)
85368642 {
....@@ -8546,14 +8652,14 @@
85468652 return texture!=null?texture.texture:null;
85478653 }
85488654
8549
- public com.sun.opengl.util.texture.TextureData GetTextureData(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception
8655
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
85508656 {
8551
- CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution);
8657
+ CacheTexture texture = GetCacheTexture(tex, bump, resolution);
85528658
85538659 return texture!=null?texture.texturedata:null;
85548660 }
85558661
8556
- boolean BindTexture(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception
8662
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
85578663 {
85588664 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
85598665 {
....@@ -8562,7 +8668,7 @@
85628668
85638669 //boolean newtex = false;
85648670
8565
- com.sun.opengl.util.texture.Texture texture = GetTexture(stream, tex, bump, resolution);
8671
+ com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
85668672
85678673 if (texture == null)
85688674 return false;
....@@ -8595,6 +8701,72 @@
85958701 return true; // Warning: not used.
85968702 }
85978703
8704
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8705
+ {
8706
+ try
8707
+ {
8708
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8709
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8710
+ ImageWriter writer = writers.next();
8711
+
8712
+ ImageWriteParam param = writer.getDefaultWriteParam();
8713
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8714
+ param.setCompressionQuality(quality);
8715
+
8716
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8717
+ writer.setOutput(ios);
8718
+ writer.write(null, new IIOImage(image, null, null), param);
8719
+
8720
+ byte[] data = baos.toByteArray();
8721
+ writer.dispose();
8722
+ return data;
8723
+ }
8724
+ catch (Exception e)
8725
+ {
8726
+ e.printStackTrace();
8727
+ return null;
8728
+ }
8729
+ }
8730
+
8731
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8732
+ {
8733
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8734
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8735
+ ImageReader reader = writers.next();
8736
+
8737
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8738
+
8739
+ ImageReadParam param = reader.getDefaultReadParam();
8740
+ param.setDestination(bim);
8741
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8742
+
8743
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8744
+ reader.setInput(ios);
8745
+ BufferedImage bim2 = reader.read(0, param);
8746
+ reader.dispose();
8747
+
8748
+// WritableRaster raster = bim2.getRaster();
8749
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8750
+// byte[] bytes = data.getData();
8751
+//
8752
+// int[] pixels = new int[bytes.length/3];
8753
+// for (int i=pixels.length; --i>=0;)
8754
+// {
8755
+// int i3 = i*3;
8756
+// pixels[i] = 0xFF;
8757
+// pixels[i] <<= 8;
8758
+// pixels[i] |= bytes[i3+2] & 0xFF;
8759
+// pixels[i] <<= 8;
8760
+// pixels[i] |= bytes[i3+1] & 0xFF;
8761
+// pixels[i] <<= 8;
8762
+// pixels[i] |= bytes[i3] & 0xFF;
8763
+// }
8764
+//
8765
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8766
+
8767
+ return bim;
8768
+ }
8769
+
85988770 ShadowBuffer shadowPBuf;
85998771 AntialiasBuffer antialiasPBuf;
86008772 int MAXSTACK;
....@@ -8611,10 +8783,12 @@
86118783
86128784 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
86138785 MAXSTACK = temp[0];
8614
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8786
+ if (Globals.DEBUG)
8787
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
86158788 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
86168789 MAXSTACK = temp[0];
8617
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8790
+ if (Globals.DEBUG)
8791
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
86188792
86198793 // Use debug pipeline
86208794 //drawable.setGL(new DebugGL(gl)); //
....@@ -8622,7 +8796,8 @@
86228796 gl = drawable.getGL(); //
86238797
86248798 GL gl3 = getGL();
8625
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8799
+ if (Globals.DEBUG)
8800
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
86268801
86278802
86288803 //float pos[] = { 100, 100, 100, 0 };
....@@ -8787,7 +8962,7 @@
87878962
87888963 if (cubemap == null)
87898964 {
8790
- LoadEnvy(5);
8965
+ //LoadEnvy(1);
87918966 }
87928967
87938968 //cubemap.enable();
....@@ -9063,6 +9238,8 @@
90639238
90649239 void LoadEnvy(int which)
90659240 {
9241
+ assert(false);
9242
+
90669243 String name;
90679244 String ext;
90689245
....@@ -9074,37 +9251,58 @@
90749251 cubemap = null;
90759252 return;
90769253 case 1:
9077
- name = "cubemaps/box_";
9078
- ext = "png";
9254
+ name = "cubemaps/rgb/";
9255
+ ext = "jpg";
90799256 reverseUP = false;
90809257 break;
90819258 case 2:
9082
- name = "cubemaps/uffizi_";
9083
- ext = "png";
9084
- break; // reverseUP = true; break;
9259
+ name = "cubemaps/uffizi/";
9260
+ ext = "jpg";
9261
+ reverseUP = false;
9262
+ break;
90859263 case 3:
9086
- name = "cubemaps/CloudyHills_";
9087
- ext = "tga";
9264
+ name = "cubemaps/CloudyHills/";
9265
+ ext = "jpg";
90889266 reverseUP = false;
90899267 break;
90909268 case 4:
9091
- name = "cubemaps/cornell_";
9269
+ name = "cubemaps/cornell/";
90929270 ext = "png";
90939271 reverseUP = false;
90949272 break;
9273
+ case 5:
9274
+ name = "cubemaps/skycube/";
9275
+ ext = "jpg";
9276
+ reverseUP = false;
9277
+ break;
9278
+ case 6:
9279
+ name = "cubemaps/SaintLazarusChurch3/";
9280
+ ext = "jpg";
9281
+ reverseUP = false;
9282
+ break;
9283
+ case 7:
9284
+ name = "cubemaps/Sodermalmsallen/";
9285
+ ext = "jpg";
9286
+ reverseUP = false;
9287
+ break;
9288
+ case 8:
9289
+ name = "cubemaps/Sodermalmsallen2/";
9290
+ ext = "jpg";
9291
+ reverseUP = false;
9292
+ break;
9293
+ case 9:
9294
+ name = "cubemaps/UnionSquare/";
9295
+ ext = "jpg";
9296
+ reverseUP = false;
9297
+ break;
90959298 default:
9096
- name = "cubemaps/rgb_";
9097
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9299
+ name = "cubemaps/box/";
9300
+ ext = "png"; /*mipmap = true;*/
9301
+ reverseUP = false;
90989302 break;
90999303 }
9100
-
9101
- try
9102
- {
9103
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
9104
- } catch (IOException e)
9105
- {
9106
- throw new RuntimeException(e);
9107
- }
9304
+
9305
+ LoadSkybox(name, ext, mipmap);
91089306 }
91099307
91109308 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -9136,8 +9334,12 @@
91369334 static double[] model = new double[16];
91379335 double[] camera2light = new double[16];
91389336 double[] light2camera = new double[16];
9139
- int newenvy = -1;
9140
- boolean envyoff = true; // false;
9337
+
9338
+ //int newenvy = -1;
9339
+ //boolean envyoff = false;
9340
+
9341
+ String loadedskyboxname;
9342
+
91419343 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
91429344 //float[] light0 = { 0,0,0 };
91439345 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9555,7 +9757,7 @@
95559757
95569758 if (renderCamera != lightCamera)
95579759 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9558
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
9760
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
95599761
95609762 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
95619763
....@@ -9571,7 +9773,7 @@
95719773
95729774 if (renderCamera != lightCamera)
95739775 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9574
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
9776
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
95759777
95769778 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
95779779
....@@ -9617,10 +9819,12 @@
96179819 rati = 1 / rati;
96189820 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
96199821 }
9620
- assert (newenvy == -1);
9822
+
9823
+ //assert (newenvy == -1);
9824
+
96219825 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
96229826 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9623
- DrawSkyBox(gl);
9827
+ DrawSkyBox(gl, (float)rati);
96249828 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
96259829 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
96269830 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10486,9 +10690,18 @@
1048610690 static boolean init = false;
1048710691
1048810692 double[][] matrix = LA.newMatrix();
10693
+
10694
+ // This is to refresh the UI of the material panel.
10695
+ ObjEditor patchMaterial;
1048910696
1049010697 public void display(GLAutoDrawable drawable)
1049110698 {
10699
+ if (patchMaterial.patchMaterial)
10700
+ {
10701
+ patchMaterial.patchMaterial = false;
10702
+ patchMaterial.objectPanel.setSelectedIndex(1);
10703
+ }
10704
+
1049210705 if (Grafreed.savesound && Grafreed.hassound)
1049310706 {
1049410707 Grafreed.wav.save();
....@@ -10657,7 +10870,7 @@
1065710870
1065810871 if (wait)
1065910872 {
10660
- Sleep(500);
10873
+ Sleep(200); // blocks everything
1066110874
1066210875 wait = false;
1066310876 }
....@@ -10772,7 +10985,7 @@
1077210985 // if (parentcam != renderCamera) // not a light
1077310986 if (cam != lightCamera)
1077410987 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10775
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
10988
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1077610989
1077710990 for (int j = 0; j < 4; j++)
1077810991 {
....@@ -10787,7 +11000,7 @@
1078711000 // if (parentcam != renderCamera) // not a light
1078811001 if (cam != lightCamera)
1078911002 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10790
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
11003
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1079111004
1079211005 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1079311006
....@@ -10873,13 +11086,43 @@
1087311086 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1087411087 }
1087511088
10876
- if (newenvy > -1)
11089
+// if (newenvy > -1)
11090
+// {
11091
+// LoadEnvy(newenvy);
11092
+// }
11093
+//
11094
+// newenvy = -1;
11095
+
11096
+ if (transformMode) // object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
1087711097 {
10878
- LoadEnvy(newenvy);
11098
+ if (cubemaprgb == null)
11099
+ {
11100
+ cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb2" + "/", "jpg", false);
11101
+ }
11102
+
11103
+ cubemap = cubemaprgb;
1087911104 }
10880
-
10881
- newenvy = -1;
10882
-
11105
+ else
11106
+ {
11107
+ if (object.skyboxname != null)
11108
+ {
11109
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11110
+ {
11111
+ if (cubemap != null && cubemap != cubemaprgb)
11112
+ cubemap.dispose();
11113
+ cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11114
+ loadedskyboxname = object.skyboxname;
11115
+ }
11116
+ }
11117
+ else
11118
+ {
11119
+ cubemapcustom = null;
11120
+ loadedskyboxname = null;
11121
+ }
11122
+
11123
+ cubemap = cubemapcustom;
11124
+ }
11125
+
1088311126 ratio = ((double) getWidth()) / getHeight();
1088411127 //System.out.println("ratio = " + ratio);
1088511128
....@@ -10895,7 +11138,7 @@
1089511138
1089611139 if (!IsFrozen() && !ambientOcclusion)
1089711140 {
10898
- DrawSkyBox(gl);
11141
+ DrawSkyBox(gl, (float)ratio);
1089911142 }
1090011143
1090111144 //if (selection_view == -1)
....@@ -11049,7 +11292,7 @@
1104911292
1105011293 try
1105111294 {
11052
- BindTexture(null, NOISE_TEXTURE, false, 2);
11295
+ BindTexture(NOISE_TEXTURE, false, 2);
1105311296 }
1105411297 catch (Exception e)
1105511298 {
....@@ -11181,7 +11424,7 @@
1118111424
1118211425 // if (cam != lightCamera)
1118311426 //for (int count = parentcam.GetTransformCount(); --count>=0;)
11184
- LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
11427
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1118511428 }
1118611429
1118711430 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -11340,7 +11583,7 @@
1134011583 }
1134111584 }
1134211585
11343
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11586
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1134411587 {
1134511588 //gl.glDepthFunc(GL.GL_LEQUAL);
1134611589 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11348,24 +11591,21 @@
1134811591
1134911592 boolean texon = textureon;
1135011593
11351
- if (RENDERPROGRAM > 0)
11352
- {
11353
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11354
- textureon = false;
11355
- }
11594
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11595
+ textureon = false;
11596
+
1135611597 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1135711598 //System.out.println("ALLO");
1135811599 gl.glColorMask(false, false, false, false);
1135911600 DrawObject(gl);
11360
- if (RENDERPROGRAM > 0)
11361
- {
11362
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11363
- textureon = texon;
11364
- }
11601
+
11602
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11603
+ textureon = texon;
11604
+
1136511605 gl.glColorMask(true, true, true, true);
1136611606
1136711607 gl.glDepthFunc(GL.GL_EQUAL);
11368
- //gl.glDepthMask(false);
11608
+ gl.glDepthMask(false);
1136911609 }
1137011610
1137111611 if (false) // DrawMode() == SHADOW)
....@@ -11705,20 +11945,32 @@
1170511945 ReleaseTextures(DEFAULT_TEXTURES);
1170611946
1170711947 if (CLEANCACHE)
11708
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11948
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1170911949 {
11710
- String tex = e.nextElement();
11950
+ cTexture tex = e.nextElement();
1171111951
1171211952 // System.out.println("Texture --------- " + tex);
1171311953
11714
- if (tex.equals("WHITE_NOISE"))
11954
+ if (tex.equals("WHITE_NOISE:"))
1171511955 continue;
1171611956
1171711957 if (!usedtextures.contains(tex))
1171811958 {
11959
+ CacheTexture gettex = texturepigment.get(tex);
1171911960 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11720
- textures.get(tex).texture.dispose();
11721
- textures.remove(tex);
11961
+ if (gettex != null)
11962
+ {
11963
+ gettex.texture.dispose();
11964
+ texturepigment.remove(tex);
11965
+ }
11966
+
11967
+ gettex = texturebump.get(tex);
11968
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11969
+ if (gettex != null)
11970
+ {
11971
+ gettex.texture.dispose();
11972
+ texturebump.remove(tex);
11973
+ }
1172211974 }
1172311975 }
1172411976 }
....@@ -12246,8 +12498,76 @@
1224612498
1224712499 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1224812500
12249
- String program =
12501
+ String programmin =
12502
+ // Min shader
1225012503 "!!ARBfp1.0\n" +
12504
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12505
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12506
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12507
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12508
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12509
+ "PARAM light2cam0 = program.env[10];" +
12510
+ "PARAM light2cam1 = program.env[11];" +
12511
+ "PARAM light2cam2 = program.env[12];" +
12512
+ "TEMP temp;" +
12513
+ "TEMP light;" +
12514
+ "TEMP ndotl;" +
12515
+ "TEMP normal;" +
12516
+ "TEMP depth;" +
12517
+ "TEMP eye;" +
12518
+ "TEMP pos;" +
12519
+
12520
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12521
+ Normalize("normal") +
12522
+ "MOV light, state.light[0].position;" +
12523
+ "DP3 ndotl.x, light, normal;" +
12524
+
12525
+ // shadow
12526
+ "MOV pos, fragment.texcoord[1];" +
12527
+ "MOV temp, pos;" +
12528
+ ShadowTextureFetch("depth", "temp", "1") +
12529
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12530
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12531
+
12532
+ // No shadow when out of frustum
12533
+ //"SGE temp.y, depth.z, zero123.y;" +
12534
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12535
+
12536
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12537
+
12538
+ // Backlit
12539
+ "MOV pos.w, zero123.y;" +
12540
+ "DP4 eye.x, pos, light2cam0;" +
12541
+ "DP4 eye.y, pos, light2cam1;" +
12542
+ "DP4 eye.z, pos, light2cam2;" +
12543
+ Normalize("eye") +
12544
+
12545
+ "DP3 ndotl.y, -eye, normal;" +
12546
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12547
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12548
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12549
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12550
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12551
+
12552
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12553
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12554
+
12555
+ // Pigment
12556
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12557
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12558
+ "MUL temp, temp, ndotl.x;" +
12559
+
12560
+ "MUL temp, temp, zero123.z;" +
12561
+
12562
+ //"MUL temp, temp, ndotl.y;" +
12563
+
12564
+ "MOV temp.w, zero123.y;" + // reset alpha
12565
+ "MOV result.color, temp;" +
12566
+ "END";
12567
+
12568
+ String programmax =
12569
+ "!!ARBfp1.0\n" +
12570
+
1225112571 //"OPTION ARB_fragment_program_shadow;" +
1225212572 "PARAM light2cam0 = program.env[10];" +
1225312573 "PARAM light2cam1 = program.env[11];" +
....@@ -12273,7 +12593,7 @@
1227312593 "PARAM params4 = program.env[4];" + // anisoV, cameralight, selfshadow, shadow
1227412594 "PARAM params5 = program.env[5];" + // texture, opacity, fakedepth, shadowbias
1227512595 "PARAM params6 = program.env[6];" + // bump, noise, borderfade, fog punchthrough
12276
- "PARAM params7 = program.env[7];" + // noise power, opacity power
12596
+ "PARAM params7 = program.env[7];" + // noise power, opacity power, parallax
1227712597 "PARAM options0 = program.env[63];" + // fog density, intensity, elevation
1227812598 "PARAM options1 = program.env[62];" + // fog rgb color
1227912599 "PARAM options2 = program.env[61];" + // image intensity, subsurface, lightsheen
....@@ -12362,8 +12682,7 @@
1236212682 "TEMP shininess;" +
1236312683 "\n" +
1236412684 "MOV texSamp, one;" +
12365
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12366
-
12685
+
1236712686 "MOV mapgrid.x, one2048th.x;" +
1236812687 "MOV temp, fragment.texcoord[1];" +
1236912688 /*
....@@ -12384,20 +12703,20 @@
1238412703 "MUL temp, floor, mapgrid.x;" +
1238512704 //"TEX depth0, temp, texture[1], 2D;" +
1238612705 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12387
- TextureFetch("depth0", "temp", "1") +
12706
+ ShadowTextureFetch("depth0", "temp", "1") +
1238812707 "") +
1238912708 "ADD temp.x, temp.x, mapgrid.x;" +
1239012709 //"TEX depth1, temp, texture[1], 2D;" +
1239112710 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12392
- TextureFetch("depth1", "temp", "1") +
12711
+ ShadowTextureFetch("depth1", "temp", "1") +
1239312712 "") +
1239412713 "ADD temp.y, temp.y, mapgrid.x;" +
1239512714 //"TEX depth2, temp, texture[1], 2D;" +
12396
- TextureFetch("depth2", "temp", "1") +
12715
+ ShadowTextureFetch("depth2", "temp", "1") +
1239712716 "SUB temp.x, temp.x, mapgrid.x;" +
1239812717 //"TEX depth3, temp, texture[1], 2D;" +
1239912718 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12400
- TextureFetch("depth3", "temp", "1") +
12719
+ ShadowTextureFetch("depth3", "temp", "1") +
1240112720 "") +
1240212721 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1240312722 //"MOV params, material;" +
....@@ -12519,7 +12838,7 @@
1251912838 "POW texSamp.a, texSamp.a, params6.w;" + // fog punch through shortcut
1252012839 // mar 2013 ??? "KIL alpha.a;" +
1252112840 "MOV alpha, texSamp.aaaa;" + // y;" +
12522
- "KIL alpha.a;" +
12841
+ "KIL alpha.a;" + // not sure with parallax mapping
1252312842 /*
1252412843 "MUL temp.xy, temp, two;" +
1252512844 "TXB bump, temp, texture[0], 2D;" +
....@@ -12605,11 +12924,6 @@
1260512924 "SUB bump0, bump0, half;" +
1260612925 "ADD bump, bump, bump0;" +
1260712926
12608
- "MOV temp.x, texSamp.a;" +
12609
- "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
12610
- //"LRP texSamp0, params5.x, texSamp0, one;" +
12611
- "MOV texSamp.a, temp.x;" +
12612
-
1261312927 // double-sided
1261412928 /**/
1261512929 (doublesided?"DP3 temp.z, normal, eye;" +
....@@ -12639,6 +12953,41 @@
1263912953 Normalize("U") +
1264012954
1264112955 // parallax mapping
12956
+
12957
+ "DP3 temp2.x, V, eye;" +
12958
+ "DP3 temp2.y, U, eye;" +
12959
+ "DP3 temp2.z, normal, eye;" +
12960
+ "RCP temp2.z, temp2.z;" +
12961
+
12962
+ "DP3 temp2.w, texSamp, texSamp;" + // Height
12963
+ "RSQ temp2.w, temp2.w;" +
12964
+ "RCP temp2.w, temp2.w;" +
12965
+
12966
+ "SUB temp2.w, temp2.w, half;" +
12967
+// "SGE temp.x, temp2.w, eps.x;" +
12968
+// "MUL temp2.w, temp2.w, temp.x;" +
12969
+
12970
+ //"MOV texSamp, U;" +
12971
+
12972
+ "MUL temp2.z, temp2.z, temp2.w;" +
12973
+ "MUL temp2.z, temp2.z, params7.z;" + // parallax
12974
+
12975
+ "MUL temp2, temp2, temp2.z;" +
12976
+
12977
+ "MOV temp, fragment.texcoord[0];" +
12978
+
12979
+ "SUB temp, temp, temp2;" +
12980
+
12981
+ "TEX texSamp, temp, texture[0], 2D;" +
12982
+ "POW texSamp.a, texSamp.a, params6.w;" + // punch through
12983
+ "MOV alpha, texSamp.aaaa;" +
12984
+
12985
+// parallax mapping
12986
+
12987
+ "MOV temp.x, texSamp.a;" +
12988
+ "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
12989
+ //"LRP texSamp0, params5.x, texSamp0, one;" +
12990
+ "MOV texSamp.a, temp.x;" +
1264212991
1264312992 //"MOV temp, fragment.texcoord[0];" +
1264412993 //
....@@ -12768,10 +13117,10 @@
1276813117 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1276913118 "") +
1277013119
12771
- // display shadow only (bump == 0)
13120
+ // display shadow only (fakedepth == 0)
1277213121 "SUB temp.x, half.x, shadow.x;" +
1277313122 "MOV temp.y, -params5.z;" + // params6.x;" +
12774
- "SLT temp.z, temp.y, -one2048th.x;" +
13123
+ "SLT temp.z, temp.y, -c256i.x;" +
1277513124 "SUB temp.y, one.x, temp.z;" +
1277613125 "MUL temp.x, temp.x, temp.y;" +
1277713126 "KIL temp.x;" +
....@@ -13102,8 +13451,19 @@
1310213451 //once = true;
1310313452 }
1310413453
13105
- System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13106
- System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13454
+ String program = programmax;
13455
+
13456
+ if (Globals.MINSHADER)
13457
+ {
13458
+ program = programmin;
13459
+ }
13460
+
13461
+ if (Globals.DEBUG)
13462
+ {
13463
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13464
+ System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13465
+ }
13466
+
1310713467 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1310813468
1310913469 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -13150,7 +13510,8 @@
1315013510 "\n" +
1315113511 "END\n";
1315213512
13153
- System.out.println("Program shadow #" + 0 + "; length = " + program.length());
13513
+ if (Globals.DEBUG)
13514
+ System.out.println("Program shadow #" + 0 + "; length = " + program.length());
1315413515 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1315513516
1315613517 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -13195,25 +13556,26 @@
1319513556 return out;
1319613557 }
1319713558
13198
- String TextureFetch(String dest, String src, String unit)
13559
+ // Also does frustum culling
13560
+ String ShadowTextureFetch(String dest, String src, String unit)
1319913561 {
1320013562 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1320113563 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1320213564 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13565
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13566
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1320313567 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13204
- "SLT " + src + ".z, " + src + ".x, one.x;" +
13205
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13206
- "SLT " + src + ".z, " + src + ".y, one.x;" +
13207
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13568
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13569
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1320813570 //"SWZ buffer, temp, w,w,w,w;";
13209
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13571
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1321013572 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1321113573 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1321213574 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13213
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13575
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1321413576
13215
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13216
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13577
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13578
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1321713579 }
1321813580
1321913581 String Shadow(String depth, String shadow)
....@@ -13260,7 +13622,7 @@
1326013622 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1326113623 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1326213624
13263
- // No shadow when out of frustrum
13625
+ // No shadow when out of frustum
1326413626 "SGE temp.x, " + depth + ".z, one.z;" +
1326513627 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1326613628 "";
....@@ -13407,7 +13769,7 @@
1340713769 /*static*/ float[] modelParams4 = new float[]{0, 0, 0, 0}; // anisoV, cameralight, selfshadow, shadow
1340813770 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1340913771 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
13410
- /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13772
+ /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power, parallax
1341113773
1341213774 //Object3D.cVector2[] vector2buffer;
1341313775
....@@ -14058,14 +14420,15 @@
1405814420 drag = false;
1405914421 //System.out.println("Mouse DOWN");
1406014422 editObj = false;
14061
- ClickInfo info = new ClickInfo();
14062
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14063
- info.pane = this;
14064
- info.camera = renderCamera;
14065
- info.x = x;
14066
- info.y = y;
14067
- info.modifiers = modifiersex;
14068
- editObj = object.doEditClick(info, 0);
14423
+ //ClickInfo info = new ClickInfo();
14424
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14425
+ object.clickInfo.pane = this;
14426
+ object.clickInfo.camera = renderCamera;
14427
+ object.clickInfo.x = x;
14428
+ object.clickInfo.y = y;
14429
+ object.clickInfo.modifiers = modifiersex;
14430
+ editObj = object.doEditClick(//info,
14431
+ 0);
1406914432 if (!editObj)
1407014433 {
1407114434 hasMarquee = true;
....@@ -14347,11 +14710,17 @@
1434714710 void GoDown(int mod)
1434814711 {
1434914712 MODIFIERS |= COMMAND;
14713
+ boolean isVR = (mouseMode&VR)!=0;
1435014714 /**/
1435114715 if((mod&SHIFT) == SHIFT)
14352
- manipCamera.RotatePosition(0, -speed);
14716
+ {
14717
+ if (isVR)
14718
+ manipCamera.RotateInterest(0, -speed);
14719
+ else
14720
+ manipCamera.RotatePosition(0, -speed);
14721
+ }
1435314722 else
14354
- manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14723
+ manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth());
1435514724 /**/
1435614725 if ((mod & SHIFT) == SHIFT)
1435714726 {
....@@ -14361,6 +14730,8 @@
1436114730 mouseMode |= BACKFORTH;
1436214731 }
1436314732
14733
+ targetLookAt.set(manipCamera.lookAt);
14734
+
1436414735 //prevX = X = anchorX;
1436514736 prevY = Y = anchorY - (int) (renderCamera.Distance());
1436614737 }
....@@ -14369,10 +14740,17 @@
1436914740 {
1437014741 MODIFIERS |= COMMAND;
1437114742 /**/
14743
+ boolean isVR = (mouseMode&VR)!=0;
14744
+
1437214745 if((mod&SHIFT) == SHIFT)
14373
- manipCamera.RotatePosition(0, speed);
14746
+ {
14747
+ if (isVR)
14748
+ manipCamera.RotateInterest(0, speed);
14749
+ else
14750
+ manipCamera.RotatePosition(0, speed);
14751
+ }
1437414752 else
14375
- manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14753
+ manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth());
1437614754 /**/
1437714755 if ((mod & SHIFT) == SHIFT)
1437814756 {
....@@ -14382,6 +14760,8 @@
1438214760 mouseMode |= BACKFORTH;
1438314761 }
1438414762
14763
+ targetLookAt.set(manipCamera.lookAt);
14764
+
1438514765 //prevX = X = anchorX;
1438614766 prevY = Y = anchorY + (int) (renderCamera.Distance());
1438714767 }
....@@ -14391,9 +14771,14 @@
1439114771 MODIFIERS |= COMMAND;
1439214772 /**/
1439314773 if((mod&SHIFT) == SHIFT)
14394
- manipCamera.Translate(speed*delta, 0, getWidth());
14774
+ manipCamera.Translate(speed*delta, 0, getWidth());
1439514775 else
14396
- manipCamera.RotatePosition(speed, 0);
14776
+ {
14777
+ if ((mouseMode&VR)!=0)
14778
+ manipCamera.RotateInterest(-speed, 0);
14779
+ else
14780
+ manipCamera.RotatePosition(speed, 0);
14781
+ }
1439714782 /**/
1439814783 if ((mod & SHIFT) == SHIFT)
1439914784 {
....@@ -14403,6 +14788,8 @@
1440314788 mouseMode |= ROTATE;
1440414789 } // TRANSLATE;
1440514790
14791
+ targetLookAt.set(manipCamera.lookAt);
14792
+
1440614793 prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance());
1440714794 prevY = Y = anchorY;
1440814795 }
....@@ -14412,9 +14799,15 @@
1441214799 MODIFIERS |= COMMAND;
1441314800 /**/
1441414801 if((mod&SHIFT) == SHIFT)
14415
- manipCamera.Translate(-speed*delta, 0, getWidth());
14802
+ manipCamera.Translate(-speed*delta, 0, getWidth());
1441614803 else
14417
- manipCamera.RotatePosition(-speed, 0);
14804
+ {
14805
+ if ((mouseMode&VR)!=0)
14806
+ manipCamera.RotateInterest(speed, 0);
14807
+ else
14808
+ manipCamera.RotatePosition(-speed, 0);
14809
+ }
14810
+
1441814811 /**/
1441914812 if ((mod & SHIFT) == SHIFT)
1442014813 {
....@@ -14424,6 +14817,8 @@
1442414817 mouseMode |= ROTATE;
1442514818 } // TRANSLATE;
1442614819
14820
+ targetLookAt.set(manipCamera.lookAt);
14821
+
1442714822 prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance());
1442814823 prevY = Y = anchorY;
1442914824 }
....@@ -14465,15 +14860,16 @@
1446514860 if (editObj)
1446614861 {
1446714862 drag = true;
14468
- ClickInfo info = new ClickInfo();
14469
- info.bounds.setBounds(0, 0,
14863
+ //ClickInfo info = new ClickInfo();
14864
+ object.clickInfo.bounds.setBounds(0, 0,
1447014865 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14471
- info.pane = this;
14472
- info.camera = renderCamera;
14473
- info.x = x;
14474
- info.y = y;
14475
- object.GetWindow().copy
14476
- .doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
14866
+ object.clickInfo.pane = this;
14867
+ object.clickInfo.camera = renderCamera;
14868
+ object.clickInfo.x = x;
14869
+ object.clickInfo.y = y;
14870
+ object //.GetWindow().copy
14871
+ .doEditDrag(//info,
14872
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1447714873 } else
1447814874 {
1447914875 if (x < startX)
....@@ -14622,24 +15018,27 @@
1462215018 }
1462315019 }
1462415020
15021
+// ClickInfo clickInfo = new ClickInfo();
15022
+
1462515023 public void mouseMoved(MouseEvent e)
1462615024 {
1462715025 //System.out.println("mouseMoved: " + e);
1462815026 if (isRenderer)
1462915027 return;
1463015028
14631
- ClickInfo ci = new ClickInfo();
14632
- ci.x = e.getX();
14633
- ci.y = e.getY();
14634
- ci.modifiers = e.getModifiersEx();
14635
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14636
- ci.pane = this;
14637
- ci.camera = renderCamera;
15029
+ // Mouse cursor feedback
15030
+ object.clickInfo.x = e.getX();
15031
+ object.clickInfo.y = e.getY();
15032
+ object.clickInfo.modifiers = e.getModifiersEx();
15033
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
15034
+ object.clickInfo.pane = this;
15035
+ object.clickInfo.camera = renderCamera;
1463815036 if (!isRenderer)
1463915037 {
1464015038 //ObjEditor editWindow = object.editWindow;
1464115039 //Object3D copy = editWindow.copy;
14642
- if (object.doEditClick(ci, 0))
15040
+ if (object.doEditClick(//clickInfo,
15041
+ 0))
1464315042 {
1464415043 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1464515044 } else
....@@ -14911,7 +15310,8 @@
1491115310 // break;
1491215311 case 'T':
1491315312 CACHETEXTURE ^= true;
14914
- textures.clear();
15313
+ texturepigment.clear();
15314
+ texturebump.clear();
1491515315 // repaint();
1491615316 break;
1491715317 case 'Y':
....@@ -14921,8 +15321,8 @@
1492115321 case 'K':
1492215322 KOMPACTTEXTURE ^= true;
1492315323 //textures.clear();
14924
- break;
14925
- case 'P': // Texture Projection macros
15324
+ // break;
15325
+ //case 'P': // Texture Projection macros
1492615326 // SAVETEXTURE ^= true;
1492715327 macromode = true;
1492815328 Udebug = Vdebug = NORMALdebug = false; programInitialized = false;
....@@ -15043,7 +15443,7 @@
1504315443 targetLookAt.set(manipCamera.lookAt);
1504415444 repaint();
1504515445 break;
15046
- case 'p':
15446
+ case 'P': // p':
1504715447 // c'est quoi ca au juste? spherical ^= true;
1504815448 Skinshader ^= true; programInitialized = false;
1504915449 repaint();
....@@ -15088,20 +15488,24 @@
1508815488 OCCLUSION_CULLING ^= true;
1508915489 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1509015490 break;
15091
- case '0': envyoff ^= true; repaint(); break;
15491
+ //case '0': envyoff ^= true; repaint(); break;
1509215492 case '1':
1509315493 case '2':
1509415494 case '3':
1509515495 case '4':
1509615496 case '5':
15097
- newenvy = Character.getNumericValue(key);
15098
- repaint();
15099
- break;
1510015497 case '6':
1510115498 case '7':
1510215499 case '8':
1510315500 case '9':
15104
- BGcolor = (key - '6')/3.f;
15501
+ if (true) // envyoff)
15502
+ {
15503
+ BGcolor = (key - '1')/8.f;
15504
+ }
15505
+ else
15506
+ {
15507
+ //newenvy = Character.getNumericValue(key);
15508
+ }
1510515509 repaint();
1510615510 break;
1510715511 case '!':
....@@ -15664,8 +16068,6 @@
1566416068
1566516069 int width = getBounds().width;
1566616070 int height = getBounds().height;
15667
- ClickInfo info = new ClickInfo();
15668
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1566916071 //Image img = CreateImage(width, height);
1567016072 //System.out.println("width = " + width + "; height = " + height + "\n");
1567116073
....@@ -15742,31 +16144,37 @@
1574216144 }
1574316145 if (object != null && !hasMarquee)
1574416146 {
16147
+ if (object.clickInfo == null)
16148
+ object.clickInfo = new ClickInfo();
16149
+ ClickInfo info = object.clickInfo;
16150
+ //ClickInfo info = new ClickInfo();
16151
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16152
+
1574516153 if (isRenderer)
1574616154 {
15747
- info.flags++;
16155
+ object.clickInfo.flags++;
1574816156 double frameAspect = (double) width / (double) height;
1574916157 if (frameAspect > renderCamera.aspect)
1575016158 {
1575116159 int desired = (int) ((double) height * renderCamera.aspect);
15752
- info.bounds.width -= width - desired;
15753
- info.bounds.x += (width - desired) / 2;
16160
+ object.clickInfo.bounds.width -= width - desired;
16161
+ object.clickInfo.bounds.x += (width - desired) / 2;
1575416162 } else
1575516163 {
1575616164 int desired = (int) ((double) width / renderCamera.aspect);
15757
- info.bounds.height -= height - desired;
15758
- info.bounds.y += (height - desired) / 2;
16165
+ object.clickInfo.bounds.height -= height - desired;
16166
+ object.clickInfo.bounds.y += (height - desired) / 2;
1575916167 }
1576016168 }
1576116169
15762
- info.g = gr;
15763
- info.camera = renderCamera;
16170
+ object.clickInfo.g = gr;
16171
+ object.clickInfo.camera = renderCamera;
1576416172 /*
1576516173 // Memory intensive (brep.verticescopy)
1576616174 if (!(object instanceof Composite))
1576716175 object.draw(info, 0, false); // SLOW :
1576816176 */
15769
- if (!isRenderer)
16177
+ if (!isRenderer) // && drag)
1577016178 {
1577116179 Grafreed.Assert(object != null);
1577216180 Grafreed.Assert(object.selection != null);
....@@ -15774,9 +16182,9 @@
1577416182 {
1577516183 int hitSomething = object.selection.get(0).hitSomething;
1577616184
15777
- info.DX = 0;
15778
- info.DY = 0;
15779
- info.W = 1;
16185
+ object.clickInfo.DX = 0;
16186
+ object.clickInfo.DY = 0;
16187
+ object.clickInfo.W = 1;
1578016188 if (hitSomething == Object3D.hitCenter)
1578116189 {
1578216190 info.DX = X;
....@@ -15788,13 +16196,14 @@
1578816196 info.DY -= info.bounds.height/2;
1578916197 }
1579016198
15791
- object.drawEditHandles(info, 0);
16199
+ object.drawEditHandles(//info,
16200
+ 0);
1579216201
1579316202 if (drag && (X != 0 || Y != 0))
1579416203 {
1579516204 switch (hitSomething)
1579616205 {
15797
- case Object3D.hitCenter: gr.setColor(Color.pink);
16206
+ case Object3D.hitCenter: gr.setColor(Color.white);
1579816207 gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
1579916208 break;
1580016209 case Object3D.hitRotate: gr.setColor(Color.yellow);
....@@ -15820,7 +16229,7 @@
1582016229 if (hasMarquee)
1582116230 {
1582216231 gr.setXORMode(Color.white);
15823
- gr.setColor(Color.red);
16232
+ gr.setColor(Color.white);
1582416233 if (!firstime)
1582516234 {
1582616235 gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH);
....@@ -16287,6 +16696,8 @@
1628716696 private /*static*/ boolean firstime;
1628816697 private /*static*/ cVector newView = new cVector();
1628916698 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16699
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16700
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1629016701 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1629116702 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1629216703 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16299,29 +16710,67 @@
1629916710 {
1630016711 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1630116712
16713
+ int usedsuf = 0;
16714
+
1630216715 for (int i = 0; i < suffixes.length; i++)
1630316716 {
16304
- String resourceName = basename + suffixes[i] + "." + suffix;
16305
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16306
- mipmapped,
16307
- FileUtil.getFileSuffix(resourceName));
16308
- if (data == null)
16717
+ String[] suffixe = suffixes;
16718
+ String[] fallback = suffixes2;
16719
+ String[] fallfallback = suffixes3;
16720
+
16721
+ for (int c=usedsuf; --c>=0;)
1630916722 {
16310
- throw new IOException("Unable to load texture " + resourceName);
16723
+// String[] temp = suffixe;
16724
+// suffixe = fallback;
16725
+// fallback = fallfallback;
16726
+// fallfallback = temp;
1631116727 }
16728
+
16729
+ String resourceName = basename + suffixe[i] + "." + suffix;
16730
+ TextureData data;
16731
+
16732
+ try
16733
+ {
16734
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16735
+ mipmapped,
16736
+ FileUtil.getFileSuffix(resourceName));
16737
+ }
16738
+ catch (Exception e)
16739
+ {
16740
+ try
16741
+ {
16742
+ resourceName = basename + fallback[i] + "." + suffix;
16743
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16744
+ mipmapped,
16745
+ FileUtil.getFileSuffix(resourceName));
16746
+ }
16747
+ catch (Exception e2)
16748
+ {
16749
+ resourceName = basename + fallfallback[i] + "." + suffix;
16750
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16751
+ mipmapped,
16752
+ FileUtil.getFileSuffix(resourceName));
16753
+ }
16754
+ }
16755
+
1631216756 //System.out.println("Target = " + targets[i]);
1631316757 cubemap.updateImage(data, targets[i]);
1631416758 }
1631516759
1631616760 return cubemap;
1631716761 }
16762
+
1631816763 int bigsphere = -1;
1631916764
1632016765 float BGcolor = 0.5f;
1632116766
16322
- private void DrawSkyBox(GL gl)
16767
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16768
+
16769
+ private void DrawSkyBox(GL gl, float ratio)
1632316770 {
16324
- if (envyoff || cubemap == null)
16771
+ if (//envyoff ||
16772
+ WIREFRAME ||
16773
+ cubemap == null)
1632516774 {
1632616775 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1632716776 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16336,7 +16785,17 @@
1633616785 // Compensates for ExaminerViewer's modification of modelview matrix
1633716786 gl.glMatrixMode(GL.GL_MODELVIEW);
1633816787 gl.glLoadIdentity();
16788
+ gl.glScalef(1,ratio,1);
1633916789
16790
+// colorV[0] = 2;
16791
+// colorV[1] = 2;
16792
+// colorV[2] = 2;
16793
+// colorV[3] = 1;
16794
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16795
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16796
+//
16797
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16798
+
1634016799 //gl.glActiveTexture(GL.GL_TEXTURE1);
1634116800 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1634216801
....@@ -16368,6 +16827,7 @@
1636816827 {
1636916828 gl.glScalef(1.0f, -1.0f, 1.0f);
1637016829 }
16830
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1637116831 gl.glMultMatrixd(viewrot_1, 0);
1637216832 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1637316833 //viewer.updateInverseRotation(gl);
....@@ -16408,7 +16868,8 @@
1640816868 gl.glDisable(GL.GL_TEXTURE_GEN_R);
1640916869
1641016870 cubemap.disable();
16411
- ////cubemap.unbind();
16871
+ //cubemap.dispose();
16872
+
1641216873 if (CULLFACE)
1641316874 {
1641416875 gl.glEnable(gl.GL_CULL_FACE);
....@@ -16626,7 +17087,7 @@
1662617087 //new Exception().printStackTrace();
1662717088 System.out.println("select buffer init");
1662817089 // Use debug pipeline
16629
- drawable.setGL(new DebugGL(drawable.getGL()));
17090
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1663017091
1663117092 GL gl = drawable.getGL();
1663217093
....@@ -16944,6 +17405,7 @@
1694417405
1694517406 public void init(GLAutoDrawable drawable)
1694617407 {
17408
+ if (Globals.DEBUG)
1694717409 System.out.println("shadow buffer init");
1694817410
1694917411 GL gl = drawable.getGL();
....@@ -17172,10 +17634,14 @@
1717217634 gl.glFlush();
1717317635
1717417636 /**/
17175
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17637
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1717617638
17177
- float[] pixels = occlusionsizebuffer.array();
17639
+ float[] depths = occlusiondepthbuffer.array();
1717817640
17641
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17642
+
17643
+ int[] pixels = selectsizebuffer.array();
17644
+
1717917645 double r = 0, g = 0, b = 0;
1718017646
1718117647 double count = 0;
....@@ -17186,7 +17652,7 @@
1718617652
1718717653 double FACTOR = 1;
1718817654
17189
- for (int i = 0; i < pixels.length; i++)
17655
+ for (int i = 0; i < depths.length; i++)
1719017656 {
1719117657 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1719217658 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -17269,7 +17735,7 @@
1726917735
1727017736 double scale = ray.z; // 1; // cos
1727117737
17272
- float depth = pixels[newindex];
17738
+ float depth = depths[newindex];
1727317739
1727417740 /*
1727517741 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -17466,11 +17932,14 @@
1746617932 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1746717933 static IntBuffer bigAAbuffer;
1746817934 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
17469
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17935
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1747017936 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1747117937 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1747217938 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17473
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17939
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17940
+
17941
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17942
+
1747417943 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1747517944 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1747617945 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();