I'm using CubicSurfaceExtractorWithNormals to extract the vertices and indices. Then converting to an irrlicht SMesh with the following code
Code:
SMesh* TerrainManager::generateCubicMesh(SimpleVolume<MaterialDensityPair44>& volData)
{
SMesh* sMesh = new SMesh();
SurfaceMesh<PositionMaterial> vMesh;
//get the vertices and indices
PolyVox::CubicSurfaceExtractor<SimpleVolume, MaterialDensityPair44 > surfaceEx(&volData, volData.getEnclosingRegion(), &vMesh,true);
surfaceEx.execute();
const std::vector<uint32_t>& vecIndices = vMesh.getIndices();
const std::vector<PositionMaterial>& vecVertices = vMesh.getVertices();
//put the indices into an array
u16 *arrIndices = new u16[vecIndices.size()];
for(int i =0; i < vMesh.getNoOfIndices();i++)
{
arrIndices[i] =(u16)vecIndices[i];
}
//put the vertices into an array of 3dvectors
irr::core::vector3df *arrVertices = new irr::core::vector3df[vecVertices.size() ];
for(int i =0; i < vecVertices.size();i++)
{
arrVertices[i] = irr::core::vector3df((f32)vecVertices[i].getPosition().getX(),
(f32)vecVertices[i].getPosition().getY(),
(f32)vecVertices[i].getPosition().getZ());
}
//add the vertices and indices to a buffer and add them to the mesh
SMeshBuffer *buf = new SMeshBuffer();
buf->append(arrVertices,vecVertices.size(),arrIndices,vecIndices.size());
sMesh->addMeshBuffer(buf);
return sMesh;
}
The odd thing is that I create a spherical shape(using create sphere in volume code), the polygons are just completely messed up(jagged and definitely not cubic) and invisible from certain angles.
If noone feels like dissecting my code( I wouldn't), How would I properly load the indices and vertexes? I feel like I'm doing it correctly, but I'm obviously not.