Normand Briere
2019-08-06 b3ae4e889872ca0b9ca76f1d17b2f0b961226729
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;
....@@ -151,6 +187,18 @@
151187 }
152188
153189 private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
190
+
191
+ public void LoadSkybox(String name, String ext, boolean mipmap) throws GLException
192
+ {
193
+ try
194
+ {
195
+ cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
196
+ } catch (IOException e)
197
+ {
198
+ System.out.println("NAME = " + name);
199
+ e.printStackTrace(); // throw new RuntimeException(e);
200
+ }
201
+ }
154202
155203 void SetAsGLRenderer(boolean b)
156204 {
....@@ -170,7 +218,8 @@
170218
171219 SetCamera(cam);
172220
173
- SetLight(new Camera(new cVector(10, 10, -20)));
221
+ // Warning: not used.
222
+ SetLight(new Camera(new cVector(15, 10, -20)));
174223
175224 object = o;
176225
....@@ -327,7 +376,7 @@
327376 cStatic.objectstack[materialdepth++] = obj;
328377 //System.out.println("material " + material);
329378 //Applet3D.tracein(this, selected);
330
- display.vector2buffer = obj.projectedVertices;
379
+ //display.vector2buffer = obj.projectedVertices;
331380 if (obj instanceof Camera)
332381 {
333382 display.options1[0] = material.shift;
....@@ -336,14 +385,28 @@
336385 display.options1[2] = material.shadowbias;
337386 display.options1[3] = material.aniso;
338387 display.options1[4] = material.anisoV;
388
+// System.out.println("display.options1[0] " + display.options1[0]);
389
+// System.out.println("display.options1[1] " + display.options1[1]);
390
+// System.out.println("display.options1[2] " + display.options1[2]);
391
+// System.out.println("display.options1[3] " + display.options1[3]);
392
+// System.out.println("display.options1[4] " + display.options1[4]);
339393 display.options2[0] = material.opacity;
340394 display.options2[1] = material.diffuse;
341395 display.options2[2] = material.factor;
396
+// System.out.println("display.options2[0] " + display.options2[0]);
397
+// System.out.println("display.options2[1] " + display.options2[1]);
398
+// System.out.println("display.options2[2] " + display.options2[2]);
342399
343400 cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
401
+// System.out.println("display.options3[0] " + display.options3[0]);
402
+// System.out.println("display.options3[1] " + display.options3[1]);
403
+// System.out.println("display.options3[2] " + display.options3[2]);
344404 display.options4[0] = material.cameralight/0.2f;
345405 display.options4[1] = material.subsurface;
346406 display.options4[2] = material.sheen;
407
+// System.out.println("display.options4[0] " + display.options4[0]);
408
+// System.out.println("display.options4[1] " + display.options4[1]);
409
+// System.out.println("display.options4[2] " + display.options4[2]);
347410
348411 // if (display.CURRENTANTIALIAS > 0)
349412 // display.options3[3] /= 4;
....@@ -359,7 +422,7 @@
359422 /**/
360423 } else
361424 {
362
- DrawMaterial(material, selected);
425
+ DrawMaterial(material, selected, obj.projectedVertices);
363426 }
364427 } else
365428 {
....@@ -383,8 +446,8 @@
383446 cStatic.objectstack[materialdepth++] = obj;
384447 //System.out.println("material " + material);
385448 //Applet3D.tracein("selected ", selected);
386
- display.vector2buffer = obj.projectedVertices;
387
- display.DrawMaterial(material, selected);
449
+ //display.vector2buffer = obj.projectedVertices;
450
+ display.DrawMaterial(material, selected, obj.projectedVertices);
388451 }
389452 }
390453
....@@ -401,8 +464,8 @@
401464 materialdepth -= 1;
402465 if (materialdepth > 0)
403466 {
404
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
405
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
467
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
468
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
406469 }
407470 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
408471 } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
....@@ -422,8 +485,8 @@
422485 materialdepth -= 1;
423486 if (materialdepth > 0)
424487 {
425
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
426
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
488
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
489
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
427490 }
428491 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
429492 //else
....@@ -464,10 +527,12 @@
464527 if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
465528 {
466529 //gl.glBegin(gl.GL_TRIANGLES);
467
- boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0);
530
+ boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0)
531
+ // TEST LIVE NORMALS && !obj.dontselect
532
+ ;
468533 if (!hasnorm)
469534 {
470
- // System.out.println("FUCK!!");
535
+ // System.out.println("Mesh normal");
471536 LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
472537 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
473538 LA.vecCross(obj.v0, obj.v1, obj.v2);
....@@ -1192,10 +1257,12 @@
11921257 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
11931258 }
11941259 }
1260
+
11951261 if (flipV)
11961262 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
11971263 else
11981264 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1265
+
11991266 //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
12001267 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
12011268
....@@ -1215,10 +1282,12 @@
12151282 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
12161283 }
12171284 }
1285
+
12181286 if (flipV)
12191287 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12201288 else
12211289 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1290
+
12221291 //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
12231292 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
12241293
....@@ -1246,8 +1315,10 @@
12461315 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12471316 else
12481317 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1318
+
12491319 //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
12501320 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1321
+
12511322 count2 += 2;
12521323 count3 += 3;
12531324 }
....@@ -1426,6 +1497,8 @@
14261497 gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
14271498 }
14281499
1500
+ float[] colorV = new float[4];
1501
+
14291502 void SetColor(Object3D obj, Vertex p0)
14301503 {
14311504 CameraPane display = this;
....@@ -1493,8 +1566,6 @@
14931566 {
14941567 return;
14951568 }
1496
-
1497
- float[] colorV = new float[3];
14981569
14991570 if (false) // marked)
15001571 {
....@@ -1603,7 +1674,7 @@
16031674 // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
16041675 }
16051676
1606
- void DrawMaterial(cMaterial material, boolean selected)
1677
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
16071678 {
16081679 CameraPane display = this;
16091680 //new Exception().printStackTrace();
....@@ -1638,7 +1709,7 @@
16381709 colorV[0] = display.modelParams0[0] * material.diffuse;
16391710 colorV[1] = display.modelParams0[1] * material.diffuse;
16401711 colorV[2] = display.modelParams0[2] * material.diffuse;
1641
- colorV[3] = material.opacity;
1712
+ colorV[3] = 1; // material.opacity;
16421713
16431714 gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
16441715 //System.out.println("Opacity = " + opacity);
....@@ -1746,9 +1817,9 @@
17461817 display.modelParams7[2] = 0;
17471818 display.modelParams7[3] = 0;
17481819
1749
- display.modelParams6[0] = 100; // criss de bug de bump
1820
+ //display.modelParams6[0] = 100; // criss de bug de bump
17501821
1751
- Object3D.cVector2[] extparams = display.vector2buffer;
1822
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
17521823 if (extparams != null && extparams.length > 0 && extparams[0] != null)
17531824 {
17541825 display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
....@@ -2044,7 +2115,7 @@
20442115 //System.err.println("Oeil on");
20452116 OEIL = true;
20462117 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2047
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2118
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
20482119 //pingthread.StepToTarget(true);
20492120 }
20502121
....@@ -2259,7 +2330,7 @@
22592330
22602331 void ToggleDebug()
22612332 {
2262
- DEBUG ^= true;
2333
+ Globals.DEBUG ^= true;
22632334 }
22642335
22652336 void ToggleLookAt()
....@@ -2277,10 +2348,17 @@
22772348 HANDLES ^= true;
22782349 }
22792350
2351
+ Object3D paintFolder;
2352
+
22802353 void TogglePaint()
22812354 {
22822355 PAINTMODE ^= true;
22832356 paintcount = 0;
2357
+
2358
+ if (PAINTMODE)
2359
+ {
2360
+ paintFolder = GetFolder();
2361
+ }
22842362 }
22852363
22862364 void SwapCamera(int a, int b)
....@@ -2377,6 +2455,21 @@
23772455 return currentGL;
23782456 }
23792457
2458
+ static private BufferedImage CreateBim(TextureData texturedata)
2459
+ {
2460
+ Grafreed.Assert(texturedata != null);
2461
+
2462
+ int width = texturedata.getWidth();
2463
+ int height = texturedata.getHeight();
2464
+
2465
+ Buffer buffer = texturedata.getBuffer();
2466
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2467
+
2468
+ byte[] bytes = bytebuf.array();
2469
+
2470
+ return CreateBim(bytes, width, height);
2471
+ }
2472
+
23802473 /**/
23812474 class CacheTexture
23822475 {
....@@ -2385,28 +2478,31 @@
23852478
23862479 int resolution;
23872480
2388
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2481
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
23892482 {
2390
- texture = tex;
2483
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2484
+ texturedata = texdata;
23912485 resolution = res;
23922486 }
23932487 }
23942488 /**/
23952489
23962490 // 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>();
2491
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2492
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2493
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2494
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2495
+
24002496 int pigmentdepth = 0;
24012497 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
24022498 int bumpdepth = 0;
24032499 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
24042500 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
24052501 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2406
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2502
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
24072503 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
24082504
2409
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2505
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
24102506 {
24112507 TextureData texturedata = null;
24122508
....@@ -2425,13 +2521,34 @@
24252521 if (bump)
24262522 texturedata = ConvertBump(texturedata, false);
24272523
2428
- com.sun.opengl.util.texture.Texture texture =
2429
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2524
+// com.sun.opengl.util.texture.Texture texture =
2525
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
24302526
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);
2527
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2528
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
24332529
2434
- return texture;
2530
+ return texturedata;
2531
+ }
2532
+
2533
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2534
+ {
2535
+ TextureData texturedata = null;
2536
+
2537
+ try
2538
+ {
2539
+ texturedata =
2540
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2541
+ bim,
2542
+ true);
2543
+ } catch (Exception e)
2544
+ {
2545
+ throw new javax.media.opengl.GLException(e);
2546
+ }
2547
+
2548
+ if (bump)
2549
+ texturedata = ConvertBump(texturedata, false);
2550
+
2551
+ return texturedata;
24352552 }
24362553
24372554 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3504,6 +3621,8 @@
35043621
35053622 System.out.println("LOADING TEXTURE : " + name);
35063623
3624
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3625
+
35073626 //
35083627 if (false) // compressbit > 0)
35093628 {
....@@ -7902,7 +8021,7 @@
79028021 String pigment = Object3D.GetPigment(tex);
79038022 String bump = Object3D.GetBump(tex);
79048023
7905
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8024
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79068025 {
79078026 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79088027 // System.out.println("; bump = " + bump);
....@@ -7917,8 +8036,8 @@
79178036 pigment = null;
79188037 }
79198038
7920
- ReleaseTexture(bump, true);
7921
- ReleaseTexture(pigment, false);
8039
+ ReleaseTexture(tex, true);
8040
+ ReleaseTexture(tex, false);
79228041 }
79238042
79248043 public void ReleasePigmentTexture(cTexture tex) // INTERFACE
....@@ -7936,7 +8055,7 @@
79368055
79378056 String pigment = Object3D.GetPigment(tex);
79388057
7939
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8058
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79408059 {
79418060 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79428061 // System.out.println("; bump = " + bump);
....@@ -7947,7 +8066,7 @@
79478066 pigment = null;
79488067 }
79498068
7950
- ReleaseTexture(pigment, false);
8069
+ ReleaseTexture(tex, false);
79518070 }
79528071
79538072 public void ReleaseBumpTexture(cTexture tex) // INTERFACE
....@@ -7965,7 +8084,7 @@
79658084
79668085 String bump = Object3D.GetBump(tex);
79678086
7968
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8087
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79698088 {
79708089 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79718090 // System.out.println("; bump = " + bump);
....@@ -7976,10 +8095,10 @@
79768095 bump = null;
79778096 }
79788097
7979
- ReleaseTexture(bump, true);
8098
+ ReleaseTexture(tex, true);
79808099 }
79818100
7982
- void ReleaseTexture(String tex, boolean bump)
8101
+ void ReleaseTexture(cTexture tex, boolean bump)
79838102 {
79848103 if (// DrawMode() != 0 || /*tex == null ||*/
79858104 ambientOcclusion ) // || !textureon)
....@@ -7990,7 +8109,7 @@
79908109 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
79918110
79928111 if (tex != null)
7993
- texture = textures.get(tex);
8112
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
79948113
79958114 // //assert( texture != null );
79968115 // if (texture == null)
....@@ -8084,47 +8203,50 @@
80848203
80858204 /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
80868205 {
8087
- if (// DrawMode() != 0 || /*tex == null ||*/
8088
- ambientOcclusion ) // || !textureon)
8089
- {
8090
- return; // false;
8091
- }
8092
-
8093
- if (tex == null)
8094
- {
8095
- BindTexture(null,false,resolution);
8096
- BindTexture(null,true,resolution);
8097
- return;
8098
- }
8206
+// if (// DrawMode() != 0 || /*tex == null ||*/
8207
+// ambientOcclusion ) // || !textureon)
8208
+// {
8209
+// return; // false;
8210
+// }
8211
+//
8212
+// if (tex == null)
8213
+// {
8214
+// BindTexture(null,false,resolution);
8215
+// BindTexture(null,true,resolution);
8216
+// return;
8217
+// }
8218
+//
8219
+// String pigment = Object3D.GetPigment(tex);
8220
+// String bump = Object3D.GetBump(tex);
8221
+//
8222
+// usedtextures.add(pigment);
8223
+// usedtextures.add(bump);
8224
+//
8225
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8226
+// {
8227
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8228
+// // System.out.println("; bump = " + bump);
8229
+// }
8230
+//
8231
+// if (bump.equals(""))
8232
+// {
8233
+// bump = null;
8234
+// }
8235
+// if (pigment.equals(""))
8236
+// {
8237
+// pigment = null;
8238
+// }
8239
+//
8240
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8241
+// BindTexture(pigment, false, resolution);
8242
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8243
+// BindTexture(bump, true, resolution);
8244
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8245
+//
8246
+// return; // true;
80998247
8100
- String pigment = Object3D.GetPigment(tex);
8101
- String bump = Object3D.GetBump(tex);
8102
-
8103
- usedtextures.put(pigment, pigment);
8104
- usedtextures.put(bump, bump);
8105
-
8106
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8107
- {
8108
- // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8109
- // System.out.println("; bump = " + bump);
8110
- }
8111
-
8112
- if (bump.equals(""))
8113
- {
8114
- bump = null;
8115
- }
8116
- if (pigment.equals(""))
8117
- {
8118
- pigment = null;
8119
- }
8120
-
8121
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8122
- BindTexture(pigment, false, resolution);
8123
- GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8124
- BindTexture(bump, true, resolution);
8125
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8126
-
8127
- return; // true;
8248
+ BindPigmentTexture(tex, resolution);
8249
+ BindBumpTexture(tex, resolution);
81288250 }
81298251
81308252 /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8143,9 +8265,9 @@
81438265
81448266 String pigment = Object3D.GetPigment(tex);
81458267
8146
- usedtextures.put(pigment, pigment);
8268
+ usedtextures.add(tex);
81478269
8148
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8270
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
81498271 {
81508272 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
81518273 // System.out.println("; bump = " + bump);
....@@ -8157,7 +8279,7 @@
81578279 }
81588280
81598281 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8160
- BindTexture(pigment, false, resolution);
8282
+ BindTexture(tex, false, resolution);
81618283 }
81628284
81638285 /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8176,9 +8298,9 @@
81768298
81778299 String bump = Object3D.GetBump(tex);
81788300
8179
- usedtextures.put(bump, bump);
8301
+ usedtextures.add(tex);
81808302
8181
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8303
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
81828304 {
81838305 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
81848306 // System.out.println("; bump = " + bump);
....@@ -8190,7 +8312,7 @@
81908312 }
81918313
81928314 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8193
- BindTexture(bump, true, resolution);
8315
+ BindTexture(tex, true, resolution);
81948316 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
81958317 }
81968318
....@@ -8214,13 +8336,19 @@
82148336 return fileExists;
82158337 }
82168338
8217
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception
8339
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
82188340 {
8219
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8341
+ CacheTexture texturecache = null;
82208342
82218343 if (tex != null)
82228344 {
8223
- String texname = tex;
8345
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8346
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
8347
+
8348
+ if (texname.equals("") && texdata == null)
8349
+ {
8350
+ return null;
8351
+ }
82248352
82258353 String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
82268354
....@@ -8230,19 +8358,46 @@
82308358 // else
82318359 // if (!texname.startsWith("/"))
82328360 // texname = "/Users/nbriere/Textures/" + texname;
8233
- if (!FileExists(tex))
8361
+ if (!FileExists(texname))
82348362 {
82358363 texname = fallbackTextureName;
82368364 }
82378365
82388366 if (CACHETEXTURE)
8239
- texture = textures.get(texname); // TEXTURE CACHE
8240
-
8241
- TextureData texturedata = null;
8242
-
8243
- if (texture == null || texture.resolution < resolution)
82448367 {
8245
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8368
+ if (texdata == null)
8369
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8370
+ else
8371
+ texturecache = bimtextures.get(texdata);
8372
+ }
8373
+
8374
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8375
+ {
8376
+ TextureData texturedata = null;
8377
+
8378
+ if (texdata != null && textureon)
8379
+ {
8380
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8381
+
8382
+ try
8383
+ {
8384
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8385
+ }
8386
+ catch (Exception e)
8387
+ {
8388
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8389
+ }
8390
+
8391
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8392
+ bimtextures.put(texdata, texturecache);
8393
+
8394
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8395
+
8396
+ //Object bim2 = CreateBim(texturecache.texturedata);
8397
+ //bim2 = bim;
8398
+ }
8399
+ else
8400
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
82468401 {
82478402 assert(!bump);
82488403 // if (bump)
....@@ -8253,19 +8408,23 @@
82538408 // }
82548409 // else
82558410 // {
8256
- texture = textures.get(tex);
8257
- if (texture == null)
8411
+ // texturecache = textures.get(texname); // suspicious
8412
+ if (texturecache == null)
82588413 {
8259
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8414
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
82608415 }
8416
+ else
8417
+ new Exception().printStackTrace();
82618418 // }
82628419 } else
8263
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8420
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
82648421 {
82658422 assert(bump);
8266
- texture = textures.get(tex);
8267
- if (texture == null)
8268
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8423
+ // texturecache = textures.get(texname); // suspicious
8424
+ if (texturecache == null)
8425
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8426
+ else
8427
+ new Exception().printStackTrace();
82698428 } else
82708429 {
82718430 //if (tex.equals("IMMORTAL"))
....@@ -8273,11 +8432,13 @@
82738432 // texture = GetResourceTexture("default.png");
82748433 //} else
82758434 //{
8276
- if (tex.equals("WHITE_NOISE"))
8435
+ if (texname.endsWith("WHITE_NOISE"))
82778436 {
8278
- texture = textures.get(tex);
8279
- if (texture == null)
8280
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8437
+ // texturecache = textures.get(texname); // suspicious
8438
+ if (texturecache == null)
8439
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8440
+ else
8441
+ new Exception().printStackTrace();
82818442 } else
82828443 {
82838444 if (textureon)
....@@ -8336,19 +8497,19 @@
83368497 if (texturedata == null)
83378498 throw new Exception();
83388499
8339
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8500
+ texturecache = new CacheTexture(texturedata,resolution);
83408501 //texture = GetTexture(tex, bump);
83418502 }
83428503 }
83438504 //}
83448505 }
83458506
8346
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8507
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
83478508 {
83488509 //return false;
83498510
83508511 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8351
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8512
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
83528513 {
83538514 // String ext = "_highres";
83548515 // if (REDUCETEXTURE)
....@@ -8365,52 +8526,17 @@
83658526 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
83668527 if (!cachefile.exists())
83678528 {
8368
- // cache to disk
8369
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
8370
- //buffers[0].
8371
-
8372
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
8373
- int[] pixels = new int[bytebuf.capacity()/3];
8374
-
8375
- // squared size heuristic...
8376
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8529
+ //if (texturedata.getWidth() == texturedata.getHeight())
83778530 {
8378
- for (int i=pixels.length; --i>=0;)
8379
- {
8380
- int i3 = i*3;
8381
- pixels[i] = 0xFF;
8382
- pixels[i] <<= 8;
8383
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
8384
- pixels[i] <<= 8;
8385
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
8386
- pixels[i] <<= 8;
8387
- pixels[i] |= bytebuf.get(i3) & 0xFF;
8388
- }
8389
-
8390
- /*
8391
- int r=0,g=0,b=0,a=0;
8392
- for (int i=0; i<width; i++)
8393
- for (int j=0; j<height; j++)
8394
- {
8395
- int index = j*width+i;
8396
- int p = pixels[index];
8397
- a = ((p>>24) & 0xFF);
8398
- r = ((p>>16) & 0xFF);
8399
- g = ((p>>8) & 0xFF);
8400
- b = (p & 0xFF);
8401
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
8402
- }
8403
- /**/
8404
- int width = (int)Math.sqrt(pixels.length); // squared
8405
- int height = width;
8406
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
8407
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8531
+ BufferedImage rendImage = CreateBim(texturedata);
8532
+
84088533 ImageWriter writer = null;
84098534 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
84108535 if (iter.hasNext()) {
84118536 writer = (ImageWriter)iter.next();
84128537 }
8413
- float compressionQuality = 0.9f;
8538
+
8539
+ float compressionQuality = 0.85f;
84148540 try
84158541 {
84168542 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8427,18 +8553,20 @@
84278553 }
84288554 }
84298555 }
8430
-
8556
+
8557
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8558
+
84318559 //System.out.println("Texture = " + tex);
8432
- if (textures.containsKey(texname))
8560
+ if (textures.containsKey(tex))
84338561 {
8434
- CacheTexture thetex = textures.get(texname);
8562
+ CacheTexture thetex = textures.get(tex);
84358563 thetex.texture.disable();
84368564 thetex.texture.dispose();
8437
- textures.remove(texname);
8565
+ textures.remove(tex);
84388566 }
84398567
8440
- texture.texturedata = texturedata;
8441
- textures.put(texname, texture);
8568
+ //texture.texturedata = texturedata;
8569
+ textures.put(tex, texturecache);
84428570
84438571 // newtex = true;
84448572 }
....@@ -8454,10 +8582,44 @@
84548582 }
84558583 }
84568584
8457
- return texture;
8585
+ return texturecache;
84588586 }
84598587
8460
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution) throws Exception
8588
+ static void EmbedTextures(cTexture tex)
8589
+ {
8590
+ if (tex.pigmentdata == null)
8591
+ {
8592
+ //String texname = Object3D.GetPigment(tex);
8593
+
8594
+ CacheTexture texturecache = texturepigment.get(tex);
8595
+
8596
+ if (texturecache != null)
8597
+ {
8598
+ tex.pw = texturecache.texturedata.getWidth();
8599
+ tex.ph = texturecache.texturedata.getHeight();
8600
+ tex.pigmentdata = //CompressJPEG(CreateBim
8601
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8602
+ ;
8603
+ //, tex.pw, tex.ph), 0.5f);
8604
+ }
8605
+ }
8606
+
8607
+ if (tex.bumpdata == null)
8608
+ {
8609
+ //String texname = Object3D.GetBump(tex);
8610
+
8611
+ CacheTexture texturecache = texturebump.get(tex);
8612
+
8613
+ if (texturecache != null)
8614
+ {
8615
+ tex.bw = texturecache.texturedata.getWidth();
8616
+ tex.bh = texturecache.texturedata.getHeight();
8617
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8618
+ }
8619
+ }
8620
+ }
8621
+
8622
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
84618623 {
84628624 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
84638625
....@@ -8475,21 +8637,21 @@
84758637 return texture!=null?texture.texture:null;
84768638 }
84778639
8478
- public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution) throws Exception
8640
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
84798641 {
84808642 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
84818643
84828644 return texture!=null?texture.texturedata:null;
84838645 }
84848646
8485
- boolean BindTexture(String tex, boolean bump, int resolution) throws Exception
8647
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
84868648 {
84878649 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
84888650 {
84898651 return false;
84908652 }
84918653
8492
- boolean newtex = false;
8654
+ //boolean newtex = false;
84938655
84948656 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
84958657
....@@ -8521,9 +8683,75 @@
85218683 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
85228684 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
85238685
8524
- return newtex;
8686
+ return true; // Warning: not used.
85258687 }
85268688
8689
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8690
+ {
8691
+ try
8692
+ {
8693
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8694
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8695
+ ImageWriter writer = writers.next();
8696
+
8697
+ ImageWriteParam param = writer.getDefaultWriteParam();
8698
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8699
+ param.setCompressionQuality(quality);
8700
+
8701
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8702
+ writer.setOutput(ios);
8703
+ writer.write(null, new IIOImage(image, null, null), param);
8704
+
8705
+ byte[] data = baos.toByteArray();
8706
+ writer.dispose();
8707
+ return data;
8708
+ }
8709
+ catch (Exception e)
8710
+ {
8711
+ e.printStackTrace();
8712
+ return null;
8713
+ }
8714
+ }
8715
+
8716
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8717
+ {
8718
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8719
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8720
+ ImageReader reader = writers.next();
8721
+
8722
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8723
+
8724
+ ImageReadParam param = reader.getDefaultReadParam();
8725
+ param.setDestination(bim);
8726
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8727
+
8728
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8729
+ reader.setInput(ios);
8730
+ BufferedImage bim2 = reader.read(0, param);
8731
+ reader.dispose();
8732
+
8733
+// WritableRaster raster = bim2.getRaster();
8734
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8735
+// byte[] bytes = data.getData();
8736
+//
8737
+// int[] pixels = new int[bytes.length/3];
8738
+// for (int i=pixels.length; --i>=0;)
8739
+// {
8740
+// int i3 = i*3;
8741
+// pixels[i] = 0xFF;
8742
+// pixels[i] <<= 8;
8743
+// pixels[i] |= bytes[i3+2] & 0xFF;
8744
+// pixels[i] <<= 8;
8745
+// pixels[i] |= bytes[i3+1] & 0xFF;
8746
+// pixels[i] <<= 8;
8747
+// pixels[i] |= bytes[i3] & 0xFF;
8748
+// }
8749
+//
8750
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8751
+
8752
+ return bim;
8753
+ }
8754
+
85278755 ShadowBuffer shadowPBuf;
85288756 AntialiasBuffer antialiasPBuf;
85298757 int MAXSTACK;
....@@ -8716,7 +8944,7 @@
87168944
87178945 if (cubemap == null)
87188946 {
8719
- LoadEnvy(5);
8947
+ //LoadEnvy(1);
87208948 }
87218949
87228950 //cubemap.enable();
....@@ -9003,37 +9231,58 @@
90039231 cubemap = null;
90049232 return;
90059233 case 1:
9006
- name = "cubemaps/box_";
9007
- ext = "png";
9234
+ name = "cubemaps/rgb/";
9235
+ ext = "jpg";
90089236 reverseUP = false;
90099237 break;
90109238 case 2:
9011
- name = "cubemaps/uffizi_";
9012
- ext = "png";
9013
- break; // reverseUP = true; break;
9239
+ name = "cubemaps/uffizi/";
9240
+ ext = "jpg";
9241
+ reverseUP = false;
9242
+ break;
90149243 case 3:
9015
- name = "cubemaps/CloudyHills_";
9016
- ext = "tga";
9244
+ name = "cubemaps/CloudyHills/";
9245
+ ext = "jpg";
90179246 reverseUP = false;
90189247 break;
90199248 case 4:
9020
- name = "cubemaps/cornell_";
9249
+ name = "cubemaps/cornell/";
90219250 ext = "png";
90229251 reverseUP = false;
90239252 break;
9253
+ case 5:
9254
+ name = "cubemaps/skycube/";
9255
+ ext = "jpg";
9256
+ reverseUP = false;
9257
+ break;
9258
+ case 6:
9259
+ name = "cubemaps/SaintLazarusChurch3/";
9260
+ ext = "jpg";
9261
+ reverseUP = false;
9262
+ break;
9263
+ case 7:
9264
+ name = "cubemaps/Sodermalmsallen/";
9265
+ ext = "jpg";
9266
+ reverseUP = false;
9267
+ break;
9268
+ case 8:
9269
+ name = "cubemaps/Sodermalmsallen2/";
9270
+ ext = "jpg";
9271
+ reverseUP = false;
9272
+ break;
9273
+ case 9:
9274
+ name = "cubemaps/UnionSquare/";
9275
+ ext = "jpg";
9276
+ reverseUP = false;
9277
+ break;
90249278 default:
9025
- name = "cubemaps/rgb_";
9026
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9279
+ name = "cubemaps/box/";
9280
+ ext = "png"; /*mipmap = true;*/
9281
+ reverseUP = false;
90279282 break;
90289283 }
9029
-
9030
- try
9031
- {
9032
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
9033
- } catch (IOException e)
9034
- {
9035
- throw new RuntimeException(e);
9036
- }
9284
+
9285
+ LoadSkybox(name, ext, mipmap);
90379286 }
90389287
90399288 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -9065,8 +9314,12 @@
90659314 static double[] model = new double[16];
90669315 double[] camera2light = new double[16];
90679316 double[] light2camera = new double[16];
9068
- int newenvy = -1;
9069
- boolean envyoff = true; // false;
9317
+
9318
+ //int newenvy = -1;
9319
+ //boolean envyoff = false;
9320
+
9321
+ String loadedskyboxname;
9322
+
90709323 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
90719324 //float[] light0 = { 0,0,0 };
90729325 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9359,11 +9612,35 @@
93599612 jy8[3] = 0.5f;
93609613 }
93619614
9362
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9615
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
93639616 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
93649617 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
93659618 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
93669619
9620
+ void ResetOptions()
9621
+ {
9622
+ options1[0] = 100;
9623
+ options1[1] = 0.025f;
9624
+ options1[2] = 0.01f;
9625
+ options1[3] = 0;
9626
+ options1[4] = 0;
9627
+
9628
+ options2[0] = 0;
9629
+ options2[1] = 0.75f;
9630
+ options2[2] = 0;
9631
+ options2[3] = 0;
9632
+
9633
+ options3[0] = 1;
9634
+ options3[1] = 1;
9635
+ options3[2] = 1;
9636
+ options3[3] = 0;
9637
+
9638
+ options4[0] = 1;
9639
+ options4[1] = 0;
9640
+ options4[2] = 1;
9641
+ options4[3] = 0;
9642
+ }
9643
+
93679644 static int imagecount = 0; // movie generation
93689645
93699646 static int jitter = 0;
....@@ -9460,7 +9737,7 @@
94609737
94619738 if (renderCamera != lightCamera)
94629739 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9463
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
9740
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
94649741
94659742 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
94669743
....@@ -9476,7 +9753,7 @@
94769753
94779754 if (renderCamera != lightCamera)
94789755 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9479
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
9756
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
94809757
94819758 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
94829759
....@@ -9522,10 +9799,12 @@
95229799 rati = 1 / rati;
95239800 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
95249801 }
9525
- assert (newenvy == -1);
9802
+
9803
+ //assert (newenvy == -1);
9804
+
95269805 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
95279806 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9528
- DrawSkyBox(gl);
9807
+ DrawSkyBox(gl, (float)rati);
95299808 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
95309809 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
95319810 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10474,6 +10753,7 @@
1047410753 ANTIALIAS = 0;
1047510754 //System.out.println("RESTART");
1047610755 AAtimer.restart();
10756
+ Globals.TIMERRUNNING = true;
1047710757 }
1047810758 }
1047910759 }
....@@ -10541,7 +10821,8 @@
1054110821 ambientOcclusion = false;
1054210822 }
1054310823
10544
- if (Globals.lighttouched && DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
10824
+ if (//Globals.lighttouched &&
10825
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1054510826 {
1054610827 //if (RENDERSHADOW) // ?
1054710828 if (!IsFrozen())
....@@ -10675,7 +10956,7 @@
1067510956 // if (parentcam != renderCamera) // not a light
1067610957 if (cam != lightCamera)
1067710958 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10678
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
10959
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1067910960
1068010961 for (int j = 0; j < 4; j++)
1068110962 {
....@@ -10690,7 +10971,7 @@
1069010971 // if (parentcam != renderCamera) // not a light
1069110972 if (cam != lightCamera)
1069210973 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10693
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
10974
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1069410975
1069510976 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1069610977
....@@ -10776,13 +11057,27 @@
1077611057 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1077711058 }
1077811059
10779
- if (newenvy > -1)
11060
+// if (newenvy > -1)
11061
+// {
11062
+// LoadEnvy(newenvy);
11063
+// }
11064
+//
11065
+// newenvy = -1;
11066
+
11067
+ if (object.skyboxname != null)
1078011068 {
10781
- LoadEnvy(newenvy);
11069
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11070
+ {
11071
+ LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11072
+ loadedskyboxname = object.skyboxname;
11073
+ }
1078211074 }
10783
-
10784
- newenvy = -1;
10785
-
11075
+ else
11076
+ {
11077
+ cubemap = null;
11078
+ loadedskyboxname = null;
11079
+ }
11080
+
1078611081 ratio = ((double) getWidth()) / getHeight();
1078711082 //System.out.println("ratio = " + ratio);
1078811083
....@@ -10798,7 +11093,7 @@
1079811093
1079911094 if (!IsFrozen() && !ambientOcclusion)
1080011095 {
10801
- DrawSkyBox(gl);
11096
+ DrawSkyBox(gl, (float)ratio);
1080211097 }
1080311098
1080411099 //if (selection_view == -1)
....@@ -10981,9 +11276,9 @@
1098111276
1098211277 gl.glMatrixMode(GL.GL_MODELVIEW);
1098311278
10984
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10985
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10986
-//gl.glEnable(gl.GL_MULTISAMPLE);
11279
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11280
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11281
+gl.glEnable(gl.GL_MULTISAMPLE);
1098711282 } else
1098811283 {
1098911284 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -10994,7 +11289,7 @@
1099411289 //System.out.println("BLENDING ON");
1099511290 gl.glEnable(GL.GL_BLEND);
1099611291 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
10997
-
11292
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1099811293 gl.glMatrixMode(gl.GL_PROJECTION);
1099911294 gl.glLoadIdentity();
1100011295
....@@ -11084,7 +11379,7 @@
1108411379
1108511380 // if (cam != lightCamera)
1108611381 //for (int count = parentcam.GetTransformCount(); --count>=0;)
11087
- LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
11382
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1108811383 }
1108911384
1109011385 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -11243,7 +11538,7 @@
1124311538 }
1124411539 }
1124511540
11246
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11541
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1124711542 {
1124811543 //gl.glDepthFunc(GL.GL_LEQUAL);
1124911544 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11251,24 +11546,21 @@
1125111546
1125211547 boolean texon = textureon;
1125311548
11254
- if (RENDERPROGRAM > 0)
11255
- {
11256
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11257
- textureon = false;
11258
- }
11549
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11550
+ textureon = false;
11551
+
1125911552 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1126011553 //System.out.println("ALLO");
1126111554 gl.glColorMask(false, false, false, false);
1126211555 DrawObject(gl);
11263
- if (RENDERPROGRAM > 0)
11264
- {
11265
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11266
- textureon = texon;
11267
- }
11556
+
11557
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11558
+ textureon = texon;
11559
+
1126811560 gl.glColorMask(true, true, true, true);
1126911561
1127011562 gl.glDepthFunc(GL.GL_EQUAL);
11271
- //gl.glDepthMask(false);
11563
+ gl.glDepthMask(false);
1127211564 }
1127311565
1127411566 if (false) // DrawMode() == SHADOW)
....@@ -11451,15 +11743,36 @@
1145111743
1145211744 static boolean zoomonce = false;
1145311745
11746
+ static void CreateSelectedPoint()
11747
+ {
11748
+ if (selectedpoint == null)
11749
+ {
11750
+ debugpointG = new Sphere();
11751
+ debugpointP = new Sphere();
11752
+ debugpointC = new Sphere();
11753
+ debugpointR = new Sphere();
11754
+
11755
+ selectedpoint = new Superellipsoid();
11756
+
11757
+ for (int i=0; i<8; i++)
11758
+ {
11759
+ debugpoints[i] = new Sphere();
11760
+ }
11761
+ }
11762
+ }
11763
+
1145411764 void DrawObject(GL gl, boolean draw)
1145511765 {
11766
+ // To clear camera values
11767
+ ResetOptions();
11768
+
1145611769 //System.out.println("DRAW OBJECT " + mouseDown);
1145711770 // DrawMode() = SELECTION;
1145811771 //GL gl = getGL();
1145911772 if ((TRACK || SHADOWTRACK) || zoomonce)
1146011773 {
1146111774 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11462
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11775
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1146311776 pingthread.StepToTarget(true); // true);
1146411777 // zoomonce = false;
1146511778 }
....@@ -11531,8 +11844,9 @@
1153111844
1153211845 if (DrawMode() == DEFAULT)
1153311846 {
11534
- if (DEBUG)
11847
+ if (Globals.DEBUG)
1153511848 {
11849
+ CreateSelectedPoint();
1153611850 float radius = 0.05f;
1153711851 if (selectedpoint.radius != radius)
1153811852 {
....@@ -11586,20 +11900,32 @@
1158611900 ReleaseTextures(DEFAULT_TEXTURES);
1158711901
1158811902 if (CLEANCACHE)
11589
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11903
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1159011904 {
11591
- String tex = e.nextElement();
11905
+ cTexture tex = e.nextElement();
1159211906
1159311907 // System.out.println("Texture --------- " + tex);
1159411908
11595
- if (tex.equals("WHITE_NOISE"))
11909
+ if (tex.equals("WHITE_NOISE:"))
1159611910 continue;
1159711911
11598
- if (!usedtextures.containsKey(tex))
11912
+ if (!usedtextures.contains(tex))
1159911913 {
11914
+ CacheTexture gettex = texturepigment.get(tex);
1160011915 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11601
- textures.get(tex).texture.dispose();
11602
- textures.remove(tex);
11916
+ if (gettex != null)
11917
+ {
11918
+ gettex.texture.dispose();
11919
+ texturepigment.remove(tex);
11920
+ }
11921
+
11922
+ gettex = texturebump.get(tex);
11923
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11924
+ if (gettex != null)
11925
+ {
11926
+ gettex.texture.dispose();
11927
+ texturebump.remove(tex);
11928
+ }
1160311929 }
1160411930 }
1160511931 }
....@@ -12019,7 +12345,7 @@
1201912345 for (int i = tp.size(); --i >= 0;)
1202012346 {
1202112347 //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12022
- LA.xformPos(light, tp.get(i).GlobalTransform(), light);
12348
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1202312349 }
1202412350
1202512351
....@@ -12127,8 +12453,76 @@
1212712453
1212812454 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1212912455
12130
- String program =
12456
+ String programmin =
12457
+ // Min shader
1213112458 "!!ARBfp1.0\n" +
12459
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12460
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12461
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12462
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12463
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12464
+ "PARAM light2cam0 = program.env[10];" +
12465
+ "PARAM light2cam1 = program.env[11];" +
12466
+ "PARAM light2cam2 = program.env[12];" +
12467
+ "TEMP temp;" +
12468
+ "TEMP light;" +
12469
+ "TEMP ndotl;" +
12470
+ "TEMP normal;" +
12471
+ "TEMP depth;" +
12472
+ "TEMP eye;" +
12473
+ "TEMP pos;" +
12474
+
12475
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12476
+ Normalize("normal") +
12477
+ "MOV light, state.light[0].position;" +
12478
+ "DP3 ndotl.x, light, normal;" +
12479
+
12480
+ // shadow
12481
+ "MOV pos, fragment.texcoord[1];" +
12482
+ "MOV temp, pos;" +
12483
+ ShadowTextureFetch("depth", "temp", "1") +
12484
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12485
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12486
+
12487
+ // No shadow when out of frustum
12488
+ //"SGE temp.y, depth.z, zero123.y;" +
12489
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12490
+
12491
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12492
+
12493
+ // Backlit
12494
+ "MOV pos.w, zero123.y;" +
12495
+ "DP4 eye.x, pos, light2cam0;" +
12496
+ "DP4 eye.y, pos, light2cam1;" +
12497
+ "DP4 eye.z, pos, light2cam2;" +
12498
+ Normalize("eye") +
12499
+
12500
+ "DP3 ndotl.y, -eye, normal;" +
12501
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12502
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12503
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12504
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12505
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12506
+
12507
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12508
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12509
+
12510
+ // Pigment
12511
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12512
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12513
+ "MUL temp, temp, ndotl.x;" +
12514
+
12515
+ "MUL temp, temp, zero123.z;" +
12516
+
12517
+ //"MUL temp, temp, ndotl.y;" +
12518
+
12519
+ "MOV temp.w, zero123.y;" + // reset alpha
12520
+ "MOV result.color, temp;" +
12521
+ "END";
12522
+
12523
+ String programmax =
12524
+ "!!ARBfp1.0\n" +
12525
+
1213212526 //"OPTION ARB_fragment_program_shadow;" +
1213312527 "PARAM light2cam0 = program.env[10];" +
1213412528 "PARAM light2cam1 = program.env[11];" +
....@@ -12243,8 +12637,7 @@
1224312637 "TEMP shininess;" +
1224412638 "\n" +
1224512639 "MOV texSamp, one;" +
12246
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12247
-
12640
+
1224812641 "MOV mapgrid.x, one2048th.x;" +
1224912642 "MOV temp, fragment.texcoord[1];" +
1225012643 /*
....@@ -12265,20 +12658,20 @@
1226512658 "MUL temp, floor, mapgrid.x;" +
1226612659 //"TEX depth0, temp, texture[1], 2D;" +
1226712660 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12268
- TextureFetch("depth0", "temp", "1") +
12661
+ ShadowTextureFetch("depth0", "temp", "1") +
1226912662 "") +
1227012663 "ADD temp.x, temp.x, mapgrid.x;" +
1227112664 //"TEX depth1, temp, texture[1], 2D;" +
1227212665 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12273
- TextureFetch("depth1", "temp", "1") +
12666
+ ShadowTextureFetch("depth1", "temp", "1") +
1227412667 "") +
1227512668 "ADD temp.y, temp.y, mapgrid.x;" +
1227612669 //"TEX depth2, temp, texture[1], 2D;" +
12277
- TextureFetch("depth2", "temp", "1") +
12670
+ ShadowTextureFetch("depth2", "temp", "1") +
1227812671 "SUB temp.x, temp.x, mapgrid.x;" +
1227912672 //"TEX depth3, temp, texture[1], 2D;" +
1228012673 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12281
- TextureFetch("depth3", "temp", "1") +
12674
+ ShadowTextureFetch("depth3", "temp", "1") +
1228212675 "") +
1228312676 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1228412677 //"MOV params, material;" +
....@@ -12649,10 +13042,10 @@
1264913042 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1265013043 "") +
1265113044
12652
- // display shadow only (bump == 0)
13045
+ // display shadow only (fakedepth == 0)
1265313046 "SUB temp.x, half.x, shadow.x;" +
1265413047 "MOV temp.y, -params5.z;" + // params6.x;" +
12655
- "SLT temp.z, temp.y, -one2048th.x;" +
13048
+ "SLT temp.z, temp.y, -c256i.x;" +
1265613049 "SUB temp.y, one.x, temp.z;" +
1265713050 "MUL temp.x, temp.x, temp.y;" +
1265813051 "KIL temp.x;" +
....@@ -12983,6 +13376,13 @@
1298313376 //once = true;
1298413377 }
1298513378
13379
+ String program = programmax;
13380
+
13381
+ if (Globals.MINSHADER)
13382
+ {
13383
+ program = programmin;
13384
+ }
13385
+
1298613386 System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1298713387 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1298813388 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
....@@ -13076,25 +13476,26 @@
1307613476 return out;
1307713477 }
1307813478
13079
- String TextureFetch(String dest, String src, String unit)
13479
+ // Also does frustum culling
13480
+ String ShadowTextureFetch(String dest, String src, String unit)
1308013481 {
1308113482 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1308213483 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1308313484 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13485
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13486
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1308413487 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13085
- "SLT " + src + ".z, " + src + ".x, one.x;" +
13086
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13087
- "SLT " + src + ".z, " + src + ".y, one.x;" +
13088
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13488
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13489
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1308913490 //"SWZ buffer, temp, w,w,w,w;";
13090
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13491
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1309113492 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1309213493 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1309313494 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13094
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13495
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1309513496
13096
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13097
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13497
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13498
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1309813499 }
1309913500
1310013501 String Shadow(String depth, String shadow)
....@@ -13141,7 +13542,7 @@
1314113542 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1314213543 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1314313544
13144
- // No shadow when out of frustrum
13545
+ // No shadow when out of frustum
1314513546 "SGE temp.x, " + depth + ".z, one.z;" +
1314613547 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1314713548 "";
....@@ -13289,7 +13690,8 @@
1328913690 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1329013691 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1329113692 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13292
- Object3D.cVector2[] vector2buffer;
13693
+
13694
+ //Object3D.cVector2[] vector2buffer;
1329313695
1329413696 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1329513697 // OUT : diff, spec
....@@ -13305,9 +13707,10 @@
1330513707 "DP3 " + dest + ".z," + "normals," + "eye;" +
1330613708 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1330713709 //"MOV " + dest + ".w," + "normal.z;" +
13308
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
13309
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13310
- //"MOV " + dest + ".z," + "params2.w;" +
13710
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13711
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13712
+
13713
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1331113714 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1331213715 "RCP " + dest + ".w," + dest + ".w;" +
1331313716 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13812,6 +14215,7 @@
1381214215 else
1381314216 if (evt.getSource() == AAtimer)
1381414217 {
14218
+ Globals.TIMERRUNNING = false;
1381514219 if (mouseDown)
1381614220 {
1381714221 //new Exception().printStackTrace();
....@@ -13871,7 +14275,7 @@
1387114275
1387214276 // fev 2014???
1387314277 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13874
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14278
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1387514279 pingthread.StepToTarget(true); // true);
1387614280 }
1387714281 // if (!LIVE)
....@@ -13886,6 +14290,7 @@
1388614290 return;
1388714291
1388814292 AAtimer.restart(); //
14293
+ Globals.TIMERRUNNING = true;
1388914294
1389014295 // waslive = LIVE;
1389114296 // LIVE = false;
....@@ -13935,14 +14340,15 @@
1393514340 drag = false;
1393614341 //System.out.println("Mouse DOWN");
1393714342 editObj = false;
13938
- ClickInfo info = new ClickInfo();
13939
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
13940
- info.pane = this;
13941
- info.camera = renderCamera;
13942
- info.x = x;
13943
- info.y = y;
13944
- info.modifiers = modifiersex;
13945
- editObj = object.doEditClick(info, 0);
14343
+ //ClickInfo info = new ClickInfo();
14344
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14345
+ object.clickInfo.pane = this;
14346
+ object.clickInfo.camera = renderCamera;
14347
+ object.clickInfo.x = x;
14348
+ object.clickInfo.y = y;
14349
+ object.clickInfo.modifiers = modifiersex;
14350
+ editObj = object.doEditClick(//info,
14351
+ 0);
1394614352 if (!editObj)
1394714353 {
1394814354 hasMarquee = true;
....@@ -14224,12 +14630,12 @@
1422414630 void GoDown(int mod)
1422514631 {
1422614632 MODIFIERS |= COMMAND;
14227
- /*
14633
+ /**/
1422814634 if((mod&SHIFT) == SHIFT)
14229
- manipCamera.RotatePosition(0, -speed);
14635
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
1423014636 else
14231
- manipCamera.BackForth(0, -speed*delta, getWidth());
14232
- */
14637
+ manipCamera.RotatePosition(0, -speed);
14638
+ /**/
1423314639 if ((mod & SHIFT) == SHIFT)
1423414640 {
1423514641 mouseMode = mouseMode; // VR??
....@@ -14245,12 +14651,12 @@
1424514651 void GoUp(int mod)
1424614652 {
1424714653 MODIFIERS |= COMMAND;
14248
- /*
14654
+ /**/
1424914655 if((mod&SHIFT) == SHIFT)
14250
- manipCamera.RotatePosition(0, speed);
14656
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
1425114657 else
14252
- manipCamera.BackForth(0, speed*delta, getWidth());
14253
- */
14658
+ manipCamera.RotatePosition(0, speed);
14659
+ /**/
1425414660 if ((mod & SHIFT) == SHIFT)
1425514661 {
1425614662 mouseMode = mouseMode;
....@@ -14266,12 +14672,12 @@
1426614672 void GoLeft(int mod)
1426714673 {
1426814674 MODIFIERS |= COMMAND;
14269
- /*
14675
+ /**/
1427014676 if((mod&SHIFT) == SHIFT)
14271
- manipCamera.RotatePosition(speed, 0);
14272
- else
1427314677 manipCamera.Translate(speed*delta, 0, getWidth());
14274
- */
14678
+ else
14679
+ manipCamera.RotatePosition(speed, 0);
14680
+ /**/
1427514681 if ((mod & SHIFT) == SHIFT)
1427614682 {
1427714683 mouseMode = mouseMode;
....@@ -14287,12 +14693,12 @@
1428714693 void GoRight(int mod)
1428814694 {
1428914695 MODIFIERS |= COMMAND;
14290
- /*
14696
+ /**/
1429114697 if((mod&SHIFT) == SHIFT)
14292
- manipCamera.RotatePosition(-speed, 0);
14293
- else
1429414698 manipCamera.Translate(-speed*delta, 0, getWidth());
14295
- */
14699
+ else
14700
+ manipCamera.RotatePosition(-speed, 0);
14701
+ /**/
1429614702 if ((mod & SHIFT) == SHIFT)
1429714703 {
1429814704 mouseMode = mouseMode;
....@@ -14342,14 +14748,16 @@
1434214748 if (editObj)
1434314749 {
1434414750 drag = true;
14345
- ClickInfo info = new ClickInfo();
14346
- info.bounds.setBounds(0, 0,
14751
+ //ClickInfo info = new ClickInfo();
14752
+ object.clickInfo.bounds.setBounds(0, 0,
1434714753 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14348
- info.pane = this;
14349
- info.camera = renderCamera;
14350
- info.x = x;
14351
- info.y = y;
14352
- object.editWindow.copy.doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
14754
+ object.clickInfo.pane = this;
14755
+ object.clickInfo.camera = renderCamera;
14756
+ object.clickInfo.x = x;
14757
+ object.clickInfo.y = y;
14758
+ object //.GetWindow().copy
14759
+ .doEditDrag(//info,
14760
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1435314761 } else
1435414762 {
1435514763 if (x < startX)
....@@ -14498,22 +14906,27 @@
1449814906 }
1449914907 }
1450014908
14909
+// ClickInfo clickInfo = new ClickInfo();
14910
+
1450114911 public void mouseMoved(MouseEvent e)
1450214912 {
1450314913 //System.out.println("mouseMoved: " + e);
1450414914 if (isRenderer)
1450514915 return;
1450614916
14507
- ClickInfo ci = new ClickInfo();
14508
- ci.x = e.getX();
14509
- ci.y = e.getY();
14510
- ci.modifiers = e.getModifiersEx();
14511
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14512
- ci.pane = this;
14513
- ci.camera = renderCamera;
14917
+ // Mouse cursor feedback
14918
+ object.clickInfo.x = e.getX();
14919
+ object.clickInfo.y = e.getY();
14920
+ object.clickInfo.modifiers = e.getModifiersEx();
14921
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14922
+ object.clickInfo.pane = this;
14923
+ object.clickInfo.camera = renderCamera;
1451414924 if (!isRenderer)
1451514925 {
14516
- if (object.editWindow.copy.doEditClick(ci, 0))
14926
+ //ObjEditor editWindow = object.editWindow;
14927
+ //Object3D copy = editWindow.copy;
14928
+ if (object.doEditClick(//clickInfo,
14929
+ 0))
1451714930 {
1451814931 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1451914932 } else
....@@ -14528,7 +14941,8 @@
1452814941 Globals.MOUSEDRAGGED = false;
1452914942
1453014943 movingcamera = false;
14531
- X = Y = 0;
14944
+ X = 0; // getBounds().width/2;
14945
+ Y = 0; // getBounds().height/2;
1453214946 //System.out.println("mouseReleased: " + e);
1453314947 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1453414948 }
....@@ -14784,7 +15198,8 @@
1478415198 // break;
1478515199 case 'T':
1478615200 CACHETEXTURE ^= true;
14787
- textures.clear();
15201
+ texturepigment.clear();
15202
+ texturebump.clear();
1478815203 // repaint();
1478915204 break;
1479015205 case 'Y':
....@@ -14869,7 +15284,9 @@
1486915284 case 'E' : COMPACT ^= true;
1487015285 repaint();
1487115286 break;
14872
- case 'W' : DEBUGHSB ^= true;
15287
+ case 'W' : // Wide Window (fullscreen)
15288
+ //DEBUGHSB ^= true;
15289
+ ObjEditor.theFrame.ToggleFullScreen();
1487315290 repaint();
1487415291 break;
1487515292 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14894,8 +15311,8 @@
1489415311 RevertCamera();
1489515312 repaint();
1489615313 break;
14897
- case 'L':
1489815314 case 'l':
15315
+ //case 'L':
1489915316 if (lightMode)
1490015317 {
1490115318 lightMode = false;
....@@ -14959,20 +15376,24 @@
1495915376 OCCLUSION_CULLING ^= true;
1496015377 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1496115378 break;
14962
- case '0': envyoff ^= true; repaint(); break;
15379
+ //case '0': envyoff ^= true; repaint(); break;
1496315380 case '1':
1496415381 case '2':
1496515382 case '3':
1496615383 case '4':
1496715384 case '5':
14968
- newenvy = Character.getNumericValue(key);
14969
- repaint();
14970
- break;
1497115385 case '6':
1497215386 case '7':
1497315387 case '8':
1497415388 case '9':
14975
- BGcolor = (key - '6')/3.f;
15389
+ if (true) // envyoff)
15390
+ {
15391
+ BGcolor = (key - '1')/8.f;
15392
+ }
15393
+ else
15394
+ {
15395
+ //newenvy = Character.getNumericValue(key);
15396
+ }
1497615397 repaint();
1497715398 break;
1497815399 case '!':
....@@ -15038,9 +15459,9 @@
1503815459 case '_':
1503915460 kompactbit = 5;
1504015461 break;
15041
- case '+':
15042
- kompactbit = 6;
15043
- break;
15462
+// case '+':
15463
+// kompactbit = 6;
15464
+// break;
1504415465 case ' ':
1504515466 lightMode ^= true;
1504615467 Globals.lighttouched = true;
....@@ -15052,6 +15473,7 @@
1505215473 case ESC:
1505315474 RENDERPROGRAM += 1;
1505415475 RENDERPROGRAM %= 3;
15476
+
1505515477 repaint();
1505615478 break;
1505715479 case 'Z':
....@@ -15091,8 +15513,9 @@
1509115513 case DELETE:
1509215514 ClearSelection();
1509315515 break;
15094
- /*
1509515516 case '+':
15517
+
15518
+ /*
1509615519 //fontsize += 1;
1509715520 bbzoom *= 2;
1509815521 repaint();
....@@ -15109,17 +15532,17 @@
1510915532 case '=':
1511015533 IncDepth();
1511115534 //fontsize += 1;
15112
- object.editWindow.refreshContents(true);
15535
+ object.GetWindow().refreshContents(true);
1511315536 maskbit = 6;
1511415537 break;
1511515538 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1511615539 DecDepth();
1511715540 maskbit = 5;
1511815541 //if(fontsize > 1) fontsize -= 1;
15119
- if (object.editWindow == null)
15120
- new Exception().printStackTrace();
15121
- else
15122
- object.editWindow.refreshContents(true);
15542
+// if (object.editWindow == null)
15543
+// new Exception().printStackTrace();
15544
+// else
15545
+ object.GetWindow().refreshContents(true);
1512315546 break;
1512415547 case '{':
1512515548 manipCamera.shaper_fovy /= 1.1;
....@@ -15343,7 +15766,7 @@
1534315766 }
1534415767 */
1534515768
15346
- object.editWindow.EditSelection();
15769
+ object.GetWindow().EditSelection(false);
1534715770 }
1534815771
1534915772 void SelectParent()
....@@ -15360,10 +15783,10 @@
1536015783 {
1536115784 //selectees.remove(i);
1536215785 System.out.println("select parent of " + elem);
15363
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15786
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1536415787 } else
1536515788 {
15366
- group.editWindow.Select(elem.GetTreePath(), first, true);
15789
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1536715790 }
1536815791
1536915792 first = false;
....@@ -15405,12 +15828,12 @@
1540515828 for (int j = 0; j < group.children.size(); j++)
1540615829 {
1540715830 elem = (Object3D) group.children.elementAt(j);
15408
- object.editWindow.Select(elem.GetTreePath(), first, true);
15831
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1540915832 first = false;
1541015833 }
1541115834 } else
1541215835 {
15413
- object.editWindow.Select(elem.GetTreePath(), first, true);
15836
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1541415837 }
1541515838
1541615839 first = false;
....@@ -15421,21 +15844,21 @@
1542115844 {
1542215845 //Composite group = (Composite) object;
1542315846 Object3D group = object;
15424
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15847
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1542515848 }
1542615849
1542715850 void ResetTransform(int mask)
1542815851 {
1542915852 //Composite group = (Composite) object;
1543015853 Object3D group = object;
15431
- group.editWindow.ResetTransform(mask);
15854
+ group.GetWindow().ResetTransform(mask);
1543215855 }
1543315856
1543415857 void FlipTransform()
1543515858 {
1543615859 //Composite group = (Composite) object;
1543715860 Object3D group = object;
15438
- group.editWindow.FlipTransform();
15861
+ group.GetWindow().FlipTransform();
1543915862 // group.editWindow.ReduceMesh(true);
1544015863 }
1544115864
....@@ -15443,7 +15866,7 @@
1544315866 {
1544415867 //Composite group = (Composite) object;
1544515868 Object3D group = object;
15446
- group.editWindow.PrintMemory();
15869
+ group.GetWindow().PrintMemory();
1544715870 // group.editWindow.ReduceMesh(true);
1544815871 }
1544915872
....@@ -15451,7 +15874,7 @@
1545115874 {
1545215875 //Composite group = (Composite) object;
1545315876 Object3D group = object;
15454
- group.editWindow.ResetCentroid();
15877
+ group.GetWindow().ResetCentroid();
1545515878 }
1545615879
1545715880 void IncDepth()
....@@ -15533,8 +15956,6 @@
1553315956
1553415957 int width = getBounds().width;
1553515958 int height = getBounds().height;
15536
- ClickInfo info = new ClickInfo();
15537
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1553815959 //Image img = CreateImage(width, height);
1553915960 //System.out.println("width = " + width + "; height = " + height + "\n");
1554015961
....@@ -15611,48 +16032,77 @@
1561116032 }
1561216033 if (object != null && !hasMarquee)
1561316034 {
16035
+ if (object.clickInfo == null)
16036
+ object.clickInfo = new ClickInfo();
16037
+ ClickInfo info = object.clickInfo;
16038
+ //ClickInfo info = new ClickInfo();
16039
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16040
+
1561416041 if (isRenderer)
1561516042 {
15616
- info.flags++;
16043
+ object.clickInfo.flags++;
1561716044 double frameAspect = (double) width / (double) height;
1561816045 if (frameAspect > renderCamera.aspect)
1561916046 {
1562016047 int desired = (int) ((double) height * renderCamera.aspect);
15621
- info.bounds.width -= width - desired;
15622
- info.bounds.x += (width - desired) / 2;
16048
+ object.clickInfo.bounds.width -= width - desired;
16049
+ object.clickInfo.bounds.x += (width - desired) / 2;
1562316050 } else
1562416051 {
1562516052 int desired = (int) ((double) width / renderCamera.aspect);
15626
- info.bounds.height -= height - desired;
15627
- info.bounds.y += (height - desired) / 2;
16053
+ object.clickInfo.bounds.height -= height - desired;
16054
+ object.clickInfo.bounds.y += (height - desired) / 2;
1562816055 }
1562916056 }
15630
- info.g = gr;
15631
- info.camera = renderCamera;
16057
+
16058
+ object.clickInfo.g = gr;
16059
+ object.clickInfo.camera = renderCamera;
1563216060 /*
1563316061 // Memory intensive (brep.verticescopy)
1563416062 if (!(object instanceof Composite))
1563516063 object.draw(info, 0, false); // SLOW :
1563616064 */
15637
- if (!isRenderer)
16065
+ if (!isRenderer) // && drag)
1563816066 {
15639
- object.drawEditHandles(info, 0);
15640
-
15641
- if (drag && (X != 0 || Y != 0) && object.selection.Size() > 0)
16067
+ Grafreed.Assert(object != null);
16068
+ Grafreed.Assert(object.selection != null);
16069
+ if (object.selection.Size() > 0)
1564216070 {
15643
- switch (object.selection.get(0).hitSomething)
16071
+ int hitSomething = object.selection.get(0).hitSomething;
16072
+
16073
+ object.clickInfo.DX = 0;
16074
+ object.clickInfo.DY = 0;
16075
+ object.clickInfo.W = 1;
16076
+ if (hitSomething == Object3D.hitCenter)
1564416077 {
15645
- case Object3D.hitCenter: gr.setColor(Color.pink);
15646
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15647
- break;
15648
- case Object3D.hitRotate: gr.setColor(Color.yellow);
15649
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15650
- break;
15651
- case Object3D.hitScale: gr.setColor(Color.cyan);
15652
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15653
- break;
16078
+ info.DX = X;
16079
+ if (X != 0)
16080
+ info.DX -= info.bounds.width/2;
16081
+
16082
+ info.DY = Y;
16083
+ if (Y != 0)
16084
+ info.DY -= info.bounds.height/2;
1565416085 }
15655
-
16086
+
16087
+ object.drawEditHandles(//info,
16088
+ 0);
16089
+
16090
+ if (drag && (X != 0 || Y != 0))
16091
+ {
16092
+ switch (hitSomething)
16093
+ {
16094
+ case Object3D.hitCenter: gr.setColor(Color.pink);
16095
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16096
+ break;
16097
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16098
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16099
+ break;
16100
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16101
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16102
+ break;
16103
+ }
16104
+
16105
+ }
1565616106 }
1565716107 }
1565816108 }
....@@ -16134,6 +16584,8 @@
1613416584 private /*static*/ boolean firstime;
1613516585 private /*static*/ cVector newView = new cVector();
1613616586 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16587
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16588
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1613716589 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1613816590 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1613916591 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16146,29 +16598,66 @@
1614616598 {
1614716599 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1614816600
16601
+ int usedsuf = 0;
16602
+
1614916603 for (int i = 0; i < suffixes.length; i++)
1615016604 {
16151
- String resourceName = basename + suffixes[i] + "." + suffix;
16152
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16153
- mipmapped,
16154
- FileUtil.getFileSuffix(resourceName));
16155
- if (data == null)
16605
+ String[] suffixe = suffixes;
16606
+ String[] fallback = suffixes2;
16607
+ String[] fallfallback = suffixes3;
16608
+
16609
+ for (int c=usedsuf; --c>=0;)
1615616610 {
16157
- throw new IOException("Unable to load texture " + resourceName);
16611
+// String[] temp = suffixe;
16612
+// suffixe = fallback;
16613
+// fallback = fallfallback;
16614
+// fallfallback = temp;
1615816615 }
16616
+
16617
+ String resourceName = basename + suffixe[i] + "." + suffix;
16618
+ TextureData data;
16619
+
16620
+ try
16621
+ {
16622
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16623
+ mipmapped,
16624
+ FileUtil.getFileSuffix(resourceName));
16625
+ }
16626
+ catch (Exception e)
16627
+ {
16628
+ try
16629
+ {
16630
+ resourceName = basename + fallback[i] + "." + suffix;
16631
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16632
+ mipmapped,
16633
+ FileUtil.getFileSuffix(resourceName));
16634
+ }
16635
+ catch (Exception e2)
16636
+ {
16637
+ resourceName = basename + fallfallback[i] + "." + suffix;
16638
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16639
+ mipmapped,
16640
+ FileUtil.getFileSuffix(resourceName));
16641
+ }
16642
+ }
16643
+
1615916644 //System.out.println("Target = " + targets[i]);
1616016645 cubemap.updateImage(data, targets[i]);
1616116646 }
1616216647
1616316648 return cubemap;
1616416649 }
16650
+
1616516651 int bigsphere = -1;
1616616652
1616716653 float BGcolor = 0.5f;
1616816654
16169
- private void DrawSkyBox(GL gl)
16655
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16656
+
16657
+ private void DrawSkyBox(GL gl, float ratio)
1617016658 {
16171
- if (envyoff || cubemap == null)
16659
+ if (//envyoff ||
16660
+ cubemap == null)
1617216661 {
1617316662 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1617416663 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16183,7 +16672,17 @@
1618316672 // Compensates for ExaminerViewer's modification of modelview matrix
1618416673 gl.glMatrixMode(GL.GL_MODELVIEW);
1618516674 gl.glLoadIdentity();
16675
+ gl.glScalef(1,ratio,1);
1618616676
16677
+// colorV[0] = 2;
16678
+// colorV[1] = 2;
16679
+// colorV[2] = 2;
16680
+// colorV[3] = 1;
16681
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16682
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16683
+//
16684
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16685
+
1618716686 //gl.glActiveTexture(GL.GL_TEXTURE1);
1618816687 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1618916688
....@@ -16215,6 +16714,7 @@
1621516714 {
1621616715 gl.glScalef(1.0f, -1.0f, 1.0f);
1621716716 }
16717
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1621816718 gl.glMultMatrixd(viewrot_1, 0);
1621916719 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1622016720 //viewer.updateInverseRotation(gl);
....@@ -16355,16 +16855,16 @@
1635516855 cStatic.objectstack[materialdepth++] = checker;
1635616856 //System.out.println("material " + material);
1635716857 //Applet3D.tracein(this, selected);
16358
- vector2buffer = checker.projectedVertices;
16858
+ //vector2buffer = checker.projectedVertices;
1635916859
1636016860 //checker.GetMaterial().Draw(this, false); // true);
16361
- DrawMaterial(checker.GetMaterial(), false); // true);
16861
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1636216862
1636316863 materialdepth -= 1;
1636416864 if (materialdepth > 0)
1636516865 {
16366
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16367
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
16866
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16867
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1636816868 }
1636916869 //checker.GetMaterial().opacity = 1f;
1637016870 ////checker.GetMaterial().ambient = 1f;
....@@ -16450,6 +16950,14 @@
1645016950 }
1645116951 }
1645216952
16953
+ private Object3D GetFolder()
16954
+ {
16955
+ Object3D folder = object.GetWindow().copy;
16956
+ if (object.GetWindow().copy.selection.Size() > 0)
16957
+ folder = object.GetWindow().copy.selection.elementAt(0);
16958
+ return folder;
16959
+ }
16960
+
1645316961 class SelectBuffer implements GLEventListener
1645416962 {
1645516963
....@@ -16465,7 +16973,7 @@
1646516973 //new Exception().printStackTrace();
1646616974 System.out.println("select buffer init");
1646716975 // Use debug pipeline
16468
- drawable.setGL(new DebugGL(drawable.getGL()));
16976
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1646916977
1647016978 GL gl = drawable.getGL();
1647116979
....@@ -16529,6 +17037,17 @@
1652917037
1653017038 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1653117039
17040
+ if (PAINTMODE)
17041
+ {
17042
+ if (object.GetWindow().copy.selection.Size() > 0)
17043
+ {
17044
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17045
+
17046
+ // Make what you paint not selectable.
17047
+ paintobj.ResetSelectable();
17048
+ }
17049
+ }
17050
+
1653217051 //int tmp = selection_view;
1653317052 //selection_view = -1;
1653417053 int temp = DrawMode();
....@@ -16540,6 +17059,17 @@
1654017059 // temp = DEFAULT; // patch for selection debug
1654117060 Globals.drawMode = temp; // WARNING
1654217061
17062
+ if (PAINTMODE)
17063
+ {
17064
+ if (object.GetWindow().copy.selection.Size() > 0)
17065
+ {
17066
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17067
+
17068
+ // Revert.
17069
+ paintobj.RestoreSelectable();
17070
+ }
17071
+ }
17072
+
1654317073 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1654417074
1654517075 // trying different ways of getting the depth info over
....@@ -16587,6 +17117,8 @@
1658717117 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1658817118 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1658917119 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
17120
+
17121
+ CreateSelectedPoint();
1659017122
1659117123 // Will fit the mesh !!!
1659217124 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16641,29 +17173,31 @@
1664117173 }
1664217174
1664317175 if (!movingcamera && !PAINTMODE)
16644
- object.editWindow.ScreenFitPoint(); // fev 2014
17176
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1664517177
16646
- if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17178
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1664717179 {
16648
- Object3D paintobj = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17180
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1664917181
16650
- Object3D group = new Object3D("inst" + paintcount++);
17182
+ if (object.GetWindow().copy.selection.Size() > 0)
17183
+ {
17184
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1665117185
16652
- group.CreateMaterial(); // use a void leaf to select instances
16653
-
16654
- group.add(paintobj); // link
16655
-
16656
- object.editWindow.SnapObject(group);
16657
-
16658
- Object3D folder = object.editWindow.copy;
16659
-
16660
- if (object.editWindow.copy.selection.Size() > 0)
16661
- folder = object.editWindow.copy.selection.elementAt(0);
16662
-
16663
- folder.add(group);
16664
-
16665
- object.editWindow.ResetModel();
16666
- object.editWindow.refreshContents();
17186
+ Object3D inst = new Object3D("inst" + paintcount++);
17187
+
17188
+ inst.CreateMaterial(); // use a void leaf to select instances
17189
+
17190
+ inst.add(paintobj); // link
17191
+
17192
+ object.GetWindow().SnapObject(inst);
17193
+
17194
+ Object3D folder = paintFolder; // GetFolder();
17195
+
17196
+ folder.add(inst);
17197
+
17198
+ object.GetWindow().ResetModel();
17199
+ object.GetWindow().refreshContents();
17200
+ }
1666717201 }
1666817202 else
1666917203 paintcount = 0;
....@@ -16702,6 +17236,11 @@
1670217236 //System.out.println("objects[color] = " + objects[color]);
1670317237 //objects[color].Select();
1670417238 indexcount = 0;
17239
+ ObjEditor window = object.GetWindow();
17240
+ if (window != null && deselect)
17241
+ {
17242
+ window.Select(null, deselect, true);
17243
+ }
1670517244 object.Select(color, deselect);
1670617245 }
1670717246
....@@ -17227,23 +17766,15 @@
1722717766 int AAbuffersize = 0;
1722817767
1722917768 //double[] selectedpoint = new double[3];
17230
- static Superellipsoid selectedpoint = new Superellipsoid();
17769
+ static Superellipsoid selectedpoint;
1723117770 static Sphere previousselectedpoint = null;
17232
- static Sphere debugpointG = new Sphere();
17233
- static Sphere debugpointP = new Sphere();
17234
- static Sphere debugpointC = new Sphere();
17235
- static Sphere debugpointR = new Sphere();
17771
+ static Sphere debugpointG;
17772
+ static Sphere debugpointP;
17773
+ static Sphere debugpointC;
17774
+ static Sphere debugpointR;
1723617775
1723717776 static Sphere debugpoints[] = new Sphere[8];
1723817777
17239
- static
17240
- {
17241
- for (int i=0; i<8; i++)
17242
- {
17243
- debugpoints[i] = new Sphere();
17244
- }
17245
- }
17246
-
1724717778 static void InitPoints(float radius)
1724817779 {
1724917780 for (int i=0; i<8; i++)