Files
issacdataengine/migerate/scan_usd_metadata.py
Tangger 03d9a5b909 fix: IS 4.5.0 -> 5.0.0 migration — USD metadata, DomeLight, scene reuse
- Fix USD metersPerUnit/upAxis for IS 5.0.0 (no longer auto-compensated)
- Batch fix all Aligned_obj.usd, table, and art USD files with backups
- Fix DomeLight rotation to Z-axis only (prevent tilted environment map)
- Fix scene reuse across episodes (arena_file caching, task clearing, prim guard)
- Add migration tools: scan_usd_metadata.py, fix_usd_metadata.py
- Add migration guide: migerate/migerate.md
- Add nvidia-curobo to .gitignore
- Fix sort_the_rubbish config: obj_0 -> obj_1 (obj_0 does not exist)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-03 11:10:39 +08:00

70 lines
2.2 KiB
Python

"""
Scan all USD files in the project and report their metersPerUnit / upAxis metadata.
Usage:
python migerate/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)