.. | .. |
---|
18 | 18 | import javax.imageio.ImageIO; |
---|
19 | 19 | import javax.imageio.ImageWriteParam; |
---|
20 | 20 | import javax.imageio.ImageWriter; |
---|
| 21 | +import javax.imageio.ImageReadParam; |
---|
| 22 | +import javax.imageio.ImageReader; |
---|
21 | 23 | import javax.imageio.plugins.jpeg.JPEGImageWriteParam; |
---|
| 24 | +import javax.imageio.stream.ImageInputStream; |
---|
22 | 25 | import javax.imageio.stream.ImageOutputStream; |
---|
23 | 26 | import javax.imageio.ImageWriteParam; |
---|
24 | 27 | |
---|
.. | .. |
---|
30 | 33 | import java.nio.*; |
---|
31 | 34 | |
---|
32 | 35 | import gleem.linalg.Mat4f; |
---|
| 36 | +import javax.imageio.ImageTypeSpecifier; |
---|
33 | 37 | |
---|
34 | 38 | class CameraPane extends GLCanvas implements iCameraPane, Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener |
---|
35 | 39 | { |
---|
.. | .. |
---|
44 | 48 | static boolean ABORTED = false; |
---|
45 | 49 | |
---|
46 | 50 | static int STEP = 1; |
---|
| 51 | + |
---|
| 52 | + private static BufferedImage CreateBim(byte[] bytes, int width, int height) |
---|
| 53 | + { |
---|
| 54 | + int[] pixels = new int[bytes.length/3]; |
---|
| 55 | + for (int i=pixels.length; --i>=0;) |
---|
| 56 | + { |
---|
| 57 | + int i3 = i*3; |
---|
| 58 | + pixels[i] = 0xFF; |
---|
| 59 | + pixels[i] <<= 8; |
---|
| 60 | + pixels[i] |= bytes[i3+2] & 0xFF; |
---|
| 61 | + pixels[i] <<= 8; |
---|
| 62 | + pixels[i] |= bytes[i3+1] & 0xFF; |
---|
| 63 | + pixels[i] <<= 8; |
---|
| 64 | + pixels[i] |= bytes[i3] & 0xFF; |
---|
| 65 | + } |
---|
| 66 | + /* |
---|
| 67 | + int r=0,g=0,b=0,a=0; |
---|
| 68 | + for (int i=0; i<width; i++) |
---|
| 69 | + for (int j=0; j<height; j++) |
---|
| 70 | + { |
---|
| 71 | + int index = j*width+i; |
---|
| 72 | + int p = pixels[index]; |
---|
| 73 | + a = ((p>>24) & 0xFF); |
---|
| 74 | + r = ((p>>16) & 0xFF); |
---|
| 75 | + g = ((p>>8) & 0xFF); |
---|
| 76 | + b = (p & 0xFF); |
---|
| 77 | + pixels[index] = (a<<24) | (b<<16) | (g<<8) | r; |
---|
| 78 | + } |
---|
| 79 | + /**/ |
---|
| 80 | + BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile); |
---|
| 81 | + rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width); |
---|
| 82 | + return rendImage; |
---|
| 83 | + } |
---|
47 | 84 | |
---|
48 | 85 | /*static*/ private boolean CULLFACE = false; // true; |
---|
49 | 86 | /*static*/ boolean NEAREST = false; // true; |
---|
.. | .. |
---|
60 | 97 | //boolean REDUCETEXTURE = true; |
---|
61 | 98 | boolean CACHETEXTURE = true; |
---|
62 | 99 | boolean CLEANCACHE = false; // true; |
---|
63 | | - boolean MIPMAP = false; // true; |
---|
| 100 | + boolean MIPMAP = false; // true; // never works... |
---|
64 | 101 | boolean COMPRESSTEXTURE = false; |
---|
65 | 102 | boolean KOMPACTTEXTURE = false; // true; |
---|
66 | 103 | boolean RESIZETEXTURE = false; |
---|
.. | .. |
---|
73 | 110 | //private Mat4f spotlightTransform = new Mat4f(); |
---|
74 | 111 | //private Mat4f spotlightInverseTransform = new Mat4f(); |
---|
75 | 112 | static GLContext glcontext = null; |
---|
76 | | - /*static*/ com.sun.opengl.util.texture.Texture cubemap; |
---|
| 113 | + /*static*/ com.sun.opengl.util.texture.Texture cubemap; // Either custom or rgb |
---|
| 114 | + /*static*/ com.sun.opengl.util.texture.Texture cubemapcustom; |
---|
| 115 | + /*static*/ com.sun.opengl.util.texture.Texture cubemaprgb; |
---|
| 116 | + boolean transformMode; |
---|
| 117 | + |
---|
77 | 118 | boolean reverseUP = false; |
---|
78 | 119 | static boolean frozen = false; |
---|
79 | 120 | boolean enablebackspace = false; // patch for back buffer refresh |
---|
.. | .. |
---|
136 | 177 | static boolean doublesided = false; // true; // reversed normals are awful for conformance |
---|
137 | 178 | boolean anisotropy = true; |
---|
138 | 179 | boolean softshadow = true; // slower but better false; |
---|
139 | | - boolean opacityhalo = false; |
---|
| 180 | + boolean opacityhalo = false; // reverse the halo effect (e.g. glass) |
---|
140 | 181 | |
---|
141 | 182 | boolean macromode = false; |
---|
142 | 183 | |
---|
.. | .. |
---|
150 | 191 | } |
---|
151 | 192 | |
---|
152 | 193 | private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory(); |
---|
| 194 | + |
---|
| 195 | + public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException |
---|
| 196 | + { |
---|
| 197 | + try |
---|
| 198 | + { |
---|
| 199 | + return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap); |
---|
| 200 | + } catch (IOException e) |
---|
| 201 | + { |
---|
| 202 | + System.out.println("NAME = " + name); |
---|
| 203 | + e.printStackTrace(); // throw new RuntimeException(e); |
---|
| 204 | + return null; |
---|
| 205 | + } |
---|
| 206 | + } |
---|
153 | 207 | |
---|
154 | 208 | void SetAsGLRenderer(boolean b) |
---|
155 | 209 | { |
---|
.. | .. |
---|
169 | 223 | |
---|
170 | 224 | SetCamera(cam); |
---|
171 | 225 | |
---|
172 | | - SetLight(new Camera(new cVector(10, 10, -20))); |
---|
| 226 | + // Warning: not used. |
---|
| 227 | + SetLight(new Camera(new cVector(15, 10, -20))); |
---|
173 | 228 | |
---|
174 | 229 | object = o; |
---|
175 | 230 | |
---|
.. | .. |
---|
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, |
---|
.. | .. |
---|
10481 | 10773 | ANTIALIAS = 0; |
---|
10482 | 10774 | //System.out.println("RESTART"); |
---|
10483 | 10775 | AAtimer.restart(); |
---|
| 10776 | + Globals.TIMERRUNNING = true; |
---|
10484 | 10777 | } |
---|
10485 | 10778 | } |
---|
10486 | 10779 | } |
---|
.. | .. |
---|
10568 | 10861 | |
---|
10569 | 10862 | if (wait) |
---|
10570 | 10863 | { |
---|
10571 | | - Sleep(500); |
---|
| 10864 | + Sleep(200); // blocks everything |
---|
10572 | 10865 | |
---|
10573 | 10866 | wait = false; |
---|
10574 | 10867 | } |
---|
.. | .. |
---|
10683 | 10976 | // if (parentcam != renderCamera) // not a light |
---|
10684 | 10977 | if (cam != lightCamera) |
---|
10685 | 10978 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
10686 | | - LA.matConcat(matrix, parentcam.GlobalTransform(), matrix); |
---|
| 10979 | + LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix); |
---|
10687 | 10980 | |
---|
10688 | 10981 | for (int j = 0; j < 4; j++) |
---|
10689 | 10982 | { |
---|
.. | .. |
---|
10698 | 10991 | // if (parentcam != renderCamera) // not a light |
---|
10699 | 10992 | if (cam != lightCamera) |
---|
10700 | 10993 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
10701 | | - LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix); |
---|
| 10994 | + LA.matConcat(parentcam.GlobalTransform(), matrix, matrix); |
---|
10702 | 10995 | |
---|
10703 | 10996 | //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix); |
---|
10704 | 10997 | |
---|
.. | .. |
---|
10784 | 11077 | gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000); |
---|
10785 | 11078 | } |
---|
10786 | 11079 | |
---|
10787 | | - if (newenvy > -1) |
---|
| 11080 | +// if (newenvy > -1) |
---|
| 11081 | +// { |
---|
| 11082 | +// LoadEnvy(newenvy); |
---|
| 11083 | +// } |
---|
| 11084 | +// |
---|
| 11085 | +// newenvy = -1; |
---|
| 11086 | + |
---|
| 11087 | + if (transformMode) // object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb")) |
---|
10788 | 11088 | { |
---|
10789 | | - LoadEnvy(newenvy); |
---|
| 11089 | + if (cubemaprgb == null) |
---|
| 11090 | + { |
---|
| 11091 | + cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb" + "/", "jpg", false); |
---|
| 11092 | + } |
---|
| 11093 | + |
---|
| 11094 | + cubemap = cubemaprgb; |
---|
10790 | 11095 | } |
---|
10791 | | - |
---|
10792 | | - newenvy = -1; |
---|
10793 | | - |
---|
| 11096 | + else |
---|
| 11097 | + { |
---|
| 11098 | + if (object.skyboxname != null) |
---|
| 11099 | + { |
---|
| 11100 | + if (!object.skyboxname.equals(this.loadedskyboxname)) |
---|
| 11101 | + { |
---|
| 11102 | + if (cubemap != null && cubemap != cubemaprgb) |
---|
| 11103 | + cubemap.dispose(); |
---|
| 11104 | + cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false); |
---|
| 11105 | + loadedskyboxname = object.skyboxname; |
---|
| 11106 | + } |
---|
| 11107 | + } |
---|
| 11108 | + else |
---|
| 11109 | + { |
---|
| 11110 | + cubemapcustom = null; |
---|
| 11111 | + loadedskyboxname = null; |
---|
| 11112 | + } |
---|
| 11113 | + |
---|
| 11114 | + cubemap = cubemapcustom; |
---|
| 11115 | + } |
---|
| 11116 | + |
---|
10794 | 11117 | ratio = ((double) getWidth()) / getHeight(); |
---|
10795 | 11118 | //System.out.println("ratio = " + ratio); |
---|
10796 | 11119 | |
---|
.. | .. |
---|
10806 | 11129 | |
---|
10807 | 11130 | if (!IsFrozen() && !ambientOcclusion) |
---|
10808 | 11131 | { |
---|
10809 | | - DrawSkyBox(gl); |
---|
| 11132 | + DrawSkyBox(gl, (float)ratio); |
---|
10810 | 11133 | } |
---|
10811 | 11134 | |
---|
10812 | 11135 | //if (selection_view == -1) |
---|
.. | .. |
---|
10989 | 11312 | |
---|
10990 | 11313 | gl.glMatrixMode(GL.GL_MODELVIEW); |
---|
10991 | 11314 | |
---|
10992 | | -//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST); |
---|
10993 | | -//gl.glEnable(gl.GL_POLYGON_SMOOTH); |
---|
10994 | | -//gl.glEnable(gl.GL_MULTISAMPLE); |
---|
| 11315 | +gl.glEnable(gl.GL_POLYGON_SMOOTH); |
---|
| 11316 | +gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST); |
---|
| 11317 | +gl.glEnable(gl.GL_MULTISAMPLE); |
---|
10995 | 11318 | } else |
---|
10996 | 11319 | { |
---|
10997 | 11320 | //gl.glDisable(GL.GL_TEXTURE_2D); |
---|
.. | .. |
---|
11002 | 11325 | //System.out.println("BLENDING ON"); |
---|
11003 | 11326 | gl.glEnable(GL.GL_BLEND); |
---|
11004 | 11327 | gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); |
---|
11005 | | - |
---|
| 11328 | +// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE); |
---|
11006 | 11329 | gl.glMatrixMode(gl.GL_PROJECTION); |
---|
11007 | 11330 | gl.glLoadIdentity(); |
---|
11008 | 11331 | |
---|
.. | .. |
---|
11092 | 11415 | |
---|
11093 | 11416 | // if (cam != lightCamera) |
---|
11094 | 11417 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
11095 | | - LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013 |
---|
| 11418 | + LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013 |
---|
11096 | 11419 | } |
---|
11097 | 11420 | |
---|
11098 | 11421 | LA.xformDir(lightposition, cam.toScreen, lightposition); |
---|
.. | .. |
---|
11251 | 11574 | } |
---|
11252 | 11575 | } |
---|
11253 | 11576 | |
---|
11254 | | - if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion) |
---|
| 11577 | + if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion) |
---|
11255 | 11578 | { |
---|
11256 | 11579 | //gl.glDepthFunc(GL.GL_LEQUAL); |
---|
11257 | 11580 | //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT); |
---|
.. | .. |
---|
11259 | 11582 | |
---|
11260 | 11583 | boolean texon = textureon; |
---|
11261 | 11584 | |
---|
11262 | | - if (RENDERPROGRAM > 0) |
---|
11263 | | - { |
---|
11264 | | - gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
11265 | | - textureon = false; |
---|
11266 | | - } |
---|
| 11585 | + gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
| 11586 | + textureon = false; |
---|
| 11587 | + |
---|
11267 | 11588 | //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB); |
---|
11268 | 11589 | //System.out.println("ALLO"); |
---|
11269 | 11590 | gl.glColorMask(false, false, false, false); |
---|
11270 | 11591 | DrawObject(gl); |
---|
11271 | | - if (RENDERPROGRAM > 0) |
---|
11272 | | - { |
---|
11273 | | - gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
11274 | | - textureon = texon; |
---|
11275 | | - } |
---|
| 11592 | + |
---|
| 11593 | + gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
| 11594 | + textureon = texon; |
---|
| 11595 | + |
---|
11276 | 11596 | gl.glColorMask(true, true, true, true); |
---|
11277 | 11597 | |
---|
11278 | 11598 | gl.glDepthFunc(GL.GL_EQUAL); |
---|
11279 | | - //gl.glDepthMask(false); |
---|
| 11599 | + gl.glDepthMask(false); |
---|
11280 | 11600 | } |
---|
11281 | 11601 | |
---|
11282 | 11602 | if (false) // DrawMode() == SHADOW) |
---|
.. | .. |
---|
11459 | 11779 | |
---|
11460 | 11780 | static boolean zoomonce = false; |
---|
11461 | 11781 | |
---|
11462 | | - void CreateSelectedPoint() |
---|
| 11782 | + static void CreateSelectedPoint() |
---|
11463 | 11783 | { |
---|
11464 | 11784 | if (selectedpoint == null) |
---|
11465 | 11785 | { |
---|
.. | .. |
---|
11479 | 11799 | |
---|
11480 | 11800 | void DrawObject(GL gl, boolean draw) |
---|
11481 | 11801 | { |
---|
| 11802 | + // To clear camera values |
---|
| 11803 | + ResetOptions(); |
---|
| 11804 | + |
---|
11482 | 11805 | //System.out.println("DRAW OBJECT " + mouseDown); |
---|
11483 | 11806 | // DrawMode() = SELECTION; |
---|
11484 | 11807 | //GL gl = getGL(); |
---|
11485 | 11808 | if ((TRACK || SHADOWTRACK) || zoomonce) |
---|
11486 | 11809 | { |
---|
11487 | 11810 | if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode) |
---|
11488 | | - object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK); |
---|
| 11811 | + object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK); |
---|
11489 | 11812 | pingthread.StepToTarget(true); // true); |
---|
11490 | 11813 | // zoomonce = false; |
---|
11491 | 11814 | } |
---|
.. | .. |
---|
11613 | 11936 | ReleaseTextures(DEFAULT_TEXTURES); |
---|
11614 | 11937 | |
---|
11615 | 11938 | if (CLEANCACHE) |
---|
11616 | | - for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();) |
---|
| 11939 | + for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();) |
---|
11617 | 11940 | { |
---|
11618 | | - String tex = e.nextElement(); |
---|
| 11941 | + cTexture tex = e.nextElement(); |
---|
11619 | 11942 | |
---|
11620 | 11943 | // System.out.println("Texture --------- " + tex); |
---|
11621 | 11944 | |
---|
11622 | | - if (tex.equals("WHITE_NOISE")) |
---|
| 11945 | + if (tex.equals("WHITE_NOISE:")) |
---|
11623 | 11946 | continue; |
---|
11624 | 11947 | |
---|
11625 | | - if (!usedtextures.containsKey(tex)) |
---|
| 11948 | + if (!usedtextures.contains(tex)) |
---|
11626 | 11949 | { |
---|
| 11950 | + CacheTexture gettex = texturepigment.get(tex); |
---|
11627 | 11951 | // System.out.println("DISPOSE +++++++++++++++ " + tex); |
---|
11628 | | - textures.get(tex).texture.dispose(); |
---|
11629 | | - textures.remove(tex); |
---|
| 11952 | + if (gettex != null) |
---|
| 11953 | + { |
---|
| 11954 | + gettex.texture.dispose(); |
---|
| 11955 | + texturepigment.remove(tex); |
---|
| 11956 | + } |
---|
| 11957 | + |
---|
| 11958 | + gettex = texturebump.get(tex); |
---|
| 11959 | + // System.out.println("DISPOSE +++++++++++++++ " + tex); |
---|
| 11960 | + if (gettex != null) |
---|
| 11961 | + { |
---|
| 11962 | + gettex.texture.dispose(); |
---|
| 11963 | + texturebump.remove(tex); |
---|
| 11964 | + } |
---|
11630 | 11965 | } |
---|
11631 | 11966 | } |
---|
11632 | 11967 | } |
---|
.. | .. |
---|
12046 | 12381 | for (int i = tp.size(); --i >= 0;) |
---|
12047 | 12382 | { |
---|
12048 | 12383 | //for (int count = tp.get(i).GetTransformCount(); --count>=0;) |
---|
12049 | | - LA.xformPos(light, tp.get(i).GlobalTransform(), light); |
---|
| 12384 | + LA.xformPos(light, tp.get(i).GlobalTransformInv(), light); |
---|
12050 | 12385 | } |
---|
12051 | 12386 | |
---|
12052 | 12387 | |
---|
.. | .. |
---|
12154 | 12489 | |
---|
12155 | 12490 | //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0); |
---|
12156 | 12491 | |
---|
12157 | | - String program = |
---|
| 12492 | + String programmin = |
---|
| 12493 | + // Min shader |
---|
12158 | 12494 | "!!ARBfp1.0\n" + |
---|
| 12495 | + "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" + |
---|
| 12496 | + "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" + |
---|
| 12497 | + "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" + |
---|
| 12498 | + "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" + |
---|
| 12499 | + "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" + |
---|
| 12500 | + "PARAM light2cam0 = program.env[10];" + |
---|
| 12501 | + "PARAM light2cam1 = program.env[11];" + |
---|
| 12502 | + "PARAM light2cam2 = program.env[12];" + |
---|
| 12503 | + "TEMP temp;" + |
---|
| 12504 | + "TEMP light;" + |
---|
| 12505 | + "TEMP ndotl;" + |
---|
| 12506 | + "TEMP normal;" + |
---|
| 12507 | + "TEMP depth;" + |
---|
| 12508 | + "TEMP eye;" + |
---|
| 12509 | + "TEMP pos;" + |
---|
| 12510 | + |
---|
| 12511 | + "MAD normal, fragment.color, zero123.z, -zero123.y;" + |
---|
| 12512 | + Normalize("normal") + |
---|
| 12513 | + "MOV light, state.light[0].position;" + |
---|
| 12514 | + "DP3 ndotl.x, light, normal;" + |
---|
| 12515 | + |
---|
| 12516 | + // shadow |
---|
| 12517 | + "MOV pos, fragment.texcoord[1];" + |
---|
| 12518 | + "MOV temp, pos;" + |
---|
| 12519 | + ShadowTextureFetch("depth", "temp", "1") + |
---|
| 12520 | + //"TEX depth, fragment.texcoord[1], texture[1], 2D;" + |
---|
| 12521 | + "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" + |
---|
| 12522 | + |
---|
| 12523 | + // No shadow when out of frustum |
---|
| 12524 | + //"SGE temp.y, depth.z, zero123.y;" + |
---|
| 12525 | + //"LRP temp.x, temp.y, zero123.y, temp.x;" + |
---|
| 12526 | + |
---|
| 12527 | + "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow |
---|
| 12528 | + |
---|
| 12529 | + // Backlit |
---|
| 12530 | + "MOV pos.w, zero123.y;" + |
---|
| 12531 | + "DP4 eye.x, pos, light2cam0;" + |
---|
| 12532 | + "DP4 eye.y, pos, light2cam1;" + |
---|
| 12533 | + "DP4 eye.z, pos, light2cam2;" + |
---|
| 12534 | + Normalize("eye") + |
---|
| 12535 | + |
---|
| 12536 | + "DP3 ndotl.y, -eye, normal;" + |
---|
| 12537 | + //"MUL ndotl.y, ndotl.y, pow2.x;" + |
---|
| 12538 | + "POW ndotl.y, ndotl.y, pow2.z;" + // backlit |
---|
| 12539 | + "SUB ndotl.y, zero123.y, ndotl.y;" + |
---|
| 12540 | + //"SUB ndotl.y, zero123.y, ndotl.y;" + |
---|
| 12541 | + //"MUL ndotl.y, ndotl.y, pow2.z;" + |
---|
| 12542 | + |
---|
| 12543 | + //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient |
---|
| 12544 | + //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient |
---|
| 12545 | + |
---|
| 12546 | + // Pigment |
---|
| 12547 | + "TEX temp, fragment.texcoord[0], texture[0], 2D;" + |
---|
| 12548 | + "LRP temp, zero123.w, temp, one;" + // texture proportion |
---|
| 12549 | + "MUL temp, temp, ndotl.x;" + |
---|
| 12550 | + |
---|
| 12551 | + "MUL temp, temp, zero123.z;" + |
---|
| 12552 | + |
---|
| 12553 | + //"MUL temp, temp, ndotl.y;" + |
---|
| 12554 | + |
---|
| 12555 | + "MOV temp.w, zero123.y;" + // reset alpha |
---|
| 12556 | + "MOV result.color, temp;" + |
---|
| 12557 | + "END"; |
---|
| 12558 | + |
---|
| 12559 | + String programmax = |
---|
| 12560 | + "!!ARBfp1.0\n" + |
---|
| 12561 | + |
---|
12159 | 12562 | //"OPTION ARB_fragment_program_shadow;" + |
---|
12160 | 12563 | "PARAM light2cam0 = program.env[10];" + |
---|
12161 | 12564 | "PARAM light2cam1 = program.env[11];" + |
---|
.. | .. |
---|
12270 | 12673 | "TEMP shininess;" + |
---|
12271 | 12674 | "\n" + |
---|
12272 | 12675 | "MOV texSamp, one;" + |
---|
12273 | | - //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" + |
---|
12274 | | - |
---|
| 12676 | + |
---|
12275 | 12677 | "MOV mapgrid.x, one2048th.x;" + |
---|
12276 | 12678 | "MOV temp, fragment.texcoord[1];" + |
---|
12277 | 12679 | /* |
---|
.. | .. |
---|
12292 | 12694 | "MUL temp, floor, mapgrid.x;" + |
---|
12293 | 12695 | //"TEX depth0, temp, texture[1], 2D;" + |
---|
12294 | 12696 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12295 | | - TextureFetch("depth0", "temp", "1") + |
---|
| 12697 | + ShadowTextureFetch("depth0", "temp", "1") + |
---|
12296 | 12698 | "") + |
---|
12297 | 12699 | "ADD temp.x, temp.x, mapgrid.x;" + |
---|
12298 | 12700 | //"TEX depth1, temp, texture[1], 2D;" + |
---|
12299 | 12701 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12300 | | - TextureFetch("depth1", "temp", "1") + |
---|
| 12702 | + ShadowTextureFetch("depth1", "temp", "1") + |
---|
12301 | 12703 | "") + |
---|
12302 | 12704 | "ADD temp.y, temp.y, mapgrid.x;" + |
---|
12303 | 12705 | //"TEX depth2, temp, texture[1], 2D;" + |
---|
12304 | | - TextureFetch("depth2", "temp", "1") + |
---|
| 12706 | + ShadowTextureFetch("depth2", "temp", "1") + |
---|
12305 | 12707 | "SUB temp.x, temp.x, mapgrid.x;" + |
---|
12306 | 12708 | //"TEX depth3, temp, texture[1], 2D;" + |
---|
12307 | 12709 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12308 | | - TextureFetch("depth3", "temp", "1") + |
---|
| 12710 | + ShadowTextureFetch("depth3", "temp", "1") + |
---|
12309 | 12711 | "") + |
---|
12310 | 12712 | //"MUL texSamp0, texSamp0, state.material.front.diffuse;" + |
---|
12311 | 12713 | //"MOV params, material;" + |
---|
.. | .. |
---|
12676 | 13078 | "MAD shadow.x, buffer.x, frac.y, shadow.x;" + |
---|
12677 | 13079 | "") + |
---|
12678 | 13080 | |
---|
12679 | | - // display shadow only (bump == 0) |
---|
| 13081 | + // display shadow only (fakedepth == 0) |
---|
12680 | 13082 | "SUB temp.x, half.x, shadow.x;" + |
---|
12681 | 13083 | "MOV temp.y, -params5.z;" + // params6.x;" + |
---|
12682 | | - "SLT temp.z, temp.y, -one2048th.x;" + |
---|
| 13084 | + "SLT temp.z, temp.y, -c256i.x;" + |
---|
12683 | 13085 | "SUB temp.y, one.x, temp.z;" + |
---|
12684 | 13086 | "MUL temp.x, temp.x, temp.y;" + |
---|
12685 | 13087 | "KIL temp.x;" + |
---|
.. | .. |
---|
13010 | 13412 | //once = true; |
---|
13011 | 13413 | } |
---|
13012 | 13414 | |
---|
| 13415 | + String program = programmax; |
---|
| 13416 | + |
---|
| 13417 | + if (Globals.MINSHADER) |
---|
| 13418 | + { |
---|
| 13419 | + program = programmin; |
---|
| 13420 | + } |
---|
| 13421 | + |
---|
13013 | 13422 | System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length()); |
---|
13014 | 13423 | System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : "")); |
---|
13015 | 13424 | loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program); |
---|
.. | .. |
---|
13103 | 13512 | return out; |
---|
13104 | 13513 | } |
---|
13105 | 13514 | |
---|
13106 | | - String TextureFetch(String dest, String src, String unit) |
---|
| 13515 | + // Also does frustum culling |
---|
| 13516 | + String ShadowTextureFetch(String dest, String src, String unit) |
---|
13107 | 13517 | { |
---|
13108 | 13518 | return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" + |
---|
13109 | 13519 | "SGE " + src + ".w, " + src + ".x, eps.x;" + |
---|
13110 | 13520 | "SGE " + src + ".z, " + src + ".y, eps.x;" + |
---|
| 13521 | + "SLT " + dest + ".x, " + src + ".x, one.x;" + |
---|
| 13522 | + "SLT " + dest + ".y, " + src + ".y, one.x;" + |
---|
13111 | 13523 | "MUL " + src + ".w, " + src + ".z, " + src + ".w;" + |
---|
13112 | | - "SLT " + src + ".z, " + src + ".x, one.x;" + |
---|
13113 | | - "MUL " + src + ".w, " + src + ".z, " + src + ".w;" + |
---|
13114 | | - "SLT " + src + ".z, " + src + ".y, one.x;" + |
---|
13115 | | - "MUL " + src + ".w, " + src + ".z, " + src + ".w;" + |
---|
| 13524 | + "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" + |
---|
| 13525 | + "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" + |
---|
13116 | 13526 | //"SWZ buffer, temp, w,w,w,w;"; |
---|
13117 | | - "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" + |
---|
| 13527 | + //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" + |
---|
13118 | 13528 | "SUB " + src + ".z, " + "one.x, " + src + ".w;" + |
---|
13119 | 13529 | //"MUL " + src + ".z, " + src + ".z, infinity.x;" + |
---|
13120 | 13530 | //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;"; |
---|
13121 | | - "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
| 13531 | + //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
13122 | 13532 | |
---|
13123 | | - //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;"; |
---|
13124 | | - //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;"; |
---|
| 13533 | + //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;"; |
---|
| 13534 | + "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
13125 | 13535 | } |
---|
13126 | 13536 | |
---|
13127 | 13537 | String Shadow(String depth, String shadow) |
---|
.. | .. |
---|
13168 | 13578 | "SLT temp.x, temp.x, zero.x;" + // shadoweps |
---|
13169 | 13579 | "LRP " + shadow + ", temp.x, one, " + shadow + ";" + |
---|
13170 | 13580 | |
---|
13171 | | - // No shadow when out of frustrum |
---|
| 13581 | + // No shadow when out of frustum |
---|
13172 | 13582 | "SGE temp.x, " + depth + ".z, one.z;" + |
---|
13173 | 13583 | "LRP " + shadow + ", temp.x, one, " + shadow + ";" + |
---|
13174 | 13584 | ""; |
---|
.. | .. |
---|
13333 | 13743 | "DP3 " + dest + ".z," + "normals," + "eye;" + |
---|
13334 | 13744 | "MAX " + dest + ".w," + dest + ".z," + "eps.x;" + |
---|
13335 | 13745 | //"MOV " + dest + ".w," + "normal.z;" + |
---|
13336 | | - "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + |
---|
13337 | | - "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" + |
---|
13338 | | - //"MOV " + dest + ".z," + "params2.w;" + |
---|
| 13746 | +// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET |
---|
| 13747 | +// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" + |
---|
| 13748 | + |
---|
| 13749 | + "MOV " + dest + ".z," + "params2.w;" + // EXACT |
---|
13339 | 13750 | "POW " + dest + ".w," + dest + ".w," + dest + ".z;" + |
---|
13340 | 13751 | "RCP " + dest + ".w," + dest + ".w;" + |
---|
13341 | 13752 | //"RSQ " + dest + ".w," + dest + ".w;" + |
---|
.. | .. |
---|
13840 | 14251 | else |
---|
13841 | 14252 | if (evt.getSource() == AAtimer) |
---|
13842 | 14253 | { |
---|
| 14254 | + Globals.TIMERRUNNING = false; |
---|
13843 | 14255 | if (mouseDown) |
---|
13844 | 14256 | { |
---|
13845 | 14257 | //new Exception().printStackTrace(); |
---|
.. | .. |
---|
13899 | 14311 | |
---|
13900 | 14312 | // fev 2014??? |
---|
13901 | 14313 | if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode) |
---|
13902 | | - object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK); |
---|
| 14314 | + object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK); |
---|
13903 | 14315 | pingthread.StepToTarget(true); // true); |
---|
13904 | 14316 | } |
---|
13905 | 14317 | // if (!LIVE) |
---|
.. | .. |
---|
13914 | 14326 | return; |
---|
13915 | 14327 | |
---|
13916 | 14328 | AAtimer.restart(); // |
---|
| 14329 | + Globals.TIMERRUNNING = true; |
---|
13917 | 14330 | |
---|
13918 | 14331 | // waslive = LIVE; |
---|
13919 | 14332 | // LIVE = false; |
---|
.. | .. |
---|
13963 | 14376 | drag = false; |
---|
13964 | 14377 | //System.out.println("Mouse DOWN"); |
---|
13965 | 14378 | editObj = false; |
---|
13966 | | - ClickInfo info = new ClickInfo(); |
---|
13967 | | - info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
13968 | | - info.pane = this; |
---|
13969 | | - info.camera = renderCamera; |
---|
13970 | | - info.x = x; |
---|
13971 | | - info.y = y; |
---|
13972 | | - info.modifiers = modifiersex; |
---|
13973 | | - editObj = object.doEditClick(info, 0); |
---|
| 14379 | + //ClickInfo info = new ClickInfo(); |
---|
| 14380 | + object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
| 14381 | + object.clickInfo.pane = this; |
---|
| 14382 | + object.clickInfo.camera = renderCamera; |
---|
| 14383 | + object.clickInfo.x = x; |
---|
| 14384 | + object.clickInfo.y = y; |
---|
| 14385 | + object.clickInfo.modifiers = modifiersex; |
---|
| 14386 | + editObj = object.doEditClick(//info, |
---|
| 14387 | + 0); |
---|
13974 | 14388 | if (!editObj) |
---|
13975 | 14389 | { |
---|
13976 | 14390 | hasMarquee = true; |
---|
.. | .. |
---|
14252 | 14666 | void GoDown(int mod) |
---|
14253 | 14667 | { |
---|
14254 | 14668 | MODIFIERS |= COMMAND; |
---|
14255 | | - /* |
---|
| 14669 | + /**/ |
---|
14256 | 14670 | if((mod&SHIFT) == SHIFT) |
---|
14257 | | - manipCamera.RotatePosition(0, -speed); |
---|
| 14671 | + manipCamera.BackForth(0, -speed*delta, 0); // getWidth()); |
---|
14258 | 14672 | else |
---|
14259 | | - manipCamera.BackForth(0, -speed*delta, getWidth()); |
---|
14260 | | - */ |
---|
| 14673 | + manipCamera.RotatePosition(0, -speed); |
---|
| 14674 | + /**/ |
---|
14261 | 14675 | if ((mod & SHIFT) == SHIFT) |
---|
14262 | 14676 | { |
---|
14263 | 14677 | mouseMode = mouseMode; // VR?? |
---|
.. | .. |
---|
14273 | 14687 | void GoUp(int mod) |
---|
14274 | 14688 | { |
---|
14275 | 14689 | MODIFIERS |= COMMAND; |
---|
14276 | | - /* |
---|
| 14690 | + /**/ |
---|
14277 | 14691 | if((mod&SHIFT) == SHIFT) |
---|
14278 | | - manipCamera.RotatePosition(0, speed); |
---|
| 14692 | + manipCamera.BackForth(0, speed*delta, 0); // getWidth()); |
---|
14279 | 14693 | else |
---|
14280 | | - manipCamera.BackForth(0, speed*delta, getWidth()); |
---|
14281 | | - */ |
---|
| 14694 | + manipCamera.RotatePosition(0, speed); |
---|
| 14695 | + /**/ |
---|
14282 | 14696 | if ((mod & SHIFT) == SHIFT) |
---|
14283 | 14697 | { |
---|
14284 | 14698 | mouseMode = mouseMode; |
---|
.. | .. |
---|
14294 | 14708 | void GoLeft(int mod) |
---|
14295 | 14709 | { |
---|
14296 | 14710 | MODIFIERS |= COMMAND; |
---|
14297 | | - /* |
---|
| 14711 | + /**/ |
---|
14298 | 14712 | if((mod&SHIFT) == SHIFT) |
---|
14299 | | - manipCamera.RotatePosition(speed, 0); |
---|
14300 | | - else |
---|
14301 | 14713 | manipCamera.Translate(speed*delta, 0, getWidth()); |
---|
14302 | | - */ |
---|
| 14714 | + else |
---|
| 14715 | + manipCamera.RotatePosition(speed, 0); |
---|
| 14716 | + /**/ |
---|
14303 | 14717 | if ((mod & SHIFT) == SHIFT) |
---|
14304 | 14718 | { |
---|
14305 | 14719 | mouseMode = mouseMode; |
---|
.. | .. |
---|
14315 | 14729 | void GoRight(int mod) |
---|
14316 | 14730 | { |
---|
14317 | 14731 | MODIFIERS |= COMMAND; |
---|
14318 | | - /* |
---|
| 14732 | + /**/ |
---|
14319 | 14733 | if((mod&SHIFT) == SHIFT) |
---|
14320 | | - manipCamera.RotatePosition(-speed, 0); |
---|
14321 | | - else |
---|
14322 | 14734 | manipCamera.Translate(-speed*delta, 0, getWidth()); |
---|
14323 | | - */ |
---|
| 14735 | + else |
---|
| 14736 | + manipCamera.RotatePosition(-speed, 0); |
---|
| 14737 | + /**/ |
---|
14324 | 14738 | if ((mod & SHIFT) == SHIFT) |
---|
14325 | 14739 | { |
---|
14326 | 14740 | mouseMode = mouseMode; |
---|
.. | .. |
---|
14370 | 14784 | if (editObj) |
---|
14371 | 14785 | { |
---|
14372 | 14786 | drag = true; |
---|
14373 | | - ClickInfo info = new ClickInfo(); |
---|
14374 | | - info.bounds.setBounds(0, 0, |
---|
| 14787 | + //ClickInfo info = new ClickInfo(); |
---|
| 14788 | + object.clickInfo.bounds.setBounds(0, 0, |
---|
14375 | 14789 | (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
14376 | | - info.pane = this; |
---|
14377 | | - info.camera = renderCamera; |
---|
14378 | | - info.x = x; |
---|
14379 | | - info.y = y; |
---|
14380 | | - object.editWindow.copy.doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0); |
---|
| 14790 | + object.clickInfo.pane = this; |
---|
| 14791 | + object.clickInfo.camera = renderCamera; |
---|
| 14792 | + object.clickInfo.x = x; |
---|
| 14793 | + object.clickInfo.y = y; |
---|
| 14794 | + object //.GetWindow().copy |
---|
| 14795 | + .doEditDrag(//info, |
---|
| 14796 | + (modifiers & MouseEvent.BUTTON3_MASK) != 0); |
---|
14381 | 14797 | } else |
---|
14382 | 14798 | { |
---|
14383 | 14799 | if (x < startX) |
---|
.. | .. |
---|
14526 | 14942 | } |
---|
14527 | 14943 | } |
---|
14528 | 14944 | |
---|
| 14945 | +// ClickInfo clickInfo = new ClickInfo(); |
---|
| 14946 | + |
---|
14529 | 14947 | public void mouseMoved(MouseEvent e) |
---|
14530 | 14948 | { |
---|
14531 | 14949 | //System.out.println("mouseMoved: " + e); |
---|
14532 | 14950 | if (isRenderer) |
---|
14533 | 14951 | return; |
---|
14534 | 14952 | |
---|
14535 | | - ClickInfo ci = new ClickInfo(); |
---|
14536 | | - ci.x = e.getX(); |
---|
14537 | | - ci.y = e.getY(); |
---|
14538 | | - ci.modifiers = e.getModifiersEx(); |
---|
14539 | | - ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
14540 | | - ci.pane = this; |
---|
14541 | | - ci.camera = renderCamera; |
---|
| 14953 | + // Mouse cursor feedback |
---|
| 14954 | + object.clickInfo.x = e.getX(); |
---|
| 14955 | + object.clickInfo.y = e.getY(); |
---|
| 14956 | + object.clickInfo.modifiers = e.getModifiersEx(); |
---|
| 14957 | + object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
| 14958 | + object.clickInfo.pane = this; |
---|
| 14959 | + object.clickInfo.camera = renderCamera; |
---|
14542 | 14960 | if (!isRenderer) |
---|
14543 | 14961 | { |
---|
14544 | | - ObjEditor editWindow = object.editWindow; |
---|
14545 | | - Object3D copy = editWindow.copy; |
---|
14546 | | - if (copy.doEditClick(ci, 0)) |
---|
| 14962 | + //ObjEditor editWindow = object.editWindow; |
---|
| 14963 | + //Object3D copy = editWindow.copy; |
---|
| 14964 | + if (object.doEditClick(//clickInfo, |
---|
| 14965 | + 0)) |
---|
14547 | 14966 | { |
---|
14548 | 14967 | setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
---|
14549 | 14968 | } else |
---|
.. | .. |
---|
14558 | 14977 | Globals.MOUSEDRAGGED = false; |
---|
14559 | 14978 | |
---|
14560 | 14979 | movingcamera = false; |
---|
14561 | | - X = Y = 0; |
---|
| 14980 | + X = 0; // getBounds().width/2; |
---|
| 14981 | + Y = 0; // getBounds().height/2; |
---|
14562 | 14982 | //System.out.println("mouseReleased: " + e); |
---|
14563 | 14983 | clickEnd(e.getX(), e.getY(), e.getModifiersEx()); |
---|
14564 | 14984 | } |
---|
.. | .. |
---|
14814 | 15234 | // break; |
---|
14815 | 15235 | case 'T': |
---|
14816 | 15236 | CACHETEXTURE ^= true; |
---|
14817 | | - textures.clear(); |
---|
| 15237 | + texturepigment.clear(); |
---|
| 15238 | + texturebump.clear(); |
---|
14818 | 15239 | // repaint(); |
---|
14819 | 15240 | break; |
---|
14820 | 15241 | case 'Y': |
---|
.. | .. |
---|
14899 | 15320 | case 'E' : COMPACT ^= true; |
---|
14900 | 15321 | repaint(); |
---|
14901 | 15322 | break; |
---|
14902 | | - case 'W' : DEBUGHSB ^= true; |
---|
| 15323 | + case 'W' : // Wide Window (fullscreen) |
---|
| 15324 | + //DEBUGHSB ^= true; |
---|
| 15325 | + ObjEditor.theFrame.ToggleFullScreen(); |
---|
14903 | 15326 | repaint(); |
---|
14904 | 15327 | break; |
---|
14905 | 15328 | case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break; |
---|
.. | .. |
---|
14925 | 15348 | repaint(); |
---|
14926 | 15349 | break; |
---|
14927 | 15350 | case 'l': |
---|
14928 | | - lightMode ^= true; |
---|
14929 | | - Globals.lighttouched = true; |
---|
14930 | | - manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera; |
---|
14931 | | - targetLookAt.set(manipCamera.lookAt); |
---|
14932 | | - repaint(); |
---|
14933 | | - break; |
---|
14934 | | - case 'L': |
---|
| 15351 | + //case 'L': |
---|
14935 | 15352 | if (lightMode) |
---|
14936 | 15353 | { |
---|
14937 | 15354 | lightMode = false; |
---|
.. | .. |
---|
14995 | 15412 | OCCLUSION_CULLING ^= true; |
---|
14996 | 15413 | System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING); |
---|
14997 | 15414 | break; |
---|
14998 | | - case '0': envyoff ^= true; repaint(); break; |
---|
| 15415 | + //case '0': envyoff ^= true; repaint(); break; |
---|
14999 | 15416 | case '1': |
---|
15000 | 15417 | case '2': |
---|
15001 | 15418 | case '3': |
---|
15002 | 15419 | case '4': |
---|
15003 | 15420 | case '5': |
---|
15004 | | - newenvy = Character.getNumericValue(key); |
---|
15005 | | - repaint(); |
---|
15006 | | - break; |
---|
15007 | 15421 | case '6': |
---|
15008 | 15422 | case '7': |
---|
15009 | 15423 | case '8': |
---|
15010 | 15424 | case '9': |
---|
15011 | | - BGcolor = (key - '6')/3.f; |
---|
| 15425 | + if (true) // envyoff) |
---|
| 15426 | + { |
---|
| 15427 | + BGcolor = (key - '1')/8.f; |
---|
| 15428 | + } |
---|
| 15429 | + else |
---|
| 15430 | + { |
---|
| 15431 | + //newenvy = Character.getNumericValue(key); |
---|
| 15432 | + } |
---|
15012 | 15433 | repaint(); |
---|
15013 | 15434 | break; |
---|
15014 | 15435 | case '!': |
---|
.. | .. |
---|
15074 | 15495 | case '_': |
---|
15075 | 15496 | kompactbit = 5; |
---|
15076 | 15497 | break; |
---|
15077 | | - case '+': |
---|
15078 | | - kompactbit = 6; |
---|
15079 | | - break; |
---|
| 15498 | +// case '+': |
---|
| 15499 | +// kompactbit = 6; |
---|
| 15500 | +// break; |
---|
15080 | 15501 | case ' ': |
---|
15081 | | - ObjEditor.theFrame.ToggleFullScreen(); |
---|
| 15502 | + lightMode ^= true; |
---|
| 15503 | + Globals.lighttouched = true; |
---|
| 15504 | + manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera; |
---|
| 15505 | + targetLookAt.set(manipCamera.lookAt); |
---|
15082 | 15506 | repaint(); |
---|
15083 | 15507 | break; |
---|
15084 | 15508 | //case '`' : |
---|
.. | .. |
---|
15125 | 15549 | case DELETE: |
---|
15126 | 15550 | ClearSelection(); |
---|
15127 | 15551 | break; |
---|
15128 | | - /* |
---|
15129 | 15552 | case '+': |
---|
| 15553 | + |
---|
| 15554 | + /* |
---|
15130 | 15555 | //fontsize += 1; |
---|
15131 | 15556 | bbzoom *= 2; |
---|
15132 | 15557 | repaint(); |
---|
.. | .. |
---|
15143 | 15568 | case '=': |
---|
15144 | 15569 | IncDepth(); |
---|
15145 | 15570 | //fontsize += 1; |
---|
15146 | | - object.editWindow.refreshContents(true); |
---|
| 15571 | + object.GetWindow().refreshContents(true); |
---|
15147 | 15572 | maskbit = 6; |
---|
15148 | 15573 | break; |
---|
15149 | 15574 | case '-': //if (PixelThreshold>1) PixelThreshold /= 2; |
---|
15150 | 15575 | DecDepth(); |
---|
15151 | 15576 | maskbit = 5; |
---|
15152 | 15577 | //if(fontsize > 1) fontsize -= 1; |
---|
15153 | | - if (object.editWindow == null) |
---|
15154 | | - new Exception().printStackTrace(); |
---|
15155 | | - else |
---|
15156 | | - object.editWindow.refreshContents(true); |
---|
| 15578 | +// if (object.editWindow == null) |
---|
| 15579 | +// new Exception().printStackTrace(); |
---|
| 15580 | +// else |
---|
| 15581 | + object.GetWindow().refreshContents(true); |
---|
15157 | 15582 | break; |
---|
15158 | 15583 | case '{': |
---|
15159 | 15584 | manipCamera.shaper_fovy /= 1.1; |
---|
.. | .. |
---|
15377 | 15802 | } |
---|
15378 | 15803 | */ |
---|
15379 | 15804 | |
---|
15380 | | - object.editWindow.EditSelection(); |
---|
| 15805 | + object.GetWindow().EditSelection(false); |
---|
15381 | 15806 | } |
---|
15382 | 15807 | |
---|
15383 | 15808 | void SelectParent() |
---|
.. | .. |
---|
15394 | 15819 | { |
---|
15395 | 15820 | //selectees.remove(i); |
---|
15396 | 15821 | System.out.println("select parent of " + elem); |
---|
15397 | | - group.editWindow.Select(elem.parent.GetTreePath(), first, true); |
---|
| 15822 | + group.GetWindow().Select(elem.parent.GetTreePath(), first, true); |
---|
15398 | 15823 | } else |
---|
15399 | 15824 | { |
---|
15400 | | - group.editWindow.Select(elem.GetTreePath(), first, true); |
---|
| 15825 | + group.GetWindow().Select(elem.GetTreePath(), first, true); |
---|
15401 | 15826 | } |
---|
15402 | 15827 | |
---|
15403 | 15828 | first = false; |
---|
.. | .. |
---|
15439 | 15864 | for (int j = 0; j < group.children.size(); j++) |
---|
15440 | 15865 | { |
---|
15441 | 15866 | elem = (Object3D) group.children.elementAt(j); |
---|
15442 | | - object.editWindow.Select(elem.GetTreePath(), first, true); |
---|
| 15867 | + object.GetWindow().Select(elem.GetTreePath(), first, true); |
---|
15443 | 15868 | first = false; |
---|
15444 | 15869 | } |
---|
15445 | 15870 | } else |
---|
15446 | 15871 | { |
---|
15447 | | - object.editWindow.Select(elem.GetTreePath(), first, true); |
---|
| 15872 | + object.GetWindow().Select(elem.GetTreePath(), first, true); |
---|
15448 | 15873 | } |
---|
15449 | 15874 | |
---|
15450 | 15875 | first = false; |
---|
.. | .. |
---|
15455 | 15880 | { |
---|
15456 | 15881 | //Composite group = (Composite) object; |
---|
15457 | 15882 | Object3D group = object; |
---|
15458 | | - group.editWindow.loadClipboard(true); // ClearSelection(false); |
---|
| 15883 | + group.GetWindow().loadClipboard(true); // ClearSelection(false); |
---|
15459 | 15884 | } |
---|
15460 | 15885 | |
---|
15461 | 15886 | void ResetTransform(int mask) |
---|
15462 | 15887 | { |
---|
15463 | 15888 | //Composite group = (Composite) object; |
---|
15464 | 15889 | Object3D group = object; |
---|
15465 | | - group.editWindow.ResetTransform(mask); |
---|
| 15890 | + group.GetWindow().ResetTransform(mask); |
---|
15466 | 15891 | } |
---|
15467 | 15892 | |
---|
15468 | 15893 | void FlipTransform() |
---|
15469 | 15894 | { |
---|
15470 | 15895 | //Composite group = (Composite) object; |
---|
15471 | 15896 | Object3D group = object; |
---|
15472 | | - group.editWindow.FlipTransform(); |
---|
| 15897 | + group.GetWindow().FlipTransform(); |
---|
15473 | 15898 | // group.editWindow.ReduceMesh(true); |
---|
15474 | 15899 | } |
---|
15475 | 15900 | |
---|
.. | .. |
---|
15477 | 15902 | { |
---|
15478 | 15903 | //Composite group = (Composite) object; |
---|
15479 | 15904 | Object3D group = object; |
---|
15480 | | - group.editWindow.PrintMemory(); |
---|
| 15905 | + group.GetWindow().PrintMemory(); |
---|
15481 | 15906 | // group.editWindow.ReduceMesh(true); |
---|
15482 | 15907 | } |
---|
15483 | 15908 | |
---|
.. | .. |
---|
15485 | 15910 | { |
---|
15486 | 15911 | //Composite group = (Composite) object; |
---|
15487 | 15912 | Object3D group = object; |
---|
15488 | | - group.editWindow.ResetCentroid(); |
---|
| 15913 | + group.GetWindow().ResetCentroid(); |
---|
15489 | 15914 | } |
---|
15490 | 15915 | |
---|
15491 | 15916 | void IncDepth() |
---|
.. | .. |
---|
15567 | 15992 | |
---|
15568 | 15993 | int width = getBounds().width; |
---|
15569 | 15994 | int height = getBounds().height; |
---|
15570 | | - ClickInfo info = new ClickInfo(); |
---|
15571 | | - info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom)); |
---|
15572 | 15995 | //Image img = CreateImage(width, height); |
---|
15573 | 15996 | //System.out.println("width = " + width + "; height = " + height + "\n"); |
---|
15574 | 15997 | |
---|
.. | .. |
---|
15645 | 16068 | } |
---|
15646 | 16069 | if (object != null && !hasMarquee) |
---|
15647 | 16070 | { |
---|
| 16071 | + if (object.clickInfo == null) |
---|
| 16072 | + object.clickInfo = new ClickInfo(); |
---|
| 16073 | + ClickInfo info = object.clickInfo; |
---|
| 16074 | + //ClickInfo info = new ClickInfo(); |
---|
| 16075 | + info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom)); |
---|
| 16076 | + |
---|
15648 | 16077 | if (isRenderer) |
---|
15649 | 16078 | { |
---|
15650 | | - info.flags++; |
---|
| 16079 | + object.clickInfo.flags++; |
---|
15651 | 16080 | double frameAspect = (double) width / (double) height; |
---|
15652 | 16081 | if (frameAspect > renderCamera.aspect) |
---|
15653 | 16082 | { |
---|
15654 | 16083 | int desired = (int) ((double) height * renderCamera.aspect); |
---|
15655 | | - info.bounds.width -= width - desired; |
---|
15656 | | - info.bounds.x += (width - desired) / 2; |
---|
| 16084 | + object.clickInfo.bounds.width -= width - desired; |
---|
| 16085 | + object.clickInfo.bounds.x += (width - desired) / 2; |
---|
15657 | 16086 | } else |
---|
15658 | 16087 | { |
---|
15659 | 16088 | int desired = (int) ((double) width / renderCamera.aspect); |
---|
15660 | | - info.bounds.height -= height - desired; |
---|
15661 | | - info.bounds.y += (height - desired) / 2; |
---|
| 16089 | + object.clickInfo.bounds.height -= height - desired; |
---|
| 16090 | + object.clickInfo.bounds.y += (height - desired) / 2; |
---|
15662 | 16091 | } |
---|
15663 | 16092 | } |
---|
15664 | | - info.g = gr; |
---|
15665 | | - info.camera = renderCamera; |
---|
| 16093 | + |
---|
| 16094 | + object.clickInfo.g = gr; |
---|
| 16095 | + object.clickInfo.camera = renderCamera; |
---|
15666 | 16096 | /* |
---|
15667 | 16097 | // Memory intensive (brep.verticescopy) |
---|
15668 | 16098 | if (!(object instanceof Composite)) |
---|
15669 | 16099 | object.draw(info, 0, false); // SLOW : |
---|
15670 | 16100 | */ |
---|
15671 | | - if (!isRenderer) |
---|
| 16101 | + if (!isRenderer) // && drag) |
---|
15672 | 16102 | { |
---|
15673 | | - object.drawEditHandles(info, 0); |
---|
15674 | | - |
---|
15675 | | - if (drag && (X != 0 || Y != 0) && object.selection.Size() > 0) |
---|
| 16103 | + Grafreed.Assert(object != null); |
---|
| 16104 | + Grafreed.Assert(object.selection != null); |
---|
| 16105 | + if (object.selection.Size() > 0) |
---|
15676 | 16106 | { |
---|
15677 | | - switch (object.selection.get(0).hitSomething) |
---|
| 16107 | + int hitSomething = object.selection.get(0).hitSomething; |
---|
| 16108 | + |
---|
| 16109 | + object.clickInfo.DX = 0; |
---|
| 16110 | + object.clickInfo.DY = 0; |
---|
| 16111 | + object.clickInfo.W = 1; |
---|
| 16112 | + if (hitSomething == Object3D.hitCenter) |
---|
15678 | 16113 | { |
---|
15679 | | - case Object3D.hitCenter: gr.setColor(Color.pink); |
---|
15680 | | - gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
15681 | | - break; |
---|
15682 | | - case Object3D.hitRotate: gr.setColor(Color.yellow); |
---|
15683 | | - gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
15684 | | - break; |
---|
15685 | | - case Object3D.hitScale: gr.setColor(Color.cyan); |
---|
15686 | | - gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
15687 | | - break; |
---|
| 16114 | + info.DX = X; |
---|
| 16115 | + if (X != 0) |
---|
| 16116 | + info.DX -= info.bounds.width/2; |
---|
| 16117 | + |
---|
| 16118 | + info.DY = Y; |
---|
| 16119 | + if (Y != 0) |
---|
| 16120 | + info.DY -= info.bounds.height/2; |
---|
15688 | 16121 | } |
---|
15689 | | - |
---|
| 16122 | + |
---|
| 16123 | + object.drawEditHandles(//info, |
---|
| 16124 | + 0); |
---|
| 16125 | + |
---|
| 16126 | + if (drag && (X != 0 || Y != 0)) |
---|
| 16127 | + { |
---|
| 16128 | + switch (hitSomething) |
---|
| 16129 | + { |
---|
| 16130 | + case Object3D.hitCenter: gr.setColor(Color.pink); |
---|
| 16131 | + gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
| 16132 | + break; |
---|
| 16133 | + case Object3D.hitRotate: gr.setColor(Color.yellow); |
---|
| 16134 | + gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
| 16135 | + break; |
---|
| 16136 | + case Object3D.hitScale: gr.setColor(Color.cyan); |
---|
| 16137 | + gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
| 16138 | + break; |
---|
| 16139 | + } |
---|
| 16140 | + |
---|
| 16141 | + } |
---|
15690 | 16142 | } |
---|
15691 | 16143 | } |
---|
15692 | 16144 | } |
---|
.. | .. |
---|
16168 | 16620 | private /*static*/ boolean firstime; |
---|
16169 | 16621 | private /*static*/ cVector newView = new cVector(); |
---|
16170 | 16622 | private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"}; |
---|
| 16623 | + private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"}; |
---|
| 16624 | + private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"}; |
---|
16171 | 16625 | private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X, |
---|
16172 | 16626 | GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X, |
---|
16173 | 16627 | GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y, |
---|
.. | .. |
---|
16180 | 16634 | { |
---|
16181 | 16635 | com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP); |
---|
16182 | 16636 | |
---|
| 16637 | + int usedsuf = 0; |
---|
| 16638 | + |
---|
16183 | 16639 | for (int i = 0; i < suffixes.length; i++) |
---|
16184 | 16640 | { |
---|
16185 | | - String resourceName = basename + suffixes[i] + "." + suffix; |
---|
16186 | | - TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
16187 | | - mipmapped, |
---|
16188 | | - FileUtil.getFileSuffix(resourceName)); |
---|
16189 | | - if (data == null) |
---|
| 16641 | + String[] suffixe = suffixes; |
---|
| 16642 | + String[] fallback = suffixes2; |
---|
| 16643 | + String[] fallfallback = suffixes3; |
---|
| 16644 | + |
---|
| 16645 | + for (int c=usedsuf; --c>=0;) |
---|
16190 | 16646 | { |
---|
16191 | | - throw new IOException("Unable to load texture " + resourceName); |
---|
| 16647 | +// String[] temp = suffixe; |
---|
| 16648 | +// suffixe = fallback; |
---|
| 16649 | +// fallback = fallfallback; |
---|
| 16650 | +// fallfallback = temp; |
---|
16192 | 16651 | } |
---|
| 16652 | + |
---|
| 16653 | + String resourceName = basename + suffixe[i] + "." + suffix; |
---|
| 16654 | + TextureData data; |
---|
| 16655 | + |
---|
| 16656 | + try |
---|
| 16657 | + { |
---|
| 16658 | + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
| 16659 | + mipmapped, |
---|
| 16660 | + FileUtil.getFileSuffix(resourceName)); |
---|
| 16661 | + } |
---|
| 16662 | + catch (Exception e) |
---|
| 16663 | + { |
---|
| 16664 | + try |
---|
| 16665 | + { |
---|
| 16666 | + resourceName = basename + fallback[i] + "." + suffix; |
---|
| 16667 | + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
| 16668 | + mipmapped, |
---|
| 16669 | + FileUtil.getFileSuffix(resourceName)); |
---|
| 16670 | + } |
---|
| 16671 | + catch (Exception e2) |
---|
| 16672 | + { |
---|
| 16673 | + resourceName = basename + fallfallback[i] + "." + suffix; |
---|
| 16674 | + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
| 16675 | + mipmapped, |
---|
| 16676 | + FileUtil.getFileSuffix(resourceName)); |
---|
| 16677 | + } |
---|
| 16678 | + } |
---|
| 16679 | + |
---|
16193 | 16680 | //System.out.println("Target = " + targets[i]); |
---|
16194 | 16681 | cubemap.updateImage(data, targets[i]); |
---|
16195 | 16682 | } |
---|
16196 | 16683 | |
---|
16197 | 16684 | return cubemap; |
---|
16198 | 16685 | } |
---|
| 16686 | + |
---|
16199 | 16687 | int bigsphere = -1; |
---|
16200 | 16688 | |
---|
16201 | 16689 | float BGcolor = 0.5f; |
---|
16202 | 16690 | |
---|
16203 | | - private void DrawSkyBox(GL gl) |
---|
| 16691 | + float ambientLight[] = {1f, 1f, 1f, 1.0f}; |
---|
| 16692 | + |
---|
| 16693 | + private void DrawSkyBox(GL gl, float ratio) |
---|
16204 | 16694 | { |
---|
16205 | | - if (envyoff || cubemap == null) |
---|
| 16695 | + if (//envyoff || |
---|
| 16696 | + WIREFRAME || |
---|
| 16697 | + cubemap == null) |
---|
16206 | 16698 | { |
---|
16207 | 16699 | gl.glClearColor(BGcolor, BGcolor, BGcolor, 1); |
---|
16208 | 16700 | gl.glClear(gl.GL_COLOR_BUFFER_BIT); |
---|
.. | .. |
---|
16217 | 16709 | // Compensates for ExaminerViewer's modification of modelview matrix |
---|
16218 | 16710 | gl.glMatrixMode(GL.GL_MODELVIEW); |
---|
16219 | 16711 | gl.glLoadIdentity(); |
---|
| 16712 | + gl.glScalef(1,ratio,1); |
---|
16220 | 16713 | |
---|
| 16714 | +// colorV[0] = 2; |
---|
| 16715 | +// colorV[1] = 2; |
---|
| 16716 | +// colorV[2] = 2; |
---|
| 16717 | +// colorV[3] = 1; |
---|
| 16718 | +// gl.glDisable(gl.GL_COLOR_MATERIAL); |
---|
| 16719 | +// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0); |
---|
| 16720 | +// |
---|
| 16721 | +// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0); |
---|
| 16722 | + |
---|
16221 | 16723 | //gl.glActiveTexture(GL.GL_TEXTURE1); |
---|
16222 | 16724 | //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP); |
---|
16223 | 16725 | |
---|
.. | .. |
---|
16249 | 16751 | { |
---|
16250 | 16752 | gl.glScalef(1.0f, -1.0f, 1.0f); |
---|
16251 | 16753 | } |
---|
| 16754 | + gl.glScalef(-1.0f, 1.0f, 1.0f); |
---|
16252 | 16755 | gl.glMultMatrixd(viewrot_1, 0); |
---|
16253 | 16756 | gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f); |
---|
16254 | 16757 | //viewer.updateInverseRotation(gl); |
---|
.. | .. |
---|
16289 | 16792 | gl.glDisable(GL.GL_TEXTURE_GEN_R); |
---|
16290 | 16793 | |
---|
16291 | 16794 | cubemap.disable(); |
---|
16292 | | - ////cubemap.unbind(); |
---|
| 16795 | + //cubemap.dispose(); |
---|
| 16796 | + |
---|
16293 | 16797 | if (CULLFACE) |
---|
16294 | 16798 | { |
---|
16295 | 16799 | gl.glEnable(gl.GL_CULL_FACE); |
---|
.. | .. |
---|
16484 | 16988 | } |
---|
16485 | 16989 | } |
---|
16486 | 16990 | |
---|
| 16991 | + private Object3D GetFolder() |
---|
| 16992 | + { |
---|
| 16993 | + Object3D folder = object.GetWindow().copy; |
---|
| 16994 | + if (object.GetWindow().copy.selection.Size() > 0) |
---|
| 16995 | + folder = object.GetWindow().copy.selection.elementAt(0); |
---|
| 16996 | + return folder; |
---|
| 16997 | + } |
---|
| 16998 | + |
---|
16487 | 16999 | class SelectBuffer implements GLEventListener |
---|
16488 | 17000 | { |
---|
16489 | 17001 | |
---|
.. | .. |
---|
16499 | 17011 | //new Exception().printStackTrace(); |
---|
16500 | 17012 | System.out.println("select buffer init"); |
---|
16501 | 17013 | // Use debug pipeline |
---|
16502 | | - drawable.setGL(new DebugGL(drawable.getGL())); |
---|
| 17014 | + //drawable.setGL(new DebugGL(drawable.getGL())); |
---|
16503 | 17015 | |
---|
16504 | 17016 | GL gl = drawable.getGL(); |
---|
16505 | 17017 | |
---|
.. | .. |
---|
16563 | 17075 | |
---|
16564 | 17076 | //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL); |
---|
16565 | 17077 | |
---|
| 17078 | + if (PAINTMODE) |
---|
| 17079 | + { |
---|
| 17080 | + if (object.GetWindow().copy.selection.Size() > 0) |
---|
| 17081 | + { |
---|
| 17082 | + Object3D paintobj = object.GetWindow().copy.selection.elementAt(0); |
---|
| 17083 | + |
---|
| 17084 | + // Make what you paint not selectable. |
---|
| 17085 | + paintobj.ResetSelectable(); |
---|
| 17086 | + } |
---|
| 17087 | + } |
---|
| 17088 | + |
---|
16566 | 17089 | //int tmp = selection_view; |
---|
16567 | 17090 | //selection_view = -1; |
---|
16568 | 17091 | int temp = DrawMode(); |
---|
.. | .. |
---|
16574 | 17097 | // temp = DEFAULT; // patch for selection debug |
---|
16575 | 17098 | Globals.drawMode = temp; // WARNING |
---|
16576 | 17099 | |
---|
| 17100 | + if (PAINTMODE) |
---|
| 17101 | + { |
---|
| 17102 | + if (object.GetWindow().copy.selection.Size() > 0) |
---|
| 17103 | + { |
---|
| 17104 | + Object3D paintobj = object.GetWindow().copy.selection.elementAt(0); |
---|
| 17105 | + |
---|
| 17106 | + // Revert. |
---|
| 17107 | + paintobj.RestoreSelectable(); |
---|
| 17108 | + } |
---|
| 17109 | + } |
---|
| 17110 | + |
---|
16577 | 17111 | //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view); |
---|
16578 | 17112 | |
---|
16579 | 17113 | // trying different ways of getting the depth info over |
---|
.. | .. |
---|
16621 | 17155 | // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]); |
---|
16622 | 17156 | // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]); |
---|
16623 | 17157 | // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]); |
---|
| 17158 | + |
---|
| 17159 | + CreateSelectedPoint(); |
---|
16624 | 17160 | |
---|
16625 | 17161 | // Will fit the mesh !!! |
---|
16626 | 17162 | selectedpoint.toParent[0][0] = 0.0001; |
---|
.. | .. |
---|
16675 | 17211 | } |
---|
16676 | 17212 | |
---|
16677 | 17213 | if (!movingcamera && !PAINTMODE) |
---|
16678 | | - object.editWindow.ScreenFitPoint(); // fev 2014 |
---|
| 17214 | + object.GetWindow().ScreenFitPoint(); // fev 2014 |
---|
16679 | 17215 | |
---|
16680 | | - if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0) |
---|
| 17216 | + if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0) |
---|
16681 | 17217 | { |
---|
16682 | | - Object3D paintobj = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0); |
---|
| 17218 | + //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0); |
---|
16683 | 17219 | |
---|
16684 | | - Object3D group = new Object3D("inst" + paintcount++); |
---|
| 17220 | + if (object.GetWindow().copy.selection.Size() > 0) |
---|
| 17221 | + { |
---|
| 17222 | + Object3D paintobj = object.GetWindow().copy.selection.elementAt(0); |
---|
16685 | 17223 | |
---|
16686 | | - group.CreateMaterial(); // use a void leaf to select instances |
---|
16687 | | - |
---|
16688 | | - group.add(paintobj); // link |
---|
16689 | | - |
---|
16690 | | - object.editWindow.SnapObject(group); |
---|
16691 | | - |
---|
16692 | | - Object3D folder = object.editWindow.copy; |
---|
16693 | | - |
---|
16694 | | - if (object.editWindow.copy.selection.Size() > 0) |
---|
16695 | | - folder = object.editWindow.copy.selection.elementAt(0); |
---|
16696 | | - |
---|
16697 | | - folder.add(group); |
---|
16698 | | - |
---|
16699 | | - object.editWindow.ResetModel(); |
---|
16700 | | - object.editWindow.refreshContents(); |
---|
| 17224 | + Object3D inst = new Object3D("inst" + paintcount++); |
---|
| 17225 | + |
---|
| 17226 | + inst.CreateMaterial(); // use a void leaf to select instances |
---|
| 17227 | + |
---|
| 17228 | + inst.add(paintobj); // link |
---|
| 17229 | + |
---|
| 17230 | + object.GetWindow().SnapObject(inst); |
---|
| 17231 | + |
---|
| 17232 | + Object3D folder = paintFolder; // GetFolder(); |
---|
| 17233 | + |
---|
| 17234 | + folder.add(inst); |
---|
| 17235 | + |
---|
| 17236 | + object.GetWindow().ResetModel(); |
---|
| 17237 | + object.GetWindow().refreshContents(); |
---|
| 17238 | + } |
---|
16701 | 17239 | } |
---|
16702 | 17240 | else |
---|
16703 | 17241 | paintcount = 0; |
---|
.. | .. |
---|
16736 | 17274 | //System.out.println("objects[color] = " + objects[color]); |
---|
16737 | 17275 | //objects[color].Select(); |
---|
16738 | 17276 | indexcount = 0; |
---|
| 17277 | + ObjEditor window = object.GetWindow(); |
---|
| 17278 | + if (window != null && deselect) |
---|
| 17279 | + { |
---|
| 17280 | + window.Select(null, deselect, true); |
---|
| 17281 | + } |
---|
16739 | 17282 | object.Select(color, deselect); |
---|
16740 | 17283 | } |
---|
16741 | 17284 | |
---|
.. | .. |
---|
17014 | 17557 | gl.glFlush(); |
---|
17015 | 17558 | |
---|
17016 | 17559 | /**/ |
---|
17017 | | - gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer); |
---|
| 17560 | + gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer); |
---|
17018 | 17561 | |
---|
17019 | | - float[] pixels = occlusionsizebuffer.array(); |
---|
| 17562 | + float[] depths = occlusiondepthbuffer.array(); |
---|
17020 | 17563 | |
---|
| 17564 | + gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer); |
---|
| 17565 | + |
---|
| 17566 | + int[] pixels = selectsizebuffer.array(); |
---|
| 17567 | + |
---|
17021 | 17568 | double r = 0, g = 0, b = 0; |
---|
17022 | 17569 | |
---|
17023 | 17570 | double count = 0; |
---|
.. | .. |
---|
17028 | 17575 | |
---|
17029 | 17576 | double FACTOR = 1; |
---|
17030 | 17577 | |
---|
17031 | | - for (int i = 0; i < pixels.length; i++) |
---|
| 17578 | + for (int i = 0; i < depths.length; i++) |
---|
17032 | 17579 | { |
---|
17033 | 17580 | int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2; |
---|
17034 | 17581 | int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2; |
---|
.. | .. |
---|
17111 | 17658 | |
---|
17112 | 17659 | double scale = ray.z; // 1; // cos |
---|
17113 | 17660 | |
---|
17114 | | - float depth = pixels[newindex]; |
---|
| 17661 | + float depth = depths[newindex]; |
---|
17115 | 17662 | |
---|
17116 | 17663 | /* |
---|
17117 | 17664 | int newindex2 = (x + 1) * OCCLUSION_SIZE + y; |
---|
.. | .. |
---|
17308 | 17855 | static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE); |
---|
17309 | 17856 | static IntBuffer bigAAbuffer; |
---|
17310 | 17857 | static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3); |
---|
17311 | | - static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE); |
---|
| 17858 | + //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE); |
---|
17312 | 17859 | static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE); |
---|
17313 | 17860 | static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE); |
---|
17314 | 17861 | //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); |
---|
17315 | | - static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); |
---|
| 17862 | + static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); |
---|
| 17863 | + |
---|
| 17864 | + static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); |
---|
| 17865 | + |
---|
17316 | 17866 | static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB); |
---|
17317 | 17867 | static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); |
---|
17318 | 17868 | static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>(); |
---|