Created
June 12, 2023 20:19
-
-
Save wuhhh/49dd0f1a8b846346fd8704238ce2daeb to your computer and use it in GitHub Desktop.
Limit OrbitControls pan
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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