mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-29 20:34:28 +00:00
fix(webui): align 3D model viewer layout and full-width control bar with video viewer
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { Play, Pause, RotateCcw, Maximize, Minimize, Minus, Plus, Download } from 'lucide-react'
|
import { Play, Pause, RotateCcw, Maximize, Minimize, Minus, Plus, Download } from 'lucide-react'
|
||||||
|
import { cn } from '@/ui/lib/utils'
|
||||||
import { RulerSlider } from './ruler-slider'
|
import { RulerSlider } from './ruler-slider'
|
||||||
|
|
||||||
export interface ModelControlBarProps {
|
export interface ModelControlBarProps {
|
||||||
@@ -44,35 +45,45 @@ export const ModelControlBar: React.FC<ModelControlBarProps> = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="absolute inset-x-0 bottom-4 z-20 flex justify-center px-4 pointer-events-none">
|
<div
|
||||||
<div className="pointer-events-auto flex items-center gap-3 px-4 py-2 rounded-xl bg-card/90 backdrop-blur-md border border-border/80 shadow-xl w-full max-w-4xl text-foreground">
|
className={cn(
|
||||||
{/* Play/Pause & Degree Readout */}
|
'transition-all duration-300 ease-in-out z-20 text-foreground',
|
||||||
<div className="flex items-center gap-3 shrink-0">
|
isFullScreen
|
||||||
|
? 'absolute bottom-0 left-0 right-0 px-4 py-3 bg-card/90 backdrop-blur-md border-t border-border'
|
||||||
|
: 'relative w-full bg-card border-t border-border px-4 py-3 z-10 transition-colors duration-200',
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{/* Top: Ruler Slider across full width */}
|
||||||
|
<div className="mb-3 px-1">
|
||||||
|
<RulerSlider currentDegree={currentDegree} onChange={onSeekDegree} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Bottom: Lower Controls Row */}
|
||||||
|
<div className="flex items-center justify-between text-foreground">
|
||||||
|
{/* Left Side: Play/Pause, Degree Readout, Reset Rotation */}
|
||||||
|
<div className="flex items-center gap-4">
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={togglePlay}
|
onClick={togglePlay}
|
||||||
aria-label={isPlaying ? 'Pause' : 'Play'}
|
aria-label={isPlaying ? 'Pause' : 'Play'}
|
||||||
className="flex items-center justify-center w-8 h-8 rounded-lg bg-primary text-primary-foreground hover:bg-primary/90 transition-colors shadow-xs"
|
className="hover:text-primary transition-colors"
|
||||||
|
data-testid="play-toggle"
|
||||||
|
data-playing={isPlaying}
|
||||||
>
|
>
|
||||||
{isPlaying ? <Pause className="w-4 h-4" /> : <Play className="w-4 h-4 ml-0.5" />}
|
{isPlaying ? (
|
||||||
|
<Pause className="w-6 h-6 fill-current" />
|
||||||
|
) : (
|
||||||
|
<Play className="w-6 h-6 fill-current" />
|
||||||
|
)}
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
className="text-xs font-mono font-medium tabular-nums min-w-[76px]"
|
className="flex items-center gap-1 text-sm font-medium tabular-nums select-none min-w-[90px]"
|
||||||
data-testid="degree-readout"
|
data-testid="degree-readout"
|
||||||
>
|
>
|
||||||
{currentDegree}° / 360°
|
<span className="text-muted-foreground font-mono">{currentDegree}° / 360°</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Ruler Slider */}
|
|
||||||
<div className="flex-1 min-w-[200px]">
|
|
||||||
<RulerSlider currentDegree={currentDegree} onChange={onSeekDegree} />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Right Action Tools */}
|
|
||||||
<div className="flex items-center gap-2 shrink-0">
|
|
||||||
{/* Reset rotation to 0° */}
|
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={onResetRotation}
|
onClick={onResetRotation}
|
||||||
@@ -82,9 +93,12 @@ export const ModelControlBar: React.FC<ModelControlBarProps> = ({
|
|||||||
>
|
>
|
||||||
<RotateCcw className="w-4 h-4" />
|
<RotateCcw className="w-4 h-4" />
|
||||||
</button>
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Right Side: Zoom controls, Download, Fullscreen */}
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
{/* Zoom controls */}
|
{/* Zoom controls */}
|
||||||
<div className="hidden sm:flex items-center gap-1 bg-muted/60 rounded-lg p-0.5 border border-border/40">
|
<div className="flex items-center gap-1 bg-muted/60 rounded-lg p-0.5 border border-border/40">
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => onZoomChange(Math.max(0.2, zoom - 0.2))}
|
onClick={() => onZoomChange(Math.max(0.2, zoom - 0.2))}
|
||||||
|
|||||||
@@ -160,4 +160,15 @@ describe('ModelViewer', () => {
|
|||||||
fireEvent.click(resetBtn)
|
fireEvent.click(resetBtn)
|
||||||
expect(onTimeUpdate).toHaveBeenCalledWith(0)
|
expect(onTimeUpdate).toHaveBeenCalledWith(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('renders children alongside viewer surface when provided', () => {
|
||||||
|
const { getByTestId } = render(
|
||||||
|
<ModelViewer file={mockAsset}>
|
||||||
|
<div data-testid="test-sidebar">Sidebar</div>
|
||||||
|
</ModelViewer>,
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(getByTestId('test-sidebar')).toBeDefined()
|
||||||
|
expect(getByTestId('model-viewer-surface')).toBeDefined()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ export const ModelViewer = React.forwardRef<MediaController, FileViewerProps>(
|
|||||||
},
|
},
|
||||||
ref,
|
ref,
|
||||||
) => {
|
) => {
|
||||||
|
const rootRef = useRef<HTMLDivElement | null>(null)
|
||||||
const videoRef = useRef<HTMLVideoElement | null>(null)
|
const videoRef = useRef<HTMLVideoElement | null>(null)
|
||||||
const containerRef = useRef<HTMLDivElement | null>(null)
|
const containerRef = useRef<HTMLDivElement | null>(null)
|
||||||
const [containerSize, setContainerSize] = useState({ width: 0, height: 0 })
|
const [containerSize, setContainerSize] = useState({ width: 0, height: 0 })
|
||||||
@@ -214,8 +215,9 @@ export const ModelViewer = React.forwardRef<MediaController, FileViewerProps>(
|
|||||||
|
|
||||||
// Fullscreen toggle
|
// Fullscreen toggle
|
||||||
const toggleFullScreen = () => {
|
const toggleFullScreen = () => {
|
||||||
|
if (!rootRef.current) return
|
||||||
if (!document.fullscreenElement) {
|
if (!document.fullscreenElement) {
|
||||||
containerRef.current?.requestFullscreen().catch(() => {})
|
rootRef.current.requestFullscreen().catch(() => {})
|
||||||
} else {
|
} else {
|
||||||
document.exitFullscreen().catch(() => {})
|
document.exitFullscreen().catch(() => {})
|
||||||
}
|
}
|
||||||
@@ -255,116 +257,125 @@ export const ModelViewer = React.forwardRef<MediaController, FileViewerProps>(
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
ref={containerRef}
|
ref={rootRef}
|
||||||
data-testid="model-viewer-container"
|
data-testid="model-viewer-container"
|
||||||
className="relative w-full h-full bg-background overflow-hidden select-none flex items-center justify-center"
|
className={cn(
|
||||||
|
'group shadow-2xl font-sans select-none flex flex-col mx-auto relative',
|
||||||
|
isFullScreen ? 'h-full w-full rounded-none bg-black' : 'w-full h-full',
|
||||||
|
)}
|
||||||
>
|
>
|
||||||
{/* Interactive Drag Rotation Surface */}
|
<div className="flex-1 flex flex-col-reverse md:flex-row min-h-0 relative">
|
||||||
<div
|
{/* Render Carousel/Sidebar here if not fullscreen */}
|
||||||
data-testid="model-viewer-surface"
|
{!isFullScreen && children}
|
||||||
onPointerDown={handleViewerPointerDown}
|
|
||||||
onPointerMove={handleViewerPointerMove}
|
|
||||||
onPointerUp={handleViewerPointerUp}
|
|
||||||
onPointerCancel={handleViewerPointerUp}
|
|
||||||
className={cn(
|
|
||||||
'absolute inset-0 z-0 touch-none',
|
|
||||||
isDrawingMode
|
|
||||||
? 'cursor-crosshair'
|
|
||||||
: isDraggingRotation
|
|
||||||
? 'cursor-grabbing'
|
|
||||||
: 'cursor-grab',
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
{/* Centered Scaled Media Wrapper */}
|
|
||||||
<div
|
|
||||||
className="absolute pointer-events-none"
|
|
||||||
style={{
|
|
||||||
left: 0,
|
|
||||||
top: 0,
|
|
||||||
width: mediaWidth,
|
|
||||||
height: mediaHeight,
|
|
||||||
transform: `translate(${pan.x}px, ${pan.y}px) scale(${zoom})`,
|
|
||||||
transformOrigin: '0 0',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{videoSrc && (
|
|
||||||
<video
|
|
||||||
ref={videoRef}
|
|
||||||
src={videoSrc}
|
|
||||||
poster={posterUrl}
|
|
||||||
playsInline
|
|
||||||
loop
|
|
||||||
muted
|
|
||||||
autoPlay={autoPlay}
|
|
||||||
preload="auto"
|
|
||||||
onLoadedData={() => {
|
|
||||||
setIsLoading(false)
|
|
||||||
if (startTime && startTime > 0) {
|
|
||||||
seekToFrame(Math.floor(startTime * FPS))
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
onPlay={() => {
|
|
||||||
setIsPlaying(true)
|
|
||||||
onPlay?.()
|
|
||||||
}}
|
|
||||||
onPause={() => {
|
|
||||||
setIsPlaying(false)
|
|
||||||
onPause?.()
|
|
||||||
}}
|
|
||||||
onTimeUpdate={() => {
|
|
||||||
if (videoRef.current && !isDraggingRotation) {
|
|
||||||
setCurrentTime(videoRef.current.currentTime)
|
|
||||||
onTimeUpdate?.(videoRef.current.currentTime)
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
onError={() => {
|
|
||||||
setIsLoading(false)
|
|
||||||
setError('Failed to load turntable video')
|
|
||||||
}}
|
|
||||||
className="w-full h-full block object-contain pointer-events-none"
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Drawing Canvas Overlay */}
|
{/* Interactive Drag Rotation Surface & Model Area */}
|
||||||
{containerSize.width > 0 && containerSize.height > 0 && (
|
<div
|
||||||
<DrawingCanvas
|
ref={containerRef}
|
||||||
width={containerSize.width}
|
data-testid="model-viewer-surface"
|
||||||
height={containerSize.height}
|
onPointerDown={handleViewerPointerDown}
|
||||||
mediaDimensions={{
|
onPointerMove={handleViewerPointerMove}
|
||||||
|
onPointerUp={handleViewerPointerUp}
|
||||||
|
onPointerCancel={handleViewerPointerUp}
|
||||||
|
className={cn(
|
||||||
|
'flex-1 bg-black relative flex items-center justify-center overflow-hidden min-h-0 touch-none',
|
||||||
|
isDrawingMode
|
||||||
|
? 'cursor-crosshair'
|
||||||
|
: isDraggingRotation
|
||||||
|
? 'cursor-grabbing'
|
||||||
|
: 'cursor-grab',
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{/* Centered Scaled Media Wrapper */}
|
||||||
|
<div
|
||||||
|
className="absolute pointer-events-none"
|
||||||
|
style={{
|
||||||
|
left: 0,
|
||||||
|
top: 0,
|
||||||
width: mediaWidth,
|
width: mediaWidth,
|
||||||
height: mediaHeight,
|
height: mediaHeight,
|
||||||
|
transform: `translate(${pan.x}px, ${pan.y}px) scale(${zoom})`,
|
||||||
|
transformOrigin: '0 0',
|
||||||
}}
|
}}
|
||||||
annotations={displayAnnotations}
|
>
|
||||||
scale={zoom}
|
{videoSrc && (
|
||||||
offset={pan}
|
<video
|
||||||
className="absolute inset-0 pointer-events-none"
|
ref={videoRef}
|
||||||
isDrawing={isDrawing}
|
src={videoSrc}
|
||||||
currentTool={currentTool}
|
poster={posterUrl}
|
||||||
currentColor={currentColor}
|
playsInline
|
||||||
onAddAnnotation={addAnnotation}
|
loop
|
||||||
/>
|
muted
|
||||||
)}
|
autoPlay={autoPlay}
|
||||||
|
preload="auto"
|
||||||
|
onLoadedData={() => {
|
||||||
|
setIsLoading(false)
|
||||||
|
if (startTime && startTime > 0) {
|
||||||
|
seekToFrame(Math.floor(startTime * FPS))
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
onPlay={() => {
|
||||||
|
setIsPlaying(true)
|
||||||
|
onPlay?.()
|
||||||
|
}}
|
||||||
|
onPause={() => {
|
||||||
|
setIsPlaying(false)
|
||||||
|
onPause?.()
|
||||||
|
}}
|
||||||
|
onTimeUpdate={() => {
|
||||||
|
if (videoRef.current && !isDraggingRotation) {
|
||||||
|
setCurrentTime(videoRef.current.currentTime)
|
||||||
|
onTimeUpdate?.(videoRef.current.currentTime)
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
onError={() => {
|
||||||
|
setIsLoading(false)
|
||||||
|
setError('Failed to load turntable video')
|
||||||
|
}}
|
||||||
|
className="w-full h-full block object-contain pointer-events-none"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Drawing Canvas Overlay */}
|
||||||
|
{containerSize.width > 0 && containerSize.height > 0 && (
|
||||||
|
<DrawingCanvas
|
||||||
|
width={containerSize.width}
|
||||||
|
height={containerSize.height}
|
||||||
|
mediaDimensions={{
|
||||||
|
width: mediaWidth,
|
||||||
|
height: mediaHeight,
|
||||||
|
}}
|
||||||
|
annotations={displayAnnotations}
|
||||||
|
scale={zoom}
|
||||||
|
offset={pan}
|
||||||
|
className="absolute inset-0 pointer-events-none"
|
||||||
|
isDrawing={isDrawing}
|
||||||
|
currentTool={currentTool}
|
||||||
|
currentColor={currentColor}
|
||||||
|
onAddAnnotation={addAnnotation}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Loading Spinner */}
|
||||||
|
{isLoading && !error && (
|
||||||
|
<div className="absolute inset-0 flex items-center justify-center bg-black/20 pointer-events-none z-10">
|
||||||
|
<div className="w-14 h-14 bg-background/80 backdrop-blur-md rounded-full flex items-center justify-center border border-border shadow-lg">
|
||||||
|
<Loader2 className="w-7 h-7 text-primary animate-spin" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Error Display */}
|
||||||
|
{error && (
|
||||||
|
<div className="absolute inset-0 flex flex-col items-center justify-center gap-2 text-destructive z-10 bg-background/90 p-4 text-center">
|
||||||
|
<AlertCircle className="w-10 h-10" />
|
||||||
|
<p className="text-sm font-medium">{error}</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Loading Spinner */}
|
{/* Full-width docked bottom control bar */}
|
||||||
{isLoading && !error && (
|
|
||||||
<div className="absolute inset-0 flex items-center justify-center bg-black/20 pointer-events-none z-10">
|
|
||||||
<div className="w-14 h-14 bg-background/80 backdrop-blur-md rounded-full flex items-center justify-center border border-border shadow-lg">
|
|
||||||
<Loader2 className="w-7 h-7 text-primary animate-spin" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Error Display */}
|
|
||||||
{error && (
|
|
||||||
<div className="absolute inset-0 flex flex-col items-center justify-center gap-2 text-destructive z-10 bg-background/90 p-4 text-center">
|
|
||||||
<AlertCircle className="w-10 h-10" />
|
|
||||||
<p className="text-sm font-medium">{error}</p>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Floating Bottom Control Bar */}
|
|
||||||
<ModelControlBar
|
<ModelControlBar
|
||||||
isPlaying={isPlaying}
|
isPlaying={isPlaying}
|
||||||
currentDegree={currentDegree}
|
currentDegree={currentDegree}
|
||||||
@@ -380,8 +391,6 @@ export const ModelViewer = React.forwardRef<MediaController, FileViewerProps>(
|
|||||||
onZoomReset={handleZoomReset}
|
onZoomReset={handleZoomReset}
|
||||||
toggleFullScreen={toggleFullScreen}
|
toggleFullScreen={toggleFullScreen}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{children}
|
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user