Adding animation to cloned objects

How do I trigger the animation for cloned objects? Do they each need their own animation? here is my code…

const loader = new THREE.GLTFLoader();
  loader.setPath(assetPath);
  loader.load('coin_v01.glb', object => {
    actions = [];

    coin = object.scene;
  
    mixer = new THREE.AnimationMixer(object.scene);
    object.animations.forEach( anim => {
      const action = mixer.clipAction(anim);
      actions.push(action);
    });
   
    actions[0].play();
    scene.add(coin);

    for(let count=0; count<1000; count++) {
      const coinClone = coin.clone();
      coinClone.position.z = count*2;
      scene.add(coinClone);
    }

    update();

  })

This works, but only the first object plays the animation.

thanks for any help,
Dale

Assuming coin is an instance of THREE.SkinnedMesh, you have to perform the clone with SkeletonUtils.clone(). Besides, you need an animation mixer for each cloned object. It’s not necessary to clone the animation clips though.

2 Likes