BABYLON.SceneLoader.ImportMesh always create an extra mesh

The method BABYLON.SceneLoader.ImportMesh always create and extra mesh in addition to the meshes. The first mesh seems to be a dummy mesh.

It not only causes extra use of memory but also gets really confusing when you need to pick a certain mesh by index.

The playground below prints the number of meshes, in this case it shoud be 1 but it prints 2. Every model that I tried has the same issue.

This mesh is created when you load a .gltf/.glb file to take care of the handedness: gltf files are right handed whereas Babylon.js is left handed, so there’s a special transformation on this node (named __root__) that transforms the geometry from left to right handed.

It is preferable to access meshes by name or by id (scene.getMeshByName / scene.getMeshById) because the order of the meshes in the returned array may change depending on how the file was exported / what data is in the file.

1 Like

@Evgeni_Popov Thank you for the explanation, I wasn’t aware of that.

That changes a lot on my side, because I was relying on index but at least now I know why some strange behaviors were happening.

If it’s by design, I will close it.