Started implementing 'IsQuadNeeded' for CubicSurfaceExtractor (without normals).
This commit is contained in:
parent
301f93d896
commit
125d9000dd
@ -27,11 +27,12 @@ freely, subject to the following restrictions:
|
|||||||
#include "PolyVoxImpl/TypeDef.h"
|
#include "PolyVoxImpl/TypeDef.h"
|
||||||
|
|
||||||
#include "PolyVoxCore/Array.h"
|
#include "PolyVoxCore/Array.h"
|
||||||
|
#include "PolyVoxCore/DefaultIsQuadNeeded.h"
|
||||||
#include "PolyVoxCore/SurfaceMesh.h"
|
#include "PolyVoxCore/SurfaceMesh.h"
|
||||||
|
|
||||||
namespace PolyVox
|
namespace PolyVox
|
||||||
{
|
{
|
||||||
template<typename VolumeType>
|
template<typename VolumeType, typename IsQuadNeeded = DefaultIsQuadNeeded<typename VolumeType::VoxelType> >
|
||||||
class CubicSurfaceExtractor
|
class CubicSurfaceExtractor
|
||||||
{
|
{
|
||||||
struct IndexAndMaterial
|
struct IndexAndMaterial
|
||||||
@ -57,7 +58,7 @@ namespace PolyVox
|
|||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh<PositionMaterial>* result, bool bMergeQuads = true);
|
CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh<PositionMaterial>* result, bool bMergeQuads = true, IsQuadNeeded isQuadNeeded = IsQuadNeeded());
|
||||||
|
|
||||||
void execute();
|
void execute();
|
||||||
|
|
||||||
@ -66,6 +67,8 @@ namespace PolyVox
|
|||||||
bool performQuadMerging(std::list<Quad>& quads);
|
bool performQuadMerging(std::list<Quad>& quads);
|
||||||
bool mergeQuads(Quad& q1, Quad& q2);
|
bool mergeQuads(Quad& q1, Quad& q2);
|
||||||
|
|
||||||
|
IsQuadNeeded m_funcIsQuadNeededCallback;
|
||||||
|
|
||||||
//The volume data and a sampler to access it.
|
//The volume data and a sampler to access it.
|
||||||
VolumeType* m_volData;
|
VolumeType* m_volData;
|
||||||
|
|
||||||
|
@ -31,20 +31,21 @@ namespace PolyVox
|
|||||||
// The vertex position at the center of this group is then going to be used by six quads all with different materials.
|
// The vertex position at the center of this group is then going to be used by six quads all with different materials.
|
||||||
// One futher note - we can actually have eight quads sharing a vertex position (imagine two 1x1x10 rows of voxels
|
// One futher note - we can actually have eight quads sharing a vertex position (imagine two 1x1x10 rows of voxels
|
||||||
// sharing a common edge) but in this case all eight quads will not have different materials.
|
// sharing a common edge) but in this case all eight quads will not have different materials.
|
||||||
template<typename VolumeType>
|
template<typename VolumeType, typename IsQuadNeeded>
|
||||||
const uint32_t CubicSurfaceExtractor<VolumeType>::MaxVerticesPerPosition = 6;
|
const uint32_t CubicSurfaceExtractor<VolumeType, IsQuadNeeded>::MaxVerticesPerPosition = 6;
|
||||||
|
|
||||||
template<typename VolumeType>
|
template<typename VolumeType, typename IsQuadNeeded>
|
||||||
CubicSurfaceExtractor<VolumeType>::CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh<PositionMaterial>* result, bool bMergeQuads)
|
CubicSurfaceExtractor<VolumeType, IsQuadNeeded>::CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh<PositionMaterial>* result, bool bMergeQuads, IsQuadNeeded isQuadNeeded)
|
||||||
:m_volData(volData)
|
:m_volData(volData)
|
||||||
,m_regSizeInVoxels(region)
|
,m_regSizeInVoxels(region)
|
||||||
,m_meshCurrent(result)
|
,m_meshCurrent(result)
|
||||||
,m_bMergeQuads(bMergeQuads)
|
,m_bMergeQuads(bMergeQuads)
|
||||||
{
|
{
|
||||||
|
m_funcIsQuadNeededCallback = isQuadNeeded;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename VolumeType>
|
template<typename VolumeType, typename IsQuadNeeded>
|
||||||
void CubicSurfaceExtractor<VolumeType>::execute()
|
void CubicSurfaceExtractor<VolumeType, IsQuadNeeded>::execute()
|
||||||
{
|
{
|
||||||
m_meshCurrent->clear();
|
m_meshCurrent->clear();
|
||||||
|
|
||||||
@ -243,8 +244,8 @@ namespace PolyVox
|
|||||||
m_meshCurrent->m_vecLodRecords.push_back(lodRecord);
|
m_meshCurrent->m_vecLodRecords.push_back(lodRecord);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename VolumeType>
|
template<typename VolumeType, typename IsQuadNeeded>
|
||||||
int32_t CubicSurfaceExtractor<VolumeType>::addVertex(float fX, float fY, float fZ, uint32_t uMaterialIn, Array<3, IndexAndMaterial>& existingVertices)
|
int32_t CubicSurfaceExtractor<VolumeType, IsQuadNeeded>::addVertex(float fX, float fY, float fZ, uint32_t uMaterialIn, Array<3, IndexAndMaterial>& existingVertices)
|
||||||
{
|
{
|
||||||
uint32_t uX = static_cast<uint32_t>(fX + 0.75f);
|
uint32_t uX = static_cast<uint32_t>(fX + 0.75f);
|
||||||
uint32_t uY = static_cast<uint32_t>(fY + 0.75f);
|
uint32_t uY = static_cast<uint32_t>(fY + 0.75f);
|
||||||
@ -275,8 +276,8 @@ namespace PolyVox
|
|||||||
return -1; //Should never happen.
|
return -1; //Should never happen.
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename VolumeType>
|
template<typename VolumeType, typename IsQuadNeeded>
|
||||||
bool CubicSurfaceExtractor<VolumeType>::performQuadMerging(std::list<Quad>& quads)
|
bool CubicSurfaceExtractor<VolumeType, IsQuadNeeded>::performQuadMerging(std::list<Quad>& quads)
|
||||||
{
|
{
|
||||||
bool bDidMerge = false;
|
bool bDidMerge = false;
|
||||||
for(typename std::list<Quad>::iterator outerIter = quads.begin(); outerIter != quads.end(); outerIter++)
|
for(typename std::list<Quad>::iterator outerIter = quads.begin(); outerIter != quads.end(); outerIter++)
|
||||||
@ -305,8 +306,8 @@ namespace PolyVox
|
|||||||
return bDidMerge;
|
return bDidMerge;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename VolumeType>
|
template<typename VolumeType, typename IsQuadNeeded>
|
||||||
bool CubicSurfaceExtractor<VolumeType>::mergeQuads(Quad& q1, Quad& q2)
|
bool CubicSurfaceExtractor<VolumeType, IsQuadNeeded>::mergeQuads(Quad& q1, Quad& q2)
|
||||||
{
|
{
|
||||||
//All four vertices of a given quad have the same material,
|
//All four vertices of a given quad have the same material,
|
||||||
//so just check that the first pair of vertices match.
|
//so just check that the first pair of vertices match.
|
||||||
|
@ -26,6 +26,8 @@ freely, subject to the following restrictions:
|
|||||||
|
|
||||||
#include "PolyVoxImpl/TypeDef.h"
|
#include "PolyVoxImpl/TypeDef.h"
|
||||||
|
|
||||||
|
#include "PolyVoxCore/DefaultIsQuadNeeded.h" //we'll specialise this function for this voxel type
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
namespace PolyVox
|
namespace PolyVox
|
||||||
@ -79,6 +81,24 @@ namespace PolyVox
|
|||||||
|
|
||||||
typedef Material<uint8_t> Material8;
|
typedef Material<uint8_t> Material8;
|
||||||
typedef Material<uint16_t> Material16;
|
typedef Material<uint16_t> Material16;
|
||||||
|
|
||||||
|
template<typename Type>
|
||||||
|
class DefaultIsQuadNeeded< Material<Type> >
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
bool operator()(Material<Type> back, Material<Type> front, float& materialToUse)
|
||||||
|
{
|
||||||
|
if((back.getMaterial() > 0) && (front.getMaterial() == 0))
|
||||||
|
{
|
||||||
|
materialToUse = static_cast<float>(back.getMaterial());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //__PolyVox_Material_H__
|
#endif //__PolyVox_Material_H__
|
||||||
|
Loading…
x
Reference in New Issue
Block a user