Normand Briere
2019-08-23 60cec91731a350fe67e9b5ffe7a00d70e9026314
CameraPane.java
....@@ -18,7 +18,10 @@
1818 import javax.imageio.ImageIO;
1919 import javax.imageio.ImageWriteParam;
2020 import javax.imageio.ImageWriter;
21
+import javax.imageio.ImageReadParam;
22
+import javax.imageio.ImageReader;
2123 import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
24
+import javax.imageio.stream.ImageInputStream;
2225 import javax.imageio.stream.ImageOutputStream;
2326 import javax.imageio.ImageWriteParam;
2427
....@@ -30,6 +33,7 @@
3033 import java.nio.*;
3134
3235 import gleem.linalg.Mat4f;
36
+import javax.imageio.ImageTypeSpecifier;
3337
3438 class CameraPane extends GLCanvas implements iCameraPane, Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener
3539 {
....@@ -37,7 +41,6 @@
3741 static boolean[] selectedstack = new boolean[65536];
3842 static int materialdepth = 0;
3943
40
- static boolean DEBUG = false;
4144 static boolean FRUSTUM = false; // still bogus true; // frustum culling
4245
4346 // camera change fix
....@@ -45,6 +48,39 @@
4548 static boolean ABORTED = false;
4649
4750 static int STEP = 1;
51
+
52
+ private static BufferedImage CreateBim(byte[] bytes, int width, int height)
53
+ {
54
+ int[] pixels = new int[bytes.length/3];
55
+ for (int i=pixels.length; --i>=0;)
56
+ {
57
+ int i3 = i*3;
58
+ pixels[i] = 0xFF;
59
+ pixels[i] <<= 8;
60
+ pixels[i] |= bytes[i3+2] & 0xFF;
61
+ pixels[i] <<= 8;
62
+ pixels[i] |= bytes[i3+1] & 0xFF;
63
+ pixels[i] <<= 8;
64
+ pixels[i] |= bytes[i3] & 0xFF;
65
+ }
66
+ /*
67
+ int r=0,g=0,b=0,a=0;
68
+ for (int i=0; i<width; i++)
69
+ for (int j=0; j<height; j++)
70
+ {
71
+ int index = j*width+i;
72
+ int p = pixels[index];
73
+ a = ((p>>24) & 0xFF);
74
+ r = ((p>>16) & 0xFF);
75
+ g = ((p>>8) & 0xFF);
76
+ b = (p & 0xFF);
77
+ pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
78
+ }
79
+ /**/
80
+ BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
81
+ rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
82
+ return rendImage;
83
+ }
4884
4985 /*static*/ private boolean CULLFACE = false; // true;
5086 /*static*/ boolean NEAREST = false; // true;
....@@ -61,7 +97,7 @@
6197 //boolean REDUCETEXTURE = true;
6298 boolean CACHETEXTURE = true;
6399 boolean CLEANCACHE = false; // true;
64
- boolean MIPMAP = false; // true;
100
+ boolean MIPMAP = false; // true; // never works...
65101 boolean COMPRESSTEXTURE = false;
66102 boolean KOMPACTTEXTURE = false; // true;
67103 boolean RESIZETEXTURE = false;
....@@ -74,7 +110,11 @@
74110 //private Mat4f spotlightTransform = new Mat4f();
75111 //private Mat4f spotlightInverseTransform = new Mat4f();
76112 static GLContext glcontext = null;
77
- /*static*/ com.sun.opengl.util.texture.Texture cubemap;
113
+ /*static*/ com.sun.opengl.util.texture.Texture cubemap; // Either custom or rgb
114
+ /*static*/ com.sun.opengl.util.texture.Texture cubemapcustom;
115
+ /*static*/ com.sun.opengl.util.texture.Texture cubemaprgb;
116
+ boolean transformMode;
117
+
78118 boolean reverseUP = false;
79119 static boolean frozen = false;
80120 boolean enablebackspace = false; // patch for back buffer refresh
....@@ -128,7 +168,7 @@
128168
129169
130170 // OPTIONS
131
- boolean Skinshader = true;
171
+ boolean Skinshader = false; // true;
132172 boolean cameraLight = false;
133173 boolean UVdebug = false;
134174 boolean Udebug = false;
....@@ -137,7 +177,7 @@
137177 static boolean doublesided = false; // true; // reversed normals are awful for conformance
138178 boolean anisotropy = true;
139179 boolean softshadow = true; // slower but better false;
140
- boolean opacityhalo = false;
180
+ boolean opacityhalo = false; // reverse the halo effect (e.g. glass)
141181
142182 boolean macromode = false;
143183
....@@ -151,6 +191,19 @@
151191 }
152192
153193 private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
194
+
195
+ public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException
196
+ {
197
+ try
198
+ {
199
+ return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
200
+ } catch (IOException e)
201
+ {
202
+ System.out.println("NAME = " + name);
203
+ e.printStackTrace(); // throw new RuntimeException(e);
204
+ return null;
205
+ }
206
+ }
154207
155208 void SetAsGLRenderer(boolean b)
156209 {
....@@ -170,7 +223,8 @@
170223
171224 SetCamera(cam);
172225
173
- SetLight(new Camera(new cVector(10, 10, -20)));
226
+ // Warning: not used.
227
+ SetLight(new Camera(new cVector(15, 10, -20)));
174228
175229 object = o;
176230
....@@ -327,7 +381,7 @@
327381 cStatic.objectstack[materialdepth++] = obj;
328382 //System.out.println("material " + material);
329383 //Applet3D.tracein(this, selected);
330
- display.vector2buffer = obj.projectedVertices;
384
+ //display.vector2buffer = obj.projectedVertices;
331385 if (obj instanceof Camera)
332386 {
333387 display.options1[0] = material.shift;
....@@ -336,14 +390,28 @@
336390 display.options1[2] = material.shadowbias;
337391 display.options1[3] = material.aniso;
338392 display.options1[4] = material.anisoV;
393
+// System.out.println("display.options1[0] " + display.options1[0]);
394
+// System.out.println("display.options1[1] " + display.options1[1]);
395
+// System.out.println("display.options1[2] " + display.options1[2]);
396
+// System.out.println("display.options1[3] " + display.options1[3]);
397
+// System.out.println("display.options1[4] " + display.options1[4]);
339398 display.options2[0] = material.opacity;
340399 display.options2[1] = material.diffuse;
341400 display.options2[2] = material.factor;
401
+// System.out.println("display.options2[0] " + display.options2[0]);
402
+// System.out.println("display.options2[1] " + display.options2[1]);
403
+// System.out.println("display.options2[2] " + display.options2[2]);
342404
343405 cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
406
+// System.out.println("display.options3[0] " + display.options3[0]);
407
+// System.out.println("display.options3[1] " + display.options3[1]);
408
+// System.out.println("display.options3[2] " + display.options3[2]);
344409 display.options4[0] = material.cameralight/0.2f;
345410 display.options4[1] = material.subsurface;
346411 display.options4[2] = material.sheen;
412
+// System.out.println("display.options4[0] " + display.options4[0]);
413
+// System.out.println("display.options4[1] " + display.options4[1]);
414
+// System.out.println("display.options4[2] " + display.options4[2]);
347415
348416 // if (display.CURRENTANTIALIAS > 0)
349417 // display.options3[3] /= 4;
....@@ -359,7 +427,7 @@
359427 /**/
360428 } else
361429 {
362
- DrawMaterial(material, selected);
430
+ DrawMaterial(material, selected, obj.projectedVertices);
363431 }
364432 } else
365433 {
....@@ -383,8 +451,8 @@
383451 cStatic.objectstack[materialdepth++] = obj;
384452 //System.out.println("material " + material);
385453 //Applet3D.tracein("selected ", selected);
386
- display.vector2buffer = obj.projectedVertices;
387
- display.DrawMaterial(material, selected);
454
+ //display.vector2buffer = obj.projectedVertices;
455
+ display.DrawMaterial(material, selected, obj.projectedVertices);
388456 }
389457 }
390458
....@@ -401,8 +469,8 @@
401469 materialdepth -= 1;
402470 if (materialdepth > 0)
403471 {
404
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
405
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
472
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
473
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
406474 }
407475 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
408476 } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
....@@ -422,8 +490,8 @@
422490 materialdepth -= 1;
423491 if (materialdepth > 0)
424492 {
425
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
426
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
493
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
494
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
427495 }
428496 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
429497 //else
....@@ -474,7 +542,8 @@
474542 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
475543 LA.vecCross(obj.v0, obj.v1, obj.v2);
476544 LA.vecNormalize(obj.v2);
477
- gl.glNormal3f((float) obj.v2.x, (float) obj.v2.y, (float) obj.v2.z);
545
+
546
+ SetGLNormal(gl, (float) obj.v2.x, (float) obj.v2.y, (float) obj.v2.z);
478547 }
479548
480549 // P
....@@ -496,7 +565,7 @@
496565 y += ny * obj.NORMALPUSH;
497566 z += nz * obj.NORMALPUSH;
498567
499
- gl.glNormal3f(nx, ny, nz);
568
+ SetGLNormal(gl, nx, ny, nz);
500569 }
501570 gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
502571 SetColor(obj, pv);
....@@ -528,7 +597,7 @@
528597 y += ny * obj.NORMALPUSH;
529598 z += nz * obj.NORMALPUSH;
530599
531
- gl.glNormal3f(nx, ny, nz);
600
+ SetGLNormal(gl, nx, ny, nz);
532601 }
533602 //System.out.println("vertexq = " + qv.s + ", " + qv.t);
534603 // boolean locked = false;
....@@ -576,7 +645,7 @@
576645 y += ny * obj.NORMALPUSH;
577646 z += nz * obj.NORMALPUSH;
578647
579
- gl.glNormal3f(nx, ny, nz);
648
+ SetGLNormal(gl, nx, ny, nz);
580649 }
581650
582651 // if ((dot&4) == 0)
....@@ -812,7 +881,7 @@
812881 //// tris.postdraw(this);
813882 }
814883
815
- static Camera localcamera = new Camera();
884
+ static Camera localAOcamera = new Camera();
816885 static cVector from = new cVector();
817886 static cVector to = new cVector();
818887
....@@ -821,7 +890,7 @@
821890 CameraPane cp = this;
822891
823892 Camera keep = cp.RenderCamera();
824
- cp.renderCamera = localcamera;
893
+ cp.renderCamera = localAOcamera;
825894
826895 if (br.trimmed)
827896 {
....@@ -839,7 +908,7 @@
839908 br.positions[i3 + 2] + br.normals[i3 + 2]);
840909 LA.xformPos(from, transform, from);
841910 LA.xformPos(to, transform, to); // RIGID ONLY
842
- localcamera.setAim(from, to);
911
+ localAOcamera.setAim(from, to);
843912
844913 CameraPane.occlusionbuffer.display();
845914
....@@ -873,7 +942,7 @@
873942 to.set(v.x+v.norm.x, v.y+v.norm.y, v.z+v.norm.z);
874943 LA.xformPos(from, transform, from);
875944 LA.xformPos(to, transform, to); // RIGID ONLY
876
- localcamera.setAim(from, to);
945
+ localAOcamera.setAim(from, to);
877946
878947 CameraPane.occlusionbuffer.display();
879948
....@@ -1182,10 +1251,10 @@
11821251 {
11831252 if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
11841253 {
1185
- gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1254
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
11861255 } else
11871256 {
1188
- gl.glNormal3f(0, 0, 1);
1257
+ SetGLNormal(gl, 0, 0, 1);
11891258 }
11901259
11911260 if (c != null)
....@@ -1209,10 +1278,10 @@
12091278 {
12101279 if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
12111280 {
1212
- gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1281
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
12131282 } else
12141283 {
1215
- gl.glNormal3f(0, 0, 1);
1284
+ SetGLNormal(gl, 0, 0, 1);
12161285 }
12171286 if (c != null)
12181287 {
....@@ -1237,10 +1306,10 @@
12371306 {
12381307 if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
12391308 {
1240
- gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1309
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
12411310 } else
12421311 {
1243
- gl.glNormal3f(0, 0, 1);
1312
+ SetGLNormal(gl, 0, 0, 1);
12441313 }
12451314 if (c != null)
12461315 {
....@@ -1422,7 +1491,7 @@
14221491 {
14231492 if (!selectmode)
14241493 {
1425
- gl.glNormal3f((float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
1494
+ SetGLNormal(gl, (float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
14261495 gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
14271496
14281497 if (flipV)
....@@ -1434,6 +1503,8 @@
14341503 gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
14351504 }
14361505
1506
+ float[] colorV = new float[4];
1507
+
14371508 void SetColor(Object3D obj, Vertex p0)
14381509 {
14391510 CameraPane display = this;
....@@ -1501,8 +1572,6 @@
15011572 {
15021573 return;
15031574 }
1504
-
1505
- float[] colorV = new float[3];
15061575
15071576 if (false) // marked)
15081577 {
....@@ -1611,7 +1680,7 @@
16111680 // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
16121681 }
16131682
1614
- void DrawMaterial(cMaterial material, boolean selected)
1683
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
16151684 {
16161685 CameraPane display = this;
16171686 //new Exception().printStackTrace();
....@@ -1646,7 +1715,7 @@
16461715 colorV[0] = display.modelParams0[0] * material.diffuse;
16471716 colorV[1] = display.modelParams0[1] * material.diffuse;
16481717 colorV[2] = display.modelParams0[2] * material.diffuse;
1649
- colorV[3] = material.opacity;
1718
+ colorV[3] = 1; // material.opacity;
16501719
16511720 gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
16521721 //System.out.println("Opacity = " + opacity);
....@@ -1751,12 +1820,12 @@
17511820
17521821 display.modelParams7[0] = 0;
17531822 display.modelParams7[1] = 1000;
1754
- display.modelParams7[2] = 0;
1823
+ display.modelParams7[2] = material.parallax;
17551824 display.modelParams7[3] = 0;
17561825
1757
- display.modelParams6[0] = 100; // criss de bug de bump
1826
+ //display.modelParams6[0] = 100; // criss de bug de bump
17581827
1759
- Object3D.cVector2[] extparams = display.vector2buffer;
1828
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
17601829 if (extparams != null && extparams.length > 0 && extparams[0] != null)
17611830 {
17621831 display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
....@@ -1984,9 +2053,9 @@
19842053 switch(viewcode)
19852054 {
19862055 case 0: return "main";
1987
- case 1: return "one";
1988
- case 2: return "two";
1989
- case 3: return "three";
2056
+ case 1: return "Red";
2057
+ case 2: return "Green";
2058
+ case 3: return "Blue";
19902059 case 4: return "light";
19912060 }
19922061
....@@ -2052,7 +2121,7 @@
20522121 //System.err.println("Oeil on");
20532122 OEIL = true;
20542123 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2055
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2124
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
20562125 //pingthread.StepToTarget(true);
20572126 }
20582127
....@@ -2267,7 +2336,7 @@
22672336
22682337 void ToggleDebug()
22692338 {
2270
- DEBUG ^= true;
2339
+ Globals.DEBUG ^= true;
22712340 }
22722341
22732342 void ToggleLookAt()
....@@ -2285,10 +2354,17 @@
22852354 HANDLES ^= true;
22862355 }
22872356
2357
+ Object3D paintFolder;
2358
+
22882359 void TogglePaint()
22892360 {
22902361 PAINTMODE ^= true;
22912362 paintcount = 0;
2363
+
2364
+ if (PAINTMODE)
2365
+ {
2366
+ paintFolder = GetFolder();
2367
+ }
22922368 }
22932369
22942370 void SwapCamera(int a, int b)
....@@ -2385,6 +2461,33 @@
23852461 return currentGL;
23862462 }
23872463
2464
+ static private BufferedImage CreateBim(TextureData texturedata)
2465
+ {
2466
+ Grafreed.Assert(texturedata != null);
2467
+
2468
+ int width = texturedata.getWidth();
2469
+ int height = texturedata.getHeight();
2470
+
2471
+ Buffer buffer = texturedata.getBuffer();
2472
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2473
+
2474
+ byte[] bytes = bytebuf.array();
2475
+
2476
+ return CreateBim(bytes, width, height);
2477
+ }
2478
+
2479
+ private void SetGLNormal(javax.media.opengl.GL gl, float nx, float ny, float nz)
2480
+ {
2481
+ gl.glNormal3f(nx, ny, nz);
2482
+
2483
+ if (ny > 0.9 || ny < -0.9)
2484
+ // Ground or ceiling
2485
+ gl.glVertexAttrib3f(4, 1, 0, 0);
2486
+ else
2487
+ // Walls
2488
+ gl.glVertexAttrib3f(4, 0, 1, 0);
2489
+ }
2490
+
23882491 /**/
23892492 class CacheTexture
23902493 {
....@@ -2393,28 +2496,31 @@
23932496
23942497 int resolution;
23952498
2396
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2499
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
23972500 {
2398
- texture = tex;
2501
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2502
+ texturedata = texdata;
23992503 resolution = res;
24002504 }
24012505 }
24022506 /**/
24032507
24042508 // TEXTURE static Texture texture;
2405
- static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures
2406
- = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>();
2407
- static public java.util.Hashtable<String, String> usedtextures = new java.util.Hashtable<String, String>();
2509
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2510
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2511
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2512
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2513
+
24082514 int pigmentdepth = 0;
24092515 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
24102516 int bumpdepth = 0;
24112517 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
24122518 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
24132519 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2414
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2520
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
24152521 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
24162522
2417
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2523
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
24182524 {
24192525 TextureData texturedata = null;
24202526
....@@ -2424,7 +2530,7 @@
24242530 com.sun.opengl.util.texture.TextureIO.newTextureData(
24252531 getClass().getClassLoader().getResourceAsStream(name),
24262532 true,
2427
- com.sun.opengl.util.texture.TextureIO.PNG);
2533
+ GetFormat(name)); // com.sun.opengl.util.texture.TextureIO.PNG);
24282534 } catch (java.io.IOException e)
24292535 {
24302536 throw new javax.media.opengl.GLException(e);
....@@ -2433,13 +2539,34 @@
24332539 if (bump)
24342540 texturedata = ConvertBump(texturedata, false);
24352541
2436
- com.sun.opengl.util.texture.Texture texture =
2437
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2542
+// com.sun.opengl.util.texture.Texture texture =
2543
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
24382544
2439
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2440
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
2545
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2546
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
24412547
2442
- return texture;
2548
+ return texturedata;
2549
+ }
2550
+
2551
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2552
+ {
2553
+ TextureData texturedata = null;
2554
+
2555
+ try
2556
+ {
2557
+ texturedata =
2558
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2559
+ bim,
2560
+ true);
2561
+ } catch (Exception e)
2562
+ {
2563
+ throw new javax.media.opengl.GLException(e);
2564
+ }
2565
+
2566
+ if (bump)
2567
+ texturedata = ConvertBump(texturedata, false);
2568
+
2569
+ return texturedata;
24432570 }
24442571
24452572 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3512,6 +3639,8 @@
35123639
35133640 System.out.println("LOADING TEXTURE : " + name);
35143641
3642
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3643
+
35153644 //
35163645 if (false) // compressbit > 0)
35173646 {
....@@ -7910,7 +8039,7 @@
79108039 String pigment = Object3D.GetPigment(tex);
79118040 String bump = Object3D.GetBump(tex);
79128041
7913
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8042
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79148043 {
79158044 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79168045 // System.out.println("; bump = " + bump);
....@@ -7925,8 +8054,8 @@
79258054 pigment = null;
79268055 }
79278056
7928
- ReleaseTexture(bump, true);
7929
- ReleaseTexture(pigment, false);
8057
+ ReleaseTexture(tex, true);
8058
+ ReleaseTexture(tex, false);
79308059 }
79318060
79328061 public void ReleasePigmentTexture(cTexture tex) // INTERFACE
....@@ -7944,7 +8073,7 @@
79448073
79458074 String pigment = Object3D.GetPigment(tex);
79468075
7947
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8076
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79488077 {
79498078 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79508079 // System.out.println("; bump = " + bump);
....@@ -7955,7 +8084,7 @@
79558084 pigment = null;
79568085 }
79578086
7958
- ReleaseTexture(pigment, false);
8087
+ ReleaseTexture(tex, false);
79598088 }
79608089
79618090 public void ReleaseBumpTexture(cTexture tex) // INTERFACE
....@@ -7973,7 +8102,7 @@
79738102
79748103 String bump = Object3D.GetBump(tex);
79758104
7976
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8105
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79778106 {
79788107 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79798108 // System.out.println("; bump = " + bump);
....@@ -7984,10 +8113,10 @@
79848113 bump = null;
79858114 }
79868115
7987
- ReleaseTexture(bump, true);
8116
+ ReleaseTexture(tex, true);
79888117 }
79898118
7990
- void ReleaseTexture(String tex, boolean bump)
8119
+ void ReleaseTexture(cTexture tex, boolean bump)
79918120 {
79928121 if (// DrawMode() != 0 || /*tex == null ||*/
79938122 ambientOcclusion ) // || !textureon)
....@@ -7998,7 +8127,7 @@
79988127 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
79998128
80008129 if (tex != null)
8001
- texture = textures.get(tex);
8130
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
80028131
80038132 // //assert( texture != null );
80048133 // if (texture == null)
....@@ -8092,47 +8221,50 @@
80928221
80938222 /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
80948223 {
8095
- if (// DrawMode() != 0 || /*tex == null ||*/
8096
- ambientOcclusion ) // || !textureon)
8097
- {
8098
- return; // false;
8099
- }
8100
-
8101
- if (tex == null)
8102
- {
8103
- BindTexture(null,false,resolution);
8104
- BindTexture(null,true,resolution);
8105
- return;
8106
- }
8224
+// if (// DrawMode() != 0 || /*tex == null ||*/
8225
+// ambientOcclusion ) // || !textureon)
8226
+// {
8227
+// return; // false;
8228
+// }
8229
+//
8230
+// if (tex == null)
8231
+// {
8232
+// BindTexture(null,false,resolution);
8233
+// BindTexture(null,true,resolution);
8234
+// return;
8235
+// }
8236
+//
8237
+// String pigment = Object3D.GetPigment(tex);
8238
+// String bump = Object3D.GetBump(tex);
8239
+//
8240
+// usedtextures.add(pigment);
8241
+// usedtextures.add(bump);
8242
+//
8243
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8244
+// {
8245
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8246
+// // System.out.println("; bump = " + bump);
8247
+// }
8248
+//
8249
+// if (bump.equals(""))
8250
+// {
8251
+// bump = null;
8252
+// }
8253
+// if (pigment.equals(""))
8254
+// {
8255
+// pigment = null;
8256
+// }
8257
+//
8258
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8259
+// BindTexture(pigment, false, resolution);
8260
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8261
+// BindTexture(bump, true, resolution);
8262
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8263
+//
8264
+// return; // true;
81078265
8108
- String pigment = Object3D.GetPigment(tex);
8109
- String bump = Object3D.GetBump(tex);
8110
-
8111
- usedtextures.put(pigment, pigment);
8112
- usedtextures.put(bump, bump);
8113
-
8114
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8115
- {
8116
- // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8117
- // System.out.println("; bump = " + bump);
8118
- }
8119
-
8120
- if (bump.equals(""))
8121
- {
8122
- bump = null;
8123
- }
8124
- if (pigment.equals(""))
8125
- {
8126
- pigment = null;
8127
- }
8128
-
8129
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8130
- BindTexture(pigment, false, resolution);
8131
- GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8132
- BindTexture(bump, true, resolution);
8133
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8134
-
8135
- return; // true;
8266
+ BindPigmentTexture(tex, resolution);
8267
+ BindBumpTexture(tex, resolution);
81368268 }
81378269
81388270 /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8151,9 +8283,9 @@
81518283
81528284 String pigment = Object3D.GetPigment(tex);
81538285
8154
- usedtextures.put(pigment, pigment);
8286
+ usedtextures.add(tex);
81558287
8156
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8288
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
81578289 {
81588290 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
81598291 // System.out.println("; bump = " + bump);
....@@ -8165,7 +8297,7 @@
81658297 }
81668298
81678299 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8168
- BindTexture(pigment, false, resolution);
8300
+ BindTexture(tex, false, resolution);
81698301 }
81708302
81718303 /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8184,9 +8316,9 @@
81848316
81858317 String bump = Object3D.GetBump(tex);
81868318
8187
- usedtextures.put(bump, bump);
8319
+ usedtextures.add(tex);
81888320
8189
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8321
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
81908322 {
81918323 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
81928324 // System.out.println("; bump = " + bump);
....@@ -8198,7 +8330,7 @@
81988330 }
81998331
82008332 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8201
- BindTexture(bump, true, resolution);
8333
+ BindTexture(tex, true, resolution);
82028334 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
82038335 }
82048336
....@@ -8222,13 +8354,19 @@
82228354 return fileExists;
82238355 }
82248356
8225
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception
8357
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
82268358 {
8227
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8359
+ CacheTexture texturecache = null;
82288360
82298361 if (tex != null)
82308362 {
8231
- String texname = tex;
8363
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8364
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
8365
+
8366
+ if (texname.equals("") && texdata == null)
8367
+ {
8368
+ return null;
8369
+ }
82328370
82338371 String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
82348372
....@@ -8238,19 +8376,46 @@
82388376 // else
82398377 // if (!texname.startsWith("/"))
82408378 // texname = "/Users/nbriere/Textures/" + texname;
8241
- if (!FileExists(tex))
8379
+ if (!FileExists(texname) && !texname.startsWith("@"))
82428380 {
82438381 texname = fallbackTextureName;
82448382 }
82458383
82468384 if (CACHETEXTURE)
8247
- texture = textures.get(texname); // TEXTURE CACHE
8248
-
8249
- TextureData texturedata = null;
8250
-
8251
- if (texture == null || texture.resolution < resolution)
82528385 {
8253
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8386
+ if (texdata == null)
8387
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8388
+ else
8389
+ texturecache = bimtextures.get(texdata);
8390
+ }
8391
+
8392
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8393
+ {
8394
+ TextureData texturedata = null;
8395
+
8396
+ if (texdata != null && textureon)
8397
+ {
8398
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8399
+
8400
+ try
8401
+ {
8402
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8403
+ }
8404
+ catch (Exception e)
8405
+ {
8406
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8407
+ }
8408
+
8409
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8410
+ bimtextures.put(texdata, texturecache);
8411
+
8412
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8413
+
8414
+ //Object bim2 = CreateBim(texturecache.texturedata);
8415
+ //bim2 = bim;
8416
+ }
8417
+ else
8418
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
82548419 {
82558420 assert(!bump);
82568421 // if (bump)
....@@ -8261,19 +8426,23 @@
82618426 // }
82628427 // else
82638428 // {
8264
- texture = textures.get(tex);
8265
- if (texture == null)
8429
+ // texturecache = textures.get(texname); // suspicious
8430
+ if (texturecache == null)
82668431 {
8267
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8432
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
82688433 }
8434
+ else
8435
+ new Exception().printStackTrace();
82698436 // }
82708437 } else
8271
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8438
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
82728439 {
82738440 assert(bump);
8274
- texture = textures.get(tex);
8275
- if (texture == null)
8276
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8441
+ // texturecache = textures.get(texname); // suspicious
8442
+ if (texturecache == null)
8443
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8444
+ else
8445
+ new Exception().printStackTrace();
82778446 } else
82788447 {
82798448 //if (tex.equals("IMMORTAL"))
....@@ -8281,11 +8450,22 @@
82818450 // texture = GetResourceTexture("default.png");
82828451 //} else
82838452 //{
8284
- if (tex.equals("WHITE_NOISE"))
8453
+ if (texname.endsWith("WHITE_NOISE"))
82858454 {
8286
- texture = textures.get(tex);
8287
- if (texture == null)
8288
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8455
+ // texturecache = textures.get(texname); // suspicious
8456
+ if (texturecache == null)
8457
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8458
+ else
8459
+ new Exception().printStackTrace();
8460
+ } else
8461
+ {
8462
+ if (texname.startsWith("@"))
8463
+ {
8464
+ // texturecache = textures.get(texname); // suspicious
8465
+ if (texturecache == null)
8466
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8467
+ else
8468
+ new Exception().printStackTrace();
82898469 } else
82908470 {
82918471 if (textureon)
....@@ -8344,19 +8524,20 @@
83448524 if (texturedata == null)
83458525 throw new Exception();
83468526
8347
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8527
+ texturecache = new CacheTexture(texturedata,resolution);
83488528 //texture = GetTexture(tex, bump);
83498529 }
8530
+ }
83508531 }
83518532 //}
83528533 }
83538534
8354
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8535
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
83558536 {
83568537 //return false;
83578538
83588539 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8359
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8540
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
83608541 {
83618542 // String ext = "_highres";
83628543 // if (REDUCETEXTURE)
....@@ -8373,52 +8554,17 @@
83738554 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
83748555 if (!cachefile.exists())
83758556 {
8376
- // cache to disk
8377
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
8378
- //buffers[0].
8379
-
8380
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
8381
- int[] pixels = new int[bytebuf.capacity()/3];
8382
-
8383
- // squared size heuristic...
8384
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8557
+ //if (texturedata.getWidth() == texturedata.getHeight())
83858558 {
8386
- for (int i=pixels.length; --i>=0;)
8387
- {
8388
- int i3 = i*3;
8389
- pixels[i] = 0xFF;
8390
- pixels[i] <<= 8;
8391
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
8392
- pixels[i] <<= 8;
8393
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
8394
- pixels[i] <<= 8;
8395
- pixels[i] |= bytebuf.get(i3) & 0xFF;
8396
- }
8397
-
8398
- /*
8399
- int r=0,g=0,b=0,a=0;
8400
- for (int i=0; i<width; i++)
8401
- for (int j=0; j<height; j++)
8402
- {
8403
- int index = j*width+i;
8404
- int p = pixels[index];
8405
- a = ((p>>24) & 0xFF);
8406
- r = ((p>>16) & 0xFF);
8407
- g = ((p>>8) & 0xFF);
8408
- b = (p & 0xFF);
8409
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
8410
- }
8411
- /**/
8412
- int width = (int)Math.sqrt(pixels.length); // squared
8413
- int height = width;
8414
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
8415
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8559
+ BufferedImage rendImage = CreateBim(texturedata);
8560
+
84168561 ImageWriter writer = null;
84178562 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
84188563 if (iter.hasNext()) {
84198564 writer = (ImageWriter)iter.next();
84208565 }
8421
- float compressionQuality = 0.9f;
8566
+
8567
+ float compressionQuality = 0.85f;
84228568 try
84238569 {
84248570 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8435,18 +8581,20 @@
84358581 }
84368582 }
84378583 }
8438
-
8584
+
8585
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8586
+
84398587 //System.out.println("Texture = " + tex);
8440
- if (textures.containsKey(texname))
8588
+ if (textures.containsKey(tex))
84418589 {
8442
- CacheTexture thetex = textures.get(texname);
8590
+ CacheTexture thetex = textures.get(tex);
84438591 thetex.texture.disable();
84448592 thetex.texture.dispose();
8445
- textures.remove(texname);
8593
+ textures.remove(tex);
84468594 }
84478595
8448
- texture.texturedata = texturedata;
8449
- textures.put(texname, texture);
8596
+ //texture.texturedata = texturedata;
8597
+ textures.put(tex, texturecache);
84508598
84518599 // newtex = true;
84528600 }
....@@ -8462,10 +8610,44 @@
84628610 }
84638611 }
84648612
8465
- return texture;
8613
+ return texturecache;
84668614 }
84678615
8468
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution) throws Exception
8616
+ static void EmbedTextures(cTexture tex)
8617
+ {
8618
+ if (tex.pigmentdata == null)
8619
+ {
8620
+ //String texname = Object3D.GetPigment(tex);
8621
+
8622
+ CacheTexture texturecache = texturepigment.get(tex);
8623
+
8624
+ if (texturecache != null)
8625
+ {
8626
+ tex.pw = texturecache.texturedata.getWidth();
8627
+ tex.ph = texturecache.texturedata.getHeight();
8628
+ tex.pigmentdata = //CompressJPEG(CreateBim
8629
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8630
+ ;
8631
+ //, tex.pw, tex.ph), 0.5f);
8632
+ }
8633
+ }
8634
+
8635
+ if (tex.bumpdata == null)
8636
+ {
8637
+ //String texname = Object3D.GetBump(tex);
8638
+
8639
+ CacheTexture texturecache = texturebump.get(tex);
8640
+
8641
+ if (texturecache != null)
8642
+ {
8643
+ tex.bw = texturecache.texturedata.getWidth();
8644
+ tex.bh = texturecache.texturedata.getHeight();
8645
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8646
+ }
8647
+ }
8648
+ }
8649
+
8650
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
84698651 {
84708652 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
84718653
....@@ -8483,21 +8665,21 @@
84838665 return texture!=null?texture.texture:null;
84848666 }
84858667
8486
- public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution) throws Exception
8668
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
84878669 {
84888670 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
84898671
84908672 return texture!=null?texture.texturedata:null;
84918673 }
84928674
8493
- boolean BindTexture(String tex, boolean bump, int resolution) throws Exception
8675
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
84948676 {
84958677 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
84968678 {
84978679 return false;
84988680 }
84998681
8500
- boolean newtex = false;
8682
+ //boolean newtex = false;
85018683
85028684 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
85038685
....@@ -8529,9 +8711,75 @@
85298711 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
85308712 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
85318713
8532
- return newtex;
8714
+ return true; // Warning: not used.
85338715 }
85348716
8717
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8718
+ {
8719
+ try
8720
+ {
8721
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8722
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8723
+ ImageWriter writer = writers.next();
8724
+
8725
+ ImageWriteParam param = writer.getDefaultWriteParam();
8726
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8727
+ param.setCompressionQuality(quality);
8728
+
8729
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8730
+ writer.setOutput(ios);
8731
+ writer.write(null, new IIOImage(image, null, null), param);
8732
+
8733
+ byte[] data = baos.toByteArray();
8734
+ writer.dispose();
8735
+ return data;
8736
+ }
8737
+ catch (Exception e)
8738
+ {
8739
+ e.printStackTrace();
8740
+ return null;
8741
+ }
8742
+ }
8743
+
8744
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8745
+ {
8746
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8747
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8748
+ ImageReader reader = writers.next();
8749
+
8750
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8751
+
8752
+ ImageReadParam param = reader.getDefaultReadParam();
8753
+ param.setDestination(bim);
8754
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8755
+
8756
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8757
+ reader.setInput(ios);
8758
+ BufferedImage bim2 = reader.read(0, param);
8759
+ reader.dispose();
8760
+
8761
+// WritableRaster raster = bim2.getRaster();
8762
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8763
+// byte[] bytes = data.getData();
8764
+//
8765
+// int[] pixels = new int[bytes.length/3];
8766
+// for (int i=pixels.length; --i>=0;)
8767
+// {
8768
+// int i3 = i*3;
8769
+// pixels[i] = 0xFF;
8770
+// pixels[i] <<= 8;
8771
+// pixels[i] |= bytes[i3+2] & 0xFF;
8772
+// pixels[i] <<= 8;
8773
+// pixels[i] |= bytes[i3+1] & 0xFF;
8774
+// pixels[i] <<= 8;
8775
+// pixels[i] |= bytes[i3] & 0xFF;
8776
+// }
8777
+//
8778
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8779
+
8780
+ return bim;
8781
+ }
8782
+
85358783 ShadowBuffer shadowPBuf;
85368784 AntialiasBuffer antialiasPBuf;
85378785 int MAXSTACK;
....@@ -8548,10 +8796,12 @@
85488796
85498797 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
85508798 MAXSTACK = temp[0];
8551
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8799
+ if (Globals.DEBUG)
8800
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
85528801 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
85538802 MAXSTACK = temp[0];
8554
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8803
+ if (Globals.DEBUG)
8804
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
85558805
85568806 // Use debug pipeline
85578807 //drawable.setGL(new DebugGL(gl)); //
....@@ -8559,7 +8809,8 @@
85598809 gl = drawable.getGL(); //
85608810
85618811 GL gl3 = getGL();
8562
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8812
+ if (Globals.DEBUG)
8813
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
85638814
85648815
85658816 //float pos[] = { 100, 100, 100, 0 };
....@@ -8724,7 +8975,7 @@
87248975
87258976 if (cubemap == null)
87268977 {
8727
- LoadEnvy(5);
8978
+ //LoadEnvy(1);
87288979 }
87298980
87308981 //cubemap.enable();
....@@ -9000,6 +9251,8 @@
90009251
90019252 void LoadEnvy(int which)
90029253 {
9254
+ assert(false);
9255
+
90039256 String name;
90049257 String ext;
90059258
....@@ -9011,37 +9264,58 @@
90119264 cubemap = null;
90129265 return;
90139266 case 1:
9014
- name = "cubemaps/box_";
9015
- ext = "png";
9267
+ name = "cubemaps/rgb/";
9268
+ ext = "jpg";
90169269 reverseUP = false;
90179270 break;
90189271 case 2:
9019
- name = "cubemaps/uffizi_";
9020
- ext = "png";
9021
- break; // reverseUP = true; break;
9272
+ name = "cubemaps/uffizi/";
9273
+ ext = "jpg";
9274
+ reverseUP = false;
9275
+ break;
90229276 case 3:
9023
- name = "cubemaps/CloudyHills_";
9024
- ext = "tga";
9277
+ name = "cubemaps/CloudyHills/";
9278
+ ext = "jpg";
90259279 reverseUP = false;
90269280 break;
90279281 case 4:
9028
- name = "cubemaps/cornell_";
9282
+ name = "cubemaps/cornell/";
90299283 ext = "png";
90309284 reverseUP = false;
90319285 break;
9286
+ case 5:
9287
+ name = "cubemaps/skycube/";
9288
+ ext = "jpg";
9289
+ reverseUP = false;
9290
+ break;
9291
+ case 6:
9292
+ name = "cubemaps/SaintLazarusChurch3/";
9293
+ ext = "jpg";
9294
+ reverseUP = false;
9295
+ break;
9296
+ case 7:
9297
+ name = "cubemaps/Sodermalmsallen/";
9298
+ ext = "jpg";
9299
+ reverseUP = false;
9300
+ break;
9301
+ case 8:
9302
+ name = "cubemaps/Sodermalmsallen2/";
9303
+ ext = "jpg";
9304
+ reverseUP = false;
9305
+ break;
9306
+ case 9:
9307
+ name = "cubemaps/UnionSquare/";
9308
+ ext = "jpg";
9309
+ reverseUP = false;
9310
+ break;
90329311 default:
9033
- name = "cubemaps/rgb_";
9034
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9312
+ name = "cubemaps/box/";
9313
+ ext = "png"; /*mipmap = true;*/
9314
+ reverseUP = false;
90359315 break;
90369316 }
9037
-
9038
- try
9039
- {
9040
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
9041
- } catch (IOException e)
9042
- {
9043
- throw new RuntimeException(e);
9044
- }
9317
+
9318
+ LoadSkybox(name, ext, mipmap);
90459319 }
90469320
90479321 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -9073,8 +9347,12 @@
90739347 static double[] model = new double[16];
90749348 double[] camera2light = new double[16];
90759349 double[] light2camera = new double[16];
9076
- int newenvy = -1;
9077
- boolean envyoff = true; // false;
9350
+
9351
+ //int newenvy = -1;
9352
+ //boolean envyoff = false;
9353
+
9354
+ String loadedskyboxname;
9355
+
90789356 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
90799357 //float[] light0 = { 0,0,0 };
90809358 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9367,11 +9645,35 @@
93679645 jy8[3] = 0.5f;
93689646 }
93699647
9370
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9648
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
93719649 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
93729650 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
93739651 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
93749652
9653
+ void ResetOptions()
9654
+ {
9655
+ options1[0] = 100;
9656
+ options1[1] = 0.025f;
9657
+ options1[2] = 0.01f;
9658
+ options1[3] = 0;
9659
+ options1[4] = 0;
9660
+
9661
+ options2[0] = 0;
9662
+ options2[1] = 0.75f;
9663
+ options2[2] = 0;
9664
+ options2[3] = 0;
9665
+
9666
+ options3[0] = 1;
9667
+ options3[1] = 1;
9668
+ options3[2] = 1;
9669
+ options3[3] = 0;
9670
+
9671
+ options4[0] = 1;
9672
+ options4[1] = 0;
9673
+ options4[2] = 1;
9674
+ options4[3] = 0;
9675
+ }
9676
+
93759677 static int imagecount = 0; // movie generation
93769678
93779679 static int jitter = 0;
....@@ -9468,7 +9770,7 @@
94689770
94699771 if (renderCamera != lightCamera)
94709772 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9471
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
9773
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
94729774
94739775 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
94749776
....@@ -9484,7 +9786,7 @@
94849786
94859787 if (renderCamera != lightCamera)
94869788 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9487
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
9789
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
94889790
94899791 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
94909792
....@@ -9530,10 +9832,12 @@
95309832 rati = 1 / rati;
95319833 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
95329834 }
9533
- assert (newenvy == -1);
9835
+
9836
+ //assert (newenvy == -1);
9837
+
95349838 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
95359839 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9536
- DrawSkyBox(gl);
9840
+ DrawSkyBox(gl, (float)rati);
95379841 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
95389842 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
95399843 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10399,9 +10703,18 @@
1039910703 static boolean init = false;
1040010704
1040110705 double[][] matrix = LA.newMatrix();
10706
+
10707
+ // This is to refresh the UI of the material panel.
10708
+ ObjEditor patchMaterial;
1040210709
1040310710 public void display(GLAutoDrawable drawable)
1040410711 {
10712
+ if (patchMaterial.patchMaterial)
10713
+ {
10714
+ patchMaterial.patchMaterial = false;
10715
+ patchMaterial.objectPanel.setSelectedIndex(1);
10716
+ }
10717
+
1040510718 if (Grafreed.savesound && Grafreed.hassound)
1040610719 {
1040710720 Grafreed.wav.save();
....@@ -10482,6 +10795,7 @@
1048210795 ANTIALIAS = 0;
1048310796 //System.out.println("RESTART");
1048410797 AAtimer.restart();
10798
+ Globals.TIMERRUNNING = true;
1048510799 }
1048610800 }
1048710801 }
....@@ -10549,7 +10863,8 @@
1054910863 ambientOcclusion = false;
1055010864 }
1055110865
10552
- if (Globals.lighttouched && DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
10866
+ if (//Globals.lighttouched &&
10867
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1055310868 {
1055410869 //if (RENDERSHADOW) // ?
1055510870 if (!IsFrozen())
....@@ -10568,7 +10883,7 @@
1056810883
1056910884 if (wait)
1057010885 {
10571
- Sleep(500);
10886
+ Sleep(200); // blocks everything
1057210887
1057310888 wait = false;
1057410889 }
....@@ -10683,7 +10998,7 @@
1068310998 // if (parentcam != renderCamera) // not a light
1068410999 if (cam != lightCamera)
1068511000 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10686
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
11001
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1068711002
1068811003 for (int j = 0; j < 4; j++)
1068911004 {
....@@ -10698,7 +11013,7 @@
1069811013 // if (parentcam != renderCamera) // not a light
1069911014 if (cam != lightCamera)
1070011015 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10701
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
11016
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1070211017
1070311018 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1070411019
....@@ -10784,13 +11099,43 @@
1078411099 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1078511100 }
1078611101
10787
- if (newenvy > -1)
11102
+// if (newenvy > -1)
11103
+// {
11104
+// LoadEnvy(newenvy);
11105
+// }
11106
+//
11107
+// newenvy = -1;
11108
+
11109
+ if (transformMode) // object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
1078811110 {
10789
- LoadEnvy(newenvy);
11111
+ if (cubemaprgb == null)
11112
+ {
11113
+ cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb2" + "/", "jpg", false);
11114
+ }
11115
+
11116
+ cubemap = cubemaprgb;
1079011117 }
10791
-
10792
- newenvy = -1;
10793
-
11118
+ else
11119
+ {
11120
+ if (object.skyboxname != null)
11121
+ {
11122
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11123
+ {
11124
+ if (cubemap != null && cubemap != cubemaprgb)
11125
+ cubemap.dispose();
11126
+ cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11127
+ loadedskyboxname = object.skyboxname;
11128
+ }
11129
+ }
11130
+ else
11131
+ {
11132
+ cubemapcustom = null;
11133
+ loadedskyboxname = null;
11134
+ }
11135
+
11136
+ cubemap = cubemapcustom;
11137
+ }
11138
+
1079411139 ratio = ((double) getWidth()) / getHeight();
1079511140 //System.out.println("ratio = " + ratio);
1079611141
....@@ -10806,7 +11151,7 @@
1080611151
1080711152 if (!IsFrozen() && !ambientOcclusion)
1080811153 {
10809
- DrawSkyBox(gl);
11154
+ DrawSkyBox(gl, (float)ratio);
1081011155 }
1081111156
1081211157 //if (selection_view == -1)
....@@ -10989,9 +11334,9 @@
1098911334
1099011335 gl.glMatrixMode(GL.GL_MODELVIEW);
1099111336
10992
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10993
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10994
-//gl.glEnable(gl.GL_MULTISAMPLE);
11337
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11338
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11339
+gl.glEnable(gl.GL_MULTISAMPLE);
1099511340 } else
1099611341 {
1099711342 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -11002,7 +11347,7 @@
1100211347 //System.out.println("BLENDING ON");
1100311348 gl.glEnable(GL.GL_BLEND);
1100411349 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
11005
-
11350
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1100611351 gl.glMatrixMode(gl.GL_PROJECTION);
1100711352 gl.glLoadIdentity();
1100811353
....@@ -11092,7 +11437,7 @@
1109211437
1109311438 // if (cam != lightCamera)
1109411439 //for (int count = parentcam.GetTransformCount(); --count>=0;)
11095
- LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
11440
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1109611441 }
1109711442
1109811443 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -11251,7 +11596,7 @@
1125111596 }
1125211597 }
1125311598
11254
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11599
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1125511600 {
1125611601 //gl.glDepthFunc(GL.GL_LEQUAL);
1125711602 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11259,24 +11604,21 @@
1125911604
1126011605 boolean texon = textureon;
1126111606
11262
- if (RENDERPROGRAM > 0)
11263
- {
11264
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11265
- textureon = false;
11266
- }
11607
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11608
+ textureon = false;
11609
+
1126711610 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1126811611 //System.out.println("ALLO");
1126911612 gl.glColorMask(false, false, false, false);
1127011613 DrawObject(gl);
11271
- if (RENDERPROGRAM > 0)
11272
- {
11273
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11274
- textureon = texon;
11275
- }
11614
+
11615
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11616
+ textureon = texon;
11617
+
1127611618 gl.glColorMask(true, true, true, true);
1127711619
1127811620 gl.glDepthFunc(GL.GL_EQUAL);
11279
- //gl.glDepthMask(false);
11621
+ gl.glDepthMask(false);
1128011622 }
1128111623
1128211624 if (false) // DrawMode() == SHADOW)
....@@ -11459,15 +11801,36 @@
1145911801
1146011802 static boolean zoomonce = false;
1146111803
11804
+ static void CreateSelectedPoint()
11805
+ {
11806
+ if (selectedpoint == null)
11807
+ {
11808
+ debugpointG = new Sphere();
11809
+ debugpointP = new Sphere();
11810
+ debugpointC = new Sphere();
11811
+ debugpointR = new Sphere();
11812
+
11813
+ selectedpoint = new Superellipsoid();
11814
+
11815
+ for (int i=0; i<8; i++)
11816
+ {
11817
+ debugpoints[i] = new Sphere();
11818
+ }
11819
+ }
11820
+ }
11821
+
1146211822 void DrawObject(GL gl, boolean draw)
1146311823 {
11824
+ // To clear camera values
11825
+ ResetOptions();
11826
+
1146411827 //System.out.println("DRAW OBJECT " + mouseDown);
1146511828 // DrawMode() = SELECTION;
1146611829 //GL gl = getGL();
1146711830 if ((TRACK || SHADOWTRACK) || zoomonce)
1146811831 {
1146911832 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11470
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11833
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1147111834 pingthread.StepToTarget(true); // true);
1147211835 // zoomonce = false;
1147311836 }
....@@ -11539,8 +11902,9 @@
1153911902
1154011903 if (DrawMode() == DEFAULT)
1154111904 {
11542
- if (DEBUG)
11905
+ if (Globals.DEBUG)
1154311906 {
11907
+ CreateSelectedPoint();
1154411908 float radius = 0.05f;
1154511909 if (selectedpoint.radius != radius)
1154611910 {
....@@ -11594,20 +11958,32 @@
1159411958 ReleaseTextures(DEFAULT_TEXTURES);
1159511959
1159611960 if (CLEANCACHE)
11597
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11961
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1159811962 {
11599
- String tex = e.nextElement();
11963
+ cTexture tex = e.nextElement();
1160011964
1160111965 // System.out.println("Texture --------- " + tex);
1160211966
11603
- if (tex.equals("WHITE_NOISE"))
11967
+ if (tex.equals("WHITE_NOISE:"))
1160411968 continue;
1160511969
11606
- if (!usedtextures.containsKey(tex))
11970
+ if (!usedtextures.contains(tex))
1160711971 {
11972
+ CacheTexture gettex = texturepigment.get(tex);
1160811973 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11609
- textures.get(tex).texture.dispose();
11610
- textures.remove(tex);
11974
+ if (gettex != null)
11975
+ {
11976
+ gettex.texture.dispose();
11977
+ texturepigment.remove(tex);
11978
+ }
11979
+
11980
+ gettex = texturebump.get(tex);
11981
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11982
+ if (gettex != null)
11983
+ {
11984
+ gettex.texture.dispose();
11985
+ texturebump.remove(tex);
11986
+ }
1161111987 }
1161211988 }
1161311989 }
....@@ -12027,7 +12403,7 @@
1202712403 for (int i = tp.size(); --i >= 0;)
1202812404 {
1202912405 //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12030
- LA.xformPos(light, tp.get(i).GlobalTransform(), light);
12406
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1203112407 }
1203212408
1203312409
....@@ -12135,8 +12511,82 @@
1213512511
1213612512 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1213712513
12138
- String program =
12514
+ String programmin =
12515
+ // Min shader
1213912516 "!!ARBfp1.0\n" +
12517
+ "PARAM zero12t = { 0.0, 1.0, 2, 1.25 };" +
12518
+ "PARAM pow_2 = { 0.5, 0.25, 0.125, 0.0 };" +
12519
+ "PARAM pow2 = { 2, 4, 8, 0.0 };" +
12520
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12521
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12522
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12523
+ "PARAM light2cam0 = program.env[10];" +
12524
+ "PARAM light2cam1 = program.env[11];" +
12525
+ "PARAM light2cam2 = program.env[12];" +
12526
+ "TEMP temp;" +
12527
+ "TEMP light;" +
12528
+ "TEMP ndotl;" +
12529
+ "TEMP normal;" +
12530
+ "TEMP depth;" +
12531
+ "TEMP eye;" +
12532
+ "TEMP pos;" +
12533
+
12534
+ "MAD normal, fragment.color, zero12t.z, -zero12t.y;" +
12535
+ Normalize("normal") +
12536
+ "MOV light, state.light[0].position;" +
12537
+ "DP3 ndotl.x, light, normal;" +
12538
+ "MAX ndotl.x, ndotl.x, zero12t.x;" +
12539
+
12540
+ // shadow
12541
+ "MOV pos, fragment.texcoord[1];" +
12542
+ "MOV temp, pos;" +
12543
+ ShadowTextureFetch("depth", "temp", "1") +
12544
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12545
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12546
+
12547
+ // No shadow when out of frustum
12548
+ //"SGE temp.y, depth.z, zero123.y;" +
12549
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12550
+
12551
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12552
+
12553
+ // Backlit
12554
+ "MOV pos.w, zero12t.y;" + // one
12555
+ "DP4 eye.x, pos, light2cam0;" +
12556
+ "DP4 eye.y, pos, light2cam1;" +
12557
+ "DP4 eye.z, pos, light2cam2;" +
12558
+ Normalize("eye") +
12559
+
12560
+ "DP3 ndotl.y, -eye, normal;" +
12561
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12562
+ "POW ndotl.y, ndotl.y, pow2.x;" + // backlit
12563
+ "SUB ndotl.y, zero12t.y, ndotl.y;" + // 1 - y
12564
+ //"POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12565
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12566
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12567
+ "ADD ndotl.y, ndotl.y, one.x;" +
12568
+ "MUL ndotl.y, ndotl.y, pow_2.x;" +
12569
+
12570
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12571
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12572
+
12573
+ // Pigment
12574
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12575
+ "LRP temp, zero12t.w, temp, one;" + // texture proportion
12576
+ "MUL temp, temp, zero12t.w;" + // Times x
12577
+
12578
+ //"MUL temp, temp, ndotl.y;" +
12579
+ "MAD ndotl.x, pow_2.xxxx, ndotl.yyyy, ndotl.x;" +
12580
+
12581
+ "MUL temp, temp, ndotl.x;" + // lambert
12582
+
12583
+ "MOV temp.w, zero12t.y;" + // reset alpha
12584
+ "MOV result.color, temp;" +
12585
+ "END";
12586
+
12587
+ String programmax =
12588
+ "!!ARBfp1.0\n" +
12589
+
1214012590 //"OPTION ARB_fragment_program_shadow;" +
1214112591 "PARAM light2cam0 = program.env[10];" +
1214212592 "PARAM light2cam1 = program.env[11];" +
....@@ -12162,7 +12612,7 @@
1216212612 "PARAM params4 = program.env[4];" + // anisoV, cameralight, selfshadow, shadow
1216312613 "PARAM params5 = program.env[5];" + // texture, opacity, fakedepth, shadowbias
1216412614 "PARAM params6 = program.env[6];" + // bump, noise, borderfade, fog punchthrough
12165
- "PARAM params7 = program.env[7];" + // noise power, opacity power
12615
+ "PARAM params7 = program.env[7];" + // noise power, opacity power, parallax
1216612616 "PARAM options0 = program.env[63];" + // fog density, intensity, elevation
1216712617 "PARAM options1 = program.env[62];" + // fog rgb color
1216812618 "PARAM options2 = program.env[61];" + // image intensity, subsurface, lightsheen
....@@ -12251,8 +12701,7 @@
1225112701 "TEMP shininess;" +
1225212702 "\n" +
1225312703 "MOV texSamp, one;" +
12254
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12255
-
12704
+
1225612705 "MOV mapgrid.x, one2048th.x;" +
1225712706 "MOV temp, fragment.texcoord[1];" +
1225812707 /*
....@@ -12273,20 +12722,20 @@
1227312722 "MUL temp, floor, mapgrid.x;" +
1227412723 //"TEX depth0, temp, texture[1], 2D;" +
1227512724 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12276
- TextureFetch("depth0", "temp", "1") +
12725
+ ShadowTextureFetch("depth0", "temp", "1") +
1227712726 "") +
1227812727 "ADD temp.x, temp.x, mapgrid.x;" +
1227912728 //"TEX depth1, temp, texture[1], 2D;" +
1228012729 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12281
- TextureFetch("depth1", "temp", "1") +
12730
+ ShadowTextureFetch("depth1", "temp", "1") +
1228212731 "") +
1228312732 "ADD temp.y, temp.y, mapgrid.x;" +
1228412733 //"TEX depth2, temp, texture[1], 2D;" +
12285
- TextureFetch("depth2", "temp", "1") +
12734
+ ShadowTextureFetch("depth2", "temp", "1") +
1228612735 "SUB temp.x, temp.x, mapgrid.x;" +
1228712736 //"TEX depth3, temp, texture[1], 2D;" +
1228812737 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12289
- TextureFetch("depth3", "temp", "1") +
12738
+ ShadowTextureFetch("depth3", "temp", "1") +
1229012739 "") +
1229112740 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1229212741 //"MOV params, material;" +
....@@ -12408,7 +12857,7 @@
1240812857 "POW texSamp.a, texSamp.a, params6.w;" + // fog punch through shortcut
1240912858 // mar 2013 ??? "KIL alpha.a;" +
1241012859 "MOV alpha, texSamp.aaaa;" + // y;" +
12411
- "KIL alpha.a;" +
12860
+ "KIL alpha.a;" + // not sure with parallax mapping
1241212861 /*
1241312862 "MUL temp.xy, temp, two;" +
1241412863 "TXB bump, temp, texture[0], 2D;" +
....@@ -12494,11 +12943,6 @@
1249412943 "SUB bump0, bump0, half;" +
1249512944 "ADD bump, bump, bump0;" +
1249612945
12497
- "MOV temp.x, texSamp.a;" +
12498
- "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
12499
- //"LRP texSamp0, params5.x, texSamp0, one;" +
12500
- "MOV texSamp.a, temp.x;" +
12501
-
1250212946 // double-sided
1250312947 /**/
1250412948 (doublesided?"DP3 temp.z, normal, eye;" +
....@@ -12515,19 +12959,62 @@
1251512959 "MOV normald, normal;" +
1251612960 "MOV normals, normal;" +
1251712961
12962
+ "MOV temp, fragment.texcoord[4];" +
12963
+
1251812964 // UV base
1251912965 //"DP3 UP.x,state.matrix.modelview.row[0],Y;" +
1252012966 //"DP3 UP.y,state.matrix.modelview.row[1],Y;" +
1252112967 //"DP3 UP.z,state.matrix.modelview.row[2],Y;" +
12522
- "DP3 UP.x,state.matrix.texture[7].row[0],Y;" +
12523
- "DP3 UP.y,state.matrix.texture[7].row[1],Y;" +
12524
- "DP3 UP.z,state.matrix.texture[7].row[2],Y;" +
12968
+ "DP3 UP.x,state.matrix.texture[7].row[0],temp;" +
12969
+ "DP3 UP.y,state.matrix.texture[7].row[1],temp;" +
12970
+ "DP3 UP.z,state.matrix.texture[7].row[2],temp;" +
12971
+ Normalize("UP") +
12972
+
1252512973 "XPD V, normal, UP;" +
1252612974 Normalize("V") +
1252712975 "XPD U, V, normal;" +
1252812976 Normalize("U") +
1252912977
1253012978 // parallax mapping
12979
+
12980
+ "DP3 temp2.x, V, eye;" +
12981
+ "DP3 temp2.y, U, eye;" +
12982
+ "DP3 temp2.z, normal, eye;" +
12983
+ "RCP temp2.z, temp2.z;" +
12984
+
12985
+ "DP3 temp2.w, texSamp, texSamp;" + // Height
12986
+ "RSQ temp2.w, temp2.w;" +
12987
+ "RCP temp2.w, temp2.w;" +
12988
+
12989
+ "SUB temp2.w, temp2.w, half;" +
12990
+// "SGE temp.x, temp2.w, eps.x;" +
12991
+// "MUL temp2.w, temp2.w, temp.x;" +
12992
+
12993
+ //"MOV texSamp, U;" +
12994
+
12995
+ "MUL temp2.z, temp2.z, temp2.w;" +
12996
+ "MUL temp2.z, temp2.z, params7.z;" + // parallax
12997
+
12998
+ "MUL temp2, temp2, temp2.z;" +
12999
+
13000
+ "MOV temp, fragment.texcoord[0];" +
13001
+
13002
+ "SUB temp, temp, temp2;" +
13003
+
13004
+ "TEX temp, temp, texture[0], 2D;" +
13005
+ "POW temp.a, temp.a, params6.w;" + // punch through
13006
+
13007
+ "ADD texSamp, temp, texSamp;" +
13008
+ "MUL texSamp.xyz, half, texSamp;" +
13009
+
13010
+ "MOV alpha, texSamp.aaaa;" +
13011
+
13012
+// parallax mapping
13013
+
13014
+ "MOV temp.x, texSamp.a;" +
13015
+ "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
13016
+ //"LRP texSamp0, params5.x, texSamp0, one;" +
13017
+ "MOV texSamp.a, temp.x;" +
1253113018
1253213019 //"MOV temp, fragment.texcoord[0];" +
1253313020 //
....@@ -12657,10 +13144,10 @@
1265713144 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1265813145 "") +
1265913146
12660
- // display shadow only (bump == 0)
13147
+ // display shadow only (fakedepth == 0)
1266113148 "SUB temp.x, half.x, shadow.x;" +
1266213149 "MOV temp.y, -params5.z;" + // params6.x;" +
12663
- "SLT temp.z, temp.y, -one2048th.x;" +
13150
+ "SLT temp.z, temp.y, -c256i.x;" +
1266413151 "SUB temp.y, one.x, temp.z;" +
1266513152 "MUL temp.x, temp.x, temp.y;" +
1266613153 "KIL temp.x;" +
....@@ -12991,8 +13478,19 @@
1299113478 //once = true;
1299213479 }
1299313480
12994
- System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
12995
- System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13481
+ String program = programmax;
13482
+
13483
+ if (Globals.MINSHADER)
13484
+ {
13485
+ program = programmin;
13486
+ }
13487
+
13488
+ if (Globals.DEBUG)
13489
+ {
13490
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13491
+ System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13492
+ }
13493
+
1299613494 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1299713495
1299813496 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -13039,7 +13537,8 @@
1303913537 "\n" +
1304013538 "END\n";
1304113539
13042
- System.out.println("Program shadow #" + 0 + "; length = " + program.length());
13540
+ if (Globals.DEBUG)
13541
+ System.out.println("Program shadow #" + 0 + "; length = " + program.length());
1304313542 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1304413543
1304513544 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -13084,25 +13583,26 @@
1308413583 return out;
1308513584 }
1308613585
13087
- String TextureFetch(String dest, String src, String unit)
13586
+ // Also does frustum culling
13587
+ String ShadowTextureFetch(String dest, String src, String unit)
1308813588 {
1308913589 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1309013590 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1309113591 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13592
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13593
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1309213594 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13093
- "SLT " + src + ".z, " + src + ".x, one.x;" +
13094
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13095
- "SLT " + src + ".z, " + src + ".y, one.x;" +
13096
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13595
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13596
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1309713597 //"SWZ buffer, temp, w,w,w,w;";
13098
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13598
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1309913599 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1310013600 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1310113601 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13102
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13602
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1310313603
13104
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13105
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13604
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13605
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1310613606 }
1310713607
1310813608 String Shadow(String depth, String shadow)
....@@ -13149,7 +13649,7 @@
1314913649 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1315013650 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1315113651
13152
- // No shadow when out of frustrum
13652
+ // No shadow when out of frustum
1315313653 "SGE temp.x, " + depth + ".z, one.z;" +
1315413654 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1315513655 "";
....@@ -13296,8 +13796,9 @@
1329613796 /*static*/ float[] modelParams4 = new float[]{0, 0, 0, 0}; // anisoV, cameralight, selfshadow, shadow
1329713797 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1329813798 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
13299
- /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13300
- Object3D.cVector2[] vector2buffer;
13799
+ /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power, parallax
13800
+
13801
+ //Object3D.cVector2[] vector2buffer;
1330113802
1330213803 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1330313804 // OUT : diff, spec
....@@ -13313,9 +13814,10 @@
1331313814 "DP3 " + dest + ".z," + "normals," + "eye;" +
1331413815 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1331513816 //"MOV " + dest + ".w," + "normal.z;" +
13316
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
13317
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13318
- //"MOV " + dest + ".z," + "params2.w;" +
13817
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13818
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13819
+
13820
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1331913821 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1332013822 "RCP " + dest + ".w," + dest + ".w;" +
1332113823 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13461,7 +13963,7 @@
1346113963 "PARAM p[4] = { state.matrix.projection }; # modelview projection matrix\n" +
1346213964 "PARAM zero = { 0.0, 0.0, 0.0, 1.0 };" +
1346313965 "PARAM half = { 0.5, 0.5, 0.5, 1.0 };" +
13464
- "PARAM one = { 1.0, 1.0, 1.0, 0.0 };" +
13966
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
1346513967 "PARAM two = { 2.0, 2.0, 2.0, 1.0 };" +
1346613968 "PARAM third = { 0.33333333333, 0.33333333333, 0.33333333333, 1.0 };" +
1346713969 //"PARAM v256 = { 256.0, 256.0, 256.0, 1.0 };" +
....@@ -13522,7 +14024,7 @@
1352214024 "DP4 temp.x,state.matrix.texture[0].inverse.row[0],vertex.texcoord;" +
1352314025 "DP4 temp.y,state.matrix.texture[0].inverse.row[1],vertex.texcoord;" +
1352414026 "DP4 temp.z,state.matrix.texture[0].inverse.row[2],vertex.texcoord;" +
13525
- //"MOV result.texcoord, vertex.texcoord;" +
14027
+ //"MOV result.texcoord, vertex.fogcoord;" +
1352614028 "MOV result.texcoord, temp;" +
1352714029 // border fade
1352814030 "MOV result.texcoord[3], vertex.texcoord;" +
....@@ -13569,7 +14071,9 @@
1356914071
1357014072 //"ADD temp.z, temp.z, one;" +
1357114073
13572
- "MOV result.color, temp;"
14074
+ "MOV result.texcoord[4], vertex.attrib[4];" + // U dir
14075
+
14076
+ "MOV result.color, temp;" // Normal
1357314077 : "MOV result.color, vertex.color;") +
1357414078 ((mode & VP_PROJECTION) != 0 ? "MOV result.color, zero;"
1357514079 : "") +
....@@ -13820,6 +14324,7 @@
1382014324 else
1382114325 if (evt.getSource() == AAtimer)
1382214326 {
14327
+ Globals.TIMERRUNNING = false;
1382314328 if (mouseDown)
1382414329 {
1382514330 //new Exception().printStackTrace();
....@@ -13879,7 +14384,7 @@
1387914384
1388014385 // fev 2014???
1388114386 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13882
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14387
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1388314388 pingthread.StepToTarget(true); // true);
1388414389 }
1388514390 // if (!LIVE)
....@@ -13894,6 +14399,7 @@
1389414399 return;
1389514400
1389614401 AAtimer.restart(); //
14402
+ Globals.TIMERRUNNING = true;
1389714403
1389814404 // waslive = LIVE;
1389914405 // LIVE = false;
....@@ -13943,14 +14449,15 @@
1394314449 drag = false;
1394414450 //System.out.println("Mouse DOWN");
1394514451 editObj = false;
13946
- ClickInfo info = new ClickInfo();
13947
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
13948
- info.pane = this;
13949
- info.camera = renderCamera;
13950
- info.x = x;
13951
- info.y = y;
13952
- info.modifiers = modifiersex;
13953
- editObj = object.doEditClick(info, 0);
14452
+ //ClickInfo info = new ClickInfo();
14453
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14454
+ object.clickInfo.pane = this;
14455
+ object.clickInfo.camera = renderCamera;
14456
+ object.clickInfo.x = x;
14457
+ object.clickInfo.y = y;
14458
+ object.clickInfo.modifiers = modifiersex;
14459
+ editObj = object.doEditClick(//info,
14460
+ 0);
1395414461 if (!editObj)
1395514462 {
1395614463 hasMarquee = true;
....@@ -14232,12 +14739,18 @@
1423214739 void GoDown(int mod)
1423314740 {
1423414741 MODIFIERS |= COMMAND;
14235
- /*
14742
+ boolean isVR = (mouseMode&VR)!=0;
14743
+ /**/
1423614744 if((mod&SHIFT) == SHIFT)
14237
- manipCamera.RotatePosition(0, -speed);
14745
+ {
14746
+ if (isVR)
14747
+ manipCamera.RotateInterest(0, -speed);
14748
+ else
14749
+ manipCamera.RotatePosition(0, -speed);
14750
+ }
1423814751 else
14239
- manipCamera.BackForth(0, -speed*delta, getWidth());
14240
- */
14752
+ manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth());
14753
+ /**/
1424114754 if ((mod & SHIFT) == SHIFT)
1424214755 {
1424314756 mouseMode = mouseMode; // VR??
....@@ -14246,6 +14759,8 @@
1424614759 mouseMode |= BACKFORTH;
1424714760 }
1424814761
14762
+ targetLookAt.set(manipCamera.lookAt);
14763
+
1424914764 //prevX = X = anchorX;
1425014765 prevY = Y = anchorY - (int) (renderCamera.Distance());
1425114766 }
....@@ -14253,12 +14768,19 @@
1425314768 void GoUp(int mod)
1425414769 {
1425514770 MODIFIERS |= COMMAND;
14256
- /*
14771
+ /**/
14772
+ boolean isVR = (mouseMode&VR)!=0;
14773
+
1425714774 if((mod&SHIFT) == SHIFT)
14258
- manipCamera.RotatePosition(0, speed);
14775
+ {
14776
+ if (isVR)
14777
+ manipCamera.RotateInterest(0, speed);
14778
+ else
14779
+ manipCamera.RotatePosition(0, speed);
14780
+ }
1425914781 else
14260
- manipCamera.BackForth(0, speed*delta, getWidth());
14261
- */
14782
+ manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth());
14783
+ /**/
1426214784 if ((mod & SHIFT) == SHIFT)
1426314785 {
1426414786 mouseMode = mouseMode;
....@@ -14267,6 +14789,8 @@
1426714789 mouseMode |= BACKFORTH;
1426814790 }
1426914791
14792
+ targetLookAt.set(manipCamera.lookAt);
14793
+
1427014794 //prevX = X = anchorX;
1427114795 prevY = Y = anchorY + (int) (renderCamera.Distance());
1427214796 }
....@@ -14274,12 +14798,17 @@
1427414798 void GoLeft(int mod)
1427514799 {
1427614800 MODIFIERS |= COMMAND;
14277
- /*
14801
+ /**/
1427814802 if((mod&SHIFT) == SHIFT)
14279
- manipCamera.RotatePosition(speed, 0);
14803
+ manipCamera.Translate(speed*delta, 0, getWidth());
1428014804 else
14281
- manipCamera.Translate(speed*delta, 0, getWidth());
14282
- */
14805
+ {
14806
+ if ((mouseMode&VR)!=0)
14807
+ manipCamera.RotateInterest(-speed, 0);
14808
+ else
14809
+ manipCamera.RotatePosition(speed, 0);
14810
+ }
14811
+ /**/
1428314812 if ((mod & SHIFT) == SHIFT)
1428414813 {
1428514814 mouseMode = mouseMode;
....@@ -14288,6 +14817,8 @@
1428814817 mouseMode |= ROTATE;
1428914818 } // TRANSLATE;
1429014819
14820
+ targetLookAt.set(manipCamera.lookAt);
14821
+
1429114822 prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance());
1429214823 prevY = Y = anchorY;
1429314824 }
....@@ -14295,12 +14826,18 @@
1429514826 void GoRight(int mod)
1429614827 {
1429714828 MODIFIERS |= COMMAND;
14298
- /*
14829
+ /**/
1429914830 if((mod&SHIFT) == SHIFT)
14300
- manipCamera.RotatePosition(-speed, 0);
14831
+ manipCamera.Translate(-speed*delta, 0, getWidth());
1430114832 else
14302
- manipCamera.Translate(-speed*delta, 0, getWidth());
14303
- */
14833
+ {
14834
+ if ((mouseMode&VR)!=0)
14835
+ manipCamera.RotateInterest(speed, 0);
14836
+ else
14837
+ manipCamera.RotatePosition(-speed, 0);
14838
+ }
14839
+
14840
+ /**/
1430414841 if ((mod & SHIFT) == SHIFT)
1430514842 {
1430614843 mouseMode = mouseMode;
....@@ -14309,6 +14846,8 @@
1430914846 mouseMode |= ROTATE;
1431014847 } // TRANSLATE;
1431114848
14849
+ targetLookAt.set(manipCamera.lookAt);
14850
+
1431214851 prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance());
1431314852 prevY = Y = anchorY;
1431414853 }
....@@ -14350,14 +14889,16 @@
1435014889 if (editObj)
1435114890 {
1435214891 drag = true;
14353
- ClickInfo info = new ClickInfo();
14354
- info.bounds.setBounds(0, 0,
14892
+ //ClickInfo info = new ClickInfo();
14893
+ object.clickInfo.bounds.setBounds(0, 0,
1435514894 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14356
- info.pane = this;
14357
- info.camera = renderCamera;
14358
- info.x = x;
14359
- info.y = y;
14360
- object.editWindow.copy.doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
14895
+ object.clickInfo.pane = this;
14896
+ object.clickInfo.camera = renderCamera;
14897
+ object.clickInfo.x = x;
14898
+ object.clickInfo.y = y;
14899
+ object //.GetWindow().copy
14900
+ .doEditDrag(//info,
14901
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1436114902 } else
1436214903 {
1436314904 if (x < startX)
....@@ -14506,22 +15047,27 @@
1450615047 }
1450715048 }
1450815049
15050
+// ClickInfo clickInfo = new ClickInfo();
15051
+
1450915052 public void mouseMoved(MouseEvent e)
1451015053 {
1451115054 //System.out.println("mouseMoved: " + e);
1451215055 if (isRenderer)
1451315056 return;
1451415057
14515
- ClickInfo ci = new ClickInfo();
14516
- ci.x = e.getX();
14517
- ci.y = e.getY();
14518
- ci.modifiers = e.getModifiersEx();
14519
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14520
- ci.pane = this;
14521
- ci.camera = renderCamera;
15058
+ // Mouse cursor feedback
15059
+ object.clickInfo.x = e.getX();
15060
+ object.clickInfo.y = e.getY();
15061
+ object.clickInfo.modifiers = e.getModifiersEx();
15062
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
15063
+ object.clickInfo.pane = this;
15064
+ object.clickInfo.camera = renderCamera;
1452215065 if (!isRenderer)
1452315066 {
14524
- if (object.editWindow.copy.doEditClick(ci, 0))
15067
+ //ObjEditor editWindow = object.editWindow;
15068
+ //Object3D copy = editWindow.copy;
15069
+ if (object.doEditClick(//clickInfo,
15070
+ 0))
1452515071 {
1452615072 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1452715073 } else
....@@ -14536,7 +15082,8 @@
1453615082 Globals.MOUSEDRAGGED = false;
1453715083
1453815084 movingcamera = false;
14539
- X = Y = 0;
15085
+ X = 0; // getBounds().width/2;
15086
+ Y = 0; // getBounds().height/2;
1454015087 //System.out.println("mouseReleased: " + e);
1454115088 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1454215089 }
....@@ -14792,7 +15339,8 @@
1479215339 // break;
1479315340 case 'T':
1479415341 CACHETEXTURE ^= true;
14795
- textures.clear();
15342
+ texturepigment.clear();
15343
+ texturebump.clear();
1479615344 // repaint();
1479715345 break;
1479815346 case 'Y':
....@@ -14802,8 +15350,8 @@
1480215350 case 'K':
1480315351 KOMPACTTEXTURE ^= true;
1480415352 //textures.clear();
14805
- break;
14806
- case 'P': // Texture Projection macros
15353
+ // break;
15354
+ //case 'P': // Texture Projection macros
1480715355 // SAVETEXTURE ^= true;
1480815356 macromode = true;
1480915357 Udebug = Vdebug = NORMALdebug = false; programInitialized = false;
....@@ -14877,7 +15425,9 @@
1487715425 case 'E' : COMPACT ^= true;
1487815426 repaint();
1487915427 break;
14880
- case 'W' : DEBUGHSB ^= true;
15428
+ case 'W' : // Wide Window (fullscreen)
15429
+ //DEBUGHSB ^= true;
15430
+ ObjEditor.theFrame.ToggleFullScreen();
1488115431 repaint();
1488215432 break;
1488315433 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14902,8 +15452,8 @@
1490215452 RevertCamera();
1490315453 repaint();
1490415454 break;
14905
- case 'L':
1490615455 case 'l':
15456
+ //case 'L':
1490715457 if (lightMode)
1490815458 {
1490915459 lightMode = false;
....@@ -14922,7 +15472,7 @@
1492215472 targetLookAt.set(manipCamera.lookAt);
1492315473 repaint();
1492415474 break;
14925
- case 'p':
15475
+ case 'P': // p':
1492615476 // c'est quoi ca au juste? spherical ^= true;
1492715477 Skinshader ^= true; programInitialized = false;
1492815478 repaint();
....@@ -14960,27 +15510,31 @@
1496015510 repaint();
1496115511 break;
1496215512 case 'O':
14963
- Globals.drawMode = OCCLUSION; // WARNING
15513
+ // Too dangerous. Use menu. Globals.drawMode = OCCLUSION; // WARNING
1496415514 repaint();
1496515515 break;
1496615516 case 'o':
1496715517 OCCLUSION_CULLING ^= true;
1496815518 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1496915519 break;
14970
- case '0': envyoff ^= true; repaint(); break;
15520
+ //case '0': envyoff ^= true; repaint(); break;
1497115521 case '1':
1497215522 case '2':
1497315523 case '3':
1497415524 case '4':
1497515525 case '5':
14976
- newenvy = Character.getNumericValue(key);
14977
- repaint();
14978
- break;
1497915526 case '6':
1498015527 case '7':
1498115528 case '8':
1498215529 case '9':
14983
- BGcolor = (key - '6')/3.f;
15530
+ if (true) // envyoff)
15531
+ {
15532
+ BGcolor = (key - '1')/8.f;
15533
+ }
15534
+ else
15535
+ {
15536
+ //newenvy = Character.getNumericValue(key);
15537
+ }
1498415538 repaint();
1498515539 break;
1498615540 case '!':
....@@ -15046,9 +15600,9 @@
1504615600 case '_':
1504715601 kompactbit = 5;
1504815602 break;
15049
- case '+':
15050
- kompactbit = 6;
15051
- break;
15603
+// case '+':
15604
+// kompactbit = 6;
15605
+// break;
1505215606 case ' ':
1505315607 lightMode ^= true;
1505415608 Globals.lighttouched = true;
....@@ -15060,6 +15614,7 @@
1506015614 case ESC:
1506115615 RENDERPROGRAM += 1;
1506215616 RENDERPROGRAM %= 3;
15617
+
1506315618 repaint();
1506415619 break;
1506515620 case 'Z':
....@@ -15099,8 +15654,9 @@
1509915654 case DELETE:
1510015655 ClearSelection();
1510115656 break;
15102
- /*
1510315657 case '+':
15658
+
15659
+ /*
1510415660 //fontsize += 1;
1510515661 bbzoom *= 2;
1510615662 repaint();
....@@ -15117,17 +15673,17 @@
1511715673 case '=':
1511815674 IncDepth();
1511915675 //fontsize += 1;
15120
- object.editWindow.refreshContents(true);
15676
+ object.GetWindow().refreshContents(true);
1512115677 maskbit = 6;
1512215678 break;
1512315679 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1512415680 DecDepth();
1512515681 maskbit = 5;
1512615682 //if(fontsize > 1) fontsize -= 1;
15127
- if (object.editWindow == null)
15128
- new Exception().printStackTrace();
15129
- else
15130
- object.editWindow.refreshContents(true);
15683
+// if (object.editWindow == null)
15684
+// new Exception().printStackTrace();
15685
+// else
15686
+ object.GetWindow().refreshContents(true);
1513115687 break;
1513215688 case '{':
1513315689 manipCamera.shaper_fovy /= 1.1;
....@@ -15351,7 +15907,7 @@
1535115907 }
1535215908 */
1535315909
15354
- object.editWindow.EditSelection();
15910
+ object.GetWindow().EditSelection(false);
1535515911 }
1535615912
1535715913 void SelectParent()
....@@ -15368,10 +15924,10 @@
1536815924 {
1536915925 //selectees.remove(i);
1537015926 System.out.println("select parent of " + elem);
15371
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15927
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1537215928 } else
1537315929 {
15374
- group.editWindow.Select(elem.GetTreePath(), first, true);
15930
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1537515931 }
1537615932
1537715933 first = false;
....@@ -15413,12 +15969,12 @@
1541315969 for (int j = 0; j < group.children.size(); j++)
1541415970 {
1541515971 elem = (Object3D) group.children.elementAt(j);
15416
- object.editWindow.Select(elem.GetTreePath(), first, true);
15972
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1541715973 first = false;
1541815974 }
1541915975 } else
1542015976 {
15421
- object.editWindow.Select(elem.GetTreePath(), first, true);
15977
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1542215978 }
1542315979
1542415980 first = false;
....@@ -15429,21 +15985,21 @@
1542915985 {
1543015986 //Composite group = (Composite) object;
1543115987 Object3D group = object;
15432
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15988
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1543315989 }
1543415990
1543515991 void ResetTransform(int mask)
1543615992 {
1543715993 //Composite group = (Composite) object;
1543815994 Object3D group = object;
15439
- group.editWindow.ResetTransform(mask);
15995
+ group.GetWindow().ResetTransform(mask);
1544015996 }
1544115997
1544215998 void FlipTransform()
1544315999 {
1544416000 //Composite group = (Composite) object;
1544516001 Object3D group = object;
15446
- group.editWindow.FlipTransform();
16002
+ group.GetWindow().FlipTransform();
1544716003 // group.editWindow.ReduceMesh(true);
1544816004 }
1544916005
....@@ -15451,7 +16007,7 @@
1545116007 {
1545216008 //Composite group = (Composite) object;
1545316009 Object3D group = object;
15454
- group.editWindow.PrintMemory();
16010
+ group.GetWindow().PrintMemory();
1545516011 // group.editWindow.ReduceMesh(true);
1545616012 }
1545716013
....@@ -15459,7 +16015,7 @@
1545916015 {
1546016016 //Composite group = (Composite) object;
1546116017 Object3D group = object;
15462
- group.editWindow.ResetCentroid();
16018
+ group.GetWindow().ResetCentroid();
1546316019 }
1546416020
1546516021 void IncDepth()
....@@ -15541,8 +16097,6 @@
1554116097
1554216098 int width = getBounds().width;
1554316099 int height = getBounds().height;
15544
- ClickInfo info = new ClickInfo();
15545
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1554616100 //Image img = CreateImage(width, height);
1554716101 //System.out.println("width = " + width + "; height = " + height + "\n");
1554816102
....@@ -15619,48 +16173,77 @@
1561916173 }
1562016174 if (object != null && !hasMarquee)
1562116175 {
16176
+ if (object.clickInfo == null)
16177
+ object.clickInfo = new ClickInfo();
16178
+ ClickInfo info = object.clickInfo;
16179
+ //ClickInfo info = new ClickInfo();
16180
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16181
+
1562216182 if (isRenderer)
1562316183 {
15624
- info.flags++;
16184
+ object.clickInfo.flags++;
1562516185 double frameAspect = (double) width / (double) height;
1562616186 if (frameAspect > renderCamera.aspect)
1562716187 {
1562816188 int desired = (int) ((double) height * renderCamera.aspect);
15629
- info.bounds.width -= width - desired;
15630
- info.bounds.x += (width - desired) / 2;
16189
+ object.clickInfo.bounds.width -= width - desired;
16190
+ object.clickInfo.bounds.x += (width - desired) / 2;
1563116191 } else
1563216192 {
1563316193 int desired = (int) ((double) width / renderCamera.aspect);
15634
- info.bounds.height -= height - desired;
15635
- info.bounds.y += (height - desired) / 2;
16194
+ object.clickInfo.bounds.height -= height - desired;
16195
+ object.clickInfo.bounds.y += (height - desired) / 2;
1563616196 }
1563716197 }
15638
- info.g = gr;
15639
- info.camera = renderCamera;
16198
+
16199
+ object.clickInfo.g = gr;
16200
+ object.clickInfo.camera = renderCamera;
1564016201 /*
1564116202 // Memory intensive (brep.verticescopy)
1564216203 if (!(object instanceof Composite))
1564316204 object.draw(info, 0, false); // SLOW :
1564416205 */
15645
- if (!isRenderer)
16206
+ if (!isRenderer) // && drag)
1564616207 {
15647
- object.drawEditHandles(info, 0);
15648
-
15649
- if (drag && (X != 0 || Y != 0) && object.selection.Size() > 0)
16208
+ Grafreed.Assert(object != null);
16209
+ Grafreed.Assert(object.selection != null);
16210
+ if (object.selection.Size() > 0)
1565016211 {
15651
- switch (object.selection.get(0).hitSomething)
16212
+ int hitSomething = object.selection.get(0).hitSomething;
16213
+
16214
+ object.clickInfo.DX = 0;
16215
+ object.clickInfo.DY = 0;
16216
+ object.clickInfo.W = 1;
16217
+ if (hitSomething == Object3D.hitCenter)
1565216218 {
15653
- case Object3D.hitCenter: gr.setColor(Color.pink);
15654
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15655
- break;
15656
- case Object3D.hitRotate: gr.setColor(Color.yellow);
15657
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15658
- break;
15659
- case Object3D.hitScale: gr.setColor(Color.cyan);
15660
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15661
- break;
16219
+ info.DX = X;
16220
+ if (X != 0)
16221
+ info.DX -= info.bounds.width/2;
16222
+
16223
+ info.DY = Y;
16224
+ if (Y != 0)
16225
+ info.DY -= info.bounds.height/2;
1566216226 }
15663
-
16227
+
16228
+ object.drawEditHandles(//info,
16229
+ 0);
16230
+
16231
+ if (drag && (X != 0 || Y != 0))
16232
+ {
16233
+ switch (hitSomething)
16234
+ {
16235
+ case Object3D.hitCenter: gr.setColor(Color.white);
16236
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16237
+ break;
16238
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16239
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16240
+ break;
16241
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16242
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16243
+ break;
16244
+ }
16245
+
16246
+ }
1566416247 }
1566516248 }
1566616249 }
....@@ -15675,7 +16258,7 @@
1567516258 if (hasMarquee)
1567616259 {
1567716260 gr.setXORMode(Color.white);
15678
- gr.setColor(Color.red);
16261
+ gr.setColor(Color.white);
1567916262 if (!firstime)
1568016263 {
1568116264 gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH);
....@@ -16142,6 +16725,8 @@
1614216725 private /*static*/ boolean firstime;
1614316726 private /*static*/ cVector newView = new cVector();
1614416727 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16728
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16729
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1614516730 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1614616731 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1614716732 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16154,29 +16739,67 @@
1615416739 {
1615516740 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1615616741
16742
+ int usedsuf = 0;
16743
+
1615716744 for (int i = 0; i < suffixes.length; i++)
1615816745 {
16159
- String resourceName = basename + suffixes[i] + "." + suffix;
16160
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16161
- mipmapped,
16162
- FileUtil.getFileSuffix(resourceName));
16163
- if (data == null)
16746
+ String[] suffixe = suffixes;
16747
+ String[] fallback = suffixes2;
16748
+ String[] fallfallback = suffixes3;
16749
+
16750
+ for (int c=usedsuf; --c>=0;)
1616416751 {
16165
- throw new IOException("Unable to load texture " + resourceName);
16752
+// String[] temp = suffixe;
16753
+// suffixe = fallback;
16754
+// fallback = fallfallback;
16755
+// fallfallback = temp;
1616616756 }
16757
+
16758
+ String resourceName = basename + suffixe[i] + "." + suffix;
16759
+ TextureData data;
16760
+
16761
+ try
16762
+ {
16763
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16764
+ mipmapped,
16765
+ FileUtil.getFileSuffix(resourceName));
16766
+ }
16767
+ catch (Exception e)
16768
+ {
16769
+ try
16770
+ {
16771
+ resourceName = basename + fallback[i] + "." + suffix;
16772
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16773
+ mipmapped,
16774
+ FileUtil.getFileSuffix(resourceName));
16775
+ }
16776
+ catch (Exception e2)
16777
+ {
16778
+ resourceName = basename + fallfallback[i] + "." + suffix;
16779
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16780
+ mipmapped,
16781
+ FileUtil.getFileSuffix(resourceName));
16782
+ }
16783
+ }
16784
+
1616716785 //System.out.println("Target = " + targets[i]);
1616816786 cubemap.updateImage(data, targets[i]);
1616916787 }
1617016788
1617116789 return cubemap;
1617216790 }
16791
+
1617316792 int bigsphere = -1;
1617416793
1617516794 float BGcolor = 0.5f;
1617616795
16177
- private void DrawSkyBox(GL gl)
16796
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16797
+
16798
+ private void DrawSkyBox(GL gl, float ratio)
1617816799 {
16179
- if (envyoff || cubemap == null)
16800
+ if (//envyoff ||
16801
+ WIREFRAME ||
16802
+ cubemap == null)
1618016803 {
1618116804 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1618216805 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16191,7 +16814,17 @@
1619116814 // Compensates for ExaminerViewer's modification of modelview matrix
1619216815 gl.glMatrixMode(GL.GL_MODELVIEW);
1619316816 gl.glLoadIdentity();
16817
+ gl.glScalef(1,ratio,1);
1619416818
16819
+// colorV[0] = 2;
16820
+// colorV[1] = 2;
16821
+// colorV[2] = 2;
16822
+// colorV[3] = 1;
16823
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16824
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16825
+//
16826
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16827
+
1619516828 //gl.glActiveTexture(GL.GL_TEXTURE1);
1619616829 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1619716830
....@@ -16223,6 +16856,7 @@
1622316856 {
1622416857 gl.glScalef(1.0f, -1.0f, 1.0f);
1622516858 }
16859
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1622616860 gl.glMultMatrixd(viewrot_1, 0);
1622716861 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1622816862 //viewer.updateInverseRotation(gl);
....@@ -16263,7 +16897,8 @@
1626316897 gl.glDisable(GL.GL_TEXTURE_GEN_R);
1626416898
1626516899 cubemap.disable();
16266
- ////cubemap.unbind();
16900
+ //cubemap.dispose();
16901
+
1626716902 if (CULLFACE)
1626816903 {
1626916904 gl.glEnable(gl.GL_CULL_FACE);
....@@ -16319,7 +16954,7 @@
1631916954 gl.glScalef(1.0f, -1.0f, 1.0f);
1632016955 }
1632116956
16322
- gl.glNormal3f(0.0f, 0.0f, 1.0f);
16957
+ SetGLNormal(gl, 0.0f, 0.0f, 1.0f);
1632316958
1632416959 float step = 2; // 0.1666f; //0.25f;
1632516960 float stepv = 2; // step * 1652 / 998;
....@@ -16363,16 +16998,16 @@
1636316998 cStatic.objectstack[materialdepth++] = checker;
1636416999 //System.out.println("material " + material);
1636517000 //Applet3D.tracein(this, selected);
16366
- vector2buffer = checker.projectedVertices;
17001
+ //vector2buffer = checker.projectedVertices;
1636717002
1636817003 //checker.GetMaterial().Draw(this, false); // true);
16369
- DrawMaterial(checker.GetMaterial(), false); // true);
17004
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1637017005
1637117006 materialdepth -= 1;
1637217007 if (materialdepth > 0)
1637317008 {
16374
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16375
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
17009
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
17010
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1637617011 }
1637717012 //checker.GetMaterial().opacity = 1f;
1637817013 ////checker.GetMaterial().ambient = 1f;
....@@ -16458,6 +17093,14 @@
1645817093 }
1645917094 }
1646017095
17096
+ private Object3D GetFolder()
17097
+ {
17098
+ Object3D folder = object.GetWindow().copy;
17099
+ if (object.GetWindow().copy.selection.Size() > 0)
17100
+ folder = object.GetWindow().copy.selection.elementAt(0);
17101
+ return folder;
17102
+ }
17103
+
1646117104 class SelectBuffer implements GLEventListener
1646217105 {
1646317106
....@@ -16473,7 +17116,7 @@
1647317116 //new Exception().printStackTrace();
1647417117 System.out.println("select buffer init");
1647517118 // Use debug pipeline
16476
- drawable.setGL(new DebugGL(drawable.getGL()));
17119
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1647717120
1647817121 GL gl = drawable.getGL();
1647917122
....@@ -16537,6 +17180,17 @@
1653717180
1653817181 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1653917182
17183
+ if (PAINTMODE)
17184
+ {
17185
+ if (object.GetWindow().copy.selection.Size() > 0)
17186
+ {
17187
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17188
+
17189
+ // Make what you paint not selectable.
17190
+ paintobj.ResetSelectable();
17191
+ }
17192
+ }
17193
+
1654017194 //int tmp = selection_view;
1654117195 //selection_view = -1;
1654217196 int temp = DrawMode();
....@@ -16548,6 +17202,17 @@
1654817202 // temp = DEFAULT; // patch for selection debug
1654917203 Globals.drawMode = temp; // WARNING
1655017204
17205
+ if (PAINTMODE)
17206
+ {
17207
+ if (object.GetWindow().copy.selection.Size() > 0)
17208
+ {
17209
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17210
+
17211
+ // Revert.
17212
+ paintobj.RestoreSelectable();
17213
+ }
17214
+ }
17215
+
1655117216 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1655217217
1655317218 // trying different ways of getting the depth info over
....@@ -16595,6 +17260,8 @@
1659517260 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1659617261 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1659717262 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
17263
+
17264
+ CreateSelectedPoint();
1659817265
1659917266 // Will fit the mesh !!!
1660017267 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16649,29 +17316,31 @@
1664917316 }
1665017317
1665117318 if (!movingcamera && !PAINTMODE)
16652
- object.editWindow.ScreenFitPoint(); // fev 2014
17319
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1665317320
16654
- if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17321
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1665517322 {
16656
- Object3D paintobj = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17323
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1665717324
16658
- Object3D group = new Object3D("inst" + paintcount++);
17325
+ if (object.GetWindow().copy.selection.Size() > 0)
17326
+ {
17327
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1665917328
16660
- group.CreateMaterial(); // use a void leaf to select instances
16661
-
16662
- group.add(paintobj); // link
16663
-
16664
- object.editWindow.SnapObject(group);
16665
-
16666
- Object3D folder = object.editWindow.copy;
16667
-
16668
- if (object.editWindow.copy.selection.Size() > 0)
16669
- folder = object.editWindow.copy.selection.elementAt(0);
16670
-
16671
- folder.add(group);
16672
-
16673
- object.editWindow.ResetModel();
16674
- object.editWindow.refreshContents();
17329
+ Object3D inst = new Object3D("inst" + paintcount++);
17330
+
17331
+ inst.CreateMaterial(); // use a void leaf to select instances
17332
+
17333
+ inst.add(paintobj); // link
17334
+
17335
+ object.GetWindow().SnapObject(inst);
17336
+
17337
+ Object3D folder = paintFolder; // GetFolder();
17338
+
17339
+ folder.add(inst);
17340
+
17341
+ object.GetWindow().ResetModel();
17342
+ object.GetWindow().refreshContents();
17343
+ }
1667517344 }
1667617345 else
1667717346 paintcount = 0;
....@@ -16710,6 +17379,11 @@
1671017379 //System.out.println("objects[color] = " + objects[color]);
1671117380 //objects[color].Select();
1671217381 indexcount = 0;
17382
+ ObjEditor window = object.GetWindow();
17383
+ if (window != null && deselect)
17384
+ {
17385
+ window.Select(null, deselect, true);
17386
+ }
1671317387 object.Select(color, deselect);
1671417388 }
1671517389
....@@ -16760,6 +17434,7 @@
1676017434
1676117435 public void init(GLAutoDrawable drawable)
1676217436 {
17437
+ if (Globals.DEBUG)
1676317438 System.out.println("shadow buffer init");
1676417439
1676517440 GL gl = drawable.getGL();
....@@ -16988,10 +17663,14 @@
1698817663 gl.glFlush();
1698917664
1699017665 /**/
16991
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17666
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1699217667
16993
- float[] pixels = occlusionsizebuffer.array();
17668
+ float[] depths = occlusiondepthbuffer.array();
1699417669
17670
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17671
+
17672
+ int[] pixels = selectsizebuffer.array();
17673
+
1699517674 double r = 0, g = 0, b = 0;
1699617675
1699717676 double count = 0;
....@@ -17002,7 +17681,7 @@
1700217681
1700317682 double FACTOR = 1;
1700417683
17005
- for (int i = 0; i < pixels.length; i++)
17684
+ for (int i = 0; i < depths.length; i++)
1700617685 {
1700717686 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1700817687 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -17085,7 +17764,7 @@
1708517764
1708617765 double scale = ray.z; // 1; // cos
1708717766
17088
- float depth = pixels[newindex];
17767
+ float depth = depths[newindex];
1708917768
1709017769 /*
1709117770 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -17235,23 +17914,15 @@
1723517914 int AAbuffersize = 0;
1723617915
1723717916 //double[] selectedpoint = new double[3];
17238
- static Superellipsoid selectedpoint = new Superellipsoid();
17917
+ static Superellipsoid selectedpoint;
1723917918 static Sphere previousselectedpoint = null;
17240
- static Sphere debugpointG = new Sphere();
17241
- static Sphere debugpointP = new Sphere();
17242
- static Sphere debugpointC = new Sphere();
17243
- static Sphere debugpointR = new Sphere();
17919
+ static Sphere debugpointG;
17920
+ static Sphere debugpointP;
17921
+ static Sphere debugpointC;
17922
+ static Sphere debugpointR;
1724417923
1724517924 static Sphere debugpoints[] = new Sphere[8];
1724617925
17247
- static
17248
- {
17249
- for (int i=0; i<8; i++)
17250
- {
17251
- debugpoints[i] = new Sphere();
17252
- }
17253
- }
17254
-
1725517926 static void InitPoints(float radius)
1725617927 {
1725717928 for (int i=0; i<8; i++)
....@@ -17290,11 +17961,14 @@
1729017961 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1729117962 static IntBuffer bigAAbuffer;
1729217963 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
17293
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17964
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1729417965 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1729517966 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1729617967 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17297
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17968
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17969
+
17970
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17971
+
1729817972 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1729917973 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1730017974 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();