Skip to main content

basic/
basic.rs

1//! Minimal example: load a VRM file, step one frame and print the final
2//! render meshes (morphs, skinning and world transforms already applied).
3//!
4//! Run with:
5//! `cargo run --example basic -- <path/to/avatar.vrm>`
6
7use vrm_runtime::{AvatarAsset, AvatarRuntime};
8
9fn main() {
10    let path = std::env::args().nth(1).expect("usage: basic <avatar.vrm>");
11    let avatar = AvatarAsset::load(&path).expect("failed to load avatar");
12
13    println!("avatar: {}", avatar.meta().name());
14    println!("primitives: {}", avatar.primitives().len());
15
16    let mut runtime = AvatarRuntime::new(avatar);
17
18    // One frame with spring bones and constraints enabled by default.
19    let frame = runtime.update(1.0 / 60.0).expect("valid delta time");
20
21    // Bake fully transformed, renderer-ready CPU meshes on demand.
22    let meshes = frame.bake_cpu();
23    for mesh in &meshes {
24        println!(
25            "mesh(node {}): vertices={} indices={} topology={:?} material={:?}",
26            mesh.node_id,
27            mesh.positions.len(),
28            mesh.indices.len(),
29            mesh.topology,
30            mesh.material_id,
31        );
32    }
33}