I am using trimesh to add terrain features to an omniverse isaac gym environment.
However despite adding the prim of the terrain to the global collider list, the collider still only interacts with one environment. (relevant code below)
If I use the same code, but with the defaultGroundPlane in the global collider list instead of the terrain, the code works.
Upon inspection of the collision groups in the simulation window, it seems, that all colliders are set correctly.
collision_filter_global_paths = list()
if not self.has_terrain:
if self._scene_config.get("add_ground_plane", True):
self._ground_plane_path = "/World/defaultGroundPlane"
collision_filter_global_paths.append(self._ground_plane_path)
scene.add_default_ground_plane(prim_path=self._ground_plane_path)
else:
heightfield = self.get_terrain_hightfield()
collision_filter_global_paths.append('/World/terrain')
vertices, triangles = convert_heightfield_to_trimesh(heightfield, self.horizontal_scale, self.vertical_scale, slope_threshold=1.5)
add_terrain_to_stage(stage=self.stage, vertices=vertices, triangles=triangles, position=self.position, orientation=self.orientation )
prim_paths = self._cloner.generate_paths("/World/envs/env", self.num_envs)
self._env_pos = self._cloner.clone(source_prim_path="/World/envs/env_0", prim_paths=prim_paths)
self._env_pos = torch.tensor(np.array(self._env_pos), device=self._device, dtype=torch.float)
self._cloner.filter_collisions(
self._env._world.get_physics_context().prim_path, "/World/collisions", prim_paths, collision_filter_global_paths)
def add_terrain_to_stage(stage, vertices, triangles, position=None, orientation=None):
num_faces = triangles.shape[0]
terrain_mesh = stage.DefinePrim("/World/terrain", "Mesh")
terrain_mesh.GetAttribute("points").Set(vertices)
terrain_mesh.GetAttribute("faceVertexIndices").Set(triangles.flatten())
terrain_mesh.GetAttribute("faceVertexCounts").Set(np.asarray([3]*num_faces))
terrain = XFormPrim(prim_path="/World/terrain",
name="terrain",
position=position,
orientation=orientation)
UsdPhysics.CollisionAPI.Apply(terrain.prim)
collision_api = UsdPhysics.MeshCollisionAPI.Apply(terrain.prim)
collision_api.CreateApproximationAttr().Set("meshSimplification")
physx_collision_api = PhysxSchema.PhysxCollisionAPI.Apply(terrain.prim)
physx_collision_api.GetContactOffsetAttr().Set(0.02)
physx_collision_api.GetRestOffsetAttr().Set(0.00)
I also had a look at the ‘AnymalTerrain’ task from the omniverseisaacgymenves, and I could not figure out how the colliders are set there.