vengine  0.0.1
3D graphics engine
Loading...
Searching...
No Matches
Model.hpp
Go to the documentation of this file.
1///
2/// @file Model.hpp
3/// @brief This file contains the Model class
4/// @namespace ven
5///
6
7#pragma once
8
9#include <memory>
10#include <vector>
11#include <unordered_map>
12#include <filesystem>
13
14#include <glm/glm.hpp>
15
16#include <assimp/scene.h>
17
20
21
22namespace ven {
23
24 ///
25 /// @class Model
26 /// @brief Class for model
27 /// @namespace ven
28 ///
29 class Model {
30
31 public:
32
33 struct Vertex {
34 glm::vec3 position{};
35 glm::vec3 color{};
36 glm::vec3 normal{};
37 glm::vec2 uv{};
38
39 static std::vector<VkVertexInputBindingDescription> getBindingDescriptions();
40 static std::vector<VkVertexInputAttributeDescription> getAttributeDescriptions();
41
42 bool operator==(const Vertex& other) const { return position == other.position && color == other.color && normal == other.normal && uv == other.uv; }
43 };
44
45 struct Builder {
46 std::vector<Vertex> vertices;
47 std::vector<uint32_t> indices;
48
49 void loadModel(const std::string &filename);
50 void processNode(const aiNode* node, const aiScene* scene);
51 void processMesh(const aiMesh* mesh, const aiScene* scene);
52 };
53
54 Model(Device &device, const Builder &builder);
55 ~Model() = default;
56
57 Model(const Model&) = delete;
58 Model& operator=(const Model&) = delete;
59 Model(Model&&) = delete;
60 Model& operator=(Model&&) = delete;
61
62 void bind(VkCommandBuffer commandBuffer) const;
63 void draw(VkCommandBuffer commandBuffer) const;
64
65 private:
66
67 void createVertexBuffer(const std::vector<Vertex>& vertices);
68 void createIndexBuffer(const std::vector<uint32_t>& indices);
69
71 std::unique_ptr<Buffer> m_vertexBuffer;
72 uint32_t m_vertexCount;
73
74 bool m_hasIndexBuffer{false};
75 std::unique_ptr<Buffer> m_indexBuffer;
76 uint32_t m_indexCount;
77
78 }; // class Model
79
80} // namespace ven
This file contains the Buffer class.
This file contains the Logger class.
Class for device.
Definition Device.hpp:35
Class for model.
Definition Model.hpp:29
Model & operator=(const Model &)=delete
void draw(VkCommandBuffer commandBuffer) const
Definition model.cpp:64
Model & operator=(Model &&)=delete
uint32_t m_indexCount
Definition Model.hpp:76
Model(Device &device, const Builder &builder)
Definition model.cpp:20
Model(const Model &)=delete
void bind(VkCommandBuffer commandBuffer) const
Definition model.cpp:73
std::unique_ptr< Buffer > m_vertexBuffer
Definition Model.hpp:71
Model(Model &&)=delete
Device & m_device
Definition Model.hpp:70
bool m_hasIndexBuffer
Definition Model.hpp:74
std::unique_ptr< Buffer > m_indexBuffer
Definition Model.hpp:75
void createVertexBuffer(const std::vector< Vertex > &vertices)
Definition model.cpp:26
uint32_t m_vertexCount
Definition Model.hpp:72
void createIndexBuffer(const std::vector< uint32_t > &indices)
Definition model.cpp:43
~Model()=default
void loadModel(const std::string &filename)
Definition model.cpp:105
std::vector< Vertex > vertices
Definition Model.hpp:46
void processMesh(const aiMesh *mesh, const aiScene *scene)
Definition model.cpp:132
std::vector< uint32_t > indices
Definition Model.hpp:47
void processNode(const aiNode *node, const aiScene *scene)
Definition model.cpp:121
glm::vec3 position
Definition Model.hpp:34
static std::vector< VkVertexInputAttributeDescription > getAttributeDescriptions()
Definition model.cpp:93
glm::vec3 color
Definition Model.hpp:35
static std::vector< VkVertexInputBindingDescription > getBindingDescriptions()
Definition model.cpp:84
bool operator==(const Vertex &other) const
Definition Model.hpp:42
glm::vec3 normal
Definition Model.hpp:36
glm::vec2 uv
Definition Model.hpp:37