Skip to main content

vrm_runtime/
diagnostic.rs

1/// Controls how recoverable VRM semantic violations are handled.
2#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
3pub enum ValidationMode {
4    /// Reject every supported VRM specification violation.
5    #[default]
6    Strict,
7    /// Keep loading when a violation cannot make the resulting asset unsafe.
8    Permissive,
9}
10
11/// Options shared by file and in-memory loading.
12#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
13pub struct LoadOptions {
14    /// Controls whether recoverable conformance violations are rejected or reported.
15    pub validation: ValidationMode,
16}
17
18/// Feature support exposed by this crate version.
19///
20/// Applications can use this value to decide whether to reject a model,
21/// offer a fallback, or route it through another implementation.
22#[derive(Debug, Clone, Copy, PartialEq, Eq)]
23pub struct Capabilities {
24    /// Supports VRM 1.0 assets.
25    pub vrm_1_0: bool,
26    /// Supports legacy VRM 0.x assets.
27    pub vrm_0_x: bool,
28    /// Supports `VRMC_materials_mtoon`.
29    pub mtoon: bool,
30    /// Supports `VRMC_node_constraint`.
31    pub node_constraints: bool,
32    /// Supports `VRMC_springBone`.
33    pub spring_bones: bool,
34    /// Supports standalone `VRMC_vrm_animation` assets.
35    pub vrma_loading: bool,
36    /// Supports the archived `VRMC_materials_hdr_emissiveMultiplier` extension.
37    pub hdr_emissive_multiplier: bool,
38    /// Supports `VRMC_springBone_extended_collider`.
39    pub extended_spring_colliders: bool,
40    /// Supports `KHR_materials_unlit` on VRM materials.
41    pub unlit_materials: bool,
42    /// Supports `KHR_materials_emissive_strength` on VRM materials.
43    pub emissive_strength: bool,
44    /// Supports per-texture `KHR_texture_transform` UV selection and transforms.
45    pub texture_transform: bool,
46}
47
48impl Capabilities {
49    /// Returns the feature set implemented by this crate version.
50    pub const fn current() -> Self {
51        Self {
52            vrm_1_0: true,
53            vrm_0_x: false,
54            mtoon: true,
55            node_constraints: true,
56            spring_bones: true,
57            vrma_loading: true,
58            hdr_emissive_multiplier: true,
59            extended_spring_colliders: true,
60            unlit_materials: true,
61            emissive_strength: true,
62            texture_transform: true,
63        }
64    }
65}
66
67/// Severity assigned to a loader diagnostic.
68#[derive(Debug, Clone, Copy, PartialEq, Eq)]
69pub enum DiagnosticSeverity {
70    /// A recoverable issue that did not prevent loading.
71    Warning,
72    /// An issue severe enough to invalidate the requested operation.
73    Error,
74}
75
76/// A machine-readable problem reported while loading an avatar.
77#[derive(Debug, Clone, PartialEq, Eq)]
78pub struct Diagnostic {
79    /// Severity assigned to the issue.
80    pub severity: DiagnosticSeverity,
81    /// Stable machine-readable identifier for the diagnostic kind.
82    pub code: &'static str,
83    /// JSON-style path to the value that produced the diagnostic.
84    pub path: String,
85    /// Human-readable explanation of the issue.
86    pub message: String,
87}
88
89impl Diagnostic {
90    pub(crate) fn warning(
91        code: &'static str,
92        path: impl Into<String>,
93        message: impl Into<String>,
94    ) -> Self {
95        Self {
96            severity: DiagnosticSeverity::Warning,
97            code,
98            path: path.into(),
99            message: message.into(),
100        }
101    }
102}