bevy_gltf_animation

Crates.iobevy_gltf_animation
lib.rsbevy_gltf_animation
version0.2.0
created_at2025-05-11 20:51:33.796152+00
updated_at2025-06-01 00:58:26.422018+00
descriptionMinimal animation setup for gltf files
homepage
repositoryhttps://github.com/dsgallups/bevy_gltf_animation
max_upload_size
id1669742
size157,913
Daniel Gallups (dsgallups)

documentation

https://docs.rs/bevy_gltf_animation

README

Easy animations for GLTF files

github crates.io

Purpose

GLTF files include animations in their files. Importing them into bevy can be tedious, especially if you don't plan to blend any animations.

This crate automatically creates a handler for your animations per scene root based on the imported GLTF file.

Example

use bevy::prelude::*;
use bevy_gltf_animation::prelude::*;

fn main() {
    App::new()
        .add_plugins((DefaultPlugins, GltfAnimationPlugin))
        .add_systems(Startup, setup)
        .add_systems(Update, play_animations)
        .run();
}


fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
    // spawns a SceneRoot and GltfAnimations on this component
    commands.spawn(GltfSceneRoot::new(asset_server.load("human.glb")));
}
// once gltf animations have been added, play animation 2.
fn play_animations(
    animations: Query<&mut GltfAnimations, Added<GltfAnimations>>,
    mut players: Query<&mut AnimationPlayer>,
) {
    for mut gltf_animations in animations {
        let index = gltf_animations.get(2).unwrap();
        // if named, you can use
        // let index = gltf_animations.get("Walking_Forward").unwrap()
        let mut player = players.get_mut(gltf_animations.animation_player).unwrap();
        player.play(index);
    }
}

With the extended feature

use bevy::prelude::*;
use bevy_gltf_animation::prelude::*;

fn main() {
    App::new()
        .add_plugins((DefaultPlugins, GltfAnimationPlugin))
        .add_systems(Startup, setup)
        .add_systems(Update, play_animations)
        .run();
}


fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
    // spawns a SceneRoot and GltfAnimations on this component
    commands.spawn(GltfSceneRoot::new(asset_server.load("human.glb")));
}


fn play_animations(
    animations: Query<&mut GltfAnimations, Added<GltfAnimations>>,
) {
    for mut animation_player in humans {
        animation_player.play(2);
    }
}

Contributing/Suggestions

This crate does one thing, but I want it to do that thing very well. Please describe your usecase in an issue or PR if you are looking for particular functionality!

Commit count: 27

cargo fmt