Build a scene with lmblender

Start in an empty directory, then extend one scene a step at a time. Each tutorial script is available from the source repository. The examples on this site pin lmblender v0.3.6.

1. First render

Goal: confirm lmscript can download lmblender and render one image.

First check that lmscript is installed (see the index for the install command):

lmscript --version

It should print a version line such as lmscript 0.2.482. The scripts on this page are the repository tutorial files: they save the bytecode with savedsl and call the host with --lmcode, which is the host protocol. The shorter equivalent for quick renders is r = run_lmcode(p), which returns a record with ok and result.

Save this as 01-first-render.lms in an empty directory, or download it:

curl -O https://raw.githubusercontent.com/lmctl-ai/lmblender/main/docs/tutorial/code/01-first-render.lms
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("first-render.png", 16, 640, 480);
end _lmcode_
file = "first-render.dslb";
savedsl(p, file);
r = system ${dsl_cli(p)} --lmcode ${file};
delete_file(file);
if (r.code != 0) { println(trim(r.stdout)); if (trim(r.stderr) != "") { println(trim(r.stderr)); } exit(1); }
println("wrote first-render.png");

Run it:

lmscript 01-first-render.lms

Expected output (the first run also downloads the lmblender release, so it takes longer):

wrote first-render.png

What each part does:

The sphere looks flat white because it has no material yet; meshes without one get a plain unlit surface. Page 4 adds materials.

2. Place objects

Goal: put several objects in the scene where you want them.

Page 1 had one sphere at the origin. This page adds a cube and a torus and moves each object with translate so that it rests on the ground at Z = 0.

Download the full script, or copy it from below:

curl -O https://raw.githubusercontent.com/lmctl-ai/lmblender/main/docs/tutorial/code/02-place-objects.lms
p = _lmcode_ cli="lmblender" install="github:lmctl-ai/lmblender@v0.3.6";
let ball = scene.uv_sphere(1.0, 48, 24, true);
ball.translate(0.0, 0.0, 1.0);
let box = scene.cube(1.6);
box.translate(-2.8, 0.0, 0.8);
let ring = scene.torus(0.8, 0.25, 48, 16, true);
ring.translate(2.8, 0.0, 0.25);
scene.studio_setup();
scene.render_png("place-objects.png", 16, 640, 480);
end _lmcode_
file = "place-objects.dslb";
savedsl(p, file);
r = system ${dsl_cli(p)} --lmcode ${file};
delete_file(file);
if (r.code != 0) { println(trim(r.stdout)); if (trim(r.stderr) != "") { println(trim(r.stderr)); } exit(1); }
println("wrote place-objects.png");

Run it:

lmscript 02-place-objects.lms

Expected output:

wrote place-objects.png

The torus reads as a flat ring and the shapes are still unlit; pages 3 and 4 fix the view and the surfaces.

3. Camera

Goal: choose the camera position yourself.

The script is page 2 plus one line: camera_look_at after studio_setup.

Download the full script, or copy it from below:

curl -O https://raw.githubusercontent.com/lmctl-ai/lmblender/main/docs/tutorial/code/03-camera.lms
p = _lmcode_ cli="lmblender" install="github:lmctl-ai/lmblender@v0.3.6";
let ball = scene.uv_sphere(1.0, 48, 24, true);
ball.translate(0.0, 0.0, 1.0);
let box = scene.cube(1.6);
box.translate(-2.8, 0.0, 0.8);
let ring = scene.torus(0.8, 0.25, 48, 16, true);
ring.translate(2.8, 0.0, 0.25);
scene.studio_setup();
scene.camera_look_at(0.0, -9.0, 3.5, 0.0, 0.0, 0.8, 40.0);
scene.render_png("camera.png", 16, 640, 480);
end _lmcode_
file = "camera.dslb";
savedsl(p, file);
r = system ${dsl_cli(p)} --lmcode ${file};
delete_file(file);
if (r.code != 0) { println(trim(r.stdout)); if (trim(r.stderr) != "") { println(trim(r.stderr)); } exit(1); }
println("wrote camera.png");

Run it:

lmscript 03-camera.lms

Expected output:

wrote camera.png

Always set a camera, or call studio_setup or fit_camera. Without one, lmblender uses a fallback view; it is aspect-corrected in v0.3.6. Explicit cameras still give the most predictable composition.

4. Materials

Goal: give each object a color and surface.

The script is page 3 plus three set_material lines, with the samples raised from 16 to 32 because shiny surfaces need more samples to look smooth.

Download the full script, or copy it from below:

curl -O https://raw.githubusercontent.com/lmctl-ai/lmblender/main/docs/tutorial/code/04-materials.lms
p = _lmcode_ cli="lmblender" install="github:lmctl-ai/lmblender@v0.3.6";
let ball = scene.uv_sphere(1.0, 48, 24, true);
ball.translate(0.0, 0.0, 1.0);
let box = scene.cube(1.6);
box.translate(-2.8, 0.0, 0.8);
let ring = scene.torus(0.8, 0.25, 48, 16, true);
ring.translate(2.8, 0.0, 0.25);
ball.set_material(scene.material(0.08, 0.25, 0.85, 0.0, 0.3, 0.0, 0.0, 0.0, 0.0, 0.0));
box.set_material(scene.material(0.9, 0.15, 0.06, 0.0, 0.4, 0.0, 0.0, 0.0, 0.0, 0.0));
ring.set_material(scene.material(0.95, 0.7, 0.2, 1.0, 0.25, 0.0, 0.0, 0.0, 0.0, 0.0));
scene.studio_setup();
scene.camera_look_at(0.0, -9.0, 3.5, 0.0, 0.0, 0.8, 40.0);
scene.render_png("materials.png", 32, 640, 480);
end _lmcode_
file = "materials.dslb";
savedsl(p, file);
r = system ${dsl_cli(p)} --lmcode ${file};
delete_file(file);
if (r.code != 0) { println(trim(r.stdout)); if (trim(r.stderr) != "") { println(trim(r.stderr)); } exit(1); }
println("wrote materials.png");

Run it:

lmscript 04-materials.lms

Expected output:

wrote materials.png

scene.material takes ten numbers in this order:

The gold torus is metallic 1.0 with roughness 0.25; the cube and sphere are dielectric. set_material assigns a material to one mesh, and one material can be shared by several meshes.

5. Lights

Goal: light the scene yourself instead of using studio_setup.

The script is page 4 with studio_setup() replaced by three calls: a ground plane, a world color, and an area light. The camera from page 3 keeps the framing.

Download the full script, or copy it from below:

curl -O https://raw.githubusercontent.com/lmctl-ai/lmblender/main/docs/tutorial/code/05-lights.lms
p = _lmcode_ cli="lmblender" install="github:lmctl-ai/lmblender@v0.3.6";
let ball = scene.uv_sphere(1.0, 48, 24, true);
ball.translate(0.0, 0.0, 1.0);
let box = scene.cube(1.6);
box.translate(-2.8, 0.0, 0.8);
let ring = scene.torus(0.8, 0.25, 48, 16, true);
ring.translate(2.8, 0.0, 0.25);
ball.set_material(scene.material(0.08, 0.25, 0.85, 0.0, 0.3, 0.0, 0.0, 0.0, 0.0, 0.0));
box.set_material(scene.material(0.9, 0.15, 0.06, 0.0, 0.4, 0.0, 0.0, 0.0, 0.0, 0.0));
ring.set_material(scene.material(0.95, 0.7, 0.2, 1.0, 0.25, 0.0, 0.0, 0.0, 0.0, 0.0));
scene.ground_plane(0.0, 20.0, 0.7, 0.7, 0.72);
scene.world_color(0.6, 0.7, 0.9, 0.3);
scene.area_light(-3.0, -4.0, 5.0, 0.0, 0.0, 1.0, 1.0, 0.92, 0.82, 600.0, 3.0);
scene.camera_look_at(0.0, -9.0, 3.5, 0.0, 0.0, 0.8, 40.0);
scene.render_png("lights.png", 32, 640, 480);
end _lmcode_
file = "lights.dslb";
savedsl(p, file);
r = system ${dsl_cli(p)} --lmcode ${file};
delete_file(file);
if (r.code != 0) { println(trim(r.stdout)); if (trim(r.stderr) != "") { println(trim(r.stderr)); } exit(1); }
println("wrote lights.png");

Run it:

lmscript 05-lights.lms

Expected output:

wrote lights.png

The bright speckles on the floor around the torus are light bounced off the gold metal that 32 samples have not averaged out yet. More samples remove them at the cost of render time. scene.render_settings(bounces, seed, true) enables OIDN denoising. The v0.3.6 Linux arm64 release is safe on AWS Graviton2; use a fixed release or turn denoising off with older v0.3.4 and earlier binaries.

6. Textures

Goal: replace flat colors with procedural textures and surface bump.

The script is page 5 with two materials changed: the sphere becomes a checker, and the cube becomes noise with bump. The ground plane becomes a checker floor.

Download the full script, or copy it from below:

curl -O https://raw.githubusercontent.com/lmctl-ai/lmblender/main/docs/tutorial/code/06-textures.lms
p = _lmcode_ cli="lmblender" install="github:lmctl-ai/lmblender@v0.3.6";
let ball = scene.uv_sphere(1.0, 48, 24, true);
ball.translate(0.0, 0.0, 1.0);
let box = scene.cube(1.6);
box.translate(-2.8, 0.0, 0.8);
let ring = scene.torus(0.8, 0.25, 48, 16, true);
ring.translate(2.8, 0.0, 0.25);
ball.set_material(scene.checker_material(0.08, 0.25, 0.85, 0.9, 0.92, 0.95, 3.0, 0.3));
let stone = scene.noise_material(0.55, 0.12, 0.05, 0.95, 0.55, 0.35, 3.0, 0.6);
stone.bump(0.4, 0.1, 12.0);
box.set_material(stone);
ring.set_material(scene.material(0.95, 0.7, 0.2, 1.0, 0.25, 0.0, 0.0, 0.0, 0.0, 0.0));
scene.checker_ground(20.0, 1.0);
scene.world_color(0.6, 0.7, 0.9, 0.3);
scene.area_light(-3.0, -4.0, 5.0, 0.0, 0.0, 1.0, 1.0, 0.92, 0.82, 600.0, 3.0);
scene.camera_look_at(0.0, -9.0, 3.5, 0.0, 0.0, 0.8, 40.0);
scene.render_png("textures.png", 32, 640, 480);
end _lmcode_
file = "textures.dslb";
savedsl(p, file);
r = system ${dsl_cli(p)} --lmcode ${file};
delete_file(file);
if (r.code != 0) { println(trim(r.stdout)); if (trim(r.stderr) != "") { println(trim(r.stderr)); } exit(1); }
println("wrote textures.png");

Run it:

lmscript 06-textures.lms

Expected output:

wrote textures.png

To use an image file instead, call scene.image_material("file.png", roughness). PNG and JPEG color images use sRGB decoding in v0.3.6, matching Blender more closely.

7. Import a mesh

Goal: render geometry from a file next to the built-in shapes.

The script is page 6 plus a small OBJ pyramid. Before the LMCode block, lmscript writes pyramid.obj with write_file, so nothing needs downloading. Inside the block, four lines import it, check it, move it behind the sphere, and give it a material.

Download the full script, or copy it from below:

curl -O https://raw.githubusercontent.com/lmctl-ai/lmblender/main/docs/tutorial/code/07-import-a-mesh.lms
obj = """o pyramid
v -1 -1 0
v 1 -1 0
v 1 1 0
v -1 1 0
v 0 0 1.5
f 1 3 2
f 1 4 3
f 1 2 5
f 2 3 5
f 3 4 5
f 4 1 5
""";
write_file("pyramid.obj", obj);
p = _lmcode_ cli="lmblender" install="github:lmctl-ai/lmblender@v0.3.6";
let ball = scene.uv_sphere(1.0, 48, 24, true);
ball.translate(0.0, 0.0, 1.0);
let box = scene.cube(1.6);
box.translate(-2.8, 0.0, 0.8);
let ring = scene.torus(0.8, 0.25, 48, 16, true);
ring.translate(2.8, 0.0, 0.25);
ball.set_material(scene.checker_material(0.08, 0.25, 0.85, 0.9, 0.92, 0.95, 3.0, 0.3));
let stone = scene.noise_material(0.55, 0.12, 0.05, 0.95, 0.55, 0.35, 3.0, 0.6);
stone.bump(0.4, 0.1, 12.0);
box.set_material(stone);
ring.set_material(scene.material(0.95, 0.7, 0.2, 1.0, 0.25, 0.0, 0.0, 0.0, 0.0, 0.0));
let pyramid = scene.import_obj("pyramid.obj");
scene.expect_int(pyramid.triangle_count(), 6);
pyramid.translate(1.5, 2.6, 0.0);
pyramid.set_material(scene.material(0.85, 0.6, 0.2, 0.0, 0.35, 0.0, 0.0, 0.0, 0.0, 0.0));
scene.checker_ground(20.0, 1.0);
scene.world_color(0.6, 0.7, 0.9, 0.3);
scene.area_light(-3.0, -4.0, 5.0, 0.0, 0.0, 1.0, 1.0, 0.92, 0.82, 600.0, 3.0);
scene.camera_look_at(0.0, -9.0, 3.5, 0.0, 0.0, 0.8, 40.0);
scene.render_png("import-a-mesh.png", 32, 640, 480);
end _lmcode_
file = "import-a-mesh.dslb";
savedsl(p, file);
r = system ${dsl_cli(p)} --lmcode ${file};
delete_file(file);
if (r.code != 0) { println(trim(r.stdout)); if (trim(r.stderr) != "") { println(trim(r.stderr)); } exit(1); }
println("wrote import-a-mesh.png");

Run it:

lmscript 07-import-a-mesh.lms

Expected output:

wrote import-a-mesh.png

The script also leaves pyramid.obj in the directory.

8. Animation

Goal: move an object over time and render each frame.

The script is page 7 plus two keyframe lines for the sphere, with render_png replaced by render_sequence at a smaller size so three frames render quickly. Like page 7 (and pages 9 and 10), it also writes pyramid.obj next to the script.

Download the full script, or copy it from below:

curl -O https://raw.githubusercontent.com/lmctl-ai/lmblender/main/docs/tutorial/code/08-animation.lms
obj = """o pyramid
v -1 -1 0
v 1 -1 0
v 1 1 0
v -1 1 0
v 0 0 1.5
f 1 3 2
f 1 4 3
f 1 2 5
f 2 3 5
f 3 4 5
f 4 1 5
""";
write_file("pyramid.obj", obj);
p = _lmcode_ cli="lmblender" install="github:lmctl-ai/lmblender@v0.3.6";
let ball = scene.uv_sphere(1.0, 48, 24, true);
ball.translate(0.0, 0.0, 1.0);
let box = scene.cube(1.6);
box.translate(-2.8, 0.0, 0.8);
let ring = scene.torus(0.8, 0.25, 48, 16, true);
ring.translate(2.8, 0.0, 0.25);
ball.set_material(scene.checker_material(0.08, 0.25, 0.85, 0.9, 0.92, 0.95, 3.0, 0.3));
let stone = scene.noise_material(0.55, 0.12, 0.05, 0.95, 0.55, 0.35, 3.0, 0.6);
stone.bump(0.4, 0.1, 12.0);
box.set_material(stone);
ring.set_material(scene.material(0.95, 0.7, 0.2, 1.0, 0.25, 0.0, 0.0, 0.0, 0.0, 0.0));
ball.keyframe_transform(0, -1.2, -1.5, 1.0, "ease");
ball.keyframe_transform(2, 1.2, -1.5, 1.0, "ease");
let pyramid = scene.import_obj("pyramid.obj");
scene.expect_int(pyramid.triangle_count(), 6);
pyramid.translate(1.5, 2.6, 0.0);
pyramid.set_material(scene.material(0.85, 0.6, 0.2, 0.0, 0.35, 0.0, 0.0, 0.0, 0.0, 0.0));
scene.checker_ground(20.0, 1.0);
scene.world_color(0.6, 0.7, 0.9, 0.3);
scene.area_light(-3.0, -4.0, 5.0, 0.0, 0.0, 1.0, 1.0, 0.92, 0.82, 600.0, 3.0);
scene.camera_look_at(0.0, -9.0, 3.5, 0.0, 0.0, 0.8, 40.0);
scene.render_sequence("animation-{frame}.png", 0, 2, 16, 320, 240);
end _lmcode_
file = "animation.dslb";
savedsl(p, file);
r = system ${dsl_cli(p)} --lmcode ${file};
delete_file(file);
if (r.code != 0) { println(trim(r.stdout)); if (trim(r.stderr) != "") { println(trim(r.stderr)); } exit(1); }
println("wrote animation-0.png, animation-1.png, animation-2.png");

Run it:

lmscript 08-animation.lms

Expected output:

wrote animation-0.png, animation-1.png, animation-2.png

9. View transforms

Goal: keep very bright light readable by choosing how scene light maps to pixels.

The script is page 8 plus one glowing orb above the scene, with render_sequence replaced by two still renders: once with the Standard view transform and once with AgX. The keyframes from page 8 stay in the script; still renders ignore keys and use each object's authored position.

Download the full script, or copy it from below:

curl -O https://raw.githubusercontent.com/lmctl-ai/lmblender/main/docs/tutorial/code/09-view-transforms.lms
obj = """o pyramid
v -1 -1 0
v 1 -1 0
v 1 1 0
v -1 1 0
v 0 0 1.5
f 1 3 2
f 1 4 3
f 1 2 5
f 2 3 5
f 3 4 5
f 4 1 5
""";
write_file("pyramid.obj", obj);
p = _lmcode_ cli="lmblender" install="github:lmctl-ai/lmblender@v0.3.6";
let ball = scene.uv_sphere(1.0, 48, 24, true);
ball.translate(0.0, 0.0, 1.0);
let box = scene.cube(1.6);
box.translate(-2.8, 0.0, 0.8);
let ring = scene.torus(0.8, 0.25, 48, 16, true);
ring.translate(2.8, 0.0, 0.25);
ball.set_material(scene.checker_material(0.08, 0.25, 0.85, 0.9, 0.92, 0.95, 3.0, 0.3));
let stone = scene.noise_material(0.55, 0.12, 0.05, 0.95, 0.55, 0.35, 3.0, 0.6);
stone.bump(0.4, 0.1, 12.0);
box.set_material(stone);
ring.set_material(scene.material(0.95, 0.7, 0.2, 1.0, 0.25, 0.0, 0.0, 0.0, 0.0, 0.0));
ball.keyframe_transform(0, -1.2, -1.5, 1.0, "ease");
ball.keyframe_transform(2, 1.2, -1.5, 1.0, "ease");
let pyramid = scene.import_obj("pyramid.obj");
scene.expect_int(pyramid.triangle_count(), 6);
pyramid.translate(1.5, 2.6, 0.0);
pyramid.set_material(scene.material(0.85, 0.6, 0.2, 0.0, 0.35, 0.0, 0.0, 0.0, 0.0, 0.0));
let lamp = scene.glow_orb(0.0, 1.2, 3.0, 0.5, 1.0, 0.55, 0.2, 8.0);
scene.checker_ground(20.0, 1.0);
scene.world_color(0.6, 0.7, 0.9, 0.3);
scene.area_light(-3.0, -4.0, 5.0, 0.0, 0.0, 1.0, 1.0, 0.92, 0.82, 600.0, 3.0);
scene.camera_look_at(0.0, -9.0, 3.5, 0.0, 0.0, 0.8, 40.0);
scene.set_view_transform("Standard");
scene.render_png("view-standard.png", 32, 320, 240);
scene.set_view_transform("AgX");
scene.render_png("view-agx.png", 32, 320, 240);
end _lmcode_
file = "view-transforms.dslb";
savedsl(p, file);
r = system ${dsl_cli(p)} --lmcode ${file};
delete_file(file);
if (r.code != 0) { println(trim(r.stdout)); if (trim(r.stderr) != "") { println(trim(r.stderr)); } exit(1); }
println("wrote view-standard.png, view-agx.png");

Run it:

lmscript 09-view-transforms.lms

Expected output:

wrote view-standard.png, view-agx.png

10. When it fails

Goal: read an lmblender error and fix the script.

The script is page 9 rendered once with AgX at full size, with one deliberate mistake on line 20: the torus has its two radii swapped, so the tube is thicker than the ring. It writes pyramid.obj before the scene block runs, so that file appears even though the render fails.

Download the full script, or copy it from below:

curl -O https://raw.githubusercontent.com/lmctl-ai/lmblender/main/docs/tutorial/code/10-when-it-fails.lms
obj = """o pyramid
v -1 -1 0
v 1 -1 0
v 1 1 0
v -1 1 0
v 0 0 1.5
f 1 3 2
f 1 4 3
f 1 2 5
f 2 3 5
f 3 4 5
f 4 1 5
""";
write_file("pyramid.obj", obj);
p = _lmcode_ cli="lmblender" install="github:lmctl-ai/lmblender@v0.3.6";
let ball = scene.uv_sphere(1.0, 48, 24, true);
ball.translate(0.0, 0.0, 1.0);
let box = scene.cube(1.6);
box.translate(-2.8, 0.0, 0.8);
let ring = scene.torus(0.25, 0.8, 48, 16, true);
ring.translate(2.8, 0.0, 0.25);
ball.set_material(scene.checker_material(0.08, 0.25, 0.85, 0.9, 0.92, 0.95, 3.0, 0.3));
let stone = scene.noise_material(0.55, 0.12, 0.05, 0.95, 0.55, 0.35, 3.0, 0.6);
stone.bump(0.4, 0.1, 12.0);
box.set_material(stone);
ring.set_material(scene.material(0.95, 0.7, 0.2, 1.0, 0.25, 0.0, 0.0, 0.0, 0.0, 0.0));
ball.keyframe_transform(0, -1.2, -1.5, 1.0, "ease");
ball.keyframe_transform(2, 1.2, -1.5, 1.0, "ease");
let pyramid = scene.import_obj("pyramid.obj");
scene.expect_int(pyramid.triangle_count(), 6);
pyramid.translate(1.5, 2.6, 0.0);
pyramid.set_material(scene.material(0.85, 0.6, 0.2, 0.0, 0.35, 0.0, 0.0, 0.0, 0.0, 0.0));
let lamp = scene.glow_orb(0.0, 1.2, 3.0, 0.5, 1.0, 0.55, 0.2, 8.0);
scene.checker_ground(20.0, 1.0);
scene.world_color(0.6, 0.7, 0.9, 0.3);
scene.area_light(-3.0, -4.0, 5.0, 0.0, 0.0, 1.0, 1.0, 0.92, 0.82, 600.0, 3.0);
scene.camera_look_at(0.0, -9.0, 3.5, 0.0, 0.0, 0.8, 40.0);
scene.set_view_transform("AgX");
scene.render_png("when-it-fails.png", 32, 640, 480);
end _lmcode_
file = "when-it-fails.dslb";
savedsl(p, file);
r = system ${dsl_cli(p)} --lmcode ${file};
delete_file(file);
if (r.code != 0) { println(trim(r.stdout)); if (trim(r.stderr) != "") { println(trim(r.stderr)); } exit(1); }
println("wrote when-it-fails.png");

Run it:

lmscript 10-when-it-fails.lms

Expected output (the script exits with status 1 and writes no image):

{"ok": false, "phase": "run", "code": "RUN_HOST", "message": "dsl line 20:18: torus radii require major > minor > 0", "line": 20, "column": 18}

The host reports every failure as one JSON line on standard output:

Fix: swap the two radii back to scene.torus(0.8, 0.25, 48, 16, true) and run the script again. It then prints:

wrote when-it-fails.png

Every script on these pages prints r.stdout on failure because the JSON error is on standard output; standard error is usually empty.

RUN_HOST and OUTPUT_PATH errors were reproduced while writing the tutorial. The older denoiser issue is fixed in v0.3.6; use that release or newer on Linux arm64.

11. Compared with Blender

The comparison ports example scenes to Blender 5.2.2 and matches geometry, camera, light, materials, and render settings. The median mean absolute RGB difference across 51 pairs was 0.52 of 255 after fixes to sRGB texture decoding, display transforms, the fallback camera, and the arm64 denoiser build.

On Linux arm64, the images on this site were rendered with the released lmblender v0.3.6 binary on an AWS Graviton2 host. Denoising was enabled. The v0.3.6 release fixes the SVE instruction crash present in v0.3.4 and earlier.

Read the full comparison notes for per-example images, timings, and reproduction steps.

What you learned

You built a scene from primitives, positioned the camera, added materials and light, used texture and imported geometry, rendered animation frames, selected a display transform, and diagnosed a host error. The API guide summarizes the methods and limits.