Changing abstract mesh of a loaded glb model with another one

Hello guys. I loaded a glb model using import mesh async. I made a transform node as the parent of this root node (meshes[0]). There is another model loaded using import mesh async itself. I want to change the one of the abstract meshes in first loaded model (approximately meshes[11]) with one of the abstract mesh of newly imported model(meshes[2]). How can I do this

Can you share a Playground with your situation?

I am sorry that it is restricted to use the model in public websites. But I could share the situation in more detail
Basically there is a avatar model. It’s loaded using import mesh async. There will be a root node for the model which can be accessed via mesh[0] right? I made a transform node and made transform node as the parent of this root node. Within this model, I want to replace a particular mesh. The mesh that is to be replaced is another mesh similar like this on another model. That’s all. If there is any limitations in doing this, I just want to know whether I could atleast copy the material and geometry of that particular mesh to this mesh. The iissue was that When I try to access mesh[11].material it shows it doesn’t have material property. Same goes for the geometry too

Hard to debug without a repro. Though, since it is an avatar you might be selecting a transformNode instead of the mesh? I would say the ez way to figure this out would be you use the Inspector to check the hierarchy of the model and look for the Then access this mesh by its name after the promise is done with scene.getMeshByName(“mymeshtoremove”)

Thanks for the solution. I will try it out and update. Also I would try to add a playground so that situation would be more clear

Hi. This is the code snippet. I am actually placing transform node as the parent of meshes[0]
const { meshes, animationGroups, geometries } = await SceneLoader.ImportMeshAsync(
const model2 =await SceneLoader.ImportMeshAsync(
meshes[11].material = model2.meshes[1].material;
I could able to change material of mesh[11] of model1 with mesh[1] of model2
Now I want to copy the corresponding geometry data too… Any solution

I’am not sure to fully understand your request. May be a language issue here. Obviously the geometry is the vertex and index of mesh. But further up in the post, you said you want to replace a mesh with another, didnt’ you? This sort of confuses me :thinking:
Anyways, you can clone a mesh or you could instance a mesh or create a new one (depending on use case). Then the clone or instance or new needs to be set as a child of your other/new parent (for the part #1 of your request).
As for updating the geometry (vertex+index) of the new mesh from your initial/old mesh, I believe it would be something like:

    let newmesh = model2.mesh[1];
    let importmesh = model1.meshes[11];

Of course, you would need to do it either inside the import function or as I said you can access them by name (or id) after the promise. But yes, basically, applying geometry is made through
mesh.geometry.applyToMesh(newmesh). As far as I know (and I know only little :grin: :wink:

Still, hope you’ll figure it out. Else, let us know (and then in this case, really try to make a PG please :pray:)

You don’t need to use your original asset, you can use any public asset just as an example.

Yeah I checked in internet, but I could not find such a model. This model was custom made. It’s basically a rigged human model with different meshes in it like hand, body, leg etc.

Could not able to find such a model in public website.

I will try my maximum to explain
The model I am using is a rigged human model with different meshes like body, hand, leg etc.
There is another model with only cloth mesh but it is also rigged model. so it has same bone structure as human avatar but only cloth mesh. So I need to change the body mesh in my avatar with cloth mesh in other model. Material could be easily shared as I mentioned before
meshes[11].material = model2.meshes[1].material;
I could also able to copy the geometry using applytomesh llike you said, but it’s looks broken.
This was a cheeky way to do like copying material and geometry

So is there any way like copy that cloth mesh from that rigged model, dispose this body mesh of my avatar and replace it with cloth mesh so that the it looks like cloth changing.
Both are rigged in same way. So all animations should sync with new cloth if it is properly changed

To keep things simple
rigged human model with the following structure

---- root
— head : transformnode
– head : mesh
— body : transformnode
– body : mesh
— arm : transformnode
– arm : mesh
… blah blah

Let’s say you want to replace a human arm with a robotic arm.
where human arm is the existing mesh[2] and robotic arm is the new mesh to be changed

  1. Dispose of mesh[2]
  2. Set up a new mesh to be transformed as a child under the parent transformnode of the mesh you want to transform to match its skeleton structure.
  3. Give new meshan existing skeleton

The structure and animation of the bones prevents them from breaking.

ps. What you said above is a little different, as you are not copying material[2] = new material, but to the material of the mesh.


I see. I have to say I’m not the best working on avatars. Though from your writing above, I believe the answer from @11128 pinpoints your issue in the aspect of

Then, if you cannot figure it, REALLY try to make a PG (with any dummy avatar in case).
It will makes things a lot easier for everyone and answers a lot more accurate.
Meanwhile, have a great day :sunglasses:

1 Like

Oh I see. Let me check that… Really thanks for the info

:smiling_face_with_tear: If I knew modeling, I could have created one for sure. Anyways thanks for the support and will try to get similar model from anywhere if @11128 method doesn’t work

Have a great day :heart_eyes:

Yeah, I hope it will work.
Else, you can try just take ‘DUDE’ and import it twice and rename the second for a quick test.
Or, you could use ‘BrainStem’ as the second model. Both available from here.

Else, I think there’s been a recent post with avatars changing clothes. I’m sure (I hope) the user wouldn’t mind if we used his PG as a base to debug your case. I would just need to find it so (in case), let me know…

Yeah. Thank you. I will update the progress. Let me check with the sample models. If I could recreate my situation it would be better

Aaaah, that explains the situation more :slight_smile: @PatrickRyan and @Evgeni_Popov have been working with avatars quite a bit, so they might have pointers on this?

From what I understand, you would simply need to find the mesh you want to replace (maybe by doing meshToReplace = scene.getMeshByName("name of mesh") or by any other mean), then put the new mesh at that location in the mesh hierarchy (newMesh.parent = meshToReplace.parent), then remove / disable the old mesh (meshToReplace.parent = null / meshToReplace.setEnabled(false)).

If meshToReplace has children, you should also loop over the children (meshToReplace.getChildren() will return all children in an array) and set the parent of these meshes equal to newMesh.


Oh. I see

Thank you. I will try this out