File size: 2,632 Bytes
41aebeb | 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 | # Copyright (c) 2026, dishsim project.
#
# SPDX-License-Identifier: BSD-3-Clause
"""Author the per-state machine USDs the scene loads: ``data/assets/<machine>/usd/model_*_v0<suffix>.usda``.
Until 2026-10-21 ``dishsim.machine`` called ``usd_prep`` at import and authored these on demand; now they ship in the
asset dataset and this script (Kit-free, pxr from ``run_py.sh``) is the only writer. Each file bakes in the rack
geometry (``rack_gen`` from ``config.RACK_GEN``), the door clamp and the state's rack drive targets, and carries a
stamp of all three; an existing file whose stamp matches is left untouched. ``artvip_compact`` derives from the
ArtVIP originals in ``../../artvip_dishwasher_2/usd`` (``fetch_artvip.py`` there) and writes next to them.
code/util/run_py.sh data/assets/bosch800/source/export_usd.py --machine bosch800 --states placement both_in
code/util/run_py.sh data/assets/bosch800/source/export_usd.py --machine artvip_compact # every cached state
"""
import argparse
import os
import sys
REPO = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))))
sys.path.insert(0, os.path.join(REPO, "code", "src"))
from dishsim import config # noqa: E402
import usd_prep # noqa: E402 (this folder)
def export(machine: str, state: str) -> str:
config.apply_machine(machine) # first: it resets scenario + base placement
config.apply_scenario(state)
kw = dict(door_open_deg=config.DOOR_OPEN_DEG, door_band_deg=config.DOOR_BAND_DEG,
rack_targets=config.RACK_JOINT_TARGETS, suffix="" if state == "both_out" else f"_{state}")
if machine == "bosch800":
return usd_prep.make_bosch800_usd(**kw)
src = os.path.join(config.machine_asset_dir(machine), "usd", "model_dishwasher_2.usda")
return usd_prep.make_dishwasher_v0_usd(src, **kw)
def main() -> None:
parser = argparse.ArgumentParser(description="Author the per-state machine USDs.")
parser.add_argument("--machine", choices=sorted(config.MACHINE_ASSET_DIRS), default="bosch800")
parser.add_argument("--states", nargs="*", default=None,
help="rack states (default: every state with a cache under <machine>/cache/)")
args = parser.parse_args()
cache = os.path.join(config.machine_asset_dir(args.machine), "cache")
states = args.states or sorted(d for d in os.listdir(cache) if d != "coacd")
for state in states:
print(f"[INFO] {args.machine} / {state}: {export(args.machine, state)}")
print(f"[RESULT] PASS {len(states)} machine USDs")
if __name__ == "__main__":
main()
|