docs: mesh polish actions, the headless intent runner and the turntable recipe
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
parent
6eb3725254
commit
0921bec89b
3 changed files with 178 additions and 0 deletions
|
|
@ -32,6 +32,9 @@ broker.
|
|||
- `surfaces/blender/brokkr_bridge`: Blender add-on target backed by
|
||||
CultLib's Python CultMesh node/server, with an optional debug export
|
||||
probes.
|
||||
- `surfaces/blender/brokkr_mesh_polish`: Blender host add-on that measures and polishes generated meshes
|
||||
(audit, repair, orient, delight, scrub markings, cut parts), agent-callable through Brokkr's host actions;
|
||||
`surfaces/blender/tools` runs intent recipes in a background Blender (`surfaces/blender/docs/mesh-polish.md`).
|
||||
- `brokkr-command`: .NET CLI that writes one Unity command intent through the
|
||||
project's directory store and reports the editor's receipt (`docs/provider-contract.md`).
|
||||
- `brokkr-daemon`: Rust CLI that emits Brokkr's provider advertisement and
|
||||
|
|
|
|||
|
|
@ -290,6 +290,9 @@ with nothing pushed; an argument Blender will not convert, or an `ERROR` report
|
|||
agent turn clears that WindowManager property before the call and copies it, up to 16000 characters and then
|
||||
`[truncated]`, into the receipt's `hostResult` (empty for every other action).
|
||||
|
||||
`surfaces/blender/brokkr_mesh_polish` is a host add-on that ships with Brokkr (`mesh-polish.md`), and
|
||||
`surfaces/blender/tools/run_intents.py` runs a list of intents, host rows included, in a background Blender.
|
||||
|
||||
The admitted rows are published in the host snapshot as `hostActions` (each with its `host` module).
|
||||
`brokkr-ctl blender send --help --store <path>` lists them after the built-ins, `send` refuses an intent
|
||||
they refuse before writing anything, and the add-on still decides. Human-only is absence: an operator only a
|
||||
|
|
|
|||
172
surfaces/blender/docs/mesh-polish.md
Normal file
172
surfaces/blender/docs/mesh-polish.md
Normal file
|
|
@ -0,0 +1,172 @@
|
|||
# Mesh polish for generated meshes
|
||||
|
||||
`surfaces/blender/brokkr_mesh_polish` is a Blender add-on that measures and polishes meshes made by image-to-3D
|
||||
generators (Tripo and its kin): one fused or many-shelled skin, vertices split at every UV seam, an arbitrary
|
||||
orientation, a unit-cube scale, and a base colour texture with the concept render's lighting and lettering baked in.
|
||||
|
||||
It is a host add-on in Brokkr's sense (`install.md`, "Host add-on actions"): it imports nothing from Brokkr, and
|
||||
`brokkr_actions.json` beside its `__init__.py` lists the operators agents may run. Every field, type, bound and
|
||||
default is in that file; `brokkr-ctl blender send --help --store <path>` prints it for a live session. The
|
||||
arithmetic is `core.py` (numpy only) and is tested without Blender.
|
||||
|
||||
Every action writes a JSON report, returned in the receipt's `hostResult`. Actions that change the scene are one
|
||||
undo step each. Lengths are in scene units; points and directions are world-space.
|
||||
|
||||
## Running it
|
||||
|
||||
In a person's Blender: enable the add-on beside Brokkr and press `Reload Host Actions` in the Brokkr panel; the
|
||||
actions then arrive as intents like any other.
|
||||
|
||||
With no Blender open, `surfaces/blender/tools/run_intents.py` runs a recipe (a JSON list of intents) in a
|
||||
background Blender through the same agent turn, and writes the receipts to a file:
|
||||
|
||||
```text
|
||||
blender --background --factory-startup --python surfaces/blender/tools/run_intents.py -- polish.json
|
||||
```
|
||||
|
||||
```json
|
||||
{"requestedBy": "nibu/hands", "importDir": "work", "outputDir": "work", "hostAddons": ["brokkr_mesh_polish"],
|
||||
"saveBlend": "work/ship.blend",
|
||||
"intents": [
|
||||
{"action": "importGltf", "filepath": "ship_tripo.glb"},
|
||||
{"action": "brokkr_mesh_polish.audit"},
|
||||
{"action": "brokkr_mesh_polish.orient", "roll_quarter_turns": 2},
|
||||
{"action": "brokkr_mesh_polish.repair", "object_name": "tripo_ab12"},
|
||||
{"action": "brokkr_mesh_polish.delight", "object_name": "tripo_ab12", "clusters": 2},
|
||||
{"action": "brokkr_mesh_polish.audit"},
|
||||
{"action": "exportGltf", "filepath": "ship_polished.glb"}]}
|
||||
```
|
||||
|
||||
The runner opens no CultMesh node: receipts go to `<recipe>.receipts.json` only. It is the human of its own
|
||||
Blender (it enables the host add-ons, reloads host actions once, opens and saves the `.blend`), and it refuses to
|
||||
start without private `BLENDER_USER_CONFIG`, `BLENDER_USER_EXTENSIONS` and `BLENDER_USER_SCRIPTS`. Its exit status is
|
||||
0 when every intent was accepted, 3 when one was not, 2 when the recipe could not run.
|
||||
|
||||
`surfaces/blender/tools/turntable_recipe.py` writes a recipe of Brokkr's own scene actions (`setWorld`,
|
||||
`createObject`, `setCamera`, `setObjectTransform`, `renderStill`) for an orthographic turntable of a `.blend` whose
|
||||
subject is centred on the origin. Two recipes with the same numbers frame two files identically, so a before and
|
||||
an after compare view by view. `--look flat` lights with a uniform white world alone and shows the texture as
|
||||
stored, baked shadows included; `--look lit` adds a sun.
|
||||
|
||||
A polish pass that works, in order: `audit`, `orient` (render a flat turntable and pick `roll_quarter_turns` and
|
||||
`flip_forward` by eye), `repair`, `delight`, then `pick` and `scrub_markings` for each patch of lettering, then
|
||||
`pick` and `cut_parts` when parts must move, `audit` again, `exportGltf`.
|
||||
|
||||
## Actions
|
||||
|
||||
### audit
|
||||
|
||||
Measures one mesh object, or every mesh in the scene. Changes nothing. Topology is counted after welding positions
|
||||
within 1e-5 of the bounding diagonal, because an imported mesh is split at every UV seam and would otherwise read
|
||||
as all open edges.
|
||||
|
||||
- `triangles`, `vertices`, `weldedVertices`, `extent`, `surfaceArea`, `degenerateTriangles`.
|
||||
- `boundaryEdges` (one triangle on the edge: an open rim), `nonManifoldEdges` (three or more), `shells` and
|
||||
the triangle count of the largest twelve.
|
||||
- `uvIslands`, `uvFlippedTriangles` (mirrored in UV space), `uvZeroAreaTriangles`, `uvOutsideUnitTriangles`,
|
||||
`uvCoverage` (share of the texture some triangle covers) and `uvOverlap` (share of covered texels that more
|
||||
than one triangle covers), both counted at texel centres on a `raster` x `raster` grid.
|
||||
- `texelDensityMedian`, `P5`, `P95` (texels per unit length for the base colour texture's size, area-weighted) and
|
||||
`texelDensitySpread` (P95 / P5; 1 is uniform).
|
||||
- `baseColorImage`, `baseColorSize`, `customNormals`.
|
||||
|
||||
### repair
|
||||
|
||||
Welds coincident vertices (UVs live on face corners, so seams keep their UVs), removes degenerate faces and loose
|
||||
edges and vertices, optionally deletes shells below `min_shell_area` of the surface, optionally closes holes of up
|
||||
to `fill_holes_sides` edges, and makes face normals consistent. With `sharp_angle` above 0 the generator's custom
|
||||
normals are dropped and shading is recomputed: smooth, hard across edges sharper than the angle.
|
||||
|
||||
A filled hole has no place in the UV map: each new face takes one UV point from the old face beside it, so it shows
|
||||
that texel's colour and adds no UV overlap (it counts in `uvZeroAreaTriangles`). Making normals consistent flips the
|
||||
winding of shells that faced inward, which mirrors their UVs; `uvFlippedTriangles` can rise.
|
||||
|
||||
Welding does not join shells that merely touch or intersect. A mesh assembled from open, interpenetrating shells
|
||||
stays one: its open edges and non-manifold edges are reported, not repaired. Closing such a mesh means remeshing it
|
||||
and rebaking its texture, which this add-on does not do.
|
||||
|
||||
### orient
|
||||
|
||||
Turns every mesh in the scene, as one rigid body, onto its area-weighted principal axes: longest on Y, shortest on
|
||||
Z, centred on the origin, the longest side scaled to `length` when given. The transform is baked into the mesh data
|
||||
and the objects are left unparented at identity. Principal axes do not know bow from stern or up from down:
|
||||
`flip_forward` and `roll_quarter_turns` choose, and `mirrorError` in the report (per axis, 0 is a perfect mirror)
|
||||
says which plane the body is symmetric across. `principal: false` keeps the current axes and applies only the
|
||||
turns, the centring and the scale.
|
||||
|
||||
### delight
|
||||
|
||||
Undoes lighting baked into the base colour texture, as far as the surface's own shape explains it.
|
||||
|
||||
For each texel the add-on knows the surface normal and the ambient occlusion there (cosine-weighted rays against
|
||||
the mesh, per vertex). It fits log luminance as an intercept per hue cluster (`clusters`: how many distinct paints
|
||||
the texture holds) plus a light term: the order-2 spherical harmonics of the normal and the log of occlusion. The
|
||||
fit follows the upper envelope of luminance (an expectile regression at 0.85), because within one hue the
|
||||
brightest paint at a given normal and occlusion shows how much light the bake put there, while darker paint in the
|
||||
same place, machinery in a crevice of a pale hull, is paint. Texels darker than 4% of the texture's white point are
|
||||
left out of the fit: they are fill the generator never saw. Each texel is then multiplied by the factor that undoes
|
||||
the fitted light, relative to the surface the light favoured (the 90th percentile), limited to `max_gain` either
|
||||
way. The result is a new packed image (`<name>.delit`) swapped into the material; nothing is written to disk.
|
||||
|
||||
The report: `explainedByLight` (share of within-hue luminance variance the light term explains, before and
|
||||
after), and two model-free readings before and after, over the texels that were judged:
|
||||
`upDownLuminanceRatio` (up-facing over down-facing surface, 1 is none) and `occlusionCorrelation`. `gain.clamped`
|
||||
is the share of texels that hit `max_gain`.
|
||||
|
||||
What it cannot do. It removes smooth, shape-following light: sky-over-ground gradients and occlusion darkening.
|
||||
It does not remove cast shadows, specular highlights, or light the shape does not explain. It cannot tell dark
|
||||
paint from shadow where a hue has no bright paint at all in some range of occlusion. Texels the generator filled
|
||||
with black stay black: there is no colour there to recover. It raises shaded paint by gain, so 8-bit noise and
|
||||
JPEG blocks in dark areas are raised with it.
|
||||
|
||||
### pick
|
||||
|
||||
The surface point seen at `(u, v)` of a camera's frame (`u` across, `v` up, both 0 to 1), with the object and
|
||||
normal there. `resolution_x` and `resolution_y` are the size of the picture the place was read from, since the
|
||||
frame's shape follows the picture's. Changes nothing. It turns "the lettering at this place in this render" into a
|
||||
point that `scrub_markings` or `cut_parts` can take.
|
||||
|
||||
### scrub_markings
|
||||
|
||||
Paints out markings on the base colour texture inside a world-space sphere. Texels of the object's surface inside
|
||||
the sphere whose colour is further than `tolerance` from the sphere's median colour are the marking; the mask is
|
||||
widened by `grow` texels, filled with a smooth blend of the unmasked texels of the same region (push-pull), and
|
||||
given the surrounding texture's grain. The result is a new packed image (`<name>.scrubbed`); successive scrubs
|
||||
keep one image, not a chain.
|
||||
|
||||
The median colour must be the panel, not the marking: keep the sphere wide enough that lettering is the minority.
|
||||
Panel lines, rivets and rust inside the sphere that differ from the panel by more than `tolerance` go with the
|
||||
lettering. The fill is a blend, not a reconstruction: a faint ghost of the removed strokes can remain where the
|
||||
unmasked source was thin.
|
||||
|
||||
### cut_parts
|
||||
|
||||
Cuts one fused skin into named parts and makes each a separate object that can move.
|
||||
|
||||
`seeds` is `name=x,y,z; name=x,y,z; ...`: points on the surface, several per name allowed; the first name is the
|
||||
body. Every triangle joins the seed it is cheapest to walk to, where a step costs its length (as a share of the
|
||||
bounding diagonal) plus `crease_cost` times the square of how concave the fold it crosses is. Parts therefore stop
|
||||
at sharp concave creases, where one part of a fused skin meets another, and split by distance where there is no
|
||||
crease. `through` above 0 also seeds the far face of each part off the body, found by a ray inward from each seed
|
||||
no longer than that share of the diagonal: a thin shell (a petal, a fin) is then held from both faces.
|
||||
|
||||
The mesh is welded and triangulated first. Each part becomes an object `<object>.<name>`; both sides of every cut
|
||||
are capped with faces of a dark `Polish Cap` material (pinned to one UV point each, as in `repair`); each part off
|
||||
the body gets its origin at the centre of its cut and is parented to the body without moving; custom properties
|
||||
`polish_cut_normal` and `polish_cut_radius` record the cut's plane and mean radius. `joint_scale` above 0 adds a
|
||||
ball of that share of the cut radius at each root, parented to the body. The original object is removed.
|
||||
|
||||
The report gives each part's `triangles`, `capTriangles`, `cutEdges`, `root`, `cutNormal` and `cutRadius`.
|
||||
|
||||
What it cannot do. Seeds decide the parts; a seed on the wrong surface gives a wrong part. Place them from a
|
||||
render with `pick`, then check where they landed before cutting (a small cube at each seed, rendered, is enough).
|
||||
Cuts follow triangle edges, so on a coarse mesh they are ragged. Caps are fans across the cut and can fold over on a
|
||||
cut that is far from planar; they are meant to be hidden by the neighbouring part, not shown. The root is the
|
||||
centre of the cut, not a designed hinge: it is a sensible pivot to start from.
|
||||
|
||||
## Tests
|
||||
|
||||
- `tests/test_mesh_polish.py`: the arithmetic on hand-built meshes and textures, `brokkr_actions.json` against
|
||||
Brokkr's own host-file checker, and the turntable recipe against the action table. No Blender; needs numpy.
|
||||
- `tests/live/mesh_polish.py`: every action through `run_intent` in a background Blender against real bpy
|
||||
(`mesh_polish.result.json` is the last run, Blender 5.3.0).
|
||||
Loading…
Reference in a new issue