Overview
TheSlabSystem is a React component that processes dirty slab nodes and generates 3D floor geometry. It supports:
- Polygon-based geometry with arbitrary shapes
- Hole support for cutouts (stairs, shafts)
- Automatic outset to extend under walls
- Configurable elevation for raised floors
useFrame hook at priority 1, ensuring slabs update early in the frame.
Location
How It Works
Processing Pipeline
Update geometry
For each dirty slab:
- Generate new geometry from the polygon
- Apply automatic outset to extend under walls
- Add holes to the shape
- Dispose old geometry and replace it
Geometry Generation
ThegenerateSlabGeometry() function:
- Outset polygon by
SLAB_OUTSET(0.05m) to extend under walls - Create THREE.Shape from polygon points
- Add holes from the
holesarray - Extrude shape by
elevationamount - Rotate so extrusion becomes vertical (Y-axis)
Props
TheSlabSystem component has no props. It reads state from the Zustand store:
Set of node IDs that need geometry updates
All nodes in the scene graph
Dependencies
SlabNode Schema
The system processesSlabNode objects with these properties:
Unique slab identifier
Array of
[x, z] coordinates defining the slab boundary in level coordinatesArray of polygons representing holes in the slab (for stairs, shafts, etc.)
Slab thickness/elevation in meters
External Systems
- Scene Registry (
sceneRegistry.nodes): Maps node IDs to THREE.js meshes
Polygon Outset
TheoutsetPolygon() function expands a polygon outward by a uniform distance:
This ensures slabs extend slightly under walls (by default
0.05m = half wall thickness) to prevent gaps.
Usage Example
Coordinate System
Slabs use the level coordinate system:- X-axis: Horizontal (left-right)
- Y-axis: Vertical (height)
- Z-axis: Horizontal (forward-back)
[x, z] plane, and extrusion happens along the Y-axis.
Holes
Slabs support multiple holes for architectural features:- Defined as polygons in the same coordinate system
- Automatically converted to THREE.Path and added to the shape
- Properly extruded through the entire slab thickness
Performance Notes
- Only updates dirty slabs (not all slabs every frame)
- Disposes old geometry before creating new geometry
- Runs at priority
1(early in frame) so other systems can use updated geometry
Integration with Other Systems
Spatial Grid
After slab geometry is generated, the spatial grid system uses slab elevations to:- Position wall bases correctly
- Elevate floor items to the right height
- Calculate item placement on raised floors
Wall System
Walls query the spatial grid for slab elevation to:- Adjust wall base height
- Extend walls downward for negative slab elevations
- Preserve wall top height regardless of floor level
Related
- WallSystem - Manages wall geometry with mitering
- CeilingSystem - Manages ceiling geometry
- ItemSystem - Positions items on slabs