Collectively change renderingGroupId for a hierarchy of meshes?

Here’s an example scene: Babylon.js Playground
I have 3 spheres: sphere, sphere2, sphere3. I set sphere and ground’s renderingGroupId to 1.

sphere2 and sphere3 are children of sphere, but do not inherit the renderingGroupId property. Lots of meshes being imported to Babylon are rigged meshes and transform nodes, and have a hierarchy to them. How do I set this property in a way that propagates through the children? I can think of some javascript-level recursion to address this, but could there be a built-in function for doing this more quickly?

        m.renderingGroupId = sphere.renderingGroupId

I could add here that if a mesh is not ‘a child of’ or if you want to tag all meshes for a certain renderingGroupId, you can also add an id to these meshes and then set your specific properties for the group of meshes with this Id. This can be very helpful because if you want to change the entire group of meshes, all you have to do is call on all meshes with this Id (or by splitting the Id, all meshes that contain within their Id an identifier that makes them part of the group of i.e. ‘renderingGroupId’).

1 Like

Thanks for this! That’s exactly the kind of function I was looking for.

One follow-up question: If one of the children is a particle emitter, how does the rendering group ID get propagated to that? Since getChildMeshes() returns an AbstractMesh and particle systems are not that.

In this case - if a child mesh is a particle emitter - it also means that particle emitter is that mesh.