A Scene in PhysX engine is a container of objects in a hierachical manner.
---title: Scene Hierachy---classDiagramdirection LRclass worldclass scene { Flags Gravity ...}class actor { ActorFlags Name GlobalPose ...}class shape { Flags GeometryType LocalPose ...}class geometry { halfExtents for box ...}class material { friction restitution damping}world "1"*.. "N"scenescene "1"*.. "N"actoractor "1"*.. "N"shapeshape o--geometryshape o--material
There are only position and rotation in GlobalPose and LocalPose, no "scale". Scale only reflects on geometry's actual size.
PhysX Scene Query
Three kinds of scene query:
raycast
sweep
overlap
In general, each SceneQuery traverses a culling structure containing the scene objects, performs a precise test using the GeometryQuery functions, and accumulates the results.
You can customize filtering logic via prefilter and postfilter.
Broad phase traverses the global scene spatial partitioning structure to find the candidates for mid and narrow phases.
midphase traverses the triangle mesh and heightfield internal culling structures, to find a smaller subset of the triangles in a mesh reported by the broad phase.
Narrow phase performs exact intersection tests
Pre-filtering happens before midphase and narrow phase and allows shapes to be efficiently discarded before the potentially expensive exact collision test.
Post-filtering happens after the narrow phase test and can therefore use the results of the test (such as PxRaycastHit.position) to determine whether a hit should be discarded or not.
More on traversal
A scene uses two query structures, one for "static" objects (PxRigidStatic), one for "dynamic" objects (PxRigidBody). Each structure can use different culling algorithms, see PxPruningStructureType.
PxPruningStructureType
Explaination
eNone
Based on grid. Full rebuild when changed.
eDYNAMIC_AABB_TREE
Based on tree. Full rebuild when changed. Only choose this if all static actors in your scene are not modified after initialization.
eSTATIC_AABB_TREE
Based on grid and tree. Incremental rebuild when changed, unless by force. Choose this if frequently add/remove geometry, at the cost of higher memory
More on prefilter and postfilter
To make prefilter works, there are 3 steps.
first attach data (PxFilterData) for on shape. It has four 32bit words to hold custom data, e.g., use word0 as layer of this shape.
second define callback function for prefilter. See PxQueryFilterCallback. The logic is totally depend on yourself, just return PxQueryHitType to tell if this shape can pass.