NGL  6.5
The NCCA Graphics Library
AbstractMesh.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 Jon Macey
3 
4  This program is free software: you can redistribute it and/or modify
5  it under the terms of the GNU 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  This program 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 General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 #ifndef ABSTRACT_MESH_H_
18 #define ABSTRACT_MESH_H_
19 // must include types.h first for Real and GLEW if required
22 #include "Types.h"
23 #include "BBox.h"
24 #include "RibExport.h"
25 #include "Texture.h"
26 #include "NGLassert.h"
27 #include "Vec4.h"
28 #include "AbstractVAO.h"
29 
30 #include <vector>
31 #include <string>
32 #include <cstdint>
33 #include <memory>
34 
35 namespace ngl
36 {
37 //----------------------------------------------------------------------------------------------------------------------
41 //----------------------------------------------------------------------------------------------------------------------
42 class Face
43 {
44 public :
45  //----------------------------------------------------------------------------------------------------------------------
47  //----------------------------------------------------------------------------------------------------------------------
48  unsigned int m_numVerts;
49  //----------------------------------------------------------------------------------------------------------------------
51  //----------------------------------------------------------------------------------------------------------------------
52  std::vector<uint32_t> m_vert;
53  //----------------------------------------------------------------------------------------------------------------------
55  //----------------------------------------------------------------------------------------------------------------------
56  std::vector<uint32_t> m_tex;
57  //----------------------------------------------------------------------------------------------------------------------
59  //----------------------------------------------------------------------------------------------------------------------
60  std::vector<uint32_t> m_norm;
61  //----------------------------------------------------------------------------------------------------------------------
63  //----------------------------------------------------------------------------------------------------------------------
65  bool m_normals;
66 };
67 
68 //----------------------------------------------------------------------------------------------------------------------
71 //----------------------------------------------------------------------------------------------------------------------
72 class IndexRef
73 {
74 public :
75 
76  //----------------------------------------------------------------------------------------------------------------------
78  //----------------------------------------------------------------------------------------------------------------------
80  //----------------------------------------------------------------------------------------------------------------------
82  //----------------------------------------------------------------------------------------------------------------------
84  //----------------------------------------------------------------------------------------------------------------------
86  //----------------------------------------------------------------------------------------------------------------------
88  //----------------------------------------------------------------------------------------------------------------------
93  //----------------------------------------------------------------------------------------------------------------------
94  IndexRef(uint32_t _v, uint32_t _n, uint32_t _t ) noexcept :m_v(_v),m_n(_n),m_t(_t) {;}
95 };
96 
97 //----------------------------------------------------------------------------------------------------------------------
104 //----------------------------------------------------------------------------------------------------------------------
106 {
107 
108 public :
109 
110  //----------------------------------------------------------------------------------------------------------------------
113  //----------------------------------------------------------------------------------------------------------------------
114  virtual bool load(const std::string &_fname,bool _calcBB=true) noexcept =0;
115  //----------------------------------------------------------------------------------------------------------------------
117  //----------------------------------------------------------------------------------------------------------------------
118  AbstractMesh() noexcept : m_vbo(false), m_vao(false), m_ext(nullptr) {;}
119  //----------------------------------------------------------------------------------------------------------------------
121  //----------------------------------------------------------------------------------------------------------------------
122  virtual ~AbstractMesh() noexcept;
123  //----------------------------------------------------------------------------------------------------------------------
125  //----------------------------------------------------------------------------------------------------------------------
126  void drawBBox() const noexcept;
127  //----------------------------------------------------------------------------------------------------------------------
129  //----------------------------------------------------------------------------------------------------------------------
130  void draw() const noexcept;
131 
132  //----------------------------------------------------------------------------------------------------------------------
135  void loadTexture(const std::string& _fname ) noexcept;
136 
137  //----------------------------------------------------------------------------------------------------------------------
142  //----------------------------------------------------------------------------------------------------------------------
143  void scale( Real _sx, Real _sy, Real _sz ) noexcept;
144  //----------------------------------------------------------------------------------------------------------------------
146  //----------------------------------------------------------------------------------------------------------------------
147  void calcDimensions() noexcept;
148  //----------------------------------------------------------------------------------------------------------------------
151  //----------------------------------------------------------------------------------------------------------------------
152  void calcBoundingSphere() noexcept;
153 
154  //----------------------------------------------------------------------------------------------------------------------
157  //----------------------------------------------------------------------------------------------------------------------
158  void writeToRibSubdiv( RibExport& _ribFile) const noexcept;
159 
160  //----------------------------------------------------------------------------------------------------------------------
162  //----------------------------------------------------------------------------------------------------------------------
163  virtual void createVAO() noexcept;
164  //----------------------------------------------------------------------------------------------------------------------
167  //----------------------------------------------------------------------------------------------------------------------
168  unsigned int getTextureID() const noexcept{ return m_textureID; }
169  //----------------------------------------------------------------------------------------------------------------------
172  //----------------------------------------------------------------------------------------------------------------------
173  Real *mapVAOVerts() noexcept;
174  //----------------------------------------------------------------------------------------------------------------------
176  //----------------------------------------------------------------------------------------------------------------------
177  void unMapVAO() noexcept;
178  //----------------------------------------------------------------------------------------------------------------------
182  //----------------------------------------------------------------------------------------------------------------------
183  const std::vector<IndexRef> & getIndices() noexcept{ return m_indices; }
184  //----------------------------------------------------------------------------------------------------------------------
188  //----------------------------------------------------------------------------------------------------------------------
189  void saveNCCABinaryMesh( const std::string &_fname ) noexcept;
190  //----------------------------------------------------------------------------------------------------------------------
193  //----------------------------------------------------------------------------------------------------------------------
194 
195  BBox &getBBox() noexcept{ return *m_ext; }
196  //----------------------------------------------------------------------------------------------------------------------
199  //----------------------------------------------------------------------------------------------------------------------
200  std::vector <Vec3> getVertexList() noexcept{return m_verts;}
201  //----------------------------------------------------------------------------------------------------------------------
204  //----------------------------------------------------------------------------------------------------------------------
205  Vec3 getVertexAtIndex( uint32_t _i ) const noexcept
206  {
207  //NGL_ASSERT(_i>0 && _i<m_nVerts);
208  return m_verts[_i];
209  }
210 
211  //----------------------------------------------------------------------------------------------------------------------
214  //----------------------------------------------------------------------------------------------------------------------
215  std::vector <Vec3> getNormalList() noexcept{return m_norm;}
216  //----------------------------------------------------------------------------------------------------------------------
219  //----------------------------------------------------------------------------------------------------------------------
220  std::vector <Vec3> getTextureCordList() noexcept{return m_tex;}
221  //----------------------------------------------------------------------------------------------------------------------
224  //----------------------------------------------------------------------------------------------------------------------
225  std::vector <Face> getFaceList() noexcept{return m_face;}
226  //----------------------------------------------------------------------------------------------------------------------
228  //----------------------------------------------------------------------------------------------------------------------
229  unsigned int getNumVerts() const noexcept{return m_nVerts;}
230  //----------------------------------------------------------------------------------------------------------------------
232  //----------------------------------------------------------------------------------------------------------------------
233  unsigned int getNumNormals()const noexcept{return m_nNorm;}
234  //----------------------------------------------------------------------------------------------------------------------
236  //----------------------------------------------------------------------------------------------------------------------
237  unsigned int getNumTexCords()const noexcept{return m_nTex;}
238  //----------------------------------------------------------------------------------------------------------------------
240  //----------------------------------------------------------------------------------------------------------------------
241  unsigned int getNumFaces()const noexcept{return m_nFaces;}
242  unsigned int getMeshSize()const noexcept{return m_meshSize;}
243  //----------------------------------------------------------------------------------------------------------------------
245  //----------------------------------------------------------------------------------------------------------------------
246  Vec3 getSphereCenter() const noexcept{return m_sphereCenter;}
247  //----------------------------------------------------------------------------------------------------------------------
249  //----------------------------------------------------------------------------------------------------------------------
250  Real getSphereRadius() const noexcept{return m_sphereRadius;}
251  //----------------------------------------------------------------------------------------------------------------------
253  //----------------------------------------------------------------------------------------------------------------------
254  Vec3 getCenter() const noexcept{return m_center;}
255  //----------------------------------------------------------------------------------------------------------------------
258  //----------------------------------------------------------------------------------------------------------------------
259  bool isTriangular() noexcept;
260 
261 protected :
262  friend class NCCAPointBake;
263  //----------------------------------------------------------------------------------------------------------------------
265  unsigned int m_nVerts;
266  //----------------------------------------------------------------------------------------------------------------------
268  //----------------------------------------------------------------------------------------------------------------------
269  unsigned int m_nNorm;
270  //----------------------------------------------------------------------------------------------------------------------
272  //----------------------------------------------------------------------------------------------------------------------
273  unsigned int m_nTex;
274  //----------------------------------------------------------------------------------------------------------------------
276  //----------------------------------------------------------------------------------------------------------------------
277  unsigned int m_nFaces;
278  //----------------------------------------------------------------------------------------------------------------------
280  //----------------------------------------------------------------------------------------------------------------------
281  std::vector<Vec3> m_verts;
282  //----------------------------------------------------------------------------------------------------------------------
284  //----------------------------------------------------------------------------------------------------------------------
285  std::vector<Vec3> m_norm;
286  //----------------------------------------------------------------------------------------------------------------------
288  //----------------------------------------------------------------------------------------------------------------------
289  std::vector<Vec3> m_tex;
290  //----------------------------------------------------------------------------------------------------------------------
292  //----------------------------------------------------------------------------------------------------------------------
293  std::vector<Face> m_face;
294  //----------------------------------------------------------------------------------------------------------------------
296  //----------------------------------------------------------------------------------------------------------------------
298  //----------------------------------------------------------------------------------------------------------------------
300  //----------------------------------------------------------------------------------------------------------------------
301  std::vector<IndexRef> m_indices;
302  //----------------------------------------------------------------------------------------------------------------------
304  //----------------------------------------------------------------------------------------------------------------------
305  std::vector<GLuint> m_outIndices;
306  //----------------------------------------------------------------------------------------------------------------------
308  //----------------------------------------------------------------------------------------------------------------------
309  size_t m_indexSize;
310  size_t m_meshSize;
311  //----------------------------------------------------------------------------------------------------------------------
313  //----------------------------------------------------------------------------------------------------------------------
315  //----------------------------------------------------------------------------------------------------------------------
317  //----------------------------------------------------------------------------------------------------------------------
318  std::unique_ptr <AbstractVAO> m_vaoMesh;
319  //----------------------------------------------------------------------------------------------------------------------
321  //----------------------------------------------------------------------------------------------------------------------
322  bool m_vbo;
323  //----------------------------------------------------------------------------------------------------------------------
325  //----------------------------------------------------------------------------------------------------------------------
326  bool m_vao;
327  //----------------------------------------------------------------------------------------------------------------------
329  //----------------------------------------------------------------------------------------------------------------------
331  //----------------------------------------------------------------------------------------------------------------------
333  //----------------------------------------------------------------------------------------------------------------------
334  bool m_texture;
335  //----------------------------------------------------------------------------------------------------------------------
337  //----------------------------------------------------------------------------------------------------------------------
339  //----------------------------------------------------------------------------------------------------------------------
341  //----------------------------------------------------------------------------------------------------------------------
343  //----------------------------------------------------------------------------------------------------------------------
345  //----------------------------------------------------------------------------------------------------------------------
347  //----------------------------------------------------------------------------------------------------------------------
349  //----------------------------------------------------------------------------------------------------------------------
351  //----------------------------------------------------------------------------------------------------------------------
353  //----------------------------------------------------------------------------------------------------------------------
355  //----------------------------------------------------------------------------------------------------------------------
357  //----------------------------------------------------------------------------------------------------------------------
359  //----------------------------------------------------------------------------------------------------------------------
361  //----------------------------------------------------------------------------------------------------------------------
363  //----------------------------------------------------------------------------------------------------------------------
365  //----------------------------------------------------------------------------------------------------------------------
366  std::unique_ptr <BBox> m_ext;
367  //----------------------------------------------------------------------------------------------------------------------
369  //----------------------------------------------------------------------------------------------------------------------
371  //----------------------------------------------------------------------------------------------------------------------
374  //----------------------------------------------------------------------------------------------------------------------
375  unsigned int m_bufferPackSize;
376  //----------------------------------------------------------------------------------------------------------------------
378  //----------------------------------------------------------------------------------------------------------------------
380 
381  //----------------------------------------------------------------------------------------------------------------------
383  //----------------------------------------------------------------------------------------------------------------------
384  bool m_loaded;
385  //----------------------------------------------------------------------------------------------------------------------
387  //----------------------------------------------------------------------------------------------------------------------
389  //----------------------------------------------------------------------------------------------------------------------
391  //----------------------------------------------------------------------------------------------------------------------
393 
394 };
395 
396 } // end of namespace ngl
397 
398 
399 #endif // end of the class
a class to hold the index into vert / norm and tex list for creating the VBO data structure ...
Definition: AbstractMesh.h:72
std::vector< uint32_t > m_tex
The texture co-ord index.
Definition: AbstractMesh.h:56
a simple texture loader / GL texture object
Real getSphereRadius() const noexcept
accesor to get the bounding sphere center
Definition: AbstractMesh.h:250
IndexRef(uint32_t _v, uint32_t _n, uint32_t _t) noexcept
ctor to set the data
Definition: AbstractMesh.h:94
unsigned int GLuint
Definition: glew.h:280
GLenum GLenum GLenum GLenum GLenum scale
Definition: glew.h:14161
std::vector< IndexRef > m_indices
a vector of indices used to pass the index into the Data arrays to the VBO
Definition: AbstractMesh.h:301
std::vector< uint32_t > m_norm
the normal index
Definition: AbstractMesh.h:60
BBox & getBBox() noexcept
a method to get the current bounding box of the mesh
Definition: AbstractMesh.h:195
main definition of types and namespace
Real m_minX
The Min X value in the obj file used to calculate the extents bbox.
Definition: AbstractMesh.h:346
#define NGL_DLLEXPORT
Definition: Types.h:65
std::vector< Vec3 > m_tex
Pointer to the Texture co-ord list (note that only x and y are used)
Definition: AbstractMesh.h:289
Vec3 getVertexAtIndex(uint32_t _i) const noexcept
accessor for the vertex data
Definition: AbstractMesh.h:205
const std::vector< IndexRef > & getIndices() noexcept
get a pointer to the indices used to represent the VBO data, this is used in the clip class when re-o...
Definition: AbstractMesh.h:183
Vec3 getCenter() const noexcept
accesor to get the center
Definition: AbstractMesh.h:254
std::vector< uint32_t > m_vert
The vertices index.
Definition: AbstractMesh.h:52
std::vector< Vec3 > m_verts
Pointer to the Vertex list.
Definition: AbstractMesh.h:281
unsigned int getNumNormals() const noexcept
accessor to get the number of normals in the object
Definition: AbstractMesh.h:233
Real m_maxX
The Maximum X value in the obj file used to calculate the extents bbox.
Definition: AbstractMesh.h:342
unsigned int GLenum
Definition: glew.h:278
simple Vec3 encapsulates a 3 float object like glsl vec3 but not maths use the Vec3 class for maths a...
Definition: Vec3.h:51
implementation files for RibExport class
Definition: AABB.cpp:22
std::unique_ptr< AbstractVAO > m_vaoMesh
id for our vertexArray object
Definition: AbstractMesh.h:318
std::vector< Vec3 > getVertexList() noexcept
accessor for the vertex data
Definition: AbstractMesh.h:200
PRECISION Real
create a variable called Real which is the main data type we use (GLfloat for most cases) ...
Definition: Types.h:127
encapsulates a 4d Homogenous Point / Vector object
Vec3 m_center
Center of the object.
Definition: AbstractMesh.h:297
unsigned int getNumVerts() const noexcept
accessor to get the number of vertices in the object
Definition: AbstractMesh.h:229
simple rib export class, attempts to auto tab the rib file etc. needs lots of work to make it complet...
Definition: RibExport.h:41
bool m_loaded
flag to indicate if anything loaded for dtor
Definition: AbstractMesh.h:384
unsigned int getMeshSize() const noexcept
Definition: AbstractMesh.h:242
GLuint m_vboBuffers
buffers for the VBO in order Vert, Tex, Norm
Definition: AbstractMesh.h:314
std::unique_ptr< BBox > m_ext
Create a bounding box of the object to store it&#39;s extents.
Definition: AbstractMesh.h:366
bool m_texture
flag to indicate if texture assigned
Definition: AbstractMesh.h:334
an abstract base mesh used to build specific meshes such as Obj
Definition: AbstractMesh.h:105
unsigned int m_nVerts
The number of vertices in the object.
Definition: AbstractMesh.h:265
simple class used to encapsulate a single face of an abstract mesh file
Definition: AbstractMesh.h:42
unsigned int uint32_t
Definition: stdint.h:126
std::vector< Vec3 > m_norm
Pointer to the Normal List.
Definition: AbstractMesh.h:285
std::vector< Vec3 > getNormalList() noexcept
accessor for the normals data
Definition: AbstractMesh.h:215
unsigned int m_nNorm
The number of normals in the object.
Definition: AbstractMesh.h:269
unsigned int getNumFaces() const noexcept
accessor to get the number of faces in the object
Definition: AbstractMesh.h:241
AbstractMesh() noexcept
default ctor must be called from the child class so our dtor is called
Definition: AbstractMesh.h:118
GLenum m_vboDrawType
which type of VBO are we going to draw
Definition: AbstractMesh.h:379
unsigned int m_bufferPackSize
the size of the buffer pack we use this for the saving of bin vbo but it actually holds the size of t...
Definition: AbstractMesh.h:375
GLuint m_dataPackType
determines if the data is Packed as either TRI or QUAD
Definition: AbstractMesh.h:370
Real m_maxY
The Max Y value in the obj file used to calculate the extents bbox.
Definition: AbstractMesh.h:350
std::vector< Face > getFaceList() noexcept
accessor for the Face data
Definition: AbstractMesh.h:225
unsigned int m_nFaces
the number of faces in the object
Definition: AbstractMesh.h:277
Real m_maxZ
The Max Z value in the obj file used to calculate the extents bbox.
Definition: AbstractMesh.h:358
std::vector< Vec3 > getTextureCordList() noexcept
accessor for the texture co-ordinates data
Definition: AbstractMesh.h:220
bool m_textureCoord
debug flag to turn face on and off
Definition: AbstractMesh.h:64
Real m_sphereRadius
the radius of the bounding sphere
Definition: AbstractMesh.h:392
GLuint m_textureID
The openGL id of the texture for the texture generation.
Definition: AbstractMesh.h:338
uint32_t m_v
index into the vert list
Definition: AbstractMesh.h:79
Vec3 getSphereCenter() const noexcept
accesor to get the bounding sphere center
Definition: AbstractMesh.h:246
a simple rib exporter function
std::vector< GLuint > m_outIndices
a vectr of indices without duplicates which are actually passed to the VBO when creating ...
Definition: AbstractMesh.h:305
bool m_vboMapped
flag to indicate if the VBO vertex data has been mapped
Definition: AbstractMesh.h:330
bool m_vbo
flag to indicate if a VBO has been created
Definition: AbstractMesh.h:322
Simple Bounding box class used in various parts of ngl and other example programs.
Definition: BBox.h:40
a simple bounding box class
Real m_minZ
The Min Z value in the obj file used to calculate the extents bbox.
Definition: AbstractMesh.h:362
unsigned int m_nTex
the number of texture co-ordinates in the object
Definition: AbstractMesh.h:273
size_t m_indexSize
the size of the index array
Definition: AbstractMesh.h:309
uint32_t m_t
index into the texture list
Definition: AbstractMesh.h:87
unsigned int getTextureID() const noexcept
get the texture id
Definition: AbstractMesh.h:168
uint32_t m_n
index into the nornmal list
Definition: AbstractMesh.h:83
Vec3 m_sphereCenter
the center of the bounding sphere
Definition: AbstractMesh.h:388
unsigned int getNumTexCords() const noexcept
accessor to get the number of texture co-ordinates in the object
Definition: AbstractMesh.h:237
re impliment asserts so we don&#39;t exit on failure
unsigned int m_numVerts
the number of vertices in the face
Definition: AbstractMesh.h:48
Class to load and manipulate NCCAPointBake data, this will replace the Houdini Clip files as they are...
Definition: NCCAPointBake.h:58
GLsizei const GLchar *const * string
Definition: glew.h:1847
Real m_minY
The Min Y value in the obj file used to calculate the extents bbox.
Definition: AbstractMesh.h:354
std::vector< Face > m_face
Pointer to the Face list.
Definition: AbstractMesh.h:293
bool m_normals
Definition: AbstractMesh.h:65
bool m_vao
flag to indicate if a VBO has been created
Definition: AbstractMesh.h:326