mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-08 13:59:13 +02:00
expanded RayPick JS API
This commit is contained in:
parent
d156680bc8
commit
c7f0f03fce
8 changed files with 129 additions and 158 deletions
|
@ -10,56 +10,17 @@
|
||||||
//
|
//
|
||||||
#include "LaserPointer.h"
|
#include "LaserPointer.h"
|
||||||
|
|
||||||
#include "JointRayPick.h"
|
|
||||||
#include "StaticRayPick.h"
|
|
||||||
#include "MouseRayPick.h"
|
|
||||||
|
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
#include "avatar/AvatarManager.h"
|
#include "avatar/AvatarManager.h"
|
||||||
|
|
||||||
LaserPointer::LaserPointer(const QString& jointName, const glm::vec3& posOffset, const glm::vec3& dirOffset, const uint16_t filter, const float maxDistance,
|
LaserPointer::LaserPointer(const QVariantMap& rayProps, const QHash<QString, RenderState>& renderStates, const bool faceAvatar, const bool centerEndY, const bool lockEnd, const bool enabled) :
|
||||||
const QHash<QString, RenderState>& renderStates, const bool faceAvatar, const bool centerEndY, const bool lockEnd, const bool enabled) :
|
|
||||||
_renderingEnabled(enabled),
|
_renderingEnabled(enabled),
|
||||||
_renderStates(renderStates),
|
_renderStates(renderStates),
|
||||||
_faceAvatar(faceAvatar),
|
_faceAvatar(faceAvatar),
|
||||||
_centerEndY(centerEndY),
|
_centerEndY(centerEndY),
|
||||||
_lockEnd(lockEnd)
|
_lockEnd(lockEnd)
|
||||||
{
|
{
|
||||||
_rayPickUID = DependencyManager::get<RayPickManager>()->addRayPick(std::make_shared<JointRayPick>(jointName, posOffset, dirOffset, filter, maxDistance, enabled));
|
_rayPickUID = DependencyManager::get<RayPickManager>()->createRayPick(rayProps);
|
||||||
|
|
||||||
for (auto& state : _renderStates.keys()) {
|
|
||||||
if (!enabled || state != _currentRenderState) {
|
|
||||||
disableRenderState(state);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LaserPointer::LaserPointer(const glm::vec3& position, const glm::vec3& direction, const uint16_t filter, const float maxDistance,
|
|
||||||
const QHash<QString, RenderState>& renderStates, const bool faceAvatar, const bool centerEndY, const bool lockEnd, const bool enabled) :
|
|
||||||
_renderingEnabled(enabled),
|
|
||||||
_renderStates(renderStates),
|
|
||||||
_faceAvatar(faceAvatar),
|
|
||||||
_centerEndY(centerEndY),
|
|
||||||
_lockEnd(lockEnd)
|
|
||||||
{
|
|
||||||
_rayPickUID = DependencyManager::get<RayPickManager>()->addRayPick(std::make_shared<StaticRayPick>(position, direction, filter, maxDistance, enabled));
|
|
||||||
|
|
||||||
for (auto& state : _renderStates.keys()) {
|
|
||||||
if (!enabled || state != _currentRenderState) {
|
|
||||||
disableRenderState(state);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LaserPointer::LaserPointer(const uint16_t filter, const float maxDistance, const QHash<QString, RenderState>& renderStates, const bool faceAvatar, const bool centerEndY,
|
|
||||||
const bool lockEnd, const bool enabled) :
|
|
||||||
_renderingEnabled(enabled),
|
|
||||||
_renderStates(renderStates),
|
|
||||||
_faceAvatar(faceAvatar),
|
|
||||||
_centerEndY(centerEndY),
|
|
||||||
_lockEnd(lockEnd)
|
|
||||||
{
|
|
||||||
_rayPickUID = DependencyManager::get<RayPickManager>()->addRayPick(std::make_shared<MouseRayPick>(filter, maxDistance, enabled));
|
|
||||||
|
|
||||||
for (auto& state : _renderStates.keys()) {
|
for (auto& state : _renderStates.keys()) {
|
||||||
if (!enabled || state != _currentRenderState) {
|
if (!enabled || state != _currentRenderState) {
|
||||||
|
|
|
@ -49,15 +49,11 @@ private:
|
||||||
class LaserPointer {
|
class LaserPointer {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
LaserPointer(const QString& jointName, const glm::vec3& posOffset, const glm::vec3& dirOffset, const uint16_t filter, const float maxDistance,
|
LaserPointer::LaserPointer(const QVariantMap& rayProps, const QHash<QString, RenderState>& renderStates, const bool faceAvatar, const bool centerEndY,
|
||||||
const QHash<QString, RenderState>& renderStates, const bool faceAvatar, const bool centerEndY, const bool lockEnd, const bool enabled);
|
const bool lockEnd, const bool enabled);
|
||||||
LaserPointer(const glm::vec3& position, const glm::vec3& direction, const uint16_t filter, const float maxDistance,
|
|
||||||
const QHash<QString, RenderState>& renderStates, const bool faceAvatar, const bool centerEndY, const bool lockEnd, const bool enabled);
|
|
||||||
LaserPointer(const uint16_t filter, const float maxDistance, const QHash<QString, RenderState>& renderStates, const bool faceAvatar,
|
|
||||||
const bool centerEndY, const bool lockEnd, const bool enabled);
|
|
||||||
~LaserPointer();
|
~LaserPointer();
|
||||||
|
|
||||||
unsigned int getUID() { return _rayPickUID; }
|
unsigned int 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<RayPickManager>()->getPrevRayPickResult(_rayPickUID); }
|
||||||
|
|
|
@ -12,44 +12,24 @@
|
||||||
#include "LaserPointer.h"
|
#include "LaserPointer.h"
|
||||||
#include "RayPick.h"
|
#include "RayPick.h"
|
||||||
|
|
||||||
unsigned int LaserPointerManager::createLaserPointer(const QString& jointName, const glm::vec3& posOffset, const glm::vec3& dirOffset, const uint16_t filter, const float maxDistance,
|
unsigned int LaserPointerManager::createLaserPointer(const QVariantMap& rayProps, const QHash<QString, RenderState>& renderStates, const bool faceAvatar, const bool centerEndY,
|
||||||
const QHash<QString, RenderState>& renderStates, const bool faceAvatar, const bool centerEndY, const bool lockEnd, const bool enabled) {
|
const bool lockEnd, const bool enabled) {
|
||||||
std::shared_ptr<LaserPointer> laserPointer = std::make_shared<LaserPointer>(jointName, posOffset, dirOffset, filter, maxDistance, renderStates, faceAvatar, centerEndY, lockEnd, enabled);
|
std::shared_ptr<LaserPointer> laserPointer = std::make_shared<LaserPointer>(rayProps, renderStates, faceAvatar, centerEndY, lockEnd, enabled);
|
||||||
unsigned int uid = laserPointer->getUID();
|
if (laserPointer->getRayUID() != 0) {
|
||||||
QWriteLocker lock(&_lock);
|
QWriteLocker lock(&_addLock);
|
||||||
_laserPointers[uid] = laserPointer;
|
_laserPointersToAdd.enqueue(QPair<unsigned int, std::shared_ptr<LaserPointer>>(_nextUID, laserPointer));
|
||||||
_laserPointerLocks[uid] = std::make_shared<QReadWriteLock>();
|
return _nextUID++;
|
||||||
return uid;
|
}
|
||||||
}
|
return 0;
|
||||||
|
|
||||||
unsigned int LaserPointerManager::createLaserPointer(const glm::vec3& position, const glm::vec3& direction, const uint16_t filter, const float maxDistance,
|
|
||||||
const QHash<QString, RenderState>& renderStates, const bool faceAvatar, const bool centerEndY, const bool lockEnd, const bool enabled) {
|
|
||||||
std::shared_ptr<LaserPointer> laserPointer = std::make_shared<LaserPointer>(position, direction, filter, maxDistance, renderStates, faceAvatar, centerEndY, lockEnd, enabled);
|
|
||||||
unsigned int uid = laserPointer->getUID();
|
|
||||||
QWriteLocker lock(&_lock);
|
|
||||||
_laserPointers[uid] = laserPointer;
|
|
||||||
_laserPointerLocks[uid] = std::make_shared<QReadWriteLock>();
|
|
||||||
return uid;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int LaserPointerManager::createLaserPointer(const uint16_t filter, const float maxDistance, const QHash<QString, RenderState>& renderStates, const bool faceAvatar,
|
|
||||||
const bool centerEndY, const bool lockEnd, const bool enabled) {
|
|
||||||
std::shared_ptr<LaserPointer> laserPointer = std::make_shared<LaserPointer>(filter, maxDistance, renderStates, faceAvatar, centerEndY, lockEnd, enabled);
|
|
||||||
unsigned int uid = laserPointer->getUID();
|
|
||||||
QWriteLocker lock(&_lock);
|
|
||||||
_laserPointers[uid] = laserPointer;
|
|
||||||
_laserPointerLocks[uid] = std::make_shared<QReadWriteLock>();
|
|
||||||
return uid;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LaserPointerManager::removeLaserPointer(const unsigned int uid) {
|
void LaserPointerManager::removeLaserPointer(const unsigned int uid) {
|
||||||
QWriteLocker lock(&_lock);
|
QWriteLocker lock(&_removeLock);
|
||||||
_laserPointers.remove(uid);
|
_laserPointersToRemove.enqueue(uid);
|
||||||
_laserPointerLocks.remove(uid);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LaserPointerManager::enableLaserPointer(const unsigned int uid) {
|
void LaserPointerManager::enableLaserPointer(const unsigned int uid) {
|
||||||
QReadLocker lock(&_lock);
|
QReadLocker lock(&_containsLock);
|
||||||
if (_laserPointers.contains(uid)) {
|
if (_laserPointers.contains(uid)) {
|
||||||
QWriteLocker laserLock(_laserPointerLocks[uid].get());
|
QWriteLocker laserLock(_laserPointerLocks[uid].get());
|
||||||
_laserPointers[uid]->enable();
|
_laserPointers[uid]->enable();
|
||||||
|
@ -57,7 +37,7 @@ void LaserPointerManager::enableLaserPointer(const unsigned int uid) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void LaserPointerManager::disableLaserPointer(const unsigned int uid) {
|
void LaserPointerManager::disableLaserPointer(const unsigned int uid) {
|
||||||
QReadLocker lock(&_lock);
|
QReadLocker lock(&_containsLock);
|
||||||
if (_laserPointers.contains(uid)) {
|
if (_laserPointers.contains(uid)) {
|
||||||
QWriteLocker laserLock(_laserPointerLocks[uid].get());
|
QWriteLocker laserLock(_laserPointerLocks[uid].get());
|
||||||
_laserPointers[uid]->disable();
|
_laserPointers[uid]->disable();
|
||||||
|
@ -65,7 +45,7 @@ void LaserPointerManager::disableLaserPointer(const unsigned int uid) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void LaserPointerManager::setRenderState(unsigned int uid, const QString & renderState) {
|
void LaserPointerManager::setRenderState(unsigned int uid, const QString & renderState) {
|
||||||
QReadLocker lock(&_lock);
|
QReadLocker lock(&_containsLock);
|
||||||
if (_laserPointers.contains(uid)) {
|
if (_laserPointers.contains(uid)) {
|
||||||
QWriteLocker laserLock(_laserPointerLocks[uid].get());
|
QWriteLocker laserLock(_laserPointerLocks[uid].get());
|
||||||
_laserPointers[uid]->setRenderState(renderState);
|
_laserPointers[uid]->setRenderState(renderState);
|
||||||
|
@ -73,7 +53,7 @@ void LaserPointerManager::setRenderState(unsigned int uid, const QString & rende
|
||||||
}
|
}
|
||||||
|
|
||||||
void LaserPointerManager::editRenderState(unsigned int uid, const QString& state, const QVariant& startProps, const QVariant& pathProps, const QVariant& endProps) {
|
void LaserPointerManager::editRenderState(unsigned int uid, const QString& state, const QVariant& startProps, const QVariant& pathProps, const QVariant& endProps) {
|
||||||
QReadLocker lock(&_lock);
|
QReadLocker lock(&_containsLock);
|
||||||
if (_laserPointers.contains(uid)) {
|
if (_laserPointers.contains(uid)) {
|
||||||
QWriteLocker laserLock(_laserPointerLocks[uid].get());
|
QWriteLocker laserLock(_laserPointerLocks[uid].get());
|
||||||
_laserPointers[uid]->editRenderState(state, startProps, pathProps, endProps);
|
_laserPointers[uid]->editRenderState(state, startProps, pathProps, endProps);
|
||||||
|
@ -81,7 +61,7 @@ void LaserPointerManager::editRenderState(unsigned int uid, const QString& state
|
||||||
}
|
}
|
||||||
|
|
||||||
const RayPickResult LaserPointerManager::getPrevRayPickResult(const unsigned int uid) {
|
const RayPickResult LaserPointerManager::getPrevRayPickResult(const unsigned int uid) {
|
||||||
QReadLocker lock(&_lock);
|
QReadLocker lock(&_containsLock);
|
||||||
if (_laserPointers.contains(uid)) {
|
if (_laserPointers.contains(uid)) {
|
||||||
QReadLocker laserLock(_laserPointerLocks[uid].get());
|
QReadLocker laserLock(_laserPointerLocks[uid].get());
|
||||||
return _laserPointers[uid]->getPrevRayPickResult();
|
return _laserPointers[uid]->getPrevRayPickResult();
|
||||||
|
@ -90,16 +70,34 @@ const RayPickResult LaserPointerManager::getPrevRayPickResult(const unsigned int
|
||||||
}
|
}
|
||||||
|
|
||||||
void LaserPointerManager::update() {
|
void LaserPointerManager::update() {
|
||||||
QReadLocker lock(&_lock);
|
|
||||||
for (unsigned int uid : _laserPointers.keys()) {
|
for (unsigned int uid : _laserPointers.keys()) {
|
||||||
// This only needs to be a read lock because update won't change any of the properties that can be modified from scripts
|
// This only needs to be a read lock because update won't change any of the properties that can be modified from scripts
|
||||||
QReadLocker laserLock(_laserPointerLocks[uid].get());
|
QReadLocker laserLock(_laserPointerLocks[uid].get());
|
||||||
_laserPointers[uid]->update();
|
_laserPointers[uid]->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QWriteLocker containsLock(&_containsLock);
|
||||||
|
{
|
||||||
|
QWriteLocker lock(&_addLock);
|
||||||
|
while (!_laserPointersToAdd.isEmpty()) {
|
||||||
|
QPair<unsigned int, std::shared_ptr<LaserPointer>> laserPointerToAdd = _laserPointersToAdd.dequeue();
|
||||||
|
_laserPointers[laserPointerToAdd.first] = laserPointerToAdd.second;
|
||||||
|
_laserPointerLocks[laserPointerToAdd.first] = std::make_shared<QReadWriteLock>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
QWriteLocker lock(&_removeLock);
|
||||||
|
while (!_laserPointersToRemove.isEmpty()) {
|
||||||
|
unsigned int uid = _laserPointersToRemove.dequeue();
|
||||||
|
_laserPointers.remove(uid);
|
||||||
|
_laserPointerLocks.remove(uid);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LaserPointerManager::setIgnoreEntities(unsigned int uid, const QScriptValue& ignoreEntities) {
|
void LaserPointerManager::setIgnoreEntities(unsigned int uid, const QScriptValue& ignoreEntities) {
|
||||||
QReadLocker lock(&_lock);
|
QReadLocker lock(&_containsLock);
|
||||||
if (_laserPointers.contains(uid)) {
|
if (_laserPointers.contains(uid)) {
|
||||||
QWriteLocker laserLock(_laserPointerLocks[uid].get());
|
QWriteLocker laserLock(_laserPointerLocks[uid].get());
|
||||||
_laserPointers[uid]->setIgnoreEntities(ignoreEntities);
|
_laserPointers[uid]->setIgnoreEntities(ignoreEntities);
|
||||||
|
@ -107,7 +105,7 @@ void LaserPointerManager::setIgnoreEntities(unsigned int uid, const QScriptValue
|
||||||
}
|
}
|
||||||
|
|
||||||
void LaserPointerManager::setIncludeEntities(unsigned int uid, const QScriptValue& includeEntities) {
|
void LaserPointerManager::setIncludeEntities(unsigned int uid, const QScriptValue& includeEntities) {
|
||||||
QReadLocker lock(&_lock);
|
QReadLocker lock(&_containsLock);
|
||||||
if (_laserPointers.contains(uid)) {
|
if (_laserPointers.contains(uid)) {
|
||||||
QWriteLocker laserLock(_laserPointerLocks[uid].get());
|
QWriteLocker laserLock(_laserPointerLocks[uid].get());
|
||||||
_laserPointers[uid]->setIncludeEntities(includeEntities);
|
_laserPointers[uid]->setIncludeEntities(includeEntities);
|
||||||
|
@ -115,7 +113,7 @@ void LaserPointerManager::setIncludeEntities(unsigned int uid, const QScriptValu
|
||||||
}
|
}
|
||||||
|
|
||||||
void LaserPointerManager::setIgnoreOverlays(unsigned int uid, const QScriptValue& ignoreOverlays) {
|
void LaserPointerManager::setIgnoreOverlays(unsigned int uid, const QScriptValue& ignoreOverlays) {
|
||||||
QReadLocker lock(&_lock);
|
QReadLocker lock(&_containsLock);
|
||||||
if (_laserPointers.contains(uid)) {
|
if (_laserPointers.contains(uid)) {
|
||||||
QWriteLocker laserLock(_laserPointerLocks[uid].get());
|
QWriteLocker laserLock(_laserPointerLocks[uid].get());
|
||||||
_laserPointers[uid]->setIgnoreOverlays(ignoreOverlays);
|
_laserPointers[uid]->setIgnoreOverlays(ignoreOverlays);
|
||||||
|
@ -123,7 +121,7 @@ void LaserPointerManager::setIgnoreOverlays(unsigned int uid, const QScriptValue
|
||||||
}
|
}
|
||||||
|
|
||||||
void LaserPointerManager::setIncludeOverlays(unsigned int uid, const QScriptValue& includeOverlays) {
|
void LaserPointerManager::setIncludeOverlays(unsigned int uid, const QScriptValue& includeOverlays) {
|
||||||
QReadLocker lock(&_lock);
|
QReadLocker lock(&_containsLock);
|
||||||
if (_laserPointers.contains(uid)) {
|
if (_laserPointers.contains(uid)) {
|
||||||
QWriteLocker laserLock(_laserPointerLocks[uid].get());
|
QWriteLocker laserLock(_laserPointerLocks[uid].get());
|
||||||
_laserPointers[uid]->setIncludeOverlays(includeOverlays);
|
_laserPointers[uid]->setIncludeOverlays(includeOverlays);
|
||||||
|
@ -131,7 +129,7 @@ void LaserPointerManager::setIncludeOverlays(unsigned int uid, const QScriptValu
|
||||||
}
|
}
|
||||||
|
|
||||||
void LaserPointerManager::setIgnoreAvatars(unsigned int uid, const QScriptValue& ignoreAvatars) {
|
void LaserPointerManager::setIgnoreAvatars(unsigned int uid, const QScriptValue& ignoreAvatars) {
|
||||||
QReadLocker lock(&_lock);
|
QReadLocker lock(&_containsLock);
|
||||||
if (_laserPointers.contains(uid)) {
|
if (_laserPointers.contains(uid)) {
|
||||||
QWriteLocker laserLock(_laserPointerLocks[uid].get());
|
QWriteLocker laserLock(_laserPointerLocks[uid].get());
|
||||||
_laserPointers[uid]->setIgnoreAvatars(ignoreAvatars);
|
_laserPointers[uid]->setIgnoreAvatars(ignoreAvatars);
|
||||||
|
@ -139,7 +137,7 @@ void LaserPointerManager::setIgnoreAvatars(unsigned int uid, const QScriptValue&
|
||||||
}
|
}
|
||||||
|
|
||||||
void LaserPointerManager::setIncludeAvatars(unsigned int uid, const QScriptValue& includeAvatars) {
|
void LaserPointerManager::setIncludeAvatars(unsigned int uid, const QScriptValue& includeAvatars) {
|
||||||
QReadLocker lock(&_lock);
|
QReadLocker lock(&_containsLock);
|
||||||
if (_laserPointers.contains(uid)) {
|
if (_laserPointers.contains(uid)) {
|
||||||
QWriteLocker laserLock(_laserPointerLocks[uid].get());
|
QWriteLocker laserLock(_laserPointerLocks[uid].get());
|
||||||
_laserPointers[uid]->setIncludeAvatars(includeAvatars);
|
_laserPointers[uid]->setIncludeAvatars(includeAvatars);
|
||||||
|
|
|
@ -25,12 +25,8 @@ class LaserPointerManager : public Dependency {
|
||||||
SINGLETON_DEPENDENCY
|
SINGLETON_DEPENDENCY
|
||||||
|
|
||||||
public:
|
public:
|
||||||
unsigned int createLaserPointer(const QString& jointName, const glm::vec3& posOffset, const glm::vec3& dirOffset, const uint16_t filter, const float maxDistance,
|
unsigned int createLaserPointer(const QVariantMap& rayProps, const QHash<QString, RenderState>& renderStates, const bool faceAvatar, const bool centerEndY,
|
||||||
const QHash<QString, RenderState>& renderStates, const bool faceAvatar, const bool centerEndY, const bool lockEnd, const bool enabled);
|
const bool lockEnd, const bool enabled);
|
||||||
unsigned int createLaserPointer(const glm::vec3& position, const glm::vec3& direction, const uint16_t filter, const float maxDistance,
|
|
||||||
const QHash<QString, RenderState>& renderStates, const bool faceAvatar, const bool centerEndY, const bool lockEnd, const bool enabled);
|
|
||||||
unsigned int createLaserPointer(const uint16_t filter, const float maxDistance, const QHash<QString, RenderState>& renderStates, const bool faceAvatar,
|
|
||||||
const bool centerEndY, const bool lockEnd, const bool enabled);
|
|
||||||
void removeLaserPointer(const unsigned int uid);
|
void removeLaserPointer(const unsigned int uid);
|
||||||
void enableLaserPointer(const unsigned int uid);
|
void enableLaserPointer(const unsigned int uid);
|
||||||
void disableLaserPointer(const unsigned int uid);
|
void disableLaserPointer(const unsigned int uid);
|
||||||
|
@ -49,8 +45,13 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QHash<unsigned int, std::shared_ptr<LaserPointer>> _laserPointers;
|
QHash<unsigned int, std::shared_ptr<LaserPointer>> _laserPointers;
|
||||||
QReadWriteLock _lock;
|
|
||||||
QHash<unsigned int, std::shared_ptr<QReadWriteLock>> _laserPointerLocks;
|
QHash<unsigned int, std::shared_ptr<QReadWriteLock>> _laserPointerLocks;
|
||||||
|
unsigned int _nextUID{ 1 }; // 0 is invalid
|
||||||
|
QReadWriteLock _addLock;
|
||||||
|
QQueue<QPair<unsigned int, std::shared_ptr<LaserPointer>>> _laserPointersToAdd;
|
||||||
|
QReadWriteLock _removeLock;
|
||||||
|
QQueue<unsigned int> _laserPointersToRemove;
|
||||||
|
QReadWriteLock _containsLock;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -20,16 +20,6 @@
|
||||||
uint32_t LaserPointerScriptingInterface::createLaserPointer(const QVariant& properties) {
|
uint32_t LaserPointerScriptingInterface::createLaserPointer(const QVariant& properties) {
|
||||||
QVariantMap propertyMap = properties.toMap();
|
QVariantMap propertyMap = properties.toMap();
|
||||||
|
|
||||||
uint16_t filter = 0;
|
|
||||||
if (propertyMap["filter"].isValid()) {
|
|
||||||
filter = propertyMap["filter"].toUInt();
|
|
||||||
}
|
|
||||||
|
|
||||||
float maxDistance = 0.0f;
|
|
||||||
if (propertyMap["maxDistance"].isValid()) {
|
|
||||||
maxDistance = propertyMap["maxDistance"].toFloat();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool faceAvatar = false;
|
bool faceAvatar = false;
|
||||||
if (propertyMap["faceAvatar"].isValid()) {
|
if (propertyMap["faceAvatar"].isValid()) {
|
||||||
faceAvatar = propertyMap["faceAvatar"].toBool();
|
faceAvatar = propertyMap["faceAvatar"].toBool();
|
||||||
|
@ -64,37 +54,7 @@ uint32_t LaserPointerScriptingInterface::createLaserPointer(const QVariant& prop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (propertyMap["joint"].isValid()) {
|
return DependencyManager::get<LaserPointerManager>()->createLaserPointer(propertyMap, renderStates, faceAvatar, centerEndY, lockEnd, enabled);
|
||||||
QString jointName = propertyMap["joint"].toString();
|
|
||||||
|
|
||||||
if (jointName != "Mouse") {
|
|
||||||
// x = upward, y = forward, z = lateral
|
|
||||||
glm::vec3 posOffset = Vectors::ZERO;
|
|
||||||
if (propertyMap["posOffset"].isValid()) {
|
|
||||||
posOffset = vec3FromVariant(propertyMap["posOffset"]);
|
|
||||||
}
|
|
||||||
|
|
||||||
glm::vec3 dirOffset = Vectors::UP;
|
|
||||||
if (propertyMap["dirOffset"].isValid()) {
|
|
||||||
dirOffset = vec3FromVariant(propertyMap["dirOffset"]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return DependencyManager::get<LaserPointerManager>()->createLaserPointer(jointName, posOffset, dirOffset, filter, maxDistance, renderStates, faceAvatar, centerEndY, lockEnd, enabled);
|
|
||||||
} else {
|
|
||||||
return DependencyManager::get<LaserPointerManager>()->createLaserPointer(filter, maxDistance, renderStates, faceAvatar, centerEndY, lockEnd, enabled);
|
|
||||||
}
|
|
||||||
} else if (propertyMap["position"].isValid()) {
|
|
||||||
glm::vec3 position = vec3FromVariant(propertyMap["position"]);
|
|
||||||
|
|
||||||
glm::vec3 direction = -Vectors::UP;
|
|
||||||
if (propertyMap["direction"].isValid()) {
|
|
||||||
direction = vec3FromVariant(propertyMap["direction"]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return DependencyManager::get<LaserPointerManager>()->createLaserPointer(position, direction, filter, maxDistance, renderStates, faceAvatar, centerEndY, lockEnd, enabled);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LaserPointerScriptingInterface::editRenderState(unsigned int uid, const QString& renderState, const QVariant& properties) {
|
void LaserPointerScriptingInterface::editRenderState(unsigned int uid, const QString& renderState, const QVariant& properties) {
|
||||||
|
|
|
@ -19,6 +19,10 @@
|
||||||
#include "scripting/HMDScriptingInterface.h"
|
#include "scripting/HMDScriptingInterface.h"
|
||||||
#include "DependencyManager.h"
|
#include "DependencyManager.h"
|
||||||
|
|
||||||
|
#include "JointRayPick.h"
|
||||||
|
#include "StaticRayPick.h"
|
||||||
|
#include "MouseRayPick.h"
|
||||||
|
|
||||||
bool RayPickManager::checkAndCompareCachedResults(QPair<glm::vec3, glm::vec3>& ray, RayPickCache& cache, RayPickResult& res, unsigned int mask) {
|
bool RayPickManager::checkAndCompareCachedResults(QPair<glm::vec3, glm::vec3>& ray, RayPickCache& cache, RayPickResult& res, unsigned int mask) {
|
||||||
if (cache.contains(ray) && cache[ray].contains(mask)) {
|
if (cache.contains(ray) && cache[ray].contains(mask)) {
|
||||||
if (cache[ray][mask].distance < res.distance) {
|
if (cache[ray][mask].distance < res.distance) {
|
||||||
|
@ -137,10 +141,59 @@ void RayPickManager::update() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int RayPickManager::addRayPick(std::shared_ptr<RayPick> rayPick) {
|
unsigned int RayPickManager::createRayPick(const QVariantMap& rayProps) {
|
||||||
QWriteLocker lock(&_addLock);
|
bool enabled = false;
|
||||||
_rayPicksToAdd.enqueue(QPair<unsigned int, std::shared_ptr<RayPick>>(_nextUID, rayPick));
|
if (rayProps["enabled"].isValid()) {
|
||||||
return _nextUID++;
|
enabled = rayProps["enabled"].toBool();
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t filter = 0;
|
||||||
|
if (rayProps["filter"].isValid()) {
|
||||||
|
filter = rayProps["filter"].toUInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
float maxDistance = 0.0f;
|
||||||
|
if (rayProps["maxDistance"].isValid()) {
|
||||||
|
maxDistance = rayProps["maxDistance"].toFloat();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rayProps["joint"].isValid()) {
|
||||||
|
QString jointName = rayProps["joint"].toString();
|
||||||
|
|
||||||
|
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);
|
||||||
|
_rayPicksToAdd.enqueue(QPair<unsigned int, std::shared_ptr<RayPick>>(_nextUID, std::make_shared<JointRayPick>(jointName, posOffset, dirOffset, filter, maxDistance, enabled)));
|
||||||
|
return _nextUID++;
|
||||||
|
} else {
|
||||||
|
QWriteLocker lock(&_addLock);
|
||||||
|
_rayPicksToAdd.enqueue(QPair<unsigned int, std::shared_ptr<RayPick>>(_nextUID, std::make_shared<MouseRayPick>(filter, maxDistance, enabled)));
|
||||||
|
return _nextUID++;
|
||||||
|
}
|
||||||
|
} 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);
|
||||||
|
_rayPicksToAdd.enqueue(QPair<unsigned int, std::shared_ptr<RayPick>>(_nextUID, std::make_shared<StaticRayPick>(position, direction, filter, maxDistance, enabled)));
|
||||||
|
return _nextUID++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RayPickManager::removeRayPick(const unsigned int uid) {
|
void RayPickManager::removeRayPick(const unsigned int uid) {
|
||||||
|
|
|
@ -58,19 +58,21 @@ class RayPickManager : public QObject, public Dependency {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void update();
|
void update();
|
||||||
unsigned int addRayPick(std::shared_ptr<RayPick> rayPick);
|
|
||||||
void removeRayPick(const unsigned int uid);
|
|
||||||
void enableRayPick(const unsigned int uid);
|
|
||||||
void disableRayPick(const unsigned int uid);
|
|
||||||
const PickRay getPickRay(const unsigned int uid);
|
const PickRay getPickRay(const unsigned int uid);
|
||||||
const RayPickResult getPrevRayPickResult(const unsigned int uid);
|
|
||||||
|
|
||||||
void setIgnoreEntities(unsigned int uid, const QScriptValue& ignoreEntities);
|
public slots:
|
||||||
void setIncludeEntities(unsigned int uid, const QScriptValue& includeEntities);
|
Q_INVOKABLE unsigned int createRayPick(const QVariantMap& rayProps);
|
||||||
void setIgnoreOverlays(unsigned int uid, const QScriptValue& ignoreOverlays);
|
Q_INVOKABLE void removeRayPick(const unsigned int uid);
|
||||||
void setIncludeOverlays(unsigned int uid, const QScriptValue& includeOverlays);
|
Q_INVOKABLE void enableRayPick(const unsigned int uid);
|
||||||
void setIgnoreAvatars(unsigned int uid, const QScriptValue& ignoreAvatars);
|
Q_INVOKABLE void disableRayPick(const unsigned int uid);
|
||||||
void setIncludeAvatars(unsigned int uid, const QScriptValue& includeAvatars);
|
Q_INVOKABLE const RayPickResult getPrevRayPickResult(const unsigned int uid);
|
||||||
|
|
||||||
|
Q_INVOKABLE void setIgnoreEntities(unsigned int uid, const QScriptValue& ignoreEntities);
|
||||||
|
Q_INVOKABLE void setIncludeEntities(unsigned int uid, const QScriptValue& includeEntities);
|
||||||
|
Q_INVOKABLE void setIgnoreOverlays(unsigned int uid, const QScriptValue& ignoreOverlays);
|
||||||
|
Q_INVOKABLE void setIncludeOverlays(unsigned int uid, const QScriptValue& includeOverlays);
|
||||||
|
Q_INVOKABLE void setIgnoreAvatars(unsigned int uid, const QScriptValue& ignoreAvatars);
|
||||||
|
Q_INVOKABLE void setIncludeAvatars(unsigned int uid, const QScriptValue& includeAvatars);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QHash<unsigned int, std::shared_ptr<RayPick>> _rayPicks;
|
QHash<unsigned int, std::shared_ptr<RayPick>> _rayPicks;
|
||||||
|
|
|
@ -257,12 +257,12 @@ function Grabber() {
|
||||||
this.liftKey = false; // SHIFT
|
this.liftKey = false; // SHIFT
|
||||||
this.rotateKey = false; // CONTROL
|
this.rotateKey = false; // CONTROL
|
||||||
|
|
||||||
this.mouseRayOverlays = LaserPointers.createLaserPointer({
|
this.mouseRayOverlays = RayPick.createRayPick({
|
||||||
joint: "Mouse",
|
joint: "Mouse",
|
||||||
filter: RayPick.PICK_OVERLAYS,
|
filter: RayPick.PICK_OVERLAYS,
|
||||||
enabled: true
|
enabled: true
|
||||||
});
|
});
|
||||||
LaserPointers.setIncludeOverlays(this.mouseRayOverlays, [HMD.tabletID, HMD.tabletScreenID, HMD.homeButtonID]);
|
RayPick.setIncludeOverlays(this.mouseRayOverlays, [HMD.tabletID, HMD.tabletScreenID, HMD.homeButtonID]);
|
||||||
this.mouseRayEntities = LaserPointers.createLaserPointer({
|
this.mouseRayEntities = LaserPointers.createLaserPointer({
|
||||||
joint: "Mouse",
|
joint: "Mouse",
|
||||||
filter: RayPick.PICK_ENTITIES,
|
filter: RayPick.PICK_ENTITIES,
|
||||||
|
@ -318,7 +318,7 @@ Grabber.prototype.pressEvent = function(event) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var overlayResult = LaserPointers.getPrevRayPickResult(this.mouseRayOverlays);
|
var overlayResult = RayPick.getPrevRayPickResult(this.mouseRayOverlays);
|
||||||
if (overlayResult.type != RayPick.INTERSECTED_NONE) {
|
if (overlayResult.type != RayPick.INTERSECTED_NONE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -572,7 +572,7 @@ Grabber.prototype.keyPressEvent = function(event) {
|
||||||
|
|
||||||
Grabber.prototype.cleanup = function() {
|
Grabber.prototype.cleanup = function() {
|
||||||
LaserPointers.removeLaserPointer(this.mouseRayEntities);
|
LaserPointers.removeLaserPointer(this.mouseRayEntities);
|
||||||
LaserPointers.removeLaserPointer(this.mouseRayOverlays);
|
RayPick.removeRayPick(this.mouseRayOverlays);
|
||||||
};
|
};
|
||||||
|
|
||||||
var grabber = new Grabber();
|
var grabber = new Grabber();
|
||||||
|
|
Loading…
Reference in a new issue