From e51b9cfee9a88f0028eca1866d7540050244c573 Mon Sep 17 00:00:00 2001 From: David Williams Date: Sat, 27 Jun 2009 19:11:33 +0000 Subject: [PATCH] Work on improving material system. --- .../PolyVoxCore/include/IndexedSurfacePatch.h | 4 ++- .../source/IndexedSurfacePatch.cpp | 34 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/library/PolyVoxCore/include/IndexedSurfacePatch.h b/library/PolyVoxCore/include/IndexedSurfacePatch.h index 06061e49..420511d9 100644 --- a/library/PolyVoxCore/include/IndexedSurfacePatch.h +++ b/library/PolyVoxCore/include/IndexedSurfacePatch.h @@ -23,6 +23,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #define __PolyVox_IndexedSurfacePatch_H__ #include +#include #include "PolyVoxImpl/CPlusPlusZeroXSupport.h" @@ -54,6 +55,8 @@ namespace PolyVox void smooth(float fAmount, bool bIncludeEdgeVertices = false); + POLYVOX_SHARED_PTR extractSubset(std::set setMaterials); + void generateAveragedFaceNormals(bool bNormalise, bool bIncludeEdgeVertices = false); //Vector3DInt32 m_v3dRegionPosition; //FIXME - remove this? @@ -66,7 +69,6 @@ namespace PolyVox std::vector m_vecTriangleIndices; std::vector m_vecVertices; }; - } #endif /* __IndexedSurfacePatch_H__ */ diff --git a/library/PolyVoxCore/source/IndexedSurfacePatch.cpp b/library/PolyVoxCore/source/IndexedSurfacePatch.cpp index 3cb2cb52..5e52ec1d 100644 --- a/library/PolyVoxCore/source/IndexedSurfacePatch.cpp +++ b/library/PolyVoxCore/source/IndexedSurfacePatch.cpp @@ -218,4 +218,38 @@ namespace PolyVox } } } + + POLYVOX_SHARED_PTR IndexedSurfacePatch::extractSubset(std::set setMaterials) + { + POLYVOX_SHARED_PTR result(new IndexedSurfacePatch); + + if(m_vecVertices.size() == 0) //FIXME - I don't think we should need this test, but I have seen crashes otherwise... + { + return result; + } + + for(vector::iterator iterIndex = m_vecTriangleIndices.begin(); iterIndex != m_vecTriangleIndices.end();) + { + SurfaceVertex& v0 = m_vecVertices[*iterIndex]; + iterIndex++; + SurfaceVertex& v1 = m_vecVertices[*iterIndex]; + iterIndex++; + SurfaceVertex& v2 = m_vecVertices[*iterIndex]; + iterIndex++; + + if( + (setMaterials.find(v0.getMaterial()) != setMaterials.end()) || + (setMaterials.find(v1.getMaterial()) != setMaterials.end()) || + (setMaterials.find(v2.getMaterial()) != setMaterials.end())) + { + uint32_t i0 = result->addVertex(v0); + uint32_t i1 = result->addVertex(v1); + uint32_t i2 = result->addVertex(v2); + + result->addTriangle(i0,i1,i2); + } + } + + return result; + } }