Normand Briere
2019-08-23 60cec91731a350fe67e9b5ffe7a00d70e9026314
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;
....@@ -56,14 +92,12 @@
5692 static int CURRENTANTIALIAS = 0; // 1;
5793 /*static*/ boolean RENDERSHADOW = true;
5894 /*static*/ int RENDERPROGRAM = 2; // 0 == none, 1 == fast, 2 == normal
59
- static boolean ANIMATION = false;
60
- static String filename;
6195
6296 boolean DISPLAYTEXT = false;
6397 //boolean REDUCETEXTURE = true;
6498 boolean CACHETEXTURE = true;
6599 boolean CLEANCACHE = false; // true;
66
- boolean MIPMAP = false; // true;
100
+ boolean MIPMAP = false; // true; // never works...
67101 boolean COMPRESSTEXTURE = false;
68102 boolean KOMPACTTEXTURE = false; // true;
69103 boolean RESIZETEXTURE = false;
....@@ -76,7 +110,11 @@
76110 //private Mat4f spotlightTransform = new Mat4f();
77111 //private Mat4f spotlightInverseTransform = new Mat4f();
78112 static GLContext glcontext = null;
79
- /*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
+
80118 boolean reverseUP = false;
81119 static boolean frozen = false;
82120 boolean enablebackspace = false; // patch for back buffer refresh
....@@ -92,6 +130,8 @@
92130
93131 static int tickcount = 0; // slow pose issue
94132
133
+static boolean BUTTONLESSWHEEL = false;
134
+static boolean ZOOMBOXMODE = false;
95135 static boolean BOXMODE = false;
96136 static boolean IMAGEFLIP = false;
97137 static boolean SMOOTHFOCUS = false;
....@@ -106,7 +146,7 @@
106146 static boolean OEIL = true;
107147 static boolean OEILONCE = false; // do oeilon then oeiloff
108148 static boolean LOOKAT = true;
109
-static boolean RANDOM = true; // false;
149
+static boolean SWITCH = true; // false;
110150 static boolean HANDLES = false; // selection doesn't work!!
111151 static boolean PAINTMODE = false;
112152
....@@ -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
....@@ -148,6 +188,21 @@
148188 defaultcaps.setAccumGreenBits(16);
149189 defaultcaps.setAccumBlueBits(16);
150190 defaultcaps.setAccumAlphaBits(16);
191
+ }
192
+
193
+ 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
+ }
151206 }
152207
153208 void SetAsGLRenderer(boolean b)
....@@ -168,7 +223,8 @@
168223
169224 SetCamera(cam);
170225
171
- SetLight(new Camera(new cVector(10, 10, -20)));
226
+ // Warning: not used.
227
+ SetLight(new Camera(new cVector(15, 10, -20)));
172228
173229 object = o;
174230
....@@ -223,6 +279,11 @@
223279 public boolean IsBoxMode()
224280 {
225281 return BOXMODE;
282
+ }
283
+
284
+ public boolean IsZoomBoxMode()
285
+ {
286
+ return ZOOMBOXMODE;
226287 }
227288
228289 public void ClearDepth()
....@@ -320,7 +381,7 @@
320381 cStatic.objectstack[materialdepth++] = obj;
321382 //System.out.println("material " + material);
322383 //Applet3D.tracein(this, selected);
323
- display.vector2buffer = obj.projectedVertices;
384
+ //display.vector2buffer = obj.projectedVertices;
324385 if (obj instanceof Camera)
325386 {
326387 display.options1[0] = material.shift;
....@@ -329,14 +390,28 @@
329390 display.options1[2] = material.shadowbias;
330391 display.options1[3] = material.aniso;
331392 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]);
332398 display.options2[0] = material.opacity;
333399 display.options2[1] = material.diffuse;
334400 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]);
335404
336405 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]);
337409 display.options4[0] = material.cameralight/0.2f;
338410 display.options4[1] = material.subsurface;
339411 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]);
340415
341416 // if (display.CURRENTANTIALIAS > 0)
342417 // display.options3[3] /= 4;
....@@ -352,7 +427,7 @@
352427 /**/
353428 } else
354429 {
355
- DrawMaterial(material, selected);
430
+ DrawMaterial(material, selected, obj.projectedVertices);
356431 }
357432 } else
358433 {
....@@ -376,8 +451,8 @@
376451 cStatic.objectstack[materialdepth++] = obj;
377452 //System.out.println("material " + material);
378453 //Applet3D.tracein("selected ", selected);
379
- display.vector2buffer = obj.projectedVertices;
380
- display.DrawMaterial(material, selected);
454
+ //display.vector2buffer = obj.projectedVertices;
455
+ display.DrawMaterial(material, selected, obj.projectedVertices);
381456 }
382457 }
383458
....@@ -394,8 +469,8 @@
394469 materialdepth -= 1;
395470 if (materialdepth > 0)
396471 {
397
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
398
- 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);
399474 }
400475 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
401476 } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
....@@ -415,8 +490,8 @@
415490 materialdepth -= 1;
416491 if (materialdepth > 0)
417492 {
418
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
419
- 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);
420495 }
421496 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
422497 //else
....@@ -457,15 +532,18 @@
457532 if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
458533 {
459534 //gl.glBegin(gl.GL_TRIANGLES);
460
- 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
+ ;
461538 if (!hasnorm)
462539 {
463
- // System.out.println("FUCK!!");
540
+ // System.out.println("Mesh normal");
464541 LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
465542 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
466543 LA.vecCross(obj.v0, obj.v1, obj.v2);
467544 LA.vecNormalize(obj.v2);
468
- 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);
469547 }
470548
471549 // P
....@@ -487,7 +565,7 @@
487565 y += ny * obj.NORMALPUSH;
488566 z += nz * obj.NORMALPUSH;
489567
490
- gl.glNormal3f(nx, ny, nz);
568
+ SetGLNormal(gl, nx, ny, nz);
491569 }
492570 gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
493571 SetColor(obj, pv);
....@@ -519,7 +597,7 @@
519597 y += ny * obj.NORMALPUSH;
520598 z += nz * obj.NORMALPUSH;
521599
522
- gl.glNormal3f(nx, ny, nz);
600
+ SetGLNormal(gl, nx, ny, nz);
523601 }
524602 //System.out.println("vertexq = " + qv.s + ", " + qv.t);
525603 // boolean locked = false;
....@@ -567,7 +645,7 @@
567645 y += ny * obj.NORMALPUSH;
568646 z += nz * obj.NORMALPUSH;
569647
570
- gl.glNormal3f(nx, ny, nz);
648
+ SetGLNormal(gl, nx, ny, nz);
571649 }
572650
573651 // if ((dot&4) == 0)
....@@ -803,7 +881,7 @@
803881 //// tris.postdraw(this);
804882 }
805883
806
- static Camera localcamera = new Camera();
884
+ static Camera localAOcamera = new Camera();
807885 static cVector from = new cVector();
808886 static cVector to = new cVector();
809887
....@@ -812,7 +890,7 @@
812890 CameraPane cp = this;
813891
814892 Camera keep = cp.RenderCamera();
815
- cp.renderCamera = localcamera;
893
+ cp.renderCamera = localAOcamera;
816894
817895 if (br.trimmed)
818896 {
....@@ -830,7 +908,7 @@
830908 br.positions[i3 + 2] + br.normals[i3 + 2]);
831909 LA.xformPos(from, transform, from);
832910 LA.xformPos(to, transform, to); // RIGID ONLY
833
- localcamera.setAim(from, to);
911
+ localAOcamera.setAim(from, to);
834912
835913 CameraPane.occlusionbuffer.display();
836914
....@@ -864,7 +942,7 @@
864942 to.set(v.x+v.norm.x, v.y+v.norm.y, v.z+v.norm.z);
865943 LA.xformPos(from, transform, from);
866944 LA.xformPos(to, transform, to); // RIGID ONLY
867
- localcamera.setAim(from, to);
945
+ localAOcamera.setAim(from, to);
868946
869947 CameraPane.occlusionbuffer.display();
870948
....@@ -1173,10 +1251,10 @@
11731251 {
11741252 if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
11751253 {
1176
- gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1254
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
11771255 } else
11781256 {
1179
- gl.glNormal3f(0, 0, 1);
1257
+ SetGLNormal(gl, 0, 0, 1);
11801258 }
11811259
11821260 if (c != null)
....@@ -1185,10 +1263,12 @@
11851263 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
11861264 }
11871265 }
1266
+
11881267 if (flipV)
11891268 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
11901269 else
11911270 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1271
+
11921272 //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
11931273 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
11941274
....@@ -1198,20 +1278,22 @@
11981278 {
11991279 if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
12001280 {
1201
- gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1281
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
12021282 } else
12031283 {
1204
- gl.glNormal3f(0, 0, 1);
1284
+ SetGLNormal(gl, 0, 0, 1);
12051285 }
12061286 if (c != null)
12071287 {
12081288 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
12091289 }
12101290 }
1291
+
12111292 if (flipV)
12121293 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12131294 else
12141295 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1296
+
12151297 //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
12161298 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
12171299
....@@ -1224,10 +1306,10 @@
12241306 {
12251307 if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
12261308 {
1227
- gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1309
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
12281310 } else
12291311 {
1230
- gl.glNormal3f(0, 0, 1);
1312
+ SetGLNormal(gl, 0, 0, 1);
12311313 }
12321314 if (c != null)
12331315 {
....@@ -1239,8 +1321,10 @@
12391321 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12401322 else
12411323 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1324
+
12421325 //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
12431326 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1327
+
12441328 count2 += 2;
12451329 count3 += 3;
12461330 }
....@@ -1407,7 +1491,7 @@
14071491 {
14081492 if (!selectmode)
14091493 {
1410
- 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);
14111495 gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
14121496
14131497 if (flipV)
....@@ -1419,6 +1503,8 @@
14191503 gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
14201504 }
14211505
1506
+ float[] colorV = new float[4];
1507
+
14221508 void SetColor(Object3D obj, Vertex p0)
14231509 {
14241510 CameraPane display = this;
....@@ -1486,8 +1572,6 @@
14861572 {
14871573 return;
14881574 }
1489
-
1490
- float[] colorV = new float[3];
14911575
14921576 if (false) // marked)
14931577 {
....@@ -1596,7 +1680,7 @@
15961680 // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
15971681 }
15981682
1599
- void DrawMaterial(cMaterial material, boolean selected)
1683
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
16001684 {
16011685 CameraPane display = this;
16021686 //new Exception().printStackTrace();
....@@ -1612,18 +1696,18 @@
16121696 //col.getColorComponents(ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB), CameraPane.modelParams0);
16131697 if (!material.multiply)
16141698 {
1615
- display.color = color;
1699
+ display.color = material.color;
16161700 display.saturation = material.modulation;
16171701 }
16181702 else
16191703 {
1620
- display.color *= color*2;
1704
+ display.color *= material.color*2;
16211705 display.saturation *= material.modulation*2;
16221706 }
16231707
16241708 cColor.HSBtoRGB(display.color, display.saturation, 1, display.modelParams0);
16251709
1626
- float[] colorV = GrafreeD.colorV;
1710
+ float[] colorV = Grafreed.colorV;
16271711
16281712 /**/
16291713 if (display.DrawMode() == display.DEFAULT) // && display.RENDERPROGRAM == 0)
....@@ -1631,7 +1715,7 @@
16311715 colorV[0] = display.modelParams0[0] * material.diffuse;
16321716 colorV[1] = display.modelParams0[1] * material.diffuse;
16331717 colorV[2] = display.modelParams0[2] * material.diffuse;
1634
- colorV[3] = material.opacity;
1718
+ colorV[3] = 1; // material.opacity;
16351719
16361720 gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
16371721 //System.out.println("Opacity = " + opacity);
....@@ -1736,12 +1820,12 @@
17361820
17371821 display.modelParams7[0] = 0;
17381822 display.modelParams7[1] = 1000;
1739
- display.modelParams7[2] = 0;
1823
+ display.modelParams7[2] = material.parallax;
17401824 display.modelParams7[3] = 0;
17411825
1742
- display.modelParams6[0] = 100; // criss de bug de bump
1826
+ //display.modelParams6[0] = 100; // criss de bug de bump
17431827
1744
- Object3D.cVector2[] extparams = display.vector2buffer;
1828
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
17451829 if (extparams != null && extparams.length > 0 && extparams[0] != null)
17461830 {
17471831 display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
....@@ -1883,7 +1967,7 @@
18831967 void PushMatrix(double[][] matrix)
18841968 {
18851969 // GrafreeD.tracein(matrix);
1886
- PushMatrix(matrix,1);
1970
+ PushMatrix(matrix, 1);
18871971 }
18881972
18891973 void PushMatrix()
....@@ -1969,9 +2053,9 @@
19692053 switch(viewcode)
19702054 {
19712055 case 0: return "main";
1972
- case 1: return "one";
1973
- case 2: return "two";
1974
- case 3: return "three";
2056
+ case 1: return "Red";
2057
+ case 2: return "Green";
2058
+ case 3: return "Blue";
19752059 case 4: return "light";
19762060 }
19772061
....@@ -2037,7 +2121,7 @@
20372121 //System.err.println("Oeil on");
20382122 OEIL = true;
20392123 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2040
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2124
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
20412125 //pingthread.StepToTarget(true);
20422126 }
20432127
....@@ -2135,7 +2219,7 @@
21352219 System.err.println("LIVE = " + Globals.isLIVE());
21362220
21372221 if (!Globals.isLIVE()) // save sound
2138
- GrafreeD.savesound = true; // wav.save();
2222
+ Grafreed.savesound = true; // wav.save();
21392223 // else
21402224 repaint(); // start loop // may 2013
21412225 }
....@@ -2168,6 +2252,11 @@
21682252 public void ToggleBoxMode()
21692253 {
21702254 BOXMODE ^= true;
2255
+ }
2256
+
2257
+ public void ToggleZoomBoxMode()
2258
+ {
2259
+ ZOOMBOXMODE ^= true;
21712260 }
21722261
21732262 public void ToggleSmoothFocus()
....@@ -2247,7 +2336,7 @@
22472336
22482337 void ToggleDebug()
22492338 {
2250
- DEBUG ^= true;
2339
+ Globals.DEBUG ^= true;
22512340 }
22522341
22532342 void ToggleLookAt()
....@@ -2255,9 +2344,9 @@
22552344 LOOKAT ^= true;
22562345 }
22572346
2258
- void ToggleRandom()
2347
+ void ToggleSwitch()
22592348 {
2260
- RANDOM ^= true;
2349
+ SWITCH ^= true;
22612350 }
22622351
22632352 void ToggleHandles()
....@@ -2265,10 +2354,17 @@
22652354 HANDLES ^= true;
22662355 }
22672356
2357
+ Object3D paintFolder;
2358
+
22682359 void TogglePaint()
22692360 {
22702361 PAINTMODE ^= true;
22712362 paintcount = 0;
2363
+
2364
+ if (PAINTMODE)
2365
+ {
2366
+ paintFolder = GetFolder();
2367
+ }
22722368 }
22732369
22742370 void SwapCamera(int a, int b)
....@@ -2364,7 +2460,34 @@
23642460 {
23652461 return currentGL;
23662462 }
2367
-
2463
+
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
+
23682491 /**/
23692492 class CacheTexture
23702493 {
....@@ -2373,28 +2496,31 @@
23732496
23742497 int resolution;
23752498
2376
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2499
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
23772500 {
2378
- texture = tex;
2501
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2502
+ texturedata = texdata;
23792503 resolution = res;
23802504 }
23812505 }
23822506 /**/
23832507
23842508 // TEXTURE static Texture texture;
2385
- static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures
2386
- = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>();
2387
- 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
+
23882514 int pigmentdepth = 0;
23892515 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
23902516 int bumpdepth = 0;
23912517 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
23922518 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
23932519 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2394
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2520
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
23952521 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
23962522
2397
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2523
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
23982524 {
23992525 TextureData texturedata = null;
24002526
....@@ -2404,7 +2530,7 @@
24042530 com.sun.opengl.util.texture.TextureIO.newTextureData(
24052531 getClass().getClassLoader().getResourceAsStream(name),
24062532 true,
2407
- com.sun.opengl.util.texture.TextureIO.PNG);
2533
+ GetFormat(name)); // com.sun.opengl.util.texture.TextureIO.PNG);
24082534 } catch (java.io.IOException e)
24092535 {
24102536 throw new javax.media.opengl.GLException(e);
....@@ -2413,13 +2539,34 @@
24132539 if (bump)
24142540 texturedata = ConvertBump(texturedata, false);
24152541
2416
- com.sun.opengl.util.texture.Texture texture =
2417
- 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);
24182544
2419
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2420
- 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);
24212547
2422
- 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;
24232570 }
24242571
24252572 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3492,6 +3639,8 @@
34923639
34933640 System.out.println("LOADING TEXTURE : " + name);
34943641
3642
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3643
+
34953644 //
34963645 if (false) // compressbit > 0)
34973646 {
....@@ -4196,6 +4345,7 @@
41964345
41974346 com.sun.opengl.util.texture.Texture CompressTexture2(String name)
41984347 {
4348
+ new Exception().printStackTrace();
41994349 System.exit(0);
42004350 com.sun.opengl.util.texture.Texture texture = null;
42014351
....@@ -7889,7 +8039,7 @@
78898039 String pigment = Object3D.GetPigment(tex);
78908040 String bump = Object3D.GetBump(tex);
78918041
7892
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8042
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
78938043 {
78948044 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
78958045 // System.out.println("; bump = " + bump);
....@@ -7904,11 +8054,69 @@
79048054 pigment = null;
79058055 }
79068056
7907
- ReleaseTexture(bump, true);
7908
- ReleaseTexture(pigment, false);
8057
+ ReleaseTexture(tex, true);
8058
+ ReleaseTexture(tex, false);
79098059 }
79108060
7911
- void ReleaseTexture(String tex, boolean bump)
8061
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
8062
+ {
8063
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8064
+ {
8065
+ return;
8066
+ }
8067
+
8068
+ if (tex == null)
8069
+ {
8070
+ ReleaseTexture(null, false);
8071
+ return;
8072
+ }
8073
+
8074
+ String pigment = Object3D.GetPigment(tex);
8075
+
8076
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8077
+ {
8078
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8079
+ // System.out.println("; bump = " + bump);
8080
+ }
8081
+
8082
+ if (pigment.equals(""))
8083
+ {
8084
+ pigment = null;
8085
+ }
8086
+
8087
+ ReleaseTexture(tex, false);
8088
+ }
8089
+
8090
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
8091
+ {
8092
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8093
+ {
8094
+ return;
8095
+ }
8096
+
8097
+ if (tex == null)
8098
+ {
8099
+ ReleaseTexture(null, true);
8100
+ return;
8101
+ }
8102
+
8103
+ String bump = Object3D.GetBump(tex);
8104
+
8105
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8106
+ {
8107
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8108
+ // System.out.println("; bump = " + bump);
8109
+ }
8110
+
8111
+ if (bump.equals(""))
8112
+ {
8113
+ bump = null;
8114
+ }
8115
+
8116
+ ReleaseTexture(tex, true);
8117
+ }
8118
+
8119
+ void ReleaseTexture(cTexture tex, boolean bump)
79128120 {
79138121 if (// DrawMode() != 0 || /*tex == null ||*/
79148122 ambientOcclusion ) // || !textureon)
....@@ -7919,7 +8127,7 @@
79198127 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
79208128
79218129 if (tex != null)
7922
- texture = textures.get(tex);
8130
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
79238131
79248132 // //assert( texture != null );
79258133 // if (texture == null)
....@@ -8011,7 +8219,55 @@
80118219 }
80128220 }
80138221
8014
- /*boolean*/ public void BindTextures(cTexture tex, int resolution) // INTERFACE
8222
+ /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
8223
+ {
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;
8265
+
8266
+ BindPigmentTexture(tex, resolution);
8267
+ BindBumpTexture(tex, resolution);
8268
+ }
8269
+
8270
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
80158271 {
80168272 if (// DrawMode() != 0 || /*tex == null ||*/
80178273 ambientOcclusion ) // || !textureon)
....@@ -8022,17 +8278,47 @@
80228278 if (tex == null)
80238279 {
80248280 BindTexture(null,false,resolution);
8025
- BindTexture(null,true,resolution);
80268281 return;
80278282 }
80288283
80298284 String pigment = Object3D.GetPigment(tex);
8285
+
8286
+ usedtextures.add(tex);
8287
+
8288
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8289
+ {
8290
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8291
+ // System.out.println("; bump = " + bump);
8292
+ }
8293
+
8294
+ if (pigment.equals(""))
8295
+ {
8296
+ pigment = null;
8297
+ }
8298
+
8299
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8300
+ BindTexture(tex, false, resolution);
8301
+ }
8302
+
8303
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8304
+ {
8305
+ if (// DrawMode() != 0 || /*tex == null ||*/
8306
+ ambientOcclusion ) // || !textureon)
8307
+ {
8308
+ return; // false;
8309
+ }
8310
+
8311
+ if (tex == null)
8312
+ {
8313
+ BindTexture(null,true,resolution);
8314
+ return;
8315
+ }
8316
+
80308317 String bump = Object3D.GetBump(tex);
80318318
8032
- usedtextures.put(pigment, pigment);
8033
- usedtextures.put(bump, bump);
8319
+ usedtextures.add(tex);
80348320
8035
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8321
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
80368322 {
80378323 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
80388324 // System.out.println("; bump = " + bump);
....@@ -8042,43 +8328,94 @@
80428328 {
80438329 bump = null;
80448330 }
8045
- if (pigment.equals(""))
8046
- {
8047
- pigment = null;
8048
- }
80498331
8050
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8051
- BindTexture(pigment, false, resolution);
80528332 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8053
- BindTexture(bump, true, resolution);
8333
+ BindTexture(tex, true, resolution);
80548334 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8055
-
8056
- return; // true;
80578335 }
80588336
8059
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution)
8337
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8338
+
8339
+ private boolean FileExists(String tex)
80608340 {
8061
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8341
+ if (missingTextures.contains(tex))
8342
+ {
8343
+ return false;
8344
+ }
8345
+
8346
+ boolean fileExists = new File(tex).exists();
8347
+
8348
+ if (!fileExists)
8349
+ {
8350
+ // If file exists, the "new File()" is not executed sgain
8351
+ missingTextures.add(tex);
8352
+ }
8353
+
8354
+ return fileExists;
8355
+ }
8356
+
8357
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
8358
+ {
8359
+ CacheTexture texturecache = null;
80628360
80638361 if (tex != null)
80648362 {
8065
- String texname = tex;
8363
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8364
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
80668365
8067
- String[] split = tex.split("Textures");
8068
- if (split.length > 1)
8069
- texname = "/Users/nbriere/Textures" + split[split.length-1];
8070
- else
8071
- if (!texname.startsWith("/"))
8072
- texname = "/Users/nbriere/Textures/" + texname;
8366
+ if (texname.equals("") && texdata == null)
8367
+ {
8368
+ return null;
8369
+ }
8370
+
8371
+ String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
8372
+
8373
+// String[] split = tex.split("Textures");
8374
+// if (split.length > 1)
8375
+// texname = "/Users/nbriere/Textures" + split[split.length-1];
8376
+// else
8377
+// if (!texname.startsWith("/"))
8378
+// texname = "/Users/nbriere/Textures/" + texname;
8379
+ if (!FileExists(texname) && !texname.startsWith("@"))
8380
+ {
8381
+ texname = fallbackTextureName;
8382
+ }
80738383
80748384 if (CACHETEXTURE)
8075
- texture = textures.get(texname); // TEXTURE CACHE
8076
-
8077
- TextureData texturedata = null;
8078
-
8079
- if (texture == null || texture.resolution < resolution)
80808385 {
8081
- 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(""))
80828419 {
80838420 assert(!bump);
80848421 // if (bump)
....@@ -8089,19 +8426,23 @@
80898426 // }
80908427 // else
80918428 // {
8092
- texture = textures.get(tex);
8093
- if (texture == null)
8429
+ // texturecache = textures.get(texname); // suspicious
8430
+ if (texturecache == null)
80948431 {
8095
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8432
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
80968433 }
8434
+ else
8435
+ new Exception().printStackTrace();
80978436 // }
80988437 } else
8099
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8438
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
81008439 {
81018440 assert(bump);
8102
- texture = textures.get(tex);
8103
- if (texture == null)
8104
- 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();
81058446 } else
81068447 {
81078448 //if (tex.equals("IMMORTAL"))
....@@ -8109,11 +8450,22 @@
81098450 // texture = GetResourceTexture("default.png");
81108451 //} else
81118452 //{
8112
- if (tex.equals("WHITE_NOISE"))
8453
+ if (texname.endsWith("WHITE_NOISE"))
81138454 {
8114
- texture = textures.get(tex);
8115
- if (texture == null)
8116
- 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();
81178469 } else
81188470 {
81198471 if (textureon)
....@@ -8138,7 +8490,7 @@
81388490 }
81398491
81408492 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
8141
- if (!new File(cachename).exists())
8493
+ if (!FileExists(cachename))
81428494 cachename = texname;
81438495 else
81448496 processbump = false; // don't process bump map again
....@@ -8160,7 +8512,7 @@
81608512 }
81618513
81628514 cachename = texname.substring(0, texname.length()-4)+ext+".png";
8163
- if (!new File(cachename).exists())
8515
+ if (!FileExists(cachename))
81648516 cachename = texname;
81658517 else
81668518 processbump = false; // don't process bump map again
....@@ -8169,20 +8521,23 @@
81698521 texturedata = GetFileTexture(cachename, processbump, resolution);
81708522
81718523
8172
- if (texturedata != null)
8173
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8524
+ if (texturedata == null)
8525
+ throw new Exception();
8526
+
8527
+ texturecache = new CacheTexture(texturedata,resolution);
81748528 //texture = GetTexture(tex, bump);
81758529 }
8530
+ }
81768531 }
81778532 //}
81788533 }
81798534
8180
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8535
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
81818536 {
81828537 //return false;
81838538
81848539 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8185
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8540
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
81868541 {
81878542 // String ext = "_highres";
81888543 // if (REDUCETEXTURE)
....@@ -8199,52 +8554,17 @@
81998554 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
82008555 if (!cachefile.exists())
82018556 {
8202
- // cache to disk
8203
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
8204
- //buffers[0].
8205
-
8206
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
8207
- int[] pixels = new int[bytebuf.capacity()/3];
8208
-
8209
- // squared size heuristic...
8210
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8557
+ //if (texturedata.getWidth() == texturedata.getHeight())
82118558 {
8212
- for (int i=pixels.length; --i>=0;)
8213
- {
8214
- int i3 = i*3;
8215
- pixels[i] = 0xFF;
8216
- pixels[i] <<= 8;
8217
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
8218
- pixels[i] <<= 8;
8219
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
8220
- pixels[i] <<= 8;
8221
- pixels[i] |= bytebuf.get(i3) & 0xFF;
8222
- }
8223
-
8224
- /*
8225
- int r=0,g=0,b=0,a=0;
8226
- for (int i=0; i<width; i++)
8227
- for (int j=0; j<height; j++)
8228
- {
8229
- int index = j*width+i;
8230
- int p = pixels[index];
8231
- a = ((p>>24) & 0xFF);
8232
- r = ((p>>16) & 0xFF);
8233
- g = ((p>>8) & 0xFF);
8234
- b = (p & 0xFF);
8235
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
8236
- }
8237
- /**/
8238
- int width = (int)Math.sqrt(pixels.length); // squared
8239
- int height = width;
8240
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
8241
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8559
+ BufferedImage rendImage = CreateBim(texturedata);
8560
+
82428561 ImageWriter writer = null;
82438562 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
82448563 if (iter.hasNext()) {
82458564 writer = (ImageWriter)iter.next();
82468565 }
8247
- float compressionQuality = 0.9f;
8566
+
8567
+ float compressionQuality = 0.85f;
82488568 try
82498569 {
82508570 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8261,18 +8581,20 @@
82618581 }
82628582 }
82638583 }
8264
-
8584
+
8585
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8586
+
82658587 //System.out.println("Texture = " + tex);
8266
- if (textures.containsKey(texname))
8588
+ if (textures.containsKey(tex))
82678589 {
8268
- CacheTexture thetex = textures.get(texname);
8590
+ CacheTexture thetex = textures.get(tex);
82698591 thetex.texture.disable();
82708592 thetex.texture.dispose();
8271
- textures.remove(texname);
8593
+ textures.remove(tex);
82728594 }
82738595
8274
- texture.texturedata = texturedata;
8275
- textures.put(texname, texture);
8596
+ //texture.texturedata = texturedata;
8597
+ textures.put(tex, texturecache);
82768598
82778599 // newtex = true;
82788600 }
....@@ -8288,10 +8610,44 @@
82888610 }
82898611 }
82908612
8291
- return texture;
8613
+ return texturecache;
82928614 }
82938615
8294
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution)
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
82958651 {
82968652 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
82978653
....@@ -8309,21 +8665,21 @@
83098665 return texture!=null?texture.texture:null;
83108666 }
83118667
8312
- public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution)
8668
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
83138669 {
83148670 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
83158671
83168672 return texture!=null?texture.texturedata:null;
83178673 }
83188674
8319
- boolean BindTexture(String tex, boolean bump, int resolution)
8675
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
83208676 {
83218677 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
83228678 {
83238679 return false;
83248680 }
83258681
8326
- boolean newtex = false;
8682
+ //boolean newtex = false;
83278683
83288684 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
83298685
....@@ -8355,9 +8711,75 @@
83558711 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
83568712 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
83578713
8358
- return newtex;
8714
+ return true; // Warning: not used.
83598715 }
83608716
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
+
83618783 ShadowBuffer shadowPBuf;
83628784 AntialiasBuffer antialiasPBuf;
83638785 int MAXSTACK;
....@@ -8374,10 +8796,12 @@
83748796
83758797 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
83768798 MAXSTACK = temp[0];
8377
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8799
+ if (Globals.DEBUG)
8800
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
83788801 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
83798802 MAXSTACK = temp[0];
8380
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8803
+ if (Globals.DEBUG)
8804
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
83818805
83828806 // Use debug pipeline
83838807 //drawable.setGL(new DebugGL(gl)); //
....@@ -8385,7 +8809,8 @@
83858809 gl = drawable.getGL(); //
83868810
83878811 GL gl3 = getGL();
8388
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8812
+ if (Globals.DEBUG)
8813
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
83898814
83908815
83918816 //float pos[] = { 100, 100, 100, 0 };
....@@ -8550,7 +8975,7 @@
85508975
85518976 if (cubemap == null)
85528977 {
8553
- LoadEnvy(5);
8978
+ //LoadEnvy(1);
85548979 }
85558980
85568981 //cubemap.enable();
....@@ -8826,6 +9251,8 @@
88269251
88279252 void LoadEnvy(int which)
88289253 {
9254
+ assert(false);
9255
+
88299256 String name;
88309257 String ext;
88319258
....@@ -8837,37 +9264,58 @@
88379264 cubemap = null;
88389265 return;
88399266 case 1:
8840
- name = "cubemaps/box_";
8841
- ext = "png";
9267
+ name = "cubemaps/rgb/";
9268
+ ext = "jpg";
88429269 reverseUP = false;
88439270 break;
88449271 case 2:
8845
- name = "cubemaps/uffizi_";
8846
- ext = "png";
8847
- break; // reverseUP = true; break;
9272
+ name = "cubemaps/uffizi/";
9273
+ ext = "jpg";
9274
+ reverseUP = false;
9275
+ break;
88489276 case 3:
8849
- name = "cubemaps/CloudyHills_";
8850
- ext = "tga";
9277
+ name = "cubemaps/CloudyHills/";
9278
+ ext = "jpg";
88519279 reverseUP = false;
88529280 break;
88539281 case 4:
8854
- name = "cubemaps/cornell_";
9282
+ name = "cubemaps/cornell/";
88559283 ext = "png";
88569284 reverseUP = false;
88579285 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;
88589311 default:
8859
- name = "cubemaps/rgb_";
8860
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9312
+ name = "cubemaps/box/";
9313
+ ext = "png"; /*mipmap = true;*/
9314
+ reverseUP = false;
88619315 break;
88629316 }
8863
-
8864
- try
8865
- {
8866
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
8867
- } catch (IOException e)
8868
- {
8869
- throw new RuntimeException(e);
8870
- }
9317
+
9318
+ LoadSkybox(name, ext, mipmap);
88719319 }
88729320
88739321 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -8899,8 +9347,12 @@
88999347 static double[] model = new double[16];
89009348 double[] camera2light = new double[16];
89019349 double[] light2camera = new double[16];
8902
- int newenvy = -1;
8903
- boolean envyoff = true; // false;
9350
+
9351
+ //int newenvy = -1;
9352
+ //boolean envyoff = false;
9353
+
9354
+ String loadedskyboxname;
9355
+
89049356 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
89059357 //float[] light0 = { 0,0,0 };
89069358 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9193,11 +9645,35 @@
91939645 jy8[3] = 0.5f;
91949646 }
91959647
9196
- 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
91979649 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
91989650 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
91999651 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
92009652
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
+
92019677 static int imagecount = 0; // movie generation
92029678
92039679 static int jitter = 0;
....@@ -9293,8 +9769,8 @@
92939769 assert (parentcam != renderCamera);
92949770
92959771 if (renderCamera != lightCamera)
9296
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9297
- LA.matConcat(matrix, parentcam.toParent, matrix);
9772
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9773
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
92989774
92999775 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
93009776
....@@ -9309,8 +9785,8 @@
93099785 LA.matCopy(renderCamera.fromScreen, matrix);
93109786
93119787 if (renderCamera != lightCamera)
9312
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9313
- LA.matConcat(parentcam.fromParent, matrix, matrix);
9788
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9789
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
93149790
93159791 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
93169792
....@@ -9356,10 +9832,12 @@
93569832 rati = 1 / rati;
93579833 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
93589834 }
9359
- assert (newenvy == -1);
9835
+
9836
+ //assert (newenvy == -1);
9837
+
93609838 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
93619839 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9362
- DrawSkyBox(gl);
9840
+ DrawSkyBox(gl, (float)rati);
93639841 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
93649842 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
93659843 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -9382,7 +9860,7 @@
93829860 //gl.glFlush();
93839861 gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE);
93849862
9385
- if (ANIMATION && ABORTED)
9863
+ if (Globals.ANIMATION && ABORTED)
93869864 {
93879865 System.err.println(" ABORTED FRAME");
93889866 break;
....@@ -9412,7 +9890,7 @@
94129890 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
94139891
94149892 // save image
9415
- if (ANIMATION && !ABORTED)
9893
+ if (Globals.ANIMATION && !ABORTED)
94169894 {
94179895 VPwidth = viewport[2];
94189896 VPheight = viewport[3];
....@@ -9523,11 +10001,11 @@
952310001
952410002 // imagecount++;
952510003
9526
- String fullname = filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
10004
+ String fullname = Globals.filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
952710005
952810006 if (!BOXMODE)
952910007 {
9530
- System.out.println("image: " + fullname + " (wav cursor=" + (GrafreeD.wav.cursor / 735 / 4) + ")");
10008
+ System.out.println("image: " + fullname + " (wav cursor=" + (Grafreed.wav.cursor / 735 / 4) + ")");
953110009 }
953210010
953310011 if (!BOXMODE)
....@@ -9565,7 +10043,7 @@
956510043 ABORTED = false;
956610044 }
956710045 else
9568
- GrafreeD.wav.cursor += 735 * ACSIZE;
10046
+ Grafreed.wav.cursor += 735 * ACSIZE;
956910047
957010048 if (false)
957110049 {
....@@ -10225,14 +10703,23 @@
1022510703 static boolean init = false;
1022610704
1022710705 double[][] matrix = LA.newMatrix();
10706
+
10707
+ // This is to refresh the UI of the material panel.
10708
+ ObjEditor patchMaterial;
1022810709
1022910710 public void display(GLAutoDrawable drawable)
1023010711 {
10231
- if (GrafreeD.savesound && GrafreeD.hassound)
10712
+ if (patchMaterial.patchMaterial)
1023210713 {
10233
- GrafreeD.wav.save();
10234
- GrafreeD.savesound = false;
10235
- GrafreeD.hassound = false;
10714
+ patchMaterial.patchMaterial = false;
10715
+ patchMaterial.objectPanel.setSelectedIndex(1);
10716
+ }
10717
+
10718
+ if (Grafreed.savesound && Grafreed.hassound)
10719
+ {
10720
+ Grafreed.wav.save();
10721
+ Grafreed.savesound = false;
10722
+ Grafreed.hassound = false;
1023610723 }
1023710724 // if (DEBUG_SELECTION)
1023810725 // {
....@@ -10308,6 +10795,7 @@
1030810795 ANTIALIAS = 0;
1030910796 //System.out.println("RESTART");
1031010797 AAtimer.restart();
10798
+ Globals.TIMERRUNNING = true;
1031110799 }
1031210800 }
1031310801 }
....@@ -10362,7 +10850,7 @@
1036210850 Object3D theobject = object;
1036310851 Object3D theparent = object.parent;
1036410852 object.parent = null;
10365
- object = (Object3D)GrafreeD.clone(object);
10853
+ object = (Object3D)Grafreed.clone(object);
1036610854 object.Stripify();
1036710855 if (theobject.selection == null || theobject.selection.Size() == 0)
1036810856 theobject.PreprocessOcclusion(this);
....@@ -10375,13 +10863,14 @@
1037510863 ambientOcclusion = false;
1037610864 }
1037710865
10378
- if (Globals.lighttouched && DrawMode() == DEFAULT && !lightMode) // && !FROZEN)
10866
+ if (//Globals.lighttouched &&
10867
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1037910868 {
1038010869 //if (RENDERSHADOW) // ?
1038110870 if (!IsFrozen())
1038210871 {
1038310872 // dec 2012
10384
- if (!ambientOcclusion && !(!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0))
10873
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
1038510874 {
1038610875 Globals.framecount++;
1038710876 shadowbuffer.display();
....@@ -10394,7 +10883,7 @@
1039410883
1039510884 if (wait)
1039610885 {
10397
- Sleep(500);
10886
+ Sleep(200); // blocks everything
1039810887
1039910888 wait = false;
1040010889 }
....@@ -10508,8 +10997,8 @@
1050810997
1050910998 // if (parentcam != renderCamera) // not a light
1051010999 if (cam != lightCamera)
10511
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10512
- LA.matConcat(matrix, parentcam.toParent, matrix);
11000
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11001
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1051311002
1051411003 for (int j = 0; j < 4; j++)
1051511004 {
....@@ -10523,8 +11012,8 @@
1052311012
1052411013 // if (parentcam != renderCamera) // not a light
1052511014 if (cam != lightCamera)
10526
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10527
- LA.matConcat(parentcam.fromParent, matrix, matrix);
11015
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11016
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1052811017
1052911018 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1053011019
....@@ -10610,13 +11099,43 @@
1061011099 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1061111100 }
1061211101
10613
- 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"))
1061411110 {
10615
- LoadEnvy(newenvy);
11111
+ if (cubemaprgb == null)
11112
+ {
11113
+ cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb2" + "/", "jpg", false);
11114
+ }
11115
+
11116
+ cubemap = cubemaprgb;
1061611117 }
10617
-
10618
- newenvy = -1;
10619
-
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
+
1062011139 ratio = ((double) getWidth()) / getHeight();
1062111140 //System.out.println("ratio = " + ratio);
1062211141
....@@ -10632,7 +11151,7 @@
1063211151
1063311152 if (!IsFrozen() && !ambientOcclusion)
1063411153 {
10635
- DrawSkyBox(gl);
11154
+ DrawSkyBox(gl, (float)ratio);
1063611155 }
1063711156
1063811157 //if (selection_view == -1)
....@@ -10783,7 +11302,16 @@
1078311302 // Bump noise
1078411303 gl.glActiveTexture(GL.GL_TEXTURE6);
1078511304 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
10786
- BindTexture(NOISE_TEXTURE, false, 2);
11305
+
11306
+ try
11307
+ {
11308
+ BindTexture(NOISE_TEXTURE, false, 2);
11309
+ }
11310
+ catch (Exception e)
11311
+ {
11312
+ System.err.println("FAILED: " + NOISE_TEXTURE);
11313
+ }
11314
+
1078711315
1078811316 gl.glActiveTexture(GL.GL_TEXTURE0);
1078911317 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -10806,9 +11334,9 @@
1080611334
1080711335 gl.glMatrixMode(GL.GL_MODELVIEW);
1080811336
10809
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10810
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10811
-//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);
1081211340 } else
1081311341 {
1081411342 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -10819,7 +11347,7 @@
1081911347 //System.out.println("BLENDING ON");
1082011348 gl.glEnable(GL.GL_BLEND);
1082111349 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
10822
-
11350
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1082311351 gl.glMatrixMode(gl.GL_PROJECTION);
1082411352 gl.glLoadIdentity();
1082511353
....@@ -10908,8 +11436,8 @@
1090811436 System.err.println("parentcam != renderCamera");
1090911437
1091011438 // if (cam != lightCamera)
10911
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10912
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11439
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11440
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1091311441 }
1091411442
1091511443 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -10930,8 +11458,8 @@
1093011458 if (true) // TODO
1093111459 {
1093211460 if (cam != lightCamera)
10933
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10934
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11461
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11462
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
1093511463 }
1093611464
1093711465 LA.xformPos(light0, cam.toScreen, light0);
....@@ -11068,7 +11596,7 @@
1106811596 }
1106911597 }
1107011598
11071
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11599
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1107211600 {
1107311601 //gl.glDepthFunc(GL.GL_LEQUAL);
1107411602 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11076,24 +11604,21 @@
1107611604
1107711605 boolean texon = textureon;
1107811606
11079
- if (RENDERPROGRAM > 0)
11080
- {
11081
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11082
- textureon = false;
11083
- }
11607
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11608
+ textureon = false;
11609
+
1108411610 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1108511611 //System.out.println("ALLO");
1108611612 gl.glColorMask(false, false, false, false);
1108711613 DrawObject(gl);
11088
- if (RENDERPROGRAM > 0)
11089
- {
11090
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11091
- textureon = texon;
11092
- }
11614
+
11615
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11616
+ textureon = texon;
11617
+
1109311618 gl.glColorMask(true, true, true, true);
1109411619
1109511620 gl.glDepthFunc(GL.GL_EQUAL);
11096
- //gl.glDepthMask(false);
11621
+ gl.glDepthMask(false);
1109711622 }
1109811623
1109911624 if (false) // DrawMode() == SHADOW)
....@@ -11247,8 +11772,14 @@
1124711772 {
1124811773 renderpass++;
1124911774 // System.out.println("Draw object... ");
11775
+ STEP = 1;
1125011776 if (FAST) // in case there is no script
11251
- STEP = 16;
11777
+ STEP = 8;
11778
+
11779
+ if (CURRENTANTIALIAS == 0 || ACSIZE == 1)
11780
+ {
11781
+ STEP *= 4;
11782
+ }
1125211783
1125311784 //object.FullInvariants();
1125411785
....@@ -11262,23 +11793,44 @@
1126211793 e.printStackTrace();
1126311794 }
1126411795
11265
- if (GrafreeD.RENDERME > 0)
11266
- GrafreeD.RENDERME--; // mechante magouille
11796
+ if (Grafreed.RENDERME > 0)
11797
+ Grafreed.RENDERME--; // mechante magouille
1126711798
1126811799 Globals.ONESTEP = false;
1126911800 }
1127011801
1127111802 static boolean zoomonce = false;
1127211803
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
+
1127311822 void DrawObject(GL gl, boolean draw)
1127411823 {
11824
+ // To clear camera values
11825
+ ResetOptions();
11826
+
1127511827 //System.out.println("DRAW OBJECT " + mouseDown);
1127611828 // DrawMode() = SELECTION;
1127711829 //GL gl = getGL();
1127811830 if ((TRACK || SHADOWTRACK) || zoomonce)
1127911831 {
1128011832 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11281
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11833
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1128211834 pingthread.StepToTarget(true); // true);
1128311835 // zoomonce = false;
1128411836 }
....@@ -11333,7 +11885,14 @@
1133311885
1133411886 usedtextures.clear();
1133511887
11336
- BindTextures(DEFAULT_TEXTURES, 2);
11888
+ try
11889
+ {
11890
+ BindTextures(DEFAULT_TEXTURES, 2);
11891
+ }
11892
+ catch (Exception e)
11893
+ {
11894
+ System.err.println("FAILED: " + DEFAULT_TEXTURES);
11895
+ }
1133711896 }
1133811897 //System.out.println("--> " + stackdepth);
1133911898 // GrafreeD.traceon();
....@@ -11343,8 +11902,9 @@
1134311902
1134411903 if (DrawMode() == DEFAULT)
1134511904 {
11346
- if (DEBUG)
11905
+ if (Globals.DEBUG)
1134711906 {
11907
+ CreateSelectedPoint();
1134811908 float radius = 0.05f;
1134911909 if (selectedpoint.radius != radius)
1135011910 {
....@@ -11398,20 +11958,32 @@
1139811958 ReleaseTextures(DEFAULT_TEXTURES);
1139911959
1140011960 if (CLEANCACHE)
11401
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11961
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1140211962 {
11403
- String tex = e.nextElement();
11963
+ cTexture tex = e.nextElement();
1140411964
1140511965 // System.out.println("Texture --------- " + tex);
1140611966
11407
- if (tex.equals("WHITE_NOISE"))
11967
+ if (tex.equals("WHITE_NOISE:"))
1140811968 continue;
1140911969
11410
- if (!usedtextures.containsKey(tex))
11970
+ if (!usedtextures.contains(tex))
1141111971 {
11972
+ CacheTexture gettex = texturepigment.get(tex);
1141211973 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11413
- textures.get(tex).texture.dispose();
11414
- 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
+ }
1141511987 }
1141611988 }
1141711989 }
....@@ -11424,7 +11996,14 @@
1142411996 if (checker != null && DrawMode() == DEFAULT)
1142511997 {
1142611998 //BindTexture(IMMORTAL_TEXTURE);
11427
- BindTextures(checker.GetTextures(), checker.texres);
11999
+ try
12000
+ {
12001
+ BindTextures(checker.GetTextures(), checker.texres);
12002
+ }
12003
+ catch (Exception e)
12004
+ {
12005
+ System.err.println("FAILED: " + checker.GetTextures());
12006
+ }
1142812007 // NEAREST
1142912008 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
1143012009 DrawChecker(gl);
....@@ -11506,7 +12085,7 @@
1150612085 return;
1150712086 }
1150812087
11509
- String string = obj.GetToolTip();
12088
+ String string = obj.toString(); //.GetToolTip();
1151012089
1151112090 GL gl = GetGL();
1151212091
....@@ -11823,8 +12402,8 @@
1182312402 //obj.TransformToWorld(light, light);
1182412403 for (int i = tp.size(); --i >= 0;)
1182512404 {
11826
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
11827
- LA.xformPos(light, tp.get(i).toParent, light);
12405
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12406
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1182812407 }
1182912408
1183012409
....@@ -11841,8 +12420,8 @@
1184112420 parentcam = cameras[0];
1184212421 }
1184312422
11844
- for (int count = parentcam.GetTransformCount(); --count>=0;)
11845
- LA.xformPos(light, parentcam.toParent, light); // may 2013
12423
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
12424
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1184612425
1184712426 LA.xformPos(light, renderCamera.toScreen, light);
1184812427
....@@ -11932,8 +12511,82 @@
1193212511
1193312512 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1193412513
11935
- String program =
12514
+ String programmin =
12515
+ // Min shader
1193612516 "!!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
+
1193712590 //"OPTION ARB_fragment_program_shadow;" +
1193812591 "PARAM light2cam0 = program.env[10];" +
1193912592 "PARAM light2cam1 = program.env[11];" +
....@@ -11959,7 +12612,7 @@
1195912612 "PARAM params4 = program.env[4];" + // anisoV, cameralight, selfshadow, shadow
1196012613 "PARAM params5 = program.env[5];" + // texture, opacity, fakedepth, shadowbias
1196112614 "PARAM params6 = program.env[6];" + // bump, noise, borderfade, fog punchthrough
11962
- "PARAM params7 = program.env[7];" + // noise power, opacity power
12615
+ "PARAM params7 = program.env[7];" + // noise power, opacity power, parallax
1196312616 "PARAM options0 = program.env[63];" + // fog density, intensity, elevation
1196412617 "PARAM options1 = program.env[62];" + // fog rgb color
1196512618 "PARAM options2 = program.env[61];" + // image intensity, subsurface, lightsheen
....@@ -12048,8 +12701,7 @@
1204812701 "TEMP shininess;" +
1204912702 "\n" +
1205012703 "MOV texSamp, one;" +
12051
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12052
-
12704
+
1205312705 "MOV mapgrid.x, one2048th.x;" +
1205412706 "MOV temp, fragment.texcoord[1];" +
1205512707 /*
....@@ -12070,20 +12722,20 @@
1207012722 "MUL temp, floor, mapgrid.x;" +
1207112723 //"TEX depth0, temp, texture[1], 2D;" +
1207212724 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12073
- TextureFetch("depth0", "temp", "1") +
12725
+ ShadowTextureFetch("depth0", "temp", "1") +
1207412726 "") +
1207512727 "ADD temp.x, temp.x, mapgrid.x;" +
1207612728 //"TEX depth1, temp, texture[1], 2D;" +
1207712729 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12078
- TextureFetch("depth1", "temp", "1") +
12730
+ ShadowTextureFetch("depth1", "temp", "1") +
1207912731 "") +
1208012732 "ADD temp.y, temp.y, mapgrid.x;" +
1208112733 //"TEX depth2, temp, texture[1], 2D;" +
12082
- TextureFetch("depth2", "temp", "1") +
12734
+ ShadowTextureFetch("depth2", "temp", "1") +
1208312735 "SUB temp.x, temp.x, mapgrid.x;" +
1208412736 //"TEX depth3, temp, texture[1], 2D;" +
1208512737 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12086
- TextureFetch("depth3", "temp", "1") +
12738
+ ShadowTextureFetch("depth3", "temp", "1") +
1208712739 "") +
1208812740 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1208912741 //"MOV params, material;" +
....@@ -12205,7 +12857,7 @@
1220512857 "POW texSamp.a, texSamp.a, params6.w;" + // fog punch through shortcut
1220612858 // mar 2013 ??? "KIL alpha.a;" +
1220712859 "MOV alpha, texSamp.aaaa;" + // y;" +
12208
- "KIL alpha.a;" +
12860
+ "KIL alpha.a;" + // not sure with parallax mapping
1220912861 /*
1221012862 "MUL temp.xy, temp, two;" +
1221112863 "TXB bump, temp, texture[0], 2D;" +
....@@ -12291,11 +12943,6 @@
1229112943 "SUB bump0, bump0, half;" +
1229212944 "ADD bump, bump, bump0;" +
1229312945
12294
- "MOV temp.x, texSamp.a;" +
12295
- "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
12296
- //"LRP texSamp0, params5.x, texSamp0, one;" +
12297
- "MOV texSamp.a, temp.x;" +
12298
-
1229912946 // double-sided
1230012947 /**/
1230112948 (doublesided?"DP3 temp.z, normal, eye;" +
....@@ -12312,19 +12959,62 @@
1231212959 "MOV normald, normal;" +
1231312960 "MOV normals, normal;" +
1231412961
12962
+ "MOV temp, fragment.texcoord[4];" +
12963
+
1231512964 // UV base
1231612965 //"DP3 UP.x,state.matrix.modelview.row[0],Y;" +
1231712966 //"DP3 UP.y,state.matrix.modelview.row[1],Y;" +
1231812967 //"DP3 UP.z,state.matrix.modelview.row[2],Y;" +
12319
- "DP3 UP.x,state.matrix.texture[7].row[0],Y;" +
12320
- "DP3 UP.y,state.matrix.texture[7].row[1],Y;" +
12321
- "DP3 UP.z,state.matrix.texture[7].row[2],Y;" +
12968
+ "DP3 UP.x,state.matrix.texture[7].row[0],temp;" +
12969
+ "DP3 UP.y,state.matrix.texture[7].row[1],temp;" +
12970
+ "DP3 UP.z,state.matrix.texture[7].row[2],temp;" +
12971
+ Normalize("UP") +
12972
+
1232212973 "XPD V, normal, UP;" +
1232312974 Normalize("V") +
1232412975 "XPD U, V, normal;" +
1232512976 Normalize("U") +
1232612977
1232712978 // parallax mapping
12979
+
12980
+ "DP3 temp2.x, V, eye;" +
12981
+ "DP3 temp2.y, U, eye;" +
12982
+ "DP3 temp2.z, normal, eye;" +
12983
+ "RCP temp2.z, temp2.z;" +
12984
+
12985
+ "DP3 temp2.w, texSamp, texSamp;" + // Height
12986
+ "RSQ temp2.w, temp2.w;" +
12987
+ "RCP temp2.w, temp2.w;" +
12988
+
12989
+ "SUB temp2.w, temp2.w, half;" +
12990
+// "SGE temp.x, temp2.w, eps.x;" +
12991
+// "MUL temp2.w, temp2.w, temp.x;" +
12992
+
12993
+ //"MOV texSamp, U;" +
12994
+
12995
+ "MUL temp2.z, temp2.z, temp2.w;" +
12996
+ "MUL temp2.z, temp2.z, params7.z;" + // parallax
12997
+
12998
+ "MUL temp2, temp2, temp2.z;" +
12999
+
13000
+ "MOV temp, fragment.texcoord[0];" +
13001
+
13002
+ "SUB temp, temp, temp2;" +
13003
+
13004
+ "TEX temp, temp, texture[0], 2D;" +
13005
+ "POW temp.a, temp.a, params6.w;" + // punch through
13006
+
13007
+ "ADD texSamp, temp, texSamp;" +
13008
+ "MUL texSamp.xyz, half, texSamp;" +
13009
+
13010
+ "MOV alpha, texSamp.aaaa;" +
13011
+
13012
+// parallax mapping
13013
+
13014
+ "MOV temp.x, texSamp.a;" +
13015
+ "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
13016
+ //"LRP texSamp0, params5.x, texSamp0, one;" +
13017
+ "MOV texSamp.a, temp.x;" +
1232813018
1232913019 //"MOV temp, fragment.texcoord[0];" +
1233013020 //
....@@ -12454,10 +13144,10 @@
1245413144 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1245513145 "") +
1245613146
12457
- // display shadow only (bump == 0)
13147
+ // display shadow only (fakedepth == 0)
1245813148 "SUB temp.x, half.x, shadow.x;" +
12459
- "MOV temp.y, -params6.x;" +
12460
- "SLT temp.z, temp.y, zero.x;" +
13149
+ "MOV temp.y, -params5.z;" + // params6.x;" +
13150
+ "SLT temp.z, temp.y, -c256i.x;" +
1246113151 "SUB temp.y, one.x, temp.z;" +
1246213152 "MUL temp.x, temp.x, temp.y;" +
1246313153 "KIL temp.x;" +
....@@ -12586,8 +13276,10 @@
1258613276 "MAX ndotl.x, ndotl.x, -ndotl.x;" +
1258713277
1258813278 "SUB temp.x, one.x, ndotl.x;" +
12589
- "ADD temp.x, temp.x, options2.z;" + // lightsheen
12590
- "ADD temp.y, one.y, options2.y;" + // sursurface
13279
+ // Tuning for default skin
13280
+ //"ADD temp.x, temp.x, options2.z;" + // lightsheen
13281
+ "MAD temp.x, options2.z, half.y, temp.x;" + // lightsheen
13282
+ "ADD temp.y, one.y, options2.y;" + // subsurface
1259113283 "MUL temp.x, temp.x, temp.y;" +
1259213284
1259313285 "MUL saturation, saturation, temp.xxxx;" +
....@@ -12786,8 +13478,19 @@
1278613478 //once = true;
1278713479 }
1278813480
12789
- System.out.print("Program #" + mode + "; length = " + program.length());
12790
- System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13481
+ String program = programmax;
13482
+
13483
+ if (Globals.MINSHADER)
13484
+ {
13485
+ program = programmin;
13486
+ }
13487
+
13488
+ if (Globals.DEBUG)
13489
+ {
13490
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13491
+ System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13492
+ }
13493
+
1279113494 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1279213495
1279313496 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -12834,7 +13537,8 @@
1283413537 "\n" +
1283513538 "END\n";
1283613539
12837
- System.out.println("Program shadow #" + 0 + "; length = " + program.length());
13540
+ if (Globals.DEBUG)
13541
+ System.out.println("Program shadow #" + 0 + "; length = " + program.length());
1283813542 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1283913543
1284013544 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -12879,25 +13583,26 @@
1287913583 return out;
1288013584 }
1288113585
12882
- String TextureFetch(String dest, String src, String unit)
13586
+ // Also does frustum culling
13587
+ String ShadowTextureFetch(String dest, String src, String unit)
1288313588 {
1288413589 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1288513590 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1288613591 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13592
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13593
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1288713594 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12888
- "SLT " + src + ".z, " + src + ".x, one.x;" +
12889
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12890
- "SLT " + src + ".z, " + src + ".y, one.x;" +
12891
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13595
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13596
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1289213597 //"SWZ buffer, temp, w,w,w,w;";
12893
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13598
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1289413599 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1289513600 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1289613601 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
12897
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13602
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1289813603
12899
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
12900
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13604
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13605
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1290113606 }
1290213607
1290313608 String Shadow(String depth, String shadow)
....@@ -12919,12 +13624,16 @@
1291913624
1292013625 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1292113626 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13627
+
13628
+ // Compare fragment depth in light space with shadowmap.
1292213629 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1292313630 "SGE temp.y, temp.x, zero.x;" +
12924
- "SUB " + shadow + ".y, one.x, temp.y;" +
13631
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13632
+
13633
+ // Reverse comparison
1292513634 "SUB temp.x, one.x, temp.x;" +
1292613635 "MUL " + shadow + ".x, temp.x, temp.y;" +
12927
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13636
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1292813637 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1292913638
1293013639 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -12938,6 +13647,10 @@
1293813647 // No shadow for backface
1293913648 "DP3 temp.x, normal, lightd;" +
1294013649 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13650
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13651
+
13652
+ // No shadow when out of frustum
13653
+ "SGE temp.x, " + depth + ".z, one.z;" +
1294113654 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1294213655 "";
1294313656 }
....@@ -13083,8 +13796,9 @@
1308313796 /*static*/ float[] modelParams4 = new float[]{0, 0, 0, 0}; // anisoV, cameralight, selfshadow, shadow
1308413797 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1308513798 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
13086
- /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13087
- Object3D.cVector2[] vector2buffer;
13799
+ /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power, parallax
13800
+
13801
+ //Object3D.cVector2[] vector2buffer;
1308813802
1308913803 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1309013804 // OUT : diff, spec
....@@ -13100,9 +13814,10 @@
1310013814 "DP3 " + dest + ".z," + "normals," + "eye;" +
1310113815 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1310213816 //"MOV " + dest + ".w," + "normal.z;" +
13103
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
13104
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13105
- //"MOV " + dest + ".z," + "params2.w;" +
13817
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13818
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13819
+
13820
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1310613821 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1310713822 "RCP " + dest + ".w," + dest + ".w;" +
1310813823 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13248,7 +13963,7 @@
1324813963 "PARAM p[4] = { state.matrix.projection }; # modelview projection matrix\n" +
1324913964 "PARAM zero = { 0.0, 0.0, 0.0, 1.0 };" +
1325013965 "PARAM half = { 0.5, 0.5, 0.5, 1.0 };" +
13251
- "PARAM one = { 1.0, 1.0, 1.0, 0.0 };" +
13966
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
1325213967 "PARAM two = { 2.0, 2.0, 2.0, 1.0 };" +
1325313968 "PARAM third = { 0.33333333333, 0.33333333333, 0.33333333333, 1.0 };" +
1325413969 //"PARAM v256 = { 256.0, 256.0, 256.0, 1.0 };" +
....@@ -13309,7 +14024,7 @@
1330914024 "DP4 temp.x,state.matrix.texture[0].inverse.row[0],vertex.texcoord;" +
1331014025 "DP4 temp.y,state.matrix.texture[0].inverse.row[1],vertex.texcoord;" +
1331114026 "DP4 temp.z,state.matrix.texture[0].inverse.row[2],vertex.texcoord;" +
13312
- //"MOV result.texcoord, vertex.texcoord;" +
14027
+ //"MOV result.texcoord, vertex.fogcoord;" +
1331314028 "MOV result.texcoord, temp;" +
1331414029 // border fade
1331514030 "MOV result.texcoord[3], vertex.texcoord;" +
....@@ -13356,7 +14071,9 @@
1335614071
1335714072 //"ADD temp.z, temp.z, one;" +
1335814073
13359
- "MOV result.color, temp;"
14074
+ "MOV result.texcoord[4], vertex.attrib[4];" + // U dir
14075
+
14076
+ "MOV result.color, temp;" // Normal
1336014077 : "MOV result.color, vertex.color;") +
1336114078 ((mode & VP_PROJECTION) != 0 ? "MOV result.color, zero;"
1336214079 : "") +
....@@ -13496,7 +14213,7 @@
1349614213 public void mousePressed(MouseEvent e)
1349714214 {
1349814215 //System.out.println("mousePressed: " + e);
13499
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14216
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1350014217 }
1350114218
1350214219 static long prevtime = 0;
....@@ -13523,6 +14240,7 @@
1352314240
1352414241 //System.err.println("Dtime = " + Dtime + "; units = " + e.getUnitsToScroll() + "; ratio (units/ms) = " + ratio);
1352514242
14243
+ if (BUTTONLESSWHEEL)
1352614244 if (Math.abs(ratio) < 0.1 || Math.abs(Dtime) == 0) // < 30)
1352714245 {
1352814246 return;
....@@ -13531,7 +14249,7 @@
1353114249 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
1353214250
1353314251 // TIMER
13534
- if (!wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
14252
+ if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
1353514253 {
1353614254 keepboxmode = BOXMODE;
1353714255 keepsupport = SUPPORT;
....@@ -13571,8 +14289,8 @@
1357114289 // mode |= META;
1357214290 //}
1357314291
13574
- SetMouseMode(WHEEL | e.getModifiersEx());
13575
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14292
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14293
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1357614294 anchorX = ax;
1357714295 anchorY = ay;
1357814296 prevX = px;
....@@ -13606,6 +14324,7 @@
1360614324 else
1360714325 if (evt.getSource() == AAtimer)
1360814326 {
14327
+ Globals.TIMERRUNNING = false;
1360914328 if (mouseDown)
1361014329 {
1361114330 //new Exception().printStackTrace();
....@@ -13631,6 +14350,10 @@
1363114350 // LIVE = waslive;
1363214351 // wasliveok = true;
1363314352 // waslive = false;
14353
+
14354
+ // May 2019 Forget it:
14355
+ if (true)
14356
+ return;
1363414357
1363514358 // source == timer
1363614359 if (mouseDown)
....@@ -13661,7 +14384,7 @@
1366114384
1366214385 // fev 2014???
1366314386 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13664
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14387
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1366514388 pingthread.StepToTarget(true); // true);
1366614389 }
1366714390 // if (!LIVE)
....@@ -13670,12 +14393,13 @@
1367014393
1367114394 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1367214395
13673
- void clickStart(int x, int y, int modifiers)
14396
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1367414397 {
1367514398 if (!wasliveok)
1367614399 return;
1367714400
1367814401 AAtimer.restart(); //
14402
+ Globals.TIMERRUNNING = true;
1367914403
1368014404 // waslive = LIVE;
1368114405 // LIVE = false;
....@@ -13687,7 +14411,7 @@
1368714411 // touched = true; // main DL
1368814412 if (isRenderer)
1368914413 {
13690
- SetMouseMode(modifiers);
14414
+ SetMouseMode(modifiers, modifiersex);
1369114415 }
1369214416
1369314417 selectX = anchorX = x;
....@@ -13700,7 +14424,7 @@
1370014424 clicked = true;
1370114425 hold = false;
1370214426
13703
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14427
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1370414428 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1370514429 {
1370614430 // System.out.println("RESTART II " + modifiers);
....@@ -13725,14 +14449,15 @@
1372514449 drag = false;
1372614450 //System.out.println("Mouse DOWN");
1372714451 editObj = false;
13728
- ClickInfo info = new ClickInfo();
13729
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
13730
- info.pane = this;
13731
- info.camera = renderCamera;
13732
- info.x = x;
13733
- info.y = y;
13734
- info.modifiers = modifiers;
13735
- editObj = object.doEditClick(info, 0);
14452
+ //ClickInfo info = new ClickInfo();
14453
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14454
+ object.clickInfo.pane = this;
14455
+ object.clickInfo.camera = renderCamera;
14456
+ object.clickInfo.x = x;
14457
+ object.clickInfo.y = y;
14458
+ object.clickInfo.modifiers = modifiersex;
14459
+ editObj = object.doEditClick(//info,
14460
+ 0);
1373614461 if (!editObj)
1373714462 {
1373814463 hasMarquee = true;
....@@ -13748,11 +14473,14 @@
1374814473
1374914474 public void mouseDragged(MouseEvent e)
1375014475 {
14476
+ Globals.MOUSEDRAGGED = true;
14477
+
14478
+ //System.out.println("mouseDragged: " + e);
1375114479 if (isRenderer)
1375214480 movingcamera = true;
14481
+
1375314482 //if (drawing)
1375414483 //return;
13755
- //System.out.println("mouseDragged: " + e);
1375614484 if ((e.getModifiersEx() & CTRL) != 0
1375714485 || (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen())
1375814486 {
....@@ -13760,7 +14488,7 @@
1376014488 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1376114489 }
1376214490 else
13763
- drag(e.getX(), e.getY(), e.getModifiersEx());
14491
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1376414492
1376514493 //try { Thread.sleep(1); } catch (Exception ex) {}
1376614494 }
....@@ -13933,6 +14661,7 @@
1393314661
1393414662 public void run()
1393514663 {
14664
+ new Exception().printStackTrace();
1393614665 System.exit(0);
1393714666 for (;;)
1393814667 {
....@@ -13996,7 +14725,7 @@
1399614725 {
1399714726 Globals.lighttouched = true;
1399814727 }
13999
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14728
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1400014729 }
1400114730 //else
1400214731 }
....@@ -14010,12 +14739,18 @@
1401014739 void GoDown(int mod)
1401114740 {
1401214741 MODIFIERS |= COMMAND;
14013
- /*
14742
+ boolean isVR = (mouseMode&VR)!=0;
14743
+ /**/
1401414744 if((mod&SHIFT) == SHIFT)
14015
- manipCamera.RotatePosition(0, -speed);
14745
+ {
14746
+ if (isVR)
14747
+ manipCamera.RotateInterest(0, -speed);
14748
+ else
14749
+ manipCamera.RotatePosition(0, -speed);
14750
+ }
1401614751 else
14017
- manipCamera.BackForth(0, -speed*delta, getWidth());
14018
- */
14752
+ manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth());
14753
+ /**/
1401914754 if ((mod & SHIFT) == SHIFT)
1402014755 {
1402114756 mouseMode = mouseMode; // VR??
....@@ -14024,6 +14759,8 @@
1402414759 mouseMode |= BACKFORTH;
1402514760 }
1402614761
14762
+ targetLookAt.set(manipCamera.lookAt);
14763
+
1402714764 //prevX = X = anchorX;
1402814765 prevY = Y = anchorY - (int) (renderCamera.Distance());
1402914766 }
....@@ -14031,12 +14768,19 @@
1403114768 void GoUp(int mod)
1403214769 {
1403314770 MODIFIERS |= COMMAND;
14034
- /*
14771
+ /**/
14772
+ boolean isVR = (mouseMode&VR)!=0;
14773
+
1403514774 if((mod&SHIFT) == SHIFT)
14036
- manipCamera.RotatePosition(0, speed);
14775
+ {
14776
+ if (isVR)
14777
+ manipCamera.RotateInterest(0, speed);
14778
+ else
14779
+ manipCamera.RotatePosition(0, speed);
14780
+ }
1403714781 else
14038
- manipCamera.BackForth(0, speed*delta, getWidth());
14039
- */
14782
+ manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth());
14783
+ /**/
1404014784 if ((mod & SHIFT) == SHIFT)
1404114785 {
1404214786 mouseMode = mouseMode;
....@@ -14045,6 +14789,8 @@
1404514789 mouseMode |= BACKFORTH;
1404614790 }
1404714791
14792
+ targetLookAt.set(manipCamera.lookAt);
14793
+
1404814794 //prevX = X = anchorX;
1404914795 prevY = Y = anchorY + (int) (renderCamera.Distance());
1405014796 }
....@@ -14052,12 +14798,17 @@
1405214798 void GoLeft(int mod)
1405314799 {
1405414800 MODIFIERS |= COMMAND;
14055
- /*
14801
+ /**/
1405614802 if((mod&SHIFT) == SHIFT)
14057
- manipCamera.RotatePosition(speed, 0);
14803
+ manipCamera.Translate(speed*delta, 0, getWidth());
1405814804 else
14059
- manipCamera.Translate(speed*delta, 0, getWidth());
14060
- */
14805
+ {
14806
+ if ((mouseMode&VR)!=0)
14807
+ manipCamera.RotateInterest(-speed, 0);
14808
+ else
14809
+ manipCamera.RotatePosition(speed, 0);
14810
+ }
14811
+ /**/
1406114812 if ((mod & SHIFT) == SHIFT)
1406214813 {
1406314814 mouseMode = mouseMode;
....@@ -14066,6 +14817,8 @@
1406614817 mouseMode |= ROTATE;
1406714818 } // TRANSLATE;
1406814819
14820
+ targetLookAt.set(manipCamera.lookAt);
14821
+
1406914822 prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance());
1407014823 prevY = Y = anchorY;
1407114824 }
....@@ -14073,12 +14826,18 @@
1407314826 void GoRight(int mod)
1407414827 {
1407514828 MODIFIERS |= COMMAND;
14076
- /*
14829
+ /**/
1407714830 if((mod&SHIFT) == SHIFT)
14078
- manipCamera.RotatePosition(-speed, 0);
14831
+ manipCamera.Translate(-speed*delta, 0, getWidth());
1407914832 else
14080
- manipCamera.Translate(-speed*delta, 0, getWidth());
14081
- */
14833
+ {
14834
+ if ((mouseMode&VR)!=0)
14835
+ manipCamera.RotateInterest(speed, 0);
14836
+ else
14837
+ manipCamera.RotatePosition(-speed, 0);
14838
+ }
14839
+
14840
+ /**/
1408214841 if ((mod & SHIFT) == SHIFT)
1408314842 {
1408414843 mouseMode = mouseMode;
....@@ -14087,6 +14846,8 @@
1408714846 mouseMode |= ROTATE;
1408814847 } // TRANSLATE;
1408914848
14849
+ targetLookAt.set(manipCamera.lookAt);
14850
+
1409014851 prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance());
1409114852 prevY = Y = anchorY;
1409214853 }
....@@ -14096,7 +14857,7 @@
1409614857 int X, Y;
1409714858 boolean SX, SY;
1409814859
14099
- void drag(int x, int y, int modifiers)
14860
+ void drag(int x, int y, int modifiers, int modifiersex)
1410014861 {
1410114862 if (IsFrozen())
1410214863 {
....@@ -14105,17 +14866,17 @@
1410514866
1410614867 drag = true; // NEW
1410714868
14108
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14869
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1410914870
1411014871 X = x;
1411114872 Y = y;
1411214873 // floating state for animation
14113
- MODIFIERS = modifiers;
14114
- modifiers &= ~1024;
14874
+ MODIFIERS = modifiersex;
14875
+ modifiersex &= ~1024;
1411514876 if (false) // modifiers != 0)
1411614877 {
1411714878 //new Exception().printStackTrace();
14118
- System.out.println("mouseDragged: " + modifiers);
14879
+ System.out.println("mouseDragged: " + modifiersex);
1411914880 System.out.println("SHIFT = " + SHIFT);
1412014881 System.out.println("CONTROL = " + COMMAND);
1412114882 System.out.println("META = " + META);
....@@ -14128,14 +14889,16 @@
1412814889 if (editObj)
1412914890 {
1413014891 drag = true;
14131
- ClickInfo info = new ClickInfo();
14132
- info.bounds.setBounds(0, 0,
14892
+ //ClickInfo info = new ClickInfo();
14893
+ object.clickInfo.bounds.setBounds(0, 0,
1413314894 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14134
- info.pane = this;
14135
- info.camera = renderCamera;
14136
- info.x = x;
14137
- info.y = y;
14138
- object.editWindow.copy.doEditDrag(info);
14895
+ object.clickInfo.pane = this;
14896
+ object.clickInfo.camera = renderCamera;
14897
+ object.clickInfo.x = x;
14898
+ object.clickInfo.y = y;
14899
+ object //.GetWindow().copy
14900
+ .doEditDrag(//info,
14901
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1413914902 } else
1414014903 {
1414114904 if (x < startX)
....@@ -14284,23 +15047,27 @@
1428415047 }
1428515048 }
1428615049
15050
+// ClickInfo clickInfo = new ClickInfo();
15051
+
1428715052 public void mouseMoved(MouseEvent e)
1428815053 {
1428915054 //System.out.println("mouseMoved: " + e);
14290
-
1429115055 if (isRenderer)
1429215056 return;
1429315057
14294
- ClickInfo ci = new ClickInfo();
14295
- ci.x = e.getX();
14296
- ci.y = e.getY();
14297
- ci.modifiers = e.getModifiersEx();
14298
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14299
- ci.pane = this;
14300
- ci.camera = renderCamera;
15058
+ // Mouse cursor feedback
15059
+ object.clickInfo.x = e.getX();
15060
+ object.clickInfo.y = e.getY();
15061
+ object.clickInfo.modifiers = e.getModifiersEx();
15062
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
15063
+ object.clickInfo.pane = this;
15064
+ object.clickInfo.camera = renderCamera;
1430115065 if (!isRenderer)
1430215066 {
14303
- if (object.editWindow.copy.doEditClick(ci, 0))
15067
+ //ObjEditor editWindow = object.editWindow;
15068
+ //Object3D copy = editWindow.copy;
15069
+ if (object.doEditClick(//clickInfo,
15070
+ 0))
1430415071 {
1430515072 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1430615073 } else
....@@ -14312,7 +15079,11 @@
1431215079
1431315080 public void mouseReleased(MouseEvent e)
1431415081 {
15082
+ Globals.MOUSEDRAGGED = false;
15083
+
1431515084 movingcamera = false;
15085
+ X = 0; // getBounds().width/2;
15086
+ Y = 0; // getBounds().height/2;
1431615087 //System.out.println("mouseReleased: " + e);
1431715088 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1431815089 }
....@@ -14335,9 +15106,9 @@
1433515106 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1433615107 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1433715108
14338
- if (control || command || IsFrozen())
15109
+// No delay if (control || command || IsFrozen())
1433915110 timeout = true;
14340
- else
15111
+// ?? May 2019 else
1434115112 // timer.setDelay((modifiers & 128) != 0?0:350);
1434215113 mouseDown = false;
1434315114 if (!control && !command) // june 2013
....@@ -14447,7 +15218,7 @@
1444715218 System.out.println("keyReleased: " + e);
1444815219 }
1444915220
14450
- void SetMouseMode(int modifiers)
15221
+ void SetMouseMode(int modifiers, int modifiersex)
1445115222 {
1445215223 //System.out.println("SetMouseMode = " + modifiers);
1445315224 //modifiers &= ~1024;
....@@ -14459,25 +15230,25 @@
1445915230 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1446015231 // return;
1446115232 //System.out.println("SetMode = " + modifiers);
14462
- if ((modifiers & WHEEL) == WHEEL)
15233
+ if ((modifiersex & WHEEL) == WHEEL)
1446315234 {
1446415235 mouseMode |= ZOOM;
1446515236 }
1446615237
1446715238 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
14468
- if (capsLocked || (modifiers & META) == META)
15239
+ if (capsLocked) // || (modifiers & META) == META)
1446915240 {
1447015241 mouseMode |= VR; // BACKFORTH;
1447115242 }
14472
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
15243
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1447315244 {
1447415245 mouseMode |= SELECT;
1447515246 }
14476
- if ((modifiers & COMMAND) == COMMAND)
15247
+ if ((modifiersex & COMMAND) == COMMAND)
1447715248 {
1447815249 mouseMode |= SELECT;
1447915250 }
14480
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15251
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
1448115252 {
1448215253 mouseMode &= ~VR;
1448315254 mouseMode |= TRANSLATE;
....@@ -14506,7 +15277,7 @@
1450615277
1450715278 if (isRenderer) //
1450815279 {
14509
- SetMouseMode(modifiers);
15280
+ SetMouseMode(0, modifiers);
1451015281 }
1451115282
1451215283 Globals.theRenderer.keyPressed(key);
....@@ -14568,7 +15339,8 @@
1456815339 // break;
1456915340 case 'T':
1457015341 CACHETEXTURE ^= true;
14571
- textures.clear();
15342
+ texturepigment.clear();
15343
+ texturebump.clear();
1457215344 // repaint();
1457315345 break;
1457415346 case 'Y':
....@@ -14578,8 +15350,8 @@
1457815350 case 'K':
1457915351 KOMPACTTEXTURE ^= true;
1458015352 //textures.clear();
14581
- break;
14582
- case 'P': // Texture Projection macros
15353
+ // break;
15354
+ //case 'P': // Texture Projection macros
1458315355 // SAVETEXTURE ^= true;
1458415356 macromode = true;
1458515357 Udebug = Vdebug = NORMALdebug = false; programInitialized = false;
....@@ -14653,7 +15425,9 @@
1465315425 case 'E' : COMPACT ^= true;
1465415426 repaint();
1465515427 break;
14656
- case 'W' : DEBUGHSB ^= true;
15428
+ case 'W' : // Wide Window (fullscreen)
15429
+ //DEBUGHSB ^= true;
15430
+ ObjEditor.theFrame.ToggleFullScreen();
1465715431 repaint();
1465815432 break;
1465915433 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14678,8 +15452,8 @@
1467815452 RevertCamera();
1467915453 repaint();
1468015454 break;
14681
- case 'L':
1468215455 case 'l':
15456
+ //case 'L':
1468315457 if (lightMode)
1468415458 {
1468515459 lightMode = false;
....@@ -14698,7 +15472,7 @@
1469815472 targetLookAt.set(manipCamera.lookAt);
1469915473 repaint();
1470015474 break;
14701
- case 'p':
15475
+ case 'P': // p':
1470215476 // c'est quoi ca au juste? spherical ^= true;
1470315477 Skinshader ^= true; programInitialized = false;
1470415478 repaint();
....@@ -14736,27 +15510,31 @@
1473615510 repaint();
1473715511 break;
1473815512 case 'O':
14739
- Globals.drawMode = OCCLUSION; // WARNING
15513
+ // Too dangerous. Use menu. Globals.drawMode = OCCLUSION; // WARNING
1474015514 repaint();
1474115515 break;
1474215516 case 'o':
1474315517 OCCLUSION_CULLING ^= true;
1474415518 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1474515519 break;
14746
- case '0': envyoff ^= true; repaint(); break;
15520
+ //case '0': envyoff ^= true; repaint(); break;
1474715521 case '1':
1474815522 case '2':
1474915523 case '3':
1475015524 case '4':
1475115525 case '5':
14752
- newenvy = Character.getNumericValue(key);
14753
- repaint();
14754
- break;
1475515526 case '6':
1475615527 case '7':
1475715528 case '8':
1475815529 case '9':
14759
- BGcolor = (key - '6')/3.f;
15530
+ if (true) // envyoff)
15531
+ {
15532
+ BGcolor = (key - '1')/8.f;
15533
+ }
15534
+ else
15535
+ {
15536
+ //newenvy = Character.getNumericValue(key);
15537
+ }
1476015538 repaint();
1476115539 break;
1476215540 case '!':
....@@ -14822,9 +15600,9 @@
1482215600 case '_':
1482315601 kompactbit = 5;
1482415602 break;
14825
- case '+':
14826
- kompactbit = 6;
14827
- break;
15603
+// case '+':
15604
+// kompactbit = 6;
15605
+// break;
1482815606 case ' ':
1482915607 lightMode ^= true;
1483015608 Globals.lighttouched = true;
....@@ -14836,13 +15614,14 @@
1483615614 case ESC:
1483715615 RENDERPROGRAM += 1;
1483815616 RENDERPROGRAM %= 3;
15617
+
1483915618 repaint();
1484015619 break;
1484115620 case 'Z':
1484215621 //RESIZETEXTURE ^= true;
1484315622 //break;
1484415623 case 'z':
14845
- RENDERSHADOW ^= true;
15624
+ Globals.RENDERSHADOW ^= true;
1484615625 Globals.lighttouched = true;
1484715626 repaint();
1484815627 break;
....@@ -14875,8 +15654,9 @@
1487515654 case DELETE:
1487615655 ClearSelection();
1487715656 break;
14878
- /*
1487915657 case '+':
15658
+
15659
+ /*
1488015660 //fontsize += 1;
1488115661 bbzoom *= 2;
1488215662 repaint();
....@@ -14893,17 +15673,17 @@
1489315673 case '=':
1489415674 IncDepth();
1489515675 //fontsize += 1;
14896
- object.editWindow.refreshContents(true);
15676
+ object.GetWindow().refreshContents(true);
1489715677 maskbit = 6;
1489815678 break;
1489915679 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1490015680 DecDepth();
1490115681 maskbit = 5;
1490215682 //if(fontsize > 1) fontsize -= 1;
14903
- if (object.editWindow == null)
14904
- new Exception().printStackTrace();
14905
- else
14906
- object.editWindow.refreshContents(true);
15683
+// if (object.editWindow == null)
15684
+// new Exception().printStackTrace();
15685
+// else
15686
+ object.GetWindow().refreshContents(true);
1490715687 break;
1490815688 case '{':
1490915689 manipCamera.shaper_fovy /= 1.1;
....@@ -14966,7 +15746,7 @@
1496615746 //mode = ROTATE;
1496715747 if ((MODIFIERS & COMMAND) == 0) // VR??
1496815748 {
14969
- SetMouseMode(modifiers);
15749
+ SetMouseMode(0, modifiers);
1497015750 }
1497115751 }
1497215752
....@@ -15100,8 +15880,9 @@
1510015880
1510115881 protected void processMouseMotionEvent(MouseEvent e)
1510215882 {
15103
- //System.out.println("processMouseMotionEvent: " + mouseMode);
15104
- if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15883
+ //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
15884
+ //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15885
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1510515886 {
1510615887 mouseMoved(e);
1510715888 } else
....@@ -15126,11 +15907,12 @@
1512615907 }
1512715908 */
1512815909
15129
- object.editWindow.EditSelection();
15910
+ object.GetWindow().EditSelection(false);
1513015911 }
1513115912
1513215913 void SelectParent()
1513315914 {
15915
+ new Exception().printStackTrace();
1513415916 System.exit(0);
1513515917 Composite group = (Composite) object;
1513615918 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -15142,10 +15924,10 @@
1514215924 {
1514315925 //selectees.remove(i);
1514415926 System.out.println("select parent of " + elem);
15145
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15927
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1514615928 } else
1514715929 {
15148
- group.editWindow.Select(elem.GetTreePath(), first, true);
15930
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1514915931 }
1515015932
1515115933 first = false;
....@@ -15154,6 +15936,7 @@
1515415936
1515515937 void SelectChildren()
1515615938 {
15939
+ new Exception().printStackTrace();
1515715940 System.exit(0);
1515815941 /*
1515915942 Composite group = (Composite) object;
....@@ -15186,12 +15969,12 @@
1518615969 for (int j = 0; j < group.children.size(); j++)
1518715970 {
1518815971 elem = (Object3D) group.children.elementAt(j);
15189
- object.editWindow.Select(elem.GetTreePath(), first, true);
15972
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1519015973 first = false;
1519115974 }
1519215975 } else
1519315976 {
15194
- object.editWindow.Select(elem.GetTreePath(), first, true);
15977
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1519515978 }
1519615979
1519715980 first = false;
....@@ -15202,21 +15985,21 @@
1520215985 {
1520315986 //Composite group = (Composite) object;
1520415987 Object3D group = object;
15205
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15988
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1520615989 }
1520715990
1520815991 void ResetTransform(int mask)
1520915992 {
1521015993 //Composite group = (Composite) object;
1521115994 Object3D group = object;
15212
- group.editWindow.ResetTransform(mask);
15995
+ group.GetWindow().ResetTransform(mask);
1521315996 }
1521415997
1521515998 void FlipTransform()
1521615999 {
1521716000 //Composite group = (Composite) object;
1521816001 Object3D group = object;
15219
- group.editWindow.FlipTransform();
16002
+ group.GetWindow().FlipTransform();
1522016003 // group.editWindow.ReduceMesh(true);
1522116004 }
1522216005
....@@ -15224,7 +16007,7 @@
1522416007 {
1522516008 //Composite group = (Composite) object;
1522616009 Object3D group = object;
15227
- group.editWindow.PrintMemory();
16010
+ group.GetWindow().PrintMemory();
1522816011 // group.editWindow.ReduceMesh(true);
1522916012 }
1523016013
....@@ -15232,7 +16015,7 @@
1523216015 {
1523316016 //Composite group = (Composite) object;
1523416017 Object3D group = object;
15235
- group.editWindow.ResetCentroid();
16018
+ group.GetWindow().ResetCentroid();
1523616019 }
1523716020
1523816021 void IncDepth()
....@@ -15314,11 +16097,11 @@
1531416097
1531516098 int width = getBounds().width;
1531616099 int height = getBounds().height;
15317
- ClickInfo info = new ClickInfo();
15318
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1531916100 //Image img = CreateImage(width, height);
1532016101 //System.out.println("width = " + width + "; height = " + height + "\n");
16102
+
1532116103 Graphics gr = g; // img.getGraphics();
16104
+
1532216105 if (!hasMarquee)
1532316106 {
1532416107 if (Xmin < Xmax) // !locked)
....@@ -15390,44 +16173,92 @@
1539016173 }
1539116174 if (object != null && !hasMarquee)
1539216175 {
16176
+ if (object.clickInfo == null)
16177
+ object.clickInfo = new ClickInfo();
16178
+ ClickInfo info = object.clickInfo;
16179
+ //ClickInfo info = new ClickInfo();
16180
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16181
+
1539316182 if (isRenderer)
1539416183 {
15395
- info.flags++;
16184
+ object.clickInfo.flags++;
1539616185 double frameAspect = (double) width / (double) height;
1539716186 if (frameAspect > renderCamera.aspect)
1539816187 {
1539916188 int desired = (int) ((double) height * renderCamera.aspect);
15400
- info.bounds.width -= width - desired;
15401
- info.bounds.x += (width - desired) / 2;
16189
+ object.clickInfo.bounds.width -= width - desired;
16190
+ object.clickInfo.bounds.x += (width - desired) / 2;
1540216191 } else
1540316192 {
1540416193 int desired = (int) ((double) width / renderCamera.aspect);
15405
- info.bounds.height -= height - desired;
15406
- info.bounds.y += (height - desired) / 2;
16194
+ object.clickInfo.bounds.height -= height - desired;
16195
+ object.clickInfo.bounds.y += (height - desired) / 2;
1540716196 }
1540816197 }
15409
- info.g = gr;
15410
- info.camera = renderCamera;
16198
+
16199
+ object.clickInfo.g = gr;
16200
+ object.clickInfo.camera = renderCamera;
1541116201 /*
1541216202 // Memory intensive (brep.verticescopy)
1541316203 if (!(object instanceof Composite))
1541416204 object.draw(info, 0, false); // SLOW :
1541516205 */
15416
- if (!isRenderer)
16206
+ if (!isRenderer) // && drag)
1541716207 {
15418
- object.drawEditHandles(info, 0);
16208
+ Grafreed.Assert(object != null);
16209
+ Grafreed.Assert(object.selection != null);
16210
+ if (object.selection.Size() > 0)
16211
+ {
16212
+ int hitSomething = object.selection.get(0).hitSomething;
16213
+
16214
+ object.clickInfo.DX = 0;
16215
+ object.clickInfo.DY = 0;
16216
+ object.clickInfo.W = 1;
16217
+ if (hitSomething == Object3D.hitCenter)
16218
+ {
16219
+ info.DX = X;
16220
+ if (X != 0)
16221
+ info.DX -= info.bounds.width/2;
16222
+
16223
+ info.DY = Y;
16224
+ if (Y != 0)
16225
+ info.DY -= info.bounds.height/2;
16226
+ }
16227
+
16228
+ object.drawEditHandles(//info,
16229
+ 0);
16230
+
16231
+ if (drag && (X != 0 || Y != 0))
16232
+ {
16233
+ switch (hitSomething)
16234
+ {
16235
+ case Object3D.hitCenter: gr.setColor(Color.white);
16236
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16237
+ break;
16238
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16239
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16240
+ break;
16241
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16242
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16243
+ break;
16244
+ }
16245
+
16246
+ }
16247
+ }
1541916248 }
1542016249 }
16250
+
1542116251 if (isRenderer)
1542216252 {
1542316253 //gr.setColor(Color.black);
1542416254 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1542516255 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1542616256 }
16257
+
1542716258 if (hasMarquee)
1542816259 {
1542916260 gr.setXORMode(Color.white);
15430
- gr.setColor(Color.red);
16261
+ gr.setColor(Color.white);
1543116262 if (!firstime)
1543216263 {
1543316264 gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH);
....@@ -15536,6 +16367,7 @@
1553616367 public boolean mouseDown(Event evt, int x, int y)
1553716368 {
1553816369 System.out.println("mouseDown: " + evt);
16370
+ System.exit(0);
1553916371 /*
1554016372 locked = true;
1554116373 drag = false;
....@@ -15579,7 +16411,7 @@
1557916411 {
1558016412 keyPressed(0, modifiers);
1558116413 }
15582
- clickStart(x, y, modifiers);
16414
+ // clickStart(x, y, modifiers);
1558316415 return true;
1558416416 }
1558516417
....@@ -15697,7 +16529,7 @@
1569716529 {
1569816530 keyReleased(0, 0);
1569916531 }
15700
- drag(x, y, modifiers);
16532
+ drag(x, y, 0, modifiers);
1570116533 return true;
1570216534 }
1570316535
....@@ -15829,7 +16661,7 @@
1582916661 Object3D object;
1583016662 static Object3D trackedobject;
1583116663 Camera renderCamera; // Light or Eye (or Occlusion)
15832
- /*static*/ Camera manipCamera; // Light or Eye
16664
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1583316665 /*static*/ Camera eyeCamera;
1583416666 /*static*/ Camera lightCamera;
1583516667 int cameracount;
....@@ -15893,6 +16725,8 @@
1589316725 private /*static*/ boolean firstime;
1589416726 private /*static*/ cVector newView = new cVector();
1589516727 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16728
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16729
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1589616730 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1589716731 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1589816732 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -15905,29 +16739,67 @@
1590516739 {
1590616740 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1590716741
16742
+ int usedsuf = 0;
16743
+
1590816744 for (int i = 0; i < suffixes.length; i++)
1590916745 {
15910
- String resourceName = basename + suffixes[i] + "." + suffix;
15911
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
15912
- mipmapped,
15913
- FileUtil.getFileSuffix(resourceName));
15914
- if (data == null)
16746
+ String[] suffixe = suffixes;
16747
+ String[] fallback = suffixes2;
16748
+ String[] fallfallback = suffixes3;
16749
+
16750
+ for (int c=usedsuf; --c>=0;)
1591516751 {
15916
- throw new IOException("Unable to load texture " + resourceName);
16752
+// String[] temp = suffixe;
16753
+// suffixe = fallback;
16754
+// fallback = fallfallback;
16755
+// fallfallback = temp;
1591716756 }
16757
+
16758
+ String resourceName = basename + suffixe[i] + "." + suffix;
16759
+ TextureData data;
16760
+
16761
+ try
16762
+ {
16763
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16764
+ mipmapped,
16765
+ FileUtil.getFileSuffix(resourceName));
16766
+ }
16767
+ catch (Exception e)
16768
+ {
16769
+ try
16770
+ {
16771
+ resourceName = basename + fallback[i] + "." + suffix;
16772
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16773
+ mipmapped,
16774
+ FileUtil.getFileSuffix(resourceName));
16775
+ }
16776
+ catch (Exception e2)
16777
+ {
16778
+ resourceName = basename + fallfallback[i] + "." + suffix;
16779
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16780
+ mipmapped,
16781
+ FileUtil.getFileSuffix(resourceName));
16782
+ }
16783
+ }
16784
+
1591816785 //System.out.println("Target = " + targets[i]);
1591916786 cubemap.updateImage(data, targets[i]);
1592016787 }
1592116788
1592216789 return cubemap;
1592316790 }
16791
+
1592416792 int bigsphere = -1;
1592516793
1592616794 float BGcolor = 0.5f;
1592716795
15928
- private void DrawSkyBox(GL gl)
16796
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16797
+
16798
+ private void DrawSkyBox(GL gl, float ratio)
1592916799 {
15930
- if (envyoff || cubemap == null)
16800
+ if (//envyoff ||
16801
+ WIREFRAME ||
16802
+ cubemap == null)
1593116803 {
1593216804 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1593316805 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -15942,7 +16814,17 @@
1594216814 // Compensates for ExaminerViewer's modification of modelview matrix
1594316815 gl.glMatrixMode(GL.GL_MODELVIEW);
1594416816 gl.glLoadIdentity();
16817
+ gl.glScalef(1,ratio,1);
1594516818
16819
+// colorV[0] = 2;
16820
+// colorV[1] = 2;
16821
+// colorV[2] = 2;
16822
+// colorV[3] = 1;
16823
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16824
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16825
+//
16826
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16827
+
1594616828 //gl.glActiveTexture(GL.GL_TEXTURE1);
1594716829 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1594816830
....@@ -15974,6 +16856,7 @@
1597416856 {
1597516857 gl.glScalef(1.0f, -1.0f, 1.0f);
1597616858 }
16859
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1597716860 gl.glMultMatrixd(viewrot_1, 0);
1597816861 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1597916862 //viewer.updateInverseRotation(gl);
....@@ -16014,7 +16897,8 @@
1601416897 gl.glDisable(GL.GL_TEXTURE_GEN_R);
1601516898
1601616899 cubemap.disable();
16017
- ////cubemap.unbind();
16900
+ //cubemap.dispose();
16901
+
1601816902 if (CULLFACE)
1601916903 {
1602016904 gl.glEnable(gl.GL_CULL_FACE);
....@@ -16070,7 +16954,7 @@
1607016954 gl.glScalef(1.0f, -1.0f, 1.0f);
1607116955 }
1607216956
16073
- gl.glNormal3f(0.0f, 0.0f, 1.0f);
16957
+ SetGLNormal(gl, 0.0f, 0.0f, 1.0f);
1607416958
1607516959 float step = 2; // 0.1666f; //0.25f;
1607616960 float stepv = 2; // step * 1652 / 998;
....@@ -16114,16 +16998,16 @@
1611416998 cStatic.objectstack[materialdepth++] = checker;
1611516999 //System.out.println("material " + material);
1611617000 //Applet3D.tracein(this, selected);
16117
- vector2buffer = checker.projectedVertices;
17001
+ //vector2buffer = checker.projectedVertices;
1611817002
1611917003 //checker.GetMaterial().Draw(this, false); // true);
16120
- DrawMaterial(checker.GetMaterial(), false); // true);
17004
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1612117005
1612217006 materialdepth -= 1;
1612317007 if (materialdepth > 0)
1612417008 {
16125
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16126
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
17009
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
17010
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1612717011 }
1612817012 //checker.GetMaterial().opacity = 1f;
1612917013 ////checker.GetMaterial().ambient = 1f;
....@@ -16209,6 +17093,14 @@
1620917093 }
1621017094 }
1621117095
17096
+ private Object3D GetFolder()
17097
+ {
17098
+ Object3D folder = object.GetWindow().copy;
17099
+ if (object.GetWindow().copy.selection.Size() > 0)
17100
+ folder = object.GetWindow().copy.selection.elementAt(0);
17101
+ return folder;
17102
+ }
17103
+
1621217104 class SelectBuffer implements GLEventListener
1621317105 {
1621417106
....@@ -16224,7 +17116,7 @@
1622417116 //new Exception().printStackTrace();
1622517117 System.out.println("select buffer init");
1622617118 // Use debug pipeline
16227
- drawable.setGL(new DebugGL(drawable.getGL()));
17119
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1622817120
1622917121 GL gl = drawable.getGL();
1623017122
....@@ -16267,6 +17159,7 @@
1626717159 {
1626817160 if (!selection)
1626917161 {
17162
+ new Exception().printStackTrace();
1627017163 System.exit(0);
1627117164 return;
1627217165 }
....@@ -16287,6 +17180,17 @@
1628717180
1628817181 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1628917182
17183
+ if (PAINTMODE)
17184
+ {
17185
+ if (object.GetWindow().copy.selection.Size() > 0)
17186
+ {
17187
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17188
+
17189
+ // Make what you paint not selectable.
17190
+ paintobj.ResetSelectable();
17191
+ }
17192
+ }
17193
+
1629017194 //int tmp = selection_view;
1629117195 //selection_view = -1;
1629217196 int temp = DrawMode();
....@@ -16298,6 +17202,17 @@
1629817202 // temp = DEFAULT; // patch for selection debug
1629917203 Globals.drawMode = temp; // WARNING
1630017204
17205
+ if (PAINTMODE)
17206
+ {
17207
+ if (object.GetWindow().copy.selection.Size() > 0)
17208
+ {
17209
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17210
+
17211
+ // Revert.
17212
+ paintobj.RestoreSelectable();
17213
+ }
17214
+ }
17215
+
1630117216 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1630217217
1630317218 // trying different ways of getting the depth info over
....@@ -16345,6 +17260,8 @@
1634517260 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1634617261 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1634717262 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
17263
+
17264
+ CreateSelectedPoint();
1634817265
1634917266 // Will fit the mesh !!!
1635017267 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16394,34 +17311,36 @@
1639417311 System.out.println("; fromto " + sel + " " + Trunk(previousselectedpoint.toParent[3][0]) + " " + Trunk(previousselectedpoint.toParent[3][2]) + " " + Trunk(selectedpoint.toParent[3][0]) + " " + Trunk(selectedpoint.toParent[3][2]));
1639517312 }
1639617313
16397
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
17314
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1639817315 }
1639917316 }
1640017317
1640117318 if (!movingcamera && !PAINTMODE)
16402
- object.editWindow.ScreenFitPoint(); // fev 2014
17319
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1640317320
16404
- if (PAINTMODE && GrafreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17321
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1640517322 {
16406
- Object3D paintobj = GrafreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17323
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1640717324
16408
- Object3D group = new Object3D("inst" + paintcount++);
17325
+ if (object.GetWindow().copy.selection.Size() > 0)
17326
+ {
17327
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1640917328
16410
- group.CreateMaterial(); // use a void leaf to select instances
16411
-
16412
- group.add(paintobj); // link
16413
-
16414
- object.editWindow.SnapObject(group);
16415
-
16416
- Object3D folder = object.editWindow.copy;
16417
-
16418
- if (object.editWindow.copy.selection.Size() > 0)
16419
- folder = object.editWindow.copy.selection.elementAt(0);
16420
-
16421
- folder.add(group);
16422
-
16423
- object.editWindow.ResetModel();
16424
- object.editWindow.refreshContents();
17329
+ Object3D inst = new Object3D("inst" + paintcount++);
17330
+
17331
+ inst.CreateMaterial(); // use a void leaf to select instances
17332
+
17333
+ inst.add(paintobj); // link
17334
+
17335
+ object.GetWindow().SnapObject(inst);
17336
+
17337
+ Object3D folder = paintFolder; // GetFolder();
17338
+
17339
+ folder.add(inst);
17340
+
17341
+ object.GetWindow().ResetModel();
17342
+ object.GetWindow().refreshContents();
17343
+ }
1642517344 }
1642617345 else
1642717346 paintcount = 0;
....@@ -16460,6 +17379,11 @@
1646017379 //System.out.println("objects[color] = " + objects[color]);
1646117380 //objects[color].Select();
1646217381 indexcount = 0;
17382
+ ObjEditor window = object.GetWindow();
17383
+ if (window != null && deselect)
17384
+ {
17385
+ window.Select(null, deselect, true);
17386
+ }
1646317387 object.Select(color, deselect);
1646417388 }
1646517389
....@@ -16510,6 +17434,7 @@
1651017434
1651117435 public void init(GLAutoDrawable drawable)
1651217436 {
17437
+ if (Globals.DEBUG)
1651317438 System.out.println("shadow buffer init");
1651417439
1651517440 GL gl = drawable.getGL();
....@@ -16559,7 +17484,7 @@
1655917484 gl.glDisable(gl.GL_CULL_FACE);
1656017485 }
1656117486
16562
- if (!RENDERSHADOW)
17487
+ if (!Globals.RENDERSHADOW)
1656317488 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1656417489
1656517490 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -16569,7 +17494,7 @@
1656917494 //gl.glColorMask(false, false, false, false);
1657017495
1657117496 //render_scene_from_light_view(gl, drawable, 0, 0);
16572
- if (RENDERSHADOW && Globals.lighttouched && !movingcamera) // && !parent.IsFreezed())
17497
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1657317498 {
1657417499 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1657517500
....@@ -16738,10 +17663,14 @@
1673817663 gl.glFlush();
1673917664
1674017665 /**/
16741
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17666
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1674217667
16743
- float[] pixels = occlusionsizebuffer.array();
17668
+ float[] depths = occlusiondepthbuffer.array();
1674417669
17670
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17671
+
17672
+ int[] pixels = selectsizebuffer.array();
17673
+
1674517674 double r = 0, g = 0, b = 0;
1674617675
1674717676 double count = 0;
....@@ -16752,7 +17681,7 @@
1675217681
1675317682 double FACTOR = 1;
1675417683
16755
- for (int i = 0; i < pixels.length; i++)
17684
+ for (int i = 0; i < depths.length; i++)
1675617685 {
1675717686 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1675817687 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -16835,7 +17764,7 @@
1683517764
1683617765 double scale = ray.z; // 1; // cos
1683717766
16838
- float depth = pixels[newindex];
17767
+ float depth = depths[newindex];
1683917768
1684017769 /*
1684117770 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -16985,23 +17914,15 @@
1698517914 int AAbuffersize = 0;
1698617915
1698717916 //double[] selectedpoint = new double[3];
16988
- static Superellipsoid selectedpoint = new Superellipsoid();
17917
+ static Superellipsoid selectedpoint;
1698917918 static Sphere previousselectedpoint = null;
16990
- static Sphere debugpointG = new Sphere();
16991
- static Sphere debugpointP = new Sphere();
16992
- static Sphere debugpointC = new Sphere();
16993
- static Sphere debugpointR = new Sphere();
17919
+ static Sphere debugpointG;
17920
+ static Sphere debugpointP;
17921
+ static Sphere debugpointC;
17922
+ static Sphere debugpointR;
1699417923
1699517924 static Sphere debugpoints[] = new Sphere[8];
1699617925
16997
- static
16998
- {
16999
- for (int i=0; i<8; i++)
17000
- {
17001
- debugpoints[i] = new Sphere();
17002
- }
17003
- }
17004
-
1700517926 static void InitPoints(float radius)
1700617927 {
1700717928 for (int i=0; i<8; i++)
....@@ -17040,11 +17961,14 @@
1704017961 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1704117962 static IntBuffer bigAAbuffer;
1704217963 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
17043
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17964
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1704417965 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1704517966 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1704617967 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17047
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17968
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17969
+
17970
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17971
+
1704817972 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1704917973 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1705017974 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();