Normand Briere
2019-08-06 b3ae4e889872ca0b9ca76f1d17b2f0b961226729
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))
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,12 @@
90729314 static double[] model = new double[16];
90739315 double[] camera2light = new double[16];
90749316 double[] light2camera = new double[16];
9075
- int newenvy = -1;
9076
- boolean envyoff = true; // false;
9317
+
9318
+ //int newenvy = -1;
9319
+ //boolean envyoff = false;
9320
+
9321
+ String loadedskyboxname;
9322
+
90779323 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
90789324 //float[] light0 = { 0,0,0 };
90799325 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9366,11 +9612,35 @@
93669612 jy8[3] = 0.5f;
93679613 }
93689614
9369
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9615
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
93709616 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
93719617 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
93729618 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
93739619
9620
+ void ResetOptions()
9621
+ {
9622
+ options1[0] = 100;
9623
+ options1[1] = 0.025f;
9624
+ options1[2] = 0.01f;
9625
+ options1[3] = 0;
9626
+ options1[4] = 0;
9627
+
9628
+ options2[0] = 0;
9629
+ options2[1] = 0.75f;
9630
+ options2[2] = 0;
9631
+ options2[3] = 0;
9632
+
9633
+ options3[0] = 1;
9634
+ options3[1] = 1;
9635
+ options3[2] = 1;
9636
+ options3[3] = 0;
9637
+
9638
+ options4[0] = 1;
9639
+ options4[1] = 0;
9640
+ options4[2] = 1;
9641
+ options4[3] = 0;
9642
+ }
9643
+
93749644 static int imagecount = 0; // movie generation
93759645
93769646 static int jitter = 0;
....@@ -9467,7 +9737,7 @@
94679737
94689738 if (renderCamera != lightCamera)
94699739 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9470
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
9740
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
94719741
94729742 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
94739743
....@@ -9483,7 +9753,7 @@
94839753
94849754 if (renderCamera != lightCamera)
94859755 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9486
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
9756
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
94879757
94889758 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
94899759
....@@ -9529,10 +9799,12 @@
95299799 rati = 1 / rati;
95309800 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
95319801 }
9532
- assert (newenvy == -1);
9802
+
9803
+ //assert (newenvy == -1);
9804
+
95339805 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
95349806 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9535
- DrawSkyBox(gl);
9807
+ DrawSkyBox(gl, (float)rati);
95369808 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
95379809 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
95389810 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10481,6 +10753,7 @@
1048110753 ANTIALIAS = 0;
1048210754 //System.out.println("RESTART");
1048310755 AAtimer.restart();
10756
+ Globals.TIMERRUNNING = true;
1048410757 }
1048510758 }
1048610759 }
....@@ -10683,7 +10956,7 @@
1068310956 // if (parentcam != renderCamera) // not a light
1068410957 if (cam != lightCamera)
1068510958 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10686
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
10959
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1068710960
1068810961 for (int j = 0; j < 4; j++)
1068910962 {
....@@ -10698,7 +10971,7 @@
1069810971 // if (parentcam != renderCamera) // not a light
1069910972 if (cam != lightCamera)
1070010973 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10701
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
10974
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1070210975
1070310976 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1070410977
....@@ -10784,13 +11057,27 @@
1078411057 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1078511058 }
1078611059
10787
- if (newenvy > -1)
11060
+// if (newenvy > -1)
11061
+// {
11062
+// LoadEnvy(newenvy);
11063
+// }
11064
+//
11065
+// newenvy = -1;
11066
+
11067
+ if (object.skyboxname != null)
1078811068 {
10789
- LoadEnvy(newenvy);
11069
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11070
+ {
11071
+ LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11072
+ loadedskyboxname = object.skyboxname;
11073
+ }
1079011074 }
10791
-
10792
- newenvy = -1;
10793
-
11075
+ else
11076
+ {
11077
+ cubemap = null;
11078
+ loadedskyboxname = null;
11079
+ }
11080
+
1079411081 ratio = ((double) getWidth()) / getHeight();
1079511082 //System.out.println("ratio = " + ratio);
1079611083
....@@ -10806,7 +11093,7 @@
1080611093
1080711094 if (!IsFrozen() && !ambientOcclusion)
1080811095 {
10809
- DrawSkyBox(gl);
11096
+ DrawSkyBox(gl, (float)ratio);
1081011097 }
1081111098
1081211099 //if (selection_view == -1)
....@@ -10989,9 +11276,9 @@
1098911276
1099011277 gl.glMatrixMode(GL.GL_MODELVIEW);
1099111278
10992
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10993
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10994
-//gl.glEnable(gl.GL_MULTISAMPLE);
11279
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11280
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11281
+gl.glEnable(gl.GL_MULTISAMPLE);
1099511282 } else
1099611283 {
1099711284 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -11002,7 +11289,7 @@
1100211289 //System.out.println("BLENDING ON");
1100311290 gl.glEnable(GL.GL_BLEND);
1100411291 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
11005
-
11292
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1100611293 gl.glMatrixMode(gl.GL_PROJECTION);
1100711294 gl.glLoadIdentity();
1100811295
....@@ -11092,7 +11379,7 @@
1109211379
1109311380 // if (cam != lightCamera)
1109411381 //for (int count = parentcam.GetTransformCount(); --count>=0;)
11095
- LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
11382
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1109611383 }
1109711384
1109811385 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -11251,7 +11538,7 @@
1125111538 }
1125211539 }
1125311540
11254
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11541
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1125511542 {
1125611543 //gl.glDepthFunc(GL.GL_LEQUAL);
1125711544 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11259,24 +11546,21 @@
1125911546
1126011547 boolean texon = textureon;
1126111548
11262
- if (RENDERPROGRAM > 0)
11263
- {
11264
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11265
- textureon = false;
11266
- }
11549
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11550
+ textureon = false;
11551
+
1126711552 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1126811553 //System.out.println("ALLO");
1126911554 gl.glColorMask(false, false, false, false);
1127011555 DrawObject(gl);
11271
- if (RENDERPROGRAM > 0)
11272
- {
11273
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11274
- textureon = texon;
11275
- }
11556
+
11557
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11558
+ textureon = texon;
11559
+
1127611560 gl.glColorMask(true, true, true, true);
1127711561
1127811562 gl.glDepthFunc(GL.GL_EQUAL);
11279
- //gl.glDepthMask(false);
11563
+ gl.glDepthMask(false);
1128011564 }
1128111565
1128211566 if (false) // DrawMode() == SHADOW)
....@@ -11479,13 +11763,16 @@
1147911763
1148011764 void DrawObject(GL gl, boolean draw)
1148111765 {
11766
+ // To clear camera values
11767
+ ResetOptions();
11768
+
1148211769 //System.out.println("DRAW OBJECT " + mouseDown);
1148311770 // DrawMode() = SELECTION;
1148411771 //GL gl = getGL();
1148511772 if ((TRACK || SHADOWTRACK) || zoomonce)
1148611773 {
1148711774 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11488
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11775
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1148911776 pingthread.StepToTarget(true); // true);
1149011777 // zoomonce = false;
1149111778 }
....@@ -11613,20 +11900,32 @@
1161311900 ReleaseTextures(DEFAULT_TEXTURES);
1161411901
1161511902 if (CLEANCACHE)
11616
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11903
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1161711904 {
11618
- String tex = e.nextElement();
11905
+ cTexture tex = e.nextElement();
1161911906
1162011907 // System.out.println("Texture --------- " + tex);
1162111908
11622
- if (tex.equals("WHITE_NOISE"))
11909
+ if (tex.equals("WHITE_NOISE:"))
1162311910 continue;
1162411911
11625
- if (!usedtextures.containsKey(tex))
11912
+ if (!usedtextures.contains(tex))
1162611913 {
11914
+ CacheTexture gettex = texturepigment.get(tex);
1162711915 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11628
- textures.get(tex).texture.dispose();
11629
- textures.remove(tex);
11916
+ if (gettex != null)
11917
+ {
11918
+ gettex.texture.dispose();
11919
+ texturepigment.remove(tex);
11920
+ }
11921
+
11922
+ gettex = texturebump.get(tex);
11923
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11924
+ if (gettex != null)
11925
+ {
11926
+ gettex.texture.dispose();
11927
+ texturebump.remove(tex);
11928
+ }
1163011929 }
1163111930 }
1163211931 }
....@@ -12046,7 +12345,7 @@
1204612345 for (int i = tp.size(); --i >= 0;)
1204712346 {
1204812347 //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12049
- LA.xformPos(light, tp.get(i).GlobalTransform(), light);
12348
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1205012349 }
1205112350
1205212351
....@@ -12154,8 +12453,76 @@
1215412453
1215512454 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1215612455
12157
- String program =
12456
+ String programmin =
12457
+ // Min shader
1215812458 "!!ARBfp1.0\n" +
12459
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12460
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12461
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12462
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12463
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12464
+ "PARAM light2cam0 = program.env[10];" +
12465
+ "PARAM light2cam1 = program.env[11];" +
12466
+ "PARAM light2cam2 = program.env[12];" +
12467
+ "TEMP temp;" +
12468
+ "TEMP light;" +
12469
+ "TEMP ndotl;" +
12470
+ "TEMP normal;" +
12471
+ "TEMP depth;" +
12472
+ "TEMP eye;" +
12473
+ "TEMP pos;" +
12474
+
12475
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12476
+ Normalize("normal") +
12477
+ "MOV light, state.light[0].position;" +
12478
+ "DP3 ndotl.x, light, normal;" +
12479
+
12480
+ // shadow
12481
+ "MOV pos, fragment.texcoord[1];" +
12482
+ "MOV temp, pos;" +
12483
+ ShadowTextureFetch("depth", "temp", "1") +
12484
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12485
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12486
+
12487
+ // No shadow when out of frustum
12488
+ //"SGE temp.y, depth.z, zero123.y;" +
12489
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12490
+
12491
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12492
+
12493
+ // Backlit
12494
+ "MOV pos.w, zero123.y;" +
12495
+ "DP4 eye.x, pos, light2cam0;" +
12496
+ "DP4 eye.y, pos, light2cam1;" +
12497
+ "DP4 eye.z, pos, light2cam2;" +
12498
+ Normalize("eye") +
12499
+
12500
+ "DP3 ndotl.y, -eye, normal;" +
12501
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12502
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12503
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12504
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12505
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12506
+
12507
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12508
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12509
+
12510
+ // Pigment
12511
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12512
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12513
+ "MUL temp, temp, ndotl.x;" +
12514
+
12515
+ "MUL temp, temp, zero123.z;" +
12516
+
12517
+ //"MUL temp, temp, ndotl.y;" +
12518
+
12519
+ "MOV temp.w, zero123.y;" + // reset alpha
12520
+ "MOV result.color, temp;" +
12521
+ "END";
12522
+
12523
+ String programmax =
12524
+ "!!ARBfp1.0\n" +
12525
+
1215912526 //"OPTION ARB_fragment_program_shadow;" +
1216012527 "PARAM light2cam0 = program.env[10];" +
1216112528 "PARAM light2cam1 = program.env[11];" +
....@@ -12270,8 +12637,7 @@
1227012637 "TEMP shininess;" +
1227112638 "\n" +
1227212639 "MOV texSamp, one;" +
12273
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12274
-
12640
+
1227512641 "MOV mapgrid.x, one2048th.x;" +
1227612642 "MOV temp, fragment.texcoord[1];" +
1227712643 /*
....@@ -12292,20 +12658,20 @@
1229212658 "MUL temp, floor, mapgrid.x;" +
1229312659 //"TEX depth0, temp, texture[1], 2D;" +
1229412660 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12295
- TextureFetch("depth0", "temp", "1") +
12661
+ ShadowTextureFetch("depth0", "temp", "1") +
1229612662 "") +
1229712663 "ADD temp.x, temp.x, mapgrid.x;" +
1229812664 //"TEX depth1, temp, texture[1], 2D;" +
1229912665 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12300
- TextureFetch("depth1", "temp", "1") +
12666
+ ShadowTextureFetch("depth1", "temp", "1") +
1230112667 "") +
1230212668 "ADD temp.y, temp.y, mapgrid.x;" +
1230312669 //"TEX depth2, temp, texture[1], 2D;" +
12304
- TextureFetch("depth2", "temp", "1") +
12670
+ ShadowTextureFetch("depth2", "temp", "1") +
1230512671 "SUB temp.x, temp.x, mapgrid.x;" +
1230612672 //"TEX depth3, temp, texture[1], 2D;" +
1230712673 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12308
- TextureFetch("depth3", "temp", "1") +
12674
+ ShadowTextureFetch("depth3", "temp", "1") +
1230912675 "") +
1231012676 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1231112677 //"MOV params, material;" +
....@@ -12676,10 +13042,10 @@
1267613042 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1267713043 "") +
1267813044
12679
- // display shadow only (bump == 0)
13045
+ // display shadow only (fakedepth == 0)
1268013046 "SUB temp.x, half.x, shadow.x;" +
1268113047 "MOV temp.y, -params5.z;" + // params6.x;" +
12682
- "SLT temp.z, temp.y, -one2048th.x;" +
13048
+ "SLT temp.z, temp.y, -c256i.x;" +
1268313049 "SUB temp.y, one.x, temp.z;" +
1268413050 "MUL temp.x, temp.x, temp.y;" +
1268513051 "KIL temp.x;" +
....@@ -13010,6 +13376,13 @@
1301013376 //once = true;
1301113377 }
1301213378
13379
+ String program = programmax;
13380
+
13381
+ if (Globals.MINSHADER)
13382
+ {
13383
+ program = programmin;
13384
+ }
13385
+
1301313386 System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1301413387 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1301513388 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
....@@ -13103,25 +13476,26 @@
1310313476 return out;
1310413477 }
1310513478
13106
- String TextureFetch(String dest, String src, String unit)
13479
+ // Also does frustum culling
13480
+ String ShadowTextureFetch(String dest, String src, String unit)
1310713481 {
1310813482 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1310913483 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1311013484 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13485
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13486
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1311113487 "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;" +
13488
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13489
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1311613490 //"SWZ buffer, temp, w,w,w,w;";
13117
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13491
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1311813492 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1311913493 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1312013494 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13121
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13495
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1312213496
13123
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13124
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13497
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13498
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1312513499 }
1312613500
1312713501 String Shadow(String depth, String shadow)
....@@ -13168,7 +13542,7 @@
1316813542 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1316913543 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1317013544
13171
- // No shadow when out of frustrum
13545
+ // No shadow when out of frustum
1317213546 "SGE temp.x, " + depth + ".z, one.z;" +
1317313547 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1317413548 "";
....@@ -13333,9 +13707,10 @@
1333313707 "DP3 " + dest + ".z," + "normals," + "eye;" +
1333413708 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1333513709 //"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;" +
13710
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13711
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13712
+
13713
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1333913714 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1334013715 "RCP " + dest + ".w," + dest + ".w;" +
1334113716 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13840,6 +14215,7 @@
1384014215 else
1384114216 if (evt.getSource() == AAtimer)
1384214217 {
14218
+ Globals.TIMERRUNNING = false;
1384314219 if (mouseDown)
1384414220 {
1384514221 //new Exception().printStackTrace();
....@@ -13899,7 +14275,7 @@
1389914275
1390014276 // fev 2014???
1390114277 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13902
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14278
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1390314279 pingthread.StepToTarget(true); // true);
1390414280 }
1390514281 // if (!LIVE)
....@@ -13914,6 +14290,7 @@
1391414290 return;
1391514291
1391614292 AAtimer.restart(); //
14293
+ Globals.TIMERRUNNING = true;
1391714294
1391814295 // waslive = LIVE;
1391914296 // LIVE = false;
....@@ -13963,14 +14340,15 @@
1396314340 drag = false;
1396414341 //System.out.println("Mouse DOWN");
1396514342 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);
14343
+ //ClickInfo info = new ClickInfo();
14344
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14345
+ object.clickInfo.pane = this;
14346
+ object.clickInfo.camera = renderCamera;
14347
+ object.clickInfo.x = x;
14348
+ object.clickInfo.y = y;
14349
+ object.clickInfo.modifiers = modifiersex;
14350
+ editObj = object.doEditClick(//info,
14351
+ 0);
1397414352 if (!editObj)
1397514353 {
1397614354 hasMarquee = true;
....@@ -14252,12 +14630,12 @@
1425214630 void GoDown(int mod)
1425314631 {
1425414632 MODIFIERS |= COMMAND;
14255
- /*
14633
+ /**/
1425614634 if((mod&SHIFT) == SHIFT)
14257
- manipCamera.RotatePosition(0, -speed);
14635
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
1425814636 else
14259
- manipCamera.BackForth(0, -speed*delta, getWidth());
14260
- */
14637
+ manipCamera.RotatePosition(0, -speed);
14638
+ /**/
1426114639 if ((mod & SHIFT) == SHIFT)
1426214640 {
1426314641 mouseMode = mouseMode; // VR??
....@@ -14273,12 +14651,12 @@
1427314651 void GoUp(int mod)
1427414652 {
1427514653 MODIFIERS |= COMMAND;
14276
- /*
14654
+ /**/
1427714655 if((mod&SHIFT) == SHIFT)
14278
- manipCamera.RotatePosition(0, speed);
14656
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
1427914657 else
14280
- manipCamera.BackForth(0, speed*delta, getWidth());
14281
- */
14658
+ manipCamera.RotatePosition(0, speed);
14659
+ /**/
1428214660 if ((mod & SHIFT) == SHIFT)
1428314661 {
1428414662 mouseMode = mouseMode;
....@@ -14294,12 +14672,12 @@
1429414672 void GoLeft(int mod)
1429514673 {
1429614674 MODIFIERS |= COMMAND;
14297
- /*
14675
+ /**/
1429814676 if((mod&SHIFT) == SHIFT)
14299
- manipCamera.RotatePosition(speed, 0);
14300
- else
1430114677 manipCamera.Translate(speed*delta, 0, getWidth());
14302
- */
14678
+ else
14679
+ manipCamera.RotatePosition(speed, 0);
14680
+ /**/
1430314681 if ((mod & SHIFT) == SHIFT)
1430414682 {
1430514683 mouseMode = mouseMode;
....@@ -14315,12 +14693,12 @@
1431514693 void GoRight(int mod)
1431614694 {
1431714695 MODIFIERS |= COMMAND;
14318
- /*
14696
+ /**/
1431914697 if((mod&SHIFT) == SHIFT)
14320
- manipCamera.RotatePosition(-speed, 0);
14321
- else
1432214698 manipCamera.Translate(-speed*delta, 0, getWidth());
14323
- */
14699
+ else
14700
+ manipCamera.RotatePosition(-speed, 0);
14701
+ /**/
1432414702 if ((mod & SHIFT) == SHIFT)
1432514703 {
1432614704 mouseMode = mouseMode;
....@@ -14370,15 +14748,16 @@
1437014748 if (editObj)
1437114749 {
1437214750 drag = true;
14373
- ClickInfo info = new ClickInfo();
14374
- info.bounds.setBounds(0, 0,
14751
+ //ClickInfo info = new ClickInfo();
14752
+ object.clickInfo.bounds.setBounds(0, 0,
1437514753 (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.manipWindow.copy
14381
- .doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
14754
+ object.clickInfo.pane = this;
14755
+ object.clickInfo.camera = renderCamera;
14756
+ object.clickInfo.x = x;
14757
+ object.clickInfo.y = y;
14758
+ object //.GetWindow().copy
14759
+ .doEditDrag(//info,
14760
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1438214761 } else
1438314762 {
1438414763 if (x < startX)
....@@ -14527,24 +14906,27 @@
1452714906 }
1452814907 }
1452914908
14909
+// ClickInfo clickInfo = new ClickInfo();
14910
+
1453014911 public void mouseMoved(MouseEvent e)
1453114912 {
1453214913 //System.out.println("mouseMoved: " + e);
1453314914 if (isRenderer)
1453414915 return;
1453514916
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;
14917
+ // Mouse cursor feedback
14918
+ object.clickInfo.x = e.getX();
14919
+ object.clickInfo.y = e.getY();
14920
+ object.clickInfo.modifiers = e.getModifiersEx();
14921
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14922
+ object.clickInfo.pane = this;
14923
+ object.clickInfo.camera = renderCamera;
1454314924 if (!isRenderer)
1454414925 {
1454514926 //ObjEditor editWindow = object.editWindow;
1454614927 //Object3D copy = editWindow.copy;
14547
- if (object.doEditClick(ci, 0))
14928
+ if (object.doEditClick(//clickInfo,
14929
+ 0))
1454814930 {
1454914931 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1455014932 } else
....@@ -14559,7 +14941,8 @@
1455914941 Globals.MOUSEDRAGGED = false;
1456014942
1456114943 movingcamera = false;
14562
- X = Y = 0;
14944
+ X = 0; // getBounds().width/2;
14945
+ Y = 0; // getBounds().height/2;
1456314946 //System.out.println("mouseReleased: " + e);
1456414947 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1456514948 }
....@@ -14815,7 +15198,8 @@
1481515198 // break;
1481615199 case 'T':
1481715200 CACHETEXTURE ^= true;
14818
- textures.clear();
15201
+ texturepigment.clear();
15202
+ texturebump.clear();
1481915203 // repaint();
1482015204 break;
1482115205 case 'Y':
....@@ -14900,7 +15284,9 @@
1490015284 case 'E' : COMPACT ^= true;
1490115285 repaint();
1490215286 break;
14903
- case 'W' : DEBUGHSB ^= true;
15287
+ case 'W' : // Wide Window (fullscreen)
15288
+ //DEBUGHSB ^= true;
15289
+ ObjEditor.theFrame.ToggleFullScreen();
1490415290 repaint();
1490515291 break;
1490615292 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14926,13 +15312,7 @@
1492615312 repaint();
1492715313 break;
1492815314 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':
15315
+ //case 'L':
1493615316 if (lightMode)
1493715317 {
1493815318 lightMode = false;
....@@ -14996,20 +15376,24 @@
1499615376 OCCLUSION_CULLING ^= true;
1499715377 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1499815378 break;
14999
- case '0': envyoff ^= true; repaint(); break;
15379
+ //case '0': envyoff ^= true; repaint(); break;
1500015380 case '1':
1500115381 case '2':
1500215382 case '3':
1500315383 case '4':
1500415384 case '5':
15005
- newenvy = Character.getNumericValue(key);
15006
- repaint();
15007
- break;
1500815385 case '6':
1500915386 case '7':
1501015387 case '8':
1501115388 case '9':
15012
- BGcolor = (key - '6')/3.f;
15389
+ if (true) // envyoff)
15390
+ {
15391
+ BGcolor = (key - '1')/8.f;
15392
+ }
15393
+ else
15394
+ {
15395
+ //newenvy = Character.getNumericValue(key);
15396
+ }
1501315397 repaint();
1501415398 break;
1501515399 case '!':
....@@ -15075,11 +15459,14 @@
1507515459 case '_':
1507615460 kompactbit = 5;
1507715461 break;
15078
- case '+':
15079
- kompactbit = 6;
15080
- break;
15462
+// case '+':
15463
+// kompactbit = 6;
15464
+// break;
1508115465 case ' ':
15082
- ObjEditor.theFrame.ToggleFullScreen();
15466
+ lightMode ^= true;
15467
+ Globals.lighttouched = true;
15468
+ manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
15469
+ targetLookAt.set(manipCamera.lookAt);
1508315470 repaint();
1508415471 break;
1508515472 //case '`' :
....@@ -15126,8 +15513,9 @@
1512615513 case DELETE:
1512715514 ClearSelection();
1512815515 break;
15129
- /*
1513015516 case '+':
15517
+
15518
+ /*
1513115519 //fontsize += 1;
1513215520 bbzoom *= 2;
1513315521 repaint();
....@@ -15144,17 +15532,17 @@
1514415532 case '=':
1514515533 IncDepth();
1514615534 //fontsize += 1;
15147
- object.editWindow.refreshContents(true);
15535
+ object.GetWindow().refreshContents(true);
1514815536 maskbit = 6;
1514915537 break;
1515015538 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1515115539 DecDepth();
1515215540 maskbit = 5;
1515315541 //if(fontsize > 1) fontsize -= 1;
15154
- if (object.editWindow == null)
15155
- new Exception().printStackTrace();
15156
- else
15157
- object.editWindow.refreshContents(true);
15542
+// if (object.editWindow == null)
15543
+// new Exception().printStackTrace();
15544
+// else
15545
+ object.GetWindow().refreshContents(true);
1515815546 break;
1515915547 case '{':
1516015548 manipCamera.shaper_fovy /= 1.1;
....@@ -15378,7 +15766,7 @@
1537815766 }
1537915767 */
1538015768
15381
- object.editWindow.EditSelection();
15769
+ object.GetWindow().EditSelection(false);
1538215770 }
1538315771
1538415772 void SelectParent()
....@@ -15395,10 +15783,10 @@
1539515783 {
1539615784 //selectees.remove(i);
1539715785 System.out.println("select parent of " + elem);
15398
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15786
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1539915787 } else
1540015788 {
15401
- group.editWindow.Select(elem.GetTreePath(), first, true);
15789
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1540215790 }
1540315791
1540415792 first = false;
....@@ -15440,12 +15828,12 @@
1544015828 for (int j = 0; j < group.children.size(); j++)
1544115829 {
1544215830 elem = (Object3D) group.children.elementAt(j);
15443
- object.editWindow.Select(elem.GetTreePath(), first, true);
15831
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1544415832 first = false;
1544515833 }
1544615834 } else
1544715835 {
15448
- object.editWindow.Select(elem.GetTreePath(), first, true);
15836
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1544915837 }
1545015838
1545115839 first = false;
....@@ -15456,21 +15844,21 @@
1545615844 {
1545715845 //Composite group = (Composite) object;
1545815846 Object3D group = object;
15459
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15847
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1546015848 }
1546115849
1546215850 void ResetTransform(int mask)
1546315851 {
1546415852 //Composite group = (Composite) object;
1546515853 Object3D group = object;
15466
- group.editWindow.ResetTransform(mask);
15854
+ group.GetWindow().ResetTransform(mask);
1546715855 }
1546815856
1546915857 void FlipTransform()
1547015858 {
1547115859 //Composite group = (Composite) object;
1547215860 Object3D group = object;
15473
- group.editWindow.FlipTransform();
15861
+ group.GetWindow().FlipTransform();
1547415862 // group.editWindow.ReduceMesh(true);
1547515863 }
1547615864
....@@ -15478,7 +15866,7 @@
1547815866 {
1547915867 //Composite group = (Composite) object;
1548015868 Object3D group = object;
15481
- group.editWindow.PrintMemory();
15869
+ group.GetWindow().PrintMemory();
1548215870 // group.editWindow.ReduceMesh(true);
1548315871 }
1548415872
....@@ -15486,7 +15874,7 @@
1548615874 {
1548715875 //Composite group = (Composite) object;
1548815876 Object3D group = object;
15489
- group.editWindow.ResetCentroid();
15877
+ group.GetWindow().ResetCentroid();
1549015878 }
1549115879
1549215880 void IncDepth()
....@@ -15568,8 +15956,6 @@
1556815956
1556915957 int width = getBounds().width;
1557015958 int height = getBounds().height;
15571
- ClickInfo info = new ClickInfo();
15572
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1557315959 //Image img = CreateImage(width, height);
1557415960 //System.out.println("width = " + width + "; height = " + height + "\n");
1557515961
....@@ -15646,48 +16032,77 @@
1564616032 }
1564716033 if (object != null && !hasMarquee)
1564816034 {
16035
+ if (object.clickInfo == null)
16036
+ object.clickInfo = new ClickInfo();
16037
+ ClickInfo info = object.clickInfo;
16038
+ //ClickInfo info = new ClickInfo();
16039
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16040
+
1564916041 if (isRenderer)
1565016042 {
15651
- info.flags++;
16043
+ object.clickInfo.flags++;
1565216044 double frameAspect = (double) width / (double) height;
1565316045 if (frameAspect > renderCamera.aspect)
1565416046 {
1565516047 int desired = (int) ((double) height * renderCamera.aspect);
15656
- info.bounds.width -= width - desired;
15657
- info.bounds.x += (width - desired) / 2;
16048
+ object.clickInfo.bounds.width -= width - desired;
16049
+ object.clickInfo.bounds.x += (width - desired) / 2;
1565816050 } else
1565916051 {
1566016052 int desired = (int) ((double) width / renderCamera.aspect);
15661
- info.bounds.height -= height - desired;
15662
- info.bounds.y += (height - desired) / 2;
16053
+ object.clickInfo.bounds.height -= height - desired;
16054
+ object.clickInfo.bounds.y += (height - desired) / 2;
1566316055 }
1566416056 }
15665
- info.g = gr;
15666
- info.camera = renderCamera;
16057
+
16058
+ object.clickInfo.g = gr;
16059
+ object.clickInfo.camera = renderCamera;
1566716060 /*
1566816061 // Memory intensive (brep.verticescopy)
1566916062 if (!(object instanceof Composite))
1567016063 object.draw(info, 0, false); // SLOW :
1567116064 */
15672
- if (!isRenderer)
16065
+ if (!isRenderer) // && drag)
1567316066 {
15674
- object.drawEditHandles(info, 0);
15675
-
15676
- if (drag && (X != 0 || Y != 0) && object.selection.Size() > 0)
16067
+ Grafreed.Assert(object != null);
16068
+ Grafreed.Assert(object.selection != null);
16069
+ if (object.selection.Size() > 0)
1567716070 {
15678
- switch (object.selection.get(0).hitSomething)
16071
+ int hitSomething = object.selection.get(0).hitSomething;
16072
+
16073
+ object.clickInfo.DX = 0;
16074
+ object.clickInfo.DY = 0;
16075
+ object.clickInfo.W = 1;
16076
+ if (hitSomething == Object3D.hitCenter)
1567916077 {
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;
16078
+ info.DX = X;
16079
+ if (X != 0)
16080
+ info.DX -= info.bounds.width/2;
16081
+
16082
+ info.DY = Y;
16083
+ if (Y != 0)
16084
+ info.DY -= info.bounds.height/2;
1568916085 }
15690
-
16086
+
16087
+ object.drawEditHandles(//info,
16088
+ 0);
16089
+
16090
+ if (drag && (X != 0 || Y != 0))
16091
+ {
16092
+ switch (hitSomething)
16093
+ {
16094
+ case Object3D.hitCenter: gr.setColor(Color.pink);
16095
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16096
+ break;
16097
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16098
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16099
+ break;
16100
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16101
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16102
+ break;
16103
+ }
16104
+
16105
+ }
1569116106 }
1569216107 }
1569316108 }
....@@ -16169,6 +16584,8 @@
1616916584 private /*static*/ boolean firstime;
1617016585 private /*static*/ cVector newView = new cVector();
1617116586 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16587
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16588
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1617216589 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1617316590 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1617416591 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16181,29 +16598,66 @@
1618116598 {
1618216599 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1618316600
16601
+ int usedsuf = 0;
16602
+
1618416603 for (int i = 0; i < suffixes.length; i++)
1618516604 {
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)
16605
+ String[] suffixe = suffixes;
16606
+ String[] fallback = suffixes2;
16607
+ String[] fallfallback = suffixes3;
16608
+
16609
+ for (int c=usedsuf; --c>=0;)
1619116610 {
16192
- throw new IOException("Unable to load texture " + resourceName);
16611
+// String[] temp = suffixe;
16612
+// suffixe = fallback;
16613
+// fallback = fallfallback;
16614
+// fallfallback = temp;
1619316615 }
16616
+
16617
+ String resourceName = basename + suffixe[i] + "." + suffix;
16618
+ TextureData data;
16619
+
16620
+ try
16621
+ {
16622
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16623
+ mipmapped,
16624
+ FileUtil.getFileSuffix(resourceName));
16625
+ }
16626
+ catch (Exception e)
16627
+ {
16628
+ try
16629
+ {
16630
+ resourceName = basename + fallback[i] + "." + suffix;
16631
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16632
+ mipmapped,
16633
+ FileUtil.getFileSuffix(resourceName));
16634
+ }
16635
+ catch (Exception e2)
16636
+ {
16637
+ resourceName = basename + fallfallback[i] + "." + suffix;
16638
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16639
+ mipmapped,
16640
+ FileUtil.getFileSuffix(resourceName));
16641
+ }
16642
+ }
16643
+
1619416644 //System.out.println("Target = " + targets[i]);
1619516645 cubemap.updateImage(data, targets[i]);
1619616646 }
1619716647
1619816648 return cubemap;
1619916649 }
16650
+
1620016651 int bigsphere = -1;
1620116652
1620216653 float BGcolor = 0.5f;
1620316654
16204
- private void DrawSkyBox(GL gl)
16655
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16656
+
16657
+ private void DrawSkyBox(GL gl, float ratio)
1620516658 {
16206
- if (envyoff || cubemap == null)
16659
+ if (//envyoff ||
16660
+ cubemap == null)
1620716661 {
1620816662 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1620916663 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16218,7 +16672,17 @@
1621816672 // Compensates for ExaminerViewer's modification of modelview matrix
1621916673 gl.glMatrixMode(GL.GL_MODELVIEW);
1622016674 gl.glLoadIdentity();
16675
+ gl.glScalef(1,ratio,1);
1622116676
16677
+// colorV[0] = 2;
16678
+// colorV[1] = 2;
16679
+// colorV[2] = 2;
16680
+// colorV[3] = 1;
16681
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16682
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16683
+//
16684
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16685
+
1622216686 //gl.glActiveTexture(GL.GL_TEXTURE1);
1622316687 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1622416688
....@@ -16250,6 +16714,7 @@
1625016714 {
1625116715 gl.glScalef(1.0f, -1.0f, 1.0f);
1625216716 }
16717
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1625316718 gl.glMultMatrixd(viewrot_1, 0);
1625416719 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1625516720 //viewer.updateInverseRotation(gl);
....@@ -16485,6 +16950,14 @@
1648516950 }
1648616951 }
1648716952
16953
+ private Object3D GetFolder()
16954
+ {
16955
+ Object3D folder = object.GetWindow().copy;
16956
+ if (object.GetWindow().copy.selection.Size() > 0)
16957
+ folder = object.GetWindow().copy.selection.elementAt(0);
16958
+ return folder;
16959
+ }
16960
+
1648816961 class SelectBuffer implements GLEventListener
1648916962 {
1649016963
....@@ -16500,7 +16973,7 @@
1650016973 //new Exception().printStackTrace();
1650116974 System.out.println("select buffer init");
1650216975 // Use debug pipeline
16503
- drawable.setGL(new DebugGL(drawable.getGL()));
16976
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1650416977
1650516978 GL gl = drawable.getGL();
1650616979
....@@ -16564,6 +17037,17 @@
1656417037
1656517038 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1656617039
17040
+ if (PAINTMODE)
17041
+ {
17042
+ if (object.GetWindow().copy.selection.Size() > 0)
17043
+ {
17044
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17045
+
17046
+ // Make what you paint not selectable.
17047
+ paintobj.ResetSelectable();
17048
+ }
17049
+ }
17050
+
1656717051 //int tmp = selection_view;
1656817052 //selection_view = -1;
1656917053 int temp = DrawMode();
....@@ -16575,6 +17059,17 @@
1657517059 // temp = DEFAULT; // patch for selection debug
1657617060 Globals.drawMode = temp; // WARNING
1657717061
17062
+ if (PAINTMODE)
17063
+ {
17064
+ if (object.GetWindow().copy.selection.Size() > 0)
17065
+ {
17066
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17067
+
17068
+ // Revert.
17069
+ paintobj.RestoreSelectable();
17070
+ }
17071
+ }
17072
+
1657817073 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1657917074
1658017075 // trying different ways of getting the depth info over
....@@ -16678,29 +17173,31 @@
1667817173 }
1667917174
1668017175 if (!movingcamera && !PAINTMODE)
16681
- object.editWindow.ScreenFitPoint(); // fev 2014
17176
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1668217177
16683
- if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17178
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1668417179 {
16685
- Object3D paintobj = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17180
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1668617181
16687
- Object3D group = new Object3D("inst" + paintcount++);
17182
+ if (object.GetWindow().copy.selection.Size() > 0)
17183
+ {
17184
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1668817185
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();
17186
+ Object3D inst = new Object3D("inst" + paintcount++);
17187
+
17188
+ inst.CreateMaterial(); // use a void leaf to select instances
17189
+
17190
+ inst.add(paintobj); // link
17191
+
17192
+ object.GetWindow().SnapObject(inst);
17193
+
17194
+ Object3D folder = paintFolder; // GetFolder();
17195
+
17196
+ folder.add(inst);
17197
+
17198
+ object.GetWindow().ResetModel();
17199
+ object.GetWindow().refreshContents();
17200
+ }
1670417201 }
1670517202 else
1670617203 paintcount = 0;
....@@ -16739,6 +17236,11 @@
1673917236 //System.out.println("objects[color] = " + objects[color]);
1674017237 //objects[color].Select();
1674117238 indexcount = 0;
17239
+ ObjEditor window = object.GetWindow();
17240
+ if (window != null && deselect)
17241
+ {
17242
+ window.Select(null, deselect, true);
17243
+ }
1674217244 object.Select(color, deselect);
1674317245 }
1674417246