diff --git a/include/PolyVox/MarchingCubesSurfaceExtractor.inl b/include/PolyVox/MarchingCubesSurfaceExtractor.inl index a585d7ee..6889fa76 100644 --- a/include/PolyVox/MarchingCubesSurfaceExtractor.inl +++ b/include/PolyVox/MarchingCubesSurfaceExtractor.inl @@ -244,71 +244,67 @@ namespace PolyVox int32_t indlist[12]; - /* Cube is entirely in/out of the surface */ - if (edgeTable[iCubeIndex] != 0) + /* Find the vertices where the surface intersects the cube */ + if (edgeTable[iCubeIndex] & 1) { - /* Find the vertices where the surface intersects the cube */ - if (edgeTable[iCubeIndex] & 1) - { - indlist[0] = pPreviousIndices(uXRegSpace, uYRegSpace - 1).getX(); - } - if (edgeTable[iCubeIndex] & 2) - { - indlist[1] = pPreviousIndices(uXRegSpace, uYRegSpace).getY(); - } - if (edgeTable[iCubeIndex] & 4) - { - indlist[2] = pPreviousIndices(uXRegSpace, uYRegSpace).getX(); - } - if (edgeTable[iCubeIndex] & 8) - { - indlist[3] = pPreviousIndices(uXRegSpace - 1, uYRegSpace).getY(); - } - if (edgeTable[iCubeIndex] & 16) - { - indlist[4] = pIndices(uXRegSpace, uYRegSpace - 1).getX(); - } - if (edgeTable[iCubeIndex] & 32) - { - indlist[5] = pIndices(uXRegSpace, uYRegSpace).getY(); - } - if (edgeTable[iCubeIndex] & 64) - { - indlist[6] = pIndices(uXRegSpace, uYRegSpace).getX(); - } - if (edgeTable[iCubeIndex] & 128) - { - indlist[7] = pIndices(uXRegSpace - 1, uYRegSpace).getY(); - } - if (edgeTable[iCubeIndex] & 256) - { - indlist[8] = pIndices(uXRegSpace - 1, uYRegSpace - 1).getZ(); - } - if (edgeTable[iCubeIndex] & 512) - { - indlist[9] = pIndices(uXRegSpace, uYRegSpace - 1).getZ(); - } - if (edgeTable[iCubeIndex] & 1024) - { - indlist[10] = pIndices(uXRegSpace, uYRegSpace).getZ(); - } - if (edgeTable[iCubeIndex] & 2048) - { - indlist[11] = pIndices(uXRegSpace - 1, uYRegSpace).getZ(); - } - - for (int i = 0; triTable[iCubeIndex][i] != -1; i += 3) - { - const int32_t ind0 = indlist[triTable[iCubeIndex][i]]; - const int32_t ind1 = indlist[triTable[iCubeIndex][i + 1]]; - const int32_t ind2 = indlist[triTable[iCubeIndex][i + 2]]; - - if ((ind0 != -1) && (ind1 != -1) && (ind2 != -1)) - { - result->addTriangle(ind0, ind1, ind2); - } - } // For each triangle + indlist[0] = pPreviousIndices(uXRegSpace, uYRegSpace - 1).getX(); } + if (edgeTable[iCubeIndex] & 2) + { + indlist[1] = pPreviousIndices(uXRegSpace, uYRegSpace).getY(); + } + if (edgeTable[iCubeIndex] & 4) + { + indlist[2] = pPreviousIndices(uXRegSpace, uYRegSpace).getX(); + } + if (edgeTable[iCubeIndex] & 8) + { + indlist[3] = pPreviousIndices(uXRegSpace - 1, uYRegSpace).getY(); + } + if (edgeTable[iCubeIndex] & 16) + { + indlist[4] = pIndices(uXRegSpace, uYRegSpace - 1).getX(); + } + if (edgeTable[iCubeIndex] & 32) + { + indlist[5] = pIndices(uXRegSpace, uYRegSpace).getY(); + } + if (edgeTable[iCubeIndex] & 64) + { + indlist[6] = pIndices(uXRegSpace, uYRegSpace).getX(); + } + if (edgeTable[iCubeIndex] & 128) + { + indlist[7] = pIndices(uXRegSpace - 1, uYRegSpace).getY(); + } + if (edgeTable[iCubeIndex] & 256) + { + indlist[8] = pIndices(uXRegSpace - 1, uYRegSpace - 1).getZ(); + } + if (edgeTable[iCubeIndex] & 512) + { + indlist[9] = pIndices(uXRegSpace, uYRegSpace - 1).getZ(); + } + if (edgeTable[iCubeIndex] & 1024) + { + indlist[10] = pIndices(uXRegSpace, uYRegSpace).getZ(); + } + if (edgeTable[iCubeIndex] & 2048) + { + indlist[11] = pIndices(uXRegSpace - 1, uYRegSpace).getZ(); + } + + for (int i = 0; triTable[iCubeIndex][i] != -1; i += 3) + { + const int32_t ind0 = indlist[triTable[iCubeIndex][i]]; + const int32_t ind1 = indlist[triTable[iCubeIndex][i + 1]]; + const int32_t ind2 = indlist[triTable[iCubeIndex][i + 2]]; + + if ((ind0 != -1) && (ind1 != -1) && (ind2 != -1)) + { + result->addTriangle(ind0, ind1, ind2); + } + } // For each triangle } } // For each cell sampler.movePositiveX();