What is the best practice for rendering PxConvexMeshGeometry with triangles?

PhysX 2.7 had a convex mesh descriptor that contained (after cooking) a list of triangles that tessellated the convex hull. With this list it was a simple matter to render the convex shape with GL_TRIANGLES.

PhysX 3.2 has a PxConvexGeometry type that references a PxConvexMesh type. The PxConvexMesh has a list of vertices for the 3D object, and a list of polygons, presumably triangles, given by

PxConvexMesh::getPolygonData(PxU32 idx, PxHullPolygon &data)

However, the PxHullPolygon type contains only the number of vertices and the plane equation. I am not sure how to go about drawing that polygon. Is there a way to get the actual vertices of the k-th polygon? Is there a better way to render a PxConvexMeshGeometry with openGL?
Thanks,
-nuun

This is totally written without any testing so I can’t make any guarantees, but I believe you could probably do something like this:

// EDIT: Removed this snippet. See post below for correct code.

I’ve never done anything like this in any of my projects, so I don’t know if there’s a better way to do it.

Thanks for the reply!

That method can’t be right though. I don’t know what precisely is stored in PxHullPolygon::mIndexBuffer (the reference just states “Offset in index buffer”) but it’s NOT the position of the first of mNbVerts PxVec3 elements in PxConvexMesh::getVertices(). My test pyramid has 5 vertices (as returned by mesh.getNbVertices()) and 5 polygons (mesh.getNbPolygons()), each of the polygons has 3 vertices. The polygon.mIndexBase for the first polygon is 0, and for the second it is 6. There are not enough elements in mesh.getVertices().

Perhaps if we understood what exactly is the “offset in index buffer” we will be able to retrieve the vertices of each polygon.

But I can’t be the only one who needs to render his convex meshes can I? The PVD renders my convex actors just fine, so I know it can be done. But the PVD also renders with DirectX, which I know nothing about.

All ideas appreciated, thanks,
-nuun

If all you want to do is draw your physics scene, read up on PxRenderBuffer class. We use it in our project and it’s worked out pretty well. It’s not as easy to distinguish objects once they’re in the buffer, but you have a lot of customization for what goes into it.

I skimmed the api docs (hence the above code not working correctly), and missed the section in the guide on Convex Meshes:

There it is! Guess I didn’t scroll down enough in the guide. Thanks!

There it is! Guess I didn’t scroll down enough in the guide. Thanks!