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 { Document } from '@gltf-transform/core';
import { dedup } from '@gltf-transform/functions';

const doc = new Document();

const texture1 = doc.createTexture('myTexture')
const texture2 = doc.createTexture('myTexture2')

// Document containing duplicate copies of the same texture.
doc.getRoot().listTextures(); // → [texture x 2]

await doc.transform(
    dedup({textures: true}),
    // ...

// Document with duplicate textures removed.
doc.getRoot().listTextures(); // → [texture x 1]



  • Document



  • createBuffer(name?: string): Buffer
  • createCamera(name?: string): Camera
  • createExtension<T>(ctor: (doc: Document) => T): T
  • createMaterial(name?: string): Material
  • createMesh(name?: string): Mesh
  • createNode(name?: string): Node
  • createScene(name?: string): Scene
  • createSkin(name?: string): Skin
  • createTexture(name?: string): Texture
  • Overrides the Logger instance used for any operations performed on this document.


        .setLogger(new Logger(Logger.Verbosity.SILENT))
        .transform(dedup(), weld());
  • transform(...transforms: Transform[]): Promise<Document>
  • 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.


    await doc.transform(
Function symbol, f(📦) → 📦, where the argument and output are a box labeled 'glTF'.

Made by Don McCurdy TypeDoc documentation Copyright 2021 under MIT license