Elevate Engine 1
Loading...
Searching...
No Matches
Mesh.h
Go to the documentation of this file.
1#pragma once
2
3#include <stdint.h>
4#include <memory>
5#include <vector>
6
9
10namespace Elevate
11{
12 class VertexBuffer;
13 class IndexBuffer;
14 class VertexArray;
15
16 struct MeshData
17 {
18 std::vector<Vertex> Vertices;
19 std::vector<uint32_t> Indices;
20 std::vector<TexturePtr> Textures;
21
22 MeshData() = default;
23 MeshData(const std::vector<Vertex>& vertices, const std::vector<uint32_t>& indices, const std::vector<TexturePtr>& textures)
24 : Vertices(vertices), Indices(indices), Textures(textures) { }
25 };
26
27 enum class PrimitiveType : uint8_t
28 {
29 Cube,
34 Capsule,
35 Plane,
36 Quad,
37 Torus,
38 };
39
40 class Mesh {
41 public:
42 Mesh() = default;
43 Mesh(const MeshData& data);
44 Mesh(const std::vector<Vertex>& vertices, const std::vector<uint32_t>& indices, const std::vector<std::shared_ptr<Texture>>& textures);
45
46 static Mesh* Create(const MeshData& data);
47 static Mesh* Create(std::vector<Vertex>& vertices, std::vector<uint32_t>& indices, std::vector<std::shared_ptr<Texture>>& textures);
48
49 std::shared_ptr<VertexBuffer> GetVertexBuffer() const { return m_VertexBuffer; }
50 std::shared_ptr<IndexBuffer> GetIndexBuffer() const { return m_IndexBuffer; }
51 std::shared_ptr<VertexArray> GetVertexArray() const { return m_VertexArray; }
52 const std::vector<std::shared_ptr<Texture>>& GetTextures() const { return m_data.Textures; }
53
54 static Mesh GenerateCube(float size = 1.0f);
55 static Mesh GenerateUVSphere(float radius, int latitudes, int longitudes);
56 static Mesh GenerateCubephere(float radius, int subdivision);
57 static Mesh GenerateQuad(float size = 1.0f);
58 static Mesh GeneratePlane(float size, int resolution);
59
60 static Mesh CombineMeshes(std::vector<Mesh>& meshes);
61
62 /*
63 TODO: GENERATIONS FOR THESE PRIMITIVES :
64 Cubesphere,
65 Icosphere,
66 Cylinder,
67 Capsule,
68 Torus,
69 */
70 private:
71 std::shared_ptr<VertexArray> m_VertexArray;
72 std::shared_ptr<VertexBuffer> m_VertexBuffer;
73 std::shared_ptr<IndexBuffer> m_IndexBuffer;
74
75 MeshData m_data;
76 };
77}
std::shared_ptr< VertexArray > GetVertexArray() const
Definition Mesh.h:51
static Mesh CombineMeshes(std::vector< Mesh > &meshes)
Definition Mesh.cpp:231
static Mesh GeneratePlane(float size, int resolution)
Definition Mesh.cpp:191
static Mesh * Create(const MeshData &data)
Definition Mesh.cpp:44
static Mesh GenerateCubephere(float radius, int subdivision)
Definition Mesh.cpp:181
Mesh()=default
const std::vector< std::shared_ptr< Texture > > & GetTextures() const
Definition Mesh.h:52
static Mesh GenerateUVSphere(float radius, int latitudes, int longitudes)
Definition Mesh.cpp:127
static Mesh GenerateQuad(float size=1.0f)
Definition Mesh.cpp:186
static Mesh GenerateCube(float size=1.0f)
Definition Mesh.cpp:54
std::shared_ptr< VertexBuffer > GetVertexBuffer() const
Definition Mesh.h:49
std::shared_ptr< IndexBuffer > GetIndexBuffer() const
Definition Mesh.h:50
PrimitiveType
Definition Mesh.h:28
std::vector< uint32_t > Indices
Definition Mesh.h:19
std::vector< Vertex > Vertices
Definition Mesh.h:18
std::vector< TexturePtr > Textures
Definition Mesh.h:20
MeshData(const std::vector< Vertex > &vertices, const std::vector< uint32_t > &indices, const std::vector< TexturePtr > &textures)
Definition Mesh.h:23
MeshData()=default