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,
....@@ -10569,7 +10851,7 @@
1056910851
1057010852 if (wait)
1057110853 {
10572
- Sleep(500);
10854
+ Sleep(200); // blocks everything
1057310855
1057410856 wait = false;
1057510857 }
....@@ -10684,7 +10966,7 @@
1068410966 // if (parentcam != renderCamera) // not a light
1068510967 if (cam != lightCamera)
1068610968 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10687
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
10969
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1068810970
1068910971 for (int j = 0; j < 4; j++)
1069010972 {
....@@ -10699,7 +10981,7 @@
1069910981 // if (parentcam != renderCamera) // not a light
1070010982 if (cam != lightCamera)
1070110983 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10702
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
10984
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1070310985
1070410986 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1070510987
....@@ -10785,13 +11067,27 @@
1078511067 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1078611068 }
1078711069
10788
- if (newenvy > -1)
11070
+// if (newenvy > -1)
11071
+// {
11072
+// LoadEnvy(newenvy);
11073
+// }
11074
+//
11075
+// newenvy = -1;
11076
+
11077
+ if (object.skyboxname != null)
1078911078 {
10790
- LoadEnvy(newenvy);
11079
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11080
+ {
11081
+ LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11082
+ loadedskyboxname = object.skyboxname;
11083
+ }
1079111084 }
10792
-
10793
- newenvy = -1;
10794
-
11085
+ else
11086
+ {
11087
+ cubemap = null;
11088
+ loadedskyboxname = null;
11089
+ }
11090
+
1079511091 ratio = ((double) getWidth()) / getHeight();
1079611092 //System.out.println("ratio = " + ratio);
1079711093
....@@ -10807,7 +11103,7 @@
1080711103
1080811104 if (!IsFrozen() && !ambientOcclusion)
1080911105 {
10810
- DrawSkyBox(gl);
11106
+ DrawSkyBox(gl, (float)ratio);
1081111107 }
1081211108
1081311109 //if (selection_view == -1)
....@@ -10990,9 +11286,9 @@
1099011286
1099111287 gl.glMatrixMode(GL.GL_MODELVIEW);
1099211288
10993
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10994
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10995
-//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);
1099611292 } else
1099711293 {
1099811294 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -11003,7 +11299,7 @@
1100311299 //System.out.println("BLENDING ON");
1100411300 gl.glEnable(GL.GL_BLEND);
1100511301 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
11006
-
11302
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1100711303 gl.glMatrixMode(gl.GL_PROJECTION);
1100811304 gl.glLoadIdentity();
1100911305
....@@ -11093,7 +11389,7 @@
1109311389
1109411390 // if (cam != lightCamera)
1109511391 //for (int count = parentcam.GetTransformCount(); --count>=0;)
11096
- LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
11392
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1109711393 }
1109811394
1109911395 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -11252,7 +11548,7 @@
1125211548 }
1125311549 }
1125411550
11255
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11551
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1125611552 {
1125711553 //gl.glDepthFunc(GL.GL_LEQUAL);
1125811554 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11260,24 +11556,21 @@
1126011556
1126111557 boolean texon = textureon;
1126211558
11263
- if (RENDERPROGRAM > 0)
11264
- {
11265
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11266
- textureon = false;
11267
- }
11559
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11560
+ textureon = false;
11561
+
1126811562 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1126911563 //System.out.println("ALLO");
1127011564 gl.glColorMask(false, false, false, false);
1127111565 DrawObject(gl);
11272
- if (RENDERPROGRAM > 0)
11273
- {
11274
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11275
- textureon = texon;
11276
- }
11566
+
11567
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11568
+ textureon = texon;
11569
+
1127711570 gl.glColorMask(true, true, true, true);
1127811571
1127911572 gl.glDepthFunc(GL.GL_EQUAL);
11280
- //gl.glDepthMask(false);
11573
+ gl.glDepthMask(false);
1128111574 }
1128211575
1128311576 if (false) // DrawMode() == SHADOW)
....@@ -11480,13 +11773,16 @@
1148011773
1148111774 void DrawObject(GL gl, boolean draw)
1148211775 {
11776
+ // To clear camera values
11777
+ ResetOptions();
11778
+
1148311779 //System.out.println("DRAW OBJECT " + mouseDown);
1148411780 // DrawMode() = SELECTION;
1148511781 //GL gl = getGL();
1148611782 if ((TRACK || SHADOWTRACK) || zoomonce)
1148711783 {
1148811784 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11489
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11785
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1149011786 pingthread.StepToTarget(true); // true);
1149111787 // zoomonce = false;
1149211788 }
....@@ -11614,20 +11910,32 @@
1161411910 ReleaseTextures(DEFAULT_TEXTURES);
1161511911
1161611912 if (CLEANCACHE)
11617
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11913
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1161811914 {
11619
- String tex = e.nextElement();
11915
+ cTexture tex = e.nextElement();
1162011916
1162111917 // System.out.println("Texture --------- " + tex);
1162211918
11623
- if (tex.equals("WHITE_NOISE"))
11919
+ if (tex.equals("WHITE_NOISE:"))
1162411920 continue;
1162511921
11626
- if (!usedtextures.containsKey(tex))
11922
+ if (!usedtextures.contains(tex))
1162711923 {
11924
+ CacheTexture gettex = texturepigment.get(tex);
1162811925 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11629
- textures.get(tex).texture.dispose();
11630
- 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
+ }
1163111939 }
1163211940 }
1163311941 }
....@@ -12047,7 +12355,7 @@
1204712355 for (int i = tp.size(); --i >= 0;)
1204812356 {
1204912357 //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12050
- LA.xformPos(light, tp.get(i).GlobalTransform(), light);
12358
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1205112359 }
1205212360
1205312361
....@@ -12155,8 +12463,76 @@
1215512463
1215612464 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1215712465
12158
- String program =
12466
+ String programmin =
12467
+ // Min shader
1215912468 "!!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
+
1216012536 //"OPTION ARB_fragment_program_shadow;" +
1216112537 "PARAM light2cam0 = program.env[10];" +
1216212538 "PARAM light2cam1 = program.env[11];" +
....@@ -12271,8 +12647,7 @@
1227112647 "TEMP shininess;" +
1227212648 "\n" +
1227312649 "MOV texSamp, one;" +
12274
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12275
-
12650
+
1227612651 "MOV mapgrid.x, one2048th.x;" +
1227712652 "MOV temp, fragment.texcoord[1];" +
1227812653 /*
....@@ -12293,20 +12668,20 @@
1229312668 "MUL temp, floor, mapgrid.x;" +
1229412669 //"TEX depth0, temp, texture[1], 2D;" +
1229512670 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12296
- TextureFetch("depth0", "temp", "1") +
12671
+ ShadowTextureFetch("depth0", "temp", "1") +
1229712672 "") +
1229812673 "ADD temp.x, temp.x, mapgrid.x;" +
1229912674 //"TEX depth1, temp, texture[1], 2D;" +
1230012675 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12301
- TextureFetch("depth1", "temp", "1") +
12676
+ ShadowTextureFetch("depth1", "temp", "1") +
1230212677 "") +
1230312678 "ADD temp.y, temp.y, mapgrid.x;" +
1230412679 //"TEX depth2, temp, texture[1], 2D;" +
12305
- TextureFetch("depth2", "temp", "1") +
12680
+ ShadowTextureFetch("depth2", "temp", "1") +
1230612681 "SUB temp.x, temp.x, mapgrid.x;" +
1230712682 //"TEX depth3, temp, texture[1], 2D;" +
1230812683 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12309
- TextureFetch("depth3", "temp", "1") +
12684
+ ShadowTextureFetch("depth3", "temp", "1") +
1231012685 "") +
1231112686 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1231212687 //"MOV params, material;" +
....@@ -12677,10 +13052,10 @@
1267713052 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1267813053 "") +
1267913054
12680
- // display shadow only (bump == 0)
13055
+ // display shadow only (fakedepth == 0)
1268113056 "SUB temp.x, half.x, shadow.x;" +
1268213057 "MOV temp.y, -params5.z;" + // params6.x;" +
12683
- "SLT temp.z, temp.y, -one2048th.x;" +
13058
+ "SLT temp.z, temp.y, -c256i.x;" +
1268413059 "SUB temp.y, one.x, temp.z;" +
1268513060 "MUL temp.x, temp.x, temp.y;" +
1268613061 "KIL temp.x;" +
....@@ -13011,6 +13386,13 @@
1301113386 //once = true;
1301213387 }
1301313388
13389
+ String program = programmax;
13390
+
13391
+ if (Globals.MINSHADER)
13392
+ {
13393
+ program = programmin;
13394
+ }
13395
+
1301413396 System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1301513397 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1301613398 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
....@@ -13104,25 +13486,26 @@
1310413486 return out;
1310513487 }
1310613488
13107
- String TextureFetch(String dest, String src, String unit)
13489
+ // Also does frustum culling
13490
+ String ShadowTextureFetch(String dest, String src, String unit)
1310813491 {
1310913492 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1311013493 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1311113494 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13495
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13496
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1311213497 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13113
- "SLT " + src + ".z, " + src + ".x, one.x;" +
13114
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13115
- "SLT " + src + ".z, " + src + ".y, one.x;" +
13116
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13498
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13499
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1311713500 //"SWZ buffer, temp, w,w,w,w;";
13118
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13501
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1311913502 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1312013503 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1312113504 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13122
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13505
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1312313506
13124
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13125
- //"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;";
1312613509 }
1312713510
1312813511 String Shadow(String depth, String shadow)
....@@ -13169,7 +13552,7 @@
1316913552 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1317013553 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1317113554
13172
- // No shadow when out of frustrum
13555
+ // No shadow when out of frustum
1317313556 "SGE temp.x, " + depth + ".z, one.z;" +
1317413557 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1317513558 "";
....@@ -13334,9 +13717,10 @@
1333413717 "DP3 " + dest + ".z," + "normals," + "eye;" +
1333513718 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1333613719 //"MOV " + dest + ".w," + "normal.z;" +
13337
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
13338
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13339
- //"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
1334013724 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1334113725 "RCP " + dest + ".w," + dest + ".w;" +
1334213726 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13901,7 +14285,7 @@
1390114285
1390214286 // fev 2014???
1390314287 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13904
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14288
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1390514289 pingthread.StepToTarget(true); // true);
1390614290 }
1390714291 // if (!LIVE)
....@@ -13966,14 +14350,15 @@
1396614350 drag = false;
1396714351 //System.out.println("Mouse DOWN");
1396814352 editObj = false;
13969
- ClickInfo info = new ClickInfo();
13970
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
13971
- info.pane = this;
13972
- info.camera = renderCamera;
13973
- info.x = x;
13974
- info.y = y;
13975
- info.modifiers = modifiersex;
13976
- 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);
1397714362 if (!editObj)
1397814363 {
1397914364 hasMarquee = true;
....@@ -14255,12 +14640,12 @@
1425514640 void GoDown(int mod)
1425614641 {
1425714642 MODIFIERS |= COMMAND;
14258
- /*
14643
+ /**/
1425914644 if((mod&SHIFT) == SHIFT)
14260
- manipCamera.RotatePosition(0, -speed);
14645
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
1426114646 else
14262
- manipCamera.BackForth(0, -speed*delta, getWidth());
14263
- */
14647
+ manipCamera.RotatePosition(0, -speed);
14648
+ /**/
1426414649 if ((mod & SHIFT) == SHIFT)
1426514650 {
1426614651 mouseMode = mouseMode; // VR??
....@@ -14276,12 +14661,12 @@
1427614661 void GoUp(int mod)
1427714662 {
1427814663 MODIFIERS |= COMMAND;
14279
- /*
14664
+ /**/
1428014665 if((mod&SHIFT) == SHIFT)
14281
- manipCamera.RotatePosition(0, speed);
14666
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
1428214667 else
14283
- manipCamera.BackForth(0, speed*delta, getWidth());
14284
- */
14668
+ manipCamera.RotatePosition(0, speed);
14669
+ /**/
1428514670 if ((mod & SHIFT) == SHIFT)
1428614671 {
1428714672 mouseMode = mouseMode;
....@@ -14297,12 +14682,12 @@
1429714682 void GoLeft(int mod)
1429814683 {
1429914684 MODIFIERS |= COMMAND;
14300
- /*
14685
+ /**/
1430114686 if((mod&SHIFT) == SHIFT)
14302
- manipCamera.RotatePosition(speed, 0);
14303
- else
1430414687 manipCamera.Translate(speed*delta, 0, getWidth());
14305
- */
14688
+ else
14689
+ manipCamera.RotatePosition(speed, 0);
14690
+ /**/
1430614691 if ((mod & SHIFT) == SHIFT)
1430714692 {
1430814693 mouseMode = mouseMode;
....@@ -14318,12 +14703,12 @@
1431814703 void GoRight(int mod)
1431914704 {
1432014705 MODIFIERS |= COMMAND;
14321
- /*
14706
+ /**/
1432214707 if((mod&SHIFT) == SHIFT)
14323
- manipCamera.RotatePosition(-speed, 0);
14324
- else
1432514708 manipCamera.Translate(-speed*delta, 0, getWidth());
14326
- */
14709
+ else
14710
+ manipCamera.RotatePosition(-speed, 0);
14711
+ /**/
1432714712 if ((mod & SHIFT) == SHIFT)
1432814713 {
1432914714 mouseMode = mouseMode;
....@@ -14373,15 +14758,16 @@
1437314758 if (editObj)
1437414759 {
1437514760 drag = true;
14376
- ClickInfo info = new ClickInfo();
14377
- info.bounds.setBounds(0, 0,
14761
+ //ClickInfo info = new ClickInfo();
14762
+ object.clickInfo.bounds.setBounds(0, 0,
1437814763 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14379
- info.pane = this;
14380
- info.camera = renderCamera;
14381
- info.x = x;
14382
- info.y = y;
14383
- object.GetWindow().copy
14384
- .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);
1438514771 } else
1438614772 {
1438714773 if (x < startX)
....@@ -14530,24 +14916,27 @@
1453014916 }
1453114917 }
1453214918
14919
+// ClickInfo clickInfo = new ClickInfo();
14920
+
1453314921 public void mouseMoved(MouseEvent e)
1453414922 {
1453514923 //System.out.println("mouseMoved: " + e);
1453614924 if (isRenderer)
1453714925 return;
1453814926
14539
- ClickInfo ci = new ClickInfo();
14540
- ci.x = e.getX();
14541
- ci.y = e.getY();
14542
- ci.modifiers = e.getModifiersEx();
14543
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14544
- ci.pane = this;
14545
- 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;
1454614934 if (!isRenderer)
1454714935 {
1454814936 //ObjEditor editWindow = object.editWindow;
1454914937 //Object3D copy = editWindow.copy;
14550
- if (object.doEditClick(ci, 0))
14938
+ if (object.doEditClick(//clickInfo,
14939
+ 0))
1455114940 {
1455214941 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1455314942 } else
....@@ -14562,7 +14951,8 @@
1456214951 Globals.MOUSEDRAGGED = false;
1456314952
1456414953 movingcamera = false;
14565
- X = Y = 0;
14954
+ X = 0; // getBounds().width/2;
14955
+ Y = 0; // getBounds().height/2;
1456614956 //System.out.println("mouseReleased: " + e);
1456714957 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1456814958 }
....@@ -14818,7 +15208,8 @@
1481815208 // break;
1481915209 case 'T':
1482015210 CACHETEXTURE ^= true;
14821
- textures.clear();
15211
+ texturepigment.clear();
15212
+ texturebump.clear();
1482215213 // repaint();
1482315214 break;
1482415215 case 'Y':
....@@ -14903,7 +15294,9 @@
1490315294 case 'E' : COMPACT ^= true;
1490415295 repaint();
1490515296 break;
14906
- case 'W' : DEBUGHSB ^= true;
15297
+ case 'W' : // Wide Window (fullscreen)
15298
+ //DEBUGHSB ^= true;
15299
+ ObjEditor.theFrame.ToggleFullScreen();
1490715300 repaint();
1490815301 break;
1490915302 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14929,13 +15322,7 @@
1492915322 repaint();
1493015323 break;
1493115324 case 'l':
14932
- lightMode ^= true;
14933
- Globals.lighttouched = true;
14934
- manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
14935
- targetLookAt.set(manipCamera.lookAt);
14936
- repaint();
14937
- break;
14938
- case 'L':
15325
+ //case 'L':
1493915326 if (lightMode)
1494015327 {
1494115328 lightMode = false;
....@@ -14999,20 +15386,24 @@
1499915386 OCCLUSION_CULLING ^= true;
1500015387 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1500115388 break;
15002
- case '0': envyoff ^= true; repaint(); break;
15389
+ //case '0': envyoff ^= true; repaint(); break;
1500315390 case '1':
1500415391 case '2':
1500515392 case '3':
1500615393 case '4':
1500715394 case '5':
15008
- newenvy = Character.getNumericValue(key);
15009
- repaint();
15010
- break;
1501115395 case '6':
1501215396 case '7':
1501315397 case '8':
1501415398 case '9':
15015
- 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
+ }
1501615407 repaint();
1501715408 break;
1501815409 case '!':
....@@ -15078,11 +15469,14 @@
1507815469 case '_':
1507915470 kompactbit = 5;
1508015471 break;
15081
- case '+':
15082
- kompactbit = 6;
15083
- break;
15472
+// case '+':
15473
+// kompactbit = 6;
15474
+// break;
1508415475 case ' ':
15085
- ObjEditor.theFrame.ToggleFullScreen();
15476
+ lightMode ^= true;
15477
+ Globals.lighttouched = true;
15478
+ manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
15479
+ targetLookAt.set(manipCamera.lookAt);
1508615480 repaint();
1508715481 break;
1508815482 //case '`' :
....@@ -15129,8 +15523,9 @@
1512915523 case DELETE:
1513015524 ClearSelection();
1513115525 break;
15132
- /*
1513315526 case '+':
15527
+
15528
+ /*
1513415529 //fontsize += 1;
1513515530 bbzoom *= 2;
1513615531 repaint();
....@@ -15147,17 +15542,17 @@
1514715542 case '=':
1514815543 IncDepth();
1514915544 //fontsize += 1;
15150
- object.editWindow.refreshContents(true);
15545
+ object.GetWindow().refreshContents(true);
1515115546 maskbit = 6;
1515215547 break;
1515315548 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1515415549 DecDepth();
1515515550 maskbit = 5;
1515615551 //if(fontsize > 1) fontsize -= 1;
15157
- if (object.editWindow == null)
15158
- new Exception().printStackTrace();
15159
- else
15160
- object.editWindow.refreshContents(true);
15552
+// if (object.editWindow == null)
15553
+// new Exception().printStackTrace();
15554
+// else
15555
+ object.GetWindow().refreshContents(true);
1516115556 break;
1516215557 case '{':
1516315558 manipCamera.shaper_fovy /= 1.1;
....@@ -15381,7 +15776,7 @@
1538115776 }
1538215777 */
1538315778
15384
- object.editWindow.EditSelection(false);
15779
+ object.GetWindow().EditSelection(false);
1538515780 }
1538615781
1538715782 void SelectParent()
....@@ -15398,10 +15793,10 @@
1539815793 {
1539915794 //selectees.remove(i);
1540015795 System.out.println("select parent of " + elem);
15401
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15796
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1540215797 } else
1540315798 {
15404
- group.editWindow.Select(elem.GetTreePath(), first, true);
15799
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1540515800 }
1540615801
1540715802 first = false;
....@@ -15443,12 +15838,12 @@
1544315838 for (int j = 0; j < group.children.size(); j++)
1544415839 {
1544515840 elem = (Object3D) group.children.elementAt(j);
15446
- object.editWindow.Select(elem.GetTreePath(), first, true);
15841
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1544715842 first = false;
1544815843 }
1544915844 } else
1545015845 {
15451
- object.editWindow.Select(elem.GetTreePath(), first, true);
15846
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1545215847 }
1545315848
1545415849 first = false;
....@@ -15459,21 +15854,21 @@
1545915854 {
1546015855 //Composite group = (Composite) object;
1546115856 Object3D group = object;
15462
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15857
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1546315858 }
1546415859
1546515860 void ResetTransform(int mask)
1546615861 {
1546715862 //Composite group = (Composite) object;
1546815863 Object3D group = object;
15469
- group.editWindow.ResetTransform(mask);
15864
+ group.GetWindow().ResetTransform(mask);
1547015865 }
1547115866
1547215867 void FlipTransform()
1547315868 {
1547415869 //Composite group = (Composite) object;
1547515870 Object3D group = object;
15476
- group.editWindow.FlipTransform();
15871
+ group.GetWindow().FlipTransform();
1547715872 // group.editWindow.ReduceMesh(true);
1547815873 }
1547915874
....@@ -15481,7 +15876,7 @@
1548115876 {
1548215877 //Composite group = (Composite) object;
1548315878 Object3D group = object;
15484
- group.editWindow.PrintMemory();
15879
+ group.GetWindow().PrintMemory();
1548515880 // group.editWindow.ReduceMesh(true);
1548615881 }
1548715882
....@@ -15489,7 +15884,7 @@
1548915884 {
1549015885 //Composite group = (Composite) object;
1549115886 Object3D group = object;
15492
- group.editWindow.ResetCentroid();
15887
+ group.GetWindow().ResetCentroid();
1549315888 }
1549415889
1549515890 void IncDepth()
....@@ -15571,8 +15966,6 @@
1557115966
1557215967 int width = getBounds().width;
1557315968 int height = getBounds().height;
15574
- ClickInfo info = new ClickInfo();
15575
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1557615969 //Image img = CreateImage(width, height);
1557715970 //System.out.println("width = " + width + "; height = " + height + "\n");
1557815971
....@@ -15649,48 +16042,77 @@
1564916042 }
1565016043 if (object != null && !hasMarquee)
1565116044 {
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
+
1565216051 if (isRenderer)
1565316052 {
15654
- info.flags++;
16053
+ object.clickInfo.flags++;
1565516054 double frameAspect = (double) width / (double) height;
1565616055 if (frameAspect > renderCamera.aspect)
1565716056 {
1565816057 int desired = (int) ((double) height * renderCamera.aspect);
15659
- info.bounds.width -= width - desired;
15660
- info.bounds.x += (width - desired) / 2;
16058
+ object.clickInfo.bounds.width -= width - desired;
16059
+ object.clickInfo.bounds.x += (width - desired) / 2;
1566116060 } else
1566216061 {
1566316062 int desired = (int) ((double) width / renderCamera.aspect);
15664
- info.bounds.height -= height - desired;
15665
- info.bounds.y += (height - desired) / 2;
16063
+ object.clickInfo.bounds.height -= height - desired;
16064
+ object.clickInfo.bounds.y += (height - desired) / 2;
1566616065 }
1566716066 }
15668
- info.g = gr;
15669
- info.camera = renderCamera;
16067
+
16068
+ object.clickInfo.g = gr;
16069
+ object.clickInfo.camera = renderCamera;
1567016070 /*
1567116071 // Memory intensive (brep.verticescopy)
1567216072 if (!(object instanceof Composite))
1567316073 object.draw(info, 0, false); // SLOW :
1567416074 */
15675
- if (!isRenderer)
16075
+ if (!isRenderer) // && drag)
1567616076 {
15677
- object.drawEditHandles(info, 0);
15678
-
15679
- 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)
1568016080 {
15681
- 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)
1568216087 {
15683
- case Object3D.hitCenter: gr.setColor(Color.pink);
15684
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15685
- break;
15686
- case Object3D.hitRotate: gr.setColor(Color.yellow);
15687
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15688
- break;
15689
- case Object3D.hitScale: gr.setColor(Color.cyan);
15690
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15691
- 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;
1569216095 }
15693
-
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
+ }
1569416116 }
1569516117 }
1569616118 }
....@@ -16172,6 +16594,8 @@
1617216594 private /*static*/ boolean firstime;
1617316595 private /*static*/ cVector newView = new cVector();
1617416596 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"};
1617516599 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1617616600 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1617716601 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16184,29 +16608,67 @@
1618416608 {
1618516609 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1618616610
16611
+ int usedsuf = 0;
16612
+
1618716613 for (int i = 0; i < suffixes.length; i++)
1618816614 {
16189
- String resourceName = basename + suffixes[i] + "." + suffix;
16190
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16191
- mipmapped,
16192
- FileUtil.getFileSuffix(resourceName));
16193
- if (data == null)
16615
+ String[] suffixe = suffixes;
16616
+ String[] fallback = suffixes2;
16617
+ String[] fallfallback = suffixes3;
16618
+
16619
+ for (int c=usedsuf; --c>=0;)
1619416620 {
16195
- throw new IOException("Unable to load texture " + resourceName);
16621
+// String[] temp = suffixe;
16622
+// suffixe = fallback;
16623
+// fallback = fallfallback;
16624
+// fallfallback = temp;
1619616625 }
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
+
1619716654 //System.out.println("Target = " + targets[i]);
1619816655 cubemap.updateImage(data, targets[i]);
1619916656 }
1620016657
1620116658 return cubemap;
1620216659 }
16660
+
1620316661 int bigsphere = -1;
1620416662
1620516663 float BGcolor = 0.5f;
1620616664
16207
- private void DrawSkyBox(GL gl)
16665
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16666
+
16667
+ private void DrawSkyBox(GL gl, float ratio)
1620816668 {
16209
- if (envyoff || cubemap == null)
16669
+ if (//envyoff ||
16670
+ WIREFRAME ||
16671
+ cubemap == null)
1621016672 {
1621116673 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1621216674 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16221,7 +16683,17 @@
1622116683 // Compensates for ExaminerViewer's modification of modelview matrix
1622216684 gl.glMatrixMode(GL.GL_MODELVIEW);
1622316685 gl.glLoadIdentity();
16686
+ gl.glScalef(1,ratio,1);
1622416687
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
+
1622516697 //gl.glActiveTexture(GL.GL_TEXTURE1);
1622616698 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1622716699
....@@ -16253,6 +16725,7 @@
1625316725 {
1625416726 gl.glScalef(1.0f, -1.0f, 1.0f);
1625516727 }
16728
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1625616729 gl.glMultMatrixd(viewrot_1, 0);
1625716730 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1625816731 //viewer.updateInverseRotation(gl);
....@@ -16488,6 +16961,14 @@
1648816961 }
1648916962 }
1649016963
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
+
1649116972 class SelectBuffer implements GLEventListener
1649216973 {
1649316974
....@@ -16503,7 +16984,7 @@
1650316984 //new Exception().printStackTrace();
1650416985 System.out.println("select buffer init");
1650516986 // Use debug pipeline
16506
- drawable.setGL(new DebugGL(drawable.getGL()));
16987
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1650716988
1650816989 GL gl = drawable.getGL();
1650916990
....@@ -16567,6 +17048,17 @@
1656717048
1656817049 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1656917050
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
+
1657017062 //int tmp = selection_view;
1657117063 //selection_view = -1;
1657217064 int temp = DrawMode();
....@@ -16578,6 +17070,17 @@
1657817070 // temp = DEFAULT; // patch for selection debug
1657917071 Globals.drawMode = temp; // WARNING
1658017072
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
+
1658117084 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1658217085
1658317086 // trying different ways of getting the depth info over
....@@ -16681,29 +17184,31 @@
1668117184 }
1668217185
1668317186 if (!movingcamera && !PAINTMODE)
16684
- object.editWindow.ScreenFitPoint(); // fev 2014
17187
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1668517188
16686
- 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)
1668717190 {
16688
- 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);
1668917192
16690
- Object3D group = new Object3D("inst" + paintcount++);
17193
+ if (object.GetWindow().copy.selection.Size() > 0)
17194
+ {
17195
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1669117196
16692
- group.CreateMaterial(); // use a void leaf to select instances
16693
-
16694
- group.add(paintobj); // link
16695
-
16696
- object.editWindow.SnapObject(group);
16697
-
16698
- Object3D folder = object.editWindow.copy;
16699
-
16700
- if (object.editWindow.copy.selection.Size() > 0)
16701
- folder = object.editWindow.copy.selection.elementAt(0);
16702
-
16703
- folder.add(group);
16704
-
16705
- object.editWindow.ResetModel();
16706
- 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
+ }
1670717212 }
1670817213 else
1670917214 paintcount = 0;
....@@ -16742,6 +17247,11 @@
1674217247 //System.out.println("objects[color] = " + objects[color]);
1674317248 //objects[color].Select();
1674417249 indexcount = 0;
17250
+ ObjEditor window = object.GetWindow();
17251
+ if (window != null && deselect)
17252
+ {
17253
+ window.Select(null, deselect, true);
17254
+ }
1674517255 object.Select(color, deselect);
1674617256 }
1674717257