.. | .. |
---|
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; |
---|
.. | .. |
---|
151 | 187 | } |
---|
152 | 188 | |
---|
153 | 189 | private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory(); |
---|
| 190 | + |
---|
| 191 | + public void LoadSkybox(String name, String ext, boolean mipmap) throws GLException |
---|
| 192 | + { |
---|
| 193 | + try |
---|
| 194 | + { |
---|
| 195 | + cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap); |
---|
| 196 | + } catch (IOException e) |
---|
| 197 | + { |
---|
| 198 | + System.out.println("NAME = " + name); |
---|
| 199 | + e.printStackTrace(); // throw new RuntimeException(e); |
---|
| 200 | + } |
---|
| 201 | + } |
---|
154 | 202 | |
---|
155 | 203 | void SetAsGLRenderer(boolean b) |
---|
156 | 204 | { |
---|
.. | .. |
---|
170 | 218 | |
---|
171 | 219 | SetCamera(cam); |
---|
172 | 220 | |
---|
173 | | - SetLight(new Camera(new cVector(10, 10, -20))); |
---|
| 221 | + // Warning: not used. |
---|
| 222 | + SetLight(new Camera(new cVector(15, 10, -20))); |
---|
174 | 223 | |
---|
175 | 224 | object = o; |
---|
176 | 225 | |
---|
.. | .. |
---|
327 | 376 | cStatic.objectstack[materialdepth++] = obj; |
---|
328 | 377 | //System.out.println("material " + material); |
---|
329 | 378 | //Applet3D.tracein(this, selected); |
---|
330 | | - display.vector2buffer = obj.projectedVertices; |
---|
| 379 | + //display.vector2buffer = obj.projectedVertices; |
---|
331 | 380 | if (obj instanceof Camera) |
---|
332 | 381 | { |
---|
333 | 382 | display.options1[0] = material.shift; |
---|
.. | .. |
---|
336 | 385 | display.options1[2] = material.shadowbias; |
---|
337 | 386 | display.options1[3] = material.aniso; |
---|
338 | 387 | display.options1[4] = material.anisoV; |
---|
| 388 | +// System.out.println("display.options1[0] " + display.options1[0]); |
---|
| 389 | +// System.out.println("display.options1[1] " + display.options1[1]); |
---|
| 390 | +// System.out.println("display.options1[2] " + display.options1[2]); |
---|
| 391 | +// System.out.println("display.options1[3] " + display.options1[3]); |
---|
| 392 | +// System.out.println("display.options1[4] " + display.options1[4]); |
---|
339 | 393 | display.options2[0] = material.opacity; |
---|
340 | 394 | display.options2[1] = material.diffuse; |
---|
341 | 395 | display.options2[2] = material.factor; |
---|
| 396 | +// System.out.println("display.options2[0] " + display.options2[0]); |
---|
| 397 | +// System.out.println("display.options2[1] " + display.options2[1]); |
---|
| 398 | +// System.out.println("display.options2[2] " + display.options2[2]); |
---|
342 | 399 | |
---|
343 | 400 | cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3); |
---|
| 401 | +// System.out.println("display.options3[0] " + display.options3[0]); |
---|
| 402 | +// System.out.println("display.options3[1] " + display.options3[1]); |
---|
| 403 | +// System.out.println("display.options3[2] " + display.options3[2]); |
---|
344 | 404 | display.options4[0] = material.cameralight/0.2f; |
---|
345 | 405 | display.options4[1] = material.subsurface; |
---|
346 | 406 | display.options4[2] = material.sheen; |
---|
| 407 | +// System.out.println("display.options4[0] " + display.options4[0]); |
---|
| 408 | +// System.out.println("display.options4[1] " + display.options4[1]); |
---|
| 409 | +// System.out.println("display.options4[2] " + display.options4[2]); |
---|
347 | 410 | |
---|
348 | 411 | // if (display.CURRENTANTIALIAS > 0) |
---|
349 | 412 | // display.options3[3] /= 4; |
---|
.. | .. |
---|
359 | 422 | /**/ |
---|
360 | 423 | } else |
---|
361 | 424 | { |
---|
362 | | - DrawMaterial(material, selected); |
---|
| 425 | + DrawMaterial(material, selected, obj.projectedVertices); |
---|
363 | 426 | } |
---|
364 | 427 | } else |
---|
365 | 428 | { |
---|
.. | .. |
---|
383 | 446 | cStatic.objectstack[materialdepth++] = obj; |
---|
384 | 447 | //System.out.println("material " + material); |
---|
385 | 448 | //Applet3D.tracein("selected ", selected); |
---|
386 | | - display.vector2buffer = obj.projectedVertices; |
---|
387 | | - display.DrawMaterial(material, selected); |
---|
| 449 | + //display.vector2buffer = obj.projectedVertices; |
---|
| 450 | + display.DrawMaterial(material, selected, obj.projectedVertices); |
---|
388 | 451 | } |
---|
389 | 452 | } |
---|
390 | 453 | |
---|
.. | .. |
---|
401 | 464 | materialdepth -= 1; |
---|
402 | 465 | if (materialdepth > 0) |
---|
403 | 466 | { |
---|
404 | | - display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices; |
---|
405 | | - display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]); |
---|
| 467 | + //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices; |
---|
| 468 | + display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices); |
---|
406 | 469 | } |
---|
407 | 470 | //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???"); |
---|
408 | 471 | } else if (selected && CameraPane.flash && obj.GetMaterial() != null) |
---|
.. | .. |
---|
422 | 485 | materialdepth -= 1; |
---|
423 | 486 | if (materialdepth > 0) |
---|
424 | 487 | { |
---|
425 | | - display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices; |
---|
426 | | - display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]); |
---|
| 488 | + //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices; |
---|
| 489 | + display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices); |
---|
427 | 490 | } |
---|
428 | 491 | //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???"); |
---|
429 | 492 | //else |
---|
.. | .. |
---|
464 | 527 | if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0) |
---|
465 | 528 | { |
---|
466 | 529 | //gl.glBegin(gl.GL_TRIANGLES); |
---|
467 | | - boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0); |
---|
| 530 | + boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0) |
---|
| 531 | + // TEST LIVE NORMALS && !obj.dontselect |
---|
| 532 | + ; |
---|
468 | 533 | if (!hasnorm) |
---|
469 | 534 | { |
---|
470 | | - // System.out.println("FUCK!!"); |
---|
| 535 | + // System.out.println("Mesh normal"); |
---|
471 | 536 | LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0); |
---|
472 | 537 | LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1); |
---|
473 | 538 | LA.vecCross(obj.v0, obj.v1, obj.v2); |
---|
.. | .. |
---|
1192 | 1257 | gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1); |
---|
1193 | 1258 | } |
---|
1194 | 1259 | } |
---|
| 1260 | + |
---|
1195 | 1261 | if (flipV) |
---|
1196 | 1262 | gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]); |
---|
1197 | 1263 | else |
---|
1198 | 1264 | gl.glTexCoord2f(uv[count2], uv[count2 + 1]); |
---|
| 1265 | + |
---|
1199 | 1266 | //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]); |
---|
1200 | 1267 | gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]); |
---|
1201 | 1268 | |
---|
.. | .. |
---|
1215 | 1282 | gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1); |
---|
1216 | 1283 | } |
---|
1217 | 1284 | } |
---|
| 1285 | + |
---|
1218 | 1286 | if (flipV) |
---|
1219 | 1287 | gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]); |
---|
1220 | 1288 | else |
---|
1221 | 1289 | gl.glTexCoord2f(uv[count2], uv[count2 + 1]); |
---|
| 1290 | + |
---|
1222 | 1291 | //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]); |
---|
1223 | 1292 | gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]); |
---|
1224 | 1293 | |
---|
.. | .. |
---|
1246 | 1315 | gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]); |
---|
1247 | 1316 | else |
---|
1248 | 1317 | gl.glTexCoord2f(uv[count2], uv[count2 + 1]); |
---|
| 1318 | + |
---|
1249 | 1319 | //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]); |
---|
1250 | 1320 | gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]); |
---|
| 1321 | + |
---|
1251 | 1322 | count2 += 2; |
---|
1252 | 1323 | count3 += 3; |
---|
1253 | 1324 | } |
---|
.. | .. |
---|
1426 | 1497 | gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z); |
---|
1427 | 1498 | } |
---|
1428 | 1499 | |
---|
| 1500 | + float[] colorV = new float[4]; |
---|
| 1501 | + |
---|
1429 | 1502 | void SetColor(Object3D obj, Vertex p0) |
---|
1430 | 1503 | { |
---|
1431 | 1504 | CameraPane display = this; |
---|
.. | .. |
---|
1493 | 1566 | { |
---|
1494 | 1567 | return; |
---|
1495 | 1568 | } |
---|
1496 | | - |
---|
1497 | | - float[] colorV = new float[3]; |
---|
1498 | 1569 | |
---|
1499 | 1570 | if (false) // marked) |
---|
1500 | 1571 | { |
---|
.. | .. |
---|
1603 | 1674 | // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0); |
---|
1604 | 1675 | } |
---|
1605 | 1676 | |
---|
1606 | | - void DrawMaterial(cMaterial material, boolean selected) |
---|
| 1677 | + void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others) |
---|
1607 | 1678 | { |
---|
1608 | 1679 | CameraPane display = this; |
---|
1609 | 1680 | //new Exception().printStackTrace(); |
---|
.. | .. |
---|
1638 | 1709 | colorV[0] = display.modelParams0[0] * material.diffuse; |
---|
1639 | 1710 | colorV[1] = display.modelParams0[1] * material.diffuse; |
---|
1640 | 1711 | colorV[2] = display.modelParams0[2] * material.diffuse; |
---|
1641 | | - colorV[3] = material.opacity; |
---|
| 1712 | + colorV[3] = 1; // material.opacity; |
---|
1642 | 1713 | |
---|
1643 | 1714 | gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity); |
---|
1644 | 1715 | //System.out.println("Opacity = " + opacity); |
---|
.. | .. |
---|
1746 | 1817 | display.modelParams7[2] = 0; |
---|
1747 | 1818 | display.modelParams7[3] = 0; |
---|
1748 | 1819 | |
---|
1749 | | - display.modelParams6[0] = 100; // criss de bug de bump |
---|
| 1820 | + //display.modelParams6[0] = 100; // criss de bug de bump |
---|
1750 | 1821 | |
---|
1751 | | - Object3D.cVector2[] extparams = display.vector2buffer; |
---|
| 1822 | + Object3D.cVector2[] extparams = others; // display.vector2buffer; |
---|
1752 | 1823 | if (extparams != null && extparams.length > 0 && extparams[0] != null) |
---|
1753 | 1824 | { |
---|
1754 | 1825 | display.modelParams6[0] = extparams[0].x / 1000.0f; // bump |
---|
.. | .. |
---|
2044 | 2115 | //System.err.println("Oeil on"); |
---|
2045 | 2116 | OEIL = true; |
---|
2046 | 2117 | if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode) |
---|
2047 | | - object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK); |
---|
| 2118 | + object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK); |
---|
2048 | 2119 | //pingthread.StepToTarget(true); |
---|
2049 | 2120 | } |
---|
2050 | 2121 | |
---|
.. | .. |
---|
2259 | 2330 | |
---|
2260 | 2331 | void ToggleDebug() |
---|
2261 | 2332 | { |
---|
2262 | | - DEBUG ^= true; |
---|
| 2333 | + Globals.DEBUG ^= true; |
---|
2263 | 2334 | } |
---|
2264 | 2335 | |
---|
2265 | 2336 | void ToggleLookAt() |
---|
.. | .. |
---|
2277 | 2348 | HANDLES ^= true; |
---|
2278 | 2349 | } |
---|
2279 | 2350 | |
---|
| 2351 | + Object3D paintFolder; |
---|
| 2352 | + |
---|
2280 | 2353 | void TogglePaint() |
---|
2281 | 2354 | { |
---|
2282 | 2355 | PAINTMODE ^= true; |
---|
2283 | 2356 | paintcount = 0; |
---|
| 2357 | + |
---|
| 2358 | + if (PAINTMODE) |
---|
| 2359 | + { |
---|
| 2360 | + paintFolder = GetFolder(); |
---|
| 2361 | + } |
---|
2284 | 2362 | } |
---|
2285 | 2363 | |
---|
2286 | 2364 | void SwapCamera(int a, int b) |
---|
.. | .. |
---|
2377 | 2455 | return currentGL; |
---|
2378 | 2456 | } |
---|
2379 | 2457 | |
---|
| 2458 | + static private BufferedImage CreateBim(TextureData texturedata) |
---|
| 2459 | + { |
---|
| 2460 | + Grafreed.Assert(texturedata != null); |
---|
| 2461 | + |
---|
| 2462 | + int width = texturedata.getWidth(); |
---|
| 2463 | + int height = texturedata.getHeight(); |
---|
| 2464 | + |
---|
| 2465 | + Buffer buffer = texturedata.getBuffer(); |
---|
| 2466 | + ByteBuffer bytebuf = (ByteBuffer)buffer; |
---|
| 2467 | + |
---|
| 2468 | + byte[] bytes = bytebuf.array(); |
---|
| 2469 | + |
---|
| 2470 | + return CreateBim(bytes, width, height); |
---|
| 2471 | + } |
---|
| 2472 | + |
---|
2380 | 2473 | /**/ |
---|
2381 | 2474 | class CacheTexture |
---|
2382 | 2475 | { |
---|
.. | .. |
---|
2385 | 2478 | |
---|
2386 | 2479 | int resolution; |
---|
2387 | 2480 | |
---|
2388 | | - CacheTexture(com.sun.opengl.util.texture.Texture tex, int res) |
---|
| 2481 | + CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res) |
---|
2389 | 2482 | { |
---|
2390 | | - texture = tex; |
---|
| 2483 | + texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata); |
---|
| 2484 | + texturedata = texdata; |
---|
2391 | 2485 | resolution = res; |
---|
2392 | 2486 | } |
---|
2393 | 2487 | } |
---|
2394 | 2488 | /**/ |
---|
2395 | 2489 | |
---|
2396 | 2490 | // TEXTURE static Texture texture; |
---|
2397 | | - static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures |
---|
2398 | | - = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>(); |
---|
2399 | | - static public java.util.Hashtable<String, String> usedtextures = new java.util.Hashtable<String, String>(); |
---|
| 2491 | + static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>(); |
---|
| 2492 | + static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>(); |
---|
| 2493 | + static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>(); |
---|
| 2494 | + static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>(); |
---|
| 2495 | + |
---|
2400 | 2496 | int pigmentdepth = 0; |
---|
2401 | 2497 | public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536]; |
---|
2402 | 2498 | int bumpdepth = 0; |
---|
2403 | 2499 | public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536]; |
---|
2404 | 2500 | //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE"; |
---|
2405 | 2501 | public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP"); |
---|
2406 | | - public static String NOISE_TEXTURE = "WHITE_NOISE"; |
---|
| 2502 | + public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:"); |
---|
2407 | 2503 | // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL"); |
---|
2408 | 2504 | |
---|
2409 | | - com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump) |
---|
| 2505 | + com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump) |
---|
2410 | 2506 | { |
---|
2411 | 2507 | TextureData texturedata = null; |
---|
2412 | 2508 | |
---|
.. | .. |
---|
2425 | 2521 | if (bump) |
---|
2426 | 2522 | texturedata = ConvertBump(texturedata, false); |
---|
2427 | 2523 | |
---|
2428 | | - com.sun.opengl.util.texture.Texture texture = |
---|
2429 | | - com.sun.opengl.util.texture.TextureIO.newTexture(texturedata); |
---|
| 2524 | +// com.sun.opengl.util.texture.Texture texture = |
---|
| 2525 | +// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata); |
---|
2430 | 2526 | |
---|
2431 | | - texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT); |
---|
2432 | | - texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT); |
---|
| 2527 | + //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT); |
---|
| 2528 | + //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT); |
---|
2433 | 2529 | |
---|
2434 | | - return texture; |
---|
| 2530 | + return texturedata; |
---|
| 2531 | + } |
---|
| 2532 | + |
---|
| 2533 | + com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump) |
---|
| 2534 | + { |
---|
| 2535 | + TextureData texturedata = null; |
---|
| 2536 | + |
---|
| 2537 | + try |
---|
| 2538 | + { |
---|
| 2539 | + texturedata = |
---|
| 2540 | + com.sun.opengl.util.texture.TextureIO.newTextureData( |
---|
| 2541 | + bim, |
---|
| 2542 | + true); |
---|
| 2543 | + } catch (Exception e) |
---|
| 2544 | + { |
---|
| 2545 | + throw new javax.media.opengl.GLException(e); |
---|
| 2546 | + } |
---|
| 2547 | + |
---|
| 2548 | + if (bump) |
---|
| 2549 | + texturedata = ConvertBump(texturedata, false); |
---|
| 2550 | + |
---|
| 2551 | + return texturedata; |
---|
2435 | 2552 | } |
---|
2436 | 2553 | |
---|
2437 | 2554 | boolean HUESMOOTH = true; // wrap around bug... true; |
---|
.. | .. |
---|
3504 | 3621 | |
---|
3505 | 3622 | System.out.println("LOADING TEXTURE : " + name); |
---|
3506 | 3623 | |
---|
| 3624 | + Object x = texturedata.getMipmapData(); // .getBuffer(); |
---|
| 3625 | + |
---|
3507 | 3626 | // |
---|
3508 | 3627 | if (false) // compressbit > 0) |
---|
3509 | 3628 | { |
---|
.. | .. |
---|
7902 | 8021 | String pigment = Object3D.GetPigment(tex); |
---|
7903 | 8022 | String bump = Object3D.GetBump(tex); |
---|
7904 | 8023 | |
---|
7905 | | - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8024 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
7906 | 8025 | { |
---|
7907 | 8026 | // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment); |
---|
7908 | 8027 | // System.out.println("; bump = " + bump); |
---|
.. | .. |
---|
7917 | 8036 | pigment = null; |
---|
7918 | 8037 | } |
---|
7919 | 8038 | |
---|
7920 | | - ReleaseTexture(bump, true); |
---|
7921 | | - ReleaseTexture(pigment, false); |
---|
| 8039 | + ReleaseTexture(tex, true); |
---|
| 8040 | + ReleaseTexture(tex, false); |
---|
7922 | 8041 | } |
---|
7923 | 8042 | |
---|
7924 | | - void ReleaseTexture(String tex, boolean bump) |
---|
| 8043 | + public void ReleasePigmentTexture(cTexture tex) // INTERFACE |
---|
| 8044 | + { |
---|
| 8045 | + if (/*tex == null ||*/ ambientOcclusion ) // || !textureon) |
---|
| 8046 | + { |
---|
| 8047 | + return; |
---|
| 8048 | + } |
---|
| 8049 | + |
---|
| 8050 | + if (tex == null) |
---|
| 8051 | + { |
---|
| 8052 | + ReleaseTexture(null, false); |
---|
| 8053 | + return; |
---|
| 8054 | + } |
---|
| 8055 | + |
---|
| 8056 | + String pigment = Object3D.GetPigment(tex); |
---|
| 8057 | + |
---|
| 8058 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8059 | + { |
---|
| 8060 | + // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment); |
---|
| 8061 | + // System.out.println("; bump = " + bump); |
---|
| 8062 | + } |
---|
| 8063 | + |
---|
| 8064 | + if (pigment.equals("")) |
---|
| 8065 | + { |
---|
| 8066 | + pigment = null; |
---|
| 8067 | + } |
---|
| 8068 | + |
---|
| 8069 | + ReleaseTexture(tex, false); |
---|
| 8070 | + } |
---|
| 8071 | + |
---|
| 8072 | + public void ReleaseBumpTexture(cTexture tex) // INTERFACE |
---|
| 8073 | + { |
---|
| 8074 | + if (/*tex == null ||*/ ambientOcclusion ) // || !textureon) |
---|
| 8075 | + { |
---|
| 8076 | + return; |
---|
| 8077 | + } |
---|
| 8078 | + |
---|
| 8079 | + if (tex == null) |
---|
| 8080 | + { |
---|
| 8081 | + ReleaseTexture(null, true); |
---|
| 8082 | + return; |
---|
| 8083 | + } |
---|
| 8084 | + |
---|
| 8085 | + String bump = Object3D.GetBump(tex); |
---|
| 8086 | + |
---|
| 8087 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8088 | + { |
---|
| 8089 | + // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment); |
---|
| 8090 | + // System.out.println("; bump = " + bump); |
---|
| 8091 | + } |
---|
| 8092 | + |
---|
| 8093 | + if (bump.equals("")) |
---|
| 8094 | + { |
---|
| 8095 | + bump = null; |
---|
| 8096 | + } |
---|
| 8097 | + |
---|
| 8098 | + ReleaseTexture(tex, true); |
---|
| 8099 | + } |
---|
| 8100 | + |
---|
| 8101 | + void ReleaseTexture(cTexture tex, boolean bump) |
---|
7925 | 8102 | { |
---|
7926 | 8103 | if (// DrawMode() != 0 || /*tex == null ||*/ |
---|
7927 | 8104 | ambientOcclusion ) // || !textureon) |
---|
.. | .. |
---|
7932 | 8109 | CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null; |
---|
7933 | 8110 | |
---|
7934 | 8111 | if (tex != null) |
---|
7935 | | - texture = textures.get(tex); |
---|
| 8112 | + texture = bump ? texturebump.get(tex) : texturepigment.get(tex); |
---|
7936 | 8113 | |
---|
7937 | 8114 | // //assert( texture != null ); |
---|
7938 | 8115 | // if (texture == null) |
---|
.. | .. |
---|
8026 | 8203 | |
---|
8027 | 8204 | /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE |
---|
8028 | 8205 | { |
---|
| 8206 | +// if (// DrawMode() != 0 || /*tex == null ||*/ |
---|
| 8207 | +// ambientOcclusion ) // || !textureon) |
---|
| 8208 | +// { |
---|
| 8209 | +// return; // false; |
---|
| 8210 | +// } |
---|
| 8211 | +// |
---|
| 8212 | +// if (tex == null) |
---|
| 8213 | +// { |
---|
| 8214 | +// BindTexture(null,false,resolution); |
---|
| 8215 | +// BindTexture(null,true,resolution); |
---|
| 8216 | +// return; |
---|
| 8217 | +// } |
---|
| 8218 | +// |
---|
| 8219 | +// String pigment = Object3D.GetPigment(tex); |
---|
| 8220 | +// String bump = Object3D.GetBump(tex); |
---|
| 8221 | +// |
---|
| 8222 | +// usedtextures.add(pigment); |
---|
| 8223 | +// usedtextures.add(bump); |
---|
| 8224 | +// |
---|
| 8225 | +// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8226 | +// { |
---|
| 8227 | +// // System.out.print("BIND +++++++++++++++ pigment = " + pigment); |
---|
| 8228 | +// // System.out.println("; bump = " + bump); |
---|
| 8229 | +// } |
---|
| 8230 | +// |
---|
| 8231 | +// if (bump.equals("")) |
---|
| 8232 | +// { |
---|
| 8233 | +// bump = null; |
---|
| 8234 | +// } |
---|
| 8235 | +// if (pigment.equals("")) |
---|
| 8236 | +// { |
---|
| 8237 | +// pigment = null; |
---|
| 8238 | +// } |
---|
| 8239 | +// |
---|
| 8240 | +// GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
| 8241 | +// BindTexture(pigment, false, resolution); |
---|
| 8242 | +// GetGL().glActiveTexture(GetGL().GL_TEXTURE2); |
---|
| 8243 | +// BindTexture(bump, true, resolution); |
---|
| 8244 | +// GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
| 8245 | +// |
---|
| 8246 | +// return; // true; |
---|
| 8247 | + |
---|
| 8248 | + BindPigmentTexture(tex, resolution); |
---|
| 8249 | + BindBumpTexture(tex, resolution); |
---|
| 8250 | + } |
---|
| 8251 | + |
---|
| 8252 | + /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE |
---|
| 8253 | + { |
---|
8029 | 8254 | if (// DrawMode() != 0 || /*tex == null ||*/ |
---|
8030 | 8255 | ambientOcclusion ) // || !textureon) |
---|
8031 | 8256 | { |
---|
.. | .. |
---|
8035 | 8260 | if (tex == null) |
---|
8036 | 8261 | { |
---|
8037 | 8262 | BindTexture(null,false,resolution); |
---|
8038 | | - BindTexture(null,true,resolution); |
---|
8039 | 8263 | return; |
---|
8040 | 8264 | } |
---|
8041 | 8265 | |
---|
8042 | 8266 | String pigment = Object3D.GetPigment(tex); |
---|
| 8267 | + |
---|
| 8268 | + usedtextures.add(tex); |
---|
| 8269 | + |
---|
| 8270 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8271 | + { |
---|
| 8272 | + // System.out.print("BIND +++++++++++++++ pigment = " + pigment); |
---|
| 8273 | + // System.out.println("; bump = " + bump); |
---|
| 8274 | + } |
---|
| 8275 | + |
---|
| 8276 | + if (pigment.equals("")) |
---|
| 8277 | + { |
---|
| 8278 | + pigment = null; |
---|
| 8279 | + } |
---|
| 8280 | + |
---|
| 8281 | + GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
| 8282 | + BindTexture(tex, false, resolution); |
---|
| 8283 | + } |
---|
| 8284 | + |
---|
| 8285 | + /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE |
---|
| 8286 | + { |
---|
| 8287 | + if (// DrawMode() != 0 || /*tex == null ||*/ |
---|
| 8288 | + ambientOcclusion ) // || !textureon) |
---|
| 8289 | + { |
---|
| 8290 | + return; // false; |
---|
| 8291 | + } |
---|
| 8292 | + |
---|
| 8293 | + if (tex == null) |
---|
| 8294 | + { |
---|
| 8295 | + BindTexture(null,true,resolution); |
---|
| 8296 | + return; |
---|
| 8297 | + } |
---|
| 8298 | + |
---|
8043 | 8299 | String bump = Object3D.GetBump(tex); |
---|
8044 | 8300 | |
---|
8045 | | - usedtextures.put(pigment, pigment); |
---|
8046 | | - usedtextures.put(bump, bump); |
---|
| 8301 | + usedtextures.add(tex); |
---|
8047 | 8302 | |
---|
8048 | | - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8303 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
8049 | 8304 | { |
---|
8050 | 8305 | // System.out.print("BIND +++++++++++++++ pigment = " + pigment); |
---|
8051 | 8306 | // System.out.println("; bump = " + bump); |
---|
.. | .. |
---|
8055 | 8310 | { |
---|
8056 | 8311 | bump = null; |
---|
8057 | 8312 | } |
---|
8058 | | - if (pigment.equals("")) |
---|
8059 | | - { |
---|
8060 | | - pigment = null; |
---|
8061 | | - } |
---|
8062 | 8313 | |
---|
8063 | | - GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
8064 | | - BindTexture(pigment, false, resolution); |
---|
8065 | 8314 | GetGL().glActiveTexture(GetGL().GL_TEXTURE2); |
---|
8066 | | - BindTexture(bump, true, resolution); |
---|
| 8315 | + BindTexture(tex, true, resolution); |
---|
8067 | 8316 | GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
8068 | | - |
---|
8069 | | - return; // true; |
---|
8070 | 8317 | } |
---|
8071 | 8318 | |
---|
8072 | 8319 | java.util.HashSet<String> missingTextures = new java.util.HashSet<String>(); |
---|
.. | .. |
---|
8089 | 8336 | return fileExists; |
---|
8090 | 8337 | } |
---|
8091 | 8338 | |
---|
8092 | | - CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception |
---|
| 8339 | + CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8093 | 8340 | { |
---|
8094 | | - CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null; |
---|
| 8341 | + CacheTexture texturecache = null; |
---|
8095 | 8342 | |
---|
8096 | 8343 | if (tex != null) |
---|
8097 | 8344 | { |
---|
8098 | | - String texname = tex; |
---|
| 8345 | + String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex); |
---|
| 8346 | + byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata; |
---|
| 8347 | + |
---|
| 8348 | + if (texname.equals("") && texdata == null) |
---|
| 8349 | + { |
---|
| 8350 | + return null; |
---|
| 8351 | + } |
---|
8099 | 8352 | |
---|
8100 | 8353 | String fallbackTextureName = defaultDirectory + "/Textures/" + texname; |
---|
8101 | 8354 | |
---|
.. | .. |
---|
8105 | 8358 | // else |
---|
8106 | 8359 | // if (!texname.startsWith("/")) |
---|
8107 | 8360 | // texname = "/Users/nbriere/Textures/" + texname; |
---|
8108 | | - if (!FileExists(tex)) |
---|
| 8361 | + if (!FileExists(texname)) |
---|
8109 | 8362 | { |
---|
8110 | 8363 | texname = fallbackTextureName; |
---|
8111 | 8364 | } |
---|
8112 | 8365 | |
---|
8113 | 8366 | if (CACHETEXTURE) |
---|
8114 | | - texture = textures.get(texname); // TEXTURE CACHE |
---|
8115 | | - |
---|
8116 | | - TextureData texturedata = null; |
---|
8117 | | - |
---|
8118 | | - if (texture == null || texture.resolution < resolution) |
---|
8119 | 8367 | { |
---|
8120 | | - if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals("")) |
---|
| 8368 | + if (texdata == null) |
---|
| 8369 | + texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex); |
---|
| 8370 | + else |
---|
| 8371 | + texturecache = bimtextures.get(texdata); |
---|
| 8372 | + } |
---|
| 8373 | + |
---|
| 8374 | + if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution) |
---|
| 8375 | + { |
---|
| 8376 | + TextureData texturedata = null; |
---|
| 8377 | + |
---|
| 8378 | + if (texdata != null && textureon) |
---|
| 8379 | + { |
---|
| 8380 | + BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB); |
---|
| 8381 | + |
---|
| 8382 | + try |
---|
| 8383 | + { |
---|
| 8384 | + bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph); |
---|
| 8385 | + } |
---|
| 8386 | + catch (Exception e) |
---|
| 8387 | + { |
---|
| 8388 | + bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph); |
---|
| 8389 | + } |
---|
| 8390 | + |
---|
| 8391 | + texturecache = new CacheTexture(GetBimTexture(bim, bump), -1); |
---|
| 8392 | + bimtextures.put(texdata, texturecache); |
---|
| 8393 | + |
---|
| 8394 | + //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB); |
---|
| 8395 | + |
---|
| 8396 | + //Object bim2 = CreateBim(texturecache.texturedata); |
---|
| 8397 | + //bim2 = bim; |
---|
| 8398 | + } |
---|
| 8399 | + else |
---|
| 8400 | + if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals("")) |
---|
8121 | 8401 | { |
---|
8122 | 8402 | assert(!bump); |
---|
8123 | 8403 | // if (bump) |
---|
.. | .. |
---|
8128 | 8408 | // } |
---|
8129 | 8409 | // else |
---|
8130 | 8410 | // { |
---|
8131 | | - texture = textures.get(tex); |
---|
8132 | | - if (texture == null) |
---|
| 8411 | + // texturecache = textures.get(texname); // suspicious |
---|
| 8412 | + if (texturecache == null) |
---|
8133 | 8413 | { |
---|
8134 | | - texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
| 8414 | + texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
8135 | 8415 | } |
---|
| 8416 | + else |
---|
| 8417 | + new Exception().printStackTrace(); |
---|
8136 | 8418 | // } |
---|
8137 | 8419 | } else |
---|
8138 | | - if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals("")) |
---|
| 8420 | + if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals("")) |
---|
8139 | 8421 | { |
---|
8140 | 8422 | assert(bump); |
---|
8141 | | - texture = textures.get(tex); |
---|
8142 | | - if (texture == null) |
---|
8143 | | - texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
| 8423 | + // texturecache = textures.get(texname); // suspicious |
---|
| 8424 | + if (texturecache == null) |
---|
| 8425 | + texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
| 8426 | + else |
---|
| 8427 | + new Exception().printStackTrace(); |
---|
8144 | 8428 | } else |
---|
8145 | 8429 | { |
---|
8146 | 8430 | //if (tex.equals("IMMORTAL")) |
---|
.. | .. |
---|
8148 | 8432 | // texture = GetResourceTexture("default.png"); |
---|
8149 | 8433 | //} else |
---|
8150 | 8434 | //{ |
---|
8151 | | - if (tex.equals("WHITE_NOISE")) |
---|
| 8435 | + if (texname.endsWith("WHITE_NOISE")) |
---|
8152 | 8436 | { |
---|
8153 | | - texture = textures.get(tex); |
---|
8154 | | - if (texture == null) |
---|
8155 | | - texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution); |
---|
| 8437 | + // texturecache = textures.get(texname); // suspicious |
---|
| 8438 | + if (texturecache == null) |
---|
| 8439 | + texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution); |
---|
| 8440 | + else |
---|
| 8441 | + new Exception().printStackTrace(); |
---|
8156 | 8442 | } else |
---|
8157 | 8443 | { |
---|
8158 | 8444 | if (textureon) |
---|
.. | .. |
---|
8211 | 8497 | if (texturedata == null) |
---|
8212 | 8498 | throw new Exception(); |
---|
8213 | 8499 | |
---|
8214 | | - texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution); |
---|
| 8500 | + texturecache = new CacheTexture(texturedata,resolution); |
---|
8215 | 8501 | //texture = GetTexture(tex, bump); |
---|
8216 | 8502 | } |
---|
8217 | 8503 | } |
---|
8218 | 8504 | //} |
---|
8219 | 8505 | } |
---|
8220 | 8506 | |
---|
8221 | | - if (/*CACHETEXTURE &&*/ texture != null && textureon) |
---|
| 8507 | + if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon) |
---|
8222 | 8508 | { |
---|
8223 | 8509 | //return false; |
---|
8224 | 8510 | |
---|
8225 | 8511 | // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")"); |
---|
8226 | | - if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG"))) |
---|
| 8512 | + if (texturedata != null && texname.toLowerCase().endsWith(".jpg")) |
---|
8227 | 8513 | { |
---|
8228 | 8514 | // String ext = "_highres"; |
---|
8229 | 8515 | // if (REDUCETEXTURE) |
---|
.. | .. |
---|
8240 | 8526 | File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg"); |
---|
8241 | 8527 | if (!cachefile.exists()) |
---|
8242 | 8528 | { |
---|
8243 | | - // cache to disk |
---|
8244 | | - Buffer buffer = texturedata.getBuffer(); // getMipmapData(); |
---|
8245 | | - //buffers[0]. |
---|
8246 | | - |
---|
8247 | | - ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer(); |
---|
8248 | | - int[] pixels = new int[bytebuf.capacity()/3]; |
---|
8249 | | - |
---|
8250 | | - // squared size heuristic... |
---|
8251 | | - if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length)) |
---|
| 8529 | + //if (texturedata.getWidth() == texturedata.getHeight()) |
---|
8252 | 8530 | { |
---|
8253 | | - for (int i=pixels.length; --i>=0;) |
---|
8254 | | - { |
---|
8255 | | - int i3 = i*3; |
---|
8256 | | - pixels[i] = 0xFF; |
---|
8257 | | - pixels[i] <<= 8; |
---|
8258 | | - pixels[i] |= bytebuf.get(i3+2) & 0xFF; |
---|
8259 | | - pixels[i] <<= 8; |
---|
8260 | | - pixels[i] |= bytebuf.get(i3+1) & 0xFF; |
---|
8261 | | - pixels[i] <<= 8; |
---|
8262 | | - pixels[i] |= bytebuf.get(i3) & 0xFF; |
---|
8263 | | - } |
---|
8264 | | - |
---|
8265 | | - /* |
---|
8266 | | - int r=0,g=0,b=0,a=0; |
---|
8267 | | - for (int i=0; i<width; i++) |
---|
8268 | | - for (int j=0; j<height; j++) |
---|
8269 | | - { |
---|
8270 | | - int index = j*width+i; |
---|
8271 | | - int p = pixels[index]; |
---|
8272 | | - a = ((p>>24) & 0xFF); |
---|
8273 | | - r = ((p>>16) & 0xFF); |
---|
8274 | | - g = ((p>>8) & 0xFF); |
---|
8275 | | - b = (p & 0xFF); |
---|
8276 | | - pixels[index] = (a<<24) | (b<<16) | (g<<8) | r; |
---|
8277 | | - } |
---|
8278 | | - /**/ |
---|
8279 | | - int width = (int)Math.sqrt(pixels.length); // squared |
---|
8280 | | - int height = width; |
---|
8281 | | - BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile); |
---|
8282 | | - rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width); |
---|
| 8531 | + BufferedImage rendImage = CreateBim(texturedata); |
---|
| 8532 | + |
---|
8283 | 8533 | ImageWriter writer = null; |
---|
8284 | 8534 | Iterator iter = ImageIO.getImageWritersByFormatName("jpg"); |
---|
8285 | 8535 | if (iter.hasNext()) { |
---|
8286 | 8536 | writer = (ImageWriter)iter.next(); |
---|
8287 | 8537 | } |
---|
8288 | | - float compressionQuality = 0.9f; |
---|
| 8538 | + |
---|
| 8539 | + float compressionQuality = 0.85f; |
---|
8289 | 8540 | try |
---|
8290 | 8541 | { |
---|
8291 | 8542 | ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile); |
---|
.. | .. |
---|
8302 | 8553 | } |
---|
8303 | 8554 | } |
---|
8304 | 8555 | } |
---|
8305 | | - |
---|
| 8556 | + |
---|
| 8557 | + Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment; |
---|
| 8558 | + |
---|
8306 | 8559 | //System.out.println("Texture = " + tex); |
---|
8307 | | - if (textures.containsKey(texname)) |
---|
| 8560 | + if (textures.containsKey(tex)) |
---|
8308 | 8561 | { |
---|
8309 | | - CacheTexture thetex = textures.get(texname); |
---|
| 8562 | + CacheTexture thetex = textures.get(tex); |
---|
8310 | 8563 | thetex.texture.disable(); |
---|
8311 | 8564 | thetex.texture.dispose(); |
---|
8312 | | - textures.remove(texname); |
---|
| 8565 | + textures.remove(tex); |
---|
8313 | 8566 | } |
---|
8314 | 8567 | |
---|
8315 | | - texture.texturedata = texturedata; |
---|
8316 | | - textures.put(texname, texture); |
---|
| 8568 | + //texture.texturedata = texturedata; |
---|
| 8569 | + textures.put(tex, texturecache); |
---|
8317 | 8570 | |
---|
8318 | 8571 | // newtex = true; |
---|
8319 | 8572 | } |
---|
.. | .. |
---|
8329 | 8582 | } |
---|
8330 | 8583 | } |
---|
8331 | 8584 | |
---|
8332 | | - return texture; |
---|
| 8585 | + return texturecache; |
---|
8333 | 8586 | } |
---|
8334 | 8587 | |
---|
8335 | | - com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution) throws Exception |
---|
| 8588 | + static void EmbedTextures(cTexture tex) |
---|
| 8589 | + { |
---|
| 8590 | + if (tex.pigmentdata == null) |
---|
| 8591 | + { |
---|
| 8592 | + //String texname = Object3D.GetPigment(tex); |
---|
| 8593 | + |
---|
| 8594 | + CacheTexture texturecache = texturepigment.get(tex); |
---|
| 8595 | + |
---|
| 8596 | + if (texturecache != null) |
---|
| 8597 | + { |
---|
| 8598 | + tex.pw = texturecache.texturedata.getWidth(); |
---|
| 8599 | + tex.ph = texturecache.texturedata.getHeight(); |
---|
| 8600 | + tex.pigmentdata = //CompressJPEG(CreateBim |
---|
| 8601 | + ((ByteBuffer)texturecache.texturedata.getBuffer()).array() |
---|
| 8602 | + ; |
---|
| 8603 | + //, tex.pw, tex.ph), 0.5f); |
---|
| 8604 | + } |
---|
| 8605 | + } |
---|
| 8606 | + |
---|
| 8607 | + if (tex.bumpdata == null) |
---|
| 8608 | + { |
---|
| 8609 | + //String texname = Object3D.GetBump(tex); |
---|
| 8610 | + |
---|
| 8611 | + CacheTexture texturecache = texturebump.get(tex); |
---|
| 8612 | + |
---|
| 8613 | + if (texturecache != null) |
---|
| 8614 | + { |
---|
| 8615 | + tex.bw = texturecache.texturedata.getWidth(); |
---|
| 8616 | + tex.bh = texturecache.texturedata.getHeight(); |
---|
| 8617 | + tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f); |
---|
| 8618 | + } |
---|
| 8619 | + } |
---|
| 8620 | + } |
---|
| 8621 | + |
---|
| 8622 | + com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8336 | 8623 | { |
---|
8337 | 8624 | CacheTexture texture = GetCacheTexture(tex, bump, resolution); |
---|
8338 | 8625 | |
---|
.. | .. |
---|
8350 | 8637 | return texture!=null?texture.texture:null; |
---|
8351 | 8638 | } |
---|
8352 | 8639 | |
---|
8353 | | - public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution) throws Exception |
---|
| 8640 | + public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8354 | 8641 | { |
---|
8355 | 8642 | CacheTexture texture = GetCacheTexture(tex, bump, resolution); |
---|
8356 | 8643 | |
---|
8357 | 8644 | return texture!=null?texture.texturedata:null; |
---|
8358 | 8645 | } |
---|
8359 | 8646 | |
---|
8360 | | - boolean BindTexture(String tex, boolean bump, int resolution) throws Exception |
---|
| 8647 | + boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8361 | 8648 | { |
---|
8362 | 8649 | if (/*tex == null ||*/ ambientOcclusion ) // || !textureon) |
---|
8363 | 8650 | { |
---|
8364 | 8651 | return false; |
---|
8365 | 8652 | } |
---|
8366 | 8653 | |
---|
8367 | | - boolean newtex = false; |
---|
| 8654 | + //boolean newtex = false; |
---|
8368 | 8655 | |
---|
8369 | 8656 | com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution); |
---|
8370 | 8657 | |
---|
.. | .. |
---|
8396 | 8683 | texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT); |
---|
8397 | 8684 | texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT); |
---|
8398 | 8685 | |
---|
8399 | | - return newtex; |
---|
| 8686 | + return true; // Warning: not used. |
---|
8400 | 8687 | } |
---|
8401 | 8688 | |
---|
| 8689 | + public static byte[] CompressJPEG(BufferedImage image, float quality) |
---|
| 8690 | + { |
---|
| 8691 | + try |
---|
| 8692 | + { |
---|
| 8693 | + ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
---|
| 8694 | + Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg"); |
---|
| 8695 | + ImageWriter writer = writers.next(); |
---|
| 8696 | + |
---|
| 8697 | + ImageWriteParam param = writer.getDefaultWriteParam(); |
---|
| 8698 | + param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); |
---|
| 8699 | + param.setCompressionQuality(quality); |
---|
| 8700 | + |
---|
| 8701 | + ImageOutputStream ios = ImageIO.createImageOutputStream(baos); |
---|
| 8702 | + writer.setOutput(ios); |
---|
| 8703 | + writer.write(null, new IIOImage(image, null, null), param); |
---|
| 8704 | + |
---|
| 8705 | + byte[] data = baos.toByteArray(); |
---|
| 8706 | + writer.dispose(); |
---|
| 8707 | + return data; |
---|
| 8708 | + } |
---|
| 8709 | + catch (Exception e) |
---|
| 8710 | + { |
---|
| 8711 | + e.printStackTrace(); |
---|
| 8712 | + return null; |
---|
| 8713 | + } |
---|
| 8714 | + } |
---|
| 8715 | + |
---|
| 8716 | + public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException |
---|
| 8717 | + { |
---|
| 8718 | + ByteArrayInputStream baos = new ByteArrayInputStream(image); |
---|
| 8719 | + Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg"); |
---|
| 8720 | + ImageReader reader = writers.next(); |
---|
| 8721 | + |
---|
| 8722 | + BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); |
---|
| 8723 | + |
---|
| 8724 | + ImageReadParam param = reader.getDefaultReadParam(); |
---|
| 8725 | + param.setDestination(bim); |
---|
| 8726 | + //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB)); |
---|
| 8727 | + |
---|
| 8728 | + ImageInputStream ios = ImageIO.createImageInputStream(baos); |
---|
| 8729 | + reader.setInput(ios); |
---|
| 8730 | + BufferedImage bim2 = reader.read(0, param); |
---|
| 8731 | + reader.dispose(); |
---|
| 8732 | + |
---|
| 8733 | +// WritableRaster raster = bim2.getRaster(); |
---|
| 8734 | +// DataBufferByte data = (DataBufferByte) raster.getDataBuffer(); |
---|
| 8735 | +// byte[] bytes = data.getData(); |
---|
| 8736 | +// |
---|
| 8737 | +// int[] pixels = new int[bytes.length/3]; |
---|
| 8738 | +// for (int i=pixels.length; --i>=0;) |
---|
| 8739 | +// { |
---|
| 8740 | +// int i3 = i*3; |
---|
| 8741 | +// pixels[i] = 0xFF; |
---|
| 8742 | +// pixels[i] <<= 8; |
---|
| 8743 | +// pixels[i] |= bytes[i3+2] & 0xFF; |
---|
| 8744 | +// pixels[i] <<= 8; |
---|
| 8745 | +// pixels[i] |= bytes[i3+1] & 0xFF; |
---|
| 8746 | +// pixels[i] <<= 8; |
---|
| 8747 | +// pixels[i] |= bytes[i3] & 0xFF; |
---|
| 8748 | +// } |
---|
| 8749 | +// |
---|
| 8750 | +// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w); |
---|
| 8751 | + |
---|
| 8752 | + return bim; |
---|
| 8753 | + } |
---|
| 8754 | + |
---|
8402 | 8755 | ShadowBuffer shadowPBuf; |
---|
8403 | 8756 | AntialiasBuffer antialiasPBuf; |
---|
8404 | 8757 | int MAXSTACK; |
---|
.. | .. |
---|
8591 | 8944 | |
---|
8592 | 8945 | if (cubemap == null) |
---|
8593 | 8946 | { |
---|
8594 | | - LoadEnvy(5); |
---|
| 8947 | + //LoadEnvy(1); |
---|
8595 | 8948 | } |
---|
8596 | 8949 | |
---|
8597 | 8950 | //cubemap.enable(); |
---|
.. | .. |
---|
8878 | 9231 | cubemap = null; |
---|
8879 | 9232 | return; |
---|
8880 | 9233 | case 1: |
---|
8881 | | - name = "cubemaps/box_"; |
---|
8882 | | - ext = "png"; |
---|
| 9234 | + name = "cubemaps/rgb/"; |
---|
| 9235 | + ext = "jpg"; |
---|
8883 | 9236 | reverseUP = false; |
---|
8884 | 9237 | break; |
---|
8885 | 9238 | case 2: |
---|
8886 | | - name = "cubemaps/uffizi_"; |
---|
8887 | | - ext = "png"; |
---|
8888 | | - break; // reverseUP = true; break; |
---|
| 9239 | + name = "cubemaps/uffizi/"; |
---|
| 9240 | + ext = "jpg"; |
---|
| 9241 | + reverseUP = false; |
---|
| 9242 | + break; |
---|
8889 | 9243 | case 3: |
---|
8890 | | - name = "cubemaps/CloudyHills_"; |
---|
8891 | | - ext = "tga"; |
---|
| 9244 | + name = "cubemaps/CloudyHills/"; |
---|
| 9245 | + ext = "jpg"; |
---|
8892 | 9246 | reverseUP = false; |
---|
8893 | 9247 | break; |
---|
8894 | 9248 | case 4: |
---|
8895 | | - name = "cubemaps/cornell_"; |
---|
| 9249 | + name = "cubemaps/cornell/"; |
---|
8896 | 9250 | ext = "png"; |
---|
8897 | 9251 | reverseUP = false; |
---|
8898 | 9252 | break; |
---|
| 9253 | + case 5: |
---|
| 9254 | + name = "cubemaps/skycube/"; |
---|
| 9255 | + ext = "jpg"; |
---|
| 9256 | + reverseUP = false; |
---|
| 9257 | + break; |
---|
| 9258 | + case 6: |
---|
| 9259 | + name = "cubemaps/SaintLazarusChurch3/"; |
---|
| 9260 | + ext = "jpg"; |
---|
| 9261 | + reverseUP = false; |
---|
| 9262 | + break; |
---|
| 9263 | + case 7: |
---|
| 9264 | + name = "cubemaps/Sodermalmsallen/"; |
---|
| 9265 | + ext = "jpg"; |
---|
| 9266 | + reverseUP = false; |
---|
| 9267 | + break; |
---|
| 9268 | + case 8: |
---|
| 9269 | + name = "cubemaps/Sodermalmsallen2/"; |
---|
| 9270 | + ext = "jpg"; |
---|
| 9271 | + reverseUP = false; |
---|
| 9272 | + break; |
---|
| 9273 | + case 9: |
---|
| 9274 | + name = "cubemaps/UnionSquare/"; |
---|
| 9275 | + ext = "jpg"; |
---|
| 9276 | + reverseUP = false; |
---|
| 9277 | + break; |
---|
8899 | 9278 | default: |
---|
8900 | | - name = "cubemaps/rgb_"; |
---|
8901 | | - ext = "png"; /*mipmap = true;*/ reverseUP = false; |
---|
| 9279 | + name = "cubemaps/box/"; |
---|
| 9280 | + ext = "png"; /*mipmap = true;*/ |
---|
| 9281 | + reverseUP = false; |
---|
8902 | 9282 | break; |
---|
8903 | 9283 | } |
---|
8904 | | - |
---|
8905 | | - try |
---|
8906 | | - { |
---|
8907 | | - cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap); |
---|
8908 | | - } catch (IOException e) |
---|
8909 | | - { |
---|
8910 | | - throw new RuntimeException(e); |
---|
8911 | | - } |
---|
| 9284 | + |
---|
| 9285 | + LoadSkybox(name, ext, mipmap); |
---|
8912 | 9286 | } |
---|
8913 | 9287 | |
---|
8914 | 9288 | public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) |
---|
.. | .. |
---|
8940 | 9314 | static double[] model = new double[16]; |
---|
8941 | 9315 | double[] camera2light = new double[16]; |
---|
8942 | 9316 | double[] light2camera = new double[16]; |
---|
8943 | | - int newenvy = -1; |
---|
8944 | | - boolean envyoff = true; // false; |
---|
| 9317 | + |
---|
| 9318 | + //int newenvy = -1; |
---|
| 9319 | + //boolean envyoff = false; |
---|
| 9320 | + |
---|
| 9321 | + String loadedskyboxname; |
---|
| 9322 | + |
---|
8945 | 9323 | cVector light0 = new cVector(0, 0, 0); // 1,3,2); |
---|
8946 | 9324 | //float[] light0 = { 0,0,0 }; |
---|
8947 | 9325 | cVector dirlight = new cVector(0, 0, 1); // 1,3,2); |
---|
.. | .. |
---|
9234 | 9612 | jy8[3] = 0.5f; |
---|
9235 | 9613 | } |
---|
9236 | 9614 | |
---|
9237 | | - float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV |
---|
| 9615 | + float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV |
---|
9238 | 9616 | float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation |
---|
9239 | 9617 | float[] options3 = new float[]{1, 1, 1, 0}; // fog color |
---|
9240 | 9618 | float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen |
---|
9241 | 9619 | |
---|
| 9620 | + void ResetOptions() |
---|
| 9621 | + { |
---|
| 9622 | + options1[0] = 100; |
---|
| 9623 | + options1[1] = 0.025f; |
---|
| 9624 | + options1[2] = 0.01f; |
---|
| 9625 | + options1[3] = 0; |
---|
| 9626 | + options1[4] = 0; |
---|
| 9627 | + |
---|
| 9628 | + options2[0] = 0; |
---|
| 9629 | + options2[1] = 0.75f; |
---|
| 9630 | + options2[2] = 0; |
---|
| 9631 | + options2[3] = 0; |
---|
| 9632 | + |
---|
| 9633 | + options3[0] = 1; |
---|
| 9634 | + options3[1] = 1; |
---|
| 9635 | + options3[2] = 1; |
---|
| 9636 | + options3[3] = 0; |
---|
| 9637 | + |
---|
| 9638 | + options4[0] = 1; |
---|
| 9639 | + options4[1] = 0; |
---|
| 9640 | + options4[2] = 1; |
---|
| 9641 | + options4[3] = 0; |
---|
| 9642 | + } |
---|
| 9643 | + |
---|
9242 | 9644 | static int imagecount = 0; // movie generation |
---|
9243 | 9645 | |
---|
9244 | 9646 | static int jitter = 0; |
---|
.. | .. |
---|
9335 | 9737 | |
---|
9336 | 9738 | if (renderCamera != lightCamera) |
---|
9337 | 9739 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
9338 | | - LA.matConcat(matrix, parentcam.GlobalTransform(), matrix); |
---|
| 9740 | + LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix); |
---|
9339 | 9741 | |
---|
9340 | 9742 | // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix); |
---|
9341 | 9743 | |
---|
.. | .. |
---|
9351 | 9753 | |
---|
9352 | 9754 | if (renderCamera != lightCamera) |
---|
9353 | 9755 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
9354 | | - LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix); |
---|
| 9756 | + LA.matConcat(parentcam.GlobalTransform(), matrix, matrix); |
---|
9355 | 9757 | |
---|
9356 | 9758 | // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix); |
---|
9357 | 9759 | |
---|
.. | .. |
---|
9397 | 9799 | rati = 1 / rati; |
---|
9398 | 9800 | gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000); |
---|
9399 | 9801 | } |
---|
9400 | | - assert (newenvy == -1); |
---|
| 9802 | + |
---|
| 9803 | + //assert (newenvy == -1); |
---|
| 9804 | + |
---|
9401 | 9805 | gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
9402 | 9806 | gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB); |
---|
9403 | | - DrawSkyBox(gl); |
---|
| 9807 | + DrawSkyBox(gl, (float)rati); |
---|
9404 | 9808 | gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
9405 | 9809 | gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB); |
---|
9406 | 9810 | accPerspective(gl, renderCamera.shaper_fovy / ratio, |
---|
.. | .. |
---|
10349 | 10753 | ANTIALIAS = 0; |
---|
10350 | 10754 | //System.out.println("RESTART"); |
---|
10351 | 10755 | AAtimer.restart(); |
---|
| 10756 | + Globals.TIMERRUNNING = true; |
---|
10352 | 10757 | } |
---|
10353 | 10758 | } |
---|
10354 | 10759 | } |
---|
.. | .. |
---|
10416 | 10821 | ambientOcclusion = false; |
---|
10417 | 10822 | } |
---|
10418 | 10823 | |
---|
10419 | | - if (Globals.lighttouched && DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN) |
---|
| 10824 | + if (//Globals.lighttouched && |
---|
| 10825 | + DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN) |
---|
10420 | 10826 | { |
---|
10421 | 10827 | //if (RENDERSHADOW) // ? |
---|
10422 | 10828 | if (!IsFrozen()) |
---|
.. | .. |
---|
10550 | 10956 | // if (parentcam != renderCamera) // not a light |
---|
10551 | 10957 | if (cam != lightCamera) |
---|
10552 | 10958 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
10553 | | - LA.matConcat(matrix, parentcam.GlobalTransform(), matrix); |
---|
| 10959 | + LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix); |
---|
10554 | 10960 | |
---|
10555 | 10961 | for (int j = 0; j < 4; j++) |
---|
10556 | 10962 | { |
---|
.. | .. |
---|
10565 | 10971 | // if (parentcam != renderCamera) // not a light |
---|
10566 | 10972 | if (cam != lightCamera) |
---|
10567 | 10973 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
10568 | | - LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix); |
---|
| 10974 | + LA.matConcat(parentcam.GlobalTransform(), matrix, matrix); |
---|
10569 | 10975 | |
---|
10570 | 10976 | //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix); |
---|
10571 | 10977 | |
---|
.. | .. |
---|
10651 | 11057 | gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000); |
---|
10652 | 11058 | } |
---|
10653 | 11059 | |
---|
10654 | | - if (newenvy > -1) |
---|
| 11060 | +// if (newenvy > -1) |
---|
| 11061 | +// { |
---|
| 11062 | +// LoadEnvy(newenvy); |
---|
| 11063 | +// } |
---|
| 11064 | +// |
---|
| 11065 | +// newenvy = -1; |
---|
| 11066 | + |
---|
| 11067 | + if (object.skyboxname != null) |
---|
10655 | 11068 | { |
---|
10656 | | - LoadEnvy(newenvy); |
---|
| 11069 | + if (!object.skyboxname.equals(this.loadedskyboxname)) |
---|
| 11070 | + { |
---|
| 11071 | + LoadSkybox(object.skyboxname + "/", object.skyboxext, false); |
---|
| 11072 | + loadedskyboxname = object.skyboxname; |
---|
| 11073 | + } |
---|
10657 | 11074 | } |
---|
10658 | | - |
---|
10659 | | - newenvy = -1; |
---|
10660 | | - |
---|
| 11075 | + else |
---|
| 11076 | + { |
---|
| 11077 | + cubemap = null; |
---|
| 11078 | + loadedskyboxname = null; |
---|
| 11079 | + } |
---|
| 11080 | + |
---|
10661 | 11081 | ratio = ((double) getWidth()) / getHeight(); |
---|
10662 | 11082 | //System.out.println("ratio = " + ratio); |
---|
10663 | 11083 | |
---|
.. | .. |
---|
10673 | 11093 | |
---|
10674 | 11094 | if (!IsFrozen() && !ambientOcclusion) |
---|
10675 | 11095 | { |
---|
10676 | | - DrawSkyBox(gl); |
---|
| 11096 | + DrawSkyBox(gl, (float)ratio); |
---|
10677 | 11097 | } |
---|
10678 | 11098 | |
---|
10679 | 11099 | //if (selection_view == -1) |
---|
.. | .. |
---|
10856 | 11276 | |
---|
10857 | 11277 | gl.glMatrixMode(GL.GL_MODELVIEW); |
---|
10858 | 11278 | |
---|
10859 | | -//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST); |
---|
10860 | | -//gl.glEnable(gl.GL_POLYGON_SMOOTH); |
---|
10861 | | -//gl.glEnable(gl.GL_MULTISAMPLE); |
---|
| 11279 | +gl.glEnable(gl.GL_POLYGON_SMOOTH); |
---|
| 11280 | +gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST); |
---|
| 11281 | +gl.glEnable(gl.GL_MULTISAMPLE); |
---|
10862 | 11282 | } else |
---|
10863 | 11283 | { |
---|
10864 | 11284 | //gl.glDisable(GL.GL_TEXTURE_2D); |
---|
.. | .. |
---|
10869 | 11289 | //System.out.println("BLENDING ON"); |
---|
10870 | 11290 | gl.glEnable(GL.GL_BLEND); |
---|
10871 | 11291 | gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); |
---|
10872 | | - |
---|
| 11292 | +// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE); |
---|
10873 | 11293 | gl.glMatrixMode(gl.GL_PROJECTION); |
---|
10874 | 11294 | gl.glLoadIdentity(); |
---|
10875 | 11295 | |
---|
.. | .. |
---|
11118 | 11538 | } |
---|
11119 | 11539 | } |
---|
11120 | 11540 | |
---|
11121 | | - if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion) |
---|
| 11541 | + if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion) |
---|
11122 | 11542 | { |
---|
11123 | 11543 | //gl.glDepthFunc(GL.GL_LEQUAL); |
---|
11124 | 11544 | //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT); |
---|
.. | .. |
---|
11126 | 11546 | |
---|
11127 | 11547 | boolean texon = textureon; |
---|
11128 | 11548 | |
---|
11129 | | - if (RENDERPROGRAM > 0) |
---|
11130 | | - { |
---|
11131 | | - gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
11132 | | - textureon = false; |
---|
11133 | | - } |
---|
| 11549 | + gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
| 11550 | + textureon = false; |
---|
| 11551 | + |
---|
11134 | 11552 | //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB); |
---|
11135 | 11553 | //System.out.println("ALLO"); |
---|
11136 | 11554 | gl.glColorMask(false, false, false, false); |
---|
11137 | 11555 | DrawObject(gl); |
---|
11138 | | - if (RENDERPROGRAM > 0) |
---|
11139 | | - { |
---|
11140 | | - gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
11141 | | - textureon = texon; |
---|
11142 | | - } |
---|
| 11556 | + |
---|
| 11557 | + gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
| 11558 | + textureon = texon; |
---|
| 11559 | + |
---|
11143 | 11560 | gl.glColorMask(true, true, true, true); |
---|
11144 | 11561 | |
---|
11145 | 11562 | gl.glDepthFunc(GL.GL_EQUAL); |
---|
11146 | | - //gl.glDepthMask(false); |
---|
| 11563 | + gl.glDepthMask(false); |
---|
11147 | 11564 | } |
---|
11148 | 11565 | |
---|
11149 | 11566 | if (false) // DrawMode() == SHADOW) |
---|
.. | .. |
---|
11326 | 11743 | |
---|
11327 | 11744 | static boolean zoomonce = false; |
---|
11328 | 11745 | |
---|
| 11746 | + static void CreateSelectedPoint() |
---|
| 11747 | + { |
---|
| 11748 | + if (selectedpoint == null) |
---|
| 11749 | + { |
---|
| 11750 | + debugpointG = new Sphere(); |
---|
| 11751 | + debugpointP = new Sphere(); |
---|
| 11752 | + debugpointC = new Sphere(); |
---|
| 11753 | + debugpointR = new Sphere(); |
---|
| 11754 | + |
---|
| 11755 | + selectedpoint = new Superellipsoid(); |
---|
| 11756 | + |
---|
| 11757 | + for (int i=0; i<8; i++) |
---|
| 11758 | + { |
---|
| 11759 | + debugpoints[i] = new Sphere(); |
---|
| 11760 | + } |
---|
| 11761 | + } |
---|
| 11762 | + } |
---|
| 11763 | + |
---|
11329 | 11764 | void DrawObject(GL gl, boolean draw) |
---|
11330 | 11765 | { |
---|
| 11766 | + // To clear camera values |
---|
| 11767 | + ResetOptions(); |
---|
| 11768 | + |
---|
11331 | 11769 | //System.out.println("DRAW OBJECT " + mouseDown); |
---|
11332 | 11770 | // DrawMode() = SELECTION; |
---|
11333 | 11771 | //GL gl = getGL(); |
---|
11334 | 11772 | if ((TRACK || SHADOWTRACK) || zoomonce) |
---|
11335 | 11773 | { |
---|
11336 | 11774 | if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode) |
---|
11337 | | - object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK); |
---|
| 11775 | + object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK); |
---|
11338 | 11776 | pingthread.StepToTarget(true); // true); |
---|
11339 | 11777 | // zoomonce = false; |
---|
11340 | 11778 | } |
---|
.. | .. |
---|
11406 | 11844 | |
---|
11407 | 11845 | if (DrawMode() == DEFAULT) |
---|
11408 | 11846 | { |
---|
11409 | | - if (DEBUG) |
---|
| 11847 | + if (Globals.DEBUG) |
---|
11410 | 11848 | { |
---|
| 11849 | + CreateSelectedPoint(); |
---|
11411 | 11850 | float radius = 0.05f; |
---|
11412 | 11851 | if (selectedpoint.radius != radius) |
---|
11413 | 11852 | { |
---|
.. | .. |
---|
11461 | 11900 | ReleaseTextures(DEFAULT_TEXTURES); |
---|
11462 | 11901 | |
---|
11463 | 11902 | if (CLEANCACHE) |
---|
11464 | | - for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();) |
---|
| 11903 | + for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();) |
---|
11465 | 11904 | { |
---|
11466 | | - String tex = e.nextElement(); |
---|
| 11905 | + cTexture tex = e.nextElement(); |
---|
11467 | 11906 | |
---|
11468 | 11907 | // System.out.println("Texture --------- " + tex); |
---|
11469 | 11908 | |
---|
11470 | | - if (tex.equals("WHITE_NOISE")) |
---|
| 11909 | + if (tex.equals("WHITE_NOISE:")) |
---|
11471 | 11910 | continue; |
---|
11472 | 11911 | |
---|
11473 | | - if (!usedtextures.containsKey(tex)) |
---|
| 11912 | + if (!usedtextures.contains(tex)) |
---|
11474 | 11913 | { |
---|
| 11914 | + CacheTexture gettex = texturepigment.get(tex); |
---|
11475 | 11915 | // System.out.println("DISPOSE +++++++++++++++ " + tex); |
---|
11476 | | - textures.get(tex).texture.dispose(); |
---|
11477 | | - textures.remove(tex); |
---|
| 11916 | + if (gettex != null) |
---|
| 11917 | + { |
---|
| 11918 | + gettex.texture.dispose(); |
---|
| 11919 | + texturepigment.remove(tex); |
---|
| 11920 | + } |
---|
| 11921 | + |
---|
| 11922 | + gettex = texturebump.get(tex); |
---|
| 11923 | + // System.out.println("DISPOSE +++++++++++++++ " + tex); |
---|
| 11924 | + if (gettex != null) |
---|
| 11925 | + { |
---|
| 11926 | + gettex.texture.dispose(); |
---|
| 11927 | + texturebump.remove(tex); |
---|
| 11928 | + } |
---|
11478 | 11929 | } |
---|
11479 | 11930 | } |
---|
11480 | 11931 | } |
---|
.. | .. |
---|
11894 | 12345 | for (int i = tp.size(); --i >= 0;) |
---|
11895 | 12346 | { |
---|
11896 | 12347 | //for (int count = tp.get(i).GetTransformCount(); --count>=0;) |
---|
11897 | | - LA.xformPos(light, tp.get(i).GlobalTransform(), light); |
---|
| 12348 | + LA.xformPos(light, tp.get(i).GlobalTransformInv(), light); |
---|
11898 | 12349 | } |
---|
11899 | 12350 | |
---|
11900 | 12351 | |
---|
.. | .. |
---|
12002 | 12453 | |
---|
12003 | 12454 | //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0); |
---|
12004 | 12455 | |
---|
| 12456 | + String program0 = |
---|
| 12457 | + // Min shader |
---|
| 12458 | + "!!ARBfp1.0\n" + |
---|
| 12459 | + "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" + |
---|
| 12460 | + "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" + |
---|
| 12461 | + "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" + |
---|
| 12462 | + "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" + |
---|
| 12463 | + "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" + |
---|
| 12464 | + "PARAM light2cam0 = program.env[10];" + |
---|
| 12465 | + "PARAM light2cam1 = program.env[11];" + |
---|
| 12466 | + "PARAM light2cam2 = program.env[12];" + |
---|
| 12467 | + "TEMP temp;" + |
---|
| 12468 | + "TEMP light;" + |
---|
| 12469 | + "TEMP ndotl;" + |
---|
| 12470 | + "TEMP normal;" + |
---|
| 12471 | + "TEMP depth;" + |
---|
| 12472 | + "TEMP eye;" + |
---|
| 12473 | + "TEMP pos;" + |
---|
| 12474 | + |
---|
| 12475 | + "MAD normal, fragment.color, zero123.z, -zero123.y;" + |
---|
| 12476 | + Normalize("normal") + |
---|
| 12477 | + "MOV light, state.light[0].position;" + |
---|
| 12478 | + "DP3 ndotl.x, light, normal;" + |
---|
| 12479 | + |
---|
| 12480 | + // shadow |
---|
| 12481 | + "MOV pos, fragment.texcoord[1];" + |
---|
| 12482 | + "MOV temp, pos;" + |
---|
| 12483 | + ShadowTextureFetch("depth", "temp", "1") + |
---|
| 12484 | + //"TEX depth, fragment.texcoord[1], texture[1], 2D;" + |
---|
| 12485 | + "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" + |
---|
| 12486 | + |
---|
| 12487 | + // No shadow when out of frustum |
---|
| 12488 | + //"SGE temp.y, depth.z, zero123.y;" + |
---|
| 12489 | + //"LRP temp.x, temp.y, zero123.y, temp.x;" + |
---|
| 12490 | + |
---|
| 12491 | + "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow |
---|
| 12492 | + |
---|
| 12493 | + // Backlit |
---|
| 12494 | + "MOV pos.w, zero123.y;" + |
---|
| 12495 | + "DP4 eye.x, pos, light2cam0;" + |
---|
| 12496 | + "DP4 eye.y, pos, light2cam1;" + |
---|
| 12497 | + "DP4 eye.z, pos, light2cam2;" + |
---|
| 12498 | + Normalize("eye") + |
---|
| 12499 | + |
---|
| 12500 | + "DP3 ndotl.y, -eye, normal;" + |
---|
| 12501 | + //"MUL ndotl.y, ndotl.y, pow2.x;" + |
---|
| 12502 | + "POW ndotl.y, ndotl.y, pow2.z;" + // backlit |
---|
| 12503 | + "SUB ndotl.y, zero123.y, ndotl.y;" + |
---|
| 12504 | + //"SUB ndotl.y, zero123.y, ndotl.y;" + |
---|
| 12505 | + //"MUL ndotl.y, ndotl.y, pow2.z;" + |
---|
| 12506 | + |
---|
| 12507 | + //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient |
---|
| 12508 | + //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient |
---|
| 12509 | + |
---|
| 12510 | + // Pigment |
---|
| 12511 | + "TEX temp, fragment.texcoord[0], texture[0], 2D;" + |
---|
| 12512 | + "LRP temp, zero123.w, temp, one;" + // texture proportion |
---|
| 12513 | + "MUL temp, temp, ndotl.x;" + |
---|
| 12514 | + |
---|
| 12515 | + "MUL temp, temp, zero123.z;" + |
---|
| 12516 | + |
---|
| 12517 | + //"MUL temp, temp, ndotl.y;" + |
---|
| 12518 | + |
---|
| 12519 | + "MOV temp.w, zero123.y;" + // reset alpha |
---|
| 12520 | + "MOV result.color, temp;" + |
---|
| 12521 | + "END"; |
---|
| 12522 | + |
---|
12005 | 12523 | String program = |
---|
12006 | 12524 | "!!ARBfp1.0\n" + |
---|
| 12525 | + |
---|
12007 | 12526 | //"OPTION ARB_fragment_program_shadow;" + |
---|
12008 | 12527 | "PARAM light2cam0 = program.env[10];" + |
---|
12009 | 12528 | "PARAM light2cam1 = program.env[11];" + |
---|
.. | .. |
---|
12118 | 12637 | "TEMP shininess;" + |
---|
12119 | 12638 | "\n" + |
---|
12120 | 12639 | "MOV texSamp, one;" + |
---|
12121 | | - //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" + |
---|
12122 | | - |
---|
| 12640 | + |
---|
12123 | 12641 | "MOV mapgrid.x, one2048th.x;" + |
---|
12124 | 12642 | "MOV temp, fragment.texcoord[1];" + |
---|
12125 | 12643 | /* |
---|
.. | .. |
---|
12140 | 12658 | "MUL temp, floor, mapgrid.x;" + |
---|
12141 | 12659 | //"TEX depth0, temp, texture[1], 2D;" + |
---|
12142 | 12660 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12143 | | - TextureFetch("depth0", "temp", "1") + |
---|
| 12661 | + ShadowTextureFetch("depth0", "temp", "1") + |
---|
12144 | 12662 | "") + |
---|
12145 | 12663 | "ADD temp.x, temp.x, mapgrid.x;" + |
---|
12146 | 12664 | //"TEX depth1, temp, texture[1], 2D;" + |
---|
12147 | 12665 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12148 | | - TextureFetch("depth1", "temp", "1") + |
---|
| 12666 | + ShadowTextureFetch("depth1", "temp", "1") + |
---|
12149 | 12667 | "") + |
---|
12150 | 12668 | "ADD temp.y, temp.y, mapgrid.x;" + |
---|
12151 | 12669 | //"TEX depth2, temp, texture[1], 2D;" + |
---|
12152 | | - TextureFetch("depth2", "temp", "1") + |
---|
| 12670 | + ShadowTextureFetch("depth2", "temp", "1") + |
---|
12153 | 12671 | "SUB temp.x, temp.x, mapgrid.x;" + |
---|
12154 | 12672 | //"TEX depth3, temp, texture[1], 2D;" + |
---|
12155 | 12673 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12156 | | - TextureFetch("depth3", "temp", "1") + |
---|
| 12674 | + ShadowTextureFetch("depth3", "temp", "1") + |
---|
12157 | 12675 | "") + |
---|
12158 | 12676 | //"MUL texSamp0, texSamp0, state.material.front.diffuse;" + |
---|
12159 | 12677 | //"MOV params, material;" + |
---|
.. | .. |
---|
12524 | 13042 | "MAD shadow.x, buffer.x, frac.y, shadow.x;" + |
---|
12525 | 13043 | "") + |
---|
12526 | 13044 | |
---|
12527 | | - // display shadow only (bump == 0) |
---|
| 13045 | + // display shadow only (fakedepth == 0) |
---|
12528 | 13046 | "SUB temp.x, half.x, shadow.x;" + |
---|
12529 | 13047 | "MOV temp.y, -params5.z;" + // params6.x;" + |
---|
12530 | | - "SLT temp.z, temp.y, -one2048th.x;" + |
---|
| 13048 | + "SLT temp.z, temp.y, -c256i.x;" + |
---|
12531 | 13049 | "SUB temp.y, one.x, temp.z;" + |
---|
12532 | 13050 | "MUL temp.x, temp.x, temp.y;" + |
---|
12533 | 13051 | "KIL temp.x;" + |
---|
.. | .. |
---|
12951 | 13469 | return out; |
---|
12952 | 13470 | } |
---|
12953 | 13471 | |
---|
12954 | | - String TextureFetch(String dest, String src, String unit) |
---|
| 13472 | + // Also does frustum culling |
---|
| 13473 | + String ShadowTextureFetch(String dest, String src, String unit) |
---|
12955 | 13474 | { |
---|
12956 | 13475 | return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" + |
---|
12957 | 13476 | "SGE " + src + ".w, " + src + ".x, eps.x;" + |
---|
12958 | 13477 | "SGE " + src + ".z, " + src + ".y, eps.x;" + |
---|
| 13478 | + "SLT " + dest + ".x, " + src + ".x, one.x;" + |
---|
| 13479 | + "SLT " + dest + ".y, " + src + ".y, one.x;" + |
---|
12959 | 13480 | "MUL " + src + ".w, " + src + ".z, " + src + ".w;" + |
---|
12960 | | - "SLT " + src + ".z, " + src + ".x, one.x;" + |
---|
12961 | | - "MUL " + src + ".w, " + src + ".z, " + src + ".w;" + |
---|
12962 | | - "SLT " + src + ".z, " + src + ".y, one.x;" + |
---|
12963 | | - "MUL " + src + ".w, " + src + ".z, " + src + ".w;" + |
---|
| 13481 | + "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" + |
---|
| 13482 | + "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" + |
---|
12964 | 13483 | //"SWZ buffer, temp, w,w,w,w;"; |
---|
12965 | | - "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" + |
---|
| 13484 | + //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" + |
---|
12966 | 13485 | "SUB " + src + ".z, " + "one.x, " + src + ".w;" + |
---|
12967 | 13486 | //"MUL " + src + ".z, " + src + ".z, infinity.x;" + |
---|
12968 | 13487 | //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;"; |
---|
12969 | | - "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
| 13488 | + //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
12970 | 13489 | |
---|
12971 | | - //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;"; |
---|
12972 | | - //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;"; |
---|
| 13490 | + //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;"; |
---|
| 13491 | + "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
12973 | 13492 | } |
---|
12974 | 13493 | |
---|
12975 | 13494 | String Shadow(String depth, String shadow) |
---|
.. | .. |
---|
13016 | 13535 | "SLT temp.x, temp.x, zero.x;" + // shadoweps |
---|
13017 | 13536 | "LRP " + shadow + ", temp.x, one, " + shadow + ";" + |
---|
13018 | 13537 | |
---|
13019 | | - // No shadow when out of frustrum |
---|
| 13538 | + // No shadow when out of frustum |
---|
13020 | 13539 | "SGE temp.x, " + depth + ".z, one.z;" + |
---|
13021 | 13540 | "LRP " + shadow + ", temp.x, one, " + shadow + ";" + |
---|
13022 | 13541 | ""; |
---|
.. | .. |
---|
13164 | 13683 | /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias |
---|
13165 | 13684 | /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough |
---|
13166 | 13685 | /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power |
---|
13167 | | - Object3D.cVector2[] vector2buffer; |
---|
| 13686 | + |
---|
| 13687 | + //Object3D.cVector2[] vector2buffer; |
---|
13168 | 13688 | |
---|
13169 | 13689 | // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea |
---|
13170 | 13690 | // OUT : diff, spec |
---|
.. | .. |
---|
13180 | 13700 | "DP3 " + dest + ".z," + "normals," + "eye;" + |
---|
13181 | 13701 | "MAX " + dest + ".w," + dest + ".z," + "eps.x;" + |
---|
13182 | 13702 | //"MOV " + dest + ".w," + "normal.z;" + |
---|
13183 | | - "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + |
---|
13184 | | - "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" + |
---|
13185 | | - //"MOV " + dest + ".z," + "params2.w;" + |
---|
| 13703 | +// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET |
---|
| 13704 | +// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" + |
---|
| 13705 | + |
---|
| 13706 | + "MOV " + dest + ".z," + "params2.w;" + // EXACT |
---|
13186 | 13707 | "POW " + dest + ".w," + dest + ".w," + dest + ".z;" + |
---|
13187 | 13708 | "RCP " + dest + ".w," + dest + ".w;" + |
---|
13188 | 13709 | //"RSQ " + dest + ".w," + dest + ".w;" + |
---|
.. | .. |
---|
13687 | 14208 | else |
---|
13688 | 14209 | if (evt.getSource() == AAtimer) |
---|
13689 | 14210 | { |
---|
| 14211 | + Globals.TIMERRUNNING = false; |
---|
13690 | 14212 | if (mouseDown) |
---|
13691 | 14213 | { |
---|
13692 | 14214 | //new Exception().printStackTrace(); |
---|
.. | .. |
---|
13746 | 14268 | |
---|
13747 | 14269 | // fev 2014??? |
---|
13748 | 14270 | if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode) |
---|
13749 | | - object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK); |
---|
| 14271 | + object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK); |
---|
13750 | 14272 | pingthread.StepToTarget(true); // true); |
---|
13751 | 14273 | } |
---|
13752 | 14274 | // if (!LIVE) |
---|
.. | .. |
---|
13761 | 14283 | return; |
---|
13762 | 14284 | |
---|
13763 | 14285 | AAtimer.restart(); // |
---|
| 14286 | + Globals.TIMERRUNNING = true; |
---|
13764 | 14287 | |
---|
13765 | 14288 | // waslive = LIVE; |
---|
13766 | 14289 | // LIVE = false; |
---|
.. | .. |
---|
13810 | 14333 | drag = false; |
---|
13811 | 14334 | //System.out.println("Mouse DOWN"); |
---|
13812 | 14335 | editObj = false; |
---|
13813 | | - ClickInfo info = new ClickInfo(); |
---|
13814 | | - info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
13815 | | - info.pane = this; |
---|
13816 | | - info.camera = renderCamera; |
---|
13817 | | - info.x = x; |
---|
13818 | | - info.y = y; |
---|
13819 | | - info.modifiers = modifiersex; |
---|
13820 | | - editObj = object.doEditClick(info, 0); |
---|
| 14336 | + //ClickInfo info = new ClickInfo(); |
---|
| 14337 | + object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
| 14338 | + object.clickInfo.pane = this; |
---|
| 14339 | + object.clickInfo.camera = renderCamera; |
---|
| 14340 | + object.clickInfo.x = x; |
---|
| 14341 | + object.clickInfo.y = y; |
---|
| 14342 | + object.clickInfo.modifiers = modifiersex; |
---|
| 14343 | + editObj = object.doEditClick(//info, |
---|
| 14344 | + 0); |
---|
13821 | 14345 | if (!editObj) |
---|
13822 | 14346 | { |
---|
13823 | 14347 | hasMarquee = true; |
---|
.. | .. |
---|
14099 | 14623 | void GoDown(int mod) |
---|
14100 | 14624 | { |
---|
14101 | 14625 | MODIFIERS |= COMMAND; |
---|
14102 | | - /* |
---|
| 14626 | + /**/ |
---|
14103 | 14627 | if((mod&SHIFT) == SHIFT) |
---|
14104 | 14628 | manipCamera.RotatePosition(0, -speed); |
---|
14105 | 14629 | else |
---|
14106 | | - manipCamera.BackForth(0, -speed*delta, getWidth()); |
---|
14107 | | - */ |
---|
| 14630 | + manipCamera.BackForth(0, -speed*delta, 0); // getWidth()); |
---|
| 14631 | + /**/ |
---|
14108 | 14632 | if ((mod & SHIFT) == SHIFT) |
---|
14109 | 14633 | { |
---|
14110 | 14634 | mouseMode = mouseMode; // VR?? |
---|
.. | .. |
---|
14120 | 14644 | void GoUp(int mod) |
---|
14121 | 14645 | { |
---|
14122 | 14646 | MODIFIERS |= COMMAND; |
---|
14123 | | - /* |
---|
| 14647 | + /**/ |
---|
14124 | 14648 | if((mod&SHIFT) == SHIFT) |
---|
14125 | 14649 | manipCamera.RotatePosition(0, speed); |
---|
14126 | 14650 | else |
---|
14127 | | - manipCamera.BackForth(0, speed*delta, getWidth()); |
---|
14128 | | - */ |
---|
| 14651 | + manipCamera.BackForth(0, speed*delta, 0); // getWidth()); |
---|
| 14652 | + /**/ |
---|
14129 | 14653 | if ((mod & SHIFT) == SHIFT) |
---|
14130 | 14654 | { |
---|
14131 | 14655 | mouseMode = mouseMode; |
---|
.. | .. |
---|
14141 | 14665 | void GoLeft(int mod) |
---|
14142 | 14666 | { |
---|
14143 | 14667 | MODIFIERS |= COMMAND; |
---|
14144 | | - /* |
---|
| 14668 | + /**/ |
---|
14145 | 14669 | if((mod&SHIFT) == SHIFT) |
---|
14146 | | - manipCamera.RotatePosition(speed, 0); |
---|
14147 | | - else |
---|
14148 | 14670 | manipCamera.Translate(speed*delta, 0, getWidth()); |
---|
14149 | | - */ |
---|
| 14671 | + else |
---|
| 14672 | + manipCamera.RotatePosition(speed, 0); |
---|
| 14673 | + /**/ |
---|
14150 | 14674 | if ((mod & SHIFT) == SHIFT) |
---|
14151 | 14675 | { |
---|
14152 | 14676 | mouseMode = mouseMode; |
---|
.. | .. |
---|
14162 | 14686 | void GoRight(int mod) |
---|
14163 | 14687 | { |
---|
14164 | 14688 | MODIFIERS |= COMMAND; |
---|
14165 | | - /* |
---|
| 14689 | + /**/ |
---|
14166 | 14690 | if((mod&SHIFT) == SHIFT) |
---|
14167 | | - manipCamera.RotatePosition(-speed, 0); |
---|
14168 | | - else |
---|
14169 | 14691 | manipCamera.Translate(-speed*delta, 0, getWidth()); |
---|
14170 | | - */ |
---|
| 14692 | + else |
---|
| 14693 | + manipCamera.RotatePosition(-speed, 0); |
---|
| 14694 | + /**/ |
---|
14171 | 14695 | if ((mod & SHIFT) == SHIFT) |
---|
14172 | 14696 | { |
---|
14173 | 14697 | mouseMode = mouseMode; |
---|
.. | .. |
---|
14217 | 14741 | if (editObj) |
---|
14218 | 14742 | { |
---|
14219 | 14743 | drag = true; |
---|
14220 | | - ClickInfo info = new ClickInfo(); |
---|
14221 | | - info.bounds.setBounds(0, 0, |
---|
| 14744 | + //ClickInfo info = new ClickInfo(); |
---|
| 14745 | + object.clickInfo.bounds.setBounds(0, 0, |
---|
14222 | 14746 | (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
14223 | | - info.pane = this; |
---|
14224 | | - info.camera = renderCamera; |
---|
14225 | | - info.x = x; |
---|
14226 | | - info.y = y; |
---|
14227 | | - object.editWindow.copy.doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0); |
---|
| 14747 | + object.clickInfo.pane = this; |
---|
| 14748 | + object.clickInfo.camera = renderCamera; |
---|
| 14749 | + object.clickInfo.x = x; |
---|
| 14750 | + object.clickInfo.y = y; |
---|
| 14751 | + object //.GetWindow().copy |
---|
| 14752 | + .doEditDrag(//info, |
---|
| 14753 | + (modifiers & MouseEvent.BUTTON3_MASK) != 0); |
---|
14228 | 14754 | } else |
---|
14229 | 14755 | { |
---|
14230 | 14756 | if (x < startX) |
---|
.. | .. |
---|
14373 | 14899 | } |
---|
14374 | 14900 | } |
---|
14375 | 14901 | |
---|
| 14902 | +// ClickInfo clickInfo = new ClickInfo(); |
---|
| 14903 | + |
---|
14376 | 14904 | public void mouseMoved(MouseEvent e) |
---|
14377 | 14905 | { |
---|
14378 | 14906 | //System.out.println("mouseMoved: " + e); |
---|
14379 | 14907 | if (isRenderer) |
---|
14380 | 14908 | return; |
---|
14381 | 14909 | |
---|
14382 | | - ClickInfo ci = new ClickInfo(); |
---|
14383 | | - ci.x = e.getX(); |
---|
14384 | | - ci.y = e.getY(); |
---|
14385 | | - ci.modifiers = e.getModifiersEx(); |
---|
14386 | | - ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
14387 | | - ci.pane = this; |
---|
14388 | | - ci.camera = renderCamera; |
---|
| 14910 | + // Mouse cursor feedback |
---|
| 14911 | + object.clickInfo.x = e.getX(); |
---|
| 14912 | + object.clickInfo.y = e.getY(); |
---|
| 14913 | + object.clickInfo.modifiers = e.getModifiersEx(); |
---|
| 14914 | + object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
| 14915 | + object.clickInfo.pane = this; |
---|
| 14916 | + object.clickInfo.camera = renderCamera; |
---|
14389 | 14917 | if (!isRenderer) |
---|
14390 | 14918 | { |
---|
14391 | | - if (object.editWindow.copy.doEditClick(ci, 0)) |
---|
| 14919 | + //ObjEditor editWindow = object.editWindow; |
---|
| 14920 | + //Object3D copy = editWindow.copy; |
---|
| 14921 | + if (object.doEditClick(//clickInfo, |
---|
| 14922 | + 0)) |
---|
14392 | 14923 | { |
---|
14393 | 14924 | setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
---|
14394 | 14925 | } else |
---|
.. | .. |
---|
14403 | 14934 | Globals.MOUSEDRAGGED = false; |
---|
14404 | 14935 | |
---|
14405 | 14936 | movingcamera = false; |
---|
14406 | | - X = Y = 0; |
---|
| 14937 | + X = 0; // getBounds().width/2; |
---|
| 14938 | + Y = 0; // getBounds().height/2; |
---|
14407 | 14939 | //System.out.println("mouseReleased: " + e); |
---|
14408 | 14940 | clickEnd(e.getX(), e.getY(), e.getModifiersEx()); |
---|
14409 | 14941 | } |
---|
.. | .. |
---|
14659 | 15191 | // break; |
---|
14660 | 15192 | case 'T': |
---|
14661 | 15193 | CACHETEXTURE ^= true; |
---|
14662 | | - textures.clear(); |
---|
| 15194 | + texturepigment.clear(); |
---|
| 15195 | + texturebump.clear(); |
---|
14663 | 15196 | // repaint(); |
---|
14664 | 15197 | break; |
---|
14665 | 15198 | case 'Y': |
---|
.. | .. |
---|
14744 | 15277 | case 'E' : COMPACT ^= true; |
---|
14745 | 15278 | repaint(); |
---|
14746 | 15279 | break; |
---|
14747 | | - case 'W' : DEBUGHSB ^= true; |
---|
| 15280 | + case 'W' : // Wide Window (fullscreen) |
---|
| 15281 | + //DEBUGHSB ^= true; |
---|
| 15282 | + ObjEditor.theFrame.ToggleFullScreen(); |
---|
14748 | 15283 | repaint(); |
---|
14749 | 15284 | break; |
---|
14750 | 15285 | case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break; |
---|
.. | .. |
---|
14769 | 15304 | RevertCamera(); |
---|
14770 | 15305 | repaint(); |
---|
14771 | 15306 | break; |
---|
14772 | | - case 'L': |
---|
14773 | 15307 | case 'l': |
---|
| 15308 | + //case 'L': |
---|
14774 | 15309 | if (lightMode) |
---|
14775 | 15310 | { |
---|
14776 | 15311 | lightMode = false; |
---|
.. | .. |
---|
14834 | 15369 | OCCLUSION_CULLING ^= true; |
---|
14835 | 15370 | System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING); |
---|
14836 | 15371 | break; |
---|
14837 | | - case '0': envyoff ^= true; repaint(); break; |
---|
| 15372 | + //case '0': envyoff ^= true; repaint(); break; |
---|
14838 | 15373 | case '1': |
---|
14839 | 15374 | case '2': |
---|
14840 | 15375 | case '3': |
---|
14841 | 15376 | case '4': |
---|
14842 | 15377 | case '5': |
---|
14843 | | - newenvy = Character.getNumericValue(key); |
---|
14844 | | - repaint(); |
---|
14845 | | - break; |
---|
14846 | 15378 | case '6': |
---|
14847 | 15379 | case '7': |
---|
14848 | 15380 | case '8': |
---|
14849 | 15381 | case '9': |
---|
14850 | | - BGcolor = (key - '6')/3.f; |
---|
| 15382 | + if (true) // envyoff) |
---|
| 15383 | + { |
---|
| 15384 | + BGcolor = (key - '1')/8.f; |
---|
| 15385 | + } |
---|
| 15386 | + else |
---|
| 15387 | + { |
---|
| 15388 | + //newenvy = Character.getNumericValue(key); |
---|
| 15389 | + } |
---|
14851 | 15390 | repaint(); |
---|
14852 | 15391 | break; |
---|
14853 | 15392 | case '!': |
---|
.. | .. |
---|
14913 | 15452 | case '_': |
---|
14914 | 15453 | kompactbit = 5; |
---|
14915 | 15454 | break; |
---|
14916 | | - case '+': |
---|
14917 | | - kompactbit = 6; |
---|
14918 | | - break; |
---|
| 15455 | +// case '+': |
---|
| 15456 | +// kompactbit = 6; |
---|
| 15457 | +// break; |
---|
14919 | 15458 | case ' ': |
---|
14920 | 15459 | lightMode ^= true; |
---|
14921 | 15460 | Globals.lighttouched = true; |
---|
.. | .. |
---|
14927 | 15466 | case ESC: |
---|
14928 | 15467 | RENDERPROGRAM += 1; |
---|
14929 | 15468 | RENDERPROGRAM %= 3; |
---|
| 15469 | + |
---|
14930 | 15470 | repaint(); |
---|
14931 | 15471 | break; |
---|
14932 | 15472 | case 'Z': |
---|
.. | .. |
---|
14966 | 15506 | case DELETE: |
---|
14967 | 15507 | ClearSelection(); |
---|
14968 | 15508 | break; |
---|
14969 | | - /* |
---|
14970 | 15509 | case '+': |
---|
| 15510 | + |
---|
| 15511 | + /* |
---|
14971 | 15512 | //fontsize += 1; |
---|
14972 | 15513 | bbzoom *= 2; |
---|
14973 | 15514 | repaint(); |
---|
.. | .. |
---|
14984 | 15525 | case '=': |
---|
14985 | 15526 | IncDepth(); |
---|
14986 | 15527 | //fontsize += 1; |
---|
14987 | | - object.editWindow.refreshContents(true); |
---|
| 15528 | + object.GetWindow().refreshContents(true); |
---|
14988 | 15529 | maskbit = 6; |
---|
14989 | 15530 | break; |
---|
14990 | 15531 | case '-': //if (PixelThreshold>1) PixelThreshold /= 2; |
---|
14991 | 15532 | DecDepth(); |
---|
14992 | 15533 | maskbit = 5; |
---|
14993 | 15534 | //if(fontsize > 1) fontsize -= 1; |
---|
14994 | | - if (object.editWindow == null) |
---|
14995 | | - new Exception().printStackTrace(); |
---|
14996 | | - else |
---|
14997 | | - object.editWindow.refreshContents(true); |
---|
| 15535 | +// if (object.editWindow == null) |
---|
| 15536 | +// new Exception().printStackTrace(); |
---|
| 15537 | +// else |
---|
| 15538 | + object.GetWindow().refreshContents(true); |
---|
14998 | 15539 | break; |
---|
14999 | 15540 | case '{': |
---|
15000 | 15541 | manipCamera.shaper_fovy /= 1.1; |
---|
.. | .. |
---|
15218 | 15759 | } |
---|
15219 | 15760 | */ |
---|
15220 | 15761 | |
---|
15221 | | - object.editWindow.EditSelection(); |
---|
| 15762 | + object.GetWindow().EditSelection(false); |
---|
15222 | 15763 | } |
---|
15223 | 15764 | |
---|
15224 | 15765 | void SelectParent() |
---|
.. | .. |
---|
15235 | 15776 | { |
---|
15236 | 15777 | //selectees.remove(i); |
---|
15237 | 15778 | System.out.println("select parent of " + elem); |
---|
15238 | | - group.editWindow.Select(elem.parent.GetTreePath(), first, true); |
---|
| 15779 | + group.GetWindow().Select(elem.parent.GetTreePath(), first, true); |
---|
15239 | 15780 | } else |
---|
15240 | 15781 | { |
---|
15241 | | - group.editWindow.Select(elem.GetTreePath(), first, true); |
---|
| 15782 | + group.GetWindow().Select(elem.GetTreePath(), first, true); |
---|
15242 | 15783 | } |
---|
15243 | 15784 | |
---|
15244 | 15785 | first = false; |
---|
.. | .. |
---|
15280 | 15821 | for (int j = 0; j < group.children.size(); j++) |
---|
15281 | 15822 | { |
---|
15282 | 15823 | elem = (Object3D) group.children.elementAt(j); |
---|
15283 | | - object.editWindow.Select(elem.GetTreePath(), first, true); |
---|
| 15824 | + object.GetWindow().Select(elem.GetTreePath(), first, true); |
---|
15284 | 15825 | first = false; |
---|
15285 | 15826 | } |
---|
15286 | 15827 | } else |
---|
15287 | 15828 | { |
---|
15288 | | - object.editWindow.Select(elem.GetTreePath(), first, true); |
---|
| 15829 | + object.GetWindow().Select(elem.GetTreePath(), first, true); |
---|
15289 | 15830 | } |
---|
15290 | 15831 | |
---|
15291 | 15832 | first = false; |
---|
.. | .. |
---|
15296 | 15837 | { |
---|
15297 | 15838 | //Composite group = (Composite) object; |
---|
15298 | 15839 | Object3D group = object; |
---|
15299 | | - group.editWindow.loadClipboard(true); // ClearSelection(false); |
---|
| 15840 | + group.GetWindow().loadClipboard(true); // ClearSelection(false); |
---|
15300 | 15841 | } |
---|
15301 | 15842 | |
---|
15302 | 15843 | void ResetTransform(int mask) |
---|
15303 | 15844 | { |
---|
15304 | 15845 | //Composite group = (Composite) object; |
---|
15305 | 15846 | Object3D group = object; |
---|
15306 | | - group.editWindow.ResetTransform(mask); |
---|
| 15847 | + group.GetWindow().ResetTransform(mask); |
---|
15307 | 15848 | } |
---|
15308 | 15849 | |
---|
15309 | 15850 | void FlipTransform() |
---|
15310 | 15851 | { |
---|
15311 | 15852 | //Composite group = (Composite) object; |
---|
15312 | 15853 | Object3D group = object; |
---|
15313 | | - group.editWindow.FlipTransform(); |
---|
| 15854 | + group.GetWindow().FlipTransform(); |
---|
15314 | 15855 | // group.editWindow.ReduceMesh(true); |
---|
15315 | 15856 | } |
---|
15316 | 15857 | |
---|
.. | .. |
---|
15318 | 15859 | { |
---|
15319 | 15860 | //Composite group = (Composite) object; |
---|
15320 | 15861 | Object3D group = object; |
---|
15321 | | - group.editWindow.PrintMemory(); |
---|
| 15862 | + group.GetWindow().PrintMemory(); |
---|
15322 | 15863 | // group.editWindow.ReduceMesh(true); |
---|
15323 | 15864 | } |
---|
15324 | 15865 | |
---|
.. | .. |
---|
15326 | 15867 | { |
---|
15327 | 15868 | //Composite group = (Composite) object; |
---|
15328 | 15869 | Object3D group = object; |
---|
15329 | | - group.editWindow.ResetCentroid(); |
---|
| 15870 | + group.GetWindow().ResetCentroid(); |
---|
15330 | 15871 | } |
---|
15331 | 15872 | |
---|
15332 | 15873 | void IncDepth() |
---|
.. | .. |
---|
15408 | 15949 | |
---|
15409 | 15950 | int width = getBounds().width; |
---|
15410 | 15951 | int height = getBounds().height; |
---|
15411 | | - ClickInfo info = new ClickInfo(); |
---|
15412 | | - info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom)); |
---|
15413 | 15952 | //Image img = CreateImage(width, height); |
---|
15414 | 15953 | //System.out.println("width = " + width + "; height = " + height + "\n"); |
---|
15415 | 15954 | |
---|
.. | .. |
---|
15486 | 16025 | } |
---|
15487 | 16026 | if (object != null && !hasMarquee) |
---|
15488 | 16027 | { |
---|
| 16028 | + if (object.clickInfo == null) |
---|
| 16029 | + object.clickInfo = new ClickInfo(); |
---|
| 16030 | + ClickInfo info = object.clickInfo; |
---|
| 16031 | + //ClickInfo info = new ClickInfo(); |
---|
| 16032 | + info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom)); |
---|
| 16033 | + |
---|
15489 | 16034 | if (isRenderer) |
---|
15490 | 16035 | { |
---|
15491 | | - info.flags++; |
---|
| 16036 | + object.clickInfo.flags++; |
---|
15492 | 16037 | double frameAspect = (double) width / (double) height; |
---|
15493 | 16038 | if (frameAspect > renderCamera.aspect) |
---|
15494 | 16039 | { |
---|
15495 | 16040 | int desired = (int) ((double) height * renderCamera.aspect); |
---|
15496 | | - info.bounds.width -= width - desired; |
---|
15497 | | - info.bounds.x += (width - desired) / 2; |
---|
| 16041 | + object.clickInfo.bounds.width -= width - desired; |
---|
| 16042 | + object.clickInfo.bounds.x += (width - desired) / 2; |
---|
15498 | 16043 | } else |
---|
15499 | 16044 | { |
---|
15500 | 16045 | int desired = (int) ((double) width / renderCamera.aspect); |
---|
15501 | | - info.bounds.height -= height - desired; |
---|
15502 | | - info.bounds.y += (height - desired) / 2; |
---|
| 16046 | + object.clickInfo.bounds.height -= height - desired; |
---|
| 16047 | + object.clickInfo.bounds.y += (height - desired) / 2; |
---|
15503 | 16048 | } |
---|
15504 | 16049 | } |
---|
15505 | | - info.g = gr; |
---|
15506 | | - info.camera = renderCamera; |
---|
| 16050 | + |
---|
| 16051 | + object.clickInfo.g = gr; |
---|
| 16052 | + object.clickInfo.camera = renderCamera; |
---|
15507 | 16053 | /* |
---|
15508 | 16054 | // Memory intensive (brep.verticescopy) |
---|
15509 | 16055 | if (!(object instanceof Composite)) |
---|
15510 | 16056 | object.draw(info, 0, false); // SLOW : |
---|
15511 | 16057 | */ |
---|
15512 | | - if (!isRenderer) |
---|
| 16058 | + if (!isRenderer) // && drag) |
---|
15513 | 16059 | { |
---|
15514 | | - object.drawEditHandles(info, 0); |
---|
15515 | | - |
---|
15516 | | - if (drag && (X != 0 || Y != 0) && object.selection.Size() > 0) |
---|
| 16060 | + Grafreed.Assert(object != null); |
---|
| 16061 | + Grafreed.Assert(object.selection != null); |
---|
| 16062 | + if (object.selection.Size() > 0) |
---|
15517 | 16063 | { |
---|
15518 | | - switch (object.selection.get(0).hitSomething) |
---|
| 16064 | + int hitSomething = object.selection.get(0).hitSomething; |
---|
| 16065 | + |
---|
| 16066 | + object.clickInfo.DX = 0; |
---|
| 16067 | + object.clickInfo.DY = 0; |
---|
| 16068 | + object.clickInfo.W = 1; |
---|
| 16069 | + if (hitSomething == Object3D.hitCenter) |
---|
15519 | 16070 | { |
---|
15520 | | - case Object3D.hitCenter: gr.setColor(Color.pink); |
---|
15521 | | - gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
15522 | | - break; |
---|
15523 | | - case Object3D.hitRotate: gr.setColor(Color.yellow); |
---|
15524 | | - gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
15525 | | - break; |
---|
15526 | | - case Object3D.hitScale: gr.setColor(Color.cyan); |
---|
15527 | | - gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
15528 | | - break; |
---|
| 16071 | + info.DX = X; |
---|
| 16072 | + if (X != 0) |
---|
| 16073 | + info.DX -= info.bounds.width/2; |
---|
| 16074 | + |
---|
| 16075 | + info.DY = Y; |
---|
| 16076 | + if (Y != 0) |
---|
| 16077 | + info.DY -= info.bounds.height/2; |
---|
15529 | 16078 | } |
---|
15530 | | - |
---|
| 16079 | + |
---|
| 16080 | + object.drawEditHandles(//info, |
---|
| 16081 | + 0); |
---|
| 16082 | + |
---|
| 16083 | + if (drag && (X != 0 || Y != 0)) |
---|
| 16084 | + { |
---|
| 16085 | + switch (hitSomething) |
---|
| 16086 | + { |
---|
| 16087 | + case Object3D.hitCenter: gr.setColor(Color.pink); |
---|
| 16088 | + gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
| 16089 | + break; |
---|
| 16090 | + case Object3D.hitRotate: gr.setColor(Color.yellow); |
---|
| 16091 | + gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
| 16092 | + break; |
---|
| 16093 | + case Object3D.hitScale: gr.setColor(Color.cyan); |
---|
| 16094 | + gr.drawLine(X, Y, 0, 0); |
---|
| 16095 | + break; |
---|
| 16096 | + } |
---|
| 16097 | + |
---|
| 16098 | + } |
---|
15531 | 16099 | } |
---|
15532 | 16100 | } |
---|
15533 | 16101 | } |
---|
.. | .. |
---|
16009 | 16577 | private /*static*/ boolean firstime; |
---|
16010 | 16578 | private /*static*/ cVector newView = new cVector(); |
---|
16011 | 16579 | private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"}; |
---|
| 16580 | + private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"}; |
---|
| 16581 | + private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"}; |
---|
16012 | 16582 | private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X, |
---|
16013 | 16583 | GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X, |
---|
16014 | 16584 | GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y, |
---|
.. | .. |
---|
16021 | 16591 | { |
---|
16022 | 16592 | com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP); |
---|
16023 | 16593 | |
---|
| 16594 | + int usedsuf = 0; |
---|
| 16595 | + |
---|
16024 | 16596 | for (int i = 0; i < suffixes.length; i++) |
---|
16025 | 16597 | { |
---|
16026 | | - String resourceName = basename + suffixes[i] + "." + suffix; |
---|
16027 | | - TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
16028 | | - mipmapped, |
---|
16029 | | - FileUtil.getFileSuffix(resourceName)); |
---|
16030 | | - if (data == null) |
---|
| 16598 | + String[] suffixe = suffixes; |
---|
| 16599 | + String[] fallback = suffixes2; |
---|
| 16600 | + String[] fallfallback = suffixes3; |
---|
| 16601 | + |
---|
| 16602 | + for (int c=usedsuf; --c>=0;) |
---|
16031 | 16603 | { |
---|
16032 | | - throw new IOException("Unable to load texture " + resourceName); |
---|
| 16604 | +// String[] temp = suffixe; |
---|
| 16605 | +// suffixe = fallback; |
---|
| 16606 | +// fallback = fallfallback; |
---|
| 16607 | +// fallfallback = temp; |
---|
16033 | 16608 | } |
---|
| 16609 | + |
---|
| 16610 | + String resourceName = basename + suffixe[i] + "." + suffix; |
---|
| 16611 | + TextureData data; |
---|
| 16612 | + |
---|
| 16613 | + try |
---|
| 16614 | + { |
---|
| 16615 | + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
| 16616 | + mipmapped, |
---|
| 16617 | + FileUtil.getFileSuffix(resourceName)); |
---|
| 16618 | + } |
---|
| 16619 | + catch (Exception e) |
---|
| 16620 | + { |
---|
| 16621 | + try |
---|
| 16622 | + { |
---|
| 16623 | + resourceName = basename + fallback[i] + "." + suffix; |
---|
| 16624 | + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
| 16625 | + mipmapped, |
---|
| 16626 | + FileUtil.getFileSuffix(resourceName)); |
---|
| 16627 | + } |
---|
| 16628 | + catch (Exception e2) |
---|
| 16629 | + { |
---|
| 16630 | + resourceName = basename + fallfallback[i] + "." + suffix; |
---|
| 16631 | + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
| 16632 | + mipmapped, |
---|
| 16633 | + FileUtil.getFileSuffix(resourceName)); |
---|
| 16634 | + } |
---|
| 16635 | + } |
---|
| 16636 | + |
---|
16034 | 16637 | //System.out.println("Target = " + targets[i]); |
---|
16035 | 16638 | cubemap.updateImage(data, targets[i]); |
---|
16036 | 16639 | } |
---|
16037 | 16640 | |
---|
16038 | 16641 | return cubemap; |
---|
16039 | 16642 | } |
---|
| 16643 | + |
---|
16040 | 16644 | int bigsphere = -1; |
---|
16041 | 16645 | |
---|
16042 | 16646 | float BGcolor = 0.5f; |
---|
16043 | 16647 | |
---|
16044 | | - private void DrawSkyBox(GL gl) |
---|
| 16648 | + float ambientLight[] = {1f, 1f, 1f, 1.0f}; |
---|
| 16649 | + |
---|
| 16650 | + private void DrawSkyBox(GL gl, float ratio) |
---|
16045 | 16651 | { |
---|
16046 | | - if (envyoff || cubemap == null) |
---|
| 16652 | + if (//envyoff || |
---|
| 16653 | + cubemap == null) |
---|
16047 | 16654 | { |
---|
16048 | 16655 | gl.glClearColor(BGcolor, BGcolor, BGcolor, 1); |
---|
16049 | 16656 | gl.glClear(gl.GL_COLOR_BUFFER_BIT); |
---|
.. | .. |
---|
16058 | 16665 | // Compensates for ExaminerViewer's modification of modelview matrix |
---|
16059 | 16666 | gl.glMatrixMode(GL.GL_MODELVIEW); |
---|
16060 | 16667 | gl.glLoadIdentity(); |
---|
| 16668 | + gl.glScalef(1,ratio,1); |
---|
16061 | 16669 | |
---|
| 16670 | + colorV[0] = 2; |
---|
| 16671 | + colorV[1] = 2; |
---|
| 16672 | + colorV[2] = 2; |
---|
| 16673 | + colorV[3] = 1; |
---|
| 16674 | + gl.glDisable(gl.GL_COLOR_MATERIAL); |
---|
| 16675 | + gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0); |
---|
| 16676 | + |
---|
| 16677 | + gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0); |
---|
| 16678 | + |
---|
16062 | 16679 | //gl.glActiveTexture(GL.GL_TEXTURE1); |
---|
16063 | 16680 | //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP); |
---|
16064 | 16681 | |
---|
.. | .. |
---|
16071 | 16688 | // GL_NORMAL_MAP texgen mode. Temporarily enabling lighting |
---|
16072 | 16689 | // causes the normals to be sent down. Thanks to Ken Dyke. |
---|
16073 | 16690 | //gl.glEnable(GL.GL_LIGHTING); |
---|
16074 | | - gl.glDisable(GL.GL_LIGHTING); |
---|
| 16691 | + gl.glEnable(GL.GL_LIGHTING); |
---|
16075 | 16692 | |
---|
16076 | 16693 | gl.glTexGeni(GL.GL_S, GL.GL_TEXTURE_GEN_MODE, GL.GL_NORMAL_MAP); |
---|
16077 | 16694 | gl.glTexGeni(GL.GL_T, GL.GL_TEXTURE_GEN_MODE, GL.GL_NORMAL_MAP); |
---|
.. | .. |
---|
16090 | 16707 | { |
---|
16091 | 16708 | gl.glScalef(1.0f, -1.0f, 1.0f); |
---|
16092 | 16709 | } |
---|
| 16710 | + gl.glScalef(-1.0f, 1.0f, 1.0f); |
---|
16093 | 16711 | gl.glMultMatrixd(viewrot_1, 0); |
---|
16094 | 16712 | gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f); |
---|
16095 | 16713 | //viewer.updateInverseRotation(gl); |
---|
.. | .. |
---|
16230 | 16848 | cStatic.objectstack[materialdepth++] = checker; |
---|
16231 | 16849 | //System.out.println("material " + material); |
---|
16232 | 16850 | //Applet3D.tracein(this, selected); |
---|
16233 | | - vector2buffer = checker.projectedVertices; |
---|
| 16851 | + //vector2buffer = checker.projectedVertices; |
---|
16234 | 16852 | |
---|
16235 | 16853 | //checker.GetMaterial().Draw(this, false); // true); |
---|
16236 | | - DrawMaterial(checker.GetMaterial(), false); // true); |
---|
| 16854 | + DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true); |
---|
16237 | 16855 | |
---|
16238 | 16856 | materialdepth -= 1; |
---|
16239 | 16857 | if (materialdepth > 0) |
---|
16240 | 16858 | { |
---|
16241 | | - vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices; |
---|
16242 | | - DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]); |
---|
| 16859 | + //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices; |
---|
| 16860 | + DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices); |
---|
16243 | 16861 | } |
---|
16244 | 16862 | //checker.GetMaterial().opacity = 1f; |
---|
16245 | 16863 | ////checker.GetMaterial().ambient = 1f; |
---|
.. | .. |
---|
16325 | 16943 | } |
---|
16326 | 16944 | } |
---|
16327 | 16945 | |
---|
| 16946 | + private Object3D GetFolder() |
---|
| 16947 | + { |
---|
| 16948 | + Object3D folder = object.GetWindow().copy; |
---|
| 16949 | + if (object.GetWindow().copy.selection.Size() > 0) |
---|
| 16950 | + folder = object.GetWindow().copy.selection.elementAt(0); |
---|
| 16951 | + return folder; |
---|
| 16952 | + } |
---|
| 16953 | + |
---|
16328 | 16954 | class SelectBuffer implements GLEventListener |
---|
16329 | 16955 | { |
---|
16330 | 16956 | |
---|
.. | .. |
---|
16340 | 16966 | //new Exception().printStackTrace(); |
---|
16341 | 16967 | System.out.println("select buffer init"); |
---|
16342 | 16968 | // Use debug pipeline |
---|
16343 | | - drawable.setGL(new DebugGL(drawable.getGL())); |
---|
| 16969 | + //drawable.setGL(new DebugGL(drawable.getGL())); |
---|
16344 | 16970 | |
---|
16345 | 16971 | GL gl = drawable.getGL(); |
---|
16346 | 16972 | |
---|
.. | .. |
---|
16404 | 17030 | |
---|
16405 | 17031 | //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL); |
---|
16406 | 17032 | |
---|
| 17033 | + if (PAINTMODE) |
---|
| 17034 | + { |
---|
| 17035 | + if (object.GetWindow().copy.selection.Size() > 0) |
---|
| 17036 | + { |
---|
| 17037 | + Object3D paintobj = object.GetWindow().copy.selection.elementAt(0); |
---|
| 17038 | + |
---|
| 17039 | + // Make what you paint not selectable. |
---|
| 17040 | + paintobj.ResetSelectable(); |
---|
| 17041 | + } |
---|
| 17042 | + } |
---|
| 17043 | + |
---|
16407 | 17044 | //int tmp = selection_view; |
---|
16408 | 17045 | //selection_view = -1; |
---|
16409 | 17046 | int temp = DrawMode(); |
---|
.. | .. |
---|
16415 | 17052 | // temp = DEFAULT; // patch for selection debug |
---|
16416 | 17053 | Globals.drawMode = temp; // WARNING |
---|
16417 | 17054 | |
---|
| 17055 | + if (PAINTMODE) |
---|
| 17056 | + { |
---|
| 17057 | + if (object.GetWindow().copy.selection.Size() > 0) |
---|
| 17058 | + { |
---|
| 17059 | + Object3D paintobj = object.GetWindow().copy.selection.elementAt(0); |
---|
| 17060 | + |
---|
| 17061 | + // Revert. |
---|
| 17062 | + paintobj.RestoreSelectable(); |
---|
| 17063 | + } |
---|
| 17064 | + } |
---|
| 17065 | + |
---|
16418 | 17066 | //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view); |
---|
16419 | 17067 | |
---|
16420 | 17068 | // trying different ways of getting the depth info over |
---|
.. | .. |
---|
16462 | 17110 | // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]); |
---|
16463 | 17111 | // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]); |
---|
16464 | 17112 | // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]); |
---|
| 17113 | + |
---|
| 17114 | + CreateSelectedPoint(); |
---|
16465 | 17115 | |
---|
16466 | 17116 | // Will fit the mesh !!! |
---|
16467 | 17117 | selectedpoint.toParent[0][0] = 0.0001; |
---|
.. | .. |
---|
16516 | 17166 | } |
---|
16517 | 17167 | |
---|
16518 | 17168 | if (!movingcamera && !PAINTMODE) |
---|
16519 | | - object.editWindow.ScreenFitPoint(); // fev 2014 |
---|
| 17169 | + object.GetWindow().ScreenFitPoint(); // fev 2014 |
---|
16520 | 17170 | |
---|
16521 | | - if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0) |
---|
| 17171 | + if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0) |
---|
16522 | 17172 | { |
---|
16523 | | - Object3D paintobj = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0); |
---|
| 17173 | + //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0); |
---|
16524 | 17174 | |
---|
16525 | | - Object3D group = new Object3D("inst" + paintcount++); |
---|
| 17175 | + if (object.GetWindow().copy.selection.Size() > 0) |
---|
| 17176 | + { |
---|
| 17177 | + Object3D paintobj = object.GetWindow().copy.selection.elementAt(0); |
---|
16526 | 17178 | |
---|
16527 | | - group.CreateMaterial(); // use a void leaf to select instances |
---|
16528 | | - |
---|
16529 | | - group.add(paintobj); // link |
---|
16530 | | - |
---|
16531 | | - object.editWindow.SnapObject(group); |
---|
16532 | | - |
---|
16533 | | - Object3D folder = object.editWindow.copy; |
---|
16534 | | - |
---|
16535 | | - if (object.editWindow.copy.selection.Size() > 0) |
---|
16536 | | - folder = object.editWindow.copy.selection.elementAt(0); |
---|
16537 | | - |
---|
16538 | | - folder.add(group); |
---|
16539 | | - |
---|
16540 | | - object.editWindow.ResetModel(); |
---|
16541 | | - object.editWindow.refreshContents(); |
---|
| 17179 | + Object3D inst = new Object3D("inst" + paintcount++); |
---|
| 17180 | + |
---|
| 17181 | + inst.CreateMaterial(); // use a void leaf to select instances |
---|
| 17182 | + |
---|
| 17183 | + inst.add(paintobj); // link |
---|
| 17184 | + |
---|
| 17185 | + object.GetWindow().SnapObject(inst); |
---|
| 17186 | + |
---|
| 17187 | + Object3D folder = paintFolder; // GetFolder(); |
---|
| 17188 | + |
---|
| 17189 | + folder.add(inst); |
---|
| 17190 | + |
---|
| 17191 | + object.GetWindow().ResetModel(); |
---|
| 17192 | + object.GetWindow().refreshContents(); |
---|
| 17193 | + } |
---|
16542 | 17194 | } |
---|
16543 | 17195 | else |
---|
16544 | 17196 | paintcount = 0; |
---|
.. | .. |
---|
16577 | 17229 | //System.out.println("objects[color] = " + objects[color]); |
---|
16578 | 17230 | //objects[color].Select(); |
---|
16579 | 17231 | indexcount = 0; |
---|
| 17232 | + ObjEditor window = object.GetWindow(); |
---|
| 17233 | + if (window != null && deselect) |
---|
| 17234 | + { |
---|
| 17235 | + window.Select(null, deselect, true); |
---|
| 17236 | + } |
---|
16580 | 17237 | object.Select(color, deselect); |
---|
16581 | 17238 | } |
---|
16582 | 17239 | |
---|
.. | .. |
---|
17102 | 17759 | int AAbuffersize = 0; |
---|
17103 | 17760 | |
---|
17104 | 17761 | //double[] selectedpoint = new double[3]; |
---|
17105 | | - static Superellipsoid selectedpoint = new Superellipsoid(); |
---|
| 17762 | + static Superellipsoid selectedpoint; |
---|
17106 | 17763 | static Sphere previousselectedpoint = null; |
---|
17107 | | - static Sphere debugpointG = new Sphere(); |
---|
17108 | | - static Sphere debugpointP = new Sphere(); |
---|
17109 | | - static Sphere debugpointC = new Sphere(); |
---|
17110 | | - static Sphere debugpointR = new Sphere(); |
---|
| 17764 | + static Sphere debugpointG; |
---|
| 17765 | + static Sphere debugpointP; |
---|
| 17766 | + static Sphere debugpointC; |
---|
| 17767 | + static Sphere debugpointR; |
---|
17111 | 17768 | |
---|
17112 | 17769 | static Sphere debugpoints[] = new Sphere[8]; |
---|
17113 | 17770 | |
---|
17114 | | - static |
---|
17115 | | - { |
---|
17116 | | - for (int i=0; i<8; i++) |
---|
17117 | | - { |
---|
17118 | | - debugpoints[i] = new Sphere(); |
---|
17119 | | - } |
---|
17120 | | - } |
---|
17121 | | - |
---|
17122 | 17771 | static void InitPoints(float radius) |
---|
17123 | 17772 | { |
---|
17124 | 17773 | for (int i=0; i<8; i++) |
---|