Normand Briere
2019-07-24 f555e2cacc4470c5b2217a14d40d2b39c4a57ba2
CameraPane.java
....@@ -18,7 +18,10 @@
1818 import javax.imageio.ImageIO;
1919 import javax.imageio.ImageWriteParam;
2020 import javax.imageio.ImageWriter;
21
+import javax.imageio.ImageReadParam;
22
+import javax.imageio.ImageReader;
2123 import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
24
+import javax.imageio.stream.ImageInputStream;
2225 import javax.imageio.stream.ImageOutputStream;
2326 import javax.imageio.ImageWriteParam;
2427
....@@ -30,6 +33,7 @@
3033 import java.nio.*;
3134
3235 import gleem.linalg.Mat4f;
36
+import javax.imageio.ImageTypeSpecifier;
3337
3438 class CameraPane extends GLCanvas implements iCameraPane, Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener
3539 {
....@@ -44,6 +48,39 @@
4448 static boolean ABORTED = false;
4549
4650 static int STEP = 1;
51
+
52
+ private static BufferedImage CreateBim(byte[] bytes, int width, int height)
53
+ {
54
+ int[] pixels = new int[bytes.length/3];
55
+ for (int i=pixels.length; --i>=0;)
56
+ {
57
+ int i3 = i*3;
58
+ pixels[i] = 0xFF;
59
+ pixels[i] <<= 8;
60
+ pixels[i] |= bytes[i3+2] & 0xFF;
61
+ pixels[i] <<= 8;
62
+ pixels[i] |= bytes[i3+1] & 0xFF;
63
+ pixels[i] <<= 8;
64
+ pixels[i] |= bytes[i3] & 0xFF;
65
+ }
66
+ /*
67
+ int r=0,g=0,b=0,a=0;
68
+ for (int i=0; i<width; i++)
69
+ for (int j=0; j<height; j++)
70
+ {
71
+ int index = j*width+i;
72
+ int p = pixels[index];
73
+ a = ((p>>24) & 0xFF);
74
+ r = ((p>>16) & 0xFF);
75
+ g = ((p>>8) & 0xFF);
76
+ b = (p & 0xFF);
77
+ pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
78
+ }
79
+ /**/
80
+ BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
81
+ rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
82
+ return rendImage;
83
+ }
4784
4885 /*static*/ private boolean CULLFACE = false; // true;
4986 /*static*/ boolean NEAREST = false; // true;
....@@ -60,7 +97,7 @@
6097 //boolean REDUCETEXTURE = true;
6198 boolean CACHETEXTURE = true;
6299 boolean CLEANCACHE = false; // true;
63
- boolean MIPMAP = false; // true;
100
+ boolean MIPMAP = false; // true; // never works...
64101 boolean COMPRESSTEXTURE = false;
65102 boolean KOMPACTTEXTURE = false; // true;
66103 boolean RESIZETEXTURE = false;
....@@ -2065,7 +2102,7 @@
20652102 //System.err.println("Oeil on");
20662103 OEIL = true;
20672104 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2068
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2105
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
20692106 //pingthread.StepToTarget(true);
20702107 }
20712108
....@@ -2298,10 +2335,17 @@
22982335 HANDLES ^= true;
22992336 }
23002337
2338
+ Object3D paintFolder;
2339
+
23012340 void TogglePaint()
23022341 {
23032342 PAINTMODE ^= true;
23042343 paintcount = 0;
2344
+
2345
+ if (PAINTMODE)
2346
+ {
2347
+ paintFolder = GetFolder();
2348
+ }
23052349 }
23062350
23072351 void SwapCamera(int a, int b)
....@@ -2398,6 +2442,21 @@
23982442 return currentGL;
23992443 }
24002444
2445
+ static private BufferedImage CreateBim(TextureData texturedata)
2446
+ {
2447
+ Grafreed.Assert(texturedata != null);
2448
+
2449
+ int width = texturedata.getWidth();
2450
+ int height = texturedata.getHeight();
2451
+
2452
+ Buffer buffer = texturedata.getBuffer();
2453
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2454
+
2455
+ byte[] bytes = bytebuf.array();
2456
+
2457
+ return CreateBim(bytes, width, height);
2458
+ }
2459
+
24012460 /**/
24022461 class CacheTexture
24032462 {
....@@ -2406,28 +2465,31 @@
24062465
24072466 int resolution;
24082467
2409
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2468
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
24102469 {
2411
- texture = tex;
2470
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2471
+ texturedata = texdata;
24122472 resolution = res;
24132473 }
24142474 }
24152475 /**/
24162476
24172477 // 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>();
2478
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2479
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2480
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2481
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2482
+
24212483 int pigmentdepth = 0;
24222484 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
24232485 int bumpdepth = 0;
24242486 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
24252487 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
24262488 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2427
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2489
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
24282490 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
24292491
2430
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2492
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
24312493 {
24322494 TextureData texturedata = null;
24332495
....@@ -2446,13 +2508,34 @@
24462508 if (bump)
24472509 texturedata = ConvertBump(texturedata, false);
24482510
2449
- com.sun.opengl.util.texture.Texture texture =
2450
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2511
+// com.sun.opengl.util.texture.Texture texture =
2512
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
24512513
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);
2514
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2515
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
24542516
2455
- return texture;
2517
+ return texturedata;
2518
+ }
2519
+
2520
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2521
+ {
2522
+ TextureData texturedata = null;
2523
+
2524
+ try
2525
+ {
2526
+ texturedata =
2527
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2528
+ bim,
2529
+ true);
2530
+ } catch (Exception e)
2531
+ {
2532
+ throw new javax.media.opengl.GLException(e);
2533
+ }
2534
+
2535
+ if (bump)
2536
+ texturedata = ConvertBump(texturedata, false);
2537
+
2538
+ return texturedata;
24562539 }
24572540
24582541 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3525,6 +3608,8 @@
35253608
35263609 System.out.println("LOADING TEXTURE : " + name);
35273610
3611
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3612
+
35283613 //
35293614 if (false) // compressbit > 0)
35303615 {
....@@ -7923,7 +8008,7 @@
79238008 String pigment = Object3D.GetPigment(tex);
79248009 String bump = Object3D.GetBump(tex);
79258010
7926
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8011
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79278012 {
79288013 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79298014 // System.out.println("; bump = " + bump);
....@@ -7938,8 +8023,8 @@
79388023 pigment = null;
79398024 }
79408025
7941
- ReleaseTexture(bump, true);
7942
- ReleaseTexture(pigment, false);
8026
+ ReleaseTexture(tex, true);
8027
+ ReleaseTexture(tex, false);
79438028 }
79448029
79458030 public void ReleasePigmentTexture(cTexture tex) // INTERFACE
....@@ -7957,7 +8042,7 @@
79578042
79588043 String pigment = Object3D.GetPigment(tex);
79598044
7960
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8045
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79618046 {
79628047 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79638048 // System.out.println("; bump = " + bump);
....@@ -7968,7 +8053,7 @@
79688053 pigment = null;
79698054 }
79708055
7971
- ReleaseTexture(pigment, false);
8056
+ ReleaseTexture(tex, false);
79728057 }
79738058
79748059 public void ReleaseBumpTexture(cTexture tex) // INTERFACE
....@@ -7986,7 +8071,7 @@
79868071
79878072 String bump = Object3D.GetBump(tex);
79888073
7989
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8074
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79908075 {
79918076 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79928077 // System.out.println("; bump = " + bump);
....@@ -7997,10 +8082,10 @@
79978082 bump = null;
79988083 }
79998084
8000
- ReleaseTexture(bump, true);
8085
+ ReleaseTexture(tex, true);
80018086 }
80028087
8003
- void ReleaseTexture(String tex, boolean bump)
8088
+ void ReleaseTexture(cTexture tex, boolean bump)
80048089 {
80058090 if (// DrawMode() != 0 || /*tex == null ||*/
80068091 ambientOcclusion ) // || !textureon)
....@@ -8011,7 +8096,7 @@
80118096 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
80128097
80138098 if (tex != null)
8014
- texture = textures.get(tex);
8099
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
80158100
80168101 // //assert( texture != null );
80178102 // if (texture == null)
....@@ -8105,47 +8190,50 @@
81058190
81068191 /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
81078192 {
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
- }
8193
+// if (// DrawMode() != 0 || /*tex == null ||*/
8194
+// ambientOcclusion ) // || !textureon)
8195
+// {
8196
+// return; // false;
8197
+// }
8198
+//
8199
+// if (tex == null)
8200
+// {
8201
+// BindTexture(null,false,resolution);
8202
+// BindTexture(null,true,resolution);
8203
+// return;
8204
+// }
8205
+//
8206
+// String pigment = Object3D.GetPigment(tex);
8207
+// String bump = Object3D.GetBump(tex);
8208
+//
8209
+// usedtextures.add(pigment);
8210
+// usedtextures.add(bump);
8211
+//
8212
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8213
+// {
8214
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8215
+// // System.out.println("; bump = " + bump);
8216
+// }
8217
+//
8218
+// if (bump.equals(""))
8219
+// {
8220
+// bump = null;
8221
+// }
8222
+// if (pigment.equals(""))
8223
+// {
8224
+// pigment = null;
8225
+// }
8226
+//
8227
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8228
+// BindTexture(pigment, false, resolution);
8229
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8230
+// BindTexture(bump, true, resolution);
8231
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8232
+//
8233
+// return; // true;
81208234
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;
8235
+ BindPigmentTexture(tex, resolution);
8236
+ BindBumpTexture(tex, resolution);
81498237 }
81508238
81518239 /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8164,9 +8252,9 @@
81648252
81658253 String pigment = Object3D.GetPigment(tex);
81668254
8167
- usedtextures.put(pigment, pigment);
8255
+ usedtextures.add(tex);
81688256
8169
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8257
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
81708258 {
81718259 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
81728260 // System.out.println("; bump = " + bump);
....@@ -8178,7 +8266,7 @@
81788266 }
81798267
81808268 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8181
- BindTexture(pigment, false, resolution);
8269
+ BindTexture(tex, false, resolution);
81828270 }
81838271
81848272 /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8197,9 +8285,9 @@
81978285
81988286 String bump = Object3D.GetBump(tex);
81998287
8200
- usedtextures.put(bump, bump);
8288
+ usedtextures.add(tex);
82018289
8202
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8290
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
82038291 {
82048292 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
82058293 // System.out.println("; bump = " + bump);
....@@ -8211,7 +8299,7 @@
82118299 }
82128300
82138301 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8214
- BindTexture(bump, true, resolution);
8302
+ BindTexture(tex, true, resolution);
82158303 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
82168304 }
82178305
....@@ -8235,13 +8323,19 @@
82358323 return fileExists;
82368324 }
82378325
8238
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception
8326
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
82398327 {
8240
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8328
+ CacheTexture texturecache = null;
82418329
82428330 if (tex != null)
82438331 {
8244
- String texname = tex;
8332
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8333
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
8334
+
8335
+ if (texname.equals("") && texdata == null)
8336
+ {
8337
+ return null;
8338
+ }
82458339
82468340 String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
82478341
....@@ -8251,19 +8345,46 @@
82518345 // else
82528346 // if (!texname.startsWith("/"))
82538347 // texname = "/Users/nbriere/Textures/" + texname;
8254
- if (!FileExists(tex))
8348
+ if (!FileExists(texname))
82558349 {
82568350 texname = fallbackTextureName;
82578351 }
82588352
82598353 if (CACHETEXTURE)
8260
- texture = textures.get(texname); // TEXTURE CACHE
8261
-
8262
- TextureData texturedata = null;
8263
-
8264
- if (texture == null || texture.resolution < resolution)
82658354 {
8266
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8355
+ if (texdata == null)
8356
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8357
+ else
8358
+ texturecache = bimtextures.get(texdata);
8359
+ }
8360
+
8361
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8362
+ {
8363
+ TextureData texturedata = null;
8364
+
8365
+ if (texdata != null && textureon)
8366
+ {
8367
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8368
+
8369
+ try
8370
+ {
8371
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8372
+ }
8373
+ catch (Exception e)
8374
+ {
8375
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8376
+ }
8377
+
8378
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8379
+ bimtextures.put(texdata, texturecache);
8380
+
8381
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8382
+
8383
+ //Object bim2 = CreateBim(texturecache.texturedata);
8384
+ //bim2 = bim;
8385
+ }
8386
+ else
8387
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
82678388 {
82688389 assert(!bump);
82698390 // if (bump)
....@@ -8274,19 +8395,23 @@
82748395 // }
82758396 // else
82768397 // {
8277
- texture = textures.get(tex);
8278
- if (texture == null)
8398
+ // texturecache = textures.get(texname); // suspicious
8399
+ if (texturecache == null)
82798400 {
8280
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8401
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
82818402 }
8403
+ else
8404
+ new Exception().printStackTrace();
82828405 // }
82838406 } else
8284
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8407
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
82858408 {
82868409 assert(bump);
8287
- texture = textures.get(tex);
8288
- if (texture == null)
8289
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8410
+ // texturecache = textures.get(texname); // suspicious
8411
+ if (texturecache == null)
8412
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8413
+ else
8414
+ new Exception().printStackTrace();
82908415 } else
82918416 {
82928417 //if (tex.equals("IMMORTAL"))
....@@ -8294,11 +8419,13 @@
82948419 // texture = GetResourceTexture("default.png");
82958420 //} else
82968421 //{
8297
- if (tex.equals("WHITE_NOISE"))
8422
+ if (texname.endsWith("WHITE_NOISE"))
82988423 {
8299
- texture = textures.get(tex);
8300
- if (texture == null)
8301
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8424
+ // texturecache = textures.get(texname); // suspicious
8425
+ if (texturecache == null)
8426
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8427
+ else
8428
+ new Exception().printStackTrace();
83028429 } else
83038430 {
83048431 if (textureon)
....@@ -8357,19 +8484,19 @@
83578484 if (texturedata == null)
83588485 throw new Exception();
83598486
8360
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8487
+ texturecache = new CacheTexture(texturedata,resolution);
83618488 //texture = GetTexture(tex, bump);
83628489 }
83638490 }
83648491 //}
83658492 }
83668493
8367
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8494
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
83688495 {
83698496 //return false;
83708497
83718498 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8372
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8499
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
83738500 {
83748501 // String ext = "_highres";
83758502 // if (REDUCETEXTURE)
....@@ -8386,52 +8513,17 @@
83868513 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
83878514 if (!cachefile.exists())
83888515 {
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))
8516
+ //if (texturedata.getWidth() == texturedata.getHeight())
83988517 {
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);
8518
+ BufferedImage rendImage = CreateBim(texturedata);
8519
+
84298520 ImageWriter writer = null;
84308521 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
84318522 if (iter.hasNext()) {
84328523 writer = (ImageWriter)iter.next();
84338524 }
8434
- float compressionQuality = 0.9f;
8525
+
8526
+ float compressionQuality = 0.85f;
84358527 try
84368528 {
84378529 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8448,18 +8540,20 @@
84488540 }
84498541 }
84508542 }
8451
-
8543
+
8544
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8545
+
84528546 //System.out.println("Texture = " + tex);
8453
- if (textures.containsKey(texname))
8547
+ if (textures.containsKey(tex))
84548548 {
8455
- CacheTexture thetex = textures.get(texname);
8549
+ CacheTexture thetex = textures.get(tex);
84568550 thetex.texture.disable();
84578551 thetex.texture.dispose();
8458
- textures.remove(texname);
8552
+ textures.remove(tex);
84598553 }
84608554
8461
- texture.texturedata = texturedata;
8462
- textures.put(texname, texture);
8555
+ //texture.texturedata = texturedata;
8556
+ textures.put(tex, texturecache);
84638557
84648558 // newtex = true;
84658559 }
....@@ -8475,10 +8569,44 @@
84758569 }
84768570 }
84778571
8478
- return texture;
8572
+ return texturecache;
84798573 }
84808574
8481
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution) throws Exception
8575
+ static void EmbedTextures(cTexture tex)
8576
+ {
8577
+ if (tex.pigmentdata == null)
8578
+ {
8579
+ //String texname = Object3D.GetPigment(tex);
8580
+
8581
+ CacheTexture texturecache = texturepigment.get(tex);
8582
+
8583
+ if (texturecache != null)
8584
+ {
8585
+ tex.pw = texturecache.texturedata.getWidth();
8586
+ tex.ph = texturecache.texturedata.getHeight();
8587
+ tex.pigmentdata = //CompressJPEG(CreateBim
8588
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8589
+ ;
8590
+ //, tex.pw, tex.ph), 0.5f);
8591
+ }
8592
+ }
8593
+
8594
+ if (tex.bumpdata == null)
8595
+ {
8596
+ //String texname = Object3D.GetBump(tex);
8597
+
8598
+ CacheTexture texturecache = texturebump.get(tex);
8599
+
8600
+ if (texturecache != null)
8601
+ {
8602
+ tex.bw = texturecache.texturedata.getWidth();
8603
+ tex.bh = texturecache.texturedata.getHeight();
8604
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8605
+ }
8606
+ }
8607
+ }
8608
+
8609
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
84828610 {
84838611 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
84848612
....@@ -8496,21 +8624,21 @@
84968624 return texture!=null?texture.texture:null;
84978625 }
84988626
8499
- public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution) throws Exception
8627
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
85008628 {
85018629 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
85028630
85038631 return texture!=null?texture.texturedata:null;
85048632 }
85058633
8506
- boolean BindTexture(String tex, boolean bump, int resolution) throws Exception
8634
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
85078635 {
85088636 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
85098637 {
85108638 return false;
85118639 }
85128640
8513
- boolean newtex = false;
8641
+ //boolean newtex = false;
85148642
85158643 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
85168644
....@@ -8542,9 +8670,75 @@
85428670 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
85438671 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
85448672
8545
- return newtex;
8673
+ return true; // Warning: not used.
85468674 }
85478675
8676
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8677
+ {
8678
+ try
8679
+ {
8680
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8681
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8682
+ ImageWriter writer = writers.next();
8683
+
8684
+ ImageWriteParam param = writer.getDefaultWriteParam();
8685
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8686
+ param.setCompressionQuality(quality);
8687
+
8688
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8689
+ writer.setOutput(ios);
8690
+ writer.write(null, new IIOImage(image, null, null), param);
8691
+
8692
+ byte[] data = baos.toByteArray();
8693
+ writer.dispose();
8694
+ return data;
8695
+ }
8696
+ catch (Exception e)
8697
+ {
8698
+ e.printStackTrace();
8699
+ return null;
8700
+ }
8701
+ }
8702
+
8703
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8704
+ {
8705
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8706
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8707
+ ImageReader reader = writers.next();
8708
+
8709
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8710
+
8711
+ ImageReadParam param = reader.getDefaultReadParam();
8712
+ param.setDestination(bim);
8713
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8714
+
8715
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8716
+ reader.setInput(ios);
8717
+ BufferedImage bim2 = reader.read(0, param);
8718
+ reader.dispose();
8719
+
8720
+// WritableRaster raster = bim2.getRaster();
8721
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8722
+// byte[] bytes = data.getData();
8723
+//
8724
+// int[] pixels = new int[bytes.length/3];
8725
+// for (int i=pixels.length; --i>=0;)
8726
+// {
8727
+// int i3 = i*3;
8728
+// pixels[i] = 0xFF;
8729
+// pixels[i] <<= 8;
8730
+// pixels[i] |= bytes[i3+2] & 0xFF;
8731
+// pixels[i] <<= 8;
8732
+// pixels[i] |= bytes[i3+1] & 0xFF;
8733
+// pixels[i] <<= 8;
8734
+// pixels[i] |= bytes[i3] & 0xFF;
8735
+// }
8736
+//
8737
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8738
+
8739
+ return bim;
8740
+ }
8741
+
85488742 ShadowBuffer shadowPBuf;
85498743 AntialiasBuffer antialiasPBuf;
85508744 int MAXSTACK;
....@@ -11028,9 +11222,9 @@
1102811222
1102911223 gl.glMatrixMode(GL.GL_MODELVIEW);
1103011224
11031
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11032
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
11033
-//gl.glEnable(gl.GL_MULTISAMPLE);
11225
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11226
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11227
+gl.glEnable(gl.GL_MULTISAMPLE);
1103411228 } else
1103511229 {
1103611230 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -11041,7 +11235,7 @@
1104111235 //System.out.println("BLENDING ON");
1104211236 gl.glEnable(GL.GL_BLEND);
1104311237 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
11044
-
11238
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1104511239 gl.glMatrixMode(gl.GL_PROJECTION);
1104611240 gl.glLoadIdentity();
1104711241
....@@ -11290,7 +11484,7 @@
1129011484 }
1129111485 }
1129211486
11293
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11487
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1129411488 {
1129511489 //gl.glDepthFunc(GL.GL_LEQUAL);
1129611490 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11298,24 +11492,21 @@
1129811492
1129911493 boolean texon = textureon;
1130011494
11301
- if (RENDERPROGRAM > 0)
11302
- {
11303
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11304
- textureon = false;
11305
- }
11495
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11496
+ textureon = false;
11497
+
1130611498 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1130711499 //System.out.println("ALLO");
1130811500 gl.glColorMask(false, false, false, false);
1130911501 DrawObject(gl);
11310
- if (RENDERPROGRAM > 0)
11311
- {
11312
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11313
- textureon = texon;
11314
- }
11502
+
11503
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11504
+ textureon = texon;
11505
+
1131511506 gl.glColorMask(true, true, true, true);
1131611507
1131711508 gl.glDepthFunc(GL.GL_EQUAL);
11318
- //gl.glDepthMask(false);
11509
+ gl.glDepthMask(false);
1131911510 }
1132011511
1132111512 if (false) // DrawMode() == SHADOW)
....@@ -11527,7 +11718,7 @@
1152711718 if ((TRACK || SHADOWTRACK) || zoomonce)
1152811719 {
1152911720 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11530
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11721
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1153111722 pingthread.StepToTarget(true); // true);
1153211723 // zoomonce = false;
1153311724 }
....@@ -11655,20 +11846,32 @@
1165511846 ReleaseTextures(DEFAULT_TEXTURES);
1165611847
1165711848 if (CLEANCACHE)
11658
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11849
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1165911850 {
11660
- String tex = e.nextElement();
11851
+ cTexture tex = e.nextElement();
1166111852
1166211853 // System.out.println("Texture --------- " + tex);
1166311854
11664
- if (tex.equals("WHITE_NOISE"))
11855
+ if (tex.equals("WHITE_NOISE:"))
1166511856 continue;
1166611857
11667
- if (!usedtextures.containsKey(tex))
11858
+ if (!usedtextures.contains(tex))
1166811859 {
11860
+ CacheTexture gettex = texturepigment.get(tex);
1166911861 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11670
- textures.get(tex).texture.dispose();
11671
- textures.remove(tex);
11862
+ if (gettex != null)
11863
+ {
11864
+ gettex.texture.dispose();
11865
+ texturepigment.remove(tex);
11866
+ }
11867
+
11868
+ gettex = texturebump.get(tex);
11869
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11870
+ if (gettex != null)
11871
+ {
11872
+ gettex.texture.dispose();
11873
+ texturebump.remove(tex);
11874
+ }
1167211875 }
1167311876 }
1167411877 }
....@@ -12197,7 +12400,52 @@
1219712400 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1219812401
1219912402 String program =
12403
+ // Min shader
1220012404 "!!ARBfp1.0\n" +
12405
+ "PARAM zero123 = { 0.0, 1.0, 2.0, 1.25 };" +
12406
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12407
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12408
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12409
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12410
+ "TEMP temp;" +
12411
+ "TEMP light;" +
12412
+ "TEMP ndotl;" +
12413
+ "TEMP normal;" +
12414
+ "TEMP depth;" +
12415
+
12416
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12417
+
12418
+ "MOV light, state.light[0].position;" +
12419
+ "DP3 ndotl.x, light, normal;" +
12420
+
12421
+ // shadow
12422
+ "MOV temp, fragment.texcoord[1];" +
12423
+ TextureFetch("depth", "temp", "1") +
12424
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12425
+ "SLT temp.x, fragment.texcoord[1].z, depth.z;" +
12426
+
12427
+
12428
+ // No shadow when out of frustum
12429
+ //"SGE temp.y, depth.z, zero123.y;" +
12430
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12431
+
12432
+ "MUL ndotl.x, ndotl.x, temp.x;" +
12433
+ "MAX ndotl.x, ndotl.x, pow2.y;" +
12434
+
12435
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12436
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12437
+ "MUL temp, temp, ndotl.x;" +
12438
+
12439
+ "MUL temp, temp, zero123.z;" +
12440
+
12441
+ "MOV temp.w, zero123.y;" + // reset alpha
12442
+
12443
+ "MOV result.color, temp;" +
12444
+ "END";
12445
+
12446
+ String program2 =
12447
+ "!!ARBfp1.0\n" +
12448
+
1220112449 //"OPTION ARB_fragment_program_shadow;" +
1220212450 "PARAM light2cam0 = program.env[10];" +
1220312451 "PARAM light2cam1 = program.env[11];" +
....@@ -12312,8 +12560,7 @@
1231212560 "TEMP shininess;" +
1231312561 "\n" +
1231412562 "MOV texSamp, one;" +
12315
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12316
-
12563
+
1231712564 "MOV mapgrid.x, one2048th.x;" +
1231812565 "MOV temp, fragment.texcoord[1];" +
1231912566 /*
....@@ -12718,7 +12965,7 @@
1271812965 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1271912966 "") +
1272012967
12721
- // display shadow only (bump == 0)
12968
+ // display shadow only (fakedepth == 0)
1272212969 "SUB temp.x, half.x, shadow.x;" +
1272312970 "MOV temp.y, -params5.z;" + // params6.x;" +
1272412971 "SLT temp.z, temp.y, -one2048th.x;" +
....@@ -13150,20 +13397,20 @@
1315013397 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1315113398 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1315213399 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13400
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13401
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1315313402 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13154
- "SLT " + src + ".z, " + src + ".x, one.x;" +
13155
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13156
- "SLT " + src + ".z, " + src + ".y, one.x;" +
13157
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13403
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13404
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1315813405 //"SWZ buffer, temp, w,w,w,w;";
13159
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13406
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1316013407 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1316113408 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1316213409 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13163
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13410
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1316413411
13165
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13166
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13412
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13413
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1316713414 }
1316813415
1316913416 String Shadow(String depth, String shadow)
....@@ -13210,7 +13457,7 @@
1321013457 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1321113458 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1321213459
13213
- // No shadow when out of frustrum
13460
+ // No shadow when out of frustum
1321413461 "SGE temp.x, " + depth + ".z, one.z;" +
1321513462 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1321613463 "";
....@@ -13375,9 +13622,10 @@
1337513622 "DP3 " + dest + ".z," + "normals," + "eye;" +
1337613623 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1337713624 //"MOV " + dest + ".w," + "normal.z;" +
13378
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
13379
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13380
- //"MOV " + dest + ".z," + "params2.w;" +
13625
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13626
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13627
+
13628
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1338113629 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1338213630 "RCP " + dest + ".w," + dest + ".w;" +
1338313631 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13942,7 +14190,7 @@
1394214190
1394314191 // fev 2014???
1394414192 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13945
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14193
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1394614194 pingthread.StepToTarget(true); // true);
1394714195 }
1394814196 // if (!LIVE)
....@@ -14007,14 +14255,15 @@
1400714255 drag = false;
1400814256 //System.out.println("Mouse DOWN");
1400914257 editObj = false;
14010
- ClickInfo info = new ClickInfo();
14011
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14012
- info.pane = this;
14013
- info.camera = renderCamera;
14014
- info.x = x;
14015
- info.y = y;
14016
- info.modifiers = modifiersex;
14017
- editObj = object.doEditClick(info, 0);
14258
+ //ClickInfo info = new ClickInfo();
14259
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14260
+ object.clickInfo.pane = this;
14261
+ object.clickInfo.camera = renderCamera;
14262
+ object.clickInfo.x = x;
14263
+ object.clickInfo.y = y;
14264
+ object.clickInfo.modifiers = modifiersex;
14265
+ editObj = object.doEditClick(//info,
14266
+ 0);
1401814267 if (!editObj)
1401914268 {
1402014269 hasMarquee = true;
....@@ -14296,12 +14545,12 @@
1429614545 void GoDown(int mod)
1429714546 {
1429814547 MODIFIERS |= COMMAND;
14299
- /*
14548
+ /**/
1430014549 if((mod&SHIFT) == SHIFT)
1430114550 manipCamera.RotatePosition(0, -speed);
1430214551 else
14303
- manipCamera.BackForth(0, -speed*delta, getWidth());
14304
- */
14552
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14553
+ /**/
1430514554 if ((mod & SHIFT) == SHIFT)
1430614555 {
1430714556 mouseMode = mouseMode; // VR??
....@@ -14317,12 +14566,12 @@
1431714566 void GoUp(int mod)
1431814567 {
1431914568 MODIFIERS |= COMMAND;
14320
- /*
14569
+ /**/
1432114570 if((mod&SHIFT) == SHIFT)
1432214571 manipCamera.RotatePosition(0, speed);
1432314572 else
14324
- manipCamera.BackForth(0, speed*delta, getWidth());
14325
- */
14573
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14574
+ /**/
1432614575 if ((mod & SHIFT) == SHIFT)
1432714576 {
1432814577 mouseMode = mouseMode;
....@@ -14338,12 +14587,12 @@
1433814587 void GoLeft(int mod)
1433914588 {
1434014589 MODIFIERS |= COMMAND;
14341
- /*
14590
+ /**/
1434214591 if((mod&SHIFT) == SHIFT)
14343
- manipCamera.RotatePosition(speed, 0);
14344
- else
1434514592 manipCamera.Translate(speed*delta, 0, getWidth());
14346
- */
14593
+ else
14594
+ manipCamera.RotatePosition(speed, 0);
14595
+ /**/
1434714596 if ((mod & SHIFT) == SHIFT)
1434814597 {
1434914598 mouseMode = mouseMode;
....@@ -14359,12 +14608,12 @@
1435914608 void GoRight(int mod)
1436014609 {
1436114610 MODIFIERS |= COMMAND;
14362
- /*
14611
+ /**/
1436314612 if((mod&SHIFT) == SHIFT)
14364
- manipCamera.RotatePosition(-speed, 0);
14365
- else
1436614613 manipCamera.Translate(-speed*delta, 0, getWidth());
14367
- */
14614
+ else
14615
+ manipCamera.RotatePosition(-speed, 0);
14616
+ /**/
1436814617 if ((mod & SHIFT) == SHIFT)
1436914618 {
1437014619 mouseMode = mouseMode;
....@@ -14414,15 +14663,16 @@
1441414663 if (editObj)
1441514664 {
1441614665 drag = true;
14417
- ClickInfo info = new ClickInfo();
14418
- info.bounds.setBounds(0, 0,
14666
+ //ClickInfo info = new ClickInfo();
14667
+ object.clickInfo.bounds.setBounds(0, 0,
1441914668 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14420
- info.pane = this;
14421
- info.camera = renderCamera;
14422
- info.x = x;
14423
- info.y = y;
14424
- object.GetWindow().copy
14425
- .doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
14669
+ object.clickInfo.pane = this;
14670
+ object.clickInfo.camera = renderCamera;
14671
+ object.clickInfo.x = x;
14672
+ object.clickInfo.y = y;
14673
+ object //.GetWindow().copy
14674
+ .doEditDrag(//info,
14675
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1442614676 } else
1442714677 {
1442814678 if (x < startX)
....@@ -14571,24 +14821,27 @@
1457114821 }
1457214822 }
1457314823
14824
+// ClickInfo clickInfo = new ClickInfo();
14825
+
1457414826 public void mouseMoved(MouseEvent e)
1457514827 {
1457614828 //System.out.println("mouseMoved: " + e);
1457714829 if (isRenderer)
1457814830 return;
1457914831
14580
- ClickInfo ci = new ClickInfo();
14581
- ci.x = e.getX();
14582
- ci.y = e.getY();
14583
- ci.modifiers = e.getModifiersEx();
14584
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14585
- ci.pane = this;
14586
- ci.camera = renderCamera;
14832
+ // Mouse cursor feedback
14833
+ object.clickInfo.x = e.getX();
14834
+ object.clickInfo.y = e.getY();
14835
+ object.clickInfo.modifiers = e.getModifiersEx();
14836
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14837
+ object.clickInfo.pane = this;
14838
+ object.clickInfo.camera = renderCamera;
1458714839 if (!isRenderer)
1458814840 {
1458914841 //ObjEditor editWindow = object.editWindow;
1459014842 //Object3D copy = editWindow.copy;
14591
- if (object.doEditClick(ci, 0))
14843
+ if (object.doEditClick(//clickInfo,
14844
+ 0))
1459214845 {
1459314846 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1459414847 } else
....@@ -14603,7 +14856,8 @@
1460314856 Globals.MOUSEDRAGGED = false;
1460414857
1460514858 movingcamera = false;
14606
- X = Y = 0;
14859
+ X = 0; // getBounds().width/2;
14860
+ Y = 0; // getBounds().height/2;
1460714861 //System.out.println("mouseReleased: " + e);
1460814862 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1460914863 }
....@@ -14859,7 +15113,8 @@
1485915113 // break;
1486015114 case 'T':
1486115115 CACHETEXTURE ^= true;
14862
- textures.clear();
15116
+ texturepigment.clear();
15117
+ texturebump.clear();
1486315118 // repaint();
1486415119 break;
1486515120 case 'Y':
....@@ -14944,7 +15199,9 @@
1494415199 case 'E' : COMPACT ^= true;
1494515200 repaint();
1494615201 break;
14947
- case 'W' : DEBUGHSB ^= true;
15202
+ case 'W' : // Wide Window (fullscreen)
15203
+ //DEBUGHSB ^= true;
15204
+ ObjEditor.theFrame.ToggleFullScreen();
1494815205 repaint();
1494915206 break;
1495015207 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14970,13 +15227,7 @@
1497015227 repaint();
1497115228 break;
1497215229 case 'l':
14973
- lightMode ^= true;
14974
- Globals.lighttouched = true;
14975
- manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
14976
- targetLookAt.set(manipCamera.lookAt);
14977
- repaint();
14978
- break;
14979
- case 'L':
15230
+ //case 'L':
1498015231 if (lightMode)
1498115232 {
1498215233 lightMode = false;
....@@ -15119,11 +15370,14 @@
1511915370 case '_':
1512015371 kompactbit = 5;
1512115372 break;
15122
- case '+':
15123
- kompactbit = 6;
15124
- break;
15373
+// case '+':
15374
+// kompactbit = 6;
15375
+// break;
1512515376 case ' ':
15126
- ObjEditor.theFrame.ToggleFullScreen();
15377
+ lightMode ^= true;
15378
+ Globals.lighttouched = true;
15379
+ manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
15380
+ targetLookAt.set(manipCamera.lookAt);
1512715381 repaint();
1512815382 break;
1512915383 //case '`' :
....@@ -15170,8 +15424,9 @@
1517015424 case DELETE:
1517115425 ClearSelection();
1517215426 break;
15173
- /*
1517415427 case '+':
15428
+
15429
+ /*
1517515430 //fontsize += 1;
1517615431 bbzoom *= 2;
1517715432 repaint();
....@@ -15188,17 +15443,17 @@
1518815443 case '=':
1518915444 IncDepth();
1519015445 //fontsize += 1;
15191
- object.editWindow.refreshContents(true);
15446
+ object.GetWindow().refreshContents(true);
1519215447 maskbit = 6;
1519315448 break;
1519415449 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1519515450 DecDepth();
1519615451 maskbit = 5;
1519715452 //if(fontsize > 1) fontsize -= 1;
15198
- if (object.editWindow == null)
15199
- new Exception().printStackTrace();
15200
- else
15201
- object.editWindow.refreshContents(true);
15453
+// if (object.editWindow == null)
15454
+// new Exception().printStackTrace();
15455
+// else
15456
+ object.GetWindow().refreshContents(true);
1520215457 break;
1520315458 case '{':
1520415459 manipCamera.shaper_fovy /= 1.1;
....@@ -15422,7 +15677,7 @@
1542215677 }
1542315678 */
1542415679
15425
- object.editWindow.EditSelection(false);
15680
+ object.GetWindow().EditSelection(false);
1542615681 }
1542715682
1542815683 void SelectParent()
....@@ -15439,10 +15694,10 @@
1543915694 {
1544015695 //selectees.remove(i);
1544115696 System.out.println("select parent of " + elem);
15442
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15697
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1544315698 } else
1544415699 {
15445
- group.editWindow.Select(elem.GetTreePath(), first, true);
15700
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1544615701 }
1544715702
1544815703 first = false;
....@@ -15484,12 +15739,12 @@
1548415739 for (int j = 0; j < group.children.size(); j++)
1548515740 {
1548615741 elem = (Object3D) group.children.elementAt(j);
15487
- object.editWindow.Select(elem.GetTreePath(), first, true);
15742
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1548815743 first = false;
1548915744 }
1549015745 } else
1549115746 {
15492
- object.editWindow.Select(elem.GetTreePath(), first, true);
15747
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1549315748 }
1549415749
1549515750 first = false;
....@@ -15500,21 +15755,21 @@
1550015755 {
1550115756 //Composite group = (Composite) object;
1550215757 Object3D group = object;
15503
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15758
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1550415759 }
1550515760
1550615761 void ResetTransform(int mask)
1550715762 {
1550815763 //Composite group = (Composite) object;
1550915764 Object3D group = object;
15510
- group.editWindow.ResetTransform(mask);
15765
+ group.GetWindow().ResetTransform(mask);
1551115766 }
1551215767
1551315768 void FlipTransform()
1551415769 {
1551515770 //Composite group = (Composite) object;
1551615771 Object3D group = object;
15517
- group.editWindow.FlipTransform();
15772
+ group.GetWindow().FlipTransform();
1551815773 // group.editWindow.ReduceMesh(true);
1551915774 }
1552015775
....@@ -15522,7 +15777,7 @@
1552215777 {
1552315778 //Composite group = (Composite) object;
1552415779 Object3D group = object;
15525
- group.editWindow.PrintMemory();
15780
+ group.GetWindow().PrintMemory();
1552615781 // group.editWindow.ReduceMesh(true);
1552715782 }
1552815783
....@@ -15530,7 +15785,7 @@
1553015785 {
1553115786 //Composite group = (Composite) object;
1553215787 Object3D group = object;
15533
- group.editWindow.ResetCentroid();
15788
+ group.GetWindow().ResetCentroid();
1553415789 }
1553515790
1553615791 void IncDepth()
....@@ -15612,8 +15867,6 @@
1561215867
1561315868 int width = getBounds().width;
1561415869 int height = getBounds().height;
15615
- ClickInfo info = new ClickInfo();
15616
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1561715870 //Image img = CreateImage(width, height);
1561815871 //System.out.println("width = " + width + "; height = " + height + "\n");
1561915872
....@@ -15690,48 +15943,77 @@
1569015943 }
1569115944 if (object != null && !hasMarquee)
1569215945 {
15946
+ if (object.clickInfo == null)
15947
+ object.clickInfo = new ClickInfo();
15948
+ ClickInfo info = object.clickInfo;
15949
+ //ClickInfo info = new ClickInfo();
15950
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
15951
+
1569315952 if (isRenderer)
1569415953 {
15695
- info.flags++;
15954
+ object.clickInfo.flags++;
1569615955 double frameAspect = (double) width / (double) height;
1569715956 if (frameAspect > renderCamera.aspect)
1569815957 {
1569915958 int desired = (int) ((double) height * renderCamera.aspect);
15700
- info.bounds.width -= width - desired;
15701
- info.bounds.x += (width - desired) / 2;
15959
+ object.clickInfo.bounds.width -= width - desired;
15960
+ object.clickInfo.bounds.x += (width - desired) / 2;
1570215961 } else
1570315962 {
1570415963 int desired = (int) ((double) width / renderCamera.aspect);
15705
- info.bounds.height -= height - desired;
15706
- info.bounds.y += (height - desired) / 2;
15964
+ object.clickInfo.bounds.height -= height - desired;
15965
+ object.clickInfo.bounds.y += (height - desired) / 2;
1570715966 }
1570815967 }
15709
- info.g = gr;
15710
- info.camera = renderCamera;
15968
+
15969
+ object.clickInfo.g = gr;
15970
+ object.clickInfo.camera = renderCamera;
1571115971 /*
1571215972 // Memory intensive (brep.verticescopy)
1571315973 if (!(object instanceof Composite))
1571415974 object.draw(info, 0, false); // SLOW :
1571515975 */
15716
- if (!isRenderer)
15976
+ if (!isRenderer) // && drag)
1571715977 {
15718
- object.drawEditHandles(info, 0);
15719
-
15720
- if (drag && (X != 0 || Y != 0) && object.selection.Size() > 0)
15978
+ Grafreed.Assert(object != null);
15979
+ Grafreed.Assert(object.selection != null);
15980
+ if (object.selection.Size() > 0)
1572115981 {
15722
- switch (object.selection.get(0).hitSomething)
15982
+ int hitSomething = object.selection.get(0).hitSomething;
15983
+
15984
+ object.clickInfo.DX = 0;
15985
+ object.clickInfo.DY = 0;
15986
+ object.clickInfo.W = 1;
15987
+ if (hitSomething == Object3D.hitCenter)
1572315988 {
15724
- case Object3D.hitCenter: gr.setColor(Color.pink);
15725
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15726
- break;
15727
- case Object3D.hitRotate: gr.setColor(Color.yellow);
15728
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15729
- break;
15730
- case Object3D.hitScale: gr.setColor(Color.cyan);
15731
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15732
- break;
15989
+ info.DX = X;
15990
+ if (X != 0)
15991
+ info.DX -= info.bounds.width/2;
15992
+
15993
+ info.DY = Y;
15994
+ if (Y != 0)
15995
+ info.DY -= info.bounds.height/2;
1573315996 }
15734
-
15997
+
15998
+ object.drawEditHandles(//info,
15999
+ 0);
16000
+
16001
+ if (drag && (X != 0 || Y != 0))
16002
+ {
16003
+ switch (hitSomething)
16004
+ {
16005
+ case Object3D.hitCenter: gr.setColor(Color.pink);
16006
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16007
+ break;
16008
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16009
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16010
+ break;
16011
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16012
+ gr.drawLine(X, Y, 0, 0);
16013
+ break;
16014
+ }
16015
+
16016
+ }
1573516017 }
1573616018 }
1573716019 }
....@@ -16529,6 +16811,14 @@
1652916811 }
1653016812 }
1653116813
16814
+ private Object3D GetFolder()
16815
+ {
16816
+ Object3D folder = object.GetWindow().copy;
16817
+ if (object.GetWindow().copy.selection.Size() > 0)
16818
+ folder = object.GetWindow().copy.selection.elementAt(0);
16819
+ return folder;
16820
+ }
16821
+
1653216822 class SelectBuffer implements GLEventListener
1653316823 {
1653416824
....@@ -16608,6 +16898,17 @@
1660816898
1660916899 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1661016900
16901
+ if (PAINTMODE)
16902
+ {
16903
+ if (object.GetWindow().copy.selection.Size() > 0)
16904
+ {
16905
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16906
+
16907
+ // Make what you paint not selectable.
16908
+ paintobj.ResetSelectable();
16909
+ }
16910
+ }
16911
+
1661116912 //int tmp = selection_view;
1661216913 //selection_view = -1;
1661316914 int temp = DrawMode();
....@@ -16619,6 +16920,17 @@
1661916920 // temp = DEFAULT; // patch for selection debug
1662016921 Globals.drawMode = temp; // WARNING
1662116922
16923
+ if (PAINTMODE)
16924
+ {
16925
+ if (object.GetWindow().copy.selection.Size() > 0)
16926
+ {
16927
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16928
+
16929
+ // Revert.
16930
+ paintobj.RestoreSelectable();
16931
+ }
16932
+ }
16933
+
1662216934 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1662316935
1662416936 // trying different ways of getting the depth info over
....@@ -16722,29 +17034,31 @@
1672217034 }
1672317035
1672417036 if (!movingcamera && !PAINTMODE)
16725
- object.editWindow.ScreenFitPoint(); // fev 2014
17037
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1672617038
16727
- if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17039
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1672817040 {
16729
- Object3D paintobj = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17041
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1673017042
16731
- Object3D group = new Object3D("inst" + paintcount++);
17043
+ if (object.GetWindow().copy.selection.Size() > 0)
17044
+ {
17045
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1673217046
16733
- group.CreateMaterial(); // use a void leaf to select instances
16734
-
16735
- group.add(paintobj); // link
16736
-
16737
- object.editWindow.SnapObject(group);
16738
-
16739
- Object3D folder = object.editWindow.copy;
16740
-
16741
- if (object.editWindow.copy.selection.Size() > 0)
16742
- folder = object.editWindow.copy.selection.elementAt(0);
16743
-
16744
- folder.add(group);
16745
-
16746
- object.editWindow.ResetModel();
16747
- object.editWindow.refreshContents();
17047
+ Object3D inst = new Object3D("inst" + paintcount++);
17048
+
17049
+ inst.CreateMaterial(); // use a void leaf to select instances
17050
+
17051
+ inst.add(paintobj); // link
17052
+
17053
+ object.GetWindow().SnapObject(inst);
17054
+
17055
+ Object3D folder = paintFolder; // GetFolder();
17056
+
17057
+ folder.add(inst);
17058
+
17059
+ object.GetWindow().ResetModel();
17060
+ object.GetWindow().refreshContents();
17061
+ }
1674817062 }
1674917063 else
1675017064 paintcount = 0;
....@@ -16783,6 +17097,11 @@
1678317097 //System.out.println("objects[color] = " + objects[color]);
1678417098 //objects[color].Select();
1678517099 indexcount = 0;
17100
+ ObjEditor window = object.GetWindow();
17101
+ if (window != null && deselect)
17102
+ {
17103
+ window.Select(null, deselect, true);
17104
+ }
1678617105 object.Select(color, deselect);
1678717106 }
1678817107