Hey there,
I'm using PolyVox to try out some terrain generation stuff with large terrain (2000x1000x2000 per terrain page). Basically, I want to to use PolyVox as a "mesh generator" (for Ogre3D) only, and forget about it once I have the mesh. Pretty mean, I know
First thing that bugged me was that it does not seem to be possible to create voxels of less than 1 byte size. Which is 8 times as much as I actually need.
I actually just need solid/air information, everything else I want to store somewhere else where it takes less space than if it was stored within each voxel. I tried LargeVolume<bool> of course, but that did not decrease the memory used at all.
Is there a way to make this possible? It really feels like I'm wasting space here
On the other hand, even when using BYTE directly, the Volume doesn't even take up 100MB. How is it even possible that 2000x1000x2000 voxels of 1 byte take up that few space?
My actual problem is the speed, though...
Here is the code that applies a heightmap to the Volume, by simply making the upmost voxel at one coordinate solid:
Code:
int y = 0;
int midLevel = _height / 2;
float range = ((float)_height) / 2.0f;
double value = 0.0;
for (int x = 0; x < _width; ++x)
{
for (int z = 0; z < _depth; ++z)
{
// Get the correct y coordinate
value = _heightMap[z * _depth + x];
y = int(midLevel + value * range + 0.5f);
// Apply to top voxel
// _voxelVolume is a PolyVox::LargeVolume<BYTE>*
_voxelVolume->setVoxelAt(x, y, z, 255);
}
}
That's not that much, IMO, yet takes 20 seconds to complete for a 2000x2000 heightmap.
Creating the heightmap itself barely takes 0.15 seconds. And yes, it is release mode.
I am sure I'm doing something very, very wrong here, but what is it?
Btw... although I'm already sure that something I'm doing is fishy, I continued and tried to generate a mesh from that LargeVolume. I think I started the process roughly 5 minutes ago and it is still not finished. Okay, I'm in Debug mode right now, but still
Here is the code I'm using for that (more or less taken from a tutorial):
Code:
void TerrainCreator::applyVoxelsToMesh(Ogre::ManualObject* p_manualMesh)
{
PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal> mesh;
PolyVox::MarchingCubesSurfaceExtractor<PolyVox::LargeVolume<BYTE> >
suf(_voxelVolume, _voxelVolume->getEnclosingRegion(), &mesh);
suf.execute();
p_manualMesh->begin("MySimple", Ogre::RenderOperation::OT_TRIANGLE_LIST);
{
const std::vector<PolyVox::PositionMaterialNormal>& vecVertices = mesh.getVertices();
const std::vector<uint32_t>& vecIndices = mesh.getIndices();
unsigned int uLodLevel = 0;
int beginIndex = mesh.m_vecLodRecords[uLodLevel].beginIndex;
int endIndex = mesh.m_vecLodRecords[uLodLevel].endIndex;
for(int index = beginIndex; index < endIndex; ++index)
{
const PolyVox::PositionMaterialNormal& vertex = vecVertices[vecIndices[index]];
const PolyVox::Vector3DFloat& v3dVertexPos = vertex.getPosition();
const PolyVox::Vector3DFloat& v3dVertexNormal = vertex.getNormal();
const PolyVox::Vector3DFloat v3dFinalVertexPos =
v3dVertexPos + static_cast<PolyVox::Vector3DFloat>(mesh.m_Region.getLowerCorner());
p_manualMesh->position(v3dFinalVertexPos.getX() - 25, v3dFinalVertexPos.getY()
- 25, v3dFinalVertexPos.getZ() - 25);
p_manualMesh->normal(v3dVertexNormal.getX(), v3dVertexNormal.getY(),
v3dVertexNormal.getZ());
p_manualMesh->colour(1.0f, 0.0f, 1.0f);
}
}
p_manualMesh->end();
}