diff --git a/library/PolyVoxCore/include/ImprovedCubicSurfaceExtractor.inl b/library/PolyVoxCore/include/ImprovedCubicSurfaceExtractor.inl index 2c0eff15..1e18cb14 100644 --- a/library/PolyVoxCore/include/ImprovedCubicSurfaceExtractor.inl +++ b/library/PolyVoxCore/include/ImprovedCubicSurfaceExtractor.inl @@ -259,12 +259,7 @@ namespace PolyVox int32_t iIndex = static_cast(rEntry.iIndex); uint8_t uMaterial = static_cast(rEntry.uMaterial); - //If we have an existing vertex and the material matches then we can return it. - if((iIndex != -1) && (uMaterial == uMaterialIn)) - { - return iIndex; - } - else + if(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)); @@ -276,6 +271,12 @@ namespace PolyVox return temp; } + + //If we have an existing vertex and the material matches then we can return it. + if(uMaterial == uMaterialIn) + { + return iIndex; + } } //If we exit the loop here then apparently all the slots were full but none of