Graphics Reference
In-Depth Information
Animating bones
With an armature loaded and our vertex skinning in place, we are now ready to playback
bone animations. In this recipe, we will access the animation's keyframes that are loaded
from the first animation in a mesh, and playback within a loop.
Getting ready
For this recipe, we will continue from where we left off in the Loading bones in the mesh
renderer recipe.
The completed project for this recipe, called Ch04_02Animate , is available within the
companion source code provided with this topic's code bundle. It is available on Packt website.
How to do it…
We will start by adding a few new properties to our mesh renderer.
1.
Open MeshRenderer.cs and add the following code:
// Create and allow access to a timer
System.Diagnostics.Stopwatch clock = new System.Diagnostics.
Stopwatch();
public System.Diagnostics.Stopwatch Clock
{
get { return clock; }
set { clock = value; }
}
// The currently active animation (allows nulls)
public Mesh.Animation? CurrentAnimation { get; set; }
// Play once or loop the animation?
public bool PlayOnce { get; set; }
2.
At the start of our MeshRenderer.DoRender method, calculate the number of
seconds elapsed:
var time = clock.ElapsedMilliseconds / 1000.0f;
3. In place of the first TODO comment that we added in the previous recipe for loading
bone transforms, add the following code:
// Load bone transforms from animation frames
if (CurrentAnimation.HasValue)
{
 
Search WWH ::




Custom Search