pub struct GltfReader { /* private fields */ }gltf-reader only.Expand description
A reader for glTF/GLB files with Draco mesh decompression support.
Implementations§
Source§impl GltfReader
impl GltfReader
Sourcepub fn open<P: AsRef<Path>>(path: P) -> Result<Self>
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.
Sourcepub fn from_bytes(data: &[u8]) -> Result<Self>
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.
Sourcepub fn from_bytes_with_base_path(
data: &[u8],
base_path: Option<&Path>,
) -> Result<Self>
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.
Sourcepub fn from_gltf(json_data: &[u8], base_path: Option<&Path>) -> Result<Self>
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.
Sourcepub fn from_bytes_lenient(data: &[u8]) -> Result<Self>
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.
Sourcepub fn from_bytes_lenient_with_base_path(
data: &[u8],
base_path: Option<&Path>,
) -> Result<Self>
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.
Sourcepub fn from_value(doc: &Value, buffers: Vec<Vec<u8>>) -> Result<Self>
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.
Sourcepub fn decode_primitive_with_semantics(
&self,
mesh_idx: usize,
prim_idx: usize,
) -> Result<(Mesh, Vec<(String, u32)>)>
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).
Sourcepub fn has_draco_extension(&self) -> bool
pub fn has_draco_extension(&self) -> bool
Check if the glTF file uses Draco compression.
Sourcepub fn draco_primitives(&self) -> Vec<DracoPrimitiveInfo>
pub fn draco_primitives(&self) -> Vec<DracoPrimitiveInfo>
Get information about all Draco-compressed primitives.
Sourcepub fn get_draco_data(&self, info: &DracoPrimitiveInfo) -> Result<&[u8]>
pub fn get_draco_data(&self, info: &DracoPrimitiveInfo) -> Result<&[u8]>
Get the raw Draco-compressed data for a primitive.
Sourcepub fn decode_draco_mesh(&self, info: &DracoPrimitiveInfo) -> Result<Mesh>
pub fn decode_draco_mesh(&self, info: &DracoPrimitiveInfo) -> Result<Mesh>
Decode a Draco-compressed primitive as a Mesh.
Sourcepub fn decode_draco_point_cloud(
&self,
info: &DracoPrimitiveInfo,
) -> Result<PointCloud>
Available on crate feature point_cloud_decode only.
pub fn decode_draco_point_cloud( &self, info: &DracoPrimitiveInfo, ) -> Result<PointCloud>
point_cloud_decode only.Decode a Draco-compressed primitive as a PointCloud.
Sourcepub fn decode_all_draco_meshes(&self) -> Result<Vec<(DracoPrimitiveInfo, Mesh)>>
pub fn decode_all_draco_meshes(&self) -> Result<Vec<(DracoPrimitiveInfo, Mesh)>>
Decode all Draco-compressed primitives as meshes.
Sourcepub fn num_meshes(&self) -> usize
pub fn num_meshes(&self) -> usize
Get the number of meshes in the glTF file.
Sourcepub fn num_buffers(&self) -> usize
pub fn num_buffers(&self) -> usize
Get the number of buffers in the glTF file.
Sourcepub fn extensions_used(&self) -> &[String]
pub fn extensions_used(&self) -> &[String]
Get the extensions used by this glTF file.
Sourcepub fn extensions_required(&self) -> &[String]
pub fn extensions_required(&self) -> &[String]
Get the extensions required by this glTF file.
Source§impl GltfReader
impl GltfReader
Sourcepub fn decode_all_meshes(&self) -> Result<Vec<Mesh>>
pub fn decode_all_meshes(&self) -> Result<Vec<Mesh>>
Decode all primitives (both Draco and standard) as meshes.