Skip to content

Instantly share code, notes, and snippets.

@ayamflow
Last active October 17, 2018 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ayamflow/39a673661075aa21d3300936dcaf1ff3 to your computer and use it in GitHub Desktop.
Save ayamflow/39a673661075aa21d3300936dcaf1ff3 to your computer and use it in GitHub Desktop.
threejs GLTF animation
// There's always some fiddling because the GLTF exports a whole scene
// with root bone and skinned mesh already appended to it.
let gltf = loadedGltf;
let skinned;
gltf.scene.traverse(function(object) {
if (object instanceof THREE.SkinnedMesh) {
skinned = object;
}
})
this.mesh = skinned;
this.mesh.material = ... // if you need a custom material, don't forget to set skinning to true
// Important: add the whole gltf scene and use it as root for the mixer
this.add(gltf.scene);
this.mixer = new THREE.AnimationMixer(gltf.scene);
this.animation = this.mixer.clipAction(gltf.animations[0]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment