Karma Engine
Loading...
Searching...
No Matches
Mesh.h
1#pragma once
2
3#include "krpch.h"
4
5#include "Buffer.h"
6#include <assimp/Importer.hpp>
7#include <assimp/scene.h>
8#include <assimp/postprocess.h>
9
10namespace Karma
11{
12 enum class MeshType
13 {
14 Mesh = 0,
15 SkeletalMesh
16 };
17
18 enum class MeshAttribute
19 {
20 Vertices = 0,
21 Normals,
22 Tangents,
23 Bitangents,
24 Colors,
25 TextureCoords,
26 AnimMeshes
27 };
28
29 class KARMA_API Mesh
30 {
31 public:
32 Mesh(std::shared_ptr<VertexBuffer> vertexBuffer, std::shared_ptr<IndexBuffer> indexBuffer, const std::string& meshName = "NoName",
33 MeshType mType = MeshType::Mesh);
34 Mesh(const std::string& filePath);
35
36 virtual void ProcessMesh(aiMesh* meshToProcess);
37 static std::shared_ptr<Mesh> ProcessTheRawMesh(aiMesh* meshToProcess, const std::string& mName = "NoName");
38 static void DealVertexIndexBufferData(float*& vertexData, uint32_t& vertexDataSize, uint32_t*& indexData, uint32_t& indexDataLength,
39 aiMesh* meshToProcess, BufferLayout& buffLayout);
40
41 void ProcessNode(aiNode* nodeToProcess, const aiScene* theScene);
42
43 static void GaugeVertexDataLayout(aiMesh* meshToProcess, BufferLayout& buffLayout);
44
45 std::shared_ptr<VertexBuffer> GetVertexBuffer() const { return m_VertexBuffer; }
46 std::shared_ptr<IndexBuffer> GetIndexBuffer() const { return m_IndexBuffer; }
47
48 void SetVertexBuffer(std::shared_ptr<VertexBuffer> vBuffer) { m_VertexBuffer = vBuffer; }
49 void SetIndexBuffer(std::shared_ptr<IndexBuffer> iBuffer) { m_IndexBuffer = iBuffer; }
50
51 // Useful dictionary related functions
52 static float LayoutElementToAttributeValue(unsigned int vertexNumber, uint32_t counter, aiMesh* meshToProcess, const BufferElement& layoutElem);
53 static void InitializeAttributeDictionary();
54
55 protected:
56 std::shared_ptr<VertexBuffer> m_VertexBuffer;
57 std::shared_ptr<IndexBuffer> m_IndexBuffer;
58
59 std::string m_MeshName;
60 MeshType m_MeshType;
61
62 static std::shared_ptr<std::unordered_map<std::string, MeshAttribute>> m_NameToAttributeDictionary;
63 };
64}
Definition Buffer.h:111
Definition Mesh.h:30
Definition Buffer.h:62