Bubba-3D  0.9.0
Awesome game engine!
Mesh.h
1 /*
2  * This file is part of Bubba-3D.
3  *
4  * Bubba-3D is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * Bubba-3D is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with Bubba-3D. If not, see http://www.gnu.org/licenses/.
16  */
17 #pragma once
18 
19 #include <string>
20 #include <vector>
21 #include "linmath/float3.h"
22 #include "Material.h"
23 #include "AABB2.h"
24 #include "assimp/material.h"
25 #include <Sphere.h>
26 #include <assimp/scene.h>
27 #include <map>
28 #include <assimp/Importer.hpp>
29 #include <memory>
30 
31 
32 class BoneTransformer;
33 class Triangle;
34 class Chunk;
36 
45 class Mesh {
46 public:
47  Mesh();
48 
49  ~Mesh() = default;
50 
51  void loadMesh(const std::string &fileName);
52 
58  std::vector<Triangle *> getTriangles();
59 
65  AABB* getAABB();
66 
72  Sphere getSphere();
73 
74  std::vector<Chunk>* getChunks();
75  std::vector<Material>* getMaterials();
76 
77  bool hasAnimations();
78 
86  std::vector<chag::float4x4> getBoneTransforms(float totalElapsedTimeInSeconds);
87 
88 private:
96  void initMesh(const aiScene *pScene, const std::string &fileNameOfMesh);
97  void initMeshFromAiMesh(unsigned int index, const aiMesh *paiMesh);
98  void initChunkFromAiMesh(const aiMesh *paiMesh, Chunk &chunk);
99  void initVerticesFromAiMesh(const aiMesh *paiMesh, Chunk &chunk);
100  void initIndicesFromAiMesh(const aiMesh *paiMesh, Chunk &chunk);
101 
102  void initBonesFromAiMesh(const aiMesh *paiMesh, Chunk &bones);
103  void assertAllVertexWeightsSumToOne(Chunk &chunk);
104 
105 
112  void initMaterials(const aiScene *pScene, const std::string &fileNameOfMesh);
113  void initMaterialTextures(Material *material, std::string fileNameOfMesh,
114  const aiMaterial *loadedMaterial);
115  void initMaterialColors(Material *material, const aiMaterial *loadedMaterial);
116  void initMaterialShininess(Material *material, const aiMaterial *loadedMaterial);
117 
128  chag::float3 getColorFromMaterial(const char* colorTypeString, unsigned int type,
129  unsigned int index, const aiMaterial &material);
130 
138  std::string getPathOfTexture(const std::string &fileNameOfMesh,
139  std::string textureName);
140 
144  std::string getDirectoryFromPath(const std::string &fileName);
145 
151  std::string cleanFileName(std::string filePath);
152 
163  Texture* getTexture(const aiMaterial *material, const std::string &fileNameOfMesh,
164  aiTextureType type);
165 
170  void setupChunkForRendering(Chunk &chunk);
171 
172  void setupSphere(std::vector<chag::float3> *positions);
173 
174  void createTriangles();
175  Triangle* createTriangleFromPositions(std::vector<chag::float3> positionBuffer,
176  std::vector<unsigned int> indices,
177  unsigned int startIndex);
178 
179  std::vector<Triangle *> triangles;
180  std::vector<Material> materials;
181  std::vector<Chunk> m_chunks;
182 
183  std::shared_ptr<BoneTransformer> boneTransformer;
184  Assimp::Importer importer;
185 
186  Sphere sphere;
187  AABB m_aabb;
188 
189  unsigned int numAnimations;
190 
191 };
Sphere getSphere()
Definition: Mesh.cpp:238
std::vector< Triangle * > getTriangles()
Definition: Mesh.cpp:325
std::vector< chag::float4x4 > getBoneTransforms(float totalElapsedTimeInSeconds)
Definition: Mesh.cpp:341
Definition: Mesh.h:45
Definition: Chunk.h:27
Struct for maintaining information of how a bone affects a vertex.
Definition: Sphere.h:19
Definition: AABB2.h:23
AABB * getAABB()
Definition: Mesh.cpp:299