AbstractMesh .getChildMeshes(false) && .getChildTransformNodes(false)

Hello again!
I think I’ve stumpled upon a bug, or atleast an unexpected behaviour from the naming of a function.

After importing a .glb file (haven’t tested with other formats but I assume it’s the same since the functions are called on the AbstractMesh class), calling .getChildMeshes(false /get all descendants/) to get all the meshes in the glb file works as expected: I get all the meshes contained within the file.

However, then wanting to get all the nodes only, using .getChildTransformNodes(false), I both get all the nodes as TransformNodes, but I also in addition get all the meshes. Is this expected? If so, then the .getChildren(null, false) seems redundant or vice-versa.

Wish you a great day!


1 Like

Well, the Mesh class extends AbstractMesh, which extends TransformNode. So, meshes are themselves transform nodes. Getting both the meshes and the other nodes from getChildTransformNodes is the expected behavior. It’s a more inclusive function.

getChildMeshes, on the other hand, returns exclusively the children who are meshes, excluding all other transform nodes. So in this case, it only returns PlaneMesh0 and PlaneMesh.

If you want to get only the non-mesh transform nodes, you could call:

getChildTransformNodes(false).filter(node => !(node instanceof BABYLON.AbstractMesh));```

This will filter the array, removing any node which is an instance of AbstractMesh.


Thanks for the thorough explanation. It makes sense, I guess the wording just spawned some different assumptions in my brain. Although I fail so see the usage of the .getChildren(null, false) function then. Could you explain what the purpose of this method is in relation to the others?

And thanks for the code tip!

getChildren() will return all child nodes, regardless of whether or not they are TransformNodes. Not all nodes are transform nodes.

So to sum it up:

  1. getChildren → all children
  2. getChildTransformNodes → all children who are transform nodes
  3. getChildMeshes → all children who are meshes

Each function returns an increasingly specific group.


Ah! Awesome. Thanks for the responses! They really helped out :smile:

1 Like