MCPcopy
hub / github.com/donmccurdy/glTF-Transform

github.com/donmccurdy/glTF-Transform @v4.4.1 sqlite

repository ↗ · DeepWiki ↗ · release v4.4.1 ↗
2,125 symbols 8,809 edges 399 files 701 documented · 33%
README

glTF Transform

Latest NPM release npm bundle size License Build Status Coverage

glTF 2.0 SDK for JavaScript and TypeScript, on Web and Node.js.

Introduction

glTF Transform supports reading, editing, and writing 3D models in glTF 2.0 format. Unlike 3D modeling tools — which are ideal for artistic changes to geometry, materials, and animation — glTF Transform provides fast, reproducible, and lossless control of the low-level details in a 3D model. The API automatically manages array indices and byte offsets, which would otherwise require careful management when editing files. These traits make it a good choice for bundling, splitting, or optimizing an existing model. It can also be used to apply quick fixes for common issues, to build a model procedurally, or to easily develop custom extensions on top of the glTF format. Because the core SDK is compatible with both Node.js and Web, glTF Transform may be used to develop offline workflows and web applications alike.

Packages:

  • @gltf-transform/core: Core SDK, providing an expressive API to read, edit, and write glTF files.
  • @gltf-transform/extensions: Extensions (optional glTF features) for the Core SDK.
  • @gltf-transform/functions: Functions for common glTF modifications, written using the core API.
  • @gltf-transform/cli: Command-line interface (CLI) to apply functions to glTF files quickly or in batch.

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

Commercial Use

<b>Using glTF Transform for a personal project?</b> That's great! Sponsorship is neither expected nor required. Feel
free to share screenshots if you've made something you're excited about — I enjoy seeing those!







<b>Using glTF Transform in for-profit work?</b> That's wonderful! Your support is important to keep glTF Transform
maintained, independent, and open source under MIT License. Please consider a
<a href="https://store.donmccurdy.com/l/gltf-transform-pro" target="_blank">subscription</a>
or
<a href="https://github.com/sponsors/donmccurdy" target="_blank">GitHub sponsorship</a>.







<i>
    Learn more in the
    <a href="https://store.donmccurdy.com/l/gltf-transform-pro" target="_blank"> glTF Transform Pro </a> FAQs</i
>.

Scripting API

Install the scripting packages:

npm install --save @gltf-transform/core @gltf-transform/extensions @gltf-transform/functions

Read and write glTF scenes with platform I/O utilities WebIO, NodeIO, or DenoIO:

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

// Configure I/O.
const io = new NodeIO()
    .registerExtensions(ALL_EXTENSIONS)
    .registerDependencies({
        'draco3d.decoder': await draco3d.createDecoderModule(), // Optional.
        'draco3d.encoder': await draco3d.createEncoderModule(), // Optional.
    });

// Read from URL.
const document = await io.read('path/to/model.glb');

// Write to byte array (Uint8Array).
const glb = await io.writeBinary(document);

To perform changes to an existing glTF Document, import off-the-shelf scripts from the Functions package, or write your own using API classes like Material, Primitive, and Texture.

import { resample, prune, dedup, draco, textureCompress } from '@gltf-transform/functions';
import sharp from 'sharp'; // Node.js only.

await document.transform(
    // Losslessly resample animation frames.
    resample(),
    // Remove unused nodes, textures, or other data.
    prune(),
    // Remove duplicate vertex or texture data, if any.
    dedup(),
    // Compress mesh geometry with Draco.
    draco(),
    // Convert textures to WebP (Requires glTF Transform v3 and Node.js).
    textureCompress({
        encoder: sharp,
        targetFormat: 'webp',
        resize: [1024, 2024],
    }),
    // Custom transform.
    backfaceCulling({cull: true}),
);

// Custom transform: enable/disable backface culling.
function backfaceCulling(options) {
    return (document) => {
        for (const material of document.getRoot().listMaterials()) {
            material.setDoubleSided(!options.cull);
        }
    };
}

To learn how glTF Transform works, and the architecture of the scripting API, start with Concepts. To try out the scripting API without installing anything, visit gltf.report/, load a glTF model, and open the Script tab.

Command-line API

Install the CLI, supported in Node.js LTS versions.

npm install --global @gltf-transform/cli

List available CLI commands:

gltf-transform --help

Optimize everything all at once:

gltf-transform optimize input.glb output.glb --texture-compress webp

Or pick and choose your optimizations, building a custom pipeline.

Compress mesh geometry with Draco or Meshoptimizer:

# Draco (compresses geometry).
gltf-transform draco input.glb output.glb --method edgebreaker

# Meshopt (compresses geometry, morph targets, and keyframe animation).
gltf-transform meshopt input.glb output.glb --level medium

Resize and compress textures with Sharp, or improve VRAM usage and performance with KTX2 and Basis Universal:

# Resize textures.
gltf-transform resize input.glb output.glb --width 1024 --height 1024

# Compress textures with WebP.
gltf-transform webp input.glb output.glb --slots "baseColor"

# Compress textures with KTX2 + Basis Universal codecs, UASTC and ETC1S.
gltf-transform uastc input.glb output1.glb \
    --slots "{normalTexture,occlusionTexture,metallicRoughnessTexture}" \
    --level 4 --rdo --rdo-lambda 4 --zstd 18 --verbose
gltf-transform etc1s output1.glb output2.glb --quality 255 --verbose

... and much more.

Credits

See Credits.

License

Copyright 2024, MIT License.

Extension points exported contracts — how you extend this code

ImageUtilsFormat (Interface)
(no doc) [6 implementers]
packages/core/src/utils/image-utils.ts
ImageProvider (Interface)
(no doc) [4 implementers]
packages/view/src/ImageProvider.ts
ImportMetaEnv (Interface)
* Global internal type definitions. * * Definitions provided here cannot be used in public APIs, as they aren't * bun
packages/global.d.ts
LayoutPlan (Interface)
@hidden
packages/functions/src/reorder.ts
IStructuralMetadata (Interface)
* Interfaces.
packages/extensions/src/ext-structural-metadata/metadata.ts
IInternalProgram (Interface)
(no doc) [1 implementers]
packages/cli/src/program.ts
TorusKnotOptions (Interface)
(no doc)
packages/test-utils/src/create-torus-primitive.ts
Export (Interface)
(no doc)
packages/docs/src/routes/+layout.server.ts

Core symbols most depended-on inside this repo

getRoot
called by 459
packages/core/src/document.ts
get
called by 292
packages/functions/src/utils.ts
getAttribute
called by 253
packages/core/src/properties/primitive.ts
createAccessor
called by 232
packages/core/src/document.ts
setArray
called by 228
packages/core/src/properties/accessor.ts
transform
called by 192
packages/cli/src/session.ts
createNode
called by 185
packages/core/src/document.ts
setAttribute
called by 180
packages/core/src/properties/primitive.ts

Shape

Method 1,079
Function 510
Class 295
Interface 221
Enum 20

Languages

TypeScript100%

Modules by API surface

packages/extensions/src/ext-structural-metadata/metadata.ts213 symbols
packages/extensions/src/ext-structural-metadata/structural-metadata.ts65 symbols
packages/core/src/properties/material.ts40 symbols
packages/cli/src/program.ts35 symbols
packages/functions/src/utils.ts34 symbols
packages/core/src/properties/node.ts31 symbols
packages/core/src/types/gltf.ts30 symbols
packages/core/src/properties/accessor.ts29 symbols
packages/core/src/document.ts29 symbols
packages/core/src/properties/root.ts27 symbols
packages/core/src/utils/image-utils.ts25 symbols
packages/view/src/ImageProvider.ts22 symbols

Dependencies from manifests, versioned

@biomejs/biome2.4.9 · 1×
@donmccurdy/caporal0.0.10 · 1×
@gltf-transform/core4.4.1 · 1×
@gltf-transform/extensions4.4.1 · 1×
@greendoc/parse0.4.1 · 1×
@greendoc/svelte0.4.1 · 1×
@sveltejs/adapter-static3.0.10 · 1×
@sveltejs/kit2.55.0 · 1×
@sveltejs/vite-plugin-svelte5.1.1 · 1×
@tweakpane/core1.1.9 · 1×
@types/d3-dsv3.0.7 · 1×

For agents

$ claude mcp add glTF-Transform \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact