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.
Categorized lookups mapping node types to Sets of node IDs. Using Sets provides faster add/delete operations than arrays.Example:
// Get all wall IDsconst wallIds = Array.from(sceneRegistry.byType.wall)// Get all wall objectsconst wallObjects = wallIds .map(id => sceneRegistry.nodes.get(id)) .filter(Boolean)
Adds the node ID → Object3D mapping to sceneRegistry.nodes
Adds the node ID to the appropriate sceneRegistry.byType Set
On unmount:
Removes the node ID from sceneRegistry.nodes
Removes the node ID from sceneRegistry.byType
Show Implementation Details
Uses useLayoutEffect to ensure registration happens synchronously before paint, preventing race conditions with code that immediately queries the registry.
import { sceneRegistry } from '@pascal-app/core'// Get a specific objectconst wallObject = sceneRegistry.nodes.get('wall-123')// Get all wallsconst wallIds = Array.from(sceneRegistry.byType.wall)const wallObjects = wallIds .map(id => sceneRegistry.nodes.get(id)) .filter((obj): obj is THREE.Object3D => obj !== undefined)// Focus camera on a nodefunction focusOnNode(nodeId: string) { const object = sceneRegistry.nodes.get(nodeId) if (object) { cameraControls.fitToBox(object, true) }}