Normand Briere
2019-08-20 564f4d12d93813b5d680fc24d4f118c3886d96ed
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,11 @@
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;
116
+ boolean transformMode;
117
+
77118 boolean reverseUP = false;
78119 static boolean frozen = false;
79120 boolean enablebackspace = false; // patch for back buffer refresh
....@@ -127,7 +168,7 @@
127168
128169
129170 // OPTIONS
130
- boolean Skinshader = true;
171
+ boolean Skinshader = false; // true;
131172 boolean cameraLight = false;
132173 boolean UVdebug = false;
133174 boolean Udebug = false;
....@@ -136,7 +177,7 @@
136177 static boolean doublesided = false; // true; // reversed normals are awful for conformance
137178 boolean anisotropy = true;
138179 boolean softshadow = true; // slower but better false;
139
- boolean opacityhalo = false;
180
+ boolean opacityhalo = false; // reverse the halo effect (e.g. glass)
140181
141182 boolean macromode = false;
142183
....@@ -150,6 +191,19 @@
150191 }
151192
152193 private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
194
+
195
+ public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException
196
+ {
197
+ try
198
+ {
199
+ return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
200
+ } catch (IOException e)
201
+ {
202
+ System.out.println("NAME = " + name);
203
+ e.printStackTrace(); // throw new RuntimeException(e);
204
+ return null;
205
+ }
206
+ }
153207
154208 void SetAsGLRenderer(boolean b)
155209 {
....@@ -169,7 +223,8 @@
169223
170224 SetCamera(cam);
171225
172
- SetLight(new Camera(new cVector(10, 10, -20)));
226
+ // Warning: not used.
227
+ SetLight(new Camera(new cVector(15, 10, -20)));
173228
174229 object = o;
175230
....@@ -1447,6 +1502,8 @@
14471502 gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
14481503 }
14491504
1505
+ float[] colorV = new float[4];
1506
+
14501507 void SetColor(Object3D obj, Vertex p0)
14511508 {
14521509 CameraPane display = this;
....@@ -1514,8 +1571,6 @@
15141571 {
15151572 return;
15161573 }
1517
-
1518
- float[] colorV = new float[3];
15191574
15201575 if (false) // marked)
15211576 {
....@@ -1764,7 +1819,7 @@
17641819
17651820 display.modelParams7[0] = 0;
17661821 display.modelParams7[1] = 1000;
1767
- display.modelParams7[2] = 0;
1822
+ display.modelParams7[2] = material.parallax;
17681823 display.modelParams7[3] = 0;
17691824
17701825 //display.modelParams6[0] = 100; // criss de bug de bump
....@@ -1997,9 +2052,9 @@
19972052 switch(viewcode)
19982053 {
19992054 case 0: return "main";
2000
- case 1: return "one";
2001
- case 2: return "two";
2002
- case 3: return "three";
2055
+ case 1: return "Red";
2056
+ case 2: return "Green";
2057
+ case 3: return "Blue";
20032058 case 4: return "light";
20042059 }
20052060
....@@ -2065,7 +2120,7 @@
20652120 //System.err.println("Oeil on");
20662121 OEIL = true;
20672122 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2068
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2123
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
20692124 //pingthread.StepToTarget(true);
20702125 }
20712126
....@@ -2298,10 +2353,17 @@
22982353 HANDLES ^= true;
22992354 }
23002355
2356
+ Object3D paintFolder;
2357
+
23012358 void TogglePaint()
23022359 {
23032360 PAINTMODE ^= true;
23042361 paintcount = 0;
2362
+
2363
+ if (PAINTMODE)
2364
+ {
2365
+ paintFolder = GetFolder();
2366
+ }
23052367 }
23062368
23072369 void SwapCamera(int a, int b)
....@@ -2398,6 +2460,21 @@
23982460 return currentGL;
23992461 }
24002462
2463
+ static private BufferedImage CreateBim(TextureData texturedata)
2464
+ {
2465
+ Grafreed.Assert(texturedata != null);
2466
+
2467
+ int width = texturedata.getWidth();
2468
+ int height = texturedata.getHeight();
2469
+
2470
+ Buffer buffer = texturedata.getBuffer();
2471
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2472
+
2473
+ byte[] bytes = bytebuf.array();
2474
+
2475
+ return CreateBim(bytes, width, height);
2476
+ }
2477
+
24012478 /**/
24022479 class CacheTexture
24032480 {
....@@ -2406,28 +2483,31 @@
24062483
24072484 int resolution;
24082485
2409
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2486
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
24102487 {
2411
- texture = tex;
2488
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2489
+ texturedata = texdata;
24122490 resolution = res;
24132491 }
24142492 }
24152493 /**/
24162494
24172495 // 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>();
2496
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2497
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2498
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2499
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2500
+
24212501 int pigmentdepth = 0;
24222502 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
24232503 int bumpdepth = 0;
24242504 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
24252505 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
24262506 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2427
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2507
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
24282508 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
24292509
2430
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2510
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
24312511 {
24322512 TextureData texturedata = null;
24332513
....@@ -2437,7 +2517,7 @@
24372517 com.sun.opengl.util.texture.TextureIO.newTextureData(
24382518 getClass().getClassLoader().getResourceAsStream(name),
24392519 true,
2440
- com.sun.opengl.util.texture.TextureIO.PNG);
2520
+ GetFormat(name)); // com.sun.opengl.util.texture.TextureIO.PNG);
24412521 } catch (java.io.IOException e)
24422522 {
24432523 throw new javax.media.opengl.GLException(e);
....@@ -2446,13 +2526,34 @@
24462526 if (bump)
24472527 texturedata = ConvertBump(texturedata, false);
24482528
2449
- com.sun.opengl.util.texture.Texture texture =
2450
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2529
+// com.sun.opengl.util.texture.Texture texture =
2530
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
24512531
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);
2532
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2533
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
24542534
2455
- return texture;
2535
+ return texturedata;
2536
+ }
2537
+
2538
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2539
+ {
2540
+ TextureData texturedata = null;
2541
+
2542
+ try
2543
+ {
2544
+ texturedata =
2545
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2546
+ bim,
2547
+ true);
2548
+ } catch (Exception e)
2549
+ {
2550
+ throw new javax.media.opengl.GLException(e);
2551
+ }
2552
+
2553
+ if (bump)
2554
+ texturedata = ConvertBump(texturedata, false);
2555
+
2556
+ return texturedata;
24562557 }
24572558
24582559 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3525,6 +3626,8 @@
35253626
35263627 System.out.println("LOADING TEXTURE : " + name);
35273628
3629
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3630
+
35283631 //
35293632 if (false) // compressbit > 0)
35303633 {
....@@ -7923,7 +8026,7 @@
79238026 String pigment = Object3D.GetPigment(tex);
79248027 String bump = Object3D.GetBump(tex);
79258028
7926
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8029
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79278030 {
79288031 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79298032 // System.out.println("; bump = " + bump);
....@@ -7938,8 +8041,8 @@
79388041 pigment = null;
79398042 }
79408043
7941
- ReleaseTexture(bump, true);
7942
- ReleaseTexture(pigment, false);
8044
+ ReleaseTexture(tex, true);
8045
+ ReleaseTexture(tex, false);
79438046 }
79448047
79458048 public void ReleasePigmentTexture(cTexture tex) // INTERFACE
....@@ -7957,7 +8060,7 @@
79578060
79588061 String pigment = Object3D.GetPigment(tex);
79598062
7960
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8063
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79618064 {
79628065 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79638066 // System.out.println("; bump = " + bump);
....@@ -7968,7 +8071,7 @@
79688071 pigment = null;
79698072 }
79708073
7971
- ReleaseTexture(pigment, false);
8074
+ ReleaseTexture(tex, false);
79728075 }
79738076
79748077 public void ReleaseBumpTexture(cTexture tex) // INTERFACE
....@@ -7986,7 +8089,7 @@
79868089
79878090 String bump = Object3D.GetBump(tex);
79888091
7989
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8092
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79908093 {
79918094 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79928095 // System.out.println("; bump = " + bump);
....@@ -7997,10 +8100,10 @@
79978100 bump = null;
79988101 }
79998102
8000
- ReleaseTexture(bump, true);
8103
+ ReleaseTexture(tex, true);
80018104 }
80028105
8003
- void ReleaseTexture(String tex, boolean bump)
8106
+ void ReleaseTexture(cTexture tex, boolean bump)
80048107 {
80058108 if (// DrawMode() != 0 || /*tex == null ||*/
80068109 ambientOcclusion ) // || !textureon)
....@@ -8011,7 +8114,7 @@
80118114 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
80128115
80138116 if (tex != null)
8014
- texture = textures.get(tex);
8117
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
80158118
80168119 // //assert( texture != null );
80178120 // if (texture == null)
....@@ -8105,47 +8208,50 @@
81058208
81068209 /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
81078210 {
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
- }
8211
+// if (// DrawMode() != 0 || /*tex == null ||*/
8212
+// ambientOcclusion ) // || !textureon)
8213
+// {
8214
+// return; // false;
8215
+// }
8216
+//
8217
+// if (tex == null)
8218
+// {
8219
+// BindTexture(null,false,resolution);
8220
+// BindTexture(null,true,resolution);
8221
+// return;
8222
+// }
8223
+//
8224
+// String pigment = Object3D.GetPigment(tex);
8225
+// String bump = Object3D.GetBump(tex);
8226
+//
8227
+// usedtextures.add(pigment);
8228
+// usedtextures.add(bump);
8229
+//
8230
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8231
+// {
8232
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8233
+// // System.out.println("; bump = " + bump);
8234
+// }
8235
+//
8236
+// if (bump.equals(""))
8237
+// {
8238
+// bump = null;
8239
+// }
8240
+// if (pigment.equals(""))
8241
+// {
8242
+// pigment = null;
8243
+// }
8244
+//
8245
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8246
+// BindTexture(pigment, false, resolution);
8247
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8248
+// BindTexture(bump, true, resolution);
8249
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8250
+//
8251
+// return; // true;
81208252
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;
8253
+ BindPigmentTexture(tex, resolution);
8254
+ BindBumpTexture(tex, resolution);
81498255 }
81508256
81518257 /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8164,9 +8270,9 @@
81648270
81658271 String pigment = Object3D.GetPigment(tex);
81668272
8167
- usedtextures.put(pigment, pigment);
8273
+ usedtextures.add(tex);
81688274
8169
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8275
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
81708276 {
81718277 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
81728278 // System.out.println("; bump = " + bump);
....@@ -8178,7 +8284,7 @@
81788284 }
81798285
81808286 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8181
- BindTexture(pigment, false, resolution);
8287
+ BindTexture(tex, false, resolution);
81828288 }
81838289
81848290 /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8197,9 +8303,9 @@
81978303
81988304 String bump = Object3D.GetBump(tex);
81998305
8200
- usedtextures.put(bump, bump);
8306
+ usedtextures.add(tex);
82018307
8202
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8308
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
82038309 {
82048310 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
82058311 // System.out.println("; bump = " + bump);
....@@ -8211,7 +8317,7 @@
82118317 }
82128318
82138319 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8214
- BindTexture(bump, true, resolution);
8320
+ BindTexture(tex, true, resolution);
82158321 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
82168322 }
82178323
....@@ -8235,13 +8341,19 @@
82358341 return fileExists;
82368342 }
82378343
8238
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception
8344
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
82398345 {
8240
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8346
+ CacheTexture texturecache = null;
82418347
82428348 if (tex != null)
82438349 {
8244
- String texname = tex;
8350
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8351
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
8352
+
8353
+ if (texname.equals("") && texdata == null)
8354
+ {
8355
+ return null;
8356
+ }
82458357
82468358 String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
82478359
....@@ -8251,19 +8363,46 @@
82518363 // else
82528364 // if (!texname.startsWith("/"))
82538365 // texname = "/Users/nbriere/Textures/" + texname;
8254
- if (!FileExists(tex))
8366
+ if (!FileExists(texname) && !texname.startsWith("@"))
82558367 {
82568368 texname = fallbackTextureName;
82578369 }
82588370
82598371 if (CACHETEXTURE)
8260
- texture = textures.get(texname); // TEXTURE CACHE
8261
-
8262
- TextureData texturedata = null;
8263
-
8264
- if (texture == null || texture.resolution < resolution)
82658372 {
8266
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8373
+ if (texdata == null)
8374
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8375
+ else
8376
+ texturecache = bimtextures.get(texdata);
8377
+ }
8378
+
8379
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8380
+ {
8381
+ TextureData texturedata = null;
8382
+
8383
+ if (texdata != null && textureon)
8384
+ {
8385
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8386
+
8387
+ try
8388
+ {
8389
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8390
+ }
8391
+ catch (Exception e)
8392
+ {
8393
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8394
+ }
8395
+
8396
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8397
+ bimtextures.put(texdata, texturecache);
8398
+
8399
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8400
+
8401
+ //Object bim2 = CreateBim(texturecache.texturedata);
8402
+ //bim2 = bim;
8403
+ }
8404
+ else
8405
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
82678406 {
82688407 assert(!bump);
82698408 // if (bump)
....@@ -8274,19 +8413,23 @@
82748413 // }
82758414 // else
82768415 // {
8277
- texture = textures.get(tex);
8278
- if (texture == null)
8416
+ // texturecache = textures.get(texname); // suspicious
8417
+ if (texturecache == null)
82798418 {
8280
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8419
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
82818420 }
8421
+ else
8422
+ new Exception().printStackTrace();
82828423 // }
82838424 } else
8284
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8425
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
82858426 {
82868427 assert(bump);
8287
- texture = textures.get(tex);
8288
- if (texture == null)
8289
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8428
+ // texturecache = textures.get(texname); // suspicious
8429
+ if (texturecache == null)
8430
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8431
+ else
8432
+ new Exception().printStackTrace();
82908433 } else
82918434 {
82928435 //if (tex.equals("IMMORTAL"))
....@@ -8294,11 +8437,22 @@
82948437 // texture = GetResourceTexture("default.png");
82958438 //} else
82968439 //{
8297
- if (tex.equals("WHITE_NOISE"))
8440
+ if (texname.endsWith("WHITE_NOISE"))
82988441 {
8299
- texture = textures.get(tex);
8300
- if (texture == null)
8301
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8442
+ // texturecache = textures.get(texname); // suspicious
8443
+ if (texturecache == null)
8444
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8445
+ else
8446
+ new Exception().printStackTrace();
8447
+ } else
8448
+ {
8449
+ if (texname.startsWith("@"))
8450
+ {
8451
+ // texturecache = textures.get(texname); // suspicious
8452
+ if (texturecache == null)
8453
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8454
+ else
8455
+ new Exception().printStackTrace();
83028456 } else
83038457 {
83048458 if (textureon)
....@@ -8357,19 +8511,20 @@
83578511 if (texturedata == null)
83588512 throw new Exception();
83598513
8360
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8514
+ texturecache = new CacheTexture(texturedata,resolution);
83618515 //texture = GetTexture(tex, bump);
83628516 }
8517
+ }
83638518 }
83648519 //}
83658520 }
83668521
8367
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8522
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
83688523 {
83698524 //return false;
83708525
83718526 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8372
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8527
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
83738528 {
83748529 // String ext = "_highres";
83758530 // if (REDUCETEXTURE)
....@@ -8386,52 +8541,17 @@
83868541 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
83878542 if (!cachefile.exists())
83888543 {
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))
8544
+ //if (texturedata.getWidth() == texturedata.getHeight())
83988545 {
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);
8546
+ BufferedImage rendImage = CreateBim(texturedata);
8547
+
84298548 ImageWriter writer = null;
84308549 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
84318550 if (iter.hasNext()) {
84328551 writer = (ImageWriter)iter.next();
84338552 }
8434
- float compressionQuality = 0.9f;
8553
+
8554
+ float compressionQuality = 0.85f;
84358555 try
84368556 {
84378557 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8448,18 +8568,20 @@
84488568 }
84498569 }
84508570 }
8451
-
8571
+
8572
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8573
+
84528574 //System.out.println("Texture = " + tex);
8453
- if (textures.containsKey(texname))
8575
+ if (textures.containsKey(tex))
84548576 {
8455
- CacheTexture thetex = textures.get(texname);
8577
+ CacheTexture thetex = textures.get(tex);
84568578 thetex.texture.disable();
84578579 thetex.texture.dispose();
8458
- textures.remove(texname);
8580
+ textures.remove(tex);
84598581 }
84608582
8461
- texture.texturedata = texturedata;
8462
- textures.put(texname, texture);
8583
+ //texture.texturedata = texturedata;
8584
+ textures.put(tex, texturecache);
84638585
84648586 // newtex = true;
84658587 }
....@@ -8475,10 +8597,44 @@
84758597 }
84768598 }
84778599
8478
- return texture;
8600
+ return texturecache;
84798601 }
84808602
8481
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution) throws Exception
8603
+ static void EmbedTextures(cTexture tex)
8604
+ {
8605
+ if (tex.pigmentdata == null)
8606
+ {
8607
+ //String texname = Object3D.GetPigment(tex);
8608
+
8609
+ CacheTexture texturecache = texturepigment.get(tex);
8610
+
8611
+ if (texturecache != null)
8612
+ {
8613
+ tex.pw = texturecache.texturedata.getWidth();
8614
+ tex.ph = texturecache.texturedata.getHeight();
8615
+ tex.pigmentdata = //CompressJPEG(CreateBim
8616
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8617
+ ;
8618
+ //, tex.pw, tex.ph), 0.5f);
8619
+ }
8620
+ }
8621
+
8622
+ if (tex.bumpdata == null)
8623
+ {
8624
+ //String texname = Object3D.GetBump(tex);
8625
+
8626
+ CacheTexture texturecache = texturebump.get(tex);
8627
+
8628
+ if (texturecache != null)
8629
+ {
8630
+ tex.bw = texturecache.texturedata.getWidth();
8631
+ tex.bh = texturecache.texturedata.getHeight();
8632
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8633
+ }
8634
+ }
8635
+ }
8636
+
8637
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
84828638 {
84838639 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
84848640
....@@ -8496,21 +8652,21 @@
84968652 return texture!=null?texture.texture:null;
84978653 }
84988654
8499
- public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution) throws Exception
8655
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
85008656 {
85018657 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
85028658
85038659 return texture!=null?texture.texturedata:null;
85048660 }
85058661
8506
- boolean BindTexture(String tex, boolean bump, int resolution) throws Exception
8662
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
85078663 {
85088664 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
85098665 {
85108666 return false;
85118667 }
85128668
8513
- boolean newtex = false;
8669
+ //boolean newtex = false;
85148670
85158671 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
85168672
....@@ -8542,9 +8698,75 @@
85428698 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
85438699 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
85448700
8545
- return newtex;
8701
+ return true; // Warning: not used.
85468702 }
85478703
8704
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8705
+ {
8706
+ try
8707
+ {
8708
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8709
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8710
+ ImageWriter writer = writers.next();
8711
+
8712
+ ImageWriteParam param = writer.getDefaultWriteParam();
8713
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8714
+ param.setCompressionQuality(quality);
8715
+
8716
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8717
+ writer.setOutput(ios);
8718
+ writer.write(null, new IIOImage(image, null, null), param);
8719
+
8720
+ byte[] data = baos.toByteArray();
8721
+ writer.dispose();
8722
+ return data;
8723
+ }
8724
+ catch (Exception e)
8725
+ {
8726
+ e.printStackTrace();
8727
+ return null;
8728
+ }
8729
+ }
8730
+
8731
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8732
+ {
8733
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8734
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8735
+ ImageReader reader = writers.next();
8736
+
8737
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8738
+
8739
+ ImageReadParam param = reader.getDefaultReadParam();
8740
+ param.setDestination(bim);
8741
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8742
+
8743
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8744
+ reader.setInput(ios);
8745
+ BufferedImage bim2 = reader.read(0, param);
8746
+ reader.dispose();
8747
+
8748
+// WritableRaster raster = bim2.getRaster();
8749
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8750
+// byte[] bytes = data.getData();
8751
+//
8752
+// int[] pixels = new int[bytes.length/3];
8753
+// for (int i=pixels.length; --i>=0;)
8754
+// {
8755
+// int i3 = i*3;
8756
+// pixels[i] = 0xFF;
8757
+// pixels[i] <<= 8;
8758
+// pixels[i] |= bytes[i3+2] & 0xFF;
8759
+// pixels[i] <<= 8;
8760
+// pixels[i] |= bytes[i3+1] & 0xFF;
8761
+// pixels[i] <<= 8;
8762
+// pixels[i] |= bytes[i3] & 0xFF;
8763
+// }
8764
+//
8765
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8766
+
8767
+ return bim;
8768
+ }
8769
+
85488770 ShadowBuffer shadowPBuf;
85498771 AntialiasBuffer antialiasPBuf;
85508772 int MAXSTACK;
....@@ -8561,10 +8783,12 @@
85618783
85628784 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
85638785 MAXSTACK = temp[0];
8564
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8786
+ if (Globals.DEBUG)
8787
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
85658788 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
85668789 MAXSTACK = temp[0];
8567
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8790
+ if (Globals.DEBUG)
8791
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
85688792
85698793 // Use debug pipeline
85708794 //drawable.setGL(new DebugGL(gl)); //
....@@ -8572,7 +8796,8 @@
85728796 gl = drawable.getGL(); //
85738797
85748798 GL gl3 = getGL();
8575
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8799
+ if (Globals.DEBUG)
8800
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
85768801
85778802
85788803 //float pos[] = { 100, 100, 100, 0 };
....@@ -8737,7 +8962,7 @@
87378962
87388963 if (cubemap == null)
87398964 {
8740
- LoadEnvy(5);
8965
+ //LoadEnvy(1);
87418966 }
87428967
87438968 //cubemap.enable();
....@@ -9013,6 +9238,8 @@
90139238
90149239 void LoadEnvy(int which)
90159240 {
9241
+ assert(false);
9242
+
90169243 String name;
90179244 String ext;
90189245
....@@ -9024,37 +9251,58 @@
90249251 cubemap = null;
90259252 return;
90269253 case 1:
9027
- name = "cubemaps/box_";
9028
- ext = "png";
9254
+ name = "cubemaps/rgb/";
9255
+ ext = "jpg";
90299256 reverseUP = false;
90309257 break;
90319258 case 2:
9032
- name = "cubemaps/uffizi_";
9033
- ext = "png";
9034
- break; // reverseUP = true; break;
9259
+ name = "cubemaps/uffizi/";
9260
+ ext = "jpg";
9261
+ reverseUP = false;
9262
+ break;
90359263 case 3:
9036
- name = "cubemaps/CloudyHills_";
9037
- ext = "tga";
9264
+ name = "cubemaps/CloudyHills/";
9265
+ ext = "jpg";
90389266 reverseUP = false;
90399267 break;
90409268 case 4:
9041
- name = "cubemaps/cornell_";
9269
+ name = "cubemaps/cornell/";
90429270 ext = "png";
90439271 reverseUP = false;
90449272 break;
9273
+ case 5:
9274
+ name = "cubemaps/skycube/";
9275
+ ext = "jpg";
9276
+ reverseUP = false;
9277
+ break;
9278
+ case 6:
9279
+ name = "cubemaps/SaintLazarusChurch3/";
9280
+ ext = "jpg";
9281
+ reverseUP = false;
9282
+ break;
9283
+ case 7:
9284
+ name = "cubemaps/Sodermalmsallen/";
9285
+ ext = "jpg";
9286
+ reverseUP = false;
9287
+ break;
9288
+ case 8:
9289
+ name = "cubemaps/Sodermalmsallen2/";
9290
+ ext = "jpg";
9291
+ reverseUP = false;
9292
+ break;
9293
+ case 9:
9294
+ name = "cubemaps/UnionSquare/";
9295
+ ext = "jpg";
9296
+ reverseUP = false;
9297
+ break;
90459298 default:
9046
- name = "cubemaps/rgb_";
9047
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9299
+ name = "cubemaps/box/";
9300
+ ext = "png"; /*mipmap = true;*/
9301
+ reverseUP = false;
90489302 break;
90499303 }
9050
-
9051
- try
9052
- {
9053
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
9054
- } catch (IOException e)
9055
- {
9056
- throw new RuntimeException(e);
9057
- }
9304
+
9305
+ LoadSkybox(name, ext, mipmap);
90589306 }
90599307
90609308 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -9086,8 +9334,12 @@
90869334 static double[] model = new double[16];
90879335 double[] camera2light = new double[16];
90889336 double[] light2camera = new double[16];
9089
- int newenvy = -1;
9090
- boolean envyoff = true; // false;
9337
+
9338
+ //int newenvy = -1;
9339
+ //boolean envyoff = false;
9340
+
9341
+ String loadedskyboxname;
9342
+
90919343 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
90929344 //float[] light0 = { 0,0,0 };
90939345 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9505,7 +9757,7 @@
95059757
95069758 if (renderCamera != lightCamera)
95079759 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9508
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
9760
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
95099761
95109762 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
95119763
....@@ -9521,7 +9773,7 @@
95219773
95229774 if (renderCamera != lightCamera)
95239775 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9524
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
9776
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
95259777
95269778 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
95279779
....@@ -9567,10 +9819,12 @@
95679819 rati = 1 / rati;
95689820 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
95699821 }
9570
- assert (newenvy == -1);
9822
+
9823
+ //assert (newenvy == -1);
9824
+
95719825 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
95729826 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9573
- DrawSkyBox(gl);
9827
+ DrawSkyBox(gl, (float)rati);
95749828 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
95759829 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
95769830 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10436,9 +10690,18 @@
1043610690 static boolean init = false;
1043710691
1043810692 double[][] matrix = LA.newMatrix();
10693
+
10694
+ // This is to refresh the UI of the material panel.
10695
+ ObjEditor patchMaterial;
1043910696
1044010697 public void display(GLAutoDrawable drawable)
1044110698 {
10699
+ if (patchMaterial.patchMaterial)
10700
+ {
10701
+ patchMaterial.patchMaterial = false;
10702
+ patchMaterial.objectPanel.setSelectedIndex(1);
10703
+ }
10704
+
1044210705 if (Grafreed.savesound && Grafreed.hassound)
1044310706 {
1044410707 Grafreed.wav.save();
....@@ -10607,7 +10870,7 @@
1060710870
1060810871 if (wait)
1060910872 {
10610
- Sleep(500);
10873
+ Sleep(200); // blocks everything
1061110874
1061210875 wait = false;
1061310876 }
....@@ -10722,7 +10985,7 @@
1072210985 // if (parentcam != renderCamera) // not a light
1072310986 if (cam != lightCamera)
1072410987 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10725
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
10988
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1072610989
1072710990 for (int j = 0; j < 4; j++)
1072810991 {
....@@ -10737,7 +11000,7 @@
1073711000 // if (parentcam != renderCamera) // not a light
1073811001 if (cam != lightCamera)
1073911002 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10740
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
11003
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1074111004
1074211005 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1074311006
....@@ -10823,13 +11086,43 @@
1082311086 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1082411087 }
1082511088
10826
- if (newenvy > -1)
11089
+// if (newenvy > -1)
11090
+// {
11091
+// LoadEnvy(newenvy);
11092
+// }
11093
+//
11094
+// newenvy = -1;
11095
+
11096
+ if (transformMode) // object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
1082711097 {
10828
- LoadEnvy(newenvy);
11098
+ if (cubemaprgb == null)
11099
+ {
11100
+ cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb2" + "/", "jpg", false);
11101
+ }
11102
+
11103
+ cubemap = cubemaprgb;
1082911104 }
10830
-
10831
- newenvy = -1;
10832
-
11105
+ else
11106
+ {
11107
+ if (object.skyboxname != null)
11108
+ {
11109
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11110
+ {
11111
+ if (cubemap != null && cubemap != cubemaprgb)
11112
+ cubemap.dispose();
11113
+ cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11114
+ loadedskyboxname = object.skyboxname;
11115
+ }
11116
+ }
11117
+ else
11118
+ {
11119
+ cubemapcustom = null;
11120
+ loadedskyboxname = null;
11121
+ }
11122
+
11123
+ cubemap = cubemapcustom;
11124
+ }
11125
+
1083311126 ratio = ((double) getWidth()) / getHeight();
1083411127 //System.out.println("ratio = " + ratio);
1083511128
....@@ -10845,7 +11138,7 @@
1084511138
1084611139 if (!IsFrozen() && !ambientOcclusion)
1084711140 {
10848
- DrawSkyBox(gl);
11141
+ DrawSkyBox(gl, (float)ratio);
1084911142 }
1085011143
1085111144 //if (selection_view == -1)
....@@ -11028,9 +11321,9 @@
1102811321
1102911322 gl.glMatrixMode(GL.GL_MODELVIEW);
1103011323
11031
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11032
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
11033
-//gl.glEnable(gl.GL_MULTISAMPLE);
11324
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11325
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11326
+gl.glEnable(gl.GL_MULTISAMPLE);
1103411327 } else
1103511328 {
1103611329 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -11041,7 +11334,7 @@
1104111334 //System.out.println("BLENDING ON");
1104211335 gl.glEnable(GL.GL_BLEND);
1104311336 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
11044
-
11337
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1104511338 gl.glMatrixMode(gl.GL_PROJECTION);
1104611339 gl.glLoadIdentity();
1104711340
....@@ -11131,7 +11424,7 @@
1113111424
1113211425 // if (cam != lightCamera)
1113311426 //for (int count = parentcam.GetTransformCount(); --count>=0;)
11134
- LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
11427
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1113511428 }
1113611429
1113711430 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -11290,7 +11583,7 @@
1129011583 }
1129111584 }
1129211585
11293
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11586
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1129411587 {
1129511588 //gl.glDepthFunc(GL.GL_LEQUAL);
1129611589 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11298,24 +11591,21 @@
1129811591
1129911592 boolean texon = textureon;
1130011593
11301
- if (RENDERPROGRAM > 0)
11302
- {
11303
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11304
- textureon = false;
11305
- }
11594
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11595
+ textureon = false;
11596
+
1130611597 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1130711598 //System.out.println("ALLO");
1130811599 gl.glColorMask(false, false, false, false);
1130911600 DrawObject(gl);
11310
- if (RENDERPROGRAM > 0)
11311
- {
11312
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11313
- textureon = texon;
11314
- }
11601
+
11602
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11603
+ textureon = texon;
11604
+
1131511605 gl.glColorMask(true, true, true, true);
1131611606
1131711607 gl.glDepthFunc(GL.GL_EQUAL);
11318
- //gl.glDepthMask(false);
11608
+ gl.glDepthMask(false);
1131911609 }
1132011610
1132111611 if (false) // DrawMode() == SHADOW)
....@@ -11527,7 +11817,7 @@
1152711817 if ((TRACK || SHADOWTRACK) || zoomonce)
1152811818 {
1152911819 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11530
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11820
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1153111821 pingthread.StepToTarget(true); // true);
1153211822 // zoomonce = false;
1153311823 }
....@@ -11655,20 +11945,32 @@
1165511945 ReleaseTextures(DEFAULT_TEXTURES);
1165611946
1165711947 if (CLEANCACHE)
11658
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11948
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1165911949 {
11660
- String tex = e.nextElement();
11950
+ cTexture tex = e.nextElement();
1166111951
1166211952 // System.out.println("Texture --------- " + tex);
1166311953
11664
- if (tex.equals("WHITE_NOISE"))
11954
+ if (tex.equals("WHITE_NOISE:"))
1166511955 continue;
1166611956
11667
- if (!usedtextures.containsKey(tex))
11957
+ if (!usedtextures.contains(tex))
1166811958 {
11959
+ CacheTexture gettex = texturepigment.get(tex);
1166911960 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11670
- textures.get(tex).texture.dispose();
11671
- textures.remove(tex);
11961
+ if (gettex != null)
11962
+ {
11963
+ gettex.texture.dispose();
11964
+ texturepigment.remove(tex);
11965
+ }
11966
+
11967
+ gettex = texturebump.get(tex);
11968
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11969
+ if (gettex != null)
11970
+ {
11971
+ gettex.texture.dispose();
11972
+ texturebump.remove(tex);
11973
+ }
1167211974 }
1167311975 }
1167411976 }
....@@ -12196,8 +12498,76 @@
1219612498
1219712499 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1219812500
12199
- String program =
12501
+ String programmin =
12502
+ // Min shader
1220012503 "!!ARBfp1.0\n" +
12504
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12505
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12506
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12507
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12508
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12509
+ "PARAM light2cam0 = program.env[10];" +
12510
+ "PARAM light2cam1 = program.env[11];" +
12511
+ "PARAM light2cam2 = program.env[12];" +
12512
+ "TEMP temp;" +
12513
+ "TEMP light;" +
12514
+ "TEMP ndotl;" +
12515
+ "TEMP normal;" +
12516
+ "TEMP depth;" +
12517
+ "TEMP eye;" +
12518
+ "TEMP pos;" +
12519
+
12520
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12521
+ Normalize("normal") +
12522
+ "MOV light, state.light[0].position;" +
12523
+ "DP3 ndotl.x, light, normal;" +
12524
+
12525
+ // shadow
12526
+ "MOV pos, fragment.texcoord[1];" +
12527
+ "MOV temp, pos;" +
12528
+ ShadowTextureFetch("depth", "temp", "1") +
12529
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12530
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12531
+
12532
+ // No shadow when out of frustum
12533
+ //"SGE temp.y, depth.z, zero123.y;" +
12534
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12535
+
12536
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12537
+
12538
+ // Backlit
12539
+ "MOV pos.w, zero123.y;" +
12540
+ "DP4 eye.x, pos, light2cam0;" +
12541
+ "DP4 eye.y, pos, light2cam1;" +
12542
+ "DP4 eye.z, pos, light2cam2;" +
12543
+ Normalize("eye") +
12544
+
12545
+ "DP3 ndotl.y, -eye, normal;" +
12546
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12547
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12548
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12549
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12550
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12551
+
12552
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12553
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12554
+
12555
+ // Pigment
12556
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12557
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12558
+ "MUL temp, temp, ndotl.x;" +
12559
+
12560
+ "MUL temp, temp, zero123.z;" +
12561
+
12562
+ //"MUL temp, temp, ndotl.y;" +
12563
+
12564
+ "MOV temp.w, zero123.y;" + // reset alpha
12565
+ "MOV result.color, temp;" +
12566
+ "END";
12567
+
12568
+ String programmax =
12569
+ "!!ARBfp1.0\n" +
12570
+
1220112571 //"OPTION ARB_fragment_program_shadow;" +
1220212572 "PARAM light2cam0 = program.env[10];" +
1220312573 "PARAM light2cam1 = program.env[11];" +
....@@ -12223,7 +12593,7 @@
1222312593 "PARAM params4 = program.env[4];" + // anisoV, cameralight, selfshadow, shadow
1222412594 "PARAM params5 = program.env[5];" + // texture, opacity, fakedepth, shadowbias
1222512595 "PARAM params6 = program.env[6];" + // bump, noise, borderfade, fog punchthrough
12226
- "PARAM params7 = program.env[7];" + // noise power, opacity power
12596
+ "PARAM params7 = program.env[7];" + // noise power, opacity power, parallax
1222712597 "PARAM options0 = program.env[63];" + // fog density, intensity, elevation
1222812598 "PARAM options1 = program.env[62];" + // fog rgb color
1222912599 "PARAM options2 = program.env[61];" + // image intensity, subsurface, lightsheen
....@@ -12312,8 +12682,7 @@
1231212682 "TEMP shininess;" +
1231312683 "\n" +
1231412684 "MOV texSamp, one;" +
12315
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12316
-
12685
+
1231712686 "MOV mapgrid.x, one2048th.x;" +
1231812687 "MOV temp, fragment.texcoord[1];" +
1231912688 /*
....@@ -12334,20 +12703,20 @@
1233412703 "MUL temp, floor, mapgrid.x;" +
1233512704 //"TEX depth0, temp, texture[1], 2D;" +
1233612705 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12337
- TextureFetch("depth0", "temp", "1") +
12706
+ ShadowTextureFetch("depth0", "temp", "1") +
1233812707 "") +
1233912708 "ADD temp.x, temp.x, mapgrid.x;" +
1234012709 //"TEX depth1, temp, texture[1], 2D;" +
1234112710 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12342
- TextureFetch("depth1", "temp", "1") +
12711
+ ShadowTextureFetch("depth1", "temp", "1") +
1234312712 "") +
1234412713 "ADD temp.y, temp.y, mapgrid.x;" +
1234512714 //"TEX depth2, temp, texture[1], 2D;" +
12346
- TextureFetch("depth2", "temp", "1") +
12715
+ ShadowTextureFetch("depth2", "temp", "1") +
1234712716 "SUB temp.x, temp.x, mapgrid.x;" +
1234812717 //"TEX depth3, temp, texture[1], 2D;" +
1234912718 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12350
- TextureFetch("depth3", "temp", "1") +
12719
+ ShadowTextureFetch("depth3", "temp", "1") +
1235112720 "") +
1235212721 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1235312722 //"MOV params, material;" +
....@@ -12469,7 +12838,7 @@
1246912838 "POW texSamp.a, texSamp.a, params6.w;" + // fog punch through shortcut
1247012839 // mar 2013 ??? "KIL alpha.a;" +
1247112840 "MOV alpha, texSamp.aaaa;" + // y;" +
12472
- "KIL alpha.a;" +
12841
+ "KIL alpha.a;" + // not sure with parallax mapping
1247312842 /*
1247412843 "MUL temp.xy, temp, two;" +
1247512844 "TXB bump, temp, texture[0], 2D;" +
....@@ -12555,11 +12924,6 @@
1255512924 "SUB bump0, bump0, half;" +
1255612925 "ADD bump, bump, bump0;" +
1255712926
12558
- "MOV temp.x, texSamp.a;" +
12559
- "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
12560
- //"LRP texSamp0, params5.x, texSamp0, one;" +
12561
- "MOV texSamp.a, temp.x;" +
12562
-
1256312927 // double-sided
1256412928 /**/
1256512929 (doublesided?"DP3 temp.z, normal, eye;" +
....@@ -12589,6 +12953,41 @@
1258912953 Normalize("U") +
1259012954
1259112955 // parallax mapping
12956
+
12957
+ "DP3 temp2.x, V, eye;" +
12958
+ "DP3 temp2.y, U, eye;" +
12959
+ "DP3 temp2.z, normal, eye;" +
12960
+ "RCP temp2.z, temp2.z;" +
12961
+
12962
+ "DP3 temp2.w, texSamp, texSamp;" + // Height
12963
+ "RSQ temp2.w, temp2.w;" +
12964
+ "RCP temp2.w, temp2.w;" +
12965
+
12966
+ "SUB temp2.w, temp2.w, half;" +
12967
+// "SGE temp.x, temp2.w, eps.x;" +
12968
+// "MUL temp2.w, temp2.w, temp.x;" +
12969
+
12970
+ //"MOV texSamp, U;" +
12971
+
12972
+ "MUL temp2.z, temp2.z, temp2.w;" +
12973
+ "MUL temp2.z, temp2.z, params7.z;" + // parallax
12974
+
12975
+ "MUL temp2, temp2, temp2.z;" +
12976
+
12977
+ "MOV temp, fragment.texcoord[0];" +
12978
+
12979
+ "SUB temp, temp, temp2;" +
12980
+
12981
+ "TEX texSamp, temp, texture[0], 2D;" +
12982
+ "POW texSamp.a, texSamp.a, params6.w;" + // punch through
12983
+ "MOV alpha, texSamp.aaaa;" +
12984
+
12985
+// parallax mapping
12986
+
12987
+ "MOV temp.x, texSamp.a;" +
12988
+ "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
12989
+ //"LRP texSamp0, params5.x, texSamp0, one;" +
12990
+ "MOV texSamp.a, temp.x;" +
1259212991
1259312992 //"MOV temp, fragment.texcoord[0];" +
1259412993 //
....@@ -12718,10 +13117,10 @@
1271813117 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1271913118 "") +
1272013119
12721
- // display shadow only (bump == 0)
13120
+ // display shadow only (fakedepth == 0)
1272213121 "SUB temp.x, half.x, shadow.x;" +
1272313122 "MOV temp.y, -params5.z;" + // params6.x;" +
12724
- "SLT temp.z, temp.y, -one2048th.x;" +
13123
+ "SLT temp.z, temp.y, -c256i.x;" +
1272513124 "SUB temp.y, one.x, temp.z;" +
1272613125 "MUL temp.x, temp.x, temp.y;" +
1272713126 "KIL temp.x;" +
....@@ -13052,8 +13451,19 @@
1305213451 //once = true;
1305313452 }
1305413453
13055
- System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13056
- System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13454
+ String program = programmax;
13455
+
13456
+ if (Globals.MINSHADER)
13457
+ {
13458
+ program = programmin;
13459
+ }
13460
+
13461
+ if (Globals.DEBUG)
13462
+ {
13463
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13464
+ System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13465
+ }
13466
+
1305713467 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1305813468
1305913469 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -13100,7 +13510,8 @@
1310013510 "\n" +
1310113511 "END\n";
1310213512
13103
- System.out.println("Program shadow #" + 0 + "; length = " + program.length());
13513
+ if (Globals.DEBUG)
13514
+ System.out.println("Program shadow #" + 0 + "; length = " + program.length());
1310413515 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1310513516
1310613517 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -13145,25 +13556,26 @@
1314513556 return out;
1314613557 }
1314713558
13148
- String TextureFetch(String dest, String src, String unit)
13559
+ // Also does frustum culling
13560
+ String ShadowTextureFetch(String dest, String src, String unit)
1314913561 {
1315013562 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1315113563 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1315213564 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13565
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13566
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1315313567 "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;" +
13568
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13569
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1315813570 //"SWZ buffer, temp, w,w,w,w;";
13159
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13571
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1316013572 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1316113573 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1316213574 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13163
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13575
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1316413576
13165
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13166
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13577
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13578
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1316713579 }
1316813580
1316913581 String Shadow(String depth, String shadow)
....@@ -13210,7 +13622,7 @@
1321013622 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1321113623 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1321213624
13213
- // No shadow when out of frustrum
13625
+ // No shadow when out of frustum
1321413626 "SGE temp.x, " + depth + ".z, one.z;" +
1321513627 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1321613628 "";
....@@ -13357,7 +13769,7 @@
1335713769 /*static*/ float[] modelParams4 = new float[]{0, 0, 0, 0}; // anisoV, cameralight, selfshadow, shadow
1335813770 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1335913771 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
13360
- /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13772
+ /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power, parallax
1336113773
1336213774 //Object3D.cVector2[] vector2buffer;
1336313775
....@@ -13375,9 +13787,10 @@
1337513787 "DP3 " + dest + ".z," + "normals," + "eye;" +
1337613788 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1337713789 //"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;" +
13790
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13791
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13792
+
13793
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1338113794 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1338213795 "RCP " + dest + ".w," + dest + ".w;" +
1338313796 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -13942,7 +14355,7 @@
1394214355
1394314356 // fev 2014???
1394414357 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13945
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14358
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1394614359 pingthread.StepToTarget(true); // true);
1394714360 }
1394814361 // if (!LIVE)
....@@ -14007,14 +14420,15 @@
1400714420 drag = false;
1400814421 //System.out.println("Mouse DOWN");
1400914422 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);
14423
+ //ClickInfo info = new ClickInfo();
14424
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14425
+ object.clickInfo.pane = this;
14426
+ object.clickInfo.camera = renderCamera;
14427
+ object.clickInfo.x = x;
14428
+ object.clickInfo.y = y;
14429
+ object.clickInfo.modifiers = modifiersex;
14430
+ editObj = object.doEditClick(//info,
14431
+ 0);
1401814432 if (!editObj)
1401914433 {
1402014434 hasMarquee = true;
....@@ -14296,12 +14710,18 @@
1429614710 void GoDown(int mod)
1429714711 {
1429814712 MODIFIERS |= COMMAND;
14299
- /*
14713
+ boolean isVR = (mouseMode&VR)!=0;
14714
+ /**/
1430014715 if((mod&SHIFT) == SHIFT)
14301
- manipCamera.RotatePosition(0, -speed);
14716
+ {
14717
+ if (isVR)
14718
+ manipCamera.RotateInterest(0, -speed);
14719
+ else
14720
+ manipCamera.RotatePosition(0, -speed);
14721
+ }
1430214722 else
14303
- manipCamera.BackForth(0, -speed*delta, getWidth());
14304
- */
14723
+ manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth());
14724
+ /**/
1430514725 if ((mod & SHIFT) == SHIFT)
1430614726 {
1430714727 mouseMode = mouseMode; // VR??
....@@ -14310,6 +14730,8 @@
1431014730 mouseMode |= BACKFORTH;
1431114731 }
1431214732
14733
+ targetLookAt.set(manipCamera.lookAt);
14734
+
1431314735 //prevX = X = anchorX;
1431414736 prevY = Y = anchorY - (int) (renderCamera.Distance());
1431514737 }
....@@ -14317,12 +14739,19 @@
1431714739 void GoUp(int mod)
1431814740 {
1431914741 MODIFIERS |= COMMAND;
14320
- /*
14742
+ /**/
14743
+ boolean isVR = (mouseMode&VR)!=0;
14744
+
1432114745 if((mod&SHIFT) == SHIFT)
14322
- manipCamera.RotatePosition(0, speed);
14746
+ {
14747
+ if (isVR)
14748
+ manipCamera.RotateInterest(0, speed);
14749
+ else
14750
+ manipCamera.RotatePosition(0, speed);
14751
+ }
1432314752 else
14324
- manipCamera.BackForth(0, speed*delta, getWidth());
14325
- */
14753
+ manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth());
14754
+ /**/
1432614755 if ((mod & SHIFT) == SHIFT)
1432714756 {
1432814757 mouseMode = mouseMode;
....@@ -14331,6 +14760,8 @@
1433114760 mouseMode |= BACKFORTH;
1433214761 }
1433314762
14763
+ targetLookAt.set(manipCamera.lookAt);
14764
+
1433414765 //prevX = X = anchorX;
1433514766 prevY = Y = anchorY + (int) (renderCamera.Distance());
1433614767 }
....@@ -14338,12 +14769,17 @@
1433814769 void GoLeft(int mod)
1433914770 {
1434014771 MODIFIERS |= COMMAND;
14341
- /*
14772
+ /**/
1434214773 if((mod&SHIFT) == SHIFT)
14343
- manipCamera.RotatePosition(speed, 0);
14774
+ manipCamera.Translate(speed*delta, 0, getWidth());
1434414775 else
14345
- manipCamera.Translate(speed*delta, 0, getWidth());
14346
- */
14776
+ {
14777
+ if ((mouseMode&VR)!=0)
14778
+ manipCamera.RotateInterest(-speed, 0);
14779
+ else
14780
+ manipCamera.RotatePosition(speed, 0);
14781
+ }
14782
+ /**/
1434714783 if ((mod & SHIFT) == SHIFT)
1434814784 {
1434914785 mouseMode = mouseMode;
....@@ -14352,6 +14788,8 @@
1435214788 mouseMode |= ROTATE;
1435314789 } // TRANSLATE;
1435414790
14791
+ targetLookAt.set(manipCamera.lookAt);
14792
+
1435514793 prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance());
1435614794 prevY = Y = anchorY;
1435714795 }
....@@ -14359,12 +14797,18 @@
1435914797 void GoRight(int mod)
1436014798 {
1436114799 MODIFIERS |= COMMAND;
14362
- /*
14800
+ /**/
1436314801 if((mod&SHIFT) == SHIFT)
14364
- manipCamera.RotatePosition(-speed, 0);
14802
+ manipCamera.Translate(-speed*delta, 0, getWidth());
1436514803 else
14366
- manipCamera.Translate(-speed*delta, 0, getWidth());
14367
- */
14804
+ {
14805
+ if ((mouseMode&VR)!=0)
14806
+ manipCamera.RotateInterest(speed, 0);
14807
+ else
14808
+ manipCamera.RotatePosition(-speed, 0);
14809
+ }
14810
+
14811
+ /**/
1436814812 if ((mod & SHIFT) == SHIFT)
1436914813 {
1437014814 mouseMode = mouseMode;
....@@ -14373,6 +14817,8 @@
1437314817 mouseMode |= ROTATE;
1437414818 } // TRANSLATE;
1437514819
14820
+ targetLookAt.set(manipCamera.lookAt);
14821
+
1437614822 prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance());
1437714823 prevY = Y = anchorY;
1437814824 }
....@@ -14414,15 +14860,16 @@
1441414860 if (editObj)
1441514861 {
1441614862 drag = true;
14417
- ClickInfo info = new ClickInfo();
14418
- info.bounds.setBounds(0, 0,
14863
+ //ClickInfo info = new ClickInfo();
14864
+ object.clickInfo.bounds.setBounds(0, 0,
1441914865 (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);
14866
+ object.clickInfo.pane = this;
14867
+ object.clickInfo.camera = renderCamera;
14868
+ object.clickInfo.x = x;
14869
+ object.clickInfo.y = y;
14870
+ object //.GetWindow().copy
14871
+ .doEditDrag(//info,
14872
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1442614873 } else
1442714874 {
1442814875 if (x < startX)
....@@ -14571,24 +15018,27 @@
1457115018 }
1457215019 }
1457315020
15021
+// ClickInfo clickInfo = new ClickInfo();
15022
+
1457415023 public void mouseMoved(MouseEvent e)
1457515024 {
1457615025 //System.out.println("mouseMoved: " + e);
1457715026 if (isRenderer)
1457815027 return;
1457915028
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;
15029
+ // Mouse cursor feedback
15030
+ object.clickInfo.x = e.getX();
15031
+ object.clickInfo.y = e.getY();
15032
+ object.clickInfo.modifiers = e.getModifiersEx();
15033
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
15034
+ object.clickInfo.pane = this;
15035
+ object.clickInfo.camera = renderCamera;
1458715036 if (!isRenderer)
1458815037 {
1458915038 //ObjEditor editWindow = object.editWindow;
1459015039 //Object3D copy = editWindow.copy;
14591
- if (object.doEditClick(ci, 0))
15040
+ if (object.doEditClick(//clickInfo,
15041
+ 0))
1459215042 {
1459315043 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1459415044 } else
....@@ -14603,7 +15053,8 @@
1460315053 Globals.MOUSEDRAGGED = false;
1460415054
1460515055 movingcamera = false;
14606
- X = Y = 0;
15056
+ X = 0; // getBounds().width/2;
15057
+ Y = 0; // getBounds().height/2;
1460715058 //System.out.println("mouseReleased: " + e);
1460815059 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1460915060 }
....@@ -14859,7 +15310,8 @@
1485915310 // break;
1486015311 case 'T':
1486115312 CACHETEXTURE ^= true;
14862
- textures.clear();
15313
+ texturepigment.clear();
15314
+ texturebump.clear();
1486315315 // repaint();
1486415316 break;
1486515317 case 'Y':
....@@ -14869,8 +15321,8 @@
1486915321 case 'K':
1487015322 KOMPACTTEXTURE ^= true;
1487115323 //textures.clear();
14872
- break;
14873
- case 'P': // Texture Projection macros
15324
+ // break;
15325
+ //case 'P': // Texture Projection macros
1487415326 // SAVETEXTURE ^= true;
1487515327 macromode = true;
1487615328 Udebug = Vdebug = NORMALdebug = false; programInitialized = false;
....@@ -14944,7 +15396,9 @@
1494415396 case 'E' : COMPACT ^= true;
1494515397 repaint();
1494615398 break;
14947
- case 'W' : DEBUGHSB ^= true;
15399
+ case 'W' : // Wide Window (fullscreen)
15400
+ //DEBUGHSB ^= true;
15401
+ ObjEditor.theFrame.ToggleFullScreen();
1494815402 repaint();
1494915403 break;
1495015404 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14970,13 +15424,7 @@
1497015424 repaint();
1497115425 break;
1497215426 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':
15427
+ //case 'L':
1498015428 if (lightMode)
1498115429 {
1498215430 lightMode = false;
....@@ -14995,7 +15443,7 @@
1499515443 targetLookAt.set(manipCamera.lookAt);
1499615444 repaint();
1499715445 break;
14998
- case 'p':
15446
+ case 'P': // p':
1499915447 // c'est quoi ca au juste? spherical ^= true;
1500015448 Skinshader ^= true; programInitialized = false;
1500115449 repaint();
....@@ -15040,20 +15488,24 @@
1504015488 OCCLUSION_CULLING ^= true;
1504115489 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1504215490 break;
15043
- case '0': envyoff ^= true; repaint(); break;
15491
+ //case '0': envyoff ^= true; repaint(); break;
1504415492 case '1':
1504515493 case '2':
1504615494 case '3':
1504715495 case '4':
1504815496 case '5':
15049
- newenvy = Character.getNumericValue(key);
15050
- repaint();
15051
- break;
1505215497 case '6':
1505315498 case '7':
1505415499 case '8':
1505515500 case '9':
15056
- BGcolor = (key - '6')/3.f;
15501
+ if (true) // envyoff)
15502
+ {
15503
+ BGcolor = (key - '1')/8.f;
15504
+ }
15505
+ else
15506
+ {
15507
+ //newenvy = Character.getNumericValue(key);
15508
+ }
1505715509 repaint();
1505815510 break;
1505915511 case '!':
....@@ -15119,11 +15571,14 @@
1511915571 case '_':
1512015572 kompactbit = 5;
1512115573 break;
15122
- case '+':
15123
- kompactbit = 6;
15124
- break;
15574
+// case '+':
15575
+// kompactbit = 6;
15576
+// break;
1512515577 case ' ':
15126
- ObjEditor.theFrame.ToggleFullScreen();
15578
+ lightMode ^= true;
15579
+ Globals.lighttouched = true;
15580
+ manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
15581
+ targetLookAt.set(manipCamera.lookAt);
1512715582 repaint();
1512815583 break;
1512915584 //case '`' :
....@@ -15170,8 +15625,9 @@
1517015625 case DELETE:
1517115626 ClearSelection();
1517215627 break;
15173
- /*
1517415628 case '+':
15629
+
15630
+ /*
1517515631 //fontsize += 1;
1517615632 bbzoom *= 2;
1517715633 repaint();
....@@ -15188,17 +15644,17 @@
1518815644 case '=':
1518915645 IncDepth();
1519015646 //fontsize += 1;
15191
- object.editWindow.refreshContents(true);
15647
+ object.GetWindow().refreshContents(true);
1519215648 maskbit = 6;
1519315649 break;
1519415650 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1519515651 DecDepth();
1519615652 maskbit = 5;
1519715653 //if(fontsize > 1) fontsize -= 1;
15198
- if (object.editWindow == null)
15199
- new Exception().printStackTrace();
15200
- else
15201
- object.editWindow.refreshContents(true);
15654
+// if (object.editWindow == null)
15655
+// new Exception().printStackTrace();
15656
+// else
15657
+ object.GetWindow().refreshContents(true);
1520215658 break;
1520315659 case '{':
1520415660 manipCamera.shaper_fovy /= 1.1;
....@@ -15422,7 +15878,7 @@
1542215878 }
1542315879 */
1542415880
15425
- object.editWindow.EditSelection(false);
15881
+ object.GetWindow().EditSelection(false);
1542615882 }
1542715883
1542815884 void SelectParent()
....@@ -15439,10 +15895,10 @@
1543915895 {
1544015896 //selectees.remove(i);
1544115897 System.out.println("select parent of " + elem);
15442
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15898
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1544315899 } else
1544415900 {
15445
- group.editWindow.Select(elem.GetTreePath(), first, true);
15901
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1544615902 }
1544715903
1544815904 first = false;
....@@ -15484,12 +15940,12 @@
1548415940 for (int j = 0; j < group.children.size(); j++)
1548515941 {
1548615942 elem = (Object3D) group.children.elementAt(j);
15487
- object.editWindow.Select(elem.GetTreePath(), first, true);
15943
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1548815944 first = false;
1548915945 }
1549015946 } else
1549115947 {
15492
- object.editWindow.Select(elem.GetTreePath(), first, true);
15948
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1549315949 }
1549415950
1549515951 first = false;
....@@ -15500,21 +15956,21 @@
1550015956 {
1550115957 //Composite group = (Composite) object;
1550215958 Object3D group = object;
15503
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15959
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1550415960 }
1550515961
1550615962 void ResetTransform(int mask)
1550715963 {
1550815964 //Composite group = (Composite) object;
1550915965 Object3D group = object;
15510
- group.editWindow.ResetTransform(mask);
15966
+ group.GetWindow().ResetTransform(mask);
1551115967 }
1551215968
1551315969 void FlipTransform()
1551415970 {
1551515971 //Composite group = (Composite) object;
1551615972 Object3D group = object;
15517
- group.editWindow.FlipTransform();
15973
+ group.GetWindow().FlipTransform();
1551815974 // group.editWindow.ReduceMesh(true);
1551915975 }
1552015976
....@@ -15522,7 +15978,7 @@
1552215978 {
1552315979 //Composite group = (Composite) object;
1552415980 Object3D group = object;
15525
- group.editWindow.PrintMemory();
15981
+ group.GetWindow().PrintMemory();
1552615982 // group.editWindow.ReduceMesh(true);
1552715983 }
1552815984
....@@ -15530,7 +15986,7 @@
1553015986 {
1553115987 //Composite group = (Composite) object;
1553215988 Object3D group = object;
15533
- group.editWindow.ResetCentroid();
15989
+ group.GetWindow().ResetCentroid();
1553415990 }
1553515991
1553615992 void IncDepth()
....@@ -15612,8 +16068,6 @@
1561216068
1561316069 int width = getBounds().width;
1561416070 int height = getBounds().height;
15615
- ClickInfo info = new ClickInfo();
15616
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1561716071 //Image img = CreateImage(width, height);
1561816072 //System.out.println("width = " + width + "; height = " + height + "\n");
1561916073
....@@ -15690,48 +16144,77 @@
1569016144 }
1569116145 if (object != null && !hasMarquee)
1569216146 {
16147
+ if (object.clickInfo == null)
16148
+ object.clickInfo = new ClickInfo();
16149
+ ClickInfo info = object.clickInfo;
16150
+ //ClickInfo info = new ClickInfo();
16151
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16152
+
1569316153 if (isRenderer)
1569416154 {
15695
- info.flags++;
16155
+ object.clickInfo.flags++;
1569616156 double frameAspect = (double) width / (double) height;
1569716157 if (frameAspect > renderCamera.aspect)
1569816158 {
1569916159 int desired = (int) ((double) height * renderCamera.aspect);
15700
- info.bounds.width -= width - desired;
15701
- info.bounds.x += (width - desired) / 2;
16160
+ object.clickInfo.bounds.width -= width - desired;
16161
+ object.clickInfo.bounds.x += (width - desired) / 2;
1570216162 } else
1570316163 {
1570416164 int desired = (int) ((double) width / renderCamera.aspect);
15705
- info.bounds.height -= height - desired;
15706
- info.bounds.y += (height - desired) / 2;
16165
+ object.clickInfo.bounds.height -= height - desired;
16166
+ object.clickInfo.bounds.y += (height - desired) / 2;
1570716167 }
1570816168 }
15709
- info.g = gr;
15710
- info.camera = renderCamera;
16169
+
16170
+ object.clickInfo.g = gr;
16171
+ object.clickInfo.camera = renderCamera;
1571116172 /*
1571216173 // Memory intensive (brep.verticescopy)
1571316174 if (!(object instanceof Composite))
1571416175 object.draw(info, 0, false); // SLOW :
1571516176 */
15716
- if (!isRenderer)
16177
+ if (!isRenderer) // && drag)
1571716178 {
15718
- object.drawEditHandles(info, 0);
15719
-
15720
- if (drag && (X != 0 || Y != 0) && object.selection.Size() > 0)
16179
+ Grafreed.Assert(object != null);
16180
+ Grafreed.Assert(object.selection != null);
16181
+ if (object.selection.Size() > 0)
1572116182 {
15722
- switch (object.selection.get(0).hitSomething)
16183
+ int hitSomething = object.selection.get(0).hitSomething;
16184
+
16185
+ object.clickInfo.DX = 0;
16186
+ object.clickInfo.DY = 0;
16187
+ object.clickInfo.W = 1;
16188
+ if (hitSomething == Object3D.hitCenter)
1572316189 {
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;
16190
+ info.DX = X;
16191
+ if (X != 0)
16192
+ info.DX -= info.bounds.width/2;
16193
+
16194
+ info.DY = Y;
16195
+ if (Y != 0)
16196
+ info.DY -= info.bounds.height/2;
1573316197 }
15734
-
16198
+
16199
+ object.drawEditHandles(//info,
16200
+ 0);
16201
+
16202
+ if (drag && (X != 0 || Y != 0))
16203
+ {
16204
+ switch (hitSomething)
16205
+ {
16206
+ case Object3D.hitCenter: gr.setColor(Color.white);
16207
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16208
+ break;
16209
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16210
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16211
+ break;
16212
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16213
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16214
+ break;
16215
+ }
16216
+
16217
+ }
1573516218 }
1573616219 }
1573716220 }
....@@ -15746,7 +16229,7 @@
1574616229 if (hasMarquee)
1574716230 {
1574816231 gr.setXORMode(Color.white);
15749
- gr.setColor(Color.red);
16232
+ gr.setColor(Color.white);
1575016233 if (!firstime)
1575116234 {
1575216235 gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH);
....@@ -16213,6 +16696,8 @@
1621316696 private /*static*/ boolean firstime;
1621416697 private /*static*/ cVector newView = new cVector();
1621516698 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16699
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16700
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1621616701 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1621716702 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1621816703 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16225,29 +16710,67 @@
1622516710 {
1622616711 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1622716712
16713
+ int usedsuf = 0;
16714
+
1622816715 for (int i = 0; i < suffixes.length; i++)
1622916716 {
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)
16717
+ String[] suffixe = suffixes;
16718
+ String[] fallback = suffixes2;
16719
+ String[] fallfallback = suffixes3;
16720
+
16721
+ for (int c=usedsuf; --c>=0;)
1623516722 {
16236
- throw new IOException("Unable to load texture " + resourceName);
16723
+// String[] temp = suffixe;
16724
+// suffixe = fallback;
16725
+// fallback = fallfallback;
16726
+// fallfallback = temp;
1623716727 }
16728
+
16729
+ String resourceName = basename + suffixe[i] + "." + suffix;
16730
+ TextureData data;
16731
+
16732
+ try
16733
+ {
16734
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16735
+ mipmapped,
16736
+ FileUtil.getFileSuffix(resourceName));
16737
+ }
16738
+ catch (Exception e)
16739
+ {
16740
+ try
16741
+ {
16742
+ resourceName = basename + fallback[i] + "." + suffix;
16743
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16744
+ mipmapped,
16745
+ FileUtil.getFileSuffix(resourceName));
16746
+ }
16747
+ catch (Exception e2)
16748
+ {
16749
+ resourceName = basename + fallfallback[i] + "." + suffix;
16750
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16751
+ mipmapped,
16752
+ FileUtil.getFileSuffix(resourceName));
16753
+ }
16754
+ }
16755
+
1623816756 //System.out.println("Target = " + targets[i]);
1623916757 cubemap.updateImage(data, targets[i]);
1624016758 }
1624116759
1624216760 return cubemap;
1624316761 }
16762
+
1624416763 int bigsphere = -1;
1624516764
1624616765 float BGcolor = 0.5f;
1624716766
16248
- private void DrawSkyBox(GL gl)
16767
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16768
+
16769
+ private void DrawSkyBox(GL gl, float ratio)
1624916770 {
16250
- if (envyoff || cubemap == null)
16771
+ if (//envyoff ||
16772
+ WIREFRAME ||
16773
+ cubemap == null)
1625116774 {
1625216775 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1625316776 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16262,7 +16785,17 @@
1626216785 // Compensates for ExaminerViewer's modification of modelview matrix
1626316786 gl.glMatrixMode(GL.GL_MODELVIEW);
1626416787 gl.glLoadIdentity();
16788
+ gl.glScalef(1,ratio,1);
1626516789
16790
+// colorV[0] = 2;
16791
+// colorV[1] = 2;
16792
+// colorV[2] = 2;
16793
+// colorV[3] = 1;
16794
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16795
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16796
+//
16797
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16798
+
1626616799 //gl.glActiveTexture(GL.GL_TEXTURE1);
1626716800 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1626816801
....@@ -16294,6 +16827,7 @@
1629416827 {
1629516828 gl.glScalef(1.0f, -1.0f, 1.0f);
1629616829 }
16830
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1629716831 gl.glMultMatrixd(viewrot_1, 0);
1629816832 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1629916833 //viewer.updateInverseRotation(gl);
....@@ -16334,7 +16868,8 @@
1633416868 gl.glDisable(GL.GL_TEXTURE_GEN_R);
1633516869
1633616870 cubemap.disable();
16337
- ////cubemap.unbind();
16871
+ //cubemap.dispose();
16872
+
1633816873 if (CULLFACE)
1633916874 {
1634016875 gl.glEnable(gl.GL_CULL_FACE);
....@@ -16529,6 +17064,14 @@
1652917064 }
1653017065 }
1653117066
17067
+ private Object3D GetFolder()
17068
+ {
17069
+ Object3D folder = object.GetWindow().copy;
17070
+ if (object.GetWindow().copy.selection.Size() > 0)
17071
+ folder = object.GetWindow().copy.selection.elementAt(0);
17072
+ return folder;
17073
+ }
17074
+
1653217075 class SelectBuffer implements GLEventListener
1653317076 {
1653417077
....@@ -16544,7 +17087,7 @@
1654417087 //new Exception().printStackTrace();
1654517088 System.out.println("select buffer init");
1654617089 // Use debug pipeline
16547
- drawable.setGL(new DebugGL(drawable.getGL()));
17090
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1654817091
1654917092 GL gl = drawable.getGL();
1655017093
....@@ -16608,6 +17151,17 @@
1660817151
1660917152 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1661017153
17154
+ if (PAINTMODE)
17155
+ {
17156
+ if (object.GetWindow().copy.selection.Size() > 0)
17157
+ {
17158
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17159
+
17160
+ // Make what you paint not selectable.
17161
+ paintobj.ResetSelectable();
17162
+ }
17163
+ }
17164
+
1661117165 //int tmp = selection_view;
1661217166 //selection_view = -1;
1661317167 int temp = DrawMode();
....@@ -16619,6 +17173,17 @@
1661917173 // temp = DEFAULT; // patch for selection debug
1662017174 Globals.drawMode = temp; // WARNING
1662117175
17176
+ if (PAINTMODE)
17177
+ {
17178
+ if (object.GetWindow().copy.selection.Size() > 0)
17179
+ {
17180
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17181
+
17182
+ // Revert.
17183
+ paintobj.RestoreSelectable();
17184
+ }
17185
+ }
17186
+
1662217187 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1662317188
1662417189 // trying different ways of getting the depth info over
....@@ -16722,29 +17287,31 @@
1672217287 }
1672317288
1672417289 if (!movingcamera && !PAINTMODE)
16725
- object.editWindow.ScreenFitPoint(); // fev 2014
17290
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1672617291
16727
- if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17292
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1672817293 {
16729
- Object3D paintobj = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17294
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1673017295
16731
- Object3D group = new Object3D("inst" + paintcount++);
17296
+ if (object.GetWindow().copy.selection.Size() > 0)
17297
+ {
17298
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1673217299
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();
17300
+ Object3D inst = new Object3D("inst" + paintcount++);
17301
+
17302
+ inst.CreateMaterial(); // use a void leaf to select instances
17303
+
17304
+ inst.add(paintobj); // link
17305
+
17306
+ object.GetWindow().SnapObject(inst);
17307
+
17308
+ Object3D folder = paintFolder; // GetFolder();
17309
+
17310
+ folder.add(inst);
17311
+
17312
+ object.GetWindow().ResetModel();
17313
+ object.GetWindow().refreshContents();
17314
+ }
1674817315 }
1674917316 else
1675017317 paintcount = 0;
....@@ -16783,6 +17350,11 @@
1678317350 //System.out.println("objects[color] = " + objects[color]);
1678417351 //objects[color].Select();
1678517352 indexcount = 0;
17353
+ ObjEditor window = object.GetWindow();
17354
+ if (window != null && deselect)
17355
+ {
17356
+ window.Select(null, deselect, true);
17357
+ }
1678617358 object.Select(color, deselect);
1678717359 }
1678817360
....@@ -16833,6 +17405,7 @@
1683317405
1683417406 public void init(GLAutoDrawable drawable)
1683517407 {
17408
+ if (Globals.DEBUG)
1683617409 System.out.println("shadow buffer init");
1683717410
1683817411 GL gl = drawable.getGL();
....@@ -17061,10 +17634,14 @@
1706117634 gl.glFlush();
1706217635
1706317636 /**/
17064
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17637
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1706517638
17066
- float[] pixels = occlusionsizebuffer.array();
17639
+ float[] depths = occlusiondepthbuffer.array();
1706717640
17641
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17642
+
17643
+ int[] pixels = selectsizebuffer.array();
17644
+
1706817645 double r = 0, g = 0, b = 0;
1706917646
1707017647 double count = 0;
....@@ -17075,7 +17652,7 @@
1707517652
1707617653 double FACTOR = 1;
1707717654
17078
- for (int i = 0; i < pixels.length; i++)
17655
+ for (int i = 0; i < depths.length; i++)
1707917656 {
1708017657 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1708117658 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -17158,7 +17735,7 @@
1715817735
1715917736 double scale = ray.z; // 1; // cos
1716017737
17161
- float depth = pixels[newindex];
17738
+ float depth = depths[newindex];
1716217739
1716317740 /*
1716417741 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -17355,11 +17932,14 @@
1735517932 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1735617933 static IntBuffer bigAAbuffer;
1735717934 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
17358
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17935
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1735917936 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1736017937 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1736117938 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17362
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17939
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17940
+
17941
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17942
+
1736317943 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1736417944 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1736517945 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();