Port of https://github.com/tscircuit/stepts to MoonBit

async fn main {
let design = @cad.Design::new(name="my-model")
.add(
@cad.Cuboid::new(20, 20, 20)
.with_name("base")
.with_color(@cad.Rgb::orange())
)
.add(
@cad.CalibrationChamferBlock::new(10, 10, 5, chamfer_size_mm=1.0)
.with_name("top-part")
.translate(z=20)
)
design.write_step(Some("model.step"))
}| Format | How | Notes |
|---|---|---|
| STEP | ./examples/run-example.sh 39 -o fits.step | Exact B-Rep; opens in any CAD viewer or slicer. |
| STL | ./examples/run-example.sh 39 -o fits.step -stl | OCCT tessellation; set STL_DEFLECTION=<mm> (default 0.05). |
| PNG | ./examples/run-example.sh 39 -o fits.step --png=preview.png | Four views (iso/top/front/side); needs OCCT, macOS sips, and Inkscape (one view without it). |
| Blender | ./examples/run-example.sh 39 --blend model.blend | Real booleans and an editable scene; see below. |
| glTF | ./examples/run-example.sh 39 --gltf fits.gltf | Z-up JSON with an embedded buffer; opens in web/three.js glTF viewers. Written by the example itself. |
design.write_blender_python(Some("model.py"))blender --background --factory-startup --python model.py./scripts/manage_examples.py all --bpydesign.to_gltf_file(Some("model.gltf"))./examples/run-example.sh 39 --gltf fits.gltffn parse_example(step_text : String) -> Unit {
match @parse.parse_repository_from_string_result(step_text) {
@parse.ParseRepositoryResult::Ok(repo) => {
let normalized = repo.to_step_file()
println("entities=" + repo.len().to_string())
println(normalized)
}
@parse.ParseRepositoryResult::Err(info) =>
@cli.eprintln(@parse.format_step_parse_error(info))
}
}design.write_step_evaluated(Some("part.step"))./examples/run-example.sh 40 --eval=hole.step --png=hole.pnglet block = @cad.Cuboid::new(40.0, 30.0, 10.0).with_name("block")
let top = @cad.Design::new(name="probe")
.add(block)
.planar_faces()
.aligned_with((0.0, 0.0, 1.0)) // normal parallel to +Z
.sort_by_z(ascending=false) // highest first
.first_matching(fn(_f) { true }) // -> FaceInfo?
let profile = @cad.Profile2D::new(@cad.Profile2D::circle(8.0, segments=48))
let design = @cad.Design::new(name="hole").add(
@cad.cut_on_face(
block,
profile,
top, // FaceInfo
10.0, // cut depth
center=top.local_xy(top.center()),
),
)@cad.bolt_circle(6, 22.0) // hole centers on a bolt circle
@cad.grid_of_holes(3, 2, 20.0, 15.0) // centered, row-major centers
@cad.point_on_circle(10.0, 90.0) // one point at an angle
@cad.midpoint(a, b)
@cad.project_point_to_line(p, a, b) // perpendicular foot
let profile = @cad.Profile2D::new(@cad.Profile2D::centered_circle(60.0))
.with_hole_at(0.0, 0.0, 20.0) // central bore
.with_bolt_circle(6, 22.0, 5.0, fit=@cad.Fit::Free) // holes grow by the fit
let plate = @cad.ExtrudedProfile::new(profile.outer, 8.0, holes=profile.holes)let hole = @cad.Profile2D::hole_with_fit(5.0, fit=@cad.Fit::Free)
let plate = @cad.ExtrudedProfile::new(
@cad.Profile2D::rect(40.0, 20.0),
5.0,
holes=[hole],
)$ moon version --all
moon 0.1.20261016 (1af328f 2026-10-16) ~/.moon/bin/moon
moonc v0.10.16+b1a0e846e (2026-10-16) ~/.moon/bin/moonc
moonrun 0.1.20261016 (1af328f 2026-10-16) ~/.moon/bin/moonrun
pub struct RawEntity {
name : String
args : String
}