AireEngine
A 3D Open-World Game Engine
Loading...
Searching...
No Matches
meshManager.h
1#pragma once
2#ifndef _meshManager_H_
3
4
5#include"matManager.h"
6#include <assimp/scene.h>
7#include"model.h"
8#include"mathHelper.h"
9#include "../utils/error.h"
10#include "../utils/log.h"
11
12namespace Aire
13{
14 using MeshPtr = shared_ptr<Mesh>;
15
16 using MeshHash = map<MeshHandle, MeshPtr>;
17
18 using ModelHash = map<ModelHandle, ModelPtr>;
19 using ModelNameHash = std::unordered_map<ModelHandle, ModelPtr>;
20
21 //the list of one hash
22 using MeshSoupHandle = unsigned int;
23
24 using MeshSoupHash = map<MeshSoupHandle, ModelData>;
25 using MeshSoupNameHash = std::unordered_map<std::string, ModelData>;
26
29 private:
30 MeshHash meshHash;
31 MeshHandle meshHandle;
32
33 ModelHash modelHash;
34 ModelHandle modelHandle;
35 ModelNameHash modelNameHash;
36
37
38 MeshSoupHash meshSoupHash;
39 MeshSoupNameHash meshSoupNameHash;
40 MeshSoupHandle meshSoupHandle;
41
42 MaterialManager& matManager = MaterialManager::get_instance();
44 std::string dir;
45
46 void processNode(aiNode* node, const aiScene* scene, std::vector<MeshPtr>&,BoneInfoMap& map, int& count, bool isflipped);
47 MeshPtr processMesh(aiMesh* mesh, const aiScene* scene, BoneInfoMap& map, int& count, bool isflipped);
48 MaterialPtr processMaterial(aiMaterial* material,bool isflipped);
49 std::string getPath(aiMaterial* mat, aiTextureType type);
50
51
52 public:
53 //singleton pattern
54 MeshManager(const MeshManager&) = delete;
55 MaterialManager& operator=(const MeshManager&) = delete;
56 static MeshManager& get_instance() {
57 static MeshManager instance;
58 return instance;
59 }
60
62
63 //NOTE: DO NOT call delete on returned pointer. The texture will be automatically deleted when the loader goes out of scope.
64
72 MeshHandle createMesh(std::vector<Vertex> vertices, std::vector<unsigned int> indices, MaterialPtr& handle);
73
79 ModelHandle createModel(const std::string& path, bool flippedUV = false);
80
83 void freeModelDataInCpu(const ModelHandle& handle);
84
87 void moveModelToGpu(const ModelHandle& );
88
91 void moveModelToGpu(const std::string&);
92
95 void moveMeshToGpu(const MeshHandle&);
96 //additional attribute maybe necesseary to add.
97
100 void RemoveMeshInGpu(const MeshHandle&);
101
104 void RemoveMoelInGpu(const ModelHandle&);
105
109 MeshPtr getMeshPtr(const MeshHandle& );
110
114 ModelPtr getModelPtr(const ModelHandle&);
115
119
124 void SetVertexBoneData(Vertex& vertex, int boneID, float weight);
125
132 void ExtractBoneWeightForVertices(std::vector<Vertex>& vertices, aiMesh* mesh, const aiScene* scene, BoneInfoMap& map, int& count);
133
134 };
135
136
137
138 inline MeshManager::MeshManager()
139 {
140 meshHandle = 0;
141 modelHandle = 0;
142
143 }
144
145}
146
147#endif // !_meshManager_H_
Material manager. Handles material creation, storage, and deletion.
Definition matManager.h:15
Mesh manager. Handles mesh creation, storage, and deletion.
Definition meshManager.h:28
void moveModelToGpu(const ModelHandle &)
Definition meshManager.cpp:89
void SetVertexBoneData(Vertex &vertex, int boneID, float weight)
Definition meshManager.cpp:228
void moveMeshToGpu(const MeshHandle &)
Definition meshManager.cpp:117
ModelPtr getModelPtr(const ModelHandle &)
Definition meshManager.cpp:213
MeshHandle createMesh(std::vector< Vertex > vertices, std::vector< unsigned int > indices, MaterialPtr &handle)
Definition meshManager.cpp:16
void ExtractBoneWeightForVertices(std::vector< Vertex > &vertices, aiMesh *mesh, const aiScene *scene, BoneInfoMap &map, int &count)
Definition meshManager.cpp:241
void freeModelDataInCpu(const ModelHandle &handle)
Definition meshManager.cpp:67
void RemoveMeshInGpu(const MeshHandle &)
Definition meshManager.cpp:177
void RemoveMoelInGpu(const ModelHandle &)
Definition meshManager.cpp:195
void SetVertexBoneDataToDefault(Vertex &vertex)
Definition meshManager.cpp:219
MeshPtr getMeshPtr(const MeshHandle &)
Definition meshManager.cpp:207
ModelHandle createModel(const std::string &path, bool flippedUV=false)
Definition meshManager.cpp:27
Definition mesh.h:23