From 9256917f150b85aa241eab5109de33dcef72340f Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 1 Sep 2015 16:21:12 -0700 Subject: [PATCH] rebake mesh when a neighbor changes --- .../src/RenderablePolyVoxEntityItem.cpp | 60 +++++++++++++++++++ .../src/RenderablePolyVoxEntityItem.h | 10 ++++ libraries/entities/src/PolyVoxEntityItem.h | 13 ++-- 3 files changed, 77 insertions(+), 6 deletions(-) diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index 1944398cf6..cd150dc44c 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -746,6 +746,25 @@ bool RenderablePolyVoxEntityItem::setVoxelInternal(int x, int y, int z, uint8_t _volData->setVoxelAt(x, y, z, toValue); } + EntityItemPointer currentXNNeighbor = _xNNeighbor.lock(); + EntityItemPointer currentYNNeighbor = _yNNeighbor.lock(); + EntityItemPointer currentZNNeighbor = _zNNeighbor.lock(); + + if (result) { + if (x == 0 && currentXNNeighbor && currentXNNeighbor->getType() == EntityTypes::PolyVox) { + auto polyVoxXNNeighbor = std::dynamic_pointer_cast(currentXNNeighbor); + polyVoxXNNeighbor->rebakeMesh(); + } + if (y == 0 && currentYNNeighbor && currentYNNeighbor->getType() == EntityTypes::PolyVox) { + auto polyVoxYNNeighbor = std::dynamic_pointer_cast(currentYNNeighbor); + polyVoxYNNeighbor->rebakeMesh(); + } + if (z == 0 && currentZNNeighbor && currentZNNeighbor->getType() == EntityTypes::PolyVox) { + auto polyVoxZNNeighbor = std::dynamic_pointer_cast(currentZNNeighbor); + polyVoxZNNeighbor->rebakeMesh(); + } + } + return result; } @@ -1274,3 +1293,44 @@ void RenderablePolyVoxEntityItem::computeShapeInfoWorkerAsync() { _threadRunning.release(); return; } + + +void RenderablePolyVoxEntityItem::setXNNeighborID(const EntityItemID& xNNeighborID) { + PolyVoxEntityItem::setXNNeighborID(xNNeighborID); +} + +void RenderablePolyVoxEntityItem::setYNNeighborID(const EntityItemID& yNNeighborID) { + PolyVoxEntityItem::setYNNeighborID(yNNeighborID); +} + +void RenderablePolyVoxEntityItem::setZNNeighborID(const EntityItemID& zNNeighborID) { + PolyVoxEntityItem::setZNNeighborID(zNNeighborID); +} + + +void RenderablePolyVoxEntityItem::setXPNeighborID(const EntityItemID& xPNeighborID) { + if (xPNeighborID != _xPNeighborID) { + PolyVoxEntityItem::setXPNeighborID(xPNeighborID); + rebakeMesh(); + } +} + +void RenderablePolyVoxEntityItem::setYPNeighborID(const EntityItemID& yPNeighborID) { + if (yPNeighborID != _yPNeighborID) { + PolyVoxEntityItem::setYPNeighborID(yPNeighborID); + rebakeMesh(); + } +} + +void RenderablePolyVoxEntityItem::setZPNeighborID(const EntityItemID& zPNeighborID) { + if (zPNeighborID != _zPNeighborID) { + PolyVoxEntityItem::setZPNeighborID(zPNeighborID); + rebakeMesh(); + } +} + + +void RenderablePolyVoxEntityItem::rebakeMesh() { + QReadLocker(&this->_volDataLock); + _volDataDirty = true; +} diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h index 8e42884051..ee94310e18 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h @@ -106,6 +106,16 @@ public: std::shared_ptr scene, render::PendingChanges& pendingChanges); + virtual void setXNNeighborID(const EntityItemID& xNNeighborID); + virtual void setYNNeighborID(const EntityItemID& yNNeighborID); + virtual void setZNNeighborID(const EntityItemID& zNNeighborID); + + virtual void setXPNeighborID(const EntityItemID& xPNeighborID); + virtual void setYPNeighborID(const EntityItemID& yPNeighborID); + virtual void setZPNeighborID(const EntityItemID& zPNeighborID); + + virtual void rebakeMesh(); + private: // The PolyVoxEntityItem class has _voxelData which contains dimensions and compressed voxel data. The dimensions // may not match _voxelVolumeSize. diff --git a/libraries/entities/src/PolyVoxEntityItem.h b/libraries/entities/src/PolyVoxEntityItem.h index 69bfb9323b..20a0646c9b 100644 --- a/libraries/entities/src/PolyVoxEntityItem.h +++ b/libraries/entities/src/PolyVoxEntityItem.h @@ -105,25 +105,26 @@ class PolyVoxEntityItem : public EntityItem { virtual const QString& getZTextureURL() const { return _zTextureURL; } virtual void setXNNeighborID(const EntityItemID& xNNeighborID) { _xNNeighborID = xNNeighborID; } - virtual void setXNNeighborID(const QString& xNNeighborID) { _xNNeighborID = QUuid(xNNeighborID); } + void setXNNeighborID(const QString& xNNeighborID) { setXNNeighborID(QUuid(xNNeighborID)); } virtual const EntityItemID& getXNNeighborID() const { return _xNNeighborID; } virtual void setYNNeighborID(const EntityItemID& yNNeighborID) { _yNNeighborID = yNNeighborID; } - virtual void setYNNeighborID(const QString& yNNeighborID) { _yNNeighborID = QUuid(yNNeighborID); } + void setYNNeighborID(const QString& yNNeighborID) { setYNNeighborID(QUuid(yNNeighborID)); } virtual const EntityItemID& getYNNeighborID() const { return _yNNeighborID; } virtual void setZNNeighborID(const EntityItemID& zNNeighborID) { _zNNeighborID = zNNeighborID; } - virtual void setZNNeighborID(const QString& zNNeighborID) { _zNNeighborID = QUuid(zNNeighborID); } + void setZNNeighborID(const QString& zNNeighborID) { setZNNeighborID(QUuid(zNNeighborID)); } virtual const EntityItemID& getZNNeighborID() const { return _zNNeighborID; } virtual void setXPNeighborID(const EntityItemID& xPNeighborID) { _xPNeighborID = xPNeighborID; } - virtual void setXPNeighborID(const QString& xPNeighborID) { _xPNeighborID = QUuid(xPNeighborID); } + void setXPNeighborID(const QString& xPNeighborID) { setXPNeighborID(QUuid(xPNeighborID)); } virtual const EntityItemID& getXPNeighborID() const { return _xPNeighborID; } virtual void setYPNeighborID(const EntityItemID& yPNeighborID) { _yPNeighborID = yPNeighborID; } - virtual void setYPNeighborID(const QString& yPNeighborID) { _yPNeighborID = QUuid(yPNeighborID); } + void setYPNeighborID(const QString& yPNeighborID) { setYPNeighborID(QUuid(yPNeighborID)); } virtual const EntityItemID& getYPNeighborID() const { return _yPNeighborID; } virtual void setZPNeighborID(const EntityItemID& zPNeighborID) { _zPNeighborID = zPNeighborID; } - virtual void setZPNeighborID(const QString& zPNeighborID) { _zPNeighborID = QUuid(zPNeighborID); } + void setZPNeighborID(const QString& zPNeighborID) { setZPNeighborID(QUuid(zPNeighborID)); } virtual const EntityItemID& getZPNeighborID() const { return _zPNeighborID; } + virtual void rebakeMesh() {}; protected: glm::vec3 _voxelVolumeSize; // this is always 3 bytes