Normand Briere
2019-07-25 7058eef32e524cae08a7373d8bc1061e373b223c
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 {
....@@ -37,7 +41,6 @@
3741 static boolean[] selectedstack = new boolean[65536];
3842 static int materialdepth = 0;
3943
40
- static boolean DEBUG = false;
4144 static boolean FRUSTUM = false; // still bogus true; // frustum culling
4245
4346 // camera change fix
....@@ -45,6 +48,39 @@
4548 static boolean ABORTED = false;
4649
4750 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
+ }
4884
4985 /*static*/ private boolean CULLFACE = false; // true;
5086 /*static*/ boolean NEAREST = false; // true;
....@@ -61,7 +97,7 @@
6197 //boolean REDUCETEXTURE = true;
6298 boolean CACHETEXTURE = true;
6399 boolean CLEANCACHE = false; // true;
64
- boolean MIPMAP = false; // true;
100
+ boolean MIPMAP = false; // true; // never works...
65101 boolean COMPRESSTEXTURE = false;
66102 boolean KOMPACTTEXTURE = false; // true;
67103 boolean RESIZETEXTURE = false;
....@@ -170,7 +206,8 @@
170206
171207 SetCamera(cam);
172208
173
- SetLight(new Camera(new cVector(10, 10, -20)));
209
+ // Warning: not used.
210
+ SetLight(new Camera(new cVector(15, 10, -20)));
174211
175212 object = o;
176213
....@@ -327,7 +364,7 @@
327364 cStatic.objectstack[materialdepth++] = obj;
328365 //System.out.println("material " + material);
329366 //Applet3D.tracein(this, selected);
330
- display.vector2buffer = obj.projectedVertices;
367
+ //display.vector2buffer = obj.projectedVertices;
331368 if (obj instanceof Camera)
332369 {
333370 display.options1[0] = material.shift;
....@@ -336,14 +373,28 @@
336373 display.options1[2] = material.shadowbias;
337374 display.options1[3] = material.aniso;
338375 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]);
339381 display.options2[0] = material.opacity;
340382 display.options2[1] = material.diffuse;
341383 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]);
342387
343388 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]);
344392 display.options4[0] = material.cameralight/0.2f;
345393 display.options4[1] = material.subsurface;
346394 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]);
347398
348399 // if (display.CURRENTANTIALIAS > 0)
349400 // display.options3[3] /= 4;
....@@ -359,7 +410,7 @@
359410 /**/
360411 } else
361412 {
362
- DrawMaterial(material, selected);
413
+ DrawMaterial(material, selected, obj.projectedVertices);
363414 }
364415 } else
365416 {
....@@ -383,8 +434,8 @@
383434 cStatic.objectstack[materialdepth++] = obj;
384435 //System.out.println("material " + material);
385436 //Applet3D.tracein("selected ", selected);
386
- display.vector2buffer = obj.projectedVertices;
387
- display.DrawMaterial(material, selected);
437
+ //display.vector2buffer = obj.projectedVertices;
438
+ display.DrawMaterial(material, selected, obj.projectedVertices);
388439 }
389440 }
390441
....@@ -401,8 +452,8 @@
401452 materialdepth -= 1;
402453 if (materialdepth > 0)
403454 {
404
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
405
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
455
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
456
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
406457 }
407458 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
408459 } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
....@@ -422,8 +473,8 @@
422473 materialdepth -= 1;
423474 if (materialdepth > 0)
424475 {
425
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
426
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
476
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
477
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
427478 }
428479 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
429480 //else
....@@ -1611,7 +1662,7 @@
16111662 // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
16121663 }
16131664
1614
- void DrawMaterial(cMaterial material, boolean selected)
1665
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
16151666 {
16161667 CameraPane display = this;
16171668 //new Exception().printStackTrace();
....@@ -1646,7 +1697,7 @@
16461697 colorV[0] = display.modelParams0[0] * material.diffuse;
16471698 colorV[1] = display.modelParams0[1] * material.diffuse;
16481699 colorV[2] = display.modelParams0[2] * material.diffuse;
1649
- colorV[3] = material.opacity;
1700
+ colorV[3] = 1; // material.opacity;
16501701
16511702 gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
16521703 //System.out.println("Opacity = " + opacity);
....@@ -1754,9 +1805,9 @@
17541805 display.modelParams7[2] = 0;
17551806 display.modelParams7[3] = 0;
17561807
1757
- display.modelParams6[0] = 100; // criss de bug de bump
1808
+ //display.modelParams6[0] = 100; // criss de bug de bump
17581809
1759
- Object3D.cVector2[] extparams = display.vector2buffer;
1810
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
17601811 if (extparams != null && extparams.length > 0 && extparams[0] != null)
17611812 {
17621813 display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
....@@ -2052,7 +2103,7 @@
20522103 //System.err.println("Oeil on");
20532104 OEIL = true;
20542105 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2055
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2106
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
20562107 //pingthread.StepToTarget(true);
20572108 }
20582109
....@@ -2267,7 +2318,7 @@
22672318
22682319 void ToggleDebug()
22692320 {
2270
- DEBUG ^= true;
2321
+ Globals.DEBUG ^= true;
22712322 }
22722323
22732324 void ToggleLookAt()
....@@ -2285,10 +2336,17 @@
22852336 HANDLES ^= true;
22862337 }
22872338
2339
+ Object3D paintFolder;
2340
+
22882341 void TogglePaint()
22892342 {
22902343 PAINTMODE ^= true;
22912344 paintcount = 0;
2345
+
2346
+ if (PAINTMODE)
2347
+ {
2348
+ paintFolder = GetFolder();
2349
+ }
22922350 }
22932351
22942352 void SwapCamera(int a, int b)
....@@ -2385,6 +2443,21 @@
23852443 return currentGL;
23862444 }
23872445
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
+
23882461 /**/
23892462 class CacheTexture
23902463 {
....@@ -2393,28 +2466,31 @@
23932466
23942467 int resolution;
23952468
2396
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2469
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
23972470 {
2398
- texture = tex;
2471
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2472
+ texturedata = texdata;
23992473 resolution = res;
24002474 }
24012475 }
24022476 /**/
24032477
24042478 // TEXTURE static Texture texture;
2405
- static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures
2406
- = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>();
2407
- 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
+
24082484 int pigmentdepth = 0;
24092485 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
24102486 int bumpdepth = 0;
24112487 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
24122488 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
24132489 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2414
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2490
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
24152491 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
24162492
2417
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2493
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
24182494 {
24192495 TextureData texturedata = null;
24202496
....@@ -2433,13 +2509,34 @@
24332509 if (bump)
24342510 texturedata = ConvertBump(texturedata, false);
24352511
2436
- com.sun.opengl.util.texture.Texture texture =
2437
- 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);
24382514
2439
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2440
- 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);
24412517
2442
- 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;
24432540 }
24442541
24452542 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3512,6 +3609,8 @@
35123609
35133610 System.out.println("LOADING TEXTURE : " + name);
35143611
3612
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3613
+
35153614 //
35163615 if (false) // compressbit > 0)
35173616 {
....@@ -7910,7 +8009,7 @@
79108009 String pigment = Object3D.GetPigment(tex);
79118010 String bump = Object3D.GetBump(tex);
79128011
7913
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8012
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79148013 {
79158014 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79168015 // System.out.println("; bump = " + bump);
....@@ -7925,8 +8024,8 @@
79258024 pigment = null;
79268025 }
79278026
7928
- ReleaseTexture(bump, true);
7929
- ReleaseTexture(pigment, false);
8027
+ ReleaseTexture(tex, true);
8028
+ ReleaseTexture(tex, false);
79308029 }
79318030
79328031 public void ReleasePigmentTexture(cTexture tex) // INTERFACE
....@@ -7944,7 +8043,7 @@
79448043
79458044 String pigment = Object3D.GetPigment(tex);
79468045
7947
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8046
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79488047 {
79498048 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79508049 // System.out.println("; bump = " + bump);
....@@ -7955,7 +8054,7 @@
79558054 pigment = null;
79568055 }
79578056
7958
- ReleaseTexture(pigment, false);
8057
+ ReleaseTexture(tex, false);
79598058 }
79608059
79618060 public void ReleaseBumpTexture(cTexture tex) // INTERFACE
....@@ -7973,7 +8072,7 @@
79738072
79748073 String bump = Object3D.GetBump(tex);
79758074
7976
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8075
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79778076 {
79788077 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79798078 // System.out.println("; bump = " + bump);
....@@ -7984,10 +8083,10 @@
79848083 bump = null;
79858084 }
79868085
7987
- ReleaseTexture(bump, true);
8086
+ ReleaseTexture(tex, true);
79888087 }
79898088
7990
- void ReleaseTexture(String tex, boolean bump)
8089
+ void ReleaseTexture(cTexture tex, boolean bump)
79918090 {
79928091 if (// DrawMode() != 0 || /*tex == null ||*/
79938092 ambientOcclusion ) // || !textureon)
....@@ -7998,7 +8097,7 @@
79988097 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
79998098
80008099 if (tex != null)
8001
- texture = textures.get(tex);
8100
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
80028101
80038102 // //assert( texture != null );
80048103 // if (texture == null)
....@@ -8092,47 +8191,50 @@
80928191
80938192 /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
80948193 {
8095
- if (// DrawMode() != 0 || /*tex == null ||*/
8096
- ambientOcclusion ) // || !textureon)
8097
- {
8098
- return; // false;
8099
- }
8100
-
8101
- if (tex == null)
8102
- {
8103
- BindTexture(null,false,resolution);
8104
- BindTexture(null,true,resolution);
8105
- return;
8106
- }
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;
81078235
8108
- String pigment = Object3D.GetPigment(tex);
8109
- String bump = Object3D.GetBump(tex);
8110
-
8111
- usedtextures.put(pigment, pigment);
8112
- usedtextures.put(bump, bump);
8113
-
8114
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8115
- {
8116
- // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8117
- // System.out.println("; bump = " + bump);
8118
- }
8119
-
8120
- if (bump.equals(""))
8121
- {
8122
- bump = null;
8123
- }
8124
- if (pigment.equals(""))
8125
- {
8126
- pigment = null;
8127
- }
8128
-
8129
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8130
- BindTexture(pigment, false, resolution);
8131
- GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8132
- BindTexture(bump, true, resolution);
8133
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8134
-
8135
- return; // true;
8236
+ BindPigmentTexture(tex, resolution);
8237
+ BindBumpTexture(tex, resolution);
81368238 }
81378239
81388240 /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8151,9 +8253,9 @@
81518253
81528254 String pigment = Object3D.GetPigment(tex);
81538255
8154
- usedtextures.put(pigment, pigment);
8256
+ usedtextures.add(tex);
81558257
8156
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8258
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
81578259 {
81588260 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
81598261 // System.out.println("; bump = " + bump);
....@@ -8165,7 +8267,7 @@
81658267 }
81668268
81678269 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8168
- BindTexture(pigment, false, resolution);
8270
+ BindTexture(tex, false, resolution);
81698271 }
81708272
81718273 /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8184,9 +8286,9 @@
81848286
81858287 String bump = Object3D.GetBump(tex);
81868288
8187
- usedtextures.put(bump, bump);
8289
+ usedtextures.add(tex);
81888290
8189
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8291
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
81908292 {
81918293 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
81928294 // System.out.println("; bump = " + bump);
....@@ -8198,7 +8300,7 @@
81988300 }
81998301
82008302 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8201
- BindTexture(bump, true, resolution);
8303
+ BindTexture(tex, true, resolution);
82028304 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
82038305 }
82048306
....@@ -8222,13 +8324,19 @@
82228324 return fileExists;
82238325 }
82248326
8225
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception
8327
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
82268328 {
8227
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8329
+ CacheTexture texturecache = null;
82288330
82298331 if (tex != null)
82308332 {
8231
- 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
+ }
82328340
82338341 String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
82348342
....@@ -8238,19 +8346,46 @@
82388346 // else
82398347 // if (!texname.startsWith("/"))
82408348 // texname = "/Users/nbriere/Textures/" + texname;
8241
- if (!FileExists(tex))
8349
+ if (!FileExists(texname))
82428350 {
82438351 texname = fallbackTextureName;
82448352 }
82458353
82468354 if (CACHETEXTURE)
8247
- texture = textures.get(texname); // TEXTURE CACHE
8248
-
8249
- TextureData texturedata = null;
8250
-
8251
- if (texture == null || texture.resolution < resolution)
82528355 {
8253
- 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(""))
82548389 {
82558390 assert(!bump);
82568391 // if (bump)
....@@ -8261,19 +8396,23 @@
82618396 // }
82628397 // else
82638398 // {
8264
- texture = textures.get(tex);
8265
- if (texture == null)
8399
+ // texturecache = textures.get(texname); // suspicious
8400
+ if (texturecache == null)
82668401 {
8267
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8402
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
82688403 }
8404
+ else
8405
+ new Exception().printStackTrace();
82698406 // }
82708407 } else
8271
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8408
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
82728409 {
82738410 assert(bump);
8274
- texture = textures.get(tex);
8275
- if (texture == null)
8276
- 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();
82778416 } else
82788417 {
82798418 //if (tex.equals("IMMORTAL"))
....@@ -8281,11 +8420,13 @@
82818420 // texture = GetResourceTexture("default.png");
82828421 //} else
82838422 //{
8284
- if (tex.equals("WHITE_NOISE"))
8423
+ if (texname.endsWith("WHITE_NOISE"))
82858424 {
8286
- texture = textures.get(tex);
8287
- if (texture == null)
8288
- 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();
82898430 } else
82908431 {
82918432 if (textureon)
....@@ -8344,19 +8485,19 @@
83448485 if (texturedata == null)
83458486 throw new Exception();
83468487
8347
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8488
+ texturecache = new CacheTexture(texturedata,resolution);
83488489 //texture = GetTexture(tex, bump);
83498490 }
83508491 }
83518492 //}
83528493 }
83538494
8354
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8495
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
83558496 {
83568497 //return false;
83578498
83588499 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8359
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8500
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
83608501 {
83618502 // String ext = "_highres";
83628503 // if (REDUCETEXTURE)
....@@ -8373,52 +8514,17 @@
83738514 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
83748515 if (!cachefile.exists())
83758516 {
8376
- // cache to disk
8377
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
8378
- //buffers[0].
8379
-
8380
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
8381
- int[] pixels = new int[bytebuf.capacity()/3];
8382
-
8383
- // squared size heuristic...
8384
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8517
+ //if (texturedata.getWidth() == texturedata.getHeight())
83858518 {
8386
- for (int i=pixels.length; --i>=0;)
8387
- {
8388
- int i3 = i*3;
8389
- pixels[i] = 0xFF;
8390
- pixels[i] <<= 8;
8391
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
8392
- pixels[i] <<= 8;
8393
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
8394
- pixels[i] <<= 8;
8395
- pixels[i] |= bytebuf.get(i3) & 0xFF;
8396
- }
8397
-
8398
- /*
8399
- int r=0,g=0,b=0,a=0;
8400
- for (int i=0; i<width; i++)
8401
- for (int j=0; j<height; j++)
8402
- {
8403
- int index = j*width+i;
8404
- int p = pixels[index];
8405
- a = ((p>>24) & 0xFF);
8406
- r = ((p>>16) & 0xFF);
8407
- g = ((p>>8) & 0xFF);
8408
- b = (p & 0xFF);
8409
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
8410
- }
8411
- /**/
8412
- int width = (int)Math.sqrt(pixels.length); // squared
8413
- int height = width;
8414
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
8415
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8519
+ BufferedImage rendImage = CreateBim(texturedata);
8520
+
84168521 ImageWriter writer = null;
84178522 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
84188523 if (iter.hasNext()) {
84198524 writer = (ImageWriter)iter.next();
84208525 }
8421
- float compressionQuality = 0.9f;
8526
+
8527
+ float compressionQuality = 0.85f;
84228528 try
84238529 {
84248530 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8435,18 +8541,20 @@
84358541 }
84368542 }
84378543 }
8438
-
8544
+
8545
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8546
+
84398547 //System.out.println("Texture = " + tex);
8440
- if (textures.containsKey(texname))
8548
+ if (textures.containsKey(tex))
84418549 {
8442
- CacheTexture thetex = textures.get(texname);
8550
+ CacheTexture thetex = textures.get(tex);
84438551 thetex.texture.disable();
84448552 thetex.texture.dispose();
8445
- textures.remove(texname);
8553
+ textures.remove(tex);
84468554 }
84478555
8448
- texture.texturedata = texturedata;
8449
- textures.put(texname, texture);
8556
+ //texture.texturedata = texturedata;
8557
+ textures.put(tex, texturecache);
84508558
84518559 // newtex = true;
84528560 }
....@@ -8462,10 +8570,44 @@
84628570 }
84638571 }
84648572
8465
- return texture;
8573
+ return texturecache;
84668574 }
84678575
8468
- 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
84698611 {
84708612 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
84718613
....@@ -8483,21 +8625,21 @@
84838625 return texture!=null?texture.texture:null;
84848626 }
84858627
8486
- 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
84878629 {
84888630 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
84898631
84908632 return texture!=null?texture.texturedata:null;
84918633 }
84928634
8493
- boolean BindTexture(String tex, boolean bump, int resolution) throws Exception
8635
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
84948636 {
84958637 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
84968638 {
84978639 return false;
84988640 }
84998641
8500
- boolean newtex = false;
8642
+ //boolean newtex = false;
85018643
85028644 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
85038645
....@@ -8529,9 +8671,75 @@
85298671 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
85308672 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
85318673
8532
- return newtex;
8674
+ return true; // Warning: not used.
85338675 }
85348676
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
+
85358743 ShadowBuffer shadowPBuf;
85368744 AntialiasBuffer antialiasPBuf;
85378745 int MAXSTACK;
....@@ -9367,11 +9575,35 @@
93679575 jy8[3] = 0.5f;
93689576 }
93699577
9370
- 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
93719579 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
93729580 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
93739581 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
93749582
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
+
93759607 static int imagecount = 0; // movie generation
93769608
93779609 static int jitter = 0;
....@@ -9468,7 +9700,7 @@
94689700
94699701 if (renderCamera != lightCamera)
94709702 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9471
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
9703
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
94729704
94739705 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
94749706
....@@ -9484,7 +9716,7 @@
94849716
94859717 if (renderCamera != lightCamera)
94869718 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9487
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
9719
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
94889720
94899721 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
94909722
....@@ -10482,6 +10714,7 @@
1048210714 ANTIALIAS = 0;
1048310715 //System.out.println("RESTART");
1048410716 AAtimer.restart();
10717
+ Globals.TIMERRUNNING = true;
1048510718 }
1048610719 }
1048710720 }
....@@ -10549,7 +10782,8 @@
1054910782 ambientOcclusion = false;
1055010783 }
1055110784
10552
- if (Globals.lighttouched && DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
10785
+ if (//Globals.lighttouched &&
10786
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1055310787 {
1055410788 //if (RENDERSHADOW) // ?
1055510789 if (!IsFrozen())
....@@ -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)
....@@ -11459,15 +11690,36 @@
1145911690
1146011691 static boolean zoomonce = false;
1146111692
11693
+ static void CreateSelectedPoint()
11694
+ {
11695
+ if (selectedpoint == null)
11696
+ {
11697
+ debugpointG = new Sphere();
11698
+ debugpointP = new Sphere();
11699
+ debugpointC = new Sphere();
11700
+ debugpointR = new Sphere();
11701
+
11702
+ selectedpoint = new Superellipsoid();
11703
+
11704
+ for (int i=0; i<8; i++)
11705
+ {
11706
+ debugpoints[i] = new Sphere();
11707
+ }
11708
+ }
11709
+ }
11710
+
1146211711 void DrawObject(GL gl, boolean draw)
1146311712 {
11713
+ // To clear camera values
11714
+ ResetOptions();
11715
+
1146411716 //System.out.println("DRAW OBJECT " + mouseDown);
1146511717 // DrawMode() = SELECTION;
1146611718 //GL gl = getGL();
1146711719 if ((TRACK || SHADOWTRACK) || zoomonce)
1146811720 {
1146911721 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11470
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11722
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1147111723 pingthread.StepToTarget(true); // true);
1147211724 // zoomonce = false;
1147311725 }
....@@ -11539,8 +11791,9 @@
1153911791
1154011792 if (DrawMode() == DEFAULT)
1154111793 {
11542
- if (DEBUG)
11794
+ if (Globals.DEBUG)
1154311795 {
11796
+ CreateSelectedPoint();
1154411797 float radius = 0.05f;
1154511798 if (selectedpoint.radius != radius)
1154611799 {
....@@ -11594,20 +11847,32 @@
1159411847 ReleaseTextures(DEFAULT_TEXTURES);
1159511848
1159611849 if (CLEANCACHE)
11597
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11850
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1159811851 {
11599
- String tex = e.nextElement();
11852
+ cTexture tex = e.nextElement();
1160011853
1160111854 // System.out.println("Texture --------- " + tex);
1160211855
11603
- if (tex.equals("WHITE_NOISE"))
11856
+ if (tex.equals("WHITE_NOISE:"))
1160411857 continue;
1160511858
11606
- if (!usedtextures.containsKey(tex))
11859
+ if (!usedtextures.contains(tex))
1160711860 {
11861
+ CacheTexture gettex = texturepigment.get(tex);
1160811862 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11609
- textures.get(tex).texture.dispose();
11610
- 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
+ }
1161111876 }
1161211877 }
1161311878 }
....@@ -12027,7 +12292,7 @@
1202712292 for (int i = tp.size(); --i >= 0;)
1202812293 {
1202912294 //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12030
- LA.xformPos(light, tp.get(i).GlobalTransform(), light);
12295
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1203112296 }
1203212297
1203312298
....@@ -12136,7 +12401,74 @@
1213612401 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1213712402
1213812403 String program =
12404
+ // Min shader
1213912405 "!!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
+
1214012472 //"OPTION ARB_fragment_program_shadow;" +
1214112473 "PARAM light2cam0 = program.env[10];" +
1214212474 "PARAM light2cam1 = program.env[11];" +
....@@ -12251,8 +12583,7 @@
1225112583 "TEMP shininess;" +
1225212584 "\n" +
1225312585 "MOV texSamp, one;" +
12254
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12255
-
12586
+
1225612587 "MOV mapgrid.x, one2048th.x;" +
1225712588 "MOV temp, fragment.texcoord[1];" +
1225812589 /*
....@@ -12273,20 +12604,20 @@
1227312604 "MUL temp, floor, mapgrid.x;" +
1227412605 //"TEX depth0, temp, texture[1], 2D;" +
1227512606 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12276
- TextureFetch("depth0", "temp", "1") +
12607
+ ShadowTextureFetch("depth0", "temp", "1") +
1227712608 "") +
1227812609 "ADD temp.x, temp.x, mapgrid.x;" +
1227912610 //"TEX depth1, temp, texture[1], 2D;" +
1228012611 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12281
- TextureFetch("depth1", "temp", "1") +
12612
+ ShadowTextureFetch("depth1", "temp", "1") +
1228212613 "") +
1228312614 "ADD temp.y, temp.y, mapgrid.x;" +
1228412615 //"TEX depth2, temp, texture[1], 2D;" +
12285
- TextureFetch("depth2", "temp", "1") +
12616
+ ShadowTextureFetch("depth2", "temp", "1") +
1228612617 "SUB temp.x, temp.x, mapgrid.x;" +
1228712618 //"TEX depth3, temp, texture[1], 2D;" +
1228812619 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12289
- TextureFetch("depth3", "temp", "1") +
12620
+ ShadowTextureFetch("depth3", "temp", "1") +
1229012621 "") +
1229112622 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1229212623 //"MOV params, material;" +
....@@ -12657,7 +12988,7 @@
1265712988 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1265812989 "") +
1265912990
12660
- // display shadow only (bump == 0)
12991
+ // display shadow only (fakedepth == 0)
1266112992 "SUB temp.x, half.x, shadow.x;" +
1266212993 "MOV temp.y, -params5.z;" + // params6.x;" +
1266312994 "SLT temp.z, temp.y, -one2048th.x;" +
....@@ -13084,25 +13415,26 @@
1308413415 return out;
1308513416 }
1308613417
13087
- String TextureFetch(String dest, String src, String unit)
13418
+ // Also does frustum culling
13419
+ String ShadowTextureFetch(String dest, String src, String unit)
1308813420 {
1308913421 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1309013422 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1309113423 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13424
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13425
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1309213426 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13093
- "SLT " + src + ".z, " + src + ".x, one.x;" +
13094
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13095
- "SLT " + src + ".z, " + src + ".y, one.x;" +
13096
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13427
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13428
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1309713429 //"SWZ buffer, temp, w,w,w,w;";
13098
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13430
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1309913431 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1310013432 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1310113433 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13102
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13434
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1310313435
13104
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13105
- //"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;";
1310613438 }
1310713439
1310813440 String Shadow(String depth, String shadow)
....@@ -13149,7 +13481,7 @@
1314913481 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1315013482 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1315113483
13152
- // No shadow when out of frustrum
13484
+ // No shadow when out of frustum
1315313485 "SGE temp.x, " + depth + ".z, one.z;" +
1315413486 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1315513487 "";
....@@ -13297,7 +13629,8 @@
1329713629 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1329813630 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1329913631 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13300
- Object3D.cVector2[] vector2buffer;
13632
+
13633
+ //Object3D.cVector2[] vector2buffer;
1330113634
1330213635 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1330313636 // OUT : diff, spec
....@@ -13313,9 +13646,10 @@
1331313646 "DP3 " + dest + ".z," + "normals," + "eye;" +
1331413647 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1331513648 //"MOV " + dest + ".w," + "normal.z;" +
13316
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
13317
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13318
- //"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
1331913653 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1332013654 "RCP " + dest + ".w," + dest + ".w;" +
1332113655 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13820,6 +14154,7 @@
1382014154 else
1382114155 if (evt.getSource() == AAtimer)
1382214156 {
14157
+ Globals.TIMERRUNNING = false;
1382314158 if (mouseDown)
1382414159 {
1382514160 //new Exception().printStackTrace();
....@@ -13879,7 +14214,7 @@
1387914214
1388014215 // fev 2014???
1388114216 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13882
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14217
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1388314218 pingthread.StepToTarget(true); // true);
1388414219 }
1388514220 // if (!LIVE)
....@@ -13894,6 +14229,7 @@
1389414229 return;
1389514230
1389614231 AAtimer.restart(); //
14232
+ Globals.TIMERRUNNING = true;
1389714233
1389814234 // waslive = LIVE;
1389914235 // LIVE = false;
....@@ -13943,14 +14279,15 @@
1394314279 drag = false;
1394414280 //System.out.println("Mouse DOWN");
1394514281 editObj = false;
13946
- ClickInfo info = new ClickInfo();
13947
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
13948
- info.pane = this;
13949
- info.camera = renderCamera;
13950
- info.x = x;
13951
- info.y = y;
13952
- info.modifiers = modifiersex;
13953
- 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);
1395414291 if (!editObj)
1395514292 {
1395614293 hasMarquee = true;
....@@ -14232,12 +14569,12 @@
1423214569 void GoDown(int mod)
1423314570 {
1423414571 MODIFIERS |= COMMAND;
14235
- /*
14572
+ /**/
1423614573 if((mod&SHIFT) == SHIFT)
1423714574 manipCamera.RotatePosition(0, -speed);
1423814575 else
14239
- manipCamera.BackForth(0, -speed*delta, getWidth());
14240
- */
14576
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14577
+ /**/
1424114578 if ((mod & SHIFT) == SHIFT)
1424214579 {
1424314580 mouseMode = mouseMode; // VR??
....@@ -14253,12 +14590,12 @@
1425314590 void GoUp(int mod)
1425414591 {
1425514592 MODIFIERS |= COMMAND;
14256
- /*
14593
+ /**/
1425714594 if((mod&SHIFT) == SHIFT)
1425814595 manipCamera.RotatePosition(0, speed);
1425914596 else
14260
- manipCamera.BackForth(0, speed*delta, getWidth());
14261
- */
14597
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14598
+ /**/
1426214599 if ((mod & SHIFT) == SHIFT)
1426314600 {
1426414601 mouseMode = mouseMode;
....@@ -14274,12 +14611,12 @@
1427414611 void GoLeft(int mod)
1427514612 {
1427614613 MODIFIERS |= COMMAND;
14277
- /*
14614
+ /**/
1427814615 if((mod&SHIFT) == SHIFT)
14279
- manipCamera.RotatePosition(speed, 0);
14280
- else
1428114616 manipCamera.Translate(speed*delta, 0, getWidth());
14282
- */
14617
+ else
14618
+ manipCamera.RotatePosition(speed, 0);
14619
+ /**/
1428314620 if ((mod & SHIFT) == SHIFT)
1428414621 {
1428514622 mouseMode = mouseMode;
....@@ -14295,12 +14632,12 @@
1429514632 void GoRight(int mod)
1429614633 {
1429714634 MODIFIERS |= COMMAND;
14298
- /*
14635
+ /**/
1429914636 if((mod&SHIFT) == SHIFT)
14300
- manipCamera.RotatePosition(-speed, 0);
14301
- else
1430214637 manipCamera.Translate(-speed*delta, 0, getWidth());
14303
- */
14638
+ else
14639
+ manipCamera.RotatePosition(-speed, 0);
14640
+ /**/
1430414641 if ((mod & SHIFT) == SHIFT)
1430514642 {
1430614643 mouseMode = mouseMode;
....@@ -14350,14 +14687,16 @@
1435014687 if (editObj)
1435114688 {
1435214689 drag = true;
14353
- ClickInfo info = new ClickInfo();
14354
- info.bounds.setBounds(0, 0,
14690
+ //ClickInfo info = new ClickInfo();
14691
+ object.clickInfo.bounds.setBounds(0, 0,
1435514692 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14356
- info.pane = this;
14357
- info.camera = renderCamera;
14358
- info.x = x;
14359
- info.y = y;
14360
- object.editWindow.copy.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);
1436114700 } else
1436214701 {
1436314702 if (x < startX)
....@@ -14506,22 +14845,27 @@
1450614845 }
1450714846 }
1450814847
14848
+// ClickInfo clickInfo = new ClickInfo();
14849
+
1450914850 public void mouseMoved(MouseEvent e)
1451014851 {
1451114852 //System.out.println("mouseMoved: " + e);
1451214853 if (isRenderer)
1451314854 return;
1451414855
14515
- ClickInfo ci = new ClickInfo();
14516
- ci.x = e.getX();
14517
- ci.y = e.getY();
14518
- ci.modifiers = e.getModifiersEx();
14519
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14520
- ci.pane = this;
14521
- 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;
1452214863 if (!isRenderer)
1452314864 {
14524
- if (object.editWindow.copy.doEditClick(ci, 0))
14865
+ //ObjEditor editWindow = object.editWindow;
14866
+ //Object3D copy = editWindow.copy;
14867
+ if (object.doEditClick(//clickInfo,
14868
+ 0))
1452514869 {
1452614870 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1452714871 } else
....@@ -14536,7 +14880,8 @@
1453614880 Globals.MOUSEDRAGGED = false;
1453714881
1453814882 movingcamera = false;
14539
- X = Y = 0;
14883
+ X = 0; // getBounds().width/2;
14884
+ Y = 0; // getBounds().height/2;
1454014885 //System.out.println("mouseReleased: " + e);
1454114886 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1454214887 }
....@@ -14792,7 +15137,8 @@
1479215137 // break;
1479315138 case 'T':
1479415139 CACHETEXTURE ^= true;
14795
- textures.clear();
15140
+ texturepigment.clear();
15141
+ texturebump.clear();
1479615142 // repaint();
1479715143 break;
1479815144 case 'Y':
....@@ -14877,7 +15223,9 @@
1487715223 case 'E' : COMPACT ^= true;
1487815224 repaint();
1487915225 break;
14880
- case 'W' : DEBUGHSB ^= true;
15226
+ case 'W' : // Wide Window (fullscreen)
15227
+ //DEBUGHSB ^= true;
15228
+ ObjEditor.theFrame.ToggleFullScreen();
1488115229 repaint();
1488215230 break;
1488315231 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14902,8 +15250,8 @@
1490215250 RevertCamera();
1490315251 repaint();
1490415252 break;
14905
- case 'L':
1490615253 case 'l':
15254
+ //case 'L':
1490715255 if (lightMode)
1490815256 {
1490915257 lightMode = false;
....@@ -15046,9 +15394,9 @@
1504615394 case '_':
1504715395 kompactbit = 5;
1504815396 break;
15049
- case '+':
15050
- kompactbit = 6;
15051
- break;
15397
+// case '+':
15398
+// kompactbit = 6;
15399
+// break;
1505215400 case ' ':
1505315401 lightMode ^= true;
1505415402 Globals.lighttouched = true;
....@@ -15060,6 +15408,7 @@
1506015408 case ESC:
1506115409 RENDERPROGRAM += 1;
1506215410 RENDERPROGRAM %= 3;
15411
+
1506315412 repaint();
1506415413 break;
1506515414 case 'Z':
....@@ -15099,8 +15448,9 @@
1509915448 case DELETE:
1510015449 ClearSelection();
1510115450 break;
15102
- /*
1510315451 case '+':
15452
+
15453
+ /*
1510415454 //fontsize += 1;
1510515455 bbzoom *= 2;
1510615456 repaint();
....@@ -15117,17 +15467,17 @@
1511715467 case '=':
1511815468 IncDepth();
1511915469 //fontsize += 1;
15120
- object.editWindow.refreshContents(true);
15470
+ object.GetWindow().refreshContents(true);
1512115471 maskbit = 6;
1512215472 break;
1512315473 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1512415474 DecDepth();
1512515475 maskbit = 5;
1512615476 //if(fontsize > 1) fontsize -= 1;
15127
- if (object.editWindow == null)
15128
- new Exception().printStackTrace();
15129
- else
15130
- object.editWindow.refreshContents(true);
15477
+// if (object.editWindow == null)
15478
+// new Exception().printStackTrace();
15479
+// else
15480
+ object.GetWindow().refreshContents(true);
1513115481 break;
1513215482 case '{':
1513315483 manipCamera.shaper_fovy /= 1.1;
....@@ -15351,7 +15701,7 @@
1535115701 }
1535215702 */
1535315703
15354
- object.editWindow.EditSelection();
15704
+ object.GetWindow().EditSelection(false);
1535515705 }
1535615706
1535715707 void SelectParent()
....@@ -15368,10 +15718,10 @@
1536815718 {
1536915719 //selectees.remove(i);
1537015720 System.out.println("select parent of " + elem);
15371
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15721
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1537215722 } else
1537315723 {
15374
- group.editWindow.Select(elem.GetTreePath(), first, true);
15724
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1537515725 }
1537615726
1537715727 first = false;
....@@ -15413,12 +15763,12 @@
1541315763 for (int j = 0; j < group.children.size(); j++)
1541415764 {
1541515765 elem = (Object3D) group.children.elementAt(j);
15416
- object.editWindow.Select(elem.GetTreePath(), first, true);
15766
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1541715767 first = false;
1541815768 }
1541915769 } else
1542015770 {
15421
- object.editWindow.Select(elem.GetTreePath(), first, true);
15771
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1542215772 }
1542315773
1542415774 first = false;
....@@ -15429,21 +15779,21 @@
1542915779 {
1543015780 //Composite group = (Composite) object;
1543115781 Object3D group = object;
15432
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15782
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1543315783 }
1543415784
1543515785 void ResetTransform(int mask)
1543615786 {
1543715787 //Composite group = (Composite) object;
1543815788 Object3D group = object;
15439
- group.editWindow.ResetTransform(mask);
15789
+ group.GetWindow().ResetTransform(mask);
1544015790 }
1544115791
1544215792 void FlipTransform()
1544315793 {
1544415794 //Composite group = (Composite) object;
1544515795 Object3D group = object;
15446
- group.editWindow.FlipTransform();
15796
+ group.GetWindow().FlipTransform();
1544715797 // group.editWindow.ReduceMesh(true);
1544815798 }
1544915799
....@@ -15451,7 +15801,7 @@
1545115801 {
1545215802 //Composite group = (Composite) object;
1545315803 Object3D group = object;
15454
- group.editWindow.PrintMemory();
15804
+ group.GetWindow().PrintMemory();
1545515805 // group.editWindow.ReduceMesh(true);
1545615806 }
1545715807
....@@ -15459,7 +15809,7 @@
1545915809 {
1546015810 //Composite group = (Composite) object;
1546115811 Object3D group = object;
15462
- group.editWindow.ResetCentroid();
15812
+ group.GetWindow().ResetCentroid();
1546315813 }
1546415814
1546515815 void IncDepth()
....@@ -15541,8 +15891,6 @@
1554115891
1554215892 int width = getBounds().width;
1554315893 int height = getBounds().height;
15544
- ClickInfo info = new ClickInfo();
15545
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1554615894 //Image img = CreateImage(width, height);
1554715895 //System.out.println("width = " + width + "; height = " + height + "\n");
1554815896
....@@ -15619,48 +15967,77 @@
1561915967 }
1562015968 if (object != null && !hasMarquee)
1562115969 {
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
+
1562215976 if (isRenderer)
1562315977 {
15624
- info.flags++;
15978
+ object.clickInfo.flags++;
1562515979 double frameAspect = (double) width / (double) height;
1562615980 if (frameAspect > renderCamera.aspect)
1562715981 {
1562815982 int desired = (int) ((double) height * renderCamera.aspect);
15629
- info.bounds.width -= width - desired;
15630
- info.bounds.x += (width - desired) / 2;
15983
+ object.clickInfo.bounds.width -= width - desired;
15984
+ object.clickInfo.bounds.x += (width - desired) / 2;
1563115985 } else
1563215986 {
1563315987 int desired = (int) ((double) width / renderCamera.aspect);
15634
- info.bounds.height -= height - desired;
15635
- info.bounds.y += (height - desired) / 2;
15988
+ object.clickInfo.bounds.height -= height - desired;
15989
+ object.clickInfo.bounds.y += (height - desired) / 2;
1563615990 }
1563715991 }
15638
- info.g = gr;
15639
- info.camera = renderCamera;
15992
+
15993
+ object.clickInfo.g = gr;
15994
+ object.clickInfo.camera = renderCamera;
1564015995 /*
1564115996 // Memory intensive (brep.verticescopy)
1564215997 if (!(object instanceof Composite))
1564315998 object.draw(info, 0, false); // SLOW :
1564415999 */
15645
- if (!isRenderer)
16000
+ if (!isRenderer) // && drag)
1564616001 {
15647
- object.drawEditHandles(info, 0);
15648
-
15649
- 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)
1565016005 {
15651
- 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)
1565216012 {
15653
- case Object3D.hitCenter: gr.setColor(Color.pink);
15654
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15655
- break;
15656
- case Object3D.hitRotate: gr.setColor(Color.yellow);
15657
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15658
- break;
15659
- case Object3D.hitScale: gr.setColor(Color.cyan);
15660
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15661
- 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;
1566216020 }
15663
-
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
+ }
1566416041 }
1566516042 }
1566616043 }
....@@ -16363,16 +16740,16 @@
1636316740 cStatic.objectstack[materialdepth++] = checker;
1636416741 //System.out.println("material " + material);
1636516742 //Applet3D.tracein(this, selected);
16366
- vector2buffer = checker.projectedVertices;
16743
+ //vector2buffer = checker.projectedVertices;
1636716744
1636816745 //checker.GetMaterial().Draw(this, false); // true);
16369
- DrawMaterial(checker.GetMaterial(), false); // true);
16746
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1637016747
1637116748 materialdepth -= 1;
1637216749 if (materialdepth > 0)
1637316750 {
16374
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16375
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
16751
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16752
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1637616753 }
1637716754 //checker.GetMaterial().opacity = 1f;
1637816755 ////checker.GetMaterial().ambient = 1f;
....@@ -16458,6 +16835,14 @@
1645816835 }
1645916836 }
1646016837
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
+
1646116846 class SelectBuffer implements GLEventListener
1646216847 {
1646316848
....@@ -16537,6 +16922,17 @@
1653716922
1653816923 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1653916924
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
+
1654016936 //int tmp = selection_view;
1654116937 //selection_view = -1;
1654216938 int temp = DrawMode();
....@@ -16548,6 +16944,17 @@
1654816944 // temp = DEFAULT; // patch for selection debug
1654916945 Globals.drawMode = temp; // WARNING
1655016946
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
+
1655116958 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1655216959
1655316960 // trying different ways of getting the depth info over
....@@ -16595,6 +17002,8 @@
1659517002 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1659617003 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1659717004 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
17005
+
17006
+ CreateSelectedPoint();
1659817007
1659917008 // Will fit the mesh !!!
1660017009 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16649,29 +17058,31 @@
1664917058 }
1665017059
1665117060 if (!movingcamera && !PAINTMODE)
16652
- object.editWindow.ScreenFitPoint(); // fev 2014
17061
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1665317062
16654
- 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)
1665517064 {
16656
- 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);
1665717066
16658
- Object3D group = new Object3D("inst" + paintcount++);
17067
+ if (object.GetWindow().copy.selection.Size() > 0)
17068
+ {
17069
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1665917070
16660
- group.CreateMaterial(); // use a void leaf to select instances
16661
-
16662
- group.add(paintobj); // link
16663
-
16664
- object.editWindow.SnapObject(group);
16665
-
16666
- Object3D folder = object.editWindow.copy;
16667
-
16668
- if (object.editWindow.copy.selection.Size() > 0)
16669
- folder = object.editWindow.copy.selection.elementAt(0);
16670
-
16671
- folder.add(group);
16672
-
16673
- object.editWindow.ResetModel();
16674
- 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
+ }
1667517086 }
1667617087 else
1667717088 paintcount = 0;
....@@ -16710,6 +17121,11 @@
1671017121 //System.out.println("objects[color] = " + objects[color]);
1671117122 //objects[color].Select();
1671217123 indexcount = 0;
17124
+ ObjEditor window = object.GetWindow();
17125
+ if (window != null && deselect)
17126
+ {
17127
+ window.Select(null, deselect, true);
17128
+ }
1671317129 object.Select(color, deselect);
1671417130 }
1671517131
....@@ -17235,23 +17651,15 @@
1723517651 int AAbuffersize = 0;
1723617652
1723717653 //double[] selectedpoint = new double[3];
17238
- static Superellipsoid selectedpoint = new Superellipsoid();
17654
+ static Superellipsoid selectedpoint;
1723917655 static Sphere previousselectedpoint = null;
17240
- static Sphere debugpointG = new Sphere();
17241
- static Sphere debugpointP = new Sphere();
17242
- static Sphere debugpointC = new Sphere();
17243
- static Sphere debugpointR = new Sphere();
17656
+ static Sphere debugpointG;
17657
+ static Sphere debugpointP;
17658
+ static Sphere debugpointC;
17659
+ static Sphere debugpointR;
1724417660
1724517661 static Sphere debugpoints[] = new Sphere[8];
1724617662
17247
- static
17248
- {
17249
- for (int i=0; i<8; i++)
17250
- {
17251
- debugpoints[i] = new Sphere();
17252
- }
17253
- }
17254
-
1725517663 static void InitPoints(float radius)
1725617664 {
1725717665 for (int i=0; i<8; i++)