Normand Briere
2019-08-17 07c0c67b88160b51e61c5c1d2b9b602daafa44a9
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
....@@ -1447,6 +1502,8 @@
14471502 gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
14481503 }
14491504
1505
+ float[] colorV = new float[4];
1506
+
14501507 void SetColor(Object3D obj, Vertex p0)
14511508 {
14521509 CameraPane display = this;
....@@ -1514,8 +1571,6 @@
15141571 {
15151572 return;
15161573 }
1517
-
1518
- float[] colorV = new float[3];
15191574
15201575 if (false) // marked)
15211576 {
....@@ -2065,7 +2120,7 @@
20652120 //System.err.println("Oeil on");
20662121 OEIL = true;
20672122 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2068
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2123
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
20692124 //pingthread.StepToTarget(true);
20702125 }
20712126
....@@ -2298,10 +2353,17 @@
22982353 HANDLES ^= true;
22992354 }
23002355
2356
+ Object3D paintFolder;
2357
+
23012358 void TogglePaint()
23022359 {
23032360 PAINTMODE ^= true;
23042361 paintcount = 0;
2362
+
2363
+ if (PAINTMODE)
2364
+ {
2365
+ paintFolder = GetFolder();
2366
+ }
23052367 }
23062368
23072369 void SwapCamera(int a, int b)
....@@ -2398,126 +2460,19 @@
23982460 return currentGL;
23992461 }
24002462
2401
- private void GetRemoteZip(String url, String name, boolean unzip, boolean save)
2463
+ static private BufferedImage CreateBim(TextureData texturedata)
24022464 {
2403
- java.net.URL u;
2404
- InputStream is = null;
2405
- DataInputStream dis;
2406
- java.util.zip.ZipInputStream zis;
2407
- //String s;
2408
-
2409
- System.out.println("GetRemoteZip " + name);
2410
-
2411
- int total = 0; // dis.available();
2412
-
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
-
2465
+ Grafreed.Assert(texturedata != null);
2466
+
2467
+ int width = texturedata.getWidth();
2468
+ int height = texturedata.getHeight();
2469
+
2470
+ Buffer buffer = texturedata.getBuffer();
2471
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2472
+
2473
+ byte[] bytes = bytebuf.array();
2474
+
2475
+ return CreateBim(bytes, width, height);
25212476 }
25222477
25232478 /**/
....@@ -2528,28 +2483,31 @@
25282483
25292484 int resolution;
25302485
2531
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2486
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
25322487 {
2533
- texture = tex;
2488
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2489
+ texturedata = texdata;
25342490 resolution = res;
25352491 }
25362492 }
25372493 /**/
25382494
25392495 // 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>();
2496
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2497
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2498
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2499
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2500
+
25432501 int pigmentdepth = 0;
25442502 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
25452503 int bumpdepth = 0;
25462504 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
25472505 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
25482506 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2549
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2507
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
25502508 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
25512509
2552
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2510
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
25532511 {
25542512 TextureData texturedata = null;
25552513
....@@ -2559,7 +2517,7 @@
25592517 com.sun.opengl.util.texture.TextureIO.newTextureData(
25602518 getClass().getClassLoader().getResourceAsStream(name),
25612519 true,
2562
- com.sun.opengl.util.texture.TextureIO.PNG);
2520
+ GetFormat(name)); // com.sun.opengl.util.texture.TextureIO.PNG);
25632521 } catch (java.io.IOException e)
25642522 {
25652523 throw new javax.media.opengl.GLException(e);
....@@ -2568,13 +2526,34 @@
25682526 if (bump)
25692527 texturedata = ConvertBump(texturedata, false);
25702528
2571
- com.sun.opengl.util.texture.Texture texture =
2572
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2529
+// com.sun.opengl.util.texture.Texture texture =
2530
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
25732531
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);
2532
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2533
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
25762534
2577
- return texture;
2535
+ return texturedata;
2536
+ }
2537
+
2538
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2539
+ {
2540
+ TextureData texturedata = null;
2541
+
2542
+ try
2543
+ {
2544
+ texturedata =
2545
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2546
+ bim,
2547
+ true);
2548
+ } catch (Exception e)
2549
+ {
2550
+ throw new javax.media.opengl.GLException(e);
2551
+ }
2552
+
2553
+ if (bump)
2554
+ texturedata = ConvertBump(texturedata, false);
2555
+
2556
+ return texturedata;
25782557 }
25792558
25802559 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3647,6 +3626,8 @@
36473626
36483627 System.out.println("LOADING TEXTURE : " + name);
36493628
3629
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3630
+
36503631 //
36513632 if (false) // compressbit > 0)
36523633 {
....@@ -8045,7 +8026,7 @@
80458026 String pigment = Object3D.GetPigment(tex);
80468027 String bump = Object3D.GetBump(tex);
80478028
8048
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8029
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
80498030 {
80508031 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
80518032 // System.out.println("; bump = " + bump);
....@@ -8060,8 +8041,8 @@
80608041 pigment = null;
80618042 }
80628043
8063
- ReleaseTexture(bump, true);
8064
- ReleaseTexture(pigment, false);
8044
+ ReleaseTexture(tex, true);
8045
+ ReleaseTexture(tex, false);
80658046 }
80668047
80678048 public void ReleasePigmentTexture(cTexture tex) // INTERFACE
....@@ -8079,7 +8060,7 @@
80798060
80808061 String pigment = Object3D.GetPigment(tex);
80818062
8082
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8063
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
80838064 {
80848065 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
80858066 // System.out.println("; bump = " + bump);
....@@ -8090,7 +8071,7 @@
80908071 pigment = null;
80918072 }
80928073
8093
- ReleaseTexture(pigment, false);
8074
+ ReleaseTexture(tex, false);
80948075 }
80958076
80968077 public void ReleaseBumpTexture(cTexture tex) // INTERFACE
....@@ -8108,7 +8089,7 @@
81088089
81098090 String bump = Object3D.GetBump(tex);
81108091
8111
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8092
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
81128093 {
81138094 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
81148095 // System.out.println("; bump = " + bump);
....@@ -8119,10 +8100,10 @@
81198100 bump = null;
81208101 }
81218102
8122
- ReleaseTexture(bump, true);
8103
+ ReleaseTexture(tex, true);
81238104 }
81248105
8125
- void ReleaseTexture(String tex, boolean bump)
8106
+ void ReleaseTexture(cTexture tex, boolean bump)
81268107 {
81278108 if (// DrawMode() != 0 || /*tex == null ||*/
81288109 ambientOcclusion ) // || !textureon)
....@@ -8133,7 +8114,7 @@
81338114 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
81348115
81358116 if (tex != null)
8136
- texture = textures.get(tex);
8117
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
81378118
81388119 // //assert( texture != null );
81398120 // if (texture == null)
....@@ -8227,47 +8208,50 @@
82278208
82288209 /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
82298210 {
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
- }
8211
+// if (// DrawMode() != 0 || /*tex == null ||*/
8212
+// ambientOcclusion ) // || !textureon)
8213
+// {
8214
+// return; // false;
8215
+// }
8216
+//
8217
+// if (tex == null)
8218
+// {
8219
+// BindTexture(null,false,resolution);
8220
+// BindTexture(null,true,resolution);
8221
+// return;
8222
+// }
8223
+//
8224
+// String pigment = Object3D.GetPigment(tex);
8225
+// String bump = Object3D.GetBump(tex);
8226
+//
8227
+// usedtextures.add(pigment);
8228
+// usedtextures.add(bump);
8229
+//
8230
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8231
+// {
8232
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8233
+// // System.out.println("; bump = " + bump);
8234
+// }
8235
+//
8236
+// if (bump.equals(""))
8237
+// {
8238
+// bump = null;
8239
+// }
8240
+// if (pigment.equals(""))
8241
+// {
8242
+// pigment = null;
8243
+// }
8244
+//
8245
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8246
+// BindTexture(pigment, false, resolution);
8247
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8248
+// BindTexture(bump, true, resolution);
8249
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8250
+//
8251
+// return; // true;
82428252
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;
8253
+ BindPigmentTexture(tex, resolution);
8254
+ BindBumpTexture(tex, resolution);
82718255 }
82728256
82738257 /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8286,9 +8270,9 @@
82868270
82878271 String pigment = Object3D.GetPigment(tex);
82888272
8289
- usedtextures.put(pigment, pigment);
8273
+ usedtextures.add(tex);
82908274
8291
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8275
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
82928276 {
82938277 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
82948278 // System.out.println("; bump = " + bump);
....@@ -8300,7 +8284,7 @@
83008284 }
83018285
83028286 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8303
- BindTexture(pigment, false, resolution);
8287
+ BindTexture(tex, false, resolution);
83048288 }
83058289
83068290 /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8319,9 +8303,9 @@
83198303
83208304 String bump = Object3D.GetBump(tex);
83218305
8322
- usedtextures.put(bump, bump);
8306
+ usedtextures.add(tex);
83238307
8324
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8308
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
83258309 {
83268310 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
83278311 // System.out.println("; bump = " + bump);
....@@ -8333,7 +8317,7 @@
83338317 }
83348318
83358319 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8336
- BindTexture(bump, true, resolution);
8320
+ BindTexture(tex, true, resolution);
83378321 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
83388322 }
83398323
....@@ -8357,13 +8341,19 @@
83578341 return fileExists;
83588342 }
83598343
8360
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception
8344
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
83618345 {
8362
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8346
+ CacheTexture texturecache = null;
83638347
83648348 if (tex != null)
83658349 {
8366
- String texname = tex;
8350
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8351
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
8352
+
8353
+ if (texname.equals("") && texdata == null)
8354
+ {
8355
+ return null;
8356
+ }
83678357
83688358 String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
83698359
....@@ -8373,19 +8363,46 @@
83738363 // else
83748364 // if (!texname.startsWith("/"))
83758365 // texname = "/Users/nbriere/Textures/" + texname;
8376
- if (!FileExists(tex))
8366
+ if (!FileExists(texname) && !texname.startsWith("@"))
83778367 {
83788368 texname = fallbackTextureName;
83798369 }
83808370
83818371 if (CACHETEXTURE)
8382
- texture = textures.get(texname); // TEXTURE CACHE
8383
-
8384
- TextureData texturedata = null;
8385
-
8386
- if (texture == null || texture.resolution < resolution)
83878372 {
8388
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8373
+ if (texdata == null)
8374
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8375
+ else
8376
+ texturecache = bimtextures.get(texdata);
8377
+ }
8378
+
8379
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8380
+ {
8381
+ TextureData texturedata = null;
8382
+
8383
+ if (texdata != null && textureon)
8384
+ {
8385
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8386
+
8387
+ try
8388
+ {
8389
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8390
+ }
8391
+ catch (Exception e)
8392
+ {
8393
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8394
+ }
8395
+
8396
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8397
+ bimtextures.put(texdata, texturecache);
8398
+
8399
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8400
+
8401
+ //Object bim2 = CreateBim(texturecache.texturedata);
8402
+ //bim2 = bim;
8403
+ }
8404
+ else
8405
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
83898406 {
83908407 assert(!bump);
83918408 // if (bump)
....@@ -8396,19 +8413,23 @@
83968413 // }
83978414 // else
83988415 // {
8399
- texture = textures.get(tex);
8400
- if (texture == null)
8416
+ // texturecache = textures.get(texname); // suspicious
8417
+ if (texturecache == null)
84018418 {
8402
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8419
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
84038420 }
8421
+ else
8422
+ new Exception().printStackTrace();
84048423 // }
84058424 } else
8406
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8425
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
84078426 {
84088427 assert(bump);
8409
- texture = textures.get(tex);
8410
- if (texture == null)
8411
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8428
+ // texturecache = textures.get(texname); // suspicious
8429
+ if (texturecache == null)
8430
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8431
+ else
8432
+ new Exception().printStackTrace();
84128433 } else
84138434 {
84148435 //if (tex.equals("IMMORTAL"))
....@@ -8416,11 +8437,22 @@
84168437 // texture = GetResourceTexture("default.png");
84178438 //} else
84188439 //{
8419
- if (tex.equals("WHITE_NOISE"))
8440
+ if (texname.endsWith("WHITE_NOISE"))
84208441 {
8421
- texture = textures.get(tex);
8422
- if (texture == null)
8423
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8442
+ // texturecache = textures.get(texname); // suspicious
8443
+ if (texturecache == null)
8444
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8445
+ else
8446
+ new Exception().printStackTrace();
8447
+ } else
8448
+ {
8449
+ if (texname.startsWith("@"))
8450
+ {
8451
+ // texturecache = textures.get(texname); // suspicious
8452
+ if (texturecache == null)
8453
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8454
+ else
8455
+ new Exception().printStackTrace();
84248456 } else
84258457 {
84268458 if (textureon)
....@@ -8479,19 +8511,20 @@
84798511 if (texturedata == null)
84808512 throw new Exception();
84818513
8482
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8514
+ texturecache = new CacheTexture(texturedata,resolution);
84838515 //texture = GetTexture(tex, bump);
84848516 }
8517
+ }
84858518 }
84868519 //}
84878520 }
84888521
8489
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8522
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
84908523 {
84918524 //return false;
84928525
84938526 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8494
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8527
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
84958528 {
84968529 // String ext = "_highres";
84978530 // if (REDUCETEXTURE)
....@@ -8508,52 +8541,17 @@
85088541 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
85098542 if (!cachefile.exists())
85108543 {
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))
8544
+ //if (texturedata.getWidth() == texturedata.getHeight())
85208545 {
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);
8546
+ BufferedImage rendImage = CreateBim(texturedata);
8547
+
85518548 ImageWriter writer = null;
85528549 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
85538550 if (iter.hasNext()) {
85548551 writer = (ImageWriter)iter.next();
85558552 }
8556
- float compressionQuality = 0.9f;
8553
+
8554
+ float compressionQuality = 0.85f;
85578555 try
85588556 {
85598557 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8570,18 +8568,20 @@
85708568 }
85718569 }
85728570 }
8573
-
8571
+
8572
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8573
+
85748574 //System.out.println("Texture = " + tex);
8575
- if (textures.containsKey(texname))
8575
+ if (textures.containsKey(tex))
85768576 {
8577
- CacheTexture thetex = textures.get(texname);
8577
+ CacheTexture thetex = textures.get(tex);
85788578 thetex.texture.disable();
85798579 thetex.texture.dispose();
8580
- textures.remove(texname);
8580
+ textures.remove(tex);
85818581 }
85828582
8583
- texture.texturedata = texturedata;
8584
- textures.put(texname, texture);
8583
+ //texture.texturedata = texturedata;
8584
+ textures.put(tex, texturecache);
85858585
85868586 // newtex = true;
85878587 }
....@@ -8597,10 +8597,44 @@
85978597 }
85988598 }
85998599
8600
- return texture;
8600
+ return texturecache;
86018601 }
86028602
8603
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution) throws Exception
8603
+ static void EmbedTextures(cTexture tex)
8604
+ {
8605
+ if (tex.pigmentdata == null)
8606
+ {
8607
+ //String texname = Object3D.GetPigment(tex);
8608
+
8609
+ CacheTexture texturecache = texturepigment.get(tex);
8610
+
8611
+ if (texturecache != null)
8612
+ {
8613
+ tex.pw = texturecache.texturedata.getWidth();
8614
+ tex.ph = texturecache.texturedata.getHeight();
8615
+ tex.pigmentdata = //CompressJPEG(CreateBim
8616
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8617
+ ;
8618
+ //, tex.pw, tex.ph), 0.5f);
8619
+ }
8620
+ }
8621
+
8622
+ if (tex.bumpdata == null)
8623
+ {
8624
+ //String texname = Object3D.GetBump(tex);
8625
+
8626
+ CacheTexture texturecache = texturebump.get(tex);
8627
+
8628
+ if (texturecache != null)
8629
+ {
8630
+ tex.bw = texturecache.texturedata.getWidth();
8631
+ tex.bh = texturecache.texturedata.getHeight();
8632
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8633
+ }
8634
+ }
8635
+ }
8636
+
8637
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
86048638 {
86058639 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
86068640
....@@ -8618,21 +8652,21 @@
86188652 return texture!=null?texture.texture:null;
86198653 }
86208654
8621
- public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution) throws Exception
8655
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
86228656 {
86238657 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
86248658
86258659 return texture!=null?texture.texturedata:null;
86268660 }
86278661
8628
- boolean BindTexture(String tex, boolean bump, int resolution) throws Exception
8662
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
86298663 {
86308664 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
86318665 {
86328666 return false;
86338667 }
86348668
8635
- boolean newtex = false;
8669
+ //boolean newtex = false;
86368670
86378671 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
86388672
....@@ -8664,9 +8698,75 @@
86648698 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
86658699 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
86668700
8667
- return newtex;
8701
+ return true; // Warning: not used.
86688702 }
86698703
8704
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8705
+ {
8706
+ try
8707
+ {
8708
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8709
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8710
+ ImageWriter writer = writers.next();
8711
+
8712
+ ImageWriteParam param = writer.getDefaultWriteParam();
8713
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8714
+ param.setCompressionQuality(quality);
8715
+
8716
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8717
+ writer.setOutput(ios);
8718
+ writer.write(null, new IIOImage(image, null, null), param);
8719
+
8720
+ byte[] data = baos.toByteArray();
8721
+ writer.dispose();
8722
+ return data;
8723
+ }
8724
+ catch (Exception e)
8725
+ {
8726
+ e.printStackTrace();
8727
+ return null;
8728
+ }
8729
+ }
8730
+
8731
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8732
+ {
8733
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8734
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8735
+ ImageReader reader = writers.next();
8736
+
8737
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8738
+
8739
+ ImageReadParam param = reader.getDefaultReadParam();
8740
+ param.setDestination(bim);
8741
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8742
+
8743
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8744
+ reader.setInput(ios);
8745
+ BufferedImage bim2 = reader.read(0, param);
8746
+ reader.dispose();
8747
+
8748
+// WritableRaster raster = bim2.getRaster();
8749
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8750
+// byte[] bytes = data.getData();
8751
+//
8752
+// int[] pixels = new int[bytes.length/3];
8753
+// for (int i=pixels.length; --i>=0;)
8754
+// {
8755
+// int i3 = i*3;
8756
+// pixels[i] = 0xFF;
8757
+// pixels[i] <<= 8;
8758
+// pixels[i] |= bytes[i3+2] & 0xFF;
8759
+// pixels[i] <<= 8;
8760
+// pixels[i] |= bytes[i3+1] & 0xFF;
8761
+// pixels[i] <<= 8;
8762
+// pixels[i] |= bytes[i3] & 0xFF;
8763
+// }
8764
+//
8765
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8766
+
8767
+ return bim;
8768
+ }
8769
+
86708770 ShadowBuffer shadowPBuf;
86718771 AntialiasBuffer antialiasPBuf;
86728772 int MAXSTACK;
....@@ -8683,10 +8783,12 @@
86838783
86848784 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
86858785 MAXSTACK = temp[0];
8686
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8786
+ if (Globals.DEBUG)
8787
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
86878788 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
86888789 MAXSTACK = temp[0];
8689
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8790
+ if (Globals.DEBUG)
8791
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
86908792
86918793 // Use debug pipeline
86928794 //drawable.setGL(new DebugGL(gl)); //
....@@ -8694,7 +8796,8 @@
86948796 gl = drawable.getGL(); //
86958797
86968798 GL gl3 = getGL();
8697
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8799
+ if (Globals.DEBUG)
8800
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
86988801
86998802
87008803 //float pos[] = { 100, 100, 100, 0 };
....@@ -8859,7 +8962,7 @@
88598962
88608963 if (cubemap == null)
88618964 {
8862
- LoadEnvy(5);
8965
+ //LoadEnvy(1);
88638966 }
88648967
88658968 //cubemap.enable();
....@@ -9135,6 +9238,8 @@
91359238
91369239 void LoadEnvy(int which)
91379240 {
9241
+ assert(false);
9242
+
91389243 String name;
91399244 String ext;
91409245
....@@ -9146,37 +9251,58 @@
91469251 cubemap = null;
91479252 return;
91489253 case 1:
9149
- name = "cubemaps/box_";
9150
- ext = "png";
9254
+ name = "cubemaps/rgb/";
9255
+ ext = "jpg";
91519256 reverseUP = false;
91529257 break;
91539258 case 2:
9154
- name = "cubemaps/uffizi_";
9155
- ext = "png";
9156
- break; // reverseUP = true; break;
9259
+ name = "cubemaps/uffizi/";
9260
+ ext = "jpg";
9261
+ reverseUP = false;
9262
+ break;
91579263 case 3:
9158
- name = "cubemaps/CloudyHills_";
9159
- ext = "tga";
9264
+ name = "cubemaps/CloudyHills/";
9265
+ ext = "jpg";
91609266 reverseUP = false;
91619267 break;
91629268 case 4:
9163
- name = "cubemaps/cornell_";
9269
+ name = "cubemaps/cornell/";
91649270 ext = "png";
91659271 reverseUP = false;
91669272 break;
9273
+ case 5:
9274
+ name = "cubemaps/skycube/";
9275
+ ext = "jpg";
9276
+ reverseUP = false;
9277
+ break;
9278
+ case 6:
9279
+ name = "cubemaps/SaintLazarusChurch3/";
9280
+ ext = "jpg";
9281
+ reverseUP = false;
9282
+ break;
9283
+ case 7:
9284
+ name = "cubemaps/Sodermalmsallen/";
9285
+ ext = "jpg";
9286
+ reverseUP = false;
9287
+ break;
9288
+ case 8:
9289
+ name = "cubemaps/Sodermalmsallen2/";
9290
+ ext = "jpg";
9291
+ reverseUP = false;
9292
+ break;
9293
+ case 9:
9294
+ name = "cubemaps/UnionSquare/";
9295
+ ext = "jpg";
9296
+ reverseUP = false;
9297
+ break;
91679298 default:
9168
- name = "cubemaps/rgb_";
9169
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9299
+ name = "cubemaps/box/";
9300
+ ext = "png"; /*mipmap = true;*/
9301
+ reverseUP = false;
91709302 break;
91719303 }
9172
-
9173
- try
9174
- {
9175
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
9176
- } catch (IOException e)
9177
- {
9178
- throw new RuntimeException(e);
9179
- }
9304
+
9305
+ LoadSkybox(name, ext, mipmap);
91809306 }
91819307
91829308 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -9208,8 +9334,12 @@
92089334 static double[] model = new double[16];
92099335 double[] camera2light = new double[16];
92109336 double[] light2camera = new double[16];
9211
- int newenvy = -1;
9212
- boolean envyoff = true; // false;
9337
+
9338
+ //int newenvy = -1;
9339
+ //boolean envyoff = false;
9340
+
9341
+ String loadedskyboxname;
9342
+
92139343 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
92149344 //float[] light0 = { 0,0,0 };
92159345 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9627,7 +9757,7 @@
96279757
96289758 if (renderCamera != lightCamera)
96299759 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9630
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
9760
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
96319761
96329762 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
96339763
....@@ -9643,7 +9773,7 @@
96439773
96449774 if (renderCamera != lightCamera)
96459775 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9646
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
9776
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
96479777
96489778 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
96499779
....@@ -9689,10 +9819,12 @@
96899819 rati = 1 / rati;
96909820 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
96919821 }
9692
- assert (newenvy == -1);
9822
+
9823
+ //assert (newenvy == -1);
9824
+
96939825 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
96949826 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9695
- DrawSkyBox(gl);
9827
+ DrawSkyBox(gl, (float)rati);
96969828 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
96979829 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
96989830 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10558,9 +10690,18 @@
1055810690 static boolean init = false;
1055910691
1056010692 double[][] matrix = LA.newMatrix();
10693
+
10694
+ // This is to refresh the UI of the material panel.
10695
+ ObjEditor patchMaterial;
1056110696
1056210697 public void display(GLAutoDrawable drawable)
1056310698 {
10699
+ if (patchMaterial.patchMaterial)
10700
+ {
10701
+ patchMaterial.patchMaterial = false;
10702
+ patchMaterial.objectPanel.setSelectedIndex(0);
10703
+ }
10704
+
1056410705 if (Grafreed.savesound && Grafreed.hassound)
1056510706 {
1056610707 Grafreed.wav.save();
....@@ -10729,7 +10870,7 @@
1072910870
1073010871 if (wait)
1073110872 {
10732
- Sleep(500);
10873
+ Sleep(200); // blocks everything
1073310874
1073410875 wait = false;
1073510876 }
....@@ -10844,7 +10985,7 @@
1084410985 // if (parentcam != renderCamera) // not a light
1084510986 if (cam != lightCamera)
1084610987 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10847
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
10988
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1084810989
1084910990 for (int j = 0; j < 4; j++)
1085010991 {
....@@ -10859,7 +11000,7 @@
1085911000 // if (parentcam != renderCamera) // not a light
1086011001 if (cam != lightCamera)
1086111002 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10862
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
11003
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1086311004
1086411005 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1086511006
....@@ -10945,13 +11086,43 @@
1094511086 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1094611087 }
1094711088
10948
- if (newenvy > -1)
11089
+// if (newenvy > -1)
11090
+// {
11091
+// LoadEnvy(newenvy);
11092
+// }
11093
+//
11094
+// newenvy = -1;
11095
+
11096
+ if (transformMode) // object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
1094911097 {
10950
- LoadEnvy(newenvy);
11098
+ if (cubemaprgb == null)
11099
+ {
11100
+ cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb2" + "/", "jpg", false);
11101
+ }
11102
+
11103
+ cubemap = cubemaprgb;
1095111104 }
10952
-
10953
- newenvy = -1;
10954
-
11105
+ else
11106
+ {
11107
+ if (object.skyboxname != null)
11108
+ {
11109
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11110
+ {
11111
+ if (cubemap != null && cubemap != cubemaprgb)
11112
+ cubemap.dispose();
11113
+ cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11114
+ loadedskyboxname = object.skyboxname;
11115
+ }
11116
+ }
11117
+ else
11118
+ {
11119
+ cubemapcustom = null;
11120
+ loadedskyboxname = null;
11121
+ }
11122
+
11123
+ cubemap = cubemapcustom;
11124
+ }
11125
+
1095511126 ratio = ((double) getWidth()) / getHeight();
1095611127 //System.out.println("ratio = " + ratio);
1095711128
....@@ -10967,7 +11138,7 @@
1096711138
1096811139 if (!IsFrozen() && !ambientOcclusion)
1096911140 {
10970
- DrawSkyBox(gl);
11141
+ DrawSkyBox(gl, (float)ratio);
1097111142 }
1097211143
1097311144 //if (selection_view == -1)
....@@ -11150,9 +11321,9 @@
1115011321
1115111322 gl.glMatrixMode(GL.GL_MODELVIEW);
1115211323
11153
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11154
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
11155
-//gl.glEnable(gl.GL_MULTISAMPLE);
11324
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11325
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11326
+gl.glEnable(gl.GL_MULTISAMPLE);
1115611327 } else
1115711328 {
1115811329 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -11163,7 +11334,7 @@
1116311334 //System.out.println("BLENDING ON");
1116411335 gl.glEnable(GL.GL_BLEND);
1116511336 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
11166
-
11337
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1116711338 gl.glMatrixMode(gl.GL_PROJECTION);
1116811339 gl.glLoadIdentity();
1116911340
....@@ -11253,7 +11424,7 @@
1125311424
1125411425 // if (cam != lightCamera)
1125511426 //for (int count = parentcam.GetTransformCount(); --count>=0;)
11256
- LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
11427
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1125711428 }
1125811429
1125911430 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -11412,7 +11583,7 @@
1141211583 }
1141311584 }
1141411585
11415
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11586
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1141611587 {
1141711588 //gl.glDepthFunc(GL.GL_LEQUAL);
1141811589 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11420,24 +11591,21 @@
1142011591
1142111592 boolean texon = textureon;
1142211593
11423
- if (RENDERPROGRAM > 0)
11424
- {
11425
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11426
- textureon = false;
11427
- }
11594
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11595
+ textureon = false;
11596
+
1142811597 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1142911598 //System.out.println("ALLO");
1143011599 gl.glColorMask(false, false, false, false);
1143111600 DrawObject(gl);
11432
- if (RENDERPROGRAM > 0)
11433
- {
11434
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11435
- textureon = texon;
11436
- }
11601
+
11602
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11603
+ textureon = texon;
11604
+
1143711605 gl.glColorMask(true, true, true, true);
1143811606
1143911607 gl.glDepthFunc(GL.GL_EQUAL);
11440
- //gl.glDepthMask(false);
11608
+ gl.glDepthMask(false);
1144111609 }
1144211610
1144311611 if (false) // DrawMode() == SHADOW)
....@@ -11649,7 +11817,7 @@
1164911817 if ((TRACK || SHADOWTRACK) || zoomonce)
1165011818 {
1165111819 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11652
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11820
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1165311821 pingthread.StepToTarget(true); // true);
1165411822 // zoomonce = false;
1165511823 }
....@@ -11777,20 +11945,32 @@
1177711945 ReleaseTextures(DEFAULT_TEXTURES);
1177811946
1177911947 if (CLEANCACHE)
11780
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11948
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1178111949 {
11782
- String tex = e.nextElement();
11950
+ cTexture tex = e.nextElement();
1178311951
1178411952 // System.out.println("Texture --------- " + tex);
1178511953
11786
- if (tex.equals("WHITE_NOISE"))
11954
+ if (tex.equals("WHITE_NOISE:"))
1178711955 continue;
1178811956
11789
- if (!usedtextures.containsKey(tex))
11957
+ if (!usedtextures.contains(tex))
1179011958 {
11959
+ CacheTexture gettex = texturepigment.get(tex);
1179111960 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11792
- textures.get(tex).texture.dispose();
11793
- textures.remove(tex);
11961
+ if (gettex != null)
11962
+ {
11963
+ gettex.texture.dispose();
11964
+ texturepigment.remove(tex);
11965
+ }
11966
+
11967
+ gettex = texturebump.get(tex);
11968
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11969
+ if (gettex != null)
11970
+ {
11971
+ gettex.texture.dispose();
11972
+ texturebump.remove(tex);
11973
+ }
1179411974 }
1179511975 }
1179611976 }
....@@ -12318,8 +12498,76 @@
1231812498
1231912499 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1232012500
12321
- String program =
12501
+ String programmin =
12502
+ // Min shader
1232212503 "!!ARBfp1.0\n" +
12504
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12505
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12506
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12507
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12508
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12509
+ "PARAM light2cam0 = program.env[10];" +
12510
+ "PARAM light2cam1 = program.env[11];" +
12511
+ "PARAM light2cam2 = program.env[12];" +
12512
+ "TEMP temp;" +
12513
+ "TEMP light;" +
12514
+ "TEMP ndotl;" +
12515
+ "TEMP normal;" +
12516
+ "TEMP depth;" +
12517
+ "TEMP eye;" +
12518
+ "TEMP pos;" +
12519
+
12520
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12521
+ Normalize("normal") +
12522
+ "MOV light, state.light[0].position;" +
12523
+ "DP3 ndotl.x, light, normal;" +
12524
+
12525
+ // shadow
12526
+ "MOV pos, fragment.texcoord[1];" +
12527
+ "MOV temp, pos;" +
12528
+ ShadowTextureFetch("depth", "temp", "1") +
12529
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12530
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12531
+
12532
+ // No shadow when out of frustum
12533
+ //"SGE temp.y, depth.z, zero123.y;" +
12534
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12535
+
12536
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12537
+
12538
+ // Backlit
12539
+ "MOV pos.w, zero123.y;" +
12540
+ "DP4 eye.x, pos, light2cam0;" +
12541
+ "DP4 eye.y, pos, light2cam1;" +
12542
+ "DP4 eye.z, pos, light2cam2;" +
12543
+ Normalize("eye") +
12544
+
12545
+ "DP3 ndotl.y, -eye, normal;" +
12546
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12547
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12548
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12549
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12550
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12551
+
12552
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12553
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12554
+
12555
+ // Pigment
12556
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12557
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12558
+ "MUL temp, temp, ndotl.x;" +
12559
+
12560
+ "MUL temp, temp, zero123.z;" +
12561
+
12562
+ //"MUL temp, temp, ndotl.y;" +
12563
+
12564
+ "MOV temp.w, zero123.y;" + // reset alpha
12565
+ "MOV result.color, temp;" +
12566
+ "END";
12567
+
12568
+ String programmax =
12569
+ "!!ARBfp1.0\n" +
12570
+
1232312571 //"OPTION ARB_fragment_program_shadow;" +
1232412572 "PARAM light2cam0 = program.env[10];" +
1232512573 "PARAM light2cam1 = program.env[11];" +
....@@ -12434,8 +12682,7 @@
1243412682 "TEMP shininess;" +
1243512683 "\n" +
1243612684 "MOV texSamp, one;" +
12437
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12438
-
12685
+
1243912686 "MOV mapgrid.x, one2048th.x;" +
1244012687 "MOV temp, fragment.texcoord[1];" +
1244112688 /*
....@@ -12456,20 +12703,20 @@
1245612703 "MUL temp, floor, mapgrid.x;" +
1245712704 //"TEX depth0, temp, texture[1], 2D;" +
1245812705 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12459
- TextureFetch("depth0", "temp", "1") +
12706
+ ShadowTextureFetch("depth0", "temp", "1") +
1246012707 "") +
1246112708 "ADD temp.x, temp.x, mapgrid.x;" +
1246212709 //"TEX depth1, temp, texture[1], 2D;" +
1246312710 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12464
- TextureFetch("depth1", "temp", "1") +
12711
+ ShadowTextureFetch("depth1", "temp", "1") +
1246512712 "") +
1246612713 "ADD temp.y, temp.y, mapgrid.x;" +
1246712714 //"TEX depth2, temp, texture[1], 2D;" +
12468
- TextureFetch("depth2", "temp", "1") +
12715
+ ShadowTextureFetch("depth2", "temp", "1") +
1246912716 "SUB temp.x, temp.x, mapgrid.x;" +
1247012717 //"TEX depth3, temp, texture[1], 2D;" +
1247112718 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12472
- TextureFetch("depth3", "temp", "1") +
12719
+ ShadowTextureFetch("depth3", "temp", "1") +
1247312720 "") +
1247412721 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1247512722 //"MOV params, material;" +
....@@ -12840,10 +13087,10 @@
1284013087 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1284113088 "") +
1284213089
12843
- // display shadow only (bump == 0)
13090
+ // display shadow only (fakedepth == 0)
1284413091 "SUB temp.x, half.x, shadow.x;" +
1284513092 "MOV temp.y, -params5.z;" + // params6.x;" +
12846
- "SLT temp.z, temp.y, -one2048th.x;" +
13093
+ "SLT temp.z, temp.y, -c256i.x;" +
1284713094 "SUB temp.y, one.x, temp.z;" +
1284813095 "MUL temp.x, temp.x, temp.y;" +
1284913096 "KIL temp.x;" +
....@@ -13174,8 +13421,19 @@
1317413421 //once = true;
1317513422 }
1317613423
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 " : ""));
13424
+ String program = programmax;
13425
+
13426
+ if (Globals.MINSHADER)
13427
+ {
13428
+ program = programmin;
13429
+ }
13430
+
13431
+ if (Globals.DEBUG)
13432
+ {
13433
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13434
+ System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13435
+ }
13436
+
1317913437 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1318013438
1318113439 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -13222,7 +13480,8 @@
1322213480 "\n" +
1322313481 "END\n";
1322413482
13225
- System.out.println("Program shadow #" + 0 + "; length = " + program.length());
13483
+ if (Globals.DEBUG)
13484
+ System.out.println("Program shadow #" + 0 + "; length = " + program.length());
1322613485 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1322713486
1322813487 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -13267,25 +13526,26 @@
1326713526 return out;
1326813527 }
1326913528
13270
- String TextureFetch(String dest, String src, String unit)
13529
+ // Also does frustum culling
13530
+ String ShadowTextureFetch(String dest, String src, String unit)
1327113531 {
1327213532 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1327313533 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1327413534 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13535
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13536
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1327513537 "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;" +
13538
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13539
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1328013540 //"SWZ buffer, temp, w,w,w,w;";
13281
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13541
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1328213542 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1328313543 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1328413544 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13285
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13545
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1328613546
13287
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13288
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13547
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13548
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1328913549 }
1329013550
1329113551 String Shadow(String depth, String shadow)
....@@ -13332,7 +13592,7 @@
1333213592 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1333313593 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1333413594
13335
- // No shadow when out of frustrum
13595
+ // No shadow when out of frustum
1333613596 "SGE temp.x, " + depth + ".z, one.z;" +
1333713597 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1333813598 "";
....@@ -14065,7 +14325,7 @@
1406514325
1406614326 // fev 2014???
1406714327 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
14068
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14328
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1406914329 pingthread.StepToTarget(true); // true);
1407014330 }
1407114331 // if (!LIVE)
....@@ -14130,14 +14390,15 @@
1413014390 drag = false;
1413114391 //System.out.println("Mouse DOWN");
1413214392 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);
14393
+ //ClickInfo info = new ClickInfo();
14394
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14395
+ object.clickInfo.pane = this;
14396
+ object.clickInfo.camera = renderCamera;
14397
+ object.clickInfo.x = x;
14398
+ object.clickInfo.y = y;
14399
+ object.clickInfo.modifiers = modifiersex;
14400
+ editObj = object.doEditClick(//info,
14401
+ 0);
1414114402 if (!editObj)
1414214403 {
1414314404 hasMarquee = true;
....@@ -14419,12 +14680,18 @@
1441914680 void GoDown(int mod)
1442014681 {
1442114682 MODIFIERS |= COMMAND;
14422
- /*
14683
+ boolean isVR = (mouseMode&VR)!=0;
14684
+ /**/
1442314685 if((mod&SHIFT) == SHIFT)
14424
- manipCamera.RotatePosition(0, -speed);
14686
+ {
14687
+ if (isVR)
14688
+ manipCamera.RotateInterest(0, -speed);
14689
+ else
14690
+ manipCamera.RotatePosition(0, -speed);
14691
+ }
1442514692 else
14426
- manipCamera.BackForth(0, -speed*delta, getWidth());
14427
- */
14693
+ manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth());
14694
+ /**/
1442814695 if ((mod & SHIFT) == SHIFT)
1442914696 {
1443014697 mouseMode = mouseMode; // VR??
....@@ -14433,6 +14700,8 @@
1443314700 mouseMode |= BACKFORTH;
1443414701 }
1443514702
14703
+ targetLookAt.set(manipCamera.lookAt);
14704
+
1443614705 //prevX = X = anchorX;
1443714706 prevY = Y = anchorY - (int) (renderCamera.Distance());
1443814707 }
....@@ -14440,12 +14709,19 @@
1444014709 void GoUp(int mod)
1444114710 {
1444214711 MODIFIERS |= COMMAND;
14443
- /*
14712
+ /**/
14713
+ boolean isVR = (mouseMode&VR)!=0;
14714
+
1444414715 if((mod&SHIFT) == SHIFT)
14445
- manipCamera.RotatePosition(0, speed);
14716
+ {
14717
+ if (isVR)
14718
+ manipCamera.RotateInterest(0, speed);
14719
+ else
14720
+ manipCamera.RotatePosition(0, speed);
14721
+ }
1444614722 else
14447
- manipCamera.BackForth(0, speed*delta, getWidth());
14448
- */
14723
+ manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth());
14724
+ /**/
1444914725 if ((mod & SHIFT) == SHIFT)
1445014726 {
1445114727 mouseMode = mouseMode;
....@@ -14454,6 +14730,8 @@
1445414730 mouseMode |= BACKFORTH;
1445514731 }
1445614732
14733
+ targetLookAt.set(manipCamera.lookAt);
14734
+
1445714735 //prevX = X = anchorX;
1445814736 prevY = Y = anchorY + (int) (renderCamera.Distance());
1445914737 }
....@@ -14461,12 +14739,17 @@
1446114739 void GoLeft(int mod)
1446214740 {
1446314741 MODIFIERS |= COMMAND;
14464
- /*
14742
+ /**/
1446514743 if((mod&SHIFT) == SHIFT)
14466
- manipCamera.RotatePosition(speed, 0);
14744
+ manipCamera.Translate(speed*delta, 0, getWidth());
1446714745 else
14468
- manipCamera.Translate(speed*delta, 0, getWidth());
14469
- */
14746
+ {
14747
+ if ((mouseMode&VR)!=0)
14748
+ manipCamera.RotateInterest(-speed, 0);
14749
+ else
14750
+ manipCamera.RotatePosition(speed, 0);
14751
+ }
14752
+ /**/
1447014753 if ((mod & SHIFT) == SHIFT)
1447114754 {
1447214755 mouseMode = mouseMode;
....@@ -14475,6 +14758,8 @@
1447514758 mouseMode |= ROTATE;
1447614759 } // TRANSLATE;
1447714760
14761
+ targetLookAt.set(manipCamera.lookAt);
14762
+
1447814763 prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance());
1447914764 prevY = Y = anchorY;
1448014765 }
....@@ -14482,12 +14767,18 @@
1448214767 void GoRight(int mod)
1448314768 {
1448414769 MODIFIERS |= COMMAND;
14485
- /*
14770
+ /**/
1448614771 if((mod&SHIFT) == SHIFT)
14487
- manipCamera.RotatePosition(-speed, 0);
14772
+ manipCamera.Translate(-speed*delta, 0, getWidth());
1448814773 else
14489
- manipCamera.Translate(-speed*delta, 0, getWidth());
14490
- */
14774
+ {
14775
+ if ((mouseMode&VR)!=0)
14776
+ manipCamera.RotateInterest(speed, 0);
14777
+ else
14778
+ manipCamera.RotatePosition(-speed, 0);
14779
+ }
14780
+
14781
+ /**/
1449114782 if ((mod & SHIFT) == SHIFT)
1449214783 {
1449314784 mouseMode = mouseMode;
....@@ -14496,6 +14787,8 @@
1449614787 mouseMode |= ROTATE;
1449714788 } // TRANSLATE;
1449814789
14790
+ targetLookAt.set(manipCamera.lookAt);
14791
+
1449914792 prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance());
1450014793 prevY = Y = anchorY;
1450114794 }
....@@ -14537,15 +14830,16 @@
1453714830 if (editObj)
1453814831 {
1453914832 drag = true;
14540
- ClickInfo info = new ClickInfo();
14541
- info.bounds.setBounds(0, 0,
14833
+ //ClickInfo info = new ClickInfo();
14834
+ object.clickInfo.bounds.setBounds(0, 0,
1454214835 (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);
14836
+ object.clickInfo.pane = this;
14837
+ object.clickInfo.camera = renderCamera;
14838
+ object.clickInfo.x = x;
14839
+ object.clickInfo.y = y;
14840
+ object //.GetWindow().copy
14841
+ .doEditDrag(//info,
14842
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1454914843 } else
1455014844 {
1455114845 if (x < startX)
....@@ -14694,24 +14988,27 @@
1469414988 }
1469514989 }
1469614990
14991
+// ClickInfo clickInfo = new ClickInfo();
14992
+
1469714993 public void mouseMoved(MouseEvent e)
1469814994 {
1469914995 //System.out.println("mouseMoved: " + e);
1470014996 if (isRenderer)
1470114997 return;
1470214998
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;
14999
+ // Mouse cursor feedback
15000
+ object.clickInfo.x = e.getX();
15001
+ object.clickInfo.y = e.getY();
15002
+ object.clickInfo.modifiers = e.getModifiersEx();
15003
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
15004
+ object.clickInfo.pane = this;
15005
+ object.clickInfo.camera = renderCamera;
1471015006 if (!isRenderer)
1471115007 {
1471215008 //ObjEditor editWindow = object.editWindow;
1471315009 //Object3D copy = editWindow.copy;
14714
- if (object.doEditClick(ci, 0))
15010
+ if (object.doEditClick(//clickInfo,
15011
+ 0))
1471515012 {
1471615013 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1471715014 } else
....@@ -14726,7 +15023,8 @@
1472615023 Globals.MOUSEDRAGGED = false;
1472715024
1472815025 movingcamera = false;
14729
- X = Y = 0;
15026
+ X = 0; // getBounds().width/2;
15027
+ Y = 0; // getBounds().height/2;
1473015028 //System.out.println("mouseReleased: " + e);
1473115029 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1473215030 }
....@@ -14982,7 +15280,8 @@
1498215280 // break;
1498315281 case 'T':
1498415282 CACHETEXTURE ^= true;
14985
- textures.clear();
15283
+ texturepigment.clear();
15284
+ texturebump.clear();
1498615285 // repaint();
1498715286 break;
1498815287 case 'Y':
....@@ -14992,8 +15291,8 @@
1499215291 case 'K':
1499315292 KOMPACTTEXTURE ^= true;
1499415293 //textures.clear();
14995
- break;
14996
- case 'P': // Texture Projection macros
15294
+ // break;
15295
+ //case 'P': // Texture Projection macros
1499715296 // SAVETEXTURE ^= true;
1499815297 macromode = true;
1499915298 Udebug = Vdebug = NORMALdebug = false; programInitialized = false;
....@@ -15067,7 +15366,9 @@
1506715366 case 'E' : COMPACT ^= true;
1506815367 repaint();
1506915368 break;
15070
- case 'W' : DEBUGHSB ^= true;
15369
+ case 'W' : // Wide Window (fullscreen)
15370
+ //DEBUGHSB ^= true;
15371
+ ObjEditor.theFrame.ToggleFullScreen();
1507115372 repaint();
1507215373 break;
1507315374 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -15093,13 +15394,7 @@
1509315394 repaint();
1509415395 break;
1509515396 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':
15397
+ //case 'L':
1510315398 if (lightMode)
1510415399 {
1510515400 lightMode = false;
....@@ -15118,7 +15413,7 @@
1511815413 targetLookAt.set(manipCamera.lookAt);
1511915414 repaint();
1512015415 break;
15121
- case 'p':
15416
+ case 'P': // p':
1512215417 // c'est quoi ca au juste? spherical ^= true;
1512315418 Skinshader ^= true; programInitialized = false;
1512415419 repaint();
....@@ -15163,20 +15458,24 @@
1516315458 OCCLUSION_CULLING ^= true;
1516415459 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1516515460 break;
15166
- case '0': envyoff ^= true; repaint(); break;
15461
+ //case '0': envyoff ^= true; repaint(); break;
1516715462 case '1':
1516815463 case '2':
1516915464 case '3':
1517015465 case '4':
1517115466 case '5':
15172
- newenvy = Character.getNumericValue(key);
15173
- repaint();
15174
- break;
1517515467 case '6':
1517615468 case '7':
1517715469 case '8':
1517815470 case '9':
15179
- BGcolor = (key - '6')/3.f;
15471
+ if (true) // envyoff)
15472
+ {
15473
+ BGcolor = (key - '1')/8.f;
15474
+ }
15475
+ else
15476
+ {
15477
+ //newenvy = Character.getNumericValue(key);
15478
+ }
1518015479 repaint();
1518115480 break;
1518215481 case '!':
....@@ -15246,7 +15545,10 @@
1524615545 // kompactbit = 6;
1524715546 // break;
1524815547 case ' ':
15249
- ObjEditor.theFrame.ToggleFullScreen();
15548
+ lightMode ^= true;
15549
+ Globals.lighttouched = true;
15550
+ manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
15551
+ targetLookAt.set(manipCamera.lookAt);
1525015552 repaint();
1525115553 break;
1525215554 //case '`' :
....@@ -15295,12 +15597,6 @@
1529515597 break;
1529615598 case '+':
1529715599
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
-
1530415600 /*
1530515601 //fontsize += 1;
1530615602 bbzoom *= 2;
....@@ -15318,17 +15614,17 @@
1531815614 case '=':
1531915615 IncDepth();
1532015616 //fontsize += 1;
15321
- object.editWindow.refreshContents(true);
15617
+ object.GetWindow().refreshContents(true);
1532215618 maskbit = 6;
1532315619 break;
1532415620 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1532515621 DecDepth();
1532615622 maskbit = 5;
1532715623 //if(fontsize > 1) fontsize -= 1;
15328
- if (object.editWindow == null)
15329
- new Exception().printStackTrace();
15330
- else
15331
- object.editWindow.refreshContents(true);
15624
+// if (object.editWindow == null)
15625
+// new Exception().printStackTrace();
15626
+// else
15627
+ object.GetWindow().refreshContents(true);
1533215628 break;
1533315629 case '{':
1533415630 manipCamera.shaper_fovy /= 1.1;
....@@ -15552,7 +15848,7 @@
1555215848 }
1555315849 */
1555415850
15555
- object.editWindow.EditSelection(false);
15851
+ object.GetWindow().EditSelection(false);
1555615852 }
1555715853
1555815854 void SelectParent()
....@@ -15569,10 +15865,10 @@
1556915865 {
1557015866 //selectees.remove(i);
1557115867 System.out.println("select parent of " + elem);
15572
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15868
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1557315869 } else
1557415870 {
15575
- group.editWindow.Select(elem.GetTreePath(), first, true);
15871
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1557615872 }
1557715873
1557815874 first = false;
....@@ -15614,12 +15910,12 @@
1561415910 for (int j = 0; j < group.children.size(); j++)
1561515911 {
1561615912 elem = (Object3D) group.children.elementAt(j);
15617
- object.editWindow.Select(elem.GetTreePath(), first, true);
15913
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1561815914 first = false;
1561915915 }
1562015916 } else
1562115917 {
15622
- object.editWindow.Select(elem.GetTreePath(), first, true);
15918
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1562315919 }
1562415920
1562515921 first = false;
....@@ -15630,21 +15926,21 @@
1563015926 {
1563115927 //Composite group = (Composite) object;
1563215928 Object3D group = object;
15633
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15929
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1563415930 }
1563515931
1563615932 void ResetTransform(int mask)
1563715933 {
1563815934 //Composite group = (Composite) object;
1563915935 Object3D group = object;
15640
- group.editWindow.ResetTransform(mask);
15936
+ group.GetWindow().ResetTransform(mask);
1564115937 }
1564215938
1564315939 void FlipTransform()
1564415940 {
1564515941 //Composite group = (Composite) object;
1564615942 Object3D group = object;
15647
- group.editWindow.FlipTransform();
15943
+ group.GetWindow().FlipTransform();
1564815944 // group.editWindow.ReduceMesh(true);
1564915945 }
1565015946
....@@ -15652,7 +15948,7 @@
1565215948 {
1565315949 //Composite group = (Composite) object;
1565415950 Object3D group = object;
15655
- group.editWindow.PrintMemory();
15951
+ group.GetWindow().PrintMemory();
1565615952 // group.editWindow.ReduceMesh(true);
1565715953 }
1565815954
....@@ -15660,7 +15956,7 @@
1566015956 {
1566115957 //Composite group = (Composite) object;
1566215958 Object3D group = object;
15663
- group.editWindow.ResetCentroid();
15959
+ group.GetWindow().ResetCentroid();
1566415960 }
1566515961
1566615962 void IncDepth()
....@@ -15742,8 +16038,6 @@
1574216038
1574316039 int width = getBounds().width;
1574416040 int height = getBounds().height;
15745
- ClickInfo info = new ClickInfo();
15746
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1574716041 //Image img = CreateImage(width, height);
1574816042 //System.out.println("width = " + width + "; height = " + height + "\n");
1574916043
....@@ -15820,48 +16114,77 @@
1582016114 }
1582116115 if (object != null && !hasMarquee)
1582216116 {
16117
+ if (object.clickInfo == null)
16118
+ object.clickInfo = new ClickInfo();
16119
+ ClickInfo info = object.clickInfo;
16120
+ //ClickInfo info = new ClickInfo();
16121
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16122
+
1582316123 if (isRenderer)
1582416124 {
15825
- info.flags++;
16125
+ object.clickInfo.flags++;
1582616126 double frameAspect = (double) width / (double) height;
1582716127 if (frameAspect > renderCamera.aspect)
1582816128 {
1582916129 int desired = (int) ((double) height * renderCamera.aspect);
15830
- info.bounds.width -= width - desired;
15831
- info.bounds.x += (width - desired) / 2;
16130
+ object.clickInfo.bounds.width -= width - desired;
16131
+ object.clickInfo.bounds.x += (width - desired) / 2;
1583216132 } else
1583316133 {
1583416134 int desired = (int) ((double) width / renderCamera.aspect);
15835
- info.bounds.height -= height - desired;
15836
- info.bounds.y += (height - desired) / 2;
16135
+ object.clickInfo.bounds.height -= height - desired;
16136
+ object.clickInfo.bounds.y += (height - desired) / 2;
1583716137 }
1583816138 }
15839
- info.g = gr;
15840
- info.camera = renderCamera;
16139
+
16140
+ object.clickInfo.g = gr;
16141
+ object.clickInfo.camera = renderCamera;
1584116142 /*
1584216143 // Memory intensive (brep.verticescopy)
1584316144 if (!(object instanceof Composite))
1584416145 object.draw(info, 0, false); // SLOW :
1584516146 */
15846
- if (!isRenderer)
16147
+ if (!isRenderer) // && drag)
1584716148 {
15848
- object.drawEditHandles(info, 0);
15849
-
15850
- if (drag && (X != 0 || Y != 0) && object.selection.Size() > 0)
16149
+ Grafreed.Assert(object != null);
16150
+ Grafreed.Assert(object.selection != null);
16151
+ if (object.selection.Size() > 0)
1585116152 {
15852
- switch (object.selection.get(0).hitSomething)
16153
+ int hitSomething = object.selection.get(0).hitSomething;
16154
+
16155
+ object.clickInfo.DX = 0;
16156
+ object.clickInfo.DY = 0;
16157
+ object.clickInfo.W = 1;
16158
+ if (hitSomething == Object3D.hitCenter)
1585316159 {
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;
16160
+ info.DX = X;
16161
+ if (X != 0)
16162
+ info.DX -= info.bounds.width/2;
16163
+
16164
+ info.DY = Y;
16165
+ if (Y != 0)
16166
+ info.DY -= info.bounds.height/2;
1586316167 }
15864
-
16168
+
16169
+ object.drawEditHandles(//info,
16170
+ 0);
16171
+
16172
+ if (drag && (X != 0 || Y != 0))
16173
+ {
16174
+ switch (hitSomething)
16175
+ {
16176
+ case Object3D.hitCenter: gr.setColor(Color.white);
16177
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16178
+ break;
16179
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16180
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16181
+ break;
16182
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16183
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16184
+ break;
16185
+ }
16186
+
16187
+ }
1586516188 }
1586616189 }
1586716190 }
....@@ -15876,7 +16199,7 @@
1587616199 if (hasMarquee)
1587716200 {
1587816201 gr.setXORMode(Color.white);
15879
- gr.setColor(Color.red);
16202
+ gr.setColor(Color.white);
1588016203 if (!firstime)
1588116204 {
1588216205 gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH);
....@@ -16343,6 +16666,8 @@
1634316666 private /*static*/ boolean firstime;
1634416667 private /*static*/ cVector newView = new cVector();
1634516668 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16669
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16670
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1634616671 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1634716672 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1634816673 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16355,29 +16680,67 @@
1635516680 {
1635616681 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1635716682
16683
+ int usedsuf = 0;
16684
+
1635816685 for (int i = 0; i < suffixes.length; i++)
1635916686 {
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)
16687
+ String[] suffixe = suffixes;
16688
+ String[] fallback = suffixes2;
16689
+ String[] fallfallback = suffixes3;
16690
+
16691
+ for (int c=usedsuf; --c>=0;)
1636516692 {
16366
- throw new IOException("Unable to load texture " + resourceName);
16693
+// String[] temp = suffixe;
16694
+// suffixe = fallback;
16695
+// fallback = fallfallback;
16696
+// fallfallback = temp;
1636716697 }
16698
+
16699
+ String resourceName = basename + suffixe[i] + "." + suffix;
16700
+ TextureData data;
16701
+
16702
+ try
16703
+ {
16704
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16705
+ mipmapped,
16706
+ FileUtil.getFileSuffix(resourceName));
16707
+ }
16708
+ catch (Exception e)
16709
+ {
16710
+ try
16711
+ {
16712
+ resourceName = basename + fallback[i] + "." + suffix;
16713
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16714
+ mipmapped,
16715
+ FileUtil.getFileSuffix(resourceName));
16716
+ }
16717
+ catch (Exception e2)
16718
+ {
16719
+ resourceName = basename + fallfallback[i] + "." + suffix;
16720
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16721
+ mipmapped,
16722
+ FileUtil.getFileSuffix(resourceName));
16723
+ }
16724
+ }
16725
+
1636816726 //System.out.println("Target = " + targets[i]);
1636916727 cubemap.updateImage(data, targets[i]);
1637016728 }
1637116729
1637216730 return cubemap;
1637316731 }
16732
+
1637416733 int bigsphere = -1;
1637516734
1637616735 float BGcolor = 0.5f;
1637716736
16378
- private void DrawSkyBox(GL gl)
16737
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16738
+
16739
+ private void DrawSkyBox(GL gl, float ratio)
1637916740 {
16380
- if (envyoff || cubemap == null)
16741
+ if (//envyoff ||
16742
+ WIREFRAME ||
16743
+ cubemap == null)
1638116744 {
1638216745 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1638316746 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16392,7 +16755,17 @@
1639216755 // Compensates for ExaminerViewer's modification of modelview matrix
1639316756 gl.glMatrixMode(GL.GL_MODELVIEW);
1639416757 gl.glLoadIdentity();
16758
+ gl.glScalef(1,ratio,1);
1639516759
16760
+// colorV[0] = 2;
16761
+// colorV[1] = 2;
16762
+// colorV[2] = 2;
16763
+// colorV[3] = 1;
16764
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16765
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16766
+//
16767
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16768
+
1639616769 //gl.glActiveTexture(GL.GL_TEXTURE1);
1639716770 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1639816771
....@@ -16424,6 +16797,7 @@
1642416797 {
1642516798 gl.glScalef(1.0f, -1.0f, 1.0f);
1642616799 }
16800
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1642716801 gl.glMultMatrixd(viewrot_1, 0);
1642816802 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1642916803 //viewer.updateInverseRotation(gl);
....@@ -16464,7 +16838,8 @@
1646416838 gl.glDisable(GL.GL_TEXTURE_GEN_R);
1646516839
1646616840 cubemap.disable();
16467
- ////cubemap.unbind();
16841
+ //cubemap.dispose();
16842
+
1646816843 if (CULLFACE)
1646916844 {
1647016845 gl.glEnable(gl.GL_CULL_FACE);
....@@ -16659,6 +17034,14 @@
1665917034 }
1666017035 }
1666117036
17037
+ private Object3D GetFolder()
17038
+ {
17039
+ Object3D folder = object.GetWindow().copy;
17040
+ if (object.GetWindow().copy.selection.Size() > 0)
17041
+ folder = object.GetWindow().copy.selection.elementAt(0);
17042
+ return folder;
17043
+ }
17044
+
1666217045 class SelectBuffer implements GLEventListener
1666317046 {
1666417047
....@@ -16674,7 +17057,7 @@
1667417057 //new Exception().printStackTrace();
1667517058 System.out.println("select buffer init");
1667617059 // Use debug pipeline
16677
- drawable.setGL(new DebugGL(drawable.getGL()));
17060
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1667817061
1667917062 GL gl = drawable.getGL();
1668017063
....@@ -16738,6 +17121,17 @@
1673817121
1673917122 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1674017123
17124
+ if (PAINTMODE)
17125
+ {
17126
+ if (object.GetWindow().copy.selection.Size() > 0)
17127
+ {
17128
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17129
+
17130
+ // Make what you paint not selectable.
17131
+ paintobj.ResetSelectable();
17132
+ }
17133
+ }
17134
+
1674117135 //int tmp = selection_view;
1674217136 //selection_view = -1;
1674317137 int temp = DrawMode();
....@@ -16749,6 +17143,17 @@
1674917143 // temp = DEFAULT; // patch for selection debug
1675017144 Globals.drawMode = temp; // WARNING
1675117145
17146
+ if (PAINTMODE)
17147
+ {
17148
+ if (object.GetWindow().copy.selection.Size() > 0)
17149
+ {
17150
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17151
+
17152
+ // Revert.
17153
+ paintobj.RestoreSelectable();
17154
+ }
17155
+ }
17156
+
1675217157 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1675317158
1675417159 // trying different ways of getting the depth info over
....@@ -16852,29 +17257,31 @@
1685217257 }
1685317258
1685417259 if (!movingcamera && !PAINTMODE)
16855
- object.editWindow.ScreenFitPoint(); // fev 2014
17260
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1685617261
16857
- if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17262
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1685817263 {
16859
- Object3D paintobj = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17264
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1686017265
16861
- Object3D group = new Object3D("inst" + paintcount++);
17266
+ if (object.GetWindow().copy.selection.Size() > 0)
17267
+ {
17268
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1686217269
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();
17270
+ Object3D inst = new Object3D("inst" + paintcount++);
17271
+
17272
+ inst.CreateMaterial(); // use a void leaf to select instances
17273
+
17274
+ inst.add(paintobj); // link
17275
+
17276
+ object.GetWindow().SnapObject(inst);
17277
+
17278
+ Object3D folder = paintFolder; // GetFolder();
17279
+
17280
+ folder.add(inst);
17281
+
17282
+ object.GetWindow().ResetModel();
17283
+ object.GetWindow().refreshContents();
17284
+ }
1687817285 }
1687917286 else
1688017287 paintcount = 0;
....@@ -16968,6 +17375,7 @@
1696817375
1696917376 public void init(GLAutoDrawable drawable)
1697017377 {
17378
+ if (Globals.DEBUG)
1697117379 System.out.println("shadow buffer init");
1697217380
1697317381 GL gl = drawable.getGL();
....@@ -17196,10 +17604,14 @@
1719617604 gl.glFlush();
1719717605
1719817606 /**/
17199
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17607
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1720017608
17201
- float[] pixels = occlusionsizebuffer.array();
17609
+ float[] depths = occlusiondepthbuffer.array();
1720217610
17611
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17612
+
17613
+ int[] pixels = selectsizebuffer.array();
17614
+
1720317615 double r = 0, g = 0, b = 0;
1720417616
1720517617 double count = 0;
....@@ -17210,7 +17622,7 @@
1721017622
1721117623 double FACTOR = 1;
1721217624
17213
- for (int i = 0; i < pixels.length; i++)
17625
+ for (int i = 0; i < depths.length; i++)
1721417626 {
1721517627 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1721617628 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -17293,7 +17705,7 @@
1729317705
1729417706 double scale = ray.z; // 1; // cos
1729517707
17296
- float depth = pixels[newindex];
17708
+ float depth = depths[newindex];
1729717709
1729817710 /*
1729917711 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -17490,11 +17902,14 @@
1749017902 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1749117903 static IntBuffer bigAAbuffer;
1749217904 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
17493
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17905
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1749417906 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1749517907 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1749617908 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17497
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17909
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17910
+
17911
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17912
+
1749817913 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1749917914 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1750017915 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();