Last active
October 17, 2018 17:07
-
-
Save ayamflow/39a673661075aa21d3300936dcaf1ff3 to your computer and use it in GitHub Desktop.
threejs GLTF animation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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