pub struct Document { /* private fields */ }Expand description
Semantically lossless glTF JSON document.
Implementations§
Source§impl Document
impl Document
Sourcepub fn from_json_bytes(bytes: &[u8]) -> Result<Self>
pub fn from_json_bytes(bytes: &[u8]) -> Result<Self>
Parses a JSON document, retaining the exact source bytes until mutation.
let bytes = br#"{"asset":{"version":"2.0"},"meshes":[]}"#;
let document = Document::from_json_bytes(bytes)?;
assert_eq!(document.meshes().len(), 0);Sourcepub fn from_value(root: Value) -> Result<Self>
pub fn from_value(root: Value) -> Result<Self>
Creates a document from a JSON value.
Sourcepub fn as_value_mut(&mut self) -> &mut Value
pub fn as_value_mut(&mut self) -> &mut Value
Returns mutable JSON and marks the source representation dirty.
Sourcepub fn to_json_bytes(&self) -> Result<Vec<u8>>
pub fn to_json_bytes(&self) -> Result<Vec<u8>>
Serializes JSON, preserving original bytes when the document is untouched.
let source = br#"{ "asset": { "version": "2.0" } }"#;
let document = Document::from_json_bytes(source)?;
assert_eq!(document.to_json_bytes()?, source);Sourcepub fn to_minified_json_bytes(&self) -> Vec<u8> ⓘ
pub fn to_minified_json_bytes(&self) -> Vec<u8> ⓘ
Serializes the current DOM without insignificant JSON whitespace.
Unlike Document::to_json_bytes, this always serializes the parsed
value, even when the document has not been changed. Object order and
number lexemes are retained; keys and numbers are not normalized.
let document = Document::from_json_bytes(
br#"{ "asset": { "version": "2.0" } }"#,
)?;
assert_eq!(
document.to_minified_json_bytes(),
br#"{"asset":{"version":"2.0"}}"#,
);Sourcepub fn validate(&self, profile: ValidationProfile) -> Result<()>
pub fn validate(&self, profile: ValidationProfile) -> Result<()>
Performs basic structural checks, plus strict graph checks when enabled.
Enable the strict-validation feature to additionally check core
references, node trees, and finite ordered POSITION bounds. Compact
readers retain local bounds checks while materializing individual data.
Sourcepub fn accessors(&self) -> Objects<'_, AccessorIndex>
pub fn accessors(&self) -> Objects<'_, AccessorIndex>
Iterates over accessor objects in document order.
Sourcepub fn accessor(&self, index: AccessorIndex) -> Option<Accessor<'_>>
pub fn accessor(&self, index: AccessorIndex) -> Option<Accessor<'_>>
Returns one accessor view by typed index.
Sourcepub fn animations(&self) -> Objects<'_, AnimationIndex>
pub fn animations(&self) -> Objects<'_, AnimationIndex>
Iterates over animation objects in document order.
Sourcepub fn animation(&self, index: AnimationIndex) -> Option<Animation<'_>>
pub fn animation(&self, index: AnimationIndex) -> Option<Animation<'_>>
Returns one animation view by typed index.
Sourcepub fn buffers(&self) -> Objects<'_, BufferIndex>
pub fn buffers(&self) -> Objects<'_, BufferIndex>
Iterates over buffer objects in document order.
Sourcepub fn buffer(&self, index: BufferIndex) -> Option<Buffer<'_>>
pub fn buffer(&self, index: BufferIndex) -> Option<Buffer<'_>>
Returns one buffer view by typed index.
Sourcepub fn buffer_views(&self) -> Objects<'_, BufferViewIndex>
pub fn buffer_views(&self) -> Objects<'_, BufferViewIndex>
Iterates over buffer-view objects in document order.
Sourcepub fn buffer_view(&self, index: BufferViewIndex) -> Option<BufferView<'_>>
pub fn buffer_view(&self, index: BufferViewIndex) -> Option<BufferView<'_>>
Returns one buffer-view by typed index.
Sourcepub fn cameras(&self) -> Objects<'_, CameraIndex>
pub fn cameras(&self) -> Objects<'_, CameraIndex>
Iterates over camera objects in document order.
Sourcepub fn external_assets(&self) -> Objects<'_, ExternalAssetIndex>
pub fn external_assets(&self) -> Objects<'_, ExternalAssetIndex>
Iterates over draft external-asset declarations.
Sourcepub fn external_asset(
&self,
index: ExternalAssetIndex,
) -> Option<ExternalAsset<'_>>
pub fn external_asset( &self, index: ExternalAssetIndex, ) -> Option<ExternalAsset<'_>>
Returns one external-asset declaration by typed index.
Sourcepub fn camera(&self, index: CameraIndex) -> Option<Camera<'_>>
pub fn camera(&self, index: CameraIndex) -> Option<Camera<'_>>
Returns one camera view by typed index.
Sourcepub fn file(&self, index: FileIndex) -> Option<File<'_>>
pub fn file(&self, index: FileIndex) -> Option<File<'_>>
Returns one packaged-file view by typed index.
Sourcepub fn images(&self) -> Objects<'_, ImageIndex>
pub fn images(&self) -> Objects<'_, ImageIndex>
Iterates over image objects in document order.
Sourcepub fn image(&self, index: ImageIndex) -> Option<Image<'_>>
pub fn image(&self, index: ImageIndex) -> Option<Image<'_>>
Returns one image view by typed index.
Sourcepub fn materials(&self) -> Objects<'_, MaterialIndex>
pub fn materials(&self) -> Objects<'_, MaterialIndex>
Iterates over material objects in document order.
Sourcepub fn material(&self, index: MaterialIndex) -> Option<Material<'_>>
pub fn material(&self, index: MaterialIndex) -> Option<Material<'_>>
Returns one material view by typed index.
Sourcepub fn samplers(&self) -> Objects<'_, SamplerIndex>
pub fn samplers(&self) -> Objects<'_, SamplerIndex>
Iterates over sampler objects in document order.
Sourcepub fn sampler(&self, index: SamplerIndex) -> Option<Sampler<'_>>
pub fn sampler(&self, index: SamplerIndex) -> Option<Sampler<'_>>
Returns one sampler view by typed index.
Sourcepub fn scenes(&self) -> Objects<'_, SceneIndex>
pub fn scenes(&self) -> Objects<'_, SceneIndex>
Iterates over scene objects in document order.
Sourcepub fn scene(&self, index: SceneIndex) -> Option<Scene<'_>>
pub fn scene(&self, index: SceneIndex) -> Option<Scene<'_>>
Returns one scene view by typed index.
Sourcepub fn default_scene(&self) -> Option<SceneIndex>
pub fn default_scene(&self) -> Option<SceneIndex>
Returns the document’s preferred scene index, if declared.
Sourcepub fn thumbnail(&self) -> Option<ImageIndex>
pub fn thumbnail(&self) -> Option<ImageIndex>
Returns the optional draft thumbnail image declared by asset.thumbnail.
Sourcepub fn shapes(&self) -> Objects<'_, ShapeIndex>
pub fn shapes(&self) -> Objects<'_, ShapeIndex>
Iterates over draft shape declarations.
Sourcepub fn shape(&self, index: ShapeIndex) -> Option<Shape<'_>>
pub fn shape(&self, index: ShapeIndex) -> Option<Shape<'_>>
Returns one shape view by typed index.
Sourcepub fn textures(&self) -> Objects<'_, TextureIndex>
pub fn textures(&self) -> Objects<'_, TextureIndex>
Iterates over texture objects in document order.
Sourcepub fn texture(&self, index: TextureIndex) -> Option<Texture<'_>>
pub fn texture(&self, index: TextureIndex) -> Option<Texture<'_>>
Returns one texture view by typed index.