Normand Briere
2019-08-12 8f1afe25ea8fc8801aab66331c32a50859a758c2
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;
....@@ -150,6 +187,18 @@
150187 }
151188
152189 private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
190
+
191
+ public void LoadSkybox(String name, String ext, boolean mipmap) throws GLException
192
+ {
193
+ try
194
+ {
195
+ cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
196
+ } catch (IOException e)
197
+ {
198
+ System.out.println("NAME = " + name);
199
+ e.printStackTrace(); // throw new RuntimeException(e);
200
+ }
201
+ }
153202
154203 void SetAsGLRenderer(boolean b)
155204 {
....@@ -169,7 +218,8 @@
169218
170219 SetCamera(cam);
171220
172
- SetLight(new Camera(new cVector(10, 10, -20)));
221
+ // Warning: not used.
222
+ SetLight(new Camera(new cVector(15, 10, -20)));
173223
174224 object = o;
175225
....@@ -1447,6 +1497,8 @@
14471497 gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
14481498 }
14491499
1500
+ float[] colorV = new float[4];
1501
+
14501502 void SetColor(Object3D obj, Vertex p0)
14511503 {
14521504 CameraPane display = this;
....@@ -1514,8 +1566,6 @@
15141566 {
15151567 return;
15161568 }
1517
-
1518
- float[] colorV = new float[3];
15191569
15201570 if (false) // marked)
15211571 {
....@@ -2065,7 +2115,7 @@
20652115 //System.err.println("Oeil on");
20662116 OEIL = true;
20672117 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2068
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2118
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
20692119 //pingthread.StepToTarget(true);
20702120 }
20712121
....@@ -2298,10 +2348,17 @@
22982348 HANDLES ^= true;
22992349 }
23002350
2351
+ Object3D paintFolder;
2352
+
23012353 void TogglePaint()
23022354 {
23032355 PAINTMODE ^= true;
23042356 paintcount = 0;
2357
+
2358
+ if (PAINTMODE)
2359
+ {
2360
+ paintFolder = GetFolder();
2361
+ }
23052362 }
23062363
23072364 void SwapCamera(int a, int b)
....@@ -2398,126 +2455,19 @@
23982455 return currentGL;
23992456 }
24002457
2401
- private void GetRemoteZip(String url, String name, boolean unzip, boolean save)
2458
+ static private BufferedImage CreateBim(TextureData texturedata)
24022459 {
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
-
2460
+ Grafreed.Assert(texturedata != null);
2461
+
2462
+ int width = texturedata.getWidth();
2463
+ int height = texturedata.getHeight();
2464
+
2465
+ Buffer buffer = texturedata.getBuffer();
2466
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2467
+
2468
+ byte[] bytes = bytebuf.array();
2469
+
2470
+ return CreateBim(bytes, width, height);
25212471 }
25222472
25232473 /**/
....@@ -2528,28 +2478,31 @@
25282478
25292479 int resolution;
25302480
2531
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2481
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
25322482 {
2533
- texture = tex;
2483
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2484
+ texturedata = texdata;
25342485 resolution = res;
25352486 }
25362487 }
25372488 /**/
25382489
25392490 // 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>();
2491
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2492
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2493
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2494
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2495
+
25432496 int pigmentdepth = 0;
25442497 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
25452498 int bumpdepth = 0;
25462499 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
25472500 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
25482501 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2549
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2502
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
25502503 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
25512504
2552
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2505
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
25532506 {
25542507 TextureData texturedata = null;
25552508
....@@ -2568,13 +2521,34 @@
25682521 if (bump)
25692522 texturedata = ConvertBump(texturedata, false);
25702523
2571
- com.sun.opengl.util.texture.Texture texture =
2572
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2524
+// com.sun.opengl.util.texture.Texture texture =
2525
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
25732526
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);
2527
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2528
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
25762529
2577
- return texture;
2530
+ return texturedata;
2531
+ }
2532
+
2533
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2534
+ {
2535
+ TextureData texturedata = null;
2536
+
2537
+ try
2538
+ {
2539
+ texturedata =
2540
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2541
+ bim,
2542
+ true);
2543
+ } catch (Exception e)
2544
+ {
2545
+ throw new javax.media.opengl.GLException(e);
2546
+ }
2547
+
2548
+ if (bump)
2549
+ texturedata = ConvertBump(texturedata, false);
2550
+
2551
+ return texturedata;
25782552 }
25792553
25802554 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3647,6 +3621,8 @@
36473621
36483622 System.out.println("LOADING TEXTURE : " + name);
36493623
3624
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3625
+
36503626 //
36513627 if (false) // compressbit > 0)
36523628 {
....@@ -8045,7 +8021,7 @@
80458021 String pigment = Object3D.GetPigment(tex);
80468022 String bump = Object3D.GetBump(tex);
80478023
8048
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8024
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
80498025 {
80508026 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
80518027 // System.out.println("; bump = " + bump);
....@@ -8060,8 +8036,8 @@
80608036 pigment = null;
80618037 }
80628038
8063
- ReleaseTexture(bump, true);
8064
- ReleaseTexture(pigment, false);
8039
+ ReleaseTexture(tex, true);
8040
+ ReleaseTexture(tex, false);
80658041 }
80668042
80678043 public void ReleasePigmentTexture(cTexture tex) // INTERFACE
....@@ -8079,7 +8055,7 @@
80798055
80808056 String pigment = Object3D.GetPigment(tex);
80818057
8082
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8058
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
80838059 {
80848060 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
80858061 // System.out.println("; bump = " + bump);
....@@ -8090,7 +8066,7 @@
80908066 pigment = null;
80918067 }
80928068
8093
- ReleaseTexture(pigment, false);
8069
+ ReleaseTexture(tex, false);
80948070 }
80958071
80968072 public void ReleaseBumpTexture(cTexture tex) // INTERFACE
....@@ -8108,7 +8084,7 @@
81088084
81098085 String bump = Object3D.GetBump(tex);
81108086
8111
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8087
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
81128088 {
81138089 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
81148090 // System.out.println("; bump = " + bump);
....@@ -8119,10 +8095,10 @@
81198095 bump = null;
81208096 }
81218097
8122
- ReleaseTexture(bump, true);
8098
+ ReleaseTexture(tex, true);
81238099 }
81248100
8125
- void ReleaseTexture(String tex, boolean bump)
8101
+ void ReleaseTexture(cTexture tex, boolean bump)
81268102 {
81278103 if (// DrawMode() != 0 || /*tex == null ||*/
81288104 ambientOcclusion ) // || !textureon)
....@@ -8133,7 +8109,7 @@
81338109 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
81348110
81358111 if (tex != null)
8136
- texture = textures.get(tex);
8112
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
81378113
81388114 // //assert( texture != null );
81398115 // if (texture == null)
....@@ -8227,47 +8203,50 @@
82278203
82288204 /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
82298205 {
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
- }
8206
+// if (// DrawMode() != 0 || /*tex == null ||*/
8207
+// ambientOcclusion ) // || !textureon)
8208
+// {
8209
+// return; // false;
8210
+// }
8211
+//
8212
+// if (tex == null)
8213
+// {
8214
+// BindTexture(null,false,resolution);
8215
+// BindTexture(null,true,resolution);
8216
+// return;
8217
+// }
8218
+//
8219
+// String pigment = Object3D.GetPigment(tex);
8220
+// String bump = Object3D.GetBump(tex);
8221
+//
8222
+// usedtextures.add(pigment);
8223
+// usedtextures.add(bump);
8224
+//
8225
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8226
+// {
8227
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8228
+// // System.out.println("; bump = " + bump);
8229
+// }
8230
+//
8231
+// if (bump.equals(""))
8232
+// {
8233
+// bump = null;
8234
+// }
8235
+// if (pigment.equals(""))
8236
+// {
8237
+// pigment = null;
8238
+// }
8239
+//
8240
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8241
+// BindTexture(pigment, false, resolution);
8242
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8243
+// BindTexture(bump, true, resolution);
8244
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8245
+//
8246
+// return; // true;
82428247
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;
8248
+ BindPigmentTexture(tex, resolution);
8249
+ BindBumpTexture(tex, resolution);
82718250 }
82728251
82738252 /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8286,9 +8265,9 @@
82868265
82878266 String pigment = Object3D.GetPigment(tex);
82888267
8289
- usedtextures.put(pigment, pigment);
8268
+ usedtextures.add(tex);
82908269
8291
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8270
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
82928271 {
82938272 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
82948273 // System.out.println("; bump = " + bump);
....@@ -8300,7 +8279,7 @@
83008279 }
83018280
83028281 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8303
- BindTexture(pigment, false, resolution);
8282
+ BindTexture(tex, false, resolution);
83048283 }
83058284
83068285 /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8319,9 +8298,9 @@
83198298
83208299 String bump = Object3D.GetBump(tex);
83218300
8322
- usedtextures.put(bump, bump);
8301
+ usedtextures.add(tex);
83238302
8324
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8303
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
83258304 {
83268305 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
83278306 // System.out.println("; bump = " + bump);
....@@ -8333,7 +8312,7 @@
83338312 }
83348313
83358314 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8336
- BindTexture(bump, true, resolution);
8315
+ BindTexture(tex, true, resolution);
83378316 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
83388317 }
83398318
....@@ -8357,13 +8336,19 @@
83578336 return fileExists;
83588337 }
83598338
8360
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception
8339
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
83618340 {
8362
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8341
+ CacheTexture texturecache = null;
83638342
83648343 if (tex != null)
83658344 {
8366
- String texname = tex;
8345
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8346
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
8347
+
8348
+ if (texname.equals("") && texdata == null)
8349
+ {
8350
+ return null;
8351
+ }
83678352
83688353 String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
83698354
....@@ -8373,19 +8358,46 @@
83738358 // else
83748359 // if (!texname.startsWith("/"))
83758360 // texname = "/Users/nbriere/Textures/" + texname;
8376
- if (!FileExists(tex))
8361
+ if (!FileExists(texname) && !texname.startsWith("@"))
83778362 {
83788363 texname = fallbackTextureName;
83798364 }
83808365
83818366 if (CACHETEXTURE)
8382
- texture = textures.get(texname); // TEXTURE CACHE
8383
-
8384
- TextureData texturedata = null;
8385
-
8386
- if (texture == null || texture.resolution < resolution)
83878367 {
8388
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8368
+ if (texdata == null)
8369
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8370
+ else
8371
+ texturecache = bimtextures.get(texdata);
8372
+ }
8373
+
8374
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8375
+ {
8376
+ TextureData texturedata = null;
8377
+
8378
+ if (texdata != null && textureon)
8379
+ {
8380
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8381
+
8382
+ try
8383
+ {
8384
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8385
+ }
8386
+ catch (Exception e)
8387
+ {
8388
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8389
+ }
8390
+
8391
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8392
+ bimtextures.put(texdata, texturecache);
8393
+
8394
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8395
+
8396
+ //Object bim2 = CreateBim(texturecache.texturedata);
8397
+ //bim2 = bim;
8398
+ }
8399
+ else
8400
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
83898401 {
83908402 assert(!bump);
83918403 // if (bump)
....@@ -8396,19 +8408,23 @@
83968408 // }
83978409 // else
83988410 // {
8399
- texture = textures.get(tex);
8400
- if (texture == null)
8411
+ // texturecache = textures.get(texname); // suspicious
8412
+ if (texturecache == null)
84018413 {
8402
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8414
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
84038415 }
8416
+ else
8417
+ new Exception().printStackTrace();
84048418 // }
84058419 } else
8406
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8420
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
84078421 {
84088422 assert(bump);
8409
- texture = textures.get(tex);
8410
- if (texture == null)
8411
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8423
+ // texturecache = textures.get(texname); // suspicious
8424
+ if (texturecache == null)
8425
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8426
+ else
8427
+ new Exception().printStackTrace();
84128428 } else
84138429 {
84148430 //if (tex.equals("IMMORTAL"))
....@@ -8416,11 +8432,22 @@
84168432 // texture = GetResourceTexture("default.png");
84178433 //} else
84188434 //{
8419
- if (tex.equals("WHITE_NOISE"))
8435
+ if (texname.endsWith("WHITE_NOISE"))
84208436 {
8421
- texture = textures.get(tex);
8422
- if (texture == null)
8423
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8437
+ // texturecache = textures.get(texname); // suspicious
8438
+ if (texturecache == null)
8439
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8440
+ else
8441
+ new Exception().printStackTrace();
8442
+ } else
8443
+ {
8444
+ if (texname.startsWith("@"))
8445
+ {
8446
+ // texturecache = textures.get(texname); // suspicious
8447
+ if (texturecache == null)
8448
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8449
+ else
8450
+ new Exception().printStackTrace();
84248451 } else
84258452 {
84268453 if (textureon)
....@@ -8479,19 +8506,20 @@
84798506 if (texturedata == null)
84808507 throw new Exception();
84818508
8482
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8509
+ texturecache = new CacheTexture(texturedata,resolution);
84838510 //texture = GetTexture(tex, bump);
84848511 }
8512
+ }
84858513 }
84868514 //}
84878515 }
84888516
8489
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8517
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
84908518 {
84918519 //return false;
84928520
84938521 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8494
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8522
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
84958523 {
84968524 // String ext = "_highres";
84978525 // if (REDUCETEXTURE)
....@@ -8508,52 +8536,17 @@
85088536 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
85098537 if (!cachefile.exists())
85108538 {
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))
8539
+ //if (texturedata.getWidth() == texturedata.getHeight())
85208540 {
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);
8541
+ BufferedImage rendImage = CreateBim(texturedata);
8542
+
85518543 ImageWriter writer = null;
85528544 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
85538545 if (iter.hasNext()) {
85548546 writer = (ImageWriter)iter.next();
85558547 }
8556
- float compressionQuality = 0.9f;
8548
+
8549
+ float compressionQuality = 0.85f;
85578550 try
85588551 {
85598552 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8570,18 +8563,20 @@
85708563 }
85718564 }
85728565 }
8573
-
8566
+
8567
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8568
+
85748569 //System.out.println("Texture = " + tex);
8575
- if (textures.containsKey(texname))
8570
+ if (textures.containsKey(tex))
85768571 {
8577
- CacheTexture thetex = textures.get(texname);
8572
+ CacheTexture thetex = textures.get(tex);
85788573 thetex.texture.disable();
85798574 thetex.texture.dispose();
8580
- textures.remove(texname);
8575
+ textures.remove(tex);
85818576 }
85828577
8583
- texture.texturedata = texturedata;
8584
- textures.put(texname, texture);
8578
+ //texture.texturedata = texturedata;
8579
+ textures.put(tex, texturecache);
85858580
85868581 // newtex = true;
85878582 }
....@@ -8597,10 +8592,44 @@
85978592 }
85988593 }
85998594
8600
- return texture;
8595
+ return texturecache;
86018596 }
86028597
8603
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution) throws Exception
8598
+ static void EmbedTextures(cTexture tex)
8599
+ {
8600
+ if (tex.pigmentdata == null)
8601
+ {
8602
+ //String texname = Object3D.GetPigment(tex);
8603
+
8604
+ CacheTexture texturecache = texturepigment.get(tex);
8605
+
8606
+ if (texturecache != null)
8607
+ {
8608
+ tex.pw = texturecache.texturedata.getWidth();
8609
+ tex.ph = texturecache.texturedata.getHeight();
8610
+ tex.pigmentdata = //CompressJPEG(CreateBim
8611
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8612
+ ;
8613
+ //, tex.pw, tex.ph), 0.5f);
8614
+ }
8615
+ }
8616
+
8617
+ if (tex.bumpdata == null)
8618
+ {
8619
+ //String texname = Object3D.GetBump(tex);
8620
+
8621
+ CacheTexture texturecache = texturebump.get(tex);
8622
+
8623
+ if (texturecache != null)
8624
+ {
8625
+ tex.bw = texturecache.texturedata.getWidth();
8626
+ tex.bh = texturecache.texturedata.getHeight();
8627
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8628
+ }
8629
+ }
8630
+ }
8631
+
8632
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
86048633 {
86058634 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
86068635
....@@ -8618,21 +8647,21 @@
86188647 return texture!=null?texture.texture:null;
86198648 }
86208649
8621
- public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution) throws Exception
8650
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
86228651 {
86238652 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
86248653
86258654 return texture!=null?texture.texturedata:null;
86268655 }
86278656
8628
- boolean BindTexture(String tex, boolean bump, int resolution) throws Exception
8657
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
86298658 {
86308659 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
86318660 {
86328661 return false;
86338662 }
86348663
8635
- boolean newtex = false;
8664
+ //boolean newtex = false;
86368665
86378666 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
86388667
....@@ -8664,9 +8693,75 @@
86648693 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
86658694 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
86668695
8667
- return newtex;
8696
+ return true; // Warning: not used.
86688697 }
86698698
8699
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8700
+ {
8701
+ try
8702
+ {
8703
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8704
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8705
+ ImageWriter writer = writers.next();
8706
+
8707
+ ImageWriteParam param = writer.getDefaultWriteParam();
8708
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8709
+ param.setCompressionQuality(quality);
8710
+
8711
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8712
+ writer.setOutput(ios);
8713
+ writer.write(null, new IIOImage(image, null, null), param);
8714
+
8715
+ byte[] data = baos.toByteArray();
8716
+ writer.dispose();
8717
+ return data;
8718
+ }
8719
+ catch (Exception e)
8720
+ {
8721
+ e.printStackTrace();
8722
+ return null;
8723
+ }
8724
+ }
8725
+
8726
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8727
+ {
8728
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8729
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8730
+ ImageReader reader = writers.next();
8731
+
8732
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8733
+
8734
+ ImageReadParam param = reader.getDefaultReadParam();
8735
+ param.setDestination(bim);
8736
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8737
+
8738
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8739
+ reader.setInput(ios);
8740
+ BufferedImage bim2 = reader.read(0, param);
8741
+ reader.dispose();
8742
+
8743
+// WritableRaster raster = bim2.getRaster();
8744
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8745
+// byte[] bytes = data.getData();
8746
+//
8747
+// int[] pixels = new int[bytes.length/3];
8748
+// for (int i=pixels.length; --i>=0;)
8749
+// {
8750
+// int i3 = i*3;
8751
+// pixels[i] = 0xFF;
8752
+// pixels[i] <<= 8;
8753
+// pixels[i] |= bytes[i3+2] & 0xFF;
8754
+// pixels[i] <<= 8;
8755
+// pixels[i] |= bytes[i3+1] & 0xFF;
8756
+// pixels[i] <<= 8;
8757
+// pixels[i] |= bytes[i3] & 0xFF;
8758
+// }
8759
+//
8760
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8761
+
8762
+ return bim;
8763
+ }
8764
+
86708765 ShadowBuffer shadowPBuf;
86718766 AntialiasBuffer antialiasPBuf;
86728767 int MAXSTACK;
....@@ -8683,10 +8778,12 @@
86838778
86848779 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
86858780 MAXSTACK = temp[0];
8686
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8781
+ if (Globals.DEBUG)
8782
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
86878783 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
86888784 MAXSTACK = temp[0];
8689
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8785
+ if (Globals.DEBUG)
8786
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
86908787
86918788 // Use debug pipeline
86928789 //drawable.setGL(new DebugGL(gl)); //
....@@ -8694,7 +8791,8 @@
86948791 gl = drawable.getGL(); //
86958792
86968793 GL gl3 = getGL();
8697
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8794
+ if (Globals.DEBUG)
8795
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
86988796
86998797
87008798 //float pos[] = { 100, 100, 100, 0 };
....@@ -8859,7 +8957,7 @@
88598957
88608958 if (cubemap == null)
88618959 {
8862
- LoadEnvy(5);
8960
+ //LoadEnvy(1);
88638961 }
88648962
88658963 //cubemap.enable();
....@@ -9146,37 +9244,58 @@
91469244 cubemap = null;
91479245 return;
91489246 case 1:
9149
- name = "cubemaps/box_";
9150
- ext = "png";
9247
+ name = "cubemaps/rgb/";
9248
+ ext = "jpg";
91519249 reverseUP = false;
91529250 break;
91539251 case 2:
9154
- name = "cubemaps/uffizi_";
9155
- ext = "png";
9156
- break; // reverseUP = true; break;
9252
+ name = "cubemaps/uffizi/";
9253
+ ext = "jpg";
9254
+ reverseUP = false;
9255
+ break;
91579256 case 3:
9158
- name = "cubemaps/CloudyHills_";
9159
- ext = "tga";
9257
+ name = "cubemaps/CloudyHills/";
9258
+ ext = "jpg";
91609259 reverseUP = false;
91619260 break;
91629261 case 4:
9163
- name = "cubemaps/cornell_";
9262
+ name = "cubemaps/cornell/";
91649263 ext = "png";
91659264 reverseUP = false;
91669265 break;
9266
+ case 5:
9267
+ name = "cubemaps/skycube/";
9268
+ ext = "jpg";
9269
+ reverseUP = false;
9270
+ break;
9271
+ case 6:
9272
+ name = "cubemaps/SaintLazarusChurch3/";
9273
+ ext = "jpg";
9274
+ reverseUP = false;
9275
+ break;
9276
+ case 7:
9277
+ name = "cubemaps/Sodermalmsallen/";
9278
+ ext = "jpg";
9279
+ reverseUP = false;
9280
+ break;
9281
+ case 8:
9282
+ name = "cubemaps/Sodermalmsallen2/";
9283
+ ext = "jpg";
9284
+ reverseUP = false;
9285
+ break;
9286
+ case 9:
9287
+ name = "cubemaps/UnionSquare/";
9288
+ ext = "jpg";
9289
+ reverseUP = false;
9290
+ break;
91679291 default:
9168
- name = "cubemaps/rgb_";
9169
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9292
+ name = "cubemaps/box/";
9293
+ ext = "png"; /*mipmap = true;*/
9294
+ reverseUP = false;
91709295 break;
91719296 }
9172
-
9173
- try
9174
- {
9175
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
9176
- } catch (IOException e)
9177
- {
9178
- throw new RuntimeException(e);
9179
- }
9297
+
9298
+ LoadSkybox(name, ext, mipmap);
91809299 }
91819300
91829301 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -9208,8 +9327,12 @@
92089327 static double[] model = new double[16];
92099328 double[] camera2light = new double[16];
92109329 double[] light2camera = new double[16];
9211
- int newenvy = -1;
9212
- boolean envyoff = true; // false;
9330
+
9331
+ //int newenvy = -1;
9332
+ //boolean envyoff = false;
9333
+
9334
+ String loadedskyboxname;
9335
+
92139336 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
92149337 //float[] light0 = { 0,0,0 };
92159338 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9627,7 +9750,7 @@
96279750
96289751 if (renderCamera != lightCamera)
96299752 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9630
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
9753
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
96319754
96329755 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
96339756
....@@ -9643,7 +9766,7 @@
96439766
96449767 if (renderCamera != lightCamera)
96459768 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9646
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
9769
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
96479770
96489771 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
96499772
....@@ -9689,10 +9812,12 @@
96899812 rati = 1 / rati;
96909813 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
96919814 }
9692
- assert (newenvy == -1);
9815
+
9816
+ //assert (newenvy == -1);
9817
+
96939818 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
96949819 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9695
- DrawSkyBox(gl);
9820
+ DrawSkyBox(gl, (float)rati);
96969821 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
96979822 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
96989823 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10729,7 +10854,7 @@
1072910854
1073010855 if (wait)
1073110856 {
10732
- Sleep(500);
10857
+ Sleep(200); // blocks everything
1073310858
1073410859 wait = false;
1073510860 }
....@@ -10844,7 +10969,7 @@
1084410969 // if (parentcam != renderCamera) // not a light
1084510970 if (cam != lightCamera)
1084610971 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10847
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
10972
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1084810973
1084910974 for (int j = 0; j < 4; j++)
1085010975 {
....@@ -10859,7 +10984,7 @@
1085910984 // if (parentcam != renderCamera) // not a light
1086010985 if (cam != lightCamera)
1086110986 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10862
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
10987
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1086310988
1086410989 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1086510990
....@@ -10945,13 +11070,27 @@
1094511070 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1094611071 }
1094711072
10948
- if (newenvy > -1)
11073
+// if (newenvy > -1)
11074
+// {
11075
+// LoadEnvy(newenvy);
11076
+// }
11077
+//
11078
+// newenvy = -1;
11079
+
11080
+ if (object.skyboxname != null)
1094911081 {
10950
- LoadEnvy(newenvy);
11082
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11083
+ {
11084
+ LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11085
+ loadedskyboxname = object.skyboxname;
11086
+ }
1095111087 }
10952
-
10953
- newenvy = -1;
10954
-
11088
+ else
11089
+ {
11090
+ cubemap = null;
11091
+ loadedskyboxname = null;
11092
+ }
11093
+
1095511094 ratio = ((double) getWidth()) / getHeight();
1095611095 //System.out.println("ratio = " + ratio);
1095711096
....@@ -10967,7 +11106,7 @@
1096711106
1096811107 if (!IsFrozen() && !ambientOcclusion)
1096911108 {
10970
- DrawSkyBox(gl);
11109
+ DrawSkyBox(gl, (float)ratio);
1097111110 }
1097211111
1097311112 //if (selection_view == -1)
....@@ -11150,9 +11289,9 @@
1115011289
1115111290 gl.glMatrixMode(GL.GL_MODELVIEW);
1115211291
11153
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11154
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
11155
-//gl.glEnable(gl.GL_MULTISAMPLE);
11292
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11293
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11294
+gl.glEnable(gl.GL_MULTISAMPLE);
1115611295 } else
1115711296 {
1115811297 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -11163,7 +11302,7 @@
1116311302 //System.out.println("BLENDING ON");
1116411303 gl.glEnable(GL.GL_BLEND);
1116511304 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
11166
-
11305
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1116711306 gl.glMatrixMode(gl.GL_PROJECTION);
1116811307 gl.glLoadIdentity();
1116911308
....@@ -11253,7 +11392,7 @@
1125311392
1125411393 // if (cam != lightCamera)
1125511394 //for (int count = parentcam.GetTransformCount(); --count>=0;)
11256
- LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
11395
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1125711396 }
1125811397
1125911398 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -11412,7 +11551,7 @@
1141211551 }
1141311552 }
1141411553
11415
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11554
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1141611555 {
1141711556 //gl.glDepthFunc(GL.GL_LEQUAL);
1141811557 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11420,24 +11559,21 @@
1142011559
1142111560 boolean texon = textureon;
1142211561
11423
- if (RENDERPROGRAM > 0)
11424
- {
11425
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11426
- textureon = false;
11427
- }
11562
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11563
+ textureon = false;
11564
+
1142811565 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1142911566 //System.out.println("ALLO");
1143011567 gl.glColorMask(false, false, false, false);
1143111568 DrawObject(gl);
11432
- if (RENDERPROGRAM > 0)
11433
- {
11434
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11435
- textureon = texon;
11436
- }
11569
+
11570
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11571
+ textureon = texon;
11572
+
1143711573 gl.glColorMask(true, true, true, true);
1143811574
1143911575 gl.glDepthFunc(GL.GL_EQUAL);
11440
- //gl.glDepthMask(false);
11576
+ gl.glDepthMask(false);
1144111577 }
1144211578
1144311579 if (false) // DrawMode() == SHADOW)
....@@ -11649,7 +11785,7 @@
1164911785 if ((TRACK || SHADOWTRACK) || zoomonce)
1165011786 {
1165111787 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11652
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11788
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1165311789 pingthread.StepToTarget(true); // true);
1165411790 // zoomonce = false;
1165511791 }
....@@ -11777,20 +11913,32 @@
1177711913 ReleaseTextures(DEFAULT_TEXTURES);
1177811914
1177911915 if (CLEANCACHE)
11780
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11916
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1178111917 {
11782
- String tex = e.nextElement();
11918
+ cTexture tex = e.nextElement();
1178311919
1178411920 // System.out.println("Texture --------- " + tex);
1178511921
11786
- if (tex.equals("WHITE_NOISE"))
11922
+ if (tex.equals("WHITE_NOISE:"))
1178711923 continue;
1178811924
11789
- if (!usedtextures.containsKey(tex))
11925
+ if (!usedtextures.contains(tex))
1179011926 {
11927
+ CacheTexture gettex = texturepigment.get(tex);
1179111928 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11792
- textures.get(tex).texture.dispose();
11793
- textures.remove(tex);
11929
+ if (gettex != null)
11930
+ {
11931
+ gettex.texture.dispose();
11932
+ texturepigment.remove(tex);
11933
+ }
11934
+
11935
+ gettex = texturebump.get(tex);
11936
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11937
+ if (gettex != null)
11938
+ {
11939
+ gettex.texture.dispose();
11940
+ texturebump.remove(tex);
11941
+ }
1179411942 }
1179511943 }
1179611944 }
....@@ -12318,8 +12466,76 @@
1231812466
1231912467 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1232012468
12321
- String program =
12469
+ String programmin =
12470
+ // Min shader
1232212471 "!!ARBfp1.0\n" +
12472
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12473
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12474
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12475
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12476
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12477
+ "PARAM light2cam0 = program.env[10];" +
12478
+ "PARAM light2cam1 = program.env[11];" +
12479
+ "PARAM light2cam2 = program.env[12];" +
12480
+ "TEMP temp;" +
12481
+ "TEMP light;" +
12482
+ "TEMP ndotl;" +
12483
+ "TEMP normal;" +
12484
+ "TEMP depth;" +
12485
+ "TEMP eye;" +
12486
+ "TEMP pos;" +
12487
+
12488
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12489
+ Normalize("normal") +
12490
+ "MOV light, state.light[0].position;" +
12491
+ "DP3 ndotl.x, light, normal;" +
12492
+
12493
+ // shadow
12494
+ "MOV pos, fragment.texcoord[1];" +
12495
+ "MOV temp, pos;" +
12496
+ ShadowTextureFetch("depth", "temp", "1") +
12497
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12498
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12499
+
12500
+ // No shadow when out of frustum
12501
+ //"SGE temp.y, depth.z, zero123.y;" +
12502
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12503
+
12504
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12505
+
12506
+ // Backlit
12507
+ "MOV pos.w, zero123.y;" +
12508
+ "DP4 eye.x, pos, light2cam0;" +
12509
+ "DP4 eye.y, pos, light2cam1;" +
12510
+ "DP4 eye.z, pos, light2cam2;" +
12511
+ Normalize("eye") +
12512
+
12513
+ "DP3 ndotl.y, -eye, normal;" +
12514
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12515
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12516
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12517
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12518
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12519
+
12520
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12521
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12522
+
12523
+ // Pigment
12524
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12525
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12526
+ "MUL temp, temp, ndotl.x;" +
12527
+
12528
+ "MUL temp, temp, zero123.z;" +
12529
+
12530
+ //"MUL temp, temp, ndotl.y;" +
12531
+
12532
+ "MOV temp.w, zero123.y;" + // reset alpha
12533
+ "MOV result.color, temp;" +
12534
+ "END";
12535
+
12536
+ String programmax =
12537
+ "!!ARBfp1.0\n" +
12538
+
1232312539 //"OPTION ARB_fragment_program_shadow;" +
1232412540 "PARAM light2cam0 = program.env[10];" +
1232512541 "PARAM light2cam1 = program.env[11];" +
....@@ -12434,8 +12650,7 @@
1243412650 "TEMP shininess;" +
1243512651 "\n" +
1243612652 "MOV texSamp, one;" +
12437
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12438
-
12653
+
1243912654 "MOV mapgrid.x, one2048th.x;" +
1244012655 "MOV temp, fragment.texcoord[1];" +
1244112656 /*
....@@ -12456,20 +12671,20 @@
1245612671 "MUL temp, floor, mapgrid.x;" +
1245712672 //"TEX depth0, temp, texture[1], 2D;" +
1245812673 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12459
- TextureFetch("depth0", "temp", "1") +
12674
+ ShadowTextureFetch("depth0", "temp", "1") +
1246012675 "") +
1246112676 "ADD temp.x, temp.x, mapgrid.x;" +
1246212677 //"TEX depth1, temp, texture[1], 2D;" +
1246312678 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12464
- TextureFetch("depth1", "temp", "1") +
12679
+ ShadowTextureFetch("depth1", "temp", "1") +
1246512680 "") +
1246612681 "ADD temp.y, temp.y, mapgrid.x;" +
1246712682 //"TEX depth2, temp, texture[1], 2D;" +
12468
- TextureFetch("depth2", "temp", "1") +
12683
+ ShadowTextureFetch("depth2", "temp", "1") +
1246912684 "SUB temp.x, temp.x, mapgrid.x;" +
1247012685 //"TEX depth3, temp, texture[1], 2D;" +
1247112686 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12472
- TextureFetch("depth3", "temp", "1") +
12687
+ ShadowTextureFetch("depth3", "temp", "1") +
1247312688 "") +
1247412689 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1247512690 //"MOV params, material;" +
....@@ -12840,10 +13055,10 @@
1284013055 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1284113056 "") +
1284213057
12843
- // display shadow only (bump == 0)
13058
+ // display shadow only (fakedepth == 0)
1284413059 "SUB temp.x, half.x, shadow.x;" +
1284513060 "MOV temp.y, -params5.z;" + // params6.x;" +
12846
- "SLT temp.z, temp.y, -one2048th.x;" +
13061
+ "SLT temp.z, temp.y, -c256i.x;" +
1284713062 "SUB temp.y, one.x, temp.z;" +
1284813063 "MUL temp.x, temp.x, temp.y;" +
1284913064 "KIL temp.x;" +
....@@ -13174,6 +13389,13 @@
1317413389 //once = true;
1317513390 }
1317613391
13392
+ String program = programmax;
13393
+
13394
+ if (Globals.MINSHADER)
13395
+ {
13396
+ program = programmin;
13397
+ }
13398
+
1317713399 System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1317813400 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1317913401 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
....@@ -13267,25 +13489,26 @@
1326713489 return out;
1326813490 }
1326913491
13270
- String TextureFetch(String dest, String src, String unit)
13492
+ // Also does frustum culling
13493
+ String ShadowTextureFetch(String dest, String src, String unit)
1327113494 {
1327213495 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1327313496 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1327413497 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13498
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13499
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1327513500 "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;" +
13501
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13502
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1328013503 //"SWZ buffer, temp, w,w,w,w;";
13281
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13504
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1328213505 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1328313506 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1328413507 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13285
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13508
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1328613509
13287
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13288
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13510
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13511
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1328913512 }
1329013513
1329113514 String Shadow(String depth, String shadow)
....@@ -13332,7 +13555,7 @@
1333213555 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1333313556 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1333413557
13335
- // No shadow when out of frustrum
13558
+ // No shadow when out of frustum
1333613559 "SGE temp.x, " + depth + ".z, one.z;" +
1333713560 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1333813561 "";
....@@ -14065,7 +14288,7 @@
1406514288
1406614289 // fev 2014???
1406714290 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
14068
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14291
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1406914292 pingthread.StepToTarget(true); // true);
1407014293 }
1407114294 // if (!LIVE)
....@@ -14130,14 +14353,15 @@
1413014353 drag = false;
1413114354 //System.out.println("Mouse DOWN");
1413214355 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);
14356
+ //ClickInfo info = new ClickInfo();
14357
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14358
+ object.clickInfo.pane = this;
14359
+ object.clickInfo.camera = renderCamera;
14360
+ object.clickInfo.x = x;
14361
+ object.clickInfo.y = y;
14362
+ object.clickInfo.modifiers = modifiersex;
14363
+ editObj = object.doEditClick(//info,
14364
+ 0);
1414114365 if (!editObj)
1414214366 {
1414314367 hasMarquee = true;
....@@ -14419,12 +14643,12 @@
1441914643 void GoDown(int mod)
1442014644 {
1442114645 MODIFIERS |= COMMAND;
14422
- /*
14646
+ /**/
1442314647 if((mod&SHIFT) == SHIFT)
14424
- manipCamera.RotatePosition(0, -speed);
14648
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
1442514649 else
14426
- manipCamera.BackForth(0, -speed*delta, getWidth());
14427
- */
14650
+ manipCamera.RotatePosition(0, -speed);
14651
+ /**/
1442814652 if ((mod & SHIFT) == SHIFT)
1442914653 {
1443014654 mouseMode = mouseMode; // VR??
....@@ -14440,12 +14664,12 @@
1444014664 void GoUp(int mod)
1444114665 {
1444214666 MODIFIERS |= COMMAND;
14443
- /*
14667
+ /**/
1444414668 if((mod&SHIFT) == SHIFT)
14445
- manipCamera.RotatePosition(0, speed);
14669
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
1444614670 else
14447
- manipCamera.BackForth(0, speed*delta, getWidth());
14448
- */
14671
+ manipCamera.RotatePosition(0, speed);
14672
+ /**/
1444914673 if ((mod & SHIFT) == SHIFT)
1445014674 {
1445114675 mouseMode = mouseMode;
....@@ -14461,12 +14685,12 @@
1446114685 void GoLeft(int mod)
1446214686 {
1446314687 MODIFIERS |= COMMAND;
14464
- /*
14688
+ /**/
1446514689 if((mod&SHIFT) == SHIFT)
14466
- manipCamera.RotatePosition(speed, 0);
14467
- else
1446814690 manipCamera.Translate(speed*delta, 0, getWidth());
14469
- */
14691
+ else
14692
+ manipCamera.RotatePosition(speed, 0);
14693
+ /**/
1447014694 if ((mod & SHIFT) == SHIFT)
1447114695 {
1447214696 mouseMode = mouseMode;
....@@ -14482,12 +14706,12 @@
1448214706 void GoRight(int mod)
1448314707 {
1448414708 MODIFIERS |= COMMAND;
14485
- /*
14709
+ /**/
1448614710 if((mod&SHIFT) == SHIFT)
14487
- manipCamera.RotatePosition(-speed, 0);
14488
- else
1448914711 manipCamera.Translate(-speed*delta, 0, getWidth());
14490
- */
14712
+ else
14713
+ manipCamera.RotatePosition(-speed, 0);
14714
+ /**/
1449114715 if ((mod & SHIFT) == SHIFT)
1449214716 {
1449314717 mouseMode = mouseMode;
....@@ -14537,15 +14761,16 @@
1453714761 if (editObj)
1453814762 {
1453914763 drag = true;
14540
- ClickInfo info = new ClickInfo();
14541
- info.bounds.setBounds(0, 0,
14764
+ //ClickInfo info = new ClickInfo();
14765
+ object.clickInfo.bounds.setBounds(0, 0,
1454214766 (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);
14767
+ object.clickInfo.pane = this;
14768
+ object.clickInfo.camera = renderCamera;
14769
+ object.clickInfo.x = x;
14770
+ object.clickInfo.y = y;
14771
+ object //.GetWindow().copy
14772
+ .doEditDrag(//info,
14773
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1454914774 } else
1455014775 {
1455114776 if (x < startX)
....@@ -14694,24 +14919,27 @@
1469414919 }
1469514920 }
1469614921
14922
+// ClickInfo clickInfo = new ClickInfo();
14923
+
1469714924 public void mouseMoved(MouseEvent e)
1469814925 {
1469914926 //System.out.println("mouseMoved: " + e);
1470014927 if (isRenderer)
1470114928 return;
1470214929
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;
14930
+ // Mouse cursor feedback
14931
+ object.clickInfo.x = e.getX();
14932
+ object.clickInfo.y = e.getY();
14933
+ object.clickInfo.modifiers = e.getModifiersEx();
14934
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14935
+ object.clickInfo.pane = this;
14936
+ object.clickInfo.camera = renderCamera;
1471014937 if (!isRenderer)
1471114938 {
1471214939 //ObjEditor editWindow = object.editWindow;
1471314940 //Object3D copy = editWindow.copy;
14714
- if (object.doEditClick(ci, 0))
14941
+ if (object.doEditClick(//clickInfo,
14942
+ 0))
1471514943 {
1471614944 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1471714945 } else
....@@ -14726,7 +14954,8 @@
1472614954 Globals.MOUSEDRAGGED = false;
1472714955
1472814956 movingcamera = false;
14729
- X = Y = 0;
14957
+ X = 0; // getBounds().width/2;
14958
+ Y = 0; // getBounds().height/2;
1473014959 //System.out.println("mouseReleased: " + e);
1473114960 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1473214961 }
....@@ -14982,7 +15211,8 @@
1498215211 // break;
1498315212 case 'T':
1498415213 CACHETEXTURE ^= true;
14985
- textures.clear();
15214
+ texturepigment.clear();
15215
+ texturebump.clear();
1498615216 // repaint();
1498715217 break;
1498815218 case 'Y':
....@@ -15067,7 +15297,9 @@
1506715297 case 'E' : COMPACT ^= true;
1506815298 repaint();
1506915299 break;
15070
- case 'W' : DEBUGHSB ^= true;
15300
+ case 'W' : // Wide Window (fullscreen)
15301
+ //DEBUGHSB ^= true;
15302
+ ObjEditor.theFrame.ToggleFullScreen();
1507115303 repaint();
1507215304 break;
1507315305 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -15093,13 +15325,7 @@
1509315325 repaint();
1509415326 break;
1509515327 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':
15328
+ //case 'L':
1510315329 if (lightMode)
1510415330 {
1510515331 lightMode = false;
....@@ -15163,20 +15389,24 @@
1516315389 OCCLUSION_CULLING ^= true;
1516415390 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1516515391 break;
15166
- case '0': envyoff ^= true; repaint(); break;
15392
+ //case '0': envyoff ^= true; repaint(); break;
1516715393 case '1':
1516815394 case '2':
1516915395 case '3':
1517015396 case '4':
1517115397 case '5':
15172
- newenvy = Character.getNumericValue(key);
15173
- repaint();
15174
- break;
1517515398 case '6':
1517615399 case '7':
1517715400 case '8':
1517815401 case '9':
15179
- BGcolor = (key - '6')/3.f;
15402
+ if (true) // envyoff)
15403
+ {
15404
+ BGcolor = (key - '1')/8.f;
15405
+ }
15406
+ else
15407
+ {
15408
+ //newenvy = Character.getNumericValue(key);
15409
+ }
1518015410 repaint();
1518115411 break;
1518215412 case '!':
....@@ -15246,7 +15476,10 @@
1524615476 // kompactbit = 6;
1524715477 // break;
1524815478 case ' ':
15249
- ObjEditor.theFrame.ToggleFullScreen();
15479
+ lightMode ^= true;
15480
+ Globals.lighttouched = true;
15481
+ manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
15482
+ targetLookAt.set(manipCamera.lookAt);
1525015483 repaint();
1525115484 break;
1525215485 //case '`' :
....@@ -15295,12 +15528,6 @@
1529515528 break;
1529615529 case '+':
1529715530
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
-
1530415531 /*
1530515532 //fontsize += 1;
1530615533 bbzoom *= 2;
....@@ -15318,17 +15545,17 @@
1531815545 case '=':
1531915546 IncDepth();
1532015547 //fontsize += 1;
15321
- object.editWindow.refreshContents(true);
15548
+ object.GetWindow().refreshContents(true);
1532215549 maskbit = 6;
1532315550 break;
1532415551 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1532515552 DecDepth();
1532615553 maskbit = 5;
1532715554 //if(fontsize > 1) fontsize -= 1;
15328
- if (object.editWindow == null)
15329
- new Exception().printStackTrace();
15330
- else
15331
- object.editWindow.refreshContents(true);
15555
+// if (object.editWindow == null)
15556
+// new Exception().printStackTrace();
15557
+// else
15558
+ object.GetWindow().refreshContents(true);
1533215559 break;
1533315560 case '{':
1533415561 manipCamera.shaper_fovy /= 1.1;
....@@ -15552,7 +15779,7 @@
1555215779 }
1555315780 */
1555415781
15555
- object.editWindow.EditSelection(false);
15782
+ object.GetWindow().EditSelection(false);
1555615783 }
1555715784
1555815785 void SelectParent()
....@@ -15569,10 +15796,10 @@
1556915796 {
1557015797 //selectees.remove(i);
1557115798 System.out.println("select parent of " + elem);
15572
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15799
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1557315800 } else
1557415801 {
15575
- group.editWindow.Select(elem.GetTreePath(), first, true);
15802
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1557615803 }
1557715804
1557815805 first = false;
....@@ -15614,12 +15841,12 @@
1561415841 for (int j = 0; j < group.children.size(); j++)
1561515842 {
1561615843 elem = (Object3D) group.children.elementAt(j);
15617
- object.editWindow.Select(elem.GetTreePath(), first, true);
15844
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1561815845 first = false;
1561915846 }
1562015847 } else
1562115848 {
15622
- object.editWindow.Select(elem.GetTreePath(), first, true);
15849
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1562315850 }
1562415851
1562515852 first = false;
....@@ -15630,21 +15857,21 @@
1563015857 {
1563115858 //Composite group = (Composite) object;
1563215859 Object3D group = object;
15633
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15860
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1563415861 }
1563515862
1563615863 void ResetTransform(int mask)
1563715864 {
1563815865 //Composite group = (Composite) object;
1563915866 Object3D group = object;
15640
- group.editWindow.ResetTransform(mask);
15867
+ group.GetWindow().ResetTransform(mask);
1564115868 }
1564215869
1564315870 void FlipTransform()
1564415871 {
1564515872 //Composite group = (Composite) object;
1564615873 Object3D group = object;
15647
- group.editWindow.FlipTransform();
15874
+ group.GetWindow().FlipTransform();
1564815875 // group.editWindow.ReduceMesh(true);
1564915876 }
1565015877
....@@ -15652,7 +15879,7 @@
1565215879 {
1565315880 //Composite group = (Composite) object;
1565415881 Object3D group = object;
15655
- group.editWindow.PrintMemory();
15882
+ group.GetWindow().PrintMemory();
1565615883 // group.editWindow.ReduceMesh(true);
1565715884 }
1565815885
....@@ -15660,7 +15887,7 @@
1566015887 {
1566115888 //Composite group = (Composite) object;
1566215889 Object3D group = object;
15663
- group.editWindow.ResetCentroid();
15890
+ group.GetWindow().ResetCentroid();
1566415891 }
1566515892
1566615893 void IncDepth()
....@@ -15742,8 +15969,6 @@
1574215969
1574315970 int width = getBounds().width;
1574415971 int height = getBounds().height;
15745
- ClickInfo info = new ClickInfo();
15746
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1574715972 //Image img = CreateImage(width, height);
1574815973 //System.out.println("width = " + width + "; height = " + height + "\n");
1574915974
....@@ -15820,48 +16045,77 @@
1582016045 }
1582116046 if (object != null && !hasMarquee)
1582216047 {
16048
+ if (object.clickInfo == null)
16049
+ object.clickInfo = new ClickInfo();
16050
+ ClickInfo info = object.clickInfo;
16051
+ //ClickInfo info = new ClickInfo();
16052
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16053
+
1582316054 if (isRenderer)
1582416055 {
15825
- info.flags++;
16056
+ object.clickInfo.flags++;
1582616057 double frameAspect = (double) width / (double) height;
1582716058 if (frameAspect > renderCamera.aspect)
1582816059 {
1582916060 int desired = (int) ((double) height * renderCamera.aspect);
15830
- info.bounds.width -= width - desired;
15831
- info.bounds.x += (width - desired) / 2;
16061
+ object.clickInfo.bounds.width -= width - desired;
16062
+ object.clickInfo.bounds.x += (width - desired) / 2;
1583216063 } else
1583316064 {
1583416065 int desired = (int) ((double) width / renderCamera.aspect);
15835
- info.bounds.height -= height - desired;
15836
- info.bounds.y += (height - desired) / 2;
16066
+ object.clickInfo.bounds.height -= height - desired;
16067
+ object.clickInfo.bounds.y += (height - desired) / 2;
1583716068 }
1583816069 }
15839
- info.g = gr;
15840
- info.camera = renderCamera;
16070
+
16071
+ object.clickInfo.g = gr;
16072
+ object.clickInfo.camera = renderCamera;
1584116073 /*
1584216074 // Memory intensive (brep.verticescopy)
1584316075 if (!(object instanceof Composite))
1584416076 object.draw(info, 0, false); // SLOW :
1584516077 */
15846
- if (!isRenderer)
16078
+ if (!isRenderer) // && drag)
1584716079 {
15848
- object.drawEditHandles(info, 0);
15849
-
15850
- if (drag && (X != 0 || Y != 0) && object.selection.Size() > 0)
16080
+ Grafreed.Assert(object != null);
16081
+ Grafreed.Assert(object.selection != null);
16082
+ if (object.selection.Size() > 0)
1585116083 {
15852
- switch (object.selection.get(0).hitSomething)
16084
+ int hitSomething = object.selection.get(0).hitSomething;
16085
+
16086
+ object.clickInfo.DX = 0;
16087
+ object.clickInfo.DY = 0;
16088
+ object.clickInfo.W = 1;
16089
+ if (hitSomething == Object3D.hitCenter)
1585316090 {
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;
16091
+ info.DX = X;
16092
+ if (X != 0)
16093
+ info.DX -= info.bounds.width/2;
16094
+
16095
+ info.DY = Y;
16096
+ if (Y != 0)
16097
+ info.DY -= info.bounds.height/2;
1586316098 }
15864
-
16099
+
16100
+ object.drawEditHandles(//info,
16101
+ 0);
16102
+
16103
+ if (drag && (X != 0 || Y != 0))
16104
+ {
16105
+ switch (hitSomething)
16106
+ {
16107
+ case Object3D.hitCenter: gr.setColor(Color.pink);
16108
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16109
+ break;
16110
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16111
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16112
+ break;
16113
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16114
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16115
+ break;
16116
+ }
16117
+
16118
+ }
1586516119 }
1586616120 }
1586716121 }
....@@ -16343,6 +16597,8 @@
1634316597 private /*static*/ boolean firstime;
1634416598 private /*static*/ cVector newView = new cVector();
1634516599 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16600
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16601
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1634616602 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1634716603 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1634816604 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16355,29 +16611,67 @@
1635516611 {
1635616612 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1635716613
16614
+ int usedsuf = 0;
16615
+
1635816616 for (int i = 0; i < suffixes.length; i++)
1635916617 {
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)
16618
+ String[] suffixe = suffixes;
16619
+ String[] fallback = suffixes2;
16620
+ String[] fallfallback = suffixes3;
16621
+
16622
+ for (int c=usedsuf; --c>=0;)
1636516623 {
16366
- throw new IOException("Unable to load texture " + resourceName);
16624
+// String[] temp = suffixe;
16625
+// suffixe = fallback;
16626
+// fallback = fallfallback;
16627
+// fallfallback = temp;
1636716628 }
16629
+
16630
+ String resourceName = basename + suffixe[i] + "." + suffix;
16631
+ TextureData data;
16632
+
16633
+ try
16634
+ {
16635
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16636
+ mipmapped,
16637
+ FileUtil.getFileSuffix(resourceName));
16638
+ }
16639
+ catch (Exception e)
16640
+ {
16641
+ try
16642
+ {
16643
+ resourceName = basename + fallback[i] + "." + suffix;
16644
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16645
+ mipmapped,
16646
+ FileUtil.getFileSuffix(resourceName));
16647
+ }
16648
+ catch (Exception e2)
16649
+ {
16650
+ resourceName = basename + fallfallback[i] + "." + suffix;
16651
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16652
+ mipmapped,
16653
+ FileUtil.getFileSuffix(resourceName));
16654
+ }
16655
+ }
16656
+
1636816657 //System.out.println("Target = " + targets[i]);
1636916658 cubemap.updateImage(data, targets[i]);
1637016659 }
1637116660
1637216661 return cubemap;
1637316662 }
16663
+
1637416664 int bigsphere = -1;
1637516665
1637616666 float BGcolor = 0.5f;
1637716667
16378
- private void DrawSkyBox(GL gl)
16668
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16669
+
16670
+ private void DrawSkyBox(GL gl, float ratio)
1637916671 {
16380
- if (envyoff || cubemap == null)
16672
+ if (//envyoff ||
16673
+ WIREFRAME ||
16674
+ cubemap == null)
1638116675 {
1638216676 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1638316677 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16392,7 +16686,17 @@
1639216686 // Compensates for ExaminerViewer's modification of modelview matrix
1639316687 gl.glMatrixMode(GL.GL_MODELVIEW);
1639416688 gl.glLoadIdentity();
16689
+ gl.glScalef(1,ratio,1);
1639516690
16691
+// colorV[0] = 2;
16692
+// colorV[1] = 2;
16693
+// colorV[2] = 2;
16694
+// colorV[3] = 1;
16695
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16696
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16697
+//
16698
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16699
+
1639616700 //gl.glActiveTexture(GL.GL_TEXTURE1);
1639716701 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1639816702
....@@ -16424,6 +16728,7 @@
1642416728 {
1642516729 gl.glScalef(1.0f, -1.0f, 1.0f);
1642616730 }
16731
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1642716732 gl.glMultMatrixd(viewrot_1, 0);
1642816733 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1642916734 //viewer.updateInverseRotation(gl);
....@@ -16659,6 +16964,14 @@
1665916964 }
1666016965 }
1666116966
16967
+ private Object3D GetFolder()
16968
+ {
16969
+ Object3D folder = object.GetWindow().copy;
16970
+ if (object.GetWindow().copy.selection.Size() > 0)
16971
+ folder = object.GetWindow().copy.selection.elementAt(0);
16972
+ return folder;
16973
+ }
16974
+
1666216975 class SelectBuffer implements GLEventListener
1666316976 {
1666416977
....@@ -16674,7 +16987,7 @@
1667416987 //new Exception().printStackTrace();
1667516988 System.out.println("select buffer init");
1667616989 // Use debug pipeline
16677
- drawable.setGL(new DebugGL(drawable.getGL()));
16990
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1667816991
1667916992 GL gl = drawable.getGL();
1668016993
....@@ -16738,6 +17051,17 @@
1673817051
1673917052 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1674017053
17054
+ if (PAINTMODE)
17055
+ {
17056
+ if (object.GetWindow().copy.selection.Size() > 0)
17057
+ {
17058
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17059
+
17060
+ // Make what you paint not selectable.
17061
+ paintobj.ResetSelectable();
17062
+ }
17063
+ }
17064
+
1674117065 //int tmp = selection_view;
1674217066 //selection_view = -1;
1674317067 int temp = DrawMode();
....@@ -16749,6 +17073,17 @@
1674917073 // temp = DEFAULT; // patch for selection debug
1675017074 Globals.drawMode = temp; // WARNING
1675117075
17076
+ if (PAINTMODE)
17077
+ {
17078
+ if (object.GetWindow().copy.selection.Size() > 0)
17079
+ {
17080
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17081
+
17082
+ // Revert.
17083
+ paintobj.RestoreSelectable();
17084
+ }
17085
+ }
17086
+
1675217087 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1675317088
1675417089 // trying different ways of getting the depth info over
....@@ -16852,29 +17187,31 @@
1685217187 }
1685317188
1685417189 if (!movingcamera && !PAINTMODE)
16855
- object.editWindow.ScreenFitPoint(); // fev 2014
17190
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1685617191
16857
- if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17192
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1685817193 {
16859
- Object3D paintobj = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17194
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1686017195
16861
- Object3D group = new Object3D("inst" + paintcount++);
17196
+ if (object.GetWindow().copy.selection.Size() > 0)
17197
+ {
17198
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1686217199
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();
17200
+ Object3D inst = new Object3D("inst" + paintcount++);
17201
+
17202
+ inst.CreateMaterial(); // use a void leaf to select instances
17203
+
17204
+ inst.add(paintobj); // link
17205
+
17206
+ object.GetWindow().SnapObject(inst);
17207
+
17208
+ Object3D folder = paintFolder; // GetFolder();
17209
+
17210
+ folder.add(inst);
17211
+
17212
+ object.GetWindow().ResetModel();
17213
+ object.GetWindow().refreshContents();
17214
+ }
1687817215 }
1687917216 else
1688017217 paintcount = 0;