Programmatic GLB/glTF 3D model compression library with a multi-phase pipeline, skinned-model awareness, and custom glTF-Transform transforms. Use when integrating compression into application code, building custom pipelines, or using individual transforms.
Programmatic API for multi-phase GLB/glTF compression. Skinned-model-aware pipeline with gltfpack-first strategy and meshopt WASM fallback.
import { compress, init, PRESETS } from 'glb-compressor';
await init(); // Pre-warm WASM (optional, called automatically)
const glbBytes = await Bun.file('model.glb').bytes();
const result = await compress(glbBytes, { preset: 'aggressive' });
await Bun.write('out.glb', result.buffer);
import { ... } from 'glb-compressor'; // Library API
import { ... } from 'glb-compressor/server'; // Server (guarded by import.meta.main)
import { ... } from 'glb-compressor/cli'; // CLI entry
Conditional exports: "bun" field for Bun runtime, "node" for Node.js.
init(): Promise<void>Pre-warm Draco + Meshopt WASM and configure glTF-Transform I/O. Called
automatically by compress(), but can be called at boot to eliminate cold-start
latency. Safe to call multiple times (shared promise).
compress(input, options?): Promise<CompressResult>Main entry point. Runs the full 6-phase pipeline.
Parameters:
| Param | Type | Description |
|---|---|---|
input | Uint8Array | Raw GLB file bytes |
options.preset | CompressPreset | 'default' | 'balanced' | 'aggressive' | 'max' |
options.simplifyRatio | number | Additional simplification in (0, 1) |
options.onLog | (msg) => void | Progress callback (used by SSE) |
options.quiet | boolean | Suppress console output |
Returns: CompressResult
interface CompressResult {
buffer: Uint8Array; // Compressed GLB binary
method: string; // 'gltfpack' | 'meshopt'
originalSize?: number; // Input byte count
}
getHasGltfpack(): booleanWhether the gltfpack binary was found during initialization.
| File | Purpose |
|---|---|
| api.md | Full API surface: types, constants, utilities |
| transforms.md | Custom glTF-Transform transforms for a-la-carte use |
| Task | Files to Read |
|---|---|
| Basic compression | This file only |
| Custom pipeline / advanced | This file + transforms.md |
| Full type reference | This file + api.md |
When skins are detected, the pipeline automatically skips destructive