How to do PhysX C++ raycast in USDPhysicsScene?

Hi all,

since neither the RTX Lidar nor the generic range sensor have the behaviour we need for our Lidar simulation, I would like to do some fast PhysX raycasting in my own C++ extension. Using the Python raycast command seems too slow to simulate multiple Lidars in an custom Python extension.

Here in the PhysX documentation I found a suitable command to do raycasting. It works on PxScenes. But the C++ extension snippets only use UsdPhysicsScene.

Questions:

  1. Is my idea at all possible?
  2. Could someone please point me to some sample code or docs on how to convert a UsdPhysicsScene into a PxScene?
  3. Upon each ray intersection with an element in the PxScene I would like to get a pointer to the corresponding prim that got hit. Is that possible, and how? Reason: I would like to retrieve the material of that prim.
  4. Or should I try to find a raycaster from Pixar?

Cheers,

Markus

Hi,
yes, this is possible to get working.
In the C++ extension you have to acquire the IPhysx interface:

    carb::Framework* framework = carb::getFramework();
    physxI = framework->acquireInterface<omni::physx::IPhysx>();

Once you have this interface you can translate between PhysX SDK and USD.
From USD to PhysX SDK you can use:

PxScene* scene = reinterpret_cast<PxScene*>(physxI->getPhysXPtr(physicsScenePath, ePTScene));

Then you can do what ever raycasting you need.
Now back from PhysX SDK to USD you can use its userData value to get translated to SdfPath, eventually you can use getName - thats the string version of the SdfPath but we treat it more of a debug information rather then fixed data. The userData have always in index into our internal database so we can return USD path:

PxRigidBody* rbo...
pxr::SdfPath sdfPath = physxI->getPhysXObjectUsdPath((ObjectId)rbo->userData);

I am not sure what all you need to do, but you can use the C++ interface on IPhysxSceneQuery, there is raycast/sweep etc exposed and it does return already translated values.

1 Like

Hi AlesBorovicka,
many thanks for your reply. I might not necessarily need not use PhysX, maybe IPhysXSceneQuery is sufficient, I don’t know yet. I just did not came up in my searches. Do you happen to have some documentation you could link here?
Cheers,
Markus

@AlesBorovicka The omni::physx::IPhysx seems to be unavailable in any headers of Omniverse Kit 105 or 104. How does one get access to it ?

We are in the process of open sourcing examples and environment how to access the omni physx interfaces, this will still take a while. Sorry about that.
Regards,
Ales

@AlesBorovicka Thank you. I plan to simply get the triangles from USD using UsdImagingMeshAdapter use the OptiX or CUDA libraries… Do you feel there is a conflict in linking to optix as an external library from Omniverse.

No I dont think there is a conflict, this is kind of exactly what we are planning to release (with PhysX SDK usage), to showcase how to use eventually directly PhysX SDK for raycasting, while leveraging already existing infrastructure that can for example cook PhysX SDK mesh data from USD. Again its in the process unfortunately, will be available later this year.

2 Likes

I am also interested in querying a USD scene heavily.
From what I gathered, PhysX raycasting runs on the CPU. If so, am I correct to presume that the built-in query that is currently being built won’t run on the GPU, and if I do want that capability I should do the same as usr39947 and link Optix?

Yes, there are no immediate plans to enable scene queries on the GPU for PhysX SDK.