mirror of
https://github.com/overte-org/overte.git
synced 2025-08-04 20:57:09 +02:00
can create static laser pointers, fixed a bug with multiple render states
This commit is contained in:
parent
8f533636f5
commit
af12b5a4bf
5 changed files with 106 additions and 90 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -121,10 +130,4 @@ RenderState::RenderState(const OverlayID& startID, const OverlayID& pathID, cons
|
|||
if (!_startID.isNull()) _startIgnoreRays = qApp->getOverlays().getOverlay(_startID)->getProperty("ignoreRayIntersection").toBool();
|
||||
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);
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -25,6 +25,61 @@ LaserPointerScriptingInterface* LaserPointerScriptingInterface::getInstance() {
|
|||
uint32_t LaserPointerScriptingInterface::createLaserPointer(const QVariant& properties) {
|
||||
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 enabled = false;
|
||||
if (propertyMap["enabled"].isValid()) {
|
||||
enabled = propertyMap["enabled"].toBool();
|
||||
}
|
||||
|
||||
QHash<QString, RenderState> renderStates;
|
||||
if (propertyMap["renderStates"].isValid()) {
|
||||
QList<QVariant> renderStateVariants = propertyMap["renderStates"].toList();
|
||||
for (QVariant& renderStateVariant : renderStateVariants) {
|
||||
if (renderStateVariant.isValid()) {
|
||||
QVariantMap renderStateMap = renderStateVariant.toMap();
|
||||
if (renderStateMap["name"].isValid()) {
|
||||
QString name = renderStateMap["name"].toString();
|
||||
|
||||
QUuid startID;
|
||||
if (renderStateMap["start"].isValid()) {
|
||||
QVariantMap startMap = renderStateMap["start"].toMap();
|
||||
if (startMap["type"].isValid()) {
|
||||
startID = qApp->getOverlays().addOverlay(startMap["type"].toString(), startMap);
|
||||
}
|
||||
}
|
||||
|
||||
QUuid pathID;
|
||||
if (renderStateMap["path"].isValid()) {
|
||||
QVariantMap pathMap = renderStateMap["path"].toMap();
|
||||
// right now paths must be line3ds
|
||||
if (pathMap["type"].isValid() && pathMap["type"].toString() == "line3d") {
|
||||
pathID = qApp->getOverlays().addOverlay(pathMap["type"].toString(), pathMap);
|
||||
}
|
||||
}
|
||||
|
||||
QUuid endID;
|
||||
if (renderStateMap["end"].isValid()) {
|
||||
QVariantMap endMap = renderStateMap["end"].toMap();
|
||||
if (endMap["type"].isValid()) {
|
||||
endID = qApp->getOverlays().addOverlay(endMap["type"].toString(), endMap);
|
||||
}
|
||||
}
|
||||
|
||||
renderStates[name] = RenderState(startID, pathID, endID);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (propertyMap["joint"].isValid()) {
|
||||
QString jointName = propertyMap["joint"].toString();
|
||||
|
||||
|
@ -39,63 +94,17 @@ uint32_t LaserPointerScriptingInterface::createLaserPointer(const QVariant& prop
|
|||
dirOffset = vec3FromVariant(propertyMap["dirOffset"]);
|
||||
}
|
||||
|
||||
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 enabled = false;
|
||||
if (propertyMap["enabled"].isValid()) {
|
||||
enabled = propertyMap["enabled"].toBool();
|
||||
}
|
||||
|
||||
QHash<QString, RenderState> renderStates;
|
||||
if (propertyMap["renderStates"].isValid()) {
|
||||
QList<QVariant> renderStateVariants = propertyMap["renderStates"].toList();
|
||||
for (QVariant& renderStateVariant : renderStateVariants) {
|
||||
if (renderStateVariant.isValid()) {
|
||||
QVariantMap renderStateMap = renderStateVariant.toMap();
|
||||
if (renderStateMap["name"].isValid()) {
|
||||
QString name = renderStateMap["name"].toString();
|
||||
|
||||
QUuid startID;
|
||||
if (renderStateMap["start"].isValid()) {
|
||||
QVariantMap startMap = renderStateMap["start"].toMap();
|
||||
if (startMap["type"].isValid()) {
|
||||
startID = qApp->getOverlays().addOverlay(startMap["type"].toString(), startMap);
|
||||
}
|
||||
}
|
||||
|
||||
QUuid pathID;
|
||||
if (renderStateMap["path"].isValid()) {
|
||||
QVariantMap pathMap = renderStateMap["path"].toMap();
|
||||
// right now paths must be line3ds
|
||||
if (pathMap["type"].isValid() && pathMap["type"].toString() == "line3d") {
|
||||
pathID = qApp->getOverlays().addOverlay(pathMap["type"].toString(), pathMap);
|
||||
}
|
||||
}
|
||||
|
||||
QUuid endID;
|
||||
if (renderStateMap["end"].isValid()) {
|
||||
QVariantMap endMap = renderStateMap["end"].toMap();
|
||||
if (endMap["type"].isValid()) {
|
||||
endID = qApp->getOverlays().addOverlay(endMap["type"].toString(), endMap);
|
||||
}
|
||||
}
|
||||
|
||||
renderStates[name] = RenderState(startID, pathID, endID);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return LaserPointerManager::getInstance().createLaserPointer(jointName, posOffset, dirOffset, filter, maxDistance, renderStates, enabled);
|
||||
} else {
|
||||
return 0;
|
||||
} 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;
|
||||
}
|
Loading…
Reference in a new issue