javascriptcanvasbabylonjscamera-view

find if camera has attached or detached keyboard control to canvas in Babylonjs


I have a program in BabylonJS that has multiple cameras (free camera, scene, follow, and sometimes an arc camera). I set the active camera(s) and attach control (keyboard based movement) using the following:

scene.activeCameras[0] = camera;
camera.attachControl(canvas);

There are times I bring up html forms in my program and allow the user to type in the form (or temporarily turn the controls over to custom keydown / keyup controls) so I use the following to detach the control (so that the typed keys are not intercepted by the canvas scene):

for (var i = 0;i < scene.activeCameras.length;i++) {
    scene.activeCameras[i].detachControl(canvas);
}

Then I attach again when done. This works great, but there are times when I need to test if the control is attached or not.

Currently, I set an outside variable (but I have to place it in many locations in my code) but I was wondering if there is a function in BabylonJS that tells you the attached control camera name or boolean true / false if camera control is currently attached?


Solution

  • you can test scene.activeCameras[i].inputs.attachedElement