chore(world): add temporary diagnostics for porte strip, octree, ctx loss

This commit is contained in:
Tom Boullay
2026-06-01 22:19:27 +02:00
parent a1798aecb3
commit f6db7d74e2
3 changed files with 61 additions and 1 deletions
+30 -1
View File
@@ -1,9 +1,29 @@
import { useEffect, useRef } from "react";
import type { RefObject } from "react";
import type { Object3D } from "three";
import { Mesh, 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,
@@ -28,6 +48,15 @@ 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]);
}