1 | // Copyright (C) 2017 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 | #include "quick3dlevelofdetailloader_p_p.h" |
5 | #include <Qt3DRender/qlevelofdetailboundingsphere.h> |
6 | #include <Qt3DRender/qcamera.h> |
7 | #include <Qt3DQuick/private/quick3dentityloader_p.h> |
8 | |
9 | QT_BEGIN_NAMESPACE |
10 | |
11 | namespace Qt3DExtras { |
12 | namespace Extras { |
13 | namespace Quick { |
14 | |
15 | Quick3DLevelOfDetailLoaderPrivate::() |
16 | : QEntityPrivate() |
17 | , m_loader(new Qt3DCore::Quick::Quick3DEntityLoader) |
18 | , m_lod(new Qt3DRender::QLevelOfDetail) |
19 | { |
20 | } |
21 | |
22 | Quick3DLevelOfDetailLoader::(QNode *parent) |
23 | : QEntity(*new Quick3DLevelOfDetailLoaderPrivate, parent) |
24 | { |
25 | Q_D(Quick3DLevelOfDetailLoader); |
26 | d->m_loader->setParent(this); |
27 | d->m_loader->addComponent(comp: d->m_lod); |
28 | |
29 | connect(sender: d->m_lod, signal: &Qt3DRender::QLevelOfDetail::cameraChanged, |
30 | context: this, slot: &Quick3DLevelOfDetailLoader::cameraChanged); |
31 | connect(sender: d->m_lod, signal: &Qt3DRender::QLevelOfDetail::currentIndexChanged, |
32 | context: this, slot: &Quick3DLevelOfDetailLoader::currentIndexChanged); |
33 | connect(sender: d->m_lod, signal: &Qt3DRender::QLevelOfDetail::thresholdTypeChanged, |
34 | context: this, slot: &Quick3DLevelOfDetailLoader::thresholdTypeChanged); |
35 | connect(sender: d->m_lod, signal: &Qt3DRender::QLevelOfDetail::thresholdsChanged, |
36 | context: this, slot: &Quick3DLevelOfDetailLoader::thresholdsChanged); |
37 | connect(sender: d->m_lod, signal: &Qt3DRender::QLevelOfDetail::volumeOverrideChanged, |
38 | context: this, slot: &Quick3DLevelOfDetailLoader::volumeOverrideChanged); |
39 | connect(sender: d->m_loader, signal: &Qt3DCore::Quick::Quick3DEntityLoader::entityChanged, |
40 | context: this, slot: &Quick3DLevelOfDetailLoader::entityChanged); |
41 | connect(sender: d->m_loader, signal: &Qt3DCore::Quick::Quick3DEntityLoader::sourceChanged, |
42 | context: this, slot: &Quick3DLevelOfDetailLoader::sourceChanged); |
43 | |
44 | connect(sender: this, signal: &Quick3DLevelOfDetailLoader::enabledChanged, |
45 | context: d->m_lod, slot: &Qt3DRender::QLevelOfDetail::setEnabled); |
46 | |
47 | auto applyCurrentSource = [this] { |
48 | Q_D(Quick3DLevelOfDetailLoader); |
49 | const auto index = currentIndex(); |
50 | if (index >= 0 && index < d->m_sources.size()) |
51 | d->m_loader->setSource(d->m_sources.at(i: index).toUrl()); |
52 | }; |
53 | |
54 | connect(sender: this, signal: &Quick3DLevelOfDetailLoader::sourcesChanged, |
55 | context: this, slot&: applyCurrentSource); |
56 | connect(sender: this, signal: &Quick3DLevelOfDetailLoader::currentIndexChanged, |
57 | context: this, slot&: applyCurrentSource); |
58 | } |
59 | |
60 | QVariantList Quick3DLevelOfDetailLoader::() const |
61 | { |
62 | Q_D(const Quick3DLevelOfDetailLoader); |
63 | return d->m_sources; |
64 | } |
65 | |
66 | void Quick3DLevelOfDetailLoader::(const QVariantList &sources) |
67 | { |
68 | Q_D(Quick3DLevelOfDetailLoader); |
69 | if (d->m_sources != sources) { |
70 | d->m_sources = sources; |
71 | emit sourcesChanged(); |
72 | } |
73 | } |
74 | |
75 | Qt3DRender::QCamera *Quick3DLevelOfDetailLoader::() const |
76 | { |
77 | Q_D(const Quick3DLevelOfDetailLoader); |
78 | return d->m_lod->camera(); |
79 | } |
80 | |
81 | void Quick3DLevelOfDetailLoader::(Qt3DRender::QCamera *camera) |
82 | { |
83 | Q_D(Quick3DLevelOfDetailLoader); |
84 | d->m_lod->setCamera(camera); |
85 | } |
86 | |
87 | int Quick3DLevelOfDetailLoader::() const |
88 | { |
89 | Q_D(const Quick3DLevelOfDetailLoader); |
90 | return d->m_lod->currentIndex(); |
91 | } |
92 | |
93 | void Quick3DLevelOfDetailLoader::(int currentIndex) |
94 | { |
95 | Q_D(Quick3DLevelOfDetailLoader); |
96 | d->m_lod->setCurrentIndex(currentIndex); |
97 | } |
98 | |
99 | Qt3DRender::QLevelOfDetail::ThresholdType Quick3DLevelOfDetailLoader::() const |
100 | { |
101 | Q_D(const Quick3DLevelOfDetailLoader); |
102 | return d->m_lod->thresholdType(); |
103 | } |
104 | |
105 | void Quick3DLevelOfDetailLoader::(Qt3DRender::QLevelOfDetail::ThresholdType thresholdType) |
106 | { |
107 | Q_D(Quick3DLevelOfDetailLoader); |
108 | d->m_lod->setThresholdType(thresholdType); |
109 | } |
110 | |
111 | QList<qreal> Quick3DLevelOfDetailLoader::() const |
112 | { |
113 | Q_D(const Quick3DLevelOfDetailLoader); |
114 | return d->m_lod->thresholds(); |
115 | } |
116 | |
117 | void Quick3DLevelOfDetailLoader::(const QList<qreal> &thresholds) |
118 | { |
119 | Q_D(Quick3DLevelOfDetailLoader); |
120 | d->m_lod->setThresholds(thresholds); |
121 | } |
122 | |
123 | Qt3DRender::QLevelOfDetailBoundingSphere Quick3DLevelOfDetailLoader::(const QVector3D ¢er, float radius) |
124 | { |
125 | return Qt3DRender::QLevelOfDetailBoundingSphere(center, radius); |
126 | } |
127 | |
128 | Qt3DRender::QLevelOfDetailBoundingSphere Quick3DLevelOfDetailLoader::() const |
129 | { |
130 | Q_D(const Quick3DLevelOfDetailLoader); |
131 | return d->m_lod->volumeOverride(); |
132 | } |
133 | |
134 | void Quick3DLevelOfDetailLoader::(const Qt3DRender::QLevelOfDetailBoundingSphere &volumeOverride) |
135 | { |
136 | Q_D(Quick3DLevelOfDetailLoader); |
137 | d->m_lod->setVolumeOverride(volumeOverride); |
138 | } |
139 | |
140 | QObject *Quick3DLevelOfDetailLoader::() const |
141 | { |
142 | Q_D(const Quick3DLevelOfDetailLoader); |
143 | return d->m_loader->entity(); |
144 | } |
145 | |
146 | QUrl Quick3DLevelOfDetailLoader::() const |
147 | { |
148 | Q_D(const Quick3DLevelOfDetailLoader); |
149 | return d->m_loader->source(); |
150 | } |
151 | |
152 | } // namespace Quick |
153 | } // namespace Extras |
154 | } // namespace Qt3DExtras |
155 | |
156 | QT_END_NAMESPACE |
157 | |
158 | #include "moc_quick3dlevelofdetailloader_p.cpp" |
159 | |
160 | |
161 | |