| 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 | #include "qpickingproxy.h" |
| 5 | #include "qpickingproxy_p.h" |
| 6 | |
| 7 | #include <private/qcomponent_p.h> |
| 8 | |
| 9 | QT_BEGIN_NAMESPACE |
| 10 | |
| 11 | |
| 12 | namespace Qt3DRender { |
| 13 | |
| 14 | using namespace Qt3DCore; |
| 15 | |
| 16 | QPickingProxyPrivate::QPickingProxyPrivate() |
| 17 | : Qt3DCore::QBoundingVolumePrivate() |
| 18 | { |
| 19 | m_primaryProvider = false; |
| 20 | } |
| 21 | |
| 22 | QPickingProxyPrivate::~QPickingProxyPrivate() |
| 23 | { |
| 24 | } |
| 25 | |
| 26 | void QPickingProxyPrivate::setView(QGeometryView *view) |
| 27 | { |
| 28 | Q_Q(QPickingProxy); |
| 29 | if (m_view == view) |
| 30 | return; |
| 31 | |
| 32 | if (m_view) |
| 33 | m_view->disconnect(receiver: q); |
| 34 | |
| 35 | QBoundingVolumePrivate::setView(view); |
| 36 | |
| 37 | // Ensures proper bookkeeping |
| 38 | if (m_view) { |
| 39 | QObject::connect(sender: view, signal: &QGeometryView::instanceCountChanged, context: q, slot: [this]() { update(); }); |
| 40 | QObject::connect(sender: view, signal: &QGeometryView::vertexCountChanged, context: q, slot: [this]() { update(); }); |
| 41 | QObject::connect(sender: view, signal: &QGeometryView::indexOffsetChanged, context: q, slot: [this]() { update(); }); |
| 42 | QObject::connect(sender: view, signal: &QGeometryView::firstInstanceChanged, context: q, slot: [this]() { update(); }); |
| 43 | QObject::connect(sender: view, signal: &QGeometryView::firstVertexChanged, context: q, slot: [this]() { update(); }); |
| 44 | QObject::connect(sender: view, signal: &QGeometryView::indexBufferByteOffsetChanged, context: q, slot: [this]() { update(); }); |
| 45 | QObject::connect(sender: view, signal: &QGeometryView::restartIndexValueChanged, context: q, slot: [this]() { update(); }); |
| 46 | QObject::connect(sender: view, signal: &QGeometryView::verticesPerPatchChanged, context: q, slot: [this]() { update(); }); |
| 47 | QObject::connect(sender: view, signal: &QGeometryView::primitiveRestartEnabledChanged, context: q, slot: [this]() { update(); }); |
| 48 | QObject::connect(sender: view, signal: &QGeometryView::geometryChanged, context: q, slot: [this]() { update(); }); |
| 49 | QObject::connect(sender: view, signal: &QGeometryView::primitiveTypeChanged, context: q, slot: [this]() { update(); }); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | /*! |
| 54 | \qmltype PickingProxy |
| 55 | \nativetype Qt3DRender::QPickingProxy |
| 56 | \inqmlmodule Qt3D.Render |
| 57 | \inherits Component3D |
| 58 | \since 2.16 |
| 59 | \brief Can be used to provide an alternate GeometryView used only for picking. |
| 60 | |
| 61 | Picking can be an expensive operation, especially if the mesh has a lot of vertices. |
| 62 | PickProxy can be used to provide an alternative geometry, usually with fewer primitives, |
| 63 | which will be used for picking, while the GeometryRenderer instance will be used |
| 64 | for rendering. |
| 65 | |
| 66 | \note Do not use a PickingProxy if the application requires picking coordinates |
| 67 | to match the rendered mesh. |
| 68 | |
| 69 | \note The picking algorithm uses a bounding volume hierarchy to optimize out |
| 70 | entities who's bounding volume does not intersect the picking ray. For that hierarchy, |
| 71 | the bounding volume of the renderered entity is used (or one explicitly set using a |
| 72 | BoundingVolume component) will be used rather than the one of the proxy. |
| 73 | */ |
| 74 | |
| 75 | /*! |
| 76 | \class Qt3DRender::QPickingProxy |
| 77 | \inmodule Qt3DRender |
| 78 | \since 6.0 |
| 79 | \brief Can be used to provide an alternate QGeometryView used only for picking. |
| 80 | |
| 81 | Picking can be an expensive operation, especially if the mesh has a lot of vertices. |
| 82 | QPickProxy can be used to provide an alternative geometry, usually with fewer primitives, |
| 83 | which will be used for picking, while the GeometryRenderer instance will be used |
| 84 | for rendering. |
| 85 | |
| 86 | \note Do not use a QPickingProxy if the application requires picking coordinates |
| 87 | to match the rendered mesh. |
| 88 | |
| 89 | \note The picking algorithm uses a bounding volume hierarchy to optimize out |
| 90 | entities who's bounding volume does not intersect the picking ray. For that hierarchy, |
| 91 | the bounding volume of the renderered entity is used (or one explicitly set using a |
| 92 | QBoundingVolume component) will be used rather than the one of the proxy. |
| 93 | */ |
| 94 | |
| 95 | |
| 96 | /*! |
| 97 | Constructs a new QPickingProxy with \a parent. |
| 98 | */ |
| 99 | QPickingProxy::QPickingProxy(QNode *parent) |
| 100 | : Qt3DCore::QBoundingVolume(*new QPickingProxyPrivate(), parent) |
| 101 | { |
| 102 | } |
| 103 | |
| 104 | /*! |
| 105 | \internal |
| 106 | */ |
| 107 | QPickingProxy::~QPickingProxy() |
| 108 | { |
| 109 | } |
| 110 | |
| 111 | /*! |
| 112 | \internal |
| 113 | */ |
| 114 | QPickingProxy::QPickingProxy(QPickingProxyPrivate &dd, QNode *parent) |
| 115 | : Qt3DCore::QBoundingVolume(dd, parent) |
| 116 | { |
| 117 | } |
| 118 | |
| 119 | } // namespace Qt3DRender |
| 120 | |
| 121 | QT_END_NAMESPACE |
| 122 | |
| 123 | #include "moc_qpickingproxy.cpp" |
| 124 | |