Normand Briere
2019-08-21 7ac1b01c591ed65743676b1181d60eb17c5cb69d
CameraPane.java
....@@ -18,7 +18,10 @@
1818 import javax.imageio.ImageIO;
1919 import javax.imageio.ImageWriteParam;
2020 import javax.imageio.ImageWriter;
21
+import javax.imageio.ImageReadParam;
22
+import javax.imageio.ImageReader;
2123 import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
24
+import javax.imageio.stream.ImageInputStream;
2225 import javax.imageio.stream.ImageOutputStream;
2326 import javax.imageio.ImageWriteParam;
2427
....@@ -30,6 +33,7 @@
3033 import java.nio.*;
3134
3235 import gleem.linalg.Mat4f;
36
+import javax.imageio.ImageTypeSpecifier;
3337
3438 class CameraPane extends GLCanvas implements iCameraPane, Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener
3539 {
....@@ -44,6 +48,39 @@
4448 static boolean ABORTED = false;
4549
4650 static int STEP = 1;
51
+
52
+ private static BufferedImage CreateBim(byte[] bytes, int width, int height)
53
+ {
54
+ int[] pixels = new int[bytes.length/3];
55
+ for (int i=pixels.length; --i>=0;)
56
+ {
57
+ int i3 = i*3;
58
+ pixels[i] = 0xFF;
59
+ pixels[i] <<= 8;
60
+ pixels[i] |= bytes[i3+2] & 0xFF;
61
+ pixels[i] <<= 8;
62
+ pixels[i] |= bytes[i3+1] & 0xFF;
63
+ pixels[i] <<= 8;
64
+ pixels[i] |= bytes[i3] & 0xFF;
65
+ }
66
+ /*
67
+ int r=0,g=0,b=0,a=0;
68
+ for (int i=0; i<width; i++)
69
+ for (int j=0; j<height; j++)
70
+ {
71
+ int index = j*width+i;
72
+ int p = pixels[index];
73
+ a = ((p>>24) & 0xFF);
74
+ r = ((p>>16) & 0xFF);
75
+ g = ((p>>8) & 0xFF);
76
+ b = (p & 0xFF);
77
+ pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
78
+ }
79
+ /**/
80
+ BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
81
+ rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
82
+ return rendImage;
83
+ }
4784
4885 /*static*/ private boolean CULLFACE = false; // true;
4986 /*static*/ boolean NEAREST = false; // true;
....@@ -60,7 +97,7 @@
6097 //boolean REDUCETEXTURE = true;
6198 boolean CACHETEXTURE = true;
6299 boolean CLEANCACHE = false; // true;
63
- boolean MIPMAP = false; // true;
100
+ boolean MIPMAP = false; // true; // never works...
64101 boolean COMPRESSTEXTURE = false;
65102 boolean KOMPACTTEXTURE = false; // true;
66103 boolean RESIZETEXTURE = false;
....@@ -73,7 +110,11 @@
73110 //private Mat4f spotlightTransform = new Mat4f();
74111 //private Mat4f spotlightInverseTransform = new Mat4f();
75112 static GLContext glcontext = null;
76
- /*static*/ com.sun.opengl.util.texture.Texture cubemap;
113
+ /*static*/ com.sun.opengl.util.texture.Texture cubemap; // Either custom or rgb
114
+ /*static*/ com.sun.opengl.util.texture.Texture cubemapcustom;
115
+ /*static*/ com.sun.opengl.util.texture.Texture cubemaprgb;
116
+ boolean transformMode;
117
+
77118 boolean reverseUP = false;
78119 static boolean frozen = false;
79120 boolean enablebackspace = false; // patch for back buffer refresh
....@@ -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
....@@ -487,7 +542,8 @@
487542 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
488543 LA.vecCross(obj.v0, obj.v1, obj.v2);
489544 LA.vecNormalize(obj.v2);
490
- gl.glNormal3f((float) obj.v2.x, (float) obj.v2.y, (float) obj.v2.z);
545
+
546
+ SetGLNormal(gl, (float) obj.v2.x, (float) obj.v2.y, (float) obj.v2.z);
491547 }
492548
493549 // P
....@@ -509,7 +565,7 @@
509565 y += ny * obj.NORMALPUSH;
510566 z += nz * obj.NORMALPUSH;
511567
512
- gl.glNormal3f(nx, ny, nz);
568
+ SetGLNormal(gl, nx, ny, nz);
513569 }
514570 gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
515571 SetColor(obj, pv);
....@@ -541,7 +597,7 @@
541597 y += ny * obj.NORMALPUSH;
542598 z += nz * obj.NORMALPUSH;
543599
544
- gl.glNormal3f(nx, ny, nz);
600
+ SetGLNormal(gl, nx, ny, nz);
545601 }
546602 //System.out.println("vertexq = " + qv.s + ", " + qv.t);
547603 // boolean locked = false;
....@@ -589,7 +645,7 @@
589645 y += ny * obj.NORMALPUSH;
590646 z += nz * obj.NORMALPUSH;
591647
592
- gl.glNormal3f(nx, ny, nz);
648
+ SetGLNormal(gl, nx, ny, nz);
593649 }
594650
595651 // if ((dot&4) == 0)
....@@ -1195,10 +1251,10 @@
11951251 {
11961252 if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
11971253 {
1198
- gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1254
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
11991255 } else
12001256 {
1201
- gl.glNormal3f(0, 0, 1);
1257
+ SetGLNormal(gl, 0, 0, 1);
12021258 }
12031259
12041260 if (c != null)
....@@ -1222,10 +1278,10 @@
12221278 {
12231279 if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
12241280 {
1225
- gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1281
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
12261282 } else
12271283 {
1228
- gl.glNormal3f(0, 0, 1);
1284
+ SetGLNormal(gl, 0, 0, 1);
12291285 }
12301286 if (c != null)
12311287 {
....@@ -1250,10 +1306,10 @@
12501306 {
12511307 if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
12521308 {
1253
- gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1309
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
12541310 } else
12551311 {
1256
- gl.glNormal3f(0, 0, 1);
1312
+ SetGLNormal(gl, 0, 0, 1);
12571313 }
12581314 if (c != null)
12591315 {
....@@ -1435,7 +1491,7 @@
14351491 {
14361492 if (!selectmode)
14371493 {
1438
- gl.glNormal3f((float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
1494
+ SetGLNormal(gl, (float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
14391495 gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
14401496
14411497 if (flipV)
....@@ -1447,6 +1503,8 @@
14471503 gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
14481504 }
14491505
1506
+ float[] colorV = new float[4];
1507
+
14501508 void SetColor(Object3D obj, Vertex p0)
14511509 {
14521510 CameraPane display = this;
....@@ -1514,8 +1572,6 @@
15141572 {
15151573 return;
15161574 }
1517
-
1518
- float[] colorV = new float[3];
15191575
15201576 if (false) // marked)
15211577 {
....@@ -1764,7 +1820,7 @@
17641820
17651821 display.modelParams7[0] = 0;
17661822 display.modelParams7[1] = 1000;
1767
- display.modelParams7[2] = 0;
1823
+ display.modelParams7[2] = material.parallax;
17681824 display.modelParams7[3] = 0;
17691825
17701826 //display.modelParams6[0] = 100; // criss de bug de bump
....@@ -1997,9 +2053,9 @@
19972053 switch(viewcode)
19982054 {
19992055 case 0: return "main";
2000
- case 1: return "one";
2001
- case 2: return "two";
2002
- case 3: return "three";
2056
+ case 1: return "Red";
2057
+ case 2: return "Green";
2058
+ case 3: return "Blue";
20032059 case 4: return "light";
20042060 }
20052061
....@@ -2065,7 +2121,7 @@
20652121 //System.err.println("Oeil on");
20662122 OEIL = true;
20672123 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2068
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2124
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
20692125 //pingthread.StepToTarget(true);
20702126 }
20712127
....@@ -2298,10 +2354,17 @@
22982354 HANDLES ^= true;
22992355 }
23002356
2357
+ Object3D paintFolder;
2358
+
23012359 void TogglePaint()
23022360 {
23032361 PAINTMODE ^= true;
23042362 paintcount = 0;
2363
+
2364
+ if (PAINTMODE)
2365
+ {
2366
+ paintFolder = GetFolder();
2367
+ }
23052368 }
23062369
23072370 void SwapCamera(int a, int b)
....@@ -2398,126 +2461,31 @@
23982461 return currentGL;
23992462 }
24002463
2401
- private void GetRemoteZip(String url, String name, boolean unzip, boolean save)
2464
+ static private BufferedImage CreateBim(TextureData texturedata)
24022465 {
2403
- java.net.URL u;
2404
- InputStream is = null;
2405
- DataInputStream dis;
2406
- java.util.zip.ZipInputStream zis;
2407
- //String s;
2466
+ Grafreed.Assert(texturedata != null);
2467
+
2468
+ int width = texturedata.getWidth();
2469
+ int height = texturedata.getHeight();
2470
+
2471
+ Buffer buffer = texturedata.getBuffer();
2472
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2473
+
2474
+ byte[] bytes = bytebuf.array();
2475
+
2476
+ return CreateBim(bytes, width, height);
2477
+ }
24082478
2409
- System.out.println("GetRemoteZip " + name);
2410
-
2411
- int total = 0; // dis.available();
2479
+ private void SetGLNormal(javax.media.opengl.GL gl, float nx, float ny, float nz)
2480
+ {
2481
+ gl.glNormal3f(nx, ny, nz);
24122482
2413
- byte[] bytes = new byte[16384];
2414
-
2415
- try
2416
- {
2417
- u = new java.net.URL(url + name);
2418
- is = u.openStream();
2419
-
2420
- System.out.println(url + name);
2421
-
2422
- if (unzip)
2423
- {
2424
- //dis = new DataInputStream(new BufferedInputStream(is));
2425
- zis = new java.util.zip.ZipInputStream(new BufferedInputStream(is));
2426
- //while ((s = dis.readLine()) != null)
2427
-
2428
- if (save)
2429
- new java.io.File(name).mkdirs();
2430
-
2431
- // FileOutputStream stream = new FileOutputStream("test.zip");
2432
- //
2433
- // int count;
2434
- //
2435
- // while ((count = dis.read(bytes)) != -1)
2436
- // {
2437
- // //System.out.println(s);
2438
- // System.out.println(count);
2439
- // total += count;
2440
- // stream.write(bytes);
2441
- // }
2442
- //
2443
- // stream.close();
2444
-
2445
- // now iterate through each item in the stream. The get next
2446
- // entry call will return a ZipEntry for each file in the
2447
- // stream
2448
- java.util.zip.ZipEntry entry;
2449
- while((entry = zis.getNextEntry())!=null)
2450
- {
2451
- if (entry.getName().endsWith(".gsm"))
2452
- {
2453
- continue;
2454
- }
2455
-
2456
- String s = String.format("Entry: %s len %d added %TD",
2457
- entry.getName(), entry.getSize(),
2458
- new java.util.Date(entry.getTime()));
2459
- System.out.println(s);
2460
-
2461
- if (save)
2462
- {
2463
- // Once we get the entry from the stream, the stream is
2464
- // positioned read to read the raw data, and we keep
2465
- // reading until read returns 0 or less.
2466
- String outpath = name + "/" + entry.getName();
2467
- FileOutputStream output = null;
2468
- try
2469
- {
2470
- output = new FileOutputStream(outpath);
2471
- int len = 0;
2472
- while ((len = zis.read(bytes)) > 0)
2473
- {
2474
- output.write(bytes, 0, len);
2475
- }
2476
- }
2477
- finally
2478
- {
2479
- // we must always close the output file
2480
- if(output!=null) output.close();
2481
- }
2482
- }
2483
- }
2484
- }
2485
- }
2486
- catch (java.net.MalformedURLException mue)
2487
- {
2488
- System.err.println("Ouch - a MalformedURLException happened.");
2489
- mue.printStackTrace();
2490
- //System.exit(2);
2491
- }
2492
- catch (IOException ioe)
2493
- {
2494
- //System.err.println("Oops - an IOException happened.");
2495
- //ioe.printStackTrace();
2496
- //System.exit(3);
2497
- }
2498
- finally
2499
- {
2500
- try
2501
- {
2502
- if (is != null)
2503
- is.close();
2504
- }
2505
- catch (IOException ioe)
2506
- {
2507
- }
2508
- }
2509
-
2510
- // System.out.println("length = " + total);
2511
-
2512
-// try
2513
-// {
2514
-// Runtime.getRuntime().exec("/usr/local/bin/wget https://archive3d.net/?a=download&do=get&id=7caca905");
2515
-// }
2516
-// catch (Exception e)
2517
-// {
2518
-// e.printStackTrace();
2519
-// }
2520
-
2483
+ if (ny > 0.9 || ny < -0.9)
2484
+ // Ground or ceiling
2485
+ gl.glVertexAttrib3f(4, 1, 0, 0);
2486
+ else
2487
+ // Walls
2488
+ gl.glVertexAttrib3f(4, 0, 1, 0);
25212489 }
25222490
25232491 /**/
....@@ -2528,28 +2496,31 @@
25282496
25292497 int resolution;
25302498
2531
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2499
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
25322500 {
2533
- texture = tex;
2501
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2502
+ texturedata = texdata;
25342503 resolution = res;
25352504 }
25362505 }
25372506 /**/
25382507
25392508 // TEXTURE static Texture texture;
2540
- static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures
2541
- = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>();
2542
- static public java.util.Hashtable<String, String> usedtextures = new java.util.Hashtable<String, String>();
2509
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2510
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2511
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2512
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2513
+
25432514 int pigmentdepth = 0;
25442515 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
25452516 int bumpdepth = 0;
25462517 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
25472518 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
25482519 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2549
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2520
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
25502521 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
25512522
2552
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2523
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
25532524 {
25542525 TextureData texturedata = null;
25552526
....@@ -2559,7 +2530,7 @@
25592530 com.sun.opengl.util.texture.TextureIO.newTextureData(
25602531 getClass().getClassLoader().getResourceAsStream(name),
25612532 true,
2562
- com.sun.opengl.util.texture.TextureIO.PNG);
2533
+ GetFormat(name)); // com.sun.opengl.util.texture.TextureIO.PNG);
25632534 } catch (java.io.IOException e)
25642535 {
25652536 throw new javax.media.opengl.GLException(e);
....@@ -2568,13 +2539,34 @@
25682539 if (bump)
25692540 texturedata = ConvertBump(texturedata, false);
25702541
2571
- com.sun.opengl.util.texture.Texture texture =
2572
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2542
+// com.sun.opengl.util.texture.Texture texture =
2543
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
25732544
2574
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2575
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
2545
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2546
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
25762547
2577
- return texture;
2548
+ return texturedata;
2549
+ }
2550
+
2551
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2552
+ {
2553
+ TextureData texturedata = null;
2554
+
2555
+ try
2556
+ {
2557
+ texturedata =
2558
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2559
+ bim,
2560
+ true);
2561
+ } catch (Exception e)
2562
+ {
2563
+ throw new javax.media.opengl.GLException(e);
2564
+ }
2565
+
2566
+ if (bump)
2567
+ texturedata = ConvertBump(texturedata, false);
2568
+
2569
+ return texturedata;
25782570 }
25792571
25802572 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3647,6 +3639,8 @@
36473639
36483640 System.out.println("LOADING TEXTURE : " + name);
36493641
3642
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3643
+
36503644 //
36513645 if (false) // compressbit > 0)
36523646 {
....@@ -8045,7 +8039,7 @@
80458039 String pigment = Object3D.GetPigment(tex);
80468040 String bump = Object3D.GetBump(tex);
80478041
8048
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8042
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
80498043 {
80508044 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
80518045 // System.out.println("; bump = " + bump);
....@@ -8060,8 +8054,8 @@
80608054 pigment = null;
80618055 }
80628056
8063
- ReleaseTexture(bump, true);
8064
- ReleaseTexture(pigment, false);
8057
+ ReleaseTexture(tex, true);
8058
+ ReleaseTexture(tex, false);
80658059 }
80668060
80678061 public void ReleasePigmentTexture(cTexture tex) // INTERFACE
....@@ -8079,7 +8073,7 @@
80798073
80808074 String pigment = Object3D.GetPigment(tex);
80818075
8082
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8076
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
80838077 {
80848078 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
80858079 // System.out.println("; bump = " + bump);
....@@ -8090,7 +8084,7 @@
80908084 pigment = null;
80918085 }
80928086
8093
- ReleaseTexture(pigment, false);
8087
+ ReleaseTexture(tex, false);
80948088 }
80958089
80968090 public void ReleaseBumpTexture(cTexture tex) // INTERFACE
....@@ -8108,7 +8102,7 @@
81088102
81098103 String bump = Object3D.GetBump(tex);
81108104
8111
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8105
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
81128106 {
81138107 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
81148108 // System.out.println("; bump = " + bump);
....@@ -8119,10 +8113,10 @@
81198113 bump = null;
81208114 }
81218115
8122
- ReleaseTexture(bump, true);
8116
+ ReleaseTexture(tex, true);
81238117 }
81248118
8125
- void ReleaseTexture(String tex, boolean bump)
8119
+ void ReleaseTexture(cTexture tex, boolean bump)
81268120 {
81278121 if (// DrawMode() != 0 || /*tex == null ||*/
81288122 ambientOcclusion ) // || !textureon)
....@@ -8133,7 +8127,7 @@
81338127 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
81348128
81358129 if (tex != null)
8136
- texture = textures.get(tex);
8130
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
81378131
81388132 // //assert( texture != null );
81398133 // if (texture == null)
....@@ -8227,47 +8221,50 @@
82278221
82288222 /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
82298223 {
8230
- if (// DrawMode() != 0 || /*tex == null ||*/
8231
- ambientOcclusion ) // || !textureon)
8232
- {
8233
- return; // false;
8234
- }
8235
-
8236
- if (tex == null)
8237
- {
8238
- BindTexture(null,false,resolution);
8239
- BindTexture(null,true,resolution);
8240
- return;
8241
- }
8224
+// if (// DrawMode() != 0 || /*tex == null ||*/
8225
+// ambientOcclusion ) // || !textureon)
8226
+// {
8227
+// return; // false;
8228
+// }
8229
+//
8230
+// if (tex == null)
8231
+// {
8232
+// BindTexture(null,false,resolution);
8233
+// BindTexture(null,true,resolution);
8234
+// return;
8235
+// }
8236
+//
8237
+// String pigment = Object3D.GetPigment(tex);
8238
+// String bump = Object3D.GetBump(tex);
8239
+//
8240
+// usedtextures.add(pigment);
8241
+// usedtextures.add(bump);
8242
+//
8243
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8244
+// {
8245
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8246
+// // System.out.println("; bump = " + bump);
8247
+// }
8248
+//
8249
+// if (bump.equals(""))
8250
+// {
8251
+// bump = null;
8252
+// }
8253
+// if (pigment.equals(""))
8254
+// {
8255
+// pigment = null;
8256
+// }
8257
+//
8258
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8259
+// BindTexture(pigment, false, resolution);
8260
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8261
+// BindTexture(bump, true, resolution);
8262
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8263
+//
8264
+// return; // true;
82428265
8243
- String pigment = Object3D.GetPigment(tex);
8244
- String bump = Object3D.GetBump(tex);
8245
-
8246
- usedtextures.put(pigment, pigment);
8247
- usedtextures.put(bump, bump);
8248
-
8249
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8250
- {
8251
- // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8252
- // System.out.println("; bump = " + bump);
8253
- }
8254
-
8255
- if (bump.equals(""))
8256
- {
8257
- bump = null;
8258
- }
8259
- if (pigment.equals(""))
8260
- {
8261
- pigment = null;
8262
- }
8263
-
8264
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8265
- BindTexture(pigment, false, resolution);
8266
- GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8267
- BindTexture(bump, true, resolution);
8268
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8269
-
8270
- return; // true;
8266
+ BindPigmentTexture(tex, resolution);
8267
+ BindBumpTexture(tex, resolution);
82718268 }
82728269
82738270 /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8286,9 +8283,9 @@
82868283
82878284 String pigment = Object3D.GetPigment(tex);
82888285
8289
- usedtextures.put(pigment, pigment);
8286
+ usedtextures.add(tex);
82908287
8291
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8288
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
82928289 {
82938290 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
82948291 // System.out.println("; bump = " + bump);
....@@ -8300,7 +8297,7 @@
83008297 }
83018298
83028299 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8303
- BindTexture(pigment, false, resolution);
8300
+ BindTexture(tex, false, resolution);
83048301 }
83058302
83068303 /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8319,9 +8316,9 @@
83198316
83208317 String bump = Object3D.GetBump(tex);
83218318
8322
- usedtextures.put(bump, bump);
8319
+ usedtextures.add(tex);
83238320
8324
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8321
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
83258322 {
83268323 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
83278324 // System.out.println("; bump = " + bump);
....@@ -8333,7 +8330,7 @@
83338330 }
83348331
83358332 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8336
- BindTexture(bump, true, resolution);
8333
+ BindTexture(tex, true, resolution);
83378334 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
83388335 }
83398336
....@@ -8357,13 +8354,19 @@
83578354 return fileExists;
83588355 }
83598356
8360
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception
8357
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
83618358 {
8362
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8359
+ CacheTexture texturecache = null;
83638360
83648361 if (tex != null)
83658362 {
8366
- String texname = tex;
8363
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8364
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
8365
+
8366
+ if (texname.equals("") && texdata == null)
8367
+ {
8368
+ return null;
8369
+ }
83678370
83688371 String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
83698372
....@@ -8373,19 +8376,46 @@
83738376 // else
83748377 // if (!texname.startsWith("/"))
83758378 // texname = "/Users/nbriere/Textures/" + texname;
8376
- if (!FileExists(tex))
8379
+ if (!FileExists(texname) && !texname.startsWith("@"))
83778380 {
83788381 texname = fallbackTextureName;
83798382 }
83808383
83818384 if (CACHETEXTURE)
8382
- texture = textures.get(texname); // TEXTURE CACHE
8383
-
8384
- TextureData texturedata = null;
8385
-
8386
- if (texture == null || texture.resolution < resolution)
83878385 {
8388
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8386
+ if (texdata == null)
8387
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8388
+ else
8389
+ texturecache = bimtextures.get(texdata);
8390
+ }
8391
+
8392
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8393
+ {
8394
+ TextureData texturedata = null;
8395
+
8396
+ if (texdata != null && textureon)
8397
+ {
8398
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8399
+
8400
+ try
8401
+ {
8402
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8403
+ }
8404
+ catch (Exception e)
8405
+ {
8406
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8407
+ }
8408
+
8409
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8410
+ bimtextures.put(texdata, texturecache);
8411
+
8412
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8413
+
8414
+ //Object bim2 = CreateBim(texturecache.texturedata);
8415
+ //bim2 = bim;
8416
+ }
8417
+ else
8418
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
83898419 {
83908420 assert(!bump);
83918421 // if (bump)
....@@ -8396,19 +8426,23 @@
83968426 // }
83978427 // else
83988428 // {
8399
- texture = textures.get(tex);
8400
- if (texture == null)
8429
+ // texturecache = textures.get(texname); // suspicious
8430
+ if (texturecache == null)
84018431 {
8402
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8432
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
84038433 }
8434
+ else
8435
+ new Exception().printStackTrace();
84048436 // }
84058437 } else
8406
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8438
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
84078439 {
84088440 assert(bump);
8409
- texture = textures.get(tex);
8410
- if (texture == null)
8411
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8441
+ // texturecache = textures.get(texname); // suspicious
8442
+ if (texturecache == null)
8443
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8444
+ else
8445
+ new Exception().printStackTrace();
84128446 } else
84138447 {
84148448 //if (tex.equals("IMMORTAL"))
....@@ -8416,11 +8450,22 @@
84168450 // texture = GetResourceTexture("default.png");
84178451 //} else
84188452 //{
8419
- if (tex.equals("WHITE_NOISE"))
8453
+ if (texname.endsWith("WHITE_NOISE"))
84208454 {
8421
- texture = textures.get(tex);
8422
- if (texture == null)
8423
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8455
+ // texturecache = textures.get(texname); // suspicious
8456
+ if (texturecache == null)
8457
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8458
+ else
8459
+ new Exception().printStackTrace();
8460
+ } else
8461
+ {
8462
+ if (texname.startsWith("@"))
8463
+ {
8464
+ // texturecache = textures.get(texname); // suspicious
8465
+ if (texturecache == null)
8466
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8467
+ else
8468
+ new Exception().printStackTrace();
84248469 } else
84258470 {
84268471 if (textureon)
....@@ -8479,19 +8524,20 @@
84798524 if (texturedata == null)
84808525 throw new Exception();
84818526
8482
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8527
+ texturecache = new CacheTexture(texturedata,resolution);
84838528 //texture = GetTexture(tex, bump);
84848529 }
8530
+ }
84858531 }
84868532 //}
84878533 }
84888534
8489
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8535
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
84908536 {
84918537 //return false;
84928538
84938539 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8494
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8540
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
84958541 {
84968542 // String ext = "_highres";
84978543 // if (REDUCETEXTURE)
....@@ -8508,52 +8554,17 @@
85088554 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
85098555 if (!cachefile.exists())
85108556 {
8511
- // cache to disk
8512
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
8513
- //buffers[0].
8514
-
8515
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
8516
- int[] pixels = new int[bytebuf.capacity()/3];
8517
-
8518
- // squared size heuristic...
8519
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8557
+ //if (texturedata.getWidth() == texturedata.getHeight())
85208558 {
8521
- for (int i=pixels.length; --i>=0;)
8522
- {
8523
- int i3 = i*3;
8524
- pixels[i] = 0xFF;
8525
- pixels[i] <<= 8;
8526
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
8527
- pixels[i] <<= 8;
8528
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
8529
- pixels[i] <<= 8;
8530
- pixels[i] |= bytebuf.get(i3) & 0xFF;
8531
- }
8532
-
8533
- /*
8534
- int r=0,g=0,b=0,a=0;
8535
- for (int i=0; i<width; i++)
8536
- for (int j=0; j<height; j++)
8537
- {
8538
- int index = j*width+i;
8539
- int p = pixels[index];
8540
- a = ((p>>24) & 0xFF);
8541
- r = ((p>>16) & 0xFF);
8542
- g = ((p>>8) & 0xFF);
8543
- b = (p & 0xFF);
8544
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
8545
- }
8546
- /**/
8547
- int width = (int)Math.sqrt(pixels.length); // squared
8548
- int height = width;
8549
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
8550
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8559
+ BufferedImage rendImage = CreateBim(texturedata);
8560
+
85518561 ImageWriter writer = null;
85528562 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
85538563 if (iter.hasNext()) {
85548564 writer = (ImageWriter)iter.next();
85558565 }
8556
- float compressionQuality = 0.9f;
8566
+
8567
+ float compressionQuality = 0.85f;
85578568 try
85588569 {
85598570 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8570,18 +8581,20 @@
85708581 }
85718582 }
85728583 }
8573
-
8584
+
8585
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8586
+
85748587 //System.out.println("Texture = " + tex);
8575
- if (textures.containsKey(texname))
8588
+ if (textures.containsKey(tex))
85768589 {
8577
- CacheTexture thetex = textures.get(texname);
8590
+ CacheTexture thetex = textures.get(tex);
85788591 thetex.texture.disable();
85798592 thetex.texture.dispose();
8580
- textures.remove(texname);
8593
+ textures.remove(tex);
85818594 }
85828595
8583
- texture.texturedata = texturedata;
8584
- textures.put(texname, texture);
8596
+ //texture.texturedata = texturedata;
8597
+ textures.put(tex, texturecache);
85858598
85868599 // newtex = true;
85878600 }
....@@ -8597,10 +8610,44 @@
85978610 }
85988611 }
85998612
8600
- return texture;
8613
+ return texturecache;
86018614 }
86028615
8603
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution) throws Exception
8616
+ static void EmbedTextures(cTexture tex)
8617
+ {
8618
+ if (tex.pigmentdata == null)
8619
+ {
8620
+ //String texname = Object3D.GetPigment(tex);
8621
+
8622
+ CacheTexture texturecache = texturepigment.get(tex);
8623
+
8624
+ if (texturecache != null)
8625
+ {
8626
+ tex.pw = texturecache.texturedata.getWidth();
8627
+ tex.ph = texturecache.texturedata.getHeight();
8628
+ tex.pigmentdata = //CompressJPEG(CreateBim
8629
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8630
+ ;
8631
+ //, tex.pw, tex.ph), 0.5f);
8632
+ }
8633
+ }
8634
+
8635
+ if (tex.bumpdata == null)
8636
+ {
8637
+ //String texname = Object3D.GetBump(tex);
8638
+
8639
+ CacheTexture texturecache = texturebump.get(tex);
8640
+
8641
+ if (texturecache != null)
8642
+ {
8643
+ tex.bw = texturecache.texturedata.getWidth();
8644
+ tex.bh = texturecache.texturedata.getHeight();
8645
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8646
+ }
8647
+ }
8648
+ }
8649
+
8650
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
86048651 {
86058652 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
86068653
....@@ -8618,21 +8665,21 @@
86188665 return texture!=null?texture.texture:null;
86198666 }
86208667
8621
- public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution) throws Exception
8668
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
86228669 {
86238670 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
86248671
86258672 return texture!=null?texture.texturedata:null;
86268673 }
86278674
8628
- boolean BindTexture(String tex, boolean bump, int resolution) throws Exception
8675
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
86298676 {
86308677 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
86318678 {
86328679 return false;
86338680 }
86348681
8635
- boolean newtex = false;
8682
+ //boolean newtex = false;
86368683
86378684 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
86388685
....@@ -8664,9 +8711,75 @@
86648711 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
86658712 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
86668713
8667
- return newtex;
8714
+ return true; // Warning: not used.
86688715 }
86698716
8717
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8718
+ {
8719
+ try
8720
+ {
8721
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8722
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8723
+ ImageWriter writer = writers.next();
8724
+
8725
+ ImageWriteParam param = writer.getDefaultWriteParam();
8726
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8727
+ param.setCompressionQuality(quality);
8728
+
8729
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8730
+ writer.setOutput(ios);
8731
+ writer.write(null, new IIOImage(image, null, null), param);
8732
+
8733
+ byte[] data = baos.toByteArray();
8734
+ writer.dispose();
8735
+ return data;
8736
+ }
8737
+ catch (Exception e)
8738
+ {
8739
+ e.printStackTrace();
8740
+ return null;
8741
+ }
8742
+ }
8743
+
8744
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8745
+ {
8746
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8747
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8748
+ ImageReader reader = writers.next();
8749
+
8750
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8751
+
8752
+ ImageReadParam param = reader.getDefaultReadParam();
8753
+ param.setDestination(bim);
8754
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8755
+
8756
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8757
+ reader.setInput(ios);
8758
+ BufferedImage bim2 = reader.read(0, param);
8759
+ reader.dispose();
8760
+
8761
+// WritableRaster raster = bim2.getRaster();
8762
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8763
+// byte[] bytes = data.getData();
8764
+//
8765
+// int[] pixels = new int[bytes.length/3];
8766
+// for (int i=pixels.length; --i>=0;)
8767
+// {
8768
+// int i3 = i*3;
8769
+// pixels[i] = 0xFF;
8770
+// pixels[i] <<= 8;
8771
+// pixels[i] |= bytes[i3+2] & 0xFF;
8772
+// pixels[i] <<= 8;
8773
+// pixels[i] |= bytes[i3+1] & 0xFF;
8774
+// pixels[i] <<= 8;
8775
+// pixels[i] |= bytes[i3] & 0xFF;
8776
+// }
8777
+//
8778
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8779
+
8780
+ return bim;
8781
+ }
8782
+
86708783 ShadowBuffer shadowPBuf;
86718784 AntialiasBuffer antialiasPBuf;
86728785 int MAXSTACK;
....@@ -8683,10 +8796,12 @@
86838796
86848797 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
86858798 MAXSTACK = temp[0];
8686
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8799
+ if (Globals.DEBUG)
8800
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
86878801 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
86888802 MAXSTACK = temp[0];
8689
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8803
+ if (Globals.DEBUG)
8804
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
86908805
86918806 // Use debug pipeline
86928807 //drawable.setGL(new DebugGL(gl)); //
....@@ -8694,7 +8809,8 @@
86948809 gl = drawable.getGL(); //
86958810
86968811 GL gl3 = getGL();
8697
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8812
+ if (Globals.DEBUG)
8813
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
86988814
86998815
87008816 //float pos[] = { 100, 100, 100, 0 };
....@@ -8859,7 +8975,7 @@
88598975
88608976 if (cubemap == null)
88618977 {
8862
- LoadEnvy(5);
8978
+ //LoadEnvy(1);
88638979 }
88648980
88658981 //cubemap.enable();
....@@ -9135,6 +9251,8 @@
91359251
91369252 void LoadEnvy(int which)
91379253 {
9254
+ assert(false);
9255
+
91389256 String name;
91399257 String ext;
91409258
....@@ -9146,37 +9264,58 @@
91469264 cubemap = null;
91479265 return;
91489266 case 1:
9149
- name = "cubemaps/box_";
9150
- ext = "png";
9267
+ name = "cubemaps/rgb/";
9268
+ ext = "jpg";
91519269 reverseUP = false;
91529270 break;
91539271 case 2:
9154
- name = "cubemaps/uffizi_";
9155
- ext = "png";
9156
- break; // reverseUP = true; break;
9272
+ name = "cubemaps/uffizi/";
9273
+ ext = "jpg";
9274
+ reverseUP = false;
9275
+ break;
91579276 case 3:
9158
- name = "cubemaps/CloudyHills_";
9159
- ext = "tga";
9277
+ name = "cubemaps/CloudyHills/";
9278
+ ext = "jpg";
91609279 reverseUP = false;
91619280 break;
91629281 case 4:
9163
- name = "cubemaps/cornell_";
9282
+ name = "cubemaps/cornell/";
91649283 ext = "png";
91659284 reverseUP = false;
91669285 break;
9286
+ case 5:
9287
+ name = "cubemaps/skycube/";
9288
+ ext = "jpg";
9289
+ reverseUP = false;
9290
+ break;
9291
+ case 6:
9292
+ name = "cubemaps/SaintLazarusChurch3/";
9293
+ ext = "jpg";
9294
+ reverseUP = false;
9295
+ break;
9296
+ case 7:
9297
+ name = "cubemaps/Sodermalmsallen/";
9298
+ ext = "jpg";
9299
+ reverseUP = false;
9300
+ break;
9301
+ case 8:
9302
+ name = "cubemaps/Sodermalmsallen2/";
9303
+ ext = "jpg";
9304
+ reverseUP = false;
9305
+ break;
9306
+ case 9:
9307
+ name = "cubemaps/UnionSquare/";
9308
+ ext = "jpg";
9309
+ reverseUP = false;
9310
+ break;
91679311 default:
9168
- name = "cubemaps/rgb_";
9169
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9312
+ name = "cubemaps/box/";
9313
+ ext = "png"; /*mipmap = true;*/
9314
+ reverseUP = false;
91709315 break;
91719316 }
9172
-
9173
- try
9174
- {
9175
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
9176
- } catch (IOException e)
9177
- {
9178
- throw new RuntimeException(e);
9179
- }
9317
+
9318
+ LoadSkybox(name, ext, mipmap);
91809319 }
91819320
91829321 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -9208,8 +9347,12 @@
92089347 static double[] model = new double[16];
92099348 double[] camera2light = new double[16];
92109349 double[] light2camera = new double[16];
9211
- int newenvy = -1;
9212
- boolean envyoff = true; // false;
9350
+
9351
+ //int newenvy = -1;
9352
+ //boolean envyoff = false;
9353
+
9354
+ String loadedskyboxname;
9355
+
92139356 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
92149357 //float[] light0 = { 0,0,0 };
92159358 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9627,7 +9770,7 @@
96279770
96289771 if (renderCamera != lightCamera)
96299772 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9630
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
9773
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
96319774
96329775 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
96339776
....@@ -9643,7 +9786,7 @@
96439786
96449787 if (renderCamera != lightCamera)
96459788 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9646
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
9789
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
96479790
96489791 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
96499792
....@@ -9689,10 +9832,12 @@
96899832 rati = 1 / rati;
96909833 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
96919834 }
9692
- assert (newenvy == -1);
9835
+
9836
+ //assert (newenvy == -1);
9837
+
96939838 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
96949839 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9695
- DrawSkyBox(gl);
9840
+ DrawSkyBox(gl, (float)rati);
96969841 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
96979842 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
96989843 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10558,9 +10703,18 @@
1055810703 static boolean init = false;
1055910704
1056010705 double[][] matrix = LA.newMatrix();
10706
+
10707
+ // This is to refresh the UI of the material panel.
10708
+ ObjEditor patchMaterial;
1056110709
1056210710 public void display(GLAutoDrawable drawable)
1056310711 {
10712
+ if (patchMaterial.patchMaterial)
10713
+ {
10714
+ patchMaterial.patchMaterial = false;
10715
+ patchMaterial.objectPanel.setSelectedIndex(1);
10716
+ }
10717
+
1056410718 if (Grafreed.savesound && Grafreed.hassound)
1056510719 {
1056610720 Grafreed.wav.save();
....@@ -10729,7 +10883,7 @@
1072910883
1073010884 if (wait)
1073110885 {
10732
- Sleep(500);
10886
+ Sleep(200); // blocks everything
1073310887
1073410888 wait = false;
1073510889 }
....@@ -10844,7 +10998,7 @@
1084410998 // if (parentcam != renderCamera) // not a light
1084510999 if (cam != lightCamera)
1084611000 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10847
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
11001
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1084811002
1084911003 for (int j = 0; j < 4; j++)
1085011004 {
....@@ -10859,7 +11013,7 @@
1085911013 // if (parentcam != renderCamera) // not a light
1086011014 if (cam != lightCamera)
1086111015 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10862
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
11016
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1086311017
1086411018 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1086511019
....@@ -10945,13 +11099,43 @@
1094511099 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1094611100 }
1094711101
10948
- if (newenvy > -1)
11102
+// if (newenvy > -1)
11103
+// {
11104
+// LoadEnvy(newenvy);
11105
+// }
11106
+//
11107
+// newenvy = -1;
11108
+
11109
+ if (transformMode) // object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
1094911110 {
10950
- LoadEnvy(newenvy);
11111
+ if (cubemaprgb == null)
11112
+ {
11113
+ cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb2" + "/", "jpg", false);
11114
+ }
11115
+
11116
+ cubemap = cubemaprgb;
1095111117 }
10952
-
10953
- newenvy = -1;
10954
-
11118
+ else
11119
+ {
11120
+ if (object.skyboxname != null)
11121
+ {
11122
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11123
+ {
11124
+ if (cubemap != null && cubemap != cubemaprgb)
11125
+ cubemap.dispose();
11126
+ cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11127
+ loadedskyboxname = object.skyboxname;
11128
+ }
11129
+ }
11130
+ else
11131
+ {
11132
+ cubemapcustom = null;
11133
+ loadedskyboxname = null;
11134
+ }
11135
+
11136
+ cubemap = cubemapcustom;
11137
+ }
11138
+
1095511139 ratio = ((double) getWidth()) / getHeight();
1095611140 //System.out.println("ratio = " + ratio);
1095711141
....@@ -10967,7 +11151,7 @@
1096711151
1096811152 if (!IsFrozen() && !ambientOcclusion)
1096911153 {
10970
- DrawSkyBox(gl);
11154
+ DrawSkyBox(gl, (float)ratio);
1097111155 }
1097211156
1097311157 //if (selection_view == -1)
....@@ -11150,9 +11334,9 @@
1115011334
1115111335 gl.glMatrixMode(GL.GL_MODELVIEW);
1115211336
11153
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11154
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
11155
-//gl.glEnable(gl.GL_MULTISAMPLE);
11337
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11338
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11339
+gl.glEnable(gl.GL_MULTISAMPLE);
1115611340 } else
1115711341 {
1115811342 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -11163,7 +11347,7 @@
1116311347 //System.out.println("BLENDING ON");
1116411348 gl.glEnable(GL.GL_BLEND);
1116511349 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
11166
-
11350
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1116711351 gl.glMatrixMode(gl.GL_PROJECTION);
1116811352 gl.glLoadIdentity();
1116911353
....@@ -11253,7 +11437,7 @@
1125311437
1125411438 // if (cam != lightCamera)
1125511439 //for (int count = parentcam.GetTransformCount(); --count>=0;)
11256
- LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
11440
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1125711441 }
1125811442
1125911443 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -11412,7 +11596,7 @@
1141211596 }
1141311597 }
1141411598
11415
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11599
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1141611600 {
1141711601 //gl.glDepthFunc(GL.GL_LEQUAL);
1141811602 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11420,24 +11604,21 @@
1142011604
1142111605 boolean texon = textureon;
1142211606
11423
- if (RENDERPROGRAM > 0)
11424
- {
11425
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11426
- textureon = false;
11427
- }
11607
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11608
+ textureon = false;
11609
+
1142811610 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1142911611 //System.out.println("ALLO");
1143011612 gl.glColorMask(false, false, false, false);
1143111613 DrawObject(gl);
11432
- if (RENDERPROGRAM > 0)
11433
- {
11434
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11435
- textureon = texon;
11436
- }
11614
+
11615
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11616
+ textureon = texon;
11617
+
1143711618 gl.glColorMask(true, true, true, true);
1143811619
1143911620 gl.glDepthFunc(GL.GL_EQUAL);
11440
- //gl.glDepthMask(false);
11621
+ gl.glDepthMask(false);
1144111622 }
1144211623
1144311624 if (false) // DrawMode() == SHADOW)
....@@ -11649,7 +11830,7 @@
1164911830 if ((TRACK || SHADOWTRACK) || zoomonce)
1165011831 {
1165111832 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11652
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11833
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1165311834 pingthread.StepToTarget(true); // true);
1165411835 // zoomonce = false;
1165511836 }
....@@ -11777,20 +11958,32 @@
1177711958 ReleaseTextures(DEFAULT_TEXTURES);
1177811959
1177911960 if (CLEANCACHE)
11780
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11961
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1178111962 {
11782
- String tex = e.nextElement();
11963
+ cTexture tex = e.nextElement();
1178311964
1178411965 // System.out.println("Texture --------- " + tex);
1178511966
11786
- if (tex.equals("WHITE_NOISE"))
11967
+ if (tex.equals("WHITE_NOISE:"))
1178711968 continue;
1178811969
11789
- if (!usedtextures.containsKey(tex))
11970
+ if (!usedtextures.contains(tex))
1179011971 {
11972
+ CacheTexture gettex = texturepigment.get(tex);
1179111973 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11792
- textures.get(tex).texture.dispose();
11793
- textures.remove(tex);
11974
+ if (gettex != null)
11975
+ {
11976
+ gettex.texture.dispose();
11977
+ texturepigment.remove(tex);
11978
+ }
11979
+
11980
+ gettex = texturebump.get(tex);
11981
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11982
+ if (gettex != null)
11983
+ {
11984
+ gettex.texture.dispose();
11985
+ texturebump.remove(tex);
11986
+ }
1179411987 }
1179511988 }
1179611989 }
....@@ -12318,8 +12511,76 @@
1231812511
1231912512 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1232012513
12321
- String program =
12514
+ String programmin =
12515
+ // Min shader
1232212516 "!!ARBfp1.0\n" +
12517
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12518
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12519
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12520
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12521
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12522
+ "PARAM light2cam0 = program.env[10];" +
12523
+ "PARAM light2cam1 = program.env[11];" +
12524
+ "PARAM light2cam2 = program.env[12];" +
12525
+ "TEMP temp;" +
12526
+ "TEMP light;" +
12527
+ "TEMP ndotl;" +
12528
+ "TEMP normal;" +
12529
+ "TEMP depth;" +
12530
+ "TEMP eye;" +
12531
+ "TEMP pos;" +
12532
+
12533
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12534
+ Normalize("normal") +
12535
+ "MOV light, state.light[0].position;" +
12536
+ "DP3 ndotl.x, light, normal;" +
12537
+
12538
+ // shadow
12539
+ "MOV pos, fragment.texcoord[1];" +
12540
+ "MOV temp, pos;" +
12541
+ ShadowTextureFetch("depth", "temp", "1") +
12542
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12543
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12544
+
12545
+ // No shadow when out of frustum
12546
+ //"SGE temp.y, depth.z, zero123.y;" +
12547
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12548
+
12549
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12550
+
12551
+ // Backlit
12552
+ "MOV pos.w, zero123.y;" +
12553
+ "DP4 eye.x, pos, light2cam0;" +
12554
+ "DP4 eye.y, pos, light2cam1;" +
12555
+ "DP4 eye.z, pos, light2cam2;" +
12556
+ Normalize("eye") +
12557
+
12558
+ "DP3 ndotl.y, -eye, normal;" +
12559
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12560
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12561
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12562
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12563
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12564
+
12565
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12566
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12567
+
12568
+ // Pigment
12569
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12570
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12571
+ "MUL temp, temp, ndotl.x;" +
12572
+
12573
+ "MUL temp, temp, zero123.z;" +
12574
+
12575
+ //"MUL temp, temp, ndotl.y;" +
12576
+
12577
+ "MOV temp.w, zero123.y;" + // reset alpha
12578
+ "MOV result.color, temp;" +
12579
+ "END";
12580
+
12581
+ String programmax =
12582
+ "!!ARBfp1.0\n" +
12583
+
1232312584 //"OPTION ARB_fragment_program_shadow;" +
1232412585 "PARAM light2cam0 = program.env[10];" +
1232512586 "PARAM light2cam1 = program.env[11];" +
....@@ -12345,7 +12606,7 @@
1234512606 "PARAM params4 = program.env[4];" + // anisoV, cameralight, selfshadow, shadow
1234612607 "PARAM params5 = program.env[5];" + // texture, opacity, fakedepth, shadowbias
1234712608 "PARAM params6 = program.env[6];" + // bump, noise, borderfade, fog punchthrough
12348
- "PARAM params7 = program.env[7];" + // noise power, opacity power
12609
+ "PARAM params7 = program.env[7];" + // noise power, opacity power, parallax
1234912610 "PARAM options0 = program.env[63];" + // fog density, intensity, elevation
1235012611 "PARAM options1 = program.env[62];" + // fog rgb color
1235112612 "PARAM options2 = program.env[61];" + // image intensity, subsurface, lightsheen
....@@ -12434,8 +12695,7 @@
1243412695 "TEMP shininess;" +
1243512696 "\n" +
1243612697 "MOV texSamp, one;" +
12437
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12438
-
12698
+
1243912699 "MOV mapgrid.x, one2048th.x;" +
1244012700 "MOV temp, fragment.texcoord[1];" +
1244112701 /*
....@@ -12456,20 +12716,20 @@
1245612716 "MUL temp, floor, mapgrid.x;" +
1245712717 //"TEX depth0, temp, texture[1], 2D;" +
1245812718 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12459
- TextureFetch("depth0", "temp", "1") +
12719
+ ShadowTextureFetch("depth0", "temp", "1") +
1246012720 "") +
1246112721 "ADD temp.x, temp.x, mapgrid.x;" +
1246212722 //"TEX depth1, temp, texture[1], 2D;" +
1246312723 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12464
- TextureFetch("depth1", "temp", "1") +
12724
+ ShadowTextureFetch("depth1", "temp", "1") +
1246512725 "") +
1246612726 "ADD temp.y, temp.y, mapgrid.x;" +
1246712727 //"TEX depth2, temp, texture[1], 2D;" +
12468
- TextureFetch("depth2", "temp", "1") +
12728
+ ShadowTextureFetch("depth2", "temp", "1") +
1246912729 "SUB temp.x, temp.x, mapgrid.x;" +
1247012730 //"TEX depth3, temp, texture[1], 2D;" +
1247112731 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12472
- TextureFetch("depth3", "temp", "1") +
12732
+ ShadowTextureFetch("depth3", "temp", "1") +
1247312733 "") +
1247412734 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1247512735 //"MOV params, material;" +
....@@ -12591,7 +12851,7 @@
1259112851 "POW texSamp.a, texSamp.a, params6.w;" + // fog punch through shortcut
1259212852 // mar 2013 ??? "KIL alpha.a;" +
1259312853 "MOV alpha, texSamp.aaaa;" + // y;" +
12594
- "KIL alpha.a;" +
12854
+ "KIL alpha.a;" + // not sure with parallax mapping
1259512855 /*
1259612856 "MUL temp.xy, temp, two;" +
1259712857 "TXB bump, temp, texture[0], 2D;" +
....@@ -12677,11 +12937,6 @@
1267712937 "SUB bump0, bump0, half;" +
1267812938 "ADD bump, bump, bump0;" +
1267912939
12680
- "MOV temp.x, texSamp.a;" +
12681
- "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
12682
- //"LRP texSamp0, params5.x, texSamp0, one;" +
12683
- "MOV texSamp.a, temp.x;" +
12684
-
1268512940 // double-sided
1268612941 /**/
1268712942 (doublesided?"DP3 temp.z, normal, eye;" +
....@@ -12698,19 +12953,62 @@
1269812953 "MOV normald, normal;" +
1269912954 "MOV normals, normal;" +
1270012955
12956
+ "MOV temp, fragment.texcoord[4];" +
12957
+
1270112958 // UV base
1270212959 //"DP3 UP.x,state.matrix.modelview.row[0],Y;" +
1270312960 //"DP3 UP.y,state.matrix.modelview.row[1],Y;" +
1270412961 //"DP3 UP.z,state.matrix.modelview.row[2],Y;" +
12705
- "DP3 UP.x,state.matrix.texture[7].row[0],Y;" +
12706
- "DP3 UP.y,state.matrix.texture[7].row[1],Y;" +
12707
- "DP3 UP.z,state.matrix.texture[7].row[2],Y;" +
12962
+ "DP3 UP.x,state.matrix.texture[7].row[0],temp;" +
12963
+ "DP3 UP.y,state.matrix.texture[7].row[1],temp;" +
12964
+ "DP3 UP.z,state.matrix.texture[7].row[2],temp;" +
12965
+ Normalize("UP") +
12966
+
1270812967 "XPD V, normal, UP;" +
1270912968 Normalize("V") +
1271012969 "XPD U, V, normal;" +
1271112970 Normalize("U") +
1271212971
1271312972 // parallax mapping
12973
+
12974
+ "DP3 temp2.x, V, eye;" +
12975
+ "DP3 temp2.y, U, eye;" +
12976
+ "DP3 temp2.z, normal, eye;" +
12977
+ "RCP temp2.z, temp2.z;" +
12978
+
12979
+ "DP3 temp2.w, texSamp, texSamp;" + // Height
12980
+ "RSQ temp2.w, temp2.w;" +
12981
+ "RCP temp2.w, temp2.w;" +
12982
+
12983
+ "SUB temp2.w, temp2.w, half;" +
12984
+// "SGE temp.x, temp2.w, eps.x;" +
12985
+// "MUL temp2.w, temp2.w, temp.x;" +
12986
+
12987
+ //"MOV texSamp, U;" +
12988
+
12989
+ "MUL temp2.z, temp2.z, temp2.w;" +
12990
+ "MUL temp2.z, temp2.z, params7.z;" + // parallax
12991
+
12992
+ "MUL temp2, temp2, temp2.z;" +
12993
+
12994
+ "MOV temp, fragment.texcoord[0];" +
12995
+
12996
+ "SUB temp, temp, temp2;" +
12997
+
12998
+ "TEX temp, temp, texture[0], 2D;" +
12999
+ "POW temp.a, temp.a, params6.w;" + // punch through
13000
+
13001
+ "ADD texSamp, temp, texSamp;" +
13002
+ "MUL temp.xyz, half, texSamp;" +
13003
+
13004
+ "MOV alpha, texSamp.aaaa;" +
13005
+
13006
+// parallax mapping
13007
+
13008
+ "MOV temp.x, texSamp.a;" +
13009
+ "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
13010
+ //"LRP texSamp0, params5.x, texSamp0, one;" +
13011
+ "MOV texSamp.a, temp.x;" +
1271413012
1271513013 //"MOV temp, fragment.texcoord[0];" +
1271613014 //
....@@ -12840,10 +13138,10 @@
1284013138 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1284113139 "") +
1284213140
12843
- // display shadow only (bump == 0)
13141
+ // display shadow only (fakedepth == 0)
1284413142 "SUB temp.x, half.x, shadow.x;" +
1284513143 "MOV temp.y, -params5.z;" + // params6.x;" +
12846
- "SLT temp.z, temp.y, -one2048th.x;" +
13144
+ "SLT temp.z, temp.y, -c256i.x;" +
1284713145 "SUB temp.y, one.x, temp.z;" +
1284813146 "MUL temp.x, temp.x, temp.y;" +
1284913147 "KIL temp.x;" +
....@@ -13174,8 +13472,19 @@
1317413472 //once = true;
1317513473 }
1317613474
13177
- System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13178
- System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13475
+ String program = programmax;
13476
+
13477
+ if (Globals.MINSHADER)
13478
+ {
13479
+ program = programmin;
13480
+ }
13481
+
13482
+ if (Globals.DEBUG)
13483
+ {
13484
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13485
+ System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13486
+ }
13487
+
1317913488 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1318013489
1318113490 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -13222,7 +13531,8 @@
1322213531 "\n" +
1322313532 "END\n";
1322413533
13225
- System.out.println("Program shadow #" + 0 + "; length = " + program.length());
13534
+ if (Globals.DEBUG)
13535
+ System.out.println("Program shadow #" + 0 + "; length = " + program.length());
1322613536 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1322713537
1322813538 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -13267,25 +13577,26 @@
1326713577 return out;
1326813578 }
1326913579
13270
- String TextureFetch(String dest, String src, String unit)
13580
+ // Also does frustum culling
13581
+ String ShadowTextureFetch(String dest, String src, String unit)
1327113582 {
1327213583 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1327313584 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1327413585 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13586
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13587
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1327513588 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13276
- "SLT " + src + ".z, " + src + ".x, one.x;" +
13277
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13278
- "SLT " + src + ".z, " + src + ".y, one.x;" +
13279
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13589
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13590
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1328013591 //"SWZ buffer, temp, w,w,w,w;";
13281
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13592
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1328213593 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1328313594 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1328413595 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13285
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13596
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1328613597
13287
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13288
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13598
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13599
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1328913600 }
1329013601
1329113602 String Shadow(String depth, String shadow)
....@@ -13332,7 +13643,7 @@
1333213643 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1333313644 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1333413645
13335
- // No shadow when out of frustrum
13646
+ // No shadow when out of frustum
1333613647 "SGE temp.x, " + depth + ".z, one.z;" +
1333713648 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1333813649 "";
....@@ -13479,7 +13790,7 @@
1347913790 /*static*/ float[] modelParams4 = new float[]{0, 0, 0, 0}; // anisoV, cameralight, selfshadow, shadow
1348013791 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1348113792 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
13482
- /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13793
+ /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power, parallax
1348313794
1348413795 //Object3D.cVector2[] vector2buffer;
1348513796
....@@ -13646,7 +13957,7 @@
1364613957 "PARAM p[4] = { state.matrix.projection }; # modelview projection matrix\n" +
1364713958 "PARAM zero = { 0.0, 0.0, 0.0, 1.0 };" +
1364813959 "PARAM half = { 0.5, 0.5, 0.5, 1.0 };" +
13649
- "PARAM one = { 1.0, 1.0, 1.0, 0.0 };" +
13960
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
1365013961 "PARAM two = { 2.0, 2.0, 2.0, 1.0 };" +
1365113962 "PARAM third = { 0.33333333333, 0.33333333333, 0.33333333333, 1.0 };" +
1365213963 //"PARAM v256 = { 256.0, 256.0, 256.0, 1.0 };" +
....@@ -13707,7 +14018,7 @@
1370714018 "DP4 temp.x,state.matrix.texture[0].inverse.row[0],vertex.texcoord;" +
1370814019 "DP4 temp.y,state.matrix.texture[0].inverse.row[1],vertex.texcoord;" +
1370914020 "DP4 temp.z,state.matrix.texture[0].inverse.row[2],vertex.texcoord;" +
13710
- //"MOV result.texcoord, vertex.texcoord;" +
14021
+ //"MOV result.texcoord, vertex.fogcoord;" +
1371114022 "MOV result.texcoord, temp;" +
1371214023 // border fade
1371314024 "MOV result.texcoord[3], vertex.texcoord;" +
....@@ -13754,7 +14065,9 @@
1375414065
1375514066 //"ADD temp.z, temp.z, one;" +
1375614067
13757
- "MOV result.color, temp;"
14068
+ "MOV result.texcoord[4], vertex.attrib[4];" + // U dir
14069
+
14070
+ "MOV result.color, temp;" // Normal
1375814071 : "MOV result.color, vertex.color;") +
1375914072 ((mode & VP_PROJECTION) != 0 ? "MOV result.color, zero;"
1376014073 : "") +
....@@ -14065,7 +14378,7 @@
1406514378
1406614379 // fev 2014???
1406714380 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
14068
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14381
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1406914382 pingthread.StepToTarget(true); // true);
1407014383 }
1407114384 // if (!LIVE)
....@@ -14130,14 +14443,15 @@
1413014443 drag = false;
1413114444 //System.out.println("Mouse DOWN");
1413214445 editObj = false;
14133
- ClickInfo info = new ClickInfo();
14134
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14135
- info.pane = this;
14136
- info.camera = renderCamera;
14137
- info.x = x;
14138
- info.y = y;
14139
- info.modifiers = modifiersex;
14140
- editObj = object.doEditClick(info, 0);
14446
+ //ClickInfo info = new ClickInfo();
14447
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14448
+ object.clickInfo.pane = this;
14449
+ object.clickInfo.camera = renderCamera;
14450
+ object.clickInfo.x = x;
14451
+ object.clickInfo.y = y;
14452
+ object.clickInfo.modifiers = modifiersex;
14453
+ editObj = object.doEditClick(//info,
14454
+ 0);
1414114455 if (!editObj)
1414214456 {
1414314457 hasMarquee = true;
....@@ -14419,12 +14733,18 @@
1441914733 void GoDown(int mod)
1442014734 {
1442114735 MODIFIERS |= COMMAND;
14422
- /*
14736
+ boolean isVR = (mouseMode&VR)!=0;
14737
+ /**/
1442314738 if((mod&SHIFT) == SHIFT)
14424
- manipCamera.RotatePosition(0, -speed);
14739
+ {
14740
+ if (isVR)
14741
+ manipCamera.RotateInterest(0, -speed);
14742
+ else
14743
+ manipCamera.RotatePosition(0, -speed);
14744
+ }
1442514745 else
14426
- manipCamera.BackForth(0, -speed*delta, getWidth());
14427
- */
14746
+ manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth());
14747
+ /**/
1442814748 if ((mod & SHIFT) == SHIFT)
1442914749 {
1443014750 mouseMode = mouseMode; // VR??
....@@ -14433,6 +14753,8 @@
1443314753 mouseMode |= BACKFORTH;
1443414754 }
1443514755
14756
+ targetLookAt.set(manipCamera.lookAt);
14757
+
1443614758 //prevX = X = anchorX;
1443714759 prevY = Y = anchorY - (int) (renderCamera.Distance());
1443814760 }
....@@ -14440,12 +14762,19 @@
1444014762 void GoUp(int mod)
1444114763 {
1444214764 MODIFIERS |= COMMAND;
14443
- /*
14765
+ /**/
14766
+ boolean isVR = (mouseMode&VR)!=0;
14767
+
1444414768 if((mod&SHIFT) == SHIFT)
14445
- manipCamera.RotatePosition(0, speed);
14769
+ {
14770
+ if (isVR)
14771
+ manipCamera.RotateInterest(0, speed);
14772
+ else
14773
+ manipCamera.RotatePosition(0, speed);
14774
+ }
1444614775 else
14447
- manipCamera.BackForth(0, speed*delta, getWidth());
14448
- */
14776
+ manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth());
14777
+ /**/
1444914778 if ((mod & SHIFT) == SHIFT)
1445014779 {
1445114780 mouseMode = mouseMode;
....@@ -14454,6 +14783,8 @@
1445414783 mouseMode |= BACKFORTH;
1445514784 }
1445614785
14786
+ targetLookAt.set(manipCamera.lookAt);
14787
+
1445714788 //prevX = X = anchorX;
1445814789 prevY = Y = anchorY + (int) (renderCamera.Distance());
1445914790 }
....@@ -14461,12 +14792,17 @@
1446114792 void GoLeft(int mod)
1446214793 {
1446314794 MODIFIERS |= COMMAND;
14464
- /*
14795
+ /**/
1446514796 if((mod&SHIFT) == SHIFT)
14466
- manipCamera.RotatePosition(speed, 0);
14797
+ manipCamera.Translate(speed*delta, 0, getWidth());
1446714798 else
14468
- manipCamera.Translate(speed*delta, 0, getWidth());
14469
- */
14799
+ {
14800
+ if ((mouseMode&VR)!=0)
14801
+ manipCamera.RotateInterest(-speed, 0);
14802
+ else
14803
+ manipCamera.RotatePosition(speed, 0);
14804
+ }
14805
+ /**/
1447014806 if ((mod & SHIFT) == SHIFT)
1447114807 {
1447214808 mouseMode = mouseMode;
....@@ -14475,6 +14811,8 @@
1447514811 mouseMode |= ROTATE;
1447614812 } // TRANSLATE;
1447714813
14814
+ targetLookAt.set(manipCamera.lookAt);
14815
+
1447814816 prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance());
1447914817 prevY = Y = anchorY;
1448014818 }
....@@ -14482,12 +14820,18 @@
1448214820 void GoRight(int mod)
1448314821 {
1448414822 MODIFIERS |= COMMAND;
14485
- /*
14823
+ /**/
1448614824 if((mod&SHIFT) == SHIFT)
14487
- manipCamera.RotatePosition(-speed, 0);
14825
+ manipCamera.Translate(-speed*delta, 0, getWidth());
1448814826 else
14489
- manipCamera.Translate(-speed*delta, 0, getWidth());
14490
- */
14827
+ {
14828
+ if ((mouseMode&VR)!=0)
14829
+ manipCamera.RotateInterest(speed, 0);
14830
+ else
14831
+ manipCamera.RotatePosition(-speed, 0);
14832
+ }
14833
+
14834
+ /**/
1449114835 if ((mod & SHIFT) == SHIFT)
1449214836 {
1449314837 mouseMode = mouseMode;
....@@ -14496,6 +14840,8 @@
1449614840 mouseMode |= ROTATE;
1449714841 } // TRANSLATE;
1449814842
14843
+ targetLookAt.set(manipCamera.lookAt);
14844
+
1449914845 prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance());
1450014846 prevY = Y = anchorY;
1450114847 }
....@@ -14537,15 +14883,16 @@
1453714883 if (editObj)
1453814884 {
1453914885 drag = true;
14540
- ClickInfo info = new ClickInfo();
14541
- info.bounds.setBounds(0, 0,
14886
+ //ClickInfo info = new ClickInfo();
14887
+ object.clickInfo.bounds.setBounds(0, 0,
1454214888 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14543
- info.pane = this;
14544
- info.camera = renderCamera;
14545
- info.x = x;
14546
- info.y = y;
14547
- object.GetWindow().copy
14548
- .doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
14889
+ object.clickInfo.pane = this;
14890
+ object.clickInfo.camera = renderCamera;
14891
+ object.clickInfo.x = x;
14892
+ object.clickInfo.y = y;
14893
+ object //.GetWindow().copy
14894
+ .doEditDrag(//info,
14895
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1454914896 } else
1455014897 {
1455114898 if (x < startX)
....@@ -14694,24 +15041,27 @@
1469415041 }
1469515042 }
1469615043
15044
+// ClickInfo clickInfo = new ClickInfo();
15045
+
1469715046 public void mouseMoved(MouseEvent e)
1469815047 {
1469915048 //System.out.println("mouseMoved: " + e);
1470015049 if (isRenderer)
1470115050 return;
1470215051
14703
- ClickInfo ci = new ClickInfo();
14704
- ci.x = e.getX();
14705
- ci.y = e.getY();
14706
- ci.modifiers = e.getModifiersEx();
14707
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14708
- ci.pane = this;
14709
- ci.camera = renderCamera;
15052
+ // Mouse cursor feedback
15053
+ object.clickInfo.x = e.getX();
15054
+ object.clickInfo.y = e.getY();
15055
+ object.clickInfo.modifiers = e.getModifiersEx();
15056
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
15057
+ object.clickInfo.pane = this;
15058
+ object.clickInfo.camera = renderCamera;
1471015059 if (!isRenderer)
1471115060 {
1471215061 //ObjEditor editWindow = object.editWindow;
1471315062 //Object3D copy = editWindow.copy;
14714
- if (object.doEditClick(ci, 0))
15063
+ if (object.doEditClick(//clickInfo,
15064
+ 0))
1471515065 {
1471615066 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1471715067 } else
....@@ -14726,7 +15076,8 @@
1472615076 Globals.MOUSEDRAGGED = false;
1472715077
1472815078 movingcamera = false;
14729
- X = Y = 0;
15079
+ X = 0; // getBounds().width/2;
15080
+ Y = 0; // getBounds().height/2;
1473015081 //System.out.println("mouseReleased: " + e);
1473115082 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1473215083 }
....@@ -14982,7 +15333,8 @@
1498215333 // break;
1498315334 case 'T':
1498415335 CACHETEXTURE ^= true;
14985
- textures.clear();
15336
+ texturepigment.clear();
15337
+ texturebump.clear();
1498615338 // repaint();
1498715339 break;
1498815340 case 'Y':
....@@ -14992,8 +15344,8 @@
1499215344 case 'K':
1499315345 KOMPACTTEXTURE ^= true;
1499415346 //textures.clear();
14995
- break;
14996
- case 'P': // Texture Projection macros
15347
+ // break;
15348
+ //case 'P': // Texture Projection macros
1499715349 // SAVETEXTURE ^= true;
1499815350 macromode = true;
1499915351 Udebug = Vdebug = NORMALdebug = false; programInitialized = false;
....@@ -15067,7 +15419,9 @@
1506715419 case 'E' : COMPACT ^= true;
1506815420 repaint();
1506915421 break;
15070
- case 'W' : DEBUGHSB ^= true;
15422
+ case 'W' : // Wide Window (fullscreen)
15423
+ //DEBUGHSB ^= true;
15424
+ ObjEditor.theFrame.ToggleFullScreen();
1507115425 repaint();
1507215426 break;
1507315427 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -15093,13 +15447,7 @@
1509315447 repaint();
1509415448 break;
1509515449 case 'l':
15096
- lightMode ^= true;
15097
- Globals.lighttouched = true;
15098
- manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
15099
- targetLookAt.set(manipCamera.lookAt);
15100
- repaint();
15101
- break;
15102
- case 'L':
15450
+ //case 'L':
1510315451 if (lightMode)
1510415452 {
1510515453 lightMode = false;
....@@ -15118,7 +15466,7 @@
1511815466 targetLookAt.set(manipCamera.lookAt);
1511915467 repaint();
1512015468 break;
15121
- case 'p':
15469
+ case 'P': // p':
1512215470 // c'est quoi ca au juste? spherical ^= true;
1512315471 Skinshader ^= true; programInitialized = false;
1512415472 repaint();
....@@ -15163,20 +15511,24 @@
1516315511 OCCLUSION_CULLING ^= true;
1516415512 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1516515513 break;
15166
- case '0': envyoff ^= true; repaint(); break;
15514
+ //case '0': envyoff ^= true; repaint(); break;
1516715515 case '1':
1516815516 case '2':
1516915517 case '3':
1517015518 case '4':
1517115519 case '5':
15172
- newenvy = Character.getNumericValue(key);
15173
- repaint();
15174
- break;
1517515520 case '6':
1517615521 case '7':
1517715522 case '8':
1517815523 case '9':
15179
- BGcolor = (key - '6')/3.f;
15524
+ if (true) // envyoff)
15525
+ {
15526
+ BGcolor = (key - '1')/8.f;
15527
+ }
15528
+ else
15529
+ {
15530
+ //newenvy = Character.getNumericValue(key);
15531
+ }
1518015532 repaint();
1518115533 break;
1518215534 case '!':
....@@ -15246,7 +15598,10 @@
1524615598 // kompactbit = 6;
1524715599 // break;
1524815600 case ' ':
15249
- ObjEditor.theFrame.ToggleFullScreen();
15601
+ lightMode ^= true;
15602
+ Globals.lighttouched = true;
15603
+ manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
15604
+ targetLookAt.set(manipCamera.lookAt);
1525015605 repaint();
1525115606 break;
1525215607 //case '`' :
....@@ -15295,12 +15650,6 @@
1529515650 break;
1529615651 case '+':
1529715652
15298
- //for (int i=0; i<0x7FFFFFFF; i++)
15299
- {
15300
- //String.format("%08X", i); // "7caca905"
15301
- GetRemoteZip("https://archive3d.net/?a=download&do=get&id=", "7caca905", true, true);
15302
- }
15303
-
1530415653 /*
1530515654 //fontsize += 1;
1530615655 bbzoom *= 2;
....@@ -15318,17 +15667,17 @@
1531815667 case '=':
1531915668 IncDepth();
1532015669 //fontsize += 1;
15321
- object.editWindow.refreshContents(true);
15670
+ object.GetWindow().refreshContents(true);
1532215671 maskbit = 6;
1532315672 break;
1532415673 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1532515674 DecDepth();
1532615675 maskbit = 5;
1532715676 //if(fontsize > 1) fontsize -= 1;
15328
- if (object.editWindow == null)
15329
- new Exception().printStackTrace();
15330
- else
15331
- object.editWindow.refreshContents(true);
15677
+// if (object.editWindow == null)
15678
+// new Exception().printStackTrace();
15679
+// else
15680
+ object.GetWindow().refreshContents(true);
1533215681 break;
1533315682 case '{':
1533415683 manipCamera.shaper_fovy /= 1.1;
....@@ -15552,7 +15901,7 @@
1555215901 }
1555315902 */
1555415903
15555
- object.editWindow.EditSelection(false);
15904
+ object.GetWindow().EditSelection(false);
1555615905 }
1555715906
1555815907 void SelectParent()
....@@ -15569,10 +15918,10 @@
1556915918 {
1557015919 //selectees.remove(i);
1557115920 System.out.println("select parent of " + elem);
15572
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15921
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1557315922 } else
1557415923 {
15575
- group.editWindow.Select(elem.GetTreePath(), first, true);
15924
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1557615925 }
1557715926
1557815927 first = false;
....@@ -15614,12 +15963,12 @@
1561415963 for (int j = 0; j < group.children.size(); j++)
1561515964 {
1561615965 elem = (Object3D) group.children.elementAt(j);
15617
- object.editWindow.Select(elem.GetTreePath(), first, true);
15966
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1561815967 first = false;
1561915968 }
1562015969 } else
1562115970 {
15622
- object.editWindow.Select(elem.GetTreePath(), first, true);
15971
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1562315972 }
1562415973
1562515974 first = false;
....@@ -15630,21 +15979,21 @@
1563015979 {
1563115980 //Composite group = (Composite) object;
1563215981 Object3D group = object;
15633
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15982
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1563415983 }
1563515984
1563615985 void ResetTransform(int mask)
1563715986 {
1563815987 //Composite group = (Composite) object;
1563915988 Object3D group = object;
15640
- group.editWindow.ResetTransform(mask);
15989
+ group.GetWindow().ResetTransform(mask);
1564115990 }
1564215991
1564315992 void FlipTransform()
1564415993 {
1564515994 //Composite group = (Composite) object;
1564615995 Object3D group = object;
15647
- group.editWindow.FlipTransform();
15996
+ group.GetWindow().FlipTransform();
1564815997 // group.editWindow.ReduceMesh(true);
1564915998 }
1565015999
....@@ -15652,7 +16001,7 @@
1565216001 {
1565316002 //Composite group = (Composite) object;
1565416003 Object3D group = object;
15655
- group.editWindow.PrintMemory();
16004
+ group.GetWindow().PrintMemory();
1565616005 // group.editWindow.ReduceMesh(true);
1565716006 }
1565816007
....@@ -15660,7 +16009,7 @@
1566016009 {
1566116010 //Composite group = (Composite) object;
1566216011 Object3D group = object;
15663
- group.editWindow.ResetCentroid();
16012
+ group.GetWindow().ResetCentroid();
1566416013 }
1566516014
1566616015 void IncDepth()
....@@ -15742,8 +16091,6 @@
1574216091
1574316092 int width = getBounds().width;
1574416093 int height = getBounds().height;
15745
- ClickInfo info = new ClickInfo();
15746
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1574716094 //Image img = CreateImage(width, height);
1574816095 //System.out.println("width = " + width + "; height = " + height + "\n");
1574916096
....@@ -15820,48 +16167,77 @@
1582016167 }
1582116168 if (object != null && !hasMarquee)
1582216169 {
16170
+ if (object.clickInfo == null)
16171
+ object.clickInfo = new ClickInfo();
16172
+ ClickInfo info = object.clickInfo;
16173
+ //ClickInfo info = new ClickInfo();
16174
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16175
+
1582316176 if (isRenderer)
1582416177 {
15825
- info.flags++;
16178
+ object.clickInfo.flags++;
1582616179 double frameAspect = (double) width / (double) height;
1582716180 if (frameAspect > renderCamera.aspect)
1582816181 {
1582916182 int desired = (int) ((double) height * renderCamera.aspect);
15830
- info.bounds.width -= width - desired;
15831
- info.bounds.x += (width - desired) / 2;
16183
+ object.clickInfo.bounds.width -= width - desired;
16184
+ object.clickInfo.bounds.x += (width - desired) / 2;
1583216185 } else
1583316186 {
1583416187 int desired = (int) ((double) width / renderCamera.aspect);
15835
- info.bounds.height -= height - desired;
15836
- info.bounds.y += (height - desired) / 2;
16188
+ object.clickInfo.bounds.height -= height - desired;
16189
+ object.clickInfo.bounds.y += (height - desired) / 2;
1583716190 }
1583816191 }
15839
- info.g = gr;
15840
- info.camera = renderCamera;
16192
+
16193
+ object.clickInfo.g = gr;
16194
+ object.clickInfo.camera = renderCamera;
1584116195 /*
1584216196 // Memory intensive (brep.verticescopy)
1584316197 if (!(object instanceof Composite))
1584416198 object.draw(info, 0, false); // SLOW :
1584516199 */
15846
- if (!isRenderer)
16200
+ if (!isRenderer) // && drag)
1584716201 {
15848
- object.drawEditHandles(info, 0);
15849
-
15850
- if (drag && (X != 0 || Y != 0) && object.selection.Size() > 0)
16202
+ Grafreed.Assert(object != null);
16203
+ Grafreed.Assert(object.selection != null);
16204
+ if (object.selection.Size() > 0)
1585116205 {
15852
- switch (object.selection.get(0).hitSomething)
16206
+ int hitSomething = object.selection.get(0).hitSomething;
16207
+
16208
+ object.clickInfo.DX = 0;
16209
+ object.clickInfo.DY = 0;
16210
+ object.clickInfo.W = 1;
16211
+ if (hitSomething == Object3D.hitCenter)
1585316212 {
15854
- case Object3D.hitCenter: gr.setColor(Color.pink);
15855
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15856
- break;
15857
- case Object3D.hitRotate: gr.setColor(Color.yellow);
15858
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15859
- break;
15860
- case Object3D.hitScale: gr.setColor(Color.cyan);
15861
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15862
- break;
16213
+ info.DX = X;
16214
+ if (X != 0)
16215
+ info.DX -= info.bounds.width/2;
16216
+
16217
+ info.DY = Y;
16218
+ if (Y != 0)
16219
+ info.DY -= info.bounds.height/2;
1586316220 }
15864
-
16221
+
16222
+ object.drawEditHandles(//info,
16223
+ 0);
16224
+
16225
+ if (drag && (X != 0 || Y != 0))
16226
+ {
16227
+ switch (hitSomething)
16228
+ {
16229
+ case Object3D.hitCenter: gr.setColor(Color.white);
16230
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16231
+ break;
16232
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16233
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16234
+ break;
16235
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16236
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16237
+ break;
16238
+ }
16239
+
16240
+ }
1586516241 }
1586616242 }
1586716243 }
....@@ -15876,7 +16252,7 @@
1587616252 if (hasMarquee)
1587716253 {
1587816254 gr.setXORMode(Color.white);
15879
- gr.setColor(Color.red);
16255
+ gr.setColor(Color.white);
1588016256 if (!firstime)
1588116257 {
1588216258 gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH);
....@@ -16343,6 +16719,8 @@
1634316719 private /*static*/ boolean firstime;
1634416720 private /*static*/ cVector newView = new cVector();
1634516721 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16722
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16723
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1634616724 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1634716725 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1634816726 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16355,29 +16733,67 @@
1635516733 {
1635616734 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1635716735
16736
+ int usedsuf = 0;
16737
+
1635816738 for (int i = 0; i < suffixes.length; i++)
1635916739 {
16360
- String resourceName = basename + suffixes[i] + "." + suffix;
16361
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16362
- mipmapped,
16363
- FileUtil.getFileSuffix(resourceName));
16364
- if (data == null)
16740
+ String[] suffixe = suffixes;
16741
+ String[] fallback = suffixes2;
16742
+ String[] fallfallback = suffixes3;
16743
+
16744
+ for (int c=usedsuf; --c>=0;)
1636516745 {
16366
- throw new IOException("Unable to load texture " + resourceName);
16746
+// String[] temp = suffixe;
16747
+// suffixe = fallback;
16748
+// fallback = fallfallback;
16749
+// fallfallback = temp;
1636716750 }
16751
+
16752
+ String resourceName = basename + suffixe[i] + "." + suffix;
16753
+ TextureData data;
16754
+
16755
+ try
16756
+ {
16757
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16758
+ mipmapped,
16759
+ FileUtil.getFileSuffix(resourceName));
16760
+ }
16761
+ catch (Exception e)
16762
+ {
16763
+ try
16764
+ {
16765
+ resourceName = basename + fallback[i] + "." + suffix;
16766
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16767
+ mipmapped,
16768
+ FileUtil.getFileSuffix(resourceName));
16769
+ }
16770
+ catch (Exception e2)
16771
+ {
16772
+ resourceName = basename + fallfallback[i] + "." + suffix;
16773
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16774
+ mipmapped,
16775
+ FileUtil.getFileSuffix(resourceName));
16776
+ }
16777
+ }
16778
+
1636816779 //System.out.println("Target = " + targets[i]);
1636916780 cubemap.updateImage(data, targets[i]);
1637016781 }
1637116782
1637216783 return cubemap;
1637316784 }
16785
+
1637416786 int bigsphere = -1;
1637516787
1637616788 float BGcolor = 0.5f;
1637716789
16378
- private void DrawSkyBox(GL gl)
16790
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16791
+
16792
+ private void DrawSkyBox(GL gl, float ratio)
1637916793 {
16380
- if (envyoff || cubemap == null)
16794
+ if (//envyoff ||
16795
+ WIREFRAME ||
16796
+ cubemap == null)
1638116797 {
1638216798 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1638316799 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16392,7 +16808,17 @@
1639216808 // Compensates for ExaminerViewer's modification of modelview matrix
1639316809 gl.glMatrixMode(GL.GL_MODELVIEW);
1639416810 gl.glLoadIdentity();
16811
+ gl.glScalef(1,ratio,1);
1639516812
16813
+// colorV[0] = 2;
16814
+// colorV[1] = 2;
16815
+// colorV[2] = 2;
16816
+// colorV[3] = 1;
16817
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16818
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16819
+//
16820
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16821
+
1639616822 //gl.glActiveTexture(GL.GL_TEXTURE1);
1639716823 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1639816824
....@@ -16424,6 +16850,7 @@
1642416850 {
1642516851 gl.glScalef(1.0f, -1.0f, 1.0f);
1642616852 }
16853
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1642716854 gl.glMultMatrixd(viewrot_1, 0);
1642816855 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1642916856 //viewer.updateInverseRotation(gl);
....@@ -16464,7 +16891,8 @@
1646416891 gl.glDisable(GL.GL_TEXTURE_GEN_R);
1646516892
1646616893 cubemap.disable();
16467
- ////cubemap.unbind();
16894
+ //cubemap.dispose();
16895
+
1646816896 if (CULLFACE)
1646916897 {
1647016898 gl.glEnable(gl.GL_CULL_FACE);
....@@ -16520,7 +16948,7 @@
1652016948 gl.glScalef(1.0f, -1.0f, 1.0f);
1652116949 }
1652216950
16523
- gl.glNormal3f(0.0f, 0.0f, 1.0f);
16951
+ SetGLNormal(gl, 0.0f, 0.0f, 1.0f);
1652416952
1652516953 float step = 2; // 0.1666f; //0.25f;
1652616954 float stepv = 2; // step * 1652 / 998;
....@@ -16659,6 +17087,14 @@
1665917087 }
1666017088 }
1666117089
17090
+ private Object3D GetFolder()
17091
+ {
17092
+ Object3D folder = object.GetWindow().copy;
17093
+ if (object.GetWindow().copy.selection.Size() > 0)
17094
+ folder = object.GetWindow().copy.selection.elementAt(0);
17095
+ return folder;
17096
+ }
17097
+
1666217098 class SelectBuffer implements GLEventListener
1666317099 {
1666417100
....@@ -16674,7 +17110,7 @@
1667417110 //new Exception().printStackTrace();
1667517111 System.out.println("select buffer init");
1667617112 // Use debug pipeline
16677
- drawable.setGL(new DebugGL(drawable.getGL()));
17113
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1667817114
1667917115 GL gl = drawable.getGL();
1668017116
....@@ -16738,6 +17174,17 @@
1673817174
1673917175 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1674017176
17177
+ if (PAINTMODE)
17178
+ {
17179
+ if (object.GetWindow().copy.selection.Size() > 0)
17180
+ {
17181
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17182
+
17183
+ // Make what you paint not selectable.
17184
+ paintobj.ResetSelectable();
17185
+ }
17186
+ }
17187
+
1674117188 //int tmp = selection_view;
1674217189 //selection_view = -1;
1674317190 int temp = DrawMode();
....@@ -16749,6 +17196,17 @@
1674917196 // temp = DEFAULT; // patch for selection debug
1675017197 Globals.drawMode = temp; // WARNING
1675117198
17199
+ if (PAINTMODE)
17200
+ {
17201
+ if (object.GetWindow().copy.selection.Size() > 0)
17202
+ {
17203
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17204
+
17205
+ // Revert.
17206
+ paintobj.RestoreSelectable();
17207
+ }
17208
+ }
17209
+
1675217210 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1675317211
1675417212 // trying different ways of getting the depth info over
....@@ -16852,29 +17310,31 @@
1685217310 }
1685317311
1685417312 if (!movingcamera && !PAINTMODE)
16855
- object.editWindow.ScreenFitPoint(); // fev 2014
17313
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1685617314
16857
- if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17315
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1685817316 {
16859
- Object3D paintobj = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17317
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1686017318
16861
- Object3D group = new Object3D("inst" + paintcount++);
17319
+ if (object.GetWindow().copy.selection.Size() > 0)
17320
+ {
17321
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1686217322
16863
- group.CreateMaterial(); // use a void leaf to select instances
16864
-
16865
- group.add(paintobj); // link
16866
-
16867
- object.editWindow.SnapObject(group);
16868
-
16869
- Object3D folder = object.editWindow.copy;
16870
-
16871
- if (object.editWindow.copy.selection.Size() > 0)
16872
- folder = object.editWindow.copy.selection.elementAt(0);
16873
-
16874
- folder.add(group);
16875
-
16876
- object.editWindow.ResetModel();
16877
- object.editWindow.refreshContents();
17323
+ Object3D inst = new Object3D("inst" + paintcount++);
17324
+
17325
+ inst.CreateMaterial(); // use a void leaf to select instances
17326
+
17327
+ inst.add(paintobj); // link
17328
+
17329
+ object.GetWindow().SnapObject(inst);
17330
+
17331
+ Object3D folder = paintFolder; // GetFolder();
17332
+
17333
+ folder.add(inst);
17334
+
17335
+ object.GetWindow().ResetModel();
17336
+ object.GetWindow().refreshContents();
17337
+ }
1687817338 }
1687917339 else
1688017340 paintcount = 0;
....@@ -16968,6 +17428,7 @@
1696817428
1696917429 public void init(GLAutoDrawable drawable)
1697017430 {
17431
+ if (Globals.DEBUG)
1697117432 System.out.println("shadow buffer init");
1697217433
1697317434 GL gl = drawable.getGL();
....@@ -17196,10 +17657,14 @@
1719617657 gl.glFlush();
1719717658
1719817659 /**/
17199
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17660
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1720017661
17201
- float[] pixels = occlusionsizebuffer.array();
17662
+ float[] depths = occlusiondepthbuffer.array();
1720217663
17664
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17665
+
17666
+ int[] pixels = selectsizebuffer.array();
17667
+
1720317668 double r = 0, g = 0, b = 0;
1720417669
1720517670 double count = 0;
....@@ -17210,7 +17675,7 @@
1721017675
1721117676 double FACTOR = 1;
1721217677
17213
- for (int i = 0; i < pixels.length; i++)
17678
+ for (int i = 0; i < depths.length; i++)
1721417679 {
1721517680 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1721617681 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -17293,7 +17758,7 @@
1729317758
1729417759 double scale = ray.z; // 1; // cos
1729517760
17296
- float depth = pixels[newindex];
17761
+ float depth = depths[newindex];
1729717762
1729817763 /*
1729917764 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -17490,11 +17955,14 @@
1749017955 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1749117956 static IntBuffer bigAAbuffer;
1749217957 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
17493
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17958
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1749417959 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1749517960 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1749617961 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17497
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17962
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17963
+
17964
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17965
+
1749817966 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1749917967 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1750017968 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();