.. | .. |
---|
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; |
---|
.. | .. |
---|
150 | 186 | defaultcaps.setAccumAlphaBits(16); |
---|
151 | 187 | } |
---|
152 | 188 | |
---|
| 189 | + private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory(); |
---|
| 190 | + |
---|
153 | 191 | void SetAsGLRenderer(boolean b) |
---|
154 | 192 | { |
---|
155 | 193 | isRenderer = b; |
---|
.. | .. |
---|
168 | 206 | |
---|
169 | 207 | SetCamera(cam); |
---|
170 | 208 | |
---|
171 | | - SetLight(new Camera(new cVector(10, 10, -20))); |
---|
| 209 | + // Warning: not used. |
---|
| 210 | + SetLight(new Camera(new cVector(15, 10, -20))); |
---|
172 | 211 | |
---|
173 | 212 | object = o; |
---|
174 | 213 | |
---|
.. | .. |
---|
325 | 364 | cStatic.objectstack[materialdepth++] = obj; |
---|
326 | 365 | //System.out.println("material " + material); |
---|
327 | 366 | //Applet3D.tracein(this, selected); |
---|
328 | | - display.vector2buffer = obj.projectedVertices; |
---|
| 367 | + //display.vector2buffer = obj.projectedVertices; |
---|
329 | 368 | if (obj instanceof Camera) |
---|
330 | 369 | { |
---|
331 | 370 | display.options1[0] = material.shift; |
---|
.. | .. |
---|
334 | 373 | display.options1[2] = material.shadowbias; |
---|
335 | 374 | display.options1[3] = material.aniso; |
---|
336 | 375 | display.options1[4] = material.anisoV; |
---|
| 376 | +// System.out.println("display.options1[0] " + display.options1[0]); |
---|
| 377 | +// System.out.println("display.options1[1] " + display.options1[1]); |
---|
| 378 | +// System.out.println("display.options1[2] " + display.options1[2]); |
---|
| 379 | +// System.out.println("display.options1[3] " + display.options1[3]); |
---|
| 380 | +// System.out.println("display.options1[4] " + display.options1[4]); |
---|
337 | 381 | display.options2[0] = material.opacity; |
---|
338 | 382 | display.options2[1] = material.diffuse; |
---|
339 | 383 | display.options2[2] = material.factor; |
---|
| 384 | +// System.out.println("display.options2[0] " + display.options2[0]); |
---|
| 385 | +// System.out.println("display.options2[1] " + display.options2[1]); |
---|
| 386 | +// System.out.println("display.options2[2] " + display.options2[2]); |
---|
340 | 387 | |
---|
341 | 388 | cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3); |
---|
| 389 | +// System.out.println("display.options3[0] " + display.options3[0]); |
---|
| 390 | +// System.out.println("display.options3[1] " + display.options3[1]); |
---|
| 391 | +// System.out.println("display.options3[2] " + display.options3[2]); |
---|
342 | 392 | display.options4[0] = material.cameralight/0.2f; |
---|
343 | 393 | display.options4[1] = material.subsurface; |
---|
344 | 394 | display.options4[2] = material.sheen; |
---|
| 395 | +// System.out.println("display.options4[0] " + display.options4[0]); |
---|
| 396 | +// System.out.println("display.options4[1] " + display.options4[1]); |
---|
| 397 | +// System.out.println("display.options4[2] " + display.options4[2]); |
---|
345 | 398 | |
---|
346 | 399 | // if (display.CURRENTANTIALIAS > 0) |
---|
347 | 400 | // display.options3[3] /= 4; |
---|
.. | .. |
---|
357 | 410 | /**/ |
---|
358 | 411 | } else |
---|
359 | 412 | { |
---|
360 | | - DrawMaterial(material, selected); |
---|
| 413 | + DrawMaterial(material, selected, obj.projectedVertices); |
---|
361 | 414 | } |
---|
362 | 415 | } else |
---|
363 | 416 | { |
---|
.. | .. |
---|
381 | 434 | cStatic.objectstack[materialdepth++] = obj; |
---|
382 | 435 | //System.out.println("material " + material); |
---|
383 | 436 | //Applet3D.tracein("selected ", selected); |
---|
384 | | - display.vector2buffer = obj.projectedVertices; |
---|
385 | | - display.DrawMaterial(material, selected); |
---|
| 437 | + //display.vector2buffer = obj.projectedVertices; |
---|
| 438 | + display.DrawMaterial(material, selected, obj.projectedVertices); |
---|
386 | 439 | } |
---|
387 | 440 | } |
---|
388 | 441 | |
---|
.. | .. |
---|
399 | 452 | materialdepth -= 1; |
---|
400 | 453 | if (materialdepth > 0) |
---|
401 | 454 | { |
---|
402 | | - display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices; |
---|
403 | | - display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]); |
---|
| 455 | + //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices; |
---|
| 456 | + display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices); |
---|
404 | 457 | } |
---|
405 | 458 | //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???"); |
---|
406 | 459 | } else if (selected && CameraPane.flash && obj.GetMaterial() != null) |
---|
.. | .. |
---|
420 | 473 | materialdepth -= 1; |
---|
421 | 474 | if (materialdepth > 0) |
---|
422 | 475 | { |
---|
423 | | - display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices; |
---|
424 | | - display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]); |
---|
| 476 | + //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices; |
---|
| 477 | + display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices); |
---|
425 | 478 | } |
---|
426 | 479 | //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???"); |
---|
427 | 480 | //else |
---|
.. | .. |
---|
462 | 515 | if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0) |
---|
463 | 516 | { |
---|
464 | 517 | //gl.glBegin(gl.GL_TRIANGLES); |
---|
465 | | - boolean hasnorm = pv.norm != null; // && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0); |
---|
| 518 | + boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0) |
---|
| 519 | + // TEST LIVE NORMALS && !obj.dontselect |
---|
| 520 | + ; |
---|
466 | 521 | if (!hasnorm) |
---|
467 | 522 | { |
---|
468 | | - // System.out.println("FUCK!!"); |
---|
| 523 | + // System.out.println("Mesh normal"); |
---|
469 | 524 | LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0); |
---|
470 | 525 | LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1); |
---|
471 | 526 | LA.vecCross(obj.v0, obj.v1, obj.v2); |
---|
.. | .. |
---|
1190 | 1245 | gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1); |
---|
1191 | 1246 | } |
---|
1192 | 1247 | } |
---|
| 1248 | + |
---|
1193 | 1249 | if (flipV) |
---|
1194 | 1250 | gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]); |
---|
1195 | 1251 | else |
---|
1196 | 1252 | gl.glTexCoord2f(uv[count2], uv[count2 + 1]); |
---|
| 1253 | + |
---|
1197 | 1254 | //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]); |
---|
1198 | 1255 | gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]); |
---|
1199 | 1256 | |
---|
.. | .. |
---|
1213 | 1270 | gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1); |
---|
1214 | 1271 | } |
---|
1215 | 1272 | } |
---|
| 1273 | + |
---|
1216 | 1274 | if (flipV) |
---|
1217 | 1275 | gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]); |
---|
1218 | 1276 | else |
---|
1219 | 1277 | gl.glTexCoord2f(uv[count2], uv[count2 + 1]); |
---|
| 1278 | + |
---|
1220 | 1279 | //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]); |
---|
1221 | 1280 | gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]); |
---|
1222 | 1281 | |
---|
.. | .. |
---|
1244 | 1303 | gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]); |
---|
1245 | 1304 | else |
---|
1246 | 1305 | gl.glTexCoord2f(uv[count2], uv[count2 + 1]); |
---|
| 1306 | + |
---|
1247 | 1307 | //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]); |
---|
1248 | 1308 | gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]); |
---|
| 1309 | + |
---|
1249 | 1310 | count2 += 2; |
---|
1250 | 1311 | count3 += 3; |
---|
1251 | 1312 | } |
---|
.. | .. |
---|
1601 | 1662 | // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0); |
---|
1602 | 1663 | } |
---|
1603 | 1664 | |
---|
1604 | | - void DrawMaterial(cMaterial material, boolean selected) |
---|
| 1665 | + void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others) |
---|
1605 | 1666 | { |
---|
1606 | 1667 | CameraPane display = this; |
---|
1607 | 1668 | //new Exception().printStackTrace(); |
---|
.. | .. |
---|
1636 | 1697 | colorV[0] = display.modelParams0[0] * material.diffuse; |
---|
1637 | 1698 | colorV[1] = display.modelParams0[1] * material.diffuse; |
---|
1638 | 1699 | colorV[2] = display.modelParams0[2] * material.diffuse; |
---|
1639 | | - colorV[3] = material.opacity; |
---|
| 1700 | + colorV[3] = 1; // material.opacity; |
---|
1640 | 1701 | |
---|
1641 | 1702 | gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity); |
---|
1642 | 1703 | //System.out.println("Opacity = " + opacity); |
---|
.. | .. |
---|
1744 | 1805 | display.modelParams7[2] = 0; |
---|
1745 | 1806 | display.modelParams7[3] = 0; |
---|
1746 | 1807 | |
---|
1747 | | - display.modelParams6[0] = 100; // criss de bug de bump |
---|
| 1808 | + //display.modelParams6[0] = 100; // criss de bug de bump |
---|
1748 | 1809 | |
---|
1749 | | - Object3D.cVector2[] extparams = display.vector2buffer; |
---|
| 1810 | + Object3D.cVector2[] extparams = others; // display.vector2buffer; |
---|
1750 | 1811 | if (extparams != null && extparams.length > 0 && extparams[0] != null) |
---|
1751 | 1812 | { |
---|
1752 | 1813 | display.modelParams6[0] = extparams[0].x / 1000.0f; // bump |
---|
.. | .. |
---|
1888 | 1949 | void PushMatrix(double[][] matrix) |
---|
1889 | 1950 | { |
---|
1890 | 1951 | // GrafreeD.tracein(matrix); |
---|
1891 | | - PushMatrix(matrix,1); |
---|
| 1952 | + PushMatrix(matrix, 1); |
---|
1892 | 1953 | } |
---|
1893 | 1954 | |
---|
1894 | 1955 | void PushMatrix() |
---|
.. | .. |
---|
2042 | 2103 | //System.err.println("Oeil on"); |
---|
2043 | 2104 | OEIL = true; |
---|
2044 | 2105 | if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode) |
---|
2045 | | - object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK); |
---|
| 2106 | + object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK); |
---|
2046 | 2107 | //pingthread.StepToTarget(true); |
---|
2047 | 2108 | } |
---|
2048 | 2109 | |
---|
.. | .. |
---|
2257 | 2318 | |
---|
2258 | 2319 | void ToggleDebug() |
---|
2259 | 2320 | { |
---|
2260 | | - DEBUG ^= true; |
---|
| 2321 | + Globals.DEBUG ^= true; |
---|
2261 | 2322 | } |
---|
2262 | 2323 | |
---|
2263 | 2324 | void ToggleLookAt() |
---|
.. | .. |
---|
2265 | 2326 | LOOKAT ^= true; |
---|
2266 | 2327 | } |
---|
2267 | 2328 | |
---|
2268 | | - void ToggleRandom() |
---|
| 2329 | + void ToggleSwitch() |
---|
2269 | 2330 | { |
---|
2270 | 2331 | SWITCH ^= true; |
---|
2271 | 2332 | } |
---|
.. | .. |
---|
2275 | 2336 | HANDLES ^= true; |
---|
2276 | 2337 | } |
---|
2277 | 2338 | |
---|
| 2339 | + Object3D paintFolder; |
---|
| 2340 | + |
---|
2278 | 2341 | void TogglePaint() |
---|
2279 | 2342 | { |
---|
2280 | 2343 | PAINTMODE ^= true; |
---|
2281 | 2344 | paintcount = 0; |
---|
| 2345 | + |
---|
| 2346 | + if (PAINTMODE) |
---|
| 2347 | + { |
---|
| 2348 | + paintFolder = GetFolder(); |
---|
| 2349 | + } |
---|
2282 | 2350 | } |
---|
2283 | 2351 | |
---|
2284 | 2352 | void SwapCamera(int a, int b) |
---|
.. | .. |
---|
2374 | 2442 | { |
---|
2375 | 2443 | return currentGL; |
---|
2376 | 2444 | } |
---|
2377 | | - |
---|
| 2445 | + |
---|
| 2446 | + static private BufferedImage CreateBim(TextureData texturedata) |
---|
| 2447 | + { |
---|
| 2448 | + Grafreed.Assert(texturedata != null); |
---|
| 2449 | + |
---|
| 2450 | + int width = texturedata.getWidth(); |
---|
| 2451 | + int height = texturedata.getHeight(); |
---|
| 2452 | + |
---|
| 2453 | + Buffer buffer = texturedata.getBuffer(); |
---|
| 2454 | + ByteBuffer bytebuf = (ByteBuffer)buffer; |
---|
| 2455 | + |
---|
| 2456 | + byte[] bytes = bytebuf.array(); |
---|
| 2457 | + |
---|
| 2458 | + return CreateBim(bytes, width, height); |
---|
| 2459 | + } |
---|
| 2460 | + |
---|
2378 | 2461 | /**/ |
---|
2379 | 2462 | class CacheTexture |
---|
2380 | 2463 | { |
---|
.. | .. |
---|
2383 | 2466 | |
---|
2384 | 2467 | int resolution; |
---|
2385 | 2468 | |
---|
2386 | | - CacheTexture(com.sun.opengl.util.texture.Texture tex, int res) |
---|
| 2469 | + CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res) |
---|
2387 | 2470 | { |
---|
2388 | | - texture = tex; |
---|
| 2471 | + texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata); |
---|
| 2472 | + texturedata = texdata; |
---|
2389 | 2473 | resolution = res; |
---|
2390 | 2474 | } |
---|
2391 | 2475 | } |
---|
2392 | 2476 | /**/ |
---|
2393 | 2477 | |
---|
2394 | 2478 | // TEXTURE static Texture texture; |
---|
2395 | | - static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures |
---|
2396 | | - = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>(); |
---|
2397 | | - static public java.util.Hashtable<String, String> usedtextures = new java.util.Hashtable<String, String>(); |
---|
| 2479 | + static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>(); |
---|
| 2480 | + static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>(); |
---|
| 2481 | + static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>(); |
---|
| 2482 | + static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>(); |
---|
| 2483 | + |
---|
2398 | 2484 | int pigmentdepth = 0; |
---|
2399 | 2485 | public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536]; |
---|
2400 | 2486 | int bumpdepth = 0; |
---|
2401 | 2487 | public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536]; |
---|
2402 | 2488 | //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE"; |
---|
2403 | 2489 | public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP"); |
---|
2404 | | - public static String NOISE_TEXTURE = "WHITE_NOISE"; |
---|
| 2490 | + public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:"); |
---|
2405 | 2491 | // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL"); |
---|
2406 | 2492 | |
---|
2407 | | - com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump) |
---|
| 2493 | + com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump) |
---|
2408 | 2494 | { |
---|
2409 | 2495 | TextureData texturedata = null; |
---|
2410 | 2496 | |
---|
.. | .. |
---|
2423 | 2509 | if (bump) |
---|
2424 | 2510 | texturedata = ConvertBump(texturedata, false); |
---|
2425 | 2511 | |
---|
2426 | | - com.sun.opengl.util.texture.Texture texture = |
---|
2427 | | - com.sun.opengl.util.texture.TextureIO.newTexture(texturedata); |
---|
| 2512 | +// com.sun.opengl.util.texture.Texture texture = |
---|
| 2513 | +// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata); |
---|
2428 | 2514 | |
---|
2429 | | - texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT); |
---|
2430 | | - texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT); |
---|
| 2515 | + //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT); |
---|
| 2516 | + //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT); |
---|
2431 | 2517 | |
---|
2432 | | - return texture; |
---|
| 2518 | + return texturedata; |
---|
| 2519 | + } |
---|
| 2520 | + |
---|
| 2521 | + com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump) |
---|
| 2522 | + { |
---|
| 2523 | + TextureData texturedata = null; |
---|
| 2524 | + |
---|
| 2525 | + try |
---|
| 2526 | + { |
---|
| 2527 | + texturedata = |
---|
| 2528 | + com.sun.opengl.util.texture.TextureIO.newTextureData( |
---|
| 2529 | + bim, |
---|
| 2530 | + true); |
---|
| 2531 | + } catch (Exception e) |
---|
| 2532 | + { |
---|
| 2533 | + throw new javax.media.opengl.GLException(e); |
---|
| 2534 | + } |
---|
| 2535 | + |
---|
| 2536 | + if (bump) |
---|
| 2537 | + texturedata = ConvertBump(texturedata, false); |
---|
| 2538 | + |
---|
| 2539 | + return texturedata; |
---|
2433 | 2540 | } |
---|
2434 | 2541 | |
---|
2435 | 2542 | boolean HUESMOOTH = true; // wrap around bug... true; |
---|
.. | .. |
---|
3502 | 3609 | |
---|
3503 | 3610 | System.out.println("LOADING TEXTURE : " + name); |
---|
3504 | 3611 | |
---|
| 3612 | + Object x = texturedata.getMipmapData(); // .getBuffer(); |
---|
| 3613 | + |
---|
3505 | 3614 | // |
---|
3506 | 3615 | if (false) // compressbit > 0) |
---|
3507 | 3616 | { |
---|
.. | .. |
---|
7900 | 8009 | String pigment = Object3D.GetPigment(tex); |
---|
7901 | 8010 | String bump = Object3D.GetBump(tex); |
---|
7902 | 8011 | |
---|
7903 | | - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8012 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
7904 | 8013 | { |
---|
7905 | 8014 | // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment); |
---|
7906 | 8015 | // System.out.println("; bump = " + bump); |
---|
.. | .. |
---|
7915 | 8024 | pigment = null; |
---|
7916 | 8025 | } |
---|
7917 | 8026 | |
---|
7918 | | - ReleaseTexture(bump, true); |
---|
7919 | | - ReleaseTexture(pigment, false); |
---|
| 8027 | + ReleaseTexture(tex, true); |
---|
| 8028 | + ReleaseTexture(tex, false); |
---|
7920 | 8029 | } |
---|
7921 | 8030 | |
---|
7922 | | - void ReleaseTexture(String tex, boolean bump) |
---|
| 8031 | + public void ReleasePigmentTexture(cTexture tex) // INTERFACE |
---|
| 8032 | + { |
---|
| 8033 | + if (/*tex == null ||*/ ambientOcclusion ) // || !textureon) |
---|
| 8034 | + { |
---|
| 8035 | + return; |
---|
| 8036 | + } |
---|
| 8037 | + |
---|
| 8038 | + if (tex == null) |
---|
| 8039 | + { |
---|
| 8040 | + ReleaseTexture(null, false); |
---|
| 8041 | + return; |
---|
| 8042 | + } |
---|
| 8043 | + |
---|
| 8044 | + String pigment = Object3D.GetPigment(tex); |
---|
| 8045 | + |
---|
| 8046 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8047 | + { |
---|
| 8048 | + // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment); |
---|
| 8049 | + // System.out.println("; bump = " + bump); |
---|
| 8050 | + } |
---|
| 8051 | + |
---|
| 8052 | + if (pigment.equals("")) |
---|
| 8053 | + { |
---|
| 8054 | + pigment = null; |
---|
| 8055 | + } |
---|
| 8056 | + |
---|
| 8057 | + ReleaseTexture(tex, false); |
---|
| 8058 | + } |
---|
| 8059 | + |
---|
| 8060 | + public void ReleaseBumpTexture(cTexture tex) // INTERFACE |
---|
| 8061 | + { |
---|
| 8062 | + if (/*tex == null ||*/ ambientOcclusion ) // || !textureon) |
---|
| 8063 | + { |
---|
| 8064 | + return; |
---|
| 8065 | + } |
---|
| 8066 | + |
---|
| 8067 | + if (tex == null) |
---|
| 8068 | + { |
---|
| 8069 | + ReleaseTexture(null, true); |
---|
| 8070 | + return; |
---|
| 8071 | + } |
---|
| 8072 | + |
---|
| 8073 | + String bump = Object3D.GetBump(tex); |
---|
| 8074 | + |
---|
| 8075 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8076 | + { |
---|
| 8077 | + // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment); |
---|
| 8078 | + // System.out.println("; bump = " + bump); |
---|
| 8079 | + } |
---|
| 8080 | + |
---|
| 8081 | + if (bump.equals("")) |
---|
| 8082 | + { |
---|
| 8083 | + bump = null; |
---|
| 8084 | + } |
---|
| 8085 | + |
---|
| 8086 | + ReleaseTexture(tex, true); |
---|
| 8087 | + } |
---|
| 8088 | + |
---|
| 8089 | + void ReleaseTexture(cTexture tex, boolean bump) |
---|
7923 | 8090 | { |
---|
7924 | 8091 | if (// DrawMode() != 0 || /*tex == null ||*/ |
---|
7925 | 8092 | ambientOcclusion ) // || !textureon) |
---|
.. | .. |
---|
7930 | 8097 | CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null; |
---|
7931 | 8098 | |
---|
7932 | 8099 | if (tex != null) |
---|
7933 | | - texture = textures.get(tex); |
---|
| 8100 | + texture = bump ? texturebump.get(tex) : texturepigment.get(tex); |
---|
7934 | 8101 | |
---|
7935 | 8102 | // //assert( texture != null ); |
---|
7936 | 8103 | // if (texture == null) |
---|
.. | .. |
---|
8022 | 8189 | } |
---|
8023 | 8190 | } |
---|
8024 | 8191 | |
---|
8025 | | - /*boolean*/ public void BindTextures(cTexture tex, int resolution) // INTERFACE |
---|
| 8192 | + /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE |
---|
| 8193 | + { |
---|
| 8194 | +// if (// DrawMode() != 0 || /*tex == null ||*/ |
---|
| 8195 | +// ambientOcclusion ) // || !textureon) |
---|
| 8196 | +// { |
---|
| 8197 | +// return; // false; |
---|
| 8198 | +// } |
---|
| 8199 | +// |
---|
| 8200 | +// if (tex == null) |
---|
| 8201 | +// { |
---|
| 8202 | +// BindTexture(null,false,resolution); |
---|
| 8203 | +// BindTexture(null,true,resolution); |
---|
| 8204 | +// return; |
---|
| 8205 | +// } |
---|
| 8206 | +// |
---|
| 8207 | +// String pigment = Object3D.GetPigment(tex); |
---|
| 8208 | +// String bump = Object3D.GetBump(tex); |
---|
| 8209 | +// |
---|
| 8210 | +// usedtextures.add(pigment); |
---|
| 8211 | +// usedtextures.add(bump); |
---|
| 8212 | +// |
---|
| 8213 | +// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8214 | +// { |
---|
| 8215 | +// // System.out.print("BIND +++++++++++++++ pigment = " + pigment); |
---|
| 8216 | +// // System.out.println("; bump = " + bump); |
---|
| 8217 | +// } |
---|
| 8218 | +// |
---|
| 8219 | +// if (bump.equals("")) |
---|
| 8220 | +// { |
---|
| 8221 | +// bump = null; |
---|
| 8222 | +// } |
---|
| 8223 | +// if (pigment.equals("")) |
---|
| 8224 | +// { |
---|
| 8225 | +// pigment = null; |
---|
| 8226 | +// } |
---|
| 8227 | +// |
---|
| 8228 | +// GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
| 8229 | +// BindTexture(pigment, false, resolution); |
---|
| 8230 | +// GetGL().glActiveTexture(GetGL().GL_TEXTURE2); |
---|
| 8231 | +// BindTexture(bump, true, resolution); |
---|
| 8232 | +// GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
| 8233 | +// |
---|
| 8234 | +// return; // true; |
---|
| 8235 | + |
---|
| 8236 | + BindPigmentTexture(tex, resolution); |
---|
| 8237 | + BindBumpTexture(tex, resolution); |
---|
| 8238 | + } |
---|
| 8239 | + |
---|
| 8240 | + /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE |
---|
8026 | 8241 | { |
---|
8027 | 8242 | if (// DrawMode() != 0 || /*tex == null ||*/ |
---|
8028 | 8243 | ambientOcclusion ) // || !textureon) |
---|
.. | .. |
---|
8033 | 8248 | if (tex == null) |
---|
8034 | 8249 | { |
---|
8035 | 8250 | BindTexture(null,false,resolution); |
---|
8036 | | - BindTexture(null,true,resolution); |
---|
8037 | 8251 | return; |
---|
8038 | 8252 | } |
---|
8039 | 8253 | |
---|
8040 | 8254 | String pigment = Object3D.GetPigment(tex); |
---|
| 8255 | + |
---|
| 8256 | + usedtextures.add(tex); |
---|
| 8257 | + |
---|
| 8258 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8259 | + { |
---|
| 8260 | + // System.out.print("BIND +++++++++++++++ pigment = " + pigment); |
---|
| 8261 | + // System.out.println("; bump = " + bump); |
---|
| 8262 | + } |
---|
| 8263 | + |
---|
| 8264 | + if (pigment.equals("")) |
---|
| 8265 | + { |
---|
| 8266 | + pigment = null; |
---|
| 8267 | + } |
---|
| 8268 | + |
---|
| 8269 | + GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
| 8270 | + BindTexture(tex, false, resolution); |
---|
| 8271 | + } |
---|
| 8272 | + |
---|
| 8273 | + /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE |
---|
| 8274 | + { |
---|
| 8275 | + if (// DrawMode() != 0 || /*tex == null ||*/ |
---|
| 8276 | + ambientOcclusion ) // || !textureon) |
---|
| 8277 | + { |
---|
| 8278 | + return; // false; |
---|
| 8279 | + } |
---|
| 8280 | + |
---|
| 8281 | + if (tex == null) |
---|
| 8282 | + { |
---|
| 8283 | + BindTexture(null,true,resolution); |
---|
| 8284 | + return; |
---|
| 8285 | + } |
---|
| 8286 | + |
---|
8041 | 8287 | String bump = Object3D.GetBump(tex); |
---|
8042 | 8288 | |
---|
8043 | | - usedtextures.put(pigment, pigment); |
---|
8044 | | - usedtextures.put(bump, bump); |
---|
| 8289 | + usedtextures.add(tex); |
---|
8045 | 8290 | |
---|
8046 | | - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8291 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
8047 | 8292 | { |
---|
8048 | 8293 | // System.out.print("BIND +++++++++++++++ pigment = " + pigment); |
---|
8049 | 8294 | // System.out.println("; bump = " + bump); |
---|
.. | .. |
---|
8053 | 8298 | { |
---|
8054 | 8299 | bump = null; |
---|
8055 | 8300 | } |
---|
8056 | | - if (pigment.equals("")) |
---|
8057 | | - { |
---|
8058 | | - pigment = null; |
---|
8059 | | - } |
---|
8060 | 8301 | |
---|
8061 | | - GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
8062 | | - BindTexture(pigment, false, resolution); |
---|
8063 | 8302 | GetGL().glActiveTexture(GetGL().GL_TEXTURE2); |
---|
8064 | | - BindTexture(bump, true, resolution); |
---|
| 8303 | + BindTexture(tex, true, resolution); |
---|
8065 | 8304 | GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
8066 | | - |
---|
8067 | | - return; // true; |
---|
8068 | 8305 | } |
---|
8069 | 8306 | |
---|
8070 | | - CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) |
---|
| 8307 | + java.util.HashSet<String> missingTextures = new java.util.HashSet<String>(); |
---|
| 8308 | + |
---|
| 8309 | + private boolean FileExists(String tex) |
---|
8071 | 8310 | { |
---|
8072 | | - CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null; |
---|
| 8311 | + if (missingTextures.contains(tex)) |
---|
| 8312 | + { |
---|
| 8313 | + return false; |
---|
| 8314 | + } |
---|
| 8315 | + |
---|
| 8316 | + boolean fileExists = new File(tex).exists(); |
---|
| 8317 | + |
---|
| 8318 | + if (!fileExists) |
---|
| 8319 | + { |
---|
| 8320 | + // If file exists, the "new File()" is not executed sgain |
---|
| 8321 | + missingTextures.add(tex); |
---|
| 8322 | + } |
---|
| 8323 | + |
---|
| 8324 | + return fileExists; |
---|
| 8325 | + } |
---|
| 8326 | + |
---|
| 8327 | + CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception |
---|
| 8328 | + { |
---|
| 8329 | + CacheTexture texturecache = null; |
---|
8073 | 8330 | |
---|
8074 | 8331 | if (tex != null) |
---|
8075 | 8332 | { |
---|
8076 | | - String texname = tex; |
---|
| 8333 | + String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex); |
---|
| 8334 | + byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata; |
---|
8077 | 8335 | |
---|
| 8336 | + if (texname.equals("") && texdata == null) |
---|
| 8337 | + { |
---|
| 8338 | + return null; |
---|
| 8339 | + } |
---|
| 8340 | + |
---|
| 8341 | + String fallbackTextureName = defaultDirectory + "/Textures/" + texname; |
---|
| 8342 | + |
---|
8078 | 8343 | // String[] split = tex.split("Textures"); |
---|
8079 | 8344 | // if (split.length > 1) |
---|
8080 | 8345 | // texname = "/Users/nbriere/Textures" + split[split.length-1]; |
---|
8081 | 8346 | // else |
---|
8082 | 8347 | // if (!texname.startsWith("/")) |
---|
8083 | 8348 | // texname = "/Users/nbriere/Textures/" + texname; |
---|
8084 | | - if (!new File(tex).exists()) |
---|
| 8349 | + if (!FileExists(texname)) |
---|
8085 | 8350 | { |
---|
8086 | | - texname = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory() + "/Textures/" + texname; |
---|
| 8351 | + texname = fallbackTextureName; |
---|
8087 | 8352 | } |
---|
8088 | 8353 | |
---|
8089 | 8354 | if (CACHETEXTURE) |
---|
8090 | | - texture = textures.get(texname); // TEXTURE CACHE |
---|
8091 | | - |
---|
8092 | | - TextureData texturedata = null; |
---|
8093 | | - |
---|
8094 | | - if (texture == null || texture.resolution < resolution) |
---|
8095 | 8355 | { |
---|
8096 | | - if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals("")) |
---|
| 8356 | + if (texdata == null) |
---|
| 8357 | + texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex); |
---|
| 8358 | + else |
---|
| 8359 | + texturecache = bimtextures.get(texdata); |
---|
| 8360 | + } |
---|
| 8361 | + |
---|
| 8362 | + if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution) |
---|
| 8363 | + { |
---|
| 8364 | + TextureData texturedata = null; |
---|
| 8365 | + |
---|
| 8366 | + if (texdata != null && textureon) |
---|
| 8367 | + { |
---|
| 8368 | + BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB); |
---|
| 8369 | + |
---|
| 8370 | + try |
---|
| 8371 | + { |
---|
| 8372 | + bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph); |
---|
| 8373 | + } |
---|
| 8374 | + catch (Exception e) |
---|
| 8375 | + { |
---|
| 8376 | + bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph); |
---|
| 8377 | + } |
---|
| 8378 | + |
---|
| 8379 | + texturecache = new CacheTexture(GetBimTexture(bim, bump), -1); |
---|
| 8380 | + bimtextures.put(texdata, texturecache); |
---|
| 8381 | + |
---|
| 8382 | + //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB); |
---|
| 8383 | + |
---|
| 8384 | + //Object bim2 = CreateBim(texturecache.texturedata); |
---|
| 8385 | + //bim2 = bim; |
---|
| 8386 | + } |
---|
| 8387 | + else |
---|
| 8388 | + if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals("")) |
---|
8097 | 8389 | { |
---|
8098 | 8390 | assert(!bump); |
---|
8099 | 8391 | // if (bump) |
---|
.. | .. |
---|
8104 | 8396 | // } |
---|
8105 | 8397 | // else |
---|
8106 | 8398 | // { |
---|
8107 | | - texture = textures.get(tex); |
---|
8108 | | - if (texture == null) |
---|
| 8399 | + // texturecache = textures.get(texname); // suspicious |
---|
| 8400 | + if (texturecache == null) |
---|
8109 | 8401 | { |
---|
8110 | | - texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
| 8402 | + texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
8111 | 8403 | } |
---|
| 8404 | + else |
---|
| 8405 | + new Exception().printStackTrace(); |
---|
8112 | 8406 | // } |
---|
8113 | 8407 | } else |
---|
8114 | | - if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals("")) |
---|
| 8408 | + if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals("")) |
---|
8115 | 8409 | { |
---|
8116 | 8410 | assert(bump); |
---|
8117 | | - texture = textures.get(tex); |
---|
8118 | | - if (texture == null) |
---|
8119 | | - texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
| 8411 | + // texturecache = textures.get(texname); // suspicious |
---|
| 8412 | + if (texturecache == null) |
---|
| 8413 | + texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
| 8414 | + else |
---|
| 8415 | + new Exception().printStackTrace(); |
---|
8120 | 8416 | } else |
---|
8121 | 8417 | { |
---|
8122 | 8418 | //if (tex.equals("IMMORTAL")) |
---|
.. | .. |
---|
8124 | 8420 | // texture = GetResourceTexture("default.png"); |
---|
8125 | 8421 | //} else |
---|
8126 | 8422 | //{ |
---|
8127 | | - if (tex.equals("WHITE_NOISE")) |
---|
| 8423 | + if (texname.endsWith("WHITE_NOISE")) |
---|
8128 | 8424 | { |
---|
8129 | | - texture = textures.get(tex); |
---|
8130 | | - if (texture == null) |
---|
8131 | | - texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution); |
---|
| 8425 | + // texturecache = textures.get(texname); // suspicious |
---|
| 8426 | + if (texturecache == null) |
---|
| 8427 | + texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution); |
---|
| 8428 | + else |
---|
| 8429 | + new Exception().printStackTrace(); |
---|
8132 | 8430 | } else |
---|
8133 | 8431 | { |
---|
8134 | 8432 | if (textureon) |
---|
.. | .. |
---|
8153 | 8451 | } |
---|
8154 | 8452 | |
---|
8155 | 8453 | cachename = texname.substring(0, texname.length()-4)+ext+".jpg"; |
---|
8156 | | - if (!new File(cachename).exists()) |
---|
| 8454 | + if (!FileExists(cachename)) |
---|
8157 | 8455 | cachename = texname; |
---|
8158 | 8456 | else |
---|
8159 | 8457 | processbump = false; // don't process bump map again |
---|
.. | .. |
---|
8175 | 8473 | } |
---|
8176 | 8474 | |
---|
8177 | 8475 | cachename = texname.substring(0, texname.length()-4)+ext+".png"; |
---|
8178 | | - if (!new File(cachename).exists()) |
---|
| 8476 | + if (!FileExists(cachename)) |
---|
8179 | 8477 | cachename = texname; |
---|
8180 | 8478 | else |
---|
8181 | 8479 | processbump = false; // don't process bump map again |
---|
.. | .. |
---|
8184 | 8482 | texturedata = GetFileTexture(cachename, processbump, resolution); |
---|
8185 | 8483 | |
---|
8186 | 8484 | |
---|
8187 | | - if (texturedata != null) |
---|
8188 | | - texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution); |
---|
| 8485 | + if (texturedata == null) |
---|
| 8486 | + throw new Exception(); |
---|
| 8487 | + |
---|
| 8488 | + texturecache = new CacheTexture(texturedata,resolution); |
---|
8189 | 8489 | //texture = GetTexture(tex, bump); |
---|
8190 | 8490 | } |
---|
8191 | 8491 | } |
---|
8192 | 8492 | //} |
---|
8193 | 8493 | } |
---|
8194 | 8494 | |
---|
8195 | | - if (/*CACHETEXTURE &&*/ texture != null && textureon) |
---|
| 8495 | + if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon) |
---|
8196 | 8496 | { |
---|
8197 | 8497 | //return false; |
---|
8198 | 8498 | |
---|
8199 | 8499 | // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")"); |
---|
8200 | | - if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG"))) |
---|
| 8500 | + if (texturedata != null && texname.toLowerCase().endsWith(".jpg")) |
---|
8201 | 8501 | { |
---|
8202 | 8502 | // String ext = "_highres"; |
---|
8203 | 8503 | // if (REDUCETEXTURE) |
---|
.. | .. |
---|
8214 | 8514 | File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg"); |
---|
8215 | 8515 | if (!cachefile.exists()) |
---|
8216 | 8516 | { |
---|
8217 | | - // cache to disk |
---|
8218 | | - Buffer buffer = texturedata.getBuffer(); // getMipmapData(); |
---|
8219 | | - //buffers[0]. |
---|
8220 | | - |
---|
8221 | | - ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer(); |
---|
8222 | | - int[] pixels = new int[bytebuf.capacity()/3]; |
---|
8223 | | - |
---|
8224 | | - // squared size heuristic... |
---|
8225 | | - if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length)) |
---|
| 8517 | + //if (texturedata.getWidth() == texturedata.getHeight()) |
---|
8226 | 8518 | { |
---|
8227 | | - for (int i=pixels.length; --i>=0;) |
---|
8228 | | - { |
---|
8229 | | - int i3 = i*3; |
---|
8230 | | - pixels[i] = 0xFF; |
---|
8231 | | - pixels[i] <<= 8; |
---|
8232 | | - pixels[i] |= bytebuf.get(i3+2) & 0xFF; |
---|
8233 | | - pixels[i] <<= 8; |
---|
8234 | | - pixels[i] |= bytebuf.get(i3+1) & 0xFF; |
---|
8235 | | - pixels[i] <<= 8; |
---|
8236 | | - pixels[i] |= bytebuf.get(i3) & 0xFF; |
---|
8237 | | - } |
---|
8238 | | - |
---|
8239 | | - /* |
---|
8240 | | - int r=0,g=0,b=0,a=0; |
---|
8241 | | - for (int i=0; i<width; i++) |
---|
8242 | | - for (int j=0; j<height; j++) |
---|
8243 | | - { |
---|
8244 | | - int index = j*width+i; |
---|
8245 | | - int p = pixels[index]; |
---|
8246 | | - a = ((p>>24) & 0xFF); |
---|
8247 | | - r = ((p>>16) & 0xFF); |
---|
8248 | | - g = ((p>>8) & 0xFF); |
---|
8249 | | - b = (p & 0xFF); |
---|
8250 | | - pixels[index] = (a<<24) | (b<<16) | (g<<8) | r; |
---|
8251 | | - } |
---|
8252 | | - /**/ |
---|
8253 | | - int width = (int)Math.sqrt(pixels.length); // squared |
---|
8254 | | - int height = width; |
---|
8255 | | - BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile); |
---|
8256 | | - rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width); |
---|
| 8519 | + BufferedImage rendImage = CreateBim(texturedata); |
---|
| 8520 | + |
---|
8257 | 8521 | ImageWriter writer = null; |
---|
8258 | 8522 | Iterator iter = ImageIO.getImageWritersByFormatName("jpg"); |
---|
8259 | 8523 | if (iter.hasNext()) { |
---|
8260 | 8524 | writer = (ImageWriter)iter.next(); |
---|
8261 | 8525 | } |
---|
8262 | | - float compressionQuality = 0.9f; |
---|
| 8526 | + |
---|
| 8527 | + float compressionQuality = 0.85f; |
---|
8263 | 8528 | try |
---|
8264 | 8529 | { |
---|
8265 | 8530 | ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile); |
---|
.. | .. |
---|
8276 | 8541 | } |
---|
8277 | 8542 | } |
---|
8278 | 8543 | } |
---|
8279 | | - |
---|
| 8544 | + |
---|
| 8545 | + Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment; |
---|
| 8546 | + |
---|
8280 | 8547 | //System.out.println("Texture = " + tex); |
---|
8281 | | - if (textures.containsKey(texname)) |
---|
| 8548 | + if (textures.containsKey(tex)) |
---|
8282 | 8549 | { |
---|
8283 | | - CacheTexture thetex = textures.get(texname); |
---|
| 8550 | + CacheTexture thetex = textures.get(tex); |
---|
8284 | 8551 | thetex.texture.disable(); |
---|
8285 | 8552 | thetex.texture.dispose(); |
---|
8286 | | - textures.remove(texname); |
---|
| 8553 | + textures.remove(tex); |
---|
8287 | 8554 | } |
---|
8288 | 8555 | |
---|
8289 | | - texture.texturedata = texturedata; |
---|
8290 | | - textures.put(texname, texture); |
---|
| 8556 | + //texture.texturedata = texturedata; |
---|
| 8557 | + textures.put(tex, texturecache); |
---|
8291 | 8558 | |
---|
8292 | 8559 | // newtex = true; |
---|
8293 | 8560 | } |
---|
.. | .. |
---|
8303 | 8570 | } |
---|
8304 | 8571 | } |
---|
8305 | 8572 | |
---|
8306 | | - return texture; |
---|
| 8573 | + return texturecache; |
---|
8307 | 8574 | } |
---|
8308 | 8575 | |
---|
8309 | | - com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution) |
---|
| 8576 | + static void EmbedTextures(cTexture tex) |
---|
| 8577 | + { |
---|
| 8578 | + if (tex.pigmentdata == null) |
---|
| 8579 | + { |
---|
| 8580 | + //String texname = Object3D.GetPigment(tex); |
---|
| 8581 | + |
---|
| 8582 | + CacheTexture texturecache = texturepigment.get(tex); |
---|
| 8583 | + |
---|
| 8584 | + if (texturecache != null) |
---|
| 8585 | + { |
---|
| 8586 | + tex.pw = texturecache.texturedata.getWidth(); |
---|
| 8587 | + tex.ph = texturecache.texturedata.getHeight(); |
---|
| 8588 | + tex.pigmentdata = //CompressJPEG(CreateBim |
---|
| 8589 | + ((ByteBuffer)texturecache.texturedata.getBuffer()).array() |
---|
| 8590 | + ; |
---|
| 8591 | + //, tex.pw, tex.ph), 0.5f); |
---|
| 8592 | + } |
---|
| 8593 | + } |
---|
| 8594 | + |
---|
| 8595 | + if (tex.bumpdata == null) |
---|
| 8596 | + { |
---|
| 8597 | + //String texname = Object3D.GetBump(tex); |
---|
| 8598 | + |
---|
| 8599 | + CacheTexture texturecache = texturebump.get(tex); |
---|
| 8600 | + |
---|
| 8601 | + if (texturecache != null) |
---|
| 8602 | + { |
---|
| 8603 | + tex.bw = texturecache.texturedata.getWidth(); |
---|
| 8604 | + tex.bh = texturecache.texturedata.getHeight(); |
---|
| 8605 | + tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f); |
---|
| 8606 | + } |
---|
| 8607 | + } |
---|
| 8608 | + } |
---|
| 8609 | + |
---|
| 8610 | + com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8310 | 8611 | { |
---|
8311 | 8612 | CacheTexture texture = GetCacheTexture(tex, bump, resolution); |
---|
8312 | 8613 | |
---|
.. | .. |
---|
8324 | 8625 | return texture!=null?texture.texture:null; |
---|
8325 | 8626 | } |
---|
8326 | 8627 | |
---|
8327 | | - public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution) |
---|
| 8628 | + public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8328 | 8629 | { |
---|
8329 | 8630 | CacheTexture texture = GetCacheTexture(tex, bump, resolution); |
---|
8330 | 8631 | |
---|
8331 | 8632 | return texture!=null?texture.texturedata:null; |
---|
8332 | 8633 | } |
---|
8333 | 8634 | |
---|
8334 | | - boolean BindTexture(String tex, boolean bump, int resolution) |
---|
| 8635 | + boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8335 | 8636 | { |
---|
8336 | 8637 | if (/*tex == null ||*/ ambientOcclusion ) // || !textureon) |
---|
8337 | 8638 | { |
---|
8338 | 8639 | return false; |
---|
8339 | 8640 | } |
---|
8340 | 8641 | |
---|
8341 | | - boolean newtex = false; |
---|
| 8642 | + //boolean newtex = false; |
---|
8342 | 8643 | |
---|
8343 | 8644 | com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution); |
---|
8344 | 8645 | |
---|
.. | .. |
---|
8370 | 8671 | texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT); |
---|
8371 | 8672 | texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT); |
---|
8372 | 8673 | |
---|
8373 | | - return newtex; |
---|
| 8674 | + return true; // Warning: not used. |
---|
8374 | 8675 | } |
---|
8375 | 8676 | |
---|
| 8677 | + public static byte[] CompressJPEG(BufferedImage image, float quality) |
---|
| 8678 | + { |
---|
| 8679 | + try |
---|
| 8680 | + { |
---|
| 8681 | + ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
---|
| 8682 | + Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg"); |
---|
| 8683 | + ImageWriter writer = writers.next(); |
---|
| 8684 | + |
---|
| 8685 | + ImageWriteParam param = writer.getDefaultWriteParam(); |
---|
| 8686 | + param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); |
---|
| 8687 | + param.setCompressionQuality(quality); |
---|
| 8688 | + |
---|
| 8689 | + ImageOutputStream ios = ImageIO.createImageOutputStream(baos); |
---|
| 8690 | + writer.setOutput(ios); |
---|
| 8691 | + writer.write(null, new IIOImage(image, null, null), param); |
---|
| 8692 | + |
---|
| 8693 | + byte[] data = baos.toByteArray(); |
---|
| 8694 | + writer.dispose(); |
---|
| 8695 | + return data; |
---|
| 8696 | + } |
---|
| 8697 | + catch (Exception e) |
---|
| 8698 | + { |
---|
| 8699 | + e.printStackTrace(); |
---|
| 8700 | + return null; |
---|
| 8701 | + } |
---|
| 8702 | + } |
---|
| 8703 | + |
---|
| 8704 | + public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException |
---|
| 8705 | + { |
---|
| 8706 | + ByteArrayInputStream baos = new ByteArrayInputStream(image); |
---|
| 8707 | + Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg"); |
---|
| 8708 | + ImageReader reader = writers.next(); |
---|
| 8709 | + |
---|
| 8710 | + BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); |
---|
| 8711 | + |
---|
| 8712 | + ImageReadParam param = reader.getDefaultReadParam(); |
---|
| 8713 | + param.setDestination(bim); |
---|
| 8714 | + //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB)); |
---|
| 8715 | + |
---|
| 8716 | + ImageInputStream ios = ImageIO.createImageInputStream(baos); |
---|
| 8717 | + reader.setInput(ios); |
---|
| 8718 | + BufferedImage bim2 = reader.read(0, param); |
---|
| 8719 | + reader.dispose(); |
---|
| 8720 | + |
---|
| 8721 | +// WritableRaster raster = bim2.getRaster(); |
---|
| 8722 | +// DataBufferByte data = (DataBufferByte) raster.getDataBuffer(); |
---|
| 8723 | +// byte[] bytes = data.getData(); |
---|
| 8724 | +// |
---|
| 8725 | +// int[] pixels = new int[bytes.length/3]; |
---|
| 8726 | +// for (int i=pixels.length; --i>=0;) |
---|
| 8727 | +// { |
---|
| 8728 | +// int i3 = i*3; |
---|
| 8729 | +// pixels[i] = 0xFF; |
---|
| 8730 | +// pixels[i] <<= 8; |
---|
| 8731 | +// pixels[i] |= bytes[i3+2] & 0xFF; |
---|
| 8732 | +// pixels[i] <<= 8; |
---|
| 8733 | +// pixels[i] |= bytes[i3+1] & 0xFF; |
---|
| 8734 | +// pixels[i] <<= 8; |
---|
| 8735 | +// pixels[i] |= bytes[i3] & 0xFF; |
---|
| 8736 | +// } |
---|
| 8737 | +// |
---|
| 8738 | +// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w); |
---|
| 8739 | + |
---|
| 8740 | + return bim; |
---|
| 8741 | + } |
---|
| 8742 | + |
---|
8376 | 8743 | ShadowBuffer shadowPBuf; |
---|
8377 | 8744 | AntialiasBuffer antialiasPBuf; |
---|
8378 | 8745 | int MAXSTACK; |
---|
.. | .. |
---|
9208 | 9575 | jy8[3] = 0.5f; |
---|
9209 | 9576 | } |
---|
9210 | 9577 | |
---|
9211 | | - float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV |
---|
| 9578 | + float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV |
---|
9212 | 9579 | float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation |
---|
9213 | 9580 | float[] options3 = new float[]{1, 1, 1, 0}; // fog color |
---|
9214 | 9581 | float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen |
---|
9215 | 9582 | |
---|
| 9583 | + void ResetOptions() |
---|
| 9584 | + { |
---|
| 9585 | + options1[0] = 100; |
---|
| 9586 | + options1[1] = 0.025f; |
---|
| 9587 | + options1[2] = 0.01f; |
---|
| 9588 | + options1[3] = 0; |
---|
| 9589 | + options1[4] = 0; |
---|
| 9590 | + |
---|
| 9591 | + options2[0] = 0; |
---|
| 9592 | + options2[1] = 0.75f; |
---|
| 9593 | + options2[2] = 0; |
---|
| 9594 | + options2[3] = 0; |
---|
| 9595 | + |
---|
| 9596 | + options3[0] = 1; |
---|
| 9597 | + options3[1] = 1; |
---|
| 9598 | + options3[2] = 1; |
---|
| 9599 | + options3[3] = 0; |
---|
| 9600 | + |
---|
| 9601 | + options4[0] = 1; |
---|
| 9602 | + options4[1] = 0; |
---|
| 9603 | + options4[2] = 1; |
---|
| 9604 | + options4[3] = 0; |
---|
| 9605 | + } |
---|
| 9606 | + |
---|
9216 | 9607 | static int imagecount = 0; // movie generation |
---|
9217 | 9608 | |
---|
9218 | 9609 | static int jitter = 0; |
---|
.. | .. |
---|
9308 | 9699 | assert (parentcam != renderCamera); |
---|
9309 | 9700 | |
---|
9310 | 9701 | if (renderCamera != lightCamera) |
---|
9311 | | - for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
9312 | | - LA.matConcat(matrix, parentcam.toParent, matrix); |
---|
| 9702 | + //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
| 9703 | + LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix); |
---|
9313 | 9704 | |
---|
9314 | 9705 | // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix); |
---|
9315 | 9706 | |
---|
.. | .. |
---|
9324 | 9715 | LA.matCopy(renderCamera.fromScreen, matrix); |
---|
9325 | 9716 | |
---|
9326 | 9717 | if (renderCamera != lightCamera) |
---|
9327 | | - for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
9328 | | - LA.matConcat(parentcam.fromParent, matrix, matrix); |
---|
| 9718 | + //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
| 9719 | + LA.matConcat(parentcam.GlobalTransform(), matrix, matrix); |
---|
9329 | 9720 | |
---|
9330 | 9721 | // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix); |
---|
9331 | 9722 | |
---|
.. | .. |
---|
10323 | 10714 | ANTIALIAS = 0; |
---|
10324 | 10715 | //System.out.println("RESTART"); |
---|
10325 | 10716 | AAtimer.restart(); |
---|
| 10717 | + Globals.TIMERRUNNING = true; |
---|
10326 | 10718 | } |
---|
10327 | 10719 | } |
---|
10328 | 10720 | } |
---|
.. | .. |
---|
10390 | 10782 | ambientOcclusion = false; |
---|
10391 | 10783 | } |
---|
10392 | 10784 | |
---|
10393 | | - if (Globals.lighttouched && DrawMode() == DEFAULT && !lightMode) // && !FROZEN) |
---|
| 10785 | + if (//Globals.lighttouched && |
---|
| 10786 | + DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN) |
---|
10394 | 10787 | { |
---|
10395 | 10788 | //if (RENDERSHADOW) // ? |
---|
10396 | 10789 | if (!IsFrozen()) |
---|
10397 | 10790 | { |
---|
10398 | 10791 | // dec 2012 |
---|
10399 | | - if (!ambientOcclusion && !(!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0)) |
---|
| 10792 | + if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0)) |
---|
10400 | 10793 | { |
---|
10401 | 10794 | Globals.framecount++; |
---|
10402 | 10795 | shadowbuffer.display(); |
---|
.. | .. |
---|
10523 | 10916 | |
---|
10524 | 10917 | // if (parentcam != renderCamera) // not a light |
---|
10525 | 10918 | if (cam != lightCamera) |
---|
10526 | | - for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
10527 | | - LA.matConcat(matrix, parentcam.toParent, matrix); |
---|
| 10919 | + //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
| 10920 | + LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix); |
---|
10528 | 10921 | |
---|
10529 | 10922 | for (int j = 0; j < 4; j++) |
---|
10530 | 10923 | { |
---|
.. | .. |
---|
10538 | 10931 | |
---|
10539 | 10932 | // if (parentcam != renderCamera) // not a light |
---|
10540 | 10933 | if (cam != lightCamera) |
---|
10541 | | - for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
10542 | | - LA.matConcat(parentcam.fromParent, matrix, matrix); |
---|
| 10934 | + //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
| 10935 | + LA.matConcat(parentcam.GlobalTransform(), matrix, matrix); |
---|
10543 | 10936 | |
---|
10544 | 10937 | //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix); |
---|
10545 | 10938 | |
---|
.. | .. |
---|
10798 | 11191 | // Bump noise |
---|
10799 | 11192 | gl.glActiveTexture(GL.GL_TEXTURE6); |
---|
10800 | 11193 | //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise); |
---|
10801 | | - BindTexture(NOISE_TEXTURE, false, 2); |
---|
| 11194 | + |
---|
| 11195 | + try |
---|
| 11196 | + { |
---|
| 11197 | + BindTexture(NOISE_TEXTURE, false, 2); |
---|
| 11198 | + } |
---|
| 11199 | + catch (Exception e) |
---|
| 11200 | + { |
---|
| 11201 | + System.err.println("FAILED: " + NOISE_TEXTURE); |
---|
| 11202 | + } |
---|
| 11203 | + |
---|
10802 | 11204 | |
---|
10803 | 11205 | gl.glActiveTexture(GL.GL_TEXTURE0); |
---|
10804 | 11206 | gl.glEnable(GL.GL_TEXTURE_2D); |
---|
.. | .. |
---|
10821 | 11223 | |
---|
10822 | 11224 | gl.glMatrixMode(GL.GL_MODELVIEW); |
---|
10823 | 11225 | |
---|
10824 | | -//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST); |
---|
10825 | | -//gl.glEnable(gl.GL_POLYGON_SMOOTH); |
---|
10826 | | -//gl.glEnable(gl.GL_MULTISAMPLE); |
---|
| 11226 | +gl.glEnable(gl.GL_POLYGON_SMOOTH); |
---|
| 11227 | +gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST); |
---|
| 11228 | +gl.glEnable(gl.GL_MULTISAMPLE); |
---|
10827 | 11229 | } else |
---|
10828 | 11230 | { |
---|
10829 | 11231 | //gl.glDisable(GL.GL_TEXTURE_2D); |
---|
.. | .. |
---|
10834 | 11236 | //System.out.println("BLENDING ON"); |
---|
10835 | 11237 | gl.glEnable(GL.GL_BLEND); |
---|
10836 | 11238 | gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); |
---|
10837 | | - |
---|
| 11239 | +// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE); |
---|
10838 | 11240 | gl.glMatrixMode(gl.GL_PROJECTION); |
---|
10839 | 11241 | gl.glLoadIdentity(); |
---|
10840 | 11242 | |
---|
.. | .. |
---|
10923 | 11325 | System.err.println("parentcam != renderCamera"); |
---|
10924 | 11326 | |
---|
10925 | 11327 | // if (cam != lightCamera) |
---|
10926 | | - for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
10927 | | - LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013 |
---|
| 11328 | + //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
| 11329 | + LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013 |
---|
10928 | 11330 | } |
---|
10929 | 11331 | |
---|
10930 | 11332 | LA.xformDir(lightposition, cam.toScreen, lightposition); |
---|
.. | .. |
---|
10945 | 11347 | if (true) // TODO |
---|
10946 | 11348 | { |
---|
10947 | 11349 | if (cam != lightCamera) |
---|
10948 | | - for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
10949 | | - LA.xformDir(light0, parentcam.toParent, light0); // may 2013 |
---|
| 11350 | + //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
| 11351 | + LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013 |
---|
10950 | 11352 | } |
---|
10951 | 11353 | |
---|
10952 | 11354 | LA.xformPos(light0, cam.toScreen, light0); |
---|
.. | .. |
---|
11083 | 11485 | } |
---|
11084 | 11486 | } |
---|
11085 | 11487 | |
---|
11086 | | - if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion) |
---|
| 11488 | + if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion) |
---|
11087 | 11489 | { |
---|
11088 | 11490 | //gl.glDepthFunc(GL.GL_LEQUAL); |
---|
11089 | 11491 | //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT); |
---|
.. | .. |
---|
11091 | 11493 | |
---|
11092 | 11494 | boolean texon = textureon; |
---|
11093 | 11495 | |
---|
11094 | | - if (RENDERPROGRAM > 0) |
---|
11095 | | - { |
---|
11096 | | - gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
11097 | | - textureon = false; |
---|
11098 | | - } |
---|
| 11496 | + gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
| 11497 | + textureon = false; |
---|
| 11498 | + |
---|
11099 | 11499 | //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB); |
---|
11100 | 11500 | //System.out.println("ALLO"); |
---|
11101 | 11501 | gl.glColorMask(false, false, false, false); |
---|
11102 | 11502 | DrawObject(gl); |
---|
11103 | | - if (RENDERPROGRAM > 0) |
---|
11104 | | - { |
---|
11105 | | - gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
11106 | | - textureon = texon; |
---|
11107 | | - } |
---|
| 11503 | + |
---|
| 11504 | + gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
| 11505 | + textureon = texon; |
---|
| 11506 | + |
---|
11108 | 11507 | gl.glColorMask(true, true, true, true); |
---|
11109 | 11508 | |
---|
11110 | 11509 | gl.glDepthFunc(GL.GL_EQUAL); |
---|
11111 | | - //gl.glDepthMask(false); |
---|
| 11510 | + gl.glDepthMask(false); |
---|
11112 | 11511 | } |
---|
11113 | 11512 | |
---|
11114 | 11513 | if (false) // DrawMode() == SHADOW) |
---|
.. | .. |
---|
11291 | 11690 | |
---|
11292 | 11691 | static boolean zoomonce = false; |
---|
11293 | 11692 | |
---|
| 11693 | + static void CreateSelectedPoint() |
---|
| 11694 | + { |
---|
| 11695 | + if (selectedpoint == null) |
---|
| 11696 | + { |
---|
| 11697 | + debugpointG = new Sphere(); |
---|
| 11698 | + debugpointP = new Sphere(); |
---|
| 11699 | + debugpointC = new Sphere(); |
---|
| 11700 | + debugpointR = new Sphere(); |
---|
| 11701 | + |
---|
| 11702 | + selectedpoint = new Superellipsoid(); |
---|
| 11703 | + |
---|
| 11704 | + for (int i=0; i<8; i++) |
---|
| 11705 | + { |
---|
| 11706 | + debugpoints[i] = new Sphere(); |
---|
| 11707 | + } |
---|
| 11708 | + } |
---|
| 11709 | + } |
---|
| 11710 | + |
---|
11294 | 11711 | void DrawObject(GL gl, boolean draw) |
---|
11295 | 11712 | { |
---|
| 11713 | + // To clear camera values |
---|
| 11714 | + ResetOptions(); |
---|
| 11715 | + |
---|
11296 | 11716 | //System.out.println("DRAW OBJECT " + mouseDown); |
---|
11297 | 11717 | // DrawMode() = SELECTION; |
---|
11298 | 11718 | //GL gl = getGL(); |
---|
11299 | 11719 | if ((TRACK || SHADOWTRACK) || zoomonce) |
---|
11300 | 11720 | { |
---|
11301 | 11721 | if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode) |
---|
11302 | | - object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK); |
---|
| 11722 | + object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK); |
---|
11303 | 11723 | pingthread.StepToTarget(true); // true); |
---|
11304 | 11724 | // zoomonce = false; |
---|
11305 | 11725 | } |
---|
.. | .. |
---|
11354 | 11774 | |
---|
11355 | 11775 | usedtextures.clear(); |
---|
11356 | 11776 | |
---|
11357 | | - BindTextures(DEFAULT_TEXTURES, 2); |
---|
| 11777 | + try |
---|
| 11778 | + { |
---|
| 11779 | + BindTextures(DEFAULT_TEXTURES, 2); |
---|
| 11780 | + } |
---|
| 11781 | + catch (Exception e) |
---|
| 11782 | + { |
---|
| 11783 | + System.err.println("FAILED: " + DEFAULT_TEXTURES); |
---|
| 11784 | + } |
---|
11358 | 11785 | } |
---|
11359 | 11786 | //System.out.println("--> " + stackdepth); |
---|
11360 | 11787 | // GrafreeD.traceon(); |
---|
.. | .. |
---|
11364 | 11791 | |
---|
11365 | 11792 | if (DrawMode() == DEFAULT) |
---|
11366 | 11793 | { |
---|
11367 | | - if (DEBUG) |
---|
| 11794 | + if (Globals.DEBUG) |
---|
11368 | 11795 | { |
---|
| 11796 | + CreateSelectedPoint(); |
---|
11369 | 11797 | float radius = 0.05f; |
---|
11370 | 11798 | if (selectedpoint.radius != radius) |
---|
11371 | 11799 | { |
---|
.. | .. |
---|
11419 | 11847 | ReleaseTextures(DEFAULT_TEXTURES); |
---|
11420 | 11848 | |
---|
11421 | 11849 | if (CLEANCACHE) |
---|
11422 | | - for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();) |
---|
| 11850 | + for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();) |
---|
11423 | 11851 | { |
---|
11424 | | - String tex = e.nextElement(); |
---|
| 11852 | + cTexture tex = e.nextElement(); |
---|
11425 | 11853 | |
---|
11426 | 11854 | // System.out.println("Texture --------- " + tex); |
---|
11427 | 11855 | |
---|
11428 | | - if (tex.equals("WHITE_NOISE")) |
---|
| 11856 | + if (tex.equals("WHITE_NOISE:")) |
---|
11429 | 11857 | continue; |
---|
11430 | 11858 | |
---|
11431 | | - if (!usedtextures.containsKey(tex)) |
---|
| 11859 | + if (!usedtextures.contains(tex)) |
---|
11432 | 11860 | { |
---|
| 11861 | + CacheTexture gettex = texturepigment.get(tex); |
---|
11433 | 11862 | // System.out.println("DISPOSE +++++++++++++++ " + tex); |
---|
11434 | | - textures.get(tex).texture.dispose(); |
---|
11435 | | - textures.remove(tex); |
---|
| 11863 | + if (gettex != null) |
---|
| 11864 | + { |
---|
| 11865 | + gettex.texture.dispose(); |
---|
| 11866 | + texturepigment.remove(tex); |
---|
| 11867 | + } |
---|
| 11868 | + |
---|
| 11869 | + gettex = texturebump.get(tex); |
---|
| 11870 | + // System.out.println("DISPOSE +++++++++++++++ " + tex); |
---|
| 11871 | + if (gettex != null) |
---|
| 11872 | + { |
---|
| 11873 | + gettex.texture.dispose(); |
---|
| 11874 | + texturebump.remove(tex); |
---|
| 11875 | + } |
---|
11436 | 11876 | } |
---|
11437 | 11877 | } |
---|
11438 | 11878 | } |
---|
.. | .. |
---|
11445 | 11885 | if (checker != null && DrawMode() == DEFAULT) |
---|
11446 | 11886 | { |
---|
11447 | 11887 | //BindTexture(IMMORTAL_TEXTURE); |
---|
11448 | | - BindTextures(checker.GetTextures(), checker.texres); |
---|
| 11888 | + try |
---|
| 11889 | + { |
---|
| 11890 | + BindTextures(checker.GetTextures(), checker.texres); |
---|
| 11891 | + } |
---|
| 11892 | + catch (Exception e) |
---|
| 11893 | + { |
---|
| 11894 | + System.err.println("FAILED: " + checker.GetTextures()); |
---|
| 11895 | + } |
---|
11449 | 11896 | // NEAREST |
---|
11450 | 11897 | GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR); |
---|
11451 | 11898 | DrawChecker(gl); |
---|
.. | .. |
---|
11527 | 11974 | return; |
---|
11528 | 11975 | } |
---|
11529 | 11976 | |
---|
11530 | | - String string = obj.GetToolTip(); |
---|
| 11977 | + String string = obj.toString(); //.GetToolTip(); |
---|
11531 | 11978 | |
---|
11532 | 11979 | GL gl = GetGL(); |
---|
11533 | 11980 | |
---|
.. | .. |
---|
11844 | 12291 | //obj.TransformToWorld(light, light); |
---|
11845 | 12292 | for (int i = tp.size(); --i >= 0;) |
---|
11846 | 12293 | { |
---|
11847 | | - for (int count = tp.get(i).GetTransformCount(); --count>=0;) |
---|
11848 | | - LA.xformPos(light, tp.get(i).toParent, light); |
---|
| 12294 | + //for (int count = tp.get(i).GetTransformCount(); --count>=0;) |
---|
| 12295 | + LA.xformPos(light, tp.get(i).GlobalTransformInv(), light); |
---|
11849 | 12296 | } |
---|
11850 | 12297 | |
---|
11851 | 12298 | |
---|
.. | .. |
---|
11862 | 12309 | parentcam = cameras[0]; |
---|
11863 | 12310 | } |
---|
11864 | 12311 | |
---|
11865 | | - for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
11866 | | - LA.xformPos(light, parentcam.toParent, light); // may 2013 |
---|
| 12312 | + //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
| 12313 | + LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013 |
---|
11867 | 12314 | |
---|
11868 | 12315 | LA.xformPos(light, renderCamera.toScreen, light); |
---|
11869 | 12316 | |
---|
.. | .. |
---|
11954 | 12401 | //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0); |
---|
11955 | 12402 | |
---|
11956 | 12403 | String program = |
---|
| 12404 | + // Min shader |
---|
11957 | 12405 | "!!ARBfp1.0\n" + |
---|
| 12406 | + "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" + |
---|
| 12407 | + "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" + |
---|
| 12408 | + "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" + |
---|
| 12409 | + "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" + |
---|
| 12410 | + "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" + |
---|
| 12411 | + "PARAM light2cam0 = program.env[10];" + |
---|
| 12412 | + "PARAM light2cam1 = program.env[11];" + |
---|
| 12413 | + "PARAM light2cam2 = program.env[12];" + |
---|
| 12414 | + "TEMP temp;" + |
---|
| 12415 | + "TEMP light;" + |
---|
| 12416 | + "TEMP ndotl;" + |
---|
| 12417 | + "TEMP normal;" + |
---|
| 12418 | + "TEMP depth;" + |
---|
| 12419 | + "TEMP eye;" + |
---|
| 12420 | + "TEMP pos;" + |
---|
| 12421 | + |
---|
| 12422 | + "MAD normal, fragment.color, zero123.z, -zero123.y;" + |
---|
| 12423 | + Normalize("normal") + |
---|
| 12424 | + "MOV light, state.light[0].position;" + |
---|
| 12425 | + "DP3 ndotl.x, light, normal;" + |
---|
| 12426 | + |
---|
| 12427 | + // shadow |
---|
| 12428 | + "MOV pos, fragment.texcoord[1];" + |
---|
| 12429 | + "MOV temp, pos;" + |
---|
| 12430 | + ShadowTextureFetch("depth", "temp", "1") + |
---|
| 12431 | + //"TEX depth, fragment.texcoord[1], texture[1], 2D;" + |
---|
| 12432 | + "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" + |
---|
| 12433 | + |
---|
| 12434 | + // No shadow when out of frustum |
---|
| 12435 | + //"SGE temp.y, depth.z, zero123.y;" + |
---|
| 12436 | + //"LRP temp.x, temp.y, zero123.y, temp.x;" + |
---|
| 12437 | + |
---|
| 12438 | + "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow |
---|
| 12439 | + |
---|
| 12440 | + // Backlit |
---|
| 12441 | + "MOV pos.w, zero123.y;" + |
---|
| 12442 | + "DP4 eye.x, pos, light2cam0;" + |
---|
| 12443 | + "DP4 eye.y, pos, light2cam1;" + |
---|
| 12444 | + "DP4 eye.z, pos, light2cam2;" + |
---|
| 12445 | + Normalize("eye") + |
---|
| 12446 | + |
---|
| 12447 | + "DP3 ndotl.y, -eye, normal;" + |
---|
| 12448 | + //"MUL ndotl.y, ndotl.y, pow2.x;" + |
---|
| 12449 | + "POW ndotl.y, ndotl.y, pow2.z;" + // backlit |
---|
| 12450 | + "SUB ndotl.y, zero123.y, ndotl.y;" + |
---|
| 12451 | + //"SUB ndotl.y, zero123.y, ndotl.y;" + |
---|
| 12452 | + //"MUL ndotl.y, ndotl.y, pow2.z;" + |
---|
| 12453 | + |
---|
| 12454 | + "MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient |
---|
| 12455 | + |
---|
| 12456 | + // Pigment |
---|
| 12457 | + "TEX temp, fragment.texcoord[0], texture[0], 2D;" + |
---|
| 12458 | + "LRP temp, zero123.w, temp, one;" + // texture proportion |
---|
| 12459 | + "MUL temp, temp, ndotl.x;" + |
---|
| 12460 | + |
---|
| 12461 | + "MUL temp, temp, zero123.z;" + |
---|
| 12462 | + |
---|
| 12463 | + //"MUL temp, temp, ndotl.y;" + |
---|
| 12464 | + |
---|
| 12465 | + "MOV temp.w, zero123.y;" + // reset alpha |
---|
| 12466 | + "MOV result.color, temp;" + |
---|
| 12467 | + "END"; |
---|
| 12468 | + |
---|
| 12469 | + String program2 = |
---|
| 12470 | + "!!ARBfp1.0\n" + |
---|
| 12471 | + |
---|
11958 | 12472 | //"OPTION ARB_fragment_program_shadow;" + |
---|
11959 | 12473 | "PARAM light2cam0 = program.env[10];" + |
---|
11960 | 12474 | "PARAM light2cam1 = program.env[11];" + |
---|
.. | .. |
---|
12069 | 12583 | "TEMP shininess;" + |
---|
12070 | 12584 | "\n" + |
---|
12071 | 12585 | "MOV texSamp, one;" + |
---|
12072 | | - //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" + |
---|
12073 | | - |
---|
| 12586 | + |
---|
12074 | 12587 | "MOV mapgrid.x, one2048th.x;" + |
---|
12075 | 12588 | "MOV temp, fragment.texcoord[1];" + |
---|
12076 | 12589 | /* |
---|
.. | .. |
---|
12091 | 12604 | "MUL temp, floor, mapgrid.x;" + |
---|
12092 | 12605 | //"TEX depth0, temp, texture[1], 2D;" + |
---|
12093 | 12606 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12094 | | - TextureFetch("depth0", "temp", "1") + |
---|
| 12607 | + ShadowTextureFetch("depth0", "temp", "1") + |
---|
12095 | 12608 | "") + |
---|
12096 | 12609 | "ADD temp.x, temp.x, mapgrid.x;" + |
---|
12097 | 12610 | //"TEX depth1, temp, texture[1], 2D;" + |
---|
12098 | 12611 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12099 | | - TextureFetch("depth1", "temp", "1") + |
---|
| 12612 | + ShadowTextureFetch("depth1", "temp", "1") + |
---|
12100 | 12613 | "") + |
---|
12101 | 12614 | "ADD temp.y, temp.y, mapgrid.x;" + |
---|
12102 | 12615 | //"TEX depth2, temp, texture[1], 2D;" + |
---|
12103 | | - TextureFetch("depth2", "temp", "1") + |
---|
| 12616 | + ShadowTextureFetch("depth2", "temp", "1") + |
---|
12104 | 12617 | "SUB temp.x, temp.x, mapgrid.x;" + |
---|
12105 | 12618 | //"TEX depth3, temp, texture[1], 2D;" + |
---|
12106 | 12619 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12107 | | - TextureFetch("depth3", "temp", "1") + |
---|
| 12620 | + ShadowTextureFetch("depth3", "temp", "1") + |
---|
12108 | 12621 | "") + |
---|
12109 | 12622 | //"MUL texSamp0, texSamp0, state.material.front.diffuse;" + |
---|
12110 | 12623 | //"MOV params, material;" + |
---|
.. | .. |
---|
12475 | 12988 | "MAD shadow.x, buffer.x, frac.y, shadow.x;" + |
---|
12476 | 12989 | "") + |
---|
12477 | 12990 | |
---|
12478 | | - // display shadow only (bump == 0) |
---|
| 12991 | + // display shadow only (fakedepth == 0) |
---|
12479 | 12992 | "SUB temp.x, half.x, shadow.x;" + |
---|
12480 | | - "MOV temp.y, -params6.x;" + |
---|
12481 | | - "SLT temp.z, temp.y, zero.x;" + |
---|
| 12993 | + "MOV temp.y, -params5.z;" + // params6.x;" + |
---|
| 12994 | + "SLT temp.z, temp.y, -one2048th.x;" + |
---|
12482 | 12995 | "SUB temp.y, one.x, temp.z;" + |
---|
12483 | 12996 | "MUL temp.x, temp.x, temp.y;" + |
---|
12484 | 12997 | "KIL temp.x;" + |
---|
.. | .. |
---|
12809 | 13322 | //once = true; |
---|
12810 | 13323 | } |
---|
12811 | 13324 | |
---|
12812 | | - System.out.print("Program #" + mode + "; length = " + program.length()); |
---|
| 13325 | + System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length()); |
---|
12813 | 13326 | System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : "")); |
---|
12814 | 13327 | loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program); |
---|
12815 | 13328 | |
---|
.. | .. |
---|
12902 | 13415 | return out; |
---|
12903 | 13416 | } |
---|
12904 | 13417 | |
---|
12905 | | - String TextureFetch(String dest, String src, String unit) |
---|
| 13418 | + // Also does frustum culling |
---|
| 13419 | + String ShadowTextureFetch(String dest, String src, String unit) |
---|
12906 | 13420 | { |
---|
12907 | 13421 | return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" + |
---|
12908 | 13422 | "SGE " + src + ".w, " + src + ".x, eps.x;" + |
---|
12909 | 13423 | "SGE " + src + ".z, " + src + ".y, eps.x;" + |
---|
| 13424 | + "SLT " + dest + ".x, " + src + ".x, one.x;" + |
---|
| 13425 | + "SLT " + dest + ".y, " + src + ".y, one.x;" + |
---|
12910 | 13426 | "MUL " + src + ".w, " + src + ".z, " + src + ".w;" + |
---|
12911 | | - "SLT " + src + ".z, " + src + ".x, one.x;" + |
---|
12912 | | - "MUL " + src + ".w, " + src + ".z, " + src + ".w;" + |
---|
12913 | | - "SLT " + src + ".z, " + src + ".y, one.x;" + |
---|
12914 | | - "MUL " + src + ".w, " + src + ".z, " + src + ".w;" + |
---|
| 13427 | + "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" + |
---|
| 13428 | + "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" + |
---|
12915 | 13429 | //"SWZ buffer, temp, w,w,w,w;"; |
---|
12916 | | - "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" + |
---|
| 13430 | + //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" + |
---|
12917 | 13431 | "SUB " + src + ".z, " + "one.x, " + src + ".w;" + |
---|
12918 | 13432 | //"MUL " + src + ".z, " + src + ".z, infinity.x;" + |
---|
12919 | 13433 | //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;"; |
---|
12920 | | - "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
| 13434 | + //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
12921 | 13435 | |
---|
12922 | | - //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;"; |
---|
12923 | | - //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;"; |
---|
| 13436 | + //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;"; |
---|
| 13437 | + "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
12924 | 13438 | } |
---|
12925 | 13439 | |
---|
12926 | 13440 | String Shadow(String depth, String shadow) |
---|
.. | .. |
---|
12942 | 13456 | |
---|
12943 | 13457 | "ADD " + depth + ".z, " + depth + ".z, temp.x;" + |
---|
12944 | 13458 | //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing! |
---|
| 13459 | + |
---|
| 13460 | + // Compare fragment depth in light space with shadowmap. |
---|
12945 | 13461 | "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" + |
---|
12946 | 13462 | "SGE temp.y, temp.x, zero.x;" + |
---|
12947 | | - "SUB " + shadow + ".y, one.x, temp.y;" + |
---|
| 13463 | + "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded |
---|
| 13464 | + |
---|
| 13465 | + // Reverse comparison |
---|
12948 | 13466 | "SUB temp.x, one.x, temp.x;" + |
---|
12949 | 13467 | "MUL " + shadow + ".x, temp.x, temp.y;" + |
---|
12950 | | - "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded |
---|
| 13468 | + "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse |
---|
12951 | 13469 | "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth |
---|
12952 | 13470 | |
---|
12953 | 13471 | "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" + |
---|
.. | .. |
---|
12961 | 13479 | // No shadow for backface |
---|
12962 | 13480 | "DP3 temp.x, normal, lightd;" + |
---|
12963 | 13481 | "SLT temp.x, temp.x, zero.x;" + // shadoweps |
---|
| 13482 | + "LRP " + shadow + ", temp.x, one, " + shadow + ";" + |
---|
| 13483 | + |
---|
| 13484 | + // No shadow when out of frustum |
---|
| 13485 | + "SGE temp.x, " + depth + ".z, one.z;" + |
---|
12964 | 13486 | "LRP " + shadow + ", temp.x, one, " + shadow + ";" + |
---|
12965 | 13487 | ""; |
---|
12966 | 13488 | } |
---|
.. | .. |
---|
13107 | 13629 | /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias |
---|
13108 | 13630 | /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough |
---|
13109 | 13631 | /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power |
---|
13110 | | - Object3D.cVector2[] vector2buffer; |
---|
| 13632 | + |
---|
| 13633 | + //Object3D.cVector2[] vector2buffer; |
---|
13111 | 13634 | |
---|
13112 | 13635 | // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea |
---|
13113 | 13636 | // OUT : diff, spec |
---|
.. | .. |
---|
13123 | 13646 | "DP3 " + dest + ".z," + "normals," + "eye;" + |
---|
13124 | 13647 | "MAX " + dest + ".w," + dest + ".z," + "eps.x;" + |
---|
13125 | 13648 | //"MOV " + dest + ".w," + "normal.z;" + |
---|
13126 | | - "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + |
---|
13127 | | - "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" + |
---|
13128 | | - //"MOV " + dest + ".z," + "params2.w;" + |
---|
| 13649 | +// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET |
---|
| 13650 | +// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" + |
---|
| 13651 | + |
---|
| 13652 | + "MOV " + dest + ".z," + "params2.w;" + // EXACT |
---|
13129 | 13653 | "POW " + dest + ".w," + dest + ".w," + dest + ".z;" + |
---|
13130 | 13654 | "RCP " + dest + ".w," + dest + ".w;" + |
---|
13131 | 13655 | //"RSQ " + dest + ".w," + dest + ".w;" + |
---|
.. | .. |
---|
13630 | 14154 | else |
---|
13631 | 14155 | if (evt.getSource() == AAtimer) |
---|
13632 | 14156 | { |
---|
| 14157 | + Globals.TIMERRUNNING = false; |
---|
13633 | 14158 | if (mouseDown) |
---|
13634 | 14159 | { |
---|
13635 | 14160 | //new Exception().printStackTrace(); |
---|
.. | .. |
---|
13689 | 14214 | |
---|
13690 | 14215 | // fev 2014??? |
---|
13691 | 14216 | if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode) |
---|
13692 | | - object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK); |
---|
| 14217 | + object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK); |
---|
13693 | 14218 | pingthread.StepToTarget(true); // true); |
---|
13694 | 14219 | } |
---|
13695 | 14220 | // if (!LIVE) |
---|
.. | .. |
---|
13704 | 14229 | return; |
---|
13705 | 14230 | |
---|
13706 | 14231 | AAtimer.restart(); // |
---|
| 14232 | + Globals.TIMERRUNNING = true; |
---|
13707 | 14233 | |
---|
13708 | 14234 | // waslive = LIVE; |
---|
13709 | 14235 | // LIVE = false; |
---|
.. | .. |
---|
13753 | 14279 | drag = false; |
---|
13754 | 14280 | //System.out.println("Mouse DOWN"); |
---|
13755 | 14281 | editObj = false; |
---|
13756 | | - ClickInfo info = new ClickInfo(); |
---|
13757 | | - info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
13758 | | - info.pane = this; |
---|
13759 | | - info.camera = renderCamera; |
---|
13760 | | - info.x = x; |
---|
13761 | | - info.y = y; |
---|
13762 | | - info.modifiers = modifiersex; |
---|
13763 | | - editObj = object.doEditClick(info, 0); |
---|
| 14282 | + //ClickInfo info = new ClickInfo(); |
---|
| 14283 | + object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
| 14284 | + object.clickInfo.pane = this; |
---|
| 14285 | + object.clickInfo.camera = renderCamera; |
---|
| 14286 | + object.clickInfo.x = x; |
---|
| 14287 | + object.clickInfo.y = y; |
---|
| 14288 | + object.clickInfo.modifiers = modifiersex; |
---|
| 14289 | + editObj = object.doEditClick(//info, |
---|
| 14290 | + 0); |
---|
13764 | 14291 | if (!editObj) |
---|
13765 | 14292 | { |
---|
13766 | 14293 | hasMarquee = true; |
---|
.. | .. |
---|
13776 | 14303 | |
---|
13777 | 14304 | public void mouseDragged(MouseEvent e) |
---|
13778 | 14305 | { |
---|
| 14306 | + Globals.MOUSEDRAGGED = true; |
---|
| 14307 | + |
---|
13779 | 14308 | //System.out.println("mouseDragged: " + e); |
---|
13780 | 14309 | if (isRenderer) |
---|
13781 | 14310 | movingcamera = true; |
---|
| 14311 | + |
---|
13782 | 14312 | //if (drawing) |
---|
13783 | 14313 | //return; |
---|
13784 | 14314 | if ((e.getModifiersEx() & CTRL) != 0 |
---|
.. | .. |
---|
14039 | 14569 | void GoDown(int mod) |
---|
14040 | 14570 | { |
---|
14041 | 14571 | MODIFIERS |= COMMAND; |
---|
14042 | | - /* |
---|
| 14572 | + /**/ |
---|
14043 | 14573 | if((mod&SHIFT) == SHIFT) |
---|
14044 | 14574 | manipCamera.RotatePosition(0, -speed); |
---|
14045 | 14575 | else |
---|
14046 | | - manipCamera.BackForth(0, -speed*delta, getWidth()); |
---|
14047 | | - */ |
---|
| 14576 | + manipCamera.BackForth(0, -speed*delta, 0); // getWidth()); |
---|
| 14577 | + /**/ |
---|
14048 | 14578 | if ((mod & SHIFT) == SHIFT) |
---|
14049 | 14579 | { |
---|
14050 | 14580 | mouseMode = mouseMode; // VR?? |
---|
.. | .. |
---|
14060 | 14590 | void GoUp(int mod) |
---|
14061 | 14591 | { |
---|
14062 | 14592 | MODIFIERS |= COMMAND; |
---|
14063 | | - /* |
---|
| 14593 | + /**/ |
---|
14064 | 14594 | if((mod&SHIFT) == SHIFT) |
---|
14065 | 14595 | manipCamera.RotatePosition(0, speed); |
---|
14066 | 14596 | else |
---|
14067 | | - manipCamera.BackForth(0, speed*delta, getWidth()); |
---|
14068 | | - */ |
---|
| 14597 | + manipCamera.BackForth(0, speed*delta, 0); // getWidth()); |
---|
| 14598 | + /**/ |
---|
14069 | 14599 | if ((mod & SHIFT) == SHIFT) |
---|
14070 | 14600 | { |
---|
14071 | 14601 | mouseMode = mouseMode; |
---|
.. | .. |
---|
14081 | 14611 | void GoLeft(int mod) |
---|
14082 | 14612 | { |
---|
14083 | 14613 | MODIFIERS |= COMMAND; |
---|
14084 | | - /* |
---|
| 14614 | + /**/ |
---|
14085 | 14615 | if((mod&SHIFT) == SHIFT) |
---|
14086 | | - manipCamera.RotatePosition(speed, 0); |
---|
14087 | | - else |
---|
14088 | 14616 | manipCamera.Translate(speed*delta, 0, getWidth()); |
---|
14089 | | - */ |
---|
| 14617 | + else |
---|
| 14618 | + manipCamera.RotatePosition(speed, 0); |
---|
| 14619 | + /**/ |
---|
14090 | 14620 | if ((mod & SHIFT) == SHIFT) |
---|
14091 | 14621 | { |
---|
14092 | 14622 | mouseMode = mouseMode; |
---|
.. | .. |
---|
14102 | 14632 | void GoRight(int mod) |
---|
14103 | 14633 | { |
---|
14104 | 14634 | MODIFIERS |= COMMAND; |
---|
14105 | | - /* |
---|
| 14635 | + /**/ |
---|
14106 | 14636 | if((mod&SHIFT) == SHIFT) |
---|
14107 | | - manipCamera.RotatePosition(-speed, 0); |
---|
14108 | | - else |
---|
14109 | 14637 | manipCamera.Translate(-speed*delta, 0, getWidth()); |
---|
14110 | | - */ |
---|
| 14638 | + else |
---|
| 14639 | + manipCamera.RotatePosition(-speed, 0); |
---|
| 14640 | + /**/ |
---|
14111 | 14641 | if ((mod & SHIFT) == SHIFT) |
---|
14112 | 14642 | { |
---|
14113 | 14643 | mouseMode = mouseMode; |
---|
.. | .. |
---|
14157 | 14687 | if (editObj) |
---|
14158 | 14688 | { |
---|
14159 | 14689 | drag = true; |
---|
14160 | | - ClickInfo info = new ClickInfo(); |
---|
14161 | | - info.bounds.setBounds(0, 0, |
---|
| 14690 | + //ClickInfo info = new ClickInfo(); |
---|
| 14691 | + object.clickInfo.bounds.setBounds(0, 0, |
---|
14162 | 14692 | (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
14163 | | - info.pane = this; |
---|
14164 | | - info.camera = renderCamera; |
---|
14165 | | - info.x = x; |
---|
14166 | | - info.y = y; |
---|
14167 | | - object.editWindow.copy.doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0); |
---|
| 14693 | + object.clickInfo.pane = this; |
---|
| 14694 | + object.clickInfo.camera = renderCamera; |
---|
| 14695 | + object.clickInfo.x = x; |
---|
| 14696 | + object.clickInfo.y = y; |
---|
| 14697 | + object //.GetWindow().copy |
---|
| 14698 | + .doEditDrag(//info, |
---|
| 14699 | + (modifiers & MouseEvent.BUTTON3_MASK) != 0); |
---|
14168 | 14700 | } else |
---|
14169 | 14701 | { |
---|
14170 | 14702 | if (x < startX) |
---|
.. | .. |
---|
14313 | 14845 | } |
---|
14314 | 14846 | } |
---|
14315 | 14847 | |
---|
| 14848 | +// ClickInfo clickInfo = new ClickInfo(); |
---|
| 14849 | + |
---|
14316 | 14850 | public void mouseMoved(MouseEvent e) |
---|
14317 | 14851 | { |
---|
14318 | 14852 | //System.out.println("mouseMoved: " + e); |
---|
14319 | 14853 | if (isRenderer) |
---|
14320 | 14854 | return; |
---|
14321 | 14855 | |
---|
14322 | | - ClickInfo ci = new ClickInfo(); |
---|
14323 | | - ci.x = e.getX(); |
---|
14324 | | - ci.y = e.getY(); |
---|
14325 | | - ci.modifiers = e.getModifiersEx(); |
---|
14326 | | - ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
14327 | | - ci.pane = this; |
---|
14328 | | - ci.camera = renderCamera; |
---|
| 14856 | + // Mouse cursor feedback |
---|
| 14857 | + object.clickInfo.x = e.getX(); |
---|
| 14858 | + object.clickInfo.y = e.getY(); |
---|
| 14859 | + object.clickInfo.modifiers = e.getModifiersEx(); |
---|
| 14860 | + object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
| 14861 | + object.clickInfo.pane = this; |
---|
| 14862 | + object.clickInfo.camera = renderCamera; |
---|
14329 | 14863 | if (!isRenderer) |
---|
14330 | 14864 | { |
---|
14331 | | - if (object.editWindow.copy.doEditClick(ci, 0)) |
---|
| 14865 | + //ObjEditor editWindow = object.editWindow; |
---|
| 14866 | + //Object3D copy = editWindow.copy; |
---|
| 14867 | + if (object.doEditClick(//clickInfo, |
---|
| 14868 | + 0)) |
---|
14332 | 14869 | { |
---|
14333 | 14870 | setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
---|
14334 | 14871 | } else |
---|
.. | .. |
---|
14340 | 14877 | |
---|
14341 | 14878 | public void mouseReleased(MouseEvent e) |
---|
14342 | 14879 | { |
---|
| 14880 | + Globals.MOUSEDRAGGED = false; |
---|
| 14881 | + |
---|
14343 | 14882 | movingcamera = false; |
---|
| 14883 | + X = 0; // getBounds().width/2; |
---|
| 14884 | + Y = 0; // getBounds().height/2; |
---|
14344 | 14885 | //System.out.println("mouseReleased: " + e); |
---|
14345 | 14886 | clickEnd(e.getX(), e.getY(), e.getModifiersEx()); |
---|
14346 | 14887 | } |
---|
.. | .. |
---|
14596 | 15137 | // break; |
---|
14597 | 15138 | case 'T': |
---|
14598 | 15139 | CACHETEXTURE ^= true; |
---|
14599 | | - textures.clear(); |
---|
| 15140 | + texturepigment.clear(); |
---|
| 15141 | + texturebump.clear(); |
---|
14600 | 15142 | // repaint(); |
---|
14601 | 15143 | break; |
---|
14602 | 15144 | case 'Y': |
---|
.. | .. |
---|
14681 | 15223 | case 'E' : COMPACT ^= true; |
---|
14682 | 15224 | repaint(); |
---|
14683 | 15225 | break; |
---|
14684 | | - case 'W' : DEBUGHSB ^= true; |
---|
| 15226 | + case 'W' : // Wide Window (fullscreen) |
---|
| 15227 | + //DEBUGHSB ^= true; |
---|
| 15228 | + ObjEditor.theFrame.ToggleFullScreen(); |
---|
14685 | 15229 | repaint(); |
---|
14686 | 15230 | break; |
---|
14687 | 15231 | case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break; |
---|
.. | .. |
---|
14706 | 15250 | RevertCamera(); |
---|
14707 | 15251 | repaint(); |
---|
14708 | 15252 | break; |
---|
14709 | | - case 'L': |
---|
14710 | 15253 | case 'l': |
---|
| 15254 | + //case 'L': |
---|
14711 | 15255 | if (lightMode) |
---|
14712 | 15256 | { |
---|
14713 | 15257 | lightMode = false; |
---|
.. | .. |
---|
14850 | 15394 | case '_': |
---|
14851 | 15395 | kompactbit = 5; |
---|
14852 | 15396 | break; |
---|
14853 | | - case '+': |
---|
14854 | | - kompactbit = 6; |
---|
14855 | | - break; |
---|
| 15397 | +// case '+': |
---|
| 15398 | +// kompactbit = 6; |
---|
| 15399 | +// break; |
---|
14856 | 15400 | case ' ': |
---|
14857 | 15401 | lightMode ^= true; |
---|
14858 | 15402 | Globals.lighttouched = true; |
---|
.. | .. |
---|
14864 | 15408 | case ESC: |
---|
14865 | 15409 | RENDERPROGRAM += 1; |
---|
14866 | 15410 | RENDERPROGRAM %= 3; |
---|
| 15411 | + |
---|
14867 | 15412 | repaint(); |
---|
14868 | 15413 | break; |
---|
14869 | 15414 | case 'Z': |
---|
14870 | 15415 | //RESIZETEXTURE ^= true; |
---|
14871 | 15416 | //break; |
---|
14872 | 15417 | case 'z': |
---|
14873 | | - RENDERSHADOW ^= true; |
---|
| 15418 | + Globals.RENDERSHADOW ^= true; |
---|
14874 | 15419 | Globals.lighttouched = true; |
---|
14875 | 15420 | repaint(); |
---|
14876 | 15421 | break; |
---|
.. | .. |
---|
14903 | 15448 | case DELETE: |
---|
14904 | 15449 | ClearSelection(); |
---|
14905 | 15450 | break; |
---|
14906 | | - /* |
---|
14907 | 15451 | case '+': |
---|
| 15452 | + |
---|
| 15453 | + /* |
---|
14908 | 15454 | //fontsize += 1; |
---|
14909 | 15455 | bbzoom *= 2; |
---|
14910 | 15456 | repaint(); |
---|
.. | .. |
---|
14921 | 15467 | case '=': |
---|
14922 | 15468 | IncDepth(); |
---|
14923 | 15469 | //fontsize += 1; |
---|
14924 | | - object.editWindow.refreshContents(true); |
---|
| 15470 | + object.GetWindow().refreshContents(true); |
---|
14925 | 15471 | maskbit = 6; |
---|
14926 | 15472 | break; |
---|
14927 | 15473 | case '-': //if (PixelThreshold>1) PixelThreshold /= 2; |
---|
14928 | 15474 | DecDepth(); |
---|
14929 | 15475 | maskbit = 5; |
---|
14930 | 15476 | //if(fontsize > 1) fontsize -= 1; |
---|
14931 | | - if (object.editWindow == null) |
---|
14932 | | - new Exception().printStackTrace(); |
---|
14933 | | - else |
---|
14934 | | - object.editWindow.refreshContents(true); |
---|
| 15477 | +// if (object.editWindow == null) |
---|
| 15478 | +// new Exception().printStackTrace(); |
---|
| 15479 | +// else |
---|
| 15480 | + object.GetWindow().refreshContents(true); |
---|
14935 | 15481 | break; |
---|
14936 | 15482 | case '{': |
---|
14937 | 15483 | manipCamera.shaper_fovy /= 1.1; |
---|
.. | .. |
---|
15155 | 15701 | } |
---|
15156 | 15702 | */ |
---|
15157 | 15703 | |
---|
15158 | | - object.editWindow.EditSelection(); |
---|
| 15704 | + object.GetWindow().EditSelection(false); |
---|
15159 | 15705 | } |
---|
15160 | 15706 | |
---|
15161 | 15707 | void SelectParent() |
---|
.. | .. |
---|
15172 | 15718 | { |
---|
15173 | 15719 | //selectees.remove(i); |
---|
15174 | 15720 | System.out.println("select parent of " + elem); |
---|
15175 | | - group.editWindow.Select(elem.parent.GetTreePath(), first, true); |
---|
| 15721 | + group.GetWindow().Select(elem.parent.GetTreePath(), first, true); |
---|
15176 | 15722 | } else |
---|
15177 | 15723 | { |
---|
15178 | | - group.editWindow.Select(elem.GetTreePath(), first, true); |
---|
| 15724 | + group.GetWindow().Select(elem.GetTreePath(), first, true); |
---|
15179 | 15725 | } |
---|
15180 | 15726 | |
---|
15181 | 15727 | first = false; |
---|
.. | .. |
---|
15217 | 15763 | for (int j = 0; j < group.children.size(); j++) |
---|
15218 | 15764 | { |
---|
15219 | 15765 | elem = (Object3D) group.children.elementAt(j); |
---|
15220 | | - object.editWindow.Select(elem.GetTreePath(), first, true); |
---|
| 15766 | + object.GetWindow().Select(elem.GetTreePath(), first, true); |
---|
15221 | 15767 | first = false; |
---|
15222 | 15768 | } |
---|
15223 | 15769 | } else |
---|
15224 | 15770 | { |
---|
15225 | | - object.editWindow.Select(elem.GetTreePath(), first, true); |
---|
| 15771 | + object.GetWindow().Select(elem.GetTreePath(), first, true); |
---|
15226 | 15772 | } |
---|
15227 | 15773 | |
---|
15228 | 15774 | first = false; |
---|
.. | .. |
---|
15233 | 15779 | { |
---|
15234 | 15780 | //Composite group = (Composite) object; |
---|
15235 | 15781 | Object3D group = object; |
---|
15236 | | - group.editWindow.loadClipboard(true); // ClearSelection(false); |
---|
| 15782 | + group.GetWindow().loadClipboard(true); // ClearSelection(false); |
---|
15237 | 15783 | } |
---|
15238 | 15784 | |
---|
15239 | 15785 | void ResetTransform(int mask) |
---|
15240 | 15786 | { |
---|
15241 | 15787 | //Composite group = (Composite) object; |
---|
15242 | 15788 | Object3D group = object; |
---|
15243 | | - group.editWindow.ResetTransform(mask); |
---|
| 15789 | + group.GetWindow().ResetTransform(mask); |
---|
15244 | 15790 | } |
---|
15245 | 15791 | |
---|
15246 | 15792 | void FlipTransform() |
---|
15247 | 15793 | { |
---|
15248 | 15794 | //Composite group = (Composite) object; |
---|
15249 | 15795 | Object3D group = object; |
---|
15250 | | - group.editWindow.FlipTransform(); |
---|
| 15796 | + group.GetWindow().FlipTransform(); |
---|
15251 | 15797 | // group.editWindow.ReduceMesh(true); |
---|
15252 | 15798 | } |
---|
15253 | 15799 | |
---|
.. | .. |
---|
15255 | 15801 | { |
---|
15256 | 15802 | //Composite group = (Composite) object; |
---|
15257 | 15803 | Object3D group = object; |
---|
15258 | | - group.editWindow.PrintMemory(); |
---|
| 15804 | + group.GetWindow().PrintMemory(); |
---|
15259 | 15805 | // group.editWindow.ReduceMesh(true); |
---|
15260 | 15806 | } |
---|
15261 | 15807 | |
---|
.. | .. |
---|
15263 | 15809 | { |
---|
15264 | 15810 | //Composite group = (Composite) object; |
---|
15265 | 15811 | Object3D group = object; |
---|
15266 | | - group.editWindow.ResetCentroid(); |
---|
| 15812 | + group.GetWindow().ResetCentroid(); |
---|
15267 | 15813 | } |
---|
15268 | 15814 | |
---|
15269 | 15815 | void IncDepth() |
---|
.. | .. |
---|
15345 | 15891 | |
---|
15346 | 15892 | int width = getBounds().width; |
---|
15347 | 15893 | int height = getBounds().height; |
---|
15348 | | - ClickInfo info = new ClickInfo(); |
---|
15349 | | - info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom)); |
---|
15350 | 15894 | //Image img = CreateImage(width, height); |
---|
15351 | 15895 | //System.out.println("width = " + width + "; height = " + height + "\n"); |
---|
| 15896 | + |
---|
15352 | 15897 | Graphics gr = g; // img.getGraphics(); |
---|
| 15898 | + |
---|
15353 | 15899 | if (!hasMarquee) |
---|
15354 | 15900 | { |
---|
15355 | 15901 | if (Xmin < Xmax) // !locked) |
---|
.. | .. |
---|
15421 | 15967 | } |
---|
15422 | 15968 | if (object != null && !hasMarquee) |
---|
15423 | 15969 | { |
---|
| 15970 | + if (object.clickInfo == null) |
---|
| 15971 | + object.clickInfo = new ClickInfo(); |
---|
| 15972 | + ClickInfo info = object.clickInfo; |
---|
| 15973 | + //ClickInfo info = new ClickInfo(); |
---|
| 15974 | + info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom)); |
---|
| 15975 | + |
---|
15424 | 15976 | if (isRenderer) |
---|
15425 | 15977 | { |
---|
15426 | | - info.flags++; |
---|
| 15978 | + object.clickInfo.flags++; |
---|
15427 | 15979 | double frameAspect = (double) width / (double) height; |
---|
15428 | 15980 | if (frameAspect > renderCamera.aspect) |
---|
15429 | 15981 | { |
---|
15430 | 15982 | int desired = (int) ((double) height * renderCamera.aspect); |
---|
15431 | | - info.bounds.width -= width - desired; |
---|
15432 | | - info.bounds.x += (width - desired) / 2; |
---|
| 15983 | + object.clickInfo.bounds.width -= width - desired; |
---|
| 15984 | + object.clickInfo.bounds.x += (width - desired) / 2; |
---|
15433 | 15985 | } else |
---|
15434 | 15986 | { |
---|
15435 | 15987 | int desired = (int) ((double) width / renderCamera.aspect); |
---|
15436 | | - info.bounds.height -= height - desired; |
---|
15437 | | - info.bounds.y += (height - desired) / 2; |
---|
| 15988 | + object.clickInfo.bounds.height -= height - desired; |
---|
| 15989 | + object.clickInfo.bounds.y += (height - desired) / 2; |
---|
15438 | 15990 | } |
---|
15439 | 15991 | } |
---|
15440 | | - info.g = gr; |
---|
15441 | | - info.camera = renderCamera; |
---|
| 15992 | + |
---|
| 15993 | + object.clickInfo.g = gr; |
---|
| 15994 | + object.clickInfo.camera = renderCamera; |
---|
15442 | 15995 | /* |
---|
15443 | 15996 | // Memory intensive (brep.verticescopy) |
---|
15444 | 15997 | if (!(object instanceof Composite)) |
---|
15445 | 15998 | object.draw(info, 0, false); // SLOW : |
---|
15446 | 15999 | */ |
---|
15447 | | - if (!isRenderer) |
---|
| 16000 | + if (!isRenderer) // && drag) |
---|
15448 | 16001 | { |
---|
15449 | | - object.drawEditHandles(info, 0); |
---|
| 16002 | + Grafreed.Assert(object != null); |
---|
| 16003 | + Grafreed.Assert(object.selection != null); |
---|
| 16004 | + if (object.selection.Size() > 0) |
---|
| 16005 | + { |
---|
| 16006 | + int hitSomething = object.selection.get(0).hitSomething; |
---|
| 16007 | + |
---|
| 16008 | + object.clickInfo.DX = 0; |
---|
| 16009 | + object.clickInfo.DY = 0; |
---|
| 16010 | + object.clickInfo.W = 1; |
---|
| 16011 | + if (hitSomething == Object3D.hitCenter) |
---|
| 16012 | + { |
---|
| 16013 | + info.DX = X; |
---|
| 16014 | + if (X != 0) |
---|
| 16015 | + info.DX -= info.bounds.width/2; |
---|
| 16016 | + |
---|
| 16017 | + info.DY = Y; |
---|
| 16018 | + if (Y != 0) |
---|
| 16019 | + info.DY -= info.bounds.height/2; |
---|
| 16020 | + } |
---|
| 16021 | + |
---|
| 16022 | + object.drawEditHandles(//info, |
---|
| 16023 | + 0); |
---|
| 16024 | + |
---|
| 16025 | + if (drag && (X != 0 || Y != 0)) |
---|
| 16026 | + { |
---|
| 16027 | + switch (hitSomething) |
---|
| 16028 | + { |
---|
| 16029 | + case Object3D.hitCenter: gr.setColor(Color.pink); |
---|
| 16030 | + gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
| 16031 | + break; |
---|
| 16032 | + case Object3D.hitRotate: gr.setColor(Color.yellow); |
---|
| 16033 | + gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
| 16034 | + break; |
---|
| 16035 | + case Object3D.hitScale: gr.setColor(Color.cyan); |
---|
| 16036 | + gr.drawLine(X, Y, 0, 0); |
---|
| 16037 | + break; |
---|
| 16038 | + } |
---|
| 16039 | + |
---|
| 16040 | + } |
---|
| 16041 | + } |
---|
15450 | 16042 | } |
---|
15451 | 16043 | } |
---|
| 16044 | + |
---|
15452 | 16045 | if (isRenderer) |
---|
15453 | 16046 | { |
---|
15454 | 16047 | //gr.setColor(Color.black); |
---|
15455 | 16048 | //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1); |
---|
15456 | 16049 | //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3); |
---|
15457 | 16050 | } |
---|
| 16051 | + |
---|
15458 | 16052 | if (hasMarquee) |
---|
15459 | 16053 | { |
---|
15460 | 16054 | gr.setXORMode(Color.white); |
---|
.. | .. |
---|
15861 | 16455 | Object3D object; |
---|
15862 | 16456 | static Object3D trackedobject; |
---|
15863 | 16457 | Camera renderCamera; // Light or Eye (or Occlusion) |
---|
15864 | | - /*static*/ Camera manipCamera; // Light or Eye |
---|
| 16458 | + /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light |
---|
15865 | 16459 | /*static*/ Camera eyeCamera; |
---|
15866 | 16460 | /*static*/ Camera lightCamera; |
---|
15867 | 16461 | int cameracount; |
---|
.. | .. |
---|
16146 | 16740 | cStatic.objectstack[materialdepth++] = checker; |
---|
16147 | 16741 | //System.out.println("material " + material); |
---|
16148 | 16742 | //Applet3D.tracein(this, selected); |
---|
16149 | | - vector2buffer = checker.projectedVertices; |
---|
| 16743 | + //vector2buffer = checker.projectedVertices; |
---|
16150 | 16744 | |
---|
16151 | 16745 | //checker.GetMaterial().Draw(this, false); // true); |
---|
16152 | | - DrawMaterial(checker.GetMaterial(), false); // true); |
---|
| 16746 | + DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true); |
---|
16153 | 16747 | |
---|
16154 | 16748 | materialdepth -= 1; |
---|
16155 | 16749 | if (materialdepth > 0) |
---|
16156 | 16750 | { |
---|
16157 | | - vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices; |
---|
16158 | | - DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]); |
---|
| 16751 | + //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices; |
---|
| 16752 | + DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices); |
---|
16159 | 16753 | } |
---|
16160 | 16754 | //checker.GetMaterial().opacity = 1f; |
---|
16161 | 16755 | ////checker.GetMaterial().ambient = 1f; |
---|
.. | .. |
---|
16241 | 16835 | } |
---|
16242 | 16836 | } |
---|
16243 | 16837 | |
---|
| 16838 | + private Object3D GetFolder() |
---|
| 16839 | + { |
---|
| 16840 | + Object3D folder = object.GetWindow().copy; |
---|
| 16841 | + if (object.GetWindow().copy.selection.Size() > 0) |
---|
| 16842 | + folder = object.GetWindow().copy.selection.elementAt(0); |
---|
| 16843 | + return folder; |
---|
| 16844 | + } |
---|
| 16845 | + |
---|
16244 | 16846 | class SelectBuffer implements GLEventListener |
---|
16245 | 16847 | { |
---|
16246 | 16848 | |
---|
.. | .. |
---|
16320 | 16922 | |
---|
16321 | 16923 | //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL); |
---|
16322 | 16924 | |
---|
| 16925 | + if (PAINTMODE) |
---|
| 16926 | + { |
---|
| 16927 | + if (object.GetWindow().copy.selection.Size() > 0) |
---|
| 16928 | + { |
---|
| 16929 | + Object3D paintobj = object.GetWindow().copy.selection.elementAt(0); |
---|
| 16930 | + |
---|
| 16931 | + // Make what you paint not selectable. |
---|
| 16932 | + paintobj.ResetSelectable(); |
---|
| 16933 | + } |
---|
| 16934 | + } |
---|
| 16935 | + |
---|
16323 | 16936 | //int tmp = selection_view; |
---|
16324 | 16937 | //selection_view = -1; |
---|
16325 | 16938 | int temp = DrawMode(); |
---|
.. | .. |
---|
16331 | 16944 | // temp = DEFAULT; // patch for selection debug |
---|
16332 | 16945 | Globals.drawMode = temp; // WARNING |
---|
16333 | 16946 | |
---|
| 16947 | + if (PAINTMODE) |
---|
| 16948 | + { |
---|
| 16949 | + if (object.GetWindow().copy.selection.Size() > 0) |
---|
| 16950 | + { |
---|
| 16951 | + Object3D paintobj = object.GetWindow().copy.selection.elementAt(0); |
---|
| 16952 | + |
---|
| 16953 | + // Revert. |
---|
| 16954 | + paintobj.RestoreSelectable(); |
---|
| 16955 | + } |
---|
| 16956 | + } |
---|
| 16957 | + |
---|
16334 | 16958 | //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view); |
---|
16335 | 16959 | |
---|
16336 | 16960 | // trying different ways of getting the depth info over |
---|
.. | .. |
---|
16378 | 17002 | // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]); |
---|
16379 | 17003 | // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]); |
---|
16380 | 17004 | // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]); |
---|
| 17005 | + |
---|
| 17006 | + CreateSelectedPoint(); |
---|
16381 | 17007 | |
---|
16382 | 17008 | // Will fit the mesh !!! |
---|
16383 | 17009 | selectedpoint.toParent[0][0] = 0.0001; |
---|
.. | .. |
---|
16432 | 17058 | } |
---|
16433 | 17059 | |
---|
16434 | 17060 | if (!movingcamera && !PAINTMODE) |
---|
16435 | | - object.editWindow.ScreenFitPoint(); // fev 2014 |
---|
| 17061 | + object.GetWindow().ScreenFitPoint(); // fev 2014 |
---|
16436 | 17062 | |
---|
16437 | | - if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0) |
---|
| 17063 | + if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0) |
---|
16438 | 17064 | { |
---|
16439 | | - Object3D paintobj = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0); |
---|
| 17065 | + //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0); |
---|
16440 | 17066 | |
---|
16441 | | - Object3D group = new Object3D("inst" + paintcount++); |
---|
| 17067 | + if (object.GetWindow().copy.selection.Size() > 0) |
---|
| 17068 | + { |
---|
| 17069 | + Object3D paintobj = object.GetWindow().copy.selection.elementAt(0); |
---|
16442 | 17070 | |
---|
16443 | | - group.CreateMaterial(); // use a void leaf to select instances |
---|
16444 | | - |
---|
16445 | | - group.add(paintobj); // link |
---|
16446 | | - |
---|
16447 | | - object.editWindow.SnapObject(group); |
---|
16448 | | - |
---|
16449 | | - Object3D folder = object.editWindow.copy; |
---|
16450 | | - |
---|
16451 | | - if (object.editWindow.copy.selection.Size() > 0) |
---|
16452 | | - folder = object.editWindow.copy.selection.elementAt(0); |
---|
16453 | | - |
---|
16454 | | - folder.add(group); |
---|
16455 | | - |
---|
16456 | | - object.editWindow.ResetModel(); |
---|
16457 | | - object.editWindow.refreshContents(); |
---|
| 17071 | + Object3D inst = new Object3D("inst" + paintcount++); |
---|
| 17072 | + |
---|
| 17073 | + inst.CreateMaterial(); // use a void leaf to select instances |
---|
| 17074 | + |
---|
| 17075 | + inst.add(paintobj); // link |
---|
| 17076 | + |
---|
| 17077 | + object.GetWindow().SnapObject(inst); |
---|
| 17078 | + |
---|
| 17079 | + Object3D folder = paintFolder; // GetFolder(); |
---|
| 17080 | + |
---|
| 17081 | + folder.add(inst); |
---|
| 17082 | + |
---|
| 17083 | + object.GetWindow().ResetModel(); |
---|
| 17084 | + object.GetWindow().refreshContents(); |
---|
| 17085 | + } |
---|
16458 | 17086 | } |
---|
16459 | 17087 | else |
---|
16460 | 17088 | paintcount = 0; |
---|
.. | .. |
---|
16493 | 17121 | //System.out.println("objects[color] = " + objects[color]); |
---|
16494 | 17122 | //objects[color].Select(); |
---|
16495 | 17123 | indexcount = 0; |
---|
| 17124 | + ObjEditor window = object.GetWindow(); |
---|
| 17125 | + if (window != null && deselect) |
---|
| 17126 | + { |
---|
| 17127 | + window.Select(null, deselect, true); |
---|
| 17128 | + } |
---|
16496 | 17129 | object.Select(color, deselect); |
---|
16497 | 17130 | } |
---|
16498 | 17131 | |
---|
.. | .. |
---|
16592 | 17225 | gl.glDisable(gl.GL_CULL_FACE); |
---|
16593 | 17226 | } |
---|
16594 | 17227 | |
---|
16595 | | - if (!RENDERSHADOW) |
---|
| 17228 | + if (!Globals.RENDERSHADOW) |
---|
16596 | 17229 | gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); |
---|
16597 | 17230 | |
---|
16598 | 17231 | // SB gl.glPolygonOffset(2.5f, 10); |
---|
.. | .. |
---|
16602 | 17235 | //gl.glColorMask(false, false, false, false); |
---|
16603 | 17236 | |
---|
16604 | 17237 | //render_scene_from_light_view(gl, drawable, 0, 0); |
---|
16605 | | - if (RENDERSHADOW && Globals.lighttouched && !movingcamera) // && !parent.IsFreezed()) |
---|
| 17238 | + if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed()) |
---|
16606 | 17239 | { |
---|
16607 | 17240 | gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); |
---|
16608 | 17241 | |
---|
.. | .. |
---|
17018 | 17651 | int AAbuffersize = 0; |
---|
17019 | 17652 | |
---|
17020 | 17653 | //double[] selectedpoint = new double[3]; |
---|
17021 | | - static Superellipsoid selectedpoint = new Superellipsoid(); |
---|
| 17654 | + static Superellipsoid selectedpoint; |
---|
17022 | 17655 | static Sphere previousselectedpoint = null; |
---|
17023 | | - static Sphere debugpointG = new Sphere(); |
---|
17024 | | - static Sphere debugpointP = new Sphere(); |
---|
17025 | | - static Sphere debugpointC = new Sphere(); |
---|
17026 | | - static Sphere debugpointR = new Sphere(); |
---|
| 17656 | + static Sphere debugpointG; |
---|
| 17657 | + static Sphere debugpointP; |
---|
| 17658 | + static Sphere debugpointC; |
---|
| 17659 | + static Sphere debugpointR; |
---|
17027 | 17660 | |
---|
17028 | 17661 | static Sphere debugpoints[] = new Sphere[8]; |
---|
17029 | 17662 | |
---|
17030 | | - static |
---|
17031 | | - { |
---|
17032 | | - for (int i=0; i<8; i++) |
---|
17033 | | - { |
---|
17034 | | - debugpoints[i] = new Sphere(); |
---|
17035 | | - } |
---|
17036 | | - } |
---|
17037 | | - |
---|
17038 | 17663 | static void InitPoints(float radius) |
---|
17039 | 17664 | { |
---|
17040 | 17665 | for (int i=0; i<8; i++) |
---|