.. | .. |
---|
18 | 18 | import javax.imageio.ImageIO; |
---|
19 | 19 | import javax.imageio.ImageWriteParam; |
---|
20 | 20 | import javax.imageio.ImageWriter; |
---|
| 21 | +import javax.imageio.ImageReadParam; |
---|
| 22 | +import javax.imageio.ImageReader; |
---|
21 | 23 | import javax.imageio.plugins.jpeg.JPEGImageWriteParam; |
---|
| 24 | +import javax.imageio.stream.ImageInputStream; |
---|
22 | 25 | import javax.imageio.stream.ImageOutputStream; |
---|
23 | 26 | import javax.imageio.ImageWriteParam; |
---|
24 | 27 | |
---|
.. | .. |
---|
30 | 33 | import java.nio.*; |
---|
31 | 34 | |
---|
32 | 35 | import gleem.linalg.Mat4f; |
---|
| 36 | +import javax.imageio.ImageTypeSpecifier; |
---|
33 | 37 | |
---|
34 | 38 | class CameraPane extends GLCanvas implements iCameraPane, Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener |
---|
35 | 39 | { |
---|
.. | .. |
---|
44 | 48 | static boolean ABORTED = false; |
---|
45 | 49 | |
---|
46 | 50 | 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 | + } |
---|
47 | 84 | |
---|
48 | 85 | /*static*/ private boolean CULLFACE = false; // true; |
---|
49 | 86 | /*static*/ boolean NEAREST = false; // true; |
---|
.. | .. |
---|
60 | 97 | //boolean REDUCETEXTURE = true; |
---|
61 | 98 | boolean CACHETEXTURE = true; |
---|
62 | 99 | boolean CLEANCACHE = false; // true; |
---|
63 | | - boolean MIPMAP = true; // false; // true; |
---|
| 100 | + boolean MIPMAP = false; // true; // never works... |
---|
64 | 101 | boolean COMPRESSTEXTURE = false; |
---|
65 | 102 | boolean KOMPACTTEXTURE = false; // true; |
---|
66 | 103 | boolean RESIZETEXTURE = false; |
---|
.. | .. |
---|
150 | 187 | } |
---|
151 | 188 | |
---|
152 | 189 | private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory(); |
---|
| 190 | + |
---|
| 191 | + public void LoadSkybox(String name, String ext, boolean mipmap) throws GLException |
---|
| 192 | + { |
---|
| 193 | + try |
---|
| 194 | + { |
---|
| 195 | + cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap); |
---|
| 196 | + } catch (IOException e) |
---|
| 197 | + { |
---|
| 198 | + System.out.println("NAME = " + name); |
---|
| 199 | + e.printStackTrace(); // throw new RuntimeException(e); |
---|
| 200 | + } |
---|
| 201 | + } |
---|
153 | 202 | |
---|
154 | 203 | void SetAsGLRenderer(boolean b) |
---|
155 | 204 | { |
---|
.. | .. |
---|
169 | 218 | |
---|
170 | 219 | SetCamera(cam); |
---|
171 | 220 | |
---|
172 | | - SetLight(new Camera(new cVector(10, 10, -20))); |
---|
| 221 | + // Warning: not used. |
---|
| 222 | + SetLight(new Camera(new cVector(15, 10, -20))); |
---|
173 | 223 | |
---|
174 | 224 | object = o; |
---|
175 | 225 | |
---|
.. | .. |
---|
1447 | 1497 | gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z); |
---|
1448 | 1498 | } |
---|
1449 | 1499 | |
---|
| 1500 | + float[] colorV = new float[4]; |
---|
| 1501 | + |
---|
1450 | 1502 | void SetColor(Object3D obj, Vertex p0) |
---|
1451 | 1503 | { |
---|
1452 | 1504 | CameraPane display = this; |
---|
.. | .. |
---|
1514 | 1566 | { |
---|
1515 | 1567 | return; |
---|
1516 | 1568 | } |
---|
1517 | | - |
---|
1518 | | - float[] colorV = new float[3]; |
---|
1519 | 1569 | |
---|
1520 | 1570 | if (false) // marked) |
---|
1521 | 1571 | { |
---|
.. | .. |
---|
2405 | 2455 | return currentGL; |
---|
2406 | 2456 | } |
---|
2407 | 2457 | |
---|
| 2458 | + static private BufferedImage CreateBim(TextureData texturedata) |
---|
| 2459 | + { |
---|
| 2460 | + Grafreed.Assert(texturedata != null); |
---|
| 2461 | + |
---|
| 2462 | + int width = texturedata.getWidth(); |
---|
| 2463 | + int height = texturedata.getHeight(); |
---|
| 2464 | + |
---|
| 2465 | + Buffer buffer = texturedata.getBuffer(); |
---|
| 2466 | + ByteBuffer bytebuf = (ByteBuffer)buffer; |
---|
| 2467 | + |
---|
| 2468 | + byte[] bytes = bytebuf.array(); |
---|
| 2469 | + |
---|
| 2470 | + return CreateBim(bytes, width, height); |
---|
| 2471 | + } |
---|
| 2472 | + |
---|
2408 | 2473 | /**/ |
---|
2409 | 2474 | class CacheTexture |
---|
2410 | 2475 | { |
---|
.. | .. |
---|
2413 | 2478 | |
---|
2414 | 2479 | int resolution; |
---|
2415 | 2480 | |
---|
2416 | | - CacheTexture(com.sun.opengl.util.texture.Texture tex, int res) |
---|
| 2481 | + CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res) |
---|
2417 | 2482 | { |
---|
2418 | | - texture = tex; |
---|
| 2483 | + texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata); |
---|
| 2484 | + texturedata = texdata; |
---|
2419 | 2485 | resolution = res; |
---|
2420 | 2486 | } |
---|
2421 | 2487 | } |
---|
2422 | 2488 | /**/ |
---|
2423 | 2489 | |
---|
2424 | 2490 | // TEXTURE static Texture texture; |
---|
2425 | | - static public java.util.Hashtable<String, CacheTexture> textures = new java.util.Hashtable<String, CacheTexture>(); |
---|
2426 | | - static public java.util.Hashtable<BufferedImage, CacheTexture> bimtextures = new java.util.Hashtable<BufferedImage, CacheTexture>(); |
---|
2427 | | - static public java.util.HashSet<String> usedtextures = new java.util.HashSet<String>(); |
---|
| 2491 | + static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>(); |
---|
| 2492 | + static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>(); |
---|
| 2493 | + static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>(); |
---|
| 2494 | + static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>(); |
---|
2428 | 2495 | |
---|
2429 | 2496 | int pigmentdepth = 0; |
---|
2430 | 2497 | public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536]; |
---|
.. | .. |
---|
2432 | 2499 | public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536]; |
---|
2433 | 2500 | //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE"; |
---|
2434 | 2501 | public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP"); |
---|
2435 | | - public static String NOISE_TEXTURE = "WHITE_NOISE"; |
---|
| 2502 | + public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:"); |
---|
2436 | 2503 | // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL"); |
---|
2437 | 2504 | |
---|
2438 | | - com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump) |
---|
| 2505 | + com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump) |
---|
2439 | 2506 | { |
---|
2440 | 2507 | TextureData texturedata = null; |
---|
2441 | 2508 | |
---|
.. | .. |
---|
2454 | 2521 | if (bump) |
---|
2455 | 2522 | texturedata = ConvertBump(texturedata, false); |
---|
2456 | 2523 | |
---|
2457 | | - com.sun.opengl.util.texture.Texture texture = |
---|
2458 | | - com.sun.opengl.util.texture.TextureIO.newTexture(texturedata); |
---|
| 2524 | +// com.sun.opengl.util.texture.Texture texture = |
---|
| 2525 | +// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata); |
---|
2459 | 2526 | |
---|
2460 | | - texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT); |
---|
2461 | | - texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT); |
---|
| 2527 | + //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT); |
---|
| 2528 | + //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT); |
---|
2462 | 2529 | |
---|
2463 | | - return texture; |
---|
| 2530 | + return texturedata; |
---|
2464 | 2531 | } |
---|
2465 | 2532 | |
---|
2466 | | - com.sun.opengl.util.texture.Texture GetBimTexture(BufferedImage name, boolean bump) |
---|
| 2533 | + com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump) |
---|
2467 | 2534 | { |
---|
2468 | 2535 | TextureData texturedata = null; |
---|
2469 | 2536 | |
---|
.. | .. |
---|
2471 | 2538 | { |
---|
2472 | 2539 | texturedata = |
---|
2473 | 2540 | com.sun.opengl.util.texture.TextureIO.newTextureData( |
---|
2474 | | - name, |
---|
| 2541 | + bim, |
---|
2475 | 2542 | true); |
---|
2476 | 2543 | } catch (Exception e) |
---|
2477 | 2544 | { |
---|
.. | .. |
---|
2480 | 2547 | |
---|
2481 | 2548 | if (bump) |
---|
2482 | 2549 | texturedata = ConvertBump(texturedata, false); |
---|
2483 | | - |
---|
2484 | | - com.sun.opengl.util.texture.Texture texture = |
---|
2485 | | - com.sun.opengl.util.texture.TextureIO.newTexture(texturedata); |
---|
2486 | | - |
---|
2487 | | - texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT); |
---|
2488 | | - texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT); |
---|
2489 | | - |
---|
2490 | | - return texture; |
---|
| 2550 | + |
---|
| 2551 | + return texturedata; |
---|
2491 | 2552 | } |
---|
2492 | 2553 | |
---|
2493 | 2554 | boolean HUESMOOTH = true; // wrap around bug... true; |
---|
.. | .. |
---|
7975 | 8036 | pigment = null; |
---|
7976 | 8037 | } |
---|
7977 | 8038 | |
---|
7978 | | - ReleaseTexture(bump, true); |
---|
7979 | | - ReleaseTexture(pigment, false); |
---|
| 8039 | + ReleaseTexture(tex, true); |
---|
| 8040 | + ReleaseTexture(tex, false); |
---|
7980 | 8041 | } |
---|
7981 | 8042 | |
---|
7982 | 8043 | public void ReleasePigmentTexture(cTexture tex) // INTERFACE |
---|
.. | .. |
---|
8005 | 8066 | pigment = null; |
---|
8006 | 8067 | } |
---|
8007 | 8068 | |
---|
8008 | | - ReleaseTexture(pigment, false); |
---|
| 8069 | + ReleaseTexture(tex, false); |
---|
8009 | 8070 | } |
---|
8010 | 8071 | |
---|
8011 | 8072 | public void ReleaseBumpTexture(cTexture tex) // INTERFACE |
---|
.. | .. |
---|
8034 | 8095 | bump = null; |
---|
8035 | 8096 | } |
---|
8036 | 8097 | |
---|
8037 | | - ReleaseTexture(bump, true); |
---|
| 8098 | + ReleaseTexture(tex, true); |
---|
8038 | 8099 | } |
---|
8039 | 8100 | |
---|
8040 | | - void ReleaseTexture(String tex, boolean bump) |
---|
| 8101 | + void ReleaseTexture(cTexture tex, boolean bump) |
---|
8041 | 8102 | { |
---|
8042 | 8103 | if (// DrawMode() != 0 || /*tex == null ||*/ |
---|
8043 | 8104 | ambientOcclusion ) // || !textureon) |
---|
.. | .. |
---|
8048 | 8109 | CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null; |
---|
8049 | 8110 | |
---|
8050 | 8111 | if (tex != null) |
---|
8051 | | - texture = textures.get(tex); |
---|
| 8112 | + texture = bump ? texturebump.get(tex) : texturepigment.get(tex); |
---|
8052 | 8113 | |
---|
8053 | 8114 | // //assert( texture != null ); |
---|
8054 | 8115 | // if (texture == null) |
---|
.. | .. |
---|
8198 | 8259 | |
---|
8199 | 8260 | if (tex == null) |
---|
8200 | 8261 | { |
---|
8201 | | - BindTexture(null, null,false,resolution); |
---|
| 8262 | + BindTexture(null,false,resolution); |
---|
8202 | 8263 | return; |
---|
8203 | 8264 | } |
---|
8204 | 8265 | |
---|
8205 | 8266 | String pigment = Object3D.GetPigment(tex); |
---|
8206 | 8267 | |
---|
8207 | | - usedtextures.add(pigment); |
---|
| 8268 | + usedtextures.add(tex); |
---|
8208 | 8269 | |
---|
8209 | 8270 | //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
8210 | 8271 | { |
---|
.. | .. |
---|
8218 | 8279 | } |
---|
8219 | 8280 | |
---|
8220 | 8281 | GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
8221 | | - BindTexture(tex.pigmenttexture, pigment, false, resolution); |
---|
| 8282 | + BindTexture(tex, false, resolution); |
---|
8222 | 8283 | } |
---|
8223 | 8284 | |
---|
8224 | 8285 | /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE |
---|
.. | .. |
---|
8231 | 8292 | |
---|
8232 | 8293 | if (tex == null) |
---|
8233 | 8294 | { |
---|
8234 | | - BindTexture(null, null,true,resolution); |
---|
| 8295 | + BindTexture(null,true,resolution); |
---|
8235 | 8296 | return; |
---|
8236 | 8297 | } |
---|
8237 | 8298 | |
---|
8238 | 8299 | String bump = Object3D.GetBump(tex); |
---|
8239 | 8300 | |
---|
8240 | | - usedtextures.add(bump); |
---|
| 8301 | + usedtextures.add(tex); |
---|
8241 | 8302 | |
---|
8242 | 8303 | //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
8243 | 8304 | { |
---|
.. | .. |
---|
8251 | 8312 | } |
---|
8252 | 8313 | |
---|
8253 | 8314 | GetGL().glActiveTexture(GetGL().GL_TEXTURE2); |
---|
8254 | | - BindTexture(tex.bumptexture, bump, true, resolution); |
---|
| 8315 | + BindTexture(tex, true, resolution); |
---|
8255 | 8316 | GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
8256 | 8317 | } |
---|
8257 | 8318 | |
---|
.. | .. |
---|
8275 | 8336 | return fileExists; |
---|
8276 | 8337 | } |
---|
8277 | 8338 | |
---|
8278 | | - CacheTexture GetCacheTexture(java.awt.image.BufferedImage bim, String tex, boolean bump, int resolution) throws Exception |
---|
| 8339 | + CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8279 | 8340 | { |
---|
8280 | 8341 | CacheTexture texturecache = null; |
---|
8281 | 8342 | |
---|
8282 | 8343 | if (tex != null) |
---|
8283 | 8344 | { |
---|
8284 | | - String texname = tex; |
---|
| 8345 | + String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex); |
---|
| 8346 | + byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata; |
---|
| 8347 | + |
---|
| 8348 | + if (texname.equals("") && texdata == null) |
---|
| 8349 | + { |
---|
| 8350 | + return null; |
---|
| 8351 | + } |
---|
8285 | 8352 | |
---|
8286 | 8353 | String fallbackTextureName = defaultDirectory + "/Textures/" + texname; |
---|
8287 | 8354 | |
---|
.. | .. |
---|
8291 | 8358 | // else |
---|
8292 | 8359 | // if (!texname.startsWith("/")) |
---|
8293 | 8360 | // texname = "/Users/nbriere/Textures/" + texname; |
---|
8294 | | - if (!FileExists(tex)) |
---|
| 8361 | + if (!FileExists(texname)) |
---|
8295 | 8362 | { |
---|
8296 | 8363 | texname = fallbackTextureName; |
---|
8297 | 8364 | } |
---|
8298 | 8365 | |
---|
8299 | 8366 | if (CACHETEXTURE) |
---|
8300 | 8367 | { |
---|
8301 | | - if (bim == null) |
---|
8302 | | - texturecache = textures.get(texname); // TEXTURE CACHE |
---|
| 8368 | + if (texdata == null) |
---|
| 8369 | + texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex); |
---|
8303 | 8370 | else |
---|
8304 | | - texturecache = bimtextures.get(bim); // TEXTURE CACHE |
---|
| 8371 | + texturecache = bimtextures.get(texdata); |
---|
8305 | 8372 | } |
---|
8306 | 8373 | |
---|
8307 | | - if (texturecache == null || texturecache.resolution < resolution) |
---|
| 8374 | + if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution) |
---|
8308 | 8375 | { |
---|
8309 | 8376 | TextureData texturedata = null; |
---|
8310 | 8377 | |
---|
8311 | | - if (bim == null) |
---|
| 8378 | + if (texdata != null && textureon) |
---|
8312 | 8379 | { |
---|
| 8380 | + BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB); |
---|
8313 | 8381 | |
---|
| 8382 | + try |
---|
| 8383 | + { |
---|
| 8384 | + bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph); |
---|
| 8385 | + } |
---|
| 8386 | + catch (Exception e) |
---|
| 8387 | + { |
---|
| 8388 | + bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph); |
---|
| 8389 | + } |
---|
| 8390 | + |
---|
| 8391 | + texturecache = new CacheTexture(GetBimTexture(bim, bump), -1); |
---|
| 8392 | + bimtextures.put(texdata, texturecache); |
---|
| 8393 | + |
---|
| 8394 | + //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB); |
---|
| 8395 | + |
---|
| 8396 | + //Object bim2 = CreateBim(texturecache.texturedata); |
---|
| 8397 | + //bim2 = bim; |
---|
8314 | 8398 | } |
---|
8315 | 8399 | else |
---|
8316 | | - if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals("")) |
---|
| 8400 | + if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals("")) |
---|
8317 | 8401 | { |
---|
8318 | 8402 | assert(!bump); |
---|
8319 | 8403 | // if (bump) |
---|
.. | .. |
---|
8324 | 8408 | // } |
---|
8325 | 8409 | // else |
---|
8326 | 8410 | // { |
---|
8327 | | - texturecache = textures.get(tex); |
---|
| 8411 | + // texturecache = textures.get(texname); // suspicious |
---|
8328 | 8412 | if (texturecache == null) |
---|
8329 | 8413 | { |
---|
8330 | 8414 | texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
8331 | 8415 | } |
---|
| 8416 | + else |
---|
| 8417 | + new Exception().printStackTrace(); |
---|
8332 | 8418 | // } |
---|
8333 | 8419 | } else |
---|
8334 | | - if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals("")) |
---|
| 8420 | + if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals("")) |
---|
8335 | 8421 | { |
---|
8336 | 8422 | assert(bump); |
---|
8337 | | - texturecache = textures.get(tex); |
---|
| 8423 | + // texturecache = textures.get(texname); // suspicious |
---|
8338 | 8424 | if (texturecache == null) |
---|
8339 | 8425 | texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
| 8426 | + else |
---|
| 8427 | + new Exception().printStackTrace(); |
---|
8340 | 8428 | } else |
---|
8341 | 8429 | { |
---|
8342 | 8430 | //if (tex.equals("IMMORTAL")) |
---|
.. | .. |
---|
8344 | 8432 | // texture = GetResourceTexture("default.png"); |
---|
8345 | 8433 | //} else |
---|
8346 | 8434 | //{ |
---|
8347 | | - if (tex.equals("WHITE_NOISE")) |
---|
| 8435 | + if (texname.endsWith("WHITE_NOISE")) |
---|
8348 | 8436 | { |
---|
8349 | | - texturecache = textures.get(tex); |
---|
| 8437 | + // texturecache = textures.get(texname); // suspicious |
---|
8350 | 8438 | if (texturecache == null) |
---|
8351 | 8439 | texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution); |
---|
| 8440 | + else |
---|
| 8441 | + new Exception().printStackTrace(); |
---|
8352 | 8442 | } else |
---|
8353 | 8443 | { |
---|
8354 | 8444 | if (textureon) |
---|
.. | .. |
---|
8407 | 8497 | if (texturedata == null) |
---|
8408 | 8498 | throw new Exception(); |
---|
8409 | 8499 | |
---|
8410 | | - texturecache = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution); |
---|
| 8500 | + texturecache = new CacheTexture(texturedata,resolution); |
---|
8411 | 8501 | //texture = GetTexture(tex, bump); |
---|
8412 | 8502 | } |
---|
8413 | 8503 | } |
---|
8414 | 8504 | //} |
---|
8415 | 8505 | } |
---|
8416 | 8506 | |
---|
8417 | | - if (/*CACHETEXTURE &&*/ texturecache != null && textureon) |
---|
| 8507 | + if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon) |
---|
8418 | 8508 | { |
---|
8419 | 8509 | //return false; |
---|
8420 | 8510 | |
---|
.. | .. |
---|
8436 | 8526 | File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg"); |
---|
8437 | 8527 | if (!cachefile.exists()) |
---|
8438 | 8528 | { |
---|
8439 | | - // cache to disk |
---|
8440 | | - Buffer buffer = texturedata.getBuffer(); // getMipmapData(); |
---|
8441 | | - //buffers[0]. |
---|
8442 | | - |
---|
8443 | | - ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer(); |
---|
8444 | | - int[] pixels = new int[bytebuf.capacity()/3]; |
---|
8445 | | - |
---|
8446 | | - // squared size heuristic... |
---|
8447 | | - if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length)) |
---|
| 8529 | + //if (texturedata.getWidth() == texturedata.getHeight()) |
---|
8448 | 8530 | { |
---|
8449 | | - for (int i=pixels.length; --i>=0;) |
---|
8450 | | - { |
---|
8451 | | - int i3 = i*3; |
---|
8452 | | - pixels[i] = 0xFF; |
---|
8453 | | - pixels[i] <<= 8; |
---|
8454 | | - pixels[i] |= bytebuf.get(i3+2) & 0xFF; |
---|
8455 | | - pixels[i] <<= 8; |
---|
8456 | | - pixels[i] |= bytebuf.get(i3+1) & 0xFF; |
---|
8457 | | - pixels[i] <<= 8; |
---|
8458 | | - pixels[i] |= bytebuf.get(i3) & 0xFF; |
---|
8459 | | - } |
---|
8460 | | - |
---|
8461 | | - /* |
---|
8462 | | - int r=0,g=0,b=0,a=0; |
---|
8463 | | - for (int i=0; i<width; i++) |
---|
8464 | | - for (int j=0; j<height; j++) |
---|
8465 | | - { |
---|
8466 | | - int index = j*width+i; |
---|
8467 | | - int p = pixels[index]; |
---|
8468 | | - a = ((p>>24) & 0xFF); |
---|
8469 | | - r = ((p>>16) & 0xFF); |
---|
8470 | | - g = ((p>>8) & 0xFF); |
---|
8471 | | - b = (p & 0xFF); |
---|
8472 | | - pixels[index] = (a<<24) | (b<<16) | (g<<8) | r; |
---|
8473 | | - } |
---|
8474 | | - /**/ |
---|
8475 | | - int width = (int)Math.sqrt(pixels.length); // squared |
---|
8476 | | - int height = width; |
---|
8477 | | - BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile); |
---|
8478 | | - rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width); |
---|
| 8531 | + BufferedImage rendImage = CreateBim(texturedata); |
---|
| 8532 | + |
---|
8479 | 8533 | ImageWriter writer = null; |
---|
8480 | 8534 | Iterator iter = ImageIO.getImageWritersByFormatName("jpg"); |
---|
8481 | 8535 | if (iter.hasNext()) { |
---|
8482 | 8536 | writer = (ImageWriter)iter.next(); |
---|
8483 | 8537 | } |
---|
8484 | | - float compressionQuality = 0.9f; |
---|
| 8538 | + |
---|
| 8539 | + float compressionQuality = 0.85f; |
---|
8485 | 8540 | try |
---|
8486 | 8541 | { |
---|
8487 | 8542 | ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile); |
---|
.. | .. |
---|
8498 | 8553 | } |
---|
8499 | 8554 | } |
---|
8500 | 8555 | } |
---|
8501 | | - |
---|
| 8556 | + |
---|
| 8557 | + Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment; |
---|
| 8558 | + |
---|
8502 | 8559 | //System.out.println("Texture = " + tex); |
---|
8503 | | - if (textures.containsKey(texname)) |
---|
| 8560 | + if (textures.containsKey(tex)) |
---|
8504 | 8561 | { |
---|
8505 | | - CacheTexture thetex = textures.get(texname); |
---|
| 8562 | + CacheTexture thetex = textures.get(tex); |
---|
8506 | 8563 | thetex.texture.disable(); |
---|
8507 | 8564 | thetex.texture.dispose(); |
---|
8508 | | - textures.remove(texname); |
---|
| 8565 | + textures.remove(tex); |
---|
8509 | 8566 | } |
---|
8510 | 8567 | |
---|
8511 | 8568 | //texture.texturedata = texturedata; |
---|
8512 | | - textures.put(texname, texturecache); |
---|
| 8569 | + textures.put(tex, texturecache); |
---|
8513 | 8570 | |
---|
8514 | 8571 | // newtex = true; |
---|
8515 | 8572 | } |
---|
.. | .. |
---|
8528 | 8585 | return texturecache; |
---|
8529 | 8586 | } |
---|
8530 | 8587 | |
---|
8531 | | - com.sun.opengl.util.texture.Texture GetTexture(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception |
---|
| 8588 | + static void EmbedTextures(cTexture tex) |
---|
8532 | 8589 | { |
---|
8533 | | - CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution); |
---|
| 8590 | + if (tex.pigmentdata == null) |
---|
| 8591 | + { |
---|
| 8592 | + //String texname = Object3D.GetPigment(tex); |
---|
| 8593 | + |
---|
| 8594 | + CacheTexture texturecache = texturepigment.get(tex); |
---|
| 8595 | + |
---|
| 8596 | + if (texturecache != null) |
---|
| 8597 | + { |
---|
| 8598 | + tex.pw = texturecache.texturedata.getWidth(); |
---|
| 8599 | + tex.ph = texturecache.texturedata.getHeight(); |
---|
| 8600 | + tex.pigmentdata = //CompressJPEG(CreateBim |
---|
| 8601 | + ((ByteBuffer)texturecache.texturedata.getBuffer()).array() |
---|
| 8602 | + ; |
---|
| 8603 | + //, tex.pw, tex.ph), 0.5f); |
---|
| 8604 | + } |
---|
| 8605 | + } |
---|
| 8606 | + |
---|
| 8607 | + if (tex.bumpdata == null) |
---|
| 8608 | + { |
---|
| 8609 | + //String texname = Object3D.GetBump(tex); |
---|
| 8610 | + |
---|
| 8611 | + CacheTexture texturecache = texturebump.get(tex); |
---|
| 8612 | + |
---|
| 8613 | + if (texturecache != null) |
---|
| 8614 | + { |
---|
| 8615 | + tex.bw = texturecache.texturedata.getWidth(); |
---|
| 8616 | + tex.bh = texturecache.texturedata.getHeight(); |
---|
| 8617 | + tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f); |
---|
| 8618 | + } |
---|
| 8619 | + } |
---|
| 8620 | + } |
---|
| 8621 | + |
---|
| 8622 | + com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception |
---|
| 8623 | + { |
---|
| 8624 | + CacheTexture texture = GetCacheTexture(tex, bump, resolution); |
---|
8534 | 8625 | |
---|
8535 | 8626 | if (bump) |
---|
8536 | 8627 | { |
---|
.. | .. |
---|
8546 | 8637 | return texture!=null?texture.texture:null; |
---|
8547 | 8638 | } |
---|
8548 | 8639 | |
---|
8549 | | - public com.sun.opengl.util.texture.TextureData GetTextureData(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception |
---|
| 8640 | + public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8550 | 8641 | { |
---|
8551 | | - CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution); |
---|
| 8642 | + CacheTexture texture = GetCacheTexture(tex, bump, resolution); |
---|
8552 | 8643 | |
---|
8553 | 8644 | return texture!=null?texture.texturedata:null; |
---|
8554 | 8645 | } |
---|
8555 | 8646 | |
---|
8556 | | - boolean BindTexture(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception |
---|
| 8647 | + boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8557 | 8648 | { |
---|
8558 | 8649 | if (/*tex == null ||*/ ambientOcclusion ) // || !textureon) |
---|
8559 | 8650 | { |
---|
.. | .. |
---|
8562 | 8653 | |
---|
8563 | 8654 | //boolean newtex = false; |
---|
8564 | 8655 | |
---|
8565 | | - com.sun.opengl.util.texture.Texture texture = GetTexture(stream, tex, bump, resolution); |
---|
| 8656 | + com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution); |
---|
8566 | 8657 | |
---|
8567 | 8658 | if (texture == null) |
---|
8568 | 8659 | return false; |
---|
.. | .. |
---|
8595 | 8686 | return true; // Warning: not used. |
---|
8596 | 8687 | } |
---|
8597 | 8688 | |
---|
| 8689 | + public static byte[] CompressJPEG(BufferedImage image, float quality) |
---|
| 8690 | + { |
---|
| 8691 | + try |
---|
| 8692 | + { |
---|
| 8693 | + ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
---|
| 8694 | + Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg"); |
---|
| 8695 | + ImageWriter writer = writers.next(); |
---|
| 8696 | + |
---|
| 8697 | + ImageWriteParam param = writer.getDefaultWriteParam(); |
---|
| 8698 | + param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); |
---|
| 8699 | + param.setCompressionQuality(quality); |
---|
| 8700 | + |
---|
| 8701 | + ImageOutputStream ios = ImageIO.createImageOutputStream(baos); |
---|
| 8702 | + writer.setOutput(ios); |
---|
| 8703 | + writer.write(null, new IIOImage(image, null, null), param); |
---|
| 8704 | + |
---|
| 8705 | + byte[] data = baos.toByteArray(); |
---|
| 8706 | + writer.dispose(); |
---|
| 8707 | + return data; |
---|
| 8708 | + } |
---|
| 8709 | + catch (Exception e) |
---|
| 8710 | + { |
---|
| 8711 | + e.printStackTrace(); |
---|
| 8712 | + return null; |
---|
| 8713 | + } |
---|
| 8714 | + } |
---|
| 8715 | + |
---|
| 8716 | + public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException |
---|
| 8717 | + { |
---|
| 8718 | + ByteArrayInputStream baos = new ByteArrayInputStream(image); |
---|
| 8719 | + Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg"); |
---|
| 8720 | + ImageReader reader = writers.next(); |
---|
| 8721 | + |
---|
| 8722 | + BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); |
---|
| 8723 | + |
---|
| 8724 | + ImageReadParam param = reader.getDefaultReadParam(); |
---|
| 8725 | + param.setDestination(bim); |
---|
| 8726 | + //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB)); |
---|
| 8727 | + |
---|
| 8728 | + ImageInputStream ios = ImageIO.createImageInputStream(baos); |
---|
| 8729 | + reader.setInput(ios); |
---|
| 8730 | + BufferedImage bim2 = reader.read(0, param); |
---|
| 8731 | + reader.dispose(); |
---|
| 8732 | + |
---|
| 8733 | +// WritableRaster raster = bim2.getRaster(); |
---|
| 8734 | +// DataBufferByte data = (DataBufferByte) raster.getDataBuffer(); |
---|
| 8735 | +// byte[] bytes = data.getData(); |
---|
| 8736 | +// |
---|
| 8737 | +// int[] pixels = new int[bytes.length/3]; |
---|
| 8738 | +// for (int i=pixels.length; --i>=0;) |
---|
| 8739 | +// { |
---|
| 8740 | +// int i3 = i*3; |
---|
| 8741 | +// pixels[i] = 0xFF; |
---|
| 8742 | +// pixels[i] <<= 8; |
---|
| 8743 | +// pixels[i] |= bytes[i3+2] & 0xFF; |
---|
| 8744 | +// pixels[i] <<= 8; |
---|
| 8745 | +// pixels[i] |= bytes[i3+1] & 0xFF; |
---|
| 8746 | +// pixels[i] <<= 8; |
---|
| 8747 | +// pixels[i] |= bytes[i3] & 0xFF; |
---|
| 8748 | +// } |
---|
| 8749 | +// |
---|
| 8750 | +// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w); |
---|
| 8751 | + |
---|
| 8752 | + return bim; |
---|
| 8753 | + } |
---|
| 8754 | + |
---|
8598 | 8755 | ShadowBuffer shadowPBuf; |
---|
8599 | 8756 | AntialiasBuffer antialiasPBuf; |
---|
8600 | 8757 | int MAXSTACK; |
---|
.. | .. |
---|
8787 | 8944 | |
---|
8788 | 8945 | if (cubemap == null) |
---|
8789 | 8946 | { |
---|
8790 | | - LoadEnvy(5); |
---|
| 8947 | + //LoadEnvy(1); |
---|
8791 | 8948 | } |
---|
8792 | 8949 | |
---|
8793 | 8950 | //cubemap.enable(); |
---|
.. | .. |
---|
9074 | 9231 | cubemap = null; |
---|
9075 | 9232 | return; |
---|
9076 | 9233 | case 1: |
---|
9077 | | - name = "cubemaps/box_"; |
---|
9078 | | - ext = "png"; |
---|
| 9234 | + name = "cubemaps/rgb/"; |
---|
| 9235 | + ext = "jpg"; |
---|
9079 | 9236 | reverseUP = false; |
---|
9080 | 9237 | break; |
---|
9081 | 9238 | case 2: |
---|
9082 | | - name = "cubemaps/uffizi_"; |
---|
9083 | | - ext = "png"; |
---|
9084 | | - break; // reverseUP = true; break; |
---|
| 9239 | + name = "cubemaps/uffizi/"; |
---|
| 9240 | + ext = "jpg"; |
---|
| 9241 | + reverseUP = false; |
---|
| 9242 | + break; |
---|
9085 | 9243 | case 3: |
---|
9086 | | - name = "cubemaps/CloudyHills_"; |
---|
9087 | | - ext = "tga"; |
---|
| 9244 | + name = "cubemaps/CloudyHills/"; |
---|
| 9245 | + ext = "jpg"; |
---|
9088 | 9246 | reverseUP = false; |
---|
9089 | 9247 | break; |
---|
9090 | 9248 | case 4: |
---|
9091 | | - name = "cubemaps/cornell_"; |
---|
| 9249 | + name = "cubemaps/cornell/"; |
---|
9092 | 9250 | ext = "png"; |
---|
9093 | 9251 | reverseUP = false; |
---|
9094 | 9252 | break; |
---|
| 9253 | + case 5: |
---|
| 9254 | + name = "cubemaps/skycube/"; |
---|
| 9255 | + ext = "jpg"; |
---|
| 9256 | + reverseUP = false; |
---|
| 9257 | + break; |
---|
| 9258 | + case 6: |
---|
| 9259 | + name = "cubemaps/SaintLazarusChurch3/"; |
---|
| 9260 | + ext = "jpg"; |
---|
| 9261 | + reverseUP = false; |
---|
| 9262 | + break; |
---|
| 9263 | + case 7: |
---|
| 9264 | + name = "cubemaps/Sodermalmsallen/"; |
---|
| 9265 | + ext = "jpg"; |
---|
| 9266 | + reverseUP = false; |
---|
| 9267 | + break; |
---|
| 9268 | + case 8: |
---|
| 9269 | + name = "cubemaps/Sodermalmsallen2/"; |
---|
| 9270 | + ext = "jpg"; |
---|
| 9271 | + reverseUP = false; |
---|
| 9272 | + break; |
---|
| 9273 | + case 9: |
---|
| 9274 | + name = "cubemaps/UnionSquare/"; |
---|
| 9275 | + ext = "jpg"; |
---|
| 9276 | + reverseUP = false; |
---|
| 9277 | + break; |
---|
9095 | 9278 | default: |
---|
9096 | | - name = "cubemaps/rgb_"; |
---|
9097 | | - ext = "png"; /*mipmap = true;*/ reverseUP = false; |
---|
| 9279 | + name = "cubemaps/box/"; |
---|
| 9280 | + ext = "png"; /*mipmap = true;*/ |
---|
| 9281 | + reverseUP = false; |
---|
9098 | 9282 | break; |
---|
9099 | 9283 | } |
---|
9100 | | - |
---|
9101 | | - try |
---|
9102 | | - { |
---|
9103 | | - cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap); |
---|
9104 | | - } catch (IOException e) |
---|
9105 | | - { |
---|
9106 | | - throw new RuntimeException(e); |
---|
9107 | | - } |
---|
| 9284 | + |
---|
| 9285 | + LoadSkybox(name, ext, mipmap); |
---|
9108 | 9286 | } |
---|
9109 | 9287 | |
---|
9110 | 9288 | public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) |
---|
.. | .. |
---|
9136 | 9314 | static double[] model = new double[16]; |
---|
9137 | 9315 | double[] camera2light = new double[16]; |
---|
9138 | 9316 | double[] light2camera = new double[16]; |
---|
9139 | | - int newenvy = -1; |
---|
9140 | | - boolean envyoff = true; // false; |
---|
| 9317 | + |
---|
| 9318 | + //int newenvy = -1; |
---|
| 9319 | + //boolean envyoff = false; |
---|
| 9320 | + |
---|
| 9321 | + String loadedskyboxname; |
---|
| 9322 | + |
---|
9141 | 9323 | cVector light0 = new cVector(0, 0, 0); // 1,3,2); |
---|
9142 | 9324 | //float[] light0 = { 0,0,0 }; |
---|
9143 | 9325 | cVector dirlight = new cVector(0, 0, 1); // 1,3,2); |
---|
.. | .. |
---|
9555 | 9737 | |
---|
9556 | 9738 | if (renderCamera != lightCamera) |
---|
9557 | 9739 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
9558 | | - LA.matConcat(matrix, parentcam.GlobalTransform(), matrix); |
---|
| 9740 | + LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix); |
---|
9559 | 9741 | |
---|
9560 | 9742 | // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix); |
---|
9561 | 9743 | |
---|
.. | .. |
---|
9571 | 9753 | |
---|
9572 | 9754 | if (renderCamera != lightCamera) |
---|
9573 | 9755 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
9574 | | - LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix); |
---|
| 9756 | + LA.matConcat(parentcam.GlobalTransform(), matrix, matrix); |
---|
9575 | 9757 | |
---|
9576 | 9758 | // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix); |
---|
9577 | 9759 | |
---|
.. | .. |
---|
9617 | 9799 | rati = 1 / rati; |
---|
9618 | 9800 | gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000); |
---|
9619 | 9801 | } |
---|
9620 | | - assert (newenvy == -1); |
---|
| 9802 | + |
---|
| 9803 | + //assert (newenvy == -1); |
---|
| 9804 | + |
---|
9621 | 9805 | gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
9622 | 9806 | gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB); |
---|
9623 | | - DrawSkyBox(gl); |
---|
| 9807 | + DrawSkyBox(gl, (float)rati); |
---|
9624 | 9808 | gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
9625 | 9809 | gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB); |
---|
9626 | 9810 | accPerspective(gl, renderCamera.shaper_fovy / ratio, |
---|
.. | .. |
---|
10772 | 10956 | // if (parentcam != renderCamera) // not a light |
---|
10773 | 10957 | if (cam != lightCamera) |
---|
10774 | 10958 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
10775 | | - LA.matConcat(matrix, parentcam.GlobalTransform(), matrix); |
---|
| 10959 | + LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix); |
---|
10776 | 10960 | |
---|
10777 | 10961 | for (int j = 0; j < 4; j++) |
---|
10778 | 10962 | { |
---|
.. | .. |
---|
10787 | 10971 | // if (parentcam != renderCamera) // not a light |
---|
10788 | 10972 | if (cam != lightCamera) |
---|
10789 | 10973 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
10790 | | - LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix); |
---|
| 10974 | + LA.matConcat(parentcam.GlobalTransform(), matrix, matrix); |
---|
10791 | 10975 | |
---|
10792 | 10976 | //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix); |
---|
10793 | 10977 | |
---|
.. | .. |
---|
10873 | 11057 | gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000); |
---|
10874 | 11058 | } |
---|
10875 | 11059 | |
---|
10876 | | - if (newenvy > -1) |
---|
| 11060 | +// if (newenvy > -1) |
---|
| 11061 | +// { |
---|
| 11062 | +// LoadEnvy(newenvy); |
---|
| 11063 | +// } |
---|
| 11064 | +// |
---|
| 11065 | +// newenvy = -1; |
---|
| 11066 | + |
---|
| 11067 | + if (object.skyboxname != null) |
---|
10877 | 11068 | { |
---|
10878 | | - LoadEnvy(newenvy); |
---|
| 11069 | + if (!object.skyboxname.equals(this.loadedskyboxname)) |
---|
| 11070 | + { |
---|
| 11071 | + LoadSkybox(object.skyboxname + "/", object.skyboxext, false); |
---|
| 11072 | + loadedskyboxname = object.skyboxname; |
---|
| 11073 | + } |
---|
10879 | 11074 | } |
---|
10880 | | - |
---|
10881 | | - newenvy = -1; |
---|
10882 | | - |
---|
| 11075 | + else |
---|
| 11076 | + { |
---|
| 11077 | + cubemap = null; |
---|
| 11078 | + loadedskyboxname = null; |
---|
| 11079 | + } |
---|
| 11080 | + |
---|
10883 | 11081 | ratio = ((double) getWidth()) / getHeight(); |
---|
10884 | 11082 | //System.out.println("ratio = " + ratio); |
---|
10885 | 11083 | |
---|
.. | .. |
---|
10895 | 11093 | |
---|
10896 | 11094 | if (!IsFrozen() && !ambientOcclusion) |
---|
10897 | 11095 | { |
---|
10898 | | - DrawSkyBox(gl); |
---|
| 11096 | + DrawSkyBox(gl, (float)ratio); |
---|
10899 | 11097 | } |
---|
10900 | 11098 | |
---|
10901 | 11099 | //if (selection_view == -1) |
---|
.. | .. |
---|
11049 | 11247 | |
---|
11050 | 11248 | try |
---|
11051 | 11249 | { |
---|
11052 | | - BindTexture(null, NOISE_TEXTURE, false, 2); |
---|
| 11250 | + BindTexture(NOISE_TEXTURE, false, 2); |
---|
11053 | 11251 | } |
---|
11054 | 11252 | catch (Exception e) |
---|
11055 | 11253 | { |
---|
.. | .. |
---|
11181 | 11379 | |
---|
11182 | 11380 | // if (cam != lightCamera) |
---|
11183 | 11381 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
11184 | | - LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013 |
---|
| 11382 | + LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013 |
---|
11185 | 11383 | } |
---|
11186 | 11384 | |
---|
11187 | 11385 | LA.xformDir(lightposition, cam.toScreen, lightposition); |
---|
.. | .. |
---|
11340 | 11538 | } |
---|
11341 | 11539 | } |
---|
11342 | 11540 | |
---|
11343 | | - if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion) |
---|
| 11541 | + if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion) |
---|
11344 | 11542 | { |
---|
11345 | 11543 | //gl.glDepthFunc(GL.GL_LEQUAL); |
---|
11346 | 11544 | //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT); |
---|
.. | .. |
---|
11348 | 11546 | |
---|
11349 | 11547 | boolean texon = textureon; |
---|
11350 | 11548 | |
---|
11351 | | - if (RENDERPROGRAM > 0) |
---|
11352 | | - { |
---|
11353 | | - gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
11354 | | - textureon = false; |
---|
11355 | | - } |
---|
| 11549 | + gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
| 11550 | + textureon = false; |
---|
| 11551 | + |
---|
11356 | 11552 | //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB); |
---|
11357 | 11553 | //System.out.println("ALLO"); |
---|
11358 | 11554 | gl.glColorMask(false, false, false, false); |
---|
11359 | 11555 | DrawObject(gl); |
---|
11360 | | - if (RENDERPROGRAM > 0) |
---|
11361 | | - { |
---|
11362 | | - gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
11363 | | - textureon = texon; |
---|
11364 | | - } |
---|
| 11556 | + |
---|
| 11557 | + gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
| 11558 | + textureon = texon; |
---|
| 11559 | + |
---|
11365 | 11560 | gl.glColorMask(true, true, true, true); |
---|
11366 | 11561 | |
---|
11367 | 11562 | gl.glDepthFunc(GL.GL_EQUAL); |
---|
11368 | | - //gl.glDepthMask(false); |
---|
| 11563 | + gl.glDepthMask(false); |
---|
11369 | 11564 | } |
---|
11370 | 11565 | |
---|
11371 | 11566 | if (false) // DrawMode() == SHADOW) |
---|
.. | .. |
---|
11705 | 11900 | ReleaseTextures(DEFAULT_TEXTURES); |
---|
11706 | 11901 | |
---|
11707 | 11902 | if (CLEANCACHE) |
---|
11708 | | - for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();) |
---|
| 11903 | + for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();) |
---|
11709 | 11904 | { |
---|
11710 | | - String tex = e.nextElement(); |
---|
| 11905 | + cTexture tex = e.nextElement(); |
---|
11711 | 11906 | |
---|
11712 | 11907 | // System.out.println("Texture --------- " + tex); |
---|
11713 | 11908 | |
---|
11714 | | - if (tex.equals("WHITE_NOISE")) |
---|
| 11909 | + if (tex.equals("WHITE_NOISE:")) |
---|
11715 | 11910 | continue; |
---|
11716 | 11911 | |
---|
11717 | 11912 | if (!usedtextures.contains(tex)) |
---|
11718 | 11913 | { |
---|
| 11914 | + CacheTexture gettex = texturepigment.get(tex); |
---|
11719 | 11915 | // System.out.println("DISPOSE +++++++++++++++ " + tex); |
---|
11720 | | - textures.get(tex).texture.dispose(); |
---|
11721 | | - textures.remove(tex); |
---|
| 11916 | + if (gettex != null) |
---|
| 11917 | + { |
---|
| 11918 | + gettex.texture.dispose(); |
---|
| 11919 | + texturepigment.remove(tex); |
---|
| 11920 | + } |
---|
| 11921 | + |
---|
| 11922 | + gettex = texturebump.get(tex); |
---|
| 11923 | + // System.out.println("DISPOSE +++++++++++++++ " + tex); |
---|
| 11924 | + if (gettex != null) |
---|
| 11925 | + { |
---|
| 11926 | + gettex.texture.dispose(); |
---|
| 11927 | + texturebump.remove(tex); |
---|
| 11928 | + } |
---|
11722 | 11929 | } |
---|
11723 | 11930 | } |
---|
11724 | 11931 | } |
---|
.. | .. |
---|
12246 | 12453 | |
---|
12247 | 12454 | //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0); |
---|
12248 | 12455 | |
---|
12249 | | - String program = |
---|
| 12456 | + String programmin = |
---|
| 12457 | + // Min shader |
---|
12250 | 12458 | "!!ARBfp1.0\n" + |
---|
| 12459 | + "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" + |
---|
| 12460 | + "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" + |
---|
| 12461 | + "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" + |
---|
| 12462 | + "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" + |
---|
| 12463 | + "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" + |
---|
| 12464 | + "PARAM light2cam0 = program.env[10];" + |
---|
| 12465 | + "PARAM light2cam1 = program.env[11];" + |
---|
| 12466 | + "PARAM light2cam2 = program.env[12];" + |
---|
| 12467 | + "TEMP temp;" + |
---|
| 12468 | + "TEMP light;" + |
---|
| 12469 | + "TEMP ndotl;" + |
---|
| 12470 | + "TEMP normal;" + |
---|
| 12471 | + "TEMP depth;" + |
---|
| 12472 | + "TEMP eye;" + |
---|
| 12473 | + "TEMP pos;" + |
---|
| 12474 | + |
---|
| 12475 | + "MAD normal, fragment.color, zero123.z, -zero123.y;" + |
---|
| 12476 | + Normalize("normal") + |
---|
| 12477 | + "MOV light, state.light[0].position;" + |
---|
| 12478 | + "DP3 ndotl.x, light, normal;" + |
---|
| 12479 | + |
---|
| 12480 | + // shadow |
---|
| 12481 | + "MOV pos, fragment.texcoord[1];" + |
---|
| 12482 | + "MOV temp, pos;" + |
---|
| 12483 | + ShadowTextureFetch("depth", "temp", "1") + |
---|
| 12484 | + //"TEX depth, fragment.texcoord[1], texture[1], 2D;" + |
---|
| 12485 | + "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" + |
---|
| 12486 | + |
---|
| 12487 | + // No shadow when out of frustum |
---|
| 12488 | + //"SGE temp.y, depth.z, zero123.y;" + |
---|
| 12489 | + //"LRP temp.x, temp.y, zero123.y, temp.x;" + |
---|
| 12490 | + |
---|
| 12491 | + "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow |
---|
| 12492 | + |
---|
| 12493 | + // Backlit |
---|
| 12494 | + "MOV pos.w, zero123.y;" + |
---|
| 12495 | + "DP4 eye.x, pos, light2cam0;" + |
---|
| 12496 | + "DP4 eye.y, pos, light2cam1;" + |
---|
| 12497 | + "DP4 eye.z, pos, light2cam2;" + |
---|
| 12498 | + Normalize("eye") + |
---|
| 12499 | + |
---|
| 12500 | + "DP3 ndotl.y, -eye, normal;" + |
---|
| 12501 | + //"MUL ndotl.y, ndotl.y, pow2.x;" + |
---|
| 12502 | + "POW ndotl.y, ndotl.y, pow2.z;" + // backlit |
---|
| 12503 | + "SUB ndotl.y, zero123.y, ndotl.y;" + |
---|
| 12504 | + //"SUB ndotl.y, zero123.y, ndotl.y;" + |
---|
| 12505 | + //"MUL ndotl.y, ndotl.y, pow2.z;" + |
---|
| 12506 | + |
---|
| 12507 | + //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient |
---|
| 12508 | + //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient |
---|
| 12509 | + |
---|
| 12510 | + // Pigment |
---|
| 12511 | + "TEX temp, fragment.texcoord[0], texture[0], 2D;" + |
---|
| 12512 | + "LRP temp, zero123.w, temp, one;" + // texture proportion |
---|
| 12513 | + "MUL temp, temp, ndotl.x;" + |
---|
| 12514 | + |
---|
| 12515 | + "MUL temp, temp, zero123.z;" + |
---|
| 12516 | + |
---|
| 12517 | + //"MUL temp, temp, ndotl.y;" + |
---|
| 12518 | + |
---|
| 12519 | + "MOV temp.w, zero123.y;" + // reset alpha |
---|
| 12520 | + "MOV result.color, temp;" + |
---|
| 12521 | + "END"; |
---|
| 12522 | + |
---|
| 12523 | + String programmax = |
---|
| 12524 | + "!!ARBfp1.0\n" + |
---|
| 12525 | + |
---|
12251 | 12526 | //"OPTION ARB_fragment_program_shadow;" + |
---|
12252 | 12527 | "PARAM light2cam0 = program.env[10];" + |
---|
12253 | 12528 | "PARAM light2cam1 = program.env[11];" + |
---|
.. | .. |
---|
12362 | 12637 | "TEMP shininess;" + |
---|
12363 | 12638 | "\n" + |
---|
12364 | 12639 | "MOV texSamp, one;" + |
---|
12365 | | - //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" + |
---|
12366 | | - |
---|
| 12640 | + |
---|
12367 | 12641 | "MOV mapgrid.x, one2048th.x;" + |
---|
12368 | 12642 | "MOV temp, fragment.texcoord[1];" + |
---|
12369 | 12643 | /* |
---|
.. | .. |
---|
12384 | 12658 | "MUL temp, floor, mapgrid.x;" + |
---|
12385 | 12659 | //"TEX depth0, temp, texture[1], 2D;" + |
---|
12386 | 12660 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12387 | | - TextureFetch("depth0", "temp", "1") + |
---|
| 12661 | + ShadowTextureFetch("depth0", "temp", "1") + |
---|
12388 | 12662 | "") + |
---|
12389 | 12663 | "ADD temp.x, temp.x, mapgrid.x;" + |
---|
12390 | 12664 | //"TEX depth1, temp, texture[1], 2D;" + |
---|
12391 | 12665 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12392 | | - TextureFetch("depth1", "temp", "1") + |
---|
| 12666 | + ShadowTextureFetch("depth1", "temp", "1") + |
---|
12393 | 12667 | "") + |
---|
12394 | 12668 | "ADD temp.y, temp.y, mapgrid.x;" + |
---|
12395 | 12669 | //"TEX depth2, temp, texture[1], 2D;" + |
---|
12396 | | - TextureFetch("depth2", "temp", "1") + |
---|
| 12670 | + ShadowTextureFetch("depth2", "temp", "1") + |
---|
12397 | 12671 | "SUB temp.x, temp.x, mapgrid.x;" + |
---|
12398 | 12672 | //"TEX depth3, temp, texture[1], 2D;" + |
---|
12399 | 12673 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12400 | | - TextureFetch("depth3", "temp", "1") + |
---|
| 12674 | + ShadowTextureFetch("depth3", "temp", "1") + |
---|
12401 | 12675 | "") + |
---|
12402 | 12676 | //"MUL texSamp0, texSamp0, state.material.front.diffuse;" + |
---|
12403 | 12677 | //"MOV params, material;" + |
---|
.. | .. |
---|
12768 | 13042 | "MAD shadow.x, buffer.x, frac.y, shadow.x;" + |
---|
12769 | 13043 | "") + |
---|
12770 | 13044 | |
---|
12771 | | - // display shadow only (bump == 0) |
---|
| 13045 | + // display shadow only (fakedepth == 0) |
---|
12772 | 13046 | "SUB temp.x, half.x, shadow.x;" + |
---|
12773 | 13047 | "MOV temp.y, -params5.z;" + // params6.x;" + |
---|
12774 | | - "SLT temp.z, temp.y, -one2048th.x;" + |
---|
| 13048 | + "SLT temp.z, temp.y, -c256i.x;" + |
---|
12775 | 13049 | "SUB temp.y, one.x, temp.z;" + |
---|
12776 | 13050 | "MUL temp.x, temp.x, temp.y;" + |
---|
12777 | 13051 | "KIL temp.x;" + |
---|
.. | .. |
---|
13102 | 13376 | //once = true; |
---|
13103 | 13377 | } |
---|
13104 | 13378 | |
---|
| 13379 | + String program = programmax; |
---|
| 13380 | + |
---|
| 13381 | + if (Globals.MINSHADER) |
---|
| 13382 | + { |
---|
| 13383 | + program = programmin; |
---|
| 13384 | + } |
---|
| 13385 | + |
---|
13105 | 13386 | System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length()); |
---|
13106 | 13387 | System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : "")); |
---|
13107 | 13388 | loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program); |
---|
.. | .. |
---|
13195 | 13476 | return out; |
---|
13196 | 13477 | } |
---|
13197 | 13478 | |
---|
13198 | | - String TextureFetch(String dest, String src, String unit) |
---|
| 13479 | + // Also does frustum culling |
---|
| 13480 | + String ShadowTextureFetch(String dest, String src, String unit) |
---|
13199 | 13481 | { |
---|
13200 | 13482 | return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" + |
---|
13201 | 13483 | "SGE " + src + ".w, " + src + ".x, eps.x;" + |
---|
13202 | 13484 | "SGE " + src + ".z, " + src + ".y, eps.x;" + |
---|
| 13485 | + "SLT " + dest + ".x, " + src + ".x, one.x;" + |
---|
| 13486 | + "SLT " + dest + ".y, " + src + ".y, one.x;" + |
---|
13203 | 13487 | "MUL " + src + ".w, " + src + ".z, " + src + ".w;" + |
---|
13204 | | - "SLT " + src + ".z, " + src + ".x, one.x;" + |
---|
13205 | | - "MUL " + src + ".w, " + src + ".z, " + src + ".w;" + |
---|
13206 | | - "SLT " + src + ".z, " + src + ".y, one.x;" + |
---|
13207 | | - "MUL " + src + ".w, " + src + ".z, " + src + ".w;" + |
---|
| 13488 | + "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" + |
---|
| 13489 | + "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" + |
---|
13208 | 13490 | //"SWZ buffer, temp, w,w,w,w;"; |
---|
13209 | | - "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" + |
---|
| 13491 | + //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" + |
---|
13210 | 13492 | "SUB " + src + ".z, " + "one.x, " + src + ".w;" + |
---|
13211 | 13493 | //"MUL " + src + ".z, " + src + ".z, infinity.x;" + |
---|
13212 | 13494 | //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;"; |
---|
13213 | | - "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
| 13495 | + //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
13214 | 13496 | |
---|
13215 | | - //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;"; |
---|
13216 | | - //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;"; |
---|
| 13497 | + //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;"; |
---|
| 13498 | + "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
13217 | 13499 | } |
---|
13218 | 13500 | |
---|
13219 | 13501 | String Shadow(String depth, String shadow) |
---|
.. | .. |
---|
13260 | 13542 | "SLT temp.x, temp.x, zero.x;" + // shadoweps |
---|
13261 | 13543 | "LRP " + shadow + ", temp.x, one, " + shadow + ";" + |
---|
13262 | 13544 | |
---|
13263 | | - // No shadow when out of frustrum |
---|
| 13545 | + // No shadow when out of frustum |
---|
13264 | 13546 | "SGE temp.x, " + depth + ".z, one.z;" + |
---|
13265 | 13547 | "LRP " + shadow + ", temp.x, one, " + shadow + ";" + |
---|
13266 | 13548 | ""; |
---|
.. | .. |
---|
14058 | 14340 | drag = false; |
---|
14059 | 14341 | //System.out.println("Mouse DOWN"); |
---|
14060 | 14342 | editObj = false; |
---|
14061 | | - ClickInfo info = new ClickInfo(); |
---|
14062 | | - info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
14063 | | - info.pane = this; |
---|
14064 | | - info.camera = renderCamera; |
---|
14065 | | - info.x = x; |
---|
14066 | | - info.y = y; |
---|
14067 | | - info.modifiers = modifiersex; |
---|
14068 | | - editObj = object.doEditClick(info, 0); |
---|
| 14343 | + //ClickInfo info = new ClickInfo(); |
---|
| 14344 | + object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
| 14345 | + object.clickInfo.pane = this; |
---|
| 14346 | + object.clickInfo.camera = renderCamera; |
---|
| 14347 | + object.clickInfo.x = x; |
---|
| 14348 | + object.clickInfo.y = y; |
---|
| 14349 | + object.clickInfo.modifiers = modifiersex; |
---|
| 14350 | + editObj = object.doEditClick(//info, |
---|
| 14351 | + 0); |
---|
14069 | 14352 | if (!editObj) |
---|
14070 | 14353 | { |
---|
14071 | 14354 | hasMarquee = true; |
---|
.. | .. |
---|
14349 | 14632 | MODIFIERS |= COMMAND; |
---|
14350 | 14633 | /**/ |
---|
14351 | 14634 | if((mod&SHIFT) == SHIFT) |
---|
14352 | | - manipCamera.RotatePosition(0, -speed); |
---|
14353 | | - else |
---|
14354 | 14635 | manipCamera.BackForth(0, -speed*delta, 0); // getWidth()); |
---|
| 14636 | + else |
---|
| 14637 | + manipCamera.RotatePosition(0, -speed); |
---|
14355 | 14638 | /**/ |
---|
14356 | 14639 | if ((mod & SHIFT) == SHIFT) |
---|
14357 | 14640 | { |
---|
.. | .. |
---|
14370 | 14653 | MODIFIERS |= COMMAND; |
---|
14371 | 14654 | /**/ |
---|
14372 | 14655 | if((mod&SHIFT) == SHIFT) |
---|
14373 | | - manipCamera.RotatePosition(0, speed); |
---|
14374 | | - else |
---|
14375 | 14656 | manipCamera.BackForth(0, speed*delta, 0); // getWidth()); |
---|
| 14657 | + else |
---|
| 14658 | + manipCamera.RotatePosition(0, speed); |
---|
14376 | 14659 | /**/ |
---|
14377 | 14660 | if ((mod & SHIFT) == SHIFT) |
---|
14378 | 14661 | { |
---|
.. | .. |
---|
14465 | 14748 | if (editObj) |
---|
14466 | 14749 | { |
---|
14467 | 14750 | drag = true; |
---|
14468 | | - ClickInfo info = new ClickInfo(); |
---|
14469 | | - info.bounds.setBounds(0, 0, |
---|
| 14751 | + //ClickInfo info = new ClickInfo(); |
---|
| 14752 | + object.clickInfo.bounds.setBounds(0, 0, |
---|
14470 | 14753 | (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
14471 | | - info.pane = this; |
---|
14472 | | - info.camera = renderCamera; |
---|
14473 | | - info.x = x; |
---|
14474 | | - info.y = y; |
---|
14475 | | - object.GetWindow().copy |
---|
14476 | | - .doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0); |
---|
| 14754 | + object.clickInfo.pane = this; |
---|
| 14755 | + object.clickInfo.camera = renderCamera; |
---|
| 14756 | + object.clickInfo.x = x; |
---|
| 14757 | + object.clickInfo.y = y; |
---|
| 14758 | + object //.GetWindow().copy |
---|
| 14759 | + .doEditDrag(//info, |
---|
| 14760 | + (modifiers & MouseEvent.BUTTON3_MASK) != 0); |
---|
14477 | 14761 | } else |
---|
14478 | 14762 | { |
---|
14479 | 14763 | if (x < startX) |
---|
.. | .. |
---|
14622 | 14906 | } |
---|
14623 | 14907 | } |
---|
14624 | 14908 | |
---|
| 14909 | +// ClickInfo clickInfo = new ClickInfo(); |
---|
| 14910 | + |
---|
14625 | 14911 | public void mouseMoved(MouseEvent e) |
---|
14626 | 14912 | { |
---|
14627 | 14913 | //System.out.println("mouseMoved: " + e); |
---|
14628 | 14914 | if (isRenderer) |
---|
14629 | 14915 | return; |
---|
14630 | 14916 | |
---|
14631 | | - ClickInfo ci = new ClickInfo(); |
---|
14632 | | - ci.x = e.getX(); |
---|
14633 | | - ci.y = e.getY(); |
---|
14634 | | - ci.modifiers = e.getModifiersEx(); |
---|
14635 | | - ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
14636 | | - ci.pane = this; |
---|
14637 | | - ci.camera = renderCamera; |
---|
| 14917 | + // Mouse cursor feedback |
---|
| 14918 | + object.clickInfo.x = e.getX(); |
---|
| 14919 | + object.clickInfo.y = e.getY(); |
---|
| 14920 | + object.clickInfo.modifiers = e.getModifiersEx(); |
---|
| 14921 | + object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
| 14922 | + object.clickInfo.pane = this; |
---|
| 14923 | + object.clickInfo.camera = renderCamera; |
---|
14638 | 14924 | if (!isRenderer) |
---|
14639 | 14925 | { |
---|
14640 | 14926 | //ObjEditor editWindow = object.editWindow; |
---|
14641 | 14927 | //Object3D copy = editWindow.copy; |
---|
14642 | | - if (object.doEditClick(ci, 0)) |
---|
| 14928 | + if (object.doEditClick(//clickInfo, |
---|
| 14929 | + 0)) |
---|
14643 | 14930 | { |
---|
14644 | 14931 | setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
---|
14645 | 14932 | } else |
---|
.. | .. |
---|
14911 | 15198 | // break; |
---|
14912 | 15199 | case 'T': |
---|
14913 | 15200 | CACHETEXTURE ^= true; |
---|
14914 | | - textures.clear(); |
---|
| 15201 | + texturepigment.clear(); |
---|
| 15202 | + texturebump.clear(); |
---|
14915 | 15203 | // repaint(); |
---|
14916 | 15204 | break; |
---|
14917 | 15205 | case 'Y': |
---|
.. | .. |
---|
15088 | 15376 | OCCLUSION_CULLING ^= true; |
---|
15089 | 15377 | System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING); |
---|
15090 | 15378 | break; |
---|
15091 | | - case '0': envyoff ^= true; repaint(); break; |
---|
| 15379 | + //case '0': envyoff ^= true; repaint(); break; |
---|
15092 | 15380 | case '1': |
---|
15093 | 15381 | case '2': |
---|
15094 | 15382 | case '3': |
---|
15095 | 15383 | case '4': |
---|
15096 | 15384 | case '5': |
---|
15097 | | - newenvy = Character.getNumericValue(key); |
---|
15098 | | - repaint(); |
---|
15099 | | - break; |
---|
15100 | 15385 | case '6': |
---|
15101 | 15386 | case '7': |
---|
15102 | 15387 | case '8': |
---|
15103 | 15388 | case '9': |
---|
15104 | | - BGcolor = (key - '6')/3.f; |
---|
| 15389 | + if (true) // envyoff) |
---|
| 15390 | + { |
---|
| 15391 | + BGcolor = (key - '1')/8.f; |
---|
| 15392 | + } |
---|
| 15393 | + else |
---|
| 15394 | + { |
---|
| 15395 | + //newenvy = Character.getNumericValue(key); |
---|
| 15396 | + } |
---|
15105 | 15397 | repaint(); |
---|
15106 | 15398 | break; |
---|
15107 | 15399 | case '!': |
---|
.. | .. |
---|
15664 | 15956 | |
---|
15665 | 15957 | int width = getBounds().width; |
---|
15666 | 15958 | int height = getBounds().height; |
---|
15667 | | - ClickInfo info = new ClickInfo(); |
---|
15668 | | - info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom)); |
---|
15669 | 15959 | //Image img = CreateImage(width, height); |
---|
15670 | 15960 | //System.out.println("width = " + width + "; height = " + height + "\n"); |
---|
15671 | 15961 | |
---|
.. | .. |
---|
15742 | 16032 | } |
---|
15743 | 16033 | if (object != null && !hasMarquee) |
---|
15744 | 16034 | { |
---|
| 16035 | + if (object.clickInfo == null) |
---|
| 16036 | + object.clickInfo = new ClickInfo(); |
---|
| 16037 | + ClickInfo info = object.clickInfo; |
---|
| 16038 | + //ClickInfo info = new ClickInfo(); |
---|
| 16039 | + info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom)); |
---|
| 16040 | + |
---|
15745 | 16041 | if (isRenderer) |
---|
15746 | 16042 | { |
---|
15747 | | - info.flags++; |
---|
| 16043 | + object.clickInfo.flags++; |
---|
15748 | 16044 | double frameAspect = (double) width / (double) height; |
---|
15749 | 16045 | if (frameAspect > renderCamera.aspect) |
---|
15750 | 16046 | { |
---|
15751 | 16047 | int desired = (int) ((double) height * renderCamera.aspect); |
---|
15752 | | - info.bounds.width -= width - desired; |
---|
15753 | | - info.bounds.x += (width - desired) / 2; |
---|
| 16048 | + object.clickInfo.bounds.width -= width - desired; |
---|
| 16049 | + object.clickInfo.bounds.x += (width - desired) / 2; |
---|
15754 | 16050 | } else |
---|
15755 | 16051 | { |
---|
15756 | 16052 | int desired = (int) ((double) width / renderCamera.aspect); |
---|
15757 | | - info.bounds.height -= height - desired; |
---|
15758 | | - info.bounds.y += (height - desired) / 2; |
---|
| 16053 | + object.clickInfo.bounds.height -= height - desired; |
---|
| 16054 | + object.clickInfo.bounds.y += (height - desired) / 2; |
---|
15759 | 16055 | } |
---|
15760 | 16056 | } |
---|
15761 | 16057 | |
---|
15762 | | - info.g = gr; |
---|
15763 | | - info.camera = renderCamera; |
---|
| 16058 | + object.clickInfo.g = gr; |
---|
| 16059 | + object.clickInfo.camera = renderCamera; |
---|
15764 | 16060 | /* |
---|
15765 | 16061 | // Memory intensive (brep.verticescopy) |
---|
15766 | 16062 | if (!(object instanceof Composite)) |
---|
15767 | 16063 | object.draw(info, 0, false); // SLOW : |
---|
15768 | 16064 | */ |
---|
15769 | | - if (!isRenderer) |
---|
| 16065 | + if (!isRenderer) // && drag) |
---|
15770 | 16066 | { |
---|
15771 | 16067 | Grafreed.Assert(object != null); |
---|
15772 | 16068 | Grafreed.Assert(object.selection != null); |
---|
.. | .. |
---|
15774 | 16070 | { |
---|
15775 | 16071 | int hitSomething = object.selection.get(0).hitSomething; |
---|
15776 | 16072 | |
---|
15777 | | - info.DX = 0; |
---|
15778 | | - info.DY = 0; |
---|
15779 | | - info.W = 1; |
---|
| 16073 | + object.clickInfo.DX = 0; |
---|
| 16074 | + object.clickInfo.DY = 0; |
---|
| 16075 | + object.clickInfo.W = 1; |
---|
15780 | 16076 | if (hitSomething == Object3D.hitCenter) |
---|
15781 | 16077 | { |
---|
15782 | 16078 | info.DX = X; |
---|
.. | .. |
---|
15788 | 16084 | info.DY -= info.bounds.height/2; |
---|
15789 | 16085 | } |
---|
15790 | 16086 | |
---|
15791 | | - object.drawEditHandles(info, 0); |
---|
| 16087 | + object.drawEditHandles(//info, |
---|
| 16088 | + 0); |
---|
15792 | 16089 | |
---|
15793 | 16090 | if (drag && (X != 0 || Y != 0)) |
---|
15794 | 16091 | { |
---|
.. | .. |
---|
16287 | 16584 | private /*static*/ boolean firstime; |
---|
16288 | 16585 | private /*static*/ cVector newView = new cVector(); |
---|
16289 | 16586 | private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"}; |
---|
| 16587 | + private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"}; |
---|
| 16588 | + private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"}; |
---|
16290 | 16589 | private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X, |
---|
16291 | 16590 | GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X, |
---|
16292 | 16591 | GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y, |
---|
.. | .. |
---|
16299 | 16598 | { |
---|
16300 | 16599 | com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP); |
---|
16301 | 16600 | |
---|
| 16601 | + int usedsuf = 0; |
---|
| 16602 | + |
---|
16302 | 16603 | for (int i = 0; i < suffixes.length; i++) |
---|
16303 | 16604 | { |
---|
16304 | | - String resourceName = basename + suffixes[i] + "." + suffix; |
---|
16305 | | - TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
16306 | | - mipmapped, |
---|
16307 | | - FileUtil.getFileSuffix(resourceName)); |
---|
16308 | | - if (data == null) |
---|
| 16605 | + String[] suffixe = suffixes; |
---|
| 16606 | + String[] fallback = suffixes2; |
---|
| 16607 | + String[] fallfallback = suffixes3; |
---|
| 16608 | + |
---|
| 16609 | + for (int c=usedsuf; --c>=0;) |
---|
16309 | 16610 | { |
---|
16310 | | - throw new IOException("Unable to load texture " + resourceName); |
---|
| 16611 | +// String[] temp = suffixe; |
---|
| 16612 | +// suffixe = fallback; |
---|
| 16613 | +// fallback = fallfallback; |
---|
| 16614 | +// fallfallback = temp; |
---|
16311 | 16615 | } |
---|
| 16616 | + |
---|
| 16617 | + String resourceName = basename + suffixe[i] + "." + suffix; |
---|
| 16618 | + TextureData data; |
---|
| 16619 | + |
---|
| 16620 | + try |
---|
| 16621 | + { |
---|
| 16622 | + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
| 16623 | + mipmapped, |
---|
| 16624 | + FileUtil.getFileSuffix(resourceName)); |
---|
| 16625 | + } |
---|
| 16626 | + catch (Exception e) |
---|
| 16627 | + { |
---|
| 16628 | + try |
---|
| 16629 | + { |
---|
| 16630 | + resourceName = basename + fallback[i] + "." + suffix; |
---|
| 16631 | + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
| 16632 | + mipmapped, |
---|
| 16633 | + FileUtil.getFileSuffix(resourceName)); |
---|
| 16634 | + } |
---|
| 16635 | + catch (Exception e2) |
---|
| 16636 | + { |
---|
| 16637 | + resourceName = basename + fallfallback[i] + "." + suffix; |
---|
| 16638 | + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
| 16639 | + mipmapped, |
---|
| 16640 | + FileUtil.getFileSuffix(resourceName)); |
---|
| 16641 | + } |
---|
| 16642 | + } |
---|
| 16643 | + |
---|
16312 | 16644 | //System.out.println("Target = " + targets[i]); |
---|
16313 | 16645 | cubemap.updateImage(data, targets[i]); |
---|
16314 | 16646 | } |
---|
16315 | 16647 | |
---|
16316 | 16648 | return cubemap; |
---|
16317 | 16649 | } |
---|
| 16650 | + |
---|
16318 | 16651 | int bigsphere = -1; |
---|
16319 | 16652 | |
---|
16320 | 16653 | float BGcolor = 0.5f; |
---|
16321 | 16654 | |
---|
16322 | | - private void DrawSkyBox(GL gl) |
---|
| 16655 | + float ambientLight[] = {1f, 1f, 1f, 1.0f}; |
---|
| 16656 | + |
---|
| 16657 | + private void DrawSkyBox(GL gl, float ratio) |
---|
16323 | 16658 | { |
---|
16324 | | - if (envyoff || cubemap == null) |
---|
| 16659 | + if (//envyoff || |
---|
| 16660 | + cubemap == null) |
---|
16325 | 16661 | { |
---|
16326 | 16662 | gl.glClearColor(BGcolor, BGcolor, BGcolor, 1); |
---|
16327 | 16663 | gl.glClear(gl.GL_COLOR_BUFFER_BIT); |
---|
.. | .. |
---|
16336 | 16672 | // Compensates for ExaminerViewer's modification of modelview matrix |
---|
16337 | 16673 | gl.glMatrixMode(GL.GL_MODELVIEW); |
---|
16338 | 16674 | gl.glLoadIdentity(); |
---|
| 16675 | + gl.glScalef(1,ratio,1); |
---|
16339 | 16676 | |
---|
| 16677 | +// colorV[0] = 2; |
---|
| 16678 | +// colorV[1] = 2; |
---|
| 16679 | +// colorV[2] = 2; |
---|
| 16680 | +// colorV[3] = 1; |
---|
| 16681 | +// gl.glDisable(gl.GL_COLOR_MATERIAL); |
---|
| 16682 | +// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0); |
---|
| 16683 | +// |
---|
| 16684 | +// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0); |
---|
| 16685 | + |
---|
16340 | 16686 | //gl.glActiveTexture(GL.GL_TEXTURE1); |
---|
16341 | 16687 | //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP); |
---|
16342 | 16688 | |
---|
.. | .. |
---|
16368 | 16714 | { |
---|
16369 | 16715 | gl.glScalef(1.0f, -1.0f, 1.0f); |
---|
16370 | 16716 | } |
---|
| 16717 | + gl.glScalef(-1.0f, 1.0f, 1.0f); |
---|
16371 | 16718 | gl.glMultMatrixd(viewrot_1, 0); |
---|
16372 | 16719 | gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f); |
---|
16373 | 16720 | //viewer.updateInverseRotation(gl); |
---|
.. | .. |
---|
16626 | 16973 | //new Exception().printStackTrace(); |
---|
16627 | 16974 | System.out.println("select buffer init"); |
---|
16628 | 16975 | // Use debug pipeline |
---|
16629 | | - drawable.setGL(new DebugGL(drawable.getGL())); |
---|
| 16976 | + //drawable.setGL(new DebugGL(drawable.getGL())); |
---|
16630 | 16977 | |
---|
16631 | 16978 | GL gl = drawable.getGL(); |
---|
16632 | 16979 | |
---|