"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, useParams } from 'react-router'; 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) { scene.scale.set(0.01, 0.01, 0.01); scene.position.set(10, 0, 10); } else { scene.scale.set(1, 1, 1); scene.position.set(0, 0, 0); } }, [actions, animations, onAnimationsLoaded, isAR]); return ( ); } const store = createXRStore(); export default function Previewer() { const { modelId } = useParams<{ modelId: 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 [modelUrl, setModelUrl] = useState(null); const navigate = useNavigate(); console.log("ID del modelo:", modelId); useEffect(() => { fetch(`${import.meta.env.BASE_URL}models.json`) .then(res => res.json()) .then(data => { const model = data.find((m: { id: string }) => m.id === modelId); if (model) setModelUrl(model.url); }); }, [modelId]); const playAnimation = (name: string) => { if (actions[name]) { Object.values(actions).forEach(action => action.stop()); actions[name].play(); setCurrentAnimation(name); } }; const pauseAnimation = () => { if (currentAnimation && actions[currentAnimation]) { actions[currentAnimation].stop(); setCurrentAnimation(null); } }; if (!modelUrl) return
Cargando modelo...
; return (
Animaciones
{animations.length > 0 ? ( animations.map((anim) => ( )) ) : (

Este modelo no tiene animaciones.

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