Normand Briere
2019-08-12 8f1afe25ea8fc8801aab66331c32a50859a758c2
CameraPane.java
....@@ -18,7 +18,10 @@
1818 import javax.imageio.ImageIO;
1919 import javax.imageio.ImageWriteParam;
2020 import javax.imageio.ImageWriter;
21
+import javax.imageio.ImageReadParam;
22
+import javax.imageio.ImageReader;
2123 import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
24
+import javax.imageio.stream.ImageInputStream;
2225 import javax.imageio.stream.ImageOutputStream;
2326 import javax.imageio.ImageWriteParam;
2427
....@@ -30,6 +33,7 @@
3033 import java.nio.*;
3134
3235 import gleem.linalg.Mat4f;
36
+import javax.imageio.ImageTypeSpecifier;
3337
3438 class CameraPane extends GLCanvas implements iCameraPane, Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener
3539 {
....@@ -37,7 +41,6 @@
3741 static boolean[] selectedstack = new boolean[65536];
3842 static int materialdepth = 0;
3943
40
- static boolean DEBUG = false;
4144 static boolean FRUSTUM = false; // still bogus true; // frustum culling
4245
4346 // camera change fix
....@@ -45,6 +48,39 @@
4548 static boolean ABORTED = false;
4649
4750 static int STEP = 1;
51
+
52
+ private static BufferedImage CreateBim(byte[] bytes, int width, int height)
53
+ {
54
+ int[] pixels = new int[bytes.length/3];
55
+ for (int i=pixels.length; --i>=0;)
56
+ {
57
+ int i3 = i*3;
58
+ pixels[i] = 0xFF;
59
+ pixels[i] <<= 8;
60
+ pixels[i] |= bytes[i3+2] & 0xFF;
61
+ pixels[i] <<= 8;
62
+ pixels[i] |= bytes[i3+1] & 0xFF;
63
+ pixels[i] <<= 8;
64
+ pixels[i] |= bytes[i3] & 0xFF;
65
+ }
66
+ /*
67
+ int r=0,g=0,b=0,a=0;
68
+ for (int i=0; i<width; i++)
69
+ for (int j=0; j<height; j++)
70
+ {
71
+ int index = j*width+i;
72
+ int p = pixels[index];
73
+ a = ((p>>24) & 0xFF);
74
+ r = ((p>>16) & 0xFF);
75
+ g = ((p>>8) & 0xFF);
76
+ b = (p & 0xFF);
77
+ pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
78
+ }
79
+ /**/
80
+ BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
81
+ rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
82
+ return rendImage;
83
+ }
4884
4985 /*static*/ private boolean CULLFACE = false; // true;
5086 /*static*/ boolean NEAREST = false; // true;
....@@ -61,7 +97,7 @@
6197 //boolean REDUCETEXTURE = true;
6298 boolean CACHETEXTURE = true;
6399 boolean CLEANCACHE = false; // true;
64
- boolean MIPMAP = false; // true;
100
+ boolean MIPMAP = false; // true; // never works...
65101 boolean COMPRESSTEXTURE = false;
66102 boolean KOMPACTTEXTURE = false; // true;
67103 boolean RESIZETEXTURE = false;
....@@ -151,6 +187,18 @@
151187 }
152188
153189 private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
190
+
191
+ public void LoadSkybox(String name, String ext, boolean mipmap) throws GLException
192
+ {
193
+ try
194
+ {
195
+ cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
196
+ } catch (IOException e)
197
+ {
198
+ System.out.println("NAME = " + name);
199
+ e.printStackTrace(); // throw new RuntimeException(e);
200
+ }
201
+ }
154202
155203 void SetAsGLRenderer(boolean b)
156204 {
....@@ -170,7 +218,8 @@
170218
171219 SetCamera(cam);
172220
173
- SetLight(new Camera(new cVector(10, 10, -20)));
221
+ // Warning: not used.
222
+ SetLight(new Camera(new cVector(15, 10, -20)));
174223
175224 object = o;
176225
....@@ -327,7 +376,7 @@
327376 cStatic.objectstack[materialdepth++] = obj;
328377 //System.out.println("material " + material);
329378 //Applet3D.tracein(this, selected);
330
- display.vector2buffer = obj.projectedVertices;
379
+ //display.vector2buffer = obj.projectedVertices;
331380 if (obj instanceof Camera)
332381 {
333382 display.options1[0] = material.shift;
....@@ -336,14 +385,28 @@
336385 display.options1[2] = material.shadowbias;
337386 display.options1[3] = material.aniso;
338387 display.options1[4] = material.anisoV;
388
+// System.out.println("display.options1[0] " + display.options1[0]);
389
+// System.out.println("display.options1[1] " + display.options1[1]);
390
+// System.out.println("display.options1[2] " + display.options1[2]);
391
+// System.out.println("display.options1[3] " + display.options1[3]);
392
+// System.out.println("display.options1[4] " + display.options1[4]);
339393 display.options2[0] = material.opacity;
340394 display.options2[1] = material.diffuse;
341395 display.options2[2] = material.factor;
396
+// System.out.println("display.options2[0] " + display.options2[0]);
397
+// System.out.println("display.options2[1] " + display.options2[1]);
398
+// System.out.println("display.options2[2] " + display.options2[2]);
342399
343400 cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
401
+// System.out.println("display.options3[0] " + display.options3[0]);
402
+// System.out.println("display.options3[1] " + display.options3[1]);
403
+// System.out.println("display.options3[2] " + display.options3[2]);
344404 display.options4[0] = material.cameralight/0.2f;
345405 display.options4[1] = material.subsurface;
346406 display.options4[2] = material.sheen;
407
+// System.out.println("display.options4[0] " + display.options4[0]);
408
+// System.out.println("display.options4[1] " + display.options4[1]);
409
+// System.out.println("display.options4[2] " + display.options4[2]);
347410
348411 // if (display.CURRENTANTIALIAS > 0)
349412 // display.options3[3] /= 4;
....@@ -359,7 +422,7 @@
359422 /**/
360423 } else
361424 {
362
- DrawMaterial(material, selected);
425
+ DrawMaterial(material, selected, obj.projectedVertices);
363426 }
364427 } else
365428 {
....@@ -383,8 +446,8 @@
383446 cStatic.objectstack[materialdepth++] = obj;
384447 //System.out.println("material " + material);
385448 //Applet3D.tracein("selected ", selected);
386
- display.vector2buffer = obj.projectedVertices;
387
- display.DrawMaterial(material, selected);
449
+ //display.vector2buffer = obj.projectedVertices;
450
+ display.DrawMaterial(material, selected, obj.projectedVertices);
388451 }
389452 }
390453
....@@ -401,8 +464,8 @@
401464 materialdepth -= 1;
402465 if (materialdepth > 0)
403466 {
404
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
405
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
467
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
468
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
406469 }
407470 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
408471 } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
....@@ -422,8 +485,8 @@
422485 materialdepth -= 1;
423486 if (materialdepth > 0)
424487 {
425
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
426
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
488
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
489
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
427490 }
428491 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
429492 //else
....@@ -1434,6 +1497,8 @@
14341497 gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
14351498 }
14361499
1500
+ float[] colorV = new float[4];
1501
+
14371502 void SetColor(Object3D obj, Vertex p0)
14381503 {
14391504 CameraPane display = this;
....@@ -1501,8 +1566,6 @@
15011566 {
15021567 return;
15031568 }
1504
-
1505
- float[] colorV = new float[3];
15061569
15071570 if (false) // marked)
15081571 {
....@@ -1611,7 +1674,7 @@
16111674 // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
16121675 }
16131676
1614
- void DrawMaterial(cMaterial material, boolean selected)
1677
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
16151678 {
16161679 CameraPane display = this;
16171680 //new Exception().printStackTrace();
....@@ -1646,7 +1709,7 @@
16461709 colorV[0] = display.modelParams0[0] * material.diffuse;
16471710 colorV[1] = display.modelParams0[1] * material.diffuse;
16481711 colorV[2] = display.modelParams0[2] * material.diffuse;
1649
- colorV[3] = material.opacity;
1712
+ colorV[3] = 1; // material.opacity;
16501713
16511714 gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
16521715 //System.out.println("Opacity = " + opacity);
....@@ -1754,9 +1817,9 @@
17541817 display.modelParams7[2] = 0;
17551818 display.modelParams7[3] = 0;
17561819
1757
- display.modelParams6[0] = 100; // criss de bug de bump
1820
+ //display.modelParams6[0] = 100; // criss de bug de bump
17581821
1759
- Object3D.cVector2[] extparams = display.vector2buffer;
1822
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
17601823 if (extparams != null && extparams.length > 0 && extparams[0] != null)
17611824 {
17621825 display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
....@@ -2052,7 +2115,7 @@
20522115 //System.err.println("Oeil on");
20532116 OEIL = true;
20542117 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2055
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2118
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
20562119 //pingthread.StepToTarget(true);
20572120 }
20582121
....@@ -2267,7 +2330,7 @@
22672330
22682331 void ToggleDebug()
22692332 {
2270
- DEBUG ^= true;
2333
+ Globals.DEBUG ^= true;
22712334 }
22722335
22732336 void ToggleLookAt()
....@@ -2285,10 +2348,17 @@
22852348 HANDLES ^= true;
22862349 }
22872350
2351
+ Object3D paintFolder;
2352
+
22882353 void TogglePaint()
22892354 {
22902355 PAINTMODE ^= true;
22912356 paintcount = 0;
2357
+
2358
+ if (PAINTMODE)
2359
+ {
2360
+ paintFolder = GetFolder();
2361
+ }
22922362 }
22932363
22942364 void SwapCamera(int a, int b)
....@@ -2385,6 +2455,21 @@
23852455 return currentGL;
23862456 }
23872457
2458
+ static private BufferedImage CreateBim(TextureData texturedata)
2459
+ {
2460
+ Grafreed.Assert(texturedata != null);
2461
+
2462
+ int width = texturedata.getWidth();
2463
+ int height = texturedata.getHeight();
2464
+
2465
+ Buffer buffer = texturedata.getBuffer();
2466
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2467
+
2468
+ byte[] bytes = bytebuf.array();
2469
+
2470
+ return CreateBim(bytes, width, height);
2471
+ }
2472
+
23882473 /**/
23892474 class CacheTexture
23902475 {
....@@ -2393,28 +2478,31 @@
23932478
23942479 int resolution;
23952480
2396
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2481
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
23972482 {
2398
- texture = tex;
2483
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2484
+ texturedata = texdata;
23992485 resolution = res;
24002486 }
24012487 }
24022488 /**/
24032489
24042490 // TEXTURE static Texture texture;
2405
- static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures
2406
- = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>();
2407
- static public java.util.Hashtable<String, String> usedtextures = new java.util.Hashtable<String, String>();
2491
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2492
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2493
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2494
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2495
+
24082496 int pigmentdepth = 0;
24092497 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
24102498 int bumpdepth = 0;
24112499 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
24122500 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
24132501 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2414
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2502
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
24152503 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
24162504
2417
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2505
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
24182506 {
24192507 TextureData texturedata = null;
24202508
....@@ -2433,13 +2521,34 @@
24332521 if (bump)
24342522 texturedata = ConvertBump(texturedata, false);
24352523
2436
- com.sun.opengl.util.texture.Texture texture =
2437
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2524
+// com.sun.opengl.util.texture.Texture texture =
2525
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
24382526
2439
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2440
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
2527
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2528
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
24412529
2442
- return texture;
2530
+ return texturedata;
2531
+ }
2532
+
2533
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2534
+ {
2535
+ TextureData texturedata = null;
2536
+
2537
+ try
2538
+ {
2539
+ texturedata =
2540
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2541
+ bim,
2542
+ true);
2543
+ } catch (Exception e)
2544
+ {
2545
+ throw new javax.media.opengl.GLException(e);
2546
+ }
2547
+
2548
+ if (bump)
2549
+ texturedata = ConvertBump(texturedata, false);
2550
+
2551
+ return texturedata;
24432552 }
24442553
24452554 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3512,6 +3621,8 @@
35123621
35133622 System.out.println("LOADING TEXTURE : " + name);
35143623
3624
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3625
+
35153626 //
35163627 if (false) // compressbit > 0)
35173628 {
....@@ -7910,7 +8021,7 @@
79108021 String pigment = Object3D.GetPigment(tex);
79118022 String bump = Object3D.GetBump(tex);
79128023
7913
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8024
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79148025 {
79158026 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79168027 // System.out.println("; bump = " + bump);
....@@ -7925,8 +8036,8 @@
79258036 pigment = null;
79268037 }
79278038
7928
- ReleaseTexture(bump, true);
7929
- ReleaseTexture(pigment, false);
8039
+ ReleaseTexture(tex, true);
8040
+ ReleaseTexture(tex, false);
79308041 }
79318042
79328043 public void ReleasePigmentTexture(cTexture tex) // INTERFACE
....@@ -7944,7 +8055,7 @@
79448055
79458056 String pigment = Object3D.GetPigment(tex);
79468057
7947
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8058
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79488059 {
79498060 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79508061 // System.out.println("; bump = " + bump);
....@@ -7955,7 +8066,7 @@
79558066 pigment = null;
79568067 }
79578068
7958
- ReleaseTexture(pigment, false);
8069
+ ReleaseTexture(tex, false);
79598070 }
79608071
79618072 public void ReleaseBumpTexture(cTexture tex) // INTERFACE
....@@ -7973,7 +8084,7 @@
79738084
79748085 String bump = Object3D.GetBump(tex);
79758086
7976
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8087
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79778088 {
79788089 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79798090 // System.out.println("; bump = " + bump);
....@@ -7984,10 +8095,10 @@
79848095 bump = null;
79858096 }
79868097
7987
- ReleaseTexture(bump, true);
8098
+ ReleaseTexture(tex, true);
79888099 }
79898100
7990
- void ReleaseTexture(String tex, boolean bump)
8101
+ void ReleaseTexture(cTexture tex, boolean bump)
79918102 {
79928103 if (// DrawMode() != 0 || /*tex == null ||*/
79938104 ambientOcclusion ) // || !textureon)
....@@ -7998,7 +8109,7 @@
79988109 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
79998110
80008111 if (tex != null)
8001
- texture = textures.get(tex);
8112
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
80028113
80038114 // //assert( texture != null );
80048115 // if (texture == null)
....@@ -8092,47 +8203,50 @@
80928203
80938204 /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
80948205 {
8095
- if (// DrawMode() != 0 || /*tex == null ||*/
8096
- ambientOcclusion ) // || !textureon)
8097
- {
8098
- return; // false;
8099
- }
8100
-
8101
- if (tex == null)
8102
- {
8103
- BindTexture(null,false,resolution);
8104
- BindTexture(null,true,resolution);
8105
- return;
8106
- }
8206
+// if (// DrawMode() != 0 || /*tex == null ||*/
8207
+// ambientOcclusion ) // || !textureon)
8208
+// {
8209
+// return; // false;
8210
+// }
8211
+//
8212
+// if (tex == null)
8213
+// {
8214
+// BindTexture(null,false,resolution);
8215
+// BindTexture(null,true,resolution);
8216
+// return;
8217
+// }
8218
+//
8219
+// String pigment = Object3D.GetPigment(tex);
8220
+// String bump = Object3D.GetBump(tex);
8221
+//
8222
+// usedtextures.add(pigment);
8223
+// usedtextures.add(bump);
8224
+//
8225
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8226
+// {
8227
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8228
+// // System.out.println("; bump = " + bump);
8229
+// }
8230
+//
8231
+// if (bump.equals(""))
8232
+// {
8233
+// bump = null;
8234
+// }
8235
+// if (pigment.equals(""))
8236
+// {
8237
+// pigment = null;
8238
+// }
8239
+//
8240
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8241
+// BindTexture(pigment, false, resolution);
8242
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8243
+// BindTexture(bump, true, resolution);
8244
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8245
+//
8246
+// return; // true;
81078247
8108
- String pigment = Object3D.GetPigment(tex);
8109
- String bump = Object3D.GetBump(tex);
8110
-
8111
- usedtextures.put(pigment, pigment);
8112
- usedtextures.put(bump, bump);
8113
-
8114
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8115
- {
8116
- // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8117
- // System.out.println("; bump = " + bump);
8118
- }
8119
-
8120
- if (bump.equals(""))
8121
- {
8122
- bump = null;
8123
- }
8124
- if (pigment.equals(""))
8125
- {
8126
- pigment = null;
8127
- }
8128
-
8129
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8130
- BindTexture(pigment, false, resolution);
8131
- GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8132
- BindTexture(bump, true, resolution);
8133
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8134
-
8135
- return; // true;
8248
+ BindPigmentTexture(tex, resolution);
8249
+ BindBumpTexture(tex, resolution);
81368250 }
81378251
81388252 /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8151,9 +8265,9 @@
81518265
81528266 String pigment = Object3D.GetPigment(tex);
81538267
8154
- usedtextures.put(pigment, pigment);
8268
+ usedtextures.add(tex);
81558269
8156
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8270
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
81578271 {
81588272 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
81598273 // System.out.println("; bump = " + bump);
....@@ -8165,7 +8279,7 @@
81658279 }
81668280
81678281 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8168
- BindTexture(pigment, false, resolution);
8282
+ BindTexture(tex, false, resolution);
81698283 }
81708284
81718285 /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8184,9 +8298,9 @@
81848298
81858299 String bump = Object3D.GetBump(tex);
81868300
8187
- usedtextures.put(bump, bump);
8301
+ usedtextures.add(tex);
81888302
8189
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8303
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
81908304 {
81918305 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
81928306 // System.out.println("; bump = " + bump);
....@@ -8198,7 +8312,7 @@
81988312 }
81998313
82008314 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8201
- BindTexture(bump, true, resolution);
8315
+ BindTexture(tex, true, resolution);
82028316 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
82038317 }
82048318
....@@ -8222,13 +8336,19 @@
82228336 return fileExists;
82238337 }
82248338
8225
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception
8339
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
82268340 {
8227
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8341
+ CacheTexture texturecache = null;
82288342
82298343 if (tex != null)
82308344 {
8231
- String texname = tex;
8345
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8346
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
8347
+
8348
+ if (texname.equals("") && texdata == null)
8349
+ {
8350
+ return null;
8351
+ }
82328352
82338353 String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
82348354
....@@ -8238,19 +8358,46 @@
82388358 // else
82398359 // if (!texname.startsWith("/"))
82408360 // texname = "/Users/nbriere/Textures/" + texname;
8241
- if (!FileExists(tex))
8361
+ if (!FileExists(texname) && !texname.startsWith("@"))
82428362 {
82438363 texname = fallbackTextureName;
82448364 }
82458365
82468366 if (CACHETEXTURE)
8247
- texture = textures.get(texname); // TEXTURE CACHE
8248
-
8249
- TextureData texturedata = null;
8250
-
8251
- if (texture == null || texture.resolution < resolution)
82528367 {
8253
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8368
+ if (texdata == null)
8369
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8370
+ else
8371
+ texturecache = bimtextures.get(texdata);
8372
+ }
8373
+
8374
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8375
+ {
8376
+ TextureData texturedata = null;
8377
+
8378
+ if (texdata != null && textureon)
8379
+ {
8380
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8381
+
8382
+ try
8383
+ {
8384
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8385
+ }
8386
+ catch (Exception e)
8387
+ {
8388
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8389
+ }
8390
+
8391
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8392
+ bimtextures.put(texdata, texturecache);
8393
+
8394
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8395
+
8396
+ //Object bim2 = CreateBim(texturecache.texturedata);
8397
+ //bim2 = bim;
8398
+ }
8399
+ else
8400
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
82548401 {
82558402 assert(!bump);
82568403 // if (bump)
....@@ -8261,19 +8408,23 @@
82618408 // }
82628409 // else
82638410 // {
8264
- texture = textures.get(tex);
8265
- if (texture == null)
8411
+ // texturecache = textures.get(texname); // suspicious
8412
+ if (texturecache == null)
82668413 {
8267
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8414
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
82688415 }
8416
+ else
8417
+ new Exception().printStackTrace();
82698418 // }
82708419 } else
8271
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8420
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
82728421 {
82738422 assert(bump);
8274
- texture = textures.get(tex);
8275
- if (texture == null)
8276
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8423
+ // texturecache = textures.get(texname); // suspicious
8424
+ if (texturecache == null)
8425
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8426
+ else
8427
+ new Exception().printStackTrace();
82778428 } else
82788429 {
82798430 //if (tex.equals("IMMORTAL"))
....@@ -8281,11 +8432,22 @@
82818432 // texture = GetResourceTexture("default.png");
82828433 //} else
82838434 //{
8284
- if (tex.equals("WHITE_NOISE"))
8435
+ if (texname.endsWith("WHITE_NOISE"))
82858436 {
8286
- texture = textures.get(tex);
8287
- if (texture == null)
8288
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8437
+ // texturecache = textures.get(texname); // suspicious
8438
+ if (texturecache == null)
8439
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8440
+ else
8441
+ new Exception().printStackTrace();
8442
+ } else
8443
+ {
8444
+ if (texname.startsWith("@"))
8445
+ {
8446
+ // texturecache = textures.get(texname); // suspicious
8447
+ if (texturecache == null)
8448
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8449
+ else
8450
+ new Exception().printStackTrace();
82898451 } else
82908452 {
82918453 if (textureon)
....@@ -8344,19 +8506,20 @@
83448506 if (texturedata == null)
83458507 throw new Exception();
83468508
8347
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8509
+ texturecache = new CacheTexture(texturedata,resolution);
83488510 //texture = GetTexture(tex, bump);
83498511 }
8512
+ }
83508513 }
83518514 //}
83528515 }
83538516
8354
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8517
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
83558518 {
83568519 //return false;
83578520
83588521 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8359
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8522
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
83608523 {
83618524 // String ext = "_highres";
83628525 // if (REDUCETEXTURE)
....@@ -8373,52 +8536,17 @@
83738536 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
83748537 if (!cachefile.exists())
83758538 {
8376
- // cache to disk
8377
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
8378
- //buffers[0].
8379
-
8380
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
8381
- int[] pixels = new int[bytebuf.capacity()/3];
8382
-
8383
- // squared size heuristic...
8384
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8539
+ //if (texturedata.getWidth() == texturedata.getHeight())
83858540 {
8386
- for (int i=pixels.length; --i>=0;)
8387
- {
8388
- int i3 = i*3;
8389
- pixels[i] = 0xFF;
8390
- pixels[i] <<= 8;
8391
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
8392
- pixels[i] <<= 8;
8393
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
8394
- pixels[i] <<= 8;
8395
- pixels[i] |= bytebuf.get(i3) & 0xFF;
8396
- }
8397
-
8398
- /*
8399
- int r=0,g=0,b=0,a=0;
8400
- for (int i=0; i<width; i++)
8401
- for (int j=0; j<height; j++)
8402
- {
8403
- int index = j*width+i;
8404
- int p = pixels[index];
8405
- a = ((p>>24) & 0xFF);
8406
- r = ((p>>16) & 0xFF);
8407
- g = ((p>>8) & 0xFF);
8408
- b = (p & 0xFF);
8409
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
8410
- }
8411
- /**/
8412
- int width = (int)Math.sqrt(pixels.length); // squared
8413
- int height = width;
8414
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
8415
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8541
+ BufferedImage rendImage = CreateBim(texturedata);
8542
+
84168543 ImageWriter writer = null;
84178544 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
84188545 if (iter.hasNext()) {
84198546 writer = (ImageWriter)iter.next();
84208547 }
8421
- float compressionQuality = 0.9f;
8548
+
8549
+ float compressionQuality = 0.85f;
84228550 try
84238551 {
84248552 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8435,18 +8563,20 @@
84358563 }
84368564 }
84378565 }
8438
-
8566
+
8567
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8568
+
84398569 //System.out.println("Texture = " + tex);
8440
- if (textures.containsKey(texname))
8570
+ if (textures.containsKey(tex))
84418571 {
8442
- CacheTexture thetex = textures.get(texname);
8572
+ CacheTexture thetex = textures.get(tex);
84438573 thetex.texture.disable();
84448574 thetex.texture.dispose();
8445
- textures.remove(texname);
8575
+ textures.remove(tex);
84468576 }
84478577
8448
- texture.texturedata = texturedata;
8449
- textures.put(texname, texture);
8578
+ //texture.texturedata = texturedata;
8579
+ textures.put(tex, texturecache);
84508580
84518581 // newtex = true;
84528582 }
....@@ -8462,10 +8592,44 @@
84628592 }
84638593 }
84648594
8465
- return texture;
8595
+ return texturecache;
84668596 }
84678597
8468
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution) throws Exception
8598
+ static void EmbedTextures(cTexture tex)
8599
+ {
8600
+ if (tex.pigmentdata == null)
8601
+ {
8602
+ //String texname = Object3D.GetPigment(tex);
8603
+
8604
+ CacheTexture texturecache = texturepigment.get(tex);
8605
+
8606
+ if (texturecache != null)
8607
+ {
8608
+ tex.pw = texturecache.texturedata.getWidth();
8609
+ tex.ph = texturecache.texturedata.getHeight();
8610
+ tex.pigmentdata = //CompressJPEG(CreateBim
8611
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8612
+ ;
8613
+ //, tex.pw, tex.ph), 0.5f);
8614
+ }
8615
+ }
8616
+
8617
+ if (tex.bumpdata == null)
8618
+ {
8619
+ //String texname = Object3D.GetBump(tex);
8620
+
8621
+ CacheTexture texturecache = texturebump.get(tex);
8622
+
8623
+ if (texturecache != null)
8624
+ {
8625
+ tex.bw = texturecache.texturedata.getWidth();
8626
+ tex.bh = texturecache.texturedata.getHeight();
8627
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8628
+ }
8629
+ }
8630
+ }
8631
+
8632
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
84698633 {
84708634 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
84718635
....@@ -8483,21 +8647,21 @@
84838647 return texture!=null?texture.texture:null;
84848648 }
84858649
8486
- public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution) throws Exception
8650
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
84878651 {
84888652 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
84898653
84908654 return texture!=null?texture.texturedata:null;
84918655 }
84928656
8493
- boolean BindTexture(String tex, boolean bump, int resolution) throws Exception
8657
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
84948658 {
84958659 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
84968660 {
84978661 return false;
84988662 }
84998663
8500
- boolean newtex = false;
8664
+ //boolean newtex = false;
85018665
85028666 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
85038667
....@@ -8529,9 +8693,75 @@
85298693 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
85308694 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
85318695
8532
- return newtex;
8696
+ return true; // Warning: not used.
85338697 }
85348698
8699
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8700
+ {
8701
+ try
8702
+ {
8703
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8704
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8705
+ ImageWriter writer = writers.next();
8706
+
8707
+ ImageWriteParam param = writer.getDefaultWriteParam();
8708
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8709
+ param.setCompressionQuality(quality);
8710
+
8711
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8712
+ writer.setOutput(ios);
8713
+ writer.write(null, new IIOImage(image, null, null), param);
8714
+
8715
+ byte[] data = baos.toByteArray();
8716
+ writer.dispose();
8717
+ return data;
8718
+ }
8719
+ catch (Exception e)
8720
+ {
8721
+ e.printStackTrace();
8722
+ return null;
8723
+ }
8724
+ }
8725
+
8726
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8727
+ {
8728
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8729
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8730
+ ImageReader reader = writers.next();
8731
+
8732
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8733
+
8734
+ ImageReadParam param = reader.getDefaultReadParam();
8735
+ param.setDestination(bim);
8736
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8737
+
8738
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8739
+ reader.setInput(ios);
8740
+ BufferedImage bim2 = reader.read(0, param);
8741
+ reader.dispose();
8742
+
8743
+// WritableRaster raster = bim2.getRaster();
8744
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8745
+// byte[] bytes = data.getData();
8746
+//
8747
+// int[] pixels = new int[bytes.length/3];
8748
+// for (int i=pixels.length; --i>=0;)
8749
+// {
8750
+// int i3 = i*3;
8751
+// pixels[i] = 0xFF;
8752
+// pixels[i] <<= 8;
8753
+// pixels[i] |= bytes[i3+2] & 0xFF;
8754
+// pixels[i] <<= 8;
8755
+// pixels[i] |= bytes[i3+1] & 0xFF;
8756
+// pixels[i] <<= 8;
8757
+// pixels[i] |= bytes[i3] & 0xFF;
8758
+// }
8759
+//
8760
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8761
+
8762
+ return bim;
8763
+ }
8764
+
85358765 ShadowBuffer shadowPBuf;
85368766 AntialiasBuffer antialiasPBuf;
85378767 int MAXSTACK;
....@@ -8548,10 +8778,12 @@
85488778
85498779 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
85508780 MAXSTACK = temp[0];
8551
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8781
+ if (Globals.DEBUG)
8782
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
85528783 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
85538784 MAXSTACK = temp[0];
8554
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8785
+ if (Globals.DEBUG)
8786
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
85558787
85568788 // Use debug pipeline
85578789 //drawable.setGL(new DebugGL(gl)); //
....@@ -8559,7 +8791,8 @@
85598791 gl = drawable.getGL(); //
85608792
85618793 GL gl3 = getGL();
8562
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8794
+ if (Globals.DEBUG)
8795
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
85638796
85648797
85658798 //float pos[] = { 100, 100, 100, 0 };
....@@ -8724,7 +8957,7 @@
87248957
87258958 if (cubemap == null)
87268959 {
8727
- LoadEnvy(5);
8960
+ //LoadEnvy(1);
87288961 }
87298962
87308963 //cubemap.enable();
....@@ -9011,37 +9244,58 @@
90119244 cubemap = null;
90129245 return;
90139246 case 1:
9014
- name = "cubemaps/box_";
9015
- ext = "png";
9247
+ name = "cubemaps/rgb/";
9248
+ ext = "jpg";
90169249 reverseUP = false;
90179250 break;
90189251 case 2:
9019
- name = "cubemaps/uffizi_";
9020
- ext = "png";
9021
- break; // reverseUP = true; break;
9252
+ name = "cubemaps/uffizi/";
9253
+ ext = "jpg";
9254
+ reverseUP = false;
9255
+ break;
90229256 case 3:
9023
- name = "cubemaps/CloudyHills_";
9024
- ext = "tga";
9257
+ name = "cubemaps/CloudyHills/";
9258
+ ext = "jpg";
90259259 reverseUP = false;
90269260 break;
90279261 case 4:
9028
- name = "cubemaps/cornell_";
9262
+ name = "cubemaps/cornell/";
90299263 ext = "png";
90309264 reverseUP = false;
90319265 break;
9266
+ case 5:
9267
+ name = "cubemaps/skycube/";
9268
+ ext = "jpg";
9269
+ reverseUP = false;
9270
+ break;
9271
+ case 6:
9272
+ name = "cubemaps/SaintLazarusChurch3/";
9273
+ ext = "jpg";
9274
+ reverseUP = false;
9275
+ break;
9276
+ case 7:
9277
+ name = "cubemaps/Sodermalmsallen/";
9278
+ ext = "jpg";
9279
+ reverseUP = false;
9280
+ break;
9281
+ case 8:
9282
+ name = "cubemaps/Sodermalmsallen2/";
9283
+ ext = "jpg";
9284
+ reverseUP = false;
9285
+ break;
9286
+ case 9:
9287
+ name = "cubemaps/UnionSquare/";
9288
+ ext = "jpg";
9289
+ reverseUP = false;
9290
+ break;
90329291 default:
9033
- name = "cubemaps/rgb_";
9034
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9292
+ name = "cubemaps/box/";
9293
+ ext = "png"; /*mipmap = true;*/
9294
+ reverseUP = false;
90359295 break;
90369296 }
9037
-
9038
- try
9039
- {
9040
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
9041
- } catch (IOException e)
9042
- {
9043
- throw new RuntimeException(e);
9044
- }
9297
+
9298
+ LoadSkybox(name, ext, mipmap);
90459299 }
90469300
90479301 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -9073,8 +9327,12 @@
90739327 static double[] model = new double[16];
90749328 double[] camera2light = new double[16];
90759329 double[] light2camera = new double[16];
9076
- int newenvy = -1;
9077
- boolean envyoff = true; // false;
9330
+
9331
+ //int newenvy = -1;
9332
+ //boolean envyoff = false;
9333
+
9334
+ String loadedskyboxname;
9335
+
90789336 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
90799337 //float[] light0 = { 0,0,0 };
90809338 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9367,11 +9625,35 @@
93679625 jy8[3] = 0.5f;
93689626 }
93699627
9370
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9628
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
93719629 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
93729630 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
93739631 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
93749632
9633
+ void ResetOptions()
9634
+ {
9635
+ options1[0] = 100;
9636
+ options1[1] = 0.025f;
9637
+ options1[2] = 0.01f;
9638
+ options1[3] = 0;
9639
+ options1[4] = 0;
9640
+
9641
+ options2[0] = 0;
9642
+ options2[1] = 0.75f;
9643
+ options2[2] = 0;
9644
+ options2[3] = 0;
9645
+
9646
+ options3[0] = 1;
9647
+ options3[1] = 1;
9648
+ options3[2] = 1;
9649
+ options3[3] = 0;
9650
+
9651
+ options4[0] = 1;
9652
+ options4[1] = 0;
9653
+ options4[2] = 1;
9654
+ options4[3] = 0;
9655
+ }
9656
+
93759657 static int imagecount = 0; // movie generation
93769658
93779659 static int jitter = 0;
....@@ -9468,7 +9750,7 @@
94689750
94699751 if (renderCamera != lightCamera)
94709752 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9471
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
9753
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
94729754
94739755 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
94749756
....@@ -9484,7 +9766,7 @@
94849766
94859767 if (renderCamera != lightCamera)
94869768 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9487
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
9769
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
94889770
94899771 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
94909772
....@@ -9530,10 +9812,12 @@
95309812 rati = 1 / rati;
95319813 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
95329814 }
9533
- assert (newenvy == -1);
9815
+
9816
+ //assert (newenvy == -1);
9817
+
95349818 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
95359819 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9536
- DrawSkyBox(gl);
9820
+ DrawSkyBox(gl, (float)rati);
95379821 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
95389822 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
95399823 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10482,6 +10766,7 @@
1048210766 ANTIALIAS = 0;
1048310767 //System.out.println("RESTART");
1048410768 AAtimer.restart();
10769
+ Globals.TIMERRUNNING = true;
1048510770 }
1048610771 }
1048710772 }
....@@ -10549,7 +10834,8 @@
1054910834 ambientOcclusion = false;
1055010835 }
1055110836
10552
- if (Globals.lighttouched && DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
10837
+ if (//Globals.lighttouched &&
10838
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1055310839 {
1055410840 //if (RENDERSHADOW) // ?
1055510841 if (!IsFrozen())
....@@ -10568,7 +10854,7 @@
1056810854
1056910855 if (wait)
1057010856 {
10571
- Sleep(500);
10857
+ Sleep(200); // blocks everything
1057210858
1057310859 wait = false;
1057410860 }
....@@ -10683,7 +10969,7 @@
1068310969 // if (parentcam != renderCamera) // not a light
1068410970 if (cam != lightCamera)
1068510971 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10686
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
10972
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1068710973
1068810974 for (int j = 0; j < 4; j++)
1068910975 {
....@@ -10698,7 +10984,7 @@
1069810984 // if (parentcam != renderCamera) // not a light
1069910985 if (cam != lightCamera)
1070010986 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10701
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
10987
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1070210988
1070310989 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1070410990
....@@ -10784,13 +11070,27 @@
1078411070 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1078511071 }
1078611072
10787
- if (newenvy > -1)
11073
+// if (newenvy > -1)
11074
+// {
11075
+// LoadEnvy(newenvy);
11076
+// }
11077
+//
11078
+// newenvy = -1;
11079
+
11080
+ if (object.skyboxname != null)
1078811081 {
10789
- LoadEnvy(newenvy);
11082
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11083
+ {
11084
+ LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11085
+ loadedskyboxname = object.skyboxname;
11086
+ }
1079011087 }
10791
-
10792
- newenvy = -1;
10793
-
11088
+ else
11089
+ {
11090
+ cubemap = null;
11091
+ loadedskyboxname = null;
11092
+ }
11093
+
1079411094 ratio = ((double) getWidth()) / getHeight();
1079511095 //System.out.println("ratio = " + ratio);
1079611096
....@@ -10806,7 +11106,7 @@
1080611106
1080711107 if (!IsFrozen() && !ambientOcclusion)
1080811108 {
10809
- DrawSkyBox(gl);
11109
+ DrawSkyBox(gl, (float)ratio);
1081011110 }
1081111111
1081211112 //if (selection_view == -1)
....@@ -10989,9 +11289,9 @@
1098911289
1099011290 gl.glMatrixMode(GL.GL_MODELVIEW);
1099111291
10992
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10993
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10994
-//gl.glEnable(gl.GL_MULTISAMPLE);
11292
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11293
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11294
+gl.glEnable(gl.GL_MULTISAMPLE);
1099511295 } else
1099611296 {
1099711297 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -11002,7 +11302,7 @@
1100211302 //System.out.println("BLENDING ON");
1100311303 gl.glEnable(GL.GL_BLEND);
1100411304 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
11005
-
11305
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1100611306 gl.glMatrixMode(gl.GL_PROJECTION);
1100711307 gl.glLoadIdentity();
1100811308
....@@ -11092,7 +11392,7 @@
1109211392
1109311393 // if (cam != lightCamera)
1109411394 //for (int count = parentcam.GetTransformCount(); --count>=0;)
11095
- LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
11395
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1109611396 }
1109711397
1109811398 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -11251,7 +11551,7 @@
1125111551 }
1125211552 }
1125311553
11254
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11554
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1125511555 {
1125611556 //gl.glDepthFunc(GL.GL_LEQUAL);
1125711557 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11259,24 +11559,21 @@
1125911559
1126011560 boolean texon = textureon;
1126111561
11262
- if (RENDERPROGRAM > 0)
11263
- {
11264
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11265
- textureon = false;
11266
- }
11562
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11563
+ textureon = false;
11564
+
1126711565 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1126811566 //System.out.println("ALLO");
1126911567 gl.glColorMask(false, false, false, false);
1127011568 DrawObject(gl);
11271
- if (RENDERPROGRAM > 0)
11272
- {
11273
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11274
- textureon = texon;
11275
- }
11569
+
11570
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11571
+ textureon = texon;
11572
+
1127611573 gl.glColorMask(true, true, true, true);
1127711574
1127811575 gl.glDepthFunc(GL.GL_EQUAL);
11279
- //gl.glDepthMask(false);
11576
+ gl.glDepthMask(false);
1128011577 }
1128111578
1128211579 if (false) // DrawMode() == SHADOW)
....@@ -11459,15 +11756,36 @@
1145911756
1146011757 static boolean zoomonce = false;
1146111758
11759
+ static void CreateSelectedPoint()
11760
+ {
11761
+ if (selectedpoint == null)
11762
+ {
11763
+ debugpointG = new Sphere();
11764
+ debugpointP = new Sphere();
11765
+ debugpointC = new Sphere();
11766
+ debugpointR = new Sphere();
11767
+
11768
+ selectedpoint = new Superellipsoid();
11769
+
11770
+ for (int i=0; i<8; i++)
11771
+ {
11772
+ debugpoints[i] = new Sphere();
11773
+ }
11774
+ }
11775
+ }
11776
+
1146211777 void DrawObject(GL gl, boolean draw)
1146311778 {
11779
+ // To clear camera values
11780
+ ResetOptions();
11781
+
1146411782 //System.out.println("DRAW OBJECT " + mouseDown);
1146511783 // DrawMode() = SELECTION;
1146611784 //GL gl = getGL();
1146711785 if ((TRACK || SHADOWTRACK) || zoomonce)
1146811786 {
1146911787 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11470
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11788
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1147111789 pingthread.StepToTarget(true); // true);
1147211790 // zoomonce = false;
1147311791 }
....@@ -11539,8 +11857,9 @@
1153911857
1154011858 if (DrawMode() == DEFAULT)
1154111859 {
11542
- if (DEBUG)
11860
+ if (Globals.DEBUG)
1154311861 {
11862
+ CreateSelectedPoint();
1154411863 float radius = 0.05f;
1154511864 if (selectedpoint.radius != radius)
1154611865 {
....@@ -11594,20 +11913,32 @@
1159411913 ReleaseTextures(DEFAULT_TEXTURES);
1159511914
1159611915 if (CLEANCACHE)
11597
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11916
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1159811917 {
11599
- String tex = e.nextElement();
11918
+ cTexture tex = e.nextElement();
1160011919
1160111920 // System.out.println("Texture --------- " + tex);
1160211921
11603
- if (tex.equals("WHITE_NOISE"))
11922
+ if (tex.equals("WHITE_NOISE:"))
1160411923 continue;
1160511924
11606
- if (!usedtextures.containsKey(tex))
11925
+ if (!usedtextures.contains(tex))
1160711926 {
11927
+ CacheTexture gettex = texturepigment.get(tex);
1160811928 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11609
- textures.get(tex).texture.dispose();
11610
- textures.remove(tex);
11929
+ if (gettex != null)
11930
+ {
11931
+ gettex.texture.dispose();
11932
+ texturepigment.remove(tex);
11933
+ }
11934
+
11935
+ gettex = texturebump.get(tex);
11936
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11937
+ if (gettex != null)
11938
+ {
11939
+ gettex.texture.dispose();
11940
+ texturebump.remove(tex);
11941
+ }
1161111942 }
1161211943 }
1161311944 }
....@@ -12027,7 +12358,7 @@
1202712358 for (int i = tp.size(); --i >= 0;)
1202812359 {
1202912360 //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12030
- LA.xformPos(light, tp.get(i).GlobalTransform(), light);
12361
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1203112362 }
1203212363
1203312364
....@@ -12135,8 +12466,76 @@
1213512466
1213612467 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1213712468
12138
- String program =
12469
+ String programmin =
12470
+ // Min shader
1213912471 "!!ARBfp1.0\n" +
12472
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12473
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12474
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12475
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12476
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12477
+ "PARAM light2cam0 = program.env[10];" +
12478
+ "PARAM light2cam1 = program.env[11];" +
12479
+ "PARAM light2cam2 = program.env[12];" +
12480
+ "TEMP temp;" +
12481
+ "TEMP light;" +
12482
+ "TEMP ndotl;" +
12483
+ "TEMP normal;" +
12484
+ "TEMP depth;" +
12485
+ "TEMP eye;" +
12486
+ "TEMP pos;" +
12487
+
12488
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12489
+ Normalize("normal") +
12490
+ "MOV light, state.light[0].position;" +
12491
+ "DP3 ndotl.x, light, normal;" +
12492
+
12493
+ // shadow
12494
+ "MOV pos, fragment.texcoord[1];" +
12495
+ "MOV temp, pos;" +
12496
+ ShadowTextureFetch("depth", "temp", "1") +
12497
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12498
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12499
+
12500
+ // No shadow when out of frustum
12501
+ //"SGE temp.y, depth.z, zero123.y;" +
12502
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12503
+
12504
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12505
+
12506
+ // Backlit
12507
+ "MOV pos.w, zero123.y;" +
12508
+ "DP4 eye.x, pos, light2cam0;" +
12509
+ "DP4 eye.y, pos, light2cam1;" +
12510
+ "DP4 eye.z, pos, light2cam2;" +
12511
+ Normalize("eye") +
12512
+
12513
+ "DP3 ndotl.y, -eye, normal;" +
12514
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12515
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12516
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12517
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12518
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12519
+
12520
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12521
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12522
+
12523
+ // Pigment
12524
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12525
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12526
+ "MUL temp, temp, ndotl.x;" +
12527
+
12528
+ "MUL temp, temp, zero123.z;" +
12529
+
12530
+ //"MUL temp, temp, ndotl.y;" +
12531
+
12532
+ "MOV temp.w, zero123.y;" + // reset alpha
12533
+ "MOV result.color, temp;" +
12534
+ "END";
12535
+
12536
+ String programmax =
12537
+ "!!ARBfp1.0\n" +
12538
+
1214012539 //"OPTION ARB_fragment_program_shadow;" +
1214112540 "PARAM light2cam0 = program.env[10];" +
1214212541 "PARAM light2cam1 = program.env[11];" +
....@@ -12251,8 +12650,7 @@
1225112650 "TEMP shininess;" +
1225212651 "\n" +
1225312652 "MOV texSamp, one;" +
12254
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12255
-
12653
+
1225612654 "MOV mapgrid.x, one2048th.x;" +
1225712655 "MOV temp, fragment.texcoord[1];" +
1225812656 /*
....@@ -12273,20 +12671,20 @@
1227312671 "MUL temp, floor, mapgrid.x;" +
1227412672 //"TEX depth0, temp, texture[1], 2D;" +
1227512673 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12276
- TextureFetch("depth0", "temp", "1") +
12674
+ ShadowTextureFetch("depth0", "temp", "1") +
1227712675 "") +
1227812676 "ADD temp.x, temp.x, mapgrid.x;" +
1227912677 //"TEX depth1, temp, texture[1], 2D;" +
1228012678 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12281
- TextureFetch("depth1", "temp", "1") +
12679
+ ShadowTextureFetch("depth1", "temp", "1") +
1228212680 "") +
1228312681 "ADD temp.y, temp.y, mapgrid.x;" +
1228412682 //"TEX depth2, temp, texture[1], 2D;" +
12285
- TextureFetch("depth2", "temp", "1") +
12683
+ ShadowTextureFetch("depth2", "temp", "1") +
1228612684 "SUB temp.x, temp.x, mapgrid.x;" +
1228712685 //"TEX depth3, temp, texture[1], 2D;" +
1228812686 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12289
- TextureFetch("depth3", "temp", "1") +
12687
+ ShadowTextureFetch("depth3", "temp", "1") +
1229012688 "") +
1229112689 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1229212690 //"MOV params, material;" +
....@@ -12657,10 +13055,10 @@
1265713055 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1265813056 "") +
1265913057
12660
- // display shadow only (bump == 0)
13058
+ // display shadow only (fakedepth == 0)
1266113059 "SUB temp.x, half.x, shadow.x;" +
1266213060 "MOV temp.y, -params5.z;" + // params6.x;" +
12663
- "SLT temp.z, temp.y, -one2048th.x;" +
13061
+ "SLT temp.z, temp.y, -c256i.x;" +
1266413062 "SUB temp.y, one.x, temp.z;" +
1266513063 "MUL temp.x, temp.x, temp.y;" +
1266613064 "KIL temp.x;" +
....@@ -12991,6 +13389,13 @@
1299113389 //once = true;
1299213390 }
1299313391
13392
+ String program = programmax;
13393
+
13394
+ if (Globals.MINSHADER)
13395
+ {
13396
+ program = programmin;
13397
+ }
13398
+
1299413399 System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1299513400 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1299613401 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
....@@ -13084,25 +13489,26 @@
1308413489 return out;
1308513490 }
1308613491
13087
- String TextureFetch(String dest, String src, String unit)
13492
+ // Also does frustum culling
13493
+ String ShadowTextureFetch(String dest, String src, String unit)
1308813494 {
1308913495 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1309013496 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1309113497 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13498
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13499
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1309213500 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13093
- "SLT " + src + ".z, " + src + ".x, one.x;" +
13094
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13095
- "SLT " + src + ".z, " + src + ".y, one.x;" +
13096
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13501
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13502
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1309713503 //"SWZ buffer, temp, w,w,w,w;";
13098
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13504
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1309913505 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1310013506 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1310113507 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13102
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13508
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1310313509
13104
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13105
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13510
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13511
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1310613512 }
1310713513
1310813514 String Shadow(String depth, String shadow)
....@@ -13149,7 +13555,7 @@
1314913555 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1315013556 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1315113557
13152
- // No shadow when out of frustrum
13558
+ // No shadow when out of frustum
1315313559 "SGE temp.x, " + depth + ".z, one.z;" +
1315413560 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1315513561 "";
....@@ -13297,7 +13703,8 @@
1329713703 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1329813704 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1329913705 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13300
- Object3D.cVector2[] vector2buffer;
13706
+
13707
+ //Object3D.cVector2[] vector2buffer;
1330113708
1330213709 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1330313710 // OUT : diff, spec
....@@ -13313,9 +13720,10 @@
1331313720 "DP3 " + dest + ".z," + "normals," + "eye;" +
1331413721 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1331513722 //"MOV " + dest + ".w," + "normal.z;" +
13316
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
13317
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13318
- //"MOV " + dest + ".z," + "params2.w;" +
13723
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13724
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13725
+
13726
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1331913727 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1332013728 "RCP " + dest + ".w," + dest + ".w;" +
1332113729 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13820,6 +14228,7 @@
1382014228 else
1382114229 if (evt.getSource() == AAtimer)
1382214230 {
14231
+ Globals.TIMERRUNNING = false;
1382314232 if (mouseDown)
1382414233 {
1382514234 //new Exception().printStackTrace();
....@@ -13879,7 +14288,7 @@
1387914288
1388014289 // fev 2014???
1388114290 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13882
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14291
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1388314292 pingthread.StepToTarget(true); // true);
1388414293 }
1388514294 // if (!LIVE)
....@@ -13894,6 +14303,7 @@
1389414303 return;
1389514304
1389614305 AAtimer.restart(); //
14306
+ Globals.TIMERRUNNING = true;
1389714307
1389814308 // waslive = LIVE;
1389914309 // LIVE = false;
....@@ -13943,14 +14353,15 @@
1394314353 drag = false;
1394414354 //System.out.println("Mouse DOWN");
1394514355 editObj = false;
13946
- ClickInfo info = new ClickInfo();
13947
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
13948
- info.pane = this;
13949
- info.camera = renderCamera;
13950
- info.x = x;
13951
- info.y = y;
13952
- info.modifiers = modifiersex;
13953
- editObj = object.doEditClick(info, 0);
14356
+ //ClickInfo info = new ClickInfo();
14357
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14358
+ object.clickInfo.pane = this;
14359
+ object.clickInfo.camera = renderCamera;
14360
+ object.clickInfo.x = x;
14361
+ object.clickInfo.y = y;
14362
+ object.clickInfo.modifiers = modifiersex;
14363
+ editObj = object.doEditClick(//info,
14364
+ 0);
1395414365 if (!editObj)
1395514366 {
1395614367 hasMarquee = true;
....@@ -14232,12 +14643,12 @@
1423214643 void GoDown(int mod)
1423314644 {
1423414645 MODIFIERS |= COMMAND;
14235
- /*
14646
+ /**/
1423614647 if((mod&SHIFT) == SHIFT)
14237
- manipCamera.RotatePosition(0, -speed);
14648
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
1423814649 else
14239
- manipCamera.BackForth(0, -speed*delta, getWidth());
14240
- */
14650
+ manipCamera.RotatePosition(0, -speed);
14651
+ /**/
1424114652 if ((mod & SHIFT) == SHIFT)
1424214653 {
1424314654 mouseMode = mouseMode; // VR??
....@@ -14253,12 +14664,12 @@
1425314664 void GoUp(int mod)
1425414665 {
1425514666 MODIFIERS |= COMMAND;
14256
- /*
14667
+ /**/
1425714668 if((mod&SHIFT) == SHIFT)
14258
- manipCamera.RotatePosition(0, speed);
14669
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
1425914670 else
14260
- manipCamera.BackForth(0, speed*delta, getWidth());
14261
- */
14671
+ manipCamera.RotatePosition(0, speed);
14672
+ /**/
1426214673 if ((mod & SHIFT) == SHIFT)
1426314674 {
1426414675 mouseMode = mouseMode;
....@@ -14274,12 +14685,12 @@
1427414685 void GoLeft(int mod)
1427514686 {
1427614687 MODIFIERS |= COMMAND;
14277
- /*
14688
+ /**/
1427814689 if((mod&SHIFT) == SHIFT)
14279
- manipCamera.RotatePosition(speed, 0);
14280
- else
1428114690 manipCamera.Translate(speed*delta, 0, getWidth());
14282
- */
14691
+ else
14692
+ manipCamera.RotatePosition(speed, 0);
14693
+ /**/
1428314694 if ((mod & SHIFT) == SHIFT)
1428414695 {
1428514696 mouseMode = mouseMode;
....@@ -14295,12 +14706,12 @@
1429514706 void GoRight(int mod)
1429614707 {
1429714708 MODIFIERS |= COMMAND;
14298
- /*
14709
+ /**/
1429914710 if((mod&SHIFT) == SHIFT)
14300
- manipCamera.RotatePosition(-speed, 0);
14301
- else
1430214711 manipCamera.Translate(-speed*delta, 0, getWidth());
14303
- */
14712
+ else
14713
+ manipCamera.RotatePosition(-speed, 0);
14714
+ /**/
1430414715 if ((mod & SHIFT) == SHIFT)
1430514716 {
1430614717 mouseMode = mouseMode;
....@@ -14350,14 +14761,16 @@
1435014761 if (editObj)
1435114762 {
1435214763 drag = true;
14353
- ClickInfo info = new ClickInfo();
14354
- info.bounds.setBounds(0, 0,
14764
+ //ClickInfo info = new ClickInfo();
14765
+ object.clickInfo.bounds.setBounds(0, 0,
1435514766 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14356
- info.pane = this;
14357
- info.camera = renderCamera;
14358
- info.x = x;
14359
- info.y = y;
14360
- object.editWindow.copy.doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
14767
+ object.clickInfo.pane = this;
14768
+ object.clickInfo.camera = renderCamera;
14769
+ object.clickInfo.x = x;
14770
+ object.clickInfo.y = y;
14771
+ object //.GetWindow().copy
14772
+ .doEditDrag(//info,
14773
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1436114774 } else
1436214775 {
1436314776 if (x < startX)
....@@ -14506,22 +14919,27 @@
1450614919 }
1450714920 }
1450814921
14922
+// ClickInfo clickInfo = new ClickInfo();
14923
+
1450914924 public void mouseMoved(MouseEvent e)
1451014925 {
1451114926 //System.out.println("mouseMoved: " + e);
1451214927 if (isRenderer)
1451314928 return;
1451414929
14515
- ClickInfo ci = new ClickInfo();
14516
- ci.x = e.getX();
14517
- ci.y = e.getY();
14518
- ci.modifiers = e.getModifiersEx();
14519
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14520
- ci.pane = this;
14521
- ci.camera = renderCamera;
14930
+ // Mouse cursor feedback
14931
+ object.clickInfo.x = e.getX();
14932
+ object.clickInfo.y = e.getY();
14933
+ object.clickInfo.modifiers = e.getModifiersEx();
14934
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14935
+ object.clickInfo.pane = this;
14936
+ object.clickInfo.camera = renderCamera;
1452214937 if (!isRenderer)
1452314938 {
14524
- if (object.editWindow.copy.doEditClick(ci, 0))
14939
+ //ObjEditor editWindow = object.editWindow;
14940
+ //Object3D copy = editWindow.copy;
14941
+ if (object.doEditClick(//clickInfo,
14942
+ 0))
1452514943 {
1452614944 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1452714945 } else
....@@ -14536,7 +14954,8 @@
1453614954 Globals.MOUSEDRAGGED = false;
1453714955
1453814956 movingcamera = false;
14539
- X = Y = 0;
14957
+ X = 0; // getBounds().width/2;
14958
+ Y = 0; // getBounds().height/2;
1454014959 //System.out.println("mouseReleased: " + e);
1454114960 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1454214961 }
....@@ -14792,7 +15211,8 @@
1479215211 // break;
1479315212 case 'T':
1479415213 CACHETEXTURE ^= true;
14795
- textures.clear();
15214
+ texturepigment.clear();
15215
+ texturebump.clear();
1479615216 // repaint();
1479715217 break;
1479815218 case 'Y':
....@@ -14877,7 +15297,9 @@
1487715297 case 'E' : COMPACT ^= true;
1487815298 repaint();
1487915299 break;
14880
- case 'W' : DEBUGHSB ^= true;
15300
+ case 'W' : // Wide Window (fullscreen)
15301
+ //DEBUGHSB ^= true;
15302
+ ObjEditor.theFrame.ToggleFullScreen();
1488115303 repaint();
1488215304 break;
1488315305 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14902,8 +15324,8 @@
1490215324 RevertCamera();
1490315325 repaint();
1490415326 break;
14905
- case 'L':
1490615327 case 'l':
15328
+ //case 'L':
1490715329 if (lightMode)
1490815330 {
1490915331 lightMode = false;
....@@ -14967,20 +15389,24 @@
1496715389 OCCLUSION_CULLING ^= true;
1496815390 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1496915391 break;
14970
- case '0': envyoff ^= true; repaint(); break;
15392
+ //case '0': envyoff ^= true; repaint(); break;
1497115393 case '1':
1497215394 case '2':
1497315395 case '3':
1497415396 case '4':
1497515397 case '5':
14976
- newenvy = Character.getNumericValue(key);
14977
- repaint();
14978
- break;
1497915398 case '6':
1498015399 case '7':
1498115400 case '8':
1498215401 case '9':
14983
- BGcolor = (key - '6')/3.f;
15402
+ if (true) // envyoff)
15403
+ {
15404
+ BGcolor = (key - '1')/8.f;
15405
+ }
15406
+ else
15407
+ {
15408
+ //newenvy = Character.getNumericValue(key);
15409
+ }
1498415410 repaint();
1498515411 break;
1498615412 case '!':
....@@ -15046,9 +15472,9 @@
1504615472 case '_':
1504715473 kompactbit = 5;
1504815474 break;
15049
- case '+':
15050
- kompactbit = 6;
15051
- break;
15475
+// case '+':
15476
+// kompactbit = 6;
15477
+// break;
1505215478 case ' ':
1505315479 lightMode ^= true;
1505415480 Globals.lighttouched = true;
....@@ -15060,6 +15486,7 @@
1506015486 case ESC:
1506115487 RENDERPROGRAM += 1;
1506215488 RENDERPROGRAM %= 3;
15489
+
1506315490 repaint();
1506415491 break;
1506515492 case 'Z':
....@@ -15099,8 +15526,9 @@
1509915526 case DELETE:
1510015527 ClearSelection();
1510115528 break;
15102
- /*
1510315529 case '+':
15530
+
15531
+ /*
1510415532 //fontsize += 1;
1510515533 bbzoom *= 2;
1510615534 repaint();
....@@ -15117,17 +15545,17 @@
1511715545 case '=':
1511815546 IncDepth();
1511915547 //fontsize += 1;
15120
- object.editWindow.refreshContents(true);
15548
+ object.GetWindow().refreshContents(true);
1512115549 maskbit = 6;
1512215550 break;
1512315551 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1512415552 DecDepth();
1512515553 maskbit = 5;
1512615554 //if(fontsize > 1) fontsize -= 1;
15127
- if (object.editWindow == null)
15128
- new Exception().printStackTrace();
15129
- else
15130
- object.editWindow.refreshContents(true);
15555
+// if (object.editWindow == null)
15556
+// new Exception().printStackTrace();
15557
+// else
15558
+ object.GetWindow().refreshContents(true);
1513115559 break;
1513215560 case '{':
1513315561 manipCamera.shaper_fovy /= 1.1;
....@@ -15351,7 +15779,7 @@
1535115779 }
1535215780 */
1535315781
15354
- object.editWindow.EditSelection();
15782
+ object.GetWindow().EditSelection(false);
1535515783 }
1535615784
1535715785 void SelectParent()
....@@ -15368,10 +15796,10 @@
1536815796 {
1536915797 //selectees.remove(i);
1537015798 System.out.println("select parent of " + elem);
15371
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15799
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1537215800 } else
1537315801 {
15374
- group.editWindow.Select(elem.GetTreePath(), first, true);
15802
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1537515803 }
1537615804
1537715805 first = false;
....@@ -15413,12 +15841,12 @@
1541315841 for (int j = 0; j < group.children.size(); j++)
1541415842 {
1541515843 elem = (Object3D) group.children.elementAt(j);
15416
- object.editWindow.Select(elem.GetTreePath(), first, true);
15844
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1541715845 first = false;
1541815846 }
1541915847 } else
1542015848 {
15421
- object.editWindow.Select(elem.GetTreePath(), first, true);
15849
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1542215850 }
1542315851
1542415852 first = false;
....@@ -15429,21 +15857,21 @@
1542915857 {
1543015858 //Composite group = (Composite) object;
1543115859 Object3D group = object;
15432
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15860
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1543315861 }
1543415862
1543515863 void ResetTransform(int mask)
1543615864 {
1543715865 //Composite group = (Composite) object;
1543815866 Object3D group = object;
15439
- group.editWindow.ResetTransform(mask);
15867
+ group.GetWindow().ResetTransform(mask);
1544015868 }
1544115869
1544215870 void FlipTransform()
1544315871 {
1544415872 //Composite group = (Composite) object;
1544515873 Object3D group = object;
15446
- group.editWindow.FlipTransform();
15874
+ group.GetWindow().FlipTransform();
1544715875 // group.editWindow.ReduceMesh(true);
1544815876 }
1544915877
....@@ -15451,7 +15879,7 @@
1545115879 {
1545215880 //Composite group = (Composite) object;
1545315881 Object3D group = object;
15454
- group.editWindow.PrintMemory();
15882
+ group.GetWindow().PrintMemory();
1545515883 // group.editWindow.ReduceMesh(true);
1545615884 }
1545715885
....@@ -15459,7 +15887,7 @@
1545915887 {
1546015888 //Composite group = (Composite) object;
1546115889 Object3D group = object;
15462
- group.editWindow.ResetCentroid();
15890
+ group.GetWindow().ResetCentroid();
1546315891 }
1546415892
1546515893 void IncDepth()
....@@ -15541,8 +15969,6 @@
1554115969
1554215970 int width = getBounds().width;
1554315971 int height = getBounds().height;
15544
- ClickInfo info = new ClickInfo();
15545
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1554615972 //Image img = CreateImage(width, height);
1554715973 //System.out.println("width = " + width + "; height = " + height + "\n");
1554815974
....@@ -15619,48 +16045,77 @@
1561916045 }
1562016046 if (object != null && !hasMarquee)
1562116047 {
16048
+ if (object.clickInfo == null)
16049
+ object.clickInfo = new ClickInfo();
16050
+ ClickInfo info = object.clickInfo;
16051
+ //ClickInfo info = new ClickInfo();
16052
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16053
+
1562216054 if (isRenderer)
1562316055 {
15624
- info.flags++;
16056
+ object.clickInfo.flags++;
1562516057 double frameAspect = (double) width / (double) height;
1562616058 if (frameAspect > renderCamera.aspect)
1562716059 {
1562816060 int desired = (int) ((double) height * renderCamera.aspect);
15629
- info.bounds.width -= width - desired;
15630
- info.bounds.x += (width - desired) / 2;
16061
+ object.clickInfo.bounds.width -= width - desired;
16062
+ object.clickInfo.bounds.x += (width - desired) / 2;
1563116063 } else
1563216064 {
1563316065 int desired = (int) ((double) width / renderCamera.aspect);
15634
- info.bounds.height -= height - desired;
15635
- info.bounds.y += (height - desired) / 2;
16066
+ object.clickInfo.bounds.height -= height - desired;
16067
+ object.clickInfo.bounds.y += (height - desired) / 2;
1563616068 }
1563716069 }
15638
- info.g = gr;
15639
- info.camera = renderCamera;
16070
+
16071
+ object.clickInfo.g = gr;
16072
+ object.clickInfo.camera = renderCamera;
1564016073 /*
1564116074 // Memory intensive (brep.verticescopy)
1564216075 if (!(object instanceof Composite))
1564316076 object.draw(info, 0, false); // SLOW :
1564416077 */
15645
- if (!isRenderer)
16078
+ if (!isRenderer) // && drag)
1564616079 {
15647
- object.drawEditHandles(info, 0);
15648
-
15649
- if (drag && (X != 0 || Y != 0) && object.selection.Size() > 0)
16080
+ Grafreed.Assert(object != null);
16081
+ Grafreed.Assert(object.selection != null);
16082
+ if (object.selection.Size() > 0)
1565016083 {
15651
- switch (object.selection.get(0).hitSomething)
16084
+ int hitSomething = object.selection.get(0).hitSomething;
16085
+
16086
+ object.clickInfo.DX = 0;
16087
+ object.clickInfo.DY = 0;
16088
+ object.clickInfo.W = 1;
16089
+ if (hitSomething == Object3D.hitCenter)
1565216090 {
15653
- case Object3D.hitCenter: gr.setColor(Color.pink);
15654
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15655
- break;
15656
- case Object3D.hitRotate: gr.setColor(Color.yellow);
15657
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15658
- break;
15659
- case Object3D.hitScale: gr.setColor(Color.cyan);
15660
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15661
- break;
16091
+ info.DX = X;
16092
+ if (X != 0)
16093
+ info.DX -= info.bounds.width/2;
16094
+
16095
+ info.DY = Y;
16096
+ if (Y != 0)
16097
+ info.DY -= info.bounds.height/2;
1566216098 }
15663
-
16099
+
16100
+ object.drawEditHandles(//info,
16101
+ 0);
16102
+
16103
+ if (drag && (X != 0 || Y != 0))
16104
+ {
16105
+ switch (hitSomething)
16106
+ {
16107
+ case Object3D.hitCenter: gr.setColor(Color.pink);
16108
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16109
+ break;
16110
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16111
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16112
+ break;
16113
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16114
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16115
+ break;
16116
+ }
16117
+
16118
+ }
1566416119 }
1566516120 }
1566616121 }
....@@ -16142,6 +16597,8 @@
1614216597 private /*static*/ boolean firstime;
1614316598 private /*static*/ cVector newView = new cVector();
1614416599 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16600
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16601
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1614516602 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1614616603 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1614716604 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16154,29 +16611,67 @@
1615416611 {
1615516612 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1615616613
16614
+ int usedsuf = 0;
16615
+
1615716616 for (int i = 0; i < suffixes.length; i++)
1615816617 {
16159
- String resourceName = basename + suffixes[i] + "." + suffix;
16160
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16161
- mipmapped,
16162
- FileUtil.getFileSuffix(resourceName));
16163
- if (data == null)
16618
+ String[] suffixe = suffixes;
16619
+ String[] fallback = suffixes2;
16620
+ String[] fallfallback = suffixes3;
16621
+
16622
+ for (int c=usedsuf; --c>=0;)
1616416623 {
16165
- throw new IOException("Unable to load texture " + resourceName);
16624
+// String[] temp = suffixe;
16625
+// suffixe = fallback;
16626
+// fallback = fallfallback;
16627
+// fallfallback = temp;
1616616628 }
16629
+
16630
+ String resourceName = basename + suffixe[i] + "." + suffix;
16631
+ TextureData data;
16632
+
16633
+ try
16634
+ {
16635
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16636
+ mipmapped,
16637
+ FileUtil.getFileSuffix(resourceName));
16638
+ }
16639
+ catch (Exception e)
16640
+ {
16641
+ try
16642
+ {
16643
+ resourceName = basename + fallback[i] + "." + suffix;
16644
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16645
+ mipmapped,
16646
+ FileUtil.getFileSuffix(resourceName));
16647
+ }
16648
+ catch (Exception e2)
16649
+ {
16650
+ resourceName = basename + fallfallback[i] + "." + suffix;
16651
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16652
+ mipmapped,
16653
+ FileUtil.getFileSuffix(resourceName));
16654
+ }
16655
+ }
16656
+
1616716657 //System.out.println("Target = " + targets[i]);
1616816658 cubemap.updateImage(data, targets[i]);
1616916659 }
1617016660
1617116661 return cubemap;
1617216662 }
16663
+
1617316664 int bigsphere = -1;
1617416665
1617516666 float BGcolor = 0.5f;
1617616667
16177
- private void DrawSkyBox(GL gl)
16668
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16669
+
16670
+ private void DrawSkyBox(GL gl, float ratio)
1617816671 {
16179
- if (envyoff || cubemap == null)
16672
+ if (//envyoff ||
16673
+ WIREFRAME ||
16674
+ cubemap == null)
1618016675 {
1618116676 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1618216677 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16191,7 +16686,17 @@
1619116686 // Compensates for ExaminerViewer's modification of modelview matrix
1619216687 gl.glMatrixMode(GL.GL_MODELVIEW);
1619316688 gl.glLoadIdentity();
16689
+ gl.glScalef(1,ratio,1);
1619416690
16691
+// colorV[0] = 2;
16692
+// colorV[1] = 2;
16693
+// colorV[2] = 2;
16694
+// colorV[3] = 1;
16695
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16696
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16697
+//
16698
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16699
+
1619516700 //gl.glActiveTexture(GL.GL_TEXTURE1);
1619616701 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1619716702
....@@ -16223,6 +16728,7 @@
1622316728 {
1622416729 gl.glScalef(1.0f, -1.0f, 1.0f);
1622516730 }
16731
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1622616732 gl.glMultMatrixd(viewrot_1, 0);
1622716733 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1622816734 //viewer.updateInverseRotation(gl);
....@@ -16363,16 +16869,16 @@
1636316869 cStatic.objectstack[materialdepth++] = checker;
1636416870 //System.out.println("material " + material);
1636516871 //Applet3D.tracein(this, selected);
16366
- vector2buffer = checker.projectedVertices;
16872
+ //vector2buffer = checker.projectedVertices;
1636716873
1636816874 //checker.GetMaterial().Draw(this, false); // true);
16369
- DrawMaterial(checker.GetMaterial(), false); // true);
16875
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1637016876
1637116877 materialdepth -= 1;
1637216878 if (materialdepth > 0)
1637316879 {
16374
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16375
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
16880
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16881
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1637616882 }
1637716883 //checker.GetMaterial().opacity = 1f;
1637816884 ////checker.GetMaterial().ambient = 1f;
....@@ -16458,6 +16964,14 @@
1645816964 }
1645916965 }
1646016966
16967
+ private Object3D GetFolder()
16968
+ {
16969
+ Object3D folder = object.GetWindow().copy;
16970
+ if (object.GetWindow().copy.selection.Size() > 0)
16971
+ folder = object.GetWindow().copy.selection.elementAt(0);
16972
+ return folder;
16973
+ }
16974
+
1646116975 class SelectBuffer implements GLEventListener
1646216976 {
1646316977
....@@ -16473,7 +16987,7 @@
1647316987 //new Exception().printStackTrace();
1647416988 System.out.println("select buffer init");
1647516989 // Use debug pipeline
16476
- drawable.setGL(new DebugGL(drawable.getGL()));
16990
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1647716991
1647816992 GL gl = drawable.getGL();
1647916993
....@@ -16537,6 +17051,17 @@
1653717051
1653817052 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1653917053
17054
+ if (PAINTMODE)
17055
+ {
17056
+ if (object.GetWindow().copy.selection.Size() > 0)
17057
+ {
17058
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17059
+
17060
+ // Make what you paint not selectable.
17061
+ paintobj.ResetSelectable();
17062
+ }
17063
+ }
17064
+
1654017065 //int tmp = selection_view;
1654117066 //selection_view = -1;
1654217067 int temp = DrawMode();
....@@ -16548,6 +17073,17 @@
1654817073 // temp = DEFAULT; // patch for selection debug
1654917074 Globals.drawMode = temp; // WARNING
1655017075
17076
+ if (PAINTMODE)
17077
+ {
17078
+ if (object.GetWindow().copy.selection.Size() > 0)
17079
+ {
17080
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17081
+
17082
+ // Revert.
17083
+ paintobj.RestoreSelectable();
17084
+ }
17085
+ }
17086
+
1655117087 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1655217088
1655317089 // trying different ways of getting the depth info over
....@@ -16595,6 +17131,8 @@
1659517131 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1659617132 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1659717133 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
17134
+
17135
+ CreateSelectedPoint();
1659817136
1659917137 // Will fit the mesh !!!
1660017138 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16649,29 +17187,31 @@
1664917187 }
1665017188
1665117189 if (!movingcamera && !PAINTMODE)
16652
- object.editWindow.ScreenFitPoint(); // fev 2014
17190
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1665317191
16654
- if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17192
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1665517193 {
16656
- Object3D paintobj = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17194
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1665717195
16658
- Object3D group = new Object3D("inst" + paintcount++);
17196
+ if (object.GetWindow().copy.selection.Size() > 0)
17197
+ {
17198
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1665917199
16660
- group.CreateMaterial(); // use a void leaf to select instances
16661
-
16662
- group.add(paintobj); // link
16663
-
16664
- object.editWindow.SnapObject(group);
16665
-
16666
- Object3D folder = object.editWindow.copy;
16667
-
16668
- if (object.editWindow.copy.selection.Size() > 0)
16669
- folder = object.editWindow.copy.selection.elementAt(0);
16670
-
16671
- folder.add(group);
16672
-
16673
- object.editWindow.ResetModel();
16674
- object.editWindow.refreshContents();
17200
+ Object3D inst = new Object3D("inst" + paintcount++);
17201
+
17202
+ inst.CreateMaterial(); // use a void leaf to select instances
17203
+
17204
+ inst.add(paintobj); // link
17205
+
17206
+ object.GetWindow().SnapObject(inst);
17207
+
17208
+ Object3D folder = paintFolder; // GetFolder();
17209
+
17210
+ folder.add(inst);
17211
+
17212
+ object.GetWindow().ResetModel();
17213
+ object.GetWindow().refreshContents();
17214
+ }
1667517215 }
1667617216 else
1667717217 paintcount = 0;
....@@ -16710,6 +17250,11 @@
1671017250 //System.out.println("objects[color] = " + objects[color]);
1671117251 //objects[color].Select();
1671217252 indexcount = 0;
17253
+ ObjEditor window = object.GetWindow();
17254
+ if (window != null && deselect)
17255
+ {
17256
+ window.Select(null, deselect, true);
17257
+ }
1671317258 object.Select(color, deselect);
1671417259 }
1671517260
....@@ -17235,23 +17780,15 @@
1723517780 int AAbuffersize = 0;
1723617781
1723717782 //double[] selectedpoint = new double[3];
17238
- static Superellipsoid selectedpoint = new Superellipsoid();
17783
+ static Superellipsoid selectedpoint;
1723917784 static Sphere previousselectedpoint = null;
17240
- static Sphere debugpointG = new Sphere();
17241
- static Sphere debugpointP = new Sphere();
17242
- static Sphere debugpointC = new Sphere();
17243
- static Sphere debugpointR = new Sphere();
17785
+ static Sphere debugpointG;
17786
+ static Sphere debugpointP;
17787
+ static Sphere debugpointC;
17788
+ static Sphere debugpointR;
1724417789
1724517790 static Sphere debugpoints[] = new Sphere[8];
1724617791
17247
- static
17248
- {
17249
- for (int i=0; i<8; i++)
17250
- {
17251
- debugpoints[i] = new Sphere();
17252
- }
17253
- }
17254
-
1725517792 static void InitPoints(float radius)
1725617793 {
1725717794 for (int i=0; i<8; i++)