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
22namespace physx {
23class PxBoxGeometry;
24class PxConvexMesh;
25class PxConvexMeshGeometry;
26class PxTriangleMesh;
27}
28
29QT_BEGIN_NAMESPACE
30
31class QQuick3DGeometry;
32
33class QQuick3DPhysicsMesh
34{
35public:
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
59private:
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
71class QQuick3DPhysicsMeshManager
72{
73public:
74 static QQuick3DPhysicsMesh *getMesh(const QUrl &source, const QObject *contextObject);
75 static void releaseMesh(QQuick3DPhysicsMesh *mesh);
76
77private:
78 static QHash<QString, QQuick3DPhysicsMesh *> meshHash;
79};
80
81QT_END_NAMESPACE
82
83#endif // QPHYSICSMESHUTILS_P_P_H
84

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