This class can be used to instead of the standard SurfaceExtractor class to extract directly into a CDynamicMeshBuffer instead of converting it into a PolyVox mesh and than have to convert it into a Irrlicht mesh.
Should speed things up a bit and make integration easier.
PolyVox webside
Example:
Code: Select all
//Include files needed for PolyVox
#include "PolyVoxCore/MaterialDensityPair.h"
#include "PolyVoxCore/CubicSurfaceExtractorWithNormals.h"
#include "PolyVoxCore/SurfaceMesh.h"
#include "PolyVoxCore/SimpleVolume.h"
//Create the volume that contains the actual voxel data and make it 64x64x64
SimpleVolume<MaterialDensityPair44> volData(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(63, 63, 63)));
//This vector hold the position of the center of the volume
Vector3DFloat v3dVolCenter(volData.getWidth() / 2, volData.getHeight() / 2, volData.getDepth() / 2);
//Create a simple sphere
//This three-level for loop iterates over every voxel in the volume
for (int z = 0; z < volData.getWidth(); z++)
{
for (int y = 0; y < volData.getHeight(); y++)
{
for (int x = 0; x < volData.getDepth(); x++)
{
//Store our current position as a vector...
Vector3DFloat v3dCurrentPos(x,y,z);
//And compute how far the current position is from the center of the volume
float fDistToCenter = (v3dCurrentPos - v3dVolCenter).length();
//If the current voxel is less than 'radius' units from the center then we make it solid.
if(fDistToCenter <= fRadius)
{
//Our new density value
uint8_t uDensity = MaterialDensityPair44::getMaxDensity();
//Get the old voxel
MaterialDensityPair44 voxel = volData.getVoxelAt(x,y,z);
//Modify the density
voxel.setDensity(uDensity);
//Wrte the voxel value into the volume
volData.setVoxelAt(x, y, z, voxel);
}
}
}
}
//Create a new meshBuffer
CDynamicMeshBuffer *newBuffer = new CDynamicMeshBuffer(EVT_STANDARD, EIT_32BIT);
//Create a new mesh extractor for making a mesh out of the voxel data
IrrSurfaceExtractor<SimpleVolume, MaterialDensityPair44 > irrsurfaceExtractor(volData, volData->getEnclosingRegion(), newBuffer);
//Execute the extractor
irrsurfaceExtractor.execute();
//Create the scene node
SMesh * newMesh = new SMesh;
newMesh->addMeshBuffer(newBuffer);
newMesh->recalculateBoundingBox();
ISceneNode * newNode = SceneManager->addMeshSceneNode(newMesh, Parent, ID, Position, Rotation, Scale);
newMesh->drop();
newBuffer->drop();
IrrSurfaceExtractor