I have few actors with custom, non convex geometry (mesh) created using PxRigidActorExt::createExclusiveShape and a lot of actors with PxSphereGeometry geometry. Now I want to check if these spheres are colliding or are inside my custom geometries. I have created PxSimulationEventCallback with onContact method, but it only gives me info about collisions.

How can I get info if my spheres are inside my custom geometry?

Edit: It doesn't have to work in "real-time", it can be much slower.

  • 1
    \$\begingroup\$ Detecting whether something is inside a non-convex mesh is a surprisingly expensive task, so many physics engines don't provide a method for it. Are you able to decompose the mesh into convex pieces, or use a voxel/octree/BSP/SDF approximation instead? These give you much more efficient inside/outside/distance-to-point checks. \$\endgroup\$
    – DMGregory
    Apr 27, 2022 at 12:23
  • \$\begingroup\$ @DMGregory Thank you for the answer! Probably I'm able to decompose the mesh, but it wouldn't be a trivial task too. Can you tell me more info about voxel/octree/BSP/SDF approximation and how it can help me? I'm not very familiar with calculations like that. \$\endgroup\$
    – Raffallo
    Apr 27, 2022 at 13:24
  • \$\begingroup\$ Search for each of those terms separately and you'll find lots of existing resources documenting them. A voxel representation discretizes the shape into a grid of cells that are either occupied or empty, do you can do an inside/overlap test just by doing a lookup into that grid. A sparse octree lets you do this at a variable level of detail, so parts of your mesh with complicated borders get denser voxels and big interior/exterior reagions get sparser. BSP is a Binary Space Partition, and SDF is a signed distance field (eg. voxels storing distance inside/outside rather than a boolean). \$\endgroup\$
    – DMGregory
    Apr 27, 2022 at 14:07
  • \$\begingroup\$ @DMGregory I figured I could use gravity simulation to make the points outside the mesh fall and the points inside bouncing back inside. Unfortunately, it does not work a bit as I wanted, because the points penetrate the walls, even if I set double sided geometry when creating with: PxTriangleMeshGeometry geom(pMesh, PxMeshScale(), PxMeshGeometryFlag::eDOUBLE_SIDED); \$\endgroup\$
    – Raffallo
    Apr 28, 2022 at 7:59

1 Answer 1


I was able to achieve what I wanted.

To check if the sphere is inside my triangle mesh, I've used raycasting from the center point into (0.0f, 1.0f, 0.0f) direction (which can be random). The point is inside if the hit count is > 0 and is odd.

Finding if a point is inside of a mesh (Point-in-polyhedron)


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .