cascade-core
v2.0.5
Published
Reusable CAD modeling engine built on OpenCascade WASM. Evaluate CAD code in a Web Worker and get triangle mesh data back.
Downloads
446
Maintainers
Readme
cascade-core
Reusable CAD modeling engine built on OpenCascade WASM. Evaluate CAD code in a Web Worker and get triangle mesh data back — no GUI dependencies.
This is the headless engine that powers Cascade Studio. Use it to embed parametric CAD modeling in any web application.
Install
npm install cascade-coreQuick Start
import { CascadeEngine } from 'cascade-core';
const engine = new CascadeEngine({ workerUrl: './cascade-worker.js' });
await engine.init();
const result = await engine.evaluate(`
let box = Box(20, 20, 20);
FilletEdges(box, 3, Edges(box).max([0,0,1]).indices());
`, { guiState: { 'Cache?': true } });
// result.meshData = { faces: [...], edges: [...] }
// Render with Three.js, Babylon.js, or any WebGL frameworkCopy cascade-worker.js, cascadestudio.wasm, and fonts/ from node_modules/cascade-core/dist/ to your static assets directory.
Examples
These are all built with the cascade-core standard library — try them live:
API
new CascadeEngine({ workerUrl })
Create an engine instance. workerUrl is the path to the bundled worker file.
engine.init() → Promise
Load the worker and OpenCascade WASM. Resolves when ready.
engine.evaluate(code, options?) → Promise<{ meshData, sceneOptions }>
Evaluate CAD code and return triangulated mesh data.
code— JavaScript string using the standard library (Box, Sphere, Sketch, etc.)options.guiState— slider/checkbox state objectoptions.maxDeviation— mesh resolution (default 0.1)- Returns
{ meshData: { faces, edges }, sceneOptions }
engine.meshHistoryStep(index, maxDeviation?) → Promise
Triangulate a specific modeling history step.
engine.exportSTEP() → Promise<string>
Export the current shape as STEP file text.
engine.on(event, handler) / engine.off(event, handler)
Listen for events: log, error, Progress, resetWorking, modelHistory, addSlider, addButton, addCheckbox, addTextbox, addDropdown, saveFile.
engine.isReady / engine.isWorking
Boolean status properties.
engine.dispose()
Terminate the worker and clean up.
Standard Library
The evaluated code has access to these functions:
- Primitives:
Box,Sphere,Cylinder,Cone,Circle,Polygon,Text3D,BSpline,Wedge - Sketch:
new Sketch([x,y], plane?).LineTo().Fillet().ArcTo().BSplineTo().End().Face() - Transforms:
Translate,Rotate,Scale,Mirror - Booleans:
Union,Difference,Intersection - Operations:
Extrude,Revolve,Loft,Pipe,Offset,FilletEdges,ChamferEdges - Selectors:
Edges(shape).ofType().parallel().max().min().indices() - Measurement:
Volume,SurfaceArea,CenterOfMass - GUI:
Slider,Checkbox(values come fromguiState)
See the full TypeScript definitions in types/StandardLibraryIntellisense.ts.
OpenSCAD
import { OpenSCADTranspiler } from 'cascade-core';
const transpiler = new OpenSCADTranspiler();
const jsCode = transpiler.transpile(`
difference() {
cube(20, center=true);
sphere(r=12);
}
`);
const result = await engine.evaluate(jsCode);Credits
- opencascade.js (CAD Kernel — OCCT 8.0.0 RC4 via Embind)
- opentype.js (Font Parsing for Text3D)
- potpack (Texture Atlas Packing)
License
MIT
