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
- You need a deterministic picture of a 3D scene (primitives, molecules, diagrams, small animations frame by frame) on a machine without a GPU or display.
- You need a mesh file (OBJ, STL or PLY) assembled from cubes, boxes, spheres, cylinders, cones, capsules, planes, rings, tubes, triangles or voxel text.
- You want textured, lit and optionally shadowed renders described entirely in a script.
- Do not use it for interactive viewing, GPU shading, physics engines or loading external 3D models: the host exposes none of these.
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
| Command | Effect |
|---|---|
| lmscript scene.lms | Compile the _lmcode_ block against the host schema, run the host and continue the outer script |
| lmscript --check scene.lms | Compile only; reports type and signature errors without rendering |
| lmctl autorun URL | Run a repository example straight from its raw GitHub URL; it writes images/NAME.png |
| lmmagnum --version | Print the host name and version |
| lmmagnum --lmcode-schema --json | Print the embedded schema JSON (schema format 2, name lmmagnum) |
| lmmagnum --lmcode-signatures | Print 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
| Direction | What |
|---|---|
| Input | An _lmcode_ block with cli="lmmagnum"; the context object scene and the functions material and magnum_version |
| Input files | Optional texture images for scene.texture_file: PNG, JPEG, BMP or TGA |
| Output files | scene.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) |
| Result | run_lmcode returns a map with ok and result; result is whatever the block set with lmcode_return_set or lmcode_return_put |
| Failure | ok 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
- Render and export calls overwrite the target path. Write into a dedicated output directory.
- The standard file functions (file_read, file_write, file_append) are unrestricted; treat a block as code with the file permissions of the caller.
- Create output directories in the outer script before run_lmcode.
- Always test r.ok after run_lmcode and stop on failure; do not assume an image exists.
- Large frame counts cost CPU time: the rasterizer is software only. Start with a small image size and few frames.
- Bytecode passed to --lmcode must be a readable file no larger than 16 MiB.
- Use only signatures printed by lmmagnum --lmcode-signatures for the installed version.
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
| Exit | Meaning | Observed case |
|---|---|---|
| 0 | Success | --version, schema and signature queries, a completed --lmcode run |
| 2 | CLI usage error; failure frame with phase cli and code CLI_USAGE | No arguments or an unknown flag |
| 3 | Load 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
- Run lmmagnum --version and confirm the version you expect (0.2.15 at the time of writing).
- Run lmscript --check on the script: exit status 0 means the block matches the host schema.
- After the run, require r.ok and check that every output file exists and is not empty.
- Return scene.shape_count() and scene.triangle_count() with lmcode_return_put and compare them with what the script should have built.
- Open the PNG and look at it: framing, lighting and visibility mistakes do not raise errors.
See also the quick reference, the guide and the reference.