-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a107c15
commit ef3f230
Showing
4 changed files
with
141 additions
and
27 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { useThree, useFrame } from "@react-three/fiber"; | ||
import { useRef, useEffect } from "react"; | ||
import { gsap } from "gsap"; | ||
import { useControls, button } from "leva"; | ||
import { OrbitControls } from "@react-three/drei"; | ||
|
||
export default function Camera() { | ||
const cameraRef = useRef(); | ||
|
||
const { camera } = useThree(); | ||
|
||
const animDuration = 3; | ||
|
||
useEffect(() => { | ||
cameraRef.current.enabled = false; | ||
|
||
gsap.to(camera.position, { | ||
x: 0, | ||
y: 0, | ||
z: 5, | ||
duration: animDuration, | ||
ease: "power2.inOut", | ||
onUpdate: () => { | ||
camera.lookAt(0, 0, 0); | ||
}, | ||
onComplete: () => { | ||
cameraRef.current.enabled = true; | ||
}, | ||
}); | ||
}, []); | ||
|
||
useControls("Camera", { | ||
anim1: button(() => { | ||
cameraRef.current.enabled = false; | ||
|
||
gsap.to(camera.position, { | ||
x: -5, | ||
y: 2, | ||
z: -5, | ||
duration: animDuration, | ||
ease: "power2.inOut", | ||
onUpdate: () => { | ||
camera.lookAt(0, 0, 0); | ||
}, | ||
onComplete: () => { | ||
cameraRef.current.enabled = true; | ||
}, | ||
}); | ||
}), | ||
reset: button(() => { | ||
cameraRef.current.enabled = false; | ||
|
||
gsap.to(camera.position, { | ||
x: 0, | ||
y: 0, | ||
z: 5, | ||
duration: animDuration, | ||
ease: "power2.inOut", | ||
onUpdate: () => { | ||
camera.lookAt(0, 0, 0); | ||
}, | ||
onComplete: () => { | ||
cameraRef.current.enabled = true; | ||
}, | ||
}); | ||
}), | ||
}); | ||
|
||
return ( | ||
<group> | ||
<OrbitControls | ||
ref={cameraRef} | ||
target={[0, 0, 0]} | ||
// autoRotate | ||
// autoRotateSpeed={0.75} | ||
// enableZoom={false} | ||
minDistance={3} | ||
maxDistance={25} | ||
enablePan={false} | ||
maxPolarAngle={(Math.PI * 2) / 3} | ||
minPolarAngle={Math.PI / 3} | ||
/> | ||
</group> | ||
); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,20 @@ | ||
import { Html, useProgress } from '@react-three/drei'; | ||
import { Html, useProgress } from "@react-three/drei"; | ||
|
||
export default function CanvasLoader() { | ||
const { progress } = useProgress(); | ||
|
||
return ( | ||
<Html center> | ||
<img src="/icon512.png" alt="Earth Placeholder" /> | ||
<h1 className=" text-white mt-4"> | ||
LOADING... {progress.toFixed(2)}% | ||
</h1> | ||
<div className="flex justify-center items-center z-20 h-screen w-screen flex-col bg-slate-950"> | ||
<img | ||
className="h-32 sm:h-64 w-32 sm:w-64" | ||
src="/icon512.png" | ||
alt="Earth Placeholder" | ||
/> | ||
<h1 className="text-white mt-2 sm:mt-4 text-xl sm:text-2xl"> | ||
LOADING... {progress.toFixed(2)}% | ||
</h1> | ||
</div> | ||
</Html> | ||
) | ||
} | ||
); | ||
} |
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