1// Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB).
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QT3DCORE_CALCBOUNDINGVOLUMEJOB_H
5#define QT3DCORE_CALCBOUNDINGVOLUMEJOB_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 <Qt3DCore/qaspectjob.h>
19#include <Qt3DCore/private/qt3dcore_global_p.h>
20
21#include <QtCore/QSharedPointer>
22#include <QtGui/qvector3d.h>
23
24QT_BEGIN_NAMESPACE
25
26namespace Qt3DCore {
27
28class QCoreAspect;
29class CalculateBoundingVolumeJobPrivate;
30class QEntity;
31class QAttribute;
32class QBoundingVolume;
33class QGeometryView;
34
35struct Q_3DCORE_PRIVATE_EXPORT BoundingVolumeComputeResult {
36 QEntity *entity = nullptr;
37 QBoundingVolume *provider = nullptr;
38 QAttribute *positionAttribute = nullptr;
39 QAttribute *indexAttribute = nullptr;
40 QVector3D m_min;
41 QVector3D m_max;
42 QVector3D m_center;
43 float m_radius = -1.f;
44
45 bool valid() const { return m_radius >= 0.f; }
46};
47
48struct Q_3DCORE_PRIVATE_EXPORT BoundingVolumeComputeData {
49 QEntity *entity = nullptr;
50 QBoundingVolume *provider = nullptr;
51 QAttribute *positionAttribute = nullptr;
52 QAttribute *indexAttribute = nullptr;
53 int vertexCount = 0;
54
55 static BoundingVolumeComputeData fromView(QGeometryView *view);
56
57 bool valid() const { return positionAttribute != nullptr; }
58 BoundingVolumeComputeResult compute() const;
59};
60
61class Q_3DCORE_PRIVATE_EXPORT BoundingVolumeJobProcessor
62{
63public:
64 virtual ~BoundingVolumeJobProcessor() { }
65
66 virtual void process(const BoundingVolumeComputeResult &result, bool computedResult) = 0;
67};
68
69class Q_3DCORE_PRIVATE_EXPORT CalculateBoundingVolumeJob : public Qt3DCore::QAspectJob
70{
71public:
72 explicit CalculateBoundingVolumeJob(QCoreAspect *aspect);
73
74 void setRoot(QEntity *root) { m_root = root; }
75 bool isRequired() override;
76 void run() override;
77 void postFrame(QAspectEngine *aspectEngine) override;
78
79 void addWatcher(QWeakPointer<BoundingVolumeJobProcessor> watcher);
80 void removeWatcher(QWeakPointer<BoundingVolumeJobProcessor> watcher);
81
82private:
83 Q_DECLARE_PRIVATE(CalculateBoundingVolumeJob)
84 QCoreAspect *m_aspect;
85 QEntity *m_root;
86 std::vector<BoundingVolumeComputeResult> m_results;
87 std::vector<QWeakPointer<BoundingVolumeJobProcessor>> m_watchers;
88};
89
90typedef QSharedPointer<CalculateBoundingVolumeJob> CalculateBoundingVolumeJobPtr;
91
92} // namespace Qt3DCore
93
94QT_END_NAMESPACE
95
96#endif // QT3DCORE_CALCBOUNDINGVOLUMEJOB_H
97

source code of qt3d/src/core/jobs/calcboundingvolumejob_p.h