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
....@@ -335,14 +373,28 @@
335373 display.options1[2] = material.shadowbias;
336374 display.options1[3] = material.aniso;
337375 display.options1[4] = material.anisoV;
376
+// System.out.println("display.options1[0] " + display.options1[0]);
377
+// System.out.println("display.options1[1] " + display.options1[1]);
378
+// System.out.println("display.options1[2] " + display.options1[2]);
379
+// System.out.println("display.options1[3] " + display.options1[3]);
380
+// System.out.println("display.options1[4] " + display.options1[4]);
338381 display.options2[0] = material.opacity;
339382 display.options2[1] = material.diffuse;
340383 display.options2[2] = material.factor;
384
+// System.out.println("display.options2[0] " + display.options2[0]);
385
+// System.out.println("display.options2[1] " + display.options2[1]);
386
+// System.out.println("display.options2[2] " + display.options2[2]);
341387
342388 cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
389
+// System.out.println("display.options3[0] " + display.options3[0]);
390
+// System.out.println("display.options3[1] " + display.options3[1]);
391
+// System.out.println("display.options3[2] " + display.options3[2]);
343392 display.options4[0] = material.cameralight/0.2f;
344393 display.options4[1] = material.subsurface;
345394 display.options4[2] = material.sheen;
395
+// System.out.println("display.options4[0] " + display.options4[0]);
396
+// System.out.println("display.options4[1] " + display.options4[1]);
397
+// System.out.println("display.options4[2] " + display.options4[2]);
346398
347399 // if (display.CURRENTANTIALIAS > 0)
348400 // display.options3[3] /= 4;
....@@ -2051,7 +2103,7 @@
20512103 //System.err.println("Oeil on");
20522104 OEIL = true;
20532105 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2054
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2106
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
20552107 //pingthread.StepToTarget(true);
20562108 }
20572109
....@@ -2284,10 +2336,17 @@
22842336 HANDLES ^= true;
22852337 }
22862338
2339
+ Object3D paintFolder;
2340
+
22872341 void TogglePaint()
22882342 {
22892343 PAINTMODE ^= true;
22902344 paintcount = 0;
2345
+
2346
+ if (PAINTMODE)
2347
+ {
2348
+ paintFolder = GetFolder();
2349
+ }
22912350 }
22922351
22932352 void SwapCamera(int a, int b)
....@@ -2384,6 +2443,21 @@
23842443 return currentGL;
23852444 }
23862445
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
+
23872461 /**/
23882462 class CacheTexture
23892463 {
....@@ -2392,28 +2466,31 @@
23922466
23932467 int resolution;
23942468
2395
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2469
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
23962470 {
2397
- texture = tex;
2471
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2472
+ texturedata = texdata;
23982473 resolution = res;
23992474 }
24002475 }
24012476 /**/
24022477
24032478 // TEXTURE static Texture texture;
2404
- static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures
2405
- = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>();
2406
- 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
+
24072484 int pigmentdepth = 0;
24082485 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
24092486 int bumpdepth = 0;
24102487 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
24112488 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
24122489 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2413
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2490
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
24142491 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
24152492
2416
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2493
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
24172494 {
24182495 TextureData texturedata = null;
24192496
....@@ -2432,13 +2509,34 @@
24322509 if (bump)
24332510 texturedata = ConvertBump(texturedata, false);
24342511
2435
- com.sun.opengl.util.texture.Texture texture =
2436
- 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);
24372514
2438
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2439
- 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);
24402517
2441
- 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;
24422540 }
24432541
24442542 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3511,6 +3609,8 @@
35113609
35123610 System.out.println("LOADING TEXTURE : " + name);
35133611
3612
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3613
+
35143614 //
35153615 if (false) // compressbit > 0)
35163616 {
....@@ -7909,7 +8009,7 @@
79098009 String pigment = Object3D.GetPigment(tex);
79108010 String bump = Object3D.GetBump(tex);
79118011
7912
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8012
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79138013 {
79148014 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79158015 // System.out.println("; bump = " + bump);
....@@ -7924,8 +8024,8 @@
79248024 pigment = null;
79258025 }
79268026
7927
- ReleaseTexture(bump, true);
7928
- ReleaseTexture(pigment, false);
8027
+ ReleaseTexture(tex, true);
8028
+ ReleaseTexture(tex, false);
79298029 }
79308030
79318031 public void ReleasePigmentTexture(cTexture tex) // INTERFACE
....@@ -7943,7 +8043,7 @@
79438043
79448044 String pigment = Object3D.GetPigment(tex);
79458045
7946
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8046
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79478047 {
79488048 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79498049 // System.out.println("; bump = " + bump);
....@@ -7954,7 +8054,7 @@
79548054 pigment = null;
79558055 }
79568056
7957
- ReleaseTexture(pigment, false);
8057
+ ReleaseTexture(tex, false);
79588058 }
79598059
79608060 public void ReleaseBumpTexture(cTexture tex) // INTERFACE
....@@ -7972,7 +8072,7 @@
79728072
79738073 String bump = Object3D.GetBump(tex);
79748074
7975
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8075
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79768076 {
79778077 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79788078 // System.out.println("; bump = " + bump);
....@@ -7983,10 +8083,10 @@
79838083 bump = null;
79848084 }
79858085
7986
- ReleaseTexture(bump, true);
8086
+ ReleaseTexture(tex, true);
79878087 }
79888088
7989
- void ReleaseTexture(String tex, boolean bump)
8089
+ void ReleaseTexture(cTexture tex, boolean bump)
79908090 {
79918091 if (// DrawMode() != 0 || /*tex == null ||*/
79928092 ambientOcclusion ) // || !textureon)
....@@ -7997,7 +8097,7 @@
79978097 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
79988098
79998099 if (tex != null)
8000
- texture = textures.get(tex);
8100
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
80018101
80028102 // //assert( texture != null );
80038103 // if (texture == null)
....@@ -8091,47 +8191,50 @@
80918191
80928192 /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
80938193 {
8094
- if (// DrawMode() != 0 || /*tex == null ||*/
8095
- ambientOcclusion ) // || !textureon)
8096
- {
8097
- return; // false;
8098
- }
8099
-
8100
- if (tex == null)
8101
- {
8102
- BindTexture(null,false,resolution);
8103
- BindTexture(null,true,resolution);
8104
- return;
8105
- }
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;
81068235
8107
- String pigment = Object3D.GetPigment(tex);
8108
- String bump = Object3D.GetBump(tex);
8109
-
8110
- usedtextures.put(pigment, pigment);
8111
- usedtextures.put(bump, bump);
8112
-
8113
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8114
- {
8115
- // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8116
- // System.out.println("; bump = " + bump);
8117
- }
8118
-
8119
- if (bump.equals(""))
8120
- {
8121
- bump = null;
8122
- }
8123
- if (pigment.equals(""))
8124
- {
8125
- pigment = null;
8126
- }
8127
-
8128
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8129
- BindTexture(pigment, false, resolution);
8130
- GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8131
- BindTexture(bump, true, resolution);
8132
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8133
-
8134
- return; // true;
8236
+ BindPigmentTexture(tex, resolution);
8237
+ BindBumpTexture(tex, resolution);
81358238 }
81368239
81378240 /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8150,9 +8253,9 @@
81508253
81518254 String pigment = Object3D.GetPigment(tex);
81528255
8153
- usedtextures.put(pigment, pigment);
8256
+ usedtextures.add(tex);
81548257
8155
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8258
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
81568259 {
81578260 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
81588261 // System.out.println("; bump = " + bump);
....@@ -8164,7 +8267,7 @@
81648267 }
81658268
81668269 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8167
- BindTexture(pigment, false, resolution);
8270
+ BindTexture(tex, false, resolution);
81688271 }
81698272
81708273 /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8183,9 +8286,9 @@
81838286
81848287 String bump = Object3D.GetBump(tex);
81858288
8186
- usedtextures.put(bump, bump);
8289
+ usedtextures.add(tex);
81878290
8188
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8291
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
81898292 {
81908293 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
81918294 // System.out.println("; bump = " + bump);
....@@ -8197,7 +8300,7 @@
81978300 }
81988301
81998302 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8200
- BindTexture(bump, true, resolution);
8303
+ BindTexture(tex, true, resolution);
82018304 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
82028305 }
82038306
....@@ -8221,13 +8324,19 @@
82218324 return fileExists;
82228325 }
82238326
8224
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception
8327
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
82258328 {
8226
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8329
+ CacheTexture texturecache = null;
82278330
82288331 if (tex != null)
82298332 {
8230
- 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
+ }
82318340
82328341 String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
82338342
....@@ -8237,19 +8346,46 @@
82378346 // else
82388347 // if (!texname.startsWith("/"))
82398348 // texname = "/Users/nbriere/Textures/" + texname;
8240
- if (!FileExists(tex))
8349
+ if (!FileExists(texname))
82418350 {
82428351 texname = fallbackTextureName;
82438352 }
82448353
82458354 if (CACHETEXTURE)
8246
- texture = textures.get(texname); // TEXTURE CACHE
8247
-
8248
- TextureData texturedata = null;
8249
-
8250
- if (texture == null || texture.resolution < resolution)
82518355 {
8252
- 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(""))
82538389 {
82548390 assert(!bump);
82558391 // if (bump)
....@@ -8260,19 +8396,23 @@
82608396 // }
82618397 // else
82628398 // {
8263
- texture = textures.get(tex);
8264
- if (texture == null)
8399
+ // texturecache = textures.get(texname); // suspicious
8400
+ if (texturecache == null)
82658401 {
8266
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8402
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
82678403 }
8404
+ else
8405
+ new Exception().printStackTrace();
82688406 // }
82698407 } else
8270
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8408
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
82718409 {
82728410 assert(bump);
8273
- texture = textures.get(tex);
8274
- if (texture == null)
8275
- 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();
82768416 } else
82778417 {
82788418 //if (tex.equals("IMMORTAL"))
....@@ -8280,11 +8420,13 @@
82808420 // texture = GetResourceTexture("default.png");
82818421 //} else
82828422 //{
8283
- if (tex.equals("WHITE_NOISE"))
8423
+ if (texname.endsWith("WHITE_NOISE"))
82848424 {
8285
- texture = textures.get(tex);
8286
- if (texture == null)
8287
- 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();
82888430 } else
82898431 {
82908432 if (textureon)
....@@ -8343,19 +8485,19 @@
83438485 if (texturedata == null)
83448486 throw new Exception();
83458487
8346
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8488
+ texturecache = new CacheTexture(texturedata,resolution);
83478489 //texture = GetTexture(tex, bump);
83488490 }
83498491 }
83508492 //}
83518493 }
83528494
8353
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8495
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
83548496 {
83558497 //return false;
83568498
83578499 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8358
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8500
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
83598501 {
83608502 // String ext = "_highres";
83618503 // if (REDUCETEXTURE)
....@@ -8372,52 +8514,17 @@
83728514 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
83738515 if (!cachefile.exists())
83748516 {
8375
- // cache to disk
8376
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
8377
- //buffers[0].
8378
-
8379
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
8380
- int[] pixels = new int[bytebuf.capacity()/3];
8381
-
8382
- // squared size heuristic...
8383
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8517
+ //if (texturedata.getWidth() == texturedata.getHeight())
83848518 {
8385
- for (int i=pixels.length; --i>=0;)
8386
- {
8387
- int i3 = i*3;
8388
- pixels[i] = 0xFF;
8389
- pixels[i] <<= 8;
8390
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
8391
- pixels[i] <<= 8;
8392
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
8393
- pixels[i] <<= 8;
8394
- pixels[i] |= bytebuf.get(i3) & 0xFF;
8395
- }
8396
-
8397
- /*
8398
- int r=0,g=0,b=0,a=0;
8399
- for (int i=0; i<width; i++)
8400
- for (int j=0; j<height; j++)
8401
- {
8402
- int index = j*width+i;
8403
- int p = pixels[index];
8404
- a = ((p>>24) & 0xFF);
8405
- r = ((p>>16) & 0xFF);
8406
- g = ((p>>8) & 0xFF);
8407
- b = (p & 0xFF);
8408
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
8409
- }
8410
- /**/
8411
- int width = (int)Math.sqrt(pixels.length); // squared
8412
- int height = width;
8413
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
8414
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8519
+ BufferedImage rendImage = CreateBim(texturedata);
8520
+
84158521 ImageWriter writer = null;
84168522 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
84178523 if (iter.hasNext()) {
84188524 writer = (ImageWriter)iter.next();
84198525 }
8420
- float compressionQuality = 0.9f;
8526
+
8527
+ float compressionQuality = 0.85f;
84218528 try
84228529 {
84238530 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8434,18 +8541,20 @@
84348541 }
84358542 }
84368543 }
8437
-
8544
+
8545
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8546
+
84388547 //System.out.println("Texture = " + tex);
8439
- if (textures.containsKey(texname))
8548
+ if (textures.containsKey(tex))
84408549 {
8441
- CacheTexture thetex = textures.get(texname);
8550
+ CacheTexture thetex = textures.get(tex);
84428551 thetex.texture.disable();
84438552 thetex.texture.dispose();
8444
- textures.remove(texname);
8553
+ textures.remove(tex);
84458554 }
84468555
8447
- texture.texturedata = texturedata;
8448
- textures.put(texname, texture);
8556
+ //texture.texturedata = texturedata;
8557
+ textures.put(tex, texturecache);
84498558
84508559 // newtex = true;
84518560 }
....@@ -8461,10 +8570,44 @@
84618570 }
84628571 }
84638572
8464
- return texture;
8573
+ return texturecache;
84658574 }
84668575
8467
- 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
84688611 {
84698612 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
84708613
....@@ -8482,21 +8625,21 @@
84828625 return texture!=null?texture.texture:null;
84838626 }
84848627
8485
- 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
84868629 {
84878630 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
84888631
84898632 return texture!=null?texture.texturedata:null;
84908633 }
84918634
8492
- boolean BindTexture(String tex, boolean bump, int resolution) throws Exception
8635
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
84938636 {
84948637 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
84958638 {
84968639 return false;
84978640 }
84988641
8499
- boolean newtex = false;
8642
+ //boolean newtex = false;
85008643
85018644 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
85028645
....@@ -8528,9 +8671,75 @@
85288671 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
85298672 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
85308673
8531
- return newtex;
8674
+ return true; // Warning: not used.
85328675 }
85338676
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
+
85348743 ShadowBuffer shadowPBuf;
85358744 AntialiasBuffer antialiasPBuf;
85368745 int MAXSTACK;
....@@ -9366,11 +9575,35 @@
93669575 jy8[3] = 0.5f;
93679576 }
93689577
9369
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9578
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
93709579 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
93719580 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
93729581 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
93739582
9583
+ void ResetOptions()
9584
+ {
9585
+ options1[0] = 100;
9586
+ options1[1] = 0.025f;
9587
+ options1[2] = 0.01f;
9588
+ options1[3] = 0;
9589
+ options1[4] = 0;
9590
+
9591
+ options2[0] = 0;
9592
+ options2[1] = 0.75f;
9593
+ options2[2] = 0;
9594
+ options2[3] = 0;
9595
+
9596
+ options3[0] = 1;
9597
+ options3[1] = 1;
9598
+ options3[2] = 1;
9599
+ options3[3] = 0;
9600
+
9601
+ options4[0] = 1;
9602
+ options4[1] = 0;
9603
+ options4[2] = 1;
9604
+ options4[3] = 0;
9605
+ }
9606
+
93749607 static int imagecount = 0; // movie generation
93759608
93769609 static int jitter = 0;
....@@ -9467,7 +9700,7 @@
94679700
94689701 if (renderCamera != lightCamera)
94699702 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9470
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
9703
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
94719704
94729705 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
94739706
....@@ -9483,7 +9716,7 @@
94839716
94849717 if (renderCamera != lightCamera)
94859718 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9486
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
9719
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
94879720
94889721 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
94899722
....@@ -10481,6 +10714,7 @@
1048110714 ANTIALIAS = 0;
1048210715 //System.out.println("RESTART");
1048310716 AAtimer.restart();
10717
+ Globals.TIMERRUNNING = true;
1048410718 }
1048510719 }
1048610720 }
....@@ -10683,7 +10917,7 @@
1068310917 // if (parentcam != renderCamera) // not a light
1068410918 if (cam != lightCamera)
1068510919 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10686
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
10920
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1068710921
1068810922 for (int j = 0; j < 4; j++)
1068910923 {
....@@ -10698,7 +10932,7 @@
1069810932 // if (parentcam != renderCamera) // not a light
1069910933 if (cam != lightCamera)
1070010934 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10701
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
10935
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1070210936
1070310937 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1070410938
....@@ -10989,9 +11223,9 @@
1098911223
1099011224 gl.glMatrixMode(GL.GL_MODELVIEW);
1099111225
10992
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10993
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10994
-//gl.glEnable(gl.GL_MULTISAMPLE);
11226
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11227
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11228
+gl.glEnable(gl.GL_MULTISAMPLE);
1099511229 } else
1099611230 {
1099711231 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -11002,7 +11236,7 @@
1100211236 //System.out.println("BLENDING ON");
1100311237 gl.glEnable(GL.GL_BLEND);
1100411238 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
11005
-
11239
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1100611240 gl.glMatrixMode(gl.GL_PROJECTION);
1100711241 gl.glLoadIdentity();
1100811242
....@@ -11251,7 +11485,7 @@
1125111485 }
1125211486 }
1125311487
11254
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11488
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1125511489 {
1125611490 //gl.glDepthFunc(GL.GL_LEQUAL);
1125711491 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11259,24 +11493,21 @@
1125911493
1126011494 boolean texon = textureon;
1126111495
11262
- if (RENDERPROGRAM > 0)
11263
- {
11264
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11265
- textureon = false;
11266
- }
11496
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11497
+ textureon = false;
11498
+
1126711499 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1126811500 //System.out.println("ALLO");
1126911501 gl.glColorMask(false, false, false, false);
1127011502 DrawObject(gl);
11271
- if (RENDERPROGRAM > 0)
11272
- {
11273
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11274
- textureon = texon;
11275
- }
11503
+
11504
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11505
+ textureon = texon;
11506
+
1127611507 gl.glColorMask(true, true, true, true);
1127711508
1127811509 gl.glDepthFunc(GL.GL_EQUAL);
11279
- //gl.glDepthMask(false);
11510
+ gl.glDepthMask(false);
1128011511 }
1128111512
1128211513 if (false) // DrawMode() == SHADOW)
....@@ -11479,13 +11710,16 @@
1147911710
1148011711 void DrawObject(GL gl, boolean draw)
1148111712 {
11713
+ // To clear camera values
11714
+ ResetOptions();
11715
+
1148211716 //System.out.println("DRAW OBJECT " + mouseDown);
1148311717 // DrawMode() = SELECTION;
1148411718 //GL gl = getGL();
1148511719 if ((TRACK || SHADOWTRACK) || zoomonce)
1148611720 {
1148711721 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11488
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11722
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1148911723 pingthread.StepToTarget(true); // true);
1149011724 // zoomonce = false;
1149111725 }
....@@ -11613,20 +11847,32 @@
1161311847 ReleaseTextures(DEFAULT_TEXTURES);
1161411848
1161511849 if (CLEANCACHE)
11616
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11850
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1161711851 {
11618
- String tex = e.nextElement();
11852
+ cTexture tex = e.nextElement();
1161911853
1162011854 // System.out.println("Texture --------- " + tex);
1162111855
11622
- if (tex.equals("WHITE_NOISE"))
11856
+ if (tex.equals("WHITE_NOISE:"))
1162311857 continue;
1162411858
11625
- if (!usedtextures.containsKey(tex))
11859
+ if (!usedtextures.contains(tex))
1162611860 {
11861
+ CacheTexture gettex = texturepigment.get(tex);
1162711862 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11628
- textures.get(tex).texture.dispose();
11629
- 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
+ }
1163011876 }
1163111877 }
1163211878 }
....@@ -12046,7 +12292,7 @@
1204612292 for (int i = tp.size(); --i >= 0;)
1204712293 {
1204812294 //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12049
- LA.xformPos(light, tp.get(i).GlobalTransform(), light);
12295
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1205012296 }
1205112297
1205212298
....@@ -12155,7 +12401,74 @@
1215512401 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1215612402
1215712403 String program =
12404
+ // Min shader
1215812405 "!!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
+
1215912472 //"OPTION ARB_fragment_program_shadow;" +
1216012473 "PARAM light2cam0 = program.env[10];" +
1216112474 "PARAM light2cam1 = program.env[11];" +
....@@ -12270,8 +12583,7 @@
1227012583 "TEMP shininess;" +
1227112584 "\n" +
1227212585 "MOV texSamp, one;" +
12273
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12274
-
12586
+
1227512587 "MOV mapgrid.x, one2048th.x;" +
1227612588 "MOV temp, fragment.texcoord[1];" +
1227712589 /*
....@@ -12292,20 +12604,20 @@
1229212604 "MUL temp, floor, mapgrid.x;" +
1229312605 //"TEX depth0, temp, texture[1], 2D;" +
1229412606 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12295
- TextureFetch("depth0", "temp", "1") +
12607
+ ShadowTextureFetch("depth0", "temp", "1") +
1229612608 "") +
1229712609 "ADD temp.x, temp.x, mapgrid.x;" +
1229812610 //"TEX depth1, temp, texture[1], 2D;" +
1229912611 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12300
- TextureFetch("depth1", "temp", "1") +
12612
+ ShadowTextureFetch("depth1", "temp", "1") +
1230112613 "") +
1230212614 "ADD temp.y, temp.y, mapgrid.x;" +
1230312615 //"TEX depth2, temp, texture[1], 2D;" +
12304
- TextureFetch("depth2", "temp", "1") +
12616
+ ShadowTextureFetch("depth2", "temp", "1") +
1230512617 "SUB temp.x, temp.x, mapgrid.x;" +
1230612618 //"TEX depth3, temp, texture[1], 2D;" +
1230712619 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12308
- TextureFetch("depth3", "temp", "1") +
12620
+ ShadowTextureFetch("depth3", "temp", "1") +
1230912621 "") +
1231012622 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1231112623 //"MOV params, material;" +
....@@ -12676,7 +12988,7 @@
1267612988 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1267712989 "") +
1267812990
12679
- // display shadow only (bump == 0)
12991
+ // display shadow only (fakedepth == 0)
1268012992 "SUB temp.x, half.x, shadow.x;" +
1268112993 "MOV temp.y, -params5.z;" + // params6.x;" +
1268212994 "SLT temp.z, temp.y, -one2048th.x;" +
....@@ -13103,25 +13415,26 @@
1310313415 return out;
1310413416 }
1310513417
13106
- String TextureFetch(String dest, String src, String unit)
13418
+ // Also does frustum culling
13419
+ String ShadowTextureFetch(String dest, String src, String unit)
1310713420 {
1310813421 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1310913422 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1311013423 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13424
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13425
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1311113426 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13112
- "SLT " + src + ".z, " + src + ".x, one.x;" +
13113
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13114
- "SLT " + src + ".z, " + src + ".y, one.x;" +
13115
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13427
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13428
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1311613429 //"SWZ buffer, temp, w,w,w,w;";
13117
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13430
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1311813431 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1311913432 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1312013433 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13121
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13434
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1312213435
13123
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13124
- //"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;";
1312513438 }
1312613439
1312713440 String Shadow(String depth, String shadow)
....@@ -13168,7 +13481,7 @@
1316813481 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1316913482 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1317013483
13171
- // No shadow when out of frustrum
13484
+ // No shadow when out of frustum
1317213485 "SGE temp.x, " + depth + ".z, one.z;" +
1317313486 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1317413487 "";
....@@ -13333,9 +13646,10 @@
1333313646 "DP3 " + dest + ".z," + "normals," + "eye;" +
1333413647 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1333513648 //"MOV " + dest + ".w," + "normal.z;" +
13336
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
13337
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13338
- //"MOV " + dest + ".z," + "params2.w;" +
13649
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13650
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13651
+
13652
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1333913653 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1334013654 "RCP " + dest + ".w," + dest + ".w;" +
1334113655 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13840,6 +14154,7 @@
1384014154 else
1384114155 if (evt.getSource() == AAtimer)
1384214156 {
14157
+ Globals.TIMERRUNNING = false;
1384314158 if (mouseDown)
1384414159 {
1384514160 //new Exception().printStackTrace();
....@@ -13899,7 +14214,7 @@
1389914214
1390014215 // fev 2014???
1390114216 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13902
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14217
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1390314218 pingthread.StepToTarget(true); // true);
1390414219 }
1390514220 // if (!LIVE)
....@@ -13914,6 +14229,7 @@
1391414229 return;
1391514230
1391614231 AAtimer.restart(); //
14232
+ Globals.TIMERRUNNING = true;
1391714233
1391814234 // waslive = LIVE;
1391914235 // LIVE = false;
....@@ -13963,14 +14279,15 @@
1396314279 drag = false;
1396414280 //System.out.println("Mouse DOWN");
1396514281 editObj = false;
13966
- ClickInfo info = new ClickInfo();
13967
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
13968
- info.pane = this;
13969
- info.camera = renderCamera;
13970
- info.x = x;
13971
- info.y = y;
13972
- info.modifiers = modifiersex;
13973
- 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);
1397414291 if (!editObj)
1397514292 {
1397614293 hasMarquee = true;
....@@ -14252,12 +14569,12 @@
1425214569 void GoDown(int mod)
1425314570 {
1425414571 MODIFIERS |= COMMAND;
14255
- /*
14572
+ /**/
1425614573 if((mod&SHIFT) == SHIFT)
1425714574 manipCamera.RotatePosition(0, -speed);
1425814575 else
14259
- manipCamera.BackForth(0, -speed*delta, getWidth());
14260
- */
14576
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14577
+ /**/
1426114578 if ((mod & SHIFT) == SHIFT)
1426214579 {
1426314580 mouseMode = mouseMode; // VR??
....@@ -14273,12 +14590,12 @@
1427314590 void GoUp(int mod)
1427414591 {
1427514592 MODIFIERS |= COMMAND;
14276
- /*
14593
+ /**/
1427714594 if((mod&SHIFT) == SHIFT)
1427814595 manipCamera.RotatePosition(0, speed);
1427914596 else
14280
- manipCamera.BackForth(0, speed*delta, getWidth());
14281
- */
14597
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14598
+ /**/
1428214599 if ((mod & SHIFT) == SHIFT)
1428314600 {
1428414601 mouseMode = mouseMode;
....@@ -14294,12 +14611,12 @@
1429414611 void GoLeft(int mod)
1429514612 {
1429614613 MODIFIERS |= COMMAND;
14297
- /*
14614
+ /**/
1429814615 if((mod&SHIFT) == SHIFT)
14299
- manipCamera.RotatePosition(speed, 0);
14300
- else
1430114616 manipCamera.Translate(speed*delta, 0, getWidth());
14302
- */
14617
+ else
14618
+ manipCamera.RotatePosition(speed, 0);
14619
+ /**/
1430314620 if ((mod & SHIFT) == SHIFT)
1430414621 {
1430514622 mouseMode = mouseMode;
....@@ -14315,12 +14632,12 @@
1431514632 void GoRight(int mod)
1431614633 {
1431714634 MODIFIERS |= COMMAND;
14318
- /*
14635
+ /**/
1431914636 if((mod&SHIFT) == SHIFT)
14320
- manipCamera.RotatePosition(-speed, 0);
14321
- else
1432214637 manipCamera.Translate(-speed*delta, 0, getWidth());
14323
- */
14638
+ else
14639
+ manipCamera.RotatePosition(-speed, 0);
14640
+ /**/
1432414641 if ((mod & SHIFT) == SHIFT)
1432514642 {
1432614643 mouseMode = mouseMode;
....@@ -14370,15 +14687,16 @@
1437014687 if (editObj)
1437114688 {
1437214689 drag = true;
14373
- ClickInfo info = new ClickInfo();
14374
- info.bounds.setBounds(0, 0,
14690
+ //ClickInfo info = new ClickInfo();
14691
+ object.clickInfo.bounds.setBounds(0, 0,
1437514692 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14376
- info.pane = this;
14377
- info.camera = renderCamera;
14378
- info.x = x;
14379
- info.y = y;
14380
- object.manipWindow.copy
14381
- .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);
1438214700 } else
1438314701 {
1438414702 if (x < startX)
....@@ -14527,24 +14845,27 @@
1452714845 }
1452814846 }
1452914847
14848
+// ClickInfo clickInfo = new ClickInfo();
14849
+
1453014850 public void mouseMoved(MouseEvent e)
1453114851 {
1453214852 //System.out.println("mouseMoved: " + e);
1453314853 if (isRenderer)
1453414854 return;
1453514855
14536
- ClickInfo ci = new ClickInfo();
14537
- ci.x = e.getX();
14538
- ci.y = e.getY();
14539
- ci.modifiers = e.getModifiersEx();
14540
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14541
- ci.pane = this;
14542
- 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;
1454314863 if (!isRenderer)
1454414864 {
1454514865 //ObjEditor editWindow = object.editWindow;
1454614866 //Object3D copy = editWindow.copy;
14547
- if (object.doEditClick(ci, 0))
14867
+ if (object.doEditClick(//clickInfo,
14868
+ 0))
1454814869 {
1454914870 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1455014871 } else
....@@ -14559,7 +14880,8 @@
1455914880 Globals.MOUSEDRAGGED = false;
1456014881
1456114882 movingcamera = false;
14562
- X = Y = 0;
14883
+ X = 0; // getBounds().width/2;
14884
+ Y = 0; // getBounds().height/2;
1456314885 //System.out.println("mouseReleased: " + e);
1456414886 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1456514887 }
....@@ -14815,7 +15137,8 @@
1481515137 // break;
1481615138 case 'T':
1481715139 CACHETEXTURE ^= true;
14818
- textures.clear();
15140
+ texturepigment.clear();
15141
+ texturebump.clear();
1481915142 // repaint();
1482015143 break;
1482115144 case 'Y':
....@@ -14900,7 +15223,9 @@
1490015223 case 'E' : COMPACT ^= true;
1490115224 repaint();
1490215225 break;
14903
- case 'W' : DEBUGHSB ^= true;
15226
+ case 'W' : // Wide Window (fullscreen)
15227
+ //DEBUGHSB ^= true;
15228
+ ObjEditor.theFrame.ToggleFullScreen();
1490415229 repaint();
1490515230 break;
1490615231 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14926,13 +15251,7 @@
1492615251 repaint();
1492715252 break;
1492815253 case 'l':
14929
- lightMode ^= true;
14930
- Globals.lighttouched = true;
14931
- manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
14932
- targetLookAt.set(manipCamera.lookAt);
14933
- repaint();
14934
- break;
14935
- case 'L':
15254
+ //case 'L':
1493615255 if (lightMode)
1493715256 {
1493815257 lightMode = false;
....@@ -15075,11 +15394,14 @@
1507515394 case '_':
1507615395 kompactbit = 5;
1507715396 break;
15078
- case '+':
15079
- kompactbit = 6;
15080
- break;
15397
+// case '+':
15398
+// kompactbit = 6;
15399
+// break;
1508115400 case ' ':
15082
- ObjEditor.theFrame.ToggleFullScreen();
15401
+ lightMode ^= true;
15402
+ Globals.lighttouched = true;
15403
+ manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
15404
+ targetLookAt.set(manipCamera.lookAt);
1508315405 repaint();
1508415406 break;
1508515407 //case '`' :
....@@ -15126,8 +15448,9 @@
1512615448 case DELETE:
1512715449 ClearSelection();
1512815450 break;
15129
- /*
1513015451 case '+':
15452
+
15453
+ /*
1513115454 //fontsize += 1;
1513215455 bbzoom *= 2;
1513315456 repaint();
....@@ -15144,17 +15467,17 @@
1514415467 case '=':
1514515468 IncDepth();
1514615469 //fontsize += 1;
15147
- object.editWindow.refreshContents(true);
15470
+ object.GetWindow().refreshContents(true);
1514815471 maskbit = 6;
1514915472 break;
1515015473 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1515115474 DecDepth();
1515215475 maskbit = 5;
1515315476 //if(fontsize > 1) fontsize -= 1;
15154
- if (object.editWindow == null)
15155
- new Exception().printStackTrace();
15156
- else
15157
- object.editWindow.refreshContents(true);
15477
+// if (object.editWindow == null)
15478
+// new Exception().printStackTrace();
15479
+// else
15480
+ object.GetWindow().refreshContents(true);
1515815481 break;
1515915482 case '{':
1516015483 manipCamera.shaper_fovy /= 1.1;
....@@ -15378,7 +15701,7 @@
1537815701 }
1537915702 */
1538015703
15381
- object.editWindow.EditSelection();
15704
+ object.GetWindow().EditSelection(false);
1538215705 }
1538315706
1538415707 void SelectParent()
....@@ -15395,10 +15718,10 @@
1539515718 {
1539615719 //selectees.remove(i);
1539715720 System.out.println("select parent of " + elem);
15398
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15721
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1539915722 } else
1540015723 {
15401
- group.editWindow.Select(elem.GetTreePath(), first, true);
15724
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1540215725 }
1540315726
1540415727 first = false;
....@@ -15440,12 +15763,12 @@
1544015763 for (int j = 0; j < group.children.size(); j++)
1544115764 {
1544215765 elem = (Object3D) group.children.elementAt(j);
15443
- object.editWindow.Select(elem.GetTreePath(), first, true);
15766
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1544415767 first = false;
1544515768 }
1544615769 } else
1544715770 {
15448
- object.editWindow.Select(elem.GetTreePath(), first, true);
15771
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1544915772 }
1545015773
1545115774 first = false;
....@@ -15456,21 +15779,21 @@
1545615779 {
1545715780 //Composite group = (Composite) object;
1545815781 Object3D group = object;
15459
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15782
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1546015783 }
1546115784
1546215785 void ResetTransform(int mask)
1546315786 {
1546415787 //Composite group = (Composite) object;
1546515788 Object3D group = object;
15466
- group.editWindow.ResetTransform(mask);
15789
+ group.GetWindow().ResetTransform(mask);
1546715790 }
1546815791
1546915792 void FlipTransform()
1547015793 {
1547115794 //Composite group = (Composite) object;
1547215795 Object3D group = object;
15473
- group.editWindow.FlipTransform();
15796
+ group.GetWindow().FlipTransform();
1547415797 // group.editWindow.ReduceMesh(true);
1547515798 }
1547615799
....@@ -15478,7 +15801,7 @@
1547815801 {
1547915802 //Composite group = (Composite) object;
1548015803 Object3D group = object;
15481
- group.editWindow.PrintMemory();
15804
+ group.GetWindow().PrintMemory();
1548215805 // group.editWindow.ReduceMesh(true);
1548315806 }
1548415807
....@@ -15486,7 +15809,7 @@
1548615809 {
1548715810 //Composite group = (Composite) object;
1548815811 Object3D group = object;
15489
- group.editWindow.ResetCentroid();
15812
+ group.GetWindow().ResetCentroid();
1549015813 }
1549115814
1549215815 void IncDepth()
....@@ -15568,8 +15891,6 @@
1556815891
1556915892 int width = getBounds().width;
1557015893 int height = getBounds().height;
15571
- ClickInfo info = new ClickInfo();
15572
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1557315894 //Image img = CreateImage(width, height);
1557415895 //System.out.println("width = " + width + "; height = " + height + "\n");
1557515896
....@@ -15646,48 +15967,77 @@
1564615967 }
1564715968 if (object != null && !hasMarquee)
1564815969 {
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
+
1564915976 if (isRenderer)
1565015977 {
15651
- info.flags++;
15978
+ object.clickInfo.flags++;
1565215979 double frameAspect = (double) width / (double) height;
1565315980 if (frameAspect > renderCamera.aspect)
1565415981 {
1565515982 int desired = (int) ((double) height * renderCamera.aspect);
15656
- info.bounds.width -= width - desired;
15657
- info.bounds.x += (width - desired) / 2;
15983
+ object.clickInfo.bounds.width -= width - desired;
15984
+ object.clickInfo.bounds.x += (width - desired) / 2;
1565815985 } else
1565915986 {
1566015987 int desired = (int) ((double) width / renderCamera.aspect);
15661
- info.bounds.height -= height - desired;
15662
- info.bounds.y += (height - desired) / 2;
15988
+ object.clickInfo.bounds.height -= height - desired;
15989
+ object.clickInfo.bounds.y += (height - desired) / 2;
1566315990 }
1566415991 }
15665
- info.g = gr;
15666
- info.camera = renderCamera;
15992
+
15993
+ object.clickInfo.g = gr;
15994
+ object.clickInfo.camera = renderCamera;
1566715995 /*
1566815996 // Memory intensive (brep.verticescopy)
1566915997 if (!(object instanceof Composite))
1567015998 object.draw(info, 0, false); // SLOW :
1567115999 */
15672
- if (!isRenderer)
16000
+ if (!isRenderer) // && drag)
1567316001 {
15674
- object.drawEditHandles(info, 0);
15675
-
15676
- if (drag && (X != 0 || Y != 0) && object.selection.Size() > 0)
16002
+ Grafreed.Assert(object != null);
16003
+ Grafreed.Assert(object.selection != null);
16004
+ if (object.selection.Size() > 0)
1567716005 {
15678
- switch (object.selection.get(0).hitSomething)
16006
+ int hitSomething = object.selection.get(0).hitSomething;
16007
+
16008
+ object.clickInfo.DX = 0;
16009
+ object.clickInfo.DY = 0;
16010
+ object.clickInfo.W = 1;
16011
+ if (hitSomething == Object3D.hitCenter)
1567916012 {
15680
- case Object3D.hitCenter: gr.setColor(Color.pink);
15681
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15682
- break;
15683
- case Object3D.hitRotate: gr.setColor(Color.yellow);
15684
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15685
- break;
15686
- case Object3D.hitScale: gr.setColor(Color.cyan);
15687
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15688
- break;
16013
+ info.DX = X;
16014
+ if (X != 0)
16015
+ info.DX -= info.bounds.width/2;
16016
+
16017
+ info.DY = Y;
16018
+ if (Y != 0)
16019
+ info.DY -= info.bounds.height/2;
1568916020 }
15690
-
16021
+
16022
+ object.drawEditHandles(//info,
16023
+ 0);
16024
+
16025
+ if (drag && (X != 0 || Y != 0))
16026
+ {
16027
+ switch (hitSomething)
16028
+ {
16029
+ case Object3D.hitCenter: gr.setColor(Color.pink);
16030
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16031
+ break;
16032
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16033
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16034
+ break;
16035
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16036
+ gr.drawLine(X, Y, 0, 0);
16037
+ break;
16038
+ }
16039
+
16040
+ }
1569116041 }
1569216042 }
1569316043 }
....@@ -16485,6 +16835,14 @@
1648516835 }
1648616836 }
1648716837
16838
+ private Object3D GetFolder()
16839
+ {
16840
+ Object3D folder = object.GetWindow().copy;
16841
+ if (object.GetWindow().copy.selection.Size() > 0)
16842
+ folder = object.GetWindow().copy.selection.elementAt(0);
16843
+ return folder;
16844
+ }
16845
+
1648816846 class SelectBuffer implements GLEventListener
1648916847 {
1649016848
....@@ -16564,6 +16922,17 @@
1656416922
1656516923 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1656616924
16925
+ if (PAINTMODE)
16926
+ {
16927
+ if (object.GetWindow().copy.selection.Size() > 0)
16928
+ {
16929
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16930
+
16931
+ // Make what you paint not selectable.
16932
+ paintobj.ResetSelectable();
16933
+ }
16934
+ }
16935
+
1656716936 //int tmp = selection_view;
1656816937 //selection_view = -1;
1656916938 int temp = DrawMode();
....@@ -16575,6 +16944,17 @@
1657516944 // temp = DEFAULT; // patch for selection debug
1657616945 Globals.drawMode = temp; // WARNING
1657716946
16947
+ if (PAINTMODE)
16948
+ {
16949
+ if (object.GetWindow().copy.selection.Size() > 0)
16950
+ {
16951
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16952
+
16953
+ // Revert.
16954
+ paintobj.RestoreSelectable();
16955
+ }
16956
+ }
16957
+
1657816958 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1657916959
1658016960 // trying different ways of getting the depth info over
....@@ -16678,29 +17058,31 @@
1667817058 }
1667917059
1668017060 if (!movingcamera && !PAINTMODE)
16681
- object.editWindow.ScreenFitPoint(); // fev 2014
17061
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1668217062
16683
- if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17063
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1668417064 {
16685
- Object3D paintobj = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17065
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1668617066
16687
- Object3D group = new Object3D("inst" + paintcount++);
17067
+ if (object.GetWindow().copy.selection.Size() > 0)
17068
+ {
17069
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1668817070
16689
- group.CreateMaterial(); // use a void leaf to select instances
16690
-
16691
- group.add(paintobj); // link
16692
-
16693
- object.editWindow.SnapObject(group);
16694
-
16695
- Object3D folder = object.editWindow.copy;
16696
-
16697
- if (object.editWindow.copy.selection.Size() > 0)
16698
- folder = object.editWindow.copy.selection.elementAt(0);
16699
-
16700
- folder.add(group);
16701
-
16702
- object.editWindow.ResetModel();
16703
- object.editWindow.refreshContents();
17071
+ Object3D inst = new Object3D("inst" + paintcount++);
17072
+
17073
+ inst.CreateMaterial(); // use a void leaf to select instances
17074
+
17075
+ inst.add(paintobj); // link
17076
+
17077
+ object.GetWindow().SnapObject(inst);
17078
+
17079
+ Object3D folder = paintFolder; // GetFolder();
17080
+
17081
+ folder.add(inst);
17082
+
17083
+ object.GetWindow().ResetModel();
17084
+ object.GetWindow().refreshContents();
17085
+ }
1670417086 }
1670517087 else
1670617088 paintcount = 0;
....@@ -16739,6 +17121,11 @@
1673917121 //System.out.println("objects[color] = " + objects[color]);
1674017122 //objects[color].Select();
1674117123 indexcount = 0;
17124
+ ObjEditor window = object.GetWindow();
17125
+ if (window != null && deselect)
17126
+ {
17127
+ window.Select(null, deselect, true);
17128
+ }
1674217129 object.Select(color, deselect);
1674317130 }
1674417131