""" Scan all USD files in the project and report their metersPerUnit / upAxis metadata. Usage: python migrate/scan_usd_metadata.py [--root DIR] Default root: current working directory (project root). """ import argparse import glob import os import sys from pxr import Usd, UsdGeom def scan(root: str, target_mpu: float = 1.0, target_up: str = "Z"): usd_files = glob.glob(os.path.join(root, "**", "*.usd"), recursive=True) usd_files = [f for f in usd_files if not f.endswith(".bak")] usd_files.sort() ok_files = [] diff_files = [] error_files = [] for fpath in usd_files: try: stage = Usd.Stage.Open(fpath) if stage is None: error_files.append((fpath, "Cannot open stage")) continue mpu = UsdGeom.GetStageMetersPerUnit(stage) up = UsdGeom.GetStageUpAxis(stage) rel = os.path.relpath(fpath, root) if mpu == target_mpu and up == target_up: ok_files.append((rel, mpu, up)) else: diff_files.append((rel, mpu, up)) except Exception as e: error_files.append((fpath, str(e))) # Report print(f"Scanned {len(ok_files) + len(diff_files) + len(error_files)} USD files under: {root}") print(f" OK (mpu={target_mpu}, up={target_up}): {len(ok_files)}") print(f" Different: {len(diff_files)}") print(f" Errors: {len(error_files)}") if diff_files: print(f"\n{'='*80}") print(f"Files with non-standard metadata (mpu != {target_mpu} or up != {target_up}):") print(f"{'='*80}") for rel, mpu, up in diff_files: print(f" mpu={mpu:<8} up={up:<4} {rel}") if error_files: print(f"\n{'='*80}") print("Files with errors:") print(f"{'='*80}") for fpath, err in error_files: print(f" ERROR: {fpath} -> {err}") return diff_files if __name__ == "__main__": parser = argparse.ArgumentParser(description="Scan USD files for metersPerUnit/upAxis metadata") parser.add_argument("--root", default=os.getcwd(), help="Root directory to scan (default: cwd)") args = parser.parse_args() diff = scan(args.root) sys.exit(1 if diff else 0)