1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef QSSGMESHBVHBUILDER_H
5#define QSSGMESHBVHBUILDER_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#include <QtQuick3DUtils/private/qtquick3dutilsglobal_p.h>
18#include <QtQuick3DUtils/private/qssgmeshbvh_p.h>
19#include <QtQuick3DUtils/private/qssgmesh_p.h>
20
21QT_BEGIN_NAMESPACE
22
23class Q_QUICK3DUTILS_EXPORT QSSGMeshBVHBuilder
24{
25public:
26 QSSGMeshBVHBuilder(const QSSGMesh::Mesh &mesh);
27 QSSGMeshBVHBuilder(const QByteArray &vertexBuffer,
28 int stride,
29 int posOffset,
30 bool hasUV = false,
31 int uvOffset = -1,
32 bool hasIndexBuffer = false,
33 const QByteArray &indexBuffer = QByteArray(),
34 QSSGRenderComponentType indexBufferType = QSSGRenderComponentType::Int32);
35
36 std::unique_ptr<QSSGMeshBVH> buildTree();
37
38private:
39 enum class Axis
40 {
41 None = -1,
42 X = 0,
43 Y = 1,
44 Z = 2
45 };
46 struct Split {
47 Axis axis;
48 float pos;
49 };
50
51 QSSGMeshBVHTriangles calculateTriangleBounds(quint32 indexOffset, quint32 indexCount) const;
52
53 static QSSGMeshBVHNode::Handle splitNode(QSSGMeshBVH &bvh, QSSGMeshBVHNode::Handle node, quint32 offset, quint32 count, quint32 depth = 0);
54 static QSSGBounds3 getBounds(const QSSGMeshBVH &bvh, quint32 offset, quint32 count);
55 static Split getOptimalSplit(const QSSGMeshBVH &bvh, const QSSGBounds3 &nodeBounds, quint32 offset, quint32 count);
56 static Axis getLongestDimension(const QSSGBounds3 &nodeBounds);
57 static float getAverageValue(const QSSGMeshBVH &bvh, quint32 offset, quint32 count, Axis axis);
58 static quint32 partition(QSSGMeshBVH &bvh, quint32 offset, quint32 count, const Split &split);
59
60 QSSGMesh::Mesh m_mesh;
61 QSSGRenderComponentType m_indexBufferComponentType;
62 QByteArray m_indexBufferData;
63 QByteArray m_vertexBufferData;
64 quint32 m_vertexStride;
65 bool m_hasPositionData = false;
66 quint32 m_vertexPosOffset;
67 bool m_hasUVData = false;
68 quint32 m_vertexUVOffset;
69 bool m_hasIndexBuffer = true;
70};
71
72QT_END_NAMESPACE
73
74#endif // QSSGMESHBVHBUILDER_H
75

Provided by KDAB

Privacy Policy
Learn Advanced QML with KDAB
Find out more

source code of qtquick3d/src/utils/qssgmeshbvhbuilder_p.h