How to limit pan in OrbitControls for OrthographicCamera?

It’s best to modify OrbitControls for this use case. So copy the class and define two new variables that you can use to control the minimum and maximum pan movement at the top of the file.

var minPan = new THREE.Vector3( - 2, - 2, - 2 );
var maxPan = new THREE.Vector3( 2, 2, 2 );

In the update() method, add the following line after panOffset was added to the target of OrbitControls.

scope.target.clamp( minPan, maxPan );

Demo: https://jsfiddle.net/t2exac47/

Panning means to offset the control’s target vector and thus the camera. If you restrict the target vector, you also restrict the camera’s final position.

8 Likes