Custom collision model for raycast

Hello there,

I’m currently facing an issue with my mouse picking. I have a character mesh, which feet are at 0 on the Y axis when it is playing its “standup still” animation. However, my character is also able to swim, which will make its feet go below 0 on Y.

The problem is that when doing my mouse picking, the collision model still matches the standup animation, and not the swimming animation.

Here’s the code I’m using to do my mouse picking:

CollisionResults results = new CollisionResults();

    Vector2f click2d = mInputManager.getCursorPosition();
    Vector3f click3d = mRenderer.getCamera().getWorldCoordinates(
            new Vector2f(click2d.x, click2d.y), 0f).clone();
    Vector3f dir = mRenderer.getCamera().getWorldCoordinates(
            new Vector2f(click2d.x, click2d.y), 1f).subtractLocal(click3d).normalizeLocal();
    Ray ray = new Ray(click3d, dir);

mEntitiesNode.collideWith(ray, results);

From quick tests, it seems like the raycasting is done at the polygon-level. As I’m used to bounding-box picking from Ogre3D, I was looking for a way to “collide” against a bounding volume instead of the mesh exact polygons. I tried doing [java]mesh.setBound(new BoundingSphere()); mesh.updateBounds();[/java] but that doesn’t seem to make any difference.

Searching the forums, I found a thread talking about the fact that collision models aren’t updated per frame, but only at the first call of collideWith (which makes sense). So I tried to put this into the rendering loop (regardless of the FPS hit):
Geometry tmpGeo = (Geometry) child;

(‘this’ extends Node, mModelNode is attached to ‘this’, and mModel is a Spatial attached to mModelNode)

But this didn’t make any difference either. I’m highlighting the currently picked model, and it still only highlights when I hover my mouse “above” (on the Y axis) the model swimming, and doesn’t do anything when I hover my mouse on the body ; that is to say, it still seems to have a collision model based on the “stand up still” animation, where feet are above the origin.

Any ideas?

Yes, it would be too much overhead computing the picking data on each frame when the animation changes the model. I suggest not moving the model down by animation but by translating the geometry.

@normen: Thanks for your reply. Unfortunately, I cannot change the animations (meshes were given to us).

Is there any way I can setup a manual collision model, and update it when I need to?

you could create a geom with an invisible material from the standard box mesh (the one that you see when you create a new jmonkey project) and size the box to be the size of what you consider to be the bounding box. then attach it to a bone’s attachment node that rotates with the character (likely their chest or something like that) and use that box mesh for ray casting purposes.