lmcad

lmcad logo

lmcad is a native lmcode host for parametric 3D solids: OpenCASCADE B-rep modelling, volume checks, and a built-in software renderer that writes PNG, APNG, STL and OBJ with no GPU or display. This page is the quick reference for lmcad 0.1.5; programs are lmscript files with a _lmcode_ block run by run_lmcode.

Install and run

npm install -g @lmctl-ai/lmctl        # lmscript + lmctl (Node.js >= 24)
export GITHUB_TOKEN=$(gh auth token)  # optional: avoids GitHub API rate limits on first install
lmctl autorun https://raw.githubusercontent.com/lmctl-ai/lmcad/main/examples/gear-train.lms
lmscript --check model.lms            # compile the blocks only
lmscript model.lms                    # compile and run

Minimal program

mkdir("images");
p = _lmcode_ cli="lmcad" install="github:lmctl-ai/lmcad@latest";
let shape = scene.box(2.0, 3.0, 4.0, material().color(0.2, 0.55, 0.85));
scene.assert_close(shape.volume(), 24.0, 0.000001);
scene.fit_camera(42.0, 1.2);
scene.directional_light(-0.5, -1.0, -0.4, 0.8);
scene.ambient(0.2);
scene.render_png("images/box-volume.png", 320, 240);
end _lmcode_
r = run_lmcode(p);
if (!r.ok) { println(r.stderr + r.stdout); }
assert(r.ok);
println("wrote images/box-volume.png");

Host protocol

CommandEffect
lmcad --versionPrints lmcad X.Y.Z. The release tag vX.Y.Z and the binary version must agree for install="github:lmctl-ai/lmcad@latest".
lmcad --lmcode-schemaPrints a compact summary: the context line, then free functions, then members grouped by type.
lmcad --lmcode-schema --jsonPrints the embedded schema bytes exactly (dsl.schema 2, name lmcad). This is the compiler input.
lmcad --lmcode-signaturesPrints the canonical signature list of the host registry, host and standard: 271 lines in 0.1.5.
lmcad --lmcode FILE [FILE ...]Runs compiled program files in argument order. Objects and scene state persist between files; locals are fresh for each file. The first failure stops execution.
Exit codeMeaning
0Success; one JSON result line per completed block.
2Invalid command line. The host prints its usage line and a CLI_USAGE result (phase cli).
3Program file load failure or a block or host run failure.
4Another application failure.

Context, types and functions

NameKindRole
sceneContext object of type SceneThe one entry point of a block.
SceneHost typeSolids, sketches, lights, cameras, renders, exports and assertions.
ShapeHost typeHandle to an OpenCASCADE solid: transforms, booleans, edge treatment, volume and bounds.
SketchHost typeStraight-segment 2D polygon to extrude or revolve.
MaterialHost typeDisplay color and Blinn-Phong surface parameters.
CameraHost typeView returned by camera and fit_camera.
LightHost typeDirectional or fill light.
AnimationHost typeAPNG writer.
KeyframesHost typeCollection read from CSV; supports len, at and for-in iteration.
KeyframeHost typeOne CSV row: time, position and color.
material()Host functionReturns a Material.
read_keyframes_csv(string)Host functionReturns Keyframes.

Main methods

TaskCalls
Primitivesscene.box, scene.sphere, scene.cylinder, scene.tube_between
Sketch solidsscene.sketch().point(x, y) ... close(), then scene.extrude or scene.revolve_y
Booleansshape.union, shape.cut, shape.intersect
Edges and shellsshape.fillet, shape.chamfer, shape.hollow, shape.hollow_top
Transformsshape.position, translate, rotate, scale, mirror
Measure and assertshape.volume, min_x to max_z, scene.assert_close(actual, expected, tolerance)
View and lightscene.camera, scene.fit_camera(fov, margin), directional_light, fill_light, ambient, background, supersample
Outputscene.render_png, render_ppm, export_stl, export_obj, scene.animation with add_frame and finish

lmcad 0.1.5 ships 206 standard-library signatures (the lmcode_std_v3 catalog at 206). The current lmcode_std_v3 catalog has 226 signatures, adding the REST and CLI interfaces; lmcad picks those up when it syncs and releases, and the 0.1.5 binary does not register them. Full signatures are in the reference.

Gray rectangular plate with eight round through-holes
A plate cut with a loop of cylinder bores.
Red rectangular brick with two rows of raised cylindrical studs
A patterned brick built by looping over unions.
Blue tapered hollow vase with an open top
A hollow vessel made from a revolved sketch.
Blue hollow mug with a rounded handle
A revolved cup body with a fused handle.
Shaded sphere at an intermediate animation position
One frame from a CSV-keyframed tween.

More