Normand Briere
2019-08-09 912749d2520afedd9b56458d771400c261fe2b88
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
....@@ -1890,7 +1961,7 @@
18901961 void PushMatrix(double[][] matrix)
18911962 {
18921963 // GrafreeD.tracein(matrix);
1893
- PushMatrix(matrix,1);
1964
+ PushMatrix(matrix, 1);
18941965 }
18951966
18961967 void PushMatrix()
....@@ -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,11 +8036,69 @@
79178036 pigment = null;
79188037 }
79198038
7920
- ReleaseTexture(bump, true);
7921
- ReleaseTexture(pigment, false);
8039
+ ReleaseTexture(tex, true);
8040
+ ReleaseTexture(tex, false);
79228041 }
79238042
7924
- void ReleaseTexture(String tex, boolean bump)
8043
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
8044
+ {
8045
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8046
+ {
8047
+ return;
8048
+ }
8049
+
8050
+ if (tex == null)
8051
+ {
8052
+ ReleaseTexture(null, false);
8053
+ return;
8054
+ }
8055
+
8056
+ String pigment = Object3D.GetPigment(tex);
8057
+
8058
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8059
+ {
8060
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8061
+ // System.out.println("; bump = " + bump);
8062
+ }
8063
+
8064
+ if (pigment.equals(""))
8065
+ {
8066
+ pigment = null;
8067
+ }
8068
+
8069
+ ReleaseTexture(tex, false);
8070
+ }
8071
+
8072
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
8073
+ {
8074
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8075
+ {
8076
+ return;
8077
+ }
8078
+
8079
+ if (tex == null)
8080
+ {
8081
+ ReleaseTexture(null, true);
8082
+ return;
8083
+ }
8084
+
8085
+ String bump = Object3D.GetBump(tex);
8086
+
8087
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8088
+ {
8089
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8090
+ // System.out.println("; bump = " + bump);
8091
+ }
8092
+
8093
+ if (bump.equals(""))
8094
+ {
8095
+ bump = null;
8096
+ }
8097
+
8098
+ ReleaseTexture(tex, true);
8099
+ }
8100
+
8101
+ void ReleaseTexture(cTexture tex, boolean bump)
79258102 {
79268103 if (// DrawMode() != 0 || /*tex == null ||*/
79278104 ambientOcclusion ) // || !textureon)
....@@ -7932,7 +8109,7 @@
79328109 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
79338110
79348111 if (tex != null)
7935
- texture = textures.get(tex);
8112
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
79368113
79378114 // //assert( texture != null );
79388115 // if (texture == null)
....@@ -8026,6 +8203,54 @@
80268203
80278204 /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
80288205 {
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;
8247
+
8248
+ BindPigmentTexture(tex, resolution);
8249
+ BindBumpTexture(tex, resolution);
8250
+ }
8251
+
8252
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8253
+ {
80298254 if (// DrawMode() != 0 || /*tex == null ||*/
80308255 ambientOcclusion ) // || !textureon)
80318256 {
....@@ -8035,17 +8260,47 @@
80358260 if (tex == null)
80368261 {
80378262 BindTexture(null,false,resolution);
8038
- BindTexture(null,true,resolution);
80398263 return;
80408264 }
80418265
80428266 String pigment = Object3D.GetPigment(tex);
8267
+
8268
+ usedtextures.add(tex);
8269
+
8270
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8271
+ {
8272
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8273
+ // System.out.println("; bump = " + bump);
8274
+ }
8275
+
8276
+ if (pigment.equals(""))
8277
+ {
8278
+ pigment = null;
8279
+ }
8280
+
8281
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8282
+ BindTexture(tex, false, resolution);
8283
+ }
8284
+
8285
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8286
+ {
8287
+ if (// DrawMode() != 0 || /*tex == null ||*/
8288
+ ambientOcclusion ) // || !textureon)
8289
+ {
8290
+ return; // false;
8291
+ }
8292
+
8293
+ if (tex == null)
8294
+ {
8295
+ BindTexture(null,true,resolution);
8296
+ return;
8297
+ }
8298
+
80438299 String bump = Object3D.GetBump(tex);
80448300
8045
- usedtextures.put(pigment, pigment);
8046
- usedtextures.put(bump, bump);
8301
+ usedtextures.add(tex);
80478302
8048
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8303
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
80498304 {
80508305 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
80518306 // System.out.println("; bump = " + bump);
....@@ -8055,18 +8310,10 @@
80558310 {
80568311 bump = null;
80578312 }
8058
- if (pigment.equals(""))
8059
- {
8060
- pigment = null;
8061
- }
80628313
8063
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8064
- BindTexture(pigment, false, resolution);
80658314 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8066
- BindTexture(bump, true, resolution);
8315
+ BindTexture(tex, true, resolution);
80678316 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8068
-
8069
- return; // true;
80708317 }
80718318
80728319 java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
....@@ -8089,13 +8336,19 @@
80898336 return fileExists;
80908337 }
80918338
8092
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception
8339
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
80938340 {
8094
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8341
+ CacheTexture texturecache = null;
80958342
80968343 if (tex != null)
80978344 {
8098
- 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
+ }
80998352
81008353 String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
81018354
....@@ -8105,19 +8358,46 @@
81058358 // else
81068359 // if (!texname.startsWith("/"))
81078360 // texname = "/Users/nbriere/Textures/" + texname;
8108
- if (!FileExists(tex))
8361
+ if (!FileExists(texname) && !texname.startsWith("@"))
81098362 {
81108363 texname = fallbackTextureName;
81118364 }
81128365
81138366 if (CACHETEXTURE)
8114
- texture = textures.get(texname); // TEXTURE CACHE
8115
-
8116
- TextureData texturedata = null;
8117
-
8118
- if (texture == null || texture.resolution < resolution)
81198367 {
8120
- 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(""))
81218401 {
81228402 assert(!bump);
81238403 // if (bump)
....@@ -8128,19 +8408,23 @@
81288408 // }
81298409 // else
81308410 // {
8131
- texture = textures.get(tex);
8132
- if (texture == null)
8411
+ // texturecache = textures.get(texname); // suspicious
8412
+ if (texturecache == null)
81338413 {
8134
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8414
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
81358415 }
8416
+ else
8417
+ new Exception().printStackTrace();
81368418 // }
81378419 } else
8138
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8420
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
81398421 {
81408422 assert(bump);
8141
- texture = textures.get(tex);
8142
- if (texture == null)
8143
- 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();
81448428 } else
81458429 {
81468430 //if (tex.equals("IMMORTAL"))
....@@ -8148,11 +8432,22 @@
81488432 // texture = GetResourceTexture("default.png");
81498433 //} else
81508434 //{
8151
- if (tex.equals("WHITE_NOISE"))
8435
+ if (texname.endsWith("WHITE_NOISE"))
81528436 {
8153
- texture = textures.get(tex);
8154
- if (texture == null)
8155
- 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();
81568451 } else
81578452 {
81588453 if (textureon)
....@@ -8211,19 +8506,20 @@
82118506 if (texturedata == null)
82128507 throw new Exception();
82138508
8214
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8509
+ texturecache = new CacheTexture(texturedata,resolution);
82158510 //texture = GetTexture(tex, bump);
82168511 }
8512
+ }
82178513 }
82188514 //}
82198515 }
82208516
8221
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8517
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
82228518 {
82238519 //return false;
82248520
82258521 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8226
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8522
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
82278523 {
82288524 // String ext = "_highres";
82298525 // if (REDUCETEXTURE)
....@@ -8240,52 +8536,17 @@
82408536 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
82418537 if (!cachefile.exists())
82428538 {
8243
- // cache to disk
8244
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
8245
- //buffers[0].
8246
-
8247
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
8248
- int[] pixels = new int[bytebuf.capacity()/3];
8249
-
8250
- // squared size heuristic...
8251
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8539
+ //if (texturedata.getWidth() == texturedata.getHeight())
82528540 {
8253
- for (int i=pixels.length; --i>=0;)
8254
- {
8255
- int i3 = i*3;
8256
- pixels[i] = 0xFF;
8257
- pixels[i] <<= 8;
8258
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
8259
- pixels[i] <<= 8;
8260
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
8261
- pixels[i] <<= 8;
8262
- pixels[i] |= bytebuf.get(i3) & 0xFF;
8263
- }
8264
-
8265
- /*
8266
- int r=0,g=0,b=0,a=0;
8267
- for (int i=0; i<width; i++)
8268
- for (int j=0; j<height; j++)
8269
- {
8270
- int index = j*width+i;
8271
- int p = pixels[index];
8272
- a = ((p>>24) & 0xFF);
8273
- r = ((p>>16) & 0xFF);
8274
- g = ((p>>8) & 0xFF);
8275
- b = (p & 0xFF);
8276
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
8277
- }
8278
- /**/
8279
- int width = (int)Math.sqrt(pixels.length); // squared
8280
- int height = width;
8281
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
8282
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8541
+ BufferedImage rendImage = CreateBim(texturedata);
8542
+
82838543 ImageWriter writer = null;
82848544 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
82858545 if (iter.hasNext()) {
82868546 writer = (ImageWriter)iter.next();
82878547 }
8288
- float compressionQuality = 0.9f;
8548
+
8549
+ float compressionQuality = 0.85f;
82898550 try
82908551 {
82918552 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8302,18 +8563,20 @@
83028563 }
83038564 }
83048565 }
8305
-
8566
+
8567
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8568
+
83068569 //System.out.println("Texture = " + tex);
8307
- if (textures.containsKey(texname))
8570
+ if (textures.containsKey(tex))
83088571 {
8309
- CacheTexture thetex = textures.get(texname);
8572
+ CacheTexture thetex = textures.get(tex);
83108573 thetex.texture.disable();
83118574 thetex.texture.dispose();
8312
- textures.remove(texname);
8575
+ textures.remove(tex);
83138576 }
83148577
8315
- texture.texturedata = texturedata;
8316
- textures.put(texname, texture);
8578
+ //texture.texturedata = texturedata;
8579
+ textures.put(tex, texturecache);
83178580
83188581 // newtex = true;
83198582 }
....@@ -8329,10 +8592,44 @@
83298592 }
83308593 }
83318594
8332
- return texture;
8595
+ return texturecache;
83338596 }
83348597
8335
- 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
83368633 {
83378634 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
83388635
....@@ -8350,21 +8647,21 @@
83508647 return texture!=null?texture.texture:null;
83518648 }
83528649
8353
- 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
83548651 {
83558652 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
83568653
83578654 return texture!=null?texture.texturedata:null;
83588655 }
83598656
8360
- boolean BindTexture(String tex, boolean bump, int resolution) throws Exception
8657
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
83618658 {
83628659 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
83638660 {
83648661 return false;
83658662 }
83668663
8367
- boolean newtex = false;
8664
+ //boolean newtex = false;
83688665
83698666 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
83708667
....@@ -8396,9 +8693,75 @@
83968693 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
83978694 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
83988695
8399
- return newtex;
8696
+ return true; // Warning: not used.
84008697 }
84018698
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
+
84028765 ShadowBuffer shadowPBuf;
84038766 AntialiasBuffer antialiasPBuf;
84048767 int MAXSTACK;
....@@ -8591,7 +8954,7 @@
85918954
85928955 if (cubemap == null)
85938956 {
8594
- LoadEnvy(5);
8957
+ //LoadEnvy(1);
85958958 }
85968959
85978960 //cubemap.enable();
....@@ -8878,37 +9241,58 @@
88789241 cubemap = null;
88799242 return;
88809243 case 1:
8881
- name = "cubemaps/box_";
8882
- ext = "png";
9244
+ name = "cubemaps/rgb/";
9245
+ ext = "jpg";
88839246 reverseUP = false;
88849247 break;
88859248 case 2:
8886
- name = "cubemaps/uffizi_";
8887
- ext = "png";
8888
- break; // reverseUP = true; break;
9249
+ name = "cubemaps/uffizi/";
9250
+ ext = "jpg";
9251
+ reverseUP = false;
9252
+ break;
88899253 case 3:
8890
- name = "cubemaps/CloudyHills_";
8891
- ext = "tga";
9254
+ name = "cubemaps/CloudyHills/";
9255
+ ext = "jpg";
88929256 reverseUP = false;
88939257 break;
88949258 case 4:
8895
- name = "cubemaps/cornell_";
9259
+ name = "cubemaps/cornell/";
88969260 ext = "png";
88979261 reverseUP = false;
88989262 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;
88999288 default:
8900
- name = "cubemaps/rgb_";
8901
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9289
+ name = "cubemaps/box/";
9290
+ ext = "png"; /*mipmap = true;*/
9291
+ reverseUP = false;
89029292 break;
89039293 }
8904
-
8905
- try
8906
- {
8907
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
8908
- } catch (IOException e)
8909
- {
8910
- throw new RuntimeException(e);
8911
- }
9294
+
9295
+ LoadSkybox(name, ext, mipmap);
89129296 }
89139297
89149298 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -8940,8 +9324,12 @@
89409324 static double[] model = new double[16];
89419325 double[] camera2light = new double[16];
89429326 double[] light2camera = new double[16];
8943
- int newenvy = -1;
8944
- boolean envyoff = true; // false;
9327
+
9328
+ //int newenvy = -1;
9329
+ //boolean envyoff = false;
9330
+
9331
+ String loadedskyboxname;
9332
+
89459333 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
89469334 //float[] light0 = { 0,0,0 };
89479335 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9234,11 +9622,35 @@
92349622 jy8[3] = 0.5f;
92359623 }
92369624
9237
- 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
92389626 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
92399627 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
92409628 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
92419629
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
+
92429654 static int imagecount = 0; // movie generation
92439655
92449656 static int jitter = 0;
....@@ -9397,10 +9809,12 @@
93979809 rati = 1 / rati;
93989810 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
93999811 }
9400
- assert (newenvy == -1);
9812
+
9813
+ //assert (newenvy == -1);
9814
+
94019815 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
94029816 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9403
- DrawSkyBox(gl);
9817
+ DrawSkyBox(gl, (float)rati);
94049818 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
94059819 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
94069820 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10349,6 +10763,7 @@
1034910763 ANTIALIAS = 0;
1035010764 //System.out.println("RESTART");
1035110765 AAtimer.restart();
10766
+ Globals.TIMERRUNNING = true;
1035210767 }
1035310768 }
1035410769 }
....@@ -10416,7 +10831,8 @@
1041610831 ambientOcclusion = false;
1041710832 }
1041810833
10419
- if (Globals.lighttouched && DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
10834
+ if (//Globals.lighttouched &&
10835
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1042010836 {
1042110837 //if (RENDERSHADOW) // ?
1042210838 if (!IsFrozen())
....@@ -10435,7 +10851,7 @@
1043510851
1043610852 if (wait)
1043710853 {
10438
- Sleep(500);
10854
+ Sleep(200); // blocks everything
1043910855
1044010856 wait = false;
1044110857 }
....@@ -10651,13 +11067,27 @@
1065111067 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1065211068 }
1065311069
10654
- if (newenvy > -1)
11070
+// if (newenvy > -1)
11071
+// {
11072
+// LoadEnvy(newenvy);
11073
+// }
11074
+//
11075
+// newenvy = -1;
11076
+
11077
+ if (object.skyboxname != null)
1065511078 {
10656
- LoadEnvy(newenvy);
11079
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11080
+ {
11081
+ LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11082
+ loadedskyboxname = object.skyboxname;
11083
+ }
1065711084 }
10658
-
10659
- newenvy = -1;
10660
-
11085
+ else
11086
+ {
11087
+ cubemap = null;
11088
+ loadedskyboxname = null;
11089
+ }
11090
+
1066111091 ratio = ((double) getWidth()) / getHeight();
1066211092 //System.out.println("ratio = " + ratio);
1066311093
....@@ -10673,7 +11103,7 @@
1067311103
1067411104 if (!IsFrozen() && !ambientOcclusion)
1067511105 {
10676
- DrawSkyBox(gl);
11106
+ DrawSkyBox(gl, (float)ratio);
1067711107 }
1067811108
1067911109 //if (selection_view == -1)
....@@ -10856,9 +11286,9 @@
1085611286
1085711287 gl.glMatrixMode(GL.GL_MODELVIEW);
1085811288
10859
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10860
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10861
-//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);
1086211292 } else
1086311293 {
1086411294 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -10869,7 +11299,7 @@
1086911299 //System.out.println("BLENDING ON");
1087011300 gl.glEnable(GL.GL_BLEND);
1087111301 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
10872
-
11302
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1087311303 gl.glMatrixMode(gl.GL_PROJECTION);
1087411304 gl.glLoadIdentity();
1087511305
....@@ -10981,7 +11411,7 @@
1098111411 {
1098211412 if (cam != lightCamera)
1098311413 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10984
- LA.xformDir(light0, parentcam.GlobalTransformInv(), light0); // may 2013
11414
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
1098511415 }
1098611416
1098711417 LA.xformPos(light0, cam.toScreen, light0);
....@@ -11118,7 +11548,7 @@
1111811548 }
1111911549 }
1112011550
11121
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11551
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1112211552 {
1112311553 //gl.glDepthFunc(GL.GL_LEQUAL);
1112411554 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11126,24 +11556,21 @@
1112611556
1112711557 boolean texon = textureon;
1112811558
11129
- if (RENDERPROGRAM > 0)
11130
- {
11131
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11132
- textureon = false;
11133
- }
11559
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11560
+ textureon = false;
11561
+
1113411562 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1113511563 //System.out.println("ALLO");
1113611564 gl.glColorMask(false, false, false, false);
1113711565 DrawObject(gl);
11138
- if (RENDERPROGRAM > 0)
11139
- {
11140
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11141
- textureon = texon;
11142
- }
11566
+
11567
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11568
+ textureon = texon;
11569
+
1114311570 gl.glColorMask(true, true, true, true);
1114411571
1114511572 gl.glDepthFunc(GL.GL_EQUAL);
11146
- //gl.glDepthMask(false);
11573
+ gl.glDepthMask(false);
1114711574 }
1114811575
1114911576 if (false) // DrawMode() == SHADOW)
....@@ -11326,15 +11753,36 @@
1132611753
1132711754 static boolean zoomonce = false;
1132811755
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
+
1132911774 void DrawObject(GL gl, boolean draw)
1133011775 {
11776
+ // To clear camera values
11777
+ ResetOptions();
11778
+
1133111779 //System.out.println("DRAW OBJECT " + mouseDown);
1133211780 // DrawMode() = SELECTION;
1133311781 //GL gl = getGL();
1133411782 if ((TRACK || SHADOWTRACK) || zoomonce)
1133511783 {
1133611784 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11337
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11785
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1133811786 pingthread.StepToTarget(true); // true);
1133911787 // zoomonce = false;
1134011788 }
....@@ -11406,8 +11854,9 @@
1140611854
1140711855 if (DrawMode() == DEFAULT)
1140811856 {
11409
- if (DEBUG)
11857
+ if (Globals.DEBUG)
1141011858 {
11859
+ CreateSelectedPoint();
1141111860 float radius = 0.05f;
1141211861 if (selectedpoint.radius != radius)
1141311862 {
....@@ -11461,20 +11910,32 @@
1146111910 ReleaseTextures(DEFAULT_TEXTURES);
1146211911
1146311912 if (CLEANCACHE)
11464
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11913
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1146511914 {
11466
- String tex = e.nextElement();
11915
+ cTexture tex = e.nextElement();
1146711916
1146811917 // System.out.println("Texture --------- " + tex);
1146911918
11470
- if (tex.equals("WHITE_NOISE"))
11919
+ if (tex.equals("WHITE_NOISE:"))
1147111920 continue;
1147211921
11473
- if (!usedtextures.containsKey(tex))
11922
+ if (!usedtextures.contains(tex))
1147411923 {
11924
+ CacheTexture gettex = texturepigment.get(tex);
1147511925 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11476
- textures.get(tex).texture.dispose();
11477
- 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
+ }
1147811939 }
1147911940 }
1148011941 }
....@@ -11912,7 +12373,7 @@
1191212373 }
1191312374
1191412375 //for (int count = parentcam.GetTransformCount(); --count>=0;)
11915
- LA.xformPos(light, parentcam.GlobalTransformInv(), light); // may 2013
12376
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1191612377
1191712378 LA.xformPos(light, renderCamera.toScreen, light);
1191812379
....@@ -12002,8 +12463,76 @@
1200212463
1200312464 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1200412465
12005
- String program =
12466
+ String programmin =
12467
+ // Min shader
1200612468 "!!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
+
1200712536 //"OPTION ARB_fragment_program_shadow;" +
1200812537 "PARAM light2cam0 = program.env[10];" +
1200912538 "PARAM light2cam1 = program.env[11];" +
....@@ -12118,8 +12647,7 @@
1211812647 "TEMP shininess;" +
1211912648 "\n" +
1212012649 "MOV texSamp, one;" +
12121
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12122
-
12650
+
1212312651 "MOV mapgrid.x, one2048th.x;" +
1212412652 "MOV temp, fragment.texcoord[1];" +
1212512653 /*
....@@ -12140,20 +12668,20 @@
1214012668 "MUL temp, floor, mapgrid.x;" +
1214112669 //"TEX depth0, temp, texture[1], 2D;" +
1214212670 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12143
- TextureFetch("depth0", "temp", "1") +
12671
+ ShadowTextureFetch("depth0", "temp", "1") +
1214412672 "") +
1214512673 "ADD temp.x, temp.x, mapgrid.x;" +
1214612674 //"TEX depth1, temp, texture[1], 2D;" +
1214712675 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12148
- TextureFetch("depth1", "temp", "1") +
12676
+ ShadowTextureFetch("depth1", "temp", "1") +
1214912677 "") +
1215012678 "ADD temp.y, temp.y, mapgrid.x;" +
1215112679 //"TEX depth2, temp, texture[1], 2D;" +
12152
- TextureFetch("depth2", "temp", "1") +
12680
+ ShadowTextureFetch("depth2", "temp", "1") +
1215312681 "SUB temp.x, temp.x, mapgrid.x;" +
1215412682 //"TEX depth3, temp, texture[1], 2D;" +
1215512683 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12156
- TextureFetch("depth3", "temp", "1") +
12684
+ ShadowTextureFetch("depth3", "temp", "1") +
1215712685 "") +
1215812686 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1215912687 //"MOV params, material;" +
....@@ -12524,10 +13052,10 @@
1252413052 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1252513053 "") +
1252613054
12527
- // display shadow only (bump == 0)
13055
+ // display shadow only (fakedepth == 0)
1252813056 "SUB temp.x, half.x, shadow.x;" +
1252913057 "MOV temp.y, -params5.z;" + // params6.x;" +
12530
- "SLT temp.z, temp.y, -one2048th.x;" +
13058
+ "SLT temp.z, temp.y, -c256i.x;" +
1253113059 "SUB temp.y, one.x, temp.z;" +
1253213060 "MUL temp.x, temp.x, temp.y;" +
1253313061 "KIL temp.x;" +
....@@ -12858,6 +13386,13 @@
1285813386 //once = true;
1285913387 }
1286013388
13389
+ String program = programmax;
13390
+
13391
+ if (Globals.MINSHADER)
13392
+ {
13393
+ program = programmin;
13394
+ }
13395
+
1286113396 System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1286213397 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1286313398 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
....@@ -12951,25 +13486,26 @@
1295113486 return out;
1295213487 }
1295313488
12954
- String TextureFetch(String dest, String src, String unit)
13489
+ // Also does frustum culling
13490
+ String ShadowTextureFetch(String dest, String src, String unit)
1295513491 {
1295613492 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1295713493 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1295813494 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13495
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13496
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1295913497 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12960
- "SLT " + src + ".z, " + src + ".x, one.x;" +
12961
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12962
- "SLT " + src + ".z, " + src + ".y, one.x;" +
12963
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13498
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13499
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1296413500 //"SWZ buffer, temp, w,w,w,w;";
12965
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13501
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1296613502 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1296713503 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1296813504 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
12969
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13505
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1297013506
12971
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
12972
- //"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;";
1297313509 }
1297413510
1297513511 String Shadow(String depth, String shadow)
....@@ -13016,7 +13552,7 @@
1301613552 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1301713553 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1301813554
13019
- // No shadow when out of frustrum
13555
+ // No shadow when out of frustum
1302013556 "SGE temp.x, " + depth + ".z, one.z;" +
1302113557 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1302213558 "";
....@@ -13164,7 +13700,8 @@
1316413700 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1316513701 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1316613702 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13167
- Object3D.cVector2[] vector2buffer;
13703
+
13704
+ //Object3D.cVector2[] vector2buffer;
1316813705
1316913706 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1317013707 // OUT : diff, spec
....@@ -13180,9 +13717,10 @@
1318013717 "DP3 " + dest + ".z," + "normals," + "eye;" +
1318113718 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1318213719 //"MOV " + dest + ".w," + "normal.z;" +
13183
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
13184
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13185
- //"MOV " + dest + ".z," + "params2.w;" +
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
1318613724 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1318713725 "RCP " + dest + ".w," + dest + ".w;" +
1318813726 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13687,6 +14225,7 @@
1368714225 else
1368814226 if (evt.getSource() == AAtimer)
1368914227 {
14228
+ Globals.TIMERRUNNING = false;
1369014229 if (mouseDown)
1369114230 {
1369214231 //new Exception().printStackTrace();
....@@ -13746,7 +14285,7 @@
1374614285
1374714286 // fev 2014???
1374814287 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13749
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14288
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1375014289 pingthread.StepToTarget(true); // true);
1375114290 }
1375214291 // if (!LIVE)
....@@ -13761,6 +14300,7 @@
1376114300 return;
1376214301
1376314302 AAtimer.restart(); //
14303
+ Globals.TIMERRUNNING = true;
1376414304
1376514305 // waslive = LIVE;
1376614306 // LIVE = false;
....@@ -13810,14 +14350,15 @@
1381014350 drag = false;
1381114351 //System.out.println("Mouse DOWN");
1381214352 editObj = false;
13813
- ClickInfo info = new ClickInfo();
13814
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
13815
- info.pane = this;
13816
- info.camera = renderCamera;
13817
- info.x = x;
13818
- info.y = y;
13819
- info.modifiers = modifiersex;
13820
- editObj = object.doEditClick(info, 0);
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);
1382114362 if (!editObj)
1382214363 {
1382314364 hasMarquee = true;
....@@ -13833,6 +14374,8 @@
1383314374
1383414375 public void mouseDragged(MouseEvent e)
1383514376 {
14377
+ Globals.MOUSEDRAGGED = true;
14378
+
1383614379 //System.out.println("mouseDragged: " + e);
1383714380 if (isRenderer)
1383814381 movingcamera = true;
....@@ -14097,12 +14640,12 @@
1409714640 void GoDown(int mod)
1409814641 {
1409914642 MODIFIERS |= COMMAND;
14100
- /*
14643
+ /**/
1410114644 if((mod&SHIFT) == SHIFT)
14102
- manipCamera.RotatePosition(0, -speed);
14645
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
1410314646 else
14104
- manipCamera.BackForth(0, -speed*delta, getWidth());
14105
- */
14647
+ manipCamera.RotatePosition(0, -speed);
14648
+ /**/
1410614649 if ((mod & SHIFT) == SHIFT)
1410714650 {
1410814651 mouseMode = mouseMode; // VR??
....@@ -14118,12 +14661,12 @@
1411814661 void GoUp(int mod)
1411914662 {
1412014663 MODIFIERS |= COMMAND;
14121
- /*
14664
+ /**/
1412214665 if((mod&SHIFT) == SHIFT)
14123
- manipCamera.RotatePosition(0, speed);
14666
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
1412414667 else
14125
- manipCamera.BackForth(0, speed*delta, getWidth());
14126
- */
14668
+ manipCamera.RotatePosition(0, speed);
14669
+ /**/
1412714670 if ((mod & SHIFT) == SHIFT)
1412814671 {
1412914672 mouseMode = mouseMode;
....@@ -14139,12 +14682,12 @@
1413914682 void GoLeft(int mod)
1414014683 {
1414114684 MODIFIERS |= COMMAND;
14142
- /*
14685
+ /**/
1414314686 if((mod&SHIFT) == SHIFT)
14144
- manipCamera.RotatePosition(speed, 0);
14145
- else
1414614687 manipCamera.Translate(speed*delta, 0, getWidth());
14147
- */
14688
+ else
14689
+ manipCamera.RotatePosition(speed, 0);
14690
+ /**/
1414814691 if ((mod & SHIFT) == SHIFT)
1414914692 {
1415014693 mouseMode = mouseMode;
....@@ -14160,12 +14703,12 @@
1416014703 void GoRight(int mod)
1416114704 {
1416214705 MODIFIERS |= COMMAND;
14163
- /*
14706
+ /**/
1416414707 if((mod&SHIFT) == SHIFT)
14165
- manipCamera.RotatePosition(-speed, 0);
14166
- else
1416714708 manipCamera.Translate(-speed*delta, 0, getWidth());
14168
- */
14709
+ else
14710
+ manipCamera.RotatePosition(-speed, 0);
14711
+ /**/
1416914712 if ((mod & SHIFT) == SHIFT)
1417014713 {
1417114714 mouseMode = mouseMode;
....@@ -14215,14 +14758,16 @@
1421514758 if (editObj)
1421614759 {
1421714760 drag = true;
14218
- ClickInfo info = new ClickInfo();
14219
- info.bounds.setBounds(0, 0,
14761
+ //ClickInfo info = new ClickInfo();
14762
+ object.clickInfo.bounds.setBounds(0, 0,
1422014763 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14221
- info.pane = this;
14222
- info.camera = renderCamera;
14223
- info.x = x;
14224
- info.y = y;
14225
- object.editWindow.copy.doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
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);
1422614771 } else
1422714772 {
1422814773 if (x < startX)
....@@ -14371,22 +14916,27 @@
1437114916 }
1437214917 }
1437314918
14919
+// ClickInfo clickInfo = new ClickInfo();
14920
+
1437414921 public void mouseMoved(MouseEvent e)
1437514922 {
1437614923 //System.out.println("mouseMoved: " + e);
1437714924 if (isRenderer)
1437814925 return;
1437914926
14380
- ClickInfo ci = new ClickInfo();
14381
- ci.x = e.getX();
14382
- ci.y = e.getY();
14383
- ci.modifiers = e.getModifiersEx();
14384
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14385
- ci.pane = this;
14386
- ci.camera = renderCamera;
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;
1438714934 if (!isRenderer)
1438814935 {
14389
- if (object.editWindow.copy.doEditClick(ci, 0))
14936
+ //ObjEditor editWindow = object.editWindow;
14937
+ //Object3D copy = editWindow.copy;
14938
+ if (object.doEditClick(//clickInfo,
14939
+ 0))
1439014940 {
1439114941 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1439214942 } else
....@@ -14398,8 +14948,11 @@
1439814948
1439914949 public void mouseReleased(MouseEvent e)
1440014950 {
14951
+ Globals.MOUSEDRAGGED = false;
14952
+
1440114953 movingcamera = false;
14402
- X = Y = 0;
14954
+ X = 0; // getBounds().width/2;
14955
+ Y = 0; // getBounds().height/2;
1440314956 //System.out.println("mouseReleased: " + e);
1440414957 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1440514958 }
....@@ -14655,7 +15208,8 @@
1465515208 // break;
1465615209 case 'T':
1465715210 CACHETEXTURE ^= true;
14658
- textures.clear();
15211
+ texturepigment.clear();
15212
+ texturebump.clear();
1465915213 // repaint();
1466015214 break;
1466115215 case 'Y':
....@@ -14740,7 +15294,9 @@
1474015294 case 'E' : COMPACT ^= true;
1474115295 repaint();
1474215296 break;
14743
- case 'W' : DEBUGHSB ^= true;
15297
+ case 'W' : // Wide Window (fullscreen)
15298
+ //DEBUGHSB ^= true;
15299
+ ObjEditor.theFrame.ToggleFullScreen();
1474415300 repaint();
1474515301 break;
1474615302 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14765,8 +15321,8 @@
1476515321 RevertCamera();
1476615322 repaint();
1476715323 break;
14768
- case 'L':
1476915324 case 'l':
15325
+ //case 'L':
1477015326 if (lightMode)
1477115327 {
1477215328 lightMode = false;
....@@ -14830,20 +15386,24 @@
1483015386 OCCLUSION_CULLING ^= true;
1483115387 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1483215388 break;
14833
- case '0': envyoff ^= true; repaint(); break;
15389
+ //case '0': envyoff ^= true; repaint(); break;
1483415390 case '1':
1483515391 case '2':
1483615392 case '3':
1483715393 case '4':
1483815394 case '5':
14839
- newenvy = Character.getNumericValue(key);
14840
- repaint();
14841
- break;
1484215395 case '6':
1484315396 case '7':
1484415397 case '8':
1484515398 case '9':
14846
- 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
+ }
1484715407 repaint();
1484815408 break;
1484915409 case '!':
....@@ -14909,9 +15469,9 @@
1490915469 case '_':
1491015470 kompactbit = 5;
1491115471 break;
14912
- case '+':
14913
- kompactbit = 6;
14914
- break;
15472
+// case '+':
15473
+// kompactbit = 6;
15474
+// break;
1491515475 case ' ':
1491615476 lightMode ^= true;
1491715477 Globals.lighttouched = true;
....@@ -14923,6 +15483,7 @@
1492315483 case ESC:
1492415484 RENDERPROGRAM += 1;
1492515485 RENDERPROGRAM %= 3;
15486
+
1492615487 repaint();
1492715488 break;
1492815489 case 'Z':
....@@ -14962,8 +15523,9 @@
1496215523 case DELETE:
1496315524 ClearSelection();
1496415525 break;
14965
- /*
1496615526 case '+':
15527
+
15528
+ /*
1496715529 //fontsize += 1;
1496815530 bbzoom *= 2;
1496915531 repaint();
....@@ -14980,17 +15542,17 @@
1498015542 case '=':
1498115543 IncDepth();
1498215544 //fontsize += 1;
14983
- object.editWindow.refreshContents(true);
15545
+ object.GetWindow().refreshContents(true);
1498415546 maskbit = 6;
1498515547 break;
1498615548 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1498715549 DecDepth();
1498815550 maskbit = 5;
1498915551 //if(fontsize > 1) fontsize -= 1;
14990
- if (object.editWindow == null)
14991
- new Exception().printStackTrace();
14992
- else
14993
- object.editWindow.refreshContents(true);
15552
+// if (object.editWindow == null)
15553
+// new Exception().printStackTrace();
15554
+// else
15555
+ object.GetWindow().refreshContents(true);
1499415556 break;
1499515557 case '{':
1499615558 manipCamera.shaper_fovy /= 1.1;
....@@ -15214,7 +15776,7 @@
1521415776 }
1521515777 */
1521615778
15217
- object.editWindow.EditSelection();
15779
+ object.GetWindow().EditSelection(false);
1521815780 }
1521915781
1522015782 void SelectParent()
....@@ -15231,10 +15793,10 @@
1523115793 {
1523215794 //selectees.remove(i);
1523315795 System.out.println("select parent of " + elem);
15234
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15796
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1523515797 } else
1523615798 {
15237
- group.editWindow.Select(elem.GetTreePath(), first, true);
15799
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1523815800 }
1523915801
1524015802 first = false;
....@@ -15276,12 +15838,12 @@
1527615838 for (int j = 0; j < group.children.size(); j++)
1527715839 {
1527815840 elem = (Object3D) group.children.elementAt(j);
15279
- object.editWindow.Select(elem.GetTreePath(), first, true);
15841
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1528015842 first = false;
1528115843 }
1528215844 } else
1528315845 {
15284
- object.editWindow.Select(elem.GetTreePath(), first, true);
15846
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1528515847 }
1528615848
1528715849 first = false;
....@@ -15292,21 +15854,21 @@
1529215854 {
1529315855 //Composite group = (Composite) object;
1529415856 Object3D group = object;
15295
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15857
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1529615858 }
1529715859
1529815860 void ResetTransform(int mask)
1529915861 {
1530015862 //Composite group = (Composite) object;
1530115863 Object3D group = object;
15302
- group.editWindow.ResetTransform(mask);
15864
+ group.GetWindow().ResetTransform(mask);
1530315865 }
1530415866
1530515867 void FlipTransform()
1530615868 {
1530715869 //Composite group = (Composite) object;
1530815870 Object3D group = object;
15309
- group.editWindow.FlipTransform();
15871
+ group.GetWindow().FlipTransform();
1531015872 // group.editWindow.ReduceMesh(true);
1531115873 }
1531215874
....@@ -15314,7 +15876,7 @@
1531415876 {
1531515877 //Composite group = (Composite) object;
1531615878 Object3D group = object;
15317
- group.editWindow.PrintMemory();
15879
+ group.GetWindow().PrintMemory();
1531815880 // group.editWindow.ReduceMesh(true);
1531915881 }
1532015882
....@@ -15322,7 +15884,7 @@
1532215884 {
1532315885 //Composite group = (Composite) object;
1532415886 Object3D group = object;
15325
- group.editWindow.ResetCentroid();
15887
+ group.GetWindow().ResetCentroid();
1532615888 }
1532715889
1532815890 void IncDepth()
....@@ -15404,8 +15966,6 @@
1540415966
1540515967 int width = getBounds().width;
1540615968 int height = getBounds().height;
15407
- ClickInfo info = new ClickInfo();
15408
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1540915969 //Image img = CreateImage(width, height);
1541015970 //System.out.println("width = " + width + "; height = " + height + "\n");
1541115971
....@@ -15482,43 +16042,77 @@
1548216042 }
1548316043 if (object != null && !hasMarquee)
1548416044 {
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
+
1548516051 if (isRenderer)
1548616052 {
15487
- info.flags++;
16053
+ object.clickInfo.flags++;
1548816054 double frameAspect = (double) width / (double) height;
1548916055 if (frameAspect > renderCamera.aspect)
1549016056 {
1549116057 int desired = (int) ((double) height * renderCamera.aspect);
15492
- info.bounds.width -= width - desired;
15493
- info.bounds.x += (width - desired) / 2;
16058
+ object.clickInfo.bounds.width -= width - desired;
16059
+ object.clickInfo.bounds.x += (width - desired) / 2;
1549416060 } else
1549516061 {
1549616062 int desired = (int) ((double) width / renderCamera.aspect);
15497
- info.bounds.height -= height - desired;
15498
- info.bounds.y += (height - desired) / 2;
16063
+ object.clickInfo.bounds.height -= height - desired;
16064
+ object.clickInfo.bounds.y += (height - desired) / 2;
1549916065 }
1550016066 }
15501
- info.g = gr;
15502
- info.camera = renderCamera;
16067
+
16068
+ object.clickInfo.g = gr;
16069
+ object.clickInfo.camera = renderCamera;
1550316070 /*
1550416071 // Memory intensive (brep.verticescopy)
1550516072 if (!(object instanceof Composite))
1550616073 object.draw(info, 0, false); // SLOW :
1550716074 */
15508
- if (!isRenderer)
16075
+ if (!isRenderer) // && drag)
1550916076 {
15510
- object.drawEditHandles(info, 0);
15511
-
15512
- 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)
1551316080 {
15514
- 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)
1551516087 {
15516
- case Object3D.hitCenter: gr.setColor(Color.pink); break;
15517
- case Object3D.hitRotate: gr.setColor(Color.green); break;
15518
- case Object3D.hitScale: gr.setColor(Color.cyan); break;
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;
1551916095 }
15520
-
15521
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
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
+ }
1552216116 }
1552316117 }
1552416118 }
....@@ -16000,6 +16594,8 @@
1600016594 private /*static*/ boolean firstime;
1600116595 private /*static*/ cVector newView = new cVector();
1600216596 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"};
1600316599 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1600416600 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1600516601 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16012,29 +16608,66 @@
1601216608 {
1601316609 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1601416610
16611
+ int usedsuf = 0;
16612
+
1601516613 for (int i = 0; i < suffixes.length; i++)
1601616614 {
16017
- String resourceName = basename + suffixes[i] + "." + suffix;
16018
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16019
- mipmapped,
16020
- FileUtil.getFileSuffix(resourceName));
16021
- if (data == null)
16615
+ String[] suffixe = suffixes;
16616
+ String[] fallback = suffixes2;
16617
+ String[] fallfallback = suffixes3;
16618
+
16619
+ for (int c=usedsuf; --c>=0;)
1602216620 {
16023
- throw new IOException("Unable to load texture " + resourceName);
16621
+// String[] temp = suffixe;
16622
+// suffixe = fallback;
16623
+// fallback = fallfallback;
16624
+// fallfallback = temp;
1602416625 }
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
+
1602516654 //System.out.println("Target = " + targets[i]);
1602616655 cubemap.updateImage(data, targets[i]);
1602716656 }
1602816657
1602916658 return cubemap;
1603016659 }
16660
+
1603116661 int bigsphere = -1;
1603216662
1603316663 float BGcolor = 0.5f;
1603416664
16035
- private void DrawSkyBox(GL gl)
16665
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16666
+
16667
+ private void DrawSkyBox(GL gl, float ratio)
1603616668 {
16037
- if (envyoff || cubemap == null)
16669
+ if (//envyoff ||
16670
+ cubemap == null)
1603816671 {
1603916672 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1604016673 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16049,7 +16682,17 @@
1604916682 // Compensates for ExaminerViewer's modification of modelview matrix
1605016683 gl.glMatrixMode(GL.GL_MODELVIEW);
1605116684 gl.glLoadIdentity();
16685
+ gl.glScalef(1,ratio,1);
1605216686
16687
+// colorV[0] = 2;
16688
+// colorV[1] = 2;
16689
+// colorV[2] = 2;
16690
+// colorV[3] = 1;
16691
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16692
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16693
+//
16694
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16695
+
1605316696 //gl.glActiveTexture(GL.GL_TEXTURE1);
1605416697 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1605516698
....@@ -16081,6 +16724,7 @@
1608116724 {
1608216725 gl.glScalef(1.0f, -1.0f, 1.0f);
1608316726 }
16727
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1608416728 gl.glMultMatrixd(viewrot_1, 0);
1608516729 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1608616730 //viewer.updateInverseRotation(gl);
....@@ -16221,16 +16865,16 @@
1622116865 cStatic.objectstack[materialdepth++] = checker;
1622216866 //System.out.println("material " + material);
1622316867 //Applet3D.tracein(this, selected);
16224
- vector2buffer = checker.projectedVertices;
16868
+ //vector2buffer = checker.projectedVertices;
1622516869
1622616870 //checker.GetMaterial().Draw(this, false); // true);
16227
- DrawMaterial(checker.GetMaterial(), false); // true);
16871
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1622816872
1622916873 materialdepth -= 1;
1623016874 if (materialdepth > 0)
1623116875 {
16232
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16233
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
16876
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16877
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1623416878 }
1623516879 //checker.GetMaterial().opacity = 1f;
1623616880 ////checker.GetMaterial().ambient = 1f;
....@@ -16316,6 +16960,14 @@
1631616960 }
1631716961 }
1631816962
16963
+ private Object3D GetFolder()
16964
+ {
16965
+ Object3D folder = object.GetWindow().copy;
16966
+ if (object.GetWindow().copy.selection.Size() > 0)
16967
+ folder = object.GetWindow().copy.selection.elementAt(0);
16968
+ return folder;
16969
+ }
16970
+
1631916971 class SelectBuffer implements GLEventListener
1632016972 {
1632116973
....@@ -16331,7 +16983,7 @@
1633116983 //new Exception().printStackTrace();
1633216984 System.out.println("select buffer init");
1633316985 // Use debug pipeline
16334
- drawable.setGL(new DebugGL(drawable.getGL()));
16986
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1633516987
1633616988 GL gl = drawable.getGL();
1633716989
....@@ -16395,6 +17047,17 @@
1639517047
1639617048 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1639717049
17050
+ if (PAINTMODE)
17051
+ {
17052
+ if (object.GetWindow().copy.selection.Size() > 0)
17053
+ {
17054
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17055
+
17056
+ // Make what you paint not selectable.
17057
+ paintobj.ResetSelectable();
17058
+ }
17059
+ }
17060
+
1639817061 //int tmp = selection_view;
1639917062 //selection_view = -1;
1640017063 int temp = DrawMode();
....@@ -16406,6 +17069,17 @@
1640617069 // temp = DEFAULT; // patch for selection debug
1640717070 Globals.drawMode = temp; // WARNING
1640817071
17072
+ if (PAINTMODE)
17073
+ {
17074
+ if (object.GetWindow().copy.selection.Size() > 0)
17075
+ {
17076
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17077
+
17078
+ // Revert.
17079
+ paintobj.RestoreSelectable();
17080
+ }
17081
+ }
17082
+
1640917083 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1641017084
1641117085 // trying different ways of getting the depth info over
....@@ -16453,6 +17127,8 @@
1645317127 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1645417128 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1645517129 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
17130
+
17131
+ CreateSelectedPoint();
1645617132
1645717133 // Will fit the mesh !!!
1645817134 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16507,29 +17183,31 @@
1650717183 }
1650817184
1650917185 if (!movingcamera && !PAINTMODE)
16510
- object.editWindow.ScreenFitPoint(); // fev 2014
17186
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1651117187
16512
- if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17188
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1651317189 {
16514
- Object3D paintobj = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17190
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1651517191
16516
- Object3D group = new Object3D("inst" + paintcount++);
17192
+ if (object.GetWindow().copy.selection.Size() > 0)
17193
+ {
17194
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1651717195
16518
- group.CreateMaterial(); // use a void leaf to select instances
16519
-
16520
- group.add(paintobj); // link
16521
-
16522
- object.editWindow.SnapObject(group);
16523
-
16524
- Object3D folder = object.editWindow.copy;
16525
-
16526
- if (object.editWindow.copy.selection.Size() > 0)
16527
- folder = object.editWindow.copy.selection.elementAt(0);
16528
-
16529
- folder.add(group);
16530
-
16531
- object.editWindow.ResetModel();
16532
- object.editWindow.refreshContents();
17196
+ Object3D inst = new Object3D("inst" + paintcount++);
17197
+
17198
+ inst.CreateMaterial(); // use a void leaf to select instances
17199
+
17200
+ inst.add(paintobj); // link
17201
+
17202
+ object.GetWindow().SnapObject(inst);
17203
+
17204
+ Object3D folder = paintFolder; // GetFolder();
17205
+
17206
+ folder.add(inst);
17207
+
17208
+ object.GetWindow().ResetModel();
17209
+ object.GetWindow().refreshContents();
17210
+ }
1653317211 }
1653417212 else
1653517213 paintcount = 0;
....@@ -16568,6 +17246,11 @@
1656817246 //System.out.println("objects[color] = " + objects[color]);
1656917247 //objects[color].Select();
1657017248 indexcount = 0;
17249
+ ObjEditor window = object.GetWindow();
17250
+ if (window != null && deselect)
17251
+ {
17252
+ window.Select(null, deselect, true);
17253
+ }
1657117254 object.Select(color, deselect);
1657217255 }
1657317256
....@@ -17093,23 +17776,15 @@
1709317776 int AAbuffersize = 0;
1709417777
1709517778 //double[] selectedpoint = new double[3];
17096
- static Superellipsoid selectedpoint = new Superellipsoid();
17779
+ static Superellipsoid selectedpoint;
1709717780 static Sphere previousselectedpoint = null;
17098
- static Sphere debugpointG = new Sphere();
17099
- static Sphere debugpointP = new Sphere();
17100
- static Sphere debugpointC = new Sphere();
17101
- static Sphere debugpointR = new Sphere();
17781
+ static Sphere debugpointG;
17782
+ static Sphere debugpointP;
17783
+ static Sphere debugpointC;
17784
+ static Sphere debugpointR;
1710217785
1710317786 static Sphere debugpoints[] = new Sphere[8];
1710417787
17105
- static
17106
- {
17107
- for (int i=0; i<8; i++)
17108
- {
17109
- debugpoints[i] = new Sphere();
17110
- }
17111
- }
17112
-
1711317788 static void InitPoints(float radius)
1711417789 {
1711517790 for (int i=0; i<8; i++)