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
Collect dirty walls by level
The system groups dirty wall nodes by their parent
levelId to process walls on the same floor together.Calculate miter data
For each level with dirty walls, the system calls
calculateLevelMiters() to compute junction intersections for all walls on that level.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
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 of node IDs that need geometry updates
All nodes in the scene graph
Dependencies
WallNode Schema
The system processesWallNode objects with these properties:
Unique wall identifier
Start point in level coordinates
[x, z]End point in level coordinates
[x, z]Wall thickness in meters
Wall height in meters
Parent level ID
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:Create cutout brushes
Each cutout’s bounding box is transformed to wall-local space and extruded through the wall thickness.
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