Hello guys,
I want to switch from arcRotateCamera to UniversalCamera by toggled switch, I want to use the same var camera and not creating a second one and detachcontrol the first and attach the second.
thank you
Anes
Hello guys,
I want to switch from arcRotateCamera to UniversalCamera by toggled switch, I want to use the same var camera and not creating a second one and detachcontrol the first and attach the second.
thank you
Anes
The scene has two functions that could help you:
setActiveCameraByName
and setActiveCameraByID
, so you can create two cameras and switch between them.
this is using detachcontrol and then make scene.activeCamera , me I want to use the same camera and then with the toggled function I switch between them.
Maybe something along these lines:
var switchCamera = function () {
var camera = new BABYLON.FreeCamera("newCamera", scene.activeCamera.position, scene);
if (scene.activeCamera.rotation) {
camera.rotation = scene.activeCamera.rotation.clone();
}
camera.fov = scene.activeCamera.fov;
camera.minZ = scene.activeCamera.minZ;
camera.maxZ = scene.activeCamera.maxZ;
scene.activeCamera = camera;
scene.activeCamera.attachControl(canvas);
};
Couldn’t you trigger the setActiveCamera function in the toggled function?
So, you have, for example, HTML Button with a click function attached to it, and the event is firing the camera switch.
@RaananW sorry to bring this thread back, but I’m a bit curious, is there a design motivation for having the camera mechanics coupled to the camera itself? When I got started with babylon.js I sort of expected things like ArcRotateCamera
, and FreeCamera
to work the way the camera input system works - you’d attach some behavior to a renderable camera.
History and Back Compatibility are the only reasons
Good reasons. Thank you for the context.
NW I know how things are confusing even for us sometimes but considering 10 years of history, it could be a lot worse