From 4c2aea3db10b278f17a66f1ee92d3117af6d8945 Mon Sep 17 00:00:00 2001 From: David Williams Date: Tue, 6 May 2014 22:00:24 +0200 Subject: [PATCH] Removed CubicSurfaceExtractorWithNornals. Going forward users will be expected to compute flat normals in the fragment shader. --- examples/Paging/OpenGLWidget.cpp | 8 +- examples/Paging/main.cpp | 4 +- library/PolyVoxCore/CMakeLists.txt | 2 - .../CubicSurfaceExtractorWithNormals.h | 70 --------- .../CubicSurfaceExtractorWithNormals.inl | 137 ------------------ 5 files changed, 6 insertions(+), 215 deletions(-) delete mode 100644 library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.h delete mode 100644 library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.inl diff --git a/examples/Paging/OpenGLWidget.cpp b/examples/Paging/OpenGLWidget.cpp index 4347be2f..758bf56e 100644 --- a/examples/Paging/OpenGLWidget.cpp +++ b/examples/Paging/OpenGLWidget.cpp @@ -62,10 +62,10 @@ void OpenGLWidget::initializeGL() glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); - //Anable smooth lighting - glEnable(GL_LIGHTING); - glEnable(GL_LIGHT0); - glShadeModel(GL_SMOOTH); + //Enable smooth lighting + //glEnable(GL_LIGHTING); + //glEnable(GL_LIGHT0); + //glShadeModel(GL_SMOOTH); //We'll be rendering with index/vertex arrays glEnableClientState(GL_VERTEX_ARRAY); diff --git a/examples/Paging/main.cpp b/examples/Paging/main.cpp index 27236afd..b5df0e20 100644 --- a/examples/Paging/main.cpp +++ b/examples/Paging/main.cpp @@ -25,7 +25,7 @@ freely, subject to the following restrictions: #include "Perlin.h" #include "PolyVoxCore/MaterialDensityPair.h" -#include "PolyVoxCore/CubicSurfaceExtractorWithNormals.h" +#include "PolyVoxCore/CubicSurfaceExtractor.h" #include "PolyVoxCore/MarchingCubesSurfaceExtractor.h" #include "PolyVoxCore/Pager.h" #include "PolyVoxCore/RLEBlockCompressor.h" @@ -187,7 +187,7 @@ int main(int argc, char *argv[]) //Extract the surface SurfaceMesh mesh; - CubicSurfaceExtractorWithNormals< LargeVolume > surfaceExtractor(&volData, reg, &mesh); + CubicSurfaceExtractor< LargeVolume > surfaceExtractor(&volData, reg, &mesh); //MarchingCubesSurfaceExtractor< LargeVolume > surfaceExtractor(&volData, reg, &mesh); //CubicSurfaceExtractorWithNormals surfaceExtractor(&volData, reg, &mesh); surfaceExtractor.execute(); diff --git a/library/PolyVoxCore/CMakeLists.txt b/library/PolyVoxCore/CMakeLists.txt index 0d07f2b8..e4289feb 100644 --- a/library/PolyVoxCore/CMakeLists.txt +++ b/library/PolyVoxCore/CMakeLists.txt @@ -48,8 +48,6 @@ SET(CORE_INC_FILES include/PolyVoxCore/CompressedBlock.inl include/PolyVoxCore/CubicSurfaceExtractor.h include/PolyVoxCore/CubicSurfaceExtractor.inl - include/PolyVoxCore/CubicSurfaceExtractorWithNormals.h - include/PolyVoxCore/CubicSurfaceExtractorWithNormals.inl include/PolyVoxCore/DefaultIsQuadNeeded.h include/PolyVoxCore/DefaultMarchingCubesController.h include/PolyVoxCore/Density.h diff --git a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.h b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.h deleted file mode 100644 index 211734f0..00000000 --- a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.h +++ /dev/null @@ -1,70 +0,0 @@ -/******************************************************************************* -Copyright (c) 2005-2009 David Williams - -This software is provided 'as-is', without any express or implied -warranty. In no event will the authors be held liable for any damages -arising from the use of this software. - -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it -freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - - 3. This notice may not be removed or altered from any source - distribution. -*******************************************************************************/ - -#ifndef __PolyVox_CubicSurfaceExtractorWithNormals_H__ -#define __PolyVox_CubicSurfaceExtractorWithNormals_H__ - -#include "PolyVoxCore/DefaultIsQuadNeeded.h" - -#include "PolyVoxCore/Array.h" -#include "PolyVoxCore/BaseVolume.h" //For wrap modes... should move these? -#include "PolyVoxCore/SurfaceMesh.h" - -namespace PolyVox -{ - template > - class CubicSurfaceExtractorWithNormals - { - public: - // 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) - CubicSurfaceExtractorWithNormals(VolumeType* volData, Region region, SurfaceMesh* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = VolumeType::VoxelType(), IsQuadNeeded isQuadNeeded = IsQuadNeeded()); -#else - CubicSurfaceExtractorWithNormals(VolumeType* volData, Region region, SurfaceMesh* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType(), IsQuadNeeded isQuadNeeded = IsQuadNeeded()); -#endif - - void execute(); - - private: - IsQuadNeeded m_funcIsQuadNeededCallback; - - //The volume data and a sampler to access it. - VolumeType* m_volData; - typename VolumeType::Sampler m_sampVolume; - - //The surface patch we are currently filling. - SurfaceMesh* m_meshCurrent; - - //Information about the region we are currently processing - Region m_regSizeInVoxels; - - //The wrap mode - WrapMode m_eWrapMode; - typename VolumeType::VoxelType m_tBorderValue; - }; -} - -#include "PolyVoxCore/CubicSurfaceExtractorWithNormals.inl" - -#endif diff --git a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.inl b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.inl deleted file mode 100644 index bd8259c5..00000000 --- a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.inl +++ /dev/null @@ -1,137 +0,0 @@ -/******************************************************************************* -Copyright (c) 2005-2009 David Williams - -This software is provided 'as-is', without any express or implied -warranty. In no event will the authors be held liable for any damages -arising from the use of this software. - -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it -freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - - 3. This notice may not be removed or altered from any source - distribution. -*******************************************************************************/ - -#include "PolyVoxCore/Impl/Timer.h" - -namespace PolyVox -{ - template - CubicSurfaceExtractorWithNormals::CubicSurfaceExtractorWithNormals(VolumeType* volData, Region region, SurfaceMesh* result, WrapMode eWrapMode, typename VolumeType::VoxelType tBorderValue, IsQuadNeeded isQuadNeeded) - :m_volData(volData) - ,m_sampVolume(volData) - ,m_meshCurrent(result) - ,m_regSizeInVoxels(region) - ,m_eWrapMode(eWrapMode) - ,m_tBorderValue(tBorderValue) - { - m_funcIsQuadNeededCallback = isQuadNeeded; - } - - template - void CubicSurfaceExtractorWithNormals::execute() - { - Timer timer; - m_meshCurrent->clear(); - - for(int32_t z = m_regSizeInVoxels.getLowerZ(); z < m_regSizeInVoxels.getUpperZ(); z++) - { - for(int32_t y = m_regSizeInVoxels.getLowerY(); y < m_regSizeInVoxels.getUpperY(); y++) - { - for(int32_t x = m_regSizeInVoxels.getLowerX(); x < m_regSizeInVoxels.getUpperX(); x++) - { - // these are always positive anyway - float regX = static_cast(x - m_regSizeInVoxels.getLowerX()); - float regY = static_cast(y - m_regSizeInVoxels.getLowerY()); - float regZ = static_cast(z - m_regSizeInVoxels.getLowerZ()); - - uint32_t material = 0; - - if(m_funcIsQuadNeededCallback(m_volData->getVoxel(x,y,z,m_eWrapMode,m_tBorderValue), m_volData->getVoxel(x+1,y,z,m_eWrapMode,m_tBorderValue), material)) - { - uint32_t v0 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX + 0.5f, regY - 0.5f, regZ - 0.5f), Vector3DFloat(1.0f, 0.0f, 0.0f), static_cast(material))); - uint32_t v1 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX + 0.5f, regY - 0.5f, regZ + 0.5f), Vector3DFloat(1.0f, 0.0f, 0.0f), static_cast(material))); - uint32_t v2 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX + 0.5f, regY + 0.5f, regZ - 0.5f), Vector3DFloat(1.0f, 0.0f, 0.0f), static_cast(material))); - uint32_t v3 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX + 0.5f, regY + 0.5f, regZ + 0.5f), Vector3DFloat(1.0f, 0.0f, 0.0f), static_cast(material))); - - m_meshCurrent->addTriangleCubic(v0,v2,v1); - m_meshCurrent->addTriangleCubic(v1,v2,v3); - } - if(m_funcIsQuadNeededCallback(m_volData->getVoxel(x+1,y,z,m_eWrapMode,m_tBorderValue), m_volData->getVoxel(x,y,z,m_eWrapMode,m_tBorderValue), material)) - { - uint32_t v0 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX + 0.5f, regY - 0.5f, regZ - 0.5f), Vector3DFloat(-1.0f, 0.0f, 0.0f), static_cast(material))); - uint32_t v1 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX + 0.5f, regY - 0.5f, regZ + 0.5f), Vector3DFloat(-1.0f, 0.0f, 0.0f), static_cast(material))); - uint32_t v2 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX + 0.5f, regY + 0.5f, regZ - 0.5f), Vector3DFloat(-1.0f, 0.0f, 0.0f), static_cast(material))); - uint32_t v3 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX + 0.5f, regY + 0.5f, regZ + 0.5f), Vector3DFloat(-1.0f, 0.0f, 0.0f), static_cast(material))); - - m_meshCurrent->addTriangleCubic(v0,v1,v2); - m_meshCurrent->addTriangleCubic(v1,v3,v2); - } - - if(m_funcIsQuadNeededCallback(m_volData->getVoxel(x,y,z,m_eWrapMode,m_tBorderValue), m_volData->getVoxel(x,y+1,z,m_eWrapMode,m_tBorderValue), material)) - { - uint32_t v0 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY + 0.5f, regZ - 0.5f), Vector3DFloat(0.0f, 1.0f, 0.0f), static_cast(material))); - uint32_t v1 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY + 0.5f, regZ + 0.5f), Vector3DFloat(0.0f, 1.0f, 0.0f), static_cast(material))); - uint32_t v2 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX + 0.5f, regY + 0.5f, regZ - 0.5f), Vector3DFloat(0.0f, 1.0f, 0.0f), static_cast(material))); - uint32_t v3 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX + 0.5f, regY + 0.5f, regZ + 0.5f), Vector3DFloat(0.0f, 1.0f, 0.0f), static_cast(material))); - - m_meshCurrent->addTriangleCubic(v0,v1,v2); - m_meshCurrent->addTriangleCubic(v1,v3,v2); - } - if(m_funcIsQuadNeededCallback(m_volData->getVoxel(x,y+1,z,m_eWrapMode,m_tBorderValue), m_volData->getVoxel(x,y,z,m_eWrapMode,m_tBorderValue), material)) - { - uint32_t v0 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY + 0.5f, regZ - 0.5f), Vector3DFloat(0.0f, -1.0f, 0.0f), static_cast(material))); - uint32_t v1 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY + 0.5f, regZ + 0.5f), Vector3DFloat(0.0f, -1.0f, 0.0f), static_cast(material))); - uint32_t v2 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX + 0.5f, regY + 0.5f, regZ - 0.5f), Vector3DFloat(0.0f, -1.0f, 0.0f), static_cast(material))); - uint32_t v3 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX + 0.5f, regY + 0.5f, regZ + 0.5f), Vector3DFloat(0.0f, -1.0f, 0.0f), static_cast(material))); - - m_meshCurrent->addTriangleCubic(v0,v2,v1); - m_meshCurrent->addTriangleCubic(v1,v2,v3); - } - - if(m_funcIsQuadNeededCallback(m_volData->getVoxel(x,y,z,m_eWrapMode,m_tBorderValue), m_volData->getVoxel(x,y,z+1,m_eWrapMode,m_tBorderValue), material)) - { - uint32_t v0 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY - 0.5f, regZ + 0.5f), Vector3DFloat(0.0f, 0.0f, 1.0f), static_cast(material))); - uint32_t v1 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY + 0.5f, regZ + 0.5f), Vector3DFloat(0.0f, 0.0f, 1.0f), static_cast(material))); - uint32_t v2 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX + 0.5f, regY - 0.5f, regZ + 0.5f), Vector3DFloat(0.0f, 0.0f, 1.0f), static_cast(material))); - uint32_t v3 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX + 0.5f, regY + 0.5f, regZ + 0.5f), Vector3DFloat(0.0f, 0.0f, 1.0f), static_cast(material))); - - m_meshCurrent->addTriangleCubic(v0,v2,v1); - m_meshCurrent->addTriangleCubic(v1,v2,v3); - } - if(m_funcIsQuadNeededCallback(m_volData->getVoxel(x,y,z+1,m_eWrapMode,m_tBorderValue), m_volData->getVoxel(x,y,z,m_eWrapMode,m_tBorderValue), material)) - { - uint32_t v0 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY - 0.5f, regZ + 0.5f), Vector3DFloat(0.0f, 0.0f, -1.0f), static_cast(material))); - uint32_t v1 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY + 0.5f, regZ + 0.5f), Vector3DFloat(0.0f, 0.0f, -1.0f), static_cast(material))); - uint32_t v2 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX + 0.5f, regY - 0.5f, regZ + 0.5f), Vector3DFloat(0.0f, 0.0f, -1.0f), static_cast(material))); - uint32_t v3 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX + 0.5f, regY + 0.5f, regZ + 0.5f), Vector3DFloat(0.0f, 0.0f, -1.0f), static_cast(material))); - - m_meshCurrent->addTriangleCubic(v0,v1,v2); - m_meshCurrent->addTriangleCubic(v1,v3,v2); - } - } - } - } - - m_meshCurrent->m_Region = m_regSizeInVoxels; - - m_meshCurrent->m_vecLodRecords.clear(); - LodRecord lodRecord; - lodRecord.beginIndex = 0; - lodRecord.endIndex = m_meshCurrent->getNoOfIndices(); - m_meshCurrent->m_vecLodRecords.push_back(lodRecord); - - POLYVOX_LOG_TRACE("Cubic surface extraction took " << timer.elapsedTimeInMilliSeconds() - << "ms (Region size = " << m_regSizeInVoxels.getWidthInVoxels() << "x" << m_regSizeInVoxels.getHeightInVoxels() - << "x" << m_regSizeInVoxels.getDepthInVoxels() << ")"); - } -}