Archived

This topic is now archived and is closed to further replies.

Weighted animation

This topic is 5499 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

If I have a character's vertices in world coordinates as the default pose, and these vertices have weights, what do I need to do to transform them back, before I begin animating? I have this simple equation to deform them forward: V' = (v,B1)*w1 + (v,B2)*w2 ... etc where B are the bone matrices, (v,B) represents a vertex-Matrix multiplication. To deform the vertices back, is it just as simple as using the same equation, except using the inverse of B? V' = (v,B1-1)*w1 + (v,B2-1)*w2 ... etc where B-1 is the inverse matrix. [edited by - jtech on November 19, 2002 5:01:10 PM]

Share this post


Link to post
Share on other sites
I''m not sure exactly what you''re trying to do, but I believe that the equation would work. Why do you want to deform them back? Why not just do all animation from the initial pose, and never worry about transforming back?
Again, I''m not entirely sure how you''re going about animating, maybe some more info would help.

________________________
Grab your sword, and get prepared for the SolidSteel RPG engine, coming soon...(i.e. when it''s done)

Share this post


Link to post
Share on other sites
The initial pose is in world coordinates, so they must be transformed
back, at least in the beginning of the animation.

I''ve been through a dozen skeleton animation tutorials on the net, and
not a single one explains how to do this. Seems like an important
step to ignore.

Share this post


Link to post
Share on other sites
Okay, why are you storing the initial pose in world coordinates? This seems like it would be confusing.

I''ve implemented skeletal animation, so I''ll give you a basic idea of the ay I did it (This probably isn''t the best way, but it works)

I''ve got a model, and the entire model mesh is defined in local model coords. The trick is that the main mesh is broken into smaller meshes that are attached to the bones. They are not defined relative to the bone pivot, they are still relative to the model origin.

Now, this is the mesh I load. It is all specified in local coordinates. This is what I use for the initial pose, ie no transformations applied to any of the bones.

All of my animation is done relative to this local coordinate system. The rotations are ultimately specified relative to the initial position. Once I do all the transformations in local space, I then transform from the local coordinates to the world coordinates. I never need to go back to local coordinates from the world coordinates. The weighted transformations are applied in the transformation of each vertex relative to each bone matrix in local space. The weights really have nothing to do with the world transformation.

The world transformation is basically to place the model in the world after all other transformations have been applied. You animate your model, and once you have the pose done, then you move it into the world properly. Maybe you could explain how you have the model pose stored in world space. You may want to redesign, as having it in world space could be awkward.

________________________
Grab your sword, and get prepared for the SolidSteel RPG engine, coming soon...(i.e. when it''s done)

Share this post


Link to post
Share on other sites
>>Okay, why are you storing the initial pose in world coordinates? This seems like it would be confusing.

I''m not doing it intentionally, that''s just how it is.

Imagine that my model is a character model with no animation, no bones,
and is standing tall with its arms out. That is it''s initial pose,
completely transformed in world coordinates.

I mean, that''s how models start out when you first create them, then
you bone them and add animation, so I''m not sure why you find this
confusing?

Are you telling me you have never had to transform your model back
from world coordinates? That I find confusing.

Share this post


Link to post
Share on other sites
the confusion of "world coordinates" methinks is just a semantic issue.

the cooddinates that the model''s vertices get from the modelling program are the "model coordinates" the coordinates that a model gets in your game are the "world coordinates"

i.e. you have 3 models each created in 3ds-max or wahtever. each of those models has their vertices calculated from wahtever was the origin in the modelling program.

now to display in your game usually you just give the object''s a position and display them as such(openGL code):


for (int i = 0; i < numModels; i++) {
glPushMatrix()
glTranslatef(model.pos.x, model.pos.y, model.pos.z);
drawModel(model);
glPopMatrix();
}


make sense?

typically you''re dynamic object''s are done that way so you can let the accelerated hardware recalculate the vertex positions so you only have to worry about moving around one coordinate (the position coordinate) for each model.

static objects you typically transform into world coordinates so that placing them into spatial partitioning structures (BSP, OctTree) is easier.

-me

Share this post


Link to post
Share on other sites
Yes, I hope everyone understands what I mean by world coordinates.

The way I''m doing animation works, but when I started using vertex
weights, some parts of the model didn''t deform the way they should.

I don''t know exactly where the problem is coming from. If I am
using vertex weights the right way, then the problem is somewhere else.

Share this post


Link to post
Share on other sites
Ohh, I see we were using different definitions of world coordinates. Now it makes more sense. I'm still confused about what exaclty you are going for?

You have an initial pose right? Where are you trying to go from there exactly. I don't understand what you are trying to go 'back' to.

Your equation for calculating transformations looks fine, perhaps calculating the bone weights is a problem? How did you model your models?

________________________
Grab your sword, and get prepared for the SolidSteel RPG engine, coming soon...(i.e. when it's done)

[edited by - Cold_Steel on November 21, 2002 7:39:27 PM]

Share this post


Link to post
Share on other sites
If you want to see the source code am I using (at least where
I started from), here it is:
http://www.swissquake.ch/chumbalum-soft/files/MsViewer.zip

I basically took this, and converted it to use vertex weights.

In the file model.cpp, under the function SetupBones(), the mesh,
which is initially posed in world coordinates is transformed back:

pVertex->Vertex[0] -= m_pBones[pVertex->nBoneIndex].mAbsolute[0][3];
pVertex->Vertex[1] -= m_pBones[pVertex->nBoneIndex].mAbsolute[1][3];
pVertex->Vertex[2] -= m_pBones[pVertex->nBoneIndex].mAbsolute[2][3];
msVec3 vTmp;
VectorIRotate (pVertex->Vertex, m_pBones[pVertex->nBoneIndex].mAbsolute, vTmp);


These lines are basically just an inverse VertexMatrix multiplication.

For vertex weights, I just do what I posted above.

What I''m thinking is, if this is correct, then maybe the problem is
with the animation keys?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites