lmmagnum skill: build and render 3D scenes headlessly from LMScript

This page tells an agent how to install, call and verify lmmagnum, the lmcode host that drives Magnum primitives through a built-in software rasterizer. Everything here was checked against lmmagnum 0.2.15 and the examples in the lmctl-ai/lmmagnum repository.

Purpose

lmmagnum is one static executable that builds a scene from Magnum primitives inside an lmscript _lmcode_ block, renders it on the CPU and exports PNG or PPM images and STL, OBJ or PLY meshes. It needs no GPU, no window system and no shared libraries.

When to use it

Install

npm install -g @lmctl-ai/lmctl
lmscript scene.lms             # downloads the lmmagnum release on first use

The install attribute github:lmctl-ai/lmmagnum@latest on the block makes lmscript download and cache the release binary. The current release lane publishes native Linux binaries named lmmagnum-linux-x64 and lmmagnum-linux-arm64; earlier releases may contain macOS and Windows assets that the current lane no longer produces.

Commands

CommandEffect
lmscript scene.lmsCompile the _lmcode_ block against the host schema, run the host and continue the outer script
lmscript --check scene.lmsCompile only; reports type and signature errors without rendering
lmctl autorun URLRun a repository example straight from its raw GitHub URL; it writes images/NAME.png
lmmagnum --versionPrint the host name and version
lmmagnum --lmcode-schema --jsonPrint the embedded schema JSON (schema format 2, name lmmagnum)
lmmagnum --lmcode-signaturesPrint one line per context, function and method signature (267 lines in 0.2.15)
lmmagnum --lmcode FILE [FILE ...]Run compiled bytecode; this is what run_lmcode invokes for you

Inputs and outputs

DirectionWhat
InputAn _lmcode_ block with cli="lmmagnum"; the context object scene and the functions material and magnum_version
Input filesOptional texture images for scene.texture_file: PNG, JPEG, BMP or TGA
Output filesscene.render_png and scene.render_ppm (path, width, height); scene.export_obj, export_stl, export_ply (path); texture.save_png (path); scene.save_accumulated_png (path)
Resultrun_lmcode returns a map with ok and result; result is whatever the block set with lmcode_return_set or lmcode_return_put
Failureok is false and phase, code and message are set in the result frame

Paths are relative to the working directory of the lmscript process. The host does not create missing directories in the repository examples; they call mkdir("images") in the outer script first.

Safety rules

Worked examples

Two solids, one picture, one mesh

prog = _lmcode_ cli="lmmagnum" install="github:lmctl-ai/lmmagnum@latest";
scene.background(0.08, 0.09, 0.12);
let m = material().color(0.85, 0.45, 0.2).specular(0.4);
scene.cube(1.0, m).translate(-1.5, 0.0, 0.0).rotate(20.0, 30.0, 0.0);
scene.sphere(0.6, m).translate(1.5, 0.0, 0.0);
scene.camera(40.0, 0.0, 1.5, 9.0, 0.0, -0.5, 0.0);
scene.directional_light(-0.5, -1.0, -0.4, 0.9);
scene.render_png("scene.png", 800, 400);
scene.export_obj("scene.obj");
lmcode_return_put("shapes", scene.shape_count());
lmcode_return_put("triangles", scene.triangle_count());
lmcode_return_put("magnum", magnum_version());
end _lmcode_
r = run_lmcode(prog);
println(json_stringify(r));
require(r.ok, "render failed");
lmscript scene.lms
{"ok":true,"result":{"shapes":2,"triangles":2220,"magnum":"369e9620ab22"}}

The run writes scene.png (800 by 400) and scene.obj next to the script.

The repository primitives example

mkdir("images");
mkdir("build");
p = _lmcode_ cli="lmmagnum" install="github:lmctl-ai/lmmagnum@latest";
scene.background(0.08, 0.09, 0.12);
let c = material().color(0.85, 0.45, 0.2).specular(0.4);
scene.cube(1.0, c).translate(-3.0, 0.0, 0.0).rotate(20.0, 30.0, 0.0);
scene.sphere(0.6, c).translate(-1.5, 0.0, 0.0);
scene.icosphere(0.6, 2, c).translate(0.0, 0.0, 0.0);
scene.cylinder(0.5, 1.2, c).translate(1.5, 0.0, 0.0);
scene.cone(0.5, 1.2, c).translate(3.0, 0.0, 0.0);
scene.capsule(0.4, 1.0, c).translate(0.0, -1.6, 0.0);
scene.camera(40.0, 0.0, 1.5, 9.0, 0.0, -0.5, 0.0);
scene.directional_light(-0.5, -1.0, -0.4, 0.9);
scene.render_png("images/primitives.png", 800, 400);
scene.export_obj("build/primitives.obj");
end _lmcode_
r = run_lmcode(p);
if (!r.ok) { println(r.stderr + r.stdout); }
assert(r.ok);
println("wrote images/primitives.png");

Run a gallery example from its URL

lmctl autorun https://raw.githubusercontent.com/lmctl-ai/lmmagnum/main/examples/primitives.lms

Errors and exit codes

ExitMeaningObserved case
0Success--version, schema and signature queries, a completed --lmcode run
2CLI usage error; failure frame with phase cli and code CLI_USAGENo arguments or an unknown flag
3Load or run error; failure frame with phase load and code RUN_HOST for unreadable bytecode--lmcode with a missing file
lmmagnum --lmcode /nonexistent.dslb
bytecode input must be a readable file no larger than 16 MiB
LMCODE_RETURN_BEGIN
{"ok":false,"phase":"load","code":"RUN_HOST","message":"bytecode input must be a readable file no larger than 16 MiB"}
LMCODE_RETURN_END

The result frame is delimited by the lines LMCODE_RETURN_BEGIN and LMCODE_RETURN_END. Compile errors (unknown method, wrong argument types) are reported by lmscript before the host starts; fix them with lmscript --check.

How to verify

See also the quick reference, the guide and the reference.