.. | .. |
---|
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; |
---|
.. | .. |
---|
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 | { |
---|
.. | .. |
---|
2298 | 2348 | HANDLES ^= true; |
---|
2299 | 2349 | } |
---|
2300 | 2350 | |
---|
| 2351 | + Object3D paintFolder; |
---|
| 2352 | + |
---|
2301 | 2353 | void TogglePaint() |
---|
2302 | 2354 | { |
---|
2303 | 2355 | PAINTMODE ^= true; |
---|
2304 | 2356 | paintcount = 0; |
---|
| 2357 | + |
---|
| 2358 | + if (PAINTMODE) |
---|
| 2359 | + { |
---|
| 2360 | + paintFolder = GetFolder(); |
---|
| 2361 | + } |
---|
2305 | 2362 | } |
---|
2306 | 2363 | |
---|
2307 | 2364 | void SwapCamera(int a, int b) |
---|
.. | .. |
---|
2398 | 2455 | return currentGL; |
---|
2399 | 2456 | } |
---|
2400 | 2457 | |
---|
| 2458 | + static private BufferedImage CreateBim(TextureData texturedata) |
---|
| 2459 | + { |
---|
| 2460 | + Grafreed.Assert(texturedata != null); |
---|
| 2461 | + |
---|
| 2462 | + int width = texturedata.getWidth(); |
---|
| 2463 | + int height = texturedata.getHeight(); |
---|
| 2464 | + |
---|
| 2465 | + Buffer buffer = texturedata.getBuffer(); |
---|
| 2466 | + ByteBuffer bytebuf = (ByteBuffer)buffer; |
---|
| 2467 | + |
---|
| 2468 | + byte[] bytes = bytebuf.array(); |
---|
| 2469 | + |
---|
| 2470 | + return CreateBim(bytes, width, height); |
---|
| 2471 | + } |
---|
| 2472 | + |
---|
2401 | 2473 | /**/ |
---|
2402 | 2474 | class CacheTexture |
---|
2403 | 2475 | { |
---|
.. | .. |
---|
2406 | 2478 | |
---|
2407 | 2479 | int resolution; |
---|
2408 | 2480 | |
---|
2409 | | - CacheTexture(com.sun.opengl.util.texture.Texture tex, int res) |
---|
| 2481 | + CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res) |
---|
2410 | 2482 | { |
---|
2411 | | - texture = tex; |
---|
| 2483 | + texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata); |
---|
| 2484 | + texturedata = texdata; |
---|
2412 | 2485 | resolution = res; |
---|
2413 | 2486 | } |
---|
2414 | 2487 | } |
---|
2415 | 2488 | /**/ |
---|
2416 | 2489 | |
---|
2417 | 2490 | // 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>(); |
---|
| 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>(); |
---|
| 2495 | + |
---|
2421 | 2496 | int pigmentdepth = 0; |
---|
2422 | 2497 | public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536]; |
---|
2423 | 2498 | int bumpdepth = 0; |
---|
2424 | 2499 | public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536]; |
---|
2425 | 2500 | //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE"; |
---|
2426 | 2501 | public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP"); |
---|
2427 | | - public static String NOISE_TEXTURE = "WHITE_NOISE"; |
---|
| 2502 | + public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:"); |
---|
2428 | 2503 | // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL"); |
---|
2429 | 2504 | |
---|
2430 | | - com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump) |
---|
| 2505 | + com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump) |
---|
2431 | 2506 | { |
---|
2432 | 2507 | TextureData texturedata = null; |
---|
2433 | 2508 | |
---|
.. | .. |
---|
2446 | 2521 | if (bump) |
---|
2447 | 2522 | texturedata = ConvertBump(texturedata, false); |
---|
2448 | 2523 | |
---|
2449 | | - com.sun.opengl.util.texture.Texture texture = |
---|
2450 | | - 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); |
---|
2451 | 2526 | |
---|
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); |
---|
| 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); |
---|
2454 | 2529 | |
---|
2455 | | - return texture; |
---|
| 2530 | + return texturedata; |
---|
| 2531 | + } |
---|
| 2532 | + |
---|
| 2533 | + com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump) |
---|
| 2534 | + { |
---|
| 2535 | + TextureData texturedata = null; |
---|
| 2536 | + |
---|
| 2537 | + try |
---|
| 2538 | + { |
---|
| 2539 | + texturedata = |
---|
| 2540 | + com.sun.opengl.util.texture.TextureIO.newTextureData( |
---|
| 2541 | + bim, |
---|
| 2542 | + true); |
---|
| 2543 | + } catch (Exception e) |
---|
| 2544 | + { |
---|
| 2545 | + throw new javax.media.opengl.GLException(e); |
---|
| 2546 | + } |
---|
| 2547 | + |
---|
| 2548 | + if (bump) |
---|
| 2549 | + texturedata = ConvertBump(texturedata, false); |
---|
| 2550 | + |
---|
| 2551 | + return texturedata; |
---|
2456 | 2552 | } |
---|
2457 | 2553 | |
---|
2458 | 2554 | boolean HUESMOOTH = true; // wrap around bug... true; |
---|
.. | .. |
---|
3525 | 3621 | |
---|
3526 | 3622 | System.out.println("LOADING TEXTURE : " + name); |
---|
3527 | 3623 | |
---|
| 3624 | + Object x = texturedata.getMipmapData(); // .getBuffer(); |
---|
| 3625 | + |
---|
3528 | 3626 | // |
---|
3529 | 3627 | if (false) // compressbit > 0) |
---|
3530 | 3628 | { |
---|
.. | .. |
---|
7923 | 8021 | String pigment = Object3D.GetPigment(tex); |
---|
7924 | 8022 | String bump = Object3D.GetBump(tex); |
---|
7925 | 8023 | |
---|
7926 | | - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8024 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
7927 | 8025 | { |
---|
7928 | 8026 | // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment); |
---|
7929 | 8027 | // System.out.println("; bump = " + bump); |
---|
.. | .. |
---|
7938 | 8036 | pigment = null; |
---|
7939 | 8037 | } |
---|
7940 | 8038 | |
---|
7941 | | - ReleaseTexture(bump, true); |
---|
7942 | | - ReleaseTexture(pigment, false); |
---|
| 8039 | + ReleaseTexture(tex, true); |
---|
| 8040 | + ReleaseTexture(tex, false); |
---|
7943 | 8041 | } |
---|
7944 | 8042 | |
---|
7945 | 8043 | public void ReleasePigmentTexture(cTexture tex) // INTERFACE |
---|
.. | .. |
---|
7957 | 8055 | |
---|
7958 | 8056 | String pigment = Object3D.GetPigment(tex); |
---|
7959 | 8057 | |
---|
7960 | | - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8058 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
7961 | 8059 | { |
---|
7962 | 8060 | // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment); |
---|
7963 | 8061 | // System.out.println("; bump = " + bump); |
---|
.. | .. |
---|
7968 | 8066 | pigment = null; |
---|
7969 | 8067 | } |
---|
7970 | 8068 | |
---|
7971 | | - ReleaseTexture(pigment, false); |
---|
| 8069 | + ReleaseTexture(tex, false); |
---|
7972 | 8070 | } |
---|
7973 | 8071 | |
---|
7974 | 8072 | public void ReleaseBumpTexture(cTexture tex) // INTERFACE |
---|
.. | .. |
---|
7986 | 8084 | |
---|
7987 | 8085 | String bump = Object3D.GetBump(tex); |
---|
7988 | 8086 | |
---|
7989 | | - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8087 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
7990 | 8088 | { |
---|
7991 | 8089 | // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment); |
---|
7992 | 8090 | // System.out.println("; bump = " + bump); |
---|
.. | .. |
---|
7997 | 8095 | bump = null; |
---|
7998 | 8096 | } |
---|
7999 | 8097 | |
---|
8000 | | - ReleaseTexture(bump, true); |
---|
| 8098 | + ReleaseTexture(tex, true); |
---|
8001 | 8099 | } |
---|
8002 | 8100 | |
---|
8003 | | - void ReleaseTexture(String tex, boolean bump) |
---|
| 8101 | + void ReleaseTexture(cTexture tex, boolean bump) |
---|
8004 | 8102 | { |
---|
8005 | 8103 | if (// DrawMode() != 0 || /*tex == null ||*/ |
---|
8006 | 8104 | ambientOcclusion ) // || !textureon) |
---|
.. | .. |
---|
8011 | 8109 | CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null; |
---|
8012 | 8110 | |
---|
8013 | 8111 | if (tex != null) |
---|
8014 | | - texture = textures.get(tex); |
---|
| 8112 | + texture = bump ? texturebump.get(tex) : texturepigment.get(tex); |
---|
8015 | 8113 | |
---|
8016 | 8114 | // //assert( texture != null ); |
---|
8017 | 8115 | // if (texture == null) |
---|
.. | .. |
---|
8105 | 8203 | |
---|
8106 | 8204 | /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE |
---|
8107 | 8205 | { |
---|
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 | | - } |
---|
| 8206 | +// if (// DrawMode() != 0 || /*tex == null ||*/ |
---|
| 8207 | +// ambientOcclusion ) // || !textureon) |
---|
| 8208 | +// { |
---|
| 8209 | +// return; // false; |
---|
| 8210 | +// } |
---|
| 8211 | +// |
---|
| 8212 | +// if (tex == null) |
---|
| 8213 | +// { |
---|
| 8214 | +// BindTexture(null,false,resolution); |
---|
| 8215 | +// BindTexture(null,true,resolution); |
---|
| 8216 | +// return; |
---|
| 8217 | +// } |
---|
| 8218 | +// |
---|
| 8219 | +// String pigment = Object3D.GetPigment(tex); |
---|
| 8220 | +// String bump = Object3D.GetBump(tex); |
---|
| 8221 | +// |
---|
| 8222 | +// usedtextures.add(pigment); |
---|
| 8223 | +// usedtextures.add(bump); |
---|
| 8224 | +// |
---|
| 8225 | +// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8226 | +// { |
---|
| 8227 | +// // System.out.print("BIND +++++++++++++++ pigment = " + pigment); |
---|
| 8228 | +// // System.out.println("; bump = " + bump); |
---|
| 8229 | +// } |
---|
| 8230 | +// |
---|
| 8231 | +// if (bump.equals("")) |
---|
| 8232 | +// { |
---|
| 8233 | +// bump = null; |
---|
| 8234 | +// } |
---|
| 8235 | +// if (pigment.equals("")) |
---|
| 8236 | +// { |
---|
| 8237 | +// pigment = null; |
---|
| 8238 | +// } |
---|
| 8239 | +// |
---|
| 8240 | +// GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
| 8241 | +// BindTexture(pigment, false, resolution); |
---|
| 8242 | +// GetGL().glActiveTexture(GetGL().GL_TEXTURE2); |
---|
| 8243 | +// BindTexture(bump, true, resolution); |
---|
| 8244 | +// GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
| 8245 | +// |
---|
| 8246 | +// return; // true; |
---|
8120 | 8247 | |
---|
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; |
---|
| 8248 | + BindPigmentTexture(tex, resolution); |
---|
| 8249 | + BindBumpTexture(tex, resolution); |
---|
8149 | 8250 | } |
---|
8150 | 8251 | |
---|
8151 | 8252 | /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE |
---|
.. | .. |
---|
8164 | 8265 | |
---|
8165 | 8266 | String pigment = Object3D.GetPigment(tex); |
---|
8166 | 8267 | |
---|
8167 | | - usedtextures.put(pigment, pigment); |
---|
| 8268 | + usedtextures.add(tex); |
---|
8168 | 8269 | |
---|
8169 | | - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8270 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
8170 | 8271 | { |
---|
8171 | 8272 | // System.out.print("BIND +++++++++++++++ pigment = " + pigment); |
---|
8172 | 8273 | // System.out.println("; bump = " + bump); |
---|
.. | .. |
---|
8178 | 8279 | } |
---|
8179 | 8280 | |
---|
8180 | 8281 | GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
8181 | | - BindTexture(pigment, false, resolution); |
---|
| 8282 | + BindTexture(tex, false, resolution); |
---|
8182 | 8283 | } |
---|
8183 | 8284 | |
---|
8184 | 8285 | /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE |
---|
.. | .. |
---|
8197 | 8298 | |
---|
8198 | 8299 | String bump = Object3D.GetBump(tex); |
---|
8199 | 8300 | |
---|
8200 | | - usedtextures.put(bump, bump); |
---|
| 8301 | + usedtextures.add(tex); |
---|
8201 | 8302 | |
---|
8202 | | - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8303 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
8203 | 8304 | { |
---|
8204 | 8305 | // System.out.print("BIND +++++++++++++++ pigment = " + pigment); |
---|
8205 | 8306 | // System.out.println("; bump = " + bump); |
---|
.. | .. |
---|
8211 | 8312 | } |
---|
8212 | 8313 | |
---|
8213 | 8314 | GetGL().glActiveTexture(GetGL().GL_TEXTURE2); |
---|
8214 | | - BindTexture(bump, true, resolution); |
---|
| 8315 | + BindTexture(tex, true, resolution); |
---|
8215 | 8316 | GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
8216 | 8317 | } |
---|
8217 | 8318 | |
---|
.. | .. |
---|
8235 | 8336 | return fileExists; |
---|
8236 | 8337 | } |
---|
8237 | 8338 | |
---|
8238 | | - CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception |
---|
| 8339 | + CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8239 | 8340 | { |
---|
8240 | | - CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null; |
---|
| 8341 | + CacheTexture texturecache = null; |
---|
8241 | 8342 | |
---|
8242 | 8343 | if (tex != null) |
---|
8243 | 8344 | { |
---|
8244 | | - 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 | + } |
---|
8245 | 8352 | |
---|
8246 | 8353 | String fallbackTextureName = defaultDirectory + "/Textures/" + texname; |
---|
8247 | 8354 | |
---|
.. | .. |
---|
8251 | 8358 | // else |
---|
8252 | 8359 | // if (!texname.startsWith("/")) |
---|
8253 | 8360 | // texname = "/Users/nbriere/Textures/" + texname; |
---|
8254 | | - if (!FileExists(tex)) |
---|
| 8361 | + if (!FileExists(texname) && !texname.startsWith("@")) |
---|
8255 | 8362 | { |
---|
8256 | 8363 | texname = fallbackTextureName; |
---|
8257 | 8364 | } |
---|
8258 | 8365 | |
---|
8259 | 8366 | if (CACHETEXTURE) |
---|
8260 | | - texture = textures.get(texname); // TEXTURE CACHE |
---|
8261 | | - |
---|
8262 | | - TextureData texturedata = null; |
---|
8263 | | - |
---|
8264 | | - if (texture == null || texture.resolution < resolution) |
---|
8265 | 8367 | { |
---|
8266 | | - if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals("")) |
---|
| 8368 | + if (texdata == null) |
---|
| 8369 | + texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex); |
---|
| 8370 | + else |
---|
| 8371 | + texturecache = bimtextures.get(texdata); |
---|
| 8372 | + } |
---|
| 8373 | + |
---|
| 8374 | + if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution) |
---|
| 8375 | + { |
---|
| 8376 | + TextureData texturedata = null; |
---|
| 8377 | + |
---|
| 8378 | + if (texdata != null && textureon) |
---|
| 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 | + |
---|
| 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; |
---|
| 8398 | + } |
---|
| 8399 | + else |
---|
| 8400 | + if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals("")) |
---|
8267 | 8401 | { |
---|
8268 | 8402 | assert(!bump); |
---|
8269 | 8403 | // if (bump) |
---|
.. | .. |
---|
8274 | 8408 | // } |
---|
8275 | 8409 | // else |
---|
8276 | 8410 | // { |
---|
8277 | | - texture = textures.get(tex); |
---|
8278 | | - if (texture == null) |
---|
| 8411 | + // texturecache = textures.get(texname); // suspicious |
---|
| 8412 | + if (texturecache == null) |
---|
8279 | 8413 | { |
---|
8280 | | - texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
| 8414 | + texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
8281 | 8415 | } |
---|
| 8416 | + else |
---|
| 8417 | + new Exception().printStackTrace(); |
---|
8282 | 8418 | // } |
---|
8283 | 8419 | } else |
---|
8284 | | - if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals("")) |
---|
| 8420 | + if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals("")) |
---|
8285 | 8421 | { |
---|
8286 | 8422 | assert(bump); |
---|
8287 | | - texture = textures.get(tex); |
---|
8288 | | - if (texture == null) |
---|
8289 | | - texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
| 8423 | + // texturecache = textures.get(texname); // suspicious |
---|
| 8424 | + if (texturecache == null) |
---|
| 8425 | + texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
| 8426 | + else |
---|
| 8427 | + new Exception().printStackTrace(); |
---|
8290 | 8428 | } else |
---|
8291 | 8429 | { |
---|
8292 | 8430 | //if (tex.equals("IMMORTAL")) |
---|
.. | .. |
---|
8294 | 8432 | // texture = GetResourceTexture("default.png"); |
---|
8295 | 8433 | //} else |
---|
8296 | 8434 | //{ |
---|
8297 | | - if (tex.equals("WHITE_NOISE")) |
---|
| 8435 | + if (texname.endsWith("WHITE_NOISE")) |
---|
8298 | 8436 | { |
---|
8299 | | - texture = textures.get(tex); |
---|
8300 | | - if (texture == null) |
---|
8301 | | - texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution); |
---|
| 8437 | + // texturecache = textures.get(texname); // suspicious |
---|
| 8438 | + if (texturecache == null) |
---|
| 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); |
---|
| 8449 | + else |
---|
| 8450 | + new Exception().printStackTrace(); |
---|
8302 | 8451 | } else |
---|
8303 | 8452 | { |
---|
8304 | 8453 | if (textureon) |
---|
.. | .. |
---|
8357 | 8506 | if (texturedata == null) |
---|
8358 | 8507 | throw new Exception(); |
---|
8359 | 8508 | |
---|
8360 | | - texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution); |
---|
| 8509 | + texturecache = new CacheTexture(texturedata,resolution); |
---|
8361 | 8510 | //texture = GetTexture(tex, bump); |
---|
8362 | 8511 | } |
---|
| 8512 | + } |
---|
8363 | 8513 | } |
---|
8364 | 8514 | //} |
---|
8365 | 8515 | } |
---|
8366 | 8516 | |
---|
8367 | | - if (/*CACHETEXTURE &&*/ texture != null && textureon) |
---|
| 8517 | + if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon) |
---|
8368 | 8518 | { |
---|
8369 | 8519 | //return false; |
---|
8370 | 8520 | |
---|
8371 | 8521 | // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")"); |
---|
8372 | | - if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG"))) |
---|
| 8522 | + if (texturedata != null && texname.toLowerCase().endsWith(".jpg")) |
---|
8373 | 8523 | { |
---|
8374 | 8524 | // String ext = "_highres"; |
---|
8375 | 8525 | // if (REDUCETEXTURE) |
---|
.. | .. |
---|
8386 | 8536 | File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg"); |
---|
8387 | 8537 | if (!cachefile.exists()) |
---|
8388 | 8538 | { |
---|
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)) |
---|
| 8539 | + //if (texturedata.getWidth() == texturedata.getHeight()) |
---|
8398 | 8540 | { |
---|
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); |
---|
| 8541 | + BufferedImage rendImage = CreateBim(texturedata); |
---|
| 8542 | + |
---|
8429 | 8543 | ImageWriter writer = null; |
---|
8430 | 8544 | Iterator iter = ImageIO.getImageWritersByFormatName("jpg"); |
---|
8431 | 8545 | if (iter.hasNext()) { |
---|
8432 | 8546 | writer = (ImageWriter)iter.next(); |
---|
8433 | 8547 | } |
---|
8434 | | - float compressionQuality = 0.9f; |
---|
| 8548 | + |
---|
| 8549 | + float compressionQuality = 0.85f; |
---|
8435 | 8550 | try |
---|
8436 | 8551 | { |
---|
8437 | 8552 | ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile); |
---|
.. | .. |
---|
8448 | 8563 | } |
---|
8449 | 8564 | } |
---|
8450 | 8565 | } |
---|
8451 | | - |
---|
| 8566 | + |
---|
| 8567 | + Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment; |
---|
| 8568 | + |
---|
8452 | 8569 | //System.out.println("Texture = " + tex); |
---|
8453 | | - if (textures.containsKey(texname)) |
---|
| 8570 | + if (textures.containsKey(tex)) |
---|
8454 | 8571 | { |
---|
8455 | | - CacheTexture thetex = textures.get(texname); |
---|
| 8572 | + CacheTexture thetex = textures.get(tex); |
---|
8456 | 8573 | thetex.texture.disable(); |
---|
8457 | 8574 | thetex.texture.dispose(); |
---|
8458 | | - textures.remove(texname); |
---|
| 8575 | + textures.remove(tex); |
---|
8459 | 8576 | } |
---|
8460 | 8577 | |
---|
8461 | | - texture.texturedata = texturedata; |
---|
8462 | | - textures.put(texname, texture); |
---|
| 8578 | + //texture.texturedata = texturedata; |
---|
| 8579 | + textures.put(tex, texturecache); |
---|
8463 | 8580 | |
---|
8464 | 8581 | // newtex = true; |
---|
8465 | 8582 | } |
---|
.. | .. |
---|
8475 | 8592 | } |
---|
8476 | 8593 | } |
---|
8477 | 8594 | |
---|
8478 | | - return texture; |
---|
| 8595 | + return texturecache; |
---|
8479 | 8596 | } |
---|
8480 | 8597 | |
---|
8481 | | - com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution) throws Exception |
---|
| 8598 | + static void EmbedTextures(cTexture tex) |
---|
| 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 | + } |
---|
| 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 | + } |
---|
| 8630 | + } |
---|
| 8631 | + |
---|
| 8632 | + com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8482 | 8633 | { |
---|
8483 | 8634 | CacheTexture texture = GetCacheTexture(tex, bump, resolution); |
---|
8484 | 8635 | |
---|
.. | .. |
---|
8496 | 8647 | return texture!=null?texture.texture:null; |
---|
8497 | 8648 | } |
---|
8498 | 8649 | |
---|
8499 | | - public com.sun.opengl.util.texture.TextureData GetTextureData(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 |
---|
8500 | 8651 | { |
---|
8501 | 8652 | CacheTexture texture = GetCacheTexture(tex, bump, resolution); |
---|
8502 | 8653 | |
---|
8503 | 8654 | return texture!=null?texture.texturedata:null; |
---|
8504 | 8655 | } |
---|
8505 | 8656 | |
---|
8506 | | - boolean BindTexture(String tex, boolean bump, int resolution) throws Exception |
---|
| 8657 | + boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8507 | 8658 | { |
---|
8508 | 8659 | if (/*tex == null ||*/ ambientOcclusion ) // || !textureon) |
---|
8509 | 8660 | { |
---|
8510 | 8661 | return false; |
---|
8511 | 8662 | } |
---|
8512 | 8663 | |
---|
8513 | | - boolean newtex = false; |
---|
| 8664 | + //boolean newtex = false; |
---|
8514 | 8665 | |
---|
8515 | 8666 | com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution); |
---|
8516 | 8667 | |
---|
.. | .. |
---|
8542 | 8693 | texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT); |
---|
8543 | 8694 | texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT); |
---|
8544 | 8695 | |
---|
8545 | | - return newtex; |
---|
| 8696 | + return true; // Warning: not used. |
---|
8546 | 8697 | } |
---|
8547 | 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 | + |
---|
8548 | 8765 | ShadowBuffer shadowPBuf; |
---|
8549 | 8766 | AntialiasBuffer antialiasPBuf; |
---|
8550 | 8767 | int MAXSTACK; |
---|
.. | .. |
---|
8737 | 8954 | |
---|
8738 | 8955 | if (cubemap == null) |
---|
8739 | 8956 | { |
---|
8740 | | - LoadEnvy(5); |
---|
| 8957 | + //LoadEnvy(1); |
---|
8741 | 8958 | } |
---|
8742 | 8959 | |
---|
8743 | 8960 | //cubemap.enable(); |
---|
.. | .. |
---|
9024 | 9241 | cubemap = null; |
---|
9025 | 9242 | return; |
---|
9026 | 9243 | case 1: |
---|
9027 | | - name = "cubemaps/box_"; |
---|
9028 | | - ext = "png"; |
---|
| 9244 | + name = "cubemaps/rgb/"; |
---|
| 9245 | + ext = "jpg"; |
---|
9029 | 9246 | reverseUP = false; |
---|
9030 | 9247 | break; |
---|
9031 | 9248 | case 2: |
---|
9032 | | - name = "cubemaps/uffizi_"; |
---|
9033 | | - ext = "png"; |
---|
9034 | | - break; // reverseUP = true; break; |
---|
| 9249 | + name = "cubemaps/uffizi/"; |
---|
| 9250 | + ext = "jpg"; |
---|
| 9251 | + reverseUP = false; |
---|
| 9252 | + break; |
---|
9035 | 9253 | case 3: |
---|
9036 | | - name = "cubemaps/CloudyHills_"; |
---|
9037 | | - ext = "tga"; |
---|
| 9254 | + name = "cubemaps/CloudyHills/"; |
---|
| 9255 | + ext = "jpg"; |
---|
9038 | 9256 | reverseUP = false; |
---|
9039 | 9257 | break; |
---|
9040 | 9258 | case 4: |
---|
9041 | | - name = "cubemaps/cornell_"; |
---|
| 9259 | + name = "cubemaps/cornell/"; |
---|
9042 | 9260 | ext = "png"; |
---|
9043 | 9261 | reverseUP = false; |
---|
9044 | 9262 | break; |
---|
| 9263 | + case 5: |
---|
| 9264 | + name = "cubemaps/skycube/"; |
---|
| 9265 | + ext = "jpg"; |
---|
| 9266 | + reverseUP = false; |
---|
| 9267 | + break; |
---|
| 9268 | + case 6: |
---|
| 9269 | + name = "cubemaps/SaintLazarusChurch3/"; |
---|
| 9270 | + ext = "jpg"; |
---|
| 9271 | + reverseUP = false; |
---|
| 9272 | + break; |
---|
| 9273 | + case 7: |
---|
| 9274 | + name = "cubemaps/Sodermalmsallen/"; |
---|
| 9275 | + ext = "jpg"; |
---|
| 9276 | + reverseUP = false; |
---|
| 9277 | + break; |
---|
| 9278 | + case 8: |
---|
| 9279 | + name = "cubemaps/Sodermalmsallen2/"; |
---|
| 9280 | + ext = "jpg"; |
---|
| 9281 | + reverseUP = false; |
---|
| 9282 | + break; |
---|
| 9283 | + case 9: |
---|
| 9284 | + name = "cubemaps/UnionSquare/"; |
---|
| 9285 | + ext = "jpg"; |
---|
| 9286 | + reverseUP = false; |
---|
| 9287 | + break; |
---|
9045 | 9288 | default: |
---|
9046 | | - name = "cubemaps/rgb_"; |
---|
9047 | | - ext = "png"; /*mipmap = true;*/ reverseUP = false; |
---|
| 9289 | + name = "cubemaps/box/"; |
---|
| 9290 | + ext = "png"; /*mipmap = true;*/ |
---|
| 9291 | + reverseUP = false; |
---|
9048 | 9292 | break; |
---|
9049 | 9293 | } |
---|
9050 | | - |
---|
9051 | | - try |
---|
9052 | | - { |
---|
9053 | | - cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap); |
---|
9054 | | - } catch (IOException e) |
---|
9055 | | - { |
---|
9056 | | - throw new RuntimeException(e); |
---|
9057 | | - } |
---|
| 9294 | + |
---|
| 9295 | + LoadSkybox(name, ext, mipmap); |
---|
9058 | 9296 | } |
---|
9059 | 9297 | |
---|
9060 | 9298 | public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) |
---|
.. | .. |
---|
9086 | 9324 | static double[] model = new double[16]; |
---|
9087 | 9325 | double[] camera2light = new double[16]; |
---|
9088 | 9326 | double[] light2camera = new double[16]; |
---|
9089 | | - int newenvy = -1; |
---|
9090 | | - boolean envyoff = true; // false; |
---|
| 9327 | + |
---|
| 9328 | + //int newenvy = -1; |
---|
| 9329 | + //boolean envyoff = false; |
---|
| 9330 | + |
---|
| 9331 | + String loadedskyboxname; |
---|
| 9332 | + |
---|
9091 | 9333 | cVector light0 = new cVector(0, 0, 0); // 1,3,2); |
---|
9092 | 9334 | //float[] light0 = { 0,0,0 }; |
---|
9093 | 9335 | cVector dirlight = new cVector(0, 0, 1); // 1,3,2); |
---|
.. | .. |
---|
9505 | 9747 | |
---|
9506 | 9748 | if (renderCamera != lightCamera) |
---|
9507 | 9749 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
9508 | | - LA.matConcat(matrix, parentcam.GlobalTransform(), matrix); |
---|
| 9750 | + LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix); |
---|
9509 | 9751 | |
---|
9510 | 9752 | // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix); |
---|
9511 | 9753 | |
---|
.. | .. |
---|
9521 | 9763 | |
---|
9522 | 9764 | if (renderCamera != lightCamera) |
---|
9523 | 9765 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
9524 | | - LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix); |
---|
| 9766 | + LA.matConcat(parentcam.GlobalTransform(), matrix, matrix); |
---|
9525 | 9767 | |
---|
9526 | 9768 | // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix); |
---|
9527 | 9769 | |
---|
.. | .. |
---|
9567 | 9809 | rati = 1 / rati; |
---|
9568 | 9810 | gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000); |
---|
9569 | 9811 | } |
---|
9570 | | - assert (newenvy == -1); |
---|
| 9812 | + |
---|
| 9813 | + //assert (newenvy == -1); |
---|
| 9814 | + |
---|
9571 | 9815 | gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
9572 | 9816 | gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB); |
---|
9573 | | - DrawSkyBox(gl); |
---|
| 9817 | + DrawSkyBox(gl, (float)rati); |
---|
9574 | 9818 | gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
9575 | 9819 | gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB); |
---|
9576 | 9820 | accPerspective(gl, renderCamera.shaper_fovy / ratio, |
---|
.. | .. |
---|
10607 | 10851 | |
---|
10608 | 10852 | if (wait) |
---|
10609 | 10853 | { |
---|
10610 | | - Sleep(500); |
---|
| 10854 | + Sleep(200); // blocks everything |
---|
10611 | 10855 | |
---|
10612 | 10856 | wait = false; |
---|
10613 | 10857 | } |
---|
.. | .. |
---|
10722 | 10966 | // if (parentcam != renderCamera) // not a light |
---|
10723 | 10967 | if (cam != lightCamera) |
---|
10724 | 10968 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
10725 | | - LA.matConcat(matrix, parentcam.GlobalTransform(), matrix); |
---|
| 10969 | + LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix); |
---|
10726 | 10970 | |
---|
10727 | 10971 | for (int j = 0; j < 4; j++) |
---|
10728 | 10972 | { |
---|
.. | .. |
---|
10737 | 10981 | // if (parentcam != renderCamera) // not a light |
---|
10738 | 10982 | if (cam != lightCamera) |
---|
10739 | 10983 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
10740 | | - LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix); |
---|
| 10984 | + LA.matConcat(parentcam.GlobalTransform(), matrix, matrix); |
---|
10741 | 10985 | |
---|
10742 | 10986 | //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix); |
---|
10743 | 10987 | |
---|
.. | .. |
---|
10823 | 11067 | gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000); |
---|
10824 | 11068 | } |
---|
10825 | 11069 | |
---|
10826 | | - if (newenvy > -1) |
---|
| 11070 | +// if (newenvy > -1) |
---|
| 11071 | +// { |
---|
| 11072 | +// LoadEnvy(newenvy); |
---|
| 11073 | +// } |
---|
| 11074 | +// |
---|
| 11075 | +// newenvy = -1; |
---|
| 11076 | + |
---|
| 11077 | + if (object.skyboxname != null) |
---|
10827 | 11078 | { |
---|
10828 | | - LoadEnvy(newenvy); |
---|
| 11079 | + if (!object.skyboxname.equals(this.loadedskyboxname)) |
---|
| 11080 | + { |
---|
| 11081 | + LoadSkybox(object.skyboxname + "/", object.skyboxext, false); |
---|
| 11082 | + loadedskyboxname = object.skyboxname; |
---|
| 11083 | + } |
---|
10829 | 11084 | } |
---|
10830 | | - |
---|
10831 | | - newenvy = -1; |
---|
10832 | | - |
---|
| 11085 | + else |
---|
| 11086 | + { |
---|
| 11087 | + cubemap = null; |
---|
| 11088 | + loadedskyboxname = null; |
---|
| 11089 | + } |
---|
| 11090 | + |
---|
10833 | 11091 | ratio = ((double) getWidth()) / getHeight(); |
---|
10834 | 11092 | //System.out.println("ratio = " + ratio); |
---|
10835 | 11093 | |
---|
.. | .. |
---|
10845 | 11103 | |
---|
10846 | 11104 | if (!IsFrozen() && !ambientOcclusion) |
---|
10847 | 11105 | { |
---|
10848 | | - DrawSkyBox(gl); |
---|
| 11106 | + DrawSkyBox(gl, (float)ratio); |
---|
10849 | 11107 | } |
---|
10850 | 11108 | |
---|
10851 | 11109 | //if (selection_view == -1) |
---|
.. | .. |
---|
11131 | 11389 | |
---|
11132 | 11390 | // if (cam != lightCamera) |
---|
11133 | 11391 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
11134 | | - LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013 |
---|
| 11392 | + LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013 |
---|
11135 | 11393 | } |
---|
11136 | 11394 | |
---|
11137 | 11395 | LA.xformDir(lightposition, cam.toScreen, lightposition); |
---|
.. | .. |
---|
11290 | 11548 | } |
---|
11291 | 11549 | } |
---|
11292 | 11550 | |
---|
11293 | | - if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion) |
---|
| 11551 | + if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion) |
---|
11294 | 11552 | { |
---|
11295 | 11553 | //gl.glDepthFunc(GL.GL_LEQUAL); |
---|
11296 | 11554 | //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT); |
---|
.. | .. |
---|
11298 | 11556 | |
---|
11299 | 11557 | boolean texon = textureon; |
---|
11300 | 11558 | |
---|
11301 | | - if (RENDERPROGRAM > 0) |
---|
11302 | | - { |
---|
11303 | | - gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
11304 | | - textureon = false; |
---|
11305 | | - } |
---|
| 11559 | + gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
| 11560 | + textureon = false; |
---|
| 11561 | + |
---|
11306 | 11562 | //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB); |
---|
11307 | 11563 | //System.out.println("ALLO"); |
---|
11308 | 11564 | gl.glColorMask(false, false, false, false); |
---|
11309 | 11565 | DrawObject(gl); |
---|
11310 | | - if (RENDERPROGRAM > 0) |
---|
11311 | | - { |
---|
11312 | | - gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
11313 | | - textureon = texon; |
---|
11314 | | - } |
---|
| 11566 | + |
---|
| 11567 | + gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
| 11568 | + textureon = texon; |
---|
| 11569 | + |
---|
11315 | 11570 | gl.glColorMask(true, true, true, true); |
---|
11316 | 11571 | |
---|
11317 | 11572 | gl.glDepthFunc(GL.GL_EQUAL); |
---|
11318 | | - //gl.glDepthMask(false); |
---|
| 11573 | + gl.glDepthMask(false); |
---|
11319 | 11574 | } |
---|
11320 | 11575 | |
---|
11321 | 11576 | if (false) // DrawMode() == SHADOW) |
---|
.. | .. |
---|
11655 | 11910 | ReleaseTextures(DEFAULT_TEXTURES); |
---|
11656 | 11911 | |
---|
11657 | 11912 | if (CLEANCACHE) |
---|
11658 | | - for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();) |
---|
| 11913 | + for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();) |
---|
11659 | 11914 | { |
---|
11660 | | - String tex = e.nextElement(); |
---|
| 11915 | + cTexture tex = e.nextElement(); |
---|
11661 | 11916 | |
---|
11662 | 11917 | // System.out.println("Texture --------- " + tex); |
---|
11663 | 11918 | |
---|
11664 | | - if (tex.equals("WHITE_NOISE")) |
---|
| 11919 | + if (tex.equals("WHITE_NOISE:")) |
---|
11665 | 11920 | continue; |
---|
11666 | 11921 | |
---|
11667 | | - if (!usedtextures.containsKey(tex)) |
---|
| 11922 | + if (!usedtextures.contains(tex)) |
---|
11668 | 11923 | { |
---|
| 11924 | + CacheTexture gettex = texturepigment.get(tex); |
---|
11669 | 11925 | // System.out.println("DISPOSE +++++++++++++++ " + tex); |
---|
11670 | | - textures.get(tex).texture.dispose(); |
---|
11671 | | - textures.remove(tex); |
---|
| 11926 | + if (gettex != null) |
---|
| 11927 | + { |
---|
| 11928 | + gettex.texture.dispose(); |
---|
| 11929 | + texturepigment.remove(tex); |
---|
| 11930 | + } |
---|
| 11931 | + |
---|
| 11932 | + gettex = texturebump.get(tex); |
---|
| 11933 | + // System.out.println("DISPOSE +++++++++++++++ " + tex); |
---|
| 11934 | + if (gettex != null) |
---|
| 11935 | + { |
---|
| 11936 | + gettex.texture.dispose(); |
---|
| 11937 | + texturebump.remove(tex); |
---|
| 11938 | + } |
---|
11672 | 11939 | } |
---|
11673 | 11940 | } |
---|
11674 | 11941 | } |
---|
.. | .. |
---|
12196 | 12463 | |
---|
12197 | 12464 | //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0); |
---|
12198 | 12465 | |
---|
12199 | | - String program = |
---|
| 12466 | + String programmin = |
---|
| 12467 | + // Min shader |
---|
12200 | 12468 | "!!ARBfp1.0\n" + |
---|
| 12469 | + "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" + |
---|
| 12470 | + "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" + |
---|
| 12471 | + "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" + |
---|
| 12472 | + "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" + |
---|
| 12473 | + "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" + |
---|
| 12474 | + "PARAM light2cam0 = program.env[10];" + |
---|
| 12475 | + "PARAM light2cam1 = program.env[11];" + |
---|
| 12476 | + "PARAM light2cam2 = program.env[12];" + |
---|
| 12477 | + "TEMP temp;" + |
---|
| 12478 | + "TEMP light;" + |
---|
| 12479 | + "TEMP ndotl;" + |
---|
| 12480 | + "TEMP normal;" + |
---|
| 12481 | + "TEMP depth;" + |
---|
| 12482 | + "TEMP eye;" + |
---|
| 12483 | + "TEMP pos;" + |
---|
| 12484 | + |
---|
| 12485 | + "MAD normal, fragment.color, zero123.z, -zero123.y;" + |
---|
| 12486 | + Normalize("normal") + |
---|
| 12487 | + "MOV light, state.light[0].position;" + |
---|
| 12488 | + "DP3 ndotl.x, light, normal;" + |
---|
| 12489 | + |
---|
| 12490 | + // shadow |
---|
| 12491 | + "MOV pos, fragment.texcoord[1];" + |
---|
| 12492 | + "MOV temp, pos;" + |
---|
| 12493 | + ShadowTextureFetch("depth", "temp", "1") + |
---|
| 12494 | + //"TEX depth, fragment.texcoord[1], texture[1], 2D;" + |
---|
| 12495 | + "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" + |
---|
| 12496 | + |
---|
| 12497 | + // No shadow when out of frustum |
---|
| 12498 | + //"SGE temp.y, depth.z, zero123.y;" + |
---|
| 12499 | + //"LRP temp.x, temp.y, zero123.y, temp.x;" + |
---|
| 12500 | + |
---|
| 12501 | + "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow |
---|
| 12502 | + |
---|
| 12503 | + // Backlit |
---|
| 12504 | + "MOV pos.w, zero123.y;" + |
---|
| 12505 | + "DP4 eye.x, pos, light2cam0;" + |
---|
| 12506 | + "DP4 eye.y, pos, light2cam1;" + |
---|
| 12507 | + "DP4 eye.z, pos, light2cam2;" + |
---|
| 12508 | + Normalize("eye") + |
---|
| 12509 | + |
---|
| 12510 | + "DP3 ndotl.y, -eye, normal;" + |
---|
| 12511 | + //"MUL ndotl.y, ndotl.y, pow2.x;" + |
---|
| 12512 | + "POW ndotl.y, ndotl.y, pow2.z;" + // backlit |
---|
| 12513 | + "SUB ndotl.y, zero123.y, ndotl.y;" + |
---|
| 12514 | + //"SUB ndotl.y, zero123.y, ndotl.y;" + |
---|
| 12515 | + //"MUL ndotl.y, ndotl.y, pow2.z;" + |
---|
| 12516 | + |
---|
| 12517 | + //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient |
---|
| 12518 | + //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient |
---|
| 12519 | + |
---|
| 12520 | + // Pigment |
---|
| 12521 | + "TEX temp, fragment.texcoord[0], texture[0], 2D;" + |
---|
| 12522 | + "LRP temp, zero123.w, temp, one;" + // texture proportion |
---|
| 12523 | + "MUL temp, temp, ndotl.x;" + |
---|
| 12524 | + |
---|
| 12525 | + "MUL temp, temp, zero123.z;" + |
---|
| 12526 | + |
---|
| 12527 | + //"MUL temp, temp, ndotl.y;" + |
---|
| 12528 | + |
---|
| 12529 | + "MOV temp.w, zero123.y;" + // reset alpha |
---|
| 12530 | + "MOV result.color, temp;" + |
---|
| 12531 | + "END"; |
---|
| 12532 | + |
---|
| 12533 | + String programmax = |
---|
| 12534 | + "!!ARBfp1.0\n" + |
---|
| 12535 | + |
---|
12201 | 12536 | //"OPTION ARB_fragment_program_shadow;" + |
---|
12202 | 12537 | "PARAM light2cam0 = program.env[10];" + |
---|
12203 | 12538 | "PARAM light2cam1 = program.env[11];" + |
---|
.. | .. |
---|
12312 | 12647 | "TEMP shininess;" + |
---|
12313 | 12648 | "\n" + |
---|
12314 | 12649 | "MOV texSamp, one;" + |
---|
12315 | | - //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" + |
---|
12316 | | - |
---|
| 12650 | + |
---|
12317 | 12651 | "MOV mapgrid.x, one2048th.x;" + |
---|
12318 | 12652 | "MOV temp, fragment.texcoord[1];" + |
---|
12319 | 12653 | /* |
---|
.. | .. |
---|
12334 | 12668 | "MUL temp, floor, mapgrid.x;" + |
---|
12335 | 12669 | //"TEX depth0, temp, texture[1], 2D;" + |
---|
12336 | 12670 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12337 | | - TextureFetch("depth0", "temp", "1") + |
---|
| 12671 | + ShadowTextureFetch("depth0", "temp", "1") + |
---|
12338 | 12672 | "") + |
---|
12339 | 12673 | "ADD temp.x, temp.x, mapgrid.x;" + |
---|
12340 | 12674 | //"TEX depth1, temp, texture[1], 2D;" + |
---|
12341 | 12675 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12342 | | - TextureFetch("depth1", "temp", "1") + |
---|
| 12676 | + ShadowTextureFetch("depth1", "temp", "1") + |
---|
12343 | 12677 | "") + |
---|
12344 | 12678 | "ADD temp.y, temp.y, mapgrid.x;" + |
---|
12345 | 12679 | //"TEX depth2, temp, texture[1], 2D;" + |
---|
12346 | | - TextureFetch("depth2", "temp", "1") + |
---|
| 12680 | + ShadowTextureFetch("depth2", "temp", "1") + |
---|
12347 | 12681 | "SUB temp.x, temp.x, mapgrid.x;" + |
---|
12348 | 12682 | //"TEX depth3, temp, texture[1], 2D;" + |
---|
12349 | 12683 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12350 | | - TextureFetch("depth3", "temp", "1") + |
---|
| 12684 | + ShadowTextureFetch("depth3", "temp", "1") + |
---|
12351 | 12685 | "") + |
---|
12352 | 12686 | //"MUL texSamp0, texSamp0, state.material.front.diffuse;" + |
---|
12353 | 12687 | //"MOV params, material;" + |
---|
.. | .. |
---|
12718 | 13052 | "MAD shadow.x, buffer.x, frac.y, shadow.x;" + |
---|
12719 | 13053 | "") + |
---|
12720 | 13054 | |
---|
12721 | | - // display shadow only (bump == 0) |
---|
| 13055 | + // display shadow only (fakedepth == 0) |
---|
12722 | 13056 | "SUB temp.x, half.x, shadow.x;" + |
---|
12723 | 13057 | "MOV temp.y, -params5.z;" + // params6.x;" + |
---|
12724 | | - "SLT temp.z, temp.y, -one2048th.x;" + |
---|
| 13058 | + "SLT temp.z, temp.y, -c256i.x;" + |
---|
12725 | 13059 | "SUB temp.y, one.x, temp.z;" + |
---|
12726 | 13060 | "MUL temp.x, temp.x, temp.y;" + |
---|
12727 | 13061 | "KIL temp.x;" + |
---|
.. | .. |
---|
13052 | 13386 | //once = true; |
---|
13053 | 13387 | } |
---|
13054 | 13388 | |
---|
| 13389 | + String program = programmax; |
---|
| 13390 | + |
---|
| 13391 | + if (Globals.MINSHADER) |
---|
| 13392 | + { |
---|
| 13393 | + program = programmin; |
---|
| 13394 | + } |
---|
| 13395 | + |
---|
13055 | 13396 | System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length()); |
---|
13056 | 13397 | System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : "")); |
---|
13057 | 13398 | loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program); |
---|
.. | .. |
---|
13145 | 13486 | return out; |
---|
13146 | 13487 | } |
---|
13147 | 13488 | |
---|
13148 | | - String TextureFetch(String dest, String src, String unit) |
---|
| 13489 | + // Also does frustum culling |
---|
| 13490 | + String ShadowTextureFetch(String dest, String src, String unit) |
---|
13149 | 13491 | { |
---|
13150 | 13492 | return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" + |
---|
13151 | 13493 | "SGE " + src + ".w, " + src + ".x, eps.x;" + |
---|
13152 | 13494 | "SGE " + src + ".z, " + src + ".y, eps.x;" + |
---|
| 13495 | + "SLT " + dest + ".x, " + src + ".x, one.x;" + |
---|
| 13496 | + "SLT " + dest + ".y, " + src + ".y, one.x;" + |
---|
13153 | 13497 | "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;" + |
---|
| 13498 | + "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" + |
---|
| 13499 | + "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" + |
---|
13158 | 13500 | //"SWZ buffer, temp, w,w,w,w;"; |
---|
13159 | | - "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" + |
---|
| 13501 | + //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" + |
---|
13160 | 13502 | "SUB " + src + ".z, " + "one.x, " + src + ".w;" + |
---|
13161 | 13503 | //"MUL " + src + ".z, " + src + ".z, infinity.x;" + |
---|
13162 | 13504 | //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;"; |
---|
13163 | | - "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
| 13505 | + //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
13164 | 13506 | |
---|
13165 | | - //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;"; |
---|
13166 | | - //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;"; |
---|
| 13507 | + //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;"; |
---|
| 13508 | + "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
13167 | 13509 | } |
---|
13168 | 13510 | |
---|
13169 | 13511 | String Shadow(String depth, String shadow) |
---|
.. | .. |
---|
13210 | 13552 | "SLT temp.x, temp.x, zero.x;" + // shadoweps |
---|
13211 | 13553 | "LRP " + shadow + ", temp.x, one, " + shadow + ";" + |
---|
13212 | 13554 | |
---|
13213 | | - // No shadow when out of frustrum |
---|
| 13555 | + // No shadow when out of frustum |
---|
13214 | 13556 | "SGE temp.x, " + depth + ".z, one.z;" + |
---|
13215 | 13557 | "LRP " + shadow + ", temp.x, one, " + shadow + ";" + |
---|
13216 | 13558 | ""; |
---|
.. | .. |
---|
14008 | 14350 | drag = false; |
---|
14009 | 14351 | //System.out.println("Mouse DOWN"); |
---|
14010 | 14352 | 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); |
---|
| 14353 | + //ClickInfo info = new ClickInfo(); |
---|
| 14354 | + object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
| 14355 | + object.clickInfo.pane = this; |
---|
| 14356 | + object.clickInfo.camera = renderCamera; |
---|
| 14357 | + object.clickInfo.x = x; |
---|
| 14358 | + object.clickInfo.y = y; |
---|
| 14359 | + object.clickInfo.modifiers = modifiersex; |
---|
| 14360 | + editObj = object.doEditClick(//info, |
---|
| 14361 | + 0); |
---|
14019 | 14362 | if (!editObj) |
---|
14020 | 14363 | { |
---|
14021 | 14364 | hasMarquee = true; |
---|
.. | .. |
---|
14299 | 14642 | MODIFIERS |= COMMAND; |
---|
14300 | 14643 | /**/ |
---|
14301 | 14644 | if((mod&SHIFT) == SHIFT) |
---|
14302 | | - manipCamera.RotatePosition(0, -speed); |
---|
14303 | | - else |
---|
14304 | 14645 | manipCamera.BackForth(0, -speed*delta, 0); // getWidth()); |
---|
| 14646 | + else |
---|
| 14647 | + manipCamera.RotatePosition(0, -speed); |
---|
14305 | 14648 | /**/ |
---|
14306 | 14649 | if ((mod & SHIFT) == SHIFT) |
---|
14307 | 14650 | { |
---|
.. | .. |
---|
14320 | 14663 | MODIFIERS |= COMMAND; |
---|
14321 | 14664 | /**/ |
---|
14322 | 14665 | if((mod&SHIFT) == SHIFT) |
---|
14323 | | - manipCamera.RotatePosition(0, speed); |
---|
14324 | | - else |
---|
14325 | 14666 | manipCamera.BackForth(0, speed*delta, 0); // getWidth()); |
---|
| 14667 | + else |
---|
| 14668 | + manipCamera.RotatePosition(0, speed); |
---|
14326 | 14669 | /**/ |
---|
14327 | 14670 | if ((mod & SHIFT) == SHIFT) |
---|
14328 | 14671 | { |
---|
.. | .. |
---|
14415 | 14758 | if (editObj) |
---|
14416 | 14759 | { |
---|
14417 | 14760 | drag = true; |
---|
14418 | | - ClickInfo info = new ClickInfo(); |
---|
14419 | | - info.bounds.setBounds(0, 0, |
---|
| 14761 | + //ClickInfo info = new ClickInfo(); |
---|
| 14762 | + object.clickInfo.bounds.setBounds(0, 0, |
---|
14420 | 14763 | (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); |
---|
| 14764 | + object.clickInfo.pane = this; |
---|
| 14765 | + object.clickInfo.camera = renderCamera; |
---|
| 14766 | + object.clickInfo.x = x; |
---|
| 14767 | + object.clickInfo.y = y; |
---|
| 14768 | + object //.GetWindow().copy |
---|
| 14769 | + .doEditDrag(//info, |
---|
| 14770 | + (modifiers & MouseEvent.BUTTON3_MASK) != 0); |
---|
14427 | 14771 | } else |
---|
14428 | 14772 | { |
---|
14429 | 14773 | if (x < startX) |
---|
.. | .. |
---|
14572 | 14916 | } |
---|
14573 | 14917 | } |
---|
14574 | 14918 | |
---|
| 14919 | +// ClickInfo clickInfo = new ClickInfo(); |
---|
| 14920 | + |
---|
14575 | 14921 | public void mouseMoved(MouseEvent e) |
---|
14576 | 14922 | { |
---|
14577 | 14923 | //System.out.println("mouseMoved: " + e); |
---|
14578 | 14924 | if (isRenderer) |
---|
14579 | 14925 | return; |
---|
14580 | 14926 | |
---|
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; |
---|
| 14927 | + // Mouse cursor feedback |
---|
| 14928 | + object.clickInfo.x = e.getX(); |
---|
| 14929 | + object.clickInfo.y = e.getY(); |
---|
| 14930 | + object.clickInfo.modifiers = e.getModifiersEx(); |
---|
| 14931 | + object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
| 14932 | + object.clickInfo.pane = this; |
---|
| 14933 | + object.clickInfo.camera = renderCamera; |
---|
14588 | 14934 | if (!isRenderer) |
---|
14589 | 14935 | { |
---|
14590 | 14936 | //ObjEditor editWindow = object.editWindow; |
---|
14591 | 14937 | //Object3D copy = editWindow.copy; |
---|
14592 | | - if (object.doEditClick(ci, 0)) |
---|
| 14938 | + if (object.doEditClick(//clickInfo, |
---|
| 14939 | + 0)) |
---|
14593 | 14940 | { |
---|
14594 | 14941 | setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
---|
14595 | 14942 | } else |
---|
.. | .. |
---|
14861 | 15208 | // break; |
---|
14862 | 15209 | case 'T': |
---|
14863 | 15210 | CACHETEXTURE ^= true; |
---|
14864 | | - textures.clear(); |
---|
| 15211 | + texturepigment.clear(); |
---|
| 15212 | + texturebump.clear(); |
---|
14865 | 15213 | // repaint(); |
---|
14866 | 15214 | break; |
---|
14867 | 15215 | case 'Y': |
---|
.. | .. |
---|
15038 | 15386 | OCCLUSION_CULLING ^= true; |
---|
15039 | 15387 | System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING); |
---|
15040 | 15388 | break; |
---|
15041 | | - case '0': envyoff ^= true; repaint(); break; |
---|
| 15389 | + //case '0': envyoff ^= true; repaint(); break; |
---|
15042 | 15390 | case '1': |
---|
15043 | 15391 | case '2': |
---|
15044 | 15392 | case '3': |
---|
15045 | 15393 | case '4': |
---|
15046 | 15394 | case '5': |
---|
15047 | | - newenvy = Character.getNumericValue(key); |
---|
15048 | | - repaint(); |
---|
15049 | | - break; |
---|
15050 | 15395 | case '6': |
---|
15051 | 15396 | case '7': |
---|
15052 | 15397 | case '8': |
---|
15053 | 15398 | case '9': |
---|
15054 | | - BGcolor = (key - '6')/3.f; |
---|
| 15399 | + if (true) // envyoff) |
---|
| 15400 | + { |
---|
| 15401 | + BGcolor = (key - '1')/8.f; |
---|
| 15402 | + } |
---|
| 15403 | + else |
---|
| 15404 | + { |
---|
| 15405 | + //newenvy = Character.getNumericValue(key); |
---|
| 15406 | + } |
---|
15055 | 15407 | repaint(); |
---|
15056 | 15408 | break; |
---|
15057 | 15409 | case '!': |
---|
.. | .. |
---|
15614 | 15966 | |
---|
15615 | 15967 | int width = getBounds().width; |
---|
15616 | 15968 | int height = getBounds().height; |
---|
15617 | | - ClickInfo info = new ClickInfo(); |
---|
15618 | | - info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom)); |
---|
15619 | 15969 | //Image img = CreateImage(width, height); |
---|
15620 | 15970 | //System.out.println("width = " + width + "; height = " + height + "\n"); |
---|
15621 | 15971 | |
---|
.. | .. |
---|
15692 | 16042 | } |
---|
15693 | 16043 | if (object != null && !hasMarquee) |
---|
15694 | 16044 | { |
---|
| 16045 | + if (object.clickInfo == null) |
---|
| 16046 | + object.clickInfo = new ClickInfo(); |
---|
| 16047 | + ClickInfo info = object.clickInfo; |
---|
| 16048 | + //ClickInfo info = new ClickInfo(); |
---|
| 16049 | + info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom)); |
---|
| 16050 | + |
---|
15695 | 16051 | if (isRenderer) |
---|
15696 | 16052 | { |
---|
15697 | | - info.flags++; |
---|
| 16053 | + object.clickInfo.flags++; |
---|
15698 | 16054 | double frameAspect = (double) width / (double) height; |
---|
15699 | 16055 | if (frameAspect > renderCamera.aspect) |
---|
15700 | 16056 | { |
---|
15701 | 16057 | int desired = (int) ((double) height * renderCamera.aspect); |
---|
15702 | | - info.bounds.width -= width - desired; |
---|
15703 | | - info.bounds.x += (width - desired) / 2; |
---|
| 16058 | + object.clickInfo.bounds.width -= width - desired; |
---|
| 16059 | + object.clickInfo.bounds.x += (width - desired) / 2; |
---|
15704 | 16060 | } else |
---|
15705 | 16061 | { |
---|
15706 | 16062 | int desired = (int) ((double) width / renderCamera.aspect); |
---|
15707 | | - info.bounds.height -= height - desired; |
---|
15708 | | - info.bounds.y += (height - desired) / 2; |
---|
| 16063 | + object.clickInfo.bounds.height -= height - desired; |
---|
| 16064 | + object.clickInfo.bounds.y += (height - desired) / 2; |
---|
15709 | 16065 | } |
---|
15710 | 16066 | } |
---|
15711 | 16067 | |
---|
15712 | | - info.g = gr; |
---|
15713 | | - info.camera = renderCamera; |
---|
| 16068 | + object.clickInfo.g = gr; |
---|
| 16069 | + object.clickInfo.camera = renderCamera; |
---|
15714 | 16070 | /* |
---|
15715 | 16071 | // Memory intensive (brep.verticescopy) |
---|
15716 | 16072 | if (!(object instanceof Composite)) |
---|
15717 | 16073 | object.draw(info, 0, false); // SLOW : |
---|
15718 | 16074 | */ |
---|
15719 | | - if (!isRenderer) |
---|
| 16075 | + if (!isRenderer) // && drag) |
---|
15720 | 16076 | { |
---|
15721 | 16077 | Grafreed.Assert(object != null); |
---|
15722 | 16078 | Grafreed.Assert(object.selection != null); |
---|
.. | .. |
---|
15724 | 16080 | { |
---|
15725 | 16081 | int hitSomething = object.selection.get(0).hitSomething; |
---|
15726 | 16082 | |
---|
15727 | | - info.DX = 0; |
---|
15728 | | - info.DY = 0; |
---|
15729 | | - info.W = 1; |
---|
| 16083 | + object.clickInfo.DX = 0; |
---|
| 16084 | + object.clickInfo.DY = 0; |
---|
| 16085 | + object.clickInfo.W = 1; |
---|
15730 | 16086 | if (hitSomething == Object3D.hitCenter) |
---|
15731 | 16087 | { |
---|
15732 | 16088 | info.DX = X; |
---|
.. | .. |
---|
15738 | 16094 | info.DY -= info.bounds.height/2; |
---|
15739 | 16095 | } |
---|
15740 | 16096 | |
---|
15741 | | - object.drawEditHandles(info, 0); |
---|
| 16097 | + object.drawEditHandles(//info, |
---|
| 16098 | + 0); |
---|
15742 | 16099 | |
---|
15743 | 16100 | if (drag && (X != 0 || Y != 0)) |
---|
15744 | 16101 | { |
---|
.. | .. |
---|
16237 | 16594 | private /*static*/ boolean firstime; |
---|
16238 | 16595 | private /*static*/ cVector newView = new cVector(); |
---|
16239 | 16596 | private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"}; |
---|
| 16597 | + private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"}; |
---|
| 16598 | + private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"}; |
---|
16240 | 16599 | private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X, |
---|
16241 | 16600 | GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X, |
---|
16242 | 16601 | GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y, |
---|
.. | .. |
---|
16249 | 16608 | { |
---|
16250 | 16609 | com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP); |
---|
16251 | 16610 | |
---|
| 16611 | + int usedsuf = 0; |
---|
| 16612 | + |
---|
16252 | 16613 | for (int i = 0; i < suffixes.length; i++) |
---|
16253 | 16614 | { |
---|
16254 | | - String resourceName = basename + suffixes[i] + "." + suffix; |
---|
16255 | | - TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
16256 | | - mipmapped, |
---|
16257 | | - FileUtil.getFileSuffix(resourceName)); |
---|
16258 | | - if (data == null) |
---|
| 16615 | + String[] suffixe = suffixes; |
---|
| 16616 | + String[] fallback = suffixes2; |
---|
| 16617 | + String[] fallfallback = suffixes3; |
---|
| 16618 | + |
---|
| 16619 | + for (int c=usedsuf; --c>=0;) |
---|
16259 | 16620 | { |
---|
16260 | | - throw new IOException("Unable to load texture " + resourceName); |
---|
| 16621 | +// String[] temp = suffixe; |
---|
| 16622 | +// suffixe = fallback; |
---|
| 16623 | +// fallback = fallfallback; |
---|
| 16624 | +// fallfallback = temp; |
---|
16261 | 16625 | } |
---|
| 16626 | + |
---|
| 16627 | + String resourceName = basename + suffixe[i] + "." + suffix; |
---|
| 16628 | + TextureData data; |
---|
| 16629 | + |
---|
| 16630 | + try |
---|
| 16631 | + { |
---|
| 16632 | + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
| 16633 | + mipmapped, |
---|
| 16634 | + FileUtil.getFileSuffix(resourceName)); |
---|
| 16635 | + } |
---|
| 16636 | + catch (Exception e) |
---|
| 16637 | + { |
---|
| 16638 | + try |
---|
| 16639 | + { |
---|
| 16640 | + resourceName = basename + fallback[i] + "." + suffix; |
---|
| 16641 | + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
| 16642 | + mipmapped, |
---|
| 16643 | + FileUtil.getFileSuffix(resourceName)); |
---|
| 16644 | + } |
---|
| 16645 | + catch (Exception e2) |
---|
| 16646 | + { |
---|
| 16647 | + resourceName = basename + fallfallback[i] + "." + suffix; |
---|
| 16648 | + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
| 16649 | + mipmapped, |
---|
| 16650 | + FileUtil.getFileSuffix(resourceName)); |
---|
| 16651 | + } |
---|
| 16652 | + } |
---|
| 16653 | + |
---|
16262 | 16654 | //System.out.println("Target = " + targets[i]); |
---|
16263 | 16655 | cubemap.updateImage(data, targets[i]); |
---|
16264 | 16656 | } |
---|
16265 | 16657 | |
---|
16266 | 16658 | return cubemap; |
---|
16267 | 16659 | } |
---|
| 16660 | + |
---|
16268 | 16661 | int bigsphere = -1; |
---|
16269 | 16662 | |
---|
16270 | 16663 | float BGcolor = 0.5f; |
---|
16271 | 16664 | |
---|
16272 | | - private void DrawSkyBox(GL gl) |
---|
| 16665 | + float ambientLight[] = {1f, 1f, 1f, 1.0f}; |
---|
| 16666 | + |
---|
| 16667 | + private void DrawSkyBox(GL gl, float ratio) |
---|
16273 | 16668 | { |
---|
16274 | | - if (envyoff || cubemap == null) |
---|
| 16669 | + if (//envyoff || |
---|
| 16670 | + WIREFRAME || |
---|
| 16671 | + cubemap == null) |
---|
16275 | 16672 | { |
---|
16276 | 16673 | gl.glClearColor(BGcolor, BGcolor, BGcolor, 1); |
---|
16277 | 16674 | gl.glClear(gl.GL_COLOR_BUFFER_BIT); |
---|
.. | .. |
---|
16286 | 16683 | // Compensates for ExaminerViewer's modification of modelview matrix |
---|
16287 | 16684 | gl.glMatrixMode(GL.GL_MODELVIEW); |
---|
16288 | 16685 | gl.glLoadIdentity(); |
---|
| 16686 | + gl.glScalef(1,ratio,1); |
---|
16289 | 16687 | |
---|
| 16688 | +// colorV[0] = 2; |
---|
| 16689 | +// colorV[1] = 2; |
---|
| 16690 | +// colorV[2] = 2; |
---|
| 16691 | +// colorV[3] = 1; |
---|
| 16692 | +// gl.glDisable(gl.GL_COLOR_MATERIAL); |
---|
| 16693 | +// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0); |
---|
| 16694 | +// |
---|
| 16695 | +// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0); |
---|
| 16696 | + |
---|
16290 | 16697 | //gl.glActiveTexture(GL.GL_TEXTURE1); |
---|
16291 | 16698 | //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP); |
---|
16292 | 16699 | |
---|
.. | .. |
---|
16318 | 16725 | { |
---|
16319 | 16726 | gl.glScalef(1.0f, -1.0f, 1.0f); |
---|
16320 | 16727 | } |
---|
| 16728 | + gl.glScalef(-1.0f, 1.0f, 1.0f); |
---|
16321 | 16729 | gl.glMultMatrixd(viewrot_1, 0); |
---|
16322 | 16730 | gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f); |
---|
16323 | 16731 | //viewer.updateInverseRotation(gl); |
---|
.. | .. |
---|
16553 | 16961 | } |
---|
16554 | 16962 | } |
---|
16555 | 16963 | |
---|
| 16964 | + private Object3D GetFolder() |
---|
| 16965 | + { |
---|
| 16966 | + Object3D folder = object.GetWindow().copy; |
---|
| 16967 | + if (object.GetWindow().copy.selection.Size() > 0) |
---|
| 16968 | + folder = object.GetWindow().copy.selection.elementAt(0); |
---|
| 16969 | + return folder; |
---|
| 16970 | + } |
---|
| 16971 | + |
---|
16556 | 16972 | class SelectBuffer implements GLEventListener |
---|
16557 | 16973 | { |
---|
16558 | 16974 | |
---|
.. | .. |
---|
16568 | 16984 | //new Exception().printStackTrace(); |
---|
16569 | 16985 | System.out.println("select buffer init"); |
---|
16570 | 16986 | // Use debug pipeline |
---|
16571 | | - drawable.setGL(new DebugGL(drawable.getGL())); |
---|
| 16987 | + //drawable.setGL(new DebugGL(drawable.getGL())); |
---|
16572 | 16988 | |
---|
16573 | 16989 | GL gl = drawable.getGL(); |
---|
16574 | 16990 | |
---|
.. | .. |
---|
16632 | 17048 | |
---|
16633 | 17049 | //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL); |
---|
16634 | 17050 | |
---|
| 17051 | + if (PAINTMODE) |
---|
| 17052 | + { |
---|
| 17053 | + if (object.GetWindow().copy.selection.Size() > 0) |
---|
| 17054 | + { |
---|
| 17055 | + Object3D paintobj = object.GetWindow().copy.selection.elementAt(0); |
---|
| 17056 | + |
---|
| 17057 | + // Make what you paint not selectable. |
---|
| 17058 | + paintobj.ResetSelectable(); |
---|
| 17059 | + } |
---|
| 17060 | + } |
---|
| 17061 | + |
---|
16635 | 17062 | //int tmp = selection_view; |
---|
16636 | 17063 | //selection_view = -1; |
---|
16637 | 17064 | int temp = DrawMode(); |
---|
.. | .. |
---|
16643 | 17070 | // temp = DEFAULT; // patch for selection debug |
---|
16644 | 17071 | Globals.drawMode = temp; // WARNING |
---|
16645 | 17072 | |
---|
| 17073 | + if (PAINTMODE) |
---|
| 17074 | + { |
---|
| 17075 | + if (object.GetWindow().copy.selection.Size() > 0) |
---|
| 17076 | + { |
---|
| 17077 | + Object3D paintobj = object.GetWindow().copy.selection.elementAt(0); |
---|
| 17078 | + |
---|
| 17079 | + // Revert. |
---|
| 17080 | + paintobj.RestoreSelectable(); |
---|
| 17081 | + } |
---|
| 17082 | + } |
---|
| 17083 | + |
---|
16646 | 17084 | //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view); |
---|
16647 | 17085 | |
---|
16648 | 17086 | // trying different ways of getting the depth info over |
---|
.. | .. |
---|
16748 | 17186 | if (!movingcamera && !PAINTMODE) |
---|
16749 | 17187 | object.GetWindow().ScreenFitPoint(); // fev 2014 |
---|
16750 | 17188 | |
---|
16751 | | - if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0) |
---|
| 17189 | + if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0) |
---|
16752 | 17190 | { |
---|
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; |
---|
| 17191 | + //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0); |
---|
16764 | 17192 | |
---|
16765 | 17193 | if (object.GetWindow().copy.selection.Size() > 0) |
---|
16766 | | - folder = object.GetWindow().copy.selection.elementAt(0); |
---|
| 17194 | + { |
---|
| 17195 | + Object3D paintobj = object.GetWindow().copy.selection.elementAt(0); |
---|
16767 | 17196 | |
---|
16768 | | - folder.add(group); |
---|
16769 | | - |
---|
16770 | | - object.GetWindow().ResetModel(); |
---|
16771 | | - object.GetWindow().refreshContents(); |
---|
| 17197 | + Object3D inst = new Object3D("inst" + paintcount++); |
---|
| 17198 | + |
---|
| 17199 | + inst.CreateMaterial(); // use a void leaf to select instances |
---|
| 17200 | + |
---|
| 17201 | + inst.add(paintobj); // link |
---|
| 17202 | + |
---|
| 17203 | + object.GetWindow().SnapObject(inst); |
---|
| 17204 | + |
---|
| 17205 | + Object3D folder = paintFolder; // GetFolder(); |
---|
| 17206 | + |
---|
| 17207 | + folder.add(inst); |
---|
| 17208 | + |
---|
| 17209 | + object.GetWindow().ResetModel(); |
---|
| 17210 | + object.GetWindow().refreshContents(); |
---|
| 17211 | + } |
---|
16772 | 17212 | } |
---|
16773 | 17213 | else |
---|
16774 | 17214 | paintcount = 0; |
---|