Normand Briere
2019-07-25 f2b6a33fdf84a06b958f9cb9d667a2eff3063d8b
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;
....@@ -326,7 +363,7 @@
326363 cStatic.objectstack[materialdepth++] = obj;
327364 //System.out.println("material " + material);
328365 //Applet3D.tracein(this, selected);
329
- display.vector2buffer = obj.projectedVertices;
366
+ //display.vector2buffer = obj.projectedVertices;
330367 if (obj instanceof Camera)
331368 {
332369 display.options1[0] = material.shift;
....@@ -335,14 +372,28 @@
335372 display.options1[2] = material.shadowbias;
336373 display.options1[3] = material.aniso;
337374 display.options1[4] = material.anisoV;
375
+// System.out.println("display.options1[0] " + display.options1[0]);
376
+// System.out.println("display.options1[1] " + display.options1[1]);
377
+// System.out.println("display.options1[2] " + display.options1[2]);
378
+// System.out.println("display.options1[3] " + display.options1[3]);
379
+// System.out.println("display.options1[4] " + display.options1[4]);
338380 display.options2[0] = material.opacity;
339381 display.options2[1] = material.diffuse;
340382 display.options2[2] = material.factor;
383
+// System.out.println("display.options2[0] " + display.options2[0]);
384
+// System.out.println("display.options2[1] " + display.options2[1]);
385
+// System.out.println("display.options2[2] " + display.options2[2]);
341386
342387 cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
388
+// System.out.println("display.options3[0] " + display.options3[0]);
389
+// System.out.println("display.options3[1] " + display.options3[1]);
390
+// System.out.println("display.options3[2] " + display.options3[2]);
343391 display.options4[0] = material.cameralight/0.2f;
344392 display.options4[1] = material.subsurface;
345393 display.options4[2] = material.sheen;
394
+// System.out.println("display.options4[0] " + display.options4[0]);
395
+// System.out.println("display.options4[1] " + display.options4[1]);
396
+// System.out.println("display.options4[2] " + display.options4[2]);
346397
347398 // if (display.CURRENTANTIALIAS > 0)
348399 // display.options3[3] /= 4;
....@@ -358,7 +409,7 @@
358409 /**/
359410 } else
360411 {
361
- DrawMaterial(material, selected);
412
+ DrawMaterial(material, selected, obj.projectedVertices);
362413 }
363414 } else
364415 {
....@@ -382,8 +433,8 @@
382433 cStatic.objectstack[materialdepth++] = obj;
383434 //System.out.println("material " + material);
384435 //Applet3D.tracein("selected ", selected);
385
- display.vector2buffer = obj.projectedVertices;
386
- display.DrawMaterial(material, selected);
436
+ //display.vector2buffer = obj.projectedVertices;
437
+ display.DrawMaterial(material, selected, obj.projectedVertices);
387438 }
388439 }
389440
....@@ -400,8 +451,8 @@
400451 materialdepth -= 1;
401452 if (materialdepth > 0)
402453 {
403
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
404
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
454
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
455
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
405456 }
406457 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
407458 } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
....@@ -421,8 +472,8 @@
421472 materialdepth -= 1;
422473 if (materialdepth > 0)
423474 {
424
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
425
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
475
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
476
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
426477 }
427478 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
428479 //else
....@@ -1610,7 +1661,7 @@
16101661 // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
16111662 }
16121663
1613
- void DrawMaterial(cMaterial material, boolean selected)
1664
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
16141665 {
16151666 CameraPane display = this;
16161667 //new Exception().printStackTrace();
....@@ -1645,7 +1696,7 @@
16451696 colorV[0] = display.modelParams0[0] * material.diffuse;
16461697 colorV[1] = display.modelParams0[1] * material.diffuse;
16471698 colorV[2] = display.modelParams0[2] * material.diffuse;
1648
- colorV[3] = material.opacity;
1699
+ colorV[3] = 1; // material.opacity;
16491700
16501701 gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
16511702 //System.out.println("Opacity = " + opacity);
....@@ -1753,9 +1804,9 @@
17531804 display.modelParams7[2] = 0;
17541805 display.modelParams7[3] = 0;
17551806
1756
- display.modelParams6[0] = 100; // criss de bug de bump
1807
+ //display.modelParams6[0] = 100; // criss de bug de bump
17571808
1758
- Object3D.cVector2[] extparams = display.vector2buffer;
1809
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
17591810 if (extparams != null && extparams.length > 0 && extparams[0] != null)
17601811 {
17611812 display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
....@@ -2051,7 +2102,7 @@
20512102 //System.err.println("Oeil on");
20522103 OEIL = true;
20532104 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2054
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2105
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
20552106 //pingthread.StepToTarget(true);
20562107 }
20572108
....@@ -2284,10 +2335,17 @@
22842335 HANDLES ^= true;
22852336 }
22862337
2338
+ Object3D paintFolder;
2339
+
22872340 void TogglePaint()
22882341 {
22892342 PAINTMODE ^= true;
22902343 paintcount = 0;
2344
+
2345
+ if (PAINTMODE)
2346
+ {
2347
+ paintFolder = GetFolder();
2348
+ }
22912349 }
22922350
22932351 void SwapCamera(int a, int b)
....@@ -2384,6 +2442,21 @@
23842442 return currentGL;
23852443 }
23862444
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
+
23872460 /**/
23882461 class CacheTexture
23892462 {
....@@ -2392,28 +2465,31 @@
23922465
23932466 int resolution;
23942467
2395
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2468
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
23962469 {
2397
- texture = tex;
2470
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2471
+ texturedata = texdata;
23982472 resolution = res;
23992473 }
24002474 }
24012475 /**/
24022476
24032477 // 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>();
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
+
24072483 int pigmentdepth = 0;
24082484 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
24092485 int bumpdepth = 0;
24102486 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
24112487 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
24122488 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2413
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2489
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
24142490 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
24152491
2416
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2492
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
24172493 {
24182494 TextureData texturedata = null;
24192495
....@@ -2432,13 +2508,34 @@
24322508 if (bump)
24332509 texturedata = ConvertBump(texturedata, false);
24342510
2435
- com.sun.opengl.util.texture.Texture texture =
2436
- 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);
24372513
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);
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);
24402516
2441
- 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;
24422539 }
24432540
24442541 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3511,6 +3608,8 @@
35113608
35123609 System.out.println("LOADING TEXTURE : " + name);
35133610
3611
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3612
+
35143613 //
35153614 if (false) // compressbit > 0)
35163615 {
....@@ -7909,7 +8008,7 @@
79098008 String pigment = Object3D.GetPigment(tex);
79108009 String bump = Object3D.GetBump(tex);
79118010
7912
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8011
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79138012 {
79148013 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79158014 // System.out.println("; bump = " + bump);
....@@ -7924,8 +8023,8 @@
79248023 pigment = null;
79258024 }
79268025
7927
- ReleaseTexture(bump, true);
7928
- ReleaseTexture(pigment, false);
8026
+ ReleaseTexture(tex, true);
8027
+ ReleaseTexture(tex, false);
79298028 }
79308029
79318030 public void ReleasePigmentTexture(cTexture tex) // INTERFACE
....@@ -7943,7 +8042,7 @@
79438042
79448043 String pigment = Object3D.GetPigment(tex);
79458044
7946
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8045
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79478046 {
79488047 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79498048 // System.out.println("; bump = " + bump);
....@@ -7954,7 +8053,7 @@
79548053 pigment = null;
79558054 }
79568055
7957
- ReleaseTexture(pigment, false);
8056
+ ReleaseTexture(tex, false);
79588057 }
79598058
79608059 public void ReleaseBumpTexture(cTexture tex) // INTERFACE
....@@ -7972,7 +8071,7 @@
79728071
79738072 String bump = Object3D.GetBump(tex);
79748073
7975
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8074
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79768075 {
79778076 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79788077 // System.out.println("; bump = " + bump);
....@@ -7983,10 +8082,10 @@
79838082 bump = null;
79848083 }
79858084
7986
- ReleaseTexture(bump, true);
8085
+ ReleaseTexture(tex, true);
79878086 }
79888087
7989
- void ReleaseTexture(String tex, boolean bump)
8088
+ void ReleaseTexture(cTexture tex, boolean bump)
79908089 {
79918090 if (// DrawMode() != 0 || /*tex == null ||*/
79928091 ambientOcclusion ) // || !textureon)
....@@ -7997,7 +8096,7 @@
79978096 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
79988097
79998098 if (tex != null)
8000
- texture = textures.get(tex);
8099
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
80018100
80028101 // //assert( texture != null );
80038102 // if (texture == null)
....@@ -8091,47 +8190,50 @@
80918190
80928191 /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
80938192 {
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
- }
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;
81068234
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;
8235
+ BindPigmentTexture(tex, resolution);
8236
+ BindBumpTexture(tex, resolution);
81358237 }
81368238
81378239 /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8150,9 +8252,9 @@
81508252
81518253 String pigment = Object3D.GetPigment(tex);
81528254
8153
- usedtextures.put(pigment, pigment);
8255
+ usedtextures.add(tex);
81548256
8155
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8257
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
81568258 {
81578259 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
81588260 // System.out.println("; bump = " + bump);
....@@ -8164,7 +8266,7 @@
81648266 }
81658267
81668268 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8167
- BindTexture(pigment, false, resolution);
8269
+ BindTexture(tex, false, resolution);
81688270 }
81698271
81708272 /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8183,9 +8285,9 @@
81838285
81848286 String bump = Object3D.GetBump(tex);
81858287
8186
- usedtextures.put(bump, bump);
8288
+ usedtextures.add(tex);
81878289
8188
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8290
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
81898291 {
81908292 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
81918293 // System.out.println("; bump = " + bump);
....@@ -8197,7 +8299,7 @@
81978299 }
81988300
81998301 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8200
- BindTexture(bump, true, resolution);
8302
+ BindTexture(tex, true, resolution);
82018303 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
82028304 }
82038305
....@@ -8221,13 +8323,19 @@
82218323 return fileExists;
82228324 }
82238325
8224
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception
8326
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
82258327 {
8226
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8328
+ CacheTexture texturecache = null;
82278329
82288330 if (tex != null)
82298331 {
8230
- 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
+ }
82318339
82328340 String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
82338341
....@@ -8237,19 +8345,46 @@
82378345 // else
82388346 // if (!texname.startsWith("/"))
82398347 // texname = "/Users/nbriere/Textures/" + texname;
8240
- if (!FileExists(tex))
8348
+ if (!FileExists(texname))
82418349 {
82428350 texname = fallbackTextureName;
82438351 }
82448352
82458353 if (CACHETEXTURE)
8246
- texture = textures.get(texname); // TEXTURE CACHE
8247
-
8248
- TextureData texturedata = null;
8249
-
8250
- if (texture == null || texture.resolution < resolution)
82518354 {
8252
- 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(""))
82538388 {
82548389 assert(!bump);
82558390 // if (bump)
....@@ -8260,19 +8395,23 @@
82608395 // }
82618396 // else
82628397 // {
8263
- texture = textures.get(tex);
8264
- if (texture == null)
8398
+ // texturecache = textures.get(texname); // suspicious
8399
+ if (texturecache == null)
82658400 {
8266
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8401
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
82678402 }
8403
+ else
8404
+ new Exception().printStackTrace();
82688405 // }
82698406 } else
8270
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8407
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
82718408 {
82728409 assert(bump);
8273
- texture = textures.get(tex);
8274
- if (texture == null)
8275
- 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();
82768415 } else
82778416 {
82788417 //if (tex.equals("IMMORTAL"))
....@@ -8280,11 +8419,13 @@
82808419 // texture = GetResourceTexture("default.png");
82818420 //} else
82828421 //{
8283
- if (tex.equals("WHITE_NOISE"))
8422
+ if (texname.endsWith("WHITE_NOISE"))
82848423 {
8285
- texture = textures.get(tex);
8286
- if (texture == null)
8287
- 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();
82888429 } else
82898430 {
82908431 if (textureon)
....@@ -8343,19 +8484,19 @@
83438484 if (texturedata == null)
83448485 throw new Exception();
83458486
8346
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8487
+ texturecache = new CacheTexture(texturedata,resolution);
83478488 //texture = GetTexture(tex, bump);
83488489 }
83498490 }
83508491 //}
83518492 }
83528493
8353
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8494
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
83548495 {
83558496 //return false;
83568497
83578498 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8358
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8499
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
83598500 {
83608501 // String ext = "_highres";
83618502 // if (REDUCETEXTURE)
....@@ -8372,52 +8513,17 @@
83728513 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
83738514 if (!cachefile.exists())
83748515 {
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))
8516
+ //if (texturedata.getWidth() == texturedata.getHeight())
83848517 {
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);
8518
+ BufferedImage rendImage = CreateBim(texturedata);
8519
+
84158520 ImageWriter writer = null;
84168521 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
84178522 if (iter.hasNext()) {
84188523 writer = (ImageWriter)iter.next();
84198524 }
8420
- float compressionQuality = 0.9f;
8525
+
8526
+ float compressionQuality = 0.85f;
84218527 try
84228528 {
84238529 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8434,18 +8540,20 @@
84348540 }
84358541 }
84368542 }
8437
-
8543
+
8544
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8545
+
84388546 //System.out.println("Texture = " + tex);
8439
- if (textures.containsKey(texname))
8547
+ if (textures.containsKey(tex))
84408548 {
8441
- CacheTexture thetex = textures.get(texname);
8549
+ CacheTexture thetex = textures.get(tex);
84428550 thetex.texture.disable();
84438551 thetex.texture.dispose();
8444
- textures.remove(texname);
8552
+ textures.remove(tex);
84458553 }
84468554
8447
- texture.texturedata = texturedata;
8448
- textures.put(texname, texture);
8555
+ //texture.texturedata = texturedata;
8556
+ textures.put(tex, texturecache);
84498557
84508558 // newtex = true;
84518559 }
....@@ -8461,10 +8569,44 @@
84618569 }
84628570 }
84638571
8464
- return texture;
8572
+ return texturecache;
84658573 }
84668574
8467
- 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
84688610 {
84698611 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
84708612
....@@ -8482,21 +8624,21 @@
84828624 return texture!=null?texture.texture:null;
84838625 }
84848626
8485
- 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
84868628 {
84878629 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
84888630
84898631 return texture!=null?texture.texturedata:null;
84908632 }
84918633
8492
- boolean BindTexture(String tex, boolean bump, int resolution) throws Exception
8634
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
84938635 {
84948636 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
84958637 {
84968638 return false;
84978639 }
84988640
8499
- boolean newtex = false;
8641
+ //boolean newtex = false;
85008642
85018643 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
85028644
....@@ -8528,9 +8670,75 @@
85288670 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
85298671 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
85308672
8531
- return newtex;
8673
+ return true; // Warning: not used.
85328674 }
85338675
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
+
85348742 ShadowBuffer shadowPBuf;
85358743 AntialiasBuffer antialiasPBuf;
85368744 int MAXSTACK;
....@@ -9366,11 +9574,35 @@
93669574 jy8[3] = 0.5f;
93679575 }
93689576
9369
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9577
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
93709578 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
93719579 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
93729580 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
93739581
9582
+ void ResetOptions()
9583
+ {
9584
+ options1[0] = 100;
9585
+ options1[1] = 0.025f;
9586
+ options1[2] = 0.01f;
9587
+ options1[3] = 0;
9588
+ options1[4] = 0;
9589
+
9590
+ options2[0] = 0;
9591
+ options2[1] = 0.75f;
9592
+ options2[2] = 0;
9593
+ options2[3] = 0;
9594
+
9595
+ options3[0] = 1;
9596
+ options3[1] = 1;
9597
+ options3[2] = 1;
9598
+ options3[3] = 0;
9599
+
9600
+ options4[0] = 1;
9601
+ options4[1] = 0;
9602
+ options4[2] = 1;
9603
+ options4[3] = 0;
9604
+ }
9605
+
93749606 static int imagecount = 0; // movie generation
93759607
93769608 static int jitter = 0;
....@@ -9467,7 +9699,7 @@
94679699
94689700 if (renderCamera != lightCamera)
94699701 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9470
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
9702
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
94719703
94729704 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
94739705
....@@ -9483,7 +9715,7 @@
94839715
94849716 if (renderCamera != lightCamera)
94859717 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9486
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
9718
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
94879719
94889720 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
94899721
....@@ -10481,6 +10713,7 @@
1048110713 ANTIALIAS = 0;
1048210714 //System.out.println("RESTART");
1048310715 AAtimer.restart();
10716
+ Globals.TIMERRUNNING = true;
1048410717 }
1048510718 }
1048610719 }
....@@ -10548,7 +10781,8 @@
1054810781 ambientOcclusion = false;
1054910782 }
1055010783
10551
- if (Globals.lighttouched && DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
10784
+ if (//Globals.lighttouched &&
10785
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1055210786 {
1055310787 //if (RENDERSHADOW) // ?
1055410788 if (!IsFrozen())
....@@ -10682,7 +10916,7 @@
1068210916 // if (parentcam != renderCamera) // not a light
1068310917 if (cam != lightCamera)
1068410918 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10685
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
10919
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1068610920
1068710921 for (int j = 0; j < 4; j++)
1068810922 {
....@@ -10697,7 +10931,7 @@
1069710931 // if (parentcam != renderCamera) // not a light
1069810932 if (cam != lightCamera)
1069910933 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10700
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
10934
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1070110935
1070210936 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1070310937
....@@ -10988,9 +11222,9 @@
1098811222
1098911223 gl.glMatrixMode(GL.GL_MODELVIEW);
1099011224
10991
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10992
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10993
-//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);
1099411228 } else
1099511229 {
1099611230 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -11001,7 +11235,7 @@
1100111235 //System.out.println("BLENDING ON");
1100211236 gl.glEnable(GL.GL_BLEND);
1100311237 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
11004
-
11238
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1100511239 gl.glMatrixMode(gl.GL_PROJECTION);
1100611240 gl.glLoadIdentity();
1100711241
....@@ -11250,7 +11484,7 @@
1125011484 }
1125111485 }
1125211486
11253
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11487
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1125411488 {
1125511489 //gl.glDepthFunc(GL.GL_LEQUAL);
1125611490 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11258,24 +11492,21 @@
1125811492
1125911493 boolean texon = textureon;
1126011494
11261
- if (RENDERPROGRAM > 0)
11262
- {
11263
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11264
- textureon = false;
11265
- }
11495
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11496
+ textureon = false;
11497
+
1126611498 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1126711499 //System.out.println("ALLO");
1126811500 gl.glColorMask(false, false, false, false);
1126911501 DrawObject(gl);
11270
- if (RENDERPROGRAM > 0)
11271
- {
11272
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11273
- textureon = texon;
11274
- }
11502
+
11503
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11504
+ textureon = texon;
11505
+
1127511506 gl.glColorMask(true, true, true, true);
1127611507
1127711508 gl.glDepthFunc(GL.GL_EQUAL);
11278
- //gl.glDepthMask(false);
11509
+ gl.glDepthMask(false);
1127911510 }
1128011511
1128111512 if (false) // DrawMode() == SHADOW)
....@@ -11458,7 +11689,7 @@
1145811689
1145911690 static boolean zoomonce = false;
1146011691
11461
- void CreateSelectedPoint()
11692
+ static void CreateSelectedPoint()
1146211693 {
1146311694 if (selectedpoint == null)
1146411695 {
....@@ -11478,13 +11709,16 @@
1147811709
1147911710 void DrawObject(GL gl, boolean draw)
1148011711 {
11712
+ // To clear camera values
11713
+ ResetOptions();
11714
+
1148111715 //System.out.println("DRAW OBJECT " + mouseDown);
1148211716 // DrawMode() = SELECTION;
1148311717 //GL gl = getGL();
1148411718 if ((TRACK || SHADOWTRACK) || zoomonce)
1148511719 {
1148611720 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11487
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11721
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1148811722 pingthread.StepToTarget(true); // true);
1148911723 // zoomonce = false;
1149011724 }
....@@ -11612,20 +11846,32 @@
1161211846 ReleaseTextures(DEFAULT_TEXTURES);
1161311847
1161411848 if (CLEANCACHE)
11615
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11849
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1161611850 {
11617
- String tex = e.nextElement();
11851
+ cTexture tex = e.nextElement();
1161811852
1161911853 // System.out.println("Texture --------- " + tex);
1162011854
11621
- if (tex.equals("WHITE_NOISE"))
11855
+ if (tex.equals("WHITE_NOISE:"))
1162211856 continue;
1162311857
11624
- if (!usedtextures.containsKey(tex))
11858
+ if (!usedtextures.contains(tex))
1162511859 {
11860
+ CacheTexture gettex = texturepigment.get(tex);
1162611861 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11627
- textures.get(tex).texture.dispose();
11628
- 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
+ }
1162911875 }
1163011876 }
1163111877 }
....@@ -12045,7 +12291,7 @@
1204512291 for (int i = tp.size(); --i >= 0;)
1204612292 {
1204712293 //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12048
- LA.xformPos(light, tp.get(i).GlobalTransform(), light);
12294
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1204912295 }
1205012296
1205112297
....@@ -12154,7 +12400,52 @@
1215412400 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1215512401
1215612402 String program =
12403
+ // Min shader
1215712404 "!!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
+
1215812449 //"OPTION ARB_fragment_program_shadow;" +
1215912450 "PARAM light2cam0 = program.env[10];" +
1216012451 "PARAM light2cam1 = program.env[11];" +
....@@ -12269,8 +12560,7 @@
1226912560 "TEMP shininess;" +
1227012561 "\n" +
1227112562 "MOV texSamp, one;" +
12272
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12273
-
12563
+
1227412564 "MOV mapgrid.x, one2048th.x;" +
1227512565 "MOV temp, fragment.texcoord[1];" +
1227612566 /*
....@@ -12675,7 +12965,7 @@
1267512965 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1267612966 "") +
1267712967
12678
- // display shadow only (bump == 0)
12968
+ // display shadow only (fakedepth == 0)
1267912969 "SUB temp.x, half.x, shadow.x;" +
1268012970 "MOV temp.y, -params5.z;" + // params6.x;" +
1268112971 "SLT temp.z, temp.y, -one2048th.x;" +
....@@ -13107,20 +13397,20 @@
1310713397 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1310813398 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1310913399 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13400
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13401
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1311013402 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13111
- "SLT " + src + ".z, " + src + ".x, one.x;" +
13112
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13113
- "SLT " + src + ".z, " + src + ".y, one.x;" +
13114
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13403
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13404
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1311513405 //"SWZ buffer, temp, w,w,w,w;";
13116
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13406
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1311713407 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1311813408 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1311913409 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13120
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13410
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1312113411
13122
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13123
- //"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;";
1312413414 }
1312513415
1312613416 String Shadow(String depth, String shadow)
....@@ -13167,7 +13457,7 @@
1316713457 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1316813458 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1316913459
13170
- // No shadow when out of frustrum
13460
+ // No shadow when out of frustum
1317113461 "SGE temp.x, " + depth + ".z, one.z;" +
1317213462 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1317313463 "";
....@@ -13315,7 +13605,8 @@
1331513605 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1331613606 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1331713607 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13318
- Object3D.cVector2[] vector2buffer;
13608
+
13609
+ //Object3D.cVector2[] vector2buffer;
1331913610
1332013611 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1332113612 // OUT : diff, spec
....@@ -13331,9 +13622,10 @@
1333113622 "DP3 " + dest + ".z," + "normals," + "eye;" +
1333213623 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1333313624 //"MOV " + dest + ".w," + "normal.z;" +
13334
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
13335
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13336
- //"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
1333713629 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1333813630 "RCP " + dest + ".w," + dest + ".w;" +
1333913631 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13838,6 +14130,7 @@
1383814130 else
1383914131 if (evt.getSource() == AAtimer)
1384014132 {
14133
+ Globals.TIMERRUNNING = false;
1384114134 if (mouseDown)
1384214135 {
1384314136 //new Exception().printStackTrace();
....@@ -13897,7 +14190,7 @@
1389714190
1389814191 // fev 2014???
1389914192 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13900
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14193
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1390114194 pingthread.StepToTarget(true); // true);
1390214195 }
1390314196 // if (!LIVE)
....@@ -13912,6 +14205,7 @@
1391214205 return;
1391314206
1391414207 AAtimer.restart(); //
14208
+ Globals.TIMERRUNNING = true;
1391514209
1391614210 // waslive = LIVE;
1391714211 // LIVE = false;
....@@ -13961,14 +14255,15 @@
1396114255 drag = false;
1396214256 //System.out.println("Mouse DOWN");
1396314257 editObj = false;
13964
- ClickInfo info = new ClickInfo();
13965
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
13966
- info.pane = this;
13967
- info.camera = renderCamera;
13968
- info.x = x;
13969
- info.y = y;
13970
- info.modifiers = modifiersex;
13971
- 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);
1397214267 if (!editObj)
1397314268 {
1397414269 hasMarquee = true;
....@@ -14250,12 +14545,12 @@
1425014545 void GoDown(int mod)
1425114546 {
1425214547 MODIFIERS |= COMMAND;
14253
- /*
14548
+ /**/
1425414549 if((mod&SHIFT) == SHIFT)
1425514550 manipCamera.RotatePosition(0, -speed);
1425614551 else
14257
- manipCamera.BackForth(0, -speed*delta, getWidth());
14258
- */
14552
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14553
+ /**/
1425914554 if ((mod & SHIFT) == SHIFT)
1426014555 {
1426114556 mouseMode = mouseMode; // VR??
....@@ -14271,12 +14566,12 @@
1427114566 void GoUp(int mod)
1427214567 {
1427314568 MODIFIERS |= COMMAND;
14274
- /*
14569
+ /**/
1427514570 if((mod&SHIFT) == SHIFT)
1427614571 manipCamera.RotatePosition(0, speed);
1427714572 else
14278
- manipCamera.BackForth(0, speed*delta, getWidth());
14279
- */
14573
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14574
+ /**/
1428014575 if ((mod & SHIFT) == SHIFT)
1428114576 {
1428214577 mouseMode = mouseMode;
....@@ -14292,12 +14587,12 @@
1429214587 void GoLeft(int mod)
1429314588 {
1429414589 MODIFIERS |= COMMAND;
14295
- /*
14590
+ /**/
1429614591 if((mod&SHIFT) == SHIFT)
14297
- manipCamera.RotatePosition(speed, 0);
14298
- else
1429914592 manipCamera.Translate(speed*delta, 0, getWidth());
14300
- */
14593
+ else
14594
+ manipCamera.RotatePosition(speed, 0);
14595
+ /**/
1430114596 if ((mod & SHIFT) == SHIFT)
1430214597 {
1430314598 mouseMode = mouseMode;
....@@ -14313,12 +14608,12 @@
1431314608 void GoRight(int mod)
1431414609 {
1431514610 MODIFIERS |= COMMAND;
14316
- /*
14611
+ /**/
1431714612 if((mod&SHIFT) == SHIFT)
14318
- manipCamera.RotatePosition(-speed, 0);
14319
- else
1432014613 manipCamera.Translate(-speed*delta, 0, getWidth());
14321
- */
14614
+ else
14615
+ manipCamera.RotatePosition(-speed, 0);
14616
+ /**/
1432214617 if ((mod & SHIFT) == SHIFT)
1432314618 {
1432414619 mouseMode = mouseMode;
....@@ -14368,14 +14663,16 @@
1436814663 if (editObj)
1436914664 {
1437014665 drag = true;
14371
- ClickInfo info = new ClickInfo();
14372
- info.bounds.setBounds(0, 0,
14666
+ //ClickInfo info = new ClickInfo();
14667
+ object.clickInfo.bounds.setBounds(0, 0,
1437314668 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14374
- info.pane = this;
14375
- info.camera = renderCamera;
14376
- info.x = x;
14377
- info.y = y;
14378
- object.editWindow.copy.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);
1437914676 } else
1438014677 {
1438114678 if (x < startX)
....@@ -14524,22 +14821,27 @@
1452414821 }
1452514822 }
1452614823
14824
+// ClickInfo clickInfo = new ClickInfo();
14825
+
1452714826 public void mouseMoved(MouseEvent e)
1452814827 {
1452914828 //System.out.println("mouseMoved: " + e);
1453014829 if (isRenderer)
1453114830 return;
1453214831
14533
- ClickInfo ci = new ClickInfo();
14534
- ci.x = e.getX();
14535
- ci.y = e.getY();
14536
- ci.modifiers = e.getModifiersEx();
14537
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14538
- ci.pane = this;
14539
- 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;
1454014839 if (!isRenderer)
1454114840 {
14542
- if (object.editWindow.copy.doEditClick(ci, 0))
14841
+ //ObjEditor editWindow = object.editWindow;
14842
+ //Object3D copy = editWindow.copy;
14843
+ if (object.doEditClick(//clickInfo,
14844
+ 0))
1454314845 {
1454414846 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1454514847 } else
....@@ -14554,7 +14856,8 @@
1455414856 Globals.MOUSEDRAGGED = false;
1455514857
1455614858 movingcamera = false;
14557
- X = Y = 0;
14859
+ X = 0; // getBounds().width/2;
14860
+ Y = 0; // getBounds().height/2;
1455814861 //System.out.println("mouseReleased: " + e);
1455914862 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1456014863 }
....@@ -14810,7 +15113,8 @@
1481015113 // break;
1481115114 case 'T':
1481215115 CACHETEXTURE ^= true;
14813
- textures.clear();
15116
+ texturepigment.clear();
15117
+ texturebump.clear();
1481415118 // repaint();
1481515119 break;
1481615120 case 'Y':
....@@ -14895,7 +15199,9 @@
1489515199 case 'E' : COMPACT ^= true;
1489615200 repaint();
1489715201 break;
14898
- case 'W' : DEBUGHSB ^= true;
15202
+ case 'W' : // Wide Window (fullscreen)
15203
+ //DEBUGHSB ^= true;
15204
+ ObjEditor.theFrame.ToggleFullScreen();
1489915205 repaint();
1490015206 break;
1490115207 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14921,13 +15227,7 @@
1492115227 repaint();
1492215228 break;
1492315229 case 'l':
14924
- lightMode ^= true;
14925
- Globals.lighttouched = true;
14926
- manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
14927
- targetLookAt.set(manipCamera.lookAt);
14928
- repaint();
14929
- break;
14930
- case 'L':
15230
+ //case 'L':
1493115231 if (lightMode)
1493215232 {
1493315233 lightMode = false;
....@@ -15070,11 +15370,14 @@
1507015370 case '_':
1507115371 kompactbit = 5;
1507215372 break;
15073
- case '+':
15074
- kompactbit = 6;
15075
- break;
15373
+// case '+':
15374
+// kompactbit = 6;
15375
+// break;
1507615376 case ' ':
15077
- ObjEditor.theFrame.ToggleFullScreen();
15377
+ lightMode ^= true;
15378
+ Globals.lighttouched = true;
15379
+ manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
15380
+ targetLookAt.set(manipCamera.lookAt);
1507815381 repaint();
1507915382 break;
1508015383 //case '`' :
....@@ -15121,8 +15424,9 @@
1512115424 case DELETE:
1512215425 ClearSelection();
1512315426 break;
15124
- /*
1512515427 case '+':
15428
+
15429
+ /*
1512615430 //fontsize += 1;
1512715431 bbzoom *= 2;
1512815432 repaint();
....@@ -15139,17 +15443,17 @@
1513915443 case '=':
1514015444 IncDepth();
1514115445 //fontsize += 1;
15142
- object.editWindow.refreshContents(true);
15446
+ object.GetWindow().refreshContents(true);
1514315447 maskbit = 6;
1514415448 break;
1514515449 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1514615450 DecDepth();
1514715451 maskbit = 5;
1514815452 //if(fontsize > 1) fontsize -= 1;
15149
- if (object.editWindow == null)
15150
- new Exception().printStackTrace();
15151
- else
15152
- object.editWindow.refreshContents(true);
15453
+// if (object.editWindow == null)
15454
+// new Exception().printStackTrace();
15455
+// else
15456
+ object.GetWindow().refreshContents(true);
1515315457 break;
1515415458 case '{':
1515515459 manipCamera.shaper_fovy /= 1.1;
....@@ -15373,7 +15677,7 @@
1537315677 }
1537415678 */
1537515679
15376
- object.editWindow.EditSelection();
15680
+ object.GetWindow().EditSelection(false);
1537715681 }
1537815682
1537915683 void SelectParent()
....@@ -15390,10 +15694,10 @@
1539015694 {
1539115695 //selectees.remove(i);
1539215696 System.out.println("select parent of " + elem);
15393
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15697
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1539415698 } else
1539515699 {
15396
- group.editWindow.Select(elem.GetTreePath(), first, true);
15700
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1539715701 }
1539815702
1539915703 first = false;
....@@ -15435,12 +15739,12 @@
1543515739 for (int j = 0; j < group.children.size(); j++)
1543615740 {
1543715741 elem = (Object3D) group.children.elementAt(j);
15438
- object.editWindow.Select(elem.GetTreePath(), first, true);
15742
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1543915743 first = false;
1544015744 }
1544115745 } else
1544215746 {
15443
- object.editWindow.Select(elem.GetTreePath(), first, true);
15747
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1544415748 }
1544515749
1544615750 first = false;
....@@ -15451,21 +15755,21 @@
1545115755 {
1545215756 //Composite group = (Composite) object;
1545315757 Object3D group = object;
15454
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15758
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1545515759 }
1545615760
1545715761 void ResetTransform(int mask)
1545815762 {
1545915763 //Composite group = (Composite) object;
1546015764 Object3D group = object;
15461
- group.editWindow.ResetTransform(mask);
15765
+ group.GetWindow().ResetTransform(mask);
1546215766 }
1546315767
1546415768 void FlipTransform()
1546515769 {
1546615770 //Composite group = (Composite) object;
1546715771 Object3D group = object;
15468
- group.editWindow.FlipTransform();
15772
+ group.GetWindow().FlipTransform();
1546915773 // group.editWindow.ReduceMesh(true);
1547015774 }
1547115775
....@@ -15473,7 +15777,7 @@
1547315777 {
1547415778 //Composite group = (Composite) object;
1547515779 Object3D group = object;
15476
- group.editWindow.PrintMemory();
15780
+ group.GetWindow().PrintMemory();
1547715781 // group.editWindow.ReduceMesh(true);
1547815782 }
1547915783
....@@ -15481,7 +15785,7 @@
1548115785 {
1548215786 //Composite group = (Composite) object;
1548315787 Object3D group = object;
15484
- group.editWindow.ResetCentroid();
15788
+ group.GetWindow().ResetCentroid();
1548515789 }
1548615790
1548715791 void IncDepth()
....@@ -15563,8 +15867,6 @@
1556315867
1556415868 int width = getBounds().width;
1556515869 int height = getBounds().height;
15566
- ClickInfo info = new ClickInfo();
15567
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1556815870 //Image img = CreateImage(width, height);
1556915871 //System.out.println("width = " + width + "; height = " + height + "\n");
1557015872
....@@ -15641,48 +15943,77 @@
1564115943 }
1564215944 if (object != null && !hasMarquee)
1564315945 {
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
+
1564415952 if (isRenderer)
1564515953 {
15646
- info.flags++;
15954
+ object.clickInfo.flags++;
1564715955 double frameAspect = (double) width / (double) height;
1564815956 if (frameAspect > renderCamera.aspect)
1564915957 {
1565015958 int desired = (int) ((double) height * renderCamera.aspect);
15651
- info.bounds.width -= width - desired;
15652
- info.bounds.x += (width - desired) / 2;
15959
+ object.clickInfo.bounds.width -= width - desired;
15960
+ object.clickInfo.bounds.x += (width - desired) / 2;
1565315961 } else
1565415962 {
1565515963 int desired = (int) ((double) width / renderCamera.aspect);
15656
- info.bounds.height -= height - desired;
15657
- info.bounds.y += (height - desired) / 2;
15964
+ object.clickInfo.bounds.height -= height - desired;
15965
+ object.clickInfo.bounds.y += (height - desired) / 2;
1565815966 }
1565915967 }
15660
- info.g = gr;
15661
- info.camera = renderCamera;
15968
+
15969
+ object.clickInfo.g = gr;
15970
+ object.clickInfo.camera = renderCamera;
1566215971 /*
1566315972 // Memory intensive (brep.verticescopy)
1566415973 if (!(object instanceof Composite))
1566515974 object.draw(info, 0, false); // SLOW :
1566615975 */
15667
- if (!isRenderer)
15976
+ if (!isRenderer) // && drag)
1566815977 {
15669
- object.drawEditHandles(info, 0);
15670
-
15671
- 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)
1567215981 {
15673
- 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)
1567415988 {
15675
- case Object3D.hitCenter: gr.setColor(Color.pink);
15676
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15677
- break;
15678
- case Object3D.hitRotate: gr.setColor(Color.yellow);
15679
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15680
- break;
15681
- case Object3D.hitScale: gr.setColor(Color.cyan);
15682
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15683
- 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;
1568415996 }
15685
-
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
+ }
1568616017 }
1568716018 }
1568816019 }
....@@ -16385,16 +16716,16 @@
1638516716 cStatic.objectstack[materialdepth++] = checker;
1638616717 //System.out.println("material " + material);
1638716718 //Applet3D.tracein(this, selected);
16388
- vector2buffer = checker.projectedVertices;
16719
+ //vector2buffer = checker.projectedVertices;
1638916720
1639016721 //checker.GetMaterial().Draw(this, false); // true);
16391
- DrawMaterial(checker.GetMaterial(), false); // true);
16722
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1639216723
1639316724 materialdepth -= 1;
1639416725 if (materialdepth > 0)
1639516726 {
16396
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16397
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
16727
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16728
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1639816729 }
1639916730 //checker.GetMaterial().opacity = 1f;
1640016731 ////checker.GetMaterial().ambient = 1f;
....@@ -16480,6 +16811,14 @@
1648016811 }
1648116812 }
1648216813
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
+
1648316822 class SelectBuffer implements GLEventListener
1648416823 {
1648516824
....@@ -16559,6 +16898,17 @@
1655916898
1656016899 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1656116900
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
+
1656216912 //int tmp = selection_view;
1656316913 //selection_view = -1;
1656416914 int temp = DrawMode();
....@@ -16570,6 +16920,17 @@
1657016920 // temp = DEFAULT; // patch for selection debug
1657116921 Globals.drawMode = temp; // WARNING
1657216922
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
+
1657316934 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1657416935
1657516936 // trying different ways of getting the depth info over
....@@ -16617,6 +16978,8 @@
1661716978 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1661816979 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1661916980 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
16981
+
16982
+ CreateSelectedPoint();
1662016983
1662116984 // Will fit the mesh !!!
1662216985 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16671,29 +17034,31 @@
1667117034 }
1667217035
1667317036 if (!movingcamera && !PAINTMODE)
16674
- object.editWindow.ScreenFitPoint(); // fev 2014
17037
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1667517038
16676
- 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)
1667717040 {
16678
- 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);
1667917042
16680
- Object3D group = new Object3D("inst" + paintcount++);
17043
+ if (object.GetWindow().copy.selection.Size() > 0)
17044
+ {
17045
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1668117046
16682
- group.CreateMaterial(); // use a void leaf to select instances
16683
-
16684
- group.add(paintobj); // link
16685
-
16686
- object.editWindow.SnapObject(group);
16687
-
16688
- Object3D folder = object.editWindow.copy;
16689
-
16690
- if (object.editWindow.copy.selection.Size() > 0)
16691
- folder = object.editWindow.copy.selection.elementAt(0);
16692
-
16693
- folder.add(group);
16694
-
16695
- object.editWindow.ResetModel();
16696
- 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
+ }
1669717062 }
1669817063 else
1669917064 paintcount = 0;
....@@ -16732,6 +17097,11 @@
1673217097 //System.out.println("objects[color] = " + objects[color]);
1673317098 //objects[color].Select();
1673417099 indexcount = 0;
17100
+ ObjEditor window = object.GetWindow();
17101
+ if (window != null && deselect)
17102
+ {
17103
+ window.Select(null, deselect, true);
17104
+ }
1673517105 object.Select(color, deselect);
1673617106 }
1673717107