33 if (qobject_cast<
const QPlaneShape *>(node) !=
nullptr) {
35 const QQuaternion rotation = QPhysicsUtils::kMinus90YawRotation * node->rotation();
36 return physx::PxTransform(QPhysicsUtils::toPhysXType(node->position()),
37 QPhysicsUtils::toPhysXType(rotation));
38 }
else if (
auto *hf = qobject_cast<
const QHeightFieldShape *>(node)) {
40 return physx::PxTransform(QPhysicsUtils::toPhysXType(node->position() + hf->hfOffset()),
41 QPhysicsUtils::toPhysXType(node->rotation()));
44 const QQuaternion &rotation = node->rotation();
45 const QVector3D &localPosition = node->position();
46 const QVector3D &scale = node->sceneScale();
47 return physx::PxTransform(QPhysicsUtils::toPhysXType(localPosition * scale),
48 QPhysicsUtils::toPhysXType(rotation));
89 if (!frontendNode || !actor)
96 const auto &collisionShapes = frontendNode->getCollisionShapesList();
97 const auto &physXShapes = shapes;
99 const int len = collisionShapes.size();
100 if (physXShapes.size() != len) {
104 for (
int i = 0; i < len; i++) {
105 auto poseNew = getPhysXLocalTransform(collisionShapes[i]);
106 auto poseOld = physXShapes[i]->getLocalPose();
108 if (!QPhysicsUtils::fuzzyEquals(poseNew, poseOld)) {
150 for (
auto *shape : std::as_const(shapes)) {
151 body->detachShape(*shape);
158 for (
const auto &collisionShape : frontendNode->getCollisionShapesList()) {
159 auto *geom = collisionShape->getPhysXGeometry();
160 if (!geom || !material)
163 auto &s_physx = StaticPhysXObjects::getReference();
167 auto physXShape = s_physx.physics->createShape(*geom, *material,
true);
169 qWarning() <<
"QtQuick3DPhysics: could not create shape, invalid geometry.";
173 if (useTriggerFlag()) {
174 physXShape->setFlag(physx::PxShapeFlag::eSIMULATION_SHAPE,
false);
175 physXShape->setFlag(physx::PxShapeFlag::eTRIGGER_SHAPE,
true);
179 physx::PxFilterData filterData;
180 filterData.word0 = frontendNode->filterGroup();
181 filterData.word1 = frontendNode->filterIgnoreGroups();
182 physXShape->setSimulationFilterData(filterData);
185 shapes.push_back(physXShape);
186 physx::PxTransform localPose = getPhysXLocalTransform(collisionShape);
187 if (!localPose.isSane()) {
188 qWarning() <<
"QtQuick3DPhysics: collision shape position/rotation is not finite, "
189 "using identity local pose instead.";
190 localPose = physx::PxTransform(physx::PxIdentity);
192 physXShape->setLocalPose(localPose);
193 body->attachShape(*physXShape);
void markDirtyShapes() override
void buildShapes(QPhysXWorld *physX)
void rebuildDirtyShapes(QPhysicsWorld *world, QPhysXWorld *physX) override
void init(QPhysicsWorld *world, QPhysXWorld *physX) override
bool debugGeometryCapability() override
void cleanup(QPhysXWorld *physX) override
physx::PxRigidActor * actor
virtual void createActor(QPhysXWorld *physX)
void sync(float deltaTime, QHash< QQuick3DNode *, QMatrix4x4 > &transformCache) override
void updateFilters() override
physx::PxTransform getGlobalPose() override
static QT_BEGIN_NAMESPACE physx::PxTransform getPhysXLocalTransform(const QQuick3DNode *node)