diff --git a/interface/src/raypick/LaserPointer.cpp b/interface/src/raypick/LaserPointer.cpp index b190539607..028b266009 100644 --- a/interface/src/raypick/LaserPointer.cpp +++ b/interface/src/raypick/LaserPointer.cpp @@ -13,7 +13,12 @@ #include "RayPickManager.h" #include "JointRayPick.h" -LaserPointer::LaserPointer(const QString& jointName, const glm::vec3& posOffset, const glm::vec3& dirOffset, const uint16_t filter, const float maxDistance, const bool enabled) +#include "Application.h" + +LaserPointer::LaserPointer(const QString& jointName, const glm::vec3& posOffset, const glm::vec3& dirOffset, const uint16_t filter, const float maxDistance, + const QHash& renderStates, const bool enabled) : + _renderingEnabled(enabled), + _renderStates(renderStates) { _rayPickUID = RayPickManager::getInstance().addRayPick(std::make_shared(jointName, posOffset, dirOffset, filter, maxDistance, enabled)); } @@ -24,16 +29,26 @@ LaserPointer::~LaserPointer() { void LaserPointer::enable() { RayPickManager::getInstance().enableRayPick(_rayPickUID); - // TODO: - // turn on rendering + _renderingEnabled = true; } void LaserPointer::disable() { RayPickManager::getInstance().disableRayPick(_rayPickUID); - // TODO: - // turn off rendering + _renderingEnabled = false; } const RayPickResult& LaserPointer::getPrevRayPickResult() { return RayPickManager::getInstance().getPrevRayPickResult(_rayPickUID); -} \ No newline at end of file +} + +void LaserPointer::render(RenderArgs* args) { + if (_renderingEnabled && !_currentRenderState.isEmpty() && _renderStates.contains(_currentRenderState)) { + _renderStates[_currentRenderState].render(args); + } +} + +void RenderState::render(RenderArgs * args) { + if (!_startID.isNull()) qApp->getOverlays().getOverlay(_startID)->render(args); + if (!_pathID.isNull()) qApp->getOverlays().getOverlay(_pathID)->render(args); + if (!_endID.isNull()) qApp->getOverlays().getOverlay(_endID)->render(args); +} diff --git a/interface/src/raypick/LaserPointer.h b/interface/src/raypick/LaserPointer.h index a65c6a9748..f970668bf1 100644 --- a/interface/src/raypick/LaserPointer.h +++ b/interface/src/raypick/LaserPointer.h @@ -13,25 +13,49 @@ #include #include "glm/glm.hpp" +#include +#include "ui/overlays/Overlay.h" class RayPickResult; +class RenderState { + +public: + RenderState() {} + RenderState(const OverlayID& startID, const OverlayID& pathID, const OverlayID& endID) : + _startID(startID), _pathID(pathID), _endID(endID) {} + + void render(RenderArgs* args); + +private: + OverlayID _startID; + OverlayID _pathID; + OverlayID _endID; +}; + + class LaserPointer { public: - LaserPointer(const QString& jointName, const glm::vec3& posOffset, const glm::vec3& dirOffset, const uint16_t filter, const float maxDistance, bool enabled); + LaserPointer(const QString& jointName, const glm::vec3& posOffset, const glm::vec3& dirOffset, const uint16_t filter, const float maxDistance, + const QHash& renderStates, const bool enabled); ~LaserPointer(); unsigned int getUID() { return _rayPickUID; } void enable(); void disable(); - // void setRenderState(const QString& stateName); - // void setRenderStateProperties(const QHash& renderStateProperties); + void setRenderState(const QString& state) { _currentRenderState = state; } const RayPickResult& getPrevRayPickResult(); + void render(RenderArgs* args); + const render::ShapeKey getShapeKey() { return render::ShapeKey::Builder::ownPipeline(); } + private: + bool _renderingEnabled; + QString _currentRenderState { "" }; + QHash _renderStates; unsigned int _rayPickUID; }; diff --git a/interface/src/raypick/LaserPointerManager.cpp b/interface/src/raypick/LaserPointerManager.cpp index 2e7b084d73..86affdb3b4 100644 --- a/interface/src/raypick/LaserPointerManager.cpp +++ b/interface/src/raypick/LaserPointerManager.cpp @@ -17,8 +17,9 @@ LaserPointerManager& LaserPointerManager::getInstance() { return instance; } -unsigned int LaserPointerManager::createLaserPointer(const QString& jointName, const glm::vec3& posOffset, const glm::vec3& dirOffset, const uint16_t filter, const float maxDistance, bool enabled) { - std::shared_ptr laserPointer = std::make_shared(jointName, posOffset, dirOffset, filter, maxDistance, enabled); +unsigned int LaserPointerManager::createLaserPointer(const QString& jointName, const glm::vec3& posOffset, const glm::vec3& dirOffset, const uint16_t filter, const float maxDistance, + const QHash& renderStates, const bool enabled) { + std::shared_ptr laserPointer = std::make_shared(jointName, posOffset, dirOffset, filter, maxDistance, renderStates, enabled); unsigned int uid = laserPointer->getUID(); _laserPointers[uid] = laserPointer; return uid; diff --git a/interface/src/raypick/LaserPointerManager.h b/interface/src/raypick/LaserPointerManager.h index f8b3ae1a26..2abe909c01 100644 --- a/interface/src/raypick/LaserPointerManager.h +++ b/interface/src/raypick/LaserPointerManager.h @@ -16,7 +16,8 @@ #include #include -class LaserPointer; +#include "LaserPointer.h" + class RayPickResult; class LaserPointerManager { @@ -24,7 +25,8 @@ class LaserPointerManager { public: static LaserPointerManager& getInstance(); - unsigned int createLaserPointer(const QString& jointName, const glm::vec3& posOffset, const glm::vec3& dirOffset, const uint16_t filter, const float maxDistance, bool enabled); + unsigned int createLaserPointer(const QString& jointName, const glm::vec3& posOffset, const glm::vec3& dirOffset, const uint16_t filter, const float maxDistance, + const QHash& renderStates, const bool enabled); void removeLaserPointer(const unsigned int uid) { _laserPointers.remove(uid); } void enableLaserPointer(const unsigned int uid); void disableLaserPointer(const unsigned int uid); diff --git a/interface/src/raypick/LaserPointerScriptingInterface.cpp b/interface/src/raypick/LaserPointerScriptingInterface.cpp index 68f8423d73..a9c096c554 100644 --- a/interface/src/raypick/LaserPointerScriptingInterface.cpp +++ b/interface/src/raypick/LaserPointerScriptingInterface.cpp @@ -15,6 +15,8 @@ #include "RegisteredMetaTypes.h" #include "GLMHelpers.h" +#include "Application.h" + LaserPointerScriptingInterface* LaserPointerScriptingInterface::getInstance() { static LaserPointerScriptingInterface instance; return &instance; @@ -52,10 +54,46 @@ uint32_t LaserPointerScriptingInterface::createLaserPointer(const QVariant& prop enabled = propertyMap["enabled"].toBool(); } - // TODO: - // handle render state properties + QHash renderStates; + if (propertyMap["renderStates"].isValid()) { + QList renderStateVariants = propertyMap["renderStates"].toList(); + for (QVariant& renderStateVariant : renderStateVariants) { + if (renderStateVariant.isValid()) { + QVariantMap renderStateMap = renderStateVariant.toMap(); + if (renderStateMap["name"].isValid()) { + QString name = renderStateMap["name"].toString(); - return LaserPointerManager::getInstance().createLaserPointer(jointName, posOffset, dirOffset, filter, maxDistance, enabled); + QUuid startID; + if (renderStateMap["start"].isValid()) { + QVariantMap startMap = renderStateMap["start"].toMap(); + if (startMap["type"].isValid()) { + startID = qApp->getOverlays().addOverlay(startMap["type"].toString(), startMap); + } + } + + QUuid pathID; + if (renderStateMap["path"].isValid()) { + QVariantMap pathMap = renderStateMap["path"].toMap(); + if (pathMap["type"].isValid()) { + pathID = qApp->getOverlays().addOverlay(pathMap["type"].toString(), pathMap); + } + } + + QUuid endID; + if (renderStateMap["end"].isValid()) { + QVariantMap endMap = renderStateMap["end"].toMap(); + if (endMap["type"].isValid()) { + endID = qApp->getOverlays().addOverlay(endMap["type"].toString(), endMap); + } + } + + renderStates[name] = RenderState(startID, pathID, endID); + } + } + } + } + + return LaserPointerManager::getInstance().createLaserPointer(jointName, posOffset, dirOffset, filter, maxDistance, renderStates, enabled); } else { return 0; } diff --git a/interface/src/raypick/RayPickManager.cpp b/interface/src/raypick/RayPickManager.cpp index c84fbfdd20..33dc16874f 100644 --- a/interface/src/raypick/RayPickManager.cpp +++ b/interface/src/raypick/RayPickManager.cpp @@ -49,7 +49,7 @@ void RayPickManager::cacheResult(const bool intersects, const RayPickResult& res void RayPickManager::update() { QHash, QHash> results; - for (auto &rayPick : _rayPicks) { + for (auto& rayPick : _rayPicks) { if (!rayPick->isEnabled() || rayPick->getFilter() == RayPickMask::PICK_NOTHING || rayPick->getMaxDistance() < 0.0f) { continue; }