lmmagnum guide: scenes, the software rasterizer and its limits

This guide explains how lmmagnum is put together and how to think about a scene script. For commands and safety rules read the skill page; for exact signatures read the reference.

Overview

lmmagnum connects two things: the Magnum graphics library, which supplies the primitive meshes, and lmscript, which supplies the language. A script describes a scene inside an _lmcode_ block; lmscript compiles the block against the schema embedded in the host and run_lmcode executes it. The host renders with its own software rasterizer, so the same script produces a picture on a laptop, a container or a CI runner without a GPU or a window system.

The repository gallery shows what this covers: headless analogues of the Magnum example index and of the Magnum Python examples, ports of lmfilament examples, and molecule, DNA, Cornell box, Saturn and truss scenes shared with lmblender and lmcad.

Architecture

LayerRole
Outer lmscript programCreates directories, holds the _lmcode_ block, calls run_lmcode, checks r.ok, and may call ffmpeg or other hosts afterwards
_lmcode_ blockStatically typed code compiled to bytecode against the lmmagnum schema; loops, variables and the standard library are available
lmmagnum hostOne static executable: runs the bytecode, owns the scene, rasterizes on the CPU, writes image and mesh files
Magnum and CorradeLinked into the host; supply the primitives. magnum_version() reports the embedded build

The public repository holds the README, documentation images and examples; binary releases are published on its releases page, and the implementation source is maintained privately.

Workflow

  1. Create output directories in the outer script, for example mkdir("images").
  2. Open a block with cli="lmmagnum" and the install attribute.
  3. Set the scene: background, ambient level, shadows.
  4. Create materials with material() and, if needed, textures.
  5. Add shapes with the scene constructors and place them with translate, rotate and scale; group them when a hierarchy helps.
  6. Set one camera and at least one directional light.
  7. Render to PNG or PPM, export a mesh if wanted, and return counts with lmcode_return_put.
  8. Outside the block call run_lmcode, test r.ok and use the files.
mkdir("images");
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.cylinder(0.5, 1.2, c).translate(-1.0, 0.0, 0.0);
scene.cone(0.5, 1.2, c).translate(1.0, 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("images/pair.png", 800, 400);
end _lmcode_
r = run_lmcode(p);
assert(r.ok);

Domain model

Scene

There is one scene per host process, reached through the context object scene. It owns every shape, group, texture, the camera and the lights, plus global settings: background colour, ambient level and the shadow map switch.

Shapes and primitives

Every constructor takes its dimensions and a material and returns a Shape. The solids are cube, box, sphere, icosphere, cylinder, cone and capsule; the flat and helper shapes are plane, ring, triangle, tube_between and text, which builds voxel text from a 5x7 font. A shape can be moved, rotated and scaled, recoloured, textured, named, hidden with visible(false) and parented to a group.

Groups and the scene graph

scene.group() creates a node with its own translate, rotate and scale. Shapes and groups attach to it with parent, so a transform on a group carries everything below it. The primitives-scene-graph and model-viewer examples build a posed toy robot this way.

Materials and textures

A material carries a colour and the shading parameters specular, shininess and roughness, and optionally a texture. Textures are created blank and painted with pixel, generated as a checker, or loaded from a PNG, JPEG, BMP or TGA file. A texture multiplies the material colour, so use white to show the image as is. Sampling uses trilinear mip filtering, nearest filtering on request, and repeat, clamp or mirror wrapping. Cubes, spheres, cylinders, cones, capsules, planes, text, rings, tubes and triangles carry UVs.

Camera and lights

scene.camera sets the view and returns a Camera whose look_at method re-aims it, which is how the arcball example orbits a scene over 12 frames. scene.directional_light adds a light and returns a Light whose intensity can be changed later. scene.ambient sets the fill level and scene.shadows(true) turns on a shadow map, as in the shadows example.

Rendering, accumulation and export

render_png and render_ppm rasterize the current scene at the requested size. The accumulation methods sum several renders and save the result, which the motion blur example uses for a 16-frame accumulation. export_obj, export_stl and export_ply write the scene geometry as a mesh.

Animation

The host renders still frames. An animation is a loop inside the block that updates transforms or visibility and renders one numbered PNG per step; the outer script then encodes the frames with ffmpeg. The gallery uses this for a 24-frame bounce GIF, a 36-frame textured planet turn and the four 240-frame homepage clips.

Limits

Licensing

The README, docs, images and examples are MIT licensed under LICENSE-examples. Releases up to and including v0.2.14 were published under the MIT License; later binary releases use the Lattice Systems Binary License 1.0 in LICENSE. Third-party components keep their own licenses.

Where to go next