Work reintegrating Region class.

This commit is contained in:
David Williams
2008-05-25 13:33:22 +00:00
parent f15491ec02
commit 50103589c6
4 changed files with 20 additions and 22 deletions

View File

@ -19,27 +19,20 @@ namespace PolyVox
regVolume.setUpperCorner(regVolume.getUpperCorner() - Vector3DInt32(1,1,1));
region.cropTo(regVolume);
const uint16_t firstX = region.getLowerCorner().x();
const uint16_t firstY = region.getLowerCorner().y();
const uint16_t firstZ = region.getLowerCorner().z();
const uint16_t lastX = region.getUpperCorner().x();
const uint16_t lastY = region.getUpperCorner().y();
const uint16_t lastZ = region.getUpperCorner().z();
//Offset from lower block corner
const Vector3DFloat offset(firstX,firstY,firstZ);
const Vector3DFloat offset = static_cast<Vector3DFloat>(region.getLowerCorner());
Vector3DFloat vertlist[12];
uint8_t vertMaterials[12];
VolumeIterator<boost::uint8_t> volIter(*volumeData);
volIter.setValidRegion(firstX,firstY,firstZ,lastX,lastY,lastZ);
volIter.setValidRegion(region);
//////////////////////////////////////////////////////////////////////////
//Get mesh data
//////////////////////////////////////////////////////////////////////////
//Iterate over each cell in the region
for(volIter.setPosition(firstX,firstY,firstZ);volIter.isValidForRegion();volIter.moveForwardInRegion())
for(volIter.setPosition(region.getLowerCorner().x(),region.getLowerCorner().y(), region.getLowerCorner().z());volIter.isValidForRegion();volIter.moveForwardInRegion())
{
//Current position
const uint16_t x = volIter.getPosX();
@ -416,23 +409,21 @@ namespace PolyVox
return result;
}
void generateSmoothMeshDataForRegion(BlockVolume<uint8_t>* volumeData, uint16_t regionX, uint16_t regionY, uint16_t regionZ, IndexedSurfacePatch* singleMaterialPatch, IndexedSurfacePatch* multiMaterialPatch)
void generateSmoothMeshDataForRegion(BlockVolume<uint8_t>* volumeData, Region region, IndexedSurfacePatch* singleMaterialPatch, IndexedSurfacePatch* multiMaterialPatch)
{
//First and last voxels in the region
const uint16_t firstX = regionX * POLYVOX_REGION_SIDE_LENGTH;
const uint16_t firstY = regionY * POLYVOX_REGION_SIDE_LENGTH;
const uint16_t firstZ = regionZ * POLYVOX_REGION_SIDE_LENGTH;
const uint16_t lastX = (std::min)(firstX + POLYVOX_REGION_SIDE_LENGTH-1,volumeData->getSideLength()-2);
const uint16_t lastY = (std::min)(firstY + POLYVOX_REGION_SIDE_LENGTH-1,volumeData->getSideLength()-2);
const uint16_t lastZ = (std::min)(firstZ + POLYVOX_REGION_SIDE_LENGTH-1,volumeData->getSideLength()-2);
//When generating the mesh for a region we actually look one voxel outside it in the
// back, bottom, right direction. Protect against access violations by cropping region here
Region regVolume = volumeData->getEnclosingRegion();
regVolume.setUpperCorner(regVolume.getUpperCorner() - Vector3DInt32(1,1,1));
region.cropTo(regVolume);
//Offset from lower block corner
const Vector3DFloat offset(firstX,firstY,firstZ);
const Vector3DFloat offset = static_cast<Vector3DFloat>(region.getLowerCorner());
Vector3DFloat vertlist[12];
uint8_t vertMaterials[12];
VolumeIterator<boost::uint8_t> volIter(*volumeData);
volIter.setValidRegion(firstX,firstY,firstZ,lastX,lastY,lastZ);
volIter.setValidRegion(region);
const float threshold = 0.5f;
@ -441,7 +432,7 @@ namespace PolyVox
//////////////////////////////////////////////////////////////////////////
//Iterate over each cell in the region
for(volIter.setPosition(firstX,firstY,firstZ);volIter.isValidForRegion();volIter.moveForwardInRegion())
for(volIter.setPosition(region.getLowerCorner().x(),region.getLowerCorner().y(), region.getLowerCorner().z());volIter.isValidForRegion();volIter.moveForwardInRegion())
{
//Current position
const uint16_t x = volIter.getPosX();