Expand description
load_source and load_source_bytes read .gltf/.glb input into
an immutable normalized-document plus raw-source-facts owner. load and
load_bytes retain the legacy document-only surface, and write::write
emits a document as
glTF/GLB, and the fix module provides byte-surgical quaternion
repairs. preflight_scale_source inventories the original raw source and
fails closed on domains that current scale producers cannot preserve.
Malformed inputs report LoadError; output failures
report WriteError.
This crate is the glTF/GLB format edge around animsmith-core.
Loading preserves authored animation values for checks and also carries
meshes, skins, materials, and embedded textures into
Document::assets.
Writing is a model round-trip for convert and transform; use
fix::FixSession when a repair must preserve every non-animation byte
of the original container.
§Quick start
Load a document and run the shared core checks:
fn lint_clip(
path: &std::path::Path,
) -> Result<Vec<animsmith_core::Finding>, Box<dyn std::error::Error>> {
let doc = animsmith_gltf::load(path)?;
let roles = animsmith_core::detect_profile(&doc.skeleton).unwrap_or_default();
let config = animsmith_core::Config::default();
let grids = animsmith_core::MetricGrids::new(&doc);
let ctx = animsmith_core::CheckCtx::new(&grids, &roles, &config);
let results = animsmith_core::evaluate_checks(
&ctx,
&animsmith_core::all_checks(),
animsmith_core::CheckSelection::All,
)?;
Ok(results
.into_iter()
.flat_map(|check| check.findings().to_vec())
.collect())
}Compose byte-surgical repairs through one session:
fn repair_quaternions(
input: &std::path::Path,
output: &std::path::Path,
) -> Result<(), Box<dyn std::error::Error>> {
use animsmith_gltf::fix::{FixSession, Repair};
let mut session = FixSession::read(input)?;
session.apply(Repair::QuatNorm);
session.apply(Repair::QuatFlip);
session.write(input, output)?;
Ok(())
}§Build and API status
This crate has no public feature flags and supports the workspace MSRV,
Rust 1.88. Its Rust API is pre-1.0; see animsmith-core’s crate-level API
status for the shared stability boundary.
See the GitHub embedding guide for crate selection and the pipeline scenario guide for raw-to-game-ready workflows.
Modules§
- fix
- Byte-surgical clip repairs: mutate only the animation accessor bytes that need to change and copy everything else through verbatim. A fixed character GLB keeps its meshes, skins, materials, and textures byte-identical — the output diff is exactly the repaired keys.
- write
- Minimal glTF 2.0 writer for
convert/transform: emits the skeleton (node hierarchy + rest TRS), each clip’s writable animation tracks, and whatever scene assets theDocumentcarries (Document::assets— triangulated meshes, skins, factor-only materials, and embedded base-color and normal textures). A document with default-empty assets writes animation + skeleton only, so animation data can still enter glTF-based tooling (including animsmith itself) straight from a DCC export.
Structs§
- Gltf
Accessor Capability - One raw accessor layout required by a future exact-source rewrite.
- Gltf
Animation Channel Capability - One animation channel and its exact accessor identities.
- Gltf
Attribute Capability - One vertex attribute declaration and its source accessor.
- Gltf
Buffer Capability - One source buffer recorded before normalized loading.
- Gltf
Buffer View Capability - One raw buffer-view layout.
- Gltf
Capability Manifest - Deterministic facts captured from the original glTF/GLB source.
- Gltf
Capability Violation - One deterministic, source-indexed preflight rejection.
- Gltf
Instancing Capability - One raw
EXT_mesh_gpu_instancingdeclaration and its accessor identities. - Gltf
Node Capability - One source node identity and authored rest representation.
- Gltf
Primitive Capability - One source primitive and every declared attribute semantic.
- Gltf
RawJson Difference - One value-free raw JSON difference found by an artifact preservation proof.
- Gltf
RawJson Difference Summary - Bounded raw JSON diagnostics for an artifact preservation proof failure.
- Gltf
Scale Artifact - A rewritten glTF/GLB container and the exact locations that changed.
- Gltf
Scale Artifact Proof - Observed artifact-level evidence from
prove_rewritten_artifactorsuper::prove_rewritten_rest_bind. - Gltf
Scale Source - A captured, immutable source that passed the common scale preflight.
- Gltf
Skin Capability - Read-side inverse-bind declaration for one source skin.
Enums§
- External
Resource Failure - Sanitized failure classes for external resources required by the loader.
- FixError
fixerrors are classified by defect, not by phase:LoadErrormeans the input was unreadable or malformed (even when detected while assembling the output, e.g. re-deriving GLB chunk bounds or validating an input-supplied buffer URI);WriteErrormeans emitting the output failed.- Gltf
Buffer Source Kind - How one source buffer was declared.
- Gltf
Capability Violation Kind - Stable machine identity for one fail-closed capability violation.
- Gltf
Container Kind - Whether the captured top-level source is JSON glTF or a binary GLB.
- Gltf
Node Rest Kind - Whether a node authored decomposed TRS or a matrix.
- Gltf
RawJson Difference Kind - The structural relationship of one raw JSON difference to the source.
- Gltf
Scale Preflight Error - Failure to load or safely preflight a captured scale source.
- Gltf
Scale Rewrite Error - Typed, fail-closed rejection from
rewrite_linear_unitsorprove_rewritten_artifact. - Load
Error - Errors returned while loading
.gltfor.glbinput. - Write
Error - Errors returned while writing a core document as glTF/GLB.
Functions§
- capability_
facts - Project a raw glTF capability manifest onto the format-neutral
ScaleCapabilityFactsthatanimsmith_core::scale::plan_scaleconsumes. - capability_
facts_ for_ source - Project scale capability facts from one immutable captured source.
- load
- Load a
.glbor.gltffile into a coreDocument, including the scene assets (meshes, skins, materials, and embedded base-color and normal textures) its geometry describes — the symmetric read side ofwrite::write, and the same one-call shapeanimsmith_fbx::loaduses. Consumers that judge only animation (lint,inspect) simply ignoreDocument::assets. Non-triangle primitives are skipped rather than reinterpreted. - load_
bytes - Load a
.glbor.gltfbyte slice into a coreDocument. - load_
bytes_ with_ resource_ root - Load captured bytes with an explicit trusted local root for external resources.
- load_
source - Load a
.gltfor.glbfile with immutable importer-sensitive source facts. - load_
source_ bytes - Load captured
.gltfor.glbbytes with immutable raw-source facts. - load_
source_ bytes_ with_ resource_ root - Load captured bytes with an explicit trusted local root for external resources.
- operation_
capability_ facts - Validate a raw glTF capability manifest for one selected scale operation.
- operation_
capability_ facts_ for_ source - Validate one captured glTF source for a selected scale operation.
- preflight_
scale_ source - Read and preflight a glTF/GLB file without creating a candidate or output.
- preflight_
scale_ source_ bytes - Preflight captured glTF/GLB bytes without creating a candidate or output.
- prove_
rewritten_ artifact - Independently re-derive and check every artifact-level claim.
- prove_
rewritten_ rest_ bind - Independently re-derive and check every artifact-level claim of the rest/bind reparameterization.
- rewrite_
linear_ units - Rewrite
source’s linear units by the caller-declared finitefactor > 0. - rewrite_
rest_ bind - Reparameterize
source’s rest/bind hierarchy, removing the compensating uniform factorexpected_factorfrom the closure anchored atsource_root_node_indexand the joints ofsource_skin_index. - rewrite_
scale_ plan - Apply one already-compiled core scale plan to the raw glTF source.