Hi,
Is there an existing function that traverse a whole gltf loaded scene.?
I need to hide nodes based on their name.
Regards
S.Ancelot
Hi,
Is there an existing function that traverse a whole gltf loaded scene.?
I need to hide nodes based on their name.
Regards
S.Ancelot
you can use rootNote.getChildren()
to get a list of children, or getChildMeshes()
to get meshes
The API:
and
Both allow you to get the direct descendants or all of them, which can allow you to build your own tree or get all of the root’s children. You can also define a predicate to filter what node will be included.
You can also traverse scene.rootNodes
/ scene.transformNodes
/ scene.meshes
depending on your needs.
Hummm… rootNodes is empty in contianerAssset !
sorry, rootNode was just an arbitraty name of, well, the root node of your model If your model is loaded, the first mesh that is returned from loadMesh or from the assets container is usually the root node, which is the parent of all others.
If you want to share a playground with your attempts we can explain better
No, I was talking about this variable, that is empty after loading the containerasset
AssetContainer | Babylon.js Documentation (babylonjs.com)
want to show your scene in the playground? will be easier to explain why it is empty.
I haven’t found a traverse or ‘isMesh()’ method in Babylon, but this worked for me:
BABYLON.SceneLoader.ImportMesh(“”, “assets/models/”, “Blarg.glb”, scene, function (meshes) {
scene.createDefaultCameraOrLight(true, true, true);
var geo
for(geo in meshes){
console.log(meshes[geo].name)
}
});
I think this is what you are looking for.
Then I use a switch case statement to target a particular geometry for an operation or effect.
Also if you need to look for the class you can use
getClassName()
small note on getClassName - it will return the exact class name, so “Mesh”, or “AbstractMesh”, or “GroundMesh”. It’s not an exact way to make sure a node is a mesh, unless you know very well what is being used in your scene.