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;
|
align-items: center;
|
||||||
padding: 18px 28px;
|
padding: 18px 28px;
|
||||||
border-bottom: 1px solid rgba(31, 41, 38, 0.12);
|
border-bottom: 1px solid rgba(31, 41, 38, 0.12);
|
||||||
background: rgba(248, 251, 249, 0.86);
|
background: #f8fbf9;
|
||||||
backdrop-filter: blur(18px);
|
box-shadow: 0 10px 24px rgba(15, 23, 42, 0.04);
|
||||||
|
isolation: isolate;
|
||||||
}
|
}
|
||||||
|
|
||||||
.brand {
|
.brand {
|
||||||
@ -432,6 +433,7 @@ output {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.canvas-wrap {
|
.canvas-wrap {
|
||||||
|
position: relative;
|
||||||
min-height: 0;
|
min-height: 0;
|
||||||
flex: 1;
|
flex: 1;
|
||||||
background:
|
background:
|
||||||
@ -442,6 +444,16 @@ output {
|
|||||||
background-size: 34px 34px, 34px 34px, auto, auto;
|
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 {
|
.result-panel {
|
||||||
min-height: 640px;
|
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 { 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 { Mesh } from 'three'
|
||||||
import type { SimulationProfile, StoredTask } from '../lib/api'
|
import type { SimulationProfile, StoredTask } from '../lib/api'
|
||||||
import { getModelUrl } from '../lib/api'
|
import { getModelUrl } from '../lib/api'
|
||||||
@ -12,6 +12,30 @@ type Viewport3DProps = {
|
|||||||
labels: Messages['viewport']
|
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 }) {
|
function SoftBody({ simulation }: { simulation: SimulationProfile }) {
|
||||||
const meshRef = useRef<Mesh>(null)
|
const meshRef = useRef<Mesh>(null)
|
||||||
const distort = 0.14 + simulation.deformation / 220
|
const distort = 0.14 + simulation.deformation / 220
|
||||||
@ -80,15 +104,18 @@ export function Viewport3D({ task, simulation, labels }: Viewport3DProps) {
|
|||||||
) : null}
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
<div className="canvas-wrap">
|
<div className="canvas-wrap">
|
||||||
<Canvas camera={{ position: [3.7, 2.5, 4.2], fov: 42 }} gl={{ preserveDrawingBuffer: true, antialias: true }} shadows>
|
<CanvasErrorBoundary>
|
||||||
<ambientLight intensity={0.72} />
|
<Canvas camera={{ position: [3.7, 2.5, 4.2], fov: 42 }} gl={{ preserveDrawingBuffer: true, antialias: true }} shadows>
|
||||||
<directionalLight position={[4, 5, 3]} intensity={2.1} castShadow />
|
<ambientLight intensity={1} />
|
||||||
<SoftBody simulation={simulation} />
|
<hemisphereLight args={['#ffffff', '#9ca3af', 1.25]} />
|
||||||
<StageGrid />
|
<directionalLight position={[4, 5, 3]} intensity={2.4} castShadow />
|
||||||
<ContactShadows position={[0, -1.08, 0]} opacity={0.28} scale={5} blur={2.4} far={3} />
|
<pointLight position={[-3, 2.2, -2]} intensity={0.65} color="#5eead4" />
|
||||||
<Environment preset="studio" />
|
<SoftBody simulation={simulation} />
|
||||||
<OrbitControls enablePan={false} minDistance={3.4} maxDistance={8} />
|
<StageGrid />
|
||||||
</Canvas>
|
<ContactShadows position={[0, -1.08, 0]} opacity={0.28} scale={5} blur={2.4} far={3} />
|
||||||
|
<OrbitControls enablePan={false} minDistance={3.4} maxDistance={8} />
|
||||||
|
</Canvas>
|
||||||
|
</CanvasErrorBoundary>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user