From 8c229d88a8e30f5a9d0815d7aa3811b4ec5463a7 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Mon, 19 Oct 2015 11:59:44 -0700 Subject: [PATCH 1/3] moving whitelist code out of octree --- libraries/entities/src/EntityTree.cpp | 46 +++++++++++++++++++++++++++ libraries/entities/src/EntityTree.h | 8 +++++ libraries/octree/src/Octree.cpp | 24 +------------- libraries/octree/src/Octree.h | 2 +- 4 files changed, 56 insertions(+), 24 deletions(-) diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index 6e487cbfe3..d40e4e6e96 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -448,6 +448,52 @@ bool EntityTree::findNearPointOperation(OctreeElementPointer element, void* extr // if this element doesn't contain the point, then none of its children can contain the point, so stop searching return false; } +// combines the ray cast arguments into a single object +class RayArgs { +public: + glm::vec3 origin; + glm::vec3 direction; + OctreeElementPointer& element; + float& distance; + BoxFace& face; + glm::vec3& surfaceNormal; + const QVector& entityIdsToInclude; + void** intersectedObject; + bool found; + bool precisionPicking; +}; + + +bool findRayIntersectionOp(OctreeElementPointer element, void* extraData) { + RayArgs* args = static_cast(extraData); + bool keepSearching = true; + if (element->findRayIntersection(args->origin, args->direction, keepSearching, + args->element, args->distance, args->face, args->surfaceNormal, args->entityIdsToInclude, + args->intersectedObject, args->precisionPicking)) { + args->found = true; + } + return keepSearching; +} + +bool EntityTree::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, + OctreeElementPointer& element, float& distance, + BoxFace& face, glm::vec3& surfaceNormal, const QVector& entityIdsToInclude, void** intersectedObject, + Octree::lockType lockType, bool* accurateResult, bool precisionPicking) { + RayArgs args = { origin, direction, element, distance, face, surfaceNormal, entityIdsToInclude, intersectedObject, false, precisionPicking }; + distance = FLT_MAX; + + bool requireLock = lockType == Octree::Lock; + bool lockResult = withReadLock([&]{ + recurseTreeWithOperation(findRayIntersectionOp, &args); + }, requireLock); + + if (accurateResult) { + *accurateResult = lockResult; // if user asked to accuracy or result, let them know this is accurate + } + + return args.found; +} + EntityItemPointer EntityTree::findClosestEntity(glm::vec3 position, float targetRadius) { FindNearPointArgs args = { position, targetRadius, false, NULL, FLT_MAX }; diff --git a/libraries/entities/src/EntityTree.h b/libraries/entities/src/EntityTree.h index ff84a79088..17c7347b2e 100644 --- a/libraries/entities/src/EntityTree.h +++ b/libraries/entities/src/EntityTree.h @@ -80,6 +80,14 @@ public: virtual int processEditPacketData(NLPacket& packet, const unsigned char* editData, int maxLength, const SharedNodePointer& senderNode); + virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, + OctreeElementPointer& node, float& distance, BoxFace& face, glm::vec3& surfaceNormal, + const QVector& entityIdsToInclude = QVector(), + void** intersectedObject = NULL, + Octree::lockType lockType = Octree::TryLock, + bool* accurateResult = NULL, + bool precisionPicking = false); + virtual bool rootElementHasData() const { return true; } // the root at least needs to store the number of entities in the packet/buffer diff --git a/libraries/octree/src/Octree.cpp b/libraries/octree/src/Octree.cpp index 3b6467401c..f573161255 100644 --- a/libraries/octree/src/Octree.cpp +++ b/libraries/octree/src/Octree.cpp @@ -709,34 +709,12 @@ public: bool precisionPicking; }; -bool findRayIntersectionOp(OctreeElementPointer element, void* extraData) { - RayArgs* args = static_cast(extraData); - bool keepSearching = true; - if (element->findRayIntersection(args->origin, args->direction, keepSearching, - args->element, args->distance, args->face, args->surfaceNormal, args->entityIdsToInclude, - args->intersectedObject, args->precisionPicking)) { - args->found = true; - } - return keepSearching; -} bool Octree::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, OctreeElementPointer& element, float& distance, BoxFace& face, glm::vec3& surfaceNormal, const QVector& entityIdsToInclude, void** intersectedObject, Octree::lockType lockType, bool* accurateResult, bool precisionPicking) { - RayArgs args = { origin, direction, element, distance, face, surfaceNormal, entityIdsToInclude, intersectedObject, false, precisionPicking}; - distance = FLT_MAX; - - bool requireLock = lockType == Octree::Lock; - bool lockResult = withReadLock([&]{ - recurseTreeWithOperation(findRayIntersectionOp, &args); - }, requireLock); - - if (accurateResult) { - *accurateResult = lockResult; // if user asked to accuracy or result, let them know this is accurate - } - - return args.found; + return false; } class SphereArgs { diff --git a/libraries/octree/src/Octree.h b/libraries/octree/src/Octree.h index f0a4d2c9c0..c785bf47fb 100644 --- a/libraries/octree/src/Octree.h +++ b/libraries/octree/src/Octree.h @@ -298,7 +298,7 @@ public: TryLock } lockType; - bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, + virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, OctreeElementPointer& node, float& distance, BoxFace& face, glm::vec3& surfaceNormal, const QVector& entityIdsToInclude = QVector(), void** intersectedObject = NULL, From dcb37ccd73c41aa85164500ee5dd94dd3e9d64a1 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Mon, 19 Oct 2015 13:14:19 -0700 Subject: [PATCH 2/3] Removed whitelist and raypicking code from octree, fixed a small bug with polylines --- libraries/entities/src/EntityTree.cpp | 3 +- libraries/entities/src/EntityTreeElement.cpp | 41 +++++++++++++ libraries/entities/src/EntityTreeElement.h | 5 +- libraries/entities/src/PolyLineEntityItem.cpp | 7 ++- libraries/octree/src/Octree.cpp | 21 ------- libraries/octree/src/Octree.h | 7 --- libraries/octree/src/OctreeElement.cpp | 58 ------------------- libraries/octree/src/OctreeElement.h | 10 ---- 8 files changed, 51 insertions(+), 101 deletions(-) diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index d40e4e6e96..e45e3e8a1e 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -467,7 +467,8 @@ public: bool findRayIntersectionOp(OctreeElementPointer element, void* extraData) { RayArgs* args = static_cast(extraData); bool keepSearching = true; - if (element->findRayIntersection(args->origin, args->direction, keepSearching, + EntityTreeElementPointer entityTreeElementPointer = std::dynamic_pointer_cast(element); + if (entityTreeElementPointer ->findRayIntersection(args->origin, args->direction, keepSearching, args->element, args->distance, args->face, args->surfaceNormal, args->entityIdsToInclude, args->intersectedObject, args->precisionPicking)) { args->found = true; diff --git a/libraries/entities/src/EntityTreeElement.cpp b/libraries/entities/src/EntityTreeElement.cpp index 56ab27836c..b3571097b3 100644 --- a/libraries/entities/src/EntityTreeElement.cpp +++ b/libraries/entities/src/EntityTreeElement.cpp @@ -493,6 +493,47 @@ bool EntityTreeElement::bestFitBounds(const glm::vec3& minPoint, const glm::vec3 return false; } +bool EntityTreeElement::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, + bool& keepSearching, OctreeElementPointer& element, float& distance, + BoxFace& face, glm::vec3& surfaceNormal, const QVector& entityIdsToInclude, + void** intersectedObject, bool precisionPicking) { + + keepSearching = true; // assume that we will continue searching after this. + + float distanceToElementCube = std::numeric_limits::max(); + float distanceToElementDetails = distance; + BoxFace localFace; + glm::vec3 localSurfaceNormal; + + // if the ray doesn't intersect with our cube, we can stop searching! + if (!_cube.findRayIntersection(origin, direction, distanceToElementCube, localFace, localSurfaceNormal)) { + keepSearching = false; // no point in continuing to search + return false; // we did not intersect + } + + // by default, we only allow intersections with leaves with content + if (!canRayIntersect()) { + return false; // we don't intersect with non-leaves, and we keep searching + } + + // if the distance to the element cube is not less than the current best distance, then it's not possible + // for any details inside the cube to be closer so we don't need to consider them. + if (_cube.contains(origin) || distanceToElementCube < distance) { + + if (findDetailedRayIntersection(origin, direction, keepSearching, element, distanceToElementDetails, + face, localSurfaceNormal, entityIdsToInclude, intersectedObject, precisionPicking, distanceToElementCube)) { + + if (distanceToElementDetails < distance) { + distance = distanceToElementDetails; + face = localFace; + surfaceNormal = localSurfaceNormal; + return true; + } + } + } + return false; +} + bool EntityTreeElement::findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction, bool& keepSearching, OctreeElementPointer& element, float& distance, BoxFace& face, glm::vec3& surfaceNormal, const QVector& entityIdsToInclude, void** intersectedObject, bool precisionPicking, float distanceToElementCube) { diff --git a/libraries/entities/src/EntityTreeElement.h b/libraries/entities/src/EntityTreeElement.h index 0a47542e65..78537dca3f 100644 --- a/libraries/entities/src/EntityTreeElement.h +++ b/libraries/entities/src/EntityTreeElement.h @@ -142,11 +142,14 @@ public: virtual bool deleteApproved() const { return !hasEntities(); } virtual bool canRayIntersect() const { return hasEntities(); } + virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, + bool& keepSearching, OctreeElementPointer& node, float& distance, + BoxFace& face, glm::vec3& surfaceNormal, const QVector& entityIdsToInclude, + void** intersectedObject = NULL, bool precisionPicking = false); virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction, bool& keepSearching, OctreeElementPointer& element, float& distance, BoxFace& face, glm::vec3& surfaceNormal, const QVector& entityIdsToInclude, void** intersectedObject, bool precisionPicking, float distanceToElementCube); - virtual bool findSpherePenetration(const glm::vec3& center, float radius, glm::vec3& penetration, void** penetratedObject) const; diff --git a/libraries/entities/src/PolyLineEntityItem.cpp b/libraries/entities/src/PolyLineEntityItem.cpp index 352d0425bf..f1be431ce8 100644 --- a/libraries/entities/src/PolyLineEntityItem.cpp +++ b/libraries/entities/src/PolyLineEntityItem.cpp @@ -108,7 +108,7 @@ bool PolyLineEntityItem::setStrokeWidths(const QVector& strokeWidths) { bool PolyLineEntityItem::setNormals(const QVector& normals) { _normals = normals; - if (_points.size() < 2 || _normals.size() < 2) { + if (_points.size() < 2 || _normals.size() < 2 || _strokeWidths.size() < 2) { return false; } @@ -123,7 +123,8 @@ bool PolyLineEntityItem::setNormals(const QVector& normals) { _vertices.clear(); glm::vec3 v1, v2, tangent, binormal, point; - for (int i = 0; i < minVectorSize - 1; i++) { + int finalIndex = minVectorSize -1; + for (int i = 0; i < finalIndex; i++) { float width = _strokeWidths.at(i); point = _points.at(i); @@ -138,7 +139,7 @@ bool PolyLineEntityItem::setNormals(const QVector& normals) { _vertices << v1 << v2; } //for last point we can just assume binormals are same since it represents last two vertices of quad - point = _points.at(minVectorSize - 1); + point = _points.at(finalIndex); v1 = point + binormal; v2 = point - binormal; _vertices << v1 << v2; diff --git a/libraries/octree/src/Octree.cpp b/libraries/octree/src/Octree.cpp index f573161255..cceb3ba706 100644 --- a/libraries/octree/src/Octree.cpp +++ b/libraries/octree/src/Octree.cpp @@ -694,29 +694,8 @@ OctreeElementPointer Octree::getOrCreateChildElementContaining(const AACube& box return getRoot()->getOrCreateChildElementContaining(box); } -// combines the ray cast arguments into a single object -class RayArgs { -public: - glm::vec3 origin; - glm::vec3 direction; - OctreeElementPointer& element; - float& distance; - BoxFace& face; - glm::vec3& surfaceNormal; - const QVector& entityIdsToInclude; - void** intersectedObject; - bool found; - bool precisionPicking; -}; -bool Octree::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, - OctreeElementPointer& element, float& distance, - BoxFace& face, glm::vec3& surfaceNormal, const QVector& entityIdsToInclude, void** intersectedObject, - Octree::lockType lockType, bool* accurateResult, bool precisionPicking) { - return false; -} - class SphereArgs { public: glm::vec3 center; diff --git a/libraries/octree/src/Octree.h b/libraries/octree/src/Octree.h index c785bf47fb..5ebb991d49 100644 --- a/libraries/octree/src/Octree.h +++ b/libraries/octree/src/Octree.h @@ -298,13 +298,6 @@ public: TryLock } lockType; - virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, - OctreeElementPointer& node, float& distance, BoxFace& face, glm::vec3& surfaceNormal, - const QVector& entityIdsToInclude = QVector(), - void** intersectedObject = NULL, - Octree::lockType lockType = Octree::TryLock, - bool* accurateResult = NULL, - bool precisionPicking = false); bool findSpherePenetration(const glm::vec3& center, float radius, glm::vec3& penetration, void** penetratedObject = NULL, Octree::lockType lockType = Octree::TryLock, bool* accurateResult = NULL); diff --git a/libraries/octree/src/OctreeElement.cpp b/libraries/octree/src/OctreeElement.cpp index 9a48079338..17ebe492ce 100644 --- a/libraries/octree/src/OctreeElement.cpp +++ b/libraries/octree/src/OctreeElement.cpp @@ -573,64 +573,6 @@ void OctreeElement::notifyUpdateHooks() { } } -bool OctreeElement::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, - bool& keepSearching, OctreeElementPointer& element, float& distance, - BoxFace& face, glm::vec3& surfaceNormal, const QVector& entityIdsToInclude, - void** intersectedObject, bool precisionPicking) { - - keepSearching = true; // assume that we will continue searching after this. - - float distanceToElementCube = std::numeric_limits::max(); - float distanceToElementDetails = distance; - BoxFace localFace; - glm::vec3 localSurfaceNormal; - - // if the ray doesn't intersect with our cube, we can stop searching! - if (!_cube.findRayIntersection(origin, direction, distanceToElementCube, localFace, localSurfaceNormal)) { - keepSearching = false; // no point in continuing to search - return false; // we did not intersect - } - - // by default, we only allow intersections with leaves with content - if (!canRayIntersect()) { - return false; // we don't intersect with non-leaves, and we keep searching - } - - // if the distance to the element cube is not less than the current best distance, then it's not possible - // for any details inside the cube to be closer so we don't need to consider them. - if (_cube.contains(origin) || distanceToElementCube < distance) { - - if (findDetailedRayIntersection(origin, direction, keepSearching, element, distanceToElementDetails, - face, localSurfaceNormal, entityIdsToInclude, intersectedObject, precisionPicking, distanceToElementCube)) { - - if (distanceToElementDetails < distance) { - distance = distanceToElementDetails; - face = localFace; - surfaceNormal = localSurfaceNormal; - return true; - } - } - } - return false; -} - -bool OctreeElement::findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction, - bool& keepSearching, OctreeElementPointer& element, float& distance, - BoxFace& face, glm::vec3& surfaceNormal, const QVector& entityIdsToInclude, - void** intersectedObject, bool precisionPicking, float distanceToElementCube) { - - // we did hit this element, so calculate appropriate distances - if (hasContent()) { - element = shared_from_this(); - distance = distanceToElementCube; - if (intersectedObject) { - *intersectedObject = this; - } - keepSearching = false; - return true; // we did intersect - } - return false; // we did not intersect -} bool OctreeElement::findSpherePenetration(const glm::vec3& center, float radius, glm::vec3& penetration, void** penetratedObject) const { diff --git a/libraries/octree/src/OctreeElement.h b/libraries/octree/src/OctreeElement.h index c132d437cd..6ccef31d4f 100644 --- a/libraries/octree/src/OctreeElement.h +++ b/libraries/octree/src/OctreeElement.h @@ -118,16 +118,6 @@ public: virtual bool deleteApproved() const { return true; } virtual bool canRayIntersect() const { return isLeaf(); } - virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, - bool& keepSearching, OctreeElementPointer& node, float& distance, - BoxFace& face, glm::vec3& surfaceNormal, const QVector& entityIdsToInclude, - void** intersectedObject = NULL, bool precisionPicking = false); - - virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction, - bool& keepSearching, OctreeElementPointer& element, float& distance, - BoxFace& face, glm::vec3& surfaceNormal, const QVector& entityIdsToInclude, - void** intersectedObject, bool precisionPicking, float distanceToElementCube); - /// \param center center of sphere in meters /// \param radius radius of sphere in meters /// \param[out] penetration pointing into cube from sphere From 0373a481f8475f4948373fbefdba406b3ec75957 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 20 Oct 2015 09:22:16 -0700 Subject: [PATCH 3/3] Using EntityItemIDs instead of QUuids --- .../entities-renderer/src/EntityTreeRenderer.cpp | 2 +- .../entities-renderer/src/EntityTreeRenderer.h | 2 +- .../entities/src/EntityScriptingInterface.cpp | 6 +++--- .../entities/src/EntityScriptingInterface.h | 2 +- libraries/entities/src/EntityTree.cpp | 4 ++-- libraries/entities/src/EntityTree.h | 2 +- libraries/entities/src/EntityTreeElement.cpp | 4 ++-- libraries/entities/src/EntityTreeElement.h | 4 ++-- libraries/shared/src/RegisteredMetaTypes.cpp | 16 +++++++++++++++- libraries/shared/src/RegisteredMetaTypes.h | 2 ++ 10 files changed, 30 insertions(+), 14 deletions(-) diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index 8f316af276..d5bf0bde8a 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -482,7 +482,7 @@ void EntityTreeRenderer::deleteReleasedModels() { } RayToEntityIntersectionResult EntityTreeRenderer::findRayIntersectionWorker(const PickRay& ray, Octree::lockType lockType, - bool precisionPicking, const QVector& entityIdsToInclude) { + bool precisionPicking, const QVector& entityIdsToInclude) { RayToEntityIntersectionResult result; if (_tree) { EntityTreePointer entityTree = std::static_pointer_cast(_tree); diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.h b/libraries/entities-renderer/src/EntityTreeRenderer.h index 15c030f77e..5cd86fba21 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.h +++ b/libraries/entities-renderer/src/EntityTreeRenderer.h @@ -130,7 +130,7 @@ private: QList _releasedModels; RayToEntityIntersectionResult findRayIntersectionWorker(const PickRay& ray, Octree::lockType lockType, - bool precisionPicking, const QVector& entityIdsToInclude = QVector()); + bool precisionPicking, const QVector& entityIdsToInclude = QVector()); EntityItemID _currentHoverOverEntityID; EntityItemID _currentClickingOnEntityID; diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index 07c932b34e..01d46e0a91 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -280,18 +280,18 @@ QVector EntityScriptingInterface::findEntitiesInBox(const glm::vec3& corn } RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersection(const PickRay& ray, bool precisionPicking, const QScriptValue& entityIdsToInclude) { - QVector entities = qVectorQUuidFromScriptValue(entityIdsToInclude); + QVector entities = qVectorEntityItemIDFromScriptValue(entityIdsToInclude); return findRayIntersectionWorker(ray, Octree::TryLock, precisionPicking, entities); } RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersectionBlocking(const PickRay& ray, bool precisionPicking, const QScriptValue& entityIdsToInclude) { - const QVector& entities = qVectorQUuidFromScriptValue(entityIdsToInclude); + const QVector& entities = qVectorEntityItemIDFromScriptValue(entityIdsToInclude); return findRayIntersectionWorker(ray, Octree::Lock, precisionPicking, entities); } RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersectionWorker(const PickRay& ray, Octree::lockType lockType, - bool precisionPicking, const QVector& entityIdsToInclude) { + bool precisionPicking, const QVector& entityIdsToInclude) { RayToEntityIntersectionResult result; diff --git a/libraries/entities/src/EntityScriptingInterface.h b/libraries/entities/src/EntityScriptingInterface.h index 48f13e81bd..d764cd7bab 100644 --- a/libraries/entities/src/EntityScriptingInterface.h +++ b/libraries/entities/src/EntityScriptingInterface.h @@ -186,7 +186,7 @@ private: /// actually does the work of finding the ray intersection, can be called in locking mode or tryLock mode RayToEntityIntersectionResult findRayIntersectionWorker(const PickRay& ray, Octree::lockType lockType, - bool precisionPicking, const QVector& entityIdsToInclude); + bool precisionPicking, const QVector& entityIdsToInclude); EntityTreePointer _entityTree; EntitiesScriptEngineProvider* _entitiesScriptEngine = nullptr; diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index e45e3e8a1e..24c13ae28e 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -457,7 +457,7 @@ public: float& distance; BoxFace& face; glm::vec3& surfaceNormal; - const QVector& entityIdsToInclude; + const QVector& entityIdsToInclude; void** intersectedObject; bool found; bool precisionPicking; @@ -478,7 +478,7 @@ bool findRayIntersectionOp(OctreeElementPointer element, void* extraData) { bool EntityTree::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, OctreeElementPointer& element, float& distance, - BoxFace& face, glm::vec3& surfaceNormal, const QVector& entityIdsToInclude, void** intersectedObject, + BoxFace& face, glm::vec3& surfaceNormal, const QVector& entityIdsToInclude, void** intersectedObject, Octree::lockType lockType, bool* accurateResult, bool precisionPicking) { RayArgs args = { origin, direction, element, distance, face, surfaceNormal, entityIdsToInclude, intersectedObject, false, precisionPicking }; distance = FLT_MAX; diff --git a/libraries/entities/src/EntityTree.h b/libraries/entities/src/EntityTree.h index 17c7347b2e..1957787a60 100644 --- a/libraries/entities/src/EntityTree.h +++ b/libraries/entities/src/EntityTree.h @@ -82,7 +82,7 @@ public: virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, OctreeElementPointer& node, float& distance, BoxFace& face, glm::vec3& surfaceNormal, - const QVector& entityIdsToInclude = QVector(), + const QVector& entityIdsToInclude = QVector(), void** intersectedObject = NULL, Octree::lockType lockType = Octree::TryLock, bool* accurateResult = NULL, diff --git a/libraries/entities/src/EntityTreeElement.cpp b/libraries/entities/src/EntityTreeElement.cpp index b3571097b3..8b3721488c 100644 --- a/libraries/entities/src/EntityTreeElement.cpp +++ b/libraries/entities/src/EntityTreeElement.cpp @@ -495,7 +495,7 @@ bool EntityTreeElement::bestFitBounds(const glm::vec3& minPoint, const glm::vec3 bool EntityTreeElement::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, bool& keepSearching, OctreeElementPointer& element, float& distance, - BoxFace& face, glm::vec3& surfaceNormal, const QVector& entityIdsToInclude, + BoxFace& face, glm::vec3& surfaceNormal, const QVector& entityIdsToInclude, void** intersectedObject, bool precisionPicking) { keepSearching = true; // assume that we will continue searching after this. @@ -536,7 +536,7 @@ bool EntityTreeElement::findRayIntersection(const glm::vec3& origin, const glm:: bool EntityTreeElement::findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction, bool& keepSearching, OctreeElementPointer& element, float& distance, BoxFace& face, glm::vec3& surfaceNormal, - const QVector& entityIdsToInclude, void** intersectedObject, bool precisionPicking, float distanceToElementCube) { + const QVector& entityIdsToInclude, void** intersectedObject, bool precisionPicking, float distanceToElementCube) { // only called if we do intersect our bounding cube, but find if we actually intersect with entities... int entityNumber = 0; diff --git a/libraries/entities/src/EntityTreeElement.h b/libraries/entities/src/EntityTreeElement.h index 78537dca3f..3be52a3740 100644 --- a/libraries/entities/src/EntityTreeElement.h +++ b/libraries/entities/src/EntityTreeElement.h @@ -144,11 +144,11 @@ public: virtual bool canRayIntersect() const { return hasEntities(); } virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, bool& keepSearching, OctreeElementPointer& node, float& distance, - BoxFace& face, glm::vec3& surfaceNormal, const QVector& entityIdsToInclude, + BoxFace& face, glm::vec3& surfaceNormal, const QVector& entityIdsToInclude, void** intersectedObject = NULL, bool precisionPicking = false); virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction, bool& keepSearching, OctreeElementPointer& element, float& distance, - BoxFace& face, glm::vec3& surfaceNormal, const QVector& entityIdsToInclude, + BoxFace& face, glm::vec3& surfaceNormal, const QVector& entityIdsToInclude, void** intersectedObject, bool precisionPicking, float distanceToElementCube); virtual bool findSpherePenetration(const glm::vec3& center, float radius, glm::vec3& penetration, void** penetratedObject) const; diff --git a/libraries/shared/src/RegisteredMetaTypes.cpp b/libraries/shared/src/RegisteredMetaTypes.cpp index 9ab0eaecb4..016c99a8dc 100644 --- a/libraries/shared/src/RegisteredMetaTypes.cpp +++ b/libraries/shared/src/RegisteredMetaTypes.cpp @@ -13,7 +13,6 @@ #include #include #include - #include #include "RegisteredMetaTypes.h" @@ -119,6 +118,21 @@ QVector qVectorQUuidFromScriptValue(const QScriptValue& array) { return newVector; } +QVector qVectorEntityItemIDFromScriptValue(const QScriptValue& array) { + if (!array.isArray()) { + return QVector(); + } + QVector newVector; + int length = array.property("length").toInteger(); + newVector.reserve(length); + for (int i = 0; i < length; i++) { + QString uuidAsString = array.property(i).toString(); + EntityItemID fromString(uuidAsString); + newVector << fromString; + } + return newVector; +} + QScriptValue qVectorFloatToScriptValue(QScriptEngine* engine, const QVector& vector) { QScriptValue array = engine->newArray(); for (int i = 0; i < vector.size(); i++) { diff --git a/libraries/shared/src/RegisteredMetaTypes.h b/libraries/shared/src/RegisteredMetaTypes.h index cd1e3b0d3e..8e53f0ee37 100644 --- a/libraries/shared/src/RegisteredMetaTypes.h +++ b/libraries/shared/src/RegisteredMetaTypes.h @@ -14,6 +14,7 @@ #include #include +#include "../../entities/src/EntityItemID.h" #include #include @@ -66,6 +67,7 @@ void qVectorFloatFromScriptValue(const QScriptValue& array, QVector& vect QVector qVectorFloatFromScriptValue(const QScriptValue& array); QVector qVectorQUuidFromScriptValue(const QScriptValue& array); +QVector qVectorEntityItemIDFromScriptValue(const QScriptValue& array); class PickRay { public: