01import { Canvas } from "@react-three/fiber"
02import { PerspectiveCamera } from "@react-three/drei"
03import { useEffect, useRef } from "react"
04import gsap from "gsap"
05import * as THREE from "three"
06
07const geometry = new THREE.BoxGeometry(1, 1, 1)
08const material = new THREE.MeshStandardMaterial({ color: "#67a7ff" })
09
10export default function Example() {
11 const groupRef = useRef<THREE.Group>(null)
12 const meshRef = useRef<THREE.Mesh>(null)
13 const lightRef = useRef<THREE.DirectionalLight>(null)
14
15 useEffect(() => {
16 if (!groupRef.current || !meshRef.current || !lightRef.current) return
17 groupRef.current.position.y = -1
18 groupRef.current.rotation.set(0.95, -0.75, 0)
19 meshRef.current.scale.setScalar(0.72)
20 lightRef.current.position.set(3, 1.5, 2.2)
21 lightRef.current.intensity = 0.45
22
23 const timeline = gsap.timeline({ repeat: -1, repeatDelay: 0.8 })
24 timeline.to(groupRef.current.position, { y: 0.15, duration: 1.15, ease: 'power3.out' }, 0)
25 timeline.to(groupRef.current.rotation, { x: 0.18, y: 0.35, duration: 1.15, ease: 'power3.out' }, 0)
26 timeline.to(meshRef.current.scale, { x: 1, y: 1, z: 1, duration: 1.05, ease: 'back.out(1.7)' }, 0.05)
27 timeline.to(lightRef.current.position, { x: -1.6, y: 2.4, z: 3.1, duration: 1.1, ease: 'power2.out' }, 0)
28 timeline.to(lightRef.current, { intensity: 1.8, duration: 0.9, ease: 'power2.out' }, 0)
29 timeline.to(groupRef.current.rotation, { y: 0.52, duration: 1, ease: 'sine.inOut' }, 1.2)
30 timeline.to(lightRef.current.position, { x: -0.4, duration: 1, ease: 'sine.inOut' }, 1.2)
31
32 return () => timeline.kill()
33 }, [])
34
35 return (
36 <Canvas>
37 <PerspectiveCamera
38 makeDefault
39 position={[0, 0.2, 4.9]}
40 fov={32}
41 onUpdate={(camera) => camera.lookAt(0, 0.1, 0)}
42 />
43 <ambientLight intensity={0.45} />
44 <directionalLight ref={lightRef} position={[2, 2, 3]} intensity={1.2} />
45 <group ref={groupRef}>
46 <mesh ref={meshRef} geometry={geometry} material={material} />
47 </group>
48 </Canvas>
49 )
50}