More work on CubicSurfaceExtractor.

This commit is contained in:
David Williams 2010-10-20 21:09:55 +00:00
parent 0ca8a334f2
commit 695c15cecd
2 changed files with 19 additions and 16 deletions

View File

@ -33,8 +33,8 @@ namespace PolyVox
{ {
struct IndexAndMaterial struct IndexAndMaterial
{ {
int32_t iIndex; int32_t iIndex : 24;
uint8_t uMaterial; int32_t uMaterial : 8;
}; };
template <typename VoxelType> template <typename VoxelType>

View File

@ -157,31 +157,34 @@ namespace PolyVox
} }
template <typename VoxelType> template <typename VoxelType>
int32_t CubicSurfaceExtractor<VoxelType>::addVertex(float fX, float fY, float fZ, uint8_t uMaterial) int32_t CubicSurfaceExtractor<VoxelType>::addVertex(float fX, float fY, float fZ, uint8_t uMaterialIn)
{ {
uint16_t uX = static_cast<uint16_t>(fX + 0.75f); uint16_t uX = static_cast<uint16_t>(fX + 0.75f);
uint16_t uY = static_cast<uint16_t>(fY + 0.75f); uint16_t uY = static_cast<uint16_t>(fY + 0.75f);
uint16_t uZ = static_cast<uint16_t>(fZ + 0.75f); uint16_t uZ = static_cast<uint16_t>(fZ + 0.75f);
//uint32_t index = uX + (uY * (m_regSizeInVoxels.width()+2)) + (uZ * (m_regSizeInVoxels.height()+2) * (m_regSizeInVoxels.height()+2));
for(int ct = 0; ct < 16; ct++) for(int ct = 0; ct < 16; ct++)
{ {
if(m_vertices[uX][uY][uZ][ct].iIndex != -1) IndexAndMaterial& rEntry = m_vertices[uX][uY][uZ][ct];
{
//We have a vertex here, check if the material matches int32_t iIndex = static_cast<int32_t>(rEntry.iIndex);
if(m_vertices[uX][uY][uZ][ct].uMaterial == uMaterial) uint8_t uMaterial = static_cast<uint8_t>(rEntry.uMaterial);
{
//Yep, this is our vertex. Return it. //If we have an existing vertex and the material matches then we can return it.
return m_vertices[uX][uY][uZ][ct].iIndex; if((iIndex != -1) && (uMaterial == uMaterialIn))
} {
return iIndex;
} }
else else
{ {
//No vertices matched and we've now hit an empty space. Fill it by creating a vertex. //No vertices matched and we've now hit an empty space. Fill it by creating a vertex.
uint32_t temp = m_meshCurrent->addVertex(PositionMaterial(Vector3DFloat(fX, fY, fZ), uMaterial)); uint32_t temp = m_meshCurrent->addVertex(PositionMaterial(Vector3DFloat(fX, fY, fZ), uMaterialIn));
m_vertices[uX][uY][uZ][ct].iIndex = temp;
m_vertices[uX][uY][uZ][ct].uMaterial = uMaterial; //Note - Slightly dodgy casting taking place here. No proper way to convert to 24-bit int though?
//If problematic in future then fix IndexAndMaterial to contain variables rather than bitfield.
rEntry.iIndex = temp;
rEntry.uMaterial = uMaterialIn;
return temp; return temp;
} }
} }