From 125d9000dd03afe1f692e546bd53d31dac43fbba Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 9 Aug 2012 16:54:45 +0200 Subject: [PATCH] Started implementing 'IsQuadNeeded' for CubicSurfaceExtractor (without normals). --- .../PolyVoxCore/CubicSurfaceExtractor.h | 7 ++++-- .../PolyVoxCore/CubicSurfaceExtractor.inl | 25 ++++++++++--------- .../include/PolyVoxCore/Material.h | 20 +++++++++++++++ 3 files changed, 38 insertions(+), 14 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h index 86922b54..70666f8a 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h +++ b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h @@ -27,11 +27,12 @@ freely, subject to the following restrictions: #include "PolyVoxImpl/TypeDef.h" #include "PolyVoxCore/Array.h" +#include "PolyVoxCore/DefaultIsQuadNeeded.h" #include "PolyVoxCore/SurfaceMesh.h" namespace PolyVox { - template + template > class CubicSurfaceExtractor { struct IndexAndMaterial @@ -57,7 +58,7 @@ namespace PolyVox }; public: - CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result, bool bMergeQuads = true); + CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result, bool bMergeQuads = true, IsQuadNeeded isQuadNeeded = IsQuadNeeded()); void execute(); @@ -66,6 +67,8 @@ namespace PolyVox bool performQuadMerging(std::list& quads); bool mergeQuads(Quad& q1, Quad& q2); + IsQuadNeeded m_funcIsQuadNeededCallback; + //The volume data and a sampler to access it. VolumeType* m_volData; diff --git a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl index 5ff1c6ac..9980abcb 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl @@ -31,20 +31,21 @@ namespace PolyVox // The vertex position at the center of this group is then going to be used by six quads all with different materials. // One futher note - we can actually have eight quads sharing a vertex position (imagine two 1x1x10 rows of voxels // sharing a common edge) but in this case all eight quads will not have different materials. - template - const uint32_t CubicSurfaceExtractor::MaxVerticesPerPosition = 6; + template + const uint32_t CubicSurfaceExtractor::MaxVerticesPerPosition = 6; - template - CubicSurfaceExtractor::CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result, bool bMergeQuads) + template + CubicSurfaceExtractor::CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result, bool bMergeQuads, IsQuadNeeded isQuadNeeded) :m_volData(volData) ,m_regSizeInVoxels(region) ,m_meshCurrent(result) ,m_bMergeQuads(bMergeQuads) { + m_funcIsQuadNeededCallback = isQuadNeeded; } - template - void CubicSurfaceExtractor::execute() + template + void CubicSurfaceExtractor::execute() { m_meshCurrent->clear(); @@ -243,8 +244,8 @@ namespace PolyVox m_meshCurrent->m_vecLodRecords.push_back(lodRecord); } - template - int32_t CubicSurfaceExtractor::addVertex(float fX, float fY, float fZ, uint32_t uMaterialIn, Array<3, IndexAndMaterial>& existingVertices) + template + int32_t CubicSurfaceExtractor::addVertex(float fX, float fY, float fZ, uint32_t uMaterialIn, Array<3, IndexAndMaterial>& existingVertices) { uint32_t uX = static_cast(fX + 0.75f); uint32_t uY = static_cast(fY + 0.75f); @@ -275,8 +276,8 @@ namespace PolyVox return -1; //Should never happen. } - template - bool CubicSurfaceExtractor::performQuadMerging(std::list& quads) + template + bool CubicSurfaceExtractor::performQuadMerging(std::list& quads) { bool bDidMerge = false; for(typename std::list::iterator outerIter = quads.begin(); outerIter != quads.end(); outerIter++) @@ -305,8 +306,8 @@ namespace PolyVox return bDidMerge; } - template - bool CubicSurfaceExtractor::mergeQuads(Quad& q1, Quad& q2) + template + bool CubicSurfaceExtractor::mergeQuads(Quad& q1, Quad& q2) { //All four vertices of a given quad have the same material, //so just check that the first pair of vertices match. diff --git a/library/PolyVoxCore/include/PolyVoxCore/Material.h b/library/PolyVoxCore/include/PolyVoxCore/Material.h index 091e9495..9bbb3bc8 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Material.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Material.h @@ -26,6 +26,8 @@ freely, subject to the following restrictions: #include "PolyVoxImpl/TypeDef.h" +#include "PolyVoxCore/DefaultIsQuadNeeded.h" //we'll specialise this function for this voxel type + #include namespace PolyVox @@ -79,6 +81,24 @@ namespace PolyVox typedef Material Material8; typedef Material Material16; + + template + class DefaultIsQuadNeeded< Material > + { + public: + bool operator()(Material back, Material front, float& materialToUse) + { + if((back.getMaterial() > 0) && (front.getMaterial() == 0)) + { + materialToUse = static_cast(back.getMaterial()); + return true; + } + else + { + return false; + } + } + }; } #endif //__PolyVox_Material_H__