Sign in to follow this  
SaTANO

Math behind skeletal mesh deforming - solved

Recommended Posts

Hi guys I am looking for good tutorial on matrix operations in skeletal animations. I already done skeleton import (structure of bones with absolute matrix and parent-relative matrix). I also done shader to deform mesh: send array of bones matrices and send attribute for bone index and weight for vertex. I am not that good in math so I don't know how to calculate these matrices (of course I know that after I transform bone I need to recalculate its children matrices but these calculs are my problem). I sent identity matrices to shader only for testing purpose and tried to rotate bone and it deform mesh so everything is working so I only need to know how to calculate those matrices. I searched gamedev forum and google and found some implementations but it was mainly code-only which was part of coder's previous project which was part... . Is here someone who can give me hint / link / algorithm please? Thanks [Edited by - SaTANO on February 19, 2010 6:55:53 AM]

Share this post


Link to post
Share on other sites
Quote:
I know that after I transform bone I need to recalculate its children

That's a good basis for beginning to understand the process.

I'm making several assumptions about how you have your bone hierarchy arranged, but I'll try to describe the general process.

Definitions:
offset:
a fixed (doesn't change with animation time) matrix for each bone.
NOT parent-relative.
Transforms the rest pose vertices to the bone's bone-space.
=======
frameTransform:
a matrix for each bone.
Calculated using parent-relative transforms in the bone's animation data,
the result of a lerp/slerp for the current animation time.
EDIT: frameTransform = child-animMatrixSlerped * parent-animMatrixSlerped * ...
=======
combinedTransform:
a matrix for each bone.
Calculated (as you seem to know) as child-frameTransform * parent-frameTransform * parent-parent-frameTransform...
=======
finalTransform:
a matrix for each bone.
finalTransform = offset * combinedTransfrom
=======
The finalTransforms are what you pass to the shader (along with bone influence indices and weights).



Is that what you're asking about?

[Edited by - Buckeye on February 18, 2010 1:35:16 PM]

Share this post


Link to post
Share on other sites
Thanks man this is what I was looking for
I think I understand it so just a question

I did not rotate bones so I have my skeleton in reference pose and for each bone I have relative matrix to it's parent

- I multiply bone's relative matrix with its parent's bone and then with parent's parent's bone and again .....
- with this I get combinedTransform matrix which should be inverse matrix to bone's offset matrix

it means if I multiply offset matrix with combinedTransform matrix my finalTransform matrix must by identity matrix (so it means I did not rotate this bone)

This is the goal. am I right?

Share this post


Link to post
Share on other sites
Quote:
it means if I multiply offset matrix with combinedTransform matrix my finalTransform matrix must by identity matrix

You have to be careful there if you want to communicate. Normally each bone's frameTransform (used to calculate the combinedTransform) is updated during animation and has nothing to do with the rest pose.

I would call the matrix you loaded for each bone's frame a base-transform or rest-pose transform, not the frameTransform. You are correct that the offset matrix for each bone is the inverse of the combination matrix of the base-transforms - inverse of ( child * parent * parent's-parent * ... ). And, yes, if you multiply the offset by the combined base-transforms, the result is an identity and the mesh should appear in its rest pose.

In my post I carefully called the "frameTransform" the parent-relative matrix updated during animation.

Also, for the purpose of definition and clarity, the finalTransform is the offset * combined(ANIMATION)Transform.

If you mix terms, sometimes meaning base pose transforms and sometimes animation transforms, it'll be difficult to communicate.

Share this post


Link to post
Share on other sites
Just a note from my experience.
If you export from KW-X Exporter from 3DStudio Max,please be extra careful. The animation Translation/rotation/scaling ALREADY contain the bone-frame transform. I losed 2 days trying to understand that. :P

Share this post


Link to post
Share on other sites
Buckeye:
THANKS for your help. With your guide and advices (you are right, frameTransform is not that good name for base transform, in my code I was sometimes also confused which was exactly which so I just rename it :D ). Well but what is much more important is:

I successfully implement it!!!

Now its time for real animation system.
My next step will be quaternions because I can reduce data sent to shader so I can use more bones.
I am glad that someone can explain me the process theoretically in few lines and not just sent code

feal87:
thanks this was also my problem

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