Sign in to follow this  
GameGeazer

Trouble creating a mesh

Recommended Posts

I'm using irrlicht and polyvox in order to generate a minecraft-esque world. I don't have much experience with 3d graphics and the mesh is being generated improperly. Am I setting up my indices and vertices correctly? Thankyou for your time.

[code]SMesh* TerrainManager::generateCubicMesh(SimpleVolume<MaterialDensityPair44>& volData)
{
//extract the surface mesh from the voxels
SMesh* sMesh = new SMesh();
SurfaceMesh<PositionMaterialNormal> vMesh;
CubicSurfaceExtractorWithNormals<SimpleVolume, MaterialDensityPair44 > surfaceExtractor(&volData, volData.getEnclosingRegion(), &vMesh);
surfaceExtractor.execute();
//get the indices and vertices
const std::vector<uint32_t>& vecIndices = vMesh.getIndices();
const std::vector<PositionMaterialNormal>& vecVertices = vMesh.getVertices();
//copy indices to an array
u16 *arrIndices = new u16[vMesh.getNoOfIndices()];
for(int i =0; i < vMesh.getNoOfIndices();i++)
{
arrIndices[i] =(u32)vecIndices[i];
}
//copy vertices to an array
f32 *arrVertices = new f32[vecVertices.size()*3];
int j = 0;
for(int i =0; i < vecVertices.size();i++)
{

arrVertices[j] = (f32)vecVertices[i].getPosition().getX();j++;
arrVertices[j] = (f32)vecVertices[i].getPosition().getY();j++;
arrVertices[j] = (f32)vecVertices[i].getPosition().getZ();j++;
}

//generate mesh buffer and add it to the mesh
SMeshBuffer *buf = new SMeshBuffer();
buf->append(arrVertices,vecVertices.size()*3,arrIndices,vecIndices.size());
sMesh->addMeshBuffer(buf);
return sMesh;
}[/code]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this