1 | // Copyright (C) 2022 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #ifndef HEIGHTFIELDMESHSHAPE_H |
5 | #define HEIGHTFIELDMESHSHAPE_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 | #include <QtQuick/private/qquickimage_p.h> |
25 | |
26 | namespace physx { |
27 | class PxBoxGeometry; |
28 | class PxTriangleMesh; |
29 | class PxTriangleMeshGeometry; |
30 | class PxHeightFieldGeometry; |
31 | class PxHeightField; |
32 | struct PxHeightFieldSample; |
33 | } |
34 | |
35 | QT_BEGIN_NAMESPACE |
36 | |
37 | class QQuick3DPhysicsHeightField; |
38 | |
39 | class Q_QUICK3DPHYSICS_EXPORT QHeightFieldShape : public QAbstractCollisionShape |
40 | { |
41 | Q_OBJECT |
42 | Q_PROPERTY(QVector3D extents READ extents WRITE setExtents NOTIFY extentsChanged) |
43 | Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged REVISION(6, 5)) |
44 | Q_PROPERTY(QQuickImage *image READ image WRITE setImage NOTIFY imageChanged REVISION(6, 7)) |
45 | QML_NAMED_ELEMENT(HeightFieldShape) |
46 | public: |
47 | QHeightFieldShape(); |
48 | ~QHeightFieldShape(); |
49 | |
50 | physx::PxGeometry *getPhysXGeometry() override; |
51 | |
52 | Q_REVISION(6, 5) const QUrl &source() const; |
53 | Q_REVISION(6, 5) void setSource(const QUrl &newSource); |
54 | |
55 | const QVector3D &hfOffset() const { return m_hfOffset; } |
56 | |
57 | const QVector3D &extents() const; |
58 | void setExtents(const QVector3D &newExtents); |
59 | bool isStaticShape() const override { return true; } |
60 | |
61 | Q_REVISION(6, 7) QQuickImage *image() const; |
62 | Q_REVISION(6, 7) void setImage(QQuickImage *newImage); |
63 | |
64 | signals: |
65 | Q_REVISION(6, 5) void sourceChanged(); |
66 | void extentsChanged(); |
67 | Q_REVISION(6, 7) void imageChanged(); |
68 | |
69 | private slots: |
70 | void imageDestroyed(QObject *image); |
71 | void imageGeometryChanged(); |
72 | |
73 | private: |
74 | void updatePhysXGeometry(); |
75 | void getSamples(); |
76 | void updateExtents(); |
77 | |
78 | QQuick3DPhysicsHeightField *m_heightField = nullptr; |
79 | |
80 | physx::PxHeightFieldGeometry *m_heightFieldGeometry = nullptr; |
81 | QVector3D m_hfOffset; |
82 | QUrl m_heightMapSource; |
83 | bool m_dirtyPhysx = false; |
84 | QVector3D m_extents = { 100, 100, 100 }; |
85 | bool m_extentsSetExplicitly = false; |
86 | QQuickImage *m_image = nullptr; |
87 | }; |
88 | |
89 | QT_END_NAMESPACE |
90 | |
91 | #endif // HEIGHTFIELDMESHSHAPE_H |
92 | |