Feature Library

Construction kit: buildings from a grid, pieces that fit their neighbours (engine-free)

2.95 GPU · 0.52 CPU ms
A still of the Construction kit: buildings from a grid, pieces that fit their neighbours (engine-free) demo
Still
The live demo starts when it’s in view.Tools: floor, wall, window, door, roof, stairs, paint, area, erase · Roof style: hip, gable, flat (R) · Storey: ground or upper · Turn the view · Keyboard: arrows, Shift with an arrow, Enter, R, Q and E · Palettes per area · Show the areas · Show live and merged · Merge distance

The HaTac engine’s construction kit, lifted whole and engine-free.

Four modules work together. The construction solvers lay out real stock from a player’s intent: stairs and ramps that divide their rise into lawful risers with landings and stringers seated on posts, brackets or floors; railings with shared, mitred corner posts; hip, gable, shed and flat roofs from any rectilinear outline with ridges, hips and valleys; wall openings framed on the wall’s grid. The piece set expands a few authored families (decks, walls, pillars, roof cells, stairs, guards) into every member a grid needs: a wall junction for each neighbour pattern, a deck with edge members on its open sides, a roof cell for each corner-height pattern, with optional plinths, bands, posts, glazing, trusses and bolts, and a checker that compares the actual mating outlines at every level of detail. Piece batches keep placed members editable near the camera and merge settled cells into shared meshes off the frame (identical cells share one), hiding the faces neighbours cover and keeping every edge vertex so nothing cracks. Palette areas resolve each material role at a piece’s placement anchor, so one palette switch rewrites a colour table and nothing else. The library adds the glue the engine kept in its core (members from the solvers, neighbour picks, a palette provider) and a small standalone WebGPU drawer with levels of detail, a shadow map and an exported light model. The demo is a build site: lay floors, walls, roofs and stairs on a grid and watch every piece pick its corners and edges from its neighbours; roofs are hipped, gabled or flat per footprint with their open ends closed, and an edit that would leave something standing on nothing is refused with the reason.

What it costs a frame

2.95 ms
0.52 ms
GPU
2.95 ms
CPU, median
0.52 ms
CPU, 95th pct
0.79 ms
Draw calls
0
Weight
Heavy

Measured 28 November 2026 on RTX 4060 Laptop, 13th Gen Intel(R) Core(TM) i9-13900H, Chrome 158, 1920×1080 at 1×. 600 frames × 3 rounds, median kept (rounds ranged GPU 1.71–2.98, CPU 0.49–0.52 ms). What ran: Alone: every member of the demo’s generated set (24 members in six families: decks, wall panels and junctions, a column, six roof cells, a stair flight and a guard) laid out in rows and drawn instanced with the fixed shadow map, the ground, the trees and the sky; no merging, no areas. Phones: tiers are being measured next.

How steadily it runs on RTX 4060 Laptop · 13th Gen Intel(R) Core(TM) i9-13900H · reference

Typical frame ?
16.82 ms
1% low ?
55 fps
Varies by ?
±0.43 ms
All metricsRTX 4060 Laptop · 13th Gen Intel(R) Core(TM) i9-13900H · reference
p50p95p9916.04 ms18.03 ms +
How long each frame took. Most frames sit in the tall bars; a long tail to the right is hitching.

Frames run on a 60 Hz timer (a page demo), so most frames take about one tick, 16.7 ms: the spread around it is what matters.

Frames

Median (p50) ?
16.82 ms
p95 ?
17.65 ms
p99 ?
17.96 ms
Slowest ?
18.48 ms
Mean ?
16.86 ms
Standard deviation ?
0.43 ms
1% low ?
55 fps
0.1% low ?
54 fps
Hitches ?
0 of 600
Over budget ?
0 of 600

Main thread

Long tasks ?
0
Long frames ?
0
Event-loop delay ?
0.0 / 1.4 / 1.7 ms

Input

No input during this run.

Memory

JavaScript heap ?
33.3 → 33.8 MB
Growth ?
+0.55 MB

Browser

JavaScript a frame ?
0.59 ms
All tasks a frame ?
2.32 ms
Layout / style ?
0.48 / 0.17 ms
Main thread busy ?
14%

Garbage collection

Collections ?
14 (3 minor, 11 major)
Pauses ?
59.7 ms in all, longest 1.9

What it needs

Renders with
WebGPUNeeds WebGPU: current Chrome and Edge, Safari 26+, Firefox 141+ on Windows.
Your browser
Checking…Looking for WebGPU
Depends on
NothingNo other packages
With an agent
install("construction-kit")Your coding agent reads its pitfalls and installs it through the library’s MCP server. Set it up

What it’s for

  1. A base-building or colony game where players lay floors, walls, roofs and stairs on a grid and every piece shows the right corner, end or tee for its neighbours
  2. A city or factory builder with thousands of placed pieces: editable near the camera, merged into shared meshes once a district settles, with no cracks at the seams
  3. Stairs, ramps, railings and roofs fitted to whatever the player drew: lawful risers and landings, shared corner posts, hips and valleys from an L- or U-shaped plan
  4. A modular kit authored as a few families instead of hundreds of hand-made pieces, checked for gaps, unmatched subdivisions and coplanar fights at every level of detail
  5. Colourways by district or team: switch a whole area’s palette, change one role in one area, or give a single piece its own colour, without rebuilding geometry
  6. A level editor or architectural sketch tool that needs real stock (stringers, cleats, headers, bolts) rather than boxes

Pitfalls, in brief

  1. The demo needs WebGPU: the drawer draws with WGSL pipelines, storage buffers for the colour table and a comparison-sampled shadow map.
  2. Reserve the horizontal run for every level landing before dividing the risers: total rise over drag length alone approves flights steeper than the grade between landings (solveFlight does this; keep maxFlightRise, landing and minTread consistent).
  3. Clip a corner post’s head against both rail triangles.
  4. Keep one local origin and the full edge subdivision on adjacent roof plates.
  5. Keep every boundary subdivision through the last level of detail, and every authored edge vertex after merging (seams.ts splitEdges): one long edge facing two short ones is a T-junction that shows background pixels.
20 more in brief
  1. Only full, congruent faces with the same mating tag hide each other.
  2. Keep family IDs, sizes in cells and variant names stable after release: saves keep the member IDs (memberId), not the geometry, so a renamed variant orphans every placed copy.
  3. A wall’s body runs between its courses, and a junction’s post replaces its column: a course laid over a full-height body shares end caps and an underside with it (the engine counted 33 coplanar overlaps on its plain workshop before it changed).
  4. Glazing panes are laid as infill, and infill leaves at the family’s detailLod (default 1): a set with glazing and a lower detailLod opens its windows into holes at distance.
  5. Roof cells are lifted by a truss detail’s depth even where no truss hangs under them: a saddle or valley cell with no level edge floats that far above the eave at its low corner.
  6. The engine’s set has no gable member: a gabled or stepped roof shows an open triangle at every side no neighbour cell continues.
  7. Give an L, T or cross gable one gable per wing (each maximal rectangle of the footprint, its ridge along its long side) and take the highest wing at every node: the wings meet in valleys the set’s roof cells already have.
  8. Pick a piece for paint or erase by casting the pointer’s ray against the placed pieces (pickPiece in the demo: each piece’s faces in its own frame, after its bounds), never by the build-plane cell under the pointer: the plane point lies behind what the pointer is on, often under another piece’s roof.
  9. Draw previews with a depth bias toward the camera (the drawer’s ghost pipeline): a ghost shares planes with the pieces it replaces and meets, and without the bias they fight as the view moves.
  10. Style a roof per footprint, not per cell, and give its corners heights in roof steps (a hip’s corner its square distance to the eave, a gable’s its distance across the ridge, an odd gable span’s middle row the set’s gable cell): cells picked one by one from their four neighbours mix hips and gables and step by more than one rise.
  11. An edit to a merged cell keeps its old mesh on screen until the replacement is built (the world’s rule, so a far cell never flickers): in a build tool, wake the cells near an edit (the demo lifts the merge distance for a moment) or a roof that spans two cells shows half old, half new.
  12. Check load paths on every edit before placing: in the demo an upper wall needs an upper floor beside its line or a wall below it, and a roof a wall of its storey under one of its edges (upper floors get columns under their corners).
  13. Pass the placement origin in world metres as the palette anchor, never a merged cell’s centre: a cell can straddle two areas, and each piece must keep its own area through a merge (createPieceWorld’s exactPaletteAnchors, the drawer’s owner table).
  14. Change a palette with setPalette and boundaries with replace: a palette switch only rewrites the colour table (the demo shows the counts), a boundary edit re-resolves every anchor but uploads no geometry.
  15. Give each merged-cell build its own reservation until it is published, and keep the previous chunk on screen until the replacement is ready: an edit can arrive while a build is in flight (the world discards a result for an earlier revision).
  16. Merged cells are built on the main thread here, after a timeout so they stay off the frame; a town of thousands of pieces wants the engine’s worker (queue.ts createCellWorker, with buildCell and packSurfaces inside it).
  17. The drawer keeps one fallback colour per palette role, from the set’s materials: two set materials that share a palette role with different colours draw in one of them where no area covers a piece.
  18. A bar with a joint (a bracket or hanger with bolted, welded, pinned or lapped ends) is a plain box in partFaces; the engine draws its beam hardware with the beams module (see free-beams).
  19. The drawer has no far silhouettes (the engine’s pieces.silhouetteDistance): distant cells keep their merged mesh at its coarsest level, and surface patterns fade to flat colours by distance instead of by level.
  20. Decide which side of a junction is a corner from its neighbours only: pickJoin gives the outside corner for two neighbours at right angles.
25 pitfalls in full, the hook-up guide, the module source and its tests come with the part.

Where it comes from

From HaTac. Adapted from published work, named below.

Hannes Andersson: The HaTac engine’s construction solvers, piece sets, piece batches, palette areas, their decisions and tests (built for his game and proven there); the library’s glue, drawer and demo.

Brian Karis, Real shading in Unreal Engine 4 (SIGGRAPH 2013): The GGX distribution, Schlick–Smith visibility and Fresnel in the drawer’s light model.

Krzysztof Narkowicz, ACES filmic tone mapping curve (2016): The fitted curve the drawer tone-maps with.

constructionbuildingbuild modebase buildingmodular kitsnappinggrid buildingneighbour rulesauto tilingwang tileswall junctionscornersteesdeck edgeskerbsroof solverhip roofgable roofvalleysstairsstair solverriserslandingsstringers

Near it in the frame