mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-04 21:03:09 +02:00
Working on guide/script support.
This commit is contained in:
parent
5458e7a555
commit
0ca2320711
6 changed files with 65 additions and 21 deletions
|
@ -39,16 +39,13 @@ void MetavoxelSystem::init() {
|
|||
|
||||
_data.setAttributeValue(p1, AttributeValue(color, encodeInline(qRgba(0xFF, 0xFF, 0xFF, 0xFF))));
|
||||
|
||||
bool blerp = true;
|
||||
_data.setAttributeValue(p1, AttributeValue(AttributeRegistry::getInstance()->getAttribute("voxelizer"), &blerp));
|
||||
|
||||
_buffer.setUsagePattern(QOpenGLBuffer::DynamicDraw);
|
||||
_buffer.create();
|
||||
}
|
||||
|
||||
void MetavoxelSystem::simulate(float deltaTime) {
|
||||
_points.clear();
|
||||
_data.traverse(_pointVisitor);
|
||||
_data.guide(_pointVisitor);
|
||||
|
||||
_buffer.bind();
|
||||
int bytes = _points.size() * sizeof(Point);
|
||||
|
@ -104,8 +101,7 @@ void MetavoxelSystem::render() {
|
|||
MetavoxelSystem::PointVisitor::PointVisitor(QVector<Point>& points) :
|
||||
MetavoxelVisitor(QVector<AttributePointer>() <<
|
||||
AttributeRegistry::getInstance()->getColorAttribute() <<
|
||||
AttributeRegistry::getInstance()->getNormalAttribute() <<
|
||||
AttributeRegistry::getInstance()->getVoxelizerAttribute()),
|
||||
AttributeRegistry::getInstance()->getNormalAttribute()),
|
||||
_points(points) {
|
||||
}
|
||||
|
||||
|
@ -115,7 +111,6 @@ bool MetavoxelSystem::PointVisitor::visit(const MetavoxelInfo& info) {
|
|||
}
|
||||
QRgb color = info.attributeValues.at(0).getInlineValue<QRgb>();
|
||||
QRgb normal = info.attributeValues.at(1).getInlineValue<QRgb>();
|
||||
bool blerp = *info.attributeValues.at(2).getPointerValue<bool>();
|
||||
int alpha = qAlpha(color);
|
||||
if (alpha > 0) {
|
||||
Point point = { glm::vec4(info.minimum + glm::vec3(info.size, info.size, info.size) * 0.5f, info.size),
|
||||
|
|
|
@ -13,7 +13,7 @@ find_package(Qt5Widgets REQUIRED)
|
|||
include(${MACRO_DIR}/SetupHifiLibrary.cmake)
|
||||
setup_hifi_library(${TARGET_NAME})
|
||||
|
||||
qt5_use_modules(${TARGET_NAME} Widgets)
|
||||
qt5_use_modules(${TARGET_NAME} Widgets Script)
|
||||
|
||||
include(${MACRO_DIR}/IncludeGLM.cmake)
|
||||
include_glm(${TARGET_NAME} ${ROOT_DIR})
|
||||
|
|
|
@ -7,13 +7,14 @@
|
|||
//
|
||||
|
||||
#include "AttributeRegistry.h"
|
||||
#include "MetavoxelData.h"
|
||||
|
||||
AttributeRegistry AttributeRegistry::_instance;
|
||||
|
||||
AttributeRegistry::AttributeRegistry() :
|
||||
_guideAttribute(registerAttribute(new PolymorphicAttribute("guide", PolymorphicDataPointer(new DefaultMetavoxelGuide())))),
|
||||
_colorAttribute(registerAttribute(new QRgbAttribute("color"))),
|
||||
_normalAttribute(registerAttribute(new QRgbAttribute("normal", qRgb(0, 127, 0)))),
|
||||
_voxelizerAttribute(registerAttribute(new SimplePointerAttribute<bool>("voxelizer", false))) {
|
||||
_normalAttribute(registerAttribute(new QRgbAttribute("normal", qRgb(0, 127, 0)))) {
|
||||
}
|
||||
|
||||
AttributePointer AttributeRegistry::registerAttribute(AttributePointer attribute) {
|
||||
|
|
|
@ -44,23 +44,23 @@ public:
|
|||
/// Retrieves an attribute by name.
|
||||
AttributePointer getAttribute(const QString& name) const { return _attributes.value(name); }
|
||||
|
||||
/// Returns a reference to the standard PolymorphicDataPointer "guide" attribute.
|
||||
const AttributePointer& getGuideAttribute() const { return _guideAttribute; }
|
||||
|
||||
/// Returns a reference to the standard QRgb "color" attribute.
|
||||
const AttributePointer& getColorAttribute() const { return _colorAttribute; }
|
||||
|
||||
/// Returns a reference to the standard QRgb "normal" attribute.
|
||||
const AttributePointer& getNormalAttribute() const { return _normalAttribute; }
|
||||
|
||||
/// Returns a reference to the standard "voxelizer" attribute.
|
||||
const AttributePointer& getVoxelizerAttribute() const { return _voxelizerAttribute; }
|
||||
|
||||
private:
|
||||
|
||||
static AttributeRegistry _instance;
|
||||
|
||||
QHash<QString, AttributePointer> _attributes;
|
||||
AttributePointer _guideAttribute;
|
||||
AttributePointer _colorAttribute;
|
||||
AttributePointer _normalAttribute;
|
||||
AttributePointer _voxelizerAttribute;
|
||||
};
|
||||
|
||||
/// Converts a value to a void pointer.
|
||||
|
@ -253,7 +253,8 @@ typedef QSharedDataPointer<PolymorphicData> PolymorphicDataPointer;
|
|||
|
||||
/// Provides polymorphic streaming and averaging.
|
||||
class PolymorphicAttribute : public InlineAttribute<PolymorphicDataPointer> {
|
||||
|
||||
public:
|
||||
|
||||
PolymorphicAttribute(const QString& name, const PolymorphicDataPointer& defaultValue = PolymorphicDataPointer());
|
||||
|
||||
virtual bool merge(void*& parent, void* children[]) const;
|
||||
|
|
|
@ -63,7 +63,7 @@ bool Visitation::allNodesLeaves() const {
|
|||
return true;
|
||||
}
|
||||
|
||||
void MetavoxelData::traverse(MetavoxelVisitor& visitor) {
|
||||
void MetavoxelData::guide(MetavoxelVisitor& visitor) {
|
||||
// start with the root values/defaults
|
||||
const float TOP_LEVEL_SIZE = 1.0f;
|
||||
const QVector<AttributePointer>& attributes = visitor.getAttributes();
|
||||
|
@ -202,3 +202,19 @@ MetavoxelPath& MetavoxelPath::operator+=(int element) {
|
|||
return *this;
|
||||
}
|
||||
|
||||
PolymorphicData* DefaultMetavoxelGuide::clone() const {
|
||||
return new DefaultMetavoxelGuide();
|
||||
}
|
||||
|
||||
void DefaultMetavoxelGuide::guide(MetavoxelTour& tour) const {
|
||||
}
|
||||
|
||||
ScriptedMetavoxelGuide::ScriptedMetavoxelGuide(const QScriptValue& guideFunction) : _guideFunction(guideFunction) {
|
||||
}
|
||||
|
||||
PolymorphicData* ScriptedMetavoxelGuide::clone() const {
|
||||
return new ScriptedMetavoxelGuide(_guideFunction);
|
||||
}
|
||||
|
||||
void ScriptedMetavoxelGuide::guide(MetavoxelTour& tour) const {
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
#include <QBitArray>
|
||||
#include <QHash>
|
||||
#include <QScriptValue>
|
||||
#include <QVector>
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
@ -19,6 +20,7 @@
|
|||
|
||||
class MetavoxelNode;
|
||||
class MetavoxelPath;
|
||||
class MetavoxelTour;
|
||||
class MetavoxelVisitor;
|
||||
|
||||
/// The base metavoxel representation shared between server and client.
|
||||
|
@ -28,7 +30,7 @@ public:
|
|||
~MetavoxelData();
|
||||
|
||||
/// Applies the specified visitor to the contained voxels.
|
||||
void traverse(MetavoxelVisitor& visitor);
|
||||
void guide(MetavoxelVisitor& visitor);
|
||||
|
||||
/// Sets the attribute value corresponding to the specified path.
|
||||
void setAttributeValue(const MetavoxelPath& path, const AttributeValue& attributeValue);
|
||||
|
@ -123,12 +125,41 @@ protected:
|
|||
QVector<AttributePointer> _attributes;
|
||||
};
|
||||
|
||||
/// Interface for objects that host metavoxel visitors.
|
||||
class MetavoxelTraverser : public PolymorphicData {
|
||||
/// Interface for objects that guide metavoxel visitors.
|
||||
class MetavoxelGuide : public PolymorphicData {
|
||||
public:
|
||||
|
||||
/// Applies the specified visitor to the contained voxels.
|
||||
virtual void traverse(MetavoxelVisitor& visitor) = 0;
|
||||
/// Guides the specified visitor to the contained voxels.
|
||||
virtual void guide(MetavoxelTour& tour) const = 0;
|
||||
};
|
||||
|
||||
/// Guides visitors through the explicit content of the system.
|
||||
class DefaultMetavoxelGuide : public MetavoxelGuide {
|
||||
public:
|
||||
|
||||
virtual PolymorphicData* clone() const;
|
||||
|
||||
virtual void guide(MetavoxelTour& tour) const;
|
||||
};
|
||||
|
||||
/// Represents a guide implemented in Javascript.
|
||||
class ScriptedMetavoxelGuide : public MetavoxelGuide {
|
||||
public:
|
||||
|
||||
ScriptedMetavoxelGuide(const QScriptValue& guideFunction);
|
||||
|
||||
virtual PolymorphicData* clone() const;
|
||||
|
||||
virtual void guide(MetavoxelTour& tour) const;
|
||||
|
||||
private:
|
||||
|
||||
QScriptValue _guideFunction;
|
||||
};
|
||||
|
||||
/// Contains the state associated with a tour of a metavoxel system.
|
||||
class MetavoxelTour {
|
||||
|
||||
};
|
||||
|
||||
#endif /* defined(__interface__MetavoxelData__) */
|
||||
|
|
Loading…
Reference in a new issue