Spaces:
Sleeping
Sleeping
File size: 6,540 Bytes
d325ede | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | /**
* ReconstructionStatus - Shows processing progress with animated 3D cube.
*/
import { useRef } from 'react';
import { Canvas, useFrame } from '@react-three/fiber';
import { motion } from 'framer-motion';
import * as THREE from 'three';
import { STEPS_CONFIG } from '../types';
import type { QueueStatus } from '../types';
interface ReconstructionStatusProps {
currentStep: string;
progress: number;
message: string;
error?: string | null;
queueStatus?: QueueStatus | null;
}
function RotatingCube() {
const meshRef = useRef<THREE.Mesh>(null);
useFrame((_, delta) => {
if (meshRef.current) {
meshRef.current.rotation.x += delta * 0.5;
meshRef.current.rotation.y += delta * 0.7;
}
});
return (
<mesh ref={meshRef}>
<boxGeometry args={[1.5, 1.5, 1.5]} />
<meshStandardMaterial
color="#6366f1"
emissive="#6366f1"
emissiveIntensity={0.3}
wireframe
/>
</mesh>
);
}
const steps = [
{ key: 'queued', ...STEPS_CONFIG.queued },
{ key: 'shape', ...STEPS_CONFIG.shape },
{ key: 'paint', ...STEPS_CONFIG.paint },
{ key: 'optimize', ...STEPS_CONFIG.optimize },
{ key: 'done', ...STEPS_CONFIG.done },
];
export default function ReconstructionStatus({
currentStep,
progress,
message,
error,
queueStatus,
}: ReconstructionStatusProps) {
const activeIndex = steps.findIndex((s) => s.key === currentStep);
const normalizedActiveIndex = activeIndex < 0 ? 0 : activeIndex;
const queueEta = queueStatus?.etaSeconds !== null && queueStatus?.etaSeconds !== undefined
? Math.max(1, Math.round(queueStatus.etaSeconds))
: null;
return (
<motion.div
initial={{ opacity: 0, scale: 0.95 }}
animate={{ opacity: 1, scale: 1 }}
className="glass-panel p-8 max-w-lg mx-auto"
>
<h2 className="text-2xl font-bold text-center mb-6 bg-gradient-to-r from-indigo-400 to-cyan-400 bg-clip-text text-transparent">
{error ? 'Generation Failed' : 'Generating Your 3D Asset'}
</h2>
{queueStatus?.stage === 'pending' && (
<motion.div
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
className="bg-cyan-500/10 border border-cyan-500/40 rounded-lg p-3 mb-5"
>
<p className="text-cyan-300 text-sm text-center font-medium">ZeroGPU Queue Status</p>
<p className="text-white/70 text-xs text-center mt-1">
{queueStatus.rank !== null ? `Position ${queueStatus.rank}` : 'Waiting for queue assignment'}
{queueStatus.queueSize !== null ? ` of ${queueStatus.queueSize}` : ''}
{queueEta !== null ? `, ETA ~${queueEta}s` : ''}
</p>
</motion.div>
)}
<div className="flex justify-center mb-8">
<div className="w-32 h-32">
<Canvas camera={{ position: [0, 0, 4], fov: 50 }}>
<ambientLight intensity={0.5} />
<pointLight position={[10, 10, 10]} intensity={1} color="#6366f1" />
<pointLight position={[-10, -10, -10]} intensity={0.5} color="#22d3ee" />
<RotatingCube />
</Canvas>
</div>
</div>
{error ? (
<motion.div
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
className="bg-red-500/20 border border-red-500/50 rounded-lg p-4 mb-4"
>
<p className="text-red-400 text-center">{error}</p>
<p className="text-white/60 text-sm text-center mt-2">
Tips: Try adding more images with overlapping views, ensure consistent lighting, avoid reflective surfaces.
</p>
</motion.div>
) : (
<>
<div className="mb-6">
<div className="flex justify-between text-sm text-white/60 mb-2">
<span>{message}</span>
<span>{progress}%</span>
</div>
<div className="h-2 bg-white/10 rounded-full overflow-hidden">
<motion.div
className="h-full bg-gradient-to-r from-indigo-500 to-cyan-400"
initial={{ width: 0 }}
animate={{ width: `${progress}%` }}
transition={{ duration: 0.5 }}
/>
</div>
</div>
<div className="space-y-2">
{steps.slice(0, -1).map((step, index) => {
const isActive = index === normalizedActiveIndex;
const isComplete = index < normalizedActiveIndex;
const isPending = index > normalizedActiveIndex;
return (
<motion.div
key={step.key}
className={`
flex items-center gap-3 p-3 rounded-lg
transition-colors duration-300
${isActive ? 'bg-indigo-500/20 border border-indigo-500/50' : ''}
${isComplete ? 'bg-green-500/10' : ''}
${isPending ? 'bg-white/5 opacity-50' : ''}
`}
initial={{ opacity: 0, x: -20 }}
animate={{ opacity: 1, x: 0 }}
transition={{ delay: index * 0.05 }}
>
<div className={`
w-8 h-8 rounded-full flex items-center justify-center
${isComplete ? 'bg-green-500' : isActive ? 'bg-indigo-500 animate-pulse' : 'bg-white/10'}
`}>
{isComplete ? (
<svg className="w-5 h-5 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M5 13l4 4L19 7" />
</svg>
) : isActive ? (
<svg className="w-5 h-5 text-white animate-spin" fill="none" viewBox="0 0 24 24">
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4" />
<path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z" />
</svg>
) : (
<span className="text-xs text-white/50">{index + 1}</span>
)}
</div>
<span className={`text-sm ${isActive ? 'text-white font-medium' : 'text-white/60'}`}>
{step.label}
</span>
</motion.div>
);
})}
</div>
</>
)}
</motion.div>
);
}
|