.. | .. |
---|
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 | { |
---|
.. | .. |
---|
37 | 41 | static boolean[] selectedstack = new boolean[65536]; |
---|
38 | 42 | static int materialdepth = 0; |
---|
39 | 43 | |
---|
40 | | - static boolean DEBUG = false; |
---|
41 | 44 | static boolean FRUSTUM = false; // still bogus true; // frustum culling |
---|
42 | 45 | |
---|
43 | 46 | // camera change fix |
---|
.. | .. |
---|
45 | 48 | static boolean ABORTED = false; |
---|
46 | 49 | |
---|
47 | 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 | + } |
---|
48 | 84 | |
---|
49 | 85 | /*static*/ private boolean CULLFACE = false; // true; |
---|
50 | 86 | /*static*/ boolean NEAREST = false; // true; |
---|
.. | .. |
---|
61 | 97 | //boolean REDUCETEXTURE = true; |
---|
62 | 98 | boolean CACHETEXTURE = true; |
---|
63 | 99 | boolean CLEANCACHE = false; // true; |
---|
64 | | - boolean MIPMAP = false; // true; |
---|
| 100 | + boolean MIPMAP = false; // true; // never works... |
---|
65 | 101 | boolean COMPRESSTEXTURE = false; |
---|
66 | 102 | boolean KOMPACTTEXTURE = false; // true; |
---|
67 | 103 | boolean RESIZETEXTURE = false; |
---|
.. | .. |
---|
74 | 110 | //private Mat4f spotlightTransform = new Mat4f(); |
---|
75 | 111 | //private Mat4f spotlightInverseTransform = new Mat4f(); |
---|
76 | 112 | static GLContext glcontext = null; |
---|
77 | | - /*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 | + |
---|
78 | 118 | boolean reverseUP = false; |
---|
79 | 119 | static boolean frozen = false; |
---|
80 | 120 | boolean enablebackspace = false; // patch for back buffer refresh |
---|
.. | .. |
---|
128 | 168 | |
---|
129 | 169 | |
---|
130 | 170 | // OPTIONS |
---|
131 | | - boolean Skinshader = true; |
---|
| 171 | + boolean Skinshader = false; // true; |
---|
132 | 172 | boolean cameraLight = false; |
---|
133 | 173 | boolean UVdebug = false; |
---|
134 | 174 | boolean Udebug = false; |
---|
.. | .. |
---|
137 | 177 | static boolean doublesided = false; // true; // reversed normals are awful for conformance |
---|
138 | 178 | boolean anisotropy = true; |
---|
139 | 179 | boolean softshadow = true; // slower but better false; |
---|
140 | | - boolean opacityhalo = false; |
---|
| 180 | + boolean opacityhalo = false; // reverse the halo effect (e.g. glass) |
---|
141 | 181 | |
---|
142 | 182 | boolean macromode = false; |
---|
143 | 183 | |
---|
.. | .. |
---|
151 | 191 | } |
---|
152 | 192 | |
---|
153 | 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 | + } |
---|
154 | 207 | |
---|
155 | 208 | void SetAsGLRenderer(boolean b) |
---|
156 | 209 | { |
---|
.. | .. |
---|
170 | 223 | |
---|
171 | 224 | SetCamera(cam); |
---|
172 | 225 | |
---|
173 | | - SetLight(new Camera(new cVector(10, 10, -20))); |
---|
| 226 | + // Warning: not used. |
---|
| 227 | + SetLight(new Camera(new cVector(15, 10, -20))); |
---|
174 | 228 | |
---|
175 | 229 | object = o; |
---|
176 | 230 | |
---|
.. | .. |
---|
327 | 381 | cStatic.objectstack[materialdepth++] = obj; |
---|
328 | 382 | //System.out.println("material " + material); |
---|
329 | 383 | //Applet3D.tracein(this, selected); |
---|
330 | | - display.vector2buffer = obj.projectedVertices; |
---|
| 384 | + //display.vector2buffer = obj.projectedVertices; |
---|
331 | 385 | if (obj instanceof Camera) |
---|
332 | 386 | { |
---|
333 | 387 | display.options1[0] = material.shift; |
---|
.. | .. |
---|
336 | 390 | display.options1[2] = material.shadowbias; |
---|
337 | 391 | display.options1[3] = material.aniso; |
---|
338 | 392 | display.options1[4] = material.anisoV; |
---|
| 393 | +// System.out.println("display.options1[0] " + display.options1[0]); |
---|
| 394 | +// System.out.println("display.options1[1] " + display.options1[1]); |
---|
| 395 | +// System.out.println("display.options1[2] " + display.options1[2]); |
---|
| 396 | +// System.out.println("display.options1[3] " + display.options1[3]); |
---|
| 397 | +// System.out.println("display.options1[4] " + display.options1[4]); |
---|
339 | 398 | display.options2[0] = material.opacity; |
---|
340 | 399 | display.options2[1] = material.diffuse; |
---|
341 | 400 | display.options2[2] = material.factor; |
---|
| 401 | +// System.out.println("display.options2[0] " + display.options2[0]); |
---|
| 402 | +// System.out.println("display.options2[1] " + display.options2[1]); |
---|
| 403 | +// System.out.println("display.options2[2] " + display.options2[2]); |
---|
342 | 404 | |
---|
343 | 405 | cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3); |
---|
| 406 | +// System.out.println("display.options3[0] " + display.options3[0]); |
---|
| 407 | +// System.out.println("display.options3[1] " + display.options3[1]); |
---|
| 408 | +// System.out.println("display.options3[2] " + display.options3[2]); |
---|
344 | 409 | display.options4[0] = material.cameralight/0.2f; |
---|
345 | 410 | display.options4[1] = material.subsurface; |
---|
346 | 411 | display.options4[2] = material.sheen; |
---|
| 412 | +// System.out.println("display.options4[0] " + display.options4[0]); |
---|
| 413 | +// System.out.println("display.options4[1] " + display.options4[1]); |
---|
| 414 | +// System.out.println("display.options4[2] " + display.options4[2]); |
---|
347 | 415 | |
---|
348 | 416 | // if (display.CURRENTANTIALIAS > 0) |
---|
349 | 417 | // display.options3[3] /= 4; |
---|
.. | .. |
---|
359 | 427 | /**/ |
---|
360 | 428 | } else |
---|
361 | 429 | { |
---|
362 | | - DrawMaterial(material, selected); |
---|
| 430 | + DrawMaterial(material, selected, obj.projectedVertices); |
---|
363 | 431 | } |
---|
364 | 432 | } else |
---|
365 | 433 | { |
---|
.. | .. |
---|
383 | 451 | cStatic.objectstack[materialdepth++] = obj; |
---|
384 | 452 | //System.out.println("material " + material); |
---|
385 | 453 | //Applet3D.tracein("selected ", selected); |
---|
386 | | - display.vector2buffer = obj.projectedVertices; |
---|
387 | | - display.DrawMaterial(material, selected); |
---|
| 454 | + //display.vector2buffer = obj.projectedVertices; |
---|
| 455 | + display.DrawMaterial(material, selected, obj.projectedVertices); |
---|
388 | 456 | } |
---|
389 | 457 | } |
---|
390 | 458 | |
---|
.. | .. |
---|
401 | 469 | materialdepth -= 1; |
---|
402 | 470 | if (materialdepth > 0) |
---|
403 | 471 | { |
---|
404 | | - display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices; |
---|
405 | | - display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]); |
---|
| 472 | + //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices; |
---|
| 473 | + display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices); |
---|
406 | 474 | } |
---|
407 | 475 | //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???"); |
---|
408 | 476 | } else if (selected && CameraPane.flash && obj.GetMaterial() != null) |
---|
.. | .. |
---|
422 | 490 | materialdepth -= 1; |
---|
423 | 491 | if (materialdepth > 0) |
---|
424 | 492 | { |
---|
425 | | - display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices; |
---|
426 | | - display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]); |
---|
| 493 | + //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices; |
---|
| 494 | + display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices); |
---|
427 | 495 | } |
---|
428 | 496 | //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???"); |
---|
429 | 497 | //else |
---|
.. | .. |
---|
1434 | 1502 | gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z); |
---|
1435 | 1503 | } |
---|
1436 | 1504 | |
---|
| 1505 | + float[] colorV = new float[4]; |
---|
| 1506 | + |
---|
1437 | 1507 | void SetColor(Object3D obj, Vertex p0) |
---|
1438 | 1508 | { |
---|
1439 | 1509 | CameraPane display = this; |
---|
.. | .. |
---|
1501 | 1571 | { |
---|
1502 | 1572 | return; |
---|
1503 | 1573 | } |
---|
1504 | | - |
---|
1505 | | - float[] colorV = new float[3]; |
---|
1506 | 1574 | |
---|
1507 | 1575 | if (false) // marked) |
---|
1508 | 1576 | { |
---|
.. | .. |
---|
1611 | 1679 | // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0); |
---|
1612 | 1680 | } |
---|
1613 | 1681 | |
---|
1614 | | - void DrawMaterial(cMaterial material, boolean selected) |
---|
| 1682 | + void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others) |
---|
1615 | 1683 | { |
---|
1616 | 1684 | CameraPane display = this; |
---|
1617 | 1685 | //new Exception().printStackTrace(); |
---|
.. | .. |
---|
1646 | 1714 | colorV[0] = display.modelParams0[0] * material.diffuse; |
---|
1647 | 1715 | colorV[1] = display.modelParams0[1] * material.diffuse; |
---|
1648 | 1716 | colorV[2] = display.modelParams0[2] * material.diffuse; |
---|
1649 | | - colorV[3] = material.opacity; |
---|
| 1717 | + colorV[3] = 1; // material.opacity; |
---|
1650 | 1718 | |
---|
1651 | 1719 | gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity); |
---|
1652 | 1720 | //System.out.println("Opacity = " + opacity); |
---|
.. | .. |
---|
1751 | 1819 | |
---|
1752 | 1820 | display.modelParams7[0] = 0; |
---|
1753 | 1821 | display.modelParams7[1] = 1000; |
---|
1754 | | - display.modelParams7[2] = 0; |
---|
| 1822 | + display.modelParams7[2] = material.parallax; |
---|
1755 | 1823 | display.modelParams7[3] = 0; |
---|
1756 | 1824 | |
---|
1757 | | - display.modelParams6[0] = 100; // criss de bug de bump |
---|
| 1825 | + //display.modelParams6[0] = 100; // criss de bug de bump |
---|
1758 | 1826 | |
---|
1759 | | - Object3D.cVector2[] extparams = display.vector2buffer; |
---|
| 1827 | + Object3D.cVector2[] extparams = others; // display.vector2buffer; |
---|
1760 | 1828 | if (extparams != null && extparams.length > 0 && extparams[0] != null) |
---|
1761 | 1829 | { |
---|
1762 | 1830 | display.modelParams6[0] = extparams[0].x / 1000.0f; // bump |
---|
.. | .. |
---|
1984 | 2052 | switch(viewcode) |
---|
1985 | 2053 | { |
---|
1986 | 2054 | case 0: return "main"; |
---|
1987 | | - case 1: return "one"; |
---|
1988 | | - case 2: return "two"; |
---|
1989 | | - case 3: return "three"; |
---|
| 2055 | + case 1: return "Red"; |
---|
| 2056 | + case 2: return "Green"; |
---|
| 2057 | + case 3: return "Blue"; |
---|
1990 | 2058 | case 4: return "light"; |
---|
1991 | 2059 | } |
---|
1992 | 2060 | |
---|
.. | .. |
---|
2052 | 2120 | //System.err.println("Oeil on"); |
---|
2053 | 2121 | OEIL = true; |
---|
2054 | 2122 | if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode) |
---|
2055 | | - object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK); |
---|
| 2123 | + object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK); |
---|
2056 | 2124 | //pingthread.StepToTarget(true); |
---|
2057 | 2125 | } |
---|
2058 | 2126 | |
---|
.. | .. |
---|
2267 | 2335 | |
---|
2268 | 2336 | void ToggleDebug() |
---|
2269 | 2337 | { |
---|
2270 | | - DEBUG ^= true; |
---|
| 2338 | + Globals.DEBUG ^= true; |
---|
2271 | 2339 | } |
---|
2272 | 2340 | |
---|
2273 | 2341 | void ToggleLookAt() |
---|
.. | .. |
---|
2285 | 2353 | HANDLES ^= true; |
---|
2286 | 2354 | } |
---|
2287 | 2355 | |
---|
| 2356 | + Object3D paintFolder; |
---|
| 2357 | + |
---|
2288 | 2358 | void TogglePaint() |
---|
2289 | 2359 | { |
---|
2290 | 2360 | PAINTMODE ^= true; |
---|
2291 | 2361 | paintcount = 0; |
---|
| 2362 | + |
---|
| 2363 | + if (PAINTMODE) |
---|
| 2364 | + { |
---|
| 2365 | + paintFolder = GetFolder(); |
---|
| 2366 | + } |
---|
2292 | 2367 | } |
---|
2293 | 2368 | |
---|
2294 | 2369 | void SwapCamera(int a, int b) |
---|
.. | .. |
---|
2385 | 2460 | return currentGL; |
---|
2386 | 2461 | } |
---|
2387 | 2462 | |
---|
| 2463 | + static private BufferedImage CreateBim(TextureData texturedata) |
---|
| 2464 | + { |
---|
| 2465 | + Grafreed.Assert(texturedata != null); |
---|
| 2466 | + |
---|
| 2467 | + int width = texturedata.getWidth(); |
---|
| 2468 | + int height = texturedata.getHeight(); |
---|
| 2469 | + |
---|
| 2470 | + Buffer buffer = texturedata.getBuffer(); |
---|
| 2471 | + ByteBuffer bytebuf = (ByteBuffer)buffer; |
---|
| 2472 | + |
---|
| 2473 | + byte[] bytes = bytebuf.array(); |
---|
| 2474 | + |
---|
| 2475 | + return CreateBim(bytes, width, height); |
---|
| 2476 | + } |
---|
| 2477 | + |
---|
2388 | 2478 | /**/ |
---|
2389 | 2479 | class CacheTexture |
---|
2390 | 2480 | { |
---|
.. | .. |
---|
2393 | 2483 | |
---|
2394 | 2484 | int resolution; |
---|
2395 | 2485 | |
---|
2396 | | - CacheTexture(com.sun.opengl.util.texture.Texture tex, int res) |
---|
| 2486 | + CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res) |
---|
2397 | 2487 | { |
---|
2398 | | - texture = tex; |
---|
| 2488 | + texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata); |
---|
| 2489 | + texturedata = texdata; |
---|
2399 | 2490 | resolution = res; |
---|
2400 | 2491 | } |
---|
2401 | 2492 | } |
---|
2402 | 2493 | /**/ |
---|
2403 | 2494 | |
---|
2404 | 2495 | // TEXTURE static Texture texture; |
---|
2405 | | - static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures |
---|
2406 | | - = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>(); |
---|
2407 | | - 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 | + |
---|
2408 | 2501 | int pigmentdepth = 0; |
---|
2409 | 2502 | public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536]; |
---|
2410 | 2503 | int bumpdepth = 0; |
---|
2411 | 2504 | public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536]; |
---|
2412 | 2505 | //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE"; |
---|
2413 | 2506 | public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP"); |
---|
2414 | | - public static String NOISE_TEXTURE = "WHITE_NOISE"; |
---|
| 2507 | + public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:"); |
---|
2415 | 2508 | // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL"); |
---|
2416 | 2509 | |
---|
2417 | | - com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump) |
---|
| 2510 | + com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump) |
---|
2418 | 2511 | { |
---|
2419 | 2512 | TextureData texturedata = null; |
---|
2420 | 2513 | |
---|
.. | .. |
---|
2424 | 2517 | com.sun.opengl.util.texture.TextureIO.newTextureData( |
---|
2425 | 2518 | getClass().getClassLoader().getResourceAsStream(name), |
---|
2426 | 2519 | true, |
---|
2427 | | - com.sun.opengl.util.texture.TextureIO.PNG); |
---|
| 2520 | + GetFormat(name)); // com.sun.opengl.util.texture.TextureIO.PNG); |
---|
2428 | 2521 | } catch (java.io.IOException e) |
---|
2429 | 2522 | { |
---|
2430 | 2523 | throw new javax.media.opengl.GLException(e); |
---|
.. | .. |
---|
2433 | 2526 | if (bump) |
---|
2434 | 2527 | texturedata = ConvertBump(texturedata, false); |
---|
2435 | 2528 | |
---|
2436 | | - com.sun.opengl.util.texture.Texture texture = |
---|
2437 | | - 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); |
---|
2438 | 2531 | |
---|
2439 | | - texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT); |
---|
2440 | | - 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); |
---|
2441 | 2534 | |
---|
2442 | | - 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; |
---|
2443 | 2557 | } |
---|
2444 | 2558 | |
---|
2445 | 2559 | boolean HUESMOOTH = true; // wrap around bug... true; |
---|
.. | .. |
---|
3512 | 3626 | |
---|
3513 | 3627 | System.out.println("LOADING TEXTURE : " + name); |
---|
3514 | 3628 | |
---|
| 3629 | + Object x = texturedata.getMipmapData(); // .getBuffer(); |
---|
| 3630 | + |
---|
3515 | 3631 | // |
---|
3516 | 3632 | if (false) // compressbit > 0) |
---|
3517 | 3633 | { |
---|
.. | .. |
---|
7910 | 8026 | String pigment = Object3D.GetPigment(tex); |
---|
7911 | 8027 | String bump = Object3D.GetBump(tex); |
---|
7912 | 8028 | |
---|
7913 | | - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8029 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
7914 | 8030 | { |
---|
7915 | 8031 | // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment); |
---|
7916 | 8032 | // System.out.println("; bump = " + bump); |
---|
.. | .. |
---|
7925 | 8041 | pigment = null; |
---|
7926 | 8042 | } |
---|
7927 | 8043 | |
---|
7928 | | - ReleaseTexture(bump, true); |
---|
7929 | | - ReleaseTexture(pigment, false); |
---|
| 8044 | + ReleaseTexture(tex, true); |
---|
| 8045 | + ReleaseTexture(tex, false); |
---|
7930 | 8046 | } |
---|
7931 | 8047 | |
---|
7932 | 8048 | public void ReleasePigmentTexture(cTexture tex) // INTERFACE |
---|
.. | .. |
---|
7944 | 8060 | |
---|
7945 | 8061 | String pigment = Object3D.GetPigment(tex); |
---|
7946 | 8062 | |
---|
7947 | | - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8063 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
7948 | 8064 | { |
---|
7949 | 8065 | // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment); |
---|
7950 | 8066 | // System.out.println("; bump = " + bump); |
---|
.. | .. |
---|
7955 | 8071 | pigment = null; |
---|
7956 | 8072 | } |
---|
7957 | 8073 | |
---|
7958 | | - ReleaseTexture(pigment, false); |
---|
| 8074 | + ReleaseTexture(tex, false); |
---|
7959 | 8075 | } |
---|
7960 | 8076 | |
---|
7961 | 8077 | public void ReleaseBumpTexture(cTexture tex) // INTERFACE |
---|
.. | .. |
---|
7973 | 8089 | |
---|
7974 | 8090 | String bump = Object3D.GetBump(tex); |
---|
7975 | 8091 | |
---|
7976 | | - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8092 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
7977 | 8093 | { |
---|
7978 | 8094 | // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment); |
---|
7979 | 8095 | // System.out.println("; bump = " + bump); |
---|
.. | .. |
---|
7984 | 8100 | bump = null; |
---|
7985 | 8101 | } |
---|
7986 | 8102 | |
---|
7987 | | - ReleaseTexture(bump, true); |
---|
| 8103 | + ReleaseTexture(tex, true); |
---|
7988 | 8104 | } |
---|
7989 | 8105 | |
---|
7990 | | - void ReleaseTexture(String tex, boolean bump) |
---|
| 8106 | + void ReleaseTexture(cTexture tex, boolean bump) |
---|
7991 | 8107 | { |
---|
7992 | 8108 | if (// DrawMode() != 0 || /*tex == null ||*/ |
---|
7993 | 8109 | ambientOcclusion ) // || !textureon) |
---|
.. | .. |
---|
7998 | 8114 | CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null; |
---|
7999 | 8115 | |
---|
8000 | 8116 | if (tex != null) |
---|
8001 | | - texture = textures.get(tex); |
---|
| 8117 | + texture = bump ? texturebump.get(tex) : texturepigment.get(tex); |
---|
8002 | 8118 | |
---|
8003 | 8119 | // //assert( texture != null ); |
---|
8004 | 8120 | // if (texture == null) |
---|
.. | .. |
---|
8092 | 8208 | |
---|
8093 | 8209 | /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE |
---|
8094 | 8210 | { |
---|
8095 | | - if (// DrawMode() != 0 || /*tex == null ||*/ |
---|
8096 | | - ambientOcclusion ) // || !textureon) |
---|
8097 | | - { |
---|
8098 | | - return; // false; |
---|
8099 | | - } |
---|
8100 | | - |
---|
8101 | | - if (tex == null) |
---|
8102 | | - { |
---|
8103 | | - BindTexture(null,false,resolution); |
---|
8104 | | - BindTexture(null,true,resolution); |
---|
8105 | | - return; |
---|
8106 | | - } |
---|
| 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; |
---|
8107 | 8252 | |
---|
8108 | | - String pigment = Object3D.GetPigment(tex); |
---|
8109 | | - String bump = Object3D.GetBump(tex); |
---|
8110 | | - |
---|
8111 | | - usedtextures.put(pigment, pigment); |
---|
8112 | | - usedtextures.put(bump, bump); |
---|
8113 | | - |
---|
8114 | | - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
8115 | | - { |
---|
8116 | | - // System.out.print("BIND +++++++++++++++ pigment = " + pigment); |
---|
8117 | | - // System.out.println("; bump = " + bump); |
---|
8118 | | - } |
---|
8119 | | - |
---|
8120 | | - if (bump.equals("")) |
---|
8121 | | - { |
---|
8122 | | - bump = null; |
---|
8123 | | - } |
---|
8124 | | - if (pigment.equals("")) |
---|
8125 | | - { |
---|
8126 | | - pigment = null; |
---|
8127 | | - } |
---|
8128 | | - |
---|
8129 | | - GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
8130 | | - BindTexture(pigment, false, resolution); |
---|
8131 | | - GetGL().glActiveTexture(GetGL().GL_TEXTURE2); |
---|
8132 | | - BindTexture(bump, true, resolution); |
---|
8133 | | - GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
8134 | | - |
---|
8135 | | - return; // true; |
---|
| 8253 | + BindPigmentTexture(tex, resolution); |
---|
| 8254 | + BindBumpTexture(tex, resolution); |
---|
8136 | 8255 | } |
---|
8137 | 8256 | |
---|
8138 | 8257 | /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE |
---|
.. | .. |
---|
8151 | 8270 | |
---|
8152 | 8271 | String pigment = Object3D.GetPigment(tex); |
---|
8153 | 8272 | |
---|
8154 | | - usedtextures.put(pigment, pigment); |
---|
| 8273 | + usedtextures.add(tex); |
---|
8155 | 8274 | |
---|
8156 | | - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8275 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
8157 | 8276 | { |
---|
8158 | 8277 | // System.out.print("BIND +++++++++++++++ pigment = " + pigment); |
---|
8159 | 8278 | // System.out.println("; bump = " + bump); |
---|
.. | .. |
---|
8165 | 8284 | } |
---|
8166 | 8285 | |
---|
8167 | 8286 | GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
8168 | | - BindTexture(pigment, false, resolution); |
---|
| 8287 | + BindTexture(tex, false, resolution); |
---|
8169 | 8288 | } |
---|
8170 | 8289 | |
---|
8171 | 8290 | /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE |
---|
.. | .. |
---|
8184 | 8303 | |
---|
8185 | 8304 | String bump = Object3D.GetBump(tex); |
---|
8186 | 8305 | |
---|
8187 | | - usedtextures.put(bump, bump); |
---|
| 8306 | + usedtextures.add(tex); |
---|
8188 | 8307 | |
---|
8189 | | - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8308 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
8190 | 8309 | { |
---|
8191 | 8310 | // System.out.print("BIND +++++++++++++++ pigment = " + pigment); |
---|
8192 | 8311 | // System.out.println("; bump = " + bump); |
---|
.. | .. |
---|
8198 | 8317 | } |
---|
8199 | 8318 | |
---|
8200 | 8319 | GetGL().glActiveTexture(GetGL().GL_TEXTURE2); |
---|
8201 | | - BindTexture(bump, true, resolution); |
---|
| 8320 | + BindTexture(tex, true, resolution); |
---|
8202 | 8321 | GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
8203 | 8322 | } |
---|
8204 | 8323 | |
---|
.. | .. |
---|
8222 | 8341 | return fileExists; |
---|
8223 | 8342 | } |
---|
8224 | 8343 | |
---|
8225 | | - CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception |
---|
| 8344 | + CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8226 | 8345 | { |
---|
8227 | | - CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null; |
---|
| 8346 | + CacheTexture texturecache = null; |
---|
8228 | 8347 | |
---|
8229 | 8348 | if (tex != null) |
---|
8230 | 8349 | { |
---|
8231 | | - 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 | + } |
---|
8232 | 8357 | |
---|
8233 | 8358 | String fallbackTextureName = defaultDirectory + "/Textures/" + texname; |
---|
8234 | 8359 | |
---|
.. | .. |
---|
8238 | 8363 | // else |
---|
8239 | 8364 | // if (!texname.startsWith("/")) |
---|
8240 | 8365 | // texname = "/Users/nbriere/Textures/" + texname; |
---|
8241 | | - if (!FileExists(tex)) |
---|
| 8366 | + if (!FileExists(texname) && !texname.startsWith("@")) |
---|
8242 | 8367 | { |
---|
8243 | 8368 | texname = fallbackTextureName; |
---|
8244 | 8369 | } |
---|
8245 | 8370 | |
---|
8246 | 8371 | if (CACHETEXTURE) |
---|
8247 | | - texture = textures.get(texname); // TEXTURE CACHE |
---|
8248 | | - |
---|
8249 | | - TextureData texturedata = null; |
---|
8250 | | - |
---|
8251 | | - if (texture == null || texture.resolution < resolution) |
---|
8252 | 8372 | { |
---|
8253 | | - 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("")) |
---|
8254 | 8406 | { |
---|
8255 | 8407 | assert(!bump); |
---|
8256 | 8408 | // if (bump) |
---|
.. | .. |
---|
8261 | 8413 | // } |
---|
8262 | 8414 | // else |
---|
8263 | 8415 | // { |
---|
8264 | | - texture = textures.get(tex); |
---|
8265 | | - if (texture == null) |
---|
| 8416 | + // texturecache = textures.get(texname); // suspicious |
---|
| 8417 | + if (texturecache == null) |
---|
8266 | 8418 | { |
---|
8267 | | - texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
| 8419 | + texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
8268 | 8420 | } |
---|
| 8421 | + else |
---|
| 8422 | + new Exception().printStackTrace(); |
---|
8269 | 8423 | // } |
---|
8270 | 8424 | } else |
---|
8271 | | - if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals("")) |
---|
| 8425 | + if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals("")) |
---|
8272 | 8426 | { |
---|
8273 | 8427 | assert(bump); |
---|
8274 | | - texture = textures.get(tex); |
---|
8275 | | - if (texture == null) |
---|
8276 | | - 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(); |
---|
8277 | 8433 | } else |
---|
8278 | 8434 | { |
---|
8279 | 8435 | //if (tex.equals("IMMORTAL")) |
---|
.. | .. |
---|
8281 | 8437 | // texture = GetResourceTexture("default.png"); |
---|
8282 | 8438 | //} else |
---|
8283 | 8439 | //{ |
---|
8284 | | - if (tex.equals("WHITE_NOISE")) |
---|
| 8440 | + if (texname.endsWith("WHITE_NOISE")) |
---|
8285 | 8441 | { |
---|
8286 | | - texture = textures.get(tex); |
---|
8287 | | - if (texture == null) |
---|
8288 | | - 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(); |
---|
8289 | 8456 | } else |
---|
8290 | 8457 | { |
---|
8291 | 8458 | if (textureon) |
---|
.. | .. |
---|
8344 | 8511 | if (texturedata == null) |
---|
8345 | 8512 | throw new Exception(); |
---|
8346 | 8513 | |
---|
8347 | | - texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution); |
---|
| 8514 | + texturecache = new CacheTexture(texturedata,resolution); |
---|
8348 | 8515 | //texture = GetTexture(tex, bump); |
---|
8349 | 8516 | } |
---|
| 8517 | + } |
---|
8350 | 8518 | } |
---|
8351 | 8519 | //} |
---|
8352 | 8520 | } |
---|
8353 | 8521 | |
---|
8354 | | - if (/*CACHETEXTURE &&*/ texture != null && textureon) |
---|
| 8522 | + if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon) |
---|
8355 | 8523 | { |
---|
8356 | 8524 | //return false; |
---|
8357 | 8525 | |
---|
8358 | 8526 | // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")"); |
---|
8359 | | - if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG"))) |
---|
| 8527 | + if (texturedata != null && texname.toLowerCase().endsWith(".jpg")) |
---|
8360 | 8528 | { |
---|
8361 | 8529 | // String ext = "_highres"; |
---|
8362 | 8530 | // if (REDUCETEXTURE) |
---|
.. | .. |
---|
8373 | 8541 | File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg"); |
---|
8374 | 8542 | if (!cachefile.exists()) |
---|
8375 | 8543 | { |
---|
8376 | | - // cache to disk |
---|
8377 | | - Buffer buffer = texturedata.getBuffer(); // getMipmapData(); |
---|
8378 | | - //buffers[0]. |
---|
8379 | | - |
---|
8380 | | - ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer(); |
---|
8381 | | - int[] pixels = new int[bytebuf.capacity()/3]; |
---|
8382 | | - |
---|
8383 | | - // squared size heuristic... |
---|
8384 | | - if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length)) |
---|
| 8544 | + //if (texturedata.getWidth() == texturedata.getHeight()) |
---|
8385 | 8545 | { |
---|
8386 | | - for (int i=pixels.length; --i>=0;) |
---|
8387 | | - { |
---|
8388 | | - int i3 = i*3; |
---|
8389 | | - pixels[i] = 0xFF; |
---|
8390 | | - pixels[i] <<= 8; |
---|
8391 | | - pixels[i] |= bytebuf.get(i3+2) & 0xFF; |
---|
8392 | | - pixels[i] <<= 8; |
---|
8393 | | - pixels[i] |= bytebuf.get(i3+1) & 0xFF; |
---|
8394 | | - pixels[i] <<= 8; |
---|
8395 | | - pixels[i] |= bytebuf.get(i3) & 0xFF; |
---|
8396 | | - } |
---|
8397 | | - |
---|
8398 | | - /* |
---|
8399 | | - int r=0,g=0,b=0,a=0; |
---|
8400 | | - for (int i=0; i<width; i++) |
---|
8401 | | - for (int j=0; j<height; j++) |
---|
8402 | | - { |
---|
8403 | | - int index = j*width+i; |
---|
8404 | | - int p = pixels[index]; |
---|
8405 | | - a = ((p>>24) & 0xFF); |
---|
8406 | | - r = ((p>>16) & 0xFF); |
---|
8407 | | - g = ((p>>8) & 0xFF); |
---|
8408 | | - b = (p & 0xFF); |
---|
8409 | | - pixels[index] = (a<<24) | (b<<16) | (g<<8) | r; |
---|
8410 | | - } |
---|
8411 | | - /**/ |
---|
8412 | | - int width = (int)Math.sqrt(pixels.length); // squared |
---|
8413 | | - int height = width; |
---|
8414 | | - BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile); |
---|
8415 | | - rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width); |
---|
| 8546 | + BufferedImage rendImage = CreateBim(texturedata); |
---|
| 8547 | + |
---|
8416 | 8548 | ImageWriter writer = null; |
---|
8417 | 8549 | Iterator iter = ImageIO.getImageWritersByFormatName("jpg"); |
---|
8418 | 8550 | if (iter.hasNext()) { |
---|
8419 | 8551 | writer = (ImageWriter)iter.next(); |
---|
8420 | 8552 | } |
---|
8421 | | - float compressionQuality = 0.9f; |
---|
| 8553 | + |
---|
| 8554 | + float compressionQuality = 0.85f; |
---|
8422 | 8555 | try |
---|
8423 | 8556 | { |
---|
8424 | 8557 | ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile); |
---|
.. | .. |
---|
8435 | 8568 | } |
---|
8436 | 8569 | } |
---|
8437 | 8570 | } |
---|
8438 | | - |
---|
| 8571 | + |
---|
| 8572 | + Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment; |
---|
| 8573 | + |
---|
8439 | 8574 | //System.out.println("Texture = " + tex); |
---|
8440 | | - if (textures.containsKey(texname)) |
---|
| 8575 | + if (textures.containsKey(tex)) |
---|
8441 | 8576 | { |
---|
8442 | | - CacheTexture thetex = textures.get(texname); |
---|
| 8577 | + CacheTexture thetex = textures.get(tex); |
---|
8443 | 8578 | thetex.texture.disable(); |
---|
8444 | 8579 | thetex.texture.dispose(); |
---|
8445 | | - textures.remove(texname); |
---|
| 8580 | + textures.remove(tex); |
---|
8446 | 8581 | } |
---|
8447 | 8582 | |
---|
8448 | | - texture.texturedata = texturedata; |
---|
8449 | | - textures.put(texname, texture); |
---|
| 8583 | + //texture.texturedata = texturedata; |
---|
| 8584 | + textures.put(tex, texturecache); |
---|
8450 | 8585 | |
---|
8451 | 8586 | // newtex = true; |
---|
8452 | 8587 | } |
---|
.. | .. |
---|
8462 | 8597 | } |
---|
8463 | 8598 | } |
---|
8464 | 8599 | |
---|
8465 | | - return texture; |
---|
| 8600 | + return texturecache; |
---|
8466 | 8601 | } |
---|
8467 | 8602 | |
---|
8468 | | - 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 |
---|
8469 | 8638 | { |
---|
8470 | 8639 | CacheTexture texture = GetCacheTexture(tex, bump, resolution); |
---|
8471 | 8640 | |
---|
.. | .. |
---|
8483 | 8652 | return texture!=null?texture.texture:null; |
---|
8484 | 8653 | } |
---|
8485 | 8654 | |
---|
8486 | | - 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 |
---|
8487 | 8656 | { |
---|
8488 | 8657 | CacheTexture texture = GetCacheTexture(tex, bump, resolution); |
---|
8489 | 8658 | |
---|
8490 | 8659 | return texture!=null?texture.texturedata:null; |
---|
8491 | 8660 | } |
---|
8492 | 8661 | |
---|
8493 | | - boolean BindTexture(String tex, boolean bump, int resolution) throws Exception |
---|
| 8662 | + boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8494 | 8663 | { |
---|
8495 | 8664 | if (/*tex == null ||*/ ambientOcclusion ) // || !textureon) |
---|
8496 | 8665 | { |
---|
8497 | 8666 | return false; |
---|
8498 | 8667 | } |
---|
8499 | 8668 | |
---|
8500 | | - boolean newtex = false; |
---|
| 8669 | + //boolean newtex = false; |
---|
8501 | 8670 | |
---|
8502 | 8671 | com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution); |
---|
8503 | 8672 | |
---|
.. | .. |
---|
8529 | 8698 | texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT); |
---|
8530 | 8699 | texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT); |
---|
8531 | 8700 | |
---|
8532 | | - return newtex; |
---|
| 8701 | + return true; // Warning: not used. |
---|
8533 | 8702 | } |
---|
8534 | 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 | + |
---|
8535 | 8770 | ShadowBuffer shadowPBuf; |
---|
8536 | 8771 | AntialiasBuffer antialiasPBuf; |
---|
8537 | 8772 | int MAXSTACK; |
---|
.. | .. |
---|
8548 | 8783 | |
---|
8549 | 8784 | gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0); |
---|
8550 | 8785 | MAXSTACK = temp[0]; |
---|
8551 | | - System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK); |
---|
| 8786 | + if (Globals.DEBUG) |
---|
| 8787 | + System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK); |
---|
8552 | 8788 | gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0); |
---|
8553 | 8789 | MAXSTACK = temp[0]; |
---|
8554 | | - System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK); |
---|
| 8790 | + if (Globals.DEBUG) |
---|
| 8791 | + System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK); |
---|
8555 | 8792 | |
---|
8556 | 8793 | // Use debug pipeline |
---|
8557 | 8794 | //drawable.setGL(new DebugGL(gl)); // |
---|
.. | .. |
---|
8559 | 8796 | gl = drawable.getGL(); // |
---|
8560 | 8797 | |
---|
8561 | 8798 | GL gl3 = getGL(); |
---|
8562 | | - System.out.println("INIT GL IS: " + gl.getClass().getName()); |
---|
| 8799 | + if (Globals.DEBUG) |
---|
| 8800 | + System.out.println("INIT GL IS: " + gl.getClass().getName()); |
---|
8563 | 8801 | |
---|
8564 | 8802 | |
---|
8565 | 8803 | //float pos[] = { 100, 100, 100, 0 }; |
---|
.. | .. |
---|
8724 | 8962 | |
---|
8725 | 8963 | if (cubemap == null) |
---|
8726 | 8964 | { |
---|
8727 | | - LoadEnvy(5); |
---|
| 8965 | + //LoadEnvy(1); |
---|
8728 | 8966 | } |
---|
8729 | 8967 | |
---|
8730 | 8968 | //cubemap.enable(); |
---|
.. | .. |
---|
9000 | 9238 | |
---|
9001 | 9239 | void LoadEnvy(int which) |
---|
9002 | 9240 | { |
---|
| 9241 | + assert(false); |
---|
| 9242 | + |
---|
9003 | 9243 | String name; |
---|
9004 | 9244 | String ext; |
---|
9005 | 9245 | |
---|
.. | .. |
---|
9011 | 9251 | cubemap = null; |
---|
9012 | 9252 | return; |
---|
9013 | 9253 | case 1: |
---|
9014 | | - name = "cubemaps/box_"; |
---|
9015 | | - ext = "png"; |
---|
| 9254 | + name = "cubemaps/rgb/"; |
---|
| 9255 | + ext = "jpg"; |
---|
9016 | 9256 | reverseUP = false; |
---|
9017 | 9257 | break; |
---|
9018 | 9258 | case 2: |
---|
9019 | | - name = "cubemaps/uffizi_"; |
---|
9020 | | - ext = "png"; |
---|
9021 | | - break; // reverseUP = true; break; |
---|
| 9259 | + name = "cubemaps/uffizi/"; |
---|
| 9260 | + ext = "jpg"; |
---|
| 9261 | + reverseUP = false; |
---|
| 9262 | + break; |
---|
9022 | 9263 | case 3: |
---|
9023 | | - name = "cubemaps/CloudyHills_"; |
---|
9024 | | - ext = "tga"; |
---|
| 9264 | + name = "cubemaps/CloudyHills/"; |
---|
| 9265 | + ext = "jpg"; |
---|
9025 | 9266 | reverseUP = false; |
---|
9026 | 9267 | break; |
---|
9027 | 9268 | case 4: |
---|
9028 | | - name = "cubemaps/cornell_"; |
---|
| 9269 | + name = "cubemaps/cornell/"; |
---|
9029 | 9270 | ext = "png"; |
---|
9030 | 9271 | reverseUP = false; |
---|
9031 | 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; |
---|
9032 | 9298 | default: |
---|
9033 | | - name = "cubemaps/rgb_"; |
---|
9034 | | - ext = "png"; /*mipmap = true;*/ reverseUP = false; |
---|
| 9299 | + name = "cubemaps/box/"; |
---|
| 9300 | + ext = "png"; /*mipmap = true;*/ |
---|
| 9301 | + reverseUP = false; |
---|
9035 | 9302 | break; |
---|
9036 | 9303 | } |
---|
9037 | | - |
---|
9038 | | - try |
---|
9039 | | - { |
---|
9040 | | - cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap); |
---|
9041 | | - } catch (IOException e) |
---|
9042 | | - { |
---|
9043 | | - throw new RuntimeException(e); |
---|
9044 | | - } |
---|
| 9304 | + |
---|
| 9305 | + LoadSkybox(name, ext, mipmap); |
---|
9045 | 9306 | } |
---|
9046 | 9307 | |
---|
9047 | 9308 | public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) |
---|
.. | .. |
---|
9073 | 9334 | static double[] model = new double[16]; |
---|
9074 | 9335 | double[] camera2light = new double[16]; |
---|
9075 | 9336 | double[] light2camera = new double[16]; |
---|
9076 | | - int newenvy = -1; |
---|
9077 | | - boolean envyoff = true; // false; |
---|
| 9337 | + |
---|
| 9338 | + //int newenvy = -1; |
---|
| 9339 | + //boolean envyoff = false; |
---|
| 9340 | + |
---|
| 9341 | + String loadedskyboxname; |
---|
| 9342 | + |
---|
9078 | 9343 | cVector light0 = new cVector(0, 0, 0); // 1,3,2); |
---|
9079 | 9344 | //float[] light0 = { 0,0,0 }; |
---|
9080 | 9345 | cVector dirlight = new cVector(0, 0, 1); // 1,3,2); |
---|
.. | .. |
---|
9367 | 9632 | jy8[3] = 0.5f; |
---|
9368 | 9633 | } |
---|
9369 | 9634 | |
---|
9370 | | - float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV |
---|
| 9635 | + float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV |
---|
9371 | 9636 | float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation |
---|
9372 | 9637 | float[] options3 = new float[]{1, 1, 1, 0}; // fog color |
---|
9373 | 9638 | float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen |
---|
9374 | 9639 | |
---|
| 9640 | + void ResetOptions() |
---|
| 9641 | + { |
---|
| 9642 | + options1[0] = 100; |
---|
| 9643 | + options1[1] = 0.025f; |
---|
| 9644 | + options1[2] = 0.01f; |
---|
| 9645 | + options1[3] = 0; |
---|
| 9646 | + options1[4] = 0; |
---|
| 9647 | + |
---|
| 9648 | + options2[0] = 0; |
---|
| 9649 | + options2[1] = 0.75f; |
---|
| 9650 | + options2[2] = 0; |
---|
| 9651 | + options2[3] = 0; |
---|
| 9652 | + |
---|
| 9653 | + options3[0] = 1; |
---|
| 9654 | + options3[1] = 1; |
---|
| 9655 | + options3[2] = 1; |
---|
| 9656 | + options3[3] = 0; |
---|
| 9657 | + |
---|
| 9658 | + options4[0] = 1; |
---|
| 9659 | + options4[1] = 0; |
---|
| 9660 | + options4[2] = 1; |
---|
| 9661 | + options4[3] = 0; |
---|
| 9662 | + } |
---|
| 9663 | + |
---|
9375 | 9664 | static int imagecount = 0; // movie generation |
---|
9376 | 9665 | |
---|
9377 | 9666 | static int jitter = 0; |
---|
.. | .. |
---|
9468 | 9757 | |
---|
9469 | 9758 | if (renderCamera != lightCamera) |
---|
9470 | 9759 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
9471 | | - LA.matConcat(matrix, parentcam.GlobalTransform(), matrix); |
---|
| 9760 | + LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix); |
---|
9472 | 9761 | |
---|
9473 | 9762 | // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix); |
---|
9474 | 9763 | |
---|
.. | .. |
---|
9484 | 9773 | |
---|
9485 | 9774 | if (renderCamera != lightCamera) |
---|
9486 | 9775 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
9487 | | - LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix); |
---|
| 9776 | + LA.matConcat(parentcam.GlobalTransform(), matrix, matrix); |
---|
9488 | 9777 | |
---|
9489 | 9778 | // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix); |
---|
9490 | 9779 | |
---|
.. | .. |
---|
9530 | 9819 | rati = 1 / rati; |
---|
9531 | 9820 | gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000); |
---|
9532 | 9821 | } |
---|
9533 | | - assert (newenvy == -1); |
---|
| 9822 | + |
---|
| 9823 | + //assert (newenvy == -1); |
---|
| 9824 | + |
---|
9534 | 9825 | gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
9535 | 9826 | gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB); |
---|
9536 | | - DrawSkyBox(gl); |
---|
| 9827 | + DrawSkyBox(gl, (float)rati); |
---|
9537 | 9828 | gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
9538 | 9829 | gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB); |
---|
9539 | 9830 | accPerspective(gl, renderCamera.shaper_fovy / ratio, |
---|
.. | .. |
---|
10399 | 10690 | static boolean init = false; |
---|
10400 | 10691 | |
---|
10401 | 10692 | double[][] matrix = LA.newMatrix(); |
---|
| 10693 | + |
---|
| 10694 | + // This is to refresh the UI of the material panel. |
---|
| 10695 | + ObjEditor patchMaterial; |
---|
10402 | 10696 | |
---|
10403 | 10697 | public void display(GLAutoDrawable drawable) |
---|
10404 | 10698 | { |
---|
| 10699 | + if (patchMaterial.patchMaterial) |
---|
| 10700 | + { |
---|
| 10701 | + patchMaterial.patchMaterial = false; |
---|
| 10702 | + patchMaterial.objectPanel.setSelectedIndex(1); |
---|
| 10703 | + } |
---|
| 10704 | + |
---|
10405 | 10705 | if (Grafreed.savesound && Grafreed.hassound) |
---|
10406 | 10706 | { |
---|
10407 | 10707 | Grafreed.wav.save(); |
---|
.. | .. |
---|
10482 | 10782 | ANTIALIAS = 0; |
---|
10483 | 10783 | //System.out.println("RESTART"); |
---|
10484 | 10784 | AAtimer.restart(); |
---|
| 10785 | + Globals.TIMERRUNNING = true; |
---|
10485 | 10786 | } |
---|
10486 | 10787 | } |
---|
10487 | 10788 | } |
---|
.. | .. |
---|
10549 | 10850 | ambientOcclusion = false; |
---|
10550 | 10851 | } |
---|
10551 | 10852 | |
---|
10552 | | - if (Globals.lighttouched && DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN) |
---|
| 10853 | + if (//Globals.lighttouched && |
---|
| 10854 | + DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN) |
---|
10553 | 10855 | { |
---|
10554 | 10856 | //if (RENDERSHADOW) // ? |
---|
10555 | 10857 | if (!IsFrozen()) |
---|
.. | .. |
---|
10568 | 10870 | |
---|
10569 | 10871 | if (wait) |
---|
10570 | 10872 | { |
---|
10571 | | - Sleep(500); |
---|
| 10873 | + Sleep(200); // blocks everything |
---|
10572 | 10874 | |
---|
10573 | 10875 | wait = false; |
---|
10574 | 10876 | } |
---|
.. | .. |
---|
10683 | 10985 | // if (parentcam != renderCamera) // not a light |
---|
10684 | 10986 | if (cam != lightCamera) |
---|
10685 | 10987 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
10686 | | - LA.matConcat(matrix, parentcam.GlobalTransform(), matrix); |
---|
| 10988 | + LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix); |
---|
10687 | 10989 | |
---|
10688 | 10990 | for (int j = 0; j < 4; j++) |
---|
10689 | 10991 | { |
---|
.. | .. |
---|
10698 | 11000 | // if (parentcam != renderCamera) // not a light |
---|
10699 | 11001 | if (cam != lightCamera) |
---|
10700 | 11002 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
10701 | | - LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix); |
---|
| 11003 | + LA.matConcat(parentcam.GlobalTransform(), matrix, matrix); |
---|
10702 | 11004 | |
---|
10703 | 11005 | //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix); |
---|
10704 | 11006 | |
---|
.. | .. |
---|
10784 | 11086 | gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000); |
---|
10785 | 11087 | } |
---|
10786 | 11088 | |
---|
10787 | | - if (newenvy > -1) |
---|
| 11089 | +// if (newenvy > -1) |
---|
| 11090 | +// { |
---|
| 11091 | +// LoadEnvy(newenvy); |
---|
| 11092 | +// } |
---|
| 11093 | +// |
---|
| 11094 | +// newenvy = -1; |
---|
| 11095 | + |
---|
| 11096 | + if (transformMode) // object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb")) |
---|
10788 | 11097 | { |
---|
10789 | | - LoadEnvy(newenvy); |
---|
| 11098 | + if (cubemaprgb == null) |
---|
| 11099 | + { |
---|
| 11100 | + cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb2" + "/", "jpg", false); |
---|
| 11101 | + } |
---|
| 11102 | + |
---|
| 11103 | + cubemap = cubemaprgb; |
---|
10790 | 11104 | } |
---|
10791 | | - |
---|
10792 | | - newenvy = -1; |
---|
10793 | | - |
---|
| 11105 | + else |
---|
| 11106 | + { |
---|
| 11107 | + if (object.skyboxname != null) |
---|
| 11108 | + { |
---|
| 11109 | + if (!object.skyboxname.equals(this.loadedskyboxname)) |
---|
| 11110 | + { |
---|
| 11111 | + if (cubemap != null && cubemap != cubemaprgb) |
---|
| 11112 | + cubemap.dispose(); |
---|
| 11113 | + cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false); |
---|
| 11114 | + loadedskyboxname = object.skyboxname; |
---|
| 11115 | + } |
---|
| 11116 | + } |
---|
| 11117 | + else |
---|
| 11118 | + { |
---|
| 11119 | + cubemapcustom = null; |
---|
| 11120 | + loadedskyboxname = null; |
---|
| 11121 | + } |
---|
| 11122 | + |
---|
| 11123 | + cubemap = cubemapcustom; |
---|
| 11124 | + } |
---|
| 11125 | + |
---|
10794 | 11126 | ratio = ((double) getWidth()) / getHeight(); |
---|
10795 | 11127 | //System.out.println("ratio = " + ratio); |
---|
10796 | 11128 | |
---|
.. | .. |
---|
10806 | 11138 | |
---|
10807 | 11139 | if (!IsFrozen() && !ambientOcclusion) |
---|
10808 | 11140 | { |
---|
10809 | | - DrawSkyBox(gl); |
---|
| 11141 | + DrawSkyBox(gl, (float)ratio); |
---|
10810 | 11142 | } |
---|
10811 | 11143 | |
---|
10812 | 11144 | //if (selection_view == -1) |
---|
.. | .. |
---|
10989 | 11321 | |
---|
10990 | 11322 | gl.glMatrixMode(GL.GL_MODELVIEW); |
---|
10991 | 11323 | |
---|
10992 | | -//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST); |
---|
10993 | | -//gl.glEnable(gl.GL_POLYGON_SMOOTH); |
---|
10994 | | -//gl.glEnable(gl.GL_MULTISAMPLE); |
---|
| 11324 | +gl.glEnable(gl.GL_POLYGON_SMOOTH); |
---|
| 11325 | +gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST); |
---|
| 11326 | +gl.glEnable(gl.GL_MULTISAMPLE); |
---|
10995 | 11327 | } else |
---|
10996 | 11328 | { |
---|
10997 | 11329 | //gl.glDisable(GL.GL_TEXTURE_2D); |
---|
.. | .. |
---|
11002 | 11334 | //System.out.println("BLENDING ON"); |
---|
11003 | 11335 | gl.glEnable(GL.GL_BLEND); |
---|
11004 | 11336 | gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); |
---|
11005 | | - |
---|
| 11337 | +// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE); |
---|
11006 | 11338 | gl.glMatrixMode(gl.GL_PROJECTION); |
---|
11007 | 11339 | gl.glLoadIdentity(); |
---|
11008 | 11340 | |
---|
.. | .. |
---|
11092 | 11424 | |
---|
11093 | 11425 | // if (cam != lightCamera) |
---|
11094 | 11426 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
11095 | | - LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013 |
---|
| 11427 | + LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013 |
---|
11096 | 11428 | } |
---|
11097 | 11429 | |
---|
11098 | 11430 | LA.xformDir(lightposition, cam.toScreen, lightposition); |
---|
.. | .. |
---|
11251 | 11583 | } |
---|
11252 | 11584 | } |
---|
11253 | 11585 | |
---|
11254 | | - if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion) |
---|
| 11586 | + if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion) |
---|
11255 | 11587 | { |
---|
11256 | 11588 | //gl.glDepthFunc(GL.GL_LEQUAL); |
---|
11257 | 11589 | //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT); |
---|
.. | .. |
---|
11259 | 11591 | |
---|
11260 | 11592 | boolean texon = textureon; |
---|
11261 | 11593 | |
---|
11262 | | - if (RENDERPROGRAM > 0) |
---|
11263 | | - { |
---|
11264 | | - gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
11265 | | - textureon = false; |
---|
11266 | | - } |
---|
| 11594 | + gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
| 11595 | + textureon = false; |
---|
| 11596 | + |
---|
11267 | 11597 | //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB); |
---|
11268 | 11598 | //System.out.println("ALLO"); |
---|
11269 | 11599 | gl.glColorMask(false, false, false, false); |
---|
11270 | 11600 | DrawObject(gl); |
---|
11271 | | - if (RENDERPROGRAM > 0) |
---|
11272 | | - { |
---|
11273 | | - gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
11274 | | - textureon = texon; |
---|
11275 | | - } |
---|
| 11601 | + |
---|
| 11602 | + gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
| 11603 | + textureon = texon; |
---|
| 11604 | + |
---|
11276 | 11605 | gl.glColorMask(true, true, true, true); |
---|
11277 | 11606 | |
---|
11278 | 11607 | gl.glDepthFunc(GL.GL_EQUAL); |
---|
11279 | | - //gl.glDepthMask(false); |
---|
| 11608 | + gl.glDepthMask(false); |
---|
11280 | 11609 | } |
---|
11281 | 11610 | |
---|
11282 | 11611 | if (false) // DrawMode() == SHADOW) |
---|
.. | .. |
---|
11459 | 11788 | |
---|
11460 | 11789 | static boolean zoomonce = false; |
---|
11461 | 11790 | |
---|
| 11791 | + static void CreateSelectedPoint() |
---|
| 11792 | + { |
---|
| 11793 | + if (selectedpoint == null) |
---|
| 11794 | + { |
---|
| 11795 | + debugpointG = new Sphere(); |
---|
| 11796 | + debugpointP = new Sphere(); |
---|
| 11797 | + debugpointC = new Sphere(); |
---|
| 11798 | + debugpointR = new Sphere(); |
---|
| 11799 | + |
---|
| 11800 | + selectedpoint = new Superellipsoid(); |
---|
| 11801 | + |
---|
| 11802 | + for (int i=0; i<8; i++) |
---|
| 11803 | + { |
---|
| 11804 | + debugpoints[i] = new Sphere(); |
---|
| 11805 | + } |
---|
| 11806 | + } |
---|
| 11807 | + } |
---|
| 11808 | + |
---|
11462 | 11809 | void DrawObject(GL gl, boolean draw) |
---|
11463 | 11810 | { |
---|
| 11811 | + // To clear camera values |
---|
| 11812 | + ResetOptions(); |
---|
| 11813 | + |
---|
11464 | 11814 | //System.out.println("DRAW OBJECT " + mouseDown); |
---|
11465 | 11815 | // DrawMode() = SELECTION; |
---|
11466 | 11816 | //GL gl = getGL(); |
---|
11467 | 11817 | if ((TRACK || SHADOWTRACK) || zoomonce) |
---|
11468 | 11818 | { |
---|
11469 | 11819 | if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode) |
---|
11470 | | - object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK); |
---|
| 11820 | + object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK); |
---|
11471 | 11821 | pingthread.StepToTarget(true); // true); |
---|
11472 | 11822 | // zoomonce = false; |
---|
11473 | 11823 | } |
---|
.. | .. |
---|
11539 | 11889 | |
---|
11540 | 11890 | if (DrawMode() == DEFAULT) |
---|
11541 | 11891 | { |
---|
11542 | | - if (DEBUG) |
---|
| 11892 | + if (Globals.DEBUG) |
---|
11543 | 11893 | { |
---|
| 11894 | + CreateSelectedPoint(); |
---|
11544 | 11895 | float radius = 0.05f; |
---|
11545 | 11896 | if (selectedpoint.radius != radius) |
---|
11546 | 11897 | { |
---|
.. | .. |
---|
11594 | 11945 | ReleaseTextures(DEFAULT_TEXTURES); |
---|
11595 | 11946 | |
---|
11596 | 11947 | if (CLEANCACHE) |
---|
11597 | | - for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();) |
---|
| 11948 | + for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();) |
---|
11598 | 11949 | { |
---|
11599 | | - String tex = e.nextElement(); |
---|
| 11950 | + cTexture tex = e.nextElement(); |
---|
11600 | 11951 | |
---|
11601 | 11952 | // System.out.println("Texture --------- " + tex); |
---|
11602 | 11953 | |
---|
11603 | | - if (tex.equals("WHITE_NOISE")) |
---|
| 11954 | + if (tex.equals("WHITE_NOISE:")) |
---|
11604 | 11955 | continue; |
---|
11605 | 11956 | |
---|
11606 | | - if (!usedtextures.containsKey(tex)) |
---|
| 11957 | + if (!usedtextures.contains(tex)) |
---|
11607 | 11958 | { |
---|
| 11959 | + CacheTexture gettex = texturepigment.get(tex); |
---|
11608 | 11960 | // System.out.println("DISPOSE +++++++++++++++ " + tex); |
---|
11609 | | - textures.get(tex).texture.dispose(); |
---|
11610 | | - textures.remove(tex); |
---|
| 11961 | + if (gettex != null) |
---|
| 11962 | + { |
---|
| 11963 | + gettex.texture.dispose(); |
---|
| 11964 | + texturepigment.remove(tex); |
---|
| 11965 | + } |
---|
| 11966 | + |
---|
| 11967 | + gettex = texturebump.get(tex); |
---|
| 11968 | + // System.out.println("DISPOSE +++++++++++++++ " + tex); |
---|
| 11969 | + if (gettex != null) |
---|
| 11970 | + { |
---|
| 11971 | + gettex.texture.dispose(); |
---|
| 11972 | + texturebump.remove(tex); |
---|
| 11973 | + } |
---|
11611 | 11974 | } |
---|
11612 | 11975 | } |
---|
11613 | 11976 | } |
---|
.. | .. |
---|
12027 | 12390 | for (int i = tp.size(); --i >= 0;) |
---|
12028 | 12391 | { |
---|
12029 | 12392 | //for (int count = tp.get(i).GetTransformCount(); --count>=0;) |
---|
12030 | | - LA.xformPos(light, tp.get(i).GlobalTransform(), light); |
---|
| 12393 | + LA.xformPos(light, tp.get(i).GlobalTransformInv(), light); |
---|
12031 | 12394 | } |
---|
12032 | 12395 | |
---|
12033 | 12396 | |
---|
.. | .. |
---|
12135 | 12498 | |
---|
12136 | 12499 | //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0); |
---|
12137 | 12500 | |
---|
12138 | | - String program = |
---|
| 12501 | + String programmin = |
---|
| 12502 | + // Min shader |
---|
12139 | 12503 | "!!ARBfp1.0\n" + |
---|
| 12504 | + "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" + |
---|
| 12505 | + "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" + |
---|
| 12506 | + "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" + |
---|
| 12507 | + "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" + |
---|
| 12508 | + "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" + |
---|
| 12509 | + "PARAM light2cam0 = program.env[10];" + |
---|
| 12510 | + "PARAM light2cam1 = program.env[11];" + |
---|
| 12511 | + "PARAM light2cam2 = program.env[12];" + |
---|
| 12512 | + "TEMP temp;" + |
---|
| 12513 | + "TEMP light;" + |
---|
| 12514 | + "TEMP ndotl;" + |
---|
| 12515 | + "TEMP normal;" + |
---|
| 12516 | + "TEMP depth;" + |
---|
| 12517 | + "TEMP eye;" + |
---|
| 12518 | + "TEMP pos;" + |
---|
| 12519 | + |
---|
| 12520 | + "MAD normal, fragment.color, zero123.z, -zero123.y;" + |
---|
| 12521 | + Normalize("normal") + |
---|
| 12522 | + "MOV light, state.light[0].position;" + |
---|
| 12523 | + "DP3 ndotl.x, light, normal;" + |
---|
| 12524 | + |
---|
| 12525 | + // shadow |
---|
| 12526 | + "MOV pos, fragment.texcoord[1];" + |
---|
| 12527 | + "MOV temp, pos;" + |
---|
| 12528 | + ShadowTextureFetch("depth", "temp", "1") + |
---|
| 12529 | + //"TEX depth, fragment.texcoord[1], texture[1], 2D;" + |
---|
| 12530 | + "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" + |
---|
| 12531 | + |
---|
| 12532 | + // No shadow when out of frustum |
---|
| 12533 | + //"SGE temp.y, depth.z, zero123.y;" + |
---|
| 12534 | + //"LRP temp.x, temp.y, zero123.y, temp.x;" + |
---|
| 12535 | + |
---|
| 12536 | + "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow |
---|
| 12537 | + |
---|
| 12538 | + // Backlit |
---|
| 12539 | + "MOV pos.w, zero123.y;" + |
---|
| 12540 | + "DP4 eye.x, pos, light2cam0;" + |
---|
| 12541 | + "DP4 eye.y, pos, light2cam1;" + |
---|
| 12542 | + "DP4 eye.z, pos, light2cam2;" + |
---|
| 12543 | + Normalize("eye") + |
---|
| 12544 | + |
---|
| 12545 | + "DP3 ndotl.y, -eye, normal;" + |
---|
| 12546 | + //"MUL ndotl.y, ndotl.y, pow2.x;" + |
---|
| 12547 | + "POW ndotl.y, ndotl.y, pow2.z;" + // backlit |
---|
| 12548 | + "SUB ndotl.y, zero123.y, ndotl.y;" + |
---|
| 12549 | + //"SUB ndotl.y, zero123.y, ndotl.y;" + |
---|
| 12550 | + //"MUL ndotl.y, ndotl.y, pow2.z;" + |
---|
| 12551 | + |
---|
| 12552 | + //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient |
---|
| 12553 | + //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient |
---|
| 12554 | + |
---|
| 12555 | + // Pigment |
---|
| 12556 | + "TEX temp, fragment.texcoord[0], texture[0], 2D;" + |
---|
| 12557 | + "LRP temp, zero123.w, temp, one;" + // texture proportion |
---|
| 12558 | + "MUL temp, temp, ndotl.x;" + |
---|
| 12559 | + |
---|
| 12560 | + "MUL temp, temp, zero123.z;" + |
---|
| 12561 | + |
---|
| 12562 | + //"MUL temp, temp, ndotl.y;" + |
---|
| 12563 | + |
---|
| 12564 | + "MOV temp.w, zero123.y;" + // reset alpha |
---|
| 12565 | + "MOV result.color, temp;" + |
---|
| 12566 | + "END"; |
---|
| 12567 | + |
---|
| 12568 | + String programmax = |
---|
| 12569 | + "!!ARBfp1.0\n" + |
---|
| 12570 | + |
---|
12140 | 12571 | //"OPTION ARB_fragment_program_shadow;" + |
---|
12141 | 12572 | "PARAM light2cam0 = program.env[10];" + |
---|
12142 | 12573 | "PARAM light2cam1 = program.env[11];" + |
---|
.. | .. |
---|
12162 | 12593 | "PARAM params4 = program.env[4];" + // anisoV, cameralight, selfshadow, shadow |
---|
12163 | 12594 | "PARAM params5 = program.env[5];" + // texture, opacity, fakedepth, shadowbias |
---|
12164 | 12595 | "PARAM params6 = program.env[6];" + // bump, noise, borderfade, fog punchthrough |
---|
12165 | | - "PARAM params7 = program.env[7];" + // noise power, opacity power |
---|
| 12596 | + "PARAM params7 = program.env[7];" + // noise power, opacity power, parallax |
---|
12166 | 12597 | "PARAM options0 = program.env[63];" + // fog density, intensity, elevation |
---|
12167 | 12598 | "PARAM options1 = program.env[62];" + // fog rgb color |
---|
12168 | 12599 | "PARAM options2 = program.env[61];" + // image intensity, subsurface, lightsheen |
---|
.. | .. |
---|
12251 | 12682 | "TEMP shininess;" + |
---|
12252 | 12683 | "\n" + |
---|
12253 | 12684 | "MOV texSamp, one;" + |
---|
12254 | | - //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" + |
---|
12255 | | - |
---|
| 12685 | + |
---|
12256 | 12686 | "MOV mapgrid.x, one2048th.x;" + |
---|
12257 | 12687 | "MOV temp, fragment.texcoord[1];" + |
---|
12258 | 12688 | /* |
---|
.. | .. |
---|
12273 | 12703 | "MUL temp, floor, mapgrid.x;" + |
---|
12274 | 12704 | //"TEX depth0, temp, texture[1], 2D;" + |
---|
12275 | 12705 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12276 | | - TextureFetch("depth0", "temp", "1") + |
---|
| 12706 | + ShadowTextureFetch("depth0", "temp", "1") + |
---|
12277 | 12707 | "") + |
---|
12278 | 12708 | "ADD temp.x, temp.x, mapgrid.x;" + |
---|
12279 | 12709 | //"TEX depth1, temp, texture[1], 2D;" + |
---|
12280 | 12710 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12281 | | - TextureFetch("depth1", "temp", "1") + |
---|
| 12711 | + ShadowTextureFetch("depth1", "temp", "1") + |
---|
12282 | 12712 | "") + |
---|
12283 | 12713 | "ADD temp.y, temp.y, mapgrid.x;" + |
---|
12284 | 12714 | //"TEX depth2, temp, texture[1], 2D;" + |
---|
12285 | | - TextureFetch("depth2", "temp", "1") + |
---|
| 12715 | + ShadowTextureFetch("depth2", "temp", "1") + |
---|
12286 | 12716 | "SUB temp.x, temp.x, mapgrid.x;" + |
---|
12287 | 12717 | //"TEX depth3, temp, texture[1], 2D;" + |
---|
12288 | 12718 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12289 | | - TextureFetch("depth3", "temp", "1") + |
---|
| 12719 | + ShadowTextureFetch("depth3", "temp", "1") + |
---|
12290 | 12720 | "") + |
---|
12291 | 12721 | //"MUL texSamp0, texSamp0, state.material.front.diffuse;" + |
---|
12292 | 12722 | //"MOV params, material;" + |
---|
.. | .. |
---|
12408 | 12838 | "POW texSamp.a, texSamp.a, params6.w;" + // fog punch through shortcut |
---|
12409 | 12839 | // mar 2013 ??? "KIL alpha.a;" + |
---|
12410 | 12840 | "MOV alpha, texSamp.aaaa;" + // y;" + |
---|
12411 | | - "KIL alpha.a;" + |
---|
| 12841 | + "KIL alpha.a;" + // not sure with parallax mapping |
---|
12412 | 12842 | /* |
---|
12413 | 12843 | "MUL temp.xy, temp, two;" + |
---|
12414 | 12844 | "TXB bump, temp, texture[0], 2D;" + |
---|
.. | .. |
---|
12494 | 12924 | "SUB bump0, bump0, half;" + |
---|
12495 | 12925 | "ADD bump, bump, bump0;" + |
---|
12496 | 12926 | |
---|
12497 | | - "MOV temp.x, texSamp.a;" + |
---|
12498 | | - "LRP texSamp, params5.x, texSamp, one;" + // texture proportion |
---|
12499 | | - //"LRP texSamp0, params5.x, texSamp0, one;" + |
---|
12500 | | - "MOV texSamp.a, temp.x;" + |
---|
12501 | | - |
---|
12502 | 12927 | // double-sided |
---|
12503 | 12928 | /**/ |
---|
12504 | 12929 | (doublesided?"DP3 temp.z, normal, eye;" + |
---|
.. | .. |
---|
12528 | 12953 | Normalize("U") + |
---|
12529 | 12954 | |
---|
12530 | 12955 | // parallax mapping |
---|
| 12956 | + |
---|
| 12957 | + "DP3 temp2.x, V, eye;" + |
---|
| 12958 | + "DP3 temp2.y, U, eye;" + |
---|
| 12959 | + "DP3 temp2.z, normal, eye;" + |
---|
| 12960 | + "RCP temp2.z, temp2.z;" + |
---|
| 12961 | + |
---|
| 12962 | + "DP3 temp2.w, texSamp, texSamp;" + // Height |
---|
| 12963 | + "RSQ temp2.w, temp2.w;" + |
---|
| 12964 | + "RCP temp2.w, temp2.w;" + |
---|
| 12965 | + |
---|
| 12966 | + "SUB temp2.w, temp2.w, half;" + |
---|
| 12967 | +// "SGE temp.x, temp2.w, eps.x;" + |
---|
| 12968 | +// "MUL temp2.w, temp2.w, temp.x;" + |
---|
| 12969 | + |
---|
| 12970 | + //"MOV texSamp, U;" + |
---|
| 12971 | + |
---|
| 12972 | + "MUL temp2.z, temp2.z, temp2.w;" + |
---|
| 12973 | + "MUL temp2.z, temp2.z, params7.z;" + // parallax |
---|
| 12974 | + |
---|
| 12975 | + "MUL temp2, temp2, temp2.z;" + |
---|
| 12976 | + |
---|
| 12977 | + "MOV temp, fragment.texcoord[0];" + |
---|
| 12978 | + |
---|
| 12979 | + "SUB temp, temp, temp2;" + |
---|
| 12980 | + |
---|
| 12981 | + "TEX texSamp, temp, texture[0], 2D;" + |
---|
| 12982 | + "POW texSamp.a, texSamp.a, params6.w;" + // punch through |
---|
| 12983 | + "MOV alpha, texSamp.aaaa;" + |
---|
| 12984 | + |
---|
| 12985 | +// parallax mapping |
---|
| 12986 | + |
---|
| 12987 | + "MOV temp.x, texSamp.a;" + |
---|
| 12988 | + "LRP texSamp, params5.x, texSamp, one;" + // texture proportion |
---|
| 12989 | + //"LRP texSamp0, params5.x, texSamp0, one;" + |
---|
| 12990 | + "MOV texSamp.a, temp.x;" + |
---|
12531 | 12991 | |
---|
12532 | 12992 | //"MOV temp, fragment.texcoord[0];" + |
---|
12533 | 12993 | // |
---|
.. | .. |
---|
12657 | 13117 | "MAD shadow.x, buffer.x, frac.y, shadow.x;" + |
---|
12658 | 13118 | "") + |
---|
12659 | 13119 | |
---|
12660 | | - // display shadow only (bump == 0) |
---|
| 13120 | + // display shadow only (fakedepth == 0) |
---|
12661 | 13121 | "SUB temp.x, half.x, shadow.x;" + |
---|
12662 | 13122 | "MOV temp.y, -params5.z;" + // params6.x;" + |
---|
12663 | | - "SLT temp.z, temp.y, -one2048th.x;" + |
---|
| 13123 | + "SLT temp.z, temp.y, -c256i.x;" + |
---|
12664 | 13124 | "SUB temp.y, one.x, temp.z;" + |
---|
12665 | 13125 | "MUL temp.x, temp.x, temp.y;" + |
---|
12666 | 13126 | "KIL temp.x;" + |
---|
.. | .. |
---|
12991 | 13451 | //once = true; |
---|
12992 | 13452 | } |
---|
12993 | 13453 | |
---|
12994 | | - System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length()); |
---|
12995 | | - System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : "")); |
---|
| 13454 | + String program = programmax; |
---|
| 13455 | + |
---|
| 13456 | + if (Globals.MINSHADER) |
---|
| 13457 | + { |
---|
| 13458 | + program = programmin; |
---|
| 13459 | + } |
---|
| 13460 | + |
---|
| 13461 | + if (Globals.DEBUG) |
---|
| 13462 | + { |
---|
| 13463 | + System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length()); |
---|
| 13464 | + System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : "")); |
---|
| 13465 | + } |
---|
| 13466 | + |
---|
12996 | 13467 | loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program); |
---|
12997 | 13468 | |
---|
12998 | 13469 | //gl.glNewList(displayListID, GL.GL_COMPILE); |
---|
.. | .. |
---|
13039 | 13510 | "\n" + |
---|
13040 | 13511 | "END\n"; |
---|
13041 | 13512 | |
---|
13042 | | - System.out.println("Program shadow #" + 0 + "; length = " + program.length()); |
---|
| 13513 | + if (Globals.DEBUG) |
---|
| 13514 | + System.out.println("Program shadow #" + 0 + "; length = " + program.length()); |
---|
13043 | 13515 | loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program); |
---|
13044 | 13516 | |
---|
13045 | 13517 | //gl.glNewList(displayListID, GL.GL_COMPILE); |
---|
.. | .. |
---|
13084 | 13556 | return out; |
---|
13085 | 13557 | } |
---|
13086 | 13558 | |
---|
13087 | | - String TextureFetch(String dest, String src, String unit) |
---|
| 13559 | + // Also does frustum culling |
---|
| 13560 | + String ShadowTextureFetch(String dest, String src, String unit) |
---|
13088 | 13561 | { |
---|
13089 | 13562 | return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" + |
---|
13090 | 13563 | "SGE " + src + ".w, " + src + ".x, eps.x;" + |
---|
13091 | 13564 | "SGE " + src + ".z, " + src + ".y, eps.x;" + |
---|
| 13565 | + "SLT " + dest + ".x, " + src + ".x, one.x;" + |
---|
| 13566 | + "SLT " + dest + ".y, " + src + ".y, one.x;" + |
---|
13092 | 13567 | "MUL " + src + ".w, " + src + ".z, " + src + ".w;" + |
---|
13093 | | - "SLT " + src + ".z, " + src + ".x, one.x;" + |
---|
13094 | | - "MUL " + src + ".w, " + src + ".z, " + src + ".w;" + |
---|
13095 | | - "SLT " + src + ".z, " + src + ".y, one.x;" + |
---|
13096 | | - "MUL " + src + ".w, " + src + ".z, " + src + ".w;" + |
---|
| 13568 | + "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" + |
---|
| 13569 | + "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" + |
---|
13097 | 13570 | //"SWZ buffer, temp, w,w,w,w;"; |
---|
13098 | | - "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" + |
---|
| 13571 | + //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" + |
---|
13099 | 13572 | "SUB " + src + ".z, " + "one.x, " + src + ".w;" + |
---|
13100 | 13573 | //"MUL " + src + ".z, " + src + ".z, infinity.x;" + |
---|
13101 | 13574 | //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;"; |
---|
13102 | | - "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
| 13575 | + //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
13103 | 13576 | |
---|
13104 | | - //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;"; |
---|
13105 | | - //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;"; |
---|
| 13577 | + //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;"; |
---|
| 13578 | + "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
13106 | 13579 | } |
---|
13107 | 13580 | |
---|
13108 | 13581 | String Shadow(String depth, String shadow) |
---|
.. | .. |
---|
13149 | 13622 | "SLT temp.x, temp.x, zero.x;" + // shadoweps |
---|
13150 | 13623 | "LRP " + shadow + ", temp.x, one, " + shadow + ";" + |
---|
13151 | 13624 | |
---|
13152 | | - // No shadow when out of frustrum |
---|
| 13625 | + // No shadow when out of frustum |
---|
13153 | 13626 | "SGE temp.x, " + depth + ".z, one.z;" + |
---|
13154 | 13627 | "LRP " + shadow + ", temp.x, one, " + shadow + ";" + |
---|
13155 | 13628 | ""; |
---|
.. | .. |
---|
13296 | 13769 | /*static*/ float[] modelParams4 = new float[]{0, 0, 0, 0}; // anisoV, cameralight, selfshadow, shadow |
---|
13297 | 13770 | /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias |
---|
13298 | 13771 | /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough |
---|
13299 | | - /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power |
---|
13300 | | - Object3D.cVector2[] vector2buffer; |
---|
| 13772 | + /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power, parallax |
---|
| 13773 | + |
---|
| 13774 | + //Object3D.cVector2[] vector2buffer; |
---|
13301 | 13775 | |
---|
13302 | 13776 | // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea |
---|
13303 | 13777 | // OUT : diff, spec |
---|
.. | .. |
---|
13313 | 13787 | "DP3 " + dest + ".z," + "normals," + "eye;" + |
---|
13314 | 13788 | "MAX " + dest + ".w," + dest + ".z," + "eps.x;" + |
---|
13315 | 13789 | //"MOV " + dest + ".w," + "normal.z;" + |
---|
13316 | | - "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + |
---|
13317 | | - "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" + |
---|
13318 | | - //"MOV " + dest + ".z," + "params2.w;" + |
---|
| 13790 | +// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET |
---|
| 13791 | +// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" + |
---|
| 13792 | + |
---|
| 13793 | + "MOV " + dest + ".z," + "params2.w;" + // EXACT |
---|
13319 | 13794 | "POW " + dest + ".w," + dest + ".w," + dest + ".z;" + |
---|
13320 | 13795 | "RCP " + dest + ".w," + dest + ".w;" + |
---|
13321 | 13796 | //"RSQ " + dest + ".w," + dest + ".w;" + |
---|
.. | .. |
---|
13820 | 14295 | else |
---|
13821 | 14296 | if (evt.getSource() == AAtimer) |
---|
13822 | 14297 | { |
---|
| 14298 | + Globals.TIMERRUNNING = false; |
---|
13823 | 14299 | if (mouseDown) |
---|
13824 | 14300 | { |
---|
13825 | 14301 | //new Exception().printStackTrace(); |
---|
.. | .. |
---|
13879 | 14355 | |
---|
13880 | 14356 | // fev 2014??? |
---|
13881 | 14357 | if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode) |
---|
13882 | | - object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK); |
---|
| 14358 | + object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK); |
---|
13883 | 14359 | pingthread.StepToTarget(true); // true); |
---|
13884 | 14360 | } |
---|
13885 | 14361 | // if (!LIVE) |
---|
.. | .. |
---|
13894 | 14370 | return; |
---|
13895 | 14371 | |
---|
13896 | 14372 | AAtimer.restart(); // |
---|
| 14373 | + Globals.TIMERRUNNING = true; |
---|
13897 | 14374 | |
---|
13898 | 14375 | // waslive = LIVE; |
---|
13899 | 14376 | // LIVE = false; |
---|
.. | .. |
---|
13943 | 14420 | drag = false; |
---|
13944 | 14421 | //System.out.println("Mouse DOWN"); |
---|
13945 | 14422 | editObj = false; |
---|
13946 | | - ClickInfo info = new ClickInfo(); |
---|
13947 | | - info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
13948 | | - info.pane = this; |
---|
13949 | | - info.camera = renderCamera; |
---|
13950 | | - info.x = x; |
---|
13951 | | - info.y = y; |
---|
13952 | | - info.modifiers = modifiersex; |
---|
13953 | | - editObj = object.doEditClick(info, 0); |
---|
| 14423 | + //ClickInfo info = new ClickInfo(); |
---|
| 14424 | + object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
| 14425 | + object.clickInfo.pane = this; |
---|
| 14426 | + object.clickInfo.camera = renderCamera; |
---|
| 14427 | + object.clickInfo.x = x; |
---|
| 14428 | + object.clickInfo.y = y; |
---|
| 14429 | + object.clickInfo.modifiers = modifiersex; |
---|
| 14430 | + editObj = object.doEditClick(//info, |
---|
| 14431 | + 0); |
---|
13954 | 14432 | if (!editObj) |
---|
13955 | 14433 | { |
---|
13956 | 14434 | hasMarquee = true; |
---|
.. | .. |
---|
14232 | 14710 | void GoDown(int mod) |
---|
14233 | 14711 | { |
---|
14234 | 14712 | MODIFIERS |= COMMAND; |
---|
14235 | | - /* |
---|
| 14713 | + boolean isVR = (mouseMode&VR)!=0; |
---|
| 14714 | + /**/ |
---|
14236 | 14715 | if((mod&SHIFT) == SHIFT) |
---|
14237 | | - manipCamera.RotatePosition(0, -speed); |
---|
| 14716 | + { |
---|
| 14717 | + if (isVR) |
---|
| 14718 | + manipCamera.RotateInterest(0, -speed); |
---|
| 14719 | + else |
---|
| 14720 | + manipCamera.RotatePosition(0, -speed); |
---|
| 14721 | + } |
---|
14238 | 14722 | else |
---|
14239 | | - manipCamera.BackForth(0, -speed*delta, getWidth()); |
---|
14240 | | - */ |
---|
| 14723 | + manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth()); |
---|
| 14724 | + /**/ |
---|
14241 | 14725 | if ((mod & SHIFT) == SHIFT) |
---|
14242 | 14726 | { |
---|
14243 | 14727 | mouseMode = mouseMode; // VR?? |
---|
.. | .. |
---|
14246 | 14730 | mouseMode |= BACKFORTH; |
---|
14247 | 14731 | } |
---|
14248 | 14732 | |
---|
| 14733 | + targetLookAt.set(manipCamera.lookAt); |
---|
| 14734 | + |
---|
14249 | 14735 | //prevX = X = anchorX; |
---|
14250 | 14736 | prevY = Y = anchorY - (int) (renderCamera.Distance()); |
---|
14251 | 14737 | } |
---|
.. | .. |
---|
14253 | 14739 | void GoUp(int mod) |
---|
14254 | 14740 | { |
---|
14255 | 14741 | MODIFIERS |= COMMAND; |
---|
14256 | | - /* |
---|
| 14742 | + /**/ |
---|
| 14743 | + boolean isVR = (mouseMode&VR)!=0; |
---|
| 14744 | + |
---|
14257 | 14745 | if((mod&SHIFT) == SHIFT) |
---|
14258 | | - manipCamera.RotatePosition(0, speed); |
---|
| 14746 | + { |
---|
| 14747 | + if (isVR) |
---|
| 14748 | + manipCamera.RotateInterest(0, speed); |
---|
| 14749 | + else |
---|
| 14750 | + manipCamera.RotatePosition(0, speed); |
---|
| 14751 | + } |
---|
14259 | 14752 | else |
---|
14260 | | - manipCamera.BackForth(0, speed*delta, getWidth()); |
---|
14261 | | - */ |
---|
| 14753 | + manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth()); |
---|
| 14754 | + /**/ |
---|
14262 | 14755 | if ((mod & SHIFT) == SHIFT) |
---|
14263 | 14756 | { |
---|
14264 | 14757 | mouseMode = mouseMode; |
---|
.. | .. |
---|
14267 | 14760 | mouseMode |= BACKFORTH; |
---|
14268 | 14761 | } |
---|
14269 | 14762 | |
---|
| 14763 | + targetLookAt.set(manipCamera.lookAt); |
---|
| 14764 | + |
---|
14270 | 14765 | //prevX = X = anchorX; |
---|
14271 | 14766 | prevY = Y = anchorY + (int) (renderCamera.Distance()); |
---|
14272 | 14767 | } |
---|
.. | .. |
---|
14274 | 14769 | void GoLeft(int mod) |
---|
14275 | 14770 | { |
---|
14276 | 14771 | MODIFIERS |= COMMAND; |
---|
14277 | | - /* |
---|
| 14772 | + /**/ |
---|
14278 | 14773 | if((mod&SHIFT) == SHIFT) |
---|
14279 | | - manipCamera.RotatePosition(speed, 0); |
---|
| 14774 | + manipCamera.Translate(speed*delta, 0, getWidth()); |
---|
14280 | 14775 | else |
---|
14281 | | - manipCamera.Translate(speed*delta, 0, getWidth()); |
---|
14282 | | - */ |
---|
| 14776 | + { |
---|
| 14777 | + if ((mouseMode&VR)!=0) |
---|
| 14778 | + manipCamera.RotateInterest(-speed, 0); |
---|
| 14779 | + else |
---|
| 14780 | + manipCamera.RotatePosition(speed, 0); |
---|
| 14781 | + } |
---|
| 14782 | + /**/ |
---|
14283 | 14783 | if ((mod & SHIFT) == SHIFT) |
---|
14284 | 14784 | { |
---|
14285 | 14785 | mouseMode = mouseMode; |
---|
.. | .. |
---|
14288 | 14788 | mouseMode |= ROTATE; |
---|
14289 | 14789 | } // TRANSLATE; |
---|
14290 | 14790 | |
---|
| 14791 | + targetLookAt.set(manipCamera.lookAt); |
---|
| 14792 | + |
---|
14291 | 14793 | prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance()); |
---|
14292 | 14794 | prevY = Y = anchorY; |
---|
14293 | 14795 | } |
---|
.. | .. |
---|
14295 | 14797 | void GoRight(int mod) |
---|
14296 | 14798 | { |
---|
14297 | 14799 | MODIFIERS |= COMMAND; |
---|
14298 | | - /* |
---|
| 14800 | + /**/ |
---|
14299 | 14801 | if((mod&SHIFT) == SHIFT) |
---|
14300 | | - manipCamera.RotatePosition(-speed, 0); |
---|
| 14802 | + manipCamera.Translate(-speed*delta, 0, getWidth()); |
---|
14301 | 14803 | else |
---|
14302 | | - manipCamera.Translate(-speed*delta, 0, getWidth()); |
---|
14303 | | - */ |
---|
| 14804 | + { |
---|
| 14805 | + if ((mouseMode&VR)!=0) |
---|
| 14806 | + manipCamera.RotateInterest(speed, 0); |
---|
| 14807 | + else |
---|
| 14808 | + manipCamera.RotatePosition(-speed, 0); |
---|
| 14809 | + } |
---|
| 14810 | + |
---|
| 14811 | + /**/ |
---|
14304 | 14812 | if ((mod & SHIFT) == SHIFT) |
---|
14305 | 14813 | { |
---|
14306 | 14814 | mouseMode = mouseMode; |
---|
.. | .. |
---|
14309 | 14817 | mouseMode |= ROTATE; |
---|
14310 | 14818 | } // TRANSLATE; |
---|
14311 | 14819 | |
---|
| 14820 | + targetLookAt.set(manipCamera.lookAt); |
---|
| 14821 | + |
---|
14312 | 14822 | prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance()); |
---|
14313 | 14823 | prevY = Y = anchorY; |
---|
14314 | 14824 | } |
---|
.. | .. |
---|
14350 | 14860 | if (editObj) |
---|
14351 | 14861 | { |
---|
14352 | 14862 | drag = true; |
---|
14353 | | - ClickInfo info = new ClickInfo(); |
---|
14354 | | - info.bounds.setBounds(0, 0, |
---|
| 14863 | + //ClickInfo info = new ClickInfo(); |
---|
| 14864 | + object.clickInfo.bounds.setBounds(0, 0, |
---|
14355 | 14865 | (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
14356 | | - info.pane = this; |
---|
14357 | | - info.camera = renderCamera; |
---|
14358 | | - info.x = x; |
---|
14359 | | - info.y = y; |
---|
14360 | | - object.editWindow.copy.doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0); |
---|
| 14866 | + object.clickInfo.pane = this; |
---|
| 14867 | + object.clickInfo.camera = renderCamera; |
---|
| 14868 | + object.clickInfo.x = x; |
---|
| 14869 | + object.clickInfo.y = y; |
---|
| 14870 | + object //.GetWindow().copy |
---|
| 14871 | + .doEditDrag(//info, |
---|
| 14872 | + (modifiers & MouseEvent.BUTTON3_MASK) != 0); |
---|
14361 | 14873 | } else |
---|
14362 | 14874 | { |
---|
14363 | 14875 | if (x < startX) |
---|
.. | .. |
---|
14506 | 15018 | } |
---|
14507 | 15019 | } |
---|
14508 | 15020 | |
---|
| 15021 | +// ClickInfo clickInfo = new ClickInfo(); |
---|
| 15022 | + |
---|
14509 | 15023 | public void mouseMoved(MouseEvent e) |
---|
14510 | 15024 | { |
---|
14511 | 15025 | //System.out.println("mouseMoved: " + e); |
---|
14512 | 15026 | if (isRenderer) |
---|
14513 | 15027 | return; |
---|
14514 | 15028 | |
---|
14515 | | - ClickInfo ci = new ClickInfo(); |
---|
14516 | | - ci.x = e.getX(); |
---|
14517 | | - ci.y = e.getY(); |
---|
14518 | | - ci.modifiers = e.getModifiersEx(); |
---|
14519 | | - ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
14520 | | - ci.pane = this; |
---|
14521 | | - ci.camera = renderCamera; |
---|
| 15029 | + // Mouse cursor feedback |
---|
| 15030 | + object.clickInfo.x = e.getX(); |
---|
| 15031 | + object.clickInfo.y = e.getY(); |
---|
| 15032 | + object.clickInfo.modifiers = e.getModifiersEx(); |
---|
| 15033 | + object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
| 15034 | + object.clickInfo.pane = this; |
---|
| 15035 | + object.clickInfo.camera = renderCamera; |
---|
14522 | 15036 | if (!isRenderer) |
---|
14523 | 15037 | { |
---|
14524 | | - if (object.editWindow.copy.doEditClick(ci, 0)) |
---|
| 15038 | + //ObjEditor editWindow = object.editWindow; |
---|
| 15039 | + //Object3D copy = editWindow.copy; |
---|
| 15040 | + if (object.doEditClick(//clickInfo, |
---|
| 15041 | + 0)) |
---|
14525 | 15042 | { |
---|
14526 | 15043 | setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
---|
14527 | 15044 | } else |
---|
.. | .. |
---|
14536 | 15053 | Globals.MOUSEDRAGGED = false; |
---|
14537 | 15054 | |
---|
14538 | 15055 | movingcamera = false; |
---|
14539 | | - X = Y = 0; |
---|
| 15056 | + X = 0; // getBounds().width/2; |
---|
| 15057 | + Y = 0; // getBounds().height/2; |
---|
14540 | 15058 | //System.out.println("mouseReleased: " + e); |
---|
14541 | 15059 | clickEnd(e.getX(), e.getY(), e.getModifiersEx()); |
---|
14542 | 15060 | } |
---|
.. | .. |
---|
14792 | 15310 | // break; |
---|
14793 | 15311 | case 'T': |
---|
14794 | 15312 | CACHETEXTURE ^= true; |
---|
14795 | | - textures.clear(); |
---|
| 15313 | + texturepigment.clear(); |
---|
| 15314 | + texturebump.clear(); |
---|
14796 | 15315 | // repaint(); |
---|
14797 | 15316 | break; |
---|
14798 | 15317 | case 'Y': |
---|
.. | .. |
---|
14802 | 15321 | case 'K': |
---|
14803 | 15322 | KOMPACTTEXTURE ^= true; |
---|
14804 | 15323 | //textures.clear(); |
---|
14805 | | - break; |
---|
14806 | | - case 'P': // Texture Projection macros |
---|
| 15324 | + // break; |
---|
| 15325 | + //case 'P': // Texture Projection macros |
---|
14807 | 15326 | // SAVETEXTURE ^= true; |
---|
14808 | 15327 | macromode = true; |
---|
14809 | 15328 | Udebug = Vdebug = NORMALdebug = false; programInitialized = false; |
---|
.. | .. |
---|
14877 | 15396 | case 'E' : COMPACT ^= true; |
---|
14878 | 15397 | repaint(); |
---|
14879 | 15398 | break; |
---|
14880 | | - case 'W' : DEBUGHSB ^= true; |
---|
| 15399 | + case 'W' : // Wide Window (fullscreen) |
---|
| 15400 | + //DEBUGHSB ^= true; |
---|
| 15401 | + ObjEditor.theFrame.ToggleFullScreen(); |
---|
14881 | 15402 | repaint(); |
---|
14882 | 15403 | break; |
---|
14883 | 15404 | case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break; |
---|
.. | .. |
---|
14902 | 15423 | RevertCamera(); |
---|
14903 | 15424 | repaint(); |
---|
14904 | 15425 | break; |
---|
14905 | | - case 'L': |
---|
14906 | 15426 | case 'l': |
---|
| 15427 | + //case 'L': |
---|
14907 | 15428 | if (lightMode) |
---|
14908 | 15429 | { |
---|
14909 | 15430 | lightMode = false; |
---|
.. | .. |
---|
14922 | 15443 | targetLookAt.set(manipCamera.lookAt); |
---|
14923 | 15444 | repaint(); |
---|
14924 | 15445 | break; |
---|
14925 | | - case 'p': |
---|
| 15446 | + case 'P': // p': |
---|
14926 | 15447 | // c'est quoi ca au juste? spherical ^= true; |
---|
14927 | 15448 | Skinshader ^= true; programInitialized = false; |
---|
14928 | 15449 | repaint(); |
---|
.. | .. |
---|
14967 | 15488 | OCCLUSION_CULLING ^= true; |
---|
14968 | 15489 | System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING); |
---|
14969 | 15490 | break; |
---|
14970 | | - case '0': envyoff ^= true; repaint(); break; |
---|
| 15491 | + //case '0': envyoff ^= true; repaint(); break; |
---|
14971 | 15492 | case '1': |
---|
14972 | 15493 | case '2': |
---|
14973 | 15494 | case '3': |
---|
14974 | 15495 | case '4': |
---|
14975 | 15496 | case '5': |
---|
14976 | | - newenvy = Character.getNumericValue(key); |
---|
14977 | | - repaint(); |
---|
14978 | | - break; |
---|
14979 | 15497 | case '6': |
---|
14980 | 15498 | case '7': |
---|
14981 | 15499 | case '8': |
---|
14982 | 15500 | case '9': |
---|
14983 | | - BGcolor = (key - '6')/3.f; |
---|
| 15501 | + if (true) // envyoff) |
---|
| 15502 | + { |
---|
| 15503 | + BGcolor = (key - '1')/8.f; |
---|
| 15504 | + } |
---|
| 15505 | + else |
---|
| 15506 | + { |
---|
| 15507 | + //newenvy = Character.getNumericValue(key); |
---|
| 15508 | + } |
---|
14984 | 15509 | repaint(); |
---|
14985 | 15510 | break; |
---|
14986 | 15511 | case '!': |
---|
.. | .. |
---|
15046 | 15571 | case '_': |
---|
15047 | 15572 | kompactbit = 5; |
---|
15048 | 15573 | break; |
---|
15049 | | - case '+': |
---|
15050 | | - kompactbit = 6; |
---|
15051 | | - break; |
---|
| 15574 | +// case '+': |
---|
| 15575 | +// kompactbit = 6; |
---|
| 15576 | +// break; |
---|
15052 | 15577 | case ' ': |
---|
15053 | 15578 | lightMode ^= true; |
---|
15054 | 15579 | Globals.lighttouched = true; |
---|
.. | .. |
---|
15060 | 15585 | case ESC: |
---|
15061 | 15586 | RENDERPROGRAM += 1; |
---|
15062 | 15587 | RENDERPROGRAM %= 3; |
---|
| 15588 | + |
---|
15063 | 15589 | repaint(); |
---|
15064 | 15590 | break; |
---|
15065 | 15591 | case 'Z': |
---|
.. | .. |
---|
15099 | 15625 | case DELETE: |
---|
15100 | 15626 | ClearSelection(); |
---|
15101 | 15627 | break; |
---|
15102 | | - /* |
---|
15103 | 15628 | case '+': |
---|
| 15629 | + |
---|
| 15630 | + /* |
---|
15104 | 15631 | //fontsize += 1; |
---|
15105 | 15632 | bbzoom *= 2; |
---|
15106 | 15633 | repaint(); |
---|
.. | .. |
---|
15117 | 15644 | case '=': |
---|
15118 | 15645 | IncDepth(); |
---|
15119 | 15646 | //fontsize += 1; |
---|
15120 | | - object.editWindow.refreshContents(true); |
---|
| 15647 | + object.GetWindow().refreshContents(true); |
---|
15121 | 15648 | maskbit = 6; |
---|
15122 | 15649 | break; |
---|
15123 | 15650 | case '-': //if (PixelThreshold>1) PixelThreshold /= 2; |
---|
15124 | 15651 | DecDepth(); |
---|
15125 | 15652 | maskbit = 5; |
---|
15126 | 15653 | //if(fontsize > 1) fontsize -= 1; |
---|
15127 | | - if (object.editWindow == null) |
---|
15128 | | - new Exception().printStackTrace(); |
---|
15129 | | - else |
---|
15130 | | - object.editWindow.refreshContents(true); |
---|
| 15654 | +// if (object.editWindow == null) |
---|
| 15655 | +// new Exception().printStackTrace(); |
---|
| 15656 | +// else |
---|
| 15657 | + object.GetWindow().refreshContents(true); |
---|
15131 | 15658 | break; |
---|
15132 | 15659 | case '{': |
---|
15133 | 15660 | manipCamera.shaper_fovy /= 1.1; |
---|
.. | .. |
---|
15351 | 15878 | } |
---|
15352 | 15879 | */ |
---|
15353 | 15880 | |
---|
15354 | | - object.editWindow.EditSelection(); |
---|
| 15881 | + object.GetWindow().EditSelection(false); |
---|
15355 | 15882 | } |
---|
15356 | 15883 | |
---|
15357 | 15884 | void SelectParent() |
---|
.. | .. |
---|
15368 | 15895 | { |
---|
15369 | 15896 | //selectees.remove(i); |
---|
15370 | 15897 | System.out.println("select parent of " + elem); |
---|
15371 | | - group.editWindow.Select(elem.parent.GetTreePath(), first, true); |
---|
| 15898 | + group.GetWindow().Select(elem.parent.GetTreePath(), first, true); |
---|
15372 | 15899 | } else |
---|
15373 | 15900 | { |
---|
15374 | | - group.editWindow.Select(elem.GetTreePath(), first, true); |
---|
| 15901 | + group.GetWindow().Select(elem.GetTreePath(), first, true); |
---|
15375 | 15902 | } |
---|
15376 | 15903 | |
---|
15377 | 15904 | first = false; |
---|
.. | .. |
---|
15413 | 15940 | for (int j = 0; j < group.children.size(); j++) |
---|
15414 | 15941 | { |
---|
15415 | 15942 | elem = (Object3D) group.children.elementAt(j); |
---|
15416 | | - object.editWindow.Select(elem.GetTreePath(), first, true); |
---|
| 15943 | + object.GetWindow().Select(elem.GetTreePath(), first, true); |
---|
15417 | 15944 | first = false; |
---|
15418 | 15945 | } |
---|
15419 | 15946 | } else |
---|
15420 | 15947 | { |
---|
15421 | | - object.editWindow.Select(elem.GetTreePath(), first, true); |
---|
| 15948 | + object.GetWindow().Select(elem.GetTreePath(), first, true); |
---|
15422 | 15949 | } |
---|
15423 | 15950 | |
---|
15424 | 15951 | first = false; |
---|
.. | .. |
---|
15429 | 15956 | { |
---|
15430 | 15957 | //Composite group = (Composite) object; |
---|
15431 | 15958 | Object3D group = object; |
---|
15432 | | - group.editWindow.loadClipboard(true); // ClearSelection(false); |
---|
| 15959 | + group.GetWindow().loadClipboard(true); // ClearSelection(false); |
---|
15433 | 15960 | } |
---|
15434 | 15961 | |
---|
15435 | 15962 | void ResetTransform(int mask) |
---|
15436 | 15963 | { |
---|
15437 | 15964 | //Composite group = (Composite) object; |
---|
15438 | 15965 | Object3D group = object; |
---|
15439 | | - group.editWindow.ResetTransform(mask); |
---|
| 15966 | + group.GetWindow().ResetTransform(mask); |
---|
15440 | 15967 | } |
---|
15441 | 15968 | |
---|
15442 | 15969 | void FlipTransform() |
---|
15443 | 15970 | { |
---|
15444 | 15971 | //Composite group = (Composite) object; |
---|
15445 | 15972 | Object3D group = object; |
---|
15446 | | - group.editWindow.FlipTransform(); |
---|
| 15973 | + group.GetWindow().FlipTransform(); |
---|
15447 | 15974 | // group.editWindow.ReduceMesh(true); |
---|
15448 | 15975 | } |
---|
15449 | 15976 | |
---|
.. | .. |
---|
15451 | 15978 | { |
---|
15452 | 15979 | //Composite group = (Composite) object; |
---|
15453 | 15980 | Object3D group = object; |
---|
15454 | | - group.editWindow.PrintMemory(); |
---|
| 15981 | + group.GetWindow().PrintMemory(); |
---|
15455 | 15982 | // group.editWindow.ReduceMesh(true); |
---|
15456 | 15983 | } |
---|
15457 | 15984 | |
---|
.. | .. |
---|
15459 | 15986 | { |
---|
15460 | 15987 | //Composite group = (Composite) object; |
---|
15461 | 15988 | Object3D group = object; |
---|
15462 | | - group.editWindow.ResetCentroid(); |
---|
| 15989 | + group.GetWindow().ResetCentroid(); |
---|
15463 | 15990 | } |
---|
15464 | 15991 | |
---|
15465 | 15992 | void IncDepth() |
---|
.. | .. |
---|
15541 | 16068 | |
---|
15542 | 16069 | int width = getBounds().width; |
---|
15543 | 16070 | int height = getBounds().height; |
---|
15544 | | - ClickInfo info = new ClickInfo(); |
---|
15545 | | - info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom)); |
---|
15546 | 16071 | //Image img = CreateImage(width, height); |
---|
15547 | 16072 | //System.out.println("width = " + width + "; height = " + height + "\n"); |
---|
15548 | 16073 | |
---|
.. | .. |
---|
15619 | 16144 | } |
---|
15620 | 16145 | if (object != null && !hasMarquee) |
---|
15621 | 16146 | { |
---|
| 16147 | + if (object.clickInfo == null) |
---|
| 16148 | + object.clickInfo = new ClickInfo(); |
---|
| 16149 | + ClickInfo info = object.clickInfo; |
---|
| 16150 | + //ClickInfo info = new ClickInfo(); |
---|
| 16151 | + info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom)); |
---|
| 16152 | + |
---|
15622 | 16153 | if (isRenderer) |
---|
15623 | 16154 | { |
---|
15624 | | - info.flags++; |
---|
| 16155 | + object.clickInfo.flags++; |
---|
15625 | 16156 | double frameAspect = (double) width / (double) height; |
---|
15626 | 16157 | if (frameAspect > renderCamera.aspect) |
---|
15627 | 16158 | { |
---|
15628 | 16159 | int desired = (int) ((double) height * renderCamera.aspect); |
---|
15629 | | - info.bounds.width -= width - desired; |
---|
15630 | | - info.bounds.x += (width - desired) / 2; |
---|
| 16160 | + object.clickInfo.bounds.width -= width - desired; |
---|
| 16161 | + object.clickInfo.bounds.x += (width - desired) / 2; |
---|
15631 | 16162 | } else |
---|
15632 | 16163 | { |
---|
15633 | 16164 | int desired = (int) ((double) width / renderCamera.aspect); |
---|
15634 | | - info.bounds.height -= height - desired; |
---|
15635 | | - info.bounds.y += (height - desired) / 2; |
---|
| 16165 | + object.clickInfo.bounds.height -= height - desired; |
---|
| 16166 | + object.clickInfo.bounds.y += (height - desired) / 2; |
---|
15636 | 16167 | } |
---|
15637 | 16168 | } |
---|
15638 | | - info.g = gr; |
---|
15639 | | - info.camera = renderCamera; |
---|
| 16169 | + |
---|
| 16170 | + object.clickInfo.g = gr; |
---|
| 16171 | + object.clickInfo.camera = renderCamera; |
---|
15640 | 16172 | /* |
---|
15641 | 16173 | // Memory intensive (brep.verticescopy) |
---|
15642 | 16174 | if (!(object instanceof Composite)) |
---|
15643 | 16175 | object.draw(info, 0, false); // SLOW : |
---|
15644 | 16176 | */ |
---|
15645 | | - if (!isRenderer) |
---|
| 16177 | + if (!isRenderer) // && drag) |
---|
15646 | 16178 | { |
---|
15647 | | - object.drawEditHandles(info, 0); |
---|
15648 | | - |
---|
15649 | | - if (drag && (X != 0 || Y != 0) && object.selection.Size() > 0) |
---|
| 16179 | + Grafreed.Assert(object != null); |
---|
| 16180 | + Grafreed.Assert(object.selection != null); |
---|
| 16181 | + if (object.selection.Size() > 0) |
---|
15650 | 16182 | { |
---|
15651 | | - switch (object.selection.get(0).hitSomething) |
---|
| 16183 | + int hitSomething = object.selection.get(0).hitSomething; |
---|
| 16184 | + |
---|
| 16185 | + object.clickInfo.DX = 0; |
---|
| 16186 | + object.clickInfo.DY = 0; |
---|
| 16187 | + object.clickInfo.W = 1; |
---|
| 16188 | + if (hitSomething == Object3D.hitCenter) |
---|
15652 | 16189 | { |
---|
15653 | | - case Object3D.hitCenter: gr.setColor(Color.pink); |
---|
15654 | | - gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
15655 | | - break; |
---|
15656 | | - case Object3D.hitRotate: gr.setColor(Color.yellow); |
---|
15657 | | - gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
15658 | | - break; |
---|
15659 | | - case Object3D.hitScale: gr.setColor(Color.cyan); |
---|
15660 | | - gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
15661 | | - break; |
---|
| 16190 | + info.DX = X; |
---|
| 16191 | + if (X != 0) |
---|
| 16192 | + info.DX -= info.bounds.width/2; |
---|
| 16193 | + |
---|
| 16194 | + info.DY = Y; |
---|
| 16195 | + if (Y != 0) |
---|
| 16196 | + info.DY -= info.bounds.height/2; |
---|
15662 | 16197 | } |
---|
15663 | | - |
---|
| 16198 | + |
---|
| 16199 | + object.drawEditHandles(//info, |
---|
| 16200 | + 0); |
---|
| 16201 | + |
---|
| 16202 | + if (drag && (X != 0 || Y != 0)) |
---|
| 16203 | + { |
---|
| 16204 | + switch (hitSomething) |
---|
| 16205 | + { |
---|
| 16206 | + case Object3D.hitCenter: gr.setColor(Color.white); |
---|
| 16207 | + gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
| 16208 | + break; |
---|
| 16209 | + case Object3D.hitRotate: gr.setColor(Color.yellow); |
---|
| 16210 | + gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
| 16211 | + break; |
---|
| 16212 | + case Object3D.hitScale: gr.setColor(Color.cyan); |
---|
| 16213 | + gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
| 16214 | + break; |
---|
| 16215 | + } |
---|
| 16216 | + |
---|
| 16217 | + } |
---|
15664 | 16218 | } |
---|
15665 | 16219 | } |
---|
15666 | 16220 | } |
---|
.. | .. |
---|
15675 | 16229 | if (hasMarquee) |
---|
15676 | 16230 | { |
---|
15677 | 16231 | gr.setXORMode(Color.white); |
---|
15678 | | - gr.setColor(Color.red); |
---|
| 16232 | + gr.setColor(Color.white); |
---|
15679 | 16233 | if (!firstime) |
---|
15680 | 16234 | { |
---|
15681 | 16235 | gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH); |
---|
.. | .. |
---|
16142 | 16696 | private /*static*/ boolean firstime; |
---|
16143 | 16697 | private /*static*/ cVector newView = new cVector(); |
---|
16144 | 16698 | private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"}; |
---|
| 16699 | + private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"}; |
---|
| 16700 | + private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"}; |
---|
16145 | 16701 | private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X, |
---|
16146 | 16702 | GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X, |
---|
16147 | 16703 | GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y, |
---|
.. | .. |
---|
16154 | 16710 | { |
---|
16155 | 16711 | com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP); |
---|
16156 | 16712 | |
---|
| 16713 | + int usedsuf = 0; |
---|
| 16714 | + |
---|
16157 | 16715 | for (int i = 0; i < suffixes.length; i++) |
---|
16158 | 16716 | { |
---|
16159 | | - String resourceName = basename + suffixes[i] + "." + suffix; |
---|
16160 | | - TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
16161 | | - mipmapped, |
---|
16162 | | - FileUtil.getFileSuffix(resourceName)); |
---|
16163 | | - if (data == null) |
---|
| 16717 | + String[] suffixe = suffixes; |
---|
| 16718 | + String[] fallback = suffixes2; |
---|
| 16719 | + String[] fallfallback = suffixes3; |
---|
| 16720 | + |
---|
| 16721 | + for (int c=usedsuf; --c>=0;) |
---|
16164 | 16722 | { |
---|
16165 | | - throw new IOException("Unable to load texture " + resourceName); |
---|
| 16723 | +// String[] temp = suffixe; |
---|
| 16724 | +// suffixe = fallback; |
---|
| 16725 | +// fallback = fallfallback; |
---|
| 16726 | +// fallfallback = temp; |
---|
16166 | 16727 | } |
---|
| 16728 | + |
---|
| 16729 | + String resourceName = basename + suffixe[i] + "." + suffix; |
---|
| 16730 | + TextureData data; |
---|
| 16731 | + |
---|
| 16732 | + try |
---|
| 16733 | + { |
---|
| 16734 | + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
| 16735 | + mipmapped, |
---|
| 16736 | + FileUtil.getFileSuffix(resourceName)); |
---|
| 16737 | + } |
---|
| 16738 | + catch (Exception e) |
---|
| 16739 | + { |
---|
| 16740 | + try |
---|
| 16741 | + { |
---|
| 16742 | + resourceName = basename + fallback[i] + "." + suffix; |
---|
| 16743 | + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
| 16744 | + mipmapped, |
---|
| 16745 | + FileUtil.getFileSuffix(resourceName)); |
---|
| 16746 | + } |
---|
| 16747 | + catch (Exception e2) |
---|
| 16748 | + { |
---|
| 16749 | + resourceName = basename + fallfallback[i] + "." + suffix; |
---|
| 16750 | + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
| 16751 | + mipmapped, |
---|
| 16752 | + FileUtil.getFileSuffix(resourceName)); |
---|
| 16753 | + } |
---|
| 16754 | + } |
---|
| 16755 | + |
---|
16167 | 16756 | //System.out.println("Target = " + targets[i]); |
---|
16168 | 16757 | cubemap.updateImage(data, targets[i]); |
---|
16169 | 16758 | } |
---|
16170 | 16759 | |
---|
16171 | 16760 | return cubemap; |
---|
16172 | 16761 | } |
---|
| 16762 | + |
---|
16173 | 16763 | int bigsphere = -1; |
---|
16174 | 16764 | |
---|
16175 | 16765 | float BGcolor = 0.5f; |
---|
16176 | 16766 | |
---|
16177 | | - private void DrawSkyBox(GL gl) |
---|
| 16767 | + float ambientLight[] = {1f, 1f, 1f, 1.0f}; |
---|
| 16768 | + |
---|
| 16769 | + private void DrawSkyBox(GL gl, float ratio) |
---|
16178 | 16770 | { |
---|
16179 | | - if (envyoff || cubemap == null) |
---|
| 16771 | + if (//envyoff || |
---|
| 16772 | + WIREFRAME || |
---|
| 16773 | + cubemap == null) |
---|
16180 | 16774 | { |
---|
16181 | 16775 | gl.glClearColor(BGcolor, BGcolor, BGcolor, 1); |
---|
16182 | 16776 | gl.glClear(gl.GL_COLOR_BUFFER_BIT); |
---|
.. | .. |
---|
16191 | 16785 | // Compensates for ExaminerViewer's modification of modelview matrix |
---|
16192 | 16786 | gl.glMatrixMode(GL.GL_MODELVIEW); |
---|
16193 | 16787 | gl.glLoadIdentity(); |
---|
| 16788 | + gl.glScalef(1,ratio,1); |
---|
16194 | 16789 | |
---|
| 16790 | +// colorV[0] = 2; |
---|
| 16791 | +// colorV[1] = 2; |
---|
| 16792 | +// colorV[2] = 2; |
---|
| 16793 | +// colorV[3] = 1; |
---|
| 16794 | +// gl.glDisable(gl.GL_COLOR_MATERIAL); |
---|
| 16795 | +// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0); |
---|
| 16796 | +// |
---|
| 16797 | +// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0); |
---|
| 16798 | + |
---|
16195 | 16799 | //gl.glActiveTexture(GL.GL_TEXTURE1); |
---|
16196 | 16800 | //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP); |
---|
16197 | 16801 | |
---|
.. | .. |
---|
16223 | 16827 | { |
---|
16224 | 16828 | gl.glScalef(1.0f, -1.0f, 1.0f); |
---|
16225 | 16829 | } |
---|
| 16830 | + gl.glScalef(-1.0f, 1.0f, 1.0f); |
---|
16226 | 16831 | gl.glMultMatrixd(viewrot_1, 0); |
---|
16227 | 16832 | gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f); |
---|
16228 | 16833 | //viewer.updateInverseRotation(gl); |
---|
.. | .. |
---|
16263 | 16868 | gl.glDisable(GL.GL_TEXTURE_GEN_R); |
---|
16264 | 16869 | |
---|
16265 | 16870 | cubemap.disable(); |
---|
16266 | | - ////cubemap.unbind(); |
---|
| 16871 | + //cubemap.dispose(); |
---|
| 16872 | + |
---|
16267 | 16873 | if (CULLFACE) |
---|
16268 | 16874 | { |
---|
16269 | 16875 | gl.glEnable(gl.GL_CULL_FACE); |
---|
.. | .. |
---|
16363 | 16969 | cStatic.objectstack[materialdepth++] = checker; |
---|
16364 | 16970 | //System.out.println("material " + material); |
---|
16365 | 16971 | //Applet3D.tracein(this, selected); |
---|
16366 | | - vector2buffer = checker.projectedVertices; |
---|
| 16972 | + //vector2buffer = checker.projectedVertices; |
---|
16367 | 16973 | |
---|
16368 | 16974 | //checker.GetMaterial().Draw(this, false); // true); |
---|
16369 | | - DrawMaterial(checker.GetMaterial(), false); // true); |
---|
| 16975 | + DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true); |
---|
16370 | 16976 | |
---|
16371 | 16977 | materialdepth -= 1; |
---|
16372 | 16978 | if (materialdepth > 0) |
---|
16373 | 16979 | { |
---|
16374 | | - vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices; |
---|
16375 | | - DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]); |
---|
| 16980 | + //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices; |
---|
| 16981 | + DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices); |
---|
16376 | 16982 | } |
---|
16377 | 16983 | //checker.GetMaterial().opacity = 1f; |
---|
16378 | 16984 | ////checker.GetMaterial().ambient = 1f; |
---|
.. | .. |
---|
16458 | 17064 | } |
---|
16459 | 17065 | } |
---|
16460 | 17066 | |
---|
| 17067 | + private Object3D GetFolder() |
---|
| 17068 | + { |
---|
| 17069 | + Object3D folder = object.GetWindow().copy; |
---|
| 17070 | + if (object.GetWindow().copy.selection.Size() > 0) |
---|
| 17071 | + folder = object.GetWindow().copy.selection.elementAt(0); |
---|
| 17072 | + return folder; |
---|
| 17073 | + } |
---|
| 17074 | + |
---|
16461 | 17075 | class SelectBuffer implements GLEventListener |
---|
16462 | 17076 | { |
---|
16463 | 17077 | |
---|
.. | .. |
---|
16473 | 17087 | //new Exception().printStackTrace(); |
---|
16474 | 17088 | System.out.println("select buffer init"); |
---|
16475 | 17089 | // Use debug pipeline |
---|
16476 | | - drawable.setGL(new DebugGL(drawable.getGL())); |
---|
| 17090 | + //drawable.setGL(new DebugGL(drawable.getGL())); |
---|
16477 | 17091 | |
---|
16478 | 17092 | GL gl = drawable.getGL(); |
---|
16479 | 17093 | |
---|
.. | .. |
---|
16537 | 17151 | |
---|
16538 | 17152 | //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL); |
---|
16539 | 17153 | |
---|
| 17154 | + if (PAINTMODE) |
---|
| 17155 | + { |
---|
| 17156 | + if (object.GetWindow().copy.selection.Size() > 0) |
---|
| 17157 | + { |
---|
| 17158 | + Object3D paintobj = object.GetWindow().copy.selection.elementAt(0); |
---|
| 17159 | + |
---|
| 17160 | + // Make what you paint not selectable. |
---|
| 17161 | + paintobj.ResetSelectable(); |
---|
| 17162 | + } |
---|
| 17163 | + } |
---|
| 17164 | + |
---|
16540 | 17165 | //int tmp = selection_view; |
---|
16541 | 17166 | //selection_view = -1; |
---|
16542 | 17167 | int temp = DrawMode(); |
---|
.. | .. |
---|
16548 | 17173 | // temp = DEFAULT; // patch for selection debug |
---|
16549 | 17174 | Globals.drawMode = temp; // WARNING |
---|
16550 | 17175 | |
---|
| 17176 | + if (PAINTMODE) |
---|
| 17177 | + { |
---|
| 17178 | + if (object.GetWindow().copy.selection.Size() > 0) |
---|
| 17179 | + { |
---|
| 17180 | + Object3D paintobj = object.GetWindow().copy.selection.elementAt(0); |
---|
| 17181 | + |
---|
| 17182 | + // Revert. |
---|
| 17183 | + paintobj.RestoreSelectable(); |
---|
| 17184 | + } |
---|
| 17185 | + } |
---|
| 17186 | + |
---|
16551 | 17187 | //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view); |
---|
16552 | 17188 | |
---|
16553 | 17189 | // trying different ways of getting the depth info over |
---|
.. | .. |
---|
16595 | 17231 | // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]); |
---|
16596 | 17232 | // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]); |
---|
16597 | 17233 | // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]); |
---|
| 17234 | + |
---|
| 17235 | + CreateSelectedPoint(); |
---|
16598 | 17236 | |
---|
16599 | 17237 | // Will fit the mesh !!! |
---|
16600 | 17238 | selectedpoint.toParent[0][0] = 0.0001; |
---|
.. | .. |
---|
16649 | 17287 | } |
---|
16650 | 17288 | |
---|
16651 | 17289 | if (!movingcamera && !PAINTMODE) |
---|
16652 | | - object.editWindow.ScreenFitPoint(); // fev 2014 |
---|
| 17290 | + object.GetWindow().ScreenFitPoint(); // fev 2014 |
---|
16653 | 17291 | |
---|
16654 | | - if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0) |
---|
| 17292 | + if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0) |
---|
16655 | 17293 | { |
---|
16656 | | - Object3D paintobj = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0); |
---|
| 17294 | + //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0); |
---|
16657 | 17295 | |
---|
16658 | | - Object3D group = new Object3D("inst" + paintcount++); |
---|
| 17296 | + if (object.GetWindow().copy.selection.Size() > 0) |
---|
| 17297 | + { |
---|
| 17298 | + Object3D paintobj = object.GetWindow().copy.selection.elementAt(0); |
---|
16659 | 17299 | |
---|
16660 | | - group.CreateMaterial(); // use a void leaf to select instances |
---|
16661 | | - |
---|
16662 | | - group.add(paintobj); // link |
---|
16663 | | - |
---|
16664 | | - object.editWindow.SnapObject(group); |
---|
16665 | | - |
---|
16666 | | - Object3D folder = object.editWindow.copy; |
---|
16667 | | - |
---|
16668 | | - if (object.editWindow.copy.selection.Size() > 0) |
---|
16669 | | - folder = object.editWindow.copy.selection.elementAt(0); |
---|
16670 | | - |
---|
16671 | | - folder.add(group); |
---|
16672 | | - |
---|
16673 | | - object.editWindow.ResetModel(); |
---|
16674 | | - object.editWindow.refreshContents(); |
---|
| 17300 | + Object3D inst = new Object3D("inst" + paintcount++); |
---|
| 17301 | + |
---|
| 17302 | + inst.CreateMaterial(); // use a void leaf to select instances |
---|
| 17303 | + |
---|
| 17304 | + inst.add(paintobj); // link |
---|
| 17305 | + |
---|
| 17306 | + object.GetWindow().SnapObject(inst); |
---|
| 17307 | + |
---|
| 17308 | + Object3D folder = paintFolder; // GetFolder(); |
---|
| 17309 | + |
---|
| 17310 | + folder.add(inst); |
---|
| 17311 | + |
---|
| 17312 | + object.GetWindow().ResetModel(); |
---|
| 17313 | + object.GetWindow().refreshContents(); |
---|
| 17314 | + } |
---|
16675 | 17315 | } |
---|
16676 | 17316 | else |
---|
16677 | 17317 | paintcount = 0; |
---|
.. | .. |
---|
16710 | 17350 | //System.out.println("objects[color] = " + objects[color]); |
---|
16711 | 17351 | //objects[color].Select(); |
---|
16712 | 17352 | indexcount = 0; |
---|
| 17353 | + ObjEditor window = object.GetWindow(); |
---|
| 17354 | + if (window != null && deselect) |
---|
| 17355 | + { |
---|
| 17356 | + window.Select(null, deselect, true); |
---|
| 17357 | + } |
---|
16713 | 17358 | object.Select(color, deselect); |
---|
16714 | 17359 | } |
---|
16715 | 17360 | |
---|
.. | .. |
---|
16760 | 17405 | |
---|
16761 | 17406 | public void init(GLAutoDrawable drawable) |
---|
16762 | 17407 | { |
---|
| 17408 | + if (Globals.DEBUG) |
---|
16763 | 17409 | System.out.println("shadow buffer init"); |
---|
16764 | 17410 | |
---|
16765 | 17411 | GL gl = drawable.getGL(); |
---|
.. | .. |
---|
16988 | 17634 | gl.glFlush(); |
---|
16989 | 17635 | |
---|
16990 | 17636 | /**/ |
---|
16991 | | - gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer); |
---|
| 17637 | + gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer); |
---|
16992 | 17638 | |
---|
16993 | | - float[] pixels = occlusionsizebuffer.array(); |
---|
| 17639 | + float[] depths = occlusiondepthbuffer.array(); |
---|
16994 | 17640 | |
---|
| 17641 | + gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer); |
---|
| 17642 | + |
---|
| 17643 | + int[] pixels = selectsizebuffer.array(); |
---|
| 17644 | + |
---|
16995 | 17645 | double r = 0, g = 0, b = 0; |
---|
16996 | 17646 | |
---|
16997 | 17647 | double count = 0; |
---|
.. | .. |
---|
17002 | 17652 | |
---|
17003 | 17653 | double FACTOR = 1; |
---|
17004 | 17654 | |
---|
17005 | | - for (int i = 0; i < pixels.length; i++) |
---|
| 17655 | + for (int i = 0; i < depths.length; i++) |
---|
17006 | 17656 | { |
---|
17007 | 17657 | int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2; |
---|
17008 | 17658 | int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2; |
---|
.. | .. |
---|
17085 | 17735 | |
---|
17086 | 17736 | double scale = ray.z; // 1; // cos |
---|
17087 | 17737 | |
---|
17088 | | - float depth = pixels[newindex]; |
---|
| 17738 | + float depth = depths[newindex]; |
---|
17089 | 17739 | |
---|
17090 | 17740 | /* |
---|
17091 | 17741 | int newindex2 = (x + 1) * OCCLUSION_SIZE + y; |
---|
.. | .. |
---|
17235 | 17885 | int AAbuffersize = 0; |
---|
17236 | 17886 | |
---|
17237 | 17887 | //double[] selectedpoint = new double[3]; |
---|
17238 | | - static Superellipsoid selectedpoint = new Superellipsoid(); |
---|
| 17888 | + static Superellipsoid selectedpoint; |
---|
17239 | 17889 | static Sphere previousselectedpoint = null; |
---|
17240 | | - static Sphere debugpointG = new Sphere(); |
---|
17241 | | - static Sphere debugpointP = new Sphere(); |
---|
17242 | | - static Sphere debugpointC = new Sphere(); |
---|
17243 | | - static Sphere debugpointR = new Sphere(); |
---|
| 17890 | + static Sphere debugpointG; |
---|
| 17891 | + static Sphere debugpointP; |
---|
| 17892 | + static Sphere debugpointC; |
---|
| 17893 | + static Sphere debugpointR; |
---|
17244 | 17894 | |
---|
17245 | 17895 | static Sphere debugpoints[] = new Sphere[8]; |
---|
17246 | 17896 | |
---|
17247 | | - static |
---|
17248 | | - { |
---|
17249 | | - for (int i=0; i<8; i++) |
---|
17250 | | - { |
---|
17251 | | - debugpoints[i] = new Sphere(); |
---|
17252 | | - } |
---|
17253 | | - } |
---|
17254 | | - |
---|
17255 | 17897 | static void InitPoints(float radius) |
---|
17256 | 17898 | { |
---|
17257 | 17899 | for (int i=0; i<8; i++) |
---|
.. | .. |
---|
17290 | 17932 | static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE); |
---|
17291 | 17933 | static IntBuffer bigAAbuffer; |
---|
17292 | 17934 | static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3); |
---|
17293 | | - static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE); |
---|
| 17935 | + //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE); |
---|
17294 | 17936 | static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE); |
---|
17295 | 17937 | static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE); |
---|
17296 | 17938 | //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); |
---|
17297 | | - static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); |
---|
| 17939 | + static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); |
---|
| 17940 | + |
---|
| 17941 | + static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); |
---|
| 17942 | + |
---|
17298 | 17943 | static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB); |
---|
17299 | 17944 | static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); |
---|
17300 | 17945 | static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>(); |
---|