vrm-runtime 0.1.0

Renderer-agnostic VRM 1.0 loader, validator, animation system, and runtime
Documentation
/// Controls how recoverable VRM semantic violations are handled.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum ValidationMode {
    /// Reject every supported VRM specification violation.
    #[default]
    Strict,
    /// Keep loading when a violation cannot make the resulting asset unsafe.
    Permissive,
}

/// Options shared by file and in-memory loading.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct LoadOptions {
    /// Controls whether recoverable conformance violations are rejected or reported.
    pub validation: ValidationMode,
}

/// Feature support exposed by this crate version.
///
/// Applications can use this value to decide whether to reject a model,
/// offer a fallback, or route it through another implementation.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Capabilities {
    /// Supports VRM 1.0 assets.
    pub vrm_1_0: bool,
    /// Supports legacy VRM 0.x assets.
    pub vrm_0_x: bool,
    /// Supports `VRMC_materials_mtoon`.
    pub mtoon: bool,
    /// Supports `VRMC_node_constraint`.
    pub node_constraints: bool,
    /// Supports `VRMC_springBone`.
    pub spring_bones: bool,
    /// Supports standalone `VRMC_vrm_animation` assets.
    pub vrma_loading: bool,
    /// Supports the archived `VRMC_materials_hdr_emissiveMultiplier` extension.
    pub hdr_emissive_multiplier: bool,
    /// Supports `VRMC_springBone_extended_collider`.
    pub extended_spring_colliders: bool,
    /// Supports `KHR_materials_unlit` on VRM materials.
    pub unlit_materials: bool,
    /// Supports `KHR_materials_emissive_strength` on VRM materials.
    pub emissive_strength: bool,
    /// Supports per-texture `KHR_texture_transform` UV selection and transforms.
    pub texture_transform: bool,
}

impl Capabilities {
    /// Returns the feature set implemented by this crate version.
    pub const fn current() -> Self {
        Self {
            vrm_1_0: true,
            vrm_0_x: false,
            mtoon: true,
            node_constraints: true,
            spring_bones: true,
            vrma_loading: true,
            hdr_emissive_multiplier: true,
            extended_spring_colliders: true,
            unlit_materials: true,
            emissive_strength: true,
            texture_transform: true,
        }
    }
}

/// Severity assigned to a loader diagnostic.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DiagnosticSeverity {
    /// A recoverable issue that did not prevent loading.
    Warning,
    /// An issue severe enough to invalidate the requested operation.
    Error,
}

/// A machine-readable problem reported while loading an avatar.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Diagnostic {
    /// Severity assigned to the issue.
    pub severity: DiagnosticSeverity,
    /// Stable machine-readable identifier for the diagnostic kind.
    pub code: &'static str,
    /// JSON-style path to the value that produced the diagnostic.
    pub path: String,
    /// Human-readable explanation of the issue.
    pub message: String,
}

impl Diagnostic {
    pub(crate) fn warning(
        code: &'static str,
        path: impl Into<String>,
        message: impl Into<String>,
    ) -> Self {
        Self {
            severity: DiagnosticSeverity::Warning,
            code,
            path: path.into(),
            message: message.into(),
        }
    }
}