Normand Briere
2019-07-21 d32f24f147068e6cbecb31c7f98047f68bc8b58a
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
....@@ -61,7 +60,7 @@
6160 //boolean REDUCETEXTURE = true;
6261 boolean CACHETEXTURE = true;
6362 boolean CLEANCACHE = false; // true;
64
- boolean MIPMAP = false; // true;
63
+ boolean MIPMAP = true; // false; // true;
6564 boolean COMPRESSTEXTURE = false;
6665 boolean KOMPACTTEXTURE = false; // true;
6766 boolean RESIZETEXTURE = false;
....@@ -149,6 +148,8 @@
149148 defaultcaps.setAccumBlueBits(16);
150149 defaultcaps.setAccumAlphaBits(16);
151150 }
151
+
152
+ private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
152153
153154 void SetAsGLRenderer(boolean b)
154155 {
....@@ -325,7 +326,7 @@
325326 cStatic.objectstack[materialdepth++] = obj;
326327 //System.out.println("material " + material);
327328 //Applet3D.tracein(this, selected);
328
- display.vector2buffer = obj.projectedVertices;
329
+ //display.vector2buffer = obj.projectedVertices;
329330 if (obj instanceof Camera)
330331 {
331332 display.options1[0] = material.shift;
....@@ -334,14 +335,28 @@
334335 display.options1[2] = material.shadowbias;
335336 display.options1[3] = material.aniso;
336337 display.options1[4] = material.anisoV;
338
+// System.out.println("display.options1[0] " + display.options1[0]);
339
+// System.out.println("display.options1[1] " + display.options1[1]);
340
+// System.out.println("display.options1[2] " + display.options1[2]);
341
+// System.out.println("display.options1[3] " + display.options1[3]);
342
+// System.out.println("display.options1[4] " + display.options1[4]);
337343 display.options2[0] = material.opacity;
338344 display.options2[1] = material.diffuse;
339345 display.options2[2] = material.factor;
346
+// System.out.println("display.options2[0] " + display.options2[0]);
347
+// System.out.println("display.options2[1] " + display.options2[1]);
348
+// System.out.println("display.options2[2] " + display.options2[2]);
340349
341350 cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
351
+// System.out.println("display.options3[0] " + display.options3[0]);
352
+// System.out.println("display.options3[1] " + display.options3[1]);
353
+// System.out.println("display.options3[2] " + display.options3[2]);
342354 display.options4[0] = material.cameralight/0.2f;
343355 display.options4[1] = material.subsurface;
344356 display.options4[2] = material.sheen;
357
+// System.out.println("display.options4[0] " + display.options4[0]);
358
+// System.out.println("display.options4[1] " + display.options4[1]);
359
+// System.out.println("display.options4[2] " + display.options4[2]);
345360
346361 // if (display.CURRENTANTIALIAS > 0)
347362 // display.options3[3] /= 4;
....@@ -357,7 +372,7 @@
357372 /**/
358373 } else
359374 {
360
- DrawMaterial(material, selected);
375
+ DrawMaterial(material, selected, obj.projectedVertices);
361376 }
362377 } else
363378 {
....@@ -381,8 +396,8 @@
381396 cStatic.objectstack[materialdepth++] = obj;
382397 //System.out.println("material " + material);
383398 //Applet3D.tracein("selected ", selected);
384
- display.vector2buffer = obj.projectedVertices;
385
- display.DrawMaterial(material, selected);
399
+ //display.vector2buffer = obj.projectedVertices;
400
+ display.DrawMaterial(material, selected, obj.projectedVertices);
386401 }
387402 }
388403
....@@ -399,8 +414,8 @@
399414 materialdepth -= 1;
400415 if (materialdepth > 0)
401416 {
402
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
403
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
417
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
418
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
404419 }
405420 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
406421 } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
....@@ -420,8 +435,8 @@
420435 materialdepth -= 1;
421436 if (materialdepth > 0)
422437 {
423
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
424
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
438
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
439
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
425440 }
426441 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
427442 //else
....@@ -462,10 +477,12 @@
462477 if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
463478 {
464479 //gl.glBegin(gl.GL_TRIANGLES);
465
- boolean hasnorm = pv.norm != null; // && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0);
480
+ boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0)
481
+ // TEST LIVE NORMALS && !obj.dontselect
482
+ ;
466483 if (!hasnorm)
467484 {
468
- // System.out.println("FUCK!!");
485
+ // System.out.println("Mesh normal");
469486 LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
470487 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
471488 LA.vecCross(obj.v0, obj.v1, obj.v2);
....@@ -1190,10 +1207,12 @@
11901207 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
11911208 }
11921209 }
1210
+
11931211 if (flipV)
11941212 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
11951213 else
11961214 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1215
+
11971216 //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
11981217 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
11991218
....@@ -1213,10 +1232,12 @@
12131232 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
12141233 }
12151234 }
1235
+
12161236 if (flipV)
12171237 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12181238 else
12191239 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1240
+
12201241 //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
12211242 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
12221243
....@@ -1244,8 +1265,10 @@
12441265 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12451266 else
12461267 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1268
+
12471269 //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
12481270 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1271
+
12491272 count2 += 2;
12501273 count3 += 3;
12511274 }
....@@ -1601,7 +1624,7 @@
16011624 // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
16021625 }
16031626
1604
- void DrawMaterial(cMaterial material, boolean selected)
1627
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
16051628 {
16061629 CameraPane display = this;
16071630 //new Exception().printStackTrace();
....@@ -1636,7 +1659,7 @@
16361659 colorV[0] = display.modelParams0[0] * material.diffuse;
16371660 colorV[1] = display.modelParams0[1] * material.diffuse;
16381661 colorV[2] = display.modelParams0[2] * material.diffuse;
1639
- colorV[3] = material.opacity;
1662
+ colorV[3] = 1; // material.opacity;
16401663
16411664 gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
16421665 //System.out.println("Opacity = " + opacity);
....@@ -1744,9 +1767,9 @@
17441767 display.modelParams7[2] = 0;
17451768 display.modelParams7[3] = 0;
17461769
1747
- display.modelParams6[0] = 100; // criss de bug de bump
1770
+ //display.modelParams6[0] = 100; // criss de bug de bump
17481771
1749
- Object3D.cVector2[] extparams = display.vector2buffer;
1772
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
17501773 if (extparams != null && extparams.length > 0 && extparams[0] != null)
17511774 {
17521775 display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
....@@ -1888,7 +1911,7 @@
18881911 void PushMatrix(double[][] matrix)
18891912 {
18901913 // GrafreeD.tracein(matrix);
1891
- PushMatrix(matrix,1);
1914
+ PushMatrix(matrix, 1);
18921915 }
18931916
18941917 void PushMatrix()
....@@ -2042,7 +2065,7 @@
20422065 //System.err.println("Oeil on");
20432066 OEIL = true;
20442067 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2045
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2068
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
20462069 //pingthread.StepToTarget(true);
20472070 }
20482071
....@@ -2257,7 +2280,7 @@
22572280
22582281 void ToggleDebug()
22592282 {
2260
- DEBUG ^= true;
2283
+ Globals.DEBUG ^= true;
22612284 }
22622285
22632286 void ToggleLookAt()
....@@ -2265,7 +2288,7 @@
22652288 LOOKAT ^= true;
22662289 }
22672290
2268
- void ToggleRandom()
2291
+ void ToggleSwitch()
22692292 {
22702293 SWITCH ^= true;
22712294 }
....@@ -2275,10 +2298,17 @@
22752298 HANDLES ^= true;
22762299 }
22772300
2301
+ Object3D paintFolder;
2302
+
22782303 void TogglePaint()
22792304 {
22802305 PAINTMODE ^= true;
22812306 paintcount = 0;
2307
+
2308
+ if (PAINTMODE)
2309
+ {
2310
+ paintFolder = GetFolder();
2311
+ }
22822312 }
22832313
22842314 void SwapCamera(int a, int b)
....@@ -2374,7 +2404,46 @@
23742404 {
23752405 return currentGL;
23762406 }
2377
-
2407
+
2408
+ private BufferedImage CreateBim(TextureData texturedata)
2409
+ {
2410
+ // cache to disk
2411
+ Buffer buffer = texturedata.getBuffer(); // getMipmapData();
2412
+ //buffers[0].
2413
+ ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
2414
+ int[] pixels = new int[bytebuf.capacity()/3];
2415
+ int width = texturedata.getWidth(); //(int)Math.sqrt(pixels.length); // squared
2416
+ int height = width;
2417
+ for (int i=pixels.length; --i>=0;)
2418
+ {
2419
+ int i3 = i*3;
2420
+ pixels[i] = 0xFF;
2421
+ pixels[i] <<= 8;
2422
+ pixels[i] |= bytebuf.get(i3+2) & 0xFF;
2423
+ pixels[i] <<= 8;
2424
+ pixels[i] |= bytebuf.get(i3+1) & 0xFF;
2425
+ pixels[i] <<= 8;
2426
+ pixels[i] |= bytebuf.get(i3) & 0xFF;
2427
+ }
2428
+ /*
2429
+ int r=0,g=0,b=0,a=0;
2430
+ for (int i=0; i<width; i++)
2431
+ for (int j=0; j<height; j++)
2432
+ {
2433
+ int index = j*width+i;
2434
+ int p = pixels[index];
2435
+ a = ((p>>24) & 0xFF);
2436
+ r = ((p>>16) & 0xFF);
2437
+ g = ((p>>8) & 0xFF);
2438
+ b = (p & 0xFF);
2439
+ pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
2440
+ }
2441
+ /**/
2442
+ BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
2443
+ rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
2444
+ return rendImage;
2445
+ }
2446
+
23782447 /**/
23792448 class CacheTexture
23802449 {
....@@ -2392,9 +2461,10 @@
23922461 /**/
23932462
23942463 // TEXTURE static Texture texture;
2395
- static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures
2396
- = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>();
2397
- static public java.util.Hashtable<String, String> usedtextures = new java.util.Hashtable<String, String>();
2464
+ static public java.util.Hashtable<String, CacheTexture> textures = new java.util.Hashtable<String, CacheTexture>();
2465
+ static public java.util.Hashtable<BufferedImage, CacheTexture> bimtextures = new java.util.Hashtable<BufferedImage, CacheTexture>();
2466
+ static public java.util.HashSet<String> usedtextures = new java.util.HashSet<String>();
2467
+
23982468 int pigmentdepth = 0;
23992469 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
24002470 int bumpdepth = 0;
....@@ -2416,6 +2486,33 @@
24162486 true,
24172487 com.sun.opengl.util.texture.TextureIO.PNG);
24182488 } catch (java.io.IOException e)
2489
+ {
2490
+ throw new javax.media.opengl.GLException(e);
2491
+ }
2492
+
2493
+ if (bump)
2494
+ texturedata = ConvertBump(texturedata, false);
2495
+
2496
+ com.sun.opengl.util.texture.Texture texture =
2497
+ com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2498
+
2499
+ texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2500
+ texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
2501
+
2502
+ return texture;
2503
+ }
2504
+
2505
+ com.sun.opengl.util.texture.Texture GetBimTexture(BufferedImage name, boolean bump)
2506
+ {
2507
+ TextureData texturedata = null;
2508
+
2509
+ try
2510
+ {
2511
+ texturedata =
2512
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2513
+ name,
2514
+ true);
2515
+ } catch (Exception e)
24192516 {
24202517 throw new javax.media.opengl.GLException(e);
24212518 }
....@@ -3502,6 +3599,8 @@
35023599
35033600 System.out.println("LOADING TEXTURE : " + name);
35043601
3602
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3603
+
35053604 //
35063605 if (false) // compressbit > 0)
35073606 {
....@@ -7900,7 +7999,7 @@
79007999 String pigment = Object3D.GetPigment(tex);
79018000 String bump = Object3D.GetBump(tex);
79028001
7903
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8002
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79048003 {
79058004 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79068005 // System.out.println("; bump = " + bump);
....@@ -7917,6 +8016,64 @@
79178016
79188017 ReleaseTexture(bump, true);
79198018 ReleaseTexture(pigment, false);
8019
+ }
8020
+
8021
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
8022
+ {
8023
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8024
+ {
8025
+ return;
8026
+ }
8027
+
8028
+ if (tex == null)
8029
+ {
8030
+ ReleaseTexture(null, false);
8031
+ return;
8032
+ }
8033
+
8034
+ String pigment = Object3D.GetPigment(tex);
8035
+
8036
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8037
+ {
8038
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8039
+ // System.out.println("; bump = " + bump);
8040
+ }
8041
+
8042
+ if (pigment.equals(""))
8043
+ {
8044
+ pigment = null;
8045
+ }
8046
+
8047
+ ReleaseTexture(pigment, false);
8048
+ }
8049
+
8050
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
8051
+ {
8052
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8053
+ {
8054
+ return;
8055
+ }
8056
+
8057
+ if (tex == null)
8058
+ {
8059
+ ReleaseTexture(null, true);
8060
+ return;
8061
+ }
8062
+
8063
+ String bump = Object3D.GetBump(tex);
8064
+
8065
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8066
+ {
8067
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8068
+ // System.out.println("; bump = " + bump);
8069
+ }
8070
+
8071
+ if (bump.equals(""))
8072
+ {
8073
+ bump = null;
8074
+ }
8075
+
8076
+ ReleaseTexture(bump, true);
79208077 }
79218078
79228079 void ReleaseTexture(String tex, boolean bump)
....@@ -8024,6 +8181,54 @@
80248181
80258182 /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
80268183 {
8184
+// if (// DrawMode() != 0 || /*tex == null ||*/
8185
+// ambientOcclusion ) // || !textureon)
8186
+// {
8187
+// return; // false;
8188
+// }
8189
+//
8190
+// if (tex == null)
8191
+// {
8192
+// BindTexture(null,false,resolution);
8193
+// BindTexture(null,true,resolution);
8194
+// return;
8195
+// }
8196
+//
8197
+// String pigment = Object3D.GetPigment(tex);
8198
+// String bump = Object3D.GetBump(tex);
8199
+//
8200
+// usedtextures.add(pigment);
8201
+// usedtextures.add(bump);
8202
+//
8203
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8204
+// {
8205
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8206
+// // System.out.println("; bump = " + bump);
8207
+// }
8208
+//
8209
+// if (bump.equals(""))
8210
+// {
8211
+// bump = null;
8212
+// }
8213
+// if (pigment.equals(""))
8214
+// {
8215
+// pigment = null;
8216
+// }
8217
+//
8218
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8219
+// BindTexture(pigment, false, resolution);
8220
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8221
+// BindTexture(bump, true, resolution);
8222
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8223
+//
8224
+// return; // true;
8225
+
8226
+ BindPigmentTexture(tex, resolution);
8227
+ BindBumpTexture(tex, resolution);
8228
+ }
8229
+
8230
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8231
+ {
80278232 if (// DrawMode() != 0 || /*tex == null ||*/
80288233 ambientOcclusion ) // || !textureon)
80298234 {
....@@ -8032,18 +8237,48 @@
80328237
80338238 if (tex == null)
80348239 {
8035
- BindTexture(null,false,resolution);
8036
- BindTexture(null,true,resolution);
8240
+ BindTexture(null, null,false,resolution);
80378241 return;
80388242 }
80398243
80408244 String pigment = Object3D.GetPigment(tex);
8245
+
8246
+ usedtextures.add(pigment);
8247
+
8248
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8249
+ {
8250
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8251
+ // System.out.println("; bump = " + bump);
8252
+ }
8253
+
8254
+ if (pigment.equals(""))
8255
+ {
8256
+ pigment = null;
8257
+ }
8258
+
8259
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8260
+ BindTexture(tex.pigmenttexture, pigment, false, resolution);
8261
+ }
8262
+
8263
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8264
+ {
8265
+ if (// DrawMode() != 0 || /*tex == null ||*/
8266
+ ambientOcclusion ) // || !textureon)
8267
+ {
8268
+ return; // false;
8269
+ }
8270
+
8271
+ if (tex == null)
8272
+ {
8273
+ BindTexture(null, null,true,resolution);
8274
+ return;
8275
+ }
8276
+
80418277 String bump = Object3D.GetBump(tex);
80428278
8043
- usedtextures.put(pigment, pigment);
8044
- usedtextures.put(bump, bump);
8279
+ usedtextures.add(bump);
80458280
8046
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8281
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
80478282 {
80488283 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
80498284 // System.out.println("; bump = " + bump);
....@@ -8053,46 +8288,70 @@
80538288 {
80548289 bump = null;
80558290 }
8056
- if (pigment.equals(""))
8057
- {
8058
- pigment = null;
8059
- }
80608291
8061
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8062
- BindTexture(pigment, false, resolution);
80638292 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8064
- BindTexture(bump, true, resolution);
8293
+ BindTexture(tex.bumptexture, bump, true, resolution);
80658294 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8066
-
8067
- return; // true;
80688295 }
80698296
8070
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception
8297
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8298
+
8299
+ private boolean FileExists(String tex)
80718300 {
8072
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8301
+ if (missingTextures.contains(tex))
8302
+ {
8303
+ return false;
8304
+ }
8305
+
8306
+ boolean fileExists = new File(tex).exists();
8307
+
8308
+ if (!fileExists)
8309
+ {
8310
+ // If file exists, the "new File()" is not executed sgain
8311
+ missingTextures.add(tex);
8312
+ }
8313
+
8314
+ return fileExists;
8315
+ }
8316
+
8317
+ CacheTexture GetCacheTexture(java.awt.image.BufferedImage bim, String tex, boolean bump, int resolution) throws Exception
8318
+ {
8319
+ CacheTexture texturecache = null;
80738320
80748321 if (tex != null)
80758322 {
80768323 String texname = tex;
80778324
8325
+ String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
8326
+
80788327 // String[] split = tex.split("Textures");
80798328 // if (split.length > 1)
80808329 // texname = "/Users/nbriere/Textures" + split[split.length-1];
80818330 // else
80828331 // if (!texname.startsWith("/"))
80838332 // texname = "/Users/nbriere/Textures/" + texname;
8084
- if (!new File(tex).exists())
8333
+ if (!FileExists(tex))
80858334 {
8086
- texname = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory() + "/Textures/" + texname;
8335
+ texname = fallbackTextureName;
80878336 }
80888337
80898338 if (CACHETEXTURE)
8090
- texture = textures.get(texname); // TEXTURE CACHE
8091
-
8092
- TextureData texturedata = null;
8093
-
8094
- if (texture == null || texture.resolution < resolution)
80958339 {
8340
+ if (bim == null)
8341
+ texturecache = textures.get(texname); // TEXTURE CACHE
8342
+ else
8343
+ texturecache = bimtextures.get(bim); // TEXTURE CACHE
8344
+ }
8345
+
8346
+ if (texturecache == null || texturecache.resolution < resolution)
8347
+ {
8348
+ TextureData texturedata = null;
8349
+
8350
+ if (bim != null)
8351
+ {
8352
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8353
+ }
8354
+ else
80968355 if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
80978356 {
80988357 assert(!bump);
....@@ -8104,19 +8363,23 @@
81048363 // }
81058364 // else
81068365 // {
8107
- texture = textures.get(tex);
8108
- if (texture == null)
8366
+ texturecache = textures.get(tex);
8367
+ if (texturecache == null)
81098368 {
8110
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8369
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
81118370 }
8371
+ else
8372
+ new Exception().printStackTrace();
81128373 // }
81138374 } else
81148375 if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
81158376 {
81168377 assert(bump);
8117
- texture = textures.get(tex);
8118
- if (texture == null)
8119
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8378
+ texturecache = textures.get(tex);
8379
+ if (texturecache == null)
8380
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8381
+ else
8382
+ new Exception().printStackTrace();
81208383 } else
81218384 {
81228385 //if (tex.equals("IMMORTAL"))
....@@ -8126,9 +8389,11 @@
81268389 //{
81278390 if (tex.equals("WHITE_NOISE"))
81288391 {
8129
- texture = textures.get(tex);
8130
- if (texture == null)
8131
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8392
+ texturecache = textures.get(tex);
8393
+ if (texturecache == null)
8394
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8395
+ else
8396
+ new Exception().printStackTrace();
81328397 } else
81338398 {
81348399 if (textureon)
....@@ -8153,7 +8418,7 @@
81538418 }
81548419
81558420 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
8156
- if (!new File(cachename).exists())
8421
+ if (!FileExists(cachename))
81578422 cachename = texname;
81588423 else
81598424 processbump = false; // don't process bump map again
....@@ -8175,7 +8440,7 @@
81758440 }
81768441
81778442 cachename = texname.substring(0, texname.length()-4)+ext+".png";
8178
- if (!new File(cachename).exists())
8443
+ if (!FileExists(cachename))
81798444 cachename = texname;
81808445 else
81818446 processbump = false; // don't process bump map again
....@@ -8187,19 +8452,20 @@
81878452 if (texturedata == null)
81888453 throw new Exception();
81898454
8190
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8455
+ texturecache = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
81918456 //texture = GetTexture(tex, bump);
81928457 }
81938458 }
81948459 //}
81958460 }
81968461
8197
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8462
+ if (/*CACHETEXTURE &&*/ texturecache != null && textureon)
81988463 {
81998464 //return false;
8465
+ assert(bim == null);
82008466
82018467 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8202
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8468
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
82038469 {
82048470 // String ext = "_highres";
82058471 // if (REDUCETEXTURE)
....@@ -8216,52 +8482,17 @@
82168482 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
82178483 if (!cachefile.exists())
82188484 {
8219
- // cache to disk
8220
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
8221
- //buffers[0].
8222
-
8223
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
8224
- int[] pixels = new int[bytebuf.capacity()/3];
8225
-
8226
- // squared size heuristic...
8227
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8485
+ //if (texturedata.getWidth() == texturedata.getHeight())
82288486 {
8229
- for (int i=pixels.length; --i>=0;)
8230
- {
8231
- int i3 = i*3;
8232
- pixels[i] = 0xFF;
8233
- pixels[i] <<= 8;
8234
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
8235
- pixels[i] <<= 8;
8236
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
8237
- pixels[i] <<= 8;
8238
- pixels[i] |= bytebuf.get(i3) & 0xFF;
8239
- }
8240
-
8241
- /*
8242
- int r=0,g=0,b=0,a=0;
8243
- for (int i=0; i<width; i++)
8244
- for (int j=0; j<height; j++)
8245
- {
8246
- int index = j*width+i;
8247
- int p = pixels[index];
8248
- a = ((p>>24) & 0xFF);
8249
- r = ((p>>16) & 0xFF);
8250
- g = ((p>>8) & 0xFF);
8251
- b = (p & 0xFF);
8252
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
8253
- }
8254
- /**/
8255
- int width = (int)Math.sqrt(pixels.length); // squared
8256
- int height = width;
8257
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
8258
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8487
+ BufferedImage rendImage = CreateBim(texturedata);
8488
+
82598489 ImageWriter writer = null;
82608490 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
82618491 if (iter.hasNext()) {
82628492 writer = (ImageWriter)iter.next();
82638493 }
8264
- float compressionQuality = 0.9f;
8494
+
8495
+ float compressionQuality = 0.85f;
82658496 try
82668497 {
82678498 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8288,8 +8519,8 @@
82888519 textures.remove(texname);
82898520 }
82908521
8291
- texture.texturedata = texturedata;
8292
- textures.put(texname, texture);
8522
+ //texture.texturedata = texturedata;
8523
+ textures.put(texname, texturecache);
82938524
82948525 // newtex = true;
82958526 }
....@@ -8305,12 +8536,17 @@
83058536 }
83068537 }
83078538
8308
- return texture;
8539
+ return texturecache;
83098540 }
83108541
8311
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution) throws Exception
8542
+ static void EmbedTextures(cTexture tex)
83128543 {
8313
- CacheTexture texture = GetCacheTexture(tex, bump, resolution);
8544
+
8545
+ }
8546
+
8547
+ com.sun.opengl.util.texture.Texture GetTexture(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception
8548
+ {
8549
+ CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution);
83148550
83158551 if (bump)
83168552 {
....@@ -8326,23 +8562,23 @@
83268562 return texture!=null?texture.texture:null;
83278563 }
83288564
8329
- public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution) throws Exception
8565
+ public com.sun.opengl.util.texture.TextureData GetTextureData(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception
83308566 {
8331
- CacheTexture texture = GetCacheTexture(tex, bump, resolution);
8567
+ CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution);
83328568
83338569 return texture!=null?texture.texturedata:null;
83348570 }
83358571
8336
- boolean BindTexture(String tex, boolean bump, int resolution) throws Exception
8572
+ boolean BindTexture(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception
83378573 {
83388574 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
83398575 {
83408576 return false;
83418577 }
83428578
8343
- boolean newtex = false;
8579
+ //boolean newtex = false;
83448580
8345
- com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
8581
+ com.sun.opengl.util.texture.Texture texture = GetTexture(stream, tex, bump, resolution);
83468582
83478583 if (texture == null)
83488584 return false;
....@@ -8372,7 +8608,7 @@
83728608 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
83738609 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
83748610
8375
- return newtex;
8611
+ return true; // Warning: not used.
83768612 }
83778613
83788614 ShadowBuffer shadowPBuf;
....@@ -9210,11 +9446,35 @@
92109446 jy8[3] = 0.5f;
92119447 }
92129448
9213
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9449
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
92149450 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
92159451 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
92169452 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
92179453
9454
+ void ResetOptions()
9455
+ {
9456
+ options1[0] = 100;
9457
+ options1[1] = 0.025f;
9458
+ options1[2] = 0.01f;
9459
+ options1[3] = 0;
9460
+ options1[4] = 0;
9461
+
9462
+ options2[0] = 0;
9463
+ options2[1] = 0.75f;
9464
+ options2[2] = 0;
9465
+ options2[3] = 0;
9466
+
9467
+ options3[0] = 1;
9468
+ options3[1] = 1;
9469
+ options3[2] = 1;
9470
+ options3[3] = 0;
9471
+
9472
+ options4[0] = 1;
9473
+ options4[1] = 0;
9474
+ options4[2] = 1;
9475
+ options4[3] = 0;
9476
+ }
9477
+
92189478 static int imagecount = 0; // movie generation
92199479
92209480 static int jitter = 0;
....@@ -9310,8 +9570,8 @@
93109570 assert (parentcam != renderCamera);
93119571
93129572 if (renderCamera != lightCamera)
9313
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9314
- LA.matConcat(matrix, parentcam.toParent, matrix);
9573
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9574
+ LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
93159575
93169576 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
93179577
....@@ -9326,8 +9586,8 @@
93269586 LA.matCopy(renderCamera.fromScreen, matrix);
93279587
93289588 if (renderCamera != lightCamera)
9329
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9330
- LA.matConcat(parentcam.fromParent, matrix, matrix);
9589
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9590
+ LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
93319591
93329592 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
93339593
....@@ -10325,6 +10585,7 @@
1032510585 ANTIALIAS = 0;
1032610586 //System.out.println("RESTART");
1032710587 AAtimer.restart();
10588
+ Globals.TIMERRUNNING = true;
1032810589 }
1032910590 }
1033010591 }
....@@ -10392,13 +10653,14 @@
1039210653 ambientOcclusion = false;
1039310654 }
1039410655
10395
- if (Globals.lighttouched && DrawMode() == DEFAULT && !lightMode) // && !FROZEN)
10656
+ if (//Globals.lighttouched &&
10657
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1039610658 {
1039710659 //if (RENDERSHADOW) // ?
1039810660 if (!IsFrozen())
1039910661 {
1040010662 // dec 2012
10401
- if (!ambientOcclusion && !(!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0))
10663
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
1040210664 {
1040310665 Globals.framecount++;
1040410666 shadowbuffer.display();
....@@ -10525,8 +10787,8 @@
1052510787
1052610788 // if (parentcam != renderCamera) // not a light
1052710789 if (cam != lightCamera)
10528
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10529
- LA.matConcat(matrix, parentcam.toParent, matrix);
10790
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10791
+ LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
1053010792
1053110793 for (int j = 0; j < 4; j++)
1053210794 {
....@@ -10540,8 +10802,8 @@
1054010802
1054110803 // if (parentcam != renderCamera) // not a light
1054210804 if (cam != lightCamera)
10543
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10544
- LA.matConcat(parentcam.fromParent, matrix, matrix);
10805
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10806
+ LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
1054510807
1054610808 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1054710809
....@@ -10803,7 +11065,7 @@
1080311065
1080411066 try
1080511067 {
10806
- BindTexture(NOISE_TEXTURE, false, 2);
11068
+ BindTexture(null, NOISE_TEXTURE, false, 2);
1080711069 }
1080811070 catch (Exception e)
1080911071 {
....@@ -10832,9 +11094,9 @@
1083211094
1083311095 gl.glMatrixMode(GL.GL_MODELVIEW);
1083411096
10835
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10836
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10837
-//gl.glEnable(gl.GL_MULTISAMPLE);
11097
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11098
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11099
+gl.glEnable(gl.GL_MULTISAMPLE);
1083811100 } else
1083911101 {
1084011102 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -10845,7 +11107,7 @@
1084511107 //System.out.println("BLENDING ON");
1084611108 gl.glEnable(GL.GL_BLEND);
1084711109 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
10848
-
11110
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1084911111 gl.glMatrixMode(gl.GL_PROJECTION);
1085011112 gl.glLoadIdentity();
1085111113
....@@ -10934,8 +11196,8 @@
1093411196 System.err.println("parentcam != renderCamera");
1093511197
1093611198 // if (cam != lightCamera)
10937
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10938
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11199
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11200
+ LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
1093911201 }
1094011202
1094111203 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -10956,8 +11218,8 @@
1095611218 if (true) // TODO
1095711219 {
1095811220 if (cam != lightCamera)
10959
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10960
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11221
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11222
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
1096111223 }
1096211224
1096311225 LA.xformPos(light0, cam.toScreen, light0);
....@@ -11302,15 +11564,36 @@
1130211564
1130311565 static boolean zoomonce = false;
1130411566
11567
+ static void CreateSelectedPoint()
11568
+ {
11569
+ if (selectedpoint == null)
11570
+ {
11571
+ debugpointG = new Sphere();
11572
+ debugpointP = new Sphere();
11573
+ debugpointC = new Sphere();
11574
+ debugpointR = new Sphere();
11575
+
11576
+ selectedpoint = new Superellipsoid();
11577
+
11578
+ for (int i=0; i<8; i++)
11579
+ {
11580
+ debugpoints[i] = new Sphere();
11581
+ }
11582
+ }
11583
+ }
11584
+
1130511585 void DrawObject(GL gl, boolean draw)
1130611586 {
11587
+ // To clear camera values
11588
+ ResetOptions();
11589
+
1130711590 //System.out.println("DRAW OBJECT " + mouseDown);
1130811591 // DrawMode() = SELECTION;
1130911592 //GL gl = getGL();
1131011593 if ((TRACK || SHADOWTRACK) || zoomonce)
1131111594 {
1131211595 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11313
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11596
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1131411597 pingthread.StepToTarget(true); // true);
1131511598 // zoomonce = false;
1131611599 }
....@@ -11382,8 +11665,9 @@
1138211665
1138311666 if (DrawMode() == DEFAULT)
1138411667 {
11385
- if (DEBUG)
11668
+ if (Globals.DEBUG)
1138611669 {
11670
+ CreateSelectedPoint();
1138711671 float radius = 0.05f;
1138811672 if (selectedpoint.radius != radius)
1138911673 {
....@@ -11446,7 +11730,7 @@
1144611730 if (tex.equals("WHITE_NOISE"))
1144711731 continue;
1144811732
11449
- if (!usedtextures.containsKey(tex))
11733
+ if (!usedtextures.contains(tex))
1145011734 {
1145111735 // System.out.println("DISPOSE +++++++++++++++ " + tex);
1145211736 textures.get(tex).texture.dispose();
....@@ -11552,7 +11836,7 @@
1155211836 return;
1155311837 }
1155411838
11555
- String string = obj.GetToolTip();
11839
+ String string = obj.toString(); //.GetToolTip();
1155611840
1155711841 GL gl = GetGL();
1155811842
....@@ -11869,8 +12153,8 @@
1186912153 //obj.TransformToWorld(light, light);
1187012154 for (int i = tp.size(); --i >= 0;)
1187112155 {
11872
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
11873
- LA.xformPos(light, tp.get(i).toParent, light);
12156
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12157
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1187412158 }
1187512159
1187612160
....@@ -11887,8 +12171,8 @@
1188712171 parentcam = cameras[0];
1188812172 }
1188912173
11890
- for (int count = parentcam.GetTransformCount(); --count>=0;)
11891
- LA.xformPos(light, parentcam.toParent, light); // may 2013
12174
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
12175
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1189212176
1189312177 LA.xformPos(light, renderCamera.toScreen, light);
1189412178
....@@ -12502,8 +12786,8 @@
1250212786
1250312787 // display shadow only (bump == 0)
1250412788 "SUB temp.x, half.x, shadow.x;" +
12505
- "MOV temp.y, -params6.x;" +
12506
- "SLT temp.z, temp.y, zero.x;" +
12789
+ "MOV temp.y, -params5.z;" + // params6.x;" +
12790
+ "SLT temp.z, temp.y, -one2048th.x;" +
1250712791 "SUB temp.y, one.x, temp.z;" +
1250812792 "MUL temp.x, temp.x, temp.y;" +
1250912793 "KIL temp.x;" +
....@@ -12834,7 +13118,7 @@
1283413118 //once = true;
1283513119 }
1283613120
12837
- System.out.print("Program #" + mode + "; length = " + program.length());
13121
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1283813122 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1283913123 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1284013124
....@@ -12967,12 +13251,16 @@
1296713251
1296813252 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1296913253 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13254
+
13255
+ // Compare fragment depth in light space with shadowmap.
1297013256 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1297113257 "SGE temp.y, temp.x, zero.x;" +
12972
- "SUB " + shadow + ".y, one.x, temp.y;" +
13258
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13259
+
13260
+ // Reverse comparison
1297313261 "SUB temp.x, one.x, temp.x;" +
1297413262 "MUL " + shadow + ".x, temp.x, temp.y;" +
12975
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13263
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1297613264 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1297713265
1297813266 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -12986,6 +13274,10 @@
1298613274 // No shadow for backface
1298713275 "DP3 temp.x, normal, lightd;" +
1298813276 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13277
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13278
+
13279
+ // No shadow when out of frustrum
13280
+ "SGE temp.x, " + depth + ".z, one.z;" +
1298913281 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1299013282 "";
1299113283 }
....@@ -13132,7 +13424,8 @@
1313213424 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1313313425 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1313413426 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13135
- Object3D.cVector2[] vector2buffer;
13427
+
13428
+ //Object3D.cVector2[] vector2buffer;
1313613429
1313713430 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1313813431 // OUT : diff, spec
....@@ -13148,9 +13441,10 @@
1314813441 "DP3 " + dest + ".z," + "normals," + "eye;" +
1314913442 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1315013443 //"MOV " + dest + ".w," + "normal.z;" +
13151
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
13152
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13153
- //"MOV " + dest + ".z," + "params2.w;" +
13444
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13445
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13446
+
13447
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1315413448 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1315513449 "RCP " + dest + ".w," + dest + ".w;" +
1315613450 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13655,6 +13949,7 @@
1365513949 else
1365613950 if (evt.getSource() == AAtimer)
1365713951 {
13952
+ Globals.TIMERRUNNING = false;
1365813953 if (mouseDown)
1365913954 {
1366013955 //new Exception().printStackTrace();
....@@ -13714,7 +14009,7 @@
1371414009
1371514010 // fev 2014???
1371614011 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13717
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14012
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1371814013 pingthread.StepToTarget(true); // true);
1371914014 }
1372014015 // if (!LIVE)
....@@ -13729,6 +14024,7 @@
1372914024 return;
1373014025
1373114026 AAtimer.restart(); //
14027
+ Globals.TIMERRUNNING = true;
1373214028
1373314029 // waslive = LIVE;
1373414030 // LIVE = false;
....@@ -13801,9 +14097,12 @@
1380114097
1380214098 public void mouseDragged(MouseEvent e)
1380314099 {
14100
+ Globals.MOUSEDRAGGED = true;
14101
+
1380414102 //System.out.println("mouseDragged: " + e);
1380514103 if (isRenderer)
1380614104 movingcamera = true;
14105
+
1380714106 //if (drawing)
1380814107 //return;
1380914108 if ((e.getModifiersEx() & CTRL) != 0
....@@ -14064,12 +14363,12 @@
1406414363 void GoDown(int mod)
1406514364 {
1406614365 MODIFIERS |= COMMAND;
14067
- /*
14366
+ /**/
1406814367 if((mod&SHIFT) == SHIFT)
1406914368 manipCamera.RotatePosition(0, -speed);
1407014369 else
14071
- manipCamera.BackForth(0, -speed*delta, getWidth());
14072
- */
14370
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14371
+ /**/
1407314372 if ((mod & SHIFT) == SHIFT)
1407414373 {
1407514374 mouseMode = mouseMode; // VR??
....@@ -14085,12 +14384,12 @@
1408514384 void GoUp(int mod)
1408614385 {
1408714386 MODIFIERS |= COMMAND;
14088
- /*
14387
+ /**/
1408914388 if((mod&SHIFT) == SHIFT)
1409014389 manipCamera.RotatePosition(0, speed);
1409114390 else
14092
- manipCamera.BackForth(0, speed*delta, getWidth());
14093
- */
14391
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14392
+ /**/
1409414393 if ((mod & SHIFT) == SHIFT)
1409514394 {
1409614395 mouseMode = mouseMode;
....@@ -14106,12 +14405,12 @@
1410614405 void GoLeft(int mod)
1410714406 {
1410814407 MODIFIERS |= COMMAND;
14109
- /*
14408
+ /**/
1411014409 if((mod&SHIFT) == SHIFT)
14111
- manipCamera.RotatePosition(speed, 0);
14112
- else
1411314410 manipCamera.Translate(speed*delta, 0, getWidth());
14114
- */
14411
+ else
14412
+ manipCamera.RotatePosition(speed, 0);
14413
+ /**/
1411514414 if ((mod & SHIFT) == SHIFT)
1411614415 {
1411714416 mouseMode = mouseMode;
....@@ -14127,12 +14426,12 @@
1412714426 void GoRight(int mod)
1412814427 {
1412914428 MODIFIERS |= COMMAND;
14130
- /*
14429
+ /**/
1413114430 if((mod&SHIFT) == SHIFT)
14132
- manipCamera.RotatePosition(-speed, 0);
14133
- else
1413414431 manipCamera.Translate(-speed*delta, 0, getWidth());
14135
- */
14432
+ else
14433
+ manipCamera.RotatePosition(-speed, 0);
14434
+ /**/
1413614435 if ((mod & SHIFT) == SHIFT)
1413714436 {
1413814437 mouseMode = mouseMode;
....@@ -14189,7 +14488,8 @@
1418914488 info.camera = renderCamera;
1419014489 info.x = x;
1419114490 info.y = y;
14192
- object.editWindow.copy.doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
14491
+ object.GetWindow().copy
14492
+ .doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1419314493 } else
1419414494 {
1419514495 if (x < startX)
....@@ -14353,7 +14653,9 @@
1435314653 ci.camera = renderCamera;
1435414654 if (!isRenderer)
1435514655 {
14356
- if (object.editWindow.copy.doEditClick(ci, 0))
14656
+ //ObjEditor editWindow = object.editWindow;
14657
+ //Object3D copy = editWindow.copy;
14658
+ if (object.doEditClick(ci, 0))
1435714659 {
1435814660 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1435914661 } else
....@@ -14365,7 +14667,11 @@
1436514667
1436614668 public void mouseReleased(MouseEvent e)
1436714669 {
14670
+ Globals.MOUSEDRAGGED = false;
14671
+
1436814672 movingcamera = false;
14673
+ X = 0; // getBounds().width/2;
14674
+ Y = 0; // getBounds().height/2;
1436914675 //System.out.println("mouseReleased: " + e);
1437014676 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1437114677 }
....@@ -14706,7 +15012,9 @@
1470615012 case 'E' : COMPACT ^= true;
1470715013 repaint();
1470815014 break;
14709
- case 'W' : DEBUGHSB ^= true;
15015
+ case 'W' : // Wide Window (fullscreen)
15016
+ //DEBUGHSB ^= true;
15017
+ ObjEditor.theFrame.ToggleFullScreen();
1471015018 repaint();
1471115019 break;
1471215020 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14731,8 +15039,8 @@
1473115039 RevertCamera();
1473215040 repaint();
1473315041 break;
14734
- case 'L':
1473515042 case 'l':
15043
+ //case 'L':
1473615044 if (lightMode)
1473715045 {
1473815046 lightMode = false;
....@@ -14875,9 +15183,9 @@
1487515183 case '_':
1487615184 kompactbit = 5;
1487715185 break;
14878
- case '+':
14879
- kompactbit = 6;
14880
- break;
15186
+// case '+':
15187
+// kompactbit = 6;
15188
+// break;
1488115189 case ' ':
1488215190 lightMode ^= true;
1488315191 Globals.lighttouched = true;
....@@ -14889,6 +15197,7 @@
1488915197 case ESC:
1489015198 RENDERPROGRAM += 1;
1489115199 RENDERPROGRAM %= 3;
15200
+
1489215201 repaint();
1489315202 break;
1489415203 case 'Z':
....@@ -14928,8 +15237,9 @@
1492815237 case DELETE:
1492915238 ClearSelection();
1493015239 break;
14931
- /*
1493215240 case '+':
15241
+
15242
+ /*
1493315243 //fontsize += 1;
1493415244 bbzoom *= 2;
1493515245 repaint();
....@@ -14946,17 +15256,17 @@
1494615256 case '=':
1494715257 IncDepth();
1494815258 //fontsize += 1;
14949
- object.editWindow.refreshContents(true);
15259
+ object.GetWindow().refreshContents(true);
1495015260 maskbit = 6;
1495115261 break;
1495215262 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1495315263 DecDepth();
1495415264 maskbit = 5;
1495515265 //if(fontsize > 1) fontsize -= 1;
14956
- if (object.editWindow == null)
14957
- new Exception().printStackTrace();
14958
- else
14959
- object.editWindow.refreshContents(true);
15266
+// if (object.editWindow == null)
15267
+// new Exception().printStackTrace();
15268
+// else
15269
+ object.GetWindow().refreshContents(true);
1496015270 break;
1496115271 case '{':
1496215272 manipCamera.shaper_fovy /= 1.1;
....@@ -15180,7 +15490,7 @@
1518015490 }
1518115491 */
1518215492
15183
- object.editWindow.EditSelection();
15493
+ object.GetWindow().EditSelection(false);
1518415494 }
1518515495
1518615496 void SelectParent()
....@@ -15197,10 +15507,10 @@
1519715507 {
1519815508 //selectees.remove(i);
1519915509 System.out.println("select parent of " + elem);
15200
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15510
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1520115511 } else
1520215512 {
15203
- group.editWindow.Select(elem.GetTreePath(), first, true);
15513
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1520415514 }
1520515515
1520615516 first = false;
....@@ -15242,12 +15552,12 @@
1524215552 for (int j = 0; j < group.children.size(); j++)
1524315553 {
1524415554 elem = (Object3D) group.children.elementAt(j);
15245
- object.editWindow.Select(elem.GetTreePath(), first, true);
15555
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1524615556 first = false;
1524715557 }
1524815558 } else
1524915559 {
15250
- object.editWindow.Select(elem.GetTreePath(), first, true);
15560
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1525115561 }
1525215562
1525315563 first = false;
....@@ -15258,21 +15568,21 @@
1525815568 {
1525915569 //Composite group = (Composite) object;
1526015570 Object3D group = object;
15261
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15571
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1526215572 }
1526315573
1526415574 void ResetTransform(int mask)
1526515575 {
1526615576 //Composite group = (Composite) object;
1526715577 Object3D group = object;
15268
- group.editWindow.ResetTransform(mask);
15578
+ group.GetWindow().ResetTransform(mask);
1526915579 }
1527015580
1527115581 void FlipTransform()
1527215582 {
1527315583 //Composite group = (Composite) object;
1527415584 Object3D group = object;
15275
- group.editWindow.FlipTransform();
15585
+ group.GetWindow().FlipTransform();
1527615586 // group.editWindow.ReduceMesh(true);
1527715587 }
1527815588
....@@ -15280,7 +15590,7 @@
1528015590 {
1528115591 //Composite group = (Composite) object;
1528215592 Object3D group = object;
15283
- group.editWindow.PrintMemory();
15593
+ group.GetWindow().PrintMemory();
1528415594 // group.editWindow.ReduceMesh(true);
1528515595 }
1528615596
....@@ -15288,7 +15598,7 @@
1528815598 {
1528915599 //Composite group = (Composite) object;
1529015600 Object3D group = object;
15291
- group.editWindow.ResetCentroid();
15601
+ group.GetWindow().ResetCentroid();
1529215602 }
1529315603
1529415604 void IncDepth()
....@@ -15374,7 +15684,9 @@
1537415684 info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1537515685 //Image img = CreateImage(width, height);
1537615686 //System.out.println("width = " + width + "; height = " + height + "\n");
15687
+
1537715688 Graphics gr = g; // img.getGraphics();
15689
+
1537815690 if (!hasMarquee)
1537915691 {
1538015692 if (Xmin < Xmax) // !locked)
....@@ -15462,6 +15774,7 @@
1546215774 info.bounds.y += (height - desired) / 2;
1546315775 }
1546415776 }
15777
+
1546515778 info.g = gr;
1546615779 info.camera = renderCamera;
1546715780 /*
....@@ -15471,15 +15784,55 @@
1547115784 */
1547215785 if (!isRenderer)
1547315786 {
15474
- object.drawEditHandles(info, 0);
15787
+ Grafreed.Assert(object != null);
15788
+ Grafreed.Assert(object.selection != null);
15789
+ if (object.selection.Size() > 0)
15790
+ {
15791
+ int hitSomething = object.selection.get(0).hitSomething;
15792
+
15793
+ info.DX = 0;
15794
+ info.DY = 0;
15795
+ info.W = 1;
15796
+ if (hitSomething == Object3D.hitCenter)
15797
+ {
15798
+ info.DX = X;
15799
+ if (X != 0)
15800
+ info.DX -= info.bounds.width/2;
15801
+
15802
+ info.DY = Y;
15803
+ if (Y != 0)
15804
+ info.DY -= info.bounds.height/2;
15805
+ }
15806
+
15807
+ object.drawEditHandles(info, 0);
15808
+
15809
+ if (drag && (X != 0 || Y != 0))
15810
+ {
15811
+ switch (hitSomething)
15812
+ {
15813
+ case Object3D.hitCenter: gr.setColor(Color.pink);
15814
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15815
+ break;
15816
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
15817
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15818
+ break;
15819
+ case Object3D.hitScale: gr.setColor(Color.cyan);
15820
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15821
+ break;
15822
+ }
15823
+
15824
+ }
15825
+ }
1547515826 }
1547615827 }
15828
+
1547715829 if (isRenderer)
1547815830 {
1547915831 //gr.setColor(Color.black);
1548015832 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1548115833 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1548215834 }
15835
+
1548315836 if (hasMarquee)
1548415837 {
1548515838 gr.setXORMode(Color.white);
....@@ -15886,7 +16239,7 @@
1588616239 Object3D object;
1588716240 static Object3D trackedobject;
1588816241 Camera renderCamera; // Light or Eye (or Occlusion)
15889
- /*static*/ Camera manipCamera; // Light or Eye
16242
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1589016243 /*static*/ Camera eyeCamera;
1589116244 /*static*/ Camera lightCamera;
1589216245 int cameracount;
....@@ -16171,16 +16524,16 @@
1617116524 cStatic.objectstack[materialdepth++] = checker;
1617216525 //System.out.println("material " + material);
1617316526 //Applet3D.tracein(this, selected);
16174
- vector2buffer = checker.projectedVertices;
16527
+ //vector2buffer = checker.projectedVertices;
1617516528
1617616529 //checker.GetMaterial().Draw(this, false); // true);
16177
- DrawMaterial(checker.GetMaterial(), false); // true);
16530
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1617816531
1617916532 materialdepth -= 1;
1618016533 if (materialdepth > 0)
1618116534 {
16182
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16183
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
16535
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16536
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1618416537 }
1618516538 //checker.GetMaterial().opacity = 1f;
1618616539 ////checker.GetMaterial().ambient = 1f;
....@@ -16266,6 +16619,14 @@
1626616619 }
1626716620 }
1626816621
16622
+ private Object3D GetFolder()
16623
+ {
16624
+ Object3D folder = object.GetWindow().copy;
16625
+ if (object.GetWindow().copy.selection.Size() > 0)
16626
+ folder = object.GetWindow().copy.selection.elementAt(0);
16627
+ return folder;
16628
+ }
16629
+
1626916630 class SelectBuffer implements GLEventListener
1627016631 {
1627116632
....@@ -16345,6 +16706,17 @@
1634516706
1634616707 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1634716708
16709
+ if (PAINTMODE)
16710
+ {
16711
+ if (object.GetWindow().copy.selection.Size() > 0)
16712
+ {
16713
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16714
+
16715
+ // Make what you paint not selectable.
16716
+ paintobj.ResetSelectable();
16717
+ }
16718
+ }
16719
+
1634816720 //int tmp = selection_view;
1634916721 //selection_view = -1;
1635016722 int temp = DrawMode();
....@@ -16356,6 +16728,17 @@
1635616728 // temp = DEFAULT; // patch for selection debug
1635716729 Globals.drawMode = temp; // WARNING
1635816730
16731
+ if (PAINTMODE)
16732
+ {
16733
+ if (object.GetWindow().copy.selection.Size() > 0)
16734
+ {
16735
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16736
+
16737
+ // Revert.
16738
+ paintobj.RestoreSelectable();
16739
+ }
16740
+ }
16741
+
1635916742 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1636016743
1636116744 // trying different ways of getting the depth info over
....@@ -16403,6 +16786,8 @@
1640316786 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1640416787 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1640516788 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
16789
+
16790
+ CreateSelectedPoint();
1640616791
1640716792 // Will fit the mesh !!!
1640816793 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16457,29 +16842,31 @@
1645716842 }
1645816843
1645916844 if (!movingcamera && !PAINTMODE)
16460
- object.editWindow.ScreenFitPoint(); // fev 2014
16845
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1646116846
16462
- if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
16847
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1646316848 {
16464
- Object3D paintobj = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
16849
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1646516850
16466
- Object3D group = new Object3D("inst" + paintcount++);
16851
+ if (object.GetWindow().copy.selection.Size() > 0)
16852
+ {
16853
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1646716854
16468
- group.CreateMaterial(); // use a void leaf to select instances
16469
-
16470
- group.add(paintobj); // link
16471
-
16472
- object.editWindow.SnapObject(group);
16473
-
16474
- Object3D folder = object.editWindow.copy;
16475
-
16476
- if (object.editWindow.copy.selection.Size() > 0)
16477
- folder = object.editWindow.copy.selection.elementAt(0);
16478
-
16479
- folder.add(group);
16480
-
16481
- object.editWindow.ResetModel();
16482
- object.editWindow.refreshContents();
16855
+ Object3D inst = new Object3D("inst" + paintcount++);
16856
+
16857
+ inst.CreateMaterial(); // use a void leaf to select instances
16858
+
16859
+ inst.add(paintobj); // link
16860
+
16861
+ object.GetWindow().SnapObject(inst);
16862
+
16863
+ Object3D folder = paintFolder; // GetFolder();
16864
+
16865
+ folder.add(inst);
16866
+
16867
+ object.GetWindow().ResetModel();
16868
+ object.GetWindow().refreshContents();
16869
+ }
1648316870 }
1648416871 else
1648516872 paintcount = 0;
....@@ -16518,6 +16905,11 @@
1651816905 //System.out.println("objects[color] = " + objects[color]);
1651916906 //objects[color].Select();
1652016907 indexcount = 0;
16908
+ ObjEditor window = object.GetWindow();
16909
+ if (window != null && deselect)
16910
+ {
16911
+ window.Select(null, deselect, true);
16912
+ }
1652116913 object.Select(color, deselect);
1652216914 }
1652316915
....@@ -17043,23 +17435,15 @@
1704317435 int AAbuffersize = 0;
1704417436
1704517437 //double[] selectedpoint = new double[3];
17046
- static Superellipsoid selectedpoint = new Superellipsoid();
17438
+ static Superellipsoid selectedpoint;
1704717439 static Sphere previousselectedpoint = null;
17048
- static Sphere debugpointG = new Sphere();
17049
- static Sphere debugpointP = new Sphere();
17050
- static Sphere debugpointC = new Sphere();
17051
- static Sphere debugpointR = new Sphere();
17440
+ static Sphere debugpointG;
17441
+ static Sphere debugpointP;
17442
+ static Sphere debugpointC;
17443
+ static Sphere debugpointR;
1705217444
1705317445 static Sphere debugpoints[] = new Sphere[8];
1705417446
17055
- static
17056
- {
17057
- for (int i=0; i<8; i++)
17058
- {
17059
- debugpoints[i] = new Sphere();
17060
- }
17061
- }
17062
-
1706317447 static void InitPoints(float radius)
1706417448 {
1706517449 for (int i=0; i<8; i++)