Files
mandy/tools/navmesh_tile_obj.py
AlxcBTW d083a2cc37 Make main's tests green: 12 test files that drifted from the code (#9896)
Twelve test files failed on main at 2d53a8055 (CI's check and semantic-tests steps, run locally): most are a test
and the code it checks changed by different pull requests in the same merge round. Each fix below is either taken
from a closed pull request that already had it, or restores what an earlier merged change intended.

From closed pull requests:
- test_make_game_resume: FakeProc gets poll(), which translate() now calls (#7018)
- test_make_game_empty_translation: the Exited stub gets poll() and the failed-shard path is checked (#7214)
- test_shader_checks: stub table_fetch_test in the Wave64Checks harness and count it (#7433)
- test_runtime_paths: runtime.yml's path filter lists tools/replace_retry.py, which rdna2spirv.py imports (#7029)
- test_psin_names: patch the same_report_path helpers that report_paths now calls (#8719)
- test_report_source_collision: the fixture is a real Bink 2 header; bink_index refuses other files (#7408)
- test_missing_input_exit_codes: tile_probe checks its inputs before it asks for numpy (#4771)

Restored:
- merge_check: a failed `git show` is an error again (5b88d58); 21016cf brought back the lenient read that
  treated it as a new file, while new files are already left out when the diff is read
- rpf_probe: a symlinked --out updates its target again (44d3595); 55d21cc's staged write replaced the link

Updated to the code:
- test_shader_stage_resume: TRANSLATION_SOURCES lists fssm_unpack.py and shader_stage_manifest.py, which the
  translator imports; existing work folders translate once more after this
- test_tool_stdout_encoding: the 15 programs merged without the stdout guard get the same block as the others
- test_rdna2spirv_decode: drop the test of decode_any_format, which SHADER-849 replaced with the table decode
  that tests/semantic/test_format_decode_table.py checks

Co-authored-by: jewmaster1337 <102986566+jewmaster1337@users.noreply.github.com>
Co-authored-by: TanmaySatyam <248538550+TanmaySatyam@users.noreply.github.com>
Co-authored-by: evilclanker9000 <45567075+evilclanker9000@users.noreply.github.com>
Co-authored-by: slint6614-dev <359954236+slint6614-dev@users.noreply.github.com>
Co-authored-by: BlackNife <108077267+Poussistar@users.noreply.github.com>
Co-authored-by: fiestorra <65175643+fiestorra@users.noreply.github.com>
Co-authored-by: fearkov <289226582+fearkov@users.noreply.github.com>
Co-authored-by: DoubleD17 <48109637+DoubleD17@users.noreply.github.com>
2026-11-24 00:21:26 +01:00

81 lines
3.0 KiB
Python

"""Export one static navmesh tile's polygon boundaries to a private Wavefront OBJ.
--tile is the zero-based ordinal among complete navmesh resources in archive order,
including dynamic tiles. A dynamic or unreadable selection is an error. Groups
use zero-based polygon record numbers. Each record owns its OBJ vertices, so
coincident positions, repeated slots and winding survive without welding.
"""
import argparse
import os
import sys
import tempfile
from contextlib import closing
from pathlib import Path
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from navmesh_nodes import navmesh_resources, tile_geometry
from report_paths import same_report_path
def write_obj(out, geometry, ordinal):
out.write(f"o tile_{ordinal}\n")
first = 1
for record, (points, _, _) in enumerate(geometry["polygons"]):
out.write(f"g polygon_{record}\n")
if not points:
out.write("# empty record\n")
continue
for x, y, z in points:
out.write(f"v {x} {y} {z}\n")
refs = list(range(first, first + len(points)))
first += len(points)
if len(points) >= 3:
refs.append(refs[0])
op = "p" if len(points) == 1 else "l"
out.write(op + " " + " ".join(map(str, refs)) + "\n")
def main(argv=None):
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("archive")
parser.add_argument("--tile", type=int, required=True)
parser.add_argument("--out", type=Path, required=True, help="local OBJ destination")
args = parser.parse_args(argv)
if args.tile < 0:
parser.error("--tile must be non-negative")
temp = None
try:
if same_report_path(args.archive, args.out):
raise ValueError("--out aliases the archive")
with closing(navmesh_resources(args.archive)) as resources:
for ordinal, tile in enumerate(resources):
if ordinal == args.tile:
geometry = tile_geometry(tile)
break
else:
raise ValueError("tile ordinal outside archive")
if geometry is None:
raise ValueError("selected tile is dynamic or unreadable")
args.out.parent.mkdir(parents=True, exist_ok=True)
with tempfile.NamedTemporaryFile(mode="w", encoding="utf-8", newline="\n",
dir=args.out.parent, delete=False) as out:
temp = Path(out.name)
write_obj(out, geometry, ordinal)
os.replace(temp, args.out)
temp = None
except (OSError, ValueError) as exc:
print(f"ERROR: {exc}", file=sys.stderr)
return 2
finally:
if temp is not None:
temp.unlink(missing_ok=True)
return 0
if __name__ == "__main__":
try: # a redirected stdout is strict ANSI code page under -I; write '?' for what it cannot encode
sys.stdout.reconfigure(errors="replace")
except (AttributeError, ValueError, OSError):
pass
sys.exit(main())