Reputation: 61
I would like to filter my collisions with layers like in Unity, but I really don't understand how to do it. I'm following this tutorial : http://docs.nvidia.com/gameworks/content/gameworkslibrary/physx/guide/Manual/RigidBodyCollision.html#collision-filtering
All I want to do is disable the collisions between the objects that have the layer Cube and Plane...
Graph.cpp :
bool Graph::Init()
{
/*...*/
cubeCollider->SetLayer(Physics::PhysicLayer::Cube);
planeCollider->SetLayer(Physics::PhysicLayer::Plane);
sphereCollider->SetLayer(Physics::PhysicLayer::Sphere);
capsuleCollider->SetLayer(Physics::PhysicLayer::Capsule);
_physX->SetCollisionFiltering(Physics::PhysicLayer::Cube, Physics::PhysicLayer::Plane);
/*...*/
}
And here is how I set the filter shader :
PhysX.cpp :
void PhysX::SetCollisionFiltering(PhysicLayer p_one, PhysicLayer p_two)
{
// I don't really know what to do here...
PxFilterData filterData;
filterData.word0 = p_one;
filterData.word1 = p_two;
// no collision between objects with layer ONE and objects with layer TWO ?
for (unsigned int i = 0; i < _colliders.size(); ++i)
{
if (_colliders[i]->GetLayer() == p_one || _colliders[i]->GetLayer() == p_two)
_colliders[i]->GetShape()->setSimulationFilterData(filterData);
}
}
physx::PxFilterFlags CreateFilterShader(PxFilterObjectAttributes p_attributes0, PxFilterData p_filterData0,
PxFilterObjectAttributes p_attributes1, PxFilterData p_filterData1,
PxPairFlags& p_pairFlags, const void* p_constantBlock, PxU32 constantBlockSize)
{
// Trigger
if (PxFilterObjectIsTrigger(p_attributes0) || PxFilterObjectIsTrigger(p_attributes1))
{
p_pairFlags = PxPairFlag::eDETECT_DISCRETE_CONTACT
| PxPairFlag::eSOLVE_CONTACT
| PxPairFlag::eNOTIFY_TOUCH_FOUND
| PxPairFlag::eNOTIFY_TOUCH_LOST;
}
// Normal Collision
else
{
// Not sure
if ((p_filterData0.word0 & p_filterData1.word1) && (p_filterData1.word0 & p_filterData0.word1))
{
p_pairFlags = PxPairFlag::eDETECT_DISCRETE_CONTACT
| PxPairFlag::eSOLVE_CONTACT
| PxPairFlag::eNOTIFY_CONTACT_POINTS
| PxPairFlag::eNOTIFY_THRESHOLD_FORCE_FOUND
| PxPairFlag::eNOTIFY_THRESHOLD_FORCE_LOST
| PxPairFlag::eNOTIFY_THRESHOLD_FORCE_PERSISTS
| PxPairFlag::eNOTIFY_TOUCH_FOUND
| PxPairFlag::eNOTIFY_TOUCH_LOST
| PxPairFlag::eNOTIFY_TOUCH_PERSISTS;
}
}
return PxFilterFlag::eDEFAULT;
}
With this code, none of my objects collide... I don't really understand what are PxFilter.word0, word1 word2 and word3 by the way...
Thanks in advance !
Upvotes: 2
Views: 878
Reputation: 1061
This a very late answer, just a reference for others.
Based on nvidia documentation you should return eSupress or kill enum.
https://docs.nvidia.com/gameworks/content/gameworkslibrary/physx/apireference/files/structPxFilterFlag.html
:
PxFilterFlags PhysicsWorldFilterShader(
PxFilterObjectAttributes attributes0, PxFilterData filterData0,
PxFilterObjectAttributes attributes1, PxFilterData filterData1,
PxPairFlags& pairFlags, const void* constantBlock, PxU32 constantBlockSize
)
{
// Checking if layers should be ignored
auto const layerMaskA = filterData0.word0;
auto const layerA = filterData0.word1;
auto const layerMaskB = filterData1.word0;
auto const layerB = filterData1.word1;
auto const aCollision = layerMaskA & layerB;
auto const bCollision = layerMaskB & layerA;
if (aCollision == 0 || bCollision == 0)
{
return PxFilterFlag::eSUPPRESS;
}
// all initial and persisting reports for everything, with per-point data
pairFlags = PxPairFlag::eSOLVE_CONTACT | PxPairFlag::eDETECT_DISCRETE_CONTACT | PxPairFlag::eTRIGGER_DEFAULT;
return PxFilterFlag::eDEFAULT;
}
Upvotes: 0