Skip to content

Instantly share code, notes, and snippets.

@cecilemuller
Created May 12, 2024 01:51
Show Gist options
  • Save cecilemuller/569daaa835d33d7f3cfdc96488366d91 to your computer and use it in GitHub Desktop.
Save cecilemuller/569daaa835d33d7f3cfdc96488366d91 to your computer and use it in GitHub Desktop.
three.js: press ESC to reset view
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