Skip to main content

vrm_runtime/
lib.rs

1#![deny(missing_docs)]
2#![deny(rustdoc::broken_intra_doc_links)]
3#![doc = include_str!("../README.md")]
4
5/// VRMA loading, typed animation tracks, sampling, and retargeting metadata.
6pub mod animation;
7/// Immutable VRM assets and strict or permissive file loading.
8pub mod avatar;
9/// Validated construction of complete programmatic avatar assets.
10pub mod builder;
11/// VRM node-constraint data and low-level constraint evaluation.
12pub mod constraint;
13/// Loader capabilities, validation modes, and recoverable diagnostics.
14pub mod diagnostic;
15/// Errors produced while loading or constructing assets.
16pub mod error;
17/// Renderer-ready material values after expressions and UV animation.
18pub mod evaluated_material;
19/// VRM expressions, binds, overrides, and evaluated updates.
20pub mod expressions;
21mod extension_declarations;
22/// First-person visibility annotations and automatic mesh separation.
23pub mod first_person;
24/// Humanoid bone definitions and validated node mappings.
25pub mod humanoid;
26/// Type-safe identifiers for objects stored in an avatar asset.
27pub mod id;
28/// Encoded PNG and JPEG image data retained by the loader.
29pub mod image;
30/// Low-level mutable avatar controls and frame evaluation results.
31pub mod instance;
32/// LookAt configuration and gaze-angle conversion.
33pub mod look_at;
34/// glTF, unlit, and MToon material and texture data.
35pub mod material;
36/// VRM authorship, licensing, and usage-permission metadata.
37pub mod meta;
38/// Morph-target vertex deltas.
39pub mod morph_target;
40/// Avatar node transforms and low-level world or joint matrix calculation.
41pub mod node;
42/// Canonical renderer geometry and validated primitive construction.
43pub mod primitive;
44/// CPU-side deformation output.
45pub mod render;
46/// High-level animation, expression, constraint, and SpringBone evaluation.
47pub mod runtime;
48/// Skin joints and inverse-bind matrices.
49pub mod skin;
50/// SpringBone colliders, chains, validation, and simulation.
51pub mod spring_bone;
52/// Renderer-independent translation, rotation, and scale values.
53pub mod transform;
54
55pub use animation::{
56    AnimationLoadError, AnimationLoadOutcome, BoneTrack, Interpolation, Keyframe,
57    SourceBoneRestPose, Track, TrackValue, VrmAnimation,
58};
59pub(crate) use avatar::AvatarAsset as Avatar;
60pub use avatar::{AvatarAsset, LoadOutcome};
61pub use builder::AvatarAssetBuilder;
62pub use constraint::{
63    AimAxis, AimConstraint, NodeConstraint, NodeConstraintKind, RollAxis, RollConstraint,
64    RotationConstraint, solve_constraints,
65};
66pub use diagnostic::{Capabilities, Diagnostic, DiagnosticSeverity, LoadOptions, ValidationMode};
67pub use error::{BuildError, LoadError};
68pub use evaluated_material::{EvaluatedMaterial, UvAnimationState};
69pub use expressions::{
70    Expression, ExpressionEvaluation, ExpressionOverrideType, Expressions, MaterialColorBind,
71    MaterialColorType, MaterialColorUpdate, MorphTargetBind, MorphTargetUpdate,
72    TextureTransformBind, TextureTransformUpdate,
73};
74pub use first_person::{AutoSplit, CameraMode, FirstPerson, FirstPersonFlag, MeshAnnotation};
75pub use humanoid::{HumanBone, HumanBoneNode, Humanoid};
76pub use id::{ImageId, MaterialId, NodeId, PrimitiveId, SkinId, TextureId};
77pub use image::AvatarImage;
78pub use instance::{AvatarEvaluation, AvatarInstance, BoneUpdate};
79pub use look_at::{LookAt, LookAtRangeMap, LookAtType, calc_yaw_pitch};
80pub use material::{
81    AlphaMode, AvatarTexture, EmissiveStrengthSource, MToonMaterial, MagFilter, Material,
82    MaterialShadingModel, MinFilter, NormalTextureInfo, OcclusionTextureInfo, OutlineWidthMode,
83    TextureInfo, TextureSampler, TextureTransform, WrapMode,
84};
85pub use meta::{
86    AvatarMeta, AvatarPermission, AvatarPermissions, CommercialUsage, CreditNotation,
87    ModificationPermission,
88};
89pub use morph_target::MorphTarget;
90pub use node::{AvatarNode, compute_joint_matrices, compute_world_matrices};
91pub use primitive::{
92    MorphedVertices, PrimitiveTopology, RenderPrimitive, RenderPrimitiveBuilder, SkinningSet,
93};
94pub use render::CpuMesh;
95pub use runtime::{
96    AvatarRuntime, ControlError, FrameSnapshot, FrameView, GpuDraw, GpuFrameView, PlaybackMode,
97    PlaybackOptions, RuntimeError, RuntimeOptions, SkinningPalette,
98};
99pub use skin::Skin;
100pub use spring_bone::{
101    ColliderShape, SpringBone, SpringBoneSimulator, SpringChain, SpringCollider,
102    SpringColliderGroup, SpringJoint,
103};
104pub use transform::Transform;
105
106#[cfg(test)]
107mod tests {
108    use super::*;
109    use vrm_spec::vrmc_vrm_1_0::VRMCVrmSchema;
110
111    #[test]
112    fn test_avatar_default() {
113        let avatar = Avatar::new();
114        assert_eq!(avatar.meta().name(), "");
115        assert_eq!(avatar.meta().version(), None);
116        assert!(avatar.meta().authors().is_empty());
117    }
118
119    #[test]
120    fn test_avatar_from_invalid_bytes() {
121        let result = Avatar::from_bytes(&[]);
122        assert!(result.is_err());
123    }
124
125    #[test]
126    fn test_corrupted_meta_json_deserialization() {
127        let invalid_meta_json = serde_json::json!({
128            "specVersion": "1.0",
129            "meta": {
130                "copyrightInformation": "invalid meta without name and authors"
131            }
132        });
133
134        let parsed: Result<VRMCVrmSchema, _> = serde_json::from_value(invalid_meta_json);
135        assert!(
136            parsed.is_err(),
137            "malformed meta JSON must fail deserialization"
138        );
139    }
140}