Animation Samples
Filament provides comprehensive support for various animation techniques. These samples demonstrate skeletal skinning, morph target animations, and dynamic vertex transformations.Basic Transform Animation
Theanimation.cpp sample demonstrates simple vertex buffer animation with rotation transforms.
Key Features
- Real-time vertex buffer updates
- Transform animations using rotation matrices
- Orthographic camera projection
- Basic renderable setup
Code Example
samples/animation.cpp:108-150
This sample shows how to animate geometry by updating vertex positions each frame and applying rotation transforms to create a spinning triangle with animated vertices.
Skeletal Skinning
Thehelloskinning.cpp sample demonstrates GPU-accelerated skeletal animation using bone weights and joint indices.
Key Features
- Bone-based vertex deformation
- Joint indices and weights attributes
- Real-time bone transform updates
- Multiple primitives with shared skinning data
Vertex Structure
samples/helloskinning.cpp:61-66
Setting Up Skinning
samples/helloskinning.cpp:179-190
Animating Bones
samples/helloskinning.cpp:221-225
The bone transforms are updated each frame to create smooth skeletal animation. Each vertex is influenced by its assigned bones based on the weight values.
Morph Target Animation
Thehellomorphing.cpp sample showcases blend shape (morph target) animation for facial expressions and shape deformations.
Key Features
- Multiple morph targets per primitive
- Position and tangent morphing
- Blend weight animation
- MorphTargetBuffer management
Creating Morph Targets
samples/hellomorphing.cpp:171-183
Configuring Morphing
samples/hellomorphing.cpp:194-206
Animating Blend Weights
samples/hellomorphing.cpp:236-239
Morph weights control the blend between the base mesh and each target shape. Weights are typically normalized to sum to 1.0 for natural blending.
Advanced Skinning Techniques
For production use, Filament also provides:- SkinningBuffer: Hardware-accelerated skinning with buffer objects (
helloskinningbuffer.cpp) - UV Morphing: Morph texture coordinates for animated materials (
hellouvmorphing.cpp) - Large Bone Counts: Support for complex rigs with many bones (
helloskinningbuffer_morebones.cpp)
Best Practices
- Vertex Attributes: Always include BONE_INDICES and BONE_WEIGHTS for skinned meshes
- Bounding Boxes: Update bounding boxes when using dynamic animations to ensure proper culling
- Performance: Use SkinningBuffer for better performance with many animated characters
- Morph Targets: Limit the number of active morph targets to 4-8 for optimal performance
- Transform Updates: Batch bone transforms when possible to reduce API calls
Related Samples
gltf_viewer.cpp- Full glTF animation support including keyframe interpolationskinningtest.cpp- Advanced skinning test casesanimation.cpp- Basic transform and vertex animations