setCameraConstraints - camera blocking problem

Hi,
I have a problem with camera locks.
I am using Viewer API

Camera locks are applied correctly except for zoomIn.
There is no limit to it and I can zoom in as much as I like.
Interestingly, zoomOut blocks the camera properly.
Does anyone have an idea what the reason is?

this.sf.setCameraLookAt([-5,-7,2], [0, 0, 0.7]);
this.sf.setCameraConstraints({
                        "position": [
                          -5,
                          -7,
                          2
                        ],
                        "target": [
                          0,
                          0,
                          0.7
                        ],
                        "fov": 15,
                        "nearFarRatio": 0.005,
                        "useCameraConstraints": true,
                        "usePanConstraints": true,
                        "useZoomConstraints": true,
                        "usePitchConstraints": true,
                        "useYawConstraints": true,
                        "zoomIn": 7,
                        "zoomOut": 7.1,
                        "left": 1.6644929497966974,
                        "right": -1.6644929497966974,
                        "up": 1.555089,
                        "down": -0.14551434605270586
});
this.sf.setEnableCameraConstraints(true);

Hi @pawelgix,
first of all: that’s a great looking configurator, also on smaller screens!

I see the zoom constraints issue. After you use setCameraConstraints to define your constraints, you should use setEnableCameraConstraints(true, { preventFocus: false }); to actually enable the constraint system and move the camera to comply with the constraints.
In your code I see you’re using setEnableCameraConstraints in a few places, but not directly when you’re adjusting your zoom constraints.

Here’s a codepen which demonstrates this: https://codepen.io/klaasnienhuis/pen/rNvrXWE

I tried your solution but it doesn’t seem to change anything.

await store.sf.setEnableCameraConstraints(false);
await store.sf.setCameraLookAt([-5,-7,2], [0, 0, 0.7]);
store.sf.setCameraConstraints({
    "position": [
        -5,
        -7,
        2
    ],
    "target": [
        0,
        0,
        0.7
    ],
    "fov": 15,
    "nearFarRatio": 0.005,
    "useCameraConstraints": true,
    "usePanConstraints": true,
    "useZoomConstraints": true,
    "usePitchConstraints": true,
    "useYawConstraints": true,
    "zoomIn": 7,
    "zoomOut": 7.1,
    "left": 1.6644929497966974,
    "right": -1.6644929497966974,
    "up": 1.555089,
    "down": -0.14551434605270586
});
store.sf.setEnableCameraConstraints(true, {
    preventFocus: false
});

You can repeat it by launching from the console:

I am beginning to think that there is something wrong with the camera limit settings. But at the moment I have no idea what is wrong.

It seems that when I remove the command:
await store.sf.setEnableCameraConstraints(false);
It is the locks that start working - despite the error. But then setCameraLookAt will not work properly due to the previous camera constraints.

The problem was probably in the sequence of actions
store.sf.setEnableCameraConstraints (true, {
preventFocus: false
});
must be before setCameraConstraints (options)

1 Like

You’re right, this is not predictable at all. In my codepen example it works fine, but when I try the same in your project, it doesn’t.
I’m glad you could solve it by tweaking the order of things.