Normand Briere
2019-07-22 c570e1e38f2ff8622a71f81436654bad01cfdd5b
CameraPane.java
....@@ -37,7 +37,6 @@
3737 static boolean[] selectedstack = new boolean[65536];
3838 static int materialdepth = 0;
3939
40
- static boolean DEBUG = false;
4140 static boolean FRUSTUM = false; // still bogus true; // frustum culling
4241
4342 // camera change fix
....@@ -45,6 +44,39 @@
4544 static boolean ABORTED = false;
4645
4746 static int STEP = 1;
47
+
48
+ private static BufferedImage CreateBim(byte[] bytes, int width, int height)
49
+ {
50
+ int[] pixels = new int[bytes.length/3];
51
+ for (int i=pixels.length; --i>=0;)
52
+ {
53
+ int i3 = i*3;
54
+ pixels[i] = 0xFF;
55
+ pixels[i] <<= 8;
56
+ pixels[i] |= bytes[i3+2] & 0xFF;
57
+ pixels[i] <<= 8;
58
+ pixels[i] |= bytes[i3+1] & 0xFF;
59
+ pixels[i] <<= 8;
60
+ pixels[i] |= bytes[i3] & 0xFF;
61
+ }
62
+ /*
63
+ int r=0,g=0,b=0,a=0;
64
+ for (int i=0; i<width; i++)
65
+ for (int j=0; j<height; j++)
66
+ {
67
+ int index = j*width+i;
68
+ int p = pixels[index];
69
+ a = ((p>>24) & 0xFF);
70
+ r = ((p>>16) & 0xFF);
71
+ g = ((p>>8) & 0xFF);
72
+ b = (p & 0xFF);
73
+ pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
74
+ }
75
+ /**/
76
+ BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
77
+ rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
78
+ return rendImage;
79
+ }
4880
4981 /*static*/ private boolean CULLFACE = false; // true;
5082 /*static*/ boolean NEAREST = false; // true;
....@@ -61,7 +93,7 @@
6193 //boolean REDUCETEXTURE = true;
6294 boolean CACHETEXTURE = true;
6395 boolean CLEANCACHE = false; // true;
64
- boolean MIPMAP = false; // true;
96
+ boolean MIPMAP = true; // false; // true;
6597 boolean COMPRESSTEXTURE = false;
6698 boolean KOMPACTTEXTURE = false; // true;
6799 boolean RESIZETEXTURE = false;
....@@ -327,7 +359,7 @@
327359 cStatic.objectstack[materialdepth++] = obj;
328360 //System.out.println("material " + material);
329361 //Applet3D.tracein(this, selected);
330
- display.vector2buffer = obj.projectedVertices;
362
+ //display.vector2buffer = obj.projectedVertices;
331363 if (obj instanceof Camera)
332364 {
333365 display.options1[0] = material.shift;
....@@ -336,14 +368,28 @@
336368 display.options1[2] = material.shadowbias;
337369 display.options1[3] = material.aniso;
338370 display.options1[4] = material.anisoV;
371
+// System.out.println("display.options1[0] " + display.options1[0]);
372
+// System.out.println("display.options1[1] " + display.options1[1]);
373
+// System.out.println("display.options1[2] " + display.options1[2]);
374
+// System.out.println("display.options1[3] " + display.options1[3]);
375
+// System.out.println("display.options1[4] " + display.options1[4]);
339376 display.options2[0] = material.opacity;
340377 display.options2[1] = material.diffuse;
341378 display.options2[2] = material.factor;
379
+// System.out.println("display.options2[0] " + display.options2[0]);
380
+// System.out.println("display.options2[1] " + display.options2[1]);
381
+// System.out.println("display.options2[2] " + display.options2[2]);
342382
343383 cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
384
+// System.out.println("display.options3[0] " + display.options3[0]);
385
+// System.out.println("display.options3[1] " + display.options3[1]);
386
+// System.out.println("display.options3[2] " + display.options3[2]);
344387 display.options4[0] = material.cameralight/0.2f;
345388 display.options4[1] = material.subsurface;
346389 display.options4[2] = material.sheen;
390
+// System.out.println("display.options4[0] " + display.options4[0]);
391
+// System.out.println("display.options4[1] " + display.options4[1]);
392
+// System.out.println("display.options4[2] " + display.options4[2]);
347393
348394 // if (display.CURRENTANTIALIAS > 0)
349395 // display.options3[3] /= 4;
....@@ -359,7 +405,7 @@
359405 /**/
360406 } else
361407 {
362
- DrawMaterial(material, selected);
408
+ DrawMaterial(material, selected, obj.projectedVertices);
363409 }
364410 } else
365411 {
....@@ -383,8 +429,8 @@
383429 cStatic.objectstack[materialdepth++] = obj;
384430 //System.out.println("material " + material);
385431 //Applet3D.tracein("selected ", selected);
386
- display.vector2buffer = obj.projectedVertices;
387
- display.DrawMaterial(material, selected);
432
+ //display.vector2buffer = obj.projectedVertices;
433
+ display.DrawMaterial(material, selected, obj.projectedVertices);
388434 }
389435 }
390436
....@@ -401,8 +447,8 @@
401447 materialdepth -= 1;
402448 if (materialdepth > 0)
403449 {
404
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
405
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
450
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
451
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
406452 }
407453 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
408454 } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
....@@ -422,8 +468,8 @@
422468 materialdepth -= 1;
423469 if (materialdepth > 0)
424470 {
425
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
426
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
471
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
472
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
427473 }
428474 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
429475 //else
....@@ -1611,7 +1657,7 @@
16111657 // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
16121658 }
16131659
1614
- void DrawMaterial(cMaterial material, boolean selected)
1660
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
16151661 {
16161662 CameraPane display = this;
16171663 //new Exception().printStackTrace();
....@@ -1646,7 +1692,7 @@
16461692 colorV[0] = display.modelParams0[0] * material.diffuse;
16471693 colorV[1] = display.modelParams0[1] * material.diffuse;
16481694 colorV[2] = display.modelParams0[2] * material.diffuse;
1649
- colorV[3] = material.opacity;
1695
+ colorV[3] = 1; // material.opacity;
16501696
16511697 gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
16521698 //System.out.println("Opacity = " + opacity);
....@@ -1754,9 +1800,9 @@
17541800 display.modelParams7[2] = 0;
17551801 display.modelParams7[3] = 0;
17561802
1757
- display.modelParams6[0] = 100; // criss de bug de bump
1803
+ //display.modelParams6[0] = 100; // criss de bug de bump
17581804
1759
- Object3D.cVector2[] extparams = display.vector2buffer;
1805
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
17601806 if (extparams != null && extparams.length > 0 && extparams[0] != null)
17611807 {
17621808 display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
....@@ -2052,7 +2098,7 @@
20522098 //System.err.println("Oeil on");
20532099 OEIL = true;
20542100 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2055
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2101
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
20562102 //pingthread.StepToTarget(true);
20572103 }
20582104
....@@ -2267,7 +2313,7 @@
22672313
22682314 void ToggleDebug()
22692315 {
2270
- DEBUG ^= true;
2316
+ Globals.DEBUG ^= true;
22712317 }
22722318
22732319 void ToggleLookAt()
....@@ -2285,10 +2331,17 @@
22852331 HANDLES ^= true;
22862332 }
22872333
2334
+ Object3D paintFolder;
2335
+
22882336 void TogglePaint()
22892337 {
22902338 PAINTMODE ^= true;
22912339 paintcount = 0;
2340
+
2341
+ if (PAINTMODE)
2342
+ {
2343
+ paintFolder = GetFolder();
2344
+ }
22922345 }
22932346
22942347 void SwapCamera(int a, int b)
....@@ -2385,6 +2438,21 @@
23852438 return currentGL;
23862439 }
23872440
2441
+ static private BufferedImage CreateBim(TextureData texturedata)
2442
+ {
2443
+ Grafreed.Assert(texturedata != null);
2444
+
2445
+ int width = texturedata.getWidth();
2446
+ int height = texturedata.getHeight();
2447
+
2448
+ Buffer buffer = texturedata.getBuffer();
2449
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2450
+
2451
+ byte[] bytes = bytebuf.array();
2452
+
2453
+ return CreateBim(bytes, width, height);
2454
+ }
2455
+
23882456 /**/
23892457 class CacheTexture
23902458 {
....@@ -2393,28 +2461,31 @@
23932461
23942462 int resolution;
23952463
2396
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2464
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
23972465 {
2398
- texture = tex;
2466
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2467
+ texturedata = texdata;
23992468 resolution = res;
24002469 }
24012470 }
24022471 /**/
24032472
24042473 // 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>();
2474
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2475
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2476
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2477
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2478
+
24082479 int pigmentdepth = 0;
24092480 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
24102481 int bumpdepth = 0;
24112482 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
24122483 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
24132484 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2414
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2485
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
24152486 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
24162487
2417
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2488
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
24182489 {
24192490 TextureData texturedata = null;
24202491
....@@ -2433,13 +2504,34 @@
24332504 if (bump)
24342505 texturedata = ConvertBump(texturedata, false);
24352506
2436
- com.sun.opengl.util.texture.Texture texture =
2437
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2507
+// com.sun.opengl.util.texture.Texture texture =
2508
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
24382509
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);
2510
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2511
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
24412512
2442
- return texture;
2513
+ return texturedata;
2514
+ }
2515
+
2516
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2517
+ {
2518
+ TextureData texturedata = null;
2519
+
2520
+ try
2521
+ {
2522
+ texturedata =
2523
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2524
+ bim,
2525
+ true);
2526
+ } catch (Exception e)
2527
+ {
2528
+ throw new javax.media.opengl.GLException(e);
2529
+ }
2530
+
2531
+ if (bump)
2532
+ texturedata = ConvertBump(texturedata, false);
2533
+
2534
+ return texturedata;
24432535 }
24442536
24452537 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3512,6 +3604,8 @@
35123604
35133605 System.out.println("LOADING TEXTURE : " + name);
35143606
3607
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3608
+
35153609 //
35163610 if (false) // compressbit > 0)
35173611 {
....@@ -7910,7 +8004,7 @@
79108004 String pigment = Object3D.GetPigment(tex);
79118005 String bump = Object3D.GetBump(tex);
79128006
7913
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8007
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79148008 {
79158009 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79168010 // System.out.println("; bump = " + bump);
....@@ -7925,8 +8019,8 @@
79258019 pigment = null;
79268020 }
79278021
7928
- ReleaseTexture(bump, true);
7929
- ReleaseTexture(pigment, false);
8022
+ ReleaseTexture(tex, true);
8023
+ ReleaseTexture(tex, false);
79308024 }
79318025
79328026 public void ReleasePigmentTexture(cTexture tex) // INTERFACE
....@@ -7944,7 +8038,7 @@
79448038
79458039 String pigment = Object3D.GetPigment(tex);
79468040
7947
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8041
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79488042 {
79498043 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79508044 // System.out.println("; bump = " + bump);
....@@ -7955,7 +8049,7 @@
79558049 pigment = null;
79568050 }
79578051
7958
- ReleaseTexture(pigment, false);
8052
+ ReleaseTexture(tex, false);
79598053 }
79608054
79618055 public void ReleaseBumpTexture(cTexture tex) // INTERFACE
....@@ -7973,7 +8067,7 @@
79738067
79748068 String bump = Object3D.GetBump(tex);
79758069
7976
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8070
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79778071 {
79788072 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79798073 // System.out.println("; bump = " + bump);
....@@ -7984,10 +8078,10 @@
79848078 bump = null;
79858079 }
79868080
7987
- ReleaseTexture(bump, true);
8081
+ ReleaseTexture(tex, true);
79888082 }
79898083
7990
- void ReleaseTexture(String tex, boolean bump)
8084
+ void ReleaseTexture(cTexture tex, boolean bump)
79918085 {
79928086 if (// DrawMode() != 0 || /*tex == null ||*/
79938087 ambientOcclusion ) // || !textureon)
....@@ -7998,7 +8092,7 @@
79988092 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
79998093
80008094 if (tex != null)
8001
- texture = textures.get(tex);
8095
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
80028096
80038097 // //assert( texture != null );
80048098 // if (texture == null)
....@@ -8092,47 +8186,50 @@
80928186
80938187 /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
80948188 {
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
- }
8189
+// if (// DrawMode() != 0 || /*tex == null ||*/
8190
+// ambientOcclusion ) // || !textureon)
8191
+// {
8192
+// return; // false;
8193
+// }
8194
+//
8195
+// if (tex == null)
8196
+// {
8197
+// BindTexture(null,false,resolution);
8198
+// BindTexture(null,true,resolution);
8199
+// return;
8200
+// }
8201
+//
8202
+// String pigment = Object3D.GetPigment(tex);
8203
+// String bump = Object3D.GetBump(tex);
8204
+//
8205
+// usedtextures.add(pigment);
8206
+// usedtextures.add(bump);
8207
+//
8208
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8209
+// {
8210
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8211
+// // System.out.println("; bump = " + bump);
8212
+// }
8213
+//
8214
+// if (bump.equals(""))
8215
+// {
8216
+// bump = null;
8217
+// }
8218
+// if (pigment.equals(""))
8219
+// {
8220
+// pigment = null;
8221
+// }
8222
+//
8223
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8224
+// BindTexture(pigment, false, resolution);
8225
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8226
+// BindTexture(bump, true, resolution);
8227
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8228
+//
8229
+// return; // true;
81078230
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;
8231
+ BindPigmentTexture(tex, resolution);
8232
+ BindBumpTexture(tex, resolution);
81368233 }
81378234
81388235 /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8151,9 +8248,9 @@
81518248
81528249 String pigment = Object3D.GetPigment(tex);
81538250
8154
- usedtextures.put(pigment, pigment);
8251
+ usedtextures.add(tex);
81558252
8156
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8253
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
81578254 {
81588255 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
81598256 // System.out.println("; bump = " + bump);
....@@ -8165,7 +8262,7 @@
81658262 }
81668263
81678264 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8168
- BindTexture(pigment, false, resolution);
8265
+ BindTexture(tex, false, resolution);
81698266 }
81708267
81718268 /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8184,9 +8281,9 @@
81848281
81858282 String bump = Object3D.GetBump(tex);
81868283
8187
- usedtextures.put(bump, bump);
8284
+ usedtextures.add(tex);
81888285
8189
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8286
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
81908287 {
81918288 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
81928289 // System.out.println("; bump = " + bump);
....@@ -8198,7 +8295,7 @@
81988295 }
81998296
82008297 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8201
- BindTexture(bump, true, resolution);
8298
+ BindTexture(tex, true, resolution);
82028299 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
82038300 }
82048301
....@@ -8222,13 +8319,19 @@
82228319 return fileExists;
82238320 }
82248321
8225
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception
8322
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
82268323 {
8227
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8324
+ CacheTexture texturecache = null;
82288325
82298326 if (tex != null)
82308327 {
8231
- String texname = tex;
8328
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8329
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
8330
+
8331
+ if (texname.equals("") && texdata == null)
8332
+ {
8333
+ return null;
8334
+ }
82328335
82338336 String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
82348337
....@@ -8238,19 +8341,34 @@
82388341 // else
82398342 // if (!texname.startsWith("/"))
82408343 // texname = "/Users/nbriere/Textures/" + texname;
8241
- if (!FileExists(tex))
8344
+ if (!FileExists(texname))
82428345 {
82438346 texname = fallbackTextureName;
82448347 }
82458348
82468349 if (CACHETEXTURE)
8247
- texture = textures.get(texname); // TEXTURE CACHE
8248
-
8249
- TextureData texturedata = null;
8250
-
8251
- if (texture == null || texture.resolution < resolution)
82528350 {
8253
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8351
+ if (texdata == null)
8352
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8353
+ else
8354
+ texturecache = bimtextures.get(texdata);
8355
+ }
8356
+
8357
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8358
+ {
8359
+ TextureData texturedata = null;
8360
+
8361
+ if (texdata != null)
8362
+ {
8363
+ BufferedImage bim = //new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8364
+
8365
+ CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8366
+
8367
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8368
+ bimtextures.put(texdata, texturecache);
8369
+ }
8370
+ else
8371
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
82548372 {
82558373 assert(!bump);
82568374 // if (bump)
....@@ -8261,19 +8379,23 @@
82618379 // }
82628380 // else
82638381 // {
8264
- texture = textures.get(tex);
8265
- if (texture == null)
8382
+ // texturecache = textures.get(texname); // suspicious
8383
+ if (texturecache == null)
82668384 {
8267
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8385
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
82688386 }
8387
+ else
8388
+ new Exception().printStackTrace();
82698389 // }
82708390 } else
8271
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8391
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
82728392 {
82738393 assert(bump);
8274
- texture = textures.get(tex);
8275
- if (texture == null)
8276
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8394
+ // texturecache = textures.get(texname); // suspicious
8395
+ if (texturecache == null)
8396
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8397
+ else
8398
+ new Exception().printStackTrace();
82778399 } else
82788400 {
82798401 //if (tex.equals("IMMORTAL"))
....@@ -8281,11 +8403,13 @@
82818403 // texture = GetResourceTexture("default.png");
82828404 //} else
82838405 //{
8284
- if (tex.equals("WHITE_NOISE"))
8406
+ if (texname.endsWith("WHITE_NOISE"))
82858407 {
8286
- texture = textures.get(tex);
8287
- if (texture == null)
8288
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8408
+ // texturecache = textures.get(texname); // suspicious
8409
+ if (texturecache == null)
8410
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8411
+ else
8412
+ new Exception().printStackTrace();
82898413 } else
82908414 {
82918415 if (textureon)
....@@ -8344,19 +8468,19 @@
83448468 if (texturedata == null)
83458469 throw new Exception();
83468470
8347
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8471
+ texturecache = new CacheTexture(texturedata,resolution);
83488472 //texture = GetTexture(tex, bump);
83498473 }
83508474 }
83518475 //}
83528476 }
83538477
8354
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8478
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
83558479 {
83568480 //return false;
83578481
83588482 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8359
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8483
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
83608484 {
83618485 // String ext = "_highres";
83628486 // if (REDUCETEXTURE)
....@@ -8373,52 +8497,17 @@
83738497 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
83748498 if (!cachefile.exists())
83758499 {
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))
8500
+ //if (texturedata.getWidth() == texturedata.getHeight())
83858501 {
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);
8502
+ BufferedImage rendImage = CreateBim(texturedata);
8503
+
84168504 ImageWriter writer = null;
84178505 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
84188506 if (iter.hasNext()) {
84198507 writer = (ImageWriter)iter.next();
84208508 }
8421
- float compressionQuality = 0.9f;
8509
+
8510
+ float compressionQuality = 0.85f;
84228511 try
84238512 {
84248513 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8435,18 +8524,20 @@
84358524 }
84368525 }
84378526 }
8438
-
8527
+
8528
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8529
+
84398530 //System.out.println("Texture = " + tex);
8440
- if (textures.containsKey(texname))
8531
+ if (textures.containsKey(tex))
84418532 {
8442
- CacheTexture thetex = textures.get(texname);
8533
+ CacheTexture thetex = textures.get(tex);
84438534 thetex.texture.disable();
84448535 thetex.texture.dispose();
8445
- textures.remove(texname);
8536
+ textures.remove(tex);
84468537 }
84478538
8448
- texture.texturedata = texturedata;
8449
- textures.put(texname, texture);
8539
+ //texture.texturedata = texturedata;
8540
+ textures.put(tex, texturecache);
84508541
84518542 // newtex = true;
84528543 }
....@@ -8462,10 +8553,41 @@
84628553 }
84638554 }
84648555
8465
- return texture;
8556
+ return texturecache;
84668557 }
84678558
8468
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution) throws Exception
8559
+ static void EmbedTextures(cTexture tex)
8560
+ {
8561
+ if (tex.pigmentdata == null)
8562
+ {
8563
+ String texname = Object3D.GetPigment(tex);
8564
+
8565
+ CacheTexture texturecache = texturepigment.get(tex);
8566
+
8567
+ if (texturecache != null)
8568
+ {
8569
+ tex.pigmentdata = ((ByteBuffer)texturecache.texturedata.getBuffer()).array();
8570
+ tex.pw = texturecache.texturedata.getWidth();
8571
+ tex.ph = texturecache.texturedata.getHeight();
8572
+ }
8573
+ }
8574
+
8575
+ if (tex.bumpdata == null)
8576
+ {
8577
+ String texname = Object3D.GetBump(tex);
8578
+
8579
+ CacheTexture texturecache = texturebump.get(tex);
8580
+
8581
+ if (texturecache != null)
8582
+ {
8583
+ tex.bumpdata = ((ByteBuffer)texturecache.texturedata.getBuffer()).array();
8584
+ tex.bw = texturecache.texturedata.getWidth();
8585
+ tex.bh = texturecache.texturedata.getHeight();
8586
+ }
8587
+ }
8588
+ }
8589
+
8590
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
84698591 {
84708592 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
84718593
....@@ -8483,21 +8605,21 @@
84838605 return texture!=null?texture.texture:null;
84848606 }
84858607
8486
- public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution) throws Exception
8608
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
84878609 {
84888610 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
84898611
84908612 return texture!=null?texture.texturedata:null;
84918613 }
84928614
8493
- boolean BindTexture(String tex, boolean bump, int resolution) throws Exception
8615
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
84948616 {
84958617 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
84968618 {
84978619 return false;
84988620 }
84998621
8500
- boolean newtex = false;
8622
+ //boolean newtex = false;
85018623
85028624 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
85038625
....@@ -8529,7 +8651,7 @@
85298651 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
85308652 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
85318653
8532
- return newtex;
8654
+ return true; // Warning: not used.
85338655 }
85348656
85358657 ShadowBuffer shadowPBuf;
....@@ -9367,11 +9489,35 @@
93679489 jy8[3] = 0.5f;
93689490 }
93699491
9370
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9492
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
93719493 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
93729494 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
93739495 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
93749496
9497
+ void ResetOptions()
9498
+ {
9499
+ options1[0] = 100;
9500
+ options1[1] = 0.025f;
9501
+ options1[2] = 0.01f;
9502
+ options1[3] = 0;
9503
+ options1[4] = 0;
9504
+
9505
+ options2[0] = 0;
9506
+ options2[1] = 0.75f;
9507
+ options2[2] = 0;
9508
+ options2[3] = 0;
9509
+
9510
+ options3[0] = 1;
9511
+ options3[1] = 1;
9512
+ options3[2] = 1;
9513
+ options3[3] = 0;
9514
+
9515
+ options4[0] = 1;
9516
+ options4[1] = 0;
9517
+ options4[2] = 1;
9518
+ options4[3] = 0;
9519
+ }
9520
+
93759521 static int imagecount = 0; // movie generation
93769522
93779523 static int jitter = 0;
....@@ -10482,6 +10628,7 @@
1048210628 ANTIALIAS = 0;
1048310629 //System.out.println("RESTART");
1048410630 AAtimer.restart();
10631
+ Globals.TIMERRUNNING = true;
1048510632 }
1048610633 }
1048710634 }
....@@ -10549,7 +10696,8 @@
1054910696 ambientOcclusion = false;
1055010697 }
1055110698
10552
- if (Globals.lighttouched && DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
10699
+ if (//Globals.lighttouched &&
10700
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1055310701 {
1055410702 //if (RENDERSHADOW) // ?
1055510703 if (!IsFrozen())
....@@ -10989,9 +11137,9 @@
1098911137
1099011138 gl.glMatrixMode(GL.GL_MODELVIEW);
1099111139
10992
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10993
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10994
-//gl.glEnable(gl.GL_MULTISAMPLE);
11140
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11141
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11142
+gl.glEnable(gl.GL_MULTISAMPLE);
1099511143 } else
1099611144 {
1099711145 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -11002,7 +11150,7 @@
1100211150 //System.out.println("BLENDING ON");
1100311151 gl.glEnable(GL.GL_BLEND);
1100411152 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
11005
-
11153
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1100611154 gl.glMatrixMode(gl.GL_PROJECTION);
1100711155 gl.glLoadIdentity();
1100811156
....@@ -11459,15 +11607,36 @@
1145911607
1146011608 static boolean zoomonce = false;
1146111609
11610
+ static void CreateSelectedPoint()
11611
+ {
11612
+ if (selectedpoint == null)
11613
+ {
11614
+ debugpointG = new Sphere();
11615
+ debugpointP = new Sphere();
11616
+ debugpointC = new Sphere();
11617
+ debugpointR = new Sphere();
11618
+
11619
+ selectedpoint = new Superellipsoid();
11620
+
11621
+ for (int i=0; i<8; i++)
11622
+ {
11623
+ debugpoints[i] = new Sphere();
11624
+ }
11625
+ }
11626
+ }
11627
+
1146211628 void DrawObject(GL gl, boolean draw)
1146311629 {
11630
+ // To clear camera values
11631
+ ResetOptions();
11632
+
1146411633 //System.out.println("DRAW OBJECT " + mouseDown);
1146511634 // DrawMode() = SELECTION;
1146611635 //GL gl = getGL();
1146711636 if ((TRACK || SHADOWTRACK) || zoomonce)
1146811637 {
1146911638 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11470
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11639
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1147111640 pingthread.StepToTarget(true); // true);
1147211641 // zoomonce = false;
1147311642 }
....@@ -11539,8 +11708,9 @@
1153911708
1154011709 if (DrawMode() == DEFAULT)
1154111710 {
11542
- if (DEBUG)
11711
+ if (Globals.DEBUG)
1154311712 {
11713
+ CreateSelectedPoint();
1154411714 float radius = 0.05f;
1154511715 if (selectedpoint.radius != radius)
1154611716 {
....@@ -11594,20 +11764,32 @@
1159411764 ReleaseTextures(DEFAULT_TEXTURES);
1159511765
1159611766 if (CLEANCACHE)
11597
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11767
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1159811768 {
11599
- String tex = e.nextElement();
11769
+ cTexture tex = e.nextElement();
1160011770
1160111771 // System.out.println("Texture --------- " + tex);
1160211772
11603
- if (tex.equals("WHITE_NOISE"))
11773
+ if (tex.equals("WHITE_NOISE:"))
1160411774 continue;
1160511775
11606
- if (!usedtextures.containsKey(tex))
11776
+ if (!usedtextures.contains(tex))
1160711777 {
11778
+ CacheTexture gettex = texturepigment.get(tex);
1160811779 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11609
- textures.get(tex).texture.dispose();
11610
- textures.remove(tex);
11780
+ if (gettex != null)
11781
+ {
11782
+ gettex.texture.dispose();
11783
+ texturepigment.remove(tex);
11784
+ }
11785
+
11786
+ gettex = texturebump.get(tex);
11787
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11788
+ if (gettex != null)
11789
+ {
11790
+ gettex.texture.dispose();
11791
+ texturebump.remove(tex);
11792
+ }
1161111793 }
1161211794 }
1161311795 }
....@@ -12027,7 +12209,7 @@
1202712209 for (int i = tp.size(); --i >= 0;)
1202812210 {
1202912211 //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12030
- LA.xformPos(light, tp.get(i).GlobalTransform(), light);
12212
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1203112213 }
1203212214
1203312215
....@@ -13297,7 +13479,8 @@
1329713479 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1329813480 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1329913481 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13300
- Object3D.cVector2[] vector2buffer;
13482
+
13483
+ //Object3D.cVector2[] vector2buffer;
1330113484
1330213485 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1330313486 // OUT : diff, spec
....@@ -13313,9 +13496,10 @@
1331313496 "DP3 " + dest + ".z," + "normals," + "eye;" +
1331413497 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1331513498 //"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;" +
13499
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13500
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13501
+
13502
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1331913503 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1332013504 "RCP " + dest + ".w," + dest + ".w;" +
1332113505 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13820,6 +14004,7 @@
1382014004 else
1382114005 if (evt.getSource() == AAtimer)
1382214006 {
14007
+ Globals.TIMERRUNNING = false;
1382314008 if (mouseDown)
1382414009 {
1382514010 //new Exception().printStackTrace();
....@@ -13879,7 +14064,7 @@
1387914064
1388014065 // fev 2014???
1388114066 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13882
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14067
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1388314068 pingthread.StepToTarget(true); // true);
1388414069 }
1388514070 // if (!LIVE)
....@@ -13894,6 +14079,7 @@
1389414079 return;
1389514080
1389614081 AAtimer.restart(); //
14082
+ Globals.TIMERRUNNING = true;
1389714083
1389814084 // waslive = LIVE;
1389914085 // LIVE = false;
....@@ -14232,12 +14418,12 @@
1423214418 void GoDown(int mod)
1423314419 {
1423414420 MODIFIERS |= COMMAND;
14235
- /*
14421
+ /**/
1423614422 if((mod&SHIFT) == SHIFT)
1423714423 manipCamera.RotatePosition(0, -speed);
1423814424 else
14239
- manipCamera.BackForth(0, -speed*delta, getWidth());
14240
- */
14425
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14426
+ /**/
1424114427 if ((mod & SHIFT) == SHIFT)
1424214428 {
1424314429 mouseMode = mouseMode; // VR??
....@@ -14253,12 +14439,12 @@
1425314439 void GoUp(int mod)
1425414440 {
1425514441 MODIFIERS |= COMMAND;
14256
- /*
14442
+ /**/
1425714443 if((mod&SHIFT) == SHIFT)
1425814444 manipCamera.RotatePosition(0, speed);
1425914445 else
14260
- manipCamera.BackForth(0, speed*delta, getWidth());
14261
- */
14446
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14447
+ /**/
1426214448 if ((mod & SHIFT) == SHIFT)
1426314449 {
1426414450 mouseMode = mouseMode;
....@@ -14274,12 +14460,12 @@
1427414460 void GoLeft(int mod)
1427514461 {
1427614462 MODIFIERS |= COMMAND;
14277
- /*
14463
+ /**/
1427814464 if((mod&SHIFT) == SHIFT)
14279
- manipCamera.RotatePosition(speed, 0);
14280
- else
1428114465 manipCamera.Translate(speed*delta, 0, getWidth());
14282
- */
14466
+ else
14467
+ manipCamera.RotatePosition(speed, 0);
14468
+ /**/
1428314469 if ((mod & SHIFT) == SHIFT)
1428414470 {
1428514471 mouseMode = mouseMode;
....@@ -14295,12 +14481,12 @@
1429514481 void GoRight(int mod)
1429614482 {
1429714483 MODIFIERS |= COMMAND;
14298
- /*
14484
+ /**/
1429914485 if((mod&SHIFT) == SHIFT)
14300
- manipCamera.RotatePosition(-speed, 0);
14301
- else
1430214486 manipCamera.Translate(-speed*delta, 0, getWidth());
14303
- */
14487
+ else
14488
+ manipCamera.RotatePosition(-speed, 0);
14489
+ /**/
1430414490 if ((mod & SHIFT) == SHIFT)
1430514491 {
1430614492 mouseMode = mouseMode;
....@@ -14357,7 +14543,8 @@
1435714543 info.camera = renderCamera;
1435814544 info.x = x;
1435914545 info.y = y;
14360
- object.editWindow.copy.doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
14546
+ object.GetWindow().copy
14547
+ .doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1436114548 } else
1436214549 {
1436314550 if (x < startX)
....@@ -14521,7 +14708,9 @@
1452114708 ci.camera = renderCamera;
1452214709 if (!isRenderer)
1452314710 {
14524
- if (object.editWindow.copy.doEditClick(ci, 0))
14711
+ //ObjEditor editWindow = object.editWindow;
14712
+ //Object3D copy = editWindow.copy;
14713
+ if (object.doEditClick(ci, 0))
1452514714 {
1452614715 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1452714716 } else
....@@ -14536,7 +14725,8 @@
1453614725 Globals.MOUSEDRAGGED = false;
1453714726
1453814727 movingcamera = false;
14539
- X = Y = 0;
14728
+ X = 0; // getBounds().width/2;
14729
+ Y = 0; // getBounds().height/2;
1454014730 //System.out.println("mouseReleased: " + e);
1454114731 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1454214732 }
....@@ -14792,7 +14982,8 @@
1479214982 // break;
1479314983 case 'T':
1479414984 CACHETEXTURE ^= true;
14795
- textures.clear();
14985
+ texturepigment.clear();
14986
+ texturebump.clear();
1479614987 // repaint();
1479714988 break;
1479814989 case 'Y':
....@@ -14877,7 +15068,9 @@
1487715068 case 'E' : COMPACT ^= true;
1487815069 repaint();
1487915070 break;
14880
- case 'W' : DEBUGHSB ^= true;
15071
+ case 'W' : // Wide Window (fullscreen)
15072
+ //DEBUGHSB ^= true;
15073
+ ObjEditor.theFrame.ToggleFullScreen();
1488115074 repaint();
1488215075 break;
1488315076 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14902,8 +15095,8 @@
1490215095 RevertCamera();
1490315096 repaint();
1490415097 break;
14905
- case 'L':
1490615098 case 'l':
15099
+ //case 'L':
1490715100 if (lightMode)
1490815101 {
1490915102 lightMode = false;
....@@ -15046,9 +15239,9 @@
1504615239 case '_':
1504715240 kompactbit = 5;
1504815241 break;
15049
- case '+':
15050
- kompactbit = 6;
15051
- break;
15242
+// case '+':
15243
+// kompactbit = 6;
15244
+// break;
1505215245 case ' ':
1505315246 lightMode ^= true;
1505415247 Globals.lighttouched = true;
....@@ -15060,6 +15253,7 @@
1506015253 case ESC:
1506115254 RENDERPROGRAM += 1;
1506215255 RENDERPROGRAM %= 3;
15256
+
1506315257 repaint();
1506415258 break;
1506515259 case 'Z':
....@@ -15099,8 +15293,9 @@
1509915293 case DELETE:
1510015294 ClearSelection();
1510115295 break;
15102
- /*
1510315296 case '+':
15297
+
15298
+ /*
1510415299 //fontsize += 1;
1510515300 bbzoom *= 2;
1510615301 repaint();
....@@ -15117,17 +15312,17 @@
1511715312 case '=':
1511815313 IncDepth();
1511915314 //fontsize += 1;
15120
- object.editWindow.refreshContents(true);
15315
+ object.GetWindow().refreshContents(true);
1512115316 maskbit = 6;
1512215317 break;
1512315318 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1512415319 DecDepth();
1512515320 maskbit = 5;
1512615321 //if(fontsize > 1) fontsize -= 1;
15127
- if (object.editWindow == null)
15128
- new Exception().printStackTrace();
15129
- else
15130
- object.editWindow.refreshContents(true);
15322
+// if (object.editWindow == null)
15323
+// new Exception().printStackTrace();
15324
+// else
15325
+ object.GetWindow().refreshContents(true);
1513115326 break;
1513215327 case '{':
1513315328 manipCamera.shaper_fovy /= 1.1;
....@@ -15351,7 +15546,7 @@
1535115546 }
1535215547 */
1535315548
15354
- object.editWindow.EditSelection();
15549
+ object.GetWindow().EditSelection(false);
1535515550 }
1535615551
1535715552 void SelectParent()
....@@ -15368,10 +15563,10 @@
1536815563 {
1536915564 //selectees.remove(i);
1537015565 System.out.println("select parent of " + elem);
15371
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15566
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1537215567 } else
1537315568 {
15374
- group.editWindow.Select(elem.GetTreePath(), first, true);
15569
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1537515570 }
1537615571
1537715572 first = false;
....@@ -15413,12 +15608,12 @@
1541315608 for (int j = 0; j < group.children.size(); j++)
1541415609 {
1541515610 elem = (Object3D) group.children.elementAt(j);
15416
- object.editWindow.Select(elem.GetTreePath(), first, true);
15611
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1541715612 first = false;
1541815613 }
1541915614 } else
1542015615 {
15421
- object.editWindow.Select(elem.GetTreePath(), first, true);
15616
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1542215617 }
1542315618
1542415619 first = false;
....@@ -15429,21 +15624,21 @@
1542915624 {
1543015625 //Composite group = (Composite) object;
1543115626 Object3D group = object;
15432
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15627
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1543315628 }
1543415629
1543515630 void ResetTransform(int mask)
1543615631 {
1543715632 //Composite group = (Composite) object;
1543815633 Object3D group = object;
15439
- group.editWindow.ResetTransform(mask);
15634
+ group.GetWindow().ResetTransform(mask);
1544015635 }
1544115636
1544215637 void FlipTransform()
1544315638 {
1544415639 //Composite group = (Composite) object;
1544515640 Object3D group = object;
15446
- group.editWindow.FlipTransform();
15641
+ group.GetWindow().FlipTransform();
1544715642 // group.editWindow.ReduceMesh(true);
1544815643 }
1544915644
....@@ -15451,7 +15646,7 @@
1545115646 {
1545215647 //Composite group = (Composite) object;
1545315648 Object3D group = object;
15454
- group.editWindow.PrintMemory();
15649
+ group.GetWindow().PrintMemory();
1545515650 // group.editWindow.ReduceMesh(true);
1545615651 }
1545715652
....@@ -15459,7 +15654,7 @@
1545915654 {
1546015655 //Composite group = (Composite) object;
1546115656 Object3D group = object;
15462
- group.editWindow.ResetCentroid();
15657
+ group.GetWindow().ResetCentroid();
1546315658 }
1546415659
1546515660 void IncDepth()
....@@ -15635,6 +15830,7 @@
1563515830 info.bounds.y += (height - desired) / 2;
1563615831 }
1563715832 }
15833
+
1563815834 info.g = gr;
1563915835 info.camera = renderCamera;
1564015836 /*
....@@ -15644,23 +15840,44 @@
1564415840 */
1564515841 if (!isRenderer)
1564615842 {
15647
- object.drawEditHandles(info, 0);
15648
-
15649
- if (drag && (X != 0 || Y != 0) && object.selection.Size() > 0)
15843
+ Grafreed.Assert(object != null);
15844
+ Grafreed.Assert(object.selection != null);
15845
+ if (object.selection.Size() > 0)
1565015846 {
15651
- switch (object.selection.get(0).hitSomething)
15847
+ int hitSomething = object.selection.get(0).hitSomething;
15848
+
15849
+ info.DX = 0;
15850
+ info.DY = 0;
15851
+ info.W = 1;
15852
+ if (hitSomething == Object3D.hitCenter)
1565215853 {
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;
15854
+ info.DX = X;
15855
+ if (X != 0)
15856
+ info.DX -= info.bounds.width/2;
15857
+
15858
+ info.DY = Y;
15859
+ if (Y != 0)
15860
+ info.DY -= info.bounds.height/2;
1566215861 }
15663
-
15862
+
15863
+ object.drawEditHandles(info, 0);
15864
+
15865
+ if (drag && (X != 0 || Y != 0))
15866
+ {
15867
+ switch (hitSomething)
15868
+ {
15869
+ case Object3D.hitCenter: gr.setColor(Color.pink);
15870
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15871
+ break;
15872
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
15873
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15874
+ break;
15875
+ case Object3D.hitScale: gr.setColor(Color.cyan);
15876
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15877
+ break;
15878
+ }
15879
+
15880
+ }
1566415881 }
1566515882 }
1566615883 }
....@@ -16363,16 +16580,16 @@
1636316580 cStatic.objectstack[materialdepth++] = checker;
1636416581 //System.out.println("material " + material);
1636516582 //Applet3D.tracein(this, selected);
16366
- vector2buffer = checker.projectedVertices;
16583
+ //vector2buffer = checker.projectedVertices;
1636716584
1636816585 //checker.GetMaterial().Draw(this, false); // true);
16369
- DrawMaterial(checker.GetMaterial(), false); // true);
16586
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1637016587
1637116588 materialdepth -= 1;
1637216589 if (materialdepth > 0)
1637316590 {
16374
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16375
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
16591
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16592
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1637616593 }
1637716594 //checker.GetMaterial().opacity = 1f;
1637816595 ////checker.GetMaterial().ambient = 1f;
....@@ -16458,6 +16675,14 @@
1645816675 }
1645916676 }
1646016677
16678
+ private Object3D GetFolder()
16679
+ {
16680
+ Object3D folder = object.GetWindow().copy;
16681
+ if (object.GetWindow().copy.selection.Size() > 0)
16682
+ folder = object.GetWindow().copy.selection.elementAt(0);
16683
+ return folder;
16684
+ }
16685
+
1646116686 class SelectBuffer implements GLEventListener
1646216687 {
1646316688
....@@ -16537,6 +16762,17 @@
1653716762
1653816763 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1653916764
16765
+ if (PAINTMODE)
16766
+ {
16767
+ if (object.GetWindow().copy.selection.Size() > 0)
16768
+ {
16769
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16770
+
16771
+ // Make what you paint not selectable.
16772
+ paintobj.ResetSelectable();
16773
+ }
16774
+ }
16775
+
1654016776 //int tmp = selection_view;
1654116777 //selection_view = -1;
1654216778 int temp = DrawMode();
....@@ -16548,6 +16784,17 @@
1654816784 // temp = DEFAULT; // patch for selection debug
1654916785 Globals.drawMode = temp; // WARNING
1655016786
16787
+ if (PAINTMODE)
16788
+ {
16789
+ if (object.GetWindow().copy.selection.Size() > 0)
16790
+ {
16791
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16792
+
16793
+ // Revert.
16794
+ paintobj.RestoreSelectable();
16795
+ }
16796
+ }
16797
+
1655116798 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1655216799
1655316800 // trying different ways of getting the depth info over
....@@ -16595,6 +16842,8 @@
1659516842 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1659616843 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1659716844 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
16845
+
16846
+ CreateSelectedPoint();
1659816847
1659916848 // Will fit the mesh !!!
1660016849 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16649,29 +16898,31 @@
1664916898 }
1665016899
1665116900 if (!movingcamera && !PAINTMODE)
16652
- object.editWindow.ScreenFitPoint(); // fev 2014
16901
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1665316902
16654
- if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
16903
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1665516904 {
16656
- Object3D paintobj = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
16905
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1665716906
16658
- Object3D group = new Object3D("inst" + paintcount++);
16907
+ if (object.GetWindow().copy.selection.Size() > 0)
16908
+ {
16909
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1665916910
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();
16911
+ Object3D inst = new Object3D("inst" + paintcount++);
16912
+
16913
+ inst.CreateMaterial(); // use a void leaf to select instances
16914
+
16915
+ inst.add(paintobj); // link
16916
+
16917
+ object.GetWindow().SnapObject(inst);
16918
+
16919
+ Object3D folder = paintFolder; // GetFolder();
16920
+
16921
+ folder.add(inst);
16922
+
16923
+ object.GetWindow().ResetModel();
16924
+ object.GetWindow().refreshContents();
16925
+ }
1667516926 }
1667616927 else
1667716928 paintcount = 0;
....@@ -16710,6 +16961,11 @@
1671016961 //System.out.println("objects[color] = " + objects[color]);
1671116962 //objects[color].Select();
1671216963 indexcount = 0;
16964
+ ObjEditor window = object.GetWindow();
16965
+ if (window != null && deselect)
16966
+ {
16967
+ window.Select(null, deselect, true);
16968
+ }
1671316969 object.Select(color, deselect);
1671416970 }
1671516971
....@@ -17235,23 +17491,15 @@
1723517491 int AAbuffersize = 0;
1723617492
1723717493 //double[] selectedpoint = new double[3];
17238
- static Superellipsoid selectedpoint = new Superellipsoid();
17494
+ static Superellipsoid selectedpoint;
1723917495 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();
17496
+ static Sphere debugpointG;
17497
+ static Sphere debugpointP;
17498
+ static Sphere debugpointC;
17499
+ static Sphere debugpointR;
1724417500
1724517501 static Sphere debugpoints[] = new Sphere[8];
1724617502
17247
- static
17248
- {
17249
- for (int i=0; i<8; i++)
17250
- {
17251
- debugpoints[i] = new Sphere();
17252
- }
17253
- }
17254
-
1725517503 static void InitPoints(float radius)
1725617504 {
1725717505 for (int i=0; i<8; i++)