Looking to understand more about how Babylon renders a mesh

I am trying to understand how a mesh is loaded and rendered in a scene in Babylonjs. It goes without question that I am very new to all of this, and the reason I want to understand this is because of a silly error I am facing.

I am trying to toggle the visibility of a mesh in this silly little demo - p2dl-test-1 (please give 30-60 seconds to load completely).

In the demo I am able to hide the object, but I don’t understand why it is not reappearing.

I am basically copy-pasting this exact same code - Show - Hide Mesh | Babylon.js Playground (babylonjs.com)

Why can’t I do this simply using some setVsibility command? All of this feels very complicated :smiley:

This is my code - p2dl-error ($3703674) · Snippets · GitLab

Hello :slight_smile:

First of all, it a good practise to share a Playground reproducing your issue, it ables us to help

Then, did you try to log ?
I added in the playground above some logs :

function toggleMeshes(meshes){
    for (mesh of meshes){
        let enabled = mesh.isEnabled();
        console.log(mesh.name, ":", enabled, "-->", mesh.isEnabled());

And the result helps to understand :

__root__ : true --> false
GROUND_ASHPLAT : false --> false
GROUND_GRASS : false --> false
GROUND_RUNWAY_LIGHTS : false --> false
GROUND_RUNWAY : false --> false

What’s happenning is that you first setEnabled(false) the parent.
Which enable as false the children too. And they cannot be set to true since parent is false
Then when you click again :

__root__ : false --> true
GROUND_ASHPLAT : true --> false
GROUND_GRASS : true --> false
GROUND_RUNWAY_LIGHTS : true --> false
GROUND_RUNWAY : true --> false

Boom, the parent comes true alongs with the children, who now go false :grin:

So, solution is to deal only with the parent :

function toggleMeshes(meshes){

And here is the Fixed Playground

++ :slight_smile:


Thank you so much. This is not a practice I am familiar with, and I will be implementing it :slight_smile:

You are a life saver