Tidying mesh class.

This commit is contained in:
David Williams 2014-08-09 09:18:30 +02:00
parent c5cf71b161
commit 94d1b57b81
2 changed files with 42 additions and 19 deletions

View File

@ -50,43 +50,54 @@ namespace PolyVox
Mesh(); Mesh();
~Mesh(); ~Mesh();
const std::vector<IndexType>& getIndices(void) const;
uint32_t getNoOfIndices(void) const;
IndexType getNoOfVertices(void) const; IndexType getNoOfVertices(void) const;
const std::vector<VertexType>& getVertices(void) const; const VertexType& getVertex(IndexType index) const;
const std::vector<VertexType>& getVertices(void) const; //Should probably deprecate
uint32_t getNoOfIndices(void) const;
IndexType getIndex(uint32_t index) const;
const std::vector<IndexType>& getIndices(void) const; //Should probably deprecate
const Vector3DInt32& getOffset(void) const; const Vector3DInt32& getOffset(void) const;
//void setNoOfVertices(IndexType noOfVertices);
//void setVertex()
void setOffset(const Vector3DInt32& offset); void setOffset(const Vector3DInt32& offset);
void addTriangle(IndexType index0, IndexType index1, IndexType index2);
IndexType addVertex(const VertexType& vertex); IndexType addVertex(const VertexType& vertex);
void addTriangle(IndexType index0, IndexType index1, IndexType index2);
void clear(void); void clear(void);
bool isEmpty(void) const; bool isEmpty(void) const;
void removeUnusedVertices(void); void removeUnusedVertices(void);
Vector3DInt32 m_offset; Vector3DInt32 m_offset;
public: private:
std::vector<IndexType> m_vecTriangleIndices; std::vector<IndexType> m_vecTriangleIndices;
std::vector<VertexType> m_vecVertices; std::vector<VertexType> m_vecVertices;
}; };
template <typename MeshType> template <typename MeshType>
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; Mesh< Vertex< typename MeshType::VertexType::DataType >, typename MeshType::IndexType > decodedMesh;
result.m_vecVertices.resize(mesh.m_vecVertices.size());
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;
} }
} }

View File

@ -34,9 +34,21 @@ namespace PolyVox
} }
template <typename VertexType, typename IndexType> template <typename VertexType, typename IndexType>
const std::vector<IndexType>& Mesh<VertexType, IndexType>::getIndices(void) const IndexType Mesh<VertexType, IndexType>::getNoOfVertices(void) const
{ {
return m_vecTriangleIndices; return m_vecVertices.size();
}
template <typename VertexType, typename IndexType>
const VertexType& Mesh<VertexType, IndexType>::getVertex(IndexType index) const
{
return m_vecVertices[index];
}
template <typename VertexType, typename IndexType>
const std::vector<VertexType>& Mesh<VertexType, IndexType>::getVertices(void) const
{
return m_vecVertices;
} }
template <typename VertexType, typename IndexType> template <typename VertexType, typename IndexType>
@ -46,15 +58,15 @@ namespace PolyVox
} }
template <typename VertexType, typename IndexType> template <typename VertexType, typename IndexType>
IndexType Mesh<VertexType, IndexType>::getNoOfVertices(void) const IndexType Mesh<VertexType, IndexType>::getIndex(uint32_t index) const
{ {
return m_vecVertices.size(); return m_vecTriangleIndices[index];
} }
template <typename VertexType, typename IndexType> template <typename VertexType, typename IndexType>
const std::vector<VertexType>& Mesh<VertexType, IndexType>::getVertices(void) const const std::vector<IndexType>& Mesh<VertexType, IndexType>::getIndices(void) const
{ {
return m_vecVertices; return m_vecTriangleIndices;
} }
template <typename VertexType, typename IndexType> template <typename VertexType, typename IndexType>