The problem only occurs with CubicSurfaceExtractor, but not CubicSurfaceExtractorWithNormals.
Code example:
Code:
#include "MaterialDensityPair.h"
#include "CubicSurfaceExtractor.h"
#include "CubicSurfaceExtractorWithNormals.h"
#include "SurfaceMesh.h"
#include "Volume.h"
//#define USE_NORMALS
using namespace PolyVox;
int main(int argc, char *argv[])
{
typedef MaterialDensityPair<uint8_t, 4, 4> Material44;
// Create a volume
Volume<Material44> volData(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(63, 63, 63)));
// Set up a voxel material
uint8_t density = Material44::getMaxDensity();
Material44 voxel;
voxel.setDensity(density);
voxel.setMaterial(1);
// Set some voxels just inside the edge of the region to be extracted. Don't set any voxels on the other side of the region border
volData.setVoxelAt(0, 0, 31, voxel);
volData.setVoxelAt(1, 0, 31, voxel);
volData.setVoxelAt(2, 0, 31, voxel);
volData.setVoxelAt(3, 0, 31, voxel);
// Extract the surface mesh from Region0 (contains voxels)
#ifdef USE_NORMALS
SurfaceMesh<PositionMaterialNormal> meshRegion0;
CubicSurfaceExtractorWithNormals<Material44> surfaceExtractorRegion0(&volData, PolyVox::Region(Vector3DInt32(0, 0, 0), Vector3DInt32(63, 63, 31)), &meshRegion0);
#else
SurfaceMesh<PositionMaterial> meshRegion0;
CubicSurfaceExtractor<Material44> surfaceExtractorRegion0(&volData, PolyVox::Region(Vector3DInt32(0, 0, 0), Vector3DInt32(63, 63, 31)), &meshRegion0);
#endif
surfaceExtractorRegion0.execute();
// Extract the surface mesh from Region1 (does not contain voxels)
#ifdef USE_NORMALS
SurfaceMesh<PositionMaterialNormal> meshRegion1;
CubicSurfaceExtractorWithNormals<Material44> surfaceExtractorRegion1(&volData, PolyVox::Region(Vector3DInt32(0, 0, 32), Vector3DInt32(63, 63, 63)), &meshRegion1);
#else
SurfaceMesh<PositionMaterial> meshRegion1;
CubicSurfaceExtractor<Material44> surfaceExtractorRegion1(&volData, PolyVox::Region(Vector3DInt32(0, 0, 32), Vector3DInt32(63, 63, 63)), &meshRegion1);
#endif
surfaceExtractorRegion1.execute();
// Check vertices on meshRegion0 - should be 20 vertices
std::cout << "meshRegion0 Vertices = " << meshRegion0.getNoOfVertices() << ", Indices = " << meshRegion0.getNoOfIndices() << ", Triangles = " << meshRegion0.getNoOfIndices()/3 << std::endl;
// Check vertices on meshRegion1 - should be 0 vertices
std::cout << "meshRegion1 Vertices = " << meshRegion1.getNoOfVertices() << ", Indices = " << meshRegion1.getNoOfIndices() << ", Triangles = " << meshRegion1.getNoOfIndices()/3 << std::endl;
return 0;
}
With USE_NORMALS defined:
meshRegion0 Vertices = 16, Indices = 24, Triangles = 8
meshRegion1 Vertices = 0, Indices = 0, Triangles = 0
With USE_NORMALS undefined
meshRegion0 Vertices = 20, Indices = 108, Triangles = 36
meshRegion1 Vertices = 10, Indices = 24, Triangles = 8
Somehow the extractor without normals is putting out more vertices than it should be, even when the result should have 0 vertices such in the region border case.