Atlaslog
Atlaslog / three.js / API reference / GLTFLoader
three.js · API reference

GLTFLoader

Quick answer

GLTFLoader reads .glb and .gltf assets and returns an object containing scene, scenes, animations, and cameras. Add gltf.scene to your scene, and hand gltf.animations to an AnimationMixer. Configure DRACOLoader, KTX2Loader, or MeshoptDecoder before loading compressed assets. loadAsync() returns a promise when you prefer async/await over callbacks.

Last verified 2026-11-03 · three.js 0.160.0 · Cite this page
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js'
Key points
Example
const loader = new GLTFLoader();

const gltf = await loader.loadAsync('/models/building.glb', function (event) {
  if (event.lengthComputable) {
    console.log('加载进度', (event.loaded / event.total * 100).toFixed(1) + '%');
  }
});

const model = gltf.scene;
model.traverse(function (obj) {
  if (obj.isMesh) {
    obj.castShadow = true;
    obj.receiveShadow = true;

    if (obj.material && obj.material.map) {
      obj.material.map.anisotropy = renderer.capabilities.getMaxAnisotropy();
    }
  }
});

scene.add(model);
if (gltf.animations.length) {
  const mixer = new THREE.AnimationMixer(model);
  mixer.clipAction(gltf.animations[0]).play();
  mixers.push(mixer);
}
import { DRACOLoader } from 'three/addons/loaders/DRACOLoader.js';
import { KTX2Loader } from 'three/addons/loaders/KTX2Loader.js';

const draco = new DRACOLoader();
draco.setDecoderPath('/wasm/draco/');

const ktx2 = new KTX2Loader()
  .setTranscoderPath('/wasm/basis/')
  .detectSupport(renderer);

loader.setDRACOLoader(draco);
loader.setKTX2Loader(ktx2);
Notes
Runnable examplesChinese originalAll API references
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Cite this page

Atlaslog (2026). GLTFLoader. https://www.jingweizhi.com/en/three/api/gltf-loader.html (accessed 2026-11-03).