meshforge

This reference documents main, which is ahead of the 0.4.0 release. Features marked "since 0.5.0" are not in 0.4.0 yet. Generated from docs/cli.md. The same text, as plain text for agents: llms-full.txt.

Contents

meshforge CLI

This page is for agents working in a shell (and the people writing them). The meshforge binary drives the same JSON command API as the Rust library and the wasm build (docs/command-api.md): a batch you write here runs unchanged in the browser.

Install it with cargo install meshforge-cli (or build it from the repository with cargo build --release -p meshforge-cli; the binary is target/release/meshforge). It is pure Rust with no C dependencies. The npm package (coming soon) will run the same CLI as WebAssembly (npx meshforge ..., single-threaded, without the experimental subcommands).

Quickstart

meshforge ops --text                             # every op name; then: meshforge ops OP [OP...] [--sig]
meshforge apply -e '{"op":"create_primitive","kind":"cube","name":"crate"}' -o crate.glb
meshforge preview crate.glb -o crate.png         # look at it
meshforge info crate.glb                         # counts, bbox, skins, attributes (JSON; --text for humans)

To make many small edits, keep the state in a session file:

meshforge apply --session crate.mfs -e '{"op":"create_primitive","kind":"cube","name":"crate"}'
meshforge apply --session crate.mfs -e '{"op":"select","object":"crate","select":{"faces_facing":[0,1,0]}}'
meshforge apply --session crate.mfs -e '{"op":"extrude","object":"crate","distance":0.1}'
meshforge preview crate.mfs -o crate.png --wireframe
meshforge apply --session crate.mfs -o crate.glb   # write the asset when it looks right

Output and exit codes

exitmeaning
0ok
1a command failed, or a file could not be read, decoded or written (code says which: parse, face_not_found, io, ...). The JSON error is on stdout.
2usage error: unknown flag, bad --views, wrong output extension, ...

Every error says how to fix it. Examples:

error: face 99 does not exist; mesh 'box' has 6 faces (ids 0..5)
  fix: Run 'meshforge apply - --in box.glb' with {"op":"query","object":"box","include":["faces"]} on stdin to list faces, or select by direction instead of ids: {"op":"select","object":"box","select":{"faces_facing":[0,1,0]}}

error: invalid command: unknown variant `extrud`, expected one of `create_primitive`, ...
  fix: did you mean 'extrude'? Valid ops: create_primitive, delete_object, extrude, ...

error: invalid command: unknown field `distanse`, expected one of `object`, `faces`, `distance`
  fix: did you mean 'distance'? Valid fields here: object, faces, distance. ...

error: malformed JSON in <stdin> at line 3, column 11: expected value at line 3 column 11
  {"op": 'query'}
         ^
  fix: JSON strings need double quotes ("), not single quotes

Commands

apply (alias: run)

meshforge apply [FILE|-] [-e JSON]... [--in [NAME=]PATH]... [-o OUT.glb|OUT.obj|OUT.stl]
                [--session FILE.mfs] [--dry-run] [--object NAME] [--max-faces N]
                [--max-total-faces N] [--preview OUT.png [--wireframe] [--highlight-selection] [--style debug|beauty]]
                [--keep-base64] [--brief | --full]
meshforge apply crate.json -o out/crate.glb
meshforge apply crate.json --dry-run
cat steps.json | meshforge apply - --session crate.mfs
meshforge apply --session crate.mfs -e '{"op":"extrude","object":"crate","distance":0.1}'
meshforge apply --in model.obj -o model.glb       # convert, no commands
meshforge apply --in part.stl -o part.glb         # STL in (welded), glTF out

Reply (abridged):

{"ok":true,"results":[],"applied":2,"objects":[{"name":"crate","tris":12,"shells":1,"boundary_loops":0,"bbox":[[-0.5,-0.5,-0.5],[0.5,0.5,0.5]]}],"glb_path":"out/crate.glb","glb_bytes":1716,"triangles":12,"vertices":24,"bbox":{"min":[-0.5,-0.5,-0.5],"max":[0.5,0.5,0.5],"center":[0,0,0],"size":[1,1,1]}}

Session files (.mfs)

--session crate.mfs creates the file if it is missing and updates it after every successful batch, atomically (a temp file renamed over it). A failed batch leaves it untouched, and a missing session is only created once something was logged: a mistyped --session typo.mfs with a failing or read-only command creates no file (stderr says so). A GLB round trip triangulates (glTF stores triangles), so the session is meshforge's own format: a JSON log of every state-changing command (file imports embedded), replayed through the command API on load. The kernel is deterministic, so replay restores the exact state: quads, object names, face and vertex ids, selections and the undo/redo history. undo works across calls. query and export_glb are not logged. To check a whole build in one call, {"op":"query","objects":"*","include":["volume","closed"]} returns a row per object (see "query" in docs/command-api.md). Loading replays the whole log; that is fast for props (milliseconds for a few hundred commands). Snapshots every N steps (to skip the replay) are planned once the core can serialize a Session (objects, selections and the undo stack); the format's version field will mark the change. meshforge info crate.mfs reports the session's objects (counts, bbox, selection), limits (max_faces, max_total_faces, total_faces) and history. An object with modifiers also gets modifiers: the stack, per stage counts (stages) and the evaluated counts (vertices, edges, faces, triangles) next to the cage counts; totals adds evaluated_faces and evaluated_triangles. --text prints modifiers: array -> evaluated (exported) 40 verts, 30 faces (60 tris); the counts above are the cage.

{"format":"meshforge-session","version":1,"meshforge":"0.1.0","max_faces":null,"max_total_faces":null,"log":[{"op":"create_primitive","kind":"cube","name":"crate"}, ...]}

preview (alias: render-preview)

meshforge preview <file.mfs|file.glb|file.obj> -o OUT.png [--views front,side,top,iso]
                  [--size 512] [--wireframe] [--shading auto|flat|smooth|keep [--angle-deg N]]
                  [--highlight-selection] [--cage] [--no-depth-cue] [--no-materials] [--uv [LAYER]]
                  [--style debug|beauty] [--per-object] [--object NAME]... [--no-labels]
                  [--commands JSON] [--pose JSON] [--skeleton] [--weights JOINT]

Two styles. --style debug (the default) is for checking a model, and is what agents should look at while building: back faces hatched, a depth cue, view-relative lighting; everything below describes it. --style beauty is for showing a finished model (a review sheet, a judge, a thumbnail): no hatch (back faces are drawn in their material colour, lit from the side the camera sees), a key light from the upper left, a fill from the camera and a sky/ground hemisphere ambient (a face turned towards the camera never reads black), material base colours, 2×2 supersampling, no depth cue. Its JSON reply has the same fields, "style":"beauty" and "depth_cue":false; apply --preview OUT.png --style beauty renders the same way. Back faces are still counted (back_faces_visible, ...) the same way, only not drawn. Use the debug style to find inside-out faces; a beauty sheet hides them. Transparency: the beauty style blends faces whose material alpha is below 1 (glass at 0.3) over what is behind them, back to front after every opaque face, so a candle shows through a lantern's panes; they hide nothing, so back faces behind them still count. The see-through faces' own back faces are not counted in beauty (flipped glass would read as normal glass there); the debug style draws them opaque, so flipped or open glass is hatched and counted like any other face.

A CPU software renderer: orthographic views framed on the geometry, a rim light, labels, a world-axis gizmo (X red, Y green, Z blue), tiled into one PNG (2×2 for four views). Views: front (camera on +Z), back, side/right (+X), left, iso/three-quarter, top (+Y), bottom. Faces are drawn in their material colour (set_material base colour, times the lighting); faces without a material stay grey. A depth cue keeps stacked parts apart in the flat views (top, front, ...): faces farther from the camera fade toward the background, and a dark outline is drawn where the depth jumps (a lid seen from above on a larger crate); a surface that is merely steep (a roof slope or a seat seen at a grazing angle) is continuous, so it is not outlined. --no-depth-cue turns it off. Back faces are hatched magenta and black, on any material: the diagonal stripes cannot come from a material (materials are flat colours), so an inside-out part reads even when it is painted red. They mean flipped normals (an inward extrusion's walls, a mirrored part), or open geometry seen from inside. A back face lying exactly on a front face wins the tie, so it shows as clean stripes, not flicker; on a silhouette edge (where a back face meets a front face of the same surface, and the two tie exactly) the front face wins, so a closed mesh shows no specks along its outline or where parts touch. The reply counts them: "back_faces_visible" is the number of back-facing triangles with real visible area after the depth test, summed over the views (a triangle seen in two views counts twice); "back_face_pixels" is those triangles' visible pixels; "back_faces_by_view" gives [{"view","count","pixels"}] per tile (with "object" under --per-object). Real area: the triangle owns at least 4 interior pixels at the default 512 px tile (scaled with the tile's area, at least 1), an interior pixel being one whose 8 neighbours are back-face pixels too. That leaves out the specks a closed mesh shows along its silhouettes (a nearly edge-on triangle behind the rim winning a pixel or a 1-2 px sliver), which the hatch may still draw. A closed, consistently wound prop (box, sphere, torus, a kart of boxes and cylinders, a solidified bowl: its inner wall faces the camera) has 0; an inward extrusion's walls or an open bowl without thickness seen from above (the inside of its outward skin) count; the text output and apply --preview's stderr warning add "N visible back faces (P px)" only then. --no-materials draws every face grey (shape only). --highlight-selection colours selected faces orange (selected vertices yellow); with a .mfs the session's selection is used, or set one with --commands. --per-object draws one row per object. Output is deterministic (same input, same PNG bytes). About 25 ms per 512×512 view for 100k triangles (release build).

Shading matches the export. By default the sheet shades with the normals a plain export_glb writes (auto: hard edges where faces meet at more than 30 degrees, smooth elsewhere), so a crate looks crisp and a sphere round, as in the game. --shading flat shows every facet, smooth and keep (normals stored by an unedited import) match the export options of the same name, and --angle-deg N changes the auto threshold. A model file (.glb/.gltf/.obj) whose objects all carry normals is drawn with the file's own normals (keep), so an asset exported with "normals":"flat" previews faceted, as the game shows it; pass --shading auto (or flat, smooth) to recompute them instead. If any stored normal is NaN or zero length, the file's normals are not used (the default is the export's auto, and --shading keep falls back to auto for that object). The JSON reply (--json) says what was used: "shading":"auto","angle_deg":30 (or "shading":"keep").

Modifiers are drawn evaluated, as export_glb writes them (its apply_modifiers default): an object with an array modifier shows every copy. --cage draws the objects' own meshes instead (the cage that edit commands and selection ids refer to); selection highlighting only applies to the cage, so an object with modifiers shows its selection with --cage. The reply says "modifiers":"evaluated" or "cage".

Rigs. A posed object (the pose op) is drawn in its pose. --pose '{"knee":[60,0,0]}' poses every drawn skinned object for this preview only (joint name -> [rx, ry, rz] Euler degrees about X, then Y, then Z, in the joint's frame; the session is not saved), so an agent can check a rig bends without changing anything. --skeleton draws the joints (dots) and bones (lines) over the mesh, in the pose, seen through the surface; skeletons no drawn object is bound to (made with create_skeleton, before auto_weights) are drawn in bind pose, to check the joints sit inside the mesh. --weights JOINT colours skinned faces by that joint's weight: blue 0, cyan, green, yellow, red 1 (materials are ignored). All three work with every view and shading. The reply adds "posed" (the objects drawn in a pose), "skeleton":true and "weights":"JOINT" when used.

meshforge preview crate.mfs -o crate.png
meshforge preview tree.glb -o tree.png --views front,side,top,iso --wireframe --size 512
meshforge preview creature.mfs -o bend.png --pose '{"knee_l":[50,0,0]}' --skeleton
meshforge preview creature.mfs -o weights.png --weights knee_l --views side
meshforge preview crate.mfs -o sel.png --highlight-selection --views iso
meshforge preview crate.mfs -o uv.png --uv --object crate

UV layout. --uv (layer uv0, or --uv uv1) draws the UV layout instead of 3D views, one tile per object: the unit square with a quarter grid, every face filled in its chart's colour, chart borders (seams) dark, inner edges faint, and faces with mirrored UVs red. UVs are drawn as stored (glTF convention: v down, so the image reads like the texture). The reply lists the charts per object: "uv":"uv0","objects":[{"object":"crate","layer":"uv0","charts":4}]. An object without the layer fails with no_uv_layer and a uv_unwrap hint.

ops (alias: commands)

Shows the commands of the API, generated from the core's schema (meshforge::command::schema::ops_schema()), which its tests check against the parser: every op, every field the parser accepts with its type, whether it is required, default, range and allowed values; the full select selector; every error code with its fields. Prose and extra examples come from docs/command-api.md.

meshforge ops               # index: every op name, grouped (about 0.9 KB; JSON {"ops":{group:[names]},"aliases":{...},"usage":...})
meshforge ops extrude       # one op in full (JSON; "select" adds the selector schema, modifier ops the modifier types)
meshforge ops transform boolean revolve   # several ops: signatures, one line of fields, types and defaults per op, then an example
meshforge ops transform boolean --long    # several ops in full: {"commands":[...]}, in the order asked
meshforge ops extrude --sig               # one op as a signature
meshforge ops --sig         # every op as a signature (about 11 KB)
meshforge ops --all         # the whole API: {"commands":[...],"selector":{...},"modifier":{...},"error_codes":[...],"types":{...},...} (takes no op names)
meshforge ops --text        # any of the above as plain text (--all --text: the full list for humans)
meshforge ops --format json-schema          # JSON Schema (2020-12) of one command or a batch
meshforge ops extrude --format json-schema  # one op's schema
meshforge ops --format gbnf                 # GBNF grammar (llama.cpp) for constrained decoding

A signature reads op: field: type, field?: type = default, ...: ? marks an optional field, an enum lists its values in place of the type (mode: union|difference|intersection), and select / bevel-style ops add one line with the selector's keys. For an agent: the index once (or the common ops in SKILL.md), then meshforge ops A B for the ops it needs in one call (signatures; --long for full entries); meshforge ops OP when a field's meaning or range matters. Op aliases (lathe, tube) resolve to their op.

--format json-schema and --format gbnf are generated (meshforge::command::schema_export) from the same tables as --all's JSON, never written by hand; the core's tests check that every example in docs/command-api.md validates against both. They print the document itself (no "ok" key). The JSON Schema lists every key of every op (other keys are invalid), types, enums, defaults, numeric ranges, the modifier and selector objects, and the reply key every command takes. The grammar has the same keys and types but expects each object's keys in schema order (op, then the fields as meshforge ops lists them, then reply), as GBNF has no unordered sets; it does not check numeric ranges.

Size (tokens estimated as bytes / 4): JSON Schema about 40.8 KB (about 10,200 tokens), GBNF about 19.2 KB (about 4,800 tokens), the default ops_schema JSON (ops --all, without the docs' prose) about 42.6 KB (about 10,700 tokens). The largest ops are create_primitive, bevel and uv_unwrap (about 2.3 to 2.6 KB of schema each); most are 300 to 1,000 bytes.

One entry:

{"op":"extrude","summary":"Region-extrudes faces along their normals by distance (negative = inwards) and selects the extruded caps.","fields":[{"name":"object","type":"string","required":true,"doc":"Object name."},{"name":"faces","type":"int[]","required":false,"doc":"Face ids (non-empty). Default: the object's current face selection."},{"name":"distance","type":"number","required":true,"doc":"Distance along the normals; negative extrudes inwards."}],"example":{"op":"extrude","object":"box","faces":[3],"distance":0.2},"examples":[...]}

Types: string, number, int, bool, number[3], int[], int[2], string[], int[2][], modifier, modifier[] (see "modifier"), number | number[3], string | number[3], number[3|4], object (keys under fields), base64, selector (see "selector"). range is {"min","max","min_exclusive"}.

info

meshforge info chair.glb [--text]
meshforge info crate.mfs [--text]      # a session: its objects, selections and history

With --text:

chair.glb (glb, 4236 bytes)
  1 object(s): 56 vertices, 162 edges, 108 faces, 108 triangles; 0 material(s)
  bbox min [-0.5000, -0.8750, -0.5000] max [0.5000, 0.9750, 0.5000] size [1.0000, 1.8500, 1.0000]
  'chair': 56 verts, 162 edges, 108 faces (108 tris); 1 shell(s), closed
      attributes: corner[normal, uv0]
  skeletons: none
  morph targets: none

JSON fields (the default output): objects, totals (vertices, edges, faces, triangles), bbox (what export writes: with modifiers, the evaluated stacks), cage_bbox (only when some object has modifiers: the objects' own meshes), materials, skins, skeletons (name, bones), joints, morph_targets (meshforge does not import them), animations, object_details[] (per object: counts, shells, boundary_loops, boundary_edges, closed, bbox and cage_bbox (null without modifiers), attributes, skinned, max_influences, import repairs: non-manifold edges cut, vertices split, degenerate faces dropped; selection: domain and count). For a .mfs, also session (logged_commands, max_faces, history).

validate

meshforge validate prop.glb [--text]      # also takes a .mfs

Imports the file and lists problems, each with severity (error, warning, info), kind, message and fix: non-manifold geometry cut on import, degenerate or zero-area faces, zero-length edges, isolated vertices, NaN positions, open meshes, faces of one connected surface passing through each other (self_intersection, an error: an unclamped bevel, a folded inset, an over-thick solidify; the fix names clamp, boolean and solidify thickness), separate parts of one object overlapping (overlapping_parts, a warning: normal for kitbashed game props, the file stays valid; boolean union them only if they must be one watertight surface), vertices of one surface touching without sharing an edge (touching_vertices, a warning: the surface pinches onto itself, typically a zero-thickness wall left by a boolean of parts that only touch along a face; fine for rendering, but tools that weld by distance count non-manifold edges there), broken connectivity (invalid_topology, a meshforge bug: report the file), suspicious scale, skin problems (no skeleton, joints out of range, unweighted vertices, weights not summing to 1), and morph targets/animations that a meshforge re-export would drop. Exit 1 if there is any error. With --text:

fin.obj: valid (0 error(s), 1 warning(s))
  warning: 'fin' is non-manifold: 1 edges were shared by 3+ faces or had inconsistent winding (cut on import), 4 vertices split
      fix: in the source, remove duplicate/internal faces, make face winding (normals) consistent, ...
  info: 'fin' is open: 3 boundary loop(s) (holes or open edges)
      fix: fine for planes, cloth and cards; a solid prop should be closed (fill the holes in the source)

A box bevelled with "width":0.8,"clamp":false, exported and validated:

block.glb: INVALID (1 error(s), 0 warning(s))
  error: 252 face pairs of one connected surface of 'block' pass through each other (e.g. faces [[12,15],[12,16],...])
      fix: an unclamped bevel or a folded inset does this: redo it with clamp: true or a smaller width. Parts welded into one surface that overlap: boolean union them instead. A solidify thicker than the gaps folds the inner shell: use a smaller thickness. query {"include":["faces"],"faces":[ids]} shows where those faces are

A crate with a smaller lid box overlapping it, joined into one object (exit 0):

crate.glb: valid (0 error(s), 1 warning(s))
  warning: 8 face pairs of separate parts of 'crate' overlap (e.g. faces [[6,14],[6,15],...])
      fix: fine for games (overlapping kitbashed parts render correctly); boolean union them if they must be one watertight surface (3D printing, booleans, solidify)

weights

meshforge weights robot.glb --skeleton-from rig.glb --out robot_skinned.glb [--skin N] [--json]

Automatic skin weights (bone heat) for every mesh of the first file, against the skeleton of a glTF skin in --skeleton-from (default: the same file). Prints the weights report (shells and how each was weighted, unattached vertices, fallback, timings, warnings) and the number of vertices dominated by each joint. Without --out nothing is written.

transfer

meshforge transfer robot_skinned.glb backpack.glb --out backpack_skinned.glb [--exclude-joints antenna_] [--json]

Copies skin weights from a skinned source onto every object of the destination (robust closest-point transfer with inpainting). The output is bound to the source's skeleton. --exclude-joints takes joint-name prefixes (repeatable or comma-separated).

Worked example: a chair from a cube

Every step below is a real command run against meshforge 0.1.0. No vertex or face ids are needed: the cube's faces are tagged (top, bottom, front, ...; see "Tags" in docs/command-api.md), and edges are named by rule.

chair.json:

[
  {"op":"create_primitive","kind":"cube","name":"chair"},
  {"op":"transform","object":"chair","target":"object","scale":[1,0.15,1]},
  {"op":"loop_cut","object":"chair","select":{"edges":"horizontal"},"cuts":2},
  {"op":"select","object":"chair","select":{"tag":"bottom"}},
  {"op":"select","object":"chair","select":{"in_box":{"min":[-0.17,-1,-1],"max":[0.17,1,1]}},"mode":"subtract"},
  {"op":"select","object":"chair","select":{"in_box":{"min":[-1,-1,-0.17],"max":[1,1,0.17]}},"mode":"subtract"},
  {"op":"extrude","object":"chair","distance":0.8},
  {"op":"select","object":"chair","select":{"tag":"top"}},
  {"op":"select","object":"chair","select":{"in_box":{"min":[-1,-1,-1],"max":[1,1,-0.17]}},"mode":"intersect"},
  {"op":"extrude","object":"chair","distance":0.9}
]
# 1. A cube flattened into a seat (1 x 0.15 x 1); one loop_cut with
#    "edges":"horizontal" cuts both horizontal rings, so the seat is a 3x3
#    grid; the four bottom corner cells are extruded down into legs, the
#    back row of the top up into a backrest.
meshforge apply chair.json --session chair.mfs

# 2. Look at it, then write the asset.
meshforge preview chair.mfs -o chair.png --wireframe
meshforge apply --session chair.mfs -o chair.glb
meshforge validate chair.glb --text

stderr of step 1 (with --full; the default brief reply prints only the lines with news, without counts or ids):

[0] create_primitive 'chair'; created: chair; 8 verts, 12 edges, 6 faces; selection: 0 faces []
[1] transform 'chair'; moved 8 vertices; 8 verts, 12 edges, 6 faces; selection: 0 faces []
[2] loop_cut 'chair'; new faces: 24; new vertices: 24; 32 verts, 60 edges, 30 faces; selection: 0 faces []
[3] select 'chair'; 32 verts, 60 edges, 30 faces; selection: 9 faces [2,8,9,14,15,16,17,18,19]
[4] select 'chair'; 32 verts, 60 edges, 30 faces; selection: 6 faces [2,8,14,15,18,19]
[5] select 'chair'; 32 verts, 60 edges, 30 faces; selection: 4 faces [2,8,14,18]
[6] extrude 'chair'; new tags: extrude_wall, extruded; new faces: 16; new vertices: 16; 48 verts, 92 edges, 46 faces; selection: 4 faces [2,8,14,18]
[7] select 'chair'; 48 verts, 92 edges, 46 faces; selection: 9 faces [3,12,13,22,23,24,25,26,27]
[8] select 'chair'; 48 verts, 92 edges, 46 faces; selection: 3 faces [3,12,13]
[9] extrude 'chair'; new faces: 8; new vertices: 8; 56 verts, 108 edges, 54 faces; selection: 3 faces [3,12,13]

Before tags this took three calls: create and flatten the cube, query its faces to look up vertex ids, then two loop cuts named by vertex pairs ("edge":[0,1], "edge":[0,4]) and the rest of the batch. The commands shrink from 892 to 778 bytes and the replies the agent reads from 5520 to 4172 bytes (full replies), in one call instead of three, for the same chair (the test chair_example_with_tags_matches_the_id_version checks it).

If something goes wrong, {"op":"undo"} (or {"op":"undo","steps":3}) against the same session steps back.

Experimental commands

face-corner-metrics, hair-cards, hair-metrics, hair-synth, hair-bench and hair-coverage serve one character pipeline (heads and hair cards). They are hidden from meshforge --help, may change in any release, and are built only with the experimental cargo feature (on by default; cargo install meshforge-cli --no-default-features leaves them out). meshforge <command> --help still documents each; see face-corner-target.md and hair-coverage.md.

Notes