.. | .. |
---|
18 | 18 | import javax.imageio.ImageIO; |
---|
19 | 19 | import javax.imageio.ImageWriteParam; |
---|
20 | 20 | import javax.imageio.ImageWriter; |
---|
| 21 | +import javax.imageio.ImageReadParam; |
---|
| 22 | +import javax.imageio.ImageReader; |
---|
21 | 23 | import javax.imageio.plugins.jpeg.JPEGImageWriteParam; |
---|
| 24 | +import javax.imageio.stream.ImageInputStream; |
---|
22 | 25 | import javax.imageio.stream.ImageOutputStream; |
---|
23 | 26 | import javax.imageio.ImageWriteParam; |
---|
24 | 27 | |
---|
.. | .. |
---|
30 | 33 | import java.nio.*; |
---|
31 | 34 | |
---|
32 | 35 | import gleem.linalg.Mat4f; |
---|
| 36 | +import javax.imageio.ImageTypeSpecifier; |
---|
33 | 37 | |
---|
34 | 38 | class CameraPane extends GLCanvas implements iCameraPane, Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener |
---|
35 | 39 | { |
---|
.. | .. |
---|
44 | 48 | static boolean ABORTED = false; |
---|
45 | 49 | |
---|
46 | 50 | static int STEP = 1; |
---|
| 51 | + |
---|
| 52 | + private static BufferedImage CreateBim(byte[] bytes, int width, int height) |
---|
| 53 | + { |
---|
| 54 | + int[] pixels = new int[bytes.length/3]; |
---|
| 55 | + for (int i=pixels.length; --i>=0;) |
---|
| 56 | + { |
---|
| 57 | + int i3 = i*3; |
---|
| 58 | + pixels[i] = 0xFF; |
---|
| 59 | + pixels[i] <<= 8; |
---|
| 60 | + pixels[i] |= bytes[i3+2] & 0xFF; |
---|
| 61 | + pixels[i] <<= 8; |
---|
| 62 | + pixels[i] |= bytes[i3+1] & 0xFF; |
---|
| 63 | + pixels[i] <<= 8; |
---|
| 64 | + pixels[i] |= bytes[i3] & 0xFF; |
---|
| 65 | + } |
---|
| 66 | + /* |
---|
| 67 | + int r=0,g=0,b=0,a=0; |
---|
| 68 | + for (int i=0; i<width; i++) |
---|
| 69 | + for (int j=0; j<height; j++) |
---|
| 70 | + { |
---|
| 71 | + int index = j*width+i; |
---|
| 72 | + int p = pixels[index]; |
---|
| 73 | + a = ((p>>24) & 0xFF); |
---|
| 74 | + r = ((p>>16) & 0xFF); |
---|
| 75 | + g = ((p>>8) & 0xFF); |
---|
| 76 | + b = (p & 0xFF); |
---|
| 77 | + pixels[index] = (a<<24) | (b<<16) | (g<<8) | r; |
---|
| 78 | + } |
---|
| 79 | + /**/ |
---|
| 80 | + BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile); |
---|
| 81 | + rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width); |
---|
| 82 | + return rendImage; |
---|
| 83 | + } |
---|
47 | 84 | |
---|
48 | 85 | /*static*/ private boolean CULLFACE = false; // true; |
---|
49 | 86 | /*static*/ boolean NEAREST = false; // true; |
---|
.. | .. |
---|
60 | 97 | //boolean REDUCETEXTURE = true; |
---|
61 | 98 | boolean CACHETEXTURE = true; |
---|
62 | 99 | boolean CLEANCACHE = false; // true; |
---|
63 | | - boolean MIPMAP = false; // true; |
---|
| 100 | + boolean MIPMAP = false; // true; // never works... |
---|
64 | 101 | boolean COMPRESSTEXTURE = false; |
---|
65 | 102 | boolean KOMPACTTEXTURE = false; // true; |
---|
66 | 103 | boolean RESIZETEXTURE = false; |
---|
.. | .. |
---|
73 | 110 | //private Mat4f spotlightTransform = new Mat4f(); |
---|
74 | 111 | //private Mat4f spotlightInverseTransform = new Mat4f(); |
---|
75 | 112 | static GLContext glcontext = null; |
---|
76 | | - /*static*/ com.sun.opengl.util.texture.Texture cubemap; |
---|
| 113 | + /*static*/ com.sun.opengl.util.texture.Texture cubemap; // Either custom or rgb |
---|
| 114 | + /*static*/ com.sun.opengl.util.texture.Texture cubemapcustom; |
---|
| 115 | + /*static*/ com.sun.opengl.util.texture.Texture cubemaprgb; |
---|
| 116 | + boolean transformMode; |
---|
| 117 | + |
---|
77 | 118 | boolean reverseUP = false; |
---|
78 | 119 | static boolean frozen = false; |
---|
79 | 120 | boolean enablebackspace = false; // patch for back buffer refresh |
---|
.. | .. |
---|
136 | 177 | static boolean doublesided = false; // true; // reversed normals are awful for conformance |
---|
137 | 178 | boolean anisotropy = true; |
---|
138 | 179 | boolean softshadow = true; // slower but better false; |
---|
139 | | - boolean opacityhalo = false; |
---|
| 180 | + boolean opacityhalo = false; // reverse the halo effect (e.g. glass) |
---|
140 | 181 | |
---|
141 | 182 | boolean macromode = false; |
---|
142 | 183 | |
---|
.. | .. |
---|
150 | 191 | } |
---|
151 | 192 | |
---|
152 | 193 | private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory(); |
---|
| 194 | + |
---|
| 195 | + public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException |
---|
| 196 | + { |
---|
| 197 | + try |
---|
| 198 | + { |
---|
| 199 | + return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap); |
---|
| 200 | + } catch (IOException e) |
---|
| 201 | + { |
---|
| 202 | + System.out.println("NAME = " + name); |
---|
| 203 | + e.printStackTrace(); // throw new RuntimeException(e); |
---|
| 204 | + return null; |
---|
| 205 | + } |
---|
| 206 | + } |
---|
153 | 207 | |
---|
154 | 208 | void SetAsGLRenderer(boolean b) |
---|
155 | 209 | { |
---|
.. | .. |
---|
169 | 223 | |
---|
170 | 224 | SetCamera(cam); |
---|
171 | 225 | |
---|
172 | | - SetLight(new Camera(new cVector(10, 10, -20))); |
---|
| 226 | + // Warning: not used. |
---|
| 227 | + SetLight(new Camera(new cVector(15, 10, -20))); |
---|
173 | 228 | |
---|
174 | 229 | object = o; |
---|
175 | 230 | |
---|
.. | .. |
---|
1447 | 1502 | gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z); |
---|
1448 | 1503 | } |
---|
1449 | 1504 | |
---|
| 1505 | + float[] colorV = new float[4]; |
---|
| 1506 | + |
---|
1450 | 1507 | void SetColor(Object3D obj, Vertex p0) |
---|
1451 | 1508 | { |
---|
1452 | 1509 | CameraPane display = this; |
---|
.. | .. |
---|
1514 | 1571 | { |
---|
1515 | 1572 | return; |
---|
1516 | 1573 | } |
---|
1517 | | - |
---|
1518 | | - float[] colorV = new float[3]; |
---|
1519 | 1574 | |
---|
1520 | 1575 | if (false) // marked) |
---|
1521 | 1576 | { |
---|
.. | .. |
---|
2065 | 2120 | //System.err.println("Oeil on"); |
---|
2066 | 2121 | OEIL = true; |
---|
2067 | 2122 | if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode) |
---|
2068 | | - object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK); |
---|
| 2123 | + object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK); |
---|
2069 | 2124 | //pingthread.StepToTarget(true); |
---|
2070 | 2125 | } |
---|
2071 | 2126 | |
---|
.. | .. |
---|
2298 | 2353 | HANDLES ^= true; |
---|
2299 | 2354 | } |
---|
2300 | 2355 | |
---|
| 2356 | + Object3D paintFolder; |
---|
| 2357 | + |
---|
2301 | 2358 | void TogglePaint() |
---|
2302 | 2359 | { |
---|
2303 | 2360 | PAINTMODE ^= true; |
---|
2304 | 2361 | paintcount = 0; |
---|
| 2362 | + |
---|
| 2363 | + if (PAINTMODE) |
---|
| 2364 | + { |
---|
| 2365 | + paintFolder = GetFolder(); |
---|
| 2366 | + } |
---|
2305 | 2367 | } |
---|
2306 | 2368 | |
---|
2307 | 2369 | void SwapCamera(int a, int b) |
---|
.. | .. |
---|
2398 | 2460 | return currentGL; |
---|
2399 | 2461 | } |
---|
2400 | 2462 | |
---|
2401 | | - private void GetRemoteZip(String url, String name, boolean unzip, boolean save) |
---|
| 2463 | + static private BufferedImage CreateBim(TextureData texturedata) |
---|
2402 | 2464 | { |
---|
2403 | | - java.net.URL u; |
---|
2404 | | - InputStream is = null; |
---|
2405 | | - DataInputStream dis; |
---|
2406 | | - java.util.zip.ZipInputStream zis; |
---|
2407 | | - //String s; |
---|
2408 | | - |
---|
2409 | | - System.out.println("GetRemoteZip " + name); |
---|
2410 | | - |
---|
2411 | | - int total = 0; // dis.available(); |
---|
2412 | | - |
---|
2413 | | - byte[] bytes = new byte[16384]; |
---|
2414 | | - |
---|
2415 | | - try |
---|
2416 | | - { |
---|
2417 | | - u = new java.net.URL(url + name); |
---|
2418 | | - is = u.openStream(); |
---|
2419 | | - |
---|
2420 | | - System.out.println(url + name); |
---|
2421 | | - |
---|
2422 | | - if (unzip) |
---|
2423 | | - { |
---|
2424 | | - //dis = new DataInputStream(new BufferedInputStream(is)); |
---|
2425 | | - zis = new java.util.zip.ZipInputStream(new BufferedInputStream(is)); |
---|
2426 | | - //while ((s = dis.readLine()) != null) |
---|
2427 | | - |
---|
2428 | | - if (save) |
---|
2429 | | - new java.io.File(name).mkdirs(); |
---|
2430 | | - |
---|
2431 | | - // FileOutputStream stream = new FileOutputStream("test.zip"); |
---|
2432 | | - // |
---|
2433 | | - // int count; |
---|
2434 | | - // |
---|
2435 | | - // while ((count = dis.read(bytes)) != -1) |
---|
2436 | | - // { |
---|
2437 | | - // //System.out.println(s); |
---|
2438 | | - // System.out.println(count); |
---|
2439 | | - // total += count; |
---|
2440 | | - // stream.write(bytes); |
---|
2441 | | - // } |
---|
2442 | | - // |
---|
2443 | | - // stream.close(); |
---|
2444 | | - |
---|
2445 | | - // now iterate through each item in the stream. The get next |
---|
2446 | | - // entry call will return a ZipEntry for each file in the |
---|
2447 | | - // stream |
---|
2448 | | - java.util.zip.ZipEntry entry; |
---|
2449 | | - while((entry = zis.getNextEntry())!=null) |
---|
2450 | | - { |
---|
2451 | | - if (entry.getName().endsWith(".gsm")) |
---|
2452 | | - { |
---|
2453 | | - continue; |
---|
2454 | | - } |
---|
2455 | | - |
---|
2456 | | - String s = String.format("Entry: %s len %d added %TD", |
---|
2457 | | - entry.getName(), entry.getSize(), |
---|
2458 | | - new java.util.Date(entry.getTime())); |
---|
2459 | | - System.out.println(s); |
---|
2460 | | - |
---|
2461 | | - if (save) |
---|
2462 | | - { |
---|
2463 | | - // Once we get the entry from the stream, the stream is |
---|
2464 | | - // positioned read to read the raw data, and we keep |
---|
2465 | | - // reading until read returns 0 or less. |
---|
2466 | | - String outpath = name + "/" + entry.getName(); |
---|
2467 | | - FileOutputStream output = null; |
---|
2468 | | - try |
---|
2469 | | - { |
---|
2470 | | - output = new FileOutputStream(outpath); |
---|
2471 | | - int len = 0; |
---|
2472 | | - while ((len = zis.read(bytes)) > 0) |
---|
2473 | | - { |
---|
2474 | | - output.write(bytes, 0, len); |
---|
2475 | | - } |
---|
2476 | | - } |
---|
2477 | | - finally |
---|
2478 | | - { |
---|
2479 | | - // we must always close the output file |
---|
2480 | | - if(output!=null) output.close(); |
---|
2481 | | - } |
---|
2482 | | - } |
---|
2483 | | - } |
---|
2484 | | - } |
---|
2485 | | - } |
---|
2486 | | - catch (java.net.MalformedURLException mue) |
---|
2487 | | - { |
---|
2488 | | - System.err.println("Ouch - a MalformedURLException happened."); |
---|
2489 | | - mue.printStackTrace(); |
---|
2490 | | - //System.exit(2); |
---|
2491 | | - } |
---|
2492 | | - catch (IOException ioe) |
---|
2493 | | - { |
---|
2494 | | - //System.err.println("Oops - an IOException happened."); |
---|
2495 | | - //ioe.printStackTrace(); |
---|
2496 | | - //System.exit(3); |
---|
2497 | | - } |
---|
2498 | | - finally |
---|
2499 | | - { |
---|
2500 | | - try |
---|
2501 | | - { |
---|
2502 | | - if (is != null) |
---|
2503 | | - is.close(); |
---|
2504 | | - } |
---|
2505 | | - catch (IOException ioe) |
---|
2506 | | - { |
---|
2507 | | - } |
---|
2508 | | - } |
---|
2509 | | - |
---|
2510 | | - // System.out.println("length = " + total); |
---|
2511 | | - |
---|
2512 | | -// try |
---|
2513 | | -// { |
---|
2514 | | -// Runtime.getRuntime().exec("/usr/local/bin/wget https://archive3d.net/?a=download&do=get&id=7caca905"); |
---|
2515 | | -// } |
---|
2516 | | -// catch (Exception e) |
---|
2517 | | -// { |
---|
2518 | | -// e.printStackTrace(); |
---|
2519 | | -// } |
---|
2520 | | - |
---|
| 2465 | + Grafreed.Assert(texturedata != null); |
---|
| 2466 | + |
---|
| 2467 | + int width = texturedata.getWidth(); |
---|
| 2468 | + int height = texturedata.getHeight(); |
---|
| 2469 | + |
---|
| 2470 | + Buffer buffer = texturedata.getBuffer(); |
---|
| 2471 | + ByteBuffer bytebuf = (ByteBuffer)buffer; |
---|
| 2472 | + |
---|
| 2473 | + byte[] bytes = bytebuf.array(); |
---|
| 2474 | + |
---|
| 2475 | + return CreateBim(bytes, width, height); |
---|
2521 | 2476 | } |
---|
2522 | 2477 | |
---|
2523 | 2478 | /**/ |
---|
.. | .. |
---|
2528 | 2483 | |
---|
2529 | 2484 | int resolution; |
---|
2530 | 2485 | |
---|
2531 | | - CacheTexture(com.sun.opengl.util.texture.Texture tex, int res) |
---|
| 2486 | + CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res) |
---|
2532 | 2487 | { |
---|
2533 | | - texture = tex; |
---|
| 2488 | + texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata); |
---|
| 2489 | + texturedata = texdata; |
---|
2534 | 2490 | resolution = res; |
---|
2535 | 2491 | } |
---|
2536 | 2492 | } |
---|
2537 | 2493 | /**/ |
---|
2538 | 2494 | |
---|
2539 | 2495 | // TEXTURE static Texture texture; |
---|
2540 | | - static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures |
---|
2541 | | - = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>(); |
---|
2542 | | - static public java.util.Hashtable<String, String> usedtextures = new java.util.Hashtable<String, String>(); |
---|
| 2496 | + static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>(); |
---|
| 2497 | + static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>(); |
---|
| 2498 | + static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>(); |
---|
| 2499 | + static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>(); |
---|
| 2500 | + |
---|
2543 | 2501 | int pigmentdepth = 0; |
---|
2544 | 2502 | public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536]; |
---|
2545 | 2503 | int bumpdepth = 0; |
---|
2546 | 2504 | public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536]; |
---|
2547 | 2505 | //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE"; |
---|
2548 | 2506 | public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP"); |
---|
2549 | | - public static String NOISE_TEXTURE = "WHITE_NOISE"; |
---|
| 2507 | + public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:"); |
---|
2550 | 2508 | // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL"); |
---|
2551 | 2509 | |
---|
2552 | | - com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump) |
---|
| 2510 | + com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump) |
---|
2553 | 2511 | { |
---|
2554 | 2512 | TextureData texturedata = null; |
---|
2555 | 2513 | |
---|
.. | .. |
---|
2559 | 2517 | com.sun.opengl.util.texture.TextureIO.newTextureData( |
---|
2560 | 2518 | getClass().getClassLoader().getResourceAsStream(name), |
---|
2561 | 2519 | true, |
---|
2562 | | - com.sun.opengl.util.texture.TextureIO.PNG); |
---|
| 2520 | + GetFormat(name)); // com.sun.opengl.util.texture.TextureIO.PNG); |
---|
2563 | 2521 | } catch (java.io.IOException e) |
---|
2564 | 2522 | { |
---|
2565 | 2523 | throw new javax.media.opengl.GLException(e); |
---|
.. | .. |
---|
2568 | 2526 | if (bump) |
---|
2569 | 2527 | texturedata = ConvertBump(texturedata, false); |
---|
2570 | 2528 | |
---|
2571 | | - com.sun.opengl.util.texture.Texture texture = |
---|
2572 | | - com.sun.opengl.util.texture.TextureIO.newTexture(texturedata); |
---|
| 2529 | +// com.sun.opengl.util.texture.Texture texture = |
---|
| 2530 | +// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata); |
---|
2573 | 2531 | |
---|
2574 | | - texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT); |
---|
2575 | | - texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT); |
---|
| 2532 | + //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT); |
---|
| 2533 | + //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT); |
---|
2576 | 2534 | |
---|
2577 | | - return texture; |
---|
| 2535 | + return texturedata; |
---|
| 2536 | + } |
---|
| 2537 | + |
---|
| 2538 | + com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump) |
---|
| 2539 | + { |
---|
| 2540 | + TextureData texturedata = null; |
---|
| 2541 | + |
---|
| 2542 | + try |
---|
| 2543 | + { |
---|
| 2544 | + texturedata = |
---|
| 2545 | + com.sun.opengl.util.texture.TextureIO.newTextureData( |
---|
| 2546 | + bim, |
---|
| 2547 | + true); |
---|
| 2548 | + } catch (Exception e) |
---|
| 2549 | + { |
---|
| 2550 | + throw new javax.media.opengl.GLException(e); |
---|
| 2551 | + } |
---|
| 2552 | + |
---|
| 2553 | + if (bump) |
---|
| 2554 | + texturedata = ConvertBump(texturedata, false); |
---|
| 2555 | + |
---|
| 2556 | + return texturedata; |
---|
2578 | 2557 | } |
---|
2579 | 2558 | |
---|
2580 | 2559 | boolean HUESMOOTH = true; // wrap around bug... true; |
---|
.. | .. |
---|
3647 | 3626 | |
---|
3648 | 3627 | System.out.println("LOADING TEXTURE : " + name); |
---|
3649 | 3628 | |
---|
| 3629 | + Object x = texturedata.getMipmapData(); // .getBuffer(); |
---|
| 3630 | + |
---|
3650 | 3631 | // |
---|
3651 | 3632 | if (false) // compressbit > 0) |
---|
3652 | 3633 | { |
---|
.. | .. |
---|
8045 | 8026 | String pigment = Object3D.GetPigment(tex); |
---|
8046 | 8027 | String bump = Object3D.GetBump(tex); |
---|
8047 | 8028 | |
---|
8048 | | - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8029 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
8049 | 8030 | { |
---|
8050 | 8031 | // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment); |
---|
8051 | 8032 | // System.out.println("; bump = " + bump); |
---|
.. | .. |
---|
8060 | 8041 | pigment = null; |
---|
8061 | 8042 | } |
---|
8062 | 8043 | |
---|
8063 | | - ReleaseTexture(bump, true); |
---|
8064 | | - ReleaseTexture(pigment, false); |
---|
| 8044 | + ReleaseTexture(tex, true); |
---|
| 8045 | + ReleaseTexture(tex, false); |
---|
8065 | 8046 | } |
---|
8066 | 8047 | |
---|
8067 | 8048 | public void ReleasePigmentTexture(cTexture tex) // INTERFACE |
---|
.. | .. |
---|
8079 | 8060 | |
---|
8080 | 8061 | String pigment = Object3D.GetPigment(tex); |
---|
8081 | 8062 | |
---|
8082 | | - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8063 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
8083 | 8064 | { |
---|
8084 | 8065 | // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment); |
---|
8085 | 8066 | // System.out.println("; bump = " + bump); |
---|
.. | .. |
---|
8090 | 8071 | pigment = null; |
---|
8091 | 8072 | } |
---|
8092 | 8073 | |
---|
8093 | | - ReleaseTexture(pigment, false); |
---|
| 8074 | + ReleaseTexture(tex, false); |
---|
8094 | 8075 | } |
---|
8095 | 8076 | |
---|
8096 | 8077 | public void ReleaseBumpTexture(cTexture tex) // INTERFACE |
---|
.. | .. |
---|
8108 | 8089 | |
---|
8109 | 8090 | String bump = Object3D.GetBump(tex); |
---|
8110 | 8091 | |
---|
8111 | | - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8092 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
8112 | 8093 | { |
---|
8113 | 8094 | // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment); |
---|
8114 | 8095 | // System.out.println("; bump = " + bump); |
---|
.. | .. |
---|
8119 | 8100 | bump = null; |
---|
8120 | 8101 | } |
---|
8121 | 8102 | |
---|
8122 | | - ReleaseTexture(bump, true); |
---|
| 8103 | + ReleaseTexture(tex, true); |
---|
8123 | 8104 | } |
---|
8124 | 8105 | |
---|
8125 | | - void ReleaseTexture(String tex, boolean bump) |
---|
| 8106 | + void ReleaseTexture(cTexture tex, boolean bump) |
---|
8126 | 8107 | { |
---|
8127 | 8108 | if (// DrawMode() != 0 || /*tex == null ||*/ |
---|
8128 | 8109 | ambientOcclusion ) // || !textureon) |
---|
.. | .. |
---|
8133 | 8114 | CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null; |
---|
8134 | 8115 | |
---|
8135 | 8116 | if (tex != null) |
---|
8136 | | - texture = textures.get(tex); |
---|
| 8117 | + texture = bump ? texturebump.get(tex) : texturepigment.get(tex); |
---|
8137 | 8118 | |
---|
8138 | 8119 | // //assert( texture != null ); |
---|
8139 | 8120 | // if (texture == null) |
---|
.. | .. |
---|
8227 | 8208 | |
---|
8228 | 8209 | /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE |
---|
8229 | 8210 | { |
---|
8230 | | - if (// DrawMode() != 0 || /*tex == null ||*/ |
---|
8231 | | - ambientOcclusion ) // || !textureon) |
---|
8232 | | - { |
---|
8233 | | - return; // false; |
---|
8234 | | - } |
---|
8235 | | - |
---|
8236 | | - if (tex == null) |
---|
8237 | | - { |
---|
8238 | | - BindTexture(null,false,resolution); |
---|
8239 | | - BindTexture(null,true,resolution); |
---|
8240 | | - return; |
---|
8241 | | - } |
---|
| 8211 | +// if (// DrawMode() != 0 || /*tex == null ||*/ |
---|
| 8212 | +// ambientOcclusion ) // || !textureon) |
---|
| 8213 | +// { |
---|
| 8214 | +// return; // false; |
---|
| 8215 | +// } |
---|
| 8216 | +// |
---|
| 8217 | +// if (tex == null) |
---|
| 8218 | +// { |
---|
| 8219 | +// BindTexture(null,false,resolution); |
---|
| 8220 | +// BindTexture(null,true,resolution); |
---|
| 8221 | +// return; |
---|
| 8222 | +// } |
---|
| 8223 | +// |
---|
| 8224 | +// String pigment = Object3D.GetPigment(tex); |
---|
| 8225 | +// String bump = Object3D.GetBump(tex); |
---|
| 8226 | +// |
---|
| 8227 | +// usedtextures.add(pigment); |
---|
| 8228 | +// usedtextures.add(bump); |
---|
| 8229 | +// |
---|
| 8230 | +// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8231 | +// { |
---|
| 8232 | +// // System.out.print("BIND +++++++++++++++ pigment = " + pigment); |
---|
| 8233 | +// // System.out.println("; bump = " + bump); |
---|
| 8234 | +// } |
---|
| 8235 | +// |
---|
| 8236 | +// if (bump.equals("")) |
---|
| 8237 | +// { |
---|
| 8238 | +// bump = null; |
---|
| 8239 | +// } |
---|
| 8240 | +// if (pigment.equals("")) |
---|
| 8241 | +// { |
---|
| 8242 | +// pigment = null; |
---|
| 8243 | +// } |
---|
| 8244 | +// |
---|
| 8245 | +// GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
| 8246 | +// BindTexture(pigment, false, resolution); |
---|
| 8247 | +// GetGL().glActiveTexture(GetGL().GL_TEXTURE2); |
---|
| 8248 | +// BindTexture(bump, true, resolution); |
---|
| 8249 | +// GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
| 8250 | +// |
---|
| 8251 | +// return; // true; |
---|
8242 | 8252 | |
---|
8243 | | - String pigment = Object3D.GetPigment(tex); |
---|
8244 | | - String bump = Object3D.GetBump(tex); |
---|
8245 | | - |
---|
8246 | | - usedtextures.put(pigment, pigment); |
---|
8247 | | - usedtextures.put(bump, bump); |
---|
8248 | | - |
---|
8249 | | - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
8250 | | - { |
---|
8251 | | - // System.out.print("BIND +++++++++++++++ pigment = " + pigment); |
---|
8252 | | - // System.out.println("; bump = " + bump); |
---|
8253 | | - } |
---|
8254 | | - |
---|
8255 | | - if (bump.equals("")) |
---|
8256 | | - { |
---|
8257 | | - bump = null; |
---|
8258 | | - } |
---|
8259 | | - if (pigment.equals("")) |
---|
8260 | | - { |
---|
8261 | | - pigment = null; |
---|
8262 | | - } |
---|
8263 | | - |
---|
8264 | | - GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
8265 | | - BindTexture(pigment, false, resolution); |
---|
8266 | | - GetGL().glActiveTexture(GetGL().GL_TEXTURE2); |
---|
8267 | | - BindTexture(bump, true, resolution); |
---|
8268 | | - GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
8269 | | - |
---|
8270 | | - return; // true; |
---|
| 8253 | + BindPigmentTexture(tex, resolution); |
---|
| 8254 | + BindBumpTexture(tex, resolution); |
---|
8271 | 8255 | } |
---|
8272 | 8256 | |
---|
8273 | 8257 | /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE |
---|
.. | .. |
---|
8286 | 8270 | |
---|
8287 | 8271 | String pigment = Object3D.GetPigment(tex); |
---|
8288 | 8272 | |
---|
8289 | | - usedtextures.put(pigment, pigment); |
---|
| 8273 | + usedtextures.add(tex); |
---|
8290 | 8274 | |
---|
8291 | | - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8275 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
8292 | 8276 | { |
---|
8293 | 8277 | // System.out.print("BIND +++++++++++++++ pigment = " + pigment); |
---|
8294 | 8278 | // System.out.println("; bump = " + bump); |
---|
.. | .. |
---|
8300 | 8284 | } |
---|
8301 | 8285 | |
---|
8302 | 8286 | GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
8303 | | - BindTexture(pigment, false, resolution); |
---|
| 8287 | + BindTexture(tex, false, resolution); |
---|
8304 | 8288 | } |
---|
8305 | 8289 | |
---|
8306 | 8290 | /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE |
---|
.. | .. |
---|
8319 | 8303 | |
---|
8320 | 8304 | String bump = Object3D.GetBump(tex); |
---|
8321 | 8305 | |
---|
8322 | | - usedtextures.put(bump, bump); |
---|
| 8306 | + usedtextures.add(tex); |
---|
8323 | 8307 | |
---|
8324 | | - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8308 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
8325 | 8309 | { |
---|
8326 | 8310 | // System.out.print("BIND +++++++++++++++ pigment = " + pigment); |
---|
8327 | 8311 | // System.out.println("; bump = " + bump); |
---|
.. | .. |
---|
8333 | 8317 | } |
---|
8334 | 8318 | |
---|
8335 | 8319 | GetGL().glActiveTexture(GetGL().GL_TEXTURE2); |
---|
8336 | | - BindTexture(bump, true, resolution); |
---|
| 8320 | + BindTexture(tex, true, resolution); |
---|
8337 | 8321 | GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
8338 | 8322 | } |
---|
8339 | 8323 | |
---|
.. | .. |
---|
8357 | 8341 | return fileExists; |
---|
8358 | 8342 | } |
---|
8359 | 8343 | |
---|
8360 | | - CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception |
---|
| 8344 | + CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8361 | 8345 | { |
---|
8362 | | - CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null; |
---|
| 8346 | + CacheTexture texturecache = null; |
---|
8363 | 8347 | |
---|
8364 | 8348 | if (tex != null) |
---|
8365 | 8349 | { |
---|
8366 | | - String texname = tex; |
---|
| 8350 | + String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex); |
---|
| 8351 | + byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata; |
---|
| 8352 | + |
---|
| 8353 | + if (texname.equals("") && texdata == null) |
---|
| 8354 | + { |
---|
| 8355 | + return null; |
---|
| 8356 | + } |
---|
8367 | 8357 | |
---|
8368 | 8358 | String fallbackTextureName = defaultDirectory + "/Textures/" + texname; |
---|
8369 | 8359 | |
---|
.. | .. |
---|
8373 | 8363 | // else |
---|
8374 | 8364 | // if (!texname.startsWith("/")) |
---|
8375 | 8365 | // texname = "/Users/nbriere/Textures/" + texname; |
---|
8376 | | - if (!FileExists(tex)) |
---|
| 8366 | + if (!FileExists(texname) && !texname.startsWith("@")) |
---|
8377 | 8367 | { |
---|
8378 | 8368 | texname = fallbackTextureName; |
---|
8379 | 8369 | } |
---|
8380 | 8370 | |
---|
8381 | 8371 | if (CACHETEXTURE) |
---|
8382 | | - texture = textures.get(texname); // TEXTURE CACHE |
---|
8383 | | - |
---|
8384 | | - TextureData texturedata = null; |
---|
8385 | | - |
---|
8386 | | - if (texture == null || texture.resolution < resolution) |
---|
8387 | 8372 | { |
---|
8388 | | - if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals("")) |
---|
| 8373 | + if (texdata == null) |
---|
| 8374 | + texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex); |
---|
| 8375 | + else |
---|
| 8376 | + texturecache = bimtextures.get(texdata); |
---|
| 8377 | + } |
---|
| 8378 | + |
---|
| 8379 | + if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution) |
---|
| 8380 | + { |
---|
| 8381 | + TextureData texturedata = null; |
---|
| 8382 | + |
---|
| 8383 | + if (texdata != null && textureon) |
---|
| 8384 | + { |
---|
| 8385 | + BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB); |
---|
| 8386 | + |
---|
| 8387 | + try |
---|
| 8388 | + { |
---|
| 8389 | + bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph); |
---|
| 8390 | + } |
---|
| 8391 | + catch (Exception e) |
---|
| 8392 | + { |
---|
| 8393 | + bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph); |
---|
| 8394 | + } |
---|
| 8395 | + |
---|
| 8396 | + texturecache = new CacheTexture(GetBimTexture(bim, bump), -1); |
---|
| 8397 | + bimtextures.put(texdata, texturecache); |
---|
| 8398 | + |
---|
| 8399 | + //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB); |
---|
| 8400 | + |
---|
| 8401 | + //Object bim2 = CreateBim(texturecache.texturedata); |
---|
| 8402 | + //bim2 = bim; |
---|
| 8403 | + } |
---|
| 8404 | + else |
---|
| 8405 | + if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals("")) |
---|
8389 | 8406 | { |
---|
8390 | 8407 | assert(!bump); |
---|
8391 | 8408 | // if (bump) |
---|
.. | .. |
---|
8396 | 8413 | // } |
---|
8397 | 8414 | // else |
---|
8398 | 8415 | // { |
---|
8399 | | - texture = textures.get(tex); |
---|
8400 | | - if (texture == null) |
---|
| 8416 | + // texturecache = textures.get(texname); // suspicious |
---|
| 8417 | + if (texturecache == null) |
---|
8401 | 8418 | { |
---|
8402 | | - texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
| 8419 | + texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
8403 | 8420 | } |
---|
| 8421 | + else |
---|
| 8422 | + new Exception().printStackTrace(); |
---|
8404 | 8423 | // } |
---|
8405 | 8424 | } else |
---|
8406 | | - if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals("")) |
---|
| 8425 | + if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals("")) |
---|
8407 | 8426 | { |
---|
8408 | 8427 | assert(bump); |
---|
8409 | | - texture = textures.get(tex); |
---|
8410 | | - if (texture == null) |
---|
8411 | | - texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
| 8428 | + // texturecache = textures.get(texname); // suspicious |
---|
| 8429 | + if (texturecache == null) |
---|
| 8430 | + texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
| 8431 | + else |
---|
| 8432 | + new Exception().printStackTrace(); |
---|
8412 | 8433 | } else |
---|
8413 | 8434 | { |
---|
8414 | 8435 | //if (tex.equals("IMMORTAL")) |
---|
.. | .. |
---|
8416 | 8437 | // texture = GetResourceTexture("default.png"); |
---|
8417 | 8438 | //} else |
---|
8418 | 8439 | //{ |
---|
8419 | | - if (tex.equals("WHITE_NOISE")) |
---|
| 8440 | + if (texname.endsWith("WHITE_NOISE")) |
---|
8420 | 8441 | { |
---|
8421 | | - texture = textures.get(tex); |
---|
8422 | | - if (texture == null) |
---|
8423 | | - texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution); |
---|
| 8442 | + // texturecache = textures.get(texname); // suspicious |
---|
| 8443 | + if (texturecache == null) |
---|
| 8444 | + texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution); |
---|
| 8445 | + else |
---|
| 8446 | + new Exception().printStackTrace(); |
---|
| 8447 | + } else |
---|
| 8448 | + { |
---|
| 8449 | + if (texname.startsWith("@")) |
---|
| 8450 | + { |
---|
| 8451 | + // texturecache = textures.get(texname); // suspicious |
---|
| 8452 | + if (texturecache == null) |
---|
| 8453 | + texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution); |
---|
| 8454 | + else |
---|
| 8455 | + new Exception().printStackTrace(); |
---|
8424 | 8456 | } else |
---|
8425 | 8457 | { |
---|
8426 | 8458 | if (textureon) |
---|
.. | .. |
---|
8479 | 8511 | if (texturedata == null) |
---|
8480 | 8512 | throw new Exception(); |
---|
8481 | 8513 | |
---|
8482 | | - texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution); |
---|
| 8514 | + texturecache = new CacheTexture(texturedata,resolution); |
---|
8483 | 8515 | //texture = GetTexture(tex, bump); |
---|
8484 | 8516 | } |
---|
| 8517 | + } |
---|
8485 | 8518 | } |
---|
8486 | 8519 | //} |
---|
8487 | 8520 | } |
---|
8488 | 8521 | |
---|
8489 | | - if (/*CACHETEXTURE &&*/ texture != null && textureon) |
---|
| 8522 | + if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon) |
---|
8490 | 8523 | { |
---|
8491 | 8524 | //return false; |
---|
8492 | 8525 | |
---|
8493 | 8526 | // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")"); |
---|
8494 | | - if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG"))) |
---|
| 8527 | + if (texturedata != null && texname.toLowerCase().endsWith(".jpg")) |
---|
8495 | 8528 | { |
---|
8496 | 8529 | // String ext = "_highres"; |
---|
8497 | 8530 | // if (REDUCETEXTURE) |
---|
.. | .. |
---|
8508 | 8541 | File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg"); |
---|
8509 | 8542 | if (!cachefile.exists()) |
---|
8510 | 8543 | { |
---|
8511 | | - // cache to disk |
---|
8512 | | - Buffer buffer = texturedata.getBuffer(); // getMipmapData(); |
---|
8513 | | - //buffers[0]. |
---|
8514 | | - |
---|
8515 | | - ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer(); |
---|
8516 | | - int[] pixels = new int[bytebuf.capacity()/3]; |
---|
8517 | | - |
---|
8518 | | - // squared size heuristic... |
---|
8519 | | - if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length)) |
---|
| 8544 | + //if (texturedata.getWidth() == texturedata.getHeight()) |
---|
8520 | 8545 | { |
---|
8521 | | - for (int i=pixels.length; --i>=0;) |
---|
8522 | | - { |
---|
8523 | | - int i3 = i*3; |
---|
8524 | | - pixels[i] = 0xFF; |
---|
8525 | | - pixels[i] <<= 8; |
---|
8526 | | - pixels[i] |= bytebuf.get(i3+2) & 0xFF; |
---|
8527 | | - pixels[i] <<= 8; |
---|
8528 | | - pixels[i] |= bytebuf.get(i3+1) & 0xFF; |
---|
8529 | | - pixels[i] <<= 8; |
---|
8530 | | - pixels[i] |= bytebuf.get(i3) & 0xFF; |
---|
8531 | | - } |
---|
8532 | | - |
---|
8533 | | - /* |
---|
8534 | | - int r=0,g=0,b=0,a=0; |
---|
8535 | | - for (int i=0; i<width; i++) |
---|
8536 | | - for (int j=0; j<height; j++) |
---|
8537 | | - { |
---|
8538 | | - int index = j*width+i; |
---|
8539 | | - int p = pixels[index]; |
---|
8540 | | - a = ((p>>24) & 0xFF); |
---|
8541 | | - r = ((p>>16) & 0xFF); |
---|
8542 | | - g = ((p>>8) & 0xFF); |
---|
8543 | | - b = (p & 0xFF); |
---|
8544 | | - pixels[index] = (a<<24) | (b<<16) | (g<<8) | r; |
---|
8545 | | - } |
---|
8546 | | - /**/ |
---|
8547 | | - int width = (int)Math.sqrt(pixels.length); // squared |
---|
8548 | | - int height = width; |
---|
8549 | | - BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile); |
---|
8550 | | - rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width); |
---|
| 8546 | + BufferedImage rendImage = CreateBim(texturedata); |
---|
| 8547 | + |
---|
8551 | 8548 | ImageWriter writer = null; |
---|
8552 | 8549 | Iterator iter = ImageIO.getImageWritersByFormatName("jpg"); |
---|
8553 | 8550 | if (iter.hasNext()) { |
---|
8554 | 8551 | writer = (ImageWriter)iter.next(); |
---|
8555 | 8552 | } |
---|
8556 | | - float compressionQuality = 0.9f; |
---|
| 8553 | + |
---|
| 8554 | + float compressionQuality = 0.85f; |
---|
8557 | 8555 | try |
---|
8558 | 8556 | { |
---|
8559 | 8557 | ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile); |
---|
.. | .. |
---|
8570 | 8568 | } |
---|
8571 | 8569 | } |
---|
8572 | 8570 | } |
---|
8573 | | - |
---|
| 8571 | + |
---|
| 8572 | + Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment; |
---|
| 8573 | + |
---|
8574 | 8574 | //System.out.println("Texture = " + tex); |
---|
8575 | | - if (textures.containsKey(texname)) |
---|
| 8575 | + if (textures.containsKey(tex)) |
---|
8576 | 8576 | { |
---|
8577 | | - CacheTexture thetex = textures.get(texname); |
---|
| 8577 | + CacheTexture thetex = textures.get(tex); |
---|
8578 | 8578 | thetex.texture.disable(); |
---|
8579 | 8579 | thetex.texture.dispose(); |
---|
8580 | | - textures.remove(texname); |
---|
| 8580 | + textures.remove(tex); |
---|
8581 | 8581 | } |
---|
8582 | 8582 | |
---|
8583 | | - texture.texturedata = texturedata; |
---|
8584 | | - textures.put(texname, texture); |
---|
| 8583 | + //texture.texturedata = texturedata; |
---|
| 8584 | + textures.put(tex, texturecache); |
---|
8585 | 8585 | |
---|
8586 | 8586 | // newtex = true; |
---|
8587 | 8587 | } |
---|
.. | .. |
---|
8597 | 8597 | } |
---|
8598 | 8598 | } |
---|
8599 | 8599 | |
---|
8600 | | - return texture; |
---|
| 8600 | + return texturecache; |
---|
8601 | 8601 | } |
---|
8602 | 8602 | |
---|
8603 | | - com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution) throws Exception |
---|
| 8603 | + static void EmbedTextures(cTexture tex) |
---|
| 8604 | + { |
---|
| 8605 | + if (tex.pigmentdata == null) |
---|
| 8606 | + { |
---|
| 8607 | + //String texname = Object3D.GetPigment(tex); |
---|
| 8608 | + |
---|
| 8609 | + CacheTexture texturecache = texturepigment.get(tex); |
---|
| 8610 | + |
---|
| 8611 | + if (texturecache != null) |
---|
| 8612 | + { |
---|
| 8613 | + tex.pw = texturecache.texturedata.getWidth(); |
---|
| 8614 | + tex.ph = texturecache.texturedata.getHeight(); |
---|
| 8615 | + tex.pigmentdata = //CompressJPEG(CreateBim |
---|
| 8616 | + ((ByteBuffer)texturecache.texturedata.getBuffer()).array() |
---|
| 8617 | + ; |
---|
| 8618 | + //, tex.pw, tex.ph), 0.5f); |
---|
| 8619 | + } |
---|
| 8620 | + } |
---|
| 8621 | + |
---|
| 8622 | + if (tex.bumpdata == null) |
---|
| 8623 | + { |
---|
| 8624 | + //String texname = Object3D.GetBump(tex); |
---|
| 8625 | + |
---|
| 8626 | + CacheTexture texturecache = texturebump.get(tex); |
---|
| 8627 | + |
---|
| 8628 | + if (texturecache != null) |
---|
| 8629 | + { |
---|
| 8630 | + tex.bw = texturecache.texturedata.getWidth(); |
---|
| 8631 | + tex.bh = texturecache.texturedata.getHeight(); |
---|
| 8632 | + tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f); |
---|
| 8633 | + } |
---|
| 8634 | + } |
---|
| 8635 | + } |
---|
| 8636 | + |
---|
| 8637 | + com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8604 | 8638 | { |
---|
8605 | 8639 | CacheTexture texture = GetCacheTexture(tex, bump, resolution); |
---|
8606 | 8640 | |
---|
.. | .. |
---|
8618 | 8652 | return texture!=null?texture.texture:null; |
---|
8619 | 8653 | } |
---|
8620 | 8654 | |
---|
8621 | | - public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution) throws Exception |
---|
| 8655 | + public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8622 | 8656 | { |
---|
8623 | 8657 | CacheTexture texture = GetCacheTexture(tex, bump, resolution); |
---|
8624 | 8658 | |
---|
8625 | 8659 | return texture!=null?texture.texturedata:null; |
---|
8626 | 8660 | } |
---|
8627 | 8661 | |
---|
8628 | | - boolean BindTexture(String tex, boolean bump, int resolution) throws Exception |
---|
| 8662 | + boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8629 | 8663 | { |
---|
8630 | 8664 | if (/*tex == null ||*/ ambientOcclusion ) // || !textureon) |
---|
8631 | 8665 | { |
---|
8632 | 8666 | return false; |
---|
8633 | 8667 | } |
---|
8634 | 8668 | |
---|
8635 | | - boolean newtex = false; |
---|
| 8669 | + //boolean newtex = false; |
---|
8636 | 8670 | |
---|
8637 | 8671 | com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution); |
---|
8638 | 8672 | |
---|
.. | .. |
---|
8664 | 8698 | texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT); |
---|
8665 | 8699 | texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT); |
---|
8666 | 8700 | |
---|
8667 | | - return newtex; |
---|
| 8701 | + return true; // Warning: not used. |
---|
8668 | 8702 | } |
---|
8669 | 8703 | |
---|
| 8704 | + public static byte[] CompressJPEG(BufferedImage image, float quality) |
---|
| 8705 | + { |
---|
| 8706 | + try |
---|
| 8707 | + { |
---|
| 8708 | + ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
---|
| 8709 | + Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg"); |
---|
| 8710 | + ImageWriter writer = writers.next(); |
---|
| 8711 | + |
---|
| 8712 | + ImageWriteParam param = writer.getDefaultWriteParam(); |
---|
| 8713 | + param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); |
---|
| 8714 | + param.setCompressionQuality(quality); |
---|
| 8715 | + |
---|
| 8716 | + ImageOutputStream ios = ImageIO.createImageOutputStream(baos); |
---|
| 8717 | + writer.setOutput(ios); |
---|
| 8718 | + writer.write(null, new IIOImage(image, null, null), param); |
---|
| 8719 | + |
---|
| 8720 | + byte[] data = baos.toByteArray(); |
---|
| 8721 | + writer.dispose(); |
---|
| 8722 | + return data; |
---|
| 8723 | + } |
---|
| 8724 | + catch (Exception e) |
---|
| 8725 | + { |
---|
| 8726 | + e.printStackTrace(); |
---|
| 8727 | + return null; |
---|
| 8728 | + } |
---|
| 8729 | + } |
---|
| 8730 | + |
---|
| 8731 | + public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException |
---|
| 8732 | + { |
---|
| 8733 | + ByteArrayInputStream baos = new ByteArrayInputStream(image); |
---|
| 8734 | + Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg"); |
---|
| 8735 | + ImageReader reader = writers.next(); |
---|
| 8736 | + |
---|
| 8737 | + BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); |
---|
| 8738 | + |
---|
| 8739 | + ImageReadParam param = reader.getDefaultReadParam(); |
---|
| 8740 | + param.setDestination(bim); |
---|
| 8741 | + //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB)); |
---|
| 8742 | + |
---|
| 8743 | + ImageInputStream ios = ImageIO.createImageInputStream(baos); |
---|
| 8744 | + reader.setInput(ios); |
---|
| 8745 | + BufferedImage bim2 = reader.read(0, param); |
---|
| 8746 | + reader.dispose(); |
---|
| 8747 | + |
---|
| 8748 | +// WritableRaster raster = bim2.getRaster(); |
---|
| 8749 | +// DataBufferByte data = (DataBufferByte) raster.getDataBuffer(); |
---|
| 8750 | +// byte[] bytes = data.getData(); |
---|
| 8751 | +// |
---|
| 8752 | +// int[] pixels = new int[bytes.length/3]; |
---|
| 8753 | +// for (int i=pixels.length; --i>=0;) |
---|
| 8754 | +// { |
---|
| 8755 | +// int i3 = i*3; |
---|
| 8756 | +// pixels[i] = 0xFF; |
---|
| 8757 | +// pixels[i] <<= 8; |
---|
| 8758 | +// pixels[i] |= bytes[i3+2] & 0xFF; |
---|
| 8759 | +// pixels[i] <<= 8; |
---|
| 8760 | +// pixels[i] |= bytes[i3+1] & 0xFF; |
---|
| 8761 | +// pixels[i] <<= 8; |
---|
| 8762 | +// pixels[i] |= bytes[i3] & 0xFF; |
---|
| 8763 | +// } |
---|
| 8764 | +// |
---|
| 8765 | +// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w); |
---|
| 8766 | + |
---|
| 8767 | + return bim; |
---|
| 8768 | + } |
---|
| 8769 | + |
---|
8670 | 8770 | ShadowBuffer shadowPBuf; |
---|
8671 | 8771 | AntialiasBuffer antialiasPBuf; |
---|
8672 | 8772 | int MAXSTACK; |
---|
.. | .. |
---|
8683 | 8783 | |
---|
8684 | 8784 | gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0); |
---|
8685 | 8785 | MAXSTACK = temp[0]; |
---|
8686 | | - System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK); |
---|
| 8786 | + if (Globals.DEBUG) |
---|
| 8787 | + System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK); |
---|
8687 | 8788 | gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0); |
---|
8688 | 8789 | MAXSTACK = temp[0]; |
---|
8689 | | - System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK); |
---|
| 8790 | + if (Globals.DEBUG) |
---|
| 8791 | + System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK); |
---|
8690 | 8792 | |
---|
8691 | 8793 | // Use debug pipeline |
---|
8692 | 8794 | //drawable.setGL(new DebugGL(gl)); // |
---|
.. | .. |
---|
8694 | 8796 | gl = drawable.getGL(); // |
---|
8695 | 8797 | |
---|
8696 | 8798 | GL gl3 = getGL(); |
---|
8697 | | - System.out.println("INIT GL IS: " + gl.getClass().getName()); |
---|
| 8799 | + if (Globals.DEBUG) |
---|
| 8800 | + System.out.println("INIT GL IS: " + gl.getClass().getName()); |
---|
8698 | 8801 | |
---|
8699 | 8802 | |
---|
8700 | 8803 | //float pos[] = { 100, 100, 100, 0 }; |
---|
.. | .. |
---|
8859 | 8962 | |
---|
8860 | 8963 | if (cubemap == null) |
---|
8861 | 8964 | { |
---|
8862 | | - LoadEnvy(5); |
---|
| 8965 | + //LoadEnvy(1); |
---|
8863 | 8966 | } |
---|
8864 | 8967 | |
---|
8865 | 8968 | //cubemap.enable(); |
---|
.. | .. |
---|
9135 | 9238 | |
---|
9136 | 9239 | void LoadEnvy(int which) |
---|
9137 | 9240 | { |
---|
| 9241 | + assert(false); |
---|
| 9242 | + |
---|
9138 | 9243 | String name; |
---|
9139 | 9244 | String ext; |
---|
9140 | 9245 | |
---|
.. | .. |
---|
9146 | 9251 | cubemap = null; |
---|
9147 | 9252 | return; |
---|
9148 | 9253 | case 1: |
---|
9149 | | - name = "cubemaps/box_"; |
---|
9150 | | - ext = "png"; |
---|
| 9254 | + name = "cubemaps/rgb/"; |
---|
| 9255 | + ext = "jpg"; |
---|
9151 | 9256 | reverseUP = false; |
---|
9152 | 9257 | break; |
---|
9153 | 9258 | case 2: |
---|
9154 | | - name = "cubemaps/uffizi_"; |
---|
9155 | | - ext = "png"; |
---|
9156 | | - break; // reverseUP = true; break; |
---|
| 9259 | + name = "cubemaps/uffizi/"; |
---|
| 9260 | + ext = "jpg"; |
---|
| 9261 | + reverseUP = false; |
---|
| 9262 | + break; |
---|
9157 | 9263 | case 3: |
---|
9158 | | - name = "cubemaps/CloudyHills_"; |
---|
9159 | | - ext = "tga"; |
---|
| 9264 | + name = "cubemaps/CloudyHills/"; |
---|
| 9265 | + ext = "jpg"; |
---|
9160 | 9266 | reverseUP = false; |
---|
9161 | 9267 | break; |
---|
9162 | 9268 | case 4: |
---|
9163 | | - name = "cubemaps/cornell_"; |
---|
| 9269 | + name = "cubemaps/cornell/"; |
---|
9164 | 9270 | ext = "png"; |
---|
9165 | 9271 | reverseUP = false; |
---|
9166 | 9272 | break; |
---|
| 9273 | + case 5: |
---|
| 9274 | + name = "cubemaps/skycube/"; |
---|
| 9275 | + ext = "jpg"; |
---|
| 9276 | + reverseUP = false; |
---|
| 9277 | + break; |
---|
| 9278 | + case 6: |
---|
| 9279 | + name = "cubemaps/SaintLazarusChurch3/"; |
---|
| 9280 | + ext = "jpg"; |
---|
| 9281 | + reverseUP = false; |
---|
| 9282 | + break; |
---|
| 9283 | + case 7: |
---|
| 9284 | + name = "cubemaps/Sodermalmsallen/"; |
---|
| 9285 | + ext = "jpg"; |
---|
| 9286 | + reverseUP = false; |
---|
| 9287 | + break; |
---|
| 9288 | + case 8: |
---|
| 9289 | + name = "cubemaps/Sodermalmsallen2/"; |
---|
| 9290 | + ext = "jpg"; |
---|
| 9291 | + reverseUP = false; |
---|
| 9292 | + break; |
---|
| 9293 | + case 9: |
---|
| 9294 | + name = "cubemaps/UnionSquare/"; |
---|
| 9295 | + ext = "jpg"; |
---|
| 9296 | + reverseUP = false; |
---|
| 9297 | + break; |
---|
9167 | 9298 | default: |
---|
9168 | | - name = "cubemaps/rgb_"; |
---|
9169 | | - ext = "png"; /*mipmap = true;*/ reverseUP = false; |
---|
| 9299 | + name = "cubemaps/box/"; |
---|
| 9300 | + ext = "png"; /*mipmap = true;*/ |
---|
| 9301 | + reverseUP = false; |
---|
9170 | 9302 | break; |
---|
9171 | 9303 | } |
---|
9172 | | - |
---|
9173 | | - try |
---|
9174 | | - { |
---|
9175 | | - cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap); |
---|
9176 | | - } catch (IOException e) |
---|
9177 | | - { |
---|
9178 | | - throw new RuntimeException(e); |
---|
9179 | | - } |
---|
| 9304 | + |
---|
| 9305 | + LoadSkybox(name, ext, mipmap); |
---|
9180 | 9306 | } |
---|
9181 | 9307 | |
---|
9182 | 9308 | public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) |
---|
.. | .. |
---|
9208 | 9334 | static double[] model = new double[16]; |
---|
9209 | 9335 | double[] camera2light = new double[16]; |
---|
9210 | 9336 | double[] light2camera = new double[16]; |
---|
9211 | | - int newenvy = -1; |
---|
9212 | | - boolean envyoff = true; // false; |
---|
| 9337 | + |
---|
| 9338 | + //int newenvy = -1; |
---|
| 9339 | + //boolean envyoff = false; |
---|
| 9340 | + |
---|
| 9341 | + String loadedskyboxname; |
---|
| 9342 | + |
---|
9213 | 9343 | cVector light0 = new cVector(0, 0, 0); // 1,3,2); |
---|
9214 | 9344 | //float[] light0 = { 0,0,0 }; |
---|
9215 | 9345 | cVector dirlight = new cVector(0, 0, 1); // 1,3,2); |
---|
.. | .. |
---|
9627 | 9757 | |
---|
9628 | 9758 | if (renderCamera != lightCamera) |
---|
9629 | 9759 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
9630 | | - LA.matConcat(matrix, parentcam.GlobalTransform(), matrix); |
---|
| 9760 | + LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix); |
---|
9631 | 9761 | |
---|
9632 | 9762 | // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix); |
---|
9633 | 9763 | |
---|
.. | .. |
---|
9643 | 9773 | |
---|
9644 | 9774 | if (renderCamera != lightCamera) |
---|
9645 | 9775 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
9646 | | - LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix); |
---|
| 9776 | + LA.matConcat(parentcam.GlobalTransform(), matrix, matrix); |
---|
9647 | 9777 | |
---|
9648 | 9778 | // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix); |
---|
9649 | 9779 | |
---|
.. | .. |
---|
9689 | 9819 | rati = 1 / rati; |
---|
9690 | 9820 | gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000); |
---|
9691 | 9821 | } |
---|
9692 | | - assert (newenvy == -1); |
---|
| 9822 | + |
---|
| 9823 | + //assert (newenvy == -1); |
---|
| 9824 | + |
---|
9693 | 9825 | gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
9694 | 9826 | gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB); |
---|
9695 | | - DrawSkyBox(gl); |
---|
| 9827 | + DrawSkyBox(gl, (float)rati); |
---|
9696 | 9828 | gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
9697 | 9829 | gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB); |
---|
9698 | 9830 | accPerspective(gl, renderCamera.shaper_fovy / ratio, |
---|
.. | .. |
---|
10729 | 10861 | |
---|
10730 | 10862 | if (wait) |
---|
10731 | 10863 | { |
---|
10732 | | - Sleep(500); |
---|
| 10864 | + Sleep(200); // blocks everything |
---|
10733 | 10865 | |
---|
10734 | 10866 | wait = false; |
---|
10735 | 10867 | } |
---|
.. | .. |
---|
10844 | 10976 | // if (parentcam != renderCamera) // not a light |
---|
10845 | 10977 | if (cam != lightCamera) |
---|
10846 | 10978 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
10847 | | - LA.matConcat(matrix, parentcam.GlobalTransform(), matrix); |
---|
| 10979 | + LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix); |
---|
10848 | 10980 | |
---|
10849 | 10981 | for (int j = 0; j < 4; j++) |
---|
10850 | 10982 | { |
---|
.. | .. |
---|
10859 | 10991 | // if (parentcam != renderCamera) // not a light |
---|
10860 | 10992 | if (cam != lightCamera) |
---|
10861 | 10993 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
10862 | | - LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix); |
---|
| 10994 | + LA.matConcat(parentcam.GlobalTransform(), matrix, matrix); |
---|
10863 | 10995 | |
---|
10864 | 10996 | //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix); |
---|
10865 | 10997 | |
---|
.. | .. |
---|
10945 | 11077 | gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000); |
---|
10946 | 11078 | } |
---|
10947 | 11079 | |
---|
10948 | | - if (newenvy > -1) |
---|
| 11080 | +// if (newenvy > -1) |
---|
| 11081 | +// { |
---|
| 11082 | +// LoadEnvy(newenvy); |
---|
| 11083 | +// } |
---|
| 11084 | +// |
---|
| 11085 | +// newenvy = -1; |
---|
| 11086 | + |
---|
| 11087 | + if (transformMode) // object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb")) |
---|
10949 | 11088 | { |
---|
10950 | | - LoadEnvy(newenvy); |
---|
| 11089 | + if (cubemaprgb == null) |
---|
| 11090 | + { |
---|
| 11091 | + cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb" + "/", "jpg", false); |
---|
| 11092 | + } |
---|
| 11093 | + |
---|
| 11094 | + cubemap = cubemaprgb; |
---|
10951 | 11095 | } |
---|
10952 | | - |
---|
10953 | | - newenvy = -1; |
---|
10954 | | - |
---|
| 11096 | + else |
---|
| 11097 | + { |
---|
| 11098 | + if (object.skyboxname != null) |
---|
| 11099 | + { |
---|
| 11100 | + if (!object.skyboxname.equals(this.loadedskyboxname)) |
---|
| 11101 | + { |
---|
| 11102 | + if (cubemap != null && cubemap != cubemaprgb) |
---|
| 11103 | + cubemap.dispose(); |
---|
| 11104 | + cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false); |
---|
| 11105 | + loadedskyboxname = object.skyboxname; |
---|
| 11106 | + } |
---|
| 11107 | + } |
---|
| 11108 | + else |
---|
| 11109 | + { |
---|
| 11110 | + cubemapcustom = null; |
---|
| 11111 | + loadedskyboxname = null; |
---|
| 11112 | + } |
---|
| 11113 | + |
---|
| 11114 | + cubemap = cubemapcustom; |
---|
| 11115 | + } |
---|
| 11116 | + |
---|
10955 | 11117 | ratio = ((double) getWidth()) / getHeight(); |
---|
10956 | 11118 | //System.out.println("ratio = " + ratio); |
---|
10957 | 11119 | |
---|
.. | .. |
---|
10967 | 11129 | |
---|
10968 | 11130 | if (!IsFrozen() && !ambientOcclusion) |
---|
10969 | 11131 | { |
---|
10970 | | - DrawSkyBox(gl); |
---|
| 11132 | + DrawSkyBox(gl, (float)ratio); |
---|
10971 | 11133 | } |
---|
10972 | 11134 | |
---|
10973 | 11135 | //if (selection_view == -1) |
---|
.. | .. |
---|
11150 | 11312 | |
---|
11151 | 11313 | gl.glMatrixMode(GL.GL_MODELVIEW); |
---|
11152 | 11314 | |
---|
11153 | | -//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST); |
---|
11154 | | -//gl.glEnable(gl.GL_POLYGON_SMOOTH); |
---|
11155 | | -//gl.glEnable(gl.GL_MULTISAMPLE); |
---|
| 11315 | +gl.glEnable(gl.GL_POLYGON_SMOOTH); |
---|
| 11316 | +gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST); |
---|
| 11317 | +gl.glEnable(gl.GL_MULTISAMPLE); |
---|
11156 | 11318 | } else |
---|
11157 | 11319 | { |
---|
11158 | 11320 | //gl.glDisable(GL.GL_TEXTURE_2D); |
---|
.. | .. |
---|
11163 | 11325 | //System.out.println("BLENDING ON"); |
---|
11164 | 11326 | gl.glEnable(GL.GL_BLEND); |
---|
11165 | 11327 | gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); |
---|
11166 | | - |
---|
| 11328 | +// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE); |
---|
11167 | 11329 | gl.glMatrixMode(gl.GL_PROJECTION); |
---|
11168 | 11330 | gl.glLoadIdentity(); |
---|
11169 | 11331 | |
---|
.. | .. |
---|
11253 | 11415 | |
---|
11254 | 11416 | // if (cam != lightCamera) |
---|
11255 | 11417 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
11256 | | - LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013 |
---|
| 11418 | + LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013 |
---|
11257 | 11419 | } |
---|
11258 | 11420 | |
---|
11259 | 11421 | LA.xformDir(lightposition, cam.toScreen, lightposition); |
---|
.. | .. |
---|
11412 | 11574 | } |
---|
11413 | 11575 | } |
---|
11414 | 11576 | |
---|
11415 | | - if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion) |
---|
| 11577 | + if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion) |
---|
11416 | 11578 | { |
---|
11417 | 11579 | //gl.glDepthFunc(GL.GL_LEQUAL); |
---|
11418 | 11580 | //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT); |
---|
.. | .. |
---|
11420 | 11582 | |
---|
11421 | 11583 | boolean texon = textureon; |
---|
11422 | 11584 | |
---|
11423 | | - if (RENDERPROGRAM > 0) |
---|
11424 | | - { |
---|
11425 | | - gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
11426 | | - textureon = false; |
---|
11427 | | - } |
---|
| 11585 | + gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
| 11586 | + textureon = false; |
---|
| 11587 | + |
---|
11428 | 11588 | //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB); |
---|
11429 | 11589 | //System.out.println("ALLO"); |
---|
11430 | 11590 | gl.glColorMask(false, false, false, false); |
---|
11431 | 11591 | DrawObject(gl); |
---|
11432 | | - if (RENDERPROGRAM > 0) |
---|
11433 | | - { |
---|
11434 | | - gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
11435 | | - textureon = texon; |
---|
11436 | | - } |
---|
| 11592 | + |
---|
| 11593 | + gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
| 11594 | + textureon = texon; |
---|
| 11595 | + |
---|
11437 | 11596 | gl.glColorMask(true, true, true, true); |
---|
11438 | 11597 | |
---|
11439 | 11598 | gl.glDepthFunc(GL.GL_EQUAL); |
---|
11440 | | - //gl.glDepthMask(false); |
---|
| 11599 | + gl.glDepthMask(false); |
---|
11441 | 11600 | } |
---|
11442 | 11601 | |
---|
11443 | 11602 | if (false) // DrawMode() == SHADOW) |
---|
.. | .. |
---|
11649 | 11808 | if ((TRACK || SHADOWTRACK) || zoomonce) |
---|
11650 | 11809 | { |
---|
11651 | 11810 | if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode) |
---|
11652 | | - object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK); |
---|
| 11811 | + object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK); |
---|
11653 | 11812 | pingthread.StepToTarget(true); // true); |
---|
11654 | 11813 | // zoomonce = false; |
---|
11655 | 11814 | } |
---|
.. | .. |
---|
11777 | 11936 | ReleaseTextures(DEFAULT_TEXTURES); |
---|
11778 | 11937 | |
---|
11779 | 11938 | if (CLEANCACHE) |
---|
11780 | | - for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();) |
---|
| 11939 | + for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();) |
---|
11781 | 11940 | { |
---|
11782 | | - String tex = e.nextElement(); |
---|
| 11941 | + cTexture tex = e.nextElement(); |
---|
11783 | 11942 | |
---|
11784 | 11943 | // System.out.println("Texture --------- " + tex); |
---|
11785 | 11944 | |
---|
11786 | | - if (tex.equals("WHITE_NOISE")) |
---|
| 11945 | + if (tex.equals("WHITE_NOISE:")) |
---|
11787 | 11946 | continue; |
---|
11788 | 11947 | |
---|
11789 | | - if (!usedtextures.containsKey(tex)) |
---|
| 11948 | + if (!usedtextures.contains(tex)) |
---|
11790 | 11949 | { |
---|
| 11950 | + CacheTexture gettex = texturepigment.get(tex); |
---|
11791 | 11951 | // System.out.println("DISPOSE +++++++++++++++ " + tex); |
---|
11792 | | - textures.get(tex).texture.dispose(); |
---|
11793 | | - textures.remove(tex); |
---|
| 11952 | + if (gettex != null) |
---|
| 11953 | + { |
---|
| 11954 | + gettex.texture.dispose(); |
---|
| 11955 | + texturepigment.remove(tex); |
---|
| 11956 | + } |
---|
| 11957 | + |
---|
| 11958 | + gettex = texturebump.get(tex); |
---|
| 11959 | + // System.out.println("DISPOSE +++++++++++++++ " + tex); |
---|
| 11960 | + if (gettex != null) |
---|
| 11961 | + { |
---|
| 11962 | + gettex.texture.dispose(); |
---|
| 11963 | + texturebump.remove(tex); |
---|
| 11964 | + } |
---|
11794 | 11965 | } |
---|
11795 | 11966 | } |
---|
11796 | 11967 | } |
---|
.. | .. |
---|
12318 | 12489 | |
---|
12319 | 12490 | //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0); |
---|
12320 | 12491 | |
---|
12321 | | - String program = |
---|
| 12492 | + String programmin = |
---|
| 12493 | + // Min shader |
---|
12322 | 12494 | "!!ARBfp1.0\n" + |
---|
| 12495 | + "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" + |
---|
| 12496 | + "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" + |
---|
| 12497 | + "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" + |
---|
| 12498 | + "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" + |
---|
| 12499 | + "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" + |
---|
| 12500 | + "PARAM light2cam0 = program.env[10];" + |
---|
| 12501 | + "PARAM light2cam1 = program.env[11];" + |
---|
| 12502 | + "PARAM light2cam2 = program.env[12];" + |
---|
| 12503 | + "TEMP temp;" + |
---|
| 12504 | + "TEMP light;" + |
---|
| 12505 | + "TEMP ndotl;" + |
---|
| 12506 | + "TEMP normal;" + |
---|
| 12507 | + "TEMP depth;" + |
---|
| 12508 | + "TEMP eye;" + |
---|
| 12509 | + "TEMP pos;" + |
---|
| 12510 | + |
---|
| 12511 | + "MAD normal, fragment.color, zero123.z, -zero123.y;" + |
---|
| 12512 | + Normalize("normal") + |
---|
| 12513 | + "MOV light, state.light[0].position;" + |
---|
| 12514 | + "DP3 ndotl.x, light, normal;" + |
---|
| 12515 | + |
---|
| 12516 | + // shadow |
---|
| 12517 | + "MOV pos, fragment.texcoord[1];" + |
---|
| 12518 | + "MOV temp, pos;" + |
---|
| 12519 | + ShadowTextureFetch("depth", "temp", "1") + |
---|
| 12520 | + //"TEX depth, fragment.texcoord[1], texture[1], 2D;" + |
---|
| 12521 | + "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" + |
---|
| 12522 | + |
---|
| 12523 | + // No shadow when out of frustum |
---|
| 12524 | + //"SGE temp.y, depth.z, zero123.y;" + |
---|
| 12525 | + //"LRP temp.x, temp.y, zero123.y, temp.x;" + |
---|
| 12526 | + |
---|
| 12527 | + "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow |
---|
| 12528 | + |
---|
| 12529 | + // Backlit |
---|
| 12530 | + "MOV pos.w, zero123.y;" + |
---|
| 12531 | + "DP4 eye.x, pos, light2cam0;" + |
---|
| 12532 | + "DP4 eye.y, pos, light2cam1;" + |
---|
| 12533 | + "DP4 eye.z, pos, light2cam2;" + |
---|
| 12534 | + Normalize("eye") + |
---|
| 12535 | + |
---|
| 12536 | + "DP3 ndotl.y, -eye, normal;" + |
---|
| 12537 | + //"MUL ndotl.y, ndotl.y, pow2.x;" + |
---|
| 12538 | + "POW ndotl.y, ndotl.y, pow2.z;" + // backlit |
---|
| 12539 | + "SUB ndotl.y, zero123.y, ndotl.y;" + |
---|
| 12540 | + //"SUB ndotl.y, zero123.y, ndotl.y;" + |
---|
| 12541 | + //"MUL ndotl.y, ndotl.y, pow2.z;" + |
---|
| 12542 | + |
---|
| 12543 | + //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient |
---|
| 12544 | + //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient |
---|
| 12545 | + |
---|
| 12546 | + // Pigment |
---|
| 12547 | + "TEX temp, fragment.texcoord[0], texture[0], 2D;" + |
---|
| 12548 | + "LRP temp, zero123.w, temp, one;" + // texture proportion |
---|
| 12549 | + "MUL temp, temp, ndotl.x;" + |
---|
| 12550 | + |
---|
| 12551 | + "MUL temp, temp, zero123.z;" + |
---|
| 12552 | + |
---|
| 12553 | + //"MUL temp, temp, ndotl.y;" + |
---|
| 12554 | + |
---|
| 12555 | + "MOV temp.w, zero123.y;" + // reset alpha |
---|
| 12556 | + "MOV result.color, temp;" + |
---|
| 12557 | + "END"; |
---|
| 12558 | + |
---|
| 12559 | + String programmax = |
---|
| 12560 | + "!!ARBfp1.0\n" + |
---|
| 12561 | + |
---|
12323 | 12562 | //"OPTION ARB_fragment_program_shadow;" + |
---|
12324 | 12563 | "PARAM light2cam0 = program.env[10];" + |
---|
12325 | 12564 | "PARAM light2cam1 = program.env[11];" + |
---|
.. | .. |
---|
12434 | 12673 | "TEMP shininess;" + |
---|
12435 | 12674 | "\n" + |
---|
12436 | 12675 | "MOV texSamp, one;" + |
---|
12437 | | - //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" + |
---|
12438 | | - |
---|
| 12676 | + |
---|
12439 | 12677 | "MOV mapgrid.x, one2048th.x;" + |
---|
12440 | 12678 | "MOV temp, fragment.texcoord[1];" + |
---|
12441 | 12679 | /* |
---|
.. | .. |
---|
12456 | 12694 | "MUL temp, floor, mapgrid.x;" + |
---|
12457 | 12695 | //"TEX depth0, temp, texture[1], 2D;" + |
---|
12458 | 12696 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12459 | | - TextureFetch("depth0", "temp", "1") + |
---|
| 12697 | + ShadowTextureFetch("depth0", "temp", "1") + |
---|
12460 | 12698 | "") + |
---|
12461 | 12699 | "ADD temp.x, temp.x, mapgrid.x;" + |
---|
12462 | 12700 | //"TEX depth1, temp, texture[1], 2D;" + |
---|
12463 | 12701 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12464 | | - TextureFetch("depth1", "temp", "1") + |
---|
| 12702 | + ShadowTextureFetch("depth1", "temp", "1") + |
---|
12465 | 12703 | "") + |
---|
12466 | 12704 | "ADD temp.y, temp.y, mapgrid.x;" + |
---|
12467 | 12705 | //"TEX depth2, temp, texture[1], 2D;" + |
---|
12468 | | - TextureFetch("depth2", "temp", "1") + |
---|
| 12706 | + ShadowTextureFetch("depth2", "temp", "1") + |
---|
12469 | 12707 | "SUB temp.x, temp.x, mapgrid.x;" + |
---|
12470 | 12708 | //"TEX depth3, temp, texture[1], 2D;" + |
---|
12471 | 12709 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12472 | | - TextureFetch("depth3", "temp", "1") + |
---|
| 12710 | + ShadowTextureFetch("depth3", "temp", "1") + |
---|
12473 | 12711 | "") + |
---|
12474 | 12712 | //"MUL texSamp0, texSamp0, state.material.front.diffuse;" + |
---|
12475 | 12713 | //"MOV params, material;" + |
---|
.. | .. |
---|
12840 | 13078 | "MAD shadow.x, buffer.x, frac.y, shadow.x;" + |
---|
12841 | 13079 | "") + |
---|
12842 | 13080 | |
---|
12843 | | - // display shadow only (bump == 0) |
---|
| 13081 | + // display shadow only (fakedepth == 0) |
---|
12844 | 13082 | "SUB temp.x, half.x, shadow.x;" + |
---|
12845 | 13083 | "MOV temp.y, -params5.z;" + // params6.x;" + |
---|
12846 | | - "SLT temp.z, temp.y, -one2048th.x;" + |
---|
| 13084 | + "SLT temp.z, temp.y, -c256i.x;" + |
---|
12847 | 13085 | "SUB temp.y, one.x, temp.z;" + |
---|
12848 | 13086 | "MUL temp.x, temp.x, temp.y;" + |
---|
12849 | 13087 | "KIL temp.x;" + |
---|
.. | .. |
---|
13174 | 13412 | //once = true; |
---|
13175 | 13413 | } |
---|
13176 | 13414 | |
---|
| 13415 | + String program = programmax; |
---|
| 13416 | + |
---|
| 13417 | + if (Globals.MINSHADER) |
---|
| 13418 | + { |
---|
| 13419 | + program = programmin; |
---|
| 13420 | + } |
---|
| 13421 | + |
---|
13177 | 13422 | System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length()); |
---|
13178 | 13423 | System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : "")); |
---|
13179 | 13424 | loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program); |
---|
.. | .. |
---|
13267 | 13512 | return out; |
---|
13268 | 13513 | } |
---|
13269 | 13514 | |
---|
13270 | | - String TextureFetch(String dest, String src, String unit) |
---|
| 13515 | + // Also does frustum culling |
---|
| 13516 | + String ShadowTextureFetch(String dest, String src, String unit) |
---|
13271 | 13517 | { |
---|
13272 | 13518 | return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" + |
---|
13273 | 13519 | "SGE " + src + ".w, " + src + ".x, eps.x;" + |
---|
13274 | 13520 | "SGE " + src + ".z, " + src + ".y, eps.x;" + |
---|
| 13521 | + "SLT " + dest + ".x, " + src + ".x, one.x;" + |
---|
| 13522 | + "SLT " + dest + ".y, " + src + ".y, one.x;" + |
---|
13275 | 13523 | "MUL " + src + ".w, " + src + ".z, " + src + ".w;" + |
---|
13276 | | - "SLT " + src + ".z, " + src + ".x, one.x;" + |
---|
13277 | | - "MUL " + src + ".w, " + src + ".z, " + src + ".w;" + |
---|
13278 | | - "SLT " + src + ".z, " + src + ".y, one.x;" + |
---|
13279 | | - "MUL " + src + ".w, " + src + ".z, " + src + ".w;" + |
---|
| 13524 | + "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" + |
---|
| 13525 | + "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" + |
---|
13280 | 13526 | //"SWZ buffer, temp, w,w,w,w;"; |
---|
13281 | | - "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" + |
---|
| 13527 | + //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" + |
---|
13282 | 13528 | "SUB " + src + ".z, " + "one.x, " + src + ".w;" + |
---|
13283 | 13529 | //"MUL " + src + ".z, " + src + ".z, infinity.x;" + |
---|
13284 | 13530 | //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;"; |
---|
13285 | | - "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
| 13531 | + //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
13286 | 13532 | |
---|
13287 | | - //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;"; |
---|
13288 | | - //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;"; |
---|
| 13533 | + //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;"; |
---|
| 13534 | + "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
13289 | 13535 | } |
---|
13290 | 13536 | |
---|
13291 | 13537 | String Shadow(String depth, String shadow) |
---|
.. | .. |
---|
13332 | 13578 | "SLT temp.x, temp.x, zero.x;" + // shadoweps |
---|
13333 | 13579 | "LRP " + shadow + ", temp.x, one, " + shadow + ";" + |
---|
13334 | 13580 | |
---|
13335 | | - // No shadow when out of frustrum |
---|
| 13581 | + // No shadow when out of frustum |
---|
13336 | 13582 | "SGE temp.x, " + depth + ".z, one.z;" + |
---|
13337 | 13583 | "LRP " + shadow + ", temp.x, one, " + shadow + ";" + |
---|
13338 | 13584 | ""; |
---|
.. | .. |
---|
14065 | 14311 | |
---|
14066 | 14312 | // fev 2014??? |
---|
14067 | 14313 | if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode) |
---|
14068 | | - object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK); |
---|
| 14314 | + object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK); |
---|
14069 | 14315 | pingthread.StepToTarget(true); // true); |
---|
14070 | 14316 | } |
---|
14071 | 14317 | // if (!LIVE) |
---|
.. | .. |
---|
14130 | 14376 | drag = false; |
---|
14131 | 14377 | //System.out.println("Mouse DOWN"); |
---|
14132 | 14378 | editObj = false; |
---|
14133 | | - ClickInfo info = new ClickInfo(); |
---|
14134 | | - info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
14135 | | - info.pane = this; |
---|
14136 | | - info.camera = renderCamera; |
---|
14137 | | - info.x = x; |
---|
14138 | | - info.y = y; |
---|
14139 | | - info.modifiers = modifiersex; |
---|
14140 | | - editObj = object.doEditClick(info, 0); |
---|
| 14379 | + //ClickInfo info = new ClickInfo(); |
---|
| 14380 | + object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
| 14381 | + object.clickInfo.pane = this; |
---|
| 14382 | + object.clickInfo.camera = renderCamera; |
---|
| 14383 | + object.clickInfo.x = x; |
---|
| 14384 | + object.clickInfo.y = y; |
---|
| 14385 | + object.clickInfo.modifiers = modifiersex; |
---|
| 14386 | + editObj = object.doEditClick(//info, |
---|
| 14387 | + 0); |
---|
14141 | 14388 | if (!editObj) |
---|
14142 | 14389 | { |
---|
14143 | 14390 | hasMarquee = true; |
---|
.. | .. |
---|
14419 | 14666 | void GoDown(int mod) |
---|
14420 | 14667 | { |
---|
14421 | 14668 | MODIFIERS |= COMMAND; |
---|
14422 | | - /* |
---|
| 14669 | + /**/ |
---|
14423 | 14670 | if((mod&SHIFT) == SHIFT) |
---|
14424 | | - manipCamera.RotatePosition(0, -speed); |
---|
| 14671 | + manipCamera.BackForth(0, -speed*delta, 0); // getWidth()); |
---|
14425 | 14672 | else |
---|
14426 | | - manipCamera.BackForth(0, -speed*delta, getWidth()); |
---|
14427 | | - */ |
---|
| 14673 | + manipCamera.RotatePosition(0, -speed); |
---|
| 14674 | + /**/ |
---|
14428 | 14675 | if ((mod & SHIFT) == SHIFT) |
---|
14429 | 14676 | { |
---|
14430 | 14677 | mouseMode = mouseMode; // VR?? |
---|
.. | .. |
---|
14440 | 14687 | void GoUp(int mod) |
---|
14441 | 14688 | { |
---|
14442 | 14689 | MODIFIERS |= COMMAND; |
---|
14443 | | - /* |
---|
| 14690 | + /**/ |
---|
14444 | 14691 | if((mod&SHIFT) == SHIFT) |
---|
14445 | | - manipCamera.RotatePosition(0, speed); |
---|
| 14692 | + manipCamera.BackForth(0, speed*delta, 0); // getWidth()); |
---|
14446 | 14693 | else |
---|
14447 | | - manipCamera.BackForth(0, speed*delta, getWidth()); |
---|
14448 | | - */ |
---|
| 14694 | + manipCamera.RotatePosition(0, speed); |
---|
| 14695 | + /**/ |
---|
14449 | 14696 | if ((mod & SHIFT) == SHIFT) |
---|
14450 | 14697 | { |
---|
14451 | 14698 | mouseMode = mouseMode; |
---|
.. | .. |
---|
14461 | 14708 | void GoLeft(int mod) |
---|
14462 | 14709 | { |
---|
14463 | 14710 | MODIFIERS |= COMMAND; |
---|
14464 | | - /* |
---|
| 14711 | + /**/ |
---|
14465 | 14712 | if((mod&SHIFT) == SHIFT) |
---|
14466 | | - manipCamera.RotatePosition(speed, 0); |
---|
14467 | | - else |
---|
14468 | 14713 | manipCamera.Translate(speed*delta, 0, getWidth()); |
---|
14469 | | - */ |
---|
| 14714 | + else |
---|
| 14715 | + manipCamera.RotatePosition(speed, 0); |
---|
| 14716 | + /**/ |
---|
14470 | 14717 | if ((mod & SHIFT) == SHIFT) |
---|
14471 | 14718 | { |
---|
14472 | 14719 | mouseMode = mouseMode; |
---|
.. | .. |
---|
14482 | 14729 | void GoRight(int mod) |
---|
14483 | 14730 | { |
---|
14484 | 14731 | MODIFIERS |= COMMAND; |
---|
14485 | | - /* |
---|
| 14732 | + /**/ |
---|
14486 | 14733 | if((mod&SHIFT) == SHIFT) |
---|
14487 | | - manipCamera.RotatePosition(-speed, 0); |
---|
14488 | | - else |
---|
14489 | 14734 | manipCamera.Translate(-speed*delta, 0, getWidth()); |
---|
14490 | | - */ |
---|
| 14735 | + else |
---|
| 14736 | + manipCamera.RotatePosition(-speed, 0); |
---|
| 14737 | + /**/ |
---|
14491 | 14738 | if ((mod & SHIFT) == SHIFT) |
---|
14492 | 14739 | { |
---|
14493 | 14740 | mouseMode = mouseMode; |
---|
.. | .. |
---|
14537 | 14784 | if (editObj) |
---|
14538 | 14785 | { |
---|
14539 | 14786 | drag = true; |
---|
14540 | | - ClickInfo info = new ClickInfo(); |
---|
14541 | | - info.bounds.setBounds(0, 0, |
---|
| 14787 | + //ClickInfo info = new ClickInfo(); |
---|
| 14788 | + object.clickInfo.bounds.setBounds(0, 0, |
---|
14542 | 14789 | (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
14543 | | - info.pane = this; |
---|
14544 | | - info.camera = renderCamera; |
---|
14545 | | - info.x = x; |
---|
14546 | | - info.y = y; |
---|
14547 | | - object.GetWindow().copy |
---|
14548 | | - .doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0); |
---|
| 14790 | + object.clickInfo.pane = this; |
---|
| 14791 | + object.clickInfo.camera = renderCamera; |
---|
| 14792 | + object.clickInfo.x = x; |
---|
| 14793 | + object.clickInfo.y = y; |
---|
| 14794 | + object //.GetWindow().copy |
---|
| 14795 | + .doEditDrag(//info, |
---|
| 14796 | + (modifiers & MouseEvent.BUTTON3_MASK) != 0); |
---|
14549 | 14797 | } else |
---|
14550 | 14798 | { |
---|
14551 | 14799 | if (x < startX) |
---|
.. | .. |
---|
14694 | 14942 | } |
---|
14695 | 14943 | } |
---|
14696 | 14944 | |
---|
| 14945 | +// ClickInfo clickInfo = new ClickInfo(); |
---|
| 14946 | + |
---|
14697 | 14947 | public void mouseMoved(MouseEvent e) |
---|
14698 | 14948 | { |
---|
14699 | 14949 | //System.out.println("mouseMoved: " + e); |
---|
14700 | 14950 | if (isRenderer) |
---|
14701 | 14951 | return; |
---|
14702 | 14952 | |
---|
14703 | | - ClickInfo ci = new ClickInfo(); |
---|
14704 | | - ci.x = e.getX(); |
---|
14705 | | - ci.y = e.getY(); |
---|
14706 | | - ci.modifiers = e.getModifiersEx(); |
---|
14707 | | - ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
14708 | | - ci.pane = this; |
---|
14709 | | - ci.camera = renderCamera; |
---|
| 14953 | + // Mouse cursor feedback |
---|
| 14954 | + object.clickInfo.x = e.getX(); |
---|
| 14955 | + object.clickInfo.y = e.getY(); |
---|
| 14956 | + object.clickInfo.modifiers = e.getModifiersEx(); |
---|
| 14957 | + object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
| 14958 | + object.clickInfo.pane = this; |
---|
| 14959 | + object.clickInfo.camera = renderCamera; |
---|
14710 | 14960 | if (!isRenderer) |
---|
14711 | 14961 | { |
---|
14712 | 14962 | //ObjEditor editWindow = object.editWindow; |
---|
14713 | 14963 | //Object3D copy = editWindow.copy; |
---|
14714 | | - if (object.doEditClick(ci, 0)) |
---|
| 14964 | + if (object.doEditClick(//clickInfo, |
---|
| 14965 | + 0)) |
---|
14715 | 14966 | { |
---|
14716 | 14967 | setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
---|
14717 | 14968 | } else |
---|
.. | .. |
---|
14726 | 14977 | Globals.MOUSEDRAGGED = false; |
---|
14727 | 14978 | |
---|
14728 | 14979 | movingcamera = false; |
---|
14729 | | - X = Y = 0; |
---|
| 14980 | + X = 0; // getBounds().width/2; |
---|
| 14981 | + Y = 0; // getBounds().height/2; |
---|
14730 | 14982 | //System.out.println("mouseReleased: " + e); |
---|
14731 | 14983 | clickEnd(e.getX(), e.getY(), e.getModifiersEx()); |
---|
14732 | 14984 | } |
---|
.. | .. |
---|
14982 | 15234 | // break; |
---|
14983 | 15235 | case 'T': |
---|
14984 | 15236 | CACHETEXTURE ^= true; |
---|
14985 | | - textures.clear(); |
---|
| 15237 | + texturepigment.clear(); |
---|
| 15238 | + texturebump.clear(); |
---|
14986 | 15239 | // repaint(); |
---|
14987 | 15240 | break; |
---|
14988 | 15241 | case 'Y': |
---|
.. | .. |
---|
15067 | 15320 | case 'E' : COMPACT ^= true; |
---|
15068 | 15321 | repaint(); |
---|
15069 | 15322 | break; |
---|
15070 | | - case 'W' : DEBUGHSB ^= true; |
---|
| 15323 | + case 'W' : // Wide Window (fullscreen) |
---|
| 15324 | + //DEBUGHSB ^= true; |
---|
| 15325 | + ObjEditor.theFrame.ToggleFullScreen(); |
---|
15071 | 15326 | repaint(); |
---|
15072 | 15327 | break; |
---|
15073 | 15328 | case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break; |
---|
.. | .. |
---|
15093 | 15348 | repaint(); |
---|
15094 | 15349 | break; |
---|
15095 | 15350 | case 'l': |
---|
15096 | | - lightMode ^= true; |
---|
15097 | | - Globals.lighttouched = true; |
---|
15098 | | - manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera; |
---|
15099 | | - targetLookAt.set(manipCamera.lookAt); |
---|
15100 | | - repaint(); |
---|
15101 | | - break; |
---|
15102 | | - case 'L': |
---|
| 15351 | + //case 'L': |
---|
15103 | 15352 | if (lightMode) |
---|
15104 | 15353 | { |
---|
15105 | 15354 | lightMode = false; |
---|
.. | .. |
---|
15163 | 15412 | OCCLUSION_CULLING ^= true; |
---|
15164 | 15413 | System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING); |
---|
15165 | 15414 | break; |
---|
15166 | | - case '0': envyoff ^= true; repaint(); break; |
---|
| 15415 | + //case '0': envyoff ^= true; repaint(); break; |
---|
15167 | 15416 | case '1': |
---|
15168 | 15417 | case '2': |
---|
15169 | 15418 | case '3': |
---|
15170 | 15419 | case '4': |
---|
15171 | 15420 | case '5': |
---|
15172 | | - newenvy = Character.getNumericValue(key); |
---|
15173 | | - repaint(); |
---|
15174 | | - break; |
---|
15175 | 15421 | case '6': |
---|
15176 | 15422 | case '7': |
---|
15177 | 15423 | case '8': |
---|
15178 | 15424 | case '9': |
---|
15179 | | - BGcolor = (key - '6')/3.f; |
---|
| 15425 | + if (true) // envyoff) |
---|
| 15426 | + { |
---|
| 15427 | + BGcolor = (key - '1')/8.f; |
---|
| 15428 | + } |
---|
| 15429 | + else |
---|
| 15430 | + { |
---|
| 15431 | + //newenvy = Character.getNumericValue(key); |
---|
| 15432 | + } |
---|
15180 | 15433 | repaint(); |
---|
15181 | 15434 | break; |
---|
15182 | 15435 | case '!': |
---|
.. | .. |
---|
15246 | 15499 | // kompactbit = 6; |
---|
15247 | 15500 | // break; |
---|
15248 | 15501 | case ' ': |
---|
15249 | | - ObjEditor.theFrame.ToggleFullScreen(); |
---|
| 15502 | + lightMode ^= true; |
---|
| 15503 | + Globals.lighttouched = true; |
---|
| 15504 | + manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera; |
---|
| 15505 | + targetLookAt.set(manipCamera.lookAt); |
---|
15250 | 15506 | repaint(); |
---|
15251 | 15507 | break; |
---|
15252 | 15508 | //case '`' : |
---|
.. | .. |
---|
15295 | 15551 | break; |
---|
15296 | 15552 | case '+': |
---|
15297 | 15553 | |
---|
15298 | | - //for (int i=0; i<0x7FFFFFFF; i++) |
---|
15299 | | - { |
---|
15300 | | - //String.format("%08X", i); // "7caca905" |
---|
15301 | | - GetRemoteZip("https://archive3d.net/?a=download&do=get&id=", "7caca905", true, true); |
---|
15302 | | - } |
---|
15303 | | - |
---|
15304 | 15554 | /* |
---|
15305 | 15555 | //fontsize += 1; |
---|
15306 | 15556 | bbzoom *= 2; |
---|
.. | .. |
---|
15318 | 15568 | case '=': |
---|
15319 | 15569 | IncDepth(); |
---|
15320 | 15570 | //fontsize += 1; |
---|
15321 | | - object.editWindow.refreshContents(true); |
---|
| 15571 | + object.GetWindow().refreshContents(true); |
---|
15322 | 15572 | maskbit = 6; |
---|
15323 | 15573 | break; |
---|
15324 | 15574 | case '-': //if (PixelThreshold>1) PixelThreshold /= 2; |
---|
15325 | 15575 | DecDepth(); |
---|
15326 | 15576 | maskbit = 5; |
---|
15327 | 15577 | //if(fontsize > 1) fontsize -= 1; |
---|
15328 | | - if (object.editWindow == null) |
---|
15329 | | - new Exception().printStackTrace(); |
---|
15330 | | - else |
---|
15331 | | - object.editWindow.refreshContents(true); |
---|
| 15578 | +// if (object.editWindow == null) |
---|
| 15579 | +// new Exception().printStackTrace(); |
---|
| 15580 | +// else |
---|
| 15581 | + object.GetWindow().refreshContents(true); |
---|
15332 | 15582 | break; |
---|
15333 | 15583 | case '{': |
---|
15334 | 15584 | manipCamera.shaper_fovy /= 1.1; |
---|
.. | .. |
---|
15552 | 15802 | } |
---|
15553 | 15803 | */ |
---|
15554 | 15804 | |
---|
15555 | | - object.editWindow.EditSelection(false); |
---|
| 15805 | + object.GetWindow().EditSelection(false); |
---|
15556 | 15806 | } |
---|
15557 | 15807 | |
---|
15558 | 15808 | void SelectParent() |
---|
.. | .. |
---|
15569 | 15819 | { |
---|
15570 | 15820 | //selectees.remove(i); |
---|
15571 | 15821 | System.out.println("select parent of " + elem); |
---|
15572 | | - group.editWindow.Select(elem.parent.GetTreePath(), first, true); |
---|
| 15822 | + group.GetWindow().Select(elem.parent.GetTreePath(), first, true); |
---|
15573 | 15823 | } else |
---|
15574 | 15824 | { |
---|
15575 | | - group.editWindow.Select(elem.GetTreePath(), first, true); |
---|
| 15825 | + group.GetWindow().Select(elem.GetTreePath(), first, true); |
---|
15576 | 15826 | } |
---|
15577 | 15827 | |
---|
15578 | 15828 | first = false; |
---|
.. | .. |
---|
15614 | 15864 | for (int j = 0; j < group.children.size(); j++) |
---|
15615 | 15865 | { |
---|
15616 | 15866 | elem = (Object3D) group.children.elementAt(j); |
---|
15617 | | - object.editWindow.Select(elem.GetTreePath(), first, true); |
---|
| 15867 | + object.GetWindow().Select(elem.GetTreePath(), first, true); |
---|
15618 | 15868 | first = false; |
---|
15619 | 15869 | } |
---|
15620 | 15870 | } else |
---|
15621 | 15871 | { |
---|
15622 | | - object.editWindow.Select(elem.GetTreePath(), first, true); |
---|
| 15872 | + object.GetWindow().Select(elem.GetTreePath(), first, true); |
---|
15623 | 15873 | } |
---|
15624 | 15874 | |
---|
15625 | 15875 | first = false; |
---|
.. | .. |
---|
15630 | 15880 | { |
---|
15631 | 15881 | //Composite group = (Composite) object; |
---|
15632 | 15882 | Object3D group = object; |
---|
15633 | | - group.editWindow.loadClipboard(true); // ClearSelection(false); |
---|
| 15883 | + group.GetWindow().loadClipboard(true); // ClearSelection(false); |
---|
15634 | 15884 | } |
---|
15635 | 15885 | |
---|
15636 | 15886 | void ResetTransform(int mask) |
---|
15637 | 15887 | { |
---|
15638 | 15888 | //Composite group = (Composite) object; |
---|
15639 | 15889 | Object3D group = object; |
---|
15640 | | - group.editWindow.ResetTransform(mask); |
---|
| 15890 | + group.GetWindow().ResetTransform(mask); |
---|
15641 | 15891 | } |
---|
15642 | 15892 | |
---|
15643 | 15893 | void FlipTransform() |
---|
15644 | 15894 | { |
---|
15645 | 15895 | //Composite group = (Composite) object; |
---|
15646 | 15896 | Object3D group = object; |
---|
15647 | | - group.editWindow.FlipTransform(); |
---|
| 15897 | + group.GetWindow().FlipTransform(); |
---|
15648 | 15898 | // group.editWindow.ReduceMesh(true); |
---|
15649 | 15899 | } |
---|
15650 | 15900 | |
---|
.. | .. |
---|
15652 | 15902 | { |
---|
15653 | 15903 | //Composite group = (Composite) object; |
---|
15654 | 15904 | Object3D group = object; |
---|
15655 | | - group.editWindow.PrintMemory(); |
---|
| 15905 | + group.GetWindow().PrintMemory(); |
---|
15656 | 15906 | // group.editWindow.ReduceMesh(true); |
---|
15657 | 15907 | } |
---|
15658 | 15908 | |
---|
.. | .. |
---|
15660 | 15910 | { |
---|
15661 | 15911 | //Composite group = (Composite) object; |
---|
15662 | 15912 | Object3D group = object; |
---|
15663 | | - group.editWindow.ResetCentroid(); |
---|
| 15913 | + group.GetWindow().ResetCentroid(); |
---|
15664 | 15914 | } |
---|
15665 | 15915 | |
---|
15666 | 15916 | void IncDepth() |
---|
.. | .. |
---|
15742 | 15992 | |
---|
15743 | 15993 | int width = getBounds().width; |
---|
15744 | 15994 | int height = getBounds().height; |
---|
15745 | | - ClickInfo info = new ClickInfo(); |
---|
15746 | | - info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom)); |
---|
15747 | 15995 | //Image img = CreateImage(width, height); |
---|
15748 | 15996 | //System.out.println("width = " + width + "; height = " + height + "\n"); |
---|
15749 | 15997 | |
---|
.. | .. |
---|
15820 | 16068 | } |
---|
15821 | 16069 | if (object != null && !hasMarquee) |
---|
15822 | 16070 | { |
---|
| 16071 | + if (object.clickInfo == null) |
---|
| 16072 | + object.clickInfo = new ClickInfo(); |
---|
| 16073 | + ClickInfo info = object.clickInfo; |
---|
| 16074 | + //ClickInfo info = new ClickInfo(); |
---|
| 16075 | + info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom)); |
---|
| 16076 | + |
---|
15823 | 16077 | if (isRenderer) |
---|
15824 | 16078 | { |
---|
15825 | | - info.flags++; |
---|
| 16079 | + object.clickInfo.flags++; |
---|
15826 | 16080 | double frameAspect = (double) width / (double) height; |
---|
15827 | 16081 | if (frameAspect > renderCamera.aspect) |
---|
15828 | 16082 | { |
---|
15829 | 16083 | int desired = (int) ((double) height * renderCamera.aspect); |
---|
15830 | | - info.bounds.width -= width - desired; |
---|
15831 | | - info.bounds.x += (width - desired) / 2; |
---|
| 16084 | + object.clickInfo.bounds.width -= width - desired; |
---|
| 16085 | + object.clickInfo.bounds.x += (width - desired) / 2; |
---|
15832 | 16086 | } else |
---|
15833 | 16087 | { |
---|
15834 | 16088 | int desired = (int) ((double) width / renderCamera.aspect); |
---|
15835 | | - info.bounds.height -= height - desired; |
---|
15836 | | - info.bounds.y += (height - desired) / 2; |
---|
| 16089 | + object.clickInfo.bounds.height -= height - desired; |
---|
| 16090 | + object.clickInfo.bounds.y += (height - desired) / 2; |
---|
15837 | 16091 | } |
---|
15838 | 16092 | } |
---|
15839 | | - info.g = gr; |
---|
15840 | | - info.camera = renderCamera; |
---|
| 16093 | + |
---|
| 16094 | + object.clickInfo.g = gr; |
---|
| 16095 | + object.clickInfo.camera = renderCamera; |
---|
15841 | 16096 | /* |
---|
15842 | 16097 | // Memory intensive (brep.verticescopy) |
---|
15843 | 16098 | if (!(object instanceof Composite)) |
---|
15844 | 16099 | object.draw(info, 0, false); // SLOW : |
---|
15845 | 16100 | */ |
---|
15846 | | - if (!isRenderer) |
---|
| 16101 | + if (!isRenderer) // && drag) |
---|
15847 | 16102 | { |
---|
15848 | | - object.drawEditHandles(info, 0); |
---|
15849 | | - |
---|
15850 | | - if (drag && (X != 0 || Y != 0) && object.selection.Size() > 0) |
---|
| 16103 | + Grafreed.Assert(object != null); |
---|
| 16104 | + Grafreed.Assert(object.selection != null); |
---|
| 16105 | + if (object.selection.Size() > 0) |
---|
15851 | 16106 | { |
---|
15852 | | - switch (object.selection.get(0).hitSomething) |
---|
| 16107 | + int hitSomething = object.selection.get(0).hitSomething; |
---|
| 16108 | + |
---|
| 16109 | + object.clickInfo.DX = 0; |
---|
| 16110 | + object.clickInfo.DY = 0; |
---|
| 16111 | + object.clickInfo.W = 1; |
---|
| 16112 | + if (hitSomething == Object3D.hitCenter) |
---|
15853 | 16113 | { |
---|
15854 | | - case Object3D.hitCenter: gr.setColor(Color.pink); |
---|
15855 | | - gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
15856 | | - break; |
---|
15857 | | - case Object3D.hitRotate: gr.setColor(Color.yellow); |
---|
15858 | | - gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
15859 | | - break; |
---|
15860 | | - case Object3D.hitScale: gr.setColor(Color.cyan); |
---|
15861 | | - gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
15862 | | - break; |
---|
| 16114 | + info.DX = X; |
---|
| 16115 | + if (X != 0) |
---|
| 16116 | + info.DX -= info.bounds.width/2; |
---|
| 16117 | + |
---|
| 16118 | + info.DY = Y; |
---|
| 16119 | + if (Y != 0) |
---|
| 16120 | + info.DY -= info.bounds.height/2; |
---|
15863 | 16121 | } |
---|
15864 | | - |
---|
| 16122 | + |
---|
| 16123 | + object.drawEditHandles(//info, |
---|
| 16124 | + 0); |
---|
| 16125 | + |
---|
| 16126 | + if (drag && (X != 0 || Y != 0)) |
---|
| 16127 | + { |
---|
| 16128 | + switch (hitSomething) |
---|
| 16129 | + { |
---|
| 16130 | + case Object3D.hitCenter: gr.setColor(Color.pink); |
---|
| 16131 | + gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
| 16132 | + break; |
---|
| 16133 | + case Object3D.hitRotate: gr.setColor(Color.yellow); |
---|
| 16134 | + gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
| 16135 | + break; |
---|
| 16136 | + case Object3D.hitScale: gr.setColor(Color.cyan); |
---|
| 16137 | + gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
| 16138 | + break; |
---|
| 16139 | + } |
---|
| 16140 | + |
---|
| 16141 | + } |
---|
15865 | 16142 | } |
---|
15866 | 16143 | } |
---|
15867 | 16144 | } |
---|
.. | .. |
---|
16343 | 16620 | private /*static*/ boolean firstime; |
---|
16344 | 16621 | private /*static*/ cVector newView = new cVector(); |
---|
16345 | 16622 | private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"}; |
---|
| 16623 | + private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"}; |
---|
| 16624 | + private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"}; |
---|
16346 | 16625 | private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X, |
---|
16347 | 16626 | GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X, |
---|
16348 | 16627 | GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y, |
---|
.. | .. |
---|
16355 | 16634 | { |
---|
16356 | 16635 | com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP); |
---|
16357 | 16636 | |
---|
| 16637 | + int usedsuf = 0; |
---|
| 16638 | + |
---|
16358 | 16639 | for (int i = 0; i < suffixes.length; i++) |
---|
16359 | 16640 | { |
---|
16360 | | - String resourceName = basename + suffixes[i] + "." + suffix; |
---|
16361 | | - TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
16362 | | - mipmapped, |
---|
16363 | | - FileUtil.getFileSuffix(resourceName)); |
---|
16364 | | - if (data == null) |
---|
| 16641 | + String[] suffixe = suffixes; |
---|
| 16642 | + String[] fallback = suffixes2; |
---|
| 16643 | + String[] fallfallback = suffixes3; |
---|
| 16644 | + |
---|
| 16645 | + for (int c=usedsuf; --c>=0;) |
---|
16365 | 16646 | { |
---|
16366 | | - throw new IOException("Unable to load texture " + resourceName); |
---|
| 16647 | +// String[] temp = suffixe; |
---|
| 16648 | +// suffixe = fallback; |
---|
| 16649 | +// fallback = fallfallback; |
---|
| 16650 | +// fallfallback = temp; |
---|
16367 | 16651 | } |
---|
| 16652 | + |
---|
| 16653 | + String resourceName = basename + suffixe[i] + "." + suffix; |
---|
| 16654 | + TextureData data; |
---|
| 16655 | + |
---|
| 16656 | + try |
---|
| 16657 | + { |
---|
| 16658 | + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
| 16659 | + mipmapped, |
---|
| 16660 | + FileUtil.getFileSuffix(resourceName)); |
---|
| 16661 | + } |
---|
| 16662 | + catch (Exception e) |
---|
| 16663 | + { |
---|
| 16664 | + try |
---|
| 16665 | + { |
---|
| 16666 | + resourceName = basename + fallback[i] + "." + suffix; |
---|
| 16667 | + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
| 16668 | + mipmapped, |
---|
| 16669 | + FileUtil.getFileSuffix(resourceName)); |
---|
| 16670 | + } |
---|
| 16671 | + catch (Exception e2) |
---|
| 16672 | + { |
---|
| 16673 | + resourceName = basename + fallfallback[i] + "." + suffix; |
---|
| 16674 | + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
| 16675 | + mipmapped, |
---|
| 16676 | + FileUtil.getFileSuffix(resourceName)); |
---|
| 16677 | + } |
---|
| 16678 | + } |
---|
| 16679 | + |
---|
16368 | 16680 | //System.out.println("Target = " + targets[i]); |
---|
16369 | 16681 | cubemap.updateImage(data, targets[i]); |
---|
16370 | 16682 | } |
---|
16371 | 16683 | |
---|
16372 | 16684 | return cubemap; |
---|
16373 | 16685 | } |
---|
| 16686 | + |
---|
16374 | 16687 | int bigsphere = -1; |
---|
16375 | 16688 | |
---|
16376 | 16689 | float BGcolor = 0.5f; |
---|
16377 | 16690 | |
---|
16378 | | - private void DrawSkyBox(GL gl) |
---|
| 16691 | + float ambientLight[] = {1f, 1f, 1f, 1.0f}; |
---|
| 16692 | + |
---|
| 16693 | + private void DrawSkyBox(GL gl, float ratio) |
---|
16379 | 16694 | { |
---|
16380 | | - if (envyoff || cubemap == null) |
---|
| 16695 | + if (//envyoff || |
---|
| 16696 | + WIREFRAME || |
---|
| 16697 | + cubemap == null) |
---|
16381 | 16698 | { |
---|
16382 | 16699 | gl.glClearColor(BGcolor, BGcolor, BGcolor, 1); |
---|
16383 | 16700 | gl.glClear(gl.GL_COLOR_BUFFER_BIT); |
---|
.. | .. |
---|
16392 | 16709 | // Compensates for ExaminerViewer's modification of modelview matrix |
---|
16393 | 16710 | gl.glMatrixMode(GL.GL_MODELVIEW); |
---|
16394 | 16711 | gl.glLoadIdentity(); |
---|
| 16712 | + gl.glScalef(1,ratio,1); |
---|
16395 | 16713 | |
---|
| 16714 | +// colorV[0] = 2; |
---|
| 16715 | +// colorV[1] = 2; |
---|
| 16716 | +// colorV[2] = 2; |
---|
| 16717 | +// colorV[3] = 1; |
---|
| 16718 | +// gl.glDisable(gl.GL_COLOR_MATERIAL); |
---|
| 16719 | +// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0); |
---|
| 16720 | +// |
---|
| 16721 | +// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0); |
---|
| 16722 | + |
---|
16396 | 16723 | //gl.glActiveTexture(GL.GL_TEXTURE1); |
---|
16397 | 16724 | //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP); |
---|
16398 | 16725 | |
---|
.. | .. |
---|
16424 | 16751 | { |
---|
16425 | 16752 | gl.glScalef(1.0f, -1.0f, 1.0f); |
---|
16426 | 16753 | } |
---|
| 16754 | + gl.glScalef(-1.0f, 1.0f, 1.0f); |
---|
16427 | 16755 | gl.glMultMatrixd(viewrot_1, 0); |
---|
16428 | 16756 | gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f); |
---|
16429 | 16757 | //viewer.updateInverseRotation(gl); |
---|
.. | .. |
---|
16464 | 16792 | gl.glDisable(GL.GL_TEXTURE_GEN_R); |
---|
16465 | 16793 | |
---|
16466 | 16794 | cubemap.disable(); |
---|
16467 | | - ////cubemap.unbind(); |
---|
| 16795 | + //cubemap.dispose(); |
---|
| 16796 | + |
---|
16468 | 16797 | if (CULLFACE) |
---|
16469 | 16798 | { |
---|
16470 | 16799 | gl.glEnable(gl.GL_CULL_FACE); |
---|
.. | .. |
---|
16659 | 16988 | } |
---|
16660 | 16989 | } |
---|
16661 | 16990 | |
---|
| 16991 | + private Object3D GetFolder() |
---|
| 16992 | + { |
---|
| 16993 | + Object3D folder = object.GetWindow().copy; |
---|
| 16994 | + if (object.GetWindow().copy.selection.Size() > 0) |
---|
| 16995 | + folder = object.GetWindow().copy.selection.elementAt(0); |
---|
| 16996 | + return folder; |
---|
| 16997 | + } |
---|
| 16998 | + |
---|
16662 | 16999 | class SelectBuffer implements GLEventListener |
---|
16663 | 17000 | { |
---|
16664 | 17001 | |
---|
.. | .. |
---|
16674 | 17011 | //new Exception().printStackTrace(); |
---|
16675 | 17012 | System.out.println("select buffer init"); |
---|
16676 | 17013 | // Use debug pipeline |
---|
16677 | | - drawable.setGL(new DebugGL(drawable.getGL())); |
---|
| 17014 | + //drawable.setGL(new DebugGL(drawable.getGL())); |
---|
16678 | 17015 | |
---|
16679 | 17016 | GL gl = drawable.getGL(); |
---|
16680 | 17017 | |
---|
.. | .. |
---|
16738 | 17075 | |
---|
16739 | 17076 | //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL); |
---|
16740 | 17077 | |
---|
| 17078 | + if (PAINTMODE) |
---|
| 17079 | + { |
---|
| 17080 | + if (object.GetWindow().copy.selection.Size() > 0) |
---|
| 17081 | + { |
---|
| 17082 | + Object3D paintobj = object.GetWindow().copy.selection.elementAt(0); |
---|
| 17083 | + |
---|
| 17084 | + // Make what you paint not selectable. |
---|
| 17085 | + paintobj.ResetSelectable(); |
---|
| 17086 | + } |
---|
| 17087 | + } |
---|
| 17088 | + |
---|
16741 | 17089 | //int tmp = selection_view; |
---|
16742 | 17090 | //selection_view = -1; |
---|
16743 | 17091 | int temp = DrawMode(); |
---|
.. | .. |
---|
16749 | 17097 | // temp = DEFAULT; // patch for selection debug |
---|
16750 | 17098 | Globals.drawMode = temp; // WARNING |
---|
16751 | 17099 | |
---|
| 17100 | + if (PAINTMODE) |
---|
| 17101 | + { |
---|
| 17102 | + if (object.GetWindow().copy.selection.Size() > 0) |
---|
| 17103 | + { |
---|
| 17104 | + Object3D paintobj = object.GetWindow().copy.selection.elementAt(0); |
---|
| 17105 | + |
---|
| 17106 | + // Revert. |
---|
| 17107 | + paintobj.RestoreSelectable(); |
---|
| 17108 | + } |
---|
| 17109 | + } |
---|
| 17110 | + |
---|
16752 | 17111 | //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view); |
---|
16753 | 17112 | |
---|
16754 | 17113 | // trying different ways of getting the depth info over |
---|
.. | .. |
---|
16852 | 17211 | } |
---|
16853 | 17212 | |
---|
16854 | 17213 | if (!movingcamera && !PAINTMODE) |
---|
16855 | | - object.editWindow.ScreenFitPoint(); // fev 2014 |
---|
| 17214 | + object.GetWindow().ScreenFitPoint(); // fev 2014 |
---|
16856 | 17215 | |
---|
16857 | | - if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0) |
---|
| 17216 | + if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0) |
---|
16858 | 17217 | { |
---|
16859 | | - Object3D paintobj = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0); |
---|
| 17218 | + //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0); |
---|
16860 | 17219 | |
---|
16861 | | - Object3D group = new Object3D("inst" + paintcount++); |
---|
| 17220 | + if (object.GetWindow().copy.selection.Size() > 0) |
---|
| 17221 | + { |
---|
| 17222 | + Object3D paintobj = object.GetWindow().copy.selection.elementAt(0); |
---|
16862 | 17223 | |
---|
16863 | | - group.CreateMaterial(); // use a void leaf to select instances |
---|
16864 | | - |
---|
16865 | | - group.add(paintobj); // link |
---|
16866 | | - |
---|
16867 | | - object.editWindow.SnapObject(group); |
---|
16868 | | - |
---|
16869 | | - Object3D folder = object.editWindow.copy; |
---|
16870 | | - |
---|
16871 | | - if (object.editWindow.copy.selection.Size() > 0) |
---|
16872 | | - folder = object.editWindow.copy.selection.elementAt(0); |
---|
16873 | | - |
---|
16874 | | - folder.add(group); |
---|
16875 | | - |
---|
16876 | | - object.editWindow.ResetModel(); |
---|
16877 | | - object.editWindow.refreshContents(); |
---|
| 17224 | + Object3D inst = new Object3D("inst" + paintcount++); |
---|
| 17225 | + |
---|
| 17226 | + inst.CreateMaterial(); // use a void leaf to select instances |
---|
| 17227 | + |
---|
| 17228 | + inst.add(paintobj); // link |
---|
| 17229 | + |
---|
| 17230 | + object.GetWindow().SnapObject(inst); |
---|
| 17231 | + |
---|
| 17232 | + Object3D folder = paintFolder; // GetFolder(); |
---|
| 17233 | + |
---|
| 17234 | + folder.add(inst); |
---|
| 17235 | + |
---|
| 17236 | + object.GetWindow().ResetModel(); |
---|
| 17237 | + object.GetWindow().refreshContents(); |
---|
| 17238 | + } |
---|
16878 | 17239 | } |
---|
16879 | 17240 | else |
---|
16880 | 17241 | paintcount = 0; |
---|
.. | .. |
---|
17196 | 17557 | gl.glFlush(); |
---|
17197 | 17558 | |
---|
17198 | 17559 | /**/ |
---|
17199 | | - gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer); |
---|
| 17560 | + gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer); |
---|
17200 | 17561 | |
---|
17201 | | - float[] pixels = occlusionsizebuffer.array(); |
---|
| 17562 | + float[] depths = occlusiondepthbuffer.array(); |
---|
17202 | 17563 | |
---|
| 17564 | + gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer); |
---|
| 17565 | + |
---|
| 17566 | + int[] pixels = selectsizebuffer.array(); |
---|
| 17567 | + |
---|
17203 | 17568 | double r = 0, g = 0, b = 0; |
---|
17204 | 17569 | |
---|
17205 | 17570 | double count = 0; |
---|
.. | .. |
---|
17210 | 17575 | |
---|
17211 | 17576 | double FACTOR = 1; |
---|
17212 | 17577 | |
---|
17213 | | - for (int i = 0; i < pixels.length; i++) |
---|
| 17578 | + for (int i = 0; i < depths.length; i++) |
---|
17214 | 17579 | { |
---|
17215 | 17580 | int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2; |
---|
17216 | 17581 | int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2; |
---|
.. | .. |
---|
17293 | 17658 | |
---|
17294 | 17659 | double scale = ray.z; // 1; // cos |
---|
17295 | 17660 | |
---|
17296 | | - float depth = pixels[newindex]; |
---|
| 17661 | + float depth = depths[newindex]; |
---|
17297 | 17662 | |
---|
17298 | 17663 | /* |
---|
17299 | 17664 | int newindex2 = (x + 1) * OCCLUSION_SIZE + y; |
---|
.. | .. |
---|
17490 | 17855 | static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE); |
---|
17491 | 17856 | static IntBuffer bigAAbuffer; |
---|
17492 | 17857 | static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3); |
---|
17493 | | - static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE); |
---|
| 17858 | + //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE); |
---|
17494 | 17859 | static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE); |
---|
17495 | 17860 | static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE); |
---|
17496 | 17861 | //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); |
---|
17497 | | - static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); |
---|
| 17862 | + static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); |
---|
| 17863 | + |
---|
| 17864 | + static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); |
---|
| 17865 | + |
---|
17498 | 17866 | static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB); |
---|
17499 | 17867 | static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); |
---|
17500 | 17868 | static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>(); |
---|