diff options
author | Mike Krus <mike.krus@kdab.com> | 2018-02-22 21:36:13 -0500 |
---|---|---|
committer | Andy Nichols <andy.nichols@qt.io> | 2018-03-07 12:17:10 +0000 |
commit | 1de8948ff8db516e683203bcc896f931adb18cae (patch) | |
tree | 847b2122cca647d0e15d85ae1b07b8d2c949e9ec /src/render/jobs | |
parent | 42a27f1a9ce319393a8e10a5f91b336e69fe2eb6 (diff) |
Add more job tests for raycasting
- test screen space ray casting
- fixed handling of filters
- fixed handling of ray length
- few tests for filter handling
Change-Id: Ifc24d8f9e73556669338b3936a41dfa2c674e306
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
Diffstat (limited to 'src/render/jobs')
-rw-r--r-- | src/render/jobs/pickboundingvolumeutils.cpp | 46 | ||||
-rw-r--r-- | src/render/jobs/raycastingjob.cpp | 10 |
2 files changed, 19 insertions, 37 deletions
diff --git a/src/render/jobs/pickboundingvolumeutils.cpp b/src/render/jobs/pickboundingvolumeutils.cpp index 21255819f..ec5af190c 100644 --- a/src/render/jobs/pickboundingvolumeutils.cpp +++ b/src/render/jobs/pickboundingvolumeutils.cpp @@ -54,6 +54,7 @@ #include <Qt3DRender/private/layer_p.h> #include <vector> +#include <algorithm> QT_BEGIN_NAMESPACE @@ -624,9 +625,9 @@ bool HierarchicalEntityPicker::collectHits(NodeManagers *manager, Entity *root) EntityData current = worklist.back(); worklist.pop_back(); + bool accepted = true; if (m_layerIds.size()) { // TODO investigate reusing logic from LayerFilter job - bool accepted = false; Qt3DCore::QNodeIdVector filterLayers = current.recursiveLayers + current.entity->componentsUuid<Layer>(); // remove disabled layers @@ -636,53 +637,34 @@ bool HierarchicalEntityPicker::collectHits(NodeManagers *manager, Entity *root) return !layer || !layer->isEnabled(); }), filterLayers.end()); + std::sort(filterLayers.begin(), filterLayers.end()); + + Qt3DCore::QNodeIdVector commonIds; + std::set_intersection(m_layerIds.cbegin(), m_layerIds.cend(), + filterLayers.cbegin(), filterLayers.cend(), + std::back_inserter(commonIds)); + switch (m_filterMode) { case QAbstractRayCaster::AcceptAnyMatchingLayers: { - for (auto id: qAsConst(filterLayers)) { - if (m_layerIds.contains(id)) { - accepted = true; - break; - } - } + accepted = !commonIds.empty(); break; } case QAbstractRayCaster::AcceptAllMatchingLayers: { - accepted = true; - for (auto id: qAsConst(filterLayers)) { - if (!m_layerIds.contains(id)) { - accepted = false; - break; - } - } + accepted = commonIds == m_layerIds; break; } case QAbstractRayCaster::DiscardAnyMatchingLayers: { - accepted = true; - for (auto id: qAsConst(filterLayers)) { - if (m_layerIds.contains(id)) { - accepted = false; - break; - } - } + accepted = commonIds.empty(); break; } case QAbstractRayCaster::DiscardAllMatchingLayers: { - accepted = false; - for (auto id: qAsConst(filterLayers)) { - if (!m_layerIds.contains(id)) { - accepted = true; - break; - } - } + accepted = !(commonIds == m_layerIds); break; } default: Q_UNREACHABLE(); break; } - - if (!accepted) - continue; } // first pick entry sub-scene-graph @@ -693,7 +675,7 @@ bool HierarchicalEntityPicker::collectHits(NodeManagers *manager, Entity *root) // if we get a hit, we check again for this specific entity queryResult = rayCasting.query(m_ray, current.entity->worldBoundingVolume()); - if (queryResult.m_distance >= 0.f && (current.hasObjectPicker || !m_objectPickersRequired)) { + if (accepted && queryResult.m_distance >= 0.f && (current.hasObjectPicker || !m_objectPickersRequired)) { m_entities.push_back(current.entity); m_hits.push_back(queryResult); } diff --git a/src/render/jobs/raycastingjob.cpp b/src/render/jobs/raycastingjob.cpp index 0fbaed219..dc332201d 100644 --- a/src/render/jobs/raycastingjob.cpp +++ b/src/render/jobs/raycastingjob.cpp @@ -46,6 +46,7 @@ #include <Qt3DRender/private/nodemanagers_p.h> #include <Qt3DRender/private/pickboundingvolumeutils_p.h> #include <Qt3DRender/private/qray3d_p.h> +#include <Qt3DRender/private/sphere_p.h> #include <Qt3DRender/private/renderer_p.h> #include <Qt3DRender/private/rendersettings_p.h> #include <Qt3DRender/private/trianglesvisitor_p.h> @@ -150,6 +151,8 @@ bool RayCastingJob::runHelper() PickingUtils::ViewportCameraAreaGatherer vcaGatherer; const QVector<PickingUtils::ViewportCameraAreaDetails> vcaDetails = vcaGatherer.gather(m_frameGraphRoot); + const float sceneRayLength = m_node->worldBoundingVolumeWithChildren()->radius() * 3.f; + for (const EntityCasterGatherer::EntityCasterList::value_type &pair: entities) { QVector<QRay3D> rays; @@ -157,15 +160,12 @@ bool RayCastingJob::runHelper() case QAbstractRayCasterPrivate::WorldSpaceRayCaster: rays << QRay3D(Vector3D(pair.second->origin()), Vector3D(pair.second->direction()), - pair.second->length()); + pair.second->length() > 0.f ? pair.second->length() : sceneRayLength); rays.back().transform(*pair.first->worldTransform()); break; case QAbstractRayCasterPrivate::ScreenScapeRayCaster: - for (const PickingUtils::ViewportCameraAreaDetails &vca : vcaDetails) { - // TODO: Fix this properly by not passing null for the eventSource + for (const PickingUtils::ViewportCameraAreaDetails &vca : vcaDetails) rays << rayForViewportAndCamera(vca, nullptr, pair.second->position()); - //rays << rayForViewportAndCamera(vca.area, pair.second->position(), vca.viewport, vca.cameraId); - } break; default: Q_UNREACHABLE(); |