summaryrefslogtreecommitdiffstats
path: root/src/quick3d/quick3drender/items
diff options
context:
space:
mode:
authorMike Krus <mike.krus@kdab.com>2020-07-16 13:35:15 +0100
committerMike Krus <mike.krus@kdab.com>2020-07-30 12:02:39 +0100
commiteb728b5501f0ffb61ca4916ff5975c496ab98970 (patch)
tree3c2652354b99e057460455ba94e478410c19b4df /src/quick3d/quick3drender/items
parent3411f202fdfd6e3c69421ae143013920a65704ee (diff)
Add support for synchronous picking
World space and screen space raycasters gain method to do a pick query synchronously, returning the list of hits. Change-Id: I41cc3940b8d97c3619456d76127841907a9170cb Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src/quick3d/quick3drender/items')
-rw-r--r--src/quick3d/quick3drender/items/quick3draycaster.cpp76
-rw-r--r--src/quick3d/quick3drender/items/quick3draycaster_p.h7
-rw-r--r--src/quick3d/quick3drender/items/quick3draycaster_p_p.h7
-rw-r--r--src/quick3d/quick3drender/items/quick3dscreenraycaster.cpp21
-rw-r--r--src/quick3d/quick3drender/items/quick3dscreenraycaster_p.h9
-rw-r--r--src/quick3d/quick3drender/items/quick3dscreenraycaster_p_p.h5
6 files changed, 5 insertions, 120 deletions
diff --git a/src/quick3d/quick3drender/items/quick3draycaster.cpp b/src/quick3d/quick3drender/items/quick3draycaster.cpp
index b8f086983..d0c282a1c 100644
--- a/src/quick3d/quick3drender/items/quick3draycaster.cpp
+++ b/src/quick3d/quick3drender/items/quick3draycaster.cpp
@@ -43,78 +43,12 @@
#include <Qt3DCore/QEntity>
-#include <QQmlEngine>
-#include <QJSValue>
-
QT_BEGIN_NAMESPACE
namespace Qt3DRender {
namespace Render {
namespace Quick {
-void Quick3DRayCasterPrivate::dispatchHits(const QAbstractRayCaster::Hits &hits)
-{
- m_hits = hits;
- updateHitEntites(m_hits, m_scene);
-
- Q_Q(Quick3DRayCaster);
- if (!m_engine)
- m_engine = qmlEngine(q->parent());
-
- m_jsHits = convertHits(m_hits, m_engine);
-
- bool v = q->blockNotifications(true);
- emit q->hitsChanged(m_jsHits);
- q->blockNotifications(v);
-}
-
-QJSValue Quick3DRayCasterPrivate::convertHits(const QAbstractRayCaster::Hits &hits, QQmlEngine *engine)
-{
- auto jsHits = engine->newArray(hits.length());
- for (int i=0; i<hits.size(); i++) {
- QJSValue v = engine->newObject();
- v.setProperty(QLatin1String("type"), hits[i].type());
- v.setProperty(QLatin1String("entity"), engine->newQObject(hits[i].entity()));
- v.setProperty(QLatin1String("distance"), hits[i].distance());
- {
- QJSValue p = engine->newObject();
- p.setProperty(QLatin1String("x"), hits[i].localIntersection().x());
- p.setProperty(QLatin1String("y"), hits[i].localIntersection().y());
- p.setProperty(QLatin1String("z"), hits[i].localIntersection().z());
- v.setProperty(QLatin1String("localIntersection"), p);
- }
- {
- QJSValue p = engine->newObject();
- p.setProperty(QLatin1String("x"), hits[i].worldIntersection().x());
- p.setProperty(QLatin1String("y"), hits[i].worldIntersection().y());
- p.setProperty(QLatin1String("z"), hits[i].worldIntersection().z());
- v.setProperty(QLatin1String("worldIntersection"), p);
- }
-
- switch (hits[i].type()) {
- case Qt3DRender::QRayCasterHit::TriangleHit:
- v.setProperty(QLatin1String("primitiveIndex"), hits[i].primitiveIndex());
- v.setProperty(QLatin1String("vertex1Index"), hits[i].vertex1Index());
- v.setProperty(QLatin1String("vertex2Index"), hits[i].vertex2Index());
- v.setProperty(QLatin1String("vertex3Index"), hits[i].vertex3Index());
- break;
- case Qt3DRender::QRayCasterHit::LineHit:
- v.setProperty(QLatin1String("primitiveIndex"), hits[i].primitiveIndex());
- v.setProperty(QLatin1String("vertex1Index"), hits[i].vertex1Index());
- v.setProperty(QLatin1String("vertex2Index"), hits[i].vertex2Index());
- break;
- case Qt3DRender::QRayCasterHit::PointHit:
- v.setProperty(QLatin1String("primitiveIndex"), hits[i].primitiveIndex());
- break;
- default: break;
- }
-
- jsHits.setProperty(i, v);
- }
-
- return jsHits;
-}
-
void Quick3DRayCasterPrivate::appendLayer(QQmlListProperty<QLayer> *list, QLayer *layer)
{
QAbstractRayCaster *filter = qobject_cast<QAbstractRayCaster *>(list->object);
@@ -134,7 +68,7 @@ int Quick3DRayCasterPrivate::layerCount(QQmlListProperty<QLayer> *list)
{
QAbstractRayCaster *filter = qobject_cast<QAbstractRayCaster *>(list->object);
if (filter)
- return filter->layers().count();
+ return int(filter->layers().size());
return 0;
}
@@ -153,15 +87,9 @@ Quick3DRayCaster::Quick3DRayCaster(QObject *parent)
{
}
-QJSValue Quick3DRayCaster::hits() const
-{
- Q_D(const Quick3DRayCaster);
- return d->m_jsHits;
-}
-
QQmlListProperty<Qt3DRender::QLayer> Qt3DRender::Render::Quick::Quick3DRayCaster::qmlLayers()
{
- return QQmlListProperty<QLayer>(this, 0,
+ return QQmlListProperty<QLayer>(this, nullptr,
&Quick3DRayCasterPrivate::appendLayer,
&Quick3DRayCasterPrivate::layerCount,
&Quick3DRayCasterPrivate::layerAt,
diff --git a/src/quick3d/quick3drender/items/quick3draycaster_p.h b/src/quick3d/quick3drender/items/quick3draycaster_p.h
index 31778dc3b..20a55a7bb 100644
--- a/src/quick3d/quick3drender/items/quick3draycaster_p.h
+++ b/src/quick3d/quick3drender/items/quick3draycaster_p.h
@@ -69,17 +69,12 @@ class Quick3DRayCasterPrivate;
class Q_3DQUICKRENDERSHARED_PRIVATE_EXPORT Quick3DRayCaster : public QRayCaster
{
Q_OBJECT
- Q_PROPERTY(QJSValue hits READ hits NOTIFY hitsChanged)
Q_PROPERTY(QQmlListProperty<Qt3DRender::QLayer> layers READ qmlLayers)
public:
- explicit Quick3DRayCaster(QObject *parent = 0);
+ explicit Quick3DRayCaster(QObject *parent = nullptr);
- QJSValue hits() const;
QQmlListProperty<QLayer> qmlLayers();
-Q_SIGNALS:
- void hitsChanged(const QJSValue &hits);
-
private:
Q_DECLARE_PRIVATE(Quick3DRayCaster)
};
diff --git a/src/quick3d/quick3drender/items/quick3draycaster_p_p.h b/src/quick3d/quick3drender/items/quick3draycaster_p_p.h
index ef875eb43..dec8dcfb6 100644
--- a/src/quick3d/quick3drender/items/quick3draycaster_p_p.h
+++ b/src/quick3d/quick3drender/items/quick3draycaster_p_p.h
@@ -57,8 +57,6 @@
#include <Qt3DQuickRender/private/quick3draycaster_p.h>
#include <Qt3DQuick/private/quick3dnode_p.h>
-#include <QtQml/QJSValue>
-
QT_BEGIN_NAMESPACE
namespace Qt3DRender {
@@ -70,11 +68,6 @@ class Q_3DQUICKRENDERSHARED_PRIVATE_EXPORT Quick3DRayCasterPrivate : public QAbs
public:
explicit Quick3DRayCasterPrivate() : QAbstractRayCasterPrivate() { }
- QJSValue m_jsHits;
- QQmlEngine *m_engine = nullptr;
-
- void dispatchHits(const QAbstractRayCaster::Hits &hits) override;
- static QJSValue convertHits(const QAbstractRayCaster::Hits &hits, QQmlEngine *engine);
static void appendLayer(QQmlListProperty<QLayer> *list, QLayer *bar);
static QLayer *layerAt(QQmlListProperty<QLayer> *list, int index);
static int layerCount(QQmlListProperty<QLayer> *list);
diff --git a/src/quick3d/quick3drender/items/quick3dscreenraycaster.cpp b/src/quick3d/quick3drender/items/quick3dscreenraycaster.cpp
index dd3d1f758..03d6268c3 100644
--- a/src/quick3d/quick3drender/items/quick3dscreenraycaster.cpp
+++ b/src/quick3d/quick3drender/items/quick3dscreenraycaster.cpp
@@ -53,33 +53,14 @@ namespace Qt3DRender {
namespace Render {
namespace Quick {
-void Quick3DScreenRayCasterPrivate::dispatchHits(const QAbstractRayCaster::Hits &hits)
-{
- m_hits = hits;
- updateHitEntites(m_hits, m_scene);
-
- Q_Q(Quick3DScreenRayCaster);
- if (!m_engine)
- m_engine = qmlEngine(q->parent());
-
- m_jsHits = Quick3DRayCasterPrivate::convertHits(m_hits, m_engine);
- emit q->hitsChanged(m_jsHits);
-}
-
Quick3DScreenRayCaster::Quick3DScreenRayCaster(QObject *parent)
: QScreenRayCaster(*new Quick3DScreenRayCasterPrivate(), qobject_cast<Qt3DCore::QNode *>(parent))
{
}
-QJSValue Quick3DScreenRayCaster::hits() const
-{
- Q_D(const Quick3DScreenRayCaster);
- return d->m_jsHits;
-}
-
QQmlListProperty<Qt3DRender::QLayer> Qt3DRender::Render::Quick::Quick3DScreenRayCaster::qmlLayers()
{
- return QQmlListProperty<QLayer>(this, 0,
+ return QQmlListProperty<QLayer>(this, nullptr,
&Quick3DRayCasterPrivate::appendLayer,
&Quick3DRayCasterPrivate::layerCount,
&Quick3DRayCasterPrivate::layerAt,
diff --git a/src/quick3d/quick3drender/items/quick3dscreenraycaster_p.h b/src/quick3d/quick3drender/items/quick3dscreenraycaster_p.h
index 63d3f0428..4f1f19a1c 100644
--- a/src/quick3d/quick3drender/items/quick3dscreenraycaster_p.h
+++ b/src/quick3d/quick3drender/items/quick3dscreenraycaster_p.h
@@ -56,8 +56,6 @@
#include <Qt3DQuickRender/private/qt3dquickrender_global_p.h>
#include <Qt3DQuick/private/quick3dnode_p.h>
-#include <QtQml/QJSValue>
-
QT_BEGIN_NAMESPACE
namespace Qt3DRender {
@@ -69,17 +67,12 @@ class Quick3DScreenRayCasterPrivate;
class Q_3DQUICKRENDERSHARED_PRIVATE_EXPORT Quick3DScreenRayCaster : public QScreenRayCaster
{
Q_OBJECT
- Q_PROPERTY(QJSValue hits READ hits NOTIFY hitsChanged)
Q_PROPERTY(QQmlListProperty<Qt3DRender::QLayer> layers READ qmlLayers)
public:
- explicit Quick3DScreenRayCaster(QObject *parent = 0);
+ explicit Quick3DScreenRayCaster(QObject *parent = nullptr);
- QJSValue hits() const;
QQmlListProperty<QLayer> qmlLayers();
-Q_SIGNALS:
- void hitsChanged(const QJSValue &hits);
-
private:
Q_DECLARE_PRIVATE(Quick3DScreenRayCaster)
};
diff --git a/src/quick3d/quick3drender/items/quick3dscreenraycaster_p_p.h b/src/quick3d/quick3drender/items/quick3dscreenraycaster_p_p.h
index ad5d0b941..e84430a7b 100644
--- a/src/quick3d/quick3drender/items/quick3dscreenraycaster_p_p.h
+++ b/src/quick3d/quick3drender/items/quick3dscreenraycaster_p_p.h
@@ -71,11 +71,6 @@ class Q_3DQUICKRENDERSHARED_PRIVATE_EXPORT Quick3DScreenRayCasterPrivate : publi
public:
explicit Quick3DScreenRayCasterPrivate() : QAbstractRayCasterPrivate() { }
- QJSValue m_jsHits;
- QQmlEngine *m_engine = nullptr;
-
- void dispatchHits(const QAbstractRayCaster::Hits &hits) override;
-
Q_DECLARE_PUBLIC(Quick3DScreenRayCaster)
};