31 void onTrigger(physx::PxTriggerPair *pairs, physx::PxU32 count)
override
33 QMutexLocker locker(&world->m_removedPhysicsNodesMutex);
35 for (physx::PxU32 i = 0; i < count; i++) {
38 & (physx::PxTriggerPairFlag::eREMOVED_SHAPE_TRIGGER
39 | physx::PxTriggerPairFlag::eREMOVED_SHAPE_OTHER))
42 QTriggerBody *triggerNode =
43 static_cast<QTriggerBody *>(pairs[i].triggerActor->userData);
45 QAbstractPhysicsNode *otherNode =
46 static_cast<QAbstractPhysicsNode *>(pairs[i].otherActor->userData);
48 if (!triggerNode || !otherNode) {
49 qWarning() <<
"QtQuick3DPhysics internal error: null pointer in trigger collision.";
53 if (world->isNodeRemoved(triggerNode) || world->isNodeRemoved(otherNode))
56 if (pairs->status == physx::PxPairFlag::eNOTIFY_TOUCH_FOUND) {
57 if (otherNode->sendTriggerReports()) {
58 triggerNode->registerCollision(otherNode);
60 if (otherNode->receiveTriggerReports()) {
61 emit otherNode->enteredTriggerBody(triggerNode);
63 }
else if (pairs->status == physx::PxPairFlag::eNOTIFY_TOUCH_LOST) {
64 if (otherNode->sendTriggerReports()) {
65 triggerNode->deregisterCollision(otherNode);
67 if (otherNode->receiveTriggerReports()) {
68 emit otherNode->exitedTriggerBody(triggerNode);
78 void onContact(
const physx::PxContactPairHeader &pairHeader,
const physx::PxContactPair *pairs,
79 physx::PxU32 nbPairs)
override
81 QMutexLocker locker(&world->m_removedPhysicsNodesMutex);
82 constexpr physx::PxU32 bufferSize = 64;
83 physx::PxContactPairPoint contacts[bufferSize];
85 for (physx::PxU32 i = 0; i < nbPairs; i++) {
86 const physx::PxContactPair &contactPair = pairs[i];
88 if (contactPair.events & physx::PxPairFlag::eNOTIFY_TOUCH_FOUND) {
89 QAbstractPhysicsNode *trigger =
90 static_cast<QAbstractPhysicsNode *>(pairHeader.actors[0]->userData);
91 QAbstractPhysicsNode *other =
92 static_cast<QAbstractPhysicsNode *>(pairHeader.actors[1]->userData);
94 if (!trigger || !other || world->isNodeRemoved(trigger)
95 || world->isNodeRemoved(other) || !trigger->m_backendObject
96 || !other->m_backendObject)
99 const bool triggerReceive =
100 trigger->receiveContactReports() && other->sendContactReports();
101 const bool otherReceive =
102 other->receiveContactReports() && trigger->sendContactReports();
104 if (!triggerReceive && !otherReceive)
107 physx::PxU32 nbContacts = pairs[i].extractContacts(contacts, bufferSize);
109 QList<QVector3D> positions;
110 QList<QVector3D> impulses;
111 QList<QVector3D> normals;
113 positions.reserve(nbContacts);
114 impulses.reserve(nbContacts);
115 normals.reserve(nbContacts);
117 for (physx::PxU32 j = 0; j < nbContacts; j++) {
118 physx::PxVec3 position = contacts[j].position;
119 physx::PxVec3 impulse = contacts[j].impulse;
120 physx::PxVec3 normal = contacts[j].normal;
122 positions.push_back(QPhysicsUtils::toQtType(position));
123 impulses.push_back(QPhysicsUtils::toQtType(impulse));
124 normals.push_back(QPhysicsUtils::toQtType(normal));
127 QList<QVector3D> normalsInverted;
128 normalsInverted.reserve(normals.size());
129 for (
const QVector3D &v : normals) {
130 normalsInverted.push_back(QVector3D(-v.x(), -v.y(), -v.z()));
134 world->registerContact(other, trigger, positions, impulses, normals);
136 world->registerContact(trigger, other, positions, impulses, normalsInverted);