.. | .. |
---|
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 | |
---|
2408 | | - private BufferedImage CreateBim(TextureData texturedata) |
---|
| 2458 | + static private BufferedImage CreateBim(TextureData texturedata) |
---|
2409 | 2459 | { |
---|
2410 | | - // cache to disk |
---|
2411 | | - Buffer buffer = texturedata.getBuffer(); // getMipmapData(); |
---|
2412 | | - //buffers[0]. |
---|
2413 | | - ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer(); |
---|
2414 | | - int[] pixels = new int[bytebuf.capacity()/3]; |
---|
2415 | | - int width = texturedata.getWidth(); //(int)Math.sqrt(pixels.length); // squared |
---|
2416 | | - int height = width; |
---|
2417 | | - for (int i=pixels.length; --i>=0;) |
---|
2418 | | - { |
---|
2419 | | - int i3 = i*3; |
---|
2420 | | - pixels[i] = 0xFF; |
---|
2421 | | - pixels[i] <<= 8; |
---|
2422 | | - pixels[i] |= bytebuf.get(i3+2) & 0xFF; |
---|
2423 | | - pixels[i] <<= 8; |
---|
2424 | | - pixels[i] |= bytebuf.get(i3+1) & 0xFF; |
---|
2425 | | - pixels[i] <<= 8; |
---|
2426 | | - pixels[i] |= bytebuf.get(i3) & 0xFF; |
---|
2427 | | - } |
---|
2428 | | - /* |
---|
2429 | | - int r=0,g=0,b=0,a=0; |
---|
2430 | | - for (int i=0; i<width; i++) |
---|
2431 | | - for (int j=0; j<height; j++) |
---|
2432 | | - { |
---|
2433 | | - int index = j*width+i; |
---|
2434 | | - int p = pixels[index]; |
---|
2435 | | - a = ((p>>24) & 0xFF); |
---|
2436 | | - r = ((p>>16) & 0xFF); |
---|
2437 | | - g = ((p>>8) & 0xFF); |
---|
2438 | | - b = (p & 0xFF); |
---|
2439 | | - pixels[index] = (a<<24) | (b<<16) | (g<<8) | r; |
---|
2440 | | - } |
---|
2441 | | - /**/ |
---|
2442 | | - BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile); |
---|
2443 | | - rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width); |
---|
2444 | | - return rendImage; |
---|
| 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); |
---|
2445 | 2471 | } |
---|
2446 | 2472 | |
---|
2447 | 2473 | /**/ |
---|
.. | .. |
---|
2452 | 2478 | |
---|
2453 | 2479 | int resolution; |
---|
2454 | 2480 | |
---|
2455 | | - CacheTexture(com.sun.opengl.util.texture.Texture tex, int res) |
---|
| 2481 | + CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res) |
---|
2456 | 2482 | { |
---|
2457 | | - texture = tex; |
---|
| 2483 | + texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata); |
---|
| 2484 | + texturedata = texdata; |
---|
2458 | 2485 | resolution = res; |
---|
2459 | 2486 | } |
---|
2460 | 2487 | } |
---|
2461 | 2488 | /**/ |
---|
2462 | 2489 | |
---|
2463 | 2490 | // TEXTURE static Texture texture; |
---|
2464 | | - static public java.util.Hashtable<String, CacheTexture> textures = new java.util.Hashtable<String, CacheTexture>(); |
---|
2465 | | - static public java.util.Hashtable<BufferedImage, CacheTexture> bimtextures = new java.util.Hashtable<BufferedImage, CacheTexture>(); |
---|
2466 | | - 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>(); |
---|
2467 | 2495 | |
---|
2468 | 2496 | int pigmentdepth = 0; |
---|
2469 | 2497 | public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536]; |
---|
.. | .. |
---|
2471 | 2499 | public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536]; |
---|
2472 | 2500 | //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE"; |
---|
2473 | 2501 | public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP"); |
---|
2474 | | - public static String NOISE_TEXTURE = "WHITE_NOISE"; |
---|
| 2502 | + public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:"); |
---|
2475 | 2503 | // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL"); |
---|
2476 | 2504 | |
---|
2477 | | - com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump) |
---|
| 2505 | + com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump) |
---|
2478 | 2506 | { |
---|
2479 | 2507 | TextureData texturedata = null; |
---|
2480 | 2508 | |
---|
.. | .. |
---|
2493 | 2521 | if (bump) |
---|
2494 | 2522 | texturedata = ConvertBump(texturedata, false); |
---|
2495 | 2523 | |
---|
2496 | | - com.sun.opengl.util.texture.Texture texture = |
---|
2497 | | - 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); |
---|
2498 | 2526 | |
---|
2499 | | - texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT); |
---|
2500 | | - 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); |
---|
2501 | 2529 | |
---|
2502 | | - return texture; |
---|
| 2530 | + return texturedata; |
---|
2503 | 2531 | } |
---|
2504 | 2532 | |
---|
2505 | | - com.sun.opengl.util.texture.Texture GetBimTexture(BufferedImage name, boolean bump) |
---|
| 2533 | + com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump) |
---|
2506 | 2534 | { |
---|
2507 | 2535 | TextureData texturedata = null; |
---|
2508 | 2536 | |
---|
.. | .. |
---|
2510 | 2538 | { |
---|
2511 | 2539 | texturedata = |
---|
2512 | 2540 | com.sun.opengl.util.texture.TextureIO.newTextureData( |
---|
2513 | | - name, |
---|
| 2541 | + bim, |
---|
2514 | 2542 | true); |
---|
2515 | 2543 | } catch (Exception e) |
---|
2516 | 2544 | { |
---|
.. | .. |
---|
2519 | 2547 | |
---|
2520 | 2548 | if (bump) |
---|
2521 | 2549 | texturedata = ConvertBump(texturedata, false); |
---|
2522 | | - |
---|
2523 | | - com.sun.opengl.util.texture.Texture texture = |
---|
2524 | | - com.sun.opengl.util.texture.TextureIO.newTexture(texturedata); |
---|
2525 | | - |
---|
2526 | | - texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT); |
---|
2527 | | - texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT); |
---|
2528 | | - |
---|
2529 | | - return texture; |
---|
| 2550 | + |
---|
| 2551 | + return texturedata; |
---|
2530 | 2552 | } |
---|
2531 | 2553 | |
---|
2532 | 2554 | boolean HUESMOOTH = true; // wrap around bug... true; |
---|
.. | .. |
---|
8014 | 8036 | pigment = null; |
---|
8015 | 8037 | } |
---|
8016 | 8038 | |
---|
8017 | | - ReleaseTexture(bump, true); |
---|
8018 | | - ReleaseTexture(pigment, false); |
---|
| 8039 | + ReleaseTexture(tex, true); |
---|
| 8040 | + ReleaseTexture(tex, false); |
---|
8019 | 8041 | } |
---|
8020 | 8042 | |
---|
8021 | 8043 | public void ReleasePigmentTexture(cTexture tex) // INTERFACE |
---|
.. | .. |
---|
8044 | 8066 | pigment = null; |
---|
8045 | 8067 | } |
---|
8046 | 8068 | |
---|
8047 | | - ReleaseTexture(pigment, false); |
---|
| 8069 | + ReleaseTexture(tex, false); |
---|
8048 | 8070 | } |
---|
8049 | 8071 | |
---|
8050 | 8072 | public void ReleaseBumpTexture(cTexture tex) // INTERFACE |
---|
.. | .. |
---|
8073 | 8095 | bump = null; |
---|
8074 | 8096 | } |
---|
8075 | 8097 | |
---|
8076 | | - ReleaseTexture(bump, true); |
---|
| 8098 | + ReleaseTexture(tex, true); |
---|
8077 | 8099 | } |
---|
8078 | 8100 | |
---|
8079 | | - void ReleaseTexture(String tex, boolean bump) |
---|
| 8101 | + void ReleaseTexture(cTexture tex, boolean bump) |
---|
8080 | 8102 | { |
---|
8081 | 8103 | if (// DrawMode() != 0 || /*tex == null ||*/ |
---|
8082 | 8104 | ambientOcclusion ) // || !textureon) |
---|
.. | .. |
---|
8087 | 8109 | CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null; |
---|
8088 | 8110 | |
---|
8089 | 8111 | if (tex != null) |
---|
8090 | | - texture = textures.get(tex); |
---|
| 8112 | + texture = bump ? texturebump.get(tex) : texturepigment.get(tex); |
---|
8091 | 8113 | |
---|
8092 | 8114 | // //assert( texture != null ); |
---|
8093 | 8115 | // if (texture == null) |
---|
.. | .. |
---|
8237 | 8259 | |
---|
8238 | 8260 | if (tex == null) |
---|
8239 | 8261 | { |
---|
8240 | | - BindTexture(null, null,false,resolution); |
---|
| 8262 | + BindTexture(null,false,resolution); |
---|
8241 | 8263 | return; |
---|
8242 | 8264 | } |
---|
8243 | 8265 | |
---|
8244 | 8266 | String pigment = Object3D.GetPigment(tex); |
---|
8245 | 8267 | |
---|
8246 | | - usedtextures.add(pigment); |
---|
| 8268 | + usedtextures.add(tex); |
---|
8247 | 8269 | |
---|
8248 | 8270 | //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
8249 | 8271 | { |
---|
.. | .. |
---|
8257 | 8279 | } |
---|
8258 | 8280 | |
---|
8259 | 8281 | GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
8260 | | - BindTexture(tex.pigmenttexture, pigment, false, resolution); |
---|
| 8282 | + BindTexture(tex, false, resolution); |
---|
8261 | 8283 | } |
---|
8262 | 8284 | |
---|
8263 | 8285 | /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE |
---|
.. | .. |
---|
8270 | 8292 | |
---|
8271 | 8293 | if (tex == null) |
---|
8272 | 8294 | { |
---|
8273 | | - BindTexture(null, null,true,resolution); |
---|
| 8295 | + BindTexture(null,true,resolution); |
---|
8274 | 8296 | return; |
---|
8275 | 8297 | } |
---|
8276 | 8298 | |
---|
8277 | 8299 | String bump = Object3D.GetBump(tex); |
---|
8278 | 8300 | |
---|
8279 | | - usedtextures.add(bump); |
---|
| 8301 | + usedtextures.add(tex); |
---|
8280 | 8302 | |
---|
8281 | 8303 | //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
8282 | 8304 | { |
---|
.. | .. |
---|
8290 | 8312 | } |
---|
8291 | 8313 | |
---|
8292 | 8314 | GetGL().glActiveTexture(GetGL().GL_TEXTURE2); |
---|
8293 | | - BindTexture(tex.bumptexture, bump, true, resolution); |
---|
| 8315 | + BindTexture(tex, true, resolution); |
---|
8294 | 8316 | GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
8295 | 8317 | } |
---|
8296 | 8318 | |
---|
.. | .. |
---|
8314 | 8336 | return fileExists; |
---|
8315 | 8337 | } |
---|
8316 | 8338 | |
---|
8317 | | - 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 |
---|
8318 | 8340 | { |
---|
8319 | 8341 | CacheTexture texturecache = null; |
---|
8320 | 8342 | |
---|
8321 | 8343 | if (tex != null) |
---|
8322 | 8344 | { |
---|
8323 | | - 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 | + } |
---|
8324 | 8352 | |
---|
8325 | 8353 | String fallbackTextureName = defaultDirectory + "/Textures/" + texname; |
---|
8326 | 8354 | |
---|
.. | .. |
---|
8330 | 8358 | // else |
---|
8331 | 8359 | // if (!texname.startsWith("/")) |
---|
8332 | 8360 | // texname = "/Users/nbriere/Textures/" + texname; |
---|
8333 | | - if (!FileExists(tex)) |
---|
| 8361 | + if (!FileExists(texname)) |
---|
8334 | 8362 | { |
---|
8335 | 8363 | texname = fallbackTextureName; |
---|
8336 | 8364 | } |
---|
8337 | 8365 | |
---|
8338 | 8366 | if (CACHETEXTURE) |
---|
8339 | 8367 | { |
---|
8340 | | - if (bim == null) |
---|
8341 | | - texturecache = textures.get(texname); // TEXTURE CACHE |
---|
| 8368 | + if (texdata == null) |
---|
| 8369 | + texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex); |
---|
8342 | 8370 | else |
---|
8343 | | - texturecache = bimtextures.get(bim); // TEXTURE CACHE |
---|
| 8371 | + texturecache = bimtextures.get(texdata); |
---|
8344 | 8372 | } |
---|
8345 | 8373 | |
---|
8346 | | - if (texturecache == null || texturecache.resolution < resolution) |
---|
| 8374 | + if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution) |
---|
8347 | 8375 | { |
---|
8348 | 8376 | TextureData texturedata = null; |
---|
8349 | 8377 | |
---|
8350 | | - if (bim != null) |
---|
| 8378 | + if (texdata != null && textureon) |
---|
8351 | 8379 | { |
---|
| 8380 | + BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB); |
---|
| 8381 | + |
---|
| 8382 | + try |
---|
| 8383 | + { |
---|
| 8384 | + bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph); |
---|
| 8385 | + } |
---|
| 8386 | + catch (Exception e) |
---|
| 8387 | + { |
---|
| 8388 | + bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph); |
---|
| 8389 | + } |
---|
| 8390 | + |
---|
8352 | 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; |
---|
8353 | 8398 | } |
---|
8354 | 8399 | else |
---|
8355 | | - if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals("")) |
---|
| 8400 | + if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals("")) |
---|
8356 | 8401 | { |
---|
8357 | 8402 | assert(!bump); |
---|
8358 | 8403 | // if (bump) |
---|
.. | .. |
---|
8363 | 8408 | // } |
---|
8364 | 8409 | // else |
---|
8365 | 8410 | // { |
---|
8366 | | - texturecache = textures.get(tex); |
---|
| 8411 | + // texturecache = textures.get(texname); // suspicious |
---|
8367 | 8412 | if (texturecache == null) |
---|
8368 | 8413 | { |
---|
8369 | 8414 | texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
.. | .. |
---|
8372 | 8417 | new Exception().printStackTrace(); |
---|
8373 | 8418 | // } |
---|
8374 | 8419 | } else |
---|
8375 | | - if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals("")) |
---|
| 8420 | + if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals("")) |
---|
8376 | 8421 | { |
---|
8377 | 8422 | assert(bump); |
---|
8378 | | - texturecache = textures.get(tex); |
---|
| 8423 | + // texturecache = textures.get(texname); // suspicious |
---|
8379 | 8424 | if (texturecache == null) |
---|
8380 | 8425 | texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
8381 | 8426 | else |
---|
.. | .. |
---|
8387 | 8432 | // texture = GetResourceTexture("default.png"); |
---|
8388 | 8433 | //} else |
---|
8389 | 8434 | //{ |
---|
8390 | | - if (tex.equals("WHITE_NOISE")) |
---|
| 8435 | + if (texname.endsWith("WHITE_NOISE")) |
---|
8391 | 8436 | { |
---|
8392 | | - texturecache = textures.get(tex); |
---|
| 8437 | + // texturecache = textures.get(texname); // suspicious |
---|
8393 | 8438 | if (texturecache == null) |
---|
8394 | 8439 | texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution); |
---|
8395 | 8440 | else |
---|
.. | .. |
---|
8452 | 8497 | if (texturedata == null) |
---|
8453 | 8498 | throw new Exception(); |
---|
8454 | 8499 | |
---|
8455 | | - texturecache = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution); |
---|
| 8500 | + texturecache = new CacheTexture(texturedata,resolution); |
---|
8456 | 8501 | //texture = GetTexture(tex, bump); |
---|
8457 | 8502 | } |
---|
8458 | 8503 | } |
---|
8459 | 8504 | //} |
---|
8460 | 8505 | } |
---|
8461 | 8506 | |
---|
8462 | | - if (/*CACHETEXTURE &&*/ texturecache != null && textureon) |
---|
| 8507 | + if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon) |
---|
8463 | 8508 | { |
---|
8464 | 8509 | //return false; |
---|
8465 | | - assert(bim == null); |
---|
8466 | 8510 | |
---|
8467 | 8511 | // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")"); |
---|
8468 | 8512 | if (texturedata != null && texname.toLowerCase().endsWith(".jpg")) |
---|
.. | .. |
---|
8509 | 8553 | } |
---|
8510 | 8554 | } |
---|
8511 | 8555 | } |
---|
8512 | | - |
---|
| 8556 | + |
---|
| 8557 | + Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment; |
---|
| 8558 | + |
---|
8513 | 8559 | //System.out.println("Texture = " + tex); |
---|
8514 | | - if (textures.containsKey(texname)) |
---|
| 8560 | + if (textures.containsKey(tex)) |
---|
8515 | 8561 | { |
---|
8516 | | - CacheTexture thetex = textures.get(texname); |
---|
| 8562 | + CacheTexture thetex = textures.get(tex); |
---|
8517 | 8563 | thetex.texture.disable(); |
---|
8518 | 8564 | thetex.texture.dispose(); |
---|
8519 | | - textures.remove(texname); |
---|
| 8565 | + textures.remove(tex); |
---|
8520 | 8566 | } |
---|
8521 | 8567 | |
---|
8522 | 8568 | //texture.texturedata = texturedata; |
---|
8523 | | - textures.put(texname, texturecache); |
---|
| 8569 | + textures.put(tex, texturecache); |
---|
8524 | 8570 | |
---|
8525 | 8571 | // newtex = true; |
---|
8526 | 8572 | } |
---|
.. | .. |
---|
8541 | 8587 | |
---|
8542 | 8588 | static void EmbedTextures(cTexture tex) |
---|
8543 | 8589 | { |
---|
| 8590 | + if (tex.pigmentdata == null) |
---|
| 8591 | + { |
---|
| 8592 | + //String texname = Object3D.GetPigment(tex); |
---|
| 8593 | + |
---|
| 8594 | + CacheTexture texturecache = texturepigment.get(tex); |
---|
| 8595 | + |
---|
| 8596 | + if (texturecache != null) |
---|
| 8597 | + { |
---|
| 8598 | + tex.pw = texturecache.texturedata.getWidth(); |
---|
| 8599 | + tex.ph = texturecache.texturedata.getHeight(); |
---|
| 8600 | + tex.pigmentdata = //CompressJPEG(CreateBim |
---|
| 8601 | + ((ByteBuffer)texturecache.texturedata.getBuffer()).array() |
---|
| 8602 | + ; |
---|
| 8603 | + //, tex.pw, tex.ph), 0.5f); |
---|
| 8604 | + } |
---|
| 8605 | + } |
---|
8544 | 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 | + } |
---|
8545 | 8620 | } |
---|
8546 | 8621 | |
---|
8547 | | - com.sun.opengl.util.texture.Texture GetTexture(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception |
---|
| 8622 | + com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8548 | 8623 | { |
---|
8549 | | - CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution); |
---|
| 8624 | + CacheTexture texture = GetCacheTexture(tex, bump, resolution); |
---|
8550 | 8625 | |
---|
8551 | 8626 | if (bump) |
---|
8552 | 8627 | { |
---|
.. | .. |
---|
8562 | 8637 | return texture!=null?texture.texture:null; |
---|
8563 | 8638 | } |
---|
8564 | 8639 | |
---|
8565 | | - 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 |
---|
8566 | 8641 | { |
---|
8567 | | - CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution); |
---|
| 8642 | + CacheTexture texture = GetCacheTexture(tex, bump, resolution); |
---|
8568 | 8643 | |
---|
8569 | 8644 | return texture!=null?texture.texturedata:null; |
---|
8570 | 8645 | } |
---|
8571 | 8646 | |
---|
8572 | | - 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 |
---|
8573 | 8648 | { |
---|
8574 | 8649 | if (/*tex == null ||*/ ambientOcclusion ) // || !textureon) |
---|
8575 | 8650 | { |
---|
.. | .. |
---|
8578 | 8653 | |
---|
8579 | 8654 | //boolean newtex = false; |
---|
8580 | 8655 | |
---|
8581 | | - com.sun.opengl.util.texture.Texture texture = GetTexture(stream, tex, bump, resolution); |
---|
| 8656 | + com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution); |
---|
8582 | 8657 | |
---|
8583 | 8658 | if (texture == null) |
---|
8584 | 8659 | return false; |
---|
.. | .. |
---|
8611 | 8686 | return true; // Warning: not used. |
---|
8612 | 8687 | } |
---|
8613 | 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 | + |
---|
8614 | 8755 | ShadowBuffer shadowPBuf; |
---|
8615 | 8756 | AntialiasBuffer antialiasPBuf; |
---|
8616 | 8757 | int MAXSTACK; |
---|
.. | .. |
---|
8803 | 8944 | |
---|
8804 | 8945 | if (cubemap == null) |
---|
8805 | 8946 | { |
---|
8806 | | - LoadEnvy(5); |
---|
| 8947 | + //LoadEnvy(1); |
---|
8807 | 8948 | } |
---|
8808 | 8949 | |
---|
8809 | 8950 | //cubemap.enable(); |
---|
.. | .. |
---|
9090 | 9231 | cubemap = null; |
---|
9091 | 9232 | return; |
---|
9092 | 9233 | case 1: |
---|
9093 | | - name = "cubemaps/box_"; |
---|
9094 | | - ext = "png"; |
---|
| 9234 | + name = "cubemaps/rgb/"; |
---|
| 9235 | + ext = "jpg"; |
---|
9095 | 9236 | reverseUP = false; |
---|
9096 | 9237 | break; |
---|
9097 | 9238 | case 2: |
---|
9098 | | - name = "cubemaps/uffizi_"; |
---|
9099 | | - ext = "png"; |
---|
9100 | | - break; // reverseUP = true; break; |
---|
| 9239 | + name = "cubemaps/uffizi/"; |
---|
| 9240 | + ext = "jpg"; |
---|
| 9241 | + reverseUP = false; |
---|
| 9242 | + break; |
---|
9101 | 9243 | case 3: |
---|
9102 | | - name = "cubemaps/CloudyHills_"; |
---|
9103 | | - ext = "tga"; |
---|
| 9244 | + name = "cubemaps/CloudyHills/"; |
---|
| 9245 | + ext = "jpg"; |
---|
9104 | 9246 | reverseUP = false; |
---|
9105 | 9247 | break; |
---|
9106 | 9248 | case 4: |
---|
9107 | | - name = "cubemaps/cornell_"; |
---|
| 9249 | + name = "cubemaps/cornell/"; |
---|
9108 | 9250 | ext = "png"; |
---|
9109 | 9251 | reverseUP = false; |
---|
9110 | 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; |
---|
9111 | 9278 | default: |
---|
9112 | | - name = "cubemaps/rgb_"; |
---|
9113 | | - ext = "png"; /*mipmap = true;*/ reverseUP = false; |
---|
| 9279 | + name = "cubemaps/box/"; |
---|
| 9280 | + ext = "png"; /*mipmap = true;*/ |
---|
| 9281 | + reverseUP = false; |
---|
9114 | 9282 | break; |
---|
9115 | 9283 | } |
---|
9116 | | - |
---|
9117 | | - try |
---|
9118 | | - { |
---|
9119 | | - cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap); |
---|
9120 | | - } catch (IOException e) |
---|
9121 | | - { |
---|
9122 | | - throw new RuntimeException(e); |
---|
9123 | | - } |
---|
| 9284 | + |
---|
| 9285 | + LoadSkybox(name, ext, mipmap); |
---|
9124 | 9286 | } |
---|
9125 | 9287 | |
---|
9126 | 9288 | public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) |
---|
.. | .. |
---|
9152 | 9314 | static double[] model = new double[16]; |
---|
9153 | 9315 | double[] camera2light = new double[16]; |
---|
9154 | 9316 | double[] light2camera = new double[16]; |
---|
9155 | | - int newenvy = -1; |
---|
9156 | | - boolean envyoff = true; // false; |
---|
| 9317 | + |
---|
| 9318 | + //int newenvy = -1; |
---|
| 9319 | + //boolean envyoff = false; |
---|
| 9320 | + |
---|
| 9321 | + String loadedskyboxname; |
---|
| 9322 | + |
---|
9157 | 9323 | cVector light0 = new cVector(0, 0, 0); // 1,3,2); |
---|
9158 | 9324 | //float[] light0 = { 0,0,0 }; |
---|
9159 | 9325 | cVector dirlight = new cVector(0, 0, 1); // 1,3,2); |
---|
.. | .. |
---|
9571 | 9737 | |
---|
9572 | 9738 | if (renderCamera != lightCamera) |
---|
9573 | 9739 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
9574 | | - LA.matConcat(matrix, parentcam.GlobalTransform(), matrix); |
---|
| 9740 | + LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix); |
---|
9575 | 9741 | |
---|
9576 | 9742 | // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix); |
---|
9577 | 9743 | |
---|
.. | .. |
---|
9587 | 9753 | |
---|
9588 | 9754 | if (renderCamera != lightCamera) |
---|
9589 | 9755 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
9590 | | - LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix); |
---|
| 9756 | + LA.matConcat(parentcam.GlobalTransform(), matrix, matrix); |
---|
9591 | 9757 | |
---|
9592 | 9758 | // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix); |
---|
9593 | 9759 | |
---|
.. | .. |
---|
9633 | 9799 | rati = 1 / rati; |
---|
9634 | 9800 | gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000); |
---|
9635 | 9801 | } |
---|
9636 | | - assert (newenvy == -1); |
---|
| 9802 | + |
---|
| 9803 | + //assert (newenvy == -1); |
---|
| 9804 | + |
---|
9637 | 9805 | gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
9638 | 9806 | gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB); |
---|
9639 | | - DrawSkyBox(gl); |
---|
| 9807 | + DrawSkyBox(gl, (float)rati); |
---|
9640 | 9808 | gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
9641 | 9809 | gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB); |
---|
9642 | 9810 | accPerspective(gl, renderCamera.shaper_fovy / ratio, |
---|
.. | .. |
---|
10788 | 10956 | // if (parentcam != renderCamera) // not a light |
---|
10789 | 10957 | if (cam != lightCamera) |
---|
10790 | 10958 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
10791 | | - LA.matConcat(matrix, parentcam.GlobalTransform(), matrix); |
---|
| 10959 | + LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix); |
---|
10792 | 10960 | |
---|
10793 | 10961 | for (int j = 0; j < 4; j++) |
---|
10794 | 10962 | { |
---|
.. | .. |
---|
10803 | 10971 | // if (parentcam != renderCamera) // not a light |
---|
10804 | 10972 | if (cam != lightCamera) |
---|
10805 | 10973 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
10806 | | - LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix); |
---|
| 10974 | + LA.matConcat(parentcam.GlobalTransform(), matrix, matrix); |
---|
10807 | 10975 | |
---|
10808 | 10976 | //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix); |
---|
10809 | 10977 | |
---|
.. | .. |
---|
10889 | 11057 | gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000); |
---|
10890 | 11058 | } |
---|
10891 | 11059 | |
---|
10892 | | - if (newenvy > -1) |
---|
| 11060 | +// if (newenvy > -1) |
---|
| 11061 | +// { |
---|
| 11062 | +// LoadEnvy(newenvy); |
---|
| 11063 | +// } |
---|
| 11064 | +// |
---|
| 11065 | +// newenvy = -1; |
---|
| 11066 | + |
---|
| 11067 | + if (object.skyboxname != null) |
---|
10893 | 11068 | { |
---|
10894 | | - LoadEnvy(newenvy); |
---|
| 11069 | + if (!object.skyboxname.equals(this.loadedskyboxname)) |
---|
| 11070 | + { |
---|
| 11071 | + LoadSkybox(object.skyboxname + "/", object.skyboxext, false); |
---|
| 11072 | + loadedskyboxname = object.skyboxname; |
---|
| 11073 | + } |
---|
10895 | 11074 | } |
---|
10896 | | - |
---|
10897 | | - newenvy = -1; |
---|
10898 | | - |
---|
| 11075 | + else |
---|
| 11076 | + { |
---|
| 11077 | + cubemap = null; |
---|
| 11078 | + loadedskyboxname = null; |
---|
| 11079 | + } |
---|
| 11080 | + |
---|
10899 | 11081 | ratio = ((double) getWidth()) / getHeight(); |
---|
10900 | 11082 | //System.out.println("ratio = " + ratio); |
---|
10901 | 11083 | |
---|
.. | .. |
---|
10911 | 11093 | |
---|
10912 | 11094 | if (!IsFrozen() && !ambientOcclusion) |
---|
10913 | 11095 | { |
---|
10914 | | - DrawSkyBox(gl); |
---|
| 11096 | + DrawSkyBox(gl, (float)ratio); |
---|
10915 | 11097 | } |
---|
10916 | 11098 | |
---|
10917 | 11099 | //if (selection_view == -1) |
---|
.. | .. |
---|
11065 | 11247 | |
---|
11066 | 11248 | try |
---|
11067 | 11249 | { |
---|
11068 | | - BindTexture(null, NOISE_TEXTURE, false, 2); |
---|
| 11250 | + BindTexture(NOISE_TEXTURE, false, 2); |
---|
11069 | 11251 | } |
---|
11070 | 11252 | catch (Exception e) |
---|
11071 | 11253 | { |
---|
.. | .. |
---|
11356 | 11538 | } |
---|
11357 | 11539 | } |
---|
11358 | 11540 | |
---|
11359 | | - if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion) |
---|
| 11541 | + if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion) |
---|
11360 | 11542 | { |
---|
11361 | 11543 | //gl.glDepthFunc(GL.GL_LEQUAL); |
---|
11362 | 11544 | //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT); |
---|
.. | .. |
---|
11364 | 11546 | |
---|
11365 | 11547 | boolean texon = textureon; |
---|
11366 | 11548 | |
---|
11367 | | - if (RENDERPROGRAM > 0) |
---|
11368 | | - { |
---|
11369 | | - gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
11370 | | - textureon = false; |
---|
11371 | | - } |
---|
| 11549 | + gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
| 11550 | + textureon = false; |
---|
| 11551 | + |
---|
11372 | 11552 | //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB); |
---|
11373 | 11553 | //System.out.println("ALLO"); |
---|
11374 | 11554 | gl.glColorMask(false, false, false, false); |
---|
11375 | 11555 | DrawObject(gl); |
---|
11376 | | - if (RENDERPROGRAM > 0) |
---|
11377 | | - { |
---|
11378 | | - gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
11379 | | - textureon = texon; |
---|
11380 | | - } |
---|
| 11556 | + |
---|
| 11557 | + gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
| 11558 | + textureon = texon; |
---|
| 11559 | + |
---|
11381 | 11560 | gl.glColorMask(true, true, true, true); |
---|
11382 | 11561 | |
---|
11383 | 11562 | gl.glDepthFunc(GL.GL_EQUAL); |
---|
11384 | | - //gl.glDepthMask(false); |
---|
| 11563 | + gl.glDepthMask(false); |
---|
11385 | 11564 | } |
---|
11386 | 11565 | |
---|
11387 | 11566 | if (false) // DrawMode() == SHADOW) |
---|
.. | .. |
---|
11721 | 11900 | ReleaseTextures(DEFAULT_TEXTURES); |
---|
11722 | 11901 | |
---|
11723 | 11902 | if (CLEANCACHE) |
---|
11724 | | - for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();) |
---|
| 11903 | + for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();) |
---|
11725 | 11904 | { |
---|
11726 | | - String tex = e.nextElement(); |
---|
| 11905 | + cTexture tex = e.nextElement(); |
---|
11727 | 11906 | |
---|
11728 | 11907 | // System.out.println("Texture --------- " + tex); |
---|
11729 | 11908 | |
---|
11730 | | - if (tex.equals("WHITE_NOISE")) |
---|
| 11909 | + if (tex.equals("WHITE_NOISE:")) |
---|
11731 | 11910 | continue; |
---|
11732 | 11911 | |
---|
11733 | 11912 | if (!usedtextures.contains(tex)) |
---|
11734 | 11913 | { |
---|
| 11914 | + CacheTexture gettex = texturepigment.get(tex); |
---|
11735 | 11915 | // System.out.println("DISPOSE +++++++++++++++ " + tex); |
---|
11736 | | - textures.get(tex).texture.dispose(); |
---|
11737 | | - 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 | + } |
---|
11738 | 11929 | } |
---|
11739 | 11930 | } |
---|
11740 | 11931 | } |
---|
.. | .. |
---|
12262 | 12453 | |
---|
12263 | 12454 | //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0); |
---|
12264 | 12455 | |
---|
| 12456 | + String program0 = |
---|
| 12457 | + // Min shader |
---|
| 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 | + |
---|
12265 | 12523 | String program = |
---|
12266 | 12524 | "!!ARBfp1.0\n" + |
---|
| 12525 | + |
---|
12267 | 12526 | //"OPTION ARB_fragment_program_shadow;" + |
---|
12268 | 12527 | "PARAM light2cam0 = program.env[10];" + |
---|
12269 | 12528 | "PARAM light2cam1 = program.env[11];" + |
---|
.. | .. |
---|
12378 | 12637 | "TEMP shininess;" + |
---|
12379 | 12638 | "\n" + |
---|
12380 | 12639 | "MOV texSamp, one;" + |
---|
12381 | | - //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" + |
---|
12382 | | - |
---|
| 12640 | + |
---|
12383 | 12641 | "MOV mapgrid.x, one2048th.x;" + |
---|
12384 | 12642 | "MOV temp, fragment.texcoord[1];" + |
---|
12385 | 12643 | /* |
---|
.. | .. |
---|
12400 | 12658 | "MUL temp, floor, mapgrid.x;" + |
---|
12401 | 12659 | //"TEX depth0, temp, texture[1], 2D;" + |
---|
12402 | 12660 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12403 | | - TextureFetch("depth0", "temp", "1") + |
---|
| 12661 | + ShadowTextureFetch("depth0", "temp", "1") + |
---|
12404 | 12662 | "") + |
---|
12405 | 12663 | "ADD temp.x, temp.x, mapgrid.x;" + |
---|
12406 | 12664 | //"TEX depth1, temp, texture[1], 2D;" + |
---|
12407 | 12665 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12408 | | - TextureFetch("depth1", "temp", "1") + |
---|
| 12666 | + ShadowTextureFetch("depth1", "temp", "1") + |
---|
12409 | 12667 | "") + |
---|
12410 | 12668 | "ADD temp.y, temp.y, mapgrid.x;" + |
---|
12411 | 12669 | //"TEX depth2, temp, texture[1], 2D;" + |
---|
12412 | | - TextureFetch("depth2", "temp", "1") + |
---|
| 12670 | + ShadowTextureFetch("depth2", "temp", "1") + |
---|
12413 | 12671 | "SUB temp.x, temp.x, mapgrid.x;" + |
---|
12414 | 12672 | //"TEX depth3, temp, texture[1], 2D;" + |
---|
12415 | 12673 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12416 | | - TextureFetch("depth3", "temp", "1") + |
---|
| 12674 | + ShadowTextureFetch("depth3", "temp", "1") + |
---|
12417 | 12675 | "") + |
---|
12418 | 12676 | //"MUL texSamp0, texSamp0, state.material.front.diffuse;" + |
---|
12419 | 12677 | //"MOV params, material;" + |
---|
.. | .. |
---|
12784 | 13042 | "MAD shadow.x, buffer.x, frac.y, shadow.x;" + |
---|
12785 | 13043 | "") + |
---|
12786 | 13044 | |
---|
12787 | | - // display shadow only (bump == 0) |
---|
| 13045 | + // display shadow only (fakedepth == 0) |
---|
12788 | 13046 | "SUB temp.x, half.x, shadow.x;" + |
---|
12789 | 13047 | "MOV temp.y, -params5.z;" + // params6.x;" + |
---|
12790 | | - "SLT temp.z, temp.y, -one2048th.x;" + |
---|
| 13048 | + "SLT temp.z, temp.y, -c256i.x;" + |
---|
12791 | 13049 | "SUB temp.y, one.x, temp.z;" + |
---|
12792 | 13050 | "MUL temp.x, temp.x, temp.y;" + |
---|
12793 | 13051 | "KIL temp.x;" + |
---|
.. | .. |
---|
13211 | 13469 | return out; |
---|
13212 | 13470 | } |
---|
13213 | 13471 | |
---|
13214 | | - String TextureFetch(String dest, String src, String unit) |
---|
| 13472 | + // Also does frustum culling |
---|
| 13473 | + String ShadowTextureFetch(String dest, String src, String unit) |
---|
13215 | 13474 | { |
---|
13216 | 13475 | return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" + |
---|
13217 | 13476 | "SGE " + src + ".w, " + src + ".x, eps.x;" + |
---|
13218 | 13477 | "SGE " + src + ".z, " + src + ".y, eps.x;" + |
---|
| 13478 | + "SLT " + dest + ".x, " + src + ".x, one.x;" + |
---|
| 13479 | + "SLT " + dest + ".y, " + src + ".y, one.x;" + |
---|
13219 | 13480 | "MUL " + src + ".w, " + src + ".z, " + src + ".w;" + |
---|
13220 | | - "SLT " + src + ".z, " + src + ".x, one.x;" + |
---|
13221 | | - "MUL " + src + ".w, " + src + ".z, " + src + ".w;" + |
---|
13222 | | - "SLT " + src + ".z, " + src + ".y, one.x;" + |
---|
13223 | | - "MUL " + src + ".w, " + src + ".z, " + src + ".w;" + |
---|
| 13481 | + "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" + |
---|
| 13482 | + "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" + |
---|
13224 | 13483 | //"SWZ buffer, temp, w,w,w,w;"; |
---|
13225 | | - "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" + |
---|
| 13484 | + //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" + |
---|
13226 | 13485 | "SUB " + src + ".z, " + "one.x, " + src + ".w;" + |
---|
13227 | 13486 | //"MUL " + src + ".z, " + src + ".z, infinity.x;" + |
---|
13228 | 13487 | //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;"; |
---|
13229 | | - "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
| 13488 | + //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
13230 | 13489 | |
---|
13231 | | - //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;"; |
---|
13232 | | - //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;"; |
---|
| 13490 | + //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;"; |
---|
| 13491 | + "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
13233 | 13492 | } |
---|
13234 | 13493 | |
---|
13235 | 13494 | String Shadow(String depth, String shadow) |
---|
.. | .. |
---|
13276 | 13535 | "SLT temp.x, temp.x, zero.x;" + // shadoweps |
---|
13277 | 13536 | "LRP " + shadow + ", temp.x, one, " + shadow + ";" + |
---|
13278 | 13537 | |
---|
13279 | | - // No shadow when out of frustrum |
---|
| 13538 | + // No shadow when out of frustum |
---|
13280 | 13539 | "SGE temp.x, " + depth + ".z, one.z;" + |
---|
13281 | 13540 | "LRP " + shadow + ", temp.x, one, " + shadow + ";" + |
---|
13282 | 13541 | ""; |
---|
.. | .. |
---|
14074 | 14333 | drag = false; |
---|
14075 | 14334 | //System.out.println("Mouse DOWN"); |
---|
14076 | 14335 | editObj = false; |
---|
14077 | | - ClickInfo info = new ClickInfo(); |
---|
14078 | | - info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
14079 | | - info.pane = this; |
---|
14080 | | - info.camera = renderCamera; |
---|
14081 | | - info.x = x; |
---|
14082 | | - info.y = y; |
---|
14083 | | - info.modifiers = modifiersex; |
---|
14084 | | - editObj = object.doEditClick(info, 0); |
---|
| 14336 | + //ClickInfo info = new ClickInfo(); |
---|
| 14337 | + object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
| 14338 | + object.clickInfo.pane = this; |
---|
| 14339 | + object.clickInfo.camera = renderCamera; |
---|
| 14340 | + object.clickInfo.x = x; |
---|
| 14341 | + object.clickInfo.y = y; |
---|
| 14342 | + object.clickInfo.modifiers = modifiersex; |
---|
| 14343 | + editObj = object.doEditClick(//info, |
---|
| 14344 | + 0); |
---|
14085 | 14345 | if (!editObj) |
---|
14086 | 14346 | { |
---|
14087 | 14347 | hasMarquee = true; |
---|
.. | .. |
---|
14481 | 14741 | if (editObj) |
---|
14482 | 14742 | { |
---|
14483 | 14743 | drag = true; |
---|
14484 | | - ClickInfo info = new ClickInfo(); |
---|
14485 | | - info.bounds.setBounds(0, 0, |
---|
| 14744 | + //ClickInfo info = new ClickInfo(); |
---|
| 14745 | + object.clickInfo.bounds.setBounds(0, 0, |
---|
14486 | 14746 | (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
14487 | | - info.pane = this; |
---|
14488 | | - info.camera = renderCamera; |
---|
14489 | | - info.x = x; |
---|
14490 | | - info.y = y; |
---|
14491 | | - object.GetWindow().copy |
---|
14492 | | - .doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0); |
---|
| 14747 | + object.clickInfo.pane = this; |
---|
| 14748 | + object.clickInfo.camera = renderCamera; |
---|
| 14749 | + object.clickInfo.x = x; |
---|
| 14750 | + object.clickInfo.y = y; |
---|
| 14751 | + object //.GetWindow().copy |
---|
| 14752 | + .doEditDrag(//info, |
---|
| 14753 | + (modifiers & MouseEvent.BUTTON3_MASK) != 0); |
---|
14493 | 14754 | } else |
---|
14494 | 14755 | { |
---|
14495 | 14756 | if (x < startX) |
---|
.. | .. |
---|
14638 | 14899 | } |
---|
14639 | 14900 | } |
---|
14640 | 14901 | |
---|
| 14902 | +// ClickInfo clickInfo = new ClickInfo(); |
---|
| 14903 | + |
---|
14641 | 14904 | public void mouseMoved(MouseEvent e) |
---|
14642 | 14905 | { |
---|
14643 | 14906 | //System.out.println("mouseMoved: " + e); |
---|
14644 | 14907 | if (isRenderer) |
---|
14645 | 14908 | return; |
---|
14646 | 14909 | |
---|
14647 | | - ClickInfo ci = new ClickInfo(); |
---|
14648 | | - ci.x = e.getX(); |
---|
14649 | | - ci.y = e.getY(); |
---|
14650 | | - ci.modifiers = e.getModifiersEx(); |
---|
14651 | | - ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
14652 | | - ci.pane = this; |
---|
14653 | | - ci.camera = renderCamera; |
---|
| 14910 | + // Mouse cursor feedback |
---|
| 14911 | + object.clickInfo.x = e.getX(); |
---|
| 14912 | + object.clickInfo.y = e.getY(); |
---|
| 14913 | + object.clickInfo.modifiers = e.getModifiersEx(); |
---|
| 14914 | + object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
| 14915 | + object.clickInfo.pane = this; |
---|
| 14916 | + object.clickInfo.camera = renderCamera; |
---|
14654 | 14917 | if (!isRenderer) |
---|
14655 | 14918 | { |
---|
14656 | 14919 | //ObjEditor editWindow = object.editWindow; |
---|
14657 | 14920 | //Object3D copy = editWindow.copy; |
---|
14658 | | - if (object.doEditClick(ci, 0)) |
---|
| 14921 | + if (object.doEditClick(//clickInfo, |
---|
| 14922 | + 0)) |
---|
14659 | 14923 | { |
---|
14660 | 14924 | setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
---|
14661 | 14925 | } else |
---|
.. | .. |
---|
14927 | 15191 | // break; |
---|
14928 | 15192 | case 'T': |
---|
14929 | 15193 | CACHETEXTURE ^= true; |
---|
14930 | | - textures.clear(); |
---|
| 15194 | + texturepigment.clear(); |
---|
| 15195 | + texturebump.clear(); |
---|
14931 | 15196 | // repaint(); |
---|
14932 | 15197 | break; |
---|
14933 | 15198 | case 'Y': |
---|
.. | .. |
---|
15104 | 15369 | OCCLUSION_CULLING ^= true; |
---|
15105 | 15370 | System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING); |
---|
15106 | 15371 | break; |
---|
15107 | | - case '0': envyoff ^= true; repaint(); break; |
---|
| 15372 | + //case '0': envyoff ^= true; repaint(); break; |
---|
15108 | 15373 | case '1': |
---|
15109 | 15374 | case '2': |
---|
15110 | 15375 | case '3': |
---|
15111 | 15376 | case '4': |
---|
15112 | 15377 | case '5': |
---|
15113 | | - newenvy = Character.getNumericValue(key); |
---|
15114 | | - repaint(); |
---|
15115 | | - break; |
---|
15116 | 15378 | case '6': |
---|
15117 | 15379 | case '7': |
---|
15118 | 15380 | case '8': |
---|
15119 | 15381 | case '9': |
---|
15120 | | - BGcolor = (key - '6')/3.f; |
---|
| 15382 | + if (true) // envyoff) |
---|
| 15383 | + { |
---|
| 15384 | + BGcolor = (key - '1')/8.f; |
---|
| 15385 | + } |
---|
| 15386 | + else |
---|
| 15387 | + { |
---|
| 15388 | + //newenvy = Character.getNumericValue(key); |
---|
| 15389 | + } |
---|
15121 | 15390 | repaint(); |
---|
15122 | 15391 | break; |
---|
15123 | 15392 | case '!': |
---|
.. | .. |
---|
15680 | 15949 | |
---|
15681 | 15950 | int width = getBounds().width; |
---|
15682 | 15951 | int height = getBounds().height; |
---|
15683 | | - ClickInfo info = new ClickInfo(); |
---|
15684 | | - info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom)); |
---|
15685 | 15952 | //Image img = CreateImage(width, height); |
---|
15686 | 15953 | //System.out.println("width = " + width + "; height = " + height + "\n"); |
---|
15687 | 15954 | |
---|
.. | .. |
---|
15758 | 16025 | } |
---|
15759 | 16026 | if (object != null && !hasMarquee) |
---|
15760 | 16027 | { |
---|
| 16028 | + if (object.clickInfo == null) |
---|
| 16029 | + object.clickInfo = new ClickInfo(); |
---|
| 16030 | + ClickInfo info = object.clickInfo; |
---|
| 16031 | + //ClickInfo info = new ClickInfo(); |
---|
| 16032 | + info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom)); |
---|
| 16033 | + |
---|
15761 | 16034 | if (isRenderer) |
---|
15762 | 16035 | { |
---|
15763 | | - info.flags++; |
---|
| 16036 | + object.clickInfo.flags++; |
---|
15764 | 16037 | double frameAspect = (double) width / (double) height; |
---|
15765 | 16038 | if (frameAspect > renderCamera.aspect) |
---|
15766 | 16039 | { |
---|
15767 | 16040 | int desired = (int) ((double) height * renderCamera.aspect); |
---|
15768 | | - info.bounds.width -= width - desired; |
---|
15769 | | - info.bounds.x += (width - desired) / 2; |
---|
| 16041 | + object.clickInfo.bounds.width -= width - desired; |
---|
| 16042 | + object.clickInfo.bounds.x += (width - desired) / 2; |
---|
15770 | 16043 | } else |
---|
15771 | 16044 | { |
---|
15772 | 16045 | int desired = (int) ((double) width / renderCamera.aspect); |
---|
15773 | | - info.bounds.height -= height - desired; |
---|
15774 | | - info.bounds.y += (height - desired) / 2; |
---|
| 16046 | + object.clickInfo.bounds.height -= height - desired; |
---|
| 16047 | + object.clickInfo.bounds.y += (height - desired) / 2; |
---|
15775 | 16048 | } |
---|
15776 | 16049 | } |
---|
15777 | 16050 | |
---|
15778 | | - info.g = gr; |
---|
15779 | | - info.camera = renderCamera; |
---|
| 16051 | + object.clickInfo.g = gr; |
---|
| 16052 | + object.clickInfo.camera = renderCamera; |
---|
15780 | 16053 | /* |
---|
15781 | 16054 | // Memory intensive (brep.verticescopy) |
---|
15782 | 16055 | if (!(object instanceof Composite)) |
---|
15783 | 16056 | object.draw(info, 0, false); // SLOW : |
---|
15784 | 16057 | */ |
---|
15785 | | - if (!isRenderer) |
---|
| 16058 | + if (!isRenderer) // && drag) |
---|
15786 | 16059 | { |
---|
15787 | 16060 | Grafreed.Assert(object != null); |
---|
15788 | 16061 | Grafreed.Assert(object.selection != null); |
---|
.. | .. |
---|
15790 | 16063 | { |
---|
15791 | 16064 | int hitSomething = object.selection.get(0).hitSomething; |
---|
15792 | 16065 | |
---|
15793 | | - info.DX = 0; |
---|
15794 | | - info.DY = 0; |
---|
15795 | | - info.W = 1; |
---|
| 16066 | + object.clickInfo.DX = 0; |
---|
| 16067 | + object.clickInfo.DY = 0; |
---|
| 16068 | + object.clickInfo.W = 1; |
---|
15796 | 16069 | if (hitSomething == Object3D.hitCenter) |
---|
15797 | 16070 | { |
---|
15798 | 16071 | info.DX = X; |
---|
.. | .. |
---|
15804 | 16077 | info.DY -= info.bounds.height/2; |
---|
15805 | 16078 | } |
---|
15806 | 16079 | |
---|
15807 | | - object.drawEditHandles(info, 0); |
---|
| 16080 | + object.drawEditHandles(//info, |
---|
| 16081 | + 0); |
---|
15808 | 16082 | |
---|
15809 | 16083 | if (drag && (X != 0 || Y != 0)) |
---|
15810 | 16084 | { |
---|
.. | .. |
---|
15817 | 16091 | gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
15818 | 16092 | break; |
---|
15819 | 16093 | case Object3D.hitScale: gr.setColor(Color.cyan); |
---|
15820 | | - gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
| 16094 | + gr.drawLine(X, Y, 0, 0); |
---|
15821 | 16095 | break; |
---|
15822 | 16096 | } |
---|
15823 | 16097 | |
---|
.. | .. |
---|
16303 | 16577 | private /*static*/ boolean firstime; |
---|
16304 | 16578 | private /*static*/ cVector newView = new cVector(); |
---|
16305 | 16579 | private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"}; |
---|
| 16580 | + private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"}; |
---|
| 16581 | + private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"}; |
---|
16306 | 16582 | private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X, |
---|
16307 | 16583 | GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X, |
---|
16308 | 16584 | GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y, |
---|
.. | .. |
---|
16315 | 16591 | { |
---|
16316 | 16592 | com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP); |
---|
16317 | 16593 | |
---|
| 16594 | + int usedsuf = 0; |
---|
| 16595 | + |
---|
16318 | 16596 | for (int i = 0; i < suffixes.length; i++) |
---|
16319 | 16597 | { |
---|
16320 | | - String resourceName = basename + suffixes[i] + "." + suffix; |
---|
16321 | | - TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
16322 | | - mipmapped, |
---|
16323 | | - FileUtil.getFileSuffix(resourceName)); |
---|
16324 | | - if (data == null) |
---|
| 16598 | + String[] suffixe = suffixes; |
---|
| 16599 | + String[] fallback = suffixes2; |
---|
| 16600 | + String[] fallfallback = suffixes3; |
---|
| 16601 | + |
---|
| 16602 | + for (int c=usedsuf; --c>=0;) |
---|
16325 | 16603 | { |
---|
16326 | | - throw new IOException("Unable to load texture " + resourceName); |
---|
| 16604 | +// String[] temp = suffixe; |
---|
| 16605 | +// suffixe = fallback; |
---|
| 16606 | +// fallback = fallfallback; |
---|
| 16607 | +// fallfallback = temp; |
---|
16327 | 16608 | } |
---|
| 16609 | + |
---|
| 16610 | + String resourceName = basename + suffixe[i] + "." + suffix; |
---|
| 16611 | + TextureData data; |
---|
| 16612 | + |
---|
| 16613 | + try |
---|
| 16614 | + { |
---|
| 16615 | + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
| 16616 | + mipmapped, |
---|
| 16617 | + FileUtil.getFileSuffix(resourceName)); |
---|
| 16618 | + } |
---|
| 16619 | + catch (Exception e) |
---|
| 16620 | + { |
---|
| 16621 | + try |
---|
| 16622 | + { |
---|
| 16623 | + resourceName = basename + fallback[i] + "." + suffix; |
---|
| 16624 | + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
| 16625 | + mipmapped, |
---|
| 16626 | + FileUtil.getFileSuffix(resourceName)); |
---|
| 16627 | + } |
---|
| 16628 | + catch (Exception e2) |
---|
| 16629 | + { |
---|
| 16630 | + resourceName = basename + fallfallback[i] + "." + suffix; |
---|
| 16631 | + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
| 16632 | + mipmapped, |
---|
| 16633 | + FileUtil.getFileSuffix(resourceName)); |
---|
| 16634 | + } |
---|
| 16635 | + } |
---|
| 16636 | + |
---|
16328 | 16637 | //System.out.println("Target = " + targets[i]); |
---|
16329 | 16638 | cubemap.updateImage(data, targets[i]); |
---|
16330 | 16639 | } |
---|
16331 | 16640 | |
---|
16332 | 16641 | return cubemap; |
---|
16333 | 16642 | } |
---|
| 16643 | + |
---|
16334 | 16644 | int bigsphere = -1; |
---|
16335 | 16645 | |
---|
16336 | 16646 | float BGcolor = 0.5f; |
---|
16337 | 16647 | |
---|
16338 | | - private void DrawSkyBox(GL gl) |
---|
| 16648 | + float ambientLight[] = {1f, 1f, 1f, 1.0f}; |
---|
| 16649 | + |
---|
| 16650 | + private void DrawSkyBox(GL gl, float ratio) |
---|
16339 | 16651 | { |
---|
16340 | | - if (envyoff || cubemap == null) |
---|
| 16652 | + if (//envyoff || |
---|
| 16653 | + cubemap == null) |
---|
16341 | 16654 | { |
---|
16342 | 16655 | gl.glClearColor(BGcolor, BGcolor, BGcolor, 1); |
---|
16343 | 16656 | gl.glClear(gl.GL_COLOR_BUFFER_BIT); |
---|
.. | .. |
---|
16352 | 16665 | // Compensates for ExaminerViewer's modification of modelview matrix |
---|
16353 | 16666 | gl.glMatrixMode(GL.GL_MODELVIEW); |
---|
16354 | 16667 | gl.glLoadIdentity(); |
---|
| 16668 | + gl.glScalef(1,ratio,1); |
---|
16355 | 16669 | |
---|
| 16670 | + colorV[0] = 2; |
---|
| 16671 | + colorV[1] = 2; |
---|
| 16672 | + colorV[2] = 2; |
---|
| 16673 | + colorV[3] = 1; |
---|
| 16674 | + gl.glDisable(gl.GL_COLOR_MATERIAL); |
---|
| 16675 | + gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0); |
---|
| 16676 | + |
---|
| 16677 | + gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0); |
---|
| 16678 | + |
---|
16356 | 16679 | //gl.glActiveTexture(GL.GL_TEXTURE1); |
---|
16357 | 16680 | //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP); |
---|
16358 | 16681 | |
---|
.. | .. |
---|
16365 | 16688 | // GL_NORMAL_MAP texgen mode. Temporarily enabling lighting |
---|
16366 | 16689 | // causes the normals to be sent down. Thanks to Ken Dyke. |
---|
16367 | 16690 | //gl.glEnable(GL.GL_LIGHTING); |
---|
16368 | | - gl.glDisable(GL.GL_LIGHTING); |
---|
| 16691 | + gl.glEnable(GL.GL_LIGHTING); |
---|
16369 | 16692 | |
---|
16370 | 16693 | gl.glTexGeni(GL.GL_S, GL.GL_TEXTURE_GEN_MODE, GL.GL_NORMAL_MAP); |
---|
16371 | 16694 | gl.glTexGeni(GL.GL_T, GL.GL_TEXTURE_GEN_MODE, GL.GL_NORMAL_MAP); |
---|
.. | .. |
---|
16384 | 16707 | { |
---|
16385 | 16708 | gl.glScalef(1.0f, -1.0f, 1.0f); |
---|
16386 | 16709 | } |
---|
| 16710 | + gl.glScalef(-1.0f, 1.0f, 1.0f); |
---|
16387 | 16711 | gl.glMultMatrixd(viewrot_1, 0); |
---|
16388 | 16712 | gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f); |
---|
16389 | 16713 | //viewer.updateInverseRotation(gl); |
---|
.. | .. |
---|
16642 | 16966 | //new Exception().printStackTrace(); |
---|
16643 | 16967 | System.out.println("select buffer init"); |
---|
16644 | 16968 | // Use debug pipeline |
---|
16645 | | - drawable.setGL(new DebugGL(drawable.getGL())); |
---|
| 16969 | + //drawable.setGL(new DebugGL(drawable.getGL())); |
---|
16646 | 16970 | |
---|
16647 | 16971 | GL gl = drawable.getGL(); |
---|
16648 | 16972 | |
---|