threejs-gltf-loading
gamedev-skills/awesome-gamedev-agent-skills
Load glTF/GLB 3D models and play animations in three.js with GLTFLoader and AnimationMixer.
What is threejs-gltf-loading?
Load .gltf/.glb models into three.js scenes, play their baked and skinned animations using AnimationMixer, and handle compressed geometry (DRACO/Meshopt) and textures (KTX2). Use this when importing 3D models, setting up animation playback, or working with model hierarchies.
- Load glTF/GLB models with GLTFLoader and add them to the scene
- Play skinned and baked animation clips using AnimationMixer with cross-fading support
- Inspect model node hierarchies and find named parts with traverse/getObjectByName
- Decode DRACO-compressed geometry and KTX2 textures by configuring DRACOLoader and KTX2Loader
- Handle animation timing with delta updates in the render loop
How to install threejs-gltf-loading
npx skills add https://github.com/gamedev-skills/awesome-gamedev-agent-skills --skill threejs-gltf-loading- three.js library installed (patterns target r186)
- GLTFLoader imported from three/addons/loaders/GLTFLoader.js
- For compressed assets: DRACOLoader and/or KTX2Loader with decoder/transcoder files matching your three.js version
- A three.js scene, camera, and renderer already set up (see threejs-scene-setup)
How to use threejs-gltf-loading
- 1.Import GLTFLoader from three/addons/loaders/GLTFLoader.js
- 2.Create a new GLTFLoader instance and call loader.load(url, onLoad, onProgress, onError)
- 3.Inside the onLoad callback, add gltf.scene to your three.js scene
- 4.Create an AnimationMixer from gltf.scene and store it outside the callback
- 5.For each animation clip you want to play, call mixer.clipAction(clip).play()
- 6.In your render loop, call mixer.update(delta) each frame with real seconds (not milliseconds)
- 7.For compressed models, attach a DRACOLoader or KTX2Loader and set their decoder/transcoder paths before loading
Use cases
- Import a character model and play walk/run/idle animations with smooth transitions
- Load a compressed city or environment model and add it to a three.js scene
- Animate specific parts of a model (wheels, doors, limbs) by finding and rotating named nodes
- Set up a glTF model with PBR materials and environment lighting for realistic rendering
- Load models with progress tracking and error handling in a game or interactive app
- Game developers building 3D scenes with three.js
- Web developers adding animated 3D models to interactive experiences
- Graphics engineers working with glTF asset pipelines
- Anyone migrating from OBJ/FBX to glTF for web runtime performance
threejs-gltf-loading FAQ
glTF is a transmission format optimized for the web: it includes a scene graph, PBR materials, and animations ready to render with minimal parsing. OBJ has no scene hierarchy or animation support, and FBX is heavy for runtime use.
The model likely has PBR materials and your scene has no light or environment map. Add a light or set scene.environment, and check the model's scale — glTF uses metres, so a 0.01-scaled asset will be tiny.
Verify you called mixer.update(delta) each frame with seconds (not milliseconds), that you called action.play() on the clip action, and that you declared mixer outside the load callback so the render loop can access it.
Create a clipAction for each clip in gltf.animations, store them in an object by name, call play() on the next action, and use crossFadeTo(nextAction, duration, false) on the current action to smoothly transition.
The decoder or transcoder path is likely wrong or version-mismatched. Use setDecoderPath() or setTranscoderPath() to point at files matching your three.js version, and verify the files exist at that URL.
Full instructions (SKILL.md)
Source of truth, from gamedev-skills/awesome-gamedev-agent-skills.
name: threejs-gltf-loading description: > Load glTF/GLB models in three.js with GLTFLoader and play their skinned animations with AnimationMixer, including DRACO/Meshopt-compressed meshes and KTX2 textures. Use when importing 3D models into three.js — when the user mentions glTF, GLB, GLTFLoader, AnimationMixer, animation clips, DRACOLoader, or "load a 3D model". For scene/camera/renderer setup use threejs-scene-setup; for materials and lights use threejs-materials-lighting.
three.js glTF Loading
Load .gltf/.glb models and play their animations in three.js, including
compressed geometry (DRACO/Meshopt) and textures (KTX2). Patterns target
r186; preserve an existing project's pinned release unless migration is requested.
When to use
- Use to import a 3D model, add it to the scene, inspect its node hierarchy, and
play baked/skinned animation clips with an
AnimationMixer. - Use when files are
.gltf/.glb, or code importsGLTFLoader/DRACOLoader/KTX2Loaderfromthree/addons/loaders/....
When not to use: creating the renderer/camera/loop → threejs-scene-setup.
Tuning surface look, lights, or shadows on the loaded model →
threejs-materials-lighting. Authoring/exporting the model itself (Blender) is out
of scope; prefer glTF over OBJ/FBX for runtime.
Core workflow
- Why glTF. It's a transmission format: binary vertex data, PBR materials, and animations are ready to render with minimal parsing. Prefer it over OBJ (no scene graph, no animation) and FBX (heavy) for the web.
- Load with
GLTFLoader.loader.load(url, onLoad, onProgress, onError). The resultgltfhasgltf.scene(theObject3Droot),gltf.animations(AnimationClip[]),gltf.cameras, andgltf.asset. - Add
gltf.sceneto your scene and frame it. Inspect the hierarchy withtraverse/getObjectByNameto find the parts you'll control. - Play animations with an
AnimationMixer. One mixer per animated root;mixer.clipAction(clip).play(); advance withmixer.update(delta)every frame. - Decode compressed assets. Attach a
DRACOLoader(and/orKTX2Loader+ Meshopt) so DRACO meshes and KTX2 textures load; point the decoders at their files. - Verify what loaded — log the scene graph and
gltf.animations, and confirm the model is visible (right scale, lit) and the clip actually plays.
Patterns
1. Load a model and frame it
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
const loader = new GLTFLoader();
loader.load(
'assets/robot.glb',
(gltf) => {
const root = gltf.scene;
scene.add(root);
// Inspect: gltf.animations is an array of AnimationClip.
console.log('clips:', gltf.animations.map((c) => c.name));
},
(event) => console.log(`${(event.loaded / event.total) * 100}% loaded`),
(error) => console.error('glTF load failed:', error)
);
2. Play a skinned animation with AnimationMixer
import * as THREE from 'three';
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
let mixer; // declare outside so the loop can see it
const timer = new THREE.Timer(); // THREE.Clock is deprecated since r183
new GLTFLoader().load('assets/character.glb', (gltf) => {
scene.add(gltf.scene);
mixer = new THREE.AnimationMixer(gltf.scene); // one mixer per animated root
const clip = THREE.AnimationClip.findByName(gltf.animations, 'Run')
?? gltf.animations[0];
mixer.clipAction(clip).play();
});
renderer.setAnimationLoop((time) => {
timer.update(time);
const dt = timer.getDelta();
if (mixer) mixer.update(dt); // advance the animation by real seconds
renderer.render(scene, camera);
});
3. Cross-fade between two clips
const actions = {};
mixer = new THREE.AnimationMixer(gltf.scene);
for (const clip of gltf.animations) {
actions[clip.name] = mixer.clipAction(clip);
}
actions['Idle'].play();
function transitionTo(name, duration = 0.3) {
const next = actions[name];
next.reset().play();
for (const [n, action] of Object.entries(actions)) {
if (n !== name) action.crossFadeTo(next, duration, false);
}
}
4. DRACO-compressed geometry
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
import { DRACOLoader } from 'three/addons/loaders/DRACOLoader.js';
const draco = new DRACOLoader();
// Point at the decoder files you ship (or a pinned CDN copy of the same version).
draco.setDecoderPath('https://cdn.jsdelivr.net/npm/three@0.186.0/examples/jsm/libs/draco/');
const loader = new GLTFLoader();
loader.setDRACOLoader(draco);
loader.load('assets/city-draco.glb', (gltf) => scene.add(gltf.scene));
5. Find and animate a named part
new GLTFLoader().load('assets/car.glb', (gltf) => {
scene.add(gltf.scene);
const wheels = [];
gltf.scene.traverse((node) => {
if (node.name.startsWith('Wheel')) wheels.push(node);
});
renderer.setAnimationLoop((time) => {
timer.update(time);
const dt = timer.getDelta();
for (const w of wheels) w.rotation.x += dt * 4;
renderer.render(scene, camera);
});
});
Pitfalls
- Model loads but is invisible → it has lit (PBR) materials and the scene has no
light or environment. Add a light or
scene.environment(seethreejs-materials-lighting), and check scale — glTF is in metres, so a 0.01-scaled asset is tiny. loadis async →gltfonly exists inside the callback; declaremixer/refs outside and assign them in the callback, or useawait loader.loadAsync(url).- Animation never moves → you didn't call
mixer.update(delta)each frame, or you passed milliseconds instead of seconds (usetimer.getDelta()aftertimer.update(time)), or you forgotaction.play(). - DRACO/KTX2 model fails → the decoder/transcoder path is wrong or version-
mismatched.
setDecoderPath/setTranscoderPathmust point at files matching your three.js version. - Multiple mixers fighting → use one
AnimationMixerper animated root and create all actions from it; don't make a new mixer per clip. - Baked-in transforms surprise you → exporters sometimes bake scale/rotation onto child nodes. Dump the hierarchy (names + position/rotation/scale) before relying on a node's local transform; re-export from the source if the rig is unusable.
- Origins are off → re-parent a part under a fresh
Object3Dto give it a clean pivot rather than fighting baked offsets.
References
- For the full decode/transcode setup (DRACO + Meshopt + KTX2 together),
loadAsync- a
LoadingManagerprogress bar, reusing models withSkeletonUtils.clone, and exporter guidance (apply transforms, one clean root), readreferences/loaders-and-animation.md.
- a
Related skills
threejs-scene-setup— the renderer, camera, and loop this model renders into.threejs-materials-lighting— lighting/environment so PBR models look right.fps-shooter— a 3D genre that composes three.js skills.
Related skills
More from gamedev-skills/awesome-gamedev-agent-skills and the wider catalog.

threejs-materials-lighting
Light and shade three.js scenes with PBR materials, shadows, and environment maps.

threejs-scene-setup
Bootstrap a three.js scene with camera, renderer, animation loop, and OrbitControls.

tower-defense
Build tower defense games with enemy pathing, wave spawning, tower targeting, and economy systems.

unity-animation
Drive character animation in Unity 6.3 LTS with Animator Controllers, parameters, blend trees, and IK.

unity-build-pipeline
Configure, script, and automate Unity 6.3 LTS player builds with platform targets, scripting backends, and CI integration.

unity-csharp-scripting
Write correct Unity 6 MonoBehaviour scripts with proper lifecycle, component caching, and coroutines.