Normand Briere
2019-08-13 c67de8aca04d988179191ccb52461af00125920e
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;
....@@ -74,7 +110,9 @@
74110 //private Mat4f spotlightTransform = new Mat4f();
75111 //private Mat4f spotlightInverseTransform = new Mat4f();
76112 static GLContext glcontext = null;
77
- /*static*/ com.sun.opengl.util.texture.Texture cubemap;
113
+ /*static*/ com.sun.opengl.util.texture.Texture cubemap; // Either custom or rgb
114
+ /*static*/ com.sun.opengl.util.texture.Texture cubemapcustom;
115
+ /*static*/ com.sun.opengl.util.texture.Texture cubemaprgb;
78116 boolean reverseUP = false;
79117 static boolean frozen = false;
80118 boolean enablebackspace = false; // patch for back buffer refresh
....@@ -137,7 +175,7 @@
137175 static boolean doublesided = false; // true; // reversed normals are awful for conformance
138176 boolean anisotropy = true;
139177 boolean softshadow = true; // slower but better false;
140
- boolean opacityhalo = false;
178
+ boolean opacityhalo = false; // reverse the halo effect (e.g. glass)
141179
142180 boolean macromode = false;
143181
....@@ -151,6 +189,19 @@
151189 }
152190
153191 private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
192
+
193
+ public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException
194
+ {
195
+ try
196
+ {
197
+ return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
198
+ } catch (IOException e)
199
+ {
200
+ System.out.println("NAME = " + name);
201
+ e.printStackTrace(); // throw new RuntimeException(e);
202
+ return null;
203
+ }
204
+ }
154205
155206 void SetAsGLRenderer(boolean b)
156207 {
....@@ -170,7 +221,8 @@
170221
171222 SetCamera(cam);
172223
173
- SetLight(new Camera(new cVector(10, 10, -20)));
224
+ // Warning: not used.
225
+ SetLight(new Camera(new cVector(15, 10, -20)));
174226
175227 object = o;
176228
....@@ -327,7 +379,7 @@
327379 cStatic.objectstack[materialdepth++] = obj;
328380 //System.out.println("material " + material);
329381 //Applet3D.tracein(this, selected);
330
- display.vector2buffer = obj.projectedVertices;
382
+ //display.vector2buffer = obj.projectedVertices;
331383 if (obj instanceof Camera)
332384 {
333385 display.options1[0] = material.shift;
....@@ -336,14 +388,28 @@
336388 display.options1[2] = material.shadowbias;
337389 display.options1[3] = material.aniso;
338390 display.options1[4] = material.anisoV;
391
+// System.out.println("display.options1[0] " + display.options1[0]);
392
+// System.out.println("display.options1[1] " + display.options1[1]);
393
+// System.out.println("display.options1[2] " + display.options1[2]);
394
+// System.out.println("display.options1[3] " + display.options1[3]);
395
+// System.out.println("display.options1[4] " + display.options1[4]);
339396 display.options2[0] = material.opacity;
340397 display.options2[1] = material.diffuse;
341398 display.options2[2] = material.factor;
399
+// System.out.println("display.options2[0] " + display.options2[0]);
400
+// System.out.println("display.options2[1] " + display.options2[1]);
401
+// System.out.println("display.options2[2] " + display.options2[2]);
342402
343403 cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
404
+// System.out.println("display.options3[0] " + display.options3[0]);
405
+// System.out.println("display.options3[1] " + display.options3[1]);
406
+// System.out.println("display.options3[2] " + display.options3[2]);
344407 display.options4[0] = material.cameralight/0.2f;
345408 display.options4[1] = material.subsurface;
346409 display.options4[2] = material.sheen;
410
+// System.out.println("display.options4[0] " + display.options4[0]);
411
+// System.out.println("display.options4[1] " + display.options4[1]);
412
+// System.out.println("display.options4[2] " + display.options4[2]);
347413
348414 // if (display.CURRENTANTIALIAS > 0)
349415 // display.options3[3] /= 4;
....@@ -359,7 +425,7 @@
359425 /**/
360426 } else
361427 {
362
- DrawMaterial(material, selected);
428
+ DrawMaterial(material, selected, obj.projectedVertices);
363429 }
364430 } else
365431 {
....@@ -383,8 +449,8 @@
383449 cStatic.objectstack[materialdepth++] = obj;
384450 //System.out.println("material " + material);
385451 //Applet3D.tracein("selected ", selected);
386
- display.vector2buffer = obj.projectedVertices;
387
- display.DrawMaterial(material, selected);
452
+ //display.vector2buffer = obj.projectedVertices;
453
+ display.DrawMaterial(material, selected, obj.projectedVertices);
388454 }
389455 }
390456
....@@ -401,8 +467,8 @@
401467 materialdepth -= 1;
402468 if (materialdepth > 0)
403469 {
404
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
405
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
470
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
471
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
406472 }
407473 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
408474 } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
....@@ -422,8 +488,8 @@
422488 materialdepth -= 1;
423489 if (materialdepth > 0)
424490 {
425
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
426
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
491
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
492
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
427493 }
428494 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
429495 //else
....@@ -464,10 +530,12 @@
464530 if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
465531 {
466532 //gl.glBegin(gl.GL_TRIANGLES);
467
- boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0);
533
+ boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0)
534
+ // TEST LIVE NORMALS && !obj.dontselect
535
+ ;
468536 if (!hasnorm)
469537 {
470
- // System.out.println("FUCK!!");
538
+ // System.out.println("Mesh normal");
471539 LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
472540 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
473541 LA.vecCross(obj.v0, obj.v1, obj.v2);
....@@ -1192,10 +1260,12 @@
11921260 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
11931261 }
11941262 }
1263
+
11951264 if (flipV)
11961265 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
11971266 else
11981267 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1268
+
11991269 //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
12001270 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
12011271
....@@ -1215,10 +1285,12 @@
12151285 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
12161286 }
12171287 }
1288
+
12181289 if (flipV)
12191290 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12201291 else
12211292 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1293
+
12221294 //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
12231295 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
12241296
....@@ -1246,8 +1318,10 @@
12461318 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12471319 else
12481320 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1321
+
12491322 //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
12501323 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1324
+
12511325 count2 += 2;
12521326 count3 += 3;
12531327 }
....@@ -1426,6 +1500,8 @@
14261500 gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
14271501 }
14281502
1503
+ float[] colorV = new float[4];
1504
+
14291505 void SetColor(Object3D obj, Vertex p0)
14301506 {
14311507 CameraPane display = this;
....@@ -1493,8 +1569,6 @@
14931569 {
14941570 return;
14951571 }
1496
-
1497
- float[] colorV = new float[3];
14981572
14991573 if (false) // marked)
15001574 {
....@@ -1603,7 +1677,7 @@
16031677 // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
16041678 }
16051679
1606
- void DrawMaterial(cMaterial material, boolean selected)
1680
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
16071681 {
16081682 CameraPane display = this;
16091683 //new Exception().printStackTrace();
....@@ -1638,7 +1712,7 @@
16381712 colorV[0] = display.modelParams0[0] * material.diffuse;
16391713 colorV[1] = display.modelParams0[1] * material.diffuse;
16401714 colorV[2] = display.modelParams0[2] * material.diffuse;
1641
- colorV[3] = material.opacity;
1715
+ colorV[3] = 1; // material.opacity;
16421716
16431717 gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
16441718 //System.out.println("Opacity = " + opacity);
....@@ -1746,9 +1820,9 @@
17461820 display.modelParams7[2] = 0;
17471821 display.modelParams7[3] = 0;
17481822
1749
- display.modelParams6[0] = 100; // criss de bug de bump
1823
+ //display.modelParams6[0] = 100; // criss de bug de bump
17501824
1751
- Object3D.cVector2[] extparams = display.vector2buffer;
1825
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
17521826 if (extparams != null && extparams.length > 0 && extparams[0] != null)
17531827 {
17541828 display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
....@@ -1890,7 +1964,7 @@
18901964 void PushMatrix(double[][] matrix)
18911965 {
18921966 // GrafreeD.tracein(matrix);
1893
- PushMatrix(matrix,1);
1967
+ PushMatrix(matrix, 1);
18941968 }
18951969
18961970 void PushMatrix()
....@@ -2044,7 +2118,7 @@
20442118 //System.err.println("Oeil on");
20452119 OEIL = true;
20462120 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2047
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2121
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
20482122 //pingthread.StepToTarget(true);
20492123 }
20502124
....@@ -2259,7 +2333,7 @@
22592333
22602334 void ToggleDebug()
22612335 {
2262
- DEBUG ^= true;
2336
+ Globals.DEBUG ^= true;
22632337 }
22642338
22652339 void ToggleLookAt()
....@@ -2277,10 +2351,17 @@
22772351 HANDLES ^= true;
22782352 }
22792353
2354
+ Object3D paintFolder;
2355
+
22802356 void TogglePaint()
22812357 {
22822358 PAINTMODE ^= true;
22832359 paintcount = 0;
2360
+
2361
+ if (PAINTMODE)
2362
+ {
2363
+ paintFolder = GetFolder();
2364
+ }
22842365 }
22852366
22862367 void SwapCamera(int a, int b)
....@@ -2377,6 +2458,21 @@
23772458 return currentGL;
23782459 }
23792460
2461
+ static private BufferedImage CreateBim(TextureData texturedata)
2462
+ {
2463
+ Grafreed.Assert(texturedata != null);
2464
+
2465
+ int width = texturedata.getWidth();
2466
+ int height = texturedata.getHeight();
2467
+
2468
+ Buffer buffer = texturedata.getBuffer();
2469
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2470
+
2471
+ byte[] bytes = bytebuf.array();
2472
+
2473
+ return CreateBim(bytes, width, height);
2474
+ }
2475
+
23802476 /**/
23812477 class CacheTexture
23822478 {
....@@ -2385,28 +2481,31 @@
23852481
23862482 int resolution;
23872483
2388
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2484
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
23892485 {
2390
- texture = tex;
2486
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2487
+ texturedata = texdata;
23912488 resolution = res;
23922489 }
23932490 }
23942491 /**/
23952492
23962493 // 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>();
2494
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2495
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2496
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2497
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2498
+
24002499 int pigmentdepth = 0;
24012500 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
24022501 int bumpdepth = 0;
24032502 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
24042503 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
24052504 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2406
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2505
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
24072506 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
24082507
2409
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2508
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
24102509 {
24112510 TextureData texturedata = null;
24122511
....@@ -2425,13 +2524,34 @@
24252524 if (bump)
24262525 texturedata = ConvertBump(texturedata, false);
24272526
2428
- com.sun.opengl.util.texture.Texture texture =
2429
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2527
+// com.sun.opengl.util.texture.Texture texture =
2528
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
24302529
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);
2530
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2531
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
24332532
2434
- return texture;
2533
+ return texturedata;
2534
+ }
2535
+
2536
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2537
+ {
2538
+ TextureData texturedata = null;
2539
+
2540
+ try
2541
+ {
2542
+ texturedata =
2543
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2544
+ bim,
2545
+ true);
2546
+ } catch (Exception e)
2547
+ {
2548
+ throw new javax.media.opengl.GLException(e);
2549
+ }
2550
+
2551
+ if (bump)
2552
+ texturedata = ConvertBump(texturedata, false);
2553
+
2554
+ return texturedata;
24352555 }
24362556
24372557 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3504,6 +3624,8 @@
35043624
35053625 System.out.println("LOADING TEXTURE : " + name);
35063626
3627
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3628
+
35073629 //
35083630 if (false) // compressbit > 0)
35093631 {
....@@ -7902,7 +8024,7 @@
79028024 String pigment = Object3D.GetPigment(tex);
79038025 String bump = Object3D.GetBump(tex);
79048026
7905
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8027
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79068028 {
79078029 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79088030 // System.out.println("; bump = " + bump);
....@@ -7917,11 +8039,69 @@
79178039 pigment = null;
79188040 }
79198041
7920
- ReleaseTexture(bump, true);
7921
- ReleaseTexture(pigment, false);
8042
+ ReleaseTexture(tex, true);
8043
+ ReleaseTexture(tex, false);
79228044 }
79238045
7924
- void ReleaseTexture(String tex, boolean bump)
8046
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
8047
+ {
8048
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8049
+ {
8050
+ return;
8051
+ }
8052
+
8053
+ if (tex == null)
8054
+ {
8055
+ ReleaseTexture(null, false);
8056
+ return;
8057
+ }
8058
+
8059
+ String pigment = Object3D.GetPigment(tex);
8060
+
8061
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8062
+ {
8063
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8064
+ // System.out.println("; bump = " + bump);
8065
+ }
8066
+
8067
+ if (pigment.equals(""))
8068
+ {
8069
+ pigment = null;
8070
+ }
8071
+
8072
+ ReleaseTexture(tex, false);
8073
+ }
8074
+
8075
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
8076
+ {
8077
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8078
+ {
8079
+ return;
8080
+ }
8081
+
8082
+ if (tex == null)
8083
+ {
8084
+ ReleaseTexture(null, true);
8085
+ return;
8086
+ }
8087
+
8088
+ String bump = Object3D.GetBump(tex);
8089
+
8090
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8091
+ {
8092
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8093
+ // System.out.println("; bump = " + bump);
8094
+ }
8095
+
8096
+ if (bump.equals(""))
8097
+ {
8098
+ bump = null;
8099
+ }
8100
+
8101
+ ReleaseTexture(tex, true);
8102
+ }
8103
+
8104
+ void ReleaseTexture(cTexture tex, boolean bump)
79258105 {
79268106 if (// DrawMode() != 0 || /*tex == null ||*/
79278107 ambientOcclusion ) // || !textureon)
....@@ -7932,7 +8112,7 @@
79328112 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
79338113
79348114 if (tex != null)
7935
- texture = textures.get(tex);
8115
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
79368116
79378117 // //assert( texture != null );
79388118 // if (texture == null)
....@@ -8026,6 +8206,54 @@
80268206
80278207 /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
80288208 {
8209
+// if (// DrawMode() != 0 || /*tex == null ||*/
8210
+// ambientOcclusion ) // || !textureon)
8211
+// {
8212
+// return; // false;
8213
+// }
8214
+//
8215
+// if (tex == null)
8216
+// {
8217
+// BindTexture(null,false,resolution);
8218
+// BindTexture(null,true,resolution);
8219
+// return;
8220
+// }
8221
+//
8222
+// String pigment = Object3D.GetPigment(tex);
8223
+// String bump = Object3D.GetBump(tex);
8224
+//
8225
+// usedtextures.add(pigment);
8226
+// usedtextures.add(bump);
8227
+//
8228
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8229
+// {
8230
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8231
+// // System.out.println("; bump = " + bump);
8232
+// }
8233
+//
8234
+// if (bump.equals(""))
8235
+// {
8236
+// bump = null;
8237
+// }
8238
+// if (pigment.equals(""))
8239
+// {
8240
+// pigment = null;
8241
+// }
8242
+//
8243
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8244
+// BindTexture(pigment, false, resolution);
8245
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8246
+// BindTexture(bump, true, resolution);
8247
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8248
+//
8249
+// return; // true;
8250
+
8251
+ BindPigmentTexture(tex, resolution);
8252
+ BindBumpTexture(tex, resolution);
8253
+ }
8254
+
8255
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8256
+ {
80298257 if (// DrawMode() != 0 || /*tex == null ||*/
80308258 ambientOcclusion ) // || !textureon)
80318259 {
....@@ -8035,17 +8263,47 @@
80358263 if (tex == null)
80368264 {
80378265 BindTexture(null,false,resolution);
8038
- BindTexture(null,true,resolution);
80398266 return;
80408267 }
80418268
80428269 String pigment = Object3D.GetPigment(tex);
8270
+
8271
+ usedtextures.add(tex);
8272
+
8273
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8274
+ {
8275
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8276
+ // System.out.println("; bump = " + bump);
8277
+ }
8278
+
8279
+ if (pigment.equals(""))
8280
+ {
8281
+ pigment = null;
8282
+ }
8283
+
8284
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8285
+ BindTexture(tex, false, resolution);
8286
+ }
8287
+
8288
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8289
+ {
8290
+ if (// DrawMode() != 0 || /*tex == null ||*/
8291
+ ambientOcclusion ) // || !textureon)
8292
+ {
8293
+ return; // false;
8294
+ }
8295
+
8296
+ if (tex == null)
8297
+ {
8298
+ BindTexture(null,true,resolution);
8299
+ return;
8300
+ }
8301
+
80438302 String bump = Object3D.GetBump(tex);
80448303
8045
- usedtextures.put(pigment, pigment);
8046
- usedtextures.put(bump, bump);
8304
+ usedtextures.add(tex);
80478305
8048
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8306
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
80498307 {
80508308 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
80518309 // System.out.println("; bump = " + bump);
....@@ -8055,18 +8313,10 @@
80558313 {
80568314 bump = null;
80578315 }
8058
- if (pigment.equals(""))
8059
- {
8060
- pigment = null;
8061
- }
80628316
8063
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8064
- BindTexture(pigment, false, resolution);
80658317 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8066
- BindTexture(bump, true, resolution);
8318
+ BindTexture(tex, true, resolution);
80678319 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8068
-
8069
- return; // true;
80708320 }
80718321
80728322 java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
....@@ -8089,13 +8339,19 @@
80898339 return fileExists;
80908340 }
80918341
8092
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception
8342
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
80938343 {
8094
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8344
+ CacheTexture texturecache = null;
80958345
80968346 if (tex != null)
80978347 {
8098
- String texname = tex;
8348
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8349
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
8350
+
8351
+ if (texname.equals("") && texdata == null)
8352
+ {
8353
+ return null;
8354
+ }
80998355
81008356 String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
81018357
....@@ -8105,19 +8361,46 @@
81058361 // else
81068362 // if (!texname.startsWith("/"))
81078363 // texname = "/Users/nbriere/Textures/" + texname;
8108
- if (!FileExists(tex))
8364
+ if (!FileExists(texname) && !texname.startsWith("@"))
81098365 {
81108366 texname = fallbackTextureName;
81118367 }
81128368
81138369 if (CACHETEXTURE)
8114
- texture = textures.get(texname); // TEXTURE CACHE
8115
-
8116
- TextureData texturedata = null;
8117
-
8118
- if (texture == null || texture.resolution < resolution)
81198370 {
8120
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8371
+ if (texdata == null)
8372
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8373
+ else
8374
+ texturecache = bimtextures.get(texdata);
8375
+ }
8376
+
8377
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8378
+ {
8379
+ TextureData texturedata = null;
8380
+
8381
+ if (texdata != null && textureon)
8382
+ {
8383
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8384
+
8385
+ try
8386
+ {
8387
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8388
+ }
8389
+ catch (Exception e)
8390
+ {
8391
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8392
+ }
8393
+
8394
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8395
+ bimtextures.put(texdata, texturecache);
8396
+
8397
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8398
+
8399
+ //Object bim2 = CreateBim(texturecache.texturedata);
8400
+ //bim2 = bim;
8401
+ }
8402
+ else
8403
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
81218404 {
81228405 assert(!bump);
81238406 // if (bump)
....@@ -8128,19 +8411,23 @@
81288411 // }
81298412 // else
81308413 // {
8131
- texture = textures.get(tex);
8132
- if (texture == null)
8414
+ // texturecache = textures.get(texname); // suspicious
8415
+ if (texturecache == null)
81338416 {
8134
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8417
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
81358418 }
8419
+ else
8420
+ new Exception().printStackTrace();
81368421 // }
81378422 } else
8138
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8423
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
81398424 {
81408425 assert(bump);
8141
- texture = textures.get(tex);
8142
- if (texture == null)
8143
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8426
+ // texturecache = textures.get(texname); // suspicious
8427
+ if (texturecache == null)
8428
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8429
+ else
8430
+ new Exception().printStackTrace();
81448431 } else
81458432 {
81468433 //if (tex.equals("IMMORTAL"))
....@@ -8148,11 +8435,22 @@
81488435 // texture = GetResourceTexture("default.png");
81498436 //} else
81508437 //{
8151
- if (tex.equals("WHITE_NOISE"))
8438
+ if (texname.endsWith("WHITE_NOISE"))
81528439 {
8153
- texture = textures.get(tex);
8154
- if (texture == null)
8155
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8440
+ // texturecache = textures.get(texname); // suspicious
8441
+ if (texturecache == null)
8442
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8443
+ else
8444
+ new Exception().printStackTrace();
8445
+ } else
8446
+ {
8447
+ if (texname.startsWith("@"))
8448
+ {
8449
+ // texturecache = textures.get(texname); // suspicious
8450
+ if (texturecache == null)
8451
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8452
+ else
8453
+ new Exception().printStackTrace();
81568454 } else
81578455 {
81588456 if (textureon)
....@@ -8211,19 +8509,20 @@
82118509 if (texturedata == null)
82128510 throw new Exception();
82138511
8214
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8512
+ texturecache = new CacheTexture(texturedata,resolution);
82158513 //texture = GetTexture(tex, bump);
82168514 }
8515
+ }
82178516 }
82188517 //}
82198518 }
82208519
8221
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8520
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
82228521 {
82238522 //return false;
82248523
82258524 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8226
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8525
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
82278526 {
82288527 // String ext = "_highres";
82298528 // if (REDUCETEXTURE)
....@@ -8240,52 +8539,17 @@
82408539 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
82418540 if (!cachefile.exists())
82428541 {
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))
8542
+ //if (texturedata.getWidth() == texturedata.getHeight())
82528543 {
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);
8544
+ BufferedImage rendImage = CreateBim(texturedata);
8545
+
82838546 ImageWriter writer = null;
82848547 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
82858548 if (iter.hasNext()) {
82868549 writer = (ImageWriter)iter.next();
82878550 }
8288
- float compressionQuality = 0.9f;
8551
+
8552
+ float compressionQuality = 0.85f;
82898553 try
82908554 {
82918555 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8302,18 +8566,20 @@
83028566 }
83038567 }
83048568 }
8305
-
8569
+
8570
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8571
+
83068572 //System.out.println("Texture = " + tex);
8307
- if (textures.containsKey(texname))
8573
+ if (textures.containsKey(tex))
83088574 {
8309
- CacheTexture thetex = textures.get(texname);
8575
+ CacheTexture thetex = textures.get(tex);
83108576 thetex.texture.disable();
83118577 thetex.texture.dispose();
8312
- textures.remove(texname);
8578
+ textures.remove(tex);
83138579 }
83148580
8315
- texture.texturedata = texturedata;
8316
- textures.put(texname, texture);
8581
+ //texture.texturedata = texturedata;
8582
+ textures.put(tex, texturecache);
83178583
83188584 // newtex = true;
83198585 }
....@@ -8329,10 +8595,44 @@
83298595 }
83308596 }
83318597
8332
- return texture;
8598
+ return texturecache;
83338599 }
83348600
8335
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution) throws Exception
8601
+ static void EmbedTextures(cTexture tex)
8602
+ {
8603
+ if (tex.pigmentdata == null)
8604
+ {
8605
+ //String texname = Object3D.GetPigment(tex);
8606
+
8607
+ CacheTexture texturecache = texturepigment.get(tex);
8608
+
8609
+ if (texturecache != null)
8610
+ {
8611
+ tex.pw = texturecache.texturedata.getWidth();
8612
+ tex.ph = texturecache.texturedata.getHeight();
8613
+ tex.pigmentdata = //CompressJPEG(CreateBim
8614
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8615
+ ;
8616
+ //, tex.pw, tex.ph), 0.5f);
8617
+ }
8618
+ }
8619
+
8620
+ if (tex.bumpdata == null)
8621
+ {
8622
+ //String texname = Object3D.GetBump(tex);
8623
+
8624
+ CacheTexture texturecache = texturebump.get(tex);
8625
+
8626
+ if (texturecache != null)
8627
+ {
8628
+ tex.bw = texturecache.texturedata.getWidth();
8629
+ tex.bh = texturecache.texturedata.getHeight();
8630
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8631
+ }
8632
+ }
8633
+ }
8634
+
8635
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
83368636 {
83378637 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
83388638
....@@ -8350,21 +8650,21 @@
83508650 return texture!=null?texture.texture:null;
83518651 }
83528652
8353
- public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution) throws Exception
8653
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
83548654 {
83558655 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
83568656
83578657 return texture!=null?texture.texturedata:null;
83588658 }
83598659
8360
- boolean BindTexture(String tex, boolean bump, int resolution) throws Exception
8660
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
83618661 {
83628662 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
83638663 {
83648664 return false;
83658665 }
83668666
8367
- boolean newtex = false;
8667
+ //boolean newtex = false;
83688668
83698669 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
83708670
....@@ -8396,9 +8696,75 @@
83968696 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
83978697 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
83988698
8399
- return newtex;
8699
+ return true; // Warning: not used.
84008700 }
84018701
8702
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8703
+ {
8704
+ try
8705
+ {
8706
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8707
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8708
+ ImageWriter writer = writers.next();
8709
+
8710
+ ImageWriteParam param = writer.getDefaultWriteParam();
8711
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8712
+ param.setCompressionQuality(quality);
8713
+
8714
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8715
+ writer.setOutput(ios);
8716
+ writer.write(null, new IIOImage(image, null, null), param);
8717
+
8718
+ byte[] data = baos.toByteArray();
8719
+ writer.dispose();
8720
+ return data;
8721
+ }
8722
+ catch (Exception e)
8723
+ {
8724
+ e.printStackTrace();
8725
+ return null;
8726
+ }
8727
+ }
8728
+
8729
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8730
+ {
8731
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8732
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8733
+ ImageReader reader = writers.next();
8734
+
8735
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8736
+
8737
+ ImageReadParam param = reader.getDefaultReadParam();
8738
+ param.setDestination(bim);
8739
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8740
+
8741
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8742
+ reader.setInput(ios);
8743
+ BufferedImage bim2 = reader.read(0, param);
8744
+ reader.dispose();
8745
+
8746
+// WritableRaster raster = bim2.getRaster();
8747
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8748
+// byte[] bytes = data.getData();
8749
+//
8750
+// int[] pixels = new int[bytes.length/3];
8751
+// for (int i=pixels.length; --i>=0;)
8752
+// {
8753
+// int i3 = i*3;
8754
+// pixels[i] = 0xFF;
8755
+// pixels[i] <<= 8;
8756
+// pixels[i] |= bytes[i3+2] & 0xFF;
8757
+// pixels[i] <<= 8;
8758
+// pixels[i] |= bytes[i3+1] & 0xFF;
8759
+// pixels[i] <<= 8;
8760
+// pixels[i] |= bytes[i3] & 0xFF;
8761
+// }
8762
+//
8763
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8764
+
8765
+ return bim;
8766
+ }
8767
+
84028768 ShadowBuffer shadowPBuf;
84038769 AntialiasBuffer antialiasPBuf;
84048770 int MAXSTACK;
....@@ -8415,10 +8781,12 @@
84158781
84168782 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
84178783 MAXSTACK = temp[0];
8418
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8784
+ if (Globals.DEBUG)
8785
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
84198786 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
84208787 MAXSTACK = temp[0];
8421
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8788
+ if (Globals.DEBUG)
8789
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
84228790
84238791 // Use debug pipeline
84248792 //drawable.setGL(new DebugGL(gl)); //
....@@ -8426,7 +8794,8 @@
84268794 gl = drawable.getGL(); //
84278795
84288796 GL gl3 = getGL();
8429
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8797
+ if (Globals.DEBUG)
8798
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
84308799
84318800
84328801 //float pos[] = { 100, 100, 100, 0 };
....@@ -8591,7 +8960,7 @@
85918960
85928961 if (cubemap == null)
85938962 {
8594
- LoadEnvy(5);
8963
+ //LoadEnvy(1);
85958964 }
85968965
85978966 //cubemap.enable();
....@@ -8867,6 +9236,8 @@
88679236
88689237 void LoadEnvy(int which)
88699238 {
9239
+ assert(false);
9240
+
88709241 String name;
88719242 String ext;
88729243
....@@ -8878,37 +9249,58 @@
88789249 cubemap = null;
88799250 return;
88809251 case 1:
8881
- name = "cubemaps/box_";
8882
- ext = "png";
9252
+ name = "cubemaps/rgb/";
9253
+ ext = "jpg";
88839254 reverseUP = false;
88849255 break;
88859256 case 2:
8886
- name = "cubemaps/uffizi_";
8887
- ext = "png";
8888
- break; // reverseUP = true; break;
9257
+ name = "cubemaps/uffizi/";
9258
+ ext = "jpg";
9259
+ reverseUP = false;
9260
+ break;
88899261 case 3:
8890
- name = "cubemaps/CloudyHills_";
8891
- ext = "tga";
9262
+ name = "cubemaps/CloudyHills/";
9263
+ ext = "jpg";
88929264 reverseUP = false;
88939265 break;
88949266 case 4:
8895
- name = "cubemaps/cornell_";
9267
+ name = "cubemaps/cornell/";
88969268 ext = "png";
88979269 reverseUP = false;
88989270 break;
9271
+ case 5:
9272
+ name = "cubemaps/skycube/";
9273
+ ext = "jpg";
9274
+ reverseUP = false;
9275
+ break;
9276
+ case 6:
9277
+ name = "cubemaps/SaintLazarusChurch3/";
9278
+ ext = "jpg";
9279
+ reverseUP = false;
9280
+ break;
9281
+ case 7:
9282
+ name = "cubemaps/Sodermalmsallen/";
9283
+ ext = "jpg";
9284
+ reverseUP = false;
9285
+ break;
9286
+ case 8:
9287
+ name = "cubemaps/Sodermalmsallen2/";
9288
+ ext = "jpg";
9289
+ reverseUP = false;
9290
+ break;
9291
+ case 9:
9292
+ name = "cubemaps/UnionSquare/";
9293
+ ext = "jpg";
9294
+ reverseUP = false;
9295
+ break;
88999296 default:
8900
- name = "cubemaps/rgb_";
8901
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9297
+ name = "cubemaps/box/";
9298
+ ext = "png"; /*mipmap = true;*/
9299
+ reverseUP = false;
89029300 break;
89039301 }
8904
-
8905
- try
8906
- {
8907
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
8908
- } catch (IOException e)
8909
- {
8910
- throw new RuntimeException(e);
8911
- }
9302
+
9303
+ LoadSkybox(name, ext, mipmap);
89129304 }
89139305
89149306 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -8940,8 +9332,12 @@
89409332 static double[] model = new double[16];
89419333 double[] camera2light = new double[16];
89429334 double[] light2camera = new double[16];
8943
- int newenvy = -1;
8944
- boolean envyoff = true; // false;
9335
+
9336
+ //int newenvy = -1;
9337
+ //boolean envyoff = false;
9338
+
9339
+ String loadedskyboxname;
9340
+
89459341 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
89469342 //float[] light0 = { 0,0,0 };
89479343 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9234,11 +9630,35 @@
92349630 jy8[3] = 0.5f;
92359631 }
92369632
9237
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9633
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
92389634 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
92399635 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
92409636 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
92419637
9638
+ void ResetOptions()
9639
+ {
9640
+ options1[0] = 100;
9641
+ options1[1] = 0.025f;
9642
+ options1[2] = 0.01f;
9643
+ options1[3] = 0;
9644
+ options1[4] = 0;
9645
+
9646
+ options2[0] = 0;
9647
+ options2[1] = 0.75f;
9648
+ options2[2] = 0;
9649
+ options2[3] = 0;
9650
+
9651
+ options3[0] = 1;
9652
+ options3[1] = 1;
9653
+ options3[2] = 1;
9654
+ options3[3] = 0;
9655
+
9656
+ options4[0] = 1;
9657
+ options4[1] = 0;
9658
+ options4[2] = 1;
9659
+ options4[3] = 0;
9660
+ }
9661
+
92429662 static int imagecount = 0; // movie generation
92439663
92449664 static int jitter = 0;
....@@ -9397,10 +9817,12 @@
93979817 rati = 1 / rati;
93989818 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
93999819 }
9400
- assert (newenvy == -1);
9820
+
9821
+ //assert (newenvy == -1);
9822
+
94019823 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
94029824 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9403
- DrawSkyBox(gl);
9825
+ DrawSkyBox(gl, (float)rati);
94049826 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
94059827 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
94069828 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10349,6 +10771,7 @@
1034910771 ANTIALIAS = 0;
1035010772 //System.out.println("RESTART");
1035110773 AAtimer.restart();
10774
+ Globals.TIMERRUNNING = true;
1035210775 }
1035310776 }
1035410777 }
....@@ -10416,7 +10839,8 @@
1041610839 ambientOcclusion = false;
1041710840 }
1041810841
10419
- if (Globals.lighttouched && DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
10842
+ if (//Globals.lighttouched &&
10843
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1042010844 {
1042110845 //if (RENDERSHADOW) // ?
1042210846 if (!IsFrozen())
....@@ -10435,7 +10859,7 @@
1043510859
1043610860 if (wait)
1043710861 {
10438
- Sleep(500);
10862
+ Sleep(200); // blocks everything
1043910863
1044010864 wait = false;
1044110865 }
....@@ -10651,13 +11075,41 @@
1065111075 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1065211076 }
1065311077
10654
- if (newenvy > -1)
11078
+// if (newenvy > -1)
11079
+// {
11080
+// LoadEnvy(newenvy);
11081
+// }
11082
+//
11083
+// newenvy = -1;
11084
+
11085
+ if (object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
1065511086 {
10656
- LoadEnvy(newenvy);
11087
+ if (cubemaprgb == null)
11088
+ {
11089
+ cubemaprgb = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11090
+ }
11091
+
11092
+ cubemap = cubemaprgb;
1065711093 }
10658
-
10659
- newenvy = -1;
10660
-
11094
+ else
11095
+ {
11096
+ if (object.skyboxname != null)
11097
+ {
11098
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11099
+ {
11100
+ cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11101
+ loadedskyboxname = object.skyboxname;
11102
+ }
11103
+ }
11104
+ else
11105
+ {
11106
+ cubemapcustom = null;
11107
+ loadedskyboxname = null;
11108
+ }
11109
+
11110
+ cubemap = cubemapcustom;
11111
+ }
11112
+
1066111113 ratio = ((double) getWidth()) / getHeight();
1066211114 //System.out.println("ratio = " + ratio);
1066311115
....@@ -10673,7 +11125,7 @@
1067311125
1067411126 if (!IsFrozen() && !ambientOcclusion)
1067511127 {
10676
- DrawSkyBox(gl);
11128
+ DrawSkyBox(gl, (float)ratio);
1067711129 }
1067811130
1067911131 //if (selection_view == -1)
....@@ -10856,9 +11308,9 @@
1085611308
1085711309 gl.glMatrixMode(GL.GL_MODELVIEW);
1085811310
10859
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10860
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10861
-//gl.glEnable(gl.GL_MULTISAMPLE);
11311
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11312
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11313
+gl.glEnable(gl.GL_MULTISAMPLE);
1086211314 } else
1086311315 {
1086411316 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -10869,7 +11321,7 @@
1086911321 //System.out.println("BLENDING ON");
1087011322 gl.glEnable(GL.GL_BLEND);
1087111323 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
10872
-
11324
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1087311325 gl.glMatrixMode(gl.GL_PROJECTION);
1087411326 gl.glLoadIdentity();
1087511327
....@@ -10981,7 +11433,7 @@
1098111433 {
1098211434 if (cam != lightCamera)
1098311435 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10984
- LA.xformDir(light0, parentcam.GlobalTransformInv(), light0); // may 2013
11436
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
1098511437 }
1098611438
1098711439 LA.xformPos(light0, cam.toScreen, light0);
....@@ -11118,7 +11570,7 @@
1111811570 }
1111911571 }
1112011572
11121
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11573
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1112211574 {
1112311575 //gl.glDepthFunc(GL.GL_LEQUAL);
1112411576 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11126,24 +11578,21 @@
1112611578
1112711579 boolean texon = textureon;
1112811580
11129
- if (RENDERPROGRAM > 0)
11130
- {
11131
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11132
- textureon = false;
11133
- }
11581
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11582
+ textureon = false;
11583
+
1113411584 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1113511585 //System.out.println("ALLO");
1113611586 gl.glColorMask(false, false, false, false);
1113711587 DrawObject(gl);
11138
- if (RENDERPROGRAM > 0)
11139
- {
11140
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11141
- textureon = texon;
11142
- }
11588
+
11589
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11590
+ textureon = texon;
11591
+
1114311592 gl.glColorMask(true, true, true, true);
1114411593
1114511594 gl.glDepthFunc(GL.GL_EQUAL);
11146
- //gl.glDepthMask(false);
11595
+ gl.glDepthMask(false);
1114711596 }
1114811597
1114911598 if (false) // DrawMode() == SHADOW)
....@@ -11326,15 +11775,36 @@
1132611775
1132711776 static boolean zoomonce = false;
1132811777
11778
+ static void CreateSelectedPoint()
11779
+ {
11780
+ if (selectedpoint == null)
11781
+ {
11782
+ debugpointG = new Sphere();
11783
+ debugpointP = new Sphere();
11784
+ debugpointC = new Sphere();
11785
+ debugpointR = new Sphere();
11786
+
11787
+ selectedpoint = new Superellipsoid();
11788
+
11789
+ for (int i=0; i<8; i++)
11790
+ {
11791
+ debugpoints[i] = new Sphere();
11792
+ }
11793
+ }
11794
+ }
11795
+
1132911796 void DrawObject(GL gl, boolean draw)
1133011797 {
11798
+ // To clear camera values
11799
+ ResetOptions();
11800
+
1133111801 //System.out.println("DRAW OBJECT " + mouseDown);
1133211802 // DrawMode() = SELECTION;
1133311803 //GL gl = getGL();
1133411804 if ((TRACK || SHADOWTRACK) || zoomonce)
1133511805 {
1133611806 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11337
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11807
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1133811808 pingthread.StepToTarget(true); // true);
1133911809 // zoomonce = false;
1134011810 }
....@@ -11406,8 +11876,9 @@
1140611876
1140711877 if (DrawMode() == DEFAULT)
1140811878 {
11409
- if (DEBUG)
11879
+ if (Globals.DEBUG)
1141011880 {
11881
+ CreateSelectedPoint();
1141111882 float radius = 0.05f;
1141211883 if (selectedpoint.radius != radius)
1141311884 {
....@@ -11461,20 +11932,32 @@
1146111932 ReleaseTextures(DEFAULT_TEXTURES);
1146211933
1146311934 if (CLEANCACHE)
11464
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11935
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1146511936 {
11466
- String tex = e.nextElement();
11937
+ cTexture tex = e.nextElement();
1146711938
1146811939 // System.out.println("Texture --------- " + tex);
1146911940
11470
- if (tex.equals("WHITE_NOISE"))
11941
+ if (tex.equals("WHITE_NOISE:"))
1147111942 continue;
1147211943
11473
- if (!usedtextures.containsKey(tex))
11944
+ if (!usedtextures.contains(tex))
1147411945 {
11946
+ CacheTexture gettex = texturepigment.get(tex);
1147511947 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11476
- textures.get(tex).texture.dispose();
11477
- textures.remove(tex);
11948
+ if (gettex != null)
11949
+ {
11950
+ gettex.texture.dispose();
11951
+ texturepigment.remove(tex);
11952
+ }
11953
+
11954
+ gettex = texturebump.get(tex);
11955
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11956
+ if (gettex != null)
11957
+ {
11958
+ gettex.texture.dispose();
11959
+ texturebump.remove(tex);
11960
+ }
1147811961 }
1147911962 }
1148011963 }
....@@ -11912,7 +12395,7 @@
1191212395 }
1191312396
1191412397 //for (int count = parentcam.GetTransformCount(); --count>=0;)
11915
- LA.xformPos(light, parentcam.GlobalTransformInv(), light); // may 2013
12398
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1191612399
1191712400 LA.xformPos(light, renderCamera.toScreen, light);
1191812401
....@@ -12002,8 +12485,76 @@
1200212485
1200312486 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1200412487
12005
- String program =
12488
+ String programmin =
12489
+ // Min shader
1200612490 "!!ARBfp1.0\n" +
12491
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12492
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12493
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12494
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12495
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12496
+ "PARAM light2cam0 = program.env[10];" +
12497
+ "PARAM light2cam1 = program.env[11];" +
12498
+ "PARAM light2cam2 = program.env[12];" +
12499
+ "TEMP temp;" +
12500
+ "TEMP light;" +
12501
+ "TEMP ndotl;" +
12502
+ "TEMP normal;" +
12503
+ "TEMP depth;" +
12504
+ "TEMP eye;" +
12505
+ "TEMP pos;" +
12506
+
12507
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12508
+ Normalize("normal") +
12509
+ "MOV light, state.light[0].position;" +
12510
+ "DP3 ndotl.x, light, normal;" +
12511
+
12512
+ // shadow
12513
+ "MOV pos, fragment.texcoord[1];" +
12514
+ "MOV temp, pos;" +
12515
+ ShadowTextureFetch("depth", "temp", "1") +
12516
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12517
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12518
+
12519
+ // No shadow when out of frustum
12520
+ //"SGE temp.y, depth.z, zero123.y;" +
12521
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12522
+
12523
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12524
+
12525
+ // Backlit
12526
+ "MOV pos.w, zero123.y;" +
12527
+ "DP4 eye.x, pos, light2cam0;" +
12528
+ "DP4 eye.y, pos, light2cam1;" +
12529
+ "DP4 eye.z, pos, light2cam2;" +
12530
+ Normalize("eye") +
12531
+
12532
+ "DP3 ndotl.y, -eye, normal;" +
12533
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12534
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12535
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12536
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12537
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12538
+
12539
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12540
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12541
+
12542
+ // Pigment
12543
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12544
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12545
+ "MUL temp, temp, ndotl.x;" +
12546
+
12547
+ "MUL temp, temp, zero123.z;" +
12548
+
12549
+ //"MUL temp, temp, ndotl.y;" +
12550
+
12551
+ "MOV temp.w, zero123.y;" + // reset alpha
12552
+ "MOV result.color, temp;" +
12553
+ "END";
12554
+
12555
+ String programmax =
12556
+ "!!ARBfp1.0\n" +
12557
+
1200712558 //"OPTION ARB_fragment_program_shadow;" +
1200812559 "PARAM light2cam0 = program.env[10];" +
1200912560 "PARAM light2cam1 = program.env[11];" +
....@@ -12118,8 +12669,7 @@
1211812669 "TEMP shininess;" +
1211912670 "\n" +
1212012671 "MOV texSamp, one;" +
12121
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12122
-
12672
+
1212312673 "MOV mapgrid.x, one2048th.x;" +
1212412674 "MOV temp, fragment.texcoord[1];" +
1212512675 /*
....@@ -12140,20 +12690,20 @@
1214012690 "MUL temp, floor, mapgrid.x;" +
1214112691 //"TEX depth0, temp, texture[1], 2D;" +
1214212692 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12143
- TextureFetch("depth0", "temp", "1") +
12693
+ ShadowTextureFetch("depth0", "temp", "1") +
1214412694 "") +
1214512695 "ADD temp.x, temp.x, mapgrid.x;" +
1214612696 //"TEX depth1, temp, texture[1], 2D;" +
1214712697 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12148
- TextureFetch("depth1", "temp", "1") +
12698
+ ShadowTextureFetch("depth1", "temp", "1") +
1214912699 "") +
1215012700 "ADD temp.y, temp.y, mapgrid.x;" +
1215112701 //"TEX depth2, temp, texture[1], 2D;" +
12152
- TextureFetch("depth2", "temp", "1") +
12702
+ ShadowTextureFetch("depth2", "temp", "1") +
1215312703 "SUB temp.x, temp.x, mapgrid.x;" +
1215412704 //"TEX depth3, temp, texture[1], 2D;" +
1215512705 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12156
- TextureFetch("depth3", "temp", "1") +
12706
+ ShadowTextureFetch("depth3", "temp", "1") +
1215712707 "") +
1215812708 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1215912709 //"MOV params, material;" +
....@@ -12524,10 +13074,10 @@
1252413074 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1252513075 "") +
1252613076
12527
- // display shadow only (bump == 0)
13077
+ // display shadow only (fakedepth == 0)
1252813078 "SUB temp.x, half.x, shadow.x;" +
1252913079 "MOV temp.y, -params5.z;" + // params6.x;" +
12530
- "SLT temp.z, temp.y, -one2048th.x;" +
13080
+ "SLT temp.z, temp.y, -c256i.x;" +
1253113081 "SUB temp.y, one.x, temp.z;" +
1253213082 "MUL temp.x, temp.x, temp.y;" +
1253313083 "KIL temp.x;" +
....@@ -12858,6 +13408,13 @@
1285813408 //once = true;
1285913409 }
1286013410
13411
+ String program = programmax;
13412
+
13413
+ if (Globals.MINSHADER)
13414
+ {
13415
+ program = programmin;
13416
+ }
13417
+
1286113418 System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1286213419 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1286313420 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
....@@ -12951,25 +13508,26 @@
1295113508 return out;
1295213509 }
1295313510
12954
- String TextureFetch(String dest, String src, String unit)
13511
+ // Also does frustum culling
13512
+ String ShadowTextureFetch(String dest, String src, String unit)
1295513513 {
1295613514 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1295713515 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1295813516 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13517
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13518
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1295913519 "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;" +
13520
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13521
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1296413522 //"SWZ buffer, temp, w,w,w,w;";
12965
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13523
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1296613524 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1296713525 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1296813526 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
12969
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13527
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1297013528
12971
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
12972
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13529
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13530
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1297313531 }
1297413532
1297513533 String Shadow(String depth, String shadow)
....@@ -13016,7 +13574,7 @@
1301613574 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1301713575 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1301813576
13019
- // No shadow when out of frustrum
13577
+ // No shadow when out of frustum
1302013578 "SGE temp.x, " + depth + ".z, one.z;" +
1302113579 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1302213580 "";
....@@ -13164,7 +13722,8 @@
1316413722 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1316513723 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1316613724 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13167
- Object3D.cVector2[] vector2buffer;
13725
+
13726
+ //Object3D.cVector2[] vector2buffer;
1316813727
1316913728 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1317013729 // OUT : diff, spec
....@@ -13180,9 +13739,10 @@
1318013739 "DP3 " + dest + ".z," + "normals," + "eye;" +
1318113740 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1318213741 //"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;" +
13742
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13743
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13744
+
13745
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1318613746 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1318713747 "RCP " + dest + ".w," + dest + ".w;" +
1318813748 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13687,6 +14247,7 @@
1368714247 else
1368814248 if (evt.getSource() == AAtimer)
1368914249 {
14250
+ Globals.TIMERRUNNING = false;
1369014251 if (mouseDown)
1369114252 {
1369214253 //new Exception().printStackTrace();
....@@ -13746,7 +14307,7 @@
1374614307
1374714308 // fev 2014???
1374814309 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13749
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14310
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1375014311 pingthread.StepToTarget(true); // true);
1375114312 }
1375214313 // if (!LIVE)
....@@ -13761,6 +14322,7 @@
1376114322 return;
1376214323
1376314324 AAtimer.restart(); //
14325
+ Globals.TIMERRUNNING = true;
1376414326
1376514327 // waslive = LIVE;
1376614328 // LIVE = false;
....@@ -13810,14 +14372,15 @@
1381014372 drag = false;
1381114373 //System.out.println("Mouse DOWN");
1381214374 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);
14375
+ //ClickInfo info = new ClickInfo();
14376
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14377
+ object.clickInfo.pane = this;
14378
+ object.clickInfo.camera = renderCamera;
14379
+ object.clickInfo.x = x;
14380
+ object.clickInfo.y = y;
14381
+ object.clickInfo.modifiers = modifiersex;
14382
+ editObj = object.doEditClick(//info,
14383
+ 0);
1382114384 if (!editObj)
1382214385 {
1382314386 hasMarquee = true;
....@@ -13833,6 +14396,8 @@
1383314396
1383414397 public void mouseDragged(MouseEvent e)
1383514398 {
14399
+ Globals.MOUSEDRAGGED = true;
14400
+
1383614401 //System.out.println("mouseDragged: " + e);
1383714402 if (isRenderer)
1383814403 movingcamera = true;
....@@ -14097,12 +14662,12 @@
1409714662 void GoDown(int mod)
1409814663 {
1409914664 MODIFIERS |= COMMAND;
14100
- /*
14665
+ /**/
1410114666 if((mod&SHIFT) == SHIFT)
14102
- manipCamera.RotatePosition(0, -speed);
14667
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
1410314668 else
14104
- manipCamera.BackForth(0, -speed*delta, getWidth());
14105
- */
14669
+ manipCamera.RotatePosition(0, -speed);
14670
+ /**/
1410614671 if ((mod & SHIFT) == SHIFT)
1410714672 {
1410814673 mouseMode = mouseMode; // VR??
....@@ -14118,12 +14683,12 @@
1411814683 void GoUp(int mod)
1411914684 {
1412014685 MODIFIERS |= COMMAND;
14121
- /*
14686
+ /**/
1412214687 if((mod&SHIFT) == SHIFT)
14123
- manipCamera.RotatePosition(0, speed);
14688
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
1412414689 else
14125
- manipCamera.BackForth(0, speed*delta, getWidth());
14126
- */
14690
+ manipCamera.RotatePosition(0, speed);
14691
+ /**/
1412714692 if ((mod & SHIFT) == SHIFT)
1412814693 {
1412914694 mouseMode = mouseMode;
....@@ -14139,12 +14704,12 @@
1413914704 void GoLeft(int mod)
1414014705 {
1414114706 MODIFIERS |= COMMAND;
14142
- /*
14707
+ /**/
1414314708 if((mod&SHIFT) == SHIFT)
14144
- manipCamera.RotatePosition(speed, 0);
14145
- else
1414614709 manipCamera.Translate(speed*delta, 0, getWidth());
14147
- */
14710
+ else
14711
+ manipCamera.RotatePosition(speed, 0);
14712
+ /**/
1414814713 if ((mod & SHIFT) == SHIFT)
1414914714 {
1415014715 mouseMode = mouseMode;
....@@ -14160,12 +14725,12 @@
1416014725 void GoRight(int mod)
1416114726 {
1416214727 MODIFIERS |= COMMAND;
14163
- /*
14728
+ /**/
1416414729 if((mod&SHIFT) == SHIFT)
14165
- manipCamera.RotatePosition(-speed, 0);
14166
- else
1416714730 manipCamera.Translate(-speed*delta, 0, getWidth());
14168
- */
14731
+ else
14732
+ manipCamera.RotatePosition(-speed, 0);
14733
+ /**/
1416914734 if ((mod & SHIFT) == SHIFT)
1417014735 {
1417114736 mouseMode = mouseMode;
....@@ -14215,14 +14780,16 @@
1421514780 if (editObj)
1421614781 {
1421714782 drag = true;
14218
- ClickInfo info = new ClickInfo();
14219
- info.bounds.setBounds(0, 0,
14783
+ //ClickInfo info = new ClickInfo();
14784
+ object.clickInfo.bounds.setBounds(0, 0,
1422014785 (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);
14786
+ object.clickInfo.pane = this;
14787
+ object.clickInfo.camera = renderCamera;
14788
+ object.clickInfo.x = x;
14789
+ object.clickInfo.y = y;
14790
+ object //.GetWindow().copy
14791
+ .doEditDrag(//info,
14792
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1422614793 } else
1422714794 {
1422814795 if (x < startX)
....@@ -14371,22 +14938,27 @@
1437114938 }
1437214939 }
1437314940
14941
+// ClickInfo clickInfo = new ClickInfo();
14942
+
1437414943 public void mouseMoved(MouseEvent e)
1437514944 {
1437614945 //System.out.println("mouseMoved: " + e);
1437714946 if (isRenderer)
1437814947 return;
1437914948
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;
14949
+ // Mouse cursor feedback
14950
+ object.clickInfo.x = e.getX();
14951
+ object.clickInfo.y = e.getY();
14952
+ object.clickInfo.modifiers = e.getModifiersEx();
14953
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14954
+ object.clickInfo.pane = this;
14955
+ object.clickInfo.camera = renderCamera;
1438714956 if (!isRenderer)
1438814957 {
14389
- if (object.editWindow.copy.doEditClick(ci, 0))
14958
+ //ObjEditor editWindow = object.editWindow;
14959
+ //Object3D copy = editWindow.copy;
14960
+ if (object.doEditClick(//clickInfo,
14961
+ 0))
1439014962 {
1439114963 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1439214964 } else
....@@ -14398,8 +14970,11 @@
1439814970
1439914971 public void mouseReleased(MouseEvent e)
1440014972 {
14973
+ Globals.MOUSEDRAGGED = false;
14974
+
1440114975 movingcamera = false;
14402
- X = Y = 0;
14976
+ X = 0; // getBounds().width/2;
14977
+ Y = 0; // getBounds().height/2;
1440314978 //System.out.println("mouseReleased: " + e);
1440414979 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1440514980 }
....@@ -14655,7 +15230,8 @@
1465515230 // break;
1465615231 case 'T':
1465715232 CACHETEXTURE ^= true;
14658
- textures.clear();
15233
+ texturepigment.clear();
15234
+ texturebump.clear();
1465915235 // repaint();
1466015236 break;
1466115237 case 'Y':
....@@ -14740,7 +15316,9 @@
1474015316 case 'E' : COMPACT ^= true;
1474115317 repaint();
1474215318 break;
14743
- case 'W' : DEBUGHSB ^= true;
15319
+ case 'W' : // Wide Window (fullscreen)
15320
+ //DEBUGHSB ^= true;
15321
+ ObjEditor.theFrame.ToggleFullScreen();
1474415322 repaint();
1474515323 break;
1474615324 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14765,8 +15343,8 @@
1476515343 RevertCamera();
1476615344 repaint();
1476715345 break;
14768
- case 'L':
1476915346 case 'l':
15347
+ //case 'L':
1477015348 if (lightMode)
1477115349 {
1477215350 lightMode = false;
....@@ -14830,20 +15408,24 @@
1483015408 OCCLUSION_CULLING ^= true;
1483115409 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1483215410 break;
14833
- case '0': envyoff ^= true; repaint(); break;
15411
+ //case '0': envyoff ^= true; repaint(); break;
1483415412 case '1':
1483515413 case '2':
1483615414 case '3':
1483715415 case '4':
1483815416 case '5':
14839
- newenvy = Character.getNumericValue(key);
14840
- repaint();
14841
- break;
1484215417 case '6':
1484315418 case '7':
1484415419 case '8':
1484515420 case '9':
14846
- BGcolor = (key - '6')/3.f;
15421
+ if (true) // envyoff)
15422
+ {
15423
+ BGcolor = (key - '1')/8.f;
15424
+ }
15425
+ else
15426
+ {
15427
+ //newenvy = Character.getNumericValue(key);
15428
+ }
1484715429 repaint();
1484815430 break;
1484915431 case '!':
....@@ -14909,9 +15491,9 @@
1490915491 case '_':
1491015492 kompactbit = 5;
1491115493 break;
14912
- case '+':
14913
- kompactbit = 6;
14914
- break;
15494
+// case '+':
15495
+// kompactbit = 6;
15496
+// break;
1491515497 case ' ':
1491615498 lightMode ^= true;
1491715499 Globals.lighttouched = true;
....@@ -14923,6 +15505,7 @@
1492315505 case ESC:
1492415506 RENDERPROGRAM += 1;
1492515507 RENDERPROGRAM %= 3;
15508
+
1492615509 repaint();
1492715510 break;
1492815511 case 'Z':
....@@ -14962,8 +15545,9 @@
1496215545 case DELETE:
1496315546 ClearSelection();
1496415547 break;
14965
- /*
1496615548 case '+':
15549
+
15550
+ /*
1496715551 //fontsize += 1;
1496815552 bbzoom *= 2;
1496915553 repaint();
....@@ -14980,17 +15564,17 @@
1498015564 case '=':
1498115565 IncDepth();
1498215566 //fontsize += 1;
14983
- object.editWindow.refreshContents(true);
15567
+ object.GetWindow().refreshContents(true);
1498415568 maskbit = 6;
1498515569 break;
1498615570 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1498715571 DecDepth();
1498815572 maskbit = 5;
1498915573 //if(fontsize > 1) fontsize -= 1;
14990
- if (object.editWindow == null)
14991
- new Exception().printStackTrace();
14992
- else
14993
- object.editWindow.refreshContents(true);
15574
+// if (object.editWindow == null)
15575
+// new Exception().printStackTrace();
15576
+// else
15577
+ object.GetWindow().refreshContents(true);
1499415578 break;
1499515579 case '{':
1499615580 manipCamera.shaper_fovy /= 1.1;
....@@ -15214,7 +15798,7 @@
1521415798 }
1521515799 */
1521615800
15217
- object.editWindow.EditSelection();
15801
+ object.GetWindow().EditSelection(false);
1521815802 }
1521915803
1522015804 void SelectParent()
....@@ -15231,10 +15815,10 @@
1523115815 {
1523215816 //selectees.remove(i);
1523315817 System.out.println("select parent of " + elem);
15234
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15818
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1523515819 } else
1523615820 {
15237
- group.editWindow.Select(elem.GetTreePath(), first, true);
15821
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1523815822 }
1523915823
1524015824 first = false;
....@@ -15276,12 +15860,12 @@
1527615860 for (int j = 0; j < group.children.size(); j++)
1527715861 {
1527815862 elem = (Object3D) group.children.elementAt(j);
15279
- object.editWindow.Select(elem.GetTreePath(), first, true);
15863
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1528015864 first = false;
1528115865 }
1528215866 } else
1528315867 {
15284
- object.editWindow.Select(elem.GetTreePath(), first, true);
15868
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1528515869 }
1528615870
1528715871 first = false;
....@@ -15292,21 +15876,21 @@
1529215876 {
1529315877 //Composite group = (Composite) object;
1529415878 Object3D group = object;
15295
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15879
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1529615880 }
1529715881
1529815882 void ResetTransform(int mask)
1529915883 {
1530015884 //Composite group = (Composite) object;
1530115885 Object3D group = object;
15302
- group.editWindow.ResetTransform(mask);
15886
+ group.GetWindow().ResetTransform(mask);
1530315887 }
1530415888
1530515889 void FlipTransform()
1530615890 {
1530715891 //Composite group = (Composite) object;
1530815892 Object3D group = object;
15309
- group.editWindow.FlipTransform();
15893
+ group.GetWindow().FlipTransform();
1531015894 // group.editWindow.ReduceMesh(true);
1531115895 }
1531215896
....@@ -15314,7 +15898,7 @@
1531415898 {
1531515899 //Composite group = (Composite) object;
1531615900 Object3D group = object;
15317
- group.editWindow.PrintMemory();
15901
+ group.GetWindow().PrintMemory();
1531815902 // group.editWindow.ReduceMesh(true);
1531915903 }
1532015904
....@@ -15322,7 +15906,7 @@
1532215906 {
1532315907 //Composite group = (Composite) object;
1532415908 Object3D group = object;
15325
- group.editWindow.ResetCentroid();
15909
+ group.GetWindow().ResetCentroid();
1532615910 }
1532715911
1532815912 void IncDepth()
....@@ -15404,8 +15988,6 @@
1540415988
1540515989 int width = getBounds().width;
1540615990 int height = getBounds().height;
15407
- ClickInfo info = new ClickInfo();
15408
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1540915991 //Image img = CreateImage(width, height);
1541015992 //System.out.println("width = " + width + "; height = " + height + "\n");
1541115993
....@@ -15482,43 +16064,77 @@
1548216064 }
1548316065 if (object != null && !hasMarquee)
1548416066 {
16067
+ if (object.clickInfo == null)
16068
+ object.clickInfo = new ClickInfo();
16069
+ ClickInfo info = object.clickInfo;
16070
+ //ClickInfo info = new ClickInfo();
16071
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16072
+
1548516073 if (isRenderer)
1548616074 {
15487
- info.flags++;
16075
+ object.clickInfo.flags++;
1548816076 double frameAspect = (double) width / (double) height;
1548916077 if (frameAspect > renderCamera.aspect)
1549016078 {
1549116079 int desired = (int) ((double) height * renderCamera.aspect);
15492
- info.bounds.width -= width - desired;
15493
- info.bounds.x += (width - desired) / 2;
16080
+ object.clickInfo.bounds.width -= width - desired;
16081
+ object.clickInfo.bounds.x += (width - desired) / 2;
1549416082 } else
1549516083 {
1549616084 int desired = (int) ((double) width / renderCamera.aspect);
15497
- info.bounds.height -= height - desired;
15498
- info.bounds.y += (height - desired) / 2;
16085
+ object.clickInfo.bounds.height -= height - desired;
16086
+ object.clickInfo.bounds.y += (height - desired) / 2;
1549916087 }
1550016088 }
15501
- info.g = gr;
15502
- info.camera = renderCamera;
16089
+
16090
+ object.clickInfo.g = gr;
16091
+ object.clickInfo.camera = renderCamera;
1550316092 /*
1550416093 // Memory intensive (brep.verticescopy)
1550516094 if (!(object instanceof Composite))
1550616095 object.draw(info, 0, false); // SLOW :
1550716096 */
15508
- if (!isRenderer)
16097
+ if (!isRenderer) // && drag)
1550916098 {
15510
- object.drawEditHandles(info, 0);
15511
-
15512
- if (drag && (X != 0 || Y != 0) && object.selection.Size() > 0)
16099
+ Grafreed.Assert(object != null);
16100
+ Grafreed.Assert(object.selection != null);
16101
+ if (object.selection.Size() > 0)
1551316102 {
15514
- switch (object.selection.get(0).hitSomething)
16103
+ int hitSomething = object.selection.get(0).hitSomething;
16104
+
16105
+ object.clickInfo.DX = 0;
16106
+ object.clickInfo.DY = 0;
16107
+ object.clickInfo.W = 1;
16108
+ if (hitSomething == Object3D.hitCenter)
1551516109 {
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;
16110
+ info.DX = X;
16111
+ if (X != 0)
16112
+ info.DX -= info.bounds.width/2;
16113
+
16114
+ info.DY = Y;
16115
+ if (Y != 0)
16116
+ info.DY -= info.bounds.height/2;
1551916117 }
15520
-
15521
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16118
+
16119
+ object.drawEditHandles(//info,
16120
+ 0);
16121
+
16122
+ if (drag && (X != 0 || Y != 0))
16123
+ {
16124
+ switch (hitSomething)
16125
+ {
16126
+ case Object3D.hitCenter: gr.setColor(Color.pink);
16127
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16128
+ break;
16129
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16130
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16131
+ break;
16132
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16133
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16134
+ break;
16135
+ }
16136
+
16137
+ }
1552216138 }
1552316139 }
1552416140 }
....@@ -16000,6 +16616,8 @@
1600016616 private /*static*/ boolean firstime;
1600116617 private /*static*/ cVector newView = new cVector();
1600216618 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16619
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16620
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1600316621 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1600416622 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1600516623 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16012,29 +16630,67 @@
1601216630 {
1601316631 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1601416632
16633
+ int usedsuf = 0;
16634
+
1601516635 for (int i = 0; i < suffixes.length; i++)
1601616636 {
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)
16637
+ String[] suffixe = suffixes;
16638
+ String[] fallback = suffixes2;
16639
+ String[] fallfallback = suffixes3;
16640
+
16641
+ for (int c=usedsuf; --c>=0;)
1602216642 {
16023
- throw new IOException("Unable to load texture " + resourceName);
16643
+// String[] temp = suffixe;
16644
+// suffixe = fallback;
16645
+// fallback = fallfallback;
16646
+// fallfallback = temp;
1602416647 }
16648
+
16649
+ String resourceName = basename + suffixe[i] + "." + suffix;
16650
+ TextureData data;
16651
+
16652
+ try
16653
+ {
16654
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16655
+ mipmapped,
16656
+ FileUtil.getFileSuffix(resourceName));
16657
+ }
16658
+ catch (Exception e)
16659
+ {
16660
+ try
16661
+ {
16662
+ resourceName = basename + fallback[i] + "." + suffix;
16663
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16664
+ mipmapped,
16665
+ FileUtil.getFileSuffix(resourceName));
16666
+ }
16667
+ catch (Exception e2)
16668
+ {
16669
+ resourceName = basename + fallfallback[i] + "." + suffix;
16670
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16671
+ mipmapped,
16672
+ FileUtil.getFileSuffix(resourceName));
16673
+ }
16674
+ }
16675
+
1602516676 //System.out.println("Target = " + targets[i]);
1602616677 cubemap.updateImage(data, targets[i]);
1602716678 }
1602816679
1602916680 return cubemap;
1603016681 }
16682
+
1603116683 int bigsphere = -1;
1603216684
1603316685 float BGcolor = 0.5f;
1603416686
16035
- private void DrawSkyBox(GL gl)
16687
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16688
+
16689
+ private void DrawSkyBox(GL gl, float ratio)
1603616690 {
16037
- if (envyoff || cubemap == null)
16691
+ if (//envyoff ||
16692
+ WIREFRAME ||
16693
+ cubemap == null)
1603816694 {
1603916695 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1604016696 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16049,7 +16705,17 @@
1604916705 // Compensates for ExaminerViewer's modification of modelview matrix
1605016706 gl.glMatrixMode(GL.GL_MODELVIEW);
1605116707 gl.glLoadIdentity();
16708
+ gl.glScalef(1,ratio,1);
1605216709
16710
+// colorV[0] = 2;
16711
+// colorV[1] = 2;
16712
+// colorV[2] = 2;
16713
+// colorV[3] = 1;
16714
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16715
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16716
+//
16717
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16718
+
1605316719 //gl.glActiveTexture(GL.GL_TEXTURE1);
1605416720 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1605516721
....@@ -16081,6 +16747,7 @@
1608116747 {
1608216748 gl.glScalef(1.0f, -1.0f, 1.0f);
1608316749 }
16750
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1608416751 gl.glMultMatrixd(viewrot_1, 0);
1608516752 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1608616753 //viewer.updateInverseRotation(gl);
....@@ -16221,16 +16888,16 @@
1622116888 cStatic.objectstack[materialdepth++] = checker;
1622216889 //System.out.println("material " + material);
1622316890 //Applet3D.tracein(this, selected);
16224
- vector2buffer = checker.projectedVertices;
16891
+ //vector2buffer = checker.projectedVertices;
1622516892
1622616893 //checker.GetMaterial().Draw(this, false); // true);
16227
- DrawMaterial(checker.GetMaterial(), false); // true);
16894
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1622816895
1622916896 materialdepth -= 1;
1623016897 if (materialdepth > 0)
1623116898 {
16232
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16233
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
16899
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16900
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1623416901 }
1623516902 //checker.GetMaterial().opacity = 1f;
1623616903 ////checker.GetMaterial().ambient = 1f;
....@@ -16316,6 +16983,14 @@
1631616983 }
1631716984 }
1631816985
16986
+ private Object3D GetFolder()
16987
+ {
16988
+ Object3D folder = object.GetWindow().copy;
16989
+ if (object.GetWindow().copy.selection.Size() > 0)
16990
+ folder = object.GetWindow().copy.selection.elementAt(0);
16991
+ return folder;
16992
+ }
16993
+
1631916994 class SelectBuffer implements GLEventListener
1632016995 {
1632116996
....@@ -16331,7 +17006,7 @@
1633117006 //new Exception().printStackTrace();
1633217007 System.out.println("select buffer init");
1633317008 // Use debug pipeline
16334
- drawable.setGL(new DebugGL(drawable.getGL()));
17009
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1633517010
1633617011 GL gl = drawable.getGL();
1633717012
....@@ -16395,6 +17070,17 @@
1639517070
1639617071 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1639717072
17073
+ if (PAINTMODE)
17074
+ {
17075
+ if (object.GetWindow().copy.selection.Size() > 0)
17076
+ {
17077
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17078
+
17079
+ // Make what you paint not selectable.
17080
+ paintobj.ResetSelectable();
17081
+ }
17082
+ }
17083
+
1639817084 //int tmp = selection_view;
1639917085 //selection_view = -1;
1640017086 int temp = DrawMode();
....@@ -16406,6 +17092,17 @@
1640617092 // temp = DEFAULT; // patch for selection debug
1640717093 Globals.drawMode = temp; // WARNING
1640817094
17095
+ if (PAINTMODE)
17096
+ {
17097
+ if (object.GetWindow().copy.selection.Size() > 0)
17098
+ {
17099
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17100
+
17101
+ // Revert.
17102
+ paintobj.RestoreSelectable();
17103
+ }
17104
+ }
17105
+
1640917106 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1641017107
1641117108 // trying different ways of getting the depth info over
....@@ -16453,6 +17150,8 @@
1645317150 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1645417151 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1645517152 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
17153
+
17154
+ CreateSelectedPoint();
1645617155
1645717156 // Will fit the mesh !!!
1645817157 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16507,29 +17206,31 @@
1650717206 }
1650817207
1650917208 if (!movingcamera && !PAINTMODE)
16510
- object.editWindow.ScreenFitPoint(); // fev 2014
17209
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1651117210
16512
- if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17211
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1651317212 {
16514
- Object3D paintobj = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17213
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1651517214
16516
- Object3D group = new Object3D("inst" + paintcount++);
17215
+ if (object.GetWindow().copy.selection.Size() > 0)
17216
+ {
17217
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1651717218
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();
17219
+ Object3D inst = new Object3D("inst" + paintcount++);
17220
+
17221
+ inst.CreateMaterial(); // use a void leaf to select instances
17222
+
17223
+ inst.add(paintobj); // link
17224
+
17225
+ object.GetWindow().SnapObject(inst);
17226
+
17227
+ Object3D folder = paintFolder; // GetFolder();
17228
+
17229
+ folder.add(inst);
17230
+
17231
+ object.GetWindow().ResetModel();
17232
+ object.GetWindow().refreshContents();
17233
+ }
1653317234 }
1653417235 else
1653517236 paintcount = 0;
....@@ -16568,6 +17269,11 @@
1656817269 //System.out.println("objects[color] = " + objects[color]);
1656917270 //objects[color].Select();
1657017271 indexcount = 0;
17272
+ ObjEditor window = object.GetWindow();
17273
+ if (window != null && deselect)
17274
+ {
17275
+ window.Select(null, deselect, true);
17276
+ }
1657117277 object.Select(color, deselect);
1657217278 }
1657317279
....@@ -16846,10 +17552,14 @@
1684617552 gl.glFlush();
1684717553
1684817554 /**/
16849
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17555
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1685017556
16851
- float[] pixels = occlusionsizebuffer.array();
17557
+ float[] depths = occlusiondepthbuffer.array();
1685217558
17559
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17560
+
17561
+ int[] pixels = selectsizebuffer.array();
17562
+
1685317563 double r = 0, g = 0, b = 0;
1685417564
1685517565 double count = 0;
....@@ -16860,7 +17570,7 @@
1686017570
1686117571 double FACTOR = 1;
1686217572
16863
- for (int i = 0; i < pixels.length; i++)
17573
+ for (int i = 0; i < depths.length; i++)
1686417574 {
1686517575 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1686617576 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -16943,7 +17653,7 @@
1694317653
1694417654 double scale = ray.z; // 1; // cos
1694517655
16946
- float depth = pixels[newindex];
17656
+ float depth = depths[newindex];
1694717657
1694817658 /*
1694917659 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -17093,23 +17803,15 @@
1709317803 int AAbuffersize = 0;
1709417804
1709517805 //double[] selectedpoint = new double[3];
17096
- static Superellipsoid selectedpoint = new Superellipsoid();
17806
+ static Superellipsoid selectedpoint;
1709717807 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();
17808
+ static Sphere debugpointG;
17809
+ static Sphere debugpointP;
17810
+ static Sphere debugpointC;
17811
+ static Sphere debugpointR;
1710217812
1710317813 static Sphere debugpoints[] = new Sphere[8];
1710417814
17105
- static
17106
- {
17107
- for (int i=0; i<8; i++)
17108
- {
17109
- debugpoints[i] = new Sphere();
17110
- }
17111
- }
17112
-
1711317815 static void InitPoints(float radius)
1711417816 {
1711517817 for (int i=0; i<8; i++)
....@@ -17148,11 +17850,14 @@
1714817850 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1714917851 static IntBuffer bigAAbuffer;
1715017852 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
17151
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17853
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1715217854 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1715317855 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1715417856 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17155
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17857
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17858
+
17859
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17860
+
1715617861 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1715717862 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1715817863 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();