threejs-gltf-loading
Ce qu’il fait
Explique comment intégrer des modèles 3D dans une scène three.js et faire jouer leurs animations. Elle s'adresse aux développeurs qui créent des expériences 3D sur le web.
Quand l’utiliser
- ✓Quand vous devez importer un modèle 3D glTF ou GLB dans une scène three.js.
- ✓Quand les animations d'un modèle doivent jouer, comme une marche ou une attente.
- ✓Quand un fichier de modèle est volumineux et doit utiliser une géométrie ou des textures compressées.
Lien du skill
https://github.com/gamedev-skills/awesome-gamedev-agent-skills/blob/main/skills/web-engines/threejs-gltf-loading/SKILL.mdCopiez-le et collez-le dans votre IA (Claude, ChatGPT ou Cursor) en lui demandant de suivre les instructions.
Comment l’utiliser
Le plus simple : copiez le message et collez-le dans votre IA. Elle lit le skill et suit les instructions.
Message prêt à coller
Pour Claude Code, Codex ou Cursor : lancez-la dans le dossier du projet et le skill est installé.
Téléchargez le SKILL.md et placez-le dans le dossier de skills de votre agent.
Exemple de demande à votre IA
“Charge mon modèle de personnage dans ma page three.js et fais jouer son animation de marche.”
5 nouveaux skills par semaine. 1 minute de lecture.
Comment ça marche
Elle explique comment charger le fichier avec le chargeur glTF, ajouter le modèle à la scène et utiliser un mélangeur d'animation pour jouer les clips fournis avec le modèle.
Contenu technique (SKILL.md original)
Texte original de l’auteur, en anglais, directement depuis GitHub.
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, aKTX2Loader, and/or the Meshopt decoder so DRACO meshes, KTX2 textures, and meshopt-compressed buffers load. Since r185 the DRACO and KTX2 loaders find their bundled decoder files on their own. - Validate changed glTF files when the project already has the tool. Run
gltf-transform validate path/to/model.glbfor each changed.gltfor.glb; fix reported errors before loading. - 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) => {
// total is 0 when the server sends no Content-Length (e.g. compressed responses)
if (event.total) 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);
}
let current = actions['Idle'];
current.play();
function transitionTo(name, duration = 0.3) {
const next = actions[name];
if (!next || next === current) return;
next.reset().play(); // rewind and clear any old fade
current.crossFadeTo(next, duration, false); // fade the old one out, new one in
current = next;
}
4. DRACO-compressed geometry
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
import { DRACOLoader, DRACO_GLTF_CONFIG } from 'three/addons/loaders/DRACOLoader.js';
// r185+: DRACOLoader finds the decoder that ships n
Questions fréquentes
Pourquoi utiliser glTF plutôt que OBJ ou FBX ?
La compétence indique que glTF est conçu pour un usage en temps réel sur le web, alors qu'OBJ n'a pas d'animation et que FBX est lourd.
Couvre-t-elle la création du modèle 3D ?
Non. La création ou l'export de modèles dans d'autres outils sort du périmètre de cette compétence.
Couvre-t-elle l'éclairage du modèle ?
Non. Les matériaux et l'éclairage relèvent d'une compétence three.js distincte.
Détails
Description originale de l’auteur
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.
Popularité
- Étoiles GitHub
- 6.6k
- Position au classement
- #13861
- Licence
- Apache-2.0
- Mis à jour
- 28/10/2026
Commentaires
- …
Autres skills de ce dépôt
router
6.6kAide votre agent à choisir la bonne compétence de développement de jeu pour une demande, en détectant votre moteur et le type de tâche.
ai-behavior-trees-utility-ai
6.6kAide votre agent à construire un arbre de comportement et une IA par utilité pour des ennemis qui choisissent leurs actions selon priorité et score.
audio-design
6.6kApprend à votre agent le mixage audio de jeu : bus, volume en décibels, baisse sous les dialogues, musique adaptative et variation des effets sonores.
camera-systems
6.6kAide votre agent à construire des caméras de jeu qui suivent en douceur, restent dans le niveau, et pivotent ou regardent autour en 3D.
Skills similaires
angular-developer
280kAide votre agent à créer du code Angular et à conseiller sur la structure des projets. Utile pour démarrer, créer des composants ou améliorer performances et accessibilité.
frontend-a11y
280kAide votre agent à rendre les interfaces web accessibles à tous. Il garantit que sites et apps fonctionnent avec les lecteurs d'écran et la navigation au clavier.
frontend-patterns
280kPermet à votre agent d'appliquer les modèles modernes du frontend : optimisation des performances, gestion d'état et bonnes pratiques avec React et Next.js.