gamedev-skills/awesome-gamedev-agent-skills

threejs-gltf-loading

Load glTF/GLB models in three.js with GLTFLoader and play their skinned animations with AnimationMixer, including DRACO/Meshopt-compressed meshes and KTX2 textures.

소스 보기

사용 방법

  1. 설치 명령을 복사하고 자신의 에이전트 환경에 설치하기 전에 소스 패키지를 확인하세요.
  2. 필요한 도구, 인증 정보, 지원 환경은 원본 문서에서 확인하세요.
  3. 입력과 원하는 산출물을 설명하고 출처와 결과를 대조하세요.
npx skills add https://github.com/gamedev-skills/awesome-gamedev-agent-skills --skill threejs-gltf-loading

시작 전 확인

  • 설치에는 모델 구독, API 한도, 파일 접근 권한이 포함되지 않습니다.
  • 별점 수와 설치 수는 활동 지표이며 독립적인 품질·보안 검증이 아닙니다.
원본 Skill 문서

원본 저장소의 제목, 예시, 코드, 표, 링크, 이미지를 유지해 표시합니다.

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 imports GLTFLoader /

DRACOLoader / KTX2Loader from three/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

  1. 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.

  1. Load with `GLTFLoader`. loader.load(url, onLoad, onProgress, onError). The

result gltf has gltf.scene (the Object3D root), gltf.animations (AnimationClip[]), gltf.cameras, and gltf.asset.

  1. Add `gltf.scene` to your scene and frame it. Inspect the hierarchy with

traverse / getObjectByName to find the parts you'll control.

  1. Play animations with an `AnimationMixer`. One mixer per animated root;

mixer.clipAction(clip).play(); advance with mixer.update(delta) every frame.

  1. Decode compressed assets. Attach a DRACOLoader (and/or KTX2Loader +

Meshopt) so DRACO meshes and KTX2 textures load; point the decoders at their files.

  1. Validate changed glTF files when the project already has the tool. Run

gltf-transform validate path/to/model.glb for each changed .gltf or .glb; fix reported errors before loading.

  1. 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

js
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

js
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

js
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

js
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

js
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 (see threejs-materials-lighting), and check scale — glTF is in metres, so a 0.01-scaled asset is tiny.

  • `load` is async → gltf only exists inside the callback; declare mixer/refs

outside and assign them in the callback, or use await loader.loadAsync(url).

  • Animation never moves → you didn't call mixer.update(delta) each frame, or you

passed milliseconds instead of seconds (use timer.getDelta() after timer.update(time)), or you forgot action.play().

  • DRACO/KTX2 model fails → the decoder/transcoder path is wrong or version-

mismatched. setDecoderPath/setTranscoderPath must point at files matching your three.js version.

  • Multiple mixers fighting → use one AnimationMixer per 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 Object3D to give it a clean

pivot rather than fighting baked offsets.

References

  • For the full decode/transcode setup (DRACO + Meshopt + KTX2 together), loadAsync
  • a LoadingManager progress bar, reusing models with SkeletonUtils.clone, and

exporter guidance (apply transforms, one clean root), read references/loaders-and-animation.md.

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.
같은 저장소의 Skills

더 많은 Skills

모든 Skills
gamedev-skills
커뮤니티

game-feel

Add "juice" and game feel that makes actions satisfying — screen shake, hit-stop/freeze frames, tweened/eased motion, squash & stretch, knockback, and layered audio-visual feedback — as engine-neutral techniques that pair with the detected engine's tween, particle, and camera APIs. Use when the user mentions game feel, juice, "make it feel good/punchy", screen shake, hit stop, screen freeze, easing, squash and stretch, impact frames, or feedback/polish on hits, jumps, pickups, and deaths.

설치 수
16
GitHub Stars
4.3천
업데이트
10월 24일
gamedev-skills
커뮤니티

audio-design

Implement game audio practice — bus/mixer architecture and gain in decibels, ducking (sidechain), adaptive/dynamic music via layering and re-sequencing, SFX variation, and beat synchronization. Engine-neutral. Use when the user mentions audio mixing, audio buses, adaptive/dynamic music, ducking, SFX variation, music layers, or syncing gameplay to the beat.

설치 수
13
GitHub Stars
4.3천
업데이트
10월 24일
gamedev-skills
커뮤니티

performance-optimization

Find and fix game performance problems methodically — measure with the engine profiler first, reason about the frame-time budget, locate the CPU-vs-GPU bottleneck, then apply the right fix: object pooling, draw-call batching, fewer allocations/GC spikes, and asset budgets. Engine- neutral method that pairs with each engine's profiler. Use when the user mentions performance, optimize, low/dropping FPS, frame drops, stutter, lag, profiler, frame budget, draw calls, batching, garbage collection/GC

설치 수
13
GitHub Stars
4.3천
업데이트
10월 24일
gamedev-skills
커뮤니티

shader-programming

Write game shaders from cross-engine fundamentals — the vertex→fragment pipeline, coordinate spaces, UV math, and common 2D/3D effects (tint, UV scroll, dissolve, outline, fresnel rim, vignette) in GLSL with HLSL equivalents. Use when the user mentions shaders, fragment/pixel shader, vertex shader, UV, GLSL, HLSL, or effects like dissolve, outline, or rim light.

설치 수
13
GitHub Stars
4.3천
업데이트
10월 24일