0

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?

Dr. Aaron Dishno
  • 1,859
  • 1
  • 29
  • 24

2 Answers2

1

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

David Catuhe
  • 1,747
  • 1
  • 10
  • 9
0

Using #DavidCatuhe 's answer I was able to write this function others might find useful. Thanks!

function iscamaraattached() {
    var attached = false;
    if (scene.activeCameras != null) {
        for (var i=0;i < scene.activeCameras.length;i++) {
            if (scene.activeCameras[i].inputs.attachedElement != null) {
console.log("i=" + i + " - " + scene.activeCameras[i].inputs.attachedElement.id);
                attached = true;
            }
        }
    }
    return attached;
}
Dr. Aaron Dishno
  • 1,859
  • 1
  • 29
  • 24