Three.js anim stopAllAction
Shows that stopAllAction needs reverse loop.
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>THREE.js Anim stopAll() reverse loop</title>
<style>
body { margin: 0; }
canvas {
width: 100%;
height: 100%;
}
</style>
<script src="//cdn.rawgit.com/mrdoob/three.js/dev/build/three.js"></script>
<script src="//cdn.rawgit.com/mrdoob/three.js/dev/examples/js/loaders/GLTFLoader.js"></script>
</head>
<body>
</body>
</html>
JavaScript
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 1000);
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputEncoding = THREE.sRGBEncoding;
document.body.appendChild(renderer.domElement);
camera.position.set(0, 1, -4);
camera.lookAt(0, 1, 0);
scene.add(new THREE.AmbientLight(0xFFFFFF));
const clock = new THREE.Clock();
let mixer = null, actionA = null, actionB = null;
const loader = new THREE.GLTFLoader();
loader.load("//cdn.rawgit.com/mrdoob/three.js/dev/examples/models/gltf/Soldier.glb", (glTF) => {
mixer = new THREE.AnimationMixer(glTF.scene);
for ( const clip of glTF.animations ) {
if ( clip.name == "Idle" ) {
actionA = mixer.clipAction(clip);
} else if ( clip.name == "Walk" ) {
actionB = mixer.clipAction(clip);
}
}
scene.add(glTF.scene);
requestAnimationFrame(renderFrame);
doActionStuff();
});
function renderFrame() {
requestAnimationFrame(renderFrame);
mixer.update(clock.getDelta());
renderer.render(scene, camera);
}
function doActionStuff() {
actionA.reset().play();
actionB.reset().play();
window.setTimeout(() => {
stopAllAction();
console.log("All actions should have stopped. But actionB (walking) is still active...");
}, 2000);
window.setTimeout(() => {
console.log("Stop manually and play again.");
actionA.stop().play();
actionB.stop().play();
}, 4000);
window.setTimeout(() => {
stopAllActionReverse();
console.log("All actions should have stopped now correctly.");
}, 6000);
window.setTimeout(() => {
// Rinse and repeat.
doActionStuff();
}, 8000);
}
function stopAllAction() {
const actions = mixer._actions,
nActions = mixer._nActiveActions;
for (let i = 0; i !== nActions; ++i) {
actions[i].stop();
}
}
function stopAllActionReverse() {
const actions = mixer._actions,
...