From 6b091807436c29a6a6dfeefbbad90e1a6eab266f Mon Sep 17 00:00:00 2001 From: Timothy Pidashev Date: Fri, 22 Mar 2024 00:38:21 -0700 Subject: [PATCH] hero section work --- src/web/src/app/page.jsx | 4 +- src/web/src/components/hero.jsx | 67 ----------------------- src/web/src/components/hero/index.jsx | 46 ++++++++++++++++ src/web/src/components/hero/objects.jsx | 0 src/web/src/components/hero/particles.jsx | 28 ++++++++++ src/web/src/components/hero/sections.jsx | 19 +++++++ src/web/src/style/globals.css | 5 +- 7 files changed, 97 insertions(+), 72 deletions(-) delete mode 100644 src/web/src/components/hero.jsx create mode 100644 src/web/src/components/hero/index.jsx create mode 100644 src/web/src/components/hero/objects.jsx create mode 100644 src/web/src/components/hero/particles.jsx create mode 100644 src/web/src/components/hero/sections.jsx diff --git a/src/web/src/app/page.jsx b/src/web/src/app/page.jsx index a3aa4c2..ca09554 100644 --- a/src/web/src/app/page.jsx +++ b/src/web/src/app/page.jsx @@ -1,11 +1,11 @@ // Imports -import { HeroSection1, HeroSection2, HeroSection3 } from "@/components/hero"; +import Hero from "@/components/hero"; // Metadata // Exports export default function Index() { return ( - null + ); } diff --git a/src/web/src/components/hero.jsx b/src/web/src/components/hero.jsx deleted file mode 100644 index f5dbc2b..0000000 --- a/src/web/src/components/hero.jsx +++ /dev/null @@ -1,67 +0,0 @@ -"use client" - -import { Suspense, useMemo } from "react"; -import { Canvas } from "@react-three/fiber"; -import { motion, AnimatePresence } from "framer-motion"; -import { useState, useEffect } from "react"; -import { OrbitControls } from "@react-three/drei"; -import Bird from "@/components/Bird"; - -function HeroSection1() { - const birds = useMemo( - () => - new Array(10).fill().map((_, index) => { - const x = - (15 + Math.random() * 30) * (Math.round(Math.random()) ? -1 : 1); - const y = -10 + Math.random() * 20; - const z = -5 + Math.random() * 10; - const bird = ["stork", "parrot", "flamingo"][ - Math.round(Math.random() * 2) - ]; - const speed = bird === "stork" ? 0.5 : bird === "flamingo" ? 2 : 5; - const factor = - bird === "stork" - ? 0.5 + Math.random() - : bird === "flamingo" - ? 0.25 + Math.random() - : 1 + Math.random() - 0.5; - - return { - key: index, - position: [x, y, z], - rotation: [0, x > 0 ? Math.PI : 0, 0], - speed, - factor, - url: `/glb/${bird}.glb`, - }; - }), - [], - ); - - return ( - - - - - - {birds.map((props) => ( - - ))} - - - ); -} - -function HeroSection2() { - -} - -function HeroSection3() { - -} - -export { - HeroSection1, - HeroSection2, - HeroSection3 -} diff --git a/src/web/src/components/hero/index.jsx b/src/web/src/components/hero/index.jsx new file mode 100644 index 0000000..7384191 --- /dev/null +++ b/src/web/src/components/hero/index.jsx @@ -0,0 +1,46 @@ +"use client" + +import React, { useRef } from 'react'; +import { Canvas, useFrame } from '@react-three/fiber'; +import { ScrollControls, Scroll } from '@react-three/drei'; +import * as THREE from 'three'; +import Particles from '@/components/hero/particles'; +import Sections from '@/components/hero/sections'; + +function Hero() { + const cameraRef = useRef(); + + return ( +
+ + + + + + + + + + + + +
+ ); +} + +function SceneUpdater({ cameraRef }) { + useFrame(({ pointer }) => { + const camera = cameraRef.current; + if (!camera) return; + + camera.position.x = THREE.MathUtils.lerp(camera.position.x, pointer.x * 0.5, 0.03); + camera.position.y = THREE.MathUtils.lerp(camera.position.y, pointer.y * 0.8, 0.01); + camera.position.z = THREE.MathUtils.lerp(camera.position.z, Math.max(4, Math.abs(pointer.x * pointer.y * 8)), 0.01); + camera.rotation.y = THREE.MathUtils.lerp(camera.rotation.y, pointer.x * -Math.PI * 0.025, 0.001); + }); + + return null; +} + +export default Hero; + diff --git a/src/web/src/components/hero/objects.jsx b/src/web/src/components/hero/objects.jsx new file mode 100644 index 0000000..e69de29 diff --git a/src/web/src/components/hero/particles.jsx b/src/web/src/components/hero/particles.jsx new file mode 100644 index 0000000..6c4549f --- /dev/null +++ b/src/web/src/components/hero/particles.jsx @@ -0,0 +1,28 @@ +import React from 'react' +import { Point, Points } from '@react-three/drei' +import { useThree } from '@react-three/fiber' + +const particleColors = ['#673ab7', '#f4b677', 'orange', 'blue', '#8bc34a', 'purple'] + +function Particles({ size = 5000 }) { + const { width, height } = useThree((state) => state.viewport) + + return ( + + + {Array.from({ length: size }).map((_, i) => ( + + ))} + + ) +} + +export default Particles diff --git a/src/web/src/components/hero/sections.jsx b/src/web/src/components/hero/sections.jsx new file mode 100644 index 0000000..0b2ca12 --- /dev/null +++ b/src/web/src/components/hero/sections.jsx @@ -0,0 +1,19 @@ +import React from 'react'; + +function Sections() { + return ( +
+
+

hello.

+
+
+

Your Future

+
+
+

Awaits

+
+
+ ); +} + +export default Sections; diff --git a/src/web/src/style/globals.css b/src/web/src/style/globals.css index 0bd33af..17440e9 100644 --- a/src/web/src/style/globals.css +++ b/src/web/src/style/globals.css @@ -41,7 +41,6 @@ body { } /* 3d goodies :D */ -canvas { - width: 100%; - height: 100vh; +canvas + div { + mix-blend-mode: multiply; }