Normand Briere
2019-07-27 1af7d3700724834e40ad8636bc9a56cdc3b19b15
CameraPane.java
....@@ -18,7 +18,10 @@
1818 import javax.imageio.ImageIO;
1919 import javax.imageio.ImageWriteParam;
2020 import javax.imageio.ImageWriter;
21
+import javax.imageio.ImageReadParam;
22
+import javax.imageio.ImageReader;
2123 import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
24
+import javax.imageio.stream.ImageInputStream;
2225 import javax.imageio.stream.ImageOutputStream;
2326 import javax.imageio.ImageWriteParam;
2427
....@@ -30,6 +33,7 @@
3033 import java.nio.*;
3134
3235 import gleem.linalg.Mat4f;
36
+import javax.imageio.ImageTypeSpecifier;
3337
3438 class CameraPane extends GLCanvas implements iCameraPane, Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener
3539 {
....@@ -37,7 +41,6 @@
3741 static boolean[] selectedstack = new boolean[65536];
3842 static int materialdepth = 0;
3943
40
- static boolean DEBUG = false;
4144 static boolean FRUSTUM = false; // still bogus true; // frustum culling
4245
4346 // camera change fix
....@@ -45,6 +48,39 @@
4548 static boolean ABORTED = false;
4649
4750 static int STEP = 1;
51
+
52
+ private static BufferedImage CreateBim(byte[] bytes, int width, int height)
53
+ {
54
+ int[] pixels = new int[bytes.length/3];
55
+ for (int i=pixels.length; --i>=0;)
56
+ {
57
+ int i3 = i*3;
58
+ pixels[i] = 0xFF;
59
+ pixels[i] <<= 8;
60
+ pixels[i] |= bytes[i3+2] & 0xFF;
61
+ pixels[i] <<= 8;
62
+ pixels[i] |= bytes[i3+1] & 0xFF;
63
+ pixels[i] <<= 8;
64
+ pixels[i] |= bytes[i3] & 0xFF;
65
+ }
66
+ /*
67
+ int r=0,g=0,b=0,a=0;
68
+ for (int i=0; i<width; i++)
69
+ for (int j=0; j<height; j++)
70
+ {
71
+ int index = j*width+i;
72
+ int p = pixels[index];
73
+ a = ((p>>24) & 0xFF);
74
+ r = ((p>>16) & 0xFF);
75
+ g = ((p>>8) & 0xFF);
76
+ b = (p & 0xFF);
77
+ pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
78
+ }
79
+ /**/
80
+ BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
81
+ rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
82
+ return rendImage;
83
+ }
4884
4985 /*static*/ private boolean CULLFACE = false; // true;
5086 /*static*/ boolean NEAREST = false; // true;
....@@ -61,7 +97,7 @@
6197 //boolean REDUCETEXTURE = true;
6298 boolean CACHETEXTURE = true;
6399 boolean CLEANCACHE = false; // true;
64
- boolean MIPMAP = false; // true;
100
+ boolean MIPMAP = false; // true; // never works...
65101 boolean COMPRESSTEXTURE = false;
66102 boolean KOMPACTTEXTURE = false; // true;
67103 boolean RESIZETEXTURE = false;
....@@ -170,7 +206,8 @@
170206
171207 SetCamera(cam);
172208
173
- SetLight(new Camera(new cVector(10, 10, -20)));
209
+ // Warning: not used.
210
+ SetLight(new Camera(new cVector(15, 10, -20)));
174211
175212 object = o;
176213
....@@ -327,7 +364,7 @@
327364 cStatic.objectstack[materialdepth++] = obj;
328365 //System.out.println("material " + material);
329366 //Applet3D.tracein(this, selected);
330
- display.vector2buffer = obj.projectedVertices;
367
+ //display.vector2buffer = obj.projectedVertices;
331368 if (obj instanceof Camera)
332369 {
333370 display.options1[0] = material.shift;
....@@ -336,14 +373,28 @@
336373 display.options1[2] = material.shadowbias;
337374 display.options1[3] = material.aniso;
338375 display.options1[4] = material.anisoV;
376
+// System.out.println("display.options1[0] " + display.options1[0]);
377
+// System.out.println("display.options1[1] " + display.options1[1]);
378
+// System.out.println("display.options1[2] " + display.options1[2]);
379
+// System.out.println("display.options1[3] " + display.options1[3]);
380
+// System.out.println("display.options1[4] " + display.options1[4]);
339381 display.options2[0] = material.opacity;
340382 display.options2[1] = material.diffuse;
341383 display.options2[2] = material.factor;
384
+// System.out.println("display.options2[0] " + display.options2[0]);
385
+// System.out.println("display.options2[1] " + display.options2[1]);
386
+// System.out.println("display.options2[2] " + display.options2[2]);
342387
343388 cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
389
+// System.out.println("display.options3[0] " + display.options3[0]);
390
+// System.out.println("display.options3[1] " + display.options3[1]);
391
+// System.out.println("display.options3[2] " + display.options3[2]);
344392 display.options4[0] = material.cameralight/0.2f;
345393 display.options4[1] = material.subsurface;
346394 display.options4[2] = material.sheen;
395
+// System.out.println("display.options4[0] " + display.options4[0]);
396
+// System.out.println("display.options4[1] " + display.options4[1]);
397
+// System.out.println("display.options4[2] " + display.options4[2]);
347398
348399 // if (display.CURRENTANTIALIAS > 0)
349400 // display.options3[3] /= 4;
....@@ -359,7 +410,7 @@
359410 /**/
360411 } else
361412 {
362
- DrawMaterial(material, selected);
413
+ DrawMaterial(material, selected, obj.projectedVertices);
363414 }
364415 } else
365416 {
....@@ -383,8 +434,8 @@
383434 cStatic.objectstack[materialdepth++] = obj;
384435 //System.out.println("material " + material);
385436 //Applet3D.tracein("selected ", selected);
386
- display.vector2buffer = obj.projectedVertices;
387
- display.DrawMaterial(material, selected);
437
+ //display.vector2buffer = obj.projectedVertices;
438
+ display.DrawMaterial(material, selected, obj.projectedVertices);
388439 }
389440 }
390441
....@@ -401,8 +452,8 @@
401452 materialdepth -= 1;
402453 if (materialdepth > 0)
403454 {
404
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
405
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
455
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
456
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
406457 }
407458 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
408459 } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
....@@ -422,8 +473,8 @@
422473 materialdepth -= 1;
423474 if (materialdepth > 0)
424475 {
425
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
426
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
476
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
477
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
427478 }
428479 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
429480 //else
....@@ -464,10 +515,12 @@
464515 if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
465516 {
466517 //gl.glBegin(gl.GL_TRIANGLES);
467
- boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0);
518
+ boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0)
519
+ // TEST LIVE NORMALS && !obj.dontselect
520
+ ;
468521 if (!hasnorm)
469522 {
470
- // System.out.println("FUCK!!");
523
+ // System.out.println("Mesh normal");
471524 LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
472525 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
473526 LA.vecCross(obj.v0, obj.v1, obj.v2);
....@@ -1192,10 +1245,12 @@
11921245 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
11931246 }
11941247 }
1248
+
11951249 if (flipV)
11961250 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
11971251 else
11981252 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1253
+
11991254 //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
12001255 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
12011256
....@@ -1215,10 +1270,12 @@
12151270 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
12161271 }
12171272 }
1273
+
12181274 if (flipV)
12191275 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12201276 else
12211277 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1278
+
12221279 //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
12231280 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
12241281
....@@ -1246,8 +1303,10 @@
12461303 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12471304 else
12481305 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1306
+
12491307 //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
12501308 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1309
+
12511310 count2 += 2;
12521311 count3 += 3;
12531312 }
....@@ -1603,7 +1662,7 @@
16031662 // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
16041663 }
16051664
1606
- void DrawMaterial(cMaterial material, boolean selected)
1665
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
16071666 {
16081667 CameraPane display = this;
16091668 //new Exception().printStackTrace();
....@@ -1638,7 +1697,7 @@
16381697 colorV[0] = display.modelParams0[0] * material.diffuse;
16391698 colorV[1] = display.modelParams0[1] * material.diffuse;
16401699 colorV[2] = display.modelParams0[2] * material.diffuse;
1641
- colorV[3] = material.opacity;
1700
+ colorV[3] = 1; // material.opacity;
16421701
16431702 gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
16441703 //System.out.println("Opacity = " + opacity);
....@@ -1746,9 +1805,9 @@
17461805 display.modelParams7[2] = 0;
17471806 display.modelParams7[3] = 0;
17481807
1749
- display.modelParams6[0] = 100; // criss de bug de bump
1808
+ //display.modelParams6[0] = 100; // criss de bug de bump
17501809
1751
- Object3D.cVector2[] extparams = display.vector2buffer;
1810
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
17521811 if (extparams != null && extparams.length > 0 && extparams[0] != null)
17531812 {
17541813 display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
....@@ -2044,7 +2103,7 @@
20442103 //System.err.println("Oeil on");
20452104 OEIL = true;
20462105 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2047
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2106
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
20482107 //pingthread.StepToTarget(true);
20492108 }
20502109
....@@ -2259,7 +2318,7 @@
22592318
22602319 void ToggleDebug()
22612320 {
2262
- DEBUG ^= true;
2321
+ Globals.DEBUG ^= true;
22632322 }
22642323
22652324 void ToggleLookAt()
....@@ -2277,10 +2336,17 @@
22772336 HANDLES ^= true;
22782337 }
22792338
2339
+ Object3D paintFolder;
2340
+
22802341 void TogglePaint()
22812342 {
22822343 PAINTMODE ^= true;
22832344 paintcount = 0;
2345
+
2346
+ if (PAINTMODE)
2347
+ {
2348
+ paintFolder = GetFolder();
2349
+ }
22842350 }
22852351
22862352 void SwapCamera(int a, int b)
....@@ -2377,6 +2443,21 @@
23772443 return currentGL;
23782444 }
23792445
2446
+ static private BufferedImage CreateBim(TextureData texturedata)
2447
+ {
2448
+ Grafreed.Assert(texturedata != null);
2449
+
2450
+ int width = texturedata.getWidth();
2451
+ int height = texturedata.getHeight();
2452
+
2453
+ Buffer buffer = texturedata.getBuffer();
2454
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2455
+
2456
+ byte[] bytes = bytebuf.array();
2457
+
2458
+ return CreateBim(bytes, width, height);
2459
+ }
2460
+
23802461 /**/
23812462 class CacheTexture
23822463 {
....@@ -2385,28 +2466,31 @@
23852466
23862467 int resolution;
23872468
2388
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2469
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
23892470 {
2390
- texture = tex;
2471
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2472
+ texturedata = texdata;
23912473 resolution = res;
23922474 }
23932475 }
23942476 /**/
23952477
23962478 // 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>();
2479
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2480
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2481
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2482
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2483
+
24002484 int pigmentdepth = 0;
24012485 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
24022486 int bumpdepth = 0;
24032487 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
24042488 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
24052489 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2406
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2490
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
24072491 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
24082492
2409
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2493
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
24102494 {
24112495 TextureData texturedata = null;
24122496
....@@ -2425,13 +2509,34 @@
24252509 if (bump)
24262510 texturedata = ConvertBump(texturedata, false);
24272511
2428
- com.sun.opengl.util.texture.Texture texture =
2429
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2512
+// com.sun.opengl.util.texture.Texture texture =
2513
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
24302514
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);
2515
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2516
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
24332517
2434
- return texture;
2518
+ return texturedata;
2519
+ }
2520
+
2521
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2522
+ {
2523
+ TextureData texturedata = null;
2524
+
2525
+ try
2526
+ {
2527
+ texturedata =
2528
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2529
+ bim,
2530
+ true);
2531
+ } catch (Exception e)
2532
+ {
2533
+ throw new javax.media.opengl.GLException(e);
2534
+ }
2535
+
2536
+ if (bump)
2537
+ texturedata = ConvertBump(texturedata, false);
2538
+
2539
+ return texturedata;
24352540 }
24362541
24372542 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3504,6 +3609,8 @@
35043609
35053610 System.out.println("LOADING TEXTURE : " + name);
35063611
3612
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3613
+
35073614 //
35083615 if (false) // compressbit > 0)
35093616 {
....@@ -7902,7 +8009,7 @@
79028009 String pigment = Object3D.GetPigment(tex);
79038010 String bump = Object3D.GetBump(tex);
79048011
7905
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8012
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79068013 {
79078014 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79088015 // System.out.println("; bump = " + bump);
....@@ -7917,11 +8024,69 @@
79178024 pigment = null;
79188025 }
79198026
7920
- ReleaseTexture(bump, true);
7921
- ReleaseTexture(pigment, false);
8027
+ ReleaseTexture(tex, true);
8028
+ ReleaseTexture(tex, false);
79228029 }
79238030
7924
- void ReleaseTexture(String tex, boolean bump)
8031
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
8032
+ {
8033
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8034
+ {
8035
+ return;
8036
+ }
8037
+
8038
+ if (tex == null)
8039
+ {
8040
+ ReleaseTexture(null, false);
8041
+ return;
8042
+ }
8043
+
8044
+ String pigment = Object3D.GetPigment(tex);
8045
+
8046
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8047
+ {
8048
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8049
+ // System.out.println("; bump = " + bump);
8050
+ }
8051
+
8052
+ if (pigment.equals(""))
8053
+ {
8054
+ pigment = null;
8055
+ }
8056
+
8057
+ ReleaseTexture(tex, false);
8058
+ }
8059
+
8060
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
8061
+ {
8062
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8063
+ {
8064
+ return;
8065
+ }
8066
+
8067
+ if (tex == null)
8068
+ {
8069
+ ReleaseTexture(null, true);
8070
+ return;
8071
+ }
8072
+
8073
+ String bump = Object3D.GetBump(tex);
8074
+
8075
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8076
+ {
8077
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8078
+ // System.out.println("; bump = " + bump);
8079
+ }
8080
+
8081
+ if (bump.equals(""))
8082
+ {
8083
+ bump = null;
8084
+ }
8085
+
8086
+ ReleaseTexture(tex, true);
8087
+ }
8088
+
8089
+ void ReleaseTexture(cTexture tex, boolean bump)
79258090 {
79268091 if (// DrawMode() != 0 || /*tex == null ||*/
79278092 ambientOcclusion ) // || !textureon)
....@@ -7932,7 +8097,7 @@
79328097 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
79338098
79348099 if (tex != null)
7935
- texture = textures.get(tex);
8100
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
79368101
79378102 // //assert( texture != null );
79388103 // if (texture == null)
....@@ -8026,6 +8191,54 @@
80268191
80278192 /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
80288193 {
8194
+// if (// DrawMode() != 0 || /*tex == null ||*/
8195
+// ambientOcclusion ) // || !textureon)
8196
+// {
8197
+// return; // false;
8198
+// }
8199
+//
8200
+// if (tex == null)
8201
+// {
8202
+// BindTexture(null,false,resolution);
8203
+// BindTexture(null,true,resolution);
8204
+// return;
8205
+// }
8206
+//
8207
+// String pigment = Object3D.GetPigment(tex);
8208
+// String bump = Object3D.GetBump(tex);
8209
+//
8210
+// usedtextures.add(pigment);
8211
+// usedtextures.add(bump);
8212
+//
8213
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8214
+// {
8215
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8216
+// // System.out.println("; bump = " + bump);
8217
+// }
8218
+//
8219
+// if (bump.equals(""))
8220
+// {
8221
+// bump = null;
8222
+// }
8223
+// if (pigment.equals(""))
8224
+// {
8225
+// pigment = null;
8226
+// }
8227
+//
8228
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8229
+// BindTexture(pigment, false, resolution);
8230
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8231
+// BindTexture(bump, true, resolution);
8232
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8233
+//
8234
+// return; // true;
8235
+
8236
+ BindPigmentTexture(tex, resolution);
8237
+ BindBumpTexture(tex, resolution);
8238
+ }
8239
+
8240
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8241
+ {
80298242 if (// DrawMode() != 0 || /*tex == null ||*/
80308243 ambientOcclusion ) // || !textureon)
80318244 {
....@@ -8035,17 +8248,47 @@
80358248 if (tex == null)
80368249 {
80378250 BindTexture(null,false,resolution);
8038
- BindTexture(null,true,resolution);
80398251 return;
80408252 }
80418253
80428254 String pigment = Object3D.GetPigment(tex);
8255
+
8256
+ usedtextures.add(tex);
8257
+
8258
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8259
+ {
8260
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8261
+ // System.out.println("; bump = " + bump);
8262
+ }
8263
+
8264
+ if (pigment.equals(""))
8265
+ {
8266
+ pigment = null;
8267
+ }
8268
+
8269
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8270
+ BindTexture(tex, false, resolution);
8271
+ }
8272
+
8273
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8274
+ {
8275
+ if (// DrawMode() != 0 || /*tex == null ||*/
8276
+ ambientOcclusion ) // || !textureon)
8277
+ {
8278
+ return; // false;
8279
+ }
8280
+
8281
+ if (tex == null)
8282
+ {
8283
+ BindTexture(null,true,resolution);
8284
+ return;
8285
+ }
8286
+
80438287 String bump = Object3D.GetBump(tex);
80448288
8045
- usedtextures.put(pigment, pigment);
8046
- usedtextures.put(bump, bump);
8289
+ usedtextures.add(tex);
80478290
8048
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8291
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
80498292 {
80508293 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
80518294 // System.out.println("; bump = " + bump);
....@@ -8055,18 +8298,10 @@
80558298 {
80568299 bump = null;
80578300 }
8058
- if (pigment.equals(""))
8059
- {
8060
- pigment = null;
8061
- }
80628301
8063
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8064
- BindTexture(pigment, false, resolution);
80658302 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8066
- BindTexture(bump, true, resolution);
8303
+ BindTexture(tex, true, resolution);
80678304 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8068
-
8069
- return; // true;
80708305 }
80718306
80728307 java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
....@@ -8089,13 +8324,19 @@
80898324 return fileExists;
80908325 }
80918326
8092
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception
8327
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
80938328 {
8094
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8329
+ CacheTexture texturecache = null;
80958330
80968331 if (tex != null)
80978332 {
8098
- String texname = tex;
8333
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8334
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
8335
+
8336
+ if (texname.equals("") && texdata == null)
8337
+ {
8338
+ return null;
8339
+ }
80998340
81008341 String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
81018342
....@@ -8105,19 +8346,46 @@
81058346 // else
81068347 // if (!texname.startsWith("/"))
81078348 // texname = "/Users/nbriere/Textures/" + texname;
8108
- if (!FileExists(tex))
8349
+ if (!FileExists(texname))
81098350 {
81108351 texname = fallbackTextureName;
81118352 }
81128353
81138354 if (CACHETEXTURE)
8114
- texture = textures.get(texname); // TEXTURE CACHE
8115
-
8116
- TextureData texturedata = null;
8117
-
8118
- if (texture == null || texture.resolution < resolution)
81198355 {
8120
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8356
+ if (texdata == null)
8357
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8358
+ else
8359
+ texturecache = bimtextures.get(texdata);
8360
+ }
8361
+
8362
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8363
+ {
8364
+ TextureData texturedata = null;
8365
+
8366
+ if (texdata != null && textureon)
8367
+ {
8368
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8369
+
8370
+ try
8371
+ {
8372
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8373
+ }
8374
+ catch (Exception e)
8375
+ {
8376
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8377
+ }
8378
+
8379
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8380
+ bimtextures.put(texdata, texturecache);
8381
+
8382
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8383
+
8384
+ //Object bim2 = CreateBim(texturecache.texturedata);
8385
+ //bim2 = bim;
8386
+ }
8387
+ else
8388
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
81218389 {
81228390 assert(!bump);
81238391 // if (bump)
....@@ -8128,19 +8396,23 @@
81288396 // }
81298397 // else
81308398 // {
8131
- texture = textures.get(tex);
8132
- if (texture == null)
8399
+ // texturecache = textures.get(texname); // suspicious
8400
+ if (texturecache == null)
81338401 {
8134
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8402
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
81358403 }
8404
+ else
8405
+ new Exception().printStackTrace();
81368406 // }
81378407 } else
8138
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8408
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
81398409 {
81408410 assert(bump);
8141
- texture = textures.get(tex);
8142
- if (texture == null)
8143
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8411
+ // texturecache = textures.get(texname); // suspicious
8412
+ if (texturecache == null)
8413
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8414
+ else
8415
+ new Exception().printStackTrace();
81448416 } else
81458417 {
81468418 //if (tex.equals("IMMORTAL"))
....@@ -8148,11 +8420,13 @@
81488420 // texture = GetResourceTexture("default.png");
81498421 //} else
81508422 //{
8151
- if (tex.equals("WHITE_NOISE"))
8423
+ if (texname.endsWith("WHITE_NOISE"))
81528424 {
8153
- texture = textures.get(tex);
8154
- if (texture == null)
8155
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8425
+ // texturecache = textures.get(texname); // suspicious
8426
+ if (texturecache == null)
8427
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8428
+ else
8429
+ new Exception().printStackTrace();
81568430 } else
81578431 {
81588432 if (textureon)
....@@ -8211,19 +8485,19 @@
82118485 if (texturedata == null)
82128486 throw new Exception();
82138487
8214
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8488
+ texturecache = new CacheTexture(texturedata,resolution);
82158489 //texture = GetTexture(tex, bump);
82168490 }
82178491 }
82188492 //}
82198493 }
82208494
8221
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8495
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
82228496 {
82238497 //return false;
82248498
82258499 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8226
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8500
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
82278501 {
82288502 // String ext = "_highres";
82298503 // if (REDUCETEXTURE)
....@@ -8240,52 +8514,17 @@
82408514 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
82418515 if (!cachefile.exists())
82428516 {
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))
8517
+ //if (texturedata.getWidth() == texturedata.getHeight())
82528518 {
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);
8519
+ BufferedImage rendImage = CreateBim(texturedata);
8520
+
82838521 ImageWriter writer = null;
82848522 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
82858523 if (iter.hasNext()) {
82868524 writer = (ImageWriter)iter.next();
82878525 }
8288
- float compressionQuality = 0.9f;
8526
+
8527
+ float compressionQuality = 0.85f;
82898528 try
82908529 {
82918530 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8302,18 +8541,20 @@
83028541 }
83038542 }
83048543 }
8305
-
8544
+
8545
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8546
+
83068547 //System.out.println("Texture = " + tex);
8307
- if (textures.containsKey(texname))
8548
+ if (textures.containsKey(tex))
83088549 {
8309
- CacheTexture thetex = textures.get(texname);
8550
+ CacheTexture thetex = textures.get(tex);
83108551 thetex.texture.disable();
83118552 thetex.texture.dispose();
8312
- textures.remove(texname);
8553
+ textures.remove(tex);
83138554 }
83148555
8315
- texture.texturedata = texturedata;
8316
- textures.put(texname, texture);
8556
+ //texture.texturedata = texturedata;
8557
+ textures.put(tex, texturecache);
83178558
83188559 // newtex = true;
83198560 }
....@@ -8329,10 +8570,44 @@
83298570 }
83308571 }
83318572
8332
- return texture;
8573
+ return texturecache;
83338574 }
83348575
8335
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution) throws Exception
8576
+ static void EmbedTextures(cTexture tex)
8577
+ {
8578
+ if (tex.pigmentdata == null)
8579
+ {
8580
+ //String texname = Object3D.GetPigment(tex);
8581
+
8582
+ CacheTexture texturecache = texturepigment.get(tex);
8583
+
8584
+ if (texturecache != null)
8585
+ {
8586
+ tex.pw = texturecache.texturedata.getWidth();
8587
+ tex.ph = texturecache.texturedata.getHeight();
8588
+ tex.pigmentdata = //CompressJPEG(CreateBim
8589
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8590
+ ;
8591
+ //, tex.pw, tex.ph), 0.5f);
8592
+ }
8593
+ }
8594
+
8595
+ if (tex.bumpdata == null)
8596
+ {
8597
+ //String texname = Object3D.GetBump(tex);
8598
+
8599
+ CacheTexture texturecache = texturebump.get(tex);
8600
+
8601
+ if (texturecache != null)
8602
+ {
8603
+ tex.bw = texturecache.texturedata.getWidth();
8604
+ tex.bh = texturecache.texturedata.getHeight();
8605
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8606
+ }
8607
+ }
8608
+ }
8609
+
8610
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
83368611 {
83378612 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
83388613
....@@ -8350,21 +8625,21 @@
83508625 return texture!=null?texture.texture:null;
83518626 }
83528627
8353
- public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution) throws Exception
8628
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
83548629 {
83558630 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
83568631
83578632 return texture!=null?texture.texturedata:null;
83588633 }
83598634
8360
- boolean BindTexture(String tex, boolean bump, int resolution) throws Exception
8635
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
83618636 {
83628637 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
83638638 {
83648639 return false;
83658640 }
83668641
8367
- boolean newtex = false;
8642
+ //boolean newtex = false;
83688643
83698644 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
83708645
....@@ -8396,9 +8671,75 @@
83968671 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
83978672 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
83988673
8399
- return newtex;
8674
+ return true; // Warning: not used.
84008675 }
84018676
8677
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8678
+ {
8679
+ try
8680
+ {
8681
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8682
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8683
+ ImageWriter writer = writers.next();
8684
+
8685
+ ImageWriteParam param = writer.getDefaultWriteParam();
8686
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8687
+ param.setCompressionQuality(quality);
8688
+
8689
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8690
+ writer.setOutput(ios);
8691
+ writer.write(null, new IIOImage(image, null, null), param);
8692
+
8693
+ byte[] data = baos.toByteArray();
8694
+ writer.dispose();
8695
+ return data;
8696
+ }
8697
+ catch (Exception e)
8698
+ {
8699
+ e.printStackTrace();
8700
+ return null;
8701
+ }
8702
+ }
8703
+
8704
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8705
+ {
8706
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8707
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8708
+ ImageReader reader = writers.next();
8709
+
8710
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8711
+
8712
+ ImageReadParam param = reader.getDefaultReadParam();
8713
+ param.setDestination(bim);
8714
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8715
+
8716
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8717
+ reader.setInput(ios);
8718
+ BufferedImage bim2 = reader.read(0, param);
8719
+ reader.dispose();
8720
+
8721
+// WritableRaster raster = bim2.getRaster();
8722
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8723
+// byte[] bytes = data.getData();
8724
+//
8725
+// int[] pixels = new int[bytes.length/3];
8726
+// for (int i=pixels.length; --i>=0;)
8727
+// {
8728
+// int i3 = i*3;
8729
+// pixels[i] = 0xFF;
8730
+// pixels[i] <<= 8;
8731
+// pixels[i] |= bytes[i3+2] & 0xFF;
8732
+// pixels[i] <<= 8;
8733
+// pixels[i] |= bytes[i3+1] & 0xFF;
8734
+// pixels[i] <<= 8;
8735
+// pixels[i] |= bytes[i3] & 0xFF;
8736
+// }
8737
+//
8738
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8739
+
8740
+ return bim;
8741
+ }
8742
+
84028743 ShadowBuffer shadowPBuf;
84038744 AntialiasBuffer antialiasPBuf;
84048745 int MAXSTACK;
....@@ -9234,11 +9575,35 @@
92349575 jy8[3] = 0.5f;
92359576 }
92369577
9237
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9578
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
92389579 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
92399580 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
92409581 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
92419582
9583
+ void ResetOptions()
9584
+ {
9585
+ options1[0] = 100;
9586
+ options1[1] = 0.025f;
9587
+ options1[2] = 0.01f;
9588
+ options1[3] = 0;
9589
+ options1[4] = 0;
9590
+
9591
+ options2[0] = 0;
9592
+ options2[1] = 0.75f;
9593
+ options2[2] = 0;
9594
+ options2[3] = 0;
9595
+
9596
+ options3[0] = 1;
9597
+ options3[1] = 1;
9598
+ options3[2] = 1;
9599
+ options3[3] = 0;
9600
+
9601
+ options4[0] = 1;
9602
+ options4[1] = 0;
9603
+ options4[2] = 1;
9604
+ options4[3] = 0;
9605
+ }
9606
+
92429607 static int imagecount = 0; // movie generation
92439608
92449609 static int jitter = 0;
....@@ -9335,7 +9700,7 @@
93359700
93369701 if (renderCamera != lightCamera)
93379702 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9338
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
9703
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
93399704
93409705 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
93419706
....@@ -9351,7 +9716,7 @@
93519716
93529717 if (renderCamera != lightCamera)
93539718 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9354
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
9719
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
93559720
93569721 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
93579722
....@@ -10349,6 +10714,7 @@
1034910714 ANTIALIAS = 0;
1035010715 //System.out.println("RESTART");
1035110716 AAtimer.restart();
10717
+ Globals.TIMERRUNNING = true;
1035210718 }
1035310719 }
1035410720 }
....@@ -10416,7 +10782,8 @@
1041610782 ambientOcclusion = false;
1041710783 }
1041810784
10419
- if (Globals.lighttouched && DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
10785
+ if (//Globals.lighttouched &&
10786
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1042010787 {
1042110788 //if (RENDERSHADOW) // ?
1042210789 if (!IsFrozen())
....@@ -10550,7 +10917,7 @@
1055010917 // if (parentcam != renderCamera) // not a light
1055110918 if (cam != lightCamera)
1055210919 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10553
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
10920
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1055410921
1055510922 for (int j = 0; j < 4; j++)
1055610923 {
....@@ -10565,7 +10932,7 @@
1056510932 // if (parentcam != renderCamera) // not a light
1056610933 if (cam != lightCamera)
1056710934 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10568
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
10935
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1056910936
1057010937 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1057110938
....@@ -10856,9 +11223,9 @@
1085611223
1085711224 gl.glMatrixMode(GL.GL_MODELVIEW);
1085811225
10859
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10860
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10861
-//gl.glEnable(gl.GL_MULTISAMPLE);
11226
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11227
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11228
+gl.glEnable(gl.GL_MULTISAMPLE);
1086211229 } else
1086311230 {
1086411231 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -10869,7 +11236,7 @@
1086911236 //System.out.println("BLENDING ON");
1087011237 gl.glEnable(GL.GL_BLEND);
1087111238 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
10872
-
11239
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1087311240 gl.glMatrixMode(gl.GL_PROJECTION);
1087411241 gl.glLoadIdentity();
1087511242
....@@ -11118,7 +11485,7 @@
1111811485 }
1111911486 }
1112011487
11121
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11488
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1112211489 {
1112311490 //gl.glDepthFunc(GL.GL_LEQUAL);
1112411491 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11126,24 +11493,21 @@
1112611493
1112711494 boolean texon = textureon;
1112811495
11129
- if (RENDERPROGRAM > 0)
11130
- {
11131
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11132
- textureon = false;
11133
- }
11496
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11497
+ textureon = false;
11498
+
1113411499 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1113511500 //System.out.println("ALLO");
1113611501 gl.glColorMask(false, false, false, false);
1113711502 DrawObject(gl);
11138
- if (RENDERPROGRAM > 0)
11139
- {
11140
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11141
- textureon = texon;
11142
- }
11503
+
11504
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11505
+ textureon = texon;
11506
+
1114311507 gl.glColorMask(true, true, true, true);
1114411508
1114511509 gl.glDepthFunc(GL.GL_EQUAL);
11146
- //gl.glDepthMask(false);
11510
+ gl.glDepthMask(false);
1114711511 }
1114811512
1114911513 if (false) // DrawMode() == SHADOW)
....@@ -11326,15 +11690,36 @@
1132611690
1132711691 static boolean zoomonce = false;
1132811692
11693
+ static void CreateSelectedPoint()
11694
+ {
11695
+ if (selectedpoint == null)
11696
+ {
11697
+ debugpointG = new Sphere();
11698
+ debugpointP = new Sphere();
11699
+ debugpointC = new Sphere();
11700
+ debugpointR = new Sphere();
11701
+
11702
+ selectedpoint = new Superellipsoid();
11703
+
11704
+ for (int i=0; i<8; i++)
11705
+ {
11706
+ debugpoints[i] = new Sphere();
11707
+ }
11708
+ }
11709
+ }
11710
+
1132911711 void DrawObject(GL gl, boolean draw)
1133011712 {
11713
+ // To clear camera values
11714
+ ResetOptions();
11715
+
1133111716 //System.out.println("DRAW OBJECT " + mouseDown);
1133211717 // DrawMode() = SELECTION;
1133311718 //GL gl = getGL();
1133411719 if ((TRACK || SHADOWTRACK) || zoomonce)
1133511720 {
1133611721 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11337
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11722
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1133811723 pingthread.StepToTarget(true); // true);
1133911724 // zoomonce = false;
1134011725 }
....@@ -11406,8 +11791,9 @@
1140611791
1140711792 if (DrawMode() == DEFAULT)
1140811793 {
11409
- if (DEBUG)
11794
+ if (Globals.DEBUG)
1141011795 {
11796
+ CreateSelectedPoint();
1141111797 float radius = 0.05f;
1141211798 if (selectedpoint.radius != radius)
1141311799 {
....@@ -11461,20 +11847,32 @@
1146111847 ReleaseTextures(DEFAULT_TEXTURES);
1146211848
1146311849 if (CLEANCACHE)
11464
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11850
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1146511851 {
11466
- String tex = e.nextElement();
11852
+ cTexture tex = e.nextElement();
1146711853
1146811854 // System.out.println("Texture --------- " + tex);
1146911855
11470
- if (tex.equals("WHITE_NOISE"))
11856
+ if (tex.equals("WHITE_NOISE:"))
1147111857 continue;
1147211858
11473
- if (!usedtextures.containsKey(tex))
11859
+ if (!usedtextures.contains(tex))
1147411860 {
11861
+ CacheTexture gettex = texturepigment.get(tex);
1147511862 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11476
- textures.get(tex).texture.dispose();
11477
- textures.remove(tex);
11863
+ if (gettex != null)
11864
+ {
11865
+ gettex.texture.dispose();
11866
+ texturepigment.remove(tex);
11867
+ }
11868
+
11869
+ gettex = texturebump.get(tex);
11870
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11871
+ if (gettex != null)
11872
+ {
11873
+ gettex.texture.dispose();
11874
+ texturebump.remove(tex);
11875
+ }
1147811876 }
1147911877 }
1148011878 }
....@@ -11894,7 +12292,7 @@
1189412292 for (int i = tp.size(); --i >= 0;)
1189512293 {
1189612294 //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
11897
- LA.xformPos(light, tp.get(i).GlobalTransform(), light);
12295
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1189812296 }
1189912297
1190012298
....@@ -12003,7 +12401,74 @@
1200312401 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1200412402
1200512403 String program =
12404
+ // Min shader
1200612405 "!!ARBfp1.0\n" +
12406
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12407
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12408
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12409
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12410
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12411
+ "PARAM light2cam0 = program.env[10];" +
12412
+ "PARAM light2cam1 = program.env[11];" +
12413
+ "PARAM light2cam2 = program.env[12];" +
12414
+ "TEMP temp;" +
12415
+ "TEMP light;" +
12416
+ "TEMP ndotl;" +
12417
+ "TEMP normal;" +
12418
+ "TEMP depth;" +
12419
+ "TEMP eye;" +
12420
+ "TEMP pos;" +
12421
+
12422
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12423
+ Normalize("normal") +
12424
+ "MOV light, state.light[0].position;" +
12425
+ "DP3 ndotl.x, light, normal;" +
12426
+
12427
+ // shadow
12428
+ "MOV pos, fragment.texcoord[1];" +
12429
+ "MOV temp, pos;" +
12430
+ ShadowTextureFetch("depth", "temp", "1") +
12431
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12432
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12433
+
12434
+ // No shadow when out of frustum
12435
+ //"SGE temp.y, depth.z, zero123.y;" +
12436
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12437
+
12438
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12439
+
12440
+ // Backlit
12441
+ "MOV pos.w, zero123.y;" +
12442
+ "DP4 eye.x, pos, light2cam0;" +
12443
+ "DP4 eye.y, pos, light2cam1;" +
12444
+ "DP4 eye.z, pos, light2cam2;" +
12445
+ Normalize("eye") +
12446
+
12447
+ "DP3 ndotl.y, -eye, normal;" +
12448
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12449
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12450
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12451
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12452
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12453
+
12454
+ "MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12455
+
12456
+ // Pigment
12457
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12458
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12459
+ "MUL temp, temp, ndotl.x;" +
12460
+
12461
+ "MUL temp, temp, zero123.z;" +
12462
+
12463
+ //"MUL temp, temp, ndotl.y;" +
12464
+
12465
+ "MOV temp.w, zero123.y;" + // reset alpha
12466
+ "MOV result.color, temp;" +
12467
+ "END";
12468
+
12469
+ String program2 =
12470
+ "!!ARBfp1.0\n" +
12471
+
1200712472 //"OPTION ARB_fragment_program_shadow;" +
1200812473 "PARAM light2cam0 = program.env[10];" +
1200912474 "PARAM light2cam1 = program.env[11];" +
....@@ -12118,8 +12583,7 @@
1211812583 "TEMP shininess;" +
1211912584 "\n" +
1212012585 "MOV texSamp, one;" +
12121
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12122
-
12586
+
1212312587 "MOV mapgrid.x, one2048th.x;" +
1212412588 "MOV temp, fragment.texcoord[1];" +
1212512589 /*
....@@ -12140,20 +12604,20 @@
1214012604 "MUL temp, floor, mapgrid.x;" +
1214112605 //"TEX depth0, temp, texture[1], 2D;" +
1214212606 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12143
- TextureFetch("depth0", "temp", "1") +
12607
+ ShadowTextureFetch("depth0", "temp", "1") +
1214412608 "") +
1214512609 "ADD temp.x, temp.x, mapgrid.x;" +
1214612610 //"TEX depth1, temp, texture[1], 2D;" +
1214712611 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12148
- TextureFetch("depth1", "temp", "1") +
12612
+ ShadowTextureFetch("depth1", "temp", "1") +
1214912613 "") +
1215012614 "ADD temp.y, temp.y, mapgrid.x;" +
1215112615 //"TEX depth2, temp, texture[1], 2D;" +
12152
- TextureFetch("depth2", "temp", "1") +
12616
+ ShadowTextureFetch("depth2", "temp", "1") +
1215312617 "SUB temp.x, temp.x, mapgrid.x;" +
1215412618 //"TEX depth3, temp, texture[1], 2D;" +
1215512619 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12156
- TextureFetch("depth3", "temp", "1") +
12620
+ ShadowTextureFetch("depth3", "temp", "1") +
1215712621 "") +
1215812622 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1215912623 //"MOV params, material;" +
....@@ -12524,7 +12988,7 @@
1252412988 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1252512989 "") +
1252612990
12527
- // display shadow only (bump == 0)
12991
+ // display shadow only (fakedepth == 0)
1252812992 "SUB temp.x, half.x, shadow.x;" +
1252912993 "MOV temp.y, -params5.z;" + // params6.x;" +
1253012994 "SLT temp.z, temp.y, -one2048th.x;" +
....@@ -12951,25 +13415,26 @@
1295113415 return out;
1295213416 }
1295313417
12954
- String TextureFetch(String dest, String src, String unit)
13418
+ // Also does frustum culling
13419
+ String ShadowTextureFetch(String dest, String src, String unit)
1295513420 {
1295613421 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1295713422 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1295813423 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13424
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13425
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1295913426 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12960
- "SLT " + src + ".z, " + src + ".x, one.x;" +
12961
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12962
- "SLT " + src + ".z, " + src + ".y, one.x;" +
12963
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13427
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13428
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1296413429 //"SWZ buffer, temp, w,w,w,w;";
12965
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13430
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1296613431 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1296713432 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1296813433 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
12969
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13434
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1297013435
12971
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
12972
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13436
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13437
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1297313438 }
1297413439
1297513440 String Shadow(String depth, String shadow)
....@@ -13016,7 +13481,7 @@
1301613481 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1301713482 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1301813483
13019
- // No shadow when out of frustrum
13484
+ // No shadow when out of frustum
1302013485 "SGE temp.x, " + depth + ".z, one.z;" +
1302113486 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1302213487 "";
....@@ -13164,7 +13629,8 @@
1316413629 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1316513630 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1316613631 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13167
- Object3D.cVector2[] vector2buffer;
13632
+
13633
+ //Object3D.cVector2[] vector2buffer;
1316813634
1316913635 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1317013636 // OUT : diff, spec
....@@ -13180,9 +13646,10 @@
1318013646 "DP3 " + dest + ".z," + "normals," + "eye;" +
1318113647 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1318213648 //"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;" +
13649
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13650
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13651
+
13652
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1318613653 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1318713654 "RCP " + dest + ".w," + dest + ".w;" +
1318813655 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13687,6 +14154,7 @@
1368714154 else
1368814155 if (evt.getSource() == AAtimer)
1368914156 {
14157
+ Globals.TIMERRUNNING = false;
1369014158 if (mouseDown)
1369114159 {
1369214160 //new Exception().printStackTrace();
....@@ -13746,7 +14214,7 @@
1374614214
1374714215 // fev 2014???
1374814216 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13749
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14217
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1375014218 pingthread.StepToTarget(true); // true);
1375114219 }
1375214220 // if (!LIVE)
....@@ -13761,6 +14229,7 @@
1376114229 return;
1376214230
1376314231 AAtimer.restart(); //
14232
+ Globals.TIMERRUNNING = true;
1376414233
1376514234 // waslive = LIVE;
1376614235 // LIVE = false;
....@@ -13810,14 +14279,15 @@
1381014279 drag = false;
1381114280 //System.out.println("Mouse DOWN");
1381214281 editObj = false;
13813
- ClickInfo info = new ClickInfo();
13814
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
13815
- info.pane = this;
13816
- info.camera = renderCamera;
13817
- info.x = x;
13818
- info.y = y;
13819
- info.modifiers = modifiersex;
13820
- editObj = object.doEditClick(info, 0);
14282
+ //ClickInfo info = new ClickInfo();
14283
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14284
+ object.clickInfo.pane = this;
14285
+ object.clickInfo.camera = renderCamera;
14286
+ object.clickInfo.x = x;
14287
+ object.clickInfo.y = y;
14288
+ object.clickInfo.modifiers = modifiersex;
14289
+ editObj = object.doEditClick(//info,
14290
+ 0);
1382114291 if (!editObj)
1382214292 {
1382314293 hasMarquee = true;
....@@ -14099,12 +14569,12 @@
1409914569 void GoDown(int mod)
1410014570 {
1410114571 MODIFIERS |= COMMAND;
14102
- /*
14572
+ /**/
1410314573 if((mod&SHIFT) == SHIFT)
1410414574 manipCamera.RotatePosition(0, -speed);
1410514575 else
14106
- manipCamera.BackForth(0, -speed*delta, getWidth());
14107
- */
14576
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14577
+ /**/
1410814578 if ((mod & SHIFT) == SHIFT)
1410914579 {
1411014580 mouseMode = mouseMode; // VR??
....@@ -14120,12 +14590,12 @@
1412014590 void GoUp(int mod)
1412114591 {
1412214592 MODIFIERS |= COMMAND;
14123
- /*
14593
+ /**/
1412414594 if((mod&SHIFT) == SHIFT)
1412514595 manipCamera.RotatePosition(0, speed);
1412614596 else
14127
- manipCamera.BackForth(0, speed*delta, getWidth());
14128
- */
14597
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14598
+ /**/
1412914599 if ((mod & SHIFT) == SHIFT)
1413014600 {
1413114601 mouseMode = mouseMode;
....@@ -14141,12 +14611,12 @@
1414114611 void GoLeft(int mod)
1414214612 {
1414314613 MODIFIERS |= COMMAND;
14144
- /*
14614
+ /**/
1414514615 if((mod&SHIFT) == SHIFT)
14146
- manipCamera.RotatePosition(speed, 0);
14147
- else
1414814616 manipCamera.Translate(speed*delta, 0, getWidth());
14149
- */
14617
+ else
14618
+ manipCamera.RotatePosition(speed, 0);
14619
+ /**/
1415014620 if ((mod & SHIFT) == SHIFT)
1415114621 {
1415214622 mouseMode = mouseMode;
....@@ -14162,12 +14632,12 @@
1416214632 void GoRight(int mod)
1416314633 {
1416414634 MODIFIERS |= COMMAND;
14165
- /*
14635
+ /**/
1416614636 if((mod&SHIFT) == SHIFT)
14167
- manipCamera.RotatePosition(-speed, 0);
14168
- else
1416914637 manipCamera.Translate(-speed*delta, 0, getWidth());
14170
- */
14638
+ else
14639
+ manipCamera.RotatePosition(-speed, 0);
14640
+ /**/
1417114641 if ((mod & SHIFT) == SHIFT)
1417214642 {
1417314643 mouseMode = mouseMode;
....@@ -14217,14 +14687,16 @@
1421714687 if (editObj)
1421814688 {
1421914689 drag = true;
14220
- ClickInfo info = new ClickInfo();
14221
- info.bounds.setBounds(0, 0,
14690
+ //ClickInfo info = new ClickInfo();
14691
+ object.clickInfo.bounds.setBounds(0, 0,
1422214692 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14223
- info.pane = this;
14224
- info.camera = renderCamera;
14225
- info.x = x;
14226
- info.y = y;
14227
- object.editWindow.copy.doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
14693
+ object.clickInfo.pane = this;
14694
+ object.clickInfo.camera = renderCamera;
14695
+ object.clickInfo.x = x;
14696
+ object.clickInfo.y = y;
14697
+ object //.GetWindow().copy
14698
+ .doEditDrag(//info,
14699
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1422814700 } else
1422914701 {
1423014702 if (x < startX)
....@@ -14373,22 +14845,27 @@
1437314845 }
1437414846 }
1437514847
14848
+// ClickInfo clickInfo = new ClickInfo();
14849
+
1437614850 public void mouseMoved(MouseEvent e)
1437714851 {
1437814852 //System.out.println("mouseMoved: " + e);
1437914853 if (isRenderer)
1438014854 return;
1438114855
14382
- ClickInfo ci = new ClickInfo();
14383
- ci.x = e.getX();
14384
- ci.y = e.getY();
14385
- ci.modifiers = e.getModifiersEx();
14386
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14387
- ci.pane = this;
14388
- ci.camera = renderCamera;
14856
+ // Mouse cursor feedback
14857
+ object.clickInfo.x = e.getX();
14858
+ object.clickInfo.y = e.getY();
14859
+ object.clickInfo.modifiers = e.getModifiersEx();
14860
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14861
+ object.clickInfo.pane = this;
14862
+ object.clickInfo.camera = renderCamera;
1438914863 if (!isRenderer)
1439014864 {
14391
- if (object.editWindow.copy.doEditClick(ci, 0))
14865
+ //ObjEditor editWindow = object.editWindow;
14866
+ //Object3D copy = editWindow.copy;
14867
+ if (object.doEditClick(//clickInfo,
14868
+ 0))
1439214869 {
1439314870 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1439414871 } else
....@@ -14403,7 +14880,8 @@
1440314880 Globals.MOUSEDRAGGED = false;
1440414881
1440514882 movingcamera = false;
14406
- X = Y = 0;
14883
+ X = 0; // getBounds().width/2;
14884
+ Y = 0; // getBounds().height/2;
1440714885 //System.out.println("mouseReleased: " + e);
1440814886 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1440914887 }
....@@ -14659,7 +15137,8 @@
1465915137 // break;
1466015138 case 'T':
1466115139 CACHETEXTURE ^= true;
14662
- textures.clear();
15140
+ texturepigment.clear();
15141
+ texturebump.clear();
1466315142 // repaint();
1466415143 break;
1466515144 case 'Y':
....@@ -14744,7 +15223,9 @@
1474415223 case 'E' : COMPACT ^= true;
1474515224 repaint();
1474615225 break;
14747
- case 'W' : DEBUGHSB ^= true;
15226
+ case 'W' : // Wide Window (fullscreen)
15227
+ //DEBUGHSB ^= true;
15228
+ ObjEditor.theFrame.ToggleFullScreen();
1474815229 repaint();
1474915230 break;
1475015231 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14769,8 +15250,8 @@
1476915250 RevertCamera();
1477015251 repaint();
1477115252 break;
14772
- case 'L':
1477315253 case 'l':
15254
+ //case 'L':
1477415255 if (lightMode)
1477515256 {
1477615257 lightMode = false;
....@@ -14913,9 +15394,9 @@
1491315394 case '_':
1491415395 kompactbit = 5;
1491515396 break;
14916
- case '+':
14917
- kompactbit = 6;
14918
- break;
15397
+// case '+':
15398
+// kompactbit = 6;
15399
+// break;
1491915400 case ' ':
1492015401 lightMode ^= true;
1492115402 Globals.lighttouched = true;
....@@ -14927,6 +15408,7 @@
1492715408 case ESC:
1492815409 RENDERPROGRAM += 1;
1492915410 RENDERPROGRAM %= 3;
15411
+
1493015412 repaint();
1493115413 break;
1493215414 case 'Z':
....@@ -14966,8 +15448,9 @@
1496615448 case DELETE:
1496715449 ClearSelection();
1496815450 break;
14969
- /*
1497015451 case '+':
15452
+
15453
+ /*
1497115454 //fontsize += 1;
1497215455 bbzoom *= 2;
1497315456 repaint();
....@@ -14984,17 +15467,17 @@
1498415467 case '=':
1498515468 IncDepth();
1498615469 //fontsize += 1;
14987
- object.editWindow.refreshContents(true);
15470
+ object.GetWindow().refreshContents(true);
1498815471 maskbit = 6;
1498915472 break;
1499015473 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1499115474 DecDepth();
1499215475 maskbit = 5;
1499315476 //if(fontsize > 1) fontsize -= 1;
14994
- if (object.editWindow == null)
14995
- new Exception().printStackTrace();
14996
- else
14997
- object.editWindow.refreshContents(true);
15477
+// if (object.editWindow == null)
15478
+// new Exception().printStackTrace();
15479
+// else
15480
+ object.GetWindow().refreshContents(true);
1499815481 break;
1499915482 case '{':
1500015483 manipCamera.shaper_fovy /= 1.1;
....@@ -15218,7 +15701,7 @@
1521815701 }
1521915702 */
1522015703
15221
- object.editWindow.EditSelection();
15704
+ object.GetWindow().EditSelection(false);
1522215705 }
1522315706
1522415707 void SelectParent()
....@@ -15235,10 +15718,10 @@
1523515718 {
1523615719 //selectees.remove(i);
1523715720 System.out.println("select parent of " + elem);
15238
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15721
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1523915722 } else
1524015723 {
15241
- group.editWindow.Select(elem.GetTreePath(), first, true);
15724
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1524215725 }
1524315726
1524415727 first = false;
....@@ -15280,12 +15763,12 @@
1528015763 for (int j = 0; j < group.children.size(); j++)
1528115764 {
1528215765 elem = (Object3D) group.children.elementAt(j);
15283
- object.editWindow.Select(elem.GetTreePath(), first, true);
15766
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1528415767 first = false;
1528515768 }
1528615769 } else
1528715770 {
15288
- object.editWindow.Select(elem.GetTreePath(), first, true);
15771
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1528915772 }
1529015773
1529115774 first = false;
....@@ -15296,21 +15779,21 @@
1529615779 {
1529715780 //Composite group = (Composite) object;
1529815781 Object3D group = object;
15299
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15782
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1530015783 }
1530115784
1530215785 void ResetTransform(int mask)
1530315786 {
1530415787 //Composite group = (Composite) object;
1530515788 Object3D group = object;
15306
- group.editWindow.ResetTransform(mask);
15789
+ group.GetWindow().ResetTransform(mask);
1530715790 }
1530815791
1530915792 void FlipTransform()
1531015793 {
1531115794 //Composite group = (Composite) object;
1531215795 Object3D group = object;
15313
- group.editWindow.FlipTransform();
15796
+ group.GetWindow().FlipTransform();
1531415797 // group.editWindow.ReduceMesh(true);
1531515798 }
1531615799
....@@ -15318,7 +15801,7 @@
1531815801 {
1531915802 //Composite group = (Composite) object;
1532015803 Object3D group = object;
15321
- group.editWindow.PrintMemory();
15804
+ group.GetWindow().PrintMemory();
1532215805 // group.editWindow.ReduceMesh(true);
1532315806 }
1532415807
....@@ -15326,7 +15809,7 @@
1532615809 {
1532715810 //Composite group = (Composite) object;
1532815811 Object3D group = object;
15329
- group.editWindow.ResetCentroid();
15812
+ group.GetWindow().ResetCentroid();
1533015813 }
1533115814
1533215815 void IncDepth()
....@@ -15408,8 +15891,6 @@
1540815891
1540915892 int width = getBounds().width;
1541015893 int height = getBounds().height;
15411
- ClickInfo info = new ClickInfo();
15412
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1541315894 //Image img = CreateImage(width, height);
1541415895 //System.out.println("width = " + width + "; height = " + height + "\n");
1541515896
....@@ -15486,48 +15967,77 @@
1548615967 }
1548715968 if (object != null && !hasMarquee)
1548815969 {
15970
+ if (object.clickInfo == null)
15971
+ object.clickInfo = new ClickInfo();
15972
+ ClickInfo info = object.clickInfo;
15973
+ //ClickInfo info = new ClickInfo();
15974
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
15975
+
1548915976 if (isRenderer)
1549015977 {
15491
- info.flags++;
15978
+ object.clickInfo.flags++;
1549215979 double frameAspect = (double) width / (double) height;
1549315980 if (frameAspect > renderCamera.aspect)
1549415981 {
1549515982 int desired = (int) ((double) height * renderCamera.aspect);
15496
- info.bounds.width -= width - desired;
15497
- info.bounds.x += (width - desired) / 2;
15983
+ object.clickInfo.bounds.width -= width - desired;
15984
+ object.clickInfo.bounds.x += (width - desired) / 2;
1549815985 } else
1549915986 {
1550015987 int desired = (int) ((double) width / renderCamera.aspect);
15501
- info.bounds.height -= height - desired;
15502
- info.bounds.y += (height - desired) / 2;
15988
+ object.clickInfo.bounds.height -= height - desired;
15989
+ object.clickInfo.bounds.y += (height - desired) / 2;
1550315990 }
1550415991 }
15505
- info.g = gr;
15506
- info.camera = renderCamera;
15992
+
15993
+ object.clickInfo.g = gr;
15994
+ object.clickInfo.camera = renderCamera;
1550715995 /*
1550815996 // Memory intensive (brep.verticescopy)
1550915997 if (!(object instanceof Composite))
1551015998 object.draw(info, 0, false); // SLOW :
1551115999 */
15512
- if (!isRenderer)
16000
+ if (!isRenderer) // && drag)
1551316001 {
15514
- object.drawEditHandles(info, 0);
15515
-
15516
- if (drag && (X != 0 || Y != 0) && object.selection.Size() > 0)
16002
+ Grafreed.Assert(object != null);
16003
+ Grafreed.Assert(object.selection != null);
16004
+ if (object.selection.Size() > 0)
1551716005 {
15518
- switch (object.selection.get(0).hitSomething)
16006
+ int hitSomething = object.selection.get(0).hitSomething;
16007
+
16008
+ object.clickInfo.DX = 0;
16009
+ object.clickInfo.DY = 0;
16010
+ object.clickInfo.W = 1;
16011
+ if (hitSomething == Object3D.hitCenter)
1551916012 {
15520
- case Object3D.hitCenter: gr.setColor(Color.pink);
15521
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15522
- break;
15523
- case Object3D.hitRotate: gr.setColor(Color.yellow);
15524
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15525
- break;
15526
- case Object3D.hitScale: gr.setColor(Color.cyan);
15527
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15528
- break;
16013
+ info.DX = X;
16014
+ if (X != 0)
16015
+ info.DX -= info.bounds.width/2;
16016
+
16017
+ info.DY = Y;
16018
+ if (Y != 0)
16019
+ info.DY -= info.bounds.height/2;
1552916020 }
15530
-
16021
+
16022
+ object.drawEditHandles(//info,
16023
+ 0);
16024
+
16025
+ if (drag && (X != 0 || Y != 0))
16026
+ {
16027
+ switch (hitSomething)
16028
+ {
16029
+ case Object3D.hitCenter: gr.setColor(Color.pink);
16030
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16031
+ break;
16032
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16033
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16034
+ break;
16035
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16036
+ gr.drawLine(X, Y, 0, 0);
16037
+ break;
16038
+ }
16039
+
16040
+ }
1553116041 }
1553216042 }
1553316043 }
....@@ -16230,16 +16740,16 @@
1623016740 cStatic.objectstack[materialdepth++] = checker;
1623116741 //System.out.println("material " + material);
1623216742 //Applet3D.tracein(this, selected);
16233
- vector2buffer = checker.projectedVertices;
16743
+ //vector2buffer = checker.projectedVertices;
1623416744
1623516745 //checker.GetMaterial().Draw(this, false); // true);
16236
- DrawMaterial(checker.GetMaterial(), false); // true);
16746
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1623716747
1623816748 materialdepth -= 1;
1623916749 if (materialdepth > 0)
1624016750 {
16241
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16242
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
16751
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16752
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1624316753 }
1624416754 //checker.GetMaterial().opacity = 1f;
1624516755 ////checker.GetMaterial().ambient = 1f;
....@@ -16325,6 +16835,14 @@
1632516835 }
1632616836 }
1632716837
16838
+ private Object3D GetFolder()
16839
+ {
16840
+ Object3D folder = object.GetWindow().copy;
16841
+ if (object.GetWindow().copy.selection.Size() > 0)
16842
+ folder = object.GetWindow().copy.selection.elementAt(0);
16843
+ return folder;
16844
+ }
16845
+
1632816846 class SelectBuffer implements GLEventListener
1632916847 {
1633016848
....@@ -16404,6 +16922,17 @@
1640416922
1640516923 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1640616924
16925
+ if (PAINTMODE)
16926
+ {
16927
+ if (object.GetWindow().copy.selection.Size() > 0)
16928
+ {
16929
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16930
+
16931
+ // Make what you paint not selectable.
16932
+ paintobj.ResetSelectable();
16933
+ }
16934
+ }
16935
+
1640716936 //int tmp = selection_view;
1640816937 //selection_view = -1;
1640916938 int temp = DrawMode();
....@@ -16415,6 +16944,17 @@
1641516944 // temp = DEFAULT; // patch for selection debug
1641616945 Globals.drawMode = temp; // WARNING
1641716946
16947
+ if (PAINTMODE)
16948
+ {
16949
+ if (object.GetWindow().copy.selection.Size() > 0)
16950
+ {
16951
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16952
+
16953
+ // Revert.
16954
+ paintobj.RestoreSelectable();
16955
+ }
16956
+ }
16957
+
1641816958 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1641916959
1642016960 // trying different ways of getting the depth info over
....@@ -16462,6 +17002,8 @@
1646217002 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1646317003 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1646417004 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
17005
+
17006
+ CreateSelectedPoint();
1646517007
1646617008 // Will fit the mesh !!!
1646717009 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16516,29 +17058,31 @@
1651617058 }
1651717059
1651817060 if (!movingcamera && !PAINTMODE)
16519
- object.editWindow.ScreenFitPoint(); // fev 2014
17061
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1652017062
16521
- if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17063
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1652217064 {
16523
- Object3D paintobj = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17065
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1652417066
16525
- Object3D group = new Object3D("inst" + paintcount++);
17067
+ if (object.GetWindow().copy.selection.Size() > 0)
17068
+ {
17069
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1652617070
16527
- group.CreateMaterial(); // use a void leaf to select instances
16528
-
16529
- group.add(paintobj); // link
16530
-
16531
- object.editWindow.SnapObject(group);
16532
-
16533
- Object3D folder = object.editWindow.copy;
16534
-
16535
- if (object.editWindow.copy.selection.Size() > 0)
16536
- folder = object.editWindow.copy.selection.elementAt(0);
16537
-
16538
- folder.add(group);
16539
-
16540
- object.editWindow.ResetModel();
16541
- object.editWindow.refreshContents();
17071
+ Object3D inst = new Object3D("inst" + paintcount++);
17072
+
17073
+ inst.CreateMaterial(); // use a void leaf to select instances
17074
+
17075
+ inst.add(paintobj); // link
17076
+
17077
+ object.GetWindow().SnapObject(inst);
17078
+
17079
+ Object3D folder = paintFolder; // GetFolder();
17080
+
17081
+ folder.add(inst);
17082
+
17083
+ object.GetWindow().ResetModel();
17084
+ object.GetWindow().refreshContents();
17085
+ }
1654217086 }
1654317087 else
1654417088 paintcount = 0;
....@@ -16577,6 +17121,11 @@
1657717121 //System.out.println("objects[color] = " + objects[color]);
1657817122 //objects[color].Select();
1657917123 indexcount = 0;
17124
+ ObjEditor window = object.GetWindow();
17125
+ if (window != null && deselect)
17126
+ {
17127
+ window.Select(null, deselect, true);
17128
+ }
1658017129 object.Select(color, deselect);
1658117130 }
1658217131
....@@ -17102,23 +17651,15 @@
1710217651 int AAbuffersize = 0;
1710317652
1710417653 //double[] selectedpoint = new double[3];
17105
- static Superellipsoid selectedpoint = new Superellipsoid();
17654
+ static Superellipsoid selectedpoint;
1710617655 static Sphere previousselectedpoint = null;
17107
- static Sphere debugpointG = new Sphere();
17108
- static Sphere debugpointP = new Sphere();
17109
- static Sphere debugpointC = new Sphere();
17110
- static Sphere debugpointR = new Sphere();
17656
+ static Sphere debugpointG;
17657
+ static Sphere debugpointP;
17658
+ static Sphere debugpointC;
17659
+ static Sphere debugpointR;
1711117660
1711217661 static Sphere debugpoints[] = new Sphere[8];
1711317662
17114
- static
17115
- {
17116
- for (int i=0; i<8; i++)
17117
- {
17118
- debugpoints[i] = new Sphere();
17119
- }
17120
- }
17121
-
1712217663 static void InitPoints(float radius)
1712317664 {
1712417665 for (int i=0; i<8; i++)