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 book'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.
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...