From 1a1b1ca3f3f2cea68117a9aeb89fe6af4d26aadd Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Tue, 2 Dec 2014 19:49:27 -0800 Subject: [PATCH] Fix for voxelizing heightfields. --- interface/src/ui/MetavoxelEditor.cpp | 1 + libraries/metavoxels/src/Spanner.cpp | 14 +++++++++++++- libraries/metavoxels/src/Spanner.h | 5 +++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/interface/src/ui/MetavoxelEditor.cpp b/interface/src/ui/MetavoxelEditor.cpp index 6989c47d67..26b403e423 100644 --- a/interface/src/ui/MetavoxelEditor.cpp +++ b/interface/src/ui/MetavoxelEditor.cpp @@ -1014,6 +1014,7 @@ QColor VoxelMaterialSpannerTool::getColor() { } void VoxelMaterialSpannerTool::applyEdit(const AttributePointer& attribute, const SharedObjectPointer& spanner) { + static_cast(spanner.data())->setWillBeVoxelized(true); MetavoxelEditMessage message = { QVariant::fromValue(VoxelMaterialSpannerEdit(spanner, _materialControl->getMaterial(), _materialControl->getColor())) }; Application::getInstance()->getMetavoxels()->applyEdit(message, true); diff --git a/libraries/metavoxels/src/Spanner.cpp b/libraries/metavoxels/src/Spanner.cpp index 69bc919e9c..f249ae2912 100644 --- a/libraries/metavoxels/src/Spanner.cpp +++ b/libraries/metavoxels/src/Spanner.cpp @@ -61,7 +61,8 @@ Spanner::Spanner() : _renderer(NULL), _placementGranularity(DEFAULT_PLACEMENT_GRANULARITY), _voxelizationGranularity(DEFAULT_VOXELIZATION_GRANULARITY), - _merged(false) { + _merged(false), + _willBeVoxelized(false) { } void Spanner::setBounds(const Box& bounds) { @@ -2542,6 +2543,9 @@ MetavoxelLOD Heightfield::transformLOD(const MetavoxelLOD& lod) const { SharedObject* Heightfield::clone(bool withID, SharedObject* target) const { Heightfield* newHeightfield = static_cast(Spanner::clone(withID, target)); + newHeightfield->setHeight(_height); + newHeightfield->setColor(_color); + newHeightfield->setMaterial(_material); newHeightfield->setRoot(_root); return newHeightfield; } @@ -2920,6 +2924,10 @@ bool Heightfield::intersects(const glm::vec3& start, const glm::vec3& end, float } void Heightfield::writeExtra(Bitstream& out) const { + if (getWillBeVoxelized()) { + out << _height << _color << _material; + return; + } MetavoxelLOD lod; if (out.getContext()) { lod = transformLOD(static_cast(out.getContext())->lod); @@ -2930,6 +2938,10 @@ void Heightfield::writeExtra(Bitstream& out) const { } void Heightfield::readExtra(Bitstream& in) { + if (getWillBeVoxelized()) { + in >> _height >> _color >> _material; + return; + } MetavoxelLOD lod; if (in.getContext()) { lod = transformLOD(static_cast(in.getContext())->lod); diff --git a/libraries/metavoxels/src/Spanner.h b/libraries/metavoxels/src/Spanner.h index 6742324f85..c4fe185a58 100644 --- a/libraries/metavoxels/src/Spanner.h +++ b/libraries/metavoxels/src/Spanner.h @@ -29,6 +29,7 @@ class Spanner : public SharedObject { Q_PROPERTY(Box bounds MEMBER _bounds WRITE setBounds NOTIFY boundsChanged DESIGNABLE false) Q_PROPERTY(float placementGranularity MEMBER _placementGranularity DESIGNABLE false) Q_PROPERTY(float voxelizationGranularity MEMBER _voxelizationGranularity DESIGNABLE false) + Q_PROPERTY(bool willBeVoxelized MEMBER _willBeVoxelized DESIGNABLE false) public: @@ -49,6 +50,9 @@ public: void setMerged(bool merged) { _merged = merged; } bool isMerged() const { return _merged; } + void setWillBeVoxelized(bool willBeVoxelized) { _willBeVoxelized = willBeVoxelized; } + bool getWillBeVoxelized() const { return _willBeVoxelized; } + /// Checks whether we've visited this object on the current traversal. If we have, returns false. /// If we haven't, sets the last visit identifier and returns true. bool testAndSetVisited(int visit); @@ -118,6 +122,7 @@ private: float _placementGranularity; float _voxelizationGranularity; bool _merged; + bool _willBeVoxelized; QHash _lastVisits; ///< last visit identifiers for each thread QMutex _lastVisitsMutex;