blob: a6016ea8190fbea2bb373d7d2d27e47ff02b76d7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#ifndef QPHYSICSMESHUTILS_P_P_H
#define QPHYSICSMESHUTILS_P_P_H
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists purely as an
// implementation detail. This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//
#include <QtQuick3DPhysics/qtquick3dphysicsglobal.h>
#include <QtGui/QVector3D>
#include <QtQuick3DUtils/private/qssgmesh_p.h>
namespace physx {
class PxBoxGeometry;
class PxConvexMesh;
class PxConvexMeshGeometry;
class PxTriangleMesh;
}
QT_BEGIN_NAMESPACE
class QQuick3DGeometry;
class QQuick3DPhysicsMesh
{
public:
QQuick3DPhysicsMesh(const QString &qmlSource) : m_meshPath(qmlSource) { }
QQuick3DPhysicsMesh(const QQuick3DGeometry *geometrySource) : m_meshGeometry(geometrySource) { }
~QQuick3DPhysicsMesh() { }
QList<QVector3D> positions();
QPair<QVector3D, QVector3D> bounds()
{
loadSsgMesh();
if (m_ssgMesh.isValid()) {
auto b = m_ssgMesh.subsets().constFirst().bounds;
return { b.min, b.max };
}
return {};
}
void ref() { ++refCount; }
int deref() { return --refCount; }
physx::PxConvexMesh *convexMesh();
physx::PxTriangleMesh *triangleMesh();
enum MeshType { Convex, Triangle };
private:
void loadSsgMesh();
physx::PxConvexMesh *convexMeshQmlSource();
physx::PxConvexMesh *convexMeshGeometrySource();
physx::PxTriangleMesh *triangleMeshQmlSource();
physx::PxTriangleMesh *triangleMeshGeometrySource();
QString m_meshPath;
const QQuick3DGeometry *m_meshGeometry = nullptr;
QSSGMesh::Mesh m_ssgMesh;
int m_posOffset = 0;
physx::PxConvexMesh *m_convexMesh = nullptr;
physx::PxTriangleMesh *m_triangleMesh = nullptr;
int refCount = 0;
};
class QQuick3DPhysicsMeshManager
{
public:
static QQuick3DPhysicsMesh *getMesh(const QUrl &source, QObject *contextObject);
static QQuick3DPhysicsMesh *getMesh(QQuick3DGeometry *source);
static void releaseMesh(QQuick3DPhysicsMesh *mesh);
private:
static QHash<QString, QQuick3DPhysicsMesh *> sourceMeshHash;
static QHash<QQuick3DGeometry *, QQuick3DPhysicsMesh *> geometryMeshHash;
};
QT_END_NAMESPACE
#endif // QPHYSICSMESHUTILS_P_P_H
|