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
25namespace physx {
26class PxBoxGeometry;
27class PxTriangleMesh;
28class PxTriangleMeshGeometry;
29class PxHeightFieldGeometry;
30class PxHeightField;
31struct PxHeightFieldSample;
32}
33
34QT_BEGIN_NAMESPACE
35
36class QQuick3DPhysicsHeightField;
37
38class Q_QUICK3DPHYSICS_EXPORT QHeightFieldShape : public QAbstractCollisionShape
39{
40 Q_OBJECT
41 Q_PROPERTY(QVector3D extents READ extents WRITE setExtents NOTIFY extentsChanged)
42 Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged REVISION(6, 5))
43 QML_NAMED_ELEMENT(HeightFieldShape)
44public:
45 QHeightFieldShape();
46 ~QHeightFieldShape();
47
48 physx::PxGeometry *getPhysXGeometry() override;
49
50 Q_REVISION(6, 5) const QUrl &source() const;
51 Q_REVISION(6, 5) void setSource(const QUrl &newSource);
52
53 const QVector3D &hfOffset() const { return m_hfOffset; }
54
55 const QVector3D &extents() const;
56 void setExtents(const QVector3D &newExtents);
57 bool isStaticShape() const override { return true; }
58
59signals:
60 Q_REVISION(6, 5) void sourceChanged();
61 void extentsChanged();
62
63private:
64 void updatePhysXGeometry();
65 void getSamples();
66 void updateExtents();
67
68 QQuick3DPhysicsHeightField *m_heightField = nullptr;
69
70 physx::PxHeightFieldGeometry *m_heightFieldGeometry = nullptr;
71 QVector3D m_hfOffset;
72 QUrl m_heightMapSource;
73 bool m_dirtyPhysx = false;
74 QVector3D m_extents = { 100, 100, 100 };
75 bool m_extentsSetExplicitly = false;
76};
77
78QT_END_NAMESPACE
79
80#endif // HEIGHTFIELDMESHSHAPE_H
81

source code of qtquick3dphysics/src/quick3dphysics/qheightfieldshape_p.h