Edit glTF Models Losslessly with JS/TS SDK

glTF Transform provides fast, reproducible editing of glTF 2.0 models via JS/TS API and CLI, automating indices/offsets for optimization, bundling, and procedural builds on Web/Node.js.

Automate Low-Level glTF Edits Without Manual Index Management

glTF Transform excels at precise, lossless modifications to glTF 2.0 models that 3D tools like Blender can't replicate reliably. It handles array indices and byte offsets automatically, preventing corruption during edits. Use it to bundle/split models, optimize for web deployment, apply fixes (e.g., backface culling), build procedurally, or extend glTF with custom features. Core packages include @gltf-transform/core for the API, @gltf-transform/extensions for optional glTF features, @gltf-transform/functions for common transforms, and @gltf-transform/cli for batch processing. Runs on Web, Node.js, and Deno via IO classes like WebIO, NodeIO, DenoIO.

Install via npm install --save @gltf-transform/core @gltf-transform/extensions @gltf-transform/functions. Read/write example:

import { Document, NodeIO } from '@gltf-transform/core';
import { ALL_EXTENSIONS } from '@gltf-transform/extensions';

const io = new NodeIO().registerExtensions(ALL_EXTENSIONS);
// Optionally register Draco decoder/encoder.
const document = await io.read('path/to/model.glb');
const data = await io.writeBinary(document);

This setup supports Draco dependencies for compression, enabling cross-platform workflows from offline pipelines to web apps.

Chain Prebuilt Functions for Model Optimization

Transform documents with composable functions from @gltf-transform/functions, each targeting specific inefficiencies. Key functions deliver measurable gains:

  • resample: Losslessly resamples animation frames to uniform intervals, reducing file size without visual loss.
  • prune: Strips unused nodes, textures, or data, eliminating bloat from exports.
  • dedup: Merges duplicate vertices or textures, shrinking geometry and assets.
  • dracoCompress: Applies Draco compression to meshes, cutting geometry size (requires Draco modules).
  • textureCompress({encoder, targetFormat: 'webp', resize: [1024, 1024]}): Converts/resizes textures to WebP (Node.js, v3+ via Sharp), or KTX2/Basis Universal (UASTC/ETC1S) for VRAM efficiency.
  • Custom: backfaceCulling({cull: true}) sets materials to single-sided, improving render performance.

Example pipeline:

import { resample, prune, dedup, dracoCompress, textureCompress } from '@gltf-transform/functions';
await document.transform(
  resample(),
  prune(),
  dedup(),
  dracoCompress(),
  textureCompress({targetFormat: 'webp', resize: [1024, 1024]})
);

Test scripts live at gltf.report without installs. Learn API via Concepts docs, using classes like Material, Primitive, Texture.

CLI Pipeline for One-Off or Batch Jobs

Global install: npm install --global @gltf-transform/cli (Node.js LTS). Run gltf-transform help for commands.

Full optimization: gltf-transform optimize input.glb output.glb --texture-compress webp applies prune/dedup/resample/Draco/texture compression in one pass.

Targeted ops:

  • Geometry: gltf-transform draco input.glb output.glb (Draco) or meshopt (geometry/morphs/keyframes).
  • Textures: gltf-transform resize input.glb output.glb 1024 1024; texture-compress input.glb output.glb webp '{baseColor}'; or KTX2/Basis for normals/occlusion.

Build custom pipelines by chaining, ideal for CI/CD or asset prep. MIT licensed; Pro subscription supports for-profit use.

Summarized by x-ai/grok-4.1-fast via openrouter

4745 input / 2076 output tokens in 16066ms

© 2026 Edge