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 "Buffer.h"
14#include <assimp/Importer.hpp>
15#include <assimp/scene.h>
16#include <assimp/postprocess.h>
17
18namespace Karma
19{
20 enum class MeshType
21 {
25 Mesh = 0,
26
31 };
32
55
60 class KARMA_API Mesh
61 {
62 public:
63 Mesh(std::shared_ptr<VertexBuffer> vertexBuffer, std::shared_ptr<IndexBuffer> indexBuffer, const std::string& meshName = "NoName",
64 MeshType mType = MeshType::Mesh);
65 Mesh(const std::string& filePath);
66
67 virtual void ProcessMesh(aiMesh* meshToProcess);
68
77 static std::shared_ptr<Mesh> ProcessTheRawMesh(aiMesh* meshToProcess, const std::string& mName = "NoName");
78
91 static void DealVertexIndexBufferData(float*& vertexData, uint32_t& vertexDataSize, uint32_t*& indexData, uint32_t& indexDataLength,
92 aiMesh* meshToProcess, BufferLayout& buffLayout);
93
94 void ProcessNode(aiNode* nodeToProcess, const aiScene* theScene);
95
104 static void GaugeVertexDataLayout(aiMesh* meshToProcess, BufferLayout& buffLayout);
105
106 std::shared_ptr<VertexBuffer> GetVertexBuffer() const { return m_VertexBuffer; }
107 std::shared_ptr<IndexBuffer> GetIndexBuffer() const { return m_IndexBuffer; }
108
109 void SetVertexBuffer(std::shared_ptr<VertexBuffer> vBuffer) { m_VertexBuffer = vBuffer; }
110 void SetIndexBuffer(std::shared_ptr<IndexBuffer> iBuffer) { m_IndexBuffer = iBuffer; }
111
112 // Useful dictionary related functions
113 static float LayoutElementToAttributeValue(unsigned int vertexNumber, uint32_t counter, aiMesh* meshToProcess, const BufferElement& layoutElem);
114 static void InitializeAttributeDictionary();
115
116 protected:
117 std::shared_ptr<VertexBuffer> m_VertexBuffer;
118 std::shared_ptr<IndexBuffer> m_IndexBuffer;
119
120 std::string m_MeshName;
121 MeshType m_MeshType;
122
123 static std::shared_ptr<std::unordered_map<std::string, MeshAttribute>> m_NameToAttributeDictionary;
124
125 std::shared_ptr<class Material> m_StaticMaterial;
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:21
@ Mesh
Static mesh.
Definition Mesh.h:25
MeshAttribute
An enum for cherning data by interleaving the following attributes.
Definition Mesh.h:39
@ Tangents
Definition Mesh.h:45
@ Normals
Definition Mesh.h:43
@ Colors
Definition Mesh.h:49
@ Bitangents
Definition Mesh.h:47
@ TextureCoords
Definition Mesh.h:51
@ Vertices
Definition Mesh.h:41
@ AnimMeshes
Definition Mesh.h:53
A format for vertex buffer say.
Definition Buffer.h:181
An organized collection of vertex and index buffers along with rest of the model specific information...
Definition Mesh.h:61
static std::shared_ptr< Mesh > ProcessTheRawMesh(aiMesh *meshToProcess, const std::string &mName="NoName")
Generate a layout (BufferLayout) for the supplied mesh.
Definition Mesh.cpp:97
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:143
static void GaugeVertexDataLayout(aiMesh *meshToProcess, BufferLayout &buffLayout)
Routine for extracting the format (BufferLayout) of vertexbuffer.
Definition Mesh.cpp:199
SkeletalMesh class.
Definition SkeletalMesh.h:36
A datastructure for creating interleaved data for Mesh with a specifc format (BufferLayout).
Definition Buffer.h:84