.. | .. |
---|
150 | 150 | defaultcaps.setAccumAlphaBits(16); |
---|
151 | 151 | } |
---|
152 | 152 | |
---|
| 153 | + private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory(); |
---|
| 154 | + |
---|
153 | 155 | void SetAsGLRenderer(boolean b) |
---|
154 | 156 | { |
---|
155 | 157 | isRenderer = b; |
---|
.. | .. |
---|
462 | 464 | if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0) |
---|
463 | 465 | { |
---|
464 | 466 | //gl.glBegin(gl.GL_TRIANGLES); |
---|
465 | | - boolean hasnorm = pv.norm != null; // && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0); |
---|
| 467 | + boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0); |
---|
466 | 468 | if (!hasnorm) |
---|
467 | 469 | { |
---|
468 | 470 | // System.out.println("FUCK!!"); |
---|
.. | .. |
---|
1888 | 1890 | void PushMatrix(double[][] matrix) |
---|
1889 | 1891 | { |
---|
1890 | 1892 | // GrafreeD.tracein(matrix); |
---|
1891 | | - PushMatrix(matrix,1); |
---|
| 1893 | + PushMatrix(matrix, 1); |
---|
1892 | 1894 | } |
---|
1893 | 1895 | |
---|
1894 | 1896 | void PushMatrix() |
---|
.. | .. |
---|
2265 | 2267 | LOOKAT ^= true; |
---|
2266 | 2268 | } |
---|
2267 | 2269 | |
---|
2268 | | - void ToggleRandom() |
---|
| 2270 | + void ToggleSwitch() |
---|
2269 | 2271 | { |
---|
2270 | 2272 | SWITCH ^= true; |
---|
2271 | 2273 | } |
---|
.. | .. |
---|
2374 | 2376 | { |
---|
2375 | 2377 | return currentGL; |
---|
2376 | 2378 | } |
---|
2377 | | - |
---|
| 2379 | + |
---|
2378 | 2380 | /**/ |
---|
2379 | 2381 | class CacheTexture |
---|
2380 | 2382 | { |
---|
.. | .. |
---|
8067 | 8069 | return; // true; |
---|
8068 | 8070 | } |
---|
8069 | 8071 | |
---|
| 8072 | + java.util.HashSet<String> missingTextures = new java.util.HashSet<String>(); |
---|
| 8073 | + |
---|
| 8074 | + private boolean FileExists(String tex) |
---|
| 8075 | + { |
---|
| 8076 | + if (missingTextures.contains(tex)) |
---|
| 8077 | + { |
---|
| 8078 | + return false; |
---|
| 8079 | + } |
---|
| 8080 | + |
---|
| 8081 | + boolean fileExists = new File(tex).exists(); |
---|
| 8082 | + |
---|
| 8083 | + if (!fileExists) |
---|
| 8084 | + { |
---|
| 8085 | + // If file exists, the "new File()" is not executed sgain |
---|
| 8086 | + missingTextures.add(tex); |
---|
| 8087 | + } |
---|
| 8088 | + |
---|
| 8089 | + return fileExists; |
---|
| 8090 | + } |
---|
| 8091 | + |
---|
8070 | 8092 | CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception |
---|
8071 | 8093 | { |
---|
8072 | 8094 | CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null; |
---|
.. | .. |
---|
8075 | 8097 | { |
---|
8076 | 8098 | String texname = tex; |
---|
8077 | 8099 | |
---|
| 8100 | + String fallbackTextureName = defaultDirectory + "/Textures/" + texname; |
---|
| 8101 | + |
---|
8078 | 8102 | // String[] split = tex.split("Textures"); |
---|
8079 | 8103 | // if (split.length > 1) |
---|
8080 | 8104 | // texname = "/Users/nbriere/Textures" + split[split.length-1]; |
---|
8081 | 8105 | // else |
---|
8082 | 8106 | // if (!texname.startsWith("/")) |
---|
8083 | 8107 | // texname = "/Users/nbriere/Textures/" + texname; |
---|
8084 | | - if (!new File(tex).exists()) |
---|
| 8108 | + if (!FileExists(tex)) |
---|
8085 | 8109 | { |
---|
8086 | | - texname = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory() + "/Textures/" + texname; |
---|
| 8110 | + texname = fallbackTextureName; |
---|
8087 | 8111 | } |
---|
8088 | 8112 | |
---|
8089 | 8113 | if (CACHETEXTURE) |
---|
.. | .. |
---|
8153 | 8177 | } |
---|
8154 | 8178 | |
---|
8155 | 8179 | cachename = texname.substring(0, texname.length()-4)+ext+".jpg"; |
---|
8156 | | - if (!new File(cachename).exists()) |
---|
| 8180 | + if (!FileExists(cachename)) |
---|
8157 | 8181 | cachename = texname; |
---|
8158 | 8182 | else |
---|
8159 | 8183 | processbump = false; // don't process bump map again |
---|
.. | .. |
---|
8175 | 8199 | } |
---|
8176 | 8200 | |
---|
8177 | 8201 | cachename = texname.substring(0, texname.length()-4)+ext+".png"; |
---|
8178 | | - if (!new File(cachename).exists()) |
---|
| 8202 | + if (!FileExists(cachename)) |
---|
8179 | 8203 | cachename = texname; |
---|
8180 | 8204 | else |
---|
8181 | 8205 | processbump = false; // don't process bump map again |
---|
.. | .. |
---|
9310 | 9334 | assert (parentcam != renderCamera); |
---|
9311 | 9335 | |
---|
9312 | 9336 | if (renderCamera != lightCamera) |
---|
9313 | | - for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
9314 | | - LA.matConcat(matrix, parentcam.toParent, matrix); |
---|
| 9337 | + //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
| 9338 | + LA.matConcat(matrix, parentcam.GlobalTransform(), matrix); |
---|
9315 | 9339 | |
---|
9316 | 9340 | // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix); |
---|
9317 | 9341 | |
---|
.. | .. |
---|
9326 | 9350 | LA.matCopy(renderCamera.fromScreen, matrix); |
---|
9327 | 9351 | |
---|
9328 | 9352 | if (renderCamera != lightCamera) |
---|
9329 | | - for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
9330 | | - LA.matConcat(parentcam.fromParent, matrix, matrix); |
---|
| 9353 | + //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
| 9354 | + LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix); |
---|
9331 | 9355 | |
---|
9332 | 9356 | // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix); |
---|
9333 | 9357 | |
---|
.. | .. |
---|
10392 | 10416 | ambientOcclusion = false; |
---|
10393 | 10417 | } |
---|
10394 | 10418 | |
---|
10395 | | - if (Globals.lighttouched && DrawMode() == DEFAULT && !lightMode) // && !FROZEN) |
---|
| 10419 | + if (Globals.lighttouched && DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN) |
---|
10396 | 10420 | { |
---|
10397 | 10421 | //if (RENDERSHADOW) // ? |
---|
10398 | 10422 | if (!IsFrozen()) |
---|
10399 | 10423 | { |
---|
10400 | 10424 | // dec 2012 |
---|
10401 | | - if (!ambientOcclusion && !(!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0)) |
---|
| 10425 | + if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0)) |
---|
10402 | 10426 | { |
---|
10403 | 10427 | Globals.framecount++; |
---|
10404 | 10428 | shadowbuffer.display(); |
---|
.. | .. |
---|
10525 | 10549 | |
---|
10526 | 10550 | // if (parentcam != renderCamera) // not a light |
---|
10527 | 10551 | if (cam != lightCamera) |
---|
10528 | | - for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
10529 | | - LA.matConcat(matrix, parentcam.toParent, matrix); |
---|
| 10552 | + //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
| 10553 | + LA.matConcat(matrix, parentcam.GlobalTransform(), matrix); |
---|
10530 | 10554 | |
---|
10531 | 10555 | for (int j = 0; j < 4; j++) |
---|
10532 | 10556 | { |
---|
.. | .. |
---|
10540 | 10564 | |
---|
10541 | 10565 | // if (parentcam != renderCamera) // not a light |
---|
10542 | 10566 | if (cam != lightCamera) |
---|
10543 | | - for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
10544 | | - LA.matConcat(parentcam.fromParent, matrix, matrix); |
---|
| 10567 | + //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
| 10568 | + LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix); |
---|
10545 | 10569 | |
---|
10546 | 10570 | //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix); |
---|
10547 | 10571 | |
---|
.. | .. |
---|
10934 | 10958 | System.err.println("parentcam != renderCamera"); |
---|
10935 | 10959 | |
---|
10936 | 10960 | // if (cam != lightCamera) |
---|
10937 | | - for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
10938 | | - LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013 |
---|
| 10961 | + //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
| 10962 | + LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013 |
---|
10939 | 10963 | } |
---|
10940 | 10964 | |
---|
10941 | 10965 | LA.xformDir(lightposition, cam.toScreen, lightposition); |
---|
.. | .. |
---|
10956 | 10980 | if (true) // TODO |
---|
10957 | 10981 | { |
---|
10958 | 10982 | if (cam != lightCamera) |
---|
10959 | | - for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
10960 | | - LA.xformDir(light0, parentcam.toParent, light0); // may 2013 |
---|
| 10983 | + //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
| 10984 | + LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013 |
---|
10961 | 10985 | } |
---|
10962 | 10986 | |
---|
10963 | 10987 | LA.xformPos(light0, cam.toScreen, light0); |
---|
.. | .. |
---|
11552 | 11576 | return; |
---|
11553 | 11577 | } |
---|
11554 | 11578 | |
---|
11555 | | - String string = obj.GetToolTip(); |
---|
| 11579 | + String string = obj.toString(); //.GetToolTip(); |
---|
11556 | 11580 | |
---|
11557 | 11581 | GL gl = GetGL(); |
---|
11558 | 11582 | |
---|
.. | .. |
---|
11869 | 11893 | //obj.TransformToWorld(light, light); |
---|
11870 | 11894 | for (int i = tp.size(); --i >= 0;) |
---|
11871 | 11895 | { |
---|
11872 | | - for (int count = tp.get(i).GetTransformCount(); --count>=0;) |
---|
11873 | | - LA.xformPos(light, tp.get(i).toParent, light); |
---|
| 11896 | + //for (int count = tp.get(i).GetTransformCount(); --count>=0;) |
---|
| 11897 | + LA.xformPos(light, tp.get(i).GlobalTransform(), light); |
---|
11874 | 11898 | } |
---|
11875 | 11899 | |
---|
11876 | 11900 | |
---|
.. | .. |
---|
11887 | 11911 | parentcam = cameras[0]; |
---|
11888 | 11912 | } |
---|
11889 | 11913 | |
---|
11890 | | - for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
11891 | | - LA.xformPos(light, parentcam.toParent, light); // may 2013 |
---|
| 11914 | + //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
| 11915 | + LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013 |
---|
11892 | 11916 | |
---|
11893 | 11917 | LA.xformPos(light, renderCamera.toScreen, light); |
---|
11894 | 11918 | |
---|
.. | .. |
---|
12502 | 12526 | |
---|
12503 | 12527 | // display shadow only (bump == 0) |
---|
12504 | 12528 | "SUB temp.x, half.x, shadow.x;" + |
---|
12505 | | - "MOV temp.y, -params6.x;" + |
---|
12506 | | - "SLT temp.z, temp.y, zero.x;" + |
---|
| 12529 | + "MOV temp.y, -params5.z;" + // params6.x;" + |
---|
| 12530 | + "SLT temp.z, temp.y, -one2048th.x;" + |
---|
12507 | 12531 | "SUB temp.y, one.x, temp.z;" + |
---|
12508 | 12532 | "MUL temp.x, temp.x, temp.y;" + |
---|
12509 | 12533 | "KIL temp.x;" + |
---|
.. | .. |
---|
12834 | 12858 | //once = true; |
---|
12835 | 12859 | } |
---|
12836 | 12860 | |
---|
12837 | | - System.out.print("Program #" + mode + "; length = " + program.length()); |
---|
| 12861 | + System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length()); |
---|
12838 | 12862 | System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : "")); |
---|
12839 | 12863 | loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program); |
---|
12840 | 12864 | |
---|
.. | .. |
---|
12967 | 12991 | |
---|
12968 | 12992 | "ADD " + depth + ".z, " + depth + ".z, temp.x;" + |
---|
12969 | 12993 | //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing! |
---|
| 12994 | + |
---|
| 12995 | + // Compare fragment depth in light space with shadowmap. |
---|
12970 | 12996 | "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" + |
---|
12971 | 12997 | "SGE temp.y, temp.x, zero.x;" + |
---|
12972 | | - "SUB " + shadow + ".y, one.x, temp.y;" + |
---|
| 12998 | + "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded |
---|
| 12999 | + |
---|
| 13000 | + // Reverse comparison |
---|
12973 | 13001 | "SUB temp.x, one.x, temp.x;" + |
---|
12974 | 13002 | "MUL " + shadow + ".x, temp.x, temp.y;" + |
---|
12975 | | - "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded |
---|
| 13003 | + "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse |
---|
12976 | 13004 | "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth |
---|
12977 | 13005 | |
---|
12978 | 13006 | "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" + |
---|
.. | .. |
---|
12986 | 13014 | // No shadow for backface |
---|
12987 | 13015 | "DP3 temp.x, normal, lightd;" + |
---|
12988 | 13016 | "SLT temp.x, temp.x, zero.x;" + // shadoweps |
---|
| 13017 | + "LRP " + shadow + ", temp.x, one, " + shadow + ";" + |
---|
| 13018 | + |
---|
| 13019 | + // No shadow when out of frustrum |
---|
| 13020 | + "SGE temp.x, " + depth + ".z, one.z;" + |
---|
12989 | 13021 | "LRP " + shadow + ", temp.x, one, " + shadow + ";" + |
---|
12990 | 13022 | ""; |
---|
12991 | 13023 | } |
---|
.. | .. |
---|
13801 | 13833 | |
---|
13802 | 13834 | public void mouseDragged(MouseEvent e) |
---|
13803 | 13835 | { |
---|
| 13836 | + Globals.MOUSEDRAGGED = true; |
---|
| 13837 | + |
---|
13804 | 13838 | //System.out.println("mouseDragged: " + e); |
---|
13805 | 13839 | if (isRenderer) |
---|
13806 | 13840 | movingcamera = true; |
---|
| 13841 | + |
---|
13807 | 13842 | //if (drawing) |
---|
13808 | 13843 | //return; |
---|
13809 | 13844 | if ((e.getModifiersEx() & CTRL) != 0 |
---|
.. | .. |
---|
14365 | 14400 | |
---|
14366 | 14401 | public void mouseReleased(MouseEvent e) |
---|
14367 | 14402 | { |
---|
| 14403 | + Globals.MOUSEDRAGGED = false; |
---|
| 14404 | + |
---|
14368 | 14405 | movingcamera = false; |
---|
| 14406 | + X = Y = 0; |
---|
14369 | 14407 | //System.out.println("mouseReleased: " + e); |
---|
14370 | 14408 | clickEnd(e.getX(), e.getY(), e.getModifiersEx()); |
---|
14371 | 14409 | } |
---|
.. | .. |
---|
15374 | 15412 | info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom)); |
---|
15375 | 15413 | //Image img = CreateImage(width, height); |
---|
15376 | 15414 | //System.out.println("width = " + width + "; height = " + height + "\n"); |
---|
| 15415 | + |
---|
15377 | 15416 | Graphics gr = g; // img.getGraphics(); |
---|
| 15417 | + |
---|
15378 | 15418 | if (!hasMarquee) |
---|
15379 | 15419 | { |
---|
15380 | 15420 | if (Xmin < Xmax) // !locked) |
---|
.. | .. |
---|
15472 | 15512 | if (!isRenderer) |
---|
15473 | 15513 | { |
---|
15474 | 15514 | object.drawEditHandles(info, 0); |
---|
| 15515 | + |
---|
| 15516 | + if (drag && (X != 0 || Y != 0) && object.selection.Size() > 0) |
---|
| 15517 | + { |
---|
| 15518 | + switch (object.selection.get(0).hitSomething) |
---|
| 15519 | + { |
---|
| 15520 | + case Object3D.hitCenter: gr.setColor(Color.pink); |
---|
| 15521 | + gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
| 15522 | + break; |
---|
| 15523 | + case Object3D.hitRotate: gr.setColor(Color.yellow); |
---|
| 15524 | + gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
| 15525 | + break; |
---|
| 15526 | + case Object3D.hitScale: gr.setColor(Color.cyan); |
---|
| 15527 | + gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
| 15528 | + break; |
---|
| 15529 | + } |
---|
| 15530 | + |
---|
| 15531 | + } |
---|
15475 | 15532 | } |
---|
15476 | 15533 | } |
---|
| 15534 | + |
---|
15477 | 15535 | if (isRenderer) |
---|
15478 | 15536 | { |
---|
15479 | 15537 | //gr.setColor(Color.black); |
---|
15480 | 15538 | //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1); |
---|
15481 | 15539 | //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3); |
---|
15482 | 15540 | } |
---|
| 15541 | + |
---|
15483 | 15542 | if (hasMarquee) |
---|
15484 | 15543 | { |
---|
15485 | 15544 | gr.setXORMode(Color.white); |
---|
.. | .. |
---|
15886 | 15945 | Object3D object; |
---|
15887 | 15946 | static Object3D trackedobject; |
---|
15888 | 15947 | Camera renderCamera; // Light or Eye (or Occlusion) |
---|
15889 | | - /*static*/ Camera manipCamera; // Light or Eye |
---|
| 15948 | + /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light |
---|
15890 | 15949 | /*static*/ Camera eyeCamera; |
---|
15891 | 15950 | /*static*/ Camera lightCamera; |
---|
15892 | 15951 | int cameracount; |
---|