Normand Briere
2019-07-28 a434119e65146fe53d612c28e1ee7af532d1b70a
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,13 @@
90869314 static double[] model = new double[16];
90879315 double[] camera2light = new double[16];
90889316 double[] light2camera = new double[16];
9089
- int newenvy = -1;
9317
+
9318
+ //int newenvy = -1;
90909319 boolean envyoff = true; // false;
9320
+ String skyboxname = "";
9321
+ String skyboxext;
9322
+ String loadedskyboxname = "";
9323
+
90919324 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
90929325 //float[] light0 = { 0,0,0 };
90939326 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9505,7 +9738,7 @@
95059738
95069739 if (renderCamera != lightCamera)
95079740 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9508
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
9741
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
95099742
95109743 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
95119744
....@@ -9521,7 +9754,7 @@
95219754
95229755 if (renderCamera != lightCamera)
95239756 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9524
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
9757
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
95259758
95269759 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
95279760
....@@ -9567,10 +9800,12 @@
95679800 rati = 1 / rati;
95689801 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
95699802 }
9570
- assert (newenvy == -1);
9803
+
9804
+ //assert (newenvy == -1);
9805
+
95719806 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
95729807 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9573
- DrawSkyBox(gl);
9808
+ DrawSkyBox(gl, (float)rati);
95749809 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
95759810 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
95769811 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10722,7 +10957,7 @@
1072210957 // if (parentcam != renderCamera) // not a light
1072310958 if (cam != lightCamera)
1072410959 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10725
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
10960
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1072610961
1072710962 for (int j = 0; j < 4; j++)
1072810963 {
....@@ -10737,7 +10972,7 @@
1073710972 // if (parentcam != renderCamera) // not a light
1073810973 if (cam != lightCamera)
1073910974 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10740
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
10975
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1074110976
1074210977 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1074310978
....@@ -10823,13 +11058,19 @@
1082311058 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1082411059 }
1082511060
10826
- if (newenvy > -1)
11061
+// if (newenvy > -1)
11062
+// {
11063
+// LoadEnvy(newenvy);
11064
+// }
11065
+//
11066
+// newenvy = -1;
11067
+
11068
+ if (!skyboxname.equals(this.loadedskyboxname))
1082711069 {
10828
- LoadEnvy(newenvy);
11070
+ LoadSkybox(skyboxname + "/", skyboxext, false);
11071
+ loadedskyboxname = skyboxname;
1082911072 }
10830
-
10831
- newenvy = -1;
10832
-
11073
+
1083311074 ratio = ((double) getWidth()) / getHeight();
1083411075 //System.out.println("ratio = " + ratio);
1083511076
....@@ -10845,7 +11086,7 @@
1084511086
1084611087 if (!IsFrozen() && !ambientOcclusion)
1084711088 {
10848
- DrawSkyBox(gl);
11089
+ DrawSkyBox(gl, (float)ratio);
1084911090 }
1085011091
1085111092 //if (selection_view == -1)
....@@ -11290,7 +11531,7 @@
1129011531 }
1129111532 }
1129211533
11293
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11534
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1129411535 {
1129511536 //gl.glDepthFunc(GL.GL_LEQUAL);
1129611537 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11298,24 +11539,21 @@
1129811539
1129911540 boolean texon = textureon;
1130011541
11301
- if (RENDERPROGRAM > 0)
11302
- {
11303
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11304
- textureon = false;
11305
- }
11542
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11543
+ textureon = false;
11544
+
1130611545 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1130711546 //System.out.println("ALLO");
1130811547 gl.glColorMask(false, false, false, false);
1130911548 DrawObject(gl);
11310
- if (RENDERPROGRAM > 0)
11311
- {
11312
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11313
- textureon = texon;
11314
- }
11549
+
11550
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11551
+ textureon = texon;
11552
+
1131511553 gl.glColorMask(true, true, true, true);
1131611554
1131711555 gl.glDepthFunc(GL.GL_EQUAL);
11318
- //gl.glDepthMask(false);
11556
+ gl.glDepthMask(false);
1131911557 }
1132011558
1132111559 if (false) // DrawMode() == SHADOW)
....@@ -11655,20 +11893,32 @@
1165511893 ReleaseTextures(DEFAULT_TEXTURES);
1165611894
1165711895 if (CLEANCACHE)
11658
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11896
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1165911897 {
11660
- String tex = e.nextElement();
11898
+ cTexture tex = e.nextElement();
1166111899
1166211900 // System.out.println("Texture --------- " + tex);
1166311901
11664
- if (tex.equals("WHITE_NOISE"))
11902
+ if (tex.equals("WHITE_NOISE:"))
1166511903 continue;
1166611904
11667
- if (!usedtextures.containsKey(tex))
11905
+ if (!usedtextures.contains(tex))
1166811906 {
11907
+ CacheTexture gettex = texturepigment.get(tex);
1166911908 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11670
- textures.get(tex).texture.dispose();
11671
- textures.remove(tex);
11909
+ if (gettex != null)
11910
+ {
11911
+ gettex.texture.dispose();
11912
+ texturepigment.remove(tex);
11913
+ }
11914
+
11915
+ gettex = texturebump.get(tex);
11916
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11917
+ if (gettex != null)
11918
+ {
11919
+ gettex.texture.dispose();
11920
+ texturebump.remove(tex);
11921
+ }
1167211922 }
1167311923 }
1167411924 }
....@@ -12196,8 +12446,76 @@
1219612446
1219712447 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1219812448
12449
+ String program0 =
12450
+ // Min shader
12451
+ "!!ARBfp1.0\n" +
12452
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12453
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12454
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12455
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12456
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12457
+ "PARAM light2cam0 = program.env[10];" +
12458
+ "PARAM light2cam1 = program.env[11];" +
12459
+ "PARAM light2cam2 = program.env[12];" +
12460
+ "TEMP temp;" +
12461
+ "TEMP light;" +
12462
+ "TEMP ndotl;" +
12463
+ "TEMP normal;" +
12464
+ "TEMP depth;" +
12465
+ "TEMP eye;" +
12466
+ "TEMP pos;" +
12467
+
12468
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12469
+ Normalize("normal") +
12470
+ "MOV light, state.light[0].position;" +
12471
+ "DP3 ndotl.x, light, normal;" +
12472
+
12473
+ // shadow
12474
+ "MOV pos, fragment.texcoord[1];" +
12475
+ "MOV temp, pos;" +
12476
+ ShadowTextureFetch("depth", "temp", "1") +
12477
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12478
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12479
+
12480
+ // No shadow when out of frustum
12481
+ //"SGE temp.y, depth.z, zero123.y;" +
12482
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12483
+
12484
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12485
+
12486
+ // Backlit
12487
+ "MOV pos.w, zero123.y;" +
12488
+ "DP4 eye.x, pos, light2cam0;" +
12489
+ "DP4 eye.y, pos, light2cam1;" +
12490
+ "DP4 eye.z, pos, light2cam2;" +
12491
+ Normalize("eye") +
12492
+
12493
+ "DP3 ndotl.y, -eye, normal;" +
12494
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12495
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12496
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12497
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12498
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12499
+
12500
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12501
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12502
+
12503
+ // Pigment
12504
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12505
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12506
+ "MUL temp, temp, ndotl.x;" +
12507
+
12508
+ "MUL temp, temp, zero123.z;" +
12509
+
12510
+ //"MUL temp, temp, ndotl.y;" +
12511
+
12512
+ "MOV temp.w, zero123.y;" + // reset alpha
12513
+ "MOV result.color, temp;" +
12514
+ "END";
12515
+
1219912516 String program =
1220012517 "!!ARBfp1.0\n" +
12518
+
1220112519 //"OPTION ARB_fragment_program_shadow;" +
1220212520 "PARAM light2cam0 = program.env[10];" +
1220312521 "PARAM light2cam1 = program.env[11];" +
....@@ -12312,8 +12630,7 @@
1231212630 "TEMP shininess;" +
1231312631 "\n" +
1231412632 "MOV texSamp, one;" +
12315
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12316
-
12633
+
1231712634 "MOV mapgrid.x, one2048th.x;" +
1231812635 "MOV temp, fragment.texcoord[1];" +
1231912636 /*
....@@ -12334,20 +12651,20 @@
1233412651 "MUL temp, floor, mapgrid.x;" +
1233512652 //"TEX depth0, temp, texture[1], 2D;" +
1233612653 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12337
- TextureFetch("depth0", "temp", "1") +
12654
+ ShadowTextureFetch("depth0", "temp", "1") +
1233812655 "") +
1233912656 "ADD temp.x, temp.x, mapgrid.x;" +
1234012657 //"TEX depth1, temp, texture[1], 2D;" +
1234112658 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12342
- TextureFetch("depth1", "temp", "1") +
12659
+ ShadowTextureFetch("depth1", "temp", "1") +
1234312660 "") +
1234412661 "ADD temp.y, temp.y, mapgrid.x;" +
1234512662 //"TEX depth2, temp, texture[1], 2D;" +
12346
- TextureFetch("depth2", "temp", "1") +
12663
+ ShadowTextureFetch("depth2", "temp", "1") +
1234712664 "SUB temp.x, temp.x, mapgrid.x;" +
1234812665 //"TEX depth3, temp, texture[1], 2D;" +
1234912666 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12350
- TextureFetch("depth3", "temp", "1") +
12667
+ ShadowTextureFetch("depth3", "temp", "1") +
1235112668 "") +
1235212669 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1235312670 //"MOV params, material;" +
....@@ -12718,7 +13035,7 @@
1271813035 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1271913036 "") +
1272013037
12721
- // display shadow only (bump == 0)
13038
+ // display shadow only (fakedepth == 0)
1272213039 "SUB temp.x, half.x, shadow.x;" +
1272313040 "MOV temp.y, -params5.z;" + // params6.x;" +
1272413041 "SLT temp.z, temp.y, -one2048th.x;" +
....@@ -13145,25 +13462,26 @@
1314513462 return out;
1314613463 }
1314713464
13148
- String TextureFetch(String dest, String src, String unit)
13465
+ // Also does frustum culling
13466
+ String ShadowTextureFetch(String dest, String src, String unit)
1314913467 {
1315013468 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1315113469 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1315213470 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13471
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13472
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1315313473 "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;" +
13474
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13475
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1315813476 //"SWZ buffer, temp, w,w,w,w;";
13159
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13477
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1316013478 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1316113479 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1316213480 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13163
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13481
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1316413482
13165
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13166
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13483
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13484
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1316713485 }
1316813486
1316913487 String Shadow(String depth, String shadow)
....@@ -13210,7 +13528,7 @@
1321013528 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1321113529 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1321213530
13213
- // No shadow when out of frustrum
13531
+ // No shadow when out of frustum
1321413532 "SGE temp.x, " + depth + ".z, one.z;" +
1321513533 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1321613534 "";
....@@ -14008,14 +14326,15 @@
1400814326 drag = false;
1400914327 //System.out.println("Mouse DOWN");
1401014328 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);
14329
+ //ClickInfo info = new ClickInfo();
14330
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14331
+ object.clickInfo.pane = this;
14332
+ object.clickInfo.camera = renderCamera;
14333
+ object.clickInfo.x = x;
14334
+ object.clickInfo.y = y;
14335
+ object.clickInfo.modifiers = modifiersex;
14336
+ editObj = object.doEditClick(//info,
14337
+ 0);
1401914338 if (!editObj)
1402014339 {
1402114340 hasMarquee = true;
....@@ -14415,15 +14734,16 @@
1441514734 if (editObj)
1441614735 {
1441714736 drag = true;
14418
- ClickInfo info = new ClickInfo();
14419
- info.bounds.setBounds(0, 0,
14737
+ //ClickInfo info = new ClickInfo();
14738
+ object.clickInfo.bounds.setBounds(0, 0,
1442014739 (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);
14740
+ object.clickInfo.pane = this;
14741
+ object.clickInfo.camera = renderCamera;
14742
+ object.clickInfo.x = x;
14743
+ object.clickInfo.y = y;
14744
+ object //.GetWindow().copy
14745
+ .doEditDrag(//info,
14746
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1442714747 } else
1442814748 {
1442914749 if (x < startX)
....@@ -14572,24 +14892,27 @@
1457214892 }
1457314893 }
1457414894
14895
+// ClickInfo clickInfo = new ClickInfo();
14896
+
1457514897 public void mouseMoved(MouseEvent e)
1457614898 {
1457714899 //System.out.println("mouseMoved: " + e);
1457814900 if (isRenderer)
1457914901 return;
1458014902
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;
14903
+ // Mouse cursor feedback
14904
+ object.clickInfo.x = e.getX();
14905
+ object.clickInfo.y = e.getY();
14906
+ object.clickInfo.modifiers = e.getModifiersEx();
14907
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14908
+ object.clickInfo.pane = this;
14909
+ object.clickInfo.camera = renderCamera;
1458814910 if (!isRenderer)
1458914911 {
1459014912 //ObjEditor editWindow = object.editWindow;
1459114913 //Object3D copy = editWindow.copy;
14592
- if (object.doEditClick(ci, 0))
14914
+ if (object.doEditClick(//clickInfo,
14915
+ 0))
1459314916 {
1459414917 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1459514918 } else
....@@ -14861,7 +15184,8 @@
1486115184 // break;
1486215185 case 'T':
1486315186 CACHETEXTURE ^= true;
14864
- textures.clear();
15187
+ texturepigment.clear();
15188
+ texturebump.clear();
1486515189 // repaint();
1486615190 break;
1486715191 case 'Y':
....@@ -15044,14 +15368,18 @@
1504415368 case '3':
1504515369 case '4':
1504615370 case '5':
15047
- newenvy = Character.getNumericValue(key);
15048
- repaint();
15049
- break;
1505015371 case '6':
1505115372 case '7':
1505215373 case '8':
1505315374 case '9':
15054
- BGcolor = (key - '6')/3.f;
15375
+ if (envyoff)
15376
+ {
15377
+ BGcolor = (key - '1')/8.f;
15378
+ }
15379
+ else
15380
+ {
15381
+ //newenvy = Character.getNumericValue(key);
15382
+ }
1505515383 repaint();
1505615384 break;
1505715385 case '!':
....@@ -15614,8 +15942,6 @@
1561415942
1561515943 int width = getBounds().width;
1561615944 int height = getBounds().height;
15617
- ClickInfo info = new ClickInfo();
15618
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1561915945 //Image img = CreateImage(width, height);
1562015946 //System.out.println("width = " + width + "; height = " + height + "\n");
1562115947
....@@ -15692,31 +16018,37 @@
1569216018 }
1569316019 if (object != null && !hasMarquee)
1569416020 {
16021
+ if (object.clickInfo == null)
16022
+ object.clickInfo = new ClickInfo();
16023
+ ClickInfo info = object.clickInfo;
16024
+ //ClickInfo info = new ClickInfo();
16025
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16026
+
1569516027 if (isRenderer)
1569616028 {
15697
- info.flags++;
16029
+ object.clickInfo.flags++;
1569816030 double frameAspect = (double) width / (double) height;
1569916031 if (frameAspect > renderCamera.aspect)
1570016032 {
1570116033 int desired = (int) ((double) height * renderCamera.aspect);
15702
- info.bounds.width -= width - desired;
15703
- info.bounds.x += (width - desired) / 2;
16034
+ object.clickInfo.bounds.width -= width - desired;
16035
+ object.clickInfo.bounds.x += (width - desired) / 2;
1570416036 } else
1570516037 {
1570616038 int desired = (int) ((double) width / renderCamera.aspect);
15707
- info.bounds.height -= height - desired;
15708
- info.bounds.y += (height - desired) / 2;
16039
+ object.clickInfo.bounds.height -= height - desired;
16040
+ object.clickInfo.bounds.y += (height - desired) / 2;
1570916041 }
1571016042 }
1571116043
15712
- info.g = gr;
15713
- info.camera = renderCamera;
16044
+ object.clickInfo.g = gr;
16045
+ object.clickInfo.camera = renderCamera;
1571416046 /*
1571516047 // Memory intensive (brep.verticescopy)
1571616048 if (!(object instanceof Composite))
1571716049 object.draw(info, 0, false); // SLOW :
1571816050 */
15719
- if (!isRenderer)
16051
+ if (!isRenderer) // && drag)
1572016052 {
1572116053 Grafreed.Assert(object != null);
1572216054 Grafreed.Assert(object.selection != null);
....@@ -15724,9 +16056,9 @@
1572416056 {
1572516057 int hitSomething = object.selection.get(0).hitSomething;
1572616058
15727
- info.DX = 0;
15728
- info.DY = 0;
15729
- info.W = 1;
16059
+ object.clickInfo.DX = 0;
16060
+ object.clickInfo.DY = 0;
16061
+ object.clickInfo.W = 1;
1573016062 if (hitSomething == Object3D.hitCenter)
1573116063 {
1573216064 info.DX = X;
....@@ -15738,7 +16070,8 @@
1573816070 info.DY -= info.bounds.height/2;
1573916071 }
1574016072
15741
- object.drawEditHandles(info, 0);
16073
+ object.drawEditHandles(//info,
16074
+ 0);
1574216075
1574316076 if (drag && (X != 0 || Y != 0))
1574416077 {
....@@ -15751,7 +16084,7 @@
1575116084 gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
1575216085 break;
1575316086 case Object3D.hitScale: gr.setColor(Color.cyan);
15754
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16087
+ gr.drawLine(X, Y, 0, 0);
1575516088 break;
1575616089 }
1575716090
....@@ -16269,7 +16602,9 @@
1626916602
1627016603 float BGcolor = 0.5f;
1627116604
16272
- private void DrawSkyBox(GL gl)
16605
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16606
+
16607
+ private void DrawSkyBox(GL gl, float ratio)
1627316608 {
1627416609 if (envyoff || cubemap == null)
1627516610 {
....@@ -16286,7 +16621,17 @@
1628616621 // Compensates for ExaminerViewer's modification of modelview matrix
1628716622 gl.glMatrixMode(GL.GL_MODELVIEW);
1628816623 gl.glLoadIdentity();
16624
+ gl.glScalef(1,ratio,1);
1628916625
16626
+ colorV[0] = 2;
16627
+ colorV[1] = 2;
16628
+ colorV[2] = 2;
16629
+ colorV[3] = 1;
16630
+ gl.glDisable(gl.GL_COLOR_MATERIAL);
16631
+ gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16632
+
16633
+ gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16634
+
1629016635 //gl.glActiveTexture(GL.GL_TEXTURE1);
1629116636 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1629216637
....@@ -16299,7 +16644,7 @@
1629916644 // GL_NORMAL_MAP texgen mode. Temporarily enabling lighting
1630016645 // causes the normals to be sent down. Thanks to Ken Dyke.
1630116646 //gl.glEnable(GL.GL_LIGHTING);
16302
- gl.glDisable(GL.GL_LIGHTING);
16647
+ gl.glEnable(GL.GL_LIGHTING);
1630316648
1630416649 gl.glTexGeni(GL.GL_S, GL.GL_TEXTURE_GEN_MODE, GL.GL_NORMAL_MAP);
1630516650 gl.glTexGeni(GL.GL_T, GL.GL_TEXTURE_GEN_MODE, GL.GL_NORMAL_MAP);
....@@ -16553,6 +16898,14 @@
1655316898 }
1655416899 }
1655516900
16901
+ private Object3D GetFolder()
16902
+ {
16903
+ Object3D folder = object.GetWindow().copy;
16904
+ if (object.GetWindow().copy.selection.Size() > 0)
16905
+ folder = object.GetWindow().copy.selection.elementAt(0);
16906
+ return folder;
16907
+ }
16908
+
1655616909 class SelectBuffer implements GLEventListener
1655716910 {
1655816911
....@@ -16568,7 +16921,7 @@
1656816921 //new Exception().printStackTrace();
1656916922 System.out.println("select buffer init");
1657016923 // Use debug pipeline
16571
- drawable.setGL(new DebugGL(drawable.getGL()));
16924
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1657216925
1657316926 GL gl = drawable.getGL();
1657416927
....@@ -16632,6 +16985,17 @@
1663216985
1663316986 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1663416987
16988
+ if (PAINTMODE)
16989
+ {
16990
+ if (object.GetWindow().copy.selection.Size() > 0)
16991
+ {
16992
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16993
+
16994
+ // Make what you paint not selectable.
16995
+ paintobj.ResetSelectable();
16996
+ }
16997
+ }
16998
+
1663516999 //int tmp = selection_view;
1663617000 //selection_view = -1;
1663717001 int temp = DrawMode();
....@@ -16643,6 +17007,17 @@
1664317007 // temp = DEFAULT; // patch for selection debug
1664417008 Globals.drawMode = temp; // WARNING
1664517009
17010
+ if (PAINTMODE)
17011
+ {
17012
+ if (object.GetWindow().copy.selection.Size() > 0)
17013
+ {
17014
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17015
+
17016
+ // Revert.
17017
+ paintobj.RestoreSelectable();
17018
+ }
17019
+ }
17020
+
1664617021 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1664717022
1664817023 // trying different ways of getting the depth info over
....@@ -16748,27 +17123,29 @@
1674817123 if (!movingcamera && !PAINTMODE)
1674917124 object.GetWindow().ScreenFitPoint(); // fev 2014
1675017125
16751
- if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17126
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1675217127 {
16753
- Object3D paintobj = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
16754
-
16755
- Object3D group = new Object3D("inst" + paintcount++);
16756
-
16757
- group.CreateMaterial(); // use a void leaf to select instances
16758
-
16759
- group.add(paintobj); // link
16760
-
16761
- object.GetWindow().SnapObject(group);
16762
-
16763
- Object3D folder = object.GetWindow().copy;
17128
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1676417129
1676517130 if (object.GetWindow().copy.selection.Size() > 0)
16766
- folder = object.GetWindow().copy.selection.elementAt(0);
17131
+ {
17132
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1676717133
16768
- folder.add(group);
16769
-
16770
- object.GetWindow().ResetModel();
16771
- object.GetWindow().refreshContents();
17134
+ Object3D inst = new Object3D("inst" + paintcount++);
17135
+
17136
+ inst.CreateMaterial(); // use a void leaf to select instances
17137
+
17138
+ inst.add(paintobj); // link
17139
+
17140
+ object.GetWindow().SnapObject(inst);
17141
+
17142
+ Object3D folder = paintFolder; // GetFolder();
17143
+
17144
+ folder.add(inst);
17145
+
17146
+ object.GetWindow().ResetModel();
17147
+ object.GetWindow().refreshContents();
17148
+ }
1677217149 }
1677317150 else
1677417151 paintcount = 0;