Mesh.hpp
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #include <etk/types.hpp>
9 #include <etk/Hash.hpp>
10 #include <gale/resource/Resource.hpp>
11 #include <ewol/resource/Image.hpp>
12 #include <gale/resource/Shader.hpp>
13 #include <gale/resource/Program.hpp>
14 #include <gale/resource/VirtualBufferObject.hpp>
15 #include <ege/Light.hpp>
16 #include <ege/Material.hpp>
19 
21 // VBO table property:
22 #define MESH_VBO_VERTICES (0)
23 #define MESH_VBO_TEXTURE (1)
24 #define MESH_VBO_VERTICES_NORMAL (2)
25 #define MESH_VBO_FACE_NORMAL (3)
26 #define MESH_VBO_COLOR (4)
27 
28 namespace ege {
29  namespace resource {
30  class Mesh : public gale::Resource {
31  public:
32  static ememory::SharedPtr<ege::resource::Mesh> createGrid(int32_t _lineCount,
33  const vec3& _position=vec3(0,0,0),
34  float _size=1.0f,
35  const std::string& _materialName="basics");
36  static ememory::SharedPtr<ege::resource::Mesh> createCube(float _size=1.0f,
37  const std::string& _materialName="basics",
38  const etk::Color<float>& _color=etk::color::white);
39  public:
43  enum normalMode {
44  normalModeNone,
45  normalModeFace,
46  normalModeVertex,
47  };
48  protected:
49  enum normalMode m_normalMode; // select the normal mode of display
51  protected:
53  int32_t m_GLPosition;
54  int32_t m_GLMatrix;
55  int32_t m_GLMatrixPosition;
56  int32_t m_GLNormal;
57  int32_t m_GLtexture;
58  int32_t m_GLColor;
59  int32_t m_bufferOfset;
60  int32_t m_numberOfElments;
61  MaterialGlId m_GLMaterial;
62  ege::Light m_light;
63  protected:
64  std::vector<vec3> m_listVertex;
65  std::vector<vec2> m_listUV;
66  std::vector<etk::Color<float>> m_listColor;
67  std::vector<vec3> m_listFacesNormal;
68  std::vector<vec3> m_listVertexNormal;
71  std::vector<ememory::SharedPtr<ege::PhysicsShape>> m_physics;
72  void clean();
73  protected:
75  protected:
76  Mesh();
77  void init(const std::string& _fileName="---", const std::string& _shaderName="DATA:textured3D2.prog");
78  public:
79  virtual ~Mesh();
80  DECLARE_RESOURCE_NAMED_FACTORY(Mesh);
81  public:
82  virtual void draw(mat4& _positionMatrix, bool _enableDepthTest=true, bool _enableDepthUpdate=true);
83  virtual void draw(mat4& _positionMatrix,
84  const etk::Color<float>& _mainColor,
85  bool _enableDepthTest = true,
86  bool _enableDepthUpdate = true) {
87  draw(_positionMatrix, _enableDepthTest, _enableDepthUpdate);
88  }
89  void generateVBO();
90  private:
91  void calculateNormaleFace(const std::string& _materialName);
92  void calculateNormaleEdge(const std::string& _materialName);
93  public :
94  void createViewBox(const std::string& _materialName,float _size=1.0);
95  void createIcoSphere(const std::string& _materialName,float _size=1.0, int32_t _subdivision=3);
96  private:
97  bool loadOBJ(const std::string& _fileName);
98  bool loadEMF(const std::string& _fileName);
99  public:
100  void addMaterial(const std::string& _name, ememory::SharedPtr<ege::Material> _data);
101  public:
106  void setCheckNormal(bool _status) {
107  m_checkNormal=_status;
108  };
113  bool getCheckNormal() {
114  return m_checkNormal;
115  };
116  const std::vector<ememory::SharedPtr<ege::PhysicsShape>>& getPhysicalProperties() const {
117  return m_physics;
118  };
119  void addPhysicElement(const ememory::SharedPtr<ege::PhysicsShape>& _shape) {
120  m_physics.push_back(_shape);
121  }
122  private:
123  void* m_pointerShape;
124  public:
129  void setShape(void* _shape);
134  void* getShape() {
135  return m_pointerShape;
136  };
137  private:
138  void (*m_functionFreeShape)(void* _pointer);
139  public:
140  void setFreeShapeFunction(void (*_functionFreeShape)(void* _pointer)) {
141  m_functionFreeShape = _functionFreeShape;
142  };
147  void addFaceIndexing(const std::string& _layerName);
148  public:
149 
150  void addPoint(const std::string& _layerName, const vec3& _pos, const etk::Color<float>& _color);
151 
152  void addLine(const std::string& _layerName, const vec3& _pos1, const vec3& _pos2, const etk::Color<float>& _color) {
153  addLine( _layerName, _pos1, _pos2, _color, _color);
154  }
155  void addLine(const std::string& _layerName, const vec3& _pos1, const vec3& _pos2, const etk::Color<float>& _color1, const etk::Color<float>& _color2);
156  void addLines(const std::string& _layerName, const std::vector<vec3>& _list, const etk::Color<float>& _color);
157  void addLines(const std::string& _layerName, const std::vector<vec3>& _list, const std::vector<etk::Color<float>>& _color);
158 
170  void addTriangle(const std::string& _layerName, const vec3& _pos1, const vec3& _pos2, const vec3& _pos3, const etk::Color<float>& _color) {
171  addTriangle(_layerName, _pos1, _pos2, _pos3, _color, _color, _color);
172  }
184  void addTriangle(const std::string& _layerName, const vec3& _pos1, const vec3& _pos2, const vec3& _pos3,
185  const etk::Color<float>& _color1, const etk::Color<float>& _color2, const etk::Color<float>& _color3);
196  void addQuad(const std::string& _layerName, const vec3& _pos1, const vec3& _pos2, const vec3& _pos3, const vec3& _pos4, const etk::Color<float>& _color) {
197  addQuad(_layerName, _pos1, _pos2, _pos3, _pos4, _color, _color, _color, _color);
198  }
212  void addQuad(const std::string& _layerName, const vec3& _pos1, const vec3& _pos2, const vec3& _pos3, const vec3& _pos4,
213  const etk::Color<float>& _color1, const etk::Color<float>& _color2, const etk::Color<float>& _color3, const etk::Color<float>& _color4) {
214  addTriangle(_layerName, _pos1, _pos2, _pos3, _color1, _color2, _color3);
215  addTriangle(_layerName, _pos1, _pos3, _pos4, _color1, _color3, _color4);
216  }
229  void addTriangle(const std::string& _layerName,
230  const vec3& _pos1, const vec3& _pos2, const vec3& _pos3,
231  const vec2& _uv1, const vec2& _uv2, const vec2& _uv3,
232  const etk::Color<float>& _color) {
233  addTriangle(_layerName, _pos1, _pos2, _pos3, _uv1, _uv2, _uv3, _color, _color, _color);
234  }
249  void addTriangle(const std::string& _layerName,
250  const vec3& _pos1, const vec3& _pos2, const vec3& _pos3,
251  const vec2& _uv1, const vec2& _uv2, const vec2& _uv3,
267  void addQuad(const std::string& _layerName,
268  const vec3& _pos1, const vec3& _pos2, const vec3& _pos3, const vec3& _pos4,
269  const vec2& _uv1, const vec2& _uv2, const vec2& _uv3, const vec2& _uv4,
270  const etk::Color<float>& _color) {
271  addQuad(_layerName, _pos1, _pos2, _pos3, _pos4, _uv1, _uv2, _uv3, _uv4, _color, _color, _color, _color);
272  }
290  void addQuad(const std::string& _layerName,
291  const vec3& _pos1, const vec3& _pos2, const vec3& _pos3, const vec3& _pos4,
292  const vec2& _uv1, const vec2& _uv2, const vec2& _uv3, const vec2& _uv4,
294  addTriangle(_layerName, _pos1, _pos2, _pos3, _uv1, _uv2, _uv3, _color1, _color2, _color3);
295  addTriangle(_layerName, _pos1, _pos3, _pos4, _uv1, _uv3, _uv4, _color1, _color3, _color4);
296  }
297  protected:
298  int32_t findPositionInList(const vec3& _pos);
299  int32_t findTextureInList(const vec2& _uv);
300  int32_t findColorInList(const etk::Color<float>& _color);
301  };
302  }
303 }
304 
Definition: Mesh.hpp:30
void setCheckNormal(bool _status)
set the check of normal position befor sending it to the openGl card
Definition: Mesh.hpp:106
std::vector< etk::Color< float > > m_listColor
List of all Color point in the mesh.
Definition: Mesh.hpp:66
void addQuad(const std::string &_layerName, const vec3 &_pos1, const vec3 &_pos2, const vec3 &_pos3, const vec3 &_pos4, const vec2 &_uv1, const vec2 &_uv2, const vec2 &_uv3, const vec2 &_uv4, const etk::Color< float > &_color1=etk::color::white, const etk::Color< float > &_color2=etk::color::white, const etk::Color< float > &_color3=etk::color::white, const etk::Color< float > &_color4=etk::color::white)
draw a textured quad (usefull for debug and test)
Definition: Mesh.hpp:290
void addQuad(const std::string &_layerName, const vec3 &_pos1, const vec3 &_pos2, const vec3 &_pos3, const vec3 &_pos4, const etk::Color< float > &_color1, const etk::Color< float > &_color2, const etk::Color< float > &_color3, const etk::Color< float > &_color4)
draw a colored quad (usefull for debug and test)
Definition: Mesh.hpp:212
normalMode
Definition: Mesh.hpp:43
Definition: Light.hpp:14
etk::Hash< FaceIndexing > m_listFaces
List of all Face for the mesh.
Definition: Mesh.hpp:69
std::vector< ememory::SharedPtr< ege::PhysicsShape > > m_physics
collision shape module ... (independent of bullet lib)
Definition: Mesh.hpp:71
bool m_checkNormal
when enable, this check the normal of the mesh before sending it at the 3d card
Definition: Mesh.hpp:50
Definition: AudioElement.hpp:8
Definition: Material.hpp:18
void addTriangle(const std::string &_layerName, const vec3 &_pos1, const vec3 &_pos2, const vec3 &_pos3, const vec2 &_uv1, const vec2 &_uv2, const vec2 &_uv3, const etk::Color< float > &_color)
draw a textured colored triangle (usefull for debug and test)
Definition: Mesh.hpp:229
std::vector< vec3 > m_listVertex
List of all vertex in the element.
Definition: Mesh.hpp:64
void addQuad(const std::string &_layerName, const vec3 &_pos1, const vec3 &_pos2, const vec3 &_pos3, const vec3 &_pos4, const vec2 &_uv1, const vec2 &_uv2, const vec2 &_uv3, const vec2 &_uv4, const etk::Color< float > &_color)
draw a textured colored quad (usefull for debug and test)
Definition: Mesh.hpp:267
void * getShape()
get the pointer on the shame (no type)
Definition: Mesh.hpp:134
std::vector< vec3 > m_listFacesNormal
List of all Face normal, when calculated.
Definition: Mesh.hpp:67
std::vector< vec3 > m_listVertexNormal
List of all Face normal, when calculated.
Definition: Mesh.hpp:68
void addFaceIndexing(const std::string &_layerName)
Add in the faces list the layer requested.
std::vector< vec2 > m_listUV
List of all UV point in the mesh (for the specify texture)
Definition: Mesh.hpp:65
void addTriangle(const std::string &_layerName, const vec3 &_pos1, const vec3 &_pos2, const vec3 &_pos3, const etk::Color< float > &_color)
draw a colored triangle (usefull for debug and test)
Definition: Mesh.hpp:170
void addQuad(const std::string &_layerName, const vec3 &_pos1, const vec3 &_pos2, const vec3 &_pos3, const vec3 &_pos4, const etk::Color< float > &_color)
draw a colored quad (usefull for debug and test)
Definition: Mesh.hpp:196
bool getCheckNormal()
get the check value of normal position befor sending it to the openGl card
Definition: Mesh.hpp:113
const Color white
void setShape(void *_shape)
set the shape pointer (no type == > user might know it ...)