Skip to content

dsgallups/bevy_gltf_animation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

This video is taken from examples/transitions.rs.

Screencast.from.2025-06-19.17-54-03.webm
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 animations {
        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!

About

No description, website, or topics provided.

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages