Normand Briere
2019-08-06 b3ae4e889872ca0b9ca76f1d17b2f0b961226729
CameraPane.java
....@@ -18,7 +18,10 @@
1818 import javax.imageio.ImageIO;
1919 import javax.imageio.ImageWriteParam;
2020 import javax.imageio.ImageWriter;
21
+import javax.imageio.ImageReadParam;
22
+import javax.imageio.ImageReader;
2123 import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
24
+import javax.imageio.stream.ImageInputStream;
2225 import javax.imageio.stream.ImageOutputStream;
2326 import javax.imageio.ImageWriteParam;
2427
....@@ -30,6 +33,7 @@
3033 import java.nio.*;
3134
3235 import gleem.linalg.Mat4f;
36
+import javax.imageio.ImageTypeSpecifier;
3337
3438 class CameraPane extends GLCanvas implements iCameraPane, Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener
3539 {
....@@ -44,6 +48,39 @@
4448 static boolean ABORTED = false;
4549
4650 static int STEP = 1;
51
+
52
+ private static BufferedImage CreateBim(byte[] bytes, int width, int height)
53
+ {
54
+ int[] pixels = new int[bytes.length/3];
55
+ for (int i=pixels.length; --i>=0;)
56
+ {
57
+ int i3 = i*3;
58
+ pixels[i] = 0xFF;
59
+ pixels[i] <<= 8;
60
+ pixels[i] |= bytes[i3+2] & 0xFF;
61
+ pixels[i] <<= 8;
62
+ pixels[i] |= bytes[i3+1] & 0xFF;
63
+ pixels[i] <<= 8;
64
+ pixels[i] |= bytes[i3] & 0xFF;
65
+ }
66
+ /*
67
+ int r=0,g=0,b=0,a=0;
68
+ for (int i=0; i<width; i++)
69
+ for (int j=0; j<height; j++)
70
+ {
71
+ int index = j*width+i;
72
+ int p = pixels[index];
73
+ a = ((p>>24) & 0xFF);
74
+ r = ((p>>16) & 0xFF);
75
+ g = ((p>>8) & 0xFF);
76
+ b = (p & 0xFF);
77
+ pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
78
+ }
79
+ /**/
80
+ BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
81
+ rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
82
+ return rendImage;
83
+ }
4784
4885 /*static*/ private boolean CULLFACE = false; // true;
4986 /*static*/ boolean NEAREST = false; // true;
....@@ -60,7 +97,7 @@
6097 //boolean REDUCETEXTURE = true;
6198 boolean CACHETEXTURE = true;
6299 boolean CLEANCACHE = false; // true;
63
- boolean MIPMAP = false; // true;
100
+ boolean MIPMAP = false; // true; // never works...
64101 boolean COMPRESSTEXTURE = false;
65102 boolean KOMPACTTEXTURE = false; // true;
66103 boolean RESIZETEXTURE = false;
....@@ -150,6 +187,18 @@
150187 }
151188
152189 private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
190
+
191
+ public void LoadSkybox(String name, String ext, boolean mipmap) throws GLException
192
+ {
193
+ try
194
+ {
195
+ cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
196
+ } catch (IOException e)
197
+ {
198
+ System.out.println("NAME = " + name);
199
+ e.printStackTrace(); // throw new RuntimeException(e);
200
+ }
201
+ }
153202
154203 void SetAsGLRenderer(boolean b)
155204 {
....@@ -169,7 +218,8 @@
169218
170219 SetCamera(cam);
171220
172
- SetLight(new Camera(new cVector(10, 10, -20)));
221
+ // Warning: not used.
222
+ SetLight(new Camera(new cVector(15, 10, -20)));
173223
174224 object = o;
175225
....@@ -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))
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,13 @@
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();
83028442 } else
83038443 {
83048444 if (textureon)
....@@ -8357,19 +8497,19 @@
83578497 if (texturedata == null)
83588498 throw new Exception();
83598499
8360
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8500
+ texturecache = new CacheTexture(texturedata,resolution);
83618501 //texture = GetTexture(tex, bump);
83628502 }
83638503 }
83648504 //}
83658505 }
83668506
8367
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8507
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
83688508 {
83698509 //return false;
83708510
83718511 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8372
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8512
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
83738513 {
83748514 // String ext = "_highres";
83758515 // if (REDUCETEXTURE)
....@@ -8386,52 +8526,17 @@
83868526 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
83878527 if (!cachefile.exists())
83888528 {
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))
8529
+ //if (texturedata.getWidth() == texturedata.getHeight())
83988530 {
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);
8531
+ BufferedImage rendImage = CreateBim(texturedata);
8532
+
84298533 ImageWriter writer = null;
84308534 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
84318535 if (iter.hasNext()) {
84328536 writer = (ImageWriter)iter.next();
84338537 }
8434
- float compressionQuality = 0.9f;
8538
+
8539
+ float compressionQuality = 0.85f;
84358540 try
84368541 {
84378542 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8448,18 +8553,20 @@
84488553 }
84498554 }
84508555 }
8451
-
8556
+
8557
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8558
+
84528559 //System.out.println("Texture = " + tex);
8453
- if (textures.containsKey(texname))
8560
+ if (textures.containsKey(tex))
84548561 {
8455
- CacheTexture thetex = textures.get(texname);
8562
+ CacheTexture thetex = textures.get(tex);
84568563 thetex.texture.disable();
84578564 thetex.texture.dispose();
8458
- textures.remove(texname);
8565
+ textures.remove(tex);
84598566 }
84608567
8461
- texture.texturedata = texturedata;
8462
- textures.put(texname, texture);
8568
+ //texture.texturedata = texturedata;
8569
+ textures.put(tex, texturecache);
84638570
84648571 // newtex = true;
84658572 }
....@@ -8475,10 +8582,44 @@
84758582 }
84768583 }
84778584
8478
- return texture;
8585
+ return texturecache;
84798586 }
84808587
8481
- 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
84828623 {
84838624 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
84848625
....@@ -8496,21 +8637,21 @@
84968637 return texture!=null?texture.texture:null;
84978638 }
84988639
8499
- 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
85008641 {
85018642 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
85028643
85038644 return texture!=null?texture.texturedata:null;
85048645 }
85058646
8506
- boolean BindTexture(String tex, boolean bump, int resolution) throws Exception
8647
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
85078648 {
85088649 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
85098650 {
85108651 return false;
85118652 }
85128653
8513
- boolean newtex = false;
8654
+ //boolean newtex = false;
85148655
85158656 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
85168657
....@@ -8542,9 +8683,75 @@
85428683 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
85438684 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
85448685
8545
- return newtex;
8686
+ return true; // Warning: not used.
85468687 }
85478688
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
+
85488755 ShadowBuffer shadowPBuf;
85498756 AntialiasBuffer antialiasPBuf;
85508757 int MAXSTACK;
....@@ -8737,7 +8944,7 @@
87378944
87388945 if (cubemap == null)
87398946 {
8740
- LoadEnvy(5);
8947
+ //LoadEnvy(1);
87418948 }
87428949
87438950 //cubemap.enable();
....@@ -9024,37 +9231,58 @@
90249231 cubemap = null;
90259232 return;
90269233 case 1:
9027
- name = "cubemaps/box_";
9028
- ext = "png";
9234
+ name = "cubemaps/rgb/";
9235
+ ext = "jpg";
90299236 reverseUP = false;
90309237 break;
90319238 case 2:
9032
- name = "cubemaps/uffizi_";
9033
- ext = "png";
9034
- break; // reverseUP = true; break;
9239
+ name = "cubemaps/uffizi/";
9240
+ ext = "jpg";
9241
+ reverseUP = false;
9242
+ break;
90359243 case 3:
9036
- name = "cubemaps/CloudyHills_";
9037
- ext = "tga";
9244
+ name = "cubemaps/CloudyHills/";
9245
+ ext = "jpg";
90389246 reverseUP = false;
90399247 break;
90409248 case 4:
9041
- name = "cubemaps/cornell_";
9249
+ name = "cubemaps/cornell/";
90429250 ext = "png";
90439251 reverseUP = false;
90449252 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;
90459278 default:
9046
- name = "cubemaps/rgb_";
9047
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9279
+ name = "cubemaps/box/";
9280
+ ext = "png"; /*mipmap = true;*/
9281
+ reverseUP = false;
90489282 break;
90499283 }
9050
-
9051
- try
9052
- {
9053
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
9054
- } catch (IOException e)
9055
- {
9056
- throw new RuntimeException(e);
9057
- }
9284
+
9285
+ LoadSkybox(name, ext, mipmap);
90589286 }
90599287
90609288 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -9086,8 +9314,12 @@
90869314 static double[] model = new double[16];
90879315 double[] camera2light = new double[16];
90889316 double[] light2camera = new double[16];
9089
- int newenvy = -1;
9090
- boolean envyoff = true; // false;
9317
+
9318
+ //int newenvy = -1;
9319
+ //boolean envyoff = false;
9320
+
9321
+ String loadedskyboxname;
9322
+
90919323 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
90929324 //float[] light0 = { 0,0,0 };
90939325 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9505,7 +9737,7 @@
95059737
95069738 if (renderCamera != lightCamera)
95079739 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9508
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
9740
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
95099741
95109742 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
95119743
....@@ -9521,7 +9753,7 @@
95219753
95229754 if (renderCamera != lightCamera)
95239755 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9524
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
9756
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
95259757
95269758 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
95279759
....@@ -9567,10 +9799,12 @@
95679799 rati = 1 / rati;
95689800 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
95699801 }
9570
- assert (newenvy == -1);
9802
+
9803
+ //assert (newenvy == -1);
9804
+
95719805 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
95729806 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9573
- DrawSkyBox(gl);
9807
+ DrawSkyBox(gl, (float)rati);
95749808 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
95759809 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
95769810 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10722,7 +10956,7 @@
1072210956 // if (parentcam != renderCamera) // not a light
1072310957 if (cam != lightCamera)
1072410958 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10725
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
10959
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1072610960
1072710961 for (int j = 0; j < 4; j++)
1072810962 {
....@@ -10737,7 +10971,7 @@
1073710971 // if (parentcam != renderCamera) // not a light
1073810972 if (cam != lightCamera)
1073910973 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10740
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
10974
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1074110975
1074210976 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1074310977
....@@ -10823,13 +11057,27 @@
1082311057 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1082411058 }
1082511059
10826
- if (newenvy > -1)
11060
+// if (newenvy > -1)
11061
+// {
11062
+// LoadEnvy(newenvy);
11063
+// }
11064
+//
11065
+// newenvy = -1;
11066
+
11067
+ if (object.skyboxname != null)
1082711068 {
10828
- LoadEnvy(newenvy);
11069
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11070
+ {
11071
+ LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11072
+ loadedskyboxname = object.skyboxname;
11073
+ }
1082911074 }
10830
-
10831
- newenvy = -1;
10832
-
11075
+ else
11076
+ {
11077
+ cubemap = null;
11078
+ loadedskyboxname = null;
11079
+ }
11080
+
1083311081 ratio = ((double) getWidth()) / getHeight();
1083411082 //System.out.println("ratio = " + ratio);
1083511083
....@@ -10845,7 +11093,7 @@
1084511093
1084611094 if (!IsFrozen() && !ambientOcclusion)
1084711095 {
10848
- DrawSkyBox(gl);
11096
+ DrawSkyBox(gl, (float)ratio);
1084911097 }
1085011098
1085111099 //if (selection_view == -1)
....@@ -11028,9 +11276,9 @@
1102811276
1102911277 gl.glMatrixMode(GL.GL_MODELVIEW);
1103011278
11031
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11032
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
11033
-//gl.glEnable(gl.GL_MULTISAMPLE);
11279
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11280
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11281
+gl.glEnable(gl.GL_MULTISAMPLE);
1103411282 } else
1103511283 {
1103611284 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -11041,7 +11289,7 @@
1104111289 //System.out.println("BLENDING ON");
1104211290 gl.glEnable(GL.GL_BLEND);
1104311291 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
11044
-
11292
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1104511293 gl.glMatrixMode(gl.GL_PROJECTION);
1104611294 gl.glLoadIdentity();
1104711295
....@@ -11131,7 +11379,7 @@
1113111379
1113211380 // if (cam != lightCamera)
1113311381 //for (int count = parentcam.GetTransformCount(); --count>=0;)
11134
- LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
11382
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1113511383 }
1113611384
1113711385 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -11290,7 +11538,7 @@
1129011538 }
1129111539 }
1129211540
11293
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11541
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1129411542 {
1129511543 //gl.glDepthFunc(GL.GL_LEQUAL);
1129611544 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11298,24 +11546,21 @@
1129811546
1129911547 boolean texon = textureon;
1130011548
11301
- if (RENDERPROGRAM > 0)
11302
- {
11303
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11304
- textureon = false;
11305
- }
11549
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11550
+ textureon = false;
11551
+
1130611552 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1130711553 //System.out.println("ALLO");
1130811554 gl.glColorMask(false, false, false, false);
1130911555 DrawObject(gl);
11310
- if (RENDERPROGRAM > 0)
11311
- {
11312
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11313
- textureon = texon;
11314
- }
11556
+
11557
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11558
+ textureon = texon;
11559
+
1131511560 gl.glColorMask(true, true, true, true);
1131611561
1131711562 gl.glDepthFunc(GL.GL_EQUAL);
11318
- //gl.glDepthMask(false);
11563
+ gl.glDepthMask(false);
1131911564 }
1132011565
1132111566 if (false) // DrawMode() == SHADOW)
....@@ -11655,20 +11900,32 @@
1165511900 ReleaseTextures(DEFAULT_TEXTURES);
1165611901
1165711902 if (CLEANCACHE)
11658
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11903
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1165911904 {
11660
- String tex = e.nextElement();
11905
+ cTexture tex = e.nextElement();
1166111906
1166211907 // System.out.println("Texture --------- " + tex);
1166311908
11664
- if (tex.equals("WHITE_NOISE"))
11909
+ if (tex.equals("WHITE_NOISE:"))
1166511910 continue;
1166611911
11667
- if (!usedtextures.containsKey(tex))
11912
+ if (!usedtextures.contains(tex))
1166811913 {
11914
+ CacheTexture gettex = texturepigment.get(tex);
1166911915 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11670
- textures.get(tex).texture.dispose();
11671
- textures.remove(tex);
11916
+ if (gettex != null)
11917
+ {
11918
+ gettex.texture.dispose();
11919
+ texturepigment.remove(tex);
11920
+ }
11921
+
11922
+ gettex = texturebump.get(tex);
11923
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11924
+ if (gettex != null)
11925
+ {
11926
+ gettex.texture.dispose();
11927
+ texturebump.remove(tex);
11928
+ }
1167211929 }
1167311930 }
1167411931 }
....@@ -12196,8 +12453,76 @@
1219612453
1219712454 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1219812455
12199
- String program =
12456
+ String programmin =
12457
+ // Min shader
1220012458 "!!ARBfp1.0\n" +
12459
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12460
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12461
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12462
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12463
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12464
+ "PARAM light2cam0 = program.env[10];" +
12465
+ "PARAM light2cam1 = program.env[11];" +
12466
+ "PARAM light2cam2 = program.env[12];" +
12467
+ "TEMP temp;" +
12468
+ "TEMP light;" +
12469
+ "TEMP ndotl;" +
12470
+ "TEMP normal;" +
12471
+ "TEMP depth;" +
12472
+ "TEMP eye;" +
12473
+ "TEMP pos;" +
12474
+
12475
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12476
+ Normalize("normal") +
12477
+ "MOV light, state.light[0].position;" +
12478
+ "DP3 ndotl.x, light, normal;" +
12479
+
12480
+ // shadow
12481
+ "MOV pos, fragment.texcoord[1];" +
12482
+ "MOV temp, pos;" +
12483
+ ShadowTextureFetch("depth", "temp", "1") +
12484
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12485
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12486
+
12487
+ // No shadow when out of frustum
12488
+ //"SGE temp.y, depth.z, zero123.y;" +
12489
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12490
+
12491
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12492
+
12493
+ // Backlit
12494
+ "MOV pos.w, zero123.y;" +
12495
+ "DP4 eye.x, pos, light2cam0;" +
12496
+ "DP4 eye.y, pos, light2cam1;" +
12497
+ "DP4 eye.z, pos, light2cam2;" +
12498
+ Normalize("eye") +
12499
+
12500
+ "DP3 ndotl.y, -eye, normal;" +
12501
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12502
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12503
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12504
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12505
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12506
+
12507
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12508
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12509
+
12510
+ // Pigment
12511
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12512
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12513
+ "MUL temp, temp, ndotl.x;" +
12514
+
12515
+ "MUL temp, temp, zero123.z;" +
12516
+
12517
+ //"MUL temp, temp, ndotl.y;" +
12518
+
12519
+ "MOV temp.w, zero123.y;" + // reset alpha
12520
+ "MOV result.color, temp;" +
12521
+ "END";
12522
+
12523
+ String programmax =
12524
+ "!!ARBfp1.0\n" +
12525
+
1220112526 //"OPTION ARB_fragment_program_shadow;" +
1220212527 "PARAM light2cam0 = program.env[10];" +
1220312528 "PARAM light2cam1 = program.env[11];" +
....@@ -12312,8 +12637,7 @@
1231212637 "TEMP shininess;" +
1231312638 "\n" +
1231412639 "MOV texSamp, one;" +
12315
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12316
-
12640
+
1231712641 "MOV mapgrid.x, one2048th.x;" +
1231812642 "MOV temp, fragment.texcoord[1];" +
1231912643 /*
....@@ -12334,20 +12658,20 @@
1233412658 "MUL temp, floor, mapgrid.x;" +
1233512659 //"TEX depth0, temp, texture[1], 2D;" +
1233612660 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12337
- TextureFetch("depth0", "temp", "1") +
12661
+ ShadowTextureFetch("depth0", "temp", "1") +
1233812662 "") +
1233912663 "ADD temp.x, temp.x, mapgrid.x;" +
1234012664 //"TEX depth1, temp, texture[1], 2D;" +
1234112665 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12342
- TextureFetch("depth1", "temp", "1") +
12666
+ ShadowTextureFetch("depth1", "temp", "1") +
1234312667 "") +
1234412668 "ADD temp.y, temp.y, mapgrid.x;" +
1234512669 //"TEX depth2, temp, texture[1], 2D;" +
12346
- TextureFetch("depth2", "temp", "1") +
12670
+ ShadowTextureFetch("depth2", "temp", "1") +
1234712671 "SUB temp.x, temp.x, mapgrid.x;" +
1234812672 //"TEX depth3, temp, texture[1], 2D;" +
1234912673 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12350
- TextureFetch("depth3", "temp", "1") +
12674
+ ShadowTextureFetch("depth3", "temp", "1") +
1235112675 "") +
1235212676 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1235312677 //"MOV params, material;" +
....@@ -12718,10 +13042,10 @@
1271813042 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1271913043 "") +
1272013044
12721
- // display shadow only (bump == 0)
13045
+ // display shadow only (fakedepth == 0)
1272213046 "SUB temp.x, half.x, shadow.x;" +
1272313047 "MOV temp.y, -params5.z;" + // params6.x;" +
12724
- "SLT temp.z, temp.y, -one2048th.x;" +
13048
+ "SLT temp.z, temp.y, -c256i.x;" +
1272513049 "SUB temp.y, one.x, temp.z;" +
1272613050 "MUL temp.x, temp.x, temp.y;" +
1272713051 "KIL temp.x;" +
....@@ -13052,6 +13376,13 @@
1305213376 //once = true;
1305313377 }
1305413378
13379
+ String program = programmax;
13380
+
13381
+ if (Globals.MINSHADER)
13382
+ {
13383
+ program = programmin;
13384
+ }
13385
+
1305513386 System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1305613387 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1305713388 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
....@@ -13145,25 +13476,26 @@
1314513476 return out;
1314613477 }
1314713478
13148
- String TextureFetch(String dest, String src, String unit)
13479
+ // Also does frustum culling
13480
+ String ShadowTextureFetch(String dest, String src, String unit)
1314913481 {
1315013482 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1315113483 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1315213484 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13485
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13486
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1315313487 "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;" +
13488
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13489
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1315813490 //"SWZ buffer, temp, w,w,w,w;";
13159
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13491
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1316013492 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1316113493 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1316213494 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13163
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13495
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1316413496
13165
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13166
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13497
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13498
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1316713499 }
1316813500
1316913501 String Shadow(String depth, String shadow)
....@@ -13210,7 +13542,7 @@
1321013542 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1321113543 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1321213544
13213
- // No shadow when out of frustrum
13545
+ // No shadow when out of frustum
1321413546 "SGE temp.x, " + depth + ".z, one.z;" +
1321513547 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1321613548 "";
....@@ -14008,14 +14340,15 @@
1400814340 drag = false;
1400914341 //System.out.println("Mouse DOWN");
1401014342 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);
14343
+ //ClickInfo info = new ClickInfo();
14344
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14345
+ object.clickInfo.pane = this;
14346
+ object.clickInfo.camera = renderCamera;
14347
+ object.clickInfo.x = x;
14348
+ object.clickInfo.y = y;
14349
+ object.clickInfo.modifiers = modifiersex;
14350
+ editObj = object.doEditClick(//info,
14351
+ 0);
1401914352 if (!editObj)
1402014353 {
1402114354 hasMarquee = true;
....@@ -14297,12 +14630,12 @@
1429714630 void GoDown(int mod)
1429814631 {
1429914632 MODIFIERS |= COMMAND;
14300
- /*
14633
+ /**/
1430114634 if((mod&SHIFT) == SHIFT)
14302
- manipCamera.RotatePosition(0, -speed);
14635
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
1430314636 else
14304
- manipCamera.BackForth(0, -speed*delta, getWidth());
14305
- */
14637
+ manipCamera.RotatePosition(0, -speed);
14638
+ /**/
1430614639 if ((mod & SHIFT) == SHIFT)
1430714640 {
1430814641 mouseMode = mouseMode; // VR??
....@@ -14318,12 +14651,12 @@
1431814651 void GoUp(int mod)
1431914652 {
1432014653 MODIFIERS |= COMMAND;
14321
- /*
14654
+ /**/
1432214655 if((mod&SHIFT) == SHIFT)
14323
- manipCamera.RotatePosition(0, speed);
14656
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
1432414657 else
14325
- manipCamera.BackForth(0, speed*delta, getWidth());
14326
- */
14658
+ manipCamera.RotatePosition(0, speed);
14659
+ /**/
1432714660 if ((mod & SHIFT) == SHIFT)
1432814661 {
1432914662 mouseMode = mouseMode;
....@@ -14339,12 +14672,12 @@
1433914672 void GoLeft(int mod)
1434014673 {
1434114674 MODIFIERS |= COMMAND;
14342
- /*
14675
+ /**/
1434314676 if((mod&SHIFT) == SHIFT)
14344
- manipCamera.RotatePosition(speed, 0);
14345
- else
1434614677 manipCamera.Translate(speed*delta, 0, getWidth());
14347
- */
14678
+ else
14679
+ manipCamera.RotatePosition(speed, 0);
14680
+ /**/
1434814681 if ((mod & SHIFT) == SHIFT)
1434914682 {
1435014683 mouseMode = mouseMode;
....@@ -14360,12 +14693,12 @@
1436014693 void GoRight(int mod)
1436114694 {
1436214695 MODIFIERS |= COMMAND;
14363
- /*
14696
+ /**/
1436414697 if((mod&SHIFT) == SHIFT)
14365
- manipCamera.RotatePosition(-speed, 0);
14366
- else
1436714698 manipCamera.Translate(-speed*delta, 0, getWidth());
14368
- */
14699
+ else
14700
+ manipCamera.RotatePosition(-speed, 0);
14701
+ /**/
1436914702 if ((mod & SHIFT) == SHIFT)
1437014703 {
1437114704 mouseMode = mouseMode;
....@@ -14415,15 +14748,16 @@
1441514748 if (editObj)
1441614749 {
1441714750 drag = true;
14418
- ClickInfo info = new ClickInfo();
14419
- info.bounds.setBounds(0, 0,
14751
+ //ClickInfo info = new ClickInfo();
14752
+ object.clickInfo.bounds.setBounds(0, 0,
1442014753 (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);
14754
+ object.clickInfo.pane = this;
14755
+ object.clickInfo.camera = renderCamera;
14756
+ object.clickInfo.x = x;
14757
+ object.clickInfo.y = y;
14758
+ object //.GetWindow().copy
14759
+ .doEditDrag(//info,
14760
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1442714761 } else
1442814762 {
1442914763 if (x < startX)
....@@ -14572,24 +14906,27 @@
1457214906 }
1457314907 }
1457414908
14909
+// ClickInfo clickInfo = new ClickInfo();
14910
+
1457514911 public void mouseMoved(MouseEvent e)
1457614912 {
1457714913 //System.out.println("mouseMoved: " + e);
1457814914 if (isRenderer)
1457914915 return;
1458014916
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;
14917
+ // Mouse cursor feedback
14918
+ object.clickInfo.x = e.getX();
14919
+ object.clickInfo.y = e.getY();
14920
+ object.clickInfo.modifiers = e.getModifiersEx();
14921
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14922
+ object.clickInfo.pane = this;
14923
+ object.clickInfo.camera = renderCamera;
1458814924 if (!isRenderer)
1458914925 {
1459014926 //ObjEditor editWindow = object.editWindow;
1459114927 //Object3D copy = editWindow.copy;
14592
- if (object.doEditClick(ci, 0))
14928
+ if (object.doEditClick(//clickInfo,
14929
+ 0))
1459314930 {
1459414931 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1459514932 } else
....@@ -14861,7 +15198,8 @@
1486115198 // break;
1486215199 case 'T':
1486315200 CACHETEXTURE ^= true;
14864
- textures.clear();
15201
+ texturepigment.clear();
15202
+ texturebump.clear();
1486515203 // repaint();
1486615204 break;
1486715205 case 'Y':
....@@ -14946,7 +15284,9 @@
1494615284 case 'E' : COMPACT ^= true;
1494715285 repaint();
1494815286 break;
14949
- case 'W' : DEBUGHSB ^= true;
15287
+ case 'W' : // Wide Window (fullscreen)
15288
+ //DEBUGHSB ^= true;
15289
+ ObjEditor.theFrame.ToggleFullScreen();
1495015290 repaint();
1495115291 break;
1495215292 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14972,13 +15312,7 @@
1497215312 repaint();
1497315313 break;
1497415314 case 'l':
14975
- lightMode ^= true;
14976
- Globals.lighttouched = true;
14977
- manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
14978
- targetLookAt.set(manipCamera.lookAt);
14979
- repaint();
14980
- break;
14981
- case 'L':
15315
+ //case 'L':
1498215316 if (lightMode)
1498315317 {
1498415318 lightMode = false;
....@@ -15042,20 +15376,24 @@
1504215376 OCCLUSION_CULLING ^= true;
1504315377 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1504415378 break;
15045
- case '0': envyoff ^= true; repaint(); break;
15379
+ //case '0': envyoff ^= true; repaint(); break;
1504615380 case '1':
1504715381 case '2':
1504815382 case '3':
1504915383 case '4':
1505015384 case '5':
15051
- newenvy = Character.getNumericValue(key);
15052
- repaint();
15053
- break;
1505415385 case '6':
1505515386 case '7':
1505615387 case '8':
1505715388 case '9':
15058
- BGcolor = (key - '6')/3.f;
15389
+ if (true) // envyoff)
15390
+ {
15391
+ BGcolor = (key - '1')/8.f;
15392
+ }
15393
+ else
15394
+ {
15395
+ //newenvy = Character.getNumericValue(key);
15396
+ }
1505915397 repaint();
1506015398 break;
1506115399 case '!':
....@@ -15125,7 +15463,10 @@
1512515463 // kompactbit = 6;
1512615464 // break;
1512715465 case ' ':
15128
- ObjEditor.theFrame.ToggleFullScreen();
15466
+ lightMode ^= true;
15467
+ Globals.lighttouched = true;
15468
+ manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
15469
+ targetLookAt.set(manipCamera.lookAt);
1512915470 repaint();
1513015471 break;
1513115472 //case '`' :
....@@ -15615,8 +15956,6 @@
1561515956
1561615957 int width = getBounds().width;
1561715958 int height = getBounds().height;
15618
- ClickInfo info = new ClickInfo();
15619
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1562015959 //Image img = CreateImage(width, height);
1562115960 //System.out.println("width = " + width + "; height = " + height + "\n");
1562215961
....@@ -15693,38 +16032,47 @@
1569316032 }
1569416033 if (object != null && !hasMarquee)
1569516034 {
16035
+ if (object.clickInfo == null)
16036
+ object.clickInfo = new ClickInfo();
16037
+ ClickInfo info = object.clickInfo;
16038
+ //ClickInfo info = new ClickInfo();
16039
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16040
+
1569616041 if (isRenderer)
1569716042 {
15698
- info.flags++;
16043
+ object.clickInfo.flags++;
1569916044 double frameAspect = (double) width / (double) height;
1570016045 if (frameAspect > renderCamera.aspect)
1570116046 {
1570216047 int desired = (int) ((double) height * renderCamera.aspect);
15703
- info.bounds.width -= width - desired;
15704
- info.bounds.x += (width - desired) / 2;
16048
+ object.clickInfo.bounds.width -= width - desired;
16049
+ object.clickInfo.bounds.x += (width - desired) / 2;
1570516050 } else
1570616051 {
1570716052 int desired = (int) ((double) width / renderCamera.aspect);
15708
- info.bounds.height -= height - desired;
15709
- info.bounds.y += (height - desired) / 2;
16053
+ object.clickInfo.bounds.height -= height - desired;
16054
+ object.clickInfo.bounds.y += (height - desired) / 2;
1571016055 }
1571116056 }
15712
- info.g = gr;
15713
- info.camera = renderCamera;
16057
+
16058
+ object.clickInfo.g = gr;
16059
+ object.clickInfo.camera = renderCamera;
1571416060 /*
1571516061 // Memory intensive (brep.verticescopy)
1571616062 if (!(object instanceof Composite))
1571716063 object.draw(info, 0, false); // SLOW :
1571816064 */
15719
- if (!isRenderer)
16065
+ if (!isRenderer) // && drag)
1572016066 {
16067
+ Grafreed.Assert(object != null);
16068
+ Grafreed.Assert(object.selection != null);
1572116069 if (object.selection.Size() > 0)
1572216070 {
1572316071 int hitSomething = object.selection.get(0).hitSomething;
1572416072
15725
- info.DX = 0;
15726
- info.DY = 0;
15727
- info.W = 1;
16073
+ object.clickInfo.DX = 0;
16074
+ object.clickInfo.DY = 0;
16075
+ object.clickInfo.W = 1;
1572816076 if (hitSomething == Object3D.hitCenter)
1572916077 {
1573016078 info.DX = X;
....@@ -15736,7 +16084,8 @@
1573616084 info.DY -= info.bounds.height/2;
1573716085 }
1573816086
15739
- object.drawEditHandles(info, 0);
16087
+ object.drawEditHandles(//info,
16088
+ 0);
1574016089
1574116090 if (drag && (X != 0 || Y != 0))
1574216091 {
....@@ -16235,6 +16584,8 @@
1623516584 private /*static*/ boolean firstime;
1623616585 private /*static*/ cVector newView = new cVector();
1623716586 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16587
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16588
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1623816589 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1623916590 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1624016591 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16247,29 +16598,66 @@
1624716598 {
1624816599 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1624916600
16601
+ int usedsuf = 0;
16602
+
1625016603 for (int i = 0; i < suffixes.length; i++)
1625116604 {
16252
- String resourceName = basename + suffixes[i] + "." + suffix;
16253
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16254
- mipmapped,
16255
- FileUtil.getFileSuffix(resourceName));
16256
- if (data == null)
16605
+ String[] suffixe = suffixes;
16606
+ String[] fallback = suffixes2;
16607
+ String[] fallfallback = suffixes3;
16608
+
16609
+ for (int c=usedsuf; --c>=0;)
1625716610 {
16258
- throw new IOException("Unable to load texture " + resourceName);
16611
+// String[] temp = suffixe;
16612
+// suffixe = fallback;
16613
+// fallback = fallfallback;
16614
+// fallfallback = temp;
1625916615 }
16616
+
16617
+ String resourceName = basename + suffixe[i] + "." + suffix;
16618
+ TextureData data;
16619
+
16620
+ try
16621
+ {
16622
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16623
+ mipmapped,
16624
+ FileUtil.getFileSuffix(resourceName));
16625
+ }
16626
+ catch (Exception e)
16627
+ {
16628
+ try
16629
+ {
16630
+ resourceName = basename + fallback[i] + "." + suffix;
16631
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16632
+ mipmapped,
16633
+ FileUtil.getFileSuffix(resourceName));
16634
+ }
16635
+ catch (Exception e2)
16636
+ {
16637
+ resourceName = basename + fallfallback[i] + "." + suffix;
16638
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16639
+ mipmapped,
16640
+ FileUtil.getFileSuffix(resourceName));
16641
+ }
16642
+ }
16643
+
1626016644 //System.out.println("Target = " + targets[i]);
1626116645 cubemap.updateImage(data, targets[i]);
1626216646 }
1626316647
1626416648 return cubemap;
1626516649 }
16650
+
1626616651 int bigsphere = -1;
1626716652
1626816653 float BGcolor = 0.5f;
1626916654
16270
- private void DrawSkyBox(GL gl)
16655
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16656
+
16657
+ private void DrawSkyBox(GL gl, float ratio)
1627116658 {
16272
- if (envyoff || cubemap == null)
16659
+ if (//envyoff ||
16660
+ cubemap == null)
1627316661 {
1627416662 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1627516663 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16284,7 +16672,17 @@
1628416672 // Compensates for ExaminerViewer's modification of modelview matrix
1628516673 gl.glMatrixMode(GL.GL_MODELVIEW);
1628616674 gl.glLoadIdentity();
16675
+ gl.glScalef(1,ratio,1);
1628716676
16677
+// colorV[0] = 2;
16678
+// colorV[1] = 2;
16679
+// colorV[2] = 2;
16680
+// colorV[3] = 1;
16681
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16682
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16683
+//
16684
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16685
+
1628816686 //gl.glActiveTexture(GL.GL_TEXTURE1);
1628916687 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1629016688
....@@ -16316,6 +16714,7 @@
1631616714 {
1631716715 gl.glScalef(1.0f, -1.0f, 1.0f);
1631816716 }
16717
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1631916718 gl.glMultMatrixd(viewrot_1, 0);
1632016719 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1632116720 //viewer.updateInverseRotation(gl);
....@@ -16551,6 +16950,14 @@
1655116950 }
1655216951 }
1655316952
16953
+ private Object3D GetFolder()
16954
+ {
16955
+ Object3D folder = object.GetWindow().copy;
16956
+ if (object.GetWindow().copy.selection.Size() > 0)
16957
+ folder = object.GetWindow().copy.selection.elementAt(0);
16958
+ return folder;
16959
+ }
16960
+
1655416961 class SelectBuffer implements GLEventListener
1655516962 {
1655616963
....@@ -16566,7 +16973,7 @@
1656616973 //new Exception().printStackTrace();
1656716974 System.out.println("select buffer init");
1656816975 // Use debug pipeline
16569
- drawable.setGL(new DebugGL(drawable.getGL()));
16976
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1657016977
1657116978 GL gl = drawable.getGL();
1657216979
....@@ -16630,6 +17037,17 @@
1663017037
1663117038 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1663217039
17040
+ if (PAINTMODE)
17041
+ {
17042
+ if (object.GetWindow().copy.selection.Size() > 0)
17043
+ {
17044
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17045
+
17046
+ // Make what you paint not selectable.
17047
+ paintobj.ResetSelectable();
17048
+ }
17049
+ }
17050
+
1663317051 //int tmp = selection_view;
1663417052 //selection_view = -1;
1663517053 int temp = DrawMode();
....@@ -16641,6 +17059,17 @@
1664117059 // temp = DEFAULT; // patch for selection debug
1664217060 Globals.drawMode = temp; // WARNING
1664317061
17062
+ if (PAINTMODE)
17063
+ {
17064
+ if (object.GetWindow().copy.selection.Size() > 0)
17065
+ {
17066
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17067
+
17068
+ // Revert.
17069
+ paintobj.RestoreSelectable();
17070
+ }
17071
+ }
17072
+
1664417073 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1664517074
1664617075 // trying different ways of getting the depth info over
....@@ -16746,27 +17175,29 @@
1674617175 if (!movingcamera && !PAINTMODE)
1674717176 object.GetWindow().ScreenFitPoint(); // fev 2014
1674817177
16749
- if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17178
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1675017179 {
16751
- Object3D paintobj = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
16752
-
16753
- Object3D group = new Object3D("inst" + paintcount++);
16754
-
16755
- group.CreateMaterial(); // use a void leaf to select instances
16756
-
16757
- group.add(paintobj); // link
16758
-
16759
- object.GetWindow().SnapObject(group);
16760
-
16761
- Object3D folder = object.GetWindow().copy;
17180
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1676217181
1676317182 if (object.GetWindow().copy.selection.Size() > 0)
16764
- folder = object.GetWindow().copy.selection.elementAt(0);
17183
+ {
17184
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1676517185
16766
- folder.add(group);
16767
-
16768
- object.GetWindow().ResetModel();
16769
- object.GetWindow().refreshContents();
17186
+ Object3D inst = new Object3D("inst" + paintcount++);
17187
+
17188
+ inst.CreateMaterial(); // use a void leaf to select instances
17189
+
17190
+ inst.add(paintobj); // link
17191
+
17192
+ object.GetWindow().SnapObject(inst);
17193
+
17194
+ Object3D folder = paintFolder; // GetFolder();
17195
+
17196
+ folder.add(inst);
17197
+
17198
+ object.GetWindow().ResetModel();
17199
+ object.GetWindow().refreshContents();
17200
+ }
1677017201 }
1677117202 else
1677217203 paintcount = 0;