From a34c1063824e18e5d93bf4b3274b24c570603118 Mon Sep 17 00:00:00 2001 From: David Williams Date: Sun, 11 May 2014 20:34:41 +0200 Subject: [PATCH] I accidentally merged the 'cubiquity-version' feature back into develop. It seems I can't simply reverse this commit (at least through SourceTree ) because it was a merge, so I'm having to simply revert the contents of the commit (i.e. the files). Bit of a mess! --- .../PolyVoxCore/CubicSurfaceExtractor.h | 10 +- .../PolyVoxCore/CubicSurfaceExtractor.inl | 12 +-- .../MarchingCubesSurfaceExtractor.h | 6 +- .../MarchingCubesSurfaceExtractor.inl | 10 +- .../PolyVoxCore/PolyVoxForwardDeclarations.h | 4 +- .../include/PolyVoxCore/UncompressedBlock.inl | 2 - .../include/PolyVoxCore/VertexTypes.h | 92 ++++--------------- library/PolyVoxCore/source/VertexTypes.cpp | 77 ++++++++++++++++ 8 files changed, 115 insertions(+), 98 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h index 86e04020..a225a3b5 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h +++ b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h @@ -82,7 +82,7 @@ namespace PolyVox struct IndexAndMaterial { int32_t iIndex; - typename VolumeType::VoxelType uMaterial; + int32_t uMaterial; //Should actually use the material type here, but this is ok for now. }; enum FaceNames @@ -113,16 +113,16 @@ namespace PolyVox // This is a bit ugly - it seems that the C++03 syntax is different from the C++11 syntax? See this thread: http://stackoverflow.com/questions/6076015/typename-outside-of-template // Long term we should probably come back to this and if the #ifdef is still needed then maybe it should check for C++11 mode instead of MSVC? #if defined(_MSC_VER) - CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh >* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = VolumeType::VoxelType(), bool bMergeQuads = true, IsQuadNeeded isQuadNeeded = IsQuadNeeded()); + CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = VolumeType::VoxelType(), bool bMergeQuads = true, IsQuadNeeded isQuadNeeded = IsQuadNeeded()); #else - CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh >* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType(), bool bMergeQuads = true, IsQuadNeeded isQuadNeeded = IsQuadNeeded()); + CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType(), bool bMergeQuads = true, IsQuadNeeded isQuadNeeded = IsQuadNeeded()); #endif void execute(); private: - int32_t addVertex(uint32_t uX, uint32_t uY, uint32_t uZ, typename VolumeType::VoxelType 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& quads); bool mergeQuads(Quad& q1, Quad& q2); @@ -135,7 +135,7 @@ namespace PolyVox Region m_regSizeInVoxels; //The surface patch we are currently filling. - SurfaceMesh >* m_meshCurrent; + SurfaceMesh* m_meshCurrent; //Used to avoid creating duplicate vertices. Array<3, IndexAndMaterial> m_previousSliceVertices; diff --git a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl index 9f8b4650..3174c63f 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl @@ -36,7 +36,7 @@ namespace PolyVox const uint32_t CubicSurfaceExtractor::MaxVerticesPerPosition = 8; template - CubicSurfaceExtractor::CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh >* result, WrapMode eWrapMode, typename VolumeType::VoxelType tBorderValue, bool bMergeQuads, IsQuadNeeded isQuadNeeded) + CubicSurfaceExtractor::CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result, WrapMode eWrapMode, typename VolumeType::VoxelType tBorderValue, bool bMergeQuads, IsQuadNeeded isQuadNeeded) :m_volData(volData) ,m_regSizeInVoxels(region) ,m_meshCurrent(result) @@ -88,7 +88,7 @@ namespace PolyVox { uint32_t regX = x - m_regSizeInVoxels.getLowerX(); - typename VolumeType::VoxelType material; //Filled in by callback + uint32_t material; //Filled in by callback typename VolumeType::VoxelType currentVoxel = volumeSampler.getVoxel(); typename VolumeType::VoxelType negXVoxel = volumeSampler.peekVoxel1nx0py0pz(); typename VolumeType::VoxelType negYVoxel = volumeSampler.peekVoxel0px1ny0pz(); @@ -205,7 +205,7 @@ namespace PolyVox } template - int32_t CubicSurfaceExtractor::addVertex(uint32_t uX, uint32_t uY, uint32_t uZ, typename VolumeType::VoxelType uMaterialIn, Array<3, IndexAndMaterial>& existingVertices) + int32_t CubicSurfaceExtractor::addVertex(uint32_t uX, uint32_t uY, uint32_t uZ, uint32_t uMaterialIn, Array<3, IndexAndMaterial>& existingVertices) { for(uint32_t ct = 0; ct < MaxVerticesPerPosition; ct++) { @@ -214,14 +214,14 @@ namespace PolyVox if(rEntry.iIndex == -1) { //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(static_cast(uX) - 0.5f, static_cast(uY) - 0.5f, static_cast(uZ) - 0.5f), uMaterialIn)); + rEntry.iIndex = m_meshCurrent->addVertex(PositionMaterial(Vector3DFloat(static_cast(uX) - 0.5f, static_cast(uY) - 0.5f, static_cast(uZ) - 0.5f), uMaterialIn)); rEntry.uMaterial = uMaterialIn; return rEntry.iIndex; } //If we have an existing vertex and the material matches then we can return it. - if(rEntry.uMaterial == uMaterialIn) + if(rEntry.uMaterial == static_cast(uMaterialIn)) { return rEntry.iIndex; } @@ -268,7 +268,7 @@ namespace PolyVox { //All four vertices of a given quad have the same material, //so just check that the first pair of vertices match. - if(m_meshCurrent->getVertices()[q1.vertices[0]].getMaterial() == m_meshCurrent->getVertices()[q2.vertices[0]].getMaterial()) + if(std::abs(m_meshCurrent->getVertices()[q1.vertices[0]].getMaterial() - m_meshCurrent->getVertices()[q2.vertices[0]].getMaterial()) < 0.001) { //Now check whether quad 2 is adjacent to quad one by comparing vertices. //Adjacent quads must share two vertices, and the second quad could be to the diff --git a/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.h b/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.h index 2e9897f9..31803437 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.h +++ b/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.h @@ -41,9 +41,9 @@ namespace PolyVox // This is a bit ugly - it seems that the C++03 syntax is different from the C++11 syntax? See this thread: http://stackoverflow.com/questions/6076015/typename-outside-of-template // Long term we should probably come back to this and if the #ifdef is still needed then maybe it should check for C++11 mode instead of MSVC? #if defined(_MSC_VER) - MarchingCubesSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh >* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = VolumeType::VoxelType(), Controller controller = Controller()); + MarchingCubesSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = VolumeType::VoxelType(), Controller controller = Controller()); #else - MarchingCubesSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh >* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType(), Controller controller = Controller()); + MarchingCubesSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType(), Controller controller = Controller()); #endif void execute(); @@ -193,7 +193,7 @@ namespace PolyVox uint32_t m_uNoOfOccupiedCells; //The surface patch we are currently filling. - SurfaceMesh >* m_meshCurrent; + SurfaceMesh* m_meshCurrent; //Information about the region we are currently processing Region m_regSizeInVoxels; diff --git a/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.inl b/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.inl index ac65966b..97b97e79 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.inl @@ -26,7 +26,7 @@ freely, subject to the following restrictions: namespace PolyVox { template - MarchingCubesSurfaceExtractor::MarchingCubesSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh >* result, WrapMode eWrapMode, typename VolumeType::VoxelType tBorderValue, Controller controller) + MarchingCubesSurfaceExtractor::MarchingCubesSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result, WrapMode eWrapMode, typename VolumeType::VoxelType tBorderValue, Controller controller) :m_volData(volData) ,m_sampVolume(volData) ,m_meshCurrent(result) @@ -459,7 +459,7 @@ namespace PolyVox // Allow the controller to decide how the material should be derived from the voxels. const typename Controller::MaterialType uMaterial = m_controller.blendMaterials(v000, v100, fInterp); - const PositionMaterialNormal surfaceVertex(v3dPosition, v3dNormal, uMaterial); + const PositionMaterialNormal surfaceVertex(v3dPosition, v3dNormal, static_cast(uMaterial)); const uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex); m_pCurrentVertexIndicesX[iXVolSpace - m_regSizeInVoxels.getLowerX()][iYVolSpace - m_regSizeInVoxels.getLowerY()] = uLastVertexIndex; @@ -488,8 +488,8 @@ namespace PolyVox // Allow the controller to decide how the material should be derived from the voxels. const typename Controller::MaterialType uMaterial = m_controller.blendMaterials(v000, v010, fInterp); - PositionMaterialNormal surfaceVertex(v3dPosition, v3dNormal, uMaterial); - uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex); + const PositionMaterialNormal surfaceVertex(v3dPosition, v3dNormal, static_cast(uMaterial)); + const uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex); m_pCurrentVertexIndicesY[iXVolSpace - m_regSizeInVoxels.getLowerX()][iYVolSpace - m_regSizeInVoxels.getLowerY()] = uLastVertexIndex; m_sampVolume.moveNegativeY(); @@ -516,7 +516,7 @@ namespace PolyVox // Allow the controller to decide how the material should be derived from the voxels. const typename Controller::MaterialType uMaterial = m_controller.blendMaterials(v000, v001, fInterp); - const PositionMaterialNormal surfaceVertex(v3dPosition, v3dNormal, uMaterial); + const PositionMaterialNormal surfaceVertex(v3dPosition, v3dNormal, static_cast(uMaterial)); const uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex); m_pCurrentVertexIndicesZ[iXVolSpace - m_regSizeInVoxels.getLowerX()][iYVolSpace - m_regSizeInVoxels.getLowerY()] = uLastVertexIndex; diff --git a/library/PolyVoxCore/include/PolyVoxCore/PolyVoxForwardDeclarations.h b/library/PolyVoxCore/include/PolyVoxCore/PolyVoxForwardDeclarations.h index 051fb93e..702e786a 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/PolyVoxForwardDeclarations.h +++ b/library/PolyVoxCore/include/PolyVoxCore/PolyVoxForwardDeclarations.h @@ -132,12 +132,12 @@ namespace PolyVox //////////////////////////////////////////////////////////////////////////////// // PositionMaterial //////////////////////////////////////////////////////////////////////////////// - template class PositionMaterial; + class PositionMaterial; //////////////////////////////////////////////////////////////////////////////// // PositionMaterialNormal //////////////////////////////////////////////////////////////////////////////// - template class PositionMaterialNormal; + class PositionMaterialNormal; //////////////////////////////////////////////////////////////////////////////// // RawVolume diff --git a/library/PolyVoxCore/include/PolyVoxCore/UncompressedBlock.inl b/library/PolyVoxCore/include/PolyVoxCore/UncompressedBlock.inl index 2239b267..4d506d74 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/UncompressedBlock.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/UncompressedBlock.inl @@ -21,8 +21,6 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ -#include "PolyVoxCore/Impl/Utility.h" - namespace PolyVox { template diff --git a/library/PolyVoxCore/include/PolyVoxCore/VertexTypes.h b/library/PolyVoxCore/include/PolyVoxCore/VertexTypes.h index 3eb18072..033fad6b 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/VertexTypes.h +++ b/library/PolyVoxCore/include/PolyVoxCore/VertexTypes.h @@ -36,107 +36,49 @@ namespace PolyVox #ifdef SWIG class PositionMaterial #else - template class POLYVOX_API PositionMaterial #endif { public: - PositionMaterial() - { - } + PositionMaterial(); + PositionMaterial(Vector3DFloat positionToSet, float materialToSet); - PositionMaterial(Vector3DFloat positionToSet, MaterialType materialToSet) - :position(positionToSet) - ,material(materialToSet) - { - } + float getMaterial(void) const; + const Vector3DFloat& getPosition(void) const; - MaterialType getMaterial(void) const - { - return material; - } - - const Vector3DFloat& getPosition(void) const - { - return position; - } - - void setMaterial(MaterialType materialToSet) - { - material = materialToSet; - } - - void setPosition(const Vector3DFloat& positionToSet) - { - position = positionToSet; - } + void setMaterial(float materialToSet); + void setPosition(const Vector3DFloat& positionToSet); public: //Nicely fits into four floats. Vector3DFloat position; - MaterialType material; + float material; }; #ifdef SWIG class PositionMaterialNormal #else - template class POLYVOX_API PositionMaterialNormal #endif { public: - PositionMaterialNormal() - { - } + PositionMaterialNormal(); + PositionMaterialNormal(Vector3DFloat positionToSet, float materialToSet); + PositionMaterialNormal(Vector3DFloat positionToSet, Vector3DFloat normalToSet, float materialToSet); - PositionMaterialNormal(Vector3DFloat positionToSet, MaterialType materialToSet) - :position(positionToSet) - ,material(materialToSet) - { - } + float getMaterial(void) const; + const Vector3DFloat& getNormal(void) const; + const Vector3DFloat& getPosition(void) const; - PositionMaterialNormal(Vector3DFloat positionToSet, Vector3DFloat normalToSet, MaterialType materialToSet) - :position(positionToSet) - ,normal(normalToSet) - ,material(materialToSet) - { - } - - MaterialType getMaterial(void) const - { - return material; - } - - const Vector3DFloat& getNormal(void) const - { - return normal; - } - - const Vector3DFloat& getPosition(void) const - { - return position; - } - - void setMaterial(MaterialType materialToSet) - { - material = materialToSet; - } - - void setNormal(const Vector3DFloat& normalToSet) - { - normal = normalToSet; - } - - void setPosition(const Vector3DFloat& positionToSet) - { - position = positionToSet; - } + void setMaterial(float materialToSet); + void setNormal(const Vector3DFloat& normalToSet); + void setPosition(const Vector3DFloat& positionToSet); public: //Nicely fits into seven floats, meaning we //can squeeze in one more for material blending. Vector3DFloat position; Vector3DFloat normal; - MaterialType material; //FIXME: This shouldn't be float on CPU? + float material; //FIXME: This shouldn't be float on CPU? }; } diff --git a/library/PolyVoxCore/source/VertexTypes.cpp b/library/PolyVoxCore/source/VertexTypes.cpp index b4dca237..22a55721 100644 --- a/library/PolyVoxCore/source/VertexTypes.cpp +++ b/library/PolyVoxCore/source/VertexTypes.cpp @@ -25,9 +25,86 @@ freely, subject to the following restrictions: namespace PolyVox { + PositionMaterialNormal::PositionMaterialNormal() + { + } + + PositionMaterialNormal::PositionMaterialNormal(Vector3DFloat positionToSet, float materialToSet) + :position(positionToSet) + ,material(materialToSet) + { + + } + + PositionMaterialNormal::PositionMaterialNormal(Vector3DFloat positionToSet, Vector3DFloat normalToSet, float materialToSet) + :position(positionToSet) + ,normal(normalToSet) + ,material(materialToSet) + { + } + + float PositionMaterialNormal::getMaterial(void) const + { + return material; + } + + const Vector3DFloat& PositionMaterialNormal::getNormal(void) const + { + return normal; + } + + const Vector3DFloat& PositionMaterialNormal::getPosition(void) const + { + return position; + } + + void PositionMaterialNormal::setMaterial(float materialToSet) + { + material = materialToSet; + } + + void PositionMaterialNormal::setNormal(const Vector3DFloat& normalToSet) + { + normal = normalToSet; + } + + void PositionMaterialNormal::setPosition(const Vector3DFloat& positionToSet) + { + position = positionToSet; + } + //////////////////////////////////////////////////////////////////////////////// // PositionMaterial //////////////////////////////////////////////////////////////////////////////// + PositionMaterial::PositionMaterial() + { + } + + PositionMaterial::PositionMaterial(Vector3DFloat positionToSet, float materialToSet) + :position(positionToSet) + ,material(materialToSet) + { + + } + + float PositionMaterial::getMaterial(void) const + { + return material; + } + + const Vector3DFloat& PositionMaterial::getPosition(void) const + { + return position; + } + void PositionMaterial::setMaterial(float materialToSet) + { + material = materialToSet; + } + + void PositionMaterial::setPosition(const Vector3DFloat& positionToSet) + { + position = positionToSet; + } }