Mouse picking on geometries manipulated by animation/bones


I have a model with skeleton and I am manipulating the bones of the skeleton from code. The model consists of several geometries (divided by material) inside jme.

But I have one problem, if I am using mouse picking like this:


CollisionResults results = new CollisionResults();

// Convert screen click to 3d position

Vector2f click2d = inputManager.getCursorPosition();

Vector3f click3d = cam.getWorldCoordinates(

new Vector2f(click2d.x, click2d.y), 0f).clone();

Vector3f dir = cam


new Vector2f(click2d.x, click2d.y), 1f)


// Aim the ray from the clicked spot forwards.

Ray ray = new Ray(click3d, dir);

// Collect intersections between ray and all nodes in results

// list.

modelNode.collideWith(ray, results); //The root node of my geometries which I try to click


and I got only the correct clicked geometry if I am clicking on the rest position of my model parts. If I click on my bone manipulated geometries (their current displayed position) I got no results/collisions. So it seems like collideWith is always working with the rest position of a geometry…but may I made another mistake. Could someone help with that?

Do I may need to change something in this line?


modelNode.collideWith(ray, results); //The root node of my geometries which I try to click


Do have someone any idea about that issue?

I have encountered the exact same thing. I have animated objects that I click on to activate an animation. However, once the animation starts, the collideWith no longer matches the objects animated position. Its like you said, its always working with the rest position of a geometry. I too would like to know how to do this…does the engine need to be changed to support this, or is there a way to do it that isn’t obvious?

Any support available or some information if this is really a bug or something we made wrong?

Updating the collision information for mesh-accurate collision would create way too much overhead. You can try and use the automatic wrapping to bullet hull shapes of the KinematicRagDollControl or imitate its code to get something like “hit zones” for mesh parts controlled by one bone. If you want to update the collision information in a certain frame, use mesh.createCollisionData().

mesh.createCollisionData() did the trick! Thanks!


I also tried mesh.createCollisionData() and found following comment on the function:

Generates a collision tree for the mesh. Called automatically by collideWith(com.jme3.collision.Collidable, com.jme3.math.Matrix4f, com.jme3.bounding.BoundingVolume, com.jme3.collision.CollisionResults).

I am using collideWith inside my MousePicking ActionListener, but the collision shape is not updated. The same if call manually this function inside my ActionListener. What I am doing wrong?

Any help?

@db2012coder: Could you please show me what you have changed?

That accounts only for the first collideWith() when no collision data is available. You’ll have to update it each time you want the current mesh to be considered.

Ok, but if I understand right calling createCollisionData() on every mesh controlled by my bones before doing a mouse-pick with collideWith should work? But I tried that and it makes no difference to calculating collideWith without calling createCollisionData before…

[UPDATE] Ok I got it. I did not know that I need to call updateModelBound(); after createCollisionData().

Much thanks!

1 Like