diff --git a/examples/Basic/OpenGLWidget.cpp b/examples/Basic/OpenGLWidget.cpp index eb47180e..7fb5f2cb 100644 --- a/examples/Basic/OpenGLWidget.cpp +++ b/examples/Basic/OpenGLWidget.cpp @@ -15,7 +15,7 @@ OpenGLWidget::OpenGLWidget(QWidget *parent) { } -void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh >& surfaceMesh) +void OpenGLWidget::setMeshToRender(const PolyVox::Mesh >& surfaceMesh) { //Convienient access to the vertices and indices const auto& vecIndices = surfaceMesh.getIndices(); diff --git a/examples/Basic/OpenGLWidget.h b/examples/Basic/OpenGLWidget.h index f95dbdbb..266ee0e6 100644 --- a/examples/Basic/OpenGLWidget.h +++ b/examples/Basic/OpenGLWidget.h @@ -24,7 +24,7 @@ distribution. #ifndef __BasicExample_OpenGLWidget_H__ #define __BasicExample_OpenGLWidget_H__ -#include "PolyVoxCore/SurfaceMesh.h" +#include "PolyVoxCore/Mesh.h" #include "glew/glew.h" @@ -50,7 +50,7 @@ public: void mousePressEvent(QMouseEvent* event); // Convert a SurfaceMesh to OpenGL index/vertex buffers - void setSurfaceMeshToRender(const PolyVox::SurfaceMesh >& surfaceMesh); + void setMeshToRender(const PolyVox::Mesh >& surfaceMesh); // The viewable region can be adjusted so that this example framework can be use for different volume sizes. void setViewableRegion(PolyVox::Region viewableRegion); diff --git a/examples/Basic/main.cpp b/examples/Basic/main.cpp index 82031152..c3a53f59 100644 --- a/examples/Basic/main.cpp +++ b/examples/Basic/main.cpp @@ -25,7 +25,7 @@ freely, subject to the following restrictions: #include "PolyVoxCore/CubicSurfaceExtractor.h" #include "PolyVoxCore/MarchingCubesSurfaceExtractor.h" -#include "PolyVoxCore/SurfaceMesh.h" +#include "PolyVoxCore/Mesh.h" #include "PolyVoxCore/SimpleVolume.h" #include @@ -85,9 +85,9 @@ int main(int argc, char *argv[]) //auto mesh2 = extractCubicMesh(&volData, PolyVox::Region(Vector3DInt32(32, 32, 32), Vector3DInt32(63, 63, 63))); //Pass the surface to the OpenGL window - openGLWidget.setSurfaceMeshToRender(mesh); + openGLWidget.setMeshToRender(mesh); openGLWidget.setViewableRegion(volData.getEnclosingRegion()); - //openGLWidget.setSurfaceMeshToRender(mesh2); + //openGLWidget.setMeshToRender(mesh2); //Run the message pump. return app.exec(); diff --git a/examples/OpenGL/OpenGLImmediateModeSupport.cpp b/examples/OpenGL/OpenGLImmediateModeSupport.cpp index 7aff64df..ab2522bd 100644 --- a/examples/OpenGL/OpenGLImmediateModeSupport.cpp +++ b/examples/OpenGL/OpenGLImmediateModeSupport.cpp @@ -24,12 +24,12 @@ freely, subject to the following restrictions: #include "OpenGLImmediateModeSupport.h" #include "OpenGLSupport.h" -#include "PolyVoxCore/SurfaceMesh.h" +#include "PolyVoxCore/Mesh.h" using namespace PolyVox; using namespace std; -void renderRegionImmediateMode(PolyVox::SurfaceMesh >& mesh, unsigned int uLodLevel) +void renderRegionImmediateMode(PolyVox::Mesh >& mesh, unsigned int uLodLevel) { const vector >& vecVertices = mesh.getVertices(); const vector& vecIndices = mesh.getIndices(); diff --git a/examples/OpenGL/OpenGLImmediateModeSupport.h b/examples/OpenGL/OpenGLImmediateModeSupport.h index 9f5aea79..3bc45a2b 100644 --- a/examples/OpenGL/OpenGLImmediateModeSupport.h +++ b/examples/OpenGL/OpenGLImmediateModeSupport.h @@ -29,6 +29,6 @@ freely, subject to the following restrictions: #include "glew/glew.h" -void renderRegionImmediateMode(PolyVox::SurfaceMesh >& mesh, unsigned int uLodLevel); +void renderRegionImmediateMode(PolyVox::Mesh >& mesh, unsigned int uLodLevel); #endif //__OpenGLExample_OpenGLImmediateModeSupport_H__ diff --git a/examples/OpenGL/OpenGLVertexBufferObjectSupport.cpp b/examples/OpenGL/OpenGLVertexBufferObjectSupport.cpp index ae5afd15..17e9e138 100644 --- a/examples/OpenGL/OpenGLVertexBufferObjectSupport.cpp +++ b/examples/OpenGL/OpenGLVertexBufferObjectSupport.cpp @@ -25,15 +25,15 @@ freely, subject to the following restrictions: #include "OpenGLVertexBufferObjectSupport.h" #include "PolyVoxCore/MaterialDensityPair.h" -#include "PolyVoxCore/SurfaceMesh.h" +#include "PolyVoxCore/Mesh.h" using namespace PolyVox; using namespace std; -OpenGLSurfaceMesh BuildOpenGLSurfaceMesh(const SurfaceMesh >& mesh) +OpenGLMesh BuildOpenGLMesh(const Mesh >& mesh) { //Represents our filled in OpenGL vertex and index buffer objects. - OpenGLSurfaceMesh result; + OpenGLMesh result; //The source result.sourceMesh = &mesh; @@ -102,23 +102,23 @@ OpenGLSurfaceMesh BuildOpenGLSurfaceMesh(const SurfaceMeshm_vecLodRecords[uLodLevel].beginIndex; - int endIndex = openGLSurfaceMesh.sourceMesh->m_vecLodRecords[uLodLevel].endIndex; - glBindBuffer(GL_ARRAY_BUFFER, openGLSurfaceMesh.vertexBuffer); + int beginIndex = openGLMesh.sourceMesh->m_vecLodRecords[uLodLevel].beginIndex; + int endIndex = openGLMesh.sourceMesh->m_vecLodRecords[uLodLevel].endIndex; + glBindBuffer(GL_ARRAY_BUFFER, openGLMesh.vertexBuffer); glVertexPointer(3, GL_FLOAT, 36, 0); glNormalPointer(GL_FLOAT, 36, (GLvoid*)12); glColorPointer(3, GL_FLOAT, 36, (GLvoid*)24); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, openGLSurfaceMesh.indexBuffer); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, openGLMesh.indexBuffer); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_COLOR_ARRAY); - //glDrawElements(GL_TRIANGLES, openGLSurfaceMesh.noOfIndices, GL_UNSIGNED_INT, 0); - glDrawRangeElements(GL_TRIANGLES, beginIndex, endIndex-1, endIndex - beginIndex,/* openGLSurfaceMesh.noOfIndices,*/ GL_UNSIGNED_INT, 0); + //glDrawElements(GL_TRIANGLES, openGLMesh.noOfIndices, GL_UNSIGNED_INT, 0); + glDrawRangeElements(GL_TRIANGLES, beginIndex, endIndex-1, endIndex - beginIndex,/* openGLMesh.noOfIndices,*/ GL_UNSIGNED_INT, 0); glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); diff --git a/examples/OpenGL/OpenGLVertexBufferObjectSupport.h b/examples/OpenGL/OpenGLVertexBufferObjectSupport.h index fc97dfb8..e82a8c29 100644 --- a/examples/OpenGL/OpenGLVertexBufferObjectSupport.h +++ b/examples/OpenGL/OpenGLVertexBufferObjectSupport.h @@ -28,15 +28,15 @@ freely, subject to the following restrictions: #include "glew/glew.h" -struct OpenGLSurfaceMesh +struct OpenGLMesh { GLulong noOfIndices; GLuint indexBuffer; GLuint vertexBuffer; - const PolyVox::SurfaceMesh >* sourceMesh; + const PolyVox::Mesh >* sourceMesh; }; -OpenGLSurfaceMesh BuildOpenGLSurfaceMesh(const PolyVox::SurfaceMesh >& mesh); -void renderRegionVertexBufferObject(const OpenGLSurfaceMesh& openGLSurfaceMesh, unsigned int uLodLevel); +OpenGLMesh BuildOpenGLMesh(const PolyVox::Mesh >& mesh); +void renderRegionVertexBufferObject(const OpenGLMesh& openGLMesh, unsigned int uLodLevel); #endif //__OpenGLExample_OpenGLVertexBufferObjectSupport_H__ diff --git a/examples/OpenGL/OpenGLWidget.cpp b/examples/OpenGL/OpenGLWidget.cpp index 475ba846..38c107a9 100644 --- a/examples/OpenGL/OpenGLWidget.cpp +++ b/examples/OpenGL/OpenGLWidget.cpp @@ -50,8 +50,8 @@ OpenGLWidget::OpenGLWidget(QWidget *parent) void OpenGLWidget::setVolume(PolyVox::LargeVolume* volData) { //First we free anything from the previous volume (if there was one). - m_mapOpenGLSurfaceMeshes.clear(); - m_mapSurfaceMeshes.clear(); + m_mapOpenGLMeshes.clear(); + m_mapMeshes.clear(); m_volData = volData; //If we have any volume data then generate the new surface patches. @@ -87,7 +87,7 @@ void OpenGLWidget::setVolume(PolyVox::LargeVolume* volDat //Extract the surface for this region //extractSurface(m_volData, 0, PolyVox::Region(regLowerCorner, regUpperCorner), meshCurrent); - std::shared_ptr< SurfaceMesh > > mesh(new SurfaceMesh >); + std::shared_ptr< Mesh > > mesh(new Mesh >); MarchingCubesSurfaceExtractor< LargeVolume > surfaceExtractor(volData, PolyVox::Region(regLowerCorner, regUpperCorner), mesh.get()); surfaceExtractor.execute(); @@ -105,12 +105,12 @@ void OpenGLWidget::setVolume(PolyVox::LargeVolume* volDat Vector3DUint8 v3dRegPos(uRegionX,uRegionY,uRegionZ); if(m_bUseOpenGLVertexBufferObjects) { - OpenGLSurfaceMesh openGLSurfaceMesh = BuildOpenGLSurfaceMesh(*(mesh.get())); - m_mapOpenGLSurfaceMeshes.insert(make_pair(v3dRegPos, openGLSurfaceMesh)); + OpenGLMesh openGLMesh = BuildOpenGLMesh(*(mesh.get())); + m_mapOpenGLMeshes.insert(make_pair(v3dRegPos, openGLMesh)); } //else //{ - m_mapSurfaceMeshes.insert(make_pair(v3dRegPos, mesh)); + m_mapMeshes.insert(make_pair(v3dRegPos, mesh)); //} //delete meshCurrent; } @@ -191,13 +191,13 @@ void OpenGLWidget::paintGL() for(uint16_t uRegionX = 0; uRegionX < m_uVolumeWidthInRegions; ++uRegionX) { Vector3DUint8 v3dRegPos(uRegionX,uRegionY,uRegionZ); - if(m_mapSurfaceMeshes.find(v3dRegPos) != m_mapSurfaceMeshes.end()) + if(m_mapMeshes.find(v3dRegPos) != m_mapMeshes.end()) { - std::shared_ptr< SurfaceMesh > > meshCurrent = m_mapSurfaceMeshes[v3dRegPos]; + std::shared_ptr< Mesh > > meshCurrent = m_mapMeshes[v3dRegPos]; unsigned int uLodLevel = 0; //meshCurrent->m_vecLodRecords.size() - 1; if(m_bUseOpenGLVertexBufferObjects) { - renderRegionVertexBufferObject(m_mapOpenGLSurfaceMeshes[v3dRegPos], uLodLevel); + renderRegionVertexBufferObject(m_mapOpenGLMeshes[v3dRegPos], uLodLevel); } else { diff --git a/examples/OpenGL/OpenGLWidget.h b/examples/OpenGL/OpenGLWidget.h index 1b4b4612..3511ac75 100644 --- a/examples/OpenGL/OpenGLWidget.h +++ b/examples/OpenGL/OpenGLWidget.h @@ -30,7 +30,7 @@ freely, subject to the following restrictions: #include #include "PolyVoxCore/LargeVolume.h" -#include "PolyVoxCore/SurfaceMesh.h" +#include "PolyVoxCore/Mesh.h" #include "PolyVoxCore/Impl/Utility.h" #include "OpenGLImmediateModeSupport.h" @@ -87,8 +87,8 @@ class OpenGLWidget : public QGLWidget PolyVox::LargeVolume* m_volData; //Rather than storing one big mesh, the volume is broken into regions and a mesh is stored for each region - std::map m_mapOpenGLSurfaceMeshes; - std::map > >, Vector3DUint8Compare> m_mapSurfaceMeshes; + std::map m_mapOpenGLMeshes; + std::map > >, Vector3DUint8Compare> m_mapMeshes; unsigned int m_uRegionSideLength; unsigned int m_uVolumeWidthInRegions; diff --git a/examples/OpenGL/main.cpp b/examples/OpenGL/main.cpp index e6ae33d7..ab70e957 100644 --- a/examples/OpenGL/main.cpp +++ b/examples/OpenGL/main.cpp @@ -27,7 +27,7 @@ freely, subject to the following restrictions: #include "PolyVoxCore/LowPassFilter.h" #include "PolyVoxCore/RawVolume.h" #include "PolyVoxCore/RLEBlockCompressor.h" -#include "PolyVoxCore/SurfaceMesh.h" +#include "PolyVoxCore/Mesh.h" #include "PolyVoxCore/Impl/Utility.h" #include "OpenGLImmediateModeSupport.h" diff --git a/examples/Paging/OpenGLWidget.cpp b/examples/Paging/OpenGLWidget.cpp index 0227a66f..fa2aa7be 100644 --- a/examples/Paging/OpenGLWidget.cpp +++ b/examples/Paging/OpenGLWidget.cpp @@ -15,7 +15,7 @@ OpenGLWidget::OpenGLWidget(QWidget *parent) { } -void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh >& surfaceMesh) +void OpenGLWidget::setMeshToRender(const PolyVox::Mesh >& surfaceMesh) { if((surfaceMesh.getNoOfIndices() == 0) || (surfaceMesh.getNoOfVertices() == 0)) { diff --git a/examples/Paging/OpenGLWidget.h b/examples/Paging/OpenGLWidget.h index 61702be1..63afbb97 100644 --- a/examples/Paging/OpenGLWidget.h +++ b/examples/Paging/OpenGLWidget.h @@ -25,7 +25,7 @@ distribution. #define __BasicExample_OpenGLWidget_H__ #include "PolyVoxCore/MaterialDensityPair.h" -#include "PolyVoxCore/SurfaceMesh.h" +#include "PolyVoxCore/Mesh.h" #include "glew/glew.h" @@ -42,7 +42,7 @@ public: void mousePressEvent(QMouseEvent* event); //Convert a SrfaceMesh to OpenGL index/vertex buffers - void setSurfaceMeshToRender(const PolyVox::SurfaceMesh >& surfaceMesh); + void setMeshToRender(const PolyVox::Mesh >& surfaceMesh); protected: //Qt OpenGL functions diff --git a/examples/Paging/main.cpp b/examples/Paging/main.cpp index d1e0ae09..77c64d16 100644 --- a/examples/Paging/main.cpp +++ b/examples/Paging/main.cpp @@ -29,7 +29,7 @@ freely, subject to the following restrictions: #include "PolyVoxCore/MarchingCubesSurfaceExtractor.h" #include "PolyVoxCore/Pager.h" #include "PolyVoxCore/RLEBlockCompressor.h" -#include "PolyVoxCore/SurfaceMesh.h" +#include "PolyVoxCore/Mesh.h" #include "PolyVoxCore/LargeVolume.h" #include @@ -185,12 +185,12 @@ int main(int argc, char *argv[]) std::cout << "Memory usage: " << (volData.calculateSizeInBytes()/1024.0/1024.0) << "MB" << std::endl; std::cout << "Compression ratio: 1 to " << (1.0/(volData.calculateCompressionRatio())) << std::endl; - //Extract the surface - auto mesh = extractCubicMesh(&volData, reg); + //Extract the surface + auto mesh = extractCubicMesh(&volData, reg); std::cout << "#vertices: " << mesh.getNoOfVertices() << std::endl; //Pass the surface to the OpenGL window - openGLWidget.setSurfaceMeshToRender(mesh); + openGLWidget.setMeshToRender(mesh); //Run the message pump. return app.exec(); diff --git a/examples/SmoothLOD/OpenGLWidget.cpp b/examples/SmoothLOD/OpenGLWidget.cpp index e804240b..d487f73b 100644 --- a/examples/SmoothLOD/OpenGLWidget.cpp +++ b/examples/SmoothLOD/OpenGLWidget.cpp @@ -21,7 +21,7 @@ OpenGLWidget::OpenGLWidget(QWidget *parent) { } -void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh >& surfaceMesh) +void OpenGLWidget::setMeshToRender(const PolyVox::Mesh >& surfaceMesh) { //Convienient access to the vertices and indices const vector& vecIndices = surfaceMesh.getIndices(); @@ -43,7 +43,7 @@ void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh >& surfaceMesh) +void OpenGLWidget::setMeshToRenderLowLOD(const PolyVox::Mesh >& surfaceMesh) { //Convienient access to the vertices and indices const vector& vecIndices = surfaceMesh.getIndices(); diff --git a/examples/SmoothLOD/OpenGLWidget.h b/examples/SmoothLOD/OpenGLWidget.h index 895e9e74..af5b96ee 100644 --- a/examples/SmoothLOD/OpenGLWidget.h +++ b/examples/SmoothLOD/OpenGLWidget.h @@ -24,7 +24,7 @@ distribution. #ifndef __BasicExample_OpenGLWidget_H__ #define __BasicExample_OpenGLWidget_H__ -#include "PolyVoxCore/SurfaceMesh.h" +#include "PolyVoxCore/Mesh.h" #include "glew/glew.h" @@ -41,8 +41,8 @@ public: void mousePressEvent(QMouseEvent* event); //Convert a SrfaceMesh to OpenGL index/vertex buffers - void setSurfaceMeshToRender(const PolyVox::SurfaceMesh >& surfaceMesh); - void setSurfaceMeshToRenderLowLOD(const PolyVox::SurfaceMesh >& surfaceMesh); + void setMeshToRender(const PolyVox::Mesh >& surfaceMesh); + void setMeshToRenderLowLOD(const PolyVox::Mesh >& surfaceMesh); protected: //Qt OpenGL functions diff --git a/examples/SmoothLOD/main.cpp b/examples/SmoothLOD/main.cpp index 5bc79f96..a0dc6dcd 100644 --- a/examples/SmoothLOD/main.cpp +++ b/examples/SmoothLOD/main.cpp @@ -25,7 +25,7 @@ freely, subject to the following restrictions: #include "PolyVoxCore/Density.h" #include "PolyVoxCore/MarchingCubesSurfaceExtractor.h" -#include "PolyVoxCore/SurfaceMesh.h" +#include "PolyVoxCore/Mesh.h" #include "PolyVoxCore/RawVolume.h" #include "PolyVoxCore/SimpleVolume.h" #include "PolyVoxCore/VolumeResampler.h" @@ -89,17 +89,17 @@ int main(int argc, char *argv[]) VolumeResampler< SimpleVolume, RawVolume > volumeResampler(&volData, PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(31, 63, 63)), &volDataLowLOD, volDataLowLOD.getEnclosingRegion()); volumeResampler.execute(); - //Extract the surface + //Extract the surface auto meshLowLOD = extractMarchingCubesMesh(&volDataLowLOD, volDataLowLOD.getEnclosingRegion()); meshLowLOD.scaleVertices(/*2.0f*/63.0f / 31.0f); //Extract the surface - auto meshHighLOD = extractMarchingCubesMesh(&volData, PolyVox::Region(Vector3DInt32(30, 0, 0), Vector3DInt32(63, 63, 63))); + auto meshHighLOD = extractMarchingCubesMesh(&volData, PolyVox::Region(Vector3DInt32(30, 0, 0), Vector3DInt32(63, 63, 63))); meshHighLOD.translateVertices(Vector3DFloat(30, 0, 0)); //Pass the surface to the OpenGL window - openGLWidget.setSurfaceMeshToRender(meshHighLOD); - openGLWidget.setSurfaceMeshToRenderLowLOD(meshLowLOD); + openGLWidget.setMeshToRender(meshHighLOD); + openGLWidget.setMeshToRenderLowLOD(meshLowLOD); //Run the message pump. return app.exec(); diff --git a/library/PolyVoxCore/CMakeLists.txt b/library/PolyVoxCore/CMakeLists.txt index e4289feb..42844fce 100644 --- a/library/PolyVoxCore/CMakeLists.txt +++ b/library/PolyVoxCore/CMakeLists.txt @@ -84,8 +84,8 @@ SET(CORE_INC_FILES include/PolyVoxCore/SimpleVolume.inl include/PolyVoxCore/SimpleVolumeBlock.inl include/PolyVoxCore/SimpleVolumeSampler.inl - include/PolyVoxCore/SurfaceMesh.h - include/PolyVoxCore/SurfaceMesh.inl + include/PolyVoxCore/Mesh.h + include/PolyVoxCore/Mesh.inl include/PolyVoxCore/UncompressedBlock.h include/PolyVoxCore/UncompressedBlock.inl include/PolyVoxCore/Vector.h diff --git a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h index 01020ad3..03e973a3 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h +++ b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h @@ -31,7 +31,7 @@ freely, subject to the following restrictions: #include "PolyVoxCore/Array.h" #include "PolyVoxCore/BaseVolume.h" //For wrap modes... should move these? #include "PolyVoxCore/DefaultIsQuadNeeded.h" -#include "PolyVoxCore/SurfaceMesh.h" +#include "PolyVoxCore/Mesh.h" namespace PolyVox { @@ -113,9 +113,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) - 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, Mesh >* 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, Mesh >* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType(), bool bMergeQuads = true, IsQuadNeeded isQuadNeeded = IsQuadNeeded()); #endif @@ -135,7 +135,7 @@ namespace PolyVox Region m_regSizeInVoxels; //The surface patch we are currently filling. - SurfaceMesh >* m_meshCurrent; + Mesh >* m_meshCurrent; //Used to avoid creating duplicate vertices. Array<3, IndexAndMaterial> m_previousSliceVertices; @@ -159,9 +159,9 @@ namespace PolyVox }; template - SurfaceMesh > extractCubicMesh(VolumeType* volData, Region region, WrapMode eWrapMode, typename VolumeType::VoxelType tBorderValue, bool bMergeQuads, IsQuadNeeded isQuadNeeded) + Mesh > extractCubicMesh(VolumeType* volData, Region region, WrapMode eWrapMode, typename VolumeType::VoxelType tBorderValue, bool bMergeQuads, IsQuadNeeded isQuadNeeded) { - SurfaceMesh > result; + Mesh > result; CubicSurfaceExtractor extractor(volData, region, &result, eWrapMode, tBorderValue, bMergeQuads, isQuadNeeded); extractor.execute(); return result; @@ -171,9 +171,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) - SurfaceMesh > extractCubicMesh(VolumeType* volData, Region region, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = VolumeType::VoxelType(), bool bMergeQuads = true) + Mesh > extractCubicMesh(VolumeType* volData, Region region, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = VolumeType::VoxelType(), bool bMergeQuads = true) #else - SurfaceMesh > extractCubicMesh(VolumeType* volData, Region region, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType(), bool bMergeQuads = true) + Mesh > extractCubicMesh(VolumeType* volData, Region region, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType(), bool bMergeQuads = true) #endif { DefaultIsQuadNeeded isQuadNeeded; diff --git a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl index 822b9256..5bc067a9 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, Mesh >* result, WrapMode eWrapMode, typename VolumeType::VoxelType tBorderValue, bool bMergeQuads, IsQuadNeeded isQuadNeeded) :m_volData(volData) ,m_regSizeInVoxels(region) ,m_meshCurrent(result) diff --git a/library/PolyVoxCore/include/PolyVoxCore/GradientEstimators.h b/library/PolyVoxCore/include/PolyVoxCore/GradientEstimators.h index cb8fcbe4..871dbcb2 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/GradientEstimators.h +++ b/library/PolyVoxCore/include/PolyVoxCore/GradientEstimators.h @@ -55,7 +55,7 @@ namespace PolyVox template Vector3DFloat computeSmoothSobelGradient(typename VolumeType::Sampler& volIter); - //POLYVOX_API void computeNormalsForVertices(VolumeType* volumeData, SurfaceMesh& mesh, NormalGenerationMethod normalGenerationMethod); + //POLYVOX_API void computeNormalsForVertices(VolumeType* volumeData, Mesh& mesh, NormalGenerationMethod normalGenerationMethod); //POLYVOX_API Vector3DFloat computeNormal(VolumeType* volumeData, const Vector3DFloat& v3dPos, NormalGenerationMethod normalGenerationMethod); } diff --git a/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.h b/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.h index cf403ab0..6510ac5c 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.h +++ b/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.h @@ -29,7 +29,7 @@ freely, subject to the following restrictions: #include "PolyVoxCore/Array.h" #include "PolyVoxCore/BaseVolume.h" //For wrap modes... should move these? -#include "PolyVoxCore/SurfaceMesh.h" +#include "PolyVoxCore/Mesh.h" #include "PolyVoxCore/DefaultMarchingCubesController.h" namespace PolyVox @@ -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, Mesh >* 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, Mesh >* 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; + Mesh >* m_meshCurrent; //Information about the region we are currently processing Region m_regSizeInVoxels; @@ -212,9 +212,9 @@ namespace PolyVox }; template< typename VolumeType, typename Controller> - SurfaceMesh > extractMarchingCubesMesh(VolumeType* volData, Region region, WrapMode eWrapMode, typename VolumeType::VoxelType tBorderValue, Controller controller) + Mesh > extractMarchingCubesMesh(VolumeType* volData, Region region, WrapMode eWrapMode, typename VolumeType::VoxelType tBorderValue, Controller controller) { - SurfaceMesh > result; + Mesh > result; MarchingCubesSurfaceExtractor extractor(volData, region, &result, eWrapMode, tBorderValue, controller); extractor.execute(); return result; @@ -224,9 +224,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) - SurfaceMesh > extractMarchingCubesMesh(VolumeType* volData, Region region, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = VolumeType::VoxelType()) + Mesh > extractMarchingCubesMesh(VolumeType* volData, Region region, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = VolumeType::VoxelType()) #else - SurfaceMesh > extractMarchingCubesMesh(VolumeType* volData, Region region, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType()) + Mesh > extractMarchingCubesMesh(VolumeType* volData, Region region, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType()) #endif { DefaultMarchingCubesController controller; diff --git a/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.inl b/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.inl index 5c2868d9..99998bf4 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.inl @@ -25,8 +25,8 @@ 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) + template + MarchingCubesSurfaceExtractor::MarchingCubesSurfaceExtractor(VolumeType* volData, Region region, Mesh >* result, WrapMode eWrapMode, typename VolumeType::VoxelType tBorderValue, Controller controller) :m_volData(volData) ,m_sampVolume(volData) ,m_meshCurrent(result) @@ -456,10 +456,10 @@ namespace PolyVox v3dNormal.normalise(); } - // Allow the controller to decide how the material should be derived from the voxels. + // Allow the controller to decide how the material should be derived from the voxels. const typename VolumeType::VoxelType uMaterial = m_controller.blendMaterials(v000, v100, fInterp); - const MarchingCubesVertex surfaceVertex(v3dPosition, v3dNormal, uMaterial); + const MarchingCubesVertex surfaceVertex(v3dPosition, v3dNormal, uMaterial); const uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex); m_pCurrentVertexIndicesX[iXVolSpace - m_regSizeInVoxels.getLowerX()][iYVolSpace - m_regSizeInVoxels.getLowerY()] = uLastVertexIndex; @@ -485,11 +485,11 @@ namespace PolyVox v3dNormal.normalise(); } - // Allow the controller to decide how the material should be derived from the voxels. + // Allow the controller to decide how the material should be derived from the voxels. const typename VolumeType::VoxelType uMaterial = m_controller.blendMaterials(v000, v010, fInterp); MarchingCubesVertex surfaceVertex(v3dPosition, v3dNormal, uMaterial); - uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex); + uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex); m_pCurrentVertexIndicesY[iXVolSpace - m_regSizeInVoxels.getLowerX()][iYVolSpace - m_regSizeInVoxels.getLowerY()] = uLastVertexIndex; m_sampVolume.moveNegativeY(); @@ -513,10 +513,10 @@ namespace PolyVox v3dNormal.normalise(); } - // Allow the controller to decide how the material should be derived from the voxels. + // Allow the controller to decide how the material should be derived from the voxels. const typename VolumeType::VoxelType uMaterial = m_controller.blendMaterials(v000, v001, fInterp); - const MarchingCubesVertex surfaceVertex(v3dPosition, v3dNormal, uMaterial); + const MarchingCubesVertex surfaceVertex(v3dPosition, v3dNormal, 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/SurfaceMesh.h b/library/PolyVoxCore/include/PolyVoxCore/Mesh.h similarity index 86% rename from library/PolyVoxCore/include/PolyVoxCore/SurfaceMesh.h rename to library/PolyVoxCore/include/PolyVoxCore/Mesh.h index 1de4a905..90ebbfac 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SurfaceMesh.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Mesh.h @@ -1,104 +1,104 @@ -/******************************************************************************* -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_SurfaceMesh_H__ -#define __PolyVox_SurfaceMesh_H__ - -#include "Impl/TypeDef.h" - -#include "PolyVoxCore/Region.h" -#include "PolyVoxCore/VertexTypes.h" //Should probably do away with this on in the future... - -#include -#include -#include -#include -#include -#include - -namespace PolyVox -{ - class LodRecord - { - public: - int beginIndex; - int endIndex; //Let's put it just past the end STL style - }; - - template - class SurfaceMesh - { - public: - SurfaceMesh(); - ~SurfaceMesh(); - - const std::vector& getIndices(void) const; - uint32_t getNoOfIndices(void) const; - uint32_t getNoOfNonUniformTrianges(void) const; - uint32_t getNoOfUniformTrianges(void) const; - uint32_t getNoOfVertices(void) const; - std::vector& getRawVertexData(void); //FIXME - this should be removed - const std::vector& getVertices(void) const; - - void addTriangle(uint32_t index0, uint32_t index1, uint32_t index2); - void addTriangleCubic(uint32_t index0, uint32_t index1, uint32_t index2); - uint32_t addVertex(const VertexType& vertex); - void clear(void); - bool isEmpty(void) const; - - void scaleVertices(float amount); - void translateVertices(const Vector3DFloat& amount); - - //THESE FUNCTIONS TO BE REMOVED IN THE FUTURE. OR AT LEAST MOVED OUT OF THIS CLASS INTO FREE FUNCTIONS. - //THEY ARE CAUSING PROBLEMS WITH THE SWIG BINDINGS. THE FUNCTIONS REGARDING NORMALS MAKE NO SENSE WHEN - //A VERTEX MIGHT NOT HAVE NORMALS. THE EXTRACT SUBSET FUNCTION SHOULD MAYBE BE APPLICATION CODE, AT ANY - //RATE THE STD::SET CAUSES PROBLEMS WITH SWIG. IF YOU UNCOMMENT ANY OF THESE FUNCTIONS, PLEASE POST ON - //THE FORUM SO WE CAN KNOW THE FUNCTIONALITY IS STILL NEEDED IN SOME FORM. - //void sumNearbyNormals(bool bNormaliseResult = true); - //std::shared_ptr< SurfaceMesh > extractSubset(std::set setMaterials); - //void generateAveragedFaceNormals(bool bNormalise, bool bIncludeEdgeVertices = false); - - int noOfDegenerateTris(void); - void removeDegenerateTris(void); - void removeUnusedVertices(void); - - Region m_Region; - - int32_t m_iTimeStamp; - - int32_t m_iNoOfLod0Tris; - - public: - std::vector m_vecTriangleIndices; - std::vector m_vecVertices; - - std::vector m_vecLodRecords; - }; - - template - std::shared_ptr< SurfaceMesh > extractSubset(SurfaceMesh& inputMesh, std::set setMaterials); -} - -#include "PolyVoxCore/SurfaceMesh.inl" - -#endif /* __SurfaceMesh_H__ */ +/******************************************************************************* +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_Mesh_H__ +#define __PolyVox_Mesh_H__ + +#include "Impl/TypeDef.h" + +#include "PolyVoxCore/Region.h" +#include "PolyVoxCore/VertexTypes.h" //Should probably do away with this on in the future... + +#include +#include +#include +#include +#include +#include + +namespace PolyVox +{ + class LodRecord + { + public: + int beginIndex; + int endIndex; //Let's put it just past the end STL style + }; + + template + class Mesh + { + public: + Mesh(); + ~Mesh(); + + const std::vector& getIndices(void) const; + uint32_t getNoOfIndices(void) const; + uint32_t getNoOfNonUniformTrianges(void) const; + uint32_t getNoOfUniformTrianges(void) const; + uint32_t getNoOfVertices(void) const; + std::vector& getRawVertexData(void); //FIXME - this should be removed + const std::vector& getVertices(void) const; + + void addTriangle(uint32_t index0, uint32_t index1, uint32_t index2); + void addTriangleCubic(uint32_t index0, uint32_t index1, uint32_t index2); + uint32_t addVertex(const VertexType& vertex); + void clear(void); + bool isEmpty(void) const; + + void scaleVertices(float amount); + void translateVertices(const Vector3DFloat& amount); + + //THESE FUNCTIONS TO BE REMOVED IN THE FUTURE. OR AT LEAST MOVED OUT OF THIS CLASS INTO FREE FUNCTIONS. + //THEY ARE CAUSING PROBLEMS WITH THE SWIG BINDINGS. THE FUNCTIONS REGARDING NORMALS MAKE NO SENSE WHEN + //A VERTEX MIGHT NOT HAVE NORMALS. THE EXTRACT SUBSET FUNCTION SHOULD MAYBE BE APPLICATION CODE, AT ANY + //RATE THE STD::SET CAUSES PROBLEMS WITH SWIG. IF YOU UNCOMMENT ANY OF THESE FUNCTIONS, PLEASE POST ON + //THE FORUM SO WE CAN KNOW THE FUNCTIONALITY IS STILL NEEDED IN SOME FORM. + //void sumNearbyNormals(bool bNormaliseResult = true); + //std::shared_ptr< Mesh > extractSubset(std::set setMaterials); + //void generateAveragedFaceNormals(bool bNormalise, bool bIncludeEdgeVertices = false); + + int noOfDegenerateTris(void); + void removeDegenerateTris(void); + void removeUnusedVertices(void); + + Region m_Region; + + int32_t m_iTimeStamp; + + int32_t m_iNoOfLod0Tris; + + public: + std::vector m_vecTriangleIndices; + std::vector m_vecVertices; + + std::vector m_vecLodRecords; + }; + + template + std::shared_ptr< Mesh > extractSubset(Mesh& inputMesh, std::set setMaterials); +} + +#include "PolyVoxCore/Mesh.inl" + +#endif /* __Mesh_H__ */ diff --git a/library/PolyVoxCore/include/PolyVoxCore/SurfaceMesh.inl b/library/PolyVoxCore/include/PolyVoxCore/Mesh.inl similarity index 85% rename from library/PolyVoxCore/include/PolyVoxCore/SurfaceMesh.inl rename to library/PolyVoxCore/include/PolyVoxCore/Mesh.inl index 9b1bf020..44fc5320 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SurfaceMesh.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/Mesh.inl @@ -1,488 +1,488 @@ -/******************************************************************************* -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. -*******************************************************************************/ - -namespace PolyVox -{ - template - SurfaceMesh::SurfaceMesh() - { - m_iTimeStamp = -1; - } - - template - SurfaceMesh::~SurfaceMesh() - { - } - - template - const std::vector& SurfaceMesh::getIndices(void) const - { - return m_vecTriangleIndices; - } - - template - uint32_t SurfaceMesh::getNoOfIndices(void) const - { - return m_vecTriangleIndices.size(); - } - - template - uint32_t SurfaceMesh::getNoOfNonUniformTrianges(void) const - { - uint32_t result = 0; - for(uint32_t i = 0; i < m_vecTriangleIndices.size() - 2; i += 3) - { - if((m_vecVertices[m_vecTriangleIndices[i]].getMaterial() == m_vecVertices[m_vecTriangleIndices[i+1]].getMaterial()) - && (m_vecVertices[m_vecTriangleIndices[i]].getMaterial() == m_vecVertices[m_vecTriangleIndices[i+2]].getMaterial())) - { - } - else - { - result++; - } - } - return result; - } - - template - uint32_t SurfaceMesh::getNoOfUniformTrianges(void) const - { - uint32_t result = 0; - for(uint32_t i = 0; i < m_vecTriangleIndices.size() - 2; i += 3) - { - if((m_vecVertices[m_vecTriangleIndices[i]].getMaterial() == m_vecVertices[m_vecTriangleIndices[i+1]].getMaterial()) - && (m_vecVertices[m_vecTriangleIndices[i]].getMaterial() == m_vecVertices[m_vecTriangleIndices[i+2]].getMaterial())) - { - result++; - } - } - return result; - } - - template - uint32_t SurfaceMesh::getNoOfVertices(void) const - { - return m_vecVertices.size(); - } - - template - std::vector& SurfaceMesh::getRawVertexData(void) - { - return m_vecVertices; - } - - template - const std::vector& SurfaceMesh::getVertices(void) const - { - return m_vecVertices; - } - - template - void SurfaceMesh::addTriangle(uint32_t index0, uint32_t index1, uint32_t index2) - { - //Make sure the specified indices correspond to valid vertices. - POLYVOX_ASSERT(index0 < m_vecVertices.size(), "Index points at an invalid vertex."); - POLYVOX_ASSERT(index1 < m_vecVertices.size(), "Index points at an invalid vertex."); - POLYVOX_ASSERT(index2 < m_vecVertices.size(), "Index points at an invalid vertex."); - - m_vecTriangleIndices.push_back(index0); - m_vecTriangleIndices.push_back(index1); - m_vecTriangleIndices.push_back(index2); - } - - template - void SurfaceMesh::addTriangleCubic(uint32_t index0, uint32_t index1, uint32_t index2) - { - //Make sure the specified indices correspond to valid vertices. - POLYVOX_ASSERT(index0 < m_vecVertices.size(), "Index points at an invalid vertex."); - POLYVOX_ASSERT(index1 < m_vecVertices.size(), "Index points at an invalid vertex."); - POLYVOX_ASSERT(index2 < m_vecVertices.size(), "Index points at an invalid vertex."); - - m_vecTriangleIndices.push_back(index0); - m_vecTriangleIndices.push_back(index1); - m_vecTriangleIndices.push_back(index2); - } - - template - uint32_t SurfaceMesh::addVertex(const VertexType& vertex) - { - m_vecVertices.push_back(vertex); - return m_vecVertices.size() - 1; - } - - template - void SurfaceMesh::clear(void) - { - m_vecVertices.clear(); - m_vecTriangleIndices.clear(); - m_vecLodRecords.clear(); - } - - template - bool SurfaceMesh::isEmpty(void) const - { - return (getNoOfVertices() == 0) || (getNoOfIndices() == 0); - } - - //////////////////////////////////////////////////////////////////////////////// - /// This function can help improve the visual appearance of a surface patch by - /// smoothing normals with other nearby normals. It iterates over each triangle - /// in the surface patch and determines the sum of its corners normals. For any - /// given vertex, these sums are in turn summed for any triangles which use the - /// vertex. Usually, the resulting normals should be renormalised afterwards. - /// Note: This function can cause lighting discontinuities accross region boundaries. - //////////////////////////////////////////////////////////////////////////////// - /*template - void SurfaceMesh::sumNearbyNormals(bool bNormaliseResult) - { - if(m_vecVertices.size() == 0) //FIXME - I don't think we should need this test, but I have seen crashes otherwise... - { - return; - } - - std::vector summedNormals(m_vecVertices.size()); - - //Initialise all normals to zero. Should be ok as the vector should store all elements contiguously. - memset(&summedNormals[0], 0, summedNormals.size() * sizeof(Vector3DFloat)); - - for(vector::iterator iterIndex = m_vecTriangleIndices.begin(); iterIndex != m_vecTriangleIndices.end();) - { - PositionMaterialNormal& v0 = m_vecVertices[*iterIndex]; - Vector3DFloat& v0New = summedNormals[*iterIndex]; - iterIndex++; - PositionMaterialNormal& v1 = m_vecVertices[*iterIndex]; - Vector3DFloat& v1New = summedNormals[*iterIndex]; - iterIndex++; - PositionMaterialNormal& v2 = m_vecVertices[*iterIndex]; - Vector3DFloat& v2New = summedNormals[*iterIndex]; - iterIndex++; - - Vector3DFloat sumOfNormals = v0.getNormal() + v1.getNormal() + v2.getNormal(); - - v0New += sumOfNormals; - v1New += sumOfNormals; - v2New += sumOfNormals; - } - - for(uint32_t uIndex = 0; uIndex < summedNormals.size(); uIndex++) - { - if(bNormaliseResult) - { - summedNormals[uIndex].normalise(); - } - m_vecVertices[uIndex].setNormal(summedNormals[uIndex]); - } - }*/ - - /*template - void SurfaceMesh::generateAveragedFaceNormals(bool bNormalise, bool bIncludeEdgeVertices) - { - Vector3DFloat offset = static_cast(m_Region.getLowerCorner()); - - //Initially zero the normals - for(vector::iterator iterVertex = m_vecVertices.begin(); iterVertex != m_vecVertices.end(); iterVertex++) - { - if(m_Region.containsPoint(iterVertex->getPosition() + offset, 0.001)) - { - iterVertex->setNormal(Vector3DFloat(0.0f,0.0f,0.0f)); - } - } - - for(vector::iterator iterIndex = m_vecTriangleIndices.begin(); iterIndex != m_vecTriangleIndices.end();) - { - PositionMaterialNormal& v0 = m_vecVertices[*iterIndex]; - iterIndex++; - PositionMaterialNormal& v1 = m_vecVertices[*iterIndex]; - iterIndex++; - PositionMaterialNormal& v2 = m_vecVertices[*iterIndex]; - iterIndex++; - - Vector3DFloat triangleNormal = (v1.getPosition()-v0.getPosition()).cross(v2.getPosition()-v0.getPosition()); - - if(m_Region.containsPoint(v0.getPosition() + offset, 0.001)) - { - v0.setNormal(v0.getNormal() + triangleNormal); - } - if(m_Region.containsPoint(v1.getPosition() + offset, 0.001)) - { - v1.setNormal(v1.getNormal() + triangleNormal); - } - if(m_Region.containsPoint(v2.getPosition() + offset, 0.001)) - { - v2.setNormal(v2.getNormal() + triangleNormal); - } - } - - if(bNormalise) - { - for(vector::iterator iterVertex = m_vecVertices.begin(); iterVertex != m_vecVertices.end(); iterVertex++) - { - Vector3DFloat normal = iterVertex->getNormal(); - normal.normalise(); - iterVertex->setNormal(normal); - } - } - }*/ - - /*template - std::shared_ptr< SurfaceMesh > SurfaceMesh::extractSubset(std::set setMaterials) - { - std::shared_ptr< SurfaceMesh > result(new SurfaceMesh); - - if(m_vecVertices.size() == 0) //FIXME - I don't think we should need this test, but I have seen crashes otherwise... - { - return result; - } - - assert(m_vecLodRecords.size() == 1); - if(m_vecLodRecords.size() != 1) - { - //If we have done progressive LOD then it's too late to split into subsets. - return result; - } - - std::vector indexMap(m_vecVertices.size()); - std::fill(indexMap.begin(), indexMap.end(), -1); - - for(uint32_t triCt = 0; triCt < m_vecTriangleIndices.size(); triCt += 3) - { - - PositionMaterialNormal& v0 = m_vecVertices[m_vecTriangleIndices[triCt]]; - PositionMaterialNormal& v1 = m_vecVertices[m_vecTriangleIndices[triCt + 1]]; - PositionMaterialNormal& v2 = m_vecVertices[m_vecTriangleIndices[triCt + 2]]; - - if( - (setMaterials.find(v0.getMaterial()) != setMaterials.end()) || - (setMaterials.find(v1.getMaterial()) != setMaterials.end()) || - (setMaterials.find(v2.getMaterial()) != setMaterials.end())) - { - uint32_t i0; - if(indexMap[m_vecTriangleIndices[triCt]] == -1) - { - indexMap[m_vecTriangleIndices[triCt]] = result->addVertex(v0); - } - i0 = indexMap[m_vecTriangleIndices[triCt]]; - - uint32_t i1; - if(indexMap[m_vecTriangleIndices[triCt+1]] == -1) - { - indexMap[m_vecTriangleIndices[triCt+1]] = result->addVertex(v1); - } - i1 = indexMap[m_vecTriangleIndices[triCt+1]]; - - uint32_t i2; - if(indexMap[m_vecTriangleIndices[triCt+2]] == -1) - { - indexMap[m_vecTriangleIndices[triCt+2]] = result->addVertex(v2); - } - i2 = indexMap[m_vecTriangleIndices[triCt+2]]; - - result->addTriangle(i0,i1,i2); - } - } - - result->m_vecLodRecords.clear(); - LodRecord lodRecord; - lodRecord.beginIndex = 0; - lodRecord.endIndex = result->getNoOfIndices(); - result->m_vecLodRecords.push_back(lodRecord); - - return result; - }*/ - - template - int SurfaceMesh::noOfDegenerateTris(void) - { - int count = 0; - for(uint32_t triCt = 0; triCt < m_vecTriangleIndices.size();) - { - int v0 = m_vecTriangleIndices[triCt]; - triCt++; - int v1 = m_vecTriangleIndices[triCt]; - triCt++; - int v2 = m_vecTriangleIndices[triCt]; - triCt++; - - if((v0 == v1) || (v1 == v2) || (v2 == v0)) - { - count++; - } - } - return count; - } - - template - void SurfaceMesh::removeDegenerateTris(void) - { - int noOfNonDegenerate = 0; - int targetCt = 0; - for(uint32_t triCt = 0; triCt < m_vecTriangleIndices.size();) - { - int v0 = m_vecTriangleIndices[triCt]; - triCt++; - int v1 = m_vecTriangleIndices[triCt]; - triCt++; - int v2 = m_vecTriangleIndices[triCt]; - triCt++; - - if((v0 != v1) && (v1 != v2) & (v2 != v0)) - { - m_vecTriangleIndices[targetCt] = v0; - targetCt++; - m_vecTriangleIndices[targetCt] = v1; - targetCt++; - m_vecTriangleIndices[targetCt] = v2; - targetCt++; - - noOfNonDegenerate++; - } - } - - m_vecTriangleIndices.resize(noOfNonDegenerate * 3); - } - - template - void SurfaceMesh::removeUnusedVertices(void) - { - std::vector isVertexUsed(m_vecVertices.size()); - std::fill(isVertexUsed.begin(), isVertexUsed.end(), false); - - for(uint32_t triCt = 0; triCt < m_vecTriangleIndices.size(); triCt++) - { - int v = m_vecTriangleIndices[triCt]; - isVertexUsed[v] = true; - } - - int noOfUsedVertices = 0; - std::vector newPos(m_vecVertices.size()); - for(uint32_t vertCt = 0; vertCt < m_vecVertices.size(); vertCt++) - { - if(isVertexUsed[vertCt]) - { - m_vecVertices[noOfUsedVertices] = m_vecVertices[vertCt]; - newPos[vertCt] = noOfUsedVertices; - noOfUsedVertices++; - } - } - - m_vecVertices.resize(noOfUsedVertices); - - for(uint32_t triCt = 0; triCt < m_vecTriangleIndices.size(); triCt++) - { - m_vecTriangleIndices[triCt] = newPos[m_vecTriangleIndices[triCt]]; - } - } - - //Currently a free function - think where this needs to go. - template - std::shared_ptr< SurfaceMesh > extractSubset(SurfaceMesh& inputMesh, std::set setMaterials) - { - std::shared_ptr< SurfaceMesh > result(new SurfaceMesh); - - result->m_Region = inputMesh.m_Region; - - if(inputMesh.m_vecVertices.size() == 0) //FIXME - I don't think we should need this test, but I have seen crashes otherwise... - { - return result; - } - - POLYVOX_ASSERT(inputMesh.m_vecLodRecords.size() == 1, "Number of LOD records must equal one."); - if(inputMesh.m_vecLodRecords.size() != 1) - { - //If we have done progressive LOD then it's too late to split into subsets. - return result; - } - - std::vector indexMap(inputMesh.m_vecVertices.size()); - std::fill(indexMap.begin(), indexMap.end(), -1); - - for(uint32_t triCt = 0; triCt < inputMesh.m_vecTriangleIndices.size(); triCt += 3) - { - - VertexType& v0 = inputMesh.m_vecVertices[inputMesh.m_vecTriangleIndices[triCt]]; - VertexType& v1 = inputMesh.m_vecVertices[inputMesh.m_vecTriangleIndices[triCt + 1]]; - VertexType& v2 = inputMesh.m_vecVertices[inputMesh.m_vecTriangleIndices[triCt + 2]]; - - if( - (setMaterials.find(v0.getMaterial()) != setMaterials.end()) || - (setMaterials.find(v1.getMaterial()) != setMaterials.end()) || - (setMaterials.find(v2.getMaterial()) != setMaterials.end())) - { - uint32_t i0; - if(indexMap[inputMesh.m_vecTriangleIndices[triCt]] == -1) - { - indexMap[inputMesh.m_vecTriangleIndices[triCt]] = result->addVertex(v0); - } - i0 = indexMap[inputMesh.m_vecTriangleIndices[triCt]]; - - uint32_t i1; - if(indexMap[inputMesh.m_vecTriangleIndices[triCt+1]] == -1) - { - indexMap[inputMesh.m_vecTriangleIndices[triCt+1]] = result->addVertex(v1); - } - i1 = indexMap[inputMesh.m_vecTriangleIndices[triCt+1]]; - - uint32_t i2; - if(indexMap[inputMesh.m_vecTriangleIndices[triCt+2]] == -1) - { - indexMap[inputMesh.m_vecTriangleIndices[triCt+2]] = result->addVertex(v2); - } - i2 = indexMap[inputMesh.m_vecTriangleIndices[triCt+2]]; - - result->addTriangle(i0,i1,i2); - } - } - - result->m_vecLodRecords.clear(); - LodRecord lodRecord; - lodRecord.beginIndex = 0; - lodRecord.endIndex = result->getNoOfIndices(); - result->m_vecLodRecords.push_back(lodRecord); - - return result; - } - - template - void SurfaceMesh::scaleVertices(float amount) - { - for(uint32_t ct = 0; ct < m_vecVertices.size(); ct++) - { - //TODO: Should rethink accessors here to provide faster access - Vector3DFloat position = m_vecVertices[ct].getPosition(); - position *= amount; - m_vecVertices[ct].setPosition(position); - } - } - - template - void SurfaceMesh::translateVertices(const Vector3DFloat& amount) - { - for(uint32_t ct = 0; ct < m_vecVertices.size(); ct++) - { - //TODO: Should rethink accessors here to provide faster access - Vector3DFloat position = m_vecVertices[ct].getPosition(); - position += amount; - m_vecVertices[ct].setPosition(position); - } - } -} +/******************************************************************************* +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. +*******************************************************************************/ + +namespace PolyVox +{ + template + Mesh::Mesh() + { + m_iTimeStamp = -1; + } + + template + Mesh::~Mesh() + { + } + + template + const std::vector& Mesh::getIndices(void) const + { + return m_vecTriangleIndices; + } + + template + uint32_t Mesh::getNoOfIndices(void) const + { + return m_vecTriangleIndices.size(); + } + + template + uint32_t Mesh::getNoOfNonUniformTrianges(void) const + { + uint32_t result = 0; + for(uint32_t i = 0; i < m_vecTriangleIndices.size() - 2; i += 3) + { + if((m_vecVertices[m_vecTriangleIndices[i]].getMaterial() == m_vecVertices[m_vecTriangleIndices[i+1]].getMaterial()) + && (m_vecVertices[m_vecTriangleIndices[i]].getMaterial() == m_vecVertices[m_vecTriangleIndices[i+2]].getMaterial())) + { + } + else + { + result++; + } + } + return result; + } + + template + uint32_t Mesh::getNoOfUniformTrianges(void) const + { + uint32_t result = 0; + for(uint32_t i = 0; i < m_vecTriangleIndices.size() - 2; i += 3) + { + if((m_vecVertices[m_vecTriangleIndices[i]].getMaterial() == m_vecVertices[m_vecTriangleIndices[i+1]].getMaterial()) + && (m_vecVertices[m_vecTriangleIndices[i]].getMaterial() == m_vecVertices[m_vecTriangleIndices[i+2]].getMaterial())) + { + result++; + } + } + return result; + } + + template + uint32_t Mesh::getNoOfVertices(void) const + { + return m_vecVertices.size(); + } + + template + std::vector& Mesh::getRawVertexData(void) + { + return m_vecVertices; + } + + template + const std::vector& Mesh::getVertices(void) const + { + return m_vecVertices; + } + + template + void Mesh::addTriangle(uint32_t index0, uint32_t index1, uint32_t index2) + { + //Make sure the specified indices correspond to valid vertices. + POLYVOX_ASSERT(index0 < m_vecVertices.size(), "Index points at an invalid vertex."); + POLYVOX_ASSERT(index1 < m_vecVertices.size(), "Index points at an invalid vertex."); + POLYVOX_ASSERT(index2 < m_vecVertices.size(), "Index points at an invalid vertex."); + + m_vecTriangleIndices.push_back(index0); + m_vecTriangleIndices.push_back(index1); + m_vecTriangleIndices.push_back(index2); + } + + template + void Mesh::addTriangleCubic(uint32_t index0, uint32_t index1, uint32_t index2) + { + //Make sure the specified indices correspond to valid vertices. + POLYVOX_ASSERT(index0 < m_vecVertices.size(), "Index points at an invalid vertex."); + POLYVOX_ASSERT(index1 < m_vecVertices.size(), "Index points at an invalid vertex."); + POLYVOX_ASSERT(index2 < m_vecVertices.size(), "Index points at an invalid vertex."); + + m_vecTriangleIndices.push_back(index0); + m_vecTriangleIndices.push_back(index1); + m_vecTriangleIndices.push_back(index2); + } + + template + uint32_t Mesh::addVertex(const VertexType& vertex) + { + m_vecVertices.push_back(vertex); + return m_vecVertices.size() - 1; + } + + template + void Mesh::clear(void) + { + m_vecVertices.clear(); + m_vecTriangleIndices.clear(); + m_vecLodRecords.clear(); + } + + template + bool Mesh::isEmpty(void) const + { + return (getNoOfVertices() == 0) || (getNoOfIndices() == 0); + } + + //////////////////////////////////////////////////////////////////////////////// + /// This function can help improve the visual appearance of a surface patch by + /// smoothing normals with other nearby normals. It iterates over each triangle + /// in the surface patch and determines the sum of its corners normals. For any + /// given vertex, these sums are in turn summed for any triangles which use the + /// vertex. Usually, the resulting normals should be renormalised afterwards. + /// Note: This function can cause lighting discontinuities accross region boundaries. + //////////////////////////////////////////////////////////////////////////////// + /*template + void Mesh::sumNearbyNormals(bool bNormaliseResult) + { + if(m_vecVertices.size() == 0) //FIXME - I don't think we should need this test, but I have seen crashes otherwise... + { + return; + } + + std::vector summedNormals(m_vecVertices.size()); + + //Initialise all normals to zero. Should be ok as the vector should store all elements contiguously. + memset(&summedNormals[0], 0, summedNormals.size() * sizeof(Vector3DFloat)); + + for(vector::iterator iterIndex = m_vecTriangleIndices.begin(); iterIndex != m_vecTriangleIndices.end();) + { + PositionMaterialNormal& v0 = m_vecVertices[*iterIndex]; + Vector3DFloat& v0New = summedNormals[*iterIndex]; + iterIndex++; + PositionMaterialNormal& v1 = m_vecVertices[*iterIndex]; + Vector3DFloat& v1New = summedNormals[*iterIndex]; + iterIndex++; + PositionMaterialNormal& v2 = m_vecVertices[*iterIndex]; + Vector3DFloat& v2New = summedNormals[*iterIndex]; + iterIndex++; + + Vector3DFloat sumOfNormals = v0.getNormal() + v1.getNormal() + v2.getNormal(); + + v0New += sumOfNormals; + v1New += sumOfNormals; + v2New += sumOfNormals; + } + + for(uint32_t uIndex = 0; uIndex < summedNormals.size(); uIndex++) + { + if(bNormaliseResult) + { + summedNormals[uIndex].normalise(); + } + m_vecVertices[uIndex].setNormal(summedNormals[uIndex]); + } + }*/ + + /*template + void Mesh::generateAveragedFaceNormals(bool bNormalise, bool bIncludeEdgeVertices) + { + Vector3DFloat offset = static_cast(m_Region.getLowerCorner()); + + //Initially zero the normals + for(vector::iterator iterVertex = m_vecVertices.begin(); iterVertex != m_vecVertices.end(); iterVertex++) + { + if(m_Region.containsPoint(iterVertex->getPosition() + offset, 0.001)) + { + iterVertex->setNormal(Vector3DFloat(0.0f,0.0f,0.0f)); + } + } + + for(vector::iterator iterIndex = m_vecTriangleIndices.begin(); iterIndex != m_vecTriangleIndices.end();) + { + PositionMaterialNormal& v0 = m_vecVertices[*iterIndex]; + iterIndex++; + PositionMaterialNormal& v1 = m_vecVertices[*iterIndex]; + iterIndex++; + PositionMaterialNormal& v2 = m_vecVertices[*iterIndex]; + iterIndex++; + + Vector3DFloat triangleNormal = (v1.getPosition()-v0.getPosition()).cross(v2.getPosition()-v0.getPosition()); + + if(m_Region.containsPoint(v0.getPosition() + offset, 0.001)) + { + v0.setNormal(v0.getNormal() + triangleNormal); + } + if(m_Region.containsPoint(v1.getPosition() + offset, 0.001)) + { + v1.setNormal(v1.getNormal() + triangleNormal); + } + if(m_Region.containsPoint(v2.getPosition() + offset, 0.001)) + { + v2.setNormal(v2.getNormal() + triangleNormal); + } + } + + if(bNormalise) + { + for(vector::iterator iterVertex = m_vecVertices.begin(); iterVertex != m_vecVertices.end(); iterVertex++) + { + Vector3DFloat normal = iterVertex->getNormal(); + normal.normalise(); + iterVertex->setNormal(normal); + } + } + }*/ + + /*template + std::shared_ptr< Mesh > Mesh::extractSubset(std::set setMaterials) + { + std::shared_ptr< Mesh > result(new Mesh); + + if(m_vecVertices.size() == 0) //FIXME - I don't think we should need this test, but I have seen crashes otherwise... + { + return result; + } + + assert(m_vecLodRecords.size() == 1); + if(m_vecLodRecords.size() != 1) + { + //If we have done progressive LOD then it's too late to split into subsets. + return result; + } + + std::vector indexMap(m_vecVertices.size()); + std::fill(indexMap.begin(), indexMap.end(), -1); + + for(uint32_t triCt = 0; triCt < m_vecTriangleIndices.size(); triCt += 3) + { + + PositionMaterialNormal& v0 = m_vecVertices[m_vecTriangleIndices[triCt]]; + PositionMaterialNormal& v1 = m_vecVertices[m_vecTriangleIndices[triCt + 1]]; + PositionMaterialNormal& v2 = m_vecVertices[m_vecTriangleIndices[triCt + 2]]; + + if( + (setMaterials.find(v0.getMaterial()) != setMaterials.end()) || + (setMaterials.find(v1.getMaterial()) != setMaterials.end()) || + (setMaterials.find(v2.getMaterial()) != setMaterials.end())) + { + uint32_t i0; + if(indexMap[m_vecTriangleIndices[triCt]] == -1) + { + indexMap[m_vecTriangleIndices[triCt]] = result->addVertex(v0); + } + i0 = indexMap[m_vecTriangleIndices[triCt]]; + + uint32_t i1; + if(indexMap[m_vecTriangleIndices[triCt+1]] == -1) + { + indexMap[m_vecTriangleIndices[triCt+1]] = result->addVertex(v1); + } + i1 = indexMap[m_vecTriangleIndices[triCt+1]]; + + uint32_t i2; + if(indexMap[m_vecTriangleIndices[triCt+2]] == -1) + { + indexMap[m_vecTriangleIndices[triCt+2]] = result->addVertex(v2); + } + i2 = indexMap[m_vecTriangleIndices[triCt+2]]; + + result->addTriangle(i0,i1,i2); + } + } + + result->m_vecLodRecords.clear(); + LodRecord lodRecord; + lodRecord.beginIndex = 0; + lodRecord.endIndex = result->getNoOfIndices(); + result->m_vecLodRecords.push_back(lodRecord); + + return result; + }*/ + + template + int Mesh::noOfDegenerateTris(void) + { + int count = 0; + for(uint32_t triCt = 0; triCt < m_vecTriangleIndices.size();) + { + int v0 = m_vecTriangleIndices[triCt]; + triCt++; + int v1 = m_vecTriangleIndices[triCt]; + triCt++; + int v2 = m_vecTriangleIndices[triCt]; + triCt++; + + if((v0 == v1) || (v1 == v2) || (v2 == v0)) + { + count++; + } + } + return count; + } + + template + void Mesh::removeDegenerateTris(void) + { + int noOfNonDegenerate = 0; + int targetCt = 0; + for(uint32_t triCt = 0; triCt < m_vecTriangleIndices.size();) + { + int v0 = m_vecTriangleIndices[triCt]; + triCt++; + int v1 = m_vecTriangleIndices[triCt]; + triCt++; + int v2 = m_vecTriangleIndices[triCt]; + triCt++; + + if((v0 != v1) && (v1 != v2) & (v2 != v0)) + { + m_vecTriangleIndices[targetCt] = v0; + targetCt++; + m_vecTriangleIndices[targetCt] = v1; + targetCt++; + m_vecTriangleIndices[targetCt] = v2; + targetCt++; + + noOfNonDegenerate++; + } + } + + m_vecTriangleIndices.resize(noOfNonDegenerate * 3); + } + + template + void Mesh::removeUnusedVertices(void) + { + std::vector isVertexUsed(m_vecVertices.size()); + std::fill(isVertexUsed.begin(), isVertexUsed.end(), false); + + for(uint32_t triCt = 0; triCt < m_vecTriangleIndices.size(); triCt++) + { + int v = m_vecTriangleIndices[triCt]; + isVertexUsed[v] = true; + } + + int noOfUsedVertices = 0; + std::vector newPos(m_vecVertices.size()); + for(uint32_t vertCt = 0; vertCt < m_vecVertices.size(); vertCt++) + { + if(isVertexUsed[vertCt]) + { + m_vecVertices[noOfUsedVertices] = m_vecVertices[vertCt]; + newPos[vertCt] = noOfUsedVertices; + noOfUsedVertices++; + } + } + + m_vecVertices.resize(noOfUsedVertices); + + for(uint32_t triCt = 0; triCt < m_vecTriangleIndices.size(); triCt++) + { + m_vecTriangleIndices[triCt] = newPos[m_vecTriangleIndices[triCt]]; + } + } + + //Currently a free function - think where this needs to go. + template + std::shared_ptr< Mesh > extractSubset(Mesh& inputMesh, std::set setMaterials) + { + std::shared_ptr< Mesh > result(new Mesh); + + result->m_Region = inputMesh.m_Region; + + if(inputMesh.m_vecVertices.size() == 0) //FIXME - I don't think we should need this test, but I have seen crashes otherwise... + { + return result; + } + + POLYVOX_ASSERT(inputMesh.m_vecLodRecords.size() == 1, "Number of LOD records must equal one."); + if(inputMesh.m_vecLodRecords.size() != 1) + { + //If we have done progressive LOD then it's too late to split into subsets. + return result; + } + + std::vector indexMap(inputMesh.m_vecVertices.size()); + std::fill(indexMap.begin(), indexMap.end(), -1); + + for(uint32_t triCt = 0; triCt < inputMesh.m_vecTriangleIndices.size(); triCt += 3) + { + + VertexType& v0 = inputMesh.m_vecVertices[inputMesh.m_vecTriangleIndices[triCt]]; + VertexType& v1 = inputMesh.m_vecVertices[inputMesh.m_vecTriangleIndices[triCt + 1]]; + VertexType& v2 = inputMesh.m_vecVertices[inputMesh.m_vecTriangleIndices[triCt + 2]]; + + if( + (setMaterials.find(v0.getMaterial()) != setMaterials.end()) || + (setMaterials.find(v1.getMaterial()) != setMaterials.end()) || + (setMaterials.find(v2.getMaterial()) != setMaterials.end())) + { + uint32_t i0; + if(indexMap[inputMesh.m_vecTriangleIndices[triCt]] == -1) + { + indexMap[inputMesh.m_vecTriangleIndices[triCt]] = result->addVertex(v0); + } + i0 = indexMap[inputMesh.m_vecTriangleIndices[triCt]]; + + uint32_t i1; + if(indexMap[inputMesh.m_vecTriangleIndices[triCt+1]] == -1) + { + indexMap[inputMesh.m_vecTriangleIndices[triCt+1]] = result->addVertex(v1); + } + i1 = indexMap[inputMesh.m_vecTriangleIndices[triCt+1]]; + + uint32_t i2; + if(indexMap[inputMesh.m_vecTriangleIndices[triCt+2]] == -1) + { + indexMap[inputMesh.m_vecTriangleIndices[triCt+2]] = result->addVertex(v2); + } + i2 = indexMap[inputMesh.m_vecTriangleIndices[triCt+2]]; + + result->addTriangle(i0,i1,i2); + } + } + + result->m_vecLodRecords.clear(); + LodRecord lodRecord; + lodRecord.beginIndex = 0; + lodRecord.endIndex = result->getNoOfIndices(); + result->m_vecLodRecords.push_back(lodRecord); + + return result; + } + + template + void Mesh::scaleVertices(float amount) + { + for(uint32_t ct = 0; ct < m_vecVertices.size(); ct++) + { + //TODO: Should rethink accessors here to provide faster access + Vector3DFloat position = m_vecVertices[ct].getPosition(); + position *= amount; + m_vecVertices[ct].setPosition(position); + } + } + + template + void Mesh::translateVertices(const Vector3DFloat& amount) + { + for(uint32_t ct = 0; ct < m_vecVertices.size(); ct++) + { + //TODO: Should rethink accessors here to provide faster access + Vector3DFloat position = m_vecVertices[ct].getPosition(); + position += amount; + m_vecVertices[ct].setPosition(position); + } + } +} diff --git a/library/PolyVoxCore/include/PolyVoxCore/PolyVoxForwardDeclarations.h b/library/PolyVoxCore/include/PolyVoxCore/PolyVoxForwardDeclarations.h index 0d68b3e9..3d9ef742 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/PolyVoxForwardDeclarations.h +++ b/library/PolyVoxCore/include/PolyVoxCore/PolyVoxForwardDeclarations.h @@ -160,9 +160,9 @@ namespace PolyVox template class MarchingCubesSurfaceExtractor; //////////////////////////////////////////////////////////////////////////////// - // SurfaceMesh + // Mesh //////////////////////////////////////////////////////////////////////////////// - template class SurfaceMesh; + template class Mesh; //////////////////////////////////////////////////////////////////////////////// // Vector diff --git a/tests/TestCubicSurfaceExtractor.cpp b/tests/TestCubicSurfaceExtractor.cpp index 7c74dee1..8476b7f8 100644 --- a/tests/TestCubicSurfaceExtractor.cpp +++ b/tests/TestCubicSurfaceExtractor.cpp @@ -130,7 +130,7 @@ void TestCubicSurfaceExtractor::testExecute() const static uint32_t uIndexToCheck = 2000; const static uint32_t uExpectedIndex = 1334; - SurfaceMesh mesh;*/ + Mesh mesh;*/ /*testForType(mesh); QCOMPARE(mesh.getNoOfVertices(), uExpectedVertices); diff --git a/tests/TestSurfaceExtractor.cpp b/tests/TestSurfaceExtractor.cpp index c11541a5..2189b9c2 100644 --- a/tests/TestSurfaceExtractor.cpp +++ b/tests/TestSurfaceExtractor.cpp @@ -102,7 +102,7 @@ void writeMaterialValueToVoxel(int valueToWrite, MaterialDensityPair88& voxel) // Runs the surface extractor for a given type. template -SurfaceMesh > testForType(void) //I think we could avoid specifying this return type by using auto/decltype? +Mesh > testForType(void) //I think we could avoid specifying this return type by using auto/decltype? { const int32_t uVolumeSideLength = 32; @@ -133,7 +133,7 @@ SurfaceMesh > testForType(void) //I think we coul return result; } -void testCustomController(SurfaceMesh >& result) +void testCustomController(Mesh >& result) { const int32_t uVolumeSideLength = 32; @@ -165,7 +165,7 @@ void TestSurfaceExtractor::testExecute() const static float fExpectedMaterial = 42.0f; const static float fNoMaterial = 1.0f; - SurfaceMesh > mesh; + Mesh > mesh; //Run the test for various voxel types. QBENCHMARK { mesh = testForType();