From 29baac9d6ddea8da312edd5e1c77c87280db53f6 Mon Sep 17 00:00:00 2001 From: David Williams Date: Sat, 9 Aug 2014 09:31:45 +0200 Subject: [PATCH] Tidying mesh class. --- .../PolyVoxCore/include/PolyVoxCore/Mesh.h | 17 ++++------ .../PolyVoxCore/include/PolyVoxCore/Mesh.inl | 34 +++++++++++++------ 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Mesh.h b/library/PolyVoxCore/include/PolyVoxCore/Mesh.h index 22eab2aa..2143133f 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Mesh.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Mesh.h @@ -52,17 +52,15 @@ namespace PolyVox IndexType getNoOfVertices(void) const; const VertexType& getVertex(IndexType index) const; - const std::vector& getVertices(void) const; //Should probably deprecate + const VertexType* getRawVertexData(void) const; + POLYVOX_DEPRECATED const std::vector& getVertices(void) const; uint32_t getNoOfIndices(void) const; IndexType getIndex(uint32_t index) const; - const std::vector& getIndices(void) const; //Should probably deprecate + const IndexType* getRawIndexData(void); + POLYVOX_DEPRECATED const std::vector& getIndices(void) const; const Vector3DInt32& getOffset(void) const; - - //void setNoOfVertices(IndexType noOfVertices); - //void setVertex() - void setOffset(const Vector3DInt32& offset); IndexType addVertex(const VertexType& vertex); @@ -70,13 +68,12 @@ namespace PolyVox void clear(void); bool isEmpty(void) const; - void removeUnusedVertices(void); - - Vector3DInt32 m_offset; + void removeUnusedVertices(void); private: - std::vector m_vecTriangleIndices; + std::vector m_vecIndices; std::vector m_vecVertices; + Vector3DInt32 m_offset; }; template diff --git a/library/PolyVoxCore/include/PolyVoxCore/Mesh.inl b/library/PolyVoxCore/include/PolyVoxCore/Mesh.inl index afecb00f..c574687f 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Mesh.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/Mesh.inl @@ -45,6 +45,12 @@ namespace PolyVox return m_vecVertices[index]; } + template + const VertexType* Mesh::getRawVertexData(void) const + { + return &(m_vecVertices[0]); + } + template const std::vector& Mesh::getVertices(void) const { @@ -54,19 +60,25 @@ namespace PolyVox template uint32_t Mesh::getNoOfIndices(void) const { - return m_vecTriangleIndices.size(); + return m_vecIndices.size(); } template IndexType Mesh::getIndex(uint32_t index) const { - return m_vecTriangleIndices[index]; + return m_vecIndices[index]; + } + + template + const IndexType* Mesh::getRawIndexData(void) + { + return &(m_vecIndices[0]); } template const std::vector& Mesh::getIndices(void) const { - return m_vecTriangleIndices; + return m_vecIndices; } template @@ -89,9 +101,9 @@ namespace PolyVox 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); + m_vecIndices.push_back(index0); + m_vecIndices.push_back(index1); + m_vecIndices.push_back(index2); } template @@ -108,7 +120,7 @@ namespace PolyVox void Mesh::clear(void) { m_vecVertices.clear(); - m_vecTriangleIndices.clear(); + m_vecIndices.clear(); } template @@ -123,9 +135,9 @@ namespace PolyVox std::vector isVertexUsed(m_vecVertices.size()); std::fill(isVertexUsed.begin(), isVertexUsed.end(), false); - for(uint32_t triCt = 0; triCt < m_vecTriangleIndices.size(); triCt++) + for(uint32_t triCt = 0; triCt < m_vecIndices.size(); triCt++) { - int v = m_vecTriangleIndices[triCt]; + int v = m_vecIndices[triCt]; isVertexUsed[v] = true; } @@ -143,9 +155,9 @@ namespace PolyVox m_vecVertices.resize(noOfUsedVertices); - for(uint32_t triCt = 0; triCt < m_vecTriangleIndices.size(); triCt++) + for(uint32_t triCt = 0; triCt < m_vecIndices.size(); triCt++) { - m_vecTriangleIndices[triCt] = newPos[m_vecTriangleIndices[triCt]]; + m_vecIndices[triCt] = newPos[m_vecIndices[triCt]]; } } }