Normand Briere
2019-08-12 8f1afe25ea8fc8801aab66331c32a50859a758c2
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;
....@@ -151,6 +187,18 @@
151187 }
152188
153189 private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
190
+
191
+ public void LoadSkybox(String name, String ext, boolean mipmap) throws GLException
192
+ {
193
+ try
194
+ {
195
+ cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
196
+ } catch (IOException e)
197
+ {
198
+ System.out.println("NAME = " + name);
199
+ e.printStackTrace(); // throw new RuntimeException(e);
200
+ }
201
+ }
154202
155203 void SetAsGLRenderer(boolean b)
156204 {
....@@ -170,7 +218,8 @@
170218
171219 SetCamera(cam);
172220
173
- SetLight(new Camera(new cVector(10, 10, -20)));
221
+ // Warning: not used.
222
+ SetLight(new Camera(new cVector(15, 10, -20)));
174223
175224 object = o;
176225
....@@ -327,7 +376,7 @@
327376 cStatic.objectstack[materialdepth++] = obj;
328377 //System.out.println("material " + material);
329378 //Applet3D.tracein(this, selected);
330
- display.vector2buffer = obj.projectedVertices;
379
+ //display.vector2buffer = obj.projectedVertices;
331380 if (obj instanceof Camera)
332381 {
333382 display.options1[0] = material.shift;
....@@ -336,14 +385,28 @@
336385 display.options1[2] = material.shadowbias;
337386 display.options1[3] = material.aniso;
338387 display.options1[4] = material.anisoV;
388
+// System.out.println("display.options1[0] " + display.options1[0]);
389
+// System.out.println("display.options1[1] " + display.options1[1]);
390
+// System.out.println("display.options1[2] " + display.options1[2]);
391
+// System.out.println("display.options1[3] " + display.options1[3]);
392
+// System.out.println("display.options1[4] " + display.options1[4]);
339393 display.options2[0] = material.opacity;
340394 display.options2[1] = material.diffuse;
341395 display.options2[2] = material.factor;
396
+// System.out.println("display.options2[0] " + display.options2[0]);
397
+// System.out.println("display.options2[1] " + display.options2[1]);
398
+// System.out.println("display.options2[2] " + display.options2[2]);
342399
343400 cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
401
+// System.out.println("display.options3[0] " + display.options3[0]);
402
+// System.out.println("display.options3[1] " + display.options3[1]);
403
+// System.out.println("display.options3[2] " + display.options3[2]);
344404 display.options4[0] = material.cameralight/0.2f;
345405 display.options4[1] = material.subsurface;
346406 display.options4[2] = material.sheen;
407
+// System.out.println("display.options4[0] " + display.options4[0]);
408
+// System.out.println("display.options4[1] " + display.options4[1]);
409
+// System.out.println("display.options4[2] " + display.options4[2]);
347410
348411 // if (display.CURRENTANTIALIAS > 0)
349412 // display.options3[3] /= 4;
....@@ -359,7 +422,7 @@
359422 /**/
360423 } else
361424 {
362
- DrawMaterial(material, selected);
425
+ DrawMaterial(material, selected, obj.projectedVertices);
363426 }
364427 } else
365428 {
....@@ -383,8 +446,8 @@
383446 cStatic.objectstack[materialdepth++] = obj;
384447 //System.out.println("material " + material);
385448 //Applet3D.tracein("selected ", selected);
386
- display.vector2buffer = obj.projectedVertices;
387
- display.DrawMaterial(material, selected);
449
+ //display.vector2buffer = obj.projectedVertices;
450
+ display.DrawMaterial(material, selected, obj.projectedVertices);
388451 }
389452 }
390453
....@@ -401,8 +464,8 @@
401464 materialdepth -= 1;
402465 if (materialdepth > 0)
403466 {
404
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
405
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
467
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
468
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
406469 }
407470 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
408471 } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
....@@ -422,8 +485,8 @@
422485 materialdepth -= 1;
423486 if (materialdepth > 0)
424487 {
425
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
426
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
488
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
489
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
427490 }
428491 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
429492 //else
....@@ -464,10 +527,12 @@
464527 if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
465528 {
466529 //gl.glBegin(gl.GL_TRIANGLES);
467
- boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0);
530
+ boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0)
531
+ // TEST LIVE NORMALS && !obj.dontselect
532
+ ;
468533 if (!hasnorm)
469534 {
470
- // System.out.println("FUCK!!");
535
+ // System.out.println("Mesh normal");
471536 LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
472537 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
473538 LA.vecCross(obj.v0, obj.v1, obj.v2);
....@@ -1192,10 +1257,12 @@
11921257 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
11931258 }
11941259 }
1260
+
11951261 if (flipV)
11961262 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
11971263 else
11981264 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1265
+
11991266 //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
12001267 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
12011268
....@@ -1215,10 +1282,12 @@
12151282 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
12161283 }
12171284 }
1285
+
12181286 if (flipV)
12191287 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12201288 else
12211289 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1290
+
12221291 //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
12231292 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
12241293
....@@ -1246,8 +1315,10 @@
12461315 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12471316 else
12481317 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1318
+
12491319 //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
12501320 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1321
+
12511322 count2 += 2;
12521323 count3 += 3;
12531324 }
....@@ -1426,6 +1497,8 @@
14261497 gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
14271498 }
14281499
1500
+ float[] colorV = new float[4];
1501
+
14291502 void SetColor(Object3D obj, Vertex p0)
14301503 {
14311504 CameraPane display = this;
....@@ -1493,8 +1566,6 @@
14931566 {
14941567 return;
14951568 }
1496
-
1497
- float[] colorV = new float[3];
14981569
14991570 if (false) // marked)
15001571 {
....@@ -1603,7 +1674,7 @@
16031674 // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
16041675 }
16051676
1606
- void DrawMaterial(cMaterial material, boolean selected)
1677
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
16071678 {
16081679 CameraPane display = this;
16091680 //new Exception().printStackTrace();
....@@ -1638,7 +1709,7 @@
16381709 colorV[0] = display.modelParams0[0] * material.diffuse;
16391710 colorV[1] = display.modelParams0[1] * material.diffuse;
16401711 colorV[2] = display.modelParams0[2] * material.diffuse;
1641
- colorV[3] = material.opacity;
1712
+ colorV[3] = 1; // material.opacity;
16421713
16431714 gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
16441715 //System.out.println("Opacity = " + opacity);
....@@ -1746,9 +1817,9 @@
17461817 display.modelParams7[2] = 0;
17471818 display.modelParams7[3] = 0;
17481819
1749
- display.modelParams6[0] = 100; // criss de bug de bump
1820
+ //display.modelParams6[0] = 100; // criss de bug de bump
17501821
1751
- Object3D.cVector2[] extparams = display.vector2buffer;
1822
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
17521823 if (extparams != null && extparams.length > 0 && extparams[0] != null)
17531824 {
17541825 display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
....@@ -2044,7 +2115,7 @@
20442115 //System.err.println("Oeil on");
20452116 OEIL = true;
20462117 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2047
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2118
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
20482119 //pingthread.StepToTarget(true);
20492120 }
20502121
....@@ -2259,7 +2330,7 @@
22592330
22602331 void ToggleDebug()
22612332 {
2262
- DEBUG ^= true;
2333
+ Globals.DEBUG ^= true;
22632334 }
22642335
22652336 void ToggleLookAt()
....@@ -2277,10 +2348,17 @@
22772348 HANDLES ^= true;
22782349 }
22792350
2351
+ Object3D paintFolder;
2352
+
22802353 void TogglePaint()
22812354 {
22822355 PAINTMODE ^= true;
22832356 paintcount = 0;
2357
+
2358
+ if (PAINTMODE)
2359
+ {
2360
+ paintFolder = GetFolder();
2361
+ }
22842362 }
22852363
22862364 void SwapCamera(int a, int b)
....@@ -2377,6 +2455,21 @@
23772455 return currentGL;
23782456 }
23792457
2458
+ static private BufferedImage CreateBim(TextureData texturedata)
2459
+ {
2460
+ Grafreed.Assert(texturedata != null);
2461
+
2462
+ int width = texturedata.getWidth();
2463
+ int height = texturedata.getHeight();
2464
+
2465
+ Buffer buffer = texturedata.getBuffer();
2466
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2467
+
2468
+ byte[] bytes = bytebuf.array();
2469
+
2470
+ return CreateBim(bytes, width, height);
2471
+ }
2472
+
23802473 /**/
23812474 class CacheTexture
23822475 {
....@@ -2385,28 +2478,31 @@
23852478
23862479 int resolution;
23872480
2388
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2481
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
23892482 {
2390
- texture = tex;
2483
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2484
+ texturedata = texdata;
23912485 resolution = res;
23922486 }
23932487 }
23942488 /**/
23952489
23962490 // TEXTURE static Texture texture;
2397
- static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures
2398
- = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>();
2399
- static public java.util.Hashtable<String, String> usedtextures = new java.util.Hashtable<String, String>();
2491
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2492
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2493
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2494
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2495
+
24002496 int pigmentdepth = 0;
24012497 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
24022498 int bumpdepth = 0;
24032499 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
24042500 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
24052501 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2406
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2502
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
24072503 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
24082504
2409
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2505
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
24102506 {
24112507 TextureData texturedata = null;
24122508
....@@ -2425,13 +2521,34 @@
24252521 if (bump)
24262522 texturedata = ConvertBump(texturedata, false);
24272523
2428
- com.sun.opengl.util.texture.Texture texture =
2429
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2524
+// com.sun.opengl.util.texture.Texture texture =
2525
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
24302526
2431
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2432
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
2527
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2528
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
24332529
2434
- return texture;
2530
+ return texturedata;
2531
+ }
2532
+
2533
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2534
+ {
2535
+ TextureData texturedata = null;
2536
+
2537
+ try
2538
+ {
2539
+ texturedata =
2540
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2541
+ bim,
2542
+ true);
2543
+ } catch (Exception e)
2544
+ {
2545
+ throw new javax.media.opengl.GLException(e);
2546
+ }
2547
+
2548
+ if (bump)
2549
+ texturedata = ConvertBump(texturedata, false);
2550
+
2551
+ return texturedata;
24352552 }
24362553
24372554 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3504,6 +3621,8 @@
35043621
35053622 System.out.println("LOADING TEXTURE : " + name);
35063623
3624
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3625
+
35073626 //
35083627 if (false) // compressbit > 0)
35093628 {
....@@ -7902,7 +8021,7 @@
79028021 String pigment = Object3D.GetPigment(tex);
79038022 String bump = Object3D.GetBump(tex);
79048023
7905
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8024
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79068025 {
79078026 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79088027 // System.out.println("; bump = " + bump);
....@@ -7917,11 +8036,69 @@
79178036 pigment = null;
79188037 }
79198038
7920
- ReleaseTexture(bump, true);
7921
- ReleaseTexture(pigment, false);
8039
+ ReleaseTexture(tex, true);
8040
+ ReleaseTexture(tex, false);
79228041 }
79238042
7924
- void ReleaseTexture(String tex, boolean bump)
8043
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
8044
+ {
8045
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8046
+ {
8047
+ return;
8048
+ }
8049
+
8050
+ if (tex == null)
8051
+ {
8052
+ ReleaseTexture(null, false);
8053
+ return;
8054
+ }
8055
+
8056
+ String pigment = Object3D.GetPigment(tex);
8057
+
8058
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8059
+ {
8060
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8061
+ // System.out.println("; bump = " + bump);
8062
+ }
8063
+
8064
+ if (pigment.equals(""))
8065
+ {
8066
+ pigment = null;
8067
+ }
8068
+
8069
+ ReleaseTexture(tex, false);
8070
+ }
8071
+
8072
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
8073
+ {
8074
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8075
+ {
8076
+ return;
8077
+ }
8078
+
8079
+ if (tex == null)
8080
+ {
8081
+ ReleaseTexture(null, true);
8082
+ return;
8083
+ }
8084
+
8085
+ String bump = Object3D.GetBump(tex);
8086
+
8087
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8088
+ {
8089
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8090
+ // System.out.println("; bump = " + bump);
8091
+ }
8092
+
8093
+ if (bump.equals(""))
8094
+ {
8095
+ bump = null;
8096
+ }
8097
+
8098
+ ReleaseTexture(tex, true);
8099
+ }
8100
+
8101
+ void ReleaseTexture(cTexture tex, boolean bump)
79258102 {
79268103 if (// DrawMode() != 0 || /*tex == null ||*/
79278104 ambientOcclusion ) // || !textureon)
....@@ -7932,7 +8109,7 @@
79328109 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
79338110
79348111 if (tex != null)
7935
- texture = textures.get(tex);
8112
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
79368113
79378114 // //assert( texture != null );
79388115 // if (texture == null)
....@@ -8026,6 +8203,54 @@
80268203
80278204 /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
80288205 {
8206
+// if (// DrawMode() != 0 || /*tex == null ||*/
8207
+// ambientOcclusion ) // || !textureon)
8208
+// {
8209
+// return; // false;
8210
+// }
8211
+//
8212
+// if (tex == null)
8213
+// {
8214
+// BindTexture(null,false,resolution);
8215
+// BindTexture(null,true,resolution);
8216
+// return;
8217
+// }
8218
+//
8219
+// String pigment = Object3D.GetPigment(tex);
8220
+// String bump = Object3D.GetBump(tex);
8221
+//
8222
+// usedtextures.add(pigment);
8223
+// usedtextures.add(bump);
8224
+//
8225
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8226
+// {
8227
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8228
+// // System.out.println("; bump = " + bump);
8229
+// }
8230
+//
8231
+// if (bump.equals(""))
8232
+// {
8233
+// bump = null;
8234
+// }
8235
+// if (pigment.equals(""))
8236
+// {
8237
+// pigment = null;
8238
+// }
8239
+//
8240
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8241
+// BindTexture(pigment, false, resolution);
8242
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8243
+// BindTexture(bump, true, resolution);
8244
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8245
+//
8246
+// return; // true;
8247
+
8248
+ BindPigmentTexture(tex, resolution);
8249
+ BindBumpTexture(tex, resolution);
8250
+ }
8251
+
8252
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8253
+ {
80298254 if (// DrawMode() != 0 || /*tex == null ||*/
80308255 ambientOcclusion ) // || !textureon)
80318256 {
....@@ -8035,17 +8260,47 @@
80358260 if (tex == null)
80368261 {
80378262 BindTexture(null,false,resolution);
8038
- BindTexture(null,true,resolution);
80398263 return;
80408264 }
80418265
80428266 String pigment = Object3D.GetPigment(tex);
8267
+
8268
+ usedtextures.add(tex);
8269
+
8270
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8271
+ {
8272
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8273
+ // System.out.println("; bump = " + bump);
8274
+ }
8275
+
8276
+ if (pigment.equals(""))
8277
+ {
8278
+ pigment = null;
8279
+ }
8280
+
8281
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8282
+ BindTexture(tex, false, resolution);
8283
+ }
8284
+
8285
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8286
+ {
8287
+ if (// DrawMode() != 0 || /*tex == null ||*/
8288
+ ambientOcclusion ) // || !textureon)
8289
+ {
8290
+ return; // false;
8291
+ }
8292
+
8293
+ if (tex == null)
8294
+ {
8295
+ BindTexture(null,true,resolution);
8296
+ return;
8297
+ }
8298
+
80438299 String bump = Object3D.GetBump(tex);
80448300
8045
- usedtextures.put(pigment, pigment);
8046
- usedtextures.put(bump, bump);
8301
+ usedtextures.add(tex);
80478302
8048
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8303
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
80498304 {
80508305 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
80518306 // System.out.println("; bump = " + bump);
....@@ -8055,18 +8310,10 @@
80558310 {
80568311 bump = null;
80578312 }
8058
- if (pigment.equals(""))
8059
- {
8060
- pigment = null;
8061
- }
80628313
8063
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8064
- BindTexture(pigment, false, resolution);
80658314 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8066
- BindTexture(bump, true, resolution);
8315
+ BindTexture(tex, true, resolution);
80678316 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8068
-
8069
- return; // true;
80708317 }
80718318
80728319 java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
....@@ -8089,13 +8336,19 @@
80898336 return fileExists;
80908337 }
80918338
8092
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception
8339
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
80938340 {
8094
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8341
+ CacheTexture texturecache = null;
80958342
80968343 if (tex != null)
80978344 {
8098
- String texname = tex;
8345
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8346
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
8347
+
8348
+ if (texname.equals("") && texdata == null)
8349
+ {
8350
+ return null;
8351
+ }
80998352
81008353 String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
81018354
....@@ -8105,19 +8358,46 @@
81058358 // else
81068359 // if (!texname.startsWith("/"))
81078360 // texname = "/Users/nbriere/Textures/" + texname;
8108
- if (!FileExists(tex))
8361
+ if (!FileExists(texname) && !texname.startsWith("@"))
81098362 {
81108363 texname = fallbackTextureName;
81118364 }
81128365
81138366 if (CACHETEXTURE)
8114
- texture = textures.get(texname); // TEXTURE CACHE
8115
-
8116
- TextureData texturedata = null;
8117
-
8118
- if (texture == null || texture.resolution < resolution)
81198367 {
8120
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8368
+ if (texdata == null)
8369
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8370
+ else
8371
+ texturecache = bimtextures.get(texdata);
8372
+ }
8373
+
8374
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8375
+ {
8376
+ TextureData texturedata = null;
8377
+
8378
+ if (texdata != null && textureon)
8379
+ {
8380
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8381
+
8382
+ try
8383
+ {
8384
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8385
+ }
8386
+ catch (Exception e)
8387
+ {
8388
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8389
+ }
8390
+
8391
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8392
+ bimtextures.put(texdata, texturecache);
8393
+
8394
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8395
+
8396
+ //Object bim2 = CreateBim(texturecache.texturedata);
8397
+ //bim2 = bim;
8398
+ }
8399
+ else
8400
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
81218401 {
81228402 assert(!bump);
81238403 // if (bump)
....@@ -8128,19 +8408,23 @@
81288408 // }
81298409 // else
81308410 // {
8131
- texture = textures.get(tex);
8132
- if (texture == null)
8411
+ // texturecache = textures.get(texname); // suspicious
8412
+ if (texturecache == null)
81338413 {
8134
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8414
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
81358415 }
8416
+ else
8417
+ new Exception().printStackTrace();
81368418 // }
81378419 } else
8138
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8420
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
81398421 {
81408422 assert(bump);
8141
- texture = textures.get(tex);
8142
- if (texture == null)
8143
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8423
+ // texturecache = textures.get(texname); // suspicious
8424
+ if (texturecache == null)
8425
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8426
+ else
8427
+ new Exception().printStackTrace();
81448428 } else
81458429 {
81468430 //if (tex.equals("IMMORTAL"))
....@@ -8148,11 +8432,22 @@
81488432 // texture = GetResourceTexture("default.png");
81498433 //} else
81508434 //{
8151
- if (tex.equals("WHITE_NOISE"))
8435
+ if (texname.endsWith("WHITE_NOISE"))
81528436 {
8153
- texture = textures.get(tex);
8154
- if (texture == null)
8155
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8437
+ // texturecache = textures.get(texname); // suspicious
8438
+ if (texturecache == null)
8439
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8440
+ else
8441
+ new Exception().printStackTrace();
8442
+ } else
8443
+ {
8444
+ if (texname.startsWith("@"))
8445
+ {
8446
+ // texturecache = textures.get(texname); // suspicious
8447
+ if (texturecache == null)
8448
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8449
+ else
8450
+ new Exception().printStackTrace();
81568451 } else
81578452 {
81588453 if (textureon)
....@@ -8211,19 +8506,20 @@
82118506 if (texturedata == null)
82128507 throw new Exception();
82138508
8214
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8509
+ texturecache = new CacheTexture(texturedata,resolution);
82158510 //texture = GetTexture(tex, bump);
82168511 }
8512
+ }
82178513 }
82188514 //}
82198515 }
82208516
8221
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8517
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
82228518 {
82238519 //return false;
82248520
82258521 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8226
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8522
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
82278523 {
82288524 // String ext = "_highres";
82298525 // if (REDUCETEXTURE)
....@@ -8240,52 +8536,17 @@
82408536 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
82418537 if (!cachefile.exists())
82428538 {
8243
- // cache to disk
8244
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
8245
- //buffers[0].
8246
-
8247
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
8248
- int[] pixels = new int[bytebuf.capacity()/3];
8249
-
8250
- // squared size heuristic...
8251
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8539
+ //if (texturedata.getWidth() == texturedata.getHeight())
82528540 {
8253
- for (int i=pixels.length; --i>=0;)
8254
- {
8255
- int i3 = i*3;
8256
- pixels[i] = 0xFF;
8257
- pixels[i] <<= 8;
8258
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
8259
- pixels[i] <<= 8;
8260
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
8261
- pixels[i] <<= 8;
8262
- pixels[i] |= bytebuf.get(i3) & 0xFF;
8263
- }
8264
-
8265
- /*
8266
- int r=0,g=0,b=0,a=0;
8267
- for (int i=0; i<width; i++)
8268
- for (int j=0; j<height; j++)
8269
- {
8270
- int index = j*width+i;
8271
- int p = pixels[index];
8272
- a = ((p>>24) & 0xFF);
8273
- r = ((p>>16) & 0xFF);
8274
- g = ((p>>8) & 0xFF);
8275
- b = (p & 0xFF);
8276
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
8277
- }
8278
- /**/
8279
- int width = (int)Math.sqrt(pixels.length); // squared
8280
- int height = width;
8281
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
8282
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8541
+ BufferedImage rendImage = CreateBim(texturedata);
8542
+
82838543 ImageWriter writer = null;
82848544 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
82858545 if (iter.hasNext()) {
82868546 writer = (ImageWriter)iter.next();
82878547 }
8288
- float compressionQuality = 0.9f;
8548
+
8549
+ float compressionQuality = 0.85f;
82898550 try
82908551 {
82918552 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8302,18 +8563,20 @@
83028563 }
83038564 }
83048565 }
8305
-
8566
+
8567
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8568
+
83068569 //System.out.println("Texture = " + tex);
8307
- if (textures.containsKey(texname))
8570
+ if (textures.containsKey(tex))
83088571 {
8309
- CacheTexture thetex = textures.get(texname);
8572
+ CacheTexture thetex = textures.get(tex);
83108573 thetex.texture.disable();
83118574 thetex.texture.dispose();
8312
- textures.remove(texname);
8575
+ textures.remove(tex);
83138576 }
83148577
8315
- texture.texturedata = texturedata;
8316
- textures.put(texname, texture);
8578
+ //texture.texturedata = texturedata;
8579
+ textures.put(tex, texturecache);
83178580
83188581 // newtex = true;
83198582 }
....@@ -8329,10 +8592,44 @@
83298592 }
83308593 }
83318594
8332
- return texture;
8595
+ return texturecache;
83338596 }
83348597
8335
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution) throws Exception
8598
+ static void EmbedTextures(cTexture tex)
8599
+ {
8600
+ if (tex.pigmentdata == null)
8601
+ {
8602
+ //String texname = Object3D.GetPigment(tex);
8603
+
8604
+ CacheTexture texturecache = texturepigment.get(tex);
8605
+
8606
+ if (texturecache != null)
8607
+ {
8608
+ tex.pw = texturecache.texturedata.getWidth();
8609
+ tex.ph = texturecache.texturedata.getHeight();
8610
+ tex.pigmentdata = //CompressJPEG(CreateBim
8611
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8612
+ ;
8613
+ //, tex.pw, tex.ph), 0.5f);
8614
+ }
8615
+ }
8616
+
8617
+ if (tex.bumpdata == null)
8618
+ {
8619
+ //String texname = Object3D.GetBump(tex);
8620
+
8621
+ CacheTexture texturecache = texturebump.get(tex);
8622
+
8623
+ if (texturecache != null)
8624
+ {
8625
+ tex.bw = texturecache.texturedata.getWidth();
8626
+ tex.bh = texturecache.texturedata.getHeight();
8627
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8628
+ }
8629
+ }
8630
+ }
8631
+
8632
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
83368633 {
83378634 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
83388635
....@@ -8350,21 +8647,21 @@
83508647 return texture!=null?texture.texture:null;
83518648 }
83528649
8353
- public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution) throws Exception
8650
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
83548651 {
83558652 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
83568653
83578654 return texture!=null?texture.texturedata:null;
83588655 }
83598656
8360
- boolean BindTexture(String tex, boolean bump, int resolution) throws Exception
8657
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
83618658 {
83628659 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
83638660 {
83648661 return false;
83658662 }
83668663
8367
- boolean newtex = false;
8664
+ //boolean newtex = false;
83688665
83698666 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
83708667
....@@ -8396,9 +8693,75 @@
83968693 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
83978694 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
83988695
8399
- return newtex;
8696
+ return true; // Warning: not used.
84008697 }
84018698
8699
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8700
+ {
8701
+ try
8702
+ {
8703
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8704
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8705
+ ImageWriter writer = writers.next();
8706
+
8707
+ ImageWriteParam param = writer.getDefaultWriteParam();
8708
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8709
+ param.setCompressionQuality(quality);
8710
+
8711
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8712
+ writer.setOutput(ios);
8713
+ writer.write(null, new IIOImage(image, null, null), param);
8714
+
8715
+ byte[] data = baos.toByteArray();
8716
+ writer.dispose();
8717
+ return data;
8718
+ }
8719
+ catch (Exception e)
8720
+ {
8721
+ e.printStackTrace();
8722
+ return null;
8723
+ }
8724
+ }
8725
+
8726
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8727
+ {
8728
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8729
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8730
+ ImageReader reader = writers.next();
8731
+
8732
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8733
+
8734
+ ImageReadParam param = reader.getDefaultReadParam();
8735
+ param.setDestination(bim);
8736
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8737
+
8738
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8739
+ reader.setInput(ios);
8740
+ BufferedImage bim2 = reader.read(0, param);
8741
+ reader.dispose();
8742
+
8743
+// WritableRaster raster = bim2.getRaster();
8744
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8745
+// byte[] bytes = data.getData();
8746
+//
8747
+// int[] pixels = new int[bytes.length/3];
8748
+// for (int i=pixels.length; --i>=0;)
8749
+// {
8750
+// int i3 = i*3;
8751
+// pixels[i] = 0xFF;
8752
+// pixels[i] <<= 8;
8753
+// pixels[i] |= bytes[i3+2] & 0xFF;
8754
+// pixels[i] <<= 8;
8755
+// pixels[i] |= bytes[i3+1] & 0xFF;
8756
+// pixels[i] <<= 8;
8757
+// pixels[i] |= bytes[i3] & 0xFF;
8758
+// }
8759
+//
8760
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8761
+
8762
+ return bim;
8763
+ }
8764
+
84028765 ShadowBuffer shadowPBuf;
84038766 AntialiasBuffer antialiasPBuf;
84048767 int MAXSTACK;
....@@ -8415,10 +8778,12 @@
84158778
84168779 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
84178780 MAXSTACK = temp[0];
8418
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8781
+ if (Globals.DEBUG)
8782
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
84198783 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
84208784 MAXSTACK = temp[0];
8421
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8785
+ if (Globals.DEBUG)
8786
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
84228787
84238788 // Use debug pipeline
84248789 //drawable.setGL(new DebugGL(gl)); //
....@@ -8426,7 +8791,8 @@
84268791 gl = drawable.getGL(); //
84278792
84288793 GL gl3 = getGL();
8429
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8794
+ if (Globals.DEBUG)
8795
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
84308796
84318797
84328798 //float pos[] = { 100, 100, 100, 0 };
....@@ -8591,7 +8957,7 @@
85918957
85928958 if (cubemap == null)
85938959 {
8594
- LoadEnvy(5);
8960
+ //LoadEnvy(1);
85958961 }
85968962
85978963 //cubemap.enable();
....@@ -8878,37 +9244,58 @@
88789244 cubemap = null;
88799245 return;
88809246 case 1:
8881
- name = "cubemaps/box_";
8882
- ext = "png";
9247
+ name = "cubemaps/rgb/";
9248
+ ext = "jpg";
88839249 reverseUP = false;
88849250 break;
88859251 case 2:
8886
- name = "cubemaps/uffizi_";
8887
- ext = "png";
8888
- break; // reverseUP = true; break;
9252
+ name = "cubemaps/uffizi/";
9253
+ ext = "jpg";
9254
+ reverseUP = false;
9255
+ break;
88899256 case 3:
8890
- name = "cubemaps/CloudyHills_";
8891
- ext = "tga";
9257
+ name = "cubemaps/CloudyHills/";
9258
+ ext = "jpg";
88929259 reverseUP = false;
88939260 break;
88949261 case 4:
8895
- name = "cubemaps/cornell_";
9262
+ name = "cubemaps/cornell/";
88969263 ext = "png";
88979264 reverseUP = false;
88989265 break;
9266
+ case 5:
9267
+ name = "cubemaps/skycube/";
9268
+ ext = "jpg";
9269
+ reverseUP = false;
9270
+ break;
9271
+ case 6:
9272
+ name = "cubemaps/SaintLazarusChurch3/";
9273
+ ext = "jpg";
9274
+ reverseUP = false;
9275
+ break;
9276
+ case 7:
9277
+ name = "cubemaps/Sodermalmsallen/";
9278
+ ext = "jpg";
9279
+ reverseUP = false;
9280
+ break;
9281
+ case 8:
9282
+ name = "cubemaps/Sodermalmsallen2/";
9283
+ ext = "jpg";
9284
+ reverseUP = false;
9285
+ break;
9286
+ case 9:
9287
+ name = "cubemaps/UnionSquare/";
9288
+ ext = "jpg";
9289
+ reverseUP = false;
9290
+ break;
88999291 default:
8900
- name = "cubemaps/rgb_";
8901
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9292
+ name = "cubemaps/box/";
9293
+ ext = "png"; /*mipmap = true;*/
9294
+ reverseUP = false;
89029295 break;
89039296 }
8904
-
8905
- try
8906
- {
8907
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
8908
- } catch (IOException e)
8909
- {
8910
- throw new RuntimeException(e);
8911
- }
9297
+
9298
+ LoadSkybox(name, ext, mipmap);
89129299 }
89139300
89149301 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -8940,8 +9327,12 @@
89409327 static double[] model = new double[16];
89419328 double[] camera2light = new double[16];
89429329 double[] light2camera = new double[16];
8943
- int newenvy = -1;
8944
- boolean envyoff = true; // false;
9330
+
9331
+ //int newenvy = -1;
9332
+ //boolean envyoff = false;
9333
+
9334
+ String loadedskyboxname;
9335
+
89459336 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
89469337 //float[] light0 = { 0,0,0 };
89479338 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9234,11 +9625,35 @@
92349625 jy8[3] = 0.5f;
92359626 }
92369627
9237
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9628
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
92389629 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
92399630 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
92409631 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
92419632
9633
+ void ResetOptions()
9634
+ {
9635
+ options1[0] = 100;
9636
+ options1[1] = 0.025f;
9637
+ options1[2] = 0.01f;
9638
+ options1[3] = 0;
9639
+ options1[4] = 0;
9640
+
9641
+ options2[0] = 0;
9642
+ options2[1] = 0.75f;
9643
+ options2[2] = 0;
9644
+ options2[3] = 0;
9645
+
9646
+ options3[0] = 1;
9647
+ options3[1] = 1;
9648
+ options3[2] = 1;
9649
+ options3[3] = 0;
9650
+
9651
+ options4[0] = 1;
9652
+ options4[1] = 0;
9653
+ options4[2] = 1;
9654
+ options4[3] = 0;
9655
+ }
9656
+
92429657 static int imagecount = 0; // movie generation
92439658
92449659 static int jitter = 0;
....@@ -9335,7 +9750,7 @@
93359750
93369751 if (renderCamera != lightCamera)
93379752 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9338
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
9753
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
93399754
93409755 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
93419756
....@@ -9351,7 +9766,7 @@
93519766
93529767 if (renderCamera != lightCamera)
93539768 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9354
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
9769
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
93559770
93569771 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
93579772
....@@ -9397,10 +9812,12 @@
93979812 rati = 1 / rati;
93989813 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
93999814 }
9400
- assert (newenvy == -1);
9815
+
9816
+ //assert (newenvy == -1);
9817
+
94019818 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
94029819 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9403
- DrawSkyBox(gl);
9820
+ DrawSkyBox(gl, (float)rati);
94049821 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
94059822 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
94069823 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10349,6 +10766,7 @@
1034910766 ANTIALIAS = 0;
1035010767 //System.out.println("RESTART");
1035110768 AAtimer.restart();
10769
+ Globals.TIMERRUNNING = true;
1035210770 }
1035310771 }
1035410772 }
....@@ -10416,7 +10834,8 @@
1041610834 ambientOcclusion = false;
1041710835 }
1041810836
10419
- if (Globals.lighttouched && DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
10837
+ if (//Globals.lighttouched &&
10838
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1042010839 {
1042110840 //if (RENDERSHADOW) // ?
1042210841 if (!IsFrozen())
....@@ -10435,7 +10854,7 @@
1043510854
1043610855 if (wait)
1043710856 {
10438
- Sleep(500);
10857
+ Sleep(200); // blocks everything
1043910858
1044010859 wait = false;
1044110860 }
....@@ -10550,7 +10969,7 @@
1055010969 // if (parentcam != renderCamera) // not a light
1055110970 if (cam != lightCamera)
1055210971 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10553
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
10972
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1055410973
1055510974 for (int j = 0; j < 4; j++)
1055610975 {
....@@ -10565,7 +10984,7 @@
1056510984 // if (parentcam != renderCamera) // not a light
1056610985 if (cam != lightCamera)
1056710986 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10568
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
10987
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1056910988
1057010989 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1057110990
....@@ -10651,13 +11070,27 @@
1065111070 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1065211071 }
1065311072
10654
- if (newenvy > -1)
11073
+// if (newenvy > -1)
11074
+// {
11075
+// LoadEnvy(newenvy);
11076
+// }
11077
+//
11078
+// newenvy = -1;
11079
+
11080
+ if (object.skyboxname != null)
1065511081 {
10656
- LoadEnvy(newenvy);
11082
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11083
+ {
11084
+ LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11085
+ loadedskyboxname = object.skyboxname;
11086
+ }
1065711087 }
10658
-
10659
- newenvy = -1;
10660
-
11088
+ else
11089
+ {
11090
+ cubemap = null;
11091
+ loadedskyboxname = null;
11092
+ }
11093
+
1066111094 ratio = ((double) getWidth()) / getHeight();
1066211095 //System.out.println("ratio = " + ratio);
1066311096
....@@ -10673,7 +11106,7 @@
1067311106
1067411107 if (!IsFrozen() && !ambientOcclusion)
1067511108 {
10676
- DrawSkyBox(gl);
11109
+ DrawSkyBox(gl, (float)ratio);
1067711110 }
1067811111
1067911112 //if (selection_view == -1)
....@@ -10856,9 +11289,9 @@
1085611289
1085711290 gl.glMatrixMode(GL.GL_MODELVIEW);
1085811291
10859
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10860
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10861
-//gl.glEnable(gl.GL_MULTISAMPLE);
11292
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11293
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11294
+gl.glEnable(gl.GL_MULTISAMPLE);
1086211295 } else
1086311296 {
1086411297 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -10869,7 +11302,7 @@
1086911302 //System.out.println("BLENDING ON");
1087011303 gl.glEnable(GL.GL_BLEND);
1087111304 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
10872
-
11305
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1087311306 gl.glMatrixMode(gl.GL_PROJECTION);
1087411307 gl.glLoadIdentity();
1087511308
....@@ -10959,7 +11392,7 @@
1095911392
1096011393 // if (cam != lightCamera)
1096111394 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10962
- LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
11395
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1096311396 }
1096411397
1096511398 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -11118,7 +11551,7 @@
1111811551 }
1111911552 }
1112011553
11121
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11554
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1112211555 {
1112311556 //gl.glDepthFunc(GL.GL_LEQUAL);
1112411557 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11126,24 +11559,21 @@
1112611559
1112711560 boolean texon = textureon;
1112811561
11129
- if (RENDERPROGRAM > 0)
11130
- {
11131
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11132
- textureon = false;
11133
- }
11562
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11563
+ textureon = false;
11564
+
1113411565 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1113511566 //System.out.println("ALLO");
1113611567 gl.glColorMask(false, false, false, false);
1113711568 DrawObject(gl);
11138
- if (RENDERPROGRAM > 0)
11139
- {
11140
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11141
- textureon = texon;
11142
- }
11569
+
11570
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11571
+ textureon = texon;
11572
+
1114311573 gl.glColorMask(true, true, true, true);
1114411574
1114511575 gl.glDepthFunc(GL.GL_EQUAL);
11146
- //gl.glDepthMask(false);
11576
+ gl.glDepthMask(false);
1114711577 }
1114811578
1114911579 if (false) // DrawMode() == SHADOW)
....@@ -11326,15 +11756,36 @@
1132611756
1132711757 static boolean zoomonce = false;
1132811758
11759
+ static void CreateSelectedPoint()
11760
+ {
11761
+ if (selectedpoint == null)
11762
+ {
11763
+ debugpointG = new Sphere();
11764
+ debugpointP = new Sphere();
11765
+ debugpointC = new Sphere();
11766
+ debugpointR = new Sphere();
11767
+
11768
+ selectedpoint = new Superellipsoid();
11769
+
11770
+ for (int i=0; i<8; i++)
11771
+ {
11772
+ debugpoints[i] = new Sphere();
11773
+ }
11774
+ }
11775
+ }
11776
+
1132911777 void DrawObject(GL gl, boolean draw)
1133011778 {
11779
+ // To clear camera values
11780
+ ResetOptions();
11781
+
1133111782 //System.out.println("DRAW OBJECT " + mouseDown);
1133211783 // DrawMode() = SELECTION;
1133311784 //GL gl = getGL();
1133411785 if ((TRACK || SHADOWTRACK) || zoomonce)
1133511786 {
1133611787 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11337
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11788
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1133811789 pingthread.StepToTarget(true); // true);
1133911790 // zoomonce = false;
1134011791 }
....@@ -11406,8 +11857,9 @@
1140611857
1140711858 if (DrawMode() == DEFAULT)
1140811859 {
11409
- if (DEBUG)
11860
+ if (Globals.DEBUG)
1141011861 {
11862
+ CreateSelectedPoint();
1141111863 float radius = 0.05f;
1141211864 if (selectedpoint.radius != radius)
1141311865 {
....@@ -11461,20 +11913,32 @@
1146111913 ReleaseTextures(DEFAULT_TEXTURES);
1146211914
1146311915 if (CLEANCACHE)
11464
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11916
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1146511917 {
11466
- String tex = e.nextElement();
11918
+ cTexture tex = e.nextElement();
1146711919
1146811920 // System.out.println("Texture --------- " + tex);
1146911921
11470
- if (tex.equals("WHITE_NOISE"))
11922
+ if (tex.equals("WHITE_NOISE:"))
1147111923 continue;
1147211924
11473
- if (!usedtextures.containsKey(tex))
11925
+ if (!usedtextures.contains(tex))
1147411926 {
11927
+ CacheTexture gettex = texturepigment.get(tex);
1147511928 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11476
- textures.get(tex).texture.dispose();
11477
- textures.remove(tex);
11929
+ if (gettex != null)
11930
+ {
11931
+ gettex.texture.dispose();
11932
+ texturepigment.remove(tex);
11933
+ }
11934
+
11935
+ gettex = texturebump.get(tex);
11936
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11937
+ if (gettex != null)
11938
+ {
11939
+ gettex.texture.dispose();
11940
+ texturebump.remove(tex);
11941
+ }
1147811942 }
1147911943 }
1148011944 }
....@@ -11894,7 +12358,7 @@
1189412358 for (int i = tp.size(); --i >= 0;)
1189512359 {
1189612360 //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
11897
- LA.xformPos(light, tp.get(i).GlobalTransform(), light);
12361
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1189812362 }
1189912363
1190012364
....@@ -12002,8 +12466,76 @@
1200212466
1200312467 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1200412468
12005
- String program =
12469
+ String programmin =
12470
+ // Min shader
1200612471 "!!ARBfp1.0\n" +
12472
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12473
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12474
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12475
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12476
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12477
+ "PARAM light2cam0 = program.env[10];" +
12478
+ "PARAM light2cam1 = program.env[11];" +
12479
+ "PARAM light2cam2 = program.env[12];" +
12480
+ "TEMP temp;" +
12481
+ "TEMP light;" +
12482
+ "TEMP ndotl;" +
12483
+ "TEMP normal;" +
12484
+ "TEMP depth;" +
12485
+ "TEMP eye;" +
12486
+ "TEMP pos;" +
12487
+
12488
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12489
+ Normalize("normal") +
12490
+ "MOV light, state.light[0].position;" +
12491
+ "DP3 ndotl.x, light, normal;" +
12492
+
12493
+ // shadow
12494
+ "MOV pos, fragment.texcoord[1];" +
12495
+ "MOV temp, pos;" +
12496
+ ShadowTextureFetch("depth", "temp", "1") +
12497
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12498
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12499
+
12500
+ // No shadow when out of frustum
12501
+ //"SGE temp.y, depth.z, zero123.y;" +
12502
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12503
+
12504
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12505
+
12506
+ // Backlit
12507
+ "MOV pos.w, zero123.y;" +
12508
+ "DP4 eye.x, pos, light2cam0;" +
12509
+ "DP4 eye.y, pos, light2cam1;" +
12510
+ "DP4 eye.z, pos, light2cam2;" +
12511
+ Normalize("eye") +
12512
+
12513
+ "DP3 ndotl.y, -eye, normal;" +
12514
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12515
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12516
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12517
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12518
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12519
+
12520
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12521
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12522
+
12523
+ // Pigment
12524
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12525
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12526
+ "MUL temp, temp, ndotl.x;" +
12527
+
12528
+ "MUL temp, temp, zero123.z;" +
12529
+
12530
+ //"MUL temp, temp, ndotl.y;" +
12531
+
12532
+ "MOV temp.w, zero123.y;" + // reset alpha
12533
+ "MOV result.color, temp;" +
12534
+ "END";
12535
+
12536
+ String programmax =
12537
+ "!!ARBfp1.0\n" +
12538
+
1200712539 //"OPTION ARB_fragment_program_shadow;" +
1200812540 "PARAM light2cam0 = program.env[10];" +
1200912541 "PARAM light2cam1 = program.env[11];" +
....@@ -12118,8 +12650,7 @@
1211812650 "TEMP shininess;" +
1211912651 "\n" +
1212012652 "MOV texSamp, one;" +
12121
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12122
-
12653
+
1212312654 "MOV mapgrid.x, one2048th.x;" +
1212412655 "MOV temp, fragment.texcoord[1];" +
1212512656 /*
....@@ -12140,20 +12671,20 @@
1214012671 "MUL temp, floor, mapgrid.x;" +
1214112672 //"TEX depth0, temp, texture[1], 2D;" +
1214212673 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12143
- TextureFetch("depth0", "temp", "1") +
12674
+ ShadowTextureFetch("depth0", "temp", "1") +
1214412675 "") +
1214512676 "ADD temp.x, temp.x, mapgrid.x;" +
1214612677 //"TEX depth1, temp, texture[1], 2D;" +
1214712678 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12148
- TextureFetch("depth1", "temp", "1") +
12679
+ ShadowTextureFetch("depth1", "temp", "1") +
1214912680 "") +
1215012681 "ADD temp.y, temp.y, mapgrid.x;" +
1215112682 //"TEX depth2, temp, texture[1], 2D;" +
12152
- TextureFetch("depth2", "temp", "1") +
12683
+ ShadowTextureFetch("depth2", "temp", "1") +
1215312684 "SUB temp.x, temp.x, mapgrid.x;" +
1215412685 //"TEX depth3, temp, texture[1], 2D;" +
1215512686 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12156
- TextureFetch("depth3", "temp", "1") +
12687
+ ShadowTextureFetch("depth3", "temp", "1") +
1215712688 "") +
1215812689 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1215912690 //"MOV params, material;" +
....@@ -12524,10 +13055,10 @@
1252413055 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1252513056 "") +
1252613057
12527
- // display shadow only (bump == 0)
13058
+ // display shadow only (fakedepth == 0)
1252813059 "SUB temp.x, half.x, shadow.x;" +
1252913060 "MOV temp.y, -params5.z;" + // params6.x;" +
12530
- "SLT temp.z, temp.y, -one2048th.x;" +
13061
+ "SLT temp.z, temp.y, -c256i.x;" +
1253113062 "SUB temp.y, one.x, temp.z;" +
1253213063 "MUL temp.x, temp.x, temp.y;" +
1253313064 "KIL temp.x;" +
....@@ -12858,6 +13389,13 @@
1285813389 //once = true;
1285913390 }
1286013391
13392
+ String program = programmax;
13393
+
13394
+ if (Globals.MINSHADER)
13395
+ {
13396
+ program = programmin;
13397
+ }
13398
+
1286113399 System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1286213400 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1286313401 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
....@@ -12951,25 +13489,26 @@
1295113489 return out;
1295213490 }
1295313491
12954
- String TextureFetch(String dest, String src, String unit)
13492
+ // Also does frustum culling
13493
+ String ShadowTextureFetch(String dest, String src, String unit)
1295513494 {
1295613495 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1295713496 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1295813497 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13498
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13499
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1295913500 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12960
- "SLT " + src + ".z, " + src + ".x, one.x;" +
12961
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12962
- "SLT " + src + ".z, " + src + ".y, one.x;" +
12963
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13501
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13502
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1296413503 //"SWZ buffer, temp, w,w,w,w;";
12965
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13504
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1296613505 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1296713506 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1296813507 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
12969
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13508
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1297013509
12971
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
12972
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13510
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13511
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1297313512 }
1297413513
1297513514 String Shadow(String depth, String shadow)
....@@ -13016,7 +13555,7 @@
1301613555 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1301713556 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1301813557
13019
- // No shadow when out of frustrum
13558
+ // No shadow when out of frustum
1302013559 "SGE temp.x, " + depth + ".z, one.z;" +
1302113560 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1302213561 "";
....@@ -13164,7 +13703,8 @@
1316413703 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1316513704 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1316613705 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13167
- Object3D.cVector2[] vector2buffer;
13706
+
13707
+ //Object3D.cVector2[] vector2buffer;
1316813708
1316913709 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1317013710 // OUT : diff, spec
....@@ -13180,9 +13720,10 @@
1318013720 "DP3 " + dest + ".z," + "normals," + "eye;" +
1318113721 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1318213722 //"MOV " + dest + ".w," + "normal.z;" +
13183
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
13184
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13185
- //"MOV " + dest + ".z," + "params2.w;" +
13723
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13724
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13725
+
13726
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1318613727 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1318713728 "RCP " + dest + ".w," + dest + ".w;" +
1318813729 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13687,6 +14228,7 @@
1368714228 else
1368814229 if (evt.getSource() == AAtimer)
1368914230 {
14231
+ Globals.TIMERRUNNING = false;
1369014232 if (mouseDown)
1369114233 {
1369214234 //new Exception().printStackTrace();
....@@ -13746,7 +14288,7 @@
1374614288
1374714289 // fev 2014???
1374814290 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13749
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14291
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1375014292 pingthread.StepToTarget(true); // true);
1375114293 }
1375214294 // if (!LIVE)
....@@ -13761,6 +14303,7 @@
1376114303 return;
1376214304
1376314305 AAtimer.restart(); //
14306
+ Globals.TIMERRUNNING = true;
1376414307
1376514308 // waslive = LIVE;
1376614309 // LIVE = false;
....@@ -13810,14 +14353,15 @@
1381014353 drag = false;
1381114354 //System.out.println("Mouse DOWN");
1381214355 editObj = false;
13813
- ClickInfo info = new ClickInfo();
13814
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
13815
- info.pane = this;
13816
- info.camera = renderCamera;
13817
- info.x = x;
13818
- info.y = y;
13819
- info.modifiers = modifiersex;
13820
- editObj = object.doEditClick(info, 0);
14356
+ //ClickInfo info = new ClickInfo();
14357
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14358
+ object.clickInfo.pane = this;
14359
+ object.clickInfo.camera = renderCamera;
14360
+ object.clickInfo.x = x;
14361
+ object.clickInfo.y = y;
14362
+ object.clickInfo.modifiers = modifiersex;
14363
+ editObj = object.doEditClick(//info,
14364
+ 0);
1382114365 if (!editObj)
1382214366 {
1382314367 hasMarquee = true;
....@@ -14099,12 +14643,12 @@
1409914643 void GoDown(int mod)
1410014644 {
1410114645 MODIFIERS |= COMMAND;
14102
- /*
14646
+ /**/
1410314647 if((mod&SHIFT) == SHIFT)
14104
- manipCamera.RotatePosition(0, -speed);
14648
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
1410514649 else
14106
- manipCamera.BackForth(0, -speed*delta, getWidth());
14107
- */
14650
+ manipCamera.RotatePosition(0, -speed);
14651
+ /**/
1410814652 if ((mod & SHIFT) == SHIFT)
1410914653 {
1411014654 mouseMode = mouseMode; // VR??
....@@ -14120,12 +14664,12 @@
1412014664 void GoUp(int mod)
1412114665 {
1412214666 MODIFIERS |= COMMAND;
14123
- /*
14667
+ /**/
1412414668 if((mod&SHIFT) == SHIFT)
14125
- manipCamera.RotatePosition(0, speed);
14669
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
1412614670 else
14127
- manipCamera.BackForth(0, speed*delta, getWidth());
14128
- */
14671
+ manipCamera.RotatePosition(0, speed);
14672
+ /**/
1412914673 if ((mod & SHIFT) == SHIFT)
1413014674 {
1413114675 mouseMode = mouseMode;
....@@ -14141,12 +14685,12 @@
1414114685 void GoLeft(int mod)
1414214686 {
1414314687 MODIFIERS |= COMMAND;
14144
- /*
14688
+ /**/
1414514689 if((mod&SHIFT) == SHIFT)
14146
- manipCamera.RotatePosition(speed, 0);
14147
- else
1414814690 manipCamera.Translate(speed*delta, 0, getWidth());
14149
- */
14691
+ else
14692
+ manipCamera.RotatePosition(speed, 0);
14693
+ /**/
1415014694 if ((mod & SHIFT) == SHIFT)
1415114695 {
1415214696 mouseMode = mouseMode;
....@@ -14162,12 +14706,12 @@
1416214706 void GoRight(int mod)
1416314707 {
1416414708 MODIFIERS |= COMMAND;
14165
- /*
14709
+ /**/
1416614710 if((mod&SHIFT) == SHIFT)
14167
- manipCamera.RotatePosition(-speed, 0);
14168
- else
1416914711 manipCamera.Translate(-speed*delta, 0, getWidth());
14170
- */
14712
+ else
14713
+ manipCamera.RotatePosition(-speed, 0);
14714
+ /**/
1417114715 if ((mod & SHIFT) == SHIFT)
1417214716 {
1417314717 mouseMode = mouseMode;
....@@ -14217,14 +14761,16 @@
1421714761 if (editObj)
1421814762 {
1421914763 drag = true;
14220
- ClickInfo info = new ClickInfo();
14221
- info.bounds.setBounds(0, 0,
14764
+ //ClickInfo info = new ClickInfo();
14765
+ object.clickInfo.bounds.setBounds(0, 0,
1422214766 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14223
- info.pane = this;
14224
- info.camera = renderCamera;
14225
- info.x = x;
14226
- info.y = y;
14227
- object.editWindow.copy.doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
14767
+ object.clickInfo.pane = this;
14768
+ object.clickInfo.camera = renderCamera;
14769
+ object.clickInfo.x = x;
14770
+ object.clickInfo.y = y;
14771
+ object //.GetWindow().copy
14772
+ .doEditDrag(//info,
14773
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1422814774 } else
1422914775 {
1423014776 if (x < startX)
....@@ -14373,22 +14919,27 @@
1437314919 }
1437414920 }
1437514921
14922
+// ClickInfo clickInfo = new ClickInfo();
14923
+
1437614924 public void mouseMoved(MouseEvent e)
1437714925 {
1437814926 //System.out.println("mouseMoved: " + e);
1437914927 if (isRenderer)
1438014928 return;
1438114929
14382
- ClickInfo ci = new ClickInfo();
14383
- ci.x = e.getX();
14384
- ci.y = e.getY();
14385
- ci.modifiers = e.getModifiersEx();
14386
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14387
- ci.pane = this;
14388
- ci.camera = renderCamera;
14930
+ // Mouse cursor feedback
14931
+ object.clickInfo.x = e.getX();
14932
+ object.clickInfo.y = e.getY();
14933
+ object.clickInfo.modifiers = e.getModifiersEx();
14934
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14935
+ object.clickInfo.pane = this;
14936
+ object.clickInfo.camera = renderCamera;
1438914937 if (!isRenderer)
1439014938 {
14391
- if (object.editWindow.copy.doEditClick(ci, 0))
14939
+ //ObjEditor editWindow = object.editWindow;
14940
+ //Object3D copy = editWindow.copy;
14941
+ if (object.doEditClick(//clickInfo,
14942
+ 0))
1439214943 {
1439314944 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1439414945 } else
....@@ -14403,7 +14954,8 @@
1440314954 Globals.MOUSEDRAGGED = false;
1440414955
1440514956 movingcamera = false;
14406
- X = Y = 0;
14957
+ X = 0; // getBounds().width/2;
14958
+ Y = 0; // getBounds().height/2;
1440714959 //System.out.println("mouseReleased: " + e);
1440814960 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1440914961 }
....@@ -14659,7 +15211,8 @@
1465915211 // break;
1466015212 case 'T':
1466115213 CACHETEXTURE ^= true;
14662
- textures.clear();
15214
+ texturepigment.clear();
15215
+ texturebump.clear();
1466315216 // repaint();
1466415217 break;
1466515218 case 'Y':
....@@ -14744,7 +15297,9 @@
1474415297 case 'E' : COMPACT ^= true;
1474515298 repaint();
1474615299 break;
14747
- case 'W' : DEBUGHSB ^= true;
15300
+ case 'W' : // Wide Window (fullscreen)
15301
+ //DEBUGHSB ^= true;
15302
+ ObjEditor.theFrame.ToggleFullScreen();
1474815303 repaint();
1474915304 break;
1475015305 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14769,8 +15324,8 @@
1476915324 RevertCamera();
1477015325 repaint();
1477115326 break;
14772
- case 'L':
1477315327 case 'l':
15328
+ //case 'L':
1477415329 if (lightMode)
1477515330 {
1477615331 lightMode = false;
....@@ -14834,20 +15389,24 @@
1483415389 OCCLUSION_CULLING ^= true;
1483515390 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1483615391 break;
14837
- case '0': envyoff ^= true; repaint(); break;
15392
+ //case '0': envyoff ^= true; repaint(); break;
1483815393 case '1':
1483915394 case '2':
1484015395 case '3':
1484115396 case '4':
1484215397 case '5':
14843
- newenvy = Character.getNumericValue(key);
14844
- repaint();
14845
- break;
1484615398 case '6':
1484715399 case '7':
1484815400 case '8':
1484915401 case '9':
14850
- BGcolor = (key - '6')/3.f;
15402
+ if (true) // envyoff)
15403
+ {
15404
+ BGcolor = (key - '1')/8.f;
15405
+ }
15406
+ else
15407
+ {
15408
+ //newenvy = Character.getNumericValue(key);
15409
+ }
1485115410 repaint();
1485215411 break;
1485315412 case '!':
....@@ -14913,9 +15472,9 @@
1491315472 case '_':
1491415473 kompactbit = 5;
1491515474 break;
14916
- case '+':
14917
- kompactbit = 6;
14918
- break;
15475
+// case '+':
15476
+// kompactbit = 6;
15477
+// break;
1491915478 case ' ':
1492015479 lightMode ^= true;
1492115480 Globals.lighttouched = true;
....@@ -14927,6 +15486,7 @@
1492715486 case ESC:
1492815487 RENDERPROGRAM += 1;
1492915488 RENDERPROGRAM %= 3;
15489
+
1493015490 repaint();
1493115491 break;
1493215492 case 'Z':
....@@ -14966,8 +15526,9 @@
1496615526 case DELETE:
1496715527 ClearSelection();
1496815528 break;
14969
- /*
1497015529 case '+':
15530
+
15531
+ /*
1497115532 //fontsize += 1;
1497215533 bbzoom *= 2;
1497315534 repaint();
....@@ -14984,17 +15545,17 @@
1498415545 case '=':
1498515546 IncDepth();
1498615547 //fontsize += 1;
14987
- object.editWindow.refreshContents(true);
15548
+ object.GetWindow().refreshContents(true);
1498815549 maskbit = 6;
1498915550 break;
1499015551 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1499115552 DecDepth();
1499215553 maskbit = 5;
1499315554 //if(fontsize > 1) fontsize -= 1;
14994
- if (object.editWindow == null)
14995
- new Exception().printStackTrace();
14996
- else
14997
- object.editWindow.refreshContents(true);
15555
+// if (object.editWindow == null)
15556
+// new Exception().printStackTrace();
15557
+// else
15558
+ object.GetWindow().refreshContents(true);
1499815559 break;
1499915560 case '{':
1500015561 manipCamera.shaper_fovy /= 1.1;
....@@ -15218,7 +15779,7 @@
1521815779 }
1521915780 */
1522015781
15221
- object.editWindow.EditSelection();
15782
+ object.GetWindow().EditSelection(false);
1522215783 }
1522315784
1522415785 void SelectParent()
....@@ -15235,10 +15796,10 @@
1523515796 {
1523615797 //selectees.remove(i);
1523715798 System.out.println("select parent of " + elem);
15238
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15799
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1523915800 } else
1524015801 {
15241
- group.editWindow.Select(elem.GetTreePath(), first, true);
15802
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1524215803 }
1524315804
1524415805 first = false;
....@@ -15280,12 +15841,12 @@
1528015841 for (int j = 0; j < group.children.size(); j++)
1528115842 {
1528215843 elem = (Object3D) group.children.elementAt(j);
15283
- object.editWindow.Select(elem.GetTreePath(), first, true);
15844
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1528415845 first = false;
1528515846 }
1528615847 } else
1528715848 {
15288
- object.editWindow.Select(elem.GetTreePath(), first, true);
15849
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1528915850 }
1529015851
1529115852 first = false;
....@@ -15296,21 +15857,21 @@
1529615857 {
1529715858 //Composite group = (Composite) object;
1529815859 Object3D group = object;
15299
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15860
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1530015861 }
1530115862
1530215863 void ResetTransform(int mask)
1530315864 {
1530415865 //Composite group = (Composite) object;
1530515866 Object3D group = object;
15306
- group.editWindow.ResetTransform(mask);
15867
+ group.GetWindow().ResetTransform(mask);
1530715868 }
1530815869
1530915870 void FlipTransform()
1531015871 {
1531115872 //Composite group = (Composite) object;
1531215873 Object3D group = object;
15313
- group.editWindow.FlipTransform();
15874
+ group.GetWindow().FlipTransform();
1531415875 // group.editWindow.ReduceMesh(true);
1531515876 }
1531615877
....@@ -15318,7 +15879,7 @@
1531815879 {
1531915880 //Composite group = (Composite) object;
1532015881 Object3D group = object;
15321
- group.editWindow.PrintMemory();
15882
+ group.GetWindow().PrintMemory();
1532215883 // group.editWindow.ReduceMesh(true);
1532315884 }
1532415885
....@@ -15326,7 +15887,7 @@
1532615887 {
1532715888 //Composite group = (Composite) object;
1532815889 Object3D group = object;
15329
- group.editWindow.ResetCentroid();
15890
+ group.GetWindow().ResetCentroid();
1533015891 }
1533115892
1533215893 void IncDepth()
....@@ -15408,8 +15969,6 @@
1540815969
1540915970 int width = getBounds().width;
1541015971 int height = getBounds().height;
15411
- ClickInfo info = new ClickInfo();
15412
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1541315972 //Image img = CreateImage(width, height);
1541415973 //System.out.println("width = " + width + "; height = " + height + "\n");
1541515974
....@@ -15486,48 +16045,77 @@
1548616045 }
1548716046 if (object != null && !hasMarquee)
1548816047 {
16048
+ if (object.clickInfo == null)
16049
+ object.clickInfo = new ClickInfo();
16050
+ ClickInfo info = object.clickInfo;
16051
+ //ClickInfo info = new ClickInfo();
16052
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16053
+
1548916054 if (isRenderer)
1549016055 {
15491
- info.flags++;
16056
+ object.clickInfo.flags++;
1549216057 double frameAspect = (double) width / (double) height;
1549316058 if (frameAspect > renderCamera.aspect)
1549416059 {
1549516060 int desired = (int) ((double) height * renderCamera.aspect);
15496
- info.bounds.width -= width - desired;
15497
- info.bounds.x += (width - desired) / 2;
16061
+ object.clickInfo.bounds.width -= width - desired;
16062
+ object.clickInfo.bounds.x += (width - desired) / 2;
1549816063 } else
1549916064 {
1550016065 int desired = (int) ((double) width / renderCamera.aspect);
15501
- info.bounds.height -= height - desired;
15502
- info.bounds.y += (height - desired) / 2;
16066
+ object.clickInfo.bounds.height -= height - desired;
16067
+ object.clickInfo.bounds.y += (height - desired) / 2;
1550316068 }
1550416069 }
15505
- info.g = gr;
15506
- info.camera = renderCamera;
16070
+
16071
+ object.clickInfo.g = gr;
16072
+ object.clickInfo.camera = renderCamera;
1550716073 /*
1550816074 // Memory intensive (brep.verticescopy)
1550916075 if (!(object instanceof Composite))
1551016076 object.draw(info, 0, false); // SLOW :
1551116077 */
15512
- if (!isRenderer)
16078
+ if (!isRenderer) // && drag)
1551316079 {
15514
- object.drawEditHandles(info, 0);
15515
-
15516
- if (drag && (X != 0 || Y != 0) && object.selection.Size() > 0)
16080
+ Grafreed.Assert(object != null);
16081
+ Grafreed.Assert(object.selection != null);
16082
+ if (object.selection.Size() > 0)
1551716083 {
15518
- switch (object.selection.get(0).hitSomething)
16084
+ int hitSomething = object.selection.get(0).hitSomething;
16085
+
16086
+ object.clickInfo.DX = 0;
16087
+ object.clickInfo.DY = 0;
16088
+ object.clickInfo.W = 1;
16089
+ if (hitSomething == Object3D.hitCenter)
1551916090 {
15520
- case Object3D.hitCenter: gr.setColor(Color.pink);
15521
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15522
- break;
15523
- case Object3D.hitRotate: gr.setColor(Color.yellow);
15524
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15525
- break;
15526
- case Object3D.hitScale: gr.setColor(Color.cyan);
15527
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15528
- break;
16091
+ info.DX = X;
16092
+ if (X != 0)
16093
+ info.DX -= info.bounds.width/2;
16094
+
16095
+ info.DY = Y;
16096
+ if (Y != 0)
16097
+ info.DY -= info.bounds.height/2;
1552916098 }
15530
-
16099
+
16100
+ object.drawEditHandles(//info,
16101
+ 0);
16102
+
16103
+ if (drag && (X != 0 || Y != 0))
16104
+ {
16105
+ switch (hitSomething)
16106
+ {
16107
+ case Object3D.hitCenter: gr.setColor(Color.pink);
16108
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16109
+ break;
16110
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16111
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16112
+ break;
16113
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16114
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16115
+ break;
16116
+ }
16117
+
16118
+ }
1553116119 }
1553216120 }
1553316121 }
....@@ -16009,6 +16597,8 @@
1600916597 private /*static*/ boolean firstime;
1601016598 private /*static*/ cVector newView = new cVector();
1601116599 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16600
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16601
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1601216602 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1601316603 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1601416604 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16021,29 +16611,67 @@
1602116611 {
1602216612 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1602316613
16614
+ int usedsuf = 0;
16615
+
1602416616 for (int i = 0; i < suffixes.length; i++)
1602516617 {
16026
- String resourceName = basename + suffixes[i] + "." + suffix;
16027
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16028
- mipmapped,
16029
- FileUtil.getFileSuffix(resourceName));
16030
- if (data == null)
16618
+ String[] suffixe = suffixes;
16619
+ String[] fallback = suffixes2;
16620
+ String[] fallfallback = suffixes3;
16621
+
16622
+ for (int c=usedsuf; --c>=0;)
1603116623 {
16032
- throw new IOException("Unable to load texture " + resourceName);
16624
+// String[] temp = suffixe;
16625
+// suffixe = fallback;
16626
+// fallback = fallfallback;
16627
+// fallfallback = temp;
1603316628 }
16629
+
16630
+ String resourceName = basename + suffixe[i] + "." + suffix;
16631
+ TextureData data;
16632
+
16633
+ try
16634
+ {
16635
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16636
+ mipmapped,
16637
+ FileUtil.getFileSuffix(resourceName));
16638
+ }
16639
+ catch (Exception e)
16640
+ {
16641
+ try
16642
+ {
16643
+ resourceName = basename + fallback[i] + "." + suffix;
16644
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16645
+ mipmapped,
16646
+ FileUtil.getFileSuffix(resourceName));
16647
+ }
16648
+ catch (Exception e2)
16649
+ {
16650
+ resourceName = basename + fallfallback[i] + "." + suffix;
16651
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16652
+ mipmapped,
16653
+ FileUtil.getFileSuffix(resourceName));
16654
+ }
16655
+ }
16656
+
1603416657 //System.out.println("Target = " + targets[i]);
1603516658 cubemap.updateImage(data, targets[i]);
1603616659 }
1603716660
1603816661 return cubemap;
1603916662 }
16663
+
1604016664 int bigsphere = -1;
1604116665
1604216666 float BGcolor = 0.5f;
1604316667
16044
- private void DrawSkyBox(GL gl)
16668
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16669
+
16670
+ private void DrawSkyBox(GL gl, float ratio)
1604516671 {
16046
- if (envyoff || cubemap == null)
16672
+ if (//envyoff ||
16673
+ WIREFRAME ||
16674
+ cubemap == null)
1604716675 {
1604816676 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1604916677 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16058,7 +16686,17 @@
1605816686 // Compensates for ExaminerViewer's modification of modelview matrix
1605916687 gl.glMatrixMode(GL.GL_MODELVIEW);
1606016688 gl.glLoadIdentity();
16689
+ gl.glScalef(1,ratio,1);
1606116690
16691
+// colorV[0] = 2;
16692
+// colorV[1] = 2;
16693
+// colorV[2] = 2;
16694
+// colorV[3] = 1;
16695
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16696
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16697
+//
16698
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16699
+
1606216700 //gl.glActiveTexture(GL.GL_TEXTURE1);
1606316701 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1606416702
....@@ -16090,6 +16728,7 @@
1609016728 {
1609116729 gl.glScalef(1.0f, -1.0f, 1.0f);
1609216730 }
16731
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1609316732 gl.glMultMatrixd(viewrot_1, 0);
1609416733 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1609516734 //viewer.updateInverseRotation(gl);
....@@ -16230,16 +16869,16 @@
1623016869 cStatic.objectstack[materialdepth++] = checker;
1623116870 //System.out.println("material " + material);
1623216871 //Applet3D.tracein(this, selected);
16233
- vector2buffer = checker.projectedVertices;
16872
+ //vector2buffer = checker.projectedVertices;
1623416873
1623516874 //checker.GetMaterial().Draw(this, false); // true);
16236
- DrawMaterial(checker.GetMaterial(), false); // true);
16875
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1623716876
1623816877 materialdepth -= 1;
1623916878 if (materialdepth > 0)
1624016879 {
16241
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16242
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
16880
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16881
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1624316882 }
1624416883 //checker.GetMaterial().opacity = 1f;
1624516884 ////checker.GetMaterial().ambient = 1f;
....@@ -16325,6 +16964,14 @@
1632516964 }
1632616965 }
1632716966
16967
+ private Object3D GetFolder()
16968
+ {
16969
+ Object3D folder = object.GetWindow().copy;
16970
+ if (object.GetWindow().copy.selection.Size() > 0)
16971
+ folder = object.GetWindow().copy.selection.elementAt(0);
16972
+ return folder;
16973
+ }
16974
+
1632816975 class SelectBuffer implements GLEventListener
1632916976 {
1633016977
....@@ -16340,7 +16987,7 @@
1634016987 //new Exception().printStackTrace();
1634116988 System.out.println("select buffer init");
1634216989 // Use debug pipeline
16343
- drawable.setGL(new DebugGL(drawable.getGL()));
16990
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1634416991
1634516992 GL gl = drawable.getGL();
1634616993
....@@ -16404,6 +17051,17 @@
1640417051
1640517052 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1640617053
17054
+ if (PAINTMODE)
17055
+ {
17056
+ if (object.GetWindow().copy.selection.Size() > 0)
17057
+ {
17058
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17059
+
17060
+ // Make what you paint not selectable.
17061
+ paintobj.ResetSelectable();
17062
+ }
17063
+ }
17064
+
1640717065 //int tmp = selection_view;
1640817066 //selection_view = -1;
1640917067 int temp = DrawMode();
....@@ -16415,6 +17073,17 @@
1641517073 // temp = DEFAULT; // patch for selection debug
1641617074 Globals.drawMode = temp; // WARNING
1641717075
17076
+ if (PAINTMODE)
17077
+ {
17078
+ if (object.GetWindow().copy.selection.Size() > 0)
17079
+ {
17080
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17081
+
17082
+ // Revert.
17083
+ paintobj.RestoreSelectable();
17084
+ }
17085
+ }
17086
+
1641817087 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1641917088
1642017089 // trying different ways of getting the depth info over
....@@ -16462,6 +17131,8 @@
1646217131 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1646317132 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1646417133 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
17134
+
17135
+ CreateSelectedPoint();
1646517136
1646617137 // Will fit the mesh !!!
1646717138 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16516,29 +17187,31 @@
1651617187 }
1651717188
1651817189 if (!movingcamera && !PAINTMODE)
16519
- object.editWindow.ScreenFitPoint(); // fev 2014
17190
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1652017191
16521
- if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17192
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1652217193 {
16523
- Object3D paintobj = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17194
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1652417195
16525
- Object3D group = new Object3D("inst" + paintcount++);
17196
+ if (object.GetWindow().copy.selection.Size() > 0)
17197
+ {
17198
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1652617199
16527
- group.CreateMaterial(); // use a void leaf to select instances
16528
-
16529
- group.add(paintobj); // link
16530
-
16531
- object.editWindow.SnapObject(group);
16532
-
16533
- Object3D folder = object.editWindow.copy;
16534
-
16535
- if (object.editWindow.copy.selection.Size() > 0)
16536
- folder = object.editWindow.copy.selection.elementAt(0);
16537
-
16538
- folder.add(group);
16539
-
16540
- object.editWindow.ResetModel();
16541
- object.editWindow.refreshContents();
17200
+ Object3D inst = new Object3D("inst" + paintcount++);
17201
+
17202
+ inst.CreateMaterial(); // use a void leaf to select instances
17203
+
17204
+ inst.add(paintobj); // link
17205
+
17206
+ object.GetWindow().SnapObject(inst);
17207
+
17208
+ Object3D folder = paintFolder; // GetFolder();
17209
+
17210
+ folder.add(inst);
17211
+
17212
+ object.GetWindow().ResetModel();
17213
+ object.GetWindow().refreshContents();
17214
+ }
1654217215 }
1654317216 else
1654417217 paintcount = 0;
....@@ -16577,6 +17250,11 @@
1657717250 //System.out.println("objects[color] = " + objects[color]);
1657817251 //objects[color].Select();
1657917252 indexcount = 0;
17253
+ ObjEditor window = object.GetWindow();
17254
+ if (window != null && deselect)
17255
+ {
17256
+ window.Select(null, deselect, true);
17257
+ }
1658017258 object.Select(color, deselect);
1658117259 }
1658217260
....@@ -17102,23 +17780,15 @@
1710217780 int AAbuffersize = 0;
1710317781
1710417782 //double[] selectedpoint = new double[3];
17105
- static Superellipsoid selectedpoint = new Superellipsoid();
17783
+ static Superellipsoid selectedpoint;
1710617784 static Sphere previousselectedpoint = null;
17107
- static Sphere debugpointG = new Sphere();
17108
- static Sphere debugpointP = new Sphere();
17109
- static Sphere debugpointC = new Sphere();
17110
- static Sphere debugpointR = new Sphere();
17785
+ static Sphere debugpointG;
17786
+ static Sphere debugpointP;
17787
+ static Sphere debugpointC;
17788
+ static Sphere debugpointR;
1711117789
1711217790 static Sphere debugpoints[] = new Sphere[8];
1711317791
17114
- static
17115
- {
17116
- for (int i=0; i<8; i++)
17117
- {
17118
- debugpoints[i] = new Sphere();
17119
- }
17120
- }
17121
-
1712217792 static void InitPoints(float radius)
1712317793 {
1712417794 for (int i=0; i<8; i++)