Constructs a new NodeIO service. Instances are reusable. By default, only NodeIO can only read/write paths on disk. To enable HTTP requests, provide a Fetch API implementation and enable setAllowNetwork.
Converts a GLB-formatted Uint8Array to a JSONDocument.
Sets the Logger used by this I/O instance. Defaults to Logger.DEFAULT_INSTANCE.
Reads a Document from the given URI.
Loads a URI and returns a JSONDocument struct, without parsing.
Converts a GLB-formatted Uint8Array to a Document.
Converts glTF-formatted JSON and a resource map to a Document.
Registers dependencies used (e.g. by extensions) in the I/O process.
Registers extensions, enabling I/O class to read and write glTF assets requiring them.
Sets whether missing external resources should throw errors (strict mode) or be ignored with warnings. Missing images can be ignored, but missing buffers will currently always result in an error. When strict mode is disabled and missing resources are encountered, the resulting Document will be created in an invalid state. Manual fixes to the Document may be necessary, resolving null images in Textures or removing the affected Textures, before the Document can be written to output or used in transforms.
Defaults to true (strict mode).
Sets the vertex layout method used by this I/O instance. Defaults to VertexLayout.INTERLEAVED.
Writes a Document instance to a local path.
Converts a Document to a GLB-formatted Uint8Array.
Converts a Document to glTF-formatted JSON and a resource map.
Made by Don McCurdy. Documentation built with greendoc and published under Creative Commons Attribution 3.0.
I/O service for Node.js.
The most common use of the I/O service is to read/write a Document with a given path. Methods are also available for converting in-memory representations of raw glTF files, both binary (Uint8Array) and JSON (JSONDocument).
Usage:
import { NodeIO } from '@gltf-transform/core'; const io = new NodeIO(); // Read. let document; document = await io.read('model.glb'); // → Document document = await io.readBinary(glb); // Uint8Array → Document // Write. await io.write('model.glb', document); // → void const glb = await io.writeBinary(document); // Document → Uint8ArrayBy default, NodeIO can only read/write paths on disk. To enable network requests, provide a Fetch API implementation (global
fetch()is stable in Node.js v21+, ornode-fetchmay be installed) and enable setAllowNetwork. Network requests may optionally be configured with RequestInit parameters.const io = new NodeIO(fetch, {headers: {...}}).setAllowNetwork(true); const document = await io.read('https://example.com/path/to/model.glb');