updated the dungeon loading so it doesnt fail first try

This commit is contained in:
phenom
2026-08-17 13:51:12 -04:00
parent e39aebf3a1
commit 7e60864e70
11 changed files with 383 additions and 69 deletions
+47 -14
View File
@@ -1,7 +1,7 @@
import { Html } from "@react-three/drei";
import { useFrame } from "@react-three/fiber";
import { Suspense, useEffect, useMemo, useRef, useState } from "react";
import type { CSSProperties, ReactNode } from "react";
import { Component, Suspense, useEffect, useMemo, useRef, useState } from "react";
import type { CSSProperties, ErrorInfo, ReactNode } from "react";
import {
AdditiveBlending,
AnimationMixer,
@@ -138,6 +138,37 @@ interface ProxyMobProps {
readonly useOriginalModels: boolean;
}
interface CreatureModelErrorBoundaryProps {
readonly children: ReactNode;
readonly fallback: ReactNode;
readonly resetKey: string;
}
class CreatureModelErrorBoundary extends Component<
CreatureModelErrorBoundaryProps,
{ readonly failed: boolean }
> {
state = { failed: false };
static getDerivedStateFromError() {
return { failed: true };
}
componentDidCatch(error: Error, info: ErrorInfo): void {
console.warn("Creature model fell back to procedural rendering", error, info.componentStack);
}
componentDidUpdate(previous: Readonly<CreatureModelErrorBoundaryProps>): void {
if (previous.resetKey !== this.props.resetKey && this.state.failed) {
this.setState({ failed: false });
}
}
render(): ReactNode {
return this.state.failed ? this.props.fallback : this.props.children;
}
}
function prepareCreatureModel(root: Object3D): Object3D {
const cachedTemplate = preparedCreatureTemplates.get(root);
if (cachedTemplate) return cachedTemplate;
@@ -902,18 +933,20 @@ function ProxyMob({
forceFullFidelity={forceFullFidelity}
>
{model ? (
<Suspense fallback={proxyBody}>
<OriginalCreatureModel
model={model}
active={active}
proceduralAnimation={proceduralModelAnimation}
animationState={animationState}
attackRevision={attackRevision}
attackAnimation={attackAnimation}
woundRevision={woundRevision}
forceFullFidelity={forceFullFidelity}
/>
</Suspense>
<CreatureModelErrorBoundary fallback={proxyBody} resetKey={model.url}>
<Suspense fallback={proxyBody}>
<OriginalCreatureModel
model={model}
active={active}
proceduralAnimation={proceduralModelAnimation}
animationState={animationState}
attackRevision={attackRevision}
attackAnimation={attackAnimation}
woundRevision={woundRevision}
forceFullFidelity={forceFullFidelity}
/>
</Suspense>
</CreatureModelErrorBoundary>
) : (
proxyBody
)}