Normand Briere
2019-07-21 40f408aaee14abd85d391008b4d22977dc586b50
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
....@@ -61,7 +60,7 @@
6160 //boolean REDUCETEXTURE = true;
6261 boolean CACHETEXTURE = true;
6362 boolean CLEANCACHE = false; // true;
64
- boolean MIPMAP = false; // true;
63
+ boolean MIPMAP = true; // false; // true;
6564 boolean COMPRESSTEXTURE = false;
6665 boolean KOMPACTTEXTURE = false; // true;
6766 boolean RESIZETEXTURE = false;
....@@ -149,6 +148,8 @@
149148 defaultcaps.setAccumBlueBits(16);
150149 defaultcaps.setAccumAlphaBits(16);
151150 }
151
+
152
+ private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
152153
153154 void SetAsGLRenderer(boolean b)
154155 {
....@@ -325,7 +326,7 @@
325326 cStatic.objectstack[materialdepth++] = obj;
326327 //System.out.println("material " + material);
327328 //Applet3D.tracein(this, selected);
328
- display.vector2buffer = obj.projectedVertices;
329
+ //display.vector2buffer = obj.projectedVertices;
329330 if (obj instanceof Camera)
330331 {
331332 display.options1[0] = material.shift;
....@@ -334,14 +335,28 @@
334335 display.options1[2] = material.shadowbias;
335336 display.options1[3] = material.aniso;
336337 display.options1[4] = material.anisoV;
338
+// System.out.println("display.options1[0] " + display.options1[0]);
339
+// System.out.println("display.options1[1] " + display.options1[1]);
340
+// System.out.println("display.options1[2] " + display.options1[2]);
341
+// System.out.println("display.options1[3] " + display.options1[3]);
342
+// System.out.println("display.options1[4] " + display.options1[4]);
337343 display.options2[0] = material.opacity;
338344 display.options2[1] = material.diffuse;
339345 display.options2[2] = material.factor;
346
+// System.out.println("display.options2[0] " + display.options2[0]);
347
+// System.out.println("display.options2[1] " + display.options2[1]);
348
+// System.out.println("display.options2[2] " + display.options2[2]);
340349
341350 cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
351
+// System.out.println("display.options3[0] " + display.options3[0]);
352
+// System.out.println("display.options3[1] " + display.options3[1]);
353
+// System.out.println("display.options3[2] " + display.options3[2]);
342354 display.options4[0] = material.cameralight/0.2f;
343355 display.options4[1] = material.subsurface;
344356 display.options4[2] = material.sheen;
357
+// System.out.println("display.options4[0] " + display.options4[0]);
358
+// System.out.println("display.options4[1] " + display.options4[1]);
359
+// System.out.println("display.options4[2] " + display.options4[2]);
345360
346361 // if (display.CURRENTANTIALIAS > 0)
347362 // display.options3[3] /= 4;
....@@ -357,7 +372,7 @@
357372 /**/
358373 } else
359374 {
360
- DrawMaterial(material, selected);
375
+ DrawMaterial(material, selected, obj.projectedVertices);
361376 }
362377 } else
363378 {
....@@ -381,8 +396,8 @@
381396 cStatic.objectstack[materialdepth++] = obj;
382397 //System.out.println("material " + material);
383398 //Applet3D.tracein("selected ", selected);
384
- display.vector2buffer = obj.projectedVertices;
385
- display.DrawMaterial(material, selected);
399
+ //display.vector2buffer = obj.projectedVertices;
400
+ display.DrawMaterial(material, selected, obj.projectedVertices);
386401 }
387402 }
388403
....@@ -399,8 +414,8 @@
399414 materialdepth -= 1;
400415 if (materialdepth > 0)
401416 {
402
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
403
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
417
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
418
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
404419 }
405420 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
406421 } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
....@@ -420,8 +435,8 @@
420435 materialdepth -= 1;
421436 if (materialdepth > 0)
422437 {
423
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
424
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
438
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
439
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
425440 }
426441 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
427442 //else
....@@ -462,10 +477,12 @@
462477 if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
463478 {
464479 //gl.glBegin(gl.GL_TRIANGLES);
465
- boolean hasnorm = pv.norm != null; // && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0);
480
+ boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0)
481
+ // TEST LIVE NORMALS && !obj.dontselect
482
+ ;
466483 if (!hasnorm)
467484 {
468
- // System.out.println("FUCK!!");
485
+ // System.out.println("Mesh normal");
469486 LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
470487 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
471488 LA.vecCross(obj.v0, obj.v1, obj.v2);
....@@ -1190,10 +1207,12 @@
11901207 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
11911208 }
11921209 }
1210
+
11931211 if (flipV)
11941212 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
11951213 else
11961214 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1215
+
11971216 //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
11981217 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
11991218
....@@ -1213,10 +1232,12 @@
12131232 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
12141233 }
12151234 }
1235
+
12161236 if (flipV)
12171237 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12181238 else
12191239 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1240
+
12201241 //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
12211242 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
12221243
....@@ -1244,8 +1265,10 @@
12441265 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12451266 else
12461267 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1268
+
12471269 //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
12481270 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1271
+
12491272 count2 += 2;
12501273 count3 += 3;
12511274 }
....@@ -1601,7 +1624,7 @@
16011624 // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
16021625 }
16031626
1604
- void DrawMaterial(cMaterial material, boolean selected)
1627
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
16051628 {
16061629 CameraPane display = this;
16071630 //new Exception().printStackTrace();
....@@ -1636,7 +1659,7 @@
16361659 colorV[0] = display.modelParams0[0] * material.diffuse;
16371660 colorV[1] = display.modelParams0[1] * material.diffuse;
16381661 colorV[2] = display.modelParams0[2] * material.diffuse;
1639
- colorV[3] = material.opacity;
1662
+ colorV[3] = 1; // material.opacity;
16401663
16411664 gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
16421665 //System.out.println("Opacity = " + opacity);
....@@ -1744,9 +1767,9 @@
17441767 display.modelParams7[2] = 0;
17451768 display.modelParams7[3] = 0;
17461769
1747
- display.modelParams6[0] = 100; // criss de bug de bump
1770
+ //display.modelParams6[0] = 100; // criss de bug de bump
17481771
1749
- Object3D.cVector2[] extparams = display.vector2buffer;
1772
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
17501773 if (extparams != null && extparams.length > 0 && extparams[0] != null)
17511774 {
17521775 display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
....@@ -1888,7 +1911,7 @@
18881911 void PushMatrix(double[][] matrix)
18891912 {
18901913 // GrafreeD.tracein(matrix);
1891
- PushMatrix(matrix,1);
1914
+ PushMatrix(matrix, 1);
18921915 }
18931916
18941917 void PushMatrix()
....@@ -2042,7 +2065,7 @@
20422065 //System.err.println("Oeil on");
20432066 OEIL = true;
20442067 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2045
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2068
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
20462069 //pingthread.StepToTarget(true);
20472070 }
20482071
....@@ -2257,7 +2280,7 @@
22572280
22582281 void ToggleDebug()
22592282 {
2260
- DEBUG ^= true;
2283
+ Globals.DEBUG ^= true;
22612284 }
22622285
22632286 void ToggleLookAt()
....@@ -2265,7 +2288,7 @@
22652288 LOOKAT ^= true;
22662289 }
22672290
2268
- void ToggleRandom()
2291
+ void ToggleSwitch()
22692292 {
22702293 SWITCH ^= true;
22712294 }
....@@ -2275,10 +2298,17 @@
22752298 HANDLES ^= true;
22762299 }
22772300
2301
+ Object3D paintFolder;
2302
+
22782303 void TogglePaint()
22792304 {
22802305 PAINTMODE ^= true;
22812306 paintcount = 0;
2307
+
2308
+ if (PAINTMODE)
2309
+ {
2310
+ paintFolder = GetFolder();
2311
+ }
22822312 }
22832313
22842314 void SwapCamera(int a, int b)
....@@ -2374,7 +2404,7 @@
23742404 {
23752405 return currentGL;
23762406 }
2377
-
2407
+
23782408 /**/
23792409 class CacheTexture
23802410 {
....@@ -2392,9 +2422,10 @@
23922422 /**/
23932423
23942424 // 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>();
2425
+ static public java.util.Hashtable<String, CacheTexture> textures = new java.util.Hashtable<String, CacheTexture>();
2426
+ static public java.util.Hashtable<BufferedImage, CacheTexture> bimtextures = new java.util.Hashtable<BufferedImage, CacheTexture>();
2427
+ static public java.util.HashSet<String> usedtextures = new java.util.HashSet<String>();
2428
+
23982429 int pigmentdepth = 0;
23992430 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
24002431 int bumpdepth = 0;
....@@ -2416,6 +2447,33 @@
24162447 true,
24172448 com.sun.opengl.util.texture.TextureIO.PNG);
24182449 } catch (java.io.IOException e)
2450
+ {
2451
+ throw new javax.media.opengl.GLException(e);
2452
+ }
2453
+
2454
+ if (bump)
2455
+ texturedata = ConvertBump(texturedata, false);
2456
+
2457
+ com.sun.opengl.util.texture.Texture texture =
2458
+ com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2459
+
2460
+ texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2461
+ texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
2462
+
2463
+ return texture;
2464
+ }
2465
+
2466
+ com.sun.opengl.util.texture.Texture GetBimTexture(BufferedImage name, boolean bump)
2467
+ {
2468
+ TextureData texturedata = null;
2469
+
2470
+ try
2471
+ {
2472
+ texturedata =
2473
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2474
+ name,
2475
+ true);
2476
+ } catch (Exception e)
24192477 {
24202478 throw new javax.media.opengl.GLException(e);
24212479 }
....@@ -3502,6 +3560,8 @@
35023560
35033561 System.out.println("LOADING TEXTURE : " + name);
35043562
3563
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3564
+
35053565 //
35063566 if (false) // compressbit > 0)
35073567 {
....@@ -7900,7 +7960,7 @@
79007960 String pigment = Object3D.GetPigment(tex);
79017961 String bump = Object3D.GetBump(tex);
79027962
7903
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
7963
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79047964 {
79057965 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79067966 // System.out.println("; bump = " + bump);
....@@ -7917,6 +7977,64 @@
79177977
79187978 ReleaseTexture(bump, true);
79197979 ReleaseTexture(pigment, false);
7980
+ }
7981
+
7982
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
7983
+ {
7984
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
7985
+ {
7986
+ return;
7987
+ }
7988
+
7989
+ if (tex == null)
7990
+ {
7991
+ ReleaseTexture(null, false);
7992
+ return;
7993
+ }
7994
+
7995
+ String pigment = Object3D.GetPigment(tex);
7996
+
7997
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
7998
+ {
7999
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8000
+ // System.out.println("; bump = " + bump);
8001
+ }
8002
+
8003
+ if (pigment.equals(""))
8004
+ {
8005
+ pigment = null;
8006
+ }
8007
+
8008
+ ReleaseTexture(pigment, false);
8009
+ }
8010
+
8011
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
8012
+ {
8013
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8014
+ {
8015
+ return;
8016
+ }
8017
+
8018
+ if (tex == null)
8019
+ {
8020
+ ReleaseTexture(null, true);
8021
+ return;
8022
+ }
8023
+
8024
+ String bump = Object3D.GetBump(tex);
8025
+
8026
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8027
+ {
8028
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8029
+ // System.out.println("; bump = " + bump);
8030
+ }
8031
+
8032
+ if (bump.equals(""))
8033
+ {
8034
+ bump = null;
8035
+ }
8036
+
8037
+ ReleaseTexture(bump, true);
79208038 }
79218039
79228040 void ReleaseTexture(String tex, boolean bump)
....@@ -8024,6 +8142,54 @@
80248142
80258143 /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
80268144 {
8145
+// if (// DrawMode() != 0 || /*tex == null ||*/
8146
+// ambientOcclusion ) // || !textureon)
8147
+// {
8148
+// return; // false;
8149
+// }
8150
+//
8151
+// if (tex == null)
8152
+// {
8153
+// BindTexture(null,false,resolution);
8154
+// BindTexture(null,true,resolution);
8155
+// return;
8156
+// }
8157
+//
8158
+// String pigment = Object3D.GetPigment(tex);
8159
+// String bump = Object3D.GetBump(tex);
8160
+//
8161
+// usedtextures.add(pigment);
8162
+// usedtextures.add(bump);
8163
+//
8164
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8165
+// {
8166
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8167
+// // System.out.println("; bump = " + bump);
8168
+// }
8169
+//
8170
+// if (bump.equals(""))
8171
+// {
8172
+// bump = null;
8173
+// }
8174
+// if (pigment.equals(""))
8175
+// {
8176
+// pigment = null;
8177
+// }
8178
+//
8179
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8180
+// BindTexture(pigment, false, resolution);
8181
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8182
+// BindTexture(bump, true, resolution);
8183
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8184
+//
8185
+// return; // true;
8186
+
8187
+ BindPigmentTexture(tex, resolution);
8188
+ BindBumpTexture(tex, resolution);
8189
+ }
8190
+
8191
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8192
+ {
80278193 if (// DrawMode() != 0 || /*tex == null ||*/
80288194 ambientOcclusion ) // || !textureon)
80298195 {
....@@ -8032,18 +8198,48 @@
80328198
80338199 if (tex == null)
80348200 {
8035
- BindTexture(null,false,resolution);
8036
- BindTexture(null,true,resolution);
8201
+ BindTexture(null, null,false,resolution);
80378202 return;
80388203 }
80398204
80408205 String pigment = Object3D.GetPigment(tex);
8206
+
8207
+ usedtextures.add(pigment);
8208
+
8209
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8210
+ {
8211
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8212
+ // System.out.println("; bump = " + bump);
8213
+ }
8214
+
8215
+ if (pigment.equals(""))
8216
+ {
8217
+ pigment = null;
8218
+ }
8219
+
8220
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8221
+ BindTexture(tex.pigmenttexture, pigment, false, resolution);
8222
+ }
8223
+
8224
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8225
+ {
8226
+ if (// DrawMode() != 0 || /*tex == null ||*/
8227
+ ambientOcclusion ) // || !textureon)
8228
+ {
8229
+ return; // false;
8230
+ }
8231
+
8232
+ if (tex == null)
8233
+ {
8234
+ BindTexture(null, null,true,resolution);
8235
+ return;
8236
+ }
8237
+
80418238 String bump = Object3D.GetBump(tex);
80428239
8043
- usedtextures.put(pigment, pigment);
8044
- usedtextures.put(bump, bump);
8240
+ usedtextures.add(bump);
80458241
8046
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8242
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
80478243 {
80488244 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
80498245 // System.out.println("; bump = " + bump);
....@@ -8053,46 +8249,70 @@
80538249 {
80548250 bump = null;
80558251 }
8056
- if (pigment.equals(""))
8057
- {
8058
- pigment = null;
8059
- }
80608252
8061
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8062
- BindTexture(pigment, false, resolution);
80638253 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8064
- BindTexture(bump, true, resolution);
8254
+ BindTexture(tex.bumptexture, bump, true, resolution);
80658255 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8066
-
8067
- return; // true;
80688256 }
80698257
8070
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception
8258
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8259
+
8260
+ private boolean FileExists(String tex)
80718261 {
8072
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8262
+ if (missingTextures.contains(tex))
8263
+ {
8264
+ return false;
8265
+ }
8266
+
8267
+ boolean fileExists = new File(tex).exists();
8268
+
8269
+ if (!fileExists)
8270
+ {
8271
+ // If file exists, the "new File()" is not executed sgain
8272
+ missingTextures.add(tex);
8273
+ }
8274
+
8275
+ return fileExists;
8276
+ }
8277
+
8278
+ CacheTexture GetCacheTexture(java.awt.image.BufferedImage bim, String tex, boolean bump, int resolution) throws Exception
8279
+ {
8280
+ CacheTexture texturecache = null;
80738281
80748282 if (tex != null)
80758283 {
80768284 String texname = tex;
80778285
8286
+ String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
8287
+
80788288 // String[] split = tex.split("Textures");
80798289 // if (split.length > 1)
80808290 // texname = "/Users/nbriere/Textures" + split[split.length-1];
80818291 // else
80828292 // if (!texname.startsWith("/"))
80838293 // texname = "/Users/nbriere/Textures/" + texname;
8084
- if (!new File(tex).exists())
8294
+ if (!FileExists(tex))
80858295 {
8086
- texname = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory() + "/Textures/" + texname;
8296
+ texname = fallbackTextureName;
80878297 }
80888298
80898299 if (CACHETEXTURE)
8090
- texture = textures.get(texname); // TEXTURE CACHE
8091
-
8092
- TextureData texturedata = null;
8093
-
8094
- if (texture == null || texture.resolution < resolution)
80958300 {
8301
+ if (bim == null)
8302
+ texturecache = textures.get(texname); // TEXTURE CACHE
8303
+ else
8304
+ texturecache = bimtextures.get(bim); // TEXTURE CACHE
8305
+ }
8306
+
8307
+ if (texturecache == null || texturecache.resolution < resolution)
8308
+ {
8309
+ TextureData texturedata = null;
8310
+
8311
+ if (bim == null)
8312
+ {
8313
+
8314
+ }
8315
+ else
80968316 if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
80978317 {
80988318 assert(!bump);
....@@ -8104,19 +8324,19 @@
81048324 // }
81058325 // else
81068326 // {
8107
- texture = textures.get(tex);
8108
- if (texture == null)
8327
+ texturecache = textures.get(tex);
8328
+ if (texturecache == null)
81098329 {
8110
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8330
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
81118331 }
81128332 // }
81138333 } else
81148334 if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
81158335 {
81168336 assert(bump);
8117
- texture = textures.get(tex);
8118
- if (texture == null)
8119
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8337
+ texturecache = textures.get(tex);
8338
+ if (texturecache == null)
8339
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
81208340 } else
81218341 {
81228342 //if (tex.equals("IMMORTAL"))
....@@ -8126,9 +8346,9 @@
81268346 //{
81278347 if (tex.equals("WHITE_NOISE"))
81288348 {
8129
- texture = textures.get(tex);
8130
- if (texture == null)
8131
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8349
+ texturecache = textures.get(tex);
8350
+ if (texturecache == null)
8351
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
81328352 } else
81338353 {
81348354 if (textureon)
....@@ -8153,7 +8373,7 @@
81538373 }
81548374
81558375 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
8156
- if (!new File(cachename).exists())
8376
+ if (!FileExists(cachename))
81578377 cachename = texname;
81588378 else
81598379 processbump = false; // don't process bump map again
....@@ -8175,7 +8395,7 @@
81758395 }
81768396
81778397 cachename = texname.substring(0, texname.length()-4)+ext+".png";
8178
- if (!new File(cachename).exists())
8398
+ if (!FileExists(cachename))
81798399 cachename = texname;
81808400 else
81818401 processbump = false; // don't process bump map again
....@@ -8187,19 +8407,19 @@
81878407 if (texturedata == null)
81888408 throw new Exception();
81898409
8190
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8410
+ texturecache = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
81918411 //texture = GetTexture(tex, bump);
81928412 }
81938413 }
81948414 //}
81958415 }
81968416
8197
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8417
+ if (/*CACHETEXTURE &&*/ texturecache != null && textureon)
81988418 {
81998419 //return false;
82008420
82018421 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8202
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8422
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
82038423 {
82048424 // String ext = "_highres";
82058425 // if (REDUCETEXTURE)
....@@ -8288,8 +8508,8 @@
82888508 textures.remove(texname);
82898509 }
82908510
8291
- texture.texturedata = texturedata;
8292
- textures.put(texname, texture);
8511
+ //texture.texturedata = texturedata;
8512
+ textures.put(texname, texturecache);
82938513
82948514 // newtex = true;
82958515 }
....@@ -8305,12 +8525,12 @@
83058525 }
83068526 }
83078527
8308
- return texture;
8528
+ return texturecache;
83098529 }
83108530
8311
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution) throws Exception
8531
+ com.sun.opengl.util.texture.Texture GetTexture(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception
83128532 {
8313
- CacheTexture texture = GetCacheTexture(tex, bump, resolution);
8533
+ CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution);
83148534
83158535 if (bump)
83168536 {
....@@ -8326,23 +8546,23 @@
83268546 return texture!=null?texture.texture:null;
83278547 }
83288548
8329
- public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution) throws Exception
8549
+ public com.sun.opengl.util.texture.TextureData GetTextureData(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception
83308550 {
8331
- CacheTexture texture = GetCacheTexture(tex, bump, resolution);
8551
+ CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution);
83328552
83338553 return texture!=null?texture.texturedata:null;
83348554 }
83358555
8336
- boolean BindTexture(String tex, boolean bump, int resolution) throws Exception
8556
+ boolean BindTexture(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception
83378557 {
83388558 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
83398559 {
83408560 return false;
83418561 }
83428562
8343
- boolean newtex = false;
8563
+ //boolean newtex = false;
83448564
8345
- com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
8565
+ com.sun.opengl.util.texture.Texture texture = GetTexture(stream, tex, bump, resolution);
83468566
83478567 if (texture == null)
83488568 return false;
....@@ -8372,7 +8592,7 @@
83728592 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
83738593 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
83748594
8375
- return newtex;
8595
+ return true; // Warning: not used.
83768596 }
83778597
83788598 ShadowBuffer shadowPBuf;
....@@ -9210,11 +9430,35 @@
92109430 jy8[3] = 0.5f;
92119431 }
92129432
9213
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9433
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
92149434 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
92159435 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
92169436 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
92179437
9438
+ void ResetOptions()
9439
+ {
9440
+ options1[0] = 100;
9441
+ options1[1] = 0.025f;
9442
+ options1[2] = 0.01f;
9443
+ options1[3] = 0;
9444
+ options1[4] = 0;
9445
+
9446
+ options2[0] = 0;
9447
+ options2[1] = 0.75f;
9448
+ options2[2] = 0;
9449
+ options2[3] = 0;
9450
+
9451
+ options3[0] = 1;
9452
+ options3[1] = 1;
9453
+ options3[2] = 1;
9454
+ options3[3] = 0;
9455
+
9456
+ options4[0] = 1;
9457
+ options4[1] = 0;
9458
+ options4[2] = 1;
9459
+ options4[3] = 0;
9460
+ }
9461
+
92189462 static int imagecount = 0; // movie generation
92199463
92209464 static int jitter = 0;
....@@ -9310,8 +9554,8 @@
93109554 assert (parentcam != renderCamera);
93119555
93129556 if (renderCamera != lightCamera)
9313
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9314
- LA.matConcat(matrix, parentcam.toParent, matrix);
9557
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9558
+ LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
93159559
93169560 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
93179561
....@@ -9326,8 +9570,8 @@
93269570 LA.matCopy(renderCamera.fromScreen, matrix);
93279571
93289572 if (renderCamera != lightCamera)
9329
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9330
- LA.matConcat(parentcam.fromParent, matrix, matrix);
9573
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9574
+ LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
93319575
93329576 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
93339577
....@@ -10325,6 +10569,7 @@
1032510569 ANTIALIAS = 0;
1032610570 //System.out.println("RESTART");
1032710571 AAtimer.restart();
10572
+ Globals.TIMERRUNNING = true;
1032810573 }
1032910574 }
1033010575 }
....@@ -10392,13 +10637,14 @@
1039210637 ambientOcclusion = false;
1039310638 }
1039410639
10395
- if (Globals.lighttouched && DrawMode() == DEFAULT && !lightMode) // && !FROZEN)
10640
+ if (//Globals.lighttouched &&
10641
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1039610642 {
1039710643 //if (RENDERSHADOW) // ?
1039810644 if (!IsFrozen())
1039910645 {
1040010646 // dec 2012
10401
- if (!ambientOcclusion && !(!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0))
10647
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
1040210648 {
1040310649 Globals.framecount++;
1040410650 shadowbuffer.display();
....@@ -10525,8 +10771,8 @@
1052510771
1052610772 // if (parentcam != renderCamera) // not a light
1052710773 if (cam != lightCamera)
10528
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10529
- LA.matConcat(matrix, parentcam.toParent, matrix);
10774
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10775
+ LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
1053010776
1053110777 for (int j = 0; j < 4; j++)
1053210778 {
....@@ -10540,8 +10786,8 @@
1054010786
1054110787 // if (parentcam != renderCamera) // not a light
1054210788 if (cam != lightCamera)
10543
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10544
- LA.matConcat(parentcam.fromParent, matrix, matrix);
10789
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10790
+ LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
1054510791
1054610792 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1054710793
....@@ -10803,7 +11049,7 @@
1080311049
1080411050 try
1080511051 {
10806
- BindTexture(NOISE_TEXTURE, false, 2);
11052
+ BindTexture(null, NOISE_TEXTURE, false, 2);
1080711053 }
1080811054 catch (Exception e)
1080911055 {
....@@ -10832,9 +11078,9 @@
1083211078
1083311079 gl.glMatrixMode(GL.GL_MODELVIEW);
1083411080
10835
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10836
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10837
-//gl.glEnable(gl.GL_MULTISAMPLE);
11081
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11082
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11083
+gl.glEnable(gl.GL_MULTISAMPLE);
1083811084 } else
1083911085 {
1084011086 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -10845,7 +11091,7 @@
1084511091 //System.out.println("BLENDING ON");
1084611092 gl.glEnable(GL.GL_BLEND);
1084711093 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
10848
-
11094
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1084911095 gl.glMatrixMode(gl.GL_PROJECTION);
1085011096 gl.glLoadIdentity();
1085111097
....@@ -10934,8 +11180,8 @@
1093411180 System.err.println("parentcam != renderCamera");
1093511181
1093611182 // if (cam != lightCamera)
10937
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10938
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11183
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11184
+ LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
1093911185 }
1094011186
1094111187 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -10956,8 +11202,8 @@
1095611202 if (true) // TODO
1095711203 {
1095811204 if (cam != lightCamera)
10959
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10960
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11205
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11206
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
1096111207 }
1096211208
1096311209 LA.xformPos(light0, cam.toScreen, light0);
....@@ -11302,15 +11548,36 @@
1130211548
1130311549 static boolean zoomonce = false;
1130411550
11551
+ static void CreateSelectedPoint()
11552
+ {
11553
+ if (selectedpoint == null)
11554
+ {
11555
+ debugpointG = new Sphere();
11556
+ debugpointP = new Sphere();
11557
+ debugpointC = new Sphere();
11558
+ debugpointR = new Sphere();
11559
+
11560
+ selectedpoint = new Superellipsoid();
11561
+
11562
+ for (int i=0; i<8; i++)
11563
+ {
11564
+ debugpoints[i] = new Sphere();
11565
+ }
11566
+ }
11567
+ }
11568
+
1130511569 void DrawObject(GL gl, boolean draw)
1130611570 {
11571
+ // To clear camera values
11572
+ ResetOptions();
11573
+
1130711574 //System.out.println("DRAW OBJECT " + mouseDown);
1130811575 // DrawMode() = SELECTION;
1130911576 //GL gl = getGL();
1131011577 if ((TRACK || SHADOWTRACK) || zoomonce)
1131111578 {
1131211579 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11313
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11580
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1131411581 pingthread.StepToTarget(true); // true);
1131511582 // zoomonce = false;
1131611583 }
....@@ -11382,8 +11649,9 @@
1138211649
1138311650 if (DrawMode() == DEFAULT)
1138411651 {
11385
- if (DEBUG)
11652
+ if (Globals.DEBUG)
1138611653 {
11654
+ CreateSelectedPoint();
1138711655 float radius = 0.05f;
1138811656 if (selectedpoint.radius != radius)
1138911657 {
....@@ -11446,7 +11714,7 @@
1144611714 if (tex.equals("WHITE_NOISE"))
1144711715 continue;
1144811716
11449
- if (!usedtextures.containsKey(tex))
11717
+ if (!usedtextures.contains(tex))
1145011718 {
1145111719 // System.out.println("DISPOSE +++++++++++++++ " + tex);
1145211720 textures.get(tex).texture.dispose();
....@@ -11552,7 +11820,7 @@
1155211820 return;
1155311821 }
1155411822
11555
- String string = obj.GetToolTip();
11823
+ String string = obj.toString(); //.GetToolTip();
1155611824
1155711825 GL gl = GetGL();
1155811826
....@@ -11869,8 +12137,8 @@
1186912137 //obj.TransformToWorld(light, light);
1187012138 for (int i = tp.size(); --i >= 0;)
1187112139 {
11872
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
11873
- LA.xformPos(light, tp.get(i).toParent, light);
12140
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12141
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1187412142 }
1187512143
1187612144
....@@ -11887,8 +12155,8 @@
1188712155 parentcam = cameras[0];
1188812156 }
1188912157
11890
- for (int count = parentcam.GetTransformCount(); --count>=0;)
11891
- LA.xformPos(light, parentcam.toParent, light); // may 2013
12158
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
12159
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1189212160
1189312161 LA.xformPos(light, renderCamera.toScreen, light);
1189412162
....@@ -12502,8 +12770,8 @@
1250212770
1250312771 // display shadow only (bump == 0)
1250412772 "SUB temp.x, half.x, shadow.x;" +
12505
- "MOV temp.y, -params6.x;" +
12506
- "SLT temp.z, temp.y, zero.x;" +
12773
+ "MOV temp.y, -params5.z;" + // params6.x;" +
12774
+ "SLT temp.z, temp.y, -one2048th.x;" +
1250712775 "SUB temp.y, one.x, temp.z;" +
1250812776 "MUL temp.x, temp.x, temp.y;" +
1250912777 "KIL temp.x;" +
....@@ -12834,7 +13102,7 @@
1283413102 //once = true;
1283513103 }
1283613104
12837
- System.out.print("Program #" + mode + "; length = " + program.length());
13105
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1283813106 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1283913107 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1284013108
....@@ -12967,12 +13235,16 @@
1296713235
1296813236 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1296913237 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13238
+
13239
+ // Compare fragment depth in light space with shadowmap.
1297013240 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1297113241 "SGE temp.y, temp.x, zero.x;" +
12972
- "SUB " + shadow + ".y, one.x, temp.y;" +
13242
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13243
+
13244
+ // Reverse comparison
1297313245 "SUB temp.x, one.x, temp.x;" +
1297413246 "MUL " + shadow + ".x, temp.x, temp.y;" +
12975
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13247
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1297613248 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1297713249
1297813250 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -12986,6 +13258,10 @@
1298613258 // No shadow for backface
1298713259 "DP3 temp.x, normal, lightd;" +
1298813260 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13261
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13262
+
13263
+ // No shadow when out of frustrum
13264
+ "SGE temp.x, " + depth + ".z, one.z;" +
1298913265 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1299013266 "";
1299113267 }
....@@ -13132,7 +13408,8 @@
1313213408 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1313313409 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1313413410 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13135
- Object3D.cVector2[] vector2buffer;
13411
+
13412
+ //Object3D.cVector2[] vector2buffer;
1313613413
1313713414 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1313813415 // OUT : diff, spec
....@@ -13148,9 +13425,10 @@
1314813425 "DP3 " + dest + ".z," + "normals," + "eye;" +
1314913426 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1315013427 //"MOV " + dest + ".w," + "normal.z;" +
13151
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
13152
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13153
- //"MOV " + dest + ".z," + "params2.w;" +
13428
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13429
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13430
+
13431
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1315413432 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1315513433 "RCP " + dest + ".w," + dest + ".w;" +
1315613434 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13655,6 +13933,7 @@
1365513933 else
1365613934 if (evt.getSource() == AAtimer)
1365713935 {
13936
+ Globals.TIMERRUNNING = false;
1365813937 if (mouseDown)
1365913938 {
1366013939 //new Exception().printStackTrace();
....@@ -13714,7 +13993,7 @@
1371413993
1371513994 // fev 2014???
1371613995 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13717
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
13996
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1371813997 pingthread.StepToTarget(true); // true);
1371913998 }
1372013999 // if (!LIVE)
....@@ -13729,6 +14008,7 @@
1372914008 return;
1373014009
1373114010 AAtimer.restart(); //
14011
+ Globals.TIMERRUNNING = true;
1373214012
1373314013 // waslive = LIVE;
1373414014 // LIVE = false;
....@@ -13801,9 +14081,12 @@
1380114081
1380214082 public void mouseDragged(MouseEvent e)
1380314083 {
14084
+ Globals.MOUSEDRAGGED = true;
14085
+
1380414086 //System.out.println("mouseDragged: " + e);
1380514087 if (isRenderer)
1380614088 movingcamera = true;
14089
+
1380714090 //if (drawing)
1380814091 //return;
1380914092 if ((e.getModifiersEx() & CTRL) != 0
....@@ -14064,12 +14347,12 @@
1406414347 void GoDown(int mod)
1406514348 {
1406614349 MODIFIERS |= COMMAND;
14067
- /*
14350
+ /**/
1406814351 if((mod&SHIFT) == SHIFT)
1406914352 manipCamera.RotatePosition(0, -speed);
1407014353 else
14071
- manipCamera.BackForth(0, -speed*delta, getWidth());
14072
- */
14354
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14355
+ /**/
1407314356 if ((mod & SHIFT) == SHIFT)
1407414357 {
1407514358 mouseMode = mouseMode; // VR??
....@@ -14085,12 +14368,12 @@
1408514368 void GoUp(int mod)
1408614369 {
1408714370 MODIFIERS |= COMMAND;
14088
- /*
14371
+ /**/
1408914372 if((mod&SHIFT) == SHIFT)
1409014373 manipCamera.RotatePosition(0, speed);
1409114374 else
14092
- manipCamera.BackForth(0, speed*delta, getWidth());
14093
- */
14375
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14376
+ /**/
1409414377 if ((mod & SHIFT) == SHIFT)
1409514378 {
1409614379 mouseMode = mouseMode;
....@@ -14106,12 +14389,12 @@
1410614389 void GoLeft(int mod)
1410714390 {
1410814391 MODIFIERS |= COMMAND;
14109
- /*
14392
+ /**/
1411014393 if((mod&SHIFT) == SHIFT)
14111
- manipCamera.RotatePosition(speed, 0);
14112
- else
1411314394 manipCamera.Translate(speed*delta, 0, getWidth());
14114
- */
14395
+ else
14396
+ manipCamera.RotatePosition(speed, 0);
14397
+ /**/
1411514398 if ((mod & SHIFT) == SHIFT)
1411614399 {
1411714400 mouseMode = mouseMode;
....@@ -14127,12 +14410,12 @@
1412714410 void GoRight(int mod)
1412814411 {
1412914412 MODIFIERS |= COMMAND;
14130
- /*
14413
+ /**/
1413114414 if((mod&SHIFT) == SHIFT)
14132
- manipCamera.RotatePosition(-speed, 0);
14133
- else
1413414415 manipCamera.Translate(-speed*delta, 0, getWidth());
14135
- */
14416
+ else
14417
+ manipCamera.RotatePosition(-speed, 0);
14418
+ /**/
1413614419 if ((mod & SHIFT) == SHIFT)
1413714420 {
1413814421 mouseMode = mouseMode;
....@@ -14189,7 +14472,8 @@
1418914472 info.camera = renderCamera;
1419014473 info.x = x;
1419114474 info.y = y;
14192
- object.editWindow.copy.doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
14475
+ object.GetWindow().copy
14476
+ .doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1419314477 } else
1419414478 {
1419514479 if (x < startX)
....@@ -14353,7 +14637,9 @@
1435314637 ci.camera = renderCamera;
1435414638 if (!isRenderer)
1435514639 {
14356
- if (object.editWindow.copy.doEditClick(ci, 0))
14640
+ //ObjEditor editWindow = object.editWindow;
14641
+ //Object3D copy = editWindow.copy;
14642
+ if (object.doEditClick(ci, 0))
1435714643 {
1435814644 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1435914645 } else
....@@ -14365,7 +14651,11 @@
1436514651
1436614652 public void mouseReleased(MouseEvent e)
1436714653 {
14654
+ Globals.MOUSEDRAGGED = false;
14655
+
1436814656 movingcamera = false;
14657
+ X = 0; // getBounds().width/2;
14658
+ Y = 0; // getBounds().height/2;
1436914659 //System.out.println("mouseReleased: " + e);
1437014660 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1437114661 }
....@@ -14706,7 +14996,9 @@
1470614996 case 'E' : COMPACT ^= true;
1470714997 repaint();
1470814998 break;
14709
- case 'W' : DEBUGHSB ^= true;
14999
+ case 'W' : // Wide Window (fullscreen)
15000
+ //DEBUGHSB ^= true;
15001
+ ObjEditor.theFrame.ToggleFullScreen();
1471015002 repaint();
1471115003 break;
1471215004 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14731,8 +15023,8 @@
1473115023 RevertCamera();
1473215024 repaint();
1473315025 break;
14734
- case 'L':
1473515026 case 'l':
15027
+ //case 'L':
1473615028 if (lightMode)
1473715029 {
1473815030 lightMode = false;
....@@ -14875,9 +15167,9 @@
1487515167 case '_':
1487615168 kompactbit = 5;
1487715169 break;
14878
- case '+':
14879
- kompactbit = 6;
14880
- break;
15170
+// case '+':
15171
+// kompactbit = 6;
15172
+// break;
1488115173 case ' ':
1488215174 lightMode ^= true;
1488315175 Globals.lighttouched = true;
....@@ -14889,6 +15181,7 @@
1488915181 case ESC:
1489015182 RENDERPROGRAM += 1;
1489115183 RENDERPROGRAM %= 3;
15184
+
1489215185 repaint();
1489315186 break;
1489415187 case 'Z':
....@@ -14928,8 +15221,9 @@
1492815221 case DELETE:
1492915222 ClearSelection();
1493015223 break;
14931
- /*
1493215224 case '+':
15225
+
15226
+ /*
1493315227 //fontsize += 1;
1493415228 bbzoom *= 2;
1493515229 repaint();
....@@ -14946,17 +15240,17 @@
1494615240 case '=':
1494715241 IncDepth();
1494815242 //fontsize += 1;
14949
- object.editWindow.refreshContents(true);
15243
+ object.GetWindow().refreshContents(true);
1495015244 maskbit = 6;
1495115245 break;
1495215246 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1495315247 DecDepth();
1495415248 maskbit = 5;
1495515249 //if(fontsize > 1) fontsize -= 1;
14956
- if (object.editWindow == null)
14957
- new Exception().printStackTrace();
14958
- else
14959
- object.editWindow.refreshContents(true);
15250
+// if (object.editWindow == null)
15251
+// new Exception().printStackTrace();
15252
+// else
15253
+ object.GetWindow().refreshContents(true);
1496015254 break;
1496115255 case '{':
1496215256 manipCamera.shaper_fovy /= 1.1;
....@@ -15180,7 +15474,7 @@
1518015474 }
1518115475 */
1518215476
15183
- object.editWindow.EditSelection();
15477
+ object.GetWindow().EditSelection(false);
1518415478 }
1518515479
1518615480 void SelectParent()
....@@ -15197,10 +15491,10 @@
1519715491 {
1519815492 //selectees.remove(i);
1519915493 System.out.println("select parent of " + elem);
15200
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15494
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1520115495 } else
1520215496 {
15203
- group.editWindow.Select(elem.GetTreePath(), first, true);
15497
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1520415498 }
1520515499
1520615500 first = false;
....@@ -15242,12 +15536,12 @@
1524215536 for (int j = 0; j < group.children.size(); j++)
1524315537 {
1524415538 elem = (Object3D) group.children.elementAt(j);
15245
- object.editWindow.Select(elem.GetTreePath(), first, true);
15539
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1524615540 first = false;
1524715541 }
1524815542 } else
1524915543 {
15250
- object.editWindow.Select(elem.GetTreePath(), first, true);
15544
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1525115545 }
1525215546
1525315547 first = false;
....@@ -15258,21 +15552,21 @@
1525815552 {
1525915553 //Composite group = (Composite) object;
1526015554 Object3D group = object;
15261
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15555
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1526215556 }
1526315557
1526415558 void ResetTransform(int mask)
1526515559 {
1526615560 //Composite group = (Composite) object;
1526715561 Object3D group = object;
15268
- group.editWindow.ResetTransform(mask);
15562
+ group.GetWindow().ResetTransform(mask);
1526915563 }
1527015564
1527115565 void FlipTransform()
1527215566 {
1527315567 //Composite group = (Composite) object;
1527415568 Object3D group = object;
15275
- group.editWindow.FlipTransform();
15569
+ group.GetWindow().FlipTransform();
1527615570 // group.editWindow.ReduceMesh(true);
1527715571 }
1527815572
....@@ -15280,7 +15574,7 @@
1528015574 {
1528115575 //Composite group = (Composite) object;
1528215576 Object3D group = object;
15283
- group.editWindow.PrintMemory();
15577
+ group.GetWindow().PrintMemory();
1528415578 // group.editWindow.ReduceMesh(true);
1528515579 }
1528615580
....@@ -15288,7 +15582,7 @@
1528815582 {
1528915583 //Composite group = (Composite) object;
1529015584 Object3D group = object;
15291
- group.editWindow.ResetCentroid();
15585
+ group.GetWindow().ResetCentroid();
1529215586 }
1529315587
1529415588 void IncDepth()
....@@ -15374,7 +15668,9 @@
1537415668 info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1537515669 //Image img = CreateImage(width, height);
1537615670 //System.out.println("width = " + width + "; height = " + height + "\n");
15671
+
1537715672 Graphics gr = g; // img.getGraphics();
15673
+
1537815674 if (!hasMarquee)
1537915675 {
1538015676 if (Xmin < Xmax) // !locked)
....@@ -15462,6 +15758,7 @@
1546215758 info.bounds.y += (height - desired) / 2;
1546315759 }
1546415760 }
15761
+
1546515762 info.g = gr;
1546615763 info.camera = renderCamera;
1546715764 /*
....@@ -15471,15 +15768,55 @@
1547115768 */
1547215769 if (!isRenderer)
1547315770 {
15474
- object.drawEditHandles(info, 0);
15771
+ Grafreed.Assert(object != null);
15772
+ Grafreed.Assert(object.selection != null);
15773
+ if (object.selection.Size() > 0)
15774
+ {
15775
+ int hitSomething = object.selection.get(0).hitSomething;
15776
+
15777
+ info.DX = 0;
15778
+ info.DY = 0;
15779
+ info.W = 1;
15780
+ if (hitSomething == Object3D.hitCenter)
15781
+ {
15782
+ info.DX = X;
15783
+ if (X != 0)
15784
+ info.DX -= info.bounds.width/2;
15785
+
15786
+ info.DY = Y;
15787
+ if (Y != 0)
15788
+ info.DY -= info.bounds.height/2;
15789
+ }
15790
+
15791
+ object.drawEditHandles(info, 0);
15792
+
15793
+ if (drag && (X != 0 || Y != 0))
15794
+ {
15795
+ switch (hitSomething)
15796
+ {
15797
+ case Object3D.hitCenter: gr.setColor(Color.pink);
15798
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15799
+ break;
15800
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
15801
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15802
+ break;
15803
+ case Object3D.hitScale: gr.setColor(Color.cyan);
15804
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15805
+ break;
15806
+ }
15807
+
15808
+ }
15809
+ }
1547515810 }
1547615811 }
15812
+
1547715813 if (isRenderer)
1547815814 {
1547915815 //gr.setColor(Color.black);
1548015816 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1548115817 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1548215818 }
15819
+
1548315820 if (hasMarquee)
1548415821 {
1548515822 gr.setXORMode(Color.white);
....@@ -15886,7 +16223,7 @@
1588616223 Object3D object;
1588716224 static Object3D trackedobject;
1588816225 Camera renderCamera; // Light or Eye (or Occlusion)
15889
- /*static*/ Camera manipCamera; // Light or Eye
16226
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1589016227 /*static*/ Camera eyeCamera;
1589116228 /*static*/ Camera lightCamera;
1589216229 int cameracount;
....@@ -16171,16 +16508,16 @@
1617116508 cStatic.objectstack[materialdepth++] = checker;
1617216509 //System.out.println("material " + material);
1617316510 //Applet3D.tracein(this, selected);
16174
- vector2buffer = checker.projectedVertices;
16511
+ //vector2buffer = checker.projectedVertices;
1617516512
1617616513 //checker.GetMaterial().Draw(this, false); // true);
16177
- DrawMaterial(checker.GetMaterial(), false); // true);
16514
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1617816515
1617916516 materialdepth -= 1;
1618016517 if (materialdepth > 0)
1618116518 {
16182
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16183
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
16519
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16520
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1618416521 }
1618516522 //checker.GetMaterial().opacity = 1f;
1618616523 ////checker.GetMaterial().ambient = 1f;
....@@ -16266,6 +16603,14 @@
1626616603 }
1626716604 }
1626816605
16606
+ private Object3D GetFolder()
16607
+ {
16608
+ Object3D folder = object.GetWindow().copy;
16609
+ if (object.GetWindow().copy.selection.Size() > 0)
16610
+ folder = object.GetWindow().copy.selection.elementAt(0);
16611
+ return folder;
16612
+ }
16613
+
1626916614 class SelectBuffer implements GLEventListener
1627016615 {
1627116616
....@@ -16345,6 +16690,17 @@
1634516690
1634616691 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1634716692
16693
+ if (PAINTMODE)
16694
+ {
16695
+ if (object.GetWindow().copy.selection.Size() > 0)
16696
+ {
16697
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16698
+
16699
+ // Make what you paint not selectable.
16700
+ paintobj.ResetSelectable();
16701
+ }
16702
+ }
16703
+
1634816704 //int tmp = selection_view;
1634916705 //selection_view = -1;
1635016706 int temp = DrawMode();
....@@ -16356,6 +16712,17 @@
1635616712 // temp = DEFAULT; // patch for selection debug
1635716713 Globals.drawMode = temp; // WARNING
1635816714
16715
+ if (PAINTMODE)
16716
+ {
16717
+ if (object.GetWindow().copy.selection.Size() > 0)
16718
+ {
16719
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16720
+
16721
+ // Revert.
16722
+ paintobj.RestoreSelectable();
16723
+ }
16724
+ }
16725
+
1635916726 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1636016727
1636116728 // trying different ways of getting the depth info over
....@@ -16403,6 +16770,8 @@
1640316770 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1640416771 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1640516772 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
16773
+
16774
+ CreateSelectedPoint();
1640616775
1640716776 // Will fit the mesh !!!
1640816777 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16457,29 +16826,31 @@
1645716826 }
1645816827
1645916828 if (!movingcamera && !PAINTMODE)
16460
- object.editWindow.ScreenFitPoint(); // fev 2014
16829
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1646116830
16462
- if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
16831
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1646316832 {
16464
- Object3D paintobj = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
16833
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1646516834
16466
- Object3D group = new Object3D("inst" + paintcount++);
16835
+ if (object.GetWindow().copy.selection.Size() > 0)
16836
+ {
16837
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1646716838
16468
- group.CreateMaterial(); // use a void leaf to select instances
16469
-
16470
- group.add(paintobj); // link
16471
-
16472
- object.editWindow.SnapObject(group);
16473
-
16474
- Object3D folder = object.editWindow.copy;
16475
-
16476
- if (object.editWindow.copy.selection.Size() > 0)
16477
- folder = object.editWindow.copy.selection.elementAt(0);
16478
-
16479
- folder.add(group);
16480
-
16481
- object.editWindow.ResetModel();
16482
- object.editWindow.refreshContents();
16839
+ Object3D inst = new Object3D("inst" + paintcount++);
16840
+
16841
+ inst.CreateMaterial(); // use a void leaf to select instances
16842
+
16843
+ inst.add(paintobj); // link
16844
+
16845
+ object.GetWindow().SnapObject(inst);
16846
+
16847
+ Object3D folder = paintFolder; // GetFolder();
16848
+
16849
+ folder.add(inst);
16850
+
16851
+ object.GetWindow().ResetModel();
16852
+ object.GetWindow().refreshContents();
16853
+ }
1648316854 }
1648416855 else
1648516856 paintcount = 0;
....@@ -16518,6 +16889,11 @@
1651816889 //System.out.println("objects[color] = " + objects[color]);
1651916890 //objects[color].Select();
1652016891 indexcount = 0;
16892
+ ObjEditor window = object.GetWindow();
16893
+ if (window != null && deselect)
16894
+ {
16895
+ window.Select(null, deselect, true);
16896
+ }
1652116897 object.Select(color, deselect);
1652216898 }
1652316899
....@@ -17043,23 +17419,15 @@
1704317419 int AAbuffersize = 0;
1704417420
1704517421 //double[] selectedpoint = new double[3];
17046
- static Superellipsoid selectedpoint = new Superellipsoid();
17422
+ static Superellipsoid selectedpoint;
1704717423 static Sphere previousselectedpoint = null;
17048
- static Sphere debugpointG = new Sphere();
17049
- static Sphere debugpointP = new Sphere();
17050
- static Sphere debugpointC = new Sphere();
17051
- static Sphere debugpointR = new Sphere();
17424
+ static Sphere debugpointG;
17425
+ static Sphere debugpointP;
17426
+ static Sphere debugpointC;
17427
+ static Sphere debugpointR;
1705217428
1705317429 static Sphere debugpoints[] = new Sphere[8];
1705417430
17055
- static
17056
- {
17057
- for (int i=0; i<8; i++)
17058
- {
17059
- debugpoints[i] = new Sphere();
17060
- }
17061
- }
17062
-
1706317431 static void InitPoints(float radius)
1706417432 {
1706517433 for (int i=0; i<8; i++)