KarmaEngine
Game Engine for practical learning and research purposes
Loading...
Searching...
No Matches
Mesh.h
Go to the documentation of this file.
1
10
11#pragma once
12
13#include "krpch.h"
14
15#include "Buffer.h"
16#include <assimp/Importer.hpp>
17#include <assimp/scene.h>
18#include <assimp/postprocess.h>
19
20namespace Karma
21{
22 enum class MeshType
23 {
27 Mesh = 0,
28
33 };
34
57
62 class KARMA_API Mesh
63 {
64 public:
65 Mesh(std::shared_ptr<VertexBuffer> vertexBuffer, std::shared_ptr<IndexBuffer> indexBuffer, const std::string& meshName = "NoName",
66 MeshType mType = MeshType::Mesh);
67 Mesh(const std::string& filePath);
68
69 virtual void ProcessMesh(aiMesh* meshToProcess);
70
79 static std::shared_ptr<Mesh> ProcessTheRawMesh(aiMesh* meshToProcess, const std::string& mName = "NoName");
80
93 static void DealVertexIndexBufferData(float*& vertexData, uint32_t& vertexDataSize, uint32_t*& indexData, uint32_t& indexDataLength,
94 aiMesh* meshToProcess, BufferLayout& buffLayout);
95
96 void ProcessNode(aiNode* nodeToProcess, const aiScene* theScene);
97
106 static void GaugeVertexDataLayout(aiMesh* meshToProcess, BufferLayout& buffLayout);
107
108 std::shared_ptr<VertexBuffer> GetVertexBuffer() const { return m_VertexBuffer; }
109 std::shared_ptr<IndexBuffer> GetIndexBuffer() const { return m_IndexBuffer; }
110
111 void SetVertexBuffer(std::shared_ptr<VertexBuffer> vBuffer) { m_VertexBuffer = vBuffer; }
112 void SetIndexBuffer(std::shared_ptr<IndexBuffer> iBuffer) { m_IndexBuffer = iBuffer; }
113
114 // Useful dictionary related functions
115 static float LayoutElementToAttributeValue(unsigned int vertexNumber, uint32_t counter, aiMesh* meshToProcess, const BufferElement& layoutElem);
116 static void InitializeAttributeDictionary();
117
118 protected:
119 std::shared_ptr<VertexBuffer> m_VertexBuffer;
120 std::shared_ptr<IndexBuffer> m_IndexBuffer;
121
122 std::string m_MeshName;
123 MeshType m_MeshType;
124
125 static std::shared_ptr<std::unordered_map<std::string, MeshAttribute>> m_NameToAttributeDictionary;
126 };
127}
This file contains base classes for various kinds of buffers used by the Engine.
#define KARMA_API
Defining Karma's API macro for storage class information.
Definition Core.h:41
MeshType
Definition Mesh.h:23
@ Mesh
Static mesh.
Definition Mesh.h:27
MeshAttribute
An enum for cherning data by interleaving the following attributes.
Definition Mesh.h:41
@ Tangents
Definition Mesh.h:47
@ Normals
Definition Mesh.h:45
@ Colors
Definition Mesh.h:51
@ Bitangents
Definition Mesh.h:49
@ TextureCoords
Definition Mesh.h:53
@ Vertices
Definition Mesh.h:43
@ AnimMeshes
Definition Mesh.h:55
A format for vertex buffer say.
Definition Buffer.h:183
An organized collection of vertex and index buffers along with rest of the model specific information...
Definition Mesh.h:63
static std::shared_ptr< Mesh > ProcessTheRawMesh(aiMesh *meshToProcess, const std::string &mName="NoName")
Generate a layout (BufferLayout) for the supplied mesh.
Definition Mesh.cpp:81
static void DealVertexIndexBufferData(float *&vertexData, uint32_t &vertexDataSize, uint32_t *&indexData, uint32_t &indexDataLength, aiMesh *meshToProcess, BufferLayout &buffLayout)
Routine for gauging the vertexbuffer data.
Definition Mesh.cpp:127
static void GaugeVertexDataLayout(aiMesh *meshToProcess, BufferLayout &buffLayout)
Routine for extracting the format (BufferLayout) of vertexbuffer.
Definition Mesh.cpp:182
SkeletalMesh class.
Definition SkeletalMesh.h:38
A datastructure for creating interleaved data for Mesh with a specifc format (BufferLayout).
Definition Buffer.h:86