.. | .. |
---|
18 | 18 | import javax.imageio.ImageIO; |
---|
19 | 19 | import javax.imageio.ImageWriteParam; |
---|
20 | 20 | import javax.imageio.ImageWriter; |
---|
| 21 | +import javax.imageio.ImageReadParam; |
---|
| 22 | +import javax.imageio.ImageReader; |
---|
21 | 23 | import javax.imageio.plugins.jpeg.JPEGImageWriteParam; |
---|
| 24 | +import javax.imageio.stream.ImageInputStream; |
---|
22 | 25 | import javax.imageio.stream.ImageOutputStream; |
---|
23 | 26 | import javax.imageio.ImageWriteParam; |
---|
24 | 27 | |
---|
.. | .. |
---|
30 | 33 | import java.nio.*; |
---|
31 | 34 | |
---|
32 | 35 | import gleem.linalg.Mat4f; |
---|
| 36 | +import javax.imageio.ImageTypeSpecifier; |
---|
33 | 37 | |
---|
34 | 38 | class CameraPane extends GLCanvas implements iCameraPane, Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener |
---|
35 | 39 | { |
---|
.. | .. |
---|
37 | 41 | static boolean[] selectedstack = new boolean[65536]; |
---|
38 | 42 | static int materialdepth = 0; |
---|
39 | 43 | |
---|
40 | | - static boolean DEBUG = false; |
---|
41 | 44 | static boolean FRUSTUM = false; // still bogus true; // frustum culling |
---|
42 | 45 | |
---|
43 | 46 | // camera change fix |
---|
.. | .. |
---|
45 | 48 | static boolean ABORTED = false; |
---|
46 | 49 | |
---|
47 | 50 | static int STEP = 1; |
---|
| 51 | + |
---|
| 52 | + private static BufferedImage CreateBim(byte[] bytes, int width, int height) |
---|
| 53 | + { |
---|
| 54 | + int[] pixels = new int[bytes.length/3]; |
---|
| 55 | + for (int i=pixels.length; --i>=0;) |
---|
| 56 | + { |
---|
| 57 | + int i3 = i*3; |
---|
| 58 | + pixels[i] = 0xFF; |
---|
| 59 | + pixels[i] <<= 8; |
---|
| 60 | + pixels[i] |= bytes[i3+2] & 0xFF; |
---|
| 61 | + pixels[i] <<= 8; |
---|
| 62 | + pixels[i] |= bytes[i3+1] & 0xFF; |
---|
| 63 | + pixels[i] <<= 8; |
---|
| 64 | + pixels[i] |= bytes[i3] & 0xFF; |
---|
| 65 | + } |
---|
| 66 | + /* |
---|
| 67 | + int r=0,g=0,b=0,a=0; |
---|
| 68 | + for (int i=0; i<width; i++) |
---|
| 69 | + for (int j=0; j<height; j++) |
---|
| 70 | + { |
---|
| 71 | + int index = j*width+i; |
---|
| 72 | + int p = pixels[index]; |
---|
| 73 | + a = ((p>>24) & 0xFF); |
---|
| 74 | + r = ((p>>16) & 0xFF); |
---|
| 75 | + g = ((p>>8) & 0xFF); |
---|
| 76 | + b = (p & 0xFF); |
---|
| 77 | + pixels[index] = (a<<24) | (b<<16) | (g<<8) | r; |
---|
| 78 | + } |
---|
| 79 | + /**/ |
---|
| 80 | + BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile); |
---|
| 81 | + rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width); |
---|
| 82 | + return rendImage; |
---|
| 83 | + } |
---|
48 | 84 | |
---|
49 | 85 | /*static*/ private boolean CULLFACE = false; // true; |
---|
50 | 86 | /*static*/ boolean NEAREST = false; // true; |
---|
.. | .. |
---|
61 | 97 | //boolean REDUCETEXTURE = true; |
---|
62 | 98 | boolean CACHETEXTURE = true; |
---|
63 | 99 | boolean CLEANCACHE = false; // true; |
---|
64 | | - boolean MIPMAP = false; // true; |
---|
| 100 | + boolean MIPMAP = false; // true; // never works... |
---|
65 | 101 | boolean COMPRESSTEXTURE = false; |
---|
66 | 102 | boolean KOMPACTTEXTURE = false; // true; |
---|
67 | 103 | boolean RESIZETEXTURE = false; |
---|
.. | .. |
---|
74 | 110 | //private Mat4f spotlightTransform = new Mat4f(); |
---|
75 | 111 | //private Mat4f spotlightInverseTransform = new Mat4f(); |
---|
76 | 112 | static GLContext glcontext = null; |
---|
77 | | - /*static*/ com.sun.opengl.util.texture.Texture cubemap; |
---|
| 113 | + /*static*/ com.sun.opengl.util.texture.Texture cubemap; // Either custom or rgb |
---|
| 114 | + /*static*/ com.sun.opengl.util.texture.Texture cubemapcustom; |
---|
| 115 | + /*static*/ com.sun.opengl.util.texture.Texture cubemaprgb; |
---|
78 | 116 | boolean reverseUP = false; |
---|
79 | 117 | static boolean frozen = false; |
---|
80 | 118 | boolean enablebackspace = false; // patch for back buffer refresh |
---|
.. | .. |
---|
137 | 175 | static boolean doublesided = false; // true; // reversed normals are awful for conformance |
---|
138 | 176 | boolean anisotropy = true; |
---|
139 | 177 | boolean softshadow = true; // slower but better false; |
---|
140 | | - boolean opacityhalo = false; |
---|
| 178 | + boolean opacityhalo = false; // reverse the halo effect (e.g. glass) |
---|
141 | 179 | |
---|
142 | 180 | boolean macromode = false; |
---|
143 | 181 | |
---|
.. | .. |
---|
148 | 186 | defaultcaps.setAccumGreenBits(16); |
---|
149 | 187 | defaultcaps.setAccumBlueBits(16); |
---|
150 | 188 | defaultcaps.setAccumAlphaBits(16); |
---|
| 189 | + } |
---|
| 190 | + |
---|
| 191 | + private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory(); |
---|
| 192 | + |
---|
| 193 | + public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException |
---|
| 194 | + { |
---|
| 195 | + try |
---|
| 196 | + { |
---|
| 197 | + return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap); |
---|
| 198 | + } catch (IOException e) |
---|
| 199 | + { |
---|
| 200 | + System.out.println("NAME = " + name); |
---|
| 201 | + e.printStackTrace(); // throw new RuntimeException(e); |
---|
| 202 | + return null; |
---|
| 203 | + } |
---|
151 | 204 | } |
---|
152 | 205 | |
---|
153 | 206 | void SetAsGLRenderer(boolean b) |
---|
.. | .. |
---|
168 | 221 | |
---|
169 | 222 | SetCamera(cam); |
---|
170 | 223 | |
---|
171 | | - SetLight(new Camera(new cVector(10, 10, -20))); |
---|
| 224 | + // Warning: not used. |
---|
| 225 | + SetLight(new Camera(new cVector(15, 10, -20))); |
---|
172 | 226 | |
---|
173 | 227 | object = o; |
---|
174 | 228 | |
---|
.. | .. |
---|
325 | 379 | cStatic.objectstack[materialdepth++] = obj; |
---|
326 | 380 | //System.out.println("material " + material); |
---|
327 | 381 | //Applet3D.tracein(this, selected); |
---|
328 | | - display.vector2buffer = obj.projectedVertices; |
---|
| 382 | + //display.vector2buffer = obj.projectedVertices; |
---|
329 | 383 | if (obj instanceof Camera) |
---|
330 | 384 | { |
---|
331 | 385 | display.options1[0] = material.shift; |
---|
.. | .. |
---|
334 | 388 | display.options1[2] = material.shadowbias; |
---|
335 | 389 | display.options1[3] = material.aniso; |
---|
336 | 390 | display.options1[4] = material.anisoV; |
---|
| 391 | +// System.out.println("display.options1[0] " + display.options1[0]); |
---|
| 392 | +// System.out.println("display.options1[1] " + display.options1[1]); |
---|
| 393 | +// System.out.println("display.options1[2] " + display.options1[2]); |
---|
| 394 | +// System.out.println("display.options1[3] " + display.options1[3]); |
---|
| 395 | +// System.out.println("display.options1[4] " + display.options1[4]); |
---|
337 | 396 | display.options2[0] = material.opacity; |
---|
338 | 397 | display.options2[1] = material.diffuse; |
---|
339 | 398 | display.options2[2] = material.factor; |
---|
| 399 | +// System.out.println("display.options2[0] " + display.options2[0]); |
---|
| 400 | +// System.out.println("display.options2[1] " + display.options2[1]); |
---|
| 401 | +// System.out.println("display.options2[2] " + display.options2[2]); |
---|
340 | 402 | |
---|
341 | 403 | cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3); |
---|
| 404 | +// System.out.println("display.options3[0] " + display.options3[0]); |
---|
| 405 | +// System.out.println("display.options3[1] " + display.options3[1]); |
---|
| 406 | +// System.out.println("display.options3[2] " + display.options3[2]); |
---|
342 | 407 | display.options4[0] = material.cameralight/0.2f; |
---|
343 | 408 | display.options4[1] = material.subsurface; |
---|
344 | 409 | display.options4[2] = material.sheen; |
---|
| 410 | +// System.out.println("display.options4[0] " + display.options4[0]); |
---|
| 411 | +// System.out.println("display.options4[1] " + display.options4[1]); |
---|
| 412 | +// System.out.println("display.options4[2] " + display.options4[2]); |
---|
345 | 413 | |
---|
346 | 414 | // if (display.CURRENTANTIALIAS > 0) |
---|
347 | 415 | // display.options3[3] /= 4; |
---|
.. | .. |
---|
357 | 425 | /**/ |
---|
358 | 426 | } else |
---|
359 | 427 | { |
---|
360 | | - DrawMaterial(material, selected); |
---|
| 428 | + DrawMaterial(material, selected, obj.projectedVertices); |
---|
361 | 429 | } |
---|
362 | 430 | } else |
---|
363 | 431 | { |
---|
.. | .. |
---|
381 | 449 | cStatic.objectstack[materialdepth++] = obj; |
---|
382 | 450 | //System.out.println("material " + material); |
---|
383 | 451 | //Applet3D.tracein("selected ", selected); |
---|
384 | | - display.vector2buffer = obj.projectedVertices; |
---|
385 | | - display.DrawMaterial(material, selected); |
---|
| 452 | + //display.vector2buffer = obj.projectedVertices; |
---|
| 453 | + display.DrawMaterial(material, selected, obj.projectedVertices); |
---|
386 | 454 | } |
---|
387 | 455 | } |
---|
388 | 456 | |
---|
.. | .. |
---|
399 | 467 | materialdepth -= 1; |
---|
400 | 468 | if (materialdepth > 0) |
---|
401 | 469 | { |
---|
402 | | - display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices; |
---|
403 | | - display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]); |
---|
| 470 | + //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices; |
---|
| 471 | + display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices); |
---|
404 | 472 | } |
---|
405 | 473 | //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???"); |
---|
406 | 474 | } else if (selected && CameraPane.flash && obj.GetMaterial() != null) |
---|
.. | .. |
---|
420 | 488 | materialdepth -= 1; |
---|
421 | 489 | if (materialdepth > 0) |
---|
422 | 490 | { |
---|
423 | | - display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices; |
---|
424 | | - display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]); |
---|
| 491 | + //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices; |
---|
| 492 | + display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices); |
---|
425 | 493 | } |
---|
426 | 494 | //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???"); |
---|
427 | 495 | //else |
---|
.. | .. |
---|
462 | 530 | if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0) |
---|
463 | 531 | { |
---|
464 | 532 | //gl.glBegin(gl.GL_TRIANGLES); |
---|
465 | | - boolean hasnorm = pv.norm != null; // && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0); |
---|
| 533 | + boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0) |
---|
| 534 | + // TEST LIVE NORMALS && !obj.dontselect |
---|
| 535 | + ; |
---|
466 | 536 | if (!hasnorm) |
---|
467 | 537 | { |
---|
468 | | - // System.out.println("FUCK!!"); |
---|
| 538 | + // System.out.println("Mesh normal"); |
---|
469 | 539 | LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0); |
---|
470 | 540 | LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1); |
---|
471 | 541 | LA.vecCross(obj.v0, obj.v1, obj.v2); |
---|
.. | .. |
---|
1190 | 1260 | gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1); |
---|
1191 | 1261 | } |
---|
1192 | 1262 | } |
---|
| 1263 | + |
---|
1193 | 1264 | if (flipV) |
---|
1194 | 1265 | gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]); |
---|
1195 | 1266 | else |
---|
1196 | 1267 | gl.glTexCoord2f(uv[count2], uv[count2 + 1]); |
---|
| 1268 | + |
---|
1197 | 1269 | //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]); |
---|
1198 | 1270 | gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]); |
---|
1199 | 1271 | |
---|
.. | .. |
---|
1213 | 1285 | gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1); |
---|
1214 | 1286 | } |
---|
1215 | 1287 | } |
---|
| 1288 | + |
---|
1216 | 1289 | if (flipV) |
---|
1217 | 1290 | gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]); |
---|
1218 | 1291 | else |
---|
1219 | 1292 | gl.glTexCoord2f(uv[count2], uv[count2 + 1]); |
---|
| 1293 | + |
---|
1220 | 1294 | //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]); |
---|
1221 | 1295 | gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]); |
---|
1222 | 1296 | |
---|
.. | .. |
---|
1244 | 1318 | gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]); |
---|
1245 | 1319 | else |
---|
1246 | 1320 | gl.glTexCoord2f(uv[count2], uv[count2 + 1]); |
---|
| 1321 | + |
---|
1247 | 1322 | //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]); |
---|
1248 | 1323 | gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]); |
---|
| 1324 | + |
---|
1249 | 1325 | count2 += 2; |
---|
1250 | 1326 | count3 += 3; |
---|
1251 | 1327 | } |
---|
.. | .. |
---|
1424 | 1500 | gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z); |
---|
1425 | 1501 | } |
---|
1426 | 1502 | |
---|
| 1503 | + float[] colorV = new float[4]; |
---|
| 1504 | + |
---|
1427 | 1505 | void SetColor(Object3D obj, Vertex p0) |
---|
1428 | 1506 | { |
---|
1429 | 1507 | CameraPane display = this; |
---|
.. | .. |
---|
1491 | 1569 | { |
---|
1492 | 1570 | return; |
---|
1493 | 1571 | } |
---|
1494 | | - |
---|
1495 | | - float[] colorV = new float[3]; |
---|
1496 | 1572 | |
---|
1497 | 1573 | if (false) // marked) |
---|
1498 | 1574 | { |
---|
.. | .. |
---|
1601 | 1677 | // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0); |
---|
1602 | 1678 | } |
---|
1603 | 1679 | |
---|
1604 | | - void DrawMaterial(cMaterial material, boolean selected) |
---|
| 1680 | + void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others) |
---|
1605 | 1681 | { |
---|
1606 | 1682 | CameraPane display = this; |
---|
1607 | 1683 | //new Exception().printStackTrace(); |
---|
.. | .. |
---|
1636 | 1712 | colorV[0] = display.modelParams0[0] * material.diffuse; |
---|
1637 | 1713 | colorV[1] = display.modelParams0[1] * material.diffuse; |
---|
1638 | 1714 | colorV[2] = display.modelParams0[2] * material.diffuse; |
---|
1639 | | - colorV[3] = material.opacity; |
---|
| 1715 | + colorV[3] = 1; // material.opacity; |
---|
1640 | 1716 | |
---|
1641 | 1717 | gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity); |
---|
1642 | 1718 | //System.out.println("Opacity = " + opacity); |
---|
.. | .. |
---|
1744 | 1820 | display.modelParams7[2] = 0; |
---|
1745 | 1821 | display.modelParams7[3] = 0; |
---|
1746 | 1822 | |
---|
1747 | | - display.modelParams6[0] = 100; // criss de bug de bump |
---|
| 1823 | + //display.modelParams6[0] = 100; // criss de bug de bump |
---|
1748 | 1824 | |
---|
1749 | | - Object3D.cVector2[] extparams = display.vector2buffer; |
---|
| 1825 | + Object3D.cVector2[] extparams = others; // display.vector2buffer; |
---|
1750 | 1826 | if (extparams != null && extparams.length > 0 && extparams[0] != null) |
---|
1751 | 1827 | { |
---|
1752 | 1828 | display.modelParams6[0] = extparams[0].x / 1000.0f; // bump |
---|
.. | .. |
---|
1888 | 1964 | void PushMatrix(double[][] matrix) |
---|
1889 | 1965 | { |
---|
1890 | 1966 | // GrafreeD.tracein(matrix); |
---|
1891 | | - PushMatrix(matrix,1); |
---|
| 1967 | + PushMatrix(matrix, 1); |
---|
1892 | 1968 | } |
---|
1893 | 1969 | |
---|
1894 | 1970 | void PushMatrix() |
---|
.. | .. |
---|
2042 | 2118 | //System.err.println("Oeil on"); |
---|
2043 | 2119 | OEIL = true; |
---|
2044 | 2120 | if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode) |
---|
2045 | | - object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK); |
---|
| 2121 | + object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK); |
---|
2046 | 2122 | //pingthread.StepToTarget(true); |
---|
2047 | 2123 | } |
---|
2048 | 2124 | |
---|
.. | .. |
---|
2257 | 2333 | |
---|
2258 | 2334 | void ToggleDebug() |
---|
2259 | 2335 | { |
---|
2260 | | - DEBUG ^= true; |
---|
| 2336 | + Globals.DEBUG ^= true; |
---|
2261 | 2337 | } |
---|
2262 | 2338 | |
---|
2263 | 2339 | void ToggleLookAt() |
---|
.. | .. |
---|
2265 | 2341 | LOOKAT ^= true; |
---|
2266 | 2342 | } |
---|
2267 | 2343 | |
---|
2268 | | - void ToggleRandom() |
---|
| 2344 | + void ToggleSwitch() |
---|
2269 | 2345 | { |
---|
2270 | 2346 | SWITCH ^= true; |
---|
2271 | 2347 | } |
---|
.. | .. |
---|
2275 | 2351 | HANDLES ^= true; |
---|
2276 | 2352 | } |
---|
2277 | 2353 | |
---|
| 2354 | + Object3D paintFolder; |
---|
| 2355 | + |
---|
2278 | 2356 | void TogglePaint() |
---|
2279 | 2357 | { |
---|
2280 | 2358 | PAINTMODE ^= true; |
---|
2281 | 2359 | paintcount = 0; |
---|
| 2360 | + |
---|
| 2361 | + if (PAINTMODE) |
---|
| 2362 | + { |
---|
| 2363 | + paintFolder = GetFolder(); |
---|
| 2364 | + } |
---|
2282 | 2365 | } |
---|
2283 | 2366 | |
---|
2284 | 2367 | void SwapCamera(int a, int b) |
---|
.. | .. |
---|
2374 | 2457 | { |
---|
2375 | 2458 | return currentGL; |
---|
2376 | 2459 | } |
---|
2377 | | - |
---|
| 2460 | + |
---|
| 2461 | + static private BufferedImage CreateBim(TextureData texturedata) |
---|
| 2462 | + { |
---|
| 2463 | + Grafreed.Assert(texturedata != null); |
---|
| 2464 | + |
---|
| 2465 | + int width = texturedata.getWidth(); |
---|
| 2466 | + int height = texturedata.getHeight(); |
---|
| 2467 | + |
---|
| 2468 | + Buffer buffer = texturedata.getBuffer(); |
---|
| 2469 | + ByteBuffer bytebuf = (ByteBuffer)buffer; |
---|
| 2470 | + |
---|
| 2471 | + byte[] bytes = bytebuf.array(); |
---|
| 2472 | + |
---|
| 2473 | + return CreateBim(bytes, width, height); |
---|
| 2474 | + } |
---|
| 2475 | + |
---|
2378 | 2476 | /**/ |
---|
2379 | 2477 | class CacheTexture |
---|
2380 | 2478 | { |
---|
.. | .. |
---|
2383 | 2481 | |
---|
2384 | 2482 | int resolution; |
---|
2385 | 2483 | |
---|
2386 | | - CacheTexture(com.sun.opengl.util.texture.Texture tex, int res) |
---|
| 2484 | + CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res) |
---|
2387 | 2485 | { |
---|
2388 | | - texture = tex; |
---|
| 2486 | + texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata); |
---|
| 2487 | + texturedata = texdata; |
---|
2389 | 2488 | resolution = res; |
---|
2390 | 2489 | } |
---|
2391 | 2490 | } |
---|
2392 | 2491 | /**/ |
---|
2393 | 2492 | |
---|
2394 | 2493 | // TEXTURE static Texture texture; |
---|
2395 | | - static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures |
---|
2396 | | - = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>(); |
---|
2397 | | - static public java.util.Hashtable<String, String> usedtextures = new java.util.Hashtable<String, String>(); |
---|
| 2494 | + static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>(); |
---|
| 2495 | + static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>(); |
---|
| 2496 | + static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>(); |
---|
| 2497 | + static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>(); |
---|
| 2498 | + |
---|
2398 | 2499 | int pigmentdepth = 0; |
---|
2399 | 2500 | public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536]; |
---|
2400 | 2501 | int bumpdepth = 0; |
---|
2401 | 2502 | public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536]; |
---|
2402 | 2503 | //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE"; |
---|
2403 | 2504 | public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP"); |
---|
2404 | | - public static String NOISE_TEXTURE = "WHITE_NOISE"; |
---|
| 2505 | + public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:"); |
---|
2405 | 2506 | // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL"); |
---|
2406 | 2507 | |
---|
2407 | | - com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump) |
---|
| 2508 | + com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump) |
---|
2408 | 2509 | { |
---|
2409 | 2510 | TextureData texturedata = null; |
---|
2410 | 2511 | |
---|
.. | .. |
---|
2423 | 2524 | if (bump) |
---|
2424 | 2525 | texturedata = ConvertBump(texturedata, false); |
---|
2425 | 2526 | |
---|
2426 | | - com.sun.opengl.util.texture.Texture texture = |
---|
2427 | | - com.sun.opengl.util.texture.TextureIO.newTexture(texturedata); |
---|
| 2527 | +// com.sun.opengl.util.texture.Texture texture = |
---|
| 2528 | +// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata); |
---|
2428 | 2529 | |
---|
2429 | | - texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT); |
---|
2430 | | - texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT); |
---|
| 2530 | + //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT); |
---|
| 2531 | + //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT); |
---|
2431 | 2532 | |
---|
2432 | | - return texture; |
---|
| 2533 | + return texturedata; |
---|
| 2534 | + } |
---|
| 2535 | + |
---|
| 2536 | + com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump) |
---|
| 2537 | + { |
---|
| 2538 | + TextureData texturedata = null; |
---|
| 2539 | + |
---|
| 2540 | + try |
---|
| 2541 | + { |
---|
| 2542 | + texturedata = |
---|
| 2543 | + com.sun.opengl.util.texture.TextureIO.newTextureData( |
---|
| 2544 | + bim, |
---|
| 2545 | + true); |
---|
| 2546 | + } catch (Exception e) |
---|
| 2547 | + { |
---|
| 2548 | + throw new javax.media.opengl.GLException(e); |
---|
| 2549 | + } |
---|
| 2550 | + |
---|
| 2551 | + if (bump) |
---|
| 2552 | + texturedata = ConvertBump(texturedata, false); |
---|
| 2553 | + |
---|
| 2554 | + return texturedata; |
---|
2433 | 2555 | } |
---|
2434 | 2556 | |
---|
2435 | 2557 | boolean HUESMOOTH = true; // wrap around bug... true; |
---|
.. | .. |
---|
3502 | 3624 | |
---|
3503 | 3625 | System.out.println("LOADING TEXTURE : " + name); |
---|
3504 | 3626 | |
---|
| 3627 | + Object x = texturedata.getMipmapData(); // .getBuffer(); |
---|
| 3628 | + |
---|
3505 | 3629 | // |
---|
3506 | 3630 | if (false) // compressbit > 0) |
---|
3507 | 3631 | { |
---|
.. | .. |
---|
7900 | 8024 | String pigment = Object3D.GetPigment(tex); |
---|
7901 | 8025 | String bump = Object3D.GetBump(tex); |
---|
7902 | 8026 | |
---|
7903 | | - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8027 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
7904 | 8028 | { |
---|
7905 | 8029 | // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment); |
---|
7906 | 8030 | // System.out.println("; bump = " + bump); |
---|
.. | .. |
---|
7915 | 8039 | pigment = null; |
---|
7916 | 8040 | } |
---|
7917 | 8041 | |
---|
7918 | | - ReleaseTexture(bump, true); |
---|
7919 | | - ReleaseTexture(pigment, false); |
---|
| 8042 | + ReleaseTexture(tex, true); |
---|
| 8043 | + ReleaseTexture(tex, false); |
---|
7920 | 8044 | } |
---|
7921 | 8045 | |
---|
7922 | | - void ReleaseTexture(String tex, boolean bump) |
---|
| 8046 | + public void ReleasePigmentTexture(cTexture tex) // INTERFACE |
---|
| 8047 | + { |
---|
| 8048 | + if (/*tex == null ||*/ ambientOcclusion ) // || !textureon) |
---|
| 8049 | + { |
---|
| 8050 | + return; |
---|
| 8051 | + } |
---|
| 8052 | + |
---|
| 8053 | + if (tex == null) |
---|
| 8054 | + { |
---|
| 8055 | + ReleaseTexture(null, false); |
---|
| 8056 | + return; |
---|
| 8057 | + } |
---|
| 8058 | + |
---|
| 8059 | + String pigment = Object3D.GetPigment(tex); |
---|
| 8060 | + |
---|
| 8061 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8062 | + { |
---|
| 8063 | + // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment); |
---|
| 8064 | + // System.out.println("; bump = " + bump); |
---|
| 8065 | + } |
---|
| 8066 | + |
---|
| 8067 | + if (pigment.equals("")) |
---|
| 8068 | + { |
---|
| 8069 | + pigment = null; |
---|
| 8070 | + } |
---|
| 8071 | + |
---|
| 8072 | + ReleaseTexture(tex, false); |
---|
| 8073 | + } |
---|
| 8074 | + |
---|
| 8075 | + public void ReleaseBumpTexture(cTexture tex) // INTERFACE |
---|
| 8076 | + { |
---|
| 8077 | + if (/*tex == null ||*/ ambientOcclusion ) // || !textureon) |
---|
| 8078 | + { |
---|
| 8079 | + return; |
---|
| 8080 | + } |
---|
| 8081 | + |
---|
| 8082 | + if (tex == null) |
---|
| 8083 | + { |
---|
| 8084 | + ReleaseTexture(null, true); |
---|
| 8085 | + return; |
---|
| 8086 | + } |
---|
| 8087 | + |
---|
| 8088 | + String bump = Object3D.GetBump(tex); |
---|
| 8089 | + |
---|
| 8090 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8091 | + { |
---|
| 8092 | + // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment); |
---|
| 8093 | + // System.out.println("; bump = " + bump); |
---|
| 8094 | + } |
---|
| 8095 | + |
---|
| 8096 | + if (bump.equals("")) |
---|
| 8097 | + { |
---|
| 8098 | + bump = null; |
---|
| 8099 | + } |
---|
| 8100 | + |
---|
| 8101 | + ReleaseTexture(tex, true); |
---|
| 8102 | + } |
---|
| 8103 | + |
---|
| 8104 | + void ReleaseTexture(cTexture tex, boolean bump) |
---|
7923 | 8105 | { |
---|
7924 | 8106 | if (// DrawMode() != 0 || /*tex == null ||*/ |
---|
7925 | 8107 | ambientOcclusion ) // || !textureon) |
---|
.. | .. |
---|
7930 | 8112 | CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null; |
---|
7931 | 8113 | |
---|
7932 | 8114 | if (tex != null) |
---|
7933 | | - texture = textures.get(tex); |
---|
| 8115 | + texture = bump ? texturebump.get(tex) : texturepigment.get(tex); |
---|
7934 | 8116 | |
---|
7935 | 8117 | // //assert( texture != null ); |
---|
7936 | 8118 | // if (texture == null) |
---|
.. | .. |
---|
8024 | 8206 | |
---|
8025 | 8207 | /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE |
---|
8026 | 8208 | { |
---|
| 8209 | +// if (// DrawMode() != 0 || /*tex == null ||*/ |
---|
| 8210 | +// ambientOcclusion ) // || !textureon) |
---|
| 8211 | +// { |
---|
| 8212 | +// return; // false; |
---|
| 8213 | +// } |
---|
| 8214 | +// |
---|
| 8215 | +// if (tex == null) |
---|
| 8216 | +// { |
---|
| 8217 | +// BindTexture(null,false,resolution); |
---|
| 8218 | +// BindTexture(null,true,resolution); |
---|
| 8219 | +// return; |
---|
| 8220 | +// } |
---|
| 8221 | +// |
---|
| 8222 | +// String pigment = Object3D.GetPigment(tex); |
---|
| 8223 | +// String bump = Object3D.GetBump(tex); |
---|
| 8224 | +// |
---|
| 8225 | +// usedtextures.add(pigment); |
---|
| 8226 | +// usedtextures.add(bump); |
---|
| 8227 | +// |
---|
| 8228 | +// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8229 | +// { |
---|
| 8230 | +// // System.out.print("BIND +++++++++++++++ pigment = " + pigment); |
---|
| 8231 | +// // System.out.println("; bump = " + bump); |
---|
| 8232 | +// } |
---|
| 8233 | +// |
---|
| 8234 | +// if (bump.equals("")) |
---|
| 8235 | +// { |
---|
| 8236 | +// bump = null; |
---|
| 8237 | +// } |
---|
| 8238 | +// if (pigment.equals("")) |
---|
| 8239 | +// { |
---|
| 8240 | +// pigment = null; |
---|
| 8241 | +// } |
---|
| 8242 | +// |
---|
| 8243 | +// GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
| 8244 | +// BindTexture(pigment, false, resolution); |
---|
| 8245 | +// GetGL().glActiveTexture(GetGL().GL_TEXTURE2); |
---|
| 8246 | +// BindTexture(bump, true, resolution); |
---|
| 8247 | +// GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
| 8248 | +// |
---|
| 8249 | +// return; // true; |
---|
| 8250 | + |
---|
| 8251 | + BindPigmentTexture(tex, resolution); |
---|
| 8252 | + BindBumpTexture(tex, resolution); |
---|
| 8253 | + } |
---|
| 8254 | + |
---|
| 8255 | + /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE |
---|
| 8256 | + { |
---|
8027 | 8257 | if (// DrawMode() != 0 || /*tex == null ||*/ |
---|
8028 | 8258 | ambientOcclusion ) // || !textureon) |
---|
8029 | 8259 | { |
---|
.. | .. |
---|
8033 | 8263 | if (tex == null) |
---|
8034 | 8264 | { |
---|
8035 | 8265 | BindTexture(null,false,resolution); |
---|
8036 | | - BindTexture(null,true,resolution); |
---|
8037 | 8266 | return; |
---|
8038 | 8267 | } |
---|
8039 | 8268 | |
---|
8040 | 8269 | String pigment = Object3D.GetPigment(tex); |
---|
| 8270 | + |
---|
| 8271 | + usedtextures.add(tex); |
---|
| 8272 | + |
---|
| 8273 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8274 | + { |
---|
| 8275 | + // System.out.print("BIND +++++++++++++++ pigment = " + pigment); |
---|
| 8276 | + // System.out.println("; bump = " + bump); |
---|
| 8277 | + } |
---|
| 8278 | + |
---|
| 8279 | + if (pigment.equals("")) |
---|
| 8280 | + { |
---|
| 8281 | + pigment = null; |
---|
| 8282 | + } |
---|
| 8283 | + |
---|
| 8284 | + GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
| 8285 | + BindTexture(tex, false, resolution); |
---|
| 8286 | + } |
---|
| 8287 | + |
---|
| 8288 | + /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE |
---|
| 8289 | + { |
---|
| 8290 | + if (// DrawMode() != 0 || /*tex == null ||*/ |
---|
| 8291 | + ambientOcclusion ) // || !textureon) |
---|
| 8292 | + { |
---|
| 8293 | + return; // false; |
---|
| 8294 | + } |
---|
| 8295 | + |
---|
| 8296 | + if (tex == null) |
---|
| 8297 | + { |
---|
| 8298 | + BindTexture(null,true,resolution); |
---|
| 8299 | + return; |
---|
| 8300 | + } |
---|
| 8301 | + |
---|
8041 | 8302 | String bump = Object3D.GetBump(tex); |
---|
8042 | 8303 | |
---|
8043 | | - usedtextures.put(pigment, pigment); |
---|
8044 | | - usedtextures.put(bump, bump); |
---|
| 8304 | + usedtextures.add(tex); |
---|
8045 | 8305 | |
---|
8046 | | - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8306 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
8047 | 8307 | { |
---|
8048 | 8308 | // System.out.print("BIND +++++++++++++++ pigment = " + pigment); |
---|
8049 | 8309 | // System.out.println("; bump = " + bump); |
---|
.. | .. |
---|
8053 | 8313 | { |
---|
8054 | 8314 | bump = null; |
---|
8055 | 8315 | } |
---|
8056 | | - if (pigment.equals("")) |
---|
8057 | | - { |
---|
8058 | | - pigment = null; |
---|
8059 | | - } |
---|
8060 | 8316 | |
---|
8061 | | - GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
8062 | | - BindTexture(pigment, false, resolution); |
---|
8063 | 8317 | GetGL().glActiveTexture(GetGL().GL_TEXTURE2); |
---|
8064 | | - BindTexture(bump, true, resolution); |
---|
| 8318 | + BindTexture(tex, true, resolution); |
---|
8065 | 8319 | GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
8066 | | - |
---|
8067 | | - return; // true; |
---|
8068 | 8320 | } |
---|
8069 | 8321 | |
---|
8070 | | - CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception |
---|
| 8322 | + java.util.HashSet<String> missingTextures = new java.util.HashSet<String>(); |
---|
| 8323 | + |
---|
| 8324 | + private boolean FileExists(String tex) |
---|
8071 | 8325 | { |
---|
8072 | | - CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null; |
---|
| 8326 | + if (missingTextures.contains(tex)) |
---|
| 8327 | + { |
---|
| 8328 | + return false; |
---|
| 8329 | + } |
---|
| 8330 | + |
---|
| 8331 | + boolean fileExists = new File(tex).exists(); |
---|
| 8332 | + |
---|
| 8333 | + if (!fileExists) |
---|
| 8334 | + { |
---|
| 8335 | + // If file exists, the "new File()" is not executed sgain |
---|
| 8336 | + missingTextures.add(tex); |
---|
| 8337 | + } |
---|
| 8338 | + |
---|
| 8339 | + return fileExists; |
---|
| 8340 | + } |
---|
| 8341 | + |
---|
| 8342 | + CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception |
---|
| 8343 | + { |
---|
| 8344 | + CacheTexture texturecache = null; |
---|
8073 | 8345 | |
---|
8074 | 8346 | if (tex != null) |
---|
8075 | 8347 | { |
---|
8076 | | - String texname = tex; |
---|
| 8348 | + String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex); |
---|
| 8349 | + byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata; |
---|
8077 | 8350 | |
---|
| 8351 | + if (texname.equals("") && texdata == null) |
---|
| 8352 | + { |
---|
| 8353 | + return null; |
---|
| 8354 | + } |
---|
| 8355 | + |
---|
| 8356 | + String fallbackTextureName = defaultDirectory + "/Textures/" + texname; |
---|
| 8357 | + |
---|
8078 | 8358 | // String[] split = tex.split("Textures"); |
---|
8079 | 8359 | // if (split.length > 1) |
---|
8080 | 8360 | // texname = "/Users/nbriere/Textures" + split[split.length-1]; |
---|
8081 | 8361 | // else |
---|
8082 | 8362 | // if (!texname.startsWith("/")) |
---|
8083 | 8363 | // texname = "/Users/nbriere/Textures/" + texname; |
---|
8084 | | - if (!new File(tex).exists()) |
---|
| 8364 | + if (!FileExists(texname) && !texname.startsWith("@")) |
---|
8085 | 8365 | { |
---|
8086 | | - texname = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory() + "/Textures/" + texname; |
---|
| 8366 | + texname = fallbackTextureName; |
---|
8087 | 8367 | } |
---|
8088 | 8368 | |
---|
8089 | 8369 | if (CACHETEXTURE) |
---|
8090 | | - texture = textures.get(texname); // TEXTURE CACHE |
---|
8091 | | - |
---|
8092 | | - TextureData texturedata = null; |
---|
8093 | | - |
---|
8094 | | - if (texture == null || texture.resolution < resolution) |
---|
8095 | 8370 | { |
---|
8096 | | - if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals("")) |
---|
| 8371 | + if (texdata == null) |
---|
| 8372 | + texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex); |
---|
| 8373 | + else |
---|
| 8374 | + texturecache = bimtextures.get(texdata); |
---|
| 8375 | + } |
---|
| 8376 | + |
---|
| 8377 | + if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution) |
---|
| 8378 | + { |
---|
| 8379 | + TextureData texturedata = null; |
---|
| 8380 | + |
---|
| 8381 | + if (texdata != null && textureon) |
---|
| 8382 | + { |
---|
| 8383 | + BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB); |
---|
| 8384 | + |
---|
| 8385 | + try |
---|
| 8386 | + { |
---|
| 8387 | + bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph); |
---|
| 8388 | + } |
---|
| 8389 | + catch (Exception e) |
---|
| 8390 | + { |
---|
| 8391 | + bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph); |
---|
| 8392 | + } |
---|
| 8393 | + |
---|
| 8394 | + texturecache = new CacheTexture(GetBimTexture(bim, bump), -1); |
---|
| 8395 | + bimtextures.put(texdata, texturecache); |
---|
| 8396 | + |
---|
| 8397 | + //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB); |
---|
| 8398 | + |
---|
| 8399 | + //Object bim2 = CreateBim(texturecache.texturedata); |
---|
| 8400 | + //bim2 = bim; |
---|
| 8401 | + } |
---|
| 8402 | + else |
---|
| 8403 | + if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals("")) |
---|
8097 | 8404 | { |
---|
8098 | 8405 | assert(!bump); |
---|
8099 | 8406 | // if (bump) |
---|
.. | .. |
---|
8104 | 8411 | // } |
---|
8105 | 8412 | // else |
---|
8106 | 8413 | // { |
---|
8107 | | - texture = textures.get(tex); |
---|
8108 | | - if (texture == null) |
---|
| 8414 | + // texturecache = textures.get(texname); // suspicious |
---|
| 8415 | + if (texturecache == null) |
---|
8109 | 8416 | { |
---|
8110 | | - texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
| 8417 | + texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
8111 | 8418 | } |
---|
| 8419 | + else |
---|
| 8420 | + new Exception().printStackTrace(); |
---|
8112 | 8421 | // } |
---|
8113 | 8422 | } else |
---|
8114 | | - if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals("")) |
---|
| 8423 | + if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals("")) |
---|
8115 | 8424 | { |
---|
8116 | 8425 | assert(bump); |
---|
8117 | | - texture = textures.get(tex); |
---|
8118 | | - if (texture == null) |
---|
8119 | | - texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
| 8426 | + // texturecache = textures.get(texname); // suspicious |
---|
| 8427 | + if (texturecache == null) |
---|
| 8428 | + texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
| 8429 | + else |
---|
| 8430 | + new Exception().printStackTrace(); |
---|
8120 | 8431 | } else |
---|
8121 | 8432 | { |
---|
8122 | 8433 | //if (tex.equals("IMMORTAL")) |
---|
.. | .. |
---|
8124 | 8435 | // texture = GetResourceTexture("default.png"); |
---|
8125 | 8436 | //} else |
---|
8126 | 8437 | //{ |
---|
8127 | | - if (tex.equals("WHITE_NOISE")) |
---|
| 8438 | + if (texname.endsWith("WHITE_NOISE")) |
---|
8128 | 8439 | { |
---|
8129 | | - texture = textures.get(tex); |
---|
8130 | | - if (texture == null) |
---|
8131 | | - texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution); |
---|
| 8440 | + // texturecache = textures.get(texname); // suspicious |
---|
| 8441 | + if (texturecache == null) |
---|
| 8442 | + texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution); |
---|
| 8443 | + else |
---|
| 8444 | + new Exception().printStackTrace(); |
---|
| 8445 | + } else |
---|
| 8446 | + { |
---|
| 8447 | + if (texname.startsWith("@")) |
---|
| 8448 | + { |
---|
| 8449 | + // texturecache = textures.get(texname); // suspicious |
---|
| 8450 | + if (texturecache == null) |
---|
| 8451 | + texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution); |
---|
| 8452 | + else |
---|
| 8453 | + new Exception().printStackTrace(); |
---|
8132 | 8454 | } else |
---|
8133 | 8455 | { |
---|
8134 | 8456 | if (textureon) |
---|
.. | .. |
---|
8153 | 8475 | } |
---|
8154 | 8476 | |
---|
8155 | 8477 | cachename = texname.substring(0, texname.length()-4)+ext+".jpg"; |
---|
8156 | | - if (!new File(cachename).exists()) |
---|
| 8478 | + if (!FileExists(cachename)) |
---|
8157 | 8479 | cachename = texname; |
---|
8158 | 8480 | else |
---|
8159 | 8481 | processbump = false; // don't process bump map again |
---|
.. | .. |
---|
8175 | 8497 | } |
---|
8176 | 8498 | |
---|
8177 | 8499 | cachename = texname.substring(0, texname.length()-4)+ext+".png"; |
---|
8178 | | - if (!new File(cachename).exists()) |
---|
| 8500 | + if (!FileExists(cachename)) |
---|
8179 | 8501 | cachename = texname; |
---|
8180 | 8502 | else |
---|
8181 | 8503 | processbump = false; // don't process bump map again |
---|
.. | .. |
---|
8187 | 8509 | if (texturedata == null) |
---|
8188 | 8510 | throw new Exception(); |
---|
8189 | 8511 | |
---|
8190 | | - texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution); |
---|
| 8512 | + texturecache = new CacheTexture(texturedata,resolution); |
---|
8191 | 8513 | //texture = GetTexture(tex, bump); |
---|
8192 | 8514 | } |
---|
| 8515 | + } |
---|
8193 | 8516 | } |
---|
8194 | 8517 | //} |
---|
8195 | 8518 | } |
---|
8196 | 8519 | |
---|
8197 | | - if (/*CACHETEXTURE &&*/ texture != null && textureon) |
---|
| 8520 | + if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon) |
---|
8198 | 8521 | { |
---|
8199 | 8522 | //return false; |
---|
8200 | 8523 | |
---|
8201 | 8524 | // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")"); |
---|
8202 | | - if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG"))) |
---|
| 8525 | + if (texturedata != null && texname.toLowerCase().endsWith(".jpg")) |
---|
8203 | 8526 | { |
---|
8204 | 8527 | // String ext = "_highres"; |
---|
8205 | 8528 | // if (REDUCETEXTURE) |
---|
.. | .. |
---|
8216 | 8539 | File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg"); |
---|
8217 | 8540 | if (!cachefile.exists()) |
---|
8218 | 8541 | { |
---|
8219 | | - // cache to disk |
---|
8220 | | - Buffer buffer = texturedata.getBuffer(); // getMipmapData(); |
---|
8221 | | - //buffers[0]. |
---|
8222 | | - |
---|
8223 | | - ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer(); |
---|
8224 | | - int[] pixels = new int[bytebuf.capacity()/3]; |
---|
8225 | | - |
---|
8226 | | - // squared size heuristic... |
---|
8227 | | - if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length)) |
---|
| 8542 | + //if (texturedata.getWidth() == texturedata.getHeight()) |
---|
8228 | 8543 | { |
---|
8229 | | - for (int i=pixels.length; --i>=0;) |
---|
8230 | | - { |
---|
8231 | | - int i3 = i*3; |
---|
8232 | | - pixels[i] = 0xFF; |
---|
8233 | | - pixels[i] <<= 8; |
---|
8234 | | - pixels[i] |= bytebuf.get(i3+2) & 0xFF; |
---|
8235 | | - pixels[i] <<= 8; |
---|
8236 | | - pixels[i] |= bytebuf.get(i3+1) & 0xFF; |
---|
8237 | | - pixels[i] <<= 8; |
---|
8238 | | - pixels[i] |= bytebuf.get(i3) & 0xFF; |
---|
8239 | | - } |
---|
8240 | | - |
---|
8241 | | - /* |
---|
8242 | | - int r=0,g=0,b=0,a=0; |
---|
8243 | | - for (int i=0; i<width; i++) |
---|
8244 | | - for (int j=0; j<height; j++) |
---|
8245 | | - { |
---|
8246 | | - int index = j*width+i; |
---|
8247 | | - int p = pixels[index]; |
---|
8248 | | - a = ((p>>24) & 0xFF); |
---|
8249 | | - r = ((p>>16) & 0xFF); |
---|
8250 | | - g = ((p>>8) & 0xFF); |
---|
8251 | | - b = (p & 0xFF); |
---|
8252 | | - pixels[index] = (a<<24) | (b<<16) | (g<<8) | r; |
---|
8253 | | - } |
---|
8254 | | - /**/ |
---|
8255 | | - int width = (int)Math.sqrt(pixels.length); // squared |
---|
8256 | | - int height = width; |
---|
8257 | | - BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile); |
---|
8258 | | - rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width); |
---|
| 8544 | + BufferedImage rendImage = CreateBim(texturedata); |
---|
| 8545 | + |
---|
8259 | 8546 | ImageWriter writer = null; |
---|
8260 | 8547 | Iterator iter = ImageIO.getImageWritersByFormatName("jpg"); |
---|
8261 | 8548 | if (iter.hasNext()) { |
---|
8262 | 8549 | writer = (ImageWriter)iter.next(); |
---|
8263 | 8550 | } |
---|
8264 | | - float compressionQuality = 0.9f; |
---|
| 8551 | + |
---|
| 8552 | + float compressionQuality = 0.85f; |
---|
8265 | 8553 | try |
---|
8266 | 8554 | { |
---|
8267 | 8555 | ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile); |
---|
.. | .. |
---|
8278 | 8566 | } |
---|
8279 | 8567 | } |
---|
8280 | 8568 | } |
---|
8281 | | - |
---|
| 8569 | + |
---|
| 8570 | + Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment; |
---|
| 8571 | + |
---|
8282 | 8572 | //System.out.println("Texture = " + tex); |
---|
8283 | | - if (textures.containsKey(texname)) |
---|
| 8573 | + if (textures.containsKey(tex)) |
---|
8284 | 8574 | { |
---|
8285 | | - CacheTexture thetex = textures.get(texname); |
---|
| 8575 | + CacheTexture thetex = textures.get(tex); |
---|
8286 | 8576 | thetex.texture.disable(); |
---|
8287 | 8577 | thetex.texture.dispose(); |
---|
8288 | | - textures.remove(texname); |
---|
| 8578 | + textures.remove(tex); |
---|
8289 | 8579 | } |
---|
8290 | 8580 | |
---|
8291 | | - texture.texturedata = texturedata; |
---|
8292 | | - textures.put(texname, texture); |
---|
| 8581 | + //texture.texturedata = texturedata; |
---|
| 8582 | + textures.put(tex, texturecache); |
---|
8293 | 8583 | |
---|
8294 | 8584 | // newtex = true; |
---|
8295 | 8585 | } |
---|
.. | .. |
---|
8305 | 8595 | } |
---|
8306 | 8596 | } |
---|
8307 | 8597 | |
---|
8308 | | - return texture; |
---|
| 8598 | + return texturecache; |
---|
8309 | 8599 | } |
---|
8310 | 8600 | |
---|
8311 | | - com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution) throws Exception |
---|
| 8601 | + static void EmbedTextures(cTexture tex) |
---|
| 8602 | + { |
---|
| 8603 | + if (tex.pigmentdata == null) |
---|
| 8604 | + { |
---|
| 8605 | + //String texname = Object3D.GetPigment(tex); |
---|
| 8606 | + |
---|
| 8607 | + CacheTexture texturecache = texturepigment.get(tex); |
---|
| 8608 | + |
---|
| 8609 | + if (texturecache != null) |
---|
| 8610 | + { |
---|
| 8611 | + tex.pw = texturecache.texturedata.getWidth(); |
---|
| 8612 | + tex.ph = texturecache.texturedata.getHeight(); |
---|
| 8613 | + tex.pigmentdata = //CompressJPEG(CreateBim |
---|
| 8614 | + ((ByteBuffer)texturecache.texturedata.getBuffer()).array() |
---|
| 8615 | + ; |
---|
| 8616 | + //, tex.pw, tex.ph), 0.5f); |
---|
| 8617 | + } |
---|
| 8618 | + } |
---|
| 8619 | + |
---|
| 8620 | + if (tex.bumpdata == null) |
---|
| 8621 | + { |
---|
| 8622 | + //String texname = Object3D.GetBump(tex); |
---|
| 8623 | + |
---|
| 8624 | + CacheTexture texturecache = texturebump.get(tex); |
---|
| 8625 | + |
---|
| 8626 | + if (texturecache != null) |
---|
| 8627 | + { |
---|
| 8628 | + tex.bw = texturecache.texturedata.getWidth(); |
---|
| 8629 | + tex.bh = texturecache.texturedata.getHeight(); |
---|
| 8630 | + tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f); |
---|
| 8631 | + } |
---|
| 8632 | + } |
---|
| 8633 | + } |
---|
| 8634 | + |
---|
| 8635 | + com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8312 | 8636 | { |
---|
8313 | 8637 | CacheTexture texture = GetCacheTexture(tex, bump, resolution); |
---|
8314 | 8638 | |
---|
.. | .. |
---|
8326 | 8650 | return texture!=null?texture.texture:null; |
---|
8327 | 8651 | } |
---|
8328 | 8652 | |
---|
8329 | | - public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution) throws Exception |
---|
| 8653 | + public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8330 | 8654 | { |
---|
8331 | 8655 | CacheTexture texture = GetCacheTexture(tex, bump, resolution); |
---|
8332 | 8656 | |
---|
8333 | 8657 | return texture!=null?texture.texturedata:null; |
---|
8334 | 8658 | } |
---|
8335 | 8659 | |
---|
8336 | | - boolean BindTexture(String tex, boolean bump, int resolution) throws Exception |
---|
| 8660 | + boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8337 | 8661 | { |
---|
8338 | 8662 | if (/*tex == null ||*/ ambientOcclusion ) // || !textureon) |
---|
8339 | 8663 | { |
---|
8340 | 8664 | return false; |
---|
8341 | 8665 | } |
---|
8342 | 8666 | |
---|
8343 | | - boolean newtex = false; |
---|
| 8667 | + //boolean newtex = false; |
---|
8344 | 8668 | |
---|
8345 | 8669 | com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution); |
---|
8346 | 8670 | |
---|
.. | .. |
---|
8372 | 8696 | texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT); |
---|
8373 | 8697 | texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT); |
---|
8374 | 8698 | |
---|
8375 | | - return newtex; |
---|
| 8699 | + return true; // Warning: not used. |
---|
8376 | 8700 | } |
---|
8377 | 8701 | |
---|
| 8702 | + public static byte[] CompressJPEG(BufferedImage image, float quality) |
---|
| 8703 | + { |
---|
| 8704 | + try |
---|
| 8705 | + { |
---|
| 8706 | + ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
---|
| 8707 | + Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg"); |
---|
| 8708 | + ImageWriter writer = writers.next(); |
---|
| 8709 | + |
---|
| 8710 | + ImageWriteParam param = writer.getDefaultWriteParam(); |
---|
| 8711 | + param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); |
---|
| 8712 | + param.setCompressionQuality(quality); |
---|
| 8713 | + |
---|
| 8714 | + ImageOutputStream ios = ImageIO.createImageOutputStream(baos); |
---|
| 8715 | + writer.setOutput(ios); |
---|
| 8716 | + writer.write(null, new IIOImage(image, null, null), param); |
---|
| 8717 | + |
---|
| 8718 | + byte[] data = baos.toByteArray(); |
---|
| 8719 | + writer.dispose(); |
---|
| 8720 | + return data; |
---|
| 8721 | + } |
---|
| 8722 | + catch (Exception e) |
---|
| 8723 | + { |
---|
| 8724 | + e.printStackTrace(); |
---|
| 8725 | + return null; |
---|
| 8726 | + } |
---|
| 8727 | + } |
---|
| 8728 | + |
---|
| 8729 | + public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException |
---|
| 8730 | + { |
---|
| 8731 | + ByteArrayInputStream baos = new ByteArrayInputStream(image); |
---|
| 8732 | + Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg"); |
---|
| 8733 | + ImageReader reader = writers.next(); |
---|
| 8734 | + |
---|
| 8735 | + BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); |
---|
| 8736 | + |
---|
| 8737 | + ImageReadParam param = reader.getDefaultReadParam(); |
---|
| 8738 | + param.setDestination(bim); |
---|
| 8739 | + //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB)); |
---|
| 8740 | + |
---|
| 8741 | + ImageInputStream ios = ImageIO.createImageInputStream(baos); |
---|
| 8742 | + reader.setInput(ios); |
---|
| 8743 | + BufferedImage bim2 = reader.read(0, param); |
---|
| 8744 | + reader.dispose(); |
---|
| 8745 | + |
---|
| 8746 | +// WritableRaster raster = bim2.getRaster(); |
---|
| 8747 | +// DataBufferByte data = (DataBufferByte) raster.getDataBuffer(); |
---|
| 8748 | +// byte[] bytes = data.getData(); |
---|
| 8749 | +// |
---|
| 8750 | +// int[] pixels = new int[bytes.length/3]; |
---|
| 8751 | +// for (int i=pixels.length; --i>=0;) |
---|
| 8752 | +// { |
---|
| 8753 | +// int i3 = i*3; |
---|
| 8754 | +// pixels[i] = 0xFF; |
---|
| 8755 | +// pixels[i] <<= 8; |
---|
| 8756 | +// pixels[i] |= bytes[i3+2] & 0xFF; |
---|
| 8757 | +// pixels[i] <<= 8; |
---|
| 8758 | +// pixels[i] |= bytes[i3+1] & 0xFF; |
---|
| 8759 | +// pixels[i] <<= 8; |
---|
| 8760 | +// pixels[i] |= bytes[i3] & 0xFF; |
---|
| 8761 | +// } |
---|
| 8762 | +// |
---|
| 8763 | +// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w); |
---|
| 8764 | + |
---|
| 8765 | + return bim; |
---|
| 8766 | + } |
---|
| 8767 | + |
---|
8378 | 8768 | ShadowBuffer shadowPBuf; |
---|
8379 | 8769 | AntialiasBuffer antialiasPBuf; |
---|
8380 | 8770 | int MAXSTACK; |
---|
.. | .. |
---|
8391 | 8781 | |
---|
8392 | 8782 | gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0); |
---|
8393 | 8783 | MAXSTACK = temp[0]; |
---|
8394 | | - System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK); |
---|
| 8784 | + if (Globals.DEBUG) |
---|
| 8785 | + System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK); |
---|
8395 | 8786 | gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0); |
---|
8396 | 8787 | MAXSTACK = temp[0]; |
---|
8397 | | - System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK); |
---|
| 8788 | + if (Globals.DEBUG) |
---|
| 8789 | + System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK); |
---|
8398 | 8790 | |
---|
8399 | 8791 | // Use debug pipeline |
---|
8400 | 8792 | //drawable.setGL(new DebugGL(gl)); // |
---|
.. | .. |
---|
8402 | 8794 | gl = drawable.getGL(); // |
---|
8403 | 8795 | |
---|
8404 | 8796 | GL gl3 = getGL(); |
---|
8405 | | - System.out.println("INIT GL IS: " + gl.getClass().getName()); |
---|
| 8797 | + if (Globals.DEBUG) |
---|
| 8798 | + System.out.println("INIT GL IS: " + gl.getClass().getName()); |
---|
8406 | 8799 | |
---|
8407 | 8800 | |
---|
8408 | 8801 | //float pos[] = { 100, 100, 100, 0 }; |
---|
.. | .. |
---|
8567 | 8960 | |
---|
8568 | 8961 | if (cubemap == null) |
---|
8569 | 8962 | { |
---|
8570 | | - LoadEnvy(5); |
---|
| 8963 | + //LoadEnvy(1); |
---|
8571 | 8964 | } |
---|
8572 | 8965 | |
---|
8573 | 8966 | //cubemap.enable(); |
---|
.. | .. |
---|
8843 | 9236 | |
---|
8844 | 9237 | void LoadEnvy(int which) |
---|
8845 | 9238 | { |
---|
| 9239 | + assert(false); |
---|
| 9240 | + |
---|
8846 | 9241 | String name; |
---|
8847 | 9242 | String ext; |
---|
8848 | 9243 | |
---|
.. | .. |
---|
8854 | 9249 | cubemap = null; |
---|
8855 | 9250 | return; |
---|
8856 | 9251 | case 1: |
---|
8857 | | - name = "cubemaps/box_"; |
---|
8858 | | - ext = "png"; |
---|
| 9252 | + name = "cubemaps/rgb/"; |
---|
| 9253 | + ext = "jpg"; |
---|
8859 | 9254 | reverseUP = false; |
---|
8860 | 9255 | break; |
---|
8861 | 9256 | case 2: |
---|
8862 | | - name = "cubemaps/uffizi_"; |
---|
8863 | | - ext = "png"; |
---|
8864 | | - break; // reverseUP = true; break; |
---|
| 9257 | + name = "cubemaps/uffizi/"; |
---|
| 9258 | + ext = "jpg"; |
---|
| 9259 | + reverseUP = false; |
---|
| 9260 | + break; |
---|
8865 | 9261 | case 3: |
---|
8866 | | - name = "cubemaps/CloudyHills_"; |
---|
8867 | | - ext = "tga"; |
---|
| 9262 | + name = "cubemaps/CloudyHills/"; |
---|
| 9263 | + ext = "jpg"; |
---|
8868 | 9264 | reverseUP = false; |
---|
8869 | 9265 | break; |
---|
8870 | 9266 | case 4: |
---|
8871 | | - name = "cubemaps/cornell_"; |
---|
| 9267 | + name = "cubemaps/cornell/"; |
---|
8872 | 9268 | ext = "png"; |
---|
8873 | 9269 | reverseUP = false; |
---|
8874 | 9270 | break; |
---|
| 9271 | + case 5: |
---|
| 9272 | + name = "cubemaps/skycube/"; |
---|
| 9273 | + ext = "jpg"; |
---|
| 9274 | + reverseUP = false; |
---|
| 9275 | + break; |
---|
| 9276 | + case 6: |
---|
| 9277 | + name = "cubemaps/SaintLazarusChurch3/"; |
---|
| 9278 | + ext = "jpg"; |
---|
| 9279 | + reverseUP = false; |
---|
| 9280 | + break; |
---|
| 9281 | + case 7: |
---|
| 9282 | + name = "cubemaps/Sodermalmsallen/"; |
---|
| 9283 | + ext = "jpg"; |
---|
| 9284 | + reverseUP = false; |
---|
| 9285 | + break; |
---|
| 9286 | + case 8: |
---|
| 9287 | + name = "cubemaps/Sodermalmsallen2/"; |
---|
| 9288 | + ext = "jpg"; |
---|
| 9289 | + reverseUP = false; |
---|
| 9290 | + break; |
---|
| 9291 | + case 9: |
---|
| 9292 | + name = "cubemaps/UnionSquare/"; |
---|
| 9293 | + ext = "jpg"; |
---|
| 9294 | + reverseUP = false; |
---|
| 9295 | + break; |
---|
8875 | 9296 | default: |
---|
8876 | | - name = "cubemaps/rgb_"; |
---|
8877 | | - ext = "png"; /*mipmap = true;*/ reverseUP = false; |
---|
| 9297 | + name = "cubemaps/box/"; |
---|
| 9298 | + ext = "png"; /*mipmap = true;*/ |
---|
| 9299 | + reverseUP = false; |
---|
8878 | 9300 | break; |
---|
8879 | 9301 | } |
---|
8880 | | - |
---|
8881 | | - try |
---|
8882 | | - { |
---|
8883 | | - cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap); |
---|
8884 | | - } catch (IOException e) |
---|
8885 | | - { |
---|
8886 | | - throw new RuntimeException(e); |
---|
8887 | | - } |
---|
| 9302 | + |
---|
| 9303 | + LoadSkybox(name, ext, mipmap); |
---|
8888 | 9304 | } |
---|
8889 | 9305 | |
---|
8890 | 9306 | public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) |
---|
.. | .. |
---|
8916 | 9332 | static double[] model = new double[16]; |
---|
8917 | 9333 | double[] camera2light = new double[16]; |
---|
8918 | 9334 | double[] light2camera = new double[16]; |
---|
8919 | | - int newenvy = -1; |
---|
8920 | | - boolean envyoff = true; // false; |
---|
| 9335 | + |
---|
| 9336 | + //int newenvy = -1; |
---|
| 9337 | + //boolean envyoff = false; |
---|
| 9338 | + |
---|
| 9339 | + String loadedskyboxname; |
---|
| 9340 | + |
---|
8921 | 9341 | cVector light0 = new cVector(0, 0, 0); // 1,3,2); |
---|
8922 | 9342 | //float[] light0 = { 0,0,0 }; |
---|
8923 | 9343 | cVector dirlight = new cVector(0, 0, 1); // 1,3,2); |
---|
.. | .. |
---|
9210 | 9630 | jy8[3] = 0.5f; |
---|
9211 | 9631 | } |
---|
9212 | 9632 | |
---|
9213 | | - float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV |
---|
| 9633 | + float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV |
---|
9214 | 9634 | float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation |
---|
9215 | 9635 | float[] options3 = new float[]{1, 1, 1, 0}; // fog color |
---|
9216 | 9636 | float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen |
---|
9217 | 9637 | |
---|
| 9638 | + void ResetOptions() |
---|
| 9639 | + { |
---|
| 9640 | + options1[0] = 100; |
---|
| 9641 | + options1[1] = 0.025f; |
---|
| 9642 | + options1[2] = 0.01f; |
---|
| 9643 | + options1[3] = 0; |
---|
| 9644 | + options1[4] = 0; |
---|
| 9645 | + |
---|
| 9646 | + options2[0] = 0; |
---|
| 9647 | + options2[1] = 0.75f; |
---|
| 9648 | + options2[2] = 0; |
---|
| 9649 | + options2[3] = 0; |
---|
| 9650 | + |
---|
| 9651 | + options3[0] = 1; |
---|
| 9652 | + options3[1] = 1; |
---|
| 9653 | + options3[2] = 1; |
---|
| 9654 | + options3[3] = 0; |
---|
| 9655 | + |
---|
| 9656 | + options4[0] = 1; |
---|
| 9657 | + options4[1] = 0; |
---|
| 9658 | + options4[2] = 1; |
---|
| 9659 | + options4[3] = 0; |
---|
| 9660 | + } |
---|
| 9661 | + |
---|
9218 | 9662 | static int imagecount = 0; // movie generation |
---|
9219 | 9663 | |
---|
9220 | 9664 | static int jitter = 0; |
---|
.. | .. |
---|
9310 | 9754 | assert (parentcam != renderCamera); |
---|
9311 | 9755 | |
---|
9312 | 9756 | if (renderCamera != lightCamera) |
---|
9313 | | - for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
9314 | | - LA.matConcat(matrix, parentcam.toParent, matrix); |
---|
| 9757 | + //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
| 9758 | + LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix); |
---|
9315 | 9759 | |
---|
9316 | 9760 | // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix); |
---|
9317 | 9761 | |
---|
.. | .. |
---|
9326 | 9770 | LA.matCopy(renderCamera.fromScreen, matrix); |
---|
9327 | 9771 | |
---|
9328 | 9772 | if (renderCamera != lightCamera) |
---|
9329 | | - for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
9330 | | - LA.matConcat(parentcam.fromParent, matrix, matrix); |
---|
| 9773 | + //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
| 9774 | + LA.matConcat(parentcam.GlobalTransform(), matrix, matrix); |
---|
9331 | 9775 | |
---|
9332 | 9776 | // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix); |
---|
9333 | 9777 | |
---|
.. | .. |
---|
9373 | 9817 | rati = 1 / rati; |
---|
9374 | 9818 | gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000); |
---|
9375 | 9819 | } |
---|
9376 | | - assert (newenvy == -1); |
---|
| 9820 | + |
---|
| 9821 | + //assert (newenvy == -1); |
---|
| 9822 | + |
---|
9377 | 9823 | gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
9378 | 9824 | gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB); |
---|
9379 | | - DrawSkyBox(gl); |
---|
| 9825 | + DrawSkyBox(gl, (float)rati); |
---|
9380 | 9826 | gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
9381 | 9827 | gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB); |
---|
9382 | 9828 | accPerspective(gl, renderCamera.shaper_fovy / ratio, |
---|
.. | .. |
---|
10325 | 10771 | ANTIALIAS = 0; |
---|
10326 | 10772 | //System.out.println("RESTART"); |
---|
10327 | 10773 | AAtimer.restart(); |
---|
| 10774 | + Globals.TIMERRUNNING = true; |
---|
10328 | 10775 | } |
---|
10329 | 10776 | } |
---|
10330 | 10777 | } |
---|
.. | .. |
---|
10392 | 10839 | ambientOcclusion = false; |
---|
10393 | 10840 | } |
---|
10394 | 10841 | |
---|
10395 | | - if (Globals.lighttouched && DrawMode() == DEFAULT && !lightMode) // && !FROZEN) |
---|
| 10842 | + if (//Globals.lighttouched && |
---|
| 10843 | + DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN) |
---|
10396 | 10844 | { |
---|
10397 | 10845 | //if (RENDERSHADOW) // ? |
---|
10398 | 10846 | if (!IsFrozen()) |
---|
10399 | 10847 | { |
---|
10400 | 10848 | // dec 2012 |
---|
10401 | | - if (!ambientOcclusion && !(!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0)) |
---|
| 10849 | + if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0)) |
---|
10402 | 10850 | { |
---|
10403 | 10851 | Globals.framecount++; |
---|
10404 | 10852 | shadowbuffer.display(); |
---|
.. | .. |
---|
10411 | 10859 | |
---|
10412 | 10860 | if (wait) |
---|
10413 | 10861 | { |
---|
10414 | | - Sleep(500); |
---|
| 10862 | + Sleep(200); // blocks everything |
---|
10415 | 10863 | |
---|
10416 | 10864 | wait = false; |
---|
10417 | 10865 | } |
---|
.. | .. |
---|
10525 | 10973 | |
---|
10526 | 10974 | // if (parentcam != renderCamera) // not a light |
---|
10527 | 10975 | if (cam != lightCamera) |
---|
10528 | | - for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
10529 | | - LA.matConcat(matrix, parentcam.toParent, matrix); |
---|
| 10976 | + //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
| 10977 | + LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix); |
---|
10530 | 10978 | |
---|
10531 | 10979 | for (int j = 0; j < 4; j++) |
---|
10532 | 10980 | { |
---|
.. | .. |
---|
10540 | 10988 | |
---|
10541 | 10989 | // if (parentcam != renderCamera) // not a light |
---|
10542 | 10990 | if (cam != lightCamera) |
---|
10543 | | - for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
10544 | | - LA.matConcat(parentcam.fromParent, matrix, matrix); |
---|
| 10991 | + //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
| 10992 | + LA.matConcat(parentcam.GlobalTransform(), matrix, matrix); |
---|
10545 | 10993 | |
---|
10546 | 10994 | //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix); |
---|
10547 | 10995 | |
---|
.. | .. |
---|
10627 | 11075 | gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000); |
---|
10628 | 11076 | } |
---|
10629 | 11077 | |
---|
10630 | | - if (newenvy > -1) |
---|
| 11078 | +// if (newenvy > -1) |
---|
| 11079 | +// { |
---|
| 11080 | +// LoadEnvy(newenvy); |
---|
| 11081 | +// } |
---|
| 11082 | +// |
---|
| 11083 | +// newenvy = -1; |
---|
| 11084 | + |
---|
| 11085 | + if (object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb")) |
---|
10631 | 11086 | { |
---|
10632 | | - LoadEnvy(newenvy); |
---|
| 11087 | + if (cubemaprgb == null) |
---|
| 11088 | + { |
---|
| 11089 | + cubemaprgb = LoadSkybox(object.skyboxname + "/", object.skyboxext, false); |
---|
| 11090 | + } |
---|
| 11091 | + |
---|
| 11092 | + cubemap = cubemaprgb; |
---|
10633 | 11093 | } |
---|
10634 | | - |
---|
10635 | | - newenvy = -1; |
---|
10636 | | - |
---|
| 11094 | + else |
---|
| 11095 | + { |
---|
| 11096 | + if (object.skyboxname != null) |
---|
| 11097 | + { |
---|
| 11098 | + if (!object.skyboxname.equals(this.loadedskyboxname)) |
---|
| 11099 | + { |
---|
| 11100 | + cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false); |
---|
| 11101 | + loadedskyboxname = object.skyboxname; |
---|
| 11102 | + } |
---|
| 11103 | + } |
---|
| 11104 | + else |
---|
| 11105 | + { |
---|
| 11106 | + cubemapcustom = null; |
---|
| 11107 | + loadedskyboxname = null; |
---|
| 11108 | + } |
---|
| 11109 | + |
---|
| 11110 | + cubemap = cubemapcustom; |
---|
| 11111 | + } |
---|
| 11112 | + |
---|
10637 | 11113 | ratio = ((double) getWidth()) / getHeight(); |
---|
10638 | 11114 | //System.out.println("ratio = " + ratio); |
---|
10639 | 11115 | |
---|
.. | .. |
---|
10649 | 11125 | |
---|
10650 | 11126 | if (!IsFrozen() && !ambientOcclusion) |
---|
10651 | 11127 | { |
---|
10652 | | - DrawSkyBox(gl); |
---|
| 11128 | + DrawSkyBox(gl, (float)ratio); |
---|
10653 | 11129 | } |
---|
10654 | 11130 | |
---|
10655 | 11131 | //if (selection_view == -1) |
---|
.. | .. |
---|
10832 | 11308 | |
---|
10833 | 11309 | gl.glMatrixMode(GL.GL_MODELVIEW); |
---|
10834 | 11310 | |
---|
10835 | | -//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST); |
---|
10836 | | -//gl.glEnable(gl.GL_POLYGON_SMOOTH); |
---|
10837 | | -//gl.glEnable(gl.GL_MULTISAMPLE); |
---|
| 11311 | +gl.glEnable(gl.GL_POLYGON_SMOOTH); |
---|
| 11312 | +gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST); |
---|
| 11313 | +gl.glEnable(gl.GL_MULTISAMPLE); |
---|
10838 | 11314 | } else |
---|
10839 | 11315 | { |
---|
10840 | 11316 | //gl.glDisable(GL.GL_TEXTURE_2D); |
---|
.. | .. |
---|
10845 | 11321 | //System.out.println("BLENDING ON"); |
---|
10846 | 11322 | gl.glEnable(GL.GL_BLEND); |
---|
10847 | 11323 | gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); |
---|
10848 | | - |
---|
| 11324 | +// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE); |
---|
10849 | 11325 | gl.glMatrixMode(gl.GL_PROJECTION); |
---|
10850 | 11326 | gl.glLoadIdentity(); |
---|
10851 | 11327 | |
---|
.. | .. |
---|
10934 | 11410 | System.err.println("parentcam != renderCamera"); |
---|
10935 | 11411 | |
---|
10936 | 11412 | // if (cam != lightCamera) |
---|
10937 | | - for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
10938 | | - LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013 |
---|
| 11413 | + //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
| 11414 | + LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013 |
---|
10939 | 11415 | } |
---|
10940 | 11416 | |
---|
10941 | 11417 | LA.xformDir(lightposition, cam.toScreen, lightposition); |
---|
.. | .. |
---|
10956 | 11432 | if (true) // TODO |
---|
10957 | 11433 | { |
---|
10958 | 11434 | if (cam != lightCamera) |
---|
10959 | | - for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
10960 | | - LA.xformDir(light0, parentcam.toParent, light0); // may 2013 |
---|
| 11435 | + //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
| 11436 | + LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013 |
---|
10961 | 11437 | } |
---|
10962 | 11438 | |
---|
10963 | 11439 | LA.xformPos(light0, cam.toScreen, light0); |
---|
.. | .. |
---|
11094 | 11570 | } |
---|
11095 | 11571 | } |
---|
11096 | 11572 | |
---|
11097 | | - if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion) |
---|
| 11573 | + if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion) |
---|
11098 | 11574 | { |
---|
11099 | 11575 | //gl.glDepthFunc(GL.GL_LEQUAL); |
---|
11100 | 11576 | //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT); |
---|
.. | .. |
---|
11102 | 11578 | |
---|
11103 | 11579 | boolean texon = textureon; |
---|
11104 | 11580 | |
---|
11105 | | - if (RENDERPROGRAM > 0) |
---|
11106 | | - { |
---|
11107 | | - gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
11108 | | - textureon = false; |
---|
11109 | | - } |
---|
| 11581 | + gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
| 11582 | + textureon = false; |
---|
| 11583 | + |
---|
11110 | 11584 | //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB); |
---|
11111 | 11585 | //System.out.println("ALLO"); |
---|
11112 | 11586 | gl.glColorMask(false, false, false, false); |
---|
11113 | 11587 | DrawObject(gl); |
---|
11114 | | - if (RENDERPROGRAM > 0) |
---|
11115 | | - { |
---|
11116 | | - gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
11117 | | - textureon = texon; |
---|
11118 | | - } |
---|
| 11588 | + |
---|
| 11589 | + gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
| 11590 | + textureon = texon; |
---|
| 11591 | + |
---|
11119 | 11592 | gl.glColorMask(true, true, true, true); |
---|
11120 | 11593 | |
---|
11121 | 11594 | gl.glDepthFunc(GL.GL_EQUAL); |
---|
11122 | | - //gl.glDepthMask(false); |
---|
| 11595 | + gl.glDepthMask(false); |
---|
11123 | 11596 | } |
---|
11124 | 11597 | |
---|
11125 | 11598 | if (false) // DrawMode() == SHADOW) |
---|
.. | .. |
---|
11302 | 11775 | |
---|
11303 | 11776 | static boolean zoomonce = false; |
---|
11304 | 11777 | |
---|
| 11778 | + static void CreateSelectedPoint() |
---|
| 11779 | + { |
---|
| 11780 | + if (selectedpoint == null) |
---|
| 11781 | + { |
---|
| 11782 | + debugpointG = new Sphere(); |
---|
| 11783 | + debugpointP = new Sphere(); |
---|
| 11784 | + debugpointC = new Sphere(); |
---|
| 11785 | + debugpointR = new Sphere(); |
---|
| 11786 | + |
---|
| 11787 | + selectedpoint = new Superellipsoid(); |
---|
| 11788 | + |
---|
| 11789 | + for (int i=0; i<8; i++) |
---|
| 11790 | + { |
---|
| 11791 | + debugpoints[i] = new Sphere(); |
---|
| 11792 | + } |
---|
| 11793 | + } |
---|
| 11794 | + } |
---|
| 11795 | + |
---|
11305 | 11796 | void DrawObject(GL gl, boolean draw) |
---|
11306 | 11797 | { |
---|
| 11798 | + // To clear camera values |
---|
| 11799 | + ResetOptions(); |
---|
| 11800 | + |
---|
11307 | 11801 | //System.out.println("DRAW OBJECT " + mouseDown); |
---|
11308 | 11802 | // DrawMode() = SELECTION; |
---|
11309 | 11803 | //GL gl = getGL(); |
---|
11310 | 11804 | if ((TRACK || SHADOWTRACK) || zoomonce) |
---|
11311 | 11805 | { |
---|
11312 | 11806 | if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode) |
---|
11313 | | - object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK); |
---|
| 11807 | + object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK); |
---|
11314 | 11808 | pingthread.StepToTarget(true); // true); |
---|
11315 | 11809 | // zoomonce = false; |
---|
11316 | 11810 | } |
---|
.. | .. |
---|
11382 | 11876 | |
---|
11383 | 11877 | if (DrawMode() == DEFAULT) |
---|
11384 | 11878 | { |
---|
11385 | | - if (DEBUG) |
---|
| 11879 | + if (Globals.DEBUG) |
---|
11386 | 11880 | { |
---|
| 11881 | + CreateSelectedPoint(); |
---|
11387 | 11882 | float radius = 0.05f; |
---|
11388 | 11883 | if (selectedpoint.radius != radius) |
---|
11389 | 11884 | { |
---|
.. | .. |
---|
11437 | 11932 | ReleaseTextures(DEFAULT_TEXTURES); |
---|
11438 | 11933 | |
---|
11439 | 11934 | if (CLEANCACHE) |
---|
11440 | | - for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();) |
---|
| 11935 | + for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();) |
---|
11441 | 11936 | { |
---|
11442 | | - String tex = e.nextElement(); |
---|
| 11937 | + cTexture tex = e.nextElement(); |
---|
11443 | 11938 | |
---|
11444 | 11939 | // System.out.println("Texture --------- " + tex); |
---|
11445 | 11940 | |
---|
11446 | | - if (tex.equals("WHITE_NOISE")) |
---|
| 11941 | + if (tex.equals("WHITE_NOISE:")) |
---|
11447 | 11942 | continue; |
---|
11448 | 11943 | |
---|
11449 | | - if (!usedtextures.containsKey(tex)) |
---|
| 11944 | + if (!usedtextures.contains(tex)) |
---|
11450 | 11945 | { |
---|
| 11946 | + CacheTexture gettex = texturepigment.get(tex); |
---|
11451 | 11947 | // System.out.println("DISPOSE +++++++++++++++ " + tex); |
---|
11452 | | - textures.get(tex).texture.dispose(); |
---|
11453 | | - textures.remove(tex); |
---|
| 11948 | + if (gettex != null) |
---|
| 11949 | + { |
---|
| 11950 | + gettex.texture.dispose(); |
---|
| 11951 | + texturepigment.remove(tex); |
---|
| 11952 | + } |
---|
| 11953 | + |
---|
| 11954 | + gettex = texturebump.get(tex); |
---|
| 11955 | + // System.out.println("DISPOSE +++++++++++++++ " + tex); |
---|
| 11956 | + if (gettex != null) |
---|
| 11957 | + { |
---|
| 11958 | + gettex.texture.dispose(); |
---|
| 11959 | + texturebump.remove(tex); |
---|
| 11960 | + } |
---|
11454 | 11961 | } |
---|
11455 | 11962 | } |
---|
11456 | 11963 | } |
---|
.. | .. |
---|
11552 | 12059 | return; |
---|
11553 | 12060 | } |
---|
11554 | 12061 | |
---|
11555 | | - String string = obj.GetToolTip(); |
---|
| 12062 | + String string = obj.toString(); //.GetToolTip(); |
---|
11556 | 12063 | |
---|
11557 | 12064 | GL gl = GetGL(); |
---|
11558 | 12065 | |
---|
.. | .. |
---|
11869 | 12376 | //obj.TransformToWorld(light, light); |
---|
11870 | 12377 | for (int i = tp.size(); --i >= 0;) |
---|
11871 | 12378 | { |
---|
11872 | | - for (int count = tp.get(i).GetTransformCount(); --count>=0;) |
---|
11873 | | - LA.xformPos(light, tp.get(i).toParent, light); |
---|
| 12379 | + //for (int count = tp.get(i).GetTransformCount(); --count>=0;) |
---|
| 12380 | + LA.xformPos(light, tp.get(i).GlobalTransformInv(), light); |
---|
11874 | 12381 | } |
---|
11875 | 12382 | |
---|
11876 | 12383 | |
---|
.. | .. |
---|
11887 | 12394 | parentcam = cameras[0]; |
---|
11888 | 12395 | } |
---|
11889 | 12396 | |
---|
11890 | | - for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
11891 | | - LA.xformPos(light, parentcam.toParent, light); // may 2013 |
---|
| 12397 | + //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
| 12398 | + LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013 |
---|
11892 | 12399 | |
---|
11893 | 12400 | LA.xformPos(light, renderCamera.toScreen, light); |
---|
11894 | 12401 | |
---|
.. | .. |
---|
11978 | 12485 | |
---|
11979 | 12486 | //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0); |
---|
11980 | 12487 | |
---|
11981 | | - String program = |
---|
| 12488 | + String programmin = |
---|
| 12489 | + // Min shader |
---|
11982 | 12490 | "!!ARBfp1.0\n" + |
---|
| 12491 | + "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" + |
---|
| 12492 | + "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" + |
---|
| 12493 | + "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" + |
---|
| 12494 | + "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" + |
---|
| 12495 | + "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" + |
---|
| 12496 | + "PARAM light2cam0 = program.env[10];" + |
---|
| 12497 | + "PARAM light2cam1 = program.env[11];" + |
---|
| 12498 | + "PARAM light2cam2 = program.env[12];" + |
---|
| 12499 | + "TEMP temp;" + |
---|
| 12500 | + "TEMP light;" + |
---|
| 12501 | + "TEMP ndotl;" + |
---|
| 12502 | + "TEMP normal;" + |
---|
| 12503 | + "TEMP depth;" + |
---|
| 12504 | + "TEMP eye;" + |
---|
| 12505 | + "TEMP pos;" + |
---|
| 12506 | + |
---|
| 12507 | + "MAD normal, fragment.color, zero123.z, -zero123.y;" + |
---|
| 12508 | + Normalize("normal") + |
---|
| 12509 | + "MOV light, state.light[0].position;" + |
---|
| 12510 | + "DP3 ndotl.x, light, normal;" + |
---|
| 12511 | + |
---|
| 12512 | + // shadow |
---|
| 12513 | + "MOV pos, fragment.texcoord[1];" + |
---|
| 12514 | + "MOV temp, pos;" + |
---|
| 12515 | + ShadowTextureFetch("depth", "temp", "1") + |
---|
| 12516 | + //"TEX depth, fragment.texcoord[1], texture[1], 2D;" + |
---|
| 12517 | + "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" + |
---|
| 12518 | + |
---|
| 12519 | + // No shadow when out of frustum |
---|
| 12520 | + //"SGE temp.y, depth.z, zero123.y;" + |
---|
| 12521 | + //"LRP temp.x, temp.y, zero123.y, temp.x;" + |
---|
| 12522 | + |
---|
| 12523 | + "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow |
---|
| 12524 | + |
---|
| 12525 | + // Backlit |
---|
| 12526 | + "MOV pos.w, zero123.y;" + |
---|
| 12527 | + "DP4 eye.x, pos, light2cam0;" + |
---|
| 12528 | + "DP4 eye.y, pos, light2cam1;" + |
---|
| 12529 | + "DP4 eye.z, pos, light2cam2;" + |
---|
| 12530 | + Normalize("eye") + |
---|
| 12531 | + |
---|
| 12532 | + "DP3 ndotl.y, -eye, normal;" + |
---|
| 12533 | + //"MUL ndotl.y, ndotl.y, pow2.x;" + |
---|
| 12534 | + "POW ndotl.y, ndotl.y, pow2.z;" + // backlit |
---|
| 12535 | + "SUB ndotl.y, zero123.y, ndotl.y;" + |
---|
| 12536 | + //"SUB ndotl.y, zero123.y, ndotl.y;" + |
---|
| 12537 | + //"MUL ndotl.y, ndotl.y, pow2.z;" + |
---|
| 12538 | + |
---|
| 12539 | + //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient |
---|
| 12540 | + //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient |
---|
| 12541 | + |
---|
| 12542 | + // Pigment |
---|
| 12543 | + "TEX temp, fragment.texcoord[0], texture[0], 2D;" + |
---|
| 12544 | + "LRP temp, zero123.w, temp, one;" + // texture proportion |
---|
| 12545 | + "MUL temp, temp, ndotl.x;" + |
---|
| 12546 | + |
---|
| 12547 | + "MUL temp, temp, zero123.z;" + |
---|
| 12548 | + |
---|
| 12549 | + //"MUL temp, temp, ndotl.y;" + |
---|
| 12550 | + |
---|
| 12551 | + "MOV temp.w, zero123.y;" + // reset alpha |
---|
| 12552 | + "MOV result.color, temp;" + |
---|
| 12553 | + "END"; |
---|
| 12554 | + |
---|
| 12555 | + String programmax = |
---|
| 12556 | + "!!ARBfp1.0\n" + |
---|
| 12557 | + |
---|
11983 | 12558 | //"OPTION ARB_fragment_program_shadow;" + |
---|
11984 | 12559 | "PARAM light2cam0 = program.env[10];" + |
---|
11985 | 12560 | "PARAM light2cam1 = program.env[11];" + |
---|
.. | .. |
---|
12094 | 12669 | "TEMP shininess;" + |
---|
12095 | 12670 | "\n" + |
---|
12096 | 12671 | "MOV texSamp, one;" + |
---|
12097 | | - //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" + |
---|
12098 | | - |
---|
| 12672 | + |
---|
12099 | 12673 | "MOV mapgrid.x, one2048th.x;" + |
---|
12100 | 12674 | "MOV temp, fragment.texcoord[1];" + |
---|
12101 | 12675 | /* |
---|
.. | .. |
---|
12116 | 12690 | "MUL temp, floor, mapgrid.x;" + |
---|
12117 | 12691 | //"TEX depth0, temp, texture[1], 2D;" + |
---|
12118 | 12692 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12119 | | - TextureFetch("depth0", "temp", "1") + |
---|
| 12693 | + ShadowTextureFetch("depth0", "temp", "1") + |
---|
12120 | 12694 | "") + |
---|
12121 | 12695 | "ADD temp.x, temp.x, mapgrid.x;" + |
---|
12122 | 12696 | //"TEX depth1, temp, texture[1], 2D;" + |
---|
12123 | 12697 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12124 | | - TextureFetch("depth1", "temp", "1") + |
---|
| 12698 | + ShadowTextureFetch("depth1", "temp", "1") + |
---|
12125 | 12699 | "") + |
---|
12126 | 12700 | "ADD temp.y, temp.y, mapgrid.x;" + |
---|
12127 | 12701 | //"TEX depth2, temp, texture[1], 2D;" + |
---|
12128 | | - TextureFetch("depth2", "temp", "1") + |
---|
| 12702 | + ShadowTextureFetch("depth2", "temp", "1") + |
---|
12129 | 12703 | "SUB temp.x, temp.x, mapgrid.x;" + |
---|
12130 | 12704 | //"TEX depth3, temp, texture[1], 2D;" + |
---|
12131 | 12705 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12132 | | - TextureFetch("depth3", "temp", "1") + |
---|
| 12706 | + ShadowTextureFetch("depth3", "temp", "1") + |
---|
12133 | 12707 | "") + |
---|
12134 | 12708 | //"MUL texSamp0, texSamp0, state.material.front.diffuse;" + |
---|
12135 | 12709 | //"MOV params, material;" + |
---|
.. | .. |
---|
12500 | 13074 | "MAD shadow.x, buffer.x, frac.y, shadow.x;" + |
---|
12501 | 13075 | "") + |
---|
12502 | 13076 | |
---|
12503 | | - // display shadow only (bump == 0) |
---|
| 13077 | + // display shadow only (fakedepth == 0) |
---|
12504 | 13078 | "SUB temp.x, half.x, shadow.x;" + |
---|
12505 | 13079 | "MOV temp.y, -params5.z;" + // params6.x;" + |
---|
12506 | | - "SLT temp.z, temp.y, -one2048th.x;" + |
---|
| 13080 | + "SLT temp.z, temp.y, -c256i.x;" + |
---|
12507 | 13081 | "SUB temp.y, one.x, temp.z;" + |
---|
12508 | 13082 | "MUL temp.x, temp.x, temp.y;" + |
---|
12509 | 13083 | "KIL temp.x;" + |
---|
.. | .. |
---|
12834 | 13408 | //once = true; |
---|
12835 | 13409 | } |
---|
12836 | 13410 | |
---|
| 13411 | + String program = programmax; |
---|
| 13412 | + |
---|
| 13413 | + if (Globals.MINSHADER) |
---|
| 13414 | + { |
---|
| 13415 | + program = programmin; |
---|
| 13416 | + } |
---|
| 13417 | + |
---|
12837 | 13418 | System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length()); |
---|
12838 | 13419 | System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : "")); |
---|
12839 | 13420 | loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program); |
---|
.. | .. |
---|
12927 | 13508 | return out; |
---|
12928 | 13509 | } |
---|
12929 | 13510 | |
---|
12930 | | - String TextureFetch(String dest, String src, String unit) |
---|
| 13511 | + // Also does frustum culling |
---|
| 13512 | + String ShadowTextureFetch(String dest, String src, String unit) |
---|
12931 | 13513 | { |
---|
12932 | 13514 | return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" + |
---|
12933 | 13515 | "SGE " + src + ".w, " + src + ".x, eps.x;" + |
---|
12934 | 13516 | "SGE " + src + ".z, " + src + ".y, eps.x;" + |
---|
| 13517 | + "SLT " + dest + ".x, " + src + ".x, one.x;" + |
---|
| 13518 | + "SLT " + dest + ".y, " + src + ".y, one.x;" + |
---|
12935 | 13519 | "MUL " + src + ".w, " + src + ".z, " + src + ".w;" + |
---|
12936 | | - "SLT " + src + ".z, " + src + ".x, one.x;" + |
---|
12937 | | - "MUL " + src + ".w, " + src + ".z, " + src + ".w;" + |
---|
12938 | | - "SLT " + src + ".z, " + src + ".y, one.x;" + |
---|
12939 | | - "MUL " + src + ".w, " + src + ".z, " + src + ".w;" + |
---|
| 13520 | + "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" + |
---|
| 13521 | + "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" + |
---|
12940 | 13522 | //"SWZ buffer, temp, w,w,w,w;"; |
---|
12941 | | - "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" + |
---|
| 13523 | + //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" + |
---|
12942 | 13524 | "SUB " + src + ".z, " + "one.x, " + src + ".w;" + |
---|
12943 | 13525 | //"MUL " + src + ".z, " + src + ".z, infinity.x;" + |
---|
12944 | 13526 | //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;"; |
---|
12945 | | - "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
| 13527 | + //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
12946 | 13528 | |
---|
12947 | | - //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;"; |
---|
12948 | | - //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;"; |
---|
| 13529 | + //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;"; |
---|
| 13530 | + "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
12949 | 13531 | } |
---|
12950 | 13532 | |
---|
12951 | 13533 | String Shadow(String depth, String shadow) |
---|
.. | .. |
---|
12992 | 13574 | "SLT temp.x, temp.x, zero.x;" + // shadoweps |
---|
12993 | 13575 | "LRP " + shadow + ", temp.x, one, " + shadow + ";" + |
---|
12994 | 13576 | |
---|
12995 | | - // No shadow when out of frustrum |
---|
| 13577 | + // No shadow when out of frustum |
---|
12996 | 13578 | "SGE temp.x, " + depth + ".z, one.z;" + |
---|
12997 | 13579 | "LRP " + shadow + ", temp.x, one, " + shadow + ";" + |
---|
12998 | 13580 | ""; |
---|
.. | .. |
---|
13140 | 13722 | /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias |
---|
13141 | 13723 | /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough |
---|
13142 | 13724 | /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power |
---|
13143 | | - Object3D.cVector2[] vector2buffer; |
---|
| 13725 | + |
---|
| 13726 | + //Object3D.cVector2[] vector2buffer; |
---|
13144 | 13727 | |
---|
13145 | 13728 | // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea |
---|
13146 | 13729 | // OUT : diff, spec |
---|
.. | .. |
---|
13156 | 13739 | "DP3 " + dest + ".z," + "normals," + "eye;" + |
---|
13157 | 13740 | "MAX " + dest + ".w," + dest + ".z," + "eps.x;" + |
---|
13158 | 13741 | //"MOV " + dest + ".w," + "normal.z;" + |
---|
13159 | | - "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + |
---|
13160 | | - "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" + |
---|
13161 | | - //"MOV " + dest + ".z," + "params2.w;" + |
---|
| 13742 | +// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET |
---|
| 13743 | +// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" + |
---|
| 13744 | + |
---|
| 13745 | + "MOV " + dest + ".z," + "params2.w;" + // EXACT |
---|
13162 | 13746 | "POW " + dest + ".w," + dest + ".w," + dest + ".z;" + |
---|
13163 | 13747 | "RCP " + dest + ".w," + dest + ".w;" + |
---|
13164 | 13748 | //"RSQ " + dest + ".w," + dest + ".w;" + |
---|
.. | .. |
---|
13663 | 14247 | else |
---|
13664 | 14248 | if (evt.getSource() == AAtimer) |
---|
13665 | 14249 | { |
---|
| 14250 | + Globals.TIMERRUNNING = false; |
---|
13666 | 14251 | if (mouseDown) |
---|
13667 | 14252 | { |
---|
13668 | 14253 | //new Exception().printStackTrace(); |
---|
.. | .. |
---|
13722 | 14307 | |
---|
13723 | 14308 | // fev 2014??? |
---|
13724 | 14309 | if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode) |
---|
13725 | | - object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK); |
---|
| 14310 | + object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK); |
---|
13726 | 14311 | pingthread.StepToTarget(true); // true); |
---|
13727 | 14312 | } |
---|
13728 | 14313 | // if (!LIVE) |
---|
.. | .. |
---|
13737 | 14322 | return; |
---|
13738 | 14323 | |
---|
13739 | 14324 | AAtimer.restart(); // |
---|
| 14325 | + Globals.TIMERRUNNING = true; |
---|
13740 | 14326 | |
---|
13741 | 14327 | // waslive = LIVE; |
---|
13742 | 14328 | // LIVE = false; |
---|
.. | .. |
---|
13786 | 14372 | drag = false; |
---|
13787 | 14373 | //System.out.println("Mouse DOWN"); |
---|
13788 | 14374 | editObj = false; |
---|
13789 | | - ClickInfo info = new ClickInfo(); |
---|
13790 | | - info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
13791 | | - info.pane = this; |
---|
13792 | | - info.camera = renderCamera; |
---|
13793 | | - info.x = x; |
---|
13794 | | - info.y = y; |
---|
13795 | | - info.modifiers = modifiersex; |
---|
13796 | | - editObj = object.doEditClick(info, 0); |
---|
| 14375 | + //ClickInfo info = new ClickInfo(); |
---|
| 14376 | + object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
| 14377 | + object.clickInfo.pane = this; |
---|
| 14378 | + object.clickInfo.camera = renderCamera; |
---|
| 14379 | + object.clickInfo.x = x; |
---|
| 14380 | + object.clickInfo.y = y; |
---|
| 14381 | + object.clickInfo.modifiers = modifiersex; |
---|
| 14382 | + editObj = object.doEditClick(//info, |
---|
| 14383 | + 0); |
---|
13797 | 14384 | if (!editObj) |
---|
13798 | 14385 | { |
---|
13799 | 14386 | hasMarquee = true; |
---|
.. | .. |
---|
13809 | 14396 | |
---|
13810 | 14397 | public void mouseDragged(MouseEvent e) |
---|
13811 | 14398 | { |
---|
| 14399 | + Globals.MOUSEDRAGGED = true; |
---|
| 14400 | + |
---|
13812 | 14401 | //System.out.println("mouseDragged: " + e); |
---|
13813 | 14402 | if (isRenderer) |
---|
13814 | 14403 | movingcamera = true; |
---|
| 14404 | + |
---|
13815 | 14405 | //if (drawing) |
---|
13816 | 14406 | //return; |
---|
13817 | 14407 | if ((e.getModifiersEx() & CTRL) != 0 |
---|
.. | .. |
---|
14072 | 14662 | void GoDown(int mod) |
---|
14073 | 14663 | { |
---|
14074 | 14664 | MODIFIERS |= COMMAND; |
---|
14075 | | - /* |
---|
| 14665 | + /**/ |
---|
14076 | 14666 | if((mod&SHIFT) == SHIFT) |
---|
14077 | | - manipCamera.RotatePosition(0, -speed); |
---|
| 14667 | + manipCamera.BackForth(0, -speed*delta, 0); // getWidth()); |
---|
14078 | 14668 | else |
---|
14079 | | - manipCamera.BackForth(0, -speed*delta, getWidth()); |
---|
14080 | | - */ |
---|
| 14669 | + manipCamera.RotatePosition(0, -speed); |
---|
| 14670 | + /**/ |
---|
14081 | 14671 | if ((mod & SHIFT) == SHIFT) |
---|
14082 | 14672 | { |
---|
14083 | 14673 | mouseMode = mouseMode; // VR?? |
---|
.. | .. |
---|
14093 | 14683 | void GoUp(int mod) |
---|
14094 | 14684 | { |
---|
14095 | 14685 | MODIFIERS |= COMMAND; |
---|
14096 | | - /* |
---|
| 14686 | + /**/ |
---|
14097 | 14687 | if((mod&SHIFT) == SHIFT) |
---|
14098 | | - manipCamera.RotatePosition(0, speed); |
---|
| 14688 | + manipCamera.BackForth(0, speed*delta, 0); // getWidth()); |
---|
14099 | 14689 | else |
---|
14100 | | - manipCamera.BackForth(0, speed*delta, getWidth()); |
---|
14101 | | - */ |
---|
| 14690 | + manipCamera.RotatePosition(0, speed); |
---|
| 14691 | + /**/ |
---|
14102 | 14692 | if ((mod & SHIFT) == SHIFT) |
---|
14103 | 14693 | { |
---|
14104 | 14694 | mouseMode = mouseMode; |
---|
.. | .. |
---|
14114 | 14704 | void GoLeft(int mod) |
---|
14115 | 14705 | { |
---|
14116 | 14706 | MODIFIERS |= COMMAND; |
---|
14117 | | - /* |
---|
| 14707 | + /**/ |
---|
14118 | 14708 | if((mod&SHIFT) == SHIFT) |
---|
14119 | | - manipCamera.RotatePosition(speed, 0); |
---|
14120 | | - else |
---|
14121 | 14709 | manipCamera.Translate(speed*delta, 0, getWidth()); |
---|
14122 | | - */ |
---|
| 14710 | + else |
---|
| 14711 | + manipCamera.RotatePosition(speed, 0); |
---|
| 14712 | + /**/ |
---|
14123 | 14713 | if ((mod & SHIFT) == SHIFT) |
---|
14124 | 14714 | { |
---|
14125 | 14715 | mouseMode = mouseMode; |
---|
.. | .. |
---|
14135 | 14725 | void GoRight(int mod) |
---|
14136 | 14726 | { |
---|
14137 | 14727 | MODIFIERS |= COMMAND; |
---|
14138 | | - /* |
---|
| 14728 | + /**/ |
---|
14139 | 14729 | if((mod&SHIFT) == SHIFT) |
---|
14140 | | - manipCamera.RotatePosition(-speed, 0); |
---|
14141 | | - else |
---|
14142 | 14730 | manipCamera.Translate(-speed*delta, 0, getWidth()); |
---|
14143 | | - */ |
---|
| 14731 | + else |
---|
| 14732 | + manipCamera.RotatePosition(-speed, 0); |
---|
| 14733 | + /**/ |
---|
14144 | 14734 | if ((mod & SHIFT) == SHIFT) |
---|
14145 | 14735 | { |
---|
14146 | 14736 | mouseMode = mouseMode; |
---|
.. | .. |
---|
14190 | 14780 | if (editObj) |
---|
14191 | 14781 | { |
---|
14192 | 14782 | drag = true; |
---|
14193 | | - ClickInfo info = new ClickInfo(); |
---|
14194 | | - info.bounds.setBounds(0, 0, |
---|
| 14783 | + //ClickInfo info = new ClickInfo(); |
---|
| 14784 | + object.clickInfo.bounds.setBounds(0, 0, |
---|
14195 | 14785 | (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
14196 | | - info.pane = this; |
---|
14197 | | - info.camera = renderCamera; |
---|
14198 | | - info.x = x; |
---|
14199 | | - info.y = y; |
---|
14200 | | - object.editWindow.copy.doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0); |
---|
| 14786 | + object.clickInfo.pane = this; |
---|
| 14787 | + object.clickInfo.camera = renderCamera; |
---|
| 14788 | + object.clickInfo.x = x; |
---|
| 14789 | + object.clickInfo.y = y; |
---|
| 14790 | + object //.GetWindow().copy |
---|
| 14791 | + .doEditDrag(//info, |
---|
| 14792 | + (modifiers & MouseEvent.BUTTON3_MASK) != 0); |
---|
14201 | 14793 | } else |
---|
14202 | 14794 | { |
---|
14203 | 14795 | if (x < startX) |
---|
.. | .. |
---|
14346 | 14938 | } |
---|
14347 | 14939 | } |
---|
14348 | 14940 | |
---|
| 14941 | +// ClickInfo clickInfo = new ClickInfo(); |
---|
| 14942 | + |
---|
14349 | 14943 | public void mouseMoved(MouseEvent e) |
---|
14350 | 14944 | { |
---|
14351 | 14945 | //System.out.println("mouseMoved: " + e); |
---|
14352 | 14946 | if (isRenderer) |
---|
14353 | 14947 | return; |
---|
14354 | 14948 | |
---|
14355 | | - ClickInfo ci = new ClickInfo(); |
---|
14356 | | - ci.x = e.getX(); |
---|
14357 | | - ci.y = e.getY(); |
---|
14358 | | - ci.modifiers = e.getModifiersEx(); |
---|
14359 | | - ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
14360 | | - ci.pane = this; |
---|
14361 | | - ci.camera = renderCamera; |
---|
| 14949 | + // Mouse cursor feedback |
---|
| 14950 | + object.clickInfo.x = e.getX(); |
---|
| 14951 | + object.clickInfo.y = e.getY(); |
---|
| 14952 | + object.clickInfo.modifiers = e.getModifiersEx(); |
---|
| 14953 | + object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
| 14954 | + object.clickInfo.pane = this; |
---|
| 14955 | + object.clickInfo.camera = renderCamera; |
---|
14362 | 14956 | if (!isRenderer) |
---|
14363 | 14957 | { |
---|
14364 | | - if (object.editWindow.copy.doEditClick(ci, 0)) |
---|
| 14958 | + //ObjEditor editWindow = object.editWindow; |
---|
| 14959 | + //Object3D copy = editWindow.copy; |
---|
| 14960 | + if (object.doEditClick(//clickInfo, |
---|
| 14961 | + 0)) |
---|
14365 | 14962 | { |
---|
14366 | 14963 | setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
---|
14367 | 14964 | } else |
---|
.. | .. |
---|
14373 | 14970 | |
---|
14374 | 14971 | public void mouseReleased(MouseEvent e) |
---|
14375 | 14972 | { |
---|
| 14973 | + Globals.MOUSEDRAGGED = false; |
---|
| 14974 | + |
---|
14376 | 14975 | movingcamera = false; |
---|
14377 | | - X = Y = 0; |
---|
| 14976 | + X = 0; // getBounds().width/2; |
---|
| 14977 | + Y = 0; // getBounds().height/2; |
---|
14378 | 14978 | //System.out.println("mouseReleased: " + e); |
---|
14379 | 14979 | clickEnd(e.getX(), e.getY(), e.getModifiersEx()); |
---|
14380 | 14980 | } |
---|
.. | .. |
---|
14630 | 15230 | // break; |
---|
14631 | 15231 | case 'T': |
---|
14632 | 15232 | CACHETEXTURE ^= true; |
---|
14633 | | - textures.clear(); |
---|
| 15233 | + texturepigment.clear(); |
---|
| 15234 | + texturebump.clear(); |
---|
14634 | 15235 | // repaint(); |
---|
14635 | 15236 | break; |
---|
14636 | 15237 | case 'Y': |
---|
.. | .. |
---|
14715 | 15316 | case 'E' : COMPACT ^= true; |
---|
14716 | 15317 | repaint(); |
---|
14717 | 15318 | break; |
---|
14718 | | - case 'W' : DEBUGHSB ^= true; |
---|
| 15319 | + case 'W' : // Wide Window (fullscreen) |
---|
| 15320 | + //DEBUGHSB ^= true; |
---|
| 15321 | + ObjEditor.theFrame.ToggleFullScreen(); |
---|
14719 | 15322 | repaint(); |
---|
14720 | 15323 | break; |
---|
14721 | 15324 | case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break; |
---|
.. | .. |
---|
14740 | 15343 | RevertCamera(); |
---|
14741 | 15344 | repaint(); |
---|
14742 | 15345 | break; |
---|
14743 | | - case 'L': |
---|
14744 | 15346 | case 'l': |
---|
| 15347 | + //case 'L': |
---|
14745 | 15348 | if (lightMode) |
---|
14746 | 15349 | { |
---|
14747 | 15350 | lightMode = false; |
---|
.. | .. |
---|
14805 | 15408 | OCCLUSION_CULLING ^= true; |
---|
14806 | 15409 | System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING); |
---|
14807 | 15410 | break; |
---|
14808 | | - case '0': envyoff ^= true; repaint(); break; |
---|
| 15411 | + //case '0': envyoff ^= true; repaint(); break; |
---|
14809 | 15412 | case '1': |
---|
14810 | 15413 | case '2': |
---|
14811 | 15414 | case '3': |
---|
14812 | 15415 | case '4': |
---|
14813 | 15416 | case '5': |
---|
14814 | | - newenvy = Character.getNumericValue(key); |
---|
14815 | | - repaint(); |
---|
14816 | | - break; |
---|
14817 | 15417 | case '6': |
---|
14818 | 15418 | case '7': |
---|
14819 | 15419 | case '8': |
---|
14820 | 15420 | case '9': |
---|
14821 | | - BGcolor = (key - '6')/3.f; |
---|
| 15421 | + if (true) // envyoff) |
---|
| 15422 | + { |
---|
| 15423 | + BGcolor = (key - '1')/8.f; |
---|
| 15424 | + } |
---|
| 15425 | + else |
---|
| 15426 | + { |
---|
| 15427 | + //newenvy = Character.getNumericValue(key); |
---|
| 15428 | + } |
---|
14822 | 15429 | repaint(); |
---|
14823 | 15430 | break; |
---|
14824 | 15431 | case '!': |
---|
.. | .. |
---|
14884 | 15491 | case '_': |
---|
14885 | 15492 | kompactbit = 5; |
---|
14886 | 15493 | break; |
---|
14887 | | - case '+': |
---|
14888 | | - kompactbit = 6; |
---|
14889 | | - break; |
---|
| 15494 | +// case '+': |
---|
| 15495 | +// kompactbit = 6; |
---|
| 15496 | +// break; |
---|
14890 | 15497 | case ' ': |
---|
14891 | 15498 | lightMode ^= true; |
---|
14892 | 15499 | Globals.lighttouched = true; |
---|
.. | .. |
---|
14898 | 15505 | case ESC: |
---|
14899 | 15506 | RENDERPROGRAM += 1; |
---|
14900 | 15507 | RENDERPROGRAM %= 3; |
---|
| 15508 | + |
---|
14901 | 15509 | repaint(); |
---|
14902 | 15510 | break; |
---|
14903 | 15511 | case 'Z': |
---|
.. | .. |
---|
14937 | 15545 | case DELETE: |
---|
14938 | 15546 | ClearSelection(); |
---|
14939 | 15547 | break; |
---|
14940 | | - /* |
---|
14941 | 15548 | case '+': |
---|
| 15549 | + |
---|
| 15550 | + /* |
---|
14942 | 15551 | //fontsize += 1; |
---|
14943 | 15552 | bbzoom *= 2; |
---|
14944 | 15553 | repaint(); |
---|
.. | .. |
---|
14955 | 15564 | case '=': |
---|
14956 | 15565 | IncDepth(); |
---|
14957 | 15566 | //fontsize += 1; |
---|
14958 | | - object.editWindow.refreshContents(true); |
---|
| 15567 | + object.GetWindow().refreshContents(true); |
---|
14959 | 15568 | maskbit = 6; |
---|
14960 | 15569 | break; |
---|
14961 | 15570 | case '-': //if (PixelThreshold>1) PixelThreshold /= 2; |
---|
14962 | 15571 | DecDepth(); |
---|
14963 | 15572 | maskbit = 5; |
---|
14964 | 15573 | //if(fontsize > 1) fontsize -= 1; |
---|
14965 | | - if (object.editWindow == null) |
---|
14966 | | - new Exception().printStackTrace(); |
---|
14967 | | - else |
---|
14968 | | - object.editWindow.refreshContents(true); |
---|
| 15574 | +// if (object.editWindow == null) |
---|
| 15575 | +// new Exception().printStackTrace(); |
---|
| 15576 | +// else |
---|
| 15577 | + object.GetWindow().refreshContents(true); |
---|
14969 | 15578 | break; |
---|
14970 | 15579 | case '{': |
---|
14971 | 15580 | manipCamera.shaper_fovy /= 1.1; |
---|
.. | .. |
---|
15189 | 15798 | } |
---|
15190 | 15799 | */ |
---|
15191 | 15800 | |
---|
15192 | | - object.editWindow.EditSelection(); |
---|
| 15801 | + object.GetWindow().EditSelection(false); |
---|
15193 | 15802 | } |
---|
15194 | 15803 | |
---|
15195 | 15804 | void SelectParent() |
---|
.. | .. |
---|
15206 | 15815 | { |
---|
15207 | 15816 | //selectees.remove(i); |
---|
15208 | 15817 | System.out.println("select parent of " + elem); |
---|
15209 | | - group.editWindow.Select(elem.parent.GetTreePath(), first, true); |
---|
| 15818 | + group.GetWindow().Select(elem.parent.GetTreePath(), first, true); |
---|
15210 | 15819 | } else |
---|
15211 | 15820 | { |
---|
15212 | | - group.editWindow.Select(elem.GetTreePath(), first, true); |
---|
| 15821 | + group.GetWindow().Select(elem.GetTreePath(), first, true); |
---|
15213 | 15822 | } |
---|
15214 | 15823 | |
---|
15215 | 15824 | first = false; |
---|
.. | .. |
---|
15251 | 15860 | for (int j = 0; j < group.children.size(); j++) |
---|
15252 | 15861 | { |
---|
15253 | 15862 | elem = (Object3D) group.children.elementAt(j); |
---|
15254 | | - object.editWindow.Select(elem.GetTreePath(), first, true); |
---|
| 15863 | + object.GetWindow().Select(elem.GetTreePath(), first, true); |
---|
15255 | 15864 | first = false; |
---|
15256 | 15865 | } |
---|
15257 | 15866 | } else |
---|
15258 | 15867 | { |
---|
15259 | | - object.editWindow.Select(elem.GetTreePath(), first, true); |
---|
| 15868 | + object.GetWindow().Select(elem.GetTreePath(), first, true); |
---|
15260 | 15869 | } |
---|
15261 | 15870 | |
---|
15262 | 15871 | first = false; |
---|
.. | .. |
---|
15267 | 15876 | { |
---|
15268 | 15877 | //Composite group = (Composite) object; |
---|
15269 | 15878 | Object3D group = object; |
---|
15270 | | - group.editWindow.loadClipboard(true); // ClearSelection(false); |
---|
| 15879 | + group.GetWindow().loadClipboard(true); // ClearSelection(false); |
---|
15271 | 15880 | } |
---|
15272 | 15881 | |
---|
15273 | 15882 | void ResetTransform(int mask) |
---|
15274 | 15883 | { |
---|
15275 | 15884 | //Composite group = (Composite) object; |
---|
15276 | 15885 | Object3D group = object; |
---|
15277 | | - group.editWindow.ResetTransform(mask); |
---|
| 15886 | + group.GetWindow().ResetTransform(mask); |
---|
15278 | 15887 | } |
---|
15279 | 15888 | |
---|
15280 | 15889 | void FlipTransform() |
---|
15281 | 15890 | { |
---|
15282 | 15891 | //Composite group = (Composite) object; |
---|
15283 | 15892 | Object3D group = object; |
---|
15284 | | - group.editWindow.FlipTransform(); |
---|
| 15893 | + group.GetWindow().FlipTransform(); |
---|
15285 | 15894 | // group.editWindow.ReduceMesh(true); |
---|
15286 | 15895 | } |
---|
15287 | 15896 | |
---|
.. | .. |
---|
15289 | 15898 | { |
---|
15290 | 15899 | //Composite group = (Composite) object; |
---|
15291 | 15900 | Object3D group = object; |
---|
15292 | | - group.editWindow.PrintMemory(); |
---|
| 15901 | + group.GetWindow().PrintMemory(); |
---|
15293 | 15902 | // group.editWindow.ReduceMesh(true); |
---|
15294 | 15903 | } |
---|
15295 | 15904 | |
---|
.. | .. |
---|
15297 | 15906 | { |
---|
15298 | 15907 | //Composite group = (Composite) object; |
---|
15299 | 15908 | Object3D group = object; |
---|
15300 | | - group.editWindow.ResetCentroid(); |
---|
| 15909 | + group.GetWindow().ResetCentroid(); |
---|
15301 | 15910 | } |
---|
15302 | 15911 | |
---|
15303 | 15912 | void IncDepth() |
---|
.. | .. |
---|
15379 | 15988 | |
---|
15380 | 15989 | int width = getBounds().width; |
---|
15381 | 15990 | int height = getBounds().height; |
---|
15382 | | - ClickInfo info = new ClickInfo(); |
---|
15383 | | - info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom)); |
---|
15384 | 15991 | //Image img = CreateImage(width, height); |
---|
15385 | 15992 | //System.out.println("width = " + width + "; height = " + height + "\n"); |
---|
15386 | 15993 | |
---|
.. | .. |
---|
15457 | 16064 | } |
---|
15458 | 16065 | if (object != null && !hasMarquee) |
---|
15459 | 16066 | { |
---|
| 16067 | + if (object.clickInfo == null) |
---|
| 16068 | + object.clickInfo = new ClickInfo(); |
---|
| 16069 | + ClickInfo info = object.clickInfo; |
---|
| 16070 | + //ClickInfo info = new ClickInfo(); |
---|
| 16071 | + info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom)); |
---|
| 16072 | + |
---|
15460 | 16073 | if (isRenderer) |
---|
15461 | 16074 | { |
---|
15462 | | - info.flags++; |
---|
| 16075 | + object.clickInfo.flags++; |
---|
15463 | 16076 | double frameAspect = (double) width / (double) height; |
---|
15464 | 16077 | if (frameAspect > renderCamera.aspect) |
---|
15465 | 16078 | { |
---|
15466 | 16079 | int desired = (int) ((double) height * renderCamera.aspect); |
---|
15467 | | - info.bounds.width -= width - desired; |
---|
15468 | | - info.bounds.x += (width - desired) / 2; |
---|
| 16080 | + object.clickInfo.bounds.width -= width - desired; |
---|
| 16081 | + object.clickInfo.bounds.x += (width - desired) / 2; |
---|
15469 | 16082 | } else |
---|
15470 | 16083 | { |
---|
15471 | 16084 | int desired = (int) ((double) width / renderCamera.aspect); |
---|
15472 | | - info.bounds.height -= height - desired; |
---|
15473 | | - info.bounds.y += (height - desired) / 2; |
---|
| 16085 | + object.clickInfo.bounds.height -= height - desired; |
---|
| 16086 | + object.clickInfo.bounds.y += (height - desired) / 2; |
---|
15474 | 16087 | } |
---|
15475 | 16088 | } |
---|
15476 | | - info.g = gr; |
---|
15477 | | - info.camera = renderCamera; |
---|
| 16089 | + |
---|
| 16090 | + object.clickInfo.g = gr; |
---|
| 16091 | + object.clickInfo.camera = renderCamera; |
---|
15478 | 16092 | /* |
---|
15479 | 16093 | // Memory intensive (brep.verticescopy) |
---|
15480 | 16094 | if (!(object instanceof Composite)) |
---|
15481 | 16095 | object.draw(info, 0, false); // SLOW : |
---|
15482 | 16096 | */ |
---|
15483 | | - if (!isRenderer) |
---|
| 16097 | + if (!isRenderer) // && drag) |
---|
15484 | 16098 | { |
---|
15485 | | - object.drawEditHandles(info, 0); |
---|
15486 | | - |
---|
15487 | | - if (drag && (X != 0 || Y != 0) && object.selection.Size() > 0) |
---|
| 16099 | + Grafreed.Assert(object != null); |
---|
| 16100 | + Grafreed.Assert(object.selection != null); |
---|
| 16101 | + if (object.selection.Size() > 0) |
---|
15488 | 16102 | { |
---|
15489 | | - switch (object.selection.get(0).hitSomething) |
---|
| 16103 | + int hitSomething = object.selection.get(0).hitSomething; |
---|
| 16104 | + |
---|
| 16105 | + object.clickInfo.DX = 0; |
---|
| 16106 | + object.clickInfo.DY = 0; |
---|
| 16107 | + object.clickInfo.W = 1; |
---|
| 16108 | + if (hitSomething == Object3D.hitCenter) |
---|
15490 | 16109 | { |
---|
15491 | | - case Object3D.hitCenter: gr.setColor(Color.pink); break; |
---|
15492 | | - case Object3D.hitRotate: gr.setColor(Color.green); break; |
---|
15493 | | - case Object3D.hitScale: gr.setColor(Color.cyan); break; |
---|
| 16110 | + info.DX = X; |
---|
| 16111 | + if (X != 0) |
---|
| 16112 | + info.DX -= info.bounds.width/2; |
---|
| 16113 | + |
---|
| 16114 | + info.DY = Y; |
---|
| 16115 | + if (Y != 0) |
---|
| 16116 | + info.DY -= info.bounds.height/2; |
---|
15494 | 16117 | } |
---|
15495 | | - |
---|
15496 | | - gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
| 16118 | + |
---|
| 16119 | + object.drawEditHandles(//info, |
---|
| 16120 | + 0); |
---|
| 16121 | + |
---|
| 16122 | + if (drag && (X != 0 || Y != 0)) |
---|
| 16123 | + { |
---|
| 16124 | + switch (hitSomething) |
---|
| 16125 | + { |
---|
| 16126 | + case Object3D.hitCenter: gr.setColor(Color.pink); |
---|
| 16127 | + gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
| 16128 | + break; |
---|
| 16129 | + case Object3D.hitRotate: gr.setColor(Color.yellow); |
---|
| 16130 | + gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
| 16131 | + break; |
---|
| 16132 | + case Object3D.hitScale: gr.setColor(Color.cyan); |
---|
| 16133 | + gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
| 16134 | + break; |
---|
| 16135 | + } |
---|
| 16136 | + |
---|
| 16137 | + } |
---|
15497 | 16138 | } |
---|
15498 | 16139 | } |
---|
15499 | 16140 | } |
---|
.. | .. |
---|
15911 | 16552 | Object3D object; |
---|
15912 | 16553 | static Object3D trackedobject; |
---|
15913 | 16554 | Camera renderCamera; // Light or Eye (or Occlusion) |
---|
15914 | | - /*static*/ Camera manipCamera; // Light or Eye |
---|
| 16555 | + /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light |
---|
15915 | 16556 | /*static*/ Camera eyeCamera; |
---|
15916 | 16557 | /*static*/ Camera lightCamera; |
---|
15917 | 16558 | int cameracount; |
---|
.. | .. |
---|
15975 | 16616 | private /*static*/ boolean firstime; |
---|
15976 | 16617 | private /*static*/ cVector newView = new cVector(); |
---|
15977 | 16618 | private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"}; |
---|
| 16619 | + private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"}; |
---|
| 16620 | + private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"}; |
---|
15978 | 16621 | private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X, |
---|
15979 | 16622 | GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X, |
---|
15980 | 16623 | GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y, |
---|
.. | .. |
---|
15987 | 16630 | { |
---|
15988 | 16631 | com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP); |
---|
15989 | 16632 | |
---|
| 16633 | + int usedsuf = 0; |
---|
| 16634 | + |
---|
15990 | 16635 | for (int i = 0; i < suffixes.length; i++) |
---|
15991 | 16636 | { |
---|
15992 | | - String resourceName = basename + suffixes[i] + "." + suffix; |
---|
15993 | | - TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
15994 | | - mipmapped, |
---|
15995 | | - FileUtil.getFileSuffix(resourceName)); |
---|
15996 | | - if (data == null) |
---|
| 16637 | + String[] suffixe = suffixes; |
---|
| 16638 | + String[] fallback = suffixes2; |
---|
| 16639 | + String[] fallfallback = suffixes3; |
---|
| 16640 | + |
---|
| 16641 | + for (int c=usedsuf; --c>=0;) |
---|
15997 | 16642 | { |
---|
15998 | | - throw new IOException("Unable to load texture " + resourceName); |
---|
| 16643 | +// String[] temp = suffixe; |
---|
| 16644 | +// suffixe = fallback; |
---|
| 16645 | +// fallback = fallfallback; |
---|
| 16646 | +// fallfallback = temp; |
---|
15999 | 16647 | } |
---|
| 16648 | + |
---|
| 16649 | + String resourceName = basename + suffixe[i] + "." + suffix; |
---|
| 16650 | + TextureData data; |
---|
| 16651 | + |
---|
| 16652 | + try |
---|
| 16653 | + { |
---|
| 16654 | + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
| 16655 | + mipmapped, |
---|
| 16656 | + FileUtil.getFileSuffix(resourceName)); |
---|
| 16657 | + } |
---|
| 16658 | + catch (Exception e) |
---|
| 16659 | + { |
---|
| 16660 | + try |
---|
| 16661 | + { |
---|
| 16662 | + resourceName = basename + fallback[i] + "." + suffix; |
---|
| 16663 | + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
| 16664 | + mipmapped, |
---|
| 16665 | + FileUtil.getFileSuffix(resourceName)); |
---|
| 16666 | + } |
---|
| 16667 | + catch (Exception e2) |
---|
| 16668 | + { |
---|
| 16669 | + resourceName = basename + fallfallback[i] + "." + suffix; |
---|
| 16670 | + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
| 16671 | + mipmapped, |
---|
| 16672 | + FileUtil.getFileSuffix(resourceName)); |
---|
| 16673 | + } |
---|
| 16674 | + } |
---|
| 16675 | + |
---|
16000 | 16676 | //System.out.println("Target = " + targets[i]); |
---|
16001 | 16677 | cubemap.updateImage(data, targets[i]); |
---|
16002 | 16678 | } |
---|
16003 | 16679 | |
---|
16004 | 16680 | return cubemap; |
---|
16005 | 16681 | } |
---|
| 16682 | + |
---|
16006 | 16683 | int bigsphere = -1; |
---|
16007 | 16684 | |
---|
16008 | 16685 | float BGcolor = 0.5f; |
---|
16009 | 16686 | |
---|
16010 | | - private void DrawSkyBox(GL gl) |
---|
| 16687 | + float ambientLight[] = {1f, 1f, 1f, 1.0f}; |
---|
| 16688 | + |
---|
| 16689 | + private void DrawSkyBox(GL gl, float ratio) |
---|
16011 | 16690 | { |
---|
16012 | | - if (envyoff || cubemap == null) |
---|
| 16691 | + if (//envyoff || |
---|
| 16692 | + WIREFRAME || |
---|
| 16693 | + cubemap == null) |
---|
16013 | 16694 | { |
---|
16014 | 16695 | gl.glClearColor(BGcolor, BGcolor, BGcolor, 1); |
---|
16015 | 16696 | gl.glClear(gl.GL_COLOR_BUFFER_BIT); |
---|
.. | .. |
---|
16024 | 16705 | // Compensates for ExaminerViewer's modification of modelview matrix |
---|
16025 | 16706 | gl.glMatrixMode(GL.GL_MODELVIEW); |
---|
16026 | 16707 | gl.glLoadIdentity(); |
---|
| 16708 | + gl.glScalef(1,ratio,1); |
---|
16027 | 16709 | |
---|
| 16710 | +// colorV[0] = 2; |
---|
| 16711 | +// colorV[1] = 2; |
---|
| 16712 | +// colorV[2] = 2; |
---|
| 16713 | +// colorV[3] = 1; |
---|
| 16714 | +// gl.glDisable(gl.GL_COLOR_MATERIAL); |
---|
| 16715 | +// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0); |
---|
| 16716 | +// |
---|
| 16717 | +// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0); |
---|
| 16718 | + |
---|
16028 | 16719 | //gl.glActiveTexture(GL.GL_TEXTURE1); |
---|
16029 | 16720 | //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP); |
---|
16030 | 16721 | |
---|
.. | .. |
---|
16056 | 16747 | { |
---|
16057 | 16748 | gl.glScalef(1.0f, -1.0f, 1.0f); |
---|
16058 | 16749 | } |
---|
| 16750 | + gl.glScalef(-1.0f, 1.0f, 1.0f); |
---|
16059 | 16751 | gl.glMultMatrixd(viewrot_1, 0); |
---|
16060 | 16752 | gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f); |
---|
16061 | 16753 | //viewer.updateInverseRotation(gl); |
---|
.. | .. |
---|
16196 | 16888 | cStatic.objectstack[materialdepth++] = checker; |
---|
16197 | 16889 | //System.out.println("material " + material); |
---|
16198 | 16890 | //Applet3D.tracein(this, selected); |
---|
16199 | | - vector2buffer = checker.projectedVertices; |
---|
| 16891 | + //vector2buffer = checker.projectedVertices; |
---|
16200 | 16892 | |
---|
16201 | 16893 | //checker.GetMaterial().Draw(this, false); // true); |
---|
16202 | | - DrawMaterial(checker.GetMaterial(), false); // true); |
---|
| 16894 | + DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true); |
---|
16203 | 16895 | |
---|
16204 | 16896 | materialdepth -= 1; |
---|
16205 | 16897 | if (materialdepth > 0) |
---|
16206 | 16898 | { |
---|
16207 | | - vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices; |
---|
16208 | | - DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]); |
---|
| 16899 | + //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices; |
---|
| 16900 | + DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices); |
---|
16209 | 16901 | } |
---|
16210 | 16902 | //checker.GetMaterial().opacity = 1f; |
---|
16211 | 16903 | ////checker.GetMaterial().ambient = 1f; |
---|
.. | .. |
---|
16291 | 16983 | } |
---|
16292 | 16984 | } |
---|
16293 | 16985 | |
---|
| 16986 | + private Object3D GetFolder() |
---|
| 16987 | + { |
---|
| 16988 | + Object3D folder = object.GetWindow().copy; |
---|
| 16989 | + if (object.GetWindow().copy.selection.Size() > 0) |
---|
| 16990 | + folder = object.GetWindow().copy.selection.elementAt(0); |
---|
| 16991 | + return folder; |
---|
| 16992 | + } |
---|
| 16993 | + |
---|
16294 | 16994 | class SelectBuffer implements GLEventListener |
---|
16295 | 16995 | { |
---|
16296 | 16996 | |
---|
.. | .. |
---|
16306 | 17006 | //new Exception().printStackTrace(); |
---|
16307 | 17007 | System.out.println("select buffer init"); |
---|
16308 | 17008 | // Use debug pipeline |
---|
16309 | | - drawable.setGL(new DebugGL(drawable.getGL())); |
---|
| 17009 | + //drawable.setGL(new DebugGL(drawable.getGL())); |
---|
16310 | 17010 | |
---|
16311 | 17011 | GL gl = drawable.getGL(); |
---|
16312 | 17012 | |
---|
.. | .. |
---|
16370 | 17070 | |
---|
16371 | 17071 | //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL); |
---|
16372 | 17072 | |
---|
| 17073 | + if (PAINTMODE) |
---|
| 17074 | + { |
---|
| 17075 | + if (object.GetWindow().copy.selection.Size() > 0) |
---|
| 17076 | + { |
---|
| 17077 | + Object3D paintobj = object.GetWindow().copy.selection.elementAt(0); |
---|
| 17078 | + |
---|
| 17079 | + // Make what you paint not selectable. |
---|
| 17080 | + paintobj.ResetSelectable(); |
---|
| 17081 | + } |
---|
| 17082 | + } |
---|
| 17083 | + |
---|
16373 | 17084 | //int tmp = selection_view; |
---|
16374 | 17085 | //selection_view = -1; |
---|
16375 | 17086 | int temp = DrawMode(); |
---|
.. | .. |
---|
16381 | 17092 | // temp = DEFAULT; // patch for selection debug |
---|
16382 | 17093 | Globals.drawMode = temp; // WARNING |
---|
16383 | 17094 | |
---|
| 17095 | + if (PAINTMODE) |
---|
| 17096 | + { |
---|
| 17097 | + if (object.GetWindow().copy.selection.Size() > 0) |
---|
| 17098 | + { |
---|
| 17099 | + Object3D paintobj = object.GetWindow().copy.selection.elementAt(0); |
---|
| 17100 | + |
---|
| 17101 | + // Revert. |
---|
| 17102 | + paintobj.RestoreSelectable(); |
---|
| 17103 | + } |
---|
| 17104 | + } |
---|
| 17105 | + |
---|
16384 | 17106 | //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view); |
---|
16385 | 17107 | |
---|
16386 | 17108 | // trying different ways of getting the depth info over |
---|
.. | .. |
---|
16428 | 17150 | // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]); |
---|
16429 | 17151 | // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]); |
---|
16430 | 17152 | // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]); |
---|
| 17153 | + |
---|
| 17154 | + CreateSelectedPoint(); |
---|
16431 | 17155 | |
---|
16432 | 17156 | // Will fit the mesh !!! |
---|
16433 | 17157 | selectedpoint.toParent[0][0] = 0.0001; |
---|
.. | .. |
---|
16482 | 17206 | } |
---|
16483 | 17207 | |
---|
16484 | 17208 | if (!movingcamera && !PAINTMODE) |
---|
16485 | | - object.editWindow.ScreenFitPoint(); // fev 2014 |
---|
| 17209 | + object.GetWindow().ScreenFitPoint(); // fev 2014 |
---|
16486 | 17210 | |
---|
16487 | | - if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0) |
---|
| 17211 | + if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0) |
---|
16488 | 17212 | { |
---|
16489 | | - Object3D paintobj = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0); |
---|
| 17213 | + //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0); |
---|
16490 | 17214 | |
---|
16491 | | - Object3D group = new Object3D("inst" + paintcount++); |
---|
| 17215 | + if (object.GetWindow().copy.selection.Size() > 0) |
---|
| 17216 | + { |
---|
| 17217 | + Object3D paintobj = object.GetWindow().copy.selection.elementAt(0); |
---|
16492 | 17218 | |
---|
16493 | | - group.CreateMaterial(); // use a void leaf to select instances |
---|
16494 | | - |
---|
16495 | | - group.add(paintobj); // link |
---|
16496 | | - |
---|
16497 | | - object.editWindow.SnapObject(group); |
---|
16498 | | - |
---|
16499 | | - Object3D folder = object.editWindow.copy; |
---|
16500 | | - |
---|
16501 | | - if (object.editWindow.copy.selection.Size() > 0) |
---|
16502 | | - folder = object.editWindow.copy.selection.elementAt(0); |
---|
16503 | | - |
---|
16504 | | - folder.add(group); |
---|
16505 | | - |
---|
16506 | | - object.editWindow.ResetModel(); |
---|
16507 | | - object.editWindow.refreshContents(); |
---|
| 17219 | + Object3D inst = new Object3D("inst" + paintcount++); |
---|
| 17220 | + |
---|
| 17221 | + inst.CreateMaterial(); // use a void leaf to select instances |
---|
| 17222 | + |
---|
| 17223 | + inst.add(paintobj); // link |
---|
| 17224 | + |
---|
| 17225 | + object.GetWindow().SnapObject(inst); |
---|
| 17226 | + |
---|
| 17227 | + Object3D folder = paintFolder; // GetFolder(); |
---|
| 17228 | + |
---|
| 17229 | + folder.add(inst); |
---|
| 17230 | + |
---|
| 17231 | + object.GetWindow().ResetModel(); |
---|
| 17232 | + object.GetWindow().refreshContents(); |
---|
| 17233 | + } |
---|
16508 | 17234 | } |
---|
16509 | 17235 | else |
---|
16510 | 17236 | paintcount = 0; |
---|
.. | .. |
---|
16543 | 17269 | //System.out.println("objects[color] = " + objects[color]); |
---|
16544 | 17270 | //objects[color].Select(); |
---|
16545 | 17271 | indexcount = 0; |
---|
| 17272 | + ObjEditor window = object.GetWindow(); |
---|
| 17273 | + if (window != null && deselect) |
---|
| 17274 | + { |
---|
| 17275 | + window.Select(null, deselect, true); |
---|
| 17276 | + } |
---|
16546 | 17277 | object.Select(color, deselect); |
---|
16547 | 17278 | } |
---|
16548 | 17279 | |
---|
.. | .. |
---|
16821 | 17552 | gl.glFlush(); |
---|
16822 | 17553 | |
---|
16823 | 17554 | /**/ |
---|
16824 | | - gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer); |
---|
| 17555 | + gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer); |
---|
16825 | 17556 | |
---|
16826 | | - float[] pixels = occlusionsizebuffer.array(); |
---|
| 17557 | + float[] depths = occlusiondepthbuffer.array(); |
---|
16827 | 17558 | |
---|
| 17559 | + gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer); |
---|
| 17560 | + |
---|
| 17561 | + int[] pixels = selectsizebuffer.array(); |
---|
| 17562 | + |
---|
16828 | 17563 | double r = 0, g = 0, b = 0; |
---|
16829 | 17564 | |
---|
16830 | 17565 | double count = 0; |
---|
.. | .. |
---|
16835 | 17570 | |
---|
16836 | 17571 | double FACTOR = 1; |
---|
16837 | 17572 | |
---|
16838 | | - for (int i = 0; i < pixels.length; i++) |
---|
| 17573 | + for (int i = 0; i < depths.length; i++) |
---|
16839 | 17574 | { |
---|
16840 | 17575 | int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2; |
---|
16841 | 17576 | int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2; |
---|
.. | .. |
---|
16918 | 17653 | |
---|
16919 | 17654 | double scale = ray.z; // 1; // cos |
---|
16920 | 17655 | |
---|
16921 | | - float depth = pixels[newindex]; |
---|
| 17656 | + float depth = depths[newindex]; |
---|
16922 | 17657 | |
---|
16923 | 17658 | /* |
---|
16924 | 17659 | int newindex2 = (x + 1) * OCCLUSION_SIZE + y; |
---|
.. | .. |
---|
17068 | 17803 | int AAbuffersize = 0; |
---|
17069 | 17804 | |
---|
17070 | 17805 | //double[] selectedpoint = new double[3]; |
---|
17071 | | - static Superellipsoid selectedpoint = new Superellipsoid(); |
---|
| 17806 | + static Superellipsoid selectedpoint; |
---|
17072 | 17807 | static Sphere previousselectedpoint = null; |
---|
17073 | | - static Sphere debugpointG = new Sphere(); |
---|
17074 | | - static Sphere debugpointP = new Sphere(); |
---|
17075 | | - static Sphere debugpointC = new Sphere(); |
---|
17076 | | - static Sphere debugpointR = new Sphere(); |
---|
| 17808 | + static Sphere debugpointG; |
---|
| 17809 | + static Sphere debugpointP; |
---|
| 17810 | + static Sphere debugpointC; |
---|
| 17811 | + static Sphere debugpointR; |
---|
17077 | 17812 | |
---|
17078 | 17813 | static Sphere debugpoints[] = new Sphere[8]; |
---|
17079 | 17814 | |
---|
17080 | | - static |
---|
17081 | | - { |
---|
17082 | | - for (int i=0; i<8; i++) |
---|
17083 | | - { |
---|
17084 | | - debugpoints[i] = new Sphere(); |
---|
17085 | | - } |
---|
17086 | | - } |
---|
17087 | | - |
---|
17088 | 17815 | static void InitPoints(float radius) |
---|
17089 | 17816 | { |
---|
17090 | 17817 | for (int i=0; i<8; i++) |
---|
.. | .. |
---|
17123 | 17850 | static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE); |
---|
17124 | 17851 | static IntBuffer bigAAbuffer; |
---|
17125 | 17852 | static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3); |
---|
17126 | | - static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE); |
---|
| 17853 | + //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE); |
---|
17127 | 17854 | static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE); |
---|
17128 | 17855 | static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE); |
---|
17129 | 17856 | //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); |
---|
17130 | | - static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); |
---|
| 17857 | + static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); |
---|
| 17858 | + |
---|
| 17859 | + static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); |
---|
| 17860 | + |
---|
17131 | 17861 | static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB); |
---|
17132 | 17862 | static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); |
---|
17133 | 17863 | static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>(); |
---|