NVIDIAGameWorks/PhysX

A collision is detected in onContact() before the shape collides.

MoonHJ98 opened this issue · 1 comments

화면 캡처 2021-12-11 090954

I'm trying the collision detection example in SampleSubmarine and I'm having a problem.

As shown in the picture, when Plane and Sphere collide, the break is made at int a = 10 of the onContact function, but the break is applied here even though there has not been a collision yet.

The size of the shape and the size of the drawn sphere are the same, but I do not know why it was before the collision.

If you don't know, I'll attach the code as well.

this is for filtershader

 PxFilterFlags SampleSubmarineFilterShader(
     PxFilterObjectAttributes attributes0, PxFilterData filterData0,
     PxFilterObjectAttributes attributes1, PxFilterData filterData1,
     PxPairFlags& pairFlags, const void* constantBlock, PxU32 constantBlockSize)
 {
     // let triggers through
     if (PxFilterObjectIsTrigger(attributes0) || PxFilterObjectIsTrigger(attributes1))
     {
	     pairFlags = PxPairFlag::eTRIGGER_DEFAULT;
	     return PxFilterFlag::eDEFAULT;
     }
     // generate contacts for all that were not filtered above
     pairFlags = PxPairFlag::eCONTACT_DEFAULT;

     // trigger the contact callback for pairs (A,B) where 
     // the filtermask of A contains the ID of B and vice versa.
     if ((filterData0.word0 & filterData1.word1) && (filterData1.word0 & filterData0.word1))
	     pairFlags |= PxPairFlag::eNOTIFY_TOUCH_FOUND;

     return PxFilterFlag::eDEFAULT;
 }

this is for PxSimulationEventCallback

 class ContactCallBack : public PxSimulationEventCallback
 {
     // PxSimulationEventCallback을(를) 통해 상속됨
     virtual void onConstraintBreak(PxConstraintInfo * constraints, PxU32 count) override;
     virtual void onWake(PxActor ** actors, PxU32 count) override;
     virtual void onSleep(PxActor ** actors, PxU32 count) override;
     virtual void onContact(const PxContactPairHeader & pairHeader, const PxContactPair * pairs, PxU32 nbPairs) override;
     virtual void onTrigger(PxTriggerPair * pairs, PxU32 count) override;
     virtual void onAdvance(const PxRigidBody * const * bodyBuffer, const PxTransform * poseBuffer, const PxU32 count) override;
 };

this is for plane

 HRESULT PhysXManager::CreateSimulation()
 {
     material = physics->createMaterial(0.5f, 0.5f, 0.1f);
     auto groundPlane = PxCreatePlane(*physics, PxPlane(0, 1, 0, 1), *material);
     SetupFiltering(groundPlane, FilterGroup::eHEIGHTFIELD, FilterGroup::eSUBMARINE);
     scene->addActor(*groundPlane);


     return S_OK;
 }

this is for sphere

 HRESULT ColliderRenderer::CreateBuffer(PxGeometryType::Enum _geoType)
 {
     switch (_geoType)
     {
     case physx::PxGeometryType::eSPHERE:
	     GeometricPrimitive::CreateSphere(vertices, indices, 10, 8, false); // 3rd parameter is diameter
	     break;
          ....
     }
      .....
  }

this is for shape

 PxShape* Collider::AddCollider()
 {
     ColliderDesc desc;
     desc.scale = Vector3(5.f, 5.f, 5.f);
     desc.radius = 5.f;
     desc.halfHeight = 10.f;

     return PhysXManager::GetInstance()->AddCollider(geoType, desc);
 }


 PxShape* PhysXManager::AddCollider(PxGeometryType::Enum _type, ColliderDesc _desc)
 {
     PxShape* shape = nullptr;

     switch (_type)
     {
     case physx::PxGeometryType::eSPHERE:
	     shape = physics->createShape(PxSphereGeometry(PxReal(_desc.radius)), *material, true);
	     break;
          ...
     }
         return shape;
  }

Spheres and spheres, as well as collisions with spheres and planes, break before shapes collide.
Does anyone know about this?

Contacts are generated from the moment that the separation distance between shapes is smaller than the sum of their contactOffsets, so you will get contacts reported even before the solver applies any forces to resolve interpenetrations.

If your sample is using default SI scalings as mentioned in the doc below, contact offset is 0.02 per shape, so the first contact is generated when the collision shapes are 2 * 0.02 = 0.04 distance units apart.

This is a good summary of the contact and rest offset shape properties: https://gameworksdocs.nvidia.com/PhysX/4.1/documentation/physxguide/Manual/AdvancedCollisionDetection.html