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