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
- Use lmblender for a 3D still image, an EXR, a frame sequence, APNG output, or a render of imported OBJ, STL, PLY or glTF geometry.
- Use it for scripted variations, repeatable product scenes, technical diagrams, and visual checks of imported geometry.
- Use Blender itself when the task depends on a Blender UI, Python add-ons, simulation systems, or a feature not exposed by the lmblender API.
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:
- lmblender --version prints the host and linked renderer versions.
- lmblender --lmcode-schema prints a compact API summary.
- lmblender --lmcode-schema --json prints the embedded schema.
- lmblender --lmcode-signatures prints the registered DSL signatures.
- lmblender --presets lists embedded scene presets, and lmblender --preset-show NAME prints one preset as JSON.
- lmblender --lmcode FILE.dslb runs compiled bytecode; this is the host protocol that run_lmcode drives.
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.
- PNG is the display-transformed still image format. EXR preserves scene-linear image data.
- Image sequences and APNG use inclusive first and last frame numbers.
- OBJ/MTL, STL, ASCII PLY and glTF 2.0 triangle meshes are supported inputs. The 0.3.6 schema has no mesh export method.
- The host vendors the lmcode_std_v3 standard library with 206 signatures (files, strings, math, Json, typed containers). The current catalog has 226 including the REST and CLI interfaces, which lmblender 0.3.6 does not ship.
- Mesh methods expose vertex count, triangle count, material count, and axis-aligned bounds.
- Host failures print a JSON object with the error code, a message, and a source line and column when available.
Safety rules
- Work in a fresh directory and write outputs only to paths created for the task.
- Treat scene scripts and imported files as trusted input. Do not run an unknown LMScript file without reviewing its filesystem and system calls.
- Keep image and mesh inputs within documented size and geometry limits. Do not claim a mesh is ready to manufacture based only on a successful render.
- Set a camera explicitly for predictable composition. Check that the render file exists and has the requested dimensions.
- On Linux arm64, use v0.3.6 or newer for denoising on CPUs without SVE, including AWS Graviton2. The v0.3.4 and earlier arm64 releases can fault with an illegal instruction when denoising is enabled.
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.
- LOAD_BAD_BYTECODE or LOAD_SCHEMA_MISMATCH: compile the source again with the schema that matches the installed host.
- RUN_HOST: a call used an invalid range, missing input, or unsupported combination. Follow the JSON message and correct that argument.
- RENDER_TIMEOUT: lower the image size or sample count, or set a higher per-render limit when appropriate.
- RUN_TIMEOUT or RUN_BUDGET: the full program exceeded its time or instruction budget. Reduce the workload before retrying.
- OUTPUT_PATH: create the output directory and use a path inside the allowed output root.
- On Linux arm64, an illegal instruction during denoising indicates an older or incompatible binary. Upgrade to v0.3.6 or newer.
How to verify
- Run lmscript from a clean directory and read the full host output.
- Confirm the requested image or mesh file exists and is nonempty.
- Check image dimensions and inspect the composition at the target size.
- Assert mesh counts or numeric properties in the scene when the task has measurable geometry requirements.
- 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.