#!/usr/bin/env python3 """Focused regression checks for MJCF-to-manifest feature coverage.""" from __future__ import annotations import tempfile from pathlib import Path import sys sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "tools")) from export_mjcf_manifest import collect_manifest # noqa: E402 def require(condition: bool, message: str) -> None: if not condition: raise AssertionError(message) def by_id(items: list[dict], key: str = "id") -> dict[str, dict]: return {str(item[key]): item for item in items} def main() -> int: with tempfile.TemporaryDirectory() as tmp: root = Path(tmp) assets = root / "assets" assets.mkdir() (assets / "mesh.obj").write_text("o mesh\nv 0 0 0\nv 1 0 0\nv 0 1 0\nf 1 2 3\n", encoding="utf-8") (assets / "tex.png").write_bytes( bytes.fromhex( "89504e470d0a1a0a0000000d4948445200000001000000010802000000907753de" "0000000c49444154789c6360f8ffff3f0005fe02fea73581e60000000049454e44ae426082" ) ) scene = root / "scene.xml" scene.write_text( """ """.strip(), encoding="utf-8", ) manifest = collect_manifest(scene, "/assets") materials = by_id(manifest["materials"]) objects = by_id(manifest["objects"]) require("skip_collision" not in objects, "nested collision default should be skipped") require(objects["ground"]["geometry"]["primitive"] == "plane", "plane geom should export as plane") require(materials["mat_checker"]["textureKind"] == "checker", "builtin checker should be preserved") require(materials["mat_checker"]["textureColors"] == ["#ff0000", "#00ff00"], "checker colors should export") require(materials["mat_checker"]["textureRepeat"] == [4.0, 5.0], "checker repeat should export") require(materials["mat_file"]["textureUrl"] == "/assets/assets/tex.png", "assetdir texture path should export") require(materials["mat_file"]["textureRepeat"] == [2.0, 3.0], "file texture repeat should export") require(materials["mat_file"]["roughness"] == 0.2, "roughness should export") require(materials["mat_file"]["metalness"] == 0.4, "metalness should export") require(objects["meshgeom"]["geometry"]["url"] == "/assets/assets/mesh.obj", "assetdir mesh path should export") require(objects["meshgeom"]["pose"]["scale"] == [0.1, 0.2, 0.3], "mesh scale should become object pose scale") require(objects["inlinegeom"]["geometry"]["kind"] == "convexMesh", "inline mesh vertices should export") require(len(objects["inlinegeom"]["geometry"]["vertices"]) == 12, "inline mesh vertices should be retained") require(objects["bar"]["geometry"]["primitive"] == "cylinder", "fromto cylinder should export as cylinder") require(abs(objects["bar"]["geometry"]["length"] - 1.0) < 1e-9, "fromto length should drive cylinder length") require(objects["bar"]["pose"]["position"] == [0.0, 0.5, 0.0], "fromto midpoint should drive pose") require(objects["bar"]["pose"]["quaternion"] != [0.0, 0.0, 0.0, 1.0], "fromto should rotate local z axis") require("/assets/assets/tex.png" in manifest["_assetFiles"], "texture asset should be served by bridge") print("exporter feature checks ok") return 0 if __name__ == "__main__": raise SystemExit(main())