Can I use the .getObjectByName method to target meshes that are grouped?

I have a very complex model created in blender and all the meshes are organised into groups (or empties) so the hierarchy looks like that:

Can I still get individual meshes using the get .getObjectByName or do I have to get the group first and cycle through children to find the name.

Ungrouping that many meshes (over 60) will take me ages and also messes up the model so I would rather keep the hierarchy as is.

Thanks for your help!

According to the documentation, getObjectByName should traverse the object and its children. To have names, the model must be in a format that supports names. GLTF is such format. However, keep in mind that the names after loading the model in Three.js might differ from the names in Blender.

BTW you could make a quick experiment - export the model in GLTF/GLB, import it in Three.js, traverse recursively all nested objects and print their names. This would show whether names are existing and preserved, existing and nor preserved or not existing.

Yeah I forgot to mention I plan to export the model as .glb

I will do a test to see if that works and report back soon. I think there would be a benefit in keeping these meshes grouped if I want to affect them in bulk but having individual control over single meshes is also useful.

yes u can use getObjectByName but this method traverse the whole scene and if u have a scene that has too many assets or mesh in it would affect ur rendering performance, I suggest u index the assets u need to be looking for then search that index instead of using getObjectByName or getObjectByProperty.

1 Like
let mesh={};

model.traverse(function(child){
if(child.name){
mesh[child.name]=child;
}
});

mesh["Amygdala_L002"].position.x=5;
mesh["Cerebellum_R002"].position.z=1;
1 Like

So after a few tests, using the .getObjectByName method works both the mesh and the group so if I want to transform a single mesh then target it by it’s name and if you want to transform a whole group then use the group name instead.

I like the above solutions too!

Thanks for your help!

1 Like