mirror of
https://github.com/overte-org/overte.git
synced 2025-08-05 01:59:59 +02:00
working on renderstates
This commit is contained in:
parent
3a35cd128f
commit
3c719b26b1
6 changed files with 97 additions and 17 deletions
|
@ -13,7 +13,12 @@
|
|||
#include "RayPickManager.h"
|
||||
#include "JointRayPick.h"
|
||||
|
||||
LaserPointer::LaserPointer(const QString& jointName, const glm::vec3& posOffset, const glm::vec3& dirOffset, const uint16_t filter, const float maxDistance, const bool enabled)
|
||||
#include "Application.h"
|
||||
|
||||
LaserPointer::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) :
|
||||
_renderingEnabled(enabled),
|
||||
_renderStates(renderStates)
|
||||
{
|
||||
_rayPickUID = RayPickManager::getInstance().addRayPick(std::make_shared<JointRayPick>(jointName, posOffset, dirOffset, filter, maxDistance, enabled));
|
||||
}
|
||||
|
@ -24,16 +29,26 @@ LaserPointer::~LaserPointer() {
|
|||
|
||||
void LaserPointer::enable() {
|
||||
RayPickManager::getInstance().enableRayPick(_rayPickUID);
|
||||
// TODO:
|
||||
// turn on rendering
|
||||
_renderingEnabled = true;
|
||||
}
|
||||
|
||||
void LaserPointer::disable() {
|
||||
RayPickManager::getInstance().disableRayPick(_rayPickUID);
|
||||
// TODO:
|
||||
// turn off rendering
|
||||
_renderingEnabled = false;
|
||||
}
|
||||
|
||||
const RayPickResult& LaserPointer::getPrevRayPickResult() {
|
||||
return RayPickManager::getInstance().getPrevRayPickResult(_rayPickUID);
|
||||
}
|
||||
}
|
||||
|
||||
void LaserPointer::render(RenderArgs* args) {
|
||||
if (_renderingEnabled && !_currentRenderState.isEmpty() && _renderStates.contains(_currentRenderState)) {
|
||||
_renderStates[_currentRenderState].render(args);
|
||||
}
|
||||
}
|
||||
|
||||
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,25 +13,49 @@
|
|||
|
||||
#include <QString>
|
||||
#include "glm/glm.hpp"
|
||||
#include <render/Scene.h>
|
||||
#include "ui/overlays/Overlay.h"
|
||||
|
||||
class RayPickResult;
|
||||
|
||||
class RenderState {
|
||||
|
||||
public:
|
||||
RenderState() {}
|
||||
RenderState(const OverlayID& startID, const OverlayID& pathID, const OverlayID& endID) :
|
||||
_startID(startID), _pathID(pathID), _endID(endID) {}
|
||||
|
||||
void render(RenderArgs* args);
|
||||
|
||||
private:
|
||||
OverlayID _startID;
|
||||
OverlayID _pathID;
|
||||
OverlayID _endID;
|
||||
};
|
||||
|
||||
|
||||
class LaserPointer {
|
||||
|
||||
public:
|
||||
LaserPointer(const QString& jointName, const glm::vec3& posOffset, const glm::vec3& dirOffset, const uint16_t filter, const float maxDistance, bool enabled);
|
||||
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();
|
||||
|
||||
unsigned int getUID() { return _rayPickUID; }
|
||||
void enable();
|
||||
void disable();
|
||||
|
||||
// void setRenderState(const QString& stateName);
|
||||
// void setRenderStateProperties(const QHash<QString, triplet of properties>& renderStateProperties);
|
||||
void setRenderState(const QString& state) { _currentRenderState = state; }
|
||||
|
||||
const RayPickResult& getPrevRayPickResult();
|
||||
|
||||
void render(RenderArgs* args);
|
||||
const render::ShapeKey getShapeKey() { return render::ShapeKey::Builder::ownPipeline(); }
|
||||
|
||||
private:
|
||||
bool _renderingEnabled;
|
||||
QString _currentRenderState { "" };
|
||||
QHash<QString, RenderState> _renderStates;
|
||||
unsigned int _rayPickUID;
|
||||
};
|
||||
|
||||
|
|
|
@ -17,8 +17,9 @@ LaserPointerManager& LaserPointerManager::getInstance() {
|
|||
return instance;
|
||||
}
|
||||
|
||||
unsigned int LaserPointerManager::createLaserPointer(const QString& jointName, const glm::vec3& posOffset, const glm::vec3& dirOffset, const uint16_t filter, const float maxDistance, bool enabled) {
|
||||
std::shared_ptr<LaserPointer> laserPointer = std::make_shared<LaserPointer>(jointName, posOffset, dirOffset, filter, maxDistance, enabled);
|
||||
unsigned int LaserPointerManager::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) {
|
||||
std::shared_ptr<LaserPointer> laserPointer = std::make_shared<LaserPointer>(jointName, posOffset, dirOffset, filter, maxDistance, renderStates, enabled);
|
||||
unsigned int uid = laserPointer->getUID();
|
||||
_laserPointers[uid] = laserPointer;
|
||||
return uid;
|
||||
|
|
|
@ -16,7 +16,8 @@
|
|||
#include <memory>
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
class LaserPointer;
|
||||
#include "LaserPointer.h"
|
||||
|
||||
class RayPickResult;
|
||||
|
||||
class LaserPointerManager {
|
||||
|
@ -24,7 +25,8 @@ class LaserPointerManager {
|
|||
public:
|
||||
static LaserPointerManager& getInstance();
|
||||
|
||||
unsigned int createLaserPointer(const QString& jointName, const glm::vec3& posOffset, const glm::vec3& dirOffset, const uint16_t filter, const float maxDistance, bool enabled);
|
||||
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);
|
||||
void removeLaserPointer(const unsigned int uid) { _laserPointers.remove(uid); }
|
||||
void enableLaserPointer(const unsigned int uid);
|
||||
void disableLaserPointer(const unsigned int uid);
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
#include "RegisteredMetaTypes.h"
|
||||
#include "GLMHelpers.h"
|
||||
|
||||
#include "Application.h"
|
||||
|
||||
LaserPointerScriptingInterface* LaserPointerScriptingInterface::getInstance() {
|
||||
static LaserPointerScriptingInterface instance;
|
||||
return &instance;
|
||||
|
@ -52,10 +54,46 @@ uint32_t LaserPointerScriptingInterface::createLaserPointer(const QVariant& prop
|
|||
enabled = propertyMap["enabled"].toBool();
|
||||
}
|
||||
|
||||
// TODO:
|
||||
// handle render state properties
|
||||
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();
|
||||
|
||||
return LaserPointerManager::getInstance().createLaserPointer(jointName, posOffset, dirOffset, filter, maxDistance, enabled);
|
||||
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();
|
||||
if (pathMap["type"].isValid()) {
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ void RayPickManager::cacheResult(const bool intersects, const RayPickResult& res
|
|||
|
||||
void RayPickManager::update() {
|
||||
QHash<QPair<glm::vec3, glm::vec3>, QHash<unsigned int, RayPickResult>> results;
|
||||
for (auto &rayPick : _rayPicks) {
|
||||
for (auto& rayPick : _rayPicks) {
|
||||
if (!rayPick->isEnabled() || rayPick->getFilter() == RayPickMask::PICK_NOTHING || rayPick->getMaxDistance() < 0.0f) {
|
||||
continue;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue