32 void onTrigger(physx::PxTriggerPair *pairs, physx::PxU32 count)
override
34 QMutexLocker locker(&world->m_removedPhysicsNodesMutex);
36 for (physx::PxU32 i = 0; i < count; i++) {
39 & (physx::PxTriggerPairFlag::eREMOVED_SHAPE_TRIGGER
40 | physx::PxTriggerPairFlag::eREMOVED_SHAPE_OTHER))
43 QTriggerBody *triggerNode =
44 static_cast<QTriggerBody *>(pairs[i].triggerActor->userData);
46 QAbstractPhysicsNode *otherNode =
47 static_cast<QAbstractPhysicsNode *>(pairs[i].otherActor->userData);
49 if (!triggerNode || !otherNode) {
50 qWarning() <<
"QtQuick3DPhysics internal error: null pointer in trigger collision.";
54 if (world->isNodeRemoved(triggerNode) || world->isNodeRemoved(otherNode))
57 if (pairs->status == physx::PxPairFlag::eNOTIFY_TOUCH_FOUND) {
58 if (otherNode->sendTriggerReports()) {
59 triggerNode->registerCollision(otherNode);
61 if (otherNode->receiveTriggerReports()) {
62 emit otherNode->enteredTriggerBody(triggerNode);
64 }
else if (pairs->status == physx::PxPairFlag::eNOTIFY_TOUCH_LOST) {
65 if (otherNode->sendTriggerReports()) {
66 triggerNode->deregisterCollision(otherNode);
68 if (otherNode->receiveTriggerReports()) {
69 emit otherNode->exitedTriggerBody(triggerNode);
79 void onContact(
const physx::PxContactPairHeader &pairHeader,
const physx::PxContactPair *pairs,
80 physx::PxU32 nbPairs)
override
82 QMutexLocker locker(&world->m_removedPhysicsNodesMutex);
83 constexpr physx::PxU32 bufferSize = 64;
84 physx::PxContactPairPoint contacts[bufferSize];
86 for (physx::PxU32 i = 0; i < nbPairs; i++) {
87 const physx::PxContactPair &contactPair = pairs[i];
89 if (contactPair.events & physx::PxPairFlag::eNOTIFY_TOUCH_FOUND) {
90 QAbstractPhysicsNode *trigger =
91 static_cast<QAbstractPhysicsNode *>(pairHeader.actors[0]->userData);
92 QAbstractPhysicsNode *other =
93 static_cast<QAbstractPhysicsNode *>(pairHeader.actors[1]->userData);
95 if (!trigger || !other || world->isNodeRemoved(trigger)
96 || world->isNodeRemoved(other) || !trigger->m_backendObject
97 || !other->m_backendObject)
100 const bool triggerReceive =
101 trigger->receiveContactReports() && other->sendContactReports();
102 const bool otherReceive =
103 other->receiveContactReports() && trigger->sendContactReports();
105 if (!triggerReceive && !otherReceive)
108 physx::PxU32 nbContacts = pairs[i].extractContacts(contacts, bufferSize);
110 QList<QVector3D> positions;
111 QList<QVector3D> impulses;
112 QList<QVector3D> normals;
114 positions.reserve(nbContacts);
115 impulses.reserve(nbContacts);
116 normals.reserve(nbContacts);
118 for (physx::PxU32 j = 0; j < nbContacts; j++) {
119 physx::PxVec3 position = contacts[j].position;
120 physx::PxVec3 impulse = contacts[j].impulse;
121 physx::PxVec3 normal = contacts[j].normal;
123 positions.push_back(QPhysicsUtils::toQtType(position));
124 impulses.push_back(QPhysicsUtils::toQtType(impulse));
125 normals.push_back(QPhysicsUtils::toQtType(normal));
128 QList<QVector3D> normalsInverted;
129 normalsInverted.reserve(normals.size());
130 for (
const QVector3D &v : normals) {
131 normalsInverted.push_back(QVector3D(-v.x(), -v.y(), -v.z()));
135 world->registerContact(other, trigger, positions, impulses, normals);
137 world->registerContact(trigger, other, positions, impulses, normalsInverted);