Created
May 12, 2024 01:51
-
-
Save cecilemuller/569daaa835d33d7f3cfdc96488366d91 to your computer and use it in GitHub Desktop.
three.js: press ESC to reset view
This file contains 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
import gsap from "gsap"; | |
const defaultPosition = {x: 40, y: 20, z: 40}; | |
const defaultTarget = {x: 0, y: 2, z: 0}; | |
// ... | |
window.addEventListener("keyup", (e) => { | |
if (controls.enabled && (e.key.toLowerCase() === "escape")) { | |
e.preventDefault(); | |
controls.enabled = false; | |
gsap.timeline({ | |
onUpdate() { | |
controls.update(); | |
}, | |
onComplete() { | |
controls.enabled = true; | |
} | |
}) | |
.to(camera.position, { | |
ease: "power2", | |
x: defaultPosition.x, | |
y: defaultPosition.y, | |
z: defaultPosition.z, | |
}) | |
.to(controls.target, { | |
ease: "power2", | |
x: defaultTarget.x, | |
y: defaultTarget.y, | |
z: defaultTarget.z, | |
}, "<"); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment