diff --git a/interface/src/renderer/MetavoxelSystem.cpp b/interface/src/renderer/MetavoxelSystem.cpp index 26f722f65c..18fb6de2ab 100644 --- a/interface/src/renderer/MetavoxelSystem.cpp +++ b/interface/src/renderer/MetavoxelSystem.cpp @@ -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& points) : MetavoxelVisitor(QVector() << 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 normal = info.attributeValues.at(1).getInlineValue(); - bool blerp = *info.attributeValues.at(2).getPointerValue(); 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), diff --git a/libraries/metavoxels/CMakeLists.txt b/libraries/metavoxels/CMakeLists.txt index 92594af4ef..0f9c1c695c 100644 --- a/libraries/metavoxels/CMakeLists.txt +++ b/libraries/metavoxels/CMakeLists.txt @@ -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}) diff --git a/libraries/metavoxels/src/AttributeRegistry.cpp b/libraries/metavoxels/src/AttributeRegistry.cpp index 7eb295490d..2b1875223e 100644 --- a/libraries/metavoxels/src/AttributeRegistry.cpp +++ b/libraries/metavoxels/src/AttributeRegistry.cpp @@ -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("voxelizer", false))) { + _normalAttribute(registerAttribute(new QRgbAttribute("normal", qRgb(0, 127, 0)))) { } AttributePointer AttributeRegistry::registerAttribute(AttributePointer attribute) { diff --git a/libraries/metavoxels/src/AttributeRegistry.h b/libraries/metavoxels/src/AttributeRegistry.h index e956be078b..f905c08eb0 100644 --- a/libraries/metavoxels/src/AttributeRegistry.h +++ b/libraries/metavoxels/src/AttributeRegistry.h @@ -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 _attributes; + AttributePointer _guideAttribute; AttributePointer _colorAttribute; AttributePointer _normalAttribute; - AttributePointer _voxelizerAttribute; }; /// Converts a value to a void pointer. @@ -253,7 +253,8 @@ typedef QSharedDataPointer PolymorphicDataPointer; /// Provides polymorphic streaming and averaging. class PolymorphicAttribute : public InlineAttribute { - +public: + PolymorphicAttribute(const QString& name, const PolymorphicDataPointer& defaultValue = PolymorphicDataPointer()); virtual bool merge(void*& parent, void* children[]) const; diff --git a/libraries/metavoxels/src/MetavoxelData.cpp b/libraries/metavoxels/src/MetavoxelData.cpp index d128e06296..0eb7b55165 100644 --- a/libraries/metavoxels/src/MetavoxelData.cpp +++ b/libraries/metavoxels/src/MetavoxelData.cpp @@ -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& 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 { +} diff --git a/libraries/metavoxels/src/MetavoxelData.h b/libraries/metavoxels/src/MetavoxelData.h index dc3ff133d3..b43292bf0b 100644 --- a/libraries/metavoxels/src/MetavoxelData.h +++ b/libraries/metavoxels/src/MetavoxelData.h @@ -11,6 +11,7 @@ #include #include +#include #include #include @@ -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 _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__) */