Merging now controlled by constructor parameter.
This commit is contained in:
parent
63d08b050b
commit
3e00303371
@ -32,23 +32,6 @@ freely, subject to the following restrictions:
|
|||||||
|
|
||||||
namespace PolyVox
|
namespace PolyVox
|
||||||
{
|
{
|
||||||
struct IndexAndMaterial
|
|
||||||
{
|
|
||||||
int32_t iIndex : 24;
|
|
||||||
int32_t uMaterial : 8;
|
|
||||||
};
|
|
||||||
|
|
||||||
enum FaceNames
|
|
||||||
{
|
|
||||||
PositiveX,
|
|
||||||
PositiveY,
|
|
||||||
PositiveZ,
|
|
||||||
NegativeX,
|
|
||||||
NegativeY,
|
|
||||||
NegativeZ,
|
|
||||||
NoOfFaces
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Quad
|
struct Quad
|
||||||
{
|
{
|
||||||
uint32_t vertices[4];
|
uint32_t vertices[4];
|
||||||
@ -58,8 +41,25 @@ namespace PolyVox
|
|||||||
template< template<typename> class VolumeType, typename VoxelType>
|
template< template<typename> class VolumeType, typename VoxelType>
|
||||||
class ImprovedCubicSurfaceExtractor
|
class ImprovedCubicSurfaceExtractor
|
||||||
{
|
{
|
||||||
|
struct IndexAndMaterial
|
||||||
|
{
|
||||||
|
int32_t iIndex : 24;
|
||||||
|
int32_t uMaterial : 8;
|
||||||
|
};
|
||||||
|
|
||||||
|
enum FaceNames
|
||||||
|
{
|
||||||
|
PositiveX,
|
||||||
|
PositiveY,
|
||||||
|
PositiveZ,
|
||||||
|
NegativeX,
|
||||||
|
NegativeY,
|
||||||
|
NegativeZ,
|
||||||
|
NoOfFaces
|
||||||
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ImprovedCubicSurfaceExtractor(VolumeType<VoxelType>* volData, Region region, SurfaceMesh<PositionMaterial>* result);
|
ImprovedCubicSurfaceExtractor(VolumeType<VoxelType>* volData, Region region, SurfaceMesh<PositionMaterial>* result, bool bMergeQuads = true);
|
||||||
|
|
||||||
void execute();
|
void execute();
|
||||||
|
|
||||||
@ -84,6 +84,8 @@ namespace PolyVox
|
|||||||
|
|
||||||
std::vector< std::list<Quad> > m_vecQuads[NoOfFaces];
|
std::vector< std::list<Quad> > m_vecQuads[NoOfFaces];
|
||||||
|
|
||||||
|
bool m_bMergeQuads;
|
||||||
|
|
||||||
//Although we try to avoid creating multiple vertices at the same location, sometimes this is unavoidable
|
//Although we try to avoid creating multiple vertices at the same location, sometimes this is unavoidable
|
||||||
//if they have different materials. For example, four different materials next to each other would mean
|
//if they have different materials. For example, four different materials next to each other would mean
|
||||||
//four quads (though more triangles) sharing the vertex. As far as I can tell, four is the worst case scenario.
|
//four quads (though more triangles) sharing the vertex. As far as I can tell, four is the worst case scenario.
|
||||||
@ -93,18 +95,6 @@ namespace PolyVox
|
|||||||
// Decimation
|
// Decimation
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
/*class Triangle
|
|
||||||
{
|
|
||||||
uint32_t v0;
|
|
||||||
uint32_t v1;
|
|
||||||
uint32_t v2;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<Triangle> triangles;
|
|
||||||
std::vector< std::vector<uint32_t> > trianglesUsingVertex;*/
|
|
||||||
|
|
||||||
//std::vector<Quad> decimate(const std::vector<Quad>& quads);
|
|
||||||
|
|
||||||
bool decimate(std::list<Quad>& quads);
|
bool decimate(std::list<Quad>& quads);
|
||||||
|
|
||||||
Quad mergeQuads(const Quad& q1, const Quad& q2);
|
Quad mergeQuads(const Quad& q1, const Quad& q2);
|
||||||
|
@ -33,11 +33,12 @@ namespace PolyVox
|
|||||||
const uint32_t ImprovedCubicSurfaceExtractor<VolumeType, VoxelType>::MaxQuadsSharingVertex = 4;
|
const uint32_t ImprovedCubicSurfaceExtractor<VolumeType, VoxelType>::MaxQuadsSharingVertex = 4;
|
||||||
|
|
||||||
template< template<typename> class VolumeType, typename VoxelType>
|
template< template<typename> class VolumeType, typename VoxelType>
|
||||||
ImprovedCubicSurfaceExtractor<VolumeType, VoxelType>::ImprovedCubicSurfaceExtractor(VolumeType<VoxelType>* volData, Region region, SurfaceMesh<PositionMaterial>* result)
|
ImprovedCubicSurfaceExtractor<VolumeType, VoxelType>::ImprovedCubicSurfaceExtractor(VolumeType<VoxelType>* volData, Region region, SurfaceMesh<PositionMaterial>* result, bool bMergeQuads)
|
||||||
:m_volData(volData)
|
:m_volData(volData)
|
||||||
,m_sampVolume(volData)
|
,m_sampVolume(volData)
|
||||||
,m_regSizeInVoxels(region)
|
,m_regSizeInVoxels(region)
|
||||||
,m_meshCurrent(result)
|
,m_meshCurrent(result)
|
||||||
|
,m_bMergeQuads(bMergeQuads)
|
||||||
{
|
{
|
||||||
m_meshCurrent->clear();
|
m_meshCurrent->clear();
|
||||||
}
|
}
|
||||||
@ -225,7 +226,10 @@ namespace PolyVox
|
|||||||
{
|
{
|
||||||
std::list<Quad>& listQuads = vecListQuads[slice];
|
std::list<Quad>& listQuads = vecListQuads[slice];
|
||||||
|
|
||||||
while(decimate(listQuads)){}
|
if(m_bMergeQuads)
|
||||||
|
{
|
||||||
|
while(decimate(listQuads)){}
|
||||||
|
}
|
||||||
|
|
||||||
std::list<Quad>::iterator iterEnd = listQuads.end();
|
std::list<Quad>::iterator iterEnd = listQuads.end();
|
||||||
for(std::list<Quad>::iterator quadIter = listQuads.begin(); quadIter != iterEnd; quadIter++)
|
for(std::list<Quad>::iterator quadIter = listQuads.begin(); quadIter != iterEnd; quadIter++)
|
||||||
@ -320,32 +324,6 @@ namespace PolyVox
|
|||||||
template< template<typename> class VolumeType, typename VoxelType>
|
template< template<typename> class VolumeType, typename VoxelType>
|
||||||
Quad ImprovedCubicSurfaceExtractor<VolumeType, VoxelType>::mergeQuads(const Quad& q1, const Quad& q2)
|
Quad ImprovedCubicSurfaceExtractor<VolumeType, VoxelType>::mergeQuads(const Quad& q1, const Quad& q2)
|
||||||
{
|
{
|
||||||
/*Quad* pCurrentQuad = &q1;
|
|
||||||
Quad* pOtherQuad = &q2;
|
|
||||||
uint32_t uCurrentInputIndex = 0;
|
|
||||||
uint32_t uCurrentOutputIndex = 0;
|
|
||||||
|
|
||||||
Quad result;
|
|
||||||
result.material = q1.material;
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
uint32_t uIndexInOtherQuad = quadContainsVertex(*pOtherQuad, (*(pCurrentQuad)).vertices[uCurrentInputIndex]);
|
|
||||||
if(uIndexInOtherQuad != -1)
|
|
||||||
{
|
|
||||||
std::swap(pCurrentQuad, pOtherQuad);
|
|
||||||
uCurrentInputIndex = (uIndexInOtherQuad + 1) % 4;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
result.vertices[uCurrentOutputIndex] = pCurrentQuad->vertices[uCurrentInputIndex];
|
|
||||||
uCurrentOutputIndex++;
|
|
||||||
uCurrentInputIndex = (uCurrentInputIndex + 1) % 4;
|
|
||||||
}
|
|
||||||
} while(uCurrentOutputIndex < 4);
|
|
||||||
|
|
||||||
return result;*/
|
|
||||||
|
|
||||||
Quad result;
|
Quad result;
|
||||||
result.material = q1.material;
|
result.material = q1.material;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user