Publish the match report through a temp file + replace so a mid-write OSError leaves any prior complete JSON intact.
Co-authored-by: Cursor <cursoragent@cursor.com>
Vonsek's write-path review exposed the JSON write last; its failure modes
were still unguarded: a missing parent directory left a FileNotFoundError
traceback after the tool already answers bad inputs in one line. Wrap the
write in an OSError handler (one error line, exit 2), matching the input
convention.
The report is written last, after every input has been read, so --json naming
the dehydrated BLAS, the manifest, the --descriptor file or --write's
export.json silently replaced it. Refuse the alias with one error line and
exit 2 before anything is opened, using the report_paths guard the other
report tools use.
A manifest that is a JSON list or scalar raised AttributeError on .get.
It now raises the same ValueError path as a manifest with no Items
("error: ...", exit 2). tex_export already handles non-object rows on main.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The matcher could identify the drawable's geometries but had no way to hand them to tools/bvh_rehydrate.py,
so the recipe §4a implies could not be followed end to end. --write DIR now writes one float3 buffer and one
uint32 index buffer per matched geometry plus an export.json (the instance transform recorded, not applied to
the vertices), which is the shape bvh_rehydrate.py already takes.
docs/bvh.md §7 gains the four steps to rebuild the sample set from the user's own copy - bvh_index, a
levels.rpf window, bvh_match with --write, bvh_rehydrate - with the counts to check them against, and the root
parent-table entry the runtime layout must hold (0xFFFFFFFF, as the GPU builder writes and #2625 validates).
Nothing of the samples enters the repository; the two excluded shader hashes stay with the user.
Checked on the sample pack: --write on one identified sample produced buffers of the same sizes as the earlier
reference export of that BLAS (732/816, 2,736/2,808, 492/576 bytes), and rehydrating them with the recorded
transform gave the declared 18,880 bytes. Synthetic tests: two cases added (the buffers and export.json; nothing
written when no candidate is consistent), 18 in total.
An empty result has two very different causes and the tool said neither: the drawable may be outside the
exported window (a window holds one region's drawables), or the model's geometry list may not follow the
triangle-count rule. Both now come with a line saying so, and a manifest that holds no model at all says that
too instead of reporting only "no Items".
While reviewing it, two traces were still possible instead of a message: an OBJ with fewer `o` groups than the
manifest's geometry arrays (now an error naming both counts) and a non-string shader hash (now reported per
candidate, not as a traceback). Exit status is documented in the docstring.
Reported by @kacper-serewis: an independent run against a 1 GiB window cut at 10 GiB exported 3,731 models with
no failures and found no candidate for the first ten BLAS of the comparison pack, whose drawables are in the 3 GiB
window this PR measured. The run was correct; the report did not name its window, and docs/bvh.md now does.
Synthetic tests only; three cases added, 16 in total.
Reads the leaf signature (triangles per geometry index, a leaf that holds two primitives counting
as two), keeps every (drawable, model) of an `rpf9dump models` manifest whose per-geometry triangle
counts contain it as an ordered subsequence, and checks the survivors with
tools/bvh_geometry_check.py from the model's exported OBJ and the 3x4 at +0x50 of the instance
descriptor. The geometries of the two shaders the BVH leaves out are filtered with --skip-shaders
(those name hashes are game data, so the rule is off unless the user passes them); a drawable whose
shader indices the manifest cannot resolve keeps every geometry and the checks decide.
All the BVH logic stays in Python: the C# side is only the model decoding and the export.
Measured on the ten BLAS of the sample pack against one 1 GiB window of levels.rpf: 1,228 models
exported, 1 to 374 candidates per BLAS from the signature, and exactly one consistent candidate
for each of the ten. The tool prints no drawable names unless --names is given.
The two tools that came with #2205 and #2428 lacked the stdout errors="replace" guard every CLI
tool needs (tests/test_tool_stdout_encoding.py), so this also adds it there; without it that test
fails for both.
Tests are synthetic (tests/test_bvh_match.py, 14 cases): the right geometry is found and verified,
a wrong one, a wrong shader rule and a missing transform are not, geometries are matched inside one
model, and a manifest without per-geometry counts is an input error.