Skip to main content

Scene Registry

The scene registry provides a global mapping from Pascal node IDs to their corresponding Three.js Object3D instances. This allows quick lookups for camera controls, raycasting, and other Three.js operations.

Import

sceneRegistry

A global singleton object containing:

nodes

Master lookup map from node ID to Three.js Object3D instance. Example:

byType

Categorized lookups mapping node types to Sets of node IDs. Using Sets provides faster add/delete operations than arrays. Example:

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:
  • site
  • building
  • ceiling
  • level
  • wall
  • item
  • slab
  • zone
  • roof
  • scan
  • guide
  • window
  • door
React.RefObject<THREE.Object3D>
required
React ref to the Three.js Object3D (or any subclass like Group, Mesh, etc.)

Behavior

  1. On mount (when ref.current becomes available):
    • Adds the node ID → Object3D mapping to sceneRegistry.nodes
    • Adds the node ID to the appropriate sceneRegistry.byType Set
  2. On unmount:
    • Removes the node ID from sceneRegistry.nodes
    • Removes the node ID from sceneRegistry.byType

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 Set is 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