lmfilament
lmfilament is a native host for the lmscript _lmcode_ statement that embeds Google Filament 1.78.1 (material compiler, engine, geometry tools) in one static executable. It builds headless scenes on the Filament noop backend and writes preview pictures with its own CPU rasterizer; it does not produce Filament pixels.
Install and run
npm install -g @lmctl-ai/lmctl
lmctl autorun https://raw.githubusercontent.com/lmctl-ai/lmfilament/main/examples/ball-stick.lms
lmscript --check scene.lms
lmscript scene.lms
The host binary is downloaded on demand through install="github:lmctl-ai/lmfilament@latest". The facts on this page were checked against lmfilament 0.3.21 (Linux x64 and arm64, glibc 2.35 or newer).
CLI and host protocol
usage: lmfilament --version | --lmcode-schema [--json] | --lmcode-signatures | --lmcode FILE [FILE ...]
| Flag | Behavior |
| --version | Print lmfilament and the version |
| --lmcode-schema | Print all signatures as text |
| --lmcode-schema --json | Print the embedded schema JSON (dsl.schema 2, name lmfilament, 7 types, context fil) |
| --lmcode-signatures | Print 269 lines: 1 context line, 206 standard signatures and 62 host methods |
| --lmcode FILE [FILE ...] | Run compiled programs; this is what run_lmcode drives |
| Exit | Meaning |
| 0 | Success |
| 2 | Usage error, phase cli, code CLI_USAGE |
| 3 | Load error, phase load, code LOAD_BAD_BYTECODE |
Context and types
| Name | Kind | Main members |
| fil | Context object of type Filament | version, material, material_file, scene, mesh and texture factories |
| Filament | Type, 19 methods | box, sphere, icosphere, cylinder, cone, capsule, plane, ring, triangle, text, tube_between, mesh_obj, texture, texture_checker, texture_file |
| Material | Type, 7 methods | name, package_size, save, set_float, set_float3, set_float4, set_texture |
| Mesh | Type, 6 methods | vertex_count, triangle_count, has_colors, has_tangents, compute_tangents, save_obj |
| Texture | Type, 7 methods | width, height, pixel, filter, wrap, repeat, save_png |
| Scene | Type, 14 methods | add, add_at, add_part, node, camera, skybox, directional_light, point_light, sun, shadows, render_frames, render_png, renderable_count, light_count |
| Part | Type, 5 methods | translate, rotate, scale, parent, visible |
| Node | Type, 4 methods | translate, rotate, scale, parent |
| Standard library | lmcode_std_v3, 206 signatures | Strings, math, files, collections, Json, result sink |
Minimal example
mkdir("build");
prog = _lmcode_ cli="lmfilament" install="github:lmctl-ai/lmfilament@latest";
let mat = fil.material("bakedColor", "material {\n name : BakedColor,\n requires : [\n color\n ],\n shadingModel : unlit,\n culling : none,\n featureLevel : 0\n}\n\nfragment {\n void material(inout MaterialInputs material) {\n prepareMaterial(material);\n material.baseColor = getColor();\n }\n}\n");
let s = fil.scene();
s.skybox(0.1, 0.125, 0.25);
s.camera(45.0, 0.0, 0.0, 3.0, 0.0, 0.0, 0.0);
let tri = fil.triangle();
s.add(tri, mat);
let frames = s.render_frames(2);
s.render_png("build/triangle.png", 800, 600);
lmcode_return_put("filament", fil.version());
lmcode_return_put("frames", frames);
lmcode_return_put("vertices", tri.vertex_count());
lmcode_return_put("renderables", s.renderable_count());
lmcode_return_put("package_bytes", mat.package_size());
end _lmcode_
r = run_lmcode(prog);
if (!r.ok) { println(r.stderr + r.stdout); }
assert(r.ok);
println(r.result);
lmscript triangle.lms
Using 'soft' CircularBuffer (12288 KiB)
FEngine (64 bits) created at 0x94eb860 (threading is enabled)
FEngine resolved backend: Noop
Backend feature level: 1
FEngine feature level: 1
{"filament":"1.78.1","frames":2,"vertices":3,"renderables":1,"package_bytes":152462}
More