Skip to content
AI-Ready Docs
/llms.txt/llms-mcp.txt

@barocss/cad-projection ​

Headless, deterministic CPU hidden-line CAD geometry projection with exact SVG vector export and CPU-rendered PNG output — with zero browser, GPU, DOM, canvas, React, or Studio dependencies.

@barocss/cad-projection builds on @barocss/cad's exact B-rep hidden-line removal (projectBrepHiddenLines) and adds mixed-scene adaptation (B-rep solids, NURBS curves, UV-trimmed surfaces, triangle meshes, Direct sources), exact 2D fill visibility clipping, compact SVG export, and pure-CPU PNG rasterization for CI visual checks and multimodal AI verification (query.render).

Quick start ​

mjs
import { evaluateCadPart } from '@barocss/cad';
import { part } from '@barocss/cad/api';
import {
  projectGeometry,
  projectGeometryFourViews,
  renderSvg,
  renderPng,
} from '@barocss/cad-projection';
mjs
const bracket = part('Bracket')
  .box({ w: 80, d: 40, h: 10 })
  .hole(p => p.faces().facing('+z').first(), { d: 8, x: 20, y: 20 });

const snapshot = evaluateCadPart(bracket.doc);
const brep = snapshot.outputs[0].brep;
const items = [{ id: 'bracket', kind: 'brep', brep }];

const doc = projectGeometry(items, {
  camera: { position: [240, -320, 220], target: [40, 20, 5], up: [0, 0, 1] },
  fills: [{ item: 'bracket', color: '#dbeafe' }],
});

const svg = renderSvg(doc, { compactFills: true, hiddenLines: true });
const png = await renderPng(doc, { hiddenLines: true, width: 320, height: 240 });
const fourView = projectGeometryFourViews(items);

This sample runs directly in CI via pnpm --filter @barocss/library-docs test:samples.

Entry points ​

SubpathPurpose
@barocss/cad-projectionScene & B-rep projection (projectGeometry, projectGeometryFourViews, projectBreps, projectDirectGeometry, projectModel) + renderSvg / renderPng
@barocss/cad-projection/compressionZero-dependency crc32, compress, and deflateZlib utilities
@barocss/cad-projection/inspectDiagnostic inspection helpers for projected curves, visibility intervals, and coverage receipts

Supported input coverage ​

Input kindItem descriptorRouting & notes
Solid / sheet / facet B-rep{ id, kind: 'brep', brep }Exact kernel HLR (projectBrepHiddenLines)
Free NURBS curve{ id, kind: 'curve', curve, interval? }Analytic lines & circles preserved; general curves adaptively sampled
UV-trimmed NURBS surface{ id, kind: 'surface', surface, trims? }Exact UV slab arrangement decomposition
Triangle mesh / soup{ id, kind: 'mesh', positions, indices, open? }Native facet adapter with non-manifold triangle-sheet fallback
Direct / compiled modelprojectDirectGeometry / projectModelAtomic validation (ProjectionSourceError) without Studio imports

Rendering options & boundaries ​

  • renderSvg(doc, options?): Preserves exact lines and affine elliptical arcs (transform="matrix(...)"), optional hiddenLines, faceGuideStyle ('illustration' | 'continuous'), and compactFills (directed-edge cancellation). Also powers semantic SVG hit metadata in @barocss/cad-react/sdk <CadDrawing />.
  • renderPng(doc, options?): Deterministic RGB PNG (Promise<Uint8Array>) rasterized on CPU using standard CompressionStream.
  • Camera & pixel limits: Cameras are strictly orthographic (position - target sets view direction, auto-fitted to bounds), supporting standard orthographic, isometric, dimetric, trimetric, and magnified detail views. Image dimensions must be positive integers up to 8192 per side and 32,000,000 total pixels.
  • Scope separation: ISO/ASME title blocks, baseline/ordinate dimensions, GD&T callouts, and vector PDF/DXF sheet export live in @barocss/cad-model; interactive WebGPU 3D rendering lives in @barocss/gpu.