Normand Briere
2019-07-27 1af7d3700724834e40ad8636bc9a56cdc3b19b15
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;
....@@ -169,7 +206,8 @@
169206
170207 SetCamera(cam);
171208
172
- SetLight(new Camera(new cVector(10, 10, -20)));
209
+ // Warning: not used.
210
+ SetLight(new Camera(new cVector(15, 10, -20)));
173211
174212 object = o;
175213
....@@ -2405,6 +2443,21 @@
24052443 return currentGL;
24062444 }
24072445
2446
+ static private BufferedImage CreateBim(TextureData texturedata)
2447
+ {
2448
+ Grafreed.Assert(texturedata != null);
2449
+
2450
+ int width = texturedata.getWidth();
2451
+ int height = texturedata.getHeight();
2452
+
2453
+ Buffer buffer = texturedata.getBuffer();
2454
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2455
+
2456
+ byte[] bytes = bytebuf.array();
2457
+
2458
+ return CreateBim(bytes, width, height);
2459
+ }
2460
+
24082461 /**/
24092462 class CacheTexture
24102463 {
....@@ -2413,28 +2466,31 @@
24132466
24142467 int resolution;
24152468
2416
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2469
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
24172470 {
2418
- texture = tex;
2471
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2472
+ texturedata = texdata;
24192473 resolution = res;
24202474 }
24212475 }
24222476 /**/
24232477
24242478 // TEXTURE static Texture texture;
2425
- static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures
2426
- = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>();
2427
- static public java.util.Hashtable<String, String> usedtextures = new java.util.Hashtable<String, String>();
2479
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2480
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2481
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2482
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2483
+
24282484 int pigmentdepth = 0;
24292485 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
24302486 int bumpdepth = 0;
24312487 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
24322488 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
24332489 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2434
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2490
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
24352491 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
24362492
2437
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2493
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
24382494 {
24392495 TextureData texturedata = null;
24402496
....@@ -2453,13 +2509,34 @@
24532509 if (bump)
24542510 texturedata = ConvertBump(texturedata, false);
24552511
2456
- com.sun.opengl.util.texture.Texture texture =
2457
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2512
+// com.sun.opengl.util.texture.Texture texture =
2513
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
24582514
2459
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2460
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
2515
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2516
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
24612517
2462
- return texture;
2518
+ return texturedata;
2519
+ }
2520
+
2521
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2522
+ {
2523
+ TextureData texturedata = null;
2524
+
2525
+ try
2526
+ {
2527
+ texturedata =
2528
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2529
+ bim,
2530
+ true);
2531
+ } catch (Exception e)
2532
+ {
2533
+ throw new javax.media.opengl.GLException(e);
2534
+ }
2535
+
2536
+ if (bump)
2537
+ texturedata = ConvertBump(texturedata, false);
2538
+
2539
+ return texturedata;
24632540 }
24642541
24652542 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3532,6 +3609,8 @@
35323609
35333610 System.out.println("LOADING TEXTURE : " + name);
35343611
3612
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3613
+
35353614 //
35363615 if (false) // compressbit > 0)
35373616 {
....@@ -7930,7 +8009,7 @@
79308009 String pigment = Object3D.GetPigment(tex);
79318010 String bump = Object3D.GetBump(tex);
79328011
7933
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8012
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79348013 {
79358014 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79368015 // System.out.println("; bump = " + bump);
....@@ -7945,8 +8024,8 @@
79458024 pigment = null;
79468025 }
79478026
7948
- ReleaseTexture(bump, true);
7949
- ReleaseTexture(pigment, false);
8027
+ ReleaseTexture(tex, true);
8028
+ ReleaseTexture(tex, false);
79508029 }
79518030
79528031 public void ReleasePigmentTexture(cTexture tex) // INTERFACE
....@@ -7964,7 +8043,7 @@
79648043
79658044 String pigment = Object3D.GetPigment(tex);
79668045
7967
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8046
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79688047 {
79698048 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79708049 // System.out.println("; bump = " + bump);
....@@ -7975,7 +8054,7 @@
79758054 pigment = null;
79768055 }
79778056
7978
- ReleaseTexture(pigment, false);
8057
+ ReleaseTexture(tex, false);
79798058 }
79808059
79818060 public void ReleaseBumpTexture(cTexture tex) // INTERFACE
....@@ -7993,7 +8072,7 @@
79938072
79948073 String bump = Object3D.GetBump(tex);
79958074
7996
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8075
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79978076 {
79988077 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79998078 // System.out.println("; bump = " + bump);
....@@ -8004,10 +8083,10 @@
80048083 bump = null;
80058084 }
80068085
8007
- ReleaseTexture(bump, true);
8086
+ ReleaseTexture(tex, true);
80088087 }
80098088
8010
- void ReleaseTexture(String tex, boolean bump)
8089
+ void ReleaseTexture(cTexture tex, boolean bump)
80118090 {
80128091 if (// DrawMode() != 0 || /*tex == null ||*/
80138092 ambientOcclusion ) // || !textureon)
....@@ -8018,7 +8097,7 @@
80188097 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
80198098
80208099 if (tex != null)
8021
- texture = textures.get(tex);
8100
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
80228101
80238102 // //assert( texture != null );
80248103 // if (texture == null)
....@@ -8112,47 +8191,50 @@
81128191
81138192 /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
81148193 {
8115
- if (// DrawMode() != 0 || /*tex == null ||*/
8116
- ambientOcclusion ) // || !textureon)
8117
- {
8118
- return; // false;
8119
- }
8120
-
8121
- if (tex == null)
8122
- {
8123
- BindTexture(null,false,resolution);
8124
- BindTexture(null,true,resolution);
8125
- return;
8126
- }
8194
+// if (// DrawMode() != 0 || /*tex == null ||*/
8195
+// ambientOcclusion ) // || !textureon)
8196
+// {
8197
+// return; // false;
8198
+// }
8199
+//
8200
+// if (tex == null)
8201
+// {
8202
+// BindTexture(null,false,resolution);
8203
+// BindTexture(null,true,resolution);
8204
+// return;
8205
+// }
8206
+//
8207
+// String pigment = Object3D.GetPigment(tex);
8208
+// String bump = Object3D.GetBump(tex);
8209
+//
8210
+// usedtextures.add(pigment);
8211
+// usedtextures.add(bump);
8212
+//
8213
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8214
+// {
8215
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8216
+// // System.out.println("; bump = " + bump);
8217
+// }
8218
+//
8219
+// if (bump.equals(""))
8220
+// {
8221
+// bump = null;
8222
+// }
8223
+// if (pigment.equals(""))
8224
+// {
8225
+// pigment = null;
8226
+// }
8227
+//
8228
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8229
+// BindTexture(pigment, false, resolution);
8230
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8231
+// BindTexture(bump, true, resolution);
8232
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8233
+//
8234
+// return; // true;
81278235
8128
- String pigment = Object3D.GetPigment(tex);
8129
- String bump = Object3D.GetBump(tex);
8130
-
8131
- usedtextures.put(pigment, pigment);
8132
- usedtextures.put(bump, bump);
8133
-
8134
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8135
- {
8136
- // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8137
- // System.out.println("; bump = " + bump);
8138
- }
8139
-
8140
- if (bump.equals(""))
8141
- {
8142
- bump = null;
8143
- }
8144
- if (pigment.equals(""))
8145
- {
8146
- pigment = null;
8147
- }
8148
-
8149
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8150
- BindTexture(pigment, false, resolution);
8151
- GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8152
- BindTexture(bump, true, resolution);
8153
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8154
-
8155
- return; // true;
8236
+ BindPigmentTexture(tex, resolution);
8237
+ BindBumpTexture(tex, resolution);
81568238 }
81578239
81588240 /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8171,9 +8253,9 @@
81718253
81728254 String pigment = Object3D.GetPigment(tex);
81738255
8174
- usedtextures.put(pigment, pigment);
8256
+ usedtextures.add(tex);
81758257
8176
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8258
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
81778259 {
81788260 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
81798261 // System.out.println("; bump = " + bump);
....@@ -8185,7 +8267,7 @@
81858267 }
81868268
81878269 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8188
- BindTexture(pigment, false, resolution);
8270
+ BindTexture(tex, false, resolution);
81898271 }
81908272
81918273 /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8204,9 +8286,9 @@
82048286
82058287 String bump = Object3D.GetBump(tex);
82068288
8207
- usedtextures.put(bump, bump);
8289
+ usedtextures.add(tex);
82088290
8209
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8291
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
82108292 {
82118293 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
82128294 // System.out.println("; bump = " + bump);
....@@ -8218,7 +8300,7 @@
82188300 }
82198301
82208302 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8221
- BindTexture(bump, true, resolution);
8303
+ BindTexture(tex, true, resolution);
82228304 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
82238305 }
82248306
....@@ -8242,13 +8324,19 @@
82428324 return fileExists;
82438325 }
82448326
8245
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception
8327
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
82468328 {
8247
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8329
+ CacheTexture texturecache = null;
82488330
82498331 if (tex != null)
82508332 {
8251
- String texname = tex;
8333
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8334
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
8335
+
8336
+ if (texname.equals("") && texdata == null)
8337
+ {
8338
+ return null;
8339
+ }
82528340
82538341 String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
82548342
....@@ -8258,19 +8346,46 @@
82588346 // else
82598347 // if (!texname.startsWith("/"))
82608348 // texname = "/Users/nbriere/Textures/" + texname;
8261
- if (!FileExists(tex))
8349
+ if (!FileExists(texname))
82628350 {
82638351 texname = fallbackTextureName;
82648352 }
82658353
82668354 if (CACHETEXTURE)
8267
- texture = textures.get(texname); // TEXTURE CACHE
8268
-
8269
- TextureData texturedata = null;
8270
-
8271
- if (texture == null || texture.resolution < resolution)
82728355 {
8273
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8356
+ if (texdata == null)
8357
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8358
+ else
8359
+ texturecache = bimtextures.get(texdata);
8360
+ }
8361
+
8362
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8363
+ {
8364
+ TextureData texturedata = null;
8365
+
8366
+ if (texdata != null && textureon)
8367
+ {
8368
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8369
+
8370
+ try
8371
+ {
8372
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8373
+ }
8374
+ catch (Exception e)
8375
+ {
8376
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8377
+ }
8378
+
8379
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8380
+ bimtextures.put(texdata, texturecache);
8381
+
8382
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8383
+
8384
+ //Object bim2 = CreateBim(texturecache.texturedata);
8385
+ //bim2 = bim;
8386
+ }
8387
+ else
8388
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
82748389 {
82758390 assert(!bump);
82768391 // if (bump)
....@@ -8281,19 +8396,23 @@
82818396 // }
82828397 // else
82838398 // {
8284
- texture = textures.get(tex);
8285
- if (texture == null)
8399
+ // texturecache = textures.get(texname); // suspicious
8400
+ if (texturecache == null)
82868401 {
8287
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8402
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
82888403 }
8404
+ else
8405
+ new Exception().printStackTrace();
82898406 // }
82908407 } else
8291
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8408
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
82928409 {
82938410 assert(bump);
8294
- texture = textures.get(tex);
8295
- if (texture == null)
8296
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8411
+ // texturecache = textures.get(texname); // suspicious
8412
+ if (texturecache == null)
8413
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8414
+ else
8415
+ new Exception().printStackTrace();
82978416 } else
82988417 {
82998418 //if (tex.equals("IMMORTAL"))
....@@ -8301,11 +8420,13 @@
83018420 // texture = GetResourceTexture("default.png");
83028421 //} else
83038422 //{
8304
- if (tex.equals("WHITE_NOISE"))
8423
+ if (texname.endsWith("WHITE_NOISE"))
83058424 {
8306
- texture = textures.get(tex);
8307
- if (texture == null)
8308
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8425
+ // texturecache = textures.get(texname); // suspicious
8426
+ if (texturecache == null)
8427
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8428
+ else
8429
+ new Exception().printStackTrace();
83098430 } else
83108431 {
83118432 if (textureon)
....@@ -8364,19 +8485,19 @@
83648485 if (texturedata == null)
83658486 throw new Exception();
83668487
8367
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8488
+ texturecache = new CacheTexture(texturedata,resolution);
83688489 //texture = GetTexture(tex, bump);
83698490 }
83708491 }
83718492 //}
83728493 }
83738494
8374
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8495
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
83758496 {
83768497 //return false;
83778498
83788499 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8379
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8500
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
83808501 {
83818502 // String ext = "_highres";
83828503 // if (REDUCETEXTURE)
....@@ -8393,52 +8514,17 @@
83938514 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
83948515 if (!cachefile.exists())
83958516 {
8396
- // cache to disk
8397
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
8398
- //buffers[0].
8399
-
8400
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
8401
- int[] pixels = new int[bytebuf.capacity()/3];
8402
-
8403
- // squared size heuristic...
8404
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8517
+ //if (texturedata.getWidth() == texturedata.getHeight())
84058518 {
8406
- for (int i=pixels.length; --i>=0;)
8407
- {
8408
- int i3 = i*3;
8409
- pixels[i] = 0xFF;
8410
- pixels[i] <<= 8;
8411
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
8412
- pixels[i] <<= 8;
8413
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
8414
- pixels[i] <<= 8;
8415
- pixels[i] |= bytebuf.get(i3) & 0xFF;
8416
- }
8417
-
8418
- /*
8419
- int r=0,g=0,b=0,a=0;
8420
- for (int i=0; i<width; i++)
8421
- for (int j=0; j<height; j++)
8422
- {
8423
- int index = j*width+i;
8424
- int p = pixels[index];
8425
- a = ((p>>24) & 0xFF);
8426
- r = ((p>>16) & 0xFF);
8427
- g = ((p>>8) & 0xFF);
8428
- b = (p & 0xFF);
8429
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
8430
- }
8431
- /**/
8432
- int width = (int)Math.sqrt(pixels.length); // squared
8433
- int height = width;
8434
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
8435
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8519
+ BufferedImage rendImage = CreateBim(texturedata);
8520
+
84368521 ImageWriter writer = null;
84378522 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
84388523 if (iter.hasNext()) {
84398524 writer = (ImageWriter)iter.next();
84408525 }
8441
- float compressionQuality = 0.9f;
8526
+
8527
+ float compressionQuality = 0.85f;
84428528 try
84438529 {
84448530 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8455,18 +8541,20 @@
84558541 }
84568542 }
84578543 }
8458
-
8544
+
8545
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8546
+
84598547 //System.out.println("Texture = " + tex);
8460
- if (textures.containsKey(texname))
8548
+ if (textures.containsKey(tex))
84618549 {
8462
- CacheTexture thetex = textures.get(texname);
8550
+ CacheTexture thetex = textures.get(tex);
84638551 thetex.texture.disable();
84648552 thetex.texture.dispose();
8465
- textures.remove(texname);
8553
+ textures.remove(tex);
84668554 }
84678555
8468
- texture.texturedata = texturedata;
8469
- textures.put(texname, texture);
8556
+ //texture.texturedata = texturedata;
8557
+ textures.put(tex, texturecache);
84708558
84718559 // newtex = true;
84728560 }
....@@ -8482,10 +8570,44 @@
84828570 }
84838571 }
84848572
8485
- return texture;
8573
+ return texturecache;
84868574 }
84878575
8488
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution) throws Exception
8576
+ static void EmbedTextures(cTexture tex)
8577
+ {
8578
+ if (tex.pigmentdata == null)
8579
+ {
8580
+ //String texname = Object3D.GetPigment(tex);
8581
+
8582
+ CacheTexture texturecache = texturepigment.get(tex);
8583
+
8584
+ if (texturecache != null)
8585
+ {
8586
+ tex.pw = texturecache.texturedata.getWidth();
8587
+ tex.ph = texturecache.texturedata.getHeight();
8588
+ tex.pigmentdata = //CompressJPEG(CreateBim
8589
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8590
+ ;
8591
+ //, tex.pw, tex.ph), 0.5f);
8592
+ }
8593
+ }
8594
+
8595
+ if (tex.bumpdata == null)
8596
+ {
8597
+ //String texname = Object3D.GetBump(tex);
8598
+
8599
+ CacheTexture texturecache = texturebump.get(tex);
8600
+
8601
+ if (texturecache != null)
8602
+ {
8603
+ tex.bw = texturecache.texturedata.getWidth();
8604
+ tex.bh = texturecache.texturedata.getHeight();
8605
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8606
+ }
8607
+ }
8608
+ }
8609
+
8610
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
84898611 {
84908612 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
84918613
....@@ -8503,26 +8625,26 @@
85038625 return texture!=null?texture.texture:null;
85048626 }
85058627
8506
- public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution) throws Exception
8628
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
85078629 {
85088630 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
85098631
85108632 return texture!=null?texture.texturedata:null;
85118633 }
85128634
8513
- com.sun.opengl.util.texture.Texture BindTexture(String tex, boolean bump, int resolution) throws Exception
8635
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
85148636 {
85158637 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
85168638 {
85178639 return false;
85188640 }
85198641
8520
- boolean newtex = false;
8642
+ //boolean newtex = false;
85218643
85228644 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
85238645
85248646 if (texture == null)
8525
- return texture;
8647
+ return false;
85268648 /**/
85278649
85288650 if (textureon || tex.equals("DEFAULT_TEXTURE") || tex.equals("DEFAULT_TEXTURE_BUMP") || tex.equals("WHITE_NOISE")) // || tex.equals("IMMORTAL"))
....@@ -8549,9 +8671,75 @@
85498671 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
85508672 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
85518673
8552
- return newtex;
8674
+ return true; // Warning: not used.
85538675 }
85548676
8677
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8678
+ {
8679
+ try
8680
+ {
8681
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8682
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8683
+ ImageWriter writer = writers.next();
8684
+
8685
+ ImageWriteParam param = writer.getDefaultWriteParam();
8686
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8687
+ param.setCompressionQuality(quality);
8688
+
8689
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8690
+ writer.setOutput(ios);
8691
+ writer.write(null, new IIOImage(image, null, null), param);
8692
+
8693
+ byte[] data = baos.toByteArray();
8694
+ writer.dispose();
8695
+ return data;
8696
+ }
8697
+ catch (Exception e)
8698
+ {
8699
+ e.printStackTrace();
8700
+ return null;
8701
+ }
8702
+ }
8703
+
8704
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8705
+ {
8706
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8707
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8708
+ ImageReader reader = writers.next();
8709
+
8710
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8711
+
8712
+ ImageReadParam param = reader.getDefaultReadParam();
8713
+ param.setDestination(bim);
8714
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8715
+
8716
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8717
+ reader.setInput(ios);
8718
+ BufferedImage bim2 = reader.read(0, param);
8719
+ reader.dispose();
8720
+
8721
+// WritableRaster raster = bim2.getRaster();
8722
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8723
+// byte[] bytes = data.getData();
8724
+//
8725
+// int[] pixels = new int[bytes.length/3];
8726
+// for (int i=pixels.length; --i>=0;)
8727
+// {
8728
+// int i3 = i*3;
8729
+// pixels[i] = 0xFF;
8730
+// pixels[i] <<= 8;
8731
+// pixels[i] |= bytes[i3+2] & 0xFF;
8732
+// pixels[i] <<= 8;
8733
+// pixels[i] |= bytes[i3+1] & 0xFF;
8734
+// pixels[i] <<= 8;
8735
+// pixels[i] |= bytes[i3] & 0xFF;
8736
+// }
8737
+//
8738
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8739
+
8740
+ return bim;
8741
+ }
8742
+
85558743 ShadowBuffer shadowPBuf;
85568744 AntialiasBuffer antialiasPBuf;
85578745 int MAXSTACK;
....@@ -9512,7 +9700,7 @@
95129700
95139701 if (renderCamera != lightCamera)
95149702 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9515
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
9703
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
95169704
95179705 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
95189706
....@@ -9528,7 +9716,7 @@
95289716
95299717 if (renderCamera != lightCamera)
95309718 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9531
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
9719
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
95329720
95339721 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
95349722
....@@ -10729,7 +10917,7 @@
1072910917 // if (parentcam != renderCamera) // not a light
1073010918 if (cam != lightCamera)
1073110919 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10732
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
10920
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1073310921
1073410922 for (int j = 0; j < 4; j++)
1073510923 {
....@@ -10744,7 +10932,7 @@
1074410932 // if (parentcam != renderCamera) // not a light
1074510933 if (cam != lightCamera)
1074610934 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10747
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
10935
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1074810936
1074910937 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1075010938
....@@ -11297,7 +11485,7 @@
1129711485 }
1129811486 }
1129911487
11300
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11488
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1130111489 {
1130211490 //gl.glDepthFunc(GL.GL_LEQUAL);
1130311491 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11305,24 +11493,21 @@
1130511493
1130611494 boolean texon = textureon;
1130711495
11308
- if (RENDERPROGRAM > 0)
11309
- {
11310
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11311
- textureon = false;
11312
- }
11496
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11497
+ textureon = false;
11498
+
1131311499 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1131411500 //System.out.println("ALLO");
1131511501 gl.glColorMask(false, false, false, false);
1131611502 DrawObject(gl);
11317
- if (RENDERPROGRAM > 0)
11318
- {
11319
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11320
- textureon = texon;
11321
- }
11503
+
11504
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11505
+ textureon = texon;
11506
+
1132211507 gl.glColorMask(true, true, true, true);
1132311508
1132411509 gl.glDepthFunc(GL.GL_EQUAL);
11325
- //gl.glDepthMask(false);
11510
+ gl.glDepthMask(false);
1132611511 }
1132711512
1132811513 if (false) // DrawMode() == SHADOW)
....@@ -11662,20 +11847,32 @@
1166211847 ReleaseTextures(DEFAULT_TEXTURES);
1166311848
1166411849 if (CLEANCACHE)
11665
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11850
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1166611851 {
11667
- String tex = e.nextElement();
11852
+ cTexture tex = e.nextElement();
1166811853
1166911854 // System.out.println("Texture --------- " + tex);
1167011855
11671
- if (tex.equals("WHITE_NOISE"))
11856
+ if (tex.equals("WHITE_NOISE:"))
1167211857 continue;
1167311858
11674
- if (!usedtextures.containsKey(tex))
11859
+ if (!usedtextures.contains(tex))
1167511860 {
11861
+ CacheTexture gettex = texturepigment.get(tex);
1167611862 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11677
- textures.get(tex).texture.dispose();
11678
- textures.remove(tex);
11863
+ if (gettex != null)
11864
+ {
11865
+ gettex.texture.dispose();
11866
+ texturepigment.remove(tex);
11867
+ }
11868
+
11869
+ gettex = texturebump.get(tex);
11870
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11871
+ if (gettex != null)
11872
+ {
11873
+ gettex.texture.dispose();
11874
+ texturebump.remove(tex);
11875
+ }
1167911876 }
1168011877 }
1168111878 }
....@@ -12204,7 +12401,74 @@
1220412401 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1220512402
1220612403 String program =
12404
+ // Min shader
1220712405 "!!ARBfp1.0\n" +
12406
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12407
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12408
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12409
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12410
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12411
+ "PARAM light2cam0 = program.env[10];" +
12412
+ "PARAM light2cam1 = program.env[11];" +
12413
+ "PARAM light2cam2 = program.env[12];" +
12414
+ "TEMP temp;" +
12415
+ "TEMP light;" +
12416
+ "TEMP ndotl;" +
12417
+ "TEMP normal;" +
12418
+ "TEMP depth;" +
12419
+ "TEMP eye;" +
12420
+ "TEMP pos;" +
12421
+
12422
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12423
+ Normalize("normal") +
12424
+ "MOV light, state.light[0].position;" +
12425
+ "DP3 ndotl.x, light, normal;" +
12426
+
12427
+ // shadow
12428
+ "MOV pos, fragment.texcoord[1];" +
12429
+ "MOV temp, pos;" +
12430
+ ShadowTextureFetch("depth", "temp", "1") +
12431
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12432
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12433
+
12434
+ // No shadow when out of frustum
12435
+ //"SGE temp.y, depth.z, zero123.y;" +
12436
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12437
+
12438
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12439
+
12440
+ // Backlit
12441
+ "MOV pos.w, zero123.y;" +
12442
+ "DP4 eye.x, pos, light2cam0;" +
12443
+ "DP4 eye.y, pos, light2cam1;" +
12444
+ "DP4 eye.z, pos, light2cam2;" +
12445
+ Normalize("eye") +
12446
+
12447
+ "DP3 ndotl.y, -eye, normal;" +
12448
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12449
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12450
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12451
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12452
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12453
+
12454
+ "MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12455
+
12456
+ // Pigment
12457
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12458
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12459
+ "MUL temp, temp, ndotl.x;" +
12460
+
12461
+ "MUL temp, temp, zero123.z;" +
12462
+
12463
+ //"MUL temp, temp, ndotl.y;" +
12464
+
12465
+ "MOV temp.w, zero123.y;" + // reset alpha
12466
+ "MOV result.color, temp;" +
12467
+ "END";
12468
+
12469
+ String program2 =
12470
+ "!!ARBfp1.0\n" +
12471
+
1220812472 //"OPTION ARB_fragment_program_shadow;" +
1220912473 "PARAM light2cam0 = program.env[10];" +
1221012474 "PARAM light2cam1 = program.env[11];" +
....@@ -12319,8 +12583,7 @@
1231912583 "TEMP shininess;" +
1232012584 "\n" +
1232112585 "MOV texSamp, one;" +
12322
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12323
-
12586
+
1232412587 "MOV mapgrid.x, one2048th.x;" +
1232512588 "MOV temp, fragment.texcoord[1];" +
1232612589 /*
....@@ -12341,20 +12604,20 @@
1234112604 "MUL temp, floor, mapgrid.x;" +
1234212605 //"TEX depth0, temp, texture[1], 2D;" +
1234312606 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12344
- TextureFetch("depth0", "temp", "1") +
12607
+ ShadowTextureFetch("depth0", "temp", "1") +
1234512608 "") +
1234612609 "ADD temp.x, temp.x, mapgrid.x;" +
1234712610 //"TEX depth1, temp, texture[1], 2D;" +
1234812611 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12349
- TextureFetch("depth1", "temp", "1") +
12612
+ ShadowTextureFetch("depth1", "temp", "1") +
1235012613 "") +
1235112614 "ADD temp.y, temp.y, mapgrid.x;" +
1235212615 //"TEX depth2, temp, texture[1], 2D;" +
12353
- TextureFetch("depth2", "temp", "1") +
12616
+ ShadowTextureFetch("depth2", "temp", "1") +
1235412617 "SUB temp.x, temp.x, mapgrid.x;" +
1235512618 //"TEX depth3, temp, texture[1], 2D;" +
1235612619 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12357
- TextureFetch("depth3", "temp", "1") +
12620
+ ShadowTextureFetch("depth3", "temp", "1") +
1235812621 "") +
1235912622 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1236012623 //"MOV params, material;" +
....@@ -12725,7 +12988,7 @@
1272512988 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1272612989 "") +
1272712990
12728
- // display shadow only (bump == 0)
12991
+ // display shadow only (fakedepth == 0)
1272912992 "SUB temp.x, half.x, shadow.x;" +
1273012993 "MOV temp.y, -params5.z;" + // params6.x;" +
1273112994 "SLT temp.z, temp.y, -one2048th.x;" +
....@@ -13152,25 +13415,26 @@
1315213415 return out;
1315313416 }
1315413417
13155
- String TextureFetch(String dest, String src, String unit)
13418
+ // Also does frustum culling
13419
+ String ShadowTextureFetch(String dest, String src, String unit)
1315613420 {
1315713421 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1315813422 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1315913423 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13424
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13425
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1316013426 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13161
- "SLT " + src + ".z, " + src + ".x, one.x;" +
13162
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13163
- "SLT " + src + ".z, " + src + ".y, one.x;" +
13164
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13427
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13428
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1316513429 //"SWZ buffer, temp, w,w,w,w;";
13166
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13430
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1316713431 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1316813432 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1316913433 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13170
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13434
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1317113435
13172
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13173
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13436
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13437
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1317413438 }
1317513439
1317613440 String Shadow(String depth, String shadow)
....@@ -13217,7 +13481,7 @@
1321713481 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1321813482 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1321913483
13220
- // No shadow when out of frustrum
13484
+ // No shadow when out of frustum
1322113485 "SGE temp.x, " + depth + ".z, one.z;" +
1322213486 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1322313487 "";
....@@ -14015,14 +14279,15 @@
1401514279 drag = false;
1401614280 //System.out.println("Mouse DOWN");
1401714281 editObj = false;
14018
- ClickInfo info = new ClickInfo();
14019
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14020
- info.pane = this;
14021
- info.camera = renderCamera;
14022
- info.x = x;
14023
- info.y = y;
14024
- info.modifiers = modifiersex;
14025
- editObj = object.doEditClick(info, 0);
14282
+ //ClickInfo info = new ClickInfo();
14283
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14284
+ object.clickInfo.pane = this;
14285
+ object.clickInfo.camera = renderCamera;
14286
+ object.clickInfo.x = x;
14287
+ object.clickInfo.y = y;
14288
+ object.clickInfo.modifiers = modifiersex;
14289
+ editObj = object.doEditClick(//info,
14290
+ 0);
1402614291 if (!editObj)
1402714292 {
1402814293 hasMarquee = true;
....@@ -14422,15 +14687,16 @@
1442214687 if (editObj)
1442314688 {
1442414689 drag = true;
14425
- ClickInfo info = new ClickInfo();
14426
- info.bounds.setBounds(0, 0,
14690
+ //ClickInfo info = new ClickInfo();
14691
+ object.clickInfo.bounds.setBounds(0, 0,
1442714692 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14428
- info.pane = this;
14429
- info.camera = renderCamera;
14430
- info.x = x;
14431
- info.y = y;
14432
- object.GetWindow().copy
14433
- .doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
14693
+ object.clickInfo.pane = this;
14694
+ object.clickInfo.camera = renderCamera;
14695
+ object.clickInfo.x = x;
14696
+ object.clickInfo.y = y;
14697
+ object //.GetWindow().copy
14698
+ .doEditDrag(//info,
14699
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1443414700 } else
1443514701 {
1443614702 if (x < startX)
....@@ -14579,24 +14845,27 @@
1457914845 }
1458014846 }
1458114847
14848
+// ClickInfo clickInfo = new ClickInfo();
14849
+
1458214850 public void mouseMoved(MouseEvent e)
1458314851 {
1458414852 //System.out.println("mouseMoved: " + e);
1458514853 if (isRenderer)
1458614854 return;
1458714855
14588
- ClickInfo ci = new ClickInfo();
14589
- ci.x = e.getX();
14590
- ci.y = e.getY();
14591
- ci.modifiers = e.getModifiersEx();
14592
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14593
- ci.pane = this;
14594
- ci.camera = renderCamera;
14856
+ // Mouse cursor feedback
14857
+ object.clickInfo.x = e.getX();
14858
+ object.clickInfo.y = e.getY();
14859
+ object.clickInfo.modifiers = e.getModifiersEx();
14860
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14861
+ object.clickInfo.pane = this;
14862
+ object.clickInfo.camera = renderCamera;
1459514863 if (!isRenderer)
1459614864 {
1459714865 //ObjEditor editWindow = object.editWindow;
1459814866 //Object3D copy = editWindow.copy;
14599
- if (object.doEditClick(ci, 0))
14867
+ if (object.doEditClick(//clickInfo,
14868
+ 0))
1460014869 {
1460114870 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1460214871 } else
....@@ -14868,7 +15137,8 @@
1486815137 // break;
1486915138 case 'T':
1487015139 CACHETEXTURE ^= true;
14871
- textures.clear();
15140
+ texturepigment.clear();
15141
+ texturebump.clear();
1487215142 // repaint();
1487315143 break;
1487415144 case 'Y':
....@@ -15621,8 +15891,6 @@
1562115891
1562215892 int width = getBounds().width;
1562315893 int height = getBounds().height;
15624
- ClickInfo info = new ClickInfo();
15625
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1562615894 //Image img = CreateImage(width, height);
1562715895 //System.out.println("width = " + width + "; height = " + height + "\n");
1562815896
....@@ -15699,31 +15967,37 @@
1569915967 }
1570015968 if (object != null && !hasMarquee)
1570115969 {
15970
+ if (object.clickInfo == null)
15971
+ object.clickInfo = new ClickInfo();
15972
+ ClickInfo info = object.clickInfo;
15973
+ //ClickInfo info = new ClickInfo();
15974
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
15975
+
1570215976 if (isRenderer)
1570315977 {
15704
- info.flags++;
15978
+ object.clickInfo.flags++;
1570515979 double frameAspect = (double) width / (double) height;
1570615980 if (frameAspect > renderCamera.aspect)
1570715981 {
1570815982 int desired = (int) ((double) height * renderCamera.aspect);
15709
- info.bounds.width -= width - desired;
15710
- info.bounds.x += (width - desired) / 2;
15983
+ object.clickInfo.bounds.width -= width - desired;
15984
+ object.clickInfo.bounds.x += (width - desired) / 2;
1571115985 } else
1571215986 {
1571315987 int desired = (int) ((double) width / renderCamera.aspect);
15714
- info.bounds.height -= height - desired;
15715
- info.bounds.y += (height - desired) / 2;
15988
+ object.clickInfo.bounds.height -= height - desired;
15989
+ object.clickInfo.bounds.y += (height - desired) / 2;
1571615990 }
1571715991 }
1571815992
15719
- info.g = gr;
15720
- info.camera = renderCamera;
15993
+ object.clickInfo.g = gr;
15994
+ object.clickInfo.camera = renderCamera;
1572115995 /*
1572215996 // Memory intensive (brep.verticescopy)
1572315997 if (!(object instanceof Composite))
1572415998 object.draw(info, 0, false); // SLOW :
1572515999 */
15726
- if (!isRenderer)
16000
+ if (!isRenderer) // && drag)
1572716001 {
1572816002 Grafreed.Assert(object != null);
1572916003 Grafreed.Assert(object.selection != null);
....@@ -15731,9 +16005,9 @@
1573116005 {
1573216006 int hitSomething = object.selection.get(0).hitSomething;
1573316007
15734
- info.DX = 0;
15735
- info.DY = 0;
15736
- info.W = 1;
16008
+ object.clickInfo.DX = 0;
16009
+ object.clickInfo.DY = 0;
16010
+ object.clickInfo.W = 1;
1573716011 if (hitSomething == Object3D.hitCenter)
1573816012 {
1573916013 info.DX = X;
....@@ -15745,7 +16019,8 @@
1574516019 info.DY -= info.bounds.height/2;
1574616020 }
1574716021
15748
- object.drawEditHandles(info, 0);
16022
+ object.drawEditHandles(//info,
16023
+ 0);
1574916024
1575016025 if (drag && (X != 0 || Y != 0))
1575116026 {
....@@ -15758,7 +16033,7 @@
1575816033 gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
1575916034 break;
1576016035 case Object3D.hitScale: gr.setColor(Color.cyan);
15761
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16036
+ gr.drawLine(X, Y, 0, 0);
1576216037 break;
1576316038 }
1576416039