Normand Briere
2019-08-01 29d5516687020263d3ae0454ce81879a3a450af0
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;
....@@ -150,6 +186,20 @@
150186 defaultcaps.setAccumAlphaBits(16);
151187 }
152188
189
+ 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
+ }
202
+
153203 void SetAsGLRenderer(boolean b)
154204 {
155205 isRenderer = b;
....@@ -168,7 +218,8 @@
168218
169219 SetCamera(cam);
170220
171
- SetLight(new Camera(new cVector(10, 10, -20)));
221
+ // Warning: not used.
222
+ SetLight(new Camera(new cVector(15, 10, -20)));
172223
173224 object = o;
174225
....@@ -325,7 +376,7 @@
325376 cStatic.objectstack[materialdepth++] = obj;
326377 //System.out.println("material " + material);
327378 //Applet3D.tracein(this, selected);
328
- display.vector2buffer = obj.projectedVertices;
379
+ //display.vector2buffer = obj.projectedVertices;
329380 if (obj instanceof Camera)
330381 {
331382 display.options1[0] = material.shift;
....@@ -334,14 +385,28 @@
334385 display.options1[2] = material.shadowbias;
335386 display.options1[3] = material.aniso;
336387 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]);
337393 display.options2[0] = material.opacity;
338394 display.options2[1] = material.diffuse;
339395 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]);
340399
341400 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]);
342404 display.options4[0] = material.cameralight/0.2f;
343405 display.options4[1] = material.subsurface;
344406 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]);
345410
346411 // if (display.CURRENTANTIALIAS > 0)
347412 // display.options3[3] /= 4;
....@@ -357,7 +422,7 @@
357422 /**/
358423 } else
359424 {
360
- DrawMaterial(material, selected);
425
+ DrawMaterial(material, selected, obj.projectedVertices);
361426 }
362427 } else
363428 {
....@@ -381,8 +446,8 @@
381446 cStatic.objectstack[materialdepth++] = obj;
382447 //System.out.println("material " + material);
383448 //Applet3D.tracein("selected ", selected);
384
- display.vector2buffer = obj.projectedVertices;
385
- display.DrawMaterial(material, selected);
449
+ //display.vector2buffer = obj.projectedVertices;
450
+ display.DrawMaterial(material, selected, obj.projectedVertices);
386451 }
387452 }
388453
....@@ -399,8 +464,8 @@
399464 materialdepth -= 1;
400465 if (materialdepth > 0)
401466 {
402
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
403
- 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);
404469 }
405470 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
406471 } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
....@@ -420,8 +485,8 @@
420485 materialdepth -= 1;
421486 if (materialdepth > 0)
422487 {
423
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
424
- 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);
425490 }
426491 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
427492 //else
....@@ -462,10 +527,12 @@
462527 if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
463528 {
464529 //gl.glBegin(gl.GL_TRIANGLES);
465
- 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
+ ;
466533 if (!hasnorm)
467534 {
468
- // System.out.println("FUCK!!");
535
+ // System.out.println("Mesh normal");
469536 LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
470537 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
471538 LA.vecCross(obj.v0, obj.v1, obj.v2);
....@@ -1190,10 +1257,12 @@
11901257 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
11911258 }
11921259 }
1260
+
11931261 if (flipV)
11941262 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
11951263 else
11961264 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1265
+
11971266 //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
11981267 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
11991268
....@@ -1213,10 +1282,12 @@
12131282 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
12141283 }
12151284 }
1285
+
12161286 if (flipV)
12171287 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12181288 else
12191289 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1290
+
12201291 //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
12211292 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
12221293
....@@ -1244,8 +1315,10 @@
12441315 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12451316 else
12461317 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1318
+
12471319 //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
12481320 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1321
+
12491322 count2 += 2;
12501323 count3 += 3;
12511324 }
....@@ -1424,6 +1497,8 @@
14241497 gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
14251498 }
14261499
1500
+ float[] colorV = new float[4];
1501
+
14271502 void SetColor(Object3D obj, Vertex p0)
14281503 {
14291504 CameraPane display = this;
....@@ -1491,8 +1566,6 @@
14911566 {
14921567 return;
14931568 }
1494
-
1495
- float[] colorV = new float[3];
14961569
14971570 if (false) // marked)
14981571 {
....@@ -1601,7 +1674,7 @@
16011674 // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
16021675 }
16031676
1604
- void DrawMaterial(cMaterial material, boolean selected)
1677
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
16051678 {
16061679 CameraPane display = this;
16071680 //new Exception().printStackTrace();
....@@ -1636,7 +1709,7 @@
16361709 colorV[0] = display.modelParams0[0] * material.diffuse;
16371710 colorV[1] = display.modelParams0[1] * material.diffuse;
16381711 colorV[2] = display.modelParams0[2] * material.diffuse;
1639
- colorV[3] = material.opacity;
1712
+ colorV[3] = 1; // material.opacity;
16401713
16411714 gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
16421715 //System.out.println("Opacity = " + opacity);
....@@ -1744,9 +1817,9 @@
17441817 display.modelParams7[2] = 0;
17451818 display.modelParams7[3] = 0;
17461819
1747
- display.modelParams6[0] = 100; // criss de bug de bump
1820
+ //display.modelParams6[0] = 100; // criss de bug de bump
17481821
1749
- Object3D.cVector2[] extparams = display.vector2buffer;
1822
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
17501823 if (extparams != null && extparams.length > 0 && extparams[0] != null)
17511824 {
17521825 display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
....@@ -1888,7 +1961,7 @@
18881961 void PushMatrix(double[][] matrix)
18891962 {
18901963 // GrafreeD.tracein(matrix);
1891
- PushMatrix(matrix,1);
1964
+ PushMatrix(matrix, 1);
18921965 }
18931966
18941967 void PushMatrix()
....@@ -2042,7 +2115,7 @@
20422115 //System.err.println("Oeil on");
20432116 OEIL = true;
20442117 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2045
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2118
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
20462119 //pingthread.StepToTarget(true);
20472120 }
20482121
....@@ -2257,7 +2330,7 @@
22572330
22582331 void ToggleDebug()
22592332 {
2260
- DEBUG ^= true;
2333
+ Globals.DEBUG ^= true;
22612334 }
22622335
22632336 void ToggleLookAt()
....@@ -2265,7 +2338,7 @@
22652338 LOOKAT ^= true;
22662339 }
22672340
2268
- void ToggleRandom()
2341
+ void ToggleSwitch()
22692342 {
22702343 SWITCH ^= true;
22712344 }
....@@ -2275,10 +2348,17 @@
22752348 HANDLES ^= true;
22762349 }
22772350
2351
+ Object3D paintFolder;
2352
+
22782353 void TogglePaint()
22792354 {
22802355 PAINTMODE ^= true;
22812356 paintcount = 0;
2357
+
2358
+ if (PAINTMODE)
2359
+ {
2360
+ paintFolder = GetFolder();
2361
+ }
22822362 }
22832363
22842364 void SwapCamera(int a, int b)
....@@ -2374,7 +2454,22 @@
23742454 {
23752455 return currentGL;
23762456 }
2377
-
2457
+
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
+
23782473 /**/
23792474 class CacheTexture
23802475 {
....@@ -2383,28 +2478,31 @@
23832478
23842479 int resolution;
23852480
2386
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2481
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
23872482 {
2388
- texture = tex;
2483
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2484
+ texturedata = texdata;
23892485 resolution = res;
23902486 }
23912487 }
23922488 /**/
23932489
23942490 // TEXTURE static Texture texture;
2395
- static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures
2396
- = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>();
2397
- 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
+
23982496 int pigmentdepth = 0;
23992497 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
24002498 int bumpdepth = 0;
24012499 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
24022500 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
24032501 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2404
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2502
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
24052503 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
24062504
2407
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2505
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
24082506 {
24092507 TextureData texturedata = null;
24102508
....@@ -2423,13 +2521,34 @@
24232521 if (bump)
24242522 texturedata = ConvertBump(texturedata, false);
24252523
2426
- com.sun.opengl.util.texture.Texture texture =
2427
- 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);
24282526
2429
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2430
- 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);
24312529
2432
- 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;
24332552 }
24342553
24352554 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3502,6 +3621,8 @@
35023621
35033622 System.out.println("LOADING TEXTURE : " + name);
35043623
3624
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3625
+
35053626 //
35063627 if (false) // compressbit > 0)
35073628 {
....@@ -7900,7 +8021,7 @@
79008021 String pigment = Object3D.GetPigment(tex);
79018022 String bump = Object3D.GetBump(tex);
79028023
7903
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8024
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79048025 {
79058026 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79068027 // System.out.println("; bump = " + bump);
....@@ -7915,11 +8036,69 @@
79158036 pigment = null;
79168037 }
79178038
7918
- ReleaseTexture(bump, true);
7919
- ReleaseTexture(pigment, false);
8039
+ ReleaseTexture(tex, true);
8040
+ ReleaseTexture(tex, false);
79208041 }
79218042
7922
- 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)
79238102 {
79248103 if (// DrawMode() != 0 || /*tex == null ||*/
79258104 ambientOcclusion ) // || !textureon)
....@@ -7930,7 +8109,7 @@
79308109 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
79318110
79328111 if (tex != null)
7933
- texture = textures.get(tex);
8112
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
79348113
79358114 // //assert( texture != null );
79368115 // if (texture == null)
....@@ -8024,6 +8203,54 @@
80248203
80258204 /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
80268205 {
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
+ {
80278254 if (// DrawMode() != 0 || /*tex == null ||*/
80288255 ambientOcclusion ) // || !textureon)
80298256 {
....@@ -8033,17 +8260,47 @@
80338260 if (tex == null)
80348261 {
80358262 BindTexture(null,false,resolution);
8036
- BindTexture(null,true,resolution);
80378263 return;
80388264 }
80398265
80408266 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
+
80418299 String bump = Object3D.GetBump(tex);
80428300
8043
- usedtextures.put(pigment, pigment);
8044
- usedtextures.put(bump, bump);
8301
+ usedtextures.add(tex);
80458302
8046
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8303
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
80478304 {
80488305 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
80498306 // System.out.println("; bump = " + bump);
....@@ -8053,47 +8310,94 @@
80538310 {
80548311 bump = null;
80558312 }
8056
- if (pigment.equals(""))
8057
- {
8058
- pigment = null;
8059
- }
80608313
8061
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8062
- BindTexture(pigment, false, resolution);
80638314 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8064
- BindTexture(bump, true, resolution);
8315
+ BindTexture(tex, true, resolution);
80658316 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8066
-
8067
- return; // true;
80688317 }
80698318
8070
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception
8319
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8320
+
8321
+ private boolean FileExists(String tex)
80718322 {
8072
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8323
+ if (missingTextures.contains(tex))
8324
+ {
8325
+ return false;
8326
+ }
8327
+
8328
+ boolean fileExists = new File(tex).exists();
8329
+
8330
+ if (!fileExists)
8331
+ {
8332
+ // If file exists, the "new File()" is not executed sgain
8333
+ missingTextures.add(tex);
8334
+ }
8335
+
8336
+ return fileExists;
8337
+ }
8338
+
8339
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
8340
+ {
8341
+ CacheTexture texturecache = null;
80738342
80748343 if (tex != null)
80758344 {
8076
- String texname = tex;
8345
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8346
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
80778347
8348
+ if (texname.equals("") && texdata == null)
8349
+ {
8350
+ return null;
8351
+ }
8352
+
8353
+ String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
8354
+
80788355 // String[] split = tex.split("Textures");
80798356 // if (split.length > 1)
80808357 // texname = "/Users/nbriere/Textures" + split[split.length-1];
80818358 // else
80828359 // if (!texname.startsWith("/"))
80838360 // texname = "/Users/nbriere/Textures/" + texname;
8084
- if (!new File(tex).exists())
8361
+ if (!FileExists(texname))
80858362 {
8086
- texname = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory() + "/Textures/" + texname;
8363
+ texname = fallbackTextureName;
80878364 }
80888365
80898366 if (CACHETEXTURE)
8090
- texture = textures.get(texname); // TEXTURE CACHE
8091
-
8092
- TextureData texturedata = null;
8093
-
8094
- if (texture == null || texture.resolution < resolution)
80958367 {
8096
- 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(""))
80978401 {
80988402 assert(!bump);
80998403 // if (bump)
....@@ -8104,19 +8408,23 @@
81048408 // }
81058409 // else
81068410 // {
8107
- texture = textures.get(tex);
8108
- if (texture == null)
8411
+ // texturecache = textures.get(texname); // suspicious
8412
+ if (texturecache == null)
81098413 {
8110
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8414
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
81118415 }
8416
+ else
8417
+ new Exception().printStackTrace();
81128418 // }
81138419 } else
8114
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8420
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
81158421 {
81168422 assert(bump);
8117
- texture = textures.get(tex);
8118
- if (texture == null)
8119
- 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();
81208428 } else
81218429 {
81228430 //if (tex.equals("IMMORTAL"))
....@@ -8124,11 +8432,13 @@
81248432 // texture = GetResourceTexture("default.png");
81258433 //} else
81268434 //{
8127
- if (tex.equals("WHITE_NOISE"))
8435
+ if (texname.endsWith("WHITE_NOISE"))
81288436 {
8129
- texture = textures.get(tex);
8130
- if (texture == null)
8131
- 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();
81328442 } else
81338443 {
81348444 if (textureon)
....@@ -8153,7 +8463,7 @@
81538463 }
81548464
81558465 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
8156
- if (!new File(cachename).exists())
8466
+ if (!FileExists(cachename))
81578467 cachename = texname;
81588468 else
81598469 processbump = false; // don't process bump map again
....@@ -8175,7 +8485,7 @@
81758485 }
81768486
81778487 cachename = texname.substring(0, texname.length()-4)+ext+".png";
8178
- if (!new File(cachename).exists())
8488
+ if (!FileExists(cachename))
81798489 cachename = texname;
81808490 else
81818491 processbump = false; // don't process bump map again
....@@ -8187,19 +8497,19 @@
81878497 if (texturedata == null)
81888498 throw new Exception();
81898499
8190
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8500
+ texturecache = new CacheTexture(texturedata,resolution);
81918501 //texture = GetTexture(tex, bump);
81928502 }
81938503 }
81948504 //}
81958505 }
81968506
8197
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8507
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
81988508 {
81998509 //return false;
82008510
82018511 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8202
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8512
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
82038513 {
82048514 // String ext = "_highres";
82058515 // if (REDUCETEXTURE)
....@@ -8216,52 +8526,17 @@
82168526 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
82178527 if (!cachefile.exists())
82188528 {
8219
- // cache to disk
8220
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
8221
- //buffers[0].
8222
-
8223
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
8224
- int[] pixels = new int[bytebuf.capacity()/3];
8225
-
8226
- // squared size heuristic...
8227
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8529
+ //if (texturedata.getWidth() == texturedata.getHeight())
82288530 {
8229
- for (int i=pixels.length; --i>=0;)
8230
- {
8231
- int i3 = i*3;
8232
- pixels[i] = 0xFF;
8233
- pixels[i] <<= 8;
8234
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
8235
- pixels[i] <<= 8;
8236
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
8237
- pixels[i] <<= 8;
8238
- pixels[i] |= bytebuf.get(i3) & 0xFF;
8239
- }
8240
-
8241
- /*
8242
- int r=0,g=0,b=0,a=0;
8243
- for (int i=0; i<width; i++)
8244
- for (int j=0; j<height; j++)
8245
- {
8246
- int index = j*width+i;
8247
- int p = pixels[index];
8248
- a = ((p>>24) & 0xFF);
8249
- r = ((p>>16) & 0xFF);
8250
- g = ((p>>8) & 0xFF);
8251
- b = (p & 0xFF);
8252
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
8253
- }
8254
- /**/
8255
- int width = (int)Math.sqrt(pixels.length); // squared
8256
- int height = width;
8257
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
8258
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8531
+ BufferedImage rendImage = CreateBim(texturedata);
8532
+
82598533 ImageWriter writer = null;
82608534 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
82618535 if (iter.hasNext()) {
82628536 writer = (ImageWriter)iter.next();
82638537 }
8264
- float compressionQuality = 0.9f;
8538
+
8539
+ float compressionQuality = 0.85f;
82658540 try
82668541 {
82678542 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8278,18 +8553,20 @@
82788553 }
82798554 }
82808555 }
8281
-
8556
+
8557
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8558
+
82828559 //System.out.println("Texture = " + tex);
8283
- if (textures.containsKey(texname))
8560
+ if (textures.containsKey(tex))
82848561 {
8285
- CacheTexture thetex = textures.get(texname);
8562
+ CacheTexture thetex = textures.get(tex);
82868563 thetex.texture.disable();
82878564 thetex.texture.dispose();
8288
- textures.remove(texname);
8565
+ textures.remove(tex);
82898566 }
82908567
8291
- texture.texturedata = texturedata;
8292
- textures.put(texname, texture);
8568
+ //texture.texturedata = texturedata;
8569
+ textures.put(tex, texturecache);
82938570
82948571 // newtex = true;
82958572 }
....@@ -8305,10 +8582,44 @@
83058582 }
83068583 }
83078584
8308
- return texture;
8585
+ return texturecache;
83098586 }
83108587
8311
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution) throws Exception
8588
+ static void EmbedTextures(cTexture tex)
8589
+ {
8590
+ if (tex.pigmentdata == null)
8591
+ {
8592
+ //String texname = Object3D.GetPigment(tex);
8593
+
8594
+ CacheTexture texturecache = texturepigment.get(tex);
8595
+
8596
+ if (texturecache != null)
8597
+ {
8598
+ tex.pw = texturecache.texturedata.getWidth();
8599
+ tex.ph = texturecache.texturedata.getHeight();
8600
+ tex.pigmentdata = //CompressJPEG(CreateBim
8601
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8602
+ ;
8603
+ //, tex.pw, tex.ph), 0.5f);
8604
+ }
8605
+ }
8606
+
8607
+ if (tex.bumpdata == null)
8608
+ {
8609
+ //String texname = Object3D.GetBump(tex);
8610
+
8611
+ CacheTexture texturecache = texturebump.get(tex);
8612
+
8613
+ if (texturecache != null)
8614
+ {
8615
+ tex.bw = texturecache.texturedata.getWidth();
8616
+ tex.bh = texturecache.texturedata.getHeight();
8617
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8618
+ }
8619
+ }
8620
+ }
8621
+
8622
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
83128623 {
83138624 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
83148625
....@@ -8326,21 +8637,21 @@
83268637 return texture!=null?texture.texture:null;
83278638 }
83288639
8329
- public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution) throws Exception
8640
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
83308641 {
83318642 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
83328643
83338644 return texture!=null?texture.texturedata:null;
83348645 }
83358646
8336
- boolean BindTexture(String tex, boolean bump, int resolution) throws Exception
8647
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
83378648 {
83388649 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
83398650 {
83408651 return false;
83418652 }
83428653
8343
- boolean newtex = false;
8654
+ //boolean newtex = false;
83448655
83458656 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
83468657
....@@ -8372,9 +8683,75 @@
83728683 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
83738684 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
83748685
8375
- return newtex;
8686
+ return true; // Warning: not used.
83768687 }
83778688
8689
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8690
+ {
8691
+ try
8692
+ {
8693
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8694
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8695
+ ImageWriter writer = writers.next();
8696
+
8697
+ ImageWriteParam param = writer.getDefaultWriteParam();
8698
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8699
+ param.setCompressionQuality(quality);
8700
+
8701
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8702
+ writer.setOutput(ios);
8703
+ writer.write(null, new IIOImage(image, null, null), param);
8704
+
8705
+ byte[] data = baos.toByteArray();
8706
+ writer.dispose();
8707
+ return data;
8708
+ }
8709
+ catch (Exception e)
8710
+ {
8711
+ e.printStackTrace();
8712
+ return null;
8713
+ }
8714
+ }
8715
+
8716
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8717
+ {
8718
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8719
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8720
+ ImageReader reader = writers.next();
8721
+
8722
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8723
+
8724
+ ImageReadParam param = reader.getDefaultReadParam();
8725
+ param.setDestination(bim);
8726
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8727
+
8728
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8729
+ reader.setInput(ios);
8730
+ BufferedImage bim2 = reader.read(0, param);
8731
+ reader.dispose();
8732
+
8733
+// WritableRaster raster = bim2.getRaster();
8734
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8735
+// byte[] bytes = data.getData();
8736
+//
8737
+// int[] pixels = new int[bytes.length/3];
8738
+// for (int i=pixels.length; --i>=0;)
8739
+// {
8740
+// int i3 = i*3;
8741
+// pixels[i] = 0xFF;
8742
+// pixels[i] <<= 8;
8743
+// pixels[i] |= bytes[i3+2] & 0xFF;
8744
+// pixels[i] <<= 8;
8745
+// pixels[i] |= bytes[i3+1] & 0xFF;
8746
+// pixels[i] <<= 8;
8747
+// pixels[i] |= bytes[i3] & 0xFF;
8748
+// }
8749
+//
8750
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8751
+
8752
+ return bim;
8753
+ }
8754
+
83788755 ShadowBuffer shadowPBuf;
83798756 AntialiasBuffer antialiasPBuf;
83808757 int MAXSTACK;
....@@ -8567,7 +8944,7 @@
85678944
85688945 if (cubemap == null)
85698946 {
8570
- LoadEnvy(5);
8947
+ //LoadEnvy(1);
85718948 }
85728949
85738950 //cubemap.enable();
....@@ -8854,37 +9231,58 @@
88549231 cubemap = null;
88559232 return;
88569233 case 1:
8857
- name = "cubemaps/box_";
8858
- ext = "png";
9234
+ name = "cubemaps/rgb/";
9235
+ ext = "jpg";
88599236 reverseUP = false;
88609237 break;
88619238 case 2:
8862
- name = "cubemaps/uffizi_";
8863
- ext = "png";
8864
- break; // reverseUP = true; break;
9239
+ name = "cubemaps/uffizi/";
9240
+ ext = "jpg";
9241
+ reverseUP = false;
9242
+ break;
88659243 case 3:
8866
- name = "cubemaps/CloudyHills_";
8867
- ext = "tga";
9244
+ name = "cubemaps/CloudyHills/";
9245
+ ext = "jpg";
88689246 reverseUP = false;
88699247 break;
88709248 case 4:
8871
- name = "cubemaps/cornell_";
9249
+ name = "cubemaps/cornell/";
88729250 ext = "png";
88739251 reverseUP = false;
88749252 break;
9253
+ case 5:
9254
+ name = "cubemaps/skycube/";
9255
+ ext = "jpg";
9256
+ reverseUP = false;
9257
+ break;
9258
+ case 6:
9259
+ name = "cubemaps/SaintLazarusChurch3/";
9260
+ ext = "jpg";
9261
+ reverseUP = false;
9262
+ break;
9263
+ case 7:
9264
+ name = "cubemaps/Sodermalmsallen/";
9265
+ ext = "jpg";
9266
+ reverseUP = false;
9267
+ break;
9268
+ case 8:
9269
+ name = "cubemaps/Sodermalmsallen2/";
9270
+ ext = "jpg";
9271
+ reverseUP = false;
9272
+ break;
9273
+ case 9:
9274
+ name = "cubemaps/UnionSquare/";
9275
+ ext = "jpg";
9276
+ reverseUP = false;
9277
+ break;
88759278 default:
8876
- name = "cubemaps/rgb_";
8877
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9279
+ name = "cubemaps/box/";
9280
+ ext = "png"; /*mipmap = true;*/
9281
+ reverseUP = false;
88789282 break;
88799283 }
8880
-
8881
- try
8882
- {
8883
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
8884
- } catch (IOException e)
8885
- {
8886
- throw new RuntimeException(e);
8887
- }
9284
+
9285
+ LoadSkybox(name, ext, mipmap);
88889286 }
88899287
88909288 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -8916,8 +9314,12 @@
89169314 static double[] model = new double[16];
89179315 double[] camera2light = new double[16];
89189316 double[] light2camera = new double[16];
8919
- int newenvy = -1;
8920
- boolean envyoff = true; // false;
9317
+
9318
+ //int newenvy = -1;
9319
+ //boolean envyoff = false;
9320
+
9321
+ String loadedskyboxname;
9322
+
89219323 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
89229324 //float[] light0 = { 0,0,0 };
89239325 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9210,11 +9612,35 @@
92109612 jy8[3] = 0.5f;
92119613 }
92129614
9213
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9615
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
92149616 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
92159617 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
92169618 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
92179619
9620
+ void ResetOptions()
9621
+ {
9622
+ options1[0] = 100;
9623
+ options1[1] = 0.025f;
9624
+ options1[2] = 0.01f;
9625
+ options1[3] = 0;
9626
+ options1[4] = 0;
9627
+
9628
+ options2[0] = 0;
9629
+ options2[1] = 0.75f;
9630
+ options2[2] = 0;
9631
+ options2[3] = 0;
9632
+
9633
+ options3[0] = 1;
9634
+ options3[1] = 1;
9635
+ options3[2] = 1;
9636
+ options3[3] = 0;
9637
+
9638
+ options4[0] = 1;
9639
+ options4[1] = 0;
9640
+ options4[2] = 1;
9641
+ options4[3] = 0;
9642
+ }
9643
+
92189644 static int imagecount = 0; // movie generation
92199645
92209646 static int jitter = 0;
....@@ -9310,8 +9736,8 @@
93109736 assert (parentcam != renderCamera);
93119737
93129738 if (renderCamera != lightCamera)
9313
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9314
- LA.matConcat(matrix, parentcam.toParent, matrix);
9739
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9740
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
93159741
93169742 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
93179743
....@@ -9326,8 +9752,8 @@
93269752 LA.matCopy(renderCamera.fromScreen, matrix);
93279753
93289754 if (renderCamera != lightCamera)
9329
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9330
- LA.matConcat(parentcam.fromParent, matrix, matrix);
9755
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9756
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
93319757
93329758 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
93339759
....@@ -9373,10 +9799,12 @@
93739799 rati = 1 / rati;
93749800 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
93759801 }
9376
- assert (newenvy == -1);
9802
+
9803
+ //assert (newenvy == -1);
9804
+
93779805 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
93789806 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9379
- DrawSkyBox(gl);
9807
+ DrawSkyBox(gl, (float)rati);
93809808 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
93819809 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
93829810 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10325,6 +10753,7 @@
1032510753 ANTIALIAS = 0;
1032610754 //System.out.println("RESTART");
1032710755 AAtimer.restart();
10756
+ Globals.TIMERRUNNING = true;
1032810757 }
1032910758 }
1033010759 }
....@@ -10392,13 +10821,14 @@
1039210821 ambientOcclusion = false;
1039310822 }
1039410823
10395
- if (Globals.lighttouched && DrawMode() == DEFAULT && !lightMode) // && !FROZEN)
10824
+ if (//Globals.lighttouched &&
10825
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1039610826 {
1039710827 //if (RENDERSHADOW) // ?
1039810828 if (!IsFrozen())
1039910829 {
1040010830 // dec 2012
10401
- if (!ambientOcclusion && !(!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0))
10831
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
1040210832 {
1040310833 Globals.framecount++;
1040410834 shadowbuffer.display();
....@@ -10525,8 +10955,8 @@
1052510955
1052610956 // if (parentcam != renderCamera) // not a light
1052710957 if (cam != lightCamera)
10528
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10529
- LA.matConcat(matrix, parentcam.toParent, matrix);
10958
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10959
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1053010960
1053110961 for (int j = 0; j < 4; j++)
1053210962 {
....@@ -10540,8 +10970,8 @@
1054010970
1054110971 // if (parentcam != renderCamera) // not a light
1054210972 if (cam != lightCamera)
10543
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10544
- LA.matConcat(parentcam.fromParent, matrix, matrix);
10973
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10974
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1054510975
1054610976 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1054710977
....@@ -10627,13 +11057,27 @@
1062711057 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1062811058 }
1062911059
10630
- if (newenvy > -1)
11060
+// if (newenvy > -1)
11061
+// {
11062
+// LoadEnvy(newenvy);
11063
+// }
11064
+//
11065
+// newenvy = -1;
11066
+
11067
+ if (object.skyboxname != null)
1063111068 {
10632
- LoadEnvy(newenvy);
11069
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11070
+ {
11071
+ LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11072
+ loadedskyboxname = object.skyboxname;
11073
+ }
1063311074 }
10634
-
10635
- newenvy = -1;
10636
-
11075
+ else
11076
+ {
11077
+ cubemap = null;
11078
+ loadedskyboxname = null;
11079
+ }
11080
+
1063711081 ratio = ((double) getWidth()) / getHeight();
1063811082 //System.out.println("ratio = " + ratio);
1063911083
....@@ -10649,7 +11093,7 @@
1064911093
1065011094 if (!IsFrozen() && !ambientOcclusion)
1065111095 {
10652
- DrawSkyBox(gl);
11096
+ DrawSkyBox(gl, (float)ratio);
1065311097 }
1065411098
1065511099 //if (selection_view == -1)
....@@ -10832,9 +11276,9 @@
1083211276
1083311277 gl.glMatrixMode(GL.GL_MODELVIEW);
1083411278
10835
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10836
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10837
-//gl.glEnable(gl.GL_MULTISAMPLE);
11279
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11280
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11281
+gl.glEnable(gl.GL_MULTISAMPLE);
1083811282 } else
1083911283 {
1084011284 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -10845,7 +11289,7 @@
1084511289 //System.out.println("BLENDING ON");
1084611290 gl.glEnable(GL.GL_BLEND);
1084711291 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
10848
-
11292
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1084911293 gl.glMatrixMode(gl.GL_PROJECTION);
1085011294 gl.glLoadIdentity();
1085111295
....@@ -10934,8 +11378,8 @@
1093411378 System.err.println("parentcam != renderCamera");
1093511379
1093611380 // if (cam != lightCamera)
10937
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10938
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11381
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11382
+ LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
1093911383 }
1094011384
1094111385 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -10956,8 +11400,8 @@
1095611400 if (true) // TODO
1095711401 {
1095811402 if (cam != lightCamera)
10959
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10960
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11403
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11404
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
1096111405 }
1096211406
1096311407 LA.xformPos(light0, cam.toScreen, light0);
....@@ -11094,7 +11538,7 @@
1109411538 }
1109511539 }
1109611540
11097
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11541
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1109811542 {
1109911543 //gl.glDepthFunc(GL.GL_LEQUAL);
1110011544 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11102,24 +11546,21 @@
1110211546
1110311547 boolean texon = textureon;
1110411548
11105
- if (RENDERPROGRAM > 0)
11106
- {
11107
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11108
- textureon = false;
11109
- }
11549
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11550
+ textureon = false;
11551
+
1111011552 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1111111553 //System.out.println("ALLO");
1111211554 gl.glColorMask(false, false, false, false);
1111311555 DrawObject(gl);
11114
- if (RENDERPROGRAM > 0)
11115
- {
11116
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11117
- textureon = texon;
11118
- }
11556
+
11557
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11558
+ textureon = texon;
11559
+
1111911560 gl.glColorMask(true, true, true, true);
1112011561
1112111562 gl.glDepthFunc(GL.GL_EQUAL);
11122
- //gl.glDepthMask(false);
11563
+ gl.glDepthMask(false);
1112311564 }
1112411565
1112511566 if (false) // DrawMode() == SHADOW)
....@@ -11302,15 +11743,36 @@
1130211743
1130311744 static boolean zoomonce = false;
1130411745
11746
+ static void CreateSelectedPoint()
11747
+ {
11748
+ if (selectedpoint == null)
11749
+ {
11750
+ debugpointG = new Sphere();
11751
+ debugpointP = new Sphere();
11752
+ debugpointC = new Sphere();
11753
+ debugpointR = new Sphere();
11754
+
11755
+ selectedpoint = new Superellipsoid();
11756
+
11757
+ for (int i=0; i<8; i++)
11758
+ {
11759
+ debugpoints[i] = new Sphere();
11760
+ }
11761
+ }
11762
+ }
11763
+
1130511764 void DrawObject(GL gl, boolean draw)
1130611765 {
11766
+ // To clear camera values
11767
+ ResetOptions();
11768
+
1130711769 //System.out.println("DRAW OBJECT " + mouseDown);
1130811770 // DrawMode() = SELECTION;
1130911771 //GL gl = getGL();
1131011772 if ((TRACK || SHADOWTRACK) || zoomonce)
1131111773 {
1131211774 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11313
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11775
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1131411776 pingthread.StepToTarget(true); // true);
1131511777 // zoomonce = false;
1131611778 }
....@@ -11382,8 +11844,9 @@
1138211844
1138311845 if (DrawMode() == DEFAULT)
1138411846 {
11385
- if (DEBUG)
11847
+ if (Globals.DEBUG)
1138611848 {
11849
+ CreateSelectedPoint();
1138711850 float radius = 0.05f;
1138811851 if (selectedpoint.radius != radius)
1138911852 {
....@@ -11437,20 +11900,32 @@
1143711900 ReleaseTextures(DEFAULT_TEXTURES);
1143811901
1143911902 if (CLEANCACHE)
11440
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11903
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1144111904 {
11442
- String tex = e.nextElement();
11905
+ cTexture tex = e.nextElement();
1144311906
1144411907 // System.out.println("Texture --------- " + tex);
1144511908
11446
- if (tex.equals("WHITE_NOISE"))
11909
+ if (tex.equals("WHITE_NOISE:"))
1144711910 continue;
1144811911
11449
- if (!usedtextures.containsKey(tex))
11912
+ if (!usedtextures.contains(tex))
1145011913 {
11914
+ CacheTexture gettex = texturepigment.get(tex);
1145111915 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11452
- textures.get(tex).texture.dispose();
11453
- textures.remove(tex);
11916
+ if (gettex != null)
11917
+ {
11918
+ gettex.texture.dispose();
11919
+ texturepigment.remove(tex);
11920
+ }
11921
+
11922
+ gettex = texturebump.get(tex);
11923
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11924
+ if (gettex != null)
11925
+ {
11926
+ gettex.texture.dispose();
11927
+ texturebump.remove(tex);
11928
+ }
1145411929 }
1145511930 }
1145611931 }
....@@ -11552,7 +12027,7 @@
1155212027 return;
1155312028 }
1155412029
11555
- String string = obj.GetToolTip();
12030
+ String string = obj.toString(); //.GetToolTip();
1155612031
1155712032 GL gl = GetGL();
1155812033
....@@ -11869,8 +12344,8 @@
1186912344 //obj.TransformToWorld(light, light);
1187012345 for (int i = tp.size(); --i >= 0;)
1187112346 {
11872
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
11873
- LA.xformPos(light, tp.get(i).toParent, light);
12347
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12348
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1187412349 }
1187512350
1187612351
....@@ -11887,8 +12362,8 @@
1188712362 parentcam = cameras[0];
1188812363 }
1188912364
11890
- for (int count = parentcam.GetTransformCount(); --count>=0;)
11891
- LA.xformPos(light, parentcam.toParent, light); // may 2013
12365
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
12366
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1189212367
1189312368 LA.xformPos(light, renderCamera.toScreen, light);
1189412369
....@@ -11978,8 +12453,76 @@
1197812453
1197912454 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1198012455
11981
- String program =
12456
+ String programmin =
12457
+ // Min shader
1198212458 "!!ARBfp1.0\n" +
12459
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12460
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12461
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12462
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12463
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12464
+ "PARAM light2cam0 = program.env[10];" +
12465
+ "PARAM light2cam1 = program.env[11];" +
12466
+ "PARAM light2cam2 = program.env[12];" +
12467
+ "TEMP temp;" +
12468
+ "TEMP light;" +
12469
+ "TEMP ndotl;" +
12470
+ "TEMP normal;" +
12471
+ "TEMP depth;" +
12472
+ "TEMP eye;" +
12473
+ "TEMP pos;" +
12474
+
12475
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12476
+ Normalize("normal") +
12477
+ "MOV light, state.light[0].position;" +
12478
+ "DP3 ndotl.x, light, normal;" +
12479
+
12480
+ // shadow
12481
+ "MOV pos, fragment.texcoord[1];" +
12482
+ "MOV temp, pos;" +
12483
+ ShadowTextureFetch("depth", "temp", "1") +
12484
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12485
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12486
+
12487
+ // No shadow when out of frustum
12488
+ //"SGE temp.y, depth.z, zero123.y;" +
12489
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12490
+
12491
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12492
+
12493
+ // Backlit
12494
+ "MOV pos.w, zero123.y;" +
12495
+ "DP4 eye.x, pos, light2cam0;" +
12496
+ "DP4 eye.y, pos, light2cam1;" +
12497
+ "DP4 eye.z, pos, light2cam2;" +
12498
+ Normalize("eye") +
12499
+
12500
+ "DP3 ndotl.y, -eye, normal;" +
12501
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12502
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12503
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12504
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12505
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12506
+
12507
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12508
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12509
+
12510
+ // Pigment
12511
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12512
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12513
+ "MUL temp, temp, ndotl.x;" +
12514
+
12515
+ "MUL temp, temp, zero123.z;" +
12516
+
12517
+ //"MUL temp, temp, ndotl.y;" +
12518
+
12519
+ "MOV temp.w, zero123.y;" + // reset alpha
12520
+ "MOV result.color, temp;" +
12521
+ "END";
12522
+
12523
+ String programmax =
12524
+ "!!ARBfp1.0\n" +
12525
+
1198312526 //"OPTION ARB_fragment_program_shadow;" +
1198412527 "PARAM light2cam0 = program.env[10];" +
1198512528 "PARAM light2cam1 = program.env[11];" +
....@@ -12094,8 +12637,7 @@
1209412637 "TEMP shininess;" +
1209512638 "\n" +
1209612639 "MOV texSamp, one;" +
12097
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12098
-
12640
+
1209912641 "MOV mapgrid.x, one2048th.x;" +
1210012642 "MOV temp, fragment.texcoord[1];" +
1210112643 /*
....@@ -12116,20 +12658,20 @@
1211612658 "MUL temp, floor, mapgrid.x;" +
1211712659 //"TEX depth0, temp, texture[1], 2D;" +
1211812660 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12119
- TextureFetch("depth0", "temp", "1") +
12661
+ ShadowTextureFetch("depth0", "temp", "1") +
1212012662 "") +
1212112663 "ADD temp.x, temp.x, mapgrid.x;" +
1212212664 //"TEX depth1, temp, texture[1], 2D;" +
1212312665 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12124
- TextureFetch("depth1", "temp", "1") +
12666
+ ShadowTextureFetch("depth1", "temp", "1") +
1212512667 "") +
1212612668 "ADD temp.y, temp.y, mapgrid.x;" +
1212712669 //"TEX depth2, temp, texture[1], 2D;" +
12128
- TextureFetch("depth2", "temp", "1") +
12670
+ ShadowTextureFetch("depth2", "temp", "1") +
1212912671 "SUB temp.x, temp.x, mapgrid.x;" +
1213012672 //"TEX depth3, temp, texture[1], 2D;" +
1213112673 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12132
- TextureFetch("depth3", "temp", "1") +
12674
+ ShadowTextureFetch("depth3", "temp", "1") +
1213312675 "") +
1213412676 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1213512677 //"MOV params, material;" +
....@@ -12500,10 +13042,10 @@
1250013042 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1250113043 "") +
1250213044
12503
- // display shadow only (bump == 0)
13045
+ // display shadow only (fakedepth == 0)
1250413046 "SUB temp.x, half.x, shadow.x;" +
1250513047 "MOV temp.y, -params5.z;" + // params6.x;" +
12506
- "SLT temp.z, temp.y, -one2048th.x;" +
13048
+ "SLT temp.z, temp.y, -c256i.x;" +
1250713049 "SUB temp.y, one.x, temp.z;" +
1250813050 "MUL temp.x, temp.x, temp.y;" +
1250913051 "KIL temp.x;" +
....@@ -12834,6 +13376,13 @@
1283413376 //once = true;
1283513377 }
1283613378
13379
+ String program = programmax;
13380
+
13381
+ if (Globals.MINSHADER)
13382
+ {
13383
+ program = programmin;
13384
+ }
13385
+
1283713386 System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1283813387 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1283913388 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
....@@ -12927,25 +13476,26 @@
1292713476 return out;
1292813477 }
1292913478
12930
- String TextureFetch(String dest, String src, String unit)
13479
+ // Also does frustum culling
13480
+ String ShadowTextureFetch(String dest, String src, String unit)
1293113481 {
1293213482 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1293313483 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1293413484 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13485
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13486
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1293513487 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12936
- "SLT " + src + ".z, " + src + ".x, one.x;" +
12937
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12938
- "SLT " + src + ".z, " + src + ".y, one.x;" +
12939
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13488
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13489
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1294013490 //"SWZ buffer, temp, w,w,w,w;";
12941
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13491
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1294213492 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1294313493 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1294413494 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
12945
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13495
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1294613496
12947
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
12948
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13497
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13498
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1294913499 }
1295013500
1295113501 String Shadow(String depth, String shadow)
....@@ -12992,7 +13542,7 @@
1299213542 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1299313543 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1299413544
12995
- // No shadow when out of frustrum
13545
+ // No shadow when out of frustum
1299613546 "SGE temp.x, " + depth + ".z, one.z;" +
1299713547 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1299813548 "";
....@@ -13140,7 +13690,8 @@
1314013690 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1314113691 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1314213692 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13143
- Object3D.cVector2[] vector2buffer;
13693
+
13694
+ //Object3D.cVector2[] vector2buffer;
1314413695
1314513696 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1314613697 // OUT : diff, spec
....@@ -13156,9 +13707,10 @@
1315613707 "DP3 " + dest + ".z," + "normals," + "eye;" +
1315713708 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1315813709 //"MOV " + dest + ".w," + "normal.z;" +
13159
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
13160
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13161
- //"MOV " + dest + ".z," + "params2.w;" +
13710
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13711
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13712
+
13713
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1316213714 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1316313715 "RCP " + dest + ".w," + dest + ".w;" +
1316413716 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13663,6 +14215,7 @@
1366314215 else
1366414216 if (evt.getSource() == AAtimer)
1366514217 {
14218
+ Globals.TIMERRUNNING = false;
1366614219 if (mouseDown)
1366714220 {
1366814221 //new Exception().printStackTrace();
....@@ -13722,7 +14275,7 @@
1372214275
1372314276 // fev 2014???
1372414277 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13725
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14278
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1372614279 pingthread.StepToTarget(true); // true);
1372714280 }
1372814281 // if (!LIVE)
....@@ -13737,6 +14290,7 @@
1373714290 return;
1373814291
1373914292 AAtimer.restart(); //
14293
+ Globals.TIMERRUNNING = true;
1374014294
1374114295 // waslive = LIVE;
1374214296 // LIVE = false;
....@@ -13786,14 +14340,15 @@
1378614340 drag = false;
1378714341 //System.out.println("Mouse DOWN");
1378814342 editObj = false;
13789
- ClickInfo info = new ClickInfo();
13790
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
13791
- info.pane = this;
13792
- info.camera = renderCamera;
13793
- info.x = x;
13794
- info.y = y;
13795
- info.modifiers = modifiersex;
13796
- editObj = object.doEditClick(info, 0);
14343
+ //ClickInfo info = new ClickInfo();
14344
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14345
+ object.clickInfo.pane = this;
14346
+ object.clickInfo.camera = renderCamera;
14347
+ object.clickInfo.x = x;
14348
+ object.clickInfo.y = y;
14349
+ object.clickInfo.modifiers = modifiersex;
14350
+ editObj = object.doEditClick(//info,
14351
+ 0);
1379714352 if (!editObj)
1379814353 {
1379914354 hasMarquee = true;
....@@ -13809,9 +14364,12 @@
1380914364
1381014365 public void mouseDragged(MouseEvent e)
1381114366 {
14367
+ Globals.MOUSEDRAGGED = true;
14368
+
1381214369 //System.out.println("mouseDragged: " + e);
1381314370 if (isRenderer)
1381414371 movingcamera = true;
14372
+
1381514373 //if (drawing)
1381614374 //return;
1381714375 if ((e.getModifiersEx() & CTRL) != 0
....@@ -14072,12 +14630,12 @@
1407214630 void GoDown(int mod)
1407314631 {
1407414632 MODIFIERS |= COMMAND;
14075
- /*
14633
+ /**/
1407614634 if((mod&SHIFT) == SHIFT)
1407714635 manipCamera.RotatePosition(0, -speed);
1407814636 else
14079
- manipCamera.BackForth(0, -speed*delta, getWidth());
14080
- */
14637
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14638
+ /**/
1408114639 if ((mod & SHIFT) == SHIFT)
1408214640 {
1408314641 mouseMode = mouseMode; // VR??
....@@ -14093,12 +14651,12 @@
1409314651 void GoUp(int mod)
1409414652 {
1409514653 MODIFIERS |= COMMAND;
14096
- /*
14654
+ /**/
1409714655 if((mod&SHIFT) == SHIFT)
1409814656 manipCamera.RotatePosition(0, speed);
1409914657 else
14100
- manipCamera.BackForth(0, speed*delta, getWidth());
14101
- */
14658
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14659
+ /**/
1410214660 if ((mod & SHIFT) == SHIFT)
1410314661 {
1410414662 mouseMode = mouseMode;
....@@ -14114,12 +14672,12 @@
1411414672 void GoLeft(int mod)
1411514673 {
1411614674 MODIFIERS |= COMMAND;
14117
- /*
14675
+ /**/
1411814676 if((mod&SHIFT) == SHIFT)
14119
- manipCamera.RotatePosition(speed, 0);
14120
- else
1412114677 manipCamera.Translate(speed*delta, 0, getWidth());
14122
- */
14678
+ else
14679
+ manipCamera.RotatePosition(speed, 0);
14680
+ /**/
1412314681 if ((mod & SHIFT) == SHIFT)
1412414682 {
1412514683 mouseMode = mouseMode;
....@@ -14135,12 +14693,12 @@
1413514693 void GoRight(int mod)
1413614694 {
1413714695 MODIFIERS |= COMMAND;
14138
- /*
14696
+ /**/
1413914697 if((mod&SHIFT) == SHIFT)
14140
- manipCamera.RotatePosition(-speed, 0);
14141
- else
1414214698 manipCamera.Translate(-speed*delta, 0, getWidth());
14143
- */
14699
+ else
14700
+ manipCamera.RotatePosition(-speed, 0);
14701
+ /**/
1414414702 if ((mod & SHIFT) == SHIFT)
1414514703 {
1414614704 mouseMode = mouseMode;
....@@ -14190,14 +14748,16 @@
1419014748 if (editObj)
1419114749 {
1419214750 drag = true;
14193
- ClickInfo info = new ClickInfo();
14194
- info.bounds.setBounds(0, 0,
14751
+ //ClickInfo info = new ClickInfo();
14752
+ object.clickInfo.bounds.setBounds(0, 0,
1419514753 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14196
- info.pane = this;
14197
- info.camera = renderCamera;
14198
- info.x = x;
14199
- info.y = y;
14200
- object.editWindow.copy.doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
14754
+ object.clickInfo.pane = this;
14755
+ object.clickInfo.camera = renderCamera;
14756
+ object.clickInfo.x = x;
14757
+ object.clickInfo.y = y;
14758
+ object //.GetWindow().copy
14759
+ .doEditDrag(//info,
14760
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1420114761 } else
1420214762 {
1420314763 if (x < startX)
....@@ -14346,22 +14906,27 @@
1434614906 }
1434714907 }
1434814908
14909
+// ClickInfo clickInfo = new ClickInfo();
14910
+
1434914911 public void mouseMoved(MouseEvent e)
1435014912 {
1435114913 //System.out.println("mouseMoved: " + e);
1435214914 if (isRenderer)
1435314915 return;
1435414916
14355
- ClickInfo ci = new ClickInfo();
14356
- ci.x = e.getX();
14357
- ci.y = e.getY();
14358
- ci.modifiers = e.getModifiersEx();
14359
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14360
- ci.pane = this;
14361
- ci.camera = renderCamera;
14917
+ // Mouse cursor feedback
14918
+ object.clickInfo.x = e.getX();
14919
+ object.clickInfo.y = e.getY();
14920
+ object.clickInfo.modifiers = e.getModifiersEx();
14921
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14922
+ object.clickInfo.pane = this;
14923
+ object.clickInfo.camera = renderCamera;
1436214924 if (!isRenderer)
1436314925 {
14364
- if (object.editWindow.copy.doEditClick(ci, 0))
14926
+ //ObjEditor editWindow = object.editWindow;
14927
+ //Object3D copy = editWindow.copy;
14928
+ if (object.doEditClick(//clickInfo,
14929
+ 0))
1436514930 {
1436614931 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1436714932 } else
....@@ -14373,8 +14938,11 @@
1437314938
1437414939 public void mouseReleased(MouseEvent e)
1437514940 {
14941
+ Globals.MOUSEDRAGGED = false;
14942
+
1437614943 movingcamera = false;
14377
- X = Y = 0;
14944
+ X = 0; // getBounds().width/2;
14945
+ Y = 0; // getBounds().height/2;
1437814946 //System.out.println("mouseReleased: " + e);
1437914947 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1438014948 }
....@@ -14630,7 +15198,8 @@
1463015198 // break;
1463115199 case 'T':
1463215200 CACHETEXTURE ^= true;
14633
- textures.clear();
15201
+ texturepigment.clear();
15202
+ texturebump.clear();
1463415203 // repaint();
1463515204 break;
1463615205 case 'Y':
....@@ -14715,7 +15284,9 @@
1471515284 case 'E' : COMPACT ^= true;
1471615285 repaint();
1471715286 break;
14718
- case 'W' : DEBUGHSB ^= true;
15287
+ case 'W' : // Wide Window (fullscreen)
15288
+ //DEBUGHSB ^= true;
15289
+ ObjEditor.theFrame.ToggleFullScreen();
1471915290 repaint();
1472015291 break;
1472115292 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14740,8 +15311,8 @@
1474015311 RevertCamera();
1474115312 repaint();
1474215313 break;
14743
- case 'L':
1474415314 case 'l':
15315
+ //case 'L':
1474515316 if (lightMode)
1474615317 {
1474715318 lightMode = false;
....@@ -14805,20 +15376,24 @@
1480515376 OCCLUSION_CULLING ^= true;
1480615377 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1480715378 break;
14808
- case '0': envyoff ^= true; repaint(); break;
15379
+ //case '0': envyoff ^= true; repaint(); break;
1480915380 case '1':
1481015381 case '2':
1481115382 case '3':
1481215383 case '4':
1481315384 case '5':
14814
- newenvy = Character.getNumericValue(key);
14815
- repaint();
14816
- break;
1481715385 case '6':
1481815386 case '7':
1481915387 case '8':
1482015388 case '9':
14821
- BGcolor = (key - '6')/3.f;
15389
+ if (true) // envyoff)
15390
+ {
15391
+ BGcolor = (key - '1')/8.f;
15392
+ }
15393
+ else
15394
+ {
15395
+ //newenvy = Character.getNumericValue(key);
15396
+ }
1482215397 repaint();
1482315398 break;
1482415399 case '!':
....@@ -14884,9 +15459,9 @@
1488415459 case '_':
1488515460 kompactbit = 5;
1488615461 break;
14887
- case '+':
14888
- kompactbit = 6;
14889
- break;
15462
+// case '+':
15463
+// kompactbit = 6;
15464
+// break;
1489015465 case ' ':
1489115466 lightMode ^= true;
1489215467 Globals.lighttouched = true;
....@@ -14898,6 +15473,7 @@
1489815473 case ESC:
1489915474 RENDERPROGRAM += 1;
1490015475 RENDERPROGRAM %= 3;
15476
+
1490115477 repaint();
1490215478 break;
1490315479 case 'Z':
....@@ -14937,8 +15513,9 @@
1493715513 case DELETE:
1493815514 ClearSelection();
1493915515 break;
14940
- /*
1494115516 case '+':
15517
+
15518
+ /*
1494215519 //fontsize += 1;
1494315520 bbzoom *= 2;
1494415521 repaint();
....@@ -14955,17 +15532,17 @@
1495515532 case '=':
1495615533 IncDepth();
1495715534 //fontsize += 1;
14958
- object.editWindow.refreshContents(true);
15535
+ object.GetWindow().refreshContents(true);
1495915536 maskbit = 6;
1496015537 break;
1496115538 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1496215539 DecDepth();
1496315540 maskbit = 5;
1496415541 //if(fontsize > 1) fontsize -= 1;
14965
- if (object.editWindow == null)
14966
- new Exception().printStackTrace();
14967
- else
14968
- object.editWindow.refreshContents(true);
15542
+// if (object.editWindow == null)
15543
+// new Exception().printStackTrace();
15544
+// else
15545
+ object.GetWindow().refreshContents(true);
1496915546 break;
1497015547 case '{':
1497115548 manipCamera.shaper_fovy /= 1.1;
....@@ -15189,7 +15766,7 @@
1518915766 }
1519015767 */
1519115768
15192
- object.editWindow.EditSelection();
15769
+ object.GetWindow().EditSelection(false);
1519315770 }
1519415771
1519515772 void SelectParent()
....@@ -15206,10 +15783,10 @@
1520615783 {
1520715784 //selectees.remove(i);
1520815785 System.out.println("select parent of " + elem);
15209
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15786
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1521015787 } else
1521115788 {
15212
- group.editWindow.Select(elem.GetTreePath(), first, true);
15789
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1521315790 }
1521415791
1521515792 first = false;
....@@ -15251,12 +15828,12 @@
1525115828 for (int j = 0; j < group.children.size(); j++)
1525215829 {
1525315830 elem = (Object3D) group.children.elementAt(j);
15254
- object.editWindow.Select(elem.GetTreePath(), first, true);
15831
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1525515832 first = false;
1525615833 }
1525715834 } else
1525815835 {
15259
- object.editWindow.Select(elem.GetTreePath(), first, true);
15836
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1526015837 }
1526115838
1526215839 first = false;
....@@ -15267,21 +15844,21 @@
1526715844 {
1526815845 //Composite group = (Composite) object;
1526915846 Object3D group = object;
15270
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15847
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1527115848 }
1527215849
1527315850 void ResetTransform(int mask)
1527415851 {
1527515852 //Composite group = (Composite) object;
1527615853 Object3D group = object;
15277
- group.editWindow.ResetTransform(mask);
15854
+ group.GetWindow().ResetTransform(mask);
1527815855 }
1527915856
1528015857 void FlipTransform()
1528115858 {
1528215859 //Composite group = (Composite) object;
1528315860 Object3D group = object;
15284
- group.editWindow.FlipTransform();
15861
+ group.GetWindow().FlipTransform();
1528515862 // group.editWindow.ReduceMesh(true);
1528615863 }
1528715864
....@@ -15289,7 +15866,7 @@
1528915866 {
1529015867 //Composite group = (Composite) object;
1529115868 Object3D group = object;
15292
- group.editWindow.PrintMemory();
15869
+ group.GetWindow().PrintMemory();
1529315870 // group.editWindow.ReduceMesh(true);
1529415871 }
1529515872
....@@ -15297,7 +15874,7 @@
1529715874 {
1529815875 //Composite group = (Composite) object;
1529915876 Object3D group = object;
15300
- group.editWindow.ResetCentroid();
15877
+ group.GetWindow().ResetCentroid();
1530115878 }
1530215879
1530315880 void IncDepth()
....@@ -15379,8 +15956,6 @@
1537915956
1538015957 int width = getBounds().width;
1538115958 int height = getBounds().height;
15382
- ClickInfo info = new ClickInfo();
15383
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1538415959 //Image img = CreateImage(width, height);
1538515960 //System.out.println("width = " + width + "; height = " + height + "\n");
1538615961
....@@ -15457,43 +16032,77 @@
1545716032 }
1545816033 if (object != null && !hasMarquee)
1545916034 {
16035
+ if (object.clickInfo == null)
16036
+ object.clickInfo = new ClickInfo();
16037
+ ClickInfo info = object.clickInfo;
16038
+ //ClickInfo info = new ClickInfo();
16039
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16040
+
1546016041 if (isRenderer)
1546116042 {
15462
- info.flags++;
16043
+ object.clickInfo.flags++;
1546316044 double frameAspect = (double) width / (double) height;
1546416045 if (frameAspect > renderCamera.aspect)
1546516046 {
1546616047 int desired = (int) ((double) height * renderCamera.aspect);
15467
- info.bounds.width -= width - desired;
15468
- info.bounds.x += (width - desired) / 2;
16048
+ object.clickInfo.bounds.width -= width - desired;
16049
+ object.clickInfo.bounds.x += (width - desired) / 2;
1546916050 } else
1547016051 {
1547116052 int desired = (int) ((double) width / renderCamera.aspect);
15472
- info.bounds.height -= height - desired;
15473
- info.bounds.y += (height - desired) / 2;
16053
+ object.clickInfo.bounds.height -= height - desired;
16054
+ object.clickInfo.bounds.y += (height - desired) / 2;
1547416055 }
1547516056 }
15476
- info.g = gr;
15477
- info.camera = renderCamera;
16057
+
16058
+ object.clickInfo.g = gr;
16059
+ object.clickInfo.camera = renderCamera;
1547816060 /*
1547916061 // Memory intensive (brep.verticescopy)
1548016062 if (!(object instanceof Composite))
1548116063 object.draw(info, 0, false); // SLOW :
1548216064 */
15483
- if (!isRenderer)
16065
+ if (!isRenderer) // && drag)
1548416066 {
15485
- object.drawEditHandles(info, 0);
15486
-
15487
- if (drag && (X != 0 || Y != 0) && object.selection.Size() > 0)
16067
+ Grafreed.Assert(object != null);
16068
+ Grafreed.Assert(object.selection != null);
16069
+ if (object.selection.Size() > 0)
1548816070 {
15489
- switch (object.selection.get(0).hitSomething)
16071
+ int hitSomething = object.selection.get(0).hitSomething;
16072
+
16073
+ object.clickInfo.DX = 0;
16074
+ object.clickInfo.DY = 0;
16075
+ object.clickInfo.W = 1;
16076
+ if (hitSomething == Object3D.hitCenter)
1549016077 {
15491
- case Object3D.hitCenter: gr.setColor(Color.pink); break;
15492
- case Object3D.hitRotate: gr.setColor(Color.green); break;
15493
- case Object3D.hitScale: gr.setColor(Color.cyan); break;
16078
+ info.DX = X;
16079
+ if (X != 0)
16080
+ info.DX -= info.bounds.width/2;
16081
+
16082
+ info.DY = Y;
16083
+ if (Y != 0)
16084
+ info.DY -= info.bounds.height/2;
1549416085 }
15495
-
15496
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16086
+
16087
+ object.drawEditHandles(//info,
16088
+ 0);
16089
+
16090
+ if (drag && (X != 0 || Y != 0))
16091
+ {
16092
+ switch (hitSomething)
16093
+ {
16094
+ case Object3D.hitCenter: gr.setColor(Color.pink);
16095
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16096
+ break;
16097
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16098
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16099
+ break;
16100
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16101
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16102
+ break;
16103
+ }
16104
+
16105
+ }
1549716106 }
1549816107 }
1549916108 }
....@@ -15911,7 +16520,7 @@
1591116520 Object3D object;
1591216521 static Object3D trackedobject;
1591316522 Camera renderCamera; // Light or Eye (or Occlusion)
15914
- /*static*/ Camera manipCamera; // Light or Eye
16523
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1591516524 /*static*/ Camera eyeCamera;
1591616525 /*static*/ Camera lightCamera;
1591716526 int cameracount;
....@@ -15975,6 +16584,8 @@
1597516584 private /*static*/ boolean firstime;
1597616585 private /*static*/ cVector newView = new cVector();
1597716586 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16587
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16588
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1597816589 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1597916590 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1598016591 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -15987,29 +16598,66 @@
1598716598 {
1598816599 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1598916600
16601
+ int usedsuf = 0;
16602
+
1599016603 for (int i = 0; i < suffixes.length; i++)
1599116604 {
15992
- String resourceName = basename + suffixes[i] + "." + suffix;
15993
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
15994
- mipmapped,
15995
- FileUtil.getFileSuffix(resourceName));
15996
- if (data == null)
16605
+ String[] suffixe = suffixes;
16606
+ String[] fallback = suffixes2;
16607
+ String[] fallfallback = suffixes3;
16608
+
16609
+ for (int c=usedsuf; --c>=0;)
1599716610 {
15998
- throw new IOException("Unable to load texture " + resourceName);
16611
+// String[] temp = suffixe;
16612
+// suffixe = fallback;
16613
+// fallback = fallfallback;
16614
+// fallfallback = temp;
1599916615 }
16616
+
16617
+ String resourceName = basename + suffixe[i] + "." + suffix;
16618
+ TextureData data;
16619
+
16620
+ try
16621
+ {
16622
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16623
+ mipmapped,
16624
+ FileUtil.getFileSuffix(resourceName));
16625
+ }
16626
+ catch (Exception e)
16627
+ {
16628
+ try
16629
+ {
16630
+ resourceName = basename + fallback[i] + "." + suffix;
16631
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16632
+ mipmapped,
16633
+ FileUtil.getFileSuffix(resourceName));
16634
+ }
16635
+ catch (Exception e2)
16636
+ {
16637
+ resourceName = basename + fallfallback[i] + "." + suffix;
16638
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16639
+ mipmapped,
16640
+ FileUtil.getFileSuffix(resourceName));
16641
+ }
16642
+ }
16643
+
1600016644 //System.out.println("Target = " + targets[i]);
1600116645 cubemap.updateImage(data, targets[i]);
1600216646 }
1600316647
1600416648 return cubemap;
1600516649 }
16650
+
1600616651 int bigsphere = -1;
1600716652
1600816653 float BGcolor = 0.5f;
1600916654
16010
- private void DrawSkyBox(GL gl)
16655
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16656
+
16657
+ private void DrawSkyBox(GL gl, float ratio)
1601116658 {
16012
- if (envyoff || cubemap == null)
16659
+ if (//envyoff ||
16660
+ cubemap == null)
1601316661 {
1601416662 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1601516663 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16024,7 +16672,17 @@
1602416672 // Compensates for ExaminerViewer's modification of modelview matrix
1602516673 gl.glMatrixMode(GL.GL_MODELVIEW);
1602616674 gl.glLoadIdentity();
16675
+ gl.glScalef(1,ratio,1);
1602716676
16677
+// colorV[0] = 2;
16678
+// colorV[1] = 2;
16679
+// colorV[2] = 2;
16680
+// colorV[3] = 1;
16681
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16682
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16683
+//
16684
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16685
+
1602816686 //gl.glActiveTexture(GL.GL_TEXTURE1);
1602916687 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1603016688
....@@ -16056,6 +16714,7 @@
1605616714 {
1605716715 gl.glScalef(1.0f, -1.0f, 1.0f);
1605816716 }
16717
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1605916718 gl.glMultMatrixd(viewrot_1, 0);
1606016719 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1606116720 //viewer.updateInverseRotation(gl);
....@@ -16196,16 +16855,16 @@
1619616855 cStatic.objectstack[materialdepth++] = checker;
1619716856 //System.out.println("material " + material);
1619816857 //Applet3D.tracein(this, selected);
16199
- vector2buffer = checker.projectedVertices;
16858
+ //vector2buffer = checker.projectedVertices;
1620016859
1620116860 //checker.GetMaterial().Draw(this, false); // true);
16202
- DrawMaterial(checker.GetMaterial(), false); // true);
16861
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1620316862
1620416863 materialdepth -= 1;
1620516864 if (materialdepth > 0)
1620616865 {
16207
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16208
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
16866
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16867
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1620916868 }
1621016869 //checker.GetMaterial().opacity = 1f;
1621116870 ////checker.GetMaterial().ambient = 1f;
....@@ -16291,6 +16950,14 @@
1629116950 }
1629216951 }
1629316952
16953
+ private Object3D GetFolder()
16954
+ {
16955
+ Object3D folder = object.GetWindow().copy;
16956
+ if (object.GetWindow().copy.selection.Size() > 0)
16957
+ folder = object.GetWindow().copy.selection.elementAt(0);
16958
+ return folder;
16959
+ }
16960
+
1629416961 class SelectBuffer implements GLEventListener
1629516962 {
1629616963
....@@ -16306,7 +16973,7 @@
1630616973 //new Exception().printStackTrace();
1630716974 System.out.println("select buffer init");
1630816975 // Use debug pipeline
16309
- drawable.setGL(new DebugGL(drawable.getGL()));
16976
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1631016977
1631116978 GL gl = drawable.getGL();
1631216979
....@@ -16370,6 +17037,17 @@
1637017037
1637117038 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1637217039
17040
+ if (PAINTMODE)
17041
+ {
17042
+ if (object.GetWindow().copy.selection.Size() > 0)
17043
+ {
17044
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17045
+
17046
+ // Make what you paint not selectable.
17047
+ paintobj.ResetSelectable();
17048
+ }
17049
+ }
17050
+
1637317051 //int tmp = selection_view;
1637417052 //selection_view = -1;
1637517053 int temp = DrawMode();
....@@ -16381,6 +17059,17 @@
1638117059 // temp = DEFAULT; // patch for selection debug
1638217060 Globals.drawMode = temp; // WARNING
1638317061
17062
+ if (PAINTMODE)
17063
+ {
17064
+ if (object.GetWindow().copy.selection.Size() > 0)
17065
+ {
17066
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17067
+
17068
+ // Revert.
17069
+ paintobj.RestoreSelectable();
17070
+ }
17071
+ }
17072
+
1638417073 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1638517074
1638617075 // trying different ways of getting the depth info over
....@@ -16428,6 +17117,8 @@
1642817117 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1642917118 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1643017119 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
17120
+
17121
+ CreateSelectedPoint();
1643117122
1643217123 // Will fit the mesh !!!
1643317124 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16482,29 +17173,31 @@
1648217173 }
1648317174
1648417175 if (!movingcamera && !PAINTMODE)
16485
- object.editWindow.ScreenFitPoint(); // fev 2014
17176
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1648617177
16487
- if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17178
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1648817179 {
16489
- Object3D paintobj = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17180
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1649017181
16491
- Object3D group = new Object3D("inst" + paintcount++);
17182
+ if (object.GetWindow().copy.selection.Size() > 0)
17183
+ {
17184
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1649217185
16493
- group.CreateMaterial(); // use a void leaf to select instances
16494
-
16495
- group.add(paintobj); // link
16496
-
16497
- object.editWindow.SnapObject(group);
16498
-
16499
- Object3D folder = object.editWindow.copy;
16500
-
16501
- if (object.editWindow.copy.selection.Size() > 0)
16502
- folder = object.editWindow.copy.selection.elementAt(0);
16503
-
16504
- folder.add(group);
16505
-
16506
- object.editWindow.ResetModel();
16507
- object.editWindow.refreshContents();
17186
+ Object3D inst = new Object3D("inst" + paintcount++);
17187
+
17188
+ inst.CreateMaterial(); // use a void leaf to select instances
17189
+
17190
+ inst.add(paintobj); // link
17191
+
17192
+ object.GetWindow().SnapObject(inst);
17193
+
17194
+ Object3D folder = paintFolder; // GetFolder();
17195
+
17196
+ folder.add(inst);
17197
+
17198
+ object.GetWindow().ResetModel();
17199
+ object.GetWindow().refreshContents();
17200
+ }
1650817201 }
1650917202 else
1651017203 paintcount = 0;
....@@ -16543,6 +17236,11 @@
1654317236 //System.out.println("objects[color] = " + objects[color]);
1654417237 //objects[color].Select();
1654517238 indexcount = 0;
17239
+ ObjEditor window = object.GetWindow();
17240
+ if (window != null && deselect)
17241
+ {
17242
+ window.Select(null, deselect, true);
17243
+ }
1654617244 object.Select(color, deselect);
1654717245 }
1654817246
....@@ -17068,23 +17766,15 @@
1706817766 int AAbuffersize = 0;
1706917767
1707017768 //double[] selectedpoint = new double[3];
17071
- static Superellipsoid selectedpoint = new Superellipsoid();
17769
+ static Superellipsoid selectedpoint;
1707217770 static Sphere previousselectedpoint = null;
17073
- static Sphere debugpointG = new Sphere();
17074
- static Sphere debugpointP = new Sphere();
17075
- static Sphere debugpointC = new Sphere();
17076
- static Sphere debugpointR = new Sphere();
17771
+ static Sphere debugpointG;
17772
+ static Sphere debugpointP;
17773
+ static Sphere debugpointC;
17774
+ static Sphere debugpointR;
1707717775
1707817776 static Sphere debugpoints[] = new Sphere[8];
1707917777
17080
- static
17081
- {
17082
- for (int i=0; i<8; i++)
17083
- {
17084
- debugpoints[i] = new Sphere();
17085
- }
17086
- }
17087
-
1708817778 static void InitPoints(float radius)
1708917779 {
1709017780 for (int i=0; i<8; i++)