Skip to main content

GltfReader

Struct GltfReader 

Source
pub struct GltfReader { /* private fields */ }
Available on crate feature gltf-reader only.
Expand description

A reader for glTF/GLB files with Draco mesh decompression support.

Implementations§

Source§

impl GltfReader

Source

pub fn open<P: AsRef<Path>>(path: P) -> Result<Self>

Open a glTF or GLB file.

The file type is detected automatically based on the magic bytes.

Source

pub fn from_glb(data: &[u8]) -> Result<Self>

Parse from GLB binary data.

Source

pub fn from_bytes(data: &[u8]) -> Result<Self>

Parse from glTF JSON or GLB binary data.

The payload type is detected automatically from the GLB magic bytes. For glTF JSON with external buffers, use Self::from_bytes_with_base_path.

Source

pub fn from_bytes_with_base_path( data: &[u8], base_path: Option<&Path>, ) -> Result<Self>

Parse from glTF JSON or GLB binary data with an optional base path for external buffers.

Source

pub fn from_gltf(json_data: &[u8], base_path: Option<&Path>) -> Result<Self>

Parse from glTF JSON data with optional base path for external buffers.

Source

pub fn from_bytes_lenient(data: &[u8]) -> Result<Self>

Parse glTF/GLB bytes, decoding geometry even when the asset uses scene features this crate does not model (skins, animations, morph targets).

Unlike Self::from_bytes, which rejects such assets, this reader ignores those features and decodes only geometry. Use it to read meshes out of skinned or animated assets, including the output of crate::compress_gltf_bytes for those assets. Per-primitive decoding still fails for unsupported attribute layouts.

Source

pub fn from_bytes_lenient_with_base_path( data: &[u8], base_path: Option<&Path>, ) -> Result<Self>

Like Self::from_bytes_lenient, with a base path for external buffers.

Source

pub fn from_value(doc: &Value, buffers: Vec<Vec<u8>>) -> Result<Self>

Builds a lenient reader from an already-parsed glTF document (doc) and its resolved buffer bytes.

This lets a caller that already holds a parsed scene and its buffers (for example a gltf-rs document and the bytes it resolved) decode geometry through this reader without serializing back to glTF/GLB bytes and re-resolving the buffers. The same lenient policy as Self::from_bytes_lenient applies: skins, animations, and morph targets are ignored (not rejected), and per-primitive decoding still fails for unsupported attribute layouts.

buffers must already be resolved and indexed by glTF buffer index; no URI or BIN-chunk resolution is performed here.

Source

pub fn decode_primitive_with_semantics( &self, mesh_idx: usize, prim_idx: usize, ) -> Result<(Mesh, Vec<(String, u32)>)>

Decode a single non-Draco primitive, returning the mesh and the (glTF semantic, Draco unique id) mapping for its attributes.

Used by the compressor to build the KHR_draco_mesh_compression attributes map with the original glTF semantic names (including TANGENT, JOINTS_n, WEIGHTS_n, extra TEXCOORD_n/COLOR_n, and custom _* attributes), which the Draco attribute model alone cannot preserve. Errors if the primitive is already Draco-compressed.

This is the geometry-decode callback expected by crate::compress_gltf_value, so a caller holding a parsed scene can drive the compressor: build a reader with Self::from_value and pass |mesh, prim| reader.decode_primitive_with_semantics(mesh, prim).

Source

pub fn has_draco_extension(&self) -> bool

Check if the glTF file uses Draco compression.

Source

pub fn draco_primitives(&self) -> Vec<DracoPrimitiveInfo>

Get information about all Draco-compressed primitives.

Source

pub fn get_draco_data(&self, info: &DracoPrimitiveInfo) -> Result<&[u8]>

Get the raw Draco-compressed data for a primitive.

Source

pub fn decode_draco_mesh(&self, info: &DracoPrimitiveInfo) -> Result<Mesh>

Decode a Draco-compressed primitive as a Mesh.

Source

pub fn decode_draco_point_cloud( &self, info: &DracoPrimitiveInfo, ) -> Result<PointCloud>

Available on crate feature point_cloud_decode only.

Decode a Draco-compressed primitive as a PointCloud.

Source

pub fn decode_all_draco_meshes(&self) -> Result<Vec<(DracoPrimitiveInfo, Mesh)>>

Decode all Draco-compressed primitives as meshes.

Source

pub fn num_meshes(&self) -> usize

Get the number of meshes in the glTF file.

Source

pub fn num_buffers(&self) -> usize

Get the number of buffers in the glTF file.

Source

pub fn extensions_used(&self) -> &[String]

Get the extensions used by this glTF file.

Source

pub fn extensions_required(&self) -> &[String]

Get the extensions required by this glTF file.

Source§

impl GltfReader

Source

pub fn decode_all_meshes(&self) -> Result<Vec<Mesh>>

Decode all primitives (both Draco and standard) as meshes.

Trait Implementations§

Source§

impl ReadFromBytes for GltfReader

Source§

fn from_bytes(bytes: &[u8]) -> Result<Self>

Create a reader from a complete file payload.
Source§

impl Reader for GltfReader

Source§

fn open<P: AsRef<Path>>(path: P) -> Result<Self>

Open a file for reading. Read more
Source§

fn read_meshes(&mut self) -> Result<Vec<Mesh>>

Read multiple meshes (a scene) from the file. Read more
Source§

fn read_mesh(&mut self) -> Result<Mesh>

Read a single mesh from the file. Read more
Source§

impl SceneReader for GltfReader

Source§

fn read_scene(&mut self) -> Result<Scene>

Available on crate feature scene only.
Read a single scene from the source/file.
Source§

fn read_scenes(&mut self) -> Result<Vec<Scene>>

Available on crate feature scene only.
Read all scenes (default: single scene wrapper).

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> 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, 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.