2021SC@SDUSC
目录
回顾一下前几篇文章,我们讲到了有关图形学三维空间的变换与各种数据存储对象的信息,接下来就是关于三维空间中物体的网格表示。
IMesh.h与Mesh.h
与网格相关的类有两个其中IMesh是一个基类,定义了4个纯虚函数用于子类继承。
namespace OvRendering::Resources
{
/**
* Interface for any mesh
*/
class IMesh
{
public:
virtual void Bind() = 0;
virtual void Unbind() = 0;
virtual uint32_t GetVertexCount() = 0;
virtual uint32_t GetIndexCount() = 0;
};
}
而重点则是以下这个Mesh类,它对IMesh进行公有继承,用于实现网格的相关操作。
class Mesh : public IMesh
{
public:
Mesh(const std::vector<Geometry::Vertex>& p_vertices, const std::vector<uint32_t>& p_indices, uint32_t p_materialIndex);
virtual void Bind() override;
virtual void Unbind() override;
virtual uint32_t GetVertexCount() override;
virtual uint32_t GetIndexCount() override;
uint32_t GetMaterialIndex() const;
const OvRendering::Geometry::BoundingSphere& GetBoundingSphere() const;
private:
void CreateBuffers(const std::vector<Geometry::Vertex>& p_vertices, const std::vector<uint32_t>& p_indices);
void ComputeBoundingSphere(const std::vector<Geometry::Vertex>& p_vertices);
private:
const uint32_t m_vertexCount;
const uint32_t m_indicesCount;
const uint32_t m_materialIndex;
Buffers::VertexArray m_vertexArray;
std::unique_ptr<Buffers::VertexBuffer<float>> m_vertexBuffer;
std::unique_ptr<Buffers::IndexBuffer> m_indexBuffer;
Geometry::BoundingSphere m_boundingSphere;
};
Mesh类中包含了以下几个成员变量:
m_vertexCount:网格中的顶点个数;
m_indicesCount:顶点索引个数;
m_materialIndex:材质索引个数;
m_vertexArray:顶点数组对象;</