Graphics Reference
In-Depth Information
// Keep track of the last key-frame used for bones
Mesh.Keyframe?[] lastKeyForBones =
new Mesh.Keyframe?[mesh.Bones.Count];
// Keep track of bone interpolation
bool[] lerpedBones = new bool[mesh.Bones.Count];
for (var i = 0; i <
CurrentAnimation.Value.Keyframes.Count; i++)
{
// Retrieve current key-frame
var frame = CurrentAnimation.Value.Keyframes[i];
// If the current frame is not in the future
if (frame.Time <= time)
{
// Retrieve transform from current key-frame
skinMatrices.Bones[frame.BoneIndex] =
frame.Transform;
// Keep track of last key-frame for bone
// for interpolation with future frame
lastKeyForBones[frame.BoneIndex] = frame;
}
// Otherwise frame is in future check interpolation
else
{
... perform frame interpolation
}
}
}
4.
To provide smoother animations, we will interpolate the current keyframe for each
bone with the next key-frame for each bone. We will use the following code:
// Only interpolate a bone's key-frames ONCE
if (!lerpedBones[frame.BoneIndex])
{
// Retrieve the previous key-frame for bone
Mesh.Keyframe prevFrame;
if (lastKeyForBones[frame.BoneIndex] != null)
prevFrame =
lastKeyForBones[frame.BoneIndex].Value;
else
continue; // nothing to interpolate
// Make sure we only interpolate with
// one future key-frame for this bone
lerpedBones[frame.BoneIndex] = true;
 
Search WWH ::




Custom Search