From 3af916e27eecd60e52af19b256d1fea3d1439dff Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 27 May 2015 09:32:10 -0700 Subject: [PATCH] use enum for polyvox surface style --- .../src/RenderablePolyVoxEntityItem.cpp | 21 ++++++++++++------- libraries/entities/src/EntityItem.cpp | 4 ++-- libraries/entities/src/PolyVoxEntityItem.cpp | 5 +++-- libraries/entities/src/PolyVoxEntityItem.h | 16 ++++++++++---- 4 files changed, 30 insertions(+), 16 deletions(-) diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index 6d06263cea..647e2fb280 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -126,14 +126,19 @@ void RenderablePolyVoxEntityItem::getModel() { // A mesh object to hold the result of surface extraction PolyVox::SurfaceMesh polyVoxMesh; - if (_voxelSurfaceStyle == 0) { - PolyVox::MarchingCubesSurfaceExtractor> surfaceExtractor - (_volData, _volData->getEnclosingRegion(), &polyVoxMesh); - surfaceExtractor.execute(); - } else { - PolyVox::CubicSurfaceExtractorWithNormals> surfaceExtractor - (_volData, _volData->getEnclosingRegion(), &polyVoxMesh); - surfaceExtractor.execute(); + switch (_voxelSurfaceStyle) { + case PolyVoxEntityItem::SURFACE_MARCHING_CUBES: { + PolyVox::MarchingCubesSurfaceExtractor> surfaceExtractor + (_volData, _volData->getEnclosingRegion(), &polyVoxMesh); + surfaceExtractor.execute(); + break; + } + case PolyVoxEntityItem::SURFACE_CUBIC: { + PolyVox::CubicSurfaceExtractorWithNormals> surfaceExtractor + (_volData, _volData->getEnclosingRegion(), &polyVoxMesh); + surfaceExtractor.execute(); + break; + } } // convert PolyVox mesh to a Sam mesh diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 38bc744e63..275b22b4a7 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -661,12 +661,12 @@ void EntityItem::adjustEditPacketForClockSkew(unsigned char* editPacketBuffer, s assert(lastEditedInLocalTime > 0); quint64 lastEditedInServerTime = lastEditedInLocalTime + clockSkew; memcpy(dataAt, &lastEditedInServerTime, sizeof(lastEditedInServerTime)); - //#ifdef WANT_DEBUG + #ifdef WANT_DEBUG qCDebug(entities, "EntityItem::adjustEditPacketForClockSkew()..."); qCDebug(entities) << " lastEditedInLocalTime: " << lastEditedInLocalTime; qCDebug(entities) << " clockSkew: " << clockSkew; qCDebug(entities) << " lastEditedInServerTime: " << lastEditedInServerTime; - //#endif + #endif } float EntityItem::computeMass() const { diff --git a/libraries/entities/src/PolyVoxEntityItem.cpp b/libraries/entities/src/PolyVoxEntityItem.cpp index a170d67241..5ba74dbff5 100644 --- a/libraries/entities/src/PolyVoxEntityItem.cpp +++ b/libraries/entities/src/PolyVoxEntityItem.cpp @@ -23,7 +23,8 @@ const glm::vec3 PolyVoxEntityItem::DEFAULT_VOXEL_VOLUME_SIZE = glm::vec3(32, 32, 32); const QByteArray PolyVoxEntityItem::DEFAULT_VOXEL_DATA(qCompress(QByteArray(0), 9)); -const int PolyVoxEntityItem::DEFAULT_VOXEL_SURFACE_STYLE = 0; +const PolyVoxEntityItem::PolyVoxSurfaceStyle PolyVoxEntityItem::DEFAULT_VOXEL_SURFACE_STYLE = + PolyVoxEntityItem::SURFACE_MARCHING_CUBES; EntityItemPointer PolyVoxEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { return EntityItemPointer(new PolyVoxEntityItem(entityID, properties)); @@ -116,7 +117,7 @@ void PolyVoxEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeB APPEND_ENTITY_PROPERTY(PROP_COLOR, getColor()); APPEND_ENTITY_PROPERTY(PROP_VOXEL_VOLUME_SIZE, getVoxelVolumeSize()); APPEND_ENTITY_PROPERTY(PROP_VOXEL_DATA, getVoxelData()); - APPEND_ENTITY_PROPERTY(PROP_VOXEL_SURFACE_STYLE, getVoxelSurfaceStyle()); + APPEND_ENTITY_PROPERTY(PROP_VOXEL_SURFACE_STYLE, (uint16_t) getVoxelSurfaceStyle()); } void PolyVoxEntityItem::debugDump() const { diff --git a/libraries/entities/src/PolyVoxEntityItem.h b/libraries/entities/src/PolyVoxEntityItem.h index d658ad365a..53675e6efa 100644 --- a/libraries/entities/src/PolyVoxEntityItem.h +++ b/libraries/entities/src/PolyVoxEntityItem.h @@ -67,12 +67,20 @@ class PolyVoxEntityItem : public EntityItem { virtual void setVoxelData(QByteArray voxelData) { _voxelData = voxelData; } virtual const QByteArray& getVoxelData() const { return _voxelData; } - virtual void setVoxelSurfaceStyle(uint16_t voxelSurfaceStyle) { _voxelSurfaceStyle = voxelSurfaceStyle; } - virtual uint16_t getVoxelSurfaceStyle() const { return _voxelSurfaceStyle; } + enum PolyVoxSurfaceStyle { + SURFACE_MARCHING_CUBES, + SURFACE_CUBIC + }; + + virtual void setVoxelSurfaceStyle(PolyVoxSurfaceStyle voxelSurfaceStyle) { _voxelSurfaceStyle = voxelSurfaceStyle; } + virtual void setVoxelSurfaceStyle(uint16_t voxelSurfaceStyle) { + _voxelSurfaceStyle = (PolyVoxSurfaceStyle) voxelSurfaceStyle; + } + virtual PolyVoxSurfaceStyle getVoxelSurfaceStyle() const { return _voxelSurfaceStyle; } static const glm::vec3 DEFAULT_VOXEL_VOLUME_SIZE; static const QByteArray DEFAULT_VOXEL_DATA; - static const int DEFAULT_VOXEL_SURFACE_STYLE; + static const PolyVoxSurfaceStyle DEFAULT_VOXEL_SURFACE_STYLE; // coords are in voxel-volume space virtual void setSphereInVolume(glm::vec3 center, float radius, uint8_t toValue) {} @@ -84,7 +92,7 @@ class PolyVoxEntityItem : public EntityItem { rgbColor _color; glm::vec3 _voxelVolumeSize; // this is always 3 bytes QByteArray _voxelData; - uint16_t _voxelSurfaceStyle; + PolyVoxSurfaceStyle _voxelSurfaceStyle; }; #endif // hifi_PolyVoxEntityItem_h