Normand Briere
2019-07-29 c6c3f0948bd31603547ef8ce47a7784a9a4d55c2
CameraPane.java
....@@ -18,7 +18,10 @@
1818 import javax.imageio.ImageIO;
1919 import javax.imageio.ImageWriteParam;
2020 import javax.imageio.ImageWriter;
21
+import javax.imageio.ImageReadParam;
22
+import javax.imageio.ImageReader;
2123 import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
24
+import javax.imageio.stream.ImageInputStream;
2225 import javax.imageio.stream.ImageOutputStream;
2326 import javax.imageio.ImageWriteParam;
2427
....@@ -30,6 +33,7 @@
3033 import java.nio.*;
3134
3235 import gleem.linalg.Mat4f;
36
+import javax.imageio.ImageTypeSpecifier;
3337
3438 class CameraPane extends GLCanvas implements iCameraPane, Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener
3539 {
....@@ -44,6 +48,39 @@
4448 static boolean ABORTED = false;
4549
4650 static int STEP = 1;
51
+
52
+ private static BufferedImage CreateBim(byte[] bytes, int width, int height)
53
+ {
54
+ int[] pixels = new int[bytes.length/3];
55
+ for (int i=pixels.length; --i>=0;)
56
+ {
57
+ int i3 = i*3;
58
+ pixels[i] = 0xFF;
59
+ pixels[i] <<= 8;
60
+ pixels[i] |= bytes[i3+2] & 0xFF;
61
+ pixels[i] <<= 8;
62
+ pixels[i] |= bytes[i3+1] & 0xFF;
63
+ pixels[i] <<= 8;
64
+ pixels[i] |= bytes[i3] & 0xFF;
65
+ }
66
+ /*
67
+ int r=0,g=0,b=0,a=0;
68
+ for (int i=0; i<width; i++)
69
+ for (int j=0; j<height; j++)
70
+ {
71
+ int index = j*width+i;
72
+ int p = pixels[index];
73
+ a = ((p>>24) & 0xFF);
74
+ r = ((p>>16) & 0xFF);
75
+ g = ((p>>8) & 0xFF);
76
+ b = (p & 0xFF);
77
+ pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
78
+ }
79
+ /**/
80
+ BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
81
+ rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
82
+ return rendImage;
83
+ }
4784
4885 /*static*/ private boolean CULLFACE = false; // true;
4986 /*static*/ boolean NEAREST = false; // true;
....@@ -60,7 +97,7 @@
6097 //boolean REDUCETEXTURE = true;
6198 boolean CACHETEXTURE = true;
6299 boolean CLEANCACHE = false; // true;
63
- boolean MIPMAP = false; // true;
100
+ boolean MIPMAP = false; // true; // never works...
64101 boolean COMPRESSTEXTURE = false;
65102 boolean KOMPACTTEXTURE = false; // true;
66103 boolean RESIZETEXTURE = false;
....@@ -150,6 +187,18 @@
150187 }
151188
152189 private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
190
+
191
+ public void LoadSkybox(String name, String ext, boolean mipmap) throws GLException
192
+ {
193
+ try
194
+ {
195
+ cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
196
+ } catch (IOException e)
197
+ {
198
+ System.out.println("NAME = " + name);
199
+ e.printStackTrace(); // throw new RuntimeException(e);
200
+ }
201
+ }
153202
154203 void SetAsGLRenderer(boolean b)
155204 {
....@@ -169,7 +218,8 @@
169218
170219 SetCamera(cam);
171220
172
- SetLight(new Camera(new cVector(10, 10, -20)));
221
+ // Warning: not used.
222
+ SetLight(new Camera(new cVector(15, 10, -20)));
173223
174224 object = o;
175225
....@@ -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 {
....@@ -2065,7 +2115,7 @@
20652115 //System.err.println("Oeil on");
20662116 OEIL = true;
20672117 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2068
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2118
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
20692119 //pingthread.StepToTarget(true);
20702120 }
20712121
....@@ -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)
....@@ -11028,9 +11269,9 @@
1102811269
1102911270 gl.glMatrixMode(GL.GL_MODELVIEW);
1103011271
11031
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11032
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
11033
-//gl.glEnable(gl.GL_MULTISAMPLE);
11272
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11273
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11274
+gl.glEnable(gl.GL_MULTISAMPLE);
1103411275 } else
1103511276 {
1103611277 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -11041,7 +11282,7 @@
1104111282 //System.out.println("BLENDING ON");
1104211283 gl.glEnable(GL.GL_BLEND);
1104311284 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
11044
-
11285
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1104511286 gl.glMatrixMode(gl.GL_PROJECTION);
1104611287 gl.glLoadIdentity();
1104711288
....@@ -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)
....@@ -11527,7 +11765,7 @@
1152711765 if ((TRACK || SHADOWTRACK) || zoomonce)
1152811766 {
1152911767 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11530
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11768
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1153111769 pingthread.StepToTarget(true); // true);
1153211770 // zoomonce = false;
1153311771 }
....@@ -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,10 +13035,10 @@
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;" +
12724
- "SLT temp.z, temp.y, -one2048th.x;" +
13041
+ "SLT temp.z, temp.y, -c256i.x;" +
1272513042 "SUB temp.y, one.x, temp.z;" +
1272613043 "MUL temp.x, temp.x, temp.y;" +
1272713044 "KIL temp.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 "";
....@@ -13375,9 +13693,10 @@
1337513693 "DP3 " + dest + ".z," + "normals," + "eye;" +
1337613694 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1337713695 //"MOV " + dest + ".w," + "normal.z;" +
13378
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
13379
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13380
- //"MOV " + dest + ".z," + "params2.w;" +
13696
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13697
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13698
+
13699
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1338113700 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1338213701 "RCP " + dest + ".w," + dest + ".w;" +
1338313702 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13942,7 +14261,7 @@
1394214261
1394314262 // fev 2014???
1394414263 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13945
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14264
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1394614265 pingthread.StepToTarget(true); // true);
1394714266 }
1394814267 // if (!LIVE)
....@@ -14007,14 +14326,15 @@
1400714326 drag = false;
1400814327 //System.out.println("Mouse DOWN");
1400914328 editObj = false;
14010
- ClickInfo info = new ClickInfo();
14011
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14012
- info.pane = this;
14013
- info.camera = renderCamera;
14014
- info.x = x;
14015
- info.y = y;
14016
- info.modifiers = modifiersex;
14017
- 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);
1401814338 if (!editObj)
1401914339 {
1402014340 hasMarquee = true;
....@@ -14296,12 +14616,12 @@
1429614616 void GoDown(int mod)
1429714617 {
1429814618 MODIFIERS |= COMMAND;
14299
- /*
14619
+ /**/
1430014620 if((mod&SHIFT) == SHIFT)
1430114621 manipCamera.RotatePosition(0, -speed);
1430214622 else
14303
- manipCamera.BackForth(0, -speed*delta, getWidth());
14304
- */
14623
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14624
+ /**/
1430514625 if ((mod & SHIFT) == SHIFT)
1430614626 {
1430714627 mouseMode = mouseMode; // VR??
....@@ -14317,12 +14637,12 @@
1431714637 void GoUp(int mod)
1431814638 {
1431914639 MODIFIERS |= COMMAND;
14320
- /*
14640
+ /**/
1432114641 if((mod&SHIFT) == SHIFT)
1432214642 manipCamera.RotatePosition(0, speed);
1432314643 else
14324
- manipCamera.BackForth(0, speed*delta, getWidth());
14325
- */
14644
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14645
+ /**/
1432614646 if ((mod & SHIFT) == SHIFT)
1432714647 {
1432814648 mouseMode = mouseMode;
....@@ -14338,12 +14658,12 @@
1433814658 void GoLeft(int mod)
1433914659 {
1434014660 MODIFIERS |= COMMAND;
14341
- /*
14661
+ /**/
1434214662 if((mod&SHIFT) == SHIFT)
14343
- manipCamera.RotatePosition(speed, 0);
14344
- else
1434514663 manipCamera.Translate(speed*delta, 0, getWidth());
14346
- */
14664
+ else
14665
+ manipCamera.RotatePosition(speed, 0);
14666
+ /**/
1434714667 if ((mod & SHIFT) == SHIFT)
1434814668 {
1434914669 mouseMode = mouseMode;
....@@ -14359,12 +14679,12 @@
1435914679 void GoRight(int mod)
1436014680 {
1436114681 MODIFIERS |= COMMAND;
14362
- /*
14682
+ /**/
1436314683 if((mod&SHIFT) == SHIFT)
14364
- manipCamera.RotatePosition(-speed, 0);
14365
- else
1436614684 manipCamera.Translate(-speed*delta, 0, getWidth());
14367
- */
14685
+ else
14686
+ manipCamera.RotatePosition(-speed, 0);
14687
+ /**/
1436814688 if ((mod & SHIFT) == SHIFT)
1436914689 {
1437014690 mouseMode = mouseMode;
....@@ -14414,15 +14734,16 @@
1441414734 if (editObj)
1441514735 {
1441614736 drag = true;
14417
- ClickInfo info = new ClickInfo();
14418
- info.bounds.setBounds(0, 0,
14737
+ //ClickInfo info = new ClickInfo();
14738
+ object.clickInfo.bounds.setBounds(0, 0,
1441914739 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14420
- info.pane = this;
14421
- info.camera = renderCamera;
14422
- info.x = x;
14423
- info.y = y;
14424
- object.GetWindow().copy
14425
- .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);
1442614747 } else
1442714748 {
1442814749 if (x < startX)
....@@ -14571,24 +14892,27 @@
1457114892 }
1457214893 }
1457314894
14895
+// ClickInfo clickInfo = new ClickInfo();
14896
+
1457414897 public void mouseMoved(MouseEvent e)
1457514898 {
1457614899 //System.out.println("mouseMoved: " + e);
1457714900 if (isRenderer)
1457814901 return;
1457914902
14580
- ClickInfo ci = new ClickInfo();
14581
- ci.x = e.getX();
14582
- ci.y = e.getY();
14583
- ci.modifiers = e.getModifiersEx();
14584
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14585
- ci.pane = this;
14586
- 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;
1458714910 if (!isRenderer)
1458814911 {
1458914912 //ObjEditor editWindow = object.editWindow;
1459014913 //Object3D copy = editWindow.copy;
14591
- if (object.doEditClick(ci, 0))
14914
+ if (object.doEditClick(//clickInfo,
14915
+ 0))
1459214916 {
1459314917 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1459414918 } else
....@@ -14603,7 +14927,8 @@
1460314927 Globals.MOUSEDRAGGED = false;
1460414928
1460514929 movingcamera = false;
14606
- X = Y = 0;
14930
+ X = 0; // getBounds().width/2;
14931
+ Y = 0; // getBounds().height/2;
1460714932 //System.out.println("mouseReleased: " + e);
1460814933 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1460914934 }
....@@ -14859,7 +15184,8 @@
1485915184 // break;
1486015185 case 'T':
1486115186 CACHETEXTURE ^= true;
14862
- textures.clear();
15187
+ texturepigment.clear();
15188
+ texturebump.clear();
1486315189 // repaint();
1486415190 break;
1486515191 case 'Y':
....@@ -14944,7 +15270,9 @@
1494415270 case 'E' : COMPACT ^= true;
1494515271 repaint();
1494615272 break;
14947
- case 'W' : DEBUGHSB ^= true;
15273
+ case 'W' : // Wide Window (fullscreen)
15274
+ //DEBUGHSB ^= true;
15275
+ ObjEditor.theFrame.ToggleFullScreen();
1494815276 repaint();
1494915277 break;
1495015278 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14970,13 +15298,7 @@
1497015298 repaint();
1497115299 break;
1497215300 case 'l':
14973
- lightMode ^= true;
14974
- Globals.lighttouched = true;
14975
- manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
14976
- targetLookAt.set(manipCamera.lookAt);
14977
- repaint();
14978
- break;
14979
- case 'L':
15301
+ //case 'L':
1498015302 if (lightMode)
1498115303 {
1498215304 lightMode = false;
....@@ -15046,14 +15368,18 @@
1504615368 case '3':
1504715369 case '4':
1504815370 case '5':
15049
- newenvy = Character.getNumericValue(key);
15050
- repaint();
15051
- break;
1505215371 case '6':
1505315372 case '7':
1505415373 case '8':
1505515374 case '9':
15056
- 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
+ }
1505715383 repaint();
1505815384 break;
1505915385 case '!':
....@@ -15119,11 +15445,14 @@
1511915445 case '_':
1512015446 kompactbit = 5;
1512115447 break;
15122
- case '+':
15123
- kompactbit = 6;
15124
- break;
15448
+// case '+':
15449
+// kompactbit = 6;
15450
+// break;
1512515451 case ' ':
15126
- ObjEditor.theFrame.ToggleFullScreen();
15452
+ lightMode ^= true;
15453
+ Globals.lighttouched = true;
15454
+ manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
15455
+ targetLookAt.set(manipCamera.lookAt);
1512715456 repaint();
1512815457 break;
1512915458 //case '`' :
....@@ -15170,8 +15499,9 @@
1517015499 case DELETE:
1517115500 ClearSelection();
1517215501 break;
15173
- /*
1517415502 case '+':
15503
+
15504
+ /*
1517515505 //fontsize += 1;
1517615506 bbzoom *= 2;
1517715507 repaint();
....@@ -15188,17 +15518,17 @@
1518815518 case '=':
1518915519 IncDepth();
1519015520 //fontsize += 1;
15191
- object.editWindow.refreshContents(true);
15521
+ object.GetWindow().refreshContents(true);
1519215522 maskbit = 6;
1519315523 break;
1519415524 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1519515525 DecDepth();
1519615526 maskbit = 5;
1519715527 //if(fontsize > 1) fontsize -= 1;
15198
- if (object.editWindow == null)
15199
- new Exception().printStackTrace();
15200
- else
15201
- object.editWindow.refreshContents(true);
15528
+// if (object.editWindow == null)
15529
+// new Exception().printStackTrace();
15530
+// else
15531
+ object.GetWindow().refreshContents(true);
1520215532 break;
1520315533 case '{':
1520415534 manipCamera.shaper_fovy /= 1.1;
....@@ -15422,7 +15752,7 @@
1542215752 }
1542315753 */
1542415754
15425
- object.editWindow.EditSelection(false);
15755
+ object.GetWindow().EditSelection(false);
1542615756 }
1542715757
1542815758 void SelectParent()
....@@ -15439,10 +15769,10 @@
1543915769 {
1544015770 //selectees.remove(i);
1544115771 System.out.println("select parent of " + elem);
15442
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15772
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1544315773 } else
1544415774 {
15445
- group.editWindow.Select(elem.GetTreePath(), first, true);
15775
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1544615776 }
1544715777
1544815778 first = false;
....@@ -15484,12 +15814,12 @@
1548415814 for (int j = 0; j < group.children.size(); j++)
1548515815 {
1548615816 elem = (Object3D) group.children.elementAt(j);
15487
- object.editWindow.Select(elem.GetTreePath(), first, true);
15817
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1548815818 first = false;
1548915819 }
1549015820 } else
1549115821 {
15492
- object.editWindow.Select(elem.GetTreePath(), first, true);
15822
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1549315823 }
1549415824
1549515825 first = false;
....@@ -15500,21 +15830,21 @@
1550015830 {
1550115831 //Composite group = (Composite) object;
1550215832 Object3D group = object;
15503
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15833
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1550415834 }
1550515835
1550615836 void ResetTransform(int mask)
1550715837 {
1550815838 //Composite group = (Composite) object;
1550915839 Object3D group = object;
15510
- group.editWindow.ResetTransform(mask);
15840
+ group.GetWindow().ResetTransform(mask);
1551115841 }
1551215842
1551315843 void FlipTransform()
1551415844 {
1551515845 //Composite group = (Composite) object;
1551615846 Object3D group = object;
15517
- group.editWindow.FlipTransform();
15847
+ group.GetWindow().FlipTransform();
1551815848 // group.editWindow.ReduceMesh(true);
1551915849 }
1552015850
....@@ -15522,7 +15852,7 @@
1552215852 {
1552315853 //Composite group = (Composite) object;
1552415854 Object3D group = object;
15525
- group.editWindow.PrintMemory();
15855
+ group.GetWindow().PrintMemory();
1552615856 // group.editWindow.ReduceMesh(true);
1552715857 }
1552815858
....@@ -15530,7 +15860,7 @@
1553015860 {
1553115861 //Composite group = (Composite) object;
1553215862 Object3D group = object;
15533
- group.editWindow.ResetCentroid();
15863
+ group.GetWindow().ResetCentroid();
1553415864 }
1553515865
1553615866 void IncDepth()
....@@ -15612,8 +15942,6 @@
1561215942
1561315943 int width = getBounds().width;
1561415944 int height = getBounds().height;
15615
- ClickInfo info = new ClickInfo();
15616
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1561715945 //Image img = CreateImage(width, height);
1561815946 //System.out.println("width = " + width + "; height = " + height + "\n");
1561915947
....@@ -15690,48 +16018,77 @@
1569016018 }
1569116019 if (object != null && !hasMarquee)
1569216020 {
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
+
1569316027 if (isRenderer)
1569416028 {
15695
- info.flags++;
16029
+ object.clickInfo.flags++;
1569616030 double frameAspect = (double) width / (double) height;
1569716031 if (frameAspect > renderCamera.aspect)
1569816032 {
1569916033 int desired = (int) ((double) height * renderCamera.aspect);
15700
- info.bounds.width -= width - desired;
15701
- info.bounds.x += (width - desired) / 2;
16034
+ object.clickInfo.bounds.width -= width - desired;
16035
+ object.clickInfo.bounds.x += (width - desired) / 2;
1570216036 } else
1570316037 {
1570416038 int desired = (int) ((double) width / renderCamera.aspect);
15705
- info.bounds.height -= height - desired;
15706
- info.bounds.y += (height - desired) / 2;
16039
+ object.clickInfo.bounds.height -= height - desired;
16040
+ object.clickInfo.bounds.y += (height - desired) / 2;
1570716041 }
1570816042 }
15709
- info.g = gr;
15710
- info.camera = renderCamera;
16043
+
16044
+ object.clickInfo.g = gr;
16045
+ object.clickInfo.camera = renderCamera;
1571116046 /*
1571216047 // Memory intensive (brep.verticescopy)
1571316048 if (!(object instanceof Composite))
1571416049 object.draw(info, 0, false); // SLOW :
1571516050 */
15716
- if (!isRenderer)
16051
+ if (!isRenderer) // && drag)
1571716052 {
15718
- object.drawEditHandles(info, 0);
15719
-
15720
- if (drag && (X != 0 || Y != 0) && object.selection.Size() > 0)
16053
+ Grafreed.Assert(object != null);
16054
+ Grafreed.Assert(object.selection != null);
16055
+ if (object.selection.Size() > 0)
1572116056 {
15722
- switch (object.selection.get(0).hitSomething)
16057
+ int hitSomething = object.selection.get(0).hitSomething;
16058
+
16059
+ object.clickInfo.DX = 0;
16060
+ object.clickInfo.DY = 0;
16061
+ object.clickInfo.W = 1;
16062
+ if (hitSomething == Object3D.hitCenter)
1572316063 {
15724
- case Object3D.hitCenter: gr.setColor(Color.pink);
15725
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15726
- break;
15727
- case Object3D.hitRotate: gr.setColor(Color.yellow);
15728
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15729
- break;
15730
- case Object3D.hitScale: gr.setColor(Color.cyan);
15731
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15732
- break;
16064
+ info.DX = X;
16065
+ if (X != 0)
16066
+ info.DX -= info.bounds.width/2;
16067
+
16068
+ info.DY = Y;
16069
+ if (Y != 0)
16070
+ info.DY -= info.bounds.height/2;
1573316071 }
15734
-
16072
+
16073
+ object.drawEditHandles(//info,
16074
+ 0);
16075
+
16076
+ if (drag && (X != 0 || Y != 0))
16077
+ {
16078
+ switch (hitSomething)
16079
+ {
16080
+ case Object3D.hitCenter: gr.setColor(Color.pink);
16081
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16082
+ break;
16083
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16084
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16085
+ break;
16086
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16087
+ gr.drawLine(X, Y, 0, 0);
16088
+ break;
16089
+ }
16090
+
16091
+ }
1573516092 }
1573616093 }
1573716094 }
....@@ -16213,6 +16570,8 @@
1621316570 private /*static*/ boolean firstime;
1621416571 private /*static*/ cVector newView = new cVector();
1621516572 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16573
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16574
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1621616575 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1621716576 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1621816577 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16225,16 +16584,49 @@
1622516584 {
1622616585 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1622716586
16587
+ int usedsuf = 0;
16588
+
1622816589 for (int i = 0; i < suffixes.length; i++)
1622916590 {
16230
- String resourceName = basename + suffixes[i] + "." + suffix;
16231
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16232
- mipmapped,
16233
- FileUtil.getFileSuffix(resourceName));
16234
- if (data == null)
16591
+ String[] suffixe = suffixes;
16592
+ String[] fallback = suffixes2;
16593
+ String[] fallfallback = suffixes3;
16594
+
16595
+ for (int c=usedsuf; --c>=0;)
1623516596 {
16236
- throw new IOException("Unable to load texture " + resourceName);
16597
+// String[] temp = suffixe;
16598
+// suffixe = fallback;
16599
+// fallback = fallfallback;
16600
+// fallfallback = temp;
1623716601 }
16602
+
16603
+ String resourceName = basename + suffixe[i] + "." + suffix;
16604
+ TextureData data;
16605
+
16606
+ try
16607
+ {
16608
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16609
+ mipmapped,
16610
+ FileUtil.getFileSuffix(resourceName));
16611
+ }
16612
+ catch (Exception e)
16613
+ {
16614
+ try
16615
+ {
16616
+ resourceName = basename + fallback[i] + "." + suffix;
16617
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16618
+ mipmapped,
16619
+ FileUtil.getFileSuffix(resourceName));
16620
+ }
16621
+ catch (Exception e2)
16622
+ {
16623
+ resourceName = basename + fallfallback[i] + "." + suffix;
16624
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16625
+ mipmapped,
16626
+ FileUtil.getFileSuffix(resourceName));
16627
+ }
16628
+ }
16629
+
1623816630 //System.out.println("Target = " + targets[i]);
1623916631 cubemap.updateImage(data, targets[i]);
1624016632 }
....@@ -16245,7 +16637,9 @@
1624516637
1624616638 float BGcolor = 0.5f;
1624716639
16248
- private void DrawSkyBox(GL gl)
16640
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16641
+
16642
+ private void DrawSkyBox(GL gl, float ratio)
1624916643 {
1625016644 if (envyoff || cubemap == null)
1625116645 {
....@@ -16262,7 +16656,17 @@
1626216656 // Compensates for ExaminerViewer's modification of modelview matrix
1626316657 gl.glMatrixMode(GL.GL_MODELVIEW);
1626416658 gl.glLoadIdentity();
16659
+ gl.glScalef(1,ratio,1);
1626516660
16661
+ colorV[0] = 2;
16662
+ colorV[1] = 2;
16663
+ colorV[2] = 2;
16664
+ colorV[3] = 1;
16665
+ gl.glDisable(gl.GL_COLOR_MATERIAL);
16666
+ gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16667
+
16668
+ gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16669
+
1626616670 //gl.glActiveTexture(GL.GL_TEXTURE1);
1626716671 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1626816672
....@@ -16275,7 +16679,7 @@
1627516679 // GL_NORMAL_MAP texgen mode. Temporarily enabling lighting
1627616680 // causes the normals to be sent down. Thanks to Ken Dyke.
1627716681 //gl.glEnable(GL.GL_LIGHTING);
16278
- gl.glDisable(GL.GL_LIGHTING);
16682
+ gl.glEnable(GL.GL_LIGHTING);
1627916683
1628016684 gl.glTexGeni(GL.GL_S, GL.GL_TEXTURE_GEN_MODE, GL.GL_NORMAL_MAP);
1628116685 gl.glTexGeni(GL.GL_T, GL.GL_TEXTURE_GEN_MODE, GL.GL_NORMAL_MAP);
....@@ -16294,6 +16698,7 @@
1629416698 {
1629516699 gl.glScalef(1.0f, -1.0f, 1.0f);
1629616700 }
16701
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1629716702 gl.glMultMatrixd(viewrot_1, 0);
1629816703 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1629916704 //viewer.updateInverseRotation(gl);
....@@ -16529,6 +16934,14 @@
1652916934 }
1653016935 }
1653116936
16937
+ private Object3D GetFolder()
16938
+ {
16939
+ Object3D folder = object.GetWindow().copy;
16940
+ if (object.GetWindow().copy.selection.Size() > 0)
16941
+ folder = object.GetWindow().copy.selection.elementAt(0);
16942
+ return folder;
16943
+ }
16944
+
1653216945 class SelectBuffer implements GLEventListener
1653316946 {
1653416947
....@@ -16544,7 +16957,7 @@
1654416957 //new Exception().printStackTrace();
1654516958 System.out.println("select buffer init");
1654616959 // Use debug pipeline
16547
- drawable.setGL(new DebugGL(drawable.getGL()));
16960
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1654816961
1654916962 GL gl = drawable.getGL();
1655016963
....@@ -16608,6 +17021,17 @@
1660817021
1660917022 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1661017023
17024
+ if (PAINTMODE)
17025
+ {
17026
+ if (object.GetWindow().copy.selection.Size() > 0)
17027
+ {
17028
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17029
+
17030
+ // Make what you paint not selectable.
17031
+ paintobj.ResetSelectable();
17032
+ }
17033
+ }
17034
+
1661117035 //int tmp = selection_view;
1661217036 //selection_view = -1;
1661317037 int temp = DrawMode();
....@@ -16619,6 +17043,17 @@
1661917043 // temp = DEFAULT; // patch for selection debug
1662017044 Globals.drawMode = temp; // WARNING
1662117045
17046
+ if (PAINTMODE)
17047
+ {
17048
+ if (object.GetWindow().copy.selection.Size() > 0)
17049
+ {
17050
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17051
+
17052
+ // Revert.
17053
+ paintobj.RestoreSelectable();
17054
+ }
17055
+ }
17056
+
1662217057 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1662317058
1662417059 // trying different ways of getting the depth info over
....@@ -16722,29 +17157,31 @@
1672217157 }
1672317158
1672417159 if (!movingcamera && !PAINTMODE)
16725
- object.editWindow.ScreenFitPoint(); // fev 2014
17160
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1672617161
16727
- if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17162
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1672817163 {
16729
- Object3D paintobj = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17164
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1673017165
16731
- Object3D group = new Object3D("inst" + paintcount++);
17166
+ if (object.GetWindow().copy.selection.Size() > 0)
17167
+ {
17168
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1673217169
16733
- group.CreateMaterial(); // use a void leaf to select instances
16734
-
16735
- group.add(paintobj); // link
16736
-
16737
- object.editWindow.SnapObject(group);
16738
-
16739
- Object3D folder = object.editWindow.copy;
16740
-
16741
- if (object.editWindow.copy.selection.Size() > 0)
16742
- folder = object.editWindow.copy.selection.elementAt(0);
16743
-
16744
- folder.add(group);
16745
-
16746
- object.editWindow.ResetModel();
16747
- object.editWindow.refreshContents();
17170
+ Object3D inst = new Object3D("inst" + paintcount++);
17171
+
17172
+ inst.CreateMaterial(); // use a void leaf to select instances
17173
+
17174
+ inst.add(paintobj); // link
17175
+
17176
+ object.GetWindow().SnapObject(inst);
17177
+
17178
+ Object3D folder = paintFolder; // GetFolder();
17179
+
17180
+ folder.add(inst);
17181
+
17182
+ object.GetWindow().ResetModel();
17183
+ object.GetWindow().refreshContents();
17184
+ }
1674817185 }
1674917186 else
1675017187 paintcount = 0;
....@@ -16783,6 +17220,11 @@
1678317220 //System.out.println("objects[color] = " + objects[color]);
1678417221 //objects[color].Select();
1678517222 indexcount = 0;
17223
+ ObjEditor window = object.GetWindow();
17224
+ if (window != null && deselect)
17225
+ {
17226
+ window.Select(null, deselect, true);
17227
+ }
1678617228 object.Select(color, deselect);
1678717229 }
1678817230