1 | // Copyright (C) 2021 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #ifndef ABSTRACTPHYSICSNODE_H |
5 | #define ABSTRACTPHYSICSNODE_H |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists purely as an |
12 | // implementation detail. This header file may change from version to |
13 | // version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | // |
17 | |
18 | #include <QtQuick3DPhysics/qtquick3dphysicsglobal.h> |
19 | #include <QtQuick3D/private/qquick3dnode_p.h> |
20 | #include <QtQml/QQmlEngine> |
21 | #include <QtQml/QQmlListProperty> |
22 | #include <QtQuick3DPhysics/private/qabstractcollisionshape_p.h> |
23 | |
24 | namespace physx { |
25 | class PxTransform; |
26 | class PxShape; |
27 | } |
28 | |
29 | QT_BEGIN_NAMESPACE |
30 | |
31 | class QAbstractPhysXNode; |
32 | |
33 | class Q_QUICK3DPHYSICS_EXPORT QAbstractPhysicsNode : public QQuick3DNode |
34 | { |
35 | Q_OBJECT |
36 | Q_PROPERTY( |
37 | QQmlListProperty<QAbstractCollisionShape> collisionShapes READ collisionShapes CONSTANT) |
38 | Q_PROPERTY(bool sendContactReports READ sendContactReports WRITE setSendContactReports NOTIFY |
39 | sendContactReportsChanged) |
40 | Q_PROPERTY(bool receiveContactReports READ receiveContactReports WRITE setReceiveContactReports |
41 | NOTIFY receiveContactReportsChanged) |
42 | Q_PROPERTY(bool sendTriggerReports READ sendTriggerReports WRITE setSendTriggerReports NOTIFY |
43 | sendTriggerReportsChanged REVISION(6, 5)) |
44 | Q_PROPERTY(bool receiveTriggerReports READ receiveTriggerReports WRITE setReceiveTriggerReports |
45 | NOTIFY receiveTriggerReportsChanged REVISION(6, 5)) |
46 | |
47 | QML_NAMED_ELEMENT(PhysicsNode) |
48 | QML_UNCREATABLE("abstract interface" ) |
49 | public: |
50 | QAbstractPhysicsNode(); |
51 | ~QAbstractPhysicsNode() override; |
52 | |
53 | QQmlListProperty<QAbstractCollisionShape> collisionShapes(); |
54 | const QVector<QAbstractCollisionShape *> &getCollisionShapesList() const; |
55 | |
56 | void updateFromPhysicsTransform(const physx::PxTransform &transform); |
57 | |
58 | void registerContact(QAbstractPhysicsNode *body, const QVector<QVector3D> &positions, |
59 | const QVector<QVector3D> &impulses, const QVector<QVector3D> &normals); |
60 | |
61 | bool sendContactReports() const; |
62 | void setSendContactReports(bool sendContactReports); |
63 | |
64 | bool receiveContactReports() const; |
65 | void setReceiveContactReports(bool receiveContactReports); |
66 | |
67 | Q_REVISION(6, 5) bool sendTriggerReports() const; |
68 | Q_REVISION(6, 5) void setSendTriggerReports(bool sendTriggerReports); |
69 | |
70 | Q_REVISION(6, 5) bool receiveTriggerReports() const; |
71 | Q_REVISION(6, 5) void setReceiveTriggerReports(bool receiveTriggerReports); |
72 | |
73 | bool hasStaticShapes() const { return m_hasStaticShapes; } |
74 | |
75 | virtual QAbstractPhysXNode *createPhysXBackend() = 0; |
76 | |
77 | private Q_SLOTS: |
78 | void onShapeDestroyed(QObject *object); |
79 | void onShapeNeedsRebuild(QObject *object); |
80 | |
81 | Q_SIGNALS: |
82 | void bodyContact(QAbstractPhysicsNode *body, const QVector<QVector3D> &positions, |
83 | const QVector<QVector3D> &impulses, const QVector<QVector3D> &normals); |
84 | void sendContactReportsChanged(float sendContactReports); |
85 | void receiveContactReportsChanged(float receiveContactReports); |
86 | Q_REVISION(6, 5) void sendTriggerReportsChanged(float sendTriggerReports); |
87 | Q_REVISION(6, 5) void receiveTriggerReportsChanged(float receiveTriggerReports); |
88 | Q_REVISION(6, 5) void enteredTriggerBody(QAbstractPhysicsNode *body); |
89 | Q_REVISION(6, 5) void exitedTriggerBody(QAbstractPhysicsNode *body); |
90 | |
91 | private: |
92 | static void qmlAppendShape(QQmlListProperty<QAbstractCollisionShape> *list, |
93 | QAbstractCollisionShape *shape); |
94 | static QAbstractCollisionShape *qmlShapeAt(QQmlListProperty<QAbstractCollisionShape> *list, |
95 | qsizetype index); |
96 | static qsizetype qmlShapeCount(QQmlListProperty<QAbstractCollisionShape> *list); |
97 | static void qmlClearShapes(QQmlListProperty<QAbstractCollisionShape> *list); |
98 | |
99 | QVector<QAbstractCollisionShape *> m_collisionShapes; |
100 | bool m_shapesDirty = false; |
101 | bool m_sendContactReports = false; |
102 | bool m_receiveContactReports = false; |
103 | bool m_sendTriggerReports = false; |
104 | bool m_receiveTriggerReports = false; |
105 | bool m_hasStaticShapes = false; |
106 | |
107 | friend class QAbstractPhysXNode; |
108 | friend class QPhysicsWorld; // for register/deregister TODO: cleaner mechanism |
109 | friend class SimulationEventCallback; |
110 | QAbstractPhysXNode *m_backendObject = nullptr; |
111 | }; |
112 | |
113 | QT_END_NAMESPACE |
114 | |
115 | #endif // ABSTRACTPHYSICSNODE_H |
116 | |