Normand Briere
2019-08-12 b1d79b74514041a059b454a9f6fc3970773c0cb8
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
....@@ -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;
....@@ -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 {
....@@ -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) && !texname.startsWith("@"))
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,22 @@
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();
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();
82888451 } else
82898452 {
82908453 if (textureon)
....@@ -8343,19 +8506,20 @@
83438506 if (texturedata == null)
83448507 throw new Exception();
83458508
8346
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8509
+ texturecache = new CacheTexture(texturedata,resolution);
83478510 //texture = GetTexture(tex, bump);
83488511 }
8512
+ }
83498513 }
83508514 //}
83518515 }
83528516
8353
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8517
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
83548518 {
83558519 //return false;
83568520
83578521 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8358
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8522
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
83598523 {
83608524 // String ext = "_highres";
83618525 // if (REDUCETEXTURE)
....@@ -8372,52 +8536,17 @@
83728536 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
83738537 if (!cachefile.exists())
83748538 {
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))
8539
+ //if (texturedata.getWidth() == texturedata.getHeight())
83848540 {
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);
8541
+ BufferedImage rendImage = CreateBim(texturedata);
8542
+
84158543 ImageWriter writer = null;
84168544 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
84178545 if (iter.hasNext()) {
84188546 writer = (ImageWriter)iter.next();
84198547 }
8420
- float compressionQuality = 0.9f;
8548
+
8549
+ float compressionQuality = 0.85f;
84218550 try
84228551 {
84238552 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8434,18 +8563,20 @@
84348563 }
84358564 }
84368565 }
8437
-
8566
+
8567
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8568
+
84388569 //System.out.println("Texture = " + tex);
8439
- if (textures.containsKey(texname))
8570
+ if (textures.containsKey(tex))
84408571 {
8441
- CacheTexture thetex = textures.get(texname);
8572
+ CacheTexture thetex = textures.get(tex);
84428573 thetex.texture.disable();
84438574 thetex.texture.dispose();
8444
- textures.remove(texname);
8575
+ textures.remove(tex);
84458576 }
84468577
8447
- texture.texturedata = texturedata;
8448
- textures.put(texname, texture);
8578
+ //texture.texturedata = texturedata;
8579
+ textures.put(tex, texturecache);
84498580
84508581 // newtex = true;
84518582 }
....@@ -8461,10 +8592,44 @@
84618592 }
84628593 }
84638594
8464
- return texture;
8595
+ return texturecache;
84658596 }
84668597
8467
- 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
84688633 {
84698634 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
84708635
....@@ -8482,21 +8647,21 @@
84828647 return texture!=null?texture.texture:null;
84838648 }
84848649
8485
- 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
84868651 {
84878652 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
84888653
84898654 return texture!=null?texture.texturedata:null;
84908655 }
84918656
8492
- boolean BindTexture(String tex, boolean bump, int resolution) throws Exception
8657
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
84938658 {
84948659 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
84958660 {
84968661 return false;
84978662 }
84988663
8499
- boolean newtex = false;
8664
+ //boolean newtex = false;
85008665
85018666 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
85028667
....@@ -8528,9 +8693,75 @@
85288693 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
85298694 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
85308695
8531
- return newtex;
8696
+ return true; // Warning: not used.
85328697 }
85338698
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
+
85348765 ShadowBuffer shadowPBuf;
85358766 AntialiasBuffer antialiasPBuf;
85368767 int MAXSTACK;
....@@ -8723,7 +8954,7 @@
87238954
87248955 if (cubemap == null)
87258956 {
8726
- LoadEnvy(5);
8957
+ //LoadEnvy(1);
87278958 }
87288959
87298960 //cubemap.enable();
....@@ -9010,37 +9241,58 @@
90109241 cubemap = null;
90119242 return;
90129243 case 1:
9013
- name = "cubemaps/box_";
9014
- ext = "png";
9244
+ name = "cubemaps/rgb/";
9245
+ ext = "jpg";
90159246 reverseUP = false;
90169247 break;
90179248 case 2:
9018
- name = "cubemaps/uffizi_";
9019
- ext = "png";
9020
- break; // reverseUP = true; break;
9249
+ name = "cubemaps/uffizi/";
9250
+ ext = "jpg";
9251
+ reverseUP = false;
9252
+ break;
90219253 case 3:
9022
- name = "cubemaps/CloudyHills_";
9023
- ext = "tga";
9254
+ name = "cubemaps/CloudyHills/";
9255
+ ext = "jpg";
90249256 reverseUP = false;
90259257 break;
90269258 case 4:
9027
- name = "cubemaps/cornell_";
9259
+ name = "cubemaps/cornell/";
90289260 ext = "png";
90299261 reverseUP = false;
90309262 break;
9263
+ case 5:
9264
+ name = "cubemaps/skycube/";
9265
+ ext = "jpg";
9266
+ reverseUP = false;
9267
+ break;
9268
+ case 6:
9269
+ name = "cubemaps/SaintLazarusChurch3/";
9270
+ ext = "jpg";
9271
+ reverseUP = false;
9272
+ break;
9273
+ case 7:
9274
+ name = "cubemaps/Sodermalmsallen/";
9275
+ ext = "jpg";
9276
+ reverseUP = false;
9277
+ break;
9278
+ case 8:
9279
+ name = "cubemaps/Sodermalmsallen2/";
9280
+ ext = "jpg";
9281
+ reverseUP = false;
9282
+ break;
9283
+ case 9:
9284
+ name = "cubemaps/UnionSquare/";
9285
+ ext = "jpg";
9286
+ reverseUP = false;
9287
+ break;
90319288 default:
9032
- name = "cubemaps/rgb_";
9033
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9289
+ name = "cubemaps/box/";
9290
+ ext = "png"; /*mipmap = true;*/
9291
+ reverseUP = false;
90349292 break;
90359293 }
9036
-
9037
- try
9038
- {
9039
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
9040
- } catch (IOException e)
9041
- {
9042
- throw new RuntimeException(e);
9043
- }
9294
+
9295
+ LoadSkybox(name, ext, mipmap);
90449296 }
90459297
90469298 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -9072,8 +9324,12 @@
90729324 static double[] model = new double[16];
90739325 double[] camera2light = new double[16];
90749326 double[] light2camera = new double[16];
9075
- int newenvy = -1;
9076
- boolean envyoff = true; // false;
9327
+
9328
+ //int newenvy = -1;
9329
+ //boolean envyoff = false;
9330
+
9331
+ String loadedskyboxname;
9332
+
90779333 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
90789334 //float[] light0 = { 0,0,0 };
90799335 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9366,11 +9622,35 @@
93669622 jy8[3] = 0.5f;
93679623 }
93689624
9369
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9625
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
93709626 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
93719627 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
93729628 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
93739629
9630
+ void ResetOptions()
9631
+ {
9632
+ options1[0] = 100;
9633
+ options1[1] = 0.025f;
9634
+ options1[2] = 0.01f;
9635
+ options1[3] = 0;
9636
+ options1[4] = 0;
9637
+
9638
+ options2[0] = 0;
9639
+ options2[1] = 0.75f;
9640
+ options2[2] = 0;
9641
+ options2[3] = 0;
9642
+
9643
+ options3[0] = 1;
9644
+ options3[1] = 1;
9645
+ options3[2] = 1;
9646
+ options3[3] = 0;
9647
+
9648
+ options4[0] = 1;
9649
+ options4[1] = 0;
9650
+ options4[2] = 1;
9651
+ options4[3] = 0;
9652
+ }
9653
+
93749654 static int imagecount = 0; // movie generation
93759655
93769656 static int jitter = 0;
....@@ -9467,7 +9747,7 @@
94679747
94689748 if (renderCamera != lightCamera)
94699749 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9470
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
9750
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
94719751
94729752 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
94739753
....@@ -9483,7 +9763,7 @@
94839763
94849764 if (renderCamera != lightCamera)
94859765 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9486
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
9766
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
94879767
94889768 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
94899769
....@@ -9529,10 +9809,12 @@
95299809 rati = 1 / rati;
95309810 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
95319811 }
9532
- assert (newenvy == -1);
9812
+
9813
+ //assert (newenvy == -1);
9814
+
95339815 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
95349816 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9535
- DrawSkyBox(gl);
9817
+ DrawSkyBox(gl, (float)rati);
95369818 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
95379819 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
95389820 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10481,6 +10763,7 @@
1048110763 ANTIALIAS = 0;
1048210764 //System.out.println("RESTART");
1048310765 AAtimer.restart();
10766
+ Globals.TIMERRUNNING = true;
1048410767 }
1048510768 }
1048610769 }
....@@ -10568,7 +10851,7 @@
1056810851
1056910852 if (wait)
1057010853 {
10571
- Sleep(500);
10854
+ Sleep(200); // blocks everything
1057210855
1057310856 wait = false;
1057410857 }
....@@ -10683,7 +10966,7 @@
1068310966 // if (parentcam != renderCamera) // not a light
1068410967 if (cam != lightCamera)
1068510968 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10686
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
10969
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1068710970
1068810971 for (int j = 0; j < 4; j++)
1068910972 {
....@@ -10698,7 +10981,7 @@
1069810981 // if (parentcam != renderCamera) // not a light
1069910982 if (cam != lightCamera)
1070010983 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10701
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
10984
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1070210985
1070310986 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1070410987
....@@ -10784,13 +11067,27 @@
1078411067 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1078511068 }
1078611069
10787
- if (newenvy > -1)
11070
+// if (newenvy > -1)
11071
+// {
11072
+// LoadEnvy(newenvy);
11073
+// }
11074
+//
11075
+// newenvy = -1;
11076
+
11077
+ if (object.skyboxname != null)
1078811078 {
10789
- LoadEnvy(newenvy);
11079
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11080
+ {
11081
+ LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11082
+ loadedskyboxname = object.skyboxname;
11083
+ }
1079011084 }
10791
-
10792
- newenvy = -1;
10793
-
11085
+ else
11086
+ {
11087
+ cubemap = null;
11088
+ loadedskyboxname = null;
11089
+ }
11090
+
1079411091 ratio = ((double) getWidth()) / getHeight();
1079511092 //System.out.println("ratio = " + ratio);
1079611093
....@@ -10806,7 +11103,7 @@
1080611103
1080711104 if (!IsFrozen() && !ambientOcclusion)
1080811105 {
10809
- DrawSkyBox(gl);
11106
+ DrawSkyBox(gl, (float)ratio);
1081011107 }
1081111108
1081211109 //if (selection_view == -1)
....@@ -10989,9 +11286,9 @@
1098911286
1099011287 gl.glMatrixMode(GL.GL_MODELVIEW);
1099111288
10992
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10993
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10994
-//gl.glEnable(gl.GL_MULTISAMPLE);
11289
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11290
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11291
+gl.glEnable(gl.GL_MULTISAMPLE);
1099511292 } else
1099611293 {
1099711294 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -11002,7 +11299,7 @@
1100211299 //System.out.println("BLENDING ON");
1100311300 gl.glEnable(GL.GL_BLEND);
1100411301 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
11005
-
11302
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1100611303 gl.glMatrixMode(gl.GL_PROJECTION);
1100711304 gl.glLoadIdentity();
1100811305
....@@ -11092,7 +11389,7 @@
1109211389
1109311390 // if (cam != lightCamera)
1109411391 //for (int count = parentcam.GetTransformCount(); --count>=0;)
11095
- LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
11392
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1109611393 }
1109711394
1109811395 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -11251,7 +11548,7 @@
1125111548 }
1125211549 }
1125311550
11254
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11551
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1125511552 {
1125611553 //gl.glDepthFunc(GL.GL_LEQUAL);
1125711554 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11259,24 +11556,21 @@
1125911556
1126011557 boolean texon = textureon;
1126111558
11262
- if (RENDERPROGRAM > 0)
11263
- {
11264
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11265
- textureon = false;
11266
- }
11559
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11560
+ textureon = false;
11561
+
1126711562 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1126811563 //System.out.println("ALLO");
1126911564 gl.glColorMask(false, false, false, false);
1127011565 DrawObject(gl);
11271
- if (RENDERPROGRAM > 0)
11272
- {
11273
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11274
- textureon = texon;
11275
- }
11566
+
11567
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11568
+ textureon = texon;
11569
+
1127611570 gl.glColorMask(true, true, true, true);
1127711571
1127811572 gl.glDepthFunc(GL.GL_EQUAL);
11279
- //gl.glDepthMask(false);
11573
+ gl.glDepthMask(false);
1128011574 }
1128111575
1128211576 if (false) // DrawMode() == SHADOW)
....@@ -11479,13 +11773,16 @@
1147911773
1148011774 void DrawObject(GL gl, boolean draw)
1148111775 {
11776
+ // To clear camera values
11777
+ ResetOptions();
11778
+
1148211779 //System.out.println("DRAW OBJECT " + mouseDown);
1148311780 // DrawMode() = SELECTION;
1148411781 //GL gl = getGL();
1148511782 if ((TRACK || SHADOWTRACK) || zoomonce)
1148611783 {
1148711784 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11488
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11785
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1148911786 pingthread.StepToTarget(true); // true);
1149011787 // zoomonce = false;
1149111788 }
....@@ -11613,20 +11910,32 @@
1161311910 ReleaseTextures(DEFAULT_TEXTURES);
1161411911
1161511912 if (CLEANCACHE)
11616
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11913
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1161711914 {
11618
- String tex = e.nextElement();
11915
+ cTexture tex = e.nextElement();
1161911916
1162011917 // System.out.println("Texture --------- " + tex);
1162111918
11622
- if (tex.equals("WHITE_NOISE"))
11919
+ if (tex.equals("WHITE_NOISE:"))
1162311920 continue;
1162411921
11625
- if (!usedtextures.containsKey(tex))
11922
+ if (!usedtextures.contains(tex))
1162611923 {
11924
+ CacheTexture gettex = texturepigment.get(tex);
1162711925 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11628
- textures.get(tex).texture.dispose();
11629
- textures.remove(tex);
11926
+ if (gettex != null)
11927
+ {
11928
+ gettex.texture.dispose();
11929
+ texturepigment.remove(tex);
11930
+ }
11931
+
11932
+ gettex = texturebump.get(tex);
11933
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11934
+ if (gettex != null)
11935
+ {
11936
+ gettex.texture.dispose();
11937
+ texturebump.remove(tex);
11938
+ }
1163011939 }
1163111940 }
1163211941 }
....@@ -12046,7 +12355,7 @@
1204612355 for (int i = tp.size(); --i >= 0;)
1204712356 {
1204812357 //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12049
- LA.xformPos(light, tp.get(i).GlobalTransform(), light);
12358
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1205012359 }
1205112360
1205212361
....@@ -12154,8 +12463,76 @@
1215412463
1215512464 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1215612465
12157
- String program =
12466
+ String programmin =
12467
+ // Min shader
1215812468 "!!ARBfp1.0\n" +
12469
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12470
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12471
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12472
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12473
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12474
+ "PARAM light2cam0 = program.env[10];" +
12475
+ "PARAM light2cam1 = program.env[11];" +
12476
+ "PARAM light2cam2 = program.env[12];" +
12477
+ "TEMP temp;" +
12478
+ "TEMP light;" +
12479
+ "TEMP ndotl;" +
12480
+ "TEMP normal;" +
12481
+ "TEMP depth;" +
12482
+ "TEMP eye;" +
12483
+ "TEMP pos;" +
12484
+
12485
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12486
+ Normalize("normal") +
12487
+ "MOV light, state.light[0].position;" +
12488
+ "DP3 ndotl.x, light, normal;" +
12489
+
12490
+ // shadow
12491
+ "MOV pos, fragment.texcoord[1];" +
12492
+ "MOV temp, pos;" +
12493
+ ShadowTextureFetch("depth", "temp", "1") +
12494
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12495
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12496
+
12497
+ // No shadow when out of frustum
12498
+ //"SGE temp.y, depth.z, zero123.y;" +
12499
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12500
+
12501
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12502
+
12503
+ // Backlit
12504
+ "MOV pos.w, zero123.y;" +
12505
+ "DP4 eye.x, pos, light2cam0;" +
12506
+ "DP4 eye.y, pos, light2cam1;" +
12507
+ "DP4 eye.z, pos, light2cam2;" +
12508
+ Normalize("eye") +
12509
+
12510
+ "DP3 ndotl.y, -eye, normal;" +
12511
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12512
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12513
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12514
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12515
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12516
+
12517
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12518
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12519
+
12520
+ // Pigment
12521
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12522
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12523
+ "MUL temp, temp, ndotl.x;" +
12524
+
12525
+ "MUL temp, temp, zero123.z;" +
12526
+
12527
+ //"MUL temp, temp, ndotl.y;" +
12528
+
12529
+ "MOV temp.w, zero123.y;" + // reset alpha
12530
+ "MOV result.color, temp;" +
12531
+ "END";
12532
+
12533
+ String programmax =
12534
+ "!!ARBfp1.0\n" +
12535
+
1215912536 //"OPTION ARB_fragment_program_shadow;" +
1216012537 "PARAM light2cam0 = program.env[10];" +
1216112538 "PARAM light2cam1 = program.env[11];" +
....@@ -12270,8 +12647,7 @@
1227012647 "TEMP shininess;" +
1227112648 "\n" +
1227212649 "MOV texSamp, one;" +
12273
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12274
-
12650
+
1227512651 "MOV mapgrid.x, one2048th.x;" +
1227612652 "MOV temp, fragment.texcoord[1];" +
1227712653 /*
....@@ -12292,20 +12668,20 @@
1229212668 "MUL temp, floor, mapgrid.x;" +
1229312669 //"TEX depth0, temp, texture[1], 2D;" +
1229412670 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12295
- TextureFetch("depth0", "temp", "1") +
12671
+ ShadowTextureFetch("depth0", "temp", "1") +
1229612672 "") +
1229712673 "ADD temp.x, temp.x, mapgrid.x;" +
1229812674 //"TEX depth1, temp, texture[1], 2D;" +
1229912675 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12300
- TextureFetch("depth1", "temp", "1") +
12676
+ ShadowTextureFetch("depth1", "temp", "1") +
1230112677 "") +
1230212678 "ADD temp.y, temp.y, mapgrid.x;" +
1230312679 //"TEX depth2, temp, texture[1], 2D;" +
12304
- TextureFetch("depth2", "temp", "1") +
12680
+ ShadowTextureFetch("depth2", "temp", "1") +
1230512681 "SUB temp.x, temp.x, mapgrid.x;" +
1230612682 //"TEX depth3, temp, texture[1], 2D;" +
1230712683 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12308
- TextureFetch("depth3", "temp", "1") +
12684
+ ShadowTextureFetch("depth3", "temp", "1") +
1230912685 "") +
1231012686 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1231112687 //"MOV params, material;" +
....@@ -12676,10 +13052,10 @@
1267613052 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1267713053 "") +
1267813054
12679
- // display shadow only (bump == 0)
13055
+ // display shadow only (fakedepth == 0)
1268013056 "SUB temp.x, half.x, shadow.x;" +
1268113057 "MOV temp.y, -params5.z;" + // params6.x;" +
12682
- "SLT temp.z, temp.y, -one2048th.x;" +
13058
+ "SLT temp.z, temp.y, -c256i.x;" +
1268313059 "SUB temp.y, one.x, temp.z;" +
1268413060 "MUL temp.x, temp.x, temp.y;" +
1268513061 "KIL temp.x;" +
....@@ -13010,6 +13386,13 @@
1301013386 //once = true;
1301113387 }
1301213388
13389
+ String program = programmax;
13390
+
13391
+ if (Globals.MINSHADER)
13392
+ {
13393
+ program = programmin;
13394
+ }
13395
+
1301313396 System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1301413397 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1301513398 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
....@@ -13103,25 +13486,26 @@
1310313486 return out;
1310413487 }
1310513488
13106
- String TextureFetch(String dest, String src, String unit)
13489
+ // Also does frustum culling
13490
+ String ShadowTextureFetch(String dest, String src, String unit)
1310713491 {
1310813492 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1310913493 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1311013494 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13495
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13496
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1311113497 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13112
- "SLT " + src + ".z, " + src + ".x, one.x;" +
13113
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13114
- "SLT " + src + ".z, " + src + ".y, one.x;" +
13115
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13498
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13499
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1311613500 //"SWZ buffer, temp, w,w,w,w;";
13117
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13501
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1311813502 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1311913503 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1312013504 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13121
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13505
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1312213506
13123
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13124
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13507
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13508
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1312513509 }
1312613510
1312713511 String Shadow(String depth, String shadow)
....@@ -13168,7 +13552,7 @@
1316813552 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1316913553 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1317013554
13171
- // No shadow when out of frustrum
13555
+ // No shadow when out of frustum
1317213556 "SGE temp.x, " + depth + ".z, one.z;" +
1317313557 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1317413558 "";
....@@ -13333,9 +13717,10 @@
1333313717 "DP3 " + dest + ".z," + "normals," + "eye;" +
1333413718 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1333513719 //"MOV " + dest + ".w," + "normal.z;" +
13336
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
13337
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13338
- //"MOV " + dest + ".z," + "params2.w;" +
13720
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13721
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13722
+
13723
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1333913724 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1334013725 "RCP " + dest + ".w," + dest + ".w;" +
1334113726 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13840,6 +14225,7 @@
1384014225 else
1384114226 if (evt.getSource() == AAtimer)
1384214227 {
14228
+ Globals.TIMERRUNNING = false;
1384314229 if (mouseDown)
1384414230 {
1384514231 //new Exception().printStackTrace();
....@@ -13899,7 +14285,7 @@
1389914285
1390014286 // fev 2014???
1390114287 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13902
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14288
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1390314289 pingthread.StepToTarget(true); // true);
1390414290 }
1390514291 // if (!LIVE)
....@@ -13914,6 +14300,7 @@
1391414300 return;
1391514301
1391614302 AAtimer.restart(); //
14303
+ Globals.TIMERRUNNING = true;
1391714304
1391814305 // waslive = LIVE;
1391914306 // LIVE = false;
....@@ -13963,14 +14350,15 @@
1396314350 drag = false;
1396414351 //System.out.println("Mouse DOWN");
1396514352 editObj = false;
13966
- ClickInfo info = new ClickInfo();
13967
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
13968
- info.pane = this;
13969
- info.camera = renderCamera;
13970
- info.x = x;
13971
- info.y = y;
13972
- info.modifiers = modifiersex;
13973
- editObj = object.doEditClick(info, 0);
14353
+ //ClickInfo info = new ClickInfo();
14354
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14355
+ object.clickInfo.pane = this;
14356
+ object.clickInfo.camera = renderCamera;
14357
+ object.clickInfo.x = x;
14358
+ object.clickInfo.y = y;
14359
+ object.clickInfo.modifiers = modifiersex;
14360
+ editObj = object.doEditClick(//info,
14361
+ 0);
1397414362 if (!editObj)
1397514363 {
1397614364 hasMarquee = true;
....@@ -14252,12 +14640,12 @@
1425214640 void GoDown(int mod)
1425314641 {
1425414642 MODIFIERS |= COMMAND;
14255
- /*
14643
+ /**/
1425614644 if((mod&SHIFT) == SHIFT)
14257
- manipCamera.RotatePosition(0, -speed);
14645
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
1425814646 else
14259
- manipCamera.BackForth(0, -speed*delta, getWidth());
14260
- */
14647
+ manipCamera.RotatePosition(0, -speed);
14648
+ /**/
1426114649 if ((mod & SHIFT) == SHIFT)
1426214650 {
1426314651 mouseMode = mouseMode; // VR??
....@@ -14273,12 +14661,12 @@
1427314661 void GoUp(int mod)
1427414662 {
1427514663 MODIFIERS |= COMMAND;
14276
- /*
14664
+ /**/
1427714665 if((mod&SHIFT) == SHIFT)
14278
- manipCamera.RotatePosition(0, speed);
14666
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
1427914667 else
14280
- manipCamera.BackForth(0, speed*delta, getWidth());
14281
- */
14668
+ manipCamera.RotatePosition(0, speed);
14669
+ /**/
1428214670 if ((mod & SHIFT) == SHIFT)
1428314671 {
1428414672 mouseMode = mouseMode;
....@@ -14294,12 +14682,12 @@
1429414682 void GoLeft(int mod)
1429514683 {
1429614684 MODIFIERS |= COMMAND;
14297
- /*
14685
+ /**/
1429814686 if((mod&SHIFT) == SHIFT)
14299
- manipCamera.RotatePosition(speed, 0);
14300
- else
1430114687 manipCamera.Translate(speed*delta, 0, getWidth());
14302
- */
14688
+ else
14689
+ manipCamera.RotatePosition(speed, 0);
14690
+ /**/
1430314691 if ((mod & SHIFT) == SHIFT)
1430414692 {
1430514693 mouseMode = mouseMode;
....@@ -14315,12 +14703,12 @@
1431514703 void GoRight(int mod)
1431614704 {
1431714705 MODIFIERS |= COMMAND;
14318
- /*
14706
+ /**/
1431914707 if((mod&SHIFT) == SHIFT)
14320
- manipCamera.RotatePosition(-speed, 0);
14321
- else
1432214708 manipCamera.Translate(-speed*delta, 0, getWidth());
14323
- */
14709
+ else
14710
+ manipCamera.RotatePosition(-speed, 0);
14711
+ /**/
1432414712 if ((mod & SHIFT) == SHIFT)
1432514713 {
1432614714 mouseMode = mouseMode;
....@@ -14370,15 +14758,16 @@
1437014758 if (editObj)
1437114759 {
1437214760 drag = true;
14373
- ClickInfo info = new ClickInfo();
14374
- info.bounds.setBounds(0, 0,
14761
+ //ClickInfo info = new ClickInfo();
14762
+ object.clickInfo.bounds.setBounds(0, 0,
1437514763 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14376
- info.pane = this;
14377
- info.camera = renderCamera;
14378
- info.x = x;
14379
- info.y = y;
14380
- object.GetWindow().copy
14381
- .doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
14764
+ object.clickInfo.pane = this;
14765
+ object.clickInfo.camera = renderCamera;
14766
+ object.clickInfo.x = x;
14767
+ object.clickInfo.y = y;
14768
+ object //.GetWindow().copy
14769
+ .doEditDrag(//info,
14770
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1438214771 } else
1438314772 {
1438414773 if (x < startX)
....@@ -14527,24 +14916,27 @@
1452714916 }
1452814917 }
1452914918
14919
+// ClickInfo clickInfo = new ClickInfo();
14920
+
1453014921 public void mouseMoved(MouseEvent e)
1453114922 {
1453214923 //System.out.println("mouseMoved: " + e);
1453314924 if (isRenderer)
1453414925 return;
1453514926
14536
- ClickInfo ci = new ClickInfo();
14537
- ci.x = e.getX();
14538
- ci.y = e.getY();
14539
- ci.modifiers = e.getModifiersEx();
14540
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14541
- ci.pane = this;
14542
- ci.camera = renderCamera;
14927
+ // Mouse cursor feedback
14928
+ object.clickInfo.x = e.getX();
14929
+ object.clickInfo.y = e.getY();
14930
+ object.clickInfo.modifiers = e.getModifiersEx();
14931
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14932
+ object.clickInfo.pane = this;
14933
+ object.clickInfo.camera = renderCamera;
1454314934 if (!isRenderer)
1454414935 {
1454514936 //ObjEditor editWindow = object.editWindow;
1454614937 //Object3D copy = editWindow.copy;
14547
- if (object.doEditClick(ci, 0))
14938
+ if (object.doEditClick(//clickInfo,
14939
+ 0))
1454814940 {
1454914941 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1455014942 } else
....@@ -14559,7 +14951,8 @@
1455914951 Globals.MOUSEDRAGGED = false;
1456014952
1456114953 movingcamera = false;
14562
- X = Y = 0;
14954
+ X = 0; // getBounds().width/2;
14955
+ Y = 0; // getBounds().height/2;
1456314956 //System.out.println("mouseReleased: " + e);
1456414957 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1456514958 }
....@@ -14815,7 +15208,8 @@
1481515208 // break;
1481615209 case 'T':
1481715210 CACHETEXTURE ^= true;
14818
- textures.clear();
15211
+ texturepigment.clear();
15212
+ texturebump.clear();
1481915213 // repaint();
1482015214 break;
1482115215 case 'Y':
....@@ -14900,7 +15294,9 @@
1490015294 case 'E' : COMPACT ^= true;
1490115295 repaint();
1490215296 break;
14903
- case 'W' : DEBUGHSB ^= true;
15297
+ case 'W' : // Wide Window (fullscreen)
15298
+ //DEBUGHSB ^= true;
15299
+ ObjEditor.theFrame.ToggleFullScreen();
1490415300 repaint();
1490515301 break;
1490615302 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14926,13 +15322,7 @@
1492615322 repaint();
1492715323 break;
1492815324 case 'l':
14929
- lightMode ^= true;
14930
- Globals.lighttouched = true;
14931
- manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
14932
- targetLookAt.set(manipCamera.lookAt);
14933
- repaint();
14934
- break;
14935
- case 'L':
15325
+ //case 'L':
1493615326 if (lightMode)
1493715327 {
1493815328 lightMode = false;
....@@ -14996,20 +15386,24 @@
1499615386 OCCLUSION_CULLING ^= true;
1499715387 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1499815388 break;
14999
- case '0': envyoff ^= true; repaint(); break;
15389
+ //case '0': envyoff ^= true; repaint(); break;
1500015390 case '1':
1500115391 case '2':
1500215392 case '3':
1500315393 case '4':
1500415394 case '5':
15005
- newenvy = Character.getNumericValue(key);
15006
- repaint();
15007
- break;
1500815395 case '6':
1500915396 case '7':
1501015397 case '8':
1501115398 case '9':
15012
- BGcolor = (key - '6')/3.f;
15399
+ if (true) // envyoff)
15400
+ {
15401
+ BGcolor = (key - '1')/8.f;
15402
+ }
15403
+ else
15404
+ {
15405
+ //newenvy = Character.getNumericValue(key);
15406
+ }
1501315407 repaint();
1501415408 break;
1501515409 case '!':
....@@ -15075,11 +15469,14 @@
1507515469 case '_':
1507615470 kompactbit = 5;
1507715471 break;
15078
- case '+':
15079
- kompactbit = 6;
15080
- break;
15472
+// case '+':
15473
+// kompactbit = 6;
15474
+// break;
1508115475 case ' ':
15082
- ObjEditor.theFrame.ToggleFullScreen();
15476
+ lightMode ^= true;
15477
+ Globals.lighttouched = true;
15478
+ manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
15479
+ targetLookAt.set(manipCamera.lookAt);
1508315480 repaint();
1508415481 break;
1508515482 //case '`' :
....@@ -15126,8 +15523,9 @@
1512615523 case DELETE:
1512715524 ClearSelection();
1512815525 break;
15129
- /*
1513015526 case '+':
15527
+
15528
+ /*
1513115529 //fontsize += 1;
1513215530 bbzoom *= 2;
1513315531 repaint();
....@@ -15144,17 +15542,17 @@
1514415542 case '=':
1514515543 IncDepth();
1514615544 //fontsize += 1;
15147
- object.editWindow.refreshContents(true);
15545
+ object.GetWindow().refreshContents(true);
1514815546 maskbit = 6;
1514915547 break;
1515015548 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1515115549 DecDepth();
1515215550 maskbit = 5;
1515315551 //if(fontsize > 1) fontsize -= 1;
15154
- if (object.editWindow == null)
15155
- new Exception().printStackTrace();
15156
- else
15157
- object.editWindow.refreshContents(true);
15552
+// if (object.editWindow == null)
15553
+// new Exception().printStackTrace();
15554
+// else
15555
+ object.GetWindow().refreshContents(true);
1515815556 break;
1515915557 case '{':
1516015558 manipCamera.shaper_fovy /= 1.1;
....@@ -15378,7 +15776,7 @@
1537815776 }
1537915777 */
1538015778
15381
- object.editWindow.EditSelection(false);
15779
+ object.GetWindow().EditSelection(false);
1538215780 }
1538315781
1538415782 void SelectParent()
....@@ -15395,10 +15793,10 @@
1539515793 {
1539615794 //selectees.remove(i);
1539715795 System.out.println("select parent of " + elem);
15398
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15796
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1539915797 } else
1540015798 {
15401
- group.editWindow.Select(elem.GetTreePath(), first, true);
15799
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1540215800 }
1540315801
1540415802 first = false;
....@@ -15440,12 +15838,12 @@
1544015838 for (int j = 0; j < group.children.size(); j++)
1544115839 {
1544215840 elem = (Object3D) group.children.elementAt(j);
15443
- object.editWindow.Select(elem.GetTreePath(), first, true);
15841
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1544415842 first = false;
1544515843 }
1544615844 } else
1544715845 {
15448
- object.editWindow.Select(elem.GetTreePath(), first, true);
15846
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1544915847 }
1545015848
1545115849 first = false;
....@@ -15456,21 +15854,21 @@
1545615854 {
1545715855 //Composite group = (Composite) object;
1545815856 Object3D group = object;
15459
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15857
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1546015858 }
1546115859
1546215860 void ResetTransform(int mask)
1546315861 {
1546415862 //Composite group = (Composite) object;
1546515863 Object3D group = object;
15466
- group.editWindow.ResetTransform(mask);
15864
+ group.GetWindow().ResetTransform(mask);
1546715865 }
1546815866
1546915867 void FlipTransform()
1547015868 {
1547115869 //Composite group = (Composite) object;
1547215870 Object3D group = object;
15473
- group.editWindow.FlipTransform();
15871
+ group.GetWindow().FlipTransform();
1547415872 // group.editWindow.ReduceMesh(true);
1547515873 }
1547615874
....@@ -15478,7 +15876,7 @@
1547815876 {
1547915877 //Composite group = (Composite) object;
1548015878 Object3D group = object;
15481
- group.editWindow.PrintMemory();
15879
+ group.GetWindow().PrintMemory();
1548215880 // group.editWindow.ReduceMesh(true);
1548315881 }
1548415882
....@@ -15486,7 +15884,7 @@
1548615884 {
1548715885 //Composite group = (Composite) object;
1548815886 Object3D group = object;
15489
- group.editWindow.ResetCentroid();
15887
+ group.GetWindow().ResetCentroid();
1549015888 }
1549115889
1549215890 void IncDepth()
....@@ -15568,8 +15966,6 @@
1556815966
1556915967 int width = getBounds().width;
1557015968 int height = getBounds().height;
15571
- ClickInfo info = new ClickInfo();
15572
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1557315969 //Image img = CreateImage(width, height);
1557415970 //System.out.println("width = " + width + "; height = " + height + "\n");
1557515971
....@@ -15646,48 +16042,77 @@
1564616042 }
1564716043 if (object != null && !hasMarquee)
1564816044 {
16045
+ if (object.clickInfo == null)
16046
+ object.clickInfo = new ClickInfo();
16047
+ ClickInfo info = object.clickInfo;
16048
+ //ClickInfo info = new ClickInfo();
16049
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16050
+
1564916051 if (isRenderer)
1565016052 {
15651
- info.flags++;
16053
+ object.clickInfo.flags++;
1565216054 double frameAspect = (double) width / (double) height;
1565316055 if (frameAspect > renderCamera.aspect)
1565416056 {
1565516057 int desired = (int) ((double) height * renderCamera.aspect);
15656
- info.bounds.width -= width - desired;
15657
- info.bounds.x += (width - desired) / 2;
16058
+ object.clickInfo.bounds.width -= width - desired;
16059
+ object.clickInfo.bounds.x += (width - desired) / 2;
1565816060 } else
1565916061 {
1566016062 int desired = (int) ((double) width / renderCamera.aspect);
15661
- info.bounds.height -= height - desired;
15662
- info.bounds.y += (height - desired) / 2;
16063
+ object.clickInfo.bounds.height -= height - desired;
16064
+ object.clickInfo.bounds.y += (height - desired) / 2;
1566316065 }
1566416066 }
15665
- info.g = gr;
15666
- info.camera = renderCamera;
16067
+
16068
+ object.clickInfo.g = gr;
16069
+ object.clickInfo.camera = renderCamera;
1566716070 /*
1566816071 // Memory intensive (brep.verticescopy)
1566916072 if (!(object instanceof Composite))
1567016073 object.draw(info, 0, false); // SLOW :
1567116074 */
15672
- if (!isRenderer)
16075
+ if (!isRenderer) // && drag)
1567316076 {
15674
- object.drawEditHandles(info, 0);
15675
-
15676
- if (drag && (X != 0 || Y != 0) && object.selection.Size() > 0)
16077
+ Grafreed.Assert(object != null);
16078
+ Grafreed.Assert(object.selection != null);
16079
+ if (object.selection.Size() > 0)
1567716080 {
15678
- switch (object.selection.get(0).hitSomething)
16081
+ int hitSomething = object.selection.get(0).hitSomething;
16082
+
16083
+ object.clickInfo.DX = 0;
16084
+ object.clickInfo.DY = 0;
16085
+ object.clickInfo.W = 1;
16086
+ if (hitSomething == Object3D.hitCenter)
1567916087 {
15680
- case Object3D.hitCenter: gr.setColor(Color.pink);
15681
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15682
- break;
15683
- case Object3D.hitRotate: gr.setColor(Color.yellow);
15684
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15685
- break;
15686
- case Object3D.hitScale: gr.setColor(Color.cyan);
15687
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15688
- break;
16088
+ info.DX = X;
16089
+ if (X != 0)
16090
+ info.DX -= info.bounds.width/2;
16091
+
16092
+ info.DY = Y;
16093
+ if (Y != 0)
16094
+ info.DY -= info.bounds.height/2;
1568916095 }
15690
-
16096
+
16097
+ object.drawEditHandles(//info,
16098
+ 0);
16099
+
16100
+ if (drag && (X != 0 || Y != 0))
16101
+ {
16102
+ switch (hitSomething)
16103
+ {
16104
+ case Object3D.hitCenter: gr.setColor(Color.pink);
16105
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16106
+ break;
16107
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16108
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16109
+ break;
16110
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16111
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16112
+ break;
16113
+ }
16114
+
16115
+ }
1569116116 }
1569216117 }
1569316118 }
....@@ -16169,6 +16594,8 @@
1616916594 private /*static*/ boolean firstime;
1617016595 private /*static*/ cVector newView = new cVector();
1617116596 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16597
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16598
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1617216599 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1617316600 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1617416601 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16181,29 +16608,67 @@
1618116608 {
1618216609 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1618316610
16611
+ int usedsuf = 0;
16612
+
1618416613 for (int i = 0; i < suffixes.length; i++)
1618516614 {
16186
- String resourceName = basename + suffixes[i] + "." + suffix;
16187
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16188
- mipmapped,
16189
- FileUtil.getFileSuffix(resourceName));
16190
- if (data == null)
16615
+ String[] suffixe = suffixes;
16616
+ String[] fallback = suffixes2;
16617
+ String[] fallfallback = suffixes3;
16618
+
16619
+ for (int c=usedsuf; --c>=0;)
1619116620 {
16192
- throw new IOException("Unable to load texture " + resourceName);
16621
+// String[] temp = suffixe;
16622
+// suffixe = fallback;
16623
+// fallback = fallfallback;
16624
+// fallfallback = temp;
1619316625 }
16626
+
16627
+ String resourceName = basename + suffixe[i] + "." + suffix;
16628
+ TextureData data;
16629
+
16630
+ try
16631
+ {
16632
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16633
+ mipmapped,
16634
+ FileUtil.getFileSuffix(resourceName));
16635
+ }
16636
+ catch (Exception e)
16637
+ {
16638
+ try
16639
+ {
16640
+ resourceName = basename + fallback[i] + "." + suffix;
16641
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16642
+ mipmapped,
16643
+ FileUtil.getFileSuffix(resourceName));
16644
+ }
16645
+ catch (Exception e2)
16646
+ {
16647
+ resourceName = basename + fallfallback[i] + "." + suffix;
16648
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16649
+ mipmapped,
16650
+ FileUtil.getFileSuffix(resourceName));
16651
+ }
16652
+ }
16653
+
1619416654 //System.out.println("Target = " + targets[i]);
1619516655 cubemap.updateImage(data, targets[i]);
1619616656 }
1619716657
1619816658 return cubemap;
1619916659 }
16660
+
1620016661 int bigsphere = -1;
1620116662
1620216663 float BGcolor = 0.5f;
1620316664
16204
- private void DrawSkyBox(GL gl)
16665
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16666
+
16667
+ private void DrawSkyBox(GL gl, float ratio)
1620516668 {
16206
- if (envyoff || cubemap == null)
16669
+ if (//envyoff ||
16670
+ WIREFRAME ||
16671
+ cubemap == null)
1620716672 {
1620816673 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1620916674 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16218,7 +16683,17 @@
1621816683 // Compensates for ExaminerViewer's modification of modelview matrix
1621916684 gl.glMatrixMode(GL.GL_MODELVIEW);
1622016685 gl.glLoadIdentity();
16686
+ gl.glScalef(1,ratio,1);
1622116687
16688
+// colorV[0] = 2;
16689
+// colorV[1] = 2;
16690
+// colorV[2] = 2;
16691
+// colorV[3] = 1;
16692
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16693
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16694
+//
16695
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16696
+
1622216697 //gl.glActiveTexture(GL.GL_TEXTURE1);
1622316698 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1622416699
....@@ -16250,6 +16725,7 @@
1625016725 {
1625116726 gl.glScalef(1.0f, -1.0f, 1.0f);
1625216727 }
16728
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1625316729 gl.glMultMatrixd(viewrot_1, 0);
1625416730 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1625516731 //viewer.updateInverseRotation(gl);
....@@ -16485,6 +16961,14 @@
1648516961 }
1648616962 }
1648716963
16964
+ private Object3D GetFolder()
16965
+ {
16966
+ Object3D folder = object.GetWindow().copy;
16967
+ if (object.GetWindow().copy.selection.Size() > 0)
16968
+ folder = object.GetWindow().copy.selection.elementAt(0);
16969
+ return folder;
16970
+ }
16971
+
1648816972 class SelectBuffer implements GLEventListener
1648916973 {
1649016974
....@@ -16500,7 +16984,7 @@
1650016984 //new Exception().printStackTrace();
1650116985 System.out.println("select buffer init");
1650216986 // Use debug pipeline
16503
- drawable.setGL(new DebugGL(drawable.getGL()));
16987
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1650416988
1650516989 GL gl = drawable.getGL();
1650616990
....@@ -16564,6 +17048,17 @@
1656417048
1656517049 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1656617050
17051
+ if (PAINTMODE)
17052
+ {
17053
+ if (object.GetWindow().copy.selection.Size() > 0)
17054
+ {
17055
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17056
+
17057
+ // Make what you paint not selectable.
17058
+ paintobj.ResetSelectable();
17059
+ }
17060
+ }
17061
+
1656717062 //int tmp = selection_view;
1656817063 //selection_view = -1;
1656917064 int temp = DrawMode();
....@@ -16575,6 +17070,17 @@
1657517070 // temp = DEFAULT; // patch for selection debug
1657617071 Globals.drawMode = temp; // WARNING
1657717072
17073
+ if (PAINTMODE)
17074
+ {
17075
+ if (object.GetWindow().copy.selection.Size() > 0)
17076
+ {
17077
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17078
+
17079
+ // Revert.
17080
+ paintobj.RestoreSelectable();
17081
+ }
17082
+ }
17083
+
1657817084 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1657917085
1658017086 // trying different ways of getting the depth info over
....@@ -16678,29 +17184,31 @@
1667817184 }
1667917185
1668017186 if (!movingcamera && !PAINTMODE)
16681
- object.editWindow.ScreenFitPoint(); // fev 2014
17187
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1668217188
16683
- if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17189
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1668417190 {
16685
- Object3D paintobj = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17191
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1668617192
16687
- Object3D group = new Object3D("inst" + paintcount++);
17193
+ if (object.GetWindow().copy.selection.Size() > 0)
17194
+ {
17195
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1668817196
16689
- group.CreateMaterial(); // use a void leaf to select instances
16690
-
16691
- group.add(paintobj); // link
16692
-
16693
- object.editWindow.SnapObject(group);
16694
-
16695
- Object3D folder = object.editWindow.copy;
16696
-
16697
- if (object.editWindow.copy.selection.Size() > 0)
16698
- folder = object.editWindow.copy.selection.elementAt(0);
16699
-
16700
- folder.add(group);
16701
-
16702
- object.editWindow.ResetModel();
16703
- object.editWindow.refreshContents();
17197
+ Object3D inst = new Object3D("inst" + paintcount++);
17198
+
17199
+ inst.CreateMaterial(); // use a void leaf to select instances
17200
+
17201
+ inst.add(paintobj); // link
17202
+
17203
+ object.GetWindow().SnapObject(inst);
17204
+
17205
+ Object3D folder = paintFolder; // GetFolder();
17206
+
17207
+ folder.add(inst);
17208
+
17209
+ object.GetWindow().ResetModel();
17210
+ object.GetWindow().refreshContents();
17211
+ }
1670417212 }
1670517213 else
1670617214 paintcount = 0;
....@@ -16739,6 +17247,11 @@
1673917247 //System.out.println("objects[color] = " + objects[color]);
1674017248 //objects[color].Select();
1674117249 indexcount = 0;
17250
+ ObjEditor window = object.GetWindow();
17251
+ if (window != null && deselect)
17252
+ {
17253
+ window.Select(null, deselect, true);
17254
+ }
1674217255 object.Select(color, deselect);
1674317256 }
1674417257