clampWhenFinished

Good day to everyone. I need the animation to finish after the first loop. clampWhenFinished does not work.

Thank you for your help.

// Model

    const loader = new GLTFLoader();

    let mixer = null;

    loader.load("model/Heli_bell.glb", (gltf) => {
        const model = gltf.scene;
        model.scale.set(2, 2, 2);
        mixer = new THREE.AnimationMixer(model);
        const action1 = mixer.clipAction(gltf.animations[0]);
        const action2 = mixer.clipAction(gltf.animations[1]);
        const action3 = mixer.clipAction(gltf.animations[3]);
        
        action1.clampWhenFinished = true;

        action1.play();
        action2.play();
        action3.play();

        scene.add(model);
    });

    const clock = new THREE.Clock();

    const tick = () => {
        const delta = clock.getDelta();
        if (mixer) {
            mixer.update(delta)
        }

        window.requestAnimationFrame(tick);
    }

    tick();

Make sure to read the docs, this should sort it.

2 Likes

Thank you.
It was easy:

action1.setLoop(THREE.LoopOnce);
action1.clampWhenFinished = true;
action1.enable = true;
1 Like