Skip to content

Instantly share code, notes, and snippets.

@Samsy
Forked from ayamflow/gltf-anim.js
Created April 15, 2018 15:59
Show Gist options
  • Save Samsy/c91e1b050dffd26abeb4400a2cff7b54 to your computer and use it in GitHub Desktop.
Save Samsy/c91e1b050dffd26abeb4400a2cff7b54 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