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 ...]
FlagBehavior
--versionPrint lmfilament and the version
--lmcode-schemaPrint all signatures as text
--lmcode-schema --jsonPrint the embedded schema JSON (dsl.schema 2, name lmfilament, 7 types, context fil)
--lmcode-signaturesPrint 269 lines: 1 context line, 206 standard signatures and 62 host methods
--lmcode FILE [FILE ...]Run compiled programs; this is what run_lmcode drives
ExitMeaning
0Success
2Usage error, phase cli, code CLI_USAGE
3Load error, phase load, code LOAD_BAD_BYTECODE

Context and types

NameKindMain members
filContext object of type Filamentversion, material, material_file, scene, mesh and texture factories
FilamentType, 19 methodsbox, sphere, icosphere, cylinder, cone, capsule, plane, ring, triangle, text, tube_between, mesh_obj, texture, texture_checker, texture_file
MaterialType, 7 methodsname, package_size, save, set_float, set_float3, set_float4, set_texture
MeshType, 6 methodsvertex_count, triangle_count, has_colors, has_tangents, compute_tangents, save_obj
TextureType, 7 methodswidth, height, pixel, filter, wrap, repeat, save_png
SceneType, 14 methodsadd, add_at, add_part, node, camera, skybox, directional_light, point_light, sun, shadows, render_frames, render_png, renderable_count, light_count
PartType, 5 methodstranslate, rotate, scale, parent, visible
NodeType, 4 methodstranslate, rotate, scale, parent
Standard librarylmcode_std_v3, 206 signaturesStrings, 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