import { Suspense, useRef } from 'react'; import { Canvas, useFrame } from '@react-three/fiber'; import { Cylinder, Sphere, Float, OrbitControls, MeshDistortMaterial, Ring, Torus } from '@react-three/drei'; import { EffectComposer, Bloom, ChromaticAberration } from '@react-three/postprocessing'; import * as THREE from 'three'; interface SpeakerProps { isPlaying: boolean; position?: [number, number, number]; } function Speaker({ isPlaying, position = [0, 0, 0] }: SpeakerProps) { const meshRef = useRef(null); const coneRef = useRef(null); const waveRefs = useRef<(THREE.Mesh | null)[]>([]); const bassWaveRefs = useRef<(THREE.Mesh | null)[]>([]); useFrame((state) => { if (meshRef.current) { meshRef.current.rotation.y = Math.sin(state.clock.elapsedTime * 0.3) * 0.1; } if (coneRef.current && isPlaying) { const vibration = Math.sin(state.clock.elapsedTime * 8) * 0.1; coneRef.current.position.z = vibration; } // Enhanced sound waves animation waveRefs.current.forEach((wave, index) => { if (wave && isPlaying) { const time = state.clock.elapsedTime; const delay = index * 0.3; const scale = 1 + Math.sin(time * 4 + delay) * 0.4; const opacity = Math.max(0, Math.sin(time * 3 + delay)); wave.scale.setScalar(scale); (wave.material as THREE.MeshBasicMaterial).opacity = opacity * 0.5; } }); // Bass wave animation bassWaveRefs.current.forEach((wave, index) => { if (wave && isPlaying) { const time = state.clock.elapsedTime; const delay = index * 0.4; const scale = 1 + Math.sin(time * 2 + delay) * 0.6; const rotation = time * 0.5 + delay; wave.scale.setScalar(scale); wave.rotation.z = rotation; (wave.material as THREE.MeshBasicMaterial).opacity = Math.max(0, Math.sin(time * 2 + delay)) * 0.3; } }); }); return ( {/* Enhanced speaker cabinet */} {/* Enhanced speaker cone with distortion */} {/* Speaker grille with glow */} {/* Enhanced sound waves with rings */} {isPlaying && [1.5, 2.2, 3.0, 3.8].map((distance, index) => ( (waveRefs.current[index] = el)} args={[distance, distance + 0.2, 32]} position={[0, 0, 0]} rotation={[0, 0, 0]} > ))} {/* Bass visualization with torus rings */} {isPlaying && [0.8, 1.4, 2.0].map((size, index) => ( (bassWaveRefs.current[index] = el)} args={[size, 0.1, 16, 32]} position={[0, 0, 0]} > ))} {/* Bass port with glow */} {/* Floating sound particles */} {isPlaying && Array.from({ length: 12 }, (_, i) => { const angle = (i / 12) * Math.PI * 2; const radius = 2.5 + Math.sin(i) * 0.5; return ( ); })} ); } interface SpeakerSceneProps { isPlaying?: boolean; className?: string; } export default function SpeakerScene({ isPlaying = false, className = "" }: SpeakerSceneProps) { return (
{/* Enhanced post-processing effects */}
); }