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