Normand Briere
2019-07-22 c570e1e38f2ff8622a71f81436654bad01cfdd5b
CameraPane.java
....@@ -45,6 +45,39 @@
4545
4646 static int STEP = 1;
4747
48
+ private static BufferedImage CreateBim(byte[] bytes, int width, int height)
49
+ {
50
+ int[] pixels = new int[bytes.length/3];
51
+ for (int i=pixels.length; --i>=0;)
52
+ {
53
+ int i3 = i*3;
54
+ pixels[i] = 0xFF;
55
+ pixels[i] <<= 8;
56
+ pixels[i] |= bytes[i3+2] & 0xFF;
57
+ pixels[i] <<= 8;
58
+ pixels[i] |= bytes[i3+1] & 0xFF;
59
+ pixels[i] <<= 8;
60
+ pixels[i] |= bytes[i3] & 0xFF;
61
+ }
62
+ /*
63
+ int r=0,g=0,b=0,a=0;
64
+ for (int i=0; i<width; i++)
65
+ for (int j=0; j<height; j++)
66
+ {
67
+ int index = j*width+i;
68
+ int p = pixels[index];
69
+ a = ((p>>24) & 0xFF);
70
+ r = ((p>>16) & 0xFF);
71
+ g = ((p>>8) & 0xFF);
72
+ b = (p & 0xFF);
73
+ pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
74
+ }
75
+ /**/
76
+ BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
77
+ rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
78
+ return rendImage;
79
+ }
80
+
4881 /*static*/ private boolean CULLFACE = false; // true;
4982 /*static*/ boolean NEAREST = false; // true;
5083 /*static*/ boolean WIREFRAME = false; // true;
....@@ -60,7 +93,7 @@
6093 //boolean REDUCETEXTURE = true;
6194 boolean CACHETEXTURE = true;
6295 boolean CLEANCACHE = false; // true;
63
- boolean MIPMAP = false; // true;
96
+ boolean MIPMAP = true; // false; // true;
6497 boolean COMPRESSTEXTURE = false;
6598 boolean KOMPACTTEXTURE = false; // true;
6699 boolean RESIZETEXTURE = false;
....@@ -2298,10 +2331,17 @@
22982331 HANDLES ^= true;
22992332 }
23002333
2334
+ Object3D paintFolder;
2335
+
23012336 void TogglePaint()
23022337 {
23032338 PAINTMODE ^= true;
23042339 paintcount = 0;
2340
+
2341
+ if (PAINTMODE)
2342
+ {
2343
+ paintFolder = GetFolder();
2344
+ }
23052345 }
23062346
23072347 void SwapCamera(int a, int b)
....@@ -2398,6 +2438,21 @@
23982438 return currentGL;
23992439 }
24002440
2441
+ static private BufferedImage CreateBim(TextureData texturedata)
2442
+ {
2443
+ Grafreed.Assert(texturedata != null);
2444
+
2445
+ int width = texturedata.getWidth();
2446
+ int height = texturedata.getHeight();
2447
+
2448
+ Buffer buffer = texturedata.getBuffer();
2449
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2450
+
2451
+ byte[] bytes = bytebuf.array();
2452
+
2453
+ return CreateBim(bytes, width, height);
2454
+ }
2455
+
24012456 /**/
24022457 class CacheTexture
24032458 {
....@@ -2406,28 +2461,31 @@
24062461
24072462 int resolution;
24082463
2409
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2464
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
24102465 {
2411
- texture = tex;
2466
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2467
+ texturedata = texdata;
24122468 resolution = res;
24132469 }
24142470 }
24152471 /**/
24162472
24172473 // TEXTURE static Texture texture;
2418
- static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures
2419
- = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>();
2420
- static public java.util.Hashtable<String, String> usedtextures = new java.util.Hashtable<String, String>();
2474
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2475
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2476
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2477
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2478
+
24212479 int pigmentdepth = 0;
24222480 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
24232481 int bumpdepth = 0;
24242482 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
24252483 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
24262484 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2427
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2485
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
24282486 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
24292487
2430
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2488
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
24312489 {
24322490 TextureData texturedata = null;
24332491
....@@ -2446,13 +2504,34 @@
24462504 if (bump)
24472505 texturedata = ConvertBump(texturedata, false);
24482506
2449
- com.sun.opengl.util.texture.Texture texture =
2450
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2507
+// com.sun.opengl.util.texture.Texture texture =
2508
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
24512509
2452
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2453
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
2510
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2511
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
24542512
2455
- return texture;
2513
+ return texturedata;
2514
+ }
2515
+
2516
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2517
+ {
2518
+ TextureData texturedata = null;
2519
+
2520
+ try
2521
+ {
2522
+ texturedata =
2523
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2524
+ bim,
2525
+ true);
2526
+ } catch (Exception e)
2527
+ {
2528
+ throw new javax.media.opengl.GLException(e);
2529
+ }
2530
+
2531
+ if (bump)
2532
+ texturedata = ConvertBump(texturedata, false);
2533
+
2534
+ return texturedata;
24562535 }
24572536
24582537 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3525,6 +3604,8 @@
35253604
35263605 System.out.println("LOADING TEXTURE : " + name);
35273606
3607
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3608
+
35283609 //
35293610 if (false) // compressbit > 0)
35303611 {
....@@ -7923,7 +8004,7 @@
79238004 String pigment = Object3D.GetPigment(tex);
79248005 String bump = Object3D.GetBump(tex);
79258006
7926
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8007
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79278008 {
79288009 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79298010 // System.out.println("; bump = " + bump);
....@@ -7938,8 +8019,8 @@
79388019 pigment = null;
79398020 }
79408021
7941
- ReleaseTexture(bump, true);
7942
- ReleaseTexture(pigment, false);
8022
+ ReleaseTexture(tex, true);
8023
+ ReleaseTexture(tex, false);
79438024 }
79448025
79458026 public void ReleasePigmentTexture(cTexture tex) // INTERFACE
....@@ -7957,7 +8038,7 @@
79578038
79588039 String pigment = Object3D.GetPigment(tex);
79598040
7960
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8041
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79618042 {
79628043 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79638044 // System.out.println("; bump = " + bump);
....@@ -7968,7 +8049,7 @@
79688049 pigment = null;
79698050 }
79708051
7971
- ReleaseTexture(pigment, false);
8052
+ ReleaseTexture(tex, false);
79728053 }
79738054
79748055 public void ReleaseBumpTexture(cTexture tex) // INTERFACE
....@@ -7986,7 +8067,7 @@
79868067
79878068 String bump = Object3D.GetBump(tex);
79888069
7989
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8070
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79908071 {
79918072 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79928073 // System.out.println("; bump = " + bump);
....@@ -7997,10 +8078,10 @@
79978078 bump = null;
79988079 }
79998080
8000
- ReleaseTexture(bump, true);
8081
+ ReleaseTexture(tex, true);
80018082 }
80028083
8003
- void ReleaseTexture(String tex, boolean bump)
8084
+ void ReleaseTexture(cTexture tex, boolean bump)
80048085 {
80058086 if (// DrawMode() != 0 || /*tex == null ||*/
80068087 ambientOcclusion ) // || !textureon)
....@@ -8011,7 +8092,7 @@
80118092 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
80128093
80138094 if (tex != null)
8014
- texture = textures.get(tex);
8095
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
80158096
80168097 // //assert( texture != null );
80178098 // if (texture == null)
....@@ -8105,47 +8186,50 @@
81058186
81068187 /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
81078188 {
8108
- if (// DrawMode() != 0 || /*tex == null ||*/
8109
- ambientOcclusion ) // || !textureon)
8110
- {
8111
- return; // false;
8112
- }
8113
-
8114
- if (tex == null)
8115
- {
8116
- BindTexture(null,false,resolution);
8117
- BindTexture(null,true,resolution);
8118
- return;
8119
- }
8189
+// if (// DrawMode() != 0 || /*tex == null ||*/
8190
+// ambientOcclusion ) // || !textureon)
8191
+// {
8192
+// return; // false;
8193
+// }
8194
+//
8195
+// if (tex == null)
8196
+// {
8197
+// BindTexture(null,false,resolution);
8198
+// BindTexture(null,true,resolution);
8199
+// return;
8200
+// }
8201
+//
8202
+// String pigment = Object3D.GetPigment(tex);
8203
+// String bump = Object3D.GetBump(tex);
8204
+//
8205
+// usedtextures.add(pigment);
8206
+// usedtextures.add(bump);
8207
+//
8208
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8209
+// {
8210
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8211
+// // System.out.println("; bump = " + bump);
8212
+// }
8213
+//
8214
+// if (bump.equals(""))
8215
+// {
8216
+// bump = null;
8217
+// }
8218
+// if (pigment.equals(""))
8219
+// {
8220
+// pigment = null;
8221
+// }
8222
+//
8223
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8224
+// BindTexture(pigment, false, resolution);
8225
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8226
+// BindTexture(bump, true, resolution);
8227
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8228
+//
8229
+// return; // true;
81208230
8121
- String pigment = Object3D.GetPigment(tex);
8122
- String bump = Object3D.GetBump(tex);
8123
-
8124
- usedtextures.put(pigment, pigment);
8125
- usedtextures.put(bump, bump);
8126
-
8127
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8128
- {
8129
- // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8130
- // System.out.println("; bump = " + bump);
8131
- }
8132
-
8133
- if (bump.equals(""))
8134
- {
8135
- bump = null;
8136
- }
8137
- if (pigment.equals(""))
8138
- {
8139
- pigment = null;
8140
- }
8141
-
8142
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8143
- BindTexture(pigment, false, resolution);
8144
- GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8145
- BindTexture(bump, true, resolution);
8146
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8147
-
8148
- return; // true;
8231
+ BindPigmentTexture(tex, resolution);
8232
+ BindBumpTexture(tex, resolution);
81498233 }
81508234
81518235 /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8164,9 +8248,9 @@
81648248
81658249 String pigment = Object3D.GetPigment(tex);
81668250
8167
- usedtextures.put(pigment, pigment);
8251
+ usedtextures.add(tex);
81688252
8169
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8253
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
81708254 {
81718255 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
81728256 // System.out.println("; bump = " + bump);
....@@ -8178,7 +8262,7 @@
81788262 }
81798263
81808264 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8181
- BindTexture(pigment, false, resolution);
8265
+ BindTexture(tex, false, resolution);
81828266 }
81838267
81848268 /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8197,9 +8281,9 @@
81978281
81988282 String bump = Object3D.GetBump(tex);
81998283
8200
- usedtextures.put(bump, bump);
8284
+ usedtextures.add(tex);
82018285
8202
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8286
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
82038287 {
82048288 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
82058289 // System.out.println("; bump = " + bump);
....@@ -8211,7 +8295,7 @@
82118295 }
82128296
82138297 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8214
- BindTexture(bump, true, resolution);
8298
+ BindTexture(tex, true, resolution);
82158299 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
82168300 }
82178301
....@@ -8235,13 +8319,19 @@
82358319 return fileExists;
82368320 }
82378321
8238
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception
8322
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
82398323 {
8240
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8324
+ CacheTexture texturecache = null;
82418325
82428326 if (tex != null)
82438327 {
8244
- String texname = tex;
8328
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8329
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
8330
+
8331
+ if (texname.equals("") && texdata == null)
8332
+ {
8333
+ return null;
8334
+ }
82458335
82468336 String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
82478337
....@@ -8251,19 +8341,34 @@
82518341 // else
82528342 // if (!texname.startsWith("/"))
82538343 // texname = "/Users/nbriere/Textures/" + texname;
8254
- if (!FileExists(tex))
8344
+ if (!FileExists(texname))
82558345 {
82568346 texname = fallbackTextureName;
82578347 }
82588348
82598349 if (CACHETEXTURE)
8260
- texture = textures.get(texname); // TEXTURE CACHE
8261
-
8262
- TextureData texturedata = null;
8263
-
8264
- if (texture == null || texture.resolution < resolution)
82658350 {
8266
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8351
+ if (texdata == null)
8352
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8353
+ else
8354
+ texturecache = bimtextures.get(texdata);
8355
+ }
8356
+
8357
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8358
+ {
8359
+ TextureData texturedata = null;
8360
+
8361
+ if (texdata != null)
8362
+ {
8363
+ BufferedImage bim = //new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8364
+
8365
+ CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8366
+
8367
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8368
+ bimtextures.put(texdata, texturecache);
8369
+ }
8370
+ else
8371
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
82678372 {
82688373 assert(!bump);
82698374 // if (bump)
....@@ -8274,19 +8379,23 @@
82748379 // }
82758380 // else
82768381 // {
8277
- texture = textures.get(tex);
8278
- if (texture == null)
8382
+ // texturecache = textures.get(texname); // suspicious
8383
+ if (texturecache == null)
82798384 {
8280
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8385
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
82818386 }
8387
+ else
8388
+ new Exception().printStackTrace();
82828389 // }
82838390 } else
8284
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8391
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
82858392 {
82868393 assert(bump);
8287
- texture = textures.get(tex);
8288
- if (texture == null)
8289
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8394
+ // texturecache = textures.get(texname); // suspicious
8395
+ if (texturecache == null)
8396
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8397
+ else
8398
+ new Exception().printStackTrace();
82908399 } else
82918400 {
82928401 //if (tex.equals("IMMORTAL"))
....@@ -8294,11 +8403,13 @@
82948403 // texture = GetResourceTexture("default.png");
82958404 //} else
82968405 //{
8297
- if (tex.equals("WHITE_NOISE"))
8406
+ if (texname.endsWith("WHITE_NOISE"))
82988407 {
8299
- texture = textures.get(tex);
8300
- if (texture == null)
8301
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8408
+ // texturecache = textures.get(texname); // suspicious
8409
+ if (texturecache == null)
8410
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8411
+ else
8412
+ new Exception().printStackTrace();
83028413 } else
83038414 {
83048415 if (textureon)
....@@ -8357,19 +8468,19 @@
83578468 if (texturedata == null)
83588469 throw new Exception();
83598470
8360
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8471
+ texturecache = new CacheTexture(texturedata,resolution);
83618472 //texture = GetTexture(tex, bump);
83628473 }
83638474 }
83648475 //}
83658476 }
83668477
8367
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8478
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
83688479 {
83698480 //return false;
83708481
83718482 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8372
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8483
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
83738484 {
83748485 // String ext = "_highres";
83758486 // if (REDUCETEXTURE)
....@@ -8386,52 +8497,17 @@
83868497 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
83878498 if (!cachefile.exists())
83888499 {
8389
- // cache to disk
8390
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
8391
- //buffers[0].
8392
-
8393
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
8394
- int[] pixels = new int[bytebuf.capacity()/3];
8395
-
8396
- // squared size heuristic...
8397
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8500
+ //if (texturedata.getWidth() == texturedata.getHeight())
83988501 {
8399
- for (int i=pixels.length; --i>=0;)
8400
- {
8401
- int i3 = i*3;
8402
- pixels[i] = 0xFF;
8403
- pixels[i] <<= 8;
8404
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
8405
- pixels[i] <<= 8;
8406
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
8407
- pixels[i] <<= 8;
8408
- pixels[i] |= bytebuf.get(i3) & 0xFF;
8409
- }
8410
-
8411
- /*
8412
- int r=0,g=0,b=0,a=0;
8413
- for (int i=0; i<width; i++)
8414
- for (int j=0; j<height; j++)
8415
- {
8416
- int index = j*width+i;
8417
- int p = pixels[index];
8418
- a = ((p>>24) & 0xFF);
8419
- r = ((p>>16) & 0xFF);
8420
- g = ((p>>8) & 0xFF);
8421
- b = (p & 0xFF);
8422
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
8423
- }
8424
- /**/
8425
- int width = (int)Math.sqrt(pixels.length); // squared
8426
- int height = width;
8427
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
8428
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8502
+ BufferedImage rendImage = CreateBim(texturedata);
8503
+
84298504 ImageWriter writer = null;
84308505 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
84318506 if (iter.hasNext()) {
84328507 writer = (ImageWriter)iter.next();
84338508 }
8434
- float compressionQuality = 0.9f;
8509
+
8510
+ float compressionQuality = 0.85f;
84358511 try
84368512 {
84378513 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8448,18 +8524,20 @@
84488524 }
84498525 }
84508526 }
8451
-
8527
+
8528
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8529
+
84528530 //System.out.println("Texture = " + tex);
8453
- if (textures.containsKey(texname))
8531
+ if (textures.containsKey(tex))
84548532 {
8455
- CacheTexture thetex = textures.get(texname);
8533
+ CacheTexture thetex = textures.get(tex);
84568534 thetex.texture.disable();
84578535 thetex.texture.dispose();
8458
- textures.remove(texname);
8536
+ textures.remove(tex);
84598537 }
84608538
8461
- texture.texturedata = texturedata;
8462
- textures.put(texname, texture);
8539
+ //texture.texturedata = texturedata;
8540
+ textures.put(tex, texturecache);
84638541
84648542 // newtex = true;
84658543 }
....@@ -8475,10 +8553,41 @@
84758553 }
84768554 }
84778555
8478
- return texture;
8556
+ return texturecache;
84798557 }
84808558
8481
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution) throws Exception
8559
+ static void EmbedTextures(cTexture tex)
8560
+ {
8561
+ if (tex.pigmentdata == null)
8562
+ {
8563
+ String texname = Object3D.GetPigment(tex);
8564
+
8565
+ CacheTexture texturecache = texturepigment.get(tex);
8566
+
8567
+ if (texturecache != null)
8568
+ {
8569
+ tex.pigmentdata = ((ByteBuffer)texturecache.texturedata.getBuffer()).array();
8570
+ tex.pw = texturecache.texturedata.getWidth();
8571
+ tex.ph = texturecache.texturedata.getHeight();
8572
+ }
8573
+ }
8574
+
8575
+ if (tex.bumpdata == null)
8576
+ {
8577
+ String texname = Object3D.GetBump(tex);
8578
+
8579
+ CacheTexture texturecache = texturebump.get(tex);
8580
+
8581
+ if (texturecache != null)
8582
+ {
8583
+ tex.bumpdata = ((ByteBuffer)texturecache.texturedata.getBuffer()).array();
8584
+ tex.bw = texturecache.texturedata.getWidth();
8585
+ tex.bh = texturecache.texturedata.getHeight();
8586
+ }
8587
+ }
8588
+ }
8589
+
8590
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
84828591 {
84838592 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
84848593
....@@ -8496,21 +8605,21 @@
84968605 return texture!=null?texture.texture:null;
84978606 }
84988607
8499
- public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution) throws Exception
8608
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
85008609 {
85018610 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
85028611
85038612 return texture!=null?texture.texturedata:null;
85048613 }
85058614
8506
- boolean BindTexture(String tex, boolean bump, int resolution) throws Exception
8615
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
85078616 {
85088617 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
85098618 {
85108619 return false;
85118620 }
85128621
8513
- boolean newtex = false;
8622
+ //boolean newtex = false;
85148623
85158624 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
85168625
....@@ -8542,7 +8651,7 @@
85428651 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
85438652 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
85448653
8545
- return newtex;
8654
+ return true; // Warning: not used.
85468655 }
85478656
85488657 ShadowBuffer shadowPBuf;
....@@ -11655,20 +11764,32 @@
1165511764 ReleaseTextures(DEFAULT_TEXTURES);
1165611765
1165711766 if (CLEANCACHE)
11658
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11767
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1165911768 {
11660
- String tex = e.nextElement();
11769
+ cTexture tex = e.nextElement();
1166111770
1166211771 // System.out.println("Texture --------- " + tex);
1166311772
11664
- if (tex.equals("WHITE_NOISE"))
11773
+ if (tex.equals("WHITE_NOISE:"))
1166511774 continue;
1166611775
11667
- if (!usedtextures.containsKey(tex))
11776
+ if (!usedtextures.contains(tex))
1166811777 {
11778
+ CacheTexture gettex = texturepigment.get(tex);
1166911779 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11670
- textures.get(tex).texture.dispose();
11671
- textures.remove(tex);
11780
+ if (gettex != null)
11781
+ {
11782
+ gettex.texture.dispose();
11783
+ texturepigment.remove(tex);
11784
+ }
11785
+
11786
+ gettex = texturebump.get(tex);
11787
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11788
+ if (gettex != null)
11789
+ {
11790
+ gettex.texture.dispose();
11791
+ texturebump.remove(tex);
11792
+ }
1167211793 }
1167311794 }
1167411795 }
....@@ -14861,7 +14982,8 @@
1486114982 // break;
1486214983 case 'T':
1486314984 CACHETEXTURE ^= true;
14864
- textures.clear();
14985
+ texturepigment.clear();
14986
+ texturebump.clear();
1486514987 // repaint();
1486614988 break;
1486714989 case 'Y':
....@@ -16553,6 +16675,14 @@
1655316675 }
1655416676 }
1655516677
16678
+ private Object3D GetFolder()
16679
+ {
16680
+ Object3D folder = object.GetWindow().copy;
16681
+ if (object.GetWindow().copy.selection.Size() > 0)
16682
+ folder = object.GetWindow().copy.selection.elementAt(0);
16683
+ return folder;
16684
+ }
16685
+
1655616686 class SelectBuffer implements GLEventListener
1655716687 {
1655816688
....@@ -16632,6 +16762,17 @@
1663216762
1663316763 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1663416764
16765
+ if (PAINTMODE)
16766
+ {
16767
+ if (object.GetWindow().copy.selection.Size() > 0)
16768
+ {
16769
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16770
+
16771
+ // Make what you paint not selectable.
16772
+ paintobj.ResetSelectable();
16773
+ }
16774
+ }
16775
+
1663516776 //int tmp = selection_view;
1663616777 //selection_view = -1;
1663716778 int temp = DrawMode();
....@@ -16643,6 +16784,17 @@
1664316784 // temp = DEFAULT; // patch for selection debug
1664416785 Globals.drawMode = temp; // WARNING
1664516786
16787
+ if (PAINTMODE)
16788
+ {
16789
+ if (object.GetWindow().copy.selection.Size() > 0)
16790
+ {
16791
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16792
+
16793
+ // Revert.
16794
+ paintobj.RestoreSelectable();
16795
+ }
16796
+ }
16797
+
1664616798 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1664716799
1664816800 // trying different ways of getting the depth info over
....@@ -16748,27 +16900,29 @@
1674816900 if (!movingcamera && !PAINTMODE)
1674916901 object.GetWindow().ScreenFitPoint(); // fev 2014
1675016902
16751
- if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
16903
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1675216904 {
16753
- Object3D paintobj = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
16754
-
16755
- Object3D group = new Object3D("inst" + paintcount++);
16756
-
16757
- group.CreateMaterial(); // use a void leaf to select instances
16758
-
16759
- group.add(paintobj); // link
16760
-
16761
- object.GetWindow().SnapObject(group);
16762
-
16763
- Object3D folder = object.GetWindow().copy;
16905
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1676416906
1676516907 if (object.GetWindow().copy.selection.Size() > 0)
16766
- folder = object.GetWindow().copy.selection.elementAt(0);
16908
+ {
16909
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1676716910
16768
- folder.add(group);
16769
-
16770
- object.GetWindow().ResetModel();
16771
- object.GetWindow().refreshContents();
16911
+ Object3D inst = new Object3D("inst" + paintcount++);
16912
+
16913
+ inst.CreateMaterial(); // use a void leaf to select instances
16914
+
16915
+ inst.add(paintobj); // link
16916
+
16917
+ object.GetWindow().SnapObject(inst);
16918
+
16919
+ Object3D folder = paintFolder; // GetFolder();
16920
+
16921
+ folder.add(inst);
16922
+
16923
+ object.GetWindow().ResetModel();
16924
+ object.GetWindow().refreshContents();
16925
+ }
1677216926 }
1677316927 else
1677416928 paintcount = 0;