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