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
....@@ -1447,6 +1497,8 @@
14471497 gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
14481498 }
14491499
1500
+ float[] colorV = new float[4];
1501
+
14501502 void SetColor(Object3D obj, Vertex p0)
14511503 {
14521504 CameraPane display = this;
....@@ -1514,8 +1566,6 @@
15141566 {
15151567 return;
15161568 }
1517
-
1518
- float[] colorV = new float[3];
15191569
15201570 if (false) // marked)
15211571 {
....@@ -2298,10 +2348,17 @@
22982348 HANDLES ^= true;
22992349 }
23002350
2351
+ Object3D paintFolder;
2352
+
23012353 void TogglePaint()
23022354 {
23032355 PAINTMODE ^= true;
23042356 paintcount = 0;
2357
+
2358
+ if (PAINTMODE)
2359
+ {
2360
+ paintFolder = GetFolder();
2361
+ }
23052362 }
23062363
23072364 void SwapCamera(int a, int b)
....@@ -2398,6 +2455,21 @@
23982455 return currentGL;
23992456 }
24002457
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
+
24012473 /**/
24022474 class CacheTexture
24032475 {
....@@ -2406,28 +2478,31 @@
24062478
24072479 int resolution;
24082480
2409
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2481
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
24102482 {
2411
- texture = tex;
2483
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2484
+ texturedata = texdata;
24122485 resolution = res;
24132486 }
24142487 }
24152488 /**/
24162489
24172490 // TEXTURE static Texture texture;
2418
- static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures
2419
- = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>();
2420
- 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
+
24212496 int pigmentdepth = 0;
24222497 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
24232498 int bumpdepth = 0;
24242499 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
24252500 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
24262501 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2427
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2502
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
24282503 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
24292504
2430
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2505
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
24312506 {
24322507 TextureData texturedata = null;
24332508
....@@ -2446,13 +2521,34 @@
24462521 if (bump)
24472522 texturedata = ConvertBump(texturedata, false);
24482523
2449
- com.sun.opengl.util.texture.Texture texture =
2450
- 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);
24512526
2452
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2453
- 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);
24542529
2455
- 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;
24562552 }
24572553
24582554 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3525,6 +3621,8 @@
35253621
35263622 System.out.println("LOADING TEXTURE : " + name);
35273623
3624
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3625
+
35283626 //
35293627 if (false) // compressbit > 0)
35303628 {
....@@ -7923,7 +8021,7 @@
79238021 String pigment = Object3D.GetPigment(tex);
79248022 String bump = Object3D.GetBump(tex);
79258023
7926
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8024
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79278025 {
79288026 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79298027 // System.out.println("; bump = " + bump);
....@@ -7938,8 +8036,8 @@
79388036 pigment = null;
79398037 }
79408038
7941
- ReleaseTexture(bump, true);
7942
- ReleaseTexture(pigment, false);
8039
+ ReleaseTexture(tex, true);
8040
+ ReleaseTexture(tex, false);
79438041 }
79448042
79458043 public void ReleasePigmentTexture(cTexture tex) // INTERFACE
....@@ -7957,7 +8055,7 @@
79578055
79588056 String pigment = Object3D.GetPigment(tex);
79598057
7960
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8058
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79618059 {
79628060 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79638061 // System.out.println("; bump = " + bump);
....@@ -7968,7 +8066,7 @@
79688066 pigment = null;
79698067 }
79708068
7971
- ReleaseTexture(pigment, false);
8069
+ ReleaseTexture(tex, false);
79728070 }
79738071
79748072 public void ReleaseBumpTexture(cTexture tex) // INTERFACE
....@@ -7986,7 +8084,7 @@
79868084
79878085 String bump = Object3D.GetBump(tex);
79888086
7989
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8087
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79908088 {
79918089 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79928090 // System.out.println("; bump = " + bump);
....@@ -7997,10 +8095,10 @@
79978095 bump = null;
79988096 }
79998097
8000
- ReleaseTexture(bump, true);
8098
+ ReleaseTexture(tex, true);
80018099 }
80028100
8003
- void ReleaseTexture(String tex, boolean bump)
8101
+ void ReleaseTexture(cTexture tex, boolean bump)
80048102 {
80058103 if (// DrawMode() != 0 || /*tex == null ||*/
80068104 ambientOcclusion ) // || !textureon)
....@@ -8011,7 +8109,7 @@
80118109 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
80128110
80138111 if (tex != null)
8014
- texture = textures.get(tex);
8112
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
80158113
80168114 // //assert( texture != null );
80178115 // if (texture == null)
....@@ -8105,47 +8203,50 @@
81058203
81068204 /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
81078205 {
8108
- if (// DrawMode() != 0 || /*tex == null ||*/
8109
- ambientOcclusion ) // || !textureon)
8110
- {
8111
- return; // false;
8112
- }
8113
-
8114
- if (tex == null)
8115
- {
8116
- BindTexture(null,false,resolution);
8117
- BindTexture(null,true,resolution);
8118
- return;
8119
- }
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;
81208247
8121
- String pigment = Object3D.GetPigment(tex);
8122
- String bump = Object3D.GetBump(tex);
8123
-
8124
- usedtextures.put(pigment, pigment);
8125
- usedtextures.put(bump, bump);
8126
-
8127
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8128
- {
8129
- // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8130
- // System.out.println("; bump = " + bump);
8131
- }
8132
-
8133
- if (bump.equals(""))
8134
- {
8135
- bump = null;
8136
- }
8137
- if (pigment.equals(""))
8138
- {
8139
- pigment = null;
8140
- }
8141
-
8142
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8143
- BindTexture(pigment, false, resolution);
8144
- GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8145
- BindTexture(bump, true, resolution);
8146
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8147
-
8148
- return; // true;
8248
+ BindPigmentTexture(tex, resolution);
8249
+ BindBumpTexture(tex, resolution);
81498250 }
81508251
81518252 /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8164,9 +8265,9 @@
81648265
81658266 String pigment = Object3D.GetPigment(tex);
81668267
8167
- usedtextures.put(pigment, pigment);
8268
+ usedtextures.add(tex);
81688269
8169
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8270
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
81708271 {
81718272 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
81728273 // System.out.println("; bump = " + bump);
....@@ -8178,7 +8279,7 @@
81788279 }
81798280
81808281 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8181
- BindTexture(pigment, false, resolution);
8282
+ BindTexture(tex, false, resolution);
81828283 }
81838284
81848285 /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8197,9 +8298,9 @@
81978298
81988299 String bump = Object3D.GetBump(tex);
81998300
8200
- usedtextures.put(bump, bump);
8301
+ usedtextures.add(tex);
82018302
8202
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8303
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
82038304 {
82048305 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
82058306 // System.out.println("; bump = " + bump);
....@@ -8211,7 +8312,7 @@
82118312 }
82128313
82138314 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8214
- BindTexture(bump, true, resolution);
8315
+ BindTexture(tex, true, resolution);
82158316 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
82168317 }
82178318
....@@ -8235,13 +8336,19 @@
82358336 return fileExists;
82368337 }
82378338
8238
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception
8339
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
82398340 {
8240
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8341
+ CacheTexture texturecache = null;
82418342
82428343 if (tex != null)
82438344 {
8244
- 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
+ }
82458352
82468353 String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
82478354
....@@ -8251,19 +8358,46 @@
82518358 // else
82528359 // if (!texname.startsWith("/"))
82538360 // texname = "/Users/nbriere/Textures/" + texname;
8254
- if (!FileExists(tex))
8361
+ if (!FileExists(texname) && !texname.startsWith("@"))
82558362 {
82568363 texname = fallbackTextureName;
82578364 }
82588365
82598366 if (CACHETEXTURE)
8260
- texture = textures.get(texname); // TEXTURE CACHE
8261
-
8262
- TextureData texturedata = null;
8263
-
8264
- if (texture == null || texture.resolution < resolution)
82658367 {
8266
- 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(""))
82678401 {
82688402 assert(!bump);
82698403 // if (bump)
....@@ -8274,19 +8408,23 @@
82748408 // }
82758409 // else
82768410 // {
8277
- texture = textures.get(tex);
8278
- if (texture == null)
8411
+ // texturecache = textures.get(texname); // suspicious
8412
+ if (texturecache == null)
82798413 {
8280
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8414
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
82818415 }
8416
+ else
8417
+ new Exception().printStackTrace();
82828418 // }
82838419 } else
8284
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8420
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
82858421 {
82868422 assert(bump);
8287
- texture = textures.get(tex);
8288
- if (texture == null)
8289
- 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();
82908428 } else
82918429 {
82928430 //if (tex.equals("IMMORTAL"))
....@@ -8294,11 +8432,22 @@
82948432 // texture = GetResourceTexture("default.png");
82958433 //} else
82968434 //{
8297
- if (tex.equals("WHITE_NOISE"))
8435
+ if (texname.endsWith("WHITE_NOISE"))
82988436 {
8299
- texture = textures.get(tex);
8300
- if (texture == null)
8301
- 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();
83028451 } else
83038452 {
83048453 if (textureon)
....@@ -8357,19 +8506,20 @@
83578506 if (texturedata == null)
83588507 throw new Exception();
83598508
8360
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8509
+ texturecache = new CacheTexture(texturedata,resolution);
83618510 //texture = GetTexture(tex, bump);
83628511 }
8512
+ }
83638513 }
83648514 //}
83658515 }
83668516
8367
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8517
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
83688518 {
83698519 //return false;
83708520
83718521 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8372
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8522
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
83738523 {
83748524 // String ext = "_highres";
83758525 // if (REDUCETEXTURE)
....@@ -8386,52 +8536,17 @@
83868536 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
83878537 if (!cachefile.exists())
83888538 {
8389
- // cache to disk
8390
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
8391
- //buffers[0].
8392
-
8393
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
8394
- int[] pixels = new int[bytebuf.capacity()/3];
8395
-
8396
- // squared size heuristic...
8397
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8539
+ //if (texturedata.getWidth() == texturedata.getHeight())
83988540 {
8399
- for (int i=pixels.length; --i>=0;)
8400
- {
8401
- int i3 = i*3;
8402
- pixels[i] = 0xFF;
8403
- pixels[i] <<= 8;
8404
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
8405
- pixels[i] <<= 8;
8406
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
8407
- pixels[i] <<= 8;
8408
- pixels[i] |= bytebuf.get(i3) & 0xFF;
8409
- }
8410
-
8411
- /*
8412
- int r=0,g=0,b=0,a=0;
8413
- for (int i=0; i<width; i++)
8414
- for (int j=0; j<height; j++)
8415
- {
8416
- int index = j*width+i;
8417
- int p = pixels[index];
8418
- a = ((p>>24) & 0xFF);
8419
- r = ((p>>16) & 0xFF);
8420
- g = ((p>>8) & 0xFF);
8421
- b = (p & 0xFF);
8422
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
8423
- }
8424
- /**/
8425
- int width = (int)Math.sqrt(pixels.length); // squared
8426
- int height = width;
8427
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
8428
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8541
+ BufferedImage rendImage = CreateBim(texturedata);
8542
+
84298543 ImageWriter writer = null;
84308544 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
84318545 if (iter.hasNext()) {
84328546 writer = (ImageWriter)iter.next();
84338547 }
8434
- float compressionQuality = 0.9f;
8548
+
8549
+ float compressionQuality = 0.85f;
84358550 try
84368551 {
84378552 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8448,18 +8563,20 @@
84488563 }
84498564 }
84508565 }
8451
-
8566
+
8567
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8568
+
84528569 //System.out.println("Texture = " + tex);
8453
- if (textures.containsKey(texname))
8570
+ if (textures.containsKey(tex))
84548571 {
8455
- CacheTexture thetex = textures.get(texname);
8572
+ CacheTexture thetex = textures.get(tex);
84568573 thetex.texture.disable();
84578574 thetex.texture.dispose();
8458
- textures.remove(texname);
8575
+ textures.remove(tex);
84598576 }
84608577
8461
- texture.texturedata = texturedata;
8462
- textures.put(texname, texture);
8578
+ //texture.texturedata = texturedata;
8579
+ textures.put(tex, texturecache);
84638580
84648581 // newtex = true;
84658582 }
....@@ -8475,10 +8592,44 @@
84758592 }
84768593 }
84778594
8478
- return texture;
8595
+ return texturecache;
84798596 }
84808597
8481
- 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
84828633 {
84838634 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
84848635
....@@ -8496,21 +8647,21 @@
84968647 return texture!=null?texture.texture:null;
84978648 }
84988649
8499
- 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
85008651 {
85018652 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
85028653
85038654 return texture!=null?texture.texturedata:null;
85048655 }
85058656
8506
- boolean BindTexture(String tex, boolean bump, int resolution) throws Exception
8657
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
85078658 {
85088659 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
85098660 {
85108661 return false;
85118662 }
85128663
8513
- boolean newtex = false;
8664
+ //boolean newtex = false;
85148665
85158666 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
85168667
....@@ -8542,9 +8693,75 @@
85428693 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
85438694 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
85448695
8545
- return newtex;
8696
+ return true; // Warning: not used.
85468697 }
85478698
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
+
85488765 ShadowBuffer shadowPBuf;
85498766 AntialiasBuffer antialiasPBuf;
85508767 int MAXSTACK;
....@@ -8737,7 +8954,7 @@
87378954
87388955 if (cubemap == null)
87398956 {
8740
- LoadEnvy(5);
8957
+ //LoadEnvy(1);
87418958 }
87428959
87438960 //cubemap.enable();
....@@ -9024,37 +9241,58 @@
90249241 cubemap = null;
90259242 return;
90269243 case 1:
9027
- name = "cubemaps/box_";
9028
- ext = "png";
9244
+ name = "cubemaps/rgb/";
9245
+ ext = "jpg";
90299246 reverseUP = false;
90309247 break;
90319248 case 2:
9032
- name = "cubemaps/uffizi_";
9033
- ext = "png";
9034
- break; // reverseUP = true; break;
9249
+ name = "cubemaps/uffizi/";
9250
+ ext = "jpg";
9251
+ reverseUP = false;
9252
+ break;
90359253 case 3:
9036
- name = "cubemaps/CloudyHills_";
9037
- ext = "tga";
9254
+ name = "cubemaps/CloudyHills/";
9255
+ ext = "jpg";
90389256 reverseUP = false;
90399257 break;
90409258 case 4:
9041
- name = "cubemaps/cornell_";
9259
+ name = "cubemaps/cornell/";
90429260 ext = "png";
90439261 reverseUP = false;
90449262 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;
90459288 default:
9046
- name = "cubemaps/rgb_";
9047
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9289
+ name = "cubemaps/box/";
9290
+ ext = "png"; /*mipmap = true;*/
9291
+ reverseUP = false;
90489292 break;
90499293 }
9050
-
9051
- try
9052
- {
9053
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
9054
- } catch (IOException e)
9055
- {
9056
- throw new RuntimeException(e);
9057
- }
9294
+
9295
+ LoadSkybox(name, ext, mipmap);
90589296 }
90599297
90609298 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -9086,8 +9324,12 @@
90869324 static double[] model = new double[16];
90879325 double[] camera2light = new double[16];
90889326 double[] light2camera = new double[16];
9089
- int newenvy = -1;
9090
- boolean envyoff = true; // false;
9327
+
9328
+ //int newenvy = -1;
9329
+ //boolean envyoff = false;
9330
+
9331
+ String loadedskyboxname;
9332
+
90919333 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
90929334 //float[] light0 = { 0,0,0 };
90939335 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9505,7 +9747,7 @@
95059747
95069748 if (renderCamera != lightCamera)
95079749 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9508
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
9750
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
95099751
95109752 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
95119753
....@@ -9521,7 +9763,7 @@
95219763
95229764 if (renderCamera != lightCamera)
95239765 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9524
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
9766
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
95259767
95269768 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
95279769
....@@ -9567,10 +9809,12 @@
95679809 rati = 1 / rati;
95689810 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
95699811 }
9570
- assert (newenvy == -1);
9812
+
9813
+ //assert (newenvy == -1);
9814
+
95719815 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
95729816 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9573
- DrawSkyBox(gl);
9817
+ DrawSkyBox(gl, (float)rati);
95749818 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
95759819 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
95769820 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10607,7 +10851,7 @@
1060710851
1060810852 if (wait)
1060910853 {
10610
- Sleep(500);
10854
+ Sleep(200); // blocks everything
1061110855
1061210856 wait = false;
1061310857 }
....@@ -10722,7 +10966,7 @@
1072210966 // if (parentcam != renderCamera) // not a light
1072310967 if (cam != lightCamera)
1072410968 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10725
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
10969
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1072610970
1072710971 for (int j = 0; j < 4; j++)
1072810972 {
....@@ -10737,7 +10981,7 @@
1073710981 // if (parentcam != renderCamera) // not a light
1073810982 if (cam != lightCamera)
1073910983 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10740
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
10984
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1074110985
1074210986 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1074310987
....@@ -10823,13 +11067,27 @@
1082311067 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1082411068 }
1082511069
10826
- if (newenvy > -1)
11070
+// if (newenvy > -1)
11071
+// {
11072
+// LoadEnvy(newenvy);
11073
+// }
11074
+//
11075
+// newenvy = -1;
11076
+
11077
+ if (object.skyboxname != null)
1082711078 {
10828
- LoadEnvy(newenvy);
11079
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11080
+ {
11081
+ LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11082
+ loadedskyboxname = object.skyboxname;
11083
+ }
1082911084 }
10830
-
10831
- newenvy = -1;
10832
-
11085
+ else
11086
+ {
11087
+ cubemap = null;
11088
+ loadedskyboxname = null;
11089
+ }
11090
+
1083311091 ratio = ((double) getWidth()) / getHeight();
1083411092 //System.out.println("ratio = " + ratio);
1083511093
....@@ -10845,7 +11103,7 @@
1084511103
1084611104 if (!IsFrozen() && !ambientOcclusion)
1084711105 {
10848
- DrawSkyBox(gl);
11106
+ DrawSkyBox(gl, (float)ratio);
1084911107 }
1085011108
1085111109 //if (selection_view == -1)
....@@ -11028,9 +11286,9 @@
1102811286
1102911287 gl.glMatrixMode(GL.GL_MODELVIEW);
1103011288
11031
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11032
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
11033
-//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);
1103411292 } else
1103511293 {
1103611294 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -11041,7 +11299,7 @@
1104111299 //System.out.println("BLENDING ON");
1104211300 gl.glEnable(GL.GL_BLEND);
1104311301 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
11044
-
11302
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1104511303 gl.glMatrixMode(gl.GL_PROJECTION);
1104611304 gl.glLoadIdentity();
1104711305
....@@ -11131,7 +11389,7 @@
1113111389
1113211390 // if (cam != lightCamera)
1113311391 //for (int count = parentcam.GetTransformCount(); --count>=0;)
11134
- LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
11392
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1113511393 }
1113611394
1113711395 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -11290,7 +11548,7 @@
1129011548 }
1129111549 }
1129211550
11293
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11551
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1129411552 {
1129511553 //gl.glDepthFunc(GL.GL_LEQUAL);
1129611554 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11298,24 +11556,21 @@
1129811556
1129911557 boolean texon = textureon;
1130011558
11301
- if (RENDERPROGRAM > 0)
11302
- {
11303
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11304
- textureon = false;
11305
- }
11559
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11560
+ textureon = false;
11561
+
1130611562 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1130711563 //System.out.println("ALLO");
1130811564 gl.glColorMask(false, false, false, false);
1130911565 DrawObject(gl);
11310
- if (RENDERPROGRAM > 0)
11311
- {
11312
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11313
- textureon = texon;
11314
- }
11566
+
11567
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11568
+ textureon = texon;
11569
+
1131511570 gl.glColorMask(true, true, true, true);
1131611571
1131711572 gl.glDepthFunc(GL.GL_EQUAL);
11318
- //gl.glDepthMask(false);
11573
+ gl.glDepthMask(false);
1131911574 }
1132011575
1132111576 if (false) // DrawMode() == SHADOW)
....@@ -11655,20 +11910,32 @@
1165511910 ReleaseTextures(DEFAULT_TEXTURES);
1165611911
1165711912 if (CLEANCACHE)
11658
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11913
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1165911914 {
11660
- String tex = e.nextElement();
11915
+ cTexture tex = e.nextElement();
1166111916
1166211917 // System.out.println("Texture --------- " + tex);
1166311918
11664
- if (tex.equals("WHITE_NOISE"))
11919
+ if (tex.equals("WHITE_NOISE:"))
1166511920 continue;
1166611921
11667
- if (!usedtextures.containsKey(tex))
11922
+ if (!usedtextures.contains(tex))
1166811923 {
11924
+ CacheTexture gettex = texturepigment.get(tex);
1166911925 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11670
- textures.get(tex).texture.dispose();
11671
- 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
+ }
1167211939 }
1167311940 }
1167411941 }
....@@ -12196,8 +12463,76 @@
1219612463
1219712464 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1219812465
12199
- String program =
12466
+ String programmin =
12467
+ // Min shader
1220012468 "!!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
+
1220112536 //"OPTION ARB_fragment_program_shadow;" +
1220212537 "PARAM light2cam0 = program.env[10];" +
1220312538 "PARAM light2cam1 = program.env[11];" +
....@@ -12312,8 +12647,7 @@
1231212647 "TEMP shininess;" +
1231312648 "\n" +
1231412649 "MOV texSamp, one;" +
12315
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12316
-
12650
+
1231712651 "MOV mapgrid.x, one2048th.x;" +
1231812652 "MOV temp, fragment.texcoord[1];" +
1231912653 /*
....@@ -12334,20 +12668,20 @@
1233412668 "MUL temp, floor, mapgrid.x;" +
1233512669 //"TEX depth0, temp, texture[1], 2D;" +
1233612670 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12337
- TextureFetch("depth0", "temp", "1") +
12671
+ ShadowTextureFetch("depth0", "temp", "1") +
1233812672 "") +
1233912673 "ADD temp.x, temp.x, mapgrid.x;" +
1234012674 //"TEX depth1, temp, texture[1], 2D;" +
1234112675 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12342
- TextureFetch("depth1", "temp", "1") +
12676
+ ShadowTextureFetch("depth1", "temp", "1") +
1234312677 "") +
1234412678 "ADD temp.y, temp.y, mapgrid.x;" +
1234512679 //"TEX depth2, temp, texture[1], 2D;" +
12346
- TextureFetch("depth2", "temp", "1") +
12680
+ ShadowTextureFetch("depth2", "temp", "1") +
1234712681 "SUB temp.x, temp.x, mapgrid.x;" +
1234812682 //"TEX depth3, temp, texture[1], 2D;" +
1234912683 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12350
- TextureFetch("depth3", "temp", "1") +
12684
+ ShadowTextureFetch("depth3", "temp", "1") +
1235112685 "") +
1235212686 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1235312687 //"MOV params, material;" +
....@@ -12718,10 +13052,10 @@
1271813052 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1271913053 "") +
1272013054
12721
- // display shadow only (bump == 0)
13055
+ // display shadow only (fakedepth == 0)
1272213056 "SUB temp.x, half.x, shadow.x;" +
1272313057 "MOV temp.y, -params5.z;" + // params6.x;" +
12724
- "SLT temp.z, temp.y, -one2048th.x;" +
13058
+ "SLT temp.z, temp.y, -c256i.x;" +
1272513059 "SUB temp.y, one.x, temp.z;" +
1272613060 "MUL temp.x, temp.x, temp.y;" +
1272713061 "KIL temp.x;" +
....@@ -13052,6 +13386,13 @@
1305213386 //once = true;
1305313387 }
1305413388
13389
+ String program = programmax;
13390
+
13391
+ if (Globals.MINSHADER)
13392
+ {
13393
+ program = programmin;
13394
+ }
13395
+
1305513396 System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1305613397 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1305713398 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
....@@ -13145,25 +13486,26 @@
1314513486 return out;
1314613487 }
1314713488
13148
- String TextureFetch(String dest, String src, String unit)
13489
+ // Also does frustum culling
13490
+ String ShadowTextureFetch(String dest, String src, String unit)
1314913491 {
1315013492 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1315113493 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1315213494 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13495
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13496
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1315313497 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13154
- "SLT " + src + ".z, " + src + ".x, one.x;" +
13155
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13156
- "SLT " + src + ".z, " + src + ".y, one.x;" +
13157
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13498
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13499
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1315813500 //"SWZ buffer, temp, w,w,w,w;";
13159
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13501
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1316013502 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1316113503 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1316213504 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13163
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13505
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1316413506
13165
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13166
- //"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;";
1316713509 }
1316813510
1316913511 String Shadow(String depth, String shadow)
....@@ -13210,7 +13552,7 @@
1321013552 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1321113553 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1321213554
13213
- // No shadow when out of frustrum
13555
+ // No shadow when out of frustum
1321413556 "SGE temp.x, " + depth + ".z, one.z;" +
1321513557 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1321613558 "";
....@@ -14008,14 +14350,15 @@
1400814350 drag = false;
1400914351 //System.out.println("Mouse DOWN");
1401014352 editObj = false;
14011
- ClickInfo info = new ClickInfo();
14012
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14013
- info.pane = this;
14014
- info.camera = renderCamera;
14015
- info.x = x;
14016
- info.y = y;
14017
- info.modifiers = modifiersex;
14018
- 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);
1401914362 if (!editObj)
1402014363 {
1402114364 hasMarquee = true;
....@@ -14297,12 +14640,12 @@
1429714640 void GoDown(int mod)
1429814641 {
1429914642 MODIFIERS |= COMMAND;
14300
- /*
14643
+ /**/
1430114644 if((mod&SHIFT) == SHIFT)
14302
- manipCamera.RotatePosition(0, -speed);
14645
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
1430314646 else
14304
- manipCamera.BackForth(0, -speed*delta, getWidth());
14305
- */
14647
+ manipCamera.RotatePosition(0, -speed);
14648
+ /**/
1430614649 if ((mod & SHIFT) == SHIFT)
1430714650 {
1430814651 mouseMode = mouseMode; // VR??
....@@ -14318,12 +14661,12 @@
1431814661 void GoUp(int mod)
1431914662 {
1432014663 MODIFIERS |= COMMAND;
14321
- /*
14664
+ /**/
1432214665 if((mod&SHIFT) == SHIFT)
14323
- manipCamera.RotatePosition(0, speed);
14666
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
1432414667 else
14325
- manipCamera.BackForth(0, speed*delta, getWidth());
14326
- */
14668
+ manipCamera.RotatePosition(0, speed);
14669
+ /**/
1432714670 if ((mod & SHIFT) == SHIFT)
1432814671 {
1432914672 mouseMode = mouseMode;
....@@ -14339,12 +14682,12 @@
1433914682 void GoLeft(int mod)
1434014683 {
1434114684 MODIFIERS |= COMMAND;
14342
- /*
14685
+ /**/
1434314686 if((mod&SHIFT) == SHIFT)
14344
- manipCamera.RotatePosition(speed, 0);
14345
- else
1434614687 manipCamera.Translate(speed*delta, 0, getWidth());
14347
- */
14688
+ else
14689
+ manipCamera.RotatePosition(speed, 0);
14690
+ /**/
1434814691 if ((mod & SHIFT) == SHIFT)
1434914692 {
1435014693 mouseMode = mouseMode;
....@@ -14360,12 +14703,12 @@
1436014703 void GoRight(int mod)
1436114704 {
1436214705 MODIFIERS |= COMMAND;
14363
- /*
14706
+ /**/
1436414707 if((mod&SHIFT) == SHIFT)
14365
- manipCamera.RotatePosition(-speed, 0);
14366
- else
1436714708 manipCamera.Translate(-speed*delta, 0, getWidth());
14368
- */
14709
+ else
14710
+ manipCamera.RotatePosition(-speed, 0);
14711
+ /**/
1436914712 if ((mod & SHIFT) == SHIFT)
1437014713 {
1437114714 mouseMode = mouseMode;
....@@ -14415,15 +14758,16 @@
1441514758 if (editObj)
1441614759 {
1441714760 drag = true;
14418
- ClickInfo info = new ClickInfo();
14419
- info.bounds.setBounds(0, 0,
14761
+ //ClickInfo info = new ClickInfo();
14762
+ object.clickInfo.bounds.setBounds(0, 0,
1442014763 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14421
- info.pane = this;
14422
- info.camera = renderCamera;
14423
- info.x = x;
14424
- info.y = y;
14425
- object.GetWindow().copy
14426
- .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);
1442714771 } else
1442814772 {
1442914773 if (x < startX)
....@@ -14572,24 +14916,27 @@
1457214916 }
1457314917 }
1457414918
14919
+// ClickInfo clickInfo = new ClickInfo();
14920
+
1457514921 public void mouseMoved(MouseEvent e)
1457614922 {
1457714923 //System.out.println("mouseMoved: " + e);
1457814924 if (isRenderer)
1457914925 return;
1458014926
14581
- ClickInfo ci = new ClickInfo();
14582
- ci.x = e.getX();
14583
- ci.y = e.getY();
14584
- ci.modifiers = e.getModifiersEx();
14585
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14586
- ci.pane = this;
14587
- 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;
1458814934 if (!isRenderer)
1458914935 {
1459014936 //ObjEditor editWindow = object.editWindow;
1459114937 //Object3D copy = editWindow.copy;
14592
- if (object.doEditClick(ci, 0))
14938
+ if (object.doEditClick(//clickInfo,
14939
+ 0))
1459314940 {
1459414941 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1459514942 } else
....@@ -14604,7 +14951,8 @@
1460414951 Globals.MOUSEDRAGGED = false;
1460514952
1460614953 movingcamera = false;
14607
- X = Y = 0;
14954
+ X = 0; // getBounds().width/2;
14955
+ Y = 0; // getBounds().height/2;
1460814956 //System.out.println("mouseReleased: " + e);
1460914957 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1461014958 }
....@@ -14860,7 +15208,8 @@
1486015208 // break;
1486115209 case 'T':
1486215210 CACHETEXTURE ^= true;
14863
- textures.clear();
15211
+ texturepigment.clear();
15212
+ texturebump.clear();
1486415213 // repaint();
1486515214 break;
1486615215 case 'Y':
....@@ -14945,7 +15294,9 @@
1494515294 case 'E' : COMPACT ^= true;
1494615295 repaint();
1494715296 break;
14948
- case 'W' : DEBUGHSB ^= true;
15297
+ case 'W' : // Wide Window (fullscreen)
15298
+ //DEBUGHSB ^= true;
15299
+ ObjEditor.theFrame.ToggleFullScreen();
1494915300 repaint();
1495015301 break;
1495115302 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14971,13 +15322,7 @@
1497115322 repaint();
1497215323 break;
1497315324 case 'l':
14974
- lightMode ^= true;
14975
- Globals.lighttouched = true;
14976
- manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
14977
- targetLookAt.set(manipCamera.lookAt);
14978
- repaint();
14979
- break;
14980
- case 'L':
15325
+ //case 'L':
1498115326 if (lightMode)
1498215327 {
1498315328 lightMode = false;
....@@ -15041,20 +15386,24 @@
1504115386 OCCLUSION_CULLING ^= true;
1504215387 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1504315388 break;
15044
- case '0': envyoff ^= true; repaint(); break;
15389
+ //case '0': envyoff ^= true; repaint(); break;
1504515390 case '1':
1504615391 case '2':
1504715392 case '3':
1504815393 case '4':
1504915394 case '5':
15050
- newenvy = Character.getNumericValue(key);
15051
- repaint();
15052
- break;
1505315395 case '6':
1505415396 case '7':
1505515397 case '8':
1505615398 case '9':
15057
- 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
+ }
1505815407 repaint();
1505915408 break;
1506015409 case '!':
....@@ -15124,7 +15473,10 @@
1512415473 // kompactbit = 6;
1512515474 // break;
1512615475 case ' ':
15127
- ObjEditor.theFrame.ToggleFullScreen();
15476
+ lightMode ^= true;
15477
+ Globals.lighttouched = true;
15478
+ manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
15479
+ targetLookAt.set(manipCamera.lookAt);
1512815480 repaint();
1512915481 break;
1513015482 //case '`' :
....@@ -15614,8 +15966,6 @@
1561415966
1561515967 int width = getBounds().width;
1561615968 int height = getBounds().height;
15617
- ClickInfo info = new ClickInfo();
15618
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1561915969 //Image img = CreateImage(width, height);
1562015970 //System.out.println("width = " + width + "; height = " + height + "\n");
1562115971
....@@ -15692,48 +16042,77 @@
1569216042 }
1569316043 if (object != null && !hasMarquee)
1569416044 {
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
+
1569516051 if (isRenderer)
1569616052 {
15697
- info.flags++;
16053
+ object.clickInfo.flags++;
1569816054 double frameAspect = (double) width / (double) height;
1569916055 if (frameAspect > renderCamera.aspect)
1570016056 {
1570116057 int desired = (int) ((double) height * renderCamera.aspect);
15702
- info.bounds.width -= width - desired;
15703
- info.bounds.x += (width - desired) / 2;
16058
+ object.clickInfo.bounds.width -= width - desired;
16059
+ object.clickInfo.bounds.x += (width - desired) / 2;
1570416060 } else
1570516061 {
1570616062 int desired = (int) ((double) width / renderCamera.aspect);
15707
- info.bounds.height -= height - desired;
15708
- info.bounds.y += (height - desired) / 2;
16063
+ object.clickInfo.bounds.height -= height - desired;
16064
+ object.clickInfo.bounds.y += (height - desired) / 2;
1570916065 }
1571016066 }
15711
- info.g = gr;
15712
- info.camera = renderCamera;
16067
+
16068
+ object.clickInfo.g = gr;
16069
+ object.clickInfo.camera = renderCamera;
1571316070 /*
1571416071 // Memory intensive (brep.verticescopy)
1571516072 if (!(object instanceof Composite))
1571616073 object.draw(info, 0, false); // SLOW :
1571716074 */
15718
- if (!isRenderer)
16075
+ if (!isRenderer) // && drag)
1571916076 {
15720
- object.drawEditHandles(info, 0);
15721
-
15722
- 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)
1572316080 {
15724
- 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)
1572516087 {
15726
- case Object3D.hitCenter: gr.setColor(Color.pink);
15727
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15728
- break;
15729
- case Object3D.hitRotate: gr.setColor(Color.yellow);
15730
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15731
- break;
15732
- case Object3D.hitScale: gr.setColor(Color.cyan);
15733
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15734
- 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;
1573516095 }
15736
-
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
+ }
1573716116 }
1573816117 }
1573916118 }
....@@ -16215,6 +16594,8 @@
1621516594 private /*static*/ boolean firstime;
1621616595 private /*static*/ cVector newView = new cVector();
1621716596 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"};
1621816599 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1621916600 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1622016601 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16227,29 +16608,67 @@
1622716608 {
1622816609 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1622916610
16611
+ int usedsuf = 0;
16612
+
1623016613 for (int i = 0; i < suffixes.length; i++)
1623116614 {
16232
- String resourceName = basename + suffixes[i] + "." + suffix;
16233
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16234
- mipmapped,
16235
- FileUtil.getFileSuffix(resourceName));
16236
- if (data == null)
16615
+ String[] suffixe = suffixes;
16616
+ String[] fallback = suffixes2;
16617
+ String[] fallfallback = suffixes3;
16618
+
16619
+ for (int c=usedsuf; --c>=0;)
1623716620 {
16238
- throw new IOException("Unable to load texture " + resourceName);
16621
+// String[] temp = suffixe;
16622
+// suffixe = fallback;
16623
+// fallback = fallfallback;
16624
+// fallfallback = temp;
1623916625 }
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
+
1624016654 //System.out.println("Target = " + targets[i]);
1624116655 cubemap.updateImage(data, targets[i]);
1624216656 }
1624316657
1624416658 return cubemap;
1624516659 }
16660
+
1624616661 int bigsphere = -1;
1624716662
1624816663 float BGcolor = 0.5f;
1624916664
16250
- private void DrawSkyBox(GL gl)
16665
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16666
+
16667
+ private void DrawSkyBox(GL gl, float ratio)
1625116668 {
16252
- if (envyoff || cubemap == null)
16669
+ if (//envyoff ||
16670
+ WIREFRAME ||
16671
+ cubemap == null)
1625316672 {
1625416673 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1625516674 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16264,7 +16683,17 @@
1626416683 // Compensates for ExaminerViewer's modification of modelview matrix
1626516684 gl.glMatrixMode(GL.GL_MODELVIEW);
1626616685 gl.glLoadIdentity();
16686
+ gl.glScalef(1,ratio,1);
1626716687
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
+
1626816697 //gl.glActiveTexture(GL.GL_TEXTURE1);
1626916698 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1627016699
....@@ -16296,6 +16725,7 @@
1629616725 {
1629716726 gl.glScalef(1.0f, -1.0f, 1.0f);
1629816727 }
16728
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1629916729 gl.glMultMatrixd(viewrot_1, 0);
1630016730 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1630116731 //viewer.updateInverseRotation(gl);
....@@ -16531,6 +16961,14 @@
1653116961 }
1653216962 }
1653316963
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
+
1653416972 class SelectBuffer implements GLEventListener
1653516973 {
1653616974
....@@ -16546,7 +16984,7 @@
1654616984 //new Exception().printStackTrace();
1654716985 System.out.println("select buffer init");
1654816986 // Use debug pipeline
16549
- drawable.setGL(new DebugGL(drawable.getGL()));
16987
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1655016988
1655116989 GL gl = drawable.getGL();
1655216990
....@@ -16610,6 +17048,17 @@
1661017048
1661117049 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1661217050
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
+
1661317062 //int tmp = selection_view;
1661417063 //selection_view = -1;
1661517064 int temp = DrawMode();
....@@ -16621,6 +17070,17 @@
1662117070 // temp = DEFAULT; // patch for selection debug
1662217071 Globals.drawMode = temp; // WARNING
1662317072
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
+
1662417084 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1662517085
1662617086 // trying different ways of getting the depth info over
....@@ -16726,27 +17186,29 @@
1672617186 if (!movingcamera && !PAINTMODE)
1672717187 object.GetWindow().ScreenFitPoint(); // fev 2014
1672817188
16729
- 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)
1673017190 {
16731
- Object3D paintobj = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
16732
-
16733
- Object3D group = new Object3D("inst" + paintcount++);
16734
-
16735
- group.CreateMaterial(); // use a void leaf to select instances
16736
-
16737
- group.add(paintobj); // link
16738
-
16739
- object.GetWindow().SnapObject(group);
16740
-
16741
- Object3D folder = object.GetWindow().copy;
17191
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1674217192
1674317193 if (object.GetWindow().copy.selection.Size() > 0)
16744
- folder = object.GetWindow().copy.selection.elementAt(0);
17194
+ {
17195
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1674517196
16746
- folder.add(group);
16747
-
16748
- object.GetWindow().ResetModel();
16749
- object.GetWindow().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
+ }
1675017212 }
1675117213 else
1675217214 paintcount = 0;