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 {
24 Mesh = 0,
25 SkeletalMesh
26 };
27
50
55 class KARMA_API Mesh
56 {
57 public:
58 Mesh(std::shared_ptr<VertexBuffer> vertexBuffer, std::shared_ptr<IndexBuffer> indexBuffer, const std::string& meshName = "NoName",
59 MeshType mType = MeshType::Mesh);
60 Mesh(const std::string& filePath);
61
62 virtual void ProcessMesh(aiMesh* meshToProcess);
63
72 static std::shared_ptr<Mesh> ProcessTheRawMesh(aiMesh* meshToProcess, const std::string& mName = "NoName");
73
86 static void DealVertexIndexBufferData(float*& vertexData, uint32_t& vertexDataSize, uint32_t*& indexData, uint32_t& indexDataLength,
87 aiMesh* meshToProcess, BufferLayout& buffLayout);
88
89 void ProcessNode(aiNode* nodeToProcess, const aiScene* theScene);
90
99 static void GaugeVertexDataLayout(aiMesh* meshToProcess, BufferLayout& buffLayout);
100
101 std::shared_ptr<VertexBuffer> GetVertexBuffer() const { return m_VertexBuffer; }
102 std::shared_ptr<IndexBuffer> GetIndexBuffer() const { return m_IndexBuffer; }
103
104 void SetVertexBuffer(std::shared_ptr<VertexBuffer> vBuffer) { m_VertexBuffer = vBuffer; }
105 void SetIndexBuffer(std::shared_ptr<IndexBuffer> iBuffer) { m_IndexBuffer = iBuffer; }
106
107 // Useful dictionary related functions
108 static float LayoutElementToAttributeValue(unsigned int vertexNumber, uint32_t counter, aiMesh* meshToProcess, const BufferElement& layoutElem);
109 static void InitializeAttributeDictionary();
110
111 protected:
112 std::shared_ptr<VertexBuffer> m_VertexBuffer;
113 std::shared_ptr<IndexBuffer> m_IndexBuffer;
114
115 std::string m_MeshName;
116 MeshType m_MeshType;
117
118 static std::shared_ptr<std::unordered_map<std::string, MeshAttribute>> m_NameToAttributeDictionary;
119 };
120}
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
MeshAttribute
An enum for cherning data by interleaving the following attributes.
Definition Mesh.h:34
@ Tangents
Definition Mesh.h:40
@ Normals
Definition Mesh.h:38
@ Colors
Definition Mesh.h:44
@ Bitangents
Definition Mesh.h:42
@ TextureCoords
Definition Mesh.h:46
@ Vertices
Definition Mesh.h:36
@ AnimMeshes
Definition Mesh.h:48
A format for vertex buffer say.
Definition Buffer.h:183
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
A datastructure for creating interleaved data for Mesh with a specifc format (BufferLayout)
Definition Buffer.h:86