Normand Briere
2019-08-13 c67de8aca04d988179191ccb52461af00125920e
CameraPane.java
....@@ -18,7 +18,10 @@
1818 import javax.imageio.ImageIO;
1919 import javax.imageio.ImageWriteParam;
2020 import javax.imageio.ImageWriter;
21
+import javax.imageio.ImageReadParam;
22
+import javax.imageio.ImageReader;
2123 import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
24
+import javax.imageio.stream.ImageInputStream;
2225 import javax.imageio.stream.ImageOutputStream;
2326 import javax.imageio.ImageWriteParam;
2427
....@@ -30,6 +33,7 @@
3033 import java.nio.*;
3134
3235 import gleem.linalg.Mat4f;
36
+import javax.imageio.ImageTypeSpecifier;
3337
3438 class CameraPane extends GLCanvas implements iCameraPane, Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener
3539 {
....@@ -44,6 +48,39 @@
4448 static boolean ABORTED = false;
4549
4650 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
+ }
4784
4885 /*static*/ private boolean CULLFACE = false; // true;
4986 /*static*/ boolean NEAREST = false; // true;
....@@ -60,7 +97,7 @@
6097 //boolean REDUCETEXTURE = true;
6198 boolean CACHETEXTURE = true;
6299 boolean CLEANCACHE = false; // true;
63
- boolean MIPMAP = false; // true;
100
+ boolean MIPMAP = false; // true; // never works...
64101 boolean COMPRESSTEXTURE = false;
65102 boolean KOMPACTTEXTURE = false; // true;
66103 boolean RESIZETEXTURE = false;
....@@ -73,7 +110,9 @@
73110 //private Mat4f spotlightTransform = new Mat4f();
74111 //private Mat4f spotlightInverseTransform = new Mat4f();
75112 static GLContext glcontext = null;
76
- /*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;
77116 boolean reverseUP = false;
78117 static boolean frozen = false;
79118 boolean enablebackspace = false; // patch for back buffer refresh
....@@ -136,7 +175,7 @@
136175 static boolean doublesided = false; // true; // reversed normals are awful for conformance
137176 boolean anisotropy = true;
138177 boolean softshadow = true; // slower but better false;
139
- boolean opacityhalo = false;
178
+ boolean opacityhalo = false; // reverse the halo effect (e.g. glass)
140179
141180 boolean macromode = false;
142181
....@@ -150,6 +189,19 @@
150189 }
151190
152191 private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
192
+
193
+ public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException
194
+ {
195
+ try
196
+ {
197
+ return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
198
+ } catch (IOException e)
199
+ {
200
+ System.out.println("NAME = " + name);
201
+ e.printStackTrace(); // throw new RuntimeException(e);
202
+ return null;
203
+ }
204
+ }
153205
154206 void SetAsGLRenderer(boolean b)
155207 {
....@@ -169,7 +221,8 @@
169221
170222 SetCamera(cam);
171223
172
- SetLight(new Camera(new cVector(10, 10, -20)));
224
+ // Warning: not used.
225
+ SetLight(new Camera(new cVector(15, 10, -20)));
173226
174227 object = o;
175228
....@@ -326,7 +379,7 @@
326379 cStatic.objectstack[materialdepth++] = obj;
327380 //System.out.println("material " + material);
328381 //Applet3D.tracein(this, selected);
329
- display.vector2buffer = obj.projectedVertices;
382
+ //display.vector2buffer = obj.projectedVertices;
330383 if (obj instanceof Camera)
331384 {
332385 display.options1[0] = material.shift;
....@@ -335,14 +388,28 @@
335388 display.options1[2] = material.shadowbias;
336389 display.options1[3] = material.aniso;
337390 display.options1[4] = material.anisoV;
391
+// System.out.println("display.options1[0] " + display.options1[0]);
392
+// System.out.println("display.options1[1] " + display.options1[1]);
393
+// System.out.println("display.options1[2] " + display.options1[2]);
394
+// System.out.println("display.options1[3] " + display.options1[3]);
395
+// System.out.println("display.options1[4] " + display.options1[4]);
338396 display.options2[0] = material.opacity;
339397 display.options2[1] = material.diffuse;
340398 display.options2[2] = material.factor;
399
+// System.out.println("display.options2[0] " + display.options2[0]);
400
+// System.out.println("display.options2[1] " + display.options2[1]);
401
+// System.out.println("display.options2[2] " + display.options2[2]);
341402
342403 cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
404
+// System.out.println("display.options3[0] " + display.options3[0]);
405
+// System.out.println("display.options3[1] " + display.options3[1]);
406
+// System.out.println("display.options3[2] " + display.options3[2]);
343407 display.options4[0] = material.cameralight/0.2f;
344408 display.options4[1] = material.subsurface;
345409 display.options4[2] = material.sheen;
410
+// System.out.println("display.options4[0] " + display.options4[0]);
411
+// System.out.println("display.options4[1] " + display.options4[1]);
412
+// System.out.println("display.options4[2] " + display.options4[2]);
346413
347414 // if (display.CURRENTANTIALIAS > 0)
348415 // display.options3[3] /= 4;
....@@ -358,7 +425,7 @@
358425 /**/
359426 } else
360427 {
361
- DrawMaterial(material, selected);
428
+ DrawMaterial(material, selected, obj.projectedVertices);
362429 }
363430 } else
364431 {
....@@ -382,8 +449,8 @@
382449 cStatic.objectstack[materialdepth++] = obj;
383450 //System.out.println("material " + material);
384451 //Applet3D.tracein("selected ", selected);
385
- display.vector2buffer = obj.projectedVertices;
386
- display.DrawMaterial(material, selected);
452
+ //display.vector2buffer = obj.projectedVertices;
453
+ display.DrawMaterial(material, selected, obj.projectedVertices);
387454 }
388455 }
389456
....@@ -400,8 +467,8 @@
400467 materialdepth -= 1;
401468 if (materialdepth > 0)
402469 {
403
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
404
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
470
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
471
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
405472 }
406473 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
407474 } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
....@@ -421,8 +488,8 @@
421488 materialdepth -= 1;
422489 if (materialdepth > 0)
423490 {
424
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
425
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
491
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
492
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
426493 }
427494 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
428495 //else
....@@ -1433,6 +1500,8 @@
14331500 gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
14341501 }
14351502
1503
+ float[] colorV = new float[4];
1504
+
14361505 void SetColor(Object3D obj, Vertex p0)
14371506 {
14381507 CameraPane display = this;
....@@ -1500,8 +1569,6 @@
15001569 {
15011570 return;
15021571 }
1503
-
1504
- float[] colorV = new float[3];
15051572
15061573 if (false) // marked)
15071574 {
....@@ -1610,7 +1677,7 @@
16101677 // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
16111678 }
16121679
1613
- void DrawMaterial(cMaterial material, boolean selected)
1680
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
16141681 {
16151682 CameraPane display = this;
16161683 //new Exception().printStackTrace();
....@@ -1645,7 +1712,7 @@
16451712 colorV[0] = display.modelParams0[0] * material.diffuse;
16461713 colorV[1] = display.modelParams0[1] * material.diffuse;
16471714 colorV[2] = display.modelParams0[2] * material.diffuse;
1648
- colorV[3] = material.opacity;
1715
+ colorV[3] = 1; // material.opacity;
16491716
16501717 gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
16511718 //System.out.println("Opacity = " + opacity);
....@@ -1753,9 +1820,9 @@
17531820 display.modelParams7[2] = 0;
17541821 display.modelParams7[3] = 0;
17551822
1756
- display.modelParams6[0] = 100; // criss de bug de bump
1823
+ //display.modelParams6[0] = 100; // criss de bug de bump
17571824
1758
- Object3D.cVector2[] extparams = display.vector2buffer;
1825
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
17591826 if (extparams != null && extparams.length > 0 && extparams[0] != null)
17601827 {
17611828 display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
....@@ -2051,7 +2118,7 @@
20512118 //System.err.println("Oeil on");
20522119 OEIL = true;
20532120 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2054
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2121
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
20552122 //pingthread.StepToTarget(true);
20562123 }
20572124
....@@ -2284,10 +2351,17 @@
22842351 HANDLES ^= true;
22852352 }
22862353
2354
+ Object3D paintFolder;
2355
+
22872356 void TogglePaint()
22882357 {
22892358 PAINTMODE ^= true;
22902359 paintcount = 0;
2360
+
2361
+ if (PAINTMODE)
2362
+ {
2363
+ paintFolder = GetFolder();
2364
+ }
22912365 }
22922366
22932367 void SwapCamera(int a, int b)
....@@ -2384,6 +2458,21 @@
23842458 return currentGL;
23852459 }
23862460
2461
+ static private BufferedImage CreateBim(TextureData texturedata)
2462
+ {
2463
+ Grafreed.Assert(texturedata != null);
2464
+
2465
+ int width = texturedata.getWidth();
2466
+ int height = texturedata.getHeight();
2467
+
2468
+ Buffer buffer = texturedata.getBuffer();
2469
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2470
+
2471
+ byte[] bytes = bytebuf.array();
2472
+
2473
+ return CreateBim(bytes, width, height);
2474
+ }
2475
+
23872476 /**/
23882477 class CacheTexture
23892478 {
....@@ -2392,28 +2481,31 @@
23922481
23932482 int resolution;
23942483
2395
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2484
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
23962485 {
2397
- texture = tex;
2486
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2487
+ texturedata = texdata;
23982488 resolution = res;
23992489 }
24002490 }
24012491 /**/
24022492
24032493 // TEXTURE static Texture texture;
2404
- static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures
2405
- = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>();
2406
- static public java.util.Hashtable<String, String> usedtextures = new java.util.Hashtable<String, String>();
2494
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2495
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2496
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2497
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2498
+
24072499 int pigmentdepth = 0;
24082500 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
24092501 int bumpdepth = 0;
24102502 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
24112503 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
24122504 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2413
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2505
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
24142506 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
24152507
2416
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2508
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
24172509 {
24182510 TextureData texturedata = null;
24192511
....@@ -2432,13 +2524,34 @@
24322524 if (bump)
24332525 texturedata = ConvertBump(texturedata, false);
24342526
2435
- com.sun.opengl.util.texture.Texture texture =
2436
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2527
+// com.sun.opengl.util.texture.Texture texture =
2528
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
24372529
2438
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2439
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
2530
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2531
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
24402532
2441
- return texture;
2533
+ return texturedata;
2534
+ }
2535
+
2536
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2537
+ {
2538
+ TextureData texturedata = null;
2539
+
2540
+ try
2541
+ {
2542
+ texturedata =
2543
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2544
+ bim,
2545
+ true);
2546
+ } catch (Exception e)
2547
+ {
2548
+ throw new javax.media.opengl.GLException(e);
2549
+ }
2550
+
2551
+ if (bump)
2552
+ texturedata = ConvertBump(texturedata, false);
2553
+
2554
+ return texturedata;
24422555 }
24432556
24442557 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3511,6 +3624,8 @@
35113624
35123625 System.out.println("LOADING TEXTURE : " + name);
35133626
3627
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3628
+
35143629 //
35153630 if (false) // compressbit > 0)
35163631 {
....@@ -7909,7 +8024,7 @@
79098024 String pigment = Object3D.GetPigment(tex);
79108025 String bump = Object3D.GetBump(tex);
79118026
7912
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8027
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79138028 {
79148029 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79158030 // System.out.println("; bump = " + bump);
....@@ -7924,8 +8039,8 @@
79248039 pigment = null;
79258040 }
79268041
7927
- ReleaseTexture(bump, true);
7928
- ReleaseTexture(pigment, false);
8042
+ ReleaseTexture(tex, true);
8043
+ ReleaseTexture(tex, false);
79298044 }
79308045
79318046 public void ReleasePigmentTexture(cTexture tex) // INTERFACE
....@@ -7943,7 +8058,7 @@
79438058
79448059 String pigment = Object3D.GetPigment(tex);
79458060
7946
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8061
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79478062 {
79488063 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79498064 // System.out.println("; bump = " + bump);
....@@ -7954,7 +8069,7 @@
79548069 pigment = null;
79558070 }
79568071
7957
- ReleaseTexture(pigment, false);
8072
+ ReleaseTexture(tex, false);
79588073 }
79598074
79608075 public void ReleaseBumpTexture(cTexture tex) // INTERFACE
....@@ -7972,7 +8087,7 @@
79728087
79738088 String bump = Object3D.GetBump(tex);
79748089
7975
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8090
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79768091 {
79778092 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79788093 // System.out.println("; bump = " + bump);
....@@ -7983,10 +8098,10 @@
79838098 bump = null;
79848099 }
79858100
7986
- ReleaseTexture(bump, true);
8101
+ ReleaseTexture(tex, true);
79878102 }
79888103
7989
- void ReleaseTexture(String tex, boolean bump)
8104
+ void ReleaseTexture(cTexture tex, boolean bump)
79908105 {
79918106 if (// DrawMode() != 0 || /*tex == null ||*/
79928107 ambientOcclusion ) // || !textureon)
....@@ -7997,7 +8112,7 @@
79978112 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
79988113
79998114 if (tex != null)
8000
- texture = textures.get(tex);
8115
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
80018116
80028117 // //assert( texture != null );
80038118 // if (texture == null)
....@@ -8091,47 +8206,50 @@
80918206
80928207 /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
80938208 {
8094
- if (// DrawMode() != 0 || /*tex == null ||*/
8095
- ambientOcclusion ) // || !textureon)
8096
- {
8097
- return; // false;
8098
- }
8099
-
8100
- if (tex == null)
8101
- {
8102
- BindTexture(null,false,resolution);
8103
- BindTexture(null,true,resolution);
8104
- return;
8105
- }
8209
+// if (// DrawMode() != 0 || /*tex == null ||*/
8210
+// ambientOcclusion ) // || !textureon)
8211
+// {
8212
+// return; // false;
8213
+// }
8214
+//
8215
+// if (tex == null)
8216
+// {
8217
+// BindTexture(null,false,resolution);
8218
+// BindTexture(null,true,resolution);
8219
+// return;
8220
+// }
8221
+//
8222
+// String pigment = Object3D.GetPigment(tex);
8223
+// String bump = Object3D.GetBump(tex);
8224
+//
8225
+// usedtextures.add(pigment);
8226
+// usedtextures.add(bump);
8227
+//
8228
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8229
+// {
8230
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8231
+// // System.out.println("; bump = " + bump);
8232
+// }
8233
+//
8234
+// if (bump.equals(""))
8235
+// {
8236
+// bump = null;
8237
+// }
8238
+// if (pigment.equals(""))
8239
+// {
8240
+// pigment = null;
8241
+// }
8242
+//
8243
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8244
+// BindTexture(pigment, false, resolution);
8245
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8246
+// BindTexture(bump, true, resolution);
8247
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8248
+//
8249
+// return; // true;
81068250
8107
- String pigment = Object3D.GetPigment(tex);
8108
- String bump = Object3D.GetBump(tex);
8109
-
8110
- usedtextures.put(pigment, pigment);
8111
- usedtextures.put(bump, bump);
8112
-
8113
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8114
- {
8115
- // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8116
- // System.out.println("; bump = " + bump);
8117
- }
8118
-
8119
- if (bump.equals(""))
8120
- {
8121
- bump = null;
8122
- }
8123
- if (pigment.equals(""))
8124
- {
8125
- pigment = null;
8126
- }
8127
-
8128
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8129
- BindTexture(pigment, false, resolution);
8130
- GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8131
- BindTexture(bump, true, resolution);
8132
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8133
-
8134
- return; // true;
8251
+ BindPigmentTexture(tex, resolution);
8252
+ BindBumpTexture(tex, resolution);
81358253 }
81368254
81378255 /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8150,9 +8268,9 @@
81508268
81518269 String pigment = Object3D.GetPigment(tex);
81528270
8153
- usedtextures.put(pigment, pigment);
8271
+ usedtextures.add(tex);
81548272
8155
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8273
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
81568274 {
81578275 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
81588276 // System.out.println("; bump = " + bump);
....@@ -8164,7 +8282,7 @@
81648282 }
81658283
81668284 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8167
- BindTexture(pigment, false, resolution);
8285
+ BindTexture(tex, false, resolution);
81688286 }
81698287
81708288 /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8183,9 +8301,9 @@
81838301
81848302 String bump = Object3D.GetBump(tex);
81858303
8186
- usedtextures.put(bump, bump);
8304
+ usedtextures.add(tex);
81878305
8188
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8306
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
81898307 {
81908308 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
81918309 // System.out.println("; bump = " + bump);
....@@ -8197,7 +8315,7 @@
81978315 }
81988316
81998317 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8200
- BindTexture(bump, true, resolution);
8318
+ BindTexture(tex, true, resolution);
82018319 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
82028320 }
82038321
....@@ -8221,13 +8339,19 @@
82218339 return fileExists;
82228340 }
82238341
8224
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception
8342
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
82258343 {
8226
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8344
+ CacheTexture texturecache = null;
82278345
82288346 if (tex != null)
82298347 {
8230
- String texname = tex;
8348
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8349
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
8350
+
8351
+ if (texname.equals("") && texdata == null)
8352
+ {
8353
+ return null;
8354
+ }
82318355
82328356 String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
82338357
....@@ -8237,19 +8361,46 @@
82378361 // else
82388362 // if (!texname.startsWith("/"))
82398363 // texname = "/Users/nbriere/Textures/" + texname;
8240
- if (!FileExists(tex))
8364
+ if (!FileExists(texname) && !texname.startsWith("@"))
82418365 {
82428366 texname = fallbackTextureName;
82438367 }
82448368
82458369 if (CACHETEXTURE)
8246
- texture = textures.get(texname); // TEXTURE CACHE
8247
-
8248
- TextureData texturedata = null;
8249
-
8250
- if (texture == null || texture.resolution < resolution)
82518370 {
8252
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8371
+ if (texdata == null)
8372
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8373
+ else
8374
+ texturecache = bimtextures.get(texdata);
8375
+ }
8376
+
8377
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8378
+ {
8379
+ TextureData texturedata = null;
8380
+
8381
+ if (texdata != null && textureon)
8382
+ {
8383
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8384
+
8385
+ try
8386
+ {
8387
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8388
+ }
8389
+ catch (Exception e)
8390
+ {
8391
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8392
+ }
8393
+
8394
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8395
+ bimtextures.put(texdata, texturecache);
8396
+
8397
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8398
+
8399
+ //Object bim2 = CreateBim(texturecache.texturedata);
8400
+ //bim2 = bim;
8401
+ }
8402
+ else
8403
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
82538404 {
82548405 assert(!bump);
82558406 // if (bump)
....@@ -8260,19 +8411,23 @@
82608411 // }
82618412 // else
82628413 // {
8263
- texture = textures.get(tex);
8264
- if (texture == null)
8414
+ // texturecache = textures.get(texname); // suspicious
8415
+ if (texturecache == null)
82658416 {
8266
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8417
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
82678418 }
8419
+ else
8420
+ new Exception().printStackTrace();
82688421 // }
82698422 } else
8270
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8423
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
82718424 {
82728425 assert(bump);
8273
- texture = textures.get(tex);
8274
- if (texture == null)
8275
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8426
+ // texturecache = textures.get(texname); // suspicious
8427
+ if (texturecache == null)
8428
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8429
+ else
8430
+ new Exception().printStackTrace();
82768431 } else
82778432 {
82788433 //if (tex.equals("IMMORTAL"))
....@@ -8280,11 +8435,22 @@
82808435 // texture = GetResourceTexture("default.png");
82818436 //} else
82828437 //{
8283
- if (tex.equals("WHITE_NOISE"))
8438
+ if (texname.endsWith("WHITE_NOISE"))
82848439 {
8285
- texture = textures.get(tex);
8286
- if (texture == null)
8287
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8440
+ // texturecache = textures.get(texname); // suspicious
8441
+ if (texturecache == null)
8442
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8443
+ else
8444
+ new Exception().printStackTrace();
8445
+ } else
8446
+ {
8447
+ if (texname.startsWith("@"))
8448
+ {
8449
+ // texturecache = textures.get(texname); // suspicious
8450
+ if (texturecache == null)
8451
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8452
+ else
8453
+ new Exception().printStackTrace();
82888454 } else
82898455 {
82908456 if (textureon)
....@@ -8343,19 +8509,20 @@
83438509 if (texturedata == null)
83448510 throw new Exception();
83458511
8346
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8512
+ texturecache = new CacheTexture(texturedata,resolution);
83478513 //texture = GetTexture(tex, bump);
83488514 }
8515
+ }
83498516 }
83508517 //}
83518518 }
83528519
8353
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8520
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
83548521 {
83558522 //return false;
83568523
83578524 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8358
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8525
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
83598526 {
83608527 // String ext = "_highres";
83618528 // if (REDUCETEXTURE)
....@@ -8372,52 +8539,17 @@
83728539 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
83738540 if (!cachefile.exists())
83748541 {
8375
- // cache to disk
8376
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
8377
- //buffers[0].
8378
-
8379
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
8380
- int[] pixels = new int[bytebuf.capacity()/3];
8381
-
8382
- // squared size heuristic...
8383
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8542
+ //if (texturedata.getWidth() == texturedata.getHeight())
83848543 {
8385
- for (int i=pixels.length; --i>=0;)
8386
- {
8387
- int i3 = i*3;
8388
- pixels[i] = 0xFF;
8389
- pixels[i] <<= 8;
8390
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
8391
- pixels[i] <<= 8;
8392
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
8393
- pixels[i] <<= 8;
8394
- pixels[i] |= bytebuf.get(i3) & 0xFF;
8395
- }
8396
-
8397
- /*
8398
- int r=0,g=0,b=0,a=0;
8399
- for (int i=0; i<width; i++)
8400
- for (int j=0; j<height; j++)
8401
- {
8402
- int index = j*width+i;
8403
- int p = pixels[index];
8404
- a = ((p>>24) & 0xFF);
8405
- r = ((p>>16) & 0xFF);
8406
- g = ((p>>8) & 0xFF);
8407
- b = (p & 0xFF);
8408
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
8409
- }
8410
- /**/
8411
- int width = (int)Math.sqrt(pixels.length); // squared
8412
- int height = width;
8413
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
8414
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8544
+ BufferedImage rendImage = CreateBim(texturedata);
8545
+
84158546 ImageWriter writer = null;
84168547 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
84178548 if (iter.hasNext()) {
84188549 writer = (ImageWriter)iter.next();
84198550 }
8420
- float compressionQuality = 0.9f;
8551
+
8552
+ float compressionQuality = 0.85f;
84218553 try
84228554 {
84238555 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8434,18 +8566,20 @@
84348566 }
84358567 }
84368568 }
8437
-
8569
+
8570
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8571
+
84388572 //System.out.println("Texture = " + tex);
8439
- if (textures.containsKey(texname))
8573
+ if (textures.containsKey(tex))
84408574 {
8441
- CacheTexture thetex = textures.get(texname);
8575
+ CacheTexture thetex = textures.get(tex);
84428576 thetex.texture.disable();
84438577 thetex.texture.dispose();
8444
- textures.remove(texname);
8578
+ textures.remove(tex);
84458579 }
84468580
8447
- texture.texturedata = texturedata;
8448
- textures.put(texname, texture);
8581
+ //texture.texturedata = texturedata;
8582
+ textures.put(tex, texturecache);
84498583
84508584 // newtex = true;
84518585 }
....@@ -8461,10 +8595,44 @@
84618595 }
84628596 }
84638597
8464
- return texture;
8598
+ return texturecache;
84658599 }
84668600
8467
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution) throws Exception
8601
+ static void EmbedTextures(cTexture tex)
8602
+ {
8603
+ if (tex.pigmentdata == null)
8604
+ {
8605
+ //String texname = Object3D.GetPigment(tex);
8606
+
8607
+ CacheTexture texturecache = texturepigment.get(tex);
8608
+
8609
+ if (texturecache != null)
8610
+ {
8611
+ tex.pw = texturecache.texturedata.getWidth();
8612
+ tex.ph = texturecache.texturedata.getHeight();
8613
+ tex.pigmentdata = //CompressJPEG(CreateBim
8614
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8615
+ ;
8616
+ //, tex.pw, tex.ph), 0.5f);
8617
+ }
8618
+ }
8619
+
8620
+ if (tex.bumpdata == null)
8621
+ {
8622
+ //String texname = Object3D.GetBump(tex);
8623
+
8624
+ CacheTexture texturecache = texturebump.get(tex);
8625
+
8626
+ if (texturecache != null)
8627
+ {
8628
+ tex.bw = texturecache.texturedata.getWidth();
8629
+ tex.bh = texturecache.texturedata.getHeight();
8630
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8631
+ }
8632
+ }
8633
+ }
8634
+
8635
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
84688636 {
84698637 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
84708638
....@@ -8482,21 +8650,21 @@
84828650 return texture!=null?texture.texture:null;
84838651 }
84848652
8485
- public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution) throws Exception
8653
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
84868654 {
84878655 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
84888656
84898657 return texture!=null?texture.texturedata:null;
84908658 }
84918659
8492
- boolean BindTexture(String tex, boolean bump, int resolution) throws Exception
8660
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
84938661 {
84948662 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
84958663 {
84968664 return false;
84978665 }
84988666
8499
- boolean newtex = false;
8667
+ //boolean newtex = false;
85008668
85018669 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
85028670
....@@ -8528,9 +8696,75 @@
85288696 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
85298697 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
85308698
8531
- return newtex;
8699
+ return true; // Warning: not used.
85328700 }
85338701
8702
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8703
+ {
8704
+ try
8705
+ {
8706
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8707
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8708
+ ImageWriter writer = writers.next();
8709
+
8710
+ ImageWriteParam param = writer.getDefaultWriteParam();
8711
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8712
+ param.setCompressionQuality(quality);
8713
+
8714
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8715
+ writer.setOutput(ios);
8716
+ writer.write(null, new IIOImage(image, null, null), param);
8717
+
8718
+ byte[] data = baos.toByteArray();
8719
+ writer.dispose();
8720
+ return data;
8721
+ }
8722
+ catch (Exception e)
8723
+ {
8724
+ e.printStackTrace();
8725
+ return null;
8726
+ }
8727
+ }
8728
+
8729
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8730
+ {
8731
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8732
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8733
+ ImageReader reader = writers.next();
8734
+
8735
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8736
+
8737
+ ImageReadParam param = reader.getDefaultReadParam();
8738
+ param.setDestination(bim);
8739
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8740
+
8741
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8742
+ reader.setInput(ios);
8743
+ BufferedImage bim2 = reader.read(0, param);
8744
+ reader.dispose();
8745
+
8746
+// WritableRaster raster = bim2.getRaster();
8747
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8748
+// byte[] bytes = data.getData();
8749
+//
8750
+// int[] pixels = new int[bytes.length/3];
8751
+// for (int i=pixels.length; --i>=0;)
8752
+// {
8753
+// int i3 = i*3;
8754
+// pixels[i] = 0xFF;
8755
+// pixels[i] <<= 8;
8756
+// pixels[i] |= bytes[i3+2] & 0xFF;
8757
+// pixels[i] <<= 8;
8758
+// pixels[i] |= bytes[i3+1] & 0xFF;
8759
+// pixels[i] <<= 8;
8760
+// pixels[i] |= bytes[i3] & 0xFF;
8761
+// }
8762
+//
8763
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8764
+
8765
+ return bim;
8766
+ }
8767
+
85348768 ShadowBuffer shadowPBuf;
85358769 AntialiasBuffer antialiasPBuf;
85368770 int MAXSTACK;
....@@ -8547,10 +8781,12 @@
85478781
85488782 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
85498783 MAXSTACK = temp[0];
8550
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8784
+ if (Globals.DEBUG)
8785
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
85518786 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
85528787 MAXSTACK = temp[0];
8553
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8788
+ if (Globals.DEBUG)
8789
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
85548790
85558791 // Use debug pipeline
85568792 //drawable.setGL(new DebugGL(gl)); //
....@@ -8558,7 +8794,8 @@
85588794 gl = drawable.getGL(); //
85598795
85608796 GL gl3 = getGL();
8561
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8797
+ if (Globals.DEBUG)
8798
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
85628799
85638800
85648801 //float pos[] = { 100, 100, 100, 0 };
....@@ -8723,7 +8960,7 @@
87238960
87248961 if (cubemap == null)
87258962 {
8726
- LoadEnvy(5);
8963
+ //LoadEnvy(1);
87278964 }
87288965
87298966 //cubemap.enable();
....@@ -8999,6 +9236,8 @@
89999236
90009237 void LoadEnvy(int which)
90019238 {
9239
+ assert(false);
9240
+
90029241 String name;
90039242 String ext;
90049243
....@@ -9010,37 +9249,58 @@
90109249 cubemap = null;
90119250 return;
90129251 case 1:
9013
- name = "cubemaps/box_";
9014
- ext = "png";
9252
+ name = "cubemaps/rgb/";
9253
+ ext = "jpg";
90159254 reverseUP = false;
90169255 break;
90179256 case 2:
9018
- name = "cubemaps/uffizi_";
9019
- ext = "png";
9020
- break; // reverseUP = true; break;
9257
+ name = "cubemaps/uffizi/";
9258
+ ext = "jpg";
9259
+ reverseUP = false;
9260
+ break;
90219261 case 3:
9022
- name = "cubemaps/CloudyHills_";
9023
- ext = "tga";
9262
+ name = "cubemaps/CloudyHills/";
9263
+ ext = "jpg";
90249264 reverseUP = false;
90259265 break;
90269266 case 4:
9027
- name = "cubemaps/cornell_";
9267
+ name = "cubemaps/cornell/";
90289268 ext = "png";
90299269 reverseUP = false;
90309270 break;
9271
+ case 5:
9272
+ name = "cubemaps/skycube/";
9273
+ ext = "jpg";
9274
+ reverseUP = false;
9275
+ break;
9276
+ case 6:
9277
+ name = "cubemaps/SaintLazarusChurch3/";
9278
+ ext = "jpg";
9279
+ reverseUP = false;
9280
+ break;
9281
+ case 7:
9282
+ name = "cubemaps/Sodermalmsallen/";
9283
+ ext = "jpg";
9284
+ reverseUP = false;
9285
+ break;
9286
+ case 8:
9287
+ name = "cubemaps/Sodermalmsallen2/";
9288
+ ext = "jpg";
9289
+ reverseUP = false;
9290
+ break;
9291
+ case 9:
9292
+ name = "cubemaps/UnionSquare/";
9293
+ ext = "jpg";
9294
+ reverseUP = false;
9295
+ break;
90319296 default:
9032
- name = "cubemaps/rgb_";
9033
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9297
+ name = "cubemaps/box/";
9298
+ ext = "png"; /*mipmap = true;*/
9299
+ reverseUP = false;
90349300 break;
90359301 }
9036
-
9037
- try
9038
- {
9039
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
9040
- } catch (IOException e)
9041
- {
9042
- throw new RuntimeException(e);
9043
- }
9302
+
9303
+ LoadSkybox(name, ext, mipmap);
90449304 }
90459305
90469306 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -9072,8 +9332,12 @@
90729332 static double[] model = new double[16];
90739333 double[] camera2light = new double[16];
90749334 double[] light2camera = new double[16];
9075
- int newenvy = -1;
9076
- boolean envyoff = true; // false;
9335
+
9336
+ //int newenvy = -1;
9337
+ //boolean envyoff = false;
9338
+
9339
+ String loadedskyboxname;
9340
+
90779341 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
90789342 //float[] light0 = { 0,0,0 };
90799343 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9366,11 +9630,35 @@
93669630 jy8[3] = 0.5f;
93679631 }
93689632
9369
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9633
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
93709634 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
93719635 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
93729636 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
93739637
9638
+ void ResetOptions()
9639
+ {
9640
+ options1[0] = 100;
9641
+ options1[1] = 0.025f;
9642
+ options1[2] = 0.01f;
9643
+ options1[3] = 0;
9644
+ options1[4] = 0;
9645
+
9646
+ options2[0] = 0;
9647
+ options2[1] = 0.75f;
9648
+ options2[2] = 0;
9649
+ options2[3] = 0;
9650
+
9651
+ options3[0] = 1;
9652
+ options3[1] = 1;
9653
+ options3[2] = 1;
9654
+ options3[3] = 0;
9655
+
9656
+ options4[0] = 1;
9657
+ options4[1] = 0;
9658
+ options4[2] = 1;
9659
+ options4[3] = 0;
9660
+ }
9661
+
93749662 static int imagecount = 0; // movie generation
93759663
93769664 static int jitter = 0;
....@@ -9467,7 +9755,7 @@
94679755
94689756 if (renderCamera != lightCamera)
94699757 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9470
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
9758
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
94719759
94729760 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
94739761
....@@ -9483,7 +9771,7 @@
94839771
94849772 if (renderCamera != lightCamera)
94859773 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9486
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
9774
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
94879775
94889776 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
94899777
....@@ -9529,10 +9817,12 @@
95299817 rati = 1 / rati;
95309818 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
95319819 }
9532
- assert (newenvy == -1);
9820
+
9821
+ //assert (newenvy == -1);
9822
+
95339823 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
95349824 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9535
- DrawSkyBox(gl);
9825
+ DrawSkyBox(gl, (float)rati);
95369826 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
95379827 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
95389828 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10481,6 +10771,7 @@
1048110771 ANTIALIAS = 0;
1048210772 //System.out.println("RESTART");
1048310773 AAtimer.restart();
10774
+ Globals.TIMERRUNNING = true;
1048410775 }
1048510776 }
1048610777 }
....@@ -10548,7 +10839,8 @@
1054810839 ambientOcclusion = false;
1054910840 }
1055010841
10551
- if (Globals.lighttouched && DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
10842
+ if (//Globals.lighttouched &&
10843
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1055210844 {
1055310845 //if (RENDERSHADOW) // ?
1055410846 if (!IsFrozen())
....@@ -10567,7 +10859,7 @@
1056710859
1056810860 if (wait)
1056910861 {
10570
- Sleep(500);
10862
+ Sleep(200); // blocks everything
1057110863
1057210864 wait = false;
1057310865 }
....@@ -10682,7 +10974,7 @@
1068210974 // if (parentcam != renderCamera) // not a light
1068310975 if (cam != lightCamera)
1068410976 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10685
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
10977
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1068610978
1068710979 for (int j = 0; j < 4; j++)
1068810980 {
....@@ -10697,7 +10989,7 @@
1069710989 // if (parentcam != renderCamera) // not a light
1069810990 if (cam != lightCamera)
1069910991 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10700
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
10992
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1070110993
1070210994 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1070310995
....@@ -10783,13 +11075,41 @@
1078311075 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1078411076 }
1078511077
10786
- if (newenvy > -1)
11078
+// if (newenvy > -1)
11079
+// {
11080
+// LoadEnvy(newenvy);
11081
+// }
11082
+//
11083
+// newenvy = -1;
11084
+
11085
+ if (object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
1078711086 {
10788
- LoadEnvy(newenvy);
11087
+ if (cubemaprgb == null)
11088
+ {
11089
+ cubemaprgb = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11090
+ }
11091
+
11092
+ cubemap = cubemaprgb;
1078911093 }
10790
-
10791
- newenvy = -1;
10792
-
11094
+ else
11095
+ {
11096
+ if (object.skyboxname != null)
11097
+ {
11098
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11099
+ {
11100
+ cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11101
+ loadedskyboxname = object.skyboxname;
11102
+ }
11103
+ }
11104
+ else
11105
+ {
11106
+ cubemapcustom = null;
11107
+ loadedskyboxname = null;
11108
+ }
11109
+
11110
+ cubemap = cubemapcustom;
11111
+ }
11112
+
1079311113 ratio = ((double) getWidth()) / getHeight();
1079411114 //System.out.println("ratio = " + ratio);
1079511115
....@@ -10805,7 +11125,7 @@
1080511125
1080611126 if (!IsFrozen() && !ambientOcclusion)
1080711127 {
10808
- DrawSkyBox(gl);
11128
+ DrawSkyBox(gl, (float)ratio);
1080911129 }
1081011130
1081111131 //if (selection_view == -1)
....@@ -10988,9 +11308,9 @@
1098811308
1098911309 gl.glMatrixMode(GL.GL_MODELVIEW);
1099011310
10991
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10992
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10993
-//gl.glEnable(gl.GL_MULTISAMPLE);
11311
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11312
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11313
+gl.glEnable(gl.GL_MULTISAMPLE);
1099411314 } else
1099511315 {
1099611316 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -11001,7 +11321,7 @@
1100111321 //System.out.println("BLENDING ON");
1100211322 gl.glEnable(GL.GL_BLEND);
1100311323 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
11004
-
11324
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1100511325 gl.glMatrixMode(gl.GL_PROJECTION);
1100611326 gl.glLoadIdentity();
1100711327
....@@ -11091,7 +11411,7 @@
1109111411
1109211412 // if (cam != lightCamera)
1109311413 //for (int count = parentcam.GetTransformCount(); --count>=0;)
11094
- LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
11414
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1109511415 }
1109611416
1109711417 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -11250,7 +11570,7 @@
1125011570 }
1125111571 }
1125211572
11253
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11573
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1125411574 {
1125511575 //gl.glDepthFunc(GL.GL_LEQUAL);
1125611576 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11258,24 +11578,21 @@
1125811578
1125911579 boolean texon = textureon;
1126011580
11261
- if (RENDERPROGRAM > 0)
11262
- {
11263
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11264
- textureon = false;
11265
- }
11581
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11582
+ textureon = false;
11583
+
1126611584 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1126711585 //System.out.println("ALLO");
1126811586 gl.glColorMask(false, false, false, false);
1126911587 DrawObject(gl);
11270
- if (RENDERPROGRAM > 0)
11271
- {
11272
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11273
- textureon = texon;
11274
- }
11588
+
11589
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11590
+ textureon = texon;
11591
+
1127511592 gl.glColorMask(true, true, true, true);
1127611593
1127711594 gl.glDepthFunc(GL.GL_EQUAL);
11278
- //gl.glDepthMask(false);
11595
+ gl.glDepthMask(false);
1127911596 }
1128011597
1128111598 if (false) // DrawMode() == SHADOW)
....@@ -11458,7 +11775,7 @@
1145811775
1145911776 static boolean zoomonce = false;
1146011777
11461
- void CreateSelectedPoint()
11778
+ static void CreateSelectedPoint()
1146211779 {
1146311780 if (selectedpoint == null)
1146411781 {
....@@ -11478,13 +11795,16 @@
1147811795
1147911796 void DrawObject(GL gl, boolean draw)
1148011797 {
11798
+ // To clear camera values
11799
+ ResetOptions();
11800
+
1148111801 //System.out.println("DRAW OBJECT " + mouseDown);
1148211802 // DrawMode() = SELECTION;
1148311803 //GL gl = getGL();
1148411804 if ((TRACK || SHADOWTRACK) || zoomonce)
1148511805 {
1148611806 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11487
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11807
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1148811808 pingthread.StepToTarget(true); // true);
1148911809 // zoomonce = false;
1149011810 }
....@@ -11612,20 +11932,32 @@
1161211932 ReleaseTextures(DEFAULT_TEXTURES);
1161311933
1161411934 if (CLEANCACHE)
11615
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11935
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1161611936 {
11617
- String tex = e.nextElement();
11937
+ cTexture tex = e.nextElement();
1161811938
1161911939 // System.out.println("Texture --------- " + tex);
1162011940
11621
- if (tex.equals("WHITE_NOISE"))
11941
+ if (tex.equals("WHITE_NOISE:"))
1162211942 continue;
1162311943
11624
- if (!usedtextures.containsKey(tex))
11944
+ if (!usedtextures.contains(tex))
1162511945 {
11946
+ CacheTexture gettex = texturepigment.get(tex);
1162611947 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11627
- textures.get(tex).texture.dispose();
11628
- textures.remove(tex);
11948
+ if (gettex != null)
11949
+ {
11950
+ gettex.texture.dispose();
11951
+ texturepigment.remove(tex);
11952
+ }
11953
+
11954
+ gettex = texturebump.get(tex);
11955
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11956
+ if (gettex != null)
11957
+ {
11958
+ gettex.texture.dispose();
11959
+ texturebump.remove(tex);
11960
+ }
1162911961 }
1163011962 }
1163111963 }
....@@ -12045,7 +12377,7 @@
1204512377 for (int i = tp.size(); --i >= 0;)
1204612378 {
1204712379 //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12048
- LA.xformPos(light, tp.get(i).GlobalTransform(), light);
12380
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1204912381 }
1205012382
1205112383
....@@ -12153,8 +12485,76 @@
1215312485
1215412486 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1215512487
12156
- String program =
12488
+ String programmin =
12489
+ // Min shader
1215712490 "!!ARBfp1.0\n" +
12491
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12492
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12493
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12494
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12495
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12496
+ "PARAM light2cam0 = program.env[10];" +
12497
+ "PARAM light2cam1 = program.env[11];" +
12498
+ "PARAM light2cam2 = program.env[12];" +
12499
+ "TEMP temp;" +
12500
+ "TEMP light;" +
12501
+ "TEMP ndotl;" +
12502
+ "TEMP normal;" +
12503
+ "TEMP depth;" +
12504
+ "TEMP eye;" +
12505
+ "TEMP pos;" +
12506
+
12507
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12508
+ Normalize("normal") +
12509
+ "MOV light, state.light[0].position;" +
12510
+ "DP3 ndotl.x, light, normal;" +
12511
+
12512
+ // shadow
12513
+ "MOV pos, fragment.texcoord[1];" +
12514
+ "MOV temp, pos;" +
12515
+ ShadowTextureFetch("depth", "temp", "1") +
12516
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12517
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12518
+
12519
+ // No shadow when out of frustum
12520
+ //"SGE temp.y, depth.z, zero123.y;" +
12521
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12522
+
12523
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12524
+
12525
+ // Backlit
12526
+ "MOV pos.w, zero123.y;" +
12527
+ "DP4 eye.x, pos, light2cam0;" +
12528
+ "DP4 eye.y, pos, light2cam1;" +
12529
+ "DP4 eye.z, pos, light2cam2;" +
12530
+ Normalize("eye") +
12531
+
12532
+ "DP3 ndotl.y, -eye, normal;" +
12533
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12534
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12535
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12536
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12537
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12538
+
12539
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12540
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12541
+
12542
+ // Pigment
12543
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12544
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12545
+ "MUL temp, temp, ndotl.x;" +
12546
+
12547
+ "MUL temp, temp, zero123.z;" +
12548
+
12549
+ //"MUL temp, temp, ndotl.y;" +
12550
+
12551
+ "MOV temp.w, zero123.y;" + // reset alpha
12552
+ "MOV result.color, temp;" +
12553
+ "END";
12554
+
12555
+ String programmax =
12556
+ "!!ARBfp1.0\n" +
12557
+
1215812558 //"OPTION ARB_fragment_program_shadow;" +
1215912559 "PARAM light2cam0 = program.env[10];" +
1216012560 "PARAM light2cam1 = program.env[11];" +
....@@ -12269,8 +12669,7 @@
1226912669 "TEMP shininess;" +
1227012670 "\n" +
1227112671 "MOV texSamp, one;" +
12272
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12273
-
12672
+
1227412673 "MOV mapgrid.x, one2048th.x;" +
1227512674 "MOV temp, fragment.texcoord[1];" +
1227612675 /*
....@@ -12291,20 +12690,20 @@
1229112690 "MUL temp, floor, mapgrid.x;" +
1229212691 //"TEX depth0, temp, texture[1], 2D;" +
1229312692 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12294
- TextureFetch("depth0", "temp", "1") +
12693
+ ShadowTextureFetch("depth0", "temp", "1") +
1229512694 "") +
1229612695 "ADD temp.x, temp.x, mapgrid.x;" +
1229712696 //"TEX depth1, temp, texture[1], 2D;" +
1229812697 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12299
- TextureFetch("depth1", "temp", "1") +
12698
+ ShadowTextureFetch("depth1", "temp", "1") +
1230012699 "") +
1230112700 "ADD temp.y, temp.y, mapgrid.x;" +
1230212701 //"TEX depth2, temp, texture[1], 2D;" +
12303
- TextureFetch("depth2", "temp", "1") +
12702
+ ShadowTextureFetch("depth2", "temp", "1") +
1230412703 "SUB temp.x, temp.x, mapgrid.x;" +
1230512704 //"TEX depth3, temp, texture[1], 2D;" +
1230612705 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12307
- TextureFetch("depth3", "temp", "1") +
12706
+ ShadowTextureFetch("depth3", "temp", "1") +
1230812707 "") +
1230912708 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1231012709 //"MOV params, material;" +
....@@ -12675,10 +13074,10 @@
1267513074 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1267613075 "") +
1267713076
12678
- // display shadow only (bump == 0)
13077
+ // display shadow only (fakedepth == 0)
1267913078 "SUB temp.x, half.x, shadow.x;" +
1268013079 "MOV temp.y, -params5.z;" + // params6.x;" +
12681
- "SLT temp.z, temp.y, -one2048th.x;" +
13080
+ "SLT temp.z, temp.y, -c256i.x;" +
1268213081 "SUB temp.y, one.x, temp.z;" +
1268313082 "MUL temp.x, temp.x, temp.y;" +
1268413083 "KIL temp.x;" +
....@@ -13009,6 +13408,13 @@
1300913408 //once = true;
1301013409 }
1301113410
13411
+ String program = programmax;
13412
+
13413
+ if (Globals.MINSHADER)
13414
+ {
13415
+ program = programmin;
13416
+ }
13417
+
1301213418 System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1301313419 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1301413420 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
....@@ -13102,25 +13508,26 @@
1310213508 return out;
1310313509 }
1310413510
13105
- String TextureFetch(String dest, String src, String unit)
13511
+ // Also does frustum culling
13512
+ String ShadowTextureFetch(String dest, String src, String unit)
1310613513 {
1310713514 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1310813515 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1310913516 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13517
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13518
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1311013519 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13111
- "SLT " + src + ".z, " + src + ".x, one.x;" +
13112
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13113
- "SLT " + src + ".z, " + src + ".y, one.x;" +
13114
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13520
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13521
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1311513522 //"SWZ buffer, temp, w,w,w,w;";
13116
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13523
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1311713524 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1311813525 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1311913526 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13120
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13527
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1312113528
13122
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13123
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13529
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13530
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1312413531 }
1312513532
1312613533 String Shadow(String depth, String shadow)
....@@ -13167,7 +13574,7 @@
1316713574 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1316813575 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1316913576
13170
- // No shadow when out of frustrum
13577
+ // No shadow when out of frustum
1317113578 "SGE temp.x, " + depth + ".z, one.z;" +
1317213579 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1317313580 "";
....@@ -13315,7 +13722,8 @@
1331513722 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1331613723 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1331713724 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13318
- Object3D.cVector2[] vector2buffer;
13725
+
13726
+ //Object3D.cVector2[] vector2buffer;
1331913727
1332013728 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1332113729 // OUT : diff, spec
....@@ -13331,9 +13739,10 @@
1333113739 "DP3 " + dest + ".z," + "normals," + "eye;" +
1333213740 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1333313741 //"MOV " + dest + ".w," + "normal.z;" +
13334
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
13335
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13336
- //"MOV " + dest + ".z," + "params2.w;" +
13742
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13743
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13744
+
13745
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1333713746 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1333813747 "RCP " + dest + ".w," + dest + ".w;" +
1333913748 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13838,6 +14247,7 @@
1383814247 else
1383914248 if (evt.getSource() == AAtimer)
1384014249 {
14250
+ Globals.TIMERRUNNING = false;
1384114251 if (mouseDown)
1384214252 {
1384314253 //new Exception().printStackTrace();
....@@ -13897,7 +14307,7 @@
1389714307
1389814308 // fev 2014???
1389914309 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13900
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14310
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1390114311 pingthread.StepToTarget(true); // true);
1390214312 }
1390314313 // if (!LIVE)
....@@ -13912,6 +14322,7 @@
1391214322 return;
1391314323
1391414324 AAtimer.restart(); //
14325
+ Globals.TIMERRUNNING = true;
1391514326
1391614327 // waslive = LIVE;
1391714328 // LIVE = false;
....@@ -13961,14 +14372,15 @@
1396114372 drag = false;
1396214373 //System.out.println("Mouse DOWN");
1396314374 editObj = false;
13964
- ClickInfo info = new ClickInfo();
13965
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
13966
- info.pane = this;
13967
- info.camera = renderCamera;
13968
- info.x = x;
13969
- info.y = y;
13970
- info.modifiers = modifiersex;
13971
- editObj = object.doEditClick(info, 0);
14375
+ //ClickInfo info = new ClickInfo();
14376
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14377
+ object.clickInfo.pane = this;
14378
+ object.clickInfo.camera = renderCamera;
14379
+ object.clickInfo.x = x;
14380
+ object.clickInfo.y = y;
14381
+ object.clickInfo.modifiers = modifiersex;
14382
+ editObj = object.doEditClick(//info,
14383
+ 0);
1397214384 if (!editObj)
1397314385 {
1397414386 hasMarquee = true;
....@@ -14250,12 +14662,12 @@
1425014662 void GoDown(int mod)
1425114663 {
1425214664 MODIFIERS |= COMMAND;
14253
- /*
14665
+ /**/
1425414666 if((mod&SHIFT) == SHIFT)
14255
- manipCamera.RotatePosition(0, -speed);
14667
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
1425614668 else
14257
- manipCamera.BackForth(0, -speed*delta, getWidth());
14258
- */
14669
+ manipCamera.RotatePosition(0, -speed);
14670
+ /**/
1425914671 if ((mod & SHIFT) == SHIFT)
1426014672 {
1426114673 mouseMode = mouseMode; // VR??
....@@ -14271,12 +14683,12 @@
1427114683 void GoUp(int mod)
1427214684 {
1427314685 MODIFIERS |= COMMAND;
14274
- /*
14686
+ /**/
1427514687 if((mod&SHIFT) == SHIFT)
14276
- manipCamera.RotatePosition(0, speed);
14688
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
1427714689 else
14278
- manipCamera.BackForth(0, speed*delta, getWidth());
14279
- */
14690
+ manipCamera.RotatePosition(0, speed);
14691
+ /**/
1428014692 if ((mod & SHIFT) == SHIFT)
1428114693 {
1428214694 mouseMode = mouseMode;
....@@ -14292,12 +14704,12 @@
1429214704 void GoLeft(int mod)
1429314705 {
1429414706 MODIFIERS |= COMMAND;
14295
- /*
14707
+ /**/
1429614708 if((mod&SHIFT) == SHIFT)
14297
- manipCamera.RotatePosition(speed, 0);
14298
- else
1429914709 manipCamera.Translate(speed*delta, 0, getWidth());
14300
- */
14710
+ else
14711
+ manipCamera.RotatePosition(speed, 0);
14712
+ /**/
1430114713 if ((mod & SHIFT) == SHIFT)
1430214714 {
1430314715 mouseMode = mouseMode;
....@@ -14313,12 +14725,12 @@
1431314725 void GoRight(int mod)
1431414726 {
1431514727 MODIFIERS |= COMMAND;
14316
- /*
14728
+ /**/
1431714729 if((mod&SHIFT) == SHIFT)
14318
- manipCamera.RotatePosition(-speed, 0);
14319
- else
1432014730 manipCamera.Translate(-speed*delta, 0, getWidth());
14321
- */
14731
+ else
14732
+ manipCamera.RotatePosition(-speed, 0);
14733
+ /**/
1432214734 if ((mod & SHIFT) == SHIFT)
1432314735 {
1432414736 mouseMode = mouseMode;
....@@ -14368,14 +14780,16 @@
1436814780 if (editObj)
1436914781 {
1437014782 drag = true;
14371
- ClickInfo info = new ClickInfo();
14372
- info.bounds.setBounds(0, 0,
14783
+ //ClickInfo info = new ClickInfo();
14784
+ object.clickInfo.bounds.setBounds(0, 0,
1437314785 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14374
- info.pane = this;
14375
- info.camera = renderCamera;
14376
- info.x = x;
14377
- info.y = y;
14378
- object.editWindow.copy.doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
14786
+ object.clickInfo.pane = this;
14787
+ object.clickInfo.camera = renderCamera;
14788
+ object.clickInfo.x = x;
14789
+ object.clickInfo.y = y;
14790
+ object //.GetWindow().copy
14791
+ .doEditDrag(//info,
14792
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1437914793 } else
1438014794 {
1438114795 if (x < startX)
....@@ -14524,22 +14938,27 @@
1452414938 }
1452514939 }
1452614940
14941
+// ClickInfo clickInfo = new ClickInfo();
14942
+
1452714943 public void mouseMoved(MouseEvent e)
1452814944 {
1452914945 //System.out.println("mouseMoved: " + e);
1453014946 if (isRenderer)
1453114947 return;
1453214948
14533
- ClickInfo ci = new ClickInfo();
14534
- ci.x = e.getX();
14535
- ci.y = e.getY();
14536
- ci.modifiers = e.getModifiersEx();
14537
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14538
- ci.pane = this;
14539
- ci.camera = renderCamera;
14949
+ // Mouse cursor feedback
14950
+ object.clickInfo.x = e.getX();
14951
+ object.clickInfo.y = e.getY();
14952
+ object.clickInfo.modifiers = e.getModifiersEx();
14953
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14954
+ object.clickInfo.pane = this;
14955
+ object.clickInfo.camera = renderCamera;
1454014956 if (!isRenderer)
1454114957 {
14542
- if (object.editWindow.copy.doEditClick(ci, 0))
14958
+ //ObjEditor editWindow = object.editWindow;
14959
+ //Object3D copy = editWindow.copy;
14960
+ if (object.doEditClick(//clickInfo,
14961
+ 0))
1454314962 {
1454414963 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1454514964 } else
....@@ -14554,7 +14973,8 @@
1455414973 Globals.MOUSEDRAGGED = false;
1455514974
1455614975 movingcamera = false;
14557
- X = Y = 0;
14976
+ X = 0; // getBounds().width/2;
14977
+ Y = 0; // getBounds().height/2;
1455814978 //System.out.println("mouseReleased: " + e);
1455914979 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1456014980 }
....@@ -14810,7 +15230,8 @@
1481015230 // break;
1481115231 case 'T':
1481215232 CACHETEXTURE ^= true;
14813
- textures.clear();
15233
+ texturepigment.clear();
15234
+ texturebump.clear();
1481415235 // repaint();
1481515236 break;
1481615237 case 'Y':
....@@ -14895,7 +15316,9 @@
1489515316 case 'E' : COMPACT ^= true;
1489615317 repaint();
1489715318 break;
14898
- case 'W' : DEBUGHSB ^= true;
15319
+ case 'W' : // Wide Window (fullscreen)
15320
+ //DEBUGHSB ^= true;
15321
+ ObjEditor.theFrame.ToggleFullScreen();
1489915322 repaint();
1490015323 break;
1490115324 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14921,13 +15344,7 @@
1492115344 repaint();
1492215345 break;
1492315346 case 'l':
14924
- lightMode ^= true;
14925
- Globals.lighttouched = true;
14926
- manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
14927
- targetLookAt.set(manipCamera.lookAt);
14928
- repaint();
14929
- break;
14930
- case 'L':
15347
+ //case 'L':
1493115348 if (lightMode)
1493215349 {
1493315350 lightMode = false;
....@@ -14991,20 +15408,24 @@
1499115408 OCCLUSION_CULLING ^= true;
1499215409 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1499315410 break;
14994
- case '0': envyoff ^= true; repaint(); break;
15411
+ //case '0': envyoff ^= true; repaint(); break;
1499515412 case '1':
1499615413 case '2':
1499715414 case '3':
1499815415 case '4':
1499915416 case '5':
15000
- newenvy = Character.getNumericValue(key);
15001
- repaint();
15002
- break;
1500315417 case '6':
1500415418 case '7':
1500515419 case '8':
1500615420 case '9':
15007
- BGcolor = (key - '6')/3.f;
15421
+ if (true) // envyoff)
15422
+ {
15423
+ BGcolor = (key - '1')/8.f;
15424
+ }
15425
+ else
15426
+ {
15427
+ //newenvy = Character.getNumericValue(key);
15428
+ }
1500815429 repaint();
1500915430 break;
1501015431 case '!':
....@@ -15070,11 +15491,14 @@
1507015491 case '_':
1507115492 kompactbit = 5;
1507215493 break;
15073
- case '+':
15074
- kompactbit = 6;
15075
- break;
15494
+// case '+':
15495
+// kompactbit = 6;
15496
+// break;
1507615497 case ' ':
15077
- ObjEditor.theFrame.ToggleFullScreen();
15498
+ lightMode ^= true;
15499
+ Globals.lighttouched = true;
15500
+ manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
15501
+ targetLookAt.set(manipCamera.lookAt);
1507815502 repaint();
1507915503 break;
1508015504 //case '`' :
....@@ -15121,8 +15545,9 @@
1512115545 case DELETE:
1512215546 ClearSelection();
1512315547 break;
15124
- /*
1512515548 case '+':
15549
+
15550
+ /*
1512615551 //fontsize += 1;
1512715552 bbzoom *= 2;
1512815553 repaint();
....@@ -15139,17 +15564,17 @@
1513915564 case '=':
1514015565 IncDepth();
1514115566 //fontsize += 1;
15142
- object.editWindow.refreshContents(true);
15567
+ object.GetWindow().refreshContents(true);
1514315568 maskbit = 6;
1514415569 break;
1514515570 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1514615571 DecDepth();
1514715572 maskbit = 5;
1514815573 //if(fontsize > 1) fontsize -= 1;
15149
- if (object.editWindow == null)
15150
- new Exception().printStackTrace();
15151
- else
15152
- object.editWindow.refreshContents(true);
15574
+// if (object.editWindow == null)
15575
+// new Exception().printStackTrace();
15576
+// else
15577
+ object.GetWindow().refreshContents(true);
1515315578 break;
1515415579 case '{':
1515515580 manipCamera.shaper_fovy /= 1.1;
....@@ -15373,7 +15798,7 @@
1537315798 }
1537415799 */
1537515800
15376
- object.editWindow.EditSelection();
15801
+ object.GetWindow().EditSelection(false);
1537715802 }
1537815803
1537915804 void SelectParent()
....@@ -15390,10 +15815,10 @@
1539015815 {
1539115816 //selectees.remove(i);
1539215817 System.out.println("select parent of " + elem);
15393
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15818
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1539415819 } else
1539515820 {
15396
- group.editWindow.Select(elem.GetTreePath(), first, true);
15821
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1539715822 }
1539815823
1539915824 first = false;
....@@ -15435,12 +15860,12 @@
1543515860 for (int j = 0; j < group.children.size(); j++)
1543615861 {
1543715862 elem = (Object3D) group.children.elementAt(j);
15438
- object.editWindow.Select(elem.GetTreePath(), first, true);
15863
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1543915864 first = false;
1544015865 }
1544115866 } else
1544215867 {
15443
- object.editWindow.Select(elem.GetTreePath(), first, true);
15868
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1544415869 }
1544515870
1544615871 first = false;
....@@ -15451,21 +15876,21 @@
1545115876 {
1545215877 //Composite group = (Composite) object;
1545315878 Object3D group = object;
15454
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15879
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1545515880 }
1545615881
1545715882 void ResetTransform(int mask)
1545815883 {
1545915884 //Composite group = (Composite) object;
1546015885 Object3D group = object;
15461
- group.editWindow.ResetTransform(mask);
15886
+ group.GetWindow().ResetTransform(mask);
1546215887 }
1546315888
1546415889 void FlipTransform()
1546515890 {
1546615891 //Composite group = (Composite) object;
1546715892 Object3D group = object;
15468
- group.editWindow.FlipTransform();
15893
+ group.GetWindow().FlipTransform();
1546915894 // group.editWindow.ReduceMesh(true);
1547015895 }
1547115896
....@@ -15473,7 +15898,7 @@
1547315898 {
1547415899 //Composite group = (Composite) object;
1547515900 Object3D group = object;
15476
- group.editWindow.PrintMemory();
15901
+ group.GetWindow().PrintMemory();
1547715902 // group.editWindow.ReduceMesh(true);
1547815903 }
1547915904
....@@ -15481,7 +15906,7 @@
1548115906 {
1548215907 //Composite group = (Composite) object;
1548315908 Object3D group = object;
15484
- group.editWindow.ResetCentroid();
15909
+ group.GetWindow().ResetCentroid();
1548515910 }
1548615911
1548715912 void IncDepth()
....@@ -15563,8 +15988,6 @@
1556315988
1556415989 int width = getBounds().width;
1556515990 int height = getBounds().height;
15566
- ClickInfo info = new ClickInfo();
15567
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1556815991 //Image img = CreateImage(width, height);
1556915992 //System.out.println("width = " + width + "; height = " + height + "\n");
1557015993
....@@ -15641,48 +16064,77 @@
1564116064 }
1564216065 if (object != null && !hasMarquee)
1564316066 {
16067
+ if (object.clickInfo == null)
16068
+ object.clickInfo = new ClickInfo();
16069
+ ClickInfo info = object.clickInfo;
16070
+ //ClickInfo info = new ClickInfo();
16071
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16072
+
1564416073 if (isRenderer)
1564516074 {
15646
- info.flags++;
16075
+ object.clickInfo.flags++;
1564716076 double frameAspect = (double) width / (double) height;
1564816077 if (frameAspect > renderCamera.aspect)
1564916078 {
1565016079 int desired = (int) ((double) height * renderCamera.aspect);
15651
- info.bounds.width -= width - desired;
15652
- info.bounds.x += (width - desired) / 2;
16080
+ object.clickInfo.bounds.width -= width - desired;
16081
+ object.clickInfo.bounds.x += (width - desired) / 2;
1565316082 } else
1565416083 {
1565516084 int desired = (int) ((double) width / renderCamera.aspect);
15656
- info.bounds.height -= height - desired;
15657
- info.bounds.y += (height - desired) / 2;
16085
+ object.clickInfo.bounds.height -= height - desired;
16086
+ object.clickInfo.bounds.y += (height - desired) / 2;
1565816087 }
1565916088 }
15660
- info.g = gr;
15661
- info.camera = renderCamera;
16089
+
16090
+ object.clickInfo.g = gr;
16091
+ object.clickInfo.camera = renderCamera;
1566216092 /*
1566316093 // Memory intensive (brep.verticescopy)
1566416094 if (!(object instanceof Composite))
1566516095 object.draw(info, 0, false); // SLOW :
1566616096 */
15667
- if (!isRenderer)
16097
+ if (!isRenderer) // && drag)
1566816098 {
15669
- object.drawEditHandles(info, 0);
15670
-
15671
- if (drag && (X != 0 || Y != 0) && object.selection.Size() > 0)
16099
+ Grafreed.Assert(object != null);
16100
+ Grafreed.Assert(object.selection != null);
16101
+ if (object.selection.Size() > 0)
1567216102 {
15673
- switch (object.selection.get(0).hitSomething)
16103
+ int hitSomething = object.selection.get(0).hitSomething;
16104
+
16105
+ object.clickInfo.DX = 0;
16106
+ object.clickInfo.DY = 0;
16107
+ object.clickInfo.W = 1;
16108
+ if (hitSomething == Object3D.hitCenter)
1567416109 {
15675
- case Object3D.hitCenter: gr.setColor(Color.pink);
15676
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15677
- break;
15678
- case Object3D.hitRotate: gr.setColor(Color.yellow);
15679
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15680
- break;
15681
- case Object3D.hitScale: gr.setColor(Color.cyan);
15682
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15683
- break;
16110
+ info.DX = X;
16111
+ if (X != 0)
16112
+ info.DX -= info.bounds.width/2;
16113
+
16114
+ info.DY = Y;
16115
+ if (Y != 0)
16116
+ info.DY -= info.bounds.height/2;
1568416117 }
15685
-
16118
+
16119
+ object.drawEditHandles(//info,
16120
+ 0);
16121
+
16122
+ if (drag && (X != 0 || Y != 0))
16123
+ {
16124
+ switch (hitSomething)
16125
+ {
16126
+ case Object3D.hitCenter: gr.setColor(Color.pink);
16127
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16128
+ break;
16129
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16130
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16131
+ break;
16132
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16133
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16134
+ break;
16135
+ }
16136
+
16137
+ }
1568616138 }
1568716139 }
1568816140 }
....@@ -16164,6 +16616,8 @@
1616416616 private /*static*/ boolean firstime;
1616516617 private /*static*/ cVector newView = new cVector();
1616616618 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16619
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16620
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1616716621 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1616816622 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1616916623 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16176,29 +16630,67 @@
1617616630 {
1617716631 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1617816632
16633
+ int usedsuf = 0;
16634
+
1617916635 for (int i = 0; i < suffixes.length; i++)
1618016636 {
16181
- String resourceName = basename + suffixes[i] + "." + suffix;
16182
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16183
- mipmapped,
16184
- FileUtil.getFileSuffix(resourceName));
16185
- if (data == null)
16637
+ String[] suffixe = suffixes;
16638
+ String[] fallback = suffixes2;
16639
+ String[] fallfallback = suffixes3;
16640
+
16641
+ for (int c=usedsuf; --c>=0;)
1618616642 {
16187
- throw new IOException("Unable to load texture " + resourceName);
16643
+// String[] temp = suffixe;
16644
+// suffixe = fallback;
16645
+// fallback = fallfallback;
16646
+// fallfallback = temp;
1618816647 }
16648
+
16649
+ String resourceName = basename + suffixe[i] + "." + suffix;
16650
+ TextureData data;
16651
+
16652
+ try
16653
+ {
16654
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16655
+ mipmapped,
16656
+ FileUtil.getFileSuffix(resourceName));
16657
+ }
16658
+ catch (Exception e)
16659
+ {
16660
+ try
16661
+ {
16662
+ resourceName = basename + fallback[i] + "." + suffix;
16663
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16664
+ mipmapped,
16665
+ FileUtil.getFileSuffix(resourceName));
16666
+ }
16667
+ catch (Exception e2)
16668
+ {
16669
+ resourceName = basename + fallfallback[i] + "." + suffix;
16670
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16671
+ mipmapped,
16672
+ FileUtil.getFileSuffix(resourceName));
16673
+ }
16674
+ }
16675
+
1618916676 //System.out.println("Target = " + targets[i]);
1619016677 cubemap.updateImage(data, targets[i]);
1619116678 }
1619216679
1619316680 return cubemap;
1619416681 }
16682
+
1619516683 int bigsphere = -1;
1619616684
1619716685 float BGcolor = 0.5f;
1619816686
16199
- private void DrawSkyBox(GL gl)
16687
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16688
+
16689
+ private void DrawSkyBox(GL gl, float ratio)
1620016690 {
16201
- if (envyoff || cubemap == null)
16691
+ if (//envyoff ||
16692
+ WIREFRAME ||
16693
+ cubemap == null)
1620216694 {
1620316695 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1620416696 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16213,7 +16705,17 @@
1621316705 // Compensates for ExaminerViewer's modification of modelview matrix
1621416706 gl.glMatrixMode(GL.GL_MODELVIEW);
1621516707 gl.glLoadIdentity();
16708
+ gl.glScalef(1,ratio,1);
1621616709
16710
+// colorV[0] = 2;
16711
+// colorV[1] = 2;
16712
+// colorV[2] = 2;
16713
+// colorV[3] = 1;
16714
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16715
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16716
+//
16717
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16718
+
1621716719 //gl.glActiveTexture(GL.GL_TEXTURE1);
1621816720 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1621916721
....@@ -16245,6 +16747,7 @@
1624516747 {
1624616748 gl.glScalef(1.0f, -1.0f, 1.0f);
1624716749 }
16750
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1624816751 gl.glMultMatrixd(viewrot_1, 0);
1624916752 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1625016753 //viewer.updateInverseRotation(gl);
....@@ -16385,16 +16888,16 @@
1638516888 cStatic.objectstack[materialdepth++] = checker;
1638616889 //System.out.println("material " + material);
1638716890 //Applet3D.tracein(this, selected);
16388
- vector2buffer = checker.projectedVertices;
16891
+ //vector2buffer = checker.projectedVertices;
1638916892
1639016893 //checker.GetMaterial().Draw(this, false); // true);
16391
- DrawMaterial(checker.GetMaterial(), false); // true);
16894
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1639216895
1639316896 materialdepth -= 1;
1639416897 if (materialdepth > 0)
1639516898 {
16396
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16397
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
16899
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16900
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1639816901 }
1639916902 //checker.GetMaterial().opacity = 1f;
1640016903 ////checker.GetMaterial().ambient = 1f;
....@@ -16480,6 +16983,14 @@
1648016983 }
1648116984 }
1648216985
16986
+ private Object3D GetFolder()
16987
+ {
16988
+ Object3D folder = object.GetWindow().copy;
16989
+ if (object.GetWindow().copy.selection.Size() > 0)
16990
+ folder = object.GetWindow().copy.selection.elementAt(0);
16991
+ return folder;
16992
+ }
16993
+
1648316994 class SelectBuffer implements GLEventListener
1648416995 {
1648516996
....@@ -16495,7 +17006,7 @@
1649517006 //new Exception().printStackTrace();
1649617007 System.out.println("select buffer init");
1649717008 // Use debug pipeline
16498
- drawable.setGL(new DebugGL(drawable.getGL()));
17009
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1649917010
1650017011 GL gl = drawable.getGL();
1650117012
....@@ -16559,6 +17070,17 @@
1655917070
1656017071 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1656117072
17073
+ if (PAINTMODE)
17074
+ {
17075
+ if (object.GetWindow().copy.selection.Size() > 0)
17076
+ {
17077
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17078
+
17079
+ // Make what you paint not selectable.
17080
+ paintobj.ResetSelectable();
17081
+ }
17082
+ }
17083
+
1656217084 //int tmp = selection_view;
1656317085 //selection_view = -1;
1656417086 int temp = DrawMode();
....@@ -16570,6 +17092,17 @@
1657017092 // temp = DEFAULT; // patch for selection debug
1657117093 Globals.drawMode = temp; // WARNING
1657217094
17095
+ if (PAINTMODE)
17096
+ {
17097
+ if (object.GetWindow().copy.selection.Size() > 0)
17098
+ {
17099
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17100
+
17101
+ // Revert.
17102
+ paintobj.RestoreSelectable();
17103
+ }
17104
+ }
17105
+
1657317106 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1657417107
1657517108 // trying different ways of getting the depth info over
....@@ -16617,6 +17150,8 @@
1661717150 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1661817151 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1661917152 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
17153
+
17154
+ CreateSelectedPoint();
1662017155
1662117156 // Will fit the mesh !!!
1662217157 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16671,29 +17206,31 @@
1667117206 }
1667217207
1667317208 if (!movingcamera && !PAINTMODE)
16674
- object.editWindow.ScreenFitPoint(); // fev 2014
17209
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1667517210
16676
- if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17211
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1667717212 {
16678
- Object3D paintobj = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17213
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1667917214
16680
- Object3D group = new Object3D("inst" + paintcount++);
17215
+ if (object.GetWindow().copy.selection.Size() > 0)
17216
+ {
17217
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1668117218
16682
- group.CreateMaterial(); // use a void leaf to select instances
16683
-
16684
- group.add(paintobj); // link
16685
-
16686
- object.editWindow.SnapObject(group);
16687
-
16688
- Object3D folder = object.editWindow.copy;
16689
-
16690
- if (object.editWindow.copy.selection.Size() > 0)
16691
- folder = object.editWindow.copy.selection.elementAt(0);
16692
-
16693
- folder.add(group);
16694
-
16695
- object.editWindow.ResetModel();
16696
- object.editWindow.refreshContents();
17219
+ Object3D inst = new Object3D("inst" + paintcount++);
17220
+
17221
+ inst.CreateMaterial(); // use a void leaf to select instances
17222
+
17223
+ inst.add(paintobj); // link
17224
+
17225
+ object.GetWindow().SnapObject(inst);
17226
+
17227
+ Object3D folder = paintFolder; // GetFolder();
17228
+
17229
+ folder.add(inst);
17230
+
17231
+ object.GetWindow().ResetModel();
17232
+ object.GetWindow().refreshContents();
17233
+ }
1669717234 }
1669817235 else
1669917236 paintcount = 0;
....@@ -16732,6 +17269,11 @@
1673217269 //System.out.println("objects[color] = " + objects[color]);
1673317270 //objects[color].Select();
1673417271 indexcount = 0;
17272
+ ObjEditor window = object.GetWindow();
17273
+ if (window != null && deselect)
17274
+ {
17275
+ window.Select(null, deselect, true);
17276
+ }
1673517277 object.Select(color, deselect);
1673617278 }
1673717279
....@@ -17010,10 +17552,14 @@
1701017552 gl.glFlush();
1701117553
1701217554 /**/
17013
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17555
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1701417556
17015
- float[] pixels = occlusionsizebuffer.array();
17557
+ float[] depths = occlusiondepthbuffer.array();
1701617558
17559
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17560
+
17561
+ int[] pixels = selectsizebuffer.array();
17562
+
1701717563 double r = 0, g = 0, b = 0;
1701817564
1701917565 double count = 0;
....@@ -17024,7 +17570,7 @@
1702417570
1702517571 double FACTOR = 1;
1702617572
17027
- for (int i = 0; i < pixels.length; i++)
17573
+ for (int i = 0; i < depths.length; i++)
1702817574 {
1702917575 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1703017576 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -17107,7 +17653,7 @@
1710717653
1710817654 double scale = ray.z; // 1; // cos
1710917655
17110
- float depth = pixels[newindex];
17656
+ float depth = depths[newindex];
1711117657
1711217658 /*
1711317659 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -17304,11 +17850,14 @@
1730417850 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1730517851 static IntBuffer bigAAbuffer;
1730617852 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
17307
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17853
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1730817854 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1730917855 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1731017856 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17311
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17857
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17858
+
17859
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17860
+
1731217861 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1731317862 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1731417863 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();