Switched to floats for vetex positions ready for mesh smoothing.
Added new way to detect duplicate vertices but it's not enabled as it doesn't work yet...
This commit is contained in:
@ -8,11 +8,17 @@ namespace PolyVox
|
||||
long int IndexedSurfacePatch::noOfVerticesAccepted = 0;
|
||||
long int IndexedSurfacePatch::noOfTrianglesSubmitted = 0;
|
||||
long int IndexedSurfacePatch::vertexIndices[POLYVOX_REGION_SIDE_LENGTH*2+1][POLYVOX_REGION_SIDE_LENGTH*2+1][POLYVOX_REGION_SIDE_LENGTH*2+1];
|
||||
int32_t IndexedSurfacePatch::vertexIndicesX[POLYVOX_REGION_SIDE_LENGTH][POLYVOX_REGION_SIDE_LENGTH][POLYVOX_REGION_SIDE_LENGTH];
|
||||
int32_t IndexedSurfacePatch::vertexIndicesY[POLYVOX_REGION_SIDE_LENGTH][POLYVOX_REGION_SIDE_LENGTH][POLYVOX_REGION_SIDE_LENGTH];
|
||||
int32_t IndexedSurfacePatch::vertexIndicesZ[POLYVOX_REGION_SIDE_LENGTH][POLYVOX_REGION_SIDE_LENGTH][POLYVOX_REGION_SIDE_LENGTH];
|
||||
|
||||
IndexedSurfacePatch::IndexedSurfacePatch(bool allowDuplicateVertices)
|
||||
:m_AllowDuplicateVertices(allowDuplicateVertices)
|
||||
{
|
||||
memset(vertexIndices,0xFF,sizeof(vertexIndices)); //0xFF is -1 as two's complement - this may not be portable...
|
||||
memset(vertexIndices,0xFF,sizeof(vertexIndices));
|
||||
memset(vertexIndicesX,0xFF,sizeof(vertexIndicesX)); //0xFF is -1 as two's complement - this may not be portable...
|
||||
memset(vertexIndicesY,0xFF,sizeof(vertexIndicesY));
|
||||
memset(vertexIndicesZ,0xFF,sizeof(vertexIndicesZ));
|
||||
}
|
||||
|
||||
IndexedSurfacePatch::~IndexedSurfacePatch()
|
||||
@ -26,11 +32,13 @@ namespace PolyVox
|
||||
if(!m_AllowDuplicateVertices)
|
||||
{
|
||||
long int index = vertexIndices[long int(v0.getPosition().x() * 2.0 +0.5)][long int(v0.getPosition().y() * 2.0 +0.5)][long int(v0.getPosition().z() * 2.0 +0.5)];
|
||||
//int32_t index = getIndexFor(v0.getPosition());
|
||||
if(index == -1)
|
||||
{
|
||||
m_vecVertices.push_back(v0);
|
||||
m_vecTriangleIndices.push_back(m_vecVertices.size()-1);
|
||||
vertexIndices[long int(v0.getPosition().x() * 2.0 +0.5)][long int(v0.getPosition().y() * 2.0 +0.5)][long int(v0.getPosition().z() * 2.0 +0.5)] = m_vecVertices.size()-1;
|
||||
//setIndexFor(v0.getPosition(), m_vecVertices.size()-1);
|
||||
|
||||
noOfVerticesAccepted++;
|
||||
}
|
||||
@ -40,11 +48,13 @@ namespace PolyVox
|
||||
}
|
||||
|
||||
index = vertexIndices[long int(v1.getPosition().x() * 2.0 +0.5)][long int(v1.getPosition().y() * 2.0 +0.5)][long int(v1.getPosition().z() * 2.0 +0.5)];
|
||||
//index = getIndexFor(v1.getPosition());
|
||||
if(index == -1)
|
||||
{
|
||||
m_vecVertices.push_back(v1);
|
||||
m_vecTriangleIndices.push_back(m_vecVertices.size()-1);
|
||||
vertexIndices[long int(v1.getPosition().x() * 2.0 +0.5)][long int(v1.getPosition().y() * 2.0 +0.5)][long int(v1.getPosition().z() * 2.0 +0.5)] = m_vecVertices.size()-1;
|
||||
//setIndexFor(v1.getPosition(), m_vecVertices.size()-1);
|
||||
|
||||
noOfVerticesAccepted++;
|
||||
}
|
||||
@ -54,11 +64,13 @@ namespace PolyVox
|
||||
}
|
||||
|
||||
index = vertexIndices[long int(v2.getPosition().x() * 2.0 +0.5)][long int(v2.getPosition().y() * 2.0 +0.5)][long int(v2.getPosition().z() * 2.0 +0.5)];
|
||||
//index = getIndexFor(v2.getPosition());
|
||||
if(index == -1)
|
||||
{
|
||||
m_vecVertices.push_back(v2);
|
||||
m_vecTriangleIndices.push_back(m_vecVertices.size()-1);
|
||||
vertexIndices[long int(v2.getPosition().x() * 2.0 +0.5)][long int(v2.getPosition().y() * 2.0 +0.5)][long int(v2.getPosition().z() * 2.0 +0.5)] = m_vecVertices.size()-1;
|
||||
//setIndexFor(v2.getPosition(), m_vecVertices.size()-1);
|
||||
|
||||
noOfVerticesAccepted++;
|
||||
}
|
||||
@ -102,4 +114,53 @@ namespace PolyVox
|
||||
size += m_vecTriangleIndices.capacity() * sizeof(m_vecTriangleIndices[0]);
|
||||
return size;
|
||||
}
|
||||
|
||||
boost::int32_t IndexedSurfacePatch::getIndexFor(const Vector3DFloat& pos)
|
||||
{
|
||||
float xIntPart;
|
||||
float xFracPart = modf(pos.x(), &xIntPart);
|
||||
float yIntPart;
|
||||
float yFracPart = modf(pos.y(), &yIntPart);
|
||||
float zIntPart;
|
||||
float zFracPart = modf(pos.z(), &zIntPart);
|
||||
|
||||
//Of all the fractional parts, two should be zero and one should have a value.
|
||||
if(xFracPart > 0.000001f)
|
||||
{
|
||||
return vertexIndicesX[static_cast<uint16_t>(xIntPart)][static_cast<uint16_t>(yIntPart)][static_cast<uint16_t>(zIntPart)];
|
||||
}
|
||||
if(yFracPart > 0.000001f)
|
||||
{
|
||||
return vertexIndicesY[static_cast<uint16_t>(xIntPart)][static_cast<uint16_t>(yIntPart)][static_cast<uint16_t>(zIntPart)];
|
||||
}
|
||||
if(zFracPart > 0.000001f)
|
||||
{
|
||||
return vertexIndicesZ[static_cast<uint16_t>(xIntPart)][static_cast<uint16_t>(yIntPart)][static_cast<uint16_t>(zIntPart)];
|
||||
}
|
||||
while(true);
|
||||
}
|
||||
|
||||
void IndexedSurfacePatch::setIndexFor(const Vector3DFloat& pos, boost::int32_t newIndex)
|
||||
{
|
||||
float xIntPart;
|
||||
float xFracPart = modf(pos.x(), &xIntPart);
|
||||
float yIntPart;
|
||||
float yFracPart = modf(pos.y(), &yIntPart);
|
||||
float zIntPart;
|
||||
float zFracPart = modf(pos.z(), &zIntPart);
|
||||
|
||||
//Of all the fractional parts, two should be zero and one should have a value.
|
||||
if(xFracPart > 0.000001f)
|
||||
{
|
||||
vertexIndicesX[static_cast<uint16_t>(xIntPart)][static_cast<uint16_t>(yIntPart)][static_cast<uint16_t>(zIntPart)] = newIndex;
|
||||
}
|
||||
if(yFracPart > 0.000001f)
|
||||
{
|
||||
vertexIndicesY[static_cast<uint16_t>(xIntPart)][static_cast<uint16_t>(yIntPart)][static_cast<uint16_t>(zIntPart)] = newIndex;
|
||||
}
|
||||
if(zFracPart > 0.000001f)
|
||||
{
|
||||
vertexIndicesZ[static_cast<uint16_t>(xIntPart)][static_cast<uint16_t>(yIntPart)][static_cast<uint16_t>(zIntPart)] = newIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user