Inverse Bine Pose

Started by
5 comments, last by Endemoniada 9 years, 9 months ago

Hi guys,

I'm having some problems implementing basic skeletal animation. I'm not concerned with skinning at the moment, just bone movements. I understand the concept, but am missing something.

I have a simple setup like this:

root->child


float4x4 transforms[2];

// root
matrixTranslation(&translation,&pose.joints[0].pos); // the pose's root joint position
matrixRotationQuaternion(&rotation,&pose.joints[0].q); // the pose's root joint orientation
matrixMultiply(&transforms[0],&rotation,&translation); // combine

// child
matrixTranslation(&translation,&pose.joints[1].pos); // the pose's child joint position
matrixRotationQuaternion(&rotation,&pose.joints[1].q); // the pose's child joint orientation
matrixMultiply(&temp,&rotation,&translation); // combine
matrixMultiply(&transforms[1],&temp,&transforms[0]); // incorporate parent's transformation
 
// then I would use the transforms I made to transform the actual vertices

I don't know where to take into account the inverse_bind_pose, or if I'm doing it right at all.

I also don't understand why there is a position/translation in the pose joint; when the parent joint is rotated doesn't that automatically change the child's position/translation since the imaginary bone between them is rigid ?

I can give more code and structs if needed.

Thanks.

edit: title should be Bind pose, not Bine

Advertisement

I also don't understand why there is a position/translation in the pose joint; when the parent joint is rotated doesn't that automatically change the child's position/translation since the imaginary bone between them is rigid ?

Not really sure what you mean here exactly, parent transforms affect child transforms, as youve done, where is this "pose joint" thats confusing you coming from?

Bones dont really exist, theyre just the space between a parent transform and a child transform, where each transform is a joint that affects the child joints below it.

Ex, an arm: shoulder joint <-> elbow joint <-> wrist joint, each "<->" would be a bone i guess

The way it works is like this: the animation stream will provide the location of each bone in parent-space, which is the space relative to the bone's parents. Then, you have to create a buffer of model-space transforms for each bone by transforming each bone by it's parent's model-space transform. Then, once you have model space transforms, you need to determine how the current model space transform differs from the original pose's model space transform for each bone. This difference is what you use to transform your verts.

In some (very) pseudo code:


bone[0] = root;
bone[1] = anim_stream[1];
bone[2] = anim_stream[2];
...
bone[n] = anim_stream[n];

model_space_bone[n] = model_space_bone[parent_of(n)] * bone[n]; 

// ok, so what can we tell from model_space_bone[n]?
// we know the original pose's model space transformation for bone[n]
// therefore model_space_bone[n] = D * bone_pose[n] where bone_pose[n] is the
// transform of the bone in it's original pose.
// this means the current model_space_bone[n] is actually just some 
// transformation (D) from the original model space position. We need to 
// find D, because that's what we'll use to transform our verts

// doing some matrix math: 

model_space_bone[n] * inv_bone_pose[n] = D * bone_pose[n] * inv_bone_pose[n];
D = model_space_bone[n] * inv_bone_pose[n]

bone_pose_space_bone[n] = D = model_space_bone[n] * inv_bone_pose[n]

// vertex transformation uses bone_pose_space_bone[n], as this transformation
// represents the transformation of that bone from it's original pose
// to the pose it's in currently

projected_vert = proj_mtx * view_mtx * model_mtx * bone_pose_space_bone[bone_idx] * vert_pos;

First, you may want to review the subject in this article about animation using matrices.

Second, it's not clear where you're getting the translation/rotation data from which you're creating matrices.

That being said, the inverse bind pose is the matrix inverse of a bone's world transform, which you appear to be calculating for the child in your OP - IF the child's position and rotation are relative to it's parent.

[ninja'd by Samith - wink.png ]

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

I guess I'll try to understand it after I actually get it to work.

This is what I'm working with (from Game Engine Architecture):


struct Joint {
 float4x4 inv_bind_pose; // matrix
 int parent;
};
 
struct Skeleton {
 int joint_count;
 Joint* joints;
};
 
struct JointPose {
 float4 rotation; // quaternion
 float3 translation;
};
 
struct SkeletonPose {
 int joint_count;
 JointPose* joints;
};
 
// it's already confusing because of the different joint types

1) Are the inv_bind_pose matrices relative to the root joint (which would have it's inv_bind_pose as identity) ?

2) Are the rotations and translations in the JointPose structs relative to their parents ?

3) How do I put it all together ?

Thanks

1) Its the transform of the joint at the time it was bound to the mesh, inverted. World coordinates.
2) Yes
3) ....

I use world/local terminology (local = parent relative, world = global = model)

A) Using the joint local transforms, compute each joints world transform, childJointWorld = parentJointWorld * childJointLocal
-> Convert to matrices first, or use quaternions/vector3 then convert, your choice, in the end youll need a world matrix to combine with the jointInvBindPose matrix

QWorld = QParentWorld * QLocal // rotate part
TWorld = TParentWorld + (QParentWorld * (SParentWorld * TLocal) // translate part
SWorld = SParentWorld * SLocal // scale part

-> If a joint has no parent, world = local

B) Now you have all joint world transforms, lets call this next one jointSkinMatrix = jointWorld * jointInvBindPose
C) The model probably has skin matrix / bind matrix / bind shape matrix, whatever its called this gets applied to all the original vertices, so you can do this once and store the modified model

Long version....

vec3 skinnedVertex = vec3(0, 0, 0)
For Each Vertex v
For Each Joint Affecting Vertex v
skinnedVertex += ((jointWorld * jointInvBindPose) * (bindShapeMatrix * v)) * jointWeight

Again, some of this depends on matrices or quaternion use, compute on gpu or cpu, but thats the general idea. Normals, same thing, but wouldnt be translated, and would have to be normalized for correct lighting.

Hey guys,

After reading your posts, going over Buckeye's article (which I'll have to get back to since it's more advanced than what I want right now), and reading a paper by Frank Luna, I was able to get it working.

I wanted to get a simple system up and running before using an importer/exporter. I load a model (.obj) that looks like three bones and create the joints by hand.

Everything seems to be fine, I can setup my bind pose structures, then put it in any other pose I like (by rotating the individual joints.)

I'm doing it like this:

for(i=0;i<n;i++)

Ci = Li * Pi

where C is the combined matrix, L is the local matrix, and P is the parent's local matrix

then I finalize them:

for(i=0;i<n;i++)

Fi = Oi * Ci

where F is the final matrix, O is the offset matrix, and C is computed above.

For the offset matrix I use the inverse_bind_matrix. Are those normally the same thing ?

There is something that is nagging me. I don't understand why I would need translations in each pose, if I'm not using scaling it seems I can set them up along with the inverse_bind_pose in the skeleton since they will never change. Maybe I'm missing something ?

Thanks a lot.

This topic is closed to new replies.

Advertisement