Skip to content

CAD guides ​

Start with the modeling API ​

Make and edit a solid plate, then follow Model a part for a complete convex sketch → extrusion → through-slab cut → component chamfer → batch parameter edit → save/load/re-edit. New solid authoring uses cad.model(), named dimensions and named outputs; readers do not choose a provider version or write IDs/revisions.

The supported/refused table and initial bounds are part of that contract. Native capabilities document additional lower-level operations separately. Engine, editor, browser and deployment evidence remain distinct.

Advanced and historical references ​

The rest of this page covers older, separately scoped geometry APIs. Exact-prism modeling, serial-part v2 files and Source0–3 programs retain their historical text and evidence. Use their explicit readers for existing files; there is no automatic migration through cad.load.

Compile and edit complete Source0–3 inputs: exact versions, outputs, refusals and the separate JSON feature-document path.

Sketch, cut and chamfer — Build an exact convex prism, widen a through-slab cut, reopen authored v0 intent and chamfer one original edge. Uses its own adopted public-source profile and complete runnable inputs.

Cut, chamfer and reopen a serial part v2: complete authored JSON, short API, actual second-component selection, exact measured edits and fresh-process reconstruction.

Adaptive Curve display — Use a complete weighted degree-five Curve request to change display tolerance while keeping the native coefficients and full source intact.

Construct an XY profile ​

Choose a builder when you have typed geometric intent:

ts
import { buildXYProfile, buildXYArc, evaluateCurve } from '@barocss/cad';

const rectangle = buildXYProfile({
  kind: 'rectangle', id: 'outline', origin: [4, -3], width: 7, height: 5,
});
const circle = buildXYArc({ kind: 'circle', id: 'rim', center: [4, -3], radius: 10 });
console.log(evaluateCurve(circle.curve, 0));

These return actual source0, Model, Curve and report. Rectangle poles run CCW in XY, start/end coordinates coincide and the degree1 domain is [0,4]. Circle geometry uses a degree2 rational representation with nine poles and four original spans over [0,4]. A circle pole polygon is not the circle's sampled outline.

Builders copy their own output occurrences. Keep the generated source for editing. Endpoint closure does not certify a topological wire, region or Solid. buildXYProfile also supports a line and an open polyline; a crossing open polyline is not a simple-region validator.

Build a bounded rectangle extrusion ​

ts
import { buildAxisRectangleExtrusion } from '@barocss/cad';

const part = buildAxisRectangleExtrusion({
  bodyId: 'part',
  profile: { kind: 'rectangle', id: 'footprint', origin: [4, -3], width: 7, height: 5 },
  distance: 6,
});
console.log(part.solidReport.volumeMM3); // 210
console.log(part.solidReport.areaMM2); // 214

This builder requires integer-mm origin, width, height and positive distance within its exact axis-box domain. It returns source2, the original profile, six planar faces, shell, native model and separate solid report. The profile report remains regionCertified:false; the shell report is distinct from the qualified solid report.

After editing source parameters, compile again and reconstruct/revalidate the actual new faces and shell. The old solid report cannot certify new geometry. An IGES export of the Curve and six Surfaces remains geometry entities, not a serialized closed Solid.

Give an original Line width and height ​

To retain an original Line while giving it a centered width, follow Line → width Face → direct extrusion. It uses a separate newer API profile and retains every complete source/Model context. Its six-Face closed abstract Shell has a different certification scope from the rectangle Solid builder above.

For dependent parameter edits, suppression and authored Save/Open, use the two-node Line-width extrusion graph. Its separate matching graph provider retains the complete source0 asset and literal-mm recipes; selective update counts remain distinct from prior cold validation.

Query original parameters and derivatives ​

Use curveDomain or surfaceDomain before querying. Do not assume every domain is [0,1]:

ts
import { curveDomain, evaluateCurveD1 } from '@barocss/cad';

const [a, b] = curveDomain(rectangle.curve);
const d1 = evaluateCurveD1(rectangle.curve, a + (b - a) / 8);
console.log(d1.point, d1.derivative);

rectangle comes from the first example. The query lies inside the first span. Derivatives use mm per original dimensionless parameter and are not normalized. evaluateSurfaceD1(surface,u,v) returns point, du and dv. Endpoints use the interior one-sided span. Exact interior knots refuse D1 when degree minus multiplicity is less than one. Point queries can still succeed there. A finite zero derivative does not certify regularity or define a unit normal.

Refine a Curve representation ​

To refine Curve coefficients without sculpting their shape, read source-qualified knot insertion. It retains the original parameter domain and complete mixed source, changes the control polygon, and separates bounded native observations from a CPU illustration. Its public API uses its own matching source profile.

Refine a Surface along U to compare complete control nets with evaluated U/V grids. The source-qualified operation keeps both original parameter domains and nonselected knots while inserting one coefficient row; its CPU projection adds no renderer or topology claim.

Sample a Surface for display ​

Use the quadratic rational Surface to compare a fixed nine-pole definition with evaluated center/off-center points. Its two typed Parameters change the interior while retaining the boundary curves. The guide separates coefficient poles, sampled U/V lines and GPU display.

Call tessellateSurface(surface,{countU,countV,revision}) after native validation. It samples uniform original U/V parameters including endpoints and returns {packet,report}. The host supplies revision; it records provenance, not freshness. Packet arrays use U-major rows and preserve native XYZ in mm under the declared right-handed Y-up convention.

Normals come from area-weighted incident triangles. They are preview normals rather than exact derivative normals. The five probes per cell report maxSampledDeviationMM with certified:false. Increasing the grid can improve a sampled display but cannot turn this report into a global error bound. Collapsed triangles and inconsistent normals refuse; no repair silently changes the packet.

Follow the complete plane example and GPU conversion guide. Keep native data independently from the mesh.

Persist intent rather than pixels ​

For reusable length/scalar calculations in authored geometry, use Source3 quantity functions. Its separate newer compiler profile retains typed named/default call receipts and compiles raw source again with explicit sourceVersion 3. Keep that raw source for its function intent; this example adds no project codec or native editor Save/Open admission.

For the current modeling API, use snapshot.save() and cad.load(text) as shown in the modeling guide. For advanced or historical native document families, use their matching exported serializer/parser pair. The public API includes rectangle features, polygon prisms, circle feature graphs, driven sketches, assemblies and additional bounded families. Each has its own version, ID/reference rules and error domain. Read operation families to choose the operation.

Do not use a display GLB as an editable-document format. Do not serialize an IR or operation report as a universal CAD file merely because it is JSON data. Preserve source, native document, owning IDs and reports separately. Failed edits must leave the previously accepted host document available.


Historical advanced-guide source snapshot: local Git 5f5ad866205a21510ac69552e704cc162fa253b5. packages/barocss-cad/package.json (Manifest; local source), packages/barocss-cad/src/index.ts (public root; local source), packages/barocss-cad/README.md (package README; local source). Source paths identify that fixed local snapshot. Local source is the authority for this manual.

Overview · Quickstart · Guides · API · Examples · Limits

Local manual snapshot. Availability is stated on each package page.