|
16 | 16 | from isaaclab_arena.utils.bounding_box import AxisAlignedBoundingBox, quaternion_to_90_deg_z_quarters |
17 | 17 | from isaaclab_arena.utils.pose import Pose |
18 | 18 | 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 | +) |
20 | 25 |
|
21 | 26 |
|
22 | 27 | class Object(ObjectBase): |
@@ -74,6 +79,31 @@ def get_bounding_box(self) -> AxisAlignedBoundingBox: |
74 | 79 | self.bounding_box = compute_local_bounding_box_from_usd(self.usd_path, self.scale) |
75 | 80 | return self.bounding_box |
76 | 81 |
|
| 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 | + |
77 | 107 | def get_world_bounding_box(self) -> AxisAlignedBoundingBox: |
78 | 108 | """Get bounding box in world coordinates (local bbox rotated and translated). |
79 | 109 |
|
|
0 commit comments