From 180b6a19452ad63f8e79172f1ec0eb38bb4f9c85 Mon Sep 17 00:00:00 2001 From: David Williams Date: Fri, 13 May 2011 23:54:09 +0100 Subject: [PATCH] Small improvements to improved cubuc surface extractor. --- .../include/ImprovedCubicSurfaceExtractor.h | 5 ++-- .../include/ImprovedCubicSurfaceExtractor.inl | 27 ++++++------------- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/library/PolyVoxCore/include/ImprovedCubicSurfaceExtractor.h b/library/PolyVoxCore/include/ImprovedCubicSurfaceExtractor.h index 2ca429b4..fa03f813 100644 --- a/library/PolyVoxCore/include/ImprovedCubicSurfaceExtractor.h +++ b/library/PolyVoxCore/include/ImprovedCubicSurfaceExtractor.h @@ -35,7 +35,6 @@ namespace PolyVox struct Quad { uint32_t vertices[4]; - uint8_t material; //Shouldn't hard code to uint8_t type? }; template< template class VolumeType, typename VoxelType> @@ -43,8 +42,8 @@ namespace PolyVox { struct IndexAndMaterial { - int32_t iIndex : 24; - int32_t uMaterial : 8; + int32_t iIndex; + int32_t uMaterial; //Should actually use the material type here, but this is ok for now. }; enum FaceNames diff --git a/library/PolyVoxCore/include/ImprovedCubicSurfaceExtractor.inl b/library/PolyVoxCore/include/ImprovedCubicSurfaceExtractor.inl index 1e18cb14..00414083 100644 --- a/library/PolyVoxCore/include/ImprovedCubicSurfaceExtractor.inl +++ b/library/PolyVoxCore/include/ImprovedCubicSurfaceExtractor.inl @@ -114,7 +114,6 @@ namespace PolyVox quad.vertices[1] = v1; quad.vertices[2] = v2; quad.vertices[3] = v3; - quad.material = material; m_vecQuads[NegativeX][regX].push_back(quad); } @@ -124,7 +123,6 @@ namespace PolyVox quad.vertices[1] = v3; quad.vertices[2] = v2; quad.vertices[3] = v1; - quad.material = material; m_vecQuads[PositiveX][regX].push_back(quad); } @@ -153,7 +151,6 @@ namespace PolyVox quad.vertices[1] = v3; quad.vertices[2] = v2; quad.vertices[3] = v1; - quad.material = material; m_vecQuads[NegativeY][regY].push_back(quad); } @@ -164,7 +161,6 @@ namespace PolyVox quad.vertices[1] = v1; quad.vertices[2] = v2; quad.vertices[3] = v3; - quad.material = material; m_vecQuads[PositiveY][regY].push_back(quad); } @@ -191,7 +187,6 @@ namespace PolyVox quad.vertices[1] = v1; quad.vertices[2] = v2; quad.vertices[3] = v3; - quad.material = material; m_vecQuads[NegativeZ][regZ].push_back(quad); } @@ -201,7 +196,6 @@ namespace PolyVox quad.vertices[1] = v3; quad.vertices[2] = v2; quad.vertices[3] = v1; - quad.material = material; m_vecQuads[PositiveZ][regZ].push_back(quad); } @@ -256,26 +250,19 @@ namespace PolyVox { IndexAndMaterial& rEntry = existingVertices[uX][uY][ct]; - int32_t iIndex = static_cast(rEntry.iIndex); - uint8_t uMaterial = static_cast(rEntry.uMaterial); - - if(iIndex == -1) + if(rEntry.iIndex == -1) { //No vertices matched and we've now hit an empty space. Fill it by creating a vertex. - uint32_t temp = m_meshCurrent->addVertex(PositionMaterial(Vector3DFloat(fX, fY, fZ), uMaterialIn)); - - //Note - Slightly dodgy casting taking place here. No proper way to convert to 24-bit int though? - //If problematic in future then fix IndexAndMaterial to contain variables rather than bitfield. - rEntry.iIndex = temp; + rEntry.iIndex = m_meshCurrent->addVertex(PositionMaterial(Vector3DFloat(fX, fY, fZ), uMaterialIn)); rEntry.uMaterial = uMaterialIn; - return temp; + return rEntry.iIndex; } //If we have an existing vertex and the material matches then we can return it. - if(uMaterial == uMaterialIn) + if(rEntry.uMaterial == uMaterialIn) { - return iIndex; + return rEntry.iIndex; } } @@ -318,7 +305,9 @@ namespace PolyVox template< template class VolumeType, typename VoxelType> bool ImprovedCubicSurfaceExtractor::mergeQuads(Quad& q1, Quad& q2) { - if(q1.material == q2.material) + //All four vertices of a given quad have the same material, + //so just check that the first pair or vertices match. + if(fabs(m_meshCurrent->getVertices()[q1.vertices[0]].getMaterial() - m_meshCurrent->getVertices()[q2.vertices[0]].getMaterial()) < 0.001) { if((q1.vertices[0] == q2.vertices[1]) && ((q1.vertices[3] == q2.vertices[2]))) {