Skip to main content

read_glb

Function read_glb 

Source
pub fn read_glb(bytes: &[u8]) -> OgeomResult<Vec<ImportedMesh>>
Expand description

Read a GLB: glTF 2.0’s single-file binary form.

The whole indirection is honoured, because a writer chooses it and a reader does not get to assume: a primitive names accessors, an accessor names a buffer view and a component type, a view names a buffer and may stride over it, and any of them may be replaced piecewise by a sparse block. Every component type the standard defines is read (signed and unsigned bytes, shorts, unsigned ints and floats), with normalized honoured where it is set, which is the difference between a colour of 255 and a colour of 1.

The scene’s node hierarchy is walked and each node’s transform composed, stated as a matrix or as translation, rotation and scale; the geometry comes back placed. Normals are carried through the transform’s inverse transpose, which is what keeps them normal to a scaled surface.

What is not read is refused rather than approximated: a primitive whose mode is not triangles, a buffer that points at an external file this function cannot open, and a KHR_draco_mesh_compression payload, each by name.

§Errors

OgeomError::Construction for a file whose framing, JSON or indices do not hold together, and for the refusals above.