.. | .. |
---|
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 |
---|
.. | .. |
---|
127 | 168 | |
---|
128 | 169 | |
---|
129 | 170 | // OPTIONS |
---|
130 | | - boolean Skinshader = true; |
---|
| 171 | + boolean Skinshader = false; // true; |
---|
131 | 172 | boolean cameraLight = false; |
---|
132 | 173 | boolean UVdebug = false; |
---|
133 | 174 | boolean Udebug = false; |
---|
.. | .. |
---|
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 | |
---|
.. | .. |
---|
335 | 390 | display.options1[2] = material.shadowbias; |
---|
336 | 391 | display.options1[3] = material.aniso; |
---|
337 | 392 | display.options1[4] = material.anisoV; |
---|
| 393 | +// System.out.println("display.options1[0] " + display.options1[0]); |
---|
| 394 | +// System.out.println("display.options1[1] " + display.options1[1]); |
---|
| 395 | +// System.out.println("display.options1[2] " + display.options1[2]); |
---|
| 396 | +// System.out.println("display.options1[3] " + display.options1[3]); |
---|
| 397 | +// System.out.println("display.options1[4] " + display.options1[4]); |
---|
338 | 398 | display.options2[0] = material.opacity; |
---|
339 | 399 | display.options2[1] = material.diffuse; |
---|
340 | 400 | display.options2[2] = material.factor; |
---|
| 401 | +// System.out.println("display.options2[0] " + display.options2[0]); |
---|
| 402 | +// System.out.println("display.options2[1] " + display.options2[1]); |
---|
| 403 | +// System.out.println("display.options2[2] " + display.options2[2]); |
---|
341 | 404 | |
---|
342 | 405 | cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3); |
---|
| 406 | +// System.out.println("display.options3[0] " + display.options3[0]); |
---|
| 407 | +// System.out.println("display.options3[1] " + display.options3[1]); |
---|
| 408 | +// System.out.println("display.options3[2] " + display.options3[2]); |
---|
343 | 409 | display.options4[0] = material.cameralight/0.2f; |
---|
344 | 410 | display.options4[1] = material.subsurface; |
---|
345 | 411 | display.options4[2] = material.sheen; |
---|
| 412 | +// System.out.println("display.options4[0] " + display.options4[0]); |
---|
| 413 | +// System.out.println("display.options4[1] " + display.options4[1]); |
---|
| 414 | +// System.out.println("display.options4[2] " + display.options4[2]); |
---|
346 | 415 | |
---|
347 | 416 | // if (display.CURRENTANTIALIAS > 0) |
---|
348 | 417 | // display.options3[3] /= 4; |
---|
.. | .. |
---|
1433 | 1502 | gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z); |
---|
1434 | 1503 | } |
---|
1435 | 1504 | |
---|
| 1505 | + float[] colorV = new float[4]; |
---|
| 1506 | + |
---|
1436 | 1507 | void SetColor(Object3D obj, Vertex p0) |
---|
1437 | 1508 | { |
---|
1438 | 1509 | CameraPane display = this; |
---|
.. | .. |
---|
1500 | 1571 | { |
---|
1501 | 1572 | return; |
---|
1502 | 1573 | } |
---|
1503 | | - |
---|
1504 | | - float[] colorV = new float[3]; |
---|
1505 | 1574 | |
---|
1506 | 1575 | if (false) // marked) |
---|
1507 | 1576 | { |
---|
.. | .. |
---|
2051 | 2120 | //System.err.println("Oeil on"); |
---|
2052 | 2121 | OEIL = true; |
---|
2053 | 2122 | if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode) |
---|
2054 | | - object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK); |
---|
| 2123 | + object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK); |
---|
2055 | 2124 | //pingthread.StepToTarget(true); |
---|
2056 | 2125 | } |
---|
2057 | 2126 | |
---|
.. | .. |
---|
2284 | 2353 | HANDLES ^= true; |
---|
2285 | 2354 | } |
---|
2286 | 2355 | |
---|
| 2356 | + Object3D paintFolder; |
---|
| 2357 | + |
---|
2287 | 2358 | void TogglePaint() |
---|
2288 | 2359 | { |
---|
2289 | 2360 | PAINTMODE ^= true; |
---|
2290 | 2361 | paintcount = 0; |
---|
| 2362 | + |
---|
| 2363 | + if (PAINTMODE) |
---|
| 2364 | + { |
---|
| 2365 | + paintFolder = GetFolder(); |
---|
| 2366 | + } |
---|
2291 | 2367 | } |
---|
2292 | 2368 | |
---|
2293 | 2369 | void SwapCamera(int a, int b) |
---|
.. | .. |
---|
2384 | 2460 | return currentGL; |
---|
2385 | 2461 | } |
---|
2386 | 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 | + |
---|
2387 | 2478 | /**/ |
---|
2388 | 2479 | class CacheTexture |
---|
2389 | 2480 | { |
---|
.. | .. |
---|
2392 | 2483 | |
---|
2393 | 2484 | int resolution; |
---|
2394 | 2485 | |
---|
2395 | | - CacheTexture(com.sun.opengl.util.texture.Texture tex, int res) |
---|
| 2486 | + CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res) |
---|
2396 | 2487 | { |
---|
2397 | | - texture = tex; |
---|
| 2488 | + texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata); |
---|
| 2489 | + texturedata = texdata; |
---|
2398 | 2490 | resolution = res; |
---|
2399 | 2491 | } |
---|
2400 | 2492 | } |
---|
2401 | 2493 | /**/ |
---|
2402 | 2494 | |
---|
2403 | 2495 | // TEXTURE static Texture texture; |
---|
2404 | | - static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures |
---|
2405 | | - = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>(); |
---|
2406 | | - 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 | + |
---|
2407 | 2501 | int pigmentdepth = 0; |
---|
2408 | 2502 | public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536]; |
---|
2409 | 2503 | int bumpdepth = 0; |
---|
2410 | 2504 | public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536]; |
---|
2411 | 2505 | //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE"; |
---|
2412 | 2506 | public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP"); |
---|
2413 | | - public static String NOISE_TEXTURE = "WHITE_NOISE"; |
---|
| 2507 | + public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:"); |
---|
2414 | 2508 | // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL"); |
---|
2415 | 2509 | |
---|
2416 | | - com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump) |
---|
| 2510 | + com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump) |
---|
2417 | 2511 | { |
---|
2418 | 2512 | TextureData texturedata = null; |
---|
2419 | 2513 | |
---|
.. | .. |
---|
2423 | 2517 | com.sun.opengl.util.texture.TextureIO.newTextureData( |
---|
2424 | 2518 | getClass().getClassLoader().getResourceAsStream(name), |
---|
2425 | 2519 | true, |
---|
2426 | | - com.sun.opengl.util.texture.TextureIO.PNG); |
---|
| 2520 | + GetFormat(name)); // com.sun.opengl.util.texture.TextureIO.PNG); |
---|
2427 | 2521 | } catch (java.io.IOException e) |
---|
2428 | 2522 | { |
---|
2429 | 2523 | throw new javax.media.opengl.GLException(e); |
---|
.. | .. |
---|
2432 | 2526 | if (bump) |
---|
2433 | 2527 | texturedata = ConvertBump(texturedata, false); |
---|
2434 | 2528 | |
---|
2435 | | - com.sun.opengl.util.texture.Texture texture = |
---|
2436 | | - 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); |
---|
2437 | 2531 | |
---|
2438 | | - texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT); |
---|
2439 | | - 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); |
---|
2440 | 2534 | |
---|
2441 | | - 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; |
---|
2442 | 2557 | } |
---|
2443 | 2558 | |
---|
2444 | 2559 | boolean HUESMOOTH = true; // wrap around bug... true; |
---|
.. | .. |
---|
3511 | 3626 | |
---|
3512 | 3627 | System.out.println("LOADING TEXTURE : " + name); |
---|
3513 | 3628 | |
---|
| 3629 | + Object x = texturedata.getMipmapData(); // .getBuffer(); |
---|
| 3630 | + |
---|
3514 | 3631 | // |
---|
3515 | 3632 | if (false) // compressbit > 0) |
---|
3516 | 3633 | { |
---|
.. | .. |
---|
7909 | 8026 | String pigment = Object3D.GetPigment(tex); |
---|
7910 | 8027 | String bump = Object3D.GetBump(tex); |
---|
7911 | 8028 | |
---|
7912 | | - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8029 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
7913 | 8030 | { |
---|
7914 | 8031 | // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment); |
---|
7915 | 8032 | // System.out.println("; bump = " + bump); |
---|
.. | .. |
---|
7924 | 8041 | pigment = null; |
---|
7925 | 8042 | } |
---|
7926 | 8043 | |
---|
7927 | | - ReleaseTexture(bump, true); |
---|
7928 | | - ReleaseTexture(pigment, false); |
---|
| 8044 | + ReleaseTexture(tex, true); |
---|
| 8045 | + ReleaseTexture(tex, false); |
---|
7929 | 8046 | } |
---|
7930 | 8047 | |
---|
7931 | 8048 | public void ReleasePigmentTexture(cTexture tex) // INTERFACE |
---|
.. | .. |
---|
7943 | 8060 | |
---|
7944 | 8061 | String pigment = Object3D.GetPigment(tex); |
---|
7945 | 8062 | |
---|
7946 | | - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8063 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
7947 | 8064 | { |
---|
7948 | 8065 | // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment); |
---|
7949 | 8066 | // System.out.println("; bump = " + bump); |
---|
.. | .. |
---|
7954 | 8071 | pigment = null; |
---|
7955 | 8072 | } |
---|
7956 | 8073 | |
---|
7957 | | - ReleaseTexture(pigment, false); |
---|
| 8074 | + ReleaseTexture(tex, false); |
---|
7958 | 8075 | } |
---|
7959 | 8076 | |
---|
7960 | 8077 | public void ReleaseBumpTexture(cTexture tex) // INTERFACE |
---|
.. | .. |
---|
7972 | 8089 | |
---|
7973 | 8090 | String bump = Object3D.GetBump(tex); |
---|
7974 | 8091 | |
---|
7975 | | - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8092 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
7976 | 8093 | { |
---|
7977 | 8094 | // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment); |
---|
7978 | 8095 | // System.out.println("; bump = " + bump); |
---|
.. | .. |
---|
7983 | 8100 | bump = null; |
---|
7984 | 8101 | } |
---|
7985 | 8102 | |
---|
7986 | | - ReleaseTexture(bump, true); |
---|
| 8103 | + ReleaseTexture(tex, true); |
---|
7987 | 8104 | } |
---|
7988 | 8105 | |
---|
7989 | | - void ReleaseTexture(String tex, boolean bump) |
---|
| 8106 | + void ReleaseTexture(cTexture tex, boolean bump) |
---|
7990 | 8107 | { |
---|
7991 | 8108 | if (// DrawMode() != 0 || /*tex == null ||*/ |
---|
7992 | 8109 | ambientOcclusion ) // || !textureon) |
---|
.. | .. |
---|
7997 | 8114 | CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null; |
---|
7998 | 8115 | |
---|
7999 | 8116 | if (tex != null) |
---|
8000 | | - texture = textures.get(tex); |
---|
| 8117 | + texture = bump ? texturebump.get(tex) : texturepigment.get(tex); |
---|
8001 | 8118 | |
---|
8002 | 8119 | // //assert( texture != null ); |
---|
8003 | 8120 | // if (texture == null) |
---|
.. | .. |
---|
8091 | 8208 | |
---|
8092 | 8209 | /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE |
---|
8093 | 8210 | { |
---|
8094 | | - if (// DrawMode() != 0 || /*tex == null ||*/ |
---|
8095 | | - ambientOcclusion ) // || !textureon) |
---|
8096 | | - { |
---|
8097 | | - return; // false; |
---|
8098 | | - } |
---|
8099 | | - |
---|
8100 | | - if (tex == null) |
---|
8101 | | - { |
---|
8102 | | - BindTexture(null,false,resolution); |
---|
8103 | | - BindTexture(null,true,resolution); |
---|
8104 | | - return; |
---|
8105 | | - } |
---|
| 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; |
---|
8106 | 8252 | |
---|
8107 | | - String pigment = Object3D.GetPigment(tex); |
---|
8108 | | - String bump = Object3D.GetBump(tex); |
---|
8109 | | - |
---|
8110 | | - usedtextures.put(pigment, pigment); |
---|
8111 | | - usedtextures.put(bump, bump); |
---|
8112 | | - |
---|
8113 | | - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
8114 | | - { |
---|
8115 | | - // System.out.print("BIND +++++++++++++++ pigment = " + pigment); |
---|
8116 | | - // System.out.println("; bump = " + bump); |
---|
8117 | | - } |
---|
8118 | | - |
---|
8119 | | - if (bump.equals("")) |
---|
8120 | | - { |
---|
8121 | | - bump = null; |
---|
8122 | | - } |
---|
8123 | | - if (pigment.equals("")) |
---|
8124 | | - { |
---|
8125 | | - pigment = null; |
---|
8126 | | - } |
---|
8127 | | - |
---|
8128 | | - GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
8129 | | - BindTexture(pigment, false, resolution); |
---|
8130 | | - GetGL().glActiveTexture(GetGL().GL_TEXTURE2); |
---|
8131 | | - BindTexture(bump, true, resolution); |
---|
8132 | | - GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
8133 | | - |
---|
8134 | | - return; // true; |
---|
| 8253 | + BindPigmentTexture(tex, resolution); |
---|
| 8254 | + BindBumpTexture(tex, resolution); |
---|
8135 | 8255 | } |
---|
8136 | 8256 | |
---|
8137 | 8257 | /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE |
---|
.. | .. |
---|
8150 | 8270 | |
---|
8151 | 8271 | String pigment = Object3D.GetPigment(tex); |
---|
8152 | 8272 | |
---|
8153 | | - usedtextures.put(pigment, pigment); |
---|
| 8273 | + usedtextures.add(tex); |
---|
8154 | 8274 | |
---|
8155 | | - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8275 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
8156 | 8276 | { |
---|
8157 | 8277 | // System.out.print("BIND +++++++++++++++ pigment = " + pigment); |
---|
8158 | 8278 | // System.out.println("; bump = " + bump); |
---|
.. | .. |
---|
8164 | 8284 | } |
---|
8165 | 8285 | |
---|
8166 | 8286 | GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
8167 | | - BindTexture(pigment, false, resolution); |
---|
| 8287 | + BindTexture(tex, false, resolution); |
---|
8168 | 8288 | } |
---|
8169 | 8289 | |
---|
8170 | 8290 | /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE |
---|
.. | .. |
---|
8183 | 8303 | |
---|
8184 | 8304 | String bump = Object3D.GetBump(tex); |
---|
8185 | 8305 | |
---|
8186 | | - usedtextures.put(bump, bump); |
---|
| 8306 | + usedtextures.add(tex); |
---|
8187 | 8307 | |
---|
8188 | | - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8308 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
8189 | 8309 | { |
---|
8190 | 8310 | // System.out.print("BIND +++++++++++++++ pigment = " + pigment); |
---|
8191 | 8311 | // System.out.println("; bump = " + bump); |
---|
.. | .. |
---|
8197 | 8317 | } |
---|
8198 | 8318 | |
---|
8199 | 8319 | GetGL().glActiveTexture(GetGL().GL_TEXTURE2); |
---|
8200 | | - BindTexture(bump, true, resolution); |
---|
| 8320 | + BindTexture(tex, true, resolution); |
---|
8201 | 8321 | GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
8202 | 8322 | } |
---|
8203 | 8323 | |
---|
.. | .. |
---|
8221 | 8341 | return fileExists; |
---|
8222 | 8342 | } |
---|
8223 | 8343 | |
---|
8224 | | - CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception |
---|
| 8344 | + CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8225 | 8345 | { |
---|
8226 | | - CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null; |
---|
| 8346 | + CacheTexture texturecache = null; |
---|
8227 | 8347 | |
---|
8228 | 8348 | if (tex != null) |
---|
8229 | 8349 | { |
---|
8230 | | - 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 | + } |
---|
8231 | 8357 | |
---|
8232 | 8358 | String fallbackTextureName = defaultDirectory + "/Textures/" + texname; |
---|
8233 | 8359 | |
---|
.. | .. |
---|
8237 | 8363 | // else |
---|
8238 | 8364 | // if (!texname.startsWith("/")) |
---|
8239 | 8365 | // texname = "/Users/nbriere/Textures/" + texname; |
---|
8240 | | - if (!FileExists(tex)) |
---|
| 8366 | + if (!FileExists(texname) && !texname.startsWith("@")) |
---|
8241 | 8367 | { |
---|
8242 | 8368 | texname = fallbackTextureName; |
---|
8243 | 8369 | } |
---|
8244 | 8370 | |
---|
8245 | 8371 | if (CACHETEXTURE) |
---|
8246 | | - texture = textures.get(texname); // TEXTURE CACHE |
---|
8247 | | - |
---|
8248 | | - TextureData texturedata = null; |
---|
8249 | | - |
---|
8250 | | - if (texture == null || texture.resolution < resolution) |
---|
8251 | 8372 | { |
---|
8252 | | - 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("")) |
---|
8253 | 8406 | { |
---|
8254 | 8407 | assert(!bump); |
---|
8255 | 8408 | // if (bump) |
---|
.. | .. |
---|
8260 | 8413 | // } |
---|
8261 | 8414 | // else |
---|
8262 | 8415 | // { |
---|
8263 | | - texture = textures.get(tex); |
---|
8264 | | - if (texture == null) |
---|
| 8416 | + // texturecache = textures.get(texname); // suspicious |
---|
| 8417 | + if (texturecache == null) |
---|
8265 | 8418 | { |
---|
8266 | | - texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
| 8419 | + texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
8267 | 8420 | } |
---|
| 8421 | + else |
---|
| 8422 | + new Exception().printStackTrace(); |
---|
8268 | 8423 | // } |
---|
8269 | 8424 | } else |
---|
8270 | | - if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals("")) |
---|
| 8425 | + if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals("")) |
---|
8271 | 8426 | { |
---|
8272 | 8427 | assert(bump); |
---|
8273 | | - texture = textures.get(tex); |
---|
8274 | | - if (texture == null) |
---|
8275 | | - 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(); |
---|
8276 | 8433 | } else |
---|
8277 | 8434 | { |
---|
8278 | 8435 | //if (tex.equals("IMMORTAL")) |
---|
.. | .. |
---|
8280 | 8437 | // texture = GetResourceTexture("default.png"); |
---|
8281 | 8438 | //} else |
---|
8282 | 8439 | //{ |
---|
8283 | | - if (tex.equals("WHITE_NOISE")) |
---|
| 8440 | + if (texname.endsWith("WHITE_NOISE")) |
---|
8284 | 8441 | { |
---|
8285 | | - texture = textures.get(tex); |
---|
8286 | | - if (texture == null) |
---|
8287 | | - 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(); |
---|
8288 | 8456 | } else |
---|
8289 | 8457 | { |
---|
8290 | 8458 | if (textureon) |
---|
.. | .. |
---|
8343 | 8511 | if (texturedata == null) |
---|
8344 | 8512 | throw new Exception(); |
---|
8345 | 8513 | |
---|
8346 | | - texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution); |
---|
| 8514 | + texturecache = new CacheTexture(texturedata,resolution); |
---|
8347 | 8515 | //texture = GetTexture(tex, bump); |
---|
8348 | 8516 | } |
---|
| 8517 | + } |
---|
8349 | 8518 | } |
---|
8350 | 8519 | //} |
---|
8351 | 8520 | } |
---|
8352 | 8521 | |
---|
8353 | | - if (/*CACHETEXTURE &&*/ texture != null && textureon) |
---|
| 8522 | + if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon) |
---|
8354 | 8523 | { |
---|
8355 | 8524 | //return false; |
---|
8356 | 8525 | |
---|
8357 | 8526 | // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")"); |
---|
8358 | | - if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG"))) |
---|
| 8527 | + if (texturedata != null && texname.toLowerCase().endsWith(".jpg")) |
---|
8359 | 8528 | { |
---|
8360 | 8529 | // String ext = "_highres"; |
---|
8361 | 8530 | // if (REDUCETEXTURE) |
---|
.. | .. |
---|
8372 | 8541 | File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg"); |
---|
8373 | 8542 | if (!cachefile.exists()) |
---|
8374 | 8543 | { |
---|
8375 | | - // cache to disk |
---|
8376 | | - Buffer buffer = texturedata.getBuffer(); // getMipmapData(); |
---|
8377 | | - //buffers[0]. |
---|
8378 | | - |
---|
8379 | | - ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer(); |
---|
8380 | | - int[] pixels = new int[bytebuf.capacity()/3]; |
---|
8381 | | - |
---|
8382 | | - // squared size heuristic... |
---|
8383 | | - if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length)) |
---|
| 8544 | + //if (texturedata.getWidth() == texturedata.getHeight()) |
---|
8384 | 8545 | { |
---|
8385 | | - for (int i=pixels.length; --i>=0;) |
---|
8386 | | - { |
---|
8387 | | - int i3 = i*3; |
---|
8388 | | - pixels[i] = 0xFF; |
---|
8389 | | - pixels[i] <<= 8; |
---|
8390 | | - pixels[i] |= bytebuf.get(i3+2) & 0xFF; |
---|
8391 | | - pixels[i] <<= 8; |
---|
8392 | | - pixels[i] |= bytebuf.get(i3+1) & 0xFF; |
---|
8393 | | - pixels[i] <<= 8; |
---|
8394 | | - pixels[i] |= bytebuf.get(i3) & 0xFF; |
---|
8395 | | - } |
---|
8396 | | - |
---|
8397 | | - /* |
---|
8398 | | - int r=0,g=0,b=0,a=0; |
---|
8399 | | - for (int i=0; i<width; i++) |
---|
8400 | | - for (int j=0; j<height; j++) |
---|
8401 | | - { |
---|
8402 | | - int index = j*width+i; |
---|
8403 | | - int p = pixels[index]; |
---|
8404 | | - a = ((p>>24) & 0xFF); |
---|
8405 | | - r = ((p>>16) & 0xFF); |
---|
8406 | | - g = ((p>>8) & 0xFF); |
---|
8407 | | - b = (p & 0xFF); |
---|
8408 | | - pixels[index] = (a<<24) | (b<<16) | (g<<8) | r; |
---|
8409 | | - } |
---|
8410 | | - /**/ |
---|
8411 | | - int width = (int)Math.sqrt(pixels.length); // squared |
---|
8412 | | - int height = width; |
---|
8413 | | - BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile); |
---|
8414 | | - rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width); |
---|
| 8546 | + BufferedImage rendImage = CreateBim(texturedata); |
---|
| 8547 | + |
---|
8415 | 8548 | ImageWriter writer = null; |
---|
8416 | 8549 | Iterator iter = ImageIO.getImageWritersByFormatName("jpg"); |
---|
8417 | 8550 | if (iter.hasNext()) { |
---|
8418 | 8551 | writer = (ImageWriter)iter.next(); |
---|
8419 | 8552 | } |
---|
8420 | | - float compressionQuality = 0.9f; |
---|
| 8553 | + |
---|
| 8554 | + float compressionQuality = 0.85f; |
---|
8421 | 8555 | try |
---|
8422 | 8556 | { |
---|
8423 | 8557 | ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile); |
---|
.. | .. |
---|
8434 | 8568 | } |
---|
8435 | 8569 | } |
---|
8436 | 8570 | } |
---|
8437 | | - |
---|
| 8571 | + |
---|
| 8572 | + Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment; |
---|
| 8573 | + |
---|
8438 | 8574 | //System.out.println("Texture = " + tex); |
---|
8439 | | - if (textures.containsKey(texname)) |
---|
| 8575 | + if (textures.containsKey(tex)) |
---|
8440 | 8576 | { |
---|
8441 | | - CacheTexture thetex = textures.get(texname); |
---|
| 8577 | + CacheTexture thetex = textures.get(tex); |
---|
8442 | 8578 | thetex.texture.disable(); |
---|
8443 | 8579 | thetex.texture.dispose(); |
---|
8444 | | - textures.remove(texname); |
---|
| 8580 | + textures.remove(tex); |
---|
8445 | 8581 | } |
---|
8446 | 8582 | |
---|
8447 | | - texture.texturedata = texturedata; |
---|
8448 | | - textures.put(texname, texture); |
---|
| 8583 | + //texture.texturedata = texturedata; |
---|
| 8584 | + textures.put(tex, texturecache); |
---|
8449 | 8585 | |
---|
8450 | 8586 | // newtex = true; |
---|
8451 | 8587 | } |
---|
.. | .. |
---|
8461 | 8597 | } |
---|
8462 | 8598 | } |
---|
8463 | 8599 | |
---|
8464 | | - return texture; |
---|
| 8600 | + return texturecache; |
---|
8465 | 8601 | } |
---|
8466 | 8602 | |
---|
8467 | | - 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 |
---|
8468 | 8638 | { |
---|
8469 | 8639 | CacheTexture texture = GetCacheTexture(tex, bump, resolution); |
---|
8470 | 8640 | |
---|
.. | .. |
---|
8482 | 8652 | return texture!=null?texture.texture:null; |
---|
8483 | 8653 | } |
---|
8484 | 8654 | |
---|
8485 | | - 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 |
---|
8486 | 8656 | { |
---|
8487 | 8657 | CacheTexture texture = GetCacheTexture(tex, bump, resolution); |
---|
8488 | 8658 | |
---|
8489 | 8659 | return texture!=null?texture.texturedata:null; |
---|
8490 | 8660 | } |
---|
8491 | 8661 | |
---|
8492 | | - boolean BindTexture(String tex, boolean bump, int resolution) throws Exception |
---|
| 8662 | + boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8493 | 8663 | { |
---|
8494 | 8664 | if (/*tex == null ||*/ ambientOcclusion ) // || !textureon) |
---|
8495 | 8665 | { |
---|
8496 | 8666 | return false; |
---|
8497 | 8667 | } |
---|
8498 | 8668 | |
---|
8499 | | - boolean newtex = false; |
---|
| 8669 | + //boolean newtex = false; |
---|
8500 | 8670 | |
---|
8501 | 8671 | com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution); |
---|
8502 | 8672 | |
---|
.. | .. |
---|
8528 | 8698 | texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT); |
---|
8529 | 8699 | texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT); |
---|
8530 | 8700 | |
---|
8531 | | - return newtex; |
---|
| 8701 | + return true; // Warning: not used. |
---|
8532 | 8702 | } |
---|
8533 | 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 | + |
---|
8534 | 8770 | ShadowBuffer shadowPBuf; |
---|
8535 | 8771 | AntialiasBuffer antialiasPBuf; |
---|
8536 | 8772 | int MAXSTACK; |
---|
.. | .. |
---|
8547 | 8783 | |
---|
8548 | 8784 | gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0); |
---|
8549 | 8785 | MAXSTACK = temp[0]; |
---|
8550 | | - System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK); |
---|
| 8786 | + if (Globals.DEBUG) |
---|
| 8787 | + System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK); |
---|
8551 | 8788 | gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0); |
---|
8552 | 8789 | MAXSTACK = temp[0]; |
---|
8553 | | - System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK); |
---|
| 8790 | + if (Globals.DEBUG) |
---|
| 8791 | + System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK); |
---|
8554 | 8792 | |
---|
8555 | 8793 | // Use debug pipeline |
---|
8556 | 8794 | //drawable.setGL(new DebugGL(gl)); // |
---|
.. | .. |
---|
8558 | 8796 | gl = drawable.getGL(); // |
---|
8559 | 8797 | |
---|
8560 | 8798 | GL gl3 = getGL(); |
---|
8561 | | - System.out.println("INIT GL IS: " + gl.getClass().getName()); |
---|
| 8799 | + if (Globals.DEBUG) |
---|
| 8800 | + System.out.println("INIT GL IS: " + gl.getClass().getName()); |
---|
8562 | 8801 | |
---|
8563 | 8802 | |
---|
8564 | 8803 | //float pos[] = { 100, 100, 100, 0 }; |
---|
.. | .. |
---|
8723 | 8962 | |
---|
8724 | 8963 | if (cubemap == null) |
---|
8725 | 8964 | { |
---|
8726 | | - LoadEnvy(5); |
---|
| 8965 | + //LoadEnvy(1); |
---|
8727 | 8966 | } |
---|
8728 | 8967 | |
---|
8729 | 8968 | //cubemap.enable(); |
---|
.. | .. |
---|
8999 | 9238 | |
---|
9000 | 9239 | void LoadEnvy(int which) |
---|
9001 | 9240 | { |
---|
| 9241 | + assert(false); |
---|
| 9242 | + |
---|
9002 | 9243 | String name; |
---|
9003 | 9244 | String ext; |
---|
9004 | 9245 | |
---|
.. | .. |
---|
9010 | 9251 | cubemap = null; |
---|
9011 | 9252 | return; |
---|
9012 | 9253 | case 1: |
---|
9013 | | - name = "cubemaps/box_"; |
---|
9014 | | - ext = "png"; |
---|
| 9254 | + name = "cubemaps/rgb/"; |
---|
| 9255 | + ext = "jpg"; |
---|
9015 | 9256 | reverseUP = false; |
---|
9016 | 9257 | break; |
---|
9017 | 9258 | case 2: |
---|
9018 | | - name = "cubemaps/uffizi_"; |
---|
9019 | | - ext = "png"; |
---|
9020 | | - break; // reverseUP = true; break; |
---|
| 9259 | + name = "cubemaps/uffizi/"; |
---|
| 9260 | + ext = "jpg"; |
---|
| 9261 | + reverseUP = false; |
---|
| 9262 | + break; |
---|
9021 | 9263 | case 3: |
---|
9022 | | - name = "cubemaps/CloudyHills_"; |
---|
9023 | | - ext = "tga"; |
---|
| 9264 | + name = "cubemaps/CloudyHills/"; |
---|
| 9265 | + ext = "jpg"; |
---|
9024 | 9266 | reverseUP = false; |
---|
9025 | 9267 | break; |
---|
9026 | 9268 | case 4: |
---|
9027 | | - name = "cubemaps/cornell_"; |
---|
| 9269 | + name = "cubemaps/cornell/"; |
---|
9028 | 9270 | ext = "png"; |
---|
9029 | 9271 | reverseUP = false; |
---|
9030 | 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; |
---|
9031 | 9298 | default: |
---|
9032 | | - name = "cubemaps/rgb_"; |
---|
9033 | | - ext = "png"; /*mipmap = true;*/ reverseUP = false; |
---|
| 9299 | + name = "cubemaps/box/"; |
---|
| 9300 | + ext = "png"; /*mipmap = true;*/ |
---|
| 9301 | + reverseUP = false; |
---|
9034 | 9302 | break; |
---|
9035 | 9303 | } |
---|
9036 | | - |
---|
9037 | | - try |
---|
9038 | | - { |
---|
9039 | | - cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap); |
---|
9040 | | - } catch (IOException e) |
---|
9041 | | - { |
---|
9042 | | - throw new RuntimeException(e); |
---|
9043 | | - } |
---|
| 9304 | + |
---|
| 9305 | + LoadSkybox(name, ext, mipmap); |
---|
9044 | 9306 | } |
---|
9045 | 9307 | |
---|
9046 | 9308 | public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) |
---|
.. | .. |
---|
9072 | 9334 | static double[] model = new double[16]; |
---|
9073 | 9335 | double[] camera2light = new double[16]; |
---|
9074 | 9336 | double[] light2camera = new double[16]; |
---|
9075 | | - int newenvy = -1; |
---|
9076 | | - boolean envyoff = true; // false; |
---|
| 9337 | + |
---|
| 9338 | + //int newenvy = -1; |
---|
| 9339 | + //boolean envyoff = false; |
---|
| 9340 | + |
---|
| 9341 | + String loadedskyboxname; |
---|
| 9342 | + |
---|
9077 | 9343 | cVector light0 = new cVector(0, 0, 0); // 1,3,2); |
---|
9078 | 9344 | //float[] light0 = { 0,0,0 }; |
---|
9079 | 9345 | cVector dirlight = new cVector(0, 0, 1); // 1,3,2); |
---|
.. | .. |
---|
9366 | 9632 | jy8[3] = 0.5f; |
---|
9367 | 9633 | } |
---|
9368 | 9634 | |
---|
9369 | | - float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV |
---|
| 9635 | + float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV |
---|
9370 | 9636 | float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation |
---|
9371 | 9637 | float[] options3 = new float[]{1, 1, 1, 0}; // fog color |
---|
9372 | 9638 | float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen |
---|
9373 | 9639 | |
---|
| 9640 | + void ResetOptions() |
---|
| 9641 | + { |
---|
| 9642 | + options1[0] = 100; |
---|
| 9643 | + options1[1] = 0.025f; |
---|
| 9644 | + options1[2] = 0.01f; |
---|
| 9645 | + options1[3] = 0; |
---|
| 9646 | + options1[4] = 0; |
---|
| 9647 | + |
---|
| 9648 | + options2[0] = 0; |
---|
| 9649 | + options2[1] = 0.75f; |
---|
| 9650 | + options2[2] = 0; |
---|
| 9651 | + options2[3] = 0; |
---|
| 9652 | + |
---|
| 9653 | + options3[0] = 1; |
---|
| 9654 | + options3[1] = 1; |
---|
| 9655 | + options3[2] = 1; |
---|
| 9656 | + options3[3] = 0; |
---|
| 9657 | + |
---|
| 9658 | + options4[0] = 1; |
---|
| 9659 | + options4[1] = 0; |
---|
| 9660 | + options4[2] = 1; |
---|
| 9661 | + options4[3] = 0; |
---|
| 9662 | + } |
---|
| 9663 | + |
---|
9374 | 9664 | static int imagecount = 0; // movie generation |
---|
9375 | 9665 | |
---|
9376 | 9666 | static int jitter = 0; |
---|
.. | .. |
---|
9467 | 9757 | |
---|
9468 | 9758 | if (renderCamera != lightCamera) |
---|
9469 | 9759 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
9470 | | - LA.matConcat(matrix, parentcam.GlobalTransform(), matrix); |
---|
| 9760 | + LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix); |
---|
9471 | 9761 | |
---|
9472 | 9762 | // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix); |
---|
9473 | 9763 | |
---|
.. | .. |
---|
9483 | 9773 | |
---|
9484 | 9774 | if (renderCamera != lightCamera) |
---|
9485 | 9775 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
9486 | | - LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix); |
---|
| 9776 | + LA.matConcat(parentcam.GlobalTransform(), matrix, matrix); |
---|
9487 | 9777 | |
---|
9488 | 9778 | // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix); |
---|
9489 | 9779 | |
---|
.. | .. |
---|
9529 | 9819 | rati = 1 / rati; |
---|
9530 | 9820 | gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000); |
---|
9531 | 9821 | } |
---|
9532 | | - assert (newenvy == -1); |
---|
| 9822 | + |
---|
| 9823 | + //assert (newenvy == -1); |
---|
| 9824 | + |
---|
9533 | 9825 | gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
9534 | 9826 | gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB); |
---|
9535 | | - DrawSkyBox(gl); |
---|
| 9827 | + DrawSkyBox(gl, (float)rati); |
---|
9536 | 9828 | gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
9537 | 9829 | gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB); |
---|
9538 | 9830 | accPerspective(gl, renderCamera.shaper_fovy / ratio, |
---|
.. | .. |
---|
10398 | 10690 | static boolean init = false; |
---|
10399 | 10691 | |
---|
10400 | 10692 | double[][] matrix = LA.newMatrix(); |
---|
| 10693 | + |
---|
| 10694 | + // This is to refresh the UI of the material panel. |
---|
| 10695 | + ObjEditor patchMaterial; |
---|
10401 | 10696 | |
---|
10402 | 10697 | public void display(GLAutoDrawable drawable) |
---|
10403 | 10698 | { |
---|
| 10699 | + if (patchMaterial.patchMaterial) |
---|
| 10700 | + { |
---|
| 10701 | + patchMaterial.patchMaterial = false; |
---|
| 10702 | + patchMaterial.objectPanel.setSelectedIndex(0); |
---|
| 10703 | + } |
---|
| 10704 | + |
---|
10404 | 10705 | if (Grafreed.savesound && Grafreed.hassound) |
---|
10405 | 10706 | { |
---|
10406 | 10707 | Grafreed.wav.save(); |
---|
.. | .. |
---|
10569 | 10870 | |
---|
10570 | 10871 | if (wait) |
---|
10571 | 10872 | { |
---|
10572 | | - Sleep(500); |
---|
| 10873 | + Sleep(200); // blocks everything |
---|
10573 | 10874 | |
---|
10574 | 10875 | wait = false; |
---|
10575 | 10876 | } |
---|
.. | .. |
---|
10684 | 10985 | // if (parentcam != renderCamera) // not a light |
---|
10685 | 10986 | if (cam != lightCamera) |
---|
10686 | 10987 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
10687 | | - LA.matConcat(matrix, parentcam.GlobalTransform(), matrix); |
---|
| 10988 | + LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix); |
---|
10688 | 10989 | |
---|
10689 | 10990 | for (int j = 0; j < 4; j++) |
---|
10690 | 10991 | { |
---|
.. | .. |
---|
10699 | 11000 | // if (parentcam != renderCamera) // not a light |
---|
10700 | 11001 | if (cam != lightCamera) |
---|
10701 | 11002 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
10702 | | - LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix); |
---|
| 11003 | + LA.matConcat(parentcam.GlobalTransform(), matrix, matrix); |
---|
10703 | 11004 | |
---|
10704 | 11005 | //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix); |
---|
10705 | 11006 | |
---|
.. | .. |
---|
10785 | 11086 | gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000); |
---|
10786 | 11087 | } |
---|
10787 | 11088 | |
---|
10788 | | - if (newenvy > -1) |
---|
| 11089 | +// if (newenvy > -1) |
---|
| 11090 | +// { |
---|
| 11091 | +// LoadEnvy(newenvy); |
---|
| 11092 | +// } |
---|
| 11093 | +// |
---|
| 11094 | +// newenvy = -1; |
---|
| 11095 | + |
---|
| 11096 | + if (transformMode) // object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb")) |
---|
10789 | 11097 | { |
---|
10790 | | - LoadEnvy(newenvy); |
---|
| 11098 | + if (cubemaprgb == null) |
---|
| 11099 | + { |
---|
| 11100 | + cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb2" + "/", "jpg", false); |
---|
| 11101 | + } |
---|
| 11102 | + |
---|
| 11103 | + cubemap = cubemaprgb; |
---|
10791 | 11104 | } |
---|
10792 | | - |
---|
10793 | | - newenvy = -1; |
---|
10794 | | - |
---|
| 11105 | + else |
---|
| 11106 | + { |
---|
| 11107 | + if (object.skyboxname != null) |
---|
| 11108 | + { |
---|
| 11109 | + if (!object.skyboxname.equals(this.loadedskyboxname)) |
---|
| 11110 | + { |
---|
| 11111 | + if (cubemap != null && cubemap != cubemaprgb) |
---|
| 11112 | + cubemap.dispose(); |
---|
| 11113 | + cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false); |
---|
| 11114 | + loadedskyboxname = object.skyboxname; |
---|
| 11115 | + } |
---|
| 11116 | + } |
---|
| 11117 | + else |
---|
| 11118 | + { |
---|
| 11119 | + cubemapcustom = null; |
---|
| 11120 | + loadedskyboxname = null; |
---|
| 11121 | + } |
---|
| 11122 | + |
---|
| 11123 | + cubemap = cubemapcustom; |
---|
| 11124 | + } |
---|
| 11125 | + |
---|
10795 | 11126 | ratio = ((double) getWidth()) / getHeight(); |
---|
10796 | 11127 | //System.out.println("ratio = " + ratio); |
---|
10797 | 11128 | |
---|
.. | .. |
---|
10807 | 11138 | |
---|
10808 | 11139 | if (!IsFrozen() && !ambientOcclusion) |
---|
10809 | 11140 | { |
---|
10810 | | - DrawSkyBox(gl); |
---|
| 11141 | + DrawSkyBox(gl, (float)ratio); |
---|
10811 | 11142 | } |
---|
10812 | 11143 | |
---|
10813 | 11144 | //if (selection_view == -1) |
---|
.. | .. |
---|
10990 | 11321 | |
---|
10991 | 11322 | gl.glMatrixMode(GL.GL_MODELVIEW); |
---|
10992 | 11323 | |
---|
10993 | | -//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST); |
---|
10994 | | -//gl.glEnable(gl.GL_POLYGON_SMOOTH); |
---|
10995 | | -//gl.glEnable(gl.GL_MULTISAMPLE); |
---|
| 11324 | +gl.glEnable(gl.GL_POLYGON_SMOOTH); |
---|
| 11325 | +gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST); |
---|
| 11326 | +gl.glEnable(gl.GL_MULTISAMPLE); |
---|
10996 | 11327 | } else |
---|
10997 | 11328 | { |
---|
10998 | 11329 | //gl.glDisable(GL.GL_TEXTURE_2D); |
---|
.. | .. |
---|
11003 | 11334 | //System.out.println("BLENDING ON"); |
---|
11004 | 11335 | gl.glEnable(GL.GL_BLEND); |
---|
11005 | 11336 | gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); |
---|
11006 | | - |
---|
| 11337 | +// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE); |
---|
11007 | 11338 | gl.glMatrixMode(gl.GL_PROJECTION); |
---|
11008 | 11339 | gl.glLoadIdentity(); |
---|
11009 | 11340 | |
---|
.. | .. |
---|
11093 | 11424 | |
---|
11094 | 11425 | // if (cam != lightCamera) |
---|
11095 | 11426 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
11096 | | - LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013 |
---|
| 11427 | + LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013 |
---|
11097 | 11428 | } |
---|
11098 | 11429 | |
---|
11099 | 11430 | LA.xformDir(lightposition, cam.toScreen, lightposition); |
---|
.. | .. |
---|
11252 | 11583 | } |
---|
11253 | 11584 | } |
---|
11254 | 11585 | |
---|
11255 | | - if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion) |
---|
| 11586 | + if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion) |
---|
11256 | 11587 | { |
---|
11257 | 11588 | //gl.glDepthFunc(GL.GL_LEQUAL); |
---|
11258 | 11589 | //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT); |
---|
.. | .. |
---|
11260 | 11591 | |
---|
11261 | 11592 | boolean texon = textureon; |
---|
11262 | 11593 | |
---|
11263 | | - if (RENDERPROGRAM > 0) |
---|
11264 | | - { |
---|
11265 | | - gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
11266 | | - textureon = false; |
---|
11267 | | - } |
---|
| 11594 | + gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
| 11595 | + textureon = false; |
---|
| 11596 | + |
---|
11268 | 11597 | //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB); |
---|
11269 | 11598 | //System.out.println("ALLO"); |
---|
11270 | 11599 | gl.glColorMask(false, false, false, false); |
---|
11271 | 11600 | DrawObject(gl); |
---|
11272 | | - if (RENDERPROGRAM > 0) |
---|
11273 | | - { |
---|
11274 | | - gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
11275 | | - textureon = texon; |
---|
11276 | | - } |
---|
| 11601 | + |
---|
| 11602 | + gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
| 11603 | + textureon = texon; |
---|
| 11604 | + |
---|
11277 | 11605 | gl.glColorMask(true, true, true, true); |
---|
11278 | 11606 | |
---|
11279 | 11607 | gl.glDepthFunc(GL.GL_EQUAL); |
---|
11280 | | - //gl.glDepthMask(false); |
---|
| 11608 | + gl.glDepthMask(false); |
---|
11281 | 11609 | } |
---|
11282 | 11610 | |
---|
11283 | 11611 | if (false) // DrawMode() == SHADOW) |
---|
.. | .. |
---|
11480 | 11808 | |
---|
11481 | 11809 | void DrawObject(GL gl, boolean draw) |
---|
11482 | 11810 | { |
---|
| 11811 | + // To clear camera values |
---|
| 11812 | + ResetOptions(); |
---|
| 11813 | + |
---|
11483 | 11814 | //System.out.println("DRAW OBJECT " + mouseDown); |
---|
11484 | 11815 | // DrawMode() = SELECTION; |
---|
11485 | 11816 | //GL gl = getGL(); |
---|
11486 | 11817 | if ((TRACK || SHADOWTRACK) || zoomonce) |
---|
11487 | 11818 | { |
---|
11488 | 11819 | if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode) |
---|
11489 | | - object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK); |
---|
| 11820 | + object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK); |
---|
11490 | 11821 | pingthread.StepToTarget(true); // true); |
---|
11491 | 11822 | // zoomonce = false; |
---|
11492 | 11823 | } |
---|
.. | .. |
---|
11614 | 11945 | ReleaseTextures(DEFAULT_TEXTURES); |
---|
11615 | 11946 | |
---|
11616 | 11947 | if (CLEANCACHE) |
---|
11617 | | - for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();) |
---|
| 11948 | + for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();) |
---|
11618 | 11949 | { |
---|
11619 | | - String tex = e.nextElement(); |
---|
| 11950 | + cTexture tex = e.nextElement(); |
---|
11620 | 11951 | |
---|
11621 | 11952 | // System.out.println("Texture --------- " + tex); |
---|
11622 | 11953 | |
---|
11623 | | - if (tex.equals("WHITE_NOISE")) |
---|
| 11954 | + if (tex.equals("WHITE_NOISE:")) |
---|
11624 | 11955 | continue; |
---|
11625 | 11956 | |
---|
11626 | | - if (!usedtextures.containsKey(tex)) |
---|
| 11957 | + if (!usedtextures.contains(tex)) |
---|
11627 | 11958 | { |
---|
| 11959 | + CacheTexture gettex = texturepigment.get(tex); |
---|
11628 | 11960 | // System.out.println("DISPOSE +++++++++++++++ " + tex); |
---|
11629 | | - textures.get(tex).texture.dispose(); |
---|
11630 | | - textures.remove(tex); |
---|
| 11961 | + if (gettex != null) |
---|
| 11962 | + { |
---|
| 11963 | + gettex.texture.dispose(); |
---|
| 11964 | + texturepigment.remove(tex); |
---|
| 11965 | + } |
---|
| 11966 | + |
---|
| 11967 | + gettex = texturebump.get(tex); |
---|
| 11968 | + // System.out.println("DISPOSE +++++++++++++++ " + tex); |
---|
| 11969 | + if (gettex != null) |
---|
| 11970 | + { |
---|
| 11971 | + gettex.texture.dispose(); |
---|
| 11972 | + texturebump.remove(tex); |
---|
| 11973 | + } |
---|
11631 | 11974 | } |
---|
11632 | 11975 | } |
---|
11633 | 11976 | } |
---|
.. | .. |
---|
12155 | 12498 | |
---|
12156 | 12499 | //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0); |
---|
12157 | 12500 | |
---|
12158 | | - String program = |
---|
| 12501 | + String programmin = |
---|
| 12502 | + // Min shader |
---|
12159 | 12503 | "!!ARBfp1.0\n" + |
---|
| 12504 | + "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" + |
---|
| 12505 | + "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" + |
---|
| 12506 | + "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" + |
---|
| 12507 | + "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" + |
---|
| 12508 | + "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" + |
---|
| 12509 | + "PARAM light2cam0 = program.env[10];" + |
---|
| 12510 | + "PARAM light2cam1 = program.env[11];" + |
---|
| 12511 | + "PARAM light2cam2 = program.env[12];" + |
---|
| 12512 | + "TEMP temp;" + |
---|
| 12513 | + "TEMP light;" + |
---|
| 12514 | + "TEMP ndotl;" + |
---|
| 12515 | + "TEMP normal;" + |
---|
| 12516 | + "TEMP depth;" + |
---|
| 12517 | + "TEMP eye;" + |
---|
| 12518 | + "TEMP pos;" + |
---|
| 12519 | + |
---|
| 12520 | + "MAD normal, fragment.color, zero123.z, -zero123.y;" + |
---|
| 12521 | + Normalize("normal") + |
---|
| 12522 | + "MOV light, state.light[0].position;" + |
---|
| 12523 | + "DP3 ndotl.x, light, normal;" + |
---|
| 12524 | + |
---|
| 12525 | + // shadow |
---|
| 12526 | + "MOV pos, fragment.texcoord[1];" + |
---|
| 12527 | + "MOV temp, pos;" + |
---|
| 12528 | + ShadowTextureFetch("depth", "temp", "1") + |
---|
| 12529 | + //"TEX depth, fragment.texcoord[1], texture[1], 2D;" + |
---|
| 12530 | + "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" + |
---|
| 12531 | + |
---|
| 12532 | + // No shadow when out of frustum |
---|
| 12533 | + //"SGE temp.y, depth.z, zero123.y;" + |
---|
| 12534 | + //"LRP temp.x, temp.y, zero123.y, temp.x;" + |
---|
| 12535 | + |
---|
| 12536 | + "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow |
---|
| 12537 | + |
---|
| 12538 | + // Backlit |
---|
| 12539 | + "MOV pos.w, zero123.y;" + |
---|
| 12540 | + "DP4 eye.x, pos, light2cam0;" + |
---|
| 12541 | + "DP4 eye.y, pos, light2cam1;" + |
---|
| 12542 | + "DP4 eye.z, pos, light2cam2;" + |
---|
| 12543 | + Normalize("eye") + |
---|
| 12544 | + |
---|
| 12545 | + "DP3 ndotl.y, -eye, normal;" + |
---|
| 12546 | + //"MUL ndotl.y, ndotl.y, pow2.x;" + |
---|
| 12547 | + "POW ndotl.y, ndotl.y, pow2.z;" + // backlit |
---|
| 12548 | + "SUB ndotl.y, zero123.y, ndotl.y;" + |
---|
| 12549 | + //"SUB ndotl.y, zero123.y, ndotl.y;" + |
---|
| 12550 | + //"MUL ndotl.y, ndotl.y, pow2.z;" + |
---|
| 12551 | + |
---|
| 12552 | + //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient |
---|
| 12553 | + //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient |
---|
| 12554 | + |
---|
| 12555 | + // Pigment |
---|
| 12556 | + "TEX temp, fragment.texcoord[0], texture[0], 2D;" + |
---|
| 12557 | + "LRP temp, zero123.w, temp, one;" + // texture proportion |
---|
| 12558 | + "MUL temp, temp, ndotl.x;" + |
---|
| 12559 | + |
---|
| 12560 | + "MUL temp, temp, zero123.z;" + |
---|
| 12561 | + |
---|
| 12562 | + //"MUL temp, temp, ndotl.y;" + |
---|
| 12563 | + |
---|
| 12564 | + "MOV temp.w, zero123.y;" + // reset alpha |
---|
| 12565 | + "MOV result.color, temp;" + |
---|
| 12566 | + "END"; |
---|
| 12567 | + |
---|
| 12568 | + String programmax = |
---|
| 12569 | + "!!ARBfp1.0\n" + |
---|
| 12570 | + |
---|
12160 | 12571 | //"OPTION ARB_fragment_program_shadow;" + |
---|
12161 | 12572 | "PARAM light2cam0 = program.env[10];" + |
---|
12162 | 12573 | "PARAM light2cam1 = program.env[11];" + |
---|
.. | .. |
---|
12271 | 12682 | "TEMP shininess;" + |
---|
12272 | 12683 | "\n" + |
---|
12273 | 12684 | "MOV texSamp, one;" + |
---|
12274 | | - //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" + |
---|
12275 | | - |
---|
| 12685 | + |
---|
12276 | 12686 | "MOV mapgrid.x, one2048th.x;" + |
---|
12277 | 12687 | "MOV temp, fragment.texcoord[1];" + |
---|
12278 | 12688 | /* |
---|
.. | .. |
---|
12293 | 12703 | "MUL temp, floor, mapgrid.x;" + |
---|
12294 | 12704 | //"TEX depth0, temp, texture[1], 2D;" + |
---|
12295 | 12705 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12296 | | - TextureFetch("depth0", "temp", "1") + |
---|
| 12706 | + ShadowTextureFetch("depth0", "temp", "1") + |
---|
12297 | 12707 | "") + |
---|
12298 | 12708 | "ADD temp.x, temp.x, mapgrid.x;" + |
---|
12299 | 12709 | //"TEX depth1, temp, texture[1], 2D;" + |
---|
12300 | 12710 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12301 | | - TextureFetch("depth1", "temp", "1") + |
---|
| 12711 | + ShadowTextureFetch("depth1", "temp", "1") + |
---|
12302 | 12712 | "") + |
---|
12303 | 12713 | "ADD temp.y, temp.y, mapgrid.x;" + |
---|
12304 | 12714 | //"TEX depth2, temp, texture[1], 2D;" + |
---|
12305 | | - TextureFetch("depth2", "temp", "1") + |
---|
| 12715 | + ShadowTextureFetch("depth2", "temp", "1") + |
---|
12306 | 12716 | "SUB temp.x, temp.x, mapgrid.x;" + |
---|
12307 | 12717 | //"TEX depth3, temp, texture[1], 2D;" + |
---|
12308 | 12718 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12309 | | - TextureFetch("depth3", "temp", "1") + |
---|
| 12719 | + ShadowTextureFetch("depth3", "temp", "1") + |
---|
12310 | 12720 | "") + |
---|
12311 | 12721 | //"MUL texSamp0, texSamp0, state.material.front.diffuse;" + |
---|
12312 | 12722 | //"MOV params, material;" + |
---|
.. | .. |
---|
12677 | 13087 | "MAD shadow.x, buffer.x, frac.y, shadow.x;" + |
---|
12678 | 13088 | "") + |
---|
12679 | 13089 | |
---|
12680 | | - // display shadow only (bump == 0) |
---|
| 13090 | + // display shadow only (fakedepth == 0) |
---|
12681 | 13091 | "SUB temp.x, half.x, shadow.x;" + |
---|
12682 | 13092 | "MOV temp.y, -params5.z;" + // params6.x;" + |
---|
12683 | | - "SLT temp.z, temp.y, -one2048th.x;" + |
---|
| 13093 | + "SLT temp.z, temp.y, -c256i.x;" + |
---|
12684 | 13094 | "SUB temp.y, one.x, temp.z;" + |
---|
12685 | 13095 | "MUL temp.x, temp.x, temp.y;" + |
---|
12686 | 13096 | "KIL temp.x;" + |
---|
.. | .. |
---|
13011 | 13421 | //once = true; |
---|
13012 | 13422 | } |
---|
13013 | 13423 | |
---|
13014 | | - System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length()); |
---|
13015 | | - System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : "")); |
---|
| 13424 | + String program = programmax; |
---|
| 13425 | + |
---|
| 13426 | + if (Globals.MINSHADER) |
---|
| 13427 | + { |
---|
| 13428 | + program = programmin; |
---|
| 13429 | + } |
---|
| 13430 | + |
---|
| 13431 | + if (Globals.DEBUG) |
---|
| 13432 | + { |
---|
| 13433 | + System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length()); |
---|
| 13434 | + System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : "")); |
---|
| 13435 | + } |
---|
| 13436 | + |
---|
13016 | 13437 | loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program); |
---|
13017 | 13438 | |
---|
13018 | 13439 | //gl.glNewList(displayListID, GL.GL_COMPILE); |
---|
.. | .. |
---|
13059 | 13480 | "\n" + |
---|
13060 | 13481 | "END\n"; |
---|
13061 | 13482 | |
---|
13062 | | - System.out.println("Program shadow #" + 0 + "; length = " + program.length()); |
---|
| 13483 | + if (Globals.DEBUG) |
---|
| 13484 | + System.out.println("Program shadow #" + 0 + "; length = " + program.length()); |
---|
13063 | 13485 | loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program); |
---|
13064 | 13486 | |
---|
13065 | 13487 | //gl.glNewList(displayListID, GL.GL_COMPILE); |
---|
.. | .. |
---|
13104 | 13526 | return out; |
---|
13105 | 13527 | } |
---|
13106 | 13528 | |
---|
13107 | | - String TextureFetch(String dest, String src, String unit) |
---|
| 13529 | + // Also does frustum culling |
---|
| 13530 | + String ShadowTextureFetch(String dest, String src, String unit) |
---|
13108 | 13531 | { |
---|
13109 | 13532 | return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" + |
---|
13110 | 13533 | "SGE " + src + ".w, " + src + ".x, eps.x;" + |
---|
13111 | 13534 | "SGE " + src + ".z, " + src + ".y, eps.x;" + |
---|
| 13535 | + "SLT " + dest + ".x, " + src + ".x, one.x;" + |
---|
| 13536 | + "SLT " + dest + ".y, " + src + ".y, one.x;" + |
---|
13112 | 13537 | "MUL " + src + ".w, " + src + ".z, " + src + ".w;" + |
---|
13113 | | - "SLT " + src + ".z, " + src + ".x, one.x;" + |
---|
13114 | | - "MUL " + src + ".w, " + src + ".z, " + src + ".w;" + |
---|
13115 | | - "SLT " + src + ".z, " + src + ".y, one.x;" + |
---|
13116 | | - "MUL " + src + ".w, " + src + ".z, " + src + ".w;" + |
---|
| 13538 | + "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" + |
---|
| 13539 | + "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" + |
---|
13117 | 13540 | //"SWZ buffer, temp, w,w,w,w;"; |
---|
13118 | | - "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" + |
---|
| 13541 | + //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" + |
---|
13119 | 13542 | "SUB " + src + ".z, " + "one.x, " + src + ".w;" + |
---|
13120 | 13543 | //"MUL " + src + ".z, " + src + ".z, infinity.x;" + |
---|
13121 | 13544 | //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;"; |
---|
13122 | | - "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
| 13545 | + //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
13123 | 13546 | |
---|
13124 | | - //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;"; |
---|
13125 | | - //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;"; |
---|
| 13547 | + //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;"; |
---|
| 13548 | + "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
13126 | 13549 | } |
---|
13127 | 13550 | |
---|
13128 | 13551 | String Shadow(String depth, String shadow) |
---|
.. | .. |
---|
13169 | 13592 | "SLT temp.x, temp.x, zero.x;" + // shadoweps |
---|
13170 | 13593 | "LRP " + shadow + ", temp.x, one, " + shadow + ";" + |
---|
13171 | 13594 | |
---|
13172 | | - // No shadow when out of frustrum |
---|
| 13595 | + // No shadow when out of frustum |
---|
13173 | 13596 | "SGE temp.x, " + depth + ".z, one.z;" + |
---|
13174 | 13597 | "LRP " + shadow + ", temp.x, one, " + shadow + ";" + |
---|
13175 | 13598 | ""; |
---|
.. | .. |
---|
13334 | 13757 | "DP3 " + dest + ".z," + "normals," + "eye;" + |
---|
13335 | 13758 | "MAX " + dest + ".w," + dest + ".z," + "eps.x;" + |
---|
13336 | 13759 | //"MOV " + dest + ".w," + "normal.z;" + |
---|
13337 | | - "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + |
---|
13338 | | - "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" + |
---|
13339 | | - //"MOV " + dest + ".z," + "params2.w;" + |
---|
| 13760 | +// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET |
---|
| 13761 | +// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" + |
---|
| 13762 | + |
---|
| 13763 | + "MOV " + dest + ".z," + "params2.w;" + // EXACT |
---|
13340 | 13764 | "POW " + dest + ".w," + dest + ".w," + dest + ".z;" + |
---|
13341 | 13765 | "RCP " + dest + ".w," + dest + ".w;" + |
---|
13342 | 13766 | //"RSQ " + dest + ".w," + dest + ".w;" + |
---|
.. | .. |
---|
13901 | 14325 | |
---|
13902 | 14326 | // fev 2014??? |
---|
13903 | 14327 | if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode) |
---|
13904 | | - object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK); |
---|
| 14328 | + object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK); |
---|
13905 | 14329 | pingthread.StepToTarget(true); // true); |
---|
13906 | 14330 | } |
---|
13907 | 14331 | // if (!LIVE) |
---|
.. | .. |
---|
13966 | 14390 | drag = false; |
---|
13967 | 14391 | //System.out.println("Mouse DOWN"); |
---|
13968 | 14392 | editObj = false; |
---|
13969 | | - ClickInfo info = new ClickInfo(); |
---|
13970 | | - info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
13971 | | - info.pane = this; |
---|
13972 | | - info.camera = renderCamera; |
---|
13973 | | - info.x = x; |
---|
13974 | | - info.y = y; |
---|
13975 | | - info.modifiers = modifiersex; |
---|
13976 | | - editObj = object.doEditClick(info, 0); |
---|
| 14393 | + //ClickInfo info = new ClickInfo(); |
---|
| 14394 | + object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
| 14395 | + object.clickInfo.pane = this; |
---|
| 14396 | + object.clickInfo.camera = renderCamera; |
---|
| 14397 | + object.clickInfo.x = x; |
---|
| 14398 | + object.clickInfo.y = y; |
---|
| 14399 | + object.clickInfo.modifiers = modifiersex; |
---|
| 14400 | + editObj = object.doEditClick(//info, |
---|
| 14401 | + 0); |
---|
13977 | 14402 | if (!editObj) |
---|
13978 | 14403 | { |
---|
13979 | 14404 | hasMarquee = true; |
---|
.. | .. |
---|
14255 | 14680 | void GoDown(int mod) |
---|
14256 | 14681 | { |
---|
14257 | 14682 | MODIFIERS |= COMMAND; |
---|
14258 | | - /* |
---|
| 14683 | + boolean isVR = (mouseMode&VR)!=0; |
---|
| 14684 | + /**/ |
---|
14259 | 14685 | if((mod&SHIFT) == SHIFT) |
---|
14260 | | - manipCamera.RotatePosition(0, -speed); |
---|
| 14686 | + { |
---|
| 14687 | + if (isVR) |
---|
| 14688 | + manipCamera.RotateInterest(0, -speed); |
---|
| 14689 | + else |
---|
| 14690 | + manipCamera.RotatePosition(0, -speed); |
---|
| 14691 | + } |
---|
14261 | 14692 | else |
---|
14262 | | - manipCamera.BackForth(0, -speed*delta, getWidth()); |
---|
14263 | | - */ |
---|
| 14693 | + manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth()); |
---|
| 14694 | + /**/ |
---|
14264 | 14695 | if ((mod & SHIFT) == SHIFT) |
---|
14265 | 14696 | { |
---|
14266 | 14697 | mouseMode = mouseMode; // VR?? |
---|
.. | .. |
---|
14269 | 14700 | mouseMode |= BACKFORTH; |
---|
14270 | 14701 | } |
---|
14271 | 14702 | |
---|
| 14703 | + targetLookAt.set(manipCamera.lookAt); |
---|
| 14704 | + |
---|
14272 | 14705 | //prevX = X = anchorX; |
---|
14273 | 14706 | prevY = Y = anchorY - (int) (renderCamera.Distance()); |
---|
14274 | 14707 | } |
---|
.. | .. |
---|
14276 | 14709 | void GoUp(int mod) |
---|
14277 | 14710 | { |
---|
14278 | 14711 | MODIFIERS |= COMMAND; |
---|
14279 | | - /* |
---|
| 14712 | + /**/ |
---|
| 14713 | + boolean isVR = (mouseMode&VR)!=0; |
---|
| 14714 | + |
---|
14280 | 14715 | if((mod&SHIFT) == SHIFT) |
---|
14281 | | - manipCamera.RotatePosition(0, speed); |
---|
| 14716 | + { |
---|
| 14717 | + if (isVR) |
---|
| 14718 | + manipCamera.RotateInterest(0, speed); |
---|
| 14719 | + else |
---|
| 14720 | + manipCamera.RotatePosition(0, speed); |
---|
| 14721 | + } |
---|
14282 | 14722 | else |
---|
14283 | | - manipCamera.BackForth(0, speed*delta, getWidth()); |
---|
14284 | | - */ |
---|
| 14723 | + manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth()); |
---|
| 14724 | + /**/ |
---|
14285 | 14725 | if ((mod & SHIFT) == SHIFT) |
---|
14286 | 14726 | { |
---|
14287 | 14727 | mouseMode = mouseMode; |
---|
.. | .. |
---|
14290 | 14730 | mouseMode |= BACKFORTH; |
---|
14291 | 14731 | } |
---|
14292 | 14732 | |
---|
| 14733 | + targetLookAt.set(manipCamera.lookAt); |
---|
| 14734 | + |
---|
14293 | 14735 | //prevX = X = anchorX; |
---|
14294 | 14736 | prevY = Y = anchorY + (int) (renderCamera.Distance()); |
---|
14295 | 14737 | } |
---|
.. | .. |
---|
14297 | 14739 | void GoLeft(int mod) |
---|
14298 | 14740 | { |
---|
14299 | 14741 | MODIFIERS |= COMMAND; |
---|
14300 | | - /* |
---|
| 14742 | + /**/ |
---|
14301 | 14743 | if((mod&SHIFT) == SHIFT) |
---|
14302 | | - manipCamera.RotatePosition(speed, 0); |
---|
| 14744 | + manipCamera.Translate(speed*delta, 0, getWidth()); |
---|
14303 | 14745 | else |
---|
14304 | | - manipCamera.Translate(speed*delta, 0, getWidth()); |
---|
14305 | | - */ |
---|
| 14746 | + { |
---|
| 14747 | + if ((mouseMode&VR)!=0) |
---|
| 14748 | + manipCamera.RotateInterest(-speed, 0); |
---|
| 14749 | + else |
---|
| 14750 | + manipCamera.RotatePosition(speed, 0); |
---|
| 14751 | + } |
---|
| 14752 | + /**/ |
---|
14306 | 14753 | if ((mod & SHIFT) == SHIFT) |
---|
14307 | 14754 | { |
---|
14308 | 14755 | mouseMode = mouseMode; |
---|
.. | .. |
---|
14311 | 14758 | mouseMode |= ROTATE; |
---|
14312 | 14759 | } // TRANSLATE; |
---|
14313 | 14760 | |
---|
| 14761 | + targetLookAt.set(manipCamera.lookAt); |
---|
| 14762 | + |
---|
14314 | 14763 | prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance()); |
---|
14315 | 14764 | prevY = Y = anchorY; |
---|
14316 | 14765 | } |
---|
.. | .. |
---|
14318 | 14767 | void GoRight(int mod) |
---|
14319 | 14768 | { |
---|
14320 | 14769 | MODIFIERS |= COMMAND; |
---|
14321 | | - /* |
---|
| 14770 | + /**/ |
---|
14322 | 14771 | if((mod&SHIFT) == SHIFT) |
---|
14323 | | - manipCamera.RotatePosition(-speed, 0); |
---|
| 14772 | + manipCamera.Translate(-speed*delta, 0, getWidth()); |
---|
14324 | 14773 | else |
---|
14325 | | - manipCamera.Translate(-speed*delta, 0, getWidth()); |
---|
14326 | | - */ |
---|
| 14774 | + { |
---|
| 14775 | + if ((mouseMode&VR)!=0) |
---|
| 14776 | + manipCamera.RotateInterest(speed, 0); |
---|
| 14777 | + else |
---|
| 14778 | + manipCamera.RotatePosition(-speed, 0); |
---|
| 14779 | + } |
---|
| 14780 | + |
---|
| 14781 | + /**/ |
---|
14327 | 14782 | if ((mod & SHIFT) == SHIFT) |
---|
14328 | 14783 | { |
---|
14329 | 14784 | mouseMode = mouseMode; |
---|
.. | .. |
---|
14332 | 14787 | mouseMode |= ROTATE; |
---|
14333 | 14788 | } // TRANSLATE; |
---|
14334 | 14789 | |
---|
| 14790 | + targetLookAt.set(manipCamera.lookAt); |
---|
| 14791 | + |
---|
14335 | 14792 | prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance()); |
---|
14336 | 14793 | prevY = Y = anchorY; |
---|
14337 | 14794 | } |
---|
.. | .. |
---|
14373 | 14830 | if (editObj) |
---|
14374 | 14831 | { |
---|
14375 | 14832 | drag = true; |
---|
14376 | | - ClickInfo info = new ClickInfo(); |
---|
14377 | | - info.bounds.setBounds(0, 0, |
---|
| 14833 | + //ClickInfo info = new ClickInfo(); |
---|
| 14834 | + object.clickInfo.bounds.setBounds(0, 0, |
---|
14378 | 14835 | (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
14379 | | - info.pane = this; |
---|
14380 | | - info.camera = renderCamera; |
---|
14381 | | - info.x = x; |
---|
14382 | | - info.y = y; |
---|
14383 | | - object.GetWindow().copy |
---|
14384 | | - .doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0); |
---|
| 14836 | + object.clickInfo.pane = this; |
---|
| 14837 | + object.clickInfo.camera = renderCamera; |
---|
| 14838 | + object.clickInfo.x = x; |
---|
| 14839 | + object.clickInfo.y = y; |
---|
| 14840 | + object //.GetWindow().copy |
---|
| 14841 | + .doEditDrag(//info, |
---|
| 14842 | + (modifiers & MouseEvent.BUTTON3_MASK) != 0); |
---|
14385 | 14843 | } else |
---|
14386 | 14844 | { |
---|
14387 | 14845 | if (x < startX) |
---|
.. | .. |
---|
14530 | 14988 | } |
---|
14531 | 14989 | } |
---|
14532 | 14990 | |
---|
| 14991 | +// ClickInfo clickInfo = new ClickInfo(); |
---|
| 14992 | + |
---|
14533 | 14993 | public void mouseMoved(MouseEvent e) |
---|
14534 | 14994 | { |
---|
14535 | 14995 | //System.out.println("mouseMoved: " + e); |
---|
14536 | 14996 | if (isRenderer) |
---|
14537 | 14997 | return; |
---|
14538 | 14998 | |
---|
14539 | | - ClickInfo ci = new ClickInfo(); |
---|
14540 | | - ci.x = e.getX(); |
---|
14541 | | - ci.y = e.getY(); |
---|
14542 | | - ci.modifiers = e.getModifiersEx(); |
---|
14543 | | - ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
14544 | | - ci.pane = this; |
---|
14545 | | - ci.camera = renderCamera; |
---|
| 14999 | + // Mouse cursor feedback |
---|
| 15000 | + object.clickInfo.x = e.getX(); |
---|
| 15001 | + object.clickInfo.y = e.getY(); |
---|
| 15002 | + object.clickInfo.modifiers = e.getModifiersEx(); |
---|
| 15003 | + object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
| 15004 | + object.clickInfo.pane = this; |
---|
| 15005 | + object.clickInfo.camera = renderCamera; |
---|
14546 | 15006 | if (!isRenderer) |
---|
14547 | 15007 | { |
---|
14548 | 15008 | //ObjEditor editWindow = object.editWindow; |
---|
14549 | 15009 | //Object3D copy = editWindow.copy; |
---|
14550 | | - if (object.doEditClick(ci, 0)) |
---|
| 15010 | + if (object.doEditClick(//clickInfo, |
---|
| 15011 | + 0)) |
---|
14551 | 15012 | { |
---|
14552 | 15013 | setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
---|
14553 | 15014 | } else |
---|
.. | .. |
---|
14562 | 15023 | Globals.MOUSEDRAGGED = false; |
---|
14563 | 15024 | |
---|
14564 | 15025 | movingcamera = false; |
---|
14565 | | - X = Y = 0; |
---|
| 15026 | + X = 0; // getBounds().width/2; |
---|
| 15027 | + Y = 0; // getBounds().height/2; |
---|
14566 | 15028 | //System.out.println("mouseReleased: " + e); |
---|
14567 | 15029 | clickEnd(e.getX(), e.getY(), e.getModifiersEx()); |
---|
14568 | 15030 | } |
---|
.. | .. |
---|
14818 | 15280 | // break; |
---|
14819 | 15281 | case 'T': |
---|
14820 | 15282 | CACHETEXTURE ^= true; |
---|
14821 | | - textures.clear(); |
---|
| 15283 | + texturepigment.clear(); |
---|
| 15284 | + texturebump.clear(); |
---|
14822 | 15285 | // repaint(); |
---|
14823 | 15286 | break; |
---|
14824 | 15287 | case 'Y': |
---|
.. | .. |
---|
14828 | 15291 | case 'K': |
---|
14829 | 15292 | KOMPACTTEXTURE ^= true; |
---|
14830 | 15293 | //textures.clear(); |
---|
14831 | | - break; |
---|
14832 | | - case 'P': // Texture Projection macros |
---|
| 15294 | + // break; |
---|
| 15295 | + //case 'P': // Texture Projection macros |
---|
14833 | 15296 | // SAVETEXTURE ^= true; |
---|
14834 | 15297 | macromode = true; |
---|
14835 | 15298 | Udebug = Vdebug = NORMALdebug = false; programInitialized = false; |
---|
.. | .. |
---|
14903 | 15366 | case 'E' : COMPACT ^= true; |
---|
14904 | 15367 | repaint(); |
---|
14905 | 15368 | break; |
---|
14906 | | - case 'W' : DEBUGHSB ^= true; |
---|
| 15369 | + case 'W' : // Wide Window (fullscreen) |
---|
| 15370 | + //DEBUGHSB ^= true; |
---|
| 15371 | + ObjEditor.theFrame.ToggleFullScreen(); |
---|
14907 | 15372 | repaint(); |
---|
14908 | 15373 | break; |
---|
14909 | 15374 | case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break; |
---|
.. | .. |
---|
14929 | 15394 | repaint(); |
---|
14930 | 15395 | break; |
---|
14931 | 15396 | case 'l': |
---|
14932 | | - lightMode ^= true; |
---|
14933 | | - Globals.lighttouched = true; |
---|
14934 | | - manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera; |
---|
14935 | | - targetLookAt.set(manipCamera.lookAt); |
---|
14936 | | - repaint(); |
---|
14937 | | - break; |
---|
14938 | | - case 'L': |
---|
| 15397 | + //case 'L': |
---|
14939 | 15398 | if (lightMode) |
---|
14940 | 15399 | { |
---|
14941 | 15400 | lightMode = false; |
---|
.. | .. |
---|
14954 | 15413 | targetLookAt.set(manipCamera.lookAt); |
---|
14955 | 15414 | repaint(); |
---|
14956 | 15415 | break; |
---|
14957 | | - case 'p': |
---|
| 15416 | + case 'P': // p': |
---|
14958 | 15417 | // c'est quoi ca au juste? spherical ^= true; |
---|
14959 | 15418 | Skinshader ^= true; programInitialized = false; |
---|
14960 | 15419 | repaint(); |
---|
.. | .. |
---|
14999 | 15458 | OCCLUSION_CULLING ^= true; |
---|
15000 | 15459 | System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING); |
---|
15001 | 15460 | break; |
---|
15002 | | - case '0': envyoff ^= true; repaint(); break; |
---|
| 15461 | + //case '0': envyoff ^= true; repaint(); break; |
---|
15003 | 15462 | case '1': |
---|
15004 | 15463 | case '2': |
---|
15005 | 15464 | case '3': |
---|
15006 | 15465 | case '4': |
---|
15007 | 15466 | case '5': |
---|
15008 | | - newenvy = Character.getNumericValue(key); |
---|
15009 | | - repaint(); |
---|
15010 | | - break; |
---|
15011 | 15467 | case '6': |
---|
15012 | 15468 | case '7': |
---|
15013 | 15469 | case '8': |
---|
15014 | 15470 | case '9': |
---|
15015 | | - BGcolor = (key - '6')/3.f; |
---|
| 15471 | + if (true) // envyoff) |
---|
| 15472 | + { |
---|
| 15473 | + BGcolor = (key - '1')/8.f; |
---|
| 15474 | + } |
---|
| 15475 | + else |
---|
| 15476 | + { |
---|
| 15477 | + //newenvy = Character.getNumericValue(key); |
---|
| 15478 | + } |
---|
15016 | 15479 | repaint(); |
---|
15017 | 15480 | break; |
---|
15018 | 15481 | case '!': |
---|
.. | .. |
---|
15078 | 15541 | case '_': |
---|
15079 | 15542 | kompactbit = 5; |
---|
15080 | 15543 | break; |
---|
15081 | | - case '+': |
---|
15082 | | - kompactbit = 6; |
---|
15083 | | - break; |
---|
| 15544 | +// case '+': |
---|
| 15545 | +// kompactbit = 6; |
---|
| 15546 | +// break; |
---|
15084 | 15547 | case ' ': |
---|
15085 | | - ObjEditor.theFrame.ToggleFullScreen(); |
---|
| 15548 | + lightMode ^= true; |
---|
| 15549 | + Globals.lighttouched = true; |
---|
| 15550 | + manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera; |
---|
| 15551 | + targetLookAt.set(manipCamera.lookAt); |
---|
15086 | 15552 | repaint(); |
---|
15087 | 15553 | break; |
---|
15088 | 15554 | //case '`' : |
---|
.. | .. |
---|
15129 | 15595 | case DELETE: |
---|
15130 | 15596 | ClearSelection(); |
---|
15131 | 15597 | break; |
---|
15132 | | - /* |
---|
15133 | 15598 | case '+': |
---|
| 15599 | + |
---|
| 15600 | + /* |
---|
15134 | 15601 | //fontsize += 1; |
---|
15135 | 15602 | bbzoom *= 2; |
---|
15136 | 15603 | repaint(); |
---|
.. | .. |
---|
15147 | 15614 | case '=': |
---|
15148 | 15615 | IncDepth(); |
---|
15149 | 15616 | //fontsize += 1; |
---|
15150 | | - object.editWindow.refreshContents(true); |
---|
| 15617 | + object.GetWindow().refreshContents(true); |
---|
15151 | 15618 | maskbit = 6; |
---|
15152 | 15619 | break; |
---|
15153 | 15620 | case '-': //if (PixelThreshold>1) PixelThreshold /= 2; |
---|
15154 | 15621 | DecDepth(); |
---|
15155 | 15622 | maskbit = 5; |
---|
15156 | 15623 | //if(fontsize > 1) fontsize -= 1; |
---|
15157 | | - if (object.editWindow == null) |
---|
15158 | | - new Exception().printStackTrace(); |
---|
15159 | | - else |
---|
15160 | | - object.editWindow.refreshContents(true); |
---|
| 15624 | +// if (object.editWindow == null) |
---|
| 15625 | +// new Exception().printStackTrace(); |
---|
| 15626 | +// else |
---|
| 15627 | + object.GetWindow().refreshContents(true); |
---|
15161 | 15628 | break; |
---|
15162 | 15629 | case '{': |
---|
15163 | 15630 | manipCamera.shaper_fovy /= 1.1; |
---|
.. | .. |
---|
15381 | 15848 | } |
---|
15382 | 15849 | */ |
---|
15383 | 15850 | |
---|
15384 | | - object.editWindow.EditSelection(false); |
---|
| 15851 | + object.GetWindow().EditSelection(false); |
---|
15385 | 15852 | } |
---|
15386 | 15853 | |
---|
15387 | 15854 | void SelectParent() |
---|
.. | .. |
---|
15398 | 15865 | { |
---|
15399 | 15866 | //selectees.remove(i); |
---|
15400 | 15867 | System.out.println("select parent of " + elem); |
---|
15401 | | - group.editWindow.Select(elem.parent.GetTreePath(), first, true); |
---|
| 15868 | + group.GetWindow().Select(elem.parent.GetTreePath(), first, true); |
---|
15402 | 15869 | } else |
---|
15403 | 15870 | { |
---|
15404 | | - group.editWindow.Select(elem.GetTreePath(), first, true); |
---|
| 15871 | + group.GetWindow().Select(elem.GetTreePath(), first, true); |
---|
15405 | 15872 | } |
---|
15406 | 15873 | |
---|
15407 | 15874 | first = false; |
---|
.. | .. |
---|
15443 | 15910 | for (int j = 0; j < group.children.size(); j++) |
---|
15444 | 15911 | { |
---|
15445 | 15912 | elem = (Object3D) group.children.elementAt(j); |
---|
15446 | | - object.editWindow.Select(elem.GetTreePath(), first, true); |
---|
| 15913 | + object.GetWindow().Select(elem.GetTreePath(), first, true); |
---|
15447 | 15914 | first = false; |
---|
15448 | 15915 | } |
---|
15449 | 15916 | } else |
---|
15450 | 15917 | { |
---|
15451 | | - object.editWindow.Select(elem.GetTreePath(), first, true); |
---|
| 15918 | + object.GetWindow().Select(elem.GetTreePath(), first, true); |
---|
15452 | 15919 | } |
---|
15453 | 15920 | |
---|
15454 | 15921 | first = false; |
---|
.. | .. |
---|
15459 | 15926 | { |
---|
15460 | 15927 | //Composite group = (Composite) object; |
---|
15461 | 15928 | Object3D group = object; |
---|
15462 | | - group.editWindow.loadClipboard(true); // ClearSelection(false); |
---|
| 15929 | + group.GetWindow().loadClipboard(true); // ClearSelection(false); |
---|
15463 | 15930 | } |
---|
15464 | 15931 | |
---|
15465 | 15932 | void ResetTransform(int mask) |
---|
15466 | 15933 | { |
---|
15467 | 15934 | //Composite group = (Composite) object; |
---|
15468 | 15935 | Object3D group = object; |
---|
15469 | | - group.editWindow.ResetTransform(mask); |
---|
| 15936 | + group.GetWindow().ResetTransform(mask); |
---|
15470 | 15937 | } |
---|
15471 | 15938 | |
---|
15472 | 15939 | void FlipTransform() |
---|
15473 | 15940 | { |
---|
15474 | 15941 | //Composite group = (Composite) object; |
---|
15475 | 15942 | Object3D group = object; |
---|
15476 | | - group.editWindow.FlipTransform(); |
---|
| 15943 | + group.GetWindow().FlipTransform(); |
---|
15477 | 15944 | // group.editWindow.ReduceMesh(true); |
---|
15478 | 15945 | } |
---|
15479 | 15946 | |
---|
.. | .. |
---|
15481 | 15948 | { |
---|
15482 | 15949 | //Composite group = (Composite) object; |
---|
15483 | 15950 | Object3D group = object; |
---|
15484 | | - group.editWindow.PrintMemory(); |
---|
| 15951 | + group.GetWindow().PrintMemory(); |
---|
15485 | 15952 | // group.editWindow.ReduceMesh(true); |
---|
15486 | 15953 | } |
---|
15487 | 15954 | |
---|
.. | .. |
---|
15489 | 15956 | { |
---|
15490 | 15957 | //Composite group = (Composite) object; |
---|
15491 | 15958 | Object3D group = object; |
---|
15492 | | - group.editWindow.ResetCentroid(); |
---|
| 15959 | + group.GetWindow().ResetCentroid(); |
---|
15493 | 15960 | } |
---|
15494 | 15961 | |
---|
15495 | 15962 | void IncDepth() |
---|
.. | .. |
---|
15571 | 16038 | |
---|
15572 | 16039 | int width = getBounds().width; |
---|
15573 | 16040 | int height = getBounds().height; |
---|
15574 | | - ClickInfo info = new ClickInfo(); |
---|
15575 | | - info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom)); |
---|
15576 | 16041 | //Image img = CreateImage(width, height); |
---|
15577 | 16042 | //System.out.println("width = " + width + "; height = " + height + "\n"); |
---|
15578 | 16043 | |
---|
.. | .. |
---|
15649 | 16114 | } |
---|
15650 | 16115 | if (object != null && !hasMarquee) |
---|
15651 | 16116 | { |
---|
| 16117 | + if (object.clickInfo == null) |
---|
| 16118 | + object.clickInfo = new ClickInfo(); |
---|
| 16119 | + ClickInfo info = object.clickInfo; |
---|
| 16120 | + //ClickInfo info = new ClickInfo(); |
---|
| 16121 | + info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom)); |
---|
| 16122 | + |
---|
15652 | 16123 | if (isRenderer) |
---|
15653 | 16124 | { |
---|
15654 | | - info.flags++; |
---|
| 16125 | + object.clickInfo.flags++; |
---|
15655 | 16126 | double frameAspect = (double) width / (double) height; |
---|
15656 | 16127 | if (frameAspect > renderCamera.aspect) |
---|
15657 | 16128 | { |
---|
15658 | 16129 | int desired = (int) ((double) height * renderCamera.aspect); |
---|
15659 | | - info.bounds.width -= width - desired; |
---|
15660 | | - info.bounds.x += (width - desired) / 2; |
---|
| 16130 | + object.clickInfo.bounds.width -= width - desired; |
---|
| 16131 | + object.clickInfo.bounds.x += (width - desired) / 2; |
---|
15661 | 16132 | } else |
---|
15662 | 16133 | { |
---|
15663 | 16134 | int desired = (int) ((double) width / renderCamera.aspect); |
---|
15664 | | - info.bounds.height -= height - desired; |
---|
15665 | | - info.bounds.y += (height - desired) / 2; |
---|
| 16135 | + object.clickInfo.bounds.height -= height - desired; |
---|
| 16136 | + object.clickInfo.bounds.y += (height - desired) / 2; |
---|
15666 | 16137 | } |
---|
15667 | 16138 | } |
---|
15668 | | - info.g = gr; |
---|
15669 | | - info.camera = renderCamera; |
---|
| 16139 | + |
---|
| 16140 | + object.clickInfo.g = gr; |
---|
| 16141 | + object.clickInfo.camera = renderCamera; |
---|
15670 | 16142 | /* |
---|
15671 | 16143 | // Memory intensive (brep.verticescopy) |
---|
15672 | 16144 | if (!(object instanceof Composite)) |
---|
15673 | 16145 | object.draw(info, 0, false); // SLOW : |
---|
15674 | 16146 | */ |
---|
15675 | | - if (!isRenderer) |
---|
| 16147 | + if (!isRenderer) // && drag) |
---|
15676 | 16148 | { |
---|
15677 | | - object.drawEditHandles(info, 0); |
---|
15678 | | - |
---|
15679 | | - if (drag && (X != 0 || Y != 0) && object.selection.Size() > 0) |
---|
| 16149 | + Grafreed.Assert(object != null); |
---|
| 16150 | + Grafreed.Assert(object.selection != null); |
---|
| 16151 | + if (object.selection.Size() > 0) |
---|
15680 | 16152 | { |
---|
15681 | | - switch (object.selection.get(0).hitSomething) |
---|
| 16153 | + int hitSomething = object.selection.get(0).hitSomething; |
---|
| 16154 | + |
---|
| 16155 | + object.clickInfo.DX = 0; |
---|
| 16156 | + object.clickInfo.DY = 0; |
---|
| 16157 | + object.clickInfo.W = 1; |
---|
| 16158 | + if (hitSomething == Object3D.hitCenter) |
---|
15682 | 16159 | { |
---|
15683 | | - case Object3D.hitCenter: gr.setColor(Color.pink); |
---|
15684 | | - gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
15685 | | - break; |
---|
15686 | | - case Object3D.hitRotate: gr.setColor(Color.yellow); |
---|
15687 | | - gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
15688 | | - break; |
---|
15689 | | - case Object3D.hitScale: gr.setColor(Color.cyan); |
---|
15690 | | - gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
15691 | | - break; |
---|
| 16160 | + info.DX = X; |
---|
| 16161 | + if (X != 0) |
---|
| 16162 | + info.DX -= info.bounds.width/2; |
---|
| 16163 | + |
---|
| 16164 | + info.DY = Y; |
---|
| 16165 | + if (Y != 0) |
---|
| 16166 | + info.DY -= info.bounds.height/2; |
---|
15692 | 16167 | } |
---|
15693 | | - |
---|
| 16168 | + |
---|
| 16169 | + object.drawEditHandles(//info, |
---|
| 16170 | + 0); |
---|
| 16171 | + |
---|
| 16172 | + if (drag && (X != 0 || Y != 0)) |
---|
| 16173 | + { |
---|
| 16174 | + switch (hitSomething) |
---|
| 16175 | + { |
---|
| 16176 | + case Object3D.hitCenter: gr.setColor(Color.white); |
---|
| 16177 | + gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
| 16178 | + break; |
---|
| 16179 | + case Object3D.hitRotate: gr.setColor(Color.yellow); |
---|
| 16180 | + gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
| 16181 | + break; |
---|
| 16182 | + case Object3D.hitScale: gr.setColor(Color.cyan); |
---|
| 16183 | + gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
| 16184 | + break; |
---|
| 16185 | + } |
---|
| 16186 | + |
---|
| 16187 | + } |
---|
15694 | 16188 | } |
---|
15695 | 16189 | } |
---|
15696 | 16190 | } |
---|
.. | .. |
---|
15705 | 16199 | if (hasMarquee) |
---|
15706 | 16200 | { |
---|
15707 | 16201 | gr.setXORMode(Color.white); |
---|
15708 | | - gr.setColor(Color.red); |
---|
| 16202 | + gr.setColor(Color.white); |
---|
15709 | 16203 | if (!firstime) |
---|
15710 | 16204 | { |
---|
15711 | 16205 | gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH); |
---|
.. | .. |
---|
16172 | 16666 | private /*static*/ boolean firstime; |
---|
16173 | 16667 | private /*static*/ cVector newView = new cVector(); |
---|
16174 | 16668 | private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"}; |
---|
| 16669 | + private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"}; |
---|
| 16670 | + private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"}; |
---|
16175 | 16671 | private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X, |
---|
16176 | 16672 | GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X, |
---|
16177 | 16673 | GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y, |
---|
.. | .. |
---|
16184 | 16680 | { |
---|
16185 | 16681 | com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP); |
---|
16186 | 16682 | |
---|
| 16683 | + int usedsuf = 0; |
---|
| 16684 | + |
---|
16187 | 16685 | for (int i = 0; i < suffixes.length; i++) |
---|
16188 | 16686 | { |
---|
16189 | | - String resourceName = basename + suffixes[i] + "." + suffix; |
---|
16190 | | - TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
16191 | | - mipmapped, |
---|
16192 | | - FileUtil.getFileSuffix(resourceName)); |
---|
16193 | | - if (data == null) |
---|
| 16687 | + String[] suffixe = suffixes; |
---|
| 16688 | + String[] fallback = suffixes2; |
---|
| 16689 | + String[] fallfallback = suffixes3; |
---|
| 16690 | + |
---|
| 16691 | + for (int c=usedsuf; --c>=0;) |
---|
16194 | 16692 | { |
---|
16195 | | - throw new IOException("Unable to load texture " + resourceName); |
---|
| 16693 | +// String[] temp = suffixe; |
---|
| 16694 | +// suffixe = fallback; |
---|
| 16695 | +// fallback = fallfallback; |
---|
| 16696 | +// fallfallback = temp; |
---|
16196 | 16697 | } |
---|
| 16698 | + |
---|
| 16699 | + String resourceName = basename + suffixe[i] + "." + suffix; |
---|
| 16700 | + TextureData data; |
---|
| 16701 | + |
---|
| 16702 | + try |
---|
| 16703 | + { |
---|
| 16704 | + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
| 16705 | + mipmapped, |
---|
| 16706 | + FileUtil.getFileSuffix(resourceName)); |
---|
| 16707 | + } |
---|
| 16708 | + catch (Exception e) |
---|
| 16709 | + { |
---|
| 16710 | + try |
---|
| 16711 | + { |
---|
| 16712 | + resourceName = basename + fallback[i] + "." + suffix; |
---|
| 16713 | + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
| 16714 | + mipmapped, |
---|
| 16715 | + FileUtil.getFileSuffix(resourceName)); |
---|
| 16716 | + } |
---|
| 16717 | + catch (Exception e2) |
---|
| 16718 | + { |
---|
| 16719 | + resourceName = basename + fallfallback[i] + "." + suffix; |
---|
| 16720 | + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
| 16721 | + mipmapped, |
---|
| 16722 | + FileUtil.getFileSuffix(resourceName)); |
---|
| 16723 | + } |
---|
| 16724 | + } |
---|
| 16725 | + |
---|
16197 | 16726 | //System.out.println("Target = " + targets[i]); |
---|
16198 | 16727 | cubemap.updateImage(data, targets[i]); |
---|
16199 | 16728 | } |
---|
16200 | 16729 | |
---|
16201 | 16730 | return cubemap; |
---|
16202 | 16731 | } |
---|
| 16732 | + |
---|
16203 | 16733 | int bigsphere = -1; |
---|
16204 | 16734 | |
---|
16205 | 16735 | float BGcolor = 0.5f; |
---|
16206 | 16736 | |
---|
16207 | | - private void DrawSkyBox(GL gl) |
---|
| 16737 | + float ambientLight[] = {1f, 1f, 1f, 1.0f}; |
---|
| 16738 | + |
---|
| 16739 | + private void DrawSkyBox(GL gl, float ratio) |
---|
16208 | 16740 | { |
---|
16209 | | - if (envyoff || cubemap == null) |
---|
| 16741 | + if (//envyoff || |
---|
| 16742 | + WIREFRAME || |
---|
| 16743 | + cubemap == null) |
---|
16210 | 16744 | { |
---|
16211 | 16745 | gl.glClearColor(BGcolor, BGcolor, BGcolor, 1); |
---|
16212 | 16746 | gl.glClear(gl.GL_COLOR_BUFFER_BIT); |
---|
.. | .. |
---|
16221 | 16755 | // Compensates for ExaminerViewer's modification of modelview matrix |
---|
16222 | 16756 | gl.glMatrixMode(GL.GL_MODELVIEW); |
---|
16223 | 16757 | gl.glLoadIdentity(); |
---|
| 16758 | + gl.glScalef(1,ratio,1); |
---|
16224 | 16759 | |
---|
| 16760 | +// colorV[0] = 2; |
---|
| 16761 | +// colorV[1] = 2; |
---|
| 16762 | +// colorV[2] = 2; |
---|
| 16763 | +// colorV[3] = 1; |
---|
| 16764 | +// gl.glDisable(gl.GL_COLOR_MATERIAL); |
---|
| 16765 | +// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0); |
---|
| 16766 | +// |
---|
| 16767 | +// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0); |
---|
| 16768 | + |
---|
16225 | 16769 | //gl.glActiveTexture(GL.GL_TEXTURE1); |
---|
16226 | 16770 | //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP); |
---|
16227 | 16771 | |
---|
.. | .. |
---|
16253 | 16797 | { |
---|
16254 | 16798 | gl.glScalef(1.0f, -1.0f, 1.0f); |
---|
16255 | 16799 | } |
---|
| 16800 | + gl.glScalef(-1.0f, 1.0f, 1.0f); |
---|
16256 | 16801 | gl.glMultMatrixd(viewrot_1, 0); |
---|
16257 | 16802 | gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f); |
---|
16258 | 16803 | //viewer.updateInverseRotation(gl); |
---|
.. | .. |
---|
16293 | 16838 | gl.glDisable(GL.GL_TEXTURE_GEN_R); |
---|
16294 | 16839 | |
---|
16295 | 16840 | cubemap.disable(); |
---|
16296 | | - ////cubemap.unbind(); |
---|
| 16841 | + //cubemap.dispose(); |
---|
| 16842 | + |
---|
16297 | 16843 | if (CULLFACE) |
---|
16298 | 16844 | { |
---|
16299 | 16845 | gl.glEnable(gl.GL_CULL_FACE); |
---|
.. | .. |
---|
16488 | 17034 | } |
---|
16489 | 17035 | } |
---|
16490 | 17036 | |
---|
| 17037 | + private Object3D GetFolder() |
---|
| 17038 | + { |
---|
| 17039 | + Object3D folder = object.GetWindow().copy; |
---|
| 17040 | + if (object.GetWindow().copy.selection.Size() > 0) |
---|
| 17041 | + folder = object.GetWindow().copy.selection.elementAt(0); |
---|
| 17042 | + return folder; |
---|
| 17043 | + } |
---|
| 17044 | + |
---|
16491 | 17045 | class SelectBuffer implements GLEventListener |
---|
16492 | 17046 | { |
---|
16493 | 17047 | |
---|
.. | .. |
---|
16503 | 17057 | //new Exception().printStackTrace(); |
---|
16504 | 17058 | System.out.println("select buffer init"); |
---|
16505 | 17059 | // Use debug pipeline |
---|
16506 | | - drawable.setGL(new DebugGL(drawable.getGL())); |
---|
| 17060 | + //drawable.setGL(new DebugGL(drawable.getGL())); |
---|
16507 | 17061 | |
---|
16508 | 17062 | GL gl = drawable.getGL(); |
---|
16509 | 17063 | |
---|
.. | .. |
---|
16567 | 17121 | |
---|
16568 | 17122 | //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL); |
---|
16569 | 17123 | |
---|
| 17124 | + if (PAINTMODE) |
---|
| 17125 | + { |
---|
| 17126 | + if (object.GetWindow().copy.selection.Size() > 0) |
---|
| 17127 | + { |
---|
| 17128 | + Object3D paintobj = object.GetWindow().copy.selection.elementAt(0); |
---|
| 17129 | + |
---|
| 17130 | + // Make what you paint not selectable. |
---|
| 17131 | + paintobj.ResetSelectable(); |
---|
| 17132 | + } |
---|
| 17133 | + } |
---|
| 17134 | + |
---|
16570 | 17135 | //int tmp = selection_view; |
---|
16571 | 17136 | //selection_view = -1; |
---|
16572 | 17137 | int temp = DrawMode(); |
---|
.. | .. |
---|
16578 | 17143 | // temp = DEFAULT; // patch for selection debug |
---|
16579 | 17144 | Globals.drawMode = temp; // WARNING |
---|
16580 | 17145 | |
---|
| 17146 | + if (PAINTMODE) |
---|
| 17147 | + { |
---|
| 17148 | + if (object.GetWindow().copy.selection.Size() > 0) |
---|
| 17149 | + { |
---|
| 17150 | + Object3D paintobj = object.GetWindow().copy.selection.elementAt(0); |
---|
| 17151 | + |
---|
| 17152 | + // Revert. |
---|
| 17153 | + paintobj.RestoreSelectable(); |
---|
| 17154 | + } |
---|
| 17155 | + } |
---|
| 17156 | + |
---|
16581 | 17157 | //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view); |
---|
16582 | 17158 | |
---|
16583 | 17159 | // trying different ways of getting the depth info over |
---|
.. | .. |
---|
16681 | 17257 | } |
---|
16682 | 17258 | |
---|
16683 | 17259 | if (!movingcamera && !PAINTMODE) |
---|
16684 | | - object.editWindow.ScreenFitPoint(); // fev 2014 |
---|
| 17260 | + object.GetWindow().ScreenFitPoint(); // fev 2014 |
---|
16685 | 17261 | |
---|
16686 | | - if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0) |
---|
| 17262 | + if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0) |
---|
16687 | 17263 | { |
---|
16688 | | - Object3D paintobj = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0); |
---|
| 17264 | + //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0); |
---|
16689 | 17265 | |
---|
16690 | | - Object3D group = new Object3D("inst" + paintcount++); |
---|
| 17266 | + if (object.GetWindow().copy.selection.Size() > 0) |
---|
| 17267 | + { |
---|
| 17268 | + Object3D paintobj = object.GetWindow().copy.selection.elementAt(0); |
---|
16691 | 17269 | |
---|
16692 | | - group.CreateMaterial(); // use a void leaf to select instances |
---|
16693 | | - |
---|
16694 | | - group.add(paintobj); // link |
---|
16695 | | - |
---|
16696 | | - object.editWindow.SnapObject(group); |
---|
16697 | | - |
---|
16698 | | - Object3D folder = object.editWindow.copy; |
---|
16699 | | - |
---|
16700 | | - if (object.editWindow.copy.selection.Size() > 0) |
---|
16701 | | - folder = object.editWindow.copy.selection.elementAt(0); |
---|
16702 | | - |
---|
16703 | | - folder.add(group); |
---|
16704 | | - |
---|
16705 | | - object.editWindow.ResetModel(); |
---|
16706 | | - object.editWindow.refreshContents(); |
---|
| 17270 | + Object3D inst = new Object3D("inst" + paintcount++); |
---|
| 17271 | + |
---|
| 17272 | + inst.CreateMaterial(); // use a void leaf to select instances |
---|
| 17273 | + |
---|
| 17274 | + inst.add(paintobj); // link |
---|
| 17275 | + |
---|
| 17276 | + object.GetWindow().SnapObject(inst); |
---|
| 17277 | + |
---|
| 17278 | + Object3D folder = paintFolder; // GetFolder(); |
---|
| 17279 | + |
---|
| 17280 | + folder.add(inst); |
---|
| 17281 | + |
---|
| 17282 | + object.GetWindow().ResetModel(); |
---|
| 17283 | + object.GetWindow().refreshContents(); |
---|
| 17284 | + } |
---|
16707 | 17285 | } |
---|
16708 | 17286 | else |
---|
16709 | 17287 | paintcount = 0; |
---|
.. | .. |
---|
16742 | 17320 | //System.out.println("objects[color] = " + objects[color]); |
---|
16743 | 17321 | //objects[color].Select(); |
---|
16744 | 17322 | indexcount = 0; |
---|
| 17323 | + ObjEditor window = object.GetWindow(); |
---|
| 17324 | + if (window != null && deselect) |
---|
| 17325 | + { |
---|
| 17326 | + window.Select(null, deselect, true); |
---|
| 17327 | + } |
---|
16745 | 17328 | object.Select(color, deselect); |
---|
16746 | 17329 | } |
---|
16747 | 17330 | |
---|
.. | .. |
---|
16792 | 17375 | |
---|
16793 | 17376 | public void init(GLAutoDrawable drawable) |
---|
16794 | 17377 | { |
---|
| 17378 | + if (Globals.DEBUG) |
---|
16795 | 17379 | System.out.println("shadow buffer init"); |
---|
16796 | 17380 | |
---|
16797 | 17381 | GL gl = drawable.getGL(); |
---|
.. | .. |
---|
17020 | 17604 | gl.glFlush(); |
---|
17021 | 17605 | |
---|
17022 | 17606 | /**/ |
---|
17023 | | - gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer); |
---|
| 17607 | + gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer); |
---|
17024 | 17608 | |
---|
17025 | | - float[] pixels = occlusionsizebuffer.array(); |
---|
| 17609 | + float[] depths = occlusiondepthbuffer.array(); |
---|
17026 | 17610 | |
---|
| 17611 | + gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer); |
---|
| 17612 | + |
---|
| 17613 | + int[] pixels = selectsizebuffer.array(); |
---|
| 17614 | + |
---|
17027 | 17615 | double r = 0, g = 0, b = 0; |
---|
17028 | 17616 | |
---|
17029 | 17617 | double count = 0; |
---|
.. | .. |
---|
17034 | 17622 | |
---|
17035 | 17623 | double FACTOR = 1; |
---|
17036 | 17624 | |
---|
17037 | | - for (int i = 0; i < pixels.length; i++) |
---|
| 17625 | + for (int i = 0; i < depths.length; i++) |
---|
17038 | 17626 | { |
---|
17039 | 17627 | int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2; |
---|
17040 | 17628 | int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2; |
---|
.. | .. |
---|
17117 | 17705 | |
---|
17118 | 17706 | double scale = ray.z; // 1; // cos |
---|
17119 | 17707 | |
---|
17120 | | - float depth = pixels[newindex]; |
---|
| 17708 | + float depth = depths[newindex]; |
---|
17121 | 17709 | |
---|
17122 | 17710 | /* |
---|
17123 | 17711 | int newindex2 = (x + 1) * OCCLUSION_SIZE + y; |
---|
.. | .. |
---|
17314 | 17902 | static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE); |
---|
17315 | 17903 | static IntBuffer bigAAbuffer; |
---|
17316 | 17904 | static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3); |
---|
17317 | | - static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE); |
---|
| 17905 | + //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE); |
---|
17318 | 17906 | static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE); |
---|
17319 | 17907 | static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE); |
---|
17320 | 17908 | //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); |
---|
17321 | | - static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); |
---|
| 17909 | + static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); |
---|
| 17910 | + |
---|
| 17911 | + static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); |
---|
| 17912 | + |
---|
17322 | 17913 | static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB); |
---|
17323 | 17914 | static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); |
---|
17324 | 17915 | static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>(); |
---|