summaryrefslogtreecommitdiffstats
path: root/src/render/picking
diff options
context:
space:
mode:
Diffstat (limited to 'src/render/picking')
-rw-r--r--src/render/picking/objectpicker.cpp13
-rw-r--r--src/render/picking/pickeventfilter.cpp21
-rw-r--r--src/render/picking/pickeventfilter_p.h7
-rw-r--r--src/render/picking/qobjectpicker.cpp44
-rw-r--r--src/render/picking/qpickevent.cpp32
-rw-r--r--src/render/picking/qpickevent_p.h11
-rw-r--r--src/render/picking/qpicktriangleevent.cpp52
-rw-r--r--src/render/picking/qpicktriangleevent.h5
8 files changed, 137 insertions, 48 deletions
diff --git a/src/render/picking/objectpicker.cpp b/src/render/picking/objectpicker.cpp
index 453bd5dc1..13d6d505c 100644
--- a/src/render/picking/objectpicker.cpp
+++ b/src/render/picking/objectpicker.cpp
@@ -44,7 +44,6 @@
#include <Qt3DRender/private/qobjectpicker_p.h>
#include <Qt3DRender/qattribute.h>
#include <Qt3DCore/qpropertyupdatedchange.h>
-#include <Qt3DCore/private/qpropertyupdatedchangebase_p.h>
QT_BEGIN_NAMESPACE
@@ -93,17 +92,11 @@ void ObjectPicker::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e)
{
if (e->type() == Qt3DCore::PropertyUpdated) {
const Qt3DCore::QPropertyUpdatedChangePtr propertyChange = qSharedPointerCast<Qt3DCore::QPropertyUpdatedChange>(e);
- bool notifyPickJob = false;
if (propertyChange->propertyName() == QByteArrayLiteral("hoverEnabled")) {
m_hoverEnabled = propertyChange->value().toBool();
- notifyPickJob = true;
} else if (propertyChange->propertyName() == QByteArrayLiteral("dragEnabled")) {
m_dragEnabled = propertyChange->value().toBool();
- notifyPickJob = true;
- } else if (propertyChange->propertyName() == QByteArrayLiteral("enabled")) {
- notifyPickJob = true;
- // actual value change handled in BackendNode::sceneChangeEvent
}
markDirty(AbstractRenderer::AllDirty);
@@ -134,7 +127,6 @@ void ObjectPicker::onClicked(QPickEventPtr event)
e->setDeliveryFlags(Qt3DCore::QSceneChange::DeliverToAll);
e->setPropertyName("clicked");
e->setValue(QVariant::fromValue(event));
- Qt3DCore::QPropertyUpdatedChangeBasePrivate::get(e.data())->m_isFinal = true;
notifyObservers(e);
}
@@ -144,7 +136,6 @@ void ObjectPicker::onMoved(QPickEventPtr event)
e->setDeliveryFlags(Qt3DCore::QSceneChange::DeliverToAll);
e->setPropertyName("moved");
e->setValue(QVariant::fromValue(event));
- Qt3DCore::QPropertyUpdatedChangeBasePrivate::get(e.data())->m_isFinal = true;
notifyObservers(e);
}
@@ -155,7 +146,6 @@ void ObjectPicker::onPressed(QPickEventPtr event)
e->setPropertyName("pressed");
e->setValue(QVariant::fromValue(event));
m_isPressed = true;
- Qt3DCore::QPropertyUpdatedChangeBasePrivate::get(e.data())->m_isFinal = true;
notifyObservers(e);
}
@@ -166,7 +156,6 @@ void ObjectPicker::onReleased(QPickEventPtr event)
e->setPropertyName("released");
e->setValue(QVariant::fromValue(event));
m_isPressed = false;
- Qt3DCore::QPropertyUpdatedChangeBasePrivate::get(e.data())->m_isFinal = true;
notifyObservers(e);
}
@@ -175,7 +164,6 @@ void ObjectPicker::onEntered()
auto e = Qt3DCore::QPropertyUpdatedChangePtr::create(peerId());
e->setDeliveryFlags(Qt3DCore::QSceneChange::DeliverToAll);
e->setPropertyName("entered");
- Qt3DCore::QPropertyUpdatedChangeBasePrivate::get(e.data())->m_isFinal = true;
notifyObservers(e);
}
@@ -184,7 +172,6 @@ void ObjectPicker::onExited()
auto e = Qt3DCore::QPropertyUpdatedChangePtr::create(peerId());
e->setDeliveryFlags(Qt3DCore::QSceneChange::DeliverToAll);
e->setPropertyName("exited");
- Qt3DCore::QPropertyUpdatedChangeBasePrivate::get(e.data())->m_isFinal = true;
notifyObservers(e);
}
diff --git a/src/render/picking/pickeventfilter.cpp b/src/render/picking/pickeventfilter.cpp
index a1ae52068..19d3b6b6e 100644
--- a/src/render/picking/pickeventfilter.cpp
+++ b/src/render/picking/pickeventfilter.cpp
@@ -61,11 +61,19 @@ PickEventFilter::~PickEventFilter()
Called from a worker thread in the thread pool so be sure to
mutex protect the data.
*/
-QList<QMouseEvent> PickEventFilter::pendingEvents()
+QList<QMouseEvent> PickEventFilter::pendingMouseEvents()
{
QMutexLocker locker(&m_mutex);
- QList<QMouseEvent> pendingEvents(m_pendingEvents);
- m_pendingEvents.clear();
+ QList<QMouseEvent> pendingEvents(m_pendingMouseEvents);
+ m_pendingMouseEvents.clear();
+ return pendingEvents;
+}
+
+QList<QKeyEvent> PickEventFilter::pendingKeyEvents()
+{
+ QMutexLocker locker(&m_mutex);
+ QList<QKeyEvent> pendingEvents(m_pendingKeyEvents);
+ m_pendingKeyEvents.clear();
return pendingEvents;
}
@@ -82,7 +90,12 @@ bool PickEventFilter::eventFilter(QObject *obj, QEvent *e)
case QEvent::MouseMove:
case QEvent::HoverMove: {
QMutexLocker locker(&m_mutex);
- m_pendingEvents.push_back(QMouseEvent(*static_cast<QMouseEvent *>(e)));
+ m_pendingMouseEvents.push_back(QMouseEvent(*static_cast<QMouseEvent *>(e)));
+ } break;
+ case QEvent::KeyPress:
+ case QEvent::KeyRelease: {
+ QMutexLocker locker(&m_mutex);
+ m_pendingKeyEvents.push_back(QKeyEvent(*static_cast<QKeyEvent *>(e)));
}
default:
break;
diff --git a/src/render/picking/pickeventfilter_p.h b/src/render/picking/pickeventfilter_p.h
index df94a3085..fc4b00ddc 100644
--- a/src/render/picking/pickeventfilter_p.h
+++ b/src/render/picking/pickeventfilter_p.h
@@ -53,6 +53,7 @@
#include <QObject>
#include <QMouseEvent>
+#include <QKeyEvent>
#include <QtCore/qmutex.h>
QT_BEGIN_NAMESPACE
@@ -68,13 +69,15 @@ public:
explicit PickEventFilter(QObject *parent = nullptr);
~PickEventFilter();
- QList<QMouseEvent> pendingEvents();
+ QList<QMouseEvent> pendingMouseEvents();
+ QList<QKeyEvent> pendingKeyEvents();
protected:
bool eventFilter(QObject *obj, QEvent *e) Q_DECL_FINAL;
private:
- QList<QMouseEvent> m_pendingEvents;
+ QList<QMouseEvent> m_pendingMouseEvents;
+ QList<QKeyEvent> m_pendingKeyEvents;
QMutex m_mutex;
};
diff --git a/src/render/picking/qobjectpicker.cpp b/src/render/picking/qobjectpicker.cpp
index 1842b7fee..49f608a67 100644
--- a/src/render/picking/qobjectpicker.cpp
+++ b/src/render/picking/qobjectpicker.cpp
@@ -55,14 +55,25 @@ namespace Qt3DRender {
\brief The QObjectPicker class instantiates a component that can
be used to interact with a QEntity by a process known as picking.
+ For every combination of viewport and camera, picking casts a ray through the scene to
+ find entities who's bounding volume intersects the ray. The bounding volume is computed using
+ the values in the attribute buffer specified by the boundingVolumePositionAttribute of the
+ geometry.
+
The signals pressed(), released(), clicked(), moved(), entered(), and exited() are
emitted when the bounding volume defined by the pickAttribute property intersects
with a ray.
+ Most signals carry a QPickEvent instance. If QPickingSettings::pickMode() is set to
+ QPickingSettings::TrianglePicking, the actual type of the pick parameter will be
+ QPickTriangleEvent.
+
Pick queries are performed on mouse press and mouse release.
If drag is enabled, queries also happen on each mouse move while any button is pressed.
If hover is enabled, queries happen on every mouse move even if no button is pressed.
- \sa QPickingSettings
+
+ \sa Qt3DRender::QPickingSettings, Qt3DRender::QGeometry, Qt3DRender::QAttribute,
+ Qt3DRender::QPickEvent, Qt3DRender::QPickTriangleEvent
\note Instances of this component shouldn't be shared, not respecting that
condition will most likely result in undefined behavior.
@@ -76,28 +87,51 @@ namespace Qt3DRender {
* \inqmlmodule Qt3D.Render
* \brief The ObjectPicker class instantiates a component that can
be used to interact with an Entity by a process known as picking.
+
+ For every combination of viewport and camera, picking casts a ray through the scene to
+ find entities who's bounding volume intersects the ray. The bounding volume is computed using
+ the values in the attribute buffer specified by the boundingVolumePositionAttribute of the
+ geometry.
+
+ The signals pressed(), released(), clicked(), moved(), entered(), and exited() are
+ emitted when the bounding volume defined by the pickAttribute property intersects
+ with a ray.
+
+ Most signals carry a PickEvent instance. If PickingSettings.pickMode is set to
+ PickingSettings.TrianglePicking, the actual type of the pick parameter will be
+ PickTriangleEvent.
+
+ Pick queries are performed on mouse press and mouse release.
+ If drag is enabled, queries also happen on each mouse move while any button is pressed.
+ If hover is enabled, queries happen on every mouse move even if no button is pressed.
+
+ \sa PickingSettings, Geometry, Attribute, PickEvent, PickTriangleEvent
+
+ \note Instances of this component shouldn't be shared, not respecting that
+ condition will most likely result in undefined behavior.
+
*/
/*!
- \qmlsignal Qt3D.Render::ObjectPicker::pressed()
+ \qmlsignal Qt3D.Render::ObjectPicker::pressed(PickEvent pick)
This signal is emitted when the bounding volume defined by the pickAttribute property intersects
with a ray on a mouse press.
*/
/*!
- \qmlsignal Qt3D.Render::ObjectPicker::released()
+ \qmlsignal Qt3D.Render::ObjectPicker::released(PickEvent pick)
This signal is emitted when the bounding volume defined by the pickAttribute property intersects
with a ray on a mouse release.
*/
/*!
- \qmlsignal Qt3D.Render::ObjectPicker::clicked()
+ \qmlsignal Qt3D.Render::ObjectPicker::clicked(PickEvent pick)
This signal is emitted when the bounding volume defined by the pickAttribute property intersects
with a ray on a mouse click.
*/
/*!
- \qmlsignal Qt3D.Render::ObjectPicker::moved()
+ \qmlsignal Qt3D.Render::ObjectPicker::moved(PickEvent pick)
This signal is emitted when the bounding volume defined by the pickAttribute property intersects
with a ray on a mouse move with a button pressed.
*/
diff --git a/src/render/picking/qpickevent.cpp b/src/render/picking/qpickevent.cpp
index c7abf639c..148850baf 100644
--- a/src/render/picking/qpickevent.cpp
+++ b/src/render/picking/qpickevent.cpp
@@ -50,6 +50,10 @@ namespace Qt3DRender {
\inmodule Qt3DRender
\brief The QPickEvent class holds information when an object is picked
+
+ This is received as a parameter in most of the QObjectPicker component signals when picking
+ succeeds.
+
\sa QPickingSettings, QPickTriangleEvent, QObjectPicker
\since 5.7
@@ -61,9 +65,10 @@ namespace Qt3DRender {
* \inqmlmodule Qt3D.Render
* \sa ObjectPicker PickingSettings
* \brief PickEvent holds information when an object is picked.
+ * This is received as a parameter in most of the QObjectPicker component signals when picking
+ * succeeds.
*/
-
/*!
\fn Qt3DRender::QPickEvent::QPickEvent()
Constructs a new QPickEvent.
@@ -73,6 +78,11 @@ QPickEvent::QPickEvent()
{
}
+QPickEventPrivate *QPickEventPrivate::get(QPickEvent *object)
+{
+ return object->d_func();
+}
+
/*!
\fn Qt3DRender::QPickEvent::QPickEvent(const QPointF &position, const QVector3D &intersection, const QVector3D &localIntersection, float distance)
Constructs a new QPickEvent with the given parameters: \a position, \a intersection, \a localIntersection and \a distance
@@ -147,11 +157,11 @@ void QPickEvent::setAccepted(bool accepted)
/*!
\qmlproperty bool Qt3D.Render::PickEvent::position
- Specifies the position of the event
+ Specifies the mouse position with respect to the render area (window or quick item)
*/
/*!
\property Qt3DRender::QPickEvent::position
- Specifies the position of the event
+ Specifies the mouse position with respect to the render area (window or quick item)
*/
/*!
* \brief QPickEvent::position
@@ -165,11 +175,11 @@ QPointF QPickEvent::position() const
/*!
\qmlproperty bool Qt3D.Render::PickEvent::distance
- Specifies the distance of the event
+ Specifies the distance of the hit to the camera
*/
/*!
\property Qt3DRender::QPickEvent::distance
- Specifies the distance of the event
+ Specifies the distance of the hit to the camera
*/
/*!
* \brief QPickEvent::distance
@@ -183,15 +193,15 @@ float QPickEvent::distance() const
/*!
\qmlproperty bool Qt3D.Render::PickEvent::worldIntersection
- Specifies the world intersection of the event
+ Specifies the coordinates of the hit in world coordinate system
*/
/*!
\property Qt3DRender::QPickEvent::worldIntersection
- Specifies the world intersection of the event
+ Specifies the coordinates of the hit in world coordinate system
*/
/*!
* \brief QPickEvent::worldIntersection
- * \return world coordinate of the pick point
+ * \return coordinates of the hit in world coordinate system
*/
QVector3D QPickEvent::worldIntersection() const
{
@@ -201,15 +211,15 @@ QVector3D QPickEvent::worldIntersection() const
/*!
\qmlproperty bool Qt3D.Render::PickEvent::localIntersection
- Specifies the world local intersection of the event
+ Specifies the coordinates of the hit in the local coordinate system of the picked entity
*/
/*!
\property Qt3DRender::QPickEvent::localIntersection
- Specifies the local intersection of the event
+ Specifies the coordinates of the hit in the local coordinate system of the picked entity
*/
/*!
* \brief QPickEvent::localIntersection
- * \return local coordinate of pick point
+ * \return coordinates of the hit in the local coordinate system of the picked entity
*/
QVector3D QPickEvent::localIntersection() const
{
diff --git a/src/render/picking/qpickevent_p.h b/src/render/picking/qpickevent_p.h
index 399795619..ced36c9bb 100644
--- a/src/render/picking/qpickevent_p.h
+++ b/src/render/picking/qpickevent_p.h
@@ -48,13 +48,19 @@
// We mean it.
//
+#include <Qt3DCore/qnodeid.h>
+
#include <private/qobject_p.h>
+#include <private/qt3drender_global_p.h>
+
QT_BEGIN_NAMESPACE
namespace Qt3DRender {
-class QPickEventPrivate : public QObjectPrivate
+class QPickEvent;
+
+class QT3DRENDERSHARED_PRIVATE_EXPORT QPickEventPrivate : public QObjectPrivate
{
public:
QPickEventPrivate()
@@ -75,6 +81,9 @@ public:
QPickEvent::Buttons m_button;
int m_buttons;
int m_modifiers;
+ Qt3DCore::QNodeId m_entity;
+
+ static QPickEventPrivate *get(QPickEvent *object);
};
} // Qt3DRender
diff --git a/src/render/picking/qpicktriangleevent.cpp b/src/render/picking/qpicktriangleevent.cpp
index ae96d5d2b..2a4cdfea2 100644
--- a/src/render/picking/qpicktriangleevent.cpp
+++ b/src/render/picking/qpicktriangleevent.cpp
@@ -61,6 +61,7 @@ public:
uint m_vertex1Index;
uint m_vertex2Index;
uint m_vertex3Index;
+ QVector3D m_uvw;
};
/*!
@@ -69,7 +70,15 @@ public:
\brief The QPickTriangleEvent class holds information when a triangle is picked
- \sa QPickEvent
+ When QPickingSettings::pickMode() is set to QPickingSettings::TrianglePicking, the signals
+ on QObjectPicker will carry an instance of QPickTriangleEvent.
+
+ This contains the details of the triangle that was picked.
+
+ \note In the case of indexed rendering, the point indices are relative to the
+ array of coordinates, not the array of indices.
+
+ \sa QPickingSettings, QPickEvent, QObjectPicker, QAttribute
\since 5.7
*/
@@ -78,7 +87,16 @@ public:
* \instantiates Qt3DRender::QPickTriangleEvent
* \inqmlmodule Qt3D.Render
* \brief PickTriangleEvent holds information when a triangle is picked.
- * \sa ObjectPicker
+ *
+ * When QPickingSettings::pickMode() is set to QPickingSettings::TrianglePicking, the signals
+ * on QObjectPicker will carry an instance of QPickTriangleEvent.
+ *
+ * This contains the details of the triangle that was picked.
+ *
+ * \note In case of indexed rendering, the point indices are relative to the
+ * array of indices, not the array of coordinates.
+ *
+ * \sa PickingSettings, PickEvent, ObjectPicker, Attribute
*/
@@ -104,7 +122,8 @@ QPickTriangleEvent::QPickTriangleEvent()
*/
// NOTE: remove in Qt6
QPickTriangleEvent::QPickTriangleEvent(const QPointF &position, const QVector3D &worldIntersection, const QVector3D &localIntersection, float distance,
- uint triangleIndex, uint vertex1Index, uint vertex2Index, uint vertex3Index)
+ uint triangleIndex, uint vertex1Index, uint vertex2Index,
+ uint vertex3Index)
: QPickEvent(*new QPickTriangleEventPrivate())
{
Q_D(QPickTriangleEvent);
@@ -118,7 +137,11 @@ QPickTriangleEvent::QPickTriangleEvent(const QPointF &position, const QVector3D
d->m_vertex3Index = vertex3Index;
}
-QPickTriangleEvent::QPickTriangleEvent(const QPointF &position, const QVector3D &worldIntersection, const QVector3D &localIntersection, float distance, uint triangleIndex, uint vertex1Index, uint vertex2Index, uint vertex3Index, QPickEvent::Buttons button, int buttons, int modifiers)
+QPickTriangleEvent::QPickTriangleEvent(const QPointF &position, const QVector3D &worldIntersection,
+ const QVector3D &localIntersection, float distance,
+ uint triangleIndex, uint vertex1Index, uint vertex2Index,
+ uint vertex3Index, QPickEvent::Buttons button, int buttons,
+ int modifiers, const QVector3D &uvw)
: QPickEvent(*new QPickTriangleEventPrivate())
{
Q_D(QPickTriangleEvent);
@@ -133,6 +156,7 @@ QPickTriangleEvent::QPickTriangleEvent(const QPointF &position, const QVector3D
d->m_button = button;
d->m_buttons = buttons;
d->m_modifiers = modifiers;
+ d->m_uvw = uvw;
}
/*! \internal */
@@ -160,11 +184,11 @@ uint QPickTriangleEvent::triangleIndex() const
/*!
\qmlproperty uint Qt3D.Render::PickTriangleEvent::vertex1Index
- Specifies the vertex 1 index of the event
+ Specifies the index of the first vertex in the triangle
*/
/*!
\property Qt3DRender::QPickTriangleEvent::vertex1Index
- Specifies the vertex 1 index of the event
+ Specifies the index of the first vertex in the triangle
*/
/*!
* \brief QPickTriangleEvent::vertex1Index
@@ -178,11 +202,11 @@ uint QPickTriangleEvent::vertex1Index() const
/*!
\qmlproperty uint Qt3D.Render::PickTriangleEvent::vertex2Index
- Specifies the vertex 2 index of the event
+ Specifies the index of the second vertex in the triangle
*/
/*!
\property Qt3DRender::QPickTriangleEvent::vertex2Index
- Specifies the vertex 2 index of the event
+ Specifies the index of the second vertex in the triangle
*/
/*!
* \brief QPickTriangleEvent::vertex2Index
@@ -196,15 +220,15 @@ uint QPickTriangleEvent::vertex2Index() const
/*!
\qmlproperty uint Qt3D.Render::PickTriangleEvent::vertex3Index
- Specifies the vertex 3 index of the event
+ Specifies the index of the third vertex in the triangle
*/
/*!
\property Qt3DRender::QPickTriangleEvent::vertex3Index
- Specifies the vertex 3 index of the event
+ Specifies the index of the third vertex in the triangle
*/
/*!
* \brief QPickTriangleEvent::vertex3Index
- * \returns index of third point of picked triangle
+ * Returns index of third point of picked triangle
*/
uint QPickTriangleEvent::vertex3Index() const
{
@@ -212,6 +236,12 @@ uint QPickTriangleEvent::vertex3Index() const
return d->m_vertex3Index;
}
+QVector3D QPickTriangleEvent::uvw() const
+{
+ Q_D(const QPickTriangleEvent);
+ return d->m_uvw;
+}
+
} // Qt3DRender
QT_END_NAMESPACE
diff --git a/src/render/picking/qpicktriangleevent.h b/src/render/picking/qpicktriangleevent.h
index 7cafa1aeb..7655a0b94 100644
--- a/src/render/picking/qpicktriangleevent.h
+++ b/src/render/picking/qpicktriangleevent.h
@@ -54,12 +54,14 @@ class QT3DRENDERSHARED_EXPORT QPickTriangleEvent : public QPickEvent
Q_PROPERTY(uint vertex1Index READ vertex1Index CONSTANT)
Q_PROPERTY(uint vertex2Index READ vertex2Index CONSTANT)
Q_PROPERTY(uint vertex3Index READ vertex3Index CONSTANT)
+ Q_PROPERTY(QVector3D uvw READ uvw CONSTANT)
public:
QPickTriangleEvent();
QPickTriangleEvent(const QPointF &position, const QVector3D& worldIntersection, const QVector3D& localIntersection, float distance,
uint triangleIndex, uint vertex1Index, uint vertex2Index, uint vertex3Index);
QPickTriangleEvent(const QPointF &position, const QVector3D& worldIntersection, const QVector3D& localIntersection, float distance,
- uint triangleIndex, uint vertex1Index, uint vertex2Index, uint vertex3Index, Buttons button, int buttons, int modifiers);
+ uint triangleIndex, uint vertex1Index, uint vertex2Index, uint vertex3Index, Buttons button, int buttons, int modifiers,
+ const QVector3D &uvw);
~QPickTriangleEvent();
public:
@@ -67,6 +69,7 @@ public:
uint vertex1Index() const;
uint vertex2Index() const;
uint vertex3Index() const;
+ QVector3D uvw() const;
private:
Q_DECLARE_PRIVATE(QPickTriangleEvent)