| Crates.io | bevy_gltf_animation |
| lib.rs | bevy_gltf_animation |
| version | 0.2.0 |
| created_at | 2025-05-11 20:51:33.796152+00 |
| updated_at | 2025-06-01 00:58:26.422018+00 |
| description | Minimal animation setup for gltf files |
| homepage | |
| repository | https://github.com/dsgallups/bevy_gltf_animation |
| max_upload_size | |
| id | 1669742 |
| size | 157,913 |
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.
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);
}
}
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!