Normand Briere
2019-07-24 ebd16116fc612bf14e2469ba27dd7ee54918eabb
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;
....@@ -327,7 +363,7 @@
327363 cStatic.objectstack[materialdepth++] = obj;
328364 //System.out.println("material " + material);
329365 //Applet3D.tracein(this, selected);
330
- display.vector2buffer = obj.projectedVertices;
366
+ //display.vector2buffer = obj.projectedVertices;
331367 if (obj instanceof Camera)
332368 {
333369 display.options1[0] = material.shift;
....@@ -336,14 +372,28 @@
336372 display.options1[2] = material.shadowbias;
337373 display.options1[3] = material.aniso;
338374 display.options1[4] = material.anisoV;
375
+// System.out.println("display.options1[0] " + display.options1[0]);
376
+// System.out.println("display.options1[1] " + display.options1[1]);
377
+// System.out.println("display.options1[2] " + display.options1[2]);
378
+// System.out.println("display.options1[3] " + display.options1[3]);
379
+// System.out.println("display.options1[4] " + display.options1[4]);
339380 display.options2[0] = material.opacity;
340381 display.options2[1] = material.diffuse;
341382 display.options2[2] = material.factor;
383
+// System.out.println("display.options2[0] " + display.options2[0]);
384
+// System.out.println("display.options2[1] " + display.options2[1]);
385
+// System.out.println("display.options2[2] " + display.options2[2]);
342386
343387 cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
388
+// System.out.println("display.options3[0] " + display.options3[0]);
389
+// System.out.println("display.options3[1] " + display.options3[1]);
390
+// System.out.println("display.options3[2] " + display.options3[2]);
344391 display.options4[0] = material.cameralight/0.2f;
345392 display.options4[1] = material.subsurface;
346393 display.options4[2] = material.sheen;
394
+// System.out.println("display.options4[0] " + display.options4[0]);
395
+// System.out.println("display.options4[1] " + display.options4[1]);
396
+// System.out.println("display.options4[2] " + display.options4[2]);
347397
348398 // if (display.CURRENTANTIALIAS > 0)
349399 // display.options3[3] /= 4;
....@@ -359,7 +409,7 @@
359409 /**/
360410 } else
361411 {
362
- DrawMaterial(material, selected);
412
+ DrawMaterial(material, selected, obj.projectedVertices);
363413 }
364414 } else
365415 {
....@@ -383,8 +433,8 @@
383433 cStatic.objectstack[materialdepth++] = obj;
384434 //System.out.println("material " + material);
385435 //Applet3D.tracein("selected ", selected);
386
- display.vector2buffer = obj.projectedVertices;
387
- display.DrawMaterial(material, selected);
436
+ //display.vector2buffer = obj.projectedVertices;
437
+ display.DrawMaterial(material, selected, obj.projectedVertices);
388438 }
389439 }
390440
....@@ -401,8 +451,8 @@
401451 materialdepth -= 1;
402452 if (materialdepth > 0)
403453 {
404
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
405
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
454
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
455
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
406456 }
407457 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
408458 } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
....@@ -422,8 +472,8 @@
422472 materialdepth -= 1;
423473 if (materialdepth > 0)
424474 {
425
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
426
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
475
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
476
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
427477 }
428478 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
429479 //else
....@@ -464,10 +514,12 @@
464514 if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
465515 {
466516 //gl.glBegin(gl.GL_TRIANGLES);
467
- boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0);
517
+ boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0)
518
+ // TEST LIVE NORMALS && !obj.dontselect
519
+ ;
468520 if (!hasnorm)
469521 {
470
- // System.out.println("FUCK!!");
522
+ // System.out.println("Mesh normal");
471523 LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
472524 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
473525 LA.vecCross(obj.v0, obj.v1, obj.v2);
....@@ -1192,10 +1244,12 @@
11921244 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
11931245 }
11941246 }
1247
+
11951248 if (flipV)
11961249 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
11971250 else
11981251 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1252
+
11991253 //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
12001254 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
12011255
....@@ -1215,10 +1269,12 @@
12151269 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
12161270 }
12171271 }
1272
+
12181273 if (flipV)
12191274 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12201275 else
12211276 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1277
+
12221278 //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
12231279 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
12241280
....@@ -1246,8 +1302,10 @@
12461302 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12471303 else
12481304 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1305
+
12491306 //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
12501307 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1308
+
12511309 count2 += 2;
12521310 count3 += 3;
12531311 }
....@@ -1603,7 +1661,7 @@
16031661 // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
16041662 }
16051663
1606
- void DrawMaterial(cMaterial material, boolean selected)
1664
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
16071665 {
16081666 CameraPane display = this;
16091667 //new Exception().printStackTrace();
....@@ -1638,7 +1696,7 @@
16381696 colorV[0] = display.modelParams0[0] * material.diffuse;
16391697 colorV[1] = display.modelParams0[1] * material.diffuse;
16401698 colorV[2] = display.modelParams0[2] * material.diffuse;
1641
- colorV[3] = material.opacity;
1699
+ colorV[3] = 1; // material.opacity;
16421700
16431701 gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
16441702 //System.out.println("Opacity = " + opacity);
....@@ -1746,9 +1804,9 @@
17461804 display.modelParams7[2] = 0;
17471805 display.modelParams7[3] = 0;
17481806
1749
- display.modelParams6[0] = 100; // criss de bug de bump
1807
+ //display.modelParams6[0] = 100; // criss de bug de bump
17501808
1751
- Object3D.cVector2[] extparams = display.vector2buffer;
1809
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
17521810 if (extparams != null && extparams.length > 0 && extparams[0] != null)
17531811 {
17541812 display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
....@@ -1890,7 +1948,7 @@
18901948 void PushMatrix(double[][] matrix)
18911949 {
18921950 // GrafreeD.tracein(matrix);
1893
- PushMatrix(matrix,1);
1951
+ PushMatrix(matrix, 1);
18941952 }
18951953
18961954 void PushMatrix()
....@@ -2044,7 +2102,7 @@
20442102 //System.err.println("Oeil on");
20452103 OEIL = true;
20462104 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2047
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2105
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
20482106 //pingthread.StepToTarget(true);
20492107 }
20502108
....@@ -2259,7 +2317,7 @@
22592317
22602318 void ToggleDebug()
22612319 {
2262
- DEBUG ^= true;
2320
+ Globals.DEBUG ^= true;
22632321 }
22642322
22652323 void ToggleLookAt()
....@@ -2277,10 +2335,17 @@
22772335 HANDLES ^= true;
22782336 }
22792337
2338
+ Object3D paintFolder;
2339
+
22802340 void TogglePaint()
22812341 {
22822342 PAINTMODE ^= true;
22832343 paintcount = 0;
2344
+
2345
+ if (PAINTMODE)
2346
+ {
2347
+ paintFolder = GetFolder();
2348
+ }
22842349 }
22852350
22862351 void SwapCamera(int a, int b)
....@@ -2377,6 +2442,21 @@
23772442 return currentGL;
23782443 }
23792444
2445
+ static private BufferedImage CreateBim(TextureData texturedata)
2446
+ {
2447
+ Grafreed.Assert(texturedata != null);
2448
+
2449
+ int width = texturedata.getWidth();
2450
+ int height = texturedata.getHeight();
2451
+
2452
+ Buffer buffer = texturedata.getBuffer();
2453
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2454
+
2455
+ byte[] bytes = bytebuf.array();
2456
+
2457
+ return CreateBim(bytes, width, height);
2458
+ }
2459
+
23802460 /**/
23812461 class CacheTexture
23822462 {
....@@ -2385,28 +2465,31 @@
23852465
23862466 int resolution;
23872467
2388
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2468
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
23892469 {
2390
- texture = tex;
2470
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2471
+ texturedata = texdata;
23912472 resolution = res;
23922473 }
23932474 }
23942475 /**/
23952476
23962477 // 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>();
2478
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2479
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2480
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2481
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2482
+
24002483 int pigmentdepth = 0;
24012484 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
24022485 int bumpdepth = 0;
24032486 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
24042487 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
24052488 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2406
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2489
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
24072490 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
24082491
2409
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2492
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
24102493 {
24112494 TextureData texturedata = null;
24122495
....@@ -2425,13 +2508,34 @@
24252508 if (bump)
24262509 texturedata = ConvertBump(texturedata, false);
24272510
2428
- com.sun.opengl.util.texture.Texture texture =
2429
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2511
+// com.sun.opengl.util.texture.Texture texture =
2512
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
24302513
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);
2514
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2515
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
24332516
2434
- return texture;
2517
+ return texturedata;
2518
+ }
2519
+
2520
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2521
+ {
2522
+ TextureData texturedata = null;
2523
+
2524
+ try
2525
+ {
2526
+ texturedata =
2527
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2528
+ bim,
2529
+ true);
2530
+ } catch (Exception e)
2531
+ {
2532
+ throw new javax.media.opengl.GLException(e);
2533
+ }
2534
+
2535
+ if (bump)
2536
+ texturedata = ConvertBump(texturedata, false);
2537
+
2538
+ return texturedata;
24352539 }
24362540
24372541 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3504,6 +3608,8 @@
35043608
35053609 System.out.println("LOADING TEXTURE : " + name);
35063610
3611
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3612
+
35073613 //
35083614 if (false) // compressbit > 0)
35093615 {
....@@ -7902,7 +8008,7 @@
79028008 String pigment = Object3D.GetPigment(tex);
79038009 String bump = Object3D.GetBump(tex);
79048010
7905
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8011
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79068012 {
79078013 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79088014 // System.out.println("; bump = " + bump);
....@@ -7917,11 +8023,69 @@
79178023 pigment = null;
79188024 }
79198025
7920
- ReleaseTexture(bump, true);
7921
- ReleaseTexture(pigment, false);
8026
+ ReleaseTexture(tex, true);
8027
+ ReleaseTexture(tex, false);
79228028 }
79238029
7924
- void ReleaseTexture(String tex, boolean bump)
8030
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
8031
+ {
8032
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8033
+ {
8034
+ return;
8035
+ }
8036
+
8037
+ if (tex == null)
8038
+ {
8039
+ ReleaseTexture(null, false);
8040
+ return;
8041
+ }
8042
+
8043
+ String pigment = Object3D.GetPigment(tex);
8044
+
8045
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8046
+ {
8047
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8048
+ // System.out.println("; bump = " + bump);
8049
+ }
8050
+
8051
+ if (pigment.equals(""))
8052
+ {
8053
+ pigment = null;
8054
+ }
8055
+
8056
+ ReleaseTexture(tex, false);
8057
+ }
8058
+
8059
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
8060
+ {
8061
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8062
+ {
8063
+ return;
8064
+ }
8065
+
8066
+ if (tex == null)
8067
+ {
8068
+ ReleaseTexture(null, true);
8069
+ return;
8070
+ }
8071
+
8072
+ String bump = Object3D.GetBump(tex);
8073
+
8074
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8075
+ {
8076
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8077
+ // System.out.println("; bump = " + bump);
8078
+ }
8079
+
8080
+ if (bump.equals(""))
8081
+ {
8082
+ bump = null;
8083
+ }
8084
+
8085
+ ReleaseTexture(tex, true);
8086
+ }
8087
+
8088
+ void ReleaseTexture(cTexture tex, boolean bump)
79258089 {
79268090 if (// DrawMode() != 0 || /*tex == null ||*/
79278091 ambientOcclusion ) // || !textureon)
....@@ -7932,7 +8096,7 @@
79328096 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
79338097
79348098 if (tex != null)
7935
- texture = textures.get(tex);
8099
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
79368100
79378101 // //assert( texture != null );
79388102 // if (texture == null)
....@@ -8026,6 +8190,54 @@
80268190
80278191 /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
80288192 {
8193
+// if (// DrawMode() != 0 || /*tex == null ||*/
8194
+// ambientOcclusion ) // || !textureon)
8195
+// {
8196
+// return; // false;
8197
+// }
8198
+//
8199
+// if (tex == null)
8200
+// {
8201
+// BindTexture(null,false,resolution);
8202
+// BindTexture(null,true,resolution);
8203
+// return;
8204
+// }
8205
+//
8206
+// String pigment = Object3D.GetPigment(tex);
8207
+// String bump = Object3D.GetBump(tex);
8208
+//
8209
+// usedtextures.add(pigment);
8210
+// usedtextures.add(bump);
8211
+//
8212
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8213
+// {
8214
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8215
+// // System.out.println("; bump = " + bump);
8216
+// }
8217
+//
8218
+// if (bump.equals(""))
8219
+// {
8220
+// bump = null;
8221
+// }
8222
+// if (pigment.equals(""))
8223
+// {
8224
+// pigment = null;
8225
+// }
8226
+//
8227
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8228
+// BindTexture(pigment, false, resolution);
8229
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8230
+// BindTexture(bump, true, resolution);
8231
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8232
+//
8233
+// return; // true;
8234
+
8235
+ BindPigmentTexture(tex, resolution);
8236
+ BindBumpTexture(tex, resolution);
8237
+ }
8238
+
8239
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8240
+ {
80298241 if (// DrawMode() != 0 || /*tex == null ||*/
80308242 ambientOcclusion ) // || !textureon)
80318243 {
....@@ -8035,17 +8247,47 @@
80358247 if (tex == null)
80368248 {
80378249 BindTexture(null,false,resolution);
8038
- BindTexture(null,true,resolution);
80398250 return;
80408251 }
80418252
80428253 String pigment = Object3D.GetPigment(tex);
8254
+
8255
+ usedtextures.add(tex);
8256
+
8257
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8258
+ {
8259
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8260
+ // System.out.println("; bump = " + bump);
8261
+ }
8262
+
8263
+ if (pigment.equals(""))
8264
+ {
8265
+ pigment = null;
8266
+ }
8267
+
8268
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8269
+ BindTexture(tex, false, resolution);
8270
+ }
8271
+
8272
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8273
+ {
8274
+ if (// DrawMode() != 0 || /*tex == null ||*/
8275
+ ambientOcclusion ) // || !textureon)
8276
+ {
8277
+ return; // false;
8278
+ }
8279
+
8280
+ if (tex == null)
8281
+ {
8282
+ BindTexture(null,true,resolution);
8283
+ return;
8284
+ }
8285
+
80438286 String bump = Object3D.GetBump(tex);
80448287
8045
- usedtextures.put(pigment, pigment);
8046
- usedtextures.put(bump, bump);
8288
+ usedtextures.add(tex);
80478289
8048
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8290
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
80498291 {
80508292 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
80518293 // System.out.println("; bump = " + bump);
....@@ -8055,18 +8297,10 @@
80558297 {
80568298 bump = null;
80578299 }
8058
- if (pigment.equals(""))
8059
- {
8060
- pigment = null;
8061
- }
80628300
8063
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8064
- BindTexture(pigment, false, resolution);
80658301 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8066
- BindTexture(bump, true, resolution);
8302
+ BindTexture(tex, true, resolution);
80678303 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8068
-
8069
- return; // true;
80708304 }
80718305
80728306 java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
....@@ -8089,13 +8323,19 @@
80898323 return fileExists;
80908324 }
80918325
8092
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception
8326
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
80938327 {
8094
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8328
+ CacheTexture texturecache = null;
80958329
80968330 if (tex != null)
80978331 {
8098
- String texname = tex;
8332
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8333
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
8334
+
8335
+ if (texname.equals("") && texdata == null)
8336
+ {
8337
+ return null;
8338
+ }
80998339
81008340 String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
81018341
....@@ -8105,19 +8345,46 @@
81058345 // else
81068346 // if (!texname.startsWith("/"))
81078347 // texname = "/Users/nbriere/Textures/" + texname;
8108
- if (!FileExists(tex))
8348
+ if (!FileExists(texname))
81098349 {
81108350 texname = fallbackTextureName;
81118351 }
81128352
81138353 if (CACHETEXTURE)
8114
- texture = textures.get(texname); // TEXTURE CACHE
8115
-
8116
- TextureData texturedata = null;
8117
-
8118
- if (texture == null || texture.resolution < resolution)
81198354 {
8120
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8355
+ if (texdata == null)
8356
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8357
+ else
8358
+ texturecache = bimtextures.get(texdata);
8359
+ }
8360
+
8361
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8362
+ {
8363
+ TextureData texturedata = null;
8364
+
8365
+ if (texdata != null && textureon)
8366
+ {
8367
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8368
+
8369
+ try
8370
+ {
8371
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8372
+ }
8373
+ catch (Exception e)
8374
+ {
8375
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8376
+ }
8377
+
8378
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8379
+ bimtextures.put(texdata, texturecache);
8380
+
8381
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8382
+
8383
+ //Object bim2 = CreateBim(texturecache.texturedata);
8384
+ //bim2 = bim;
8385
+ }
8386
+ else
8387
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
81218388 {
81228389 assert(!bump);
81238390 // if (bump)
....@@ -8128,19 +8395,23 @@
81288395 // }
81298396 // else
81308397 // {
8131
- texture = textures.get(tex);
8132
- if (texture == null)
8398
+ // texturecache = textures.get(texname); // suspicious
8399
+ if (texturecache == null)
81338400 {
8134
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8401
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
81358402 }
8403
+ else
8404
+ new Exception().printStackTrace();
81368405 // }
81378406 } else
8138
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8407
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
81398408 {
81408409 assert(bump);
8141
- texture = textures.get(tex);
8142
- if (texture == null)
8143
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8410
+ // texturecache = textures.get(texname); // suspicious
8411
+ if (texturecache == null)
8412
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8413
+ else
8414
+ new Exception().printStackTrace();
81448415 } else
81458416 {
81468417 //if (tex.equals("IMMORTAL"))
....@@ -8148,11 +8419,13 @@
81488419 // texture = GetResourceTexture("default.png");
81498420 //} else
81508421 //{
8151
- if (tex.equals("WHITE_NOISE"))
8422
+ if (texname.endsWith("WHITE_NOISE"))
81528423 {
8153
- texture = textures.get(tex);
8154
- if (texture == null)
8155
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8424
+ // texturecache = textures.get(texname); // suspicious
8425
+ if (texturecache == null)
8426
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8427
+ else
8428
+ new Exception().printStackTrace();
81568429 } else
81578430 {
81588431 if (textureon)
....@@ -8211,19 +8484,19 @@
82118484 if (texturedata == null)
82128485 throw new Exception();
82138486
8214
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8487
+ texturecache = new CacheTexture(texturedata,resolution);
82158488 //texture = GetTexture(tex, bump);
82168489 }
82178490 }
82188491 //}
82198492 }
82208493
8221
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8494
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
82228495 {
82238496 //return false;
82248497
82258498 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8226
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8499
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
82278500 {
82288501 // String ext = "_highres";
82298502 // if (REDUCETEXTURE)
....@@ -8240,52 +8513,17 @@
82408513 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
82418514 if (!cachefile.exists())
82428515 {
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))
8516
+ //if (texturedata.getWidth() == texturedata.getHeight())
82528517 {
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);
8518
+ BufferedImage rendImage = CreateBim(texturedata);
8519
+
82838520 ImageWriter writer = null;
82848521 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
82858522 if (iter.hasNext()) {
82868523 writer = (ImageWriter)iter.next();
82878524 }
8288
- float compressionQuality = 0.9f;
8525
+
8526
+ float compressionQuality = 0.85f;
82898527 try
82908528 {
82918529 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8302,18 +8540,20 @@
83028540 }
83038541 }
83048542 }
8305
-
8543
+
8544
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8545
+
83068546 //System.out.println("Texture = " + tex);
8307
- if (textures.containsKey(texname))
8547
+ if (textures.containsKey(tex))
83088548 {
8309
- CacheTexture thetex = textures.get(texname);
8549
+ CacheTexture thetex = textures.get(tex);
83108550 thetex.texture.disable();
83118551 thetex.texture.dispose();
8312
- textures.remove(texname);
8552
+ textures.remove(tex);
83138553 }
83148554
8315
- texture.texturedata = texturedata;
8316
- textures.put(texname, texture);
8555
+ //texture.texturedata = texturedata;
8556
+ textures.put(tex, texturecache);
83178557
83188558 // newtex = true;
83198559 }
....@@ -8329,10 +8569,44 @@
83298569 }
83308570 }
83318571
8332
- return texture;
8572
+ return texturecache;
83338573 }
83348574
8335
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution) throws Exception
8575
+ static void EmbedTextures(cTexture tex)
8576
+ {
8577
+ if (tex.pigmentdata == null)
8578
+ {
8579
+ //String texname = Object3D.GetPigment(tex);
8580
+
8581
+ CacheTexture texturecache = texturepigment.get(tex);
8582
+
8583
+ if (texturecache != null)
8584
+ {
8585
+ tex.pw = texturecache.texturedata.getWidth();
8586
+ tex.ph = texturecache.texturedata.getHeight();
8587
+ tex.pigmentdata = //CompressJPEG(CreateBim
8588
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8589
+ ;
8590
+ //, tex.pw, tex.ph), 0.5f);
8591
+ }
8592
+ }
8593
+
8594
+ if (tex.bumpdata == null)
8595
+ {
8596
+ //String texname = Object3D.GetBump(tex);
8597
+
8598
+ CacheTexture texturecache = texturebump.get(tex);
8599
+
8600
+ if (texturecache != null)
8601
+ {
8602
+ tex.bw = texturecache.texturedata.getWidth();
8603
+ tex.bh = texturecache.texturedata.getHeight();
8604
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8605
+ }
8606
+ }
8607
+ }
8608
+
8609
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
83368610 {
83378611 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
83388612
....@@ -8350,21 +8624,21 @@
83508624 return texture!=null?texture.texture:null;
83518625 }
83528626
8353
- public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution) throws Exception
8627
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
83548628 {
83558629 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
83568630
83578631 return texture!=null?texture.texturedata:null;
83588632 }
83598633
8360
- boolean BindTexture(String tex, boolean bump, int resolution) throws Exception
8634
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
83618635 {
83628636 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
83638637 {
83648638 return false;
83658639 }
83668640
8367
- boolean newtex = false;
8641
+ //boolean newtex = false;
83688642
83698643 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
83708644
....@@ -8396,9 +8670,75 @@
83968670 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
83978671 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
83988672
8399
- return newtex;
8673
+ return true; // Warning: not used.
84008674 }
84018675
8676
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8677
+ {
8678
+ try
8679
+ {
8680
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8681
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8682
+ ImageWriter writer = writers.next();
8683
+
8684
+ ImageWriteParam param = writer.getDefaultWriteParam();
8685
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8686
+ param.setCompressionQuality(quality);
8687
+
8688
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8689
+ writer.setOutput(ios);
8690
+ writer.write(null, new IIOImage(image, null, null), param);
8691
+
8692
+ byte[] data = baos.toByteArray();
8693
+ writer.dispose();
8694
+ return data;
8695
+ }
8696
+ catch (Exception e)
8697
+ {
8698
+ e.printStackTrace();
8699
+ return null;
8700
+ }
8701
+ }
8702
+
8703
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8704
+ {
8705
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8706
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8707
+ ImageReader reader = writers.next();
8708
+
8709
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8710
+
8711
+ ImageReadParam param = reader.getDefaultReadParam();
8712
+ param.setDestination(bim);
8713
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8714
+
8715
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8716
+ reader.setInput(ios);
8717
+ BufferedImage bim2 = reader.read(0, param);
8718
+ reader.dispose();
8719
+
8720
+// WritableRaster raster = bim2.getRaster();
8721
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8722
+// byte[] bytes = data.getData();
8723
+//
8724
+// int[] pixels = new int[bytes.length/3];
8725
+// for (int i=pixels.length; --i>=0;)
8726
+// {
8727
+// int i3 = i*3;
8728
+// pixels[i] = 0xFF;
8729
+// pixels[i] <<= 8;
8730
+// pixels[i] |= bytes[i3+2] & 0xFF;
8731
+// pixels[i] <<= 8;
8732
+// pixels[i] |= bytes[i3+1] & 0xFF;
8733
+// pixels[i] <<= 8;
8734
+// pixels[i] |= bytes[i3] & 0xFF;
8735
+// }
8736
+//
8737
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8738
+
8739
+ return bim;
8740
+ }
8741
+
84028742 ShadowBuffer shadowPBuf;
84038743 AntialiasBuffer antialiasPBuf;
84048744 int MAXSTACK;
....@@ -9234,11 +9574,35 @@
92349574 jy8[3] = 0.5f;
92359575 }
92369576
9237
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9577
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
92389578 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
92399579 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
92409580 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
92419581
9582
+ void ResetOptions()
9583
+ {
9584
+ options1[0] = 100;
9585
+ options1[1] = 0.025f;
9586
+ options1[2] = 0.01f;
9587
+ options1[3] = 0;
9588
+ options1[4] = 0;
9589
+
9590
+ options2[0] = 0;
9591
+ options2[1] = 0.75f;
9592
+ options2[2] = 0;
9593
+ options2[3] = 0;
9594
+
9595
+ options3[0] = 1;
9596
+ options3[1] = 1;
9597
+ options3[2] = 1;
9598
+ options3[3] = 0;
9599
+
9600
+ options4[0] = 1;
9601
+ options4[1] = 0;
9602
+ options4[2] = 1;
9603
+ options4[3] = 0;
9604
+ }
9605
+
92429606 static int imagecount = 0; // movie generation
92439607
92449608 static int jitter = 0;
....@@ -9335,7 +9699,7 @@
93359699
93369700 if (renderCamera != lightCamera)
93379701 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9338
- LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
9702
+ LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
93399703
93409704 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
93419705
....@@ -9351,7 +9715,7 @@
93519715
93529716 if (renderCamera != lightCamera)
93539717 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9354
- LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
9718
+ LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
93559719
93569720 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
93579721
....@@ -10349,6 +10713,7 @@
1034910713 ANTIALIAS = 0;
1035010714 //System.out.println("RESTART");
1035110715 AAtimer.restart();
10716
+ Globals.TIMERRUNNING = true;
1035210717 }
1035310718 }
1035410719 }
....@@ -10416,7 +10781,8 @@
1041610781 ambientOcclusion = false;
1041710782 }
1041810783
10419
- if (Globals.lighttouched && DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
10784
+ if (//Globals.lighttouched &&
10785
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1042010786 {
1042110787 //if (RENDERSHADOW) // ?
1042210788 if (!IsFrozen())
....@@ -10550,7 +10916,7 @@
1055010916 // if (parentcam != renderCamera) // not a light
1055110917 if (cam != lightCamera)
1055210918 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10553
- LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
10919
+ LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
1055410920
1055510921 for (int j = 0; j < 4; j++)
1055610922 {
....@@ -10565,7 +10931,7 @@
1056510931 // if (parentcam != renderCamera) // not a light
1056610932 if (cam != lightCamera)
1056710933 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10568
- LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
10934
+ LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
1056910935
1057010936 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1057110937
....@@ -10856,9 +11222,9 @@
1085611222
1085711223 gl.glMatrixMode(GL.GL_MODELVIEW);
1085811224
10859
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10860
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10861
-//gl.glEnable(gl.GL_MULTISAMPLE);
11225
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11226
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11227
+gl.glEnable(gl.GL_MULTISAMPLE);
1086211228 } else
1086311229 {
1086411230 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -10869,7 +11235,7 @@
1086911235 //System.out.println("BLENDING ON");
1087011236 gl.glEnable(GL.GL_BLEND);
1087111237 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
10872
-
11238
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1087311239 gl.glMatrixMode(gl.GL_PROJECTION);
1087411240 gl.glLoadIdentity();
1087511241
....@@ -10959,7 +11325,7 @@
1095911325
1096011326 // if (cam != lightCamera)
1096111327 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10962
- LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
11328
+ LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
1096311329 }
1096411330
1096511331 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -10981,7 +11347,7 @@
1098111347 {
1098211348 if (cam != lightCamera)
1098311349 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10984
- LA.xformDir(light0, parentcam.GlobalTransformInv(), light0); // may 2013
11350
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
1098511351 }
1098611352
1098711353 LA.xformPos(light0, cam.toScreen, light0);
....@@ -11118,7 +11484,7 @@
1111811484 }
1111911485 }
1112011486
11121
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11487
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1112211488 {
1112311489 //gl.glDepthFunc(GL.GL_LEQUAL);
1112411490 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11126,24 +11492,21 @@
1112611492
1112711493 boolean texon = textureon;
1112811494
11129
- if (RENDERPROGRAM > 0)
11130
- {
11131
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11132
- textureon = false;
11133
- }
11495
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11496
+ textureon = false;
11497
+
1113411498 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1113511499 //System.out.println("ALLO");
1113611500 gl.glColorMask(false, false, false, false);
1113711501 DrawObject(gl);
11138
- if (RENDERPROGRAM > 0)
11139
- {
11140
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11141
- textureon = texon;
11142
- }
11502
+
11503
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11504
+ textureon = texon;
11505
+
1114311506 gl.glColorMask(true, true, true, true);
1114411507
1114511508 gl.glDepthFunc(GL.GL_EQUAL);
11146
- //gl.glDepthMask(false);
11509
+ gl.glDepthMask(false);
1114711510 }
1114811511
1114911512 if (false) // DrawMode() == SHADOW)
....@@ -11326,15 +11689,36 @@
1132611689
1132711690 static boolean zoomonce = false;
1132811691
11692
+ static void CreateSelectedPoint()
11693
+ {
11694
+ if (selectedpoint == null)
11695
+ {
11696
+ debugpointG = new Sphere();
11697
+ debugpointP = new Sphere();
11698
+ debugpointC = new Sphere();
11699
+ debugpointR = new Sphere();
11700
+
11701
+ selectedpoint = new Superellipsoid();
11702
+
11703
+ for (int i=0; i<8; i++)
11704
+ {
11705
+ debugpoints[i] = new Sphere();
11706
+ }
11707
+ }
11708
+ }
11709
+
1132911710 void DrawObject(GL gl, boolean draw)
1133011711 {
11712
+ // To clear camera values
11713
+ ResetOptions();
11714
+
1133111715 //System.out.println("DRAW OBJECT " + mouseDown);
1133211716 // DrawMode() = SELECTION;
1133311717 //GL gl = getGL();
1133411718 if ((TRACK || SHADOWTRACK) || zoomonce)
1133511719 {
1133611720 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11337
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11721
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1133811722 pingthread.StepToTarget(true); // true);
1133911723 // zoomonce = false;
1134011724 }
....@@ -11406,8 +11790,9 @@
1140611790
1140711791 if (DrawMode() == DEFAULT)
1140811792 {
11409
- if (DEBUG)
11793
+ if (Globals.DEBUG)
1141011794 {
11795
+ CreateSelectedPoint();
1141111796 float radius = 0.05f;
1141211797 if (selectedpoint.radius != radius)
1141311798 {
....@@ -11461,20 +11846,32 @@
1146111846 ReleaseTextures(DEFAULT_TEXTURES);
1146211847
1146311848 if (CLEANCACHE)
11464
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11849
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1146511850 {
11466
- String tex = e.nextElement();
11851
+ cTexture tex = e.nextElement();
1146711852
1146811853 // System.out.println("Texture --------- " + tex);
1146911854
11470
- if (tex.equals("WHITE_NOISE"))
11855
+ if (tex.equals("WHITE_NOISE:"))
1147111856 continue;
1147211857
11473
- if (!usedtextures.containsKey(tex))
11858
+ if (!usedtextures.contains(tex))
1147411859 {
11860
+ CacheTexture gettex = texturepigment.get(tex);
1147511861 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11476
- textures.get(tex).texture.dispose();
11477
- textures.remove(tex);
11862
+ if (gettex != null)
11863
+ {
11864
+ gettex.texture.dispose();
11865
+ texturepigment.remove(tex);
11866
+ }
11867
+
11868
+ gettex = texturebump.get(tex);
11869
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11870
+ if (gettex != null)
11871
+ {
11872
+ gettex.texture.dispose();
11873
+ texturebump.remove(tex);
11874
+ }
1147811875 }
1147911876 }
1148011877 }
....@@ -11912,7 +12309,7 @@
1191212309 }
1191312310
1191412311 //for (int count = parentcam.GetTransformCount(); --count>=0;)
11915
- LA.xformPos(light, parentcam.GlobalTransformInv(), light); // may 2013
12312
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1191612313
1191712314 LA.xformPos(light, renderCamera.toScreen, light);
1191812315
....@@ -12003,7 +12400,52 @@
1200312400 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1200412401
1200512402 String program =
12403
+ // Min shader
1200612404 "!!ARBfp1.0\n" +
12405
+ "PARAM zero123 = { 0.0, 1.0, 2.0, 1.25 };" +
12406
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12407
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12408
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12409
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12410
+ "TEMP temp;" +
12411
+ "TEMP light;" +
12412
+ "TEMP ndotl;" +
12413
+ "TEMP normal;" +
12414
+ "TEMP depth;" +
12415
+
12416
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12417
+
12418
+ "MOV light, state.light[0].position;" +
12419
+ "DP3 ndotl.x, light, normal;" +
12420
+
12421
+ // shadow
12422
+ "MOV temp, fragment.texcoord[1];" +
12423
+ TextureFetch("depth", "temp", "1") +
12424
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12425
+ "SLT temp.x, fragment.texcoord[1].z, depth.z;" +
12426
+
12427
+
12428
+ // No shadow when out of frustum
12429
+ //"SGE temp.y, depth.z, zero123.y;" +
12430
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12431
+
12432
+ "MUL ndotl.x, ndotl.x, temp.x;" +
12433
+ "MAX ndotl.x, ndotl.x, pow2.y;" +
12434
+
12435
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12436
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12437
+ "MUL temp, temp, ndotl.x;" +
12438
+
12439
+ "MUL temp, temp, zero123.z;" +
12440
+
12441
+ "MOV temp.w, zero123.y;" + // reset alpha
12442
+
12443
+ "MOV result.color, temp;" +
12444
+ "END";
12445
+
12446
+ String program2 =
12447
+ "!!ARBfp1.0\n" +
12448
+
1200712449 //"OPTION ARB_fragment_program_shadow;" +
1200812450 "PARAM light2cam0 = program.env[10];" +
1200912451 "PARAM light2cam1 = program.env[11];" +
....@@ -12118,8 +12560,7 @@
1211812560 "TEMP shininess;" +
1211912561 "\n" +
1212012562 "MOV texSamp, one;" +
12121
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12122
-
12563
+
1212312564 "MOV mapgrid.x, one2048th.x;" +
1212412565 "MOV temp, fragment.texcoord[1];" +
1212512566 /*
....@@ -12524,7 +12965,7 @@
1252412965 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1252512966 "") +
1252612967
12527
- // display shadow only (bump == 0)
12968
+ // display shadow only (fakedepth == 0)
1252812969 "SUB temp.x, half.x, shadow.x;" +
1252912970 "MOV temp.y, -params5.z;" + // params6.x;" +
1253012971 "SLT temp.z, temp.y, -one2048th.x;" +
....@@ -12956,20 +13397,20 @@
1295613397 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1295713398 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1295813399 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13400
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13401
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1295913402 "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;" +
13403
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13404
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1296413405 //"SWZ buffer, temp, w,w,w,w;";
12965
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13406
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1296613407 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1296713408 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1296813409 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
12969
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13410
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1297013411
12971
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
12972
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13412
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13413
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1297313414 }
1297413415
1297513416 String Shadow(String depth, String shadow)
....@@ -13016,7 +13457,7 @@
1301613457 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1301713458 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1301813459
13019
- // No shadow when out of frustrum
13460
+ // No shadow when out of frustum
1302013461 "SGE temp.x, " + depth + ".z, one.z;" +
1302113462 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1302213463 "";
....@@ -13164,7 +13605,8 @@
1316413605 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1316513606 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1316613607 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13167
- Object3D.cVector2[] vector2buffer;
13608
+
13609
+ //Object3D.cVector2[] vector2buffer;
1316813610
1316913611 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1317013612 // OUT : diff, spec
....@@ -13180,9 +13622,10 @@
1318013622 "DP3 " + dest + ".z," + "normals," + "eye;" +
1318113623 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1318213624 //"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;" +
13625
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13626
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13627
+
13628
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1318613629 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1318713630 "RCP " + dest + ".w," + dest + ".w;" +
1318813631 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13687,6 +14130,7 @@
1368714130 else
1368814131 if (evt.getSource() == AAtimer)
1368914132 {
14133
+ Globals.TIMERRUNNING = false;
1369014134 if (mouseDown)
1369114135 {
1369214136 //new Exception().printStackTrace();
....@@ -13746,7 +14190,7 @@
1374614190
1374714191 // fev 2014???
1374814192 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13749
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14193
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1375014194 pingthread.StepToTarget(true); // true);
1375114195 }
1375214196 // if (!LIVE)
....@@ -13761,6 +14205,7 @@
1376114205 return;
1376214206
1376314207 AAtimer.restart(); //
14208
+ Globals.TIMERRUNNING = true;
1376414209
1376514210 // waslive = LIVE;
1376614211 // LIVE = false;
....@@ -13810,14 +14255,15 @@
1381014255 drag = false;
1381114256 //System.out.println("Mouse DOWN");
1381214257 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);
14258
+ //ClickInfo info = new ClickInfo();
14259
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14260
+ object.clickInfo.pane = this;
14261
+ object.clickInfo.camera = renderCamera;
14262
+ object.clickInfo.x = x;
14263
+ object.clickInfo.y = y;
14264
+ object.clickInfo.modifiers = modifiersex;
14265
+ editObj = object.doEditClick(//info,
14266
+ 0);
1382114267 if (!editObj)
1382214268 {
1382314269 hasMarquee = true;
....@@ -13833,6 +14279,8 @@
1383314279
1383414280 public void mouseDragged(MouseEvent e)
1383514281 {
14282
+ Globals.MOUSEDRAGGED = true;
14283
+
1383614284 //System.out.println("mouseDragged: " + e);
1383714285 if (isRenderer)
1383814286 movingcamera = true;
....@@ -14097,12 +14545,12 @@
1409714545 void GoDown(int mod)
1409814546 {
1409914547 MODIFIERS |= COMMAND;
14100
- /*
14548
+ /**/
1410114549 if((mod&SHIFT) == SHIFT)
1410214550 manipCamera.RotatePosition(0, -speed);
1410314551 else
14104
- manipCamera.BackForth(0, -speed*delta, getWidth());
14105
- */
14552
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14553
+ /**/
1410614554 if ((mod & SHIFT) == SHIFT)
1410714555 {
1410814556 mouseMode = mouseMode; // VR??
....@@ -14118,12 +14566,12 @@
1411814566 void GoUp(int mod)
1411914567 {
1412014568 MODIFIERS |= COMMAND;
14121
- /*
14569
+ /**/
1412214570 if((mod&SHIFT) == SHIFT)
1412314571 manipCamera.RotatePosition(0, speed);
1412414572 else
14125
- manipCamera.BackForth(0, speed*delta, getWidth());
14126
- */
14573
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14574
+ /**/
1412714575 if ((mod & SHIFT) == SHIFT)
1412814576 {
1412914577 mouseMode = mouseMode;
....@@ -14139,12 +14587,12 @@
1413914587 void GoLeft(int mod)
1414014588 {
1414114589 MODIFIERS |= COMMAND;
14142
- /*
14590
+ /**/
1414314591 if((mod&SHIFT) == SHIFT)
14144
- manipCamera.RotatePosition(speed, 0);
14145
- else
1414614592 manipCamera.Translate(speed*delta, 0, getWidth());
14147
- */
14593
+ else
14594
+ manipCamera.RotatePosition(speed, 0);
14595
+ /**/
1414814596 if ((mod & SHIFT) == SHIFT)
1414914597 {
1415014598 mouseMode = mouseMode;
....@@ -14160,12 +14608,12 @@
1416014608 void GoRight(int mod)
1416114609 {
1416214610 MODIFIERS |= COMMAND;
14163
- /*
14611
+ /**/
1416414612 if((mod&SHIFT) == SHIFT)
14165
- manipCamera.RotatePosition(-speed, 0);
14166
- else
1416714613 manipCamera.Translate(-speed*delta, 0, getWidth());
14168
- */
14614
+ else
14615
+ manipCamera.RotatePosition(-speed, 0);
14616
+ /**/
1416914617 if ((mod & SHIFT) == SHIFT)
1417014618 {
1417114619 mouseMode = mouseMode;
....@@ -14215,14 +14663,16 @@
1421514663 if (editObj)
1421614664 {
1421714665 drag = true;
14218
- ClickInfo info = new ClickInfo();
14219
- info.bounds.setBounds(0, 0,
14666
+ //ClickInfo info = new ClickInfo();
14667
+ object.clickInfo.bounds.setBounds(0, 0,
1422014668 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14221
- info.pane = this;
14222
- info.camera = renderCamera;
14223
- info.x = x;
14224
- info.y = y;
14225
- object.editWindow.copy.doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
14669
+ object.clickInfo.pane = this;
14670
+ object.clickInfo.camera = renderCamera;
14671
+ object.clickInfo.x = x;
14672
+ object.clickInfo.y = y;
14673
+ object //.GetWindow().copy
14674
+ .doEditDrag(//info,
14675
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1422614676 } else
1422714677 {
1422814678 if (x < startX)
....@@ -14371,22 +14821,27 @@
1437114821 }
1437214822 }
1437314823
14824
+// ClickInfo clickInfo = new ClickInfo();
14825
+
1437414826 public void mouseMoved(MouseEvent e)
1437514827 {
1437614828 //System.out.println("mouseMoved: " + e);
1437714829 if (isRenderer)
1437814830 return;
1437914831
14380
- ClickInfo ci = new ClickInfo();
14381
- ci.x = e.getX();
14382
- ci.y = e.getY();
14383
- ci.modifiers = e.getModifiersEx();
14384
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14385
- ci.pane = this;
14386
- ci.camera = renderCamera;
14832
+ // Mouse cursor feedback
14833
+ object.clickInfo.x = e.getX();
14834
+ object.clickInfo.y = e.getY();
14835
+ object.clickInfo.modifiers = e.getModifiersEx();
14836
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14837
+ object.clickInfo.pane = this;
14838
+ object.clickInfo.camera = renderCamera;
1438714839 if (!isRenderer)
1438814840 {
14389
- if (object.editWindow.copy.doEditClick(ci, 0))
14841
+ //ObjEditor editWindow = object.editWindow;
14842
+ //Object3D copy = editWindow.copy;
14843
+ if (object.doEditClick(//clickInfo,
14844
+ 0))
1439014845 {
1439114846 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1439214847 } else
....@@ -14398,8 +14853,11 @@
1439814853
1439914854 public void mouseReleased(MouseEvent e)
1440014855 {
14856
+ Globals.MOUSEDRAGGED = false;
14857
+
1440114858 movingcamera = false;
14402
- X = Y = 0;
14859
+ X = 0; // getBounds().width/2;
14860
+ Y = 0; // getBounds().height/2;
1440314861 //System.out.println("mouseReleased: " + e);
1440414862 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1440514863 }
....@@ -14655,7 +15113,8 @@
1465515113 // break;
1465615114 case 'T':
1465715115 CACHETEXTURE ^= true;
14658
- textures.clear();
15116
+ texturepigment.clear();
15117
+ texturebump.clear();
1465915118 // repaint();
1466015119 break;
1466115120 case 'Y':
....@@ -14740,7 +15199,9 @@
1474015199 case 'E' : COMPACT ^= true;
1474115200 repaint();
1474215201 break;
14743
- case 'W' : DEBUGHSB ^= true;
15202
+ case 'W' : // Wide Window (fullscreen)
15203
+ //DEBUGHSB ^= true;
15204
+ ObjEditor.theFrame.ToggleFullScreen();
1474415205 repaint();
1474515206 break;
1474615207 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14765,8 +15226,8 @@
1476515226 RevertCamera();
1476615227 repaint();
1476715228 break;
14768
- case 'L':
1476915229 case 'l':
15230
+ //case 'L':
1477015231 if (lightMode)
1477115232 {
1477215233 lightMode = false;
....@@ -14909,9 +15370,9 @@
1490915370 case '_':
1491015371 kompactbit = 5;
1491115372 break;
14912
- case '+':
14913
- kompactbit = 6;
14914
- break;
15373
+// case '+':
15374
+// kompactbit = 6;
15375
+// break;
1491515376 case ' ':
1491615377 lightMode ^= true;
1491715378 Globals.lighttouched = true;
....@@ -14923,6 +15384,7 @@
1492315384 case ESC:
1492415385 RENDERPROGRAM += 1;
1492515386 RENDERPROGRAM %= 3;
15387
+
1492615388 repaint();
1492715389 break;
1492815390 case 'Z':
....@@ -14962,8 +15424,9 @@
1496215424 case DELETE:
1496315425 ClearSelection();
1496415426 break;
14965
- /*
1496615427 case '+':
15428
+
15429
+ /*
1496715430 //fontsize += 1;
1496815431 bbzoom *= 2;
1496915432 repaint();
....@@ -14980,17 +15443,17 @@
1498015443 case '=':
1498115444 IncDepth();
1498215445 //fontsize += 1;
14983
- object.editWindow.refreshContents(true);
15446
+ object.GetWindow().refreshContents(true);
1498415447 maskbit = 6;
1498515448 break;
1498615449 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1498715450 DecDepth();
1498815451 maskbit = 5;
1498915452 //if(fontsize > 1) fontsize -= 1;
14990
- if (object.editWindow == null)
14991
- new Exception().printStackTrace();
14992
- else
14993
- object.editWindow.refreshContents(true);
15453
+// if (object.editWindow == null)
15454
+// new Exception().printStackTrace();
15455
+// else
15456
+ object.GetWindow().refreshContents(true);
1499415457 break;
1499515458 case '{':
1499615459 manipCamera.shaper_fovy /= 1.1;
....@@ -15214,7 +15677,7 @@
1521415677 }
1521515678 */
1521615679
15217
- object.editWindow.EditSelection();
15680
+ object.GetWindow().EditSelection(false);
1521815681 }
1521915682
1522015683 void SelectParent()
....@@ -15231,10 +15694,10 @@
1523115694 {
1523215695 //selectees.remove(i);
1523315696 System.out.println("select parent of " + elem);
15234
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15697
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1523515698 } else
1523615699 {
15237
- group.editWindow.Select(elem.GetTreePath(), first, true);
15700
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1523815701 }
1523915702
1524015703 first = false;
....@@ -15276,12 +15739,12 @@
1527615739 for (int j = 0; j < group.children.size(); j++)
1527715740 {
1527815741 elem = (Object3D) group.children.elementAt(j);
15279
- object.editWindow.Select(elem.GetTreePath(), first, true);
15742
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1528015743 first = false;
1528115744 }
1528215745 } else
1528315746 {
15284
- object.editWindow.Select(elem.GetTreePath(), first, true);
15747
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1528515748 }
1528615749
1528715750 first = false;
....@@ -15292,21 +15755,21 @@
1529215755 {
1529315756 //Composite group = (Composite) object;
1529415757 Object3D group = object;
15295
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15758
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1529615759 }
1529715760
1529815761 void ResetTransform(int mask)
1529915762 {
1530015763 //Composite group = (Composite) object;
1530115764 Object3D group = object;
15302
- group.editWindow.ResetTransform(mask);
15765
+ group.GetWindow().ResetTransform(mask);
1530315766 }
1530415767
1530515768 void FlipTransform()
1530615769 {
1530715770 //Composite group = (Composite) object;
1530815771 Object3D group = object;
15309
- group.editWindow.FlipTransform();
15772
+ group.GetWindow().FlipTransform();
1531015773 // group.editWindow.ReduceMesh(true);
1531115774 }
1531215775
....@@ -15314,7 +15777,7 @@
1531415777 {
1531515778 //Composite group = (Composite) object;
1531615779 Object3D group = object;
15317
- group.editWindow.PrintMemory();
15780
+ group.GetWindow().PrintMemory();
1531815781 // group.editWindow.ReduceMesh(true);
1531915782 }
1532015783
....@@ -15322,7 +15785,7 @@
1532215785 {
1532315786 //Composite group = (Composite) object;
1532415787 Object3D group = object;
15325
- group.editWindow.ResetCentroid();
15788
+ group.GetWindow().ResetCentroid();
1532615789 }
1532715790
1532815791 void IncDepth()
....@@ -15404,8 +15867,6 @@
1540415867
1540515868 int width = getBounds().width;
1540615869 int height = getBounds().height;
15407
- ClickInfo info = new ClickInfo();
15408
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1540915870 //Image img = CreateImage(width, height);
1541015871 //System.out.println("width = " + width + "; height = " + height + "\n");
1541115872
....@@ -15482,43 +15943,77 @@
1548215943 }
1548315944 if (object != null && !hasMarquee)
1548415945 {
15946
+ if (object.clickInfo == null)
15947
+ object.clickInfo = new ClickInfo();
15948
+ ClickInfo info = object.clickInfo;
15949
+ //ClickInfo info = new ClickInfo();
15950
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
15951
+
1548515952 if (isRenderer)
1548615953 {
15487
- info.flags++;
15954
+ object.clickInfo.flags++;
1548815955 double frameAspect = (double) width / (double) height;
1548915956 if (frameAspect > renderCamera.aspect)
1549015957 {
1549115958 int desired = (int) ((double) height * renderCamera.aspect);
15492
- info.bounds.width -= width - desired;
15493
- info.bounds.x += (width - desired) / 2;
15959
+ object.clickInfo.bounds.width -= width - desired;
15960
+ object.clickInfo.bounds.x += (width - desired) / 2;
1549415961 } else
1549515962 {
1549615963 int desired = (int) ((double) width / renderCamera.aspect);
15497
- info.bounds.height -= height - desired;
15498
- info.bounds.y += (height - desired) / 2;
15964
+ object.clickInfo.bounds.height -= height - desired;
15965
+ object.clickInfo.bounds.y += (height - desired) / 2;
1549915966 }
1550015967 }
15501
- info.g = gr;
15502
- info.camera = renderCamera;
15968
+
15969
+ object.clickInfo.g = gr;
15970
+ object.clickInfo.camera = renderCamera;
1550315971 /*
1550415972 // Memory intensive (brep.verticescopy)
1550515973 if (!(object instanceof Composite))
1550615974 object.draw(info, 0, false); // SLOW :
1550715975 */
15508
- if (!isRenderer)
15976
+ if (!isRenderer) // && drag)
1550915977 {
15510
- object.drawEditHandles(info, 0);
15511
-
15512
- if (drag && (X != 0 || Y != 0) && object.selection.Size() > 0)
15978
+ Grafreed.Assert(object != null);
15979
+ Grafreed.Assert(object.selection != null);
15980
+ if (object.selection.Size() > 0)
1551315981 {
15514
- switch (object.selection.get(0).hitSomething)
15982
+ int hitSomething = object.selection.get(0).hitSomething;
15983
+
15984
+ object.clickInfo.DX = 0;
15985
+ object.clickInfo.DY = 0;
15986
+ object.clickInfo.W = 1;
15987
+ if (hitSomething == Object3D.hitCenter)
1551515988 {
15516
- case Object3D.hitCenter: gr.setColor(Color.pink); break;
15517
- case Object3D.hitRotate: gr.setColor(Color.green); break;
15518
- case Object3D.hitScale: gr.setColor(Color.cyan); break;
15989
+ info.DX = X;
15990
+ if (X != 0)
15991
+ info.DX -= info.bounds.width/2;
15992
+
15993
+ info.DY = Y;
15994
+ if (Y != 0)
15995
+ info.DY -= info.bounds.height/2;
1551915996 }
15520
-
15521
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15997
+
15998
+ object.drawEditHandles(//info,
15999
+ 0);
16000
+
16001
+ if (drag && (X != 0 || Y != 0))
16002
+ {
16003
+ switch (hitSomething)
16004
+ {
16005
+ case Object3D.hitCenter: gr.setColor(Color.pink);
16006
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16007
+ break;
16008
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16009
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16010
+ break;
16011
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16012
+ gr.drawLine(X, Y, 0, 0);
16013
+ break;
16014
+ }
16015
+
16016
+ }
1552216017 }
1552316018 }
1552416019 }
....@@ -16221,16 +16716,16 @@
1622116716 cStatic.objectstack[materialdepth++] = checker;
1622216717 //System.out.println("material " + material);
1622316718 //Applet3D.tracein(this, selected);
16224
- vector2buffer = checker.projectedVertices;
16719
+ //vector2buffer = checker.projectedVertices;
1622516720
1622616721 //checker.GetMaterial().Draw(this, false); // true);
16227
- DrawMaterial(checker.GetMaterial(), false); // true);
16722
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1622816723
1622916724 materialdepth -= 1;
1623016725 if (materialdepth > 0)
1623116726 {
16232
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16233
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
16727
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16728
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1623416729 }
1623516730 //checker.GetMaterial().opacity = 1f;
1623616731 ////checker.GetMaterial().ambient = 1f;
....@@ -16316,6 +16811,14 @@
1631616811 }
1631716812 }
1631816813
16814
+ private Object3D GetFolder()
16815
+ {
16816
+ Object3D folder = object.GetWindow().copy;
16817
+ if (object.GetWindow().copy.selection.Size() > 0)
16818
+ folder = object.GetWindow().copy.selection.elementAt(0);
16819
+ return folder;
16820
+ }
16821
+
1631916822 class SelectBuffer implements GLEventListener
1632016823 {
1632116824
....@@ -16395,6 +16898,17 @@
1639516898
1639616899 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1639716900
16901
+ if (PAINTMODE)
16902
+ {
16903
+ if (object.GetWindow().copy.selection.Size() > 0)
16904
+ {
16905
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16906
+
16907
+ // Make what you paint not selectable.
16908
+ paintobj.ResetSelectable();
16909
+ }
16910
+ }
16911
+
1639816912 //int tmp = selection_view;
1639916913 //selection_view = -1;
1640016914 int temp = DrawMode();
....@@ -16406,6 +16920,17 @@
1640616920 // temp = DEFAULT; // patch for selection debug
1640716921 Globals.drawMode = temp; // WARNING
1640816922
16923
+ if (PAINTMODE)
16924
+ {
16925
+ if (object.GetWindow().copy.selection.Size() > 0)
16926
+ {
16927
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16928
+
16929
+ // Revert.
16930
+ paintobj.RestoreSelectable();
16931
+ }
16932
+ }
16933
+
1640916934 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1641016935
1641116936 // trying different ways of getting the depth info over
....@@ -16453,6 +16978,8 @@
1645316978 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1645416979 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1645516980 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
16981
+
16982
+ CreateSelectedPoint();
1645616983
1645716984 // Will fit the mesh !!!
1645816985 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16507,29 +17034,31 @@
1650717034 }
1650817035
1650917036 if (!movingcamera && !PAINTMODE)
16510
- object.editWindow.ScreenFitPoint(); // fev 2014
17037
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1651117038
16512
- if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17039
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1651317040 {
16514
- Object3D paintobj = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17041
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1651517042
16516
- Object3D group = new Object3D("inst" + paintcount++);
17043
+ if (object.GetWindow().copy.selection.Size() > 0)
17044
+ {
17045
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1651717046
16518
- group.CreateMaterial(); // use a void leaf to select instances
16519
-
16520
- group.add(paintobj); // link
16521
-
16522
- object.editWindow.SnapObject(group);
16523
-
16524
- Object3D folder = object.editWindow.copy;
16525
-
16526
- if (object.editWindow.copy.selection.Size() > 0)
16527
- folder = object.editWindow.copy.selection.elementAt(0);
16528
-
16529
- folder.add(group);
16530
-
16531
- object.editWindow.ResetModel();
16532
- object.editWindow.refreshContents();
17047
+ Object3D inst = new Object3D("inst" + paintcount++);
17048
+
17049
+ inst.CreateMaterial(); // use a void leaf to select instances
17050
+
17051
+ inst.add(paintobj); // link
17052
+
17053
+ object.GetWindow().SnapObject(inst);
17054
+
17055
+ Object3D folder = paintFolder; // GetFolder();
17056
+
17057
+ folder.add(inst);
17058
+
17059
+ object.GetWindow().ResetModel();
17060
+ object.GetWindow().refreshContents();
17061
+ }
1653317062 }
1653417063 else
1653517064 paintcount = 0;
....@@ -16568,6 +17097,11 @@
1656817097 //System.out.println("objects[color] = " + objects[color]);
1656917098 //objects[color].Select();
1657017099 indexcount = 0;
17100
+ ObjEditor window = object.GetWindow();
17101
+ if (window != null && deselect)
17102
+ {
17103
+ window.Select(null, deselect, true);
17104
+ }
1657117105 object.Select(color, deselect);
1657217106 }
1657317107
....@@ -17093,23 +17627,15 @@
1709317627 int AAbuffersize = 0;
1709417628
1709517629 //double[] selectedpoint = new double[3];
17096
- static Superellipsoid selectedpoint = new Superellipsoid();
17630
+ static Superellipsoid selectedpoint;
1709717631 static Sphere previousselectedpoint = null;
17098
- static Sphere debugpointG = new Sphere();
17099
- static Sphere debugpointP = new Sphere();
17100
- static Sphere debugpointC = new Sphere();
17101
- static Sphere debugpointR = new Sphere();
17632
+ static Sphere debugpointG;
17633
+ static Sphere debugpointP;
17634
+ static Sphere debugpointC;
17635
+ static Sphere debugpointR;
1710217636
1710317637 static Sphere debugpoints[] = new Sphere[8];
1710417638
17105
- static
17106
- {
17107
- for (int i=0; i<8; i++)
17108
- {
17109
- debugpoints[i] = new Sphere();
17110
- }
17111
- }
17112
-
1711317639 static void InitPoints(float radius)
1711417640 {
1711517641 for (int i=0; i<8; i++)