fileFormats.importGltf

Polygon geometry from a GLB or glTF 2.0 JSON file’s default scene, its node tree flattened in f64, with ids in file order.

GeometricSince 0.18.0

Usage

TypeScript
FileFormats.importGltf(file: Uint8Array, options?: FileImportGltfOptions): Result<FileImport>

Parameters

  • fileUint8Array

    A GLB, or glTF JSON (metres, +Y up by its specification).

    Required

  • options.scopestring

    The importing node’s id; ids are minted under it. Default undefined (index ids, minter 0).

  • options.resourcesReadonly<Record<string, Uint8Array>>

    External buffers by URI, exactly as the file writes it; nothing is fetched. Default {}.

Returns

Ok with a FileImport, as importStl: each TRIANGLES primitive’s vertices are its points and each triangle a face, in node order; no weld across primitives.

Errors

Guarantees

  • under a mirroring transform each triangle’s winding is reversed, so faces still face out
  • the same bytes and options give the same transport and ref on every target
  • The same result on every machine.

Example

TypeScript
const r = FileFormats.importGltf(new Uint8Array(12))
r.ok || r.diagnostics[0].code // → IO_MALFORMED for a GLB with no chunks once loadKernelIo() has run

See also