diff --git a/library/PolyVoxCore/include/ImprovedCubicSurfaceExtractor.h b/library/PolyVoxCore/include/ImprovedCubicSurfaceExtractor.h index 23a985b6..34616521 100644 --- a/library/PolyVoxCore/include/ImprovedCubicSurfaceExtractor.h +++ b/library/PolyVoxCore/include/ImprovedCubicSurfaceExtractor.h @@ -32,23 +32,6 @@ freely, subject to the following restrictions: namespace PolyVox { - struct IndexAndMaterial - { - int32_t iIndex : 24; - int32_t uMaterial : 8; - }; - - enum FaceNames - { - PositiveX, - PositiveY, - PositiveZ, - NegativeX, - NegativeY, - NegativeZ, - NoOfFaces - }; - struct Quad { uint32_t vertices[4]; @@ -58,8 +41,25 @@ namespace PolyVox template< template class VolumeType, typename VoxelType> class ImprovedCubicSurfaceExtractor { + struct IndexAndMaterial + { + int32_t iIndex : 24; + int32_t uMaterial : 8; + }; + + enum FaceNames + { + PositiveX, + PositiveY, + PositiveZ, + NegativeX, + NegativeY, + NegativeZ, + NoOfFaces + }; + public: - ImprovedCubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result); + ImprovedCubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result, bool bMergeQuads = true); void execute(); @@ -84,6 +84,8 @@ namespace PolyVox std::vector< std::list > m_vecQuads[NoOfFaces]; + bool m_bMergeQuads; + //Although we try to avoid creating multiple vertices at the same location, sometimes this is unavoidable //if they have different materials. For example, four different materials next to each other would mean //four quads (though more triangles) sharing the vertex. As far as I can tell, four is the worst case scenario. @@ -93,18 +95,6 @@ namespace PolyVox // Decimation //////////////////////////////////////////////////////////////////////////////// - /*class Triangle - { - uint32_t v0; - uint32_t v1; - uint32_t v2; - } - - std::vector triangles; - std::vector< std::vector > trianglesUsingVertex;*/ - - //std::vector decimate(const std::vector& quads); - bool decimate(std::list& quads); Quad mergeQuads(const Quad& q1, const Quad& q2); diff --git a/library/PolyVoxCore/include/ImprovedCubicSurfaceExtractor.inl b/library/PolyVoxCore/include/ImprovedCubicSurfaceExtractor.inl index bb0e1889..4415ddc8 100644 --- a/library/PolyVoxCore/include/ImprovedCubicSurfaceExtractor.inl +++ b/library/PolyVoxCore/include/ImprovedCubicSurfaceExtractor.inl @@ -33,11 +33,12 @@ namespace PolyVox const uint32_t ImprovedCubicSurfaceExtractor::MaxQuadsSharingVertex = 4; template< template class VolumeType, typename VoxelType> - ImprovedCubicSurfaceExtractor::ImprovedCubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result) + ImprovedCubicSurfaceExtractor::ImprovedCubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result, bool bMergeQuads) :m_volData(volData) ,m_sampVolume(volData) ,m_regSizeInVoxels(region) ,m_meshCurrent(result) + ,m_bMergeQuads(bMergeQuads) { m_meshCurrent->clear(); } @@ -225,7 +226,10 @@ namespace PolyVox { std::list& listQuads = vecListQuads[slice]; - while(decimate(listQuads)){} + if(m_bMergeQuads) + { + while(decimate(listQuads)){} + } std::list::iterator iterEnd = listQuads.end(); for(std::list::iterator quadIter = listQuads.begin(); quadIter != iterEnd; quadIter++) @@ -320,32 +324,6 @@ namespace PolyVox template< template class VolumeType, typename VoxelType> Quad ImprovedCubicSurfaceExtractor::mergeQuads(const Quad& q1, const Quad& q2) { - /*Quad* pCurrentQuad = &q1; - Quad* pOtherQuad = &q2; - uint32_t uCurrentInputIndex = 0; - uint32_t uCurrentOutputIndex = 0; - - Quad result; - result.material = q1.material; - - do - { - uint32_t uIndexInOtherQuad = quadContainsVertex(*pOtherQuad, (*(pCurrentQuad)).vertices[uCurrentInputIndex]); - if(uIndexInOtherQuad != -1) - { - std::swap(pCurrentQuad, pOtherQuad); - uCurrentInputIndex = (uIndexInOtherQuad + 1) % 4; - } - else - { - result.vertices[uCurrentOutputIndex] = pCurrentQuad->vertices[uCurrentInputIndex]; - uCurrentOutputIndex++; - uCurrentInputIndex = (uCurrentInputIndex + 1) % 4; - } - } while(uCurrentOutputIndex < 4); - - return result;*/ - Quad result; result.material = q1.material;