zone rendering

This commit is contained in:
wass08
2026-01-22 11:44:04 +09:00
parent 68e573f494
commit 36b7117173
4 changed files with 58 additions and 25 deletions
@@ -1,5 +1,5 @@
import { useLayoutEffect } from 'react'
import type * as THREE from 'three'
import { useLayoutEffect } from "react";
import type * as THREE from "three";
export const sceneRegistry = {
// Master lookup: ID -> Object3D
@@ -13,8 +13,9 @@ export const sceneRegistry = {
wall: new Set<string>(),
item: new Set<string>(),
slab: new Set<string>(),
zone: new Set<string>(),
},
}
};
export function useRegistry(
id: string,
@@ -22,19 +23,19 @@ export function useRegistry(
ref: React.RefObject<THREE.Object3D>,
) {
useLayoutEffect(() => {
const obj = ref.current
if (!obj) return
const obj = ref.current;
if (!obj) return;
// 1. Add to master map
sceneRegistry.nodes.set(id, obj)
sceneRegistry.nodes.set(id, obj);
// 2. Add to type-specific set
sceneRegistry.byType[type].add(id)
sceneRegistry.byType[type].add(id);
// 4. Cleanup when component unmounts
return () => {
sceneRegistry.nodes.delete(id)
sceneRegistry.byType[type].delete(id)
}
}, [id, type, ref])
sceneRegistry.nodes.delete(id);
sceneRegistry.byType[type].delete(id);
};
}, [id, type, ref]);
}