Normand Briere
2019-07-28 a434119e65146fe53d612c28e1ee7af532d1b70a
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 {
....@@ -44,6 +48,39 @@
4448 static boolean ABORTED = false;
4549
4650 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
+ }
4784
4885 /*static*/ private boolean CULLFACE = false; // true;
4986 /*static*/ boolean NEAREST = false; // true;
....@@ -60,7 +97,7 @@
6097 //boolean REDUCETEXTURE = true;
6198 boolean CACHETEXTURE = true;
6299 boolean CLEANCACHE = false; // true;
63
- boolean MIPMAP = false; // true;
100
+ boolean MIPMAP = false; // true; // never works...
64101 boolean COMPRESSTEXTURE = false;
65102 boolean KOMPACTTEXTURE = false; // true;
66103 boolean RESIZETEXTURE = false;
....@@ -150,6 +187,18 @@
150187 }
151188
152189 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
+ }
153202
154203 void SetAsGLRenderer(boolean b)
155204 {
....@@ -169,7 +218,8 @@
169218
170219 SetCamera(cam);
171220
172
- SetLight(new Camera(new cVector(10, 10, -20)));
221
+ // Warning: not used.
222
+ SetLight(new Camera(new cVector(15, 10, -20)));
173223
174224 object = o;
175225
....@@ -326,7 +376,7 @@
326376 cStatic.objectstack[materialdepth++] = obj;
327377 //System.out.println("material " + material);
328378 //Applet3D.tracein(this, selected);
329
- display.vector2buffer = obj.projectedVertices;
379
+ //display.vector2buffer = obj.projectedVertices;
330380 if (obj instanceof Camera)
331381 {
332382 display.options1[0] = material.shift;
....@@ -335,14 +385,28 @@
335385 display.options1[2] = material.shadowbias;
336386 display.options1[3] = material.aniso;
337387 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]);
338393 display.options2[0] = material.opacity;
339394 display.options2[1] = material.diffuse;
340395 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]);
341399
342400 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]);
343404 display.options4[0] = material.cameralight/0.2f;
344405 display.options4[1] = material.subsurface;
345406 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]);
346410
347411 // if (display.CURRENTANTIALIAS > 0)
348412 // display.options3[3] /= 4;
....@@ -358,7 +422,7 @@
358422 /**/
359423 } else
360424 {
361
- DrawMaterial(material, selected);
425
+ DrawMaterial(material, selected, obj.projectedVertices);
362426 }
363427 } else
364428 {
....@@ -382,8 +446,8 @@
382446 cStatic.objectstack[materialdepth++] = obj;
383447 //System.out.println("material " + material);
384448 //Applet3D.tracein("selected ", selected);
385
- display.vector2buffer = obj.projectedVertices;
386
- display.DrawMaterial(material, selected);
449
+ //display.vector2buffer = obj.projectedVertices;
450
+ display.DrawMaterial(material, selected, obj.projectedVertices);
387451 }
388452 }
389453
....@@ -400,8 +464,8 @@
400464 materialdepth -= 1;
401465 if (materialdepth > 0)
402466 {
403
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
404
- 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);
405469 }
406470 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
407471 } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
....@@ -421,8 +485,8 @@
421485 materialdepth -= 1;
422486 if (materialdepth > 0)
423487 {
424
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
425
- 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);
426490 }
427491 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
428492 //else
....@@ -1433,6 +1497,8 @@
14331497 gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
14341498 }
14351499
1500
+ float[] colorV = new float[4];
1501
+
14361502 void SetColor(Object3D obj, Vertex p0)
14371503 {
14381504 CameraPane display = this;
....@@ -1500,8 +1566,6 @@
15001566 {
15011567 return;
15021568 }
1503
-
1504
- float[] colorV = new float[3];
15051569
15061570 if (false) // marked)
15071571 {
....@@ -1610,7 +1674,7 @@
16101674 // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
16111675 }
16121676
1613
- void DrawMaterial(cMaterial material, boolean selected)
1677
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
16141678 {
16151679 CameraPane display = this;
16161680 //new Exception().printStackTrace();
....@@ -1645,7 +1709,7 @@
16451709 colorV[0] = display.modelParams0[0] * material.diffuse;
16461710 colorV[1] = display.modelParams0[1] * material.diffuse;
16471711 colorV[2] = display.modelParams0[2] * material.diffuse;
1648
- colorV[3] = material.opacity;
1712
+ colorV[3] = 1; // material.opacity;
16491713
16501714 gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
16511715 //System.out.println("Opacity = " + opacity);
....@@ -1753,9 +1817,9 @@
17531817 display.modelParams7[2] = 0;
17541818 display.modelParams7[3] = 0;
17551819
1756
- display.modelParams6[0] = 100; // criss de bug de bump
1820
+ //display.modelParams6[0] = 100; // criss de bug de bump
17571821
1758
- Object3D.cVector2[] extparams = display.vector2buffer;
1822
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
17591823 if (extparams != null && extparams.length > 0 && extparams[0] != null)
17601824 {
17611825 display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
....@@ -2051,7 +2115,7 @@
20512115 //System.err.println("Oeil on");
20522116 OEIL = true;
20532117 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2054
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2118
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
20552119 //pingthread.StepToTarget(true);
20562120 }
20572121
....@@ -2284,10 +2348,17 @@
22842348 HANDLES ^= true;
22852349 }
22862350
2351
+ Object3D paintFolder;
2352
+
22872353 void TogglePaint()
22882354 {
22892355 PAINTMODE ^= true;
22902356 paintcount = 0;
2357
+
2358
+ if (PAINTMODE)
2359
+ {
2360
+ paintFolder = GetFolder();
2361
+ }
22912362 }
22922363
22932364 void SwapCamera(int a, int b)
....@@ -2384,6 +2455,21 @@
23842455 return currentGL;
23852456 }
23862457
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
+
23872473 /**/
23882474 class CacheTexture
23892475 {
....@@ -2392,28 +2478,31 @@
23922478
23932479 int resolution;
23942480
2395
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2481
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
23962482 {
2397
- texture = tex;
2483
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2484
+ texturedata = texdata;
23982485 resolution = res;
23992486 }
24002487 }
24012488 /**/
24022489
24032490 // TEXTURE static Texture texture;
2404
- static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures
2405
- = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>();
2406
- 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
+
24072496 int pigmentdepth = 0;
24082497 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
24092498 int bumpdepth = 0;
24102499 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
24112500 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
24122501 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2413
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2502
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
24142503 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
24152504
2416
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2505
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
24172506 {
24182507 TextureData texturedata = null;
24192508
....@@ -2432,13 +2521,34 @@
24322521 if (bump)
24332522 texturedata = ConvertBump(texturedata, false);
24342523
2435
- com.sun.opengl.util.texture.Texture texture =
2436
- 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);
24372526
2438
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2439
- 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);
24402529
2441
- 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;
24422552 }
24432553
24442554 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3511,6 +3621,8 @@
35113621
35123622 System.out.println("LOADING TEXTURE : " + name);
35133623
3624
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3625
+
35143626 //
35153627 if (false) // compressbit > 0)
35163628 {
....@@ -7909,7 +8021,7 @@
79098021 String pigment = Object3D.GetPigment(tex);
79108022 String bump = Object3D.GetBump(tex);
79118023
7912
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8024
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79138025 {
79148026 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79158027 // System.out.println("; bump = " + bump);
....@@ -7924,8 +8036,8 @@
79248036 pigment = null;
79258037 }
79268038
7927
- ReleaseTexture(bump, true);
7928
- ReleaseTexture(pigment, false);
8039
+ ReleaseTexture(tex, true);
8040
+ ReleaseTexture(tex, false);
79298041 }
79308042
79318043 public void ReleasePigmentTexture(cTexture tex) // INTERFACE
....@@ -7943,7 +8055,7 @@
79438055
79448056 String pigment = Object3D.GetPigment(tex);
79458057
7946
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8058
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79478059 {
79488060 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79498061 // System.out.println("; bump = " + bump);
....@@ -7954,7 +8066,7 @@
79548066 pigment = null;
79558067 }
79568068
7957
- ReleaseTexture(pigment, false);
8069
+ ReleaseTexture(tex, false);
79588070 }
79598071
79608072 public void ReleaseBumpTexture(cTexture tex) // INTERFACE
....@@ -7972,7 +8084,7 @@
79728084
79738085 String bump = Object3D.GetBump(tex);
79748086
7975
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8087
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79768088 {
79778089 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79788090 // System.out.println("; bump = " + bump);
....@@ -7983,10 +8095,10 @@
79838095 bump = null;
79848096 }
79858097
7986
- ReleaseTexture(bump, true);
8098
+ ReleaseTexture(tex, true);
79878099 }
79888100
7989
- void ReleaseTexture(String tex, boolean bump)
8101
+ void ReleaseTexture(cTexture tex, boolean bump)
79908102 {
79918103 if (// DrawMode() != 0 || /*tex == null ||*/
79928104 ambientOcclusion ) // || !textureon)
....@@ -7997,7 +8109,7 @@
79978109 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
79988110
79998111 if (tex != null)
8000
- texture = textures.get(tex);
8112
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
80018113
80028114 // //assert( texture != null );
80038115 // if (texture == null)
....@@ -8091,47 +8203,50 @@
80918203
80928204 /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
80938205 {
8094
- if (// DrawMode() != 0 || /*tex == null ||*/
8095
- ambientOcclusion ) // || !textureon)
8096
- {
8097
- return; // false;
8098
- }
8099
-
8100
- if (tex == null)
8101
- {
8102
- BindTexture(null,false,resolution);
8103
- BindTexture(null,true,resolution);
8104
- return;
8105
- }
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;
81068247
8107
- String pigment = Object3D.GetPigment(tex);
8108
- String bump = Object3D.GetBump(tex);
8109
-
8110
- usedtextures.put(pigment, pigment);
8111
- usedtextures.put(bump, bump);
8112
-
8113
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8114
- {
8115
- // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8116
- // System.out.println("; bump = " + bump);
8117
- }
8118
-
8119
- if (bump.equals(""))
8120
- {
8121
- bump = null;
8122
- }
8123
- if (pigment.equals(""))
8124
- {
8125
- pigment = null;
8126
- }
8127
-
8128
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8129
- BindTexture(pigment, false, resolution);
8130
- GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8131
- BindTexture(bump, true, resolution);
8132
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8133
-
8134
- return; // true;
8248
+ BindPigmentTexture(tex, resolution);
8249
+ BindBumpTexture(tex, resolution);
81358250 }
81368251
81378252 /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8150,9 +8265,9 @@
81508265
81518266 String pigment = Object3D.GetPigment(tex);
81528267
8153
- usedtextures.put(pigment, pigment);
8268
+ usedtextures.add(tex);
81548269
8155
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8270
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
81568271 {
81578272 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
81588273 // System.out.println("; bump = " + bump);
....@@ -8164,7 +8279,7 @@
81648279 }
81658280
81668281 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8167
- BindTexture(pigment, false, resolution);
8282
+ BindTexture(tex, false, resolution);
81688283 }
81698284
81708285 /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8183,9 +8298,9 @@
81838298
81848299 String bump = Object3D.GetBump(tex);
81858300
8186
- usedtextures.put(bump, bump);
8301
+ usedtextures.add(tex);
81878302
8188
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8303
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
81898304 {
81908305 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
81918306 // System.out.println("; bump = " + bump);
....@@ -8197,7 +8312,7 @@
81978312 }
81988313
81998314 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8200
- BindTexture(bump, true, resolution);
8315
+ BindTexture(tex, true, resolution);
82018316 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
82028317 }
82038318
....@@ -8221,13 +8336,19 @@
82218336 return fileExists;
82228337 }
82238338
8224
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception
8339
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
82258340 {
8226
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8341
+ CacheTexture texturecache = null;
82278342
82288343 if (tex != null)
82298344 {
8230
- 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
+ }
82318352
82328353 String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
82338354
....@@ -8237,19 +8358,46 @@
82378358 // else
82388359 // if (!texname.startsWith("/"))
82398360 // texname = "/Users/nbriere/Textures/" + texname;
8240
- if (!FileExists(tex))
8361
+ if (!FileExists(texname))
82418362 {
82428363 texname = fallbackTextureName;
82438364 }
82448365
82458366 if (CACHETEXTURE)
8246
- texture = textures.get(texname); // TEXTURE CACHE
8247
-
8248
- TextureData texturedata = null;
8249
-
8250
- if (texture == null || texture.resolution < resolution)
82518367 {
8252
- 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(""))
82538401 {
82548402 assert(!bump);
82558403 // if (bump)
....@@ -8260,19 +8408,23 @@
82608408 // }
82618409 // else
82628410 // {
8263
- texture = textures.get(tex);
8264
- if (texture == null)
8411
+ // texturecache = textures.get(texname); // suspicious
8412
+ if (texturecache == null)
82658413 {
8266
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8414
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
82678415 }
8416
+ else
8417
+ new Exception().printStackTrace();
82688418 // }
82698419 } else
8270
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8420
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
82718421 {
82728422 assert(bump);
8273
- texture = textures.get(tex);
8274
- if (texture == null)
8275
- 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();
82768428 } else
82778429 {
82788430 //if (tex.equals("IMMORTAL"))
....@@ -8280,11 +8432,13 @@
82808432 // texture = GetResourceTexture("default.png");
82818433 //} else
82828434 //{
8283
- if (tex.equals("WHITE_NOISE"))
8435
+ if (texname.endsWith("WHITE_NOISE"))
82848436 {
8285
- texture = textures.get(tex);
8286
- if (texture == null)
8287
- 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();
82888442 } else
82898443 {
82908444 if (textureon)
....@@ -8343,19 +8497,19 @@
83438497 if (texturedata == null)
83448498 throw new Exception();
83458499
8346
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8500
+ texturecache = new CacheTexture(texturedata,resolution);
83478501 //texture = GetTexture(tex, bump);
83488502 }
83498503 }
83508504 //}
83518505 }
83528506
8353
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8507
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
83548508 {
83558509 //return false;
83568510
83578511 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8358
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8512
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
83598513 {
83608514 // String ext = "_highres";
83618515 // if (REDUCETEXTURE)
....@@ -8372,52 +8526,17 @@
83728526 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
83738527 if (!cachefile.exists())
83748528 {
8375
- // cache to disk
8376
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
8377
- //buffers[0].
8378
-
8379
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
8380
- int[] pixels = new int[bytebuf.capacity()/3];
8381
-
8382
- // squared size heuristic...
8383
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8529
+ //if (texturedata.getWidth() == texturedata.getHeight())
83848530 {
8385
- for (int i=pixels.length; --i>=0;)
8386
- {
8387
- int i3 = i*3;
8388
- pixels[i] = 0xFF;
8389
- pixels[i] <<= 8;
8390
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
8391
- pixels[i] <<= 8;
8392
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
8393
- pixels[i] <<= 8;
8394
- pixels[i] |= bytebuf.get(i3) & 0xFF;
8395
- }
8396
-
8397
- /*
8398
- int r=0,g=0,b=0,a=0;
8399
- for (int i=0; i<width; i++)
8400
- for (int j=0; j<height; j++)
8401
- {
8402
- int index = j*width+i;
8403
- int p = pixels[index];
8404
- a = ((p>>24) & 0xFF);
8405
- r = ((p>>16) & 0xFF);
8406
- g = ((p>>8) & 0xFF);
8407
- b = (p & 0xFF);
8408
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
8409
- }
8410
- /**/
8411
- int width = (int)Math.sqrt(pixels.length); // squared
8412
- int height = width;
8413
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
8414
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8531
+ BufferedImage rendImage = CreateBim(texturedata);
8532
+
84158533 ImageWriter writer = null;
84168534 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
84178535 if (iter.hasNext()) {
84188536 writer = (ImageWriter)iter.next();
84198537 }
8420
- float compressionQuality = 0.9f;
8538
+
8539
+ float compressionQuality = 0.85f;
84218540 try
84228541 {
84238542 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8434,18 +8553,20 @@
84348553 }
84358554 }
84368555 }
8437
-
8556
+
8557
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8558
+
84388559 //System.out.println("Texture = " + tex);
8439
- if (textures.containsKey(texname))
8560
+ if (textures.containsKey(tex))
84408561 {
8441
- CacheTexture thetex = textures.get(texname);
8562
+ CacheTexture thetex = textures.get(tex);
84428563 thetex.texture.disable();
84438564 thetex.texture.dispose();
8444
- textures.remove(texname);
8565
+ textures.remove(tex);
84458566 }
84468567
8447
- texture.texturedata = texturedata;
8448
- textures.put(texname, texture);
8568
+ //texture.texturedata = texturedata;
8569
+ textures.put(tex, texturecache);
84498570
84508571 // newtex = true;
84518572 }
....@@ -8461,10 +8582,44 @@
84618582 }
84628583 }
84638584
8464
- return texture;
8585
+ return texturecache;
84658586 }
84668587
8467
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution) throws Exception
8588
+ static void EmbedTextures(cTexture tex)
8589
+ {
8590
+ if (tex.pigmentdata == null)
8591
+ {
8592
+ //String texname = Object3D.GetPigment(tex);
8593
+
8594
+ CacheTexture texturecache = texturepigment.get(tex);
8595
+
8596
+ if (texturecache != null)
8597
+ {
8598
+ tex.pw = texturecache.texturedata.getWidth();
8599
+ tex.ph = texturecache.texturedata.getHeight();
8600
+ tex.pigmentdata = //CompressJPEG(CreateBim
8601
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8602
+ ;
8603
+ //, tex.pw, tex.ph), 0.5f);
8604
+ }
8605
+ }
8606
+
8607
+ if (tex.bumpdata == null)
8608
+ {
8609
+ //String texname = Object3D.GetBump(tex);
8610
+
8611
+ CacheTexture texturecache = texturebump.get(tex);
8612
+
8613
+ if (texturecache != null)
8614
+ {
8615
+ tex.bw = texturecache.texturedata.getWidth();
8616
+ tex.bh = texturecache.texturedata.getHeight();
8617
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8618
+ }
8619
+ }
8620
+ }
8621
+
8622
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
84688623 {
84698624 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
84708625
....@@ -8482,21 +8637,21 @@
84828637 return texture!=null?texture.texture:null;
84838638 }
84848639
8485
- public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution) throws Exception
8640
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
84868641 {
84878642 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
84888643
84898644 return texture!=null?texture.texturedata:null;
84908645 }
84918646
8492
- boolean BindTexture(String tex, boolean bump, int resolution) throws Exception
8647
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
84938648 {
84948649 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
84958650 {
84968651 return false;
84978652 }
84988653
8499
- boolean newtex = false;
8654
+ //boolean newtex = false;
85008655
85018656 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
85028657
....@@ -8528,9 +8683,75 @@
85288683 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
85298684 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
85308685
8531
- return newtex;
8686
+ return true; // Warning: not used.
85328687 }
85338688
8689
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8690
+ {
8691
+ try
8692
+ {
8693
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8694
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8695
+ ImageWriter writer = writers.next();
8696
+
8697
+ ImageWriteParam param = writer.getDefaultWriteParam();
8698
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8699
+ param.setCompressionQuality(quality);
8700
+
8701
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8702
+ writer.setOutput(ios);
8703
+ writer.write(null, new IIOImage(image, null, null), param);
8704
+
8705
+ byte[] data = baos.toByteArray();
8706
+ writer.dispose();
8707
+ return data;
8708
+ }
8709
+ catch (Exception e)
8710
+ {
8711
+ e.printStackTrace();
8712
+ return null;
8713
+ }
8714
+ }
8715
+
8716
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8717
+ {
8718
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8719
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8720
+ ImageReader reader = writers.next();
8721
+
8722
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8723
+
8724
+ ImageReadParam param = reader.getDefaultReadParam();
8725
+ param.setDestination(bim);
8726
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8727
+
8728
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8729
+ reader.setInput(ios);
8730
+ BufferedImage bim2 = reader.read(0, param);
8731
+ reader.dispose();
8732
+
8733
+// WritableRaster raster = bim2.getRaster();
8734
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8735
+// byte[] bytes = data.getData();
8736
+//
8737
+// int[] pixels = new int[bytes.length/3];
8738
+// for (int i=pixels.length; --i>=0;)
8739
+// {
8740
+// int i3 = i*3;
8741
+// pixels[i] = 0xFF;
8742
+// pixels[i] <<= 8;
8743
+// pixels[i] |= bytes[i3+2] & 0xFF;
8744
+// pixels[i] <<= 8;
8745
+// pixels[i] |= bytes[i3+1] & 0xFF;
8746
+// pixels[i] <<= 8;
8747
+// pixels[i] |= bytes[i3] & 0xFF;
8748
+// }
8749
+//
8750
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8751
+
8752
+ return bim;
8753
+ }
8754
+
85348755 ShadowBuffer shadowPBuf;
85358756 AntialiasBuffer antialiasPBuf;
85368757 int MAXSTACK;
....@@ -8723,7 +8944,7 @@
87238944
87248945 if (cubemap == null)
87258946 {
8726
- LoadEnvy(5);
8947
+ //LoadEnvy(1);
87278948 }
87288949
87298950 //cubemap.enable();
....@@ -9010,37 +9231,58 @@
90109231 cubemap = null;
90119232 return;
90129233 case 1:
9013
- name = "cubemaps/box_";
9014
- ext = "png";
9234
+ name = "cubemaps/rgb/";
9235
+ ext = "jpg";
90159236 reverseUP = false;
90169237 break;
90179238 case 2:
9018
- name = "cubemaps/uffizi_";
9019
- ext = "png";
9020
- break; // reverseUP = true; break;
9239
+ name = "cubemaps/uffizi/";
9240
+ ext = "jpg";
9241
+ reverseUP = false;
9242
+ break;
90219243 case 3:
9022
- name = "cubemaps/CloudyHills_";
9023
- ext = "tga";
9244
+ name = "cubemaps/CloudyHills/";
9245
+ ext = "jpg";
90249246 reverseUP = false;
90259247 break;
90269248 case 4:
9027
- name = "cubemaps/cornell_";
9249
+ name = "cubemaps/cornell/";
90289250 ext = "png";
90299251 reverseUP = false;
90309252 break;
9253
+ case 5:
9254
+ name = "cubemaps/skycube/";
9255
+ ext = "jpg";
9256
+ reverseUP = false;
9257
+ break;
9258
+ case 6:
9259
+ name = "cubemaps/SaintLazarusChurch3/";
9260
+ ext = "jpg";
9261
+ reverseUP = false;
9262
+ break;
9263
+ case 7:
9264
+ name = "cubemaps/Sodermalmsallen/";
9265
+ ext = "jpg";
9266
+ reverseUP = false;
9267
+ break;
9268
+ case 8:
9269
+ name = "cubemaps/Sodermalmsallen2/";
9270
+ ext = "jpg";
9271
+ reverseUP = false;
9272
+ break;
9273
+ case 9:
9274
+ name = "cubemaps/UnionSquare/";
9275
+ ext = "jpg";
9276
+ reverseUP = false;
9277
+ break;
90319278 default:
9032
- name = "cubemaps/rgb_";
9033
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9279
+ name = "cubemaps/box/";
9280
+ ext = "png"; /*mipmap = true;*/
9281
+ reverseUP = false;
90349282 break;
90359283 }
9036
-
9037
- try
9038
- {
9039
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
9040
- } catch (IOException e)
9041
- {
9042
- throw new RuntimeException(e);
9043
- }
9284
+
9285
+ LoadSkybox(name, ext, mipmap);
90449286 }
90459287
90469288 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -9072,8 +9314,13 @@
90729314 static double[] model = new double[16];
90739315 double[] camera2light = new double[16];
90749316 double[] light2camera = new double[16];
9075
- int newenvy = -1;
9317
+
9318
+ //int newenvy = -1;
90769319 boolean envyoff = true; // false;
9320
+ String skyboxname = "";
9321
+ String skyboxext;
9322
+ String loadedskyboxname = "";
9323
+
90779324 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
90789325 //float[] light0 = { 0,0,0 };
90799326 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9366,11 +9613,35 @@
93669613 jy8[3] = 0.5f;
93679614 }
93689615
9369
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9616
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
93709617 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
93719618 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
93729619 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
93739620
9621
+ void ResetOptions()
9622
+ {
9623
+ options1[0] = 100;
9624
+ options1[1] = 0.025f;
9625
+ options1[2] = 0.01f;
9626
+ options1[3] = 0;
9627
+ options1[4] = 0;
9628
+
9629
+ options2[0] = 0;
9630
+ options2[1] = 0.75f;
9631
+ options2[2] = 0;
9632
+ options2[3] = 0;
9633
+
9634
+ options3[0] = 1;
9635
+ options3[1] = 1;
9636
+ options3[2] = 1;
9637
+ options3[3] = 0;
9638
+
9639
+ options4[0] = 1;
9640
+ options4[1] = 0;
9641
+ options4[2] = 1;
9642
+ options4[3] = 0;
9643
+ }
9644
+
93749645 static int imagecount = 0; // movie generation
93759646
93769647 static int jitter = 0;
....@@ -9467,7 +9738,7 @@
94679738
94689739 if (renderCamera != lightCamera)
94699740 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9470
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
9741
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
94719742
94729743 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
94739744
....@@ -9483,7 +9754,7 @@
94839754
94849755 if (renderCamera != lightCamera)
94859756 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9486
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
9757
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
94879758
94889759 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
94899760
....@@ -9529,10 +9800,12 @@
95299800 rati = 1 / rati;
95309801 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
95319802 }
9532
- assert (newenvy == -1);
9803
+
9804
+ //assert (newenvy == -1);
9805
+
95339806 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
95349807 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9535
- DrawSkyBox(gl);
9808
+ DrawSkyBox(gl, (float)rati);
95369809 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
95379810 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
95389811 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10481,6 +10754,7 @@
1048110754 ANTIALIAS = 0;
1048210755 //System.out.println("RESTART");
1048310756 AAtimer.restart();
10757
+ Globals.TIMERRUNNING = true;
1048410758 }
1048510759 }
1048610760 }
....@@ -10548,7 +10822,8 @@
1054810822 ambientOcclusion = false;
1054910823 }
1055010824
10551
- if (Globals.lighttouched && DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
10825
+ if (//Globals.lighttouched &&
10826
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1055210827 {
1055310828 //if (RENDERSHADOW) // ?
1055410829 if (!IsFrozen())
....@@ -10682,7 +10957,7 @@
1068210957 // if (parentcam != renderCamera) // not a light
1068310958 if (cam != lightCamera)
1068410959 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10685
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
10960
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1068610961
1068710962 for (int j = 0; j < 4; j++)
1068810963 {
....@@ -10697,7 +10972,7 @@
1069710972 // if (parentcam != renderCamera) // not a light
1069810973 if (cam != lightCamera)
1069910974 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10700
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
10975
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1070110976
1070210977 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1070310978
....@@ -10783,13 +11058,19 @@
1078311058 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1078411059 }
1078511060
10786
- if (newenvy > -1)
11061
+// if (newenvy > -1)
11062
+// {
11063
+// LoadEnvy(newenvy);
11064
+// }
11065
+//
11066
+// newenvy = -1;
11067
+
11068
+ if (!skyboxname.equals(this.loadedskyboxname))
1078711069 {
10788
- LoadEnvy(newenvy);
11070
+ LoadSkybox(skyboxname + "/", skyboxext, false);
11071
+ loadedskyboxname = skyboxname;
1078911072 }
10790
-
10791
- newenvy = -1;
10792
-
11073
+
1079311074 ratio = ((double) getWidth()) / getHeight();
1079411075 //System.out.println("ratio = " + ratio);
1079511076
....@@ -10805,7 +11086,7 @@
1080511086
1080611087 if (!IsFrozen() && !ambientOcclusion)
1080711088 {
10808
- DrawSkyBox(gl);
11089
+ DrawSkyBox(gl, (float)ratio);
1080911090 }
1081011091
1081111092 //if (selection_view == -1)
....@@ -10988,9 +11269,9 @@
1098811269
1098911270 gl.glMatrixMode(GL.GL_MODELVIEW);
1099011271
10991
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10992
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10993
-//gl.glEnable(gl.GL_MULTISAMPLE);
11272
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11273
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11274
+gl.glEnable(gl.GL_MULTISAMPLE);
1099411275 } else
1099511276 {
1099611277 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -11001,7 +11282,7 @@
1100111282 //System.out.println("BLENDING ON");
1100211283 gl.glEnable(GL.GL_BLEND);
1100311284 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
11004
-
11285
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1100511286 gl.glMatrixMode(gl.GL_PROJECTION);
1100611287 gl.glLoadIdentity();
1100711288
....@@ -11250,7 +11531,7 @@
1125011531 }
1125111532 }
1125211533
11253
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11534
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1125411535 {
1125511536 //gl.glDepthFunc(GL.GL_LEQUAL);
1125611537 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11258,24 +11539,21 @@
1125811539
1125911540 boolean texon = textureon;
1126011541
11261
- if (RENDERPROGRAM > 0)
11262
- {
11263
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11264
- textureon = false;
11265
- }
11542
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11543
+ textureon = false;
11544
+
1126611545 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1126711546 //System.out.println("ALLO");
1126811547 gl.glColorMask(false, false, false, false);
1126911548 DrawObject(gl);
11270
- if (RENDERPROGRAM > 0)
11271
- {
11272
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11273
- textureon = texon;
11274
- }
11549
+
11550
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11551
+ textureon = texon;
11552
+
1127511553 gl.glColorMask(true, true, true, true);
1127611554
1127711555 gl.glDepthFunc(GL.GL_EQUAL);
11278
- //gl.glDepthMask(false);
11556
+ gl.glDepthMask(false);
1127911557 }
1128011558
1128111559 if (false) // DrawMode() == SHADOW)
....@@ -11458,7 +11736,7 @@
1145811736
1145911737 static boolean zoomonce = false;
1146011738
11461
- void CreateSelectedPoint()
11739
+ static void CreateSelectedPoint()
1146211740 {
1146311741 if (selectedpoint == null)
1146411742 {
....@@ -11478,13 +11756,16 @@
1147811756
1147911757 void DrawObject(GL gl, boolean draw)
1148011758 {
11759
+ // To clear camera values
11760
+ ResetOptions();
11761
+
1148111762 //System.out.println("DRAW OBJECT " + mouseDown);
1148211763 // DrawMode() = SELECTION;
1148311764 //GL gl = getGL();
1148411765 if ((TRACK || SHADOWTRACK) || zoomonce)
1148511766 {
1148611767 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11487
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11768
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1148811769 pingthread.StepToTarget(true); // true);
1148911770 // zoomonce = false;
1149011771 }
....@@ -11612,20 +11893,32 @@
1161211893 ReleaseTextures(DEFAULT_TEXTURES);
1161311894
1161411895 if (CLEANCACHE)
11615
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11896
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1161611897 {
11617
- String tex = e.nextElement();
11898
+ cTexture tex = e.nextElement();
1161811899
1161911900 // System.out.println("Texture --------- " + tex);
1162011901
11621
- if (tex.equals("WHITE_NOISE"))
11902
+ if (tex.equals("WHITE_NOISE:"))
1162211903 continue;
1162311904
11624
- if (!usedtextures.containsKey(tex))
11905
+ if (!usedtextures.contains(tex))
1162511906 {
11907
+ CacheTexture gettex = texturepigment.get(tex);
1162611908 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11627
- textures.get(tex).texture.dispose();
11628
- textures.remove(tex);
11909
+ if (gettex != null)
11910
+ {
11911
+ gettex.texture.dispose();
11912
+ texturepigment.remove(tex);
11913
+ }
11914
+
11915
+ gettex = texturebump.get(tex);
11916
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11917
+ if (gettex != null)
11918
+ {
11919
+ gettex.texture.dispose();
11920
+ texturebump.remove(tex);
11921
+ }
1162911922 }
1163011923 }
1163111924 }
....@@ -12045,7 +12338,7 @@
1204512338 for (int i = tp.size(); --i >= 0;)
1204612339 {
1204712340 //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12048
- LA.xformPos(light, tp.get(i).GlobalTransform(), light);
12341
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1204912342 }
1205012343
1205112344
....@@ -12153,8 +12446,76 @@
1215312446
1215412447 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1215512448
12449
+ String program0 =
12450
+ // Min shader
12451
+ "!!ARBfp1.0\n" +
12452
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12453
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12454
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12455
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12456
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12457
+ "PARAM light2cam0 = program.env[10];" +
12458
+ "PARAM light2cam1 = program.env[11];" +
12459
+ "PARAM light2cam2 = program.env[12];" +
12460
+ "TEMP temp;" +
12461
+ "TEMP light;" +
12462
+ "TEMP ndotl;" +
12463
+ "TEMP normal;" +
12464
+ "TEMP depth;" +
12465
+ "TEMP eye;" +
12466
+ "TEMP pos;" +
12467
+
12468
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12469
+ Normalize("normal") +
12470
+ "MOV light, state.light[0].position;" +
12471
+ "DP3 ndotl.x, light, normal;" +
12472
+
12473
+ // shadow
12474
+ "MOV pos, fragment.texcoord[1];" +
12475
+ "MOV temp, pos;" +
12476
+ ShadowTextureFetch("depth", "temp", "1") +
12477
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12478
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12479
+
12480
+ // No shadow when out of frustum
12481
+ //"SGE temp.y, depth.z, zero123.y;" +
12482
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12483
+
12484
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12485
+
12486
+ // Backlit
12487
+ "MOV pos.w, zero123.y;" +
12488
+ "DP4 eye.x, pos, light2cam0;" +
12489
+ "DP4 eye.y, pos, light2cam1;" +
12490
+ "DP4 eye.z, pos, light2cam2;" +
12491
+ Normalize("eye") +
12492
+
12493
+ "DP3 ndotl.y, -eye, normal;" +
12494
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12495
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12496
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12497
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12498
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12499
+
12500
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12501
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12502
+
12503
+ // Pigment
12504
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12505
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12506
+ "MUL temp, temp, ndotl.x;" +
12507
+
12508
+ "MUL temp, temp, zero123.z;" +
12509
+
12510
+ //"MUL temp, temp, ndotl.y;" +
12511
+
12512
+ "MOV temp.w, zero123.y;" + // reset alpha
12513
+ "MOV result.color, temp;" +
12514
+ "END";
12515
+
1215612516 String program =
1215712517 "!!ARBfp1.0\n" +
12518
+
1215812519 //"OPTION ARB_fragment_program_shadow;" +
1215912520 "PARAM light2cam0 = program.env[10];" +
1216012521 "PARAM light2cam1 = program.env[11];" +
....@@ -12269,8 +12630,7 @@
1226912630 "TEMP shininess;" +
1227012631 "\n" +
1227112632 "MOV texSamp, one;" +
12272
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12273
-
12633
+
1227412634 "MOV mapgrid.x, one2048th.x;" +
1227512635 "MOV temp, fragment.texcoord[1];" +
1227612636 /*
....@@ -12291,20 +12651,20 @@
1229112651 "MUL temp, floor, mapgrid.x;" +
1229212652 //"TEX depth0, temp, texture[1], 2D;" +
1229312653 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12294
- TextureFetch("depth0", "temp", "1") +
12654
+ ShadowTextureFetch("depth0", "temp", "1") +
1229512655 "") +
1229612656 "ADD temp.x, temp.x, mapgrid.x;" +
1229712657 //"TEX depth1, temp, texture[1], 2D;" +
1229812658 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12299
- TextureFetch("depth1", "temp", "1") +
12659
+ ShadowTextureFetch("depth1", "temp", "1") +
1230012660 "") +
1230112661 "ADD temp.y, temp.y, mapgrid.x;" +
1230212662 //"TEX depth2, temp, texture[1], 2D;" +
12303
- TextureFetch("depth2", "temp", "1") +
12663
+ ShadowTextureFetch("depth2", "temp", "1") +
1230412664 "SUB temp.x, temp.x, mapgrid.x;" +
1230512665 //"TEX depth3, temp, texture[1], 2D;" +
1230612666 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12307
- TextureFetch("depth3", "temp", "1") +
12667
+ ShadowTextureFetch("depth3", "temp", "1") +
1230812668 "") +
1230912669 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1231012670 //"MOV params, material;" +
....@@ -12675,7 +13035,7 @@
1267513035 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1267613036 "") +
1267713037
12678
- // display shadow only (bump == 0)
13038
+ // display shadow only (fakedepth == 0)
1267913039 "SUB temp.x, half.x, shadow.x;" +
1268013040 "MOV temp.y, -params5.z;" + // params6.x;" +
1268113041 "SLT temp.z, temp.y, -one2048th.x;" +
....@@ -13102,25 +13462,26 @@
1310213462 return out;
1310313463 }
1310413464
13105
- String TextureFetch(String dest, String src, String unit)
13465
+ // Also does frustum culling
13466
+ String ShadowTextureFetch(String dest, String src, String unit)
1310613467 {
1310713468 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1310813469 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1310913470 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13471
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13472
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1311013473 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13111
- "SLT " + src + ".z, " + src + ".x, one.x;" +
13112
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13113
- "SLT " + src + ".z, " + src + ".y, one.x;" +
13114
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13474
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13475
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1311513476 //"SWZ buffer, temp, w,w,w,w;";
13116
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13477
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1311713478 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1311813479 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1311913480 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13120
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13481
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1312113482
13122
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13123
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13483
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13484
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1312413485 }
1312513486
1312613487 String Shadow(String depth, String shadow)
....@@ -13167,7 +13528,7 @@
1316713528 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1316813529 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1316913530
13170
- // No shadow when out of frustrum
13531
+ // No shadow when out of frustum
1317113532 "SGE temp.x, " + depth + ".z, one.z;" +
1317213533 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1317313534 "";
....@@ -13315,7 +13676,8 @@
1331513676 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1331613677 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1331713678 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13318
- Object3D.cVector2[] vector2buffer;
13679
+
13680
+ //Object3D.cVector2[] vector2buffer;
1331913681
1332013682 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1332113683 // OUT : diff, spec
....@@ -13331,9 +13693,10 @@
1333113693 "DP3 " + dest + ".z," + "normals," + "eye;" +
1333213694 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1333313695 //"MOV " + dest + ".w," + "normal.z;" +
13334
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
13335
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13336
- //"MOV " + dest + ".z," + "params2.w;" +
13696
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13697
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13698
+
13699
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1333713700 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1333813701 "RCP " + dest + ".w," + dest + ".w;" +
1333913702 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13838,6 +14201,7 @@
1383814201 else
1383914202 if (evt.getSource() == AAtimer)
1384014203 {
14204
+ Globals.TIMERRUNNING = false;
1384114205 if (mouseDown)
1384214206 {
1384314207 //new Exception().printStackTrace();
....@@ -13897,7 +14261,7 @@
1389714261
1389814262 // fev 2014???
1389914263 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13900
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14264
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1390114265 pingthread.StepToTarget(true); // true);
1390214266 }
1390314267 // if (!LIVE)
....@@ -13912,6 +14276,7 @@
1391214276 return;
1391314277
1391414278 AAtimer.restart(); //
14279
+ Globals.TIMERRUNNING = true;
1391514280
1391614281 // waslive = LIVE;
1391714282 // LIVE = false;
....@@ -13961,14 +14326,15 @@
1396114326 drag = false;
1396214327 //System.out.println("Mouse DOWN");
1396314328 editObj = false;
13964
- ClickInfo info = new ClickInfo();
13965
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
13966
- info.pane = this;
13967
- info.camera = renderCamera;
13968
- info.x = x;
13969
- info.y = y;
13970
- info.modifiers = modifiersex;
13971
- editObj = object.doEditClick(info, 0);
14329
+ //ClickInfo info = new ClickInfo();
14330
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14331
+ object.clickInfo.pane = this;
14332
+ object.clickInfo.camera = renderCamera;
14333
+ object.clickInfo.x = x;
14334
+ object.clickInfo.y = y;
14335
+ object.clickInfo.modifiers = modifiersex;
14336
+ editObj = object.doEditClick(//info,
14337
+ 0);
1397214338 if (!editObj)
1397314339 {
1397414340 hasMarquee = true;
....@@ -14250,12 +14616,12 @@
1425014616 void GoDown(int mod)
1425114617 {
1425214618 MODIFIERS |= COMMAND;
14253
- /*
14619
+ /**/
1425414620 if((mod&SHIFT) == SHIFT)
1425514621 manipCamera.RotatePosition(0, -speed);
1425614622 else
14257
- manipCamera.BackForth(0, -speed*delta, getWidth());
14258
- */
14623
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14624
+ /**/
1425914625 if ((mod & SHIFT) == SHIFT)
1426014626 {
1426114627 mouseMode = mouseMode; // VR??
....@@ -14271,12 +14637,12 @@
1427114637 void GoUp(int mod)
1427214638 {
1427314639 MODIFIERS |= COMMAND;
14274
- /*
14640
+ /**/
1427514641 if((mod&SHIFT) == SHIFT)
1427614642 manipCamera.RotatePosition(0, speed);
1427714643 else
14278
- manipCamera.BackForth(0, speed*delta, getWidth());
14279
- */
14644
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14645
+ /**/
1428014646 if ((mod & SHIFT) == SHIFT)
1428114647 {
1428214648 mouseMode = mouseMode;
....@@ -14292,12 +14658,12 @@
1429214658 void GoLeft(int mod)
1429314659 {
1429414660 MODIFIERS |= COMMAND;
14295
- /*
14661
+ /**/
1429614662 if((mod&SHIFT) == SHIFT)
14297
- manipCamera.RotatePosition(speed, 0);
14298
- else
1429914663 manipCamera.Translate(speed*delta, 0, getWidth());
14300
- */
14664
+ else
14665
+ manipCamera.RotatePosition(speed, 0);
14666
+ /**/
1430114667 if ((mod & SHIFT) == SHIFT)
1430214668 {
1430314669 mouseMode = mouseMode;
....@@ -14313,12 +14679,12 @@
1431314679 void GoRight(int mod)
1431414680 {
1431514681 MODIFIERS |= COMMAND;
14316
- /*
14682
+ /**/
1431714683 if((mod&SHIFT) == SHIFT)
14318
- manipCamera.RotatePosition(-speed, 0);
14319
- else
1432014684 manipCamera.Translate(-speed*delta, 0, getWidth());
14321
- */
14685
+ else
14686
+ manipCamera.RotatePosition(-speed, 0);
14687
+ /**/
1432214688 if ((mod & SHIFT) == SHIFT)
1432314689 {
1432414690 mouseMode = mouseMode;
....@@ -14368,14 +14734,16 @@
1436814734 if (editObj)
1436914735 {
1437014736 drag = true;
14371
- ClickInfo info = new ClickInfo();
14372
- info.bounds.setBounds(0, 0,
14737
+ //ClickInfo info = new ClickInfo();
14738
+ object.clickInfo.bounds.setBounds(0, 0,
1437314739 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14374
- info.pane = this;
14375
- info.camera = renderCamera;
14376
- info.x = x;
14377
- info.y = y;
14378
- object.editWindow.copy.doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
14740
+ object.clickInfo.pane = this;
14741
+ object.clickInfo.camera = renderCamera;
14742
+ object.clickInfo.x = x;
14743
+ object.clickInfo.y = y;
14744
+ object //.GetWindow().copy
14745
+ .doEditDrag(//info,
14746
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1437914747 } else
1438014748 {
1438114749 if (x < startX)
....@@ -14524,22 +14892,27 @@
1452414892 }
1452514893 }
1452614894
14895
+// ClickInfo clickInfo = new ClickInfo();
14896
+
1452714897 public void mouseMoved(MouseEvent e)
1452814898 {
1452914899 //System.out.println("mouseMoved: " + e);
1453014900 if (isRenderer)
1453114901 return;
1453214902
14533
- ClickInfo ci = new ClickInfo();
14534
- ci.x = e.getX();
14535
- ci.y = e.getY();
14536
- ci.modifiers = e.getModifiersEx();
14537
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14538
- ci.pane = this;
14539
- ci.camera = renderCamera;
14903
+ // Mouse cursor feedback
14904
+ object.clickInfo.x = e.getX();
14905
+ object.clickInfo.y = e.getY();
14906
+ object.clickInfo.modifiers = e.getModifiersEx();
14907
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14908
+ object.clickInfo.pane = this;
14909
+ object.clickInfo.camera = renderCamera;
1454014910 if (!isRenderer)
1454114911 {
14542
- if (object.editWindow.copy.doEditClick(ci, 0))
14912
+ //ObjEditor editWindow = object.editWindow;
14913
+ //Object3D copy = editWindow.copy;
14914
+ if (object.doEditClick(//clickInfo,
14915
+ 0))
1454314916 {
1454414917 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1454514918 } else
....@@ -14554,7 +14927,8 @@
1455414927 Globals.MOUSEDRAGGED = false;
1455514928
1455614929 movingcamera = false;
14557
- X = Y = 0;
14930
+ X = 0; // getBounds().width/2;
14931
+ Y = 0; // getBounds().height/2;
1455814932 //System.out.println("mouseReleased: " + e);
1455914933 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1456014934 }
....@@ -14810,7 +15184,8 @@
1481015184 // break;
1481115185 case 'T':
1481215186 CACHETEXTURE ^= true;
14813
- textures.clear();
15187
+ texturepigment.clear();
15188
+ texturebump.clear();
1481415189 // repaint();
1481515190 break;
1481615191 case 'Y':
....@@ -14895,7 +15270,9 @@
1489515270 case 'E' : COMPACT ^= true;
1489615271 repaint();
1489715272 break;
14898
- case 'W' : DEBUGHSB ^= true;
15273
+ case 'W' : // Wide Window (fullscreen)
15274
+ //DEBUGHSB ^= true;
15275
+ ObjEditor.theFrame.ToggleFullScreen();
1489915276 repaint();
1490015277 break;
1490115278 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14921,13 +15298,7 @@
1492115298 repaint();
1492215299 break;
1492315300 case 'l':
14924
- lightMode ^= true;
14925
- Globals.lighttouched = true;
14926
- manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
14927
- targetLookAt.set(manipCamera.lookAt);
14928
- repaint();
14929
- break;
14930
- case 'L':
15301
+ //case 'L':
1493115302 if (lightMode)
1493215303 {
1493315304 lightMode = false;
....@@ -14997,14 +15368,18 @@
1499715368 case '3':
1499815369 case '4':
1499915370 case '5':
15000
- newenvy = Character.getNumericValue(key);
15001
- repaint();
15002
- break;
1500315371 case '6':
1500415372 case '7':
1500515373 case '8':
1500615374 case '9':
15007
- BGcolor = (key - '6')/3.f;
15375
+ if (envyoff)
15376
+ {
15377
+ BGcolor = (key - '1')/8.f;
15378
+ }
15379
+ else
15380
+ {
15381
+ //newenvy = Character.getNumericValue(key);
15382
+ }
1500815383 repaint();
1500915384 break;
1501015385 case '!':
....@@ -15070,11 +15445,14 @@
1507015445 case '_':
1507115446 kompactbit = 5;
1507215447 break;
15073
- case '+':
15074
- kompactbit = 6;
15075
- break;
15448
+// case '+':
15449
+// kompactbit = 6;
15450
+// break;
1507615451 case ' ':
15077
- ObjEditor.theFrame.ToggleFullScreen();
15452
+ lightMode ^= true;
15453
+ Globals.lighttouched = true;
15454
+ manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
15455
+ targetLookAt.set(manipCamera.lookAt);
1507815456 repaint();
1507915457 break;
1508015458 //case '`' :
....@@ -15121,8 +15499,9 @@
1512115499 case DELETE:
1512215500 ClearSelection();
1512315501 break;
15124
- /*
1512515502 case '+':
15503
+
15504
+ /*
1512615505 //fontsize += 1;
1512715506 bbzoom *= 2;
1512815507 repaint();
....@@ -15139,17 +15518,17 @@
1513915518 case '=':
1514015519 IncDepth();
1514115520 //fontsize += 1;
15142
- object.editWindow.refreshContents(true);
15521
+ object.GetWindow().refreshContents(true);
1514315522 maskbit = 6;
1514415523 break;
1514515524 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1514615525 DecDepth();
1514715526 maskbit = 5;
1514815527 //if(fontsize > 1) fontsize -= 1;
15149
- if (object.editWindow == null)
15150
- new Exception().printStackTrace();
15151
- else
15152
- object.editWindow.refreshContents(true);
15528
+// if (object.editWindow == null)
15529
+// new Exception().printStackTrace();
15530
+// else
15531
+ object.GetWindow().refreshContents(true);
1515315532 break;
1515415533 case '{':
1515515534 manipCamera.shaper_fovy /= 1.1;
....@@ -15373,7 +15752,7 @@
1537315752 }
1537415753 */
1537515754
15376
- object.editWindow.EditSelection();
15755
+ object.GetWindow().EditSelection(false);
1537715756 }
1537815757
1537915758 void SelectParent()
....@@ -15390,10 +15769,10 @@
1539015769 {
1539115770 //selectees.remove(i);
1539215771 System.out.println("select parent of " + elem);
15393
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15772
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1539415773 } else
1539515774 {
15396
- group.editWindow.Select(elem.GetTreePath(), first, true);
15775
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1539715776 }
1539815777
1539915778 first = false;
....@@ -15435,12 +15814,12 @@
1543515814 for (int j = 0; j < group.children.size(); j++)
1543615815 {
1543715816 elem = (Object3D) group.children.elementAt(j);
15438
- object.editWindow.Select(elem.GetTreePath(), first, true);
15817
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1543915818 first = false;
1544015819 }
1544115820 } else
1544215821 {
15443
- object.editWindow.Select(elem.GetTreePath(), first, true);
15822
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1544415823 }
1544515824
1544615825 first = false;
....@@ -15451,21 +15830,21 @@
1545115830 {
1545215831 //Composite group = (Composite) object;
1545315832 Object3D group = object;
15454
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15833
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1545515834 }
1545615835
1545715836 void ResetTransform(int mask)
1545815837 {
1545915838 //Composite group = (Composite) object;
1546015839 Object3D group = object;
15461
- group.editWindow.ResetTransform(mask);
15840
+ group.GetWindow().ResetTransform(mask);
1546215841 }
1546315842
1546415843 void FlipTransform()
1546515844 {
1546615845 //Composite group = (Composite) object;
1546715846 Object3D group = object;
15468
- group.editWindow.FlipTransform();
15847
+ group.GetWindow().FlipTransform();
1546915848 // group.editWindow.ReduceMesh(true);
1547015849 }
1547115850
....@@ -15473,7 +15852,7 @@
1547315852 {
1547415853 //Composite group = (Composite) object;
1547515854 Object3D group = object;
15476
- group.editWindow.PrintMemory();
15855
+ group.GetWindow().PrintMemory();
1547715856 // group.editWindow.ReduceMesh(true);
1547815857 }
1547915858
....@@ -15481,7 +15860,7 @@
1548115860 {
1548215861 //Composite group = (Composite) object;
1548315862 Object3D group = object;
15484
- group.editWindow.ResetCentroid();
15863
+ group.GetWindow().ResetCentroid();
1548515864 }
1548615865
1548715866 void IncDepth()
....@@ -15563,8 +15942,6 @@
1556315942
1556415943 int width = getBounds().width;
1556515944 int height = getBounds().height;
15566
- ClickInfo info = new ClickInfo();
15567
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1556815945 //Image img = CreateImage(width, height);
1556915946 //System.out.println("width = " + width + "; height = " + height + "\n");
1557015947
....@@ -15641,48 +16018,77 @@
1564116018 }
1564216019 if (object != null && !hasMarquee)
1564316020 {
16021
+ if (object.clickInfo == null)
16022
+ object.clickInfo = new ClickInfo();
16023
+ ClickInfo info = object.clickInfo;
16024
+ //ClickInfo info = new ClickInfo();
16025
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16026
+
1564416027 if (isRenderer)
1564516028 {
15646
- info.flags++;
16029
+ object.clickInfo.flags++;
1564716030 double frameAspect = (double) width / (double) height;
1564816031 if (frameAspect > renderCamera.aspect)
1564916032 {
1565016033 int desired = (int) ((double) height * renderCamera.aspect);
15651
- info.bounds.width -= width - desired;
15652
- info.bounds.x += (width - desired) / 2;
16034
+ object.clickInfo.bounds.width -= width - desired;
16035
+ object.clickInfo.bounds.x += (width - desired) / 2;
1565316036 } else
1565416037 {
1565516038 int desired = (int) ((double) width / renderCamera.aspect);
15656
- info.bounds.height -= height - desired;
15657
- info.bounds.y += (height - desired) / 2;
16039
+ object.clickInfo.bounds.height -= height - desired;
16040
+ object.clickInfo.bounds.y += (height - desired) / 2;
1565816041 }
1565916042 }
15660
- info.g = gr;
15661
- info.camera = renderCamera;
16043
+
16044
+ object.clickInfo.g = gr;
16045
+ object.clickInfo.camera = renderCamera;
1566216046 /*
1566316047 // Memory intensive (brep.verticescopy)
1566416048 if (!(object instanceof Composite))
1566516049 object.draw(info, 0, false); // SLOW :
1566616050 */
15667
- if (!isRenderer)
16051
+ if (!isRenderer) // && drag)
1566816052 {
15669
- object.drawEditHandles(info, 0);
15670
-
15671
- if (drag && (X != 0 || Y != 0) && object.selection.Size() > 0)
16053
+ Grafreed.Assert(object != null);
16054
+ Grafreed.Assert(object.selection != null);
16055
+ if (object.selection.Size() > 0)
1567216056 {
15673
- switch (object.selection.get(0).hitSomething)
16057
+ int hitSomething = object.selection.get(0).hitSomething;
16058
+
16059
+ object.clickInfo.DX = 0;
16060
+ object.clickInfo.DY = 0;
16061
+ object.clickInfo.W = 1;
16062
+ if (hitSomething == Object3D.hitCenter)
1567416063 {
15675
- case Object3D.hitCenter: gr.setColor(Color.pink);
15676
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15677
- break;
15678
- case Object3D.hitRotate: gr.setColor(Color.yellow);
15679
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15680
- break;
15681
- case Object3D.hitScale: gr.setColor(Color.cyan);
15682
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15683
- break;
16064
+ info.DX = X;
16065
+ if (X != 0)
16066
+ info.DX -= info.bounds.width/2;
16067
+
16068
+ info.DY = Y;
16069
+ if (Y != 0)
16070
+ info.DY -= info.bounds.height/2;
1568416071 }
15685
-
16072
+
16073
+ object.drawEditHandles(//info,
16074
+ 0);
16075
+
16076
+ if (drag && (X != 0 || Y != 0))
16077
+ {
16078
+ switch (hitSomething)
16079
+ {
16080
+ case Object3D.hitCenter: gr.setColor(Color.pink);
16081
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16082
+ break;
16083
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16084
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16085
+ break;
16086
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16087
+ gr.drawLine(X, Y, 0, 0);
16088
+ break;
16089
+ }
16090
+
16091
+ }
1568616092 }
1568716093 }
1568816094 }
....@@ -16196,7 +16602,9 @@
1619616602
1619716603 float BGcolor = 0.5f;
1619816604
16199
- private void DrawSkyBox(GL gl)
16605
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16606
+
16607
+ private void DrawSkyBox(GL gl, float ratio)
1620016608 {
1620116609 if (envyoff || cubemap == null)
1620216610 {
....@@ -16213,7 +16621,17 @@
1621316621 // Compensates for ExaminerViewer's modification of modelview matrix
1621416622 gl.glMatrixMode(GL.GL_MODELVIEW);
1621516623 gl.glLoadIdentity();
16624
+ gl.glScalef(1,ratio,1);
1621616625
16626
+ colorV[0] = 2;
16627
+ colorV[1] = 2;
16628
+ colorV[2] = 2;
16629
+ colorV[3] = 1;
16630
+ gl.glDisable(gl.GL_COLOR_MATERIAL);
16631
+ gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16632
+
16633
+ gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16634
+
1621716635 //gl.glActiveTexture(GL.GL_TEXTURE1);
1621816636 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1621916637
....@@ -16226,7 +16644,7 @@
1622616644 // GL_NORMAL_MAP texgen mode. Temporarily enabling lighting
1622716645 // causes the normals to be sent down. Thanks to Ken Dyke.
1622816646 //gl.glEnable(GL.GL_LIGHTING);
16229
- gl.glDisable(GL.GL_LIGHTING);
16647
+ gl.glEnable(GL.GL_LIGHTING);
1623016648
1623116649 gl.glTexGeni(GL.GL_S, GL.GL_TEXTURE_GEN_MODE, GL.GL_NORMAL_MAP);
1623216650 gl.glTexGeni(GL.GL_T, GL.GL_TEXTURE_GEN_MODE, GL.GL_NORMAL_MAP);
....@@ -16385,16 +16803,16 @@
1638516803 cStatic.objectstack[materialdepth++] = checker;
1638616804 //System.out.println("material " + material);
1638716805 //Applet3D.tracein(this, selected);
16388
- vector2buffer = checker.projectedVertices;
16806
+ //vector2buffer = checker.projectedVertices;
1638916807
1639016808 //checker.GetMaterial().Draw(this, false); // true);
16391
- DrawMaterial(checker.GetMaterial(), false); // true);
16809
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1639216810
1639316811 materialdepth -= 1;
1639416812 if (materialdepth > 0)
1639516813 {
16396
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16397
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
16814
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16815
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1639816816 }
1639916817 //checker.GetMaterial().opacity = 1f;
1640016818 ////checker.GetMaterial().ambient = 1f;
....@@ -16480,6 +16898,14 @@
1648016898 }
1648116899 }
1648216900
16901
+ private Object3D GetFolder()
16902
+ {
16903
+ Object3D folder = object.GetWindow().copy;
16904
+ if (object.GetWindow().copy.selection.Size() > 0)
16905
+ folder = object.GetWindow().copy.selection.elementAt(0);
16906
+ return folder;
16907
+ }
16908
+
1648316909 class SelectBuffer implements GLEventListener
1648416910 {
1648516911
....@@ -16495,7 +16921,7 @@
1649516921 //new Exception().printStackTrace();
1649616922 System.out.println("select buffer init");
1649716923 // Use debug pipeline
16498
- drawable.setGL(new DebugGL(drawable.getGL()));
16924
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1649916925
1650016926 GL gl = drawable.getGL();
1650116927
....@@ -16559,6 +16985,17 @@
1655916985
1656016986 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1656116987
16988
+ if (PAINTMODE)
16989
+ {
16990
+ if (object.GetWindow().copy.selection.Size() > 0)
16991
+ {
16992
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16993
+
16994
+ // Make what you paint not selectable.
16995
+ paintobj.ResetSelectable();
16996
+ }
16997
+ }
16998
+
1656216999 //int tmp = selection_view;
1656317000 //selection_view = -1;
1656417001 int temp = DrawMode();
....@@ -16570,6 +17007,17 @@
1657017007 // temp = DEFAULT; // patch for selection debug
1657117008 Globals.drawMode = temp; // WARNING
1657217009
17010
+ if (PAINTMODE)
17011
+ {
17012
+ if (object.GetWindow().copy.selection.Size() > 0)
17013
+ {
17014
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17015
+
17016
+ // Revert.
17017
+ paintobj.RestoreSelectable();
17018
+ }
17019
+ }
17020
+
1657317021 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1657417022
1657517023 // trying different ways of getting the depth info over
....@@ -16617,6 +17065,8 @@
1661717065 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1661817066 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1661917067 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
17068
+
17069
+ CreateSelectedPoint();
1662017070
1662117071 // Will fit the mesh !!!
1662217072 selectedpoint.toParent[0][0] = 0.0001;
....@@ -16671,29 +17121,31 @@
1667117121 }
1667217122
1667317123 if (!movingcamera && !PAINTMODE)
16674
- object.editWindow.ScreenFitPoint(); // fev 2014
17124
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1667517125
16676
- if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17126
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1667717127 {
16678
- Object3D paintobj = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17128
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1667917129
16680
- Object3D group = new Object3D("inst" + paintcount++);
17130
+ if (object.GetWindow().copy.selection.Size() > 0)
17131
+ {
17132
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1668117133
16682
- group.CreateMaterial(); // use a void leaf to select instances
16683
-
16684
- group.add(paintobj); // link
16685
-
16686
- object.editWindow.SnapObject(group);
16687
-
16688
- Object3D folder = object.editWindow.copy;
16689
-
16690
- if (object.editWindow.copy.selection.Size() > 0)
16691
- folder = object.editWindow.copy.selection.elementAt(0);
16692
-
16693
- folder.add(group);
16694
-
16695
- object.editWindow.ResetModel();
16696
- object.editWindow.refreshContents();
17134
+ Object3D inst = new Object3D("inst" + paintcount++);
17135
+
17136
+ inst.CreateMaterial(); // use a void leaf to select instances
17137
+
17138
+ inst.add(paintobj); // link
17139
+
17140
+ object.GetWindow().SnapObject(inst);
17141
+
17142
+ Object3D folder = paintFolder; // GetFolder();
17143
+
17144
+ folder.add(inst);
17145
+
17146
+ object.GetWindow().ResetModel();
17147
+ object.GetWindow().refreshContents();
17148
+ }
1669717149 }
1669817150 else
1669917151 paintcount = 0;
....@@ -16732,6 +17184,11 @@
1673217184 //System.out.println("objects[color] = " + objects[color]);
1673317185 //objects[color].Select();
1673417186 indexcount = 0;
17187
+ ObjEditor window = object.GetWindow();
17188
+ if (window != null && deselect)
17189
+ {
17190
+ window.Select(null, deselect, true);
17191
+ }
1673517192 object.Select(color, deselect);
1673617193 }
1673717194