Portion of code taken from tainicom.Aether.Animation
- Skeletal Animation - Import animations from a Model.
- Material Animation (WIP) - Import animations from a Model.
- GPU Animated Model - Import an animated Model.
- CPU Animated Model - Import an animated Model to be animated by the CPU. Based on DynamicModelProcessor, the imported asset is of type Microsoft.Xna.Framework.Graphics.Model where the VertexBuffer is replaced by a DefaultAnimatedDynamicVertexBuffer, it inherits from DynamicVertexBuffer.
-Import 3D model with GPU Animated Model or CPU Animated Model Processor.
Use SkinnedEffect for GPU and BasicEffect or AlphaTestEffect for CPU based animation.
-Load as any 3D Model:
_model = Content.Load<Model>("animatedModel");
-Load the Skeletal and Material animation from model:
_skeletalAnimations = _model.GetSkeletalAnimations();
_skeletalAnimations.SetClip("ClipName");
_materialAnimations = _model.GetMaterialAnimations();
_materialAnimations.SetClip("ClipName");
_skeletalAnimations = _model.GetSkeletalAnimations();
var skeletalClip = _skeletalAnimations.Clips["ClipName"];
_skeletalAnimations.SetClip(skeletalClip);
_materialAnimations = _model.GetMaterialAnimations();
var materialClip = _materialAnimations.Clips["ClipName"];
_materialAnimations.SetClip(materialClip);
-Update animation on every frame:
_skeletalAnimations.Update(gameTime.ElapsedGameTime, true, Matrix.Identity);
_materialAnimations.Update(gameTime.ElapsedGameTime, true, Matrix.Identity);
-Draw GPU Skeletal animation:
foreach (ModelMesh mesh in _model.Meshes)
{
foreach (var meshPart in mesh.MeshParts)
{
meshPart.effect.SetBoneTransforms(_animations.AnimationTransforms);
// set effect parameters, lights, etc
}
mesh.Draw();
}
-Draw GPU Material animation:
MonoGame's shaders do not support it, create one yourself.
-Draw CPU Skeletal and Material animation:
foreach (ModelMesh mesh in _model.Meshes)
{
foreach (var meshPart in mesh.MeshParts)
{
meshPart.UpdateVertices(_skeletalAnimations.AnimationTransforms, _materialAnimations.AnimationTransforms);
// set effect parameters, lights, etc
}
mesh.Draw();
}