.. | .. |
---|
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; |
---|
.. | .. |
---|
73 | 110 | //private Mat4f spotlightTransform = new Mat4f(); |
---|
74 | 111 | //private Mat4f spotlightInverseTransform = new Mat4f(); |
---|
75 | 112 | static GLContext glcontext = null; |
---|
76 | | - /*static*/ com.sun.opengl.util.texture.Texture cubemap; |
---|
| 113 | + /*static*/ com.sun.opengl.util.texture.Texture cubemap; // Either custom or rgb |
---|
| 114 | + /*static*/ com.sun.opengl.util.texture.Texture cubemapcustom; |
---|
| 115 | + /*static*/ com.sun.opengl.util.texture.Texture cubemaprgb; |
---|
| 116 | + boolean transformMode; |
---|
| 117 | + |
---|
77 | 118 | boolean reverseUP = false; |
---|
78 | 119 | static boolean frozen = false; |
---|
79 | 120 | boolean enablebackspace = false; // patch for back buffer refresh |
---|
.. | .. |
---|
136 | 177 | static boolean doublesided = false; // true; // reversed normals are awful for conformance |
---|
137 | 178 | boolean anisotropy = true; |
---|
138 | 179 | boolean softshadow = true; // slower but better false; |
---|
139 | | - boolean opacityhalo = false; |
---|
| 180 | + boolean opacityhalo = false; // reverse the halo effect (e.g. glass) |
---|
140 | 181 | |
---|
141 | 182 | boolean macromode = false; |
---|
142 | 183 | |
---|
.. | .. |
---|
150 | 191 | } |
---|
151 | 192 | |
---|
152 | 193 | private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory(); |
---|
| 194 | + |
---|
| 195 | + public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException |
---|
| 196 | + { |
---|
| 197 | + try |
---|
| 198 | + { |
---|
| 199 | + return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap); |
---|
| 200 | + } catch (IOException e) |
---|
| 201 | + { |
---|
| 202 | + System.out.println("NAME = " + name); |
---|
| 203 | + e.printStackTrace(); // throw new RuntimeException(e); |
---|
| 204 | + return null; |
---|
| 205 | + } |
---|
| 206 | + } |
---|
153 | 207 | |
---|
154 | 208 | void SetAsGLRenderer(boolean b) |
---|
155 | 209 | { |
---|
.. | .. |
---|
169 | 223 | |
---|
170 | 224 | SetCamera(cam); |
---|
171 | 225 | |
---|
172 | | - SetLight(new Camera(new cVector(10, 10, -20))); |
---|
| 226 | + // Warning: not used. |
---|
| 227 | + SetLight(new Camera(new cVector(15, 10, -20))); |
---|
173 | 228 | |
---|
174 | 229 | object = o; |
---|
175 | 230 | |
---|
.. | .. |
---|
1447 | 1502 | gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z); |
---|
1448 | 1503 | } |
---|
1449 | 1504 | |
---|
| 1505 | + float[] colorV = new float[4]; |
---|
| 1506 | + |
---|
1450 | 1507 | void SetColor(Object3D obj, Vertex p0) |
---|
1451 | 1508 | { |
---|
1452 | 1509 | CameraPane display = this; |
---|
.. | .. |
---|
1514 | 1571 | { |
---|
1515 | 1572 | return; |
---|
1516 | 1573 | } |
---|
1517 | | - |
---|
1518 | | - float[] colorV = new float[3]; |
---|
1519 | 1574 | |
---|
1520 | 1575 | if (false) // marked) |
---|
1521 | 1576 | { |
---|
.. | .. |
---|
2065 | 2120 | //System.err.println("Oeil on"); |
---|
2066 | 2121 | OEIL = true; |
---|
2067 | 2122 | if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode) |
---|
2068 | | - object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK); |
---|
| 2123 | + object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK); |
---|
2069 | 2124 | //pingthread.StepToTarget(true); |
---|
2070 | 2125 | } |
---|
2071 | 2126 | |
---|
.. | .. |
---|
2298 | 2353 | HANDLES ^= true; |
---|
2299 | 2354 | } |
---|
2300 | 2355 | |
---|
| 2356 | + Object3D paintFolder; |
---|
| 2357 | + |
---|
2301 | 2358 | void TogglePaint() |
---|
2302 | 2359 | { |
---|
2303 | 2360 | PAINTMODE ^= true; |
---|
2304 | 2361 | paintcount = 0; |
---|
| 2362 | + |
---|
| 2363 | + if (PAINTMODE) |
---|
| 2364 | + { |
---|
| 2365 | + paintFolder = GetFolder(); |
---|
| 2366 | + } |
---|
2305 | 2367 | } |
---|
2306 | 2368 | |
---|
2307 | 2369 | void SwapCamera(int a, int b) |
---|
.. | .. |
---|
2398 | 2460 | return currentGL; |
---|
2399 | 2461 | } |
---|
2400 | 2462 | |
---|
| 2463 | + static private BufferedImage CreateBim(TextureData texturedata) |
---|
| 2464 | + { |
---|
| 2465 | + Grafreed.Assert(texturedata != null); |
---|
| 2466 | + |
---|
| 2467 | + int width = texturedata.getWidth(); |
---|
| 2468 | + int height = texturedata.getHeight(); |
---|
| 2469 | + |
---|
| 2470 | + Buffer buffer = texturedata.getBuffer(); |
---|
| 2471 | + ByteBuffer bytebuf = (ByteBuffer)buffer; |
---|
| 2472 | + |
---|
| 2473 | + byte[] bytes = bytebuf.array(); |
---|
| 2474 | + |
---|
| 2475 | + return CreateBim(bytes, width, height); |
---|
| 2476 | + } |
---|
| 2477 | + |
---|
2401 | 2478 | /**/ |
---|
2402 | 2479 | class CacheTexture |
---|
2403 | 2480 | { |
---|
.. | .. |
---|
2406 | 2483 | |
---|
2407 | 2484 | int resolution; |
---|
2408 | 2485 | |
---|
2409 | | - CacheTexture(com.sun.opengl.util.texture.Texture tex, int res) |
---|
| 2486 | + CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res) |
---|
2410 | 2487 | { |
---|
2411 | | - texture = tex; |
---|
| 2488 | + texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata); |
---|
| 2489 | + texturedata = texdata; |
---|
2412 | 2490 | resolution = res; |
---|
2413 | 2491 | } |
---|
2414 | 2492 | } |
---|
2415 | 2493 | /**/ |
---|
2416 | 2494 | |
---|
2417 | 2495 | // 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>(); |
---|
| 2496 | + static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>(); |
---|
| 2497 | + static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>(); |
---|
| 2498 | + static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>(); |
---|
| 2499 | + static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>(); |
---|
| 2500 | + |
---|
2421 | 2501 | int pigmentdepth = 0; |
---|
2422 | 2502 | public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536]; |
---|
2423 | 2503 | int bumpdepth = 0; |
---|
2424 | 2504 | public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536]; |
---|
2425 | 2505 | //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE"; |
---|
2426 | 2506 | public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP"); |
---|
2427 | | - public static String NOISE_TEXTURE = "WHITE_NOISE"; |
---|
| 2507 | + public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:"); |
---|
2428 | 2508 | // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL"); |
---|
2429 | 2509 | |
---|
2430 | | - com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump) |
---|
| 2510 | + com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump) |
---|
2431 | 2511 | { |
---|
2432 | 2512 | TextureData texturedata = null; |
---|
2433 | 2513 | |
---|
.. | .. |
---|
2437 | 2517 | com.sun.opengl.util.texture.TextureIO.newTextureData( |
---|
2438 | 2518 | getClass().getClassLoader().getResourceAsStream(name), |
---|
2439 | 2519 | true, |
---|
2440 | | - com.sun.opengl.util.texture.TextureIO.PNG); |
---|
| 2520 | + GetFormat(name)); // com.sun.opengl.util.texture.TextureIO.PNG); |
---|
2441 | 2521 | } catch (java.io.IOException e) |
---|
2442 | 2522 | { |
---|
2443 | 2523 | throw new javax.media.opengl.GLException(e); |
---|
.. | .. |
---|
2446 | 2526 | if (bump) |
---|
2447 | 2527 | texturedata = ConvertBump(texturedata, false); |
---|
2448 | 2528 | |
---|
2449 | | - com.sun.opengl.util.texture.Texture texture = |
---|
2450 | | - com.sun.opengl.util.texture.TextureIO.newTexture(texturedata); |
---|
| 2529 | +// com.sun.opengl.util.texture.Texture texture = |
---|
| 2530 | +// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata); |
---|
2451 | 2531 | |
---|
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); |
---|
| 2532 | + //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT); |
---|
| 2533 | + //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT); |
---|
2454 | 2534 | |
---|
2455 | | - return texture; |
---|
| 2535 | + return texturedata; |
---|
| 2536 | + } |
---|
| 2537 | + |
---|
| 2538 | + com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump) |
---|
| 2539 | + { |
---|
| 2540 | + TextureData texturedata = null; |
---|
| 2541 | + |
---|
| 2542 | + try |
---|
| 2543 | + { |
---|
| 2544 | + texturedata = |
---|
| 2545 | + com.sun.opengl.util.texture.TextureIO.newTextureData( |
---|
| 2546 | + bim, |
---|
| 2547 | + true); |
---|
| 2548 | + } catch (Exception e) |
---|
| 2549 | + { |
---|
| 2550 | + throw new javax.media.opengl.GLException(e); |
---|
| 2551 | + } |
---|
| 2552 | + |
---|
| 2553 | + if (bump) |
---|
| 2554 | + texturedata = ConvertBump(texturedata, false); |
---|
| 2555 | + |
---|
| 2556 | + return texturedata; |
---|
2456 | 2557 | } |
---|
2457 | 2558 | |
---|
2458 | 2559 | boolean HUESMOOTH = true; // wrap around bug... true; |
---|
.. | .. |
---|
3525 | 3626 | |
---|
3526 | 3627 | System.out.println("LOADING TEXTURE : " + name); |
---|
3527 | 3628 | |
---|
| 3629 | + Object x = texturedata.getMipmapData(); // .getBuffer(); |
---|
| 3630 | + |
---|
3528 | 3631 | // |
---|
3529 | 3632 | if (false) // compressbit > 0) |
---|
3530 | 3633 | { |
---|
.. | .. |
---|
7923 | 8026 | String pigment = Object3D.GetPigment(tex); |
---|
7924 | 8027 | String bump = Object3D.GetBump(tex); |
---|
7925 | 8028 | |
---|
7926 | | - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8029 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
7927 | 8030 | { |
---|
7928 | 8031 | // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment); |
---|
7929 | 8032 | // System.out.println("; bump = " + bump); |
---|
.. | .. |
---|
7938 | 8041 | pigment = null; |
---|
7939 | 8042 | } |
---|
7940 | 8043 | |
---|
7941 | | - ReleaseTexture(bump, true); |
---|
7942 | | - ReleaseTexture(pigment, false); |
---|
| 8044 | + ReleaseTexture(tex, true); |
---|
| 8045 | + ReleaseTexture(tex, false); |
---|
7943 | 8046 | } |
---|
7944 | 8047 | |
---|
7945 | 8048 | public void ReleasePigmentTexture(cTexture tex) // INTERFACE |
---|
.. | .. |
---|
7957 | 8060 | |
---|
7958 | 8061 | String pigment = Object3D.GetPigment(tex); |
---|
7959 | 8062 | |
---|
7960 | | - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8063 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
7961 | 8064 | { |
---|
7962 | 8065 | // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment); |
---|
7963 | 8066 | // System.out.println("; bump = " + bump); |
---|
.. | .. |
---|
7968 | 8071 | pigment = null; |
---|
7969 | 8072 | } |
---|
7970 | 8073 | |
---|
7971 | | - ReleaseTexture(pigment, false); |
---|
| 8074 | + ReleaseTexture(tex, false); |
---|
7972 | 8075 | } |
---|
7973 | 8076 | |
---|
7974 | 8077 | public void ReleaseBumpTexture(cTexture tex) // INTERFACE |
---|
.. | .. |
---|
7986 | 8089 | |
---|
7987 | 8090 | String bump = Object3D.GetBump(tex); |
---|
7988 | 8091 | |
---|
7989 | | - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8092 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
7990 | 8093 | { |
---|
7991 | 8094 | // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment); |
---|
7992 | 8095 | // System.out.println("; bump = " + bump); |
---|
.. | .. |
---|
7997 | 8100 | bump = null; |
---|
7998 | 8101 | } |
---|
7999 | 8102 | |
---|
8000 | | - ReleaseTexture(bump, true); |
---|
| 8103 | + ReleaseTexture(tex, true); |
---|
8001 | 8104 | } |
---|
8002 | 8105 | |
---|
8003 | | - void ReleaseTexture(String tex, boolean bump) |
---|
| 8106 | + void ReleaseTexture(cTexture tex, boolean bump) |
---|
8004 | 8107 | { |
---|
8005 | 8108 | if (// DrawMode() != 0 || /*tex == null ||*/ |
---|
8006 | 8109 | ambientOcclusion ) // || !textureon) |
---|
.. | .. |
---|
8011 | 8114 | CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null; |
---|
8012 | 8115 | |
---|
8013 | 8116 | if (tex != null) |
---|
8014 | | - texture = textures.get(tex); |
---|
| 8117 | + texture = bump ? texturebump.get(tex) : texturepigment.get(tex); |
---|
8015 | 8118 | |
---|
8016 | 8119 | // //assert( texture != null ); |
---|
8017 | 8120 | // if (texture == null) |
---|
.. | .. |
---|
8105 | 8208 | |
---|
8106 | 8209 | /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE |
---|
8107 | 8210 | { |
---|
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 | | - } |
---|
| 8211 | +// if (// DrawMode() != 0 || /*tex == null ||*/ |
---|
| 8212 | +// ambientOcclusion ) // || !textureon) |
---|
| 8213 | +// { |
---|
| 8214 | +// return; // false; |
---|
| 8215 | +// } |
---|
| 8216 | +// |
---|
| 8217 | +// if (tex == null) |
---|
| 8218 | +// { |
---|
| 8219 | +// BindTexture(null,false,resolution); |
---|
| 8220 | +// BindTexture(null,true,resolution); |
---|
| 8221 | +// return; |
---|
| 8222 | +// } |
---|
| 8223 | +// |
---|
| 8224 | +// String pigment = Object3D.GetPigment(tex); |
---|
| 8225 | +// String bump = Object3D.GetBump(tex); |
---|
| 8226 | +// |
---|
| 8227 | +// usedtextures.add(pigment); |
---|
| 8228 | +// usedtextures.add(bump); |
---|
| 8229 | +// |
---|
| 8230 | +// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8231 | +// { |
---|
| 8232 | +// // System.out.print("BIND +++++++++++++++ pigment = " + pigment); |
---|
| 8233 | +// // System.out.println("; bump = " + bump); |
---|
| 8234 | +// } |
---|
| 8235 | +// |
---|
| 8236 | +// if (bump.equals("")) |
---|
| 8237 | +// { |
---|
| 8238 | +// bump = null; |
---|
| 8239 | +// } |
---|
| 8240 | +// if (pigment.equals("")) |
---|
| 8241 | +// { |
---|
| 8242 | +// pigment = null; |
---|
| 8243 | +// } |
---|
| 8244 | +// |
---|
| 8245 | +// GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
| 8246 | +// BindTexture(pigment, false, resolution); |
---|
| 8247 | +// GetGL().glActiveTexture(GetGL().GL_TEXTURE2); |
---|
| 8248 | +// BindTexture(bump, true, resolution); |
---|
| 8249 | +// GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
| 8250 | +// |
---|
| 8251 | +// return; // true; |
---|
8120 | 8252 | |
---|
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; |
---|
| 8253 | + BindPigmentTexture(tex, resolution); |
---|
| 8254 | + BindBumpTexture(tex, resolution); |
---|
8149 | 8255 | } |
---|
8150 | 8256 | |
---|
8151 | 8257 | /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE |
---|
.. | .. |
---|
8164 | 8270 | |
---|
8165 | 8271 | String pigment = Object3D.GetPigment(tex); |
---|
8166 | 8272 | |
---|
8167 | | - usedtextures.put(pigment, pigment); |
---|
| 8273 | + usedtextures.add(tex); |
---|
8168 | 8274 | |
---|
8169 | | - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8275 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
8170 | 8276 | { |
---|
8171 | 8277 | // System.out.print("BIND +++++++++++++++ pigment = " + pigment); |
---|
8172 | 8278 | // System.out.println("; bump = " + bump); |
---|
.. | .. |
---|
8178 | 8284 | } |
---|
8179 | 8285 | |
---|
8180 | 8286 | GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
8181 | | - BindTexture(pigment, false, resolution); |
---|
| 8287 | + BindTexture(tex, false, resolution); |
---|
8182 | 8288 | } |
---|
8183 | 8289 | |
---|
8184 | 8290 | /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE |
---|
.. | .. |
---|
8197 | 8303 | |
---|
8198 | 8304 | String bump = Object3D.GetBump(tex); |
---|
8199 | 8305 | |
---|
8200 | | - usedtextures.put(bump, bump); |
---|
| 8306 | + usedtextures.add(tex); |
---|
8201 | 8307 | |
---|
8202 | | - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8308 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
8203 | 8309 | { |
---|
8204 | 8310 | // System.out.print("BIND +++++++++++++++ pigment = " + pigment); |
---|
8205 | 8311 | // System.out.println("; bump = " + bump); |
---|
.. | .. |
---|
8211 | 8317 | } |
---|
8212 | 8318 | |
---|
8213 | 8319 | GetGL().glActiveTexture(GetGL().GL_TEXTURE2); |
---|
8214 | | - BindTexture(bump, true, resolution); |
---|
| 8320 | + BindTexture(tex, true, resolution); |
---|
8215 | 8321 | GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
8216 | 8322 | } |
---|
8217 | 8323 | |
---|
.. | .. |
---|
8235 | 8341 | return fileExists; |
---|
8236 | 8342 | } |
---|
8237 | 8343 | |
---|
8238 | | - CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception |
---|
| 8344 | + CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8239 | 8345 | { |
---|
8240 | | - CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null; |
---|
| 8346 | + CacheTexture texturecache = null; |
---|
8241 | 8347 | |
---|
8242 | 8348 | if (tex != null) |
---|
8243 | 8349 | { |
---|
8244 | | - String texname = tex; |
---|
| 8350 | + String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex); |
---|
| 8351 | + byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata; |
---|
| 8352 | + |
---|
| 8353 | + if (texname.equals("") && texdata == null) |
---|
| 8354 | + { |
---|
| 8355 | + return null; |
---|
| 8356 | + } |
---|
8245 | 8357 | |
---|
8246 | 8358 | String fallbackTextureName = defaultDirectory + "/Textures/" + texname; |
---|
8247 | 8359 | |
---|
.. | .. |
---|
8251 | 8363 | // else |
---|
8252 | 8364 | // if (!texname.startsWith("/")) |
---|
8253 | 8365 | // texname = "/Users/nbriere/Textures/" + texname; |
---|
8254 | | - if (!FileExists(tex)) |
---|
| 8366 | + if (!FileExists(texname) && !texname.startsWith("@")) |
---|
8255 | 8367 | { |
---|
8256 | 8368 | texname = fallbackTextureName; |
---|
8257 | 8369 | } |
---|
8258 | 8370 | |
---|
8259 | 8371 | if (CACHETEXTURE) |
---|
8260 | | - texture = textures.get(texname); // TEXTURE CACHE |
---|
8261 | | - |
---|
8262 | | - TextureData texturedata = null; |
---|
8263 | | - |
---|
8264 | | - if (texture == null || texture.resolution < resolution) |
---|
8265 | 8372 | { |
---|
8266 | | - if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals("")) |
---|
| 8373 | + if (texdata == null) |
---|
| 8374 | + texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex); |
---|
| 8375 | + else |
---|
| 8376 | + texturecache = bimtextures.get(texdata); |
---|
| 8377 | + } |
---|
| 8378 | + |
---|
| 8379 | + if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution) |
---|
| 8380 | + { |
---|
| 8381 | + TextureData texturedata = null; |
---|
| 8382 | + |
---|
| 8383 | + if (texdata != null && textureon) |
---|
| 8384 | + { |
---|
| 8385 | + BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB); |
---|
| 8386 | + |
---|
| 8387 | + try |
---|
| 8388 | + { |
---|
| 8389 | + bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph); |
---|
| 8390 | + } |
---|
| 8391 | + catch (Exception e) |
---|
| 8392 | + { |
---|
| 8393 | + bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph); |
---|
| 8394 | + } |
---|
| 8395 | + |
---|
| 8396 | + texturecache = new CacheTexture(GetBimTexture(bim, bump), -1); |
---|
| 8397 | + bimtextures.put(texdata, texturecache); |
---|
| 8398 | + |
---|
| 8399 | + //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB); |
---|
| 8400 | + |
---|
| 8401 | + //Object bim2 = CreateBim(texturecache.texturedata); |
---|
| 8402 | + //bim2 = bim; |
---|
| 8403 | + } |
---|
| 8404 | + else |
---|
| 8405 | + if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals("")) |
---|
8267 | 8406 | { |
---|
8268 | 8407 | assert(!bump); |
---|
8269 | 8408 | // if (bump) |
---|
.. | .. |
---|
8274 | 8413 | // } |
---|
8275 | 8414 | // else |
---|
8276 | 8415 | // { |
---|
8277 | | - texture = textures.get(tex); |
---|
8278 | | - if (texture == null) |
---|
| 8416 | + // texturecache = textures.get(texname); // suspicious |
---|
| 8417 | + if (texturecache == null) |
---|
8279 | 8418 | { |
---|
8280 | | - texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
| 8419 | + texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
8281 | 8420 | } |
---|
| 8421 | + else |
---|
| 8422 | + new Exception().printStackTrace(); |
---|
8282 | 8423 | // } |
---|
8283 | 8424 | } else |
---|
8284 | | - if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals("")) |
---|
| 8425 | + if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals("")) |
---|
8285 | 8426 | { |
---|
8286 | 8427 | assert(bump); |
---|
8287 | | - texture = textures.get(tex); |
---|
8288 | | - if (texture == null) |
---|
8289 | | - texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
| 8428 | + // texturecache = textures.get(texname); // suspicious |
---|
| 8429 | + if (texturecache == null) |
---|
| 8430 | + texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
| 8431 | + else |
---|
| 8432 | + new Exception().printStackTrace(); |
---|
8290 | 8433 | } else |
---|
8291 | 8434 | { |
---|
8292 | 8435 | //if (tex.equals("IMMORTAL")) |
---|
.. | .. |
---|
8294 | 8437 | // texture = GetResourceTexture("default.png"); |
---|
8295 | 8438 | //} else |
---|
8296 | 8439 | //{ |
---|
8297 | | - if (tex.equals("WHITE_NOISE")) |
---|
| 8440 | + if (texname.endsWith("WHITE_NOISE")) |
---|
8298 | 8441 | { |
---|
8299 | | - texture = textures.get(tex); |
---|
8300 | | - if (texture == null) |
---|
8301 | | - texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution); |
---|
| 8442 | + // texturecache = textures.get(texname); // suspicious |
---|
| 8443 | + if (texturecache == null) |
---|
| 8444 | + texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution); |
---|
| 8445 | + else |
---|
| 8446 | + new Exception().printStackTrace(); |
---|
| 8447 | + } else |
---|
| 8448 | + { |
---|
| 8449 | + if (texname.startsWith("@")) |
---|
| 8450 | + { |
---|
| 8451 | + // texturecache = textures.get(texname); // suspicious |
---|
| 8452 | + if (texturecache == null) |
---|
| 8453 | + texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution); |
---|
| 8454 | + else |
---|
| 8455 | + new Exception().printStackTrace(); |
---|
8302 | 8456 | } else |
---|
8303 | 8457 | { |
---|
8304 | 8458 | if (textureon) |
---|
.. | .. |
---|
8357 | 8511 | if (texturedata == null) |
---|
8358 | 8512 | throw new Exception(); |
---|
8359 | 8513 | |
---|
8360 | | - texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution); |
---|
| 8514 | + texturecache = new CacheTexture(texturedata,resolution); |
---|
8361 | 8515 | //texture = GetTexture(tex, bump); |
---|
8362 | 8516 | } |
---|
| 8517 | + } |
---|
8363 | 8518 | } |
---|
8364 | 8519 | //} |
---|
8365 | 8520 | } |
---|
8366 | 8521 | |
---|
8367 | | - if (/*CACHETEXTURE &&*/ texture != null && textureon) |
---|
| 8522 | + if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon) |
---|
8368 | 8523 | { |
---|
8369 | 8524 | //return false; |
---|
8370 | 8525 | |
---|
8371 | 8526 | // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")"); |
---|
8372 | | - if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG"))) |
---|
| 8527 | + if (texturedata != null && texname.toLowerCase().endsWith(".jpg")) |
---|
8373 | 8528 | { |
---|
8374 | 8529 | // String ext = "_highres"; |
---|
8375 | 8530 | // if (REDUCETEXTURE) |
---|
.. | .. |
---|
8386 | 8541 | File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg"); |
---|
8387 | 8542 | if (!cachefile.exists()) |
---|
8388 | 8543 | { |
---|
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)) |
---|
| 8544 | + //if (texturedata.getWidth() == texturedata.getHeight()) |
---|
8398 | 8545 | { |
---|
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); |
---|
| 8546 | + BufferedImage rendImage = CreateBim(texturedata); |
---|
| 8547 | + |
---|
8429 | 8548 | ImageWriter writer = null; |
---|
8430 | 8549 | Iterator iter = ImageIO.getImageWritersByFormatName("jpg"); |
---|
8431 | 8550 | if (iter.hasNext()) { |
---|
8432 | 8551 | writer = (ImageWriter)iter.next(); |
---|
8433 | 8552 | } |
---|
8434 | | - float compressionQuality = 0.9f; |
---|
| 8553 | + |
---|
| 8554 | + float compressionQuality = 0.85f; |
---|
8435 | 8555 | try |
---|
8436 | 8556 | { |
---|
8437 | 8557 | ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile); |
---|
.. | .. |
---|
8448 | 8568 | } |
---|
8449 | 8569 | } |
---|
8450 | 8570 | } |
---|
8451 | | - |
---|
| 8571 | + |
---|
| 8572 | + Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment; |
---|
| 8573 | + |
---|
8452 | 8574 | //System.out.println("Texture = " + tex); |
---|
8453 | | - if (textures.containsKey(texname)) |
---|
| 8575 | + if (textures.containsKey(tex)) |
---|
8454 | 8576 | { |
---|
8455 | | - CacheTexture thetex = textures.get(texname); |
---|
| 8577 | + CacheTexture thetex = textures.get(tex); |
---|
8456 | 8578 | thetex.texture.disable(); |
---|
8457 | 8579 | thetex.texture.dispose(); |
---|
8458 | | - textures.remove(texname); |
---|
| 8580 | + textures.remove(tex); |
---|
8459 | 8581 | } |
---|
8460 | 8582 | |
---|
8461 | | - texture.texturedata = texturedata; |
---|
8462 | | - textures.put(texname, texture); |
---|
| 8583 | + //texture.texturedata = texturedata; |
---|
| 8584 | + textures.put(tex, texturecache); |
---|
8463 | 8585 | |
---|
8464 | 8586 | // newtex = true; |
---|
8465 | 8587 | } |
---|
.. | .. |
---|
8475 | 8597 | } |
---|
8476 | 8598 | } |
---|
8477 | 8599 | |
---|
8478 | | - return texture; |
---|
| 8600 | + return texturecache; |
---|
8479 | 8601 | } |
---|
8480 | 8602 | |
---|
8481 | | - com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution) throws Exception |
---|
| 8603 | + static void EmbedTextures(cTexture tex) |
---|
| 8604 | + { |
---|
| 8605 | + if (tex.pigmentdata == null) |
---|
| 8606 | + { |
---|
| 8607 | + //String texname = Object3D.GetPigment(tex); |
---|
| 8608 | + |
---|
| 8609 | + CacheTexture texturecache = texturepigment.get(tex); |
---|
| 8610 | + |
---|
| 8611 | + if (texturecache != null) |
---|
| 8612 | + { |
---|
| 8613 | + tex.pw = texturecache.texturedata.getWidth(); |
---|
| 8614 | + tex.ph = texturecache.texturedata.getHeight(); |
---|
| 8615 | + tex.pigmentdata = //CompressJPEG(CreateBim |
---|
| 8616 | + ((ByteBuffer)texturecache.texturedata.getBuffer()).array() |
---|
| 8617 | + ; |
---|
| 8618 | + //, tex.pw, tex.ph), 0.5f); |
---|
| 8619 | + } |
---|
| 8620 | + } |
---|
| 8621 | + |
---|
| 8622 | + if (tex.bumpdata == null) |
---|
| 8623 | + { |
---|
| 8624 | + //String texname = Object3D.GetBump(tex); |
---|
| 8625 | + |
---|
| 8626 | + CacheTexture texturecache = texturebump.get(tex); |
---|
| 8627 | + |
---|
| 8628 | + if (texturecache != null) |
---|
| 8629 | + { |
---|
| 8630 | + tex.bw = texturecache.texturedata.getWidth(); |
---|
| 8631 | + tex.bh = texturecache.texturedata.getHeight(); |
---|
| 8632 | + tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f); |
---|
| 8633 | + } |
---|
| 8634 | + } |
---|
| 8635 | + } |
---|
| 8636 | + |
---|
| 8637 | + com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8482 | 8638 | { |
---|
8483 | 8639 | CacheTexture texture = GetCacheTexture(tex, bump, resolution); |
---|
8484 | 8640 | |
---|
.. | .. |
---|
8496 | 8652 | return texture!=null?texture.texture:null; |
---|
8497 | 8653 | } |
---|
8498 | 8654 | |
---|
8499 | | - public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution) throws Exception |
---|
| 8655 | + public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8500 | 8656 | { |
---|
8501 | 8657 | CacheTexture texture = GetCacheTexture(tex, bump, resolution); |
---|
8502 | 8658 | |
---|
8503 | 8659 | return texture!=null?texture.texturedata:null; |
---|
8504 | 8660 | } |
---|
8505 | 8661 | |
---|
8506 | | - boolean BindTexture(String tex, boolean bump, int resolution) throws Exception |
---|
| 8662 | + boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8507 | 8663 | { |
---|
8508 | 8664 | if (/*tex == null ||*/ ambientOcclusion ) // || !textureon) |
---|
8509 | 8665 | { |
---|
8510 | 8666 | return false; |
---|
8511 | 8667 | } |
---|
8512 | 8668 | |
---|
8513 | | - boolean newtex = false; |
---|
| 8669 | + //boolean newtex = false; |
---|
8514 | 8670 | |
---|
8515 | 8671 | com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution); |
---|
8516 | 8672 | |
---|
.. | .. |
---|
8542 | 8698 | texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT); |
---|
8543 | 8699 | texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT); |
---|
8544 | 8700 | |
---|
8545 | | - return newtex; |
---|
| 8701 | + return true; // Warning: not used. |
---|
8546 | 8702 | } |
---|
8547 | 8703 | |
---|
| 8704 | + public static byte[] CompressJPEG(BufferedImage image, float quality) |
---|
| 8705 | + { |
---|
| 8706 | + try |
---|
| 8707 | + { |
---|
| 8708 | + ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
---|
| 8709 | + Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg"); |
---|
| 8710 | + ImageWriter writer = writers.next(); |
---|
| 8711 | + |
---|
| 8712 | + ImageWriteParam param = writer.getDefaultWriteParam(); |
---|
| 8713 | + param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); |
---|
| 8714 | + param.setCompressionQuality(quality); |
---|
| 8715 | + |
---|
| 8716 | + ImageOutputStream ios = ImageIO.createImageOutputStream(baos); |
---|
| 8717 | + writer.setOutput(ios); |
---|
| 8718 | + writer.write(null, new IIOImage(image, null, null), param); |
---|
| 8719 | + |
---|
| 8720 | + byte[] data = baos.toByteArray(); |
---|
| 8721 | + writer.dispose(); |
---|
| 8722 | + return data; |
---|
| 8723 | + } |
---|
| 8724 | + catch (Exception e) |
---|
| 8725 | + { |
---|
| 8726 | + e.printStackTrace(); |
---|
| 8727 | + return null; |
---|
| 8728 | + } |
---|
| 8729 | + } |
---|
| 8730 | + |
---|
| 8731 | + public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException |
---|
| 8732 | + { |
---|
| 8733 | + ByteArrayInputStream baos = new ByteArrayInputStream(image); |
---|
| 8734 | + Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg"); |
---|
| 8735 | + ImageReader reader = writers.next(); |
---|
| 8736 | + |
---|
| 8737 | + BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); |
---|
| 8738 | + |
---|
| 8739 | + ImageReadParam param = reader.getDefaultReadParam(); |
---|
| 8740 | + param.setDestination(bim); |
---|
| 8741 | + //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB)); |
---|
| 8742 | + |
---|
| 8743 | + ImageInputStream ios = ImageIO.createImageInputStream(baos); |
---|
| 8744 | + reader.setInput(ios); |
---|
| 8745 | + BufferedImage bim2 = reader.read(0, param); |
---|
| 8746 | + reader.dispose(); |
---|
| 8747 | + |
---|
| 8748 | +// WritableRaster raster = bim2.getRaster(); |
---|
| 8749 | +// DataBufferByte data = (DataBufferByte) raster.getDataBuffer(); |
---|
| 8750 | +// byte[] bytes = data.getData(); |
---|
| 8751 | +// |
---|
| 8752 | +// int[] pixels = new int[bytes.length/3]; |
---|
| 8753 | +// for (int i=pixels.length; --i>=0;) |
---|
| 8754 | +// { |
---|
| 8755 | +// int i3 = i*3; |
---|
| 8756 | +// pixels[i] = 0xFF; |
---|
| 8757 | +// pixels[i] <<= 8; |
---|
| 8758 | +// pixels[i] |= bytes[i3+2] & 0xFF; |
---|
| 8759 | +// pixels[i] <<= 8; |
---|
| 8760 | +// pixels[i] |= bytes[i3+1] & 0xFF; |
---|
| 8761 | +// pixels[i] <<= 8; |
---|
| 8762 | +// pixels[i] |= bytes[i3] & 0xFF; |
---|
| 8763 | +// } |
---|
| 8764 | +// |
---|
| 8765 | +// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w); |
---|
| 8766 | + |
---|
| 8767 | + return bim; |
---|
| 8768 | + } |
---|
| 8769 | + |
---|
8548 | 8770 | ShadowBuffer shadowPBuf; |
---|
8549 | 8771 | AntialiasBuffer antialiasPBuf; |
---|
8550 | 8772 | int MAXSTACK; |
---|
.. | .. |
---|
8561 | 8783 | |
---|
8562 | 8784 | gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0); |
---|
8563 | 8785 | MAXSTACK = temp[0]; |
---|
8564 | | - System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK); |
---|
| 8786 | + if (Globals.DEBUG) |
---|
| 8787 | + System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK); |
---|
8565 | 8788 | gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0); |
---|
8566 | 8789 | MAXSTACK = temp[0]; |
---|
8567 | | - System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK); |
---|
| 8790 | + if (Globals.DEBUG) |
---|
| 8791 | + System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK); |
---|
8568 | 8792 | |
---|
8569 | 8793 | // Use debug pipeline |
---|
8570 | 8794 | //drawable.setGL(new DebugGL(gl)); // |
---|
.. | .. |
---|
8572 | 8796 | gl = drawable.getGL(); // |
---|
8573 | 8797 | |
---|
8574 | 8798 | GL gl3 = getGL(); |
---|
8575 | | - System.out.println("INIT GL IS: " + gl.getClass().getName()); |
---|
| 8799 | + if (Globals.DEBUG) |
---|
| 8800 | + System.out.println("INIT GL IS: " + gl.getClass().getName()); |
---|
8576 | 8801 | |
---|
8577 | 8802 | |
---|
8578 | 8803 | //float pos[] = { 100, 100, 100, 0 }; |
---|
.. | .. |
---|
8737 | 8962 | |
---|
8738 | 8963 | if (cubemap == null) |
---|
8739 | 8964 | { |
---|
8740 | | - LoadEnvy(5); |
---|
| 8965 | + //LoadEnvy(1); |
---|
8741 | 8966 | } |
---|
8742 | 8967 | |
---|
8743 | 8968 | //cubemap.enable(); |
---|
.. | .. |
---|
9013 | 9238 | |
---|
9014 | 9239 | void LoadEnvy(int which) |
---|
9015 | 9240 | { |
---|
| 9241 | + assert(false); |
---|
| 9242 | + |
---|
9016 | 9243 | String name; |
---|
9017 | 9244 | String ext; |
---|
9018 | 9245 | |
---|
.. | .. |
---|
9024 | 9251 | cubemap = null; |
---|
9025 | 9252 | return; |
---|
9026 | 9253 | case 1: |
---|
9027 | | - name = "cubemaps/box_"; |
---|
9028 | | - ext = "png"; |
---|
| 9254 | + name = "cubemaps/rgb/"; |
---|
| 9255 | + ext = "jpg"; |
---|
9029 | 9256 | reverseUP = false; |
---|
9030 | 9257 | break; |
---|
9031 | 9258 | case 2: |
---|
9032 | | - name = "cubemaps/uffizi_"; |
---|
9033 | | - ext = "png"; |
---|
9034 | | - break; // reverseUP = true; break; |
---|
| 9259 | + name = "cubemaps/uffizi/"; |
---|
| 9260 | + ext = "jpg"; |
---|
| 9261 | + reverseUP = false; |
---|
| 9262 | + break; |
---|
9035 | 9263 | case 3: |
---|
9036 | | - name = "cubemaps/CloudyHills_"; |
---|
9037 | | - ext = "tga"; |
---|
| 9264 | + name = "cubemaps/CloudyHills/"; |
---|
| 9265 | + ext = "jpg"; |
---|
9038 | 9266 | reverseUP = false; |
---|
9039 | 9267 | break; |
---|
9040 | 9268 | case 4: |
---|
9041 | | - name = "cubemaps/cornell_"; |
---|
| 9269 | + name = "cubemaps/cornell/"; |
---|
9042 | 9270 | ext = "png"; |
---|
9043 | 9271 | reverseUP = false; |
---|
9044 | 9272 | break; |
---|
| 9273 | + case 5: |
---|
| 9274 | + name = "cubemaps/skycube/"; |
---|
| 9275 | + ext = "jpg"; |
---|
| 9276 | + reverseUP = false; |
---|
| 9277 | + break; |
---|
| 9278 | + case 6: |
---|
| 9279 | + name = "cubemaps/SaintLazarusChurch3/"; |
---|
| 9280 | + ext = "jpg"; |
---|
| 9281 | + reverseUP = false; |
---|
| 9282 | + break; |
---|
| 9283 | + case 7: |
---|
| 9284 | + name = "cubemaps/Sodermalmsallen/"; |
---|
| 9285 | + ext = "jpg"; |
---|
| 9286 | + reverseUP = false; |
---|
| 9287 | + break; |
---|
| 9288 | + case 8: |
---|
| 9289 | + name = "cubemaps/Sodermalmsallen2/"; |
---|
| 9290 | + ext = "jpg"; |
---|
| 9291 | + reverseUP = false; |
---|
| 9292 | + break; |
---|
| 9293 | + case 9: |
---|
| 9294 | + name = "cubemaps/UnionSquare/"; |
---|
| 9295 | + ext = "jpg"; |
---|
| 9296 | + reverseUP = false; |
---|
| 9297 | + break; |
---|
9045 | 9298 | default: |
---|
9046 | | - name = "cubemaps/rgb_"; |
---|
9047 | | - ext = "png"; /*mipmap = true;*/ reverseUP = false; |
---|
| 9299 | + name = "cubemaps/box/"; |
---|
| 9300 | + ext = "png"; /*mipmap = true;*/ |
---|
| 9301 | + reverseUP = false; |
---|
9048 | 9302 | break; |
---|
9049 | 9303 | } |
---|
9050 | | - |
---|
9051 | | - try |
---|
9052 | | - { |
---|
9053 | | - cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap); |
---|
9054 | | - } catch (IOException e) |
---|
9055 | | - { |
---|
9056 | | - throw new RuntimeException(e); |
---|
9057 | | - } |
---|
| 9304 | + |
---|
| 9305 | + LoadSkybox(name, ext, mipmap); |
---|
9058 | 9306 | } |
---|
9059 | 9307 | |
---|
9060 | 9308 | public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) |
---|
.. | .. |
---|
9086 | 9334 | static double[] model = new double[16]; |
---|
9087 | 9335 | double[] camera2light = new double[16]; |
---|
9088 | 9336 | double[] light2camera = new double[16]; |
---|
9089 | | - int newenvy = -1; |
---|
9090 | | - boolean envyoff = true; // false; |
---|
| 9337 | + |
---|
| 9338 | + //int newenvy = -1; |
---|
| 9339 | + //boolean envyoff = false; |
---|
| 9340 | + |
---|
| 9341 | + String loadedskyboxname; |
---|
| 9342 | + |
---|
9091 | 9343 | cVector light0 = new cVector(0, 0, 0); // 1,3,2); |
---|
9092 | 9344 | //float[] light0 = { 0,0,0 }; |
---|
9093 | 9345 | cVector dirlight = new cVector(0, 0, 1); // 1,3,2); |
---|
.. | .. |
---|
9505 | 9757 | |
---|
9506 | 9758 | if (renderCamera != lightCamera) |
---|
9507 | 9759 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
9508 | | - LA.matConcat(matrix, parentcam.GlobalTransform(), matrix); |
---|
| 9760 | + LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix); |
---|
9509 | 9761 | |
---|
9510 | 9762 | // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix); |
---|
9511 | 9763 | |
---|
.. | .. |
---|
9521 | 9773 | |
---|
9522 | 9774 | if (renderCamera != lightCamera) |
---|
9523 | 9775 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
9524 | | - LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix); |
---|
| 9776 | + LA.matConcat(parentcam.GlobalTransform(), matrix, matrix); |
---|
9525 | 9777 | |
---|
9526 | 9778 | // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix); |
---|
9527 | 9779 | |
---|
.. | .. |
---|
9567 | 9819 | rati = 1 / rati; |
---|
9568 | 9820 | gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000); |
---|
9569 | 9821 | } |
---|
9570 | | - assert (newenvy == -1); |
---|
| 9822 | + |
---|
| 9823 | + //assert (newenvy == -1); |
---|
| 9824 | + |
---|
9571 | 9825 | gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
9572 | 9826 | gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB); |
---|
9573 | | - DrawSkyBox(gl); |
---|
| 9827 | + DrawSkyBox(gl, (float)rati); |
---|
9574 | 9828 | gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
9575 | 9829 | gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB); |
---|
9576 | 9830 | accPerspective(gl, renderCamera.shaper_fovy / ratio, |
---|
.. | .. |
---|
10607 | 10861 | |
---|
10608 | 10862 | if (wait) |
---|
10609 | 10863 | { |
---|
10610 | | - Sleep(500); |
---|
| 10864 | + Sleep(200); // blocks everything |
---|
10611 | 10865 | |
---|
10612 | 10866 | wait = false; |
---|
10613 | 10867 | } |
---|
.. | .. |
---|
10722 | 10976 | // if (parentcam != renderCamera) // not a light |
---|
10723 | 10977 | if (cam != lightCamera) |
---|
10724 | 10978 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
10725 | | - LA.matConcat(matrix, parentcam.GlobalTransform(), matrix); |
---|
| 10979 | + LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix); |
---|
10726 | 10980 | |
---|
10727 | 10981 | for (int j = 0; j < 4; j++) |
---|
10728 | 10982 | { |
---|
.. | .. |
---|
10737 | 10991 | // if (parentcam != renderCamera) // not a light |
---|
10738 | 10992 | if (cam != lightCamera) |
---|
10739 | 10993 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
10740 | | - LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix); |
---|
| 10994 | + LA.matConcat(parentcam.GlobalTransform(), matrix, matrix); |
---|
10741 | 10995 | |
---|
10742 | 10996 | //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix); |
---|
10743 | 10997 | |
---|
.. | .. |
---|
10823 | 11077 | gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000); |
---|
10824 | 11078 | } |
---|
10825 | 11079 | |
---|
10826 | | - if (newenvy > -1) |
---|
| 11080 | +// if (newenvy > -1) |
---|
| 11081 | +// { |
---|
| 11082 | +// LoadEnvy(newenvy); |
---|
| 11083 | +// } |
---|
| 11084 | +// |
---|
| 11085 | +// newenvy = -1; |
---|
| 11086 | + |
---|
| 11087 | + if (transformMode) // object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb")) |
---|
10827 | 11088 | { |
---|
10828 | | - LoadEnvy(newenvy); |
---|
| 11089 | + if (cubemaprgb == null) |
---|
| 11090 | + { |
---|
| 11091 | + cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb2" + "/", "jpg", false); |
---|
| 11092 | + } |
---|
| 11093 | + |
---|
| 11094 | + cubemap = cubemaprgb; |
---|
10829 | 11095 | } |
---|
10830 | | - |
---|
10831 | | - newenvy = -1; |
---|
10832 | | - |
---|
| 11096 | + else |
---|
| 11097 | + { |
---|
| 11098 | + if (object.skyboxname != null) |
---|
| 11099 | + { |
---|
| 11100 | + if (!object.skyboxname.equals(this.loadedskyboxname)) |
---|
| 11101 | + { |
---|
| 11102 | + if (cubemap != null && cubemap != cubemaprgb) |
---|
| 11103 | + cubemap.dispose(); |
---|
| 11104 | + cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false); |
---|
| 11105 | + loadedskyboxname = object.skyboxname; |
---|
| 11106 | + } |
---|
| 11107 | + } |
---|
| 11108 | + else |
---|
| 11109 | + { |
---|
| 11110 | + cubemapcustom = null; |
---|
| 11111 | + loadedskyboxname = null; |
---|
| 11112 | + } |
---|
| 11113 | + |
---|
| 11114 | + cubemap = cubemapcustom; |
---|
| 11115 | + } |
---|
| 11116 | + |
---|
10833 | 11117 | ratio = ((double) getWidth()) / getHeight(); |
---|
10834 | 11118 | //System.out.println("ratio = " + ratio); |
---|
10835 | 11119 | |
---|
.. | .. |
---|
10845 | 11129 | |
---|
10846 | 11130 | if (!IsFrozen() && !ambientOcclusion) |
---|
10847 | 11131 | { |
---|
10848 | | - DrawSkyBox(gl); |
---|
| 11132 | + DrawSkyBox(gl, (float)ratio); |
---|
10849 | 11133 | } |
---|
10850 | 11134 | |
---|
10851 | 11135 | //if (selection_view == -1) |
---|
.. | .. |
---|
11028 | 11312 | |
---|
11029 | 11313 | gl.glMatrixMode(GL.GL_MODELVIEW); |
---|
11030 | 11314 | |
---|
11031 | | -//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST); |
---|
11032 | | -//gl.glEnable(gl.GL_POLYGON_SMOOTH); |
---|
11033 | | -//gl.glEnable(gl.GL_MULTISAMPLE); |
---|
| 11315 | +gl.glEnable(gl.GL_POLYGON_SMOOTH); |
---|
| 11316 | +gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST); |
---|
| 11317 | +gl.glEnable(gl.GL_MULTISAMPLE); |
---|
11034 | 11318 | } else |
---|
11035 | 11319 | { |
---|
11036 | 11320 | //gl.glDisable(GL.GL_TEXTURE_2D); |
---|
.. | .. |
---|
11041 | 11325 | //System.out.println("BLENDING ON"); |
---|
11042 | 11326 | gl.glEnable(GL.GL_BLEND); |
---|
11043 | 11327 | gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); |
---|
11044 | | - |
---|
| 11328 | +// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE); |
---|
11045 | 11329 | gl.glMatrixMode(gl.GL_PROJECTION); |
---|
11046 | 11330 | gl.glLoadIdentity(); |
---|
11047 | 11331 | |
---|
.. | .. |
---|
11131 | 11415 | |
---|
11132 | 11416 | // if (cam != lightCamera) |
---|
11133 | 11417 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
11134 | | - LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013 |
---|
| 11418 | + LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013 |
---|
11135 | 11419 | } |
---|
11136 | 11420 | |
---|
11137 | 11421 | LA.xformDir(lightposition, cam.toScreen, lightposition); |
---|
.. | .. |
---|
11290 | 11574 | } |
---|
11291 | 11575 | } |
---|
11292 | 11576 | |
---|
11293 | | - if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion) |
---|
| 11577 | + if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion) |
---|
11294 | 11578 | { |
---|
11295 | 11579 | //gl.glDepthFunc(GL.GL_LEQUAL); |
---|
11296 | 11580 | //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT); |
---|
.. | .. |
---|
11298 | 11582 | |
---|
11299 | 11583 | boolean texon = textureon; |
---|
11300 | 11584 | |
---|
11301 | | - if (RENDERPROGRAM > 0) |
---|
11302 | | - { |
---|
11303 | | - gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
11304 | | - textureon = false; |
---|
11305 | | - } |
---|
| 11585 | + gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
| 11586 | + textureon = false; |
---|
| 11587 | + |
---|
11306 | 11588 | //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB); |
---|
11307 | 11589 | //System.out.println("ALLO"); |
---|
11308 | 11590 | gl.glColorMask(false, false, false, false); |
---|
11309 | 11591 | DrawObject(gl); |
---|
11310 | | - if (RENDERPROGRAM > 0) |
---|
11311 | | - { |
---|
11312 | | - gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
11313 | | - textureon = texon; |
---|
11314 | | - } |
---|
| 11592 | + |
---|
| 11593 | + gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
| 11594 | + textureon = texon; |
---|
| 11595 | + |
---|
11315 | 11596 | gl.glColorMask(true, true, true, true); |
---|
11316 | 11597 | |
---|
11317 | 11598 | gl.glDepthFunc(GL.GL_EQUAL); |
---|
11318 | | - //gl.glDepthMask(false); |
---|
| 11599 | + gl.glDepthMask(false); |
---|
11319 | 11600 | } |
---|
11320 | 11601 | |
---|
11321 | 11602 | if (false) // DrawMode() == SHADOW) |
---|
.. | .. |
---|
11527 | 11808 | if ((TRACK || SHADOWTRACK) || zoomonce) |
---|
11528 | 11809 | { |
---|
11529 | 11810 | if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode) |
---|
11530 | | - object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK); |
---|
| 11811 | + object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK); |
---|
11531 | 11812 | pingthread.StepToTarget(true); // true); |
---|
11532 | 11813 | // zoomonce = false; |
---|
11533 | 11814 | } |
---|
.. | .. |
---|
11655 | 11936 | ReleaseTextures(DEFAULT_TEXTURES); |
---|
11656 | 11937 | |
---|
11657 | 11938 | if (CLEANCACHE) |
---|
11658 | | - for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();) |
---|
| 11939 | + for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();) |
---|
11659 | 11940 | { |
---|
11660 | | - String tex = e.nextElement(); |
---|
| 11941 | + cTexture tex = e.nextElement(); |
---|
11661 | 11942 | |
---|
11662 | 11943 | // System.out.println("Texture --------- " + tex); |
---|
11663 | 11944 | |
---|
11664 | | - if (tex.equals("WHITE_NOISE")) |
---|
| 11945 | + if (tex.equals("WHITE_NOISE:")) |
---|
11665 | 11946 | continue; |
---|
11666 | 11947 | |
---|
11667 | | - if (!usedtextures.containsKey(tex)) |
---|
| 11948 | + if (!usedtextures.contains(tex)) |
---|
11668 | 11949 | { |
---|
| 11950 | + CacheTexture gettex = texturepigment.get(tex); |
---|
11669 | 11951 | // System.out.println("DISPOSE +++++++++++++++ " + tex); |
---|
11670 | | - textures.get(tex).texture.dispose(); |
---|
11671 | | - textures.remove(tex); |
---|
| 11952 | + if (gettex != null) |
---|
| 11953 | + { |
---|
| 11954 | + gettex.texture.dispose(); |
---|
| 11955 | + texturepigment.remove(tex); |
---|
| 11956 | + } |
---|
| 11957 | + |
---|
| 11958 | + gettex = texturebump.get(tex); |
---|
| 11959 | + // System.out.println("DISPOSE +++++++++++++++ " + tex); |
---|
| 11960 | + if (gettex != null) |
---|
| 11961 | + { |
---|
| 11962 | + gettex.texture.dispose(); |
---|
| 11963 | + texturebump.remove(tex); |
---|
| 11964 | + } |
---|
11672 | 11965 | } |
---|
11673 | 11966 | } |
---|
11674 | 11967 | } |
---|
.. | .. |
---|
12196 | 12489 | |
---|
12197 | 12490 | //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0); |
---|
12198 | 12491 | |
---|
12199 | | - String program = |
---|
| 12492 | + String programmin = |
---|
| 12493 | + // Min shader |
---|
12200 | 12494 | "!!ARBfp1.0\n" + |
---|
| 12495 | + "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" + |
---|
| 12496 | + "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" + |
---|
| 12497 | + "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" + |
---|
| 12498 | + "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" + |
---|
| 12499 | + "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" + |
---|
| 12500 | + "PARAM light2cam0 = program.env[10];" + |
---|
| 12501 | + "PARAM light2cam1 = program.env[11];" + |
---|
| 12502 | + "PARAM light2cam2 = program.env[12];" + |
---|
| 12503 | + "TEMP temp;" + |
---|
| 12504 | + "TEMP light;" + |
---|
| 12505 | + "TEMP ndotl;" + |
---|
| 12506 | + "TEMP normal;" + |
---|
| 12507 | + "TEMP depth;" + |
---|
| 12508 | + "TEMP eye;" + |
---|
| 12509 | + "TEMP pos;" + |
---|
| 12510 | + |
---|
| 12511 | + "MAD normal, fragment.color, zero123.z, -zero123.y;" + |
---|
| 12512 | + Normalize("normal") + |
---|
| 12513 | + "MOV light, state.light[0].position;" + |
---|
| 12514 | + "DP3 ndotl.x, light, normal;" + |
---|
| 12515 | + |
---|
| 12516 | + // shadow |
---|
| 12517 | + "MOV pos, fragment.texcoord[1];" + |
---|
| 12518 | + "MOV temp, pos;" + |
---|
| 12519 | + ShadowTextureFetch("depth", "temp", "1") + |
---|
| 12520 | + //"TEX depth, fragment.texcoord[1], texture[1], 2D;" + |
---|
| 12521 | + "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" + |
---|
| 12522 | + |
---|
| 12523 | + // No shadow when out of frustum |
---|
| 12524 | + //"SGE temp.y, depth.z, zero123.y;" + |
---|
| 12525 | + //"LRP temp.x, temp.y, zero123.y, temp.x;" + |
---|
| 12526 | + |
---|
| 12527 | + "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow |
---|
| 12528 | + |
---|
| 12529 | + // Backlit |
---|
| 12530 | + "MOV pos.w, zero123.y;" + |
---|
| 12531 | + "DP4 eye.x, pos, light2cam0;" + |
---|
| 12532 | + "DP4 eye.y, pos, light2cam1;" + |
---|
| 12533 | + "DP4 eye.z, pos, light2cam2;" + |
---|
| 12534 | + Normalize("eye") + |
---|
| 12535 | + |
---|
| 12536 | + "DP3 ndotl.y, -eye, normal;" + |
---|
| 12537 | + //"MUL ndotl.y, ndotl.y, pow2.x;" + |
---|
| 12538 | + "POW ndotl.y, ndotl.y, pow2.z;" + // backlit |
---|
| 12539 | + "SUB ndotl.y, zero123.y, ndotl.y;" + |
---|
| 12540 | + //"SUB ndotl.y, zero123.y, ndotl.y;" + |
---|
| 12541 | + //"MUL ndotl.y, ndotl.y, pow2.z;" + |
---|
| 12542 | + |
---|
| 12543 | + //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient |
---|
| 12544 | + //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient |
---|
| 12545 | + |
---|
| 12546 | + // Pigment |
---|
| 12547 | + "TEX temp, fragment.texcoord[0], texture[0], 2D;" + |
---|
| 12548 | + "LRP temp, zero123.w, temp, one;" + // texture proportion |
---|
| 12549 | + "MUL temp, temp, ndotl.x;" + |
---|
| 12550 | + |
---|
| 12551 | + "MUL temp, temp, zero123.z;" + |
---|
| 12552 | + |
---|
| 12553 | + //"MUL temp, temp, ndotl.y;" + |
---|
| 12554 | + |
---|
| 12555 | + "MOV temp.w, zero123.y;" + // reset alpha |
---|
| 12556 | + "MOV result.color, temp;" + |
---|
| 12557 | + "END"; |
---|
| 12558 | + |
---|
| 12559 | + String programmax = |
---|
| 12560 | + "!!ARBfp1.0\n" + |
---|
| 12561 | + |
---|
12201 | 12562 | //"OPTION ARB_fragment_program_shadow;" + |
---|
12202 | 12563 | "PARAM light2cam0 = program.env[10];" + |
---|
12203 | 12564 | "PARAM light2cam1 = program.env[11];" + |
---|
.. | .. |
---|
12312 | 12673 | "TEMP shininess;" + |
---|
12313 | 12674 | "\n" + |
---|
12314 | 12675 | "MOV texSamp, one;" + |
---|
12315 | | - //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" + |
---|
12316 | | - |
---|
| 12676 | + |
---|
12317 | 12677 | "MOV mapgrid.x, one2048th.x;" + |
---|
12318 | 12678 | "MOV temp, fragment.texcoord[1];" + |
---|
12319 | 12679 | /* |
---|
.. | .. |
---|
12334 | 12694 | "MUL temp, floor, mapgrid.x;" + |
---|
12335 | 12695 | //"TEX depth0, temp, texture[1], 2D;" + |
---|
12336 | 12696 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12337 | | - TextureFetch("depth0", "temp", "1") + |
---|
| 12697 | + ShadowTextureFetch("depth0", "temp", "1") + |
---|
12338 | 12698 | "") + |
---|
12339 | 12699 | "ADD temp.x, temp.x, mapgrid.x;" + |
---|
12340 | 12700 | //"TEX depth1, temp, texture[1], 2D;" + |
---|
12341 | 12701 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12342 | | - TextureFetch("depth1", "temp", "1") + |
---|
| 12702 | + ShadowTextureFetch("depth1", "temp", "1") + |
---|
12343 | 12703 | "") + |
---|
12344 | 12704 | "ADD temp.y, temp.y, mapgrid.x;" + |
---|
12345 | 12705 | //"TEX depth2, temp, texture[1], 2D;" + |
---|
12346 | | - TextureFetch("depth2", "temp", "1") + |
---|
| 12706 | + ShadowTextureFetch("depth2", "temp", "1") + |
---|
12347 | 12707 | "SUB temp.x, temp.x, mapgrid.x;" + |
---|
12348 | 12708 | //"TEX depth3, temp, texture[1], 2D;" + |
---|
12349 | 12709 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12350 | | - TextureFetch("depth3", "temp", "1") + |
---|
| 12710 | + ShadowTextureFetch("depth3", "temp", "1") + |
---|
12351 | 12711 | "") + |
---|
12352 | 12712 | //"MUL texSamp0, texSamp0, state.material.front.diffuse;" + |
---|
12353 | 12713 | //"MOV params, material;" + |
---|
.. | .. |
---|
12718 | 13078 | "MAD shadow.x, buffer.x, frac.y, shadow.x;" + |
---|
12719 | 13079 | "") + |
---|
12720 | 13080 | |
---|
12721 | | - // display shadow only (bump == 0) |
---|
| 13081 | + // display shadow only (fakedepth == 0) |
---|
12722 | 13082 | "SUB temp.x, half.x, shadow.x;" + |
---|
12723 | 13083 | "MOV temp.y, -params5.z;" + // params6.x;" + |
---|
12724 | | - "SLT temp.z, temp.y, -one2048th.x;" + |
---|
| 13084 | + "SLT temp.z, temp.y, -c256i.x;" + |
---|
12725 | 13085 | "SUB temp.y, one.x, temp.z;" + |
---|
12726 | 13086 | "MUL temp.x, temp.x, temp.y;" + |
---|
12727 | 13087 | "KIL temp.x;" + |
---|
.. | .. |
---|
13052 | 13412 | //once = true; |
---|
13053 | 13413 | } |
---|
13054 | 13414 | |
---|
13055 | | - System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length()); |
---|
13056 | | - System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : "")); |
---|
| 13415 | + String program = programmax; |
---|
| 13416 | + |
---|
| 13417 | + if (Globals.MINSHADER) |
---|
| 13418 | + { |
---|
| 13419 | + program = programmin; |
---|
| 13420 | + } |
---|
| 13421 | + |
---|
| 13422 | + if (Globals.DEBUG) |
---|
| 13423 | + { |
---|
| 13424 | + System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length()); |
---|
| 13425 | + System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : "")); |
---|
| 13426 | + } |
---|
| 13427 | + |
---|
13057 | 13428 | loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program); |
---|
13058 | 13429 | |
---|
13059 | 13430 | //gl.glNewList(displayListID, GL.GL_COMPILE); |
---|
.. | .. |
---|
13100 | 13471 | "\n" + |
---|
13101 | 13472 | "END\n"; |
---|
13102 | 13473 | |
---|
13103 | | - System.out.println("Program shadow #" + 0 + "; length = " + program.length()); |
---|
| 13474 | + if (Globals.DEBUG) |
---|
| 13475 | + System.out.println("Program shadow #" + 0 + "; length = " + program.length()); |
---|
13104 | 13476 | loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program); |
---|
13105 | 13477 | |
---|
13106 | 13478 | //gl.glNewList(displayListID, GL.GL_COMPILE); |
---|
.. | .. |
---|
13145 | 13517 | return out; |
---|
13146 | 13518 | } |
---|
13147 | 13519 | |
---|
13148 | | - String TextureFetch(String dest, String src, String unit) |
---|
| 13520 | + // Also does frustum culling |
---|
| 13521 | + String ShadowTextureFetch(String dest, String src, String unit) |
---|
13149 | 13522 | { |
---|
13150 | 13523 | return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" + |
---|
13151 | 13524 | "SGE " + src + ".w, " + src + ".x, eps.x;" + |
---|
13152 | 13525 | "SGE " + src + ".z, " + src + ".y, eps.x;" + |
---|
| 13526 | + "SLT " + dest + ".x, " + src + ".x, one.x;" + |
---|
| 13527 | + "SLT " + dest + ".y, " + src + ".y, one.x;" + |
---|
13153 | 13528 | "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;" + |
---|
| 13529 | + "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" + |
---|
| 13530 | + "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" + |
---|
13158 | 13531 | //"SWZ buffer, temp, w,w,w,w;"; |
---|
13159 | | - "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" + |
---|
| 13532 | + //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" + |
---|
13160 | 13533 | "SUB " + src + ".z, " + "one.x, " + src + ".w;" + |
---|
13161 | 13534 | //"MUL " + src + ".z, " + src + ".z, infinity.x;" + |
---|
13162 | 13535 | //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;"; |
---|
13163 | | - "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
| 13536 | + //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
13164 | 13537 | |
---|
13165 | | - //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;"; |
---|
13166 | | - //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;"; |
---|
| 13538 | + //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;"; |
---|
| 13539 | + "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
13167 | 13540 | } |
---|
13168 | 13541 | |
---|
13169 | 13542 | String Shadow(String depth, String shadow) |
---|
.. | .. |
---|
13210 | 13583 | "SLT temp.x, temp.x, zero.x;" + // shadoweps |
---|
13211 | 13584 | "LRP " + shadow + ", temp.x, one, " + shadow + ";" + |
---|
13212 | 13585 | |
---|
13213 | | - // No shadow when out of frustrum |
---|
| 13586 | + // No shadow when out of frustum |
---|
13214 | 13587 | "SGE temp.x, " + depth + ".z, one.z;" + |
---|
13215 | 13588 | "LRP " + shadow + ", temp.x, one, " + shadow + ";" + |
---|
13216 | 13589 | ""; |
---|
.. | .. |
---|
13375 | 13748 | "DP3 " + dest + ".z," + "normals," + "eye;" + |
---|
13376 | 13749 | "MAX " + dest + ".w," + dest + ".z," + "eps.x;" + |
---|
13377 | 13750 | //"MOV " + dest + ".w," + "normal.z;" + |
---|
13378 | | - "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + |
---|
13379 | | - "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" + |
---|
13380 | | - //"MOV " + dest + ".z," + "params2.w;" + |
---|
| 13751 | +// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET |
---|
| 13752 | +// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" + |
---|
| 13753 | + |
---|
| 13754 | + "MOV " + dest + ".z," + "params2.w;" + // EXACT |
---|
13381 | 13755 | "POW " + dest + ".w," + dest + ".w," + dest + ".z;" + |
---|
13382 | 13756 | "RCP " + dest + ".w," + dest + ".w;" + |
---|
13383 | 13757 | //"RSQ " + dest + ".w," + dest + ".w;" + |
---|
.. | .. |
---|
13942 | 14316 | |
---|
13943 | 14317 | // fev 2014??? |
---|
13944 | 14318 | if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode) |
---|
13945 | | - object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK); |
---|
| 14319 | + object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK); |
---|
13946 | 14320 | pingthread.StepToTarget(true); // true); |
---|
13947 | 14321 | } |
---|
13948 | 14322 | // if (!LIVE) |
---|
.. | .. |
---|
14007 | 14381 | drag = false; |
---|
14008 | 14382 | //System.out.println("Mouse DOWN"); |
---|
14009 | 14383 | editObj = false; |
---|
14010 | | - ClickInfo info = new ClickInfo(); |
---|
14011 | | - info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
14012 | | - info.pane = this; |
---|
14013 | | - info.camera = renderCamera; |
---|
14014 | | - info.x = x; |
---|
14015 | | - info.y = y; |
---|
14016 | | - info.modifiers = modifiersex; |
---|
14017 | | - editObj = object.doEditClick(info, 0); |
---|
| 14384 | + //ClickInfo info = new ClickInfo(); |
---|
| 14385 | + object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
| 14386 | + object.clickInfo.pane = this; |
---|
| 14387 | + object.clickInfo.camera = renderCamera; |
---|
| 14388 | + object.clickInfo.x = x; |
---|
| 14389 | + object.clickInfo.y = y; |
---|
| 14390 | + object.clickInfo.modifiers = modifiersex; |
---|
| 14391 | + editObj = object.doEditClick(//info, |
---|
| 14392 | + 0); |
---|
14018 | 14393 | if (!editObj) |
---|
14019 | 14394 | { |
---|
14020 | 14395 | hasMarquee = true; |
---|
.. | .. |
---|
14296 | 14671 | void GoDown(int mod) |
---|
14297 | 14672 | { |
---|
14298 | 14673 | MODIFIERS |= COMMAND; |
---|
14299 | | - /* |
---|
| 14674 | + boolean isVR = (mouseMode&VR)!=0; |
---|
| 14675 | + /**/ |
---|
14300 | 14676 | if((mod&SHIFT) == SHIFT) |
---|
14301 | | - manipCamera.RotatePosition(0, -speed); |
---|
| 14677 | + { |
---|
| 14678 | + if (isVR) |
---|
| 14679 | + manipCamera.RotateInterest(0, -speed); |
---|
| 14680 | + else |
---|
| 14681 | + manipCamera.RotatePosition(0, -speed); |
---|
| 14682 | + } |
---|
14302 | 14683 | else |
---|
14303 | | - manipCamera.BackForth(0, -speed*delta, getWidth()); |
---|
14304 | | - */ |
---|
| 14684 | + manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth()); |
---|
| 14685 | + /**/ |
---|
14305 | 14686 | if ((mod & SHIFT) == SHIFT) |
---|
14306 | 14687 | { |
---|
14307 | 14688 | mouseMode = mouseMode; // VR?? |
---|
.. | .. |
---|
14310 | 14691 | mouseMode |= BACKFORTH; |
---|
14311 | 14692 | } |
---|
14312 | 14693 | |
---|
| 14694 | + targetLookAt.set(manipCamera.lookAt); |
---|
| 14695 | + |
---|
14313 | 14696 | //prevX = X = anchorX; |
---|
14314 | 14697 | prevY = Y = anchorY - (int) (renderCamera.Distance()); |
---|
14315 | 14698 | } |
---|
.. | .. |
---|
14317 | 14700 | void GoUp(int mod) |
---|
14318 | 14701 | { |
---|
14319 | 14702 | MODIFIERS |= COMMAND; |
---|
14320 | | - /* |
---|
| 14703 | + /**/ |
---|
| 14704 | + boolean isVR = (mouseMode&VR)!=0; |
---|
| 14705 | + |
---|
14321 | 14706 | if((mod&SHIFT) == SHIFT) |
---|
14322 | | - manipCamera.RotatePosition(0, speed); |
---|
| 14707 | + { |
---|
| 14708 | + if (isVR) |
---|
| 14709 | + manipCamera.RotateInterest(0, speed); |
---|
| 14710 | + else |
---|
| 14711 | + manipCamera.RotatePosition(0, speed); |
---|
| 14712 | + } |
---|
14323 | 14713 | else |
---|
14324 | | - manipCamera.BackForth(0, speed*delta, getWidth()); |
---|
14325 | | - */ |
---|
| 14714 | + manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth()); |
---|
| 14715 | + /**/ |
---|
14326 | 14716 | if ((mod & SHIFT) == SHIFT) |
---|
14327 | 14717 | { |
---|
14328 | 14718 | mouseMode = mouseMode; |
---|
.. | .. |
---|
14331 | 14721 | mouseMode |= BACKFORTH; |
---|
14332 | 14722 | } |
---|
14333 | 14723 | |
---|
| 14724 | + targetLookAt.set(manipCamera.lookAt); |
---|
| 14725 | + |
---|
14334 | 14726 | //prevX = X = anchorX; |
---|
14335 | 14727 | prevY = Y = anchorY + (int) (renderCamera.Distance()); |
---|
14336 | 14728 | } |
---|
.. | .. |
---|
14338 | 14730 | void GoLeft(int mod) |
---|
14339 | 14731 | { |
---|
14340 | 14732 | MODIFIERS |= COMMAND; |
---|
14341 | | - /* |
---|
| 14733 | + /**/ |
---|
14342 | 14734 | if((mod&SHIFT) == SHIFT) |
---|
14343 | | - manipCamera.RotatePosition(speed, 0); |
---|
| 14735 | + manipCamera.Translate(speed*delta, 0, getWidth()); |
---|
14344 | 14736 | else |
---|
14345 | | - manipCamera.Translate(speed*delta, 0, getWidth()); |
---|
14346 | | - */ |
---|
| 14737 | + { |
---|
| 14738 | + if ((mouseMode&VR)!=0) |
---|
| 14739 | + manipCamera.RotateInterest(-speed, 0); |
---|
| 14740 | + else |
---|
| 14741 | + manipCamera.RotatePosition(speed, 0); |
---|
| 14742 | + } |
---|
| 14743 | + /**/ |
---|
14347 | 14744 | if ((mod & SHIFT) == SHIFT) |
---|
14348 | 14745 | { |
---|
14349 | 14746 | mouseMode = mouseMode; |
---|
.. | .. |
---|
14352 | 14749 | mouseMode |= ROTATE; |
---|
14353 | 14750 | } // TRANSLATE; |
---|
14354 | 14751 | |
---|
| 14752 | + targetLookAt.set(manipCamera.lookAt); |
---|
| 14753 | + |
---|
14355 | 14754 | prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance()); |
---|
14356 | 14755 | prevY = Y = anchorY; |
---|
14357 | 14756 | } |
---|
.. | .. |
---|
14359 | 14758 | void GoRight(int mod) |
---|
14360 | 14759 | { |
---|
14361 | 14760 | MODIFIERS |= COMMAND; |
---|
14362 | | - /* |
---|
| 14761 | + /**/ |
---|
14363 | 14762 | if((mod&SHIFT) == SHIFT) |
---|
14364 | | - manipCamera.RotatePosition(-speed, 0); |
---|
| 14763 | + manipCamera.Translate(-speed*delta, 0, getWidth()); |
---|
14365 | 14764 | else |
---|
14366 | | - manipCamera.Translate(-speed*delta, 0, getWidth()); |
---|
14367 | | - */ |
---|
| 14765 | + { |
---|
| 14766 | + if ((mouseMode&VR)!=0) |
---|
| 14767 | + manipCamera.RotateInterest(speed, 0); |
---|
| 14768 | + else |
---|
| 14769 | + manipCamera.RotatePosition(-speed, 0); |
---|
| 14770 | + } |
---|
| 14771 | + |
---|
| 14772 | + /**/ |
---|
14368 | 14773 | if ((mod & SHIFT) == SHIFT) |
---|
14369 | 14774 | { |
---|
14370 | 14775 | mouseMode = mouseMode; |
---|
.. | .. |
---|
14373 | 14778 | mouseMode |= ROTATE; |
---|
14374 | 14779 | } // TRANSLATE; |
---|
14375 | 14780 | |
---|
| 14781 | + targetLookAt.set(manipCamera.lookAt); |
---|
| 14782 | + |
---|
14376 | 14783 | prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance()); |
---|
14377 | 14784 | prevY = Y = anchorY; |
---|
14378 | 14785 | } |
---|
.. | .. |
---|
14414 | 14821 | if (editObj) |
---|
14415 | 14822 | { |
---|
14416 | 14823 | drag = true; |
---|
14417 | | - ClickInfo info = new ClickInfo(); |
---|
14418 | | - info.bounds.setBounds(0, 0, |
---|
| 14824 | + //ClickInfo info = new ClickInfo(); |
---|
| 14825 | + object.clickInfo.bounds.setBounds(0, 0, |
---|
14419 | 14826 | (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
14420 | | - info.pane = this; |
---|
14421 | | - info.camera = renderCamera; |
---|
14422 | | - info.x = x; |
---|
14423 | | - info.y = y; |
---|
14424 | | - object.GetWindow().copy |
---|
14425 | | - .doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0); |
---|
| 14827 | + object.clickInfo.pane = this; |
---|
| 14828 | + object.clickInfo.camera = renderCamera; |
---|
| 14829 | + object.clickInfo.x = x; |
---|
| 14830 | + object.clickInfo.y = y; |
---|
| 14831 | + object //.GetWindow().copy |
---|
| 14832 | + .doEditDrag(//info, |
---|
| 14833 | + (modifiers & MouseEvent.BUTTON3_MASK) != 0); |
---|
14426 | 14834 | } else |
---|
14427 | 14835 | { |
---|
14428 | 14836 | if (x < startX) |
---|
.. | .. |
---|
14571 | 14979 | } |
---|
14572 | 14980 | } |
---|
14573 | 14981 | |
---|
| 14982 | +// ClickInfo clickInfo = new ClickInfo(); |
---|
| 14983 | + |
---|
14574 | 14984 | public void mouseMoved(MouseEvent e) |
---|
14575 | 14985 | { |
---|
14576 | 14986 | //System.out.println("mouseMoved: " + e); |
---|
14577 | 14987 | if (isRenderer) |
---|
14578 | 14988 | return; |
---|
14579 | 14989 | |
---|
14580 | | - ClickInfo ci = new ClickInfo(); |
---|
14581 | | - ci.x = e.getX(); |
---|
14582 | | - ci.y = e.getY(); |
---|
14583 | | - ci.modifiers = e.getModifiersEx(); |
---|
14584 | | - ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
14585 | | - ci.pane = this; |
---|
14586 | | - ci.camera = renderCamera; |
---|
| 14990 | + // Mouse cursor feedback |
---|
| 14991 | + object.clickInfo.x = e.getX(); |
---|
| 14992 | + object.clickInfo.y = e.getY(); |
---|
| 14993 | + object.clickInfo.modifiers = e.getModifiersEx(); |
---|
| 14994 | + object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
| 14995 | + object.clickInfo.pane = this; |
---|
| 14996 | + object.clickInfo.camera = renderCamera; |
---|
14587 | 14997 | if (!isRenderer) |
---|
14588 | 14998 | { |
---|
14589 | 14999 | //ObjEditor editWindow = object.editWindow; |
---|
14590 | 15000 | //Object3D copy = editWindow.copy; |
---|
14591 | | - if (object.doEditClick(ci, 0)) |
---|
| 15001 | + if (object.doEditClick(//clickInfo, |
---|
| 15002 | + 0)) |
---|
14592 | 15003 | { |
---|
14593 | 15004 | setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
---|
14594 | 15005 | } else |
---|
.. | .. |
---|
14603 | 15014 | Globals.MOUSEDRAGGED = false; |
---|
14604 | 15015 | |
---|
14605 | 15016 | movingcamera = false; |
---|
14606 | | - X = Y = 0; |
---|
| 15017 | + X = 0; // getBounds().width/2; |
---|
| 15018 | + Y = 0; // getBounds().height/2; |
---|
14607 | 15019 | //System.out.println("mouseReleased: " + e); |
---|
14608 | 15020 | clickEnd(e.getX(), e.getY(), e.getModifiersEx()); |
---|
14609 | 15021 | } |
---|
.. | .. |
---|
14859 | 15271 | // break; |
---|
14860 | 15272 | case 'T': |
---|
14861 | 15273 | CACHETEXTURE ^= true; |
---|
14862 | | - textures.clear(); |
---|
| 15274 | + texturepigment.clear(); |
---|
| 15275 | + texturebump.clear(); |
---|
14863 | 15276 | // repaint(); |
---|
14864 | 15277 | break; |
---|
14865 | 15278 | case 'Y': |
---|
.. | .. |
---|
14944 | 15357 | case 'E' : COMPACT ^= true; |
---|
14945 | 15358 | repaint(); |
---|
14946 | 15359 | break; |
---|
14947 | | - case 'W' : DEBUGHSB ^= true; |
---|
| 15360 | + case 'W' : // Wide Window (fullscreen) |
---|
| 15361 | + //DEBUGHSB ^= true; |
---|
| 15362 | + ObjEditor.theFrame.ToggleFullScreen(); |
---|
14948 | 15363 | repaint(); |
---|
14949 | 15364 | break; |
---|
14950 | 15365 | case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break; |
---|
.. | .. |
---|
14970 | 15385 | repaint(); |
---|
14971 | 15386 | break; |
---|
14972 | 15387 | case 'l': |
---|
14973 | | - lightMode ^= true; |
---|
14974 | | - Globals.lighttouched = true; |
---|
14975 | | - manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera; |
---|
14976 | | - targetLookAt.set(manipCamera.lookAt); |
---|
14977 | | - repaint(); |
---|
14978 | | - break; |
---|
14979 | | - case 'L': |
---|
| 15388 | + //case 'L': |
---|
14980 | 15389 | if (lightMode) |
---|
14981 | 15390 | { |
---|
14982 | 15391 | lightMode = false; |
---|
.. | .. |
---|
15040 | 15449 | OCCLUSION_CULLING ^= true; |
---|
15041 | 15450 | System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING); |
---|
15042 | 15451 | break; |
---|
15043 | | - case '0': envyoff ^= true; repaint(); break; |
---|
| 15452 | + //case '0': envyoff ^= true; repaint(); break; |
---|
15044 | 15453 | case '1': |
---|
15045 | 15454 | case '2': |
---|
15046 | 15455 | case '3': |
---|
15047 | 15456 | case '4': |
---|
15048 | 15457 | case '5': |
---|
15049 | | - newenvy = Character.getNumericValue(key); |
---|
15050 | | - repaint(); |
---|
15051 | | - break; |
---|
15052 | 15458 | case '6': |
---|
15053 | 15459 | case '7': |
---|
15054 | 15460 | case '8': |
---|
15055 | 15461 | case '9': |
---|
15056 | | - BGcolor = (key - '6')/3.f; |
---|
| 15462 | + if (true) // envyoff) |
---|
| 15463 | + { |
---|
| 15464 | + BGcolor = (key - '1')/8.f; |
---|
| 15465 | + } |
---|
| 15466 | + else |
---|
| 15467 | + { |
---|
| 15468 | + //newenvy = Character.getNumericValue(key); |
---|
| 15469 | + } |
---|
15057 | 15470 | repaint(); |
---|
15058 | 15471 | break; |
---|
15059 | 15472 | case '!': |
---|
.. | .. |
---|
15119 | 15532 | case '_': |
---|
15120 | 15533 | kompactbit = 5; |
---|
15121 | 15534 | break; |
---|
15122 | | - case '+': |
---|
15123 | | - kompactbit = 6; |
---|
15124 | | - break; |
---|
| 15535 | +// case '+': |
---|
| 15536 | +// kompactbit = 6; |
---|
| 15537 | +// break; |
---|
15125 | 15538 | case ' ': |
---|
15126 | | - ObjEditor.theFrame.ToggleFullScreen(); |
---|
| 15539 | + lightMode ^= true; |
---|
| 15540 | + Globals.lighttouched = true; |
---|
| 15541 | + manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera; |
---|
| 15542 | + targetLookAt.set(manipCamera.lookAt); |
---|
15127 | 15543 | repaint(); |
---|
15128 | 15544 | break; |
---|
15129 | 15545 | //case '`' : |
---|
.. | .. |
---|
15170 | 15586 | case DELETE: |
---|
15171 | 15587 | ClearSelection(); |
---|
15172 | 15588 | break; |
---|
15173 | | - /* |
---|
15174 | 15589 | case '+': |
---|
| 15590 | + |
---|
| 15591 | + /* |
---|
15175 | 15592 | //fontsize += 1; |
---|
15176 | 15593 | bbzoom *= 2; |
---|
15177 | 15594 | repaint(); |
---|
.. | .. |
---|
15188 | 15605 | case '=': |
---|
15189 | 15606 | IncDepth(); |
---|
15190 | 15607 | //fontsize += 1; |
---|
15191 | | - object.editWindow.refreshContents(true); |
---|
| 15608 | + object.GetWindow().refreshContents(true); |
---|
15192 | 15609 | maskbit = 6; |
---|
15193 | 15610 | break; |
---|
15194 | 15611 | case '-': //if (PixelThreshold>1) PixelThreshold /= 2; |
---|
15195 | 15612 | DecDepth(); |
---|
15196 | 15613 | maskbit = 5; |
---|
15197 | 15614 | //if(fontsize > 1) fontsize -= 1; |
---|
15198 | | - if (object.editWindow == null) |
---|
15199 | | - new Exception().printStackTrace(); |
---|
15200 | | - else |
---|
15201 | | - object.editWindow.refreshContents(true); |
---|
| 15615 | +// if (object.editWindow == null) |
---|
| 15616 | +// new Exception().printStackTrace(); |
---|
| 15617 | +// else |
---|
| 15618 | + object.GetWindow().refreshContents(true); |
---|
15202 | 15619 | break; |
---|
15203 | 15620 | case '{': |
---|
15204 | 15621 | manipCamera.shaper_fovy /= 1.1; |
---|
.. | .. |
---|
15422 | 15839 | } |
---|
15423 | 15840 | */ |
---|
15424 | 15841 | |
---|
15425 | | - object.editWindow.EditSelection(false); |
---|
| 15842 | + object.GetWindow().EditSelection(false); |
---|
15426 | 15843 | } |
---|
15427 | 15844 | |
---|
15428 | 15845 | void SelectParent() |
---|
.. | .. |
---|
15439 | 15856 | { |
---|
15440 | 15857 | //selectees.remove(i); |
---|
15441 | 15858 | System.out.println("select parent of " + elem); |
---|
15442 | | - group.editWindow.Select(elem.parent.GetTreePath(), first, true); |
---|
| 15859 | + group.GetWindow().Select(elem.parent.GetTreePath(), first, true); |
---|
15443 | 15860 | } else |
---|
15444 | 15861 | { |
---|
15445 | | - group.editWindow.Select(elem.GetTreePath(), first, true); |
---|
| 15862 | + group.GetWindow().Select(elem.GetTreePath(), first, true); |
---|
15446 | 15863 | } |
---|
15447 | 15864 | |
---|
15448 | 15865 | first = false; |
---|
.. | .. |
---|
15484 | 15901 | for (int j = 0; j < group.children.size(); j++) |
---|
15485 | 15902 | { |
---|
15486 | 15903 | elem = (Object3D) group.children.elementAt(j); |
---|
15487 | | - object.editWindow.Select(elem.GetTreePath(), first, true); |
---|
| 15904 | + object.GetWindow().Select(elem.GetTreePath(), first, true); |
---|
15488 | 15905 | first = false; |
---|
15489 | 15906 | } |
---|
15490 | 15907 | } else |
---|
15491 | 15908 | { |
---|
15492 | | - object.editWindow.Select(elem.GetTreePath(), first, true); |
---|
| 15909 | + object.GetWindow().Select(elem.GetTreePath(), first, true); |
---|
15493 | 15910 | } |
---|
15494 | 15911 | |
---|
15495 | 15912 | first = false; |
---|
.. | .. |
---|
15500 | 15917 | { |
---|
15501 | 15918 | //Composite group = (Composite) object; |
---|
15502 | 15919 | Object3D group = object; |
---|
15503 | | - group.editWindow.loadClipboard(true); // ClearSelection(false); |
---|
| 15920 | + group.GetWindow().loadClipboard(true); // ClearSelection(false); |
---|
15504 | 15921 | } |
---|
15505 | 15922 | |
---|
15506 | 15923 | void ResetTransform(int mask) |
---|
15507 | 15924 | { |
---|
15508 | 15925 | //Composite group = (Composite) object; |
---|
15509 | 15926 | Object3D group = object; |
---|
15510 | | - group.editWindow.ResetTransform(mask); |
---|
| 15927 | + group.GetWindow().ResetTransform(mask); |
---|
15511 | 15928 | } |
---|
15512 | 15929 | |
---|
15513 | 15930 | void FlipTransform() |
---|
15514 | 15931 | { |
---|
15515 | 15932 | //Composite group = (Composite) object; |
---|
15516 | 15933 | Object3D group = object; |
---|
15517 | | - group.editWindow.FlipTransform(); |
---|
| 15934 | + group.GetWindow().FlipTransform(); |
---|
15518 | 15935 | // group.editWindow.ReduceMesh(true); |
---|
15519 | 15936 | } |
---|
15520 | 15937 | |
---|
.. | .. |
---|
15522 | 15939 | { |
---|
15523 | 15940 | //Composite group = (Composite) object; |
---|
15524 | 15941 | Object3D group = object; |
---|
15525 | | - group.editWindow.PrintMemory(); |
---|
| 15942 | + group.GetWindow().PrintMemory(); |
---|
15526 | 15943 | // group.editWindow.ReduceMesh(true); |
---|
15527 | 15944 | } |
---|
15528 | 15945 | |
---|
.. | .. |
---|
15530 | 15947 | { |
---|
15531 | 15948 | //Composite group = (Composite) object; |
---|
15532 | 15949 | Object3D group = object; |
---|
15533 | | - group.editWindow.ResetCentroid(); |
---|
| 15950 | + group.GetWindow().ResetCentroid(); |
---|
15534 | 15951 | } |
---|
15535 | 15952 | |
---|
15536 | 15953 | void IncDepth() |
---|
.. | .. |
---|
15612 | 16029 | |
---|
15613 | 16030 | int width = getBounds().width; |
---|
15614 | 16031 | int height = getBounds().height; |
---|
15615 | | - ClickInfo info = new ClickInfo(); |
---|
15616 | | - info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom)); |
---|
15617 | 16032 | //Image img = CreateImage(width, height); |
---|
15618 | 16033 | //System.out.println("width = " + width + "; height = " + height + "\n"); |
---|
15619 | 16034 | |
---|
.. | .. |
---|
15690 | 16105 | } |
---|
15691 | 16106 | if (object != null && !hasMarquee) |
---|
15692 | 16107 | { |
---|
| 16108 | + if (object.clickInfo == null) |
---|
| 16109 | + object.clickInfo = new ClickInfo(); |
---|
| 16110 | + ClickInfo info = object.clickInfo; |
---|
| 16111 | + //ClickInfo info = new ClickInfo(); |
---|
| 16112 | + info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom)); |
---|
| 16113 | + |
---|
15693 | 16114 | if (isRenderer) |
---|
15694 | 16115 | { |
---|
15695 | | - info.flags++; |
---|
| 16116 | + object.clickInfo.flags++; |
---|
15696 | 16117 | double frameAspect = (double) width / (double) height; |
---|
15697 | 16118 | if (frameAspect > renderCamera.aspect) |
---|
15698 | 16119 | { |
---|
15699 | 16120 | int desired = (int) ((double) height * renderCamera.aspect); |
---|
15700 | | - info.bounds.width -= width - desired; |
---|
15701 | | - info.bounds.x += (width - desired) / 2; |
---|
| 16121 | + object.clickInfo.bounds.width -= width - desired; |
---|
| 16122 | + object.clickInfo.bounds.x += (width - desired) / 2; |
---|
15702 | 16123 | } else |
---|
15703 | 16124 | { |
---|
15704 | 16125 | int desired = (int) ((double) width / renderCamera.aspect); |
---|
15705 | | - info.bounds.height -= height - desired; |
---|
15706 | | - info.bounds.y += (height - desired) / 2; |
---|
| 16126 | + object.clickInfo.bounds.height -= height - desired; |
---|
| 16127 | + object.clickInfo.bounds.y += (height - desired) / 2; |
---|
15707 | 16128 | } |
---|
15708 | 16129 | } |
---|
15709 | | - info.g = gr; |
---|
15710 | | - info.camera = renderCamera; |
---|
| 16130 | + |
---|
| 16131 | + object.clickInfo.g = gr; |
---|
| 16132 | + object.clickInfo.camera = renderCamera; |
---|
15711 | 16133 | /* |
---|
15712 | 16134 | // Memory intensive (brep.verticescopy) |
---|
15713 | 16135 | if (!(object instanceof Composite)) |
---|
15714 | 16136 | object.draw(info, 0, false); // SLOW : |
---|
15715 | 16137 | */ |
---|
15716 | | - if (!isRenderer) |
---|
| 16138 | + if (!isRenderer) // && drag) |
---|
15717 | 16139 | { |
---|
15718 | | - object.drawEditHandles(info, 0); |
---|
15719 | | - |
---|
15720 | | - if (drag && (X != 0 || Y != 0) && object.selection.Size() > 0) |
---|
| 16140 | + Grafreed.Assert(object != null); |
---|
| 16141 | + Grafreed.Assert(object.selection != null); |
---|
| 16142 | + if (object.selection.Size() > 0) |
---|
15721 | 16143 | { |
---|
15722 | | - switch (object.selection.get(0).hitSomething) |
---|
| 16144 | + int hitSomething = object.selection.get(0).hitSomething; |
---|
| 16145 | + |
---|
| 16146 | + object.clickInfo.DX = 0; |
---|
| 16147 | + object.clickInfo.DY = 0; |
---|
| 16148 | + object.clickInfo.W = 1; |
---|
| 16149 | + if (hitSomething == Object3D.hitCenter) |
---|
15723 | 16150 | { |
---|
15724 | | - case Object3D.hitCenter: gr.setColor(Color.pink); |
---|
15725 | | - gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
15726 | | - break; |
---|
15727 | | - case Object3D.hitRotate: gr.setColor(Color.yellow); |
---|
15728 | | - gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
15729 | | - break; |
---|
15730 | | - case Object3D.hitScale: gr.setColor(Color.cyan); |
---|
15731 | | - gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
15732 | | - break; |
---|
| 16151 | + info.DX = X; |
---|
| 16152 | + if (X != 0) |
---|
| 16153 | + info.DX -= info.bounds.width/2; |
---|
| 16154 | + |
---|
| 16155 | + info.DY = Y; |
---|
| 16156 | + if (Y != 0) |
---|
| 16157 | + info.DY -= info.bounds.height/2; |
---|
15733 | 16158 | } |
---|
15734 | | - |
---|
| 16159 | + |
---|
| 16160 | + object.drawEditHandles(//info, |
---|
| 16161 | + 0); |
---|
| 16162 | + |
---|
| 16163 | + if (drag && (X != 0 || Y != 0)) |
---|
| 16164 | + { |
---|
| 16165 | + switch (hitSomething) |
---|
| 16166 | + { |
---|
| 16167 | + case Object3D.hitCenter: gr.setColor(Color.white); |
---|
| 16168 | + gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
| 16169 | + break; |
---|
| 16170 | + case Object3D.hitRotate: gr.setColor(Color.yellow); |
---|
| 16171 | + gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
| 16172 | + break; |
---|
| 16173 | + case Object3D.hitScale: gr.setColor(Color.cyan); |
---|
| 16174 | + gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
| 16175 | + break; |
---|
| 16176 | + } |
---|
| 16177 | + |
---|
| 16178 | + } |
---|
15735 | 16179 | } |
---|
15736 | 16180 | } |
---|
15737 | 16181 | } |
---|
.. | .. |
---|
15746 | 16190 | if (hasMarquee) |
---|
15747 | 16191 | { |
---|
15748 | 16192 | gr.setXORMode(Color.white); |
---|
15749 | | - gr.setColor(Color.red); |
---|
| 16193 | + gr.setColor(Color.white); |
---|
15750 | 16194 | if (!firstime) |
---|
15751 | 16195 | { |
---|
15752 | 16196 | gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH); |
---|
.. | .. |
---|
16213 | 16657 | private /*static*/ boolean firstime; |
---|
16214 | 16658 | private /*static*/ cVector newView = new cVector(); |
---|
16215 | 16659 | private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"}; |
---|
| 16660 | + private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"}; |
---|
| 16661 | + private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"}; |
---|
16216 | 16662 | private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X, |
---|
16217 | 16663 | GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X, |
---|
16218 | 16664 | GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y, |
---|
.. | .. |
---|
16225 | 16671 | { |
---|
16226 | 16672 | com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP); |
---|
16227 | 16673 | |
---|
| 16674 | + int usedsuf = 0; |
---|
| 16675 | + |
---|
16228 | 16676 | for (int i = 0; i < suffixes.length; i++) |
---|
16229 | 16677 | { |
---|
16230 | | - String resourceName = basename + suffixes[i] + "." + suffix; |
---|
16231 | | - TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
16232 | | - mipmapped, |
---|
16233 | | - FileUtil.getFileSuffix(resourceName)); |
---|
16234 | | - if (data == null) |
---|
| 16678 | + String[] suffixe = suffixes; |
---|
| 16679 | + String[] fallback = suffixes2; |
---|
| 16680 | + String[] fallfallback = suffixes3; |
---|
| 16681 | + |
---|
| 16682 | + for (int c=usedsuf; --c>=0;) |
---|
16235 | 16683 | { |
---|
16236 | | - throw new IOException("Unable to load texture " + resourceName); |
---|
| 16684 | +// String[] temp = suffixe; |
---|
| 16685 | +// suffixe = fallback; |
---|
| 16686 | +// fallback = fallfallback; |
---|
| 16687 | +// fallfallback = temp; |
---|
16237 | 16688 | } |
---|
| 16689 | + |
---|
| 16690 | + String resourceName = basename + suffixe[i] + "." + suffix; |
---|
| 16691 | + TextureData data; |
---|
| 16692 | + |
---|
| 16693 | + try |
---|
| 16694 | + { |
---|
| 16695 | + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
| 16696 | + mipmapped, |
---|
| 16697 | + FileUtil.getFileSuffix(resourceName)); |
---|
| 16698 | + } |
---|
| 16699 | + catch (Exception e) |
---|
| 16700 | + { |
---|
| 16701 | + try |
---|
| 16702 | + { |
---|
| 16703 | + resourceName = basename + fallback[i] + "." + suffix; |
---|
| 16704 | + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
| 16705 | + mipmapped, |
---|
| 16706 | + FileUtil.getFileSuffix(resourceName)); |
---|
| 16707 | + } |
---|
| 16708 | + catch (Exception e2) |
---|
| 16709 | + { |
---|
| 16710 | + resourceName = basename + fallfallback[i] + "." + suffix; |
---|
| 16711 | + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
| 16712 | + mipmapped, |
---|
| 16713 | + FileUtil.getFileSuffix(resourceName)); |
---|
| 16714 | + } |
---|
| 16715 | + } |
---|
| 16716 | + |
---|
16238 | 16717 | //System.out.println("Target = " + targets[i]); |
---|
16239 | 16718 | cubemap.updateImage(data, targets[i]); |
---|
16240 | 16719 | } |
---|
16241 | 16720 | |
---|
16242 | 16721 | return cubemap; |
---|
16243 | 16722 | } |
---|
| 16723 | + |
---|
16244 | 16724 | int bigsphere = -1; |
---|
16245 | 16725 | |
---|
16246 | 16726 | float BGcolor = 0.5f; |
---|
16247 | 16727 | |
---|
16248 | | - private void DrawSkyBox(GL gl) |
---|
| 16728 | + float ambientLight[] = {1f, 1f, 1f, 1.0f}; |
---|
| 16729 | + |
---|
| 16730 | + private void DrawSkyBox(GL gl, float ratio) |
---|
16249 | 16731 | { |
---|
16250 | | - if (envyoff || cubemap == null) |
---|
| 16732 | + if (//envyoff || |
---|
| 16733 | + WIREFRAME || |
---|
| 16734 | + cubemap == null) |
---|
16251 | 16735 | { |
---|
16252 | 16736 | gl.glClearColor(BGcolor, BGcolor, BGcolor, 1); |
---|
16253 | 16737 | gl.glClear(gl.GL_COLOR_BUFFER_BIT); |
---|
.. | .. |
---|
16262 | 16746 | // Compensates for ExaminerViewer's modification of modelview matrix |
---|
16263 | 16747 | gl.glMatrixMode(GL.GL_MODELVIEW); |
---|
16264 | 16748 | gl.glLoadIdentity(); |
---|
| 16749 | + gl.glScalef(1,ratio,1); |
---|
16265 | 16750 | |
---|
| 16751 | +// colorV[0] = 2; |
---|
| 16752 | +// colorV[1] = 2; |
---|
| 16753 | +// colorV[2] = 2; |
---|
| 16754 | +// colorV[3] = 1; |
---|
| 16755 | +// gl.glDisable(gl.GL_COLOR_MATERIAL); |
---|
| 16756 | +// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0); |
---|
| 16757 | +// |
---|
| 16758 | +// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0); |
---|
| 16759 | + |
---|
16266 | 16760 | //gl.glActiveTexture(GL.GL_TEXTURE1); |
---|
16267 | 16761 | //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP); |
---|
16268 | 16762 | |
---|
.. | .. |
---|
16294 | 16788 | { |
---|
16295 | 16789 | gl.glScalef(1.0f, -1.0f, 1.0f); |
---|
16296 | 16790 | } |
---|
| 16791 | + gl.glScalef(-1.0f, 1.0f, 1.0f); |
---|
16297 | 16792 | gl.glMultMatrixd(viewrot_1, 0); |
---|
16298 | 16793 | gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f); |
---|
16299 | 16794 | //viewer.updateInverseRotation(gl); |
---|
.. | .. |
---|
16334 | 16829 | gl.glDisable(GL.GL_TEXTURE_GEN_R); |
---|
16335 | 16830 | |
---|
16336 | 16831 | cubemap.disable(); |
---|
16337 | | - ////cubemap.unbind(); |
---|
| 16832 | + //cubemap.dispose(); |
---|
| 16833 | + |
---|
16338 | 16834 | if (CULLFACE) |
---|
16339 | 16835 | { |
---|
16340 | 16836 | gl.glEnable(gl.GL_CULL_FACE); |
---|
.. | .. |
---|
16529 | 17025 | } |
---|
16530 | 17026 | } |
---|
16531 | 17027 | |
---|
| 17028 | + private Object3D GetFolder() |
---|
| 17029 | + { |
---|
| 17030 | + Object3D folder = object.GetWindow().copy; |
---|
| 17031 | + if (object.GetWindow().copy.selection.Size() > 0) |
---|
| 17032 | + folder = object.GetWindow().copy.selection.elementAt(0); |
---|
| 17033 | + return folder; |
---|
| 17034 | + } |
---|
| 17035 | + |
---|
16532 | 17036 | class SelectBuffer implements GLEventListener |
---|
16533 | 17037 | { |
---|
16534 | 17038 | |
---|
.. | .. |
---|
16544 | 17048 | //new Exception().printStackTrace(); |
---|
16545 | 17049 | System.out.println("select buffer init"); |
---|
16546 | 17050 | // Use debug pipeline |
---|
16547 | | - drawable.setGL(new DebugGL(drawable.getGL())); |
---|
| 17051 | + //drawable.setGL(new DebugGL(drawable.getGL())); |
---|
16548 | 17052 | |
---|
16549 | 17053 | GL gl = drawable.getGL(); |
---|
16550 | 17054 | |
---|
.. | .. |
---|
16608 | 17112 | |
---|
16609 | 17113 | //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL); |
---|
16610 | 17114 | |
---|
| 17115 | + if (PAINTMODE) |
---|
| 17116 | + { |
---|
| 17117 | + if (object.GetWindow().copy.selection.Size() > 0) |
---|
| 17118 | + { |
---|
| 17119 | + Object3D paintobj = object.GetWindow().copy.selection.elementAt(0); |
---|
| 17120 | + |
---|
| 17121 | + // Make what you paint not selectable. |
---|
| 17122 | + paintobj.ResetSelectable(); |
---|
| 17123 | + } |
---|
| 17124 | + } |
---|
| 17125 | + |
---|
16611 | 17126 | //int tmp = selection_view; |
---|
16612 | 17127 | //selection_view = -1; |
---|
16613 | 17128 | int temp = DrawMode(); |
---|
.. | .. |
---|
16619 | 17134 | // temp = DEFAULT; // patch for selection debug |
---|
16620 | 17135 | Globals.drawMode = temp; // WARNING |
---|
16621 | 17136 | |
---|
| 17137 | + if (PAINTMODE) |
---|
| 17138 | + { |
---|
| 17139 | + if (object.GetWindow().copy.selection.Size() > 0) |
---|
| 17140 | + { |
---|
| 17141 | + Object3D paintobj = object.GetWindow().copy.selection.elementAt(0); |
---|
| 17142 | + |
---|
| 17143 | + // Revert. |
---|
| 17144 | + paintobj.RestoreSelectable(); |
---|
| 17145 | + } |
---|
| 17146 | + } |
---|
| 17147 | + |
---|
16622 | 17148 | //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view); |
---|
16623 | 17149 | |
---|
16624 | 17150 | // trying different ways of getting the depth info over |
---|
.. | .. |
---|
16722 | 17248 | } |
---|
16723 | 17249 | |
---|
16724 | 17250 | if (!movingcamera && !PAINTMODE) |
---|
16725 | | - object.editWindow.ScreenFitPoint(); // fev 2014 |
---|
| 17251 | + object.GetWindow().ScreenFitPoint(); // fev 2014 |
---|
16726 | 17252 | |
---|
16727 | | - if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0) |
---|
| 17253 | + if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0) |
---|
16728 | 17254 | { |
---|
16729 | | - Object3D paintobj = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0); |
---|
| 17255 | + //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0); |
---|
16730 | 17256 | |
---|
16731 | | - Object3D group = new Object3D("inst" + paintcount++); |
---|
| 17257 | + if (object.GetWindow().copy.selection.Size() > 0) |
---|
| 17258 | + { |
---|
| 17259 | + Object3D paintobj = object.GetWindow().copy.selection.elementAt(0); |
---|
16732 | 17260 | |
---|
16733 | | - group.CreateMaterial(); // use a void leaf to select instances |
---|
16734 | | - |
---|
16735 | | - group.add(paintobj); // link |
---|
16736 | | - |
---|
16737 | | - object.editWindow.SnapObject(group); |
---|
16738 | | - |
---|
16739 | | - Object3D folder = object.editWindow.copy; |
---|
16740 | | - |
---|
16741 | | - if (object.editWindow.copy.selection.Size() > 0) |
---|
16742 | | - folder = object.editWindow.copy.selection.elementAt(0); |
---|
16743 | | - |
---|
16744 | | - folder.add(group); |
---|
16745 | | - |
---|
16746 | | - object.editWindow.ResetModel(); |
---|
16747 | | - object.editWindow.refreshContents(); |
---|
| 17261 | + Object3D inst = new Object3D("inst" + paintcount++); |
---|
| 17262 | + |
---|
| 17263 | + inst.CreateMaterial(); // use a void leaf to select instances |
---|
| 17264 | + |
---|
| 17265 | + inst.add(paintobj); // link |
---|
| 17266 | + |
---|
| 17267 | + object.GetWindow().SnapObject(inst); |
---|
| 17268 | + |
---|
| 17269 | + Object3D folder = paintFolder; // GetFolder(); |
---|
| 17270 | + |
---|
| 17271 | + folder.add(inst); |
---|
| 17272 | + |
---|
| 17273 | + object.GetWindow().ResetModel(); |
---|
| 17274 | + object.GetWindow().refreshContents(); |
---|
| 17275 | + } |
---|
16748 | 17276 | } |
---|
16749 | 17277 | else |
---|
16750 | 17278 | paintcount = 0; |
---|
.. | .. |
---|
16783 | 17311 | //System.out.println("objects[color] = " + objects[color]); |
---|
16784 | 17312 | //objects[color].Select(); |
---|
16785 | 17313 | indexcount = 0; |
---|
| 17314 | + ObjEditor window = object.GetWindow(); |
---|
| 17315 | + if (window != null && deselect) |
---|
| 17316 | + { |
---|
| 17317 | + window.Select(null, deselect, true); |
---|
| 17318 | + } |
---|
16786 | 17319 | object.Select(color, deselect); |
---|
16787 | 17320 | } |
---|
16788 | 17321 | |
---|
.. | .. |
---|
16833 | 17366 | |
---|
16834 | 17367 | public void init(GLAutoDrawable drawable) |
---|
16835 | 17368 | { |
---|
| 17369 | + if (Globals.DEBUG) |
---|
16836 | 17370 | System.out.println("shadow buffer init"); |
---|
16837 | 17371 | |
---|
16838 | 17372 | GL gl = drawable.getGL(); |
---|
.. | .. |
---|
17061 | 17595 | gl.glFlush(); |
---|
17062 | 17596 | |
---|
17063 | 17597 | /**/ |
---|
17064 | | - gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer); |
---|
| 17598 | + gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer); |
---|
17065 | 17599 | |
---|
17066 | | - float[] pixels = occlusionsizebuffer.array(); |
---|
| 17600 | + float[] depths = occlusiondepthbuffer.array(); |
---|
17067 | 17601 | |
---|
| 17602 | + gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer); |
---|
| 17603 | + |
---|
| 17604 | + int[] pixels = selectsizebuffer.array(); |
---|
| 17605 | + |
---|
17068 | 17606 | double r = 0, g = 0, b = 0; |
---|
17069 | 17607 | |
---|
17070 | 17608 | double count = 0; |
---|
.. | .. |
---|
17075 | 17613 | |
---|
17076 | 17614 | double FACTOR = 1; |
---|
17077 | 17615 | |
---|
17078 | | - for (int i = 0; i < pixels.length; i++) |
---|
| 17616 | + for (int i = 0; i < depths.length; i++) |
---|
17079 | 17617 | { |
---|
17080 | 17618 | int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2; |
---|
17081 | 17619 | int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2; |
---|
.. | .. |
---|
17158 | 17696 | |
---|
17159 | 17697 | double scale = ray.z; // 1; // cos |
---|
17160 | 17698 | |
---|
17161 | | - float depth = pixels[newindex]; |
---|
| 17699 | + float depth = depths[newindex]; |
---|
17162 | 17700 | |
---|
17163 | 17701 | /* |
---|
17164 | 17702 | int newindex2 = (x + 1) * OCCLUSION_SIZE + y; |
---|
.. | .. |
---|
17355 | 17893 | static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE); |
---|
17356 | 17894 | static IntBuffer bigAAbuffer; |
---|
17357 | 17895 | static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3); |
---|
17358 | | - static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE); |
---|
| 17896 | + //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE); |
---|
17359 | 17897 | static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE); |
---|
17360 | 17898 | static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE); |
---|
17361 | 17899 | //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); |
---|
17362 | | - static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); |
---|
| 17900 | + static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); |
---|
| 17901 | + |
---|
| 17902 | + static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); |
---|
| 17903 | + |
---|
17363 | 17904 | static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB); |
---|
17364 | 17905 | static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); |
---|
17365 | 17906 | static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>(); |
---|