Neo  0.5.0
Developer Documentation
Mesh.h
Go to the documentation of this file.
1 //========================================================================
2 // Copyright (c) 2003-2011 Anael Seghezzi <www.maratis3d.com>
3 // Copyright (c) 2014-2015 Yannick Pflanzer <www.neo-engine.de>
4 //
5 // This software is provided 'as-is', without any express or implied
6 // warranty. In no event will the authors be held liable for any damages
7 // arising from the use of this software.
8 //
9 // Permission is granted to anyone to use this software for any purpose,
10 // including commercial applications, and to alter it and redistribute it
11 // freely, subject to the following restrictions:
12 //
13 // 1. The origin of this software must not be misrepresented; you must not
14 // claim that you wrote the original software. If you use this software
15 // in a product, an acknowledgment in the product documentation would
16 // be appreciated but is not required.
17 //
18 // 2. Altered source versions must be plainly marked as such, and must not
19 // be misrepresented as being the original software.
20 //
21 // 3. This notice may not be removed or altered from any source
22 // distribution.
23 //
24 //========================================================================
25 
26 #ifndef __MESH_H
27 #define __MESH_H
28 
29 #include "MorphingData.h"
30 #include "SkinData.h"
31 
32 namespace Neo
33 {
34 // Display
35 class NEO_ENGINE_EXPORT MaterialDisplay
36 {
37 public:
38  MaterialDisplay(PRIMITIVE_TYPES primitiveType, unsigned int begin,
39  unsigned int size);
40 
41  MaterialDisplay(const MaterialDisplay &display);
42  ~MaterialDisplay(void);
43 
44 private:
45  // draw array infos
46  PRIMITIVE_TYPES m_primitiveType;
47  unsigned int m_begin;
48  unsigned int m_size;
49 
50  // cull mode
51  CULL_MODES m_cullMode;
52 
53  // material
54  Material *m_material;
55  unsigned int m_materialId;
56 
57  // visibility
58  bool m_visibility;
59 
60  unsigned int m_vao;
61 
62 public:
63  // array infos
64  inline PRIMITIVE_TYPES getPrimitiveType(void) { return m_primitiveType; }
65  inline unsigned int getBegin(void) { return m_begin; }
66  inline unsigned int getSize(void) { return m_size; }
67 
68  // cull mode
69  inline void setCullMode(CULL_MODES cullMode) { m_cullMode = cullMode; }
70  inline CULL_MODES getCullMode(void) { return m_cullMode; }
71 
72  // material
73  inline void setMaterial(Material *material) { m_material = material; }
74  inline Material *getMaterial(void) { return m_material; }
75 
76  // visibility
77  inline void setVisibility(bool visibility) { m_visibility = visibility; }
78  inline bool isVisible(void) { return m_visibility; }
79 
80  inline unsigned int* getVAO() { return &m_vao; }
81 
82  void setMaterialId(unsigned int id) { m_materialId = id; }
83  unsigned int getMaterialId() { return m_materialId; }
84 };
85 
86 // SubMesh
87 class NEO_ENGINE_EXPORT SubMesh
88 {
89 public:
90  SubMesh(void);
91  ~SubMesh(void);
92 
93 private:
94  // morphing data
95  MorphingData *m_morphingData;
96 
97  // skin data
98  SkinData *m_skinData;
99 
100  // data
101  unsigned int m_indicesSize;
102  unsigned int m_verticesSize;
103  unsigned int m_normalsSize;
104  unsigned int m_tangentsSize;
105  unsigned int m_texCoordsSize;
106  unsigned int m_colorsSize;
107 
108  VAR_TYPES m_indicesType;
109  void* m_indices;
110 
111  Color* m_colors;
112  Vector3* m_vertices;
113  Vector3* m_normals;
114  Vector3* m_tangents;
115  Vector2* m_texCoords;
116 
117  Vector3* m_skinVertices;
118  Vector3* m_skinNormals;
119  Vector3* m_skinTangents;
120 
121  // VBO (optional)
122  unsigned int m_vboId1;
123  unsigned int m_vboId2; // for indices
124 
125  // mapChannels offset (map of textureCoords offsets used for channel
126  // mapping)
127  map<unsigned int, unsigned int> m_mapChannelsOffset;
128 
129  // displays
130  unsigned int m_displaysNumber;
131  MaterialDisplay **m_displays;
132 
133  // bounding box
134  Box3d m_boundingBox;
135 
136 public:
137  // morphing data
138  void clearMorphingData(void);
139  MorphingData *createMorphingData(void);
140  inline MorphingData *getMorphingData(void) { return m_morphingData; }
141 
142  // skin data
143  void clearSkinData(void);
144  SkinData *createSkinData(void);
145  inline SkinData *getSkinData(void) { return m_skinData; }
146 
147  // data
148  void clearIndices(void);
149  void clearVertices(void);
150  void clearNormals(void);
151  void clearTangents(void);
152  void clearTexCoords(void);
153  void clearColors(void);
154 
155  void *allocIndices(unsigned int size, VAR_TYPES type);
156  Color *allocColors(unsigned int size);
157  Vector3 *allocVertices(unsigned int size);
158  Vector3 *allocNormals(unsigned int size);
159  Vector3 *allocTangents(unsigned int size);
160  Vector2 *allocTexCoords(unsigned int size);
161 
162  inline unsigned int getIndicesSize(void) { return m_indicesSize; }
163  inline unsigned int getVerticesSize(void) { return m_verticesSize; }
164  inline unsigned int getNormalsSize(void) { return m_normalsSize; }
165  inline unsigned int getTangentsSize(void) { return m_tangentsSize; }
166  inline unsigned int getTexCoordsSize(void) { return m_texCoordsSize; }
167  inline unsigned int getColorsSize(void) { return m_colorsSize; }
168 
169  VAR_TYPES getIndicesType(void) { return m_indicesType; }
170  inline void *getIndices(void) { return m_indices; }
171 
172  inline Color *getColors(void) { return m_colors; }
173  inline Vector3 *getVertices(void) { return m_vertices; }
174  inline Vector3 *getNormals(void) { return m_normals; }
175  inline Vector3 *getTangents(void) { return m_tangents; }
176  inline Vector2 *getTexCoords(void) { return m_texCoords; }
177 
178  inline Vector3 *getSkinVertices(void) { return m_skinVertices; }
179  inline Vector3 *getSkinNormals(void) { return m_skinNormals; }
180  inline Vector3 *getSkinTangents(void) { return m_skinTangents; }
181 
182  Vector3* getVertex(size_t idx) { return m_vertices + idx; }
183  unsigned int getIndex(size_t idx) { return (m_indicesType == VAR_UINT) ?
184  *(((unsigned int*) m_indices) + idx)
185  : *(((unsigned short*) m_indices) + idx); }
186 
187  // VBO
188  void clearVBO(void);
189  unsigned int *getVBOid1(void) { return &m_vboId1; }
190  unsigned int *getVBOid2(void) { return &m_vboId2; }
191 
192  // mapChannels offset
193  void clearMapChannelOffset(void);
194  void setMapChannelOffset(unsigned int channel, unsigned int offset);
195  bool isMapChannelExist(unsigned int channel);
196  unsigned int getMapChannelOffset(unsigned int channel);
197 
198  map<unsigned int, unsigned int> *getMapChannelOffsets(void)
199  {
200  return &m_mapChannelsOffset;
201  }
202 
203  // displays
204  void allocDisplays(unsigned int size);
205  void clearDisplays(void);
206  MaterialDisplay *addNewDisplay(PRIMITIVE_TYPES primitiveType,
207  unsigned int begin, unsigned int size);
208 
209  inline unsigned int getDisplaysNumber(void) { return m_displaysNumber; }
210 
211  inline MaterialDisplay *getDisplay(unsigned int id)
212  {
213  return m_displays[id];
214  }
215 
216  // bounding box
217  inline Box3d *getBoundingBox(void) { return &m_boundingBox; }
218 
219  // transparency
220  bool hasTransparency(void);
221 };
222 
227 class NEO_ENGINE_EXPORT AnimRange : public Range
228 {
229 public:
230  AnimRange(void) : loops(-1) {}
231 
233  int loops;
234 };
235 
241 class NEO_ENGINE_EXPORT Mesh
242 {
243 public:
244 
245  Mesh(void);
246  ~Mesh(void);
247 
255  static Mesh * getNew(void);
256 
260  void destroy(void);
261 
262 private:
263 
264  // anims ranges
265  unsigned int m_animsRangesNumber;
266  AnimRange * m_animsRanges;
267 
268  // armature anim
269  ArmatureAnimRef * m_armatureAnimRef;
270 
271  // textures anim
272  TexturesAnimRef * m_texturesAnimRef;
273 
274  // materials anim
275  MaterialsAnimRef * m_materialsAnimRef;
276 
277  // armature
278  Armature * m_armature;
279 
280  // textures
281  unsigned int m_texturesNumber;
282  Texture ** m_textures;
283 
284  // materials
285  unsigned int m_materialsNumber;
286  Material ** m_materials;
287 
288  // subMeshs
289  unsigned int m_subMeshsNumber;
290  SubMesh * m_subMeshs;
291 
292  // bounding box
293  Box3d m_boundingBox;
294 
295 public:
296 
297  // clear
298  void clear(void);
299 
300  // anims ranges
301  void clearAnimsRanges(void);
302  AnimRange *allocAnimsRanges(unsigned int size);
303 
308  inline unsigned int getAnimsRangesNumber(void)
309  {
310  return m_animsRangesNumber;
311  }
312 
317  inline AnimRange *getAnimsRanges(void) { return m_animsRanges; }
318 
325  inline void setArmatureAnimRef(ArmatureAnimRef *armatureAnimRef)
326  {
327  m_armatureAnimRef = armatureAnimRef;
328  }
329 
336  {
337  return m_armatureAnimRef;
338  }
339 
340  ArmatureAnim *getArmatureAnim(void);
341 
342  // textures anim
343  inline void setTexturesAnimRef(TexturesAnimRef *texturesAnimRef)
344  {
345  m_texturesAnimRef = texturesAnimRef;
346  }
348  {
349  return m_texturesAnimRef;
350  }
351 
352  TexturesAnim *getTexturesAnim(void);
353 
360  inline void setMaterialsAnimRef(MaterialsAnimRef *materialsAnimRef)
361  {
362  m_materialsAnimRef = materialsAnimRef;
363  }
364 
371  {
372  return m_materialsAnimRef;
373  }
374 
375  MaterialsAnim *getMaterialsAnim(void);
376 
377  // armature
378  void clearArmature(void);
379  Armature *createArmature(void);
380  inline Armature *getArmature(void) { return m_armature; }
381 
382  // textures
383  void allocTextures(unsigned int size);
384  void clearTextures(void);
385  Texture *addNewTexture(TextureRef *texRef);
386  inline unsigned int getTexturesNumber(void) { return m_texturesNumber; }
387  inline Texture *getTexture(unsigned int id) { return m_textures[id]; }
388 
393  void allocMaterials(unsigned int size);
394 
398  void clearMaterials(void);
399 
405  Material *addNewMaterial(void);
406 
411  inline unsigned int getMaterialsNumber(void) { return m_materialsNumber; }
412 
418  inline Material *getMaterial(unsigned int id) { return m_materials[id]; }
419 
420  void clearSubMeshs(void);
421  SubMesh *allocSubMeshs(unsigned int size);
422  inline unsigned int getSubMeshsNumber(void) { return m_subMeshsNumber; }
423  inline SubMesh *getSubMeshs(void) { return m_subMeshs; }
424 
425  SubMesh* getSubMesh(size_t idx) { return &m_subMeshs[idx]; }
426 
431  void updateBoundingBox(void);
432 
438  inline Box3d *getBoundingBox(void) { return &m_boundingBox; }
439 };
440 }
441 #endif
map< unsigned int, unsigned int > * getMapChannelOffsets(void)
Definition: Mesh.h:198
Definition: SkinData.h:66
PRIMITIVE_TYPES
Definition: RenderingContext.h:64
Definition: Texture.h:31
Vector3 * getVertices(void)
Definition: Mesh.h:173
VAR_TYPES getIndicesType(void)
Definition: Mesh.h:169
void * getIndices(void)
Definition: Mesh.h:170
unsigned int getTangentsSize(void)
Definition: Mesh.h:165
unsigned int * getVAO()
Definition: Mesh.h:80
bool isVisible(void)
Definition: Mesh.h:78
Vector2 * getTexCoords(void)
Definition: Mesh.h:176
MaterialDisplay * getDisplay(unsigned int id)
Definition: Mesh.h:211
Definition: Vector3.h:31
Definition: MaterialsAnim.h:31
unsigned int * getVBOid2(void)
Definition: Mesh.h:190
Definition: MorphingData.h:82
Color * getColors(void)
Definition: Mesh.h:172
CULL_MODES
Definition: RenderingContext.h:131
Definition: Armature.h:32
Definition: TexturesAnim.h:31
Definition: MaterialsAnimRef.h:32
unsigned int getIndex(size_t idx)
Definition: Mesh.h:183
The Material class contains the implementation of a material used by 3D meshes for rendering differen...
Definition: Material.h:118
Definition: ArmatureAnimRef.h:32
unsigned int getColorsSize(void)
Definition: Mesh.h:167
Implements a range data structure.
Definition: Maths.h:76
int loops
How should the animation loop.
Definition: Mesh.h:233
Vector3 * getSkinNormals(void)
Definition: Mesh.h:179
void setVisibility(bool visibility)
Definition: Mesh.h:77
Definition: Box3d.h:31
unsigned int getAnimsRangesNumber(void)
Returns the number of animation ranges.
Definition: Mesh.h:308
unsigned int getBegin(void)
Definition: Mesh.h:65
Definition: RenderingContext.h:148
void setCullMode(CULL_MODES cullMode)
Definition: Mesh.h:69
Vector3 * getNormals(void)
Definition: Mesh.h:174
ArmatureAnimRef * getArmatureAnimRef(void)
Returns the current armature animation reference.
Definition: Mesh.h:335
Vector3 * getVertex(size_t idx)
Definition: Mesh.h:182
void setMaterial(Material *material)
Definition: Mesh.h:73
unsigned int getMaterialsNumber(void)
Returns the number of currently active materials.
Definition: Mesh.h:411
unsigned int getTexCoordsSize(void)
Definition: Mesh.h:166
Box3d * getBoundingBox(void)
Definition: Mesh.h:217
Definition: Vector2.h:31
AnimRange * getAnimsRanges(void)
Returns the array of animation ranges.
Definition: Mesh.h:317
Definition: Color.h:31
SubMesh * getSubMesh(size_t idx)
Definition: Mesh.h:425
TexturesAnimRef * getTexturesAnimRef(void)
Definition: Mesh.h:347
MaterialsAnimRef * getMaterialsAnimRef(void)
Returns the current material animation reference.
Definition: Mesh.h:370
void setArmatureAnimRef(ArmatureAnimRef *armatureAnimRef)
Sets the armature reference.
Definition: Mesh.h:325
AnimRange(void)
Definition: Mesh.h:230
SkinData * getSkinData(void)
Definition: Mesh.h:145
void setMaterialId(unsigned int id)
Definition: Mesh.h:82
Texture * getTexture(unsigned int id)
Definition: Mesh.h:387
Material * getMaterial(void)
Definition: Mesh.h:74
void setTexturesAnimRef(TexturesAnimRef *texturesAnimRef)
Definition: Mesh.h:343
unsigned int getDisplaysNumber(void)
Definition: Mesh.h:209
Definition: Mesh.h:87
PRIMITIVE_TYPES getPrimitiveType(void)
Definition: Mesh.h:64
unsigned int getSize(void)
Definition: Mesh.h:66
unsigned int getSubMeshsNumber(void)
Definition: Mesh.h:422
Armature * getArmature(void)
Definition: Mesh.h:380
unsigned int getTexturesNumber(void)
Definition: Mesh.h:386
Definition: TextureRef.h:32
Vector3 * getSkinVertices(void)
Definition: Mesh.h:178
Vector3 * getSkinTangents(void)
Definition: Mesh.h:180
unsigned int getIndicesSize(void)
Definition: Mesh.h:162
unsigned int getVerticesSize(void)
Definition: Mesh.h:163
unsigned int getMaterialId()
Definition: Mesh.h:83
Definition: Mesh.h:35
The Mesh class contains the implementation of a generic (i.e. file format agnostic) 3D mesh with supp...
Definition: Mesh.h:241
unsigned int * getVBOid1(void)
Definition: Mesh.h:189
void setMaterialsAnimRef(MaterialsAnimRef *materialsAnimRef)
Sets the material animation reference.
Definition: Mesh.h:360
unsigned int getNormalsSize(void)
Definition: Mesh.h:164
Definition: Color.h:29
CULL_MODES getCullMode(void)
Definition: Mesh.h:70
VAR_TYPES
Definition: RenderingContext.h:140
Definition: TexturesAnimRef.h:32
Vector3 * getTangents(void)
Definition: Mesh.h:175
SubMesh * getSubMeshs(void)
Definition: Mesh.h:423
Material * getMaterial(unsigned int id)
Retrieves a specific material from the internal array.
Definition: Mesh.h:418
Definition: ArmatureAnim.h:31
Describes a Range in an animation starting at a certain frame and ending at another certain frame...
Definition: Mesh.h:227
MorphingData * getMorphingData(void)
Definition: Mesh.h:140
Box3d * getBoundingBox(void)
Returns the current bounding box.
Definition: Mesh.h:438