Morph targets
Morph targets (blend shapes) deform a mesh toward stored shapes. Play them from glTF animations or set their weights yourself with MorphWeights.
On this page
A morph target is a stored version of a mesh with its vertices moved, such as a smile or a blink. Each target has a weight from 0 to 1, and the mesh shows the sum of the targets by their weights. Faces, muscles and simple shape changes use them where bones would be awkward.
Morph targets and morph target animation are on in NEO's builds, including on the web.
Where weights live#
| Component | Where | What it holds |
|---|---|---|
MorphWeights | On the parent of the mesh entities, usually the glTF mesh's node | The weights for every mesh primitive under it. This is the one to change. |
MeshMorphWeights | On each Mesh3d entity | Value { weights } for that mesh alone, or Reference(entity) pointing at a MorphWeights to share. Writing MorphWeights overwrites it. |
A glTF file with morph targets sets these up when it spawns.
Playing them from glTF#
glTF animations can animate morph weights; the loader turns them into clip curves. Play them like any other glTF animation; see glTF animation.
Setting weights yourself#
Change the weights through MorphWeights::weights_mut():
fn blink(time: Res<Time>, mut morphs: Query<&mut MorphWeights>) {
let w = (time.elapsed_secs() * 4.0).sin().max(0.0);
for mut morph in &mut morphs {
if let Some(first) = morph.weights_mut().first_mut() {
*first = w;
}
}
}An animation that also drives these weights overwrites what you write, so do one or the other per mesh.
Target names#
glTF files can name their targets. Mesh::morph_target_names() returns them, so you can find a target's index by name:
fn list_targets(mut events: MessageReader<AssetEvent<Mesh>>, meshes: Res<Assets<Mesh>>) {
for event in events.read() {
if let AssetEvent::Added { id } = event
&& let Some(names) = meshes.get(*id).and_then(|m| m.morph_target_names())
{
info!("morph targets: {names:?}");
}
}
}MorphWeights::first_mesh() gives the handle of the first mesh the weights control, to look its names up.
Limits#
A mesh can have up to 256 morph targets (MAX_MORPH_WEIGHTS). Morph data is stored in a texture at most 2048 × 2048 values, so very dense meshes with many targets can run out of room.
Faces in NEO#
NEO's own deformation crate, neo_deform, adds a CPU path for skinning (linear and dual quaternion), sparse morphs, corrective pose drivers and simple faces driven by the 52 common face-tracking channels. It's a library you call yourself, separate from MorphWeights and the renderer.
Examples: cargo run --example morph_targets.