@barocss/cad-worker
@barocss/cad-worker moves heavy B-Rep evaluation, mass properties, 2D proposal callouts, robotics workspace sweeps, and parallel generative variants off the browser main thread using standard Web Workers and zero-copy transferable buffers.
Because the underlying @barocss/cad kernel is pure TypeScript with zero WebAssembly, the same worker modules run identically in browser Web Workers, Vite/esbuild apps, or synchronous in-process test ports.
Subpath Entry Points
| Entry Point | Purpose |
|---|---|
@barocss/cad-worker | Main barrel exporting EngineClient, Lanes, ports, analysis router, robot tasks, and VariantWorkerPool |
@barocss/cad-worker/client | EngineClient RPC wrapper over a Web Worker with typed replies (MassReply, VolumeReply, FootprintReply, RobotSweepReply, ProposalOverlay) |
@barocss/cad-worker/worker | Ready-to-bundle engine.worker.ts entry point |
@barocss/cad-worker/analysis | createAnalysisWorkerRouter for modular auxiliary analysis workers (faces, print, clearance, cam) |
@barocss/cad-worker/port | createDefaultEnginePort, createWorkerEnginePort, and createSyncEnginePort (CadEnginePort abstraction) |
@barocss/cad-worker/lanes | Lanes request-lane coordinator (latest-wins cancellation for live slider dragging vs queued exports) |
@barocss/cad-worker/variantPool | VariantWorkerPool, evaluateVariants, buildParametricVariantCandidates, computeSafeParameterBounds, and projectVariantThumbnail |
@barocss/cad-worker/robotTasks | collectRobotPartMeshes, runRobotSweep, and runRobotWorkspace |
@barocss/cad-worker/proposalDrawingCallouts | proposalDrawingCallouts for computing 2D drawing annotation diffs on AI proposals |
@barocss/cad-worker/stepMetadata | stepMetadata / receiveStepMetadata for STEP provenance inspection |
@barocss/cad-worker/mouldView | mouldView parting-line and draft loop computation |
Choosing an Engine Port (CadEnginePort)
Use @barocss/cad-worker/port when your UI or SDK wants automatic Web Worker acceleration in browsers while falling back seamlessly to synchronous execution in Node.js or unit tests:
import {
createDefaultEnginePort,
createSyncEnginePort,
createWorkerEnginePort,
} from '@barocss/cad-worker/port';
// Browser: spawns a Web Worker when available; Node/SSR: falls back to synchronous evaluation.
const port = createDefaultEnginePort();
// Explicit synchronous port for deterministic CI tests or CLI tooling:
const syncPort = createSyncEnginePort();Request Lanes (Lanes)
Interactive CAD sliders fire dozens of updates per second. Lanes separates high-frequency interactive preview requests from authoritative operations:
- Latest-wins lanes supersede stale in-flight slider evaluations so the UI never queues behind obsolete drag frames.
- Authoritative lanes preserve ordering for saves, exports, and proposal acceptance.
Parallel Generative Variants (VariantWorkerPool)
The Generative Variant Explorer uses @barocss/cad-worker/variantPool to evaluate multiple parameter and topology candidates in parallel without blocking viewport orbiting:
import {
buildParametricVariantCandidates,
evaluateVariants,
applyCandidateToDoc,
type VariantCandidateInput,
} from '@barocss/cad-worker/variantPool';
// 1. Derive safe bounded parameter candidates around the active document
const candidates: VariantCandidateInput[] = buildParametricVariantCandidates(doc, {
preset: 'lightweight',
count: 4,
});
// 2. Evaluate all candidates in parallel (B-Rep mass, bounds, DFM, checkSpec, 2D thumbnails)
const batch = await evaluateVariants(doc, candidates);
// 3. Promote the winning candidate into an editable document revision
const winner = batch.results.find(r => r.ok && r.specs?.hardFailing === 0);
if (winner) {
const nextDoc = applyCandidateToDoc(doc, winner.candidate);
}Each VariantCandidateResult carries:
VariantBaselineMetricsdeltas (mass, volume, bounding box)VariantSpecSummary(checkSpecpass/fail counts)VariantDfmSummary&VariantPhysicsSummaryVariantThumbnaillightweight 2D projection segments for side-by-side card previews
Auxiliary Analysis Router (createAnalysisWorkerRouter)
Heavy inspection tasks — print slice previews, clearance checks, face queries, and CAM toolpaths — run on isolated auxiliary workers routed through createAnalysisWorkerRouter:
import { createAnalysisWorkerRouter } from '@barocss/cad-worker/analysis';
const router = createAnalysisWorkerRouter({
print: () => import('./printLane'),
clearance: () => import('./clearanceLane'),
cam: () => import('./camLane'),
});