Use lmblender to build and check a rendered scene

Use lmblender when a task needs a procedural 3D scene, a CPU-rendered image, an animation, or a render of imported mesh geometry from LMScript. The host uses Cycles and executes compiled DSL bytecode directly. It does not start Blender or run Python.

Purpose

Translate a concrete visual or geometry request into a small, reproducible LMScript program. The program should create the geometry, assign materials, set the camera and lights, render to a path inside the working directory, and check a measurable property such as triangle count or volume when applicable.

When to use it

Install

Install lmscript through the lmctl package. The host is fetched automatically the first time the script runs. Pin the exact version when reproducible output matters. This book uses lmblender v0.3.6.

npm install -g @lmctl-ai/lmctl
lmscript --version
lmscript 0.2.482

Declare the released host on the _lmcode_ block and execute it with run_lmcode, which compiles the block against the host schema, runs the host and returns a record with ok and result:

p = _lmcode_ cli="lmblender" install="github:lmctl-ai/lmblender@v0.3.6";
let ball = scene.uv_sphere(1.0, 48, 24, true);
scene.studio_setup();
scene.render_png("build/ball.png", 16, 640, 480);
end _lmcode_
r = run_lmcode(p);
if (!r.ok) { println("lmblender failed"); exit(1); }

Commands

Run a complete lmscript file from an empty working directory. Output paths are relative to that directory. Make each output directory before calling the host.

lmscript scene.lms

Useful host commands are:

For renders that can take longer than sixty seconds, save the bytecode with savedsl(p, "build/scene.dslb"), build an argument list and pass an explicit timeout in milliseconds to system, as the repository examples do. Keep the render within the example-book limit of 180 seconds.

argv = dsl_cli(p);
push(argv, "--lmcode");
push(argv, "build/scene.dslb");
r = system(argv, 240000);

Inputs and outputs

Scene code lives inside an LMScript LMCode block. Values such as sample counts, dimensions, mesh sizes, and colors are supplied as positional arguments. Coordinates are right-handed and Z-up; distances are scene units and RGB color channels are linear values between zero and one.

Safety rules

Worked examples

Start with one sphere and the automatic studio setup. The source should create the output directory before rendering:

if (!file_exists("build")) { mkdir("build"); }
p = _lmcode_ cli="lmblender" install="github:lmctl-ai/lmblender@v0.3.6";
let ball = scene.uv_sphere(1.0, 48, 24, true);
scene.studio_setup();
scene.render_png("build/ball.png", 16, 640, 480);
end _lmcode_
r = run_lmcode(p);
if (!r.ok) { println("lmblender failed"); exit(1); }

For a geometric model, check a count before adding presentation details (expect_int is the only assertion in the schema):

let box = scene.cube(2.0);
scene.expect_int(box.triangle_count(), 12);

The Cornell box shows indirect lighting. The gear pair combines a mesh generator with lmblender's renderer. Browse the example book for twelve complete scenes and their runnable source.

Errors and exit codes

Exit code 0 is success, 2 is a usage error or unknown preset name, 3 is a load or run error reported as a JSON line with ok false, phase, code and message, and 4 is APP_FAIL or a failed schema write. See the reference for the full tables.

How to verify

  1. Run lmscript from a clean directory and read the full host output.
  2. Confirm the requested image or mesh file exists and is nonempty.
  3. Check image dimensions and inspect the composition at the target size.
  4. Assert mesh counts or numeric properties in the scene when the task has measurable geometry requirements.
  5. For a release check, compare --version with the pinned release tag, compare --lmcode-schema --json byte-for-byte with the repository schema, and compare --lmcode-signatures with the generated schema signatures.