Sign in to follow this  
mixeu

How to "Attach" stuff to a skinned mesh ??

Recommended Posts

HI everyone! I was wondering how to attach some things, mostly weapons or cloths, to a skinned .X mesh, in such a way that, for instance, when a character moves his arm the attached sword follows... Anyway, heres what I tried: Say I´v got a "Mesh" class with a "Draw" Method. I added some custom data to the D3DXMeshContainer structure, and all I had to do was, while rendering a mesh container, call the Mesh::Draw() with the his transformation matrix. Well, it didnt work. Turns out only a few D3DXFRAME´s actually had any mesh container. So, even if I call Attach("left_arm",...) and there is a D3DXFRAME called "left_arm", chances are this frame will have no mesh container at all, so I cant add my custom stuff :( Then I tried this: To call the ID3DXSkinInfo::UpdateSkinnedMesh, we should send the bone transforms as the first parameter. I tried using these matrixes as the world transformation for my custom stuff, but it also didnt work :( SO, if any of u guys could be so kind and please help me out, I would be INSANELY grateful :p ( PS: sorry for d bad english... )

Share this post


Link to post
Share on other sites
I'll use your example of attaching a sword to a hand to try to explain this, though there won't be any explanations directly related to the D3DXMesh class. The transformation's are defined in local object space for the model's animation, that meaning they are performed local to the object being animated. Once the animation is complete, you then translate the object to world space using the proper world transformation which transforms all the object's vertices in their current location to world coordinates.

Since each sub-joint utilizes the parent's transformation to build its own, you could do something along these lines:

1) For each joint, store off the overall transformation which is a sum of all the previous joint's transformations
2) Calculate a bounding-box after each frame of animation for your mesh
3) Locate the root node in local object space relative to this bounding box, store off this location
4) Get the final transformation matrix for the joint to which you want to attach the sword
5) Set the swords transformation to(and not necessarily perform the operations in this order):

object_world_transform + root_node_offset_in_bounding_box + joints_final_transformation_matrix

Then for the frame:

1) Animate the base model
2) Store off the final transformation as per above for the sword and set any minute offsets you may need to to properly position the handle in the hand (depends on the middle of the sword's local object space)
3) Set the world transform for the base model, render model
4) Set the world transform for the sword to the one stored off in step 2 above, render the sword

I wrote this out while thinking it through so a few things might be a little off, but this should give you a good starting point to translate the object's local coordinate space into world coordinate space for rendering the sword in the final position of the hand

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this