diff --git a/jme3-core/src/main/java/com/jme3/scene/debug/custom/ArmatureDebugAppState.java b/jme3-core/src/main/java/com/jme3/scene/debug/custom/ArmatureDebugAppState.java index fb16135e6..a3618b444 100644 --- a/jme3-core/src/main/java/com/jme3/scene/debug/custom/ArmatureDebugAppState.java +++ b/jme3-core/src/main/java/com/jme3/scene/debug/custom/ArmatureDebugAppState.java @@ -30,6 +30,8 @@ public class ArmatureDebugAppState extends BaseAppState { private Application app; private boolean displayAllJoints = false; private float clickDelay = -1; + Vector3f tmp = new Vector3f(); + Vector3f tmp2 = new Vector3f(); ViewPort vp; @Override @@ -84,10 +86,15 @@ public class ArmatureDebugAppState extends BaseAppState { public ArmatureDebugger addArmatureFrom(Armature armature, Spatial forSpatial) { + ArmatureDebugger ad = armatures.get(armature); + if(ad != null){ + return ad; + } + JointInfoVisitor visitor = new JointInfoVisitor(armature); forSpatial.depthFirstTraversal(visitor); - ArmatureDebugger ad = new ArmatureDebugger(forSpatial.getName() + "_Armature", armature, visitor.deformingJoints); + ad = new ArmatureDebugger(forSpatial.getName() + "_Armature", armature, visitor.deformingJoints); ad.setLocalTransform(forSpatial.getWorldTransform()); if (forSpatial instanceof Node) { List geoms = new ArrayList<>(); @@ -122,18 +129,11 @@ public class ArmatureDebugAppState extends BaseAppState { if (name.equals("shoot") && !isPressed && clickDelay < CLICK_MAX_DELAY) { Vector2f click2d = app.getInputManager().getCursorPosition(); CollisionResults results = new CollisionResults(); - //first check 2d collision with joints - for (ArmatureDebugger ad : armatures.values()) { - ad.pick(click2d, results); - } - if (results.size() == 0) { - //no result, let's ray cast for bone geometries - Vector3f click3d = app.getCamera().getWorldCoordinates(new Vector2f(click2d.x, click2d.y), 0f).clone(); - Vector3f dir = app.getCamera().getWorldCoordinates(new Vector2f(click2d.x, click2d.y), 1f).subtractLocal(click3d); - Ray ray = new Ray(click3d, dir); - debugNode.collideWith(ray, results); - } + Vector3f click3d = app.getCamera().getWorldCoordinates(new Vector2f(click2d.x, click2d.y), 0f, tmp); + Vector3f dir = app.getCamera().getWorldCoordinates(new Vector2f(click2d.x, click2d.y), 1f, tmp2).subtractLocal(click3d); + Ray ray = new Ray(click3d, dir); + debugNode.collideWith(ray, results); if (results.size() == 0) { for (ArmatureDebugger ad : armatures.values()) { diff --git a/jme3-core/src/main/java/com/jme3/scene/debug/custom/ArmatureDebugger.java b/jme3-core/src/main/java/com/jme3/scene/debug/custom/ArmatureDebugger.java index ac93bfaaf..31c292186 100644 --- a/jme3-core/src/main/java/com/jme3/scene/debug/custom/ArmatureDebugger.java +++ b/jme3-core/src/main/java/com/jme3/scene/debug/custom/ArmatureDebugger.java @@ -121,7 +121,7 @@ public class ArmatureDebugger extends Node { ((Node) wires.getChild(1)).getChild(0).setCullHint(display ? CullHint.Dynamic : CullHint.Always); } - protected void initialize(AssetManager assetManager, Camera camera) { + public void initialize(AssetManager assetManager, Camera camera) { armatureNode.setCamera(camera); @@ -153,10 +153,6 @@ public class ArmatureDebugger extends Node { } - public int pick(Vector2f cursor, CollisionResults results) { - return armatureNode.pick(cursor, results); - } - public Armature getArmature() { return armature; } @@ -169,9 +165,7 @@ public class ArmatureDebugger extends Node { @Override public int collideWith(Collidable other, CollisionResults results) { - return armatureNode.collideWith(other, results); - } protected Joint select(Geometry g) { diff --git a/jme3-core/src/main/java/com/jme3/scene/debug/custom/ArmatureNode.java b/jme3-core/src/main/java/com/jme3/scene/debug/custom/ArmatureNode.java index 7f8b26c2d..038936049 100644 --- a/jme3-core/src/main/java/com/jme3/scene/debug/custom/ArmatureNode.java +++ b/jme3-core/src/main/java/com/jme3/scene/debug/custom/ArmatureNode.java @@ -62,6 +62,7 @@ public class ArmatureNode extends Node { private Map geomToJoint = new HashMap<>(); private Joint selectedJoint = null; private Vector3f tmp = new Vector3f(); + private Vector2f tmpv2 = new Vector2f(); private final static ColorRGBA selectedColor = ColorRGBA.Orange; private final static ColorRGBA selectedColorJ = ColorRGBA.Yellow; private final static ColorRGBA outlineColor = ColorRGBA.LightGray; @@ -262,7 +263,16 @@ public class ArmatureNode extends Node { if (!(other instanceof Ray)) { return 0; } - int nbCol = 0; + + // first try a 2D pick; + camera.getScreenCoordinates(((Ray)other).getOrigin(),tmp); + tmpv2.x = tmp.x; + tmpv2.y = tmp.y; + int nbHit = pick(tmpv2, results); + if (nbHit > 0) { + return nbHit; + } + for (Geometry g : geomToJoint.keySet()) { if (g.getMesh() instanceof JointShape) { continue; @@ -275,11 +285,11 @@ public class ArmatureNode extends Node { CollisionResult res = new CollisionResult(); res.setGeometry(g); results.addCollision(res); - nbCol++; + nbHit++; } } } - return nbCol; + return nbHit; } private void updateBoneMesh(Geometry geom, Vector3f start, Vector3f[] ends) {