.. | .. |
---|
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; |
---|
77 | 116 | boolean reverseUP = false; |
---|
78 | 117 | static boolean frozen = false; |
---|
79 | 118 | boolean enablebackspace = false; // patch for back buffer refresh |
---|
.. | .. |
---|
136 | 175 | static boolean doublesided = false; // true; // reversed normals are awful for conformance |
---|
137 | 176 | boolean anisotropy = true; |
---|
138 | 177 | boolean softshadow = true; // slower but better false; |
---|
139 | | - boolean opacityhalo = false; |
---|
| 178 | + boolean opacityhalo = false; // reverse the halo effect (e.g. glass) |
---|
140 | 179 | |
---|
141 | 180 | boolean macromode = false; |
---|
142 | 181 | |
---|
.. | .. |
---|
150 | 189 | } |
---|
151 | 190 | |
---|
152 | 191 | private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory(); |
---|
| 192 | + |
---|
| 193 | + public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException |
---|
| 194 | + { |
---|
| 195 | + try |
---|
| 196 | + { |
---|
| 197 | + return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap); |
---|
| 198 | + } catch (IOException e) |
---|
| 199 | + { |
---|
| 200 | + System.out.println("NAME = " + name); |
---|
| 201 | + e.printStackTrace(); // throw new RuntimeException(e); |
---|
| 202 | + return null; |
---|
| 203 | + } |
---|
| 204 | + } |
---|
153 | 205 | |
---|
154 | 206 | void SetAsGLRenderer(boolean b) |
---|
155 | 207 | { |
---|
.. | .. |
---|
169 | 221 | |
---|
170 | 222 | SetCamera(cam); |
---|
171 | 223 | |
---|
172 | | - SetLight(new Camera(new cVector(10, 10, -20))); |
---|
| 224 | + // Warning: not used. |
---|
| 225 | + SetLight(new Camera(new cVector(15, 10, -20))); |
---|
173 | 226 | |
---|
174 | 227 | object = o; |
---|
175 | 228 | |
---|
.. | .. |
---|
335 | 388 | display.options1[2] = material.shadowbias; |
---|
336 | 389 | display.options1[3] = material.aniso; |
---|
337 | 390 | display.options1[4] = material.anisoV; |
---|
| 391 | +// System.out.println("display.options1[0] " + display.options1[0]); |
---|
| 392 | +// System.out.println("display.options1[1] " + display.options1[1]); |
---|
| 393 | +// System.out.println("display.options1[2] " + display.options1[2]); |
---|
| 394 | +// System.out.println("display.options1[3] " + display.options1[3]); |
---|
| 395 | +// System.out.println("display.options1[4] " + display.options1[4]); |
---|
338 | 396 | display.options2[0] = material.opacity; |
---|
339 | 397 | display.options2[1] = material.diffuse; |
---|
340 | 398 | display.options2[2] = material.factor; |
---|
| 399 | +// System.out.println("display.options2[0] " + display.options2[0]); |
---|
| 400 | +// System.out.println("display.options2[1] " + display.options2[1]); |
---|
| 401 | +// System.out.println("display.options2[2] " + display.options2[2]); |
---|
341 | 402 | |
---|
342 | 403 | cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3); |
---|
| 404 | +// System.out.println("display.options3[0] " + display.options3[0]); |
---|
| 405 | +// System.out.println("display.options3[1] " + display.options3[1]); |
---|
| 406 | +// System.out.println("display.options3[2] " + display.options3[2]); |
---|
343 | 407 | display.options4[0] = material.cameralight/0.2f; |
---|
344 | 408 | display.options4[1] = material.subsurface; |
---|
345 | 409 | display.options4[2] = material.sheen; |
---|
| 410 | +// System.out.println("display.options4[0] " + display.options4[0]); |
---|
| 411 | +// System.out.println("display.options4[1] " + display.options4[1]); |
---|
| 412 | +// System.out.println("display.options4[2] " + display.options4[2]); |
---|
346 | 413 | |
---|
347 | 414 | // if (display.CURRENTANTIALIAS > 0) |
---|
348 | 415 | // display.options3[3] /= 4; |
---|
.. | .. |
---|
1433 | 1500 | gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z); |
---|
1434 | 1501 | } |
---|
1435 | 1502 | |
---|
| 1503 | + float[] colorV = new float[4]; |
---|
| 1504 | + |
---|
1436 | 1505 | void SetColor(Object3D obj, Vertex p0) |
---|
1437 | 1506 | { |
---|
1438 | 1507 | CameraPane display = this; |
---|
.. | .. |
---|
1500 | 1569 | { |
---|
1501 | 1570 | return; |
---|
1502 | 1571 | } |
---|
1503 | | - |
---|
1504 | | - float[] colorV = new float[3]; |
---|
1505 | 1572 | |
---|
1506 | 1573 | if (false) // marked) |
---|
1507 | 1574 | { |
---|
.. | .. |
---|
2051 | 2118 | //System.err.println("Oeil on"); |
---|
2052 | 2119 | OEIL = true; |
---|
2053 | 2120 | if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode) |
---|
2054 | | - object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK); |
---|
| 2121 | + object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK); |
---|
2055 | 2122 | //pingthread.StepToTarget(true); |
---|
2056 | 2123 | } |
---|
2057 | 2124 | |
---|
.. | .. |
---|
2284 | 2351 | HANDLES ^= true; |
---|
2285 | 2352 | } |
---|
2286 | 2353 | |
---|
| 2354 | + Object3D paintFolder; |
---|
| 2355 | + |
---|
2287 | 2356 | void TogglePaint() |
---|
2288 | 2357 | { |
---|
2289 | 2358 | PAINTMODE ^= true; |
---|
2290 | 2359 | paintcount = 0; |
---|
| 2360 | + |
---|
| 2361 | + if (PAINTMODE) |
---|
| 2362 | + { |
---|
| 2363 | + paintFolder = GetFolder(); |
---|
| 2364 | + } |
---|
2291 | 2365 | } |
---|
2292 | 2366 | |
---|
2293 | 2367 | void SwapCamera(int a, int b) |
---|
.. | .. |
---|
2384 | 2458 | return currentGL; |
---|
2385 | 2459 | } |
---|
2386 | 2460 | |
---|
| 2461 | + static private BufferedImage CreateBim(TextureData texturedata) |
---|
| 2462 | + { |
---|
| 2463 | + Grafreed.Assert(texturedata != null); |
---|
| 2464 | + |
---|
| 2465 | + int width = texturedata.getWidth(); |
---|
| 2466 | + int height = texturedata.getHeight(); |
---|
| 2467 | + |
---|
| 2468 | + Buffer buffer = texturedata.getBuffer(); |
---|
| 2469 | + ByteBuffer bytebuf = (ByteBuffer)buffer; |
---|
| 2470 | + |
---|
| 2471 | + byte[] bytes = bytebuf.array(); |
---|
| 2472 | + |
---|
| 2473 | + return CreateBim(bytes, width, height); |
---|
| 2474 | + } |
---|
| 2475 | + |
---|
2387 | 2476 | /**/ |
---|
2388 | 2477 | class CacheTexture |
---|
2389 | 2478 | { |
---|
.. | .. |
---|
2392 | 2481 | |
---|
2393 | 2482 | int resolution; |
---|
2394 | 2483 | |
---|
2395 | | - CacheTexture(com.sun.opengl.util.texture.Texture tex, int res) |
---|
| 2484 | + CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res) |
---|
2396 | 2485 | { |
---|
2397 | | - texture = tex; |
---|
| 2486 | + texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata); |
---|
| 2487 | + texturedata = texdata; |
---|
2398 | 2488 | resolution = res; |
---|
2399 | 2489 | } |
---|
2400 | 2490 | } |
---|
2401 | 2491 | /**/ |
---|
2402 | 2492 | |
---|
2403 | 2493 | // 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>(); |
---|
| 2494 | + static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>(); |
---|
| 2495 | + static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>(); |
---|
| 2496 | + static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>(); |
---|
| 2497 | + static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>(); |
---|
| 2498 | + |
---|
2407 | 2499 | int pigmentdepth = 0; |
---|
2408 | 2500 | public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536]; |
---|
2409 | 2501 | int bumpdepth = 0; |
---|
2410 | 2502 | public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536]; |
---|
2411 | 2503 | //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE"; |
---|
2412 | 2504 | public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP"); |
---|
2413 | | - public static String NOISE_TEXTURE = "WHITE_NOISE"; |
---|
| 2505 | + public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:"); |
---|
2414 | 2506 | // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL"); |
---|
2415 | 2507 | |
---|
2416 | | - com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump) |
---|
| 2508 | + com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump) |
---|
2417 | 2509 | { |
---|
2418 | 2510 | TextureData texturedata = null; |
---|
2419 | 2511 | |
---|
.. | .. |
---|
2432 | 2524 | if (bump) |
---|
2433 | 2525 | texturedata = ConvertBump(texturedata, false); |
---|
2434 | 2526 | |
---|
2435 | | - com.sun.opengl.util.texture.Texture texture = |
---|
2436 | | - com.sun.opengl.util.texture.TextureIO.newTexture(texturedata); |
---|
| 2527 | +// com.sun.opengl.util.texture.Texture texture = |
---|
| 2528 | +// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata); |
---|
2437 | 2529 | |
---|
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); |
---|
| 2530 | + //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT); |
---|
| 2531 | + //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT); |
---|
2440 | 2532 | |
---|
2441 | | - return texture; |
---|
| 2533 | + return texturedata; |
---|
| 2534 | + } |
---|
| 2535 | + |
---|
| 2536 | + com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump) |
---|
| 2537 | + { |
---|
| 2538 | + TextureData texturedata = null; |
---|
| 2539 | + |
---|
| 2540 | + try |
---|
| 2541 | + { |
---|
| 2542 | + texturedata = |
---|
| 2543 | + com.sun.opengl.util.texture.TextureIO.newTextureData( |
---|
| 2544 | + bim, |
---|
| 2545 | + true); |
---|
| 2546 | + } catch (Exception e) |
---|
| 2547 | + { |
---|
| 2548 | + throw new javax.media.opengl.GLException(e); |
---|
| 2549 | + } |
---|
| 2550 | + |
---|
| 2551 | + if (bump) |
---|
| 2552 | + texturedata = ConvertBump(texturedata, false); |
---|
| 2553 | + |
---|
| 2554 | + return texturedata; |
---|
2442 | 2555 | } |
---|
2443 | 2556 | |
---|
2444 | 2557 | boolean HUESMOOTH = true; // wrap around bug... true; |
---|
.. | .. |
---|
3511 | 3624 | |
---|
3512 | 3625 | System.out.println("LOADING TEXTURE : " + name); |
---|
3513 | 3626 | |
---|
| 3627 | + Object x = texturedata.getMipmapData(); // .getBuffer(); |
---|
| 3628 | + |
---|
3514 | 3629 | // |
---|
3515 | 3630 | if (false) // compressbit > 0) |
---|
3516 | 3631 | { |
---|
.. | .. |
---|
7909 | 8024 | String pigment = Object3D.GetPigment(tex); |
---|
7910 | 8025 | String bump = Object3D.GetBump(tex); |
---|
7911 | 8026 | |
---|
7912 | | - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8027 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
7913 | 8028 | { |
---|
7914 | 8029 | // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment); |
---|
7915 | 8030 | // System.out.println("; bump = " + bump); |
---|
.. | .. |
---|
7924 | 8039 | pigment = null; |
---|
7925 | 8040 | } |
---|
7926 | 8041 | |
---|
7927 | | - ReleaseTexture(bump, true); |
---|
7928 | | - ReleaseTexture(pigment, false); |
---|
| 8042 | + ReleaseTexture(tex, true); |
---|
| 8043 | + ReleaseTexture(tex, false); |
---|
7929 | 8044 | } |
---|
7930 | 8045 | |
---|
7931 | 8046 | public void ReleasePigmentTexture(cTexture tex) // INTERFACE |
---|
.. | .. |
---|
7943 | 8058 | |
---|
7944 | 8059 | String pigment = Object3D.GetPigment(tex); |
---|
7945 | 8060 | |
---|
7946 | | - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8061 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
7947 | 8062 | { |
---|
7948 | 8063 | // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment); |
---|
7949 | 8064 | // System.out.println("; bump = " + bump); |
---|
.. | .. |
---|
7954 | 8069 | pigment = null; |
---|
7955 | 8070 | } |
---|
7956 | 8071 | |
---|
7957 | | - ReleaseTexture(pigment, false); |
---|
| 8072 | + ReleaseTexture(tex, false); |
---|
7958 | 8073 | } |
---|
7959 | 8074 | |
---|
7960 | 8075 | public void ReleaseBumpTexture(cTexture tex) // INTERFACE |
---|
.. | .. |
---|
7972 | 8087 | |
---|
7973 | 8088 | String bump = Object3D.GetBump(tex); |
---|
7974 | 8089 | |
---|
7975 | | - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8090 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
7976 | 8091 | { |
---|
7977 | 8092 | // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment); |
---|
7978 | 8093 | // System.out.println("; bump = " + bump); |
---|
.. | .. |
---|
7983 | 8098 | bump = null; |
---|
7984 | 8099 | } |
---|
7985 | 8100 | |
---|
7986 | | - ReleaseTexture(bump, true); |
---|
| 8101 | + ReleaseTexture(tex, true); |
---|
7987 | 8102 | } |
---|
7988 | 8103 | |
---|
7989 | | - void ReleaseTexture(String tex, boolean bump) |
---|
| 8104 | + void ReleaseTexture(cTexture tex, boolean bump) |
---|
7990 | 8105 | { |
---|
7991 | 8106 | if (// DrawMode() != 0 || /*tex == null ||*/ |
---|
7992 | 8107 | ambientOcclusion ) // || !textureon) |
---|
.. | .. |
---|
7997 | 8112 | CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null; |
---|
7998 | 8113 | |
---|
7999 | 8114 | if (tex != null) |
---|
8000 | | - texture = textures.get(tex); |
---|
| 8115 | + texture = bump ? texturebump.get(tex) : texturepigment.get(tex); |
---|
8001 | 8116 | |
---|
8002 | 8117 | // //assert( texture != null ); |
---|
8003 | 8118 | // if (texture == null) |
---|
.. | .. |
---|
8091 | 8206 | |
---|
8092 | 8207 | /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE |
---|
8093 | 8208 | { |
---|
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 | | - } |
---|
| 8209 | +// if (// DrawMode() != 0 || /*tex == null ||*/ |
---|
| 8210 | +// ambientOcclusion ) // || !textureon) |
---|
| 8211 | +// { |
---|
| 8212 | +// return; // false; |
---|
| 8213 | +// } |
---|
| 8214 | +// |
---|
| 8215 | +// if (tex == null) |
---|
| 8216 | +// { |
---|
| 8217 | +// BindTexture(null,false,resolution); |
---|
| 8218 | +// BindTexture(null,true,resolution); |
---|
| 8219 | +// return; |
---|
| 8220 | +// } |
---|
| 8221 | +// |
---|
| 8222 | +// String pigment = Object3D.GetPigment(tex); |
---|
| 8223 | +// String bump = Object3D.GetBump(tex); |
---|
| 8224 | +// |
---|
| 8225 | +// usedtextures.add(pigment); |
---|
| 8226 | +// usedtextures.add(bump); |
---|
| 8227 | +// |
---|
| 8228 | +// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8229 | +// { |
---|
| 8230 | +// // System.out.print("BIND +++++++++++++++ pigment = " + pigment); |
---|
| 8231 | +// // System.out.println("; bump = " + bump); |
---|
| 8232 | +// } |
---|
| 8233 | +// |
---|
| 8234 | +// if (bump.equals("")) |
---|
| 8235 | +// { |
---|
| 8236 | +// bump = null; |
---|
| 8237 | +// } |
---|
| 8238 | +// if (pigment.equals("")) |
---|
| 8239 | +// { |
---|
| 8240 | +// pigment = null; |
---|
| 8241 | +// } |
---|
| 8242 | +// |
---|
| 8243 | +// GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
| 8244 | +// BindTexture(pigment, false, resolution); |
---|
| 8245 | +// GetGL().glActiveTexture(GetGL().GL_TEXTURE2); |
---|
| 8246 | +// BindTexture(bump, true, resolution); |
---|
| 8247 | +// GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
| 8248 | +// |
---|
| 8249 | +// return; // true; |
---|
8106 | 8250 | |
---|
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; |
---|
| 8251 | + BindPigmentTexture(tex, resolution); |
---|
| 8252 | + BindBumpTexture(tex, resolution); |
---|
8135 | 8253 | } |
---|
8136 | 8254 | |
---|
8137 | 8255 | /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE |
---|
.. | .. |
---|
8150 | 8268 | |
---|
8151 | 8269 | String pigment = Object3D.GetPigment(tex); |
---|
8152 | 8270 | |
---|
8153 | | - usedtextures.put(pigment, pigment); |
---|
| 8271 | + usedtextures.add(tex); |
---|
8154 | 8272 | |
---|
8155 | | - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8273 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
8156 | 8274 | { |
---|
8157 | 8275 | // System.out.print("BIND +++++++++++++++ pigment = " + pigment); |
---|
8158 | 8276 | // System.out.println("; bump = " + bump); |
---|
.. | .. |
---|
8164 | 8282 | } |
---|
8165 | 8283 | |
---|
8166 | 8284 | GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
8167 | | - BindTexture(pigment, false, resolution); |
---|
| 8285 | + BindTexture(tex, false, resolution); |
---|
8168 | 8286 | } |
---|
8169 | 8287 | |
---|
8170 | 8288 | /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE |
---|
.. | .. |
---|
8183 | 8301 | |
---|
8184 | 8302 | String bump = Object3D.GetBump(tex); |
---|
8185 | 8303 | |
---|
8186 | | - usedtextures.put(bump, bump); |
---|
| 8304 | + usedtextures.add(tex); |
---|
8187 | 8305 | |
---|
8188 | | - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8306 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
8189 | 8307 | { |
---|
8190 | 8308 | // System.out.print("BIND +++++++++++++++ pigment = " + pigment); |
---|
8191 | 8309 | // System.out.println("; bump = " + bump); |
---|
.. | .. |
---|
8197 | 8315 | } |
---|
8198 | 8316 | |
---|
8199 | 8317 | GetGL().glActiveTexture(GetGL().GL_TEXTURE2); |
---|
8200 | | - BindTexture(bump, true, resolution); |
---|
| 8318 | + BindTexture(tex, true, resolution); |
---|
8201 | 8319 | GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
8202 | 8320 | } |
---|
8203 | 8321 | |
---|
.. | .. |
---|
8221 | 8339 | return fileExists; |
---|
8222 | 8340 | } |
---|
8223 | 8341 | |
---|
8224 | | - CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception |
---|
| 8342 | + CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8225 | 8343 | { |
---|
8226 | | - CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null; |
---|
| 8344 | + CacheTexture texturecache = null; |
---|
8227 | 8345 | |
---|
8228 | 8346 | if (tex != null) |
---|
8229 | 8347 | { |
---|
8230 | | - String texname = tex; |
---|
| 8348 | + String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex); |
---|
| 8349 | + byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata; |
---|
| 8350 | + |
---|
| 8351 | + if (texname.equals("") && texdata == null) |
---|
| 8352 | + { |
---|
| 8353 | + return null; |
---|
| 8354 | + } |
---|
8231 | 8355 | |
---|
8232 | 8356 | String fallbackTextureName = defaultDirectory + "/Textures/" + texname; |
---|
8233 | 8357 | |
---|
.. | .. |
---|
8237 | 8361 | // else |
---|
8238 | 8362 | // if (!texname.startsWith("/")) |
---|
8239 | 8363 | // texname = "/Users/nbriere/Textures/" + texname; |
---|
8240 | | - if (!FileExists(tex)) |
---|
| 8364 | + if (!FileExists(texname) && !texname.startsWith("@")) |
---|
8241 | 8365 | { |
---|
8242 | 8366 | texname = fallbackTextureName; |
---|
8243 | 8367 | } |
---|
8244 | 8368 | |
---|
8245 | 8369 | if (CACHETEXTURE) |
---|
8246 | | - texture = textures.get(texname); // TEXTURE CACHE |
---|
8247 | | - |
---|
8248 | | - TextureData texturedata = null; |
---|
8249 | | - |
---|
8250 | | - if (texture == null || texture.resolution < resolution) |
---|
8251 | 8370 | { |
---|
8252 | | - if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals("")) |
---|
| 8371 | + if (texdata == null) |
---|
| 8372 | + texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex); |
---|
| 8373 | + else |
---|
| 8374 | + texturecache = bimtextures.get(texdata); |
---|
| 8375 | + } |
---|
| 8376 | + |
---|
| 8377 | + if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution) |
---|
| 8378 | + { |
---|
| 8379 | + TextureData texturedata = null; |
---|
| 8380 | + |
---|
| 8381 | + if (texdata != null && textureon) |
---|
| 8382 | + { |
---|
| 8383 | + BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB); |
---|
| 8384 | + |
---|
| 8385 | + try |
---|
| 8386 | + { |
---|
| 8387 | + bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph); |
---|
| 8388 | + } |
---|
| 8389 | + catch (Exception e) |
---|
| 8390 | + { |
---|
| 8391 | + bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph); |
---|
| 8392 | + } |
---|
| 8393 | + |
---|
| 8394 | + texturecache = new CacheTexture(GetBimTexture(bim, bump), -1); |
---|
| 8395 | + bimtextures.put(texdata, texturecache); |
---|
| 8396 | + |
---|
| 8397 | + //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB); |
---|
| 8398 | + |
---|
| 8399 | + //Object bim2 = CreateBim(texturecache.texturedata); |
---|
| 8400 | + //bim2 = bim; |
---|
| 8401 | + } |
---|
| 8402 | + else |
---|
| 8403 | + if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals("")) |
---|
8253 | 8404 | { |
---|
8254 | 8405 | assert(!bump); |
---|
8255 | 8406 | // if (bump) |
---|
.. | .. |
---|
8260 | 8411 | // } |
---|
8261 | 8412 | // else |
---|
8262 | 8413 | // { |
---|
8263 | | - texture = textures.get(tex); |
---|
8264 | | - if (texture == null) |
---|
| 8414 | + // texturecache = textures.get(texname); // suspicious |
---|
| 8415 | + if (texturecache == null) |
---|
8265 | 8416 | { |
---|
8266 | | - texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
| 8417 | + texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
8267 | 8418 | } |
---|
| 8419 | + else |
---|
| 8420 | + new Exception().printStackTrace(); |
---|
8268 | 8421 | // } |
---|
8269 | 8422 | } else |
---|
8270 | | - if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals("")) |
---|
| 8423 | + if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals("")) |
---|
8271 | 8424 | { |
---|
8272 | 8425 | assert(bump); |
---|
8273 | | - texture = textures.get(tex); |
---|
8274 | | - if (texture == null) |
---|
8275 | | - texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
| 8426 | + // texturecache = textures.get(texname); // suspicious |
---|
| 8427 | + if (texturecache == null) |
---|
| 8428 | + texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
| 8429 | + else |
---|
| 8430 | + new Exception().printStackTrace(); |
---|
8276 | 8431 | } else |
---|
8277 | 8432 | { |
---|
8278 | 8433 | //if (tex.equals("IMMORTAL")) |
---|
.. | .. |
---|
8280 | 8435 | // texture = GetResourceTexture("default.png"); |
---|
8281 | 8436 | //} else |
---|
8282 | 8437 | //{ |
---|
8283 | | - if (tex.equals("WHITE_NOISE")) |
---|
| 8438 | + if (texname.endsWith("WHITE_NOISE")) |
---|
8284 | 8439 | { |
---|
8285 | | - texture = textures.get(tex); |
---|
8286 | | - if (texture == null) |
---|
8287 | | - texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution); |
---|
| 8440 | + // texturecache = textures.get(texname); // suspicious |
---|
| 8441 | + if (texturecache == null) |
---|
| 8442 | + texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution); |
---|
| 8443 | + else |
---|
| 8444 | + new Exception().printStackTrace(); |
---|
| 8445 | + } else |
---|
| 8446 | + { |
---|
| 8447 | + if (texname.startsWith("@")) |
---|
| 8448 | + { |
---|
| 8449 | + // texturecache = textures.get(texname); // suspicious |
---|
| 8450 | + if (texturecache == null) |
---|
| 8451 | + texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution); |
---|
| 8452 | + else |
---|
| 8453 | + new Exception().printStackTrace(); |
---|
8288 | 8454 | } else |
---|
8289 | 8455 | { |
---|
8290 | 8456 | if (textureon) |
---|
.. | .. |
---|
8343 | 8509 | if (texturedata == null) |
---|
8344 | 8510 | throw new Exception(); |
---|
8345 | 8511 | |
---|
8346 | | - texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution); |
---|
| 8512 | + texturecache = new CacheTexture(texturedata,resolution); |
---|
8347 | 8513 | //texture = GetTexture(tex, bump); |
---|
8348 | 8514 | } |
---|
| 8515 | + } |
---|
8349 | 8516 | } |
---|
8350 | 8517 | //} |
---|
8351 | 8518 | } |
---|
8352 | 8519 | |
---|
8353 | | - if (/*CACHETEXTURE &&*/ texture != null && textureon) |
---|
| 8520 | + if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon) |
---|
8354 | 8521 | { |
---|
8355 | 8522 | //return false; |
---|
8356 | 8523 | |
---|
8357 | 8524 | // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")"); |
---|
8358 | | - if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG"))) |
---|
| 8525 | + if (texturedata != null && texname.toLowerCase().endsWith(".jpg")) |
---|
8359 | 8526 | { |
---|
8360 | 8527 | // String ext = "_highres"; |
---|
8361 | 8528 | // if (REDUCETEXTURE) |
---|
.. | .. |
---|
8372 | 8539 | File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg"); |
---|
8373 | 8540 | if (!cachefile.exists()) |
---|
8374 | 8541 | { |
---|
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)) |
---|
| 8542 | + //if (texturedata.getWidth() == texturedata.getHeight()) |
---|
8384 | 8543 | { |
---|
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); |
---|
| 8544 | + BufferedImage rendImage = CreateBim(texturedata); |
---|
| 8545 | + |
---|
8415 | 8546 | ImageWriter writer = null; |
---|
8416 | 8547 | Iterator iter = ImageIO.getImageWritersByFormatName("jpg"); |
---|
8417 | 8548 | if (iter.hasNext()) { |
---|
8418 | 8549 | writer = (ImageWriter)iter.next(); |
---|
8419 | 8550 | } |
---|
8420 | | - float compressionQuality = 0.9f; |
---|
| 8551 | + |
---|
| 8552 | + float compressionQuality = 0.85f; |
---|
8421 | 8553 | try |
---|
8422 | 8554 | { |
---|
8423 | 8555 | ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile); |
---|
.. | .. |
---|
8434 | 8566 | } |
---|
8435 | 8567 | } |
---|
8436 | 8568 | } |
---|
8437 | | - |
---|
| 8569 | + |
---|
| 8570 | + Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment; |
---|
| 8571 | + |
---|
8438 | 8572 | //System.out.println("Texture = " + tex); |
---|
8439 | | - if (textures.containsKey(texname)) |
---|
| 8573 | + if (textures.containsKey(tex)) |
---|
8440 | 8574 | { |
---|
8441 | | - CacheTexture thetex = textures.get(texname); |
---|
| 8575 | + CacheTexture thetex = textures.get(tex); |
---|
8442 | 8576 | thetex.texture.disable(); |
---|
8443 | 8577 | thetex.texture.dispose(); |
---|
8444 | | - textures.remove(texname); |
---|
| 8578 | + textures.remove(tex); |
---|
8445 | 8579 | } |
---|
8446 | 8580 | |
---|
8447 | | - texture.texturedata = texturedata; |
---|
8448 | | - textures.put(texname, texture); |
---|
| 8581 | + //texture.texturedata = texturedata; |
---|
| 8582 | + textures.put(tex, texturecache); |
---|
8449 | 8583 | |
---|
8450 | 8584 | // newtex = true; |
---|
8451 | 8585 | } |
---|
.. | .. |
---|
8461 | 8595 | } |
---|
8462 | 8596 | } |
---|
8463 | 8597 | |
---|
8464 | | - return texture; |
---|
| 8598 | + return texturecache; |
---|
8465 | 8599 | } |
---|
8466 | 8600 | |
---|
8467 | | - com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution) throws Exception |
---|
| 8601 | + static void EmbedTextures(cTexture tex) |
---|
| 8602 | + { |
---|
| 8603 | + if (tex.pigmentdata == null) |
---|
| 8604 | + { |
---|
| 8605 | + //String texname = Object3D.GetPigment(tex); |
---|
| 8606 | + |
---|
| 8607 | + CacheTexture texturecache = texturepigment.get(tex); |
---|
| 8608 | + |
---|
| 8609 | + if (texturecache != null) |
---|
| 8610 | + { |
---|
| 8611 | + tex.pw = texturecache.texturedata.getWidth(); |
---|
| 8612 | + tex.ph = texturecache.texturedata.getHeight(); |
---|
| 8613 | + tex.pigmentdata = //CompressJPEG(CreateBim |
---|
| 8614 | + ((ByteBuffer)texturecache.texturedata.getBuffer()).array() |
---|
| 8615 | + ; |
---|
| 8616 | + //, tex.pw, tex.ph), 0.5f); |
---|
| 8617 | + } |
---|
| 8618 | + } |
---|
| 8619 | + |
---|
| 8620 | + if (tex.bumpdata == null) |
---|
| 8621 | + { |
---|
| 8622 | + //String texname = Object3D.GetBump(tex); |
---|
| 8623 | + |
---|
| 8624 | + CacheTexture texturecache = texturebump.get(tex); |
---|
| 8625 | + |
---|
| 8626 | + if (texturecache != null) |
---|
| 8627 | + { |
---|
| 8628 | + tex.bw = texturecache.texturedata.getWidth(); |
---|
| 8629 | + tex.bh = texturecache.texturedata.getHeight(); |
---|
| 8630 | + tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f); |
---|
| 8631 | + } |
---|
| 8632 | + } |
---|
| 8633 | + } |
---|
| 8634 | + |
---|
| 8635 | + com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8468 | 8636 | { |
---|
8469 | 8637 | CacheTexture texture = GetCacheTexture(tex, bump, resolution); |
---|
8470 | 8638 | |
---|
.. | .. |
---|
8482 | 8650 | return texture!=null?texture.texture:null; |
---|
8483 | 8651 | } |
---|
8484 | 8652 | |
---|
8485 | | - public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution) throws Exception |
---|
| 8653 | + public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8486 | 8654 | { |
---|
8487 | 8655 | CacheTexture texture = GetCacheTexture(tex, bump, resolution); |
---|
8488 | 8656 | |
---|
8489 | 8657 | return texture!=null?texture.texturedata:null; |
---|
8490 | 8658 | } |
---|
8491 | 8659 | |
---|
8492 | | - boolean BindTexture(String tex, boolean bump, int resolution) throws Exception |
---|
| 8660 | + boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8493 | 8661 | { |
---|
8494 | 8662 | if (/*tex == null ||*/ ambientOcclusion ) // || !textureon) |
---|
8495 | 8663 | { |
---|
8496 | 8664 | return false; |
---|
8497 | 8665 | } |
---|
8498 | 8666 | |
---|
8499 | | - boolean newtex = false; |
---|
| 8667 | + //boolean newtex = false; |
---|
8500 | 8668 | |
---|
8501 | 8669 | com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution); |
---|
8502 | 8670 | |
---|
.. | .. |
---|
8528 | 8696 | texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT); |
---|
8529 | 8697 | texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT); |
---|
8530 | 8698 | |
---|
8531 | | - return newtex; |
---|
| 8699 | + return true; // Warning: not used. |
---|
8532 | 8700 | } |
---|
8533 | 8701 | |
---|
| 8702 | + public static byte[] CompressJPEG(BufferedImage image, float quality) |
---|
| 8703 | + { |
---|
| 8704 | + try |
---|
| 8705 | + { |
---|
| 8706 | + ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
---|
| 8707 | + Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg"); |
---|
| 8708 | + ImageWriter writer = writers.next(); |
---|
| 8709 | + |
---|
| 8710 | + ImageWriteParam param = writer.getDefaultWriteParam(); |
---|
| 8711 | + param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); |
---|
| 8712 | + param.setCompressionQuality(quality); |
---|
| 8713 | + |
---|
| 8714 | + ImageOutputStream ios = ImageIO.createImageOutputStream(baos); |
---|
| 8715 | + writer.setOutput(ios); |
---|
| 8716 | + writer.write(null, new IIOImage(image, null, null), param); |
---|
| 8717 | + |
---|
| 8718 | + byte[] data = baos.toByteArray(); |
---|
| 8719 | + writer.dispose(); |
---|
| 8720 | + return data; |
---|
| 8721 | + } |
---|
| 8722 | + catch (Exception e) |
---|
| 8723 | + { |
---|
| 8724 | + e.printStackTrace(); |
---|
| 8725 | + return null; |
---|
| 8726 | + } |
---|
| 8727 | + } |
---|
| 8728 | + |
---|
| 8729 | + public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException |
---|
| 8730 | + { |
---|
| 8731 | + ByteArrayInputStream baos = new ByteArrayInputStream(image); |
---|
| 8732 | + Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg"); |
---|
| 8733 | + ImageReader reader = writers.next(); |
---|
| 8734 | + |
---|
| 8735 | + BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); |
---|
| 8736 | + |
---|
| 8737 | + ImageReadParam param = reader.getDefaultReadParam(); |
---|
| 8738 | + param.setDestination(bim); |
---|
| 8739 | + //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB)); |
---|
| 8740 | + |
---|
| 8741 | + ImageInputStream ios = ImageIO.createImageInputStream(baos); |
---|
| 8742 | + reader.setInput(ios); |
---|
| 8743 | + BufferedImage bim2 = reader.read(0, param); |
---|
| 8744 | + reader.dispose(); |
---|
| 8745 | + |
---|
| 8746 | +// WritableRaster raster = bim2.getRaster(); |
---|
| 8747 | +// DataBufferByte data = (DataBufferByte) raster.getDataBuffer(); |
---|
| 8748 | +// byte[] bytes = data.getData(); |
---|
| 8749 | +// |
---|
| 8750 | +// int[] pixels = new int[bytes.length/3]; |
---|
| 8751 | +// for (int i=pixels.length; --i>=0;) |
---|
| 8752 | +// { |
---|
| 8753 | +// int i3 = i*3; |
---|
| 8754 | +// pixels[i] = 0xFF; |
---|
| 8755 | +// pixels[i] <<= 8; |
---|
| 8756 | +// pixels[i] |= bytes[i3+2] & 0xFF; |
---|
| 8757 | +// pixels[i] <<= 8; |
---|
| 8758 | +// pixels[i] |= bytes[i3+1] & 0xFF; |
---|
| 8759 | +// pixels[i] <<= 8; |
---|
| 8760 | +// pixels[i] |= bytes[i3] & 0xFF; |
---|
| 8761 | +// } |
---|
| 8762 | +// |
---|
| 8763 | +// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w); |
---|
| 8764 | + |
---|
| 8765 | + return bim; |
---|
| 8766 | + } |
---|
| 8767 | + |
---|
8534 | 8768 | ShadowBuffer shadowPBuf; |
---|
8535 | 8769 | AntialiasBuffer antialiasPBuf; |
---|
8536 | 8770 | int MAXSTACK; |
---|
.. | .. |
---|
8547 | 8781 | |
---|
8548 | 8782 | gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0); |
---|
8549 | 8783 | MAXSTACK = temp[0]; |
---|
8550 | | - System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK); |
---|
| 8784 | + if (Globals.DEBUG) |
---|
| 8785 | + System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK); |
---|
8551 | 8786 | gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0); |
---|
8552 | 8787 | MAXSTACK = temp[0]; |
---|
8553 | | - System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK); |
---|
| 8788 | + if (Globals.DEBUG) |
---|
| 8789 | + System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK); |
---|
8554 | 8790 | |
---|
8555 | 8791 | // Use debug pipeline |
---|
8556 | 8792 | //drawable.setGL(new DebugGL(gl)); // |
---|
.. | .. |
---|
8558 | 8794 | gl = drawable.getGL(); // |
---|
8559 | 8795 | |
---|
8560 | 8796 | GL gl3 = getGL(); |
---|
8561 | | - System.out.println("INIT GL IS: " + gl.getClass().getName()); |
---|
| 8797 | + if (Globals.DEBUG) |
---|
| 8798 | + System.out.println("INIT GL IS: " + gl.getClass().getName()); |
---|
8562 | 8799 | |
---|
8563 | 8800 | |
---|
8564 | 8801 | //float pos[] = { 100, 100, 100, 0 }; |
---|
.. | .. |
---|
8723 | 8960 | |
---|
8724 | 8961 | if (cubemap == null) |
---|
8725 | 8962 | { |
---|
8726 | | - LoadEnvy(5); |
---|
| 8963 | + //LoadEnvy(1); |
---|
8727 | 8964 | } |
---|
8728 | 8965 | |
---|
8729 | 8966 | //cubemap.enable(); |
---|
.. | .. |
---|
8999 | 9236 | |
---|
9000 | 9237 | void LoadEnvy(int which) |
---|
9001 | 9238 | { |
---|
| 9239 | + assert(false); |
---|
| 9240 | + |
---|
9002 | 9241 | String name; |
---|
9003 | 9242 | String ext; |
---|
9004 | 9243 | |
---|
.. | .. |
---|
9010 | 9249 | cubemap = null; |
---|
9011 | 9250 | return; |
---|
9012 | 9251 | case 1: |
---|
9013 | | - name = "cubemaps/box_"; |
---|
9014 | | - ext = "png"; |
---|
| 9252 | + name = "cubemaps/rgb/"; |
---|
| 9253 | + ext = "jpg"; |
---|
9015 | 9254 | reverseUP = false; |
---|
9016 | 9255 | break; |
---|
9017 | 9256 | case 2: |
---|
9018 | | - name = "cubemaps/uffizi_"; |
---|
9019 | | - ext = "png"; |
---|
9020 | | - break; // reverseUP = true; break; |
---|
| 9257 | + name = "cubemaps/uffizi/"; |
---|
| 9258 | + ext = "jpg"; |
---|
| 9259 | + reverseUP = false; |
---|
| 9260 | + break; |
---|
9021 | 9261 | case 3: |
---|
9022 | | - name = "cubemaps/CloudyHills_"; |
---|
9023 | | - ext = "tga"; |
---|
| 9262 | + name = "cubemaps/CloudyHills/"; |
---|
| 9263 | + ext = "jpg"; |
---|
9024 | 9264 | reverseUP = false; |
---|
9025 | 9265 | break; |
---|
9026 | 9266 | case 4: |
---|
9027 | | - name = "cubemaps/cornell_"; |
---|
| 9267 | + name = "cubemaps/cornell/"; |
---|
9028 | 9268 | ext = "png"; |
---|
9029 | 9269 | reverseUP = false; |
---|
9030 | 9270 | break; |
---|
| 9271 | + case 5: |
---|
| 9272 | + name = "cubemaps/skycube/"; |
---|
| 9273 | + ext = "jpg"; |
---|
| 9274 | + reverseUP = false; |
---|
| 9275 | + break; |
---|
| 9276 | + case 6: |
---|
| 9277 | + name = "cubemaps/SaintLazarusChurch3/"; |
---|
| 9278 | + ext = "jpg"; |
---|
| 9279 | + reverseUP = false; |
---|
| 9280 | + break; |
---|
| 9281 | + case 7: |
---|
| 9282 | + name = "cubemaps/Sodermalmsallen/"; |
---|
| 9283 | + ext = "jpg"; |
---|
| 9284 | + reverseUP = false; |
---|
| 9285 | + break; |
---|
| 9286 | + case 8: |
---|
| 9287 | + name = "cubemaps/Sodermalmsallen2/"; |
---|
| 9288 | + ext = "jpg"; |
---|
| 9289 | + reverseUP = false; |
---|
| 9290 | + break; |
---|
| 9291 | + case 9: |
---|
| 9292 | + name = "cubemaps/UnionSquare/"; |
---|
| 9293 | + ext = "jpg"; |
---|
| 9294 | + reverseUP = false; |
---|
| 9295 | + break; |
---|
9031 | 9296 | default: |
---|
9032 | | - name = "cubemaps/rgb_"; |
---|
9033 | | - ext = "png"; /*mipmap = true;*/ reverseUP = false; |
---|
| 9297 | + name = "cubemaps/box/"; |
---|
| 9298 | + ext = "png"; /*mipmap = true;*/ |
---|
| 9299 | + reverseUP = false; |
---|
9034 | 9300 | break; |
---|
9035 | 9301 | } |
---|
9036 | | - |
---|
9037 | | - try |
---|
9038 | | - { |
---|
9039 | | - cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap); |
---|
9040 | | - } catch (IOException e) |
---|
9041 | | - { |
---|
9042 | | - throw new RuntimeException(e); |
---|
9043 | | - } |
---|
| 9302 | + |
---|
| 9303 | + LoadSkybox(name, ext, mipmap); |
---|
9044 | 9304 | } |
---|
9045 | 9305 | |
---|
9046 | 9306 | public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) |
---|
.. | .. |
---|
9072 | 9332 | static double[] model = new double[16]; |
---|
9073 | 9333 | double[] camera2light = new double[16]; |
---|
9074 | 9334 | double[] light2camera = new double[16]; |
---|
9075 | | - int newenvy = -1; |
---|
9076 | | - boolean envyoff = true; // false; |
---|
| 9335 | + |
---|
| 9336 | + //int newenvy = -1; |
---|
| 9337 | + //boolean envyoff = false; |
---|
| 9338 | + |
---|
| 9339 | + String loadedskyboxname; |
---|
| 9340 | + |
---|
9077 | 9341 | cVector light0 = new cVector(0, 0, 0); // 1,3,2); |
---|
9078 | 9342 | //float[] light0 = { 0,0,0 }; |
---|
9079 | 9343 | cVector dirlight = new cVector(0, 0, 1); // 1,3,2); |
---|
.. | .. |
---|
9366 | 9630 | jy8[3] = 0.5f; |
---|
9367 | 9631 | } |
---|
9368 | 9632 | |
---|
9369 | | - float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV |
---|
| 9633 | + float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV |
---|
9370 | 9634 | float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation |
---|
9371 | 9635 | float[] options3 = new float[]{1, 1, 1, 0}; // fog color |
---|
9372 | 9636 | float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen |
---|
9373 | 9637 | |
---|
| 9638 | + void ResetOptions() |
---|
| 9639 | + { |
---|
| 9640 | + options1[0] = 100; |
---|
| 9641 | + options1[1] = 0.025f; |
---|
| 9642 | + options1[2] = 0.01f; |
---|
| 9643 | + options1[3] = 0; |
---|
| 9644 | + options1[4] = 0; |
---|
| 9645 | + |
---|
| 9646 | + options2[0] = 0; |
---|
| 9647 | + options2[1] = 0.75f; |
---|
| 9648 | + options2[2] = 0; |
---|
| 9649 | + options2[3] = 0; |
---|
| 9650 | + |
---|
| 9651 | + options3[0] = 1; |
---|
| 9652 | + options3[1] = 1; |
---|
| 9653 | + options3[2] = 1; |
---|
| 9654 | + options3[3] = 0; |
---|
| 9655 | + |
---|
| 9656 | + options4[0] = 1; |
---|
| 9657 | + options4[1] = 0; |
---|
| 9658 | + options4[2] = 1; |
---|
| 9659 | + options4[3] = 0; |
---|
| 9660 | + } |
---|
| 9661 | + |
---|
9374 | 9662 | static int imagecount = 0; // movie generation |
---|
9375 | 9663 | |
---|
9376 | 9664 | static int jitter = 0; |
---|
.. | .. |
---|
9467 | 9755 | |
---|
9468 | 9756 | if (renderCamera != lightCamera) |
---|
9469 | 9757 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
9470 | | - LA.matConcat(matrix, parentcam.GlobalTransform(), matrix); |
---|
| 9758 | + LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix); |
---|
9471 | 9759 | |
---|
9472 | 9760 | // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix); |
---|
9473 | 9761 | |
---|
.. | .. |
---|
9483 | 9771 | |
---|
9484 | 9772 | if (renderCamera != lightCamera) |
---|
9485 | 9773 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
9486 | | - LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix); |
---|
| 9774 | + LA.matConcat(parentcam.GlobalTransform(), matrix, matrix); |
---|
9487 | 9775 | |
---|
9488 | 9776 | // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix); |
---|
9489 | 9777 | |
---|
.. | .. |
---|
9529 | 9817 | rati = 1 / rati; |
---|
9530 | 9818 | gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000); |
---|
9531 | 9819 | } |
---|
9532 | | - assert (newenvy == -1); |
---|
| 9820 | + |
---|
| 9821 | + //assert (newenvy == -1); |
---|
| 9822 | + |
---|
9533 | 9823 | gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
9534 | 9824 | gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB); |
---|
9535 | | - DrawSkyBox(gl); |
---|
| 9825 | + DrawSkyBox(gl, (float)rati); |
---|
9536 | 9826 | gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
9537 | 9827 | gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB); |
---|
9538 | 9828 | accPerspective(gl, renderCamera.shaper_fovy / ratio, |
---|
.. | .. |
---|
10481 | 10771 | ANTIALIAS = 0; |
---|
10482 | 10772 | //System.out.println("RESTART"); |
---|
10483 | 10773 | AAtimer.restart(); |
---|
| 10774 | + Globals.TIMERRUNNING = true; |
---|
10484 | 10775 | } |
---|
10485 | 10776 | } |
---|
10486 | 10777 | } |
---|
.. | .. |
---|
10568 | 10859 | |
---|
10569 | 10860 | if (wait) |
---|
10570 | 10861 | { |
---|
10571 | | - Sleep(500); |
---|
| 10862 | + Sleep(200); // blocks everything |
---|
10572 | 10863 | |
---|
10573 | 10864 | wait = false; |
---|
10574 | 10865 | } |
---|
.. | .. |
---|
10683 | 10974 | // if (parentcam != renderCamera) // not a light |
---|
10684 | 10975 | if (cam != lightCamera) |
---|
10685 | 10976 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
10686 | | - LA.matConcat(matrix, parentcam.GlobalTransform(), matrix); |
---|
| 10977 | + LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix); |
---|
10687 | 10978 | |
---|
10688 | 10979 | for (int j = 0; j < 4; j++) |
---|
10689 | 10980 | { |
---|
.. | .. |
---|
10698 | 10989 | // if (parentcam != renderCamera) // not a light |
---|
10699 | 10990 | if (cam != lightCamera) |
---|
10700 | 10991 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
10701 | | - LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix); |
---|
| 10992 | + LA.matConcat(parentcam.GlobalTransform(), matrix, matrix); |
---|
10702 | 10993 | |
---|
10703 | 10994 | //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix); |
---|
10704 | 10995 | |
---|
.. | .. |
---|
10784 | 11075 | gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000); |
---|
10785 | 11076 | } |
---|
10786 | 11077 | |
---|
10787 | | - if (newenvy > -1) |
---|
| 11078 | +// if (newenvy > -1) |
---|
| 11079 | +// { |
---|
| 11080 | +// LoadEnvy(newenvy); |
---|
| 11081 | +// } |
---|
| 11082 | +// |
---|
| 11083 | +// newenvy = -1; |
---|
| 11084 | + |
---|
| 11085 | + if (object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb")) |
---|
10788 | 11086 | { |
---|
10789 | | - LoadEnvy(newenvy); |
---|
| 11087 | + if (cubemaprgb == null) |
---|
| 11088 | + { |
---|
| 11089 | + cubemaprgb = LoadSkybox(object.skyboxname + "/", object.skyboxext, false); |
---|
| 11090 | + } |
---|
| 11091 | + |
---|
| 11092 | + cubemap = cubemaprgb; |
---|
10790 | 11093 | } |
---|
10791 | | - |
---|
10792 | | - newenvy = -1; |
---|
10793 | | - |
---|
| 11094 | + else |
---|
| 11095 | + { |
---|
| 11096 | + if (object.skyboxname != null) |
---|
| 11097 | + { |
---|
| 11098 | + if (!object.skyboxname.equals(this.loadedskyboxname)) |
---|
| 11099 | + { |
---|
| 11100 | + cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false); |
---|
| 11101 | + loadedskyboxname = object.skyboxname; |
---|
| 11102 | + } |
---|
| 11103 | + } |
---|
| 11104 | + else |
---|
| 11105 | + { |
---|
| 11106 | + cubemapcustom = null; |
---|
| 11107 | + loadedskyboxname = null; |
---|
| 11108 | + } |
---|
| 11109 | + |
---|
| 11110 | + cubemap = cubemapcustom; |
---|
| 11111 | + } |
---|
| 11112 | + |
---|
10794 | 11113 | ratio = ((double) getWidth()) / getHeight(); |
---|
10795 | 11114 | //System.out.println("ratio = " + ratio); |
---|
10796 | 11115 | |
---|
.. | .. |
---|
10806 | 11125 | |
---|
10807 | 11126 | if (!IsFrozen() && !ambientOcclusion) |
---|
10808 | 11127 | { |
---|
10809 | | - DrawSkyBox(gl); |
---|
| 11128 | + DrawSkyBox(gl, (float)ratio); |
---|
10810 | 11129 | } |
---|
10811 | 11130 | |
---|
10812 | 11131 | //if (selection_view == -1) |
---|
.. | .. |
---|
10989 | 11308 | |
---|
10990 | 11309 | gl.glMatrixMode(GL.GL_MODELVIEW); |
---|
10991 | 11310 | |
---|
10992 | | -//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST); |
---|
10993 | | -//gl.glEnable(gl.GL_POLYGON_SMOOTH); |
---|
10994 | | -//gl.glEnable(gl.GL_MULTISAMPLE); |
---|
| 11311 | +gl.glEnable(gl.GL_POLYGON_SMOOTH); |
---|
| 11312 | +gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST); |
---|
| 11313 | +gl.glEnable(gl.GL_MULTISAMPLE); |
---|
10995 | 11314 | } else |
---|
10996 | 11315 | { |
---|
10997 | 11316 | //gl.glDisable(GL.GL_TEXTURE_2D); |
---|
.. | .. |
---|
11002 | 11321 | //System.out.println("BLENDING ON"); |
---|
11003 | 11322 | gl.glEnable(GL.GL_BLEND); |
---|
11004 | 11323 | gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); |
---|
11005 | | - |
---|
| 11324 | +// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE); |
---|
11006 | 11325 | gl.glMatrixMode(gl.GL_PROJECTION); |
---|
11007 | 11326 | gl.glLoadIdentity(); |
---|
11008 | 11327 | |
---|
.. | .. |
---|
11092 | 11411 | |
---|
11093 | 11412 | // if (cam != lightCamera) |
---|
11094 | 11413 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
11095 | | - LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013 |
---|
| 11414 | + LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013 |
---|
11096 | 11415 | } |
---|
11097 | 11416 | |
---|
11098 | 11417 | LA.xformDir(lightposition, cam.toScreen, lightposition); |
---|
.. | .. |
---|
11251 | 11570 | } |
---|
11252 | 11571 | } |
---|
11253 | 11572 | |
---|
11254 | | - if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion) |
---|
| 11573 | + if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion) |
---|
11255 | 11574 | { |
---|
11256 | 11575 | //gl.glDepthFunc(GL.GL_LEQUAL); |
---|
11257 | 11576 | //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT); |
---|
.. | .. |
---|
11259 | 11578 | |
---|
11260 | 11579 | boolean texon = textureon; |
---|
11261 | 11580 | |
---|
11262 | | - if (RENDERPROGRAM > 0) |
---|
11263 | | - { |
---|
11264 | | - gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
11265 | | - textureon = false; |
---|
11266 | | - } |
---|
| 11581 | + gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
| 11582 | + textureon = false; |
---|
| 11583 | + |
---|
11267 | 11584 | //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB); |
---|
11268 | 11585 | //System.out.println("ALLO"); |
---|
11269 | 11586 | gl.glColorMask(false, false, false, false); |
---|
11270 | 11587 | DrawObject(gl); |
---|
11271 | | - if (RENDERPROGRAM > 0) |
---|
11272 | | - { |
---|
11273 | | - gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
11274 | | - textureon = texon; |
---|
11275 | | - } |
---|
| 11588 | + |
---|
| 11589 | + gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
| 11590 | + textureon = texon; |
---|
| 11591 | + |
---|
11276 | 11592 | gl.glColorMask(true, true, true, true); |
---|
11277 | 11593 | |
---|
11278 | 11594 | gl.glDepthFunc(GL.GL_EQUAL); |
---|
11279 | | - //gl.glDepthMask(false); |
---|
| 11595 | + gl.glDepthMask(false); |
---|
11280 | 11596 | } |
---|
11281 | 11597 | |
---|
11282 | 11598 | if (false) // DrawMode() == SHADOW) |
---|
.. | .. |
---|
11479 | 11795 | |
---|
11480 | 11796 | void DrawObject(GL gl, boolean draw) |
---|
11481 | 11797 | { |
---|
| 11798 | + // To clear camera values |
---|
| 11799 | + ResetOptions(); |
---|
| 11800 | + |
---|
11482 | 11801 | //System.out.println("DRAW OBJECT " + mouseDown); |
---|
11483 | 11802 | // DrawMode() = SELECTION; |
---|
11484 | 11803 | //GL gl = getGL(); |
---|
11485 | 11804 | if ((TRACK || SHADOWTRACK) || zoomonce) |
---|
11486 | 11805 | { |
---|
11487 | 11806 | if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode) |
---|
11488 | | - object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK); |
---|
| 11807 | + object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK); |
---|
11489 | 11808 | pingthread.StepToTarget(true); // true); |
---|
11490 | 11809 | // zoomonce = false; |
---|
11491 | 11810 | } |
---|
.. | .. |
---|
11613 | 11932 | ReleaseTextures(DEFAULT_TEXTURES); |
---|
11614 | 11933 | |
---|
11615 | 11934 | if (CLEANCACHE) |
---|
11616 | | - for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();) |
---|
| 11935 | + for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();) |
---|
11617 | 11936 | { |
---|
11618 | | - String tex = e.nextElement(); |
---|
| 11937 | + cTexture tex = e.nextElement(); |
---|
11619 | 11938 | |
---|
11620 | 11939 | // System.out.println("Texture --------- " + tex); |
---|
11621 | 11940 | |
---|
11622 | | - if (tex.equals("WHITE_NOISE")) |
---|
| 11941 | + if (tex.equals("WHITE_NOISE:")) |
---|
11623 | 11942 | continue; |
---|
11624 | 11943 | |
---|
11625 | | - if (!usedtextures.containsKey(tex)) |
---|
| 11944 | + if (!usedtextures.contains(tex)) |
---|
11626 | 11945 | { |
---|
| 11946 | + CacheTexture gettex = texturepigment.get(tex); |
---|
11627 | 11947 | // System.out.println("DISPOSE +++++++++++++++ " + tex); |
---|
11628 | | - textures.get(tex).texture.dispose(); |
---|
11629 | | - textures.remove(tex); |
---|
| 11948 | + if (gettex != null) |
---|
| 11949 | + { |
---|
| 11950 | + gettex.texture.dispose(); |
---|
| 11951 | + texturepigment.remove(tex); |
---|
| 11952 | + } |
---|
| 11953 | + |
---|
| 11954 | + gettex = texturebump.get(tex); |
---|
| 11955 | + // System.out.println("DISPOSE +++++++++++++++ " + tex); |
---|
| 11956 | + if (gettex != null) |
---|
| 11957 | + { |
---|
| 11958 | + gettex.texture.dispose(); |
---|
| 11959 | + texturebump.remove(tex); |
---|
| 11960 | + } |
---|
11630 | 11961 | } |
---|
11631 | 11962 | } |
---|
11632 | 11963 | } |
---|
.. | .. |
---|
12046 | 12377 | for (int i = tp.size(); --i >= 0;) |
---|
12047 | 12378 | { |
---|
12048 | 12379 | //for (int count = tp.get(i).GetTransformCount(); --count>=0;) |
---|
12049 | | - LA.xformPos(light, tp.get(i).GlobalTransform(), light); |
---|
| 12380 | + LA.xformPos(light, tp.get(i).GlobalTransformInv(), light); |
---|
12050 | 12381 | } |
---|
12051 | 12382 | |
---|
12052 | 12383 | |
---|
.. | .. |
---|
12154 | 12485 | |
---|
12155 | 12486 | //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0); |
---|
12156 | 12487 | |
---|
12157 | | - String program = |
---|
| 12488 | + String programmin = |
---|
| 12489 | + // Min shader |
---|
12158 | 12490 | "!!ARBfp1.0\n" + |
---|
| 12491 | + "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" + |
---|
| 12492 | + "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" + |
---|
| 12493 | + "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" + |
---|
| 12494 | + "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" + |
---|
| 12495 | + "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" + |
---|
| 12496 | + "PARAM light2cam0 = program.env[10];" + |
---|
| 12497 | + "PARAM light2cam1 = program.env[11];" + |
---|
| 12498 | + "PARAM light2cam2 = program.env[12];" + |
---|
| 12499 | + "TEMP temp;" + |
---|
| 12500 | + "TEMP light;" + |
---|
| 12501 | + "TEMP ndotl;" + |
---|
| 12502 | + "TEMP normal;" + |
---|
| 12503 | + "TEMP depth;" + |
---|
| 12504 | + "TEMP eye;" + |
---|
| 12505 | + "TEMP pos;" + |
---|
| 12506 | + |
---|
| 12507 | + "MAD normal, fragment.color, zero123.z, -zero123.y;" + |
---|
| 12508 | + Normalize("normal") + |
---|
| 12509 | + "MOV light, state.light[0].position;" + |
---|
| 12510 | + "DP3 ndotl.x, light, normal;" + |
---|
| 12511 | + |
---|
| 12512 | + // shadow |
---|
| 12513 | + "MOV pos, fragment.texcoord[1];" + |
---|
| 12514 | + "MOV temp, pos;" + |
---|
| 12515 | + ShadowTextureFetch("depth", "temp", "1") + |
---|
| 12516 | + //"TEX depth, fragment.texcoord[1], texture[1], 2D;" + |
---|
| 12517 | + "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" + |
---|
| 12518 | + |
---|
| 12519 | + // No shadow when out of frustum |
---|
| 12520 | + //"SGE temp.y, depth.z, zero123.y;" + |
---|
| 12521 | + //"LRP temp.x, temp.y, zero123.y, temp.x;" + |
---|
| 12522 | + |
---|
| 12523 | + "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow |
---|
| 12524 | + |
---|
| 12525 | + // Backlit |
---|
| 12526 | + "MOV pos.w, zero123.y;" + |
---|
| 12527 | + "DP4 eye.x, pos, light2cam0;" + |
---|
| 12528 | + "DP4 eye.y, pos, light2cam1;" + |
---|
| 12529 | + "DP4 eye.z, pos, light2cam2;" + |
---|
| 12530 | + Normalize("eye") + |
---|
| 12531 | + |
---|
| 12532 | + "DP3 ndotl.y, -eye, normal;" + |
---|
| 12533 | + //"MUL ndotl.y, ndotl.y, pow2.x;" + |
---|
| 12534 | + "POW ndotl.y, ndotl.y, pow2.z;" + // backlit |
---|
| 12535 | + "SUB ndotl.y, zero123.y, ndotl.y;" + |
---|
| 12536 | + //"SUB ndotl.y, zero123.y, ndotl.y;" + |
---|
| 12537 | + //"MUL ndotl.y, ndotl.y, pow2.z;" + |
---|
| 12538 | + |
---|
| 12539 | + //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient |
---|
| 12540 | + //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient |
---|
| 12541 | + |
---|
| 12542 | + // Pigment |
---|
| 12543 | + "TEX temp, fragment.texcoord[0], texture[0], 2D;" + |
---|
| 12544 | + "LRP temp, zero123.w, temp, one;" + // texture proportion |
---|
| 12545 | + "MUL temp, temp, ndotl.x;" + |
---|
| 12546 | + |
---|
| 12547 | + "MUL temp, temp, zero123.z;" + |
---|
| 12548 | + |
---|
| 12549 | + //"MUL temp, temp, ndotl.y;" + |
---|
| 12550 | + |
---|
| 12551 | + "MOV temp.w, zero123.y;" + // reset alpha |
---|
| 12552 | + "MOV result.color, temp;" + |
---|
| 12553 | + "END"; |
---|
| 12554 | + |
---|
| 12555 | + String programmax = |
---|
| 12556 | + "!!ARBfp1.0\n" + |
---|
| 12557 | + |
---|
12159 | 12558 | //"OPTION ARB_fragment_program_shadow;" + |
---|
12160 | 12559 | "PARAM light2cam0 = program.env[10];" + |
---|
12161 | 12560 | "PARAM light2cam1 = program.env[11];" + |
---|
.. | .. |
---|
12270 | 12669 | "TEMP shininess;" + |
---|
12271 | 12670 | "\n" + |
---|
12272 | 12671 | "MOV texSamp, one;" + |
---|
12273 | | - //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" + |
---|
12274 | | - |
---|
| 12672 | + |
---|
12275 | 12673 | "MOV mapgrid.x, one2048th.x;" + |
---|
12276 | 12674 | "MOV temp, fragment.texcoord[1];" + |
---|
12277 | 12675 | /* |
---|
.. | .. |
---|
12292 | 12690 | "MUL temp, floor, mapgrid.x;" + |
---|
12293 | 12691 | //"TEX depth0, temp, texture[1], 2D;" + |
---|
12294 | 12692 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12295 | | - TextureFetch("depth0", "temp", "1") + |
---|
| 12693 | + ShadowTextureFetch("depth0", "temp", "1") + |
---|
12296 | 12694 | "") + |
---|
12297 | 12695 | "ADD temp.x, temp.x, mapgrid.x;" + |
---|
12298 | 12696 | //"TEX depth1, temp, texture[1], 2D;" + |
---|
12299 | 12697 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12300 | | - TextureFetch("depth1", "temp", "1") + |
---|
| 12698 | + ShadowTextureFetch("depth1", "temp", "1") + |
---|
12301 | 12699 | "") + |
---|
12302 | 12700 | "ADD temp.y, temp.y, mapgrid.x;" + |
---|
12303 | 12701 | //"TEX depth2, temp, texture[1], 2D;" + |
---|
12304 | | - TextureFetch("depth2", "temp", "1") + |
---|
| 12702 | + ShadowTextureFetch("depth2", "temp", "1") + |
---|
12305 | 12703 | "SUB temp.x, temp.x, mapgrid.x;" + |
---|
12306 | 12704 | //"TEX depth3, temp, texture[1], 2D;" + |
---|
12307 | 12705 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12308 | | - TextureFetch("depth3", "temp", "1") + |
---|
| 12706 | + ShadowTextureFetch("depth3", "temp", "1") + |
---|
12309 | 12707 | "") + |
---|
12310 | 12708 | //"MUL texSamp0, texSamp0, state.material.front.diffuse;" + |
---|
12311 | 12709 | //"MOV params, material;" + |
---|
.. | .. |
---|
12676 | 13074 | "MAD shadow.x, buffer.x, frac.y, shadow.x;" + |
---|
12677 | 13075 | "") + |
---|
12678 | 13076 | |
---|
12679 | | - // display shadow only (bump == 0) |
---|
| 13077 | + // display shadow only (fakedepth == 0) |
---|
12680 | 13078 | "SUB temp.x, half.x, shadow.x;" + |
---|
12681 | 13079 | "MOV temp.y, -params5.z;" + // params6.x;" + |
---|
12682 | | - "SLT temp.z, temp.y, -one2048th.x;" + |
---|
| 13080 | + "SLT temp.z, temp.y, -c256i.x;" + |
---|
12683 | 13081 | "SUB temp.y, one.x, temp.z;" + |
---|
12684 | 13082 | "MUL temp.x, temp.x, temp.y;" + |
---|
12685 | 13083 | "KIL temp.x;" + |
---|
.. | .. |
---|
13010 | 13408 | //once = true; |
---|
13011 | 13409 | } |
---|
13012 | 13410 | |
---|
| 13411 | + String program = programmax; |
---|
| 13412 | + |
---|
| 13413 | + if (Globals.MINSHADER) |
---|
| 13414 | + { |
---|
| 13415 | + program = programmin; |
---|
| 13416 | + } |
---|
| 13417 | + |
---|
13013 | 13418 | System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length()); |
---|
13014 | 13419 | System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : "")); |
---|
13015 | 13420 | loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program); |
---|
.. | .. |
---|
13103 | 13508 | return out; |
---|
13104 | 13509 | } |
---|
13105 | 13510 | |
---|
13106 | | - String TextureFetch(String dest, String src, String unit) |
---|
| 13511 | + // Also does frustum culling |
---|
| 13512 | + String ShadowTextureFetch(String dest, String src, String unit) |
---|
13107 | 13513 | { |
---|
13108 | 13514 | return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" + |
---|
13109 | 13515 | "SGE " + src + ".w, " + src + ".x, eps.x;" + |
---|
13110 | 13516 | "SGE " + src + ".z, " + src + ".y, eps.x;" + |
---|
| 13517 | + "SLT " + dest + ".x, " + src + ".x, one.x;" + |
---|
| 13518 | + "SLT " + dest + ".y, " + src + ".y, one.x;" + |
---|
13111 | 13519 | "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;" + |
---|
| 13520 | + "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" + |
---|
| 13521 | + "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" + |
---|
13116 | 13522 | //"SWZ buffer, temp, w,w,w,w;"; |
---|
13117 | | - "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" + |
---|
| 13523 | + //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" + |
---|
13118 | 13524 | "SUB " + src + ".z, " + "one.x, " + src + ".w;" + |
---|
13119 | 13525 | //"MUL " + src + ".z, " + src + ".z, infinity.x;" + |
---|
13120 | 13526 | //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;"; |
---|
13121 | | - "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
| 13527 | + //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
13122 | 13528 | |
---|
13123 | | - //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;"; |
---|
13124 | | - //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;"; |
---|
| 13529 | + //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;"; |
---|
| 13530 | + "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
13125 | 13531 | } |
---|
13126 | 13532 | |
---|
13127 | 13533 | String Shadow(String depth, String shadow) |
---|
.. | .. |
---|
13168 | 13574 | "SLT temp.x, temp.x, zero.x;" + // shadoweps |
---|
13169 | 13575 | "LRP " + shadow + ", temp.x, one, " + shadow + ";" + |
---|
13170 | 13576 | |
---|
13171 | | - // No shadow when out of frustrum |
---|
| 13577 | + // No shadow when out of frustum |
---|
13172 | 13578 | "SGE temp.x, " + depth + ".z, one.z;" + |
---|
13173 | 13579 | "LRP " + shadow + ", temp.x, one, " + shadow + ";" + |
---|
13174 | 13580 | ""; |
---|
.. | .. |
---|
13333 | 13739 | "DP3 " + dest + ".z," + "normals," + "eye;" + |
---|
13334 | 13740 | "MAX " + dest + ".w," + dest + ".z," + "eps.x;" + |
---|
13335 | 13741 | //"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;" + |
---|
| 13742 | +// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET |
---|
| 13743 | +// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" + |
---|
| 13744 | + |
---|
| 13745 | + "MOV " + dest + ".z," + "params2.w;" + // EXACT |
---|
13339 | 13746 | "POW " + dest + ".w," + dest + ".w," + dest + ".z;" + |
---|
13340 | 13747 | "RCP " + dest + ".w," + dest + ".w;" + |
---|
13341 | 13748 | //"RSQ " + dest + ".w," + dest + ".w;" + |
---|
.. | .. |
---|
13840 | 14247 | else |
---|
13841 | 14248 | if (evt.getSource() == AAtimer) |
---|
13842 | 14249 | { |
---|
| 14250 | + Globals.TIMERRUNNING = false; |
---|
13843 | 14251 | if (mouseDown) |
---|
13844 | 14252 | { |
---|
13845 | 14253 | //new Exception().printStackTrace(); |
---|
.. | .. |
---|
13899 | 14307 | |
---|
13900 | 14308 | // fev 2014??? |
---|
13901 | 14309 | if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode) |
---|
13902 | | - object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK); |
---|
| 14310 | + object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK); |
---|
13903 | 14311 | pingthread.StepToTarget(true); // true); |
---|
13904 | 14312 | } |
---|
13905 | 14313 | // if (!LIVE) |
---|
.. | .. |
---|
13914 | 14322 | return; |
---|
13915 | 14323 | |
---|
13916 | 14324 | AAtimer.restart(); // |
---|
| 14325 | + Globals.TIMERRUNNING = true; |
---|
13917 | 14326 | |
---|
13918 | 14327 | // waslive = LIVE; |
---|
13919 | 14328 | // LIVE = false; |
---|
.. | .. |
---|
13963 | 14372 | drag = false; |
---|
13964 | 14373 | //System.out.println("Mouse DOWN"); |
---|
13965 | 14374 | 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); |
---|
| 14375 | + //ClickInfo info = new ClickInfo(); |
---|
| 14376 | + object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
| 14377 | + object.clickInfo.pane = this; |
---|
| 14378 | + object.clickInfo.camera = renderCamera; |
---|
| 14379 | + object.clickInfo.x = x; |
---|
| 14380 | + object.clickInfo.y = y; |
---|
| 14381 | + object.clickInfo.modifiers = modifiersex; |
---|
| 14382 | + editObj = object.doEditClick(//info, |
---|
| 14383 | + 0); |
---|
13974 | 14384 | if (!editObj) |
---|
13975 | 14385 | { |
---|
13976 | 14386 | hasMarquee = true; |
---|
.. | .. |
---|
14252 | 14662 | void GoDown(int mod) |
---|
14253 | 14663 | { |
---|
14254 | 14664 | MODIFIERS |= COMMAND; |
---|
14255 | | - /* |
---|
| 14665 | + /**/ |
---|
14256 | 14666 | if((mod&SHIFT) == SHIFT) |
---|
14257 | | - manipCamera.RotatePosition(0, -speed); |
---|
| 14667 | + manipCamera.BackForth(0, -speed*delta, 0); // getWidth()); |
---|
14258 | 14668 | else |
---|
14259 | | - manipCamera.BackForth(0, -speed*delta, getWidth()); |
---|
14260 | | - */ |
---|
| 14669 | + manipCamera.RotatePosition(0, -speed); |
---|
| 14670 | + /**/ |
---|
14261 | 14671 | if ((mod & SHIFT) == SHIFT) |
---|
14262 | 14672 | { |
---|
14263 | 14673 | mouseMode = mouseMode; // VR?? |
---|
.. | .. |
---|
14273 | 14683 | void GoUp(int mod) |
---|
14274 | 14684 | { |
---|
14275 | 14685 | MODIFIERS |= COMMAND; |
---|
14276 | | - /* |
---|
| 14686 | + /**/ |
---|
14277 | 14687 | if((mod&SHIFT) == SHIFT) |
---|
14278 | | - manipCamera.RotatePosition(0, speed); |
---|
| 14688 | + manipCamera.BackForth(0, speed*delta, 0); // getWidth()); |
---|
14279 | 14689 | else |
---|
14280 | | - manipCamera.BackForth(0, speed*delta, getWidth()); |
---|
14281 | | - */ |
---|
| 14690 | + manipCamera.RotatePosition(0, speed); |
---|
| 14691 | + /**/ |
---|
14282 | 14692 | if ((mod & SHIFT) == SHIFT) |
---|
14283 | 14693 | { |
---|
14284 | 14694 | mouseMode = mouseMode; |
---|
.. | .. |
---|
14294 | 14704 | void GoLeft(int mod) |
---|
14295 | 14705 | { |
---|
14296 | 14706 | MODIFIERS |= COMMAND; |
---|
14297 | | - /* |
---|
| 14707 | + /**/ |
---|
14298 | 14708 | if((mod&SHIFT) == SHIFT) |
---|
14299 | | - manipCamera.RotatePosition(speed, 0); |
---|
14300 | | - else |
---|
14301 | 14709 | manipCamera.Translate(speed*delta, 0, getWidth()); |
---|
14302 | | - */ |
---|
| 14710 | + else |
---|
| 14711 | + manipCamera.RotatePosition(speed, 0); |
---|
| 14712 | + /**/ |
---|
14303 | 14713 | if ((mod & SHIFT) == SHIFT) |
---|
14304 | 14714 | { |
---|
14305 | 14715 | mouseMode = mouseMode; |
---|
.. | .. |
---|
14315 | 14725 | void GoRight(int mod) |
---|
14316 | 14726 | { |
---|
14317 | 14727 | MODIFIERS |= COMMAND; |
---|
14318 | | - /* |
---|
| 14728 | + /**/ |
---|
14319 | 14729 | if((mod&SHIFT) == SHIFT) |
---|
14320 | | - manipCamera.RotatePosition(-speed, 0); |
---|
14321 | | - else |
---|
14322 | 14730 | manipCamera.Translate(-speed*delta, 0, getWidth()); |
---|
14323 | | - */ |
---|
| 14731 | + else |
---|
| 14732 | + manipCamera.RotatePosition(-speed, 0); |
---|
| 14733 | + /**/ |
---|
14324 | 14734 | if ((mod & SHIFT) == SHIFT) |
---|
14325 | 14735 | { |
---|
14326 | 14736 | mouseMode = mouseMode; |
---|
.. | .. |
---|
14370 | 14780 | if (editObj) |
---|
14371 | 14781 | { |
---|
14372 | 14782 | drag = true; |
---|
14373 | | - ClickInfo info = new ClickInfo(); |
---|
14374 | | - info.bounds.setBounds(0, 0, |
---|
| 14783 | + //ClickInfo info = new ClickInfo(); |
---|
| 14784 | + object.clickInfo.bounds.setBounds(0, 0, |
---|
14375 | 14785 | (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.manipWindow.copy |
---|
14381 | | - .doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0); |
---|
| 14786 | + object.clickInfo.pane = this; |
---|
| 14787 | + object.clickInfo.camera = renderCamera; |
---|
| 14788 | + object.clickInfo.x = x; |
---|
| 14789 | + object.clickInfo.y = y; |
---|
| 14790 | + object //.GetWindow().copy |
---|
| 14791 | + .doEditDrag(//info, |
---|
| 14792 | + (modifiers & MouseEvent.BUTTON3_MASK) != 0); |
---|
14382 | 14793 | } else |
---|
14383 | 14794 | { |
---|
14384 | 14795 | if (x < startX) |
---|
.. | .. |
---|
14527 | 14938 | } |
---|
14528 | 14939 | } |
---|
14529 | 14940 | |
---|
| 14941 | +// ClickInfo clickInfo = new ClickInfo(); |
---|
| 14942 | + |
---|
14530 | 14943 | public void mouseMoved(MouseEvent e) |
---|
14531 | 14944 | { |
---|
14532 | 14945 | //System.out.println("mouseMoved: " + e); |
---|
14533 | 14946 | if (isRenderer) |
---|
14534 | 14947 | return; |
---|
14535 | 14948 | |
---|
14536 | | - ClickInfo ci = new ClickInfo(); |
---|
14537 | | - ci.x = e.getX(); |
---|
14538 | | - ci.y = e.getY(); |
---|
14539 | | - ci.modifiers = e.getModifiersEx(); |
---|
14540 | | - ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
14541 | | - ci.pane = this; |
---|
14542 | | - ci.camera = renderCamera; |
---|
| 14949 | + // Mouse cursor feedback |
---|
| 14950 | + object.clickInfo.x = e.getX(); |
---|
| 14951 | + object.clickInfo.y = e.getY(); |
---|
| 14952 | + object.clickInfo.modifiers = e.getModifiersEx(); |
---|
| 14953 | + object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
| 14954 | + object.clickInfo.pane = this; |
---|
| 14955 | + object.clickInfo.camera = renderCamera; |
---|
14543 | 14956 | if (!isRenderer) |
---|
14544 | 14957 | { |
---|
14545 | 14958 | //ObjEditor editWindow = object.editWindow; |
---|
14546 | 14959 | //Object3D copy = editWindow.copy; |
---|
14547 | | - if (object.doEditClick(ci, 0)) |
---|
| 14960 | + if (object.doEditClick(//clickInfo, |
---|
| 14961 | + 0)) |
---|
14548 | 14962 | { |
---|
14549 | 14963 | setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
---|
14550 | 14964 | } else |
---|
.. | .. |
---|
14559 | 14973 | Globals.MOUSEDRAGGED = false; |
---|
14560 | 14974 | |
---|
14561 | 14975 | movingcamera = false; |
---|
14562 | | - X = Y = 0; |
---|
| 14976 | + X = 0; // getBounds().width/2; |
---|
| 14977 | + Y = 0; // getBounds().height/2; |
---|
14563 | 14978 | //System.out.println("mouseReleased: " + e); |
---|
14564 | 14979 | clickEnd(e.getX(), e.getY(), e.getModifiersEx()); |
---|
14565 | 14980 | } |
---|
.. | .. |
---|
14815 | 15230 | // break; |
---|
14816 | 15231 | case 'T': |
---|
14817 | 15232 | CACHETEXTURE ^= true; |
---|
14818 | | - textures.clear(); |
---|
| 15233 | + texturepigment.clear(); |
---|
| 15234 | + texturebump.clear(); |
---|
14819 | 15235 | // repaint(); |
---|
14820 | 15236 | break; |
---|
14821 | 15237 | case 'Y': |
---|
.. | .. |
---|
14900 | 15316 | case 'E' : COMPACT ^= true; |
---|
14901 | 15317 | repaint(); |
---|
14902 | 15318 | break; |
---|
14903 | | - case 'W' : DEBUGHSB ^= true; |
---|
| 15319 | + case 'W' : // Wide Window (fullscreen) |
---|
| 15320 | + //DEBUGHSB ^= true; |
---|
| 15321 | + ObjEditor.theFrame.ToggleFullScreen(); |
---|
14904 | 15322 | repaint(); |
---|
14905 | 15323 | break; |
---|
14906 | 15324 | case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break; |
---|
.. | .. |
---|
14926 | 15344 | repaint(); |
---|
14927 | 15345 | break; |
---|
14928 | 15346 | case 'l': |
---|
14929 | | - lightMode ^= true; |
---|
14930 | | - Globals.lighttouched = true; |
---|
14931 | | - manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera; |
---|
14932 | | - targetLookAt.set(manipCamera.lookAt); |
---|
14933 | | - repaint(); |
---|
14934 | | - break; |
---|
14935 | | - case 'L': |
---|
| 15347 | + //case 'L': |
---|
14936 | 15348 | if (lightMode) |
---|
14937 | 15349 | { |
---|
14938 | 15350 | lightMode = false; |
---|
.. | .. |
---|
14996 | 15408 | OCCLUSION_CULLING ^= true; |
---|
14997 | 15409 | System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING); |
---|
14998 | 15410 | break; |
---|
14999 | | - case '0': envyoff ^= true; repaint(); break; |
---|
| 15411 | + //case '0': envyoff ^= true; repaint(); break; |
---|
15000 | 15412 | case '1': |
---|
15001 | 15413 | case '2': |
---|
15002 | 15414 | case '3': |
---|
15003 | 15415 | case '4': |
---|
15004 | 15416 | case '5': |
---|
15005 | | - newenvy = Character.getNumericValue(key); |
---|
15006 | | - repaint(); |
---|
15007 | | - break; |
---|
15008 | 15417 | case '6': |
---|
15009 | 15418 | case '7': |
---|
15010 | 15419 | case '8': |
---|
15011 | 15420 | case '9': |
---|
15012 | | - BGcolor = (key - '6')/3.f; |
---|
| 15421 | + if (true) // envyoff) |
---|
| 15422 | + { |
---|
| 15423 | + BGcolor = (key - '1')/8.f; |
---|
| 15424 | + } |
---|
| 15425 | + else |
---|
| 15426 | + { |
---|
| 15427 | + //newenvy = Character.getNumericValue(key); |
---|
| 15428 | + } |
---|
15013 | 15429 | repaint(); |
---|
15014 | 15430 | break; |
---|
15015 | 15431 | case '!': |
---|
.. | .. |
---|
15075 | 15491 | case '_': |
---|
15076 | 15492 | kompactbit = 5; |
---|
15077 | 15493 | break; |
---|
15078 | | - case '+': |
---|
15079 | | - kompactbit = 6; |
---|
15080 | | - break; |
---|
| 15494 | +// case '+': |
---|
| 15495 | +// kompactbit = 6; |
---|
| 15496 | +// break; |
---|
15081 | 15497 | case ' ': |
---|
15082 | | - ObjEditor.theFrame.ToggleFullScreen(); |
---|
| 15498 | + lightMode ^= true; |
---|
| 15499 | + Globals.lighttouched = true; |
---|
| 15500 | + manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera; |
---|
| 15501 | + targetLookAt.set(manipCamera.lookAt); |
---|
15083 | 15502 | repaint(); |
---|
15084 | 15503 | break; |
---|
15085 | 15504 | //case '`' : |
---|
.. | .. |
---|
15126 | 15545 | case DELETE: |
---|
15127 | 15546 | ClearSelection(); |
---|
15128 | 15547 | break; |
---|
15129 | | - /* |
---|
15130 | 15548 | case '+': |
---|
| 15549 | + |
---|
| 15550 | + /* |
---|
15131 | 15551 | //fontsize += 1; |
---|
15132 | 15552 | bbzoom *= 2; |
---|
15133 | 15553 | repaint(); |
---|
.. | .. |
---|
15144 | 15564 | case '=': |
---|
15145 | 15565 | IncDepth(); |
---|
15146 | 15566 | //fontsize += 1; |
---|
15147 | | - object.editWindow.refreshContents(true); |
---|
| 15567 | + object.GetWindow().refreshContents(true); |
---|
15148 | 15568 | maskbit = 6; |
---|
15149 | 15569 | break; |
---|
15150 | 15570 | case '-': //if (PixelThreshold>1) PixelThreshold /= 2; |
---|
15151 | 15571 | DecDepth(); |
---|
15152 | 15572 | maskbit = 5; |
---|
15153 | 15573 | //if(fontsize > 1) fontsize -= 1; |
---|
15154 | | - if (object.editWindow == null) |
---|
15155 | | - new Exception().printStackTrace(); |
---|
15156 | | - else |
---|
15157 | | - object.editWindow.refreshContents(true); |
---|
| 15574 | +// if (object.editWindow == null) |
---|
| 15575 | +// new Exception().printStackTrace(); |
---|
| 15576 | +// else |
---|
| 15577 | + object.GetWindow().refreshContents(true); |
---|
15158 | 15578 | break; |
---|
15159 | 15579 | case '{': |
---|
15160 | 15580 | manipCamera.shaper_fovy /= 1.1; |
---|
.. | .. |
---|
15378 | 15798 | } |
---|
15379 | 15799 | */ |
---|
15380 | 15800 | |
---|
15381 | | - object.editWindow.EditSelection(); |
---|
| 15801 | + object.GetWindow().EditSelection(false); |
---|
15382 | 15802 | } |
---|
15383 | 15803 | |
---|
15384 | 15804 | void SelectParent() |
---|
.. | .. |
---|
15395 | 15815 | { |
---|
15396 | 15816 | //selectees.remove(i); |
---|
15397 | 15817 | System.out.println("select parent of " + elem); |
---|
15398 | | - group.editWindow.Select(elem.parent.GetTreePath(), first, true); |
---|
| 15818 | + group.GetWindow().Select(elem.parent.GetTreePath(), first, true); |
---|
15399 | 15819 | } else |
---|
15400 | 15820 | { |
---|
15401 | | - group.editWindow.Select(elem.GetTreePath(), first, true); |
---|
| 15821 | + group.GetWindow().Select(elem.GetTreePath(), first, true); |
---|
15402 | 15822 | } |
---|
15403 | 15823 | |
---|
15404 | 15824 | first = false; |
---|
.. | .. |
---|
15440 | 15860 | for (int j = 0; j < group.children.size(); j++) |
---|
15441 | 15861 | { |
---|
15442 | 15862 | elem = (Object3D) group.children.elementAt(j); |
---|
15443 | | - object.editWindow.Select(elem.GetTreePath(), first, true); |
---|
| 15863 | + object.GetWindow().Select(elem.GetTreePath(), first, true); |
---|
15444 | 15864 | first = false; |
---|
15445 | 15865 | } |
---|
15446 | 15866 | } else |
---|
15447 | 15867 | { |
---|
15448 | | - object.editWindow.Select(elem.GetTreePath(), first, true); |
---|
| 15868 | + object.GetWindow().Select(elem.GetTreePath(), first, true); |
---|
15449 | 15869 | } |
---|
15450 | 15870 | |
---|
15451 | 15871 | first = false; |
---|
.. | .. |
---|
15456 | 15876 | { |
---|
15457 | 15877 | //Composite group = (Composite) object; |
---|
15458 | 15878 | Object3D group = object; |
---|
15459 | | - group.editWindow.loadClipboard(true); // ClearSelection(false); |
---|
| 15879 | + group.GetWindow().loadClipboard(true); // ClearSelection(false); |
---|
15460 | 15880 | } |
---|
15461 | 15881 | |
---|
15462 | 15882 | void ResetTransform(int mask) |
---|
15463 | 15883 | { |
---|
15464 | 15884 | //Composite group = (Composite) object; |
---|
15465 | 15885 | Object3D group = object; |
---|
15466 | | - group.editWindow.ResetTransform(mask); |
---|
| 15886 | + group.GetWindow().ResetTransform(mask); |
---|
15467 | 15887 | } |
---|
15468 | 15888 | |
---|
15469 | 15889 | void FlipTransform() |
---|
15470 | 15890 | { |
---|
15471 | 15891 | //Composite group = (Composite) object; |
---|
15472 | 15892 | Object3D group = object; |
---|
15473 | | - group.editWindow.FlipTransform(); |
---|
| 15893 | + group.GetWindow().FlipTransform(); |
---|
15474 | 15894 | // group.editWindow.ReduceMesh(true); |
---|
15475 | 15895 | } |
---|
15476 | 15896 | |
---|
.. | .. |
---|
15478 | 15898 | { |
---|
15479 | 15899 | //Composite group = (Composite) object; |
---|
15480 | 15900 | Object3D group = object; |
---|
15481 | | - group.editWindow.PrintMemory(); |
---|
| 15901 | + group.GetWindow().PrintMemory(); |
---|
15482 | 15902 | // group.editWindow.ReduceMesh(true); |
---|
15483 | 15903 | } |
---|
15484 | 15904 | |
---|
.. | .. |
---|
15486 | 15906 | { |
---|
15487 | 15907 | //Composite group = (Composite) object; |
---|
15488 | 15908 | Object3D group = object; |
---|
15489 | | - group.editWindow.ResetCentroid(); |
---|
| 15909 | + group.GetWindow().ResetCentroid(); |
---|
15490 | 15910 | } |
---|
15491 | 15911 | |
---|
15492 | 15912 | void IncDepth() |
---|
.. | .. |
---|
15568 | 15988 | |
---|
15569 | 15989 | int width = getBounds().width; |
---|
15570 | 15990 | int height = getBounds().height; |
---|
15571 | | - ClickInfo info = new ClickInfo(); |
---|
15572 | | - info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom)); |
---|
15573 | 15991 | //Image img = CreateImage(width, height); |
---|
15574 | 15992 | //System.out.println("width = " + width + "; height = " + height + "\n"); |
---|
15575 | 15993 | |
---|
.. | .. |
---|
15646 | 16064 | } |
---|
15647 | 16065 | if (object != null && !hasMarquee) |
---|
15648 | 16066 | { |
---|
| 16067 | + if (object.clickInfo == null) |
---|
| 16068 | + object.clickInfo = new ClickInfo(); |
---|
| 16069 | + ClickInfo info = object.clickInfo; |
---|
| 16070 | + //ClickInfo info = new ClickInfo(); |
---|
| 16071 | + info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom)); |
---|
| 16072 | + |
---|
15649 | 16073 | if (isRenderer) |
---|
15650 | 16074 | { |
---|
15651 | | - info.flags++; |
---|
| 16075 | + object.clickInfo.flags++; |
---|
15652 | 16076 | double frameAspect = (double) width / (double) height; |
---|
15653 | 16077 | if (frameAspect > renderCamera.aspect) |
---|
15654 | 16078 | { |
---|
15655 | 16079 | int desired = (int) ((double) height * renderCamera.aspect); |
---|
15656 | | - info.bounds.width -= width - desired; |
---|
15657 | | - info.bounds.x += (width - desired) / 2; |
---|
| 16080 | + object.clickInfo.bounds.width -= width - desired; |
---|
| 16081 | + object.clickInfo.bounds.x += (width - desired) / 2; |
---|
15658 | 16082 | } else |
---|
15659 | 16083 | { |
---|
15660 | 16084 | int desired = (int) ((double) width / renderCamera.aspect); |
---|
15661 | | - info.bounds.height -= height - desired; |
---|
15662 | | - info.bounds.y += (height - desired) / 2; |
---|
| 16085 | + object.clickInfo.bounds.height -= height - desired; |
---|
| 16086 | + object.clickInfo.bounds.y += (height - desired) / 2; |
---|
15663 | 16087 | } |
---|
15664 | 16088 | } |
---|
15665 | | - info.g = gr; |
---|
15666 | | - info.camera = renderCamera; |
---|
| 16089 | + |
---|
| 16090 | + object.clickInfo.g = gr; |
---|
| 16091 | + object.clickInfo.camera = renderCamera; |
---|
15667 | 16092 | /* |
---|
15668 | 16093 | // Memory intensive (brep.verticescopy) |
---|
15669 | 16094 | if (!(object instanceof Composite)) |
---|
15670 | 16095 | object.draw(info, 0, false); // SLOW : |
---|
15671 | 16096 | */ |
---|
15672 | | - if (!isRenderer) |
---|
| 16097 | + if (!isRenderer) // && drag) |
---|
15673 | 16098 | { |
---|
15674 | | - object.drawEditHandles(info, 0); |
---|
15675 | | - |
---|
15676 | | - if (drag && (X != 0 || Y != 0) && object.selection.Size() > 0) |
---|
| 16099 | + Grafreed.Assert(object != null); |
---|
| 16100 | + Grafreed.Assert(object.selection != null); |
---|
| 16101 | + if (object.selection.Size() > 0) |
---|
15677 | 16102 | { |
---|
15678 | | - switch (object.selection.get(0).hitSomething) |
---|
| 16103 | + int hitSomething = object.selection.get(0).hitSomething; |
---|
| 16104 | + |
---|
| 16105 | + object.clickInfo.DX = 0; |
---|
| 16106 | + object.clickInfo.DY = 0; |
---|
| 16107 | + object.clickInfo.W = 1; |
---|
| 16108 | + if (hitSomething == Object3D.hitCenter) |
---|
15679 | 16109 | { |
---|
15680 | | - case Object3D.hitCenter: gr.setColor(Color.pink); |
---|
15681 | | - gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
15682 | | - break; |
---|
15683 | | - case Object3D.hitRotate: gr.setColor(Color.yellow); |
---|
15684 | | - gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
15685 | | - break; |
---|
15686 | | - case Object3D.hitScale: gr.setColor(Color.cyan); |
---|
15687 | | - gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
15688 | | - break; |
---|
| 16110 | + info.DX = X; |
---|
| 16111 | + if (X != 0) |
---|
| 16112 | + info.DX -= info.bounds.width/2; |
---|
| 16113 | + |
---|
| 16114 | + info.DY = Y; |
---|
| 16115 | + if (Y != 0) |
---|
| 16116 | + info.DY -= info.bounds.height/2; |
---|
15689 | 16117 | } |
---|
15690 | | - |
---|
| 16118 | + |
---|
| 16119 | + object.drawEditHandles(//info, |
---|
| 16120 | + 0); |
---|
| 16121 | + |
---|
| 16122 | + if (drag && (X != 0 || Y != 0)) |
---|
| 16123 | + { |
---|
| 16124 | + switch (hitSomething) |
---|
| 16125 | + { |
---|
| 16126 | + case Object3D.hitCenter: gr.setColor(Color.pink); |
---|
| 16127 | + gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
| 16128 | + break; |
---|
| 16129 | + case Object3D.hitRotate: gr.setColor(Color.yellow); |
---|
| 16130 | + gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
| 16131 | + break; |
---|
| 16132 | + case Object3D.hitScale: gr.setColor(Color.cyan); |
---|
| 16133 | + gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
| 16134 | + break; |
---|
| 16135 | + } |
---|
| 16136 | + |
---|
| 16137 | + } |
---|
15691 | 16138 | } |
---|
15692 | 16139 | } |
---|
15693 | 16140 | } |
---|
.. | .. |
---|
16169 | 16616 | private /*static*/ boolean firstime; |
---|
16170 | 16617 | private /*static*/ cVector newView = new cVector(); |
---|
16171 | 16618 | private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"}; |
---|
| 16619 | + private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"}; |
---|
| 16620 | + private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"}; |
---|
16172 | 16621 | private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X, |
---|
16173 | 16622 | GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X, |
---|
16174 | 16623 | GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y, |
---|
.. | .. |
---|
16181 | 16630 | { |
---|
16182 | 16631 | com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP); |
---|
16183 | 16632 | |
---|
| 16633 | + int usedsuf = 0; |
---|
| 16634 | + |
---|
16184 | 16635 | for (int i = 0; i < suffixes.length; i++) |
---|
16185 | 16636 | { |
---|
16186 | | - String resourceName = basename + suffixes[i] + "." + suffix; |
---|
16187 | | - TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
16188 | | - mipmapped, |
---|
16189 | | - FileUtil.getFileSuffix(resourceName)); |
---|
16190 | | - if (data == null) |
---|
| 16637 | + String[] suffixe = suffixes; |
---|
| 16638 | + String[] fallback = suffixes2; |
---|
| 16639 | + String[] fallfallback = suffixes3; |
---|
| 16640 | + |
---|
| 16641 | + for (int c=usedsuf; --c>=0;) |
---|
16191 | 16642 | { |
---|
16192 | | - throw new IOException("Unable to load texture " + resourceName); |
---|
| 16643 | +// String[] temp = suffixe; |
---|
| 16644 | +// suffixe = fallback; |
---|
| 16645 | +// fallback = fallfallback; |
---|
| 16646 | +// fallfallback = temp; |
---|
16193 | 16647 | } |
---|
| 16648 | + |
---|
| 16649 | + String resourceName = basename + suffixe[i] + "." + suffix; |
---|
| 16650 | + TextureData data; |
---|
| 16651 | + |
---|
| 16652 | + try |
---|
| 16653 | + { |
---|
| 16654 | + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
| 16655 | + mipmapped, |
---|
| 16656 | + FileUtil.getFileSuffix(resourceName)); |
---|
| 16657 | + } |
---|
| 16658 | + catch (Exception e) |
---|
| 16659 | + { |
---|
| 16660 | + try |
---|
| 16661 | + { |
---|
| 16662 | + resourceName = basename + fallback[i] + "." + suffix; |
---|
| 16663 | + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
| 16664 | + mipmapped, |
---|
| 16665 | + FileUtil.getFileSuffix(resourceName)); |
---|
| 16666 | + } |
---|
| 16667 | + catch (Exception e2) |
---|
| 16668 | + { |
---|
| 16669 | + resourceName = basename + fallfallback[i] + "." + suffix; |
---|
| 16670 | + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
| 16671 | + mipmapped, |
---|
| 16672 | + FileUtil.getFileSuffix(resourceName)); |
---|
| 16673 | + } |
---|
| 16674 | + } |
---|
| 16675 | + |
---|
16194 | 16676 | //System.out.println("Target = " + targets[i]); |
---|
16195 | 16677 | cubemap.updateImage(data, targets[i]); |
---|
16196 | 16678 | } |
---|
16197 | 16679 | |
---|
16198 | 16680 | return cubemap; |
---|
16199 | 16681 | } |
---|
| 16682 | + |
---|
16200 | 16683 | int bigsphere = -1; |
---|
16201 | 16684 | |
---|
16202 | 16685 | float BGcolor = 0.5f; |
---|
16203 | 16686 | |
---|
16204 | | - private void DrawSkyBox(GL gl) |
---|
| 16687 | + float ambientLight[] = {1f, 1f, 1f, 1.0f}; |
---|
| 16688 | + |
---|
| 16689 | + private void DrawSkyBox(GL gl, float ratio) |
---|
16205 | 16690 | { |
---|
16206 | | - if (envyoff || cubemap == null) |
---|
| 16691 | + if (//envyoff || |
---|
| 16692 | + WIREFRAME || |
---|
| 16693 | + cubemap == null) |
---|
16207 | 16694 | { |
---|
16208 | 16695 | gl.glClearColor(BGcolor, BGcolor, BGcolor, 1); |
---|
16209 | 16696 | gl.glClear(gl.GL_COLOR_BUFFER_BIT); |
---|
.. | .. |
---|
16218 | 16705 | // Compensates for ExaminerViewer's modification of modelview matrix |
---|
16219 | 16706 | gl.glMatrixMode(GL.GL_MODELVIEW); |
---|
16220 | 16707 | gl.glLoadIdentity(); |
---|
| 16708 | + gl.glScalef(1,ratio,1); |
---|
16221 | 16709 | |
---|
| 16710 | +// colorV[0] = 2; |
---|
| 16711 | +// colorV[1] = 2; |
---|
| 16712 | +// colorV[2] = 2; |
---|
| 16713 | +// colorV[3] = 1; |
---|
| 16714 | +// gl.glDisable(gl.GL_COLOR_MATERIAL); |
---|
| 16715 | +// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0); |
---|
| 16716 | +// |
---|
| 16717 | +// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0); |
---|
| 16718 | + |
---|
16222 | 16719 | //gl.glActiveTexture(GL.GL_TEXTURE1); |
---|
16223 | 16720 | //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP); |
---|
16224 | 16721 | |
---|
.. | .. |
---|
16250 | 16747 | { |
---|
16251 | 16748 | gl.glScalef(1.0f, -1.0f, 1.0f); |
---|
16252 | 16749 | } |
---|
| 16750 | + gl.glScalef(-1.0f, 1.0f, 1.0f); |
---|
16253 | 16751 | gl.glMultMatrixd(viewrot_1, 0); |
---|
16254 | 16752 | gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f); |
---|
16255 | 16753 | //viewer.updateInverseRotation(gl); |
---|
.. | .. |
---|
16485 | 16983 | } |
---|
16486 | 16984 | } |
---|
16487 | 16985 | |
---|
| 16986 | + private Object3D GetFolder() |
---|
| 16987 | + { |
---|
| 16988 | + Object3D folder = object.GetWindow().copy; |
---|
| 16989 | + if (object.GetWindow().copy.selection.Size() > 0) |
---|
| 16990 | + folder = object.GetWindow().copy.selection.elementAt(0); |
---|
| 16991 | + return folder; |
---|
| 16992 | + } |
---|
| 16993 | + |
---|
16488 | 16994 | class SelectBuffer implements GLEventListener |
---|
16489 | 16995 | { |
---|
16490 | 16996 | |
---|
.. | .. |
---|
16500 | 17006 | //new Exception().printStackTrace(); |
---|
16501 | 17007 | System.out.println("select buffer init"); |
---|
16502 | 17008 | // Use debug pipeline |
---|
16503 | | - drawable.setGL(new DebugGL(drawable.getGL())); |
---|
| 17009 | + //drawable.setGL(new DebugGL(drawable.getGL())); |
---|
16504 | 17010 | |
---|
16505 | 17011 | GL gl = drawable.getGL(); |
---|
16506 | 17012 | |
---|
.. | .. |
---|
16564 | 17070 | |
---|
16565 | 17071 | //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL); |
---|
16566 | 17072 | |
---|
| 17073 | + if (PAINTMODE) |
---|
| 17074 | + { |
---|
| 17075 | + if (object.GetWindow().copy.selection.Size() > 0) |
---|
| 17076 | + { |
---|
| 17077 | + Object3D paintobj = object.GetWindow().copy.selection.elementAt(0); |
---|
| 17078 | + |
---|
| 17079 | + // Make what you paint not selectable. |
---|
| 17080 | + paintobj.ResetSelectable(); |
---|
| 17081 | + } |
---|
| 17082 | + } |
---|
| 17083 | + |
---|
16567 | 17084 | //int tmp = selection_view; |
---|
16568 | 17085 | //selection_view = -1; |
---|
16569 | 17086 | int temp = DrawMode(); |
---|
.. | .. |
---|
16575 | 17092 | // temp = DEFAULT; // patch for selection debug |
---|
16576 | 17093 | Globals.drawMode = temp; // WARNING |
---|
16577 | 17094 | |
---|
| 17095 | + if (PAINTMODE) |
---|
| 17096 | + { |
---|
| 17097 | + if (object.GetWindow().copy.selection.Size() > 0) |
---|
| 17098 | + { |
---|
| 17099 | + Object3D paintobj = object.GetWindow().copy.selection.elementAt(0); |
---|
| 17100 | + |
---|
| 17101 | + // Revert. |
---|
| 17102 | + paintobj.RestoreSelectable(); |
---|
| 17103 | + } |
---|
| 17104 | + } |
---|
| 17105 | + |
---|
16578 | 17106 | //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view); |
---|
16579 | 17107 | |
---|
16580 | 17108 | // trying different ways of getting the depth info over |
---|
.. | .. |
---|
16678 | 17206 | } |
---|
16679 | 17207 | |
---|
16680 | 17208 | if (!movingcamera && !PAINTMODE) |
---|
16681 | | - object.editWindow.ScreenFitPoint(); // fev 2014 |
---|
| 17209 | + object.GetWindow().ScreenFitPoint(); // fev 2014 |
---|
16682 | 17210 | |
---|
16683 | | - if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0) |
---|
| 17211 | + if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0) |
---|
16684 | 17212 | { |
---|
16685 | | - Object3D paintobj = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0); |
---|
| 17213 | + //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0); |
---|
16686 | 17214 | |
---|
16687 | | - Object3D group = new Object3D("inst" + paintcount++); |
---|
| 17215 | + if (object.GetWindow().copy.selection.Size() > 0) |
---|
| 17216 | + { |
---|
| 17217 | + Object3D paintobj = object.GetWindow().copy.selection.elementAt(0); |
---|
16688 | 17218 | |
---|
16689 | | - group.CreateMaterial(); // use a void leaf to select instances |
---|
16690 | | - |
---|
16691 | | - group.add(paintobj); // link |
---|
16692 | | - |
---|
16693 | | - object.editWindow.SnapObject(group); |
---|
16694 | | - |
---|
16695 | | - Object3D folder = object.editWindow.copy; |
---|
16696 | | - |
---|
16697 | | - if (object.editWindow.copy.selection.Size() > 0) |
---|
16698 | | - folder = object.editWindow.copy.selection.elementAt(0); |
---|
16699 | | - |
---|
16700 | | - folder.add(group); |
---|
16701 | | - |
---|
16702 | | - object.editWindow.ResetModel(); |
---|
16703 | | - object.editWindow.refreshContents(); |
---|
| 17219 | + Object3D inst = new Object3D("inst" + paintcount++); |
---|
| 17220 | + |
---|
| 17221 | + inst.CreateMaterial(); // use a void leaf to select instances |
---|
| 17222 | + |
---|
| 17223 | + inst.add(paintobj); // link |
---|
| 17224 | + |
---|
| 17225 | + object.GetWindow().SnapObject(inst); |
---|
| 17226 | + |
---|
| 17227 | + Object3D folder = paintFolder; // GetFolder(); |
---|
| 17228 | + |
---|
| 17229 | + folder.add(inst); |
---|
| 17230 | + |
---|
| 17231 | + object.GetWindow().ResetModel(); |
---|
| 17232 | + object.GetWindow().refreshContents(); |
---|
| 17233 | + } |
---|
16704 | 17234 | } |
---|
16705 | 17235 | else |
---|
16706 | 17236 | paintcount = 0; |
---|
.. | .. |
---|
16739 | 17269 | //System.out.println("objects[color] = " + objects[color]); |
---|
16740 | 17270 | //objects[color].Select(); |
---|
16741 | 17271 | indexcount = 0; |
---|
| 17272 | + ObjEditor window = object.GetWindow(); |
---|
| 17273 | + if (window != null && deselect) |
---|
| 17274 | + { |
---|
| 17275 | + window.Select(null, deselect, true); |
---|
| 17276 | + } |
---|
16742 | 17277 | object.Select(color, deselect); |
---|
16743 | 17278 | } |
---|
16744 | 17279 | |
---|
.. | .. |
---|
17017 | 17552 | gl.glFlush(); |
---|
17018 | 17553 | |
---|
17019 | 17554 | /**/ |
---|
17020 | | - gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer); |
---|
| 17555 | + gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer); |
---|
17021 | 17556 | |
---|
17022 | | - float[] pixels = occlusionsizebuffer.array(); |
---|
| 17557 | + float[] depths = occlusiondepthbuffer.array(); |
---|
17023 | 17558 | |
---|
| 17559 | + gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer); |
---|
| 17560 | + |
---|
| 17561 | + int[] pixels = selectsizebuffer.array(); |
---|
| 17562 | + |
---|
17024 | 17563 | double r = 0, g = 0, b = 0; |
---|
17025 | 17564 | |
---|
17026 | 17565 | double count = 0; |
---|
.. | .. |
---|
17031 | 17570 | |
---|
17032 | 17571 | double FACTOR = 1; |
---|
17033 | 17572 | |
---|
17034 | | - for (int i = 0; i < pixels.length; i++) |
---|
| 17573 | + for (int i = 0; i < depths.length; i++) |
---|
17035 | 17574 | { |
---|
17036 | 17575 | int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2; |
---|
17037 | 17576 | int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2; |
---|
.. | .. |
---|
17114 | 17653 | |
---|
17115 | 17654 | double scale = ray.z; // 1; // cos |
---|
17116 | 17655 | |
---|
17117 | | - float depth = pixels[newindex]; |
---|
| 17656 | + float depth = depths[newindex]; |
---|
17118 | 17657 | |
---|
17119 | 17658 | /* |
---|
17120 | 17659 | int newindex2 = (x + 1) * OCCLUSION_SIZE + y; |
---|
.. | .. |
---|
17311 | 17850 | static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE); |
---|
17312 | 17851 | static IntBuffer bigAAbuffer; |
---|
17313 | 17852 | static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3); |
---|
17314 | | - static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE); |
---|
| 17853 | + //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE); |
---|
17315 | 17854 | static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE); |
---|
17316 | 17855 | static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE); |
---|
17317 | 17856 | //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); |
---|
17318 | | - static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); |
---|
| 17857 | + static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); |
---|
| 17858 | + |
---|
| 17859 | + static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); |
---|
| 17860 | + |
---|
17319 | 17861 | static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB); |
---|
17320 | 17862 | static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); |
---|
17321 | 17863 | static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>(); |
---|