Skip to main content

Document

Struct Document 

Source
pub struct Document { /* private fields */ }
Expand description

Semantically lossless glTF JSON document.

Implementations§

Source§

impl Document

Source

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);
Source

pub fn from_value(root: Value) -> Result<Self>

Creates a document from a JSON value.

Source

pub fn as_value(&self) -> &Value

Returns the complete lossless JSON value.

Source

pub fn as_value_mut(&mut self) -> &mut Value

Returns mutable JSON and marks the source representation dirty.

Source

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);
Source

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"}}"#,
);
Source

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.

Source

pub fn accessors(&self) -> Objects<'_, AccessorIndex>

Iterates over accessor objects in document order.

Source

pub fn accessor(&self, index: AccessorIndex) -> Option<Accessor<'_>>

Returns one accessor view by typed index.

Source

pub fn animations(&self) -> Objects<'_, AnimationIndex>

Iterates over animation objects in document order.

Source

pub fn animation(&self, index: AnimationIndex) -> Option<Animation<'_>>

Returns one animation view by typed index.

Source

pub fn buffers(&self) -> Objects<'_, BufferIndex>

Iterates over buffer objects in document order.

Source

pub fn buffer(&self, index: BufferIndex) -> Option<Buffer<'_>>

Returns one buffer view by typed index.

Source

pub fn buffer_views(&self) -> Objects<'_, BufferViewIndex>

Iterates over buffer-view objects in document order.

Source

pub fn buffer_view(&self, index: BufferViewIndex) -> Option<BufferView<'_>>

Returns one buffer-view by typed index.

Source

pub fn cameras(&self) -> Objects<'_, CameraIndex>

Iterates over camera objects in document order.

Source

pub fn external_assets(&self) -> Objects<'_, ExternalAssetIndex>

Iterates over draft external-asset declarations.

Source

pub fn external_asset( &self, index: ExternalAssetIndex, ) -> Option<ExternalAsset<'_>>

Returns one external-asset declaration by typed index.

Source

pub fn camera(&self, index: CameraIndex) -> Option<Camera<'_>>

Returns one camera view by typed index.

Source

pub fn files(&self) -> Objects<'_, FileIndex>

Iterates over draft packaged-file declarations.

Source

pub fn file(&self, index: FileIndex) -> Option<File<'_>>

Returns one packaged-file view by typed index.

Source

pub fn images(&self) -> Objects<'_, ImageIndex>

Iterates over image objects in document order.

Source

pub fn image(&self, index: ImageIndex) -> Option<Image<'_>>

Returns one image view by typed index.

Source

pub fn materials(&self) -> Objects<'_, MaterialIndex>

Iterates over material objects in document order.

Source

pub fn material(&self, index: MaterialIndex) -> Option<Material<'_>>

Returns one material view by typed index.

Source

pub fn meshes(&self) -> Objects<'_, MeshIndex>

Iterates over mesh objects in document order.

Source

pub fn mesh(&self, index: MeshIndex) -> Option<Mesh<'_>>

Returns one mesh view by typed index.

Source

pub fn nodes(&self) -> Objects<'_, NodeIndex>

Iterates over node objects in document order.

Source

pub fn node(&self, index: NodeIndex) -> Option<Node<'_>>

Returns one node view by typed index.

Source

pub fn samplers(&self) -> Objects<'_, SamplerIndex>

Iterates over sampler objects in document order.

Source

pub fn sampler(&self, index: SamplerIndex) -> Option<Sampler<'_>>

Returns one sampler view by typed index.

Source

pub fn scenes(&self) -> Objects<'_, SceneIndex>

Iterates over scene objects in document order.

Source

pub fn scene(&self, index: SceneIndex) -> Option<Scene<'_>>

Returns one scene view by typed index.

Source

pub fn default_scene(&self) -> Option<SceneIndex>

Returns the document’s preferred scene index, if declared.

Source

pub fn thumbnail(&self) -> Option<ImageIndex>

Returns the optional draft thumbnail image declared by asset.thumbnail.

Source

pub fn shapes(&self) -> Objects<'_, ShapeIndex>

Iterates over draft shape declarations.

Source

pub fn shape(&self, index: ShapeIndex) -> Option<Shape<'_>>

Returns one shape view by typed index.

Source

pub fn skins(&self) -> Objects<'_, SkinIndex>

Iterates over skin objects in document order.

Source

pub fn skin(&self, index: SkinIndex) -> Option<Skin<'_>>

Returns one skin view by typed index.

Source

pub fn textures(&self) -> Objects<'_, TextureIndex>

Iterates over texture objects in document order.

Source

pub fn texture(&self, index: TextureIndex) -> Option<Texture<'_>>

Returns one texture view by typed index.

Source

pub fn primitive( &self, mesh: MeshIndex, primitive: usize, ) -> Option<PrimitiveRef<'_>>

Returns a primitive addressed by stable mesh and primitive indices.

Trait Implementations§

Source§

impl Clone for Document

Source§

fn clone(&self) -> Document

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Document

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.