How to get triangle meshes?

Hello, I am testing create_collision_sphere_generator() in CollisionSphereGenerator class. It needs vertices and triangles as inputs.
I can use get_mesh_vertices_relative_to() to get all vertices of a mesh. But how can I get the correspond triangles in the collider?

You can install external python packages, like trimesh. Then create a trimesh sphere like:

ico = trimesh.creation.icosphere(2)
faces = ico.faces
vertices = ico.vertices
face_vertex_count = np.ones(faces.shape[0], dtype=np.int64) * 3

Then create a sphere via omniverse:


def create_sphere(manual_sphere_path, vertices, face_vertex_count, faces, 
                  steel_density, position, velocity):

    convexGeom = UsdGeom.Mesh.Define(stage, manual_sphere_path)
    convexPrim = stage.GetPrimAtPath(manual_sphere_path)

    convexGeom.CreatePointsAttr(vertices)
    convexGeom.CreateFaceVertexCountsAttr(face_vertex_count)
    convexGeom.CreateFaceVertexIndicesAttr(faces)

    contactReportAPI = PhysxSchema.PhysxContactReportAPI.Apply(convexPrim)

    mass_api_sphere = UsdPhysics.MassAPI.Apply(stage.GetPrimAtPath(manual_sphere_path))

    omni.kit.commands.execute('TransformMultiPrimsSRTCpp',
        count=1,
        paths=[manual_sphere_path],
        new_translations=[position[0], position[1], position[2]],
        new_rotation_eulers=[0.0, -0.0, 0.0],
        new_rotation_orders=[0, 1, 2],
        new_scales=[1.0, 1.0, 1.0],
        old_translations=[0.0, 0.0, 0.5],
        old_rotation_eulers=[0.0, -0.0, 0.0],
        old_rotation_orders=[0, 1, 2],
        old_scales=[1.0, 1.0, 1.0],
        usd_context_name='',
        time_code=0.0)

    omni.kit.commands.execute('SetRigidBody',
        path=Sdf.Path(manual_sphere_path),
        approximationShape='convexHull',
        kinematic=False)

    omni.kit.commands.execute('ChangeProperty',
        prop_path=Sdf.Path('{}.physxRigidBody:maxLinearVelocity'.format(manual_sphere_path)),
        value=150.0,
        prev=0.0,
        usd_context_name=stage)

    omni.kit.commands.execute('ChangeProperty',
        prop_path=Sdf.Path('{}.physics:density'.format(manual_sphere_path)),
        value=steel_density,
        prev=0.0,
        usd_context_name=stage)

    omni.kit.commands.execute('ChangeProperty',
        prop_path=Sdf.Path('{}.physxRigidBody:disableGravity'.format(manual_sphere_path)),
        value=True,
        prev=None,
        usd_context_name=stage)

    return

# Create spheres
sphere_path_00 = "/World/obj_00"
position_00 = [3.0, 0, 1.5]
velocity_00 = [-10, 0, 0]
create_sphere(sphere_path_00, vertices, face_vertex_count, faces, 
                  steel_density, position_00, velocity_00)

After creation via this method, you can access the faces, face vertex counts, and vertices via:

convexGeom = UsdGeom.Mesh(stage.GetPrimAtPath(prim_path))
sphere_verts = np.array(convexGeom.GetPointsAttr().Get())
face_verts = np.array(convexGeom.GetFaceVertexIndicesAttr().Get())
face_vertex_count = np.array(convexGeom.GetFaceVertexCountsAttr().Get())