mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 16:18:05 +02:00
add searchRay to RayPickResult, fix precision picking caching with multiple lasers, make laser addition/removal immediate
This commit is contained in:
parent
20cb02dabb
commit
cbe621f2b7
9 changed files with 45 additions and 91 deletions
|
@ -92,8 +92,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 PickRay& pickRay, const bool defaultState) {
|
||||||
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));
|
||||||
|
@ -186,11 +185,11 @@ void LaserPointer::disableRenderState(const RenderState& renderState) {
|
||||||
void LaserPointer::update() {
|
void LaserPointer::update() {
|
||||||
RayPickResult prevRayPickResult = DependencyManager::get<RayPickScriptingInterface>()->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, prevRayPickResult.searchRay, false);
|
||||||
disableRenderState(_defaultRenderStates[_currentRenderState].second);
|
disableRenderState(_defaultRenderStates[_currentRenderState].second);
|
||||||
} else if (_renderingEnabled && !_currentRenderState.empty() && _defaultRenderStates.find(_currentRenderState) != _defaultRenderStates.end()) {
|
} else if (_renderingEnabled && !_currentRenderState.empty() && _defaultRenderStates.find(_currentRenderState) != _defaultRenderStates.end()) {
|
||||||
disableRenderState(_renderStates[_currentRenderState]);
|
disableRenderState(_renderStates[_currentRenderState]);
|
||||||
updateRenderState(_defaultRenderStates[_currentRenderState].second, IntersectionType::NONE, _defaultRenderStates[_currentRenderState].first, QUuid(), true);
|
updateRenderState(_defaultRenderStates[_currentRenderState].second, IntersectionType::NONE, _defaultRenderStates[_currentRenderState].first, QUuid(), prevRayPickResult.searchRay, true);
|
||||||
} else if (!_currentRenderState.empty()) {
|
} else if (!_currentRenderState.empty()) {
|
||||||
disableRenderState(_renderStates[_currentRenderState]);
|
disableRenderState(_renderStates[_currentRenderState]);
|
||||||
disableRenderState(_defaultRenderStates[_currentRenderState].second);
|
disableRenderState(_defaultRenderStates[_currentRenderState].second);
|
||||||
|
|
|
@ -89,7 +89,7 @@ private:
|
||||||
QUuid _rayPickUID;
|
QUuid _rayPickUID;
|
||||||
|
|
||||||
void updateRenderStateOverlay(const OverlayID& id, const QVariant& props);
|
void updateRenderStateOverlay(const OverlayID& id, const QVariant& props);
|
||||||
void updateRenderState(const RenderState& renderState, const IntersectionType type, const float distance, const QUuid& objectID, const bool defaultState);
|
void updateRenderState(const RenderState& renderState, const IntersectionType type, const float distance, const QUuid& objectID, const PickRay& pickRay, const bool defaultState);
|
||||||
void disableRenderState(const RenderState& renderState);
|
void disableRenderState(const RenderState& renderState);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -14,17 +14,19 @@ QUuid LaserPointerManager::createLaserPointer(const QVariant& rayProps, const La
|
||||||
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()) {
|
||||||
QWriteLocker lock(&_addLock);
|
QWriteLocker containsLock(&_containsLock);
|
||||||
QUuid id = QUuid::createUuid();
|
QUuid id = QUuid::createUuid();
|
||||||
_laserPointersToAdd.push(std::pair<QUuid, std::shared_ptr<LaserPointer>>(id, laserPointer));
|
_laserPointers[id] = laserPointer;
|
||||||
|
_laserPointerLocks[id] = std::make_shared<QReadWriteLock>();
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
return QUuid();
|
return QUuid();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LaserPointerManager::removeLaserPointer(const QUuid uid) {
|
void LaserPointerManager::removeLaserPointer(const QUuid uid) {
|
||||||
QWriteLocker lock(&_removeLock);
|
QWriteLocker lock(&_containsLock);
|
||||||
_laserPointersToRemove.push(uid);
|
_laserPointers.remove(uid);
|
||||||
|
_laserPointerLocks.remove(uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LaserPointerManager::enableLaserPointer(const QUuid uid) {
|
void LaserPointerManager::enableLaserPointer(const QUuid uid) {
|
||||||
|
@ -69,32 +71,12 @@ const RayPickResult LaserPointerManager::getPrevRayPickResult(const QUuid uid) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void LaserPointerManager::update() {
|
void LaserPointerManager::update() {
|
||||||
|
QReadLocker lock(&_containsLock);
|
||||||
for (QUuid& uid : _laserPointers.keys()) {
|
for (QUuid& 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.empty()) {
|
|
||||||
std::pair<QUuid, std::shared_ptr<LaserPointer>> laserPointerToAdd = _laserPointersToAdd.front();
|
|
||||||
_laserPointersToAdd.pop();
|
|
||||||
_laserPointers[laserPointerToAdd.first] = laserPointerToAdd.second;
|
|
||||||
_laserPointerLocks[laserPointerToAdd.first] = std::make_shared<QReadWriteLock>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
QWriteLocker lock(&_removeLock);
|
|
||||||
while (!_laserPointersToRemove.empty()) {
|
|
||||||
QUuid uid = _laserPointersToRemove.front();
|
|
||||||
_laserPointersToRemove.pop();
|
|
||||||
_laserPointers.remove(uid);
|
|
||||||
_laserPointerLocks.remove(uid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LaserPointerManager::setPrecisionPicking(QUuid uid, const bool precisionPicking) {
|
void LaserPointerManager::setPrecisionPicking(QUuid uid, const bool precisionPicking) {
|
||||||
|
|
|
@ -46,10 +46,6 @@ public:
|
||||||
private:
|
private:
|
||||||
QHash<QUuid, std::shared_ptr<LaserPointer>> _laserPointers;
|
QHash<QUuid, std::shared_ptr<LaserPointer>> _laserPointers;
|
||||||
QHash<QUuid, std::shared_ptr<QReadWriteLock>> _laserPointerLocks;
|
QHash<QUuid, std::shared_ptr<QReadWriteLock>> _laserPointerLocks;
|
||||||
QReadWriteLock _addLock;
|
|
||||||
std::queue<std::pair<QUuid, std::shared_ptr<LaserPointer>>> _laserPointersToAdd;
|
|
||||||
QReadWriteLock _removeLock;
|
|
||||||
std::queue<QUuid> _laserPointersToRemove;
|
|
||||||
QReadWriteLock _containsLock;
|
QReadWriteLock _containsLock;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -70,6 +70,9 @@ public:
|
||||||
if (doesPickNonCollidable()) {
|
if (doesPickNonCollidable()) {
|
||||||
toReturn |= getBitMask(PICK_INCLUDE_NONCOLLIDABLE);
|
toReturn |= getBitMask(PICK_INCLUDE_NONCOLLIDABLE);
|
||||||
}
|
}
|
||||||
|
if (doesPickCourse()) {
|
||||||
|
toReturn |= getBitMask(PICK_COURSE);
|
||||||
|
}
|
||||||
return Flags(toReturn);
|
return Flags(toReturn);
|
||||||
}
|
}
|
||||||
Flags getOverlayFlags() const {
|
Flags getOverlayFlags() const {
|
||||||
|
@ -80,6 +83,9 @@ public:
|
||||||
if (doesPickNonCollidable()) {
|
if (doesPickNonCollidable()) {
|
||||||
toReturn |= getBitMask(PICK_INCLUDE_NONCOLLIDABLE);
|
toReturn |= getBitMask(PICK_INCLUDE_NONCOLLIDABLE);
|
||||||
}
|
}
|
||||||
|
if (doesPickCourse()) {
|
||||||
|
toReturn |= getBitMask(PICK_COURSE);
|
||||||
|
}
|
||||||
return Flags(toReturn);
|
return Flags(toReturn);
|
||||||
}
|
}
|
||||||
Flags getAvatarFlags() const { return Flags(getBitMask(PICK_AVATARS)); }
|
Flags getAvatarFlags() const { return Flags(getBitMask(PICK_AVATARS)); }
|
||||||
|
|
|
@ -38,11 +38,12 @@ void RayPickManager::cacheResult(const bool intersects, const RayPickResult& res
|
||||||
res = resTemp;
|
res = resTemp;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
cache[ray][mask] = RayPickResult();
|
cache[ray][mask] = RayPickResult(res.searchRay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RayPickManager::update() {
|
void RayPickManager::update() {
|
||||||
|
QReadLocker lock(&_containsLock);
|
||||||
RayPickCache results;
|
RayPickCache results;
|
||||||
for (auto& uid : _rayPicks.keys()) {
|
for (auto& uid : _rayPicks.keys()) {
|
||||||
std::shared_ptr<RayPick> rayPick = _rayPicks[uid];
|
std::shared_ptr<RayPick> rayPick = _rayPicks[uid];
|
||||||
|
@ -58,7 +59,7 @@ void RayPickManager::update() {
|
||||||
}
|
}
|
||||||
|
|
||||||
QPair<glm::vec3, glm::vec3> rayKey = QPair<glm::vec3, glm::vec3>(ray.origin, ray.direction);
|
QPair<glm::vec3, glm::vec3> rayKey = QPair<glm::vec3, glm::vec3>(ray.origin, ray.direction);
|
||||||
RayPickResult res;
|
RayPickResult res = RayPickResult(ray);
|
||||||
|
|
||||||
if (rayPick->getFilter().doesPickEntities()) {
|
if (rayPick->getFilter().doesPickEntities()) {
|
||||||
RayToEntityIntersectionResult entityRes;
|
RayToEntityIntersectionResult entityRes;
|
||||||
|
@ -73,7 +74,7 @@ void RayPickManager::update() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fromCache) {
|
if (!fromCache) {
|
||||||
cacheResult(entityRes.intersects, RayPickResult(IntersectionType::ENTITY, entityRes.entityID, entityRes.distance, entityRes.intersection, entityRes.surfaceNormal),
|
cacheResult(entityRes.intersects, RayPickResult(IntersectionType::ENTITY, entityRes.entityID, entityRes.distance, entityRes.intersection, ray, entityRes.surfaceNormal),
|
||||||
entityMask, res, rayKey, results);
|
entityMask, res, rayKey, results);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,7 +92,7 @@ void RayPickManager::update() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fromCache) {
|
if (!fromCache) {
|
||||||
cacheResult(overlayRes.intersects, RayPickResult(IntersectionType::OVERLAY, overlayRes.overlayID, overlayRes.distance, overlayRes.intersection, overlayRes.surfaceNormal),
|
cacheResult(overlayRes.intersects, RayPickResult(IntersectionType::OVERLAY, overlayRes.overlayID, overlayRes.distance, overlayRes.intersection, ray, overlayRes.surfaceNormal),
|
||||||
overlayMask, res, rayKey, results);
|
overlayMask, res, rayKey, results);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,7 +101,7 @@ void RayPickManager::update() {
|
||||||
RayPickFilter::Flags avatarMask = rayPick->getFilter().getAvatarFlags();
|
RayPickFilter::Flags avatarMask = rayPick->getFilter().getAvatarFlags();
|
||||||
if (!checkAndCompareCachedResults(rayKey, results, res, avatarMask)) {
|
if (!checkAndCompareCachedResults(rayKey, results, res, avatarMask)) {
|
||||||
RayToAvatarIntersectionResult avatarRes = DependencyManager::get<AvatarManager>()->findRayIntersectionVector(ray, rayPick->getIncludeAvatars(), rayPick->getIgnoreAvatars());
|
RayToAvatarIntersectionResult avatarRes = DependencyManager::get<AvatarManager>()->findRayIntersectionVector(ray, rayPick->getIncludeAvatars(), rayPick->getIgnoreAvatars());
|
||||||
cacheResult(avatarRes.intersects, RayPickResult(IntersectionType::AVATAR, avatarRes.avatarID, avatarRes.distance, avatarRes.intersection), avatarMask, res, rayKey, results);
|
cacheResult(avatarRes.intersects, RayPickResult(IntersectionType::AVATAR, avatarRes.avatarID, avatarRes.distance, avatarRes.intersection, ray), avatarMask, res, rayKey, results);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,7 +110,7 @@ void RayPickManager::update() {
|
||||||
RayPickFilter::Flags hudMask = rayPick->getFilter().getHUDFlags();
|
RayPickFilter::Flags hudMask = rayPick->getFilter().getHUDFlags();
|
||||||
if (!checkAndCompareCachedResults(rayKey, results, res, hudMask)) {
|
if (!checkAndCompareCachedResults(rayKey, results, res, hudMask)) {
|
||||||
glm::vec3 hudRes = DependencyManager::get<HMDScriptingInterface>()->calculateRayUICollisionPoint(ray.origin, ray.direction);
|
glm::vec3 hudRes = DependencyManager::get<HMDScriptingInterface>()->calculateRayUICollisionPoint(ray.origin, ray.direction);
|
||||||
cacheResult(true, RayPickResult(IntersectionType::HUD, 0, glm::distance(ray.origin, hudRes), hudRes), hudMask, res, rayKey, results);
|
cacheResult(true, RayPickResult(IntersectionType::HUD, 0, glm::distance(ray.origin, hudRes), hudRes, ray), hudMask, res, rayKey, results);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,56 +118,39 @@ void RayPickManager::update() {
|
||||||
if (rayPick->getMaxDistance() == 0.0f || (rayPick->getMaxDistance() > 0.0f && res.distance < rayPick->getMaxDistance())) {
|
if (rayPick->getMaxDistance() == 0.0f || (rayPick->getMaxDistance() > 0.0f && res.distance < rayPick->getMaxDistance())) {
|
||||||
rayPick->setRayPickResult(res);
|
rayPick->setRayPickResult(res);
|
||||||
} else {
|
} else {
|
||||||
rayPick->setRayPickResult(RayPickResult());
|
rayPick->setRayPickResult(RayPickResult(ray));
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QWriteLocker containsLock(&_containsLock);
|
|
||||||
{
|
|
||||||
QWriteLocker lock(&_addLock);
|
|
||||||
while (!_rayPicksToAdd.empty()) {
|
|
||||||
std::pair<QUuid, std::shared_ptr<RayPick>> rayPickToAdd = _rayPicksToAdd.front();
|
|
||||||
_rayPicksToAdd.pop();
|
|
||||||
_rayPicks[rayPickToAdd.first] = rayPickToAdd.second;
|
|
||||||
_rayPickLocks[rayPickToAdd.first] = std::make_shared<QReadWriteLock>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
QWriteLocker lock(&_removeLock);
|
|
||||||
while (!_rayPicksToRemove.empty()) {
|
|
||||||
QUuid uid = _rayPicksToRemove.front();
|
|
||||||
_rayPicksToRemove.pop();
|
|
||||||
_rayPicks.remove(uid);
|
|
||||||
_rayPickLocks.remove(uid);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QUuid RayPickManager::createRayPick(const std::string& jointName, const glm::vec3& posOffset, const glm::vec3& dirOffset, const RayPickFilter& filter, const float maxDistance, const bool enabled) {
|
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);
|
QWriteLocker lock(&_containsLock);
|
||||||
QUuid id = QUuid::createUuid();
|
QUuid id = QUuid::createUuid();
|
||||||
_rayPicksToAdd.push(std::pair<QUuid, std::shared_ptr<RayPick>>(id, std::make_shared<JointRayPick>(jointName, posOffset, dirOffset, filter, maxDistance, enabled)));
|
_rayPicks[id] = std::make_shared<JointRayPick>(jointName, posOffset, dirOffset, filter, maxDistance, enabled);
|
||||||
|
_rayPickLocks[id] = std::make_shared<QReadWriteLock>();
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
QUuid RayPickManager::createRayPick(const RayPickFilter& filter, const float maxDistance, const bool enabled) {
|
QUuid RayPickManager::createRayPick(const RayPickFilter& filter, const float maxDistance, const bool enabled) {
|
||||||
QWriteLocker lock(&_addLock);
|
QWriteLocker lock(&_containsLock);
|
||||||
QUuid id = QUuid::createUuid();
|
QUuid id = QUuid::createUuid();
|
||||||
_rayPicksToAdd.push(std::pair<QUuid, std::shared_ptr<RayPick>>(id, std::make_shared<MouseRayPick>(filter, maxDistance, enabled)));
|
_rayPicks[id] = std::make_shared<MouseRayPick>(filter, maxDistance, enabled);
|
||||||
|
_rayPickLocks[id] = std::make_shared<QReadWriteLock>();
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
QUuid RayPickManager::createRayPick(const glm::vec3& position, const glm::vec3& direction, const RayPickFilter& filter, const float maxDistance, const bool enabled) {
|
QUuid RayPickManager::createRayPick(const glm::vec3& position, const glm::vec3& direction, const RayPickFilter& filter, const float maxDistance, const bool enabled) {
|
||||||
QWriteLocker lock(&_addLock);
|
QWriteLocker lock(&_containsLock);
|
||||||
QUuid id = QUuid::createUuid();
|
QUuid id = QUuid::createUuid();
|
||||||
_rayPicksToAdd.push(std::pair<QUuid, std::shared_ptr<RayPick>>(id, std::make_shared<StaticRayPick>(position, direction, filter, maxDistance, enabled)));
|
_rayPicks[id] = std::make_shared<StaticRayPick>(position, direction, filter, maxDistance, enabled);
|
||||||
|
_rayPickLocks[id] = std::make_shared<QReadWriteLock>();
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RayPickManager::removeRayPick(const QUuid uid) {
|
void RayPickManager::removeRayPick(const QUuid uid) {
|
||||||
QWriteLocker lock(&_removeLock);
|
QWriteLocker lock(&_containsLock);
|
||||||
_rayPicksToRemove.push(uid);
|
_rayPicks.remove(uid);
|
||||||
|
_rayPickLocks.remove(uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RayPickManager::enableRayPick(const QUuid uid) {
|
void RayPickManager::enableRayPick(const QUuid uid) {
|
||||||
|
@ -185,18 +169,6 @@ void RayPickManager::disableRayPick(const QUuid uid) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const PickRay RayPickManager::getPickRay(const QUuid uid) {
|
|
||||||
QReadLocker containsLock(&_containsLock);
|
|
||||||
if (_rayPicks.contains(uid)) {
|
|
||||||
bool valid;
|
|
||||||
PickRay pickRay = _rayPicks[uid]->getPickRay(valid);
|
|
||||||
if (valid) {
|
|
||||||
return pickRay;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return PickRay();
|
|
||||||
}
|
|
||||||
|
|
||||||
const RayPickResult RayPickManager::getPrevRayPickResult(const QUuid uid) {
|
const RayPickResult RayPickManager::getPrevRayPickResult(const QUuid uid) {
|
||||||
QReadLocker containsLock(&_containsLock);
|
QReadLocker containsLock(&_containsLock);
|
||||||
if (_rayPicks.contains(uid)) {
|
if (_rayPicks.contains(uid)) {
|
||||||
|
|
|
@ -28,7 +28,6 @@ class RayPickManager {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void update();
|
void update();
|
||||||
const PickRay getPickRay(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 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 RayPickFilter& filter, const float maxDistance, const bool enabled);
|
||||||
|
@ -49,10 +48,6 @@ public:
|
||||||
private:
|
private:
|
||||||
QHash<QUuid, std::shared_ptr<RayPick>> _rayPicks;
|
QHash<QUuid, std::shared_ptr<RayPick>> _rayPicks;
|
||||||
QHash<QUuid, std::shared_ptr<QReadWriteLock>> _rayPickLocks;
|
QHash<QUuid, std::shared_ptr<QReadWriteLock>> _rayPickLocks;
|
||||||
QReadWriteLock _addLock;
|
|
||||||
std::queue<std::pair<QUuid, std::shared_ptr<RayPick>>> _rayPicksToAdd;
|
|
||||||
QReadWriteLock _removeLock;
|
|
||||||
std::queue<QUuid> _rayPicksToRemove;
|
|
||||||
QReadWriteLock _containsLock;
|
QReadWriteLock _containsLock;
|
||||||
|
|
||||||
typedef QHash<QPair<glm::vec3, glm::vec3>, std::unordered_map<RayPickFilter::Flags, RayPickResult>> RayPickCache;
|
typedef QHash<QPair<glm::vec3, glm::vec3>, std::unordered_map<RayPickFilter::Flags, RayPickResult>> RayPickCache;
|
||||||
|
|
|
@ -762,6 +762,8 @@ QScriptValue rayPickResultToScriptValue(QScriptEngine* engine, const RayPickResu
|
||||||
QScriptValue intersection = vec3toScriptValue(engine, rayPickResult.intersection);
|
QScriptValue intersection = vec3toScriptValue(engine, rayPickResult.intersection);
|
||||||
obj.setProperty("intersection", intersection);
|
obj.setProperty("intersection", intersection);
|
||||||
obj.setProperty("intersects", rayPickResult.type != NONE);
|
obj.setProperty("intersects", rayPickResult.type != NONE);
|
||||||
|
QScriptValue searchRay = pickRayToScriptValue(engine, rayPickResult.searchRay);
|
||||||
|
obj.setProperty("searchRay", searchRay);
|
||||||
QScriptValue surfaceNormal = vec3toScriptValue(engine, rayPickResult.surfaceNormal);
|
QScriptValue surfaceNormal = vec3toScriptValue(engine, rayPickResult.surfaceNormal);
|
||||||
obj.setProperty("surfaceNormal", surfaceNormal);
|
obj.setProperty("surfaceNormal", surfaceNormal);
|
||||||
return obj;
|
return obj;
|
||||||
|
|
|
@ -137,7 +137,7 @@ QScriptValue pickRayToScriptValue(QScriptEngine* engine, const PickRay& pickRay)
|
||||||
void pickRayFromScriptValue(const QScriptValue& object, PickRay& pickRay);
|
void pickRayFromScriptValue(const QScriptValue& object, PickRay& pickRay);
|
||||||
|
|
||||||
enum IntersectionType {
|
enum IntersectionType {
|
||||||
NONE,
|
NONE = 0,
|
||||||
ENTITY,
|
ENTITY,
|
||||||
OVERLAY,
|
OVERLAY,
|
||||||
AVATAR,
|
AVATAR,
|
||||||
|
@ -147,12 +147,14 @@ enum IntersectionType {
|
||||||
class RayPickResult {
|
class RayPickResult {
|
||||||
public:
|
public:
|
||||||
RayPickResult() {}
|
RayPickResult() {}
|
||||||
RayPickResult(const IntersectionType type, const QUuid& objectID, const float distance, const glm::vec3& intersection, const glm::vec3& surfaceNormal = glm::vec3(NAN)) :
|
RayPickResult(const PickRay& searchRay) : searchRay(searchRay) {}
|
||||||
type(type), objectID(objectID), distance(distance), intersection(intersection), surfaceNormal(surfaceNormal) {}
|
RayPickResult(const IntersectionType type, const QUuid& objectID, const float distance, const glm::vec3& intersection, const PickRay& searchRay, const glm::vec3& surfaceNormal = glm::vec3(NAN)) :
|
||||||
|
type(type), objectID(objectID), distance(distance), intersection(intersection), searchRay(searchRay), surfaceNormal(surfaceNormal) {}
|
||||||
IntersectionType type { NONE };
|
IntersectionType type { NONE };
|
||||||
QUuid objectID { 0 };
|
QUuid objectID;
|
||||||
float distance { FLT_MAX };
|
float distance { FLT_MAX };
|
||||||
glm::vec3 intersection { NAN };
|
glm::vec3 intersection { NAN };
|
||||||
|
PickRay searchRay;
|
||||||
glm::vec3 surfaceNormal { NAN };
|
glm::vec3 surfaceNormal { NAN };
|
||||||
};
|
};
|
||||||
Q_DECLARE_METATYPE(RayPickResult)
|
Q_DECLARE_METATYPE(RayPickResult)
|
||||||
|
|
Loading…
Reference in a new issue