lmblender API guide
Overview
lmblender executes lmscript DSL v5 bytecode and builds a Cycles CPU scene. Use it when a task needs procedural geometry, materials, lighting, image rendering, animation, or renders of imported meshes from a script. It is a standalone renderer, not a Python interface to Blender.
Install and run
Declare the host in an lmscript block. This book pins v0.3.6 so every example uses the same released binary:
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); }
Run the source from an empty working directory with lmscript. Create every output directory before the host writes into it. run_lmcode compiles the block, runs the host and returns a record with ok and result. For a render that may take longer than lmscript's default 60-second system timeout, save the bytecode with savedsl, build an argument list from dsl_cli(p) plus --lmcode and the file, and call system with an explicit timeout in milliseconds. The host ships lmcode_std_v3 with 206 signatures; the full API is in the reference.
Scene coordinates
Coordinates are right-handed and Z-up. Units are scene units. Colors passed as float channels are linear RGB values in the range 0 to 1. API methods use positional arguments; there are no implicit unit conversions.
Geometry and materials
| Call | Purpose |
|---|---|
| scene.cube(size), scene.uv_sphere(radius, segments, rings, smooth), scene.cylinder(radius, depth, segments, capped) | Create primitive meshes centered around their origin. |
| scene.plane(size), scene.torus(major, minor, segments, rings, smooth), scene.cone(radius, depth, segments, capped) | Create additional primitives. The torus major radius must be greater than its minor radius. |
| mesh.translate(x, y, z), mesh.rotate_x(angle), mesh.rotate_y(angle), mesh.rotate_z(angle), mesh.scale(x, y, z) | Place or resize a mesh. Rotations use radians. |
| scene.material(r, g, b, metallic, roughness, transmission, er, eg, eb, emission_strength) | Create a Principled surface material. |
| material.texture_maps(normal, roughness, metallic, ao), material.bump(strength, distance, scale) | Add image maps or procedural bump to a material. |
| mesh.set_material(material), mesh.set_smooth(enabled) | Assign a material or smooth shading to a mesh. |
Camera and lighting
- scene.camera_look_at(px, py, pz, tx, ty, tz, fov) sets a perspective camera with vertical field of view in degrees.
- scene.camera_orthographic(px, py, pz, tx, ty, tz, vertical_span) sets an orthographic view.
- scene.fit_camera(margin) frames visible geometry. Set a camera explicitly for stable composition.
- scene.studio_setup() adds an automatic camera, floor, and soft lights around the scene.
- scene.area_light(px, py, pz, tx, ty, tz, r, g, b, power, size) places a square light at a position and aims it at a target; r, g, and b are its linear color.
- scene.point_light(x, y, z, r, g, b, power) creates a point source. scene.sun_light(dx, dy, dz, r, g, b, power, angle_degrees) takes a direction vector, color, strength, and angular diameter in degrees.
- scene.world_color(r, g, b, strength) sets linear world color and illumination.
- scene.sky_texture(elevation, rotation, intensity) and scene.environment_texture(path, rotation, strength) use environment lighting.
Rendering and animation
| Call | Output |
|---|---|
| scene.render_png(path, samples, width, height) | One display-transformed PNG. A sample count of zero selects the active preset. |
| scene.render_exr(path, samples, width, height) | One scene-linear OpenEXR image. |
| scene.render_passes(prefix, samples, width, height) | Combined, depth, normal, and albedo passes. |
| scene.render_sequence(pattern, first, last, samples, width, height) | Numbered images for each inclusive animation frame. |
| scene.render_apng(path, first, last, samples, width, height, fps) | An animated PNG. |
| mesh.keyframe_transform(frame, x, y, z, interpolation) | Set absolute position keys with linear or ease interpolation. |
| scene.set_view_transform(name), scene.render_settings(bounces, seed, denoise) | Choose Standard, Filmic, or AgX display mapping and render behavior. |
Still renders use the authored object state. Keyframes are evaluated by sequence and animation render methods. For a loop, make the first and last keyframes match.
Import and checks
- scene.import_obj(path), scene.import_ply(path), scene.import_stl(path), and scene.import_gltf(path) load mesh files.
- mesh.vertex_count(), mesh.triangle_count(), and bounds methods help verify imported or generated geometry. mesh.material_count() reports stored slots on imported mesh data; it does not count materials assigned to procedural scene objects.
- scene.expect_int(actual, expected) checks an integer result.
Limits
Render dimensions are limited to 4096 per side and 16 million pixels. A scene is limited to 4096 meshes and materials, 10 million vertices, and 20 million triangles. Input images are limited to 64 MiB each and 64 megapixels decoded. APNG output is limited to 240 frames and 64 million total frame-pixels. CPU rendering uses four worker threads by default, capped by available cores; set a different count with scene.set_threads(n).
Errors and recovery
Host errors are printed as a JSON object with a phase, code, message, and, for DSL errors, a line and column. A load error usually means bytecode was compiled against a different schema; rerun the lmscript source to compile it again. A host validation error names the method and accepted values. Reduce scene size or samples for a budget or timeout error, and fix invalid input paths rather than retrying them unchanged.
The CLI reports its release and renderer versions with lmblender --version, prints the human-readable API with lmblender --lmcode-schema, prints embedded schema JSON with lmblender --lmcode-schema --json, and prints canonical method signatures with lmblender --lmcode-signatures.
Known differences from Blender
The tutorial compares matched scenes rendered with lmblender and Blender 5.2.2. The median image difference across the tested examples was 0.52 of 255 after renderer fixes. Remaining differences include sun-disc sparkles in sky-texture, distinct motion-blur sampling, OBJ material interpretation, and differing glTF vertex splitting. See the comparison section for details.