"""Readies one package of this dataset for NVIDIA's SimReady Robot-Body profile, then re-hashes it. - Writes the provenance fields of SR.004 into the root USD's `SimReady_Metadata` (customLayerData). - Makes the guide-purpose collision meshes invisible: VG.008 only skips invisible meshes, so a collider that coincides with its visual mesh fails it. Physics ignores visibility. - Rewrites the package's file list and hashes (`.metadata/com.nvidia.simready.packaging.bom.json`, `com.nvidia.simready.packaging.json`), per PKG.HASH.001. usage: simready.py """ import datetime import hashlib import json import os import sys from pxr import Gf, Usd, UsdGeom, UsdPhysics DEFINITION = "com.nvidia.simready.packaging.json" BOM = "com.nvidia.simready.packaging.bom.json" pkg, category, qcode, version = sys.argv[1:5] package = os.path.basename(os.path.normpath(pkg)) with open(os.path.join(pkg, DEFINITION)) as f: license_id = json.load(f)["license"] with open(os.path.join(pkg, ".metadata", "com.nvidia.simready.root_usds.json")) as f: (root_usd,) = json.load(f)["entries"] stage = Usd.Stage.Open(os.path.join(pkg, root_usd)) layer = stage.GetRootLayer() for prim in stage.Traverse(): if prim.HasAPI(UsdPhysics.CollisionAPI) and prim.IsA(UsdGeom.Gprim) and UsdGeom.Imageable(prim).ComputePurpose() == UsdGeom.Tokens.guide: UsdGeom.Imageable(prim).GetVisibilityAttr().Set(UsdGeom.Tokens.invisible) bodies = [p for p in stage.Traverse() if p.HasAPI(UsdPhysics.RigidBodyAPI)] extents = UsdGeom.BBoxCache(Usd.TimeCode.Default(), [UsdGeom.Tokens.default_, UsdGeom.Tokens.render]).ComputeWorldBound(stage.GetDefaultPrim()).ComputeAlignedRange().GetSize() layer.customLayerData = { **layer.customLayerData, "SimReady_Metadata": { "author": "Hugging Face LeRobot", "asset_name": package, "asset_type": "robot", "asset_license": license_id, "category": category, "source_file": layer.customLayerData["lerobot:source"], "usd_date_generated": datetime.date.today().isoformat(), "qcode": qcode, "rigid_body_count": len(bodies), "asset_extents": Gf.Vec3f(*(round(v, 4) for v in extents)), "mass": round(sum(UsdPhysics.MassAPI(b).GetMassAttr().Get() or 0.0 for b in bodies), 3), }, } layer.Save() def sha256(data): return hashlib.sha256(data).hexdigest() items = [] for root, _, files in os.walk(pkg): for name in files: path = os.path.join(root, name) rel = os.path.relpath(path, pkg).replace(os.sep, "/") if rel == DEFINITION or rel.startswith(".metadata/"): continue with open(path, "rb") as f: items.append({"relative_path": rel, "size": os.path.getsize(path), "hash": {"sha256": sha256(f.read())}}) items.sort(key=lambda i: i["relative_path"].encode()) bom_json = json.dumps({"format_version": "1.0", "items": items}, indent=2) with open(os.path.join(pkg, ".metadata", BOM), "w") as f: f.write(bom_json) content = bytearray() for item in items: content += item["relative_path"].encode() + b"\0" + bytes.fromhex(item["hash"]["sha256"]) content_hash = sha256(bytes(content)) metadata = [{"name": BOM, "hash": {"sha256": sha256(bom_json.encode())}}] package_id = f"simready.hf.lerobot.robot-usds.{package}.{version}" buf = bytearray(package_id.encode() + b"\0" + license_id.encode() + b"\0" + bytes.fromhex(content_hash)) for entry in sorted(metadata, key=lambda e: e["name"].encode()): buf += entry["name"].encode() + b"\0" + bytes.fromhex(entry["hash"]["sha256"]) with open(os.path.join(pkg, DEFINITION), "w") as f: definition = { "format_version": "1.0", "package_id": package_id, "license": license_id, "metadata": metadata, "content_hash": {"sha256": content_hash}, "package_hash": {"sha256": sha256(bytes(buf))}, } f.write(json.dumps(definition, indent=2) + "\n") print(package, json.dumps(dict(layer.customLayerData["SimReady_Metadata"]), default=list))