import { Suspense, useRef, useState } from 'react'; import { Canvas, useFrame } from '@react-three/fiber'; import { Sphere, Box, Float, Text3D, OrbitControls, MeshDistortMaterial, Ring } from '@react-three/drei'; import { EffectComposer, Bloom, ChromaticAberration } from '@react-three/postprocessing'; import * as THREE from 'three'; interface MicrophoneProps { isRecording: boolean; position?: [number, number, number]; } function Microphone({ isRecording, position = [0, 0, 0] }: MicrophoneProps) { const meshRef = useRef(null); const sphereRef = useRef(null); const ringRefs = useRef<(THREE.Mesh | null)[]>([]); useFrame((state) => { if (meshRef.current) { meshRef.current.rotation.y = Math.sin(state.clock.elapsedTime * 0.5) * 0.1; } if (sphereRef.current && isRecording) { const scale = 1 + Math.sin(state.clock.elapsedTime * 4) * 0.2; sphereRef.current.scale.setScalar(scale); } // Animate recording rings ringRefs.current.forEach((ring, index) => { if (ring && isRecording) { const time = state.clock.elapsedTime; const delay = index * 0.3; const scale = 1 + Math.sin(time * 2 + delay) * 0.5; const opacity = Math.max(0, Math.sin(time * 1.5 + delay)); ring.scale.setScalar(scale); (ring.material as THREE.MeshBasicMaterial).opacity = opacity * 0.3; } }); }); return ( {/* Microphone body with enhanced materials */} {/* Enhanced microphone head with distortion effect */} {/* Enhanced base with glow */} {/* Multiple recording indicator rings with different sizes */} {isRecording && [0.8, 1.2, 1.6, 2.0].map((size, index) => ( (ringRefs.current[index] = el)} args={[size, size + 0.1, 32]} position={[0, 1, 0]} rotation={[Math.PI / 2, 0, 0]} > ))} {/* Floating energy particles around microphone when recording */} {isRecording && Array.from({ length: 8 }, (_, i) => { const angle = (i / 8) * Math.PI * 2; const radius = 2; return ( ); })} ); } interface MicrophoneSceneProps { isRecording?: boolean; className?: string; } export default function MicrophoneScene({ isRecording = false, className = "" }: MicrophoneSceneProps) { return (
{ try { gl.setPixelRatio(1); gl.domElement.addEventListener('webglcontextlost', (e) => (e as Event).preventDefault(), false); } catch {} }} > {/* Enhanced post-processing effects */} {isRecording && ( )}
); }