Skip to main content

FrameView

Struct FrameView 

Source
pub struct FrameView<'a> { /* private fields */ }
Expand description

A zero-copy view of the most recently evaluated frame.

Implementations§

Source§

impl<'a> FrameView<'a>

Source

pub fn gpu(self) -> GpuFrameView<'a>

Returns GPU-oriented draw data without copying frame buffers.

Each GpuDraw combines immutable primitive attributes with the current world matrix, morph weights, joint matrices, and evaluated material data required by a renderer.

Examples found in repository?
examples/vrma.rs (line 35)
8fn main() -> Result<(), Box<dyn std::error::Error>> {
9    let mut arguments = std::env::args().skip(1);
10    let avatar_path = arguments
11        .next()
12        .expect("usage: vrma <avatar.vrm> <motion.vrma>");
13    let animation_path = arguments
14        .next()
15        .expect("usage: vrma <avatar.vrm> <motion.vrma>");
16
17    let avatar = AvatarAsset::load(avatar_path)?;
18    let animation = VrmAnimation::load(animation_path)?;
19    let duration = animation.duration();
20    let mut runtime = AvatarRuntime::new(avatar);
21
22    runtime.play(
23        animation,
24        PlaybackOptions {
25            mode: PlaybackMode::Once,
26            ..PlaybackOptions::default()
27        },
28    )?;
29
30    let delta_seconds = 1.0 / 60.0;
31    let frame_count = ((duration / delta_seconds).ceil() as usize).max(1) + 1;
32    for frame_index in 0..frame_count {
33        let (draw_count, bone_update_count) = {
34            let frame = runtime.update(delta_seconds)?;
35            (frame.gpu().draws().len(), frame.bone_updates().len())
36        };
37
38        if frame_index % 60 == 0 || !runtime.is_playing() {
39            println!(
40                "time={:.3}s draws={} bone_updates={}",
41                runtime.playback_time().unwrap_or(0.0),
42                draw_count,
43                bone_update_count,
44            );
45        }
46        if !runtime.is_playing() {
47            break;
48        }
49    }
50
51    Ok(())
52}
Source

pub fn bake_cpu(self) -> Vec<CpuMesh>

Applies morphing, skinning, and world transforms on the CPU.

The returned CpuMesh values contain world-space vertices and can be rendered without morph-target or skinning shader stages.

Examples found in repository?
examples/basic.rs (line 22)
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}
Source

pub fn bake_cpu_for(self, camera: CameraMode) -> Vec<CpuMesh>

Bakes CPU meshes with VRM first-person visibility already applied.

Source

pub fn to_owned(self) -> FrameSnapshot

Clones this frame into an independently owned snapshot.

Source

pub fn world_matrices(self) -> &'a [Mat4]

Returns current world matrices in avatar node order.

Source

pub fn skinning_palettes(self) -> &'a [SkinningPalette]

Returns current joint-matrix palettes in skin order.

Source

pub fn morph_updates(self) -> &'a [MorphTargetUpdate]

Returns expression-produced morph target updates.

Source

pub fn material_color_updates(self) -> &'a [MaterialColorUpdate]

Returns expression-produced material color updates.

Source

pub fn texture_transform_updates(self) -> &'a [TextureTransformUpdate]

Returns expression-produced texture transform updates.

Source

pub fn evaluated_materials(self) -> &'a [EvaluatedMaterial]

Returns renderer-ready dynamic values for every material in the asset.

Source

pub fn evaluated_material(self, id: MaterialId) -> Option<&'a EvaluatedMaterial>

Resolves one renderer-ready material value by its stable identifier.

Source

pub fn bone_updates(self) -> &'a [BoneUpdate]

Returns local humanoid bone updates applied to this frame.

Examples found in repository?
examples/vrma.rs (line 35)
8fn main() -> Result<(), Box<dyn std::error::Error>> {
9    let mut arguments = std::env::args().skip(1);
10    let avatar_path = arguments
11        .next()
12        .expect("usage: vrma <avatar.vrm> <motion.vrma>");
13    let animation_path = arguments
14        .next()
15        .expect("usage: vrma <avatar.vrm> <motion.vrma>");
16
17    let avatar = AvatarAsset::load(avatar_path)?;
18    let animation = VrmAnimation::load(animation_path)?;
19    let duration = animation.duration();
20    let mut runtime = AvatarRuntime::new(avatar);
21
22    runtime.play(
23        animation,
24        PlaybackOptions {
25            mode: PlaybackMode::Once,
26            ..PlaybackOptions::default()
27        },
28    )?;
29
30    let delta_seconds = 1.0 / 60.0;
31    let frame_count = ((duration / delta_seconds).ceil() as usize).max(1) + 1;
32    for frame_index in 0..frame_count {
33        let (draw_count, bone_update_count) = {
34            let frame = runtime.update(delta_seconds)?;
35            (frame.gpu().draws().len(), frame.bone_updates().len())
36        };
37
38        if frame_index % 60 == 0 || !runtime.is_playing() {
39            println!(
40                "time={:.3}s draws={} bone_updates={}",
41                runtime.playback_time().unwrap_or(0.0),
42                draw_count,
43                bone_update_count,
44            );
45        }
46        if !runtime.is_playing() {
47            break;
48        }
49    }
50
51    Ok(())
52}

Trait Implementations§

Source§

impl<'a> Clone for FrameView<'a>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Copy for FrameView<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for FrameView<'a>

§

impl<'a> RefUnwindSafe for FrameView<'a>

§

impl<'a> Send for FrameView<'a>

§

impl<'a> Sync for FrameView<'a>

§

impl<'a> Unpin for FrameView<'a>

§

impl<'a> UnsafeUnpin for FrameView<'a>

§

impl<'a> UnwindSafe for FrameView<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.