From 94d1b57b81468a66b9585a14a1f2c6cfd1d07e2c Mon Sep 17 00:00:00 2001 From: David Williams Date: Sat, 9 Aug 2014 09:18:30 +0200 Subject: [PATCH] Tidying mesh class. --- .../PolyVoxCore/include/PolyVoxCore/Mesh.h | 37 ++++++++++++------- .../PolyVoxCore/include/PolyVoxCore/Mesh.inl | 24 +++++++++--- 2 files changed, 42 insertions(+), 19 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Mesh.h b/library/PolyVoxCore/include/PolyVoxCore/Mesh.h index 64356785..22eab2aa 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Mesh.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Mesh.h @@ -50,43 +50,54 @@ namespace PolyVox Mesh(); ~Mesh(); - const std::vector& getIndices(void) const; - uint32_t getNoOfIndices(void) const; IndexType getNoOfVertices(void) const; - const std::vector& getVertices(void) const; + const VertexType& getVertex(IndexType index) const; + const std::vector& getVertices(void) const; //Should probably deprecate + + uint32_t getNoOfIndices(void) const; + IndexType getIndex(uint32_t index) const; + const std::vector& getIndices(void) const; //Should probably deprecate + const Vector3DInt32& getOffset(void) const; + //void setNoOfVertices(IndexType noOfVertices); + //void setVertex() + void setOffset(const Vector3DInt32& offset); - void addTriangle(IndexType index0, IndexType index1, IndexType index2); IndexType addVertex(const VertexType& vertex); + void addTriangle(IndexType index0, IndexType index1, IndexType index2); + void clear(void); bool isEmpty(void) const; void removeUnusedVertices(void); Vector3DInt32 m_offset; - public: + private: std::vector m_vecTriangleIndices; std::vector m_vecVertices; }; template - Mesh< Vertex< typename MeshType::VertexType::DataType >, typename MeshType::IndexType > decodeMesh(const MeshType& mesh) + Mesh< Vertex< typename MeshType::VertexType::DataType >, typename MeshType::IndexType > decodeMesh(const MeshType& encodedMesh) { - Mesh< Vertex< typename MeshType::VertexType::DataType >, typename MeshType::IndexType > result; - result.m_vecVertices.resize(mesh.m_vecVertices.size()); + Mesh< Vertex< typename MeshType::VertexType::DataType >, typename MeshType::IndexType > decodedMesh; - for(typename MeshType::IndexType ct = 0; ct < mesh.m_vecVertices.size(); ct++) + for (auto ct = 0; ct < encodedMesh.getNoOfVertices(); ct++) { - result.m_vecVertices[ct] = decodeVertex(mesh.m_vecVertices[ct]); + decodedMesh.addVertex(decodeVertex(encodedMesh.getVertex(ct))); } - result.m_vecTriangleIndices = mesh.m_vecTriangleIndices; + POLYVOX_ASSERT(encodedMesh.getNoOfIndices() % 3 == 0, "The number of indices must always be a multiple of three."); + for (auto ct = 0; ct < encodedMesh.getNoOfIndices(); ct += 3) + { + decodedMesh.addTriangle(encodedMesh.getIndex(ct), encodedMesh.getIndex(ct + 1), encodedMesh.getIndex(ct + 2)); + } - result.m_offset = mesh.m_offset; + decodedMesh.setOffset(encodedMesh.getOffset()); - return result; + return decodedMesh; } } diff --git a/library/PolyVoxCore/include/PolyVoxCore/Mesh.inl b/library/PolyVoxCore/include/PolyVoxCore/Mesh.inl index e34f51ff..afecb00f 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Mesh.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/Mesh.inl @@ -34,9 +34,21 @@ namespace PolyVox } template - const std::vector& Mesh::getIndices(void) const + IndexType Mesh::getNoOfVertices(void) const { - return m_vecTriangleIndices; + return m_vecVertices.size(); + } + + template + const VertexType& Mesh::getVertex(IndexType index) const + { + return m_vecVertices[index]; + } + + template + const std::vector& Mesh::getVertices(void) const + { + return m_vecVertices; } template @@ -46,15 +58,15 @@ namespace PolyVox } template - IndexType Mesh::getNoOfVertices(void) const + IndexType Mesh::getIndex(uint32_t index) const { - return m_vecVertices.size(); + return m_vecTriangleIndices[index]; } template - const std::vector& Mesh::getVertices(void) const + const std::vector& Mesh::getIndices(void) const { - return m_vecVertices; + return m_vecTriangleIndices; } template