Normand Briere
2019-07-28 d7fd07756f4095cb87dc25d89fcffcbda092e2cf
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,13 @@
92089314 static double[] model = new double[16];
92099315 double[] camera2light = new double[16];
92109316 double[] light2camera = new double[16];
9211
- int newenvy = -1;
9317
+
9318
+ //int newenvy = -1;
92129319 boolean envyoff = true; // false;
9320
+ String skyboxname = "";
9321
+ String skyboxext;
9322
+ String loadedskyboxname = "";
9323
+
92139324 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
92149325 //float[] light0 = { 0,0,0 };
92159326 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9627,7 +9738,7 @@
96279738
96289739 if (renderCamera != lightCamera)
96299740 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9630
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
9741
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
96319742
96329743 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
96339744
....@@ -9643,7 +9754,7 @@
96439754
96449755 if (renderCamera != lightCamera)
96459756 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9646
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
9757
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
96479758
96489759 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
96499760
....@@ -9689,10 +9800,12 @@
96899800 rati = 1 / rati;
96909801 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
96919802 }
9692
- assert (newenvy == -1);
9803
+
9804
+ //assert (newenvy == -1);
9805
+
96939806 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
96949807 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9695
- DrawSkyBox(gl);
9808
+ DrawSkyBox(gl, (float)rati);
96969809 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
96979810 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
96989811 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10844,7 +10957,7 @@
1084410957 // if (parentcam != renderCamera) // not a light
1084510958 if (cam != lightCamera)
1084610959 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10847
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
10960
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1084810961
1084910962 for (int j = 0; j < 4; j++)
1085010963 {
....@@ -10859,7 +10972,7 @@
1085910972 // if (parentcam != renderCamera) // not a light
1086010973 if (cam != lightCamera)
1086110974 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10862
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
10975
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1086310976
1086410977 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1086510978
....@@ -10945,13 +11058,19 @@
1094511058 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1094611059 }
1094711060
10948
- if (newenvy > -1)
11061
+// if (newenvy > -1)
11062
+// {
11063
+// LoadEnvy(newenvy);
11064
+// }
11065
+//
11066
+// newenvy = -1;
11067
+
11068
+ if (!skyboxname.equals(this.loadedskyboxname))
1094911069 {
10950
- LoadEnvy(newenvy);
11070
+ LoadSkybox(skyboxname + "/", skyboxext, false);
11071
+ loadedskyboxname = skyboxname;
1095111072 }
10952
-
10953
- newenvy = -1;
10954
-
11073
+
1095511074 ratio = ((double) getWidth()) / getHeight();
1095611075 //System.out.println("ratio = " + ratio);
1095711076
....@@ -10967,7 +11086,7 @@
1096711086
1096811087 if (!IsFrozen() && !ambientOcclusion)
1096911088 {
10970
- DrawSkyBox(gl);
11089
+ DrawSkyBox(gl, (float)ratio);
1097111090 }
1097211091
1097311092 //if (selection_view == -1)
....@@ -11150,9 +11269,9 @@
1115011269
1115111270 gl.glMatrixMode(GL.GL_MODELVIEW);
1115211271
11153
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11154
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
11155
-//gl.glEnable(gl.GL_MULTISAMPLE);
11272
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11273
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11274
+gl.glEnable(gl.GL_MULTISAMPLE);
1115611275 } else
1115711276 {
1115811277 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -11163,7 +11282,7 @@
1116311282 //System.out.println("BLENDING ON");
1116411283 gl.glEnable(GL.GL_BLEND);
1116511284 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
11166
-
11285
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1116711286 gl.glMatrixMode(gl.GL_PROJECTION);
1116811287 gl.glLoadIdentity();
1116911288
....@@ -11412,7 +11531,7 @@
1141211531 }
1141311532 }
1141411533
11415
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11534
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1141611535 {
1141711536 //gl.glDepthFunc(GL.GL_LEQUAL);
1141811537 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11420,24 +11539,21 @@
1142011539
1142111540 boolean texon = textureon;
1142211541
11423
- if (RENDERPROGRAM > 0)
11424
- {
11425
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11426
- textureon = false;
11427
- }
11542
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11543
+ textureon = false;
11544
+
1142811545 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1142911546 //System.out.println("ALLO");
1143011547 gl.glColorMask(false, false, false, false);
1143111548 DrawObject(gl);
11432
- if (RENDERPROGRAM > 0)
11433
- {
11434
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11435
- textureon = texon;
11436
- }
11549
+
11550
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11551
+ textureon = texon;
11552
+
1143711553 gl.glColorMask(true, true, true, true);
1143811554
1143911555 gl.glDepthFunc(GL.GL_EQUAL);
11440
- //gl.glDepthMask(false);
11556
+ gl.glDepthMask(false);
1144111557 }
1144211558
1144311559 if (false) // DrawMode() == SHADOW)
....@@ -11649,7 +11765,7 @@
1164911765 if ((TRACK || SHADOWTRACK) || zoomonce)
1165011766 {
1165111767 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11652
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11768
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1165311769 pingthread.StepToTarget(true); // true);
1165411770 // zoomonce = false;
1165511771 }
....@@ -11777,20 +11893,32 @@
1177711893 ReleaseTextures(DEFAULT_TEXTURES);
1177811894
1177911895 if (CLEANCACHE)
11780
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11896
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1178111897 {
11782
- String tex = e.nextElement();
11898
+ cTexture tex = e.nextElement();
1178311899
1178411900 // System.out.println("Texture --------- " + tex);
1178511901
11786
- if (tex.equals("WHITE_NOISE"))
11902
+ if (tex.equals("WHITE_NOISE:"))
1178711903 continue;
1178811904
11789
- if (!usedtextures.containsKey(tex))
11905
+ if (!usedtextures.contains(tex))
1179011906 {
11907
+ CacheTexture gettex = texturepigment.get(tex);
1179111908 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11792
- textures.get(tex).texture.dispose();
11793
- textures.remove(tex);
11909
+ if (gettex != null)
11910
+ {
11911
+ gettex.texture.dispose();
11912
+ texturepigment.remove(tex);
11913
+ }
11914
+
11915
+ gettex = texturebump.get(tex);
11916
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11917
+ if (gettex != null)
11918
+ {
11919
+ gettex.texture.dispose();
11920
+ texturebump.remove(tex);
11921
+ }
1179411922 }
1179511923 }
1179611924 }
....@@ -12318,8 +12446,76 @@
1231812446
1231912447 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1232012448
12449
+ String program0 =
12450
+ // Min shader
12451
+ "!!ARBfp1.0\n" +
12452
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12453
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12454
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12455
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12456
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12457
+ "PARAM light2cam0 = program.env[10];" +
12458
+ "PARAM light2cam1 = program.env[11];" +
12459
+ "PARAM light2cam2 = program.env[12];" +
12460
+ "TEMP temp;" +
12461
+ "TEMP light;" +
12462
+ "TEMP ndotl;" +
12463
+ "TEMP normal;" +
12464
+ "TEMP depth;" +
12465
+ "TEMP eye;" +
12466
+ "TEMP pos;" +
12467
+
12468
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12469
+ Normalize("normal") +
12470
+ "MOV light, state.light[0].position;" +
12471
+ "DP3 ndotl.x, light, normal;" +
12472
+
12473
+ // shadow
12474
+ "MOV pos, fragment.texcoord[1];" +
12475
+ "MOV temp, pos;" +
12476
+ ShadowTextureFetch("depth", "temp", "1") +
12477
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12478
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12479
+
12480
+ // No shadow when out of frustum
12481
+ //"SGE temp.y, depth.z, zero123.y;" +
12482
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12483
+
12484
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12485
+
12486
+ // Backlit
12487
+ "MOV pos.w, zero123.y;" +
12488
+ "DP4 eye.x, pos, light2cam0;" +
12489
+ "DP4 eye.y, pos, light2cam1;" +
12490
+ "DP4 eye.z, pos, light2cam2;" +
12491
+ Normalize("eye") +
12492
+
12493
+ "DP3 ndotl.y, -eye, normal;" +
12494
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12495
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12496
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12497
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12498
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12499
+
12500
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12501
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12502
+
12503
+ // Pigment
12504
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12505
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12506
+ "MUL temp, temp, ndotl.x;" +
12507
+
12508
+ "MUL temp, temp, zero123.z;" +
12509
+
12510
+ //"MUL temp, temp, ndotl.y;" +
12511
+
12512
+ "MOV temp.w, zero123.y;" + // reset alpha
12513
+ "MOV result.color, temp;" +
12514
+ "END";
12515
+
1232112516 String program =
1232212517 "!!ARBfp1.0\n" +
12518
+
1232312519 //"OPTION ARB_fragment_program_shadow;" +
1232412520 "PARAM light2cam0 = program.env[10];" +
1232512521 "PARAM light2cam1 = program.env[11];" +
....@@ -12434,8 +12630,7 @@
1243412630 "TEMP shininess;" +
1243512631 "\n" +
1243612632 "MOV texSamp, one;" +
12437
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12438
-
12633
+
1243912634 "MOV mapgrid.x, one2048th.x;" +
1244012635 "MOV temp, fragment.texcoord[1];" +
1244112636 /*
....@@ -12456,20 +12651,20 @@
1245612651 "MUL temp, floor, mapgrid.x;" +
1245712652 //"TEX depth0, temp, texture[1], 2D;" +
1245812653 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12459
- TextureFetch("depth0", "temp", "1") +
12654
+ ShadowTextureFetch("depth0", "temp", "1") +
1246012655 "") +
1246112656 "ADD temp.x, temp.x, mapgrid.x;" +
1246212657 //"TEX depth1, temp, texture[1], 2D;" +
1246312658 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12464
- TextureFetch("depth1", "temp", "1") +
12659
+ ShadowTextureFetch("depth1", "temp", "1") +
1246512660 "") +
1246612661 "ADD temp.y, temp.y, mapgrid.x;" +
1246712662 //"TEX depth2, temp, texture[1], 2D;" +
12468
- TextureFetch("depth2", "temp", "1") +
12663
+ ShadowTextureFetch("depth2", "temp", "1") +
1246912664 "SUB temp.x, temp.x, mapgrid.x;" +
1247012665 //"TEX depth3, temp, texture[1], 2D;" +
1247112666 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12472
- TextureFetch("depth3", "temp", "1") +
12667
+ ShadowTextureFetch("depth3", "temp", "1") +
1247312668 "") +
1247412669 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1247512670 //"MOV params, material;" +
....@@ -12840,10 +13035,10 @@
1284013035 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1284113036 "") +
1284213037
12843
- // display shadow only (bump == 0)
13038
+ // display shadow only (fakedepth == 0)
1284413039 "SUB temp.x, half.x, shadow.x;" +
1284513040 "MOV temp.y, -params5.z;" + // params6.x;" +
12846
- "SLT temp.z, temp.y, -one2048th.x;" +
13041
+ "SLT temp.z, temp.y, -c256i.x;" +
1284713042 "SUB temp.y, one.x, temp.z;" +
1284813043 "MUL temp.x, temp.x, temp.y;" +
1284913044 "KIL temp.x;" +
....@@ -13267,25 +13462,26 @@
1326713462 return out;
1326813463 }
1326913464
13270
- String TextureFetch(String dest, String src, String unit)
13465
+ // Also does frustum culling
13466
+ String ShadowTextureFetch(String dest, String src, String unit)
1327113467 {
1327213468 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1327313469 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1327413470 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13471
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13472
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1327513473 "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;" +
13474
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13475
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1328013476 //"SWZ buffer, temp, w,w,w,w;";
13281
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13477
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1328213478 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1328313479 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1328413480 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13285
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13481
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1328613482
13287
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13288
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13483
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13484
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1328913485 }
1329013486
1329113487 String Shadow(String depth, String shadow)
....@@ -13332,7 +13528,7 @@
1333213528 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1333313529 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1333413530
13335
- // No shadow when out of frustrum
13531
+ // No shadow when out of frustum
1333613532 "SGE temp.x, " + depth + ".z, one.z;" +
1333713533 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1333813534 "";
....@@ -14065,7 +14261,7 @@
1406514261
1406614262 // fev 2014???
1406714263 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
14068
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14264
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1406914265 pingthread.StepToTarget(true); // true);
1407014266 }
1407114267 // if (!LIVE)
....@@ -14130,14 +14326,15 @@
1413014326 drag = false;
1413114327 //System.out.println("Mouse DOWN");
1413214328 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);
14329
+ //ClickInfo info = new ClickInfo();
14330
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14331
+ object.clickInfo.pane = this;
14332
+ object.clickInfo.camera = renderCamera;
14333
+ object.clickInfo.x = x;
14334
+ object.clickInfo.y = y;
14335
+ object.clickInfo.modifiers = modifiersex;
14336
+ editObj = object.doEditClick(//info,
14337
+ 0);
1414114338 if (!editObj)
1414214339 {
1414314340 hasMarquee = true;
....@@ -14419,12 +14616,12 @@
1441914616 void GoDown(int mod)
1442014617 {
1442114618 MODIFIERS |= COMMAND;
14422
- /*
14619
+ /**/
1442314620 if((mod&SHIFT) == SHIFT)
1442414621 manipCamera.RotatePosition(0, -speed);
1442514622 else
14426
- manipCamera.BackForth(0, -speed*delta, getWidth());
14427
- */
14623
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14624
+ /**/
1442814625 if ((mod & SHIFT) == SHIFT)
1442914626 {
1443014627 mouseMode = mouseMode; // VR??
....@@ -14440,12 +14637,12 @@
1444014637 void GoUp(int mod)
1444114638 {
1444214639 MODIFIERS |= COMMAND;
14443
- /*
14640
+ /**/
1444414641 if((mod&SHIFT) == SHIFT)
1444514642 manipCamera.RotatePosition(0, speed);
1444614643 else
14447
- manipCamera.BackForth(0, speed*delta, getWidth());
14448
- */
14644
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14645
+ /**/
1444914646 if ((mod & SHIFT) == SHIFT)
1445014647 {
1445114648 mouseMode = mouseMode;
....@@ -14461,12 +14658,12 @@
1446114658 void GoLeft(int mod)
1446214659 {
1446314660 MODIFIERS |= COMMAND;
14464
- /*
14661
+ /**/
1446514662 if((mod&SHIFT) == SHIFT)
14466
- manipCamera.RotatePosition(speed, 0);
14467
- else
1446814663 manipCamera.Translate(speed*delta, 0, getWidth());
14469
- */
14664
+ else
14665
+ manipCamera.RotatePosition(speed, 0);
14666
+ /**/
1447014667 if ((mod & SHIFT) == SHIFT)
1447114668 {
1447214669 mouseMode = mouseMode;
....@@ -14482,12 +14679,12 @@
1448214679 void GoRight(int mod)
1448314680 {
1448414681 MODIFIERS |= COMMAND;
14485
- /*
14682
+ /**/
1448614683 if((mod&SHIFT) == SHIFT)
14487
- manipCamera.RotatePosition(-speed, 0);
14488
- else
1448914684 manipCamera.Translate(-speed*delta, 0, getWidth());
14490
- */
14685
+ else
14686
+ manipCamera.RotatePosition(-speed, 0);
14687
+ /**/
1449114688 if ((mod & SHIFT) == SHIFT)
1449214689 {
1449314690 mouseMode = mouseMode;
....@@ -14537,15 +14734,16 @@
1453714734 if (editObj)
1453814735 {
1453914736 drag = true;
14540
- ClickInfo info = new ClickInfo();
14541
- info.bounds.setBounds(0, 0,
14737
+ //ClickInfo info = new ClickInfo();
14738
+ object.clickInfo.bounds.setBounds(0, 0,
1454214739 (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);
14740
+ object.clickInfo.pane = this;
14741
+ object.clickInfo.camera = renderCamera;
14742
+ object.clickInfo.x = x;
14743
+ object.clickInfo.y = y;
14744
+ object //.GetWindow().copy
14745
+ .doEditDrag(//info,
14746
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1454914747 } else
1455014748 {
1455114749 if (x < startX)
....@@ -14694,24 +14892,27 @@
1469414892 }
1469514893 }
1469614894
14895
+// ClickInfo clickInfo = new ClickInfo();
14896
+
1469714897 public void mouseMoved(MouseEvent e)
1469814898 {
1469914899 //System.out.println("mouseMoved: " + e);
1470014900 if (isRenderer)
1470114901 return;
1470214902
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;
14903
+ // Mouse cursor feedback
14904
+ object.clickInfo.x = e.getX();
14905
+ object.clickInfo.y = e.getY();
14906
+ object.clickInfo.modifiers = e.getModifiersEx();
14907
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14908
+ object.clickInfo.pane = this;
14909
+ object.clickInfo.camera = renderCamera;
1471014910 if (!isRenderer)
1471114911 {
1471214912 //ObjEditor editWindow = object.editWindow;
1471314913 //Object3D copy = editWindow.copy;
14714
- if (object.doEditClick(ci, 0))
14914
+ if (object.doEditClick(//clickInfo,
14915
+ 0))
1471514916 {
1471614917 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1471714918 } else
....@@ -14726,7 +14927,8 @@
1472614927 Globals.MOUSEDRAGGED = false;
1472714928
1472814929 movingcamera = false;
14729
- X = Y = 0;
14930
+ X = 0; // getBounds().width/2;
14931
+ Y = 0; // getBounds().height/2;
1473014932 //System.out.println("mouseReleased: " + e);
1473114933 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1473214934 }
....@@ -14982,7 +15184,8 @@
1498215184 // break;
1498315185 case 'T':
1498415186 CACHETEXTURE ^= true;
14985
- textures.clear();
15187
+ texturepigment.clear();
15188
+ texturebump.clear();
1498615189 // repaint();
1498715190 break;
1498815191 case 'Y':
....@@ -15067,7 +15270,9 @@
1506715270 case 'E' : COMPACT ^= true;
1506815271 repaint();
1506915272 break;
15070
- case 'W' : DEBUGHSB ^= true;
15273
+ case 'W' : // Wide Window (fullscreen)
15274
+ //DEBUGHSB ^= true;
15275
+ ObjEditor.theFrame.ToggleFullScreen();
1507115276 repaint();
1507215277 break;
1507315278 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -15093,13 +15298,7 @@
1509315298 repaint();
1509415299 break;
1509515300 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':
15301
+ //case 'L':
1510315302 if (lightMode)
1510415303 {
1510515304 lightMode = false;
....@@ -15169,14 +15368,18 @@
1516915368 case '3':
1517015369 case '4':
1517115370 case '5':
15172
- newenvy = Character.getNumericValue(key);
15173
- repaint();
15174
- break;
1517515371 case '6':
1517615372 case '7':
1517715373 case '8':
1517815374 case '9':
15179
- BGcolor = (key - '6')/3.f;
15375
+ if (envyoff)
15376
+ {
15377
+ BGcolor = (key - '1')/8.f;
15378
+ }
15379
+ else
15380
+ {
15381
+ //newenvy = Character.getNumericValue(key);
15382
+ }
1518015383 repaint();
1518115384 break;
1518215385 case '!':
....@@ -15246,7 +15449,10 @@
1524615449 // kompactbit = 6;
1524715450 // break;
1524815451 case ' ':
15249
- ObjEditor.theFrame.ToggleFullScreen();
15452
+ lightMode ^= true;
15453
+ Globals.lighttouched = true;
15454
+ manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
15455
+ targetLookAt.set(manipCamera.lookAt);
1525015456 repaint();
1525115457 break;
1525215458 //case '`' :
....@@ -15295,12 +15501,6 @@
1529515501 break;
1529615502 case '+':
1529715503
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
-
1530415504 /*
1530515505 //fontsize += 1;
1530615506 bbzoom *= 2;
....@@ -15318,17 +15518,17 @@
1531815518 case '=':
1531915519 IncDepth();
1532015520 //fontsize += 1;
15321
- object.editWindow.refreshContents(true);
15521
+ object.GetWindow().refreshContents(true);
1532215522 maskbit = 6;
1532315523 break;
1532415524 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1532515525 DecDepth();
1532615526 maskbit = 5;
1532715527 //if(fontsize > 1) fontsize -= 1;
15328
- if (object.editWindow == null)
15329
- new Exception().printStackTrace();
15330
- else
15331
- object.editWindow.refreshContents(true);
15528
+// if (object.editWindow == null)
15529
+// new Exception().printStackTrace();
15530
+// else
15531
+ object.GetWindow().refreshContents(true);
1533215532 break;
1533315533 case '{':
1533415534 manipCamera.shaper_fovy /= 1.1;
....@@ -15552,7 +15752,7 @@
1555215752 }
1555315753 */
1555415754
15555
- object.editWindow.EditSelection(false);
15755
+ object.GetWindow().EditSelection(false);
1555615756 }
1555715757
1555815758 void SelectParent()
....@@ -15569,10 +15769,10 @@
1556915769 {
1557015770 //selectees.remove(i);
1557115771 System.out.println("select parent of " + elem);
15572
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15772
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1557315773 } else
1557415774 {
15575
- group.editWindow.Select(elem.GetTreePath(), first, true);
15775
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1557615776 }
1557715777
1557815778 first = false;
....@@ -15614,12 +15814,12 @@
1561415814 for (int j = 0; j < group.children.size(); j++)
1561515815 {
1561615816 elem = (Object3D) group.children.elementAt(j);
15617
- object.editWindow.Select(elem.GetTreePath(), first, true);
15817
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1561815818 first = false;
1561915819 }
1562015820 } else
1562115821 {
15622
- object.editWindow.Select(elem.GetTreePath(), first, true);
15822
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1562315823 }
1562415824
1562515825 first = false;
....@@ -15630,21 +15830,21 @@
1563015830 {
1563115831 //Composite group = (Composite) object;
1563215832 Object3D group = object;
15633
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15833
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1563415834 }
1563515835
1563615836 void ResetTransform(int mask)
1563715837 {
1563815838 //Composite group = (Composite) object;
1563915839 Object3D group = object;
15640
- group.editWindow.ResetTransform(mask);
15840
+ group.GetWindow().ResetTransform(mask);
1564115841 }
1564215842
1564315843 void FlipTransform()
1564415844 {
1564515845 //Composite group = (Composite) object;
1564615846 Object3D group = object;
15647
- group.editWindow.FlipTransform();
15847
+ group.GetWindow().FlipTransform();
1564815848 // group.editWindow.ReduceMesh(true);
1564915849 }
1565015850
....@@ -15652,7 +15852,7 @@
1565215852 {
1565315853 //Composite group = (Composite) object;
1565415854 Object3D group = object;
15655
- group.editWindow.PrintMemory();
15855
+ group.GetWindow().PrintMemory();
1565615856 // group.editWindow.ReduceMesh(true);
1565715857 }
1565815858
....@@ -15660,7 +15860,7 @@
1566015860 {
1566115861 //Composite group = (Composite) object;
1566215862 Object3D group = object;
15663
- group.editWindow.ResetCentroid();
15863
+ group.GetWindow().ResetCentroid();
1566415864 }
1566515865
1566615866 void IncDepth()
....@@ -15742,8 +15942,6 @@
1574215942
1574315943 int width = getBounds().width;
1574415944 int height = getBounds().height;
15745
- ClickInfo info = new ClickInfo();
15746
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1574715945 //Image img = CreateImage(width, height);
1574815946 //System.out.println("width = " + width + "; height = " + height + "\n");
1574915947
....@@ -15820,48 +16018,77 @@
1582016018 }
1582116019 if (object != null && !hasMarquee)
1582216020 {
16021
+ if (object.clickInfo == null)
16022
+ object.clickInfo = new ClickInfo();
16023
+ ClickInfo info = object.clickInfo;
16024
+ //ClickInfo info = new ClickInfo();
16025
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16026
+
1582316027 if (isRenderer)
1582416028 {
15825
- info.flags++;
16029
+ object.clickInfo.flags++;
1582616030 double frameAspect = (double) width / (double) height;
1582716031 if (frameAspect > renderCamera.aspect)
1582816032 {
1582916033 int desired = (int) ((double) height * renderCamera.aspect);
15830
- info.bounds.width -= width - desired;
15831
- info.bounds.x += (width - desired) / 2;
16034
+ object.clickInfo.bounds.width -= width - desired;
16035
+ object.clickInfo.bounds.x += (width - desired) / 2;
1583216036 } else
1583316037 {
1583416038 int desired = (int) ((double) width / renderCamera.aspect);
15835
- info.bounds.height -= height - desired;
15836
- info.bounds.y += (height - desired) / 2;
16039
+ object.clickInfo.bounds.height -= height - desired;
16040
+ object.clickInfo.bounds.y += (height - desired) / 2;
1583716041 }
1583816042 }
15839
- info.g = gr;
15840
- info.camera = renderCamera;
16043
+
16044
+ object.clickInfo.g = gr;
16045
+ object.clickInfo.camera = renderCamera;
1584116046 /*
1584216047 // Memory intensive (brep.verticescopy)
1584316048 if (!(object instanceof Composite))
1584416049 object.draw(info, 0, false); // SLOW :
1584516050 */
15846
- if (!isRenderer)
16051
+ if (!isRenderer) // && drag)
1584716052 {
15848
- object.drawEditHandles(info, 0);
15849
-
15850
- if (drag && (X != 0 || Y != 0) && object.selection.Size() > 0)
16053
+ Grafreed.Assert(object != null);
16054
+ Grafreed.Assert(object.selection != null);
16055
+ if (object.selection.Size() > 0)
1585116056 {
15852
- switch (object.selection.get(0).hitSomething)
16057
+ int hitSomething = object.selection.get(0).hitSomething;
16058
+
16059
+ object.clickInfo.DX = 0;
16060
+ object.clickInfo.DY = 0;
16061
+ object.clickInfo.W = 1;
16062
+ if (hitSomething == Object3D.hitCenter)
1585316063 {
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;
16064
+ info.DX = X;
16065
+ if (X != 0)
16066
+ info.DX -= info.bounds.width/2;
16067
+
16068
+ info.DY = Y;
16069
+ if (Y != 0)
16070
+ info.DY -= info.bounds.height/2;
1586316071 }
15864
-
16072
+
16073
+ object.drawEditHandles(//info,
16074
+ 0);
16075
+
16076
+ if (drag && (X != 0 || Y != 0))
16077
+ {
16078
+ switch (hitSomething)
16079
+ {
16080
+ case Object3D.hitCenter: gr.setColor(Color.pink);
16081
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16082
+ break;
16083
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16084
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16085
+ break;
16086
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16087
+ gr.drawLine(X, Y, 0, 0);
16088
+ break;
16089
+ }
16090
+
16091
+ }
1586516092 }
1586616093 }
1586716094 }
....@@ -16375,7 +16602,9 @@
1637516602
1637616603 float BGcolor = 0.5f;
1637716604
16378
- private void DrawSkyBox(GL gl)
16605
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16606
+
16607
+ private void DrawSkyBox(GL gl, float ratio)
1637916608 {
1638016609 if (envyoff || cubemap == null)
1638116610 {
....@@ -16392,7 +16621,17 @@
1639216621 // Compensates for ExaminerViewer's modification of modelview matrix
1639316622 gl.glMatrixMode(GL.GL_MODELVIEW);
1639416623 gl.glLoadIdentity();
16624
+ gl.glScalef(1,ratio,1);
1639516625
16626
+ colorV[0] = 2;
16627
+ colorV[1] = 2;
16628
+ colorV[2] = 2;
16629
+ colorV[3] = 1;
16630
+ gl.glDisable(gl.GL_COLOR_MATERIAL);
16631
+ gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16632
+
16633
+ gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16634
+
1639616635 //gl.glActiveTexture(GL.GL_TEXTURE1);
1639716636 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1639816637
....@@ -16405,7 +16644,7 @@
1640516644 // GL_NORMAL_MAP texgen mode. Temporarily enabling lighting
1640616645 // causes the normals to be sent down. Thanks to Ken Dyke.
1640716646 //gl.glEnable(GL.GL_LIGHTING);
16408
- gl.glDisable(GL.GL_LIGHTING);
16647
+ gl.glEnable(GL.GL_LIGHTING);
1640916648
1641016649 gl.glTexGeni(GL.GL_S, GL.GL_TEXTURE_GEN_MODE, GL.GL_NORMAL_MAP);
1641116650 gl.glTexGeni(GL.GL_T, GL.GL_TEXTURE_GEN_MODE, GL.GL_NORMAL_MAP);
....@@ -16659,6 +16898,14 @@
1665916898 }
1666016899 }
1666116900
16901
+ private Object3D GetFolder()
16902
+ {
16903
+ Object3D folder = object.GetWindow().copy;
16904
+ if (object.GetWindow().copy.selection.Size() > 0)
16905
+ folder = object.GetWindow().copy.selection.elementAt(0);
16906
+ return folder;
16907
+ }
16908
+
1666216909 class SelectBuffer implements GLEventListener
1666316910 {
1666416911
....@@ -16674,7 +16921,7 @@
1667416921 //new Exception().printStackTrace();
1667516922 System.out.println("select buffer init");
1667616923 // Use debug pipeline
16677
- drawable.setGL(new DebugGL(drawable.getGL()));
16924
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1667816925
1667916926 GL gl = drawable.getGL();
1668016927
....@@ -16738,6 +16985,17 @@
1673816985
1673916986 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1674016987
16988
+ if (PAINTMODE)
16989
+ {
16990
+ if (object.GetWindow().copy.selection.Size() > 0)
16991
+ {
16992
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16993
+
16994
+ // Make what you paint not selectable.
16995
+ paintobj.ResetSelectable();
16996
+ }
16997
+ }
16998
+
1674116999 //int tmp = selection_view;
1674217000 //selection_view = -1;
1674317001 int temp = DrawMode();
....@@ -16749,6 +17007,17 @@
1674917007 // temp = DEFAULT; // patch for selection debug
1675017008 Globals.drawMode = temp; // WARNING
1675117009
17010
+ if (PAINTMODE)
17011
+ {
17012
+ if (object.GetWindow().copy.selection.Size() > 0)
17013
+ {
17014
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17015
+
17016
+ // Revert.
17017
+ paintobj.RestoreSelectable();
17018
+ }
17019
+ }
17020
+
1675217021 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1675317022
1675417023 // trying different ways of getting the depth info over
....@@ -16852,29 +17121,31 @@
1685217121 }
1685317122
1685417123 if (!movingcamera && !PAINTMODE)
16855
- object.editWindow.ScreenFitPoint(); // fev 2014
17124
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1685617125
16857
- if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17126
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1685817127 {
16859
- Object3D paintobj = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17128
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1686017129
16861
- Object3D group = new Object3D("inst" + paintcount++);
17130
+ if (object.GetWindow().copy.selection.Size() > 0)
17131
+ {
17132
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1686217133
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();
17134
+ Object3D inst = new Object3D("inst" + paintcount++);
17135
+
17136
+ inst.CreateMaterial(); // use a void leaf to select instances
17137
+
17138
+ inst.add(paintobj); // link
17139
+
17140
+ object.GetWindow().SnapObject(inst);
17141
+
17142
+ Object3D folder = paintFolder; // GetFolder();
17143
+
17144
+ folder.add(inst);
17145
+
17146
+ object.GetWindow().ResetModel();
17147
+ object.GetWindow().refreshContents();
17148
+ }
1687817149 }
1687917150 else
1688017151 paintcount = 0;