vrm-runtime 0.1.0

Renderer-agnostic VRM 1.0 loader, validator, animation system, and runtime
Documentation
use std::fmt;

macro_rules! define_id {
    ($name:ident, $label:literal) => {
        #[doc = concat!("A stable identifier for an avatar ", $label, ".")]
        #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
        pub struct $name(u32);

        impl $name {
            /// Creates an identifier from an index supplied to an asset builder.
            ///
            /// [`crate::AvatarAssetBuilder::build`] rejects identifiers that do
            /// not resolve inside the completed asset.
            pub const fn from_index(index: usize) -> Self {
                Self(index as u32)
            }

            /// Returns the index used by the immutable asset storage.
            pub const fn index(self) -> usize {
                self.0 as usize
            }
        }

        impl fmt::Display for $name {
            fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
                self.0.fmt(formatter)
            }
        }
    };
}

define_id!(NodeId, "node");
define_id!(PrimitiveId, "render primitive");
define_id!(MaterialId, "material");
define_id!(TextureId, "texture");
define_id!(ImageId, "image");
define_id!(SkinId, "skin");