Scene Registry
The scene registry provides a global mapping from Pascal node IDs to their corresponding Three.jsObject3D instances. This allows quick lookups for camera controls, raycasting, and other Three.js operations.
Import
sceneRegistry
A global singleton object containing:nodes
byType
useRegistry
React hook to register a Three.js object with the scene registry. Automatically handles cleanup on unmount.Signature
Parameters
string
required
The Pascal node ID (e.g.,
wall-123, item-456)keyof typeof sceneRegistry.byType
required
The node type. Must be one of:
sitebuildingceilinglevelwallitemslabzoneroofscanguidewindowdoor
React.RefObject<THREE.Object3D>
required
React ref to the Three.js Object3D (or any subclass like Group, Mesh, etc.)
Behavior
-
On mount (when
ref.currentbecomes available):- Adds the node ID → Object3D mapping to
sceneRegistry.nodes - Adds the node ID to the appropriate
sceneRegistry.byTypeSet
- Adds the node ID → Object3D mapping to
-
On unmount:
- Removes the node ID from
sceneRegistry.nodes - Removes the node ID from
sceneRegistry.byType
- Removes the node ID from
Usage Examples
Registering a Component
Querying the Registry
Counting Nodes by Type
Iterating Over Typed Nodes
Camera Control Integration
Type Definitions
Performance Considerations
- Fast lookups:
Map.get()is O(1) - Fast iteration: Iterating over a
Setis faster than filtering an array - Memory efficient: Only stores references to existing Three.js objects
- Automatic cleanup: No memory leaks from unmounted components
See Also
- Scene Store - State management for node data
- Spatial Grid Manager - Spatial queries
- Package Overview - Full exports list