Animating a Collision Mesh?

Brutal
Posts: 14
Joined: Mon Jul 26, 2010 8:03 am

Animating a Collision Mesh?

Post by Brutal »

I have implemented a Character Controller and I have my player mesh in the world. My problem is that I am trying to think of how to bind them together, and despite a massive amount of searching I have found relatively little on the topic of animating a collision mesh. I was going to use btCapsuleShape originally, but I would really like to have a more precise collision representation of my player than a generic primitive. I found some code snippets that convert the vertex data from an Ogre .mesh file to a bullet collision shape, but then it occured to me that this shape would be static while my character would be animating.

So I am looking for any sort of information you guys can provide on the subject. My assumption is that I am going to want to create some sort of collection of primitives to make up a complete collision mesh for my player, and then somehow use the skeletal animation from my Ogre player model to control them.

Here is a screenshot of my player model...
http://i54.tinypic.com/1olzlx.png

and here is a screenshot of what I am talking about being implemented on the player models in Valve games.
http://i52.tinypic.com/25fkcw4.png

I am hoping I am over complicating this in my head, but from the lack of information I am pretty worried. Here is something someone said that does & doesn't make sense to me. I don't know what he means by bone-primitive mapping, and I can't really think of how I would drive the primitives positions with my player's bones unless their is someway for me to parent them.
You should be able to take the bones from the animation and tie them to collision primitives. Just setup a bone-primitive mapping and use your animation skeleton to drive the positions of the collision primitives. When you are done animating the object, look at the RagDoll demo in the bullet demos for how you could then constrain all those primitives together into a phsyics object that could then drive the animation bones.
slithEToves
Posts: 24
Joined: Mon Mar 12, 2007 9:55 pm

Re: Animating a Collision Mesh?

Post by slithEToves »

You can use a btCompoundShape to do this. Your model likely has an internal hierarchy that you may not need to preserve in the collision, however, so you can flatten it to only have a 1 level deep hierarchy in your compound. Use convex primitives, such as boxes and cylinders/capsules for the body parts. This way, your character has one collision object, but multiple children. You will need to update the local transforms as the model animates, and when you do so, you will need to update the appropriate bits of your compound (aabb, hierarchy, etc.).