File size: 6,163 Bytes
5401084
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
"""
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"

# Asset paths are authored RELATIVE to the output layer's directory.
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"


# ── the task-9 scene definition (kept in sync with the task-9 script) ─────────

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)

    # 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)
    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}")

    # 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}")

    # Lights (same as the task-9 script's streaming lights), so the background
    # is lit even if the loading app adds none of its own.
    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()