blob: 8094e202bd44220de470a6fc703bff56206abcd5 (
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
|
// Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "expandboundingvolumejob_p.h"
#include <Qt3DRender/private/entity_p.h>
#include <Qt3DRender/private/renderlogging_p.h>
#include <Qt3DRender/private/sphere_p.h>
#include <Qt3DRender/private/job_common_p.h>
#include <Qt3DRender/private/managers_p.h>
#include <Qt3DRender/private/nodemanagers_p.h>
#include <QThread>
QT_BEGIN_NAMESPACE
namespace Qt3DRender {
namespace Render {
namespace {
void expandWorldBoundingVolume(NodeManagers *manager, Entity *node)
{
// Go to the nodes that have the most depth
const auto &childrenHandles = node->childrenHandles();
for (const HEntity &handle : childrenHandles) {
Entity *c = manager->renderNodesManager()->data(handle);
if (c && c->isEnabled())
expandWorldBoundingVolume(manager, c);
}
// Then traverse back from leaf to root
// Initialize parent bounding volume to be equal to that of the first child
if (!childrenHandles.empty()) {
Qt3DRender::Render::Sphere *parentBoundingVolume = node->worldBoundingVolumeWithChildren();
for (const HEntity &handle : childrenHandles) {
Entity *c = manager->renderNodesManager()->data(handle);
if (c && c->isEnabled())
parentBoundingVolume->expandToContain(*c->worldBoundingVolumeWithChildren());
}
}
}
}
ExpandBoundingVolumeJob::ExpandBoundingVolumeJob()
: m_node(nullptr)
, m_manager(nullptr)
{
SET_JOB_RUN_STAT_TYPE(this, JobTypes::ExpandBoundingVolume, 0)
}
void ExpandBoundingVolumeJob::setRoot(Entity *root)
{
m_node = root;
}
void ExpandBoundingVolumeJob::setManagers(NodeManagers *manager)
{
m_manager = manager;
}
void ExpandBoundingVolumeJob::run()
{
// Expand worldBoundingVolumeWithChildren of each node that has children by the
// bounding volumes of the children.
// TODO: Implement this using a parallel_for
qCDebug(Jobs) << "Entering" << Q_FUNC_INFO << QThread::currentThread();
expandWorldBoundingVolume(m_manager, m_node);
qCDebug(Jobs) << "Exiting" << Q_FUNC_INFO << QThread::currentThread();
}
} // namespace Render
} // namespace Qt3DRender
QT_END_NAMESPACE
|