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
....@@ -464,10 +510,12 @@
464510 if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
465511 {
466512 //gl.glBegin(gl.GL_TRIANGLES);
467
- boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0);
513
+ boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0)
514
+ // TEST LIVE NORMALS && !obj.dontselect
515
+ ;
468516 if (!hasnorm)
469517 {
470
- // System.out.println("FUCK!!");
518
+ // System.out.println("Mesh normal");
471519 LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
472520 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
473521 LA.vecCross(obj.v0, obj.v1, obj.v2);
....@@ -1192,10 +1240,12 @@
11921240 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
11931241 }
11941242 }
1243
+
11951244 if (flipV)
11961245 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
11971246 else
11981247 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1248
+
11991249 //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
12001250 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
12011251
....@@ -1215,10 +1265,12 @@
12151265 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
12161266 }
12171267 }
1268
+
12181269 if (flipV)
12191270 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12201271 else
12211272 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1273
+
12221274 //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
12231275 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
12241276
....@@ -1246,8 +1298,10 @@
12461298 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12471299 else
12481300 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1301
+
12491302 //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
12501303 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1304
+
12511305 count2 += 2;
12521306 count3 += 3;
12531307 }
....@@ -1603,7 +1657,7 @@
16031657 // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
16041658 }
16051659
1606
- void DrawMaterial(cMaterial material, boolean selected)
1660
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
16071661 {
16081662 CameraPane display = this;
16091663 //new Exception().printStackTrace();
....@@ -1638,7 +1692,7 @@
16381692 colorV[0] = display.modelParams0[0] * material.diffuse;
16391693 colorV[1] = display.modelParams0[1] * material.diffuse;
16401694 colorV[2] = display.modelParams0[2] * material.diffuse;
1641
- colorV[3] = material.opacity;
1695
+ colorV[3] = 1; // material.opacity;
16421696
16431697 gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
16441698 //System.out.println("Opacity = " + opacity);
....@@ -1746,9 +1800,9 @@
17461800 display.modelParams7[2] = 0;
17471801 display.modelParams7[3] = 0;
17481802
1749
- display.modelParams6[0] = 100; // criss de bug de bump
1803
+ //display.modelParams6[0] = 100; // criss de bug de bump
17501804
1751
- Object3D.cVector2[] extparams = display.vector2buffer;
1805
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
17521806 if (extparams != null && extparams.length > 0 && extparams[0] != null)
17531807 {
17541808 display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
....@@ -2044,7 +2098,7 @@
20442098 //System.err.println("Oeil on");
20452099 OEIL = true;
20462100 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2047
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2101
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
20482102 //pingthread.StepToTarget(true);
20492103 }
20502104
....@@ -2259,7 +2313,7 @@
22592313
22602314 void ToggleDebug()
22612315 {
2262
- DEBUG ^= true;
2316
+ Globals.DEBUG ^= true;
22632317 }
22642318
22652319 void ToggleLookAt()
....@@ -2277,10 +2331,17 @@
22772331 HANDLES ^= true;
22782332 }
22792333
2334
+ Object3D paintFolder;
2335
+
22802336 void TogglePaint()
22812337 {
22822338 PAINTMODE ^= true;
22832339 paintcount = 0;
2340
+
2341
+ if (PAINTMODE)
2342
+ {
2343
+ paintFolder = GetFolder();
2344
+ }
22842345 }
22852346
22862347 void SwapCamera(int a, int b)
....@@ -2377,6 +2438,21 @@
23772438 return currentGL;
23782439 }
23792440
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
+
23802456 /**/
23812457 class CacheTexture
23822458 {
....@@ -2385,28 +2461,31 @@
23852461
23862462 int resolution;
23872463
2388
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2464
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
23892465 {
2390
- texture = tex;
2466
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2467
+ texturedata = texdata;
23912468 resolution = res;
23922469 }
23932470 }
23942471 /**/
23952472
23962473 // TEXTURE static Texture texture;
2397
- static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures
2398
- = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>();
2399
- 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
+
24002479 int pigmentdepth = 0;
24012480 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
24022481 int bumpdepth = 0;
24032482 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
24042483 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
24052484 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2406
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2485
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
24072486 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
24082487
2409
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2488
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
24102489 {
24112490 TextureData texturedata = null;
24122491
....@@ -2425,13 +2504,34 @@
24252504 if (bump)
24262505 texturedata = ConvertBump(texturedata, false);
24272506
2428
- com.sun.opengl.util.texture.Texture texture =
2429
- 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);
24302509
2431
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2432
- 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);
24332512
2434
- 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;
24352535 }
24362536
24372537 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3504,6 +3604,8 @@
35043604
35053605 System.out.println("LOADING TEXTURE : " + name);
35063606
3607
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3608
+
35073609 //
35083610 if (false) // compressbit > 0)
35093611 {
....@@ -7902,7 +8004,7 @@
79028004 String pigment = Object3D.GetPigment(tex);
79038005 String bump = Object3D.GetBump(tex);
79048006
7905
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8007
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79068008 {
79078009 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79088010 // System.out.println("; bump = " + bump);
....@@ -7917,8 +8019,8 @@
79178019 pigment = null;
79188020 }
79198021
7920
- ReleaseTexture(bump, true);
7921
- ReleaseTexture(pigment, false);
8022
+ ReleaseTexture(tex, true);
8023
+ ReleaseTexture(tex, false);
79228024 }
79238025
79248026 public void ReleasePigmentTexture(cTexture tex) // INTERFACE
....@@ -7936,7 +8038,7 @@
79368038
79378039 String pigment = Object3D.GetPigment(tex);
79388040
7939
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8041
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79408042 {
79418043 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79428044 // System.out.println("; bump = " + bump);
....@@ -7947,7 +8049,7 @@
79478049 pigment = null;
79488050 }
79498051
7950
- ReleaseTexture(pigment, false);
8052
+ ReleaseTexture(tex, false);
79518053 }
79528054
79538055 public void ReleaseBumpTexture(cTexture tex) // INTERFACE
....@@ -7965,7 +8067,7 @@
79658067
79668068 String bump = Object3D.GetBump(tex);
79678069
7968
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8070
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79698071 {
79708072 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79718073 // System.out.println("; bump = " + bump);
....@@ -7976,10 +8078,10 @@
79768078 bump = null;
79778079 }
79788080
7979
- ReleaseTexture(bump, true);
8081
+ ReleaseTexture(tex, true);
79808082 }
79818083
7982
- void ReleaseTexture(String tex, boolean bump)
8084
+ void ReleaseTexture(cTexture tex, boolean bump)
79838085 {
79848086 if (// DrawMode() != 0 || /*tex == null ||*/
79858087 ambientOcclusion ) // || !textureon)
....@@ -7990,7 +8092,7 @@
79908092 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
79918093
79928094 if (tex != null)
7993
- texture = textures.get(tex);
8095
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
79948096
79958097 // //assert( texture != null );
79968098 // if (texture == null)
....@@ -8084,47 +8186,50 @@
80848186
80858187 /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
80868188 {
8087
- if (// DrawMode() != 0 || /*tex == null ||*/
8088
- ambientOcclusion ) // || !textureon)
8089
- {
8090
- return; // false;
8091
- }
8092
-
8093
- if (tex == null)
8094
- {
8095
- BindTexture(null,false,resolution);
8096
- BindTexture(null,true,resolution);
8097
- return;
8098
- }
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;
80998230
8100
- String pigment = Object3D.GetPigment(tex);
8101
- String bump = Object3D.GetBump(tex);
8102
-
8103
- usedtextures.put(pigment, pigment);
8104
- usedtextures.put(bump, bump);
8105
-
8106
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8107
- {
8108
- // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8109
- // System.out.println("; bump = " + bump);
8110
- }
8111
-
8112
- if (bump.equals(""))
8113
- {
8114
- bump = null;
8115
- }
8116
- if (pigment.equals(""))
8117
- {
8118
- pigment = null;
8119
- }
8120
-
8121
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8122
- BindTexture(pigment, false, resolution);
8123
- GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8124
- BindTexture(bump, true, resolution);
8125
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8126
-
8127
- return; // true;
8231
+ BindPigmentTexture(tex, resolution);
8232
+ BindBumpTexture(tex, resolution);
81288233 }
81298234
81308235 /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8143,9 +8248,9 @@
81438248
81448249 String pigment = Object3D.GetPigment(tex);
81458250
8146
- usedtextures.put(pigment, pigment);
8251
+ usedtextures.add(tex);
81478252
8148
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8253
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
81498254 {
81508255 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
81518256 // System.out.println("; bump = " + bump);
....@@ -8157,7 +8262,7 @@
81578262 }
81588263
81598264 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8160
- BindTexture(pigment, false, resolution);
8265
+ BindTexture(tex, false, resolution);
81618266 }
81628267
81638268 /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8176,9 +8281,9 @@
81768281
81778282 String bump = Object3D.GetBump(tex);
81788283
8179
- usedtextures.put(bump, bump);
8284
+ usedtextures.add(tex);
81808285
8181
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8286
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
81828287 {
81838288 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
81848289 // System.out.println("; bump = " + bump);
....@@ -8190,7 +8295,7 @@
81908295 }
81918296
81928297 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8193
- BindTexture(bump, true, resolution);
8298
+ BindTexture(tex, true, resolution);
81948299 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
81958300 }
81968301
....@@ -8214,13 +8319,19 @@
82148319 return fileExists;
82158320 }
82168321
8217
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception
8322
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
82188323 {
8219
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8324
+ CacheTexture texturecache = null;
82208325
82218326 if (tex != null)
82228327 {
8223
- 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
+ }
82248335
82258336 String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
82268337
....@@ -8230,19 +8341,34 @@
82308341 // else
82318342 // if (!texname.startsWith("/"))
82328343 // texname = "/Users/nbriere/Textures/" + texname;
8233
- if (!FileExists(tex))
8344
+ if (!FileExists(texname))
82348345 {
82358346 texname = fallbackTextureName;
82368347 }
82378348
82388349 if (CACHETEXTURE)
8239
- texture = textures.get(texname); // TEXTURE CACHE
8240
-
8241
- TextureData texturedata = null;
8242
-
8243
- if (texture == null || texture.resolution < resolution)
82448350 {
8245
- 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(""))
82468372 {
82478373 assert(!bump);
82488374 // if (bump)
....@@ -8253,19 +8379,23 @@
82538379 // }
82548380 // else
82558381 // {
8256
- texture = textures.get(tex);
8257
- if (texture == null)
8382
+ // texturecache = textures.get(texname); // suspicious
8383
+ if (texturecache == null)
82588384 {
8259
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8385
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
82608386 }
8387
+ else
8388
+ new Exception().printStackTrace();
82618389 // }
82628390 } else
8263
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8391
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
82648392 {
82658393 assert(bump);
8266
- texture = textures.get(tex);
8267
- if (texture == null)
8268
- 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();
82698399 } else
82708400 {
82718401 //if (tex.equals("IMMORTAL"))
....@@ -8273,11 +8403,13 @@
82738403 // texture = GetResourceTexture("default.png");
82748404 //} else
82758405 //{
8276
- if (tex.equals("WHITE_NOISE"))
8406
+ if (texname.endsWith("WHITE_NOISE"))
82778407 {
8278
- texture = textures.get(tex);
8279
- if (texture == null)
8280
- 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();
82818413 } else
82828414 {
82838415 if (textureon)
....@@ -8336,19 +8468,19 @@
83368468 if (texturedata == null)
83378469 throw new Exception();
83388470
8339
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8471
+ texturecache = new CacheTexture(texturedata,resolution);
83408472 //texture = GetTexture(tex, bump);
83418473 }
83428474 }
83438475 //}
83448476 }
83458477
8346
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8478
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
83478479 {
83488480 //return false;
83498481
83508482 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8351
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8483
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
83528484 {
83538485 // String ext = "_highres";
83548486 // if (REDUCETEXTURE)
....@@ -8365,52 +8497,17 @@
83658497 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
83668498 if (!cachefile.exists())
83678499 {
8368
- // cache to disk
8369
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
8370
- //buffers[0].
8371
-
8372
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
8373
- int[] pixels = new int[bytebuf.capacity()/3];
8374
-
8375
- // squared size heuristic...
8376
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8500
+ //if (texturedata.getWidth() == texturedata.getHeight())
83778501 {
8378
- for (int i=pixels.length; --i>=0;)
8379
- {
8380
- int i3 = i*3;
8381
- pixels[i] = 0xFF;
8382
- pixels[i] <<= 8;
8383
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
8384
- pixels[i] <<= 8;
8385
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
8386
- pixels[i] <<= 8;
8387
- pixels[i] |= bytebuf.get(i3) & 0xFF;
8388
- }
8389
-
8390
- /*
8391
- int r=0,g=0,b=0,a=0;
8392
- for (int i=0; i<width; i++)
8393
- for (int j=0; j<height; j++)
8394
- {
8395
- int index = j*width+i;
8396
- int p = pixels[index];
8397
- a = ((p>>24) & 0xFF);
8398
- r = ((p>>16) & 0xFF);
8399
- g = ((p>>8) & 0xFF);
8400
- b = (p & 0xFF);
8401
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
8402
- }
8403
- /**/
8404
- int width = (int)Math.sqrt(pixels.length); // squared
8405
- int height = width;
8406
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
8407
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8502
+ BufferedImage rendImage = CreateBim(texturedata);
8503
+
84088504 ImageWriter writer = null;
84098505 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
84108506 if (iter.hasNext()) {
84118507 writer = (ImageWriter)iter.next();
84128508 }
8413
- float compressionQuality = 0.9f;
8509
+
8510
+ float compressionQuality = 0.85f;
84148511 try
84158512 {
84168513 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8427,18 +8524,20 @@
84278524 }
84288525 }
84298526 }
8430
-
8527
+
8528
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8529
+
84318530 //System.out.println("Texture = " + tex);
8432
- if (textures.containsKey(texname))
8531
+ if (textures.containsKey(tex))
84338532 {
8434
- CacheTexture thetex = textures.get(texname);
8533
+ CacheTexture thetex = textures.get(tex);
84358534 thetex.texture.disable();
84368535 thetex.texture.dispose();
8437
- textures.remove(texname);
8536
+ textures.remove(tex);
84388537 }
84398538
8440
- texture.texturedata = texturedata;
8441
- textures.put(texname, texture);
8539
+ //texture.texturedata = texturedata;
8540
+ textures.put(tex, texturecache);
84428541
84438542 // newtex = true;
84448543 }
....@@ -8454,10 +8553,41 @@
84548553 }
84558554 }
84568555
8457
- return texture;
8556
+ return texturecache;
84588557 }
84598558
8460
- 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
84618591 {
84628592 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
84638593
....@@ -8475,21 +8605,21 @@
84758605 return texture!=null?texture.texture:null;
84768606 }
84778607
8478
- 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
84798609 {
84808610 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
84818611
84828612 return texture!=null?texture.texturedata:null;
84838613 }
84848614
8485
- boolean BindTexture(String tex, boolean bump, int resolution) throws Exception
8615
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
84868616 {
84878617 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
84888618 {
84898619 return false;
84908620 }
84918621
8492
- boolean newtex = false;
8622
+ //boolean newtex = false;
84938623
84948624 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
84958625
....@@ -8521,7 +8651,7 @@
85218651 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
85228652 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
85238653
8524
- return newtex;
8654
+ return true; // Warning: not used.
85258655 }
85268656
85278657 ShadowBuffer shadowPBuf;
....@@ -9359,11 +9489,35 @@
93599489 jy8[3] = 0.5f;
93609490 }
93619491
9362
- 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
93639493 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
93649494 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
93659495 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
93669496
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
+
93679521 static int imagecount = 0; // movie generation
93689522
93699523 static int jitter = 0;
....@@ -10474,6 +10628,7 @@
1047410628 ANTIALIAS = 0;
1047510629 //System.out.println("RESTART");
1047610630 AAtimer.restart();
10631
+ Globals.TIMERRUNNING = true;
1047710632 }
1047810633 }
1047910634 }
....@@ -10541,7 +10696,8 @@
1054110696 ambientOcclusion = false;
1054210697 }
1054310698
10544
- if (Globals.lighttouched && DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
10699
+ if (//Globals.lighttouched &&
10700
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1054510701 {
1054610702 //if (RENDERSHADOW) // ?
1054710703 if (!IsFrozen())
....@@ -10981,9 +11137,9 @@
1098111137
1098211138 gl.glMatrixMode(GL.GL_MODELVIEW);
1098311139
10984
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10985
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10986
-//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);
1098711143 } else
1098811144 {
1098911145 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -10994,7 +11150,7 @@
1099411150 //System.out.println("BLENDING ON");
1099511151 gl.glEnable(GL.GL_BLEND);
1099611152 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
10997
-
11153
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1099811154 gl.glMatrixMode(gl.GL_PROJECTION);
1099911155 gl.glLoadIdentity();
1100011156
....@@ -11451,15 +11607,36 @@
1145111607
1145211608 static boolean zoomonce = false;
1145311609
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
+
1145411628 void DrawObject(GL gl, boolean draw)
1145511629 {
11630
+ // To clear camera values
11631
+ ResetOptions();
11632
+
1145611633 //System.out.println("DRAW OBJECT " + mouseDown);
1145711634 // DrawMode() = SELECTION;
1145811635 //GL gl = getGL();
1145911636 if ((TRACK || SHADOWTRACK) || zoomonce)
1146011637 {
1146111638 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11462
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11639
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1146311640 pingthread.StepToTarget(true); // true);
1146411641 // zoomonce = false;
1146511642 }
....@@ -11531,8 +11708,9 @@
1153111708
1153211709 if (DrawMode() == DEFAULT)
1153311710 {
11534
- if (DEBUG)
11711
+ if (Globals.DEBUG)
1153511712 {
11713
+ CreateSelectedPoint();
1153611714 float radius = 0.05f;
1153711715 if (selectedpoint.radius != radius)
1153811716 {
....@@ -11586,20 +11764,32 @@
1158611764 ReleaseTextures(DEFAULT_TEXTURES);
1158711765
1158811766 if (CLEANCACHE)
11589
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11767
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1159011768 {
11591
- String tex = e.nextElement();
11769
+ cTexture tex = e.nextElement();
1159211770
1159311771 // System.out.println("Texture --------- " + tex);
1159411772
11595
- if (tex.equals("WHITE_NOISE"))
11773
+ if (tex.equals("WHITE_NOISE:"))
1159611774 continue;
1159711775
11598
- if (!usedtextures.containsKey(tex))
11776
+ if (!usedtextures.contains(tex))
1159911777 {
11778
+ CacheTexture gettex = texturepigment.get(tex);
1160011779 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11601
- textures.get(tex).texture.dispose();
11602
- 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
+ }
1160311793 }
1160411794 }
1160511795 }
....@@ -12019,7 +12209,7 @@
1201912209 for (int i = tp.size(); --i >= 0;)
1202012210 {
1202112211 //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12022
- LA.xformPos(light, tp.get(i).GlobalTransform(), light);
12212
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1202312213 }
1202412214
1202512215
....@@ -13289,7 +13479,8 @@
1328913479 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1329013480 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1329113481 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13292
- Object3D.cVector2[] vector2buffer;
13482
+
13483
+ //Object3D.cVector2[] vector2buffer;
1329313484
1329413485 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1329513486 // OUT : diff, spec
....@@ -13305,9 +13496,10 @@
1330513496 "DP3 " + dest + ".z," + "normals," + "eye;" +
1330613497 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1330713498 //"MOV " + dest + ".w," + "normal.z;" +
13308
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
13309
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13310
- //"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
1331113503 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1331213504 "RCP " + dest + ".w," + dest + ".w;" +
1331313505 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13812,6 +14004,7 @@
1381214004 else
1381314005 if (evt.getSource() == AAtimer)
1381414006 {
14007
+ Globals.TIMERRUNNING = false;
1381514008 if (mouseDown)
1381614009 {
1381714010 //new Exception().printStackTrace();
....@@ -13871,7 +14064,7 @@
1387114064
1387214065 // fev 2014???
1387314066 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13874
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14067
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1387514068 pingthread.StepToTarget(true); // true);
1387614069 }
1387714070 // if (!LIVE)
....@@ -13886,6 +14079,7 @@
1388614079 return;
1388714080
1388814081 AAtimer.restart(); //
14082
+ Globals.TIMERRUNNING = true;
1388914083
1389014084 // waslive = LIVE;
1389114085 // LIVE = false;
....@@ -14224,12 +14418,12 @@
1422414418 void GoDown(int mod)
1422514419 {
1422614420 MODIFIERS |= COMMAND;
14227
- /*
14421
+ /**/
1422814422 if((mod&SHIFT) == SHIFT)
1422914423 manipCamera.RotatePosition(0, -speed);
1423014424 else
14231
- manipCamera.BackForth(0, -speed*delta, getWidth());
14232
- */
14425
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14426
+ /**/
1423314427 if ((mod & SHIFT) == SHIFT)
1423414428 {
1423514429 mouseMode = mouseMode; // VR??
....@@ -14245,12 +14439,12 @@
1424514439 void GoUp(int mod)
1424614440 {
1424714441 MODIFIERS |= COMMAND;
14248
- /*
14442
+ /**/
1424914443 if((mod&SHIFT) == SHIFT)
1425014444 manipCamera.RotatePosition(0, speed);
1425114445 else
14252
- manipCamera.BackForth(0, speed*delta, getWidth());
14253
- */
14446
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14447
+ /**/
1425414448 if ((mod & SHIFT) == SHIFT)
1425514449 {
1425614450 mouseMode = mouseMode;
....@@ -14266,12 +14460,12 @@
1426614460 void GoLeft(int mod)
1426714461 {
1426814462 MODIFIERS |= COMMAND;
14269
- /*
14463
+ /**/
1427014464 if((mod&SHIFT) == SHIFT)
14271
- manipCamera.RotatePosition(speed, 0);
14272
- else
1427314465 manipCamera.Translate(speed*delta, 0, getWidth());
14274
- */
14466
+ else
14467
+ manipCamera.RotatePosition(speed, 0);
14468
+ /**/
1427514469 if ((mod & SHIFT) == SHIFT)
1427614470 {
1427714471 mouseMode = mouseMode;
....@@ -14287,12 +14481,12 @@
1428714481 void GoRight(int mod)
1428814482 {
1428914483 MODIFIERS |= COMMAND;
14290
- /*
14484
+ /**/
1429114485 if((mod&SHIFT) == SHIFT)
14292
- manipCamera.RotatePosition(-speed, 0);
14293
- else
1429414486 manipCamera.Translate(-speed*delta, 0, getWidth());
14295
- */
14487
+ else
14488
+ manipCamera.RotatePosition(-speed, 0);
14489
+ /**/
1429614490 if ((mod & SHIFT) == SHIFT)
1429714491 {
1429814492 mouseMode = mouseMode;
....@@ -14349,7 +14543,8 @@
1434914543 info.camera = renderCamera;
1435014544 info.x = x;
1435114545 info.y = y;
14352
- object.editWindow.copy.doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
14546
+ object.GetWindow().copy
14547
+ .doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1435314548 } else
1435414549 {
1435514550 if (x < startX)
....@@ -14513,7 +14708,9 @@
1451314708 ci.camera = renderCamera;
1451414709 if (!isRenderer)
1451514710 {
14516
- if (object.editWindow.copy.doEditClick(ci, 0))
14711
+ //ObjEditor editWindow = object.editWindow;
14712
+ //Object3D copy = editWindow.copy;
14713
+ if (object.doEditClick(ci, 0))
1451714714 {
1451814715 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1451914716 } else
....@@ -14528,7 +14725,8 @@
1452814725 Globals.MOUSEDRAGGED = false;
1452914726
1453014727 movingcamera = false;
14531
- X = Y = 0;
14728
+ X = 0; // getBounds().width/2;
14729
+ Y = 0; // getBounds().height/2;
1453214730 //System.out.println("mouseReleased: " + e);
1453314731 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1453414732 }
....@@ -14784,7 +14982,8 @@
1478414982 // break;
1478514983 case 'T':
1478614984 CACHETEXTURE ^= true;
14787
- textures.clear();
14985
+ texturepigment.clear();
14986
+ texturebump.clear();
1478814987 // repaint();
1478914988 break;
1479014989 case 'Y':
....@@ -14869,7 +15068,9 @@
1486915068 case 'E' : COMPACT ^= true;
1487015069 repaint();
1487115070 break;
14872
- case 'W' : DEBUGHSB ^= true;
15071
+ case 'W' : // Wide Window (fullscreen)
15072
+ //DEBUGHSB ^= true;
15073
+ ObjEditor.theFrame.ToggleFullScreen();
1487315074 repaint();
1487415075 break;
1487515076 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14894,8 +15095,8 @@
1489415095 RevertCamera();
1489515096 repaint();
1489615097 break;
14897
- case 'L':
1489815098 case 'l':
15099
+ //case 'L':
1489915100 if (lightMode)
1490015101 {
1490115102 lightMode = false;
....@@ -15038,9 +15239,9 @@
1503815239 case '_':
1503915240 kompactbit = 5;
1504015241 break;
15041
- case '+':
15042
- kompactbit = 6;
15043
- break;
15242
+// case '+':
15243
+// kompactbit = 6;
15244
+// break;
1504415245 case ' ':
1504515246 lightMode ^= true;
1504615247 Globals.lighttouched = true;
....@@ -15052,6 +15253,7 @@
1505215253 case ESC:
1505315254 RENDERPROGRAM += 1;
1505415255 RENDERPROGRAM %= 3;
15256
+
1505515257 repaint();
1505615258 break;
1505715259 case 'Z':
....@@ -15091,8 +15293,9 @@
1509115293 case DELETE:
1509215294 ClearSelection();
1509315295 break;
15094
- /*
1509515296 case '+':
15297
+
15298
+ /*
1509615299 //fontsize += 1;
1509715300 bbzoom *= 2;
1509815301 repaint();
....@@ -15109,17 +15312,17 @@
1510915312 case '=':
1511015313 IncDepth();
1511115314 //fontsize += 1;
15112
- object.editWindow.refreshContents(true);
15315
+ object.GetWindow().refreshContents(true);
1511315316 maskbit = 6;
1511415317 break;
1511515318 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1511615319 DecDepth();
1511715320 maskbit = 5;
1511815321 //if(fontsize > 1) fontsize -= 1;
15119
- if (object.editWindow == null)
15120
- new Exception().printStackTrace();
15121
- else
15122
- object.editWindow.refreshContents(true);
15322
+// if (object.editWindow == null)
15323
+// new Exception().printStackTrace();
15324
+// else
15325
+ object.GetWindow().refreshContents(true);
1512315326 break;
1512415327 case '{':
1512515328 manipCamera.shaper_fovy /= 1.1;
....@@ -15343,7 +15546,7 @@
1534315546 }
1534415547 */
1534515548
15346
- object.editWindow.EditSelection();
15549
+ object.GetWindow().EditSelection(false);
1534715550 }
1534815551
1534915552 void SelectParent()
....@@ -15360,10 +15563,10 @@
1536015563 {
1536115564 //selectees.remove(i);
1536215565 System.out.println("select parent of " + elem);
15363
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15566
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1536415567 } else
1536515568 {
15366
- group.editWindow.Select(elem.GetTreePath(), first, true);
15569
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1536715570 }
1536815571
1536915572 first = false;
....@@ -15405,12 +15608,12 @@
1540515608 for (int j = 0; j < group.children.size(); j++)
1540615609 {
1540715610 elem = (Object3D) group.children.elementAt(j);
15408
- object.editWindow.Select(elem.GetTreePath(), first, true);
15611
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1540915612 first = false;
1541015613 }
1541115614 } else
1541215615 {
15413
- object.editWindow.Select(elem.GetTreePath(), first, true);
15616
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1541415617 }
1541515618
1541615619 first = false;
....@@ -15421,21 +15624,21 @@
1542115624 {
1542215625 //Composite group = (Composite) object;
1542315626 Object3D group = object;
15424
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15627
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1542515628 }
1542615629
1542715630 void ResetTransform(int mask)
1542815631 {
1542915632 //Composite group = (Composite) object;
1543015633 Object3D group = object;
15431
- group.editWindow.ResetTransform(mask);
15634
+ group.GetWindow().ResetTransform(mask);
1543215635 }
1543315636
1543415637 void FlipTransform()
1543515638 {
1543615639 //Composite group = (Composite) object;
1543715640 Object3D group = object;
15438
- group.editWindow.FlipTransform();
15641
+ group.GetWindow().FlipTransform();
1543915642 // group.editWindow.ReduceMesh(true);
1544015643 }
1544115644
....@@ -15443,7 +15646,7 @@
1544315646 {
1544415647 //Composite group = (Composite) object;
1544515648 Object3D group = object;
15446
- group.editWindow.PrintMemory();
15649
+ group.GetWindow().PrintMemory();
1544715650 // group.editWindow.ReduceMesh(true);
1544815651 }
1544915652
....@@ -15451,7 +15654,7 @@
1545115654 {
1545215655 //Composite group = (Composite) object;
1545315656 Object3D group = object;
15454
- group.editWindow.ResetCentroid();
15657
+ group.GetWindow().ResetCentroid();
1545515658 }
1545615659
1545715660 void IncDepth()
....@@ -15627,6 +15830,7 @@
1562715830 info.bounds.y += (height - desired) / 2;
1562815831 }
1562915832 }
15833
+
1563015834 info.g = gr;
1563115835 info.camera = renderCamera;
1563215836 /*
....@@ -15636,23 +15840,44 @@
1563615840 */
1563715841 if (!isRenderer)
1563815842 {
15639
- object.drawEditHandles(info, 0);
15640
-
15641
- 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)
1564215846 {
15643
- 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)
1564415853 {
15645
- case Object3D.hitCenter: gr.setColor(Color.pink);
15646
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15647
- break;
15648
- case Object3D.hitRotate: gr.setColor(Color.yellow);
15649
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15650
- break;
15651
- case Object3D.hitScale: gr.setColor(Color.cyan);
15652
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15653
- 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;
1565415861 }
15655
-
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
+ }
1565615881 }
1565715882 }
1565815883 }
....@@ -16355,16 +16580,16 @@
1635516580 cStatic.objectstack[materialdepth++] = checker;
1635616581 //System.out.println("material " + material);
1635716582 //Applet3D.tracein(this, selected);
16358
- vector2buffer = checker.projectedVertices;
16583
+ //vector2buffer = checker.projectedVertices;
1635916584
1636016585 //checker.GetMaterial().Draw(this, false); // true);
16361
- DrawMaterial(checker.GetMaterial(), false); // true);
16586
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1636216587
1636316588 materialdepth -= 1;
1636416589 if (materialdepth > 0)
1636516590 {
16366
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16367
- 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);
1636816593 }
1636916594 //checker.GetMaterial().opacity = 1f;
1637016595 ////checker.GetMaterial().ambient = 1f;
....@@ -16450,6 +16675,14 @@
1645016675 }
1645116676 }
1645216677
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
+
1645316686 class SelectBuffer implements GLEventListener
1645416687 {
1645516688
....@@ -16529,6 +16762,17 @@
1652916762
1653016763 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1653116764
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
+
1653216776 //int tmp = selection_view;
1653316777 //selection_view = -1;
1653416778 int temp = DrawMode();
....@@ -16540,6 +16784,17 @@
1654016784 // temp = DEFAULT; // patch for selection debug
1654116785 Globals.drawMode = temp; // WARNING
1654216786
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
+
1654316798 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1654416799
1654516800 // trying different ways of getting the depth info over
....@@ -16587,6 +16842,8 @@
1658716842 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1658816843 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1658916844 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
16845
+
16846
+ CreateSelectedPoint();
1659016847
1659116848 // Will fit the mesh !!!
1659216849 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16641,29 +16898,31 @@
1664116898 }
1664216899
1664316900 if (!movingcamera && !PAINTMODE)
16644
- object.editWindow.ScreenFitPoint(); // fev 2014
16901
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1664516902
16646
- 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)
1664716904 {
16648
- 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);
1664916906
16650
- Object3D group = new Object3D("inst" + paintcount++);
16907
+ if (object.GetWindow().copy.selection.Size() > 0)
16908
+ {
16909
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1665116910
16652
- group.CreateMaterial(); // use a void leaf to select instances
16653
-
16654
- group.add(paintobj); // link
16655
-
16656
- object.editWindow.SnapObject(group);
16657
-
16658
- Object3D folder = object.editWindow.copy;
16659
-
16660
- if (object.editWindow.copy.selection.Size() > 0)
16661
- folder = object.editWindow.copy.selection.elementAt(0);
16662
-
16663
- folder.add(group);
16664
-
16665
- object.editWindow.ResetModel();
16666
- 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
+ }
1666716926 }
1666816927 else
1666916928 paintcount = 0;
....@@ -16702,6 +16961,11 @@
1670216961 //System.out.println("objects[color] = " + objects[color]);
1670316962 //objects[color].Select();
1670416963 indexcount = 0;
16964
+ ObjEditor window = object.GetWindow();
16965
+ if (window != null && deselect)
16966
+ {
16967
+ window.Select(null, deselect, true);
16968
+ }
1670516969 object.Select(color, deselect);
1670616970 }
1670716971
....@@ -17227,23 +17491,15 @@
1722717491 int AAbuffersize = 0;
1722817492
1722917493 //double[] selectedpoint = new double[3];
17230
- static Superellipsoid selectedpoint = new Superellipsoid();
17494
+ static Superellipsoid selectedpoint;
1723117495 static Sphere previousselectedpoint = null;
17232
- static Sphere debugpointG = new Sphere();
17233
- static Sphere debugpointP = new Sphere();
17234
- static Sphere debugpointC = new Sphere();
17235
- static Sphere debugpointR = new Sphere();
17496
+ static Sphere debugpointG;
17497
+ static Sphere debugpointP;
17498
+ static Sphere debugpointC;
17499
+ static Sphere debugpointR;
1723617500
1723717501 static Sphere debugpoints[] = new Sphere[8];
1723817502
17239
- static
17240
- {
17241
- for (int i=0; i<8; i++)
17242
- {
17243
- debugpoints[i] = new Sphere();
17244
- }
17245
- }
17246
-
1724717503 static void InitPoints(float radius)
1724817504 {
1724917505 for (int i=0; i<8; i++)