Keeping mesh on camera

Hey team,

again on my journey toward babylon, I am stuck on a point where I need to hide meshes from second camera, I am using layer mask like this:

	var firstCamera = new BABYLON.ArcRotateCamera('firstCamera', 0, 2.3, 32, BABYLON.Vector3.Zero(), scene);
        firstCamera.layerMask = 0x10000000;
	var secondCamera = new BABYLON.ArcRotateCamera('secondCamera', 0, 2.3, 32, BABYLON.Vector3.Zero(), scene);
        secondCamera.layerMask = 0x20000000;

and to show a a unique mesh on each camera, I am assigning layerMask like this
firstMesh.layerMask = 0x10000000;
secondMesh.layerMask = 0x20000000;

I want to show first Mesh also on second camera, something like maybe layerMask takes an array? :
firstMesh.layerMask = [0x10000000 , 0x20000000 ];
secondMesh.layerMask = 0x20000000;

how could I achieve that?

p.s, second question: how can I capture if my mouse is hovering over firstCamera or secondCamera? , for secondCamera I am using viewport
secondCamera.viewport = new BABYLON.Viewport(0, 0, (2) / (canvas.width / 100) / 1.2,(2) / (canvas.height / 100) / 1.2);


LayerMask is a bit mask:

so if ground is one and sphere (both using a bit) to see both you need to use 3 (really just a plain bitmask);

1 Like

Thanks @sebavan … that worked ,

any idea how can I capture mouseEnter/Leave events
what I want to accomplish is, when I hover on second camera it should set scene.cameraToUseForPointers = secondCamera; and when mouse Leave secondCamera it should set scene.cameraToUseForPointers = camera;

could you not simply check scene.PointerX and scene.pointerY manually to see if you are in your wished Viewport ? it would be the easiest

@sebavan I think you are suggesting it to add on move?

scene.onPointerMove = function (evt, pickResult) {
   // do something with scene.pointerX here ?

isn’t scene.pointerY/X values different on each screen? and, also will that work on touch event? could you please example in PG , Thanks

So the screen will be different but if you use a viewport of 0.5 for the width you know that if pointerX > engine.getRenderingWidth() / 2 you would be into it. you could apply the same on y.

And yup doing it this event is ok.

1 Like

Thanks @sebavan, I was getting undefined error with engine.getRenderingWidth so I used canvas.widthand later found its engine.getRenderWidth, but seems my mind is stuck on this simple math calculation. I have setup a viewport like this

let viewSizeX =  (2 / (canvas.width / 100) / 1.2);
let viewSizeY =  (2 / (canvas.height / 100) / 1.2);
secondCamera.viewport = new BABYLON.Viewport(0, 0, viewSizeX ,viewSizeY);
scene.onPointerMove = function (evt, pickResult) {
let whatX = ?
let whatY = ?
       if(scene.pointerX  <<  whatX && scene.pointerY <<  whatY){


The issue I am facing is, scene.pointerX/Y coordinates start from top left corner of screen, while viewport’s start from bottom left corner, so trying to figure out how to calculate this.

@sebavan, Thanks for the points… finally figured after awoke up, I had to calculate like this

let percentage = 50;
let viewSizeX =  percentage / 100;
let viewSizeXPoz =  (canvas.width/100)*percentage ;

guess needed a good night sleep :grin:

1 Like