用途:在 three.js 中导入 .gltf/.glb 模型、加入场景、检查节点层级,并用 AnimationMixer 播放烘焙或骨骼动画;适用于文件为 glTF 格式,或代码从 three/addons/loaders/... 导入 GLTFLoader、DRACOLoader、KTX2Loader 的场景。创建渲染器、相机与循环应使用 threejs-scene-setup;调整材质、灯光与阴影使用 threejs-materials-lighting;模型本身的制作与导出不在范围内。
主要能力:GLTFLoader.load(url, onLoad, onProgress, onError) 返回的 gltf 含 gltf.scene、gltf.animations、gltf.cameras、gltf.asset;用 traverse/getObjectByName 定位可控制部件;每个动画根一个 AnimationMixer,通过 mixer.clipAction(clip).play() 播放,并在每帧 mixer.update(delta) 推进;支持多个 clip 间的 crossFadeTo 过渡;可挂 DRACOLoader 加载 DRACO 压缩几何,示例中 draco.setDecoderPath('https://cdn.jsdelivr.net/npm/three@0.186.0/examples/jsm/libs/draco/'),也可组合 KTX2Loader 与 Meshopt 处理压缩纹理。
使用方式:声明 mixer 在回调外以便循环访问;用 THREE.Timer(r183 起 Clock 已弃用),在 setAnimationLoop 中先 timer.update(time) 再取 timer.getDelta() 传给 mixer.update;或用 await loader.loadAsync(url)。
限制与常见问题:模型不可见通常是缺少灯光或 scene.environment,以及 glTF 以米为单位导致缩放过小;load 为异步,回调外引用需提前声明;动画不动多因未每帧 mixer.update 或误传毫秒;DRACO/KTX2 失败常因解码器路径或版本不匹配;不要为每个 clip 新建 mixer;导出器可能烘焙变换,使用前应检查节点层级。完整解码配置、LoadingManager 进度条、SkeletonUtils.clone 与导出建议见 references/loaders-and-animation.md。相关技能:threejs-scene-setup、threejs-materials-lighting、fps-shooter。