Normand Briere
2019-08-13 c67de8aca04d988179191ccb52461af00125920e
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;
....@@ -73,7 +110,9 @@
73110 //private Mat4f spotlightTransform = new Mat4f();
74111 //private Mat4f spotlightInverseTransform = new Mat4f();
75112 static GLContext glcontext = null;
76
- /*static*/ com.sun.opengl.util.texture.Texture cubemap;
113
+ /*static*/ com.sun.opengl.util.texture.Texture cubemap; // Either custom or rgb
114
+ /*static*/ com.sun.opengl.util.texture.Texture cubemapcustom;
115
+ /*static*/ com.sun.opengl.util.texture.Texture cubemaprgb;
77116 boolean reverseUP = false;
78117 static boolean frozen = false;
79118 boolean enablebackspace = false; // patch for back buffer refresh
....@@ -136,7 +175,7 @@
136175 static boolean doublesided = false; // true; // reversed normals are awful for conformance
137176 boolean anisotropy = true;
138177 boolean softshadow = true; // slower but better false;
139
- boolean opacityhalo = false;
178
+ boolean opacityhalo = false; // reverse the halo effect (e.g. glass)
140179
141180 boolean macromode = false;
142181
....@@ -150,6 +189,19 @@
150189 }
151190
152191 private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
192
+
193
+ public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException
194
+ {
195
+ try
196
+ {
197
+ return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
198
+ } catch (IOException e)
199
+ {
200
+ System.out.println("NAME = " + name);
201
+ e.printStackTrace(); // throw new RuntimeException(e);
202
+ return null;
203
+ }
204
+ }
153205
154206 void SetAsGLRenderer(boolean b)
155207 {
....@@ -169,7 +221,8 @@
169221
170222 SetCamera(cam);
171223
172
- SetLight(new Camera(new cVector(10, 10, -20)));
224
+ // Warning: not used.
225
+ SetLight(new Camera(new cVector(15, 10, -20)));
173226
174227 object = o;
175228
....@@ -1447,6 +1500,8 @@
14471500 gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
14481501 }
14491502
1503
+ float[] colorV = new float[4];
1504
+
14501505 void SetColor(Object3D obj, Vertex p0)
14511506 {
14521507 CameraPane display = this;
....@@ -1514,8 +1569,6 @@
15141569 {
15151570 return;
15161571 }
1517
-
1518
- float[] colorV = new float[3];
15191572
15201573 if (false) // marked)
15211574 {
....@@ -2065,7 +2118,7 @@
20652118 //System.err.println("Oeil on");
20662119 OEIL = true;
20672120 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2068
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2121
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
20692122 //pingthread.StepToTarget(true);
20702123 }
20712124
....@@ -2298,10 +2351,17 @@
22982351 HANDLES ^= true;
22992352 }
23002353
2354
+ Object3D paintFolder;
2355
+
23012356 void TogglePaint()
23022357 {
23032358 PAINTMODE ^= true;
23042359 paintcount = 0;
2360
+
2361
+ if (PAINTMODE)
2362
+ {
2363
+ paintFolder = GetFolder();
2364
+ }
23052365 }
23062366
23072367 void SwapCamera(int a, int b)
....@@ -2398,6 +2458,21 @@
23982458 return currentGL;
23992459 }
24002460
2461
+ static private BufferedImage CreateBim(TextureData texturedata)
2462
+ {
2463
+ Grafreed.Assert(texturedata != null);
2464
+
2465
+ int width = texturedata.getWidth();
2466
+ int height = texturedata.getHeight();
2467
+
2468
+ Buffer buffer = texturedata.getBuffer();
2469
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2470
+
2471
+ byte[] bytes = bytebuf.array();
2472
+
2473
+ return CreateBim(bytes, width, height);
2474
+ }
2475
+
24012476 /**/
24022477 class CacheTexture
24032478 {
....@@ -2406,28 +2481,31 @@
24062481
24072482 int resolution;
24082483
2409
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2484
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
24102485 {
2411
- texture = tex;
2486
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2487
+ texturedata = texdata;
24122488 resolution = res;
24132489 }
24142490 }
24152491 /**/
24162492
24172493 // 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>();
2494
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2495
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2496
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2497
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2498
+
24212499 int pigmentdepth = 0;
24222500 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
24232501 int bumpdepth = 0;
24242502 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
24252503 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
24262504 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2427
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2505
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
24282506 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
24292507
2430
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2508
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
24312509 {
24322510 TextureData texturedata = null;
24332511
....@@ -2446,13 +2524,34 @@
24462524 if (bump)
24472525 texturedata = ConvertBump(texturedata, false);
24482526
2449
- com.sun.opengl.util.texture.Texture texture =
2450
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2527
+// com.sun.opengl.util.texture.Texture texture =
2528
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
24512529
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);
2530
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2531
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
24542532
2455
- return texture;
2533
+ return texturedata;
2534
+ }
2535
+
2536
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2537
+ {
2538
+ TextureData texturedata = null;
2539
+
2540
+ try
2541
+ {
2542
+ texturedata =
2543
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2544
+ bim,
2545
+ true);
2546
+ } catch (Exception e)
2547
+ {
2548
+ throw new javax.media.opengl.GLException(e);
2549
+ }
2550
+
2551
+ if (bump)
2552
+ texturedata = ConvertBump(texturedata, false);
2553
+
2554
+ return texturedata;
24562555 }
24572556
24582557 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3525,6 +3624,8 @@
35253624
35263625 System.out.println("LOADING TEXTURE : " + name);
35273626
3627
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3628
+
35283629 //
35293630 if (false) // compressbit > 0)
35303631 {
....@@ -7923,7 +8024,7 @@
79238024 String pigment = Object3D.GetPigment(tex);
79248025 String bump = Object3D.GetBump(tex);
79258026
7926
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8027
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79278028 {
79288029 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79298030 // System.out.println("; bump = " + bump);
....@@ -7938,8 +8039,8 @@
79388039 pigment = null;
79398040 }
79408041
7941
- ReleaseTexture(bump, true);
7942
- ReleaseTexture(pigment, false);
8042
+ ReleaseTexture(tex, true);
8043
+ ReleaseTexture(tex, false);
79438044 }
79448045
79458046 public void ReleasePigmentTexture(cTexture tex) // INTERFACE
....@@ -7957,7 +8058,7 @@
79578058
79588059 String pigment = Object3D.GetPigment(tex);
79598060
7960
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8061
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79618062 {
79628063 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79638064 // System.out.println("; bump = " + bump);
....@@ -7968,7 +8069,7 @@
79688069 pigment = null;
79698070 }
79708071
7971
- ReleaseTexture(pigment, false);
8072
+ ReleaseTexture(tex, false);
79728073 }
79738074
79748075 public void ReleaseBumpTexture(cTexture tex) // INTERFACE
....@@ -7986,7 +8087,7 @@
79868087
79878088 String bump = Object3D.GetBump(tex);
79888089
7989
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8090
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79908091 {
79918092 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79928093 // System.out.println("; bump = " + bump);
....@@ -7997,10 +8098,10 @@
79978098 bump = null;
79988099 }
79998100
8000
- ReleaseTexture(bump, true);
8101
+ ReleaseTexture(tex, true);
80018102 }
80028103
8003
- void ReleaseTexture(String tex, boolean bump)
8104
+ void ReleaseTexture(cTexture tex, boolean bump)
80048105 {
80058106 if (// DrawMode() != 0 || /*tex == null ||*/
80068107 ambientOcclusion ) // || !textureon)
....@@ -8011,7 +8112,7 @@
80118112 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
80128113
80138114 if (tex != null)
8014
- texture = textures.get(tex);
8115
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
80158116
80168117 // //assert( texture != null );
80178118 // if (texture == null)
....@@ -8105,47 +8206,50 @@
81058206
81068207 /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
81078208 {
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
- }
8209
+// if (// DrawMode() != 0 || /*tex == null ||*/
8210
+// ambientOcclusion ) // || !textureon)
8211
+// {
8212
+// return; // false;
8213
+// }
8214
+//
8215
+// if (tex == null)
8216
+// {
8217
+// BindTexture(null,false,resolution);
8218
+// BindTexture(null,true,resolution);
8219
+// return;
8220
+// }
8221
+//
8222
+// String pigment = Object3D.GetPigment(tex);
8223
+// String bump = Object3D.GetBump(tex);
8224
+//
8225
+// usedtextures.add(pigment);
8226
+// usedtextures.add(bump);
8227
+//
8228
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8229
+// {
8230
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8231
+// // System.out.println("; bump = " + bump);
8232
+// }
8233
+//
8234
+// if (bump.equals(""))
8235
+// {
8236
+// bump = null;
8237
+// }
8238
+// if (pigment.equals(""))
8239
+// {
8240
+// pigment = null;
8241
+// }
8242
+//
8243
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8244
+// BindTexture(pigment, false, resolution);
8245
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8246
+// BindTexture(bump, true, resolution);
8247
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8248
+//
8249
+// return; // true;
81208250
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;
8251
+ BindPigmentTexture(tex, resolution);
8252
+ BindBumpTexture(tex, resolution);
81498253 }
81508254
81518255 /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8164,9 +8268,9 @@
81648268
81658269 String pigment = Object3D.GetPigment(tex);
81668270
8167
- usedtextures.put(pigment, pigment);
8271
+ usedtextures.add(tex);
81688272
8169
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8273
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
81708274 {
81718275 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
81728276 // System.out.println("; bump = " + bump);
....@@ -8178,7 +8282,7 @@
81788282 }
81798283
81808284 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8181
- BindTexture(pigment, false, resolution);
8285
+ BindTexture(tex, false, resolution);
81828286 }
81838287
81848288 /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8197,9 +8301,9 @@
81978301
81988302 String bump = Object3D.GetBump(tex);
81998303
8200
- usedtextures.put(bump, bump);
8304
+ usedtextures.add(tex);
82018305
8202
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8306
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
82038307 {
82048308 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
82058309 // System.out.println("; bump = " + bump);
....@@ -8211,7 +8315,7 @@
82118315 }
82128316
82138317 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8214
- BindTexture(bump, true, resolution);
8318
+ BindTexture(tex, true, resolution);
82158319 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
82168320 }
82178321
....@@ -8235,13 +8339,19 @@
82358339 return fileExists;
82368340 }
82378341
8238
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception
8342
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
82398343 {
8240
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8344
+ CacheTexture texturecache = null;
82418345
82428346 if (tex != null)
82438347 {
8244
- String texname = tex;
8348
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8349
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
8350
+
8351
+ if (texname.equals("") && texdata == null)
8352
+ {
8353
+ return null;
8354
+ }
82458355
82468356 String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
82478357
....@@ -8251,19 +8361,46 @@
82518361 // else
82528362 // if (!texname.startsWith("/"))
82538363 // texname = "/Users/nbriere/Textures/" + texname;
8254
- if (!FileExists(tex))
8364
+ if (!FileExists(texname) && !texname.startsWith("@"))
82558365 {
82568366 texname = fallbackTextureName;
82578367 }
82588368
82598369 if (CACHETEXTURE)
8260
- texture = textures.get(texname); // TEXTURE CACHE
8261
-
8262
- TextureData texturedata = null;
8263
-
8264
- if (texture == null || texture.resolution < resolution)
82658370 {
8266
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8371
+ if (texdata == null)
8372
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8373
+ else
8374
+ texturecache = bimtextures.get(texdata);
8375
+ }
8376
+
8377
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8378
+ {
8379
+ TextureData texturedata = null;
8380
+
8381
+ if (texdata != null && textureon)
8382
+ {
8383
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8384
+
8385
+ try
8386
+ {
8387
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8388
+ }
8389
+ catch (Exception e)
8390
+ {
8391
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8392
+ }
8393
+
8394
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8395
+ bimtextures.put(texdata, texturecache);
8396
+
8397
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8398
+
8399
+ //Object bim2 = CreateBim(texturecache.texturedata);
8400
+ //bim2 = bim;
8401
+ }
8402
+ else
8403
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
82678404 {
82688405 assert(!bump);
82698406 // if (bump)
....@@ -8274,19 +8411,23 @@
82748411 // }
82758412 // else
82768413 // {
8277
- texture = textures.get(tex);
8278
- if (texture == null)
8414
+ // texturecache = textures.get(texname); // suspicious
8415
+ if (texturecache == null)
82798416 {
8280
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8417
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
82818418 }
8419
+ else
8420
+ new Exception().printStackTrace();
82828421 // }
82838422 } else
8284
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8423
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
82858424 {
82868425 assert(bump);
8287
- texture = textures.get(tex);
8288
- if (texture == null)
8289
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8426
+ // texturecache = textures.get(texname); // suspicious
8427
+ if (texturecache == null)
8428
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8429
+ else
8430
+ new Exception().printStackTrace();
82908431 } else
82918432 {
82928433 //if (tex.equals("IMMORTAL"))
....@@ -8294,11 +8435,22 @@
82948435 // texture = GetResourceTexture("default.png");
82958436 //} else
82968437 //{
8297
- if (tex.equals("WHITE_NOISE"))
8438
+ if (texname.endsWith("WHITE_NOISE"))
82988439 {
8299
- texture = textures.get(tex);
8300
- if (texture == null)
8301
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8440
+ // texturecache = textures.get(texname); // suspicious
8441
+ if (texturecache == null)
8442
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8443
+ else
8444
+ new Exception().printStackTrace();
8445
+ } else
8446
+ {
8447
+ if (texname.startsWith("@"))
8448
+ {
8449
+ // texturecache = textures.get(texname); // suspicious
8450
+ if (texturecache == null)
8451
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8452
+ else
8453
+ new Exception().printStackTrace();
83028454 } else
83038455 {
83048456 if (textureon)
....@@ -8357,19 +8509,20 @@
83578509 if (texturedata == null)
83588510 throw new Exception();
83598511
8360
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8512
+ texturecache = new CacheTexture(texturedata,resolution);
83618513 //texture = GetTexture(tex, bump);
83628514 }
8515
+ }
83638516 }
83648517 //}
83658518 }
83668519
8367
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8520
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
83688521 {
83698522 //return false;
83708523
83718524 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8372
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8525
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
83738526 {
83748527 // String ext = "_highres";
83758528 // if (REDUCETEXTURE)
....@@ -8386,52 +8539,17 @@
83868539 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
83878540 if (!cachefile.exists())
83888541 {
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))
8542
+ //if (texturedata.getWidth() == texturedata.getHeight())
83988543 {
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);
8544
+ BufferedImage rendImage = CreateBim(texturedata);
8545
+
84298546 ImageWriter writer = null;
84308547 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
84318548 if (iter.hasNext()) {
84328549 writer = (ImageWriter)iter.next();
84338550 }
8434
- float compressionQuality = 0.9f;
8551
+
8552
+ float compressionQuality = 0.85f;
84358553 try
84368554 {
84378555 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8448,18 +8566,20 @@
84488566 }
84498567 }
84508568 }
8451
-
8569
+
8570
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8571
+
84528572 //System.out.println("Texture = " + tex);
8453
- if (textures.containsKey(texname))
8573
+ if (textures.containsKey(tex))
84548574 {
8455
- CacheTexture thetex = textures.get(texname);
8575
+ CacheTexture thetex = textures.get(tex);
84568576 thetex.texture.disable();
84578577 thetex.texture.dispose();
8458
- textures.remove(texname);
8578
+ textures.remove(tex);
84598579 }
84608580
8461
- texture.texturedata = texturedata;
8462
- textures.put(texname, texture);
8581
+ //texture.texturedata = texturedata;
8582
+ textures.put(tex, texturecache);
84638583
84648584 // newtex = true;
84658585 }
....@@ -8475,10 +8595,44 @@
84758595 }
84768596 }
84778597
8478
- return texture;
8598
+ return texturecache;
84798599 }
84808600
8481
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution) throws Exception
8601
+ static void EmbedTextures(cTexture tex)
8602
+ {
8603
+ if (tex.pigmentdata == null)
8604
+ {
8605
+ //String texname = Object3D.GetPigment(tex);
8606
+
8607
+ CacheTexture texturecache = texturepigment.get(tex);
8608
+
8609
+ if (texturecache != null)
8610
+ {
8611
+ tex.pw = texturecache.texturedata.getWidth();
8612
+ tex.ph = texturecache.texturedata.getHeight();
8613
+ tex.pigmentdata = //CompressJPEG(CreateBim
8614
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8615
+ ;
8616
+ //, tex.pw, tex.ph), 0.5f);
8617
+ }
8618
+ }
8619
+
8620
+ if (tex.bumpdata == null)
8621
+ {
8622
+ //String texname = Object3D.GetBump(tex);
8623
+
8624
+ CacheTexture texturecache = texturebump.get(tex);
8625
+
8626
+ if (texturecache != null)
8627
+ {
8628
+ tex.bw = texturecache.texturedata.getWidth();
8629
+ tex.bh = texturecache.texturedata.getHeight();
8630
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8631
+ }
8632
+ }
8633
+ }
8634
+
8635
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
84828636 {
84838637 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
84848638
....@@ -8496,21 +8650,21 @@
84968650 return texture!=null?texture.texture:null;
84978651 }
84988652
8499
- public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution) throws Exception
8653
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
85008654 {
85018655 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
85028656
85038657 return texture!=null?texture.texturedata:null;
85048658 }
85058659
8506
- boolean BindTexture(String tex, boolean bump, int resolution) throws Exception
8660
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
85078661 {
85088662 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
85098663 {
85108664 return false;
85118665 }
85128666
8513
- boolean newtex = false;
8667
+ //boolean newtex = false;
85148668
85158669 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
85168670
....@@ -8542,9 +8696,75 @@
85428696 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
85438697 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
85448698
8545
- return newtex;
8699
+ return true; // Warning: not used.
85468700 }
85478701
8702
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8703
+ {
8704
+ try
8705
+ {
8706
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8707
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8708
+ ImageWriter writer = writers.next();
8709
+
8710
+ ImageWriteParam param = writer.getDefaultWriteParam();
8711
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8712
+ param.setCompressionQuality(quality);
8713
+
8714
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8715
+ writer.setOutput(ios);
8716
+ writer.write(null, new IIOImage(image, null, null), param);
8717
+
8718
+ byte[] data = baos.toByteArray();
8719
+ writer.dispose();
8720
+ return data;
8721
+ }
8722
+ catch (Exception e)
8723
+ {
8724
+ e.printStackTrace();
8725
+ return null;
8726
+ }
8727
+ }
8728
+
8729
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8730
+ {
8731
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8732
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8733
+ ImageReader reader = writers.next();
8734
+
8735
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8736
+
8737
+ ImageReadParam param = reader.getDefaultReadParam();
8738
+ param.setDestination(bim);
8739
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8740
+
8741
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8742
+ reader.setInput(ios);
8743
+ BufferedImage bim2 = reader.read(0, param);
8744
+ reader.dispose();
8745
+
8746
+// WritableRaster raster = bim2.getRaster();
8747
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8748
+// byte[] bytes = data.getData();
8749
+//
8750
+// int[] pixels = new int[bytes.length/3];
8751
+// for (int i=pixels.length; --i>=0;)
8752
+// {
8753
+// int i3 = i*3;
8754
+// pixels[i] = 0xFF;
8755
+// pixels[i] <<= 8;
8756
+// pixels[i] |= bytes[i3+2] & 0xFF;
8757
+// pixels[i] <<= 8;
8758
+// pixels[i] |= bytes[i3+1] & 0xFF;
8759
+// pixels[i] <<= 8;
8760
+// pixels[i] |= bytes[i3] & 0xFF;
8761
+// }
8762
+//
8763
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8764
+
8765
+ return bim;
8766
+ }
8767
+
85488768 ShadowBuffer shadowPBuf;
85498769 AntialiasBuffer antialiasPBuf;
85508770 int MAXSTACK;
....@@ -8561,10 +8781,12 @@
85618781
85628782 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
85638783 MAXSTACK = temp[0];
8564
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8784
+ if (Globals.DEBUG)
8785
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
85658786 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
85668787 MAXSTACK = temp[0];
8567
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8788
+ if (Globals.DEBUG)
8789
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
85688790
85698791 // Use debug pipeline
85708792 //drawable.setGL(new DebugGL(gl)); //
....@@ -8572,7 +8794,8 @@
85728794 gl = drawable.getGL(); //
85738795
85748796 GL gl3 = getGL();
8575
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8797
+ if (Globals.DEBUG)
8798
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
85768799
85778800
85788801 //float pos[] = { 100, 100, 100, 0 };
....@@ -8737,7 +8960,7 @@
87378960
87388961 if (cubemap == null)
87398962 {
8740
- LoadEnvy(5);
8963
+ //LoadEnvy(1);
87418964 }
87428965
87438966 //cubemap.enable();
....@@ -9013,6 +9236,8 @@
90139236
90149237 void LoadEnvy(int which)
90159238 {
9239
+ assert(false);
9240
+
90169241 String name;
90179242 String ext;
90189243
....@@ -9024,37 +9249,58 @@
90249249 cubemap = null;
90259250 return;
90269251 case 1:
9027
- name = "cubemaps/box_";
9028
- ext = "png";
9252
+ name = "cubemaps/rgb/";
9253
+ ext = "jpg";
90299254 reverseUP = false;
90309255 break;
90319256 case 2:
9032
- name = "cubemaps/uffizi_";
9033
- ext = "png";
9034
- break; // reverseUP = true; break;
9257
+ name = "cubemaps/uffizi/";
9258
+ ext = "jpg";
9259
+ reverseUP = false;
9260
+ break;
90359261 case 3:
9036
- name = "cubemaps/CloudyHills_";
9037
- ext = "tga";
9262
+ name = "cubemaps/CloudyHills/";
9263
+ ext = "jpg";
90389264 reverseUP = false;
90399265 break;
90409266 case 4:
9041
- name = "cubemaps/cornell_";
9267
+ name = "cubemaps/cornell/";
90429268 ext = "png";
90439269 reverseUP = false;
90449270 break;
9271
+ case 5:
9272
+ name = "cubemaps/skycube/";
9273
+ ext = "jpg";
9274
+ reverseUP = false;
9275
+ break;
9276
+ case 6:
9277
+ name = "cubemaps/SaintLazarusChurch3/";
9278
+ ext = "jpg";
9279
+ reverseUP = false;
9280
+ break;
9281
+ case 7:
9282
+ name = "cubemaps/Sodermalmsallen/";
9283
+ ext = "jpg";
9284
+ reverseUP = false;
9285
+ break;
9286
+ case 8:
9287
+ name = "cubemaps/Sodermalmsallen2/";
9288
+ ext = "jpg";
9289
+ reverseUP = false;
9290
+ break;
9291
+ case 9:
9292
+ name = "cubemaps/UnionSquare/";
9293
+ ext = "jpg";
9294
+ reverseUP = false;
9295
+ break;
90459296 default:
9046
- name = "cubemaps/rgb_";
9047
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9297
+ name = "cubemaps/box/";
9298
+ ext = "png"; /*mipmap = true;*/
9299
+ reverseUP = false;
90489300 break;
90499301 }
9050
-
9051
- try
9052
- {
9053
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
9054
- } catch (IOException e)
9055
- {
9056
- throw new RuntimeException(e);
9057
- }
9302
+
9303
+ LoadSkybox(name, ext, mipmap);
90589304 }
90599305
90609306 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -9086,8 +9332,12 @@
90869332 static double[] model = new double[16];
90879333 double[] camera2light = new double[16];
90889334 double[] light2camera = new double[16];
9089
- int newenvy = -1;
9090
- boolean envyoff = true; // false;
9335
+
9336
+ //int newenvy = -1;
9337
+ //boolean envyoff = false;
9338
+
9339
+ String loadedskyboxname;
9340
+
90919341 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
90929342 //float[] light0 = { 0,0,0 };
90939343 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9505,7 +9755,7 @@
95059755
95069756 if (renderCamera != lightCamera)
95079757 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9508
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
9758
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
95099759
95109760 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
95119761
....@@ -9521,7 +9771,7 @@
95219771
95229772 if (renderCamera != lightCamera)
95239773 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9524
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
9774
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
95259775
95269776 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
95279777
....@@ -9567,10 +9817,12 @@
95679817 rati = 1 / rati;
95689818 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
95699819 }
9570
- assert (newenvy == -1);
9820
+
9821
+ //assert (newenvy == -1);
9822
+
95719823 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
95729824 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9573
- DrawSkyBox(gl);
9825
+ DrawSkyBox(gl, (float)rati);
95749826 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
95759827 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
95769828 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10607,7 +10859,7 @@
1060710859
1060810860 if (wait)
1060910861 {
10610
- Sleep(500);
10862
+ Sleep(200); // blocks everything
1061110863
1061210864 wait = false;
1061310865 }
....@@ -10722,7 +10974,7 @@
1072210974 // if (parentcam != renderCamera) // not a light
1072310975 if (cam != lightCamera)
1072410976 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10725
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
10977
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1072610978
1072710979 for (int j = 0; j < 4; j++)
1072810980 {
....@@ -10737,7 +10989,7 @@
1073710989 // if (parentcam != renderCamera) // not a light
1073810990 if (cam != lightCamera)
1073910991 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10740
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
10992
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1074110993
1074210994 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1074310995
....@@ -10823,13 +11075,41 @@
1082311075 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1082411076 }
1082511077
10826
- if (newenvy > -1)
11078
+// if (newenvy > -1)
11079
+// {
11080
+// LoadEnvy(newenvy);
11081
+// }
11082
+//
11083
+// newenvy = -1;
11084
+
11085
+ if (object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
1082711086 {
10828
- LoadEnvy(newenvy);
11087
+ if (cubemaprgb == null)
11088
+ {
11089
+ cubemaprgb = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11090
+ }
11091
+
11092
+ cubemap = cubemaprgb;
1082911093 }
10830
-
10831
- newenvy = -1;
10832
-
11094
+ else
11095
+ {
11096
+ if (object.skyboxname != null)
11097
+ {
11098
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11099
+ {
11100
+ cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11101
+ loadedskyboxname = object.skyboxname;
11102
+ }
11103
+ }
11104
+ else
11105
+ {
11106
+ cubemapcustom = null;
11107
+ loadedskyboxname = null;
11108
+ }
11109
+
11110
+ cubemap = cubemapcustom;
11111
+ }
11112
+
1083311113 ratio = ((double) getWidth()) / getHeight();
1083411114 //System.out.println("ratio = " + ratio);
1083511115
....@@ -10845,7 +11125,7 @@
1084511125
1084611126 if (!IsFrozen() && !ambientOcclusion)
1084711127 {
10848
- DrawSkyBox(gl);
11128
+ DrawSkyBox(gl, (float)ratio);
1084911129 }
1085011130
1085111131 //if (selection_view == -1)
....@@ -11028,9 +11308,9 @@
1102811308
1102911309 gl.glMatrixMode(GL.GL_MODELVIEW);
1103011310
11031
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11032
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
11033
-//gl.glEnable(gl.GL_MULTISAMPLE);
11311
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11312
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11313
+gl.glEnable(gl.GL_MULTISAMPLE);
1103411314 } else
1103511315 {
1103611316 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -11041,7 +11321,7 @@
1104111321 //System.out.println("BLENDING ON");
1104211322 gl.glEnable(GL.GL_BLEND);
1104311323 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
11044
-
11324
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1104511325 gl.glMatrixMode(gl.GL_PROJECTION);
1104611326 gl.glLoadIdentity();
1104711327
....@@ -11131,7 +11411,7 @@
1113111411
1113211412 // if (cam != lightCamera)
1113311413 //for (int count = parentcam.GetTransformCount(); --count>=0;)
11134
- LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
11414
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1113511415 }
1113611416
1113711417 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -11290,7 +11570,7 @@
1129011570 }
1129111571 }
1129211572
11293
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11573
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1129411574 {
1129511575 //gl.glDepthFunc(GL.GL_LEQUAL);
1129611576 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11298,24 +11578,21 @@
1129811578
1129911579 boolean texon = textureon;
1130011580
11301
- if (RENDERPROGRAM > 0)
11302
- {
11303
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11304
- textureon = false;
11305
- }
11581
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11582
+ textureon = false;
11583
+
1130611584 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1130711585 //System.out.println("ALLO");
1130811586 gl.glColorMask(false, false, false, false);
1130911587 DrawObject(gl);
11310
- if (RENDERPROGRAM > 0)
11311
- {
11312
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11313
- textureon = texon;
11314
- }
11588
+
11589
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11590
+ textureon = texon;
11591
+
1131511592 gl.glColorMask(true, true, true, true);
1131611593
1131711594 gl.glDepthFunc(GL.GL_EQUAL);
11318
- //gl.glDepthMask(false);
11595
+ gl.glDepthMask(false);
1131911596 }
1132011597
1132111598 if (false) // DrawMode() == SHADOW)
....@@ -11527,7 +11804,7 @@
1152711804 if ((TRACK || SHADOWTRACK) || zoomonce)
1152811805 {
1152911806 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11530
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11807
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1153111808 pingthread.StepToTarget(true); // true);
1153211809 // zoomonce = false;
1153311810 }
....@@ -11655,20 +11932,32 @@
1165511932 ReleaseTextures(DEFAULT_TEXTURES);
1165611933
1165711934 if (CLEANCACHE)
11658
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11935
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1165911936 {
11660
- String tex = e.nextElement();
11937
+ cTexture tex = e.nextElement();
1166111938
1166211939 // System.out.println("Texture --------- " + tex);
1166311940
11664
- if (tex.equals("WHITE_NOISE"))
11941
+ if (tex.equals("WHITE_NOISE:"))
1166511942 continue;
1166611943
11667
- if (!usedtextures.containsKey(tex))
11944
+ if (!usedtextures.contains(tex))
1166811945 {
11946
+ CacheTexture gettex = texturepigment.get(tex);
1166911947 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11670
- textures.get(tex).texture.dispose();
11671
- textures.remove(tex);
11948
+ if (gettex != null)
11949
+ {
11950
+ gettex.texture.dispose();
11951
+ texturepigment.remove(tex);
11952
+ }
11953
+
11954
+ gettex = texturebump.get(tex);
11955
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11956
+ if (gettex != null)
11957
+ {
11958
+ gettex.texture.dispose();
11959
+ texturebump.remove(tex);
11960
+ }
1167211961 }
1167311962 }
1167411963 }
....@@ -12196,8 +12485,76 @@
1219612485
1219712486 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1219812487
12199
- String program =
12488
+ String programmin =
12489
+ // Min shader
1220012490 "!!ARBfp1.0\n" +
12491
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12492
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12493
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12494
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12495
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12496
+ "PARAM light2cam0 = program.env[10];" +
12497
+ "PARAM light2cam1 = program.env[11];" +
12498
+ "PARAM light2cam2 = program.env[12];" +
12499
+ "TEMP temp;" +
12500
+ "TEMP light;" +
12501
+ "TEMP ndotl;" +
12502
+ "TEMP normal;" +
12503
+ "TEMP depth;" +
12504
+ "TEMP eye;" +
12505
+ "TEMP pos;" +
12506
+
12507
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12508
+ Normalize("normal") +
12509
+ "MOV light, state.light[0].position;" +
12510
+ "DP3 ndotl.x, light, normal;" +
12511
+
12512
+ // shadow
12513
+ "MOV pos, fragment.texcoord[1];" +
12514
+ "MOV temp, pos;" +
12515
+ ShadowTextureFetch("depth", "temp", "1") +
12516
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12517
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12518
+
12519
+ // No shadow when out of frustum
12520
+ //"SGE temp.y, depth.z, zero123.y;" +
12521
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12522
+
12523
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12524
+
12525
+ // Backlit
12526
+ "MOV pos.w, zero123.y;" +
12527
+ "DP4 eye.x, pos, light2cam0;" +
12528
+ "DP4 eye.y, pos, light2cam1;" +
12529
+ "DP4 eye.z, pos, light2cam2;" +
12530
+ Normalize("eye") +
12531
+
12532
+ "DP3 ndotl.y, -eye, normal;" +
12533
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12534
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12535
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12536
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12537
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12538
+
12539
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12540
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12541
+
12542
+ // Pigment
12543
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12544
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12545
+ "MUL temp, temp, ndotl.x;" +
12546
+
12547
+ "MUL temp, temp, zero123.z;" +
12548
+
12549
+ //"MUL temp, temp, ndotl.y;" +
12550
+
12551
+ "MOV temp.w, zero123.y;" + // reset alpha
12552
+ "MOV result.color, temp;" +
12553
+ "END";
12554
+
12555
+ String programmax =
12556
+ "!!ARBfp1.0\n" +
12557
+
1220112558 //"OPTION ARB_fragment_program_shadow;" +
1220212559 "PARAM light2cam0 = program.env[10];" +
1220312560 "PARAM light2cam1 = program.env[11];" +
....@@ -12312,8 +12669,7 @@
1231212669 "TEMP shininess;" +
1231312670 "\n" +
1231412671 "MOV texSamp, one;" +
12315
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12316
-
12672
+
1231712673 "MOV mapgrid.x, one2048th.x;" +
1231812674 "MOV temp, fragment.texcoord[1];" +
1231912675 /*
....@@ -12334,20 +12690,20 @@
1233412690 "MUL temp, floor, mapgrid.x;" +
1233512691 //"TEX depth0, temp, texture[1], 2D;" +
1233612692 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12337
- TextureFetch("depth0", "temp", "1") +
12693
+ ShadowTextureFetch("depth0", "temp", "1") +
1233812694 "") +
1233912695 "ADD temp.x, temp.x, mapgrid.x;" +
1234012696 //"TEX depth1, temp, texture[1], 2D;" +
1234112697 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12342
- TextureFetch("depth1", "temp", "1") +
12698
+ ShadowTextureFetch("depth1", "temp", "1") +
1234312699 "") +
1234412700 "ADD temp.y, temp.y, mapgrid.x;" +
1234512701 //"TEX depth2, temp, texture[1], 2D;" +
12346
- TextureFetch("depth2", "temp", "1") +
12702
+ ShadowTextureFetch("depth2", "temp", "1") +
1234712703 "SUB temp.x, temp.x, mapgrid.x;" +
1234812704 //"TEX depth3, temp, texture[1], 2D;" +
1234912705 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12350
- TextureFetch("depth3", "temp", "1") +
12706
+ ShadowTextureFetch("depth3", "temp", "1") +
1235112707 "") +
1235212708 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1235312709 //"MOV params, material;" +
....@@ -12718,10 +13074,10 @@
1271813074 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1271913075 "") +
1272013076
12721
- // display shadow only (bump == 0)
13077
+ // display shadow only (fakedepth == 0)
1272213078 "SUB temp.x, half.x, shadow.x;" +
1272313079 "MOV temp.y, -params5.z;" + // params6.x;" +
12724
- "SLT temp.z, temp.y, -one2048th.x;" +
13080
+ "SLT temp.z, temp.y, -c256i.x;" +
1272513081 "SUB temp.y, one.x, temp.z;" +
1272613082 "MUL temp.x, temp.x, temp.y;" +
1272713083 "KIL temp.x;" +
....@@ -13052,6 +13408,13 @@
1305213408 //once = true;
1305313409 }
1305413410
13411
+ String program = programmax;
13412
+
13413
+ if (Globals.MINSHADER)
13414
+ {
13415
+ program = programmin;
13416
+ }
13417
+
1305513418 System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1305613419 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1305713420 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
....@@ -13145,25 +13508,26 @@
1314513508 return out;
1314613509 }
1314713510
13148
- String TextureFetch(String dest, String src, String unit)
13511
+ // Also does frustum culling
13512
+ String ShadowTextureFetch(String dest, String src, String unit)
1314913513 {
1315013514 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1315113515 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1315213516 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13517
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13518
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1315313519 "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;" +
13520
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13521
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1315813522 //"SWZ buffer, temp, w,w,w,w;";
13159
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13523
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1316013524 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1316113525 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1316213526 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13163
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13527
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1316413528
13165
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13166
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13529
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13530
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1316713531 }
1316813532
1316913533 String Shadow(String depth, String shadow)
....@@ -13210,7 +13574,7 @@
1321013574 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1321113575 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1321213576
13213
- // No shadow when out of frustrum
13577
+ // No shadow when out of frustum
1321413578 "SGE temp.x, " + depth + ".z, one.z;" +
1321513579 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1321613580 "";
....@@ -13375,9 +13739,10 @@
1337513739 "DP3 " + dest + ".z," + "normals," + "eye;" +
1337613740 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1337713741 //"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;" +
13742
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13743
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13744
+
13745
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1338113746 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1338213747 "RCP " + dest + ".w," + dest + ".w;" +
1338313748 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13942,7 +14307,7 @@
1394214307
1394314308 // fev 2014???
1394414309 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13945
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14310
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1394614311 pingthread.StepToTarget(true); // true);
1394714312 }
1394814313 // if (!LIVE)
....@@ -14007,14 +14372,15 @@
1400714372 drag = false;
1400814373 //System.out.println("Mouse DOWN");
1400914374 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);
14375
+ //ClickInfo info = new ClickInfo();
14376
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14377
+ object.clickInfo.pane = this;
14378
+ object.clickInfo.camera = renderCamera;
14379
+ object.clickInfo.x = x;
14380
+ object.clickInfo.y = y;
14381
+ object.clickInfo.modifiers = modifiersex;
14382
+ editObj = object.doEditClick(//info,
14383
+ 0);
1401814384 if (!editObj)
1401914385 {
1402014386 hasMarquee = true;
....@@ -14296,12 +14662,12 @@
1429614662 void GoDown(int mod)
1429714663 {
1429814664 MODIFIERS |= COMMAND;
14299
- /*
14665
+ /**/
1430014666 if((mod&SHIFT) == SHIFT)
14301
- manipCamera.RotatePosition(0, -speed);
14667
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
1430214668 else
14303
- manipCamera.BackForth(0, -speed*delta, getWidth());
14304
- */
14669
+ manipCamera.RotatePosition(0, -speed);
14670
+ /**/
1430514671 if ((mod & SHIFT) == SHIFT)
1430614672 {
1430714673 mouseMode = mouseMode; // VR??
....@@ -14317,12 +14683,12 @@
1431714683 void GoUp(int mod)
1431814684 {
1431914685 MODIFIERS |= COMMAND;
14320
- /*
14686
+ /**/
1432114687 if((mod&SHIFT) == SHIFT)
14322
- manipCamera.RotatePosition(0, speed);
14688
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
1432314689 else
14324
- manipCamera.BackForth(0, speed*delta, getWidth());
14325
- */
14690
+ manipCamera.RotatePosition(0, speed);
14691
+ /**/
1432614692 if ((mod & SHIFT) == SHIFT)
1432714693 {
1432814694 mouseMode = mouseMode;
....@@ -14338,12 +14704,12 @@
1433814704 void GoLeft(int mod)
1433914705 {
1434014706 MODIFIERS |= COMMAND;
14341
- /*
14707
+ /**/
1434214708 if((mod&SHIFT) == SHIFT)
14343
- manipCamera.RotatePosition(speed, 0);
14344
- else
1434514709 manipCamera.Translate(speed*delta, 0, getWidth());
14346
- */
14710
+ else
14711
+ manipCamera.RotatePosition(speed, 0);
14712
+ /**/
1434714713 if ((mod & SHIFT) == SHIFT)
1434814714 {
1434914715 mouseMode = mouseMode;
....@@ -14359,12 +14725,12 @@
1435914725 void GoRight(int mod)
1436014726 {
1436114727 MODIFIERS |= COMMAND;
14362
- /*
14728
+ /**/
1436314729 if((mod&SHIFT) == SHIFT)
14364
- manipCamera.RotatePosition(-speed, 0);
14365
- else
1436614730 manipCamera.Translate(-speed*delta, 0, getWidth());
14367
- */
14731
+ else
14732
+ manipCamera.RotatePosition(-speed, 0);
14733
+ /**/
1436814734 if ((mod & SHIFT) == SHIFT)
1436914735 {
1437014736 mouseMode = mouseMode;
....@@ -14414,15 +14780,16 @@
1441414780 if (editObj)
1441514781 {
1441614782 drag = true;
14417
- ClickInfo info = new ClickInfo();
14418
- info.bounds.setBounds(0, 0,
14783
+ //ClickInfo info = new ClickInfo();
14784
+ object.clickInfo.bounds.setBounds(0, 0,
1441914785 (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);
14786
+ object.clickInfo.pane = this;
14787
+ object.clickInfo.camera = renderCamera;
14788
+ object.clickInfo.x = x;
14789
+ object.clickInfo.y = y;
14790
+ object //.GetWindow().copy
14791
+ .doEditDrag(//info,
14792
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1442614793 } else
1442714794 {
1442814795 if (x < startX)
....@@ -14571,24 +14938,27 @@
1457114938 }
1457214939 }
1457314940
14941
+// ClickInfo clickInfo = new ClickInfo();
14942
+
1457414943 public void mouseMoved(MouseEvent e)
1457514944 {
1457614945 //System.out.println("mouseMoved: " + e);
1457714946 if (isRenderer)
1457814947 return;
1457914948
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;
14949
+ // Mouse cursor feedback
14950
+ object.clickInfo.x = e.getX();
14951
+ object.clickInfo.y = e.getY();
14952
+ object.clickInfo.modifiers = e.getModifiersEx();
14953
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14954
+ object.clickInfo.pane = this;
14955
+ object.clickInfo.camera = renderCamera;
1458714956 if (!isRenderer)
1458814957 {
1458914958 //ObjEditor editWindow = object.editWindow;
1459014959 //Object3D copy = editWindow.copy;
14591
- if (object.doEditClick(ci, 0))
14960
+ if (object.doEditClick(//clickInfo,
14961
+ 0))
1459214962 {
1459314963 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1459414964 } else
....@@ -14603,7 +14973,8 @@
1460314973 Globals.MOUSEDRAGGED = false;
1460414974
1460514975 movingcamera = false;
14606
- X = Y = 0;
14976
+ X = 0; // getBounds().width/2;
14977
+ Y = 0; // getBounds().height/2;
1460714978 //System.out.println("mouseReleased: " + e);
1460814979 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1460914980 }
....@@ -14859,7 +15230,8 @@
1485915230 // break;
1486015231 case 'T':
1486115232 CACHETEXTURE ^= true;
14862
- textures.clear();
15233
+ texturepigment.clear();
15234
+ texturebump.clear();
1486315235 // repaint();
1486415236 break;
1486515237 case 'Y':
....@@ -14944,7 +15316,9 @@
1494415316 case 'E' : COMPACT ^= true;
1494515317 repaint();
1494615318 break;
14947
- case 'W' : DEBUGHSB ^= true;
15319
+ case 'W' : // Wide Window (fullscreen)
15320
+ //DEBUGHSB ^= true;
15321
+ ObjEditor.theFrame.ToggleFullScreen();
1494815322 repaint();
1494915323 break;
1495015324 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14970,13 +15344,7 @@
1497015344 repaint();
1497115345 break;
1497215346 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':
15347
+ //case 'L':
1498015348 if (lightMode)
1498115349 {
1498215350 lightMode = false;
....@@ -15040,20 +15408,24 @@
1504015408 OCCLUSION_CULLING ^= true;
1504115409 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1504215410 break;
15043
- case '0': envyoff ^= true; repaint(); break;
15411
+ //case '0': envyoff ^= true; repaint(); break;
1504415412 case '1':
1504515413 case '2':
1504615414 case '3':
1504715415 case '4':
1504815416 case '5':
15049
- newenvy = Character.getNumericValue(key);
15050
- repaint();
15051
- break;
1505215417 case '6':
1505315418 case '7':
1505415419 case '8':
1505515420 case '9':
15056
- BGcolor = (key - '6')/3.f;
15421
+ if (true) // envyoff)
15422
+ {
15423
+ BGcolor = (key - '1')/8.f;
15424
+ }
15425
+ else
15426
+ {
15427
+ //newenvy = Character.getNumericValue(key);
15428
+ }
1505715429 repaint();
1505815430 break;
1505915431 case '!':
....@@ -15119,11 +15491,14 @@
1511915491 case '_':
1512015492 kompactbit = 5;
1512115493 break;
15122
- case '+':
15123
- kompactbit = 6;
15124
- break;
15494
+// case '+':
15495
+// kompactbit = 6;
15496
+// break;
1512515497 case ' ':
15126
- ObjEditor.theFrame.ToggleFullScreen();
15498
+ lightMode ^= true;
15499
+ Globals.lighttouched = true;
15500
+ manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
15501
+ targetLookAt.set(manipCamera.lookAt);
1512715502 repaint();
1512815503 break;
1512915504 //case '`' :
....@@ -15170,8 +15545,9 @@
1517015545 case DELETE:
1517115546 ClearSelection();
1517215547 break;
15173
- /*
1517415548 case '+':
15549
+
15550
+ /*
1517515551 //fontsize += 1;
1517615552 bbzoom *= 2;
1517715553 repaint();
....@@ -15188,17 +15564,17 @@
1518815564 case '=':
1518915565 IncDepth();
1519015566 //fontsize += 1;
15191
- object.editWindow.refreshContents(true);
15567
+ object.GetWindow().refreshContents(true);
1519215568 maskbit = 6;
1519315569 break;
1519415570 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1519515571 DecDepth();
1519615572 maskbit = 5;
1519715573 //if(fontsize > 1) fontsize -= 1;
15198
- if (object.editWindow == null)
15199
- new Exception().printStackTrace();
15200
- else
15201
- object.editWindow.refreshContents(true);
15574
+// if (object.editWindow == null)
15575
+// new Exception().printStackTrace();
15576
+// else
15577
+ object.GetWindow().refreshContents(true);
1520215578 break;
1520315579 case '{':
1520415580 manipCamera.shaper_fovy /= 1.1;
....@@ -15422,7 +15798,7 @@
1542215798 }
1542315799 */
1542415800
15425
- object.editWindow.EditSelection(false);
15801
+ object.GetWindow().EditSelection(false);
1542615802 }
1542715803
1542815804 void SelectParent()
....@@ -15439,10 +15815,10 @@
1543915815 {
1544015816 //selectees.remove(i);
1544115817 System.out.println("select parent of " + elem);
15442
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15818
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1544315819 } else
1544415820 {
15445
- group.editWindow.Select(elem.GetTreePath(), first, true);
15821
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1544615822 }
1544715823
1544815824 first = false;
....@@ -15484,12 +15860,12 @@
1548415860 for (int j = 0; j < group.children.size(); j++)
1548515861 {
1548615862 elem = (Object3D) group.children.elementAt(j);
15487
- object.editWindow.Select(elem.GetTreePath(), first, true);
15863
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1548815864 first = false;
1548915865 }
1549015866 } else
1549115867 {
15492
- object.editWindow.Select(elem.GetTreePath(), first, true);
15868
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1549315869 }
1549415870
1549515871 first = false;
....@@ -15500,21 +15876,21 @@
1550015876 {
1550115877 //Composite group = (Composite) object;
1550215878 Object3D group = object;
15503
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15879
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1550415880 }
1550515881
1550615882 void ResetTransform(int mask)
1550715883 {
1550815884 //Composite group = (Composite) object;
1550915885 Object3D group = object;
15510
- group.editWindow.ResetTransform(mask);
15886
+ group.GetWindow().ResetTransform(mask);
1551115887 }
1551215888
1551315889 void FlipTransform()
1551415890 {
1551515891 //Composite group = (Composite) object;
1551615892 Object3D group = object;
15517
- group.editWindow.FlipTransform();
15893
+ group.GetWindow().FlipTransform();
1551815894 // group.editWindow.ReduceMesh(true);
1551915895 }
1552015896
....@@ -15522,7 +15898,7 @@
1552215898 {
1552315899 //Composite group = (Composite) object;
1552415900 Object3D group = object;
15525
- group.editWindow.PrintMemory();
15901
+ group.GetWindow().PrintMemory();
1552615902 // group.editWindow.ReduceMesh(true);
1552715903 }
1552815904
....@@ -15530,7 +15906,7 @@
1553015906 {
1553115907 //Composite group = (Composite) object;
1553215908 Object3D group = object;
15533
- group.editWindow.ResetCentroid();
15909
+ group.GetWindow().ResetCentroid();
1553415910 }
1553515911
1553615912 void IncDepth()
....@@ -15612,8 +15988,6 @@
1561215988
1561315989 int width = getBounds().width;
1561415990 int height = getBounds().height;
15615
- ClickInfo info = new ClickInfo();
15616
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1561715991 //Image img = CreateImage(width, height);
1561815992 //System.out.println("width = " + width + "; height = " + height + "\n");
1561915993
....@@ -15690,48 +16064,77 @@
1569016064 }
1569116065 if (object != null && !hasMarquee)
1569216066 {
16067
+ if (object.clickInfo == null)
16068
+ object.clickInfo = new ClickInfo();
16069
+ ClickInfo info = object.clickInfo;
16070
+ //ClickInfo info = new ClickInfo();
16071
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16072
+
1569316073 if (isRenderer)
1569416074 {
15695
- info.flags++;
16075
+ object.clickInfo.flags++;
1569616076 double frameAspect = (double) width / (double) height;
1569716077 if (frameAspect > renderCamera.aspect)
1569816078 {
1569916079 int desired = (int) ((double) height * renderCamera.aspect);
15700
- info.bounds.width -= width - desired;
15701
- info.bounds.x += (width - desired) / 2;
16080
+ object.clickInfo.bounds.width -= width - desired;
16081
+ object.clickInfo.bounds.x += (width - desired) / 2;
1570216082 } else
1570316083 {
1570416084 int desired = (int) ((double) width / renderCamera.aspect);
15705
- info.bounds.height -= height - desired;
15706
- info.bounds.y += (height - desired) / 2;
16085
+ object.clickInfo.bounds.height -= height - desired;
16086
+ object.clickInfo.bounds.y += (height - desired) / 2;
1570716087 }
1570816088 }
15709
- info.g = gr;
15710
- info.camera = renderCamera;
16089
+
16090
+ object.clickInfo.g = gr;
16091
+ object.clickInfo.camera = renderCamera;
1571116092 /*
1571216093 // Memory intensive (brep.verticescopy)
1571316094 if (!(object instanceof Composite))
1571416095 object.draw(info, 0, false); // SLOW :
1571516096 */
15716
- if (!isRenderer)
16097
+ if (!isRenderer) // && drag)
1571716098 {
15718
- object.drawEditHandles(info, 0);
15719
-
15720
- if (drag && (X != 0 || Y != 0) && object.selection.Size() > 0)
16099
+ Grafreed.Assert(object != null);
16100
+ Grafreed.Assert(object.selection != null);
16101
+ if (object.selection.Size() > 0)
1572116102 {
15722
- switch (object.selection.get(0).hitSomething)
16103
+ int hitSomething = object.selection.get(0).hitSomething;
16104
+
16105
+ object.clickInfo.DX = 0;
16106
+ object.clickInfo.DY = 0;
16107
+ object.clickInfo.W = 1;
16108
+ if (hitSomething == Object3D.hitCenter)
1572316109 {
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;
16110
+ info.DX = X;
16111
+ if (X != 0)
16112
+ info.DX -= info.bounds.width/2;
16113
+
16114
+ info.DY = Y;
16115
+ if (Y != 0)
16116
+ info.DY -= info.bounds.height/2;
1573316117 }
15734
-
16118
+
16119
+ object.drawEditHandles(//info,
16120
+ 0);
16121
+
16122
+ if (drag && (X != 0 || Y != 0))
16123
+ {
16124
+ switch (hitSomething)
16125
+ {
16126
+ case Object3D.hitCenter: gr.setColor(Color.pink);
16127
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16128
+ break;
16129
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16130
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16131
+ break;
16132
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16133
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16134
+ break;
16135
+ }
16136
+
16137
+ }
1573516138 }
1573616139 }
1573716140 }
....@@ -16213,6 +16616,8 @@
1621316616 private /*static*/ boolean firstime;
1621416617 private /*static*/ cVector newView = new cVector();
1621516618 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16619
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16620
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1621616621 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1621716622 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1621816623 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16225,29 +16630,67 @@
1622516630 {
1622616631 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1622716632
16633
+ int usedsuf = 0;
16634
+
1622816635 for (int i = 0; i < suffixes.length; i++)
1622916636 {
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)
16637
+ String[] suffixe = suffixes;
16638
+ String[] fallback = suffixes2;
16639
+ String[] fallfallback = suffixes3;
16640
+
16641
+ for (int c=usedsuf; --c>=0;)
1623516642 {
16236
- throw new IOException("Unable to load texture " + resourceName);
16643
+// String[] temp = suffixe;
16644
+// suffixe = fallback;
16645
+// fallback = fallfallback;
16646
+// fallfallback = temp;
1623716647 }
16648
+
16649
+ String resourceName = basename + suffixe[i] + "." + suffix;
16650
+ TextureData data;
16651
+
16652
+ try
16653
+ {
16654
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16655
+ mipmapped,
16656
+ FileUtil.getFileSuffix(resourceName));
16657
+ }
16658
+ catch (Exception e)
16659
+ {
16660
+ try
16661
+ {
16662
+ resourceName = basename + fallback[i] + "." + suffix;
16663
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16664
+ mipmapped,
16665
+ FileUtil.getFileSuffix(resourceName));
16666
+ }
16667
+ catch (Exception e2)
16668
+ {
16669
+ resourceName = basename + fallfallback[i] + "." + suffix;
16670
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16671
+ mipmapped,
16672
+ FileUtil.getFileSuffix(resourceName));
16673
+ }
16674
+ }
16675
+
1623816676 //System.out.println("Target = " + targets[i]);
1623916677 cubemap.updateImage(data, targets[i]);
1624016678 }
1624116679
1624216680 return cubemap;
1624316681 }
16682
+
1624416683 int bigsphere = -1;
1624516684
1624616685 float BGcolor = 0.5f;
1624716686
16248
- private void DrawSkyBox(GL gl)
16687
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16688
+
16689
+ private void DrawSkyBox(GL gl, float ratio)
1624916690 {
16250
- if (envyoff || cubemap == null)
16691
+ if (//envyoff ||
16692
+ WIREFRAME ||
16693
+ cubemap == null)
1625116694 {
1625216695 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1625316696 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16262,7 +16705,17 @@
1626216705 // Compensates for ExaminerViewer's modification of modelview matrix
1626316706 gl.glMatrixMode(GL.GL_MODELVIEW);
1626416707 gl.glLoadIdentity();
16708
+ gl.glScalef(1,ratio,1);
1626516709
16710
+// colorV[0] = 2;
16711
+// colorV[1] = 2;
16712
+// colorV[2] = 2;
16713
+// colorV[3] = 1;
16714
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16715
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16716
+//
16717
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16718
+
1626616719 //gl.glActiveTexture(GL.GL_TEXTURE1);
1626716720 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1626816721
....@@ -16294,6 +16747,7 @@
1629416747 {
1629516748 gl.glScalef(1.0f, -1.0f, 1.0f);
1629616749 }
16750
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1629716751 gl.glMultMatrixd(viewrot_1, 0);
1629816752 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1629916753 //viewer.updateInverseRotation(gl);
....@@ -16529,6 +16983,14 @@
1652916983 }
1653016984 }
1653116985
16986
+ private Object3D GetFolder()
16987
+ {
16988
+ Object3D folder = object.GetWindow().copy;
16989
+ if (object.GetWindow().copy.selection.Size() > 0)
16990
+ folder = object.GetWindow().copy.selection.elementAt(0);
16991
+ return folder;
16992
+ }
16993
+
1653216994 class SelectBuffer implements GLEventListener
1653316995 {
1653416996
....@@ -16544,7 +17006,7 @@
1654417006 //new Exception().printStackTrace();
1654517007 System.out.println("select buffer init");
1654617008 // Use debug pipeline
16547
- drawable.setGL(new DebugGL(drawable.getGL()));
17009
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1654817010
1654917011 GL gl = drawable.getGL();
1655017012
....@@ -16608,6 +17070,17 @@
1660817070
1660917071 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1661017072
17073
+ if (PAINTMODE)
17074
+ {
17075
+ if (object.GetWindow().copy.selection.Size() > 0)
17076
+ {
17077
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17078
+
17079
+ // Make what you paint not selectable.
17080
+ paintobj.ResetSelectable();
17081
+ }
17082
+ }
17083
+
1661117084 //int tmp = selection_view;
1661217085 //selection_view = -1;
1661317086 int temp = DrawMode();
....@@ -16619,6 +17092,17 @@
1661917092 // temp = DEFAULT; // patch for selection debug
1662017093 Globals.drawMode = temp; // WARNING
1662117094
17095
+ if (PAINTMODE)
17096
+ {
17097
+ if (object.GetWindow().copy.selection.Size() > 0)
17098
+ {
17099
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17100
+
17101
+ // Revert.
17102
+ paintobj.RestoreSelectable();
17103
+ }
17104
+ }
17105
+
1662217106 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1662317107
1662417108 // trying different ways of getting the depth info over
....@@ -16722,29 +17206,31 @@
1672217206 }
1672317207
1672417208 if (!movingcamera && !PAINTMODE)
16725
- object.editWindow.ScreenFitPoint(); // fev 2014
17209
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1672617210
16727
- if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17211
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1672817212 {
16729
- Object3D paintobj = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17213
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1673017214
16731
- Object3D group = new Object3D("inst" + paintcount++);
17215
+ if (object.GetWindow().copy.selection.Size() > 0)
17216
+ {
17217
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1673217218
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();
17219
+ Object3D inst = new Object3D("inst" + paintcount++);
17220
+
17221
+ inst.CreateMaterial(); // use a void leaf to select instances
17222
+
17223
+ inst.add(paintobj); // link
17224
+
17225
+ object.GetWindow().SnapObject(inst);
17226
+
17227
+ Object3D folder = paintFolder; // GetFolder();
17228
+
17229
+ folder.add(inst);
17230
+
17231
+ object.GetWindow().ResetModel();
17232
+ object.GetWindow().refreshContents();
17233
+ }
1674817234 }
1674917235 else
1675017236 paintcount = 0;
....@@ -17066,10 +17552,14 @@
1706617552 gl.glFlush();
1706717553
1706817554 /**/
17069
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17555
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1707017556
17071
- float[] pixels = occlusionsizebuffer.array();
17557
+ float[] depths = occlusiondepthbuffer.array();
1707217558
17559
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17560
+
17561
+ int[] pixels = selectsizebuffer.array();
17562
+
1707317563 double r = 0, g = 0, b = 0;
1707417564
1707517565 double count = 0;
....@@ -17080,7 +17570,7 @@
1708017570
1708117571 double FACTOR = 1;
1708217572
17083
- for (int i = 0; i < pixels.length; i++)
17573
+ for (int i = 0; i < depths.length; i++)
1708417574 {
1708517575 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1708617576 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -17163,7 +17653,7 @@
1716317653
1716417654 double scale = ray.z; // 1; // cos
1716517655
17166
- float depth = pixels[newindex];
17656
+ float depth = depths[newindex];
1716717657
1716817658 /*
1716917659 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -17360,11 +17850,14 @@
1736017850 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1736117851 static IntBuffer bigAAbuffer;
1736217852 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
17363
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17853
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1736417854 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1736517855 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1736617856 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17367
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17857
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17858
+
17859
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17860
+
1736817861 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1736917862 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1737017863 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();