From 92ca1048b3d8f05baf61a4291eac9889818da10c Mon Sep 17 00:00:00 2001 From: David Williams Date: Sun, 7 Oct 2012 12:59:17 +0200 Subject: [PATCH] CubicSurfaceExtractor now makes use of callback. --- .../PolyVoxCore/CubicSurfaceExtractor.h | 2 +- .../PolyVoxCore/CubicSurfaceExtractor.inl | 94 +++++++++---------- .../CubicSurfaceExtractorWithNormals.inl | 2 +- .../include/PolyVoxCore/DefaultIsQuadNeeded.h | 6 +- .../include/PolyVoxCore/Material.h | 4 +- .../include/PolyVoxCore/MaterialDensityPair.h | 4 +- 6 files changed, 56 insertions(+), 56 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h index 10a54bfa..39aafcf5 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h +++ b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h @@ -107,7 +107,7 @@ namespace PolyVox }; public: - CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result, bool bMergeQuads = true, IsQuadNeeded isQuadNeeded = IsQuadNeeded()); + CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result, bool bMergeQuads = true, IsQuadNeeded isQuadNeeded = IsQuadNeeded()); void execute(); diff --git a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl index 69c3c3d9..12bcdc2c 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl @@ -87,75 +87,73 @@ namespace PolyVox volumeSampler.setPosition(x,y,z); + uint32_t material; //Filled in by callback typename VolumeType::VoxelType currentVoxel = volumeSampler.getVoxel(); - bool currentVoxelIsSolid = currentVoxel.getMaterial() != 0; - typename VolumeType::VoxelType negXVoxel = volumeSampler.peekVoxel1nx0py0pz(); - bool negXVoxelIsSolid = negXVoxel.getMaterial() != 0; + typename VolumeType::VoxelType negYVoxel = volumeSampler.peekVoxel0px1ny0pz(); + typename VolumeType::VoxelType negZVoxel = volumeSampler.peekVoxel0px0py1nz(); - if(currentVoxelIsSolid != negXVoxelIsSolid) + // X + if(m_funcIsQuadNeededCallback(currentVoxel, negXVoxel, material)) { - uint32_t material = (std::max)(currentVoxel.getMaterial(), negXVoxel.getMaterial()); - uint32_t v0 = addVertex(regX - 0.5f, regY - 0.5f, regZ - 0.5f, material, m_previousSliceVertices); uint32_t v1 = addVertex(regX - 0.5f, regY - 0.5f, regZ + 0.5f, material, m_currentSliceVertices); uint32_t v2 = addVertex(regX - 0.5f, regY + 0.5f, regZ + 0.5f, material, m_currentSliceVertices); uint32_t v3 = addVertex(regX - 0.5f, regY + 0.5f, regZ - 0.5f, material, m_previousSliceVertices); - if(currentVoxelIsSolid > negXVoxelIsSolid) - { - m_vecQuads[NegativeX][regX].push_back(Quad(v0, v1, v2, v3)); - } - else - { - m_vecQuads[PositiveX][regX].push_back(Quad(v0, v3, v2, v1)); - } + m_vecQuads[NegativeX][regX].push_back(Quad(v0, v1, v2, v3)); } - typename VolumeType::VoxelType negYVoxel = volumeSampler.peekVoxel0px1ny0pz(); - bool negYVoxelIsSolid = negYVoxel.getMaterial() != 0; - - if(currentVoxelIsSolid != negYVoxelIsSolid) + if(m_funcIsQuadNeededCallback(negXVoxel, currentVoxel, material)) { - int material = (std::max)(currentVoxel.getMaterial(),negYVoxel.getMaterial()); - uint32_t v0 = addVertex(regX - 0.5f, regY - 0.5f, regZ - 0.5f, material, m_previousSliceVertices); - uint32_t v1 = addVertex(regX - 0.5f, regY - 0.5f, regZ + 0.5f, material, m_currentSliceVertices); - uint32_t v2 = addVertex(regX + 0.5f, regY - 0.5f, regZ + 0.5f, material, m_currentSliceVertices); - uint32_t v3 = addVertex(regX + 0.5f, regY - 0.5f, regZ - 0.5f, material, m_previousSliceVertices); + uint32_t v1 = addVertex(regX - 0.5f, regY - 0.5f, regZ + 0.5f, material, m_currentSliceVertices); + uint32_t v2 = addVertex(regX - 0.5f, regY + 0.5f, regZ + 0.5f, material, m_currentSliceVertices); + uint32_t v3 = addVertex(regX - 0.5f, regY + 0.5f, regZ - 0.5f, material, m_previousSliceVertices); - if(currentVoxelIsSolid > negYVoxelIsSolid) - { - //NOTE: For some reason y windong is opposite of X and Z. Investigate this... - m_vecQuads[NegativeY][regY].push_back(Quad(v0, v3, v2, v1)); - } - else - { - //NOTE: For some reason y windong is opposite of X and Z. Investigate this... - m_vecQuads[PositiveY][regY].push_back(Quad(v0, v1, v2, v3)); - } + m_vecQuads[PositiveX][regX].push_back(Quad(v0, v3, v2, v1)); } - typename VolumeType::VoxelType negZVoxel = volumeSampler.peekVoxel0px0py1nz(); - bool negZVoxelIsSolid = negZVoxel.getMaterial() != 0; - - if(currentVoxelIsSolid != negZVoxelIsSolid) + // Y + if(m_funcIsQuadNeededCallback(currentVoxel, negYVoxel, material)) { - int material = (std::max)(currentVoxel.getMaterial(), negZVoxel.getMaterial()); + uint32_t v0 = addVertex(regX - 0.5f, regY - 0.5f, regZ - 0.5f, material, m_previousSliceVertices); + uint32_t v1 = addVertex(regX + 0.5f, regY - 0.5f, regZ - 0.5f, material, m_previousSliceVertices); + uint32_t v2 = addVertex(regX + 0.5f, regY - 0.5f, regZ + 0.5f, material, m_currentSliceVertices); + uint32_t v3 = addVertex(regX - 0.5f, regY - 0.5f, regZ + 0.5f, material, m_currentSliceVertices); + m_vecQuads[NegativeY][regY].push_back(Quad(v0, v1, v2, v3)); + } + + if(m_funcIsQuadNeededCallback(negYVoxel, currentVoxel, material)) + { + uint32_t v0 = addVertex(regX - 0.5f, regY - 0.5f, regZ - 0.5f, material, m_previousSliceVertices); + uint32_t v1 = addVertex(regX + 0.5f, regY - 0.5f, regZ - 0.5f, material, m_previousSliceVertices); + uint32_t v2 = addVertex(regX + 0.5f, regY - 0.5f, regZ + 0.5f, material, m_currentSliceVertices); + uint32_t v3 = addVertex(regX - 0.5f, regY - 0.5f, regZ + 0.5f, material, m_currentSliceVertices); + + m_vecQuads[PositiveY][regY].push_back(Quad(v0, v3, v2, v1)); + } + + // Z + if(m_funcIsQuadNeededCallback(currentVoxel, negZVoxel, material)) + { uint32_t v0 = addVertex(regX - 0.5f, regY - 0.5f, regZ - 0.5f, material, m_previousSliceVertices); uint32_t v1 = addVertex(regX - 0.5f, regY + 0.5f, regZ - 0.5f, material, m_previousSliceVertices); uint32_t v2 = addVertex(regX + 0.5f, regY + 0.5f, regZ - 0.5f, material, m_previousSliceVertices); - uint32_t v3 = addVertex(regX + 0.5f, regY - 0.5f, regZ - 0.5f, material, m_previousSliceVertices); - - if(currentVoxelIsSolid > negZVoxelIsSolid) - { - m_vecQuads[NegativeZ][regZ].push_back(Quad(v0, v1, v2, v3)); - } - else - { - m_vecQuads[PositiveZ][regZ].push_back(Quad(v0, v3, v2, v1)); - } + uint32_t v3 = addVertex(regX + 0.5f, regY - 0.5f, regZ - 0.5f, material, m_previousSliceVertices); + + m_vecQuads[NegativeZ][regZ].push_back(Quad(v0, v1, v2, v3)); + } + + if(m_funcIsQuadNeededCallback(negZVoxel, currentVoxel, material)) + { + uint32_t v0 = addVertex(regX - 0.5f, regY - 0.5f, regZ - 0.5f, material, m_previousSliceVertices); + uint32_t v1 = addVertex(regX - 0.5f, regY + 0.5f, regZ - 0.5f, material, m_previousSliceVertices); + uint32_t v2 = addVertex(regX + 0.5f, regY + 0.5f, regZ - 0.5f, material, m_previousSliceVertices); + uint32_t v3 = addVertex(regX + 0.5f, regY - 0.5f, regZ - 0.5f, material, m_previousSliceVertices); + + m_vecQuads[PositiveZ][regZ].push_back(Quad(v0, v3, v2, v1)); } } } diff --git a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.inl b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.inl index 59e752a7..ef7183f9 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.inl @@ -49,7 +49,7 @@ namespace PolyVox float regY = static_cast(y - m_regSizeInVoxels.getLowerCorner().getY()); float regZ = static_cast(z - m_regSizeInVoxels.getLowerCorner().getZ()); - float material = 0.0f; + uint32_t material = 0.0f; if(m_funcIsQuadNeededCallback(m_volData->getVoxelAt(x,y,z), m_volData->getVoxelAt(x+1,y,z), material)) { diff --git a/library/PolyVoxCore/include/PolyVoxCore/DefaultIsQuadNeeded.h b/library/PolyVoxCore/include/PolyVoxCore/DefaultIsQuadNeeded.h index e679edf6..5775c4ba 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/DefaultIsQuadNeeded.h +++ b/library/PolyVoxCore/include/PolyVoxCore/DefaultIsQuadNeeded.h @@ -24,17 +24,19 @@ freely, subject to the following restrictions: #ifndef __PolyVox_DefaultIsQuadNeeded_H__ #define __PolyVox_DefaultIsQuadNeeded_H__ +#include + namespace PolyVox { template class DefaultIsQuadNeeded { public: - bool operator()(VoxelType back, VoxelType front, float& materialToUse) + bool operator()(VoxelType back, VoxelType front, uint32_t& materialToUse) { if((back > 0) && (front == 0)) { - materialToUse = static_cast(back); + materialToUse = static_cast(back); return true; } else diff --git a/library/PolyVoxCore/include/PolyVoxCore/Material.h b/library/PolyVoxCore/include/PolyVoxCore/Material.h index 5cc074cb..7bbf78fb 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Material.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Material.h @@ -72,11 +72,11 @@ namespace PolyVox class DefaultIsQuadNeeded< Material > { public: - bool operator()(Material back, Material front, float& materialToUse) + bool operator()(Material back, Material front, uint32_t& materialToUse) { if((back.getMaterial() > 0) && (front.getMaterial() == 0)) { - materialToUse = static_cast(back.getMaterial()); + materialToUse = static_cast(back.getMaterial()); return true; } else diff --git a/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h b/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h index 8da28bfd..95a2b184 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h +++ b/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h @@ -90,11 +90,11 @@ namespace PolyVox class DefaultIsQuadNeeded< MaterialDensityPair > { public: - bool operator()(MaterialDensityPair back, MaterialDensityPair front, float& materialToUse) + bool operator()(MaterialDensityPair back, MaterialDensityPair front, uint32_t& materialToUse) { if((back.getMaterial() > 0) && (front.getMaterial() == 0)) { - materialToUse = static_cast(back.getMaterial()); + materialToUse = static_cast(back.getMaterial()); return true; } else