Implementing avatar feature, need help on switching between meshes

If you go https://three-d-f7212.web.app/ , you’ll find a small avatar customiser, but as you can see the replaced mesh doesn’t follow the animation, the code snippet responsible for the switch is

    clicked(name:string){
        const meshToRemove = this.scene.getMeshByName(name);
        const meshToAdd:B.AbstractMesh = this.allCustomizations[name][1];///customization in containers
        meshToAdd.skeleton = meshToRemove.skeleton;
        meshToAdd.parent = meshToRemove.parent;
        meshToAdd.animations = meshToRemove.animations;
        this.scene.removeMesh(meshToRemove);
        this.scene.addMesh(meshToAdd);
        this.allCustomizations[name] = [meshToAdd,meshToRemove];
    }

hope you understood what iam trying to achieve, what i am missing?

Welcome abroad! It seems that you should start the animations of meshToAdd?(just guess, it is hard for me to find the reason with the code)

Hi thanks for the reply, here what is happening is, I’m loading two glb’s, both are similar in hierarchy but visually different, lets a say hair mesh is different(visually), but only first file has animations, heres the psuedo code

meshToAdd = hairMeshFromFile2
meshToRemove = hairMeshFromFile1

how do i replace meshToRemove with meshToAdd so the meshToAdd becomes part of the scene from file1 and participates in all the animations.

1 Like

Hello @yadunandanks just checking in, do you need any further help? If so, can you please create a Playground example so that we can assist you better?

2 Likes