import { Canvas, useThree } from '@react-three/fiber'; import { OrbitControls, useGLTF, useAnimations } from '@react-three/drei'; import { useEffect, useState, useRef } from 'react'; function DuckModel({ onLoaded }: { onLoaded: () => void }) { const character = useGLTF('/duck3D/Character_output.glb'); const animations = useGLTF('/duck3D/Meshy_Merged_Animations.glb'); const meshRef = useRef(null); const { actions } = useAnimations(animations.animations, meshRef); useEffect(() => { onLoaded(); }, [character, animations, onLoaded]); useEffect(() => { if (!actions) return; const action = actions['Walking']; if (!action) return; action.reset(); action.setLoop(2201, Infinity); action.clampWhenFinished = false; action.fadeIn(0.4); action.play(); }, [actions]); return ; } function Camera() { const { camera } = useThree(); const controlsRef = useRef(null); useEffect(() => { if (controlsRef.current) { controlsRef.current.target.set(0.3, 3.29, -0.4); camera.position.set(2.89, 5.24, 7.38); controlsRef.current.update(); } }, [camera]); return ; } export function DuckAvatar() { const [isLoaded, setIsLoaded] = useState(false); return (
setIsLoaded(true)} />
); }