We are 'on final' when it comes to finishing the project, but just before implementing the animation system.
Our Client decided to choose "Bones Animation" - which is that I should export each Transformation Matrix ( matrix4x4 rotation+translation ) for every frame and for every bone that this animated object has.
Objects in our game are animated with 3DS Max Physique Modifier, so we will have bones / weighting data per vertex. But I will simplify things here just to get a bit of light on this subject.
I would like to split this post into 2 points, where :
Exporting bones matrices for every frame
- treats about the correct method of exporting the bones positions for later animation purposes, where i have to 'move' and 'rotate' every vertex influenced by this bone to bone position at frame X.
Calculating final vertex position
- treats about proper matrices operations to calculate new vertex position according to bone transformation in frame X.
1. EXPORTING BONES MATRICES FOR EVERY FRAME
Do I understand correctly that while exporting the animated object I should:
Grab BONE transformation matrix at frame 0 and Invert this matrix
Grab BONE transformation matrix at FRAMEx
Multiply 1 * 2 to get the transformation offset of the BONE at FRAMEx
[pseudocode]
// Animation export
// For each frame, export bone transformation offset
for(int iFrame = 0; iFrame < vFrames.size(); iFrame++)
{
// For every bone in the object
for(int iBone = 0; iBone < vBones.size(); iBone++)
{
// Grab transformation matrix for this bone at frame 0 and inverse it
Matrix3 matBoneMatrixAtStart = pNode->GetObjectTMAfterWSM( 0 );
matBoneMatrixAtStart.Inverse();
// Grab transformation matrix for this bone at frame iFrame
Matrix3 matBoneMatrixAtCurrentFrame = pNode->GetObjectTMAfterWSM( iFrame );
// Multiply Inversed Transformation Matrix of this bone at frame 0 - with
// current frame transformation matrix
Matrix3 matBoneTransformationOffset = matBoneMatrixAtStart
* matBoneMatrixAtCurrentFrame ;
// Save matBoneTransformationOffset - vertex will be multiplied by this
// matrix for animation purposes
fwrite(.....)
}
}
[/pseudocode]
Will that be enough ? Or there is something I am missing here?
2. CALCULATING NEW VERTICES POSITIONS ( FINAL VERTEX POSITION AT FRAME X)
Later on, when rendering, object vertices are going to be multiplied by exported bone transformation matrix for actual animation frame, and then multiplied by this whole model transformation matrix to place the object in correct position inside the level :
[pseudocode]
Update()
{
// The model transformation matrix describing the position of
// the model in the level
matModelTransformationMatrix
// Calculate new vertex position according to it's bone transformation offset
NewVertexPosition = (OriginalVertexPosition * matBoneTransformationOffset[iFrame])
* matModelTransformationMatrix;
// Increment the frame for testing purposes
iFrame++;
}
[/pseudocode]
Am I thinking correct here? So, Having bone transformation offset for frame X, multiplying every vertex affected by this bone by this offset should result in a vertex transformed exactly as this bone right?