"use client"; import type { OrbitControls as OrbitControlsImpl } from 'three-stdlib'; import { Canvas } from "@react-three/fiber"; import { useGLTF, useAnimations, Environment, Loader, OrbitControls, Bounds } from "@react-three/drei"; 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, onNodesLoaded }: { url: string; onAnimationsLoaded: (animations: string[], actions: Record) => void; onNodesLoaded: (nodes: string[], nodePositions: Record) => void; }) { const { scene, animations } = useGLTF(url); const { actions } = useAnimations(animations, scene); useEffect(() => { if (actions) { onAnimationsLoaded(animations.map(anim => anim.name), actions); } if (scene.children) { const nodeList = scene.children.map(node => node.name); const nodePositions = scene.children.reduce((acc, node) => { acc[node.name] = [node.position.x, node.position.y, node.position.z]; return acc; }, {} as Record); onNodesLoaded(nodeList, nodePositions); } }, [actions, animations, onAnimationsLoaded, onNodesLoaded]); return ( {/* find the object in the perfect angle */} ); } 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 [_, setNodes] = useState([]); const [nodePositions, setNodePositions] = useState>({}); const [isFullscreen, setIsFullscreen] = useState(false); const navigate = useNavigate(); nodePositions; 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); } }; // Handle Fullscreen Mode const toggleFullscreen = () => { if (!document.fullscreenElement) { containerRef.current?.requestFullscreen().then(() => { setIsFullscreen(true); }).catch(err => { console.error("Error entering fullscreen:", err); }); } else { document.exitFullscreen().then(() => { setIsFullscreen(false); }).catch(err => { console.error("Error exiting fullscreen:", err); }); } }; return (
Animaciones
{animations.length > 0 ? ( animations.map((anim) => ( )) ) : (

Este modelo no tiene animaciones.

)}
}> { setAnimations(animNames); setActions(actionMap); }} onNodesLoaded={(nodeList, nodePos) => { setNodes(nodeList); setNodePositions(nodePos); }} />
); }