Normand Briere
2019-08-12 b1d79b74514041a059b454a9f6fc3970773c0cb8
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) && !texname.startsWith("@"))
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,22 @@
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();
8442
+ } else
8443
+ {
8444
+ if (texname.startsWith("@"))
8445
+ {
8446
+ // texturecache = textures.get(texname); // suspicious
8447
+ if (texturecache == null)
8448
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8449
+ else
8450
+ new Exception().printStackTrace();
82818451 } else
82828452 {
82838453 if (textureon)
....@@ -8336,19 +8506,20 @@
83368506 if (texturedata == null)
83378507 throw new Exception();
83388508
8339
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8509
+ texturecache = new CacheTexture(texturedata,resolution);
83408510 //texture = GetTexture(tex, bump);
83418511 }
8512
+ }
83428513 }
83438514 //}
83448515 }
83458516
8346
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8517
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
83478518 {
83488519 //return false;
83498520
83508521 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8351
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8522
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
83528523 {
83538524 // String ext = "_highres";
83548525 // if (REDUCETEXTURE)
....@@ -8365,52 +8536,17 @@
83658536 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
83668537 if (!cachefile.exists())
83678538 {
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))
8539
+ //if (texturedata.getWidth() == texturedata.getHeight())
83778540 {
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);
8541
+ BufferedImage rendImage = CreateBim(texturedata);
8542
+
84088543 ImageWriter writer = null;
84098544 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
84108545 if (iter.hasNext()) {
84118546 writer = (ImageWriter)iter.next();
84128547 }
8413
- float compressionQuality = 0.9f;
8548
+
8549
+ float compressionQuality = 0.85f;
84148550 try
84158551 {
84168552 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8427,18 +8563,20 @@
84278563 }
84288564 }
84298565 }
8430
-
8566
+
8567
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8568
+
84318569 //System.out.println("Texture = " + tex);
8432
- if (textures.containsKey(texname))
8570
+ if (textures.containsKey(tex))
84338571 {
8434
- CacheTexture thetex = textures.get(texname);
8572
+ CacheTexture thetex = textures.get(tex);
84358573 thetex.texture.disable();
84368574 thetex.texture.dispose();
8437
- textures.remove(texname);
8575
+ textures.remove(tex);
84388576 }
84398577
8440
- texture.texturedata = texturedata;
8441
- textures.put(texname, texture);
8578
+ //texture.texturedata = texturedata;
8579
+ textures.put(tex, texturecache);
84428580
84438581 // newtex = true;
84448582 }
....@@ -8454,10 +8592,44 @@
84548592 }
84558593 }
84568594
8457
- return texture;
8595
+ return texturecache;
84588596 }
84598597
8460
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution) throws Exception
8598
+ static void EmbedTextures(cTexture tex)
8599
+ {
8600
+ if (tex.pigmentdata == null)
8601
+ {
8602
+ //String texname = Object3D.GetPigment(tex);
8603
+
8604
+ CacheTexture texturecache = texturepigment.get(tex);
8605
+
8606
+ if (texturecache != null)
8607
+ {
8608
+ tex.pw = texturecache.texturedata.getWidth();
8609
+ tex.ph = texturecache.texturedata.getHeight();
8610
+ tex.pigmentdata = //CompressJPEG(CreateBim
8611
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8612
+ ;
8613
+ //, tex.pw, tex.ph), 0.5f);
8614
+ }
8615
+ }
8616
+
8617
+ if (tex.bumpdata == null)
8618
+ {
8619
+ //String texname = Object3D.GetBump(tex);
8620
+
8621
+ CacheTexture texturecache = texturebump.get(tex);
8622
+
8623
+ if (texturecache != null)
8624
+ {
8625
+ tex.bw = texturecache.texturedata.getWidth();
8626
+ tex.bh = texturecache.texturedata.getHeight();
8627
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8628
+ }
8629
+ }
8630
+ }
8631
+
8632
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
84618633 {
84628634 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
84638635
....@@ -8475,21 +8647,21 @@
84758647 return texture!=null?texture.texture:null;
84768648 }
84778649
8478
- public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution) throws Exception
8650
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
84798651 {
84808652 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
84818653
84828654 return texture!=null?texture.texturedata:null;
84838655 }
84848656
8485
- boolean BindTexture(String tex, boolean bump, int resolution) throws Exception
8657
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
84868658 {
84878659 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
84888660 {
84898661 return false;
84908662 }
84918663
8492
- boolean newtex = false;
8664
+ //boolean newtex = false;
84938665
84948666 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
84958667
....@@ -8521,9 +8693,75 @@
85218693 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
85228694 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
85238695
8524
- return newtex;
8696
+ return true; // Warning: not used.
85258697 }
85268698
8699
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8700
+ {
8701
+ try
8702
+ {
8703
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8704
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8705
+ ImageWriter writer = writers.next();
8706
+
8707
+ ImageWriteParam param = writer.getDefaultWriteParam();
8708
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8709
+ param.setCompressionQuality(quality);
8710
+
8711
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8712
+ writer.setOutput(ios);
8713
+ writer.write(null, new IIOImage(image, null, null), param);
8714
+
8715
+ byte[] data = baos.toByteArray();
8716
+ writer.dispose();
8717
+ return data;
8718
+ }
8719
+ catch (Exception e)
8720
+ {
8721
+ e.printStackTrace();
8722
+ return null;
8723
+ }
8724
+ }
8725
+
8726
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8727
+ {
8728
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8729
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8730
+ ImageReader reader = writers.next();
8731
+
8732
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8733
+
8734
+ ImageReadParam param = reader.getDefaultReadParam();
8735
+ param.setDestination(bim);
8736
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8737
+
8738
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8739
+ reader.setInput(ios);
8740
+ BufferedImage bim2 = reader.read(0, param);
8741
+ reader.dispose();
8742
+
8743
+// WritableRaster raster = bim2.getRaster();
8744
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8745
+// byte[] bytes = data.getData();
8746
+//
8747
+// int[] pixels = new int[bytes.length/3];
8748
+// for (int i=pixels.length; --i>=0;)
8749
+// {
8750
+// int i3 = i*3;
8751
+// pixels[i] = 0xFF;
8752
+// pixels[i] <<= 8;
8753
+// pixels[i] |= bytes[i3+2] & 0xFF;
8754
+// pixels[i] <<= 8;
8755
+// pixels[i] |= bytes[i3+1] & 0xFF;
8756
+// pixels[i] <<= 8;
8757
+// pixels[i] |= bytes[i3] & 0xFF;
8758
+// }
8759
+//
8760
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8761
+
8762
+ return bim;
8763
+ }
8764
+
85278765 ShadowBuffer shadowPBuf;
85288766 AntialiasBuffer antialiasPBuf;
85298767 int MAXSTACK;
....@@ -8716,7 +8954,7 @@
87168954
87178955 if (cubemap == null)
87188956 {
8719
- LoadEnvy(5);
8957
+ //LoadEnvy(1);
87208958 }
87218959
87228960 //cubemap.enable();
....@@ -9003,37 +9241,58 @@
90039241 cubemap = null;
90049242 return;
90059243 case 1:
9006
- name = "cubemaps/box_";
9007
- ext = "png";
9244
+ name = "cubemaps/rgb/";
9245
+ ext = "jpg";
90089246 reverseUP = false;
90099247 break;
90109248 case 2:
9011
- name = "cubemaps/uffizi_";
9012
- ext = "png";
9013
- break; // reverseUP = true; break;
9249
+ name = "cubemaps/uffizi/";
9250
+ ext = "jpg";
9251
+ reverseUP = false;
9252
+ break;
90149253 case 3:
9015
- name = "cubemaps/CloudyHills_";
9016
- ext = "tga";
9254
+ name = "cubemaps/CloudyHills/";
9255
+ ext = "jpg";
90179256 reverseUP = false;
90189257 break;
90199258 case 4:
9020
- name = "cubemaps/cornell_";
9259
+ name = "cubemaps/cornell/";
90219260 ext = "png";
90229261 reverseUP = false;
90239262 break;
9263
+ case 5:
9264
+ name = "cubemaps/skycube/";
9265
+ ext = "jpg";
9266
+ reverseUP = false;
9267
+ break;
9268
+ case 6:
9269
+ name = "cubemaps/SaintLazarusChurch3/";
9270
+ ext = "jpg";
9271
+ reverseUP = false;
9272
+ break;
9273
+ case 7:
9274
+ name = "cubemaps/Sodermalmsallen/";
9275
+ ext = "jpg";
9276
+ reverseUP = false;
9277
+ break;
9278
+ case 8:
9279
+ name = "cubemaps/Sodermalmsallen2/";
9280
+ ext = "jpg";
9281
+ reverseUP = false;
9282
+ break;
9283
+ case 9:
9284
+ name = "cubemaps/UnionSquare/";
9285
+ ext = "jpg";
9286
+ reverseUP = false;
9287
+ break;
90249288 default:
9025
- name = "cubemaps/rgb_";
9026
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9289
+ name = "cubemaps/box/";
9290
+ ext = "png"; /*mipmap = true;*/
9291
+ reverseUP = false;
90279292 break;
90289293 }
9029
-
9030
- try
9031
- {
9032
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
9033
- } catch (IOException e)
9034
- {
9035
- throw new RuntimeException(e);
9036
- }
9294
+
9295
+ LoadSkybox(name, ext, mipmap);
90379296 }
90389297
90399298 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -9065,8 +9324,12 @@
90659324 static double[] model = new double[16];
90669325 double[] camera2light = new double[16];
90679326 double[] light2camera = new double[16];
9068
- int newenvy = -1;
9069
- boolean envyoff = true; // false;
9327
+
9328
+ //int newenvy = -1;
9329
+ //boolean envyoff = false;
9330
+
9331
+ String loadedskyboxname;
9332
+
90709333 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
90719334 //float[] light0 = { 0,0,0 };
90729335 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9359,11 +9622,35 @@
93599622 jy8[3] = 0.5f;
93609623 }
93619624
9362
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9625
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
93639626 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
93649627 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
93659628 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
93669629
9630
+ void ResetOptions()
9631
+ {
9632
+ options1[0] = 100;
9633
+ options1[1] = 0.025f;
9634
+ options1[2] = 0.01f;
9635
+ options1[3] = 0;
9636
+ options1[4] = 0;
9637
+
9638
+ options2[0] = 0;
9639
+ options2[1] = 0.75f;
9640
+ options2[2] = 0;
9641
+ options2[3] = 0;
9642
+
9643
+ options3[0] = 1;
9644
+ options3[1] = 1;
9645
+ options3[2] = 1;
9646
+ options3[3] = 0;
9647
+
9648
+ options4[0] = 1;
9649
+ options4[1] = 0;
9650
+ options4[2] = 1;
9651
+ options4[3] = 0;
9652
+ }
9653
+
93679654 static int imagecount = 0; // movie generation
93689655
93699656 static int jitter = 0;
....@@ -9460,7 +9747,7 @@
94609747
94619748 if (renderCamera != lightCamera)
94629749 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9463
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
9750
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
94649751
94659752 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
94669753
....@@ -9476,7 +9763,7 @@
94769763
94779764 if (renderCamera != lightCamera)
94789765 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9479
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
9766
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
94809767
94819768 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
94829769
....@@ -9522,10 +9809,12 @@
95229809 rati = 1 / rati;
95239810 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
95249811 }
9525
- assert (newenvy == -1);
9812
+
9813
+ //assert (newenvy == -1);
9814
+
95269815 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
95279816 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9528
- DrawSkyBox(gl);
9817
+ DrawSkyBox(gl, (float)rati);
95299818 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
95309819 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
95319820 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10474,6 +10763,7 @@
1047410763 ANTIALIAS = 0;
1047510764 //System.out.println("RESTART");
1047610765 AAtimer.restart();
10766
+ Globals.TIMERRUNNING = true;
1047710767 }
1047810768 }
1047910769 }
....@@ -10541,7 +10831,8 @@
1054110831 ambientOcclusion = false;
1054210832 }
1054310833
10544
- if (Globals.lighttouched && DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
10834
+ if (//Globals.lighttouched &&
10835
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1054510836 {
1054610837 //if (RENDERSHADOW) // ?
1054710838 if (!IsFrozen())
....@@ -10560,7 +10851,7 @@
1056010851
1056110852 if (wait)
1056210853 {
10563
- Sleep(500);
10854
+ Sleep(200); // blocks everything
1056410855
1056510856 wait = false;
1056610857 }
....@@ -10675,7 +10966,7 @@
1067510966 // if (parentcam != renderCamera) // not a light
1067610967 if (cam != lightCamera)
1067710968 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10678
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
10969
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1067910970
1068010971 for (int j = 0; j < 4; j++)
1068110972 {
....@@ -10690,7 +10981,7 @@
1069010981 // if (parentcam != renderCamera) // not a light
1069110982 if (cam != lightCamera)
1069210983 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10693
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
10984
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1069410985
1069510986 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1069610987
....@@ -10776,13 +11067,27 @@
1077611067 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1077711068 }
1077811069
10779
- if (newenvy > -1)
11070
+// if (newenvy > -1)
11071
+// {
11072
+// LoadEnvy(newenvy);
11073
+// }
11074
+//
11075
+// newenvy = -1;
11076
+
11077
+ if (object.skyboxname != null)
1078011078 {
10781
- LoadEnvy(newenvy);
11079
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11080
+ {
11081
+ LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11082
+ loadedskyboxname = object.skyboxname;
11083
+ }
1078211084 }
10783
-
10784
- newenvy = -1;
10785
-
11085
+ else
11086
+ {
11087
+ cubemap = null;
11088
+ loadedskyboxname = null;
11089
+ }
11090
+
1078611091 ratio = ((double) getWidth()) / getHeight();
1078711092 //System.out.println("ratio = " + ratio);
1078811093
....@@ -10798,7 +11103,7 @@
1079811103
1079911104 if (!IsFrozen() && !ambientOcclusion)
1080011105 {
10801
- DrawSkyBox(gl);
11106
+ DrawSkyBox(gl, (float)ratio);
1080211107 }
1080311108
1080411109 //if (selection_view == -1)
....@@ -10981,9 +11286,9 @@
1098111286
1098211287 gl.glMatrixMode(GL.GL_MODELVIEW);
1098311288
10984
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10985
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10986
-//gl.glEnable(gl.GL_MULTISAMPLE);
11289
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11290
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11291
+gl.glEnable(gl.GL_MULTISAMPLE);
1098711292 } else
1098811293 {
1098911294 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -10994,7 +11299,7 @@
1099411299 //System.out.println("BLENDING ON");
1099511300 gl.glEnable(GL.GL_BLEND);
1099611301 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
10997
-
11302
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1099811303 gl.glMatrixMode(gl.GL_PROJECTION);
1099911304 gl.glLoadIdentity();
1100011305
....@@ -11084,7 +11389,7 @@
1108411389
1108511390 // if (cam != lightCamera)
1108611391 //for (int count = parentcam.GetTransformCount(); --count>=0;)
11087
- LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
11392
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1108811393 }
1108911394
1109011395 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -11243,7 +11548,7 @@
1124311548 }
1124411549 }
1124511550
11246
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11551
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1124711552 {
1124811553 //gl.glDepthFunc(GL.GL_LEQUAL);
1124911554 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11251,24 +11556,21 @@
1125111556
1125211557 boolean texon = textureon;
1125311558
11254
- if (RENDERPROGRAM > 0)
11255
- {
11256
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11257
- textureon = false;
11258
- }
11559
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11560
+ textureon = false;
11561
+
1125911562 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1126011563 //System.out.println("ALLO");
1126111564 gl.glColorMask(false, false, false, false);
1126211565 DrawObject(gl);
11263
- if (RENDERPROGRAM > 0)
11264
- {
11265
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11266
- textureon = texon;
11267
- }
11566
+
11567
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11568
+ textureon = texon;
11569
+
1126811570 gl.glColorMask(true, true, true, true);
1126911571
1127011572 gl.glDepthFunc(GL.GL_EQUAL);
11271
- //gl.glDepthMask(false);
11573
+ gl.glDepthMask(false);
1127211574 }
1127311575
1127411576 if (false) // DrawMode() == SHADOW)
....@@ -11451,15 +11753,36 @@
1145111753
1145211754 static boolean zoomonce = false;
1145311755
11756
+ static void CreateSelectedPoint()
11757
+ {
11758
+ if (selectedpoint == null)
11759
+ {
11760
+ debugpointG = new Sphere();
11761
+ debugpointP = new Sphere();
11762
+ debugpointC = new Sphere();
11763
+ debugpointR = new Sphere();
11764
+
11765
+ selectedpoint = new Superellipsoid();
11766
+
11767
+ for (int i=0; i<8; i++)
11768
+ {
11769
+ debugpoints[i] = new Sphere();
11770
+ }
11771
+ }
11772
+ }
11773
+
1145411774 void DrawObject(GL gl, boolean draw)
1145511775 {
11776
+ // To clear camera values
11777
+ ResetOptions();
11778
+
1145611779 //System.out.println("DRAW OBJECT " + mouseDown);
1145711780 // DrawMode() = SELECTION;
1145811781 //GL gl = getGL();
1145911782 if ((TRACK || SHADOWTRACK) || zoomonce)
1146011783 {
1146111784 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11462
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11785
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1146311786 pingthread.StepToTarget(true); // true);
1146411787 // zoomonce = false;
1146511788 }
....@@ -11531,8 +11854,9 @@
1153111854
1153211855 if (DrawMode() == DEFAULT)
1153311856 {
11534
- if (DEBUG)
11857
+ if (Globals.DEBUG)
1153511858 {
11859
+ CreateSelectedPoint();
1153611860 float radius = 0.05f;
1153711861 if (selectedpoint.radius != radius)
1153811862 {
....@@ -11586,20 +11910,32 @@
1158611910 ReleaseTextures(DEFAULT_TEXTURES);
1158711911
1158811912 if (CLEANCACHE)
11589
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11913
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1159011914 {
11591
- String tex = e.nextElement();
11915
+ cTexture tex = e.nextElement();
1159211916
1159311917 // System.out.println("Texture --------- " + tex);
1159411918
11595
- if (tex.equals("WHITE_NOISE"))
11919
+ if (tex.equals("WHITE_NOISE:"))
1159611920 continue;
1159711921
11598
- if (!usedtextures.containsKey(tex))
11922
+ if (!usedtextures.contains(tex))
1159911923 {
11924
+ CacheTexture gettex = texturepigment.get(tex);
1160011925 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11601
- textures.get(tex).texture.dispose();
11602
- textures.remove(tex);
11926
+ if (gettex != null)
11927
+ {
11928
+ gettex.texture.dispose();
11929
+ texturepigment.remove(tex);
11930
+ }
11931
+
11932
+ gettex = texturebump.get(tex);
11933
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11934
+ if (gettex != null)
11935
+ {
11936
+ gettex.texture.dispose();
11937
+ texturebump.remove(tex);
11938
+ }
1160311939 }
1160411940 }
1160511941 }
....@@ -12019,7 +12355,7 @@
1201912355 for (int i = tp.size(); --i >= 0;)
1202012356 {
1202112357 //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12022
- LA.xformPos(light, tp.get(i).GlobalTransform(), light);
12358
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1202312359 }
1202412360
1202512361
....@@ -12127,8 +12463,76 @@
1212712463
1212812464 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1212912465
12130
- String program =
12466
+ String programmin =
12467
+ // Min shader
1213112468 "!!ARBfp1.0\n" +
12469
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12470
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12471
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12472
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12473
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12474
+ "PARAM light2cam0 = program.env[10];" +
12475
+ "PARAM light2cam1 = program.env[11];" +
12476
+ "PARAM light2cam2 = program.env[12];" +
12477
+ "TEMP temp;" +
12478
+ "TEMP light;" +
12479
+ "TEMP ndotl;" +
12480
+ "TEMP normal;" +
12481
+ "TEMP depth;" +
12482
+ "TEMP eye;" +
12483
+ "TEMP pos;" +
12484
+
12485
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12486
+ Normalize("normal") +
12487
+ "MOV light, state.light[0].position;" +
12488
+ "DP3 ndotl.x, light, normal;" +
12489
+
12490
+ // shadow
12491
+ "MOV pos, fragment.texcoord[1];" +
12492
+ "MOV temp, pos;" +
12493
+ ShadowTextureFetch("depth", "temp", "1") +
12494
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12495
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12496
+
12497
+ // No shadow when out of frustum
12498
+ //"SGE temp.y, depth.z, zero123.y;" +
12499
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12500
+
12501
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12502
+
12503
+ // Backlit
12504
+ "MOV pos.w, zero123.y;" +
12505
+ "DP4 eye.x, pos, light2cam0;" +
12506
+ "DP4 eye.y, pos, light2cam1;" +
12507
+ "DP4 eye.z, pos, light2cam2;" +
12508
+ Normalize("eye") +
12509
+
12510
+ "DP3 ndotl.y, -eye, normal;" +
12511
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12512
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12513
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12514
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12515
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12516
+
12517
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12518
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12519
+
12520
+ // Pigment
12521
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12522
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12523
+ "MUL temp, temp, ndotl.x;" +
12524
+
12525
+ "MUL temp, temp, zero123.z;" +
12526
+
12527
+ //"MUL temp, temp, ndotl.y;" +
12528
+
12529
+ "MOV temp.w, zero123.y;" + // reset alpha
12530
+ "MOV result.color, temp;" +
12531
+ "END";
12532
+
12533
+ String programmax =
12534
+ "!!ARBfp1.0\n" +
12535
+
1213212536 //"OPTION ARB_fragment_program_shadow;" +
1213312537 "PARAM light2cam0 = program.env[10];" +
1213412538 "PARAM light2cam1 = program.env[11];" +
....@@ -12243,8 +12647,7 @@
1224312647 "TEMP shininess;" +
1224412648 "\n" +
1224512649 "MOV texSamp, one;" +
12246
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12247
-
12650
+
1224812651 "MOV mapgrid.x, one2048th.x;" +
1224912652 "MOV temp, fragment.texcoord[1];" +
1225012653 /*
....@@ -12265,20 +12668,20 @@
1226512668 "MUL temp, floor, mapgrid.x;" +
1226612669 //"TEX depth0, temp, texture[1], 2D;" +
1226712670 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12268
- TextureFetch("depth0", "temp", "1") +
12671
+ ShadowTextureFetch("depth0", "temp", "1") +
1226912672 "") +
1227012673 "ADD temp.x, temp.x, mapgrid.x;" +
1227112674 //"TEX depth1, temp, texture[1], 2D;" +
1227212675 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12273
- TextureFetch("depth1", "temp", "1") +
12676
+ ShadowTextureFetch("depth1", "temp", "1") +
1227412677 "") +
1227512678 "ADD temp.y, temp.y, mapgrid.x;" +
1227612679 //"TEX depth2, temp, texture[1], 2D;" +
12277
- TextureFetch("depth2", "temp", "1") +
12680
+ ShadowTextureFetch("depth2", "temp", "1") +
1227812681 "SUB temp.x, temp.x, mapgrid.x;" +
1227912682 //"TEX depth3, temp, texture[1], 2D;" +
1228012683 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12281
- TextureFetch("depth3", "temp", "1") +
12684
+ ShadowTextureFetch("depth3", "temp", "1") +
1228212685 "") +
1228312686 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1228412687 //"MOV params, material;" +
....@@ -12649,10 +13052,10 @@
1264913052 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1265013053 "") +
1265113054
12652
- // display shadow only (bump == 0)
13055
+ // display shadow only (fakedepth == 0)
1265313056 "SUB temp.x, half.x, shadow.x;" +
1265413057 "MOV temp.y, -params5.z;" + // params6.x;" +
12655
- "SLT temp.z, temp.y, -one2048th.x;" +
13058
+ "SLT temp.z, temp.y, -c256i.x;" +
1265613059 "SUB temp.y, one.x, temp.z;" +
1265713060 "MUL temp.x, temp.x, temp.y;" +
1265813061 "KIL temp.x;" +
....@@ -12983,6 +13386,13 @@
1298313386 //once = true;
1298413387 }
1298513388
13389
+ String program = programmax;
13390
+
13391
+ if (Globals.MINSHADER)
13392
+ {
13393
+ program = programmin;
13394
+ }
13395
+
1298613396 System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1298713397 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1298813398 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
....@@ -13076,25 +13486,26 @@
1307613486 return out;
1307713487 }
1307813488
13079
- String TextureFetch(String dest, String src, String unit)
13489
+ // Also does frustum culling
13490
+ String ShadowTextureFetch(String dest, String src, String unit)
1308013491 {
1308113492 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1308213493 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1308313494 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13495
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13496
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1308413497 "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;" +
13498
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13499
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1308913500 //"SWZ buffer, temp, w,w,w,w;";
13090
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13501
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1309113502 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1309213503 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1309313504 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13094
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13505
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1309513506
13096
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13097
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13507
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13508
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1309813509 }
1309913510
1310013511 String Shadow(String depth, String shadow)
....@@ -13141,7 +13552,7 @@
1314113552 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1314213553 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1314313554
13144
- // No shadow when out of frustrum
13555
+ // No shadow when out of frustum
1314513556 "SGE temp.x, " + depth + ".z, one.z;" +
1314613557 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1314713558 "";
....@@ -13289,7 +13700,8 @@
1328913700 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1329013701 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1329113702 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13292
- Object3D.cVector2[] vector2buffer;
13703
+
13704
+ //Object3D.cVector2[] vector2buffer;
1329313705
1329413706 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1329513707 // OUT : diff, spec
....@@ -13305,9 +13717,10 @@
1330513717 "DP3 " + dest + ".z," + "normals," + "eye;" +
1330613718 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1330713719 //"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;" +
13720
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13721
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13722
+
13723
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1331113724 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1331213725 "RCP " + dest + ".w," + dest + ".w;" +
1331313726 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13812,6 +14225,7 @@
1381214225 else
1381314226 if (evt.getSource() == AAtimer)
1381414227 {
14228
+ Globals.TIMERRUNNING = false;
1381514229 if (mouseDown)
1381614230 {
1381714231 //new Exception().printStackTrace();
....@@ -13871,7 +14285,7 @@
1387114285
1387214286 // fev 2014???
1387314287 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13874
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14288
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1387514289 pingthread.StepToTarget(true); // true);
1387614290 }
1387714291 // if (!LIVE)
....@@ -13886,6 +14300,7 @@
1388614300 return;
1388714301
1388814302 AAtimer.restart(); //
14303
+ Globals.TIMERRUNNING = true;
1388914304
1389014305 // waslive = LIVE;
1389114306 // LIVE = false;
....@@ -13935,14 +14350,15 @@
1393514350 drag = false;
1393614351 //System.out.println("Mouse DOWN");
1393714352 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);
14353
+ //ClickInfo info = new ClickInfo();
14354
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14355
+ object.clickInfo.pane = this;
14356
+ object.clickInfo.camera = renderCamera;
14357
+ object.clickInfo.x = x;
14358
+ object.clickInfo.y = y;
14359
+ object.clickInfo.modifiers = modifiersex;
14360
+ editObj = object.doEditClick(//info,
14361
+ 0);
1394614362 if (!editObj)
1394714363 {
1394814364 hasMarquee = true;
....@@ -14224,12 +14640,12 @@
1422414640 void GoDown(int mod)
1422514641 {
1422614642 MODIFIERS |= COMMAND;
14227
- /*
14643
+ /**/
1422814644 if((mod&SHIFT) == SHIFT)
14229
- manipCamera.RotatePosition(0, -speed);
14645
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
1423014646 else
14231
- manipCamera.BackForth(0, -speed*delta, getWidth());
14232
- */
14647
+ manipCamera.RotatePosition(0, -speed);
14648
+ /**/
1423314649 if ((mod & SHIFT) == SHIFT)
1423414650 {
1423514651 mouseMode = mouseMode; // VR??
....@@ -14245,12 +14661,12 @@
1424514661 void GoUp(int mod)
1424614662 {
1424714663 MODIFIERS |= COMMAND;
14248
- /*
14664
+ /**/
1424914665 if((mod&SHIFT) == SHIFT)
14250
- manipCamera.RotatePosition(0, speed);
14666
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
1425114667 else
14252
- manipCamera.BackForth(0, speed*delta, getWidth());
14253
- */
14668
+ manipCamera.RotatePosition(0, speed);
14669
+ /**/
1425414670 if ((mod & SHIFT) == SHIFT)
1425514671 {
1425614672 mouseMode = mouseMode;
....@@ -14266,12 +14682,12 @@
1426614682 void GoLeft(int mod)
1426714683 {
1426814684 MODIFIERS |= COMMAND;
14269
- /*
14685
+ /**/
1427014686 if((mod&SHIFT) == SHIFT)
14271
- manipCamera.RotatePosition(speed, 0);
14272
- else
1427314687 manipCamera.Translate(speed*delta, 0, getWidth());
14274
- */
14688
+ else
14689
+ manipCamera.RotatePosition(speed, 0);
14690
+ /**/
1427514691 if ((mod & SHIFT) == SHIFT)
1427614692 {
1427714693 mouseMode = mouseMode;
....@@ -14287,12 +14703,12 @@
1428714703 void GoRight(int mod)
1428814704 {
1428914705 MODIFIERS |= COMMAND;
14290
- /*
14706
+ /**/
1429114707 if((mod&SHIFT) == SHIFT)
14292
- manipCamera.RotatePosition(-speed, 0);
14293
- else
1429414708 manipCamera.Translate(-speed*delta, 0, getWidth());
14295
- */
14709
+ else
14710
+ manipCamera.RotatePosition(-speed, 0);
14711
+ /**/
1429614712 if ((mod & SHIFT) == SHIFT)
1429714713 {
1429814714 mouseMode = mouseMode;
....@@ -14342,14 +14758,16 @@
1434214758 if (editObj)
1434314759 {
1434414760 drag = true;
14345
- ClickInfo info = new ClickInfo();
14346
- info.bounds.setBounds(0, 0,
14761
+ //ClickInfo info = new ClickInfo();
14762
+ object.clickInfo.bounds.setBounds(0, 0,
1434714763 (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);
14764
+ object.clickInfo.pane = this;
14765
+ object.clickInfo.camera = renderCamera;
14766
+ object.clickInfo.x = x;
14767
+ object.clickInfo.y = y;
14768
+ object //.GetWindow().copy
14769
+ .doEditDrag(//info,
14770
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1435314771 } else
1435414772 {
1435514773 if (x < startX)
....@@ -14498,22 +14916,27 @@
1449814916 }
1449914917 }
1450014918
14919
+// ClickInfo clickInfo = new ClickInfo();
14920
+
1450114921 public void mouseMoved(MouseEvent e)
1450214922 {
1450314923 //System.out.println("mouseMoved: " + e);
1450414924 if (isRenderer)
1450514925 return;
1450614926
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;
14927
+ // Mouse cursor feedback
14928
+ object.clickInfo.x = e.getX();
14929
+ object.clickInfo.y = e.getY();
14930
+ object.clickInfo.modifiers = e.getModifiersEx();
14931
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14932
+ object.clickInfo.pane = this;
14933
+ object.clickInfo.camera = renderCamera;
1451414934 if (!isRenderer)
1451514935 {
14516
- if (object.editWindow.copy.doEditClick(ci, 0))
14936
+ //ObjEditor editWindow = object.editWindow;
14937
+ //Object3D copy = editWindow.copy;
14938
+ if (object.doEditClick(//clickInfo,
14939
+ 0))
1451714940 {
1451814941 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1451914942 } else
....@@ -14528,7 +14951,8 @@
1452814951 Globals.MOUSEDRAGGED = false;
1452914952
1453014953 movingcamera = false;
14531
- X = Y = 0;
14954
+ X = 0; // getBounds().width/2;
14955
+ Y = 0; // getBounds().height/2;
1453214956 //System.out.println("mouseReleased: " + e);
1453314957 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1453414958 }
....@@ -14784,7 +15208,8 @@
1478415208 // break;
1478515209 case 'T':
1478615210 CACHETEXTURE ^= true;
14787
- textures.clear();
15211
+ texturepigment.clear();
15212
+ texturebump.clear();
1478815213 // repaint();
1478915214 break;
1479015215 case 'Y':
....@@ -14869,7 +15294,9 @@
1486915294 case 'E' : COMPACT ^= true;
1487015295 repaint();
1487115296 break;
14872
- case 'W' : DEBUGHSB ^= true;
15297
+ case 'W' : // Wide Window (fullscreen)
15298
+ //DEBUGHSB ^= true;
15299
+ ObjEditor.theFrame.ToggleFullScreen();
1487315300 repaint();
1487415301 break;
1487515302 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14894,8 +15321,8 @@
1489415321 RevertCamera();
1489515322 repaint();
1489615323 break;
14897
- case 'L':
1489815324 case 'l':
15325
+ //case 'L':
1489915326 if (lightMode)
1490015327 {
1490115328 lightMode = false;
....@@ -14959,20 +15386,24 @@
1495915386 OCCLUSION_CULLING ^= true;
1496015387 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1496115388 break;
14962
- case '0': envyoff ^= true; repaint(); break;
15389
+ //case '0': envyoff ^= true; repaint(); break;
1496315390 case '1':
1496415391 case '2':
1496515392 case '3':
1496615393 case '4':
1496715394 case '5':
14968
- newenvy = Character.getNumericValue(key);
14969
- repaint();
14970
- break;
1497115395 case '6':
1497215396 case '7':
1497315397 case '8':
1497415398 case '9':
14975
- BGcolor = (key - '6')/3.f;
15399
+ if (true) // envyoff)
15400
+ {
15401
+ BGcolor = (key - '1')/8.f;
15402
+ }
15403
+ else
15404
+ {
15405
+ //newenvy = Character.getNumericValue(key);
15406
+ }
1497615407 repaint();
1497715408 break;
1497815409 case '!':
....@@ -15038,9 +15469,9 @@
1503815469 case '_':
1503915470 kompactbit = 5;
1504015471 break;
15041
- case '+':
15042
- kompactbit = 6;
15043
- break;
15472
+// case '+':
15473
+// kompactbit = 6;
15474
+// break;
1504415475 case ' ':
1504515476 lightMode ^= true;
1504615477 Globals.lighttouched = true;
....@@ -15052,6 +15483,7 @@
1505215483 case ESC:
1505315484 RENDERPROGRAM += 1;
1505415485 RENDERPROGRAM %= 3;
15486
+
1505515487 repaint();
1505615488 break;
1505715489 case 'Z':
....@@ -15091,8 +15523,9 @@
1509115523 case DELETE:
1509215524 ClearSelection();
1509315525 break;
15094
- /*
1509515526 case '+':
15527
+
15528
+ /*
1509615529 //fontsize += 1;
1509715530 bbzoom *= 2;
1509815531 repaint();
....@@ -15109,17 +15542,17 @@
1510915542 case '=':
1511015543 IncDepth();
1511115544 //fontsize += 1;
15112
- object.editWindow.refreshContents(true);
15545
+ object.GetWindow().refreshContents(true);
1511315546 maskbit = 6;
1511415547 break;
1511515548 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1511615549 DecDepth();
1511715550 maskbit = 5;
1511815551 //if(fontsize > 1) fontsize -= 1;
15119
- if (object.editWindow == null)
15120
- new Exception().printStackTrace();
15121
- else
15122
- object.editWindow.refreshContents(true);
15552
+// if (object.editWindow == null)
15553
+// new Exception().printStackTrace();
15554
+// else
15555
+ object.GetWindow().refreshContents(true);
1512315556 break;
1512415557 case '{':
1512515558 manipCamera.shaper_fovy /= 1.1;
....@@ -15343,7 +15776,7 @@
1534315776 }
1534415777 */
1534515778
15346
- object.editWindow.EditSelection();
15779
+ object.GetWindow().EditSelection(false);
1534715780 }
1534815781
1534915782 void SelectParent()
....@@ -15360,10 +15793,10 @@
1536015793 {
1536115794 //selectees.remove(i);
1536215795 System.out.println("select parent of " + elem);
15363
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15796
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1536415797 } else
1536515798 {
15366
- group.editWindow.Select(elem.GetTreePath(), first, true);
15799
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1536715800 }
1536815801
1536915802 first = false;
....@@ -15405,12 +15838,12 @@
1540515838 for (int j = 0; j < group.children.size(); j++)
1540615839 {
1540715840 elem = (Object3D) group.children.elementAt(j);
15408
- object.editWindow.Select(elem.GetTreePath(), first, true);
15841
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1540915842 first = false;
1541015843 }
1541115844 } else
1541215845 {
15413
- object.editWindow.Select(elem.GetTreePath(), first, true);
15846
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1541415847 }
1541515848
1541615849 first = false;
....@@ -15421,21 +15854,21 @@
1542115854 {
1542215855 //Composite group = (Composite) object;
1542315856 Object3D group = object;
15424
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15857
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1542515858 }
1542615859
1542715860 void ResetTransform(int mask)
1542815861 {
1542915862 //Composite group = (Composite) object;
1543015863 Object3D group = object;
15431
- group.editWindow.ResetTransform(mask);
15864
+ group.GetWindow().ResetTransform(mask);
1543215865 }
1543315866
1543415867 void FlipTransform()
1543515868 {
1543615869 //Composite group = (Composite) object;
1543715870 Object3D group = object;
15438
- group.editWindow.FlipTransform();
15871
+ group.GetWindow().FlipTransform();
1543915872 // group.editWindow.ReduceMesh(true);
1544015873 }
1544115874
....@@ -15443,7 +15876,7 @@
1544315876 {
1544415877 //Composite group = (Composite) object;
1544515878 Object3D group = object;
15446
- group.editWindow.PrintMemory();
15879
+ group.GetWindow().PrintMemory();
1544715880 // group.editWindow.ReduceMesh(true);
1544815881 }
1544915882
....@@ -15451,7 +15884,7 @@
1545115884 {
1545215885 //Composite group = (Composite) object;
1545315886 Object3D group = object;
15454
- group.editWindow.ResetCentroid();
15887
+ group.GetWindow().ResetCentroid();
1545515888 }
1545615889
1545715890 void IncDepth()
....@@ -15533,8 +15966,6 @@
1553315966
1553415967 int width = getBounds().width;
1553515968 int height = getBounds().height;
15536
- ClickInfo info = new ClickInfo();
15537
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1553815969 //Image img = CreateImage(width, height);
1553915970 //System.out.println("width = " + width + "; height = " + height + "\n");
1554015971
....@@ -15611,48 +16042,77 @@
1561116042 }
1561216043 if (object != null && !hasMarquee)
1561316044 {
16045
+ if (object.clickInfo == null)
16046
+ object.clickInfo = new ClickInfo();
16047
+ ClickInfo info = object.clickInfo;
16048
+ //ClickInfo info = new ClickInfo();
16049
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16050
+
1561416051 if (isRenderer)
1561516052 {
15616
- info.flags++;
16053
+ object.clickInfo.flags++;
1561716054 double frameAspect = (double) width / (double) height;
1561816055 if (frameAspect > renderCamera.aspect)
1561916056 {
1562016057 int desired = (int) ((double) height * renderCamera.aspect);
15621
- info.bounds.width -= width - desired;
15622
- info.bounds.x += (width - desired) / 2;
16058
+ object.clickInfo.bounds.width -= width - desired;
16059
+ object.clickInfo.bounds.x += (width - desired) / 2;
1562316060 } else
1562416061 {
1562516062 int desired = (int) ((double) width / renderCamera.aspect);
15626
- info.bounds.height -= height - desired;
15627
- info.bounds.y += (height - desired) / 2;
16063
+ object.clickInfo.bounds.height -= height - desired;
16064
+ object.clickInfo.bounds.y += (height - desired) / 2;
1562816065 }
1562916066 }
15630
- info.g = gr;
15631
- info.camera = renderCamera;
16067
+
16068
+ object.clickInfo.g = gr;
16069
+ object.clickInfo.camera = renderCamera;
1563216070 /*
1563316071 // Memory intensive (brep.verticescopy)
1563416072 if (!(object instanceof Composite))
1563516073 object.draw(info, 0, false); // SLOW :
1563616074 */
15637
- if (!isRenderer)
16075
+ if (!isRenderer) // && drag)
1563816076 {
15639
- object.drawEditHandles(info, 0);
15640
-
15641
- if (drag && (X != 0 || Y != 0) && object.selection.Size() > 0)
16077
+ Grafreed.Assert(object != null);
16078
+ Grafreed.Assert(object.selection != null);
16079
+ if (object.selection.Size() > 0)
1564216080 {
15643
- switch (object.selection.get(0).hitSomething)
16081
+ int hitSomething = object.selection.get(0).hitSomething;
16082
+
16083
+ object.clickInfo.DX = 0;
16084
+ object.clickInfo.DY = 0;
16085
+ object.clickInfo.W = 1;
16086
+ if (hitSomething == Object3D.hitCenter)
1564416087 {
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;
16088
+ info.DX = X;
16089
+ if (X != 0)
16090
+ info.DX -= info.bounds.width/2;
16091
+
16092
+ info.DY = Y;
16093
+ if (Y != 0)
16094
+ info.DY -= info.bounds.height/2;
1565416095 }
15655
-
16096
+
16097
+ object.drawEditHandles(//info,
16098
+ 0);
16099
+
16100
+ if (drag && (X != 0 || Y != 0))
16101
+ {
16102
+ switch (hitSomething)
16103
+ {
16104
+ case Object3D.hitCenter: gr.setColor(Color.pink);
16105
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16106
+ break;
16107
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16108
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16109
+ break;
16110
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16111
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16112
+ break;
16113
+ }
16114
+
16115
+ }
1565616116 }
1565716117 }
1565816118 }
....@@ -16134,6 +16594,8 @@
1613416594 private /*static*/ boolean firstime;
1613516595 private /*static*/ cVector newView = new cVector();
1613616596 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16597
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16598
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1613716599 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1613816600 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1613916601 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16146,29 +16608,67 @@
1614616608 {
1614716609 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1614816610
16611
+ int usedsuf = 0;
16612
+
1614916613 for (int i = 0; i < suffixes.length; i++)
1615016614 {
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)
16615
+ String[] suffixe = suffixes;
16616
+ String[] fallback = suffixes2;
16617
+ String[] fallfallback = suffixes3;
16618
+
16619
+ for (int c=usedsuf; --c>=0;)
1615616620 {
16157
- throw new IOException("Unable to load texture " + resourceName);
16621
+// String[] temp = suffixe;
16622
+// suffixe = fallback;
16623
+// fallback = fallfallback;
16624
+// fallfallback = temp;
1615816625 }
16626
+
16627
+ String resourceName = basename + suffixe[i] + "." + suffix;
16628
+ TextureData data;
16629
+
16630
+ try
16631
+ {
16632
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16633
+ mipmapped,
16634
+ FileUtil.getFileSuffix(resourceName));
16635
+ }
16636
+ catch (Exception e)
16637
+ {
16638
+ try
16639
+ {
16640
+ resourceName = basename + fallback[i] + "." + suffix;
16641
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16642
+ mipmapped,
16643
+ FileUtil.getFileSuffix(resourceName));
16644
+ }
16645
+ catch (Exception e2)
16646
+ {
16647
+ resourceName = basename + fallfallback[i] + "." + suffix;
16648
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16649
+ mipmapped,
16650
+ FileUtil.getFileSuffix(resourceName));
16651
+ }
16652
+ }
16653
+
1615916654 //System.out.println("Target = " + targets[i]);
1616016655 cubemap.updateImage(data, targets[i]);
1616116656 }
1616216657
1616316658 return cubemap;
1616416659 }
16660
+
1616516661 int bigsphere = -1;
1616616662
1616716663 float BGcolor = 0.5f;
1616816664
16169
- private void DrawSkyBox(GL gl)
16665
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16666
+
16667
+ private void DrawSkyBox(GL gl, float ratio)
1617016668 {
16171
- if (envyoff || cubemap == null)
16669
+ if (//envyoff ||
16670
+ WIREFRAME ||
16671
+ cubemap == null)
1617216672 {
1617316673 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1617416674 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16183,7 +16683,17 @@
1618316683 // Compensates for ExaminerViewer's modification of modelview matrix
1618416684 gl.glMatrixMode(GL.GL_MODELVIEW);
1618516685 gl.glLoadIdentity();
16686
+ gl.glScalef(1,ratio,1);
1618616687
16688
+// colorV[0] = 2;
16689
+// colorV[1] = 2;
16690
+// colorV[2] = 2;
16691
+// colorV[3] = 1;
16692
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16693
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16694
+//
16695
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16696
+
1618716697 //gl.glActiveTexture(GL.GL_TEXTURE1);
1618816698 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1618916699
....@@ -16215,6 +16725,7 @@
1621516725 {
1621616726 gl.glScalef(1.0f, -1.0f, 1.0f);
1621716727 }
16728
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1621816729 gl.glMultMatrixd(viewrot_1, 0);
1621916730 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1622016731 //viewer.updateInverseRotation(gl);
....@@ -16355,16 +16866,16 @@
1635516866 cStatic.objectstack[materialdepth++] = checker;
1635616867 //System.out.println("material " + material);
1635716868 //Applet3D.tracein(this, selected);
16358
- vector2buffer = checker.projectedVertices;
16869
+ //vector2buffer = checker.projectedVertices;
1635916870
1636016871 //checker.GetMaterial().Draw(this, false); // true);
16361
- DrawMaterial(checker.GetMaterial(), false); // true);
16872
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1636216873
1636316874 materialdepth -= 1;
1636416875 if (materialdepth > 0)
1636516876 {
16366
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16367
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
16877
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16878
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1636816879 }
1636916880 //checker.GetMaterial().opacity = 1f;
1637016881 ////checker.GetMaterial().ambient = 1f;
....@@ -16450,6 +16961,14 @@
1645016961 }
1645116962 }
1645216963
16964
+ private Object3D GetFolder()
16965
+ {
16966
+ Object3D folder = object.GetWindow().copy;
16967
+ if (object.GetWindow().copy.selection.Size() > 0)
16968
+ folder = object.GetWindow().copy.selection.elementAt(0);
16969
+ return folder;
16970
+ }
16971
+
1645316972 class SelectBuffer implements GLEventListener
1645416973 {
1645516974
....@@ -16465,7 +16984,7 @@
1646516984 //new Exception().printStackTrace();
1646616985 System.out.println("select buffer init");
1646716986 // Use debug pipeline
16468
- drawable.setGL(new DebugGL(drawable.getGL()));
16987
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1646916988
1647016989 GL gl = drawable.getGL();
1647116990
....@@ -16529,6 +17048,17 @@
1652917048
1653017049 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1653117050
17051
+ if (PAINTMODE)
17052
+ {
17053
+ if (object.GetWindow().copy.selection.Size() > 0)
17054
+ {
17055
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17056
+
17057
+ // Make what you paint not selectable.
17058
+ paintobj.ResetSelectable();
17059
+ }
17060
+ }
17061
+
1653217062 //int tmp = selection_view;
1653317063 //selection_view = -1;
1653417064 int temp = DrawMode();
....@@ -16540,6 +17070,17 @@
1654017070 // temp = DEFAULT; // patch for selection debug
1654117071 Globals.drawMode = temp; // WARNING
1654217072
17073
+ if (PAINTMODE)
17074
+ {
17075
+ if (object.GetWindow().copy.selection.Size() > 0)
17076
+ {
17077
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17078
+
17079
+ // Revert.
17080
+ paintobj.RestoreSelectable();
17081
+ }
17082
+ }
17083
+
1654317084 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1654417085
1654517086 // trying different ways of getting the depth info over
....@@ -16587,6 +17128,8 @@
1658717128 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1658817129 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1658917130 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
17131
+
17132
+ CreateSelectedPoint();
1659017133
1659117134 // Will fit the mesh !!!
1659217135 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16641,29 +17184,31 @@
1664117184 }
1664217185
1664317186 if (!movingcamera && !PAINTMODE)
16644
- object.editWindow.ScreenFitPoint(); // fev 2014
17187
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1664517188
16646
- if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17189
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1664717190 {
16648
- Object3D paintobj = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17191
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1664917192
16650
- Object3D group = new Object3D("inst" + paintcount++);
17193
+ if (object.GetWindow().copy.selection.Size() > 0)
17194
+ {
17195
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1665117196
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();
17197
+ Object3D inst = new Object3D("inst" + paintcount++);
17198
+
17199
+ inst.CreateMaterial(); // use a void leaf to select instances
17200
+
17201
+ inst.add(paintobj); // link
17202
+
17203
+ object.GetWindow().SnapObject(inst);
17204
+
17205
+ Object3D folder = paintFolder; // GetFolder();
17206
+
17207
+ folder.add(inst);
17208
+
17209
+ object.GetWindow().ResetModel();
17210
+ object.GetWindow().refreshContents();
17211
+ }
1666717212 }
1666817213 else
1666917214 paintcount = 0;
....@@ -16702,6 +17247,11 @@
1670217247 //System.out.println("objects[color] = " + objects[color]);
1670317248 //objects[color].Select();
1670417249 indexcount = 0;
17250
+ ObjEditor window = object.GetWindow();
17251
+ if (window != null && deselect)
17252
+ {
17253
+ window.Select(null, deselect, true);
17254
+ }
1670517255 object.Select(color, deselect);
1670617256 }
1670717257
....@@ -17227,23 +17777,15 @@
1722717777 int AAbuffersize = 0;
1722817778
1722917779 //double[] selectedpoint = new double[3];
17230
- static Superellipsoid selectedpoint = new Superellipsoid();
17780
+ static Superellipsoid selectedpoint;
1723117781 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();
17782
+ static Sphere debugpointG;
17783
+ static Sphere debugpointP;
17784
+ static Sphere debugpointC;
17785
+ static Sphere debugpointR;
1723617786
1723717787 static Sphere debugpoints[] = new Sphere[8];
1723817788
17239
- static
17240
- {
17241
- for (int i=0; i<8; i++)
17242
- {
17243
- debugpoints[i] = new Sphere();
17244
- }
17245
- }
17246
-
1724717789 static void InitPoints(float radius)
1724817790 {
1724917791 for (int i=0; i<8; i++)