Moved some stuff from VolumeChangeTracker to SurfaceExtractors.

This commit is contained in:
David Williams 2008-05-25 21:06:58 +00:00
parent 29d1cd8ad1
commit 22fd38b255
6 changed files with 46 additions and 61 deletions

View File

@ -45,7 +45,7 @@ namespace PolyVox
BlockVolume& operator=(const BlockVolume& rhs);
Region getEnclosingRegion(void);
Region getEnclosingRegion(void) const;
boost::uint16_t getSideLength(void) const;
VoxelType getVoxelAt(boost::uint16_t uXPos, boost::uint16_t uYPos, boost::uint16_t uZPos) const;
VoxelType getVoxelAt(const Vector3DUint16& v3dPos) const;

View File

@ -121,7 +121,7 @@ namespace PolyVox
#pragma region Getters
template <typename VoxelType>
Region BlockVolume<VoxelType>::getEnclosingRegion(void)
Region BlockVolume<VoxelType>::getEnclosingRegion(void) const
{
return Region(Vector3DInt32(0,0,0), Vector3DInt32(m_uSideLength-1,m_uSideLength-1,m_uSideLength-1));
}

View File

@ -24,17 +24,22 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#pragma region Headers
#include "PolyVoxForwardDeclarations.h"
#include "TypeDef.h"
#include "boost/cstdint.hpp"
#include <list>
#pragma endregion
namespace PolyVox
{
void generateRoughMeshDataForRegion(BlockVolume<boost::uint8_t>* volumeData, Region region, IndexedSurfacePatch* singleMaterialPatch, IndexedSurfacePatch* multiMaterialPatch);
Vector3DFloat computeNormal(BlockVolume<boost::uint8_t>* volumeData, const Vector3DFloat& position, NormalGenerationMethod normalGenerationMethod);
POLYVOX_API std::list<RegionGeometry> getChangedRegionGeometry(VolumeChangeTracker& volume);
void generateSmoothMeshDataForRegion(BlockVolume<boost::uint8_t>* volumeData, Region region, IndexedSurfacePatch* singleMaterialPatch, IndexedSurfacePatch* multiMaterialPatch);
Vector3DFloat computeSmoothNormal(BlockVolume<boost::uint8_t>* volumeData, const Vector3DFloat& position, NormalGenerationMethod normalGenerationMethod);
POLYVOX_API void generateRoughMeshDataForRegion(BlockVolume<boost::uint8_t>* volumeData, Region region, IndexedSurfacePatch* singleMaterialPatch, IndexedSurfacePatch* multiMaterialPatch);
POLYVOX_API Vector3DFloat computeNormal(BlockVolume<boost::uint8_t>* volumeData, const Vector3DFloat& position, NormalGenerationMethod normalGenerationMethod);
POLYVOX_API void generateSmoothMeshDataForRegion(BlockVolume<boost::uint8_t>* volumeData, Region region, IndexedSurfacePatch* singleMaterialPatch, IndexedSurfacePatch* multiMaterialPatch);
POLYVOX_API Vector3DFloat computeSmoothNormal(BlockVolume<boost::uint8_t>* volumeData, const Vector3DFloat& position, NormalGenerationMethod normalGenerationMethod);
}
#endif

View File

@ -42,11 +42,10 @@ namespace PolyVox
~VolumeChangeTracker();
//Getters
std::list<RegionGeometry> getChangedRegionGeometry(void);
void getChangedRegions(std::list<Region>& listToFill);
Region getEnclosingRegion(void);
void getChangedRegions(std::list<Region>& listToFill) const;
Region getEnclosingRegion(void) const;
boost::uint16_t getSideLength(void);
const BlockVolume<boost::uint8_t>* getVolumeData(void) const;
BlockVolume<boost::uint8_t>* getVolumeData(void) const;
boost::uint8_t getVoxelAt(const Vector3DUint16& pos);
boost::uint8_t getVoxelAt(boost::uint16_t uX, boost::uint16_t uY, boost::uint16_t uZ);

View File

@ -5,12 +5,40 @@
#include "IndexedSurfacePatch.h"
#include "MarchingCubesTables.h"
#include "Region.h"
#include "RegionGeometry.h"
#include "VolumeChangeTracker.h"
#include "VolumeIterator.h"
using namespace boost;
namespace PolyVox
{
std::list<RegionGeometry> getChangedRegionGeometry(VolumeChangeTracker& volume)
{
std::list<Region> listChangedRegions;
volume.getChangedRegions(listChangedRegions);
std::list<RegionGeometry> listChangedRegionGeometry;
for(std::list<Region>::const_iterator iterChangedRegions = listChangedRegions.begin(); iterChangedRegions != listChangedRegions.end(); ++iterChangedRegions)
{
//Generate the surface
RegionGeometry regionGeometry;
regionGeometry.m_patchSingleMaterial = new IndexedSurfacePatch(false);
regionGeometry.m_patchMultiMaterial = new IndexedSurfacePatch(true);
regionGeometry.m_v3dRegionPosition = iterChangedRegions->getLowerCorner();
generateRoughMeshDataForRegion(volume.getVolumeData(), *iterChangedRegions, regionGeometry.m_patchSingleMaterial, regionGeometry.m_patchMultiMaterial);
regionGeometry.m_bContainsSingleMaterialPatch = regionGeometry.m_patchSingleMaterial->getVertices().size() > 0;
regionGeometry.m_bContainsMultiMaterialPatch = regionGeometry.m_patchMultiMaterial->getVertices().size() > 0;
regionGeometry.m_bIsEmpty = ((regionGeometry.m_patchSingleMaterial->getVertices().size() == 0) && (regionGeometry.m_patchMultiMaterial->getIndices().size() == 0));
listChangedRegionGeometry.push_back(regionGeometry);
}
return listChangedRegionGeometry;
}
void generateRoughMeshDataForRegion(BlockVolume<uint8_t>* volumeData, Region region, IndexedSurfacePatch* singleMaterialPatch, IndexedSurfacePatch* multiMaterialPatch)
{
//When generating the mesh for a region we actually look one voxel outside it in the

View File

@ -56,33 +56,9 @@ namespace PolyVox
volRegionUpToDate = new LinearVolume<bool>(PolyVox::logBase2(POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS));
}
std::list<RegionGeometry> VolumeChangeTracker::getChangedRegionGeometry(void)
{
std::list<Region> listChangedRegions;
getChangedRegions(listChangedRegions);
std::list<RegionGeometry> listChangedRegionGeometry;
for(std::list<Region>::const_iterator iterChangedRegions = listChangedRegions.begin(); iterChangedRegions != listChangedRegions.end(); ++iterChangedRegions)
{
//Generate the surface
RegionGeometry regionGeometry;
regionGeometry.m_patchSingleMaterial = new IndexedSurfacePatch(false);
regionGeometry.m_patchMultiMaterial = new IndexedSurfacePatch(true);
regionGeometry.m_v3dRegionPosition = iterChangedRegions->getLowerCorner();
generateRoughMeshDataForRegion(volumeData, *iterChangedRegions, regionGeometry.m_patchSingleMaterial, regionGeometry.m_patchMultiMaterial);
regionGeometry.m_bContainsSingleMaterialPatch = regionGeometry.m_patchSingleMaterial->getVertices().size() > 0;
regionGeometry.m_bContainsMultiMaterialPatch = regionGeometry.m_patchMultiMaterial->getVertices().size() > 0;
regionGeometry.m_bIsEmpty = ((regionGeometry.m_patchSingleMaterial->getVertices().size() == 0) && (regionGeometry.m_patchMultiMaterial->getIndices().size() == 0));
listChangedRegionGeometry.push_back(regionGeometry);
}
return listChangedRegionGeometry;
}
void VolumeChangeTracker::getChangedRegions(std::list<Region>& listToFill)
void VolumeChangeTracker::getChangedRegions(std::list<Region>& listToFill) const
{
//Clear the list
listToFill.clear();
@ -127,35 +103,12 @@ namespace PolyVox
}
}
/*void VolumeChangeTracker::markRegionChanged(uint16_t firstX, uint16_t firstY, uint16_t firstZ, uint16_t lastX, uint16_t lastY, uint16_t lastZ)
{
const uint16_t firstRegionX = firstX >> POLYVOX_REGION_SIDE_LENGTH_POWER;
const uint16_t firstRegionY = firstY >> POLYVOX_REGION_SIDE_LENGTH_POWER;
const uint16_t firstRegionZ = firstZ >> POLYVOX_REGION_SIDE_LENGTH_POWER;
const uint16_t lastRegionX = lastX >> POLYVOX_REGION_SIDE_LENGTH_POWER;
const uint16_t lastRegionY = lastY >> POLYVOX_REGION_SIDE_LENGTH_POWER;
const uint16_t lastRegionZ = lastZ >> POLYVOX_REGION_SIDE_LENGTH_POWER;
for(uint16_t zCt = firstRegionZ; zCt <= lastRegionZ; zCt++)
{
for(uint16_t yCt = firstRegionY; yCt <= lastRegionY; yCt++)
{
for(uint16_t xCt = firstRegionX; xCt <= lastRegionX; xCt++)
{
//surfaceUpToDate[xCt][yCt][zCt] = false;
volRegionUpToDate->setVoxelAt(xCt,yCt,zCt,false);
}
}
}
}*/
uint16_t VolumeChangeTracker::getSideLength(void)
{
return volumeData->getSideLength();
}
Region VolumeChangeTracker::getEnclosingRegion(void)
Region VolumeChangeTracker::getEnclosingRegion(void) const
{
return volumeData->getEnclosingRegion();
}
@ -176,7 +129,7 @@ namespace PolyVox
return volIter.getVoxel();
}
const BlockVolume<boost::uint8_t>* VolumeChangeTracker::getVolumeData(void) const
BlockVolume<boost::uint8_t>* VolumeChangeTracker::getVolumeData(void) const
{
return volumeData;
}