Replacing SkinnedMesh on fly

Hi, I work on kinda character’s editor and struggling with swapping skinned meshes(clothes, glasses and so on).

How I imagine the ideal implementation: We have one gltf file with animated default character, then we have the ability to switch T-shirts, for example. The T-shirt asset saved as separate GLTF, it doesn’t have any additional information, just simple mesh. When we download T-shirt assets on the client, we somehow attach it to existing bones and it starts moving with the character on the scene. As you probably noticed I have no idea how to attach simple mesh to bones and make it works. I can add some simple asset to specific bone and it will move with that bone, but for example we have pants asset that is also single mesh, but we have at least 4 bones(2 bones for each leg) for this mesh. How to attach single mesh to multiple bones?

Not very ideal option but still acceptable: a T-shirt has the same bones structure as default character. In that case it’s not just a Mesh, but Skinned mesh, but still I cannot attach it to existing bones correctly, it’s not clear to me at all to which skeleton I should bind these meshes to make it move with the rest of the character. For now, my mesh either become broken(looks like vertices of mesh attached to the wrong bones and end of shoe stretched to right hand for example) or it renders correctly but only change it’s position with character, without changing it’s form(both shoes just attached to one leg and only moves up/down, left/right, without rotation and bending).

I searched trough documentation, specs, courses, guides for a week and still haven’t found the solution and I do not understand maybe I just missed something obvious because the character’s editor looks pretty common challenge to me, but there is not much info about that. Or maybe I misunderstood some fundamentals and now I’m doing wrong conclusions based on this misunderstanding.

This is example of second approach, it works :slightly_smiling_face: Edit fiddle - JSFiddle - Code Playground

Not sure about first approach, looks like I would need to create some very smart algorithm to make the thing I wanted to.