Normand Briere
2019-08-20 564f4d12d93813b5d680fc24d4f118c3886d96ed
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,10 +532,12 @@
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);
....@@ -1185,10 +1262,12 @@
11851262 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
11861263 }
11871264 }
1265
+
11881266 if (flipV)
11891267 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
11901268 else
11911269 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1270
+
11921271 //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
11931272 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
11941273
....@@ -1208,10 +1287,12 @@
12081287 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
12091288 }
12101289 }
1290
+
12111291 if (flipV)
12121292 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12131293 else
12141294 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1295
+
12151296 //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
12161297 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
12171298
....@@ -1239,8 +1320,10 @@
12391320 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12401321 else
12411322 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1323
+
12421324 //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
12431325 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1326
+
12441327 count2 += 2;
12451328 count3 += 3;
12461329 }
....@@ -1419,6 +1502,8 @@
14191502 gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
14201503 }
14211504
1505
+ float[] colorV = new float[4];
1506
+
14221507 void SetColor(Object3D obj, Vertex p0)
14231508 {
14241509 CameraPane display = this;
....@@ -1486,8 +1571,6 @@
14861571 {
14871572 return;
14881573 }
1489
-
1490
- float[] colorV = new float[3];
14911574
14921575 if (false) // marked)
14931576 {
....@@ -1596,7 +1679,7 @@
15961679 // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
15971680 }
15981681
1599
- void DrawMaterial(cMaterial material, boolean selected)
1682
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
16001683 {
16011684 CameraPane display = this;
16021685 //new Exception().printStackTrace();
....@@ -1612,18 +1695,18 @@
16121695 //col.getColorComponents(ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB), CameraPane.modelParams0);
16131696 if (!material.multiply)
16141697 {
1615
- display.color = color;
1698
+ display.color = material.color;
16161699 display.saturation = material.modulation;
16171700 }
16181701 else
16191702 {
1620
- display.color *= color*2;
1703
+ display.color *= material.color*2;
16211704 display.saturation *= material.modulation*2;
16221705 }
16231706
16241707 cColor.HSBtoRGB(display.color, display.saturation, 1, display.modelParams0);
16251708
1626
- float[] colorV = GrafreeD.colorV;
1709
+ float[] colorV = Grafreed.colorV;
16271710
16281711 /**/
16291712 if (display.DrawMode() == display.DEFAULT) // && display.RENDERPROGRAM == 0)
....@@ -1631,7 +1714,7 @@
16311714 colorV[0] = display.modelParams0[0] * material.diffuse;
16321715 colorV[1] = display.modelParams0[1] * material.diffuse;
16331716 colorV[2] = display.modelParams0[2] * material.diffuse;
1634
- colorV[3] = material.opacity;
1717
+ colorV[3] = 1; // material.opacity;
16351718
16361719 gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
16371720 //System.out.println("Opacity = " + opacity);
....@@ -1736,12 +1819,12 @@
17361819
17371820 display.modelParams7[0] = 0;
17381821 display.modelParams7[1] = 1000;
1739
- display.modelParams7[2] = 0;
1822
+ display.modelParams7[2] = material.parallax;
17401823 display.modelParams7[3] = 0;
17411824
1742
- display.modelParams6[0] = 100; // criss de bug de bump
1825
+ //display.modelParams6[0] = 100; // criss de bug de bump
17431826
1744
- Object3D.cVector2[] extparams = display.vector2buffer;
1827
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
17451828 if (extparams != null && extparams.length > 0 && extparams[0] != null)
17461829 {
17471830 display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
....@@ -1883,7 +1966,7 @@
18831966 void PushMatrix(double[][] matrix)
18841967 {
18851968 // GrafreeD.tracein(matrix);
1886
- PushMatrix(matrix,1);
1969
+ PushMatrix(matrix, 1);
18871970 }
18881971
18891972 void PushMatrix()
....@@ -1969,9 +2052,9 @@
19692052 switch(viewcode)
19702053 {
19712054 case 0: return "main";
1972
- case 1: return "one";
1973
- case 2: return "two";
1974
- case 3: return "three";
2055
+ case 1: return "Red";
2056
+ case 2: return "Green";
2057
+ case 3: return "Blue";
19752058 case 4: return "light";
19762059 }
19772060
....@@ -2037,7 +2120,7 @@
20372120 //System.err.println("Oeil on");
20382121 OEIL = true;
20392122 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2040
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2123
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
20412124 //pingthread.StepToTarget(true);
20422125 }
20432126
....@@ -2135,7 +2218,7 @@
21352218 System.err.println("LIVE = " + Globals.isLIVE());
21362219
21372220 if (!Globals.isLIVE()) // save sound
2138
- GrafreeD.savesound = true; // wav.save();
2221
+ Grafreed.savesound = true; // wav.save();
21392222 // else
21402223 repaint(); // start loop // may 2013
21412224 }
....@@ -2168,6 +2251,11 @@
21682251 public void ToggleBoxMode()
21692252 {
21702253 BOXMODE ^= true;
2254
+ }
2255
+
2256
+ public void ToggleZoomBoxMode()
2257
+ {
2258
+ ZOOMBOXMODE ^= true;
21712259 }
21722260
21732261 public void ToggleSmoothFocus()
....@@ -2247,7 +2335,7 @@
22472335
22482336 void ToggleDebug()
22492337 {
2250
- DEBUG ^= true;
2338
+ Globals.DEBUG ^= true;
22512339 }
22522340
22532341 void ToggleLookAt()
....@@ -2255,9 +2343,9 @@
22552343 LOOKAT ^= true;
22562344 }
22572345
2258
- void ToggleRandom()
2346
+ void ToggleSwitch()
22592347 {
2260
- RANDOM ^= true;
2348
+ SWITCH ^= true;
22612349 }
22622350
22632351 void ToggleHandles()
....@@ -2265,10 +2353,17 @@
22652353 HANDLES ^= true;
22662354 }
22672355
2356
+ Object3D paintFolder;
2357
+
22682358 void TogglePaint()
22692359 {
22702360 PAINTMODE ^= true;
22712361 paintcount = 0;
2362
+
2363
+ if (PAINTMODE)
2364
+ {
2365
+ paintFolder = GetFolder();
2366
+ }
22722367 }
22732368
22742369 void SwapCamera(int a, int b)
....@@ -2364,7 +2459,22 @@
23642459 {
23652460 return currentGL;
23662461 }
2367
-
2462
+
2463
+ static private BufferedImage CreateBim(TextureData texturedata)
2464
+ {
2465
+ Grafreed.Assert(texturedata != null);
2466
+
2467
+ int width = texturedata.getWidth();
2468
+ int height = texturedata.getHeight();
2469
+
2470
+ Buffer buffer = texturedata.getBuffer();
2471
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2472
+
2473
+ byte[] bytes = bytebuf.array();
2474
+
2475
+ return CreateBim(bytes, width, height);
2476
+ }
2477
+
23682478 /**/
23692479 class CacheTexture
23702480 {
....@@ -2373,28 +2483,31 @@
23732483
23742484 int resolution;
23752485
2376
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2486
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
23772487 {
2378
- texture = tex;
2488
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2489
+ texturedata = texdata;
23792490 resolution = res;
23802491 }
23812492 }
23822493 /**/
23832494
23842495 // 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>();
2496
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2497
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2498
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2499
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2500
+
23882501 int pigmentdepth = 0;
23892502 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
23902503 int bumpdepth = 0;
23912504 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
23922505 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
23932506 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2394
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2507
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
23952508 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
23962509
2397
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2510
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
23982511 {
23992512 TextureData texturedata = null;
24002513
....@@ -2404,7 +2517,7 @@
24042517 com.sun.opengl.util.texture.TextureIO.newTextureData(
24052518 getClass().getClassLoader().getResourceAsStream(name),
24062519 true,
2407
- com.sun.opengl.util.texture.TextureIO.PNG);
2520
+ GetFormat(name)); // com.sun.opengl.util.texture.TextureIO.PNG);
24082521 } catch (java.io.IOException e)
24092522 {
24102523 throw new javax.media.opengl.GLException(e);
....@@ -2413,13 +2526,34 @@
24132526 if (bump)
24142527 texturedata = ConvertBump(texturedata, false);
24152528
2416
- com.sun.opengl.util.texture.Texture texture =
2417
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2529
+// com.sun.opengl.util.texture.Texture texture =
2530
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
24182531
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);
2532
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2533
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
24212534
2422
- return texture;
2535
+ return texturedata;
2536
+ }
2537
+
2538
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2539
+ {
2540
+ TextureData texturedata = null;
2541
+
2542
+ try
2543
+ {
2544
+ texturedata =
2545
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2546
+ bim,
2547
+ true);
2548
+ } catch (Exception e)
2549
+ {
2550
+ throw new javax.media.opengl.GLException(e);
2551
+ }
2552
+
2553
+ if (bump)
2554
+ texturedata = ConvertBump(texturedata, false);
2555
+
2556
+ return texturedata;
24232557 }
24242558
24252559 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3492,6 +3626,8 @@
34923626
34933627 System.out.println("LOADING TEXTURE : " + name);
34943628
3629
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3630
+
34953631 //
34963632 if (false) // compressbit > 0)
34973633 {
....@@ -4196,6 +4332,7 @@
41964332
41974333 com.sun.opengl.util.texture.Texture CompressTexture2(String name)
41984334 {
4335
+ new Exception().printStackTrace();
41994336 System.exit(0);
42004337 com.sun.opengl.util.texture.Texture texture = null;
42014338
....@@ -7889,7 +8026,7 @@
78898026 String pigment = Object3D.GetPigment(tex);
78908027 String bump = Object3D.GetBump(tex);
78918028
7892
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8029
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
78938030 {
78948031 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
78958032 // System.out.println("; bump = " + bump);
....@@ -7904,11 +8041,69 @@
79048041 pigment = null;
79058042 }
79068043
7907
- ReleaseTexture(bump, true);
7908
- ReleaseTexture(pigment, false);
8044
+ ReleaseTexture(tex, true);
8045
+ ReleaseTexture(tex, false);
79098046 }
79108047
7911
- void ReleaseTexture(String tex, boolean bump)
8048
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
8049
+ {
8050
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8051
+ {
8052
+ return;
8053
+ }
8054
+
8055
+ if (tex == null)
8056
+ {
8057
+ ReleaseTexture(null, false);
8058
+ return;
8059
+ }
8060
+
8061
+ String pigment = Object3D.GetPigment(tex);
8062
+
8063
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8064
+ {
8065
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8066
+ // System.out.println("; bump = " + bump);
8067
+ }
8068
+
8069
+ if (pigment.equals(""))
8070
+ {
8071
+ pigment = null;
8072
+ }
8073
+
8074
+ ReleaseTexture(tex, false);
8075
+ }
8076
+
8077
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
8078
+ {
8079
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8080
+ {
8081
+ return;
8082
+ }
8083
+
8084
+ if (tex == null)
8085
+ {
8086
+ ReleaseTexture(null, true);
8087
+ return;
8088
+ }
8089
+
8090
+ String bump = Object3D.GetBump(tex);
8091
+
8092
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8093
+ {
8094
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8095
+ // System.out.println("; bump = " + bump);
8096
+ }
8097
+
8098
+ if (bump.equals(""))
8099
+ {
8100
+ bump = null;
8101
+ }
8102
+
8103
+ ReleaseTexture(tex, true);
8104
+ }
8105
+
8106
+ void ReleaseTexture(cTexture tex, boolean bump)
79128107 {
79138108 if (// DrawMode() != 0 || /*tex == null ||*/
79148109 ambientOcclusion ) // || !textureon)
....@@ -7919,7 +8114,7 @@
79198114 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
79208115
79218116 if (tex != null)
7922
- texture = textures.get(tex);
8117
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
79238118
79248119 // //assert( texture != null );
79258120 // if (texture == null)
....@@ -8011,7 +8206,55 @@
80118206 }
80128207 }
80138208
8014
- /*boolean*/ public void BindTextures(cTexture tex, int resolution) // INTERFACE
8209
+ /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
8210
+ {
8211
+// if (// DrawMode() != 0 || /*tex == null ||*/
8212
+// ambientOcclusion ) // || !textureon)
8213
+// {
8214
+// return; // false;
8215
+// }
8216
+//
8217
+// if (tex == null)
8218
+// {
8219
+// BindTexture(null,false,resolution);
8220
+// BindTexture(null,true,resolution);
8221
+// return;
8222
+// }
8223
+//
8224
+// String pigment = Object3D.GetPigment(tex);
8225
+// String bump = Object3D.GetBump(tex);
8226
+//
8227
+// usedtextures.add(pigment);
8228
+// usedtextures.add(bump);
8229
+//
8230
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8231
+// {
8232
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8233
+// // System.out.println("; bump = " + bump);
8234
+// }
8235
+//
8236
+// if (bump.equals(""))
8237
+// {
8238
+// bump = null;
8239
+// }
8240
+// if (pigment.equals(""))
8241
+// {
8242
+// pigment = null;
8243
+// }
8244
+//
8245
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8246
+// BindTexture(pigment, false, resolution);
8247
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8248
+// BindTexture(bump, true, resolution);
8249
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8250
+//
8251
+// return; // true;
8252
+
8253
+ BindPigmentTexture(tex, resolution);
8254
+ BindBumpTexture(tex, resolution);
8255
+ }
8256
+
8257
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
80158258 {
80168259 if (// DrawMode() != 0 || /*tex == null ||*/
80178260 ambientOcclusion ) // || !textureon)
....@@ -8022,17 +8265,47 @@
80228265 if (tex == null)
80238266 {
80248267 BindTexture(null,false,resolution);
8025
- BindTexture(null,true,resolution);
80268268 return;
80278269 }
80288270
80298271 String pigment = Object3D.GetPigment(tex);
8272
+
8273
+ usedtextures.add(tex);
8274
+
8275
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8276
+ {
8277
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8278
+ // System.out.println("; bump = " + bump);
8279
+ }
8280
+
8281
+ if (pigment.equals(""))
8282
+ {
8283
+ pigment = null;
8284
+ }
8285
+
8286
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8287
+ BindTexture(tex, false, resolution);
8288
+ }
8289
+
8290
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8291
+ {
8292
+ if (// DrawMode() != 0 || /*tex == null ||*/
8293
+ ambientOcclusion ) // || !textureon)
8294
+ {
8295
+ return; // false;
8296
+ }
8297
+
8298
+ if (tex == null)
8299
+ {
8300
+ BindTexture(null,true,resolution);
8301
+ return;
8302
+ }
8303
+
80308304 String bump = Object3D.GetBump(tex);
80318305
8032
- usedtextures.put(pigment, pigment);
8033
- usedtextures.put(bump, bump);
8306
+ usedtextures.add(tex);
80348307
8035
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8308
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
80368309 {
80378310 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
80388311 // System.out.println("; bump = " + bump);
....@@ -8042,43 +8315,94 @@
80428315 {
80438316 bump = null;
80448317 }
8045
- if (pigment.equals(""))
8046
- {
8047
- pigment = null;
8048
- }
80498318
8050
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8051
- BindTexture(pigment, false, resolution);
80528319 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8053
- BindTexture(bump, true, resolution);
8320
+ BindTexture(tex, true, resolution);
80548321 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8055
-
8056
- return; // true;
80578322 }
80588323
8059
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution)
8324
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8325
+
8326
+ private boolean FileExists(String tex)
80608327 {
8061
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8328
+ if (missingTextures.contains(tex))
8329
+ {
8330
+ return false;
8331
+ }
8332
+
8333
+ boolean fileExists = new File(tex).exists();
8334
+
8335
+ if (!fileExists)
8336
+ {
8337
+ // If file exists, the "new File()" is not executed sgain
8338
+ missingTextures.add(tex);
8339
+ }
8340
+
8341
+ return fileExists;
8342
+ }
8343
+
8344
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
8345
+ {
8346
+ CacheTexture texturecache = null;
80628347
80638348 if (tex != null)
80648349 {
8065
- String texname = tex;
8350
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8351
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
80668352
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;
8353
+ if (texname.equals("") && texdata == null)
8354
+ {
8355
+ return null;
8356
+ }
8357
+
8358
+ String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
8359
+
8360
+// String[] split = tex.split("Textures");
8361
+// if (split.length > 1)
8362
+// texname = "/Users/nbriere/Textures" + split[split.length-1];
8363
+// else
8364
+// if (!texname.startsWith("/"))
8365
+// texname = "/Users/nbriere/Textures/" + texname;
8366
+ if (!FileExists(texname) && !texname.startsWith("@"))
8367
+ {
8368
+ texname = fallbackTextureName;
8369
+ }
80738370
80748371 if (CACHETEXTURE)
8075
- texture = textures.get(texname); // TEXTURE CACHE
8076
-
8077
- TextureData texturedata = null;
8078
-
8079
- if (texture == null || texture.resolution < resolution)
80808372 {
8081
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8373
+ if (texdata == null)
8374
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8375
+ else
8376
+ texturecache = bimtextures.get(texdata);
8377
+ }
8378
+
8379
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8380
+ {
8381
+ TextureData texturedata = null;
8382
+
8383
+ if (texdata != null && textureon)
8384
+ {
8385
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8386
+
8387
+ try
8388
+ {
8389
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8390
+ }
8391
+ catch (Exception e)
8392
+ {
8393
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8394
+ }
8395
+
8396
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8397
+ bimtextures.put(texdata, texturecache);
8398
+
8399
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8400
+
8401
+ //Object bim2 = CreateBim(texturecache.texturedata);
8402
+ //bim2 = bim;
8403
+ }
8404
+ else
8405
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
80828406 {
80838407 assert(!bump);
80848408 // if (bump)
....@@ -8089,19 +8413,23 @@
80898413 // }
80908414 // else
80918415 // {
8092
- texture = textures.get(tex);
8093
- if (texture == null)
8416
+ // texturecache = textures.get(texname); // suspicious
8417
+ if (texturecache == null)
80948418 {
8095
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8419
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
80968420 }
8421
+ else
8422
+ new Exception().printStackTrace();
80978423 // }
80988424 } else
8099
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8425
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
81008426 {
81018427 assert(bump);
8102
- texture = textures.get(tex);
8103
- if (texture == null)
8104
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8428
+ // texturecache = textures.get(texname); // suspicious
8429
+ if (texturecache == null)
8430
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8431
+ else
8432
+ new Exception().printStackTrace();
81058433 } else
81068434 {
81078435 //if (tex.equals("IMMORTAL"))
....@@ -8109,11 +8437,22 @@
81098437 // texture = GetResourceTexture("default.png");
81108438 //} else
81118439 //{
8112
- if (tex.equals("WHITE_NOISE"))
8440
+ if (texname.endsWith("WHITE_NOISE"))
81138441 {
8114
- texture = textures.get(tex);
8115
- if (texture == null)
8116
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8442
+ // texturecache = textures.get(texname); // suspicious
8443
+ if (texturecache == null)
8444
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8445
+ else
8446
+ new Exception().printStackTrace();
8447
+ } else
8448
+ {
8449
+ if (texname.startsWith("@"))
8450
+ {
8451
+ // texturecache = textures.get(texname); // suspicious
8452
+ if (texturecache == null)
8453
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8454
+ else
8455
+ new Exception().printStackTrace();
81178456 } else
81188457 {
81198458 if (textureon)
....@@ -8138,7 +8477,7 @@
81388477 }
81398478
81408479 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
8141
- if (!new File(cachename).exists())
8480
+ if (!FileExists(cachename))
81428481 cachename = texname;
81438482 else
81448483 processbump = false; // don't process bump map again
....@@ -8160,7 +8499,7 @@
81608499 }
81618500
81628501 cachename = texname.substring(0, texname.length()-4)+ext+".png";
8163
- if (!new File(cachename).exists())
8502
+ if (!FileExists(cachename))
81648503 cachename = texname;
81658504 else
81668505 processbump = false; // don't process bump map again
....@@ -8169,20 +8508,23 @@
81698508 texturedata = GetFileTexture(cachename, processbump, resolution);
81708509
81718510
8172
- if (texturedata != null)
8173
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8511
+ if (texturedata == null)
8512
+ throw new Exception();
8513
+
8514
+ texturecache = new CacheTexture(texturedata,resolution);
81748515 //texture = GetTexture(tex, bump);
81758516 }
8517
+ }
81768518 }
81778519 //}
81788520 }
81798521
8180
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8522
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
81818523 {
81828524 //return false;
81838525
81848526 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8185
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8527
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
81868528 {
81878529 // String ext = "_highres";
81888530 // if (REDUCETEXTURE)
....@@ -8199,52 +8541,17 @@
81998541 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
82008542 if (!cachefile.exists())
82018543 {
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))
8544
+ //if (texturedata.getWidth() == texturedata.getHeight())
82118545 {
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);
8546
+ BufferedImage rendImage = CreateBim(texturedata);
8547
+
82428548 ImageWriter writer = null;
82438549 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
82448550 if (iter.hasNext()) {
82458551 writer = (ImageWriter)iter.next();
82468552 }
8247
- float compressionQuality = 0.9f;
8553
+
8554
+ float compressionQuality = 0.85f;
82488555 try
82498556 {
82508557 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8261,18 +8568,20 @@
82618568 }
82628569 }
82638570 }
8264
-
8571
+
8572
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8573
+
82658574 //System.out.println("Texture = " + tex);
8266
- if (textures.containsKey(texname))
8575
+ if (textures.containsKey(tex))
82678576 {
8268
- CacheTexture thetex = textures.get(texname);
8577
+ CacheTexture thetex = textures.get(tex);
82698578 thetex.texture.disable();
82708579 thetex.texture.dispose();
8271
- textures.remove(texname);
8580
+ textures.remove(tex);
82728581 }
82738582
8274
- texture.texturedata = texturedata;
8275
- textures.put(texname, texture);
8583
+ //texture.texturedata = texturedata;
8584
+ textures.put(tex, texturecache);
82768585
82778586 // newtex = true;
82788587 }
....@@ -8288,10 +8597,44 @@
82888597 }
82898598 }
82908599
8291
- return texture;
8600
+ return texturecache;
82928601 }
82938602
8294
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution)
8603
+ static void EmbedTextures(cTexture tex)
8604
+ {
8605
+ if (tex.pigmentdata == null)
8606
+ {
8607
+ //String texname = Object3D.GetPigment(tex);
8608
+
8609
+ CacheTexture texturecache = texturepigment.get(tex);
8610
+
8611
+ if (texturecache != null)
8612
+ {
8613
+ tex.pw = texturecache.texturedata.getWidth();
8614
+ tex.ph = texturecache.texturedata.getHeight();
8615
+ tex.pigmentdata = //CompressJPEG(CreateBim
8616
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8617
+ ;
8618
+ //, tex.pw, tex.ph), 0.5f);
8619
+ }
8620
+ }
8621
+
8622
+ if (tex.bumpdata == null)
8623
+ {
8624
+ //String texname = Object3D.GetBump(tex);
8625
+
8626
+ CacheTexture texturecache = texturebump.get(tex);
8627
+
8628
+ if (texturecache != null)
8629
+ {
8630
+ tex.bw = texturecache.texturedata.getWidth();
8631
+ tex.bh = texturecache.texturedata.getHeight();
8632
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8633
+ }
8634
+ }
8635
+ }
8636
+
8637
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
82958638 {
82968639 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
82978640
....@@ -8309,21 +8652,21 @@
83098652 return texture!=null?texture.texture:null;
83108653 }
83118654
8312
- public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution)
8655
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
83138656 {
83148657 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
83158658
83168659 return texture!=null?texture.texturedata:null;
83178660 }
83188661
8319
- boolean BindTexture(String tex, boolean bump, int resolution)
8662
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
83208663 {
83218664 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
83228665 {
83238666 return false;
83248667 }
83258668
8326
- boolean newtex = false;
8669
+ //boolean newtex = false;
83278670
83288671 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
83298672
....@@ -8355,9 +8698,75 @@
83558698 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
83568699 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
83578700
8358
- return newtex;
8701
+ return true; // Warning: not used.
83598702 }
83608703
8704
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8705
+ {
8706
+ try
8707
+ {
8708
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8709
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8710
+ ImageWriter writer = writers.next();
8711
+
8712
+ ImageWriteParam param = writer.getDefaultWriteParam();
8713
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8714
+ param.setCompressionQuality(quality);
8715
+
8716
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8717
+ writer.setOutput(ios);
8718
+ writer.write(null, new IIOImage(image, null, null), param);
8719
+
8720
+ byte[] data = baos.toByteArray();
8721
+ writer.dispose();
8722
+ return data;
8723
+ }
8724
+ catch (Exception e)
8725
+ {
8726
+ e.printStackTrace();
8727
+ return null;
8728
+ }
8729
+ }
8730
+
8731
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8732
+ {
8733
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8734
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8735
+ ImageReader reader = writers.next();
8736
+
8737
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8738
+
8739
+ ImageReadParam param = reader.getDefaultReadParam();
8740
+ param.setDestination(bim);
8741
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8742
+
8743
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8744
+ reader.setInput(ios);
8745
+ BufferedImage bim2 = reader.read(0, param);
8746
+ reader.dispose();
8747
+
8748
+// WritableRaster raster = bim2.getRaster();
8749
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8750
+// byte[] bytes = data.getData();
8751
+//
8752
+// int[] pixels = new int[bytes.length/3];
8753
+// for (int i=pixels.length; --i>=0;)
8754
+// {
8755
+// int i3 = i*3;
8756
+// pixels[i] = 0xFF;
8757
+// pixels[i] <<= 8;
8758
+// pixels[i] |= bytes[i3+2] & 0xFF;
8759
+// pixels[i] <<= 8;
8760
+// pixels[i] |= bytes[i3+1] & 0xFF;
8761
+// pixels[i] <<= 8;
8762
+// pixels[i] |= bytes[i3] & 0xFF;
8763
+// }
8764
+//
8765
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8766
+
8767
+ return bim;
8768
+ }
8769
+
83618770 ShadowBuffer shadowPBuf;
83628771 AntialiasBuffer antialiasPBuf;
83638772 int MAXSTACK;
....@@ -8374,10 +8783,12 @@
83748783
83758784 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
83768785 MAXSTACK = temp[0];
8377
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8786
+ if (Globals.DEBUG)
8787
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
83788788 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
83798789 MAXSTACK = temp[0];
8380
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8790
+ if (Globals.DEBUG)
8791
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
83818792
83828793 // Use debug pipeline
83838794 //drawable.setGL(new DebugGL(gl)); //
....@@ -8385,7 +8796,8 @@
83858796 gl = drawable.getGL(); //
83868797
83878798 GL gl3 = getGL();
8388
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8799
+ if (Globals.DEBUG)
8800
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
83898801
83908802
83918803 //float pos[] = { 100, 100, 100, 0 };
....@@ -8550,7 +8962,7 @@
85508962
85518963 if (cubemap == null)
85528964 {
8553
- LoadEnvy(5);
8965
+ //LoadEnvy(1);
85548966 }
85558967
85568968 //cubemap.enable();
....@@ -8826,6 +9238,8 @@
88269238
88279239 void LoadEnvy(int which)
88289240 {
9241
+ assert(false);
9242
+
88299243 String name;
88309244 String ext;
88319245
....@@ -8837,37 +9251,58 @@
88379251 cubemap = null;
88389252 return;
88399253 case 1:
8840
- name = "cubemaps/box_";
8841
- ext = "png";
9254
+ name = "cubemaps/rgb/";
9255
+ ext = "jpg";
88429256 reverseUP = false;
88439257 break;
88449258 case 2:
8845
- name = "cubemaps/uffizi_";
8846
- ext = "png";
8847
- break; // reverseUP = true; break;
9259
+ name = "cubemaps/uffizi/";
9260
+ ext = "jpg";
9261
+ reverseUP = false;
9262
+ break;
88489263 case 3:
8849
- name = "cubemaps/CloudyHills_";
8850
- ext = "tga";
9264
+ name = "cubemaps/CloudyHills/";
9265
+ ext = "jpg";
88519266 reverseUP = false;
88529267 break;
88539268 case 4:
8854
- name = "cubemaps/cornell_";
9269
+ name = "cubemaps/cornell/";
88559270 ext = "png";
88569271 reverseUP = false;
88579272 break;
9273
+ case 5:
9274
+ name = "cubemaps/skycube/";
9275
+ ext = "jpg";
9276
+ reverseUP = false;
9277
+ break;
9278
+ case 6:
9279
+ name = "cubemaps/SaintLazarusChurch3/";
9280
+ ext = "jpg";
9281
+ reverseUP = false;
9282
+ break;
9283
+ case 7:
9284
+ name = "cubemaps/Sodermalmsallen/";
9285
+ ext = "jpg";
9286
+ reverseUP = false;
9287
+ break;
9288
+ case 8:
9289
+ name = "cubemaps/Sodermalmsallen2/";
9290
+ ext = "jpg";
9291
+ reverseUP = false;
9292
+ break;
9293
+ case 9:
9294
+ name = "cubemaps/UnionSquare/";
9295
+ ext = "jpg";
9296
+ reverseUP = false;
9297
+ break;
88589298 default:
8859
- name = "cubemaps/rgb_";
8860
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9299
+ name = "cubemaps/box/";
9300
+ ext = "png"; /*mipmap = true;*/
9301
+ reverseUP = false;
88619302 break;
88629303 }
8863
-
8864
- try
8865
- {
8866
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
8867
- } catch (IOException e)
8868
- {
8869
- throw new RuntimeException(e);
8870
- }
9304
+
9305
+ LoadSkybox(name, ext, mipmap);
88719306 }
88729307
88739308 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -8899,8 +9334,12 @@
88999334 static double[] model = new double[16];
89009335 double[] camera2light = new double[16];
89019336 double[] light2camera = new double[16];
8902
- int newenvy = -1;
8903
- boolean envyoff = true; // false;
9337
+
9338
+ //int newenvy = -1;
9339
+ //boolean envyoff = false;
9340
+
9341
+ String loadedskyboxname;
9342
+
89049343 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
89059344 //float[] light0 = { 0,0,0 };
89069345 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9193,11 +9632,35 @@
91939632 jy8[3] = 0.5f;
91949633 }
91959634
9196
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9635
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
91979636 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
91989637 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
91999638 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
92009639
9640
+ void ResetOptions()
9641
+ {
9642
+ options1[0] = 100;
9643
+ options1[1] = 0.025f;
9644
+ options1[2] = 0.01f;
9645
+ options1[3] = 0;
9646
+ options1[4] = 0;
9647
+
9648
+ options2[0] = 0;
9649
+ options2[1] = 0.75f;
9650
+ options2[2] = 0;
9651
+ options2[3] = 0;
9652
+
9653
+ options3[0] = 1;
9654
+ options3[1] = 1;
9655
+ options3[2] = 1;
9656
+ options3[3] = 0;
9657
+
9658
+ options4[0] = 1;
9659
+ options4[1] = 0;
9660
+ options4[2] = 1;
9661
+ options4[3] = 0;
9662
+ }
9663
+
92019664 static int imagecount = 0; // movie generation
92029665
92039666 static int jitter = 0;
....@@ -9293,8 +9756,8 @@
92939756 assert (parentcam != renderCamera);
92949757
92959758 if (renderCamera != lightCamera)
9296
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9297
- LA.matConcat(matrix, parentcam.toParent, matrix);
9759
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9760
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
92989761
92999762 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
93009763
....@@ -9309,8 +9772,8 @@
93099772 LA.matCopy(renderCamera.fromScreen, matrix);
93109773
93119774 if (renderCamera != lightCamera)
9312
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9313
- LA.matConcat(parentcam.fromParent, matrix, matrix);
9775
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9776
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
93149777
93159778 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
93169779
....@@ -9356,10 +9819,12 @@
93569819 rati = 1 / rati;
93579820 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
93589821 }
9359
- assert (newenvy == -1);
9822
+
9823
+ //assert (newenvy == -1);
9824
+
93609825 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
93619826 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9362
- DrawSkyBox(gl);
9827
+ DrawSkyBox(gl, (float)rati);
93639828 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
93649829 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
93659830 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -9382,7 +9847,7 @@
93829847 //gl.glFlush();
93839848 gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE);
93849849
9385
- if (ANIMATION && ABORTED)
9850
+ if (Globals.ANIMATION && ABORTED)
93869851 {
93879852 System.err.println(" ABORTED FRAME");
93889853 break;
....@@ -9412,7 +9877,7 @@
94129877 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
94139878
94149879 // save image
9415
- if (ANIMATION && !ABORTED)
9880
+ if (Globals.ANIMATION && !ABORTED)
94169881 {
94179882 VPwidth = viewport[2];
94189883 VPheight = viewport[3];
....@@ -9523,11 +9988,11 @@
95239988
95249989 // imagecount++;
95259990
9526
- String fullname = filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
9991
+ String fullname = Globals.filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
95279992
95289993 if (!BOXMODE)
95299994 {
9530
- System.out.println("image: " + fullname + " (wav cursor=" + (GrafreeD.wav.cursor / 735 / 4) + ")");
9995
+ System.out.println("image: " + fullname + " (wav cursor=" + (Grafreed.wav.cursor / 735 / 4) + ")");
95319996 }
95329997
95339998 if (!BOXMODE)
....@@ -9565,7 +10030,7 @@
956510030 ABORTED = false;
956610031 }
956710032 else
9568
- GrafreeD.wav.cursor += 735 * ACSIZE;
10033
+ Grafreed.wav.cursor += 735 * ACSIZE;
956910034
957010035 if (false)
957110036 {
....@@ -10225,14 +10690,23 @@
1022510690 static boolean init = false;
1022610691
1022710692 double[][] matrix = LA.newMatrix();
10693
+
10694
+ // This is to refresh the UI of the material panel.
10695
+ ObjEditor patchMaterial;
1022810696
1022910697 public void display(GLAutoDrawable drawable)
1023010698 {
10231
- if (GrafreeD.savesound && GrafreeD.hassound)
10699
+ if (patchMaterial.patchMaterial)
1023210700 {
10233
- GrafreeD.wav.save();
10234
- GrafreeD.savesound = false;
10235
- GrafreeD.hassound = false;
10701
+ patchMaterial.patchMaterial = false;
10702
+ patchMaterial.objectPanel.setSelectedIndex(1);
10703
+ }
10704
+
10705
+ if (Grafreed.savesound && Grafreed.hassound)
10706
+ {
10707
+ Grafreed.wav.save();
10708
+ Grafreed.savesound = false;
10709
+ Grafreed.hassound = false;
1023610710 }
1023710711 // if (DEBUG_SELECTION)
1023810712 // {
....@@ -10308,6 +10782,7 @@
1030810782 ANTIALIAS = 0;
1030910783 //System.out.println("RESTART");
1031010784 AAtimer.restart();
10785
+ Globals.TIMERRUNNING = true;
1031110786 }
1031210787 }
1031310788 }
....@@ -10362,7 +10837,7 @@
1036210837 Object3D theobject = object;
1036310838 Object3D theparent = object.parent;
1036410839 object.parent = null;
10365
- object = (Object3D)GrafreeD.clone(object);
10840
+ object = (Object3D)Grafreed.clone(object);
1036610841 object.Stripify();
1036710842 if (theobject.selection == null || theobject.selection.Size() == 0)
1036810843 theobject.PreprocessOcclusion(this);
....@@ -10375,13 +10850,14 @@
1037510850 ambientOcclusion = false;
1037610851 }
1037710852
10378
- if (Globals.lighttouched && DrawMode() == DEFAULT && !lightMode) // && !FROZEN)
10853
+ if (//Globals.lighttouched &&
10854
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1037910855 {
1038010856 //if (RENDERSHADOW) // ?
1038110857 if (!IsFrozen())
1038210858 {
1038310859 // dec 2012
10384
- if (!ambientOcclusion && !(!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0))
10860
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
1038510861 {
1038610862 Globals.framecount++;
1038710863 shadowbuffer.display();
....@@ -10394,7 +10870,7 @@
1039410870
1039510871 if (wait)
1039610872 {
10397
- Sleep(500);
10873
+ Sleep(200); // blocks everything
1039810874
1039910875 wait = false;
1040010876 }
....@@ -10508,8 +10984,8 @@
1050810984
1050910985 // if (parentcam != renderCamera) // not a light
1051010986 if (cam != lightCamera)
10511
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10512
- LA.matConcat(matrix, parentcam.toParent, matrix);
10987
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10988
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1051310989
1051410990 for (int j = 0; j < 4; j++)
1051510991 {
....@@ -10523,8 +10999,8 @@
1052310999
1052411000 // if (parentcam != renderCamera) // not a light
1052511001 if (cam != lightCamera)
10526
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10527
- LA.matConcat(parentcam.fromParent, matrix, matrix);
11002
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11003
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1052811004
1052911005 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1053011006
....@@ -10610,13 +11086,43 @@
1061011086 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1061111087 }
1061211088
10613
- if (newenvy > -1)
11089
+// if (newenvy > -1)
11090
+// {
11091
+// LoadEnvy(newenvy);
11092
+// }
11093
+//
11094
+// newenvy = -1;
11095
+
11096
+ if (transformMode) // object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
1061411097 {
10615
- LoadEnvy(newenvy);
11098
+ if (cubemaprgb == null)
11099
+ {
11100
+ cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb2" + "/", "jpg", false);
11101
+ }
11102
+
11103
+ cubemap = cubemaprgb;
1061611104 }
10617
-
10618
- newenvy = -1;
10619
-
11105
+ else
11106
+ {
11107
+ if (object.skyboxname != null)
11108
+ {
11109
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11110
+ {
11111
+ if (cubemap != null && cubemap != cubemaprgb)
11112
+ cubemap.dispose();
11113
+ cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11114
+ loadedskyboxname = object.skyboxname;
11115
+ }
11116
+ }
11117
+ else
11118
+ {
11119
+ cubemapcustom = null;
11120
+ loadedskyboxname = null;
11121
+ }
11122
+
11123
+ cubemap = cubemapcustom;
11124
+ }
11125
+
1062011126 ratio = ((double) getWidth()) / getHeight();
1062111127 //System.out.println("ratio = " + ratio);
1062211128
....@@ -10632,7 +11138,7 @@
1063211138
1063311139 if (!IsFrozen() && !ambientOcclusion)
1063411140 {
10635
- DrawSkyBox(gl);
11141
+ DrawSkyBox(gl, (float)ratio);
1063611142 }
1063711143
1063811144 //if (selection_view == -1)
....@@ -10783,7 +11289,16 @@
1078311289 // Bump noise
1078411290 gl.glActiveTexture(GL.GL_TEXTURE6);
1078511291 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
10786
- BindTexture(NOISE_TEXTURE, false, 2);
11292
+
11293
+ try
11294
+ {
11295
+ BindTexture(NOISE_TEXTURE, false, 2);
11296
+ }
11297
+ catch (Exception e)
11298
+ {
11299
+ System.err.println("FAILED: " + NOISE_TEXTURE);
11300
+ }
11301
+
1078711302
1078811303 gl.glActiveTexture(GL.GL_TEXTURE0);
1078911304 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -10806,9 +11321,9 @@
1080611321
1080711322 gl.glMatrixMode(GL.GL_MODELVIEW);
1080811323
10809
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10810
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10811
-//gl.glEnable(gl.GL_MULTISAMPLE);
11324
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11325
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11326
+gl.glEnable(gl.GL_MULTISAMPLE);
1081211327 } else
1081311328 {
1081411329 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -10819,7 +11334,7 @@
1081911334 //System.out.println("BLENDING ON");
1082011335 gl.glEnable(GL.GL_BLEND);
1082111336 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
10822
-
11337
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1082311338 gl.glMatrixMode(gl.GL_PROJECTION);
1082411339 gl.glLoadIdentity();
1082511340
....@@ -10908,8 +11423,8 @@
1090811423 System.err.println("parentcam != renderCamera");
1090911424
1091011425 // if (cam != lightCamera)
10911
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10912
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11426
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11427
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1091311428 }
1091411429
1091511430 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -10930,8 +11445,8 @@
1093011445 if (true) // TODO
1093111446 {
1093211447 if (cam != lightCamera)
10933
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10934
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11448
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11449
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
1093511450 }
1093611451
1093711452 LA.xformPos(light0, cam.toScreen, light0);
....@@ -11068,7 +11583,7 @@
1106811583 }
1106911584 }
1107011585
11071
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11586
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1107211587 {
1107311588 //gl.glDepthFunc(GL.GL_LEQUAL);
1107411589 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11076,24 +11591,21 @@
1107611591
1107711592 boolean texon = textureon;
1107811593
11079
- if (RENDERPROGRAM > 0)
11080
- {
11081
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11082
- textureon = false;
11083
- }
11594
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11595
+ textureon = false;
11596
+
1108411597 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1108511598 //System.out.println("ALLO");
1108611599 gl.glColorMask(false, false, false, false);
1108711600 DrawObject(gl);
11088
- if (RENDERPROGRAM > 0)
11089
- {
11090
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11091
- textureon = texon;
11092
- }
11601
+
11602
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11603
+ textureon = texon;
11604
+
1109311605 gl.glColorMask(true, true, true, true);
1109411606
1109511607 gl.glDepthFunc(GL.GL_EQUAL);
11096
- //gl.glDepthMask(false);
11608
+ gl.glDepthMask(false);
1109711609 }
1109811610
1109911611 if (false) // DrawMode() == SHADOW)
....@@ -11247,8 +11759,14 @@
1124711759 {
1124811760 renderpass++;
1124911761 // System.out.println("Draw object... ");
11762
+ STEP = 1;
1125011763 if (FAST) // in case there is no script
11251
- STEP = 16;
11764
+ STEP = 8;
11765
+
11766
+ if (CURRENTANTIALIAS == 0 || ACSIZE == 1)
11767
+ {
11768
+ STEP *= 4;
11769
+ }
1125211770
1125311771 //object.FullInvariants();
1125411772
....@@ -11262,23 +11780,44 @@
1126211780 e.printStackTrace();
1126311781 }
1126411782
11265
- if (GrafreeD.RENDERME > 0)
11266
- GrafreeD.RENDERME--; // mechante magouille
11783
+ if (Grafreed.RENDERME > 0)
11784
+ Grafreed.RENDERME--; // mechante magouille
1126711785
1126811786 Globals.ONESTEP = false;
1126911787 }
1127011788
1127111789 static boolean zoomonce = false;
1127211790
11791
+ static void CreateSelectedPoint()
11792
+ {
11793
+ if (selectedpoint == null)
11794
+ {
11795
+ debugpointG = new Sphere();
11796
+ debugpointP = new Sphere();
11797
+ debugpointC = new Sphere();
11798
+ debugpointR = new Sphere();
11799
+
11800
+ selectedpoint = new Superellipsoid();
11801
+
11802
+ for (int i=0; i<8; i++)
11803
+ {
11804
+ debugpoints[i] = new Sphere();
11805
+ }
11806
+ }
11807
+ }
11808
+
1127311809 void DrawObject(GL gl, boolean draw)
1127411810 {
11811
+ // To clear camera values
11812
+ ResetOptions();
11813
+
1127511814 //System.out.println("DRAW OBJECT " + mouseDown);
1127611815 // DrawMode() = SELECTION;
1127711816 //GL gl = getGL();
1127811817 if ((TRACK || SHADOWTRACK) || zoomonce)
1127911818 {
1128011819 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11281
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11820
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1128211821 pingthread.StepToTarget(true); // true);
1128311822 // zoomonce = false;
1128411823 }
....@@ -11333,7 +11872,14 @@
1133311872
1133411873 usedtextures.clear();
1133511874
11336
- BindTextures(DEFAULT_TEXTURES, 2);
11875
+ try
11876
+ {
11877
+ BindTextures(DEFAULT_TEXTURES, 2);
11878
+ }
11879
+ catch (Exception e)
11880
+ {
11881
+ System.err.println("FAILED: " + DEFAULT_TEXTURES);
11882
+ }
1133711883 }
1133811884 //System.out.println("--> " + stackdepth);
1133911885 // GrafreeD.traceon();
....@@ -11343,8 +11889,9 @@
1134311889
1134411890 if (DrawMode() == DEFAULT)
1134511891 {
11346
- if (DEBUG)
11892
+ if (Globals.DEBUG)
1134711893 {
11894
+ CreateSelectedPoint();
1134811895 float radius = 0.05f;
1134911896 if (selectedpoint.radius != radius)
1135011897 {
....@@ -11398,20 +11945,32 @@
1139811945 ReleaseTextures(DEFAULT_TEXTURES);
1139911946
1140011947 if (CLEANCACHE)
11401
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11948
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1140211949 {
11403
- String tex = e.nextElement();
11950
+ cTexture tex = e.nextElement();
1140411951
1140511952 // System.out.println("Texture --------- " + tex);
1140611953
11407
- if (tex.equals("WHITE_NOISE"))
11954
+ if (tex.equals("WHITE_NOISE:"))
1140811955 continue;
1140911956
11410
- if (!usedtextures.containsKey(tex))
11957
+ if (!usedtextures.contains(tex))
1141111958 {
11959
+ CacheTexture gettex = texturepigment.get(tex);
1141211960 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11413
- textures.get(tex).texture.dispose();
11414
- textures.remove(tex);
11961
+ if (gettex != null)
11962
+ {
11963
+ gettex.texture.dispose();
11964
+ texturepigment.remove(tex);
11965
+ }
11966
+
11967
+ gettex = texturebump.get(tex);
11968
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11969
+ if (gettex != null)
11970
+ {
11971
+ gettex.texture.dispose();
11972
+ texturebump.remove(tex);
11973
+ }
1141511974 }
1141611975 }
1141711976 }
....@@ -11424,7 +11983,14 @@
1142411983 if (checker != null && DrawMode() == DEFAULT)
1142511984 {
1142611985 //BindTexture(IMMORTAL_TEXTURE);
11427
- BindTextures(checker.GetTextures(), checker.texres);
11986
+ try
11987
+ {
11988
+ BindTextures(checker.GetTextures(), checker.texres);
11989
+ }
11990
+ catch (Exception e)
11991
+ {
11992
+ System.err.println("FAILED: " + checker.GetTextures());
11993
+ }
1142811994 // NEAREST
1142911995 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
1143011996 DrawChecker(gl);
....@@ -11506,7 +12072,7 @@
1150612072 return;
1150712073 }
1150812074
11509
- String string = obj.GetToolTip();
12075
+ String string = obj.toString(); //.GetToolTip();
1151012076
1151112077 GL gl = GetGL();
1151212078
....@@ -11823,8 +12389,8 @@
1182312389 //obj.TransformToWorld(light, light);
1182412390 for (int i = tp.size(); --i >= 0;)
1182512391 {
11826
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
11827
- LA.xformPos(light, tp.get(i).toParent, light);
12392
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12393
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1182812394 }
1182912395
1183012396
....@@ -11841,8 +12407,8 @@
1184112407 parentcam = cameras[0];
1184212408 }
1184312409
11844
- for (int count = parentcam.GetTransformCount(); --count>=0;)
11845
- LA.xformPos(light, parentcam.toParent, light); // may 2013
12410
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
12411
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1184612412
1184712413 LA.xformPos(light, renderCamera.toScreen, light);
1184812414
....@@ -11932,8 +12498,76 @@
1193212498
1193312499 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1193412500
11935
- String program =
12501
+ String programmin =
12502
+ // Min shader
1193612503 "!!ARBfp1.0\n" +
12504
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12505
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12506
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12507
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12508
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12509
+ "PARAM light2cam0 = program.env[10];" +
12510
+ "PARAM light2cam1 = program.env[11];" +
12511
+ "PARAM light2cam2 = program.env[12];" +
12512
+ "TEMP temp;" +
12513
+ "TEMP light;" +
12514
+ "TEMP ndotl;" +
12515
+ "TEMP normal;" +
12516
+ "TEMP depth;" +
12517
+ "TEMP eye;" +
12518
+ "TEMP pos;" +
12519
+
12520
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12521
+ Normalize("normal") +
12522
+ "MOV light, state.light[0].position;" +
12523
+ "DP3 ndotl.x, light, normal;" +
12524
+
12525
+ // shadow
12526
+ "MOV pos, fragment.texcoord[1];" +
12527
+ "MOV temp, pos;" +
12528
+ ShadowTextureFetch("depth", "temp", "1") +
12529
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12530
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12531
+
12532
+ // No shadow when out of frustum
12533
+ //"SGE temp.y, depth.z, zero123.y;" +
12534
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12535
+
12536
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12537
+
12538
+ // Backlit
12539
+ "MOV pos.w, zero123.y;" +
12540
+ "DP4 eye.x, pos, light2cam0;" +
12541
+ "DP4 eye.y, pos, light2cam1;" +
12542
+ "DP4 eye.z, pos, light2cam2;" +
12543
+ Normalize("eye") +
12544
+
12545
+ "DP3 ndotl.y, -eye, normal;" +
12546
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12547
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12548
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12549
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12550
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12551
+
12552
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12553
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12554
+
12555
+ // Pigment
12556
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12557
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12558
+ "MUL temp, temp, ndotl.x;" +
12559
+
12560
+ "MUL temp, temp, zero123.z;" +
12561
+
12562
+ //"MUL temp, temp, ndotl.y;" +
12563
+
12564
+ "MOV temp.w, zero123.y;" + // reset alpha
12565
+ "MOV result.color, temp;" +
12566
+ "END";
12567
+
12568
+ String programmax =
12569
+ "!!ARBfp1.0\n" +
12570
+
1193712571 //"OPTION ARB_fragment_program_shadow;" +
1193812572 "PARAM light2cam0 = program.env[10];" +
1193912573 "PARAM light2cam1 = program.env[11];" +
....@@ -11959,7 +12593,7 @@
1195912593 "PARAM params4 = program.env[4];" + // anisoV, cameralight, selfshadow, shadow
1196012594 "PARAM params5 = program.env[5];" + // texture, opacity, fakedepth, shadowbias
1196112595 "PARAM params6 = program.env[6];" + // bump, noise, borderfade, fog punchthrough
11962
- "PARAM params7 = program.env[7];" + // noise power, opacity power
12596
+ "PARAM params7 = program.env[7];" + // noise power, opacity power, parallax
1196312597 "PARAM options0 = program.env[63];" + // fog density, intensity, elevation
1196412598 "PARAM options1 = program.env[62];" + // fog rgb color
1196512599 "PARAM options2 = program.env[61];" + // image intensity, subsurface, lightsheen
....@@ -12048,8 +12682,7 @@
1204812682 "TEMP shininess;" +
1204912683 "\n" +
1205012684 "MOV texSamp, one;" +
12051
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12052
-
12685
+
1205312686 "MOV mapgrid.x, one2048th.x;" +
1205412687 "MOV temp, fragment.texcoord[1];" +
1205512688 /*
....@@ -12070,20 +12703,20 @@
1207012703 "MUL temp, floor, mapgrid.x;" +
1207112704 //"TEX depth0, temp, texture[1], 2D;" +
1207212705 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12073
- TextureFetch("depth0", "temp", "1") +
12706
+ ShadowTextureFetch("depth0", "temp", "1") +
1207412707 "") +
1207512708 "ADD temp.x, temp.x, mapgrid.x;" +
1207612709 //"TEX depth1, temp, texture[1], 2D;" +
1207712710 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12078
- TextureFetch("depth1", "temp", "1") +
12711
+ ShadowTextureFetch("depth1", "temp", "1") +
1207912712 "") +
1208012713 "ADD temp.y, temp.y, mapgrid.x;" +
1208112714 //"TEX depth2, temp, texture[1], 2D;" +
12082
- TextureFetch("depth2", "temp", "1") +
12715
+ ShadowTextureFetch("depth2", "temp", "1") +
1208312716 "SUB temp.x, temp.x, mapgrid.x;" +
1208412717 //"TEX depth3, temp, texture[1], 2D;" +
1208512718 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12086
- TextureFetch("depth3", "temp", "1") +
12719
+ ShadowTextureFetch("depth3", "temp", "1") +
1208712720 "") +
1208812721 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1208912722 //"MOV params, material;" +
....@@ -12205,7 +12838,7 @@
1220512838 "POW texSamp.a, texSamp.a, params6.w;" + // fog punch through shortcut
1220612839 // mar 2013 ??? "KIL alpha.a;" +
1220712840 "MOV alpha, texSamp.aaaa;" + // y;" +
12208
- "KIL alpha.a;" +
12841
+ "KIL alpha.a;" + // not sure with parallax mapping
1220912842 /*
1221012843 "MUL temp.xy, temp, two;" +
1221112844 "TXB bump, temp, texture[0], 2D;" +
....@@ -12291,11 +12924,6 @@
1229112924 "SUB bump0, bump0, half;" +
1229212925 "ADD bump, bump, bump0;" +
1229312926
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
-
1229912927 // double-sided
1230012928 /**/
1230112929 (doublesided?"DP3 temp.z, normal, eye;" +
....@@ -12325,6 +12953,41 @@
1232512953 Normalize("U") +
1232612954
1232712955 // parallax mapping
12956
+
12957
+ "DP3 temp2.x, V, eye;" +
12958
+ "DP3 temp2.y, U, eye;" +
12959
+ "DP3 temp2.z, normal, eye;" +
12960
+ "RCP temp2.z, temp2.z;" +
12961
+
12962
+ "DP3 temp2.w, texSamp, texSamp;" + // Height
12963
+ "RSQ temp2.w, temp2.w;" +
12964
+ "RCP temp2.w, temp2.w;" +
12965
+
12966
+ "SUB temp2.w, temp2.w, half;" +
12967
+// "SGE temp.x, temp2.w, eps.x;" +
12968
+// "MUL temp2.w, temp2.w, temp.x;" +
12969
+
12970
+ //"MOV texSamp, U;" +
12971
+
12972
+ "MUL temp2.z, temp2.z, temp2.w;" +
12973
+ "MUL temp2.z, temp2.z, params7.z;" + // parallax
12974
+
12975
+ "MUL temp2, temp2, temp2.z;" +
12976
+
12977
+ "MOV temp, fragment.texcoord[0];" +
12978
+
12979
+ "SUB temp, temp, temp2;" +
12980
+
12981
+ "TEX texSamp, temp, texture[0], 2D;" +
12982
+ "POW texSamp.a, texSamp.a, params6.w;" + // punch through
12983
+ "MOV alpha, texSamp.aaaa;" +
12984
+
12985
+// parallax mapping
12986
+
12987
+ "MOV temp.x, texSamp.a;" +
12988
+ "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
12989
+ //"LRP texSamp0, params5.x, texSamp0, one;" +
12990
+ "MOV texSamp.a, temp.x;" +
1232812991
1232912992 //"MOV temp, fragment.texcoord[0];" +
1233012993 //
....@@ -12454,10 +13117,10 @@
1245413117 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1245513118 "") +
1245613119
12457
- // display shadow only (bump == 0)
13120
+ // display shadow only (fakedepth == 0)
1245813121 "SUB temp.x, half.x, shadow.x;" +
12459
- "MOV temp.y, -params6.x;" +
12460
- "SLT temp.z, temp.y, zero.x;" +
13122
+ "MOV temp.y, -params5.z;" + // params6.x;" +
13123
+ "SLT temp.z, temp.y, -c256i.x;" +
1246113124 "SUB temp.y, one.x, temp.z;" +
1246213125 "MUL temp.x, temp.x, temp.y;" +
1246313126 "KIL temp.x;" +
....@@ -12586,8 +13249,10 @@
1258613249 "MAX ndotl.x, ndotl.x, -ndotl.x;" +
1258713250
1258813251 "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
13252
+ // Tuning for default skin
13253
+ //"ADD temp.x, temp.x, options2.z;" + // lightsheen
13254
+ "MAD temp.x, options2.z, half.y, temp.x;" + // lightsheen
13255
+ "ADD temp.y, one.y, options2.y;" + // subsurface
1259113256 "MUL temp.x, temp.x, temp.y;" +
1259213257
1259313258 "MUL saturation, saturation, temp.xxxx;" +
....@@ -12786,8 +13451,19 @@
1278613451 //once = true;
1278713452 }
1278813453
12789
- System.out.print("Program #" + mode + "; length = " + program.length());
12790
- System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13454
+ String program = programmax;
13455
+
13456
+ if (Globals.MINSHADER)
13457
+ {
13458
+ program = programmin;
13459
+ }
13460
+
13461
+ if (Globals.DEBUG)
13462
+ {
13463
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13464
+ System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13465
+ }
13466
+
1279113467 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1279213468
1279313469 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -12834,7 +13510,8 @@
1283413510 "\n" +
1283513511 "END\n";
1283613512
12837
- System.out.println("Program shadow #" + 0 + "; length = " + program.length());
13513
+ if (Globals.DEBUG)
13514
+ System.out.println("Program shadow #" + 0 + "; length = " + program.length());
1283813515 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1283913516
1284013517 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -12879,25 +13556,26 @@
1287913556 return out;
1288013557 }
1288113558
12882
- String TextureFetch(String dest, String src, String unit)
13559
+ // Also does frustum culling
13560
+ String ShadowTextureFetch(String dest, String src, String unit)
1288313561 {
1288413562 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1288513563 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1288613564 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13565
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13566
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1288713567 "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;" +
13568
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13569
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1289213570 //"SWZ buffer, temp, w,w,w,w;";
12893
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13571
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1289413572 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1289513573 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1289613574 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
12897
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13575
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1289813576
12899
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
12900
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13577
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13578
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1290113579 }
1290213580
1290313581 String Shadow(String depth, String shadow)
....@@ -12919,12 +13597,16 @@
1291913597
1292013598 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1292113599 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13600
+
13601
+ // Compare fragment depth in light space with shadowmap.
1292213602 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1292313603 "SGE temp.y, temp.x, zero.x;" +
12924
- "SUB " + shadow + ".y, one.x, temp.y;" +
13604
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13605
+
13606
+ // Reverse comparison
1292513607 "SUB temp.x, one.x, temp.x;" +
1292613608 "MUL " + shadow + ".x, temp.x, temp.y;" +
12927
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13609
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1292813610 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1292913611
1293013612 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -12938,6 +13620,10 @@
1293813620 // No shadow for backface
1293913621 "DP3 temp.x, normal, lightd;" +
1294013622 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13623
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13624
+
13625
+ // No shadow when out of frustum
13626
+ "SGE temp.x, " + depth + ".z, one.z;" +
1294113627 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1294213628 "";
1294313629 }
....@@ -13083,8 +13769,9 @@
1308313769 /*static*/ float[] modelParams4 = new float[]{0, 0, 0, 0}; // anisoV, cameralight, selfshadow, shadow
1308413770 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1308513771 /*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;
13772
+ /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power, parallax
13773
+
13774
+ //Object3D.cVector2[] vector2buffer;
1308813775
1308913776 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1309013777 // OUT : diff, spec
....@@ -13100,9 +13787,10 @@
1310013787 "DP3 " + dest + ".z," + "normals," + "eye;" +
1310113788 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1310213789 //"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;" +
13790
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13791
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13792
+
13793
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1310613794 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1310713795 "RCP " + dest + ".w," + dest + ".w;" +
1310813796 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13496,7 +14184,7 @@
1349614184 public void mousePressed(MouseEvent e)
1349714185 {
1349814186 //System.out.println("mousePressed: " + e);
13499
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14187
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1350014188 }
1350114189
1350214190 static long prevtime = 0;
....@@ -13523,6 +14211,7 @@
1352314211
1352414212 //System.err.println("Dtime = " + Dtime + "; units = " + e.getUnitsToScroll() + "; ratio (units/ms) = " + ratio);
1352514213
14214
+ if (BUTTONLESSWHEEL)
1352614215 if (Math.abs(ratio) < 0.1 || Math.abs(Dtime) == 0) // < 30)
1352714216 {
1352814217 return;
....@@ -13531,7 +14220,7 @@
1353114220 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
1353214221
1353314222 // TIMER
13534
- if (!wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
14223
+ if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
1353514224 {
1353614225 keepboxmode = BOXMODE;
1353714226 keepsupport = SUPPORT;
....@@ -13571,8 +14260,8 @@
1357114260 // mode |= META;
1357214261 //}
1357314262
13574
- SetMouseMode(WHEEL | e.getModifiersEx());
13575
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14263
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14264
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1357614265 anchorX = ax;
1357714266 anchorY = ay;
1357814267 prevX = px;
....@@ -13606,6 +14295,7 @@
1360614295 else
1360714296 if (evt.getSource() == AAtimer)
1360814297 {
14298
+ Globals.TIMERRUNNING = false;
1360914299 if (mouseDown)
1361014300 {
1361114301 //new Exception().printStackTrace();
....@@ -13631,6 +14321,10 @@
1363114321 // LIVE = waslive;
1363214322 // wasliveok = true;
1363314323 // waslive = false;
14324
+
14325
+ // May 2019 Forget it:
14326
+ if (true)
14327
+ return;
1363414328
1363514329 // source == timer
1363614330 if (mouseDown)
....@@ -13661,7 +14355,7 @@
1366114355
1366214356 // fev 2014???
1366314357 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13664
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14358
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1366514359 pingthread.StepToTarget(true); // true);
1366614360 }
1366714361 // if (!LIVE)
....@@ -13670,12 +14364,13 @@
1367014364
1367114365 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1367214366
13673
- void clickStart(int x, int y, int modifiers)
14367
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1367414368 {
1367514369 if (!wasliveok)
1367614370 return;
1367714371
1367814372 AAtimer.restart(); //
14373
+ Globals.TIMERRUNNING = true;
1367914374
1368014375 // waslive = LIVE;
1368114376 // LIVE = false;
....@@ -13687,7 +14382,7 @@
1368714382 // touched = true; // main DL
1368814383 if (isRenderer)
1368914384 {
13690
- SetMouseMode(modifiers);
14385
+ SetMouseMode(modifiers, modifiersex);
1369114386 }
1369214387
1369314388 selectX = anchorX = x;
....@@ -13700,7 +14395,7 @@
1370014395 clicked = true;
1370114396 hold = false;
1370214397
13703
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14398
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1370414399 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1370514400 {
1370614401 // System.out.println("RESTART II " + modifiers);
....@@ -13725,14 +14420,15 @@
1372514420 drag = false;
1372614421 //System.out.println("Mouse DOWN");
1372714422 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);
14423
+ //ClickInfo info = new ClickInfo();
14424
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14425
+ object.clickInfo.pane = this;
14426
+ object.clickInfo.camera = renderCamera;
14427
+ object.clickInfo.x = x;
14428
+ object.clickInfo.y = y;
14429
+ object.clickInfo.modifiers = modifiersex;
14430
+ editObj = object.doEditClick(//info,
14431
+ 0);
1373614432 if (!editObj)
1373714433 {
1373814434 hasMarquee = true;
....@@ -13748,11 +14444,14 @@
1374814444
1374914445 public void mouseDragged(MouseEvent e)
1375014446 {
14447
+ Globals.MOUSEDRAGGED = true;
14448
+
14449
+ //System.out.println("mouseDragged: " + e);
1375114450 if (isRenderer)
1375214451 movingcamera = true;
14452
+
1375314453 //if (drawing)
1375414454 //return;
13755
- //System.out.println("mouseDragged: " + e);
1375614455 if ((e.getModifiersEx() & CTRL) != 0
1375714456 || (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen())
1375814457 {
....@@ -13760,7 +14459,7 @@
1376014459 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1376114460 }
1376214461 else
13763
- drag(e.getX(), e.getY(), e.getModifiersEx());
14462
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1376414463
1376514464 //try { Thread.sleep(1); } catch (Exception ex) {}
1376614465 }
....@@ -13933,6 +14632,7 @@
1393314632
1393414633 public void run()
1393514634 {
14635
+ new Exception().printStackTrace();
1393614636 System.exit(0);
1393714637 for (;;)
1393814638 {
....@@ -13996,7 +14696,7 @@
1399614696 {
1399714697 Globals.lighttouched = true;
1399814698 }
13999
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14699
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1400014700 }
1400114701 //else
1400214702 }
....@@ -14010,12 +14710,18 @@
1401014710 void GoDown(int mod)
1401114711 {
1401214712 MODIFIERS |= COMMAND;
14013
- /*
14713
+ boolean isVR = (mouseMode&VR)!=0;
14714
+ /**/
1401414715 if((mod&SHIFT) == SHIFT)
14015
- manipCamera.RotatePosition(0, -speed);
14716
+ {
14717
+ if (isVR)
14718
+ manipCamera.RotateInterest(0, -speed);
14719
+ else
14720
+ manipCamera.RotatePosition(0, -speed);
14721
+ }
1401614722 else
14017
- manipCamera.BackForth(0, -speed*delta, getWidth());
14018
- */
14723
+ manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth());
14724
+ /**/
1401914725 if ((mod & SHIFT) == SHIFT)
1402014726 {
1402114727 mouseMode = mouseMode; // VR??
....@@ -14024,6 +14730,8 @@
1402414730 mouseMode |= BACKFORTH;
1402514731 }
1402614732
14733
+ targetLookAt.set(manipCamera.lookAt);
14734
+
1402714735 //prevX = X = anchorX;
1402814736 prevY = Y = anchorY - (int) (renderCamera.Distance());
1402914737 }
....@@ -14031,12 +14739,19 @@
1403114739 void GoUp(int mod)
1403214740 {
1403314741 MODIFIERS |= COMMAND;
14034
- /*
14742
+ /**/
14743
+ boolean isVR = (mouseMode&VR)!=0;
14744
+
1403514745 if((mod&SHIFT) == SHIFT)
14036
- manipCamera.RotatePosition(0, speed);
14746
+ {
14747
+ if (isVR)
14748
+ manipCamera.RotateInterest(0, speed);
14749
+ else
14750
+ manipCamera.RotatePosition(0, speed);
14751
+ }
1403714752 else
14038
- manipCamera.BackForth(0, speed*delta, getWidth());
14039
- */
14753
+ manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth());
14754
+ /**/
1404014755 if ((mod & SHIFT) == SHIFT)
1404114756 {
1404214757 mouseMode = mouseMode;
....@@ -14045,6 +14760,8 @@
1404514760 mouseMode |= BACKFORTH;
1404614761 }
1404714762
14763
+ targetLookAt.set(manipCamera.lookAt);
14764
+
1404814765 //prevX = X = anchorX;
1404914766 prevY = Y = anchorY + (int) (renderCamera.Distance());
1405014767 }
....@@ -14052,12 +14769,17 @@
1405214769 void GoLeft(int mod)
1405314770 {
1405414771 MODIFIERS |= COMMAND;
14055
- /*
14772
+ /**/
1405614773 if((mod&SHIFT) == SHIFT)
14057
- manipCamera.RotatePosition(speed, 0);
14774
+ manipCamera.Translate(speed*delta, 0, getWidth());
1405814775 else
14059
- manipCamera.Translate(speed*delta, 0, getWidth());
14060
- */
14776
+ {
14777
+ if ((mouseMode&VR)!=0)
14778
+ manipCamera.RotateInterest(-speed, 0);
14779
+ else
14780
+ manipCamera.RotatePosition(speed, 0);
14781
+ }
14782
+ /**/
1406114783 if ((mod & SHIFT) == SHIFT)
1406214784 {
1406314785 mouseMode = mouseMode;
....@@ -14066,6 +14788,8 @@
1406614788 mouseMode |= ROTATE;
1406714789 } // TRANSLATE;
1406814790
14791
+ targetLookAt.set(manipCamera.lookAt);
14792
+
1406914793 prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance());
1407014794 prevY = Y = anchorY;
1407114795 }
....@@ -14073,12 +14797,18 @@
1407314797 void GoRight(int mod)
1407414798 {
1407514799 MODIFIERS |= COMMAND;
14076
- /*
14800
+ /**/
1407714801 if((mod&SHIFT) == SHIFT)
14078
- manipCamera.RotatePosition(-speed, 0);
14802
+ manipCamera.Translate(-speed*delta, 0, getWidth());
1407914803 else
14080
- manipCamera.Translate(-speed*delta, 0, getWidth());
14081
- */
14804
+ {
14805
+ if ((mouseMode&VR)!=0)
14806
+ manipCamera.RotateInterest(speed, 0);
14807
+ else
14808
+ manipCamera.RotatePosition(-speed, 0);
14809
+ }
14810
+
14811
+ /**/
1408214812 if ((mod & SHIFT) == SHIFT)
1408314813 {
1408414814 mouseMode = mouseMode;
....@@ -14087,6 +14817,8 @@
1408714817 mouseMode |= ROTATE;
1408814818 } // TRANSLATE;
1408914819
14820
+ targetLookAt.set(manipCamera.lookAt);
14821
+
1409014822 prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance());
1409114823 prevY = Y = anchorY;
1409214824 }
....@@ -14096,7 +14828,7 @@
1409614828 int X, Y;
1409714829 boolean SX, SY;
1409814830
14099
- void drag(int x, int y, int modifiers)
14831
+ void drag(int x, int y, int modifiers, int modifiersex)
1410014832 {
1410114833 if (IsFrozen())
1410214834 {
....@@ -14105,17 +14837,17 @@
1410514837
1410614838 drag = true; // NEW
1410714839
14108
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14840
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1410914841
1411014842 X = x;
1411114843 Y = y;
1411214844 // floating state for animation
14113
- MODIFIERS = modifiers;
14114
- modifiers &= ~1024;
14845
+ MODIFIERS = modifiersex;
14846
+ modifiersex &= ~1024;
1411514847 if (false) // modifiers != 0)
1411614848 {
1411714849 //new Exception().printStackTrace();
14118
- System.out.println("mouseDragged: " + modifiers);
14850
+ System.out.println("mouseDragged: " + modifiersex);
1411914851 System.out.println("SHIFT = " + SHIFT);
1412014852 System.out.println("CONTROL = " + COMMAND);
1412114853 System.out.println("META = " + META);
....@@ -14128,14 +14860,16 @@
1412814860 if (editObj)
1412914861 {
1413014862 drag = true;
14131
- ClickInfo info = new ClickInfo();
14132
- info.bounds.setBounds(0, 0,
14863
+ //ClickInfo info = new ClickInfo();
14864
+ object.clickInfo.bounds.setBounds(0, 0,
1413314865 (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);
14866
+ object.clickInfo.pane = this;
14867
+ object.clickInfo.camera = renderCamera;
14868
+ object.clickInfo.x = x;
14869
+ object.clickInfo.y = y;
14870
+ object //.GetWindow().copy
14871
+ .doEditDrag(//info,
14872
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1413914873 } else
1414014874 {
1414114875 if (x < startX)
....@@ -14284,23 +15018,27 @@
1428415018 }
1428515019 }
1428615020
15021
+// ClickInfo clickInfo = new ClickInfo();
15022
+
1428715023 public void mouseMoved(MouseEvent e)
1428815024 {
1428915025 //System.out.println("mouseMoved: " + e);
14290
-
1429115026 if (isRenderer)
1429215027 return;
1429315028
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;
15029
+ // Mouse cursor feedback
15030
+ object.clickInfo.x = e.getX();
15031
+ object.clickInfo.y = e.getY();
15032
+ object.clickInfo.modifiers = e.getModifiersEx();
15033
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
15034
+ object.clickInfo.pane = this;
15035
+ object.clickInfo.camera = renderCamera;
1430115036 if (!isRenderer)
1430215037 {
14303
- if (object.editWindow.copy.doEditClick(ci, 0))
15038
+ //ObjEditor editWindow = object.editWindow;
15039
+ //Object3D copy = editWindow.copy;
15040
+ if (object.doEditClick(//clickInfo,
15041
+ 0))
1430415042 {
1430515043 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1430615044 } else
....@@ -14312,7 +15050,11 @@
1431215050
1431315051 public void mouseReleased(MouseEvent e)
1431415052 {
15053
+ Globals.MOUSEDRAGGED = false;
15054
+
1431515055 movingcamera = false;
15056
+ X = 0; // getBounds().width/2;
15057
+ Y = 0; // getBounds().height/2;
1431615058 //System.out.println("mouseReleased: " + e);
1431715059 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1431815060 }
....@@ -14335,9 +15077,9 @@
1433515077 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1433615078 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1433715079
14338
- if (control || command || IsFrozen())
15080
+// No delay if (control || command || IsFrozen())
1433915081 timeout = true;
14340
- else
15082
+// ?? May 2019 else
1434115083 // timer.setDelay((modifiers & 128) != 0?0:350);
1434215084 mouseDown = false;
1434315085 if (!control && !command) // june 2013
....@@ -14447,7 +15189,7 @@
1444715189 System.out.println("keyReleased: " + e);
1444815190 }
1444915191
14450
- void SetMouseMode(int modifiers)
15192
+ void SetMouseMode(int modifiers, int modifiersex)
1445115193 {
1445215194 //System.out.println("SetMouseMode = " + modifiers);
1445315195 //modifiers &= ~1024;
....@@ -14459,25 +15201,25 @@
1445915201 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1446015202 // return;
1446115203 //System.out.println("SetMode = " + modifiers);
14462
- if ((modifiers & WHEEL) == WHEEL)
15204
+ if ((modifiersex & WHEEL) == WHEEL)
1446315205 {
1446415206 mouseMode |= ZOOM;
1446515207 }
1446615208
1446715209 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
14468
- if (capsLocked || (modifiers & META) == META)
15210
+ if (capsLocked) // || (modifiers & META) == META)
1446915211 {
1447015212 mouseMode |= VR; // BACKFORTH;
1447115213 }
14472
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
15214
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1447315215 {
1447415216 mouseMode |= SELECT;
1447515217 }
14476
- if ((modifiers & COMMAND) == COMMAND)
15218
+ if ((modifiersex & COMMAND) == COMMAND)
1447715219 {
1447815220 mouseMode |= SELECT;
1447915221 }
14480
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15222
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
1448115223 {
1448215224 mouseMode &= ~VR;
1448315225 mouseMode |= TRANSLATE;
....@@ -14506,7 +15248,7 @@
1450615248
1450715249 if (isRenderer) //
1450815250 {
14509
- SetMouseMode(modifiers);
15251
+ SetMouseMode(0, modifiers);
1451015252 }
1451115253
1451215254 Globals.theRenderer.keyPressed(key);
....@@ -14568,7 +15310,8 @@
1456815310 // break;
1456915311 case 'T':
1457015312 CACHETEXTURE ^= true;
14571
- textures.clear();
15313
+ texturepigment.clear();
15314
+ texturebump.clear();
1457215315 // repaint();
1457315316 break;
1457415317 case 'Y':
....@@ -14578,8 +15321,8 @@
1457815321 case 'K':
1457915322 KOMPACTTEXTURE ^= true;
1458015323 //textures.clear();
14581
- break;
14582
- case 'P': // Texture Projection macros
15324
+ // break;
15325
+ //case 'P': // Texture Projection macros
1458315326 // SAVETEXTURE ^= true;
1458415327 macromode = true;
1458515328 Udebug = Vdebug = NORMALdebug = false; programInitialized = false;
....@@ -14653,7 +15396,9 @@
1465315396 case 'E' : COMPACT ^= true;
1465415397 repaint();
1465515398 break;
14656
- case 'W' : DEBUGHSB ^= true;
15399
+ case 'W' : // Wide Window (fullscreen)
15400
+ //DEBUGHSB ^= true;
15401
+ ObjEditor.theFrame.ToggleFullScreen();
1465715402 repaint();
1465815403 break;
1465915404 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14678,8 +15423,8 @@
1467815423 RevertCamera();
1467915424 repaint();
1468015425 break;
14681
- case 'L':
1468215426 case 'l':
15427
+ //case 'L':
1468315428 if (lightMode)
1468415429 {
1468515430 lightMode = false;
....@@ -14698,7 +15443,7 @@
1469815443 targetLookAt.set(manipCamera.lookAt);
1469915444 repaint();
1470015445 break;
14701
- case 'p':
15446
+ case 'P': // p':
1470215447 // c'est quoi ca au juste? spherical ^= true;
1470315448 Skinshader ^= true; programInitialized = false;
1470415449 repaint();
....@@ -14743,20 +15488,24 @@
1474315488 OCCLUSION_CULLING ^= true;
1474415489 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1474515490 break;
14746
- case '0': envyoff ^= true; repaint(); break;
15491
+ //case '0': envyoff ^= true; repaint(); break;
1474715492 case '1':
1474815493 case '2':
1474915494 case '3':
1475015495 case '4':
1475115496 case '5':
14752
- newenvy = Character.getNumericValue(key);
14753
- repaint();
14754
- break;
1475515497 case '6':
1475615498 case '7':
1475715499 case '8':
1475815500 case '9':
14759
- BGcolor = (key - '6')/3.f;
15501
+ if (true) // envyoff)
15502
+ {
15503
+ BGcolor = (key - '1')/8.f;
15504
+ }
15505
+ else
15506
+ {
15507
+ //newenvy = Character.getNumericValue(key);
15508
+ }
1476015509 repaint();
1476115510 break;
1476215511 case '!':
....@@ -14822,9 +15571,9 @@
1482215571 case '_':
1482315572 kompactbit = 5;
1482415573 break;
14825
- case '+':
14826
- kompactbit = 6;
14827
- break;
15574
+// case '+':
15575
+// kompactbit = 6;
15576
+// break;
1482815577 case ' ':
1482915578 lightMode ^= true;
1483015579 Globals.lighttouched = true;
....@@ -14836,13 +15585,14 @@
1483615585 case ESC:
1483715586 RENDERPROGRAM += 1;
1483815587 RENDERPROGRAM %= 3;
15588
+
1483915589 repaint();
1484015590 break;
1484115591 case 'Z':
1484215592 //RESIZETEXTURE ^= true;
1484315593 //break;
1484415594 case 'z':
14845
- RENDERSHADOW ^= true;
15595
+ Globals.RENDERSHADOW ^= true;
1484615596 Globals.lighttouched = true;
1484715597 repaint();
1484815598 break;
....@@ -14875,8 +15625,9 @@
1487515625 case DELETE:
1487615626 ClearSelection();
1487715627 break;
14878
- /*
1487915628 case '+':
15629
+
15630
+ /*
1488015631 //fontsize += 1;
1488115632 bbzoom *= 2;
1488215633 repaint();
....@@ -14893,17 +15644,17 @@
1489315644 case '=':
1489415645 IncDepth();
1489515646 //fontsize += 1;
14896
- object.editWindow.refreshContents(true);
15647
+ object.GetWindow().refreshContents(true);
1489715648 maskbit = 6;
1489815649 break;
1489915650 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1490015651 DecDepth();
1490115652 maskbit = 5;
1490215653 //if(fontsize > 1) fontsize -= 1;
14903
- if (object.editWindow == null)
14904
- new Exception().printStackTrace();
14905
- else
14906
- object.editWindow.refreshContents(true);
15654
+// if (object.editWindow == null)
15655
+// new Exception().printStackTrace();
15656
+// else
15657
+ object.GetWindow().refreshContents(true);
1490715658 break;
1490815659 case '{':
1490915660 manipCamera.shaper_fovy /= 1.1;
....@@ -14966,7 +15717,7 @@
1496615717 //mode = ROTATE;
1496715718 if ((MODIFIERS & COMMAND) == 0) // VR??
1496815719 {
14969
- SetMouseMode(modifiers);
15720
+ SetMouseMode(0, modifiers);
1497015721 }
1497115722 }
1497215723
....@@ -15100,8 +15851,9 @@
1510015851
1510115852 protected void processMouseMotionEvent(MouseEvent e)
1510215853 {
15103
- //System.out.println("processMouseMotionEvent: " + mouseMode);
15104
- if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15854
+ //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
15855
+ //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15856
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1510515857 {
1510615858 mouseMoved(e);
1510715859 } else
....@@ -15126,11 +15878,12 @@
1512615878 }
1512715879 */
1512815880
15129
- object.editWindow.EditSelection();
15881
+ object.GetWindow().EditSelection(false);
1513015882 }
1513115883
1513215884 void SelectParent()
1513315885 {
15886
+ new Exception().printStackTrace();
1513415887 System.exit(0);
1513515888 Composite group = (Composite) object;
1513615889 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -15142,10 +15895,10 @@
1514215895 {
1514315896 //selectees.remove(i);
1514415897 System.out.println("select parent of " + elem);
15145
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15898
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1514615899 } else
1514715900 {
15148
- group.editWindow.Select(elem.GetTreePath(), first, true);
15901
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1514915902 }
1515015903
1515115904 first = false;
....@@ -15154,6 +15907,7 @@
1515415907
1515515908 void SelectChildren()
1515615909 {
15910
+ new Exception().printStackTrace();
1515715911 System.exit(0);
1515815912 /*
1515915913 Composite group = (Composite) object;
....@@ -15186,12 +15940,12 @@
1518615940 for (int j = 0; j < group.children.size(); j++)
1518715941 {
1518815942 elem = (Object3D) group.children.elementAt(j);
15189
- object.editWindow.Select(elem.GetTreePath(), first, true);
15943
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1519015944 first = false;
1519115945 }
1519215946 } else
1519315947 {
15194
- object.editWindow.Select(elem.GetTreePath(), first, true);
15948
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1519515949 }
1519615950
1519715951 first = false;
....@@ -15202,21 +15956,21 @@
1520215956 {
1520315957 //Composite group = (Composite) object;
1520415958 Object3D group = object;
15205
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15959
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1520615960 }
1520715961
1520815962 void ResetTransform(int mask)
1520915963 {
1521015964 //Composite group = (Composite) object;
1521115965 Object3D group = object;
15212
- group.editWindow.ResetTransform(mask);
15966
+ group.GetWindow().ResetTransform(mask);
1521315967 }
1521415968
1521515969 void FlipTransform()
1521615970 {
1521715971 //Composite group = (Composite) object;
1521815972 Object3D group = object;
15219
- group.editWindow.FlipTransform();
15973
+ group.GetWindow().FlipTransform();
1522015974 // group.editWindow.ReduceMesh(true);
1522115975 }
1522215976
....@@ -15224,7 +15978,7 @@
1522415978 {
1522515979 //Composite group = (Composite) object;
1522615980 Object3D group = object;
15227
- group.editWindow.PrintMemory();
15981
+ group.GetWindow().PrintMemory();
1522815982 // group.editWindow.ReduceMesh(true);
1522915983 }
1523015984
....@@ -15232,7 +15986,7 @@
1523215986 {
1523315987 //Composite group = (Composite) object;
1523415988 Object3D group = object;
15235
- group.editWindow.ResetCentroid();
15989
+ group.GetWindow().ResetCentroid();
1523615990 }
1523715991
1523815992 void IncDepth()
....@@ -15314,11 +16068,11 @@
1531416068
1531516069 int width = getBounds().width;
1531616070 int height = getBounds().height;
15317
- ClickInfo info = new ClickInfo();
15318
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1531916071 //Image img = CreateImage(width, height);
1532016072 //System.out.println("width = " + width + "; height = " + height + "\n");
16073
+
1532116074 Graphics gr = g; // img.getGraphics();
16075
+
1532216076 if (!hasMarquee)
1532316077 {
1532416078 if (Xmin < Xmax) // !locked)
....@@ -15390,44 +16144,92 @@
1539016144 }
1539116145 if (object != null && !hasMarquee)
1539216146 {
16147
+ if (object.clickInfo == null)
16148
+ object.clickInfo = new ClickInfo();
16149
+ ClickInfo info = object.clickInfo;
16150
+ //ClickInfo info = new ClickInfo();
16151
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16152
+
1539316153 if (isRenderer)
1539416154 {
15395
- info.flags++;
16155
+ object.clickInfo.flags++;
1539616156 double frameAspect = (double) width / (double) height;
1539716157 if (frameAspect > renderCamera.aspect)
1539816158 {
1539916159 int desired = (int) ((double) height * renderCamera.aspect);
15400
- info.bounds.width -= width - desired;
15401
- info.bounds.x += (width - desired) / 2;
16160
+ object.clickInfo.bounds.width -= width - desired;
16161
+ object.clickInfo.bounds.x += (width - desired) / 2;
1540216162 } else
1540316163 {
1540416164 int desired = (int) ((double) width / renderCamera.aspect);
15405
- info.bounds.height -= height - desired;
15406
- info.bounds.y += (height - desired) / 2;
16165
+ object.clickInfo.bounds.height -= height - desired;
16166
+ object.clickInfo.bounds.y += (height - desired) / 2;
1540716167 }
1540816168 }
15409
- info.g = gr;
15410
- info.camera = renderCamera;
16169
+
16170
+ object.clickInfo.g = gr;
16171
+ object.clickInfo.camera = renderCamera;
1541116172 /*
1541216173 // Memory intensive (brep.verticescopy)
1541316174 if (!(object instanceof Composite))
1541416175 object.draw(info, 0, false); // SLOW :
1541516176 */
15416
- if (!isRenderer)
16177
+ if (!isRenderer) // && drag)
1541716178 {
15418
- object.drawEditHandles(info, 0);
16179
+ Grafreed.Assert(object != null);
16180
+ Grafreed.Assert(object.selection != null);
16181
+ if (object.selection.Size() > 0)
16182
+ {
16183
+ int hitSomething = object.selection.get(0).hitSomething;
16184
+
16185
+ object.clickInfo.DX = 0;
16186
+ object.clickInfo.DY = 0;
16187
+ object.clickInfo.W = 1;
16188
+ if (hitSomething == Object3D.hitCenter)
16189
+ {
16190
+ info.DX = X;
16191
+ if (X != 0)
16192
+ info.DX -= info.bounds.width/2;
16193
+
16194
+ info.DY = Y;
16195
+ if (Y != 0)
16196
+ info.DY -= info.bounds.height/2;
16197
+ }
16198
+
16199
+ object.drawEditHandles(//info,
16200
+ 0);
16201
+
16202
+ if (drag && (X != 0 || Y != 0))
16203
+ {
16204
+ switch (hitSomething)
16205
+ {
16206
+ case Object3D.hitCenter: gr.setColor(Color.white);
16207
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16208
+ break;
16209
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16210
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16211
+ break;
16212
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16213
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16214
+ break;
16215
+ }
16216
+
16217
+ }
16218
+ }
1541916219 }
1542016220 }
16221
+
1542116222 if (isRenderer)
1542216223 {
1542316224 //gr.setColor(Color.black);
1542416225 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1542516226 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1542616227 }
16228
+
1542716229 if (hasMarquee)
1542816230 {
1542916231 gr.setXORMode(Color.white);
15430
- gr.setColor(Color.red);
16232
+ gr.setColor(Color.white);
1543116233 if (!firstime)
1543216234 {
1543316235 gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH);
....@@ -15536,6 +16338,7 @@
1553616338 public boolean mouseDown(Event evt, int x, int y)
1553716339 {
1553816340 System.out.println("mouseDown: " + evt);
16341
+ System.exit(0);
1553916342 /*
1554016343 locked = true;
1554116344 drag = false;
....@@ -15579,7 +16382,7 @@
1557916382 {
1558016383 keyPressed(0, modifiers);
1558116384 }
15582
- clickStart(x, y, modifiers);
16385
+ // clickStart(x, y, modifiers);
1558316386 return true;
1558416387 }
1558516388
....@@ -15697,7 +16500,7 @@
1569716500 {
1569816501 keyReleased(0, 0);
1569916502 }
15700
- drag(x, y, modifiers);
16503
+ drag(x, y, 0, modifiers);
1570116504 return true;
1570216505 }
1570316506
....@@ -15829,7 +16632,7 @@
1582916632 Object3D object;
1583016633 static Object3D trackedobject;
1583116634 Camera renderCamera; // Light or Eye (or Occlusion)
15832
- /*static*/ Camera manipCamera; // Light or Eye
16635
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1583316636 /*static*/ Camera eyeCamera;
1583416637 /*static*/ Camera lightCamera;
1583516638 int cameracount;
....@@ -15893,6 +16696,8 @@
1589316696 private /*static*/ boolean firstime;
1589416697 private /*static*/ cVector newView = new cVector();
1589516698 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16699
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16700
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1589616701 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1589716702 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1589816703 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -15905,29 +16710,67 @@
1590516710 {
1590616711 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1590716712
16713
+ int usedsuf = 0;
16714
+
1590816715 for (int i = 0; i < suffixes.length; i++)
1590916716 {
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)
16717
+ String[] suffixe = suffixes;
16718
+ String[] fallback = suffixes2;
16719
+ String[] fallfallback = suffixes3;
16720
+
16721
+ for (int c=usedsuf; --c>=0;)
1591516722 {
15916
- throw new IOException("Unable to load texture " + resourceName);
16723
+// String[] temp = suffixe;
16724
+// suffixe = fallback;
16725
+// fallback = fallfallback;
16726
+// fallfallback = temp;
1591716727 }
16728
+
16729
+ String resourceName = basename + suffixe[i] + "." + suffix;
16730
+ TextureData data;
16731
+
16732
+ try
16733
+ {
16734
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16735
+ mipmapped,
16736
+ FileUtil.getFileSuffix(resourceName));
16737
+ }
16738
+ catch (Exception e)
16739
+ {
16740
+ try
16741
+ {
16742
+ resourceName = basename + fallback[i] + "." + suffix;
16743
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16744
+ mipmapped,
16745
+ FileUtil.getFileSuffix(resourceName));
16746
+ }
16747
+ catch (Exception e2)
16748
+ {
16749
+ resourceName = basename + fallfallback[i] + "." + suffix;
16750
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16751
+ mipmapped,
16752
+ FileUtil.getFileSuffix(resourceName));
16753
+ }
16754
+ }
16755
+
1591816756 //System.out.println("Target = " + targets[i]);
1591916757 cubemap.updateImage(data, targets[i]);
1592016758 }
1592116759
1592216760 return cubemap;
1592316761 }
16762
+
1592416763 int bigsphere = -1;
1592516764
1592616765 float BGcolor = 0.5f;
1592716766
15928
- private void DrawSkyBox(GL gl)
16767
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16768
+
16769
+ private void DrawSkyBox(GL gl, float ratio)
1592916770 {
15930
- if (envyoff || cubemap == null)
16771
+ if (//envyoff ||
16772
+ WIREFRAME ||
16773
+ cubemap == null)
1593116774 {
1593216775 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1593316776 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -15942,7 +16785,17 @@
1594216785 // Compensates for ExaminerViewer's modification of modelview matrix
1594316786 gl.glMatrixMode(GL.GL_MODELVIEW);
1594416787 gl.glLoadIdentity();
16788
+ gl.glScalef(1,ratio,1);
1594516789
16790
+// colorV[0] = 2;
16791
+// colorV[1] = 2;
16792
+// colorV[2] = 2;
16793
+// colorV[3] = 1;
16794
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16795
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16796
+//
16797
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16798
+
1594616799 //gl.glActiveTexture(GL.GL_TEXTURE1);
1594716800 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1594816801
....@@ -15974,6 +16827,7 @@
1597416827 {
1597516828 gl.glScalef(1.0f, -1.0f, 1.0f);
1597616829 }
16830
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1597716831 gl.glMultMatrixd(viewrot_1, 0);
1597816832 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1597916833 //viewer.updateInverseRotation(gl);
....@@ -16014,7 +16868,8 @@
1601416868 gl.glDisable(GL.GL_TEXTURE_GEN_R);
1601516869
1601616870 cubemap.disable();
16017
- ////cubemap.unbind();
16871
+ //cubemap.dispose();
16872
+
1601816873 if (CULLFACE)
1601916874 {
1602016875 gl.glEnable(gl.GL_CULL_FACE);
....@@ -16114,16 +16969,16 @@
1611416969 cStatic.objectstack[materialdepth++] = checker;
1611516970 //System.out.println("material " + material);
1611616971 //Applet3D.tracein(this, selected);
16117
- vector2buffer = checker.projectedVertices;
16972
+ //vector2buffer = checker.projectedVertices;
1611816973
1611916974 //checker.GetMaterial().Draw(this, false); // true);
16120
- DrawMaterial(checker.GetMaterial(), false); // true);
16975
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1612116976
1612216977 materialdepth -= 1;
1612316978 if (materialdepth > 0)
1612416979 {
16125
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16126
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
16980
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16981
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1612716982 }
1612816983 //checker.GetMaterial().opacity = 1f;
1612916984 ////checker.GetMaterial().ambient = 1f;
....@@ -16209,6 +17064,14 @@
1620917064 }
1621017065 }
1621117066
17067
+ private Object3D GetFolder()
17068
+ {
17069
+ Object3D folder = object.GetWindow().copy;
17070
+ if (object.GetWindow().copy.selection.Size() > 0)
17071
+ folder = object.GetWindow().copy.selection.elementAt(0);
17072
+ return folder;
17073
+ }
17074
+
1621217075 class SelectBuffer implements GLEventListener
1621317076 {
1621417077
....@@ -16224,7 +17087,7 @@
1622417087 //new Exception().printStackTrace();
1622517088 System.out.println("select buffer init");
1622617089 // Use debug pipeline
16227
- drawable.setGL(new DebugGL(drawable.getGL()));
17090
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1622817091
1622917092 GL gl = drawable.getGL();
1623017093
....@@ -16267,6 +17130,7 @@
1626717130 {
1626817131 if (!selection)
1626917132 {
17133
+ new Exception().printStackTrace();
1627017134 System.exit(0);
1627117135 return;
1627217136 }
....@@ -16287,6 +17151,17 @@
1628717151
1628817152 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1628917153
17154
+ if (PAINTMODE)
17155
+ {
17156
+ if (object.GetWindow().copy.selection.Size() > 0)
17157
+ {
17158
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17159
+
17160
+ // Make what you paint not selectable.
17161
+ paintobj.ResetSelectable();
17162
+ }
17163
+ }
17164
+
1629017165 //int tmp = selection_view;
1629117166 //selection_view = -1;
1629217167 int temp = DrawMode();
....@@ -16298,6 +17173,17 @@
1629817173 // temp = DEFAULT; // patch for selection debug
1629917174 Globals.drawMode = temp; // WARNING
1630017175
17176
+ if (PAINTMODE)
17177
+ {
17178
+ if (object.GetWindow().copy.selection.Size() > 0)
17179
+ {
17180
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17181
+
17182
+ // Revert.
17183
+ paintobj.RestoreSelectable();
17184
+ }
17185
+ }
17186
+
1630117187 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1630217188
1630317189 // trying different ways of getting the depth info over
....@@ -16345,6 +17231,8 @@
1634517231 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1634617232 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1634717233 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
17234
+
17235
+ CreateSelectedPoint();
1634817236
1634917237 // Will fit the mesh !!!
1635017238 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16394,34 +17282,36 @@
1639417282 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]));
1639517283 }
1639617284
16397
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
17285
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1639817286 }
1639917287 }
1640017288
1640117289 if (!movingcamera && !PAINTMODE)
16402
- object.editWindow.ScreenFitPoint(); // fev 2014
17290
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1640317291
16404
- if (PAINTMODE && GrafreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17292
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1640517293 {
16406
- Object3D paintobj = GrafreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17294
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1640717295
16408
- Object3D group = new Object3D("inst" + paintcount++);
17296
+ if (object.GetWindow().copy.selection.Size() > 0)
17297
+ {
17298
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1640917299
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();
17300
+ Object3D inst = new Object3D("inst" + paintcount++);
17301
+
17302
+ inst.CreateMaterial(); // use a void leaf to select instances
17303
+
17304
+ inst.add(paintobj); // link
17305
+
17306
+ object.GetWindow().SnapObject(inst);
17307
+
17308
+ Object3D folder = paintFolder; // GetFolder();
17309
+
17310
+ folder.add(inst);
17311
+
17312
+ object.GetWindow().ResetModel();
17313
+ object.GetWindow().refreshContents();
17314
+ }
1642517315 }
1642617316 else
1642717317 paintcount = 0;
....@@ -16460,6 +17350,11 @@
1646017350 //System.out.println("objects[color] = " + objects[color]);
1646117351 //objects[color].Select();
1646217352 indexcount = 0;
17353
+ ObjEditor window = object.GetWindow();
17354
+ if (window != null && deselect)
17355
+ {
17356
+ window.Select(null, deselect, true);
17357
+ }
1646317358 object.Select(color, deselect);
1646417359 }
1646517360
....@@ -16510,6 +17405,7 @@
1651017405
1651117406 public void init(GLAutoDrawable drawable)
1651217407 {
17408
+ if (Globals.DEBUG)
1651317409 System.out.println("shadow buffer init");
1651417410
1651517411 GL gl = drawable.getGL();
....@@ -16559,7 +17455,7 @@
1655917455 gl.glDisable(gl.GL_CULL_FACE);
1656017456 }
1656117457
16562
- if (!RENDERSHADOW)
17458
+ if (!Globals.RENDERSHADOW)
1656317459 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1656417460
1656517461 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -16569,7 +17465,7 @@
1656917465 //gl.glColorMask(false, false, false, false);
1657017466
1657117467 //render_scene_from_light_view(gl, drawable, 0, 0);
16572
- if (RENDERSHADOW && Globals.lighttouched && !movingcamera) // && !parent.IsFreezed())
17468
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1657317469 {
1657417470 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1657517471
....@@ -16738,10 +17634,14 @@
1673817634 gl.glFlush();
1673917635
1674017636 /**/
16741
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17637
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1674217638
16743
- float[] pixels = occlusionsizebuffer.array();
17639
+ float[] depths = occlusiondepthbuffer.array();
1674417640
17641
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17642
+
17643
+ int[] pixels = selectsizebuffer.array();
17644
+
1674517645 double r = 0, g = 0, b = 0;
1674617646
1674717647 double count = 0;
....@@ -16752,7 +17652,7 @@
1675217652
1675317653 double FACTOR = 1;
1675417654
16755
- for (int i = 0; i < pixels.length; i++)
17655
+ for (int i = 0; i < depths.length; i++)
1675617656 {
1675717657 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1675817658 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -16835,7 +17735,7 @@
1683517735
1683617736 double scale = ray.z; // 1; // cos
1683717737
16838
- float depth = pixels[newindex];
17738
+ float depth = depths[newindex];
1683917739
1684017740 /*
1684117741 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -16985,23 +17885,15 @@
1698517885 int AAbuffersize = 0;
1698617886
1698717887 //double[] selectedpoint = new double[3];
16988
- static Superellipsoid selectedpoint = new Superellipsoid();
17888
+ static Superellipsoid selectedpoint;
1698917889 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();
17890
+ static Sphere debugpointG;
17891
+ static Sphere debugpointP;
17892
+ static Sphere debugpointC;
17893
+ static Sphere debugpointR;
1699417894
1699517895 static Sphere debugpoints[] = new Sphere[8];
1699617896
16997
- static
16998
- {
16999
- for (int i=0; i<8; i++)
17000
- {
17001
- debugpoints[i] = new Sphere();
17002
- }
17003
- }
17004
-
1700517897 static void InitPoints(float radius)
1700617898 {
1700717899 for (int i=0; i<8; i++)
....@@ -17040,11 +17932,14 @@
1704017932 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1704117933 static IntBuffer bigAAbuffer;
1704217934 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
17043
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17935
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1704417936 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1704517937 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1704617938 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17047
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17939
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17940
+
17941
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17942
+
1704817943 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1704917944 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1705017945 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();