lmcad tutorial

Run these examples from the lmcad source directory after installing the latest lmscript compiler and building lmcad. The first script source below is saved as hello.lms in a text editor.

1. Write a DSL block and compile it

p = _dsl_ schema="schema/lmcad.dsl.json";
scene.background(0.04, 0.06, 0.1);
let blue = material().color(0.18, 0.62, 0.88);
scene.box(2.0, 1.2, 0.8, blue);
scene.camera(42.0, 0.0, 3.0, 8.0, 0.0, 0.0, 0.0);
scene.directional_light(-0.4, -1.0, -0.5, 0.72);
scene.fill_light(0.8, -0.2, 0.9, 0.42);
scene.ambient(0.24);
scene.fit_camera(42.0, 1.25);
scene.render_png("build/hello.png", 480, 320);
end _dsl_
savedsl(p, "build/hello.dslb");

Compile the file with the published compiler and run the bytecode. The compiler emits a bytecode file; the host prints one JSON result line.

npx --yes --package=@lmctl-ai/lmctl -- lmscript hello.lms build/hello.dslb
exit status: 0
build/lmcad --dsl build/hello.dslb
{"ok": true, "result": null}
file build/hello.png
build/hello.png: PNG image data, 480 x 320, 8-bit/color RGB, non-interlaced

Open build/hello.png in an image viewer to inspect the fitted camera, silhouette and lighting.

2. Render a range loop

Range loops use an integer counter and an exclusive upper bound. This example places seven boxes along the x-axis:

for (i in range(0, 7)) {
  let x = float(i) - 3.0;
  scene.box(0.7, 0.7, 0.7, mat).position(x, 0.0, 0.0);
}

Compile and run the complete loop example:

npx --yes --package=@lmctl-ai/lmctl -- lmscript examples/loop-row.lms build/loop-row.dslb
exit status: 0
build/lmcad --dsl build/loop-row.dslb
{"ok": true, "result": null}
file build/loop-row.png
build/loop-row.png: PNG image data, 480 x 270, 8-bit/color RGB, non-interlaced

3. Create a tween animation

The tween example reads keyframes from CSV, interpolates position and color in DSL loops, writes numbered PNGs and assembles a 30-frame APNG.

npx --yes --package=@lmctl-ai/lmctl -- lmscript examples/tween.lms build/tween.dslb
exit status: 0
build/lmcad --dsl build/tween.dslb
{"ok": true, "result": null}
ls -lh build/tween.apng build/tween-15.png
build/tween-15.png  9.1K
build/tween.apng  288K
file build/tween-15.png
build/tween-15.png: PNG image data, 320 x 240, 8-bit/color RGB, non-interlaced

What you learned

A script binds to a schema, compiles to portable bytecode and runs inside the native host. The same typed API supports solid modeling, range loops, CSV-backed keyframes, PNG output and APNG animation.