docs/reference.md: fit_shell, what its acceptance and its per-point readings are worth, and what it gives up

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-12-03 04:29:15 +01:00
commit f00a5a247d

View file

@ -1,4 +1,4 @@
# Reference views: the camera a picture was drawn through, and traced lines scored against the build
# Reference views: the camera a picture was drawn through, traced lines scored against the build, and a shell fitted to them
`surfaces/blender/brokkr_reference` is a Blender add-on that fits a scene to a reference image. A concept sheet,
a render or a photograph draws its subject through a camera nobody wrote down; given points whose place in the
@ -8,11 +8,11 @@ it lays over the image pixel for pixel and a line traced on the image can be sco
It is a host add-on in Brokkr's sense (`install.md`, "Host add-on actions"), a sibling of `brokkr_mesh_polish`: it
imports that package's operator base and `Refused`, and nothing from `brokkr_bridge`. Enable `brokkr_mesh_polish`
first; `brokkr_reference` refuses to register without it. `brokkr_actions.json` beside its `__init__.py` lists the
two operators agents may run (`solve_camera`, `flow_score`); the arithmetic is `core.py` (numpy only, tested without Blender), which a script may
three operators agents may run (`solve_camera`, `flow_score`, `fit_shell`); the arithmetic is `core.py` (numpy only, tested without Blender), which a script may
import directly. The action writes its JSON report to `brokkr_mesh_polish_result`, returned in the receipt's
`hostResult`.
The package takes points and traced lines and gives cameras and scores. The images, the marks on them, traces and masks belong to whoever
The package takes points and traced lines and gives cameras, scores and a fitted sheet. The images, the marks on them, traces and masks belong to whoever
made them; nothing here opens an image.
## Conventions
@ -172,6 +172,83 @@ surface has the hull's margin, and a surface nearer it than a thousandth of the
about 20000 diagonals off, where the ray's own rounding reaches the margin. The action writes nothing to the scene (its row says `changesScene`
because the operator base pushes an undo step).
## fit_shell: a shell's sheet fitted to traces of its hard runs
A kitbash shell (`kitbash.md`, "Making a shell") is blocked in by eye; `fit_shell` moves the cage points of its
traced runs until the runs, as Blender builds them and the cameras draw them, lie on the traces. A run is a hard
crease or rim run of a loft, named as the sheet's creases name runs. The unknowns are the authored points on the
traced runs; a mirrored sheet is one set of points seen twice, so a trace of each half through one camera is two
views of the run (Francois et al. 2003), and that is where depth comes from in a single picture. Each built point
of a run is pulled onto its trace along the trace's normal, and the run's two ends onto the trace's ends; no
point of a trace is matched to a point of the run or of another trace (after Debevec's Facade and Drummond and
Cipolla's edge tracker). A prior holds every point to the sheet as it stands: a move of `share` of the sheet's
diagonal costs what one pixel of miss does.
```json
{"action": "brokkr_reference.fit_shell", "object_name": "Pauldron", "tol": 3,
"traces": "[{\"camera\": \"Concept\", \"box\": [0, 0, 1024, 1024], \"run\": {\"column\": 3, \"from\": 0, \"to\": 5}, \"side\": 1, \"line\": [[412.5, 96.0], [431.0, 180.2], [440.8, 266.0]]}, {\"camera\": \"Concept\", \"box\": [0, 0, 1024, 1024], \"run\": {\"column\": 3, \"from\": 0, \"to\": 5}, \"side\": -1, \"line\": [[612.0, 90.5], [590.2, 176.0], [583.1, 262.4]]}]"}
```
| field | |
| --- | --- |
| `object_name` | a loft shell made by `brokkr_kitbash.shell`, unscaled; its place in the world is the sheet's frame |
| `traces` | a JSON array, up to 12000 characters, of `{camera, box, run, side, line}` |
| `share` | the prior (default 0.1) |
| `tol` | pixels (default 3): every point of every trace must lie this near its built run |
In a trace, `camera` names a camera object (`solve_camera` stands one) and `box` is its frame on the image, absent
for the render's own; `run` is `{"ring": i, "from": a, "to": b}` or `{"column": j, "from": a, "to": b}` in authored
indices; `side` is 1, or -1 for the mirrored half of a mirrored sheet; `line` is `[[u, v], ...]` in the box's
pixels, drawn from the run's `from` end to its `to` end.
**It returns a fit only where the built runs explain every trace.** After the fit, each trace is walked a pixel
at a time, and every point of it must lie within `tol` of its run as built and drawn. Otherwise the action is
refused, naming the trace, how much of it is unexplained, where along it and by how much, and nothing is returned
as a fit. The fit's own residual is no such test: on strokes doubled back over part of themselves 3% of the view
off, every fit converged and without this check all of them came back, up to 0.10 m wrong on a 2 m crease; with
it every one is refused (the least reads 9 px against the 3 asked). The check also binds the ends: a trace that
runs on past where its run ends, or two traces of a mirrored pair whose tips are not one point and its mirror
image through the camera, are refused at the tip.
**It writes nothing.** The report carries `sheet`, the shell's own request with the traced points moved, ready
for `brokkr_kitbash.shell`, which is the cage's one writer; `flow_score` on the rebuilt shell is the score. The
rest of the report: `traces` (`[{miss_px, unexplained_px}]`: the root mean square distance of the built points
from the trace, and the trace's furthest point from the built run), `points` (`[{ring, point, moved_m, m_per_px,
prior_share}]`, one per moved point) and `seconds`.
`m_per_px` says how far a point slides along its line of sight per pixel of error in the traces (the worst of
the views that trace it), from the inverse of the fit's normal matrix, prior included (Triggs et al. 2000,
sections 9 and 10). `prior_share` is that over `share` x the diagonal: at 1 the traces say nothing about the
point along the sight line and it stands where the blocking put it. Read it per point:
- A run traced on one half only, in one view, reads 1.0 on every point: its depth is the blocking's.
- A mirrored pair reads low where the mirror plane stands well off the sight line. On the Orchid's concept c09
(plane 34 degrees off, a nearly orthographic camera) the pair's points read 0.12 at most, 0.024 m per px on a
ship one unit long.
- The sight line is taken whole. Where a run recedes along the view, a cage point's slide along its own run is
in the reading: the traces do not decide that slide and it does not move the built run. A column 24 to 38
degrees off the sight line, both halves traced and its built run right to 0.2 mm, reads 0.63 to 0.88 on its
inner points. A high reading on such a run is not a depth error.
- A run on the mirror plane itself (a spine, a keel) has no partner and reads 1.0.
What it refuses before fitting, naming the trace: a run with an edge under weight 1 (a semi-sharp edge rounds
off by an amount the fit does not model), a run whose end does not hold (a dart; a ring run from point 0 of a
mirrored sheet, which runs on across the middle), a run with a point held partway (a corner point or a crossing
crease: trace it as two), a closed loop, an unknown camera, a line of fewer than two points, a free cage (it has
no rings or columns; `core.fit_runs` takes vertex chains), a scaled shell, and a result that would pass the
16000 characters a receipt carries.
Measured (Blender 5.3 and Python 3.13 on Starfire): a mirrored column of 10 points traced in one view at a time,
from blockings 0.10 m and 0.30 m off a 2 m crease, came back within 0.7 mm in 0.1 to 0.6 s. The Orchid's c09
petal edges, traced by hand through a camera solved from hand marks (13 px rms), are refused at 3 px: the left
trace's first 10 px stand up to 9.2 px off the built run. At 18.5 px they fit in 0.2 s, and from blockings 5%,
10% and 20% of the ship's length off the built run lands in one place, 2.0% of the length from a stand-in mesh
in the mean and 3.4% at worst. A trace drawn by hand through a camera solved by hand wants a `tol` near that
camera's own `rms`, and the acceptance is then that much weaker.
What it gives up: it fits hard runs of a loft only. Silhouettes of the smooth surface, semi-sharp creases and
free cages are not fitted; a run's depth with no mirror partner and no second view is the blocking's.
## What it cannot do
It solves one pinhole camera for one view: no lens distortion, no two views solved together, one turned group and
@ -188,6 +265,7 @@ u_v = core.project(cam, points) # where it draws wor
origin, direction = core.ray(cam, (u, v)) # a pixel's line of sight
point = core.lift(cam, (u, v), plane_point, plane_normal) # a traced pixel on a plane
run = core.crease_run(column) # the hard crease Blender builds from a cage column
fit = core.fit_sheet(sheet, cage, frame, traces, cams) # the fitted sheet and its report; cage is brokkr_kitbash.core.sheet(sheet)
score = core.along(line, segments, height) # on, off, run against [u0, v0, u1, v1] segments
params = core.blender(cam, 1000) # matrix_world, lens, shifts, resolution
cam2 = core.camera_of(params, box) # and back
@ -196,4 +274,6 @@ cam2 = core.camera_of(params, box) # and back
The tests are `tests/test_reference.py` (no Blender), `tests/live/reference.py` (a known scene rendered, solved
through the action and rendered again; `reference.result.json` is its last run) and `tests/live/reference_flow.py`
(`crease_run` against Blender's own subdivision, a box and a folded sheet scored by `flow_score`;
`reference_flow.result.json` is its last run).
`reference_flow.result.json` is its last run) and `tests/live/reference_fit.py` (a mirrored shell blocked off its
design, fitted through the action, rebuilt by `brokkr_kitbash.shell` and scored; `reference_fit.result.json` is
its last run).