Weighted animation

Started by
10 comments, last by jtech 21 years, 4 months ago
Hi, I am implementing an x-file animation renderer at the time. So I can tell you what I am doing.

What I have:

An indexed list of vertices in model space, something like this:
std::vector m_VertexData;
std::Vector m_IndexData;

A bone hierachy which looks like this:

struct BoneH
{
LPCSTR pName;
CMatrix4x4 TO;
KeyframeLL pKeyframeData;

struct BoneH* pFirstChild;
struct BoneH* pSibling;
}

Also I have a vector of Skinning Data. The number of nodes of the bonetree is equal to the number of elements in this vector.
The keyframe data is a linked list of matrices which define a coordinate system at a given time.
struct SkinningData
{
LPCSTR pName;
int NumOfInfluences // The size of the arrays below
int* pIndices;
float pWeights;
}

So each Skinning Data element is actually a bone which knowsthe vertices it tranbsforms ( via the pIndices ) and the corresponding weight.

I also have a linear array of matrices of the RestPose.
When you load a mesh you get a hierachy of matrices which define coordinate systems relative to their parent in the hierachy. Because all your vertices are given in model space you have to find these matrices in modelspace as well. To get them you have to multiply each bonematrix with ALL its parents.


So what you have to do is the following:

Traverse through the BoneHierachy. In each node interpolate the KeyframeData. Save this matrix to TO. Since this matrix is relative concatenate it with its parent TO matrix. This gives you the interpolated keyframe matrices in model space.

Now for each bone:

Get the bone matrix of the Restpose in modelspace: FROM
Get the interpolated keyframe matrix in modelspace: TO

You find a transition matrix TRANS = TO * FROM.Inverse();

Now for all vertices in this bone:

VTransformed = w * Trans * VRestpose;

Thats it.

if you have question mail me, I don''t think that I will look into this forum in the next time.

dirk@dirkgregorius.de

Dirk

Advertisement
Well, X file animation is a little different than the Milkshape code above,
because X animation keys, whether they be in matrix form or PRS form, are not
relative to the rest pose. Milkshape animation keys are relative to the
rest pose.


Here's a better question:

Given two models that have exactly the same vertices and faces,
but one is weighted and the other is rigid, can these two models
use the same bones and the same animation keys, provided that the
animation keys are relative to the rest pose?

In other words, if I give a rigid model some vertex weights, does
this affect its animation keys?


[edited by - jtech on November 22, 2002 10:45:37 PM]

This topic is closed to new replies.

Advertisement