| """ |
| Export the TASK 9 packing-area scene as a single self-describing USD. |
| |
| Authors the same composition as teleop_openarm_demo_simready_warehouse_task_9.py |
| -- the empty warehouse shell (populated zones deactivated), the cleared |
| SM_CratePacking_Table_A1 packing bench at the origin, the dressing props |
| around it, and the dome/key lights -- into one USD layer that references the |
| PhysicalAI SimReady Warehouse assets by RELATIVE path. The output lives inside |
| the assets tree so those relative references stay valid: |
| |
| assets/task9_packing_area/task9_packing_area.usd |
| |
| Reference it as the background in benchmark scenes (e.g. under a /Root/ |
| Background Xform). The table work surface is at z=0.994 m; the area in front |
| of the table (world -y) is left clear for the robot. All props are static |
| colliders (physics variants), no rigid bodies. |
| |
| Pure pxr -- no Isaac Sim launch needed. Run with any python that has pxr, |
| e.g. the Isaac Sim USD libs: |
| |
| USDLIBS=/opt/isaac-sim/extscache/omni.usd.libs-1.0.1+69cbf6ad.lx64.r.cp311 |
| PYTHONPATH=$USDLIBS LD_LIBRARY_PATH=$USDLIBS/bin \ |
| /opt/isaac-sim/kit/python/bin/python3 simready_warehouse_tasks/export_task9_scene_usd.py |
| |
| or simply /opt/isaac-sim/python.sh (slower startup). |
| """ |
|
|
| from pathlib import Path |
|
|
| from pxr import Gf, Sdf, Usd, UsdGeom, UsdLux |
|
|
| SCRIPT_DIR = Path(__file__).resolve().parent |
| PROJECT_DIR = SCRIPT_DIR.parent |
| ASSETS_DIR = PROJECT_DIR / "assets" / "physicalai_simready_warehouse_01" |
| OUTPUT_PATH = PROJECT_DIR / "assets" / "task9_packing_area" / "task9_packing_area.usd" |
|
|
| |
| WAREHOUSE_REL = "../physicalai_simready_warehouse_01/physical_ai_simready_warehouse_01.usd" |
|
|
|
|
| def _assembly(name): |
| return f"../physicalai_simready_warehouse_01/Props/assembly/{name}/{name}_physics.usd" |
|
|
|
|
| def _general(name): |
| return f"../physicalai_simready_warehouse_01/Props/general/{name}/{name}_physics.usd" |
|
|
|
|
| |
|
|
| WAREHOUSE_KEEP_ZONES = ("warehouse_floorplan", "Environment") |
| WAREHOUSE_ROT = 270.0 |
| WAREHOUSE_POS = (56.08, -53.41, 0.0) |
|
|
| TABLE_USD = _assembly("SM_CratePacking_Table_A1") |
| TABLE_ROOT = "/Root/PackingTable" |
| TABLE_POS = (0.0, 0.0, 0.0) |
| TABLE_ROT = 0.0 |
| TABLE_KEEP = ("SM_HeavyDutyPackingTable",) |
| SHELF_Z = 0.354 |
|
|
| SCENERY = ( |
| ("RackBoxes", _assembly("sm_rackcomposition_s58_01"), (0.3, 3.0, 0.0), 0.0, 0.01), |
| ("BoxPileLeft", _assembly("WarehousePile_A3"), (-2.7, 1.0, 0.0), -15.0, 0.01), |
| ("BoxPileRight", _assembly("WarehousePile_A5"), (2.5, 0.4, 0.0), 15.0, 0.01), |
| ("PalletTruck", _general("SM_HeavyDutyPalletTruck_A01_01"), (3.6, 2.0, 0.0), -90.0, 0.01), |
| ("FloorBox", _general("Cardbox_C1"), (-1.9, -0.9, 0.0), 30.0, 0.01), |
| ("ShelfCartonA", _general("Cardbox_C1"), (-0.55, 0.0, SHELF_Z), 12.0, 0.01), |
| ("ShelfCartonB", _general("Cardbox_C1"), (0.35, -0.02, SHELF_Z), -30.0, 0.01), |
| ("ShelfCartonC", _general("Cardbox_D2"), (0.92, 0.05, SHELF_Z), 40.0, 0.01), |
| ) |
|
|
|
|
| def set_xform(prim, position, rotate_z=None, scale=None): |
| xf = UsdGeom.Xformable(prim) |
| xf.ClearXformOpOrder() |
| xf.AddTranslateOp(UsdGeom.XformOp.PrecisionDouble).Set(Gf.Vec3d(*position)) |
| if rotate_z is not None: |
| xf.AddRotateZOp(UsdGeom.XformOp.PrecisionDouble).Set(float(rotate_z)) |
| if scale is not None and abs(float(scale) - 1.0) > 1e-9: |
| s = float(scale) |
| xf.AddScaleOp(UsdGeom.XformOp.PrecisionDouble).Set(Gf.Vec3d(s, s, s)) |
|
|
|
|
| def main(): |
| OUTPUT_PATH.parent.mkdir(parents=True, exist_ok=True) |
| stage = Usd.Stage.CreateNew(str(OUTPUT_PATH)) |
| UsdGeom.SetStageUpAxis(stage, UsdGeom.Tokens.z) |
| UsdGeom.SetStageMetersPerUnit(stage, 1.0) |
|
|
| root = stage.DefinePrim("/Root", "Xform") |
| stage.SetDefaultPrim(root) |
|
|
| |
| warehouse = stage.DefinePrim("/Root/Warehouse", "Xform") |
| warehouse.GetReferences().AddReference(WAREHOUSE_REL) |
| set_xform(warehouse, WAREHOUSE_POS, WAREHOUSE_ROT) |
| dropped = [] |
| for child in warehouse.GetChildren(): |
| if child.GetName() not in WAREHOUSE_KEEP_ZONES: |
| child.SetActive(False) |
| dropped.append(child.GetName()) |
| print(f"Warehouse referenced; dropped zones: {dropped}") |
|
|
| |
| table = stage.DefinePrim(TABLE_ROOT, "Xform") |
| table.GetReferences().AddReference(TABLE_USD) |
| set_xform(table, TABLE_POS, TABLE_ROT) |
| if table.IsInstance(): |
| table.SetInstanceable(False) |
| cleared = [] |
| for child in table.GetChildren(): |
| if any(child.GetName().startswith(keep) for keep in TABLE_KEEP): |
| continue |
| child.SetActive(False) |
| cleared.append(child.GetName()) |
| print(f"Table referenced; cleared {len(cleared)} props") |
|
|
| |
| |
| |
| for name, usd_rel, pos, rot, scale in SCENERY: |
| prop = stage.DefinePrim(f"/Root/Scenery/{name}", "Xform") |
| model = stage.DefinePrim(f"/Root/Scenery/{name}/Model", "Xform") |
| model.GetReferences().AddReference(usd_rel) |
| set_xform(prop, pos, rot, scale) |
| print(f"Scenery {name}: {usd_rel} at {pos}, rot={rot}, scale={scale}") |
|
|
| |
| |
| dome = UsdLux.DomeLight.Define(stage, "/Root/Lights/DomeLight") |
| dome.CreateIntensityAttr(120.0) |
| dome.CreateColorAttr(Gf.Vec3f(1.0, 1.0, 1.0)) |
| key = UsdLux.DistantLight.Define(stage, "/Root/Lights/KeyLight") |
| key.CreateIntensityAttr(900.0) |
| key.CreateAngleAttr(0.35) |
| key.CreateColorAttr(Gf.Vec3f(1.0, 0.96, 0.90)) |
| xf = UsdGeom.Xformable(key.GetPrim()) |
| xf.ClearXformOpOrder() |
| xf.AddRotateXYZOp(UsdGeom.XformOp.PrecisionDouble).Set(Gf.Vec3d(-55.0, 0.0, 30.0)) |
|
|
| stage.GetRootLayer().Save() |
| print(f"Saved: {OUTPUT_PATH}") |
|
|
|
|
| if __name__ == "__main__": |
| main() |
|
|