Normand Briere
2019-07-22 c570e1e38f2ff8622a71f81436654bad01cfdd5b
CameraPane.java
....@@ -37,7 +37,6 @@
3737 static boolean[] selectedstack = new boolean[65536];
3838 static int materialdepth = 0;
3939
40
- static boolean DEBUG = false;
4140 static boolean FRUSTUM = false; // still bogus true; // frustum culling
4241
4342 // camera change fix
....@@ -45,6 +44,39 @@
4544 static boolean ABORTED = false;
4645
4746 static int STEP = 1;
47
+
48
+ private static BufferedImage CreateBim(byte[] bytes, int width, int height)
49
+ {
50
+ int[] pixels = new int[bytes.length/3];
51
+ for (int i=pixels.length; --i>=0;)
52
+ {
53
+ int i3 = i*3;
54
+ pixels[i] = 0xFF;
55
+ pixels[i] <<= 8;
56
+ pixels[i] |= bytes[i3+2] & 0xFF;
57
+ pixels[i] <<= 8;
58
+ pixels[i] |= bytes[i3+1] & 0xFF;
59
+ pixels[i] <<= 8;
60
+ pixels[i] |= bytes[i3] & 0xFF;
61
+ }
62
+ /*
63
+ int r=0,g=0,b=0,a=0;
64
+ for (int i=0; i<width; i++)
65
+ for (int j=0; j<height; j++)
66
+ {
67
+ int index = j*width+i;
68
+ int p = pixels[index];
69
+ a = ((p>>24) & 0xFF);
70
+ r = ((p>>16) & 0xFF);
71
+ g = ((p>>8) & 0xFF);
72
+ b = (p & 0xFF);
73
+ pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
74
+ }
75
+ /**/
76
+ BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
77
+ rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
78
+ return rendImage;
79
+ }
4880
4981 /*static*/ private boolean CULLFACE = false; // true;
5082 /*static*/ boolean NEAREST = false; // true;
....@@ -61,7 +93,7 @@
6193 //boolean REDUCETEXTURE = true;
6294 boolean CACHETEXTURE = true;
6395 boolean CLEANCACHE = false; // true;
64
- boolean MIPMAP = false; // true;
96
+ boolean MIPMAP = true; // false; // true;
6597 boolean COMPRESSTEXTURE = false;
6698 boolean KOMPACTTEXTURE = false; // true;
6799 boolean RESIZETEXTURE = false;
....@@ -149,6 +181,8 @@
149181 defaultcaps.setAccumBlueBits(16);
150182 defaultcaps.setAccumAlphaBits(16);
151183 }
184
+
185
+ private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
152186
153187 void SetAsGLRenderer(boolean b)
154188 {
....@@ -325,7 +359,7 @@
325359 cStatic.objectstack[materialdepth++] = obj;
326360 //System.out.println("material " + material);
327361 //Applet3D.tracein(this, selected);
328
- display.vector2buffer = obj.projectedVertices;
362
+ //display.vector2buffer = obj.projectedVertices;
329363 if (obj instanceof Camera)
330364 {
331365 display.options1[0] = material.shift;
....@@ -334,14 +368,28 @@
334368 display.options1[2] = material.shadowbias;
335369 display.options1[3] = material.aniso;
336370 display.options1[4] = material.anisoV;
371
+// System.out.println("display.options1[0] " + display.options1[0]);
372
+// System.out.println("display.options1[1] " + display.options1[1]);
373
+// System.out.println("display.options1[2] " + display.options1[2]);
374
+// System.out.println("display.options1[3] " + display.options1[3]);
375
+// System.out.println("display.options1[4] " + display.options1[4]);
337376 display.options2[0] = material.opacity;
338377 display.options2[1] = material.diffuse;
339378 display.options2[2] = material.factor;
379
+// System.out.println("display.options2[0] " + display.options2[0]);
380
+// System.out.println("display.options2[1] " + display.options2[1]);
381
+// System.out.println("display.options2[2] " + display.options2[2]);
340382
341383 cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
384
+// System.out.println("display.options3[0] " + display.options3[0]);
385
+// System.out.println("display.options3[1] " + display.options3[1]);
386
+// System.out.println("display.options3[2] " + display.options3[2]);
342387 display.options4[0] = material.cameralight/0.2f;
343388 display.options4[1] = material.subsurface;
344389 display.options4[2] = material.sheen;
390
+// System.out.println("display.options4[0] " + display.options4[0]);
391
+// System.out.println("display.options4[1] " + display.options4[1]);
392
+// System.out.println("display.options4[2] " + display.options4[2]);
345393
346394 // if (display.CURRENTANTIALIAS > 0)
347395 // display.options3[3] /= 4;
....@@ -357,7 +405,7 @@
357405 /**/
358406 } else
359407 {
360
- DrawMaterial(material, selected);
408
+ DrawMaterial(material, selected, obj.projectedVertices);
361409 }
362410 } else
363411 {
....@@ -381,8 +429,8 @@
381429 cStatic.objectstack[materialdepth++] = obj;
382430 //System.out.println("material " + material);
383431 //Applet3D.tracein("selected ", selected);
384
- display.vector2buffer = obj.projectedVertices;
385
- display.DrawMaterial(material, selected);
432
+ //display.vector2buffer = obj.projectedVertices;
433
+ display.DrawMaterial(material, selected, obj.projectedVertices);
386434 }
387435 }
388436
....@@ -399,8 +447,8 @@
399447 materialdepth -= 1;
400448 if (materialdepth > 0)
401449 {
402
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
403
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
450
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
451
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
404452 }
405453 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
406454 } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
....@@ -420,8 +468,8 @@
420468 materialdepth -= 1;
421469 if (materialdepth > 0)
422470 {
423
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
424
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
471
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
472
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
425473 }
426474 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
427475 //else
....@@ -462,10 +510,12 @@
462510 if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
463511 {
464512 //gl.glBegin(gl.GL_TRIANGLES);
465
- boolean hasnorm = pv.norm != null; // && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0);
513
+ boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0)
514
+ // TEST LIVE NORMALS && !obj.dontselect
515
+ ;
466516 if (!hasnorm)
467517 {
468
- // System.out.println("FUCK!!");
518
+ // System.out.println("Mesh normal");
469519 LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
470520 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
471521 LA.vecCross(obj.v0, obj.v1, obj.v2);
....@@ -1190,10 +1240,12 @@
11901240 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
11911241 }
11921242 }
1243
+
11931244 if (flipV)
11941245 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
11951246 else
11961247 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1248
+
11971249 //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
11981250 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
11991251
....@@ -1213,10 +1265,12 @@
12131265 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
12141266 }
12151267 }
1268
+
12161269 if (flipV)
12171270 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12181271 else
12191272 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1273
+
12201274 //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
12211275 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
12221276
....@@ -1244,8 +1298,10 @@
12441298 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12451299 else
12461300 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1301
+
12471302 //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
12481303 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1304
+
12491305 count2 += 2;
12501306 count3 += 3;
12511307 }
....@@ -1601,7 +1657,7 @@
16011657 // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
16021658 }
16031659
1604
- void DrawMaterial(cMaterial material, boolean selected)
1660
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
16051661 {
16061662 CameraPane display = this;
16071663 //new Exception().printStackTrace();
....@@ -1628,7 +1684,7 @@
16281684
16291685 cColor.HSBtoRGB(display.color, display.saturation, 1, display.modelParams0);
16301686
1631
- float[] colorV = GrafreeD.colorV;
1687
+ float[] colorV = Grafreed.colorV;
16321688
16331689 /**/
16341690 if (display.DrawMode() == display.DEFAULT) // && display.RENDERPROGRAM == 0)
....@@ -1636,7 +1692,7 @@
16361692 colorV[0] = display.modelParams0[0] * material.diffuse;
16371693 colorV[1] = display.modelParams0[1] * material.diffuse;
16381694 colorV[2] = display.modelParams0[2] * material.diffuse;
1639
- colorV[3] = material.opacity;
1695
+ colorV[3] = 1; // material.opacity;
16401696
16411697 gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
16421698 //System.out.println("Opacity = " + opacity);
....@@ -1744,9 +1800,9 @@
17441800 display.modelParams7[2] = 0;
17451801 display.modelParams7[3] = 0;
17461802
1747
- display.modelParams6[0] = 100; // criss de bug de bump
1803
+ //display.modelParams6[0] = 100; // criss de bug de bump
17481804
1749
- Object3D.cVector2[] extparams = display.vector2buffer;
1805
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
17501806 if (extparams != null && extparams.length > 0 && extparams[0] != null)
17511807 {
17521808 display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
....@@ -1888,7 +1944,7 @@
18881944 void PushMatrix(double[][] matrix)
18891945 {
18901946 // GrafreeD.tracein(matrix);
1891
- PushMatrix(matrix,1);
1947
+ PushMatrix(matrix, 1);
18921948 }
18931949
18941950 void PushMatrix()
....@@ -2042,7 +2098,7 @@
20422098 //System.err.println("Oeil on");
20432099 OEIL = true;
20442100 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2045
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2101
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
20462102 //pingthread.StepToTarget(true);
20472103 }
20482104
....@@ -2140,7 +2196,7 @@
21402196 System.err.println("LIVE = " + Globals.isLIVE());
21412197
21422198 if (!Globals.isLIVE()) // save sound
2143
- GrafreeD.savesound = true; // wav.save();
2199
+ Grafreed.savesound = true; // wav.save();
21442200 // else
21452201 repaint(); // start loop // may 2013
21462202 }
....@@ -2257,7 +2313,7 @@
22572313
22582314 void ToggleDebug()
22592315 {
2260
- DEBUG ^= true;
2316
+ Globals.DEBUG ^= true;
22612317 }
22622318
22632319 void ToggleLookAt()
....@@ -2265,7 +2321,7 @@
22652321 LOOKAT ^= true;
22662322 }
22672323
2268
- void ToggleRandom()
2324
+ void ToggleSwitch()
22692325 {
22702326 SWITCH ^= true;
22712327 }
....@@ -2275,10 +2331,17 @@
22752331 HANDLES ^= true;
22762332 }
22772333
2334
+ Object3D paintFolder;
2335
+
22782336 void TogglePaint()
22792337 {
22802338 PAINTMODE ^= true;
22812339 paintcount = 0;
2340
+
2341
+ if (PAINTMODE)
2342
+ {
2343
+ paintFolder = GetFolder();
2344
+ }
22822345 }
22832346
22842347 void SwapCamera(int a, int b)
....@@ -2374,7 +2437,22 @@
23742437 {
23752438 return currentGL;
23762439 }
2377
-
2440
+
2441
+ static private BufferedImage CreateBim(TextureData texturedata)
2442
+ {
2443
+ Grafreed.Assert(texturedata != null);
2444
+
2445
+ int width = texturedata.getWidth();
2446
+ int height = texturedata.getHeight();
2447
+
2448
+ Buffer buffer = texturedata.getBuffer();
2449
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2450
+
2451
+ byte[] bytes = bytebuf.array();
2452
+
2453
+ return CreateBim(bytes, width, height);
2454
+ }
2455
+
23782456 /**/
23792457 class CacheTexture
23802458 {
....@@ -2383,28 +2461,31 @@
23832461
23842462 int resolution;
23852463
2386
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2464
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
23872465 {
2388
- texture = tex;
2466
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2467
+ texturedata = texdata;
23892468 resolution = res;
23902469 }
23912470 }
23922471 /**/
23932472
23942473 // 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>();
2474
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2475
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2476
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2477
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2478
+
23982479 int pigmentdepth = 0;
23992480 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
24002481 int bumpdepth = 0;
24012482 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
24022483 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
24032484 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2404
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2485
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
24052486 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
24062487
2407
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2488
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
24082489 {
24092490 TextureData texturedata = null;
24102491
....@@ -2423,13 +2504,34 @@
24232504 if (bump)
24242505 texturedata = ConvertBump(texturedata, false);
24252506
2426
- com.sun.opengl.util.texture.Texture texture =
2427
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2507
+// com.sun.opengl.util.texture.Texture texture =
2508
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
24282509
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);
2510
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2511
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
24312512
2432
- return texture;
2513
+ return texturedata;
2514
+ }
2515
+
2516
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2517
+ {
2518
+ TextureData texturedata = null;
2519
+
2520
+ try
2521
+ {
2522
+ texturedata =
2523
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2524
+ bim,
2525
+ true);
2526
+ } catch (Exception e)
2527
+ {
2528
+ throw new javax.media.opengl.GLException(e);
2529
+ }
2530
+
2531
+ if (bump)
2532
+ texturedata = ConvertBump(texturedata, false);
2533
+
2534
+ return texturedata;
24332535 }
24342536
24352537 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3502,6 +3604,8 @@
35023604
35033605 System.out.println("LOADING TEXTURE : " + name);
35043606
3607
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3608
+
35053609 //
35063610 if (false) // compressbit > 0)
35073611 {
....@@ -7900,7 +8004,7 @@
79008004 String pigment = Object3D.GetPigment(tex);
79018005 String bump = Object3D.GetBump(tex);
79028006
7903
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8007
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79048008 {
79058009 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79068010 // System.out.println("; bump = " + bump);
....@@ -7915,11 +8019,69 @@
79158019 pigment = null;
79168020 }
79178021
7918
- ReleaseTexture(bump, true);
7919
- ReleaseTexture(pigment, false);
8022
+ ReleaseTexture(tex, true);
8023
+ ReleaseTexture(tex, false);
79208024 }
79218025
7922
- void ReleaseTexture(String tex, boolean bump)
8026
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
8027
+ {
8028
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8029
+ {
8030
+ return;
8031
+ }
8032
+
8033
+ if (tex == null)
8034
+ {
8035
+ ReleaseTexture(null, false);
8036
+ return;
8037
+ }
8038
+
8039
+ String pigment = Object3D.GetPigment(tex);
8040
+
8041
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8042
+ {
8043
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8044
+ // System.out.println("; bump = " + bump);
8045
+ }
8046
+
8047
+ if (pigment.equals(""))
8048
+ {
8049
+ pigment = null;
8050
+ }
8051
+
8052
+ ReleaseTexture(tex, false);
8053
+ }
8054
+
8055
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
8056
+ {
8057
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8058
+ {
8059
+ return;
8060
+ }
8061
+
8062
+ if (tex == null)
8063
+ {
8064
+ ReleaseTexture(null, true);
8065
+ return;
8066
+ }
8067
+
8068
+ String bump = Object3D.GetBump(tex);
8069
+
8070
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8071
+ {
8072
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8073
+ // System.out.println("; bump = " + bump);
8074
+ }
8075
+
8076
+ if (bump.equals(""))
8077
+ {
8078
+ bump = null;
8079
+ }
8080
+
8081
+ ReleaseTexture(tex, true);
8082
+ }
8083
+
8084
+ void ReleaseTexture(cTexture tex, boolean bump)
79238085 {
79248086 if (// DrawMode() != 0 || /*tex == null ||*/
79258087 ambientOcclusion ) // || !textureon)
....@@ -7930,7 +8092,7 @@
79308092 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
79318093
79328094 if (tex != null)
7933
- texture = textures.get(tex);
8095
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
79348096
79358097 // //assert( texture != null );
79368098 // if (texture == null)
....@@ -8022,7 +8184,55 @@
80228184 }
80238185 }
80248186
8025
- /*boolean*/ public void BindTextures(cTexture tex, int resolution) // INTERFACE
8187
+ /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
8188
+ {
8189
+// if (// DrawMode() != 0 || /*tex == null ||*/
8190
+// ambientOcclusion ) // || !textureon)
8191
+// {
8192
+// return; // false;
8193
+// }
8194
+//
8195
+// if (tex == null)
8196
+// {
8197
+// BindTexture(null,false,resolution);
8198
+// BindTexture(null,true,resolution);
8199
+// return;
8200
+// }
8201
+//
8202
+// String pigment = Object3D.GetPigment(tex);
8203
+// String bump = Object3D.GetBump(tex);
8204
+//
8205
+// usedtextures.add(pigment);
8206
+// usedtextures.add(bump);
8207
+//
8208
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8209
+// {
8210
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8211
+// // System.out.println("; bump = " + bump);
8212
+// }
8213
+//
8214
+// if (bump.equals(""))
8215
+// {
8216
+// bump = null;
8217
+// }
8218
+// if (pigment.equals(""))
8219
+// {
8220
+// pigment = null;
8221
+// }
8222
+//
8223
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8224
+// BindTexture(pigment, false, resolution);
8225
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8226
+// BindTexture(bump, true, resolution);
8227
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8228
+//
8229
+// return; // true;
8230
+
8231
+ BindPigmentTexture(tex, resolution);
8232
+ BindBumpTexture(tex, resolution);
8233
+ }
8234
+
8235
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
80268236 {
80278237 if (// DrawMode() != 0 || /*tex == null ||*/
80288238 ambientOcclusion ) // || !textureon)
....@@ -8033,17 +8243,47 @@
80338243 if (tex == null)
80348244 {
80358245 BindTexture(null,false,resolution);
8036
- BindTexture(null,true,resolution);
80378246 return;
80388247 }
80398248
80408249 String pigment = Object3D.GetPigment(tex);
8250
+
8251
+ usedtextures.add(tex);
8252
+
8253
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8254
+ {
8255
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8256
+ // System.out.println("; bump = " + bump);
8257
+ }
8258
+
8259
+ if (pigment.equals(""))
8260
+ {
8261
+ pigment = null;
8262
+ }
8263
+
8264
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8265
+ BindTexture(tex, false, resolution);
8266
+ }
8267
+
8268
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8269
+ {
8270
+ if (// DrawMode() != 0 || /*tex == null ||*/
8271
+ ambientOcclusion ) // || !textureon)
8272
+ {
8273
+ return; // false;
8274
+ }
8275
+
8276
+ if (tex == null)
8277
+ {
8278
+ BindTexture(null,true,resolution);
8279
+ return;
8280
+ }
8281
+
80418282 String bump = Object3D.GetBump(tex);
80428283
8043
- usedtextures.put(pigment, pigment);
8044
- usedtextures.put(bump, bump);
8284
+ usedtextures.add(tex);
80458285
8046
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8286
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
80478287 {
80488288 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
80498289 // System.out.println("; bump = " + bump);
....@@ -8053,43 +8293,82 @@
80538293 {
80548294 bump = null;
80558295 }
8056
- if (pigment.equals(""))
8057
- {
8058
- pigment = null;
8059
- }
80608296
8061
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8062
- BindTexture(pigment, false, resolution);
80638297 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8064
- BindTexture(bump, true, resolution);
8298
+ BindTexture(tex, true, resolution);
80658299 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8066
-
8067
- return; // true;
80688300 }
80698301
8070
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution)
8302
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8303
+
8304
+ private boolean FileExists(String tex)
80718305 {
8072
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8306
+ if (missingTextures.contains(tex))
8307
+ {
8308
+ return false;
8309
+ }
8310
+
8311
+ boolean fileExists = new File(tex).exists();
8312
+
8313
+ if (!fileExists)
8314
+ {
8315
+ // If file exists, the "new File()" is not executed sgain
8316
+ missingTextures.add(tex);
8317
+ }
8318
+
8319
+ return fileExists;
8320
+ }
8321
+
8322
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
8323
+ {
8324
+ CacheTexture texturecache = null;
80738325
80748326 if (tex != null)
80758327 {
8076
- String texname = tex;
8328
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8329
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
80778330
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;
8331
+ if (texname.equals("") && texdata == null)
8332
+ {
8333
+ return null;
8334
+ }
8335
+
8336
+ String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
8337
+
8338
+// String[] split = tex.split("Textures");
8339
+// if (split.length > 1)
8340
+// texname = "/Users/nbriere/Textures" + split[split.length-1];
8341
+// else
8342
+// if (!texname.startsWith("/"))
8343
+// texname = "/Users/nbriere/Textures/" + texname;
8344
+ if (!FileExists(texname))
8345
+ {
8346
+ texname = fallbackTextureName;
8347
+ }
80848348
80858349 if (CACHETEXTURE)
8086
- texture = textures.get(texname); // TEXTURE CACHE
8087
-
8088
- TextureData texturedata = null;
8089
-
8090
- if (texture == null || texture.resolution < resolution)
80918350 {
8092
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8351
+ if (texdata == null)
8352
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8353
+ else
8354
+ texturecache = bimtextures.get(texdata);
8355
+ }
8356
+
8357
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8358
+ {
8359
+ TextureData texturedata = null;
8360
+
8361
+ if (texdata != null)
8362
+ {
8363
+ BufferedImage bim = //new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8364
+
8365
+ CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8366
+
8367
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8368
+ bimtextures.put(texdata, texturecache);
8369
+ }
8370
+ else
8371
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
80938372 {
80948373 assert(!bump);
80958374 // if (bump)
....@@ -8100,19 +8379,23 @@
81008379 // }
81018380 // else
81028381 // {
8103
- texture = textures.get(tex);
8104
- if (texture == null)
8382
+ // texturecache = textures.get(texname); // suspicious
8383
+ if (texturecache == null)
81058384 {
8106
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8385
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
81078386 }
8387
+ else
8388
+ new Exception().printStackTrace();
81088389 // }
81098390 } else
8110
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8391
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
81118392 {
81128393 assert(bump);
8113
- texture = textures.get(tex);
8114
- if (texture == null)
8115
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8394
+ // texturecache = textures.get(texname); // suspicious
8395
+ if (texturecache == null)
8396
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8397
+ else
8398
+ new Exception().printStackTrace();
81168399 } else
81178400 {
81188401 //if (tex.equals("IMMORTAL"))
....@@ -8120,11 +8403,13 @@
81208403 // texture = GetResourceTexture("default.png");
81218404 //} else
81228405 //{
8123
- if (tex.equals("WHITE_NOISE"))
8406
+ if (texname.endsWith("WHITE_NOISE"))
81248407 {
8125
- texture = textures.get(tex);
8126
- if (texture == null)
8127
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8408
+ // texturecache = textures.get(texname); // suspicious
8409
+ if (texturecache == null)
8410
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8411
+ else
8412
+ new Exception().printStackTrace();
81288413 } else
81298414 {
81308415 if (textureon)
....@@ -8149,7 +8434,7 @@
81498434 }
81508435
81518436 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
8152
- if (!new File(cachename).exists())
8437
+ if (!FileExists(cachename))
81538438 cachename = texname;
81548439 else
81558440 processbump = false; // don't process bump map again
....@@ -8171,7 +8456,7 @@
81718456 }
81728457
81738458 cachename = texname.substring(0, texname.length()-4)+ext+".png";
8174
- if (!new File(cachename).exists())
8459
+ if (!FileExists(cachename))
81758460 cachename = texname;
81768461 else
81778462 processbump = false; // don't process bump map again
....@@ -8180,20 +8465,22 @@
81808465 texturedata = GetFileTexture(cachename, processbump, resolution);
81818466
81828467
8183
- if (texturedata != null)
8184
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8468
+ if (texturedata == null)
8469
+ throw new Exception();
8470
+
8471
+ texturecache = new CacheTexture(texturedata,resolution);
81858472 //texture = GetTexture(tex, bump);
81868473 }
81878474 }
81888475 //}
81898476 }
81908477
8191
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8478
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
81928479 {
81938480 //return false;
81948481
81958482 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8196
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8483
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
81978484 {
81988485 // String ext = "_highres";
81998486 // if (REDUCETEXTURE)
....@@ -8210,52 +8497,17 @@
82108497 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
82118498 if (!cachefile.exists())
82128499 {
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))
8500
+ //if (texturedata.getWidth() == texturedata.getHeight())
82228501 {
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);
8502
+ BufferedImage rendImage = CreateBim(texturedata);
8503
+
82538504 ImageWriter writer = null;
82548505 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
82558506 if (iter.hasNext()) {
82568507 writer = (ImageWriter)iter.next();
82578508 }
8258
- float compressionQuality = 0.9f;
8509
+
8510
+ float compressionQuality = 0.85f;
82598511 try
82608512 {
82618513 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8272,18 +8524,20 @@
82728524 }
82738525 }
82748526 }
8275
-
8527
+
8528
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8529
+
82768530 //System.out.println("Texture = " + tex);
8277
- if (textures.containsKey(texname))
8531
+ if (textures.containsKey(tex))
82788532 {
8279
- CacheTexture thetex = textures.get(texname);
8533
+ CacheTexture thetex = textures.get(tex);
82808534 thetex.texture.disable();
82818535 thetex.texture.dispose();
8282
- textures.remove(texname);
8536
+ textures.remove(tex);
82838537 }
82848538
8285
- texture.texturedata = texturedata;
8286
- textures.put(texname, texture);
8539
+ //texture.texturedata = texturedata;
8540
+ textures.put(tex, texturecache);
82878541
82888542 // newtex = true;
82898543 }
....@@ -8299,10 +8553,41 @@
82998553 }
83008554 }
83018555
8302
- return texture;
8556
+ return texturecache;
83038557 }
83048558
8305
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution)
8559
+ static void EmbedTextures(cTexture tex)
8560
+ {
8561
+ if (tex.pigmentdata == null)
8562
+ {
8563
+ String texname = Object3D.GetPigment(tex);
8564
+
8565
+ CacheTexture texturecache = texturepigment.get(tex);
8566
+
8567
+ if (texturecache != null)
8568
+ {
8569
+ tex.pigmentdata = ((ByteBuffer)texturecache.texturedata.getBuffer()).array();
8570
+ tex.pw = texturecache.texturedata.getWidth();
8571
+ tex.ph = texturecache.texturedata.getHeight();
8572
+ }
8573
+ }
8574
+
8575
+ if (tex.bumpdata == null)
8576
+ {
8577
+ String texname = Object3D.GetBump(tex);
8578
+
8579
+ CacheTexture texturecache = texturebump.get(tex);
8580
+
8581
+ if (texturecache != null)
8582
+ {
8583
+ tex.bumpdata = ((ByteBuffer)texturecache.texturedata.getBuffer()).array();
8584
+ tex.bw = texturecache.texturedata.getWidth();
8585
+ tex.bh = texturecache.texturedata.getHeight();
8586
+ }
8587
+ }
8588
+ }
8589
+
8590
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
83068591 {
83078592 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
83088593
....@@ -8320,21 +8605,21 @@
83208605 return texture!=null?texture.texture:null;
83218606 }
83228607
8323
- public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution)
8608
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
83248609 {
83258610 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
83268611
83278612 return texture!=null?texture.texturedata:null;
83288613 }
83298614
8330
- boolean BindTexture(String tex, boolean bump, int resolution)
8615
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
83318616 {
83328617 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
83338618 {
83348619 return false;
83358620 }
83368621
8337
- boolean newtex = false;
8622
+ //boolean newtex = false;
83388623
83398624 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
83408625
....@@ -8366,7 +8651,7 @@
83668651 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
83678652 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
83688653
8369
- return newtex;
8654
+ return true; // Warning: not used.
83708655 }
83718656
83728657 ShadowBuffer shadowPBuf;
....@@ -9204,11 +9489,35 @@
92049489 jy8[3] = 0.5f;
92059490 }
92069491
9207
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9492
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
92089493 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
92099494 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
92109495 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
92119496
9497
+ void ResetOptions()
9498
+ {
9499
+ options1[0] = 100;
9500
+ options1[1] = 0.025f;
9501
+ options1[2] = 0.01f;
9502
+ options1[3] = 0;
9503
+ options1[4] = 0;
9504
+
9505
+ options2[0] = 0;
9506
+ options2[1] = 0.75f;
9507
+ options2[2] = 0;
9508
+ options2[3] = 0;
9509
+
9510
+ options3[0] = 1;
9511
+ options3[1] = 1;
9512
+ options3[2] = 1;
9513
+ options3[3] = 0;
9514
+
9515
+ options4[0] = 1;
9516
+ options4[1] = 0;
9517
+ options4[2] = 1;
9518
+ options4[3] = 0;
9519
+ }
9520
+
92129521 static int imagecount = 0; // movie generation
92139522
92149523 static int jitter = 0;
....@@ -9304,8 +9613,8 @@
93049613 assert (parentcam != renderCamera);
93059614
93069615 if (renderCamera != lightCamera)
9307
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9308
- LA.matConcat(matrix, parentcam.toParent, matrix);
9616
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9617
+ LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
93099618
93109619 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
93119620
....@@ -9320,8 +9629,8 @@
93209629 LA.matCopy(renderCamera.fromScreen, matrix);
93219630
93229631 if (renderCamera != lightCamera)
9323
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9324
- LA.matConcat(parentcam.fromParent, matrix, matrix);
9632
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9633
+ LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
93259634
93269635 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
93279636
....@@ -9538,7 +9847,7 @@
95389847
95399848 if (!BOXMODE)
95409849 {
9541
- System.out.println("image: " + fullname + " (wav cursor=" + (GrafreeD.wav.cursor / 735 / 4) + ")");
9850
+ System.out.println("image: " + fullname + " (wav cursor=" + (Grafreed.wav.cursor / 735 / 4) + ")");
95429851 }
95439852
95449853 if (!BOXMODE)
....@@ -9576,7 +9885,7 @@
95769885 ABORTED = false;
95779886 }
95789887 else
9579
- GrafreeD.wav.cursor += 735 * ACSIZE;
9888
+ Grafreed.wav.cursor += 735 * ACSIZE;
95809889
95819890 if (false)
95829891 {
....@@ -10239,11 +10548,11 @@
1023910548
1024010549 public void display(GLAutoDrawable drawable)
1024110550 {
10242
- if (GrafreeD.savesound && GrafreeD.hassound)
10551
+ if (Grafreed.savesound && Grafreed.hassound)
1024310552 {
10244
- GrafreeD.wav.save();
10245
- GrafreeD.savesound = false;
10246
- GrafreeD.hassound = false;
10553
+ Grafreed.wav.save();
10554
+ Grafreed.savesound = false;
10555
+ Grafreed.hassound = false;
1024710556 }
1024810557 // if (DEBUG_SELECTION)
1024910558 // {
....@@ -10319,6 +10628,7 @@
1031910628 ANTIALIAS = 0;
1032010629 //System.out.println("RESTART");
1032110630 AAtimer.restart();
10631
+ Globals.TIMERRUNNING = true;
1032210632 }
1032310633 }
1032410634 }
....@@ -10373,7 +10683,7 @@
1037310683 Object3D theobject = object;
1037410684 Object3D theparent = object.parent;
1037510685 object.parent = null;
10376
- object = (Object3D)GrafreeD.clone(object);
10686
+ object = (Object3D)Grafreed.clone(object);
1037710687 object.Stripify();
1037810688 if (theobject.selection == null || theobject.selection.Size() == 0)
1037910689 theobject.PreprocessOcclusion(this);
....@@ -10386,13 +10696,14 @@
1038610696 ambientOcclusion = false;
1038710697 }
1038810698
10389
- if (Globals.lighttouched && DrawMode() == DEFAULT && !lightMode) // && !FROZEN)
10699
+ if (//Globals.lighttouched &&
10700
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1039010701 {
1039110702 //if (RENDERSHADOW) // ?
1039210703 if (!IsFrozen())
1039310704 {
1039410705 // dec 2012
10395
- if (!ambientOcclusion && !(!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0))
10706
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
1039610707 {
1039710708 Globals.framecount++;
1039810709 shadowbuffer.display();
....@@ -10519,8 +10830,8 @@
1051910830
1052010831 // if (parentcam != renderCamera) // not a light
1052110832 if (cam != lightCamera)
10522
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10523
- LA.matConcat(matrix, parentcam.toParent, matrix);
10833
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10834
+ LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
1052410835
1052510836 for (int j = 0; j < 4; j++)
1052610837 {
....@@ -10534,8 +10845,8 @@
1053410845
1053510846 // if (parentcam != renderCamera) // not a light
1053610847 if (cam != lightCamera)
10537
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10538
- LA.matConcat(parentcam.fromParent, matrix, matrix);
10848
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10849
+ LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
1053910850
1054010851 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1054110852
....@@ -10794,7 +11105,16 @@
1079411105 // Bump noise
1079511106 gl.glActiveTexture(GL.GL_TEXTURE6);
1079611107 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
10797
- BindTexture(NOISE_TEXTURE, false, 2);
11108
+
11109
+ try
11110
+ {
11111
+ BindTexture(NOISE_TEXTURE, false, 2);
11112
+ }
11113
+ catch (Exception e)
11114
+ {
11115
+ System.err.println("FAILED: " + NOISE_TEXTURE);
11116
+ }
11117
+
1079811118
1079911119 gl.glActiveTexture(GL.GL_TEXTURE0);
1080011120 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -10817,9 +11137,9 @@
1081711137
1081811138 gl.glMatrixMode(GL.GL_MODELVIEW);
1081911139
10820
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10821
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10822
-//gl.glEnable(gl.GL_MULTISAMPLE);
11140
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11141
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11142
+gl.glEnable(gl.GL_MULTISAMPLE);
1082311143 } else
1082411144 {
1082511145 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -10830,7 +11150,7 @@
1083011150 //System.out.println("BLENDING ON");
1083111151 gl.glEnable(GL.GL_BLEND);
1083211152 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
10833
-
11153
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1083411154 gl.glMatrixMode(gl.GL_PROJECTION);
1083511155 gl.glLoadIdentity();
1083611156
....@@ -10919,8 +11239,8 @@
1091911239 System.err.println("parentcam != renderCamera");
1092011240
1092111241 // if (cam != lightCamera)
10922
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10923
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11242
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11243
+ LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
1092411244 }
1092511245
1092611246 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -10941,8 +11261,8 @@
1094111261 if (true) // TODO
1094211262 {
1094311263 if (cam != lightCamera)
10944
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10945
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11264
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11265
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
1094611266 }
1094711267
1094811268 LA.xformPos(light0, cam.toScreen, light0);
....@@ -11279,23 +11599,44 @@
1127911599 e.printStackTrace();
1128011600 }
1128111601
11282
- if (GrafreeD.RENDERME > 0)
11283
- GrafreeD.RENDERME--; // mechante magouille
11602
+ if (Grafreed.RENDERME > 0)
11603
+ Grafreed.RENDERME--; // mechante magouille
1128411604
1128511605 Globals.ONESTEP = false;
1128611606 }
1128711607
1128811608 static boolean zoomonce = false;
1128911609
11610
+ static void CreateSelectedPoint()
11611
+ {
11612
+ if (selectedpoint == null)
11613
+ {
11614
+ debugpointG = new Sphere();
11615
+ debugpointP = new Sphere();
11616
+ debugpointC = new Sphere();
11617
+ debugpointR = new Sphere();
11618
+
11619
+ selectedpoint = new Superellipsoid();
11620
+
11621
+ for (int i=0; i<8; i++)
11622
+ {
11623
+ debugpoints[i] = new Sphere();
11624
+ }
11625
+ }
11626
+ }
11627
+
1129011628 void DrawObject(GL gl, boolean draw)
1129111629 {
11630
+ // To clear camera values
11631
+ ResetOptions();
11632
+
1129211633 //System.out.println("DRAW OBJECT " + mouseDown);
1129311634 // DrawMode() = SELECTION;
1129411635 //GL gl = getGL();
1129511636 if ((TRACK || SHADOWTRACK) || zoomonce)
1129611637 {
1129711638 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11298
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11639
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1129911640 pingthread.StepToTarget(true); // true);
1130011641 // zoomonce = false;
1130111642 }
....@@ -11350,7 +11691,14 @@
1135011691
1135111692 usedtextures.clear();
1135211693
11353
- BindTextures(DEFAULT_TEXTURES, 2);
11694
+ try
11695
+ {
11696
+ BindTextures(DEFAULT_TEXTURES, 2);
11697
+ }
11698
+ catch (Exception e)
11699
+ {
11700
+ System.err.println("FAILED: " + DEFAULT_TEXTURES);
11701
+ }
1135411702 }
1135511703 //System.out.println("--> " + stackdepth);
1135611704 // GrafreeD.traceon();
....@@ -11360,8 +11708,9 @@
1136011708
1136111709 if (DrawMode() == DEFAULT)
1136211710 {
11363
- if (DEBUG)
11711
+ if (Globals.DEBUG)
1136411712 {
11713
+ CreateSelectedPoint();
1136511714 float radius = 0.05f;
1136611715 if (selectedpoint.radius != radius)
1136711716 {
....@@ -11415,20 +11764,32 @@
1141511764 ReleaseTextures(DEFAULT_TEXTURES);
1141611765
1141711766 if (CLEANCACHE)
11418
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11767
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1141911768 {
11420
- String tex = e.nextElement();
11769
+ cTexture tex = e.nextElement();
1142111770
1142211771 // System.out.println("Texture --------- " + tex);
1142311772
11424
- if (tex.equals("WHITE_NOISE"))
11773
+ if (tex.equals("WHITE_NOISE:"))
1142511774 continue;
1142611775
11427
- if (!usedtextures.containsKey(tex))
11776
+ if (!usedtextures.contains(tex))
1142811777 {
11778
+ CacheTexture gettex = texturepigment.get(tex);
1142911779 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11430
- textures.get(tex).texture.dispose();
11431
- textures.remove(tex);
11780
+ if (gettex != null)
11781
+ {
11782
+ gettex.texture.dispose();
11783
+ texturepigment.remove(tex);
11784
+ }
11785
+
11786
+ gettex = texturebump.get(tex);
11787
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11788
+ if (gettex != null)
11789
+ {
11790
+ gettex.texture.dispose();
11791
+ texturebump.remove(tex);
11792
+ }
1143211793 }
1143311794 }
1143411795 }
....@@ -11441,7 +11802,14 @@
1144111802 if (checker != null && DrawMode() == DEFAULT)
1144211803 {
1144311804 //BindTexture(IMMORTAL_TEXTURE);
11444
- BindTextures(checker.GetTextures(), checker.texres);
11805
+ try
11806
+ {
11807
+ BindTextures(checker.GetTextures(), checker.texres);
11808
+ }
11809
+ catch (Exception e)
11810
+ {
11811
+ System.err.println("FAILED: " + checker.GetTextures());
11812
+ }
1144511813 // NEAREST
1144611814 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
1144711815 DrawChecker(gl);
....@@ -11523,7 +11891,7 @@
1152311891 return;
1152411892 }
1152511893
11526
- String string = obj.GetToolTip();
11894
+ String string = obj.toString(); //.GetToolTip();
1152711895
1152811896 GL gl = GetGL();
1152911897
....@@ -11840,8 +12208,8 @@
1184012208 //obj.TransformToWorld(light, light);
1184112209 for (int i = tp.size(); --i >= 0;)
1184212210 {
11843
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
11844
- LA.xformPos(light, tp.get(i).toParent, light);
12211
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12212
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1184512213 }
1184612214
1184712215
....@@ -11858,8 +12226,8 @@
1185812226 parentcam = cameras[0];
1185912227 }
1186012228
11861
- for (int count = parentcam.GetTransformCount(); --count>=0;)
11862
- LA.xformPos(light, parentcam.toParent, light); // may 2013
12229
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
12230
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1186312231
1186412232 LA.xformPos(light, renderCamera.toScreen, light);
1186512233
....@@ -12473,8 +12841,8 @@
1247312841
1247412842 // display shadow only (bump == 0)
1247512843 "SUB temp.x, half.x, shadow.x;" +
12476
- "MOV temp.y, -params6.x;" +
12477
- "SLT temp.z, temp.y, zero.x;" +
12844
+ "MOV temp.y, -params5.z;" + // params6.x;" +
12845
+ "SLT temp.z, temp.y, -one2048th.x;" +
1247812846 "SUB temp.y, one.x, temp.z;" +
1247912847 "MUL temp.x, temp.x, temp.y;" +
1248012848 "KIL temp.x;" +
....@@ -12754,7 +13122,7 @@
1275413122 "MUL final.y, fragment.texcoord[0].x, c256;" +
1275513123 "FLR final.x, final.y;" +
1275613124 "SUB final.y, final.y, final.x;" +
12757
- //"MUL final.x, final.x, c256i;" +
13125
+ "MUL final.x, final.x, c256i;" +
1275813126 "MOV final.z, zero.x;" +
1275913127 "MOV final.a, one.w;":""
1276013128 ) +
....@@ -12762,7 +13130,7 @@
1276213130 "MUL final.y, fragment.texcoord[0].y, c256;" +
1276313131 "FLR final.x, final.y;" +
1276413132 "SUB final.y, final.y, final.x;" +
12765
- //"MUL final.x, final.x, c256i;" +
13133
+ "MUL final.x, final.x, c256i;" +
1276613134 "MOV final.z, zero.x;" +
1276713135 "MOV final.a, one.w;":""
1276813136 ) +
....@@ -12805,7 +13173,7 @@
1280513173 //once = true;
1280613174 }
1280713175
12808
- System.out.print("Program #" + mode + "; length = " + program.length());
13176
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1280913177 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1281013178 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1281113179
....@@ -12938,12 +13306,16 @@
1293813306
1293913307 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1294013308 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13309
+
13310
+ // Compare fragment depth in light space with shadowmap.
1294113311 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1294213312 "SGE temp.y, temp.x, zero.x;" +
12943
- "SUB " + shadow + ".y, one.x, temp.y;" +
13313
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13314
+
13315
+ // Reverse comparison
1294413316 "SUB temp.x, one.x, temp.x;" +
1294513317 "MUL " + shadow + ".x, temp.x, temp.y;" +
12946
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13318
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1294713319 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1294813320
1294913321 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -12957,6 +13329,10 @@
1295713329 // No shadow for backface
1295813330 "DP3 temp.x, normal, lightd;" +
1295913331 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13332
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13333
+
13334
+ // No shadow when out of frustrum
13335
+ "SGE temp.x, " + depth + ".z, one.z;" +
1296013336 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1296113337 "";
1296213338 }
....@@ -13103,7 +13479,8 @@
1310313479 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1310413480 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1310513481 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13106
- Object3D.cVector2[] vector2buffer;
13482
+
13483
+ //Object3D.cVector2[] vector2buffer;
1310713484
1310813485 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1310913486 // OUT : diff, spec
....@@ -13119,9 +13496,10 @@
1311913496 "DP3 " + dest + ".z," + "normals," + "eye;" +
1312013497 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1312113498 //"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;" +
13499
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13500
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13501
+
13502
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1312513503 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1312613504 "RCP " + dest + ".w," + dest + ".w;" +
1312713505 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13515,7 +13893,7 @@
1351513893 public void mousePressed(MouseEvent e)
1351613894 {
1351713895 //System.out.println("mousePressed: " + e);
13518
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
13896
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1351913897 }
1352013898
1352113899 static long prevtime = 0;
....@@ -13591,8 +13969,8 @@
1359113969 // mode |= META;
1359213970 //}
1359313971
13594
- SetMouseMode(WHEEL | e.getModifiersEx());
13595
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
13972
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
13973
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1359613974 anchorX = ax;
1359713975 anchorY = ay;
1359813976 prevX = px;
....@@ -13626,6 +14004,7 @@
1362614004 else
1362714005 if (evt.getSource() == AAtimer)
1362814006 {
14007
+ Globals.TIMERRUNNING = false;
1362914008 if (mouseDown)
1363014009 {
1363114010 //new Exception().printStackTrace();
....@@ -13651,6 +14030,10 @@
1365114030 // LIVE = waslive;
1365214031 // wasliveok = true;
1365314032 // waslive = false;
14033
+
14034
+ // May 2019 Forget it:
14035
+ if (true)
14036
+ return;
1365414037
1365514038 // source == timer
1365614039 if (mouseDown)
....@@ -13681,7 +14064,7 @@
1368114064
1368214065 // fev 2014???
1368314066 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13684
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14067
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1368514068 pingthread.StepToTarget(true); // true);
1368614069 }
1368714070 // if (!LIVE)
....@@ -13690,12 +14073,13 @@
1369014073
1369114074 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1369214075
13693
- void clickStart(int x, int y, int modifiers)
14076
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1369414077 {
1369514078 if (!wasliveok)
1369614079 return;
1369714080
1369814081 AAtimer.restart(); //
14082
+ Globals.TIMERRUNNING = true;
1369914083
1370014084 // waslive = LIVE;
1370114085 // LIVE = false;
....@@ -13707,7 +14091,7 @@
1370714091 // touched = true; // main DL
1370814092 if (isRenderer)
1370914093 {
13710
- SetMouseMode(modifiers);
14094
+ SetMouseMode(modifiers, modifiersex);
1371114095 }
1371214096
1371314097 selectX = anchorX = x;
....@@ -13720,7 +14104,7 @@
1372014104 clicked = true;
1372114105 hold = false;
1372214106
13723
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14107
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1372414108 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1372514109 {
1372614110 // System.out.println("RESTART II " + modifiers);
....@@ -13751,7 +14135,7 @@
1375114135 info.camera = renderCamera;
1375214136 info.x = x;
1375314137 info.y = y;
13754
- info.modifiers = modifiers;
14138
+ info.modifiers = modifiersex;
1375514139 editObj = object.doEditClick(info, 0);
1375614140 if (!editObj)
1375714141 {
....@@ -13768,9 +14152,12 @@
1376814152
1376914153 public void mouseDragged(MouseEvent e)
1377014154 {
14155
+ Globals.MOUSEDRAGGED = true;
14156
+
1377114157 //System.out.println("mouseDragged: " + e);
1377214158 if (isRenderer)
1377314159 movingcamera = true;
14160
+
1377414161 //if (drawing)
1377514162 //return;
1377614163 if ((e.getModifiersEx() & CTRL) != 0
....@@ -13780,7 +14167,7 @@
1378014167 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1378114168 }
1378214169 else
13783
- drag(e.getX(), e.getY(), e.getModifiersEx());
14170
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1378414171
1378514172 //try { Thread.sleep(1); } catch (Exception ex) {}
1378614173 }
....@@ -14017,7 +14404,7 @@
1401714404 {
1401814405 Globals.lighttouched = true;
1401914406 }
14020
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14407
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1402114408 }
1402214409 //else
1402314410 }
....@@ -14031,12 +14418,12 @@
1403114418 void GoDown(int mod)
1403214419 {
1403314420 MODIFIERS |= COMMAND;
14034
- /*
14421
+ /**/
1403514422 if((mod&SHIFT) == SHIFT)
1403614423 manipCamera.RotatePosition(0, -speed);
1403714424 else
14038
- manipCamera.BackForth(0, -speed*delta, getWidth());
14039
- */
14425
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14426
+ /**/
1404014427 if ((mod & SHIFT) == SHIFT)
1404114428 {
1404214429 mouseMode = mouseMode; // VR??
....@@ -14052,12 +14439,12 @@
1405214439 void GoUp(int mod)
1405314440 {
1405414441 MODIFIERS |= COMMAND;
14055
- /*
14442
+ /**/
1405614443 if((mod&SHIFT) == SHIFT)
1405714444 manipCamera.RotatePosition(0, speed);
1405814445 else
14059
- manipCamera.BackForth(0, speed*delta, getWidth());
14060
- */
14446
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14447
+ /**/
1406114448 if ((mod & SHIFT) == SHIFT)
1406214449 {
1406314450 mouseMode = mouseMode;
....@@ -14073,12 +14460,12 @@
1407314460 void GoLeft(int mod)
1407414461 {
1407514462 MODIFIERS |= COMMAND;
14076
- /*
14463
+ /**/
1407714464 if((mod&SHIFT) == SHIFT)
14078
- manipCamera.RotatePosition(speed, 0);
14079
- else
1408014465 manipCamera.Translate(speed*delta, 0, getWidth());
14081
- */
14466
+ else
14467
+ manipCamera.RotatePosition(speed, 0);
14468
+ /**/
1408214469 if ((mod & SHIFT) == SHIFT)
1408314470 {
1408414471 mouseMode = mouseMode;
....@@ -14094,12 +14481,12 @@
1409414481 void GoRight(int mod)
1409514482 {
1409614483 MODIFIERS |= COMMAND;
14097
- /*
14484
+ /**/
1409814485 if((mod&SHIFT) == SHIFT)
14099
- manipCamera.RotatePosition(-speed, 0);
14100
- else
1410114486 manipCamera.Translate(-speed*delta, 0, getWidth());
14102
- */
14487
+ else
14488
+ manipCamera.RotatePosition(-speed, 0);
14489
+ /**/
1410314490 if ((mod & SHIFT) == SHIFT)
1410414491 {
1410514492 mouseMode = mouseMode;
....@@ -14117,7 +14504,7 @@
1411714504 int X, Y;
1411814505 boolean SX, SY;
1411914506
14120
- void drag(int x, int y, int modifiers)
14507
+ void drag(int x, int y, int modifiers, int modifiersex)
1412114508 {
1412214509 if (IsFrozen())
1412314510 {
....@@ -14126,17 +14513,17 @@
1412614513
1412714514 drag = true; // NEW
1412814515
14129
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14516
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1413014517
1413114518 X = x;
1413214519 Y = y;
1413314520 // floating state for animation
14134
- MODIFIERS = modifiers;
14135
- modifiers &= ~1024;
14521
+ MODIFIERS = modifiersex;
14522
+ modifiersex &= ~1024;
1413614523 if (false) // modifiers != 0)
1413714524 {
1413814525 //new Exception().printStackTrace();
14139
- System.out.println("mouseDragged: " + modifiers);
14526
+ System.out.println("mouseDragged: " + modifiersex);
1414014527 System.out.println("SHIFT = " + SHIFT);
1414114528 System.out.println("CONTROL = " + COMMAND);
1414214529 System.out.println("META = " + META);
....@@ -14156,7 +14543,8 @@
1415614543 info.camera = renderCamera;
1415714544 info.x = x;
1415814545 info.y = y;
14159
- object.editWindow.copy.doEditDrag(info);
14546
+ object.GetWindow().copy
14547
+ .doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1416014548 } else
1416114549 {
1416214550 if (x < startX)
....@@ -14320,7 +14708,9 @@
1432014708 ci.camera = renderCamera;
1432114709 if (!isRenderer)
1432214710 {
14323
- if (object.editWindow.copy.doEditClick(ci, 0))
14711
+ //ObjEditor editWindow = object.editWindow;
14712
+ //Object3D copy = editWindow.copy;
14713
+ if (object.doEditClick(ci, 0))
1432414714 {
1432514715 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1432614716 } else
....@@ -14332,7 +14722,11 @@
1433214722
1433314723 public void mouseReleased(MouseEvent e)
1433414724 {
14725
+ Globals.MOUSEDRAGGED = false;
14726
+
1433514727 movingcamera = false;
14728
+ X = 0; // getBounds().width/2;
14729
+ Y = 0; // getBounds().height/2;
1433614730 //System.out.println("mouseReleased: " + e);
1433714731 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1433814732 }
....@@ -14355,9 +14749,9 @@
1435514749 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1435614750 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1435714751
14358
- if (control || command || IsFrozen())
14752
+// No delay if (control || command || IsFrozen())
1435914753 timeout = true;
14360
- else
14754
+// ?? May 2019 else
1436114755 // timer.setDelay((modifiers & 128) != 0?0:350);
1436214756 mouseDown = false;
1436314757 if (!control && !command) // june 2013
....@@ -14467,7 +14861,7 @@
1446714861 System.out.println("keyReleased: " + e);
1446814862 }
1446914863
14470
- void SetMouseMode(int modifiers)
14864
+ void SetMouseMode(int modifiers, int modifiersex)
1447114865 {
1447214866 //System.out.println("SetMouseMode = " + modifiers);
1447314867 //modifiers &= ~1024;
....@@ -14479,25 +14873,25 @@
1447914873 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1448014874 // return;
1448114875 //System.out.println("SetMode = " + modifiers);
14482
- if ((modifiers & WHEEL) == WHEEL)
14876
+ if ((modifiersex & WHEEL) == WHEEL)
1448314877 {
1448414878 mouseMode |= ZOOM;
1448514879 }
1448614880
1448714881 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
14488
- if (capsLocked || (modifiers & META) == META)
14882
+ if (capsLocked) // || (modifiers & META) == META)
1448914883 {
1449014884 mouseMode |= VR; // BACKFORTH;
1449114885 }
14492
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
14886
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1449314887 {
1449414888 mouseMode |= SELECT;
1449514889 }
14496
- if ((modifiers & COMMAND) == COMMAND)
14890
+ if ((modifiersex & COMMAND) == COMMAND)
1449714891 {
1449814892 mouseMode |= SELECT;
1449914893 }
14500
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
14894
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
1450114895 {
1450214896 mouseMode &= ~VR;
1450314897 mouseMode |= TRANSLATE;
....@@ -14526,7 +14920,7 @@
1452614920
1452714921 if (isRenderer) //
1452814922 {
14529
- SetMouseMode(modifiers);
14923
+ SetMouseMode(0, modifiers);
1453014924 }
1453114925
1453214926 Globals.theRenderer.keyPressed(key);
....@@ -14588,7 +14982,8 @@
1458814982 // break;
1458914983 case 'T':
1459014984 CACHETEXTURE ^= true;
14591
- textures.clear();
14985
+ texturepigment.clear();
14986
+ texturebump.clear();
1459214987 // repaint();
1459314988 break;
1459414989 case 'Y':
....@@ -14673,7 +15068,9 @@
1467315068 case 'E' : COMPACT ^= true;
1467415069 repaint();
1467515070 break;
14676
- case 'W' : DEBUGHSB ^= true;
15071
+ case 'W' : // Wide Window (fullscreen)
15072
+ //DEBUGHSB ^= true;
15073
+ ObjEditor.theFrame.ToggleFullScreen();
1467715074 repaint();
1467815075 break;
1467915076 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14698,8 +15095,8 @@
1469815095 RevertCamera();
1469915096 repaint();
1470015097 break;
14701
- case 'L':
1470215098 case 'l':
15099
+ //case 'L':
1470315100 if (lightMode)
1470415101 {
1470515102 lightMode = false;
....@@ -14842,9 +15239,9 @@
1484215239 case '_':
1484315240 kompactbit = 5;
1484415241 break;
14845
- case '+':
14846
- kompactbit = 6;
14847
- break;
15242
+// case '+':
15243
+// kompactbit = 6;
15244
+// break;
1484815245 case ' ':
1484915246 lightMode ^= true;
1485015247 Globals.lighttouched = true;
....@@ -14856,13 +15253,14 @@
1485615253 case ESC:
1485715254 RENDERPROGRAM += 1;
1485815255 RENDERPROGRAM %= 3;
15256
+
1485915257 repaint();
1486015258 break;
1486115259 case 'Z':
1486215260 //RESIZETEXTURE ^= true;
1486315261 //break;
1486415262 case 'z':
14865
- RENDERSHADOW ^= true;
15263
+ Globals.RENDERSHADOW ^= true;
1486615264 Globals.lighttouched = true;
1486715265 repaint();
1486815266 break;
....@@ -14895,8 +15293,9 @@
1489515293 case DELETE:
1489615294 ClearSelection();
1489715295 break;
14898
- /*
1489915296 case '+':
15297
+
15298
+ /*
1490015299 //fontsize += 1;
1490115300 bbzoom *= 2;
1490215301 repaint();
....@@ -14913,17 +15312,17 @@
1491315312 case '=':
1491415313 IncDepth();
1491515314 //fontsize += 1;
14916
- object.editWindow.refreshContents(true);
15315
+ object.GetWindow().refreshContents(true);
1491715316 maskbit = 6;
1491815317 break;
1491915318 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1492015319 DecDepth();
1492115320 maskbit = 5;
1492215321 //if(fontsize > 1) fontsize -= 1;
14923
- if (object.editWindow == null)
14924
- new Exception().printStackTrace();
14925
- else
14926
- object.editWindow.refreshContents(true);
15322
+// if (object.editWindow == null)
15323
+// new Exception().printStackTrace();
15324
+// else
15325
+ object.GetWindow().refreshContents(true);
1492715326 break;
1492815327 case '{':
1492915328 manipCamera.shaper_fovy /= 1.1;
....@@ -14986,7 +15385,7 @@
1498615385 //mode = ROTATE;
1498715386 if ((MODIFIERS & COMMAND) == 0) // VR??
1498815387 {
14989
- SetMouseMode(modifiers);
15388
+ SetMouseMode(0, modifiers);
1499015389 }
1499115390 }
1499215391
....@@ -15122,7 +15521,7 @@
1512215521 {
1512315522 //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
1512415523 //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15125
- if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (mouseMode & SELECT) == 0)
15524
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1512615525 {
1512715526 mouseMoved(e);
1512815527 } else
....@@ -15147,7 +15546,7 @@
1514715546 }
1514815547 */
1514915548
15150
- object.editWindow.EditSelection();
15549
+ object.GetWindow().EditSelection(false);
1515115550 }
1515215551
1515315552 void SelectParent()
....@@ -15164,10 +15563,10 @@
1516415563 {
1516515564 //selectees.remove(i);
1516615565 System.out.println("select parent of " + elem);
15167
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15566
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1516815567 } else
1516915568 {
15170
- group.editWindow.Select(elem.GetTreePath(), first, true);
15569
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1517115570 }
1517215571
1517315572 first = false;
....@@ -15209,12 +15608,12 @@
1520915608 for (int j = 0; j < group.children.size(); j++)
1521015609 {
1521115610 elem = (Object3D) group.children.elementAt(j);
15212
- object.editWindow.Select(elem.GetTreePath(), first, true);
15611
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1521315612 first = false;
1521415613 }
1521515614 } else
1521615615 {
15217
- object.editWindow.Select(elem.GetTreePath(), first, true);
15616
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1521815617 }
1521915618
1522015619 first = false;
....@@ -15225,21 +15624,21 @@
1522515624 {
1522615625 //Composite group = (Composite) object;
1522715626 Object3D group = object;
15228
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15627
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1522915628 }
1523015629
1523115630 void ResetTransform(int mask)
1523215631 {
1523315632 //Composite group = (Composite) object;
1523415633 Object3D group = object;
15235
- group.editWindow.ResetTransform(mask);
15634
+ group.GetWindow().ResetTransform(mask);
1523615635 }
1523715636
1523815637 void FlipTransform()
1523915638 {
1524015639 //Composite group = (Composite) object;
1524115640 Object3D group = object;
15242
- group.editWindow.FlipTransform();
15641
+ group.GetWindow().FlipTransform();
1524315642 // group.editWindow.ReduceMesh(true);
1524415643 }
1524515644
....@@ -15247,7 +15646,7 @@
1524715646 {
1524815647 //Composite group = (Composite) object;
1524915648 Object3D group = object;
15250
- group.editWindow.PrintMemory();
15649
+ group.GetWindow().PrintMemory();
1525115650 // group.editWindow.ReduceMesh(true);
1525215651 }
1525315652
....@@ -15255,7 +15654,7 @@
1525515654 {
1525615655 //Composite group = (Composite) object;
1525715656 Object3D group = object;
15258
- group.editWindow.ResetCentroid();
15657
+ group.GetWindow().ResetCentroid();
1525915658 }
1526015659
1526115660 void IncDepth()
....@@ -15341,7 +15740,9 @@
1534115740 info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1534215741 //Image img = CreateImage(width, height);
1534315742 //System.out.println("width = " + width + "; height = " + height + "\n");
15743
+
1534415744 Graphics gr = g; // img.getGraphics();
15745
+
1534515746 if (!hasMarquee)
1534615747 {
1534715748 if (Xmin < Xmax) // !locked)
....@@ -15429,6 +15830,7 @@
1542915830 info.bounds.y += (height - desired) / 2;
1543015831 }
1543115832 }
15833
+
1543215834 info.g = gr;
1543315835 info.camera = renderCamera;
1543415836 /*
....@@ -15438,15 +15840,55 @@
1543815840 */
1543915841 if (!isRenderer)
1544015842 {
15441
- object.drawEditHandles(info, 0);
15843
+ Grafreed.Assert(object != null);
15844
+ Grafreed.Assert(object.selection != null);
15845
+ if (object.selection.Size() > 0)
15846
+ {
15847
+ int hitSomething = object.selection.get(0).hitSomething;
15848
+
15849
+ info.DX = 0;
15850
+ info.DY = 0;
15851
+ info.W = 1;
15852
+ if (hitSomething == Object3D.hitCenter)
15853
+ {
15854
+ info.DX = X;
15855
+ if (X != 0)
15856
+ info.DX -= info.bounds.width/2;
15857
+
15858
+ info.DY = Y;
15859
+ if (Y != 0)
15860
+ info.DY -= info.bounds.height/2;
15861
+ }
15862
+
15863
+ object.drawEditHandles(info, 0);
15864
+
15865
+ if (drag && (X != 0 || Y != 0))
15866
+ {
15867
+ switch (hitSomething)
15868
+ {
15869
+ case Object3D.hitCenter: gr.setColor(Color.pink);
15870
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15871
+ break;
15872
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
15873
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15874
+ break;
15875
+ case Object3D.hitScale: gr.setColor(Color.cyan);
15876
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15877
+ break;
15878
+ }
15879
+
15880
+ }
15881
+ }
1544215882 }
1544315883 }
15884
+
1544415885 if (isRenderer)
1544515886 {
1544615887 //gr.setColor(Color.black);
1544715888 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1544815889 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1544915890 }
15891
+
1545015892 if (hasMarquee)
1545115893 {
1545215894 gr.setXORMode(Color.white);
....@@ -15559,6 +16001,7 @@
1555916001 public boolean mouseDown(Event evt, int x, int y)
1556016002 {
1556116003 System.out.println("mouseDown: " + evt);
16004
+ System.exit(0);
1556216005 /*
1556316006 locked = true;
1556416007 drag = false;
....@@ -15602,7 +16045,7 @@
1560216045 {
1560316046 keyPressed(0, modifiers);
1560416047 }
15605
- clickStart(x, y, modifiers);
16048
+ // clickStart(x, y, modifiers);
1560616049 return true;
1560716050 }
1560816051
....@@ -15720,7 +16163,7 @@
1572016163 {
1572116164 keyReleased(0, 0);
1572216165 }
15723
- drag(x, y, modifiers);
16166
+ drag(x, y, 0, modifiers);
1572416167 return true;
1572516168 }
1572616169
....@@ -15852,7 +16295,7 @@
1585216295 Object3D object;
1585316296 static Object3D trackedobject;
1585416297 Camera renderCamera; // Light or Eye (or Occlusion)
15855
- /*static*/ Camera manipCamera; // Light or Eye
16298
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1585616299 /*static*/ Camera eyeCamera;
1585716300 /*static*/ Camera lightCamera;
1585816301 int cameracount;
....@@ -16137,16 +16580,16 @@
1613716580 cStatic.objectstack[materialdepth++] = checker;
1613816581 //System.out.println("material " + material);
1613916582 //Applet3D.tracein(this, selected);
16140
- vector2buffer = checker.projectedVertices;
16583
+ //vector2buffer = checker.projectedVertices;
1614116584
1614216585 //checker.GetMaterial().Draw(this, false); // true);
16143
- DrawMaterial(checker.GetMaterial(), false); // true);
16586
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1614416587
1614516588 materialdepth -= 1;
1614616589 if (materialdepth > 0)
1614716590 {
16148
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16149
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
16591
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16592
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1615016593 }
1615116594 //checker.GetMaterial().opacity = 1f;
1615216595 ////checker.GetMaterial().ambient = 1f;
....@@ -16232,6 +16675,14 @@
1623216675 }
1623316676 }
1623416677
16678
+ private Object3D GetFolder()
16679
+ {
16680
+ Object3D folder = object.GetWindow().copy;
16681
+ if (object.GetWindow().copy.selection.Size() > 0)
16682
+ folder = object.GetWindow().copy.selection.elementAt(0);
16683
+ return folder;
16684
+ }
16685
+
1623516686 class SelectBuffer implements GLEventListener
1623616687 {
1623716688
....@@ -16311,6 +16762,17 @@
1631116762
1631216763 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1631316764
16765
+ if (PAINTMODE)
16766
+ {
16767
+ if (object.GetWindow().copy.selection.Size() > 0)
16768
+ {
16769
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16770
+
16771
+ // Make what you paint not selectable.
16772
+ paintobj.ResetSelectable();
16773
+ }
16774
+ }
16775
+
1631416776 //int tmp = selection_view;
1631516777 //selection_view = -1;
1631616778 int temp = DrawMode();
....@@ -16322,6 +16784,17 @@
1632216784 // temp = DEFAULT; // patch for selection debug
1632316785 Globals.drawMode = temp; // WARNING
1632416786
16787
+ if (PAINTMODE)
16788
+ {
16789
+ if (object.GetWindow().copy.selection.Size() > 0)
16790
+ {
16791
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16792
+
16793
+ // Revert.
16794
+ paintobj.RestoreSelectable();
16795
+ }
16796
+ }
16797
+
1632516798 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1632616799
1632716800 // trying different ways of getting the depth info over
....@@ -16369,6 +16842,8 @@
1636916842 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1637016843 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1637116844 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
16845
+
16846
+ CreateSelectedPoint();
1637216847
1637316848 // Will fit the mesh !!!
1637416849 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16418,34 +16893,36 @@
1641816893 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]));
1641916894 }
1642016895
16421
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
16896
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1642216897 }
1642316898 }
1642416899
1642516900 if (!movingcamera && !PAINTMODE)
16426
- object.editWindow.ScreenFitPoint(); // fev 2014
16901
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1642716902
16428
- if (PAINTMODE && GrafreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
16903
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1642916904 {
16430
- Object3D paintobj = GrafreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
16905
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1643116906
16432
- Object3D group = new Object3D("inst" + paintcount++);
16907
+ if (object.GetWindow().copy.selection.Size() > 0)
16908
+ {
16909
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1643316910
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();
16911
+ Object3D inst = new Object3D("inst" + paintcount++);
16912
+
16913
+ inst.CreateMaterial(); // use a void leaf to select instances
16914
+
16915
+ inst.add(paintobj); // link
16916
+
16917
+ object.GetWindow().SnapObject(inst);
16918
+
16919
+ Object3D folder = paintFolder; // GetFolder();
16920
+
16921
+ folder.add(inst);
16922
+
16923
+ object.GetWindow().ResetModel();
16924
+ object.GetWindow().refreshContents();
16925
+ }
1644916926 }
1645016927 else
1645116928 paintcount = 0;
....@@ -16484,6 +16961,11 @@
1648416961 //System.out.println("objects[color] = " + objects[color]);
1648516962 //objects[color].Select();
1648616963 indexcount = 0;
16964
+ ObjEditor window = object.GetWindow();
16965
+ if (window != null && deselect)
16966
+ {
16967
+ window.Select(null, deselect, true);
16968
+ }
1648716969 object.Select(color, deselect);
1648816970 }
1648916971
....@@ -16583,7 +17065,7 @@
1658317065 gl.glDisable(gl.GL_CULL_FACE);
1658417066 }
1658517067
16586
- if (!RENDERSHADOW)
17068
+ if (!Globals.RENDERSHADOW)
1658717069 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1658817070
1658917071 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -16593,7 +17075,7 @@
1659317075 //gl.glColorMask(false, false, false, false);
1659417076
1659517077 //render_scene_from_light_view(gl, drawable, 0, 0);
16596
- if (RENDERSHADOW && Globals.lighttouched && !movingcamera) // && !parent.IsFreezed())
17078
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1659717079 {
1659817080 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1659917081
....@@ -17009,23 +17491,15 @@
1700917491 int AAbuffersize = 0;
1701017492
1701117493 //double[] selectedpoint = new double[3];
17012
- static Superellipsoid selectedpoint = new Superellipsoid();
17494
+ static Superellipsoid selectedpoint;
1701317495 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();
17496
+ static Sphere debugpointG;
17497
+ static Sphere debugpointP;
17498
+ static Sphere debugpointC;
17499
+ static Sphere debugpointR;
1701817500
1701917501 static Sphere debugpoints[] = new Sphere[8];
1702017502
17021
- static
17022
- {
17023
- for (int i=0; i<8; i++)
17024
- {
17025
- debugpoints[i] = new Sphere();
17026
- }
17027
- }
17028
-
1702917503 static void InitPoints(float radius)
1703017504 {
1703117505 for (int i=0; i<8; i++)