"use client"; import { OrbitControls as OrbitControlsImpl } from 'three-stdlib'; import { useGLTF, useAnimations, Environment, Loader, OrbitControls, Bounds } from "@react-three/drei"; import { Canvas } from "@react-three/fiber"; import { createXRStore, XR } from "@react-three/xr"; import { Suspense, useEffect, useRef, useState } from "react"; import { RotateCw, Play, Pause, Film, Shrink, Expand } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/popover"; import { ScrollArea } from "@/components/ui/scroll-area"; import { useNavigate } from 'react-router'; // Model component function Model({ url, onAnimationsLoaded, isAR }: { url: string; onAnimationsLoaded: (animations: string[], actions: Record) => void; isAR: boolean; }) { const { scene, animations } = useGLTF(url); const { actions } = useAnimations(animations, scene); useEffect(() => { if (actions) { onAnimationsLoaded(animations.map(anim => anim.name), actions); } if (isAR) { // 100 times smaller scene.scale.set(0.01, 0.01, 0.01); scene.position.set(0, 0, 0); } else { scene.scale.set(1, 1, 1); scene.position.set(0, 0, 0); } }, [actions, animations, onAnimationsLoaded, isAR]); return ( {/* find the object in the perfect angle */} ); } const store = createXRStore(); export default function Previewer({ modelUrl }: { modelUrl: string }) { const controlsRef = useRef(null); const containerRef = useRef(null); const [animations, setAnimations] = useState([]); const [actions, setActions] = useState>({}); const [currentAnimation, setCurrentAnimation] = useState(null); const [isAR, setIsAR] = useState(false); const navigate = useNavigate(); const playAnimation = (name: string) => { if (actions[name]) { Object.values(actions).forEach(action => action.stop()); // Stop other animations actions[name].play(); setCurrentAnimation(name); } }; const pauseAnimation = () => { if (currentAnimation && actions[currentAnimation]) { actions[currentAnimation].stop(); setCurrentAnimation(null); } }; return (
Animaciones
{animations.length > 0 ? ( animations.map((anim) => ( )) ) : (

Este modelo no tiene animaciones.

)}
}> { setAnimations(animNames); setActions(actionMap); }} isAR={isAR} />
); }