I have imported a mesh in pg I can able to change the texture of the childmeshes ( like changing colour) but I want to change the childmesh itself for example if avatar is wearing a t-shirt I wanna replace it with shirt.can I do that using Babylon.js
@Wingnut help me with this
Thank you all in advance
Yes, you can remove a mesh (
mesh.dispose() if you want to remove the mesh from the scene or
mesh.setEnabled(false) if you simply want to hide it) and add a new one.
I think the mesh section of the doc should help you: Meshes | Babylon.js Documentation
Maybe you can provide a playground so that we can help with some code.
You did not say it was animated…
It will be quite more difficult because you would need that the cube have the same bones than the existing torso for the animation to work as expected.
You can try to use
attachToBone so that the box follows the same animation than the torso, but it has some limits (also, you need to tweak the box position and scaling to match the model):
@Evgeni_Popov I have a mesh with same bones as shirt then how to replace the shirt with that mesh.can you share code snippet
Simply hide/remove the old mesh and parent the new mesh to the same parent than the old mesh. You should also assign the same skeleton:
newMesh.parent = oldMesh.parent; newMesh.skeleton = oldMesh.skeleton; oldMesh.setEnabled(false); newMesh.setEnabled(true);
@Evgeni_Popov Mesh attached to avatar but animations are not working properly.newmesh has same bones and animations as the oldmesh.
I guess we will need a PG to be able to help more.