From 9dc5064ad871745ef9563dcb5ffd379114b30f96 Mon Sep 17 00:00:00 2001 From: eust-w Date: Wed, 3 Jun 2026 11:55:17 +0800 Subject: [PATCH] fix: stabilize 3d viewport rendering --- src/App.css | 16 ++++++++++-- src/components/Viewport3D.tsx | 49 +++++++++++++++++++++++++++-------- 2 files changed, 52 insertions(+), 13 deletions(-) diff --git a/src/App.css b/src/App.css index 92977fc..b394471 100644 --- a/src/App.css +++ b/src/App.css @@ -18,8 +18,9 @@ align-items: center; padding: 18px 28px; border-bottom: 1px solid rgba(31, 41, 38, 0.12); - background: rgba(248, 251, 249, 0.86); - backdrop-filter: blur(18px); + background: #f8fbf9; + box-shadow: 0 10px 24px rgba(15, 23, 42, 0.04); + isolation: isolate; } .brand { @@ -432,6 +433,7 @@ output { } .canvas-wrap { + position: relative; min-height: 0; flex: 1; background: @@ -442,6 +444,16 @@ output { background-size: 34px 34px, 34px 34px, auto, auto; } +.canvas-fallback { + display: grid; + width: 100%; + height: 100%; + min-height: 420px; + place-items: center; + color: #60706b; + font-size: 14px; +} + .result-panel { min-height: 640px; } diff --git a/src/components/Viewport3D.tsx b/src/components/Viewport3D.tsx index 5897e73..99f6c28 100644 --- a/src/components/Viewport3D.tsx +++ b/src/components/Viewport3D.tsx @@ -1,6 +1,6 @@ -import { Environment, Float, MeshDistortMaterial, OrbitControls, ContactShadows } from '@react-three/drei' +import { Float, MeshDistortMaterial, OrbitControls, ContactShadows } from '@react-three/drei' import { Canvas, useFrame } from '@react-three/fiber' -import { useRef } from 'react' +import { Component, useRef, type ErrorInfo, type ReactNode } from 'react' import type { Mesh } from 'three' import type { SimulationProfile, StoredTask } from '../lib/api' import { getModelUrl } from '../lib/api' @@ -12,6 +12,30 @@ type Viewport3DProps = { labels: Messages['viewport'] } +class CanvasErrorBoundary extends Component<{ children: ReactNode }, { failed: boolean }> { + state = { failed: false } + + static getDerivedStateFromError() { + return { failed: true } + } + + componentDidCatch(error: Error, info: ErrorInfo) { + console.error('3D viewport failed', error, info.componentStack) + } + + render() { + if (this.state.failed) { + return ( +
+ 3D preview unavailable +
+ ) + } + + return this.props.children + } +} + function SoftBody({ simulation }: { simulation: SimulationProfile }) { const meshRef = useRef(null) const distort = 0.14 + simulation.deformation / 220 @@ -80,15 +104,18 @@ export function Viewport3D({ task, simulation, labels }: Viewport3DProps) { ) : null}
- - - - - - - - - + + + + + + + + + + + +
)