separate raypickscriptinginterface, cleanup

This commit is contained in:
SamGondelman 2017-08-15 13:36:41 -07:00
parent f058781f49
commit 9bb7e66859
12 changed files with 240 additions and 132 deletions

View file

@ -193,8 +193,9 @@
#include <src/scripting/LimitlessVoiceRecognitionScriptingInterface.h> #include <src/scripting/LimitlessVoiceRecognitionScriptingInterface.h>
#include <EntityScriptClient.h> #include <EntityScriptClient.h>
#include <ModelScriptingInterface.h> #include <ModelScriptingInterface.h>
#include <raypick/RayPickScriptingInterface.h>
#include <raypick/LaserPointerScriptingInterface.h> #include <raypick/LaserPointerScriptingInterface.h>
#include <raypick/RayPickManager.h>
#include "commerce/Ledger.h" #include "commerce/Ledger.h"
#include "commerce/Wallet.h" #include "commerce/Wallet.h"
@ -608,7 +609,7 @@ bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) {
DependencyManager::set<Wallet>(); DependencyManager::set<Wallet>();
DependencyManager::set<LaserPointerScriptingInterface>(); DependencyManager::set<LaserPointerScriptingInterface>();
DependencyManager::set<RayPickManager>(); DependencyManager::set<RayPickScriptingInterface>();
return previousSessionCrashed; return previousSessionCrashed;
} }
@ -5096,8 +5097,8 @@ void Application::update(float deltaTime) {
} }
{ {
PROFILE_RANGE(app, "RayPick"); PROFILE_RANGE(app, "RayPickManager");
DependencyManager::get<RayPickManager>()->update(); _rayPickManager.update();
} }
{ {
@ -5965,6 +5966,8 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri
scriptEngine->registerGlobalObject("AudioScope", DependencyManager::get<AudioScope>().data()); scriptEngine->registerGlobalObject("AudioScope", DependencyManager::get<AudioScope>().data());
scriptEngine->registerGlobalObject("AvatarBookmarks", DependencyManager::get<AvatarBookmarks>().data()); scriptEngine->registerGlobalObject("AvatarBookmarks", DependencyManager::get<AvatarBookmarks>().data());
scriptEngine->registerGlobalObject("LocationBookmarks", DependencyManager::get<LocationBookmarks>().data()); scriptEngine->registerGlobalObject("LocationBookmarks", DependencyManager::get<LocationBookmarks>().data());
scriptEngine->registerGlobalObject("RayPick", DependencyManager::get<RayPickScriptingInterface>().data());
scriptEngine->registerGlobalObject("LaserPointers", DependencyManager::get<LaserPointerScriptingInterface>().data()); scriptEngine->registerGlobalObject("LaserPointers", DependencyManager::get<LaserPointerScriptingInterface>().data());
// Caches // Caches
@ -6019,8 +6022,6 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri
scriptEngine->registerGlobalObject("AvatarInputs", AvatarInputs::getInstance()); scriptEngine->registerGlobalObject("AvatarInputs", AvatarInputs::getInstance());
scriptEngine->registerGlobalObject("ContextOverlay", DependencyManager::get<ContextOverlayInterface>().data()); scriptEngine->registerGlobalObject("ContextOverlay", DependencyManager::get<ContextOverlayInterface>().data());
scriptEngine->registerGlobalObject("RayPick", DependencyManager::get<RayPickManager>().data());
qScriptRegisterMetaType(scriptEngine, OverlayIDtoScriptValue, OverlayIDfromScriptValue); qScriptRegisterMetaType(scriptEngine, OverlayIDtoScriptValue, OverlayIDfromScriptValue);
// connect this script engines printedMessage signal to the global ScriptEngines these various messages // connect this script engines printedMessage signal to the global ScriptEngines these various messages

View file

@ -70,6 +70,8 @@
#include "ui/OverlayConductor.h" #include "ui/OverlayConductor.h"
#include "ui/overlays/Overlays.h" #include "ui/overlays/Overlays.h"
#include "UndoStackScriptingInterface.h" #include "UndoStackScriptingInterface.h"
#include "raypick/RayPickManager.h"
#include "raypick/LaserPointerManager.h" #include "raypick/LaserPointerManager.h"
#include <procedural/ProceduralSkybox.h> #include <procedural/ProceduralSkybox.h>
@ -303,6 +305,7 @@ public:
bool getSaveAvatarOverrideUrl() { return _saveAvatarOverrideUrl; } bool getSaveAvatarOverrideUrl() { return _saveAvatarOverrideUrl; }
LaserPointerManager& getLaserPointerManager() { return _laserPointerManager; } LaserPointerManager& getLaserPointerManager() { return _laserPointerManager; }
RayPickManager& getRayPickManager() { return _rayPickManager; }
signals: signals:
void svoImportRequested(const QString& url); void svoImportRequested(const QString& url);
@ -702,6 +705,7 @@ private:
bool _saveAvatarOverrideUrl { false }; bool _saveAvatarOverrideUrl { false };
LaserPointerManager _laserPointerManager; LaserPointerManager _laserPointerManager;
RayPickManager _rayPickManager;
}; };
#endif // hifi_Application_h #endif // hifi_Application_h

View file

@ -11,9 +11,10 @@
#include "LaserPointer.h" #include "LaserPointer.h"
#include "Application.h" #include "Application.h"
#include "ui/overlays/Overlay.h"
#include "avatar/AvatarManager.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) : const bool faceAvatar, const bool centerEndY, const bool lockEnd, const bool enabled) :
_renderingEnabled(enabled), _renderingEnabled(enabled),
_renderStates(renderStates), _renderStates(renderStates),
@ -22,7 +23,7 @@ LaserPointer::LaserPointer(const QVariantMap& rayProps, const RenderStateMap& re
_centerEndY(centerEndY), _centerEndY(centerEndY),
_lockEnd(lockEnd) _lockEnd(lockEnd)
{ {
_rayPickUID = DependencyManager::get<RayPickManager>()->createRayPick(rayProps); _rayPickUID = DependencyManager::get<RayPickScriptingInterface>()->createRayPick(rayProps);
for (auto& state : _renderStates) { for (auto& state : _renderStates) {
if (!enabled || state.first != _currentRenderState) { if (!enabled || state.first != _currentRenderState) {
@ -37,7 +38,7 @@ LaserPointer::LaserPointer(const QVariantMap& rayProps, const RenderStateMap& re
} }
LaserPointer::~LaserPointer() { LaserPointer::~LaserPointer() {
DependencyManager::get<RayPickManager>()->removeRayPick(_rayPickUID); DependencyManager::get<RayPickScriptingInterface>()->removeRayPick(_rayPickUID);
for (auto& renderState : _renderStates) { for (auto& renderState : _renderStates) {
renderState.second.deleteOverlays(); renderState.second.deleteOverlays();
@ -48,12 +49,12 @@ LaserPointer::~LaserPointer() {
} }
void LaserPointer::enable() { void LaserPointer::enable() {
DependencyManager::get<RayPickManager>()->enableRayPick(_rayPickUID); DependencyManager::get<RayPickScriptingInterface>()->enableRayPick(_rayPickUID);
_renderingEnabled = true; _renderingEnabled = true;
} }
void LaserPointer::disable() { void LaserPointer::disable() {
DependencyManager::get<RayPickManager>()->disableRayPick(_rayPickUID); DependencyManager::get<RayPickScriptingInterface>()->disableRayPick(_rayPickUID);
_renderingEnabled = false; _renderingEnabled = false;
if (!_currentRenderState.empty()) { if (!_currentRenderState.empty()) {
if (_renderStates.find(_currentRenderState) != _renderStates.end()) { 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) { void LaserPointer::updateRenderState(const RenderState& renderState, const IntersectionType type, const float distance, const QUuid& objectID, const bool defaultState) {
PickRay pickRay = DependencyManager::get<RayPickManager>()->getPickRay(_rayPickUID); PickRay pickRay = qApp->getRayPickManager().getPickRay(_rayPickUID);
if (!renderState.getStartID().isNull()) { if (!renderState.getStartID().isNull()) {
QVariantMap startProps; QVariantMap startProps;
startProps.insert("position", vec3toVariant(pickRay.origin)); startProps.insert("position", vec3toVariant(pickRay.origin));
@ -180,7 +181,7 @@ void LaserPointer::disableRenderState(const RenderState& renderState) {
} }
void LaserPointer::update() { void LaserPointer::update() {
RayPickResult prevRayPickResult = DependencyManager::get<RayPickManager>()->getPrevRayPickResult(_rayPickUID); RayPickResult prevRayPickResult = DependencyManager::get<RayPickScriptingInterface>()->getPrevRayPickResult(_rayPickUID);
if (_renderingEnabled && !_currentRenderState.empty() && _renderStates.find(_currentRenderState) != _renderStates.end() && prevRayPickResult.type != IntersectionType::NONE) { if (_renderingEnabled && !_currentRenderState.empty() && _renderStates.find(_currentRenderState) != _renderStates.end() && prevRayPickResult.type != IntersectionType::NONE) {
updateRenderState(_renderStates[_currentRenderState], prevRayPickResult.type, prevRayPickResult.distance, prevRayPickResult.objectID, false); updateRenderState(_renderStates[_currentRenderState], prevRayPickResult.type, prevRayPickResult.distance, prevRayPickResult.objectID, false);
disableRenderState(_defaultRenderStates[_currentRenderState].second); disableRenderState(_defaultRenderStates[_currentRenderState].second);

View file

@ -13,10 +13,9 @@
#include <QString> #include <QString>
#include "glm/glm.hpp" #include "glm/glm.hpp"
#include "ui/overlays/Overlay.h"
#include <DependencyManager.h> #include <DependencyManager.h>
#include "RayPickManager.h" #include "raypick/RayPickScriptingInterface.h"
class RayPickResult; class RayPickResult;
@ -52,25 +51,25 @@ public:
typedef std::unordered_map<std::string, RenderState> RenderStateMap; typedef std::unordered_map<std::string, RenderState> RenderStateMap;
typedef std::unordered_map<std::string, std::pair<float, RenderState>> DefaultRenderStateMap; typedef std::unordered_map<std::string, std::pair<float, RenderState>> 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); const bool faceAvatar, const bool centerEndY, const bool lockEnd, const bool enabled);
~LaserPointer(); ~LaserPointer();
QUuid getRayUID() { return _rayPickUID; } QUuid getRayUID() { return _rayPickUID; }
void enable(); void enable();
void disable(); void disable();
const RayPickResult getPrevRayPickResult() { return DependencyManager::get<RayPickManager>()->getPrevRayPickResult(_rayPickUID); } const RayPickResult getPrevRayPickResult() { return DependencyManager::get<RayPickScriptingInterface>()->getPrevRayPickResult(_rayPickUID); }
void setRenderState(const std::string& state); 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. // 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 editRenderState(const std::string& state, const QVariant& startProps, const QVariant& pathProps, const QVariant& endProps);
void setIgnoreEntities(const QScriptValue& ignoreEntities) { DependencyManager::get<RayPickManager>()->setIgnoreEntities(_rayPickUID, ignoreEntities); } void setIgnoreEntities(const QScriptValue& ignoreEntities) { DependencyManager::get<RayPickScriptingInterface>()->setIgnoreEntities(_rayPickUID, ignoreEntities); }
void setIncludeEntities(const QScriptValue& includeEntities) { DependencyManager::get<RayPickManager>()->setIncludeEntities(_rayPickUID, includeEntities); } void setIncludeEntities(const QScriptValue& includeEntities) { DependencyManager::get<RayPickScriptingInterface>()->setIncludeEntities(_rayPickUID, includeEntities); }
void setIgnoreOverlays(const QScriptValue& ignoreOverlays) { DependencyManager::get<RayPickManager>()->setIgnoreOverlays(_rayPickUID, ignoreOverlays); } void setIgnoreOverlays(const QScriptValue& ignoreOverlays) { DependencyManager::get<RayPickScriptingInterface>()->setIgnoreOverlays(_rayPickUID, ignoreOverlays); }
void setIncludeOverlays(const QScriptValue& includeOverlays) { DependencyManager::get<RayPickManager>()->setIncludeOverlays(_rayPickUID, includeOverlays); } void setIncludeOverlays(const QScriptValue& includeOverlays) { DependencyManager::get<RayPickScriptingInterface>()->setIncludeOverlays(_rayPickUID, includeOverlays); }
void setIgnoreAvatars(const QScriptValue& ignoreAvatars) { DependencyManager::get<RayPickManager>()->setIgnoreAvatars(_rayPickUID, ignoreAvatars); } void setIgnoreAvatars(const QScriptValue& ignoreAvatars) { DependencyManager::get<RayPickScriptingInterface>()->setIgnoreAvatars(_rayPickUID, ignoreAvatars); }
void setIncludeAvatars(const QScriptValue& includeAvatars) { DependencyManager::get<RayPickManager>()->setIncludeAvatars(_rayPickUID, includeAvatars); } void setIncludeAvatars(const QScriptValue& includeAvatars) { DependencyManager::get<RayPickScriptingInterface>()->setIncludeAvatars(_rayPickUID, includeAvatars); }
void setLockEndUUID(QUuid objectID, const bool isOverlay) { _objectLockEnd = std::pair<QUuid, bool>(objectID, isOverlay); } void setLockEndUUID(QUuid objectID, const bool isOverlay) { _objectLockEnd = std::pair<QUuid, bool>(objectID, isOverlay); }

View file

@ -9,9 +9,8 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
#include "LaserPointerManager.h" #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) { const bool faceAvatar, const bool centerEndY, const bool lockEnd, const bool enabled) {
std::shared_ptr<LaserPointer> laserPointer = std::make_shared<LaserPointer>(rayProps, renderStates, defaultRenderStates, faceAvatar, centerEndY, lockEnd, enabled); std::shared_ptr<LaserPointer> laserPointer = std::make_shared<LaserPointer>(rayProps, renderStates, defaultRenderStates, faceAvatar, centerEndY, lockEnd, enabled);
if (!laserPointer->getRayUID().isNull()) { if (!laserPointer->getRayUID().isNull()) {

View file

@ -22,7 +22,7 @@ class RayPickResult;
class LaserPointerManager { class LaserPointerManager {
public: 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); const bool faceAvatar, const bool centerEndY, const bool lockEnd, const bool enabled);
void removeLaserPointer(const QUuid uid); void removeLaserPointer(const QUuid uid);
void enableLaserPointer(const QUuid uid); void enableLaserPointer(const QUuid uid);

View file

@ -12,11 +12,8 @@
#include "LaserPointerScriptingInterface.h" #include "LaserPointerScriptingInterface.h"
#include <QVariant> #include <QVariant>
#include "RegisteredMetaTypes.h"
#include "GLMHelpers.h" #include "GLMHelpers.h"
#include "Application.h"
QUuid LaserPointerScriptingInterface::createLaserPointer(const QVariant& properties) { QUuid LaserPointerScriptingInterface::createLaserPointer(const QVariant& properties) {
QVariantMap propertyMap = properties.toMap(); 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) { void LaserPointerScriptingInterface::editRenderState(QUuid uid, const QString& renderState, const QVariant& properties) {

View file

@ -13,7 +13,6 @@
#include <QtCore/QObject> #include <QtCore/QObject>
#include "LaserPointerManager.h"
#include "RegisteredMetaTypes.h" #include "RegisteredMetaTypes.h"
#include "DependencyManager.h" #include "DependencyManager.h"
#include "Application.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); } Q_INVOKABLE void setLockEndUUID(QUuid uid, QUuid objectID, const bool isOverlay) { qApp->getLaserPointerManager().setLockEndUUID(uid, objectID, isOverlay); }
private: private:
const RenderState buildRenderState(const QVariantMap & propMap); const RenderState buildRenderState(const QVariantMap& propMap);
}; };

View file

@ -141,62 +141,25 @@ void RayPickManager::update() {
} }
} }
QUuid RayPickManager::createRayPick(const QVariantMap& rayProps) { QUuid RayPickManager::createRayPick(const std::string& jointName, const glm::vec3& posOffset, const glm::vec3& dirOffset, const RayPickFilter& filter, const float maxDistance, const bool enabled) {
bool enabled = false; QWriteLocker lock(&_addLock);
if (rayProps["enabled"].isValid()) { QUuid id = QUuid::createUuid();
enabled = rayProps["enabled"].toBool(); _rayPicksToAdd.push(std::pair<QUuid, std::shared_ptr<RayPick>>(id, std::make_shared<JointRayPick>(jointName, posOffset, dirOffset, filter, maxDistance, enabled)));
} return id;
}
RayPickFilter filter = RayPickFilter(); QUuid RayPickManager::createRayPick(const RayPickFilter& filter, const float maxDistance, const bool enabled) {
if (rayProps["filter"].isValid()) { QWriteLocker lock(&_addLock);
filter = RayPickFilter(rayProps["filter"].toUInt()); QUuid id = QUuid::createUuid();
} _rayPicksToAdd.push(std::pair<QUuid, std::shared_ptr<RayPick>>(id, std::make_shared<MouseRayPick>(filter, maxDistance, enabled)));
return id;
}
float maxDistance = 0.0f; QUuid RayPickManager::createRayPick(const glm::vec3& position, const glm::vec3& direction, const RayPickFilter& filter, const float maxDistance, const bool enabled) {
if (rayProps["maxDistance"].isValid()) { QWriteLocker lock(&_addLock);
maxDistance = rayProps["maxDistance"].toFloat(); QUuid id = QUuid::createUuid();
} _rayPicksToAdd.push(std::pair<QUuid, std::shared_ptr<RayPick>>(id, std::make_shared<StaticRayPick>(position, direction, filter, maxDistance, enabled)));
return id;
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<QUuid, std::shared_ptr<RayPick>>(id, std::make_shared<JointRayPick>(jointName, posOffset, dirOffset, filter, maxDistance, enabled)));
return id;
} else {
QWriteLocker lock(&_addLock);
QUuid id = QUuid::createUuid();
_rayPicksToAdd.push(std::pair<QUuid, std::shared_ptr<RayPick>>(id, std::make_shared<MouseRayPick>(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<QUuid, std::shared_ptr<RayPick>>(id, std::make_shared<StaticRayPick>(position, direction, filter, maxDistance, enabled)));
return id;
}
return QUuid();
} }
void RayPickManager::removeRayPick(const QUuid uid) { void RayPickManager::removeRayPick(const QUuid uid) {

View file

@ -18,48 +18,32 @@
#include <QReadWriteLock> #include <QReadWriteLock>
#include "RegisteredMetaTypes.h" #include "RegisteredMetaTypes.h"
#include "DependencyManager.h"
#include <unordered_map> #include <unordered_map>
#include <queue> #include <queue>
class RayPickResult; class RayPickResult;
class RayPickManager : public QObject, public Dependency { class RayPickManager {
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
public: public:
void update(); void update();
const PickRay getPickRay(const QUuid uid); const PickRay getPickRay(const QUuid uid);
public slots: QUuid createRayPick(const std::string& jointName, const glm::vec3& posOffset, const glm::vec3& dirOffset, const RayPickFilter& filter, const float maxDistance, const bool enabled);
Q_INVOKABLE QUuid createRayPick(const QVariantMap& rayProps); QUuid createRayPick(const RayPickFilter& filter, const float maxDistance, const bool enabled);
Q_INVOKABLE void removeRayPick(const QUuid uid); QUuid createRayPick(const glm::vec3& position, const glm::vec3& direction, const RayPickFilter& filter, const float maxDistance, const bool enabled);
Q_INVOKABLE void enableRayPick(const QUuid uid); void removeRayPick(const QUuid uid);
Q_INVOKABLE void disableRayPick(const QUuid uid); void enableRayPick(const QUuid uid);
Q_INVOKABLE const RayPickResult getPrevRayPickResult(const QUuid uid); void disableRayPick(const QUuid uid);
const RayPickResult getPrevRayPickResult(const QUuid uid);
Q_INVOKABLE void setIgnoreEntities(QUuid uid, const QScriptValue& ignoreEntities); void setIgnoreEntities(QUuid uid, const QScriptValue& ignoreEntities);
Q_INVOKABLE void setIncludeEntities(QUuid uid, const QScriptValue& includeEntities); void setIncludeEntities(QUuid uid, const QScriptValue& includeEntities);
Q_INVOKABLE void setIgnoreOverlays(QUuid uid, const QScriptValue& ignoreOverlays); void setIgnoreOverlays(QUuid uid, const QScriptValue& ignoreOverlays);
Q_INVOKABLE void setIncludeOverlays(QUuid uid, const QScriptValue& includeOverlays); void setIncludeOverlays(QUuid uid, const QScriptValue& includeOverlays);
Q_INVOKABLE void setIgnoreAvatars(QUuid uid, const QScriptValue& ignoreAvatars); void setIgnoreAvatars(QUuid uid, const QScriptValue& ignoreAvatars);
Q_INVOKABLE void setIncludeAvatars(QUuid uid, const QScriptValue& includeAvatars); void setIncludeAvatars(QUuid uid, const QScriptValue& includeAvatars);
private: private:
QHash<QUuid, std::shared_ptr<RayPick>> _rayPicks; QHash<QUuid, std::shared_ptr<RayPick>> _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 // Returns true if this ray exists in the cache, and if it does, update res if the cached result is closer
bool checkAndCompareCachedResults(QPair<glm::vec3, glm::vec3>& ray, RayPickCache& cache, RayPickResult& res, const RayPickFilter::Flags& mask); bool checkAndCompareCachedResults(QPair<glm::vec3, glm::vec3>& ray, RayPickCache& cache, RayPickResult& res, const RayPickFilter::Flags& mask);
void cacheResult(const bool intersects, const RayPickResult& resTemp, const RayPickFilter::Flags& mask, RayPickResult& res, QPair<glm::vec3, glm::vec3>& ray, RayPickCache& cache); void cacheResult(const bool intersects, const RayPickResult& resTemp, const RayPickFilter::Flags& mask, RayPickResult& res, QPair<glm::vec3, glm::vec3>& 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 #endif // hifi_RayPickManager_h

View file

@ -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 <QVariant>
#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);
}

View file

@ -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 <QtCore/QObject>
#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