mp_yam_code / scripts /yam_asset_probe.py
yqi19's picture
YAM bimanual task suite: env, solvers, tasks, converters
7399b6f verified
Raw
History Blame Contribute Delete
2.16 kB
"""Spawn candidate scenesmith assets (scale 1.0) off to the side and print native AABB size,
so we can choose a scale that makes an object graspable (~4.5 cm) or a container usable."""
import sys, os
from isaaclab.app import AppLauncher
import argparse
p=argparse.ArgumentParser(); AppLauncher.add_app_launcher_args(p); a=p.parse_args(); a.headless=True; a.enable_cameras=False
app=AppLauncher(a).app
import numpy as np, gymnasium as gym
REPO=os.path.dirname(os.path.dirname(os.path.abspath(__file__))); sys.path.insert(0,os.path.join(REPO,"source"))
import bimanual.tasks.manager_based.yam # noqa
from bimanual.tasks.manager_based.yam.yam import CUSTOM_ASSETS_DIR
from isaaclab_tasks.utils import parse_env_cfg
env=gym.make("Template-YAM-Play-v0", cfg=parse_env_cfg("Template-YAM-Play-v0", device="cuda:0", num_envs=1)); u=env.unwrapped; env.reset()
import omni.usd, isaaclab.sim as sim_utils
from pxr import UsdGeom, Usd
stage=omni.usd.get_context().get_stage()
CAND=["coffee_mug","ceramic_cup","ceramic_mug","amber_glass_bottle","glass_tumbler_cup",
"bathroom_tumbler_cup","carafe_bottle","fruit_bowl","mixing_bowl","ceramic_bowl",
"decorative_bowl","storage_box","cardboard_box","serving_tray"]
xf=UsdGeom.XformCache(Usd.TimeCode.Default())
for i,name in enumerate(CAND):
up=f"{CUSTOM_ASSETS_DIR}/scenesmith_obj/{name}/{name}.usd"
if not os.path.exists(up): print(f"{name:22s} MISSING", flush=True); continue
try:
cfg=sim_utils.UsdFileCfg(usd_path=up, scale=(1,1,1))
cfg.func(f"/World/probe_{i}", cfg, translation=(3.0+i*0.6, 3.0, 1.0))
bb=UsdGeom.BBoxCache(Usd.TimeCode.Default(),[UsdGeom.Tokens.default_,UsdGeom.Tokens.render])
rng=bb.ComputeWorldBound(stage.GetPrimAtPath(f"/World/probe_{i}")).ComputeAlignedRange()
ext=np.array(rng.GetMax())-np.array(rng.GetMin())
wmax=max(ext[0],ext[1]); s_grasp=0.045/wmax if wmax>0 else 0
print(f"{name:22s} native(m)=[{ext[0]:.3f},{ext[1]:.3f},{ext[2]:.3f}] scale->4.5cm_wide={s_grasp:.3f}", flush=True)
except Exception as e:
print(f"{name:22s} ERR {e}", flush=True)
env.close(); app.close(); print("PROBE_OK", flush=True)