David Williams wrote:
I'd be more interested in the code where you generate the volume. Are you calling both setDensity() and setMaterial()? I guess you were using a Material8 before and were only calling setMaterial? Now that you are using MaterialDensityPair you have to call setDensity() as well.
If that's not the problem then post the code for where you create the volume and write the data into it.
It seems not the case you mentioned above. the code for generation the volume and updating it is below:
Code:
VolumeStone::VolumeStone(Vector3DUint16 lowerCorner, Vector3DUint16 upperCorner, uint8_t uValue)//:volData(0)
{
volData = new SimpleVolume<MaterialDensityPair44>(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(31, 31, 31)));
createCubeVolume(lowerCorner, upperCorner, uValue);
mesh=new SurfaceMesh<PositionMaterialNormal>();
oMO=NULL;
surfaceExtractor=NULL;
}
VolumeStone::~VolumeStone(void)
{
}
void VolumeStone::createCubeVolume(Vector3DUint16 lowerCorner, Vector3DUint16 upperCorner, uint8_t uValue)
{
//This three-level for loop iterates over every voxel between the specified corners
for (int z = lowerCorner.getZ(); z <= upperCorner.getZ(); z++)
{
for (int y = lowerCorner.getY(); y <= upperCorner.getY(); y++)
{
for (int x = lowerCorner.getX() ; x <= upperCorner.getX(); x++)
{
volData->setVoxelAt(x,y,z, MaterialDensityPair44(uValue,MaterialDensityPair44::getMaxDensity()));
}
}
}
}
SimpleVolume<MaterialDensityPair44>* VolumeStone::updateVolData(float fRadius, uint8_t uValue,Ogre::Vector3 position)
{
//get the center of your knife!!
Vector3DFloat v3dVolCenter(position.x,position.y,position.z);
//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++)
{
if(volData->getVoxelAt(x,y,z).getDensity()!=MaterialDensityPair44::getMinDensity())
{
//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 more than 'radius' units from the center
//then we make it solid, otherwise we make it empty space.
if(fDistToCenter >= fRadius)
{
volData->setVoxelAt(x,y,z, MaterialDensityPair44(uValue,MaterialDensityPair44::getMaxDensity()));
}
else
volData->setVoxelAt(x,y,z, MaterialDensityPair44(uValue,MaterialDensityPair44::getMinDensity()));
}
}
}
}
//smoothRegion<SimpleVolume, MaterialDensityPair44>(*volData, PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(31, 31, 31)));
//smoothRegion<SimpleVolume, MaterialDensityPair44>(*volData, PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(31, 31, 31)));
//smoothRegion<SimpleVolume, MaterialDensityPair44>(*volData, PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(31, 31, 31)));
return volData;
}
Ogre::ManualObject*
VolumeStone::updatePolyvox(Ogre::String materialName)
{
//Extract the surface
surfaceExtractor= new SurfaceExtractor<SimpleVolume,MaterialDensityPair44>(volData, volData->getEnclosingRegion(), mesh);
surfaceExtractor->execute();
return updateConvertPolyVoxMesh(materialName);
}
Ogre::ManualObject*
VolumeStone::initPolyvox(Ogre::String materialName,Ogre::SceneManager *sm)
{
surfaceExtractor= new SurfaceExtractor<SimpleVolume, MaterialDensityPair44>(volData, volData->getEnclosingRegion(), mesh);
surfaceExtractor->execute();
oMO = sm->createManualObject(); // create manual object
oMO->setCastShadows(true);
oMO->setDynamic(true);
return updateConvertPolyVoxMesh(materialName);
}
And in my header file, I define variables as:
Code:
Ogre::ManualObject* oMO;
SimpleVolume<MaterialDensityPair44> *volData;
SurfaceMesh<PositionMaterialNormal> *mesh;
SurfaceExtractor<SimpleVolume, MaterialDensityPair44> *surfaceExtractor;