lmcad tutorial

Install lmscript with npm install -g @lmctl-ai/lmctl. Each program below is an lmscript file whose _lmcode_ block names lmcad; lmscript downloads the released host through install=, compiles the block against the schema that binary reports, and run_lmcode executes it.

1. Write a block and run it

Save this as hello.lms.

mkdir("build");
p = _lmcode_ cli="lmcad" install="github:lmctl-ai/lmcad@latest";
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 _lmcode_
r = run_lmcode(p);
if (!r.ok) { println(r.stderr + r.stdout); }
assert(r.ok);
println("wrote build/hello.png");

Check the file without running it, then run it. run_lmcode returns a result with ok and result.

lmscript --check hello.lms
lmscript hello.lms
wrote build/hello.png
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 fragment, inside a block, 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);
}

The complete loop example is in the repository; run it in an empty directory:

lmctl autorun https://raw.githubusercontent.com/lmctl-ai/lmcad/main/examples/loop-row.lms

3. Create a tween animation

The tween example reads keyframes from CSV with read_keyframes_csv, interpolates position and color in block loops, and assembles an APNG with scene.animation, add_frame and finish.

lmctl autorun https://raw.githubusercontent.com/lmctl-ai/lmcad/main/examples/tween.lms

What you learned

A _lmcode_ block binds to the host schema, compiles to bytecode and runs inside the native host through run_lmcode. The same typed API supports solid modeling, range loops, CSV-backed keyframes, PNG output and APNG animation. The reference lists every method.