import { Maximize2, RotateCcw, X } from 'lucide-react'; import { useCallback, useEffect, useRef, useState } from 'react'; import { PlatformActionButton } from '../../../../../packages/shared/src/components/PlatformActionButton'; import { PlatformIconButton } from '../../../../../packages/shared/src/components/PlatformIconButton'; import { ThemedModal } from '../../components/modal/ThemedModal'; import type { ProjectResourceCardPreviewState } from './resourceCardPreviewModel'; import { ResourceModelViewer, type ResourceModelViewerHandle, } from './ResourceModelViewer'; import type { ProjectResource } from './resourceProjectionModel'; /** * 引擎模型的**放大预览浮层**:在独立浮层里给出与 3D 建模软件一致的视角操作。 * * 卡片上仍然是静态缩略图(一张画布上十几张模型卡共用缩略图那一个 WebGL 上下文); * 只有打开这个浮层时才会新建一个交互式上下文,关闭即释放。浮层内的指针与滚轮事件由 * three 的 OrbitControls 独占:左键旋转、右键/中键平移、滚轮推拉。 */ export function ResourceModelPreviewDialog({ resource, identity, preview, onRequestPreview, onClose, }: { resource: ProjectResource; identity: string; preview: ProjectResourceCardPreviewState; onRequestPreview: ( resource: ProjectResource, identity: string, reason: 'detail', ) => void; onClose: () => void; }) { const [resetSignal, setResetSignal] = useState(0); const viewerHandleRef = useRef(null); useEffect(() => { onRequestPreview(resource, identity, 'detail'); }, [resource, identity, onRequestPreview]); const handleReady = useCallback((handle: ResourceModelViewerHandle) => { viewerHandleRef.current = handle; }, []); const sourceUrl = preview.status === 'loaded' ? (preview.preview.sourceUrl ?? null) : null; return (
{resource.label}
setResetSignal((current) => current + 1)} >
{preview.status === 'failed' ? ( <>

{preview.error}

{preview.retryable ? ( onRequestPreview(resource, identity, 'detail')} > 重试 ) : null} ) : preview.status === 'loaded' && !sourceUrl ? (

没有可预览的模型内容

) : sourceUrl ? ( ) : (

正在加载模型…

)}

); }