1// Copyright (C) 2016 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 "qpickingsettings.h"
5#include "qpickingsettings_p.h"
6
7QT_BEGIN_NAMESPACE
8
9namespace Qt3DRender {
10
11/*!
12 \class Qt3DRender::QPickingSettings
13 \brief The QPickingSettings class specifies how entity picking is handled.
14 \since 5.7
15 \inmodule Qt3DRender
16 \inherits Qt3DCore::QNode
17
18 The picking settings determine how the entity picking is handled. For more details about
19 entity picking, see QObjectPicker and QRayCaster component documentation.
20
21 When using QObjectPicker components, picking is triggered by mouse events.
22
23 When using QRayCaster or QScreenRayCaster components, picking can be explicitly triggered by
24 the application.
25
26 In both cases, a ray will be cast through the scene to find geometry intersecting the ray.
27
28 \sa QObjectPicker, QPickEvent, QPickTriangleEvent, QRayCaster, QScreenRayCaster
29 */
30
31/*!
32 \qmltype PickingSettings
33 \brief The PickingSettings class specifies how entity picking is handled.
34 \since 5.7
35 \inqmlmodule Qt3D.Render
36 \instantiates Qt3DRender::QPickingSettings
37
38 The picking settings determine how the entity picking is handled. For more details about
39 entity picking, see Qt3D.Render::ObjectPicker or Qt3D.Render::RayCaster component documentation.
40
41 When using ObjectPicker components, picking is triggered by mouse events.
42
43 When using RayCaster or ScreenRayCaster components, picking can be explicitly triggered by
44 the application.
45
46 In both cases, a ray will be cast through the scene to find geometry intersecting the ray.
47
48 \sa ObjectPicker, RayCaster, ScreenRayCaster
49 */
50
51QPickingSettingsPrivate::QPickingSettingsPrivate()
52 : Qt3DCore::QNodePrivate()
53 , m_pickMethod(QPickingSettings::BoundingVolumePicking)
54 , m_pickResultMode(QPickingSettings::NearestPick)
55 , m_faceOrientationPickingMode(QPickingSettings::FrontFace)
56 , m_worldSpaceTolerance(.1f)
57{
58}
59
60QPickingSettings::QPickingSettings(Qt3DCore::QNode *parent)
61 : Qt3DCore::QNode(*new QPickingSettingsPrivate, parent)
62{
63 // Block all notifications for this class as it should have been a QObject
64 blockNotifications(block: true);
65}
66
67/*! \internal */
68QPickingSettings::~QPickingSettings()
69{
70}
71
72/*! \internal */
73QPickingSettings::QPickingSettings(QPickingSettingsPrivate &dd, Qt3DCore::QNode *parent)
74 : Qt3DCore::QNode(dd, parent)
75{
76}
77
78QPickingSettings::PickMethod QPickingSettings::pickMethod() const
79{
80 Q_D(const QPickingSettings);
81 return d->m_pickMethod;
82}
83
84QPickingSettings::PickResultMode QPickingSettings::pickResultMode() const
85{
86 Q_D(const QPickingSettings);
87 return d->m_pickResultMode;
88}
89
90QPickingSettings::FaceOrientationPickingMode QPickingSettings::faceOrientationPickingMode() const
91{
92 Q_D(const QPickingSettings);
93 return d->m_faceOrientationPickingMode;
94}
95
96/*!
97 * \return the line and point precision worldSpaceTolerance
98 */
99float QPickingSettings::worldSpaceTolerance() const
100{
101 Q_D(const QPickingSettings);
102 return d->m_worldSpaceTolerance;
103}
104
105/*!
106 * \enum Qt3DRender::QPickingSettings::PickMethod
107 *
108 * Specifies the picking method.
109 *
110 * \value BoundingVolumePicking An entity is considered picked if the picking ray intersects
111 * the bounding volume of the entity (default).
112 * \value TrianglePicking An entity is considered picked if the picking ray intersects with
113 * any triangle of the entity's mesh component.
114 * \value LinePicking An entity is considered picked if the picking ray intersects with
115 * any edge of the entity's mesh component.
116 * \value PointPicking An entity is considered picked if the picking ray intersects with
117 * any point of the entity's mesh component.
118 * \value PrimitivePicking An entity is considered picked if the picking ray intersects with
119 * any point, edge or triangle of the entity's mesh component.
120 */
121
122/*!
123 \qmlproperty enumeration PickingSettings::pickMethod
124
125 Holds the current pick method.
126
127 \list
128 \li PickingSettings.BoundingVolumePicking
129 \li PickingSettings.TrianglePicking
130 \li PickingSettings.LinePicking
131 \li PickingSettings.PointPicking
132 \li PickingSettings.PrimitivePicking: picks either points, lines or triangles
133 \endlist
134
135 \sa Qt3DRender::QPickingSettings::PickMethod
136*/
137/*!
138 \property QPickingSettings::pickMethod
139
140 Holds the current pick method.
141
142 By default, for performance reasons, ray casting will use bounding volume picking.
143 This may however lead to unexpected results if a small object is englobed
144 in the bounding sphere of a large object behind it.
145
146 Triangle picking will produce exact results but is computationally more expensive.
147*/
148void QPickingSettings::setPickMethod(QPickingSettings::PickMethod pickMethod)
149{
150 Q_D(QPickingSettings);
151 if (d->m_pickMethod == pickMethod)
152 return;
153
154 d->m_pickMethod = pickMethod;
155 emit pickMethodChanged(pickMethod);
156}
157
158/*!
159 * \enum Qt3DRender::QPickingSettings::PickResultMode
160 *
161 * Specifies what is included into the picking results.
162 *
163 * \value NearestPick Only the nearest entity to picking ray origin intersected by the picking ray
164 * is picked (default).
165 * \value AllPicks All entities that intersect the picking ray are picked.
166 * \value NearestPriorityPick Selects the entity whose object picker has the highest
167 * value. If several object pickers have the same priority, the closest one on
168 * the ray is selected.
169 *
170 * \sa Qt3DRender::QPickEvent
171 */
172
173/*!
174 \qmlproperty enumeration PickingSettings::pickResultMode
175
176 Holds the current pick results mode.
177
178 \list
179 \li PickingSettings.NearestPick
180 \li PickingSettings.AllPicks
181 \li PickingSettings.NearestPriorityPick
182 \endlist
183
184 \sa Qt3DRender::QPickingSettings::PickResultMode
185*/
186/*!
187 \property QPickingSettings::pickResultMode
188
189 Holds the current pick results mode.
190
191 By default, pick results will only be produced for the entity closest to the camera.
192
193 When setting the pick method to AllPicks, events will be triggered for all the
194 entities with a QObjectPicker along the ray.
195
196 When setting the pick method to NearestPriorityPick, events will be
197 triggered for the nearest highest priority picker. This can be used when a
198 given element should always be selected even if others are in front of it.
199
200 If a QObjectPicker is assigned to an entity with multiple children, an event will
201 be triggered for each child entity that intersects the ray.
202*/
203void QPickingSettings::setPickResultMode(QPickingSettings::PickResultMode pickResultMode)
204{
205 Q_D(QPickingSettings);
206 if (d->m_pickResultMode == pickResultMode)
207 return;
208
209 d->m_pickResultMode = pickResultMode;
210 emit pickResultModeChanged(pickResult: pickResultMode);
211}
212
213/*!
214 \enum Qt3DRender::QPickingSettings::FaceOrientationPickingMode
215
216 Specifies how face orientation affects triangle picking
217
218 \value FrontFace Only front-facing triangles will be picked (default).
219 \value BackFace Only back-facing triangles will be picked.
220 \value FrontAndBackFace Both front- and back-facing triangles will be picked.
221*/
222
223/*!
224 \qmlproperty enumeration PickingSettings::faceOrientationPickingMode
225
226 Specifies how face orientation affects triangle picking
227
228 \list
229 \li PickingSettings.FrontFace Only front-facing triangles will be picked (default).
230 \li PickingSettings.BackFace Only back-facing triangles will be picked.
231 \li PickingSettings.FrontAndBackFace Both front- and back-facing triangles will be picked.
232 \endlist
233*/
234/*!
235 \property QPickingSettings::faceOrientationPickingMode
236
237 Specifies how face orientation affects triangle picking
238*/
239void QPickingSettings::setFaceOrientationPickingMode(QPickingSettings::FaceOrientationPickingMode faceOrientationPickingMode)
240{
241 Q_D(QPickingSettings);
242 if (d->m_faceOrientationPickingMode == faceOrientationPickingMode)
243 return;
244
245 d->m_faceOrientationPickingMode = faceOrientationPickingMode;
246 emit faceOrientationPickingModeChanged(faceOrientationPickingMode);
247}
248
249/*!
250 \qmlproperty qreal PickingSettings::worldSpaceTolerance
251
252 Holds the threshold, in model space coordinates, used to evaluate line and point picking.
253*/
254/*!
255 \property QPickingSettings::worldSpaceTolerance
256
257 Holds the threshold, in model space coordinates, used to evaluate line and point picking.
258*/
259/*!
260 * Sets the threshold used for line and point picking to \a worldSpaceTolerance.
261 */
262void QPickingSettings::setWorldSpaceTolerance(float worldSpaceTolerance)
263{
264 Q_D(QPickingSettings);
265 if (qFuzzyCompare(p1: worldSpaceTolerance, p2: d->m_worldSpaceTolerance))
266 return;
267
268 d->m_worldSpaceTolerance = worldSpaceTolerance;
269 emit worldSpaceToleranceChanged(worldSpaceTolerance);
270}
271
272} // namespace Qt3Drender
273
274QT_END_NAMESPACE
275
276#include "moc_qpickingsettings.cpp"
277

source code of qt3d/src/render/frontend/qpickingsettings.cpp