fix(world): reallocate shadow map after Suspense + clear LaFabrik doorway
🔍 Lint / 🪄 Check lint (pull_request) Has been cancelled
🔍 Lint / 🎨 Check format (pull_request) Has been cancelled
🔍 Lint / 🔎 Typecheck (pull_request) Has been cancelled
📊 Quality / 🔒 Security Audit (pull_request) Has been cancelled
📊 Quality / 📋 Dependency Freshness (pull_request) Has been cancelled
📊 Quality / 📦 Bundle Size (pull_request) Has been cancelled
🔍 Lint / 🏗 Build (pull_request) Has been cancelled

Shadows occasionally failed to render on initial load and the Fabrik
doorway sometimes blocked the player. Both issues are tracked down to
geometry that mounts after Lighting:

- Shadows: GLTFs and the merged static map mount imperatively after
  Lighting, so materials get compiled against a renderer state that
  pre-dates the final scene and bake a 'no shadow map' permutation,
  silently dropping shadows. A WebGL context-restore cycle fixes it,
  but is too invasive. New 'useShadowMapWarmup' hook replays it
  cheaply: once the scene mesh count has been stable for ~1s, it
  disposes the directional shadow map (three.js reallocates it on
  the next render) and marks every material 'needsUpdate' so shaders
  rebind to the freshly created shadow sampler.
- Doorway: the door slab + its Solidify-modifier frame (children of
  the 'Thicken' parent in the LaFabrik GLTF) sat inside the doorway
  AABB and prevented the player from walking through. Stripped from
  the collision octree alongside the existing 'porte' slab; visual
  rendering is unaffected.

Also: extract sun-relative-to-camera placement into a small helper,
remove the temporary diagnostic logs, and document the shadow warmup
in three-debugging.md.
This commit is contained in:
Tom Boullay
2026-06-01 23:37:57 +02:00
parent b144dc1c18
commit 134c0aecb7
5 changed files with 178 additions and 190 deletions
+1 -30
View File
@@ -1,29 +1,9 @@
import { useEffect, useRef } from "react";
import type { RefObject } from "react";
import { Mesh, type Object3D } from "three";
import { type Object3D } from "three";
import { Octree } from "three-stdlib";
import type { OctreeReadyHandler } from "@/types/three/three";
// [diag] temporary — count meshes/triangles captured in the octree graph node
function snapshotGraphNode(node: Object3D): {
meshCount: number;
triCount: number;
} {
let meshCount = 0;
let triCount = 0;
node.traverse((obj) => {
if (obj instanceof Mesh) {
meshCount += 1;
const geom = obj.geometry;
const idx = geom.index;
triCount += idx
? idx.count / 3
: (geom.attributes.position?.count ?? 0) / 3;
}
});
return { meshCount, triCount };
}
export function useOctreeGraphNode(
graphNodeRef: RefObject<Object3D | null>,
onOctreeReady: OctreeReadyHandler,
@@ -48,15 +28,6 @@ export function useOctreeGraphNode(
const octree = new Octree();
octree.fromGraphNode(graphNode);
// [diag] temporary — log octree contents to detect partial builds
const snapshot = snapshotGraphNode(graphNode);
console.log("[octree:build]", {
rebuildKey,
meshCount: snapshot.meshCount,
triCount: Math.round(snapshot.triCount),
timestamp: performance.now().toFixed(0),
});
onOctreeReady(octree);
}, [enabled, graphNodeRef, onOctreeReady, rebuildKey]);
}