Normand Briere
2019-08-26 6266c8a4b2485b29a7d5bcb217460d7aad3e1c4a
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,11 @@
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;
116
+ boolean transformMode;
117
+
78118 boolean reverseUP = false;
79119 static boolean frozen = false;
80120 boolean enablebackspace = false; // patch for back buffer refresh
....@@ -128,7 +168,7 @@
128168
129169
130170 // OPTIONS
131
- boolean Skinshader = true;
171
+ boolean Skinshader = false; // true;
132172 boolean cameraLight = false;
133173 boolean UVdebug = false;
134174 boolean Udebug = false;
....@@ -137,7 +177,7 @@
137177 static boolean doublesided = false; // true; // reversed normals are awful for conformance
138178 boolean anisotropy = true;
139179 boolean softshadow = true; // slower but better false;
140
- boolean opacityhalo = false;
180
+ boolean opacityhalo = false; // reverse the halo effect (e.g. glass)
141181
142182 boolean macromode = false;
143183
....@@ -151,6 +191,19 @@
151191 }
152192
153193 private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
194
+
195
+ public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException
196
+ {
197
+ try
198
+ {
199
+ return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
200
+ } catch (IOException e)
201
+ {
202
+ System.out.println("NAME = " + name);
203
+ e.printStackTrace(); // throw new RuntimeException(e);
204
+ return null;
205
+ }
206
+ }
154207
155208 void SetAsGLRenderer(boolean b)
156209 {
....@@ -170,7 +223,8 @@
170223
171224 SetCamera(cam);
172225
173
- SetLight(new Camera(new cVector(10, 10, -20)));
226
+ // Warning: not used.
227
+ SetLight(new Camera(new cVector(15, 10, -20)));
174228
175229 object = o;
176230
....@@ -327,7 +381,7 @@
327381 cStatic.objectstack[materialdepth++] = obj;
328382 //System.out.println("material " + material);
329383 //Applet3D.tracein(this, selected);
330
- display.vector2buffer = obj.projectedVertices;
384
+ //display.vector2buffer = obj.projectedVertices;
331385 if (obj instanceof Camera)
332386 {
333387 display.options1[0] = material.shift;
....@@ -336,14 +390,28 @@
336390 display.options1[2] = material.shadowbias;
337391 display.options1[3] = material.aniso;
338392 display.options1[4] = material.anisoV;
393
+// System.out.println("display.options1[0] " + display.options1[0]);
394
+// System.out.println("display.options1[1] " + display.options1[1]);
395
+// System.out.println("display.options1[2] " + display.options1[2]);
396
+// System.out.println("display.options1[3] " + display.options1[3]);
397
+// System.out.println("display.options1[4] " + display.options1[4]);
339398 display.options2[0] = material.opacity;
340399 display.options2[1] = material.diffuse;
341400 display.options2[2] = material.factor;
401
+// System.out.println("display.options2[0] " + display.options2[0]);
402
+// System.out.println("display.options2[1] " + display.options2[1]);
403
+// System.out.println("display.options2[2] " + display.options2[2]);
342404
343405 cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
406
+// System.out.println("display.options3[0] " + display.options3[0]);
407
+// System.out.println("display.options3[1] " + display.options3[1]);
408
+// System.out.println("display.options3[2] " + display.options3[2]);
344409 display.options4[0] = material.cameralight/0.2f;
345410 display.options4[1] = material.subsurface;
346411 display.options4[2] = material.sheen;
412
+// System.out.println("display.options4[0] " + display.options4[0]);
413
+// System.out.println("display.options4[1] " + display.options4[1]);
414
+// System.out.println("display.options4[2] " + display.options4[2]);
347415
348416 // if (display.CURRENTANTIALIAS > 0)
349417 // display.options3[3] /= 4;
....@@ -359,7 +427,7 @@
359427 /**/
360428 } else
361429 {
362
- DrawMaterial(material, selected);
430
+ DrawMaterial(material, selected, obj.projectedVertices);
363431 }
364432 } else
365433 {
....@@ -383,8 +451,8 @@
383451 cStatic.objectstack[materialdepth++] = obj;
384452 //System.out.println("material " + material);
385453 //Applet3D.tracein("selected ", selected);
386
- display.vector2buffer = obj.projectedVertices;
387
- display.DrawMaterial(material, selected);
454
+ //display.vector2buffer = obj.projectedVertices;
455
+ display.DrawMaterial(material, selected, obj.projectedVertices);
388456 }
389457 }
390458
....@@ -401,8 +469,8 @@
401469 materialdepth -= 1;
402470 if (materialdepth > 0)
403471 {
404
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
405
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
472
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
473
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
406474 }
407475 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
408476 } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
....@@ -422,8 +490,8 @@
422490 materialdepth -= 1;
423491 if (materialdepth > 0)
424492 {
425
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
426
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
493
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
494
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
427495 }
428496 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
429497 //else
....@@ -464,15 +532,18 @@
464532 if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
465533 {
466534 //gl.glBegin(gl.GL_TRIANGLES);
467
- boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0);
535
+ boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0)
536
+ // TEST LIVE NORMALS && !obj.dontselect
537
+ ;
468538 if (!hasnorm)
469539 {
470
- // System.out.println("FUCK!!");
540
+ // System.out.println("Mesh normal");
471541 LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
472542 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
473543 LA.vecCross(obj.v0, obj.v1, obj.v2);
474544 LA.vecNormalize(obj.v2);
475
- gl.glNormal3f((float) obj.v2.x, (float) obj.v2.y, (float) obj.v2.z);
545
+
546
+ SetGLNormal(gl, (float) obj.v2.x, (float) obj.v2.y, (float) obj.v2.z);
476547 }
477548
478549 // P
....@@ -494,7 +565,7 @@
494565 y += ny * obj.NORMALPUSH;
495566 z += nz * obj.NORMALPUSH;
496567
497
- gl.glNormal3f(nx, ny, nz);
568
+ SetGLNormal(gl, nx, ny, nz);
498569 }
499570 gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
500571 SetColor(obj, pv);
....@@ -526,7 +597,7 @@
526597 y += ny * obj.NORMALPUSH;
527598 z += nz * obj.NORMALPUSH;
528599
529
- gl.glNormal3f(nx, ny, nz);
600
+ SetGLNormal(gl, nx, ny, nz);
530601 }
531602 //System.out.println("vertexq = " + qv.s + ", " + qv.t);
532603 // boolean locked = false;
....@@ -574,7 +645,7 @@
574645 y += ny * obj.NORMALPUSH;
575646 z += nz * obj.NORMALPUSH;
576647
577
- gl.glNormal3f(nx, ny, nz);
648
+ SetGLNormal(gl, nx, ny, nz);
578649 }
579650
580651 // if ((dot&4) == 0)
....@@ -810,7 +881,7 @@
810881 //// tris.postdraw(this);
811882 }
812883
813
- static Camera localcamera = new Camera();
884
+ static Camera localAOcamera = new Camera();
814885 static cVector from = new cVector();
815886 static cVector to = new cVector();
816887
....@@ -819,7 +890,7 @@
819890 CameraPane cp = this;
820891
821892 Camera keep = cp.RenderCamera();
822
- cp.renderCamera = localcamera;
893
+ cp.renderCamera = localAOcamera;
823894
824895 if (br.trimmed)
825896 {
....@@ -837,7 +908,7 @@
837908 br.positions[i3 + 2] + br.normals[i3 + 2]);
838909 LA.xformPos(from, transform, from);
839910 LA.xformPos(to, transform, to); // RIGID ONLY
840
- localcamera.setAim(from, to);
911
+ localAOcamera.setAim(from, to);
841912
842913 CameraPane.occlusionbuffer.display();
843914
....@@ -871,7 +942,7 @@
871942 to.set(v.x+v.norm.x, v.y+v.norm.y, v.z+v.norm.z);
872943 LA.xformPos(from, transform, from);
873944 LA.xformPos(to, transform, to); // RIGID ONLY
874
- localcamera.setAim(from, to);
945
+ localAOcamera.setAim(from, to);
875946
876947 CameraPane.occlusionbuffer.display();
877948
....@@ -1180,10 +1251,10 @@
11801251 {
11811252 if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
11821253 {
1183
- gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1254
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
11841255 } else
11851256 {
1186
- gl.glNormal3f(0, 0, 1);
1257
+ SetGLNormal(gl, 0, 0, 1);
11871258 }
11881259
11891260 if (c != null)
....@@ -1192,10 +1263,12 @@
11921263 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
11931264 }
11941265 }
1266
+
11951267 if (flipV)
11961268 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
11971269 else
11981270 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1271
+
11991272 //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
12001273 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
12011274
....@@ -1205,20 +1278,22 @@
12051278 {
12061279 if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
12071280 {
1208
- gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1281
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
12091282 } else
12101283 {
1211
- gl.glNormal3f(0, 0, 1);
1284
+ SetGLNormal(gl, 0, 0, 1);
12121285 }
12131286 if (c != null)
12141287 {
12151288 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
12161289 }
12171290 }
1291
+
12181292 if (flipV)
12191293 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12201294 else
12211295 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1296
+
12221297 //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
12231298 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
12241299
....@@ -1231,10 +1306,10 @@
12311306 {
12321307 if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
12331308 {
1234
- gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1309
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
12351310 } else
12361311 {
1237
- gl.glNormal3f(0, 0, 1);
1312
+ SetGLNormal(gl, 0, 0, 1);
12381313 }
12391314 if (c != null)
12401315 {
....@@ -1246,8 +1321,10 @@
12461321 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12471322 else
12481323 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1324
+
12491325 //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
12501326 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1327
+
12511328 count2 += 2;
12521329 count3 += 3;
12531330 }
....@@ -1414,7 +1491,7 @@
14141491 {
14151492 if (!selectmode)
14161493 {
1417
- gl.glNormal3f((float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
1494
+ SetGLNormal(gl, (float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
14181495 gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
14191496
14201497 if (flipV)
....@@ -1426,6 +1503,8 @@
14261503 gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
14271504 }
14281505
1506
+ float[] colorV = new float[4];
1507
+
14291508 void SetColor(Object3D obj, Vertex p0)
14301509 {
14311510 CameraPane display = this;
....@@ -1493,8 +1572,6 @@
14931572 {
14941573 return;
14951574 }
1496
-
1497
- float[] colorV = new float[3];
14981575
14991576 if (false) // marked)
15001577 {
....@@ -1603,7 +1680,7 @@
16031680 // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
16041681 }
16051682
1606
- void DrawMaterial(cMaterial material, boolean selected)
1683
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
16071684 {
16081685 CameraPane display = this;
16091686 //new Exception().printStackTrace();
....@@ -1638,7 +1715,7 @@
16381715 colorV[0] = display.modelParams0[0] * material.diffuse;
16391716 colorV[1] = display.modelParams0[1] * material.diffuse;
16401717 colorV[2] = display.modelParams0[2] * material.diffuse;
1641
- colorV[3] = material.opacity;
1718
+ colorV[3] = 1; // material.opacity;
16421719
16431720 gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
16441721 //System.out.println("Opacity = " + opacity);
....@@ -1743,12 +1820,12 @@
17431820
17441821 display.modelParams7[0] = 0;
17451822 display.modelParams7[1] = 1000;
1746
- display.modelParams7[2] = 0;
1823
+ display.modelParams7[2] = material.parallax;
17471824 display.modelParams7[3] = 0;
17481825
1749
- display.modelParams6[0] = 100; // criss de bug de bump
1826
+ //display.modelParams6[0] = 100; // criss de bug de bump
17501827
1751
- Object3D.cVector2[] extparams = display.vector2buffer;
1828
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
17521829 if (extparams != null && extparams.length > 0 && extparams[0] != null)
17531830 {
17541831 display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
....@@ -1976,9 +2053,9 @@
19762053 switch(viewcode)
19772054 {
19782055 case 0: return "main";
1979
- case 1: return "one";
1980
- case 2: return "two";
1981
- case 3: return "three";
2056
+ case 1: return "Red";
2057
+ case 2: return "Green";
2058
+ case 3: return "Blue";
19822059 case 4: return "light";
19832060 }
19842061
....@@ -2044,7 +2121,7 @@
20442121 //System.err.println("Oeil on");
20452122 OEIL = true;
20462123 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2047
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2124
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
20482125 //pingthread.StepToTarget(true);
20492126 }
20502127
....@@ -2259,7 +2336,7 @@
22592336
22602337 void ToggleDebug()
22612338 {
2262
- DEBUG ^= true;
2339
+ Globals.DEBUG ^= true;
22632340 }
22642341
22652342 void ToggleLookAt()
....@@ -2277,10 +2354,17 @@
22772354 HANDLES ^= true;
22782355 }
22792356
2357
+ Object3D paintFolder;
2358
+
22802359 void TogglePaint()
22812360 {
22822361 PAINTMODE ^= true;
22832362 paintcount = 0;
2363
+
2364
+ if (PAINTMODE)
2365
+ {
2366
+ paintFolder = GetFolder();
2367
+ }
22842368 }
22852369
22862370 void SwapCamera(int a, int b)
....@@ -2377,6 +2461,33 @@
23772461 return currentGL;
23782462 }
23792463
2464
+ static private BufferedImage CreateBim(TextureData texturedata)
2465
+ {
2466
+ Grafreed.Assert(texturedata != null);
2467
+
2468
+ int width = texturedata.getWidth();
2469
+ int height = texturedata.getHeight();
2470
+
2471
+ Buffer buffer = texturedata.getBuffer();
2472
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2473
+
2474
+ byte[] bytes = bytebuf.array();
2475
+
2476
+ return CreateBim(bytes, width, height);
2477
+ }
2478
+
2479
+ private void SetGLNormal(javax.media.opengl.GL gl, float nx, float ny, float nz)
2480
+ {
2481
+ gl.glNormal3f(nx, ny, nz);
2482
+
2483
+ if (ny > 0.9 || ny < -0.9)
2484
+ // Ground or ceiling
2485
+ gl.glVertexAttrib3f(4, 1, 0, 0);
2486
+ else
2487
+ // Walls
2488
+ gl.glVertexAttrib3f(4, 0, 1, 0);
2489
+ }
2490
+
23802491 /**/
23812492 class CacheTexture
23822493 {
....@@ -2385,28 +2496,31 @@
23852496
23862497 int resolution;
23872498
2388
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2499
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
23892500 {
2390
- texture = tex;
2501
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2502
+ texturedata = texdata;
23912503 resolution = res;
23922504 }
23932505 }
23942506 /**/
23952507
23962508 // 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>();
2509
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2510
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2511
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2512
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2513
+
24002514 int pigmentdepth = 0;
24012515 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
24022516 int bumpdepth = 0;
24032517 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
24042518 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
24052519 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2406
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2520
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
24072521 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
24082522
2409
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2523
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
24102524 {
24112525 TextureData texturedata = null;
24122526
....@@ -2416,7 +2530,7 @@
24162530 com.sun.opengl.util.texture.TextureIO.newTextureData(
24172531 getClass().getClassLoader().getResourceAsStream(name),
24182532 true,
2419
- com.sun.opengl.util.texture.TextureIO.PNG);
2533
+ GetFormat(name)); // com.sun.opengl.util.texture.TextureIO.PNG);
24202534 } catch (java.io.IOException e)
24212535 {
24222536 throw new javax.media.opengl.GLException(e);
....@@ -2425,13 +2539,34 @@
24252539 if (bump)
24262540 texturedata = ConvertBump(texturedata, false);
24272541
2428
- com.sun.opengl.util.texture.Texture texture =
2429
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2542
+// com.sun.opengl.util.texture.Texture texture =
2543
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
24302544
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);
2545
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2546
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
24332547
2434
- return texture;
2548
+ return texturedata;
2549
+ }
2550
+
2551
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2552
+ {
2553
+ TextureData texturedata = null;
2554
+
2555
+ try
2556
+ {
2557
+ texturedata =
2558
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2559
+ bim,
2560
+ true);
2561
+ } catch (Exception e)
2562
+ {
2563
+ throw new javax.media.opengl.GLException(e);
2564
+ }
2565
+
2566
+ if (bump)
2567
+ texturedata = ConvertBump(texturedata, false);
2568
+
2569
+ return texturedata;
24352570 }
24362571
24372572 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3504,6 +3639,8 @@
35043639
35053640 System.out.println("LOADING TEXTURE : " + name);
35063641
3642
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3643
+
35073644 //
35083645 if (false) // compressbit > 0)
35093646 {
....@@ -7902,7 +8039,7 @@
79028039 String pigment = Object3D.GetPigment(tex);
79038040 String bump = Object3D.GetBump(tex);
79048041
7905
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8042
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79068043 {
79078044 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79088045 // System.out.println("; bump = " + bump);
....@@ -7917,8 +8054,8 @@
79178054 pigment = null;
79188055 }
79198056
7920
- ReleaseTexture(bump, true);
7921
- ReleaseTexture(pigment, false);
8057
+ ReleaseTexture(tex, true);
8058
+ ReleaseTexture(tex, false);
79228059 }
79238060
79248061 public void ReleasePigmentTexture(cTexture tex) // INTERFACE
....@@ -7936,7 +8073,7 @@
79368073
79378074 String pigment = Object3D.GetPigment(tex);
79388075
7939
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8076
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79408077 {
79418078 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79428079 // System.out.println("; bump = " + bump);
....@@ -7947,7 +8084,7 @@
79478084 pigment = null;
79488085 }
79498086
7950
- ReleaseTexture(pigment, false);
8087
+ ReleaseTexture(tex, false);
79518088 }
79528089
79538090 public void ReleaseBumpTexture(cTexture tex) // INTERFACE
....@@ -7965,7 +8102,7 @@
79658102
79668103 String bump = Object3D.GetBump(tex);
79678104
7968
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8105
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79698106 {
79708107 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79718108 // System.out.println("; bump = " + bump);
....@@ -7976,10 +8113,10 @@
79768113 bump = null;
79778114 }
79788115
7979
- ReleaseTexture(bump, true);
8116
+ ReleaseTexture(tex, true);
79808117 }
79818118
7982
- void ReleaseTexture(String tex, boolean bump)
8119
+ void ReleaseTexture(cTexture tex, boolean bump)
79838120 {
79848121 if (// DrawMode() != 0 || /*tex == null ||*/
79858122 ambientOcclusion ) // || !textureon)
....@@ -7990,7 +8127,7 @@
79908127 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
79918128
79928129 if (tex != null)
7993
- texture = textures.get(tex);
8130
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
79948131
79958132 // //assert( texture != null );
79968133 // if (texture == null)
....@@ -8084,47 +8221,50 @@
80848221
80858222 /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
80868223 {
8087
- if (// DrawMode() != 0 || /*tex == null ||*/
8088
- ambientOcclusion ) // || !textureon)
8089
- {
8090
- return; // false;
8091
- }
8092
-
8093
- if (tex == null)
8094
- {
8095
- BindTexture(null,false,resolution);
8096
- BindTexture(null,true,resolution);
8097
- return;
8098
- }
8224
+// if (// DrawMode() != 0 || /*tex == null ||*/
8225
+// ambientOcclusion ) // || !textureon)
8226
+// {
8227
+// return; // false;
8228
+// }
8229
+//
8230
+// if (tex == null)
8231
+// {
8232
+// BindTexture(null,false,resolution);
8233
+// BindTexture(null,true,resolution);
8234
+// return;
8235
+// }
8236
+//
8237
+// String pigment = Object3D.GetPigment(tex);
8238
+// String bump = Object3D.GetBump(tex);
8239
+//
8240
+// usedtextures.add(pigment);
8241
+// usedtextures.add(bump);
8242
+//
8243
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8244
+// {
8245
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8246
+// // System.out.println("; bump = " + bump);
8247
+// }
8248
+//
8249
+// if (bump.equals(""))
8250
+// {
8251
+// bump = null;
8252
+// }
8253
+// if (pigment.equals(""))
8254
+// {
8255
+// pigment = null;
8256
+// }
8257
+//
8258
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8259
+// BindTexture(pigment, false, resolution);
8260
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8261
+// BindTexture(bump, true, resolution);
8262
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8263
+//
8264
+// return; // true;
80998265
8100
- String pigment = Object3D.GetPigment(tex);
8101
- String bump = Object3D.GetBump(tex);
8102
-
8103
- usedtextures.put(pigment, pigment);
8104
- usedtextures.put(bump, bump);
8105
-
8106
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8107
- {
8108
- // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8109
- // System.out.println("; bump = " + bump);
8110
- }
8111
-
8112
- if (bump.equals(""))
8113
- {
8114
- bump = null;
8115
- }
8116
- if (pigment.equals(""))
8117
- {
8118
- pigment = null;
8119
- }
8120
-
8121
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8122
- BindTexture(pigment, false, resolution);
8123
- GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8124
- BindTexture(bump, true, resolution);
8125
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8126
-
8127
- return; // true;
8266
+ BindPigmentTexture(tex, resolution);
8267
+ BindBumpTexture(tex, resolution);
81288268 }
81298269
81308270 /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8143,9 +8283,9 @@
81438283
81448284 String pigment = Object3D.GetPigment(tex);
81458285
8146
- usedtextures.put(pigment, pigment);
8286
+ usedtextures.add(tex);
81478287
8148
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8288
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
81498289 {
81508290 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
81518291 // System.out.println("; bump = " + bump);
....@@ -8157,7 +8297,7 @@
81578297 }
81588298
81598299 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8160
- BindTexture(pigment, false, resolution);
8300
+ BindTexture(tex, false, resolution);
81618301 }
81628302
81638303 /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8176,9 +8316,9 @@
81768316
81778317 String bump = Object3D.GetBump(tex);
81788318
8179
- usedtextures.put(bump, bump);
8319
+ usedtextures.add(tex);
81808320
8181
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8321
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
81828322 {
81838323 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
81848324 // System.out.println("; bump = " + bump);
....@@ -8190,7 +8330,7 @@
81908330 }
81918331
81928332 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8193
- BindTexture(bump, true, resolution);
8333
+ BindTexture(tex, true, resolution);
81948334 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
81958335 }
81968336
....@@ -8214,13 +8354,19 @@
82148354 return fileExists;
82158355 }
82168356
8217
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception
8357
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
82188358 {
8219
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8359
+ CacheTexture texturecache = null;
82208360
82218361 if (tex != null)
82228362 {
8223
- String texname = tex;
8363
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8364
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
8365
+
8366
+ if (texname.equals("") && texdata == null)
8367
+ {
8368
+ return null;
8369
+ }
82248370
82258371 String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
82268372
....@@ -8230,19 +8376,46 @@
82308376 // else
82318377 // if (!texname.startsWith("/"))
82328378 // texname = "/Users/nbriere/Textures/" + texname;
8233
- if (!FileExists(tex))
8379
+ if (!FileExists(texname) && !texname.startsWith("@"))
82348380 {
82358381 texname = fallbackTextureName;
82368382 }
82378383
82388384 if (CACHETEXTURE)
8239
- texture = textures.get(texname); // TEXTURE CACHE
8240
-
8241
- TextureData texturedata = null;
8242
-
8243
- if (texture == null || texture.resolution < resolution)
82448385 {
8245
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8386
+ if (texdata == null)
8387
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8388
+ else
8389
+ texturecache = bimtextures.get(texdata);
8390
+ }
8391
+
8392
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8393
+ {
8394
+ TextureData texturedata = null;
8395
+
8396
+ if (texdata != null && textureon)
8397
+ {
8398
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8399
+
8400
+ try
8401
+ {
8402
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8403
+ }
8404
+ catch (Exception e)
8405
+ {
8406
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8407
+ }
8408
+
8409
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8410
+ bimtextures.put(texdata, texturecache);
8411
+
8412
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8413
+
8414
+ //Object bim2 = CreateBim(texturecache.texturedata);
8415
+ //bim2 = bim;
8416
+ }
8417
+ else
8418
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
82468419 {
82478420 assert(!bump);
82488421 // if (bump)
....@@ -8253,19 +8426,23 @@
82538426 // }
82548427 // else
82558428 // {
8256
- texture = textures.get(tex);
8257
- if (texture == null)
8429
+ // texturecache = textures.get(texname); // suspicious
8430
+ if (texturecache == null)
82588431 {
8259
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8432
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
82608433 }
8434
+ else
8435
+ new Exception().printStackTrace();
82618436 // }
82628437 } else
8263
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8438
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
82648439 {
82658440 assert(bump);
8266
- texture = textures.get(tex);
8267
- if (texture == null)
8268
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8441
+ // texturecache = textures.get(texname); // suspicious
8442
+ if (texturecache == null)
8443
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8444
+ else
8445
+ new Exception().printStackTrace();
82698446 } else
82708447 {
82718448 //if (tex.equals("IMMORTAL"))
....@@ -8273,11 +8450,22 @@
82738450 // texture = GetResourceTexture("default.png");
82748451 //} else
82758452 //{
8276
- if (tex.equals("WHITE_NOISE"))
8453
+ if (texname.endsWith("WHITE_NOISE"))
82778454 {
8278
- texture = textures.get(tex);
8279
- if (texture == null)
8280
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8455
+ // texturecache = textures.get(texname); // suspicious
8456
+ if (texturecache == null)
8457
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8458
+ else
8459
+ new Exception().printStackTrace();
8460
+ } else
8461
+ {
8462
+ if (texname.startsWith("@"))
8463
+ {
8464
+ // texturecache = textures.get(texname); // suspicious
8465
+ if (texturecache == null)
8466
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8467
+ else
8468
+ new Exception().printStackTrace();
82818469 } else
82828470 {
82838471 if (textureon)
....@@ -8336,19 +8524,20 @@
83368524 if (texturedata == null)
83378525 throw new Exception();
83388526
8339
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8527
+ texturecache = new CacheTexture(texturedata,resolution);
83408528 //texture = GetTexture(tex, bump);
83418529 }
8530
+ }
83428531 }
83438532 //}
83448533 }
83458534
8346
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8535
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
83478536 {
83488537 //return false;
83498538
83508539 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8351
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8540
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
83528541 {
83538542 // String ext = "_highres";
83548543 // if (REDUCETEXTURE)
....@@ -8365,52 +8554,17 @@
83658554 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
83668555 if (!cachefile.exists())
83678556 {
8368
- // cache to disk
8369
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
8370
- //buffers[0].
8371
-
8372
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
8373
- int[] pixels = new int[bytebuf.capacity()/3];
8374
-
8375
- // squared size heuristic...
8376
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8557
+ //if (texturedata.getWidth() == texturedata.getHeight())
83778558 {
8378
- for (int i=pixels.length; --i>=0;)
8379
- {
8380
- int i3 = i*3;
8381
- pixels[i] = 0xFF;
8382
- pixels[i] <<= 8;
8383
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
8384
- pixels[i] <<= 8;
8385
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
8386
- pixels[i] <<= 8;
8387
- pixels[i] |= bytebuf.get(i3) & 0xFF;
8388
- }
8389
-
8390
- /*
8391
- int r=0,g=0,b=0,a=0;
8392
- for (int i=0; i<width; i++)
8393
- for (int j=0; j<height; j++)
8394
- {
8395
- int index = j*width+i;
8396
- int p = pixels[index];
8397
- a = ((p>>24) & 0xFF);
8398
- r = ((p>>16) & 0xFF);
8399
- g = ((p>>8) & 0xFF);
8400
- b = (p & 0xFF);
8401
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
8402
- }
8403
- /**/
8404
- int width = (int)Math.sqrt(pixels.length); // squared
8405
- int height = width;
8406
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
8407
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8559
+ BufferedImage rendImage = CreateBim(texturedata);
8560
+
84088561 ImageWriter writer = null;
84098562 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
84108563 if (iter.hasNext()) {
84118564 writer = (ImageWriter)iter.next();
84128565 }
8413
- float compressionQuality = 0.9f;
8566
+
8567
+ float compressionQuality = 0.85f;
84148568 try
84158569 {
84168570 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8427,18 +8581,20 @@
84278581 }
84288582 }
84298583 }
8430
-
8584
+
8585
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8586
+
84318587 //System.out.println("Texture = " + tex);
8432
- if (textures.containsKey(texname))
8588
+ if (textures.containsKey(tex))
84338589 {
8434
- CacheTexture thetex = textures.get(texname);
8590
+ CacheTexture thetex = textures.get(tex);
84358591 thetex.texture.disable();
84368592 thetex.texture.dispose();
8437
- textures.remove(texname);
8593
+ textures.remove(tex);
84388594 }
84398595
8440
- texture.texturedata = texturedata;
8441
- textures.put(texname, texture);
8596
+ //texture.texturedata = texturedata;
8597
+ textures.put(tex, texturecache);
84428598
84438599 // newtex = true;
84448600 }
....@@ -8454,10 +8610,44 @@
84548610 }
84558611 }
84568612
8457
- return texture;
8613
+ return texturecache;
84588614 }
84598615
8460
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution) throws Exception
8616
+ static void EmbedTextures(cTexture tex)
8617
+ {
8618
+ if (tex.pigmentdata == null)
8619
+ {
8620
+ //String texname = Object3D.GetPigment(tex);
8621
+
8622
+ CacheTexture texturecache = texturepigment.get(tex);
8623
+
8624
+ if (texturecache != null)
8625
+ {
8626
+ tex.pw = texturecache.texturedata.getWidth();
8627
+ tex.ph = texturecache.texturedata.getHeight();
8628
+ tex.pigmentdata = //CompressJPEG(CreateBim
8629
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8630
+ ;
8631
+ //, tex.pw, tex.ph), 0.5f);
8632
+ }
8633
+ }
8634
+
8635
+ if (tex.bumpdata == null)
8636
+ {
8637
+ //String texname = Object3D.GetBump(tex);
8638
+
8639
+ CacheTexture texturecache = texturebump.get(tex);
8640
+
8641
+ if (texturecache != null)
8642
+ {
8643
+ tex.bw = texturecache.texturedata.getWidth();
8644
+ tex.bh = texturecache.texturedata.getHeight();
8645
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8646
+ }
8647
+ }
8648
+ }
8649
+
8650
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
84618651 {
84628652 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
84638653
....@@ -8475,21 +8665,21 @@
84758665 return texture!=null?texture.texture:null;
84768666 }
84778667
8478
- public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution) throws Exception
8668
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
84798669 {
84808670 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
84818671
84828672 return texture!=null?texture.texturedata:null;
84838673 }
84848674
8485
- boolean BindTexture(String tex, boolean bump, int resolution) throws Exception
8675
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
84868676 {
84878677 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
84888678 {
84898679 return false;
84908680 }
84918681
8492
- boolean newtex = false;
8682
+ //boolean newtex = false;
84938683
84948684 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
84958685
....@@ -8521,9 +8711,75 @@
85218711 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
85228712 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
85238713
8524
- return newtex;
8714
+ return true; // Warning: not used.
85258715 }
85268716
8717
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8718
+ {
8719
+ try
8720
+ {
8721
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8722
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8723
+ ImageWriter writer = writers.next();
8724
+
8725
+ ImageWriteParam param = writer.getDefaultWriteParam();
8726
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8727
+ param.setCompressionQuality(quality);
8728
+
8729
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8730
+ writer.setOutput(ios);
8731
+ writer.write(null, new IIOImage(image, null, null), param);
8732
+
8733
+ byte[] data = baos.toByteArray();
8734
+ writer.dispose();
8735
+ return data;
8736
+ }
8737
+ catch (Exception e)
8738
+ {
8739
+ e.printStackTrace();
8740
+ return null;
8741
+ }
8742
+ }
8743
+
8744
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8745
+ {
8746
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8747
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8748
+ ImageReader reader = writers.next();
8749
+
8750
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8751
+
8752
+ ImageReadParam param = reader.getDefaultReadParam();
8753
+ param.setDestination(bim);
8754
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8755
+
8756
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8757
+ reader.setInput(ios);
8758
+ BufferedImage bim2 = reader.read(0, param);
8759
+ reader.dispose();
8760
+
8761
+// WritableRaster raster = bim2.getRaster();
8762
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8763
+// byte[] bytes = data.getData();
8764
+//
8765
+// int[] pixels = new int[bytes.length/3];
8766
+// for (int i=pixels.length; --i>=0;)
8767
+// {
8768
+// int i3 = i*3;
8769
+// pixels[i] = 0xFF;
8770
+// pixels[i] <<= 8;
8771
+// pixels[i] |= bytes[i3+2] & 0xFF;
8772
+// pixels[i] <<= 8;
8773
+// pixels[i] |= bytes[i3+1] & 0xFF;
8774
+// pixels[i] <<= 8;
8775
+// pixels[i] |= bytes[i3] & 0xFF;
8776
+// }
8777
+//
8778
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8779
+
8780
+ return bim;
8781
+ }
8782
+
85278783 ShadowBuffer shadowPBuf;
85288784 AntialiasBuffer antialiasPBuf;
85298785 int MAXSTACK;
....@@ -8540,10 +8796,12 @@
85408796
85418797 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
85428798 MAXSTACK = temp[0];
8543
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8799
+ if (Globals.DEBUG)
8800
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
85448801 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
85458802 MAXSTACK = temp[0];
8546
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8803
+ if (Globals.DEBUG)
8804
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
85478805
85488806 // Use debug pipeline
85498807 //drawable.setGL(new DebugGL(gl)); //
....@@ -8551,7 +8809,8 @@
85518809 gl = drawable.getGL(); //
85528810
85538811 GL gl3 = getGL();
8554
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8812
+ if (Globals.DEBUG)
8813
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
85558814
85568815
85578816 //float pos[] = { 100, 100, 100, 0 };
....@@ -8716,7 +8975,7 @@
87168975
87178976 if (cubemap == null)
87188977 {
8719
- LoadEnvy(5);
8978
+ //LoadEnvy(1);
87208979 }
87218980
87228981 //cubemap.enable();
....@@ -8992,6 +9251,8 @@
89929251
89939252 void LoadEnvy(int which)
89949253 {
9254
+ assert(false);
9255
+
89959256 String name;
89969257 String ext;
89979258
....@@ -9003,37 +9264,58 @@
90039264 cubemap = null;
90049265 return;
90059266 case 1:
9006
- name = "cubemaps/box_";
9007
- ext = "png";
9267
+ name = "cubemaps/rgb/";
9268
+ ext = "jpg";
90089269 reverseUP = false;
90099270 break;
90109271 case 2:
9011
- name = "cubemaps/uffizi_";
9012
- ext = "png";
9013
- break; // reverseUP = true; break;
9272
+ name = "cubemaps/uffizi/";
9273
+ ext = "jpg";
9274
+ reverseUP = false;
9275
+ break;
90149276 case 3:
9015
- name = "cubemaps/CloudyHills_";
9016
- ext = "tga";
9277
+ name = "cubemaps/CloudyHills/";
9278
+ ext = "jpg";
90179279 reverseUP = false;
90189280 break;
90199281 case 4:
9020
- name = "cubemaps/cornell_";
9282
+ name = "cubemaps/cornell/";
90219283 ext = "png";
90229284 reverseUP = false;
90239285 break;
9286
+ case 5:
9287
+ name = "cubemaps/skycube/";
9288
+ ext = "jpg";
9289
+ reverseUP = false;
9290
+ break;
9291
+ case 6:
9292
+ name = "cubemaps/SaintLazarusChurch3/";
9293
+ ext = "jpg";
9294
+ reverseUP = false;
9295
+ break;
9296
+ case 7:
9297
+ name = "cubemaps/Sodermalmsallen/";
9298
+ ext = "jpg";
9299
+ reverseUP = false;
9300
+ break;
9301
+ case 8:
9302
+ name = "cubemaps/Sodermalmsallen2/";
9303
+ ext = "jpg";
9304
+ reverseUP = false;
9305
+ break;
9306
+ case 9:
9307
+ name = "cubemaps/UnionSquare/";
9308
+ ext = "jpg";
9309
+ reverseUP = false;
9310
+ break;
90249311 default:
9025
- name = "cubemaps/rgb_";
9026
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9312
+ name = "cubemaps/box/";
9313
+ ext = "png"; /*mipmap = true;*/
9314
+ reverseUP = false;
90279315 break;
90289316 }
9029
-
9030
- try
9031
- {
9032
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
9033
- } catch (IOException e)
9034
- {
9035
- throw new RuntimeException(e);
9036
- }
9317
+
9318
+ LoadSkybox(name, ext, mipmap);
90379319 }
90389320
90399321 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -9065,8 +9347,12 @@
90659347 static double[] model = new double[16];
90669348 double[] camera2light = new double[16];
90679349 double[] light2camera = new double[16];
9068
- int newenvy = -1;
9069
- boolean envyoff = true; // false;
9350
+
9351
+ //int newenvy = -1;
9352
+ //boolean envyoff = false;
9353
+
9354
+ String loadedskyboxname;
9355
+
90709356 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
90719357 //float[] light0 = { 0,0,0 };
90729358 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9359,11 +9645,35 @@
93599645 jy8[3] = 0.5f;
93609646 }
93619647
9362
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9648
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
93639649 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
93649650 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
93659651 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
93669652
9653
+ void ResetOptions()
9654
+ {
9655
+ options1[0] = 100;
9656
+ options1[1] = 0.025f;
9657
+ options1[2] = 0.01f;
9658
+ options1[3] = 0;
9659
+ options1[4] = 0;
9660
+
9661
+ options2[0] = 0;
9662
+ options2[1] = 0.75f;
9663
+ options2[2] = 0;
9664
+ options2[3] = 0;
9665
+
9666
+ options3[0] = 1;
9667
+ options3[1] = 1;
9668
+ options3[2] = 1;
9669
+ options3[3] = 0;
9670
+
9671
+ options4[0] = 1;
9672
+ options4[1] = 0;
9673
+ options4[2] = 1;
9674
+ options4[3] = 0;
9675
+ }
9676
+
93679677 static int imagecount = 0; // movie generation
93689678
93699679 static int jitter = 0;
....@@ -9460,7 +9770,7 @@
94609770
94619771 if (renderCamera != lightCamera)
94629772 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9463
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
9773
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
94649774
94659775 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
94669776
....@@ -9476,7 +9786,7 @@
94769786
94779787 if (renderCamera != lightCamera)
94789788 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9479
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
9789
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
94809790
94819791 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
94829792
....@@ -9522,10 +9832,12 @@
95229832 rati = 1 / rati;
95239833 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
95249834 }
9525
- assert (newenvy == -1);
9835
+
9836
+ //assert (newenvy == -1);
9837
+
95269838 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
95279839 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9528
- DrawSkyBox(gl);
9840
+ DrawSkyBox(gl, (float)rati);
95299841 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
95309842 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
95319843 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10391,9 +10703,18 @@
1039110703 static boolean init = false;
1039210704
1039310705 double[][] matrix = LA.newMatrix();
10706
+
10707
+ // This is to refresh the UI of the material panel.
10708
+ ObjEditor patchMaterial;
1039410709
1039510710 public void display(GLAutoDrawable drawable)
1039610711 {
10712
+ if (patchMaterial.patchMaterial)
10713
+ {
10714
+ patchMaterial.patchMaterial = false;
10715
+ patchMaterial.objectPanel.setSelectedIndex(1);
10716
+ }
10717
+
1039710718 if (Grafreed.savesound && Grafreed.hassound)
1039810719 {
1039910720 Grafreed.wav.save();
....@@ -10474,6 +10795,7 @@
1047410795 ANTIALIAS = 0;
1047510796 //System.out.println("RESTART");
1047610797 AAtimer.restart();
10798
+ Globals.TIMERRUNNING = true;
1047710799 }
1047810800 }
1047910801 }
....@@ -10541,7 +10863,8 @@
1054110863 ambientOcclusion = false;
1054210864 }
1054310865
10544
- if (Globals.lighttouched && DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
10866
+ if (//Globals.lighttouched &&
10867
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1054510868 {
1054610869 //if (RENDERSHADOW) // ?
1054710870 if (!IsFrozen())
....@@ -10560,7 +10883,7 @@
1056010883
1056110884 if (wait)
1056210885 {
10563
- Sleep(500);
10886
+ Sleep(200); // blocks everything
1056410887
1056510888 wait = false;
1056610889 }
....@@ -10675,7 +10998,7 @@
1067510998 // if (parentcam != renderCamera) // not a light
1067610999 if (cam != lightCamera)
1067711000 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10678
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
11001
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1067911002
1068011003 for (int j = 0; j < 4; j++)
1068111004 {
....@@ -10690,7 +11013,7 @@
1069011013 // if (parentcam != renderCamera) // not a light
1069111014 if (cam != lightCamera)
1069211015 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10693
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
11016
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1069411017
1069511018 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1069611019
....@@ -10776,13 +11099,43 @@
1077611099 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1077711100 }
1077811101
10779
- if (newenvy > -1)
11102
+// if (newenvy > -1)
11103
+// {
11104
+// LoadEnvy(newenvy);
11105
+// }
11106
+//
11107
+// newenvy = -1;
11108
+
11109
+ if (transformMode) // object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
1078011110 {
10781
- LoadEnvy(newenvy);
11111
+ if (cubemaprgb == null)
11112
+ {
11113
+ cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb2" + "/", "jpg", false);
11114
+ }
11115
+
11116
+ cubemap = cubemaprgb;
1078211117 }
10783
-
10784
- newenvy = -1;
10785
-
11118
+ else
11119
+ {
11120
+ if (object.skyboxname != null)
11121
+ {
11122
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11123
+ {
11124
+ if (cubemap != null && cubemap != cubemaprgb)
11125
+ cubemap.dispose();
11126
+ cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11127
+ loadedskyboxname = object.skyboxname;
11128
+ }
11129
+ }
11130
+ else
11131
+ {
11132
+ cubemapcustom = null;
11133
+ loadedskyboxname = null;
11134
+ }
11135
+
11136
+ cubemap = cubemapcustom;
11137
+ }
11138
+
1078611139 ratio = ((double) getWidth()) / getHeight();
1078711140 //System.out.println("ratio = " + ratio);
1078811141
....@@ -10798,7 +11151,7 @@
1079811151
1079911152 if (!IsFrozen() && !ambientOcclusion)
1080011153 {
10801
- DrawSkyBox(gl);
11154
+ DrawSkyBox(gl, (float)ratio);
1080211155 }
1080311156
1080411157 //if (selection_view == -1)
....@@ -10981,9 +11334,9 @@
1098111334
1098211335 gl.glMatrixMode(GL.GL_MODELVIEW);
1098311336
10984
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10985
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10986
-//gl.glEnable(gl.GL_MULTISAMPLE);
11337
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11338
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11339
+gl.glEnable(gl.GL_MULTISAMPLE);
1098711340 } else
1098811341 {
1098911342 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -10994,7 +11347,7 @@
1099411347 //System.out.println("BLENDING ON");
1099511348 gl.glEnable(GL.GL_BLEND);
1099611349 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
10997
-
11350
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1099811351 gl.glMatrixMode(gl.GL_PROJECTION);
1099911352 gl.glLoadIdentity();
1100011353
....@@ -11084,7 +11437,7 @@
1108411437
1108511438 // if (cam != lightCamera)
1108611439 //for (int count = parentcam.GetTransformCount(); --count>=0;)
11087
- LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
11440
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1108811441 }
1108911442
1109011443 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -11243,7 +11596,7 @@
1124311596 }
1124411597 }
1124511598
11246
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11599
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1124711600 {
1124811601 //gl.glDepthFunc(GL.GL_LEQUAL);
1124911602 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11251,24 +11604,21 @@
1125111604
1125211605 boolean texon = textureon;
1125311606
11254
- if (RENDERPROGRAM > 0)
11255
- {
11256
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11257
- textureon = false;
11258
- }
11607
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11608
+ textureon = false;
11609
+
1125911610 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1126011611 //System.out.println("ALLO");
1126111612 gl.glColorMask(false, false, false, false);
1126211613 DrawObject(gl);
11263
- if (RENDERPROGRAM > 0)
11264
- {
11265
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11266
- textureon = texon;
11267
- }
11614
+
11615
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11616
+ textureon = texon;
11617
+
1126811618 gl.glColorMask(true, true, true, true);
1126911619
1127011620 gl.glDepthFunc(GL.GL_EQUAL);
11271
- //gl.glDepthMask(false);
11621
+ gl.glDepthMask(false);
1127211622 }
1127311623
1127411624 if (false) // DrawMode() == SHADOW)
....@@ -11451,15 +11801,36 @@
1145111801
1145211802 static boolean zoomonce = false;
1145311803
11804
+ static void CreateSelectedPoint()
11805
+ {
11806
+ if (selectedpoint == null)
11807
+ {
11808
+ debugpointG = new Sphere();
11809
+ debugpointP = new Sphere();
11810
+ debugpointC = new Sphere();
11811
+ debugpointR = new Sphere();
11812
+
11813
+ selectedpoint = new Superellipsoid();
11814
+
11815
+ for (int i=0; i<8; i++)
11816
+ {
11817
+ debugpoints[i] = new Sphere();
11818
+ }
11819
+ }
11820
+ }
11821
+
1145411822 void DrawObject(GL gl, boolean draw)
1145511823 {
11824
+ // To clear camera values
11825
+ ResetOptions();
11826
+
1145611827 //System.out.println("DRAW OBJECT " + mouseDown);
1145711828 // DrawMode() = SELECTION;
1145811829 //GL gl = getGL();
1145911830 if ((TRACK || SHADOWTRACK) || zoomonce)
1146011831 {
1146111832 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11462
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11833
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1146311834 pingthread.StepToTarget(true); // true);
1146411835 // zoomonce = false;
1146511836 }
....@@ -11531,8 +11902,9 @@
1153111902
1153211903 if (DrawMode() == DEFAULT)
1153311904 {
11534
- if (DEBUG)
11905
+ if (Globals.DEBUG)
1153511906 {
11907
+ CreateSelectedPoint();
1153611908 float radius = 0.05f;
1153711909 if (selectedpoint.radius != radius)
1153811910 {
....@@ -11586,20 +11958,32 @@
1158611958 ReleaseTextures(DEFAULT_TEXTURES);
1158711959
1158811960 if (CLEANCACHE)
11589
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11961
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1159011962 {
11591
- String tex = e.nextElement();
11963
+ cTexture tex = e.nextElement();
1159211964
1159311965 // System.out.println("Texture --------- " + tex);
1159411966
11595
- if (tex.equals("WHITE_NOISE"))
11967
+ if (tex.equals("WHITE_NOISE:"))
1159611968 continue;
1159711969
11598
- if (!usedtextures.containsKey(tex))
11970
+ if (!usedtextures.contains(tex))
1159911971 {
11972
+ CacheTexture gettex = texturepigment.get(tex);
1160011973 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11601
- textures.get(tex).texture.dispose();
11602
- textures.remove(tex);
11974
+ if (gettex != null)
11975
+ {
11976
+ gettex.texture.dispose();
11977
+ texturepigment.remove(tex);
11978
+ }
11979
+
11980
+ gettex = texturebump.get(tex);
11981
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11982
+ if (gettex != null)
11983
+ {
11984
+ gettex.texture.dispose();
11985
+ texturebump.remove(tex);
11986
+ }
1160311987 }
1160411988 }
1160511989 }
....@@ -12019,7 +12403,7 @@
1201912403 for (int i = tp.size(); --i >= 0;)
1202012404 {
1202112405 //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12022
- LA.xformPos(light, tp.get(i).GlobalTransform(), light);
12406
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1202312407 }
1202412408
1202512409
....@@ -12127,8 +12511,82 @@
1212712511
1212812512 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1212912513
12130
- String program =
12514
+ String programmin =
12515
+ // Min shader
1213112516 "!!ARBfp1.0\n" +
12517
+ "PARAM zero12t = { 0.0, 1.0, 2, 1.25 };" +
12518
+ "PARAM pow_2 = { 0.5, 0.25, 0.125, 0.0 };" +
12519
+ "PARAM pow2 = { 2, 4, 8, 0.0 };" +
12520
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12521
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12522
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12523
+ "PARAM light2cam0 = program.env[10];" +
12524
+ "PARAM light2cam1 = program.env[11];" +
12525
+ "PARAM light2cam2 = program.env[12];" +
12526
+ "TEMP temp;" +
12527
+ "TEMP light;" +
12528
+ "TEMP ndotl;" +
12529
+ "TEMP normal;" +
12530
+ "TEMP depth;" +
12531
+ "TEMP eye;" +
12532
+ "TEMP pos;" +
12533
+
12534
+ "MAD normal, fragment.color, zero12t.z, -zero12t.y;" +
12535
+ Normalize("normal") +
12536
+ "MOV light, state.light[0].position;" +
12537
+ "DP3 ndotl.x, light, normal;" +
12538
+ "MAX ndotl.x, ndotl.x, zero12t.x;" +
12539
+
12540
+ // shadow
12541
+ "MOV pos, fragment.texcoord[1];" +
12542
+ "MOV temp, pos;" +
12543
+ ShadowTextureFetch("depth", "temp", "1") +
12544
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12545
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12546
+
12547
+ // No shadow when out of frustum
12548
+ //"SGE temp.y, depth.z, zero123.y;" +
12549
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12550
+
12551
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12552
+
12553
+ // Backlit
12554
+ "MOV pos.w, zero12t.y;" + // one
12555
+ "DP4 eye.x, pos, light2cam0;" +
12556
+ "DP4 eye.y, pos, light2cam1;" +
12557
+ "DP4 eye.z, pos, light2cam2;" +
12558
+ Normalize("eye") +
12559
+
12560
+ "DP3 ndotl.y, -eye, normal;" +
12561
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12562
+ "POW ndotl.y, ndotl.y, pow2.x;" + // backlit
12563
+ "SUB ndotl.y, zero12t.y, ndotl.y;" + // 1 - y
12564
+ //"POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12565
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12566
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12567
+ "ADD ndotl.y, ndotl.y, one.x;" +
12568
+ "MUL ndotl.y, ndotl.y, pow_2.x;" +
12569
+
12570
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12571
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12572
+
12573
+ // Pigment
12574
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12575
+ "LRP temp, zero12t.w, temp, one;" + // texture proportion
12576
+ "MUL temp, temp, zero12t.w;" + // Times x
12577
+
12578
+ //"MUL temp, temp, ndotl.y;" +
12579
+ "MAD ndotl.x, pow_2.xxxx, ndotl.yyyy, ndotl.x;" +
12580
+
12581
+ "MUL temp, temp, ndotl.x;" + // lambert
12582
+
12583
+ "MOV temp.w, zero12t.y;" + // reset alpha
12584
+ "MOV result.color, temp;" +
12585
+ "END";
12586
+
12587
+ String programmax =
12588
+ "!!ARBfp1.0\n" +
12589
+
1213212590 //"OPTION ARB_fragment_program_shadow;" +
1213312591 "PARAM light2cam0 = program.env[10];" +
1213412592 "PARAM light2cam1 = program.env[11];" +
....@@ -12154,7 +12612,7 @@
1215412612 "PARAM params4 = program.env[4];" + // anisoV, cameralight, selfshadow, shadow
1215512613 "PARAM params5 = program.env[5];" + // texture, opacity, fakedepth, shadowbias
1215612614 "PARAM params6 = program.env[6];" + // bump, noise, borderfade, fog punchthrough
12157
- "PARAM params7 = program.env[7];" + // noise power, opacity power
12615
+ "PARAM params7 = program.env[7];" + // noise power, opacity power, parallax
1215812616 "PARAM options0 = program.env[63];" + // fog density, intensity, elevation
1215912617 "PARAM options1 = program.env[62];" + // fog rgb color
1216012618 "PARAM options2 = program.env[61];" + // image intensity, subsurface, lightsheen
....@@ -12243,8 +12701,7 @@
1224312701 "TEMP shininess;" +
1224412702 "\n" +
1224512703 "MOV texSamp, one;" +
12246
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12247
-
12704
+
1224812705 "MOV mapgrid.x, one2048th.x;" +
1224912706 "MOV temp, fragment.texcoord[1];" +
1225012707 /*
....@@ -12265,20 +12722,20 @@
1226512722 "MUL temp, floor, mapgrid.x;" +
1226612723 //"TEX depth0, temp, texture[1], 2D;" +
1226712724 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12268
- TextureFetch("depth0", "temp", "1") +
12725
+ ShadowTextureFetch("depth0", "temp", "1") +
1226912726 "") +
1227012727 "ADD temp.x, temp.x, mapgrid.x;" +
1227112728 //"TEX depth1, temp, texture[1], 2D;" +
1227212729 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12273
- TextureFetch("depth1", "temp", "1") +
12730
+ ShadowTextureFetch("depth1", "temp", "1") +
1227412731 "") +
1227512732 "ADD temp.y, temp.y, mapgrid.x;" +
1227612733 //"TEX depth2, temp, texture[1], 2D;" +
12277
- TextureFetch("depth2", "temp", "1") +
12734
+ ShadowTextureFetch("depth2", "temp", "1") +
1227812735 "SUB temp.x, temp.x, mapgrid.x;" +
1227912736 //"TEX depth3, temp, texture[1], 2D;" +
1228012737 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12281
- TextureFetch("depth3", "temp", "1") +
12738
+ ShadowTextureFetch("depth3", "temp", "1") +
1228212739 "") +
1228312740 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1228412741 //"MOV params, material;" +
....@@ -12400,7 +12857,7 @@
1240012857 "POW texSamp.a, texSamp.a, params6.w;" + // fog punch through shortcut
1240112858 // mar 2013 ??? "KIL alpha.a;" +
1240212859 "MOV alpha, texSamp.aaaa;" + // y;" +
12403
- "KIL alpha.a;" +
12860
+ "KIL alpha.a;" + // not sure with parallax mapping
1240412861 /*
1240512862 "MUL temp.xy, temp, two;" +
1240612863 "TXB bump, temp, texture[0], 2D;" +
....@@ -12486,11 +12943,6 @@
1248612943 "SUB bump0, bump0, half;" +
1248712944 "ADD bump, bump, bump0;" +
1248812945
12489
- "MOV temp.x, texSamp.a;" +
12490
- "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
12491
- //"LRP texSamp0, params5.x, texSamp0, one;" +
12492
- "MOV texSamp.a, temp.x;" +
12493
-
1249412946 // double-sided
1249512947 /**/
1249612948 (doublesided?"DP3 temp.z, normal, eye;" +
....@@ -12500,26 +12952,73 @@
1250012952 "ADD temp.x, temp.x, one.x;" +
1250112953 "MUL normal, normal, temp.xxxx;":""
1250212954 ) +
12503
- /**/
12504
-//// Normalize("normal") +
12505
-//// "MAX normal.z, eps.x, normal.z;" +
12506
-// Normalize("normal") +
12507
- "MOV normald, normal;" +
12508
- "MOV normals, normal;" +
12955
+ /**/
12956
+
12957
+ "MOV temp, fragment.texcoord[4];" +
1250912958
1251012959 // UV base
1251112960 //"DP3 UP.x,state.matrix.modelview.row[0],Y;" +
1251212961 //"DP3 UP.y,state.matrix.modelview.row[1],Y;" +
1251312962 //"DP3 UP.z,state.matrix.modelview.row[2],Y;" +
12514
- "DP3 UP.x,state.matrix.texture[7].row[0],Y;" +
12515
- "DP3 UP.y,state.matrix.texture[7].row[1],Y;" +
12516
- "DP3 UP.z,state.matrix.texture[7].row[2],Y;" +
12963
+ "DP3 UP.x,state.matrix.texture[7].row[0],temp;" +
12964
+ "DP3 UP.y,state.matrix.texture[7].row[1],temp;" +
12965
+ "DP3 UP.z,state.matrix.texture[7].row[2],temp;" +
12966
+ Normalize("UP") +
12967
+
1251712968 "XPD V, normal, UP;" +
1251812969 Normalize("V") +
1251912970 "XPD U, V, normal;" +
1252012971 Normalize("U") +
1252112972
12973
+ "MOV temp, fragment.texcoord[0];" +
12974
+
12975
+// "MAD normal, -temp.x, U, normal;" +
12976
+// "MAD normal, -temp.y, V, normal;" +
12977
+// Normalize("normal") +
12978
+
12979
+//// "MAX normal.z, eps.x, normal.z;" +
12980
+// Normalize("normal") +
12981
+ "MOV normald, normal;" +
12982
+ "MOV normals, normal;" +
12983
+
1252212984 // parallax mapping
12985
+
12986
+ "DP3 temp2.x, V, eye;" +
12987
+ "DP3 temp2.y, U, eye;" +
12988
+ "DP3 temp2.z, normal, eye;" +
12989
+ "RCP temp2.z, temp2.z;" +
12990
+
12991
+ "DP3 temp2.w, texSamp, texSamp;" + // Height
12992
+ "RSQ temp2.w, temp2.w;" +
12993
+ "RCP temp2.w, temp2.w;" +
12994
+
12995
+ "SUB temp2.w, temp2.w, half;" +
12996
+ // "SGE temp.x, temp2.w, eps.x;" +
12997
+ // "MUL temp2.w, temp2.w, temp.x;" +
12998
+
12999
+ // "MOV texSamp, U;" +
13000
+
13001
+ "MUL temp2.z, temp2.z, temp2.w;" +
13002
+ "MUL temp2.z, temp2.z, params7.z;" + // parallax
13003
+
13004
+ "MUL temp2, temp2, temp2.z;" +
13005
+
13006
+ "SUB temp, temp, temp2;" +
13007
+
13008
+ "TEX temp, temp, texture[0], 2D;" +
13009
+ "POW temp.a, temp.a, params6.w;" + // punch through
13010
+
13011
+ "ADD texSamp, temp, texSamp;" +
13012
+ "MUL texSamp.xyz, half, texSamp;" +
13013
+
13014
+ "MOV alpha, texSamp.aaaa;" +
13015
+
13016
+// parallax mapping
13017
+
13018
+ "MOV temp.x, texSamp.a;" +
13019
+ "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
13020
+ //"LRP texSamp0, params5.x, texSamp0, one;" +
13021
+ "MOV texSamp.a, temp.x;" +
1252313022
1252413023 //"MOV temp, fragment.texcoord[0];" +
1252513024 //
....@@ -12649,10 +13148,10 @@
1264913148 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1265013149 "") +
1265113150
12652
- // display shadow only (bump == 0)
13151
+ // display shadow only (fakedepth == 0)
1265313152 "SUB temp.x, half.x, shadow.x;" +
1265413153 "MOV temp.y, -params5.z;" + // params6.x;" +
12655
- "SLT temp.z, temp.y, -one2048th.x;" +
13154
+ "SLT temp.z, temp.y, -c256i.x;" +
1265613155 "SUB temp.y, one.x, temp.z;" +
1265713156 "MUL temp.x, temp.x, temp.y;" +
1265813157 "KIL temp.x;" +
....@@ -12983,8 +13482,19 @@
1298313482 //once = true;
1298413483 }
1298513484
12986
- System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
12987
- System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13485
+ String program = programmax;
13486
+
13487
+ if (Globals.MINSHADER)
13488
+ {
13489
+ program = programmin;
13490
+ }
13491
+
13492
+ if (Globals.DEBUG)
13493
+ {
13494
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13495
+ System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13496
+ }
13497
+
1298813498 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1298913499
1299013500 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -13031,7 +13541,8 @@
1303113541 "\n" +
1303213542 "END\n";
1303313543
13034
- System.out.println("Program shadow #" + 0 + "; length = " + program.length());
13544
+ if (Globals.DEBUG)
13545
+ System.out.println("Program shadow #" + 0 + "; length = " + program.length());
1303513546 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1303613547
1303713548 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -13076,25 +13587,26 @@
1307613587 return out;
1307713588 }
1307813589
13079
- String TextureFetch(String dest, String src, String unit)
13590
+ // Also does frustum culling
13591
+ String ShadowTextureFetch(String dest, String src, String unit)
1308013592 {
1308113593 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1308213594 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1308313595 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13596
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13597
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1308413598 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13085
- "SLT " + src + ".z, " + src + ".x, one.x;" +
13086
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13087
- "SLT " + src + ".z, " + src + ".y, one.x;" +
13088
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13599
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13600
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1308913601 //"SWZ buffer, temp, w,w,w,w;";
13090
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13602
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1309113603 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1309213604 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1309313605 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13094
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13606
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1309513607
13096
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13097
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13608
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13609
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1309813610 }
1309913611
1310013612 String Shadow(String depth, String shadow)
....@@ -13141,7 +13653,7 @@
1314113653 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1314213654 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1314313655
13144
- // No shadow when out of frustrum
13656
+ // No shadow when out of frustum
1314513657 "SGE temp.x, " + depth + ".z, one.z;" +
1314613658 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1314713659 "";
....@@ -13288,8 +13800,9 @@
1328813800 /*static*/ float[] modelParams4 = new float[]{0, 0, 0, 0}; // anisoV, cameralight, selfshadow, shadow
1328913801 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1329013802 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
13291
- /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13292
- Object3D.cVector2[] vector2buffer;
13803
+ /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power, parallax
13804
+
13805
+ //Object3D.cVector2[] vector2buffer;
1329313806
1329413807 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1329513808 // OUT : diff, spec
....@@ -13305,9 +13818,10 @@
1330513818 "DP3 " + dest + ".z," + "normals," + "eye;" +
1330613819 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1330713820 //"MOV " + dest + ".w," + "normal.z;" +
13308
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
13309
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13310
- //"MOV " + dest + ".z," + "params2.w;" +
13821
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13822
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13823
+
13824
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1331113825 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1331213826 "RCP " + dest + ".w," + dest + ".w;" +
1331313827 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13453,7 +13967,7 @@
1345313967 "PARAM p[4] = { state.matrix.projection }; # modelview projection matrix\n" +
1345413968 "PARAM zero = { 0.0, 0.0, 0.0, 1.0 };" +
1345513969 "PARAM half = { 0.5, 0.5, 0.5, 1.0 };" +
13456
- "PARAM one = { 1.0, 1.0, 1.0, 0.0 };" +
13970
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
1345713971 "PARAM two = { 2.0, 2.0, 2.0, 1.0 };" +
1345813972 "PARAM third = { 0.33333333333, 0.33333333333, 0.33333333333, 1.0 };" +
1345913973 //"PARAM v256 = { 256.0, 256.0, 256.0, 1.0 };" +
....@@ -13514,7 +14028,7 @@
1351414028 "DP4 temp.x,state.matrix.texture[0].inverse.row[0],vertex.texcoord;" +
1351514029 "DP4 temp.y,state.matrix.texture[0].inverse.row[1],vertex.texcoord;" +
1351614030 "DP4 temp.z,state.matrix.texture[0].inverse.row[2],vertex.texcoord;" +
13517
- //"MOV result.texcoord, vertex.texcoord;" +
14031
+ //"MOV result.texcoord, vertex.fogcoord;" +
1351814032 "MOV result.texcoord, temp;" +
1351914033 // border fade
1352014034 "MOV result.texcoord[3], vertex.texcoord;" +
....@@ -13561,7 +14075,9 @@
1356114075
1356214076 //"ADD temp.z, temp.z, one;" +
1356314077
13564
- "MOV result.color, temp;"
14078
+ "MOV result.texcoord[4], vertex.attrib[4];" + // U dir
14079
+
14080
+ "MOV result.color, temp;" // Normal
1356514081 : "MOV result.color, vertex.color;") +
1356614082 ((mode & VP_PROJECTION) != 0 ? "MOV result.color, zero;"
1356714083 : "") +
....@@ -13812,6 +14328,7 @@
1381214328 else
1381314329 if (evt.getSource() == AAtimer)
1381414330 {
14331
+ Globals.TIMERRUNNING = false;
1381514332 if (mouseDown)
1381614333 {
1381714334 //new Exception().printStackTrace();
....@@ -13871,7 +14388,7 @@
1387114388
1387214389 // fev 2014???
1387314390 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13874
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14391
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1387514392 pingthread.StepToTarget(true); // true);
1387614393 }
1387714394 // if (!LIVE)
....@@ -13886,6 +14403,7 @@
1388614403 return;
1388714404
1388814405 AAtimer.restart(); //
14406
+ Globals.TIMERRUNNING = true;
1388914407
1389014408 // waslive = LIVE;
1389114409 // LIVE = false;
....@@ -13935,14 +14453,15 @@
1393514453 drag = false;
1393614454 //System.out.println("Mouse DOWN");
1393714455 editObj = false;
13938
- ClickInfo info = new ClickInfo();
13939
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
13940
- info.pane = this;
13941
- info.camera = renderCamera;
13942
- info.x = x;
13943
- info.y = y;
13944
- info.modifiers = modifiersex;
13945
- editObj = object.doEditClick(info, 0);
14456
+ //ClickInfo info = new ClickInfo();
14457
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14458
+ object.clickInfo.pane = this;
14459
+ object.clickInfo.camera = renderCamera;
14460
+ object.clickInfo.x = x;
14461
+ object.clickInfo.y = y;
14462
+ object.clickInfo.modifiers = modifiersex;
14463
+ editObj = object.doEditClick(//info,
14464
+ 0);
1394614465 if (!editObj)
1394714466 {
1394814467 hasMarquee = true;
....@@ -14217,19 +14736,25 @@
1421714736 }
1421814737 }
1421914738 PingThread pingthread = new PingThread();
14220
- int delta = 5;
14221
- int speed = 5;
14739
+ int delta = 2;
14740
+ int speed = 10;
1422214741 boolean autorepeat = false;
1422314742
1422414743 void GoDown(int mod)
1422514744 {
1422614745 MODIFIERS |= COMMAND;
14227
- /*
14746
+ boolean isVR = (mouseMode&VR)!=0;
14747
+ /**/
1422814748 if((mod&SHIFT) == SHIFT)
14229
- manipCamera.RotatePosition(0, -speed);
14749
+ {
14750
+ if (isVR)
14751
+ manipCamera.RotateInterest(0, -speed);
14752
+ else
14753
+ manipCamera.RotatePosition(0, -speed);
14754
+ }
1423014755 else
14231
- manipCamera.BackForth(0, -speed*delta, getWidth());
14232
- */
14756
+ manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth());
14757
+ /**/
1423314758 if ((mod & SHIFT) == SHIFT)
1423414759 {
1423514760 mouseMode = mouseMode; // VR??
....@@ -14238,6 +14763,8 @@
1423814763 mouseMode |= BACKFORTH;
1423914764 }
1424014765
14766
+ targetLookAt.set(manipCamera.lookAt);
14767
+
1424114768 //prevX = X = anchorX;
1424214769 prevY = Y = anchorY - (int) (renderCamera.Distance());
1424314770 }
....@@ -14245,12 +14772,19 @@
1424514772 void GoUp(int mod)
1424614773 {
1424714774 MODIFIERS |= COMMAND;
14248
- /*
14775
+ /**/
14776
+ boolean isVR = (mouseMode&VR)!=0;
14777
+
1424914778 if((mod&SHIFT) == SHIFT)
14250
- manipCamera.RotatePosition(0, speed);
14779
+ {
14780
+ if (isVR)
14781
+ manipCamera.RotateInterest(0, speed);
14782
+ else
14783
+ manipCamera.RotatePosition(0, speed);
14784
+ }
1425114785 else
14252
- manipCamera.BackForth(0, speed*delta, getWidth());
14253
- */
14786
+ manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth());
14787
+ /**/
1425414788 if ((mod & SHIFT) == SHIFT)
1425514789 {
1425614790 mouseMode = mouseMode;
....@@ -14259,6 +14793,8 @@
1425914793 mouseMode |= BACKFORTH;
1426014794 }
1426114795
14796
+ targetLookAt.set(manipCamera.lookAt);
14797
+
1426214798 //prevX = X = anchorX;
1426314799 prevY = Y = anchorY + (int) (renderCamera.Distance());
1426414800 }
....@@ -14266,12 +14802,17 @@
1426614802 void GoLeft(int mod)
1426714803 {
1426814804 MODIFIERS |= COMMAND;
14269
- /*
14805
+ /**/
1427014806 if((mod&SHIFT) == SHIFT)
14271
- manipCamera.RotatePosition(speed, 0);
14807
+ manipCamera.Translate(speed*delta, 0, getWidth());
1427214808 else
14273
- manipCamera.Translate(speed*delta, 0, getWidth());
14274
- */
14809
+ {
14810
+ if ((mouseMode&VR)!=0)
14811
+ manipCamera.RotateInterest(-speed, 0);
14812
+ else
14813
+ manipCamera.RotatePosition(speed, 0);
14814
+ }
14815
+ /**/
1427514816 if ((mod & SHIFT) == SHIFT)
1427614817 {
1427714818 mouseMode = mouseMode;
....@@ -14280,6 +14821,8 @@
1428014821 mouseMode |= ROTATE;
1428114822 } // TRANSLATE;
1428214823
14824
+ targetLookAt.set(manipCamera.lookAt);
14825
+
1428314826 prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance());
1428414827 prevY = Y = anchorY;
1428514828 }
....@@ -14287,12 +14830,18 @@
1428714830 void GoRight(int mod)
1428814831 {
1428914832 MODIFIERS |= COMMAND;
14290
- /*
14833
+ /**/
1429114834 if((mod&SHIFT) == SHIFT)
14292
- manipCamera.RotatePosition(-speed, 0);
14835
+ manipCamera.Translate(-speed*delta, 0, getWidth());
1429314836 else
14294
- manipCamera.Translate(-speed*delta, 0, getWidth());
14295
- */
14837
+ {
14838
+ if ((mouseMode&VR)!=0)
14839
+ manipCamera.RotateInterest(speed, 0);
14840
+ else
14841
+ manipCamera.RotatePosition(-speed, 0);
14842
+ }
14843
+
14844
+ /**/
1429614845 if ((mod & SHIFT) == SHIFT)
1429714846 {
1429814847 mouseMode = mouseMode;
....@@ -14301,6 +14850,8 @@
1430114850 mouseMode |= ROTATE;
1430214851 } // TRANSLATE;
1430314852
14853
+ targetLookAt.set(manipCamera.lookAt);
14854
+
1430414855 prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance());
1430514856 prevY = Y = anchorY;
1430614857 }
....@@ -14342,14 +14893,16 @@
1434214893 if (editObj)
1434314894 {
1434414895 drag = true;
14345
- ClickInfo info = new ClickInfo();
14346
- info.bounds.setBounds(0, 0,
14896
+ //ClickInfo info = new ClickInfo();
14897
+ object.clickInfo.bounds.setBounds(0, 0,
1434714898 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14348
- info.pane = this;
14349
- info.camera = renderCamera;
14350
- info.x = x;
14351
- info.y = y;
14352
- object.editWindow.copy.doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
14899
+ object.clickInfo.pane = this;
14900
+ object.clickInfo.camera = renderCamera;
14901
+ object.clickInfo.x = x;
14902
+ object.clickInfo.y = y;
14903
+ object //.GetWindow().copy
14904
+ .doEditDrag(//info,
14905
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1435314906 } else
1435414907 {
1435514908 if (x < startX)
....@@ -14498,22 +15051,27 @@
1449815051 }
1449915052 }
1450015053
15054
+// ClickInfo clickInfo = new ClickInfo();
15055
+
1450115056 public void mouseMoved(MouseEvent e)
1450215057 {
1450315058 //System.out.println("mouseMoved: " + e);
1450415059 if (isRenderer)
1450515060 return;
1450615061
14507
- ClickInfo ci = new ClickInfo();
14508
- ci.x = e.getX();
14509
- ci.y = e.getY();
14510
- ci.modifiers = e.getModifiersEx();
14511
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14512
- ci.pane = this;
14513
- ci.camera = renderCamera;
15062
+ // Mouse cursor feedback
15063
+ object.clickInfo.x = e.getX();
15064
+ object.clickInfo.y = e.getY();
15065
+ object.clickInfo.modifiers = e.getModifiersEx();
15066
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
15067
+ object.clickInfo.pane = this;
15068
+ object.clickInfo.camera = renderCamera;
1451415069 if (!isRenderer)
1451515070 {
14516
- if (object.editWindow.copy.doEditClick(ci, 0))
15071
+ //ObjEditor editWindow = object.editWindow;
15072
+ //Object3D copy = editWindow.copy;
15073
+ if (object.doEditClick(//clickInfo,
15074
+ 0))
1451715075 {
1451815076 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1451915077 } else
....@@ -14528,7 +15086,8 @@
1452815086 Globals.MOUSEDRAGGED = false;
1452915087
1453015088 movingcamera = false;
14531
- X = Y = 0;
15089
+ X = 0; // getBounds().width/2;
15090
+ Y = 0; // getBounds().height/2;
1453215091 //System.out.println("mouseReleased: " + e);
1453315092 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1453415093 }
....@@ -14784,7 +15343,8 @@
1478415343 // break;
1478515344 case 'T':
1478615345 CACHETEXTURE ^= true;
14787
- textures.clear();
15346
+ texturepigment.clear();
15347
+ texturebump.clear();
1478815348 // repaint();
1478915349 break;
1479015350 case 'Y':
....@@ -14794,8 +15354,8 @@
1479415354 case 'K':
1479515355 KOMPACTTEXTURE ^= true;
1479615356 //textures.clear();
14797
- break;
14798
- case 'P': // Texture Projection macros
15357
+ // break;
15358
+ //case 'P': // Texture Projection macros
1479915359 // SAVETEXTURE ^= true;
1480015360 macromode = true;
1480115361 Udebug = Vdebug = NORMALdebug = false; programInitialized = false;
....@@ -14869,7 +15429,9 @@
1486915429 case 'E' : COMPACT ^= true;
1487015430 repaint();
1487115431 break;
14872
- case 'W' : DEBUGHSB ^= true;
15432
+ case 'W' : // Wide Window (fullscreen)
15433
+ //DEBUGHSB ^= true;
15434
+ ObjEditor.theFrame.ToggleFullScreen();
1487315435 repaint();
1487415436 break;
1487515437 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14894,8 +15456,8 @@
1489415456 RevertCamera();
1489515457 repaint();
1489615458 break;
14897
- case 'L':
1489815459 case 'l':
15460
+ //case 'L':
1489915461 if (lightMode)
1490015462 {
1490115463 lightMode = false;
....@@ -14914,7 +15476,7 @@
1491415476 targetLookAt.set(manipCamera.lookAt);
1491515477 repaint();
1491615478 break;
14917
- case 'p':
15479
+ case 'P': // p':
1491815480 // c'est quoi ca au juste? spherical ^= true;
1491915481 Skinshader ^= true; programInitialized = false;
1492015482 repaint();
....@@ -14952,27 +15514,31 @@
1495215514 repaint();
1495315515 break;
1495415516 case 'O':
14955
- Globals.drawMode = OCCLUSION; // WARNING
15517
+ // Too dangerous. Use menu. Globals.drawMode = OCCLUSION; // WARNING
1495615518 repaint();
1495715519 break;
1495815520 case 'o':
1495915521 OCCLUSION_CULLING ^= true;
1496015522 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1496115523 break;
14962
- case '0': envyoff ^= true; repaint(); break;
15524
+ //case '0': envyoff ^= true; repaint(); break;
1496315525 case '1':
1496415526 case '2':
1496515527 case '3':
1496615528 case '4':
1496715529 case '5':
14968
- newenvy = Character.getNumericValue(key);
14969
- repaint();
14970
- break;
1497115530 case '6':
1497215531 case '7':
1497315532 case '8':
1497415533 case '9':
14975
- BGcolor = (key - '6')/3.f;
15534
+ if (true) // envyoff)
15535
+ {
15536
+ BGcolor = (key - '1')/8.f;
15537
+ }
15538
+ else
15539
+ {
15540
+ //newenvy = Character.getNumericValue(key);
15541
+ }
1497615542 repaint();
1497715543 break;
1497815544 case '!':
....@@ -15038,9 +15604,9 @@
1503815604 case '_':
1503915605 kompactbit = 5;
1504015606 break;
15041
- case '+':
15042
- kompactbit = 6;
15043
- break;
15607
+// case '+':
15608
+// kompactbit = 6;
15609
+// break;
1504415610 case ' ':
1504515611 lightMode ^= true;
1504615612 Globals.lighttouched = true;
....@@ -15052,6 +15618,7 @@
1505215618 case ESC:
1505315619 RENDERPROGRAM += 1;
1505415620 RENDERPROGRAM %= 3;
15621
+
1505515622 repaint();
1505615623 break;
1505715624 case 'Z':
....@@ -15091,8 +15658,9 @@
1509115658 case DELETE:
1509215659 ClearSelection();
1509315660 break;
15094
- /*
1509515661 case '+':
15662
+
15663
+ /*
1509615664 //fontsize += 1;
1509715665 bbzoom *= 2;
1509815666 repaint();
....@@ -15109,17 +15677,17 @@
1510915677 case '=':
1511015678 IncDepth();
1511115679 //fontsize += 1;
15112
- object.editWindow.refreshContents(true);
15680
+ object.GetWindow().refreshContents(true);
1511315681 maskbit = 6;
1511415682 break;
1511515683 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1511615684 DecDepth();
1511715685 maskbit = 5;
1511815686 //if(fontsize > 1) fontsize -= 1;
15119
- if (object.editWindow == null)
15120
- new Exception().printStackTrace();
15121
- else
15122
- object.editWindow.refreshContents(true);
15687
+// if (object.editWindow == null)
15688
+// new Exception().printStackTrace();
15689
+// else
15690
+ object.GetWindow().refreshContents(true);
1512315691 break;
1512415692 case '{':
1512515693 manipCamera.shaper_fovy /= 1.1;
....@@ -15343,7 +15911,7 @@
1534315911 }
1534415912 */
1534515913
15346
- object.editWindow.EditSelection();
15914
+ object.GetWindow().EditSelection(false);
1534715915 }
1534815916
1534915917 void SelectParent()
....@@ -15360,10 +15928,10 @@
1536015928 {
1536115929 //selectees.remove(i);
1536215930 System.out.println("select parent of " + elem);
15363
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15931
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1536415932 } else
1536515933 {
15366
- group.editWindow.Select(elem.GetTreePath(), first, true);
15934
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1536715935 }
1536815936
1536915937 first = false;
....@@ -15405,12 +15973,12 @@
1540515973 for (int j = 0; j < group.children.size(); j++)
1540615974 {
1540715975 elem = (Object3D) group.children.elementAt(j);
15408
- object.editWindow.Select(elem.GetTreePath(), first, true);
15976
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1540915977 first = false;
1541015978 }
1541115979 } else
1541215980 {
15413
- object.editWindow.Select(elem.GetTreePath(), first, true);
15981
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1541415982 }
1541515983
1541615984 first = false;
....@@ -15421,21 +15989,21 @@
1542115989 {
1542215990 //Composite group = (Composite) object;
1542315991 Object3D group = object;
15424
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15992
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1542515993 }
1542615994
1542715995 void ResetTransform(int mask)
1542815996 {
1542915997 //Composite group = (Composite) object;
1543015998 Object3D group = object;
15431
- group.editWindow.ResetTransform(mask);
15999
+ group.GetWindow().ResetTransform(mask);
1543216000 }
1543316001
1543416002 void FlipTransform()
1543516003 {
1543616004 //Composite group = (Composite) object;
1543716005 Object3D group = object;
15438
- group.editWindow.FlipTransform();
16006
+ group.GetWindow().FlipTransform();
1543916007 // group.editWindow.ReduceMesh(true);
1544016008 }
1544116009
....@@ -15443,7 +16011,7 @@
1544316011 {
1544416012 //Composite group = (Composite) object;
1544516013 Object3D group = object;
15446
- group.editWindow.PrintMemory();
16014
+ group.GetWindow().PrintMemory();
1544716015 // group.editWindow.ReduceMesh(true);
1544816016 }
1544916017
....@@ -15451,7 +16019,7 @@
1545116019 {
1545216020 //Composite group = (Composite) object;
1545316021 Object3D group = object;
15454
- group.editWindow.ResetCentroid();
16022
+ group.GetWindow().ResetCentroid();
1545516023 }
1545616024
1545716025 void IncDepth()
....@@ -15533,8 +16101,6 @@
1553316101
1553416102 int width = getBounds().width;
1553516103 int height = getBounds().height;
15536
- ClickInfo info = new ClickInfo();
15537
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1553816104 //Image img = CreateImage(width, height);
1553916105 //System.out.println("width = " + width + "; height = " + height + "\n");
1554016106
....@@ -15611,48 +16177,77 @@
1561116177 }
1561216178 if (object != null && !hasMarquee)
1561316179 {
16180
+ if (object.clickInfo == null)
16181
+ object.clickInfo = new ClickInfo();
16182
+ ClickInfo info = object.clickInfo;
16183
+ //ClickInfo info = new ClickInfo();
16184
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16185
+
1561416186 if (isRenderer)
1561516187 {
15616
- info.flags++;
16188
+ object.clickInfo.flags++;
1561716189 double frameAspect = (double) width / (double) height;
1561816190 if (frameAspect > renderCamera.aspect)
1561916191 {
1562016192 int desired = (int) ((double) height * renderCamera.aspect);
15621
- info.bounds.width -= width - desired;
15622
- info.bounds.x += (width - desired) / 2;
16193
+ object.clickInfo.bounds.width -= width - desired;
16194
+ object.clickInfo.bounds.x += (width - desired) / 2;
1562316195 } else
1562416196 {
1562516197 int desired = (int) ((double) width / renderCamera.aspect);
15626
- info.bounds.height -= height - desired;
15627
- info.bounds.y += (height - desired) / 2;
16198
+ object.clickInfo.bounds.height -= height - desired;
16199
+ object.clickInfo.bounds.y += (height - desired) / 2;
1562816200 }
1562916201 }
15630
- info.g = gr;
15631
- info.camera = renderCamera;
16202
+
16203
+ object.clickInfo.g = gr;
16204
+ object.clickInfo.camera = renderCamera;
1563216205 /*
1563316206 // Memory intensive (brep.verticescopy)
1563416207 if (!(object instanceof Composite))
1563516208 object.draw(info, 0, false); // SLOW :
1563616209 */
15637
- if (!isRenderer)
16210
+ if (!isRenderer) // && drag)
1563816211 {
15639
- object.drawEditHandles(info, 0);
15640
-
15641
- if (drag && (X != 0 || Y != 0) && object.selection.Size() > 0)
16212
+ Grafreed.Assert(object != null);
16213
+ Grafreed.Assert(object.selection != null);
16214
+ if (object.selection.Size() > 0)
1564216215 {
15643
- switch (object.selection.get(0).hitSomething)
16216
+ int hitSomething = object.selection.get(0).hitSomething;
16217
+
16218
+ object.clickInfo.DX = 0;
16219
+ object.clickInfo.DY = 0;
16220
+ object.clickInfo.W = 1;
16221
+ if (hitSomething == Object3D.hitCenter)
1564416222 {
15645
- case Object3D.hitCenter: gr.setColor(Color.pink);
15646
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15647
- break;
15648
- case Object3D.hitRotate: gr.setColor(Color.yellow);
15649
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15650
- break;
15651
- case Object3D.hitScale: gr.setColor(Color.cyan);
15652
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15653
- break;
16223
+ info.DX = X;
16224
+ if (X != 0)
16225
+ info.DX -= info.bounds.width/2;
16226
+
16227
+ info.DY = Y;
16228
+ if (Y != 0)
16229
+ info.DY -= info.bounds.height/2;
1565416230 }
15655
-
16231
+
16232
+ object.drawEditHandles(//info,
16233
+ 0);
16234
+
16235
+ if (drag && (X != 0 || Y != 0))
16236
+ {
16237
+ switch (hitSomething)
16238
+ {
16239
+ case Object3D.hitCenter: gr.setColor(Color.white);
16240
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16241
+ break;
16242
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16243
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16244
+ break;
16245
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16246
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16247
+ break;
16248
+ }
16249
+
16250
+ }
1565616251 }
1565716252 }
1565816253 }
....@@ -15667,7 +16262,7 @@
1566716262 if (hasMarquee)
1566816263 {
1566916264 gr.setXORMode(Color.white);
15670
- gr.setColor(Color.red);
16265
+ gr.setColor(Color.white);
1567116266 if (!firstime)
1567216267 {
1567316268 gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH);
....@@ -16134,6 +16729,8 @@
1613416729 private /*static*/ boolean firstime;
1613516730 private /*static*/ cVector newView = new cVector();
1613616731 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16732
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16733
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1613716734 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1613816735 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1613916736 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16146,29 +16743,67 @@
1614616743 {
1614716744 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1614816745
16746
+ int usedsuf = 0;
16747
+
1614916748 for (int i = 0; i < suffixes.length; i++)
1615016749 {
16151
- String resourceName = basename + suffixes[i] + "." + suffix;
16152
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16153
- mipmapped,
16154
- FileUtil.getFileSuffix(resourceName));
16155
- if (data == null)
16750
+ String[] suffixe = suffixes;
16751
+ String[] fallback = suffixes2;
16752
+ String[] fallfallback = suffixes3;
16753
+
16754
+ for (int c=usedsuf; --c>=0;)
1615616755 {
16157
- throw new IOException("Unable to load texture " + resourceName);
16756
+// String[] temp = suffixe;
16757
+// suffixe = fallback;
16758
+// fallback = fallfallback;
16759
+// fallfallback = temp;
1615816760 }
16761
+
16762
+ String resourceName = basename + suffixe[i] + "." + suffix;
16763
+ TextureData data;
16764
+
16765
+ try
16766
+ {
16767
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16768
+ mipmapped,
16769
+ FileUtil.getFileSuffix(resourceName));
16770
+ }
16771
+ catch (Exception e)
16772
+ {
16773
+ try
16774
+ {
16775
+ resourceName = basename + fallback[i] + "." + suffix;
16776
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16777
+ mipmapped,
16778
+ FileUtil.getFileSuffix(resourceName));
16779
+ }
16780
+ catch (Exception e2)
16781
+ {
16782
+ resourceName = basename + fallfallback[i] + "." + suffix;
16783
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16784
+ mipmapped,
16785
+ FileUtil.getFileSuffix(resourceName));
16786
+ }
16787
+ }
16788
+
1615916789 //System.out.println("Target = " + targets[i]);
1616016790 cubemap.updateImage(data, targets[i]);
1616116791 }
1616216792
1616316793 return cubemap;
1616416794 }
16795
+
1616516796 int bigsphere = -1;
1616616797
1616716798 float BGcolor = 0.5f;
1616816799
16169
- private void DrawSkyBox(GL gl)
16800
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16801
+
16802
+ private void DrawSkyBox(GL gl, float ratio)
1617016803 {
16171
- if (envyoff || cubemap == null)
16804
+ if (//envyoff ||
16805
+ WIREFRAME ||
16806
+ cubemap == null)
1617216807 {
1617316808 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1617416809 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16183,7 +16818,17 @@
1618316818 // Compensates for ExaminerViewer's modification of modelview matrix
1618416819 gl.glMatrixMode(GL.GL_MODELVIEW);
1618516820 gl.glLoadIdentity();
16821
+ gl.glScalef(1,ratio,1);
1618616822
16823
+// colorV[0] = 2;
16824
+// colorV[1] = 2;
16825
+// colorV[2] = 2;
16826
+// colorV[3] = 1;
16827
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16828
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16829
+//
16830
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16831
+
1618716832 //gl.glActiveTexture(GL.GL_TEXTURE1);
1618816833 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1618916834
....@@ -16215,6 +16860,7 @@
1621516860 {
1621616861 gl.glScalef(1.0f, -1.0f, 1.0f);
1621716862 }
16863
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1621816864 gl.glMultMatrixd(viewrot_1, 0);
1621916865 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1622016866 //viewer.updateInverseRotation(gl);
....@@ -16255,7 +16901,8 @@
1625516901 gl.glDisable(GL.GL_TEXTURE_GEN_R);
1625616902
1625716903 cubemap.disable();
16258
- ////cubemap.unbind();
16904
+ //cubemap.dispose();
16905
+
1625916906 if (CULLFACE)
1626016907 {
1626116908 gl.glEnable(gl.GL_CULL_FACE);
....@@ -16311,7 +16958,7 @@
1631116958 gl.glScalef(1.0f, -1.0f, 1.0f);
1631216959 }
1631316960
16314
- gl.glNormal3f(0.0f, 0.0f, 1.0f);
16961
+ SetGLNormal(gl, 0.0f, 0.0f, 1.0f);
1631516962
1631616963 float step = 2; // 0.1666f; //0.25f;
1631716964 float stepv = 2; // step * 1652 / 998;
....@@ -16355,16 +17002,16 @@
1635517002 cStatic.objectstack[materialdepth++] = checker;
1635617003 //System.out.println("material " + material);
1635717004 //Applet3D.tracein(this, selected);
16358
- vector2buffer = checker.projectedVertices;
17005
+ //vector2buffer = checker.projectedVertices;
1635917006
1636017007 //checker.GetMaterial().Draw(this, false); // true);
16361
- DrawMaterial(checker.GetMaterial(), false); // true);
17008
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1636217009
1636317010 materialdepth -= 1;
1636417011 if (materialdepth > 0)
1636517012 {
16366
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16367
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
17013
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
17014
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1636817015 }
1636917016 //checker.GetMaterial().opacity = 1f;
1637017017 ////checker.GetMaterial().ambient = 1f;
....@@ -16450,6 +17097,14 @@
1645017097 }
1645117098 }
1645217099
17100
+ private Object3D GetFolder()
17101
+ {
17102
+ Object3D folder = object.GetWindow().copy;
17103
+ if (object.GetWindow().copy.selection.Size() > 0)
17104
+ folder = object.GetWindow().copy.selection.elementAt(0);
17105
+ return folder;
17106
+ }
17107
+
1645317108 class SelectBuffer implements GLEventListener
1645417109 {
1645517110
....@@ -16465,7 +17120,7 @@
1646517120 //new Exception().printStackTrace();
1646617121 System.out.println("select buffer init");
1646717122 // Use debug pipeline
16468
- drawable.setGL(new DebugGL(drawable.getGL()));
17123
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1646917124
1647017125 GL gl = drawable.getGL();
1647117126
....@@ -16529,6 +17184,17 @@
1652917184
1653017185 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1653117186
17187
+ if (PAINTMODE)
17188
+ {
17189
+ if (object.GetWindow().copy.selection.Size() > 0)
17190
+ {
17191
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17192
+
17193
+ // Make what you paint not selectable.
17194
+ paintobj.ResetSelectable();
17195
+ }
17196
+ }
17197
+
1653217198 //int tmp = selection_view;
1653317199 //selection_view = -1;
1653417200 int temp = DrawMode();
....@@ -16540,6 +17206,17 @@
1654017206 // temp = DEFAULT; // patch for selection debug
1654117207 Globals.drawMode = temp; // WARNING
1654217208
17209
+ if (PAINTMODE)
17210
+ {
17211
+ if (object.GetWindow().copy.selection.Size() > 0)
17212
+ {
17213
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17214
+
17215
+ // Revert.
17216
+ paintobj.RestoreSelectable();
17217
+ }
17218
+ }
17219
+
1654317220 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1654417221
1654517222 // trying different ways of getting the depth info over
....@@ -16587,6 +17264,8 @@
1658717264 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1658817265 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1658917266 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
17267
+
17268
+ CreateSelectedPoint();
1659017269
1659117270 // Will fit the mesh !!!
1659217271 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16641,29 +17320,31 @@
1664117320 }
1664217321
1664317322 if (!movingcamera && !PAINTMODE)
16644
- object.editWindow.ScreenFitPoint(); // fev 2014
17323
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1664517324
16646
- if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17325
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1664717326 {
16648
- Object3D paintobj = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17327
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1664917328
16650
- Object3D group = new Object3D("inst" + paintcount++);
17329
+ if (object.GetWindow().copy.selection.Size() > 0)
17330
+ {
17331
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1665117332
16652
- group.CreateMaterial(); // use a void leaf to select instances
16653
-
16654
- group.add(paintobj); // link
16655
-
16656
- object.editWindow.SnapObject(group);
16657
-
16658
- Object3D folder = object.editWindow.copy;
16659
-
16660
- if (object.editWindow.copy.selection.Size() > 0)
16661
- folder = object.editWindow.copy.selection.elementAt(0);
16662
-
16663
- folder.add(group);
16664
-
16665
- object.editWindow.ResetModel();
16666
- object.editWindow.refreshContents();
17333
+ Object3D inst = new Object3D("inst" + paintcount++);
17334
+
17335
+ inst.CreateMaterial(); // use a void leaf to select instances
17336
+
17337
+ inst.add(paintobj); // link
17338
+
17339
+ object.GetWindow().SnapObject(inst);
17340
+
17341
+ Object3D folder = paintFolder; // GetFolder();
17342
+
17343
+ folder.add(inst);
17344
+
17345
+ object.GetWindow().ResetModel();
17346
+ object.GetWindow().refreshContents();
17347
+ }
1666717348 }
1666817349 else
1666917350 paintcount = 0;
....@@ -16702,6 +17383,11 @@
1670217383 //System.out.println("objects[color] = " + objects[color]);
1670317384 //objects[color].Select();
1670417385 indexcount = 0;
17386
+ ObjEditor window = object.GetWindow();
17387
+ if (window != null && deselect)
17388
+ {
17389
+ window.Select(null, deselect, true);
17390
+ }
1670517391 object.Select(color, deselect);
1670617392 }
1670717393
....@@ -16752,6 +17438,7 @@
1675217438
1675317439 public void init(GLAutoDrawable drawable)
1675417440 {
17441
+ if (Globals.DEBUG)
1675517442 System.out.println("shadow buffer init");
1675617443
1675717444 GL gl = drawable.getGL();
....@@ -16980,10 +17667,14 @@
1698017667 gl.glFlush();
1698117668
1698217669 /**/
16983
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17670
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1698417671
16985
- float[] pixels = occlusionsizebuffer.array();
17672
+ float[] depths = occlusiondepthbuffer.array();
1698617673
17674
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17675
+
17676
+ int[] pixels = selectsizebuffer.array();
17677
+
1698717678 double r = 0, g = 0, b = 0;
1698817679
1698917680 double count = 0;
....@@ -16994,7 +17685,7 @@
1699417685
1699517686 double FACTOR = 1;
1699617687
16997
- for (int i = 0; i < pixels.length; i++)
17688
+ for (int i = 0; i < depths.length; i++)
1699817689 {
1699917690 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1700017691 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -17077,7 +17768,7 @@
1707717768
1707817769 double scale = ray.z; // 1; // cos
1707917770
17080
- float depth = pixels[newindex];
17771
+ float depth = depths[newindex];
1708117772
1708217773 /*
1708317774 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -17227,23 +17918,15 @@
1722717918 int AAbuffersize = 0;
1722817919
1722917920 //double[] selectedpoint = new double[3];
17230
- static Superellipsoid selectedpoint = new Superellipsoid();
17921
+ static Superellipsoid selectedpoint;
1723117922 static Sphere previousselectedpoint = null;
17232
- static Sphere debugpointG = new Sphere();
17233
- static Sphere debugpointP = new Sphere();
17234
- static Sphere debugpointC = new Sphere();
17235
- static Sphere debugpointR = new Sphere();
17923
+ static Sphere debugpointG;
17924
+ static Sphere debugpointP;
17925
+ static Sphere debugpointC;
17926
+ static Sphere debugpointR;
1723617927
1723717928 static Sphere debugpoints[] = new Sphere[8];
1723817929
17239
- static
17240
- {
17241
- for (int i=0; i<8; i++)
17242
- {
17243
- debugpoints[i] = new Sphere();
17244
- }
17245
- }
17246
-
1724717930 static void InitPoints(float radius)
1724817931 {
1724917932 for (int i=0; i<8; i++)
....@@ -17282,11 +17965,14 @@
1728217965 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1728317966 static IntBuffer bigAAbuffer;
1728417967 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
17285
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17968
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1728617969 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1728717970 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1728817971 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17289
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17972
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17973
+
17974
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17975
+
1729017976 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1729117977 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1729217978 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();