Overview
TheWallSystem is a React component that processes dirty wall nodes and generates 3D geometry with:
- Automatic mitering at wall junctions (L-joints, T-joints, corners)
- CSG cutouts for doors and windows using three-bvh-csg
- Level-aware processing with slab elevation support
- Adjacent wall updates when walls share junctions
useFrame hook at priority 4, ensuring walls update after items and slabs.
Location
How It Works
Processing Pipeline
1
Collect dirty walls by level
The system groups dirty wall nodes by their parent
levelId to process walls on the same floor together.2
Calculate miter data
For each level with dirty walls, the system calls
calculateLevelMiters() to compute junction intersections for all walls on that level.3
Update dirty walls
Each dirty wall gets new geometry via
updateWallGeometry(), which:- Retrieves slab elevation from the spatial grid
- Collects child nodes (doors, windows)
- Generates extruded wall geometry with mitering
- Applies CSG subtraction for cutouts
- Updates the mesh and collision mesh
4
Update adjacent walls
Walls that share junctions with dirty walls also get updated to maintain consistent mitering.
Geometry Generation
ThegenerateExtrudedWall() function builds wall geometry in these steps:
- Build polygon in world coordinates using junction miter data
- Transform to wall-local coordinates (x along wall, z perpendicular)
- Create THREE.Shape and extrude along height
- Rotate geometry so extrusion becomes vertical (Y-axis)
- Apply CSG subtraction for door/window cutouts
Props
TheWallSystem component has no props. It reads state from the Zustand store:
Set<AnyNodeId>
Set of node IDs that need geometry updates
Record<AnyNodeId, AnyNode>
All nodes in the scene graph
Dependencies
WallNode Schema
The system processesWallNode objects with these properties:
string
required
Unique wall identifier
[number, number]
required
Start point in level coordinates
[x, z][number, number]
required
End point in level coordinates
[x, z]number
default:"0.1"
Wall thickness in meters
number
default:"2.5"
Wall height in meters
string
Parent level ID
string[]
Child item IDs (doors, windows)
External Systems
- Scene Registry (
sceneRegistry.nodes): Maps node IDs to THREE.js meshes - Spatial Grid Manager (
spatialGridManager): Provides slab elevation data - Wall Mitering (
wall-mitering.ts): Calculates junction intersections
Mitering Algorithm
The mitering system handles complex wall intersections:Junction Detection
- Corner junctions: Two or more walls meeting at endpoints
- T-junctions: A wall endpoint touching another wall’s segment
Miter Calculation
For each junction:- Sort walls by outgoing angle
- Compute left and right edge lines for each wall (offset by
thickness/2) - Intersect adjacent wall edges to find miter points
- Build polygon with miter points at junctions and center vertices for clean fans
~/workspace/source/packages/core/src/systems/wall/wall-mitering.ts for implementation.
CSG Cutouts
Doors and windows create cutouts using Constructive Solid Geometry:1
Find cutout meshes
Child nodes with a mesh named
'cutout' are collected.2
Create cutout brushes
Each cutout’s bounding box is transformed to wall-local space and extruded through the wall thickness.
3
Subtract from wall
The CSG evaluator subtracts each cutout brush from the wall geometry using
SUBTRACTION operation.Usage in Viewer
- Monitors the
dirtyNodesstore - Updates walls when they’re marked dirty
- Maintains consistent geometry across all walls on a level
Performance Notes
- Processes walls level-by-level to share miter calculations
- Reuses a single
csgEvaluatorinstance for all CSG operations - Only updates dirty walls and their immediate neighbors
- Pre-computes BVH trees for efficient CSG operations
- Disposes old geometries to prevent memory leaks
Related
- SlabSystem - Manages floor geometry
- CeilingSystem - Manages ceiling geometry
- ItemSystem - Positions items on walls