Face3d
Model.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 // Common
4 #include <vector>
5 #include <string>
6 #include <memory>
7 #include <map>
8 // Assimp
9 #include <assimp/Importer.hpp> // C++ importer interface
10 #include <assimp/scene.h> // Output data structure
11 #include <assimp/postprocess.h> // Post processing flags
12 // Helpers
13 #include "FaceCoordinates3d.hpp"
14 #include "GLHeader.hpp"
15 
16 
17 
18 namespace Face3D
19 {
21  template<class T>
22  bool isInsideEpsBall(const T& a, const T& b)
23  {
24  return glm::distance(a, b) < 0.01;
25  }
26 
27 
29  struct Vertex
30  {
31  glm::vec4 position;
32  glm::vec4 normal;
33  };
34 
36  class Mesh
37  {
38  public:
39  Mesh(const std::vector<Vertex>& vertices, const std::vector<GLuint>& indices);
40  void render();
41 
42  private:
43  std::vector<Vertex> m_Vertices;
44  std::vector<GLuint> m_Indices;
45  GLuint m_VaoID=0, m_VboID=0, m_EboID=0;
46 
47  void setup();
48  };
49 
51  class Model
52  {
53  public:
54 
56  struct ModelInfo
57  {
58  std::string modelPath;
59  std::string textureFront;
60  std::string textureSide;
61 
62  glm::vec3 modelDimension;
63 
65  glm::vec3 leftEye, rightEye, mouth, nose, chin;
66 
68  std::vector<glm::vec3> allMouthVertices, allNoseVertices, allLeftEyeVertices, allRightEyeVertices;
69 
70  };
71 
72  Model(const ModelInfo& modelInfo);
73  void rotate(GLfloat val){ m_RotationAngle = val; }
74  void scale(GLfloat val){ m_ScaleVal = val; }
75  void render();
76 
77 
78  private:
81 
82  GLuint m_TextureFrontID = 0;
83  GLuint m_TextureSideID = 0;
84  GLuint m_SamplerID = 0;
85  std::shared_ptr<std::vector<Mesh>> m_pMeshes;
86  GLuint m_ShaderID=0;
87  GLuint m_MVPMatrixLocation = 0;
88  GLuint m_TextureFrontSamplerLocation = 0;
89  GLuint m_TextureSideSamplerLocation = 0;
90  GLuint m_ChinVerticalPosLocation = 0;
91  GLuint m_EyeVerticalPosLocation = 0;
92  GLuint m_LEyeTexVerticalPosLocation = 0;
93  GLuint m_REyeTexVerticalPosLocation = 0;
94  GLuint m_ChinTexVerticalPosLocation = 0;
95  glm::mat4 m_MVPMatrix;
96  GLfloat m_RotationAngle = 0.0f;
97  GLfloat m_ScaleVal = 1.0f;
98  GLfloat m_fx=0, m_fy=0, m_fz=0;
99 
101  void load(const std::string& path);
102  void processNode(aiNode *node, const aiScene *scene);
103  Mesh processMesh(aiMesh *mesh, const aiScene *scene, std::string name);
104 
106  void calcScalingFactors();
107 
109  glm::vec3 moveGenericVertex(const glm::vec3& genericVertex);
110  };
111 }
std::string modelPath
Definition: Model.hpp:58
glm::vec4 normal
Definition: Model.hpp:32
glm::vec3 modelDimension
Definition: Model.hpp:62
std::vector< glm::vec3 > allRightEyeVertices
Definition: Model.hpp:68
FaceCoordinates3d m_FaceCoords
Definition: Model.hpp:80
void rotate(GLfloat val)
Definition: Model.hpp:73
void scale(GLfloat val)
Definition: Model.hpp:74
std::string textureFront
Definition: Model.hpp:59
Definition: Model.hpp:51
std::vector< GLuint > m_Indices
Definition: Model.hpp:44
glm::vec4 position
Definition: Model.hpp:31
ModelInfo m_ModelInfo
Definition: Model.hpp:79
Definition: Model.hpp:36
std::string textureSide
Definition: Model.hpp:60
glm::vec3 rightEye
Definition: Model.hpp:65
std::vector< Vertex > m_Vertices
Definition: Model.hpp:43
Definition: Model.hpp:29
Definition: Model.hpp:56
bool isInsideEpsBall(const T &a, const T &b)
Definition: Model.hpp:22
Definition: Common.hpp:7
glm::mat4 m_MVPMatrix
Definition: Model.hpp:95
std::shared_ptr< std::vector< Mesh > > m_pMeshes
Definition: Model.hpp:85
Definition: FaceCoordinates3d.hpp:9