.. | .. |
---|
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 = 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; |
---|
.. | .. |
---|
169 | 206 | |
---|
170 | 207 | SetCamera(cam); |
---|
171 | 208 | |
---|
172 | | - SetLight(new Camera(new cVector(10, 10, -20))); |
---|
| 209 | + // Warning: not used. |
---|
| 210 | + SetLight(new Camera(new cVector(15, 10, -20))); |
---|
173 | 211 | |
---|
174 | 212 | object = o; |
---|
175 | 213 | |
---|
.. | .. |
---|
2298 | 2336 | HANDLES ^= true; |
---|
2299 | 2337 | } |
---|
2300 | 2338 | |
---|
| 2339 | + Object3D paintFolder; |
---|
| 2340 | + |
---|
2301 | 2341 | void TogglePaint() |
---|
2302 | 2342 | { |
---|
2303 | 2343 | PAINTMODE ^= true; |
---|
2304 | 2344 | paintcount = 0; |
---|
| 2345 | + |
---|
| 2346 | + if (PAINTMODE) |
---|
| 2347 | + { |
---|
| 2348 | + paintFolder = GetFolder(); |
---|
| 2349 | + } |
---|
2305 | 2350 | } |
---|
2306 | 2351 | |
---|
2307 | 2352 | void SwapCamera(int a, int b) |
---|
.. | .. |
---|
2398 | 2443 | return currentGL; |
---|
2399 | 2444 | } |
---|
2400 | 2445 | |
---|
| 2446 | + static private BufferedImage CreateBim(TextureData texturedata) |
---|
| 2447 | + { |
---|
| 2448 | + Grafreed.Assert(texturedata != null); |
---|
| 2449 | + |
---|
| 2450 | + int width = texturedata.getWidth(); |
---|
| 2451 | + int height = texturedata.getHeight(); |
---|
| 2452 | + |
---|
| 2453 | + Buffer buffer = texturedata.getBuffer(); |
---|
| 2454 | + ByteBuffer bytebuf = (ByteBuffer)buffer; |
---|
| 2455 | + |
---|
| 2456 | + byte[] bytes = bytebuf.array(); |
---|
| 2457 | + |
---|
| 2458 | + return CreateBim(bytes, width, height); |
---|
| 2459 | + } |
---|
| 2460 | + |
---|
2401 | 2461 | /**/ |
---|
2402 | 2462 | class CacheTexture |
---|
2403 | 2463 | { |
---|
.. | .. |
---|
2406 | 2466 | |
---|
2407 | 2467 | int resolution; |
---|
2408 | 2468 | |
---|
2409 | | - CacheTexture(com.sun.opengl.util.texture.Texture tex, int res) |
---|
| 2469 | + CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res) |
---|
2410 | 2470 | { |
---|
2411 | | - texture = tex; |
---|
| 2471 | + texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata); |
---|
| 2472 | + texturedata = texdata; |
---|
2412 | 2473 | resolution = res; |
---|
2413 | 2474 | } |
---|
2414 | 2475 | } |
---|
2415 | 2476 | /**/ |
---|
2416 | 2477 | |
---|
2417 | 2478 | // TEXTURE static Texture texture; |
---|
2418 | | - static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures |
---|
2419 | | - = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>(); |
---|
2420 | | - static public java.util.Hashtable<String, String> usedtextures = new java.util.Hashtable<String, String>(); |
---|
| 2479 | + static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>(); |
---|
| 2480 | + static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>(); |
---|
| 2481 | + static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>(); |
---|
| 2482 | + static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>(); |
---|
| 2483 | + |
---|
2421 | 2484 | int pigmentdepth = 0; |
---|
2422 | 2485 | public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536]; |
---|
2423 | 2486 | int bumpdepth = 0; |
---|
2424 | 2487 | public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536]; |
---|
2425 | 2488 | //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE"; |
---|
2426 | 2489 | public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP"); |
---|
2427 | | - public static String NOISE_TEXTURE = "WHITE_NOISE"; |
---|
| 2490 | + public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:"); |
---|
2428 | 2491 | // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL"); |
---|
2429 | 2492 | |
---|
2430 | | - com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump) |
---|
| 2493 | + com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump) |
---|
2431 | 2494 | { |
---|
2432 | 2495 | TextureData texturedata = null; |
---|
2433 | 2496 | |
---|
.. | .. |
---|
2446 | 2509 | if (bump) |
---|
2447 | 2510 | texturedata = ConvertBump(texturedata, false); |
---|
2448 | 2511 | |
---|
2449 | | - com.sun.opengl.util.texture.Texture texture = |
---|
2450 | | - com.sun.opengl.util.texture.TextureIO.newTexture(texturedata); |
---|
| 2512 | +// com.sun.opengl.util.texture.Texture texture = |
---|
| 2513 | +// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata); |
---|
2451 | 2514 | |
---|
2452 | | - texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT); |
---|
2453 | | - texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT); |
---|
| 2515 | + //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT); |
---|
| 2516 | + //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT); |
---|
2454 | 2517 | |
---|
2455 | | - return texture; |
---|
| 2518 | + return texturedata; |
---|
| 2519 | + } |
---|
| 2520 | + |
---|
| 2521 | + com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump) |
---|
| 2522 | + { |
---|
| 2523 | + TextureData texturedata = null; |
---|
| 2524 | + |
---|
| 2525 | + try |
---|
| 2526 | + { |
---|
| 2527 | + texturedata = |
---|
| 2528 | + com.sun.opengl.util.texture.TextureIO.newTextureData( |
---|
| 2529 | + bim, |
---|
| 2530 | + true); |
---|
| 2531 | + } catch (Exception e) |
---|
| 2532 | + { |
---|
| 2533 | + throw new javax.media.opengl.GLException(e); |
---|
| 2534 | + } |
---|
| 2535 | + |
---|
| 2536 | + if (bump) |
---|
| 2537 | + texturedata = ConvertBump(texturedata, false); |
---|
| 2538 | + |
---|
| 2539 | + return texturedata; |
---|
2456 | 2540 | } |
---|
2457 | 2541 | |
---|
2458 | 2542 | boolean HUESMOOTH = true; // wrap around bug... true; |
---|
.. | .. |
---|
3525 | 3609 | |
---|
3526 | 3610 | System.out.println("LOADING TEXTURE : " + name); |
---|
3527 | 3611 | |
---|
| 3612 | + Object x = texturedata.getMipmapData(); // .getBuffer(); |
---|
| 3613 | + |
---|
3528 | 3614 | // |
---|
3529 | 3615 | if (false) // compressbit > 0) |
---|
3530 | 3616 | { |
---|
.. | .. |
---|
7923 | 8009 | String pigment = Object3D.GetPigment(tex); |
---|
7924 | 8010 | String bump = Object3D.GetBump(tex); |
---|
7925 | 8011 | |
---|
7926 | | - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8012 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
7927 | 8013 | { |
---|
7928 | 8014 | // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment); |
---|
7929 | 8015 | // System.out.println("; bump = " + bump); |
---|
.. | .. |
---|
7938 | 8024 | pigment = null; |
---|
7939 | 8025 | } |
---|
7940 | 8026 | |
---|
7941 | | - ReleaseTexture(bump, true); |
---|
7942 | | - ReleaseTexture(pigment, false); |
---|
| 8027 | + ReleaseTexture(tex, true); |
---|
| 8028 | + ReleaseTexture(tex, false); |
---|
7943 | 8029 | } |
---|
7944 | 8030 | |
---|
7945 | 8031 | public void ReleasePigmentTexture(cTexture tex) // INTERFACE |
---|
.. | .. |
---|
7957 | 8043 | |
---|
7958 | 8044 | String pigment = Object3D.GetPigment(tex); |
---|
7959 | 8045 | |
---|
7960 | | - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8046 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
7961 | 8047 | { |
---|
7962 | 8048 | // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment); |
---|
7963 | 8049 | // System.out.println("; bump = " + bump); |
---|
.. | .. |
---|
7968 | 8054 | pigment = null; |
---|
7969 | 8055 | } |
---|
7970 | 8056 | |
---|
7971 | | - ReleaseTexture(pigment, false); |
---|
| 8057 | + ReleaseTexture(tex, false); |
---|
7972 | 8058 | } |
---|
7973 | 8059 | |
---|
7974 | 8060 | public void ReleaseBumpTexture(cTexture tex) // INTERFACE |
---|
.. | .. |
---|
7986 | 8072 | |
---|
7987 | 8073 | String bump = Object3D.GetBump(tex); |
---|
7988 | 8074 | |
---|
7989 | | - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8075 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
7990 | 8076 | { |
---|
7991 | 8077 | // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment); |
---|
7992 | 8078 | // System.out.println("; bump = " + bump); |
---|
.. | .. |
---|
7997 | 8083 | bump = null; |
---|
7998 | 8084 | } |
---|
7999 | 8085 | |
---|
8000 | | - ReleaseTexture(bump, true); |
---|
| 8086 | + ReleaseTexture(tex, true); |
---|
8001 | 8087 | } |
---|
8002 | 8088 | |
---|
8003 | | - void ReleaseTexture(String tex, boolean bump) |
---|
| 8089 | + void ReleaseTexture(cTexture tex, boolean bump) |
---|
8004 | 8090 | { |
---|
8005 | 8091 | if (// DrawMode() != 0 || /*tex == null ||*/ |
---|
8006 | 8092 | ambientOcclusion ) // || !textureon) |
---|
.. | .. |
---|
8011 | 8097 | CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null; |
---|
8012 | 8098 | |
---|
8013 | 8099 | if (tex != null) |
---|
8014 | | - texture = textures.get(tex); |
---|
| 8100 | + texture = bump ? texturebump.get(tex) : texturepigment.get(tex); |
---|
8015 | 8101 | |
---|
8016 | 8102 | // //assert( texture != null ); |
---|
8017 | 8103 | // if (texture == null) |
---|
.. | .. |
---|
8105 | 8191 | |
---|
8106 | 8192 | /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE |
---|
8107 | 8193 | { |
---|
8108 | | - if (// DrawMode() != 0 || /*tex == null ||*/ |
---|
8109 | | - ambientOcclusion ) // || !textureon) |
---|
8110 | | - { |
---|
8111 | | - return; // false; |
---|
8112 | | - } |
---|
8113 | | - |
---|
8114 | | - if (tex == null) |
---|
8115 | | - { |
---|
8116 | | - BindTexture(null,false,resolution); |
---|
8117 | | - BindTexture(null,true,resolution); |
---|
8118 | | - return; |
---|
8119 | | - } |
---|
| 8194 | +// if (// DrawMode() != 0 || /*tex == null ||*/ |
---|
| 8195 | +// ambientOcclusion ) // || !textureon) |
---|
| 8196 | +// { |
---|
| 8197 | +// return; // false; |
---|
| 8198 | +// } |
---|
| 8199 | +// |
---|
| 8200 | +// if (tex == null) |
---|
| 8201 | +// { |
---|
| 8202 | +// BindTexture(null,false,resolution); |
---|
| 8203 | +// BindTexture(null,true,resolution); |
---|
| 8204 | +// return; |
---|
| 8205 | +// } |
---|
| 8206 | +// |
---|
| 8207 | +// String pigment = Object3D.GetPigment(tex); |
---|
| 8208 | +// String bump = Object3D.GetBump(tex); |
---|
| 8209 | +// |
---|
| 8210 | +// usedtextures.add(pigment); |
---|
| 8211 | +// usedtextures.add(bump); |
---|
| 8212 | +// |
---|
| 8213 | +// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8214 | +// { |
---|
| 8215 | +// // System.out.print("BIND +++++++++++++++ pigment = " + pigment); |
---|
| 8216 | +// // System.out.println("; bump = " + bump); |
---|
| 8217 | +// } |
---|
| 8218 | +// |
---|
| 8219 | +// if (bump.equals("")) |
---|
| 8220 | +// { |
---|
| 8221 | +// bump = null; |
---|
| 8222 | +// } |
---|
| 8223 | +// if (pigment.equals("")) |
---|
| 8224 | +// { |
---|
| 8225 | +// pigment = null; |
---|
| 8226 | +// } |
---|
| 8227 | +// |
---|
| 8228 | +// GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
| 8229 | +// BindTexture(pigment, false, resolution); |
---|
| 8230 | +// GetGL().glActiveTexture(GetGL().GL_TEXTURE2); |
---|
| 8231 | +// BindTexture(bump, true, resolution); |
---|
| 8232 | +// GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
| 8233 | +// |
---|
| 8234 | +// return; // true; |
---|
8120 | 8235 | |
---|
8121 | | - String pigment = Object3D.GetPigment(tex); |
---|
8122 | | - String bump = Object3D.GetBump(tex); |
---|
8123 | | - |
---|
8124 | | - usedtextures.put(pigment, pigment); |
---|
8125 | | - usedtextures.put(bump, bump); |
---|
8126 | | - |
---|
8127 | | - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
8128 | | - { |
---|
8129 | | - // System.out.print("BIND +++++++++++++++ pigment = " + pigment); |
---|
8130 | | - // System.out.println("; bump = " + bump); |
---|
8131 | | - } |
---|
8132 | | - |
---|
8133 | | - if (bump.equals("")) |
---|
8134 | | - { |
---|
8135 | | - bump = null; |
---|
8136 | | - } |
---|
8137 | | - if (pigment.equals("")) |
---|
8138 | | - { |
---|
8139 | | - pigment = null; |
---|
8140 | | - } |
---|
8141 | | - |
---|
8142 | | - GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
8143 | | - BindTexture(pigment, false, resolution); |
---|
8144 | | - GetGL().glActiveTexture(GetGL().GL_TEXTURE2); |
---|
8145 | | - BindTexture(bump, true, resolution); |
---|
8146 | | - GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
8147 | | - |
---|
8148 | | - return; // true; |
---|
| 8236 | + BindPigmentTexture(tex, resolution); |
---|
| 8237 | + BindBumpTexture(tex, resolution); |
---|
8149 | 8238 | } |
---|
8150 | 8239 | |
---|
8151 | 8240 | /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE |
---|
.. | .. |
---|
8164 | 8253 | |
---|
8165 | 8254 | String pigment = Object3D.GetPigment(tex); |
---|
8166 | 8255 | |
---|
8167 | | - usedtextures.put(pigment, pigment); |
---|
| 8256 | + usedtextures.add(tex); |
---|
8168 | 8257 | |
---|
8169 | | - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8258 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
8170 | 8259 | { |
---|
8171 | 8260 | // System.out.print("BIND +++++++++++++++ pigment = " + pigment); |
---|
8172 | 8261 | // System.out.println("; bump = " + bump); |
---|
.. | .. |
---|
8178 | 8267 | } |
---|
8179 | 8268 | |
---|
8180 | 8269 | GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
8181 | | - BindTexture(pigment, false, resolution); |
---|
| 8270 | + BindTexture(tex, false, resolution); |
---|
8182 | 8271 | } |
---|
8183 | 8272 | |
---|
8184 | 8273 | /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE |
---|
.. | .. |
---|
8197 | 8286 | |
---|
8198 | 8287 | String bump = Object3D.GetBump(tex); |
---|
8199 | 8288 | |
---|
8200 | | - usedtextures.put(bump, bump); |
---|
| 8289 | + usedtextures.add(tex); |
---|
8201 | 8290 | |
---|
8202 | | - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8291 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
8203 | 8292 | { |
---|
8204 | 8293 | // System.out.print("BIND +++++++++++++++ pigment = " + pigment); |
---|
8205 | 8294 | // System.out.println("; bump = " + bump); |
---|
.. | .. |
---|
8211 | 8300 | } |
---|
8212 | 8301 | |
---|
8213 | 8302 | GetGL().glActiveTexture(GetGL().GL_TEXTURE2); |
---|
8214 | | - BindTexture(bump, true, resolution); |
---|
| 8303 | + BindTexture(tex, true, resolution); |
---|
8215 | 8304 | GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
8216 | 8305 | } |
---|
8217 | 8306 | |
---|
.. | .. |
---|
8235 | 8324 | return fileExists; |
---|
8236 | 8325 | } |
---|
8237 | 8326 | |
---|
8238 | | - CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception |
---|
| 8327 | + CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8239 | 8328 | { |
---|
8240 | | - CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null; |
---|
| 8329 | + CacheTexture texturecache = null; |
---|
8241 | 8330 | |
---|
8242 | 8331 | if (tex != null) |
---|
8243 | 8332 | { |
---|
8244 | | - String texname = tex; |
---|
| 8333 | + String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex); |
---|
| 8334 | + byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata; |
---|
| 8335 | + |
---|
| 8336 | + if (texname.equals("") && texdata == null) |
---|
| 8337 | + { |
---|
| 8338 | + return null; |
---|
| 8339 | + } |
---|
8245 | 8340 | |
---|
8246 | 8341 | String fallbackTextureName = defaultDirectory + "/Textures/" + texname; |
---|
8247 | 8342 | |
---|
.. | .. |
---|
8251 | 8346 | // else |
---|
8252 | 8347 | // if (!texname.startsWith("/")) |
---|
8253 | 8348 | // texname = "/Users/nbriere/Textures/" + texname; |
---|
8254 | | - if (!FileExists(tex)) |
---|
| 8349 | + if (!FileExists(texname)) |
---|
8255 | 8350 | { |
---|
8256 | 8351 | texname = fallbackTextureName; |
---|
8257 | 8352 | } |
---|
8258 | 8353 | |
---|
8259 | 8354 | if (CACHETEXTURE) |
---|
8260 | | - texture = textures.get(texname); // TEXTURE CACHE |
---|
8261 | | - |
---|
8262 | | - TextureData texturedata = null; |
---|
8263 | | - |
---|
8264 | | - if (texture == null || texture.resolution < resolution) |
---|
8265 | 8355 | { |
---|
8266 | | - if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals("")) |
---|
| 8356 | + if (texdata == null) |
---|
| 8357 | + texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex); |
---|
| 8358 | + else |
---|
| 8359 | + texturecache = bimtextures.get(texdata); |
---|
| 8360 | + } |
---|
| 8361 | + |
---|
| 8362 | + if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution) |
---|
| 8363 | + { |
---|
| 8364 | + TextureData texturedata = null; |
---|
| 8365 | + |
---|
| 8366 | + if (texdata != null && textureon) |
---|
| 8367 | + { |
---|
| 8368 | + BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB); |
---|
| 8369 | + |
---|
| 8370 | + try |
---|
| 8371 | + { |
---|
| 8372 | + bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph); |
---|
| 8373 | + } |
---|
| 8374 | + catch (Exception e) |
---|
| 8375 | + { |
---|
| 8376 | + bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph); |
---|
| 8377 | + } |
---|
| 8378 | + |
---|
| 8379 | + texturecache = new CacheTexture(GetBimTexture(bim, bump), -1); |
---|
| 8380 | + bimtextures.put(texdata, texturecache); |
---|
| 8381 | + |
---|
| 8382 | + //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB); |
---|
| 8383 | + |
---|
| 8384 | + //Object bim2 = CreateBim(texturecache.texturedata); |
---|
| 8385 | + //bim2 = bim; |
---|
| 8386 | + } |
---|
| 8387 | + else |
---|
| 8388 | + if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals("")) |
---|
8267 | 8389 | { |
---|
8268 | 8390 | assert(!bump); |
---|
8269 | 8391 | // if (bump) |
---|
.. | .. |
---|
8274 | 8396 | // } |
---|
8275 | 8397 | // else |
---|
8276 | 8398 | // { |
---|
8277 | | - texture = textures.get(tex); |
---|
8278 | | - if (texture == null) |
---|
| 8399 | + // texturecache = textures.get(texname); // suspicious |
---|
| 8400 | + if (texturecache == null) |
---|
8279 | 8401 | { |
---|
8280 | | - texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
| 8402 | + texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
8281 | 8403 | } |
---|
| 8404 | + else |
---|
| 8405 | + new Exception().printStackTrace(); |
---|
8282 | 8406 | // } |
---|
8283 | 8407 | } else |
---|
8284 | | - if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals("")) |
---|
| 8408 | + if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals("")) |
---|
8285 | 8409 | { |
---|
8286 | 8410 | assert(bump); |
---|
8287 | | - texture = textures.get(tex); |
---|
8288 | | - if (texture == null) |
---|
8289 | | - texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
| 8411 | + // texturecache = textures.get(texname); // suspicious |
---|
| 8412 | + if (texturecache == null) |
---|
| 8413 | + texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
| 8414 | + else |
---|
| 8415 | + new Exception().printStackTrace(); |
---|
8290 | 8416 | } else |
---|
8291 | 8417 | { |
---|
8292 | 8418 | //if (tex.equals("IMMORTAL")) |
---|
.. | .. |
---|
8294 | 8420 | // texture = GetResourceTexture("default.png"); |
---|
8295 | 8421 | //} else |
---|
8296 | 8422 | //{ |
---|
8297 | | - if (tex.equals("WHITE_NOISE")) |
---|
| 8423 | + if (texname.endsWith("WHITE_NOISE")) |
---|
8298 | 8424 | { |
---|
8299 | | - texture = textures.get(tex); |
---|
8300 | | - if (texture == null) |
---|
8301 | | - texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution); |
---|
| 8425 | + // texturecache = textures.get(texname); // suspicious |
---|
| 8426 | + if (texturecache == null) |
---|
| 8427 | + texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution); |
---|
| 8428 | + else |
---|
| 8429 | + new Exception().printStackTrace(); |
---|
8302 | 8430 | } else |
---|
8303 | 8431 | { |
---|
8304 | 8432 | if (textureon) |
---|
.. | .. |
---|
8357 | 8485 | if (texturedata == null) |
---|
8358 | 8486 | throw new Exception(); |
---|
8359 | 8487 | |
---|
8360 | | - texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution); |
---|
| 8488 | + texturecache = new CacheTexture(texturedata,resolution); |
---|
8361 | 8489 | //texture = GetTexture(tex, bump); |
---|
8362 | 8490 | } |
---|
8363 | 8491 | } |
---|
8364 | 8492 | //} |
---|
8365 | 8493 | } |
---|
8366 | 8494 | |
---|
8367 | | - if (/*CACHETEXTURE &&*/ texture != null && textureon) |
---|
| 8495 | + if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon) |
---|
8368 | 8496 | { |
---|
8369 | 8497 | //return false; |
---|
8370 | 8498 | |
---|
8371 | 8499 | // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")"); |
---|
8372 | | - if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG"))) |
---|
| 8500 | + if (texturedata != null && texname.toLowerCase().endsWith(".jpg")) |
---|
8373 | 8501 | { |
---|
8374 | 8502 | // String ext = "_highres"; |
---|
8375 | 8503 | // if (REDUCETEXTURE) |
---|
.. | .. |
---|
8386 | 8514 | File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg"); |
---|
8387 | 8515 | if (!cachefile.exists()) |
---|
8388 | 8516 | { |
---|
8389 | | - // cache to disk |
---|
8390 | | - Buffer buffer = texturedata.getBuffer(); // getMipmapData(); |
---|
8391 | | - //buffers[0]. |
---|
8392 | | - |
---|
8393 | | - ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer(); |
---|
8394 | | - int[] pixels = new int[bytebuf.capacity()/3]; |
---|
8395 | | - |
---|
8396 | | - // squared size heuristic... |
---|
8397 | | - if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length)) |
---|
| 8517 | + //if (texturedata.getWidth() == texturedata.getHeight()) |
---|
8398 | 8518 | { |
---|
8399 | | - for (int i=pixels.length; --i>=0;) |
---|
8400 | | - { |
---|
8401 | | - int i3 = i*3; |
---|
8402 | | - pixels[i] = 0xFF; |
---|
8403 | | - pixels[i] <<= 8; |
---|
8404 | | - pixels[i] |= bytebuf.get(i3+2) & 0xFF; |
---|
8405 | | - pixels[i] <<= 8; |
---|
8406 | | - pixels[i] |= bytebuf.get(i3+1) & 0xFF; |
---|
8407 | | - pixels[i] <<= 8; |
---|
8408 | | - pixels[i] |= bytebuf.get(i3) & 0xFF; |
---|
8409 | | - } |
---|
8410 | | - |
---|
8411 | | - /* |
---|
8412 | | - int r=0,g=0,b=0,a=0; |
---|
8413 | | - for (int i=0; i<width; i++) |
---|
8414 | | - for (int j=0; j<height; j++) |
---|
8415 | | - { |
---|
8416 | | - int index = j*width+i; |
---|
8417 | | - int p = pixels[index]; |
---|
8418 | | - a = ((p>>24) & 0xFF); |
---|
8419 | | - r = ((p>>16) & 0xFF); |
---|
8420 | | - g = ((p>>8) & 0xFF); |
---|
8421 | | - b = (p & 0xFF); |
---|
8422 | | - pixels[index] = (a<<24) | (b<<16) | (g<<8) | r; |
---|
8423 | | - } |
---|
8424 | | - /**/ |
---|
8425 | | - int width = (int)Math.sqrt(pixels.length); // squared |
---|
8426 | | - int height = width; |
---|
8427 | | - BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile); |
---|
8428 | | - rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width); |
---|
| 8519 | + BufferedImage rendImage = CreateBim(texturedata); |
---|
| 8520 | + |
---|
8429 | 8521 | ImageWriter writer = null; |
---|
8430 | 8522 | Iterator iter = ImageIO.getImageWritersByFormatName("jpg"); |
---|
8431 | 8523 | if (iter.hasNext()) { |
---|
8432 | 8524 | writer = (ImageWriter)iter.next(); |
---|
8433 | 8525 | } |
---|
8434 | | - float compressionQuality = 0.9f; |
---|
| 8526 | + |
---|
| 8527 | + float compressionQuality = 0.85f; |
---|
8435 | 8528 | try |
---|
8436 | 8529 | { |
---|
8437 | 8530 | ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile); |
---|
.. | .. |
---|
8448 | 8541 | } |
---|
8449 | 8542 | } |
---|
8450 | 8543 | } |
---|
8451 | | - |
---|
| 8544 | + |
---|
| 8545 | + Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment; |
---|
| 8546 | + |
---|
8452 | 8547 | //System.out.println("Texture = " + tex); |
---|
8453 | | - if (textures.containsKey(texname)) |
---|
| 8548 | + if (textures.containsKey(tex)) |
---|
8454 | 8549 | { |
---|
8455 | | - CacheTexture thetex = textures.get(texname); |
---|
| 8550 | + CacheTexture thetex = textures.get(tex); |
---|
8456 | 8551 | thetex.texture.disable(); |
---|
8457 | 8552 | thetex.texture.dispose(); |
---|
8458 | | - textures.remove(texname); |
---|
| 8553 | + textures.remove(tex); |
---|
8459 | 8554 | } |
---|
8460 | 8555 | |
---|
8461 | | - texture.texturedata = texturedata; |
---|
8462 | | - textures.put(texname, texture); |
---|
| 8556 | + //texture.texturedata = texturedata; |
---|
| 8557 | + textures.put(tex, texturecache); |
---|
8463 | 8558 | |
---|
8464 | 8559 | // newtex = true; |
---|
8465 | 8560 | } |
---|
.. | .. |
---|
8475 | 8570 | } |
---|
8476 | 8571 | } |
---|
8477 | 8572 | |
---|
8478 | | - return texture; |
---|
| 8573 | + return texturecache; |
---|
8479 | 8574 | } |
---|
8480 | 8575 | |
---|
8481 | | - com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution) throws Exception |
---|
| 8576 | + static void EmbedTextures(cTexture tex) |
---|
| 8577 | + { |
---|
| 8578 | + if (tex.pigmentdata == null) |
---|
| 8579 | + { |
---|
| 8580 | + //String texname = Object3D.GetPigment(tex); |
---|
| 8581 | + |
---|
| 8582 | + CacheTexture texturecache = texturepigment.get(tex); |
---|
| 8583 | + |
---|
| 8584 | + if (texturecache != null) |
---|
| 8585 | + { |
---|
| 8586 | + tex.pw = texturecache.texturedata.getWidth(); |
---|
| 8587 | + tex.ph = texturecache.texturedata.getHeight(); |
---|
| 8588 | + tex.pigmentdata = //CompressJPEG(CreateBim |
---|
| 8589 | + ((ByteBuffer)texturecache.texturedata.getBuffer()).array() |
---|
| 8590 | + ; |
---|
| 8591 | + //, tex.pw, tex.ph), 0.5f); |
---|
| 8592 | + } |
---|
| 8593 | + } |
---|
| 8594 | + |
---|
| 8595 | + if (tex.bumpdata == null) |
---|
| 8596 | + { |
---|
| 8597 | + //String texname = Object3D.GetBump(tex); |
---|
| 8598 | + |
---|
| 8599 | + CacheTexture texturecache = texturebump.get(tex); |
---|
| 8600 | + |
---|
| 8601 | + if (texturecache != null) |
---|
| 8602 | + { |
---|
| 8603 | + tex.bw = texturecache.texturedata.getWidth(); |
---|
| 8604 | + tex.bh = texturecache.texturedata.getHeight(); |
---|
| 8605 | + tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f); |
---|
| 8606 | + } |
---|
| 8607 | + } |
---|
| 8608 | + } |
---|
| 8609 | + |
---|
| 8610 | + com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8482 | 8611 | { |
---|
8483 | 8612 | CacheTexture texture = GetCacheTexture(tex, bump, resolution); |
---|
8484 | 8613 | |
---|
.. | .. |
---|
8496 | 8625 | return texture!=null?texture.texture:null; |
---|
8497 | 8626 | } |
---|
8498 | 8627 | |
---|
8499 | | - public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution) throws Exception |
---|
| 8628 | + public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8500 | 8629 | { |
---|
8501 | 8630 | CacheTexture texture = GetCacheTexture(tex, bump, resolution); |
---|
8502 | 8631 | |
---|
8503 | 8632 | return texture!=null?texture.texturedata:null; |
---|
8504 | 8633 | } |
---|
8505 | 8634 | |
---|
8506 | | - boolean BindTexture(String tex, boolean bump, int resolution) throws Exception |
---|
| 8635 | + boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8507 | 8636 | { |
---|
8508 | 8637 | if (/*tex == null ||*/ ambientOcclusion ) // || !textureon) |
---|
8509 | 8638 | { |
---|
8510 | 8639 | return false; |
---|
8511 | 8640 | } |
---|
8512 | 8641 | |
---|
8513 | | - boolean newtex = false; |
---|
| 8642 | + //boolean newtex = false; |
---|
8514 | 8643 | |
---|
8515 | 8644 | com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution); |
---|
8516 | 8645 | |
---|
.. | .. |
---|
8542 | 8671 | texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT); |
---|
8543 | 8672 | texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT); |
---|
8544 | 8673 | |
---|
8545 | | - return newtex; |
---|
| 8674 | + return true; // Warning: not used. |
---|
8546 | 8675 | } |
---|
8547 | 8676 | |
---|
| 8677 | + public static byte[] CompressJPEG(BufferedImage image, float quality) |
---|
| 8678 | + { |
---|
| 8679 | + try |
---|
| 8680 | + { |
---|
| 8681 | + ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
---|
| 8682 | + Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg"); |
---|
| 8683 | + ImageWriter writer = writers.next(); |
---|
| 8684 | + |
---|
| 8685 | + ImageWriteParam param = writer.getDefaultWriteParam(); |
---|
| 8686 | + param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); |
---|
| 8687 | + param.setCompressionQuality(quality); |
---|
| 8688 | + |
---|
| 8689 | + ImageOutputStream ios = ImageIO.createImageOutputStream(baos); |
---|
| 8690 | + writer.setOutput(ios); |
---|
| 8691 | + writer.write(null, new IIOImage(image, null, null), param); |
---|
| 8692 | + |
---|
| 8693 | + byte[] data = baos.toByteArray(); |
---|
| 8694 | + writer.dispose(); |
---|
| 8695 | + return data; |
---|
| 8696 | + } |
---|
| 8697 | + catch (Exception e) |
---|
| 8698 | + { |
---|
| 8699 | + e.printStackTrace(); |
---|
| 8700 | + return null; |
---|
| 8701 | + } |
---|
| 8702 | + } |
---|
| 8703 | + |
---|
| 8704 | + public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException |
---|
| 8705 | + { |
---|
| 8706 | + ByteArrayInputStream baos = new ByteArrayInputStream(image); |
---|
| 8707 | + Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg"); |
---|
| 8708 | + ImageReader reader = writers.next(); |
---|
| 8709 | + |
---|
| 8710 | + BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); |
---|
| 8711 | + |
---|
| 8712 | + ImageReadParam param = reader.getDefaultReadParam(); |
---|
| 8713 | + param.setDestination(bim); |
---|
| 8714 | + //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB)); |
---|
| 8715 | + |
---|
| 8716 | + ImageInputStream ios = ImageIO.createImageInputStream(baos); |
---|
| 8717 | + reader.setInput(ios); |
---|
| 8718 | + BufferedImage bim2 = reader.read(0, param); |
---|
| 8719 | + reader.dispose(); |
---|
| 8720 | + |
---|
| 8721 | +// WritableRaster raster = bim2.getRaster(); |
---|
| 8722 | +// DataBufferByte data = (DataBufferByte) raster.getDataBuffer(); |
---|
| 8723 | +// byte[] bytes = data.getData(); |
---|
| 8724 | +// |
---|
| 8725 | +// int[] pixels = new int[bytes.length/3]; |
---|
| 8726 | +// for (int i=pixels.length; --i>=0;) |
---|
| 8727 | +// { |
---|
| 8728 | +// int i3 = i*3; |
---|
| 8729 | +// pixels[i] = 0xFF; |
---|
| 8730 | +// pixels[i] <<= 8; |
---|
| 8731 | +// pixels[i] |= bytes[i3+2] & 0xFF; |
---|
| 8732 | +// pixels[i] <<= 8; |
---|
| 8733 | +// pixels[i] |= bytes[i3+1] & 0xFF; |
---|
| 8734 | +// pixels[i] <<= 8; |
---|
| 8735 | +// pixels[i] |= bytes[i3] & 0xFF; |
---|
| 8736 | +// } |
---|
| 8737 | +// |
---|
| 8738 | +// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w); |
---|
| 8739 | + |
---|
| 8740 | + return bim; |
---|
| 8741 | + } |
---|
| 8742 | + |
---|
8548 | 8743 | ShadowBuffer shadowPBuf; |
---|
8549 | 8744 | AntialiasBuffer antialiasPBuf; |
---|
8550 | 8745 | int MAXSTACK; |
---|
.. | .. |
---|
9505 | 9700 | |
---|
9506 | 9701 | if (renderCamera != lightCamera) |
---|
9507 | 9702 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
9508 | | - LA.matConcat(matrix, parentcam.GlobalTransform(), matrix); |
---|
| 9703 | + LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix); |
---|
9509 | 9704 | |
---|
9510 | 9705 | // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix); |
---|
9511 | 9706 | |
---|
.. | .. |
---|
9521 | 9716 | |
---|
9522 | 9717 | if (renderCamera != lightCamera) |
---|
9523 | 9718 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
9524 | | - LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix); |
---|
| 9719 | + LA.matConcat(parentcam.GlobalTransform(), matrix, matrix); |
---|
9525 | 9720 | |
---|
9526 | 9721 | // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix); |
---|
9527 | 9722 | |
---|
.. | .. |
---|
10722 | 10917 | // if (parentcam != renderCamera) // not a light |
---|
10723 | 10918 | if (cam != lightCamera) |
---|
10724 | 10919 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
10725 | | - LA.matConcat(matrix, parentcam.GlobalTransform(), matrix); |
---|
| 10920 | + LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix); |
---|
10726 | 10921 | |
---|
10727 | 10922 | for (int j = 0; j < 4; j++) |
---|
10728 | 10923 | { |
---|
.. | .. |
---|
10737 | 10932 | // if (parentcam != renderCamera) // not a light |
---|
10738 | 10933 | if (cam != lightCamera) |
---|
10739 | 10934 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
10740 | | - LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix); |
---|
| 10935 | + LA.matConcat(parentcam.GlobalTransform(), matrix, matrix); |
---|
10741 | 10936 | |
---|
10742 | 10937 | //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix); |
---|
10743 | 10938 | |
---|
.. | .. |
---|
11290 | 11485 | } |
---|
11291 | 11486 | } |
---|
11292 | 11487 | |
---|
11293 | | - if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion) |
---|
| 11488 | + if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion) |
---|
11294 | 11489 | { |
---|
11295 | 11490 | //gl.glDepthFunc(GL.GL_LEQUAL); |
---|
11296 | 11491 | //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT); |
---|
.. | .. |
---|
11298 | 11493 | |
---|
11299 | 11494 | boolean texon = textureon; |
---|
11300 | 11495 | |
---|
11301 | | - if (RENDERPROGRAM > 0) |
---|
11302 | | - { |
---|
11303 | | - gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
11304 | | - textureon = false; |
---|
11305 | | - } |
---|
| 11496 | + gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
| 11497 | + textureon = false; |
---|
| 11498 | + |
---|
11306 | 11499 | //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB); |
---|
11307 | 11500 | //System.out.println("ALLO"); |
---|
11308 | 11501 | gl.glColorMask(false, false, false, false); |
---|
11309 | 11502 | DrawObject(gl); |
---|
11310 | | - if (RENDERPROGRAM > 0) |
---|
11311 | | - { |
---|
11312 | | - gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
11313 | | - textureon = texon; |
---|
11314 | | - } |
---|
| 11503 | + |
---|
| 11504 | + gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
| 11505 | + textureon = texon; |
---|
| 11506 | + |
---|
11315 | 11507 | gl.glColorMask(true, true, true, true); |
---|
11316 | 11508 | |
---|
11317 | 11509 | gl.glDepthFunc(GL.GL_EQUAL); |
---|
11318 | | - //gl.glDepthMask(false); |
---|
| 11510 | + gl.glDepthMask(false); |
---|
11319 | 11511 | } |
---|
11320 | 11512 | |
---|
11321 | 11513 | if (false) // DrawMode() == SHADOW) |
---|
.. | .. |
---|
11655 | 11847 | ReleaseTextures(DEFAULT_TEXTURES); |
---|
11656 | 11848 | |
---|
11657 | 11849 | if (CLEANCACHE) |
---|
11658 | | - for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();) |
---|
| 11850 | + for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();) |
---|
11659 | 11851 | { |
---|
11660 | | - String tex = e.nextElement(); |
---|
| 11852 | + cTexture tex = e.nextElement(); |
---|
11661 | 11853 | |
---|
11662 | 11854 | // System.out.println("Texture --------- " + tex); |
---|
11663 | 11855 | |
---|
11664 | | - if (tex.equals("WHITE_NOISE")) |
---|
| 11856 | + if (tex.equals("WHITE_NOISE:")) |
---|
11665 | 11857 | continue; |
---|
11666 | 11858 | |
---|
11667 | | - if (!usedtextures.containsKey(tex)) |
---|
| 11859 | + if (!usedtextures.contains(tex)) |
---|
11668 | 11860 | { |
---|
| 11861 | + CacheTexture gettex = texturepigment.get(tex); |
---|
11669 | 11862 | // System.out.println("DISPOSE +++++++++++++++ " + tex); |
---|
11670 | | - textures.get(tex).texture.dispose(); |
---|
11671 | | - textures.remove(tex); |
---|
| 11863 | + if (gettex != null) |
---|
| 11864 | + { |
---|
| 11865 | + gettex.texture.dispose(); |
---|
| 11866 | + texturepigment.remove(tex); |
---|
| 11867 | + } |
---|
| 11868 | + |
---|
| 11869 | + gettex = texturebump.get(tex); |
---|
| 11870 | + // System.out.println("DISPOSE +++++++++++++++ " + tex); |
---|
| 11871 | + if (gettex != null) |
---|
| 11872 | + { |
---|
| 11873 | + gettex.texture.dispose(); |
---|
| 11874 | + texturebump.remove(tex); |
---|
| 11875 | + } |
---|
11672 | 11876 | } |
---|
11673 | 11877 | } |
---|
11674 | 11878 | } |
---|
.. | .. |
---|
12197 | 12401 | //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0); |
---|
12198 | 12402 | |
---|
12199 | 12403 | String program = |
---|
| 12404 | + // Min shader |
---|
12200 | 12405 | "!!ARBfp1.0\n" + |
---|
| 12406 | + "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" + |
---|
| 12407 | + "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" + |
---|
| 12408 | + "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" + |
---|
| 12409 | + "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" + |
---|
| 12410 | + "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" + |
---|
| 12411 | + "PARAM light2cam0 = program.env[10];" + |
---|
| 12412 | + "PARAM light2cam1 = program.env[11];" + |
---|
| 12413 | + "PARAM light2cam2 = program.env[12];" + |
---|
| 12414 | + "TEMP temp;" + |
---|
| 12415 | + "TEMP light;" + |
---|
| 12416 | + "TEMP ndotl;" + |
---|
| 12417 | + "TEMP normal;" + |
---|
| 12418 | + "TEMP depth;" + |
---|
| 12419 | + "TEMP eye;" + |
---|
| 12420 | + "TEMP pos;" + |
---|
| 12421 | + |
---|
| 12422 | + "MAD normal, fragment.color, zero123.z, -zero123.y;" + |
---|
| 12423 | + Normalize("normal") + |
---|
| 12424 | + "MOV light, state.light[0].position;" + |
---|
| 12425 | + "DP3 ndotl.x, light, normal;" + |
---|
| 12426 | + |
---|
| 12427 | + // shadow |
---|
| 12428 | + "MOV pos, fragment.texcoord[1];" + |
---|
| 12429 | + "MOV temp, pos;" + |
---|
| 12430 | + ShadowTextureFetch("depth", "temp", "1") + |
---|
| 12431 | + //"TEX depth, fragment.texcoord[1], texture[1], 2D;" + |
---|
| 12432 | + "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" + |
---|
| 12433 | + |
---|
| 12434 | + // No shadow when out of frustum |
---|
| 12435 | + //"SGE temp.y, depth.z, zero123.y;" + |
---|
| 12436 | + //"LRP temp.x, temp.y, zero123.y, temp.x;" + |
---|
| 12437 | + |
---|
| 12438 | + "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow |
---|
| 12439 | + |
---|
| 12440 | + // Backlit |
---|
| 12441 | + "MOV pos.w, zero123.y;" + |
---|
| 12442 | + "DP4 eye.x, pos, light2cam0;" + |
---|
| 12443 | + "DP4 eye.y, pos, light2cam1;" + |
---|
| 12444 | + "DP4 eye.z, pos, light2cam2;" + |
---|
| 12445 | + Normalize("eye") + |
---|
| 12446 | + |
---|
| 12447 | + "DP3 ndotl.y, -eye, normal;" + |
---|
| 12448 | + //"MUL ndotl.y, ndotl.y, pow2.x;" + |
---|
| 12449 | + "POW ndotl.y, ndotl.y, pow2.z;" + // backlit |
---|
| 12450 | + "SUB ndotl.y, zero123.y, ndotl.y;" + |
---|
| 12451 | + //"SUB ndotl.y, zero123.y, ndotl.y;" + |
---|
| 12452 | + //"MUL ndotl.y, ndotl.y, pow2.z;" + |
---|
| 12453 | + |
---|
| 12454 | + "MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient |
---|
| 12455 | + |
---|
| 12456 | + // Pigment |
---|
| 12457 | + "TEX temp, fragment.texcoord[0], texture[0], 2D;" + |
---|
| 12458 | + "LRP temp, zero123.w, temp, one;" + // texture proportion |
---|
| 12459 | + "MUL temp, temp, ndotl.x;" + |
---|
| 12460 | + |
---|
| 12461 | + "MUL temp, temp, zero123.z;" + |
---|
| 12462 | + |
---|
| 12463 | + //"MUL temp, temp, ndotl.y;" + |
---|
| 12464 | + |
---|
| 12465 | + "MOV temp.w, zero123.y;" + // reset alpha |
---|
| 12466 | + "MOV result.color, temp;" + |
---|
| 12467 | + "END"; |
---|
| 12468 | + |
---|
| 12469 | + String program2 = |
---|
| 12470 | + "!!ARBfp1.0\n" + |
---|
| 12471 | + |
---|
12201 | 12472 | //"OPTION ARB_fragment_program_shadow;" + |
---|
12202 | 12473 | "PARAM light2cam0 = program.env[10];" + |
---|
12203 | 12474 | "PARAM light2cam1 = program.env[11];" + |
---|
.. | .. |
---|
12312 | 12583 | "TEMP shininess;" + |
---|
12313 | 12584 | "\n" + |
---|
12314 | 12585 | "MOV texSamp, one;" + |
---|
12315 | | - //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" + |
---|
12316 | | - |
---|
| 12586 | + |
---|
12317 | 12587 | "MOV mapgrid.x, one2048th.x;" + |
---|
12318 | 12588 | "MOV temp, fragment.texcoord[1];" + |
---|
12319 | 12589 | /* |
---|
.. | .. |
---|
12334 | 12604 | "MUL temp, floor, mapgrid.x;" + |
---|
12335 | 12605 | //"TEX depth0, temp, texture[1], 2D;" + |
---|
12336 | 12606 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12337 | | - TextureFetch("depth0", "temp", "1") + |
---|
| 12607 | + ShadowTextureFetch("depth0", "temp", "1") + |
---|
12338 | 12608 | "") + |
---|
12339 | 12609 | "ADD temp.x, temp.x, mapgrid.x;" + |
---|
12340 | 12610 | //"TEX depth1, temp, texture[1], 2D;" + |
---|
12341 | 12611 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12342 | | - TextureFetch("depth1", "temp", "1") + |
---|
| 12612 | + ShadowTextureFetch("depth1", "temp", "1") + |
---|
12343 | 12613 | "") + |
---|
12344 | 12614 | "ADD temp.y, temp.y, mapgrid.x;" + |
---|
12345 | 12615 | //"TEX depth2, temp, texture[1], 2D;" + |
---|
12346 | | - TextureFetch("depth2", "temp", "1") + |
---|
| 12616 | + ShadowTextureFetch("depth2", "temp", "1") + |
---|
12347 | 12617 | "SUB temp.x, temp.x, mapgrid.x;" + |
---|
12348 | 12618 | //"TEX depth3, temp, texture[1], 2D;" + |
---|
12349 | 12619 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12350 | | - TextureFetch("depth3", "temp", "1") + |
---|
| 12620 | + ShadowTextureFetch("depth3", "temp", "1") + |
---|
12351 | 12621 | "") + |
---|
12352 | 12622 | //"MUL texSamp0, texSamp0, state.material.front.diffuse;" + |
---|
12353 | 12623 | //"MOV params, material;" + |
---|
.. | .. |
---|
12718 | 12988 | "MAD shadow.x, buffer.x, frac.y, shadow.x;" + |
---|
12719 | 12989 | "") + |
---|
12720 | 12990 | |
---|
12721 | | - // display shadow only (bump == 0) |
---|
| 12991 | + // display shadow only (fakedepth == 0) |
---|
12722 | 12992 | "SUB temp.x, half.x, shadow.x;" + |
---|
12723 | 12993 | "MOV temp.y, -params5.z;" + // params6.x;" + |
---|
12724 | 12994 | "SLT temp.z, temp.y, -one2048th.x;" + |
---|
.. | .. |
---|
13145 | 13415 | return out; |
---|
13146 | 13416 | } |
---|
13147 | 13417 | |
---|
13148 | | - String TextureFetch(String dest, String src, String unit) |
---|
| 13418 | + // Also does frustum culling |
---|
| 13419 | + String ShadowTextureFetch(String dest, String src, String unit) |
---|
13149 | 13420 | { |
---|
13150 | 13421 | return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" + |
---|
13151 | 13422 | "SGE " + src + ".w, " + src + ".x, eps.x;" + |
---|
13152 | 13423 | "SGE " + src + ".z, " + src + ".y, eps.x;" + |
---|
| 13424 | + "SLT " + dest + ".x, " + src + ".x, one.x;" + |
---|
| 13425 | + "SLT " + dest + ".y, " + src + ".y, one.x;" + |
---|
13153 | 13426 | "MUL " + src + ".w, " + src + ".z, " + src + ".w;" + |
---|
13154 | | - "SLT " + src + ".z, " + src + ".x, one.x;" + |
---|
13155 | | - "MUL " + src + ".w, " + src + ".z, " + src + ".w;" + |
---|
13156 | | - "SLT " + src + ".z, " + src + ".y, one.x;" + |
---|
13157 | | - "MUL " + src + ".w, " + src + ".z, " + src + ".w;" + |
---|
| 13427 | + "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" + |
---|
| 13428 | + "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" + |
---|
13158 | 13429 | //"SWZ buffer, temp, w,w,w,w;"; |
---|
13159 | | - "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" + |
---|
| 13430 | + //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" + |
---|
13160 | 13431 | "SUB " + src + ".z, " + "one.x, " + src + ".w;" + |
---|
13161 | 13432 | //"MUL " + src + ".z, " + src + ".z, infinity.x;" + |
---|
13162 | 13433 | //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;"; |
---|
13163 | | - "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
| 13434 | + //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
13164 | 13435 | |
---|
13165 | | - //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;"; |
---|
13166 | | - //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;"; |
---|
| 13436 | + //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;"; |
---|
| 13437 | + "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
13167 | 13438 | } |
---|
13168 | 13439 | |
---|
13169 | 13440 | String Shadow(String depth, String shadow) |
---|
.. | .. |
---|
13210 | 13481 | "SLT temp.x, temp.x, zero.x;" + // shadoweps |
---|
13211 | 13482 | "LRP " + shadow + ", temp.x, one, " + shadow + ";" + |
---|
13212 | 13483 | |
---|
13213 | | - // No shadow when out of frustrum |
---|
| 13484 | + // No shadow when out of frustum |
---|
13214 | 13485 | "SGE temp.x, " + depth + ".z, one.z;" + |
---|
13215 | 13486 | "LRP " + shadow + ", temp.x, one, " + shadow + ";" + |
---|
13216 | 13487 | ""; |
---|
.. | .. |
---|
14008 | 14279 | drag = false; |
---|
14009 | 14280 | //System.out.println("Mouse DOWN"); |
---|
14010 | 14281 | editObj = false; |
---|
14011 | | - ClickInfo info = new ClickInfo(); |
---|
14012 | | - info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
14013 | | - info.pane = this; |
---|
14014 | | - info.camera = renderCamera; |
---|
14015 | | - info.x = x; |
---|
14016 | | - info.y = y; |
---|
14017 | | - info.modifiers = modifiersex; |
---|
14018 | | - editObj = object.doEditClick(info, 0); |
---|
| 14282 | + //ClickInfo info = new ClickInfo(); |
---|
| 14283 | + object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
| 14284 | + object.clickInfo.pane = this; |
---|
| 14285 | + object.clickInfo.camera = renderCamera; |
---|
| 14286 | + object.clickInfo.x = x; |
---|
| 14287 | + object.clickInfo.y = y; |
---|
| 14288 | + object.clickInfo.modifiers = modifiersex; |
---|
| 14289 | + editObj = object.doEditClick(//info, |
---|
| 14290 | + 0); |
---|
14019 | 14291 | if (!editObj) |
---|
14020 | 14292 | { |
---|
14021 | 14293 | hasMarquee = true; |
---|
.. | .. |
---|
14415 | 14687 | if (editObj) |
---|
14416 | 14688 | { |
---|
14417 | 14689 | drag = true; |
---|
14418 | | - ClickInfo info = new ClickInfo(); |
---|
14419 | | - info.bounds.setBounds(0, 0, |
---|
| 14690 | + //ClickInfo info = new ClickInfo(); |
---|
| 14691 | + object.clickInfo.bounds.setBounds(0, 0, |
---|
14420 | 14692 | (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
14421 | | - info.pane = this; |
---|
14422 | | - info.camera = renderCamera; |
---|
14423 | | - info.x = x; |
---|
14424 | | - info.y = y; |
---|
14425 | | - object.GetWindow().copy |
---|
14426 | | - .doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0); |
---|
| 14693 | + object.clickInfo.pane = this; |
---|
| 14694 | + object.clickInfo.camera = renderCamera; |
---|
| 14695 | + object.clickInfo.x = x; |
---|
| 14696 | + object.clickInfo.y = y; |
---|
| 14697 | + object //.GetWindow().copy |
---|
| 14698 | + .doEditDrag(//info, |
---|
| 14699 | + (modifiers & MouseEvent.BUTTON3_MASK) != 0); |
---|
14427 | 14700 | } else |
---|
14428 | 14701 | { |
---|
14429 | 14702 | if (x < startX) |
---|
.. | .. |
---|
14572 | 14845 | } |
---|
14573 | 14846 | } |
---|
14574 | 14847 | |
---|
| 14848 | +// ClickInfo clickInfo = new ClickInfo(); |
---|
| 14849 | + |
---|
14575 | 14850 | public void mouseMoved(MouseEvent e) |
---|
14576 | 14851 | { |
---|
14577 | 14852 | //System.out.println("mouseMoved: " + e); |
---|
14578 | 14853 | if (isRenderer) |
---|
14579 | 14854 | return; |
---|
14580 | 14855 | |
---|
14581 | | - ClickInfo ci = new ClickInfo(); |
---|
14582 | | - ci.x = e.getX(); |
---|
14583 | | - ci.y = e.getY(); |
---|
14584 | | - ci.modifiers = e.getModifiersEx(); |
---|
14585 | | - ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
14586 | | - ci.pane = this; |
---|
14587 | | - ci.camera = renderCamera; |
---|
| 14856 | + // Mouse cursor feedback |
---|
| 14857 | + object.clickInfo.x = e.getX(); |
---|
| 14858 | + object.clickInfo.y = e.getY(); |
---|
| 14859 | + object.clickInfo.modifiers = e.getModifiersEx(); |
---|
| 14860 | + object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
| 14861 | + object.clickInfo.pane = this; |
---|
| 14862 | + object.clickInfo.camera = renderCamera; |
---|
14588 | 14863 | if (!isRenderer) |
---|
14589 | 14864 | { |
---|
14590 | 14865 | //ObjEditor editWindow = object.editWindow; |
---|
14591 | 14866 | //Object3D copy = editWindow.copy; |
---|
14592 | | - if (object.doEditClick(ci, 0)) |
---|
| 14867 | + if (object.doEditClick(//clickInfo, |
---|
| 14868 | + 0)) |
---|
14593 | 14869 | { |
---|
14594 | 14870 | setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
---|
14595 | 14871 | } else |
---|
.. | .. |
---|
14861 | 15137 | // break; |
---|
14862 | 15138 | case 'T': |
---|
14863 | 15139 | CACHETEXTURE ^= true; |
---|
14864 | | - textures.clear(); |
---|
| 15140 | + texturepigment.clear(); |
---|
| 15141 | + texturebump.clear(); |
---|
14865 | 15142 | // repaint(); |
---|
14866 | 15143 | break; |
---|
14867 | 15144 | case 'Y': |
---|
.. | .. |
---|
15614 | 15891 | |
---|
15615 | 15892 | int width = getBounds().width; |
---|
15616 | 15893 | int height = getBounds().height; |
---|
15617 | | - ClickInfo info = new ClickInfo(); |
---|
15618 | | - info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom)); |
---|
15619 | 15894 | //Image img = CreateImage(width, height); |
---|
15620 | 15895 | //System.out.println("width = " + width + "; height = " + height + "\n"); |
---|
15621 | 15896 | |
---|
.. | .. |
---|
15692 | 15967 | } |
---|
15693 | 15968 | if (object != null && !hasMarquee) |
---|
15694 | 15969 | { |
---|
| 15970 | + if (object.clickInfo == null) |
---|
| 15971 | + object.clickInfo = new ClickInfo(); |
---|
| 15972 | + ClickInfo info = object.clickInfo; |
---|
| 15973 | + //ClickInfo info = new ClickInfo(); |
---|
| 15974 | + info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom)); |
---|
| 15975 | + |
---|
15695 | 15976 | if (isRenderer) |
---|
15696 | 15977 | { |
---|
15697 | | - info.flags++; |
---|
| 15978 | + object.clickInfo.flags++; |
---|
15698 | 15979 | double frameAspect = (double) width / (double) height; |
---|
15699 | 15980 | if (frameAspect > renderCamera.aspect) |
---|
15700 | 15981 | { |
---|
15701 | 15982 | int desired = (int) ((double) height * renderCamera.aspect); |
---|
15702 | | - info.bounds.width -= width - desired; |
---|
15703 | | - info.bounds.x += (width - desired) / 2; |
---|
| 15983 | + object.clickInfo.bounds.width -= width - desired; |
---|
| 15984 | + object.clickInfo.bounds.x += (width - desired) / 2; |
---|
15704 | 15985 | } else |
---|
15705 | 15986 | { |
---|
15706 | 15987 | int desired = (int) ((double) width / renderCamera.aspect); |
---|
15707 | | - info.bounds.height -= height - desired; |
---|
15708 | | - info.bounds.y += (height - desired) / 2; |
---|
| 15988 | + object.clickInfo.bounds.height -= height - desired; |
---|
| 15989 | + object.clickInfo.bounds.y += (height - desired) / 2; |
---|
15709 | 15990 | } |
---|
15710 | 15991 | } |
---|
15711 | 15992 | |
---|
15712 | | - info.g = gr; |
---|
15713 | | - info.camera = renderCamera; |
---|
| 15993 | + object.clickInfo.g = gr; |
---|
| 15994 | + object.clickInfo.camera = renderCamera; |
---|
15714 | 15995 | /* |
---|
15715 | 15996 | // Memory intensive (brep.verticescopy) |
---|
15716 | 15997 | if (!(object instanceof Composite)) |
---|
15717 | 15998 | object.draw(info, 0, false); // SLOW : |
---|
15718 | 15999 | */ |
---|
15719 | | - if (!isRenderer) |
---|
| 16000 | + if (!isRenderer) // && drag) |
---|
15720 | 16001 | { |
---|
15721 | 16002 | Grafreed.Assert(object != null); |
---|
15722 | 16003 | Grafreed.Assert(object.selection != null); |
---|
.. | .. |
---|
15724 | 16005 | { |
---|
15725 | 16006 | int hitSomething = object.selection.get(0).hitSomething; |
---|
15726 | 16007 | |
---|
15727 | | - info.DX = 0; |
---|
15728 | | - info.DY = 0; |
---|
15729 | | - info.W = 1; |
---|
| 16008 | + object.clickInfo.DX = 0; |
---|
| 16009 | + object.clickInfo.DY = 0; |
---|
| 16010 | + object.clickInfo.W = 1; |
---|
15730 | 16011 | if (hitSomething == Object3D.hitCenter) |
---|
15731 | 16012 | { |
---|
15732 | 16013 | info.DX = X; |
---|
.. | .. |
---|
15738 | 16019 | info.DY -= info.bounds.height/2; |
---|
15739 | 16020 | } |
---|
15740 | 16021 | |
---|
15741 | | - object.drawEditHandles(info, 0); |
---|
| 16022 | + object.drawEditHandles(//info, |
---|
| 16023 | + 0); |
---|
15742 | 16024 | |
---|
15743 | 16025 | if (drag && (X != 0 || Y != 0)) |
---|
15744 | 16026 | { |
---|
.. | .. |
---|
15751 | 16033 | gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
15752 | 16034 | break; |
---|
15753 | 16035 | case Object3D.hitScale: gr.setColor(Color.cyan); |
---|
15754 | | - gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
| 16036 | + gr.drawLine(X, Y, 0, 0); |
---|
15755 | 16037 | break; |
---|
15756 | 16038 | } |
---|
15757 | 16039 | |
---|
.. | .. |
---|
16553 | 16835 | } |
---|
16554 | 16836 | } |
---|
16555 | 16837 | |
---|
| 16838 | + private Object3D GetFolder() |
---|
| 16839 | + { |
---|
| 16840 | + Object3D folder = object.GetWindow().copy; |
---|
| 16841 | + if (object.GetWindow().copy.selection.Size() > 0) |
---|
| 16842 | + folder = object.GetWindow().copy.selection.elementAt(0); |
---|
| 16843 | + return folder; |
---|
| 16844 | + } |
---|
| 16845 | + |
---|
16556 | 16846 | class SelectBuffer implements GLEventListener |
---|
16557 | 16847 | { |
---|
16558 | 16848 | |
---|
.. | .. |
---|
16632 | 16922 | |
---|
16633 | 16923 | //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL); |
---|
16634 | 16924 | |
---|
| 16925 | + if (PAINTMODE) |
---|
| 16926 | + { |
---|
| 16927 | + if (object.GetWindow().copy.selection.Size() > 0) |
---|
| 16928 | + { |
---|
| 16929 | + Object3D paintobj = object.GetWindow().copy.selection.elementAt(0); |
---|
| 16930 | + |
---|
| 16931 | + // Make what you paint not selectable. |
---|
| 16932 | + paintobj.ResetSelectable(); |
---|
| 16933 | + } |
---|
| 16934 | + } |
---|
| 16935 | + |
---|
16635 | 16936 | //int tmp = selection_view; |
---|
16636 | 16937 | //selection_view = -1; |
---|
16637 | 16938 | int temp = DrawMode(); |
---|
.. | .. |
---|
16643 | 16944 | // temp = DEFAULT; // patch for selection debug |
---|
16644 | 16945 | Globals.drawMode = temp; // WARNING |
---|
16645 | 16946 | |
---|
| 16947 | + if (PAINTMODE) |
---|
| 16948 | + { |
---|
| 16949 | + if (object.GetWindow().copy.selection.Size() > 0) |
---|
| 16950 | + { |
---|
| 16951 | + Object3D paintobj = object.GetWindow().copy.selection.elementAt(0); |
---|
| 16952 | + |
---|
| 16953 | + // Revert. |
---|
| 16954 | + paintobj.RestoreSelectable(); |
---|
| 16955 | + } |
---|
| 16956 | + } |
---|
| 16957 | + |
---|
16646 | 16958 | //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view); |
---|
16647 | 16959 | |
---|
16648 | 16960 | // trying different ways of getting the depth info over |
---|
.. | .. |
---|
16748 | 17060 | if (!movingcamera && !PAINTMODE) |
---|
16749 | 17061 | object.GetWindow().ScreenFitPoint(); // fev 2014 |
---|
16750 | 17062 | |
---|
16751 | | - if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0) |
---|
| 17063 | + if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0) |
---|
16752 | 17064 | { |
---|
16753 | | - Object3D paintobj = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0); |
---|
16754 | | - |
---|
16755 | | - Object3D group = new Object3D("inst" + paintcount++); |
---|
16756 | | - |
---|
16757 | | - group.CreateMaterial(); // use a void leaf to select instances |
---|
16758 | | - |
---|
16759 | | - group.add(paintobj); // link |
---|
16760 | | - |
---|
16761 | | - object.GetWindow().SnapObject(group); |
---|
16762 | | - |
---|
16763 | | - Object3D folder = object.GetWindow().copy; |
---|
| 17065 | + //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0); |
---|
16764 | 17066 | |
---|
16765 | 17067 | if (object.GetWindow().copy.selection.Size() > 0) |
---|
16766 | | - folder = object.GetWindow().copy.selection.elementAt(0); |
---|
| 17068 | + { |
---|
| 17069 | + Object3D paintobj = object.GetWindow().copy.selection.elementAt(0); |
---|
16767 | 17070 | |
---|
16768 | | - folder.add(group); |
---|
16769 | | - |
---|
16770 | | - object.GetWindow().ResetModel(); |
---|
16771 | | - object.GetWindow().refreshContents(); |
---|
| 17071 | + Object3D inst = new Object3D("inst" + paintcount++); |
---|
| 17072 | + |
---|
| 17073 | + inst.CreateMaterial(); // use a void leaf to select instances |
---|
| 17074 | + |
---|
| 17075 | + inst.add(paintobj); // link |
---|
| 17076 | + |
---|
| 17077 | + object.GetWindow().SnapObject(inst); |
---|
| 17078 | + |
---|
| 17079 | + Object3D folder = paintFolder; // GetFolder(); |
---|
| 17080 | + |
---|
| 17081 | + folder.add(inst); |
---|
| 17082 | + |
---|
| 17083 | + object.GetWindow().ResetModel(); |
---|
| 17084 | + object.GetWindow().refreshContents(); |
---|
| 17085 | + } |
---|
16772 | 17086 | } |
---|
16773 | 17087 | else |
---|
16774 | 17088 | paintcount = 0; |
---|