Normand Briere
2019-07-23 de4f66e0239a736bce24e09c9a0b49b5bb92d84b
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,51 @@
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, 3.0 };" +
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
+ "MUL temp, temp, ndotl.x;" +
12437
+
12438
+ "MUL temp, temp, zero123.z;" +
12439
+
12440
+ "MOV temp.w, zero123.y;" + // reset alpha
12441
+
12442
+ "MOV result.color, temp;" +
12443
+ "END";
12444
+
12445
+ String program2 =
12446
+ "!!ARBfp1.0\n" +
12447
+
1232312448 //"OPTION ARB_fragment_program_shadow;" +
1232412449 "PARAM light2cam0 = program.env[10];" +
1232512450 "PARAM light2cam1 = program.env[11];" +
....@@ -12434,8 +12559,7 @@
1243412559 "TEMP shininess;" +
1243512560 "\n" +
1243612561 "MOV texSamp, one;" +
12437
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12438
-
12562
+
1243912563 "MOV mapgrid.x, one2048th.x;" +
1244012564 "MOV temp, fragment.texcoord[1];" +
1244112565 /*
....@@ -12840,7 +12964,7 @@
1284012964 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1284112965 "") +
1284212966
12843
- // display shadow only (bump == 0)
12967
+ // display shadow only (fakedepth == 0)
1284412968 "SUB temp.x, half.x, shadow.x;" +
1284512969 "MOV temp.y, -params5.z;" + // params6.x;" +
1284612970 "SLT temp.z, temp.y, -one2048th.x;" +
....@@ -13332,7 +13456,7 @@
1333213456 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1333313457 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1333413458
13335
- // No shadow when out of frustrum
13459
+ // No shadow when out of frustum
1333613460 "SGE temp.x, " + depth + ".z, one.z;" +
1333713461 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1333813462 "";
....@@ -14065,7 +14189,7 @@
1406514189
1406614190 // fev 2014???
1406714191 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
14068
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14192
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1406914193 pingthread.StepToTarget(true); // true);
1407014194 }
1407114195 // if (!LIVE)
....@@ -14419,12 +14543,12 @@
1441914543 void GoDown(int mod)
1442014544 {
1442114545 MODIFIERS |= COMMAND;
14422
- /*
14546
+ /**/
1442314547 if((mod&SHIFT) == SHIFT)
1442414548 manipCamera.RotatePosition(0, -speed);
1442514549 else
14426
- manipCamera.BackForth(0, -speed*delta, getWidth());
14427
- */
14550
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14551
+ /**/
1442814552 if ((mod & SHIFT) == SHIFT)
1442914553 {
1443014554 mouseMode = mouseMode; // VR??
....@@ -14440,12 +14564,12 @@
1444014564 void GoUp(int mod)
1444114565 {
1444214566 MODIFIERS |= COMMAND;
14443
- /*
14567
+ /**/
1444414568 if((mod&SHIFT) == SHIFT)
1444514569 manipCamera.RotatePosition(0, speed);
1444614570 else
14447
- manipCamera.BackForth(0, speed*delta, getWidth());
14448
- */
14571
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14572
+ /**/
1444914573 if ((mod & SHIFT) == SHIFT)
1445014574 {
1445114575 mouseMode = mouseMode;
....@@ -14461,12 +14585,12 @@
1446114585 void GoLeft(int mod)
1446214586 {
1446314587 MODIFIERS |= COMMAND;
14464
- /*
14588
+ /**/
1446514589 if((mod&SHIFT) == SHIFT)
14466
- manipCamera.RotatePosition(speed, 0);
14467
- else
1446814590 manipCamera.Translate(speed*delta, 0, getWidth());
14469
- */
14591
+ else
14592
+ manipCamera.RotatePosition(speed, 0);
14593
+ /**/
1447014594 if ((mod & SHIFT) == SHIFT)
1447114595 {
1447214596 mouseMode = mouseMode;
....@@ -14482,12 +14606,12 @@
1448214606 void GoRight(int mod)
1448314607 {
1448414608 MODIFIERS |= COMMAND;
14485
- /*
14609
+ /**/
1448614610 if((mod&SHIFT) == SHIFT)
14487
- manipCamera.RotatePosition(-speed, 0);
14488
- else
1448914611 manipCamera.Translate(-speed*delta, 0, getWidth());
14490
- */
14612
+ else
14613
+ manipCamera.RotatePosition(-speed, 0);
14614
+ /**/
1449114615 if ((mod & SHIFT) == SHIFT)
1449214616 {
1449314617 mouseMode = mouseMode;
....@@ -14726,7 +14850,8 @@
1472614850 Globals.MOUSEDRAGGED = false;
1472714851
1472814852 movingcamera = false;
14729
- X = Y = 0;
14853
+ X = 0; // getBounds().width/2;
14854
+ Y = 0; // getBounds().height/2;
1473014855 //System.out.println("mouseReleased: " + e);
1473114856 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1473214857 }
....@@ -14982,7 +15107,8 @@
1498215107 // break;
1498315108 case 'T':
1498415109 CACHETEXTURE ^= true;
14985
- textures.clear();
15110
+ texturepigment.clear();
15111
+ texturebump.clear();
1498615112 // repaint();
1498715113 break;
1498815114 case 'Y':
....@@ -15067,7 +15193,9 @@
1506715193 case 'E' : COMPACT ^= true;
1506815194 repaint();
1506915195 break;
15070
- case 'W' : DEBUGHSB ^= true;
15196
+ case 'W' : // Wide Window (fullscreen)
15197
+ //DEBUGHSB ^= true;
15198
+ ObjEditor.theFrame.ToggleFullScreen();
1507115199 repaint();
1507215200 break;
1507315201 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -15093,13 +15221,7 @@
1509315221 repaint();
1509415222 break;
1509515223 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':
15224
+ //case 'L':
1510315225 if (lightMode)
1510415226 {
1510515227 lightMode = false;
....@@ -15246,7 +15368,10 @@
1524615368 // kompactbit = 6;
1524715369 // break;
1524815370 case ' ':
15249
- ObjEditor.theFrame.ToggleFullScreen();
15371
+ lightMode ^= true;
15372
+ Globals.lighttouched = true;
15373
+ manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
15374
+ targetLookAt.set(manipCamera.lookAt);
1525015375 repaint();
1525115376 break;
1525215377 //case '`' :
....@@ -15295,12 +15420,6 @@
1529515420 break;
1529615421 case '+':
1529715422
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
-
1530415423 /*
1530515424 //fontsize += 1;
1530615425 bbzoom *= 2;
....@@ -15318,17 +15437,17 @@
1531815437 case '=':
1531915438 IncDepth();
1532015439 //fontsize += 1;
15321
- object.editWindow.refreshContents(true);
15440
+ object.GetWindow().refreshContents(true);
1532215441 maskbit = 6;
1532315442 break;
1532415443 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1532515444 DecDepth();
1532615445 maskbit = 5;
1532715446 //if(fontsize > 1) fontsize -= 1;
15328
- if (object.editWindow == null)
15329
- new Exception().printStackTrace();
15330
- else
15331
- object.editWindow.refreshContents(true);
15447
+// if (object.editWindow == null)
15448
+// new Exception().printStackTrace();
15449
+// else
15450
+ object.GetWindow().refreshContents(true);
1533215451 break;
1533315452 case '{':
1533415453 manipCamera.shaper_fovy /= 1.1;
....@@ -15552,7 +15671,7 @@
1555215671 }
1555315672 */
1555415673
15555
- object.editWindow.EditSelection(false);
15674
+ object.GetWindow().EditSelection(false);
1555615675 }
1555715676
1555815677 void SelectParent()
....@@ -15569,10 +15688,10 @@
1556915688 {
1557015689 //selectees.remove(i);
1557115690 System.out.println("select parent of " + elem);
15572
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15691
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1557315692 } else
1557415693 {
15575
- group.editWindow.Select(elem.GetTreePath(), first, true);
15694
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1557615695 }
1557715696
1557815697 first = false;
....@@ -15614,12 +15733,12 @@
1561415733 for (int j = 0; j < group.children.size(); j++)
1561515734 {
1561615735 elem = (Object3D) group.children.elementAt(j);
15617
- object.editWindow.Select(elem.GetTreePath(), first, true);
15736
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1561815737 first = false;
1561915738 }
1562015739 } else
1562115740 {
15622
- object.editWindow.Select(elem.GetTreePath(), first, true);
15741
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1562315742 }
1562415743
1562515744 first = false;
....@@ -15630,21 +15749,21 @@
1563015749 {
1563115750 //Composite group = (Composite) object;
1563215751 Object3D group = object;
15633
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15752
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1563415753 }
1563515754
1563615755 void ResetTransform(int mask)
1563715756 {
1563815757 //Composite group = (Composite) object;
1563915758 Object3D group = object;
15640
- group.editWindow.ResetTransform(mask);
15759
+ group.GetWindow().ResetTransform(mask);
1564115760 }
1564215761
1564315762 void FlipTransform()
1564415763 {
1564515764 //Composite group = (Composite) object;
1564615765 Object3D group = object;
15647
- group.editWindow.FlipTransform();
15766
+ group.GetWindow().FlipTransform();
1564815767 // group.editWindow.ReduceMesh(true);
1564915768 }
1565015769
....@@ -15652,7 +15771,7 @@
1565215771 {
1565315772 //Composite group = (Composite) object;
1565415773 Object3D group = object;
15655
- group.editWindow.PrintMemory();
15774
+ group.GetWindow().PrintMemory();
1565615775 // group.editWindow.ReduceMesh(true);
1565715776 }
1565815777
....@@ -15660,7 +15779,7 @@
1566015779 {
1566115780 //Composite group = (Composite) object;
1566215781 Object3D group = object;
15663
- group.editWindow.ResetCentroid();
15782
+ group.GetWindow().ResetCentroid();
1566415783 }
1566515784
1566615785 void IncDepth()
....@@ -15836,6 +15955,7 @@
1583615955 info.bounds.y += (height - desired) / 2;
1583715956 }
1583815957 }
15958
+
1583915959 info.g = gr;
1584015960 info.camera = renderCamera;
1584115961 /*
....@@ -15845,23 +15965,44 @@
1584515965 */
1584615966 if (!isRenderer)
1584715967 {
15848
- object.drawEditHandles(info, 0);
15849
-
15850
- if (drag && (X != 0 || Y != 0) && object.selection.Size() > 0)
15968
+ Grafreed.Assert(object != null);
15969
+ Grafreed.Assert(object.selection != null);
15970
+ if (object.selection.Size() > 0)
1585115971 {
15852
- switch (object.selection.get(0).hitSomething)
15972
+ int hitSomething = object.selection.get(0).hitSomething;
15973
+
15974
+ info.DX = 0;
15975
+ info.DY = 0;
15976
+ info.W = 1;
15977
+ if (hitSomething == Object3D.hitCenter)
1585315978 {
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;
15979
+ info.DX = X;
15980
+ if (X != 0)
15981
+ info.DX -= info.bounds.width/2;
15982
+
15983
+ info.DY = Y;
15984
+ if (Y != 0)
15985
+ info.DY -= info.bounds.height/2;
1586315986 }
15864
-
15987
+
15988
+ object.drawEditHandles(info, 0);
15989
+
15990
+ if (drag && (X != 0 || Y != 0))
15991
+ {
15992
+ switch (hitSomething)
15993
+ {
15994
+ case Object3D.hitCenter: gr.setColor(Color.pink);
15995
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15996
+ break;
15997
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
15998
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15999
+ break;
16000
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16001
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16002
+ break;
16003
+ }
16004
+
16005
+ }
1586516006 }
1586616007 }
1586716008 }
....@@ -16659,6 +16800,14 @@
1665916800 }
1666016801 }
1666116802
16803
+ private Object3D GetFolder()
16804
+ {
16805
+ Object3D folder = object.GetWindow().copy;
16806
+ if (object.GetWindow().copy.selection.Size() > 0)
16807
+ folder = object.GetWindow().copy.selection.elementAt(0);
16808
+ return folder;
16809
+ }
16810
+
1666216811 class SelectBuffer implements GLEventListener
1666316812 {
1666416813
....@@ -16738,6 +16887,17 @@
1673816887
1673916888 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1674016889
16890
+ if (PAINTMODE)
16891
+ {
16892
+ if (object.GetWindow().copy.selection.Size() > 0)
16893
+ {
16894
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16895
+
16896
+ // Make what you paint not selectable.
16897
+ paintobj.ResetSelectable();
16898
+ }
16899
+ }
16900
+
1674116901 //int tmp = selection_view;
1674216902 //selection_view = -1;
1674316903 int temp = DrawMode();
....@@ -16749,6 +16909,17 @@
1674916909 // temp = DEFAULT; // patch for selection debug
1675016910 Globals.drawMode = temp; // WARNING
1675116911
16912
+ if (PAINTMODE)
16913
+ {
16914
+ if (object.GetWindow().copy.selection.Size() > 0)
16915
+ {
16916
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16917
+
16918
+ // Revert.
16919
+ paintobj.RestoreSelectable();
16920
+ }
16921
+ }
16922
+
1675216923 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1675316924
1675416925 // trying different ways of getting the depth info over
....@@ -16852,29 +17023,31 @@
1685217023 }
1685317024
1685417025 if (!movingcamera && !PAINTMODE)
16855
- object.editWindow.ScreenFitPoint(); // fev 2014
17026
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1685617027
16857
- if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17028
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1685817029 {
16859
- Object3D paintobj = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17030
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1686017031
16861
- Object3D group = new Object3D("inst" + paintcount++);
17032
+ if (object.GetWindow().copy.selection.Size() > 0)
17033
+ {
17034
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1686217035
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();
17036
+ Object3D inst = new Object3D("inst" + paintcount++);
17037
+
17038
+ inst.CreateMaterial(); // use a void leaf to select instances
17039
+
17040
+ inst.add(paintobj); // link
17041
+
17042
+ object.GetWindow().SnapObject(inst);
17043
+
17044
+ Object3D folder = paintFolder; // GetFolder();
17045
+
17046
+ folder.add(inst);
17047
+
17048
+ object.GetWindow().ResetModel();
17049
+ object.GetWindow().refreshContents();
17050
+ }
1687817051 }
1687917052 else
1688017053 paintcount = 0;