lmmagnum

lmmagnum is a native lmcode host that builds a 3D scene from Magnum primitives, renders it with a built-in software rasterizer and exports PNG, PPM, STL, OBJ or PLY. It is one static executable with no GPU, window system or shared library requirement, and lmscript installs it automatically.

This page is the quick reference. The latest release checked here is lmmagnum 0.2.15; it ships the 206-signature lmcode_std_v3 standard library next to its 60 host signatures.

Install and run

npm install -g @lmctl-ai/lmctl
lmscript scene.lms             # downloads the lmmagnum release on first use
lmscript --check scene.lms     # compile the _lmcode_ block against the host schema

The install attribute github:lmctl-ai/lmmagnum@latest on the block makes lmscript download and cache the release binary. The current release lane publishes Linux x64 and arm64 binaries. Run a repository example straight from its URL (it writes images/primitives.png):

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

Minimal runnable example

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");

Saved as scene.lms and run with lmscript scene.lms, the program writes scene.png and scene.obj and prints:

lmscript scene.lms
{"ok":true,"result":{"shapes":2,"triangles":2220,"magnum":"369e9620ab22"}}

Host CLI and protocol

InvocationEffectExit
lmmagnum --versionPrint lmmagnum and its version, for example lmmagnum 0.2.150
lmmagnum --lmcode-schema --jsonPrint the embedded schema JSON (dsl.schema 2, name lmmagnum) that lmscript compiles against0
lmmagnum --lmcode-signaturesPrint one line per context, function and method signature: 267 lines in 0.2.150
lmmagnum --lmcode FILE [FILE ...]Run compiled bytecode files; the result frame is printed between LMCODE_RETURN_BEGIN and LMCODE_RETURN_END0 or 3
Anything elseUsage text and a failure frame with phase cli and code CLI_USAGE2
ItemValue
Block headercli="lmmagnum" install="github:lmctl-ai/lmmagnum@latest"
Outer callr = run_lmcode(prog) returns a map with ok and result; on failure ok is false and phase, code and message are set
Result valueSet inside the block with lmcode_return_set(value) or lmcode_return_put(name, value)
Exit codes0 success, 2 CLI usage, 3 load or run error
Bytecode limitEach --lmcode input must be a readable file no larger than 16 MiB
Standard librarylmcode_std_v3, 206 signatures in release 0.2.15 (the current catalog has 226; see the reference)

Host API quick reference

The single context object is scene, of type Scene. Builder methods return their receiver so calls chain. Argument descriptions follow the usage in the repository examples.

CallReturnsPurpose
material()MaterialNew material; chain color(r, g, b), specular(v), shininess(v), roughness(v), texture(tex)
magnum_version()stringIdentifier of the embedded Magnum build
scene.background(r, g, b), scene.ambient(v), scene.shadows(on)SceneBackground colour, ambient light level, shadow map switch
scene.cube(size, m), scene.box(x, y, z, m), scene.sphere(radius, m), scene.icosphere(radius, subdivisions, m)ShapeSolid primitives
scene.cylinder(radius, length, m), scene.cone(radius, length, m), scene.capsule(radius, length, m)ShapeRound primitives taking two floats and a material
scene.plane(size, m), scene.ring(float, float, m), scene.text(string, size, m)ShapeFlat quad, ring, voxel text from a 5x7 font
scene.tube_between(x1, y1, z1, x2, y2, z2, radius, m)ShapeTube between two points (bonds, struts, streamlines)
scene.triangle(nine floats, m)ShapeOne triangle from three points
shape.translate(x, y, z), rotate(x, y, z), scale(x, y, z)ShapeTransform; rotation arguments are degrees in the examples
shape.color(r, g, b), texture(tex), name(string), visible(bool), parent(group)ShapePer-shape overrides, naming, visibility and scene graph parent
scene.group()GroupScene graph node with translate, rotate, scale and parent(group)
scene.camera(seven floats)CameraCamera; camera.look_at(six floats) re-aims it
scene.directional_light(x, y, z, intensity)LightDirectional light; light.intensity(v) changes it
scene.texture(w, h), texture_checker(w, h, six floats), texture_file(path)TextureBlank, checker or file-backed texture (PNG, JPEG, BMP, TGA)
texture.pixel(x, y, r, g, b), filter(mode), wrap(mode), repeat(u, v), save_png(path), width(), height()Texture, void or intPaint, sampling modes (linear, nearest; repeat, clamp, mirror), save
scene.render_png(path, w, h), scene.render_ppm(path, w, h)voidRender the scene to an image file
scene.accumulate(int, int), reset_accumulation(), save_accumulated_png(path)voidFrame accumulation, used by the motion blur example
scene.export_obj(path), export_stl(path), export_ply(path)voidMesh export
scene.shape_count(), scene.triangle_count(), shape.triangle_count()intCounts for verification

Detail pages