summaryrefslogtreecommitdiffstats
path: root/src/quick3d/quick3drender/items
diff options
context:
space:
mode:
authorMike Krus <mike.krus@kdab.com>2018-01-30 22:13:14 +0000
committerSean Harmer <sean.harmer@kdab.com>2018-02-05 09:12:47 +0000
commitc8a48a9a28889598cb2a06fc8d5deb9b803509ca (patch)
tree686fb006c636a0a7ea5fe1ba78457aa02fd6f8b6 /src/quick3d/quick3drender/items
parentba8e3dc09a772faaeb08aa652e59c49cf175040e (diff)
Add support for layers to control ray casting
RayCaster and ScreenRayCaster can have a number of layers which are used to control how entities with the matching layers are handled for ray casting. Similar rules apply as for LayerFilter in the frame graph. Change-Id: I9f666563a686ac99d7f178da33a539ba9edef51b Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/quick3d/quick3drender/items')
-rw-r--r--src/quick3d/quick3drender/items/quick3draycaster.cpp42
-rw-r--r--src/quick3d/quick3drender/items/quick3draycaster_p.h2
-rw-r--r--src/quick3d/quick3drender/items/quick3draycaster_p_p.h4
-rw-r--r--src/quick3d/quick3drender/items/quick3dscreenraycaster.cpp9
-rw-r--r--src/quick3d/quick3drender/items/quick3dscreenraycaster_p.h2
5 files changed, 59 insertions, 0 deletions
diff --git a/src/quick3d/quick3drender/items/quick3draycaster.cpp b/src/quick3d/quick3drender/items/quick3draycaster.cpp
index fa05b67d6..55c08a806 100644
--- a/src/quick3d/quick3drender/items/quick3draycaster.cpp
+++ b/src/quick3d/quick3drender/items/quick3draycaster.cpp
@@ -115,6 +115,39 @@ QJSValue Quick3DRayCasterPrivate::convertHits(const QAbstractRayCaster::Hits &hi
return jsHits;
}
+void Quick3DRayCasterPrivate::appendLayer(QQmlListProperty<QLayer> *list, QLayer *layer)
+{
+ QAbstractRayCaster *filter = qobject_cast<QAbstractRayCaster *>(list->object);
+ if (filter)
+ filter->addLayer(layer);
+}
+
+QLayer *Quick3DRayCasterPrivate::layerAt(QQmlListProperty<QLayer> *list, int index)
+{
+ QAbstractRayCaster *filter = qobject_cast<QAbstractRayCaster *>(list->object);
+ if (filter)
+ return filter->layers().at(index);
+ return nullptr;
+}
+
+int Quick3DRayCasterPrivate::layerCount(QQmlListProperty<QLayer> *list)
+{
+ QAbstractRayCaster *filter = qobject_cast<QAbstractRayCaster *>(list->object);
+ if (filter)
+ return filter->layers().count();
+ return 0;
+}
+
+void Quick3DRayCasterPrivate::clearLayers(QQmlListProperty<QLayer> *list)
+{
+ QAbstractRayCaster *filter = qobject_cast<QAbstractRayCaster *>(list->object);
+ if (filter) {
+ const auto layers = filter->layers();
+ for (QLayer *layer : layers)
+ filter->removeLayer(layer);
+ }
+}
+
Quick3DRayCaster::Quick3DRayCaster(QObject *parent)
: QRayCaster(*new Quick3DRayCasterPrivate(), qobject_cast<Qt3DCore::QNode *>(parent))
{
@@ -126,6 +159,15 @@ QJSValue Quick3DRayCaster::hits() const
return d->m_jsHits;
}
+QQmlListProperty<Qt3DRender::QLayer> Qt3DRender::Render::Quick::Quick3DRayCaster::qmlLayers()
+{
+ return QQmlListProperty<QLayer>(this, 0,
+ &Quick3DRayCasterPrivate::appendLayer,
+ &Quick3DRayCasterPrivate::layerCount,
+ &Quick3DRayCasterPrivate::layerAt,
+ &Quick3DRayCasterPrivate::clearLayers);
+}
+
} // namespace Quick
} // namespace Render
} // namespace Qt3DRender
diff --git a/src/quick3d/quick3drender/items/quick3draycaster_p.h b/src/quick3d/quick3drender/items/quick3draycaster_p.h
index 682cee7f7..9be11f534 100644
--- a/src/quick3d/quick3drender/items/quick3draycaster_p.h
+++ b/src/quick3d/quick3drender/items/quick3draycaster_p.h
@@ -70,10 +70,12 @@ class QT3DQUICKRENDERSHARED_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);
QJSValue hits() const;
+ QQmlListProperty<QLayer> qmlLayers();
Q_SIGNALS:
void hitsChanged(const QJSValue &hits);
diff --git a/src/quick3d/quick3drender/items/quick3draycaster_p_p.h b/src/quick3d/quick3drender/items/quick3draycaster_p_p.h
index d1bef5be3..0098634bc 100644
--- a/src/quick3d/quick3drender/items/quick3draycaster_p_p.h
+++ b/src/quick3d/quick3drender/items/quick3draycaster_p_p.h
@@ -75,6 +75,10 @@ public:
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);
+ static void clearLayers(QQmlListProperty<QLayer> *list);
Q_DECLARE_PUBLIC(Quick3DRayCaster)
};
diff --git a/src/quick3d/quick3drender/items/quick3dscreenraycaster.cpp b/src/quick3d/quick3drender/items/quick3dscreenraycaster.cpp
index 629acf0f3..dd3d1f758 100644
--- a/src/quick3d/quick3drender/items/quick3dscreenraycaster.cpp
+++ b/src/quick3d/quick3drender/items/quick3dscreenraycaster.cpp
@@ -77,6 +77,15 @@ QJSValue Quick3DScreenRayCaster::hits() const
return d->m_jsHits;
}
+QQmlListProperty<Qt3DRender::QLayer> Qt3DRender::Render::Quick::Quick3DScreenRayCaster::qmlLayers()
+{
+ return QQmlListProperty<QLayer>(this, 0,
+ &Quick3DRayCasterPrivate::appendLayer,
+ &Quick3DRayCasterPrivate::layerCount,
+ &Quick3DRayCasterPrivate::layerAt,
+ &Quick3DRayCasterPrivate::clearLayers);
+}
+
} // namespace Quick
} // namespace Render
} // namespace Qt3DRender
diff --git a/src/quick3d/quick3drender/items/quick3dscreenraycaster_p.h b/src/quick3d/quick3drender/items/quick3dscreenraycaster_p.h
index 5d9b157cd..b337163c5 100644
--- a/src/quick3d/quick3drender/items/quick3dscreenraycaster_p.h
+++ b/src/quick3d/quick3drender/items/quick3dscreenraycaster_p.h
@@ -70,10 +70,12 @@ class QT3DQUICKRENDERSHARED_PRIVATE_EXPORT Quick3DScreenRayCaster : public QScre
{
Q_OBJECT
Q_PROPERTY(QJSValue hits READ hits NOTIFY hitsChanged)
+ Q_PROPERTY(QQmlListProperty<Qt3DRender::QLayer> layers READ qmlLayers)
public:
explicit Quick3DScreenRayCaster(QObject *parent = 0);
QJSValue hits() const;
+ QQmlListProperty<QLayer> qmlLayers();
Q_SIGNALS:
void hitsChanged(const QJSValue &hits);