Normand Briere
2019-07-29 c6c3f0948bd31603547ef8ce47a7784a9a4d55c2
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,13 @@
90729314 static double[] model = new double[16];
90739315 double[] camera2light = new double[16];
90749316 double[] light2camera = new double[16];
9075
- int newenvy = -1;
9317
+
9318
+ //int newenvy = -1;
90769319 boolean envyoff = true; // false;
9320
+ String skyboxname = "";
9321
+ String skyboxext;
9322
+ String loadedskyboxname = "";
9323
+
90779324 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
90789325 //float[] light0 = { 0,0,0 };
90799326 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9366,11 +9613,35 @@
93669613 jy8[3] = 0.5f;
93679614 }
93689615
9369
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9616
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
93709617 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
93719618 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
93729619 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
93739620
9621
+ void ResetOptions()
9622
+ {
9623
+ options1[0] = 100;
9624
+ options1[1] = 0.025f;
9625
+ options1[2] = 0.01f;
9626
+ options1[3] = 0;
9627
+ options1[4] = 0;
9628
+
9629
+ options2[0] = 0;
9630
+ options2[1] = 0.75f;
9631
+ options2[2] = 0;
9632
+ options2[3] = 0;
9633
+
9634
+ options3[0] = 1;
9635
+ options3[1] = 1;
9636
+ options3[2] = 1;
9637
+ options3[3] = 0;
9638
+
9639
+ options4[0] = 1;
9640
+ options4[1] = 0;
9641
+ options4[2] = 1;
9642
+ options4[3] = 0;
9643
+ }
9644
+
93749645 static int imagecount = 0; // movie generation
93759646
93769647 static int jitter = 0;
....@@ -9467,7 +9738,7 @@
94679738
94689739 if (renderCamera != lightCamera)
94699740 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9470
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
9741
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
94719742
94729743 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
94739744
....@@ -9483,7 +9754,7 @@
94839754
94849755 if (renderCamera != lightCamera)
94859756 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9486
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
9757
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
94879758
94889759 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
94899760
....@@ -9529,10 +9800,12 @@
95299800 rati = 1 / rati;
95309801 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
95319802 }
9532
- assert (newenvy == -1);
9803
+
9804
+ //assert (newenvy == -1);
9805
+
95339806 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
95349807 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9535
- DrawSkyBox(gl);
9808
+ DrawSkyBox(gl, (float)rati);
95369809 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
95379810 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
95389811 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10481,6 +10754,7 @@
1048110754 ANTIALIAS = 0;
1048210755 //System.out.println("RESTART");
1048310756 AAtimer.restart();
10757
+ Globals.TIMERRUNNING = true;
1048410758 }
1048510759 }
1048610760 }
....@@ -10683,7 +10957,7 @@
1068310957 // if (parentcam != renderCamera) // not a light
1068410958 if (cam != lightCamera)
1068510959 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10686
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
10960
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1068710961
1068810962 for (int j = 0; j < 4; j++)
1068910963 {
....@@ -10698,7 +10972,7 @@
1069810972 // if (parentcam != renderCamera) // not a light
1069910973 if (cam != lightCamera)
1070010974 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10701
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
10975
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1070210976
1070310977 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1070410978
....@@ -10784,13 +11058,19 @@
1078411058 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1078511059 }
1078611060
10787
- if (newenvy > -1)
11061
+// if (newenvy > -1)
11062
+// {
11063
+// LoadEnvy(newenvy);
11064
+// }
11065
+//
11066
+// newenvy = -1;
11067
+
11068
+ if (!skyboxname.equals(this.loadedskyboxname))
1078811069 {
10789
- LoadEnvy(newenvy);
11070
+ LoadSkybox(skyboxname + "/", skyboxext, false);
11071
+ loadedskyboxname = skyboxname;
1079011072 }
10791
-
10792
- newenvy = -1;
10793
-
11073
+
1079411074 ratio = ((double) getWidth()) / getHeight();
1079511075 //System.out.println("ratio = " + ratio);
1079611076
....@@ -10806,7 +11086,7 @@
1080611086
1080711087 if (!IsFrozen() && !ambientOcclusion)
1080811088 {
10809
- DrawSkyBox(gl);
11089
+ DrawSkyBox(gl, (float)ratio);
1081011090 }
1081111091
1081211092 //if (selection_view == -1)
....@@ -10989,9 +11269,9 @@
1098911269
1099011270 gl.glMatrixMode(GL.GL_MODELVIEW);
1099111271
10992
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10993
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10994
-//gl.glEnable(gl.GL_MULTISAMPLE);
11272
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11273
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11274
+gl.glEnable(gl.GL_MULTISAMPLE);
1099511275 } else
1099611276 {
1099711277 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -11002,7 +11282,7 @@
1100211282 //System.out.println("BLENDING ON");
1100311283 gl.glEnable(GL.GL_BLEND);
1100411284 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
11005
-
11285
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1100611286 gl.glMatrixMode(gl.GL_PROJECTION);
1100711287 gl.glLoadIdentity();
1100811288
....@@ -11251,7 +11531,7 @@
1125111531 }
1125211532 }
1125311533
11254
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11534
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1125511535 {
1125611536 //gl.glDepthFunc(GL.GL_LEQUAL);
1125711537 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11259,24 +11539,21 @@
1125911539
1126011540 boolean texon = textureon;
1126111541
11262
- if (RENDERPROGRAM > 0)
11263
- {
11264
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11265
- textureon = false;
11266
- }
11542
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11543
+ textureon = false;
11544
+
1126711545 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1126811546 //System.out.println("ALLO");
1126911547 gl.glColorMask(false, false, false, false);
1127011548 DrawObject(gl);
11271
- if (RENDERPROGRAM > 0)
11272
- {
11273
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11274
- textureon = texon;
11275
- }
11549
+
11550
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11551
+ textureon = texon;
11552
+
1127611553 gl.glColorMask(true, true, true, true);
1127711554
1127811555 gl.glDepthFunc(GL.GL_EQUAL);
11279
- //gl.glDepthMask(false);
11556
+ gl.glDepthMask(false);
1128011557 }
1128111558
1128211559 if (false) // DrawMode() == SHADOW)
....@@ -11479,13 +11756,16 @@
1147911756
1148011757 void DrawObject(GL gl, boolean draw)
1148111758 {
11759
+ // To clear camera values
11760
+ ResetOptions();
11761
+
1148211762 //System.out.println("DRAW OBJECT " + mouseDown);
1148311763 // DrawMode() = SELECTION;
1148411764 //GL gl = getGL();
1148511765 if ((TRACK || SHADOWTRACK) || zoomonce)
1148611766 {
1148711767 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11488
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11768
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1148911769 pingthread.StepToTarget(true); // true);
1149011770 // zoomonce = false;
1149111771 }
....@@ -11613,20 +11893,32 @@
1161311893 ReleaseTextures(DEFAULT_TEXTURES);
1161411894
1161511895 if (CLEANCACHE)
11616
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11896
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1161711897 {
11618
- String tex = e.nextElement();
11898
+ cTexture tex = e.nextElement();
1161911899
1162011900 // System.out.println("Texture --------- " + tex);
1162111901
11622
- if (tex.equals("WHITE_NOISE"))
11902
+ if (tex.equals("WHITE_NOISE:"))
1162311903 continue;
1162411904
11625
- if (!usedtextures.containsKey(tex))
11905
+ if (!usedtextures.contains(tex))
1162611906 {
11907
+ CacheTexture gettex = texturepigment.get(tex);
1162711908 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11628
- textures.get(tex).texture.dispose();
11629
- textures.remove(tex);
11909
+ if (gettex != null)
11910
+ {
11911
+ gettex.texture.dispose();
11912
+ texturepigment.remove(tex);
11913
+ }
11914
+
11915
+ gettex = texturebump.get(tex);
11916
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11917
+ if (gettex != null)
11918
+ {
11919
+ gettex.texture.dispose();
11920
+ texturebump.remove(tex);
11921
+ }
1163011922 }
1163111923 }
1163211924 }
....@@ -12046,7 +12338,7 @@
1204612338 for (int i = tp.size(); --i >= 0;)
1204712339 {
1204812340 //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12049
- LA.xformPos(light, tp.get(i).GlobalTransform(), light);
12341
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1205012342 }
1205112343
1205212344
....@@ -12154,8 +12446,76 @@
1215412446
1215512447 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1215612448
12449
+ String program0 =
12450
+ // Min shader
12451
+ "!!ARBfp1.0\n" +
12452
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12453
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12454
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12455
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12456
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12457
+ "PARAM light2cam0 = program.env[10];" +
12458
+ "PARAM light2cam1 = program.env[11];" +
12459
+ "PARAM light2cam2 = program.env[12];" +
12460
+ "TEMP temp;" +
12461
+ "TEMP light;" +
12462
+ "TEMP ndotl;" +
12463
+ "TEMP normal;" +
12464
+ "TEMP depth;" +
12465
+ "TEMP eye;" +
12466
+ "TEMP pos;" +
12467
+
12468
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12469
+ Normalize("normal") +
12470
+ "MOV light, state.light[0].position;" +
12471
+ "DP3 ndotl.x, light, normal;" +
12472
+
12473
+ // shadow
12474
+ "MOV pos, fragment.texcoord[1];" +
12475
+ "MOV temp, pos;" +
12476
+ ShadowTextureFetch("depth", "temp", "1") +
12477
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12478
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12479
+
12480
+ // No shadow when out of frustum
12481
+ //"SGE temp.y, depth.z, zero123.y;" +
12482
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12483
+
12484
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12485
+
12486
+ // Backlit
12487
+ "MOV pos.w, zero123.y;" +
12488
+ "DP4 eye.x, pos, light2cam0;" +
12489
+ "DP4 eye.y, pos, light2cam1;" +
12490
+ "DP4 eye.z, pos, light2cam2;" +
12491
+ Normalize("eye") +
12492
+
12493
+ "DP3 ndotl.y, -eye, normal;" +
12494
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12495
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12496
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12497
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12498
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12499
+
12500
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12501
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12502
+
12503
+ // Pigment
12504
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12505
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12506
+ "MUL temp, temp, ndotl.x;" +
12507
+
12508
+ "MUL temp, temp, zero123.z;" +
12509
+
12510
+ //"MUL temp, temp, ndotl.y;" +
12511
+
12512
+ "MOV temp.w, zero123.y;" + // reset alpha
12513
+ "MOV result.color, temp;" +
12514
+ "END";
12515
+
1215712516 String program =
1215812517 "!!ARBfp1.0\n" +
12518
+
1215912519 //"OPTION ARB_fragment_program_shadow;" +
1216012520 "PARAM light2cam0 = program.env[10];" +
1216112521 "PARAM light2cam1 = program.env[11];" +
....@@ -12270,8 +12630,7 @@
1227012630 "TEMP shininess;" +
1227112631 "\n" +
1227212632 "MOV texSamp, one;" +
12273
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12274
-
12633
+
1227512634 "MOV mapgrid.x, one2048th.x;" +
1227612635 "MOV temp, fragment.texcoord[1];" +
1227712636 /*
....@@ -12292,20 +12651,20 @@
1229212651 "MUL temp, floor, mapgrid.x;" +
1229312652 //"TEX depth0, temp, texture[1], 2D;" +
1229412653 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12295
- TextureFetch("depth0", "temp", "1") +
12654
+ ShadowTextureFetch("depth0", "temp", "1") +
1229612655 "") +
1229712656 "ADD temp.x, temp.x, mapgrid.x;" +
1229812657 //"TEX depth1, temp, texture[1], 2D;" +
1229912658 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12300
- TextureFetch("depth1", "temp", "1") +
12659
+ ShadowTextureFetch("depth1", "temp", "1") +
1230112660 "") +
1230212661 "ADD temp.y, temp.y, mapgrid.x;" +
1230312662 //"TEX depth2, temp, texture[1], 2D;" +
12304
- TextureFetch("depth2", "temp", "1") +
12663
+ ShadowTextureFetch("depth2", "temp", "1") +
1230512664 "SUB temp.x, temp.x, mapgrid.x;" +
1230612665 //"TEX depth3, temp, texture[1], 2D;" +
1230712666 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12308
- TextureFetch("depth3", "temp", "1") +
12667
+ ShadowTextureFetch("depth3", "temp", "1") +
1230912668 "") +
1231012669 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1231112670 //"MOV params, material;" +
....@@ -12676,10 +13035,10 @@
1267613035 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1267713036 "") +
1267813037
12679
- // display shadow only (bump == 0)
13038
+ // display shadow only (fakedepth == 0)
1268013039 "SUB temp.x, half.x, shadow.x;" +
1268113040 "MOV temp.y, -params5.z;" + // params6.x;" +
12682
- "SLT temp.z, temp.y, -one2048th.x;" +
13041
+ "SLT temp.z, temp.y, -c256i.x;" +
1268313042 "SUB temp.y, one.x, temp.z;" +
1268413043 "MUL temp.x, temp.x, temp.y;" +
1268513044 "KIL temp.x;" +
....@@ -13103,25 +13462,26 @@
1310313462 return out;
1310413463 }
1310513464
13106
- String TextureFetch(String dest, String src, String unit)
13465
+ // Also does frustum culling
13466
+ String ShadowTextureFetch(String dest, String src, String unit)
1310713467 {
1310813468 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1310913469 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1311013470 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13471
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13472
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1311113473 "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;" +
13474
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13475
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1311613476 //"SWZ buffer, temp, w,w,w,w;";
13117
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13477
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1311813478 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1311913479 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1312013480 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13121
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13481
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1312213482
13123
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13124
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13483
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13484
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1312513485 }
1312613486
1312713487 String Shadow(String depth, String shadow)
....@@ -13168,7 +13528,7 @@
1316813528 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1316913529 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1317013530
13171
- // No shadow when out of frustrum
13531
+ // No shadow when out of frustum
1317213532 "SGE temp.x, " + depth + ".z, one.z;" +
1317313533 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1317413534 "";
....@@ -13333,9 +13693,10 @@
1333313693 "DP3 " + dest + ".z," + "normals," + "eye;" +
1333413694 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1333513695 //"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;" +
13696
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13697
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13698
+
13699
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1333913700 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1334013701 "RCP " + dest + ".w," + dest + ".w;" +
1334113702 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13840,6 +14201,7 @@
1384014201 else
1384114202 if (evt.getSource() == AAtimer)
1384214203 {
14204
+ Globals.TIMERRUNNING = false;
1384314205 if (mouseDown)
1384414206 {
1384514207 //new Exception().printStackTrace();
....@@ -13899,7 +14261,7 @@
1389914261
1390014262 // fev 2014???
1390114263 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13902
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14264
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1390314265 pingthread.StepToTarget(true); // true);
1390414266 }
1390514267 // if (!LIVE)
....@@ -13914,6 +14276,7 @@
1391414276 return;
1391514277
1391614278 AAtimer.restart(); //
14279
+ Globals.TIMERRUNNING = true;
1391714280
1391814281 // waslive = LIVE;
1391914282 // LIVE = false;
....@@ -13963,14 +14326,15 @@
1396314326 drag = false;
1396414327 //System.out.println("Mouse DOWN");
1396514328 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);
14329
+ //ClickInfo info = new ClickInfo();
14330
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14331
+ object.clickInfo.pane = this;
14332
+ object.clickInfo.camera = renderCamera;
14333
+ object.clickInfo.x = x;
14334
+ object.clickInfo.y = y;
14335
+ object.clickInfo.modifiers = modifiersex;
14336
+ editObj = object.doEditClick(//info,
14337
+ 0);
1397414338 if (!editObj)
1397514339 {
1397614340 hasMarquee = true;
....@@ -14252,12 +14616,12 @@
1425214616 void GoDown(int mod)
1425314617 {
1425414618 MODIFIERS |= COMMAND;
14255
- /*
14619
+ /**/
1425614620 if((mod&SHIFT) == SHIFT)
1425714621 manipCamera.RotatePosition(0, -speed);
1425814622 else
14259
- manipCamera.BackForth(0, -speed*delta, getWidth());
14260
- */
14623
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14624
+ /**/
1426114625 if ((mod & SHIFT) == SHIFT)
1426214626 {
1426314627 mouseMode = mouseMode; // VR??
....@@ -14273,12 +14637,12 @@
1427314637 void GoUp(int mod)
1427414638 {
1427514639 MODIFIERS |= COMMAND;
14276
- /*
14640
+ /**/
1427714641 if((mod&SHIFT) == SHIFT)
1427814642 manipCamera.RotatePosition(0, speed);
1427914643 else
14280
- manipCamera.BackForth(0, speed*delta, getWidth());
14281
- */
14644
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14645
+ /**/
1428214646 if ((mod & SHIFT) == SHIFT)
1428314647 {
1428414648 mouseMode = mouseMode;
....@@ -14294,12 +14658,12 @@
1429414658 void GoLeft(int mod)
1429514659 {
1429614660 MODIFIERS |= COMMAND;
14297
- /*
14661
+ /**/
1429814662 if((mod&SHIFT) == SHIFT)
14299
- manipCamera.RotatePosition(speed, 0);
14300
- else
1430114663 manipCamera.Translate(speed*delta, 0, getWidth());
14302
- */
14664
+ else
14665
+ manipCamera.RotatePosition(speed, 0);
14666
+ /**/
1430314667 if ((mod & SHIFT) == SHIFT)
1430414668 {
1430514669 mouseMode = mouseMode;
....@@ -14315,12 +14679,12 @@
1431514679 void GoRight(int mod)
1431614680 {
1431714681 MODIFIERS |= COMMAND;
14318
- /*
14682
+ /**/
1431914683 if((mod&SHIFT) == SHIFT)
14320
- manipCamera.RotatePosition(-speed, 0);
14321
- else
1432214684 manipCamera.Translate(-speed*delta, 0, getWidth());
14323
- */
14685
+ else
14686
+ manipCamera.RotatePosition(-speed, 0);
14687
+ /**/
1432414688 if ((mod & SHIFT) == SHIFT)
1432514689 {
1432614690 mouseMode = mouseMode;
....@@ -14370,15 +14734,16 @@
1437014734 if (editObj)
1437114735 {
1437214736 drag = true;
14373
- ClickInfo info = new ClickInfo();
14374
- info.bounds.setBounds(0, 0,
14737
+ //ClickInfo info = new ClickInfo();
14738
+ object.clickInfo.bounds.setBounds(0, 0,
1437514739 (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);
14740
+ object.clickInfo.pane = this;
14741
+ object.clickInfo.camera = renderCamera;
14742
+ object.clickInfo.x = x;
14743
+ object.clickInfo.y = y;
14744
+ object //.GetWindow().copy
14745
+ .doEditDrag(//info,
14746
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1438214747 } else
1438314748 {
1438414749 if (x < startX)
....@@ -14527,24 +14892,27 @@
1452714892 }
1452814893 }
1452914894
14895
+// ClickInfo clickInfo = new ClickInfo();
14896
+
1453014897 public void mouseMoved(MouseEvent e)
1453114898 {
1453214899 //System.out.println("mouseMoved: " + e);
1453314900 if (isRenderer)
1453414901 return;
1453514902
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;
14903
+ // Mouse cursor feedback
14904
+ object.clickInfo.x = e.getX();
14905
+ object.clickInfo.y = e.getY();
14906
+ object.clickInfo.modifiers = e.getModifiersEx();
14907
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14908
+ object.clickInfo.pane = this;
14909
+ object.clickInfo.camera = renderCamera;
1454314910 if (!isRenderer)
1454414911 {
1454514912 //ObjEditor editWindow = object.editWindow;
1454614913 //Object3D copy = editWindow.copy;
14547
- if (object.doEditClick(ci, 0))
14914
+ if (object.doEditClick(//clickInfo,
14915
+ 0))
1454814916 {
1454914917 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1455014918 } else
....@@ -14559,7 +14927,8 @@
1455914927 Globals.MOUSEDRAGGED = false;
1456014928
1456114929 movingcamera = false;
14562
- X = Y = 0;
14930
+ X = 0; // getBounds().width/2;
14931
+ Y = 0; // getBounds().height/2;
1456314932 //System.out.println("mouseReleased: " + e);
1456414933 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1456514934 }
....@@ -14815,7 +15184,8 @@
1481515184 // break;
1481615185 case 'T':
1481715186 CACHETEXTURE ^= true;
14818
- textures.clear();
15187
+ texturepigment.clear();
15188
+ texturebump.clear();
1481915189 // repaint();
1482015190 break;
1482115191 case 'Y':
....@@ -14900,7 +15270,9 @@
1490015270 case 'E' : COMPACT ^= true;
1490115271 repaint();
1490215272 break;
14903
- case 'W' : DEBUGHSB ^= true;
15273
+ case 'W' : // Wide Window (fullscreen)
15274
+ //DEBUGHSB ^= true;
15275
+ ObjEditor.theFrame.ToggleFullScreen();
1490415276 repaint();
1490515277 break;
1490615278 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14926,13 +15298,7 @@
1492615298 repaint();
1492715299 break;
1492815300 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':
15301
+ //case 'L':
1493615302 if (lightMode)
1493715303 {
1493815304 lightMode = false;
....@@ -15002,14 +15368,18 @@
1500215368 case '3':
1500315369 case '4':
1500415370 case '5':
15005
- newenvy = Character.getNumericValue(key);
15006
- repaint();
15007
- break;
1500815371 case '6':
1500915372 case '7':
1501015373 case '8':
1501115374 case '9':
15012
- BGcolor = (key - '6')/3.f;
15375
+ if (envyoff)
15376
+ {
15377
+ BGcolor = (key - '1')/8.f;
15378
+ }
15379
+ else
15380
+ {
15381
+ //newenvy = Character.getNumericValue(key);
15382
+ }
1501315383 repaint();
1501415384 break;
1501515385 case '!':
....@@ -15075,11 +15445,14 @@
1507515445 case '_':
1507615446 kompactbit = 5;
1507715447 break;
15078
- case '+':
15079
- kompactbit = 6;
15080
- break;
15448
+// case '+':
15449
+// kompactbit = 6;
15450
+// break;
1508115451 case ' ':
15082
- ObjEditor.theFrame.ToggleFullScreen();
15452
+ lightMode ^= true;
15453
+ Globals.lighttouched = true;
15454
+ manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
15455
+ targetLookAt.set(manipCamera.lookAt);
1508315456 repaint();
1508415457 break;
1508515458 //case '`' :
....@@ -15126,8 +15499,9 @@
1512615499 case DELETE:
1512715500 ClearSelection();
1512815501 break;
15129
- /*
1513015502 case '+':
15503
+
15504
+ /*
1513115505 //fontsize += 1;
1513215506 bbzoom *= 2;
1513315507 repaint();
....@@ -15144,17 +15518,17 @@
1514415518 case '=':
1514515519 IncDepth();
1514615520 //fontsize += 1;
15147
- object.editWindow.refreshContents(true);
15521
+ object.GetWindow().refreshContents(true);
1514815522 maskbit = 6;
1514915523 break;
1515015524 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1515115525 DecDepth();
1515215526 maskbit = 5;
1515315527 //if(fontsize > 1) fontsize -= 1;
15154
- if (object.editWindow == null)
15155
- new Exception().printStackTrace();
15156
- else
15157
- object.editWindow.refreshContents(true);
15528
+// if (object.editWindow == null)
15529
+// new Exception().printStackTrace();
15530
+// else
15531
+ object.GetWindow().refreshContents(true);
1515815532 break;
1515915533 case '{':
1516015534 manipCamera.shaper_fovy /= 1.1;
....@@ -15378,7 +15752,7 @@
1537815752 }
1537915753 */
1538015754
15381
- object.editWindow.EditSelection();
15755
+ object.GetWindow().EditSelection(false);
1538215756 }
1538315757
1538415758 void SelectParent()
....@@ -15395,10 +15769,10 @@
1539515769 {
1539615770 //selectees.remove(i);
1539715771 System.out.println("select parent of " + elem);
15398
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15772
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1539915773 } else
1540015774 {
15401
- group.editWindow.Select(elem.GetTreePath(), first, true);
15775
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1540215776 }
1540315777
1540415778 first = false;
....@@ -15440,12 +15814,12 @@
1544015814 for (int j = 0; j < group.children.size(); j++)
1544115815 {
1544215816 elem = (Object3D) group.children.elementAt(j);
15443
- object.editWindow.Select(elem.GetTreePath(), first, true);
15817
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1544415818 first = false;
1544515819 }
1544615820 } else
1544715821 {
15448
- object.editWindow.Select(elem.GetTreePath(), first, true);
15822
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1544915823 }
1545015824
1545115825 first = false;
....@@ -15456,21 +15830,21 @@
1545615830 {
1545715831 //Composite group = (Composite) object;
1545815832 Object3D group = object;
15459
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15833
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1546015834 }
1546115835
1546215836 void ResetTransform(int mask)
1546315837 {
1546415838 //Composite group = (Composite) object;
1546515839 Object3D group = object;
15466
- group.editWindow.ResetTransform(mask);
15840
+ group.GetWindow().ResetTransform(mask);
1546715841 }
1546815842
1546915843 void FlipTransform()
1547015844 {
1547115845 //Composite group = (Composite) object;
1547215846 Object3D group = object;
15473
- group.editWindow.FlipTransform();
15847
+ group.GetWindow().FlipTransform();
1547415848 // group.editWindow.ReduceMesh(true);
1547515849 }
1547615850
....@@ -15478,7 +15852,7 @@
1547815852 {
1547915853 //Composite group = (Composite) object;
1548015854 Object3D group = object;
15481
- group.editWindow.PrintMemory();
15855
+ group.GetWindow().PrintMemory();
1548215856 // group.editWindow.ReduceMesh(true);
1548315857 }
1548415858
....@@ -15486,7 +15860,7 @@
1548615860 {
1548715861 //Composite group = (Composite) object;
1548815862 Object3D group = object;
15489
- group.editWindow.ResetCentroid();
15863
+ group.GetWindow().ResetCentroid();
1549015864 }
1549115865
1549215866 void IncDepth()
....@@ -15568,8 +15942,6 @@
1556815942
1556915943 int width = getBounds().width;
1557015944 int height = getBounds().height;
15571
- ClickInfo info = new ClickInfo();
15572
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1557315945 //Image img = CreateImage(width, height);
1557415946 //System.out.println("width = " + width + "; height = " + height + "\n");
1557515947
....@@ -15646,48 +16018,77 @@
1564616018 }
1564716019 if (object != null && !hasMarquee)
1564816020 {
16021
+ if (object.clickInfo == null)
16022
+ object.clickInfo = new ClickInfo();
16023
+ ClickInfo info = object.clickInfo;
16024
+ //ClickInfo info = new ClickInfo();
16025
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16026
+
1564916027 if (isRenderer)
1565016028 {
15651
- info.flags++;
16029
+ object.clickInfo.flags++;
1565216030 double frameAspect = (double) width / (double) height;
1565316031 if (frameAspect > renderCamera.aspect)
1565416032 {
1565516033 int desired = (int) ((double) height * renderCamera.aspect);
15656
- info.bounds.width -= width - desired;
15657
- info.bounds.x += (width - desired) / 2;
16034
+ object.clickInfo.bounds.width -= width - desired;
16035
+ object.clickInfo.bounds.x += (width - desired) / 2;
1565816036 } else
1565916037 {
1566016038 int desired = (int) ((double) width / renderCamera.aspect);
15661
- info.bounds.height -= height - desired;
15662
- info.bounds.y += (height - desired) / 2;
16039
+ object.clickInfo.bounds.height -= height - desired;
16040
+ object.clickInfo.bounds.y += (height - desired) / 2;
1566316041 }
1566416042 }
15665
- info.g = gr;
15666
- info.camera = renderCamera;
16043
+
16044
+ object.clickInfo.g = gr;
16045
+ object.clickInfo.camera = renderCamera;
1566716046 /*
1566816047 // Memory intensive (brep.verticescopy)
1566916048 if (!(object instanceof Composite))
1567016049 object.draw(info, 0, false); // SLOW :
1567116050 */
15672
- if (!isRenderer)
16051
+ if (!isRenderer) // && drag)
1567316052 {
15674
- object.drawEditHandles(info, 0);
15675
-
15676
- if (drag && (X != 0 || Y != 0) && object.selection.Size() > 0)
16053
+ Grafreed.Assert(object != null);
16054
+ Grafreed.Assert(object.selection != null);
16055
+ if (object.selection.Size() > 0)
1567716056 {
15678
- switch (object.selection.get(0).hitSomething)
16057
+ int hitSomething = object.selection.get(0).hitSomething;
16058
+
16059
+ object.clickInfo.DX = 0;
16060
+ object.clickInfo.DY = 0;
16061
+ object.clickInfo.W = 1;
16062
+ if (hitSomething == Object3D.hitCenter)
1567916063 {
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;
16064
+ info.DX = X;
16065
+ if (X != 0)
16066
+ info.DX -= info.bounds.width/2;
16067
+
16068
+ info.DY = Y;
16069
+ if (Y != 0)
16070
+ info.DY -= info.bounds.height/2;
1568916071 }
15690
-
16072
+
16073
+ object.drawEditHandles(//info,
16074
+ 0);
16075
+
16076
+ if (drag && (X != 0 || Y != 0))
16077
+ {
16078
+ switch (hitSomething)
16079
+ {
16080
+ case Object3D.hitCenter: gr.setColor(Color.pink);
16081
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16082
+ break;
16083
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16084
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16085
+ break;
16086
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16087
+ gr.drawLine(X, Y, 0, 0);
16088
+ break;
16089
+ }
16090
+
16091
+ }
1569116092 }
1569216093 }
1569316094 }
....@@ -16169,6 +16570,8 @@
1616916570 private /*static*/ boolean firstime;
1617016571 private /*static*/ cVector newView = new cVector();
1617116572 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16573
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16574
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1617216575 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1617316576 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1617416577 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16181,16 +16584,49 @@
1618116584 {
1618216585 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1618316586
16587
+ int usedsuf = 0;
16588
+
1618416589 for (int i = 0; i < suffixes.length; i++)
1618516590 {
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)
16591
+ String[] suffixe = suffixes;
16592
+ String[] fallback = suffixes2;
16593
+ String[] fallfallback = suffixes3;
16594
+
16595
+ for (int c=usedsuf; --c>=0;)
1619116596 {
16192
- throw new IOException("Unable to load texture " + resourceName);
16597
+// String[] temp = suffixe;
16598
+// suffixe = fallback;
16599
+// fallback = fallfallback;
16600
+// fallfallback = temp;
1619316601 }
16602
+
16603
+ String resourceName = basename + suffixe[i] + "." + suffix;
16604
+ TextureData data;
16605
+
16606
+ try
16607
+ {
16608
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16609
+ mipmapped,
16610
+ FileUtil.getFileSuffix(resourceName));
16611
+ }
16612
+ catch (Exception e)
16613
+ {
16614
+ try
16615
+ {
16616
+ resourceName = basename + fallback[i] + "." + suffix;
16617
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16618
+ mipmapped,
16619
+ FileUtil.getFileSuffix(resourceName));
16620
+ }
16621
+ catch (Exception e2)
16622
+ {
16623
+ resourceName = basename + fallfallback[i] + "." + suffix;
16624
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16625
+ mipmapped,
16626
+ FileUtil.getFileSuffix(resourceName));
16627
+ }
16628
+ }
16629
+
1619416630 //System.out.println("Target = " + targets[i]);
1619516631 cubemap.updateImage(data, targets[i]);
1619616632 }
....@@ -16201,7 +16637,9 @@
1620116637
1620216638 float BGcolor = 0.5f;
1620316639
16204
- private void DrawSkyBox(GL gl)
16640
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16641
+
16642
+ private void DrawSkyBox(GL gl, float ratio)
1620516643 {
1620616644 if (envyoff || cubemap == null)
1620716645 {
....@@ -16218,7 +16656,17 @@
1621816656 // Compensates for ExaminerViewer's modification of modelview matrix
1621916657 gl.glMatrixMode(GL.GL_MODELVIEW);
1622016658 gl.glLoadIdentity();
16659
+ gl.glScalef(1,ratio,1);
1622116660
16661
+ colorV[0] = 2;
16662
+ colorV[1] = 2;
16663
+ colorV[2] = 2;
16664
+ colorV[3] = 1;
16665
+ gl.glDisable(gl.GL_COLOR_MATERIAL);
16666
+ gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16667
+
16668
+ gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16669
+
1622216670 //gl.glActiveTexture(GL.GL_TEXTURE1);
1622316671 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1622416672
....@@ -16231,7 +16679,7 @@
1623116679 // GL_NORMAL_MAP texgen mode. Temporarily enabling lighting
1623216680 // causes the normals to be sent down. Thanks to Ken Dyke.
1623316681 //gl.glEnable(GL.GL_LIGHTING);
16234
- gl.glDisable(GL.GL_LIGHTING);
16682
+ gl.glEnable(GL.GL_LIGHTING);
1623516683
1623616684 gl.glTexGeni(GL.GL_S, GL.GL_TEXTURE_GEN_MODE, GL.GL_NORMAL_MAP);
1623716685 gl.glTexGeni(GL.GL_T, GL.GL_TEXTURE_GEN_MODE, GL.GL_NORMAL_MAP);
....@@ -16250,6 +16698,7 @@
1625016698 {
1625116699 gl.glScalef(1.0f, -1.0f, 1.0f);
1625216700 }
16701
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1625316702 gl.glMultMatrixd(viewrot_1, 0);
1625416703 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1625516704 //viewer.updateInverseRotation(gl);
....@@ -16485,6 +16934,14 @@
1648516934 }
1648616935 }
1648716936
16937
+ private Object3D GetFolder()
16938
+ {
16939
+ Object3D folder = object.GetWindow().copy;
16940
+ if (object.GetWindow().copy.selection.Size() > 0)
16941
+ folder = object.GetWindow().copy.selection.elementAt(0);
16942
+ return folder;
16943
+ }
16944
+
1648816945 class SelectBuffer implements GLEventListener
1648916946 {
1649016947
....@@ -16500,7 +16957,7 @@
1650016957 //new Exception().printStackTrace();
1650116958 System.out.println("select buffer init");
1650216959 // Use debug pipeline
16503
- drawable.setGL(new DebugGL(drawable.getGL()));
16960
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1650416961
1650516962 GL gl = drawable.getGL();
1650616963
....@@ -16564,6 +17021,17 @@
1656417021
1656517022 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1656617023
17024
+ if (PAINTMODE)
17025
+ {
17026
+ if (object.GetWindow().copy.selection.Size() > 0)
17027
+ {
17028
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17029
+
17030
+ // Make what you paint not selectable.
17031
+ paintobj.ResetSelectable();
17032
+ }
17033
+ }
17034
+
1656717035 //int tmp = selection_view;
1656817036 //selection_view = -1;
1656917037 int temp = DrawMode();
....@@ -16575,6 +17043,17 @@
1657517043 // temp = DEFAULT; // patch for selection debug
1657617044 Globals.drawMode = temp; // WARNING
1657717045
17046
+ if (PAINTMODE)
17047
+ {
17048
+ if (object.GetWindow().copy.selection.Size() > 0)
17049
+ {
17050
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17051
+
17052
+ // Revert.
17053
+ paintobj.RestoreSelectable();
17054
+ }
17055
+ }
17056
+
1657817057 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1657917058
1658017059 // trying different ways of getting the depth info over
....@@ -16678,29 +17157,31 @@
1667817157 }
1667917158
1668017159 if (!movingcamera && !PAINTMODE)
16681
- object.editWindow.ScreenFitPoint(); // fev 2014
17160
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1668217161
16683
- if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17162
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1668417163 {
16685
- Object3D paintobj = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17164
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1668617165
16687
- Object3D group = new Object3D("inst" + paintcount++);
17166
+ if (object.GetWindow().copy.selection.Size() > 0)
17167
+ {
17168
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1668817169
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();
17170
+ Object3D inst = new Object3D("inst" + paintcount++);
17171
+
17172
+ inst.CreateMaterial(); // use a void leaf to select instances
17173
+
17174
+ inst.add(paintobj); // link
17175
+
17176
+ object.GetWindow().SnapObject(inst);
17177
+
17178
+ Object3D folder = paintFolder; // GetFolder();
17179
+
17180
+ folder.add(inst);
17181
+
17182
+ object.GetWindow().ResetModel();
17183
+ object.GetWindow().refreshContents();
17184
+ }
1670417185 }
1670517186 else
1670617187 paintcount = 0;
....@@ -16739,6 +17220,11 @@
1673917220 //System.out.println("objects[color] = " + objects[color]);
1674017221 //objects[color].Select();
1674117222 indexcount = 0;
17223
+ ObjEditor window = object.GetWindow();
17224
+ if (window != null && deselect)
17225
+ {
17226
+ window.Select(null, deselect, true);
17227
+ }
1674217228 object.Select(color, deselect);
1674317229 }
1674417230