File size: 5,253 Bytes
870b85a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env python3
from __future__ import annotations

import argparse
import hashlib
import json
import sys
from pathlib import Path


INTERNAL_PHYSICS_DIR = Path(__file__).resolve().parent / "internal" / "physics_isaac"
if str(INTERNAL_PHYSICS_DIR) not in sys.path:
    sys.path.insert(0, str(INTERNAL_PHYSICS_DIR))

from rhg_visual_scene_package_v16_60 import validate_scene_package, validate_visual_contract


def load_json(path: Path) -> dict:
    return json.loads(path.read_text(encoding="utf-8"))


def main() -> int:
    parser = argparse.ArgumentParser(description="Validate a lightweight Scene Package or generation output root.")
    parser.add_argument("--root", required=True, type=Path)
    parser.add_argument("--report", type=Path, default=None, help="Optional path to save the JSON validation report.")
    args = parser.parse_args()
    root = args.root.resolve()
    scene_root = root / "scenes" if (root / "scenes").is_dir() else root
    scene_dirs = [root] if root.name.startswith("fullhome_asset_v16_") and root.is_dir() else sorted(path for path in scene_root.glob("fullhome_asset_v16_*") if path.is_dir())
    report = {
        "schema": "robohavengen.scene_package.validation.v0_1",
        "root": str(root),
        "scene_count": len(scene_dirs),
        "scenes": [],
    }
    for scene_dir in scene_dirs:
        row = {
            "scene_id": scene_dir.name,
            "path": str(scene_dir),
            **validate_scene_package(scene_dir),
        }
        camera_path=scene_dir/'camera_manifest.json'
        if (scene_dir/'door_hinge_contract.json').is_file():
            sys.path.insert(0,str(Path(__file__).parent/'internal/scene_generation/real_assets'))
            from door_gate_contract import validate as validate_doors
            door_check=validate_doors(scene_dir);row['door_physics_contract']=door_check
            if not door_check['passed']:
                row['passed']=False
                row['capabilities']['metadata_ready']=False
                row['capabilities']['usd_export_ready']=False
        audit_path=scene_dir/'render_audit.json'
        if (scene_dir/'native_articulation_policy.json').is_file():
            sys.path.insert(0,str(Path(__file__).parent/'internal/scene_generation/real_assets'))
            from native_scene_contract import validate as validate_native
            native_check=validate_native(scene_dir);row['native_articulation_contract']=native_check
            if not native_check['passed']:
                row['passed']=False;row['capabilities']['metadata_ready']=False;row['capabilities']['usd_export_ready']=False
        if not camera_path.is_file() and audit_path.is_file() and load_json(audit_path).get('profile')=='overview':
            row['rendered_preview_contract']={'passed':False,'failures':['missing_fixed_overview_camera_manifest']}
            row['passed']=False
            row['capabilities']['metadata_ready']=False
            row['capabilities']['usd_export_ready']=False
        if camera_path.is_file():
            camera=load_json(camera_path);errors=[]
            if camera.get('profile')=='overview':
                sys.path.insert(0,str(Path(__file__).parent/'internal/scene_generation/real_assets'))
                from presentation_windows import overview_views_valid
                if not overview_views_valid(camera.get('views',[])):
                    errors.append('fixed_top_oblique_camera_contract_mismatch')
            for view in camera.get('views',[]):
                image=(scene_dir/view['path']).resolve()
                if (not image.is_relative_to(scene_dir.resolve()) or not image.is_file()
                        or hashlib.sha256(image.read_bytes()).hexdigest()!=view['sha256']):
                    errors.append('packaged_preview_missing_or_changed:'+view.get('name','unknown'))
            row['rendered_preview_contract']={'passed':not errors,'profile':camera.get('profile'),
                'view_count':len(camera.get('views',[])),'failures':errors}
            if errors:
                row['passed']=False
                row['capabilities']['metadata_ready']=False
                row['capabilities']['usd_export_ready']=False
        manifest = scene_dir / "SceneManifest.v16.json"
        if manifest.is_file() and not any(item["name"] == manifest.name for item in row["invalid_required_files"]):
            data = load_json(manifest)
            row["scene_manifest_schema"] = data.get("schema")
            row["manifest_visual_contract"] = data.get("visual_contract_v16_60")
        report["scenes"].append(row)
    report["capabilities"] = {
        name: bool(scene_dirs) and all(scene["capabilities"][name] for scene in report["scenes"])
        for name in ("metadata_ready", "usd_export_ready", "sim_ready")
    }
    report["passed"] = report["capabilities"]["metadata_ready"]
    if args.report:
        report_path = args.report.resolve()
        report_path.parent.mkdir(parents=True, exist_ok=True)
        report_path.write_text(json.dumps(report, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
    print(json.dumps(report, ensure_ascii=False, indent=2))
    return 0 if report["passed"] else 1


if __name__ == "__main__":
    raise SystemExit(main())