Creates a new Document, representing an empty glTF asset.
Clones this Document, copying all resources within it.
Creates a new PrimitiveTarget, or morph target. Targets must be attached to a Primitive for use and export; they are not otherwise associated with a Root.
Creates a new Extension, for the extension type of the given constructor. If the extension is already enabled for this Document, the previous Extension reference is reused.
Creates a new AnimationSampler. Samplers must be attached to an Animation for use and export; they are not otherwise associated with a Root.
Creates a new AnimationChannel. Channels must be attached to an Animation for use and export; they are not otherwise associated with a Root.
Returns the Logger instance used for any operations performed on this document.
Overrides the Logger instance used for any operations performed on this document.
Usage:
doc
.setLogger(new Logger(Logger.Verbosity.SILENT))
.transform(dedup(), weld());
Merges the content of another Document into this one, without affecting the original.
Returns the glTF Root property.
Applies a series of modifications to this document. Each transformation is asynchronous, takes the Document as input, and returns nothing. Transforms are applied in the order given, which may affect the final result.
Usage:
await doc.transform(
dedup(),
prune()
);
Made by Don McCurdy. Documentation built with greendoc and published under Creative Commons Attribution 3.0.
Wraps a glTF asset and its resources for easier modification.
Documents manage glTF assets and the relationships among dependencies. The document wrapper allow tools to read and write changes without dealing with array indices or byte offsets, which would otherwise require careful management over the course of a file modification. An internal graph structure allows any property in the glTF file to maintain references to its dependencies, and makes it easy to determine where a particular property dependency is being used. For example, finding a list of materials that use a particular texture is as simple as calling Texture.listParents().
A new resource Property (e.g. a Mesh or Material) is created by calling 'create' methods on the document. Resources are destroyed by calling Property.dispose().
import fs from 'fs/promises'; import { Document } from '@gltf-transform/core'; import { dedup } from '@gltf-transform/functions'; const document = new Document(); const texture1 = document.createTexture('myTexture') .setImage(await fs.readFile('path/to/image.png')) .setMimeType('image/png'); const texture2 = document.createTexture('myTexture2') .setImage(await fs.readFile('path/to/image2.png')) .setMimeType('image/png'); // Document containing duplicate copies of the same texture. document.getRoot().listTextures(); // → [texture x 2] await document.transform( dedup({textures: true}), // ... ); // Document with duplicate textures removed. document.getRoot().listTextures(); // → [texture x 1]
Reference: