Update TestMap.tsx
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import { useRef } from "react";
|
import type { ReactNode } from "react";
|
||||||
|
import { Component, useRef } from "react";
|
||||||
import * as THREE from "three";
|
import * as THREE from "three";
|
||||||
import { Physics, RigidBody, CuboidCollider } from "@react-three/rapier";
|
import { Physics, RigidBody, CuboidCollider } from "@react-three/rapier";
|
||||||
import { RepairGameZone } from "@/components/three/gameplay/RepairGameZone";
|
import { RepairGameZone } from "@/components/three/gameplay/RepairGameZone";
|
||||||
@@ -29,6 +30,40 @@ interface TestMapProps {
|
|||||||
onOctreeReady: OctreeReadyHandler;
|
onOctreeReady: OctreeReadyHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface ModelPreviewErrorBoundaryProps {
|
||||||
|
children: ReactNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ModelPreviewErrorBoundaryState {
|
||||||
|
hasError: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
class ModelPreviewErrorBoundary extends Component<
|
||||||
|
ModelPreviewErrorBoundaryProps,
|
||||||
|
ModelPreviewErrorBoundaryState
|
||||||
|
> {
|
||||||
|
constructor(props: ModelPreviewErrorBoundaryProps) {
|
||||||
|
super(props);
|
||||||
|
this.state = { hasError: false };
|
||||||
|
}
|
||||||
|
|
||||||
|
static getDerivedStateFromError(): ModelPreviewErrorBoundaryState {
|
||||||
|
return { hasError: true };
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidCatch(error: Error): void {
|
||||||
|
console.warn("Failed to load debug animated model preview", error);
|
||||||
|
}
|
||||||
|
|
||||||
|
render(): ReactNode {
|
||||||
|
if (this.state.hasError) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.props.children;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function TestMap({ onOctreeReady }: TestMapProps): React.JSX.Element {
|
export function TestMap({ onOctreeReady }: TestMapProps): React.JSX.Element {
|
||||||
const floorRef = useRef<THREE.Group>(null);
|
const floorRef = useRef<THREE.Group>(null);
|
||||||
|
|
||||||
@@ -89,12 +124,14 @@ export function TestMap({ onOctreeReady }: TestMapProps): React.JSX.Element {
|
|||||||
<RepairGameZone />
|
<RepairGameZone />
|
||||||
</Physics>
|
</Physics>
|
||||||
|
|
||||||
<AnimatedModel
|
<ModelPreviewErrorBoundary>
|
||||||
modelPath="/models/elec/model.gltf"
|
<AnimatedModel
|
||||||
defaultAnimation="Idle"
|
modelPath="/models/elec/model.gltf"
|
||||||
position={[0, 0, -5]}
|
defaultAnimation="Idle"
|
||||||
scale={1}
|
position={[0, 0, -5]}
|
||||||
/>
|
scale={1}
|
||||||
|
/>
|
||||||
|
</ModelPreviewErrorBoundary>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user