pub struct FrameView<'a> { /* private fields */ }Expand description
A zero-copy view of the most recently evaluated frame.
Implementations§
Source§impl<'a> FrameView<'a>
impl<'a> FrameView<'a>
Sourcepub fn gpu(self) -> GpuFrameView<'a>
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?
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}Sourcepub fn bake_cpu(self) -> Vec<CpuMesh>
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?
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}Sourcepub fn bake_cpu_for(self, camera: CameraMode) -> Vec<CpuMesh>
pub fn bake_cpu_for(self, camera: CameraMode) -> Vec<CpuMesh>
Bakes CPU meshes with VRM first-person visibility already applied.
Sourcepub fn to_owned(self) -> FrameSnapshot
pub fn to_owned(self) -> FrameSnapshot
Clones this frame into an independently owned snapshot.
Sourcepub fn world_matrices(self) -> &'a [Mat4]
pub fn world_matrices(self) -> &'a [Mat4]
Returns current world matrices in avatar node order.
Sourcepub fn skinning_palettes(self) -> &'a [SkinningPalette]
pub fn skinning_palettes(self) -> &'a [SkinningPalette]
Returns current joint-matrix palettes in skin order.
Sourcepub fn morph_updates(self) -> &'a [MorphTargetUpdate]
pub fn morph_updates(self) -> &'a [MorphTargetUpdate]
Returns expression-produced morph target updates.
Sourcepub fn material_color_updates(self) -> &'a [MaterialColorUpdate]
pub fn material_color_updates(self) -> &'a [MaterialColorUpdate]
Returns expression-produced material color updates.
Sourcepub fn texture_transform_updates(self) -> &'a [TextureTransformUpdate]
pub fn texture_transform_updates(self) -> &'a [TextureTransformUpdate]
Returns expression-produced texture transform updates.
Sourcepub fn evaluated_materials(self) -> &'a [EvaluatedMaterial]
pub fn evaluated_materials(self) -> &'a [EvaluatedMaterial]
Returns renderer-ready dynamic values for every material in the asset.
Sourcepub fn evaluated_material(self, id: MaterialId) -> Option<&'a EvaluatedMaterial>
pub fn evaluated_material(self, id: MaterialId) -> Option<&'a EvaluatedMaterial>
Resolves one renderer-ready material value by its stable identifier.
Sourcepub fn bone_updates(self) -> &'a [BoneUpdate]
pub fn bone_updates(self) -> &'a [BoneUpdate]
Returns local humanoid bone updates applied to this frame.
Examples found in repository?
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}