Hello guys, I’m new with using three.js. I’m trying to load my character and plays its animation, everything seems to work fine but mixer.clipAction(myanimations[index]).play(); are not playing.
var model;
var action1;
var action2;
var action3;
var action4;
var action5;
var myanimations = new Array(5);
var loader = new THREE.GLTFLoader();
loader.load('3D/model/model.glb', function (gltf) {
model = gltf.scene;
scene.add(model);
mixer = new THREE.AnimationMixer(model);
myanimations = gltf.animations;
console.log(myanimations);
// get all the animations
//first animation
action1 = mixer.clipAction(myanimations[0]);
//second animation
action2 = mixer.clipAction(myanimations[1]);
//third animation
action3 = mixer.clipAction(myanimations[2]);
//fourth animation
action4 = mixer.clipAction(myanimations[3]);
//fifth animation
action5 = mixer.clipAction(myanimations[4]);
});
document.addEventListener("keydown", onDocumentKeyDown, false);
function onDocumentKeyDown(event) {
var keyCode = event.which;
if (keyCode == 87) {
action1.play();
console.log(myanimations[0].name);
} else if (keyCode == 83) {
action2.play();
console.log(myanimations[1].name);
} else if (keyCode == 65) {
action3.play();
} else if (keyCode == 68) {
action4.play();
console.log(myanimations[3].name);
} else if (keyCode == 32) {
action5.play();
console.log(myanimations[4].name);
}
};
the scene is loaded from another script and here is my html script tags
<script src="js/three.js"></script>
<script src="js/OrbitControls.js"></script>
<script src="https://threejs.org/examples/js/loaders/GLTFLoader.js"></script>
<script src="js/AnimationMixer.js"></script>
<script src="js/sceneloader.js"></script>
<script src="js/modelcontroller.js"></script>
What can be wrong ? Thank you in advance guys.