From 5dfa7e2562da59c3139d31f0450dd0013063f1a8 Mon Sep 17 00:00:00 2001 From: David Williams Date: Mon, 5 May 2014 20:53:47 +0200 Subject: [PATCH] The CubicSurfaceExtractor now generates vertices of type PositionMaterialNormal rather than PositionMaterial. The normal property is just a dummy and is not filled in, though conceptually we could put something in there in the future (average normal of surrounding faces?) The point of this change is to move towards having a single vertex class with known properties (including normal). This makes it simpler to write code which uses the vertices because we always know which properties are present. This will probably be useful when working with vertex buffer objects. --- examples/Basic/OpenGLWidget.cpp | 6 +++--- examples/Basic/OpenGLWidget.h | 2 +- examples/Basic/main.cpp | 2 +- .../PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h | 6 +++--- .../include/PolyVoxCore/CubicSurfaceExtractor.inl | 4 ++-- tests/TestCubicSurfaceExtractor.cpp | 2 +- tests/TestVolumeSubclass.cpp | 2 +- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/examples/Basic/OpenGLWidget.cpp b/examples/Basic/OpenGLWidget.cpp index 9b662fb2..d3bc72c0 100644 --- a/examples/Basic/OpenGLWidget.cpp +++ b/examples/Basic/OpenGLWidget.cpp @@ -14,7 +14,7 @@ OpenGLWidget::OpenGLWidget(QWidget *parent) { } -void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh& surfaceMesh) +void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh& surfaceMesh) { //Convienient access to the vertices and indices const auto& vecIndices = surfaceMesh.getIndices(); @@ -27,7 +27,7 @@ void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh& surfaceMesh); + void setSurfaceMeshToRender(const PolyVox::SurfaceMesh& surfaceMesh); protected: //Qt OpenGL functions diff --git a/examples/Basic/main.cpp b/examples/Basic/main.cpp index 9a3dac94..516fb9d4 100644 --- a/examples/Basic/main.cpp +++ b/examples/Basic/main.cpp @@ -78,7 +78,7 @@ int main(int argc, char *argv[]) createSphereInVolume(volData, 30); //A mesh object to hold the result of surface extraction - SurfaceMesh mesh; + SurfaceMesh mesh; //Create a surface extractor. Comment out one of the following two lines to decide which type gets created. CubicSurfaceExtractor< SimpleVolume > surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh); diff --git a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h index a225a3b5..c3149de2 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h +++ b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h @@ -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, 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 @@ -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 3174c63f..e069cfbe 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) @@ -214,7 +214,7 @@ 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(PositionMaterialNormal(Vector3DFloat(static_cast(uX)-0.5f, static_cast(uY)-0.5f, static_cast(uZ)-0.5f), uMaterialIn)); rEntry.uMaterial = uMaterialIn; return rEntry.iIndex; diff --git a/tests/TestCubicSurfaceExtractor.cpp b/tests/TestCubicSurfaceExtractor.cpp index 45919e85..8e184162 100644 --- a/tests/TestCubicSurfaceExtractor.cpp +++ b/tests/TestCubicSurfaceExtractor.cpp @@ -106,7 +106,7 @@ uint32_t testForType(void) { for (int32_t x = 0; x < uVolumeSideLength; x += uRegionSideLength) { - SurfaceMesh result; + SurfaceMesh result; Region regionToExtract(x, y, z, x + uRegionSideLength - 1, y + uRegionSideLength - 1, z + uRegionSideLength - 1); CubicSurfaceExtractor< SimpleVolume > extractor(&volData, regionToExtract, &result); extractor.execute(); diff --git a/tests/TestVolumeSubclass.cpp b/tests/TestVolumeSubclass.cpp index 91a619b4..b9a71b6b 100644 --- a/tests/TestVolumeSubclass.cpp +++ b/tests/TestVolumeSubclass.cpp @@ -184,7 +184,7 @@ void TestVolumeSubclass::testExtractSurface() } } - SurfaceMesh result; + SurfaceMesh result; CubicSurfaceExtractor< VolumeSubclass > cubicSurfaceExtractor(&volumeSubclass, volumeSubclass.getEnclosingRegion(), &result); cubicSurfaceExtractor.execute();