Some of the equirectangular images I import have an “initial heading” set which is the direction (0…360) to point the camera and I would like to support this. I added some code to reset the camera rotation in terms of the OrbitControls() in place but it doesn’t seem to work despite trying many different things. Is it possible and if so, can someone point me in the right direction?
Put the camera in the desired position and call the saveState() method.
Then the state of the camera is saved.
After this, if you call the reset() method at a desired point in time, the camera position is restored.
OrbitControls automatically calls the saveState() method upon creation.
Understood and reset() seems to do what you describe - fiddle here with code.
However, positioning the camera still only works the first click - moving the scene with the mouse then clicking the left button again (same angles) should move it back to same position each time surely?
Resetting does not erase the saved information.
When I run the source you gave me, it works like that.
Checking the source does not seem to clear the saved location.
Here is another fiddle with 3 buttons - pressing each should move the camera to a predefined angle. They all work the first time, but subsequently, they move the camera by a tiny amount.
I didn’t understand your answer at first, but using what you wrote to position the camera target and calling controls.update() appeared to do the trick.
function position_camera(controls, angle) {
var spherical_target = new THREE.Spherical(1, Math.PI / 2, angle);
var target = new THREE.Vector3().setFromSpherical(spherical_target);
camera.position.set(target.x, target.y, target.z)
controls.update();
controls.saveState();
}
This feels like a bit of a cheat but it’s the only thing that has worked so thank you.