fix: stabilize 3d viewport rendering
This commit is contained in:
parent
a40cef7553
commit
9dc5064ad8
16
src/App.css
16
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;
|
||||
}
|
||||
|
||||
@ -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 (
|
||||
<div className="canvas-fallback" role="status">
|
||||
3D preview unavailable
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return this.props.children
|
||||
}
|
||||
}
|
||||
|
||||
function SoftBody({ simulation }: { simulation: SimulationProfile }) {
|
||||
const meshRef = useRef<Mesh>(null)
|
||||
const distort = 0.14 + simulation.deformation / 220
|
||||
@ -80,15 +104,18 @@ export function Viewport3D({ task, simulation, labels }: Viewport3DProps) {
|
||||
) : null}
|
||||
</div>
|
||||
<div className="canvas-wrap">
|
||||
<CanvasErrorBoundary>
|
||||
<Canvas camera={{ position: [3.7, 2.5, 4.2], fov: 42 }} gl={{ preserveDrawingBuffer: true, antialias: true }} shadows>
|
||||
<ambientLight intensity={0.72} />
|
||||
<directionalLight position={[4, 5, 3]} intensity={2.1} castShadow />
|
||||
<ambientLight intensity={1} />
|
||||
<hemisphereLight args={['#ffffff', '#9ca3af', 1.25]} />
|
||||
<directionalLight position={[4, 5, 3]} intensity={2.4} castShadow />
|
||||
<pointLight position={[-3, 2.2, -2]} intensity={0.65} color="#5eead4" />
|
||||
<SoftBody simulation={simulation} />
|
||||
<StageGrid />
|
||||
<ContactShadows position={[0, -1.08, 0]} opacity={0.28} scale={5} blur={2.4} far={3} />
|
||||
<Environment preset="studio" />
|
||||
<OrbitControls enablePan={false} minDistance={3.4} maxDistance={8} />
|
||||
</Canvas>
|
||||
</CanvasErrorBoundary>
|
||||
</div>
|
||||
</section>
|
||||
)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user