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;
....@@ -11028,9 +11137,9 @@
1102811137
1102911138 gl.glMatrixMode(GL.GL_MODELVIEW);
1103011139
11031
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11032
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
11033
-//gl.glEnable(gl.GL_MULTISAMPLE);
11140
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11141
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11142
+gl.glEnable(gl.GL_MULTISAMPLE);
1103411143 } else
1103511144 {
1103611145 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -11041,7 +11150,7 @@
1104111150 //System.out.println("BLENDING ON");
1104211151 gl.glEnable(GL.GL_BLEND);
1104311152 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
11044
-
11153
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1104511154 gl.glMatrixMode(gl.GL_PROJECTION);
1104611155 gl.glLoadIdentity();
1104711156
....@@ -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 }
....@@ -14297,12 +14418,12 @@
1429714418 void GoDown(int mod)
1429814419 {
1429914420 MODIFIERS |= COMMAND;
14300
- /*
14421
+ /**/
1430114422 if((mod&SHIFT) == SHIFT)
1430214423 manipCamera.RotatePosition(0, -speed);
1430314424 else
14304
- manipCamera.BackForth(0, -speed*delta, getWidth());
14305
- */
14425
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14426
+ /**/
1430614427 if ((mod & SHIFT) == SHIFT)
1430714428 {
1430814429 mouseMode = mouseMode; // VR??
....@@ -14318,12 +14439,12 @@
1431814439 void GoUp(int mod)
1431914440 {
1432014441 MODIFIERS |= COMMAND;
14321
- /*
14442
+ /**/
1432214443 if((mod&SHIFT) == SHIFT)
1432314444 manipCamera.RotatePosition(0, speed);
1432414445 else
14325
- manipCamera.BackForth(0, speed*delta, getWidth());
14326
- */
14446
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14447
+ /**/
1432714448 if ((mod & SHIFT) == SHIFT)
1432814449 {
1432914450 mouseMode = mouseMode;
....@@ -14339,12 +14460,12 @@
1433914460 void GoLeft(int mod)
1434014461 {
1434114462 MODIFIERS |= COMMAND;
14342
- /*
14463
+ /**/
1434314464 if((mod&SHIFT) == SHIFT)
14344
- manipCamera.RotatePosition(speed, 0);
14345
- else
1434614465 manipCamera.Translate(speed*delta, 0, getWidth());
14347
- */
14466
+ else
14467
+ manipCamera.RotatePosition(speed, 0);
14468
+ /**/
1434814469 if ((mod & SHIFT) == SHIFT)
1434914470 {
1435014471 mouseMode = mouseMode;
....@@ -14360,12 +14481,12 @@
1436014481 void GoRight(int mod)
1436114482 {
1436214483 MODIFIERS |= COMMAND;
14363
- /*
14484
+ /**/
1436414485 if((mod&SHIFT) == SHIFT)
14365
- manipCamera.RotatePosition(-speed, 0);
14366
- else
1436714486 manipCamera.Translate(-speed*delta, 0, getWidth());
14368
- */
14487
+ else
14488
+ manipCamera.RotatePosition(-speed, 0);
14489
+ /**/
1436914490 if ((mod & SHIFT) == SHIFT)
1437014491 {
1437114492 mouseMode = mouseMode;
....@@ -14604,7 +14725,8 @@
1460414725 Globals.MOUSEDRAGGED = false;
1460514726
1460614727 movingcamera = false;
14607
- X = Y = 0;
14728
+ X = 0; // getBounds().width/2;
14729
+ Y = 0; // getBounds().height/2;
1460814730 //System.out.println("mouseReleased: " + e);
1460914731 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1461014732 }
....@@ -14860,7 +14982,8 @@
1486014982 // break;
1486114983 case 'T':
1486214984 CACHETEXTURE ^= true;
14863
- textures.clear();
14985
+ texturepigment.clear();
14986
+ texturebump.clear();
1486414987 // repaint();
1486514988 break;
1486614989 case 'Y':
....@@ -14945,7 +15068,9 @@
1494515068 case 'E' : COMPACT ^= true;
1494615069 repaint();
1494715070 break;
14948
- case 'W' : DEBUGHSB ^= true;
15071
+ case 'W' : // Wide Window (fullscreen)
15072
+ //DEBUGHSB ^= true;
15073
+ ObjEditor.theFrame.ToggleFullScreen();
1494915074 repaint();
1495015075 break;
1495115076 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14971,13 +15096,7 @@
1497115096 repaint();
1497215097 break;
1497315098 case 'l':
14974
- lightMode ^= true;
14975
- Globals.lighttouched = true;
14976
- manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
14977
- targetLookAt.set(manipCamera.lookAt);
14978
- repaint();
14979
- break;
14980
- case 'L':
15099
+ //case 'L':
1498115100 if (lightMode)
1498215101 {
1498315102 lightMode = false;
....@@ -15124,7 +15243,10 @@
1512415243 // kompactbit = 6;
1512515244 // break;
1512615245 case ' ':
15127
- ObjEditor.theFrame.ToggleFullScreen();
15246
+ lightMode ^= true;
15247
+ Globals.lighttouched = true;
15248
+ manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
15249
+ targetLookAt.set(manipCamera.lookAt);
1512815250 repaint();
1512915251 break;
1513015252 //case '`' :
....@@ -15708,6 +15830,7 @@
1570815830 info.bounds.y += (height - desired) / 2;
1570915831 }
1571015832 }
15833
+
1571115834 info.g = gr;
1571215835 info.camera = renderCamera;
1571315836 /*
....@@ -15717,23 +15840,44 @@
1571715840 */
1571815841 if (!isRenderer)
1571915842 {
15720
- object.drawEditHandles(info, 0);
15721
-
15722
- if (drag && (X != 0 || Y != 0) && object.selection.Size() > 0)
15843
+ Grafreed.Assert(object != null);
15844
+ Grafreed.Assert(object.selection != null);
15845
+ if (object.selection.Size() > 0)
1572315846 {
15724
- switch (object.selection.get(0).hitSomething)
15847
+ int hitSomething = object.selection.get(0).hitSomething;
15848
+
15849
+ info.DX = 0;
15850
+ info.DY = 0;
15851
+ info.W = 1;
15852
+ if (hitSomething == Object3D.hitCenter)
1572515853 {
15726
- case Object3D.hitCenter: gr.setColor(Color.pink);
15727
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15728
- break;
15729
- case Object3D.hitRotate: gr.setColor(Color.yellow);
15730
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15731
- break;
15732
- case Object3D.hitScale: gr.setColor(Color.cyan);
15733
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15734
- break;
15854
+ info.DX = X;
15855
+ if (X != 0)
15856
+ info.DX -= info.bounds.width/2;
15857
+
15858
+ info.DY = Y;
15859
+ if (Y != 0)
15860
+ info.DY -= info.bounds.height/2;
1573515861 }
15736
-
15862
+
15863
+ object.drawEditHandles(info, 0);
15864
+
15865
+ if (drag && (X != 0 || Y != 0))
15866
+ {
15867
+ switch (hitSomething)
15868
+ {
15869
+ case Object3D.hitCenter: gr.setColor(Color.pink);
15870
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15871
+ break;
15872
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
15873
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15874
+ break;
15875
+ case Object3D.hitScale: gr.setColor(Color.cyan);
15876
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15877
+ break;
15878
+ }
15879
+
15880
+ }
1573715881 }
1573815882 }
1573915883 }
....@@ -16531,6 +16675,14 @@
1653116675 }
1653216676 }
1653316677
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
+
1653416686 class SelectBuffer implements GLEventListener
1653516687 {
1653616688
....@@ -16610,6 +16762,17 @@
1661016762
1661116763 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1661216764
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
+
1661316776 //int tmp = selection_view;
1661416777 //selection_view = -1;
1661516778 int temp = DrawMode();
....@@ -16621,6 +16784,17 @@
1662116784 // temp = DEFAULT; // patch for selection debug
1662216785 Globals.drawMode = temp; // WARNING
1662316786
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
+
1662416798 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1662516799
1662616800 // trying different ways of getting the depth info over
....@@ -16726,27 +16900,29 @@
1672616900 if (!movingcamera && !PAINTMODE)
1672716901 object.GetWindow().ScreenFitPoint(); // fev 2014
1672816902
16729
- 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)
1673016904 {
16731
- Object3D paintobj = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
16732
-
16733
- Object3D group = new Object3D("inst" + paintcount++);
16734
-
16735
- group.CreateMaterial(); // use a void leaf to select instances
16736
-
16737
- group.add(paintobj); // link
16738
-
16739
- object.GetWindow().SnapObject(group);
16740
-
16741
- Object3D folder = object.GetWindow().copy;
16905
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1674216906
1674316907 if (object.GetWindow().copy.selection.Size() > 0)
16744
- folder = object.GetWindow().copy.selection.elementAt(0);
16908
+ {
16909
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1674516910
16746
- folder.add(group);
16747
-
16748
- object.GetWindow().ResetModel();
16749
- 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
+ }
1675016926 }
1675116927 else
1675216928 paintcount = 0;