registry / systems / renderer

This commit is contained in:
wass08
2026-01-15 10:43:32 +09:00
parent 7a4d6e397d
commit 0c07c482a5
93 changed files with 440 additions and 75 deletions
@@ -0,0 +1,40 @@
import * as THREE from "three";
import { useLayoutEffect } from "react";
export const sceneRegistry = {
// Master lookup: ID -> Object3D
nodes: new Map<string, THREE.Object3D>(),
// Categorized lookups: Type -> Set of IDs
// Using a Set is faster for adding/deleting than an Array
byType: {
level: new Set<string>(),
wall: new Set<string>(),
item: new Set<string>(),
slab: new Set<string>(),
},
};
export function useRegistry(
id: string,
type: keyof typeof sceneRegistry.byType,
ref: React.RefObject<THREE.Object3D>
) {
useLayoutEffect(() => {
const obj = ref.current;
if (!obj) return;
// 1. Add to master map
sceneRegistry.nodes.set(id, obj);
// 2. Add to type-specific set
sceneRegistry.byType[type].add(id);
// 4. Cleanup when component unmounts
return () => {
sceneRegistry.nodes.delete(id);
sceneRegistry.byType[type].delete(id);
};
}, [id, type, ref]);
}