<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[TrueDraft CAD Engineering]]></title><description><![CDATA[TrueDraft CAD Engineering]]></description><link>https://truedraftcad.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Fri, 04 Dec 2026 22:16:21 GMT</lastBuildDate><atom:link href="https://truedraftcad.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Building an Open-Source Browser Floor Plan CAD Engine in TypeScript (Canvas2D, Three.js, Pure-JS DXF & Binary STL)]]></title><description><![CDATA[How a single pure-TypeScript parametric wall graph drives 2D blueprints, live 3D cutaways, AutoCAD R12 DXF, and watertight 3D-print STL without monthly…]]></description><link>https://truedraftcad.hashnode.dev/building-an-open-source-browser-floor-plan-cad-engine-in-typescript-canvas2d-three-js-pure-js-dxf-binary-stl</link><guid isPermaLink="true">https://truedraftcad.hashnode.dev/building-an-open-source-browser-floor-plan-cad-engine-in-typescript-canvas2d-three-js-pure-js-dxf-binary-stl</guid><category><![CDATA[open source]]></category><category><![CDATA[TypeScript]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[ThreeJS]]></category><category><![CDATA[Sveltekit]]></category><dc:creator><![CDATA[Anders Kessler]]></dc:creator><pubDate>Fri, 04 Dec 2026 18:28:43 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6b0d835a7f7611369f197f73/e9c2e150-583b-4ed8-b57d-ca4b0dcd64af.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Most browser floor plan tools lock you into a $30–$99/month subscription and keep your drawings inside a proprietary cloud format. When we built <a href="https://www.truedraftcad.com/open-source">TrueDraft CAD</a> (<code>GNU AGPL-3.0</code>), we wanted to see how far a pure client-side TypeScript CAD engine could go with zero native binaries, zero account walls on first visit, and deterministic exports to AutoCAD <code>.DXF</code>, vector Blueprint <code>.PDF</code>, 3D <code>.OBJ</code>, and watertight 3D-printable <code>.STL</code>.</p>
<p>Here is how the core geometry, rendering, and export pipeline works under the hood — and why keeping the CAD kernel in plain TypeScript solves several headaches of desktop floor plan software.</p>
<p><img src="https://raw.githubusercontent.com/truedraftcad/truedraft-cad/main/docs/screenshots/split-2d-3d-2story.png" alt="TrueDraft CAD 2D Blueprint + Live 3D Split Viewport" /></p>
<h2>1. One Pure-TypeScript Model Drives Four Views and Seven Exporters</h2>
<p>Desktop CAD tools often drift between their 2D drafting canvas, 3D preview, and print/export pipeline. In TrueDraft CAD, every floor plan lives in a single normalized metric data structure (<code>FloorPlan</code>, stored in meters internally and formatted to US Imperial feet/inches or metric millimeters at the UI boundary).</p>
<p>Every edit — dragging a wall endpoint, placing a 36" entry door, adding a second story, or importing a <code>.DXF</code> — runs through a pure, deterministic <code>computePlan()</code> pass in <a href="https://github.com/truedraftcad/truedraft-cad/blob/main/src/lib/cad/geometry.ts"><code>src/lib/cad/geometry.ts</code></a>:</p>
<pre><code class="language-ts">const SNAP_TOL = 0.06; // 6 cm tolerance for vertex merging &amp; T-junctions
const MIN_ROOM_AREA_SQM = 0.4; // ignore tiny slivers &lt; 0.4 m²
const DRYWALL_SHEET_SQM = 32 / SQ_FEET_PER_SQ_METER; // 4'x8' = 32 sq ft

export function wallNormal(w: Wall): Point2D {
  const len = wallLength(w);
  if (len &lt; 1e-9) return { x: 0, y: 1 };
  return {
    x: -(w.y2 - w.y1) / len,
    y: (w.x2 - w.y1) / len
  };
}
</code></pre>
<p>From that single <code>ComputedPlan</code> output, the app synchronously derives:</p>
<ol>
<li><strong>Interactive 2D Canvas2D Drafting &amp; Blueprint Sheet View</strong> (true-scale architectural wall poche, mitered corners, exterior dimension chains, live snap guides).</li>
<li><strong>Live Three.js 3D Cutaway Viewport</strong> (wall extrusions punched cleanly around door and window openings, multi-story floor stacking, orbit/walkthrough camera).</li>
<li><strong>Planar Half-Edge Room Detection &amp; Material Takeoffs</strong> (automatic enclosed polygon detection, net square footage, interior/exterior linear wall feet, 4'×8' drywall sheet estimates, and door/window schedules).</li>
<li><strong>Seven Client-Side Exporters</strong> (vector Blueprint <code>.PDF</code>, AIA-layered AutoCAD R12 <code>.DXF</code>, 3D <code>.OBJ</code>, watertight binary <code>.STL</code>, <code>.SVG</code>, <code>.CSV</code> takeoff schedules, and 4K <code>.PNG</code>).</li>
</ol>
<h2>2. Why Pure-JS AutoCAD R12 <code>.DXF</code> Still Beats Heavy CAD Conversions</h2>
<p>Contractors, drafters, and permitting offices do not want a flat raster screenshot — they want crisp, layered linework they can open immediately in AutoCAD, LibreCAD, QCAD, Revit, or Rhino without broken hatches or random layer names.</p>
<p>Rather than relying on a server-side converter, <a href="https://github.com/truedraftcad/truedraft-cad/blob/main/src/lib/exporters/dxf.ts"><code>src/lib/exporters/dxf.ts</code></a> emits clean <strong>AutoCAD R12 ASCII <code>.DXF</code></strong> directly in the browser using standard <strong>AIA CAD layer conventions</strong>:</p>
<pre><code class="language-ts">const AIA_LAYERS: DxfLayerDef[] = [
  { name: '0', color: 7, ltype: 'CONTINUOUS' },
  { name: 'A-WALL', color: 7, ltype: 'CONTINUOUS' },
  { name: 'A-WALL-INTR', color: 8, ltype: 'CONTINUOUS' },
  { name: 'A-DOOR', color: 30, ltype: 'CONTINUOUS' },
  { name: 'A-GLAZ', color: 5, ltype: 'CONTINUOUS' },
  { name: 'A-FURN', color: 9, ltype: 'CONTINUOUS' },
  { name: 'A-ELEC', color: 2, ltype: 'CONTINUOUS' },
  { name: 'A-PLMB', color: 4, ltype: 'CONTINUOUS' },
  { name: 'A-AREA', color: 3, ltype: 'CONTINUOUS' },
  { name: 'A-ANNO-DIMS', color: 1, ltype: 'CONTINUOUS' },
  { name: 'A-ANNO-TEXT', color: 7, ltype: 'CONTINUOUS' }
];
</code></pre>
<p>Two details matter enormously when exporting <code>.DXF</code> files from wall centerlines:</p>
<ul>
<li><strong>Solid wall span splitting around openings:</strong> Before writing wall offset polylines, every wall is split into solid <code>WallSpan</code> segments around its doors and windows so jambs close cleanly instead of drawing wall lines straight across door swings.</li>
<li><strong>Native unit scaling (<code>$INSUNITS</code>):</strong> Plans drafted in US feet/inches export in true inches (<code>39.37007874 in/m</code>); metric plans export in exact millimeters (<code>1000 mm/m</code>), so measuring a 20'-0" garage wall in AutoCAD or LibreCAD reads <code>240.000000</code> with zero rescaling.</li>
</ul>
<h2>3. Generating Watertight 3D-Printable <code>.STL</code> Scale Models Without Boolean Crashes</h2>
<p>Homeowners planning a remodel, barndominium, or backyard ADU love seeing a physical scale model on their desk. Most architectural <code>.OBJ</code> exports fail in PrusaSlicer, OrcaSlicer, or Bambu Studio because walls have zero thickness, flipped normals, or unclosed gaps around windows.</p>
<p>Our binary <code>.STL</code> generator (<code>src/lib/exporters/stl.ts</code>) builds closed, Z-up, manifold geometry directly from the parametric wall graph:</p>
<ul>
<li>Enforces a minimum print wall thickness (<code>&gt;= 1.2 mm</code> at <code>1:50</code>, <code>1:100</code>, <code>1:150</code>, or <code>1:200</code>) so a 4.5" interior partition doesn't vanish under a 0.4 mm FDM nozzle.</li>
<li>Adds a solid <code>1.6 mm</code> structural baseplate so disconnected interior partitions stay anchored on the build plate.</li>
<li>Supports both <strong>stacked multi-story <code>.STL</code></strong> and <strong>split-by-floor lift-off <code>.STL</code> files</strong> for inspecting upper and lower stories of two-story homes.</li>
</ul>
<p>You can test the full pipeline with our free 40-file <a href="https://github.com/truedraftcad/truedraft-cad/releases">10-Plan Architectural Starter Pack on GitHub Releases</a> (10 plans × <code>.DXF</code>, <code>.OBJ</code>, <code>.STL</code>, and editable <code>.truedraft.json</code>).</p>
<h2>4. Open-Source + One-Time Pricing vs. Subscription Floor Plan Software</h2>
<p>We built TrueDraft CAD as a <a href="https://www.truedraftcad.com/floor-plan-software-no-subscription">zero-subscription floor plan software alternative</a> to monthly CAD suites:</p>
<ul>
<li><strong>100% Public Source (<code>GNU AGPL-3.0</code>):</strong> Audit the geometry engine, fork it, or self-host it from <a href="https://github.com/truedraftcad/truedraft-cad">github.com/truedraftcad/truedraft-cad</a>.</li>
<li><strong>Free Browser Studio (No Account Required):</strong> Draft unlimited walls, doors, windows, furniture, and multi-story levels, preview live 3D, run up to 2 free AI sketch/PDF traces per 24 hours, import existing <code>.DXF</code> plans (up to 1,200 walls with per-layer checkboxes), and download a watermarked proof PDF + <code>.truedraft.json</code> backup free.</li>
<li><strong>Optional One-Time Export Unlocks:</strong> Clean vector Blueprint PDF, AutoCAD <code>.DXF</code>, 3D <code>.OBJ</code>, watertight <code>.STL</code>, SVG, CSV takeoff, and 4K PNG unlock with a one-time payment starting at <strong>$9</strong> (Single Project) or <strong>$29</strong> (Pro Lifetime) — no recurring monthly billing, backed by a 14-day refund policy.</li>
</ul>
<h2>Try It in Your Browser or Inspect the Code</h2>
<ul>
<li><strong>Open the Free Browser CAD Studio:</strong> <a href="https://www.truedraftcad.com/studio">truedraftcad.com/studio</a></li>
<li><strong>Open-Source Architecture &amp; Comparison (vs Sweet Home 3D, LibreCAD, FreeCAD):</strong> <a href="https://www.truedraftcad.com/open-source">truedraftcad.com/open-source</a></li>
<li><strong>Convert a Hand Sketch or PDF to CAD &amp; 3D:</strong> <a href="https://www.truedraftcad.com/sketch-to-cad">truedraftcad.com/sketch-to-cad</a></li>
<li><strong>Source Code &amp; 10-Plan Starter Kit (<code>GNU AGPL-3.0</code>):</strong> <a href="https://github.com/truedraftcad/truedraft-cad">github.com/truedraftcad/truedraft-cad</a></li>
</ul>
<p>If you're building browser CAD tools, TypeScript geometry kernels, or parametric DXF/STL pipelines, feel free to check out the repository or open an issue with feedback!</p>
]]></content:encoded></item><item><title><![CDATA[Generating True-Scale Architectural Blueprint PDFs (1/4"=1', Arch D 24x36 & Schedules) in Browser TypeScript]]></title><description><![CDATA[Most browser-based floor plan apps take the easy shortcut when you click Export PDF: they rasterize an HTML5 <canvas> at 72 or 150 DPI and drop a PNG…]]></description><link>https://truedraftcad.hashnode.dev/generating-true-scale-architectural-blueprint-pdfs-1-4-1-arch-d-24x36-schedules-in-browser-typescript</link><guid isPermaLink="true">https://truedraftcad.hashnode.dev/generating-true-scale-architectural-blueprint-pdfs-1-4-1-arch-d-24x36-schedules-in-browser-typescript</guid><category><![CDATA[TypeScript]]></category><category><![CDATA[open source]]></category><category><![CDATA[cad]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[Web Development]]></category><dc:creator><![CDATA[Anders Kessler]]></dc:creator><pubDate>Fri, 04 Dec 2026 14:33:35 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6b0d835a7f7611369f197f73/e30aa775-007a-427b-b368-b5af17470a08.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Most browser-based floor plan apps take the easy shortcut when you click <strong>Export PDF</strong>: they rasterize an HTML5 <code>&lt;canvas&gt;</code> at 72 or 150 DPI and drop a PNG inside a Letter page.</p>
<p>Print that sheet at a copy shop and pull a triangular architectural scale ruler across it — nothing measures true. Walls blur when zoomed, doors turn into pixelated arcs, and a 24' kitchen run ends up reading 23'-5" on paper.</p>
<p>When we built <strong><a href="https://www.truedraftcad.com">TrueDraft CAD</a></strong> — an open-source (GNU AGPL-3.0) 2D/3D architectural floor plan studio that runs entirely in the browser — we wrote a pure-TypeScript vector PDF compiler (<code>src/lib/exporters/pdf.ts</code>) that plots directly in physical paper inches using <code>jsPDF</code>, with true architectural scales (<code>1/4" = 1'-0"</code>, <code>3/16" = 1'-0"</code>, <code>1/8" = 1'-0"</code>, <code>1:50</code>, <code>1:100</code>), double-line sheet borders, title blocks, and automatic <strong>Sheet A2.0</strong> Room/Door/Window schedules.</p>
<p>Here is how the math and layout pipeline works under the hood.</p>
<hr />
<h2>1. Work Internally in SI Meters, Plot Directly in Physical Inches</h2>
<p>The single worst bug in web CAD exporters is mixing CSS pixels with paper coordinates. Instead, TrueDraft stores every wall vertex, opening width, and fixture footprint in <strong>SI meters</strong> (snapping to <code>1/16"</code> or <code>10 mm</code> increments in the viewport), then initializes <code>jsPDF</code> with <code>unit: 'in'</code> on standard US architectural sheet sizes:</p>
<pre><code class="language-ts">const SHEET_SPECS: Record&lt;SheetSize, SheetSpec&gt; = {
  letter:  { widthIn: 11, heightIn: 8.5, label: 'Letter',        marginIn: 0.30, titleBlockW: 2.05, fontScale: 1.00 },
  tabloid: { widthIn: 17, heightIn: 11,  label: 'Tabloid 11×17', marginIn: 0.40, titleBlockW: 2.55, fontScale: 1.18 },
  arch_d:  { widthIn: 36, heightIn: 24,  label: 'Arch D 24×36',  marginIn: 0.55, titleBlockW: 3.80, fontScale: 1.65 }
};
</code></pre>
<p>Because <code>jsPDF</code> accepts raw physical inches, converting a model coordinate in meters to a paper offset in inches requires a single exact scalar — <code>inPerMeter</code>:</p>
<pre><code class="language-ts">const SCALE_TABLE: Record&lt;ArchitecturalScale, ScaleDef&gt; = {
  '1/4"=1\'':  { scale: '1/4"=1\'',  inPerMeter: 0.25   / 0.3048, label: '1/4" = 1\'-0"',  family: 'imperial' },
  '3/16"=1\'': { scale: '3/16"=1\'', inPerMeter: 0.1875 / 0.3048, label: '3/16" = 1\'-0"', family: 'imperial' },
  '1/8"=1\'':  { scale: '1/8"=1\'',  inPerMeter: 0.125  / 0.3048, label: '1/8" = 1\'-0"',  family: 'imperial' },
  '1:50':      { scale: '1:50',      inPerMeter: 1000 / 50  / 25.4, label: '1:50',         family: 'metric'   },
  '1:100':     { scale: '1:100',     inPerMeter: 1000 / 100 / 25.4, label: '1:100',        family: 'metric'   }
};
</code></pre>
<p>Notice the exact constants (<code>0.3048</code> m/ft and <code>25.4</code> mm/in): a <code>42'-0"</code> Craftsman cottage (<code>12.8016 m</code>) plotted at <code>1/4" = 1'-0"</code> measures <strong>exactly <code>10.500"</code></strong> on a Tabloid <code>11×17</code> sheet — zero DPI rounding drift.</p>
<hr />
<h2>2. Never Silently Clip a Building — Auto-Step Down Standard Scales</h2>
<p>A common surprise with fixed-scale printing is when a homeowner drafts a <code>60' × 40'</code> barndominium or a <code>52' × 30'</code> duplex and asks for <code>1/4" = 1'-0"</code> on an <code>8.5 × 11</code> Letter sheet (<code>60 × 0.25" = 15"</code> — wider than the paper!).</p>
<p>Silently shrinking to an arbitrary scale breaks the printed title block label (<code>SCALE: 1/4"=1'-0"</code> becomes a lie). Clipping walls off the margin ruins the sheet.</p>
<p>Our resolver tries the requested scale first against the available viewport (subtracting outer margins, double border, title block width, and exterior dimension-string padding). If it doesn't fit, it steps cleanly down standard architectural scales in the <strong>same unit family</strong> — and only falls back to <code>NTS (Auto-fitted)</code> when even <code>1/8" = 1'-0"</code> or <code>1:100</code> exceeds the sheet:</p>
<pre><code class="language-ts">const IMPERIAL_STEPDOWN: ArchitecturalScale[] = ['1/4"=1\'', '3/16"=1\'', '1/8"=1\''];
const METRIC_STEPDOWN: ArchitecturalScale[] = ['1:50', '1:100'];

function resolveSheetScale(
  requested: ArchitecturalScale,
  planW: number,
  planH: number,
  availW: number,
  availH: number,
  sheetLabel: string,
  fitToSheet: boolean
) {
  const maxFitInPerM = Math.min(availW / Math.max(0.5, planW), availH / Math.max(0.5, planH));
  if (fitToSheet) {
    return { inPerMeter: maxFitInPerM, actualScaleLabel: `NTS (Fitted to ${sheetLabel})`, scaleFitted: true };
  }

  const req = SCALE_TABLE[requested] ?? SCALE_TABLE['1/4"=1\''];
  if (planW * req.inPerMeter &lt;= availW + 1e-4 &amp;&amp; planH * req.inPerMeter &lt;= availH + 1e-4) {
    return { inPerMeter: req.inPerMeter, actualScaleLabel: req.label, scaleFitted: false };
  }

  const ladder = req.family === 'imperial' ? IMPERIAL_STEPDOWN : METRIC_STEPDOWN;
  for (const candidate of ladder) {
    const def = SCALE_TABLE[candidate];
    if (def.inPerMeter &gt;= req.inPerMeter) continue;
    if (planW * def.inPerMeter &lt;= availW + 1e-4 &amp;&amp; planH * def.inPerMeter &lt;= availH + 1e-4) {
      return {
        inPerMeter: def.inPerMeter,
        actualScaleLabel: `${def.label} (Auto-fitted to ${sheetLabel})`,
        scaleFitted: true
      };
    }
  }
  return { inPerMeter: maxFitInPerM, actualScaleLabel: `NTS (Auto-fitted to ${sheetLabel})`, scaleFitted: true };
}
</code></pre>
<p>Every time <code>resolveSheetScale</code> steps down, the title block's <code>SCALE</code> field and graphical scale bar update automatically so what is printed in the corner always matches what a ruler measures on paper.</p>
<hr />
<h2>3. Architectural Line-Weight Hierarchy in Inches</h2>
<p>Readable CAD blueprints depend on crisp stroke contrast, not color. On every sheet we enforce four distinct pen weights in physical inches (<code>pdf.setLineWidth(...)</code>):</p>
<table>
<thead>
<tr>
<th>Element</th>
<th>Pen Weight (in)</th>
<th>Visual Role</th>
</tr>
</thead>
<tbody><tr>
<td>Sheet outer border</td>
<td><code>0.022"</code></td>
<td>Anchors the drawing frame</td>
</tr>
<tr>
<td>Cut walls (filled mitered polygons)</td>
<td><code>0.014"</code> + dark poche</td>
<td>Primary architectural figure-ground</td>
</tr>
<tr>
<td>Doors, windows, cabinetry &amp; fixtures</td>
<td><code>0.008"</code></td>
<td>Secondary architectural symbols</td>
</tr>
<tr>
<td>Dimension strings, witness lines &amp; 45° ticks</td>
<td><code>0.005"</code></td>
<td>Clean technical annotation without clutter</td>
</tr>
</tbody></table>
<p>Room polygons are computed from our planar half-edge graph, then subtly tinted <code>22%</code> toward white (<code>tintTowardWhite(rgb, 0.22)</code>) so printed floor zones stay legible even on black-and-white laser plotters.</p>
<hr />
<h2>4. Multi-Story Packet Assembly (<code>Sheet A1.0</code>, <code>A1.1</code> &amp; <code>Sheet A2.0</code> Schedules)</h2>
<p>For multi-level buildings (like a <a href="https://www.truedraftcad.com/two-story-house-plan-maker">two-story house floor plan</a> with Ground + Upper + Basement levels), clicking <strong>Export All Floors</strong> generates one continuous vector PDF packet:</p>
<ol>
<li><strong>Sheet A1.0 (<code>Level 1 · Ground</code>)</strong>, <strong>Sheet A1.1 (<code>Level 2 · Upper</code>)</strong>, <strong>Sheet A1.2 (<code>Level B1 · Basement</code>)</strong> — each level plotted at consistent architectural scale with synced stair footprints, North arrow, and sheet index (<code>SHEET 1 OF 4</code>).</li>
<li><strong>Sheet A2.0 (<code>Schedules &amp; Material Takeoff</code>)</strong> — deterministic multi-column tables listing every room's net square footage &amp; perimeter, complete door/window schedules with rough-opening sizes, drywall sheet counts (<code>4×8</code> sheets with <code>10%</code> waste factor), framing lumber linear feet, and flooring areas.</li>
</ol>
<hr />
<h2>Try It Live (Zero Signup) &amp; Read the Source</h2>
<p>You can test the full vector PDF compiler right now in your browser — draw walls, load a <a href="https://www.truedraftcad.com/kitchen-floor-plan-maker">kitchen remodel</a> or <a href="https://www.truedraftcad.com/free-blueprint-maker">free blueprint template</a>, switch to the <strong>Blueprint</strong> tab, and download a free Watermarked Proof PDF immediately with no account required:</p>
<ul>
<li><strong>Launch Free Browser CAD Studio:</strong> <a href="https://www.truedraftcad.com/studio">https://www.truedraftcad.com/studio</a></li>
<li><strong>Free Blueprint Maker &amp; Scale Guide:</strong> <a href="https://www.truedraftcad.com/free-blueprint-maker">https://www.truedraftcad.com/free-blueprint-maker</a></li>
<li><strong>Full AGPL-3.0 Source Code (<code>src/lib/exporters/pdf.ts</code>):</strong> <a href="https://github.com/truedraftcad/truedraft-cad">https://github.com/truedraftcad/truedraft-cad</a></li>
</ul>
<p><em>(Need clean unwatermarked sheets, AIA-layered AutoCAD <code>.DXF</code>, 3D <code>.OBJ</code>, or watertight 3D-print <code>.STL</code> scale models? One-time unlocks start at <code>$9</code> — zero recurring subscriptions.)</em></p>
]]></content:encoded></item><item><title><![CDATA[Turning a Hand-Drawn Sketch or PDF Blueprint Into Snapped CAD Walls, .DXF, and Watertight 3D Meshes in TypeScript]]></title><description><![CDATA[How we clean noisy vision-extracted floor plan coordinates into closed rooms with union-find corner snapping, orthogonal intersections, and ear-clipped 3D…]]></description><link>https://truedraftcad.hashnode.dev/turning-a-hand-drawn-sketch-or-pdf-blueprint-into-snapped-cad-walls-dxf-and-watertight-3d-meshes-in-typescript</link><guid isPermaLink="true">https://truedraftcad.hashnode.dev/turning-a-hand-drawn-sketch-or-pdf-blueprint-into-snapped-cad-walls-dxf-and-watertight-3d-meshes-in-typescript</guid><category><![CDATA[TypeScript]]></category><category><![CDATA[cad]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[Open Source]]></category><dc:creator><![CDATA[Anders Kessler]]></dc:creator><pubDate>Fri, 04 Dec 2026 10:13:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6b0d835a7f7611369f197f73/bd1728ac-2398-4f8e-a228-832bacde970b.jpg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Vision models can read a scanned floor plan or hand-drawn graph-paper sketch and return a list of wall segments, doors, and room labels in a few seconds. The hard part is what happens next.</p>
<p>Raw vision output is almost never CAD-ready. Walls that are supposed to be horizontal drift by 3 to 7 degrees. Adjacent exterior corners miss each other by 15 cm, which leaves rooms unclosed so automated square-footage and floor-slab detection fail. Duplicate lines sit on top of one another along thick masonry borders. Doors float slightly off the centerline of the wall they belong to.</p>
<p>In <a href="https://www.truedraftcad.com">TrueDraft CAD</a> (an open-source AGPL-3.0 browser CAD studio built in SvelteKit and TypeScript), we solve this with a deterministic post-processing pipeline (<code>src/lib/server/trace.ts</code>) paired with a zero-dependency 3D prism and ear-clipping mesh builder (<code>src/lib/exporters/obj.ts</code>). Every step is pure geometry, covered by unit tests, and produces editable 2D walls that export straight to AutoCAD <code>.DXF</code>, scaled <code>.PDF</code> blueprints, <code>.OBJ</code>/<code>.GLB</code>, and 3D-printable <code>.STL</code> scale models.</p>
<p>Here is how the geometry pipeline works, step by step.</p>
<h2>Watch the full Sketch/PDF to .DXF &amp; 3D walkthrough</h2>
<p><a class="embed-card" href="https://youtu.be/N8re7-DuOVw">https://youtu.be/N8re7-DuOVw</a></p>

<h2>Step 1: Calibrated scaling and ±12° axis snapping</h2>
<p>Before touching coordinates, the user sets one real-world calibration dimension (overall footprint width or a known wall span) so normalized <code>[0, 1]</code> coordinates map cleanly into meters.</p>
<p>Next, each candidate wall segment is checked against the horizontal (<code>0°</code>) and vertical (<code>90°</code>) axes using a <code>±12°</code> threshold (<code>ANGLE_SNAP_DEG = 12</code>):</p>
<pre><code class="language-ts">const ANGLE_SNAP_DEG = 12;
const ENDPOINT_CLUSTER_M = 0.25;
const MIN_WALL_LENGTH_M = 0.3;
const DUPLICATE_TOL_M = 0.15;

// Snap near-horizontal and near-vertical walls to exact axes
const absAngleDeg = Math.abs((Math.atan2(dy, dx) * 180) / Math.PI);
let axis: 'h' | 'v' | 'd' = 'd';

if (absAngleDeg &lt;= ANGLE_SNAP_DEG || absAngleDeg &gt;= 180 - ANGLE_SNAP_DEG) {
	const midY = (y1 + y2) / 2;
	y1 = midY;
	y2 = midY;
	axis = 'h';
} else if (absAngleDeg &gt;= 90 - ANGLE_SNAP_DEG) {
	const midX = (x1 + x2) / 2;
	x1 = midX;
	x2 = midX;
	axis = 'v';
}
</code></pre>
<p>Snapping to <code>midY</code> or <code>midX</code> preserves the wall's centroid instead of pivoting around one arbitrary end. Diagonal walls (45-degree bay windows, angled garage entries, chamfered corners) sit outside the <code>±12°</code> band and keep their true slope with <code>axis = 'd'</code>.</p>
<h2>Step 2: Union-find endpoint clustering with exact orthogonal corners</h2>
<p>If you average endpoints naively inside a small radius, an L-shaped corner drifts slightly inward and knocks both walls off axis by a few millimeters. That breaks downstream rectilinear snapping and creates hairline gaps in room polygons.</p>
<p>We collect every wall endpoint into a flat array, cluster points within <code>0.25 m</code> (<code>ENDPOINT_CLUSTER_M</code>) using union-find with path compression, and treat horizontal-meets-vertical clusters specially:</p>
<pre><code class="language-ts">let cx = sumX / members.length;
let cy = sumY / members.length;

// When horizontal and vertical walls meet at a corner, snap to their exact
// orthogonal intersection if it stays within the cluster tolerance.
if (hCount &gt; 0 &amp;&amp; vCount &gt; 0) {
	const ix = vSumX / vCount;
	const iy = hSumY / hCount;
	if (Math.hypot(ix - cx, iy - cy) &lt;= ENDPOINT_CLUSTER_M) {
		cx = ix;
		cy = iy;
	}
}
</code></pre>
<p>When a horizontal wall and a vertical wall meet, <code>(vSumX / vCount, hSumY / hCount)</code> is their exact 90-degree intersection. Both walls stay perfectly orthogonal, their endpoints share identical floating-point coordinates, and our planar half-edge room detector immediately closes every room boundary to compute accurate square footage.</p>
<p>After clustering, we drop stub fragments shorter than <code>0.3 m</code> (<code>MIN_WALL_LENGTH_M</code>) and collapse forward or reversed duplicate segments within <code>0.15 m</code> (<code>DUPLICATE_TOL_M</code>), keeping <code>exterior = true</code> whenever either duplicate came from the perimeter envelope. Standard US framing defaults are applied right away: <code>6"</code> (<code>0.1524 m</code>) exterior walls, <code>4.5"</code> (<code>0.1143 m</code>) interior partitions, and <code>9'-0"</code> (<code>2.7432 m</code>) ceiling height.</p>
<h2>Step 3: Projecting doors and windows onto wall centerlines</h2>
<p>Extracted openings rarely land cleanly on a snapped wall centerline. Instead of rejecting them, we project each opening's <code>(x, y)</code> point orthogonally onto the nearest cleaned wall within <code>maxSnapDist = Math.max(0.6, widthM * 0.08)</code> and clamp its parametric position <code>t</code> to <code>[0.1, 0.9]</code>:</p>
<pre><code class="language-ts">for (const w of walls) {
	const { t, dist } = projectPointToSegment(ox, oy, w.x1, w.y1, w.x2, w.y2);
	if (dist &lt; bestDist) {
		bestDist = dist;
		bestWall = w;
		bestT = t;
	}
}
</code></pre>
<p>Clamping <code>t</code> keeps doors and windows away from corner miters so jambs do not intersect perpendicular walls. Each opening gets an architectural schedule tag (<code>D1</code>, <code>D2</code>, <code>W1</code>, <code>W2</code>), standard width defaults (<code>36"</code> doors, <code>48"</code> windows, <code>60"</code> sliders/double doors), and a <code>36"</code> (<code>0.9144 m</code>) sill height for windows.</p>
<h2>Step 4: Carving real 3D door and window cutouts without a CSG library</h2>
<p>Once walls and openings live in the unified vector plan, converting the same data model into a clean <code>.OBJ</code>, <code>.GLB</code>, or watertight <code>.STL</code> scale model does not require shipping a heavy WebAssembly CSG boolean kernel to the browser.</p>
<p>In <code>src/lib/exporters/obj.ts</code>, each wall is parameterized along its unit vector <code>(ux, uy)</code> from <code>s = 0</code> to <code>s = len</code>. Every opening attached to that wall becomes a sorted interval <code>[s0, s1]</code>. Walking <code>cursor</code> from <code>0</code> to <code>len</code> emits strictly manifold quad prisms:</p>
<ol>
<li><strong>Solid wall pier</strong> from <code>cursor</code> to <code>segStart</code> covering <code>[y0, y0 + wallH]</code>.</li>
<li><strong>Window sill prism</strong> from <code>segStart</code> to <code>segEnd</code> covering <code>[y0, y0 + sillH]</code> whenever <code>sillH &gt; 0</code>.</li>
<li><strong>Header / lintel prism</strong> from <code>segStart</code> to <code>segEnd</code> covering <code>[y0 + headH, y0 + wallH]</code> whenever <code>headH &lt; wallH</code>.</li>
<li><strong>Final pier</strong> from <code>cursor</code> to <code>len</code> covering <code>[y0, y0 + wallH]</code>.</li>
</ol>
<pre><code class="language-ts">if (segEnd &gt; segStart + 1e-4) {
	const sillH = Math.max(0, Math.min(wallH, safeNum(slice.opening.sillHeight)));
	const headH = Math.max(sillH, Math.min(wallH, sillH + safeNum(slice.opening.height)));

	if (sillH &gt; 1e-4) {
		builder.addSegmentPrism(ptAt(segStart), ptAt(segEnd), halfT, y0, y0 + sillH);
	}
	if (wallH - headH &gt; 1e-4) {
		builder.addSegmentPrism(ptAt(segStart), ptAt(segEnd), halfT, y0 + headH, y0 + wallH);
	}
}
</code></pre>
<p>For room floor slabs, we triangulate arbitrary concave polygons (L-shaped living/dining rooms, U-shaped kitchens, hallways around closets) with a compact ear-clipping triangulator (<code>triangulatePolygon</code>) normalized to right-handed Y-up winding (<code>z = y_plan</code>, negative 2D signed area for upward <code>+Y</code> normals). Every triangle faces outward, which means zero flipped normals in Blender, SketchUp, Bambu Studio, PrusaSlicer, or Cura.</p>
<h2>Try it free on your own sketch, PDF, or photo</h2>
<p>No account is required to test the full pipeline on your own drawing. The free tier includes 2 AI traces per 24 hours, unlimited manual 2D/3D drafting, <code>.DXF</code> import with layer filtering, live 3D cutaway viewing, and watermarked proof PDF export:</p>
<ul>
<li><strong>Trace a hand-drawn sketch into CAD walls:</strong> <a href="https://www.truedraftcad.com/sketch-to-cad">truedraftcad.com/sketch-to-cad</a></li>
<li><strong>Convert a 2D blueprint or image to an interactive 3D cutaway:</strong> <a href="https://www.truedraftcad.com/blueprint-to-3d">truedraftcad.com/blueprint-to-3d</a></li>
<li><strong>PDF floor plan to layered AutoCAD .DXF guide:</strong> <a href="https://www.truedraftcad.com/pdf-floor-plan-to-dxf">truedraftcad.com/pdf-floor-plan-to-dxf</a></li>
<li><strong>Export watertight architectural .STL scale models for 3D printing:</strong> <a href="https://www.truedraftcad.com/floor-plan-to-stl">truedraftcad.com/floor-plan-to-stl</a></li>
<li><strong>Read the full AGPL-3.0 TypeScript source (<code>src/lib/server/trace.ts</code> and <code>src/lib/exporters/obj.ts</code>):</strong> <a href="https://github.com/truedraftcad/truedraft-cad">github.com/truedraftcad/truedraft-cad</a></li>
</ul>
<p>If you hit a tricky angled plan, multi-wing commercial blueprint, or slicer edge case, open an issue on GitHub with a minimal repro and we will add a regression test to the suite.</p>
]]></content:encoded></item><item><title><![CDATA[Planar Half-Edge Room Polygon Detection & Real-Time Material Takeoffs in Browser CAD (TypeScript)]]></title><description><![CDATA[Most web floor plan apps force users to draw rooms as isolated boxes. The moment you sketch an L-shaped hallway, split a bedroom with a T-junction…]]></description><link>https://truedraftcad.hashnode.dev/planar-half-edge-room-polygon-detection-real-time-material-takeoffs-in-browser-cad-typescript</link><guid isPermaLink="true">https://truedraftcad.hashnode.dev/planar-half-edge-room-polygon-detection-real-time-material-takeoffs-in-browser-cad-typescript</guid><category><![CDATA[TypeScript]]></category><category><![CDATA[open source]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[cad]]></category><category><![CDATA[architecture]]></category><dc:creator><![CDATA[Anders Kessler]]></dc:creator><pubDate>Fri, 04 Dec 2026 08:13:53 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6b0d835a7f7611369f197f73/356b7f86-5d72-4103-993b-3e6edfac1c5a.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Most web floor plan apps force users to draw rooms as isolated boxes. The moment you sketch an L-shaped hallway, split a bedroom with a T-junction partition wall, or import an existing <code>.DXF</code> blueprint, box-based room tools break down.</p>
<p>In <a href="https://www.truedraftcad.com/">TrueDraft CAD</a> — an <a href="https://www.truedraftcad.com/open-source">open-source (AGPL-3.0) browser CAD studio</a> (<a href="https://github.com/truedraftcad/truedraft-cad">GitHub</a>) built as a <a href="https://www.truedraftcad.com/floor-plan-software-no-subscription">zero-subscription alternative to desktop floor plan software</a> — users draw freeform walls, trace sketches, or import layered <code>.DXF</code> plans, and the geometry engine automatically detects enclosed rooms, places readable room labels inside concave L-shapes, computes clean wall miter joins, and updates framing/drywall/paint takeoffs in real time on every drag frame.</p>
<p>Here is how the pure-TypeScript planar half-edge geometry engine in <code>src/lib/cad/geometry.ts</code> works with zero native/WASM dependencies.</p>
<hr />
<h2>1. Planarizing Freeform Walls (Snapping, T-Junctions, and Crossings)</h2>
<p>Users rarely terminate every interior partition cleanly at another wall's vertex. They drag a new partition straight into the midpoint of an existing exterior wall (a T-junction), or cross two walls when laying out a hallway. Before we can extract faces, we have to turn a raw <code>Wall[]</code> list into a proper planar graph:</p>
<ol>
<li><strong>Endpoint snapping (<code>SNAP_TOL</code>)</strong>: Merge endpoints within tolerance into shared vertex indices.</li>
<li><strong>T-junction splitting</strong>: For every vertex $v$ that lies within <code>SNAP_TOL</code> of the interior of segment $(a, b)$, record a parametric split \(t \in (0, 1)\) on that segment.</li>
<li><strong>Crossing splits</strong>: For every pair of segments with a proper intersection \((t, u) \in (0, 1)^2\), create a new vertex at the intersection and record split points on both segments.</li>
<li><strong>Dangling-edge pruning</strong>: Iteratively strip degree-1 vertices (stub walls or partial dividers) so open spurs never corrupt cycle traversal.</li>
</ol>
<pre><code class="language-ts">function segmentIntersection(
	a: Point2D,
	b: Point2D,
	c: Point2D,
	d: Point2D
): { t: number; u: number; point: Point2D } | null {
	const rX = b.x - a.x;
	const rY = b.y - a.y;
	const sX = d.x - c.x;
	const sY = d.y - c.y;
	const denom = rX * sY - rY * sX;
	if (Math.abs(denom) &lt; 1e-9) return null;

	const qpX = c.x - a.x;
	const qpY = c.y - a.y;
	const t = (qpX * sY - qpY * sX) / denom;
	const u = (qpX * rY - qpY * rX) / denom;

	if (t &gt; 1e-4 &amp;&amp; t &lt; 1 - 1e-4 &amp;&amp; u &gt; 1e-4 &amp;&amp; u &lt; 1 - 1e-4) {
		return { t, u, point: { x: a.x + rX * t, y: a.y + rY * t } };
	}
	return null;
}
</code></pre>
<hr />
<h2>2. Walking Minimal Cycles via Twin Half-Edges</h2>
<p>Once split segments are deduplicated into undirected edges, we emit two directed half-edges (\(u \to v\) and its twin \(v \to u\)) per edge and sort every vertex's outgoing half-edges counter-clockwise by <code>Math.atan2(dy, dx)</code>.</p>
<p>To trace minimal faces, at each vertex we take the <strong>sharpest left turn</strong> from the incoming edge's twin: <code>(twinIdx - 1 + outList.length) % outList.length</code>.</p>
<pre><code class="language-ts">const posInOutgoing = new Int32Array(halfEdges.length);
for (const list of outgoing.values()) {
	list.sort((a, b) =&gt; halfEdges[a].angle - halfEdges[b].angle);
	for (let i = 0; i &lt; list.length; i++) {
		posInOutgoing[list[i]] = i;
	}
}

for (let startId = 0; startId &lt; halfEdges.length; startId++) {
	if (visited[startId]) continue;

	const cycleNodeIds: number[] = [];
	let curr = startId;
	let steps = 0;
	let closed = false;

	while (steps &lt;= halfEdges.length + 1) {
		if (visited[curr]) {
			closed = curr === startId;
			break;
		}
		visited[curr] = 1;
		const he = halfEdges[curr];
		cycleNodeIds.push(he.from);

		const outList = outgoing.get(he.to);
		if (!outList || outList.length === 0) break;
		const twinIdx = posInOutgoing[he.twin];
		const nextIdx = (twinIdx - 1 + outList.length) % outList.length;
		curr = outList[nextIdx];
		steps++;
	}

	if (!closed || cycleNodeIds.length &lt; 3) continue;

	const poly = cycleNodeIds.map((idx) =&gt; ({ x: nodes[idx].x, y: nodes[idx].y }));
	const signedArea = polygonSignedArea(poly);

	// Bounded interior rooms have positive signed area;
	// the outer building silhouette has negative signed area and is skipped.
	if (signedArea &lt;= MIN_ROOM_AREA_SQM) continue;
	// ...
}
</code></pre>
<p>The shoelace signed area automatically separates enclosed rooms (positive area) from the unbounded exterior perimeter face (negative area) in \(O(E \log E)\) time — fast enough to run continuously at 60 FPS while dragging walls in the browser.</p>
<hr />
<h2>3. Concave Room Label Placement (<code>polygonVisualCenter</code>)</h2>
<p>Standard polygon centroids fail badly on L-shaped hallways and U-shaped kitchens: the geometric centroid frequently lands <em>outside</em> the room, floating on top of an adjacent bathroom or exterior wall.</p>
<p>Instead, <code>polygonVisualCenter(poly)</code> samples an adaptive interior grid inside the room's bounding box, filters candidate points with <code>pointInPolygon</code>, and maximizes the minimum distance to all polygon edges (<code>minEdgeDist</code>), then runs a local refinement pass. The result guarantees every room label ("Living Room · 312 sq ft") stays centered cleanly inside the widest walkable area of the room — both on screen and in exported <a href="https://www.truedraftcad.com/blueprint-to-3d">blueprint-to-3D &amp; vector PDF sheets</a>.</p>
<hr />
<h2>4. Bounded Wall Miter Joins (<code>computeWallPolygons</code>)</h2>
<p>Centerline walls look crude in 2D architectural drawings and leave triangular gaps at corners in 3D extrusions. <code>computeWallPolygons(walls)</code> groups walls meeting at shared endpoints, intersects their offset left/right face lines with adjacent walls, and clamps acute angles to <code>maxMiter = Math.max(selfHalfThick, adj.halfThick) * 2.5</code> so sharp bay-window or angled-wall joins never shoot spikes across the drawing:</p>
<pre><code class="language-ts">const maxMiter = Math.max(selfHalfThick, adj.halfThick) * 2.5;
if (dist(hit, endpoint) &gt; maxMiter) {
	return fallback;
}
return hit;
</code></pre>
<hr />
<h2>5. Live Framing, Drywall &amp; Paint Takeoffs with Opening Deductions</h2>
<p>Because doors and windows are stored parametrically along their host wall (<code>wallId</code>, normalized position <code>t</code>, <code>width</code>, <code>height</code>, <code>sillHeight</code>), <code>computeTakeoff(plan, rooms)</code> recalculates real construction quantities in milliseconds:</p>
<ul>
<li><strong>Exterior walls</strong> count 1 interior drywall face (<code>sides = 1</code>); <strong>interior partitions</strong> count both faces (<code>sides = 2</code>).</li>
<li>Every door and window opening on a wall is subtracted from <code>len * w.height</code> before multiplying by <code>sides</code>.</li>
<li>Drywall adds a standard 10% cut-waste factor and divides by 4×8 ft sheet area (<code>2.9729 m²</code>).</li>
<li>Two-coat interior paint computes <code>Math.ceil((rawDrywallSqM * 10.7639 * 2) / 350)</code> gallons.</li>
<li>Door (<code>D1, D2...</code>) and Window (<code>W1, W2...</code>) schedules sort deterministically and stay synchronized across the live Studio sidebar, Sheet A2.0 PDF schedules, and CSV takeoff exports.</li>
</ul>
<pre><code class="language-ts">const sides = w.exterior ? 1 : 2;
const grossFaceSqM = len * w.height;
const wallOpenings = openingsByWall.get(w.id) ?? [];
const openingSqM = wallOpenings.reduce((s, o) =&gt; s + o.width * o.height, 0);
rawDrywallSqM += Math.max(0, grossFaceSqM - openingSqM) * sides;
</code></pre>
<hr />
<h2>Try It Live or Inspect the Source</h2>
<p>You can test the half-edge room detector, wall miter engine, <a href="https://www.truedraftcad.com/sketch-to-cad">sketch-to-CAD tracing</a>, and real-time material takeoffs immediately in the browser with zero signup:</p>
<ul>
<li><strong>Interactive 2D/3D Studio:</strong> <a href="https://www.truedraftcad.com/studio">https://www.truedraftcad.com/studio</a></li>
<li><strong>No-Subscription Floor Plan Software Comparison:</strong> <a href="https://www.truedraftcad.com/floor-plan-software-no-subscription">https://www.truedraftcad.com/floor-plan-software-no-subscription</a></li>
<li><strong>AGPL-3.0 Source Code (<code>src/lib/cad/geometry.ts</code>):</strong> <a href="https://github.com/truedraftcad/truedraft-cad">https://github.com/truedraftcad/truedraft-cad</a></li>
</ul>
<p><em>(Watch a 38-second walkthrough of TrueDraft CAD exporting multi-story &amp; barndominium plans to DXF, PDF, and 3D-print STL: <a href="https://youtu.be/XpJcYWnkOZw">https://youtu.be/XpJcYWnkOZw</a>)</em></p>
]]></content:encoded></item><item><title><![CDATA[Converting Multi-Page PDF Floor Plans to Layered AutoCAD R12 .DXF in the Browser (PDF.js + TypeScript)]]></title><description><![CDATA[Homeowners, remodelers, and builders almost always start with the same file: a flattened PDF floor plan from a developer brochure, real estate listing, or…]]></description><link>https://truedraftcad.hashnode.dev/converting-multi-page-pdf-floor-plans-to-layered-autocad-r12-dxf-in-the-browser-pdf-js-typescript</link><guid isPermaLink="true">https://truedraftcad.hashnode.dev/converting-multi-page-pdf-floor-plans-to-layered-autocad-r12-dxf-in-the-browser-pdf-js-typescript</guid><category><![CDATA[TypeScript]]></category><category><![CDATA[Svelte]]></category><category><![CDATA[open source]]></category><category><![CDATA[Web Development]]></category><dc:creator><![CDATA[Anders Kessler]]></dc:creator><pubDate>Thu, 03 Dec 2026 19:56:41 GMT</pubDate><content:encoded><![CDATA[<p>Homeowners, remodelers, and builders almost always start with the same file: a flattened PDF floor plan from a developer brochure, real estate listing, or older permit packet. Turning that PDF into an editable, true-scale AutoCAD <code>.DXF</code> normally means installing heavy desktop vectorization software, paying a monthly CAD subscription, or waiting two days for a manual redraw.</p>
<p>In <a href="https://www.truedraftcad.com/">TrueDraft CAD</a> (open-source under AGPL-3.0 on <a href="https://github.com/truedraftcad/truedraft-cad">GitHub</a>), we built the full PDF-to-CAD pipeline directly in the browser using lazy-loaded <code>pdfjs-dist</code>, an orthogonal wall-graph model, single-dimension scale calibration, and a pure-TypeScript AutoCAD R12 <code>.DXF</code> compiler. Here are the concrete engineering details that made multi-page PDF floor plan conversion fast, memory-safe, and reliable on Mac, Windows, Chromebook, and Linux.</p>
<hr />
<h2>1. Lazy-Loading <code>pdfjs-dist</code> Only When a User Drops a <code>.PDF</code></h2>
<p>Shipping PDF.js in the initial studio bundle adds unnecessary startup weight for users drafting from scratch or starting from a starter template. Instead, <code>src/lib/studio/TraceModal.svelte</code> dynamically imports both <code>pdfjs-dist</code> and its worker URL only the first time a <code>.pdf</code> file is dropped or selected:</p>
<pre><code class="language-ts">let pdfjsPromise: Promise&lt;typeof import('pdfjs-dist')&gt; | null = null;

function loadPdfJs(): Promise&lt;typeof import('pdfjs-dist')&gt; {
	if (!pdfjsPromise) {
		pdfjsPromise = Promise.all([
			import('pdfjs-dist'),
			import('pdfjs-dist/build/pdf.worker.min.mjs?url')
		])
			.then(([pdfjs, workerMod]) =&gt; {
				pdfjs.GlobalWorkerOptions.workerSrc = workerMod.default;
				return pdfjs;
			})
			.catch((err) =&gt; {
				pdfjsPromise = null;
				throw err;
			});
	}
	return pdfjsPromise;
}
</code></pre>
<p>Clearing <code>pdfjsPromise = null</code> inside <code>.catch()</code> prevents a transient network hiccup from poisoning retries for the rest of the session.</p>
<hr />
<h2>2. Race-Safe Multi-Page Sheet Rendering Without Memory Leaks</h2>
<p>Architectural PDF packets routinely contain 8 to 20 sheets (cover page, site plan, Level 1 floor plan, Level 2 floor plan, elevations). Users click rapidly through page thumbnails until they find the floor plan sheet they actually want to trace.</p>
<p>Two bugs bite almost every naive PDF.js viewer:</p>
<ol>
<li><strong>Out-of-order page paints:</strong> Page 2 finishes rendering <em>after</em> Page 4, overwriting the preview with the wrong floor.</li>
<li><strong>Canvas and PDF page memory leaks:</strong> Repeatedly calling <code>pdfDoc.getPage(n)</code> without <code>page.cleanup()</code> and <code>loadingTask.destroy()</code> spikes RAM quickly on Safari and Chromebooks.</li>
</ol>
<p>Our renderer solves both with a monotonic <code>pdfRenderToken</code>, bounded viewport scaling (<code>maxW = 1600</code>, <code>maxH = 2200</code>, <code>scale</code> clamped to <code>0.5..4</code>), an explicit opaque white fill (architectural CAD PDFs frequently have transparent backgrounds that look black if encoded straight to JPEG), and deterministic cleanup in <code>finally</code> and <code>onDestroy</code>:</p>
<pre><code class="language-ts">async function renderPdfPage(pageNum: number): Promise&lt;void&gt; {
	if (!pdfDoc) return;
	const token = ++pdfRenderToken;
	pdfRendering = true;

	try {
		const page = await pdfDoc.getPage(pageNum);
		if (token !== pdfRenderToken || !pdfDoc) {
			page.cleanup();
			return;
		}

		try {
			const baseViewport = page.getViewport({ scale: 1 });
			const scale = Math.max(
				0.5,
				Math.min(1600 / baseViewport.width, 2200 / baseViewport.height, 4)
			);
			const viewport = page.getViewport({ scale });

			const canvas = document.createElement('canvas');
			canvas.width = Math.max(1, Math.round(viewport.width));
			canvas.height = Math.max(1, Math.round(viewport.height));
			const ctx = canvas.getContext('2d');
			if (!ctx) throw new Error('Canvas 2D context unavailable.');

			ctx.fillStyle = '#FFFFFF';
			ctx.fillRect(0, 0, canvas.width, canvas.height);
			await page.render({ canvas, viewport, background: '#FFFFFF' }).promise;
			if (token !== pdfRenderToken) return;

			imageDataUrl = canvas.toDataURL('image/jpeg', 0.82);
		} finally {
			page.cleanup();
		}
	} finally {
		if (token === pdfRenderToken) {
			pdfRendering = false;
		}
	}
}
</code></pre>
<p>Because rendering runs completely client-side inside the browser tab, multi-page permit PDFs never need to be stored on a server just to pick a sheet.</p>
<hr />
<h2>3. Why Single-Dimension Scale Calibration Beats Guessed Pixel DPI</h2>
<p>A PDF exported from a real estate flyer rarely preserves a strict <code>1/4" = 1'</code> physical scale after cropping or print-to-PDF margins. Rather than trusting PDF media-box points blindly, we keep internal CAD geometry strictly in meters and let the user calibrate against any known reference span (for example, an overall building width like <code>40'-0"</code> or a standard <code>3'-0"</code> exterior entry door).</p>
<p>Once traced walls and openings land on the 2D drafting grid, every wall stays live and parametric:</p>
<ul>
<li>Drag any corner node and connected walls re-miter cleanly.</li>
<li>Toggle <strong>Split 2D + 3D</strong> to verify ceiling heights, door swings, and window sill elevations immediately in Three.js WebGL.</li>
<li>Live room cycle detection recomputes net square footage and exterior/interior wall linear footage automatically.</li>
</ul>
<hr />
<h2>4. Compiling Clean AIA-Layered AutoCAD R12 <code>.DXF</code> in Pure TypeScript</h2>
<p>Opening a traced floor plan inside AutoCAD, LibreCAD, QCAD, BricsCAD, or Rhino only feels clean when every entity lands on standard architectural layers with true 1:1 model-space coordinates (inches for US imperial plans, millimeters for metric plans).</p>
<p>In <code>src/lib/exporters/dxf.ts</code>, we emit an ASCII AutoCAD R12 (<code>AC1009</code>) file with an explicit <code>TABLES -&gt; LAYER</code> table covering standard AIA architectural layers:</p>
<table>
<thead>
<tr>
<th>Layer</th>
<th>ACI Color</th>
<th>Entities Written</th>
</tr>
</thead>
<tbody><tr>
<td><code>A-WALL</code></td>
<td>7 (White/Black)</td>
<td>Exterior wall boundary polygons and segments</td>
</tr>
<tr>
<td><code>A-WALL-INTR</code></td>
<td>8 (Dark Gray)</td>
<td>Interior partition walls</td>
</tr>
<tr>
<td><code>A-DOOR</code></td>
<td>30 (Orange)</td>
<td>Door frames, leaf lines, and 90-degree swing arcs</td>
</tr>
<tr>
<td><code>A-GLAZ</code></td>
<td>5 (Blue)</td>
<td>Window jambs, glazing bars, and sills</td>
</tr>
<tr>
<td><code>A-FURN</code></td>
<td>9 (Light Gray)</td>
<td>Architectural furniture and fixture blocks</td>
</tr>
<tr>
<td><code>A-ELEC</code> / <code>A-PLMB</code></td>
<td>2 / 4</td>
<td>Electrical panels, outlets, and plumbing fixtures</td>
</tr>
<tr>
<td><code>A-AREA</code></td>
<td>3 (Green)</td>
<td>Closed room boundary polylines</td>
</tr>
<tr>
<td><code>A-ANNO-DIMS</code></td>
<td>1 (Red)</td>
<td>Dimension extension lines, tick marks, and text</td>
</tr>
<tr>
<td><code>A-ANNO-TEXT</code></td>
<td>7 (White/Black)</td>
<td>Room labels, area callouts, and title notes</td>
</tr>
</tbody></table>
<p>Writing ASCII R12 (<code>AC1009</code>) directly with explicit <code>safeNum()</code> finite checks and <code>sanitizeDxfText()</code> line-break stripping avoids binary handle corruption and opens cleanly across every desktop CAD package from AutoCAD 2026 down to lightweight open-source viewers like LibreCAD and QCAD.</p>
<hr />
<h2>Watch It in Action &amp; Try It Free</h2>
<p>Watch our 38-second walkthrough editing a 60x40 Barndominium and a 960 sq ft Backyard ADU in 2D and live 3D cutaway before exporting scaled Blueprint PDFs, AutoCAD <code>.DXF</code>, and watertight 3D-printable <code>.STL</code> scale models:</p>
<p><a class="embed-card" href="https://youtu.be/XpJcYWnkOZw">https://youtu.be/XpJcYWnkOZw</a></p>

<p>Try the PDF-to-DXF workflow free in your browser (zero signup required to draft, inspect in 3D, or run 2 free AI traces per 24 hours; optional one-time clean export unlock from $9 with zero subscription):</p>
<ul>
<li><strong>Convert PDF Floor Plan to AutoCAD .DXF:</strong> <a href="https://www.truedraftcad.com/pdf-floor-plan-to-dxf">truedraftcad.com/pdf-floor-plan-to-dxf</a></li>
<li><strong>Open Studio Trace Tool directly:</strong> <a href="https://www.truedraftcad.com/studio?trace=1">truedraftcad.com/studio?trace=1</a></li>
<li><strong>Mac, Chromebook &amp; Linux Browser CAD Guide:</strong> <a href="https://www.truedraftcad.com/floor-plan-software-for-mac">truedraftcad.com/floor-plan-software-for-mac</a></li>
<li><strong>Full Open-Source Repository (AGPL-3.0):</strong> <a href="https://github.com/truedraftcad/truedraft-cad">github.com/truedraftcad/truedraft-cad</a></li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Why 400 Walls Wasn't Enough: Interactive AutoCAD .DXF Layer Filtering in Pure TypeScript]]></title><description><![CDATA[If you build a browser CAD importer, clean test fixtures will lie to you. When we shipped our pure-TypeScript ASCII AutoCAD .DXF importer (R12 through…]]></description><link>https://truedraftcad.hashnode.dev/why-400-walls-wasn-t-enough-interactive-autocad-dxf-layer-filtering-in-pure-typescript</link><guid isPermaLink="true">https://truedraftcad.hashnode.dev/why-400-walls-wasn-t-enough-interactive-autocad-dxf-layer-filtering-in-pure-typescript</guid><category><![CDATA[TypeScript]]></category><dc:creator><![CDATA[Anders Kessler]]></dc:creator><pubDate>Thu, 03 Dec 2026 15:28:12 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6b0d835a7f7611369f197f73/fefa9765-f57e-4ab4-8d58-a7ffbe648e45.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>If you build a browser CAD importer, clean test fixtures will lie to you.</p>
<p>When we shipped our pure-TypeScript ASCII AutoCAD <code>.DXF</code> importer (<code>R12</code> through <code>R2018</code>) in <a href="https://www.truedraftcad.com/free-dxf-floor-plan-editor">TrueDraft CAD</a>, our automated test suite passed with clean AIA-layered residential drawings (<code>A-WALL</code>, <code>A-ANNO-DIMS</code>, <code>A-FURN</code>). Parallel double-line wall shells collapsed into centered parametric walls, enclosed polygons resolved into named rooms, and the 3D WebGL cutaway rendered in milliseconds with zero WASM and zero server upload.</p>
<p>Then a real user dropped five metric architectural <code>.DXF</code> drawings into the live studio.</p>
<p>Four of the five files hit our <code>MAX_WALLS = 400</code> guardrail and detected <strong>0 closed rooms</strong>.</p>
<h2>What broke in real-world architectural .DXF files</h2>
<p>Production <code>.DXF</code> exports from AutoCAD, ArchiCAD, BricsCAD, and regional engineering offices rarely follow strict US National CAD Standard (<code>A-WALL</code>) naming. In practice, a single floor-plan <code>.DXF</code> mixes:</p>
<ul>
<li>Structural walls on custom or localized layers (<code>MUR</code>, <code>WALLS_200</code>, <code>ARQ-MUROS</code>, <code>0</code>, <code>PLAN</code>)</li>
<li>Dense hatch patterns, tile grids, stair treads, cabinetry, furniture blocks, and title blocks on layers whose names do not match <code>A-FURN</code> or <code>HATCH</code></li>
<li>Metric coordinates (<code>$INSUNITS = 4</code> for millimeters) where a 14-meter house spans <code>14,000</code> units and small fixture strokes slip past length thresholds</li>
</ul>
<p>When an importer applies a hard wall cap without showing the user which layers consumed that budget, two bad things happen:</p>
<ol>
<li><strong>Silent truncation:</strong> Hundreds of furniture, grid, or stair segments eat the first 400 slots before the exterior wall loop even finishes.</li>
<li><strong>Broken room topology:</strong> Because even a single missing wall segment leaves a room polygon open, enclosed room detection drops from 8 rooms to 0.</li>
</ol>
<h2>The fix: first-pass layer inventory + interactive filtering</h2>
<p>Instead of guessing harder with a brittle regex list, we updated <code>src/lib/cad/dxfImport.ts</code> in <a href="https://github.com/truedraftcad/truedraft-cad">TrueDraft CAD v1.4.4</a> to compute a complete per-layer segment inventory during the initial parse pass and expose <code>includeLayers?: string[]</code> plus <code>truncatedWallCount</code> directly to the import modal.</p>
<p>Here is the core data model from <code>src/lib/cad/dxfImport.ts</code>:</p>
<pre><code class="language-ts">export interface DxfLayerSummary {
  name: string;
  segmentCount: number;
  isWallLayer: boolean;
  selected: boolean;
}

export interface DxfImportOptions {
  name?: string;
  unitOverride?: DxfUnitOverride;
  includeLayers?: string[];
}

export interface DxfImportResult {
  plan: FloorPlan;
  stats: {
    wallCount: number;
    roomCount: number;
    rawSegments: number;
    detectedUnit: DetectedDxfUnit;
    collapsedPairs: number;
    ignoredEntities: number;
    layerSummaries: DxfLayerSummary[];
    truncatedWallCount: number;
  };
}
</code></pre>
<h3>How the two-tier default selection works</h3>
<p>During parsing, we read <code>LINE</code>, <code>LWPOLYLINE</code>, and legacy R12 <code>POLYLINE</code>/<code>VERTEX</code>/<code>SEQEND</code> entities into normalized segment lists while tracking exact segment counts per layer:</p>
<pre><code class="language-ts">const nonSkippedLines = dxfLines.filter((l) =&gt; !isNonWallLayer(l.layer));
const nonSkippedPolys = dxfPolylines.filter((p) =&gt; !isNonWallLayer(p.layer));

const explicitWallLines = nonSkippedLines.filter((l) =&gt; isExplicitWallLayer(l.layer));
const explicitWallPolys = nonSkippedPolys.filter((p) =&gt; isExplicitWallLayer(p.layer));
const hasExplicitWalls = explicitWallLines.length &gt; 0 || explicitWallPolys.length &gt; 0;
</code></pre>
<ul>
<li><strong>Case 1 (Standard AIA / explicit wall layers present):</strong> If the file contains <code>A-WALL*</code>, <code>WALL*</code>, or <code>ARCH-WALL*</code> layers, we auto-select only those layers by default so doors, furniture, dimensions, and hatches stay out of the wall solver.</li>
<li><strong>Case 2 (Custom / localized / layer-0 drawings):</strong> If no explicit wall layers exist, we auto-select all non-annotation layers and sort <code>layerSummaries</code> with candidate wall layers first, then by descending segment count.</li>
<li><strong>User override in real time:</strong> Because parsing a 2 MB ASCII <code>.DXF</code> in pure TypeScript takes ~15 to 40 ms on the main thread, unchecking a noisy <code>CABINETRY (312 segs)</code> or <code>GRID (180 segs)</code> checkbox inside the import modal re-runs <code>parseDxfToFloorPlan(rawText, { unitOverride, includeLayers })</code> instantaneously and updates the live wall count, detected room count, and unit scale before the user clicks <strong>Import</strong>.</li>
</ul>
<h3>Raising the ceiling without freezing WebGL</h3>
<p>We also raised <code>MAX_WALLS</code> from <code>400</code> to <code>1200</code> (plenty for multi-wing commercial and custom residential footprints) and added explicit truncation telemetry (<code>truncatedWallCount</code>). Whenever a drawing still exceeds 1,200 collapsed wall segments, the modal displays a clear warning telling the user exactly how many walls were clipped and suggesting they uncheck non-wall layers right above it.</p>
<h2>Watch the .DXF to 3D and 3D-Print .STL workflow</h2>
<p><a class="embed-card" href="https://youtu.be/OVR4Bs4YrZY">https://youtu.be/OVR4Bs4YrZY</a></p>

<h2>Try it on your own .DXF drawing (free, client-side, open source)</h2>
<p>Everything runs locally inside your browser tab, so client drawings never leave your machine:</p>
<ul>
<li><strong>Import a</strong> <code>.DXF</code> <strong>straight into the 2D/3D studio:</strong> <a href="https://www.truedraftcad.com/studio?action=import-dxf">truedraftcad.com/studio?action=import-dxf</a></li>
<li><strong>Interactive .DXF Floor Plan Editor guide:</strong> <a href="https://www.truedraftcad.com/free-dxf-floor-plan-editor">truedraftcad.com/free-dxf-floor-plan-editor</a></li>
<li><strong>Convert .DXF to 3D cutaway &amp; watertight .STL scale models:</strong> <a href="https://www.truedraftcad.com/floor-plan-to-stl">truedraftcad.com/floor-plan-to-stl</a></li>
<li><strong>Full AGPL-3.0 TypeScript source (</strong><code>src/lib/cad/dxfImport.ts</code> <strong>+ 83 unit tests):</strong> <a href="https://github.com/truedraftcad/truedraft-cad">github.com/truedraftcad/truedraft-cad</a></li>
</ul>
<p>If you have an unusual metric or legacy AutoCAD <code>.DXF</code> file that triggers edge cases in wall pairing or room detection, open an issue on GitHub with the layer structure and we will add a regression test for it.</p>
]]></content:encoded></item><item><title><![CDATA[Parsing AutoCAD ASCII .DXF Floor Plans in Pure TypeScript (No WASM, No Server)]]></title><description><![CDATA[Most browser floor plan tools can export a .DXF file, or at least claim to. Far fewer can import a real AutoCAD .DXF floor plan cleanly without shipping a…]]></description><link>https://truedraftcad.hashnode.dev/parsing-autocad-ascii-dxf-floor-plans-in-pure-typescript-no-wasm-no-server</link><guid isPermaLink="true">https://truedraftcad.hashnode.dev/parsing-autocad-ascii-dxf-floor-plans-in-pure-typescript-no-wasm-no-server</guid><category><![CDATA[TypeScript]]></category><category><![CDATA[open source]]></category><category><![CDATA[Sveltekit]]></category><category><![CDATA[WebGL]]></category><category><![CDATA[JavaScript]]></category><dc:creator><![CDATA[Anders Kessler]]></dc:creator><pubDate>Wed, 02 Dec 2026 17:49:36 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6b0d835a7f7611369f197f73/5208516f-6abb-413c-83df-ae623adc8ec4.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Most browser floor plan tools can export a <code>.DXF</code> file, or at least claim to. Far fewer can <strong>import</strong> a real AutoCAD <code>.DXF</code> floor plan cleanly without shipping a 25 MB WebAssembly binary or uploading your client's drawings to a remote conversion server.</p>
<p>When building <a href="https://www.truedraftcad.com">TrueDraft CAD</a> (an open-source browser 2D/3D architectural floor plan studio under <code>AGPL-3.0</code>), I wanted anyone with an existing architectural <code>.DXF</code> to drop it into the browser, turn raw CAD linework into parametric walls with real thickness, compute room areas and drywall/paint material takeoffs automatically, inspect it in 3D, and export scaled multi-sheet PDFs or 3D-printable <code>.STL</code> plates.</p>
<p>Here are the five real-world geometry problems you hit the moment you parse actual AutoCAD <code>.DXF</code> floor plans, and how we solved them in 1,119 lines of zero-dependency TypeScript (<code>src/lib/cad/dxfImport.ts</code>).</p>
<p><a class="embed-card" href="https://youtu.be/OVR4Bs4YrZY">https://youtu.be/OVR4Bs4YrZY</a></p>

<hr />
<h2>1. ASCII DXF Is Just Alternating <code>(GroupCode, Value)</code> Pairs</h2>
<p>Forget giant parser generators. Every ASCII AutoCAD <code>.DXF</code> file from R12 (<code>AC1009</code>) through R2018 is a flat stream of line pairs: an integer group code on line <code>2n</code> followed by its value on line <code>2n + 1</code>.</p>
<p>The catch is that architectural floor plans mix two different polyline encodings:</p>
<ul>
<li><strong><code>LWPOLYLINE</code> (R14+):</strong> All vertices live inside one entity as repeated <code>(10, x)</code> and <code>(20, y)</code> pairs with closed flag <code>(70 &amp; 1) !== 0</code>.</li>
<li><strong><code>POLYLINE -&gt; VERTEX -&gt; SEQEND</code> (R12 and many CAD exporters):</strong> A header entity followed by separate <code>VERTEX</code> entities until <code>SEQEND</code>.</li>
</ul>
<pre><code class="language-ts">if (entityType === 'LINE') {
  if (hasX1 &amp;&amp; hasY1 &amp;&amp; hasX2 &amp;&amp; hasY2) {
    dxfLines.push({ layer: entityLayer, x1, y1, x2, y2 });
  }
} else if (entityType === 'LWPOLYLINE') {
  if (lwVertices.length &gt;= 2) {
    dxfPolylines.push({
      layer: entityLayer,
      vertices: lwVertices,
      closed: (flags70 &amp; 1) !== 0
    });
  }
} else if (entityType === 'POLYLINE') {
  activePoly = { layer: entityLayer, vertices: [], closed: (flags70 &amp; 1) !== 0 };
} else if (entityType === 'VERTEX') {
  if (activePoly &amp;&amp; hasX1 &amp;&amp; hasY1) activePoly.vertices.push({ x: x1, y: y1 });
} else if (entityType === 'SEQEND') {
  if (activePoly &amp;&amp; activePoly.vertices.length &gt;= 2) dxfPolylines.push(activePoly);
  activePoly = null;
}
</code></pre>
<p>Rejecting <code>AutoCAD Binary DXF</code> upfront with a clear message and capping raw text at 12 MB keeps client-side parsing under ~40 ms even on dense commercial sheets.</p>
<hr />
<h2>2. Filtering AIA Wall Layers Without Breaking "Everything on Layer 0" Drawings</h2>
<p>Real architectural <code>.DXF</code> files are crowded with title blocks, hatch fills, dimension ticks, electrical symbols, and furniture blocks. If you convert every <code>LINE</code> in the file into a wall, your 3D view turns into solid concrete soup.</p>
<p>We use a two-stage AIA layer filter:</p>
<ol>
<li><strong>Always discard non-wall prefixes:</strong> <code>A-ANNO</code>, <code>DIM</code>, <code>DEFPOINTS</code>, <code>A-FURN</code>, <code>A-DOOR</code>, <code>A-GLAZ</code>, <code>A-ELEC</code>, <code>A-PLMB</code>, <code>A-AREA</code>, <code>TEXT</code>, <code>TITLE</code>, <code>BORDER</code>, and <code>HATCH</code>.</li>
<li><strong>Prefer explicit wall layers when present:</strong> If any entities live on <code>A-WALL*</code>, <code>WALL*</code>, or <code>ARCH-WALL*</code>, keep only those. Otherwise fall back gracefully to the remaining geometry (essential for quick contractor or SketchUp exports placed entirely on Layer <code>0</code>).</li>
</ol>
<p>Layer names also seed exterior vs. interior wall classification (<code>A-WALL-INTR</code> maps to interior 4.5" framing; <code>A-WALL</code> / <code>A-WALL-EXT</code> maps to exterior 6" framing).</p>
<hr />
<h2>3. Inferring Drawing Units When <code>$INSUNITS</code> Is Missing or Wrong</h2>
<p>AutoCAD's <code>$INSUNITS</code> header (<code>1 = inches</code>, <code>2 = feet</code>, <code>4 = mm</code>, <code>5 = cm</code>, <code>6 = meters</code>) is often omitted or left at <code>0</code> (unitless) in R12 files and third-party exports.</p>
<p>When <code>$INSUNITS</code> is absent and the user has not chosen a manual override, we inspect the bounding-box <code>maxSpan</code> of the kept wall geometry alongside the <code>$MEASUREMENT</code> flag (<code>0 = Imperial</code>, <code>1 = Metric</code>):</p>
<pre><code class="language-ts">if (options?.unitOverride &amp;&amp; options.unitOverride !== 'auto') {
  detectedUnit = options.unitOverride;
} else if (insunits !== null &amp;&amp; INSUNITS_MAP[insunits]) {
  detectedUnit = INSUNITS_MAP[insunits];
} else if (maxSpan &gt; 1500) {
  detectedUnit = 'mm';
} else if (maxSpan &gt; 80) {
  detectedUnit = measurement === 1 &amp;&amp; maxSpan &lt;= 1500 ? 'cm' : 'inches';
} else if (maxSpan &gt; 20) {
  detectedUnit = 'feet';
} else {
  detectedUnit = 'meters';
}
</code></pre>
<p>A 40-foot residential house has a <code>maxSpan</code> of <code>12,192</code> in millimeters, <code>480</code> in inches, <code>40</code> in feet, and <code>12.2</code> in meters. That single ladder gets automatic unit detection right on the vast majority of residential and small commercial plans, and flips CAD's Y-up axis to 2D canvas Y-down (<code>y: -y * toMeters</code>) in one pass.</p>
<hr />
<h2>4. Collapsing Double-Line Wall Shells Into Parametric Centerline Walls</h2>
<p>This is the core geometric challenge of architectural <code>.DXF</code> import. Architects draw walls as <strong>two parallel faces</strong> (for example, exterior sheathing and interior drywall spaced 6 inches / <code>0.1524 m</code> apart), not as single centerlines. If you feed double-line faces into a 3D extruder or planar room-area solver, you get paper-thin hollow corridors instead of real walls and rooms.</p>
<p>We collapse double-line walls in two stages:</p>
<h3>Stage A: Closed 4-Vertex Wall Shells (<code>tryCollapseThinWallShell</code>)</h3>
<p>Many CAD programs export each wall segment as a closed 4-vertex <code>LWPOLYLINE</code> rectangle or mitered trapezoid. For every 4-vertex closed polyline, we test both opposite edge pairs:</p>
<ul>
<li>Parallel within 5 degrees (<code>angleSinDiff &lt;= sin(5 deg)</code>)</li>
<li>Perpendicular separation between <code>0.06 m</code> and <code>0.36 m</code> (2.4" to 14.2")</li>
<li>Uniform width (<code>|w1 - w2| &lt;= 0.04 m</code>) and aspect ratio <code>avgLen &gt;= width * 1.15</code></li>
</ul>
<p>When matched, the entire 4-edge box collapses directly into a single centerline <code>WallDraft</code> carrying its exact measured thickness.</p>
<h3>Stage B: General Parallel Line Pairing (<code>collapseParallelSegments</code>)</h3>
<p>Unclosed <code>LINE</code> entities are paired greedily across opposing parallel segments:</p>
<pre><code class="language-ts">const perp = Math.abs((bMidX - a.x1) * nx + (bMidY - a.y1) * ny);
if (perp &lt; MIN_SHELL_WIDTH_M || perp &gt; MAX_SHELL_WIDTH_M) continue;

const bProj1 = (b.x1 - a.x1) * ux + (b.y1 - a.y1) * uy;
const bProj2 = (b.x2 - a.x1) * ux + (b.y2 - a.y1) * uy;
const overlap = Math.min(lenA, Math.max(bProj1, bProj2)) - Math.max(0, Math.min(bProj1, bProj2));
if (overlap &lt; Math.min(lenA, lenB) * 0.6 || overlap &lt; 0.15) continue;
</code></pre>
<p>Pairs are sorted by longest longitudinal overlap (breaking ties by realistic wall thickness) so exterior wall faces pair with their true interior counterparts instead of accidentally pairing across a narrow hallway. Any leftover stub segments from overhanging wall faces get preserved so T-junctions stay intact.</p>
<p>Finally, a three-step cleanup pipeline turns raw drafts into a clean planar graph ready for our half-edge room solver:</p>
<ol>
<li><strong>Endpoint snapping (<code>snapWallEndpoints</code>, <code>60 mm</code> tolerance):</strong> Clusters near-coincident corners so rooms close cleanly even when source CAD lines slightly undershoot.</li>
<li><strong>Collinear merging (<code>mergeCollinearWalls</code>):</strong> Fuses broken inline wall segments into clean continuous walls.</li>
<li><strong>Deduplication &amp; normalization (<code>deduplicateWalls</code>):</strong> Drops overlapping duplicates and translates the bounding box to <code>(1.0, 1.0)</code> meters.</li>
</ol>
<hr />
<h2>5. Pulling Clean Room Labels Out of Formatted <code>MTEXT</code></h2>
<p>AutoCAD <code>MTEXT</code> strings embed formatting escapes like <code>{\fArial|b1;PRIMARY BEDROOM\P14'-6" x 12'-0"\P174 SQ FT}</code>. Splitting on <code>\P</code> paragraph breaks, stripping <code>\{...\}</code> and <code>\f...;</code> codes, filtering out pure dimension/area strings (<code>14'-6"</code>, <code>174 SQ FT</code>, <code>D1</code>, <code>W12</code>), and discarding text outside the wall bounding box (+1.5 m margin so title-block notes never pollute the floor plan) lets us anchor real room labels and auto-assign sensible 3D floor finishes (<code>tile</code> for Kitchen/Bath, <code>carpet</code> for Bedrooms, <code>concrete</code> for Garage/Shop, <code>hardwood</code> elsewhere).</p>
<hr />
<h2>Try It Live or Inspect the Source</h2>
<p>Everything runs 100% client-side in the browser (zero server upload, zero signup required to try):</p>
<ul>
<li><strong>Interactive DXF Guide &amp; Importer:</strong> <a href="https://www.truedraftcad.com/floor-plan-to-dxf">www.truedraftcad.com/floor-plan-to-dxf</a></li>
<li><strong>Open Live CAD Studio (Free):</strong> <a href="https://www.truedraftcad.com/studio">www.truedraftcad.com/studio</a> (click <strong>Import DXF</strong> in the toolbar, or load any of the 14 US starter templates)</li>
<li><strong>Compare No-Subscription CAD Options:</strong> <a href="https://www.truedraftcad.com/autocad-floor-plan-alternative">AutoCAD Floor Plan Alternative</a> · <a href="https://www.truedraftcad.com/sketchup-alternative">SketchUp Alternative</a></li>
<li><strong>Full Open-Source Code (<code>AGPL-3.0</code>):</strong> <a href="https://github.com/truedraftcad/truedraft-cad">github.com/truedraftcad/truedraft-cad</a> (see <code>src/lib/cad/dxfImport.ts</code> and <code>src/lib/cad/dxfImport.test.ts</code>)</li>
</ul>
<p>If you run into a quirky <code>.DXF</code> exporter from Revit, Chief Architect, LibreCAD, or QCAD whose layer conventions or wall shells behave unexpectedly, open an issue on GitHub with a tiny sample snippet and I will add a regression test for it.</p>
]]></content:encoded></item><item><title><![CDATA[Building a Watertight Binary .STL 3D-Print Exporter in Pure TypeScript]]></title><description><![CDATA[A few hours into launching TrueDraft CAD on Product Hunt today, a maker asked a great question in the comments: "With the .OBJ export, could you print the…]]></description><link>https://truedraftcad.hashnode.dev/building-a-watertight-binary-stl-3d-print-exporter-in-pure-typescript</link><guid isPermaLink="true">https://truedraftcad.hashnode.dev/building-a-watertight-binary-stl-3d-print-exporter-in-pure-typescript</guid><category><![CDATA[TypeScript]]></category><category><![CDATA[open source]]></category><category><![CDATA[3D printing]]></category><category><![CDATA[cad]]></category><dc:creator><![CDATA[Anders Kessler]]></dc:creator><pubDate>Tue, 01 Dec 2026 22:08:54 GMT</pubDate><content:encoded><![CDATA[<p>A few hours into launching <a href="https://www.truedraftcad.com">TrueDraft CAD</a> on Product Hunt today, a maker asked a great question in the comments:</p>
<blockquote>
<p>"With the .OBJ export, could you print the house as a little scale model on a Bambu P2S? Split by floor sounds great, you could lift the roof off and look inside."</p>
</blockquote>
<p>Exporting a 3D mesh that <em>renders</em> nicely in Three.js is very different from exporting a mesh that <em>slices and prints cleanly</em> on an FDM 3D printer. Instead of leaving it on a roadmap, I wrote a zero-dependency binary <code>.STL</code> architectural compiler in pure TypeScript (<code>src/lib/exporters/stl.ts</code>) and shipped it in <a href="https://github.com/truedraftcad/truedraft-cad/releases/tag/v1.4.0">TrueDraft CAD v1.4.0 (AGPL-3.0)</a>, along with a free interactive <a href="https://www.truedraftcad.com/floor-plan-to-stl">Floor Plan to STL Scale &amp; Build-Plate Calculator</a>.</p>
<p><a class="embed-card" href="https://youtu.be/OVR4Bs4YrZY">https://youtu.be/OVR4Bs4YrZY</a></p>

<p>Here are the four geometric problems you hit immediately when turning a 2D/3D architectural floor plan into an FDM-printable <code>.STL</code>, and how we solved them in ~800 lines of client-side TypeScript.</p>
<hr />
<h2>1. Coordinate System, Units, and the 80-Byte Binary <code>.STL</code> Trap</h2>
<p>Architectural web CAD engines typically work in real-world meters with <strong>Y-up</strong> (matching Three.js). Every major FDM slicer (Bambu Studio, OrcaSlicer, PrusaSlicer, and Cura) expects <strong>millimeters</strong> with <strong>Z-up</strong> and the model resting flat on <code>z = 0</code>.</p>
<p>Converting a floor plan at scale <code>1:S</code> (for example <code>1:100</code>, where <code>1 m = 10 mm</code>) maps world <code>(x, y, z)</code> to slicer millimeters:</p>
<pre><code class="language-ts">const mmPerMeter = 1000 / scaleDenominator;
const xMm = (worldX - originMinX) * mmPerMeter;
const yMm = (originMaxY - worldY) * mmPerMeter; // flip 2D canvas Y to preserve right-handed orientation
const zMm = worldZ * mmPerMeter;
</code></pre>
<p>Two subtle details matter in the binary <code>.STL</code> buffer (<code>84 + 50 * triangleCount</code> bytes, little-endian <code>DataView</code>):</p>
<ol>
<li><strong>Never start the 80-byte header with</strong> <code>"solid "</code><strong>:</strong> Many slicers sniff the first 5 bytes to decide whether a file is ASCII or binary <code>.STL</code>. Starting the header with <code>"TrueDraft CAD Binary STL..."</code> avoids misdetection.</li>
<li><strong>Enforce exact outward unit normals:</strong> Every triangle computes <code>(v1 - v0) × (v2 - v0)</code>, normalizes it, and drops degenerate zero-area triangles before writing so slicers never complain about non-finite normals.</li>
</ol>
<hr />
<h2>2. Why Real Drywall Partitions Vanish on a 0.4 mm Nozzle</h2>
<p>A standard US interior partition wall is <code>4.5 inches</code> (<code>0.1143 m</code>) thick. Look at what happens when you scale it down:</p>
<table>
<thead>
<tr>
<th>Scale</th>
<th>6" Exterior Wall</th>
<th>4.5" Interior Partition</th>
<th>0.4 mm Nozzle Behavior</th>
</tr>
</thead>
<tbody><tr>
<td><code>1:50</code></td>
<td><code>3.05 mm</code></td>
<td><code>2.29 mm</code></td>
<td>Prints solidly</td>
</tr>
<tr>
<td><code>1:100</code></td>
<td><code>1.52 mm</code></td>
<td><code>1.14 mm</code></td>
<td>Borderline: thin walls risk gaps</td>
</tr>
<tr>
<td><code>1:150</code></td>
<td><code>1.02 mm</code></td>
<td><code>0.76 mm</code></td>
<td>Interior walls drop or print brittle</td>
</tr>
<tr>
<td><code>1:200</code></td>
<td><code>0.76 mm</code></td>
<td><code>0.57 mm</code></td>
<td>Below 2 perimeters: vanishes in slicer</td>
</tr>
</tbody></table>
<p>Instead of letting slicers silently delete interior rooms, <code>src/lib/exporters/stl.ts</code> clamps wall thickness <strong>in world meters before extrusion</strong>:</p>
<pre><code class="language-ts">const minWallMeters = minWallThicknessMm / mmPerMeter; // default 1.2 mm = 3 perimeters on 0.4 mm nozzle
const effectiveThickness = Math.max(wall.thickness, minWallMeters);
</code></pre>
<p>We also emit solid square corner posts wherever walls meet at L-junctions or T-junctions so mitered corners never leave vertical hairline seams, and we deliberately omit fragile floating door leaves and <code>25 mm</code> window glass planes while keeping real doorway headers (lintels) and window sills as closed 6-face prisms.</p>
<hr />
<h2>3. Solid Bed-Aligned Baseplates (<code>z = 0</code>)</h2>
<p>A raw wall shell floating on thin footprints warps off an FDM build plate. TrueDraft CAD ear-clips every detected room polygon (with a rectangular footprint fallback for open walls) and extrudes a solid <code>1.6 mm</code> baseplate seated strictly at <code>z = 0.0 mm</code>. Every wall starts flush on top of that plate (<code>z = baseplateMm</code>), giving clean first-layer bed adhesion and zero floating overhangs.</p>
<hr />
<h2>4. Split-by-Floor Multi-Story Exports (Lift-Off Study Models)</h2>
<p>Printing a 2-story or 3-story house as one fused solid traps support material inside the ground floor and hides the rooms you actually want to inspect.</p>
<p>With <code>compilePlanLevelsToStl()</code>, every story is compiled to its own <code>.STL</code> file with two invariants:</p>
<ol>
<li><strong>Independent</strong> <code>z = 0</code> <strong>bed seating:</strong> Level 1, Level 2, and Basement each start flat at <code>z = 0</code> with their own <code>1.6 mm</code> slab baseplate, so zero interior supports are required.</li>
<li><strong>Shared global XY origin:</strong> Every floor uses the exact same <code>originMinX</code> / <code>originMaxY</code> computed across the union of all stories, so when you print Level 1 and Level 2 separately, the upper story stacks cleanly on top of the lower perimeter walls like a real architectural study model.</li>
</ol>
<hr />
<h2>Try It Free in Your Browser (AGPL-3.0)</h2>
<ul>
<li><strong>3D-Print Build-Plate &amp; Scale Calculator (Bambu Lab, Prusa, Ender presets):</strong> <a href="https://www.truedraftcad.com/floor-plan-to-stl">truedraftcad.com/floor-plan-to-stl</a></li>
<li><strong>Live Multi-Story CAD Studio (zero signup):</strong> <a href="https://www.truedraftcad.com/studio?template=two-story-house-1840">truedraftcad.com/studio?template=two-story-house-1840</a></li>
<li><strong>Source Code &amp; v1.4.0 Release (AGPL-3.0):</strong> <a href="https://github.com/truedraftcad/truedraft-cad/releases/tag/v1.4.0">github.com/truedraftcad/truedraft-cad/releases/tag/v1.4.0</a></li>
</ul>
<p>If you print a floor plan from TrueDraft CAD or have ideas for roof pitches or magnetic alignment lips between stories, drop a comment or open an issue on GitHub!</p>
]]></content:encoded></item><item><title><![CDATA[How I Built an Open-Source Multi-Story 2D/3D Floor Plan CAD Engine in TypeScript]]></title><description><![CDATA[How TrueDraft CAD implements planar half-edge room detection, client-side AutoCAD DXF import/export, scaled vector blueprint PDFs, and stacked 3D WebGL in…]]></description><link>https://truedraftcad.hashnode.dev/how-i-built-an-open-source-multi-story-2d-3d-floor-plan-cad-engine-in-typescript</link><guid isPermaLink="true">https://truedraftcad.hashnode.dev/how-i-built-an-open-source-multi-story-2d-3d-floor-plan-cad-engine-in-typescript</guid><category><![CDATA[Open Source]]></category><category><![CDATA[TypeScript]]></category><category><![CDATA[Svelte]]></category><category><![CDATA[ThreeJS]]></category><dc:creator><![CDATA[Anders Kessler]]></dc:creator><pubDate>Mon, 30 Nov 2026 14:18:23 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6b0d835a7f7611369f197f73/cf9186d4-1000-4295-ac62-f671988b9ebc.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Homeowners, remodelers, and small contractors run into an annoying split when they need a real floor plan:</p>
<ul>
<li>Consumer room planners run in the browser, but lock scaled PDFs and CAD files behind $24–$39/month recurring subscriptions.</li>
<li>Desktop CAD packages (AutoCAD, Revit, Chief Architect) are built for full architectural firms and cost $200+/month.</li>
</ul>
<p>I built <a href="https://www.truedraftcad.com"><strong>TrueDraft CAD</strong></a> — an AGPL-3.0 open-source browser-native multi-story 2D/3D architectural CAD studio written in TypeScript, Svelte 5, HTML5 Canvas, and Three.js — so anyone can draw rooms to exact imperial (<code>ft-in</code>) or metric dimensions, import existing <code>.DXF</code> drawings, inspect a stacked 3D cutaway or WASD walkthrough, and export deterministic scaled Blueprint PDFs, AIA-layered AutoCAD <code>.DXF</code> files, and 3D <code>.OBJ</code> meshes.</p>
<ul>
<li><strong>Live Studio (no login required):</strong> <a href="https://www.truedraftcad.com/studio">https://www.truedraftcad.com/studio</a></li>
<li><strong>2-Story Modern House Demo:</strong> <a href="https://www.truedraftcad.com/studio?template=two-story-house-1840">https://www.truedraftcad.com/studio?template=two-story-house-1840</a></li>
<li><strong>Source Code (AGPL-3.0):</strong> <a href="https://github.com/truedraftcad/truedraft-cad">https://github.com/truedraftcad/truedraft-cad</a></li>
</ul>
<p><a class="embed-card" href="https://youtu.be/UL8NWvUv5Fg">https://youtu.be/UL8NWvUv5Fg</a></p>

<p><em>39-second walkthrough of TrueDraft CAD v1.3.0 (multi-story 2D/3D drafting, Ghost Below, AutoCAD .DXF, and scaled Blueprint PDF export).</em></p>
<p>Here are the four most interesting geometry and compiler problems I had to solve to make browser-native CAD feel crisp and reliable.</p>
<hr />
<h2>1. Automatic Room Detection with a Planar Half-Edge Cycle Solver (<code>src/lib/cad/geometry.ts</code>)</h2>
<p>In a real floor plan editor, users draw individual wall segments — often crossing through other walls to form T-junctions or interior partitions. Nobody wants to manually trace closed room polygons after moving a wall by 6 inches.</p>
<p>Every time a wall changes, <code>computePlan()</code> builds a planar graph in four deterministic passes:</p>
<ol>
<li><strong>Intersection &amp; T-junction splitting:</strong> Every wall segment is checked against all other wall segments (plus endpoints within a 2 cm weld tolerance) and split at intersection points so every crossing becomes an explicit shared graph vertex.</li>
<li><strong>Vertex clustering &amp; pruning:</strong> Endpoints within snap tolerance are welded into canonical vertices, and dangling degree-1 wall stubs are pruned cleanly from cycle detection while remaining intact in rendering and takeoff.</li>
<li><strong>Half-edge minimal face traversal:</strong> Each undirected edge becomes two directed half-edges sorted counter-clockwise by angle at each vertex. Walking the next rightmost turn (<code>next(u-&gt;v) = prevCCW(v-&gt;u)</code>) traces every minimal cycle in <code>O(E log E)</code> time.</li>
<li><strong>Signed area filtering:</strong> The shoelace formula computes each face's signed area. Negative/outer boundary cycles are dropped, and valid interior cycles become live rooms with automatic net square footage, perimeter, and material takeoff estimates (4x8 drywall sheets, 2-coat paint gallons, baseboard linear feet, and flooring +10% waste).</li>
</ol>
<p>Because all geometry is stored internally in meters (and formatted into architectural feet-inches to the 1/16" or metric on demand), floating-point drift stays tiny and imperial/metric switching is lossless.</p>
<hr />
<h2>2. Client-Side AutoCAD <code>.DXF</code> R12–R2018 Importer (<code>src/lib/cad/dxfImport.ts</code>)</h2>
<p>Importing real architectural <code>.DXF</code> files is trickier than parsing <code>LINE</code> and <code>LWPOLYLINE</code> entities: real architects almost always draft walls as <strong>parallel double lines</strong> (two lines 4.5" or 6" apart representing both faces of drywall).</p>
<p>To convert raw DXF linework into TrueDraft's parametric centerline wall model without uploading user files to a server, <code>dxfImport.ts</code> runs entirely client-side:</p>
<ul>
<li><strong>Automatic unit inference:</strong> Reads <code>$INSUNITS</code> from the <code>HEADER</code> section when present (<code>1 = inches</code>, <code>2 = feet</code>, <code>4 = mm</code>, <code>6 = meters</code>), and falls back to bounding-box span heuristics when legacy DXF files omit <code>$INSUNITS</code>.</li>
<li><strong>AIA wall-layer filtering:</strong> Prioritizes architectural wall layers (<code>A-WALL*</code>, <code>WALL*</code>, <code>0</code>) while ignoring dimension lines, hatch grids, and title-block borders.</li>
<li><strong>Double-line wall shell collapse:</strong> Detects parallel opposing segments separated by 3.5"–14" with significant longitudinal overlap and collapses each pair into a single parametric wall centerline preserving exact thickness.</li>
<li><strong>Collinear merging &amp;</strong> <code>TEXT</code><strong>/</strong><code>MTEXT</code> <strong>room labels:</strong> Merges fragmented collinear segments and maps <code>TEXT</code>/<code>MTEXT</code> labels inside closed faces into room overrides automatically.</li>
</ul>
<p>For export (<code>src/lib/exporters/dxf.ts</code>), TrueDraft writes valid AutoCAD DXF R12 (<code>AC1009</code>) organized cleanly onto standard AIA layers (<code>A-WALL</code>, <code>A-WALL-INTR</code>, <code>A-DOOR</code>, <code>A-GLAZ</code>, <code>A-ELEC</code>, <code>A-PLMB</code>, <code>A-FURN</code>, <code>A-AREA</code>, <code>A-ANNO-DIMS</code>) so contractors and draftsmen can open the output directly in AutoCAD, LibreCAD, QCAD, Revit, or SketchUp.</p>
<hr />
<h2>3. True Physical-Scale Vector Blueprint PDF Compiler (<code>src/lib/exporters/pdf.ts</code>)</h2>
<img src="https://raw.githubusercontent.com/truedraftcad/truedraft-cad/main/docs/screenshots/blueprint-sheet-a1.png" alt="True-to-Scale Architectural Blueprint Sheet A1.0 on Tabloid 11x17" style="display:block;margin:0 auto" />

<p>Many browser floor plan tools "export PDF" by screenshotting a <code>&lt;canvas&gt;</code> bitmap and pasting it onto a page — which produces fuzzy lines and breaks physical scale.</p>
<p>TrueDraft compiles floor plans directly into <strong>pure vector PDF drawing commands</strong> via <code>jsPDF</code> using exact physical point geometry (<code>1 inch = 72 pt</code>):</p>
<ul>
<li>At <code>1/4" = 1'-0"</code>, every 1 foot of real-world wall length is rendered at exactly <code>18.0 pt</code> (<code>0.25 in</code>) on Letter (<code>8.5x11</code>), Tabloid (<code>11x17</code>), or Arch D (<code>24x36</code>) paper. Print at 100% and an architect's scale ruler matches wall-to-wall.</li>
<li>Multi-story buildings compile into a complete architectural packet: one scaled plan sheet per floor (<code>A1.1 Level 1 · Ground</code>, <code>A1.2 Level 2 · Upper</code>, …) followed by <strong>Sheet A2.0</strong> containing combined Door Schedules, Window Schedules, Room Area tables, and Material Takeoffs.</li>
<li>Title blocks support live editing of Project Name, Firm/Studio, Drawn By, Address, Sheet #, and Revision with a synchronized vector preview.</li>
</ul>
<hr />
<h2>4. Multi-Story Onion-Skin Alignment &amp; Stacked 3D WebGL (<code>src/lib/cad/levels.ts</code>, <code>Viewport3D.svelte</code>)</h2>
<img src="https://raw.githubusercontent.com/truedraftcad/truedraft-cad/main/docs/screenshots/level2-ghost-takeoff.png" alt="Level 2 Upper Floor with Ghost Below Alignment and Live Material Takeoff" style="display:block;margin:0 auto" />

<p>In v1.3.0, I added full multi-story support (up to 6 floors plus a Basement below grade) without breaking single-floor simplicity or backward compatibility with saved JSON plans:</p>
<ul>
<li><strong>2D Onion-Skin Ghosting (</strong><code>Canvas2D.svelte</code><strong>):</strong> When editing an upper floor, toggling <code>Ghost Below</code> overlays the floor directly underneath as dashed blueprint reference walls plus highlighted <code>STAIRS (BELOW)</code> callout outlines so stairwells, bearing walls, and plumbing chases line up vertically.</li>
<li><strong>Stacked 3D Cutaway &amp; Inter-Story Slabs (</strong><code>Viewport3D.svelte</code> <strong>&amp;</strong> <code>obj.ts</code><strong>):</strong> Every level extrudes walls with real geometric door/window cutouts (no alpha hacks), sits at its true elevation (<code>ceilingHeight + slabThickness</code>), and generates thick structural floor slabs between stories. In <code>Cutaway</code> mode, lower stories render full-height while the topmost floor cuts away like an architectural dollhouse model — and first-person WASD walkthrough automatically sets camera eye-height to <code>activeLevel.elevationM + 1.68m</code>.</li>
<li><strong>Watertight Stacked 3D</strong> <code>.OBJ</code> <strong>Export (</strong><code>src/lib/exporters/obj.ts</code><strong>):</strong> Exports clean triangulated meshes grouped by story (<code>Level_1_Exterior_Walls</code>, <code>Level_2_Floor_Slabs</code>, etc.) ready for Blender, SketchUp, or Rhino.</li>
</ul>
<hr />
<h2>Open Source &amp; Business Model</h2>
<p>The entire codebase — CAD engine, DXF parser/writer, PDF/OBJ/SVG/CSV compilers, 76 architectural &amp; MEP symbols, and 10 starter templates — is public under <strong>AGPL-3.0</strong>.</p>
<p>On <a href="https://www.truedraftcad.com">truedraftcad.com</a>, the hosted studio is free to use on your own floor plan with zero signup (including 2D/3D drafting, <code>.DXF</code> import, 1 free AI sketch trace, live material takeoff, and watermarked blueprint preview). When someone wants clean, unwatermarked production files or multi-story packets without self-hosting, they pay once ($9 Single Project, $29 Pro Lifetime, $79 Studio 5-seat — zero subscriptions, 14-day easy refunds).</p>
<p>If you build CAD, computational geometry, WebGL, or AEC tools, I'd love feedback on the geometry engine, DXF parser edge cases, or what architectural features would make this most useful in real workflows!</p>
<ul>
<li><strong>GitHub:</strong> <a href="https://github.com/truedraftcad/truedraft-cad">https://github.com/truedraftcad/truedraft-cad</a></li>
<li><strong>Live Studio:</strong> <a href="https://www.truedraftcad.com/studio">https://www.truedraftcad.com/studio</a></li>
</ul>
<hr />
<p><strong>Update (Dec 1, 2026):</strong> TrueDraft CAD is featured live on Product Hunt today, and we just shipped 14 live SVG starter templates at <a href="https://www.truedraftcad.com/templates">truedraftcad.com/templates</a>. If you test the multi-story engine or AutoCAD <code>.DXF</code> importer and have technical feedback or feature requests, join the maker Q&amp;A thread here: <a href="https://www.producthunt.com/posts/truedraft-cad">TrueDraft CAD on Product Hunt</a>.</p>
]]></content:encoded></item></channel></rss>