Jump to content
  • Advertisement
Sign in to follow this  

Skinning Matrices [Solved]

This topic is 2278 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm attempting to animate a skinned mesh with joints. I have looked at many different materials, and something isn't right with my understanding. All of my nodes hold a local and global matrix. When I load in the joints, I calculate the inverse pose matrix like so:

Pose Matrix = Mesh's Inverse Global * Joint Global
Inverse Pose Matrix = Inverse of Pose Matrix

Then when my joints are updated, I calculate the joint in mesh space and multiply it with the inverse pose matrix.

Joint wrt Mesh = Mesh's Inverse Global * Joint Global
Deform Matrix = Joint wrt Mesh * Inverse Pose Matrix

I uploaded the following video files to demonstrate what is happening to my mesh. Is my algorithm correct in handling the matrices in mesh space and calculating the inverse pose matrix? If I knew that, it would be easier to further study the problem.

Source animation..

My Results..

These are my references -
Introduction to Game Development
UCSD - Skinning powerpoint
Animation in Video Games

Share this post

Link to post
Share on other sites
Hi, the solution in my game engine is the following:

struct Bone {
Matrix4 staticMat;
unsigned int jointIndex;
std::string name;
std::vector<Bone*> children;

struct Skeleton {
Bone* rootBone;
std::map<std::string, Bone*> bones;

struct BonePose {
Matrix4 poseMat, dynamicMat;

class SkeletonPose {
std::map<std::string, BonePose*> bonePoses;
SkeletonPose(Skeleton* skeleton);
void calculateBonePose(Bone* bone, Bone* parentBone);
void calculateDisplayMatrix(Bone* bone, Bone* parentBone, Matrix4* mats);

void SkeletonPose::calculateBonePose(Bone* bone, Bone* parentBone) {
BonePose* bonePose = bonePoses[bone->name];
if(parentBone) {
bonePose->dynamicMat = bonePose->poseMat;
bonePose->dynamicMat *= bonePoses[parentBone->name]->dynamicMat;
}else{ //Is root bone
bonePose->dynamicMat = bonePose->poseMat;
for(unsigned int i = 0; i < bone->children.size(); i ++)
calculateBonePose(bone->children, bone);

void SkeletonPose::calculateDisplayMatrix(Bone* bone, Bone* parentBone, Matrix4* mats) {
Matrix4 mat;
mats[bone->jointIndex] = mat * bonePoses[bone->name]->dynamicMat;
for(unsigned int i = 0; i < bone->children.size(); i ++)
calculateDisplayMatrix(bone->children, bone, mats);

//Draw Frame

//Calculate the hierarchical transformations of the skeleton
skeletonPose->calculateBonePose(humanModel->skeleton->rootBone, NULL);

//Calculate the matrices used in the shader
Matrix4* mats = new Matrix4[skeleton->bones.size()];
skeletonPose->calculateDisplayMatrix(skeleton->rootBone, NULL, mats);
currentShaderProgram->setUniformMatrix4("jointMats", mats, skeleton->bones.size());
delete [] mats;
for(unsigned int i = 0; i < meshes.size(); i ++)

I hope you can understand my code wink.png.

Share this post

Link to post
Share on other sites
Thank you - I'll look over this and see where my code differs. smile.png

EDIT: I found that my code is correct, but I didn't notice that all of the joints were using global positions, which is why the rotations appear to be offset. In Modo 401 'weightmap deformers' were used to rig geometry, and I didn't realize that the center of all the deformers was zero while the pivot position was always relative to the model center.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!