import React, { useRef, useMemo } from 'react'; import { useFrame } from '@react-three/fiber'; import * as THREE from 'three'; const Rain = ({ count = 1000 }) => { const meshRef = useRef(); const dummy = useMemo(() => new THREE.Object3D(), []); const particles = useMemo(() => { const temp = []; for (let i = 0; i < count; i++) { temp.push({ x: (Math.random() - 0.5) * 20, y: Math.random() * 20 + 10, z: (Math.random() - 0.5) * 20, speed: Math.random() * 0.1 + 0.05, }); } return temp; }, [count]); useFrame(() => { particles.forEach((particle, i) => { particle.y -= particle.speed; if (particle.y < -1) { particle.y = 20; } dummy.position.set(particle.x, particle.y, particle.z); dummy.updateMatrix(); meshRef.current.setMatrixAt(i, dummy.matrix); }); meshRef.current.instanceMatrix.needsUpdate = true; }); return ( ); }; export default Rain;