Skip to content

Instantly share code, notes, and snippets.

@wuhhh
Created June 12, 2023 20:19
Show Gist options
  • Save wuhhh/49dd0f1a8b846346fd8704238ce2daeb to your computer and use it in GitHub Desktop.
Save wuhhh/49dd0f1a8b846346fd8704238ce2daeb to your computer and use it in GitHub Desktop.
Limit OrbitControls pan
/**
* Limit OrbitControls pan
*/
const controls = useRef();
const minPan = new THREE.Vector3(-2, 1, 0);
const maxPan = new THREE.Vector3(2, -1, 0);
useEffect(() => {
const _v = new THREE.Vector3();
controls.current.addEventListener("change", function () {
_v.copy(controls.current.target);
controls.current.target.clamp(minPan, maxPan);
_v.sub(controls.current.target);
camera.position.sub(_v);
});
}, []);
<OrbitControls ref={controls} />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment