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
....@@ -1890,7 +1944,7 @@
18901944 void PushMatrix(double[][] matrix)
18911945 {
18921946 // GrafreeD.tracein(matrix);
1893
- PushMatrix(matrix,1);
1947
+ PushMatrix(matrix, 1);
18941948 }
18951949
18961950 void PushMatrix()
....@@ -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,11 +8019,69 @@
79178019 pigment = null;
79188020 }
79198021
7920
- ReleaseTexture(bump, true);
7921
- ReleaseTexture(pigment, false);
8022
+ ReleaseTexture(tex, true);
8023
+ ReleaseTexture(tex, false);
79228024 }
79238025
7924
- void ReleaseTexture(String tex, boolean bump)
8026
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
8027
+ {
8028
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8029
+ {
8030
+ return;
8031
+ }
8032
+
8033
+ if (tex == null)
8034
+ {
8035
+ ReleaseTexture(null, false);
8036
+ return;
8037
+ }
8038
+
8039
+ String pigment = Object3D.GetPigment(tex);
8040
+
8041
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8042
+ {
8043
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8044
+ // System.out.println("; bump = " + bump);
8045
+ }
8046
+
8047
+ if (pigment.equals(""))
8048
+ {
8049
+ pigment = null;
8050
+ }
8051
+
8052
+ ReleaseTexture(tex, false);
8053
+ }
8054
+
8055
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
8056
+ {
8057
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8058
+ {
8059
+ return;
8060
+ }
8061
+
8062
+ if (tex == null)
8063
+ {
8064
+ ReleaseTexture(null, true);
8065
+ return;
8066
+ }
8067
+
8068
+ String bump = Object3D.GetBump(tex);
8069
+
8070
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8071
+ {
8072
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8073
+ // System.out.println("; bump = " + bump);
8074
+ }
8075
+
8076
+ if (bump.equals(""))
8077
+ {
8078
+ bump = null;
8079
+ }
8080
+
8081
+ ReleaseTexture(tex, true);
8082
+ }
8083
+
8084
+ void ReleaseTexture(cTexture tex, boolean bump)
79258085 {
79268086 if (// DrawMode() != 0 || /*tex == null ||*/
79278087 ambientOcclusion ) // || !textureon)
....@@ -7932,7 +8092,7 @@
79328092 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
79338093
79348094 if (tex != null)
7935
- texture = textures.get(tex);
8095
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
79368096
79378097 // //assert( texture != null );
79388098 // if (texture == null)
....@@ -8026,6 +8186,54 @@
80268186
80278187 /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
80288188 {
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;
8230
+
8231
+ BindPigmentTexture(tex, resolution);
8232
+ BindBumpTexture(tex, resolution);
8233
+ }
8234
+
8235
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8236
+ {
80298237 if (// DrawMode() != 0 || /*tex == null ||*/
80308238 ambientOcclusion ) // || !textureon)
80318239 {
....@@ -8035,17 +8243,47 @@
80358243 if (tex == null)
80368244 {
80378245 BindTexture(null,false,resolution);
8038
- BindTexture(null,true,resolution);
80398246 return;
80408247 }
80418248
80428249 String pigment = Object3D.GetPigment(tex);
8250
+
8251
+ usedtextures.add(tex);
8252
+
8253
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8254
+ {
8255
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8256
+ // System.out.println("; bump = " + bump);
8257
+ }
8258
+
8259
+ if (pigment.equals(""))
8260
+ {
8261
+ pigment = null;
8262
+ }
8263
+
8264
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8265
+ BindTexture(tex, false, resolution);
8266
+ }
8267
+
8268
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8269
+ {
8270
+ if (// DrawMode() != 0 || /*tex == null ||*/
8271
+ ambientOcclusion ) // || !textureon)
8272
+ {
8273
+ return; // false;
8274
+ }
8275
+
8276
+ if (tex == null)
8277
+ {
8278
+ BindTexture(null,true,resolution);
8279
+ return;
8280
+ }
8281
+
80438282 String bump = Object3D.GetBump(tex);
80448283
8045
- usedtextures.put(pigment, pigment);
8046
- usedtextures.put(bump, bump);
8284
+ usedtextures.add(tex);
80478285
8048
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8286
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
80498287 {
80508288 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
80518289 // System.out.println("; bump = " + bump);
....@@ -8055,18 +8293,10 @@
80558293 {
80568294 bump = null;
80578295 }
8058
- if (pigment.equals(""))
8059
- {
8060
- pigment = null;
8061
- }
80628296
8063
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8064
- BindTexture(pigment, false, resolution);
80658297 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8066
- BindTexture(bump, true, resolution);
8298
+ BindTexture(tex, true, resolution);
80678299 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8068
-
8069
- return; // true;
80708300 }
80718301
80728302 java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
....@@ -8089,13 +8319,19 @@
80898319 return fileExists;
80908320 }
80918321
8092
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception
8322
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
80938323 {
8094
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8324
+ CacheTexture texturecache = null;
80958325
80968326 if (tex != null)
80978327 {
8098
- 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
+ }
80998335
81008336 String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
81018337
....@@ -8105,19 +8341,34 @@
81058341 // else
81068342 // if (!texname.startsWith("/"))
81078343 // texname = "/Users/nbriere/Textures/" + texname;
8108
- if (!FileExists(tex))
8344
+ if (!FileExists(texname))
81098345 {
81108346 texname = fallbackTextureName;
81118347 }
81128348
81138349 if (CACHETEXTURE)
8114
- texture = textures.get(texname); // TEXTURE CACHE
8115
-
8116
- TextureData texturedata = null;
8117
-
8118
- if (texture == null || texture.resolution < resolution)
81198350 {
8120
- 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(""))
81218372 {
81228373 assert(!bump);
81238374 // if (bump)
....@@ -8128,19 +8379,23 @@
81288379 // }
81298380 // else
81308381 // {
8131
- texture = textures.get(tex);
8132
- if (texture == null)
8382
+ // texturecache = textures.get(texname); // suspicious
8383
+ if (texturecache == null)
81338384 {
8134
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8385
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
81358386 }
8387
+ else
8388
+ new Exception().printStackTrace();
81368389 // }
81378390 } else
8138
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8391
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
81398392 {
81408393 assert(bump);
8141
- texture = textures.get(tex);
8142
- if (texture == null)
8143
- 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();
81448399 } else
81458400 {
81468401 //if (tex.equals("IMMORTAL"))
....@@ -8148,11 +8403,13 @@
81488403 // texture = GetResourceTexture("default.png");
81498404 //} else
81508405 //{
8151
- if (tex.equals("WHITE_NOISE"))
8406
+ if (texname.endsWith("WHITE_NOISE"))
81528407 {
8153
- texture = textures.get(tex);
8154
- if (texture == null)
8155
- 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();
81568413 } else
81578414 {
81588415 if (textureon)
....@@ -8211,19 +8468,19 @@
82118468 if (texturedata == null)
82128469 throw new Exception();
82138470
8214
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8471
+ texturecache = new CacheTexture(texturedata,resolution);
82158472 //texture = GetTexture(tex, bump);
82168473 }
82178474 }
82188475 //}
82198476 }
82208477
8221
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8478
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
82228479 {
82238480 //return false;
82248481
82258482 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8226
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8483
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
82278484 {
82288485 // String ext = "_highres";
82298486 // if (REDUCETEXTURE)
....@@ -8240,52 +8497,17 @@
82408497 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
82418498 if (!cachefile.exists())
82428499 {
8243
- // cache to disk
8244
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
8245
- //buffers[0].
8246
-
8247
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
8248
- int[] pixels = new int[bytebuf.capacity()/3];
8249
-
8250
- // squared size heuristic...
8251
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8500
+ //if (texturedata.getWidth() == texturedata.getHeight())
82528501 {
8253
- for (int i=pixels.length; --i>=0;)
8254
- {
8255
- int i3 = i*3;
8256
- pixels[i] = 0xFF;
8257
- pixels[i] <<= 8;
8258
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
8259
- pixels[i] <<= 8;
8260
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
8261
- pixels[i] <<= 8;
8262
- pixels[i] |= bytebuf.get(i3) & 0xFF;
8263
- }
8264
-
8265
- /*
8266
- int r=0,g=0,b=0,a=0;
8267
- for (int i=0; i<width; i++)
8268
- for (int j=0; j<height; j++)
8269
- {
8270
- int index = j*width+i;
8271
- int p = pixels[index];
8272
- a = ((p>>24) & 0xFF);
8273
- r = ((p>>16) & 0xFF);
8274
- g = ((p>>8) & 0xFF);
8275
- b = (p & 0xFF);
8276
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
8277
- }
8278
- /**/
8279
- int width = (int)Math.sqrt(pixels.length); // squared
8280
- int height = width;
8281
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
8282
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8502
+ BufferedImage rendImage = CreateBim(texturedata);
8503
+
82838504 ImageWriter writer = null;
82848505 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
82858506 if (iter.hasNext()) {
82868507 writer = (ImageWriter)iter.next();
82878508 }
8288
- float compressionQuality = 0.9f;
8509
+
8510
+ float compressionQuality = 0.85f;
82898511 try
82908512 {
82918513 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8302,18 +8524,20 @@
83028524 }
83038525 }
83048526 }
8305
-
8527
+
8528
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8529
+
83068530 //System.out.println("Texture = " + tex);
8307
- if (textures.containsKey(texname))
8531
+ if (textures.containsKey(tex))
83088532 {
8309
- CacheTexture thetex = textures.get(texname);
8533
+ CacheTexture thetex = textures.get(tex);
83108534 thetex.texture.disable();
83118535 thetex.texture.dispose();
8312
- textures.remove(texname);
8536
+ textures.remove(tex);
83138537 }
83148538
8315
- texture.texturedata = texturedata;
8316
- textures.put(texname, texture);
8539
+ //texture.texturedata = texturedata;
8540
+ textures.put(tex, texturecache);
83178541
83188542 // newtex = true;
83198543 }
....@@ -8329,10 +8553,41 @@
83298553 }
83308554 }
83318555
8332
- return texture;
8556
+ return texturecache;
83338557 }
83348558
8335
- 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
83368591 {
83378592 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
83388593
....@@ -8350,21 +8605,21 @@
83508605 return texture!=null?texture.texture:null;
83518606 }
83528607
8353
- 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
83548609 {
83558610 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
83568611
83578612 return texture!=null?texture.texturedata:null;
83588613 }
83598614
8360
- boolean BindTexture(String tex, boolean bump, int resolution) throws Exception
8615
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
83618616 {
83628617 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
83638618 {
83648619 return false;
83658620 }
83668621
8367
- boolean newtex = false;
8622
+ //boolean newtex = false;
83688623
83698624 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
83708625
....@@ -8396,7 +8651,7 @@
83968651 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
83978652 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
83988653
8399
- return newtex;
8654
+ return true; // Warning: not used.
84008655 }
84018656
84028657 ShadowBuffer shadowPBuf;
....@@ -9234,11 +9489,35 @@
92349489 jy8[3] = 0.5f;
92359490 }
92369491
9237
- 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
92389493 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
92399494 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
92409495 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
92419496
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
+
92429521 static int imagecount = 0; // movie generation
92439522
92449523 static int jitter = 0;
....@@ -9335,7 +9614,7 @@
93359614
93369615 if (renderCamera != lightCamera)
93379616 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9338
- LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
9617
+ LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
93399618
93409619 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
93419620
....@@ -9351,7 +9630,7 @@
93519630
93529631 if (renderCamera != lightCamera)
93539632 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9354
- LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
9633
+ LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
93559634
93569635 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
93579636
....@@ -10349,6 +10628,7 @@
1034910628 ANTIALIAS = 0;
1035010629 //System.out.println("RESTART");
1035110630 AAtimer.restart();
10631
+ Globals.TIMERRUNNING = true;
1035210632 }
1035310633 }
1035410634 }
....@@ -10416,7 +10696,8 @@
1041610696 ambientOcclusion = false;
1041710697 }
1041810698
10419
- if (Globals.lighttouched && DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
10699
+ if (//Globals.lighttouched &&
10700
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1042010701 {
1042110702 //if (RENDERSHADOW) // ?
1042210703 if (!IsFrozen())
....@@ -10550,7 +10831,7 @@
1055010831 // if (parentcam != renderCamera) // not a light
1055110832 if (cam != lightCamera)
1055210833 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10553
- LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
10834
+ LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
1055410835
1055510836 for (int j = 0; j < 4; j++)
1055610837 {
....@@ -10565,7 +10846,7 @@
1056510846 // if (parentcam != renderCamera) // not a light
1056610847 if (cam != lightCamera)
1056710848 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10568
- LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
10849
+ LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
1056910850
1057010851 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1057110852
....@@ -10856,9 +11137,9 @@
1085611137
1085711138 gl.glMatrixMode(GL.GL_MODELVIEW);
1085811139
10859
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10860
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10861
-//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);
1086211143 } else
1086311144 {
1086411145 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -10869,7 +11150,7 @@
1086911150 //System.out.println("BLENDING ON");
1087011151 gl.glEnable(GL.GL_BLEND);
1087111152 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
10872
-
11153
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1087311154 gl.glMatrixMode(gl.GL_PROJECTION);
1087411155 gl.glLoadIdentity();
1087511156
....@@ -10959,7 +11240,7 @@
1095911240
1096011241 // if (cam != lightCamera)
1096111242 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10962
- LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
11243
+ LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
1096311244 }
1096411245
1096511246 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -10981,7 +11262,7 @@
1098111262 {
1098211263 if (cam != lightCamera)
1098311264 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10984
- LA.xformDir(light0, parentcam.GlobalTransformInv(), light0); // may 2013
11265
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
1098511266 }
1098611267
1098711268 LA.xformPos(light0, cam.toScreen, light0);
....@@ -11326,15 +11607,36 @@
1132611607
1132711608 static boolean zoomonce = false;
1132811609
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
+
1132911628 void DrawObject(GL gl, boolean draw)
1133011629 {
11630
+ // To clear camera values
11631
+ ResetOptions();
11632
+
1133111633 //System.out.println("DRAW OBJECT " + mouseDown);
1133211634 // DrawMode() = SELECTION;
1133311635 //GL gl = getGL();
1133411636 if ((TRACK || SHADOWTRACK) || zoomonce)
1133511637 {
1133611638 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11337
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11639
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1133811640 pingthread.StepToTarget(true); // true);
1133911641 // zoomonce = false;
1134011642 }
....@@ -11406,8 +11708,9 @@
1140611708
1140711709 if (DrawMode() == DEFAULT)
1140811710 {
11409
- if (DEBUG)
11711
+ if (Globals.DEBUG)
1141011712 {
11713
+ CreateSelectedPoint();
1141111714 float radius = 0.05f;
1141211715 if (selectedpoint.radius != radius)
1141311716 {
....@@ -11461,20 +11764,32 @@
1146111764 ReleaseTextures(DEFAULT_TEXTURES);
1146211765
1146311766 if (CLEANCACHE)
11464
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11767
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1146511768 {
11466
- String tex = e.nextElement();
11769
+ cTexture tex = e.nextElement();
1146711770
1146811771 // System.out.println("Texture --------- " + tex);
1146911772
11470
- if (tex.equals("WHITE_NOISE"))
11773
+ if (tex.equals("WHITE_NOISE:"))
1147111774 continue;
1147211775
11473
- if (!usedtextures.containsKey(tex))
11776
+ if (!usedtextures.contains(tex))
1147411777 {
11778
+ CacheTexture gettex = texturepigment.get(tex);
1147511779 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11476
- textures.get(tex).texture.dispose();
11477
- 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
+ }
1147811793 }
1147911794 }
1148011795 }
....@@ -11912,7 +12227,7 @@
1191212227 }
1191312228
1191412229 //for (int count = parentcam.GetTransformCount(); --count>=0;)
11915
- LA.xformPos(light, parentcam.GlobalTransformInv(), light); // may 2013
12230
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1191612231
1191712232 LA.xformPos(light, renderCamera.toScreen, light);
1191812233
....@@ -13164,7 +13479,8 @@
1316413479 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1316513480 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1316613481 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13167
- Object3D.cVector2[] vector2buffer;
13482
+
13483
+ //Object3D.cVector2[] vector2buffer;
1316813484
1316913485 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1317013486 // OUT : diff, spec
....@@ -13180,9 +13496,10 @@
1318013496 "DP3 " + dest + ".z," + "normals," + "eye;" +
1318113497 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1318213498 //"MOV " + dest + ".w," + "normal.z;" +
13183
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
13184
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13185
- //"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
1318613503 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1318713504 "RCP " + dest + ".w," + dest + ".w;" +
1318813505 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13687,6 +14004,7 @@
1368714004 else
1368814005 if (evt.getSource() == AAtimer)
1368914006 {
14007
+ Globals.TIMERRUNNING = false;
1369014008 if (mouseDown)
1369114009 {
1369214010 //new Exception().printStackTrace();
....@@ -13746,7 +14064,7 @@
1374614064
1374714065 // fev 2014???
1374814066 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13749
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14067
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1375014068 pingthread.StepToTarget(true); // true);
1375114069 }
1375214070 // if (!LIVE)
....@@ -13761,6 +14079,7 @@
1376114079 return;
1376214080
1376314081 AAtimer.restart(); //
14082
+ Globals.TIMERRUNNING = true;
1376414083
1376514084 // waslive = LIVE;
1376614085 // LIVE = false;
....@@ -13833,6 +14152,8 @@
1383314152
1383414153 public void mouseDragged(MouseEvent e)
1383514154 {
14155
+ Globals.MOUSEDRAGGED = true;
14156
+
1383614157 //System.out.println("mouseDragged: " + e);
1383714158 if (isRenderer)
1383814159 movingcamera = true;
....@@ -14097,12 +14418,12 @@
1409714418 void GoDown(int mod)
1409814419 {
1409914420 MODIFIERS |= COMMAND;
14100
- /*
14421
+ /**/
1410114422 if((mod&SHIFT) == SHIFT)
1410214423 manipCamera.RotatePosition(0, -speed);
1410314424 else
14104
- manipCamera.BackForth(0, -speed*delta, getWidth());
14105
- */
14425
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14426
+ /**/
1410614427 if ((mod & SHIFT) == SHIFT)
1410714428 {
1410814429 mouseMode = mouseMode; // VR??
....@@ -14118,12 +14439,12 @@
1411814439 void GoUp(int mod)
1411914440 {
1412014441 MODIFIERS |= COMMAND;
14121
- /*
14442
+ /**/
1412214443 if((mod&SHIFT) == SHIFT)
1412314444 manipCamera.RotatePosition(0, speed);
1412414445 else
14125
- manipCamera.BackForth(0, speed*delta, getWidth());
14126
- */
14446
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14447
+ /**/
1412714448 if ((mod & SHIFT) == SHIFT)
1412814449 {
1412914450 mouseMode = mouseMode;
....@@ -14139,12 +14460,12 @@
1413914460 void GoLeft(int mod)
1414014461 {
1414114462 MODIFIERS |= COMMAND;
14142
- /*
14463
+ /**/
1414314464 if((mod&SHIFT) == SHIFT)
14144
- manipCamera.RotatePosition(speed, 0);
14145
- else
1414614465 manipCamera.Translate(speed*delta, 0, getWidth());
14147
- */
14466
+ else
14467
+ manipCamera.RotatePosition(speed, 0);
14468
+ /**/
1414814469 if ((mod & SHIFT) == SHIFT)
1414914470 {
1415014471 mouseMode = mouseMode;
....@@ -14160,12 +14481,12 @@
1416014481 void GoRight(int mod)
1416114482 {
1416214483 MODIFIERS |= COMMAND;
14163
- /*
14484
+ /**/
1416414485 if((mod&SHIFT) == SHIFT)
14165
- manipCamera.RotatePosition(-speed, 0);
14166
- else
1416714486 manipCamera.Translate(-speed*delta, 0, getWidth());
14168
- */
14487
+ else
14488
+ manipCamera.RotatePosition(-speed, 0);
14489
+ /**/
1416914490 if ((mod & SHIFT) == SHIFT)
1417014491 {
1417114492 mouseMode = mouseMode;
....@@ -14222,7 +14543,8 @@
1422214543 info.camera = renderCamera;
1422314544 info.x = x;
1422414545 info.y = y;
14225
- object.editWindow.copy.doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
14546
+ object.GetWindow().copy
14547
+ .doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1422614548 } else
1422714549 {
1422814550 if (x < startX)
....@@ -14386,7 +14708,9 @@
1438614708 ci.camera = renderCamera;
1438714709 if (!isRenderer)
1438814710 {
14389
- if (object.editWindow.copy.doEditClick(ci, 0))
14711
+ //ObjEditor editWindow = object.editWindow;
14712
+ //Object3D copy = editWindow.copy;
14713
+ if (object.doEditClick(ci, 0))
1439014714 {
1439114715 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1439214716 } else
....@@ -14398,8 +14722,11 @@
1439814722
1439914723 public void mouseReleased(MouseEvent e)
1440014724 {
14725
+ Globals.MOUSEDRAGGED = false;
14726
+
1440114727 movingcamera = false;
14402
- X = Y = 0;
14728
+ X = 0; // getBounds().width/2;
14729
+ Y = 0; // getBounds().height/2;
1440314730 //System.out.println("mouseReleased: " + e);
1440414731 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1440514732 }
....@@ -14655,7 +14982,8 @@
1465514982 // break;
1465614983 case 'T':
1465714984 CACHETEXTURE ^= true;
14658
- textures.clear();
14985
+ texturepigment.clear();
14986
+ texturebump.clear();
1465914987 // repaint();
1466014988 break;
1466114989 case 'Y':
....@@ -14740,7 +15068,9 @@
1474015068 case 'E' : COMPACT ^= true;
1474115069 repaint();
1474215070 break;
14743
- case 'W' : DEBUGHSB ^= true;
15071
+ case 'W' : // Wide Window (fullscreen)
15072
+ //DEBUGHSB ^= true;
15073
+ ObjEditor.theFrame.ToggleFullScreen();
1474415074 repaint();
1474515075 break;
1474615076 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14765,8 +15095,8 @@
1476515095 RevertCamera();
1476615096 repaint();
1476715097 break;
14768
- case 'L':
1476915098 case 'l':
15099
+ //case 'L':
1477015100 if (lightMode)
1477115101 {
1477215102 lightMode = false;
....@@ -14909,9 +15239,9 @@
1490915239 case '_':
1491015240 kompactbit = 5;
1491115241 break;
14912
- case '+':
14913
- kompactbit = 6;
14914
- break;
15242
+// case '+':
15243
+// kompactbit = 6;
15244
+// break;
1491515245 case ' ':
1491615246 lightMode ^= true;
1491715247 Globals.lighttouched = true;
....@@ -14923,6 +15253,7 @@
1492315253 case ESC:
1492415254 RENDERPROGRAM += 1;
1492515255 RENDERPROGRAM %= 3;
15256
+
1492615257 repaint();
1492715258 break;
1492815259 case 'Z':
....@@ -14962,8 +15293,9 @@
1496215293 case DELETE:
1496315294 ClearSelection();
1496415295 break;
14965
- /*
1496615296 case '+':
15297
+
15298
+ /*
1496715299 //fontsize += 1;
1496815300 bbzoom *= 2;
1496915301 repaint();
....@@ -14980,17 +15312,17 @@
1498015312 case '=':
1498115313 IncDepth();
1498215314 //fontsize += 1;
14983
- object.editWindow.refreshContents(true);
15315
+ object.GetWindow().refreshContents(true);
1498415316 maskbit = 6;
1498515317 break;
1498615318 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1498715319 DecDepth();
1498815320 maskbit = 5;
1498915321 //if(fontsize > 1) fontsize -= 1;
14990
- if (object.editWindow == null)
14991
- new Exception().printStackTrace();
14992
- else
14993
- object.editWindow.refreshContents(true);
15322
+// if (object.editWindow == null)
15323
+// new Exception().printStackTrace();
15324
+// else
15325
+ object.GetWindow().refreshContents(true);
1499415326 break;
1499515327 case '{':
1499615328 manipCamera.shaper_fovy /= 1.1;
....@@ -15214,7 +15546,7 @@
1521415546 }
1521515547 */
1521615548
15217
- object.editWindow.EditSelection();
15549
+ object.GetWindow().EditSelection(false);
1521815550 }
1521915551
1522015552 void SelectParent()
....@@ -15231,10 +15563,10 @@
1523115563 {
1523215564 //selectees.remove(i);
1523315565 System.out.println("select parent of " + elem);
15234
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15566
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1523515567 } else
1523615568 {
15237
- group.editWindow.Select(elem.GetTreePath(), first, true);
15569
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1523815570 }
1523915571
1524015572 first = false;
....@@ -15276,12 +15608,12 @@
1527615608 for (int j = 0; j < group.children.size(); j++)
1527715609 {
1527815610 elem = (Object3D) group.children.elementAt(j);
15279
- object.editWindow.Select(elem.GetTreePath(), first, true);
15611
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1528015612 first = false;
1528115613 }
1528215614 } else
1528315615 {
15284
- object.editWindow.Select(elem.GetTreePath(), first, true);
15616
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1528515617 }
1528615618
1528715619 first = false;
....@@ -15292,21 +15624,21 @@
1529215624 {
1529315625 //Composite group = (Composite) object;
1529415626 Object3D group = object;
15295
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15627
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1529615628 }
1529715629
1529815630 void ResetTransform(int mask)
1529915631 {
1530015632 //Composite group = (Composite) object;
1530115633 Object3D group = object;
15302
- group.editWindow.ResetTransform(mask);
15634
+ group.GetWindow().ResetTransform(mask);
1530315635 }
1530415636
1530515637 void FlipTransform()
1530615638 {
1530715639 //Composite group = (Composite) object;
1530815640 Object3D group = object;
15309
- group.editWindow.FlipTransform();
15641
+ group.GetWindow().FlipTransform();
1531015642 // group.editWindow.ReduceMesh(true);
1531115643 }
1531215644
....@@ -15314,7 +15646,7 @@
1531415646 {
1531515647 //Composite group = (Composite) object;
1531615648 Object3D group = object;
15317
- group.editWindow.PrintMemory();
15649
+ group.GetWindow().PrintMemory();
1531815650 // group.editWindow.ReduceMesh(true);
1531915651 }
1532015652
....@@ -15322,7 +15654,7 @@
1532215654 {
1532315655 //Composite group = (Composite) object;
1532415656 Object3D group = object;
15325
- group.editWindow.ResetCentroid();
15657
+ group.GetWindow().ResetCentroid();
1532615658 }
1532715659
1532815660 void IncDepth()
....@@ -15498,6 +15830,7 @@
1549815830 info.bounds.y += (height - desired) / 2;
1549915831 }
1550015832 }
15833
+
1550115834 info.g = gr;
1550215835 info.camera = renderCamera;
1550315836 /*
....@@ -15507,18 +15840,44 @@
1550715840 */
1550815841 if (!isRenderer)
1550915842 {
15510
- object.drawEditHandles(info, 0);
15511
-
15512
- 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)
1551315846 {
15514
- 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)
1551515853 {
15516
- case Object3D.hitCenter: gr.setColor(Color.pink); break;
15517
- case Object3D.hitRotate: gr.setColor(Color.green); break;
15518
- case Object3D.hitScale: gr.setColor(Color.cyan); 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;
1551915861 }
15520
-
15521
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
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
+ }
1552215881 }
1552315882 }
1552415883 }
....@@ -16221,16 +16580,16 @@
1622116580 cStatic.objectstack[materialdepth++] = checker;
1622216581 //System.out.println("material " + material);
1622316582 //Applet3D.tracein(this, selected);
16224
- vector2buffer = checker.projectedVertices;
16583
+ //vector2buffer = checker.projectedVertices;
1622516584
1622616585 //checker.GetMaterial().Draw(this, false); // true);
16227
- DrawMaterial(checker.GetMaterial(), false); // true);
16586
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1622816587
1622916588 materialdepth -= 1;
1623016589 if (materialdepth > 0)
1623116590 {
16232
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16233
- 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);
1623416593 }
1623516594 //checker.GetMaterial().opacity = 1f;
1623616595 ////checker.GetMaterial().ambient = 1f;
....@@ -16316,6 +16675,14 @@
1631616675 }
1631716676 }
1631816677
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
+
1631916686 class SelectBuffer implements GLEventListener
1632016687 {
1632116688
....@@ -16395,6 +16762,17 @@
1639516762
1639616763 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1639716764
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
+
1639816776 //int tmp = selection_view;
1639916777 //selection_view = -1;
1640016778 int temp = DrawMode();
....@@ -16406,6 +16784,17 @@
1640616784 // temp = DEFAULT; // patch for selection debug
1640716785 Globals.drawMode = temp; // WARNING
1640816786
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
+
1640916798 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1641016799
1641116800 // trying different ways of getting the depth info over
....@@ -16453,6 +16842,8 @@
1645316842 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1645416843 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1645516844 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
16845
+
16846
+ CreateSelectedPoint();
1645616847
1645716848 // Will fit the mesh !!!
1645816849 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16507,29 +16898,31 @@
1650716898 }
1650816899
1650916900 if (!movingcamera && !PAINTMODE)
16510
- object.editWindow.ScreenFitPoint(); // fev 2014
16901
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1651116902
16512
- 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)
1651316904 {
16514
- 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);
1651516906
16516
- Object3D group = new Object3D("inst" + paintcount++);
16907
+ if (object.GetWindow().copy.selection.Size() > 0)
16908
+ {
16909
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1651716910
16518
- group.CreateMaterial(); // use a void leaf to select instances
16519
-
16520
- group.add(paintobj); // link
16521
-
16522
- object.editWindow.SnapObject(group);
16523
-
16524
- Object3D folder = object.editWindow.copy;
16525
-
16526
- if (object.editWindow.copy.selection.Size() > 0)
16527
- folder = object.editWindow.copy.selection.elementAt(0);
16528
-
16529
- folder.add(group);
16530
-
16531
- object.editWindow.ResetModel();
16532
- 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
+ }
1653316926 }
1653416927 else
1653516928 paintcount = 0;
....@@ -16568,6 +16961,11 @@
1656816961 //System.out.println("objects[color] = " + objects[color]);
1656916962 //objects[color].Select();
1657016963 indexcount = 0;
16964
+ ObjEditor window = object.GetWindow();
16965
+ if (window != null && deselect)
16966
+ {
16967
+ window.Select(null, deselect, true);
16968
+ }
1657116969 object.Select(color, deselect);
1657216970 }
1657316971
....@@ -17093,23 +17491,15 @@
1709317491 int AAbuffersize = 0;
1709417492
1709517493 //double[] selectedpoint = new double[3];
17096
- static Superellipsoid selectedpoint = new Superellipsoid();
17494
+ static Superellipsoid selectedpoint;
1709717495 static Sphere previousselectedpoint = null;
17098
- static Sphere debugpointG = new Sphere();
17099
- static Sphere debugpointP = new Sphere();
17100
- static Sphere debugpointC = new Sphere();
17101
- static Sphere debugpointR = new Sphere();
17496
+ static Sphere debugpointG;
17497
+ static Sphere debugpointP;
17498
+ static Sphere debugpointC;
17499
+ static Sphere debugpointR;
1710217500
1710317501 static Sphere debugpoints[] = new Sphere[8];
1710417502
17105
- static
17106
- {
17107
- for (int i=0; i<8; i++)
17108
- {
17109
- debugpoints[i] = new Sphere();
17110
- }
17111
- }
17112
-
1711317503 static void InitPoints(float radius)
1711417504 {
1711517505 for (int i=0; i<8; i++)