packingbench-assets / scripts /export_simple_packing_scene_usd.py
Hovessian's picture
Update export_simple_packing_scene_usd.py (shell at identity, tuned lighting)
d8d8dc6 verified
Raw
History Blame Contribute Delete
7 kB
"""
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). Frame contract: origin at the table (work surface center),
x = table long axis, y = away from the robot; work surface at z=0.994 m,
floor at z=0. Depth order along -y: table, robot spot (~y=-0.5, kept clear),
box rack behind the robot, warehouse wall behind that; open warehouse beyond
the table. 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" / "simple_packing_area" / "simple_packing_area.usd"
# Asset paths are authored RELATIVE to the output layer's directory.
WAREHOUSE_REL = "../isaac_sim_assets_51/Isaac/Environments/Simple_Warehouse/warehouse.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"
# ── the task-9 scene definition (kept in sync with the task-9 script) ─────────
# Isaac Simple_Warehouse shell (local mirror of NVIDIA's cloud asset,
# ~24x39 m hall, floor z=0). Referenced at IDENTITY, matching the live
# teleop layout that was visually approved. Do NOT shift the shell +y: the
# hall has an interior dividing wall at shell-local y=-12.1 (full-width
# panels SM_WallA_6M4/6/7 + upper 3M rows, with a 6 m back room behind it);
# a +10 y shift parks that wall at world y=-2.1, exactly in front of the
# box rack (y -4.7..-2.1), hiding every box behind brick. At identity the
# wall sits ~11.6 m behind the robot and the rack stands inside the hall.
WAREHOUSE_KEEP_ZONES = None
WAREHOUSE_ROT = 0.0
WAREHOUSE_POS = (0.0, 0.0, 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 = (
# Boxes-loaded double rack BEHIND the robot (robot ~y=-0.5): rack depth
# 2.56 m centered at y=-3.4 spans y -4.7..-2.1, ~1.2 m behind the robot.
("RackBoxes", _assembly("sm_rackcomposition_s58_01"), (0.3, -3.4, 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),
# Hand pallet truck parked by the rack, behind the robot.
("PalletTruck", _general("SM_HeavyDutyPalletTruck_A01_01"), (3.4, -3.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)
# Empty warehouse: reference the full scene, deactivate populated zones.
warehouse = stage.DefinePrim("/Root/Warehouse", "Xform")
warehouse.GetReferences().AddReference(WAREHOUSE_REL)
set_xform(warehouse, WAREHOUSE_POS, WAREHOUSE_ROT)
print(f"Simple_Warehouse shell referenced at {WAREHOUSE_POS}")
# Packing bench, cleared down to the bare table.
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")
# Dressing props. Reference each on a child prim: the assets author their
# own float3 xformOp:scale, which collides with set_xform's
# double-precision ops if the reference sits directly on the root.
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}")
# Lighting. The Simple_Warehouse shell lights itself: 16 ceiling lamps
# (RectLight 400k each) plus one hall-wide fill RectLight whose authored
# 5000 intensity alone overexposes the packing area (table-view mean
# ~171/255). Dim that fill to 2000 and add only a soft dome for shadow
# fill -- no distant key light (the task-9 photoreal shell needed one,
# this shell does not). Tuned to table-view mean ~118/255.
fill = stage.GetPrimAtPath("/Root/Warehouse/RectLight")
fill.GetAttribute("inputs:intensity").Set(2000.0)
dome = UsdLux.DomeLight.Define(stage, "/Root/Lights/DomeLight")
dome.CreateIntensityAttr(60.0)
dome.CreateColorAttr(Gf.Vec3f(1.0, 1.0, 1.0))
stage.GetRootLayer().Save()
print(f"Saved: {OUTPUT_PATH}")
if __name__ == "__main__":
main()