# Detect if actors are inside another actor with custom shape

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.

• 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. Apr 27, 2022 at 12:23
• @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. Apr 27, 2022 at 13:24
• 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). Apr 27, 2022 at 14:07
• @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); Apr 28, 2022 at 7:59