Is there an easy way to limit the zoom in/out on the camera for the viewer?

I tried looking for something simple in hoops but could not find anything. Do I have to like create a custom operator or something and capture mouse events and restrict zoom that way?

Seems like something simple that Hoops should provide for the camera or the view…

Thanks!

Hello @mark.aronin,

The camera behaves dynamically when zooming because its position, width and height adjust together. This coordinated change helps prevent artefacts such as extreme pincushion distortion. There isn’t a built-in setting to clamp zooming.

That said, I think it’s possible to leverage the camera callback to limit the zoom based on the value of the camera width attribute. Below is a quick example:

let viewer = hwv;
let widthLimit, heightLimit;
let multiplier = 0.1; //some arbitrary limit based on the initial camera

let initialCam = viewer.view.getCamera();
widthLimit = initialCam.getWidth() * multiplier;

// holds the last good camera
let lastValidCamera = null;

function clampCameraZoom(camera, view) {
    const width = camera.getWidth();

    // Check camera width attribute
    if (width < widthLimit) {
        if (lastValidCamera) {
            let restoreCam = new Communicator.Camera();
            restoreCam = lastValidCamera.copy();
            view.setCamera(restoreCam);
        }
        return;
    }

    /// STore the last good camera
    let stored = new Communicator.Camera();
    stored = camera.copy();
    lastValidCamera = stored;
}

//set camera callback
hwv.setCallbacks({
    camera: clampCameraZoom
});