Hiding meshes depending of the camera position

Hello, I have to hide some meshes when the camera enters into an invisible box and then show this meshes once the camera is outside of the box. I know this is quite simple but I am just starting and havent found anything similar yet. Can somebody point out some examples or documentation?

Thank you

Hi. You can check intersections between meshes https://playground.babylonjs.com/frame.html#KQV9SA#0

3 Likes

https://www.babylonjs-playground.com/#5WY5G0#1

2 Likes

I leave that code for you to try to do it.
Notice that babylon.js has actions manager, among some of its properties is when a body enters, the explanation is here.
https://doc.babylonjs.com/how_to/how_to_use_actions

var Puntajes: BABYLON.Mesh[] = scene.getMeshesByTags("puntos") as BABYLON.Mesh[];//busco el nodo padre que contiene a esas columnas
        Puntajes.forEach(i => { //recorro todos esos objetos
            i.visibility = 0;//hago Visible/invisible las mallas que funcionan para sumar puntos
            //agrego un action manager a cada columna
            i.actionManager = new BABYLON.ActionManager(scene);//creo el nuevo action manager
            //register a new action with the marble's actionManager..this will execute code whenever the marble intersects the "killBox"
            i.actionManager.registerAction(
                new BABYLON.ExecuteCodeAction(
                    {
                    trigger:BABYLON.ActionManager.OnIntersectionEnterTrigger,//cuando nu cuerpo entra a esta area
                    parameter:pajaro//cuando el pajaro entra a esta area
                    }, 
                    function()
                    {//funcion para sumar puntos
                        ConteoDePuntos +=1;
                        Puntos.innerHTML = ConteoDePuntos as unknown as string;//convierto a string
                        //console.log("el pajaro entro al area para los puntos");//muestro este mensaje por consola
                    }
                )
            );
        });

Thank you everyone for your replies! I managed to mix them all and get exactly what I wanted, heres the PG, please correct me if there is something that can be optimized:

https://www.babylonjs-playground.com/#GR3IW2