Normand Briere
2019-07-23 5140c320d8addf4bd8dcaa7f350b6accdc4ffbaf
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;
....@@ -2065,7 +2102,7 @@
20652102 //System.err.println("Oeil on");
20662103 OEIL = true;
20672104 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2068
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2105
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
20692106 //pingthread.StepToTarget(true);
20702107 }
20712108
....@@ -2298,10 +2335,17 @@
22982335 HANDLES ^= true;
22992336 }
23002337
2338
+ Object3D paintFolder;
2339
+
23012340 void TogglePaint()
23022341 {
23032342 PAINTMODE ^= true;
23042343 paintcount = 0;
2344
+
2345
+ if (PAINTMODE)
2346
+ {
2347
+ paintFolder = GetFolder();
2348
+ }
23052349 }
23062350
23072351 void SwapCamera(int a, int b)
....@@ -2398,126 +2442,19 @@
23982442 return currentGL;
23992443 }
24002444
2401
- private void GetRemoteZip(String url, String name, boolean unzip, boolean save)
2445
+ static private BufferedImage CreateBim(TextureData texturedata)
24022446 {
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
-
2447
+ Grafreed.Assert(texturedata != null);
2448
+
2449
+ int width = texturedata.getWidth();
2450
+ int height = texturedata.getHeight();
2451
+
2452
+ Buffer buffer = texturedata.getBuffer();
2453
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2454
+
2455
+ byte[] bytes = bytebuf.array();
2456
+
2457
+ return CreateBim(bytes, width, height);
25212458 }
25222459
25232460 /**/
....@@ -2528,28 +2465,31 @@
25282465
25292466 int resolution;
25302467
2531
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2468
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
25322469 {
2533
- texture = tex;
2470
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2471
+ texturedata = texdata;
25342472 resolution = res;
25352473 }
25362474 }
25372475 /**/
25382476
25392477 // 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>();
2478
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2479
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2480
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2481
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2482
+
25432483 int pigmentdepth = 0;
25442484 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
25452485 int bumpdepth = 0;
25462486 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
25472487 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
25482488 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2549
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2489
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
25502490 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
25512491
2552
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2492
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
25532493 {
25542494 TextureData texturedata = null;
25552495
....@@ -2568,13 +2508,34 @@
25682508 if (bump)
25692509 texturedata = ConvertBump(texturedata, false);
25702510
2571
- com.sun.opengl.util.texture.Texture texture =
2572
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2511
+// com.sun.opengl.util.texture.Texture texture =
2512
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
25732513
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);
2514
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2515
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
25762516
2577
- return texture;
2517
+ return texturedata;
2518
+ }
2519
+
2520
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2521
+ {
2522
+ TextureData texturedata = null;
2523
+
2524
+ try
2525
+ {
2526
+ texturedata =
2527
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2528
+ bim,
2529
+ true);
2530
+ } catch (Exception e)
2531
+ {
2532
+ throw new javax.media.opengl.GLException(e);
2533
+ }
2534
+
2535
+ if (bump)
2536
+ texturedata = ConvertBump(texturedata, false);
2537
+
2538
+ return texturedata;
25782539 }
25792540
25802541 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3647,6 +3608,8 @@
36473608
36483609 System.out.println("LOADING TEXTURE : " + name);
36493610
3611
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3612
+
36503613 //
36513614 if (false) // compressbit > 0)
36523615 {
....@@ -8045,7 +8008,7 @@
80458008 String pigment = Object3D.GetPigment(tex);
80468009 String bump = Object3D.GetBump(tex);
80478010
8048
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8011
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
80498012 {
80508013 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
80518014 // System.out.println("; bump = " + bump);
....@@ -8060,8 +8023,8 @@
80608023 pigment = null;
80618024 }
80628025
8063
- ReleaseTexture(bump, true);
8064
- ReleaseTexture(pigment, false);
8026
+ ReleaseTexture(tex, true);
8027
+ ReleaseTexture(tex, false);
80658028 }
80668029
80678030 public void ReleasePigmentTexture(cTexture tex) // INTERFACE
....@@ -8079,7 +8042,7 @@
80798042
80808043 String pigment = Object3D.GetPigment(tex);
80818044
8082
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8045
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
80838046 {
80848047 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
80858048 // System.out.println("; bump = " + bump);
....@@ -8090,7 +8053,7 @@
80908053 pigment = null;
80918054 }
80928055
8093
- ReleaseTexture(pigment, false);
8056
+ ReleaseTexture(tex, false);
80948057 }
80958058
80968059 public void ReleaseBumpTexture(cTexture tex) // INTERFACE
....@@ -8108,7 +8071,7 @@
81088071
81098072 String bump = Object3D.GetBump(tex);
81108073
8111
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8074
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
81128075 {
81138076 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
81148077 // System.out.println("; bump = " + bump);
....@@ -8119,10 +8082,10 @@
81198082 bump = null;
81208083 }
81218084
8122
- ReleaseTexture(bump, true);
8085
+ ReleaseTexture(tex, true);
81238086 }
81248087
8125
- void ReleaseTexture(String tex, boolean bump)
8088
+ void ReleaseTexture(cTexture tex, boolean bump)
81268089 {
81278090 if (// DrawMode() != 0 || /*tex == null ||*/
81288091 ambientOcclusion ) // || !textureon)
....@@ -8133,7 +8096,7 @@
81338096 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
81348097
81358098 if (tex != null)
8136
- texture = textures.get(tex);
8099
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
81378100
81388101 // //assert( texture != null );
81398102 // if (texture == null)
....@@ -8227,47 +8190,50 @@
82278190
82288191 /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
82298192 {
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
- }
8193
+// if (// DrawMode() != 0 || /*tex == null ||*/
8194
+// ambientOcclusion ) // || !textureon)
8195
+// {
8196
+// return; // false;
8197
+// }
8198
+//
8199
+// if (tex == null)
8200
+// {
8201
+// BindTexture(null,false,resolution);
8202
+// BindTexture(null,true,resolution);
8203
+// return;
8204
+// }
8205
+//
8206
+// String pigment = Object3D.GetPigment(tex);
8207
+// String bump = Object3D.GetBump(tex);
8208
+//
8209
+// usedtextures.add(pigment);
8210
+// usedtextures.add(bump);
8211
+//
8212
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8213
+// {
8214
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8215
+// // System.out.println("; bump = " + bump);
8216
+// }
8217
+//
8218
+// if (bump.equals(""))
8219
+// {
8220
+// bump = null;
8221
+// }
8222
+// if (pigment.equals(""))
8223
+// {
8224
+// pigment = null;
8225
+// }
8226
+//
8227
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8228
+// BindTexture(pigment, false, resolution);
8229
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8230
+// BindTexture(bump, true, resolution);
8231
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8232
+//
8233
+// return; // true;
82428234
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;
8235
+ BindPigmentTexture(tex, resolution);
8236
+ BindBumpTexture(tex, resolution);
82718237 }
82728238
82738239 /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8286,9 +8252,9 @@
82868252
82878253 String pigment = Object3D.GetPigment(tex);
82888254
8289
- usedtextures.put(pigment, pigment);
8255
+ usedtextures.add(tex);
82908256
8291
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8257
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
82928258 {
82938259 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
82948260 // System.out.println("; bump = " + bump);
....@@ -8300,7 +8266,7 @@
83008266 }
83018267
83028268 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8303
- BindTexture(pigment, false, resolution);
8269
+ BindTexture(tex, false, resolution);
83048270 }
83058271
83068272 /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8319,9 +8285,9 @@
83198285
83208286 String bump = Object3D.GetBump(tex);
83218287
8322
- usedtextures.put(bump, bump);
8288
+ usedtextures.add(tex);
83238289
8324
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8290
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
83258291 {
83268292 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
83278293 // System.out.println("; bump = " + bump);
....@@ -8333,7 +8299,7 @@
83338299 }
83348300
83358301 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8336
- BindTexture(bump, true, resolution);
8302
+ BindTexture(tex, true, resolution);
83378303 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
83388304 }
83398305
....@@ -8357,13 +8323,19 @@
83578323 return fileExists;
83588324 }
83598325
8360
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception
8326
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
83618327 {
8362
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8328
+ CacheTexture texturecache = null;
83638329
83648330 if (tex != null)
83658331 {
8366
- String texname = tex;
8332
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8333
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
8334
+
8335
+ if (texname.equals("") && texdata == null)
8336
+ {
8337
+ return null;
8338
+ }
83678339
83688340 String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
83698341
....@@ -8373,19 +8345,46 @@
83738345 // else
83748346 // if (!texname.startsWith("/"))
83758347 // texname = "/Users/nbriere/Textures/" + texname;
8376
- if (!FileExists(tex))
8348
+ if (!FileExists(texname))
83778349 {
83788350 texname = fallbackTextureName;
83798351 }
83808352
83818353 if (CACHETEXTURE)
8382
- texture = textures.get(texname); // TEXTURE CACHE
8383
-
8384
- TextureData texturedata = null;
8385
-
8386
- if (texture == null || texture.resolution < resolution)
83878354 {
8388
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8355
+ if (texdata == null)
8356
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8357
+ else
8358
+ texturecache = bimtextures.get(texdata);
8359
+ }
8360
+
8361
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8362
+ {
8363
+ TextureData texturedata = null;
8364
+
8365
+ if (texdata != null && textureon)
8366
+ {
8367
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8368
+
8369
+ try
8370
+ {
8371
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8372
+ }
8373
+ catch (Exception e)
8374
+ {
8375
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8376
+ }
8377
+
8378
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8379
+ bimtextures.put(texdata, texturecache);
8380
+
8381
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8382
+
8383
+ //Object bim2 = CreateBim(texturecache.texturedata);
8384
+ //bim2 = bim;
8385
+ }
8386
+ else
8387
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
83898388 {
83908389 assert(!bump);
83918390 // if (bump)
....@@ -8396,19 +8395,23 @@
83968395 // }
83978396 // else
83988397 // {
8399
- texture = textures.get(tex);
8400
- if (texture == null)
8398
+ // texturecache = textures.get(texname); // suspicious
8399
+ if (texturecache == null)
84018400 {
8402
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8401
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
84038402 }
8403
+ else
8404
+ new Exception().printStackTrace();
84048405 // }
84058406 } else
8406
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8407
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
84078408 {
84088409 assert(bump);
8409
- texture = textures.get(tex);
8410
- if (texture == null)
8411
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8410
+ // texturecache = textures.get(texname); // suspicious
8411
+ if (texturecache == null)
8412
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8413
+ else
8414
+ new Exception().printStackTrace();
84128415 } else
84138416 {
84148417 //if (tex.equals("IMMORTAL"))
....@@ -8416,11 +8419,13 @@
84168419 // texture = GetResourceTexture("default.png");
84178420 //} else
84188421 //{
8419
- if (tex.equals("WHITE_NOISE"))
8422
+ if (texname.endsWith("WHITE_NOISE"))
84208423 {
8421
- texture = textures.get(tex);
8422
- if (texture == null)
8423
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8424
+ // texturecache = textures.get(texname); // suspicious
8425
+ if (texturecache == null)
8426
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8427
+ else
8428
+ new Exception().printStackTrace();
84248429 } else
84258430 {
84268431 if (textureon)
....@@ -8479,19 +8484,19 @@
84798484 if (texturedata == null)
84808485 throw new Exception();
84818486
8482
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8487
+ texturecache = new CacheTexture(texturedata,resolution);
84838488 //texture = GetTexture(tex, bump);
84848489 }
84858490 }
84868491 //}
84878492 }
84888493
8489
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8494
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
84908495 {
84918496 //return false;
84928497
84938498 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8494
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8499
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
84958500 {
84968501 // String ext = "_highres";
84978502 // if (REDUCETEXTURE)
....@@ -8508,52 +8513,17 @@
85088513 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
85098514 if (!cachefile.exists())
85108515 {
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))
8516
+ //if (texturedata.getWidth() == texturedata.getHeight())
85208517 {
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);
8518
+ BufferedImage rendImage = CreateBim(texturedata);
8519
+
85518520 ImageWriter writer = null;
85528521 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
85538522 if (iter.hasNext()) {
85548523 writer = (ImageWriter)iter.next();
85558524 }
8556
- float compressionQuality = 0.9f;
8525
+
8526
+ float compressionQuality = 0.85f;
85578527 try
85588528 {
85598529 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8570,18 +8540,20 @@
85708540 }
85718541 }
85728542 }
8573
-
8543
+
8544
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8545
+
85748546 //System.out.println("Texture = " + tex);
8575
- if (textures.containsKey(texname))
8547
+ if (textures.containsKey(tex))
85768548 {
8577
- CacheTexture thetex = textures.get(texname);
8549
+ CacheTexture thetex = textures.get(tex);
85788550 thetex.texture.disable();
85798551 thetex.texture.dispose();
8580
- textures.remove(texname);
8552
+ textures.remove(tex);
85818553 }
85828554
8583
- texture.texturedata = texturedata;
8584
- textures.put(texname, texture);
8555
+ //texture.texturedata = texturedata;
8556
+ textures.put(tex, texturecache);
85858557
85868558 // newtex = true;
85878559 }
....@@ -8597,10 +8569,44 @@
85978569 }
85988570 }
85998571
8600
- return texture;
8572
+ return texturecache;
86018573 }
86028574
8603
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution) throws Exception
8575
+ static void EmbedTextures(cTexture tex)
8576
+ {
8577
+ if (tex.pigmentdata == null)
8578
+ {
8579
+ //String texname = Object3D.GetPigment(tex);
8580
+
8581
+ CacheTexture texturecache = texturepigment.get(tex);
8582
+
8583
+ if (texturecache != null)
8584
+ {
8585
+ tex.pw = texturecache.texturedata.getWidth();
8586
+ tex.ph = texturecache.texturedata.getHeight();
8587
+ tex.pigmentdata = //CompressJPEG(CreateBim
8588
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8589
+ ;
8590
+ //, tex.pw, tex.ph), 0.5f);
8591
+ }
8592
+ }
8593
+
8594
+ if (tex.bumpdata == null)
8595
+ {
8596
+ //String texname = Object3D.GetBump(tex);
8597
+
8598
+ CacheTexture texturecache = texturebump.get(tex);
8599
+
8600
+ if (texturecache != null)
8601
+ {
8602
+ tex.bw = texturecache.texturedata.getWidth();
8603
+ tex.bh = texturecache.texturedata.getHeight();
8604
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8605
+ }
8606
+ }
8607
+ }
8608
+
8609
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
86048610 {
86058611 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
86068612
....@@ -8618,21 +8624,21 @@
86188624 return texture!=null?texture.texture:null;
86198625 }
86208626
8621
- public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution) throws Exception
8627
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
86228628 {
86238629 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
86248630
86258631 return texture!=null?texture.texturedata:null;
86268632 }
86278633
8628
- boolean BindTexture(String tex, boolean bump, int resolution) throws Exception
8634
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
86298635 {
86308636 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
86318637 {
86328638 return false;
86338639 }
86348640
8635
- boolean newtex = false;
8641
+ //boolean newtex = false;
86368642
86378643 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
86388644
....@@ -8664,9 +8670,75 @@
86648670 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
86658671 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
86668672
8667
- return newtex;
8673
+ return true; // Warning: not used.
86688674 }
86698675
8676
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8677
+ {
8678
+ try
8679
+ {
8680
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8681
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8682
+ ImageWriter writer = writers.next();
8683
+
8684
+ ImageWriteParam param = writer.getDefaultWriteParam();
8685
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8686
+ param.setCompressionQuality(quality);
8687
+
8688
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8689
+ writer.setOutput(ios);
8690
+ writer.write(null, new IIOImage(image, null, null), param);
8691
+
8692
+ byte[] data = baos.toByteArray();
8693
+ writer.dispose();
8694
+ return data;
8695
+ }
8696
+ catch (Exception e)
8697
+ {
8698
+ e.printStackTrace();
8699
+ return null;
8700
+ }
8701
+ }
8702
+
8703
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8704
+ {
8705
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8706
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8707
+ ImageReader reader = writers.next();
8708
+
8709
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8710
+
8711
+ ImageReadParam param = reader.getDefaultReadParam();
8712
+ param.setDestination(bim);
8713
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8714
+
8715
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8716
+ reader.setInput(ios);
8717
+ BufferedImage bim2 = reader.read(0, param);
8718
+ reader.dispose();
8719
+
8720
+// WritableRaster raster = bim2.getRaster();
8721
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8722
+// byte[] bytes = data.getData();
8723
+//
8724
+// int[] pixels = new int[bytes.length/3];
8725
+// for (int i=pixels.length; --i>=0;)
8726
+// {
8727
+// int i3 = i*3;
8728
+// pixels[i] = 0xFF;
8729
+// pixels[i] <<= 8;
8730
+// pixels[i] |= bytes[i3+2] & 0xFF;
8731
+// pixels[i] <<= 8;
8732
+// pixels[i] |= bytes[i3+1] & 0xFF;
8733
+// pixels[i] <<= 8;
8734
+// pixels[i] |= bytes[i3] & 0xFF;
8735
+// }
8736
+//
8737
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8738
+
8739
+ return bim;
8740
+ }
8741
+
86708742 ShadowBuffer shadowPBuf;
86718743 AntialiasBuffer antialiasPBuf;
86728744 int MAXSTACK;
....@@ -11150,9 +11222,9 @@
1115011222
1115111223 gl.glMatrixMode(GL.GL_MODELVIEW);
1115211224
11153
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11154
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
11155
-//gl.glEnable(gl.GL_MULTISAMPLE);
11225
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11226
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11227
+gl.glEnable(gl.GL_MULTISAMPLE);
1115611228 } else
1115711229 {
1115811230 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -11163,7 +11235,7 @@
1116311235 //System.out.println("BLENDING ON");
1116411236 gl.glEnable(GL.GL_BLEND);
1116511237 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
11166
-
11238
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1116711239 gl.glMatrixMode(gl.GL_PROJECTION);
1116811240 gl.glLoadIdentity();
1116911241
....@@ -11412,7 +11484,7 @@
1141211484 }
1141311485 }
1141411486
11415
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11487
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1141611488 {
1141711489 //gl.glDepthFunc(GL.GL_LEQUAL);
1141811490 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11420,24 +11492,21 @@
1142011492
1142111493 boolean texon = textureon;
1142211494
11423
- if (RENDERPROGRAM > 0)
11424
- {
11425
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11426
- textureon = false;
11427
- }
11495
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11496
+ textureon = false;
11497
+
1142811498 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1142911499 //System.out.println("ALLO");
1143011500 gl.glColorMask(false, false, false, false);
1143111501 DrawObject(gl);
11432
- if (RENDERPROGRAM > 0)
11433
- {
11434
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11435
- textureon = texon;
11436
- }
11502
+
11503
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11504
+ textureon = texon;
11505
+
1143711506 gl.glColorMask(true, true, true, true);
1143811507
1143911508 gl.glDepthFunc(GL.GL_EQUAL);
11440
- //gl.glDepthMask(false);
11509
+ gl.glDepthMask(false);
1144111510 }
1144211511
1144311512 if (false) // DrawMode() == SHADOW)
....@@ -11649,7 +11718,7 @@
1164911718 if ((TRACK || SHADOWTRACK) || zoomonce)
1165011719 {
1165111720 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11652
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11721
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1165311722 pingthread.StepToTarget(true); // true);
1165411723 // zoomonce = false;
1165511724 }
....@@ -11777,20 +11846,32 @@
1177711846 ReleaseTextures(DEFAULT_TEXTURES);
1177811847
1177911848 if (CLEANCACHE)
11780
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11849
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1178111850 {
11782
- String tex = e.nextElement();
11851
+ cTexture tex = e.nextElement();
1178311852
1178411853 // System.out.println("Texture --------- " + tex);
1178511854
11786
- if (tex.equals("WHITE_NOISE"))
11855
+ if (tex.equals("WHITE_NOISE:"))
1178711856 continue;
1178811857
11789
- if (!usedtextures.containsKey(tex))
11858
+ if (!usedtextures.contains(tex))
1179011859 {
11860
+ CacheTexture gettex = texturepigment.get(tex);
1179111861 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11792
- textures.get(tex).texture.dispose();
11793
- textures.remove(tex);
11862
+ if (gettex != null)
11863
+ {
11864
+ gettex.texture.dispose();
11865
+ texturepigment.remove(tex);
11866
+ }
11867
+
11868
+ gettex = texturebump.get(tex);
11869
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11870
+ if (gettex != null)
11871
+ {
11872
+ gettex.texture.dispose();
11873
+ texturebump.remove(tex);
11874
+ }
1179411875 }
1179511876 }
1179611877 }
....@@ -12319,7 +12400,52 @@
1231912400 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1232012401
1232112402 String program =
12403
+ // Min shader
1232212404 "!!ARBfp1.0\n" +
12405
+ "PARAM zero123 = { 0.0, 1.0, 2.0, 1.25 };" +
12406
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12407
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12408
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12409
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12410
+ "TEMP temp;" +
12411
+ "TEMP light;" +
12412
+ "TEMP ndotl;" +
12413
+ "TEMP normal;" +
12414
+ "TEMP depth;" +
12415
+
12416
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12417
+
12418
+ "MOV light, state.light[0].position;" +
12419
+ "DP3 ndotl.x, light, normal;" +
12420
+
12421
+ // shadow
12422
+ "MOV temp, fragment.texcoord[1];" +
12423
+ TextureFetch("depth", "temp", "1") +
12424
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12425
+ "SLT temp.x, fragment.texcoord[1].z, depth.z;" +
12426
+
12427
+
12428
+ // No shadow when out of frustum
12429
+ //"SGE temp.y, depth.z, zero123.y;" +
12430
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12431
+
12432
+ "MUL ndotl.x, ndotl.x, temp.x;" +
12433
+ "MAX ndotl.x, ndotl.x, pow2.y;" +
12434
+
12435
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12436
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12437
+ "MUL temp, temp, ndotl.x;" +
12438
+
12439
+ "MUL temp, temp, zero123.z;" +
12440
+
12441
+ "MOV temp.w, zero123.y;" + // reset alpha
12442
+
12443
+ "MOV result.color, temp;" +
12444
+ "END";
12445
+
12446
+ String program2 =
12447
+ "!!ARBfp1.0\n" +
12448
+
1232312449 //"OPTION ARB_fragment_program_shadow;" +
1232412450 "PARAM light2cam0 = program.env[10];" +
1232512451 "PARAM light2cam1 = program.env[11];" +
....@@ -12434,8 +12560,7 @@
1243412560 "TEMP shininess;" +
1243512561 "\n" +
1243612562 "MOV texSamp, one;" +
12437
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12438
-
12563
+
1243912564 "MOV mapgrid.x, one2048th.x;" +
1244012565 "MOV temp, fragment.texcoord[1];" +
1244112566 /*
....@@ -12840,7 +12965,7 @@
1284012965 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1284112966 "") +
1284212967
12843
- // display shadow only (bump == 0)
12968
+ // display shadow only (fakedepth == 0)
1284412969 "SUB temp.x, half.x, shadow.x;" +
1284512970 "MOV temp.y, -params5.z;" + // params6.x;" +
1284612971 "SLT temp.z, temp.y, -one2048th.x;" +
....@@ -13272,20 +13397,20 @@
1327213397 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1327313398 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1327413399 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13400
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13401
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1327513402 "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;" +
13403
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13404
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1328013405 //"SWZ buffer, temp, w,w,w,w;";
13281
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13406
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1328213407 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1328313408 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1328413409 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13285
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13410
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1328613411
13287
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13288
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13412
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13413
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1328913414 }
1329013415
1329113416 String Shadow(String depth, String shadow)
....@@ -13332,7 +13457,7 @@
1333213457 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1333313458 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1333413459
13335
- // No shadow when out of frustrum
13460
+ // No shadow when out of frustum
1333613461 "SGE temp.x, " + depth + ".z, one.z;" +
1333713462 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1333813463 "";
....@@ -14065,7 +14190,7 @@
1406514190
1406614191 // fev 2014???
1406714192 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
14068
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14193
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1406914194 pingthread.StepToTarget(true); // true);
1407014195 }
1407114196 // if (!LIVE)
....@@ -14130,14 +14255,15 @@
1413014255 drag = false;
1413114256 //System.out.println("Mouse DOWN");
1413214257 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);
14258
+ //ClickInfo info = new ClickInfo();
14259
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14260
+ object.clickInfo.pane = this;
14261
+ object.clickInfo.camera = renderCamera;
14262
+ object.clickInfo.x = x;
14263
+ object.clickInfo.y = y;
14264
+ object.clickInfo.modifiers = modifiersex;
14265
+ editObj = object.doEditClick(//info,
14266
+ 0);
1414114267 if (!editObj)
1414214268 {
1414314269 hasMarquee = true;
....@@ -14419,12 +14545,12 @@
1441914545 void GoDown(int mod)
1442014546 {
1442114547 MODIFIERS |= COMMAND;
14422
- /*
14548
+ /**/
1442314549 if((mod&SHIFT) == SHIFT)
1442414550 manipCamera.RotatePosition(0, -speed);
1442514551 else
14426
- manipCamera.BackForth(0, -speed*delta, getWidth());
14427
- */
14552
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14553
+ /**/
1442814554 if ((mod & SHIFT) == SHIFT)
1442914555 {
1443014556 mouseMode = mouseMode; // VR??
....@@ -14440,12 +14566,12 @@
1444014566 void GoUp(int mod)
1444114567 {
1444214568 MODIFIERS |= COMMAND;
14443
- /*
14569
+ /**/
1444414570 if((mod&SHIFT) == SHIFT)
1444514571 manipCamera.RotatePosition(0, speed);
1444614572 else
14447
- manipCamera.BackForth(0, speed*delta, getWidth());
14448
- */
14573
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14574
+ /**/
1444914575 if ((mod & SHIFT) == SHIFT)
1445014576 {
1445114577 mouseMode = mouseMode;
....@@ -14461,12 +14587,12 @@
1446114587 void GoLeft(int mod)
1446214588 {
1446314589 MODIFIERS |= COMMAND;
14464
- /*
14590
+ /**/
1446514591 if((mod&SHIFT) == SHIFT)
14466
- manipCamera.RotatePosition(speed, 0);
14467
- else
1446814592 manipCamera.Translate(speed*delta, 0, getWidth());
14469
- */
14593
+ else
14594
+ manipCamera.RotatePosition(speed, 0);
14595
+ /**/
1447014596 if ((mod & SHIFT) == SHIFT)
1447114597 {
1447214598 mouseMode = mouseMode;
....@@ -14482,12 +14608,12 @@
1448214608 void GoRight(int mod)
1448314609 {
1448414610 MODIFIERS |= COMMAND;
14485
- /*
14611
+ /**/
1448614612 if((mod&SHIFT) == SHIFT)
14487
- manipCamera.RotatePosition(-speed, 0);
14488
- else
1448914613 manipCamera.Translate(-speed*delta, 0, getWidth());
14490
- */
14614
+ else
14615
+ manipCamera.RotatePosition(-speed, 0);
14616
+ /**/
1449114617 if ((mod & SHIFT) == SHIFT)
1449214618 {
1449314619 mouseMode = mouseMode;
....@@ -14537,15 +14663,16 @@
1453714663 if (editObj)
1453814664 {
1453914665 drag = true;
14540
- ClickInfo info = new ClickInfo();
14541
- info.bounds.setBounds(0, 0,
14666
+ //ClickInfo info = new ClickInfo();
14667
+ object.clickInfo.bounds.setBounds(0, 0,
1454214668 (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);
14669
+ object.clickInfo.pane = this;
14670
+ object.clickInfo.camera = renderCamera;
14671
+ object.clickInfo.x = x;
14672
+ object.clickInfo.y = y;
14673
+ object //.GetWindow().copy
14674
+ .doEditDrag(//info,
14675
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1454914676 } else
1455014677 {
1455114678 if (x < startX)
....@@ -14694,24 +14821,27 @@
1469414821 }
1469514822 }
1469614823
14824
+// ClickInfo clickInfo = new ClickInfo();
14825
+
1469714826 public void mouseMoved(MouseEvent e)
1469814827 {
1469914828 //System.out.println("mouseMoved: " + e);
1470014829 if (isRenderer)
1470114830 return;
1470214831
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;
14832
+ // Mouse cursor feedback
14833
+ object.clickInfo.x = e.getX();
14834
+ object.clickInfo.y = e.getY();
14835
+ object.clickInfo.modifiers = e.getModifiersEx();
14836
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14837
+ object.clickInfo.pane = this;
14838
+ object.clickInfo.camera = renderCamera;
1471014839 if (!isRenderer)
1471114840 {
1471214841 //ObjEditor editWindow = object.editWindow;
1471314842 //Object3D copy = editWindow.copy;
14714
- if (object.doEditClick(ci, 0))
14843
+ if (object.doEditClick(//clickInfo,
14844
+ 0))
1471514845 {
1471614846 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1471714847 } else
....@@ -14726,7 +14856,8 @@
1472614856 Globals.MOUSEDRAGGED = false;
1472714857
1472814858 movingcamera = false;
14729
- X = Y = 0;
14859
+ X = 0; // getBounds().width/2;
14860
+ Y = 0; // getBounds().height/2;
1473014861 //System.out.println("mouseReleased: " + e);
1473114862 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1473214863 }
....@@ -14982,7 +15113,8 @@
1498215113 // break;
1498315114 case 'T':
1498415115 CACHETEXTURE ^= true;
14985
- textures.clear();
15116
+ texturepigment.clear();
15117
+ texturebump.clear();
1498615118 // repaint();
1498715119 break;
1498815120 case 'Y':
....@@ -15067,7 +15199,9 @@
1506715199 case 'E' : COMPACT ^= true;
1506815200 repaint();
1506915201 break;
15070
- case 'W' : DEBUGHSB ^= true;
15202
+ case 'W' : // Wide Window (fullscreen)
15203
+ //DEBUGHSB ^= true;
15204
+ ObjEditor.theFrame.ToggleFullScreen();
1507115205 repaint();
1507215206 break;
1507315207 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -15093,13 +15227,7 @@
1509315227 repaint();
1509415228 break;
1509515229 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':
15230
+ //case 'L':
1510315231 if (lightMode)
1510415232 {
1510515233 lightMode = false;
....@@ -15246,7 +15374,10 @@
1524615374 // kompactbit = 6;
1524715375 // break;
1524815376 case ' ':
15249
- ObjEditor.theFrame.ToggleFullScreen();
15377
+ lightMode ^= true;
15378
+ Globals.lighttouched = true;
15379
+ manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
15380
+ targetLookAt.set(manipCamera.lookAt);
1525015381 repaint();
1525115382 break;
1525215383 //case '`' :
....@@ -15295,12 +15426,6 @@
1529515426 break;
1529615427 case '+':
1529715428
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
-
1530415429 /*
1530515430 //fontsize += 1;
1530615431 bbzoom *= 2;
....@@ -15318,17 +15443,17 @@
1531815443 case '=':
1531915444 IncDepth();
1532015445 //fontsize += 1;
15321
- object.editWindow.refreshContents(true);
15446
+ object.GetWindow().refreshContents(true);
1532215447 maskbit = 6;
1532315448 break;
1532415449 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1532515450 DecDepth();
1532615451 maskbit = 5;
1532715452 //if(fontsize > 1) fontsize -= 1;
15328
- if (object.editWindow == null)
15329
- new Exception().printStackTrace();
15330
- else
15331
- object.editWindow.refreshContents(true);
15453
+// if (object.editWindow == null)
15454
+// new Exception().printStackTrace();
15455
+// else
15456
+ object.GetWindow().refreshContents(true);
1533215457 break;
1533315458 case '{':
1533415459 manipCamera.shaper_fovy /= 1.1;
....@@ -15552,7 +15677,7 @@
1555215677 }
1555315678 */
1555415679
15555
- object.editWindow.EditSelection(false);
15680
+ object.GetWindow().EditSelection(false);
1555615681 }
1555715682
1555815683 void SelectParent()
....@@ -15569,10 +15694,10 @@
1556915694 {
1557015695 //selectees.remove(i);
1557115696 System.out.println("select parent of " + elem);
15572
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15697
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1557315698 } else
1557415699 {
15575
- group.editWindow.Select(elem.GetTreePath(), first, true);
15700
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1557615701 }
1557715702
1557815703 first = false;
....@@ -15614,12 +15739,12 @@
1561415739 for (int j = 0; j < group.children.size(); j++)
1561515740 {
1561615741 elem = (Object3D) group.children.elementAt(j);
15617
- object.editWindow.Select(elem.GetTreePath(), first, true);
15742
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1561815743 first = false;
1561915744 }
1562015745 } else
1562115746 {
15622
- object.editWindow.Select(elem.GetTreePath(), first, true);
15747
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1562315748 }
1562415749
1562515750 first = false;
....@@ -15630,21 +15755,21 @@
1563015755 {
1563115756 //Composite group = (Composite) object;
1563215757 Object3D group = object;
15633
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15758
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1563415759 }
1563515760
1563615761 void ResetTransform(int mask)
1563715762 {
1563815763 //Composite group = (Composite) object;
1563915764 Object3D group = object;
15640
- group.editWindow.ResetTransform(mask);
15765
+ group.GetWindow().ResetTransform(mask);
1564115766 }
1564215767
1564315768 void FlipTransform()
1564415769 {
1564515770 //Composite group = (Composite) object;
1564615771 Object3D group = object;
15647
- group.editWindow.FlipTransform();
15772
+ group.GetWindow().FlipTransform();
1564815773 // group.editWindow.ReduceMesh(true);
1564915774 }
1565015775
....@@ -15652,7 +15777,7 @@
1565215777 {
1565315778 //Composite group = (Composite) object;
1565415779 Object3D group = object;
15655
- group.editWindow.PrintMemory();
15780
+ group.GetWindow().PrintMemory();
1565615781 // group.editWindow.ReduceMesh(true);
1565715782 }
1565815783
....@@ -15660,7 +15785,7 @@
1566015785 {
1566115786 //Composite group = (Composite) object;
1566215787 Object3D group = object;
15663
- group.editWindow.ResetCentroid();
15788
+ group.GetWindow().ResetCentroid();
1566415789 }
1566515790
1566615791 void IncDepth()
....@@ -15742,8 +15867,6 @@
1574215867
1574315868 int width = getBounds().width;
1574415869 int height = getBounds().height;
15745
- ClickInfo info = new ClickInfo();
15746
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1574715870 //Image img = CreateImage(width, height);
1574815871 //System.out.println("width = " + width + "; height = " + height + "\n");
1574915872
....@@ -15820,48 +15943,77 @@
1582015943 }
1582115944 if (object != null && !hasMarquee)
1582215945 {
15946
+ if (object.clickInfo == null)
15947
+ object.clickInfo = new ClickInfo();
15948
+ ClickInfo info = object.clickInfo;
15949
+ //ClickInfo info = new ClickInfo();
15950
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
15951
+
1582315952 if (isRenderer)
1582415953 {
15825
- info.flags++;
15954
+ object.clickInfo.flags++;
1582615955 double frameAspect = (double) width / (double) height;
1582715956 if (frameAspect > renderCamera.aspect)
1582815957 {
1582915958 int desired = (int) ((double) height * renderCamera.aspect);
15830
- info.bounds.width -= width - desired;
15831
- info.bounds.x += (width - desired) / 2;
15959
+ object.clickInfo.bounds.width -= width - desired;
15960
+ object.clickInfo.bounds.x += (width - desired) / 2;
1583215961 } else
1583315962 {
1583415963 int desired = (int) ((double) width / renderCamera.aspect);
15835
- info.bounds.height -= height - desired;
15836
- info.bounds.y += (height - desired) / 2;
15964
+ object.clickInfo.bounds.height -= height - desired;
15965
+ object.clickInfo.bounds.y += (height - desired) / 2;
1583715966 }
1583815967 }
15839
- info.g = gr;
15840
- info.camera = renderCamera;
15968
+
15969
+ object.clickInfo.g = gr;
15970
+ object.clickInfo.camera = renderCamera;
1584115971 /*
1584215972 // Memory intensive (brep.verticescopy)
1584315973 if (!(object instanceof Composite))
1584415974 object.draw(info, 0, false); // SLOW :
1584515975 */
15846
- if (!isRenderer)
15976
+ if (!isRenderer) // && drag)
1584715977 {
15848
- object.drawEditHandles(info, 0);
15849
-
15850
- if (drag && (X != 0 || Y != 0) && object.selection.Size() > 0)
15978
+ Grafreed.Assert(object != null);
15979
+ Grafreed.Assert(object.selection != null);
15980
+ if (object.selection.Size() > 0)
1585115981 {
15852
- switch (object.selection.get(0).hitSomething)
15982
+ int hitSomething = object.selection.get(0).hitSomething;
15983
+
15984
+ object.clickInfo.DX = 0;
15985
+ object.clickInfo.DY = 0;
15986
+ object.clickInfo.W = 1;
15987
+ if (hitSomething == Object3D.hitCenter)
1585315988 {
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;
15989
+ info.DX = X;
15990
+ if (X != 0)
15991
+ info.DX -= info.bounds.width/2;
15992
+
15993
+ info.DY = Y;
15994
+ if (Y != 0)
15995
+ info.DY -= info.bounds.height/2;
1586315996 }
15864
-
15997
+
15998
+ object.drawEditHandles(//info,
15999
+ 0);
16000
+
16001
+ if (drag && (X != 0 || Y != 0))
16002
+ {
16003
+ switch (hitSomething)
16004
+ {
16005
+ case Object3D.hitCenter: gr.setColor(Color.pink);
16006
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16007
+ break;
16008
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16009
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16010
+ break;
16011
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16012
+ gr.drawLine(X, Y, 0, 0);
16013
+ break;
16014
+ }
16015
+
16016
+ }
1586516017 }
1586616018 }
1586716019 }
....@@ -16659,6 +16811,14 @@
1665916811 }
1666016812 }
1666116813
16814
+ private Object3D GetFolder()
16815
+ {
16816
+ Object3D folder = object.GetWindow().copy;
16817
+ if (object.GetWindow().copy.selection.Size() > 0)
16818
+ folder = object.GetWindow().copy.selection.elementAt(0);
16819
+ return folder;
16820
+ }
16821
+
1666216822 class SelectBuffer implements GLEventListener
1666316823 {
1666416824
....@@ -16738,6 +16898,17 @@
1673816898
1673916899 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1674016900
16901
+ if (PAINTMODE)
16902
+ {
16903
+ if (object.GetWindow().copy.selection.Size() > 0)
16904
+ {
16905
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16906
+
16907
+ // Make what you paint not selectable.
16908
+ paintobj.ResetSelectable();
16909
+ }
16910
+ }
16911
+
1674116912 //int tmp = selection_view;
1674216913 //selection_view = -1;
1674316914 int temp = DrawMode();
....@@ -16749,6 +16920,17 @@
1674916920 // temp = DEFAULT; // patch for selection debug
1675016921 Globals.drawMode = temp; // WARNING
1675116922
16923
+ if (PAINTMODE)
16924
+ {
16925
+ if (object.GetWindow().copy.selection.Size() > 0)
16926
+ {
16927
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16928
+
16929
+ // Revert.
16930
+ paintobj.RestoreSelectable();
16931
+ }
16932
+ }
16933
+
1675216934 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1675316935
1675416936 // trying different ways of getting the depth info over
....@@ -16852,29 +17034,31 @@
1685217034 }
1685317035
1685417036 if (!movingcamera && !PAINTMODE)
16855
- object.editWindow.ScreenFitPoint(); // fev 2014
17037
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1685617038
16857
- if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17039
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1685817040 {
16859
- Object3D paintobj = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17041
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1686017042
16861
- Object3D group = new Object3D("inst" + paintcount++);
17043
+ if (object.GetWindow().copy.selection.Size() > 0)
17044
+ {
17045
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1686217046
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();
17047
+ Object3D inst = new Object3D("inst" + paintcount++);
17048
+
17049
+ inst.CreateMaterial(); // use a void leaf to select instances
17050
+
17051
+ inst.add(paintobj); // link
17052
+
17053
+ object.GetWindow().SnapObject(inst);
17054
+
17055
+ Object3D folder = paintFolder; // GetFolder();
17056
+
17057
+ folder.add(inst);
17058
+
17059
+ object.GetWindow().ResetModel();
17060
+ object.GetWindow().refreshContents();
17061
+ }
1687817062 }
1687917063 else
1688017064 paintcount = 0;