@pascal-app/core
The@pascal-app/core package provides the foundational scene graph management, state store, and spatial systems for Pascal. It handles the hierarchical node structure, undo/redo, persistence, and collision detection.
Installation
Package Exports
Store
useScene- Main Zustand store for scene state management
Events
emitter- Event bus for scene interactions (based on mitt)eventSuffixes- Available event suffixes:click,move,enter,leave,pointerdown,pointerup,context-menu,double-click
BuildingEvent- Building interaction eventsCameraControlEvent- Camera control eventsCeilingEvent- Ceiling interaction eventsDoorEvent- Door interaction eventsEventSuffix- Type for event suffix stringsGridEvent- Grid interaction eventsItemEvent- Item interaction eventsLevelEvent- Level interaction eventsNodeEvent- Generic node eventsRoofEvent- Roof interaction eventsSiteEvent- Site interaction eventsSlabEvent- Slab interaction eventsWallEvent- Wall interaction eventsWindowEvent- Window interaction eventsZoneEvent- Zone interaction events
Hooks & Registry
sceneRegistry- Global registry mapping node IDs to Three.js Object3D instancesuseRegistry- React hook to register Three.js objects with the scene registry
Spatial Grid
spatialGridManager- Singleton for spatial queries and collision detectionuseSpatialQuery- Hook for querying spatial grid (floor, wall, ceiling placement)initSpatialGridSync- Initialize spatial grid synchronization with scene storeresolveLevelId- Resolve level ID from any node by walking up the parent chain
Schema
Node Types:SiteNode- Root container for buildingsBuildingNode- Contains levelsLevelNode- Contains walls, slabs, itemsWallNode- Wall geometrySlabNode- Floor/ceiling slabCeilingNode- Ceiling geometryItemNode- 3D object/furnitureZoneNode- Spatial zoneRoofNode- Roof geometryScanNode- Scan dataGuideNode- Guide/helper objectWindowNode- Window in wallDoorNode- Door in wall
generateId- Generate unique node IDs with prefix (e.g.,wall_abc123)objectId- Zod schema for object IDs with default generationnodeType- Zod schema for node type literalsMaterial- Zod schema for material preset name referencesgetScaledDimensions- Get item dimensions with scale applied
BaseNode- Base node schemaCameraSchema- Camera configuration schemaAnyNode- Union type of all node typesAnyNodeId- Any node ID typeAnyNodeType- Any node type string
Systems
Systems are React components that run physics/validation logic each frame:CeilingSystem- Ceiling validation and updatesDoorSystem- Door placement and validationItemSystem- Item collision detectionRoofSystem- Roof geometry updatesSlabSystem- Slab elevation and validationWallSystem- Wall mitering and CSG operationsWindowSystem- Window placement validation
Space Detection
detectSpacesForLevel- Detect enclosed spaces in a levelinitSpaceDetectionSync- Initialize space detection synchronizationwallTouchesOthers- Check if wall connects to other wallsSpace- Space detection result type
Asset Storage
loadAssetUrl- Load asset URL from storagesaveAsset- Save asset to storage
Utilities
Type Guards:isObject- Type guard to check if value is a plain object (not null or array)
pointInPolygon- Point-in-polygon test using ray casting algorithm
Architecture
Scene Graph
The scene is a hierarchical tree structure:State Management
TheuseScene store is built with:
- Zustand - State management
- Zundo - Undo/redo (temporal middleware)
- Persist - LocalStorage persistence
Spatial Systems
ThespatialGridManager provides:
- Floor grid for item placement
- Wall grid for wall-mounted items
- Ceiling grid for ceiling items
- Slab elevation queries
- Collision detection