Hello,
I am trying to animate a character for a three js project… I just can’t get this to work . I have used https://gltf-viewer.donmccurdy.com/ gltf viewer, I can see the animations loading in the viewer and working… I’ve revised the source code, but as I am fairly inexperienced in threejs development, I am finding this tricky to apply to my project.
here’s my code:
// Create an AnimationMixer, and get the list of AnimationClip instances
var mixer;
const model = new GLTFLoader ()
.setPath('./3d/characters/')
.setCrossOrigin('anonymous')
.load( 'Witch.gltf', function ( gltf ) {
const clips = gltf.animations || [];
scene.add( gltf.scene );
var model = gltf.scene;
model.position.set(0, 0, 0);
model.scale.set(5.5, 5.5, 5.5);
console.log(clips);
mixer = new THREE.AnimationMixer( model );
// const clip = THREE.AnimationClip.findByName( clips, )
mixer.clipAction( clips[1] ).play();
// Play all animations
// clips.forEach( function ( clip ) {
// mixer.clipAction( clip ).play();
// } );
animate();
render();
});
function update() {
mixer.update( deltaSeconds );
}
and later…
//render / animate loop
function animate() {
requestAnimationFrame( animate );
}
function render() {
renderer.render( scene, camera );
}
animate();
render();
I can see all the animations listed when I console.log clips. I can’t access them, but my code seems okay from the tutorials I’ve follow on threejs… Any help much appreciated