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;
....@@ -106,7 +142,7 @@
106142 static boolean OEIL = true;
107143 static boolean OEILONCE = false; // do oeilon then oeiloff
108144 static boolean LOOKAT = true;
109
-static boolean RANDOM = true; // false;
145
+static boolean SWITCH = true; // false;
110146 static boolean HANDLES = false; // selection doesn't work!!
111147 static boolean PAINTMODE = false;
112148
....@@ -150,6 +186,20 @@
150186 defaultcaps.setAccumAlphaBits(16);
151187 }
152188
189
+ 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
+ }
202
+
153203 void SetAsGLRenderer(boolean b)
154204 {
155205 isRenderer = b;
....@@ -168,7 +218,8 @@
168218
169219 SetCamera(cam);
170220
171
- SetLight(new Camera(new cVector(10, 10, -20)));
221
+ // Warning: not used.
222
+ SetLight(new Camera(new cVector(15, 10, -20)));
172223
173224 object = o;
174225
....@@ -325,7 +376,7 @@
325376 cStatic.objectstack[materialdepth++] = obj;
326377 //System.out.println("material " + material);
327378 //Applet3D.tracein(this, selected);
328
- display.vector2buffer = obj.projectedVertices;
379
+ //display.vector2buffer = obj.projectedVertices;
329380 if (obj instanceof Camera)
330381 {
331382 display.options1[0] = material.shift;
....@@ -334,14 +385,28 @@
334385 display.options1[2] = material.shadowbias;
335386 display.options1[3] = material.aniso;
336387 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]);
337393 display.options2[0] = material.opacity;
338394 display.options2[1] = material.diffuse;
339395 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]);
340399
341400 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]);
342404 display.options4[0] = material.cameralight/0.2f;
343405 display.options4[1] = material.subsurface;
344406 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]);
345410
346411 // if (display.CURRENTANTIALIAS > 0)
347412 // display.options3[3] /= 4;
....@@ -357,7 +422,7 @@
357422 /**/
358423 } else
359424 {
360
- DrawMaterial(material, selected);
425
+ DrawMaterial(material, selected, obj.projectedVertices);
361426 }
362427 } else
363428 {
....@@ -381,8 +446,8 @@
381446 cStatic.objectstack[materialdepth++] = obj;
382447 //System.out.println("material " + material);
383448 //Applet3D.tracein("selected ", selected);
384
- display.vector2buffer = obj.projectedVertices;
385
- display.DrawMaterial(material, selected);
449
+ //display.vector2buffer = obj.projectedVertices;
450
+ display.DrawMaterial(material, selected, obj.projectedVertices);
386451 }
387452 }
388453
....@@ -399,8 +464,8 @@
399464 materialdepth -= 1;
400465 if (materialdepth > 0)
401466 {
402
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
403
- 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);
404469 }
405470 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
406471 } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
....@@ -420,8 +485,8 @@
420485 materialdepth -= 1;
421486 if (materialdepth > 0)
422487 {
423
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
424
- 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);
425490 }
426491 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
427492 //else
....@@ -462,10 +527,12 @@
462527 if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
463528 {
464529 //gl.glBegin(gl.GL_TRIANGLES);
465
- 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
+ ;
466533 if (!hasnorm)
467534 {
468
- // System.out.println("FUCK!!");
535
+ // System.out.println("Mesh normal");
469536 LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
470537 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
471538 LA.vecCross(obj.v0, obj.v1, obj.v2);
....@@ -1190,10 +1257,12 @@
11901257 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
11911258 }
11921259 }
1260
+
11931261 if (flipV)
11941262 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
11951263 else
11961264 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1265
+
11971266 //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
11981267 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
11991268
....@@ -1213,10 +1282,12 @@
12131282 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
12141283 }
12151284 }
1285
+
12161286 if (flipV)
12171287 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12181288 else
12191289 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1290
+
12201291 //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
12211292 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
12221293
....@@ -1244,8 +1315,10 @@
12441315 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12451316 else
12461317 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1318
+
12471319 //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
12481320 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1321
+
12491322 count2 += 2;
12501323 count3 += 3;
12511324 }
....@@ -1424,6 +1497,8 @@
14241497 gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
14251498 }
14261499
1500
+ float[] colorV = new float[4];
1501
+
14271502 void SetColor(Object3D obj, Vertex p0)
14281503 {
14291504 CameraPane display = this;
....@@ -1491,8 +1566,6 @@
14911566 {
14921567 return;
14931568 }
1494
-
1495
- float[] colorV = new float[3];
14961569
14971570 if (false) // marked)
14981571 {
....@@ -1601,7 +1674,7 @@
16011674 // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
16021675 }
16031676
1604
- void DrawMaterial(cMaterial material, boolean selected)
1677
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
16051678 {
16061679 CameraPane display = this;
16071680 //new Exception().printStackTrace();
....@@ -1628,7 +1701,7 @@
16281701
16291702 cColor.HSBtoRGB(display.color, display.saturation, 1, display.modelParams0);
16301703
1631
- float[] colorV = GrafreeD.colorV;
1704
+ float[] colorV = Grafreed.colorV;
16321705
16331706 /**/
16341707 if (display.DrawMode() == display.DEFAULT) // && display.RENDERPROGRAM == 0)
....@@ -1636,7 +1709,7 @@
16361709 colorV[0] = display.modelParams0[0] * material.diffuse;
16371710 colorV[1] = display.modelParams0[1] * material.diffuse;
16381711 colorV[2] = display.modelParams0[2] * material.diffuse;
1639
- colorV[3] = material.opacity;
1712
+ colorV[3] = 1; // material.opacity;
16401713
16411714 gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
16421715 //System.out.println("Opacity = " + opacity);
....@@ -1744,9 +1817,9 @@
17441817 display.modelParams7[2] = 0;
17451818 display.modelParams7[3] = 0;
17461819
1747
- display.modelParams6[0] = 100; // criss de bug de bump
1820
+ //display.modelParams6[0] = 100; // criss de bug de bump
17481821
1749
- Object3D.cVector2[] extparams = display.vector2buffer;
1822
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
17501823 if (extparams != null && extparams.length > 0 && extparams[0] != null)
17511824 {
17521825 display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
....@@ -1888,7 +1961,7 @@
18881961 void PushMatrix(double[][] matrix)
18891962 {
18901963 // GrafreeD.tracein(matrix);
1891
- PushMatrix(matrix,1);
1964
+ PushMatrix(matrix, 1);
18921965 }
18931966
18941967 void PushMatrix()
....@@ -2042,7 +2115,7 @@
20422115 //System.err.println("Oeil on");
20432116 OEIL = true;
20442117 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2045
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2118
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
20462119 //pingthread.StepToTarget(true);
20472120 }
20482121
....@@ -2140,7 +2213,7 @@
21402213 System.err.println("LIVE = " + Globals.isLIVE());
21412214
21422215 if (!Globals.isLIVE()) // save sound
2143
- GrafreeD.savesound = true; // wav.save();
2216
+ Grafreed.savesound = true; // wav.save();
21442217 // else
21452218 repaint(); // start loop // may 2013
21462219 }
....@@ -2257,7 +2330,7 @@
22572330
22582331 void ToggleDebug()
22592332 {
2260
- DEBUG ^= true;
2333
+ Globals.DEBUG ^= true;
22612334 }
22622335
22632336 void ToggleLookAt()
....@@ -2265,9 +2338,9 @@
22652338 LOOKAT ^= true;
22662339 }
22672340
2268
- void ToggleRandom()
2341
+ void ToggleSwitch()
22692342 {
2270
- RANDOM ^= true;
2343
+ SWITCH ^= true;
22712344 }
22722345
22732346 void ToggleHandles()
....@@ -2275,10 +2348,17 @@
22752348 HANDLES ^= true;
22762349 }
22772350
2351
+ Object3D paintFolder;
2352
+
22782353 void TogglePaint()
22792354 {
22802355 PAINTMODE ^= true;
22812356 paintcount = 0;
2357
+
2358
+ if (PAINTMODE)
2359
+ {
2360
+ paintFolder = GetFolder();
2361
+ }
22822362 }
22832363
22842364 void SwapCamera(int a, int b)
....@@ -2374,7 +2454,22 @@
23742454 {
23752455 return currentGL;
23762456 }
2377
-
2457
+
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
+
23782473 /**/
23792474 class CacheTexture
23802475 {
....@@ -2383,28 +2478,31 @@
23832478
23842479 int resolution;
23852480
2386
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2481
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
23872482 {
2388
- texture = tex;
2483
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2484
+ texturedata = texdata;
23892485 resolution = res;
23902486 }
23912487 }
23922488 /**/
23932489
23942490 // TEXTURE static Texture texture;
2395
- static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures
2396
- = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>();
2397
- 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
+
23982496 int pigmentdepth = 0;
23992497 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
24002498 int bumpdepth = 0;
24012499 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
24022500 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
24032501 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2404
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2502
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
24052503 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
24062504
2407
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2505
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
24082506 {
24092507 TextureData texturedata = null;
24102508
....@@ -2423,13 +2521,34 @@
24232521 if (bump)
24242522 texturedata = ConvertBump(texturedata, false);
24252523
2426
- com.sun.opengl.util.texture.Texture texture =
2427
- 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);
24282526
2429
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2430
- 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);
24312529
2432
- 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;
24332552 }
24342553
24352554 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3502,6 +3621,8 @@
35023621
35033622 System.out.println("LOADING TEXTURE : " + name);
35043623
3624
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3625
+
35053626 //
35063627 if (false) // compressbit > 0)
35073628 {
....@@ -7900,7 +8021,7 @@
79008021 String pigment = Object3D.GetPigment(tex);
79018022 String bump = Object3D.GetBump(tex);
79028023
7903
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8024
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79048025 {
79058026 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79068027 // System.out.println("; bump = " + bump);
....@@ -7915,11 +8036,69 @@
79158036 pigment = null;
79168037 }
79178038
7918
- ReleaseTexture(bump, true);
7919
- ReleaseTexture(pigment, false);
8039
+ ReleaseTexture(tex, true);
8040
+ ReleaseTexture(tex, false);
79208041 }
79218042
7922
- 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)
79238102 {
79248103 if (// DrawMode() != 0 || /*tex == null ||*/
79258104 ambientOcclusion ) // || !textureon)
....@@ -7930,7 +8109,7 @@
79308109 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
79318110
79328111 if (tex != null)
7933
- texture = textures.get(tex);
8112
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
79348113
79358114 // //assert( texture != null );
79368115 // if (texture == null)
....@@ -8022,7 +8201,55 @@
80228201 }
80238202 }
80248203
8025
- /*boolean*/ public void BindTextures(cTexture tex, int resolution) // INTERFACE
8204
+ /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
8205
+ {
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
80268253 {
80278254 if (// DrawMode() != 0 || /*tex == null ||*/
80288255 ambientOcclusion ) // || !textureon)
....@@ -8033,17 +8260,47 @@
80338260 if (tex == null)
80348261 {
80358262 BindTexture(null,false,resolution);
8036
- BindTexture(null,true,resolution);
80378263 return;
80388264 }
80398265
80408266 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
+
80418299 String bump = Object3D.GetBump(tex);
80428300
8043
- usedtextures.put(pigment, pigment);
8044
- usedtextures.put(bump, bump);
8301
+ usedtextures.add(tex);
80458302
8046
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8303
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
80478304 {
80488305 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
80498306 // System.out.println("; bump = " + bump);
....@@ -8053,43 +8310,94 @@
80538310 {
80548311 bump = null;
80558312 }
8056
- if (pigment.equals(""))
8057
- {
8058
- pigment = null;
8059
- }
80608313
8061
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8062
- BindTexture(pigment, false, resolution);
80638314 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8064
- BindTexture(bump, true, resolution);
8315
+ BindTexture(tex, true, resolution);
80658316 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8066
-
8067
- return; // true;
80688317 }
80698318
8070
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution)
8319
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8320
+
8321
+ private boolean FileExists(String tex)
80718322 {
8072
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8323
+ if (missingTextures.contains(tex))
8324
+ {
8325
+ return false;
8326
+ }
8327
+
8328
+ boolean fileExists = new File(tex).exists();
8329
+
8330
+ if (!fileExists)
8331
+ {
8332
+ // If file exists, the "new File()" is not executed sgain
8333
+ missingTextures.add(tex);
8334
+ }
8335
+
8336
+ return fileExists;
8337
+ }
8338
+
8339
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
8340
+ {
8341
+ CacheTexture texturecache = null;
80738342
80748343 if (tex != null)
80758344 {
8076
- String texname = tex;
8345
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8346
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
80778347
8078
- String[] split = tex.split("Textures");
8079
- if (split.length > 1)
8080
- texname = "/Users/nbriere/Textures" + split[split.length-1];
8081
- else
8082
- if (!texname.startsWith("/"))
8083
- texname = "/Users/nbriere/Textures/" + texname;
8348
+ if (texname.equals("") && texdata == null)
8349
+ {
8350
+ return null;
8351
+ }
8352
+
8353
+ String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
8354
+
8355
+// String[] split = tex.split("Textures");
8356
+// if (split.length > 1)
8357
+// texname = "/Users/nbriere/Textures" + split[split.length-1];
8358
+// else
8359
+// if (!texname.startsWith("/"))
8360
+// texname = "/Users/nbriere/Textures/" + texname;
8361
+ if (!FileExists(texname) && !texname.startsWith("@"))
8362
+ {
8363
+ texname = fallbackTextureName;
8364
+ }
80848365
80858366 if (CACHETEXTURE)
8086
- texture = textures.get(texname); // TEXTURE CACHE
8087
-
8088
- TextureData texturedata = null;
8089
-
8090
- if (texture == null || texture.resolution < resolution)
80918367 {
8092
- 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(""))
80938401 {
80948402 assert(!bump);
80958403 // if (bump)
....@@ -8100,19 +8408,23 @@
81008408 // }
81018409 // else
81028410 // {
8103
- texture = textures.get(tex);
8104
- if (texture == null)
8411
+ // texturecache = textures.get(texname); // suspicious
8412
+ if (texturecache == null)
81058413 {
8106
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8414
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
81078415 }
8416
+ else
8417
+ new Exception().printStackTrace();
81088418 // }
81098419 } else
8110
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8420
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
81118421 {
81128422 assert(bump);
8113
- texture = textures.get(tex);
8114
- if (texture == null)
8115
- 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();
81168428 } else
81178429 {
81188430 //if (tex.equals("IMMORTAL"))
....@@ -8120,11 +8432,22 @@
81208432 // texture = GetResourceTexture("default.png");
81218433 //} else
81228434 //{
8123
- if (tex.equals("WHITE_NOISE"))
8435
+ if (texname.endsWith("WHITE_NOISE"))
81248436 {
8125
- texture = textures.get(tex);
8126
- if (texture == null)
8127
- 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();
81288451 } else
81298452 {
81308453 if (textureon)
....@@ -8149,7 +8472,7 @@
81498472 }
81508473
81518474 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
8152
- if (!new File(cachename).exists())
8475
+ if (!FileExists(cachename))
81538476 cachename = texname;
81548477 else
81558478 processbump = false; // don't process bump map again
....@@ -8171,7 +8494,7 @@
81718494 }
81728495
81738496 cachename = texname.substring(0, texname.length()-4)+ext+".png";
8174
- if (!new File(cachename).exists())
8497
+ if (!FileExists(cachename))
81758498 cachename = texname;
81768499 else
81778500 processbump = false; // don't process bump map again
....@@ -8180,20 +8503,23 @@
81808503 texturedata = GetFileTexture(cachename, processbump, resolution);
81818504
81828505
8183
- if (texturedata != null)
8184
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8506
+ if (texturedata == null)
8507
+ throw new Exception();
8508
+
8509
+ texturecache = new CacheTexture(texturedata,resolution);
81858510 //texture = GetTexture(tex, bump);
81868511 }
8512
+ }
81878513 }
81888514 //}
81898515 }
81908516
8191
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8517
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
81928518 {
81938519 //return false;
81948520
81958521 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8196
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8522
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
81978523 {
81988524 // String ext = "_highres";
81998525 // if (REDUCETEXTURE)
....@@ -8210,52 +8536,17 @@
82108536 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
82118537 if (!cachefile.exists())
82128538 {
8213
- // cache to disk
8214
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
8215
- //buffers[0].
8216
-
8217
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
8218
- int[] pixels = new int[bytebuf.capacity()/3];
8219
-
8220
- // squared size heuristic...
8221
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8539
+ //if (texturedata.getWidth() == texturedata.getHeight())
82228540 {
8223
- for (int i=pixels.length; --i>=0;)
8224
- {
8225
- int i3 = i*3;
8226
- pixels[i] = 0xFF;
8227
- pixels[i] <<= 8;
8228
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
8229
- pixels[i] <<= 8;
8230
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
8231
- pixels[i] <<= 8;
8232
- pixels[i] |= bytebuf.get(i3) & 0xFF;
8233
- }
8234
-
8235
- /*
8236
- int r=0,g=0,b=0,a=0;
8237
- for (int i=0; i<width; i++)
8238
- for (int j=0; j<height; j++)
8239
- {
8240
- int index = j*width+i;
8241
- int p = pixels[index];
8242
- a = ((p>>24) & 0xFF);
8243
- r = ((p>>16) & 0xFF);
8244
- g = ((p>>8) & 0xFF);
8245
- b = (p & 0xFF);
8246
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
8247
- }
8248
- /**/
8249
- int width = (int)Math.sqrt(pixels.length); // squared
8250
- int height = width;
8251
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
8252
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8541
+ BufferedImage rendImage = CreateBim(texturedata);
8542
+
82538543 ImageWriter writer = null;
82548544 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
82558545 if (iter.hasNext()) {
82568546 writer = (ImageWriter)iter.next();
82578547 }
8258
- float compressionQuality = 0.9f;
8548
+
8549
+ float compressionQuality = 0.85f;
82598550 try
82608551 {
82618552 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8272,18 +8563,20 @@
82728563 }
82738564 }
82748565 }
8275
-
8566
+
8567
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8568
+
82768569 //System.out.println("Texture = " + tex);
8277
- if (textures.containsKey(texname))
8570
+ if (textures.containsKey(tex))
82788571 {
8279
- CacheTexture thetex = textures.get(texname);
8572
+ CacheTexture thetex = textures.get(tex);
82808573 thetex.texture.disable();
82818574 thetex.texture.dispose();
8282
- textures.remove(texname);
8575
+ textures.remove(tex);
82838576 }
82848577
8285
- texture.texturedata = texturedata;
8286
- textures.put(texname, texture);
8578
+ //texture.texturedata = texturedata;
8579
+ textures.put(tex, texturecache);
82878580
82888581 // newtex = true;
82898582 }
....@@ -8299,10 +8592,44 @@
82998592 }
83008593 }
83018594
8302
- return texture;
8595
+ return texturecache;
83038596 }
83048597
8305
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution)
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
83068633 {
83078634 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
83088635
....@@ -8320,21 +8647,21 @@
83208647 return texture!=null?texture.texture:null;
83218648 }
83228649
8323
- public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution)
8650
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
83248651 {
83258652 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
83268653
83278654 return texture!=null?texture.texturedata:null;
83288655 }
83298656
8330
- boolean BindTexture(String tex, boolean bump, int resolution)
8657
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
83318658 {
83328659 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
83338660 {
83348661 return false;
83358662 }
83368663
8337
- boolean newtex = false;
8664
+ //boolean newtex = false;
83388665
83398666 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
83408667
....@@ -8366,9 +8693,75 @@
83668693 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
83678694 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
83688695
8369
- return newtex;
8696
+ return true; // Warning: not used.
83708697 }
83718698
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
+
83728765 ShadowBuffer shadowPBuf;
83738766 AntialiasBuffer antialiasPBuf;
83748767 int MAXSTACK;
....@@ -8385,10 +8778,12 @@
83858778
83868779 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
83878780 MAXSTACK = temp[0];
8388
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8781
+ if (Globals.DEBUG)
8782
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
83898783 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
83908784 MAXSTACK = temp[0];
8391
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8785
+ if (Globals.DEBUG)
8786
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
83928787
83938788 // Use debug pipeline
83948789 //drawable.setGL(new DebugGL(gl)); //
....@@ -8396,7 +8791,8 @@
83968791 gl = drawable.getGL(); //
83978792
83988793 GL gl3 = getGL();
8399
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8794
+ if (Globals.DEBUG)
8795
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
84008796
84018797
84028798 //float pos[] = { 100, 100, 100, 0 };
....@@ -8561,7 +8957,7 @@
85618957
85628958 if (cubemap == null)
85638959 {
8564
- LoadEnvy(5);
8960
+ //LoadEnvy(1);
85658961 }
85668962
85678963 //cubemap.enable();
....@@ -8848,37 +9244,58 @@
88489244 cubemap = null;
88499245 return;
88509246 case 1:
8851
- name = "cubemaps/box_";
8852
- ext = "png";
9247
+ name = "cubemaps/rgb/";
9248
+ ext = "jpg";
88539249 reverseUP = false;
88549250 break;
88559251 case 2:
8856
- name = "cubemaps/uffizi_";
8857
- ext = "png";
8858
- break; // reverseUP = true; break;
9252
+ name = "cubemaps/uffizi/";
9253
+ ext = "jpg";
9254
+ reverseUP = false;
9255
+ break;
88599256 case 3:
8860
- name = "cubemaps/CloudyHills_";
8861
- ext = "tga";
9257
+ name = "cubemaps/CloudyHills/";
9258
+ ext = "jpg";
88629259 reverseUP = false;
88639260 break;
88649261 case 4:
8865
- name = "cubemaps/cornell_";
9262
+ name = "cubemaps/cornell/";
88669263 ext = "png";
88679264 reverseUP = false;
88689265 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;
88699291 default:
8870
- name = "cubemaps/rgb_";
8871
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9292
+ name = "cubemaps/box/";
9293
+ ext = "png"; /*mipmap = true;*/
9294
+ reverseUP = false;
88729295 break;
88739296 }
8874
-
8875
- try
8876
- {
8877
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
8878
- } catch (IOException e)
8879
- {
8880
- throw new RuntimeException(e);
8881
- }
9297
+
9298
+ LoadSkybox(name, ext, mipmap);
88829299 }
88839300
88849301 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -8910,8 +9327,12 @@
89109327 static double[] model = new double[16];
89119328 double[] camera2light = new double[16];
89129329 double[] light2camera = new double[16];
8913
- int newenvy = -1;
8914
- boolean envyoff = true; // false;
9330
+
9331
+ //int newenvy = -1;
9332
+ //boolean envyoff = false;
9333
+
9334
+ String loadedskyboxname;
9335
+
89159336 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
89169337 //float[] light0 = { 0,0,0 };
89179338 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9204,11 +9625,35 @@
92049625 jy8[3] = 0.5f;
92059626 }
92069627
9207
- 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
92089629 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
92099630 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
92109631 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
92119632
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
+
92129657 static int imagecount = 0; // movie generation
92139658
92149659 static int jitter = 0;
....@@ -9304,8 +9749,8 @@
93049749 assert (parentcam != renderCamera);
93059750
93069751 if (renderCamera != lightCamera)
9307
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9308
- LA.matConcat(matrix, parentcam.toParent, matrix);
9752
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9753
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
93099754
93109755 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
93119756
....@@ -9320,8 +9765,8 @@
93209765 LA.matCopy(renderCamera.fromScreen, matrix);
93219766
93229767 if (renderCamera != lightCamera)
9323
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9324
- LA.matConcat(parentcam.fromParent, matrix, matrix);
9768
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9769
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
93259770
93269771 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
93279772
....@@ -9367,10 +9812,12 @@
93679812 rati = 1 / rati;
93689813 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
93699814 }
9370
- assert (newenvy == -1);
9815
+
9816
+ //assert (newenvy == -1);
9817
+
93719818 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
93729819 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9373
- DrawSkyBox(gl);
9820
+ DrawSkyBox(gl, (float)rati);
93749821 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
93759822 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
93769823 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -9538,7 +9985,7 @@
95389985
95399986 if (!BOXMODE)
95409987 {
9541
- System.out.println("image: " + fullname + " (wav cursor=" + (GrafreeD.wav.cursor / 735 / 4) + ")");
9988
+ System.out.println("image: " + fullname + " (wav cursor=" + (Grafreed.wav.cursor / 735 / 4) + ")");
95429989 }
95439990
95449991 if (!BOXMODE)
....@@ -9576,7 +10023,7 @@
957610023 ABORTED = false;
957710024 }
957810025 else
9579
- GrafreeD.wav.cursor += 735 * ACSIZE;
10026
+ Grafreed.wav.cursor += 735 * ACSIZE;
958010027
958110028 if (false)
958210029 {
....@@ -10239,11 +10686,11 @@
1023910686
1024010687 public void display(GLAutoDrawable drawable)
1024110688 {
10242
- if (GrafreeD.savesound && GrafreeD.hassound)
10689
+ if (Grafreed.savesound && Grafreed.hassound)
1024310690 {
10244
- GrafreeD.wav.save();
10245
- GrafreeD.savesound = false;
10246
- GrafreeD.hassound = false;
10691
+ Grafreed.wav.save();
10692
+ Grafreed.savesound = false;
10693
+ Grafreed.hassound = false;
1024710694 }
1024810695 // if (DEBUG_SELECTION)
1024910696 // {
....@@ -10319,6 +10766,7 @@
1031910766 ANTIALIAS = 0;
1032010767 //System.out.println("RESTART");
1032110768 AAtimer.restart();
10769
+ Globals.TIMERRUNNING = true;
1032210770 }
1032310771 }
1032410772 }
....@@ -10373,7 +10821,7 @@
1037310821 Object3D theobject = object;
1037410822 Object3D theparent = object.parent;
1037510823 object.parent = null;
10376
- object = (Object3D)GrafreeD.clone(object);
10824
+ object = (Object3D)Grafreed.clone(object);
1037710825 object.Stripify();
1037810826 if (theobject.selection == null || theobject.selection.Size() == 0)
1037910827 theobject.PreprocessOcclusion(this);
....@@ -10386,13 +10834,14 @@
1038610834 ambientOcclusion = false;
1038710835 }
1038810836
10389
- if (Globals.lighttouched && DrawMode() == DEFAULT && !lightMode) // && !FROZEN)
10837
+ if (//Globals.lighttouched &&
10838
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1039010839 {
1039110840 //if (RENDERSHADOW) // ?
1039210841 if (!IsFrozen())
1039310842 {
1039410843 // dec 2012
10395
- if (!ambientOcclusion && !(!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0))
10844
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
1039610845 {
1039710846 Globals.framecount++;
1039810847 shadowbuffer.display();
....@@ -10405,7 +10854,7 @@
1040510854
1040610855 if (wait)
1040710856 {
10408
- Sleep(500);
10857
+ Sleep(200); // blocks everything
1040910858
1041010859 wait = false;
1041110860 }
....@@ -10519,8 +10968,8 @@
1051910968
1052010969 // if (parentcam != renderCamera) // not a light
1052110970 if (cam != lightCamera)
10522
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10523
- LA.matConcat(matrix, parentcam.toParent, matrix);
10971
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10972
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1052410973
1052510974 for (int j = 0; j < 4; j++)
1052610975 {
....@@ -10534,8 +10983,8 @@
1053410983
1053510984 // if (parentcam != renderCamera) // not a light
1053610985 if (cam != lightCamera)
10537
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10538
- LA.matConcat(parentcam.fromParent, matrix, matrix);
10986
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10987
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1053910988
1054010989 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1054110990
....@@ -10621,13 +11070,27 @@
1062111070 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1062211071 }
1062311072
10624
- if (newenvy > -1)
11073
+// if (newenvy > -1)
11074
+// {
11075
+// LoadEnvy(newenvy);
11076
+// }
11077
+//
11078
+// newenvy = -1;
11079
+
11080
+ if (object.skyboxname != null)
1062511081 {
10626
- LoadEnvy(newenvy);
11082
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11083
+ {
11084
+ LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11085
+ loadedskyboxname = object.skyboxname;
11086
+ }
1062711087 }
10628
-
10629
- newenvy = -1;
10630
-
11088
+ else
11089
+ {
11090
+ cubemap = null;
11091
+ loadedskyboxname = null;
11092
+ }
11093
+
1063111094 ratio = ((double) getWidth()) / getHeight();
1063211095 //System.out.println("ratio = " + ratio);
1063311096
....@@ -10643,7 +11106,7 @@
1064311106
1064411107 if (!IsFrozen() && !ambientOcclusion)
1064511108 {
10646
- DrawSkyBox(gl);
11109
+ DrawSkyBox(gl, (float)ratio);
1064711110 }
1064811111
1064911112 //if (selection_view == -1)
....@@ -10794,7 +11257,16 @@
1079411257 // Bump noise
1079511258 gl.glActiveTexture(GL.GL_TEXTURE6);
1079611259 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
10797
- BindTexture(NOISE_TEXTURE, false, 2);
11260
+
11261
+ try
11262
+ {
11263
+ BindTexture(NOISE_TEXTURE, false, 2);
11264
+ }
11265
+ catch (Exception e)
11266
+ {
11267
+ System.err.println("FAILED: " + NOISE_TEXTURE);
11268
+ }
11269
+
1079811270
1079911271 gl.glActiveTexture(GL.GL_TEXTURE0);
1080011272 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -10817,9 +11289,9 @@
1081711289
1081811290 gl.glMatrixMode(GL.GL_MODELVIEW);
1081911291
10820
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10821
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10822
-//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);
1082311295 } else
1082411296 {
1082511297 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -10830,7 +11302,7 @@
1083011302 //System.out.println("BLENDING ON");
1083111303 gl.glEnable(GL.GL_BLEND);
1083211304 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
10833
-
11305
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1083411306 gl.glMatrixMode(gl.GL_PROJECTION);
1083511307 gl.glLoadIdentity();
1083611308
....@@ -10919,8 +11391,8 @@
1091911391 System.err.println("parentcam != renderCamera");
1092011392
1092111393 // if (cam != lightCamera)
10922
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10923
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11394
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11395
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1092411396 }
1092511397
1092611398 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -10941,8 +11413,8 @@
1094111413 if (true) // TODO
1094211414 {
1094311415 if (cam != lightCamera)
10944
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10945
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11416
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11417
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
1094611418 }
1094711419
1094811420 LA.xformPos(light0, cam.toScreen, light0);
....@@ -11079,7 +11551,7 @@
1107911551 }
1108011552 }
1108111553
11082
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11554
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1108311555 {
1108411556 //gl.glDepthFunc(GL.GL_LEQUAL);
1108511557 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11087,24 +11559,21 @@
1108711559
1108811560 boolean texon = textureon;
1108911561
11090
- if (RENDERPROGRAM > 0)
11091
- {
11092
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11093
- textureon = false;
11094
- }
11562
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11563
+ textureon = false;
11564
+
1109511565 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1109611566 //System.out.println("ALLO");
1109711567 gl.glColorMask(false, false, false, false);
1109811568 DrawObject(gl);
11099
- if (RENDERPROGRAM > 0)
11100
- {
11101
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11102
- textureon = texon;
11103
- }
11569
+
11570
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11571
+ textureon = texon;
11572
+
1110411573 gl.glColorMask(true, true, true, true);
1110511574
1110611575 gl.glDepthFunc(GL.GL_EQUAL);
11107
- //gl.glDepthMask(false);
11576
+ gl.glDepthMask(false);
1110811577 }
1110911578
1111011579 if (false) // DrawMode() == SHADOW)
....@@ -11279,23 +11748,44 @@
1127911748 e.printStackTrace();
1128011749 }
1128111750
11282
- if (GrafreeD.RENDERME > 0)
11283
- GrafreeD.RENDERME--; // mechante magouille
11751
+ if (Grafreed.RENDERME > 0)
11752
+ Grafreed.RENDERME--; // mechante magouille
1128411753
1128511754 Globals.ONESTEP = false;
1128611755 }
1128711756
1128811757 static boolean zoomonce = false;
1128911758
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
+
1129011777 void DrawObject(GL gl, boolean draw)
1129111778 {
11779
+ // To clear camera values
11780
+ ResetOptions();
11781
+
1129211782 //System.out.println("DRAW OBJECT " + mouseDown);
1129311783 // DrawMode() = SELECTION;
1129411784 //GL gl = getGL();
1129511785 if ((TRACK || SHADOWTRACK) || zoomonce)
1129611786 {
1129711787 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11298
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11788
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1129911789 pingthread.StepToTarget(true); // true);
1130011790 // zoomonce = false;
1130111791 }
....@@ -11350,7 +11840,14 @@
1135011840
1135111841 usedtextures.clear();
1135211842
11353
- BindTextures(DEFAULT_TEXTURES, 2);
11843
+ try
11844
+ {
11845
+ BindTextures(DEFAULT_TEXTURES, 2);
11846
+ }
11847
+ catch (Exception e)
11848
+ {
11849
+ System.err.println("FAILED: " + DEFAULT_TEXTURES);
11850
+ }
1135411851 }
1135511852 //System.out.println("--> " + stackdepth);
1135611853 // GrafreeD.traceon();
....@@ -11360,8 +11857,9 @@
1136011857
1136111858 if (DrawMode() == DEFAULT)
1136211859 {
11363
- if (DEBUG)
11860
+ if (Globals.DEBUG)
1136411861 {
11862
+ CreateSelectedPoint();
1136511863 float radius = 0.05f;
1136611864 if (selectedpoint.radius != radius)
1136711865 {
....@@ -11415,20 +11913,32 @@
1141511913 ReleaseTextures(DEFAULT_TEXTURES);
1141611914
1141711915 if (CLEANCACHE)
11418
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11916
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1141911917 {
11420
- String tex = e.nextElement();
11918
+ cTexture tex = e.nextElement();
1142111919
1142211920 // System.out.println("Texture --------- " + tex);
1142311921
11424
- if (tex.equals("WHITE_NOISE"))
11922
+ if (tex.equals("WHITE_NOISE:"))
1142511923 continue;
1142611924
11427
- if (!usedtextures.containsKey(tex))
11925
+ if (!usedtextures.contains(tex))
1142811926 {
11927
+ CacheTexture gettex = texturepigment.get(tex);
1142911928 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11430
- textures.get(tex).texture.dispose();
11431
- 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
+ }
1143211942 }
1143311943 }
1143411944 }
....@@ -11441,7 +11951,14 @@
1144111951 if (checker != null && DrawMode() == DEFAULT)
1144211952 {
1144311953 //BindTexture(IMMORTAL_TEXTURE);
11444
- BindTextures(checker.GetTextures(), checker.texres);
11954
+ try
11955
+ {
11956
+ BindTextures(checker.GetTextures(), checker.texres);
11957
+ }
11958
+ catch (Exception e)
11959
+ {
11960
+ System.err.println("FAILED: " + checker.GetTextures());
11961
+ }
1144511962 // NEAREST
1144611963 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
1144711964 DrawChecker(gl);
....@@ -11523,7 +12040,7 @@
1152312040 return;
1152412041 }
1152512042
11526
- String string = obj.GetToolTip();
12043
+ String string = obj.toString(); //.GetToolTip();
1152712044
1152812045 GL gl = GetGL();
1152912046
....@@ -11840,8 +12357,8 @@
1184012357 //obj.TransformToWorld(light, light);
1184112358 for (int i = tp.size(); --i >= 0;)
1184212359 {
11843
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
11844
- LA.xformPos(light, tp.get(i).toParent, light);
12360
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12361
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1184512362 }
1184612363
1184712364
....@@ -11858,8 +12375,8 @@
1185812375 parentcam = cameras[0];
1185912376 }
1186012377
11861
- for (int count = parentcam.GetTransformCount(); --count>=0;)
11862
- LA.xformPos(light, parentcam.toParent, light); // may 2013
12378
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
12379
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1186312380
1186412381 LA.xformPos(light, renderCamera.toScreen, light);
1186512382
....@@ -11949,8 +12466,76 @@
1194912466
1195012467 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1195112468
11952
- String program =
12469
+ String programmin =
12470
+ // Min shader
1195312471 "!!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
+
1195412539 //"OPTION ARB_fragment_program_shadow;" +
1195512540 "PARAM light2cam0 = program.env[10];" +
1195612541 "PARAM light2cam1 = program.env[11];" +
....@@ -12065,8 +12650,7 @@
1206512650 "TEMP shininess;" +
1206612651 "\n" +
1206712652 "MOV texSamp, one;" +
12068
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12069
-
12653
+
1207012654 "MOV mapgrid.x, one2048th.x;" +
1207112655 "MOV temp, fragment.texcoord[1];" +
1207212656 /*
....@@ -12087,20 +12671,20 @@
1208712671 "MUL temp, floor, mapgrid.x;" +
1208812672 //"TEX depth0, temp, texture[1], 2D;" +
1208912673 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12090
- TextureFetch("depth0", "temp", "1") +
12674
+ ShadowTextureFetch("depth0", "temp", "1") +
1209112675 "") +
1209212676 "ADD temp.x, temp.x, mapgrid.x;" +
1209312677 //"TEX depth1, temp, texture[1], 2D;" +
1209412678 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12095
- TextureFetch("depth1", "temp", "1") +
12679
+ ShadowTextureFetch("depth1", "temp", "1") +
1209612680 "") +
1209712681 "ADD temp.y, temp.y, mapgrid.x;" +
1209812682 //"TEX depth2, temp, texture[1], 2D;" +
12099
- TextureFetch("depth2", "temp", "1") +
12683
+ ShadowTextureFetch("depth2", "temp", "1") +
1210012684 "SUB temp.x, temp.x, mapgrid.x;" +
1210112685 //"TEX depth3, temp, texture[1], 2D;" +
1210212686 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12103
- TextureFetch("depth3", "temp", "1") +
12687
+ ShadowTextureFetch("depth3", "temp", "1") +
1210412688 "") +
1210512689 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1210612690 //"MOV params, material;" +
....@@ -12471,10 +13055,10 @@
1247113055 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1247213056 "") +
1247313057
12474
- // display shadow only (bump == 0)
13058
+ // display shadow only (fakedepth == 0)
1247513059 "SUB temp.x, half.x, shadow.x;" +
12476
- "MOV temp.y, -params6.x;" +
12477
- "SLT temp.z, temp.y, zero.x;" +
13060
+ "MOV temp.y, -params5.z;" + // params6.x;" +
13061
+ "SLT temp.z, temp.y, -c256i.x;" +
1247813062 "SUB temp.y, one.x, temp.z;" +
1247913063 "MUL temp.x, temp.x, temp.y;" +
1248013064 "KIL temp.x;" +
....@@ -12754,7 +13338,7 @@
1275413338 "MUL final.y, fragment.texcoord[0].x, c256;" +
1275513339 "FLR final.x, final.y;" +
1275613340 "SUB final.y, final.y, final.x;" +
12757
- //"MUL final.x, final.x, c256i;" +
13341
+ "MUL final.x, final.x, c256i;" +
1275813342 "MOV final.z, zero.x;" +
1275913343 "MOV final.a, one.w;":""
1276013344 ) +
....@@ -12762,7 +13346,7 @@
1276213346 "MUL final.y, fragment.texcoord[0].y, c256;" +
1276313347 "FLR final.x, final.y;" +
1276413348 "SUB final.y, final.y, final.x;" +
12765
- //"MUL final.x, final.x, c256i;" +
13349
+ "MUL final.x, final.x, c256i;" +
1276613350 "MOV final.z, zero.x;" +
1276713351 "MOV final.a, one.w;":""
1276813352 ) +
....@@ -12805,7 +13389,14 @@
1280513389 //once = true;
1280613390 }
1280713391
12808
- System.out.print("Program #" + mode + "; length = " + program.length());
13392
+ String program = programmax;
13393
+
13394
+ if (Globals.MINSHADER)
13395
+ {
13396
+ program = programmin;
13397
+ }
13398
+
13399
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1280913400 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1281013401 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1281113402
....@@ -12898,25 +13489,26 @@
1289813489 return out;
1289913490 }
1290013491
12901
- String TextureFetch(String dest, String src, String unit)
13492
+ // Also does frustum culling
13493
+ String ShadowTextureFetch(String dest, String src, String unit)
1290213494 {
1290313495 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1290413496 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1290513497 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13498
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13499
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1290613500 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12907
- "SLT " + src + ".z, " + src + ".x, one.x;" +
12908
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12909
- "SLT " + src + ".z, " + src + ".y, one.x;" +
12910
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13501
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13502
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1291113503 //"SWZ buffer, temp, w,w,w,w;";
12912
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13504
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1291313505 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1291413506 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1291513507 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
12916
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13508
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1291713509
12918
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
12919
- //"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;";
1292013512 }
1292113513
1292213514 String Shadow(String depth, String shadow)
....@@ -12938,12 +13530,16 @@
1293813530
1293913531 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1294013532 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13533
+
13534
+ // Compare fragment depth in light space with shadowmap.
1294113535 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1294213536 "SGE temp.y, temp.x, zero.x;" +
12943
- "SUB " + shadow + ".y, one.x, temp.y;" +
13537
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13538
+
13539
+ // Reverse comparison
1294413540 "SUB temp.x, one.x, temp.x;" +
1294513541 "MUL " + shadow + ".x, temp.x, temp.y;" +
12946
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13542
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1294713543 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1294813544
1294913545 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -12957,6 +13553,10 @@
1295713553 // No shadow for backface
1295813554 "DP3 temp.x, normal, lightd;" +
1295913555 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13556
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13557
+
13558
+ // No shadow when out of frustum
13559
+ "SGE temp.x, " + depth + ".z, one.z;" +
1296013560 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1296113561 "";
1296213562 }
....@@ -13103,7 +13703,8 @@
1310313703 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1310413704 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1310513705 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13106
- Object3D.cVector2[] vector2buffer;
13706
+
13707
+ //Object3D.cVector2[] vector2buffer;
1310713708
1310813709 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1310913710 // OUT : diff, spec
....@@ -13119,9 +13720,10 @@
1311913720 "DP3 " + dest + ".z," + "normals," + "eye;" +
1312013721 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1312113722 //"MOV " + dest + ".w," + "normal.z;" +
13122
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
13123
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13124
- //"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
1312513727 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1312613728 "RCP " + dest + ".w," + dest + ".w;" +
1312713729 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13515,7 +14117,7 @@
1351514117 public void mousePressed(MouseEvent e)
1351614118 {
1351714119 //System.out.println("mousePressed: " + e);
13518
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14120
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1351914121 }
1352014122
1352114123 static long prevtime = 0;
....@@ -13591,8 +14193,8 @@
1359114193 // mode |= META;
1359214194 //}
1359314195
13594
- SetMouseMode(WHEEL | e.getModifiersEx());
13595
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14196
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14197
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1359614198 anchorX = ax;
1359714199 anchorY = ay;
1359814200 prevX = px;
....@@ -13626,6 +14228,7 @@
1362614228 else
1362714229 if (evt.getSource() == AAtimer)
1362814230 {
14231
+ Globals.TIMERRUNNING = false;
1362914232 if (mouseDown)
1363014233 {
1363114234 //new Exception().printStackTrace();
....@@ -13651,6 +14254,10 @@
1365114254 // LIVE = waslive;
1365214255 // wasliveok = true;
1365314256 // waslive = false;
14257
+
14258
+ // May 2019 Forget it:
14259
+ if (true)
14260
+ return;
1365414261
1365514262 // source == timer
1365614263 if (mouseDown)
....@@ -13681,7 +14288,7 @@
1368114288
1368214289 // fev 2014???
1368314290 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13684
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14291
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1368514292 pingthread.StepToTarget(true); // true);
1368614293 }
1368714294 // if (!LIVE)
....@@ -13690,12 +14297,13 @@
1369014297
1369114298 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1369214299
13693
- void clickStart(int x, int y, int modifiers)
14300
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1369414301 {
1369514302 if (!wasliveok)
1369614303 return;
1369714304
1369814305 AAtimer.restart(); //
14306
+ Globals.TIMERRUNNING = true;
1369914307
1370014308 // waslive = LIVE;
1370114309 // LIVE = false;
....@@ -13707,7 +14315,7 @@
1370714315 // touched = true; // main DL
1370814316 if (isRenderer)
1370914317 {
13710
- SetMouseMode(modifiers);
14318
+ SetMouseMode(modifiers, modifiersex);
1371114319 }
1371214320
1371314321 selectX = anchorX = x;
....@@ -13720,7 +14328,7 @@
1372014328 clicked = true;
1372114329 hold = false;
1372214330
13723
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14331
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1372414332 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1372514333 {
1372614334 // System.out.println("RESTART II " + modifiers);
....@@ -13745,14 +14353,15 @@
1374514353 drag = false;
1374614354 //System.out.println("Mouse DOWN");
1374714355 editObj = false;
13748
- ClickInfo info = new ClickInfo();
13749
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
13750
- info.pane = this;
13751
- info.camera = renderCamera;
13752
- info.x = x;
13753
- info.y = y;
13754
- info.modifiers = modifiers;
13755
- 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);
1375614365 if (!editObj)
1375714366 {
1375814367 hasMarquee = true;
....@@ -13768,9 +14377,12 @@
1376814377
1376914378 public void mouseDragged(MouseEvent e)
1377014379 {
14380
+ Globals.MOUSEDRAGGED = true;
14381
+
1377114382 //System.out.println("mouseDragged: " + e);
1377214383 if (isRenderer)
1377314384 movingcamera = true;
14385
+
1377414386 //if (drawing)
1377514387 //return;
1377614388 if ((e.getModifiersEx() & CTRL) != 0
....@@ -13780,7 +14392,7 @@
1378014392 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1378114393 }
1378214394 else
13783
- drag(e.getX(), e.getY(), e.getModifiersEx());
14395
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1378414396
1378514397 //try { Thread.sleep(1); } catch (Exception ex) {}
1378614398 }
....@@ -14017,7 +14629,7 @@
1401714629 {
1401814630 Globals.lighttouched = true;
1401914631 }
14020
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14632
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1402114633 }
1402214634 //else
1402314635 }
....@@ -14031,12 +14643,12 @@
1403114643 void GoDown(int mod)
1403214644 {
1403314645 MODIFIERS |= COMMAND;
14034
- /*
14646
+ /**/
1403514647 if((mod&SHIFT) == SHIFT)
14036
- manipCamera.RotatePosition(0, -speed);
14648
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
1403714649 else
14038
- manipCamera.BackForth(0, -speed*delta, getWidth());
14039
- */
14650
+ manipCamera.RotatePosition(0, -speed);
14651
+ /**/
1404014652 if ((mod & SHIFT) == SHIFT)
1404114653 {
1404214654 mouseMode = mouseMode; // VR??
....@@ -14052,12 +14664,12 @@
1405214664 void GoUp(int mod)
1405314665 {
1405414666 MODIFIERS |= COMMAND;
14055
- /*
14667
+ /**/
1405614668 if((mod&SHIFT) == SHIFT)
14057
- manipCamera.RotatePosition(0, speed);
14669
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
1405814670 else
14059
- manipCamera.BackForth(0, speed*delta, getWidth());
14060
- */
14671
+ manipCamera.RotatePosition(0, speed);
14672
+ /**/
1406114673 if ((mod & SHIFT) == SHIFT)
1406214674 {
1406314675 mouseMode = mouseMode;
....@@ -14073,12 +14685,12 @@
1407314685 void GoLeft(int mod)
1407414686 {
1407514687 MODIFIERS |= COMMAND;
14076
- /*
14688
+ /**/
1407714689 if((mod&SHIFT) == SHIFT)
14078
- manipCamera.RotatePosition(speed, 0);
14079
- else
1408014690 manipCamera.Translate(speed*delta, 0, getWidth());
14081
- */
14691
+ else
14692
+ manipCamera.RotatePosition(speed, 0);
14693
+ /**/
1408214694 if ((mod & SHIFT) == SHIFT)
1408314695 {
1408414696 mouseMode = mouseMode;
....@@ -14094,12 +14706,12 @@
1409414706 void GoRight(int mod)
1409514707 {
1409614708 MODIFIERS |= COMMAND;
14097
- /*
14709
+ /**/
1409814710 if((mod&SHIFT) == SHIFT)
14099
- manipCamera.RotatePosition(-speed, 0);
14100
- else
1410114711 manipCamera.Translate(-speed*delta, 0, getWidth());
14102
- */
14712
+ else
14713
+ manipCamera.RotatePosition(-speed, 0);
14714
+ /**/
1410314715 if ((mod & SHIFT) == SHIFT)
1410414716 {
1410514717 mouseMode = mouseMode;
....@@ -14117,7 +14729,7 @@
1411714729 int X, Y;
1411814730 boolean SX, SY;
1411914731
14120
- void drag(int x, int y, int modifiers)
14732
+ void drag(int x, int y, int modifiers, int modifiersex)
1412114733 {
1412214734 if (IsFrozen())
1412314735 {
....@@ -14126,17 +14738,17 @@
1412614738
1412714739 drag = true; // NEW
1412814740
14129
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14741
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1413014742
1413114743 X = x;
1413214744 Y = y;
1413314745 // floating state for animation
14134
- MODIFIERS = modifiers;
14135
- modifiers &= ~1024;
14746
+ MODIFIERS = modifiersex;
14747
+ modifiersex &= ~1024;
1413614748 if (false) // modifiers != 0)
1413714749 {
1413814750 //new Exception().printStackTrace();
14139
- System.out.println("mouseDragged: " + modifiers);
14751
+ System.out.println("mouseDragged: " + modifiersex);
1414014752 System.out.println("SHIFT = " + SHIFT);
1414114753 System.out.println("CONTROL = " + COMMAND);
1414214754 System.out.println("META = " + META);
....@@ -14149,14 +14761,16 @@
1414914761 if (editObj)
1415014762 {
1415114763 drag = true;
14152
- ClickInfo info = new ClickInfo();
14153
- info.bounds.setBounds(0, 0,
14764
+ //ClickInfo info = new ClickInfo();
14765
+ object.clickInfo.bounds.setBounds(0, 0,
1415414766 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14155
- info.pane = this;
14156
- info.camera = renderCamera;
14157
- info.x = x;
14158
- info.y = y;
14159
- object.editWindow.copy.doEditDrag(info);
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);
1416014774 } else
1416114775 {
1416214776 if (x < startX)
....@@ -14305,22 +14919,27 @@
1430514919 }
1430614920 }
1430714921
14922
+// ClickInfo clickInfo = new ClickInfo();
14923
+
1430814924 public void mouseMoved(MouseEvent e)
1430914925 {
1431014926 //System.out.println("mouseMoved: " + e);
1431114927 if (isRenderer)
1431214928 return;
1431314929
14314
- ClickInfo ci = new ClickInfo();
14315
- ci.x = e.getX();
14316
- ci.y = e.getY();
14317
- ci.modifiers = e.getModifiersEx();
14318
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14319
- ci.pane = this;
14320
- 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;
1432114937 if (!isRenderer)
1432214938 {
14323
- if (object.editWindow.copy.doEditClick(ci, 0))
14939
+ //ObjEditor editWindow = object.editWindow;
14940
+ //Object3D copy = editWindow.copy;
14941
+ if (object.doEditClick(//clickInfo,
14942
+ 0))
1432414943 {
1432514944 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1432614945 } else
....@@ -14332,7 +14951,11 @@
1433214951
1433314952 public void mouseReleased(MouseEvent e)
1433414953 {
14954
+ Globals.MOUSEDRAGGED = false;
14955
+
1433514956 movingcamera = false;
14957
+ X = 0; // getBounds().width/2;
14958
+ Y = 0; // getBounds().height/2;
1433614959 //System.out.println("mouseReleased: " + e);
1433714960 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1433814961 }
....@@ -14355,9 +14978,9 @@
1435514978 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1435614979 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1435714980
14358
- if (control || command || IsFrozen())
14981
+// No delay if (control || command || IsFrozen())
1435914982 timeout = true;
14360
- else
14983
+// ?? May 2019 else
1436114984 // timer.setDelay((modifiers & 128) != 0?0:350);
1436214985 mouseDown = false;
1436314986 if (!control && !command) // june 2013
....@@ -14467,7 +15090,7 @@
1446715090 System.out.println("keyReleased: " + e);
1446815091 }
1446915092
14470
- void SetMouseMode(int modifiers)
15093
+ void SetMouseMode(int modifiers, int modifiersex)
1447115094 {
1447215095 //System.out.println("SetMouseMode = " + modifiers);
1447315096 //modifiers &= ~1024;
....@@ -14479,25 +15102,25 @@
1447915102 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1448015103 // return;
1448115104 //System.out.println("SetMode = " + modifiers);
14482
- if ((modifiers & WHEEL) == WHEEL)
15105
+ if ((modifiersex & WHEEL) == WHEEL)
1448315106 {
1448415107 mouseMode |= ZOOM;
1448515108 }
1448615109
1448715110 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
14488
- if (capsLocked || (modifiers & META) == META)
15111
+ if (capsLocked) // || (modifiers & META) == META)
1448915112 {
1449015113 mouseMode |= VR; // BACKFORTH;
1449115114 }
14492
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
15115
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1449315116 {
1449415117 mouseMode |= SELECT;
1449515118 }
14496
- if ((modifiers & COMMAND) == COMMAND)
15119
+ if ((modifiersex & COMMAND) == COMMAND)
1449715120 {
1449815121 mouseMode |= SELECT;
1449915122 }
14500
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15123
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
1450115124 {
1450215125 mouseMode &= ~VR;
1450315126 mouseMode |= TRANSLATE;
....@@ -14526,7 +15149,7 @@
1452615149
1452715150 if (isRenderer) //
1452815151 {
14529
- SetMouseMode(modifiers);
15152
+ SetMouseMode(0, modifiers);
1453015153 }
1453115154
1453215155 Globals.theRenderer.keyPressed(key);
....@@ -14588,7 +15211,8 @@
1458815211 // break;
1458915212 case 'T':
1459015213 CACHETEXTURE ^= true;
14591
- textures.clear();
15214
+ texturepigment.clear();
15215
+ texturebump.clear();
1459215216 // repaint();
1459315217 break;
1459415218 case 'Y':
....@@ -14673,7 +15297,9 @@
1467315297 case 'E' : COMPACT ^= true;
1467415298 repaint();
1467515299 break;
14676
- case 'W' : DEBUGHSB ^= true;
15300
+ case 'W' : // Wide Window (fullscreen)
15301
+ //DEBUGHSB ^= true;
15302
+ ObjEditor.theFrame.ToggleFullScreen();
1467715303 repaint();
1467815304 break;
1467915305 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14698,8 +15324,8 @@
1469815324 RevertCamera();
1469915325 repaint();
1470015326 break;
14701
- case 'L':
1470215327 case 'l':
15328
+ //case 'L':
1470315329 if (lightMode)
1470415330 {
1470515331 lightMode = false;
....@@ -14763,20 +15389,24 @@
1476315389 OCCLUSION_CULLING ^= true;
1476415390 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1476515391 break;
14766
- case '0': envyoff ^= true; repaint(); break;
15392
+ //case '0': envyoff ^= true; repaint(); break;
1476715393 case '1':
1476815394 case '2':
1476915395 case '3':
1477015396 case '4':
1477115397 case '5':
14772
- newenvy = Character.getNumericValue(key);
14773
- repaint();
14774
- break;
1477515398 case '6':
1477615399 case '7':
1477715400 case '8':
1477815401 case '9':
14779
- 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
+ }
1478015410 repaint();
1478115411 break;
1478215412 case '!':
....@@ -14842,9 +15472,9 @@
1484215472 case '_':
1484315473 kompactbit = 5;
1484415474 break;
14845
- case '+':
14846
- kompactbit = 6;
14847
- break;
15475
+// case '+':
15476
+// kompactbit = 6;
15477
+// break;
1484815478 case ' ':
1484915479 lightMode ^= true;
1485015480 Globals.lighttouched = true;
....@@ -14856,13 +15486,14 @@
1485615486 case ESC:
1485715487 RENDERPROGRAM += 1;
1485815488 RENDERPROGRAM %= 3;
15489
+
1485915490 repaint();
1486015491 break;
1486115492 case 'Z':
1486215493 //RESIZETEXTURE ^= true;
1486315494 //break;
1486415495 case 'z':
14865
- RENDERSHADOW ^= true;
15496
+ Globals.RENDERSHADOW ^= true;
1486615497 Globals.lighttouched = true;
1486715498 repaint();
1486815499 break;
....@@ -14895,8 +15526,9 @@
1489515526 case DELETE:
1489615527 ClearSelection();
1489715528 break;
14898
- /*
1489915529 case '+':
15530
+
15531
+ /*
1490015532 //fontsize += 1;
1490115533 bbzoom *= 2;
1490215534 repaint();
....@@ -14913,17 +15545,17 @@
1491315545 case '=':
1491415546 IncDepth();
1491515547 //fontsize += 1;
14916
- object.editWindow.refreshContents(true);
15548
+ object.GetWindow().refreshContents(true);
1491715549 maskbit = 6;
1491815550 break;
1491915551 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1492015552 DecDepth();
1492115553 maskbit = 5;
1492215554 //if(fontsize > 1) fontsize -= 1;
14923
- if (object.editWindow == null)
14924
- new Exception().printStackTrace();
14925
- else
14926
- object.editWindow.refreshContents(true);
15555
+// if (object.editWindow == null)
15556
+// new Exception().printStackTrace();
15557
+// else
15558
+ object.GetWindow().refreshContents(true);
1492715559 break;
1492815560 case '{':
1492915561 manipCamera.shaper_fovy /= 1.1;
....@@ -14986,7 +15618,7 @@
1498615618 //mode = ROTATE;
1498715619 if ((MODIFIERS & COMMAND) == 0) // VR??
1498815620 {
14989
- SetMouseMode(modifiers);
15621
+ SetMouseMode(0, modifiers);
1499015622 }
1499115623 }
1499215624
....@@ -15122,7 +15754,7 @@
1512215754 {
1512315755 //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
1512415756 //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15125
- if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (mouseMode & SELECT) == 0)
15757
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1512615758 {
1512715759 mouseMoved(e);
1512815760 } else
....@@ -15147,7 +15779,7 @@
1514715779 }
1514815780 */
1514915781
15150
- object.editWindow.EditSelection();
15782
+ object.GetWindow().EditSelection(false);
1515115783 }
1515215784
1515315785 void SelectParent()
....@@ -15164,10 +15796,10 @@
1516415796 {
1516515797 //selectees.remove(i);
1516615798 System.out.println("select parent of " + elem);
15167
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15799
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1516815800 } else
1516915801 {
15170
- group.editWindow.Select(elem.GetTreePath(), first, true);
15802
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1517115803 }
1517215804
1517315805 first = false;
....@@ -15209,12 +15841,12 @@
1520915841 for (int j = 0; j < group.children.size(); j++)
1521015842 {
1521115843 elem = (Object3D) group.children.elementAt(j);
15212
- object.editWindow.Select(elem.GetTreePath(), first, true);
15844
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1521315845 first = false;
1521415846 }
1521515847 } else
1521615848 {
15217
- object.editWindow.Select(elem.GetTreePath(), first, true);
15849
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1521815850 }
1521915851
1522015852 first = false;
....@@ -15225,21 +15857,21 @@
1522515857 {
1522615858 //Composite group = (Composite) object;
1522715859 Object3D group = object;
15228
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15860
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1522915861 }
1523015862
1523115863 void ResetTransform(int mask)
1523215864 {
1523315865 //Composite group = (Composite) object;
1523415866 Object3D group = object;
15235
- group.editWindow.ResetTransform(mask);
15867
+ group.GetWindow().ResetTransform(mask);
1523615868 }
1523715869
1523815870 void FlipTransform()
1523915871 {
1524015872 //Composite group = (Composite) object;
1524115873 Object3D group = object;
15242
- group.editWindow.FlipTransform();
15874
+ group.GetWindow().FlipTransform();
1524315875 // group.editWindow.ReduceMesh(true);
1524415876 }
1524515877
....@@ -15247,7 +15879,7 @@
1524715879 {
1524815880 //Composite group = (Composite) object;
1524915881 Object3D group = object;
15250
- group.editWindow.PrintMemory();
15882
+ group.GetWindow().PrintMemory();
1525115883 // group.editWindow.ReduceMesh(true);
1525215884 }
1525315885
....@@ -15255,7 +15887,7 @@
1525515887 {
1525615888 //Composite group = (Composite) object;
1525715889 Object3D group = object;
15258
- group.editWindow.ResetCentroid();
15890
+ group.GetWindow().ResetCentroid();
1525915891 }
1526015892
1526115893 void IncDepth()
....@@ -15337,11 +15969,11 @@
1533715969
1533815970 int width = getBounds().width;
1533915971 int height = getBounds().height;
15340
- ClickInfo info = new ClickInfo();
15341
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1534215972 //Image img = CreateImage(width, height);
1534315973 //System.out.println("width = " + width + "; height = " + height + "\n");
15974
+
1534415975 Graphics gr = g; // img.getGraphics();
15976
+
1534515977 if (!hasMarquee)
1534615978 {
1534715979 if (Xmin < Xmax) // !locked)
....@@ -15413,40 +16045,88 @@
1541316045 }
1541416046 if (object != null && !hasMarquee)
1541516047 {
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
+
1541616054 if (isRenderer)
1541716055 {
15418
- info.flags++;
16056
+ object.clickInfo.flags++;
1541916057 double frameAspect = (double) width / (double) height;
1542016058 if (frameAspect > renderCamera.aspect)
1542116059 {
1542216060 int desired = (int) ((double) height * renderCamera.aspect);
15423
- info.bounds.width -= width - desired;
15424
- info.bounds.x += (width - desired) / 2;
16061
+ object.clickInfo.bounds.width -= width - desired;
16062
+ object.clickInfo.bounds.x += (width - desired) / 2;
1542516063 } else
1542616064 {
1542716065 int desired = (int) ((double) width / renderCamera.aspect);
15428
- info.bounds.height -= height - desired;
15429
- info.bounds.y += (height - desired) / 2;
16066
+ object.clickInfo.bounds.height -= height - desired;
16067
+ object.clickInfo.bounds.y += (height - desired) / 2;
1543016068 }
1543116069 }
15432
- info.g = gr;
15433
- info.camera = renderCamera;
16070
+
16071
+ object.clickInfo.g = gr;
16072
+ object.clickInfo.camera = renderCamera;
1543416073 /*
1543516074 // Memory intensive (brep.verticescopy)
1543616075 if (!(object instanceof Composite))
1543716076 object.draw(info, 0, false); // SLOW :
1543816077 */
15439
- if (!isRenderer)
16078
+ if (!isRenderer) // && drag)
1544016079 {
15441
- object.drawEditHandles(info, 0);
16080
+ Grafreed.Assert(object != null);
16081
+ Grafreed.Assert(object.selection != null);
16082
+ if (object.selection.Size() > 0)
16083
+ {
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)
16090
+ {
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;
16098
+ }
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
+ }
16119
+ }
1544216120 }
1544316121 }
16122
+
1544416123 if (isRenderer)
1544516124 {
1544616125 //gr.setColor(Color.black);
1544716126 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1544816127 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1544916128 }
16129
+
1545016130 if (hasMarquee)
1545116131 {
1545216132 gr.setXORMode(Color.white);
....@@ -15559,6 +16239,7 @@
1555916239 public boolean mouseDown(Event evt, int x, int y)
1556016240 {
1556116241 System.out.println("mouseDown: " + evt);
16242
+ System.exit(0);
1556216243 /*
1556316244 locked = true;
1556416245 drag = false;
....@@ -15602,7 +16283,7 @@
1560216283 {
1560316284 keyPressed(0, modifiers);
1560416285 }
15605
- clickStart(x, y, modifiers);
16286
+ // clickStart(x, y, modifiers);
1560616287 return true;
1560716288 }
1560816289
....@@ -15720,7 +16401,7 @@
1572016401 {
1572116402 keyReleased(0, 0);
1572216403 }
15723
- drag(x, y, modifiers);
16404
+ drag(x, y, 0, modifiers);
1572416405 return true;
1572516406 }
1572616407
....@@ -15852,7 +16533,7 @@
1585216533 Object3D object;
1585316534 static Object3D trackedobject;
1585416535 Camera renderCamera; // Light or Eye (or Occlusion)
15855
- /*static*/ Camera manipCamera; // Light or Eye
16536
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1585616537 /*static*/ Camera eyeCamera;
1585716538 /*static*/ Camera lightCamera;
1585816539 int cameracount;
....@@ -15916,6 +16597,8 @@
1591616597 private /*static*/ boolean firstime;
1591716598 private /*static*/ cVector newView = new cVector();
1591816599 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"};
1591916602 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1592016603 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1592116604 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -15928,29 +16611,67 @@
1592816611 {
1592916612 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1593016613
16614
+ int usedsuf = 0;
16615
+
1593116616 for (int i = 0; i < suffixes.length; i++)
1593216617 {
15933
- String resourceName = basename + suffixes[i] + "." + suffix;
15934
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
15935
- mipmapped,
15936
- FileUtil.getFileSuffix(resourceName));
15937
- if (data == null)
16618
+ String[] suffixe = suffixes;
16619
+ String[] fallback = suffixes2;
16620
+ String[] fallfallback = suffixes3;
16621
+
16622
+ for (int c=usedsuf; --c>=0;)
1593816623 {
15939
- throw new IOException("Unable to load texture " + resourceName);
16624
+// String[] temp = suffixe;
16625
+// suffixe = fallback;
16626
+// fallback = fallfallback;
16627
+// fallfallback = temp;
1594016628 }
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
+
1594116657 //System.out.println("Target = " + targets[i]);
1594216658 cubemap.updateImage(data, targets[i]);
1594316659 }
1594416660
1594516661 return cubemap;
1594616662 }
16663
+
1594716664 int bigsphere = -1;
1594816665
1594916666 float BGcolor = 0.5f;
1595016667
15951
- private void DrawSkyBox(GL gl)
16668
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16669
+
16670
+ private void DrawSkyBox(GL gl, float ratio)
1595216671 {
15953
- if (envyoff || cubemap == null)
16672
+ if (//envyoff ||
16673
+ WIREFRAME ||
16674
+ cubemap == null)
1595416675 {
1595516676 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1595616677 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -15965,7 +16686,17 @@
1596516686 // Compensates for ExaminerViewer's modification of modelview matrix
1596616687 gl.glMatrixMode(GL.GL_MODELVIEW);
1596716688 gl.glLoadIdentity();
16689
+ gl.glScalef(1,ratio,1);
1596816690
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
+
1596916700 //gl.glActiveTexture(GL.GL_TEXTURE1);
1597016701 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1597116702
....@@ -15997,6 +16728,7 @@
1599716728 {
1599816729 gl.glScalef(1.0f, -1.0f, 1.0f);
1599916730 }
16731
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1600016732 gl.glMultMatrixd(viewrot_1, 0);
1600116733 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1600216734 //viewer.updateInverseRotation(gl);
....@@ -16137,16 +16869,16 @@
1613716869 cStatic.objectstack[materialdepth++] = checker;
1613816870 //System.out.println("material " + material);
1613916871 //Applet3D.tracein(this, selected);
16140
- vector2buffer = checker.projectedVertices;
16872
+ //vector2buffer = checker.projectedVertices;
1614116873
1614216874 //checker.GetMaterial().Draw(this, false); // true);
16143
- DrawMaterial(checker.GetMaterial(), false); // true);
16875
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1614416876
1614516877 materialdepth -= 1;
1614616878 if (materialdepth > 0)
1614716879 {
16148
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16149
- 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);
1615016882 }
1615116883 //checker.GetMaterial().opacity = 1f;
1615216884 ////checker.GetMaterial().ambient = 1f;
....@@ -16232,6 +16964,14 @@
1623216964 }
1623316965 }
1623416966
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
+
1623516975 class SelectBuffer implements GLEventListener
1623616976 {
1623716977
....@@ -16247,7 +16987,7 @@
1624716987 //new Exception().printStackTrace();
1624816988 System.out.println("select buffer init");
1624916989 // Use debug pipeline
16250
- drawable.setGL(new DebugGL(drawable.getGL()));
16990
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1625116991
1625216992 GL gl = drawable.getGL();
1625316993
....@@ -16311,6 +17051,17 @@
1631117051
1631217052 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1631317053
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
+
1631417065 //int tmp = selection_view;
1631517066 //selection_view = -1;
1631617067 int temp = DrawMode();
....@@ -16322,6 +17073,17 @@
1632217073 // temp = DEFAULT; // patch for selection debug
1632317074 Globals.drawMode = temp; // WARNING
1632417075
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
+
1632517087 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1632617088
1632717089 // trying different ways of getting the depth info over
....@@ -16369,6 +17131,8 @@
1636917131 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1637017132 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1637117133 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
17134
+
17135
+ CreateSelectedPoint();
1637217136
1637317137 // Will fit the mesh !!!
1637417138 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16418,34 +17182,36 @@
1641817182 System.out.println("; fromto " + sel + " " + Trunk(previousselectedpoint.toParent[3][0]) + " " + Trunk(previousselectedpoint.toParent[3][2]) + " " + Trunk(selectedpoint.toParent[3][0]) + " " + Trunk(selectedpoint.toParent[3][2]));
1641917183 }
1642017184
16421
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
17185
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1642217186 }
1642317187 }
1642417188
1642517189 if (!movingcamera && !PAINTMODE)
16426
- object.editWindow.ScreenFitPoint(); // fev 2014
17190
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1642717191
16428
- 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)
1642917193 {
16430
- 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);
1643117195
16432
- Object3D group = new Object3D("inst" + paintcount++);
17196
+ if (object.GetWindow().copy.selection.Size() > 0)
17197
+ {
17198
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1643317199
16434
- group.CreateMaterial(); // use a void leaf to select instances
16435
-
16436
- group.add(paintobj); // link
16437
-
16438
- object.editWindow.SnapObject(group);
16439
-
16440
- Object3D folder = object.editWindow.copy;
16441
-
16442
- if (object.editWindow.copy.selection.Size() > 0)
16443
- folder = object.editWindow.copy.selection.elementAt(0);
16444
-
16445
- folder.add(group);
16446
-
16447
- object.editWindow.ResetModel();
16448
- 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
+ }
1644917215 }
1645017216 else
1645117217 paintcount = 0;
....@@ -16484,6 +17250,11 @@
1648417250 //System.out.println("objects[color] = " + objects[color]);
1648517251 //objects[color].Select();
1648617252 indexcount = 0;
17253
+ ObjEditor window = object.GetWindow();
17254
+ if (window != null && deselect)
17255
+ {
17256
+ window.Select(null, deselect, true);
17257
+ }
1648717258 object.Select(color, deselect);
1648817259 }
1648917260
....@@ -16583,7 +17354,7 @@
1658317354 gl.glDisable(gl.GL_CULL_FACE);
1658417355 }
1658517356
16586
- if (!RENDERSHADOW)
17357
+ if (!Globals.RENDERSHADOW)
1658717358 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1658817359
1658917360 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -16593,7 +17364,7 @@
1659317364 //gl.glColorMask(false, false, false, false);
1659417365
1659517366 //render_scene_from_light_view(gl, drawable, 0, 0);
16596
- if (RENDERSHADOW && Globals.lighttouched && !movingcamera) // && !parent.IsFreezed())
17367
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1659717368 {
1659817369 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1659917370
....@@ -17009,23 +17780,15 @@
1700917780 int AAbuffersize = 0;
1701017781
1701117782 //double[] selectedpoint = new double[3];
17012
- static Superellipsoid selectedpoint = new Superellipsoid();
17783
+ static Superellipsoid selectedpoint;
1701317784 static Sphere previousselectedpoint = null;
17014
- static Sphere debugpointG = new Sphere();
17015
- static Sphere debugpointP = new Sphere();
17016
- static Sphere debugpointC = new Sphere();
17017
- static Sphere debugpointR = new Sphere();
17785
+ static Sphere debugpointG;
17786
+ static Sphere debugpointP;
17787
+ static Sphere debugpointC;
17788
+ static Sphere debugpointR;
1701817789
1701917790 static Sphere debugpoints[] = new Sphere[8];
1702017791
17021
- static
17022
- {
17023
- for (int i=0; i<8; i++)
17024
- {
17025
- debugpoints[i] = new Sphere();
17026
- }
17027
- }
17028
-
1702917792 static void InitPoints(float radius)
1703017793 {
1703117794 for (int i=0; i<8; i++)