ok.. I got into some trouble with the 32bit ints... I'm working on it thou...
here is a 16 bit streaming world that will probably crash if you move to the upper range of a uint16
I'm writing an example currently to show off the streaming feature (like create perlin noise on the fly when requested instead of precomputing the volume)
I'm unable to upload files... posting it somewhere else
it looks a little odd... I hope this didn't mess up the diff file (the upload added blank lines everywhere)
http://paste.pocoo.org/raw/JWzOXN5vup9oVhRBHysH/ok... this was easier than expected:
this is an example callback for volume data creation
Code:
void createPerlinTerrainChunk(Volume<MaterialDensityPair44>& volData, PolyVox::Region reg)
{
Perlin perlin(2,2,1,234);
for(int x = reg.getLowerCorner().getX(); x < reg.getUpperCorner().getX(); x++) {
for(int y = reg.getLowerCorner().getY(); y < reg.getUpperCorner().getY(); y++) {
float perlinVal = perlin.Get(x / 254.0f , y / 254.0f);
perlinVal += 1.0f;
perlinVal *= 0.5f;
perlinVal *= 255.0f;
for(int z = reg.getLowerCorner().getZ(); z < reg.getUpperCorner().getZ(); z++) {
MaterialDensityPair44 voxel;
if(z < perlinVal)
{
voxel.setMaterial(245);
voxel.setDensity(MaterialDensityPair44::getMaxDensity());
}
else
{
voxel.setMaterial(0);
voxel.setDensity(MaterialDensityPair44::getMinDensity());
}
volData.setVoxelAt(x, y, z, voxel);
}
}
}
}
and this is how you use it:
Code:
int main(int argc, char *argv[])
{
//Create and show the Qt OpenGL window
QApplication app(argc, argv);
OpenGLWidget openGLWidget(0);
openGLWidget.show();
//Create an empty volume and then place a sphere in it
Volume<MaterialDensityPair44> volData;
volData.setBlockCacheSize(4096);
volData.m_fLoad = boost::bind(&createPerlinTerrainChunk, boost::ref(volData), _1);
//createSphereInVolume(volData, 30);
//createPerlinTerrain(volData, Vector3DInt16(255,255,255));
//createPerlinVolumeSlow(volData);
std::cout << "Memory usage: " << volData.calculateSizeInBytes() << std::endl;
//volData.setBlockCacheSize(8);
std::cout << "Memory usage: " << volData.calculateSizeInBytes() << std::endl;
std::cout << "Compression ratio: " << volData.calculateCompressionRatio() << std::endl;
//Extract the surface
SurfaceMesh<PositionMaterialNormal> mesh;
SurfaceExtractor<MaterialDensityPair44> surfaceExtractor(&volData, PolyVox::Region(Vector3DInt16(1,1,1), Vector3DInt16(1022,253,253)), &mesh);
surfaceExtractor.execute();
//Pass the surface to the OpenGL window
openGLWidget.setSurfaceMeshToRender(mesh);
//Run the message pump.
return app.exec();
}