Normand Briere
2019-07-30 475f8cbdbd96fdbf8f5b216ffebb31a51f25c2f9
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))
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,13 @@
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();
84248442 } else
84258443 {
84268444 if (textureon)
....@@ -8479,19 +8497,19 @@
84798497 if (texturedata == null)
84808498 throw new Exception();
84818499
8482
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8500
+ texturecache = new CacheTexture(texturedata,resolution);
84838501 //texture = GetTexture(tex, bump);
84848502 }
84858503 }
84868504 //}
84878505 }
84888506
8489
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8507
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
84908508 {
84918509 //return false;
84928510
84938511 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8494
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8512
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
84958513 {
84968514 // String ext = "_highres";
84978515 // if (REDUCETEXTURE)
....@@ -8508,52 +8526,17 @@
85088526 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
85098527 if (!cachefile.exists())
85108528 {
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))
8529
+ //if (texturedata.getWidth() == texturedata.getHeight())
85208530 {
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);
8531
+ BufferedImage rendImage = CreateBim(texturedata);
8532
+
85518533 ImageWriter writer = null;
85528534 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
85538535 if (iter.hasNext()) {
85548536 writer = (ImageWriter)iter.next();
85558537 }
8556
- float compressionQuality = 0.9f;
8538
+
8539
+ float compressionQuality = 0.85f;
85578540 try
85588541 {
85598542 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8570,18 +8553,20 @@
85708553 }
85718554 }
85728555 }
8573
-
8556
+
8557
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8558
+
85748559 //System.out.println("Texture = " + tex);
8575
- if (textures.containsKey(texname))
8560
+ if (textures.containsKey(tex))
85768561 {
8577
- CacheTexture thetex = textures.get(texname);
8562
+ CacheTexture thetex = textures.get(tex);
85788563 thetex.texture.disable();
85798564 thetex.texture.dispose();
8580
- textures.remove(texname);
8565
+ textures.remove(tex);
85818566 }
85828567
8583
- texture.texturedata = texturedata;
8584
- textures.put(texname, texture);
8568
+ //texture.texturedata = texturedata;
8569
+ textures.put(tex, texturecache);
85858570
85868571 // newtex = true;
85878572 }
....@@ -8597,10 +8582,44 @@
85978582 }
85988583 }
85998584
8600
- return texture;
8585
+ return texturecache;
86018586 }
86028587
8603
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution) throws Exception
8588
+ static void EmbedTextures(cTexture tex)
8589
+ {
8590
+ if (tex.pigmentdata == null)
8591
+ {
8592
+ //String texname = Object3D.GetPigment(tex);
8593
+
8594
+ CacheTexture texturecache = texturepigment.get(tex);
8595
+
8596
+ if (texturecache != null)
8597
+ {
8598
+ tex.pw = texturecache.texturedata.getWidth();
8599
+ tex.ph = texturecache.texturedata.getHeight();
8600
+ tex.pigmentdata = //CompressJPEG(CreateBim
8601
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8602
+ ;
8603
+ //, tex.pw, tex.ph), 0.5f);
8604
+ }
8605
+ }
8606
+
8607
+ if (tex.bumpdata == null)
8608
+ {
8609
+ //String texname = Object3D.GetBump(tex);
8610
+
8611
+ CacheTexture texturecache = texturebump.get(tex);
8612
+
8613
+ if (texturecache != null)
8614
+ {
8615
+ tex.bw = texturecache.texturedata.getWidth();
8616
+ tex.bh = texturecache.texturedata.getHeight();
8617
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8618
+ }
8619
+ }
8620
+ }
8621
+
8622
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
86048623 {
86058624 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
86068625
....@@ -8618,21 +8637,21 @@
86188637 return texture!=null?texture.texture:null;
86198638 }
86208639
8621
- public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution) throws Exception
8640
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
86228641 {
86238642 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
86248643
86258644 return texture!=null?texture.texturedata:null;
86268645 }
86278646
8628
- boolean BindTexture(String tex, boolean bump, int resolution) throws Exception
8647
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
86298648 {
86308649 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
86318650 {
86328651 return false;
86338652 }
86348653
8635
- boolean newtex = false;
8654
+ //boolean newtex = false;
86368655
86378656 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
86388657
....@@ -8664,9 +8683,75 @@
86648683 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
86658684 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
86668685
8667
- return newtex;
8686
+ return true; // Warning: not used.
86688687 }
86698688
8689
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8690
+ {
8691
+ try
8692
+ {
8693
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8694
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8695
+ ImageWriter writer = writers.next();
8696
+
8697
+ ImageWriteParam param = writer.getDefaultWriteParam();
8698
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8699
+ param.setCompressionQuality(quality);
8700
+
8701
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8702
+ writer.setOutput(ios);
8703
+ writer.write(null, new IIOImage(image, null, null), param);
8704
+
8705
+ byte[] data = baos.toByteArray();
8706
+ writer.dispose();
8707
+ return data;
8708
+ }
8709
+ catch (Exception e)
8710
+ {
8711
+ e.printStackTrace();
8712
+ return null;
8713
+ }
8714
+ }
8715
+
8716
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8717
+ {
8718
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8719
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8720
+ ImageReader reader = writers.next();
8721
+
8722
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8723
+
8724
+ ImageReadParam param = reader.getDefaultReadParam();
8725
+ param.setDestination(bim);
8726
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8727
+
8728
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8729
+ reader.setInput(ios);
8730
+ BufferedImage bim2 = reader.read(0, param);
8731
+ reader.dispose();
8732
+
8733
+// WritableRaster raster = bim2.getRaster();
8734
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8735
+// byte[] bytes = data.getData();
8736
+//
8737
+// int[] pixels = new int[bytes.length/3];
8738
+// for (int i=pixels.length; --i>=0;)
8739
+// {
8740
+// int i3 = i*3;
8741
+// pixels[i] = 0xFF;
8742
+// pixels[i] <<= 8;
8743
+// pixels[i] |= bytes[i3+2] & 0xFF;
8744
+// pixels[i] <<= 8;
8745
+// pixels[i] |= bytes[i3+1] & 0xFF;
8746
+// pixels[i] <<= 8;
8747
+// pixels[i] |= bytes[i3] & 0xFF;
8748
+// }
8749
+//
8750
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8751
+
8752
+ return bim;
8753
+ }
8754
+
86708755 ShadowBuffer shadowPBuf;
86718756 AntialiasBuffer antialiasPBuf;
86728757 int MAXSTACK;
....@@ -8859,7 +8944,7 @@
88598944
88608945 if (cubemap == null)
88618946 {
8862
- LoadEnvy(5);
8947
+ //LoadEnvy(1);
88638948 }
88648949
88658950 //cubemap.enable();
....@@ -9146,37 +9231,58 @@
91469231 cubemap = null;
91479232 return;
91489233 case 1:
9149
- name = "cubemaps/box_";
9150
- ext = "png";
9234
+ name = "cubemaps/rgb/";
9235
+ ext = "jpg";
91519236 reverseUP = false;
91529237 break;
91539238 case 2:
9154
- name = "cubemaps/uffizi_";
9155
- ext = "png";
9156
- break; // reverseUP = true; break;
9239
+ name = "cubemaps/uffizi/";
9240
+ ext = "jpg";
9241
+ reverseUP = false;
9242
+ break;
91579243 case 3:
9158
- name = "cubemaps/CloudyHills_";
9159
- ext = "tga";
9244
+ name = "cubemaps/CloudyHills/";
9245
+ ext = "jpg";
91609246 reverseUP = false;
91619247 break;
91629248 case 4:
9163
- name = "cubemaps/cornell_";
9249
+ name = "cubemaps/cornell/";
91649250 ext = "png";
91659251 reverseUP = false;
91669252 break;
9253
+ case 5:
9254
+ name = "cubemaps/skycube/";
9255
+ ext = "jpg";
9256
+ reverseUP = false;
9257
+ break;
9258
+ case 6:
9259
+ name = "cubemaps/SaintLazarusChurch3/";
9260
+ ext = "jpg";
9261
+ reverseUP = false;
9262
+ break;
9263
+ case 7:
9264
+ name = "cubemaps/Sodermalmsallen/";
9265
+ ext = "jpg";
9266
+ reverseUP = false;
9267
+ break;
9268
+ case 8:
9269
+ name = "cubemaps/Sodermalmsallen2/";
9270
+ ext = "jpg";
9271
+ reverseUP = false;
9272
+ break;
9273
+ case 9:
9274
+ name = "cubemaps/UnionSquare/";
9275
+ ext = "jpg";
9276
+ reverseUP = false;
9277
+ break;
91679278 default:
9168
- name = "cubemaps/rgb_";
9169
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9279
+ name = "cubemaps/box/";
9280
+ ext = "png"; /*mipmap = true;*/
9281
+ reverseUP = false;
91709282 break;
91719283 }
9172
-
9173
- try
9174
- {
9175
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
9176
- } catch (IOException e)
9177
- {
9178
- throw new RuntimeException(e);
9179
- }
9284
+
9285
+ LoadSkybox(name, ext, mipmap);
91809286 }
91819287
91829288 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -9208,8 +9314,12 @@
92089314 static double[] model = new double[16];
92099315 double[] camera2light = new double[16];
92109316 double[] light2camera = new double[16];
9211
- int newenvy = -1;
9212
- boolean envyoff = true; // false;
9317
+
9318
+ //int newenvy = -1;
9319
+ //boolean envyoff = false;
9320
+
9321
+ String loadedskyboxname;
9322
+
92139323 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
92149324 //float[] light0 = { 0,0,0 };
92159325 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9627,7 +9737,7 @@
96279737
96289738 if (renderCamera != lightCamera)
96299739 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9630
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
9740
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
96319741
96329742 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
96339743
....@@ -9643,7 +9753,7 @@
96439753
96449754 if (renderCamera != lightCamera)
96459755 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9646
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
9756
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
96479757
96489758 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
96499759
....@@ -9689,10 +9799,12 @@
96899799 rati = 1 / rati;
96909800 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
96919801 }
9692
- assert (newenvy == -1);
9802
+
9803
+ //assert (newenvy == -1);
9804
+
96939805 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
96949806 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9695
- DrawSkyBox(gl);
9807
+ DrawSkyBox(gl, (float)rati);
96969808 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
96979809 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
96989810 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10844,7 +10956,7 @@
1084410956 // if (parentcam != renderCamera) // not a light
1084510957 if (cam != lightCamera)
1084610958 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10847
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
10959
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1084810960
1084910961 for (int j = 0; j < 4; j++)
1085010962 {
....@@ -10859,7 +10971,7 @@
1085910971 // if (parentcam != renderCamera) // not a light
1086010972 if (cam != lightCamera)
1086110973 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10862
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
10974
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1086310975
1086410976 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1086510977
....@@ -10945,13 +11057,27 @@
1094511057 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1094611058 }
1094711059
10948
- if (newenvy > -1)
11060
+// if (newenvy > -1)
11061
+// {
11062
+// LoadEnvy(newenvy);
11063
+// }
11064
+//
11065
+// newenvy = -1;
11066
+
11067
+ if (object.skyboxname != null)
1094911068 {
10950
- LoadEnvy(newenvy);
11069
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11070
+ {
11071
+ LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11072
+ loadedskyboxname = object.skyboxname;
11073
+ }
1095111074 }
10952
-
10953
- newenvy = -1;
10954
-
11075
+ else
11076
+ {
11077
+ cubemap = null;
11078
+ loadedskyboxname = null;
11079
+ }
11080
+
1095511081 ratio = ((double) getWidth()) / getHeight();
1095611082 //System.out.println("ratio = " + ratio);
1095711083
....@@ -10967,7 +11093,7 @@
1096711093
1096811094 if (!IsFrozen() && !ambientOcclusion)
1096911095 {
10970
- DrawSkyBox(gl);
11096
+ DrawSkyBox(gl, (float)ratio);
1097111097 }
1097211098
1097311099 //if (selection_view == -1)
....@@ -11150,9 +11276,9 @@
1115011276
1115111277 gl.glMatrixMode(GL.GL_MODELVIEW);
1115211278
11153
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11154
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
11155
-//gl.glEnable(gl.GL_MULTISAMPLE);
11279
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11280
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11281
+gl.glEnable(gl.GL_MULTISAMPLE);
1115611282 } else
1115711283 {
1115811284 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -11163,7 +11289,7 @@
1116311289 //System.out.println("BLENDING ON");
1116411290 gl.glEnable(GL.GL_BLEND);
1116511291 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
11166
-
11292
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1116711293 gl.glMatrixMode(gl.GL_PROJECTION);
1116811294 gl.glLoadIdentity();
1116911295
....@@ -11412,7 +11538,7 @@
1141211538 }
1141311539 }
1141411540
11415
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11541
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1141611542 {
1141711543 //gl.glDepthFunc(GL.GL_LEQUAL);
1141811544 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11420,24 +11546,21 @@
1142011546
1142111547 boolean texon = textureon;
1142211548
11423
- if (RENDERPROGRAM > 0)
11424
- {
11425
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11426
- textureon = false;
11427
- }
11549
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11550
+ textureon = false;
11551
+
1142811552 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1142911553 //System.out.println("ALLO");
1143011554 gl.glColorMask(false, false, false, false);
1143111555 DrawObject(gl);
11432
- if (RENDERPROGRAM > 0)
11433
- {
11434
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11435
- textureon = texon;
11436
- }
11556
+
11557
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11558
+ textureon = texon;
11559
+
1143711560 gl.glColorMask(true, true, true, true);
1143811561
1143911562 gl.glDepthFunc(GL.GL_EQUAL);
11440
- //gl.glDepthMask(false);
11563
+ gl.glDepthMask(false);
1144111564 }
1144211565
1144311566 if (false) // DrawMode() == SHADOW)
....@@ -11649,7 +11772,7 @@
1164911772 if ((TRACK || SHADOWTRACK) || zoomonce)
1165011773 {
1165111774 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11652
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11775
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1165311776 pingthread.StepToTarget(true); // true);
1165411777 // zoomonce = false;
1165511778 }
....@@ -11777,20 +11900,32 @@
1177711900 ReleaseTextures(DEFAULT_TEXTURES);
1177811901
1177911902 if (CLEANCACHE)
11780
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11903
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1178111904 {
11782
- String tex = e.nextElement();
11905
+ cTexture tex = e.nextElement();
1178311906
1178411907 // System.out.println("Texture --------- " + tex);
1178511908
11786
- if (tex.equals("WHITE_NOISE"))
11909
+ if (tex.equals("WHITE_NOISE:"))
1178711910 continue;
1178811911
11789
- if (!usedtextures.containsKey(tex))
11912
+ if (!usedtextures.contains(tex))
1179011913 {
11914
+ CacheTexture gettex = texturepigment.get(tex);
1179111915 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11792
- textures.get(tex).texture.dispose();
11793
- textures.remove(tex);
11916
+ if (gettex != null)
11917
+ {
11918
+ gettex.texture.dispose();
11919
+ texturepigment.remove(tex);
11920
+ }
11921
+
11922
+ gettex = texturebump.get(tex);
11923
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11924
+ if (gettex != null)
11925
+ {
11926
+ gettex.texture.dispose();
11927
+ texturebump.remove(tex);
11928
+ }
1179411929 }
1179511930 }
1179611931 }
....@@ -12318,8 +12453,76 @@
1231812453
1231912454 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1232012455
12456
+ String program0 =
12457
+ // Min shader
12458
+ "!!ARBfp1.0\n" +
12459
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12460
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12461
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12462
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12463
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12464
+ "PARAM light2cam0 = program.env[10];" +
12465
+ "PARAM light2cam1 = program.env[11];" +
12466
+ "PARAM light2cam2 = program.env[12];" +
12467
+ "TEMP temp;" +
12468
+ "TEMP light;" +
12469
+ "TEMP ndotl;" +
12470
+ "TEMP normal;" +
12471
+ "TEMP depth;" +
12472
+ "TEMP eye;" +
12473
+ "TEMP pos;" +
12474
+
12475
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12476
+ Normalize("normal") +
12477
+ "MOV light, state.light[0].position;" +
12478
+ "DP3 ndotl.x, light, normal;" +
12479
+
12480
+ // shadow
12481
+ "MOV pos, fragment.texcoord[1];" +
12482
+ "MOV temp, pos;" +
12483
+ ShadowTextureFetch("depth", "temp", "1") +
12484
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12485
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12486
+
12487
+ // No shadow when out of frustum
12488
+ //"SGE temp.y, depth.z, zero123.y;" +
12489
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12490
+
12491
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12492
+
12493
+ // Backlit
12494
+ "MOV pos.w, zero123.y;" +
12495
+ "DP4 eye.x, pos, light2cam0;" +
12496
+ "DP4 eye.y, pos, light2cam1;" +
12497
+ "DP4 eye.z, pos, light2cam2;" +
12498
+ Normalize("eye") +
12499
+
12500
+ "DP3 ndotl.y, -eye, normal;" +
12501
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12502
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12503
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12504
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12505
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12506
+
12507
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12508
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12509
+
12510
+ // Pigment
12511
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12512
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12513
+ "MUL temp, temp, ndotl.x;" +
12514
+
12515
+ "MUL temp, temp, zero123.z;" +
12516
+
12517
+ //"MUL temp, temp, ndotl.y;" +
12518
+
12519
+ "MOV temp.w, zero123.y;" + // reset alpha
12520
+ "MOV result.color, temp;" +
12521
+ "END";
12522
+
1232112523 String program =
1232212524 "!!ARBfp1.0\n" +
12525
+
1232312526 //"OPTION ARB_fragment_program_shadow;" +
1232412527 "PARAM light2cam0 = program.env[10];" +
1232512528 "PARAM light2cam1 = program.env[11];" +
....@@ -12434,8 +12637,7 @@
1243412637 "TEMP shininess;" +
1243512638 "\n" +
1243612639 "MOV texSamp, one;" +
12437
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12438
-
12640
+
1243912641 "MOV mapgrid.x, one2048th.x;" +
1244012642 "MOV temp, fragment.texcoord[1];" +
1244112643 /*
....@@ -12456,20 +12658,20 @@
1245612658 "MUL temp, floor, mapgrid.x;" +
1245712659 //"TEX depth0, temp, texture[1], 2D;" +
1245812660 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12459
- TextureFetch("depth0", "temp", "1") +
12661
+ ShadowTextureFetch("depth0", "temp", "1") +
1246012662 "") +
1246112663 "ADD temp.x, temp.x, mapgrid.x;" +
1246212664 //"TEX depth1, temp, texture[1], 2D;" +
1246312665 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12464
- TextureFetch("depth1", "temp", "1") +
12666
+ ShadowTextureFetch("depth1", "temp", "1") +
1246512667 "") +
1246612668 "ADD temp.y, temp.y, mapgrid.x;" +
1246712669 //"TEX depth2, temp, texture[1], 2D;" +
12468
- TextureFetch("depth2", "temp", "1") +
12670
+ ShadowTextureFetch("depth2", "temp", "1") +
1246912671 "SUB temp.x, temp.x, mapgrid.x;" +
1247012672 //"TEX depth3, temp, texture[1], 2D;" +
1247112673 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12472
- TextureFetch("depth3", "temp", "1") +
12674
+ ShadowTextureFetch("depth3", "temp", "1") +
1247312675 "") +
1247412676 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1247512677 //"MOV params, material;" +
....@@ -12840,10 +13042,10 @@
1284013042 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1284113043 "") +
1284213044
12843
- // display shadow only (bump == 0)
13045
+ // display shadow only (fakedepth == 0)
1284413046 "SUB temp.x, half.x, shadow.x;" +
1284513047 "MOV temp.y, -params5.z;" + // params6.x;" +
12846
- "SLT temp.z, temp.y, -one2048th.x;" +
13048
+ "SLT temp.z, temp.y, -c256i.x;" +
1284713049 "SUB temp.y, one.x, temp.z;" +
1284813050 "MUL temp.x, temp.x, temp.y;" +
1284913051 "KIL temp.x;" +
....@@ -13267,25 +13469,26 @@
1326713469 return out;
1326813470 }
1326913471
13270
- String TextureFetch(String dest, String src, String unit)
13472
+ // Also does frustum culling
13473
+ String ShadowTextureFetch(String dest, String src, String unit)
1327113474 {
1327213475 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1327313476 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1327413477 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13478
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13479
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1327513480 "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;" +
13481
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13482
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1328013483 //"SWZ buffer, temp, w,w,w,w;";
13281
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13484
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1328213485 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1328313486 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1328413487 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13285
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13488
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1328613489
13287
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13288
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13490
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13491
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1328913492 }
1329013493
1329113494 String Shadow(String depth, String shadow)
....@@ -13332,7 +13535,7 @@
1333213535 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1333313536 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1333413537
13335
- // No shadow when out of frustrum
13538
+ // No shadow when out of frustum
1333613539 "SGE temp.x, " + depth + ".z, one.z;" +
1333713540 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1333813541 "";
....@@ -14065,7 +14268,7 @@
1406514268
1406614269 // fev 2014???
1406714270 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
14068
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14271
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1406914272 pingthread.StepToTarget(true); // true);
1407014273 }
1407114274 // if (!LIVE)
....@@ -14130,14 +14333,15 @@
1413014333 drag = false;
1413114334 //System.out.println("Mouse DOWN");
1413214335 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);
14336
+ //ClickInfo info = new ClickInfo();
14337
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14338
+ object.clickInfo.pane = this;
14339
+ object.clickInfo.camera = renderCamera;
14340
+ object.clickInfo.x = x;
14341
+ object.clickInfo.y = y;
14342
+ object.clickInfo.modifiers = modifiersex;
14343
+ editObj = object.doEditClick(//info,
14344
+ 0);
1414114345 if (!editObj)
1414214346 {
1414314347 hasMarquee = true;
....@@ -14419,12 +14623,12 @@
1441914623 void GoDown(int mod)
1442014624 {
1442114625 MODIFIERS |= COMMAND;
14422
- /*
14626
+ /**/
1442314627 if((mod&SHIFT) == SHIFT)
1442414628 manipCamera.RotatePosition(0, -speed);
1442514629 else
14426
- manipCamera.BackForth(0, -speed*delta, getWidth());
14427
- */
14630
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14631
+ /**/
1442814632 if ((mod & SHIFT) == SHIFT)
1442914633 {
1443014634 mouseMode = mouseMode; // VR??
....@@ -14440,12 +14644,12 @@
1444014644 void GoUp(int mod)
1444114645 {
1444214646 MODIFIERS |= COMMAND;
14443
- /*
14647
+ /**/
1444414648 if((mod&SHIFT) == SHIFT)
1444514649 manipCamera.RotatePosition(0, speed);
1444614650 else
14447
- manipCamera.BackForth(0, speed*delta, getWidth());
14448
- */
14651
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14652
+ /**/
1444914653 if ((mod & SHIFT) == SHIFT)
1445014654 {
1445114655 mouseMode = mouseMode;
....@@ -14461,12 +14665,12 @@
1446114665 void GoLeft(int mod)
1446214666 {
1446314667 MODIFIERS |= COMMAND;
14464
- /*
14668
+ /**/
1446514669 if((mod&SHIFT) == SHIFT)
14466
- manipCamera.RotatePosition(speed, 0);
14467
- else
1446814670 manipCamera.Translate(speed*delta, 0, getWidth());
14469
- */
14671
+ else
14672
+ manipCamera.RotatePosition(speed, 0);
14673
+ /**/
1447014674 if ((mod & SHIFT) == SHIFT)
1447114675 {
1447214676 mouseMode = mouseMode;
....@@ -14482,12 +14686,12 @@
1448214686 void GoRight(int mod)
1448314687 {
1448414688 MODIFIERS |= COMMAND;
14485
- /*
14689
+ /**/
1448614690 if((mod&SHIFT) == SHIFT)
14487
- manipCamera.RotatePosition(-speed, 0);
14488
- else
1448914691 manipCamera.Translate(-speed*delta, 0, getWidth());
14490
- */
14692
+ else
14693
+ manipCamera.RotatePosition(-speed, 0);
14694
+ /**/
1449114695 if ((mod & SHIFT) == SHIFT)
1449214696 {
1449314697 mouseMode = mouseMode;
....@@ -14537,15 +14741,16 @@
1453714741 if (editObj)
1453814742 {
1453914743 drag = true;
14540
- ClickInfo info = new ClickInfo();
14541
- info.bounds.setBounds(0, 0,
14744
+ //ClickInfo info = new ClickInfo();
14745
+ object.clickInfo.bounds.setBounds(0, 0,
1454214746 (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);
14747
+ object.clickInfo.pane = this;
14748
+ object.clickInfo.camera = renderCamera;
14749
+ object.clickInfo.x = x;
14750
+ object.clickInfo.y = y;
14751
+ object //.GetWindow().copy
14752
+ .doEditDrag(//info,
14753
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1454914754 } else
1455014755 {
1455114756 if (x < startX)
....@@ -14694,24 +14899,27 @@
1469414899 }
1469514900 }
1469614901
14902
+// ClickInfo clickInfo = new ClickInfo();
14903
+
1469714904 public void mouseMoved(MouseEvent e)
1469814905 {
1469914906 //System.out.println("mouseMoved: " + e);
1470014907 if (isRenderer)
1470114908 return;
1470214909
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;
14910
+ // Mouse cursor feedback
14911
+ object.clickInfo.x = e.getX();
14912
+ object.clickInfo.y = e.getY();
14913
+ object.clickInfo.modifiers = e.getModifiersEx();
14914
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14915
+ object.clickInfo.pane = this;
14916
+ object.clickInfo.camera = renderCamera;
1471014917 if (!isRenderer)
1471114918 {
1471214919 //ObjEditor editWindow = object.editWindow;
1471314920 //Object3D copy = editWindow.copy;
14714
- if (object.doEditClick(ci, 0))
14921
+ if (object.doEditClick(//clickInfo,
14922
+ 0))
1471514923 {
1471614924 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1471714925 } else
....@@ -14726,7 +14934,8 @@
1472614934 Globals.MOUSEDRAGGED = false;
1472714935
1472814936 movingcamera = false;
14729
- X = Y = 0;
14937
+ X = 0; // getBounds().width/2;
14938
+ Y = 0; // getBounds().height/2;
1473014939 //System.out.println("mouseReleased: " + e);
1473114940 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1473214941 }
....@@ -14982,7 +15191,8 @@
1498215191 // break;
1498315192 case 'T':
1498415193 CACHETEXTURE ^= true;
14985
- textures.clear();
15194
+ texturepigment.clear();
15195
+ texturebump.clear();
1498615196 // repaint();
1498715197 break;
1498815198 case 'Y':
....@@ -15067,7 +15277,9 @@
1506715277 case 'E' : COMPACT ^= true;
1506815278 repaint();
1506915279 break;
15070
- case 'W' : DEBUGHSB ^= true;
15280
+ case 'W' : // Wide Window (fullscreen)
15281
+ //DEBUGHSB ^= true;
15282
+ ObjEditor.theFrame.ToggleFullScreen();
1507115283 repaint();
1507215284 break;
1507315285 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -15093,13 +15305,7 @@
1509315305 repaint();
1509415306 break;
1509515307 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':
15308
+ //case 'L':
1510315309 if (lightMode)
1510415310 {
1510515311 lightMode = false;
....@@ -15163,20 +15369,24 @@
1516315369 OCCLUSION_CULLING ^= true;
1516415370 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1516515371 break;
15166
- case '0': envyoff ^= true; repaint(); break;
15372
+ //case '0': envyoff ^= true; repaint(); break;
1516715373 case '1':
1516815374 case '2':
1516915375 case '3':
1517015376 case '4':
1517115377 case '5':
15172
- newenvy = Character.getNumericValue(key);
15173
- repaint();
15174
- break;
1517515378 case '6':
1517615379 case '7':
1517715380 case '8':
1517815381 case '9':
15179
- BGcolor = (key - '6')/3.f;
15382
+ if (true) // envyoff)
15383
+ {
15384
+ BGcolor = (key - '1')/8.f;
15385
+ }
15386
+ else
15387
+ {
15388
+ //newenvy = Character.getNumericValue(key);
15389
+ }
1518015390 repaint();
1518115391 break;
1518215392 case '!':
....@@ -15246,7 +15456,10 @@
1524615456 // kompactbit = 6;
1524715457 // break;
1524815458 case ' ':
15249
- ObjEditor.theFrame.ToggleFullScreen();
15459
+ lightMode ^= true;
15460
+ Globals.lighttouched = true;
15461
+ manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
15462
+ targetLookAt.set(manipCamera.lookAt);
1525015463 repaint();
1525115464 break;
1525215465 //case '`' :
....@@ -15295,12 +15508,6 @@
1529515508 break;
1529615509 case '+':
1529715510
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
-
1530415511 /*
1530515512 //fontsize += 1;
1530615513 bbzoom *= 2;
....@@ -15318,17 +15525,17 @@
1531815525 case '=':
1531915526 IncDepth();
1532015527 //fontsize += 1;
15321
- object.editWindow.refreshContents(true);
15528
+ object.GetWindow().refreshContents(true);
1532215529 maskbit = 6;
1532315530 break;
1532415531 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1532515532 DecDepth();
1532615533 maskbit = 5;
1532715534 //if(fontsize > 1) fontsize -= 1;
15328
- if (object.editWindow == null)
15329
- new Exception().printStackTrace();
15330
- else
15331
- object.editWindow.refreshContents(true);
15535
+// if (object.editWindow == null)
15536
+// new Exception().printStackTrace();
15537
+// else
15538
+ object.GetWindow().refreshContents(true);
1533215539 break;
1533315540 case '{':
1533415541 manipCamera.shaper_fovy /= 1.1;
....@@ -15552,7 +15759,7 @@
1555215759 }
1555315760 */
1555415761
15555
- object.editWindow.EditSelection(false);
15762
+ object.GetWindow().EditSelection(false);
1555615763 }
1555715764
1555815765 void SelectParent()
....@@ -15569,10 +15776,10 @@
1556915776 {
1557015777 //selectees.remove(i);
1557115778 System.out.println("select parent of " + elem);
15572
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15779
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1557315780 } else
1557415781 {
15575
- group.editWindow.Select(elem.GetTreePath(), first, true);
15782
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1557615783 }
1557715784
1557815785 first = false;
....@@ -15614,12 +15821,12 @@
1561415821 for (int j = 0; j < group.children.size(); j++)
1561515822 {
1561615823 elem = (Object3D) group.children.elementAt(j);
15617
- object.editWindow.Select(elem.GetTreePath(), first, true);
15824
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1561815825 first = false;
1561915826 }
1562015827 } else
1562115828 {
15622
- object.editWindow.Select(elem.GetTreePath(), first, true);
15829
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1562315830 }
1562415831
1562515832 first = false;
....@@ -15630,21 +15837,21 @@
1563015837 {
1563115838 //Composite group = (Composite) object;
1563215839 Object3D group = object;
15633
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15840
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1563415841 }
1563515842
1563615843 void ResetTransform(int mask)
1563715844 {
1563815845 //Composite group = (Composite) object;
1563915846 Object3D group = object;
15640
- group.editWindow.ResetTransform(mask);
15847
+ group.GetWindow().ResetTransform(mask);
1564115848 }
1564215849
1564315850 void FlipTransform()
1564415851 {
1564515852 //Composite group = (Composite) object;
1564615853 Object3D group = object;
15647
- group.editWindow.FlipTransform();
15854
+ group.GetWindow().FlipTransform();
1564815855 // group.editWindow.ReduceMesh(true);
1564915856 }
1565015857
....@@ -15652,7 +15859,7 @@
1565215859 {
1565315860 //Composite group = (Composite) object;
1565415861 Object3D group = object;
15655
- group.editWindow.PrintMemory();
15862
+ group.GetWindow().PrintMemory();
1565615863 // group.editWindow.ReduceMesh(true);
1565715864 }
1565815865
....@@ -15660,7 +15867,7 @@
1566015867 {
1566115868 //Composite group = (Composite) object;
1566215869 Object3D group = object;
15663
- group.editWindow.ResetCentroid();
15870
+ group.GetWindow().ResetCentroid();
1566415871 }
1566515872
1566615873 void IncDepth()
....@@ -15742,8 +15949,6 @@
1574215949
1574315950 int width = getBounds().width;
1574415951 int height = getBounds().height;
15745
- ClickInfo info = new ClickInfo();
15746
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1574715952 //Image img = CreateImage(width, height);
1574815953 //System.out.println("width = " + width + "; height = " + height + "\n");
1574915954
....@@ -15820,48 +16025,77 @@
1582016025 }
1582116026 if (object != null && !hasMarquee)
1582216027 {
16028
+ if (object.clickInfo == null)
16029
+ object.clickInfo = new ClickInfo();
16030
+ ClickInfo info = object.clickInfo;
16031
+ //ClickInfo info = new ClickInfo();
16032
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16033
+
1582316034 if (isRenderer)
1582416035 {
15825
- info.flags++;
16036
+ object.clickInfo.flags++;
1582616037 double frameAspect = (double) width / (double) height;
1582716038 if (frameAspect > renderCamera.aspect)
1582816039 {
1582916040 int desired = (int) ((double) height * renderCamera.aspect);
15830
- info.bounds.width -= width - desired;
15831
- info.bounds.x += (width - desired) / 2;
16041
+ object.clickInfo.bounds.width -= width - desired;
16042
+ object.clickInfo.bounds.x += (width - desired) / 2;
1583216043 } else
1583316044 {
1583416045 int desired = (int) ((double) width / renderCamera.aspect);
15835
- info.bounds.height -= height - desired;
15836
- info.bounds.y += (height - desired) / 2;
16046
+ object.clickInfo.bounds.height -= height - desired;
16047
+ object.clickInfo.bounds.y += (height - desired) / 2;
1583716048 }
1583816049 }
15839
- info.g = gr;
15840
- info.camera = renderCamera;
16050
+
16051
+ object.clickInfo.g = gr;
16052
+ object.clickInfo.camera = renderCamera;
1584116053 /*
1584216054 // Memory intensive (brep.verticescopy)
1584316055 if (!(object instanceof Composite))
1584416056 object.draw(info, 0, false); // SLOW :
1584516057 */
15846
- if (!isRenderer)
16058
+ if (!isRenderer) // && drag)
1584716059 {
15848
- object.drawEditHandles(info, 0);
15849
-
15850
- if (drag && (X != 0 || Y != 0) && object.selection.Size() > 0)
16060
+ Grafreed.Assert(object != null);
16061
+ Grafreed.Assert(object.selection != null);
16062
+ if (object.selection.Size() > 0)
1585116063 {
15852
- switch (object.selection.get(0).hitSomething)
16064
+ int hitSomething = object.selection.get(0).hitSomething;
16065
+
16066
+ object.clickInfo.DX = 0;
16067
+ object.clickInfo.DY = 0;
16068
+ object.clickInfo.W = 1;
16069
+ if (hitSomething == Object3D.hitCenter)
1585316070 {
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;
16071
+ info.DX = X;
16072
+ if (X != 0)
16073
+ info.DX -= info.bounds.width/2;
16074
+
16075
+ info.DY = Y;
16076
+ if (Y != 0)
16077
+ info.DY -= info.bounds.height/2;
1586316078 }
15864
-
16079
+
16080
+ object.drawEditHandles(//info,
16081
+ 0);
16082
+
16083
+ if (drag && (X != 0 || Y != 0))
16084
+ {
16085
+ switch (hitSomething)
16086
+ {
16087
+ case Object3D.hitCenter: gr.setColor(Color.pink);
16088
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16089
+ break;
16090
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16091
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16092
+ break;
16093
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16094
+ gr.drawLine(X, Y, 0, 0);
16095
+ break;
16096
+ }
16097
+
16098
+ }
1586516099 }
1586616100 }
1586716101 }
....@@ -16343,6 +16577,8 @@
1634316577 private /*static*/ boolean firstime;
1634416578 private /*static*/ cVector newView = new cVector();
1634516579 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16580
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16581
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1634616582 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1634716583 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1634816584 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16355,29 +16591,66 @@
1635516591 {
1635616592 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1635716593
16594
+ int usedsuf = 0;
16595
+
1635816596 for (int i = 0; i < suffixes.length; i++)
1635916597 {
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)
16598
+ String[] suffixe = suffixes;
16599
+ String[] fallback = suffixes2;
16600
+ String[] fallfallback = suffixes3;
16601
+
16602
+ for (int c=usedsuf; --c>=0;)
1636516603 {
16366
- throw new IOException("Unable to load texture " + resourceName);
16604
+// String[] temp = suffixe;
16605
+// suffixe = fallback;
16606
+// fallback = fallfallback;
16607
+// fallfallback = temp;
1636716608 }
16609
+
16610
+ String resourceName = basename + suffixe[i] + "." + suffix;
16611
+ TextureData data;
16612
+
16613
+ try
16614
+ {
16615
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16616
+ mipmapped,
16617
+ FileUtil.getFileSuffix(resourceName));
16618
+ }
16619
+ catch (Exception e)
16620
+ {
16621
+ try
16622
+ {
16623
+ resourceName = basename + fallback[i] + "." + suffix;
16624
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16625
+ mipmapped,
16626
+ FileUtil.getFileSuffix(resourceName));
16627
+ }
16628
+ catch (Exception e2)
16629
+ {
16630
+ resourceName = basename + fallfallback[i] + "." + suffix;
16631
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16632
+ mipmapped,
16633
+ FileUtil.getFileSuffix(resourceName));
16634
+ }
16635
+ }
16636
+
1636816637 //System.out.println("Target = " + targets[i]);
1636916638 cubemap.updateImage(data, targets[i]);
1637016639 }
1637116640
1637216641 return cubemap;
1637316642 }
16643
+
1637416644 int bigsphere = -1;
1637516645
1637616646 float BGcolor = 0.5f;
1637716647
16378
- private void DrawSkyBox(GL gl)
16648
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16649
+
16650
+ private void DrawSkyBox(GL gl, float ratio)
1637916651 {
16380
- if (envyoff || cubemap == null)
16652
+ if (//envyoff ||
16653
+ cubemap == null)
1638116654 {
1638216655 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1638316656 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16392,7 +16665,17 @@
1639216665 // Compensates for ExaminerViewer's modification of modelview matrix
1639316666 gl.glMatrixMode(GL.GL_MODELVIEW);
1639416667 gl.glLoadIdentity();
16668
+ gl.glScalef(1,ratio,1);
1639516669
16670
+ colorV[0] = 2;
16671
+ colorV[1] = 2;
16672
+ colorV[2] = 2;
16673
+ colorV[3] = 1;
16674
+ gl.glDisable(gl.GL_COLOR_MATERIAL);
16675
+ gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16676
+
16677
+ gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16678
+
1639616679 //gl.glActiveTexture(GL.GL_TEXTURE1);
1639716680 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1639816681
....@@ -16405,7 +16688,7 @@
1640516688 // GL_NORMAL_MAP texgen mode. Temporarily enabling lighting
1640616689 // causes the normals to be sent down. Thanks to Ken Dyke.
1640716690 //gl.glEnable(GL.GL_LIGHTING);
16408
- gl.glDisable(GL.GL_LIGHTING);
16691
+ gl.glEnable(GL.GL_LIGHTING);
1640916692
1641016693 gl.glTexGeni(GL.GL_S, GL.GL_TEXTURE_GEN_MODE, GL.GL_NORMAL_MAP);
1641116694 gl.glTexGeni(GL.GL_T, GL.GL_TEXTURE_GEN_MODE, GL.GL_NORMAL_MAP);
....@@ -16424,6 +16707,7 @@
1642416707 {
1642516708 gl.glScalef(1.0f, -1.0f, 1.0f);
1642616709 }
16710
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1642716711 gl.glMultMatrixd(viewrot_1, 0);
1642816712 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1642916713 //viewer.updateInverseRotation(gl);
....@@ -16659,6 +16943,14 @@
1665916943 }
1666016944 }
1666116945
16946
+ private Object3D GetFolder()
16947
+ {
16948
+ Object3D folder = object.GetWindow().copy;
16949
+ if (object.GetWindow().copy.selection.Size() > 0)
16950
+ folder = object.GetWindow().copy.selection.elementAt(0);
16951
+ return folder;
16952
+ }
16953
+
1666216954 class SelectBuffer implements GLEventListener
1666316955 {
1666416956
....@@ -16674,7 +16966,7 @@
1667416966 //new Exception().printStackTrace();
1667516967 System.out.println("select buffer init");
1667616968 // Use debug pipeline
16677
- drawable.setGL(new DebugGL(drawable.getGL()));
16969
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1667816970
1667916971 GL gl = drawable.getGL();
1668016972
....@@ -16738,6 +17030,17 @@
1673817030
1673917031 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1674017032
17033
+ if (PAINTMODE)
17034
+ {
17035
+ if (object.GetWindow().copy.selection.Size() > 0)
17036
+ {
17037
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17038
+
17039
+ // Make what you paint not selectable.
17040
+ paintobj.ResetSelectable();
17041
+ }
17042
+ }
17043
+
1674117044 //int tmp = selection_view;
1674217045 //selection_view = -1;
1674317046 int temp = DrawMode();
....@@ -16749,6 +17052,17 @@
1674917052 // temp = DEFAULT; // patch for selection debug
1675017053 Globals.drawMode = temp; // WARNING
1675117054
17055
+ if (PAINTMODE)
17056
+ {
17057
+ if (object.GetWindow().copy.selection.Size() > 0)
17058
+ {
17059
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17060
+
17061
+ // Revert.
17062
+ paintobj.RestoreSelectable();
17063
+ }
17064
+ }
17065
+
1675217066 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1675317067
1675417068 // trying different ways of getting the depth info over
....@@ -16852,29 +17166,31 @@
1685217166 }
1685317167
1685417168 if (!movingcamera && !PAINTMODE)
16855
- object.editWindow.ScreenFitPoint(); // fev 2014
17169
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1685617170
16857
- if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17171
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1685817172 {
16859
- Object3D paintobj = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17173
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1686017174
16861
- Object3D group = new Object3D("inst" + paintcount++);
17175
+ if (object.GetWindow().copy.selection.Size() > 0)
17176
+ {
17177
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1686217178
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();
17179
+ Object3D inst = new Object3D("inst" + paintcount++);
17180
+
17181
+ inst.CreateMaterial(); // use a void leaf to select instances
17182
+
17183
+ inst.add(paintobj); // link
17184
+
17185
+ object.GetWindow().SnapObject(inst);
17186
+
17187
+ Object3D folder = paintFolder; // GetFolder();
17188
+
17189
+ folder.add(inst);
17190
+
17191
+ object.GetWindow().ResetModel();
17192
+ object.GetWindow().refreshContents();
17193
+ }
1687817194 }
1687917195 else
1688017196 paintcount = 0;