Skip to content

Commit db06239

Browse files
committed
add supoort for random init
Signed-off-by: zhx06 <zihaox@nvidia.com>
1 parent 24d6696 commit db06239

13 files changed

Lines changed: 1235 additions & 122 deletions

isaaclab_arena/assets/object.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@
1616
from isaaclab_arena.utils.bounding_box import AxisAlignedBoundingBox, quaternion_to_90_deg_z_quarters
1717
from isaaclab_arena.utils.pose import Pose
1818
from isaaclab_arena.utils.usd.rigid_bodies import find_shallowest_rigid_body
19-
from isaaclab_arena.utils.usd_helpers import compute_local_bounding_box_from_usd, has_light, open_stage
19+
from isaaclab_arena.utils.usd_helpers import (
20+
compute_local_bounding_box_from_usd,
21+
extract_trimesh_from_usd,
22+
has_light,
23+
open_stage,
24+
)
2025

2126

2227
class Object(ObjectBase):
@@ -74,6 +79,31 @@ def get_bounding_box(self) -> AxisAlignedBoundingBox:
7479
self.bounding_box = compute_local_bounding_box_from_usd(self.usd_path, self.scale)
7580
return self.bounding_box
7681

82+
def get_collision_mesh(self):
83+
"""Lazily extract collision mesh from USD. Cached after first call."""
84+
if not hasattr(self, "_collision_mesh"):
85+
self._collision_mesh = None
86+
if self.usd_path is not None:
87+
try:
88+
self._collision_mesh = extract_trimesh_from_usd(self.usd_path, self.scale)
89+
except (ValueError, RuntimeError, OSError) as e:
90+
print(f" [MeshCollision] Could not extract mesh for '{self.name}': {e}")
91+
return self._collision_mesh
92+
93+
def __deepcopy__(self, memo):
94+
"""Exclude _collision_mesh from deepcopy (trimesh has unpicklable C pointers)."""
95+
import copy
96+
97+
cls = self.__class__
98+
result = cls.__new__(cls)
99+
memo[id(self)] = result
100+
for k, v in self.__dict__.items():
101+
if k == "_collision_mesh":
102+
setattr(result, k, None)
103+
else:
104+
setattr(result, k, copy.deepcopy(v, memo))
105+
return result
106+
77107
def get_world_bounding_box(self) -> AxisAlignedBoundingBox:
78108
"""Get bounding box in world coordinates (local bbox rotated and translated).
79109

isaaclab_arena/cli/isaaclab_arena_cli.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ def add_isaaclab_arena_cli_args(parser: argparse.ArgumentParser) -> None:
8686
"Only affects objects positioned by the placement solver; manually-placed objects are unaffected."
8787
),
8888
)
89+
arena_group.add_argument(
90+
"--collision_mode",
91+
type=str,
92+
choices=["bbox", "mesh"],
93+
default="bbox",
94+
help="Collision detection mode: 'bbox' (AABB, default) or 'mesh' (sphere-to-SDF, requires Warp).",
95+
)
8996

9097

9198
def add_env_graph_spec_cli_args(parser: argparse.ArgumentParser) -> None:

isaaclab_arena/environments/arena_env_builder.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ def _solve_relations(self) -> None:
7373
placement_seed=self.args.placement_seed,
7474
resolve_on_reset=self.args.resolve_on_reset,
7575
random_yaw_init=self.args.random_yaw_init,
76+
collision_mode=getattr(self.args, "collision_mode", "bbox"),
7677
)
7778

7879
def get_all_variations(self) -> dict[str, list[VariationBase]]:

isaaclab_arena/environments/relation_solver_interface.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def solve_and_apply_relation_placement(
2626
placement_seed: int | None = None,
2727
resolve_on_reset: bool | None = None,
2828
random_yaw_init: bool = False,
29+
collision_mode: str = "bbox",
2930
) -> EventTermCfg | None:
3031
"""Solve relation placement and apply the result to object reset/static state.
3132
@@ -38,20 +39,24 @@ def solve_and_apply_relation_placement(
3839
initial poses are applied immediately.
3940
random_yaw_init: If True, randomly rotates non-anchor objects around the vertical (Z)
4041
axis at startup to add visual variety to the scene.
42+
collision_mode: Collision detection mode: "bbox" or "mesh".
4143
4244
Returns:
4345
Reset event config to attach to the environment when placement should be
4446
resolved on reset. Returns ``None`` when no reset event is needed.
4547
"""
48+
from isaaclab_arena.relations.relation_solver_params import CollisionMode
49+
4650
objects = list(objects)
4751
if not objects:
4852
print("No objects with relations found in scene. Skipping relation solving.")
4953
return None
5054

55+
mode = CollisionMode.MESH if collision_mode == "mesh" else CollisionMode.BBOX
5156
placer_params = ObjectPlacerParams(
5257
placement_seed=placement_seed,
5358
apply_positions_to_objects=False,
54-
solver_params=RelationSolverParams(save_position_history=False, verbose=False),
59+
solver_params=RelationSolverParams(collision_mode=mode, save_position_history=False, verbose=False),
5560
random_yaw_init=random_yaw_init,
5661
)
5762
if resolve_on_reset is not None:

0 commit comments

Comments
 (0)