CubicSurfaceExtractor now uses int for some internal work instead of floats.
This commit is contained in:
parent
b7eeda3370
commit
1a39577ec0
@ -122,7 +122,7 @@ namespace PolyVox
|
|||||||
void execute();
|
void execute();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int32_t addVertex(float fX, float fY, float fZ, uint32_t uMaterial, Array<3, IndexAndMaterial>& existingVertices);
|
int32_t addVertex(uint32_t uX, uint32_t uY, uint32_t uZ, uint32_t uMaterial, Array<3, IndexAndMaterial>& existingVertices);
|
||||||
bool performQuadMerging(std::list<Quad>& quads);
|
bool performQuadMerging(std::list<Quad>& quads);
|
||||||
bool mergeQuads(Quad& q1, Quad& q2);
|
bool mergeQuads(Quad& q1, Quad& q2);
|
||||||
|
|
||||||
|
@ -94,20 +94,20 @@ namespace PolyVox
|
|||||||
// X
|
// X
|
||||||
if(m_funcIsQuadNeededCallback(currentVoxel, negXVoxel, material))
|
if(m_funcIsQuadNeededCallback(currentVoxel, negXVoxel, material))
|
||||||
{
|
{
|
||||||
uint32_t v0 = addVertex(static_cast<float>(regX) - 0.5f, static_cast<float>(regY) - 0.5f, static_cast<float>(regZ) - 0.5f, material, m_previousSliceVertices);
|
uint32_t v0 = addVertex(regX , regY , regZ , material, m_previousSliceVertices);
|
||||||
uint32_t v1 = addVertex(static_cast<float>(regX) - 0.5f, static_cast<float>(regY) - 0.5f, static_cast<float>(regZ) + 0.5f, material, m_currentSliceVertices);
|
uint32_t v1 = addVertex(regX , regY , regZ + 1, material, m_currentSliceVertices);
|
||||||
uint32_t v2 = addVertex(static_cast<float>(regX) - 0.5f, static_cast<float>(regY) + 0.5f, static_cast<float>(regZ) + 0.5f, material, m_currentSliceVertices);
|
uint32_t v2 = addVertex(regX , regY + 1, regZ + 1, material, m_currentSliceVertices);
|
||||||
uint32_t v3 = addVertex(static_cast<float>(regX) - 0.5f, static_cast<float>(regY) + 0.5f, static_cast<float>(regZ) - 0.5f, material, m_previousSliceVertices);
|
uint32_t v3 = addVertex(regX , regY + 1, regZ , material, m_previousSliceVertices);
|
||||||
|
|
||||||
m_vecQuads[NegativeX][regX].push_back(Quad(v0, v1, v2, v3));
|
m_vecQuads[NegativeX][regX].push_back(Quad(v0, v1, v2, v3));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(m_funcIsQuadNeededCallback(negXVoxel, currentVoxel, material))
|
if(m_funcIsQuadNeededCallback(negXVoxel, currentVoxel, material))
|
||||||
{
|
{
|
||||||
uint32_t v0 = addVertex(static_cast<float>(regX) - 0.5f, static_cast<float>(regY) - 0.5f, static_cast<float>(regZ) - 0.5f, material, m_previousSliceVertices);
|
uint32_t v0 = addVertex(regX , regY , regZ , material, m_previousSliceVertices);
|
||||||
uint32_t v1 = addVertex(static_cast<float>(regX) - 0.5f, static_cast<float>(regY) - 0.5f, static_cast<float>(regZ) + 0.5f, material, m_currentSliceVertices);
|
uint32_t v1 = addVertex(regX , regY , regZ + 1, material, m_currentSliceVertices);
|
||||||
uint32_t v2 = addVertex(static_cast<float>(regX) - 0.5f, static_cast<float>(regY) + 0.5f, static_cast<float>(regZ) + 0.5f, material, m_currentSliceVertices);
|
uint32_t v2 = addVertex(regX , regY + 1, regZ + 1, material, m_currentSliceVertices);
|
||||||
uint32_t v3 = addVertex(static_cast<float>(regX) - 0.5f, static_cast<float>(regY) + 0.5f, static_cast<float>(regZ) - 0.5f, material, m_previousSliceVertices);
|
uint32_t v3 = addVertex(regX , regY + 1, regZ , material, m_previousSliceVertices);
|
||||||
|
|
||||||
m_vecQuads[PositiveX][regX].push_back(Quad(v0, v3, v2, v1));
|
m_vecQuads[PositiveX][regX].push_back(Quad(v0, v3, v2, v1));
|
||||||
}
|
}
|
||||||
@ -115,20 +115,20 @@ namespace PolyVox
|
|||||||
// Y
|
// Y
|
||||||
if(m_funcIsQuadNeededCallback(currentVoxel, negYVoxel, material))
|
if(m_funcIsQuadNeededCallback(currentVoxel, negYVoxel, material))
|
||||||
{
|
{
|
||||||
uint32_t v0 = addVertex(static_cast<float>(regX) - 0.5f, static_cast<float>(regY) - 0.5f, static_cast<float>(regZ) - 0.5f, material, m_previousSliceVertices);
|
uint32_t v0 = addVertex(regX , regY , regZ , material, m_previousSliceVertices);
|
||||||
uint32_t v1 = addVertex(static_cast<float>(regX) + 0.5f, static_cast<float>(regY) - 0.5f, static_cast<float>(regZ) - 0.5f, material, m_previousSliceVertices);
|
uint32_t v1 = addVertex(regX + 1, regY , regZ , material, m_previousSliceVertices);
|
||||||
uint32_t v2 = addVertex(static_cast<float>(regX) + 0.5f, static_cast<float>(regY) - 0.5f, static_cast<float>(regZ) + 0.5f, material, m_currentSliceVertices);
|
uint32_t v2 = addVertex(regX + 1, regY , regZ + 1, material, m_currentSliceVertices);
|
||||||
uint32_t v3 = addVertex(static_cast<float>(regX) - 0.5f, static_cast<float>(regY) - 0.5f, static_cast<float>(regZ) + 0.5f, material, m_currentSliceVertices);
|
uint32_t v3 = addVertex(regX , regY , regZ + 1, material, m_currentSliceVertices);
|
||||||
|
|
||||||
m_vecQuads[NegativeY][regY].push_back(Quad(v0, v1, v2, v3));
|
m_vecQuads[NegativeY][regY].push_back(Quad(v0, v1, v2, v3));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(m_funcIsQuadNeededCallback(negYVoxel, currentVoxel, material))
|
if(m_funcIsQuadNeededCallback(negYVoxel, currentVoxel, material))
|
||||||
{
|
{
|
||||||
uint32_t v0 = addVertex(static_cast<float>(regX) - 0.5f, static_cast<float>(regY) - 0.5f, static_cast<float>(regZ) - 0.5f, material, m_previousSliceVertices);
|
uint32_t v0 = addVertex(regX , regY , regZ , material, m_previousSliceVertices);
|
||||||
uint32_t v1 = addVertex(static_cast<float>(regX) + 0.5f, static_cast<float>(regY) - 0.5f, static_cast<float>(regZ) - 0.5f, material, m_previousSliceVertices);
|
uint32_t v1 = addVertex(regX + 1, regY , regZ , material, m_previousSliceVertices);
|
||||||
uint32_t v2 = addVertex(static_cast<float>(regX) + 0.5f, static_cast<float>(regY) - 0.5f, static_cast<float>(regZ) + 0.5f, material, m_currentSliceVertices);
|
uint32_t v2 = addVertex(regX + 1, regY , regZ + 1, material, m_currentSliceVertices);
|
||||||
uint32_t v3 = addVertex(static_cast<float>(regX) - 0.5f, static_cast<float>(regY) - 0.5f, static_cast<float>(regZ) + 0.5f, material, m_currentSliceVertices);
|
uint32_t v3 = addVertex(regX , regY , regZ + 1, material, m_currentSliceVertices);
|
||||||
|
|
||||||
m_vecQuads[PositiveY][regY].push_back(Quad(v0, v3, v2, v1));
|
m_vecQuads[PositiveY][regY].push_back(Quad(v0, v3, v2, v1));
|
||||||
}
|
}
|
||||||
@ -136,20 +136,20 @@ namespace PolyVox
|
|||||||
// Z
|
// Z
|
||||||
if(m_funcIsQuadNeededCallback(currentVoxel, negZVoxel, material))
|
if(m_funcIsQuadNeededCallback(currentVoxel, negZVoxel, material))
|
||||||
{
|
{
|
||||||
uint32_t v0 = addVertex(static_cast<float>(regX) - 0.5f, static_cast<float>(regY) - 0.5f, static_cast<float>(regZ) - 0.5f, material, m_previousSliceVertices);
|
uint32_t v0 = addVertex(regX , regY , regZ , material, m_previousSliceVertices);
|
||||||
uint32_t v1 = addVertex(static_cast<float>(regX) - 0.5f, static_cast<float>(regY) + 0.5f, static_cast<float>(regZ) - 0.5f, material, m_previousSliceVertices);
|
uint32_t v1 = addVertex(regX , regY + 1, regZ , material, m_previousSliceVertices);
|
||||||
uint32_t v2 = addVertex(static_cast<float>(regX) + 0.5f, static_cast<float>(regY) + 0.5f, static_cast<float>(regZ) - 0.5f, material, m_previousSliceVertices);
|
uint32_t v2 = addVertex(regX + 1, regY + 1, regZ , material, m_previousSliceVertices);
|
||||||
uint32_t v3 = addVertex(static_cast<float>(regX) + 0.5f, static_cast<float>(regY) - 0.5f, static_cast<float>(regZ) - 0.5f, material, m_previousSliceVertices);
|
uint32_t v3 = addVertex(regX + 1, regY , regZ , material, m_previousSliceVertices);
|
||||||
|
|
||||||
m_vecQuads[NegativeZ][regZ].push_back(Quad(v0, v1, v2, v3));
|
m_vecQuads[NegativeZ][regZ].push_back(Quad(v0, v1, v2, v3));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(m_funcIsQuadNeededCallback(negZVoxel, currentVoxel, material))
|
if(m_funcIsQuadNeededCallback(negZVoxel, currentVoxel, material))
|
||||||
{
|
{
|
||||||
uint32_t v0 = addVertex(static_cast<float>(regX) - 0.5f, static_cast<float>(regY) - 0.5f, static_cast<float>(regZ) - 0.5f, material, m_previousSliceVertices);
|
uint32_t v0 = addVertex(regX , regY , regZ , material, m_previousSliceVertices);
|
||||||
uint32_t v1 = addVertex(static_cast<float>(regX) - 0.5f, static_cast<float>(regY) + 0.5f, static_cast<float>(regZ) - 0.5f, material, m_previousSliceVertices);
|
uint32_t v1 = addVertex(regX , regY + 1, regZ , material, m_previousSliceVertices);
|
||||||
uint32_t v2 = addVertex(static_cast<float>(regX) + 0.5f, static_cast<float>(regY) + 0.5f, static_cast<float>(regZ) - 0.5f, material, m_previousSliceVertices);
|
uint32_t v2 = addVertex(regX + 1, regY + 1, regZ , material, m_previousSliceVertices);
|
||||||
uint32_t v3 = addVertex(static_cast<float>(regX) + 0.5f, static_cast<float>(regY) - 0.5f, static_cast<float>(regZ) - 0.5f, material, m_previousSliceVertices);
|
uint32_t v3 = addVertex(regX + 1, regY , regZ , material, m_previousSliceVertices);
|
||||||
|
|
||||||
m_vecQuads[PositiveZ][regZ].push_back(Quad(v0, v3, v2, v1));
|
m_vecQuads[PositiveZ][regZ].push_back(Quad(v0, v3, v2, v1));
|
||||||
}
|
}
|
||||||
@ -198,19 +198,16 @@ namespace PolyVox
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename VolumeType, typename IsQuadNeeded>
|
template<typename VolumeType, typename IsQuadNeeded>
|
||||||
int32_t CubicSurfaceExtractor<VolumeType, IsQuadNeeded>::addVertex(float fX, float fY, float fZ, uint32_t uMaterialIn, Array<3, IndexAndMaterial>& existingVertices)
|
int32_t CubicSurfaceExtractor<VolumeType, IsQuadNeeded>::addVertex(uint32_t uX, uint32_t uY, uint32_t uZ, uint32_t uMaterialIn, Array<3, IndexAndMaterial>& existingVertices)
|
||||||
{
|
{
|
||||||
uint32_t uX = static_cast<uint32_t>(fX + 0.75f);
|
|
||||||
uint32_t uY = static_cast<uint32_t>(fY + 0.75f);
|
|
||||||
|
|
||||||
for(uint32_t ct = 0; ct < MaxVerticesPerPosition; ct++)
|
for(uint32_t ct = 0; ct < MaxVerticesPerPosition; ct++)
|
||||||
{
|
{
|
||||||
IndexAndMaterial& rEntry = existingVertices[uX][uY][ct];
|
IndexAndMaterial& rEntry = existingVertices[uX][uY][ct];
|
||||||
|
|
||||||
if(rEntry.iIndex == -1)
|
if(rEntry.iIndex == -1)
|
||||||
{
|
{
|
||||||
//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. The 0.5f offset is because vertices set between voxels in order to build cubes around them.
|
||||||
rEntry.iIndex = m_meshCurrent->addVertex(PositionMaterial(Vector3DFloat(fX, fY, fZ), uMaterialIn));
|
rEntry.iIndex = m_meshCurrent->addVertex(PositionMaterial(Vector3DFloat(static_cast<float>(uX) - 0.5f, static_cast<float>(uY) - 0.5f, static_cast<float>(uZ) - 0.5f), uMaterialIn));
|
||||||
rEntry.uMaterial = uMaterialIn;
|
rEntry.uMaterial = uMaterialIn;
|
||||||
|
|
||||||
return rEntry.iIndex;
|
return rEntry.iIndex;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user