can create static laser pointers, fixed a bug with multiple render states

This commit is contained in:
SamGondelman 2017-07-14 18:35:27 -07:00
parent 8f533636f5
commit af12b5a4bf
5 changed files with 106 additions and 90 deletions

View file

@ -12,6 +12,7 @@
#include "RayPickManager.h"
#include "JointRayPick.h"
#include "StaticRayPick.h"
#include "Application.h"
@ -22,8 +23,22 @@ LaserPointer::LaserPointer(const QString& jointName, const glm::vec3& posOffset,
{
_rayPickUID = RayPickManager::getInstance().addRayPick(std::make_shared<JointRayPick>(jointName, posOffset, dirOffset, filter, maxDistance, enabled));
if (!enabled) {
disableCurrentRenderState();
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 enabled) :
_renderingEnabled(enabled),
_renderStates(renderStates)
{
_rayPickUID = RayPickManager::getInstance().addRayPick(std::make_shared<StaticRayPick>(position, direction, filter, maxDistance, enabled));
for (auto& state : _renderStates.keys()) {
if (!enabled || state != _currentRenderState)
disableRenderState(state);
}
}
@ -44,11 +59,11 @@ void LaserPointer::enable() {
void LaserPointer::disable() {
RayPickManager::getInstance().disableRayPick(_rayPickUID);
_renderingEnabled = false;
if (!_currentRenderState.isEmpty() && _renderStates.contains(_currentRenderState)) disableCurrentRenderState();
if (!_currentRenderState.isEmpty() && _renderStates.contains(_currentRenderState)) disableRenderState(_currentRenderState);
}
void LaserPointer::setRenderState(const QString& state) {
if (!_currentRenderState.isEmpty() && _renderStates.contains(_currentRenderState)) disableCurrentRenderState();
if (!_currentRenderState.isEmpty() && _renderStates.contains(_currentRenderState)) disableRenderState(_currentRenderState);
_currentRenderState = state;
}
@ -56,24 +71,24 @@ const RayPickResult& LaserPointer::getPrevRayPickResult() {
return RayPickManager::getInstance().getPrevRayPickResult(_rayPickUID);
}
void LaserPointer::disableCurrentRenderState() {
if (!_renderStates[_currentRenderState].getStartID().isNull()) {
void LaserPointer::disableRenderState(const QString& renderState) {
if (!_renderStates[renderState].getStartID().isNull()) {
QVariantMap startProps;
startProps.insert("visible", false);
startProps.insert("ignoreRayIntersection", true);
qApp->getOverlays().editOverlay(_renderStates[_currentRenderState].getStartID(), startProps);
qApp->getOverlays().editOverlay(_renderStates[renderState].getStartID(), startProps);
}
if (!_renderStates[_currentRenderState].getPathID().isNull()) {
if (!_renderStates[renderState].getPathID().isNull()) {
QVariantMap pathProps;
pathProps.insert("visible", false);
pathProps.insert("ignoreRayIntersection", true);
qApp->getOverlays().editOverlay(_renderStates[_currentRenderState].getPathID(), pathProps);
qApp->getOverlays().editOverlay(_renderStates[renderState].getPathID(), pathProps);
}
if (!_renderStates[_currentRenderState].getEndID().isNull()) {
if (!_renderStates[renderState].getEndID().isNull()) {
QVariantMap endProps;
endProps.insert("visible", false);
endProps.insert("ignoreRayIntersection", true);
qApp->getOverlays().editOverlay(_renderStates[_currentRenderState].getEndID(), endProps);
qApp->getOverlays().editOverlay(_renderStates[renderState].getEndID(), endProps);
}
}
@ -105,13 +120,7 @@ void LaserPointer::update() {
qApp->getOverlays().editOverlay(_renderStates[_currentRenderState].getEndID(), endProps);
}
} else {
disableCurrentRenderState();
}
}
void LaserPointer::render(RenderArgs* args) {
if (_renderingEnabled && !_currentRenderState.isEmpty() && _renderStates.contains(_currentRenderState)) {
_renderStates[_currentRenderState].render(args);
disableRenderState(_currentRenderState);
}
}
@ -122,9 +131,3 @@ RenderState::RenderState(const OverlayID& startID, const OverlayID& pathID, cons
if (!_pathID.isNull()) _pathIgnoreRays = qApp->getOverlays().getOverlay(_pathID)->getProperty("ignoreRayIntersection").toBool();
if (!_endID.isNull()) _endIgnoreRays = qApp->getOverlays().getOverlay(_endID)->getProperty("ignoreRayIntersection").toBool();
}
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);
}

View file

@ -13,7 +13,6 @@
#include <QString>
#include "glm/glm.hpp"
#include <render/Scene.h>
#include "ui/overlays/Overlay.h"
class RayPickResult;
@ -24,8 +23,6 @@ public:
RenderState() {}
RenderState(const OverlayID& startID, const OverlayID& pathID, const OverlayID& endID);
void render(RenderArgs* args);
const OverlayID& getStartID() { return _startID; }
const OverlayID& getPathID() { return _pathID; }
const OverlayID& getEndID() { return _endID; }
@ -48,21 +45,19 @@ class LaserPointer {
public:
LaserPointer(const QString& jointName, const glm::vec3& posOffset, const glm::vec3& dirOffset, const uint16_t filter, const float maxDistance,
const QHash<QString, RenderState>& renderStates, 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 enabled);
~LaserPointer();
unsigned int getUID() { return _rayPickUID; }
void enable();
void disable();
void setRenderState(const QString& state);
const RayPickResult& getPrevRayPickResult();
void disableCurrentRenderState();
void setRenderState(const QString& state);
void disableRenderState(const QString& renderState);
void update();
void render(RenderArgs* args);
const render::ShapeKey getShapeKey() { return render::ShapeKey::Builder::ownPipeline(); }
private:
bool _renderingEnabled;

View file

@ -25,6 +25,13 @@ unsigned int LaserPointerManager::createLaserPointer(const QString& jointName, c
return uid;
}
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 enabled) {
std::shared_ptr<LaserPointer> laserPointer = std::make_shared<LaserPointer>(position, direction, filter, maxDistance, renderStates, enabled);
unsigned int uid = laserPointer->getUID();
_laserPointers[uid] = laserPointer;
return uid;
}
void LaserPointerManager::enableLaserPointer(const unsigned int uid) {
if (_laserPointers.contains(uid)) {
_laserPointers[uid]->enable();

View file

@ -27,6 +27,8 @@ public:
unsigned int createLaserPointer(const QString& jointName, const glm::vec3& posOffset, const glm::vec3& dirOffset, const uint16_t filter, const float maxDistance,
const QHash<QString, RenderState>& renderStates, 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 enabled);
void removeLaserPointer(const unsigned int uid) { _laserPointers.remove(uid); }
void enableLaserPointer(const unsigned int uid);
void disableLaserPointer(const unsigned int uid);

View file

@ -25,20 +25,6 @@ LaserPointerScriptingInterface* LaserPointerScriptingInterface::getInstance() {
uint32_t LaserPointerScriptingInterface::createLaserPointer(const QVariant& properties) {
QVariantMap propertyMap = properties.toMap();
if (propertyMap["joint"].isValid()) {
QString jointName = propertyMap["joint"].toString();
// 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"]);
}
uint16_t filter = 0;
if (propertyMap["filter"].isValid()) {
filter = propertyMap["filter"].toUInt();
@ -94,8 +80,31 @@ uint32_t LaserPointerScriptingInterface::createLaserPointer(const QVariant& prop
}
}
if (propertyMap["joint"].isValid()) {
QString jointName = propertyMap["joint"].toString();
// 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 LaserPointerManager::getInstance().createLaserPointer(jointName, posOffset, dirOffset, filter, maxDistance, renderStates, enabled);
} else {
} 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 LaserPointerManager::getInstance().createLaserPointer(position, direction, filter, maxDistance, renderStates, enabled);
}
return 0;
}
}