1 | // Copyright (C) 2022 The Qt Company Ltd. |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #ifndef QPHYSICSMESHUTILS_P_P_H |
5 | #define QPHYSICSMESHUTILS_P_P_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 <QtGui/QVector3D> |
20 | #include <QtQuick3DUtils/private/qssgmesh_p.h> |
21 | |
22 | namespace physx { |
23 | class PxBoxGeometry; |
24 | class PxConvexMesh; |
25 | class PxConvexMeshGeometry; |
26 | class PxTriangleMesh; |
27 | } |
28 | |
29 | QT_BEGIN_NAMESPACE |
30 | |
31 | class QQuick3DGeometry; |
32 | |
33 | class QQuick3DPhysicsMesh |
34 | { |
35 | public: |
36 | QQuick3DPhysicsMesh(const QString &qmlSource) : m_meshPath(qmlSource) { } |
37 | ~QQuick3DPhysicsMesh() { } |
38 | |
39 | QList<QVector3D> positions(); |
40 | |
41 | QPair<QVector3D, QVector3D> bounds() |
42 | { |
43 | loadSsgMesh(); |
44 | if (m_ssgMesh.isValid()) { |
45 | auto b = m_ssgMesh.subsets().constFirst().bounds; |
46 | return { b.min, b.max }; |
47 | } |
48 | return {}; |
49 | } |
50 | |
51 | void ref() { ++refCount; } |
52 | int deref() { return --refCount; } |
53 | |
54 | physx::PxConvexMesh *convexMesh(); |
55 | physx::PxTriangleMesh *triangleMesh(); |
56 | |
57 | enum MeshType { Convex, Triangle }; |
58 | |
59 | private: |
60 | void loadSsgMesh(); |
61 | |
62 | QString m_meshPath; |
63 | QSSGMesh::Mesh m_ssgMesh; |
64 | int m_posOffset = 0; |
65 | |
66 | physx::PxConvexMesh *m_convexMesh = nullptr; |
67 | physx::PxTriangleMesh *m_triangleMesh = nullptr; |
68 | int refCount = 0; |
69 | }; |
70 | |
71 | class QQuick3DPhysicsMeshManager |
72 | { |
73 | public: |
74 | static QQuick3DPhysicsMesh *getMesh(const QUrl &source, const QObject *contextObject); |
75 | static void releaseMesh(QQuick3DPhysicsMesh *mesh); |
76 | |
77 | private: |
78 | static QHash<QString, QQuick3DPhysicsMesh *> meshHash; |
79 | }; |
80 | |
81 | QT_END_NAMESPACE |
82 | |
83 | #endif // QPHYSICSMESHUTILS_P_P_H |
84 |