| 1 | // Copyright (C) 2023 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef MESHSHAPE_H |
| 5 | #define MESHSHAPE_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 <QtQuick3DPhysics/private/qabstractcollisionshape_p.h> |
| 20 | #include <QtCore/QObject> |
| 21 | #include <QtGui/QVector3D> |
| 22 | #include <QtQml/QQmlEngine> |
| 23 | #include <QtQuick3D/QQuick3DGeometry> |
| 24 | |
| 25 | namespace physx { |
| 26 | class PxBoxGeometry; |
| 27 | class PxConvexMesh; |
| 28 | class PxConvexMeshGeometry; |
| 29 | class PxTriangleMesh; |
| 30 | class PxTriangleMeshGeometry; |
| 31 | } |
| 32 | |
| 33 | QT_BEGIN_NAMESPACE |
| 34 | class QQuick3DPhysicsMesh; |
| 35 | |
| 36 | class Q_QUICK3DPHYSICS_EXPORT QMeshShape : public QAbstractCollisionShape |
| 37 | { |
| 38 | Q_OBJECT |
| 39 | Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged REVISION(6, 5)) |
| 40 | Q_PROPERTY(QQuick3DGeometry *geometry READ geometry WRITE setGeometry NOTIFY geometryChanged |
| 41 | REVISION(6, 7)) |
| 42 | QML_NAMED_ELEMENT(MeshShape) |
| 43 | QML_UNCREATABLE("abstract interface" ) |
| 44 | |
| 45 | public: |
| 46 | ~QMeshShape(); |
| 47 | |
| 48 | enum class MeshType { TRIANGLE, CONVEX }; |
| 49 | virtual MeshType shapeType() const = 0; |
| 50 | |
| 51 | physx::PxGeometry *getPhysXGeometry() override; |
| 52 | |
| 53 | Q_REVISION(6, 5) const QUrl &source() const; |
| 54 | Q_REVISION(6, 5) void setSource(const QUrl &newSource); |
| 55 | Q_REVISION(6, 7) QQuick3DGeometry *geometry() const; |
| 56 | Q_REVISION(6, 7) void setGeometry(QQuick3DGeometry *newGeometry); |
| 57 | |
| 58 | signals: |
| 59 | Q_REVISION(6, 5) void sourceChanged(); |
| 60 | Q_REVISION(6, 7) void geometryChanged(); |
| 61 | |
| 62 | private slots: |
| 63 | void geometryDestroyed(QObject *geometry); |
| 64 | void geometryContentChanged(); |
| 65 | |
| 66 | private: |
| 67 | void updatePhysXGeometry(); |
| 68 | |
| 69 | bool m_dirtyPhysx = false; |
| 70 | physx::PxConvexMeshGeometry *m_convexGeometry = nullptr; |
| 71 | physx::PxTriangleMeshGeometry *m_triangleGeometry = nullptr; |
| 72 | QUrl m_meshSource; |
| 73 | QQuick3DPhysicsMesh *m_mesh = nullptr; |
| 74 | QQuick3DGeometry *m_geometry = nullptr; |
| 75 | }; |
| 76 | |
| 77 | QT_END_NAMESPACE |
| 78 | |
| 79 | #endif // MESHSHAPE_H |
| 80 | |