addTargetedAnimation to more than one mesh or element

Hello,
i’m working with an AnimationGroup and i was wondering if there’s a way to associate an animation to more than one element, cause it seems redundant.
Probably i’m not using babylon functionalities at its fullest, cause this is the verbose result:

this.animGroupMesh.addTargetedAnimation(animColor, scene.meshes[1]);
this.animGroupMesh.addTargetedAnimation(animColor, scene.meshes[2]);
this.animGroupMesh.addTargetedAnimation(animColor, scene.meshes[3]);
this.animGroupMesh.addTargetedAnimation(animColor, scene.meshes[4]);
this.animGroupMesh.addTargetedAnimation(animColor, scene.meshes[6]);
this.animGroupMesh.addTargetedAnimation(animColor, scene.meshes[7]);
this.animGroupMesh.addTargetedAnimation(animColor, scene.meshes[8]);
this.animGroupMesh.addTargetedAnimation(animColor, scene.meshes[10]);
this.animGroupMesh.addTargetedAnimation(animColor, scene.meshes[11]);
this.animGroupMesh.addTargetedAnimation(animColor, scene.meshes[13]);
this.animGroupMesh.addTargetedAnimation(animColor, scene.meshes[14]);
this.animGroupMesh.addTargetedAnimation(animColor, scene.meshes[15]);
this.animGroupMesh.addTargetedAnimation(animColor, scene.meshes[16]);
this.animGroupMesh.addTargetedAnimation(animColor, scene.meshes[17]);
this.animGroupMesh.addTargetedAnimation(animColor, scene.meshes[18]);
this.animGroupMesh.addTargetedAnimation(animColor, scene.meshes[19]);

Do you know if there’s a way to avoid this repetition and to do something like:
this.animGroupMesh.addTargetedAnimation(animColor, [scene.meshes[1], scene.meshes[2], scene.meshes[3], scene.meshes[4]]); ?
Or to prevent this situation in any ways?
Thank you

well you can do a loop :slight_smile: addTargetedAnimation will attribute an animation to a target so if you have multiple targets you need to call it many times

thank you for the answer!
The loop was my first try but, i wrongly left inside the loop also the root mesh (i’m working with a .gltf), and that made the animation start immediately without taking care of animation.pause().
Silly mistake, thank you again!

1 Like