-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: remove StarsCanvas component and replace with Stars component f…
…or improved performance
- Loading branch information
Showing
3 changed files
with
48 additions
and
8 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 was deleted.
Oops, something went wrong.
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,47 @@ | ||
import { Suspense, useRef, useState } from 'react'; | ||
|
||
import { PointMaterial, Points, Preload } from '@react-three/drei'; | ||
import { Canvas, useFrame } from '@react-three/fiber'; | ||
import * as random from 'maath/random'; | ||
|
||
const Stars = (props) => { | ||
const ref = useRef(); | ||
const [sphere] = useState(() => | ||
random.inSphere(new Float32Array(5000), { radius: 1.2 }) | ||
); | ||
|
||
useFrame((state, delta) => { | ||
ref.current.rotation.x -= delta / 10; | ||
ref.current.rotation.y -= delta / 15; | ||
}); | ||
|
||
return ( | ||
<group rotation={[0, 0, Math.PI / 4]}> | ||
<Points ref={ref} positions={sphere} stride={3} frustumCulled {...props}> | ||
<PointMaterial | ||
transparent | ||
color="#f272c8" | ||
size={0.002} | ||
sizeAttenuation={true} | ||
depthWrite={false} | ||
/> | ||
</Points> | ||
</group> | ||
); | ||
}; | ||
|
||
const StarsCanvas = () => { | ||
return ( | ||
<div className="w-full h-auto absolute inset-0 z-[-1]"> | ||
<Canvas camera={{ position: [0, 0, 1] }}> | ||
<Suspense fallback={null}> | ||
<Stars /> | ||
</Suspense> | ||
|
||
<Preload all /> | ||
</Canvas> | ||
</div> | ||
); | ||
}; | ||
|
||
export default StarsCanvas; |