.. | .. |
---|
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) && !texname.startsWith("@")) |
---|
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); |
---|
| 8440 | + else |
---|
| 8441 | + new Exception().printStackTrace(); |
---|
| 8442 | + } else |
---|
| 8443 | + { |
---|
| 8444 | + if (texname.startsWith("@")) |
---|
| 8445 | + { |
---|
| 8446 | + // texturecache = textures.get(texname); // suspicious |
---|
| 8447 | + if (texturecache == null) |
---|
| 8448 | + texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution); |
---|
8395 | 8449 | else |
---|
8396 | 8450 | new Exception().printStackTrace(); |
---|
8397 | 8451 | } else |
---|
.. | .. |
---|
8452 | 8506 | if (texturedata == null) |
---|
8453 | 8507 | throw new Exception(); |
---|
8454 | 8508 | |
---|
8455 | | - texturecache = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution); |
---|
| 8509 | + texturecache = new CacheTexture(texturedata,resolution); |
---|
8456 | 8510 | //texture = GetTexture(tex, bump); |
---|
8457 | 8511 | } |
---|
| 8512 | + } |
---|
8458 | 8513 | } |
---|
8459 | 8514 | //} |
---|
8460 | 8515 | } |
---|
8461 | 8516 | |
---|
8462 | | - if (/*CACHETEXTURE &&*/ texturecache != null && textureon) |
---|
| 8517 | + if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon) |
---|
8463 | 8518 | { |
---|
8464 | 8519 | //return false; |
---|
8465 | | - assert(bim == null); |
---|
8466 | 8520 | |
---|
8467 | 8521 | // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")"); |
---|
8468 | 8522 | if (texturedata != null && texname.toLowerCase().endsWith(".jpg")) |
---|
.. | .. |
---|
8509 | 8563 | } |
---|
8510 | 8564 | } |
---|
8511 | 8565 | } |
---|
8512 | | - |
---|
| 8566 | + |
---|
| 8567 | + Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment; |
---|
| 8568 | + |
---|
8513 | 8569 | //System.out.println("Texture = " + tex); |
---|
8514 | | - if (textures.containsKey(texname)) |
---|
| 8570 | + if (textures.containsKey(tex)) |
---|
8515 | 8571 | { |
---|
8516 | | - CacheTexture thetex = textures.get(texname); |
---|
| 8572 | + CacheTexture thetex = textures.get(tex); |
---|
8517 | 8573 | thetex.texture.disable(); |
---|
8518 | 8574 | thetex.texture.dispose(); |
---|
8519 | | - textures.remove(texname); |
---|
| 8575 | + textures.remove(tex); |
---|
8520 | 8576 | } |
---|
8521 | 8577 | |
---|
8522 | 8578 | //texture.texturedata = texturedata; |
---|
8523 | | - textures.put(texname, texturecache); |
---|
| 8579 | + textures.put(tex, texturecache); |
---|
8524 | 8580 | |
---|
8525 | 8581 | // newtex = true; |
---|
8526 | 8582 | } |
---|
.. | .. |
---|
8541 | 8597 | |
---|
8542 | 8598 | static void EmbedTextures(cTexture tex) |
---|
8543 | 8599 | { |
---|
| 8600 | + if (tex.pigmentdata == null) |
---|
| 8601 | + { |
---|
| 8602 | + //String texname = Object3D.GetPigment(tex); |
---|
| 8603 | + |
---|
| 8604 | + CacheTexture texturecache = texturepigment.get(tex); |
---|
| 8605 | + |
---|
| 8606 | + if (texturecache != null) |
---|
| 8607 | + { |
---|
| 8608 | + tex.pw = texturecache.texturedata.getWidth(); |
---|
| 8609 | + tex.ph = texturecache.texturedata.getHeight(); |
---|
| 8610 | + tex.pigmentdata = //CompressJPEG(CreateBim |
---|
| 8611 | + ((ByteBuffer)texturecache.texturedata.getBuffer()).array() |
---|
| 8612 | + ; |
---|
| 8613 | + //, tex.pw, tex.ph), 0.5f); |
---|
| 8614 | + } |
---|
| 8615 | + } |
---|
8544 | 8616 | |
---|
| 8617 | + if (tex.bumpdata == null) |
---|
| 8618 | + { |
---|
| 8619 | + //String texname = Object3D.GetBump(tex); |
---|
| 8620 | + |
---|
| 8621 | + CacheTexture texturecache = texturebump.get(tex); |
---|
| 8622 | + |
---|
| 8623 | + if (texturecache != null) |
---|
| 8624 | + { |
---|
| 8625 | + tex.bw = texturecache.texturedata.getWidth(); |
---|
| 8626 | + tex.bh = texturecache.texturedata.getHeight(); |
---|
| 8627 | + tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f); |
---|
| 8628 | + } |
---|
| 8629 | + } |
---|
8545 | 8630 | } |
---|
8546 | 8631 | |
---|
8547 | | - com.sun.opengl.util.texture.Texture GetTexture(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception |
---|
| 8632 | + com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8548 | 8633 | { |
---|
8549 | | - CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution); |
---|
| 8634 | + CacheTexture texture = GetCacheTexture(tex, bump, resolution); |
---|
8550 | 8635 | |
---|
8551 | 8636 | if (bump) |
---|
8552 | 8637 | { |
---|
.. | .. |
---|
8562 | 8647 | return texture!=null?texture.texture:null; |
---|
8563 | 8648 | } |
---|
8564 | 8649 | |
---|
8565 | | - public com.sun.opengl.util.texture.TextureData GetTextureData(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception |
---|
| 8650 | + public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8566 | 8651 | { |
---|
8567 | | - CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution); |
---|
| 8652 | + CacheTexture texture = GetCacheTexture(tex, bump, resolution); |
---|
8568 | 8653 | |
---|
8569 | 8654 | return texture!=null?texture.texturedata:null; |
---|
8570 | 8655 | } |
---|
8571 | 8656 | |
---|
8572 | | - boolean BindTexture(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception |
---|
| 8657 | + boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8573 | 8658 | { |
---|
8574 | 8659 | if (/*tex == null ||*/ ambientOcclusion ) // || !textureon) |
---|
8575 | 8660 | { |
---|
.. | .. |
---|
8578 | 8663 | |
---|
8579 | 8664 | //boolean newtex = false; |
---|
8580 | 8665 | |
---|
8581 | | - com.sun.opengl.util.texture.Texture texture = GetTexture(stream, tex, bump, resolution); |
---|
| 8666 | + com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution); |
---|
8582 | 8667 | |
---|
8583 | 8668 | if (texture == null) |
---|
8584 | 8669 | return false; |
---|
.. | .. |
---|
8611 | 8696 | return true; // Warning: not used. |
---|
8612 | 8697 | } |
---|
8613 | 8698 | |
---|
| 8699 | + public static byte[] CompressJPEG(BufferedImage image, float quality) |
---|
| 8700 | + { |
---|
| 8701 | + try |
---|
| 8702 | + { |
---|
| 8703 | + ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
---|
| 8704 | + Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg"); |
---|
| 8705 | + ImageWriter writer = writers.next(); |
---|
| 8706 | + |
---|
| 8707 | + ImageWriteParam param = writer.getDefaultWriteParam(); |
---|
| 8708 | + param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); |
---|
| 8709 | + param.setCompressionQuality(quality); |
---|
| 8710 | + |
---|
| 8711 | + ImageOutputStream ios = ImageIO.createImageOutputStream(baos); |
---|
| 8712 | + writer.setOutput(ios); |
---|
| 8713 | + writer.write(null, new IIOImage(image, null, null), param); |
---|
| 8714 | + |
---|
| 8715 | + byte[] data = baos.toByteArray(); |
---|
| 8716 | + writer.dispose(); |
---|
| 8717 | + return data; |
---|
| 8718 | + } |
---|
| 8719 | + catch (Exception e) |
---|
| 8720 | + { |
---|
| 8721 | + e.printStackTrace(); |
---|
| 8722 | + return null; |
---|
| 8723 | + } |
---|
| 8724 | + } |
---|
| 8725 | + |
---|
| 8726 | + public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException |
---|
| 8727 | + { |
---|
| 8728 | + ByteArrayInputStream baos = new ByteArrayInputStream(image); |
---|
| 8729 | + Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg"); |
---|
| 8730 | + ImageReader reader = writers.next(); |
---|
| 8731 | + |
---|
| 8732 | + BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); |
---|
| 8733 | + |
---|
| 8734 | + ImageReadParam param = reader.getDefaultReadParam(); |
---|
| 8735 | + param.setDestination(bim); |
---|
| 8736 | + //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB)); |
---|
| 8737 | + |
---|
| 8738 | + ImageInputStream ios = ImageIO.createImageInputStream(baos); |
---|
| 8739 | + reader.setInput(ios); |
---|
| 8740 | + BufferedImage bim2 = reader.read(0, param); |
---|
| 8741 | + reader.dispose(); |
---|
| 8742 | + |
---|
| 8743 | +// WritableRaster raster = bim2.getRaster(); |
---|
| 8744 | +// DataBufferByte data = (DataBufferByte) raster.getDataBuffer(); |
---|
| 8745 | +// byte[] bytes = data.getData(); |
---|
| 8746 | +// |
---|
| 8747 | +// int[] pixels = new int[bytes.length/3]; |
---|
| 8748 | +// for (int i=pixels.length; --i>=0;) |
---|
| 8749 | +// { |
---|
| 8750 | +// int i3 = i*3; |
---|
| 8751 | +// pixels[i] = 0xFF; |
---|
| 8752 | +// pixels[i] <<= 8; |
---|
| 8753 | +// pixels[i] |= bytes[i3+2] & 0xFF; |
---|
| 8754 | +// pixels[i] <<= 8; |
---|
| 8755 | +// pixels[i] |= bytes[i3+1] & 0xFF; |
---|
| 8756 | +// pixels[i] <<= 8; |
---|
| 8757 | +// pixels[i] |= bytes[i3] & 0xFF; |
---|
| 8758 | +// } |
---|
| 8759 | +// |
---|
| 8760 | +// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w); |
---|
| 8761 | + |
---|
| 8762 | + return bim; |
---|
| 8763 | + } |
---|
| 8764 | + |
---|
8614 | 8765 | ShadowBuffer shadowPBuf; |
---|
8615 | 8766 | AntialiasBuffer antialiasPBuf; |
---|
8616 | 8767 | int MAXSTACK; |
---|
.. | .. |
---|
8627 | 8778 | |
---|
8628 | 8779 | gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0); |
---|
8629 | 8780 | MAXSTACK = temp[0]; |
---|
8630 | | - System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK); |
---|
| 8781 | + if (Globals.DEBUG) |
---|
| 8782 | + System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK); |
---|
8631 | 8783 | gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0); |
---|
8632 | 8784 | MAXSTACK = temp[0]; |
---|
8633 | | - System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK); |
---|
| 8785 | + if (Globals.DEBUG) |
---|
| 8786 | + System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK); |
---|
8634 | 8787 | |
---|
8635 | 8788 | // Use debug pipeline |
---|
8636 | 8789 | //drawable.setGL(new DebugGL(gl)); // |
---|
.. | .. |
---|
8638 | 8791 | gl = drawable.getGL(); // |
---|
8639 | 8792 | |
---|
8640 | 8793 | GL gl3 = getGL(); |
---|
8641 | | - System.out.println("INIT GL IS: " + gl.getClass().getName()); |
---|
| 8794 | + if (Globals.DEBUG) |
---|
| 8795 | + System.out.println("INIT GL IS: " + gl.getClass().getName()); |
---|
8642 | 8796 | |
---|
8643 | 8797 | |
---|
8644 | 8798 | //float pos[] = { 100, 100, 100, 0 }; |
---|
.. | .. |
---|
8803 | 8957 | |
---|
8804 | 8958 | if (cubemap == null) |
---|
8805 | 8959 | { |
---|
8806 | | - LoadEnvy(5); |
---|
| 8960 | + //LoadEnvy(1); |
---|
8807 | 8961 | } |
---|
8808 | 8962 | |
---|
8809 | 8963 | //cubemap.enable(); |
---|
.. | .. |
---|
9090 | 9244 | cubemap = null; |
---|
9091 | 9245 | return; |
---|
9092 | 9246 | case 1: |
---|
9093 | | - name = "cubemaps/box_"; |
---|
9094 | | - ext = "png"; |
---|
| 9247 | + name = "cubemaps/rgb/"; |
---|
| 9248 | + ext = "jpg"; |
---|
9095 | 9249 | reverseUP = false; |
---|
9096 | 9250 | break; |
---|
9097 | 9251 | case 2: |
---|
9098 | | - name = "cubemaps/uffizi_"; |
---|
9099 | | - ext = "png"; |
---|
9100 | | - break; // reverseUP = true; break; |
---|
| 9252 | + name = "cubemaps/uffizi/"; |
---|
| 9253 | + ext = "jpg"; |
---|
| 9254 | + reverseUP = false; |
---|
| 9255 | + break; |
---|
9101 | 9256 | case 3: |
---|
9102 | | - name = "cubemaps/CloudyHills_"; |
---|
9103 | | - ext = "tga"; |
---|
| 9257 | + name = "cubemaps/CloudyHills/"; |
---|
| 9258 | + ext = "jpg"; |
---|
9104 | 9259 | reverseUP = false; |
---|
9105 | 9260 | break; |
---|
9106 | 9261 | case 4: |
---|
9107 | | - name = "cubemaps/cornell_"; |
---|
| 9262 | + name = "cubemaps/cornell/"; |
---|
9108 | 9263 | ext = "png"; |
---|
9109 | 9264 | reverseUP = false; |
---|
9110 | 9265 | break; |
---|
| 9266 | + case 5: |
---|
| 9267 | + name = "cubemaps/skycube/"; |
---|
| 9268 | + ext = "jpg"; |
---|
| 9269 | + reverseUP = false; |
---|
| 9270 | + break; |
---|
| 9271 | + case 6: |
---|
| 9272 | + name = "cubemaps/SaintLazarusChurch3/"; |
---|
| 9273 | + ext = "jpg"; |
---|
| 9274 | + reverseUP = false; |
---|
| 9275 | + break; |
---|
| 9276 | + case 7: |
---|
| 9277 | + name = "cubemaps/Sodermalmsallen/"; |
---|
| 9278 | + ext = "jpg"; |
---|
| 9279 | + reverseUP = false; |
---|
| 9280 | + break; |
---|
| 9281 | + case 8: |
---|
| 9282 | + name = "cubemaps/Sodermalmsallen2/"; |
---|
| 9283 | + ext = "jpg"; |
---|
| 9284 | + reverseUP = false; |
---|
| 9285 | + break; |
---|
| 9286 | + case 9: |
---|
| 9287 | + name = "cubemaps/UnionSquare/"; |
---|
| 9288 | + ext = "jpg"; |
---|
| 9289 | + reverseUP = false; |
---|
| 9290 | + break; |
---|
9111 | 9291 | default: |
---|
9112 | | - name = "cubemaps/rgb_"; |
---|
9113 | | - ext = "png"; /*mipmap = true;*/ reverseUP = false; |
---|
| 9292 | + name = "cubemaps/box/"; |
---|
| 9293 | + ext = "png"; /*mipmap = true;*/ |
---|
| 9294 | + reverseUP = false; |
---|
9114 | 9295 | break; |
---|
9115 | 9296 | } |
---|
9116 | | - |
---|
9117 | | - try |
---|
9118 | | - { |
---|
9119 | | - cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap); |
---|
9120 | | - } catch (IOException e) |
---|
9121 | | - { |
---|
9122 | | - throw new RuntimeException(e); |
---|
9123 | | - } |
---|
| 9297 | + |
---|
| 9298 | + LoadSkybox(name, ext, mipmap); |
---|
9124 | 9299 | } |
---|
9125 | 9300 | |
---|
9126 | 9301 | public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) |
---|
.. | .. |
---|
9152 | 9327 | static double[] model = new double[16]; |
---|
9153 | 9328 | double[] camera2light = new double[16]; |
---|
9154 | 9329 | double[] light2camera = new double[16]; |
---|
9155 | | - int newenvy = -1; |
---|
9156 | | - boolean envyoff = true; // false; |
---|
| 9330 | + |
---|
| 9331 | + //int newenvy = -1; |
---|
| 9332 | + //boolean envyoff = false; |
---|
| 9333 | + |
---|
| 9334 | + String loadedskyboxname; |
---|
| 9335 | + |
---|
9157 | 9336 | cVector light0 = new cVector(0, 0, 0); // 1,3,2); |
---|
9158 | 9337 | //float[] light0 = { 0,0,0 }; |
---|
9159 | 9338 | cVector dirlight = new cVector(0, 0, 1); // 1,3,2); |
---|
.. | .. |
---|
9571 | 9750 | |
---|
9572 | 9751 | if (renderCamera != lightCamera) |
---|
9573 | 9752 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
9574 | | - LA.matConcat(matrix, parentcam.GlobalTransform(), matrix); |
---|
| 9753 | + LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix); |
---|
9575 | 9754 | |
---|
9576 | 9755 | // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix); |
---|
9577 | 9756 | |
---|
.. | .. |
---|
9587 | 9766 | |
---|
9588 | 9767 | if (renderCamera != lightCamera) |
---|
9589 | 9768 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
9590 | | - LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix); |
---|
| 9769 | + LA.matConcat(parentcam.GlobalTransform(), matrix, matrix); |
---|
9591 | 9770 | |
---|
9592 | 9771 | // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix); |
---|
9593 | 9772 | |
---|
.. | .. |
---|
9633 | 9812 | rati = 1 / rati; |
---|
9634 | 9813 | gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000); |
---|
9635 | 9814 | } |
---|
9636 | | - assert (newenvy == -1); |
---|
| 9815 | + |
---|
| 9816 | + //assert (newenvy == -1); |
---|
| 9817 | + |
---|
9637 | 9818 | gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
9638 | 9819 | gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB); |
---|
9639 | | - DrawSkyBox(gl); |
---|
| 9820 | + DrawSkyBox(gl, (float)rati); |
---|
9640 | 9821 | gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
9641 | 9822 | gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB); |
---|
9642 | 9823 | accPerspective(gl, renderCamera.shaper_fovy / ratio, |
---|
.. | .. |
---|
10673 | 10854 | |
---|
10674 | 10855 | if (wait) |
---|
10675 | 10856 | { |
---|
10676 | | - Sleep(500); |
---|
| 10857 | + Sleep(200); // blocks everything |
---|
10677 | 10858 | |
---|
10678 | 10859 | wait = false; |
---|
10679 | 10860 | } |
---|
.. | .. |
---|
10788 | 10969 | // if (parentcam != renderCamera) // not a light |
---|
10789 | 10970 | if (cam != lightCamera) |
---|
10790 | 10971 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
10791 | | - LA.matConcat(matrix, parentcam.GlobalTransform(), matrix); |
---|
| 10972 | + LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix); |
---|
10792 | 10973 | |
---|
10793 | 10974 | for (int j = 0; j < 4; j++) |
---|
10794 | 10975 | { |
---|
.. | .. |
---|
10803 | 10984 | // if (parentcam != renderCamera) // not a light |
---|
10804 | 10985 | if (cam != lightCamera) |
---|
10805 | 10986 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
10806 | | - LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix); |
---|
| 10987 | + LA.matConcat(parentcam.GlobalTransform(), matrix, matrix); |
---|
10807 | 10988 | |
---|
10808 | 10989 | //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix); |
---|
10809 | 10990 | |
---|
.. | .. |
---|
10889 | 11070 | gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000); |
---|
10890 | 11071 | } |
---|
10891 | 11072 | |
---|
10892 | | - if (newenvy > -1) |
---|
| 11073 | +// if (newenvy > -1) |
---|
| 11074 | +// { |
---|
| 11075 | +// LoadEnvy(newenvy); |
---|
| 11076 | +// } |
---|
| 11077 | +// |
---|
| 11078 | +// newenvy = -1; |
---|
| 11079 | + |
---|
| 11080 | + if (object.skyboxname != null) |
---|
10893 | 11081 | { |
---|
10894 | | - LoadEnvy(newenvy); |
---|
| 11082 | + if (!object.skyboxname.equals(this.loadedskyboxname)) |
---|
| 11083 | + { |
---|
| 11084 | + LoadSkybox(object.skyboxname + "/", object.skyboxext, false); |
---|
| 11085 | + loadedskyboxname = object.skyboxname; |
---|
| 11086 | + } |
---|
10895 | 11087 | } |
---|
10896 | | - |
---|
10897 | | - newenvy = -1; |
---|
10898 | | - |
---|
| 11088 | + else |
---|
| 11089 | + { |
---|
| 11090 | + cubemap = null; |
---|
| 11091 | + loadedskyboxname = null; |
---|
| 11092 | + } |
---|
| 11093 | + |
---|
10899 | 11094 | ratio = ((double) getWidth()) / getHeight(); |
---|
10900 | 11095 | //System.out.println("ratio = " + ratio); |
---|
10901 | 11096 | |
---|
.. | .. |
---|
10911 | 11106 | |
---|
10912 | 11107 | if (!IsFrozen() && !ambientOcclusion) |
---|
10913 | 11108 | { |
---|
10914 | | - DrawSkyBox(gl); |
---|
| 11109 | + DrawSkyBox(gl, (float)ratio); |
---|
10915 | 11110 | } |
---|
10916 | 11111 | |
---|
10917 | 11112 | //if (selection_view == -1) |
---|
.. | .. |
---|
11065 | 11260 | |
---|
11066 | 11261 | try |
---|
11067 | 11262 | { |
---|
11068 | | - BindTexture(null, NOISE_TEXTURE, false, 2); |
---|
| 11263 | + BindTexture(NOISE_TEXTURE, false, 2); |
---|
11069 | 11264 | } |
---|
11070 | 11265 | catch (Exception e) |
---|
11071 | 11266 | { |
---|
.. | .. |
---|
11197 | 11392 | |
---|
11198 | 11393 | // if (cam != lightCamera) |
---|
11199 | 11394 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
11200 | | - LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013 |
---|
| 11395 | + LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013 |
---|
11201 | 11396 | } |
---|
11202 | 11397 | |
---|
11203 | 11398 | LA.xformDir(lightposition, cam.toScreen, lightposition); |
---|
.. | .. |
---|
11356 | 11551 | } |
---|
11357 | 11552 | } |
---|
11358 | 11553 | |
---|
11359 | | - if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion) |
---|
| 11554 | + if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion) |
---|
11360 | 11555 | { |
---|
11361 | 11556 | //gl.glDepthFunc(GL.GL_LEQUAL); |
---|
11362 | 11557 | //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT); |
---|
.. | .. |
---|
11364 | 11559 | |
---|
11365 | 11560 | boolean texon = textureon; |
---|
11366 | 11561 | |
---|
11367 | | - if (RENDERPROGRAM > 0) |
---|
11368 | | - { |
---|
11369 | | - gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
11370 | | - textureon = false; |
---|
11371 | | - } |
---|
| 11562 | + gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
| 11563 | + textureon = false; |
---|
| 11564 | + |
---|
11372 | 11565 | //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB); |
---|
11373 | 11566 | //System.out.println("ALLO"); |
---|
11374 | 11567 | gl.glColorMask(false, false, false, false); |
---|
11375 | 11568 | DrawObject(gl); |
---|
11376 | | - if (RENDERPROGRAM > 0) |
---|
11377 | | - { |
---|
11378 | | - gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
11379 | | - textureon = texon; |
---|
11380 | | - } |
---|
| 11569 | + |
---|
| 11570 | + gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
| 11571 | + textureon = texon; |
---|
| 11572 | + |
---|
11381 | 11573 | gl.glColorMask(true, true, true, true); |
---|
11382 | 11574 | |
---|
11383 | 11575 | gl.glDepthFunc(GL.GL_EQUAL); |
---|
11384 | | - //gl.glDepthMask(false); |
---|
| 11576 | + gl.glDepthMask(false); |
---|
11385 | 11577 | } |
---|
11386 | 11578 | |
---|
11387 | 11579 | if (false) // DrawMode() == SHADOW) |
---|
.. | .. |
---|
11721 | 11913 | ReleaseTextures(DEFAULT_TEXTURES); |
---|
11722 | 11914 | |
---|
11723 | 11915 | if (CLEANCACHE) |
---|
11724 | | - for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();) |
---|
| 11916 | + for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();) |
---|
11725 | 11917 | { |
---|
11726 | | - String tex = e.nextElement(); |
---|
| 11918 | + cTexture tex = e.nextElement(); |
---|
11727 | 11919 | |
---|
11728 | 11920 | // System.out.println("Texture --------- " + tex); |
---|
11729 | 11921 | |
---|
11730 | | - if (tex.equals("WHITE_NOISE")) |
---|
| 11922 | + if (tex.equals("WHITE_NOISE:")) |
---|
11731 | 11923 | continue; |
---|
11732 | 11924 | |
---|
11733 | 11925 | if (!usedtextures.contains(tex)) |
---|
11734 | 11926 | { |
---|
| 11927 | + CacheTexture gettex = texturepigment.get(tex); |
---|
11735 | 11928 | // System.out.println("DISPOSE +++++++++++++++ " + tex); |
---|
11736 | | - textures.get(tex).texture.dispose(); |
---|
11737 | | - textures.remove(tex); |
---|
| 11929 | + if (gettex != null) |
---|
| 11930 | + { |
---|
| 11931 | + gettex.texture.dispose(); |
---|
| 11932 | + texturepigment.remove(tex); |
---|
| 11933 | + } |
---|
| 11934 | + |
---|
| 11935 | + gettex = texturebump.get(tex); |
---|
| 11936 | + // System.out.println("DISPOSE +++++++++++++++ " + tex); |
---|
| 11937 | + if (gettex != null) |
---|
| 11938 | + { |
---|
| 11939 | + gettex.texture.dispose(); |
---|
| 11940 | + texturebump.remove(tex); |
---|
| 11941 | + } |
---|
11738 | 11942 | } |
---|
11739 | 11943 | } |
---|
11740 | 11944 | } |
---|
.. | .. |
---|
12262 | 12466 | |
---|
12263 | 12467 | //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0); |
---|
12264 | 12468 | |
---|
12265 | | - String program = |
---|
| 12469 | + String programmin = |
---|
| 12470 | + // Min shader |
---|
12266 | 12471 | "!!ARBfp1.0\n" + |
---|
| 12472 | + "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" + |
---|
| 12473 | + "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" + |
---|
| 12474 | + "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" + |
---|
| 12475 | + "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" + |
---|
| 12476 | + "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" + |
---|
| 12477 | + "PARAM light2cam0 = program.env[10];" + |
---|
| 12478 | + "PARAM light2cam1 = program.env[11];" + |
---|
| 12479 | + "PARAM light2cam2 = program.env[12];" + |
---|
| 12480 | + "TEMP temp;" + |
---|
| 12481 | + "TEMP light;" + |
---|
| 12482 | + "TEMP ndotl;" + |
---|
| 12483 | + "TEMP normal;" + |
---|
| 12484 | + "TEMP depth;" + |
---|
| 12485 | + "TEMP eye;" + |
---|
| 12486 | + "TEMP pos;" + |
---|
| 12487 | + |
---|
| 12488 | + "MAD normal, fragment.color, zero123.z, -zero123.y;" + |
---|
| 12489 | + Normalize("normal") + |
---|
| 12490 | + "MOV light, state.light[0].position;" + |
---|
| 12491 | + "DP3 ndotl.x, light, normal;" + |
---|
| 12492 | + |
---|
| 12493 | + // shadow |
---|
| 12494 | + "MOV pos, fragment.texcoord[1];" + |
---|
| 12495 | + "MOV temp, pos;" + |
---|
| 12496 | + ShadowTextureFetch("depth", "temp", "1") + |
---|
| 12497 | + //"TEX depth, fragment.texcoord[1], texture[1], 2D;" + |
---|
| 12498 | + "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" + |
---|
| 12499 | + |
---|
| 12500 | + // No shadow when out of frustum |
---|
| 12501 | + //"SGE temp.y, depth.z, zero123.y;" + |
---|
| 12502 | + //"LRP temp.x, temp.y, zero123.y, temp.x;" + |
---|
| 12503 | + |
---|
| 12504 | + "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow |
---|
| 12505 | + |
---|
| 12506 | + // Backlit |
---|
| 12507 | + "MOV pos.w, zero123.y;" + |
---|
| 12508 | + "DP4 eye.x, pos, light2cam0;" + |
---|
| 12509 | + "DP4 eye.y, pos, light2cam1;" + |
---|
| 12510 | + "DP4 eye.z, pos, light2cam2;" + |
---|
| 12511 | + Normalize("eye") + |
---|
| 12512 | + |
---|
| 12513 | + "DP3 ndotl.y, -eye, normal;" + |
---|
| 12514 | + //"MUL ndotl.y, ndotl.y, pow2.x;" + |
---|
| 12515 | + "POW ndotl.y, ndotl.y, pow2.z;" + // backlit |
---|
| 12516 | + "SUB ndotl.y, zero123.y, ndotl.y;" + |
---|
| 12517 | + //"SUB ndotl.y, zero123.y, ndotl.y;" + |
---|
| 12518 | + //"MUL ndotl.y, ndotl.y, pow2.z;" + |
---|
| 12519 | + |
---|
| 12520 | + //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient |
---|
| 12521 | + //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient |
---|
| 12522 | + |
---|
| 12523 | + // Pigment |
---|
| 12524 | + "TEX temp, fragment.texcoord[0], texture[0], 2D;" + |
---|
| 12525 | + "LRP temp, zero123.w, temp, one;" + // texture proportion |
---|
| 12526 | + "MUL temp, temp, ndotl.x;" + |
---|
| 12527 | + |
---|
| 12528 | + "MUL temp, temp, zero123.z;" + |
---|
| 12529 | + |
---|
| 12530 | + //"MUL temp, temp, ndotl.y;" + |
---|
| 12531 | + |
---|
| 12532 | + "MOV temp.w, zero123.y;" + // reset alpha |
---|
| 12533 | + "MOV result.color, temp;" + |
---|
| 12534 | + "END"; |
---|
| 12535 | + |
---|
| 12536 | + String programmax = |
---|
| 12537 | + "!!ARBfp1.0\n" + |
---|
| 12538 | + |
---|
12267 | 12539 | //"OPTION ARB_fragment_program_shadow;" + |
---|
12268 | 12540 | "PARAM light2cam0 = program.env[10];" + |
---|
12269 | 12541 | "PARAM light2cam1 = program.env[11];" + |
---|
.. | .. |
---|
12378 | 12650 | "TEMP shininess;" + |
---|
12379 | 12651 | "\n" + |
---|
12380 | 12652 | "MOV texSamp, one;" + |
---|
12381 | | - //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" + |
---|
12382 | | - |
---|
| 12653 | + |
---|
12383 | 12654 | "MOV mapgrid.x, one2048th.x;" + |
---|
12384 | 12655 | "MOV temp, fragment.texcoord[1];" + |
---|
12385 | 12656 | /* |
---|
.. | .. |
---|
12400 | 12671 | "MUL temp, floor, mapgrid.x;" + |
---|
12401 | 12672 | //"TEX depth0, temp, texture[1], 2D;" + |
---|
12402 | 12673 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12403 | | - TextureFetch("depth0", "temp", "1") + |
---|
| 12674 | + ShadowTextureFetch("depth0", "temp", "1") + |
---|
12404 | 12675 | "") + |
---|
12405 | 12676 | "ADD temp.x, temp.x, mapgrid.x;" + |
---|
12406 | 12677 | //"TEX depth1, temp, texture[1], 2D;" + |
---|
12407 | 12678 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12408 | | - TextureFetch("depth1", "temp", "1") + |
---|
| 12679 | + ShadowTextureFetch("depth1", "temp", "1") + |
---|
12409 | 12680 | "") + |
---|
12410 | 12681 | "ADD temp.y, temp.y, mapgrid.x;" + |
---|
12411 | 12682 | //"TEX depth2, temp, texture[1], 2D;" + |
---|
12412 | | - TextureFetch("depth2", "temp", "1") + |
---|
| 12683 | + ShadowTextureFetch("depth2", "temp", "1") + |
---|
12413 | 12684 | "SUB temp.x, temp.x, mapgrid.x;" + |
---|
12414 | 12685 | //"TEX depth3, temp, texture[1], 2D;" + |
---|
12415 | 12686 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12416 | | - TextureFetch("depth3", "temp", "1") + |
---|
| 12687 | + ShadowTextureFetch("depth3", "temp", "1") + |
---|
12417 | 12688 | "") + |
---|
12418 | 12689 | //"MUL texSamp0, texSamp0, state.material.front.diffuse;" + |
---|
12419 | 12690 | //"MOV params, material;" + |
---|
.. | .. |
---|
12784 | 13055 | "MAD shadow.x, buffer.x, frac.y, shadow.x;" + |
---|
12785 | 13056 | "") + |
---|
12786 | 13057 | |
---|
12787 | | - // display shadow only (bump == 0) |
---|
| 13058 | + // display shadow only (fakedepth == 0) |
---|
12788 | 13059 | "SUB temp.x, half.x, shadow.x;" + |
---|
12789 | 13060 | "MOV temp.y, -params5.z;" + // params6.x;" + |
---|
12790 | | - "SLT temp.z, temp.y, -one2048th.x;" + |
---|
| 13061 | + "SLT temp.z, temp.y, -c256i.x;" + |
---|
12791 | 13062 | "SUB temp.y, one.x, temp.z;" + |
---|
12792 | 13063 | "MUL temp.x, temp.x, temp.y;" + |
---|
12793 | 13064 | "KIL temp.x;" + |
---|
.. | .. |
---|
13118 | 13389 | //once = true; |
---|
13119 | 13390 | } |
---|
13120 | 13391 | |
---|
| 13392 | + String program = programmax; |
---|
| 13393 | + |
---|
| 13394 | + if (Globals.MINSHADER) |
---|
| 13395 | + { |
---|
| 13396 | + program = programmin; |
---|
| 13397 | + } |
---|
| 13398 | + |
---|
13121 | 13399 | System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length()); |
---|
13122 | 13400 | System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : "")); |
---|
13123 | 13401 | loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program); |
---|
.. | .. |
---|
13211 | 13489 | return out; |
---|
13212 | 13490 | } |
---|
13213 | 13491 | |
---|
13214 | | - String TextureFetch(String dest, String src, String unit) |
---|
| 13492 | + // Also does frustum culling |
---|
| 13493 | + String ShadowTextureFetch(String dest, String src, String unit) |
---|
13215 | 13494 | { |
---|
13216 | 13495 | return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" + |
---|
13217 | 13496 | "SGE " + src + ".w, " + src + ".x, eps.x;" + |
---|
13218 | 13497 | "SGE " + src + ".z, " + src + ".y, eps.x;" + |
---|
| 13498 | + "SLT " + dest + ".x, " + src + ".x, one.x;" + |
---|
| 13499 | + "SLT " + dest + ".y, " + src + ".y, one.x;" + |
---|
13219 | 13500 | "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;" + |
---|
| 13501 | + "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" + |
---|
| 13502 | + "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" + |
---|
13224 | 13503 | //"SWZ buffer, temp, w,w,w,w;"; |
---|
13225 | | - "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" + |
---|
| 13504 | + //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" + |
---|
13226 | 13505 | "SUB " + src + ".z, " + "one.x, " + src + ".w;" + |
---|
13227 | 13506 | //"MUL " + src + ".z, " + src + ".z, infinity.x;" + |
---|
13228 | 13507 | //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;"; |
---|
13229 | | - "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
| 13508 | + //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
13230 | 13509 | |
---|
13231 | | - //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;"; |
---|
13232 | | - //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;"; |
---|
| 13510 | + //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;"; |
---|
| 13511 | + "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
13233 | 13512 | } |
---|
13234 | 13513 | |
---|
13235 | 13514 | String Shadow(String depth, String shadow) |
---|
.. | .. |
---|
13276 | 13555 | "SLT temp.x, temp.x, zero.x;" + // shadoweps |
---|
13277 | 13556 | "LRP " + shadow + ", temp.x, one, " + shadow + ";" + |
---|
13278 | 13557 | |
---|
13279 | | - // No shadow when out of frustrum |
---|
| 13558 | + // No shadow when out of frustum |
---|
13280 | 13559 | "SGE temp.x, " + depth + ".z, one.z;" + |
---|
13281 | 13560 | "LRP " + shadow + ", temp.x, one, " + shadow + ";" + |
---|
13282 | 13561 | ""; |
---|
.. | .. |
---|
14074 | 14353 | drag = false; |
---|
14075 | 14354 | //System.out.println("Mouse DOWN"); |
---|
14076 | 14355 | 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); |
---|
| 14356 | + //ClickInfo info = new ClickInfo(); |
---|
| 14357 | + object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
| 14358 | + object.clickInfo.pane = this; |
---|
| 14359 | + object.clickInfo.camera = renderCamera; |
---|
| 14360 | + object.clickInfo.x = x; |
---|
| 14361 | + object.clickInfo.y = y; |
---|
| 14362 | + object.clickInfo.modifiers = modifiersex; |
---|
| 14363 | + editObj = object.doEditClick(//info, |
---|
| 14364 | + 0); |
---|
14085 | 14365 | if (!editObj) |
---|
14086 | 14366 | { |
---|
14087 | 14367 | hasMarquee = true; |
---|
.. | .. |
---|
14365 | 14645 | MODIFIERS |= COMMAND; |
---|
14366 | 14646 | /**/ |
---|
14367 | 14647 | if((mod&SHIFT) == SHIFT) |
---|
14368 | | - manipCamera.RotatePosition(0, -speed); |
---|
14369 | | - else |
---|
14370 | 14648 | manipCamera.BackForth(0, -speed*delta, 0); // getWidth()); |
---|
| 14649 | + else |
---|
| 14650 | + manipCamera.RotatePosition(0, -speed); |
---|
14371 | 14651 | /**/ |
---|
14372 | 14652 | if ((mod & SHIFT) == SHIFT) |
---|
14373 | 14653 | { |
---|
.. | .. |
---|
14386 | 14666 | MODIFIERS |= COMMAND; |
---|
14387 | 14667 | /**/ |
---|
14388 | 14668 | if((mod&SHIFT) == SHIFT) |
---|
14389 | | - manipCamera.RotatePosition(0, speed); |
---|
14390 | | - else |
---|
14391 | 14669 | manipCamera.BackForth(0, speed*delta, 0); // getWidth()); |
---|
| 14670 | + else |
---|
| 14671 | + manipCamera.RotatePosition(0, speed); |
---|
14392 | 14672 | /**/ |
---|
14393 | 14673 | if ((mod & SHIFT) == SHIFT) |
---|
14394 | 14674 | { |
---|
.. | .. |
---|
14481 | 14761 | if (editObj) |
---|
14482 | 14762 | { |
---|
14483 | 14763 | drag = true; |
---|
14484 | | - ClickInfo info = new ClickInfo(); |
---|
14485 | | - info.bounds.setBounds(0, 0, |
---|
| 14764 | + //ClickInfo info = new ClickInfo(); |
---|
| 14765 | + object.clickInfo.bounds.setBounds(0, 0, |
---|
14486 | 14766 | (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); |
---|
| 14767 | + object.clickInfo.pane = this; |
---|
| 14768 | + object.clickInfo.camera = renderCamera; |
---|
| 14769 | + object.clickInfo.x = x; |
---|
| 14770 | + object.clickInfo.y = y; |
---|
| 14771 | + object //.GetWindow().copy |
---|
| 14772 | + .doEditDrag(//info, |
---|
| 14773 | + (modifiers & MouseEvent.BUTTON3_MASK) != 0); |
---|
14493 | 14774 | } else |
---|
14494 | 14775 | { |
---|
14495 | 14776 | if (x < startX) |
---|
.. | .. |
---|
14638 | 14919 | } |
---|
14639 | 14920 | } |
---|
14640 | 14921 | |
---|
| 14922 | +// ClickInfo clickInfo = new ClickInfo(); |
---|
| 14923 | + |
---|
14641 | 14924 | public void mouseMoved(MouseEvent e) |
---|
14642 | 14925 | { |
---|
14643 | 14926 | //System.out.println("mouseMoved: " + e); |
---|
14644 | 14927 | if (isRenderer) |
---|
14645 | 14928 | return; |
---|
14646 | 14929 | |
---|
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; |
---|
| 14930 | + // Mouse cursor feedback |
---|
| 14931 | + object.clickInfo.x = e.getX(); |
---|
| 14932 | + object.clickInfo.y = e.getY(); |
---|
| 14933 | + object.clickInfo.modifiers = e.getModifiersEx(); |
---|
| 14934 | + object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
| 14935 | + object.clickInfo.pane = this; |
---|
| 14936 | + object.clickInfo.camera = renderCamera; |
---|
14654 | 14937 | if (!isRenderer) |
---|
14655 | 14938 | { |
---|
14656 | 14939 | //ObjEditor editWindow = object.editWindow; |
---|
14657 | 14940 | //Object3D copy = editWindow.copy; |
---|
14658 | | - if (object.doEditClick(ci, 0)) |
---|
| 14941 | + if (object.doEditClick(//clickInfo, |
---|
| 14942 | + 0)) |
---|
14659 | 14943 | { |
---|
14660 | 14944 | setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
---|
14661 | 14945 | } else |
---|
.. | .. |
---|
14927 | 15211 | // break; |
---|
14928 | 15212 | case 'T': |
---|
14929 | 15213 | CACHETEXTURE ^= true; |
---|
14930 | | - textures.clear(); |
---|
| 15214 | + texturepigment.clear(); |
---|
| 15215 | + texturebump.clear(); |
---|
14931 | 15216 | // repaint(); |
---|
14932 | 15217 | break; |
---|
14933 | 15218 | case 'Y': |
---|
.. | .. |
---|
15104 | 15389 | OCCLUSION_CULLING ^= true; |
---|
15105 | 15390 | System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING); |
---|
15106 | 15391 | break; |
---|
15107 | | - case '0': envyoff ^= true; repaint(); break; |
---|
| 15392 | + //case '0': envyoff ^= true; repaint(); break; |
---|
15108 | 15393 | case '1': |
---|
15109 | 15394 | case '2': |
---|
15110 | 15395 | case '3': |
---|
15111 | 15396 | case '4': |
---|
15112 | 15397 | case '5': |
---|
15113 | | - newenvy = Character.getNumericValue(key); |
---|
15114 | | - repaint(); |
---|
15115 | | - break; |
---|
15116 | 15398 | case '6': |
---|
15117 | 15399 | case '7': |
---|
15118 | 15400 | case '8': |
---|
15119 | 15401 | case '9': |
---|
15120 | | - BGcolor = (key - '6')/3.f; |
---|
| 15402 | + if (true) // envyoff) |
---|
| 15403 | + { |
---|
| 15404 | + BGcolor = (key - '1')/8.f; |
---|
| 15405 | + } |
---|
| 15406 | + else |
---|
| 15407 | + { |
---|
| 15408 | + //newenvy = Character.getNumericValue(key); |
---|
| 15409 | + } |
---|
15121 | 15410 | repaint(); |
---|
15122 | 15411 | break; |
---|
15123 | 15412 | case '!': |
---|
.. | .. |
---|
15680 | 15969 | |
---|
15681 | 15970 | int width = getBounds().width; |
---|
15682 | 15971 | int height = getBounds().height; |
---|
15683 | | - ClickInfo info = new ClickInfo(); |
---|
15684 | | - info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom)); |
---|
15685 | 15972 | //Image img = CreateImage(width, height); |
---|
15686 | 15973 | //System.out.println("width = " + width + "; height = " + height + "\n"); |
---|
15687 | 15974 | |
---|
.. | .. |
---|
15758 | 16045 | } |
---|
15759 | 16046 | if (object != null && !hasMarquee) |
---|
15760 | 16047 | { |
---|
| 16048 | + if (object.clickInfo == null) |
---|
| 16049 | + object.clickInfo = new ClickInfo(); |
---|
| 16050 | + ClickInfo info = object.clickInfo; |
---|
| 16051 | + //ClickInfo info = new ClickInfo(); |
---|
| 16052 | + info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom)); |
---|
| 16053 | + |
---|
15761 | 16054 | if (isRenderer) |
---|
15762 | 16055 | { |
---|
15763 | | - info.flags++; |
---|
| 16056 | + object.clickInfo.flags++; |
---|
15764 | 16057 | double frameAspect = (double) width / (double) height; |
---|
15765 | 16058 | if (frameAspect > renderCamera.aspect) |
---|
15766 | 16059 | { |
---|
15767 | 16060 | int desired = (int) ((double) height * renderCamera.aspect); |
---|
15768 | | - info.bounds.width -= width - desired; |
---|
15769 | | - info.bounds.x += (width - desired) / 2; |
---|
| 16061 | + object.clickInfo.bounds.width -= width - desired; |
---|
| 16062 | + object.clickInfo.bounds.x += (width - desired) / 2; |
---|
15770 | 16063 | } else |
---|
15771 | 16064 | { |
---|
15772 | 16065 | int desired = (int) ((double) width / renderCamera.aspect); |
---|
15773 | | - info.bounds.height -= height - desired; |
---|
15774 | | - info.bounds.y += (height - desired) / 2; |
---|
| 16066 | + object.clickInfo.bounds.height -= height - desired; |
---|
| 16067 | + object.clickInfo.bounds.y += (height - desired) / 2; |
---|
15775 | 16068 | } |
---|
15776 | 16069 | } |
---|
15777 | 16070 | |
---|
15778 | | - info.g = gr; |
---|
15779 | | - info.camera = renderCamera; |
---|
| 16071 | + object.clickInfo.g = gr; |
---|
| 16072 | + object.clickInfo.camera = renderCamera; |
---|
15780 | 16073 | /* |
---|
15781 | 16074 | // Memory intensive (brep.verticescopy) |
---|
15782 | 16075 | if (!(object instanceof Composite)) |
---|
15783 | 16076 | object.draw(info, 0, false); // SLOW : |
---|
15784 | 16077 | */ |
---|
15785 | | - if (!isRenderer) |
---|
| 16078 | + if (!isRenderer) // && drag) |
---|
15786 | 16079 | { |
---|
15787 | 16080 | Grafreed.Assert(object != null); |
---|
15788 | 16081 | Grafreed.Assert(object.selection != null); |
---|
.. | .. |
---|
15790 | 16083 | { |
---|
15791 | 16084 | int hitSomething = object.selection.get(0).hitSomething; |
---|
15792 | 16085 | |
---|
15793 | | - info.DX = 0; |
---|
15794 | | - info.DY = 0; |
---|
15795 | | - info.W = 1; |
---|
| 16086 | + object.clickInfo.DX = 0; |
---|
| 16087 | + object.clickInfo.DY = 0; |
---|
| 16088 | + object.clickInfo.W = 1; |
---|
15796 | 16089 | if (hitSomething == Object3D.hitCenter) |
---|
15797 | 16090 | { |
---|
15798 | 16091 | info.DX = X; |
---|
.. | .. |
---|
15804 | 16097 | info.DY -= info.bounds.height/2; |
---|
15805 | 16098 | } |
---|
15806 | 16099 | |
---|
15807 | | - object.drawEditHandles(info, 0); |
---|
| 16100 | + object.drawEditHandles(//info, |
---|
| 16101 | + 0); |
---|
15808 | 16102 | |
---|
15809 | 16103 | if (drag && (X != 0 || Y != 0)) |
---|
15810 | 16104 | { |
---|
.. | .. |
---|
16303 | 16597 | private /*static*/ boolean firstime; |
---|
16304 | 16598 | private /*static*/ cVector newView = new cVector(); |
---|
16305 | 16599 | private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"}; |
---|
| 16600 | + private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"}; |
---|
| 16601 | + private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"}; |
---|
16306 | 16602 | private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X, |
---|
16307 | 16603 | GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X, |
---|
16308 | 16604 | GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y, |
---|
.. | .. |
---|
16315 | 16611 | { |
---|
16316 | 16612 | com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP); |
---|
16317 | 16613 | |
---|
| 16614 | + int usedsuf = 0; |
---|
| 16615 | + |
---|
16318 | 16616 | for (int i = 0; i < suffixes.length; i++) |
---|
16319 | 16617 | { |
---|
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) |
---|
| 16618 | + String[] suffixe = suffixes; |
---|
| 16619 | + String[] fallback = suffixes2; |
---|
| 16620 | + String[] fallfallback = suffixes3; |
---|
| 16621 | + |
---|
| 16622 | + for (int c=usedsuf; --c>=0;) |
---|
16325 | 16623 | { |
---|
16326 | | - throw new IOException("Unable to load texture " + resourceName); |
---|
| 16624 | +// String[] temp = suffixe; |
---|
| 16625 | +// suffixe = fallback; |
---|
| 16626 | +// fallback = fallfallback; |
---|
| 16627 | +// fallfallback = temp; |
---|
16327 | 16628 | } |
---|
| 16629 | + |
---|
| 16630 | + String resourceName = basename + suffixe[i] + "." + suffix; |
---|
| 16631 | + TextureData data; |
---|
| 16632 | + |
---|
| 16633 | + try |
---|
| 16634 | + { |
---|
| 16635 | + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
| 16636 | + mipmapped, |
---|
| 16637 | + FileUtil.getFileSuffix(resourceName)); |
---|
| 16638 | + } |
---|
| 16639 | + catch (Exception e) |
---|
| 16640 | + { |
---|
| 16641 | + try |
---|
| 16642 | + { |
---|
| 16643 | + resourceName = basename + fallback[i] + "." + suffix; |
---|
| 16644 | + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
| 16645 | + mipmapped, |
---|
| 16646 | + FileUtil.getFileSuffix(resourceName)); |
---|
| 16647 | + } |
---|
| 16648 | + catch (Exception e2) |
---|
| 16649 | + { |
---|
| 16650 | + resourceName = basename + fallfallback[i] + "." + suffix; |
---|
| 16651 | + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
| 16652 | + mipmapped, |
---|
| 16653 | + FileUtil.getFileSuffix(resourceName)); |
---|
| 16654 | + } |
---|
| 16655 | + } |
---|
| 16656 | + |
---|
16328 | 16657 | //System.out.println("Target = " + targets[i]); |
---|
16329 | 16658 | cubemap.updateImage(data, targets[i]); |
---|
16330 | 16659 | } |
---|
16331 | 16660 | |
---|
16332 | 16661 | return cubemap; |
---|
16333 | 16662 | } |
---|
| 16663 | + |
---|
16334 | 16664 | int bigsphere = -1; |
---|
16335 | 16665 | |
---|
16336 | 16666 | float BGcolor = 0.5f; |
---|
16337 | 16667 | |
---|
16338 | | - private void DrawSkyBox(GL gl) |
---|
| 16668 | + float ambientLight[] = {1f, 1f, 1f, 1.0f}; |
---|
| 16669 | + |
---|
| 16670 | + private void DrawSkyBox(GL gl, float ratio) |
---|
16339 | 16671 | { |
---|
16340 | | - if (envyoff || cubemap == null) |
---|
| 16672 | + if (//envyoff || |
---|
| 16673 | + WIREFRAME || |
---|
| 16674 | + cubemap == null) |
---|
16341 | 16675 | { |
---|
16342 | 16676 | gl.glClearColor(BGcolor, BGcolor, BGcolor, 1); |
---|
16343 | 16677 | gl.glClear(gl.GL_COLOR_BUFFER_BIT); |
---|
.. | .. |
---|
16352 | 16686 | // Compensates for ExaminerViewer's modification of modelview matrix |
---|
16353 | 16687 | gl.glMatrixMode(GL.GL_MODELVIEW); |
---|
16354 | 16688 | gl.glLoadIdentity(); |
---|
| 16689 | + gl.glScalef(1,ratio,1); |
---|
16355 | 16690 | |
---|
| 16691 | +// colorV[0] = 2; |
---|
| 16692 | +// colorV[1] = 2; |
---|
| 16693 | +// colorV[2] = 2; |
---|
| 16694 | +// colorV[3] = 1; |
---|
| 16695 | +// gl.glDisable(gl.GL_COLOR_MATERIAL); |
---|
| 16696 | +// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0); |
---|
| 16697 | +// |
---|
| 16698 | +// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0); |
---|
| 16699 | + |
---|
16356 | 16700 | //gl.glActiveTexture(GL.GL_TEXTURE1); |
---|
16357 | 16701 | //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP); |
---|
16358 | 16702 | |
---|
.. | .. |
---|
16384 | 16728 | { |
---|
16385 | 16729 | gl.glScalef(1.0f, -1.0f, 1.0f); |
---|
16386 | 16730 | } |
---|
| 16731 | + gl.glScalef(-1.0f, 1.0f, 1.0f); |
---|
16387 | 16732 | gl.glMultMatrixd(viewrot_1, 0); |
---|
16388 | 16733 | gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f); |
---|
16389 | 16734 | //viewer.updateInverseRotation(gl); |
---|
.. | .. |
---|
16642 | 16987 | //new Exception().printStackTrace(); |
---|
16643 | 16988 | System.out.println("select buffer init"); |
---|
16644 | 16989 | // Use debug pipeline |
---|
16645 | | - drawable.setGL(new DebugGL(drawable.getGL())); |
---|
| 16990 | + //drawable.setGL(new DebugGL(drawable.getGL())); |
---|
16646 | 16991 | |
---|
16647 | 16992 | GL gl = drawable.getGL(); |
---|
16648 | 16993 | |
---|