A 2D floor plan tells a carpenter where the studs go, while a 3D massing model lets a homeowner immediately spot tight hallways, awkward window heights, and kitchen island sightlines before framing starts. Many remodelers and designers also want to pull their preliminary floor plan directly into Blender, SketchUp, Rhino, or Unreal Engine without paying for heavy desktop CAD suites.

At PlanCaliber, we generate both our real-time browser 3D preview and downloadable Wavefront .OBJ + .MTL mesh archives directly from our canonical 2D inches-based wall graph in pure TypeScript with zero heavy CSG libraries or WebAssembly booleans.

Here is how to turn 2D walls with door and window openings into clean, watertight, manifold 3D geometry in ~120 lines of TypeScript.

1. Why CSG Boolean Subtraction Fails in Browser CAD

The naive approach to cutting doors and windows out of a 3D wall is to extrude a solid wall box and run a 3D CSG boolean difference for each opening. In production browser tools, CSG subtraction causes three recurring problems:

  • Coplanar Z-fighting and slivers: When an opening box touches the exact front and back planes of a 4.5" or 6.5" wall, floating-point epsilon noise produces T-junctions and degenerate hairline triangles.
  • Flipped normals: Importers like SketchUp and Blender shade inverted faces dark gray or break ambient occlusion.
  • Bundle bloat: General-purpose 3D boolean kernels add hundreds of kilobytes to client bundles.

Because residential wall openings (doors, cased openings, windows, garage bays) are axis-aligned along the wall's local (u, z) plane, you never need 3D CSG at all.

2. Exact Sub-Prism Decomposition Along Each Wall

Parameterize every wall in its local 2D elevation coordinate system:

  • u in [0, L]: distance along the wall centerline from start vertex (x1, y1) to end vertex (x2, y2)
  • v in [-t/2, +t/2]: wall thickness perpendicular to the wall unit direction (ux, uy) along right-hand normal (-uy, ux)
  • z in [0, H]: vertical elevation off the finished floor (default 96" for an 8'-0" US ceiling)

Sort all openings along the wall by offsetIn ([u0, u1], vertical span [sillZ, headZ]):

  1. Solid Pier Before Each Opening: [cursor, u0] x [0, H]
  2. Sill Wall Below Window (when sillZ > 0): [u0, u1] x [0, sillZ]
  3. Header Lintel Above Door/Window (when headZ < H): [u0, u1] x [headZ, H]
  4. Final Solid Pier After Last Opening: [cursor, L] x [0, H]

Look at a single 12'-0" (144") exterior wall (8'-0" / 96" high) with one 36"-wide window (sillZ = 36", headZ = 80"):

  • It decomposes deterministically into 4 airtight rectangular sub-prisms: LEFT PIER, SILL (0"-36"), HEADER (80"-96"), and RIGHT PIER.
  • Every box has 6 quad faces = 12 triangles (4 * 12 = 48 triangles total), zero overlapping coplanar faces, zero T-junctions inside a face, and mathematically exact outward normals.
export interface ElevationSpan { u0: number; u1: number; z0: number; z1: number; } export interface OpeningElevation { offsetIn: number; widthIn: number; sillHeightIn: number; headHeightIn: number; } export function decomposeWallElevation( lengthIn: number, wallHeightIn: number, openings: readonly OpeningElevation[] ): ElevationSpan[] { const spans: ElevationSpan[] = []; const sorted = [...openings].sort((a, b) => a.offsetIn - b.offsetIn); let cursor = 0; for (const op of sorted) { const u0 = Math.max(cursor, Math.min(lengthIn, op.offsetIn)); const u1 = Math.max(u0, Math.min(lengthIn, op.offsetIn + op.widthIn)); const sill = Math.max(0, Math.min(wallHeightIn, op.sillHeightIn)); const head = Math.max(sill, Math.min(wallHeightIn, op.headHeightIn)); if (u0 - cursor > 0.25) { spans.push({ u0: cursor, u1: u0, z0: 0, z1: wallHeightIn }); } if (u1 - u0 > 0.25) { if (sill > 0.25) { spans.push({ u0, u1, z0: 0, z1: sill }); } if (wallHeightIn - head > 0.25) { spans.push({ u0, u1, z0: head, z1: wallHeightIn }); } } cursor = Math.max(cursor, u1); } if (lengthIn - cursor > 0.25) { spans.push({ u0: cursor, u1: lengthIn, z0: 0, z1: wallHeightIn }); } return spans; } 

3. Mapping Local Prisms to Right-Handed Y-Up Wavefront .OBJ

Most 3D importers (Blender, SketchUp, Three.js) default to a right-handed Y-up coordinate system (X = east, Y = elevation, Z = south). Converting each (u, v, z) corner in inches (or meters via 0.0254 scale) into 8 world vertices and emitting counter-clockwise (CCW) faces guarantees outward-facing normals on every single prism:

export class ObjBuilder { private vertices: string[] = []; private normals: string[] = []; private groups = new Map<string, string[]>(); addBox( material: string, corners: readonly [number, number, number][] // 8 corners: bottom 0..3 CCW, top 4..7 CCW ): void { const baseV = this.vertices.length + 1; // Wavefront OBJ is 1-indexed! for (const [x, y, z] of corners) { this.vertices.push(`v ${x.toFixed(3)} ${y.toFixed(3)} ${z.toFixed(3)}`); } const faces: readonly [number, number, number, number][] = [ [0, 3, 2, 1], // bottom (-Y) [4, 5, 6, 7], // top (+Y) [0, 1, 5, 4], // front [2, 3, 7, 6], // back [1, 2, 6, 5], // right [3, 0, 4, 7] // left ]; const list = this.groups.get(material) ?? []; for (const [a, b, c, d] of faces) { list.push(`f ${baseV + a} ${baseV + b} ${baseV + c}`); list.push(`f ${baseV + a} ${baseV + c} ${baseV + d}`); } this.groups.set(material, list); } toObjString(mtlFilename: string): string { const lines = ['# PlanCaliber 3D Floor Plan Export (Units: Inches)', `mtllib ${mtlFilename}`, '']; lines.push(...this.vertices, ''); for (const [mat, faces] of this.groups.entries()) { lines.push(`g ${mat}`, `usemtl ${mat}`, ...faces, ''); } return lines.join('\n'); } } 

4. Grouping Materials Cleanly in .MTL for Instant Downstream Styling

Instead of dumping all geometry into a single unnamed mesh, emitting semantic material groups in the companion .MTL file lets users swap wood floors, exterior siding, drywall paint, and glazing in one click inside Blender or SketchUp:

# PlanCaliber Material Library newmtl wall_ext Kd 0.88 0.87 0.84 Ka 0.20 0.20 0.20 d 1.00 newmtl wall_int Kd 0.96 0.96 0.94 d 1.00 newmtl floor_slab Kd 0.78 0.72 0.64 d 1.00 newmtl window_glazing Kd 0.55 0.75 0.88 d 0.35 

You can explore live 2D-to-3D wall extrusion across 40 residential US templates right inside your browser, including our 4-Bed Modern Farmhouse and 24'x32' A-Frame Cabin.

5. Free Browser 3D Preview and Transparent Export Tiers

In PlanCaliber, interactive 2D drafting and real-time 3D preview run completely free in your browser:

  • Free Studio Draft ($0): Full 2D/3D studio, 40 US templates, 20 building-code calculators, 2 AI sketch/text scans/day, and instant watermarked proof PNG exports.
  • Print Pass ($9 one-time): Unwatermarked 2-sheet vector PDF (A-101 + M-101), 2400px PNG, SVG, and custom title block.
  • Full CAD Pack ($19 one-time, or $49 5-Plan Pack): Full 5-sheet 1/4" = 1'-0" PDF set, 8-layer AutoCAD R12 .DXF, 3D Wavefront .OBJ + .MTL, and Framing & Drywall .CSV takeoff. See all tiers on Pricing.

Note: PlanCaliber produces preliminary space-planning drawings and 3D massing models only. Always verify structural framing, dimensions, and local codes on site with licensed local professionals before construction.