diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 3d2841923f..750c41d48a 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -193,8 +193,9 @@ #include #include #include + +#include #include -#include #include "commerce/Ledger.h" #include "commerce/Wallet.h" @@ -608,7 +609,7 @@ bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) { DependencyManager::set(); DependencyManager::set(); - DependencyManager::set(); + DependencyManager::set(); return previousSessionCrashed; } @@ -5096,8 +5097,8 @@ void Application::update(float deltaTime) { } { - PROFILE_RANGE(app, "RayPick"); - DependencyManager::get()->update(); + PROFILE_RANGE(app, "RayPickManager"); + _rayPickManager.update(); } { @@ -5965,6 +5966,8 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri scriptEngine->registerGlobalObject("AudioScope", DependencyManager::get().data()); scriptEngine->registerGlobalObject("AvatarBookmarks", DependencyManager::get().data()); scriptEngine->registerGlobalObject("LocationBookmarks", DependencyManager::get().data()); + + scriptEngine->registerGlobalObject("RayPick", DependencyManager::get().data()); scriptEngine->registerGlobalObject("LaserPointers", DependencyManager::get().data()); // Caches @@ -6019,8 +6022,6 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri scriptEngine->registerGlobalObject("AvatarInputs", AvatarInputs::getInstance()); scriptEngine->registerGlobalObject("ContextOverlay", DependencyManager::get().data()); - scriptEngine->registerGlobalObject("RayPick", DependencyManager::get().data()); - qScriptRegisterMetaType(scriptEngine, OverlayIDtoScriptValue, OverlayIDfromScriptValue); // connect this script engines printedMessage signal to the global ScriptEngines these various messages diff --git a/interface/src/Application.h b/interface/src/Application.h index fcd47faa41..8a38116fe8 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -70,6 +70,8 @@ #include "ui/OverlayConductor.h" #include "ui/overlays/Overlays.h" #include "UndoStackScriptingInterface.h" + +#include "raypick/RayPickManager.h" #include "raypick/LaserPointerManager.h" #include @@ -303,6 +305,7 @@ public: bool getSaveAvatarOverrideUrl() { return _saveAvatarOverrideUrl; } LaserPointerManager& getLaserPointerManager() { return _laserPointerManager; } + RayPickManager& getRayPickManager() { return _rayPickManager; } signals: void svoImportRequested(const QString& url); @@ -702,6 +705,7 @@ private: bool _saveAvatarOverrideUrl { false }; LaserPointerManager _laserPointerManager; + RayPickManager _rayPickManager; }; #endif // hifi_Application_h diff --git a/interface/src/raypick/LaserPointer.cpp b/interface/src/raypick/LaserPointer.cpp index 0e1d384e5d..f4adcc736d 100644 --- a/interface/src/raypick/LaserPointer.cpp +++ b/interface/src/raypick/LaserPointer.cpp @@ -11,9 +11,10 @@ #include "LaserPointer.h" #include "Application.h" +#include "ui/overlays/Overlay.h" #include "avatar/AvatarManager.h" -LaserPointer::LaserPointer(const QVariantMap& rayProps, const RenderStateMap& renderStates, const DefaultRenderStateMap& defaultRenderStates, +LaserPointer::LaserPointer(const QVariant& rayProps, const RenderStateMap& renderStates, const DefaultRenderStateMap& defaultRenderStates, const bool faceAvatar, const bool centerEndY, const bool lockEnd, const bool enabled) : _renderingEnabled(enabled), _renderStates(renderStates), @@ -22,7 +23,7 @@ LaserPointer::LaserPointer(const QVariantMap& rayProps, const RenderStateMap& re _centerEndY(centerEndY), _lockEnd(lockEnd) { - _rayPickUID = DependencyManager::get()->createRayPick(rayProps); + _rayPickUID = DependencyManager::get()->createRayPick(rayProps); for (auto& state : _renderStates) { if (!enabled || state.first != _currentRenderState) { @@ -37,7 +38,7 @@ LaserPointer::LaserPointer(const QVariantMap& rayProps, const RenderStateMap& re } LaserPointer::~LaserPointer() { - DependencyManager::get()->removeRayPick(_rayPickUID); + DependencyManager::get()->removeRayPick(_rayPickUID); for (auto& renderState : _renderStates) { renderState.second.deleteOverlays(); @@ -48,12 +49,12 @@ LaserPointer::~LaserPointer() { } void LaserPointer::enable() { - DependencyManager::get()->enableRayPick(_rayPickUID); + DependencyManager::get()->enableRayPick(_rayPickUID); _renderingEnabled = true; } void LaserPointer::disable() { - DependencyManager::get()->disableRayPick(_rayPickUID); + DependencyManager::get()->disableRayPick(_rayPickUID); _renderingEnabled = false; if (!_currentRenderState.empty()) { if (_renderStates.find(_currentRenderState) != _renderStates.end()) { @@ -90,7 +91,7 @@ void LaserPointer::updateRenderStateOverlay(const OverlayID& id, const QVariant& } void LaserPointer::updateRenderState(const RenderState& renderState, const IntersectionType type, const float distance, const QUuid& objectID, const bool defaultState) { - PickRay pickRay = DependencyManager::get()->getPickRay(_rayPickUID); + PickRay pickRay = qApp->getRayPickManager().getPickRay(_rayPickUID); if (!renderState.getStartID().isNull()) { QVariantMap startProps; startProps.insert("position", vec3toVariant(pickRay.origin)); @@ -180,7 +181,7 @@ void LaserPointer::disableRenderState(const RenderState& renderState) { } void LaserPointer::update() { - RayPickResult prevRayPickResult = DependencyManager::get()->getPrevRayPickResult(_rayPickUID); + RayPickResult prevRayPickResult = DependencyManager::get()->getPrevRayPickResult(_rayPickUID); if (_renderingEnabled && !_currentRenderState.empty() && _renderStates.find(_currentRenderState) != _renderStates.end() && prevRayPickResult.type != IntersectionType::NONE) { updateRenderState(_renderStates[_currentRenderState], prevRayPickResult.type, prevRayPickResult.distance, prevRayPickResult.objectID, false); disableRenderState(_defaultRenderStates[_currentRenderState].second); diff --git a/interface/src/raypick/LaserPointer.h b/interface/src/raypick/LaserPointer.h index aaa9dad83f..d901d12cf4 100644 --- a/interface/src/raypick/LaserPointer.h +++ b/interface/src/raypick/LaserPointer.h @@ -13,10 +13,9 @@ #include #include "glm/glm.hpp" -#include "ui/overlays/Overlay.h" #include -#include "RayPickManager.h" +#include "raypick/RayPickScriptingInterface.h" class RayPickResult; @@ -52,25 +51,25 @@ public: typedef std::unordered_map RenderStateMap; typedef std::unordered_map> DefaultRenderStateMap; - LaserPointer(const QVariantMap& rayProps, const RenderStateMap& renderStates, const DefaultRenderStateMap& defaultRenderStates, + LaserPointer(const QVariant& rayProps, const RenderStateMap& renderStates, const DefaultRenderStateMap& defaultRenderStates, const bool faceAvatar, const bool centerEndY, const bool lockEnd, const bool enabled); ~LaserPointer(); QUuid getRayUID() { return _rayPickUID; } void enable(); void disable(); - const RayPickResult getPrevRayPickResult() { return DependencyManager::get()->getPrevRayPickResult(_rayPickUID); } + const RayPickResult getPrevRayPickResult() { return DependencyManager::get()->getPrevRayPickResult(_rayPickUID); } void setRenderState(const std::string& state); // You cannot use editRenderState to change the overlay type of any part of the laser pointer. You can only edit the properties of the existing overlays. void editRenderState(const std::string& state, const QVariant& startProps, const QVariant& pathProps, const QVariant& endProps); - void setIgnoreEntities(const QScriptValue& ignoreEntities) { DependencyManager::get()->setIgnoreEntities(_rayPickUID, ignoreEntities); } - void setIncludeEntities(const QScriptValue& includeEntities) { DependencyManager::get()->setIncludeEntities(_rayPickUID, includeEntities); } - void setIgnoreOverlays(const QScriptValue& ignoreOverlays) { DependencyManager::get()->setIgnoreOverlays(_rayPickUID, ignoreOverlays); } - void setIncludeOverlays(const QScriptValue& includeOverlays) { DependencyManager::get()->setIncludeOverlays(_rayPickUID, includeOverlays); } - void setIgnoreAvatars(const QScriptValue& ignoreAvatars) { DependencyManager::get()->setIgnoreAvatars(_rayPickUID, ignoreAvatars); } - void setIncludeAvatars(const QScriptValue& includeAvatars) { DependencyManager::get()->setIncludeAvatars(_rayPickUID, includeAvatars); } + void setIgnoreEntities(const QScriptValue& ignoreEntities) { DependencyManager::get()->setIgnoreEntities(_rayPickUID, ignoreEntities); } + void setIncludeEntities(const QScriptValue& includeEntities) { DependencyManager::get()->setIncludeEntities(_rayPickUID, includeEntities); } + void setIgnoreOverlays(const QScriptValue& ignoreOverlays) { DependencyManager::get()->setIgnoreOverlays(_rayPickUID, ignoreOverlays); } + void setIncludeOverlays(const QScriptValue& includeOverlays) { DependencyManager::get()->setIncludeOverlays(_rayPickUID, includeOverlays); } + void setIgnoreAvatars(const QScriptValue& ignoreAvatars) { DependencyManager::get()->setIgnoreAvatars(_rayPickUID, ignoreAvatars); } + void setIncludeAvatars(const QScriptValue& includeAvatars) { DependencyManager::get()->setIncludeAvatars(_rayPickUID, includeAvatars); } void setLockEndUUID(QUuid objectID, const bool isOverlay) { _objectLockEnd = std::pair(objectID, isOverlay); } diff --git a/interface/src/raypick/LaserPointerManager.cpp b/interface/src/raypick/LaserPointerManager.cpp index 089b9911d0..908bcc39f1 100644 --- a/interface/src/raypick/LaserPointerManager.cpp +++ b/interface/src/raypick/LaserPointerManager.cpp @@ -9,9 +9,8 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // #include "LaserPointerManager.h" -#include "RayPick.h" -QUuid LaserPointerManager::createLaserPointer(const QVariantMap& rayProps, const LaserPointer::RenderStateMap& renderStates, const LaserPointer::DefaultRenderStateMap& defaultRenderStates, +QUuid LaserPointerManager::createLaserPointer(const QVariant& rayProps, const LaserPointer::RenderStateMap& renderStates, const LaserPointer::DefaultRenderStateMap& defaultRenderStates, const bool faceAvatar, const bool centerEndY, const bool lockEnd, const bool enabled) { std::shared_ptr laserPointer = std::make_shared(rayProps, renderStates, defaultRenderStates, faceAvatar, centerEndY, lockEnd, enabled); if (!laserPointer->getRayUID().isNull()) { diff --git a/interface/src/raypick/LaserPointerManager.h b/interface/src/raypick/LaserPointerManager.h index b981dde9fb..020b778983 100644 --- a/interface/src/raypick/LaserPointerManager.h +++ b/interface/src/raypick/LaserPointerManager.h @@ -22,7 +22,7 @@ class RayPickResult; class LaserPointerManager { public: - QUuid createLaserPointer(const QVariantMap& rayProps, const LaserPointer::RenderStateMap& renderStates, const LaserPointer::DefaultRenderStateMap& defaultRenderStates, + QUuid createLaserPointer(const QVariant& rayProps, const LaserPointer::RenderStateMap& renderStates, const LaserPointer::DefaultRenderStateMap& defaultRenderStates, const bool faceAvatar, const bool centerEndY, const bool lockEnd, const bool enabled); void removeLaserPointer(const QUuid uid); void enableLaserPointer(const QUuid uid); diff --git a/interface/src/raypick/LaserPointerScriptingInterface.cpp b/interface/src/raypick/LaserPointerScriptingInterface.cpp index 9b7f18d436..a976a00893 100644 --- a/interface/src/raypick/LaserPointerScriptingInterface.cpp +++ b/interface/src/raypick/LaserPointerScriptingInterface.cpp @@ -12,11 +12,8 @@ #include "LaserPointerScriptingInterface.h" #include -#include "RegisteredMetaTypes.h" #include "GLMHelpers.h" -#include "Application.h" - QUuid LaserPointerScriptingInterface::createLaserPointer(const QVariant& properties) { QVariantMap propertyMap = properties.toMap(); @@ -69,7 +66,7 @@ QUuid LaserPointerScriptingInterface::createLaserPointer(const QVariant& propert } } - return qApp->getLaserPointerManager().createLaserPointer(propertyMap, renderStates, defaultRenderStates, faceAvatar, centerEndY, lockEnd, enabled); + return qApp->getLaserPointerManager().createLaserPointer(properties, renderStates, defaultRenderStates, faceAvatar, centerEndY, lockEnd, enabled); } void LaserPointerScriptingInterface::editRenderState(QUuid uid, const QString& renderState, const QVariant& properties) { diff --git a/interface/src/raypick/LaserPointerScriptingInterface.h b/interface/src/raypick/LaserPointerScriptingInterface.h index 7866a5da51..8ae263b0ec 100644 --- a/interface/src/raypick/LaserPointerScriptingInterface.h +++ b/interface/src/raypick/LaserPointerScriptingInterface.h @@ -13,7 +13,6 @@ #include -#include "LaserPointerManager.h" #include "RegisteredMetaTypes.h" #include "DependencyManager.h" #include "Application.h" @@ -41,7 +40,7 @@ public slots: Q_INVOKABLE void setLockEndUUID(QUuid uid, QUuid objectID, const bool isOverlay) { qApp->getLaserPointerManager().setLockEndUUID(uid, objectID, isOverlay); } private: - const RenderState buildRenderState(const QVariantMap & propMap); + const RenderState buildRenderState(const QVariantMap& propMap); }; diff --git a/interface/src/raypick/RayPickManager.cpp b/interface/src/raypick/RayPickManager.cpp index 68c850b295..cf135ffdca 100644 --- a/interface/src/raypick/RayPickManager.cpp +++ b/interface/src/raypick/RayPickManager.cpp @@ -141,62 +141,25 @@ void RayPickManager::update() { } } -QUuid RayPickManager::createRayPick(const QVariantMap& rayProps) { - bool enabled = false; - if (rayProps["enabled"].isValid()) { - enabled = rayProps["enabled"].toBool(); - } +QUuid RayPickManager::createRayPick(const std::string& jointName, const glm::vec3& posOffset, const glm::vec3& dirOffset, const RayPickFilter& filter, const float maxDistance, const bool enabled) { + QWriteLocker lock(&_addLock); + QUuid id = QUuid::createUuid(); + _rayPicksToAdd.push(std::pair>(id, std::make_shared(jointName, posOffset, dirOffset, filter, maxDistance, enabled))); + return id; +} - RayPickFilter filter = RayPickFilter(); - if (rayProps["filter"].isValid()) { - filter = RayPickFilter(rayProps["filter"].toUInt()); - } +QUuid RayPickManager::createRayPick(const RayPickFilter& filter, const float maxDistance, const bool enabled) { + QWriteLocker lock(&_addLock); + QUuid id = QUuid::createUuid(); + _rayPicksToAdd.push(std::pair>(id, std::make_shared(filter, maxDistance, enabled))); + return id; +} - float maxDistance = 0.0f; - if (rayProps["maxDistance"].isValid()) { - maxDistance = rayProps["maxDistance"].toFloat(); - } - - if (rayProps["joint"].isValid()) { - std::string jointName = rayProps["joint"].toString().toStdString(); - - if (jointName != "Mouse") { - // x = upward, y = forward, z = lateral - glm::vec3 posOffset = Vectors::ZERO; - if (rayProps["posOffset"].isValid()) { - posOffset = vec3FromVariant(rayProps["posOffset"]); - } - - glm::vec3 dirOffset = Vectors::UP; - if (rayProps["dirOffset"].isValid()) { - dirOffset = vec3FromVariant(rayProps["dirOffset"]); - } - - QWriteLocker lock(&_addLock); - QUuid id = QUuid::createUuid(); - _rayPicksToAdd.push(std::pair>(id, std::make_shared(jointName, posOffset, dirOffset, filter, maxDistance, enabled))); - return id; - } else { - QWriteLocker lock(&_addLock); - QUuid id = QUuid::createUuid(); - _rayPicksToAdd.push(std::pair>(id, std::make_shared(filter, maxDistance, enabled))); - return id; - } - } else if (rayProps["position"].isValid()) { - glm::vec3 position = vec3FromVariant(rayProps["position"]); - - glm::vec3 direction = -Vectors::UP; - if (rayProps["direction"].isValid()) { - direction = vec3FromVariant(rayProps["direction"]); - } - - QWriteLocker lock(&_addLock); - QUuid id = QUuid::createUuid(); - _rayPicksToAdd.push(std::pair>(id, std::make_shared(position, direction, filter, maxDistance, enabled))); - return id; - } - - return QUuid(); +QUuid RayPickManager::createRayPick(const glm::vec3& position, const glm::vec3& direction, const RayPickFilter& filter, const float maxDistance, const bool enabled) { + QWriteLocker lock(&_addLock); + QUuid id = QUuid::createUuid(); + _rayPicksToAdd.push(std::pair>(id, std::make_shared(position, direction, filter, maxDistance, enabled))); + return id; } void RayPickManager::removeRayPick(const QUuid uid) { diff --git a/interface/src/raypick/RayPickManager.h b/interface/src/raypick/RayPickManager.h index e422995810..8ef2ceebe0 100644 --- a/interface/src/raypick/RayPickManager.h +++ b/interface/src/raypick/RayPickManager.h @@ -18,48 +18,32 @@ #include #include "RegisteredMetaTypes.h" -#include "DependencyManager.h" #include #include class RayPickResult; -class RayPickManager : public QObject, public Dependency { - Q_OBJECT - Q_PROPERTY(unsigned int PICK_NOTHING READ PICK_NOTHING CONSTANT) - Q_PROPERTY(unsigned int PICK_ENTITIES READ PICK_ENTITIES CONSTANT) - Q_PROPERTY(unsigned int PICK_OVERLAYS READ PICK_OVERLAYS CONSTANT) - Q_PROPERTY(unsigned int PICK_AVATARS READ PICK_AVATARS CONSTANT) - Q_PROPERTY(unsigned int PICK_HUD READ PICK_HUD CONSTANT) - Q_PROPERTY(unsigned int PICK_BOUNDING_BOX READ PICK_BOUNDING_BOX CONSTANT) - Q_PROPERTY(unsigned int PICK_INCLUDE_INVISIBLE READ PICK_INCLUDE_INVISIBLE CONSTANT) - Q_PROPERTY(unsigned int PICK_INCLUDE_NONCOLLIDABLE READ PICK_INCLUDE_NONCOLLIDABLE CONSTANT) - Q_PROPERTY(unsigned int PICK_ALL_INTERSECTIONS READ PICK_ALL_INTERSECTIONS CONSTANT) - Q_PROPERTY(unsigned int INTERSECTED_NONE READ INTERSECTED_NONE CONSTANT) - Q_PROPERTY(unsigned int INTERSECTED_ENTITY READ INTERSECTED_ENTITY CONSTANT) - Q_PROPERTY(unsigned int INTERSECTED_OVERLAY READ INTERSECTED_OVERLAY CONSTANT) - Q_PROPERTY(unsigned int INTERSECTED_AVATAR READ INTERSECTED_AVATAR CONSTANT) - Q_PROPERTY(unsigned int INTERSECTED_HUD READ INTERSECTED_HUD CONSTANT) - SINGLETON_DEPENDENCY +class RayPickManager { public: void update(); const PickRay getPickRay(const QUuid uid); -public slots: - Q_INVOKABLE QUuid createRayPick(const QVariantMap& rayProps); - Q_INVOKABLE void removeRayPick(const QUuid uid); - Q_INVOKABLE void enableRayPick(const QUuid uid); - Q_INVOKABLE void disableRayPick(const QUuid uid); - Q_INVOKABLE const RayPickResult getPrevRayPickResult(const QUuid uid); + QUuid createRayPick(const std::string& jointName, const glm::vec3& posOffset, const glm::vec3& dirOffset, const RayPickFilter& filter, const float maxDistance, const bool enabled); + QUuid createRayPick(const RayPickFilter& filter, const float maxDistance, const bool enabled); + QUuid createRayPick(const glm::vec3& position, const glm::vec3& direction, const RayPickFilter& filter, const float maxDistance, const bool enabled); + void removeRayPick(const QUuid uid); + void enableRayPick(const QUuid uid); + void disableRayPick(const QUuid uid); + const RayPickResult getPrevRayPickResult(const QUuid uid); - Q_INVOKABLE void setIgnoreEntities(QUuid uid, const QScriptValue& ignoreEntities); - Q_INVOKABLE void setIncludeEntities(QUuid uid, const QScriptValue& includeEntities); - Q_INVOKABLE void setIgnoreOverlays(QUuid uid, const QScriptValue& ignoreOverlays); - Q_INVOKABLE void setIncludeOverlays(QUuid uid, const QScriptValue& includeOverlays); - Q_INVOKABLE void setIgnoreAvatars(QUuid uid, const QScriptValue& ignoreAvatars); - Q_INVOKABLE void setIncludeAvatars(QUuid uid, const QScriptValue& includeAvatars); + void setIgnoreEntities(QUuid uid, const QScriptValue& ignoreEntities); + void setIncludeEntities(QUuid uid, const QScriptValue& includeEntities); + void setIgnoreOverlays(QUuid uid, const QScriptValue& ignoreOverlays); + void setIncludeOverlays(QUuid uid, const QScriptValue& includeOverlays); + void setIgnoreAvatars(QUuid uid, const QScriptValue& ignoreAvatars); + void setIncludeAvatars(QUuid uid, const QScriptValue& includeAvatars); private: QHash> _rayPicks; @@ -75,22 +59,6 @@ private: // Returns true if this ray exists in the cache, and if it does, update res if the cached result is closer bool checkAndCompareCachedResults(QPair& ray, RayPickCache& cache, RayPickResult& res, const RayPickFilter::Flags& mask); void cacheResult(const bool intersects, const RayPickResult& resTemp, const RayPickFilter::Flags& mask, RayPickResult& res, QPair& ray, RayPickCache& cache); - - unsigned int PICK_NOTHING() { return RayPickFilter::getBitMask(RayPickFilter::FlagBit::PICK_NOTHING); } - unsigned int PICK_ENTITIES() { return RayPickFilter::getBitMask(RayPickFilter::FlagBit::PICK_ENTITIES); } - unsigned int PICK_OVERLAYS() { return RayPickFilter::getBitMask(RayPickFilter::FlagBit::PICK_OVERLAYS); } - unsigned int PICK_AVATARS() { return RayPickFilter::getBitMask(RayPickFilter::FlagBit::PICK_AVATARS); } - unsigned int PICK_HUD() { return RayPickFilter::getBitMask(RayPickFilter::FlagBit::PICK_HUD); } - unsigned int PICK_BOUNDING_BOX() { return RayPickFilter::getBitMask(RayPickFilter::FlagBit::PICK_COURSE); } - unsigned int PICK_INCLUDE_INVISIBLE() { return RayPickFilter::getBitMask(RayPickFilter::FlagBit::PICK_INCLUDE_INVISIBLE); } - unsigned int PICK_INCLUDE_NONCOLLIDABLE() { return RayPickFilter::getBitMask(RayPickFilter::FlagBit::PICK_INCLUDE_NONCOLLIDABLE); } - unsigned int PICK_ALL_INTERSECTIONS() { return RayPickFilter::getBitMask(RayPickFilter::FlagBit::PICK_ALL_INTERSECTIONS); } - unsigned int INTERSECTED_NONE() { return IntersectionType::NONE; } - unsigned int INTERSECTED_ENTITY() { return IntersectionType::ENTITY; } - unsigned int INTERSECTED_OVERLAY() { return IntersectionType::OVERLAY; } - unsigned int INTERSECTED_AVATAR() { return IntersectionType::AVATAR; } - unsigned int INTERSECTED_HUD() { return IntersectionType::HUD; } - }; #endif // hifi_RayPickManager_h \ No newline at end of file diff --git a/interface/src/raypick/RayPickScriptingInterface.cpp b/interface/src/raypick/RayPickScriptingInterface.cpp new file mode 100644 index 0000000000..aa1613d696 --- /dev/null +++ b/interface/src/raypick/RayPickScriptingInterface.cpp @@ -0,0 +1,107 @@ +// +// RayPickScriptingInterface.cpp +// interface/src/raypick +// +// Created by Sam Gondelman 8/15/2017 +// Copyright 2017 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include "RayPickScriptingInterface.h" + +#include +#include "GLMHelpers.h" +#include "Application.h" + +QUuid RayPickScriptingInterface::createRayPick(const QVariant& properties) { + QVariantMap propMap = properties.toMap(); + + bool enabled = false; + if (propMap["enabled"].isValid()) { + enabled = propMap["enabled"].toBool(); + } + + RayPickFilter filter = RayPickFilter(); + if (propMap["filter"].isValid()) { + filter = RayPickFilter(propMap["filter"].toUInt()); + } + + float maxDistance = 0.0f; + if (propMap["maxDistance"].isValid()) { + maxDistance = propMap["maxDistance"].toFloat(); + } + + if (propMap["joint"].isValid()) { + std::string jointName = propMap["joint"].toString().toStdString(); + + if (jointName != "Mouse") { + // x = upward, y = forward, z = lateral + glm::vec3 posOffset = Vectors::ZERO; + if (propMap["posOffset"].isValid()) { + posOffset = vec3FromVariant(propMap["posOffset"]); + } + + glm::vec3 dirOffset = Vectors::UP; + if (propMap["dirOffset"].isValid()) { + dirOffset = vec3FromVariant(propMap["dirOffset"]); + } + + return qApp->getRayPickManager().createRayPick(jointName, posOffset, dirOffset, filter, maxDistance, enabled); + } else { + return qApp->getRayPickManager().createRayPick(filter, maxDistance, enabled); + } + } else if (propMap["position"].isValid()) { + glm::vec3 position = vec3FromVariant(propMap["position"]); + + glm::vec3 direction = -Vectors::UP; + if (propMap["direction"].isValid()) { + direction = vec3FromVariant(propMap["direction"]); + } + + return qApp->getRayPickManager().createRayPick(position, direction, filter, maxDistance, enabled); + } + + return QUuid(); +} + +void RayPickScriptingInterface::enableRayPick(QUuid uid) { + qApp->getRayPickManager().enableRayPick(uid); +} + +void RayPickScriptingInterface::disableRayPick(QUuid uid) { + qApp->getRayPickManager().disableRayPick(uid); +} + +void RayPickScriptingInterface::removeRayPick(QUuid uid) { + qApp->getRayPickManager().removeRayPick(uid); +} + +RayPickResult RayPickScriptingInterface::getPrevRayPickResult(QUuid uid) { + return qApp->getRayPickManager().getPrevRayPickResult(uid); +} + +void RayPickScriptingInterface::setIgnoreEntities(QUuid uid, const QScriptValue& ignoreEntities) { + qApp->getRayPickManager().setIgnoreEntities(uid, ignoreEntities); +} + +void RayPickScriptingInterface::setIncludeEntities(QUuid uid, const QScriptValue& includeEntities) { + qApp->getRayPickManager().setIncludeEntities(uid, includeEntities); +} + +void RayPickScriptingInterface::setIgnoreOverlays(QUuid uid, const QScriptValue& ignoreOverlays) { + qApp->getRayPickManager().setIgnoreOverlays(uid, ignoreOverlays); +} + +void RayPickScriptingInterface::setIncludeOverlays(QUuid uid, const QScriptValue& includeOverlays) { + qApp->getRayPickManager().setIncludeOverlays(uid, includeOverlays); +} + +void RayPickScriptingInterface::setIgnoreAvatars(QUuid uid, const QScriptValue& ignoreAvatars) { + qApp->getRayPickManager().setIgnoreAvatars(uid, ignoreAvatars); +} + +void RayPickScriptingInterface::setIncludeAvatars(QUuid uid, const QScriptValue& includeAvatars) { + qApp->getRayPickManager().setIncludeAvatars(uid, includeAvatars); +} \ No newline at end of file diff --git a/interface/src/raypick/RayPickScriptingInterface.h b/interface/src/raypick/RayPickScriptingInterface.h new file mode 100644 index 0000000000..e576b5d076 --- /dev/null +++ b/interface/src/raypick/RayPickScriptingInterface.h @@ -0,0 +1,70 @@ +// +// RayPickScriptingInterface.h +// interface/src/raypick +// +// Created by Sam Gondelman 8/15/2017 +// Copyright 2017 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// +#ifndef hifi_RayPickScriptingInterface_h +#define hifi_RayPickScriptingInterface_h + +#include + +#include "RegisteredMetaTypes.h" +#include "DependencyManager.h" + +#include "RayPick.h" + +class RayPickScriptingInterface : public QObject, public Dependency { + Q_OBJECT + Q_PROPERTY(unsigned int PICK_NOTHING READ PICK_NOTHING CONSTANT) + Q_PROPERTY(unsigned int PICK_ENTITIES READ PICK_ENTITIES CONSTANT) + Q_PROPERTY(unsigned int PICK_OVERLAYS READ PICK_OVERLAYS CONSTANT) + Q_PROPERTY(unsigned int PICK_AVATARS READ PICK_AVATARS CONSTANT) + Q_PROPERTY(unsigned int PICK_HUD READ PICK_HUD CONSTANT) + Q_PROPERTY(unsigned int PICK_COURSE READ PICK_COURSE CONSTANT) + Q_PROPERTY(unsigned int PICK_INCLUDE_INVISIBLE READ PICK_INCLUDE_INVISIBLE CONSTANT) + Q_PROPERTY(unsigned int PICK_INCLUDE_NONCOLLIDABLE READ PICK_INCLUDE_NONCOLLIDABLE CONSTANT) + Q_PROPERTY(unsigned int PICK_ALL_INTERSECTIONS READ PICK_ALL_INTERSECTIONS CONSTANT) + Q_PROPERTY(unsigned int INTERSECTED_NONE READ INTERSECTED_NONE CONSTANT) + Q_PROPERTY(unsigned int INTERSECTED_ENTITY READ INTERSECTED_ENTITY CONSTANT) + Q_PROPERTY(unsigned int INTERSECTED_OVERLAY READ INTERSECTED_OVERLAY CONSTANT) + Q_PROPERTY(unsigned int INTERSECTED_AVATAR READ INTERSECTED_AVATAR CONSTANT) + Q_PROPERTY(unsigned int INTERSECTED_HUD READ INTERSECTED_HUD CONSTANT) + SINGLETON_DEPENDENCY + +public slots: + Q_INVOKABLE QUuid createRayPick(const QVariant& properties); + Q_INVOKABLE void enableRayPick(QUuid uid); + Q_INVOKABLE void disableRayPick(QUuid uid); + Q_INVOKABLE void removeRayPick(QUuid uid); + Q_INVOKABLE RayPickResult getPrevRayPickResult(QUuid uid); + + Q_INVOKABLE void setIgnoreEntities(QUuid uid, const QScriptValue& ignoreEntities); + Q_INVOKABLE void setIncludeEntities(QUuid uid, const QScriptValue& includeEntities); + Q_INVOKABLE void setIgnoreOverlays(QUuid uid, const QScriptValue& ignoreOverlays); + Q_INVOKABLE void setIncludeOverlays(QUuid uid, const QScriptValue& includeOverlays); + Q_INVOKABLE void setIgnoreAvatars(QUuid uid, const QScriptValue& ignoreAvatars); + Q_INVOKABLE void setIncludeAvatars(QUuid uid, const QScriptValue& includeAvatars); + +private: + unsigned int PICK_NOTHING() { return RayPickFilter::getBitMask(RayPickFilter::FlagBit::PICK_NOTHING); } + unsigned int PICK_ENTITIES() { return RayPickFilter::getBitMask(RayPickFilter::FlagBit::PICK_ENTITIES); } + unsigned int PICK_OVERLAYS() { return RayPickFilter::getBitMask(RayPickFilter::FlagBit::PICK_OVERLAYS); } + unsigned int PICK_AVATARS() { return RayPickFilter::getBitMask(RayPickFilter::FlagBit::PICK_AVATARS); } + unsigned int PICK_HUD() { return RayPickFilter::getBitMask(RayPickFilter::FlagBit::PICK_HUD); } + unsigned int PICK_COURSE() { return RayPickFilter::getBitMask(RayPickFilter::FlagBit::PICK_COURSE); } + unsigned int PICK_INCLUDE_INVISIBLE() { return RayPickFilter::getBitMask(RayPickFilter::FlagBit::PICK_INCLUDE_INVISIBLE); } + unsigned int PICK_INCLUDE_NONCOLLIDABLE() { return RayPickFilter::getBitMask(RayPickFilter::FlagBit::PICK_INCLUDE_NONCOLLIDABLE); } + unsigned int PICK_ALL_INTERSECTIONS() { return RayPickFilter::getBitMask(RayPickFilter::FlagBit::PICK_ALL_INTERSECTIONS); } + unsigned int INTERSECTED_NONE() { return IntersectionType::NONE; } + unsigned int INTERSECTED_ENTITY() { return IntersectionType::ENTITY; } + unsigned int INTERSECTED_OVERLAY() { return IntersectionType::OVERLAY; } + unsigned int INTERSECTED_AVATAR() { return IntersectionType::AVATAR; } + unsigned int INTERSECTED_HUD() { return IntersectionType::HUD; } +}; + +#endif // hifi_RayPickScriptingInterface_h