Search Three3D

All articles

glTF

Smaller glTF files with gltfpack

Pack an asset into GLB and load a mesh-compressed version in Three.js.

gltfpack is the command-line tool included with meshoptimizer. It can repack glTF assets into GLB, optimize mesh data, and optionally enable Meshopt compression.

Pack the asset

Create a baseline GLB first, then try the compressed variant so you can compare output sizes.

gltfpack -i scene.gltf -o scene.glb
gltfpack -c -i scene.gltf -o scene-compressed.glb

Load the compressed GLB

In Three.js, configure GLTFLoader with MeshoptDecoder before loading the compressed file. Check the model in your scene and compare size, appearance, and decode time on the devices you support.

import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
import { MeshoptDecoder } from 'three/addons/libs/meshopt_decoder.module.js';

const loader = new GLTFLoader().setMeshoptDecoder(MeshoptDecoder);
loader.load('/scene-compressed.glb', ({ scene: model }) => scene.add(model));
Green toy car and red fabric rendered from the uncompressed gltfpack baseline

Baseline GLB · 4,173,620 bytes

The same toy car and fabric after Three.js decodes the Meshopt-compressed file

Meshopt GLB · 2,488,444 bytes

Both files were packed with gltfpack 1.3 and rendered with the same camera and lights. The compressed GLB was about 40% smaller and loaded through MeshoptDecoder. Compare the car’s highlights and the fabric folds to check whether the result suits your scene. Khronos Toy Car by Guido Odendahl and Eric Chadwick (CC0) · gltfpack documentation.

gltfpack documentation · Original article (Chinese)