| 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(const QQuick3DGeometry *geometrySource) : m_meshGeometry(geometrySource) { } |
| 38 | ~QQuick3DPhysicsMesh() { } |
| 39 | |
| 40 | QList<QVector3D> positions(); |
| 41 | |
| 42 | QPair<QVector3D, QVector3D> bounds() |
| 43 | { |
| 44 | loadSsgMesh(); |
| 45 | if (m_ssgMesh.isValid()) { |
| 46 | auto b = m_ssgMesh.subsets().constFirst().bounds; |
| 47 | return { b.min, b.max }; |
| 48 | } |
| 49 | return {}; |
| 50 | } |
| 51 | |
| 52 | void ref() { ++refCount; } |
| 53 | int deref() { return --refCount; } |
| 54 | |
| 55 | physx::PxConvexMesh *convexMesh(); |
| 56 | physx::PxTriangleMesh *triangleMesh(); |
| 57 | |
| 58 | enum MeshType { Convex, Triangle }; |
| 59 | |
| 60 | private: |
| 61 | void loadSsgMesh(); |
| 62 | physx::PxConvexMesh *convexMeshQmlSource(); |
| 63 | physx::PxConvexMesh *convexMeshGeometrySource(); |
| 64 | physx::PxTriangleMesh *triangleMeshQmlSource(); |
| 65 | physx::PxTriangleMesh *triangleMeshGeometrySource(); |
| 66 | |
| 67 | QString m_meshPath; |
| 68 | const QQuick3DGeometry *m_meshGeometry = nullptr; |
| 69 | QSSGMesh::Mesh m_ssgMesh; |
| 70 | int m_posOffset = 0; |
| 71 | |
| 72 | physx::PxConvexMesh *m_convexMesh = nullptr; |
| 73 | physx::PxTriangleMesh *m_triangleMesh = nullptr; |
| 74 | int refCount = 0; |
| 75 | }; |
| 76 | |
| 77 | class QQuick3DPhysicsMeshManager |
| 78 | { |
| 79 | public: |
| 80 | static QQuick3DPhysicsMesh *getMesh(const QUrl &source, const QObject *contextObject); |
| 81 | static QQuick3DPhysicsMesh *getMesh(QQuick3DGeometry *source); |
| 82 | static void releaseMesh(QQuick3DPhysicsMesh *mesh); |
| 83 | |
| 84 | private: |
| 85 | static QHash<QString, QQuick3DPhysicsMesh *> sourceMeshHash; |
| 86 | static QHash<QQuick3DGeometry *, QQuick3DPhysicsMesh *> geometryMeshHash; |
| 87 | }; |
| 88 | |
| 89 | QT_END_NAMESPACE |
| 90 | |
| 91 | #endif // QPHYSICSMESHUTILS_P_P_H |
| 92 |
