NGL  6.5
The NCCA Graphics Library
AbstractMesh.cpp
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 
18 #include "AbstractMesh.h"
19 #include "Util.h"
20 #include <list>
21 #include "NGLStream.h"
22 #include "VAOFactory.h"
23 #include "SimpleVAO.h"
24 //----------------------------------------------------------------------------------------------------------------------
27 //----------------------------------------------------------------------------------------------------------------------
28 
29 namespace ngl
30 {
31  //----------------------------------------------------------------------------------------------------------------------
32 
33 //----------------------------------------------------------------------------------------------------------------------
34 
35 //----------------------------------------------------------------------------------------------------------------------
36 void AbstractMesh::drawBBox() const noexcept
37 {
38  m_ext->draw();
39 }
40 
41 void AbstractMesh::scale(Real _sx, Real _sy, Real _sz ) noexcept
42 {
43  m_center=0;
44  // do lambda here
45  for (auto &v : m_verts)
46  {
47  v.m_x*=_sx;
48  v.m_y*=_sy;
49  v.m_z*=_sz;
50  m_center+=v;
51  }
52 // calculate the center
55 }
56 
57 
58 
59 //----------------------------------------------------------------------------------------------------------------------
61 {
62  if(m_loaded == true)
63  {
64  m_verts.erase(m_verts.begin(),m_verts.end());
65  m_norm.erase(m_norm.begin(),m_norm.end());
66  m_tex.erase(m_tex.begin(),m_tex.end());
67  m_face.erase(m_face.begin(),m_face.end());
68  m_indices.erase(m_indices.begin(),m_indices.end());
69  m_outIndices.erase(m_outIndices.begin(),m_outIndices.end());
70 
71  if(m_vbo)
72  {
74  }
75  }
76 }
77 
78 
79 //----------------------------------------------------------------------------------------------------------------------
80 void AbstractMesh::loadTexture( const std::string& _fName ) noexcept
81 {
82  // load in the texture
83  Texture *t=new Texture(_fName);
85  delete t;
86  m_texture=true;
87 }
88 
96 
97 //----------------------------------------------------------------------------------------------------------------------
98 void AbstractMesh::writeToRibSubdiv(RibExport& _ribFile )const noexcept
99 {
100  // Declare the variables
101  std::list< int > lVertLink;
102  std::list< int >::iterator vertLinkItr;
103  std::vector< float > vVerts;
104  std::vector< float >::iterator vertsItr;
105 
106  // Check if the rib exists
107  if( _ribFile.isOpen() != 0 )
108  {
109  _ribFile.comment( "OBJ AbstractMeshect" );
110  // Start printing the SubdivisionPolygons tag to the rib
111  _ribFile.getStream() << "SubdivisionMesh \"catmull-clark\" [ ";
112 
113  // Loop through all the Polygons
114  for (unsigned long int I=0; I<m_nVerts; ++I)
115  {
116  // Print the count of vertices for the current polygon to the rib
117  _ribFile.getStream() << m_face[I].m_numVerts << " ";
118  // Start building the vertids and parameterlist
119  for (unsigned long int i = 0; i < m_face[I].m_numVerts; ++i)
120  {
121  // Set the verts vector size and testing variables
122  size_t iVecSize = vVerts.size();
123  bool bTest = false;
124  int counter = 0;
125  // Loop through the expanding vector checking whether
126  // the current vertice exists
127  for (unsigned int j = 0; j < iVecSize; j = j + 3)
128  {
129  // If the vertice if found in the vector, set the test
130  // flag and exit the loop. Else keep going.
131  if( ( FCompare(m_verts[i].m_x ,vVerts[j]) ) &&
132  ( FCompare(m_verts[i].m_y,vVerts[j + 1]) ) &&
133  ( FCompare(m_verts[i].m_y,vVerts[j + 2]) )
134  )
135  {
136  bTest = true;
137  break;
138  }
139  else
140  {
141  counter++;
142  }
143  } //end for
144 
145  // Add the vertice to the vector if it is not found
146  if( bTest == false )
147  {
148  vVerts.push_back( m_verts[m_face[I].m_vert[i]].m_x );
149  vVerts.push_back( m_verts[m_face[I].m_vert[i]].m_y );
150  vVerts.push_back( m_verts[m_face[I].m_vert[i]].m_z );
151  lVertLink.push_back( counter );
152  }
153  else
154  {
155  lVertLink.push_back( counter );
156  }
157 
158  }// end outer for
159 
160  }// end if
161 
162  _ribFile.getStream() << "] [ ";
163 
164  // Print the vertids to the rib
165  std::list< int >::iterator vertLinkEnd=lVertLink.end();
166  for (vertLinkItr = lVertLink.begin(); vertLinkItr != vertLinkEnd; ++vertLinkItr)
167  {
168  _ribFile.getStream() << *vertLinkItr << " ";
169  }
170 
171  _ribFile.getStream() << "] [\"interpolateboundary\"] [0 0] [] [] \"P\" [ ";
172  // Print the parameterlist to the rib
173  std::vector< float >::iterator vVertEnd=vVerts.end();
174  for (vertsItr = vVerts.begin(); vertsItr != vVertEnd; ++vertsItr)
175  {
176  _ribFile.getStream() << *vertsItr << " ";
177  }
178 
179  // Print new lines to the rib
180  _ribFile.getStream() << "]\n\n";
181  }
182 
183 }
184 
185 //----------------------------------------------------------------------------------------------------------------------
187 {
188  for(auto f : m_face)
189  {
190  if (f.m_numVerts >3)
191  {
192  return false;
193  }
194  }
195  return true;
196 }
197 
198 // a simple structure to hold our vertex data
199 // had to move this outside the method as g++ complains about it
200 // clang doesn't have a problem tho
201 struct VertData
202 {
203  GLfloat u; // tex cords
204  GLfloat v; // tex cords
205  GLfloat nx; // normal from obj mesh
208  GLfloat x; // position from obj
211 };
212 
213 
214 void AbstractMesh::createVAO() noexcept
215 {
216  // if we have already created a VBO just return.
217  if(m_vao == true)
218  {
219  std::cout<<"VAO exist so returning\n";
220  return;
221  }
222 // else allocate space as build our VAO
223  m_dataPackType=0;
224  if(isTriangular())
225  {
227  std::cout <<"Doing Tri Data"<<std::endl;
228  }
229  // data is mixed of > quad so exit error
230  if(m_dataPackType == 0)
231  {
232  std::cerr<<"Can only create VBO from all Triangle or ALL Quad data at present"<<std::endl;
233  exit(EXIT_FAILURE);
234  }
235 
236  // now we are going to process and pack the mesh into an ngl::VertexArrayObject
237  std::vector <VertData> vboMesh;
238  VertData d;
239 
240 
241  // loop for each of the faces
242  for(unsigned int i=0;i<m_nFaces;++i)
243  {
244  // now for each triangle in the face (remember we ensured tri above)
245  for(unsigned int j=0;j<3;++j)
246  {
247 
248  // pack in the vertex data first
249  d.x=m_verts[m_face[i].m_vert[j]].m_x;
250  d.y=m_verts[m_face[i].m_vert[j]].m_y;
251  d.z=m_verts[m_face[i].m_vert[j]].m_z;
252  // now if we have norms of tex (possibly could not) pack them as well
253  if(m_nNorm >0 && m_nTex > 0)
254  {
255  d.nx=m_norm[m_face[i].m_norm[j]].m_x;
256  d.ny=m_norm[m_face[i].m_norm[j]].m_y;
257  d.nz=m_norm[m_face[i].m_norm[j]].m_z;
258 
259  d.u=m_tex[m_face[i].m_tex[j]].m_x;
260  d.v=m_tex[m_face[i].m_tex[j]].m_y;
261  }
262  // now if neither are present (only verts like Zbrush models)
263  else if(m_nNorm ==0 && m_nTex==0)
264  {
265  d.nx=0;
266  d.ny=0;
267  d.nz=0;
268  d.u=0;
269  d.v=0;
270  }
271  // here we've got norms but not tex
272  else if(m_nNorm >0 && m_nTex==0)
273  {
274  d.nx=m_norm[m_face[i].m_norm[j]].m_x;
275  d.ny=m_norm[m_face[i].m_norm[j]].m_y;
276  d.nz=m_norm[m_face[i].m_norm[j]].m_z;
277  d.u=0;
278  d.v=0;
279  }
280  // here we've got tex but not norm least common
281  else if(m_nNorm ==0 && m_nTex>0)
282  {
283  d.nx=0;
284  d.ny=0;
285  d.nz=0;
286  d.u=m_tex[m_face[i].m_tex[j]].m_x;
287  d.v=m_tex[m_face[i].m_tex[j]].m_y;
288  }
289  vboMesh.push_back(d);
290  }
291  }
292 
293  // first we grab an instance of our VOA
295  // next we bind it so it's active for setting data
296  m_vaoMesh->bind();
297  m_meshSize=vboMesh.size();
298 
299  // now we have our data add it to the VAO, we need to tell the VAO the following
300  // how much (in bytes) data we are copying
301  // a pointer to the first element of data (in this case the address of the first element of the
302  // std::vector
303  //m_vaoMesh->setData(m_meshSize*sizeof(VertData),vboMesh[0].u);
304  m_vaoMesh->setData(SimpleVAO::VertexData(m_meshSize*sizeof(VertData),vboMesh[0].u));
305  // in this case we have packed our data in interleaved format as follows
306  // u,v,nx,ny,nz,x,y,z
307  // If you look at the shader we have the following attributes being used
308  // attribute vec3 inVert; attribute 0
309  // attribute vec2 inUV; attribute 1
310  // attribute vec3 inNormal; attribure 2
311  // so we need to set the vertexAttributePointer so the correct size and type as follows
312  // vertex is attribute 0 with x,y,z(3) parts of type GL_FLOAT, our complete packed data is
313  // sizeof(vertData) and the offset into the data structure for the first x component is 5 (u,v,nx,ny,nz)..x
314  m_vaoMesh->setVertexAttributePointer(0,3,GL_FLOAT,sizeof(VertData),5);
315  // uv same as above but starts at 0 and is attrib 1 and only u,v so 2
316  m_vaoMesh->setVertexAttributePointer(1,2,GL_FLOAT,sizeof(VertData),0);
317  // normal same as vertex only starts at position 2 (u,v)-> nx
318  m_vaoMesh->setVertexAttributePointer(2,3,GL_FLOAT,sizeof(VertData),2);
319 
320 
321  // now we have set the vertex attributes we tell the VAO class how many indices to draw when
322  // glDrawArrays is called, in this case we use buffSize (but if we wished less of the sphere to be drawn we could
323  // specify less (in steps of 3))
324  m_vaoMesh->setNumIndices(m_meshSize);
325  // finally we have finished for now so time to unbind the VAO
326  m_vaoMesh->unbind();
327 
328  // indicate we have a vao now
329  m_vao=true;
330 
331 }
332 
333 
334 
335 //----------------------------------------------------------------------------------------------------------------------
336 void AbstractMesh::draw() const noexcept
337 {
338  if(m_vao == true)
339  {
340  if(m_texture == true)
341  {
343  }
344  m_vaoMesh->bind();
345  m_vaoMesh->draw();
346  m_vaoMesh->unbind();
347  }
348 
349 }
350 
351 
352 //----------------------------------------------------------------------------------------------------------------------
354 {
355 
356  Real* ptr=nullptr;
357 
358  // bind our VBO data
359 //
360  m_vaoMesh->bind();
361  //NGLCheckGLError("Abstract Mesh",__LINE__);
362  glBindBuffer(GL_ARRAY_BUFFER, m_vaoMesh->getBufferID(0));
363  //NGLCheckGLError("Abstract Mesh",__LINE__);
364 #ifndef USINGIOS_
365  ptr = static_cast<Real *>(glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE));
366 #else
367  //ptr = (float*)glMapBufferOES(GL_ARRAY_BUFFER,GL_READ_WRITE_OES);
368 #endif
369  //NGLCheckGLError("Abstract Mesh",__LINE__);
370  m_vboMapped=true;
371  return ptr;
372 }
373 
374 //----------------------------------------------------------------------------------------------------------------------
375 void AbstractMesh::unMapVAO() noexcept
376 {
377 
378  if(m_vboMapped==true)
379  {
380  glUnmapBuffer(GL_ARRAY_BUFFER); // unmap it after use
381  m_vboMapped=false;
382  m_vaoMesh->unbind();
383  }
384 
385 }
386 //----------------------------------------------------------------------------------------------------------------------
388 {
389  // Calculate the center of the object.
390  m_center=0.0;
391  for(auto v : m_verts)
392  {
393  m_center+=v;
394  }
396  // calculate the extents
400 
401 
402  // Calculate the center of the object.
403  m_center=0.0;
404  for( auto v :m_verts)
405  {
406  m_center+=v;
407  }
409  // calculate the extents
413 
414  for(auto v : m_verts)
415  {
416  if (v.m_x >m_maxX) { m_maxX=v.m_x; }
417  else if(v.m_x <m_minX) { m_minX=v.m_x; }
418  if (v.m_y >m_maxY) { m_maxY=v.m_y; }
419  else if(v.m_y <m_minY) { m_minY=v.m_y; }
420  if (v.m_z >m_maxZ) { m_maxZ=v.m_z; }
421  else if(v.m_z <m_minZ) { m_minZ=v.m_z; }
422  }
423 
424 
425 
426  // create a new bbox based on the new object size
428 
429 }
430 
431 void AbstractMesh::saveNCCABinaryMesh( const std::string &_fname ) noexcept
432 {
433 // so basically we need to save all the state data from the abstract mesh
434 // then map the vbo on the gpu and dump that in one go, this means we have to
435 // call CreateVBO first the Save
436  std::fstream file;
437  file.open(_fname.c_str(),std::ios::out | std::ios::binary);
438  if (!file.is_open())
439  {
440  std::cerr<<"problems Opening File "<<_fname<<std::endl;
441  return;
442  }
443  // lets write out our own Magic Number file ID
444  const std::string header("ngl::bin");
445  file.write(header.c_str(),header.length());
447  file.write(reinterpret_cast <char *>(&m_nVerts),sizeof(unsigned long int));
449  file.write(reinterpret_cast <char *>(&m_nNorm),sizeof(unsigned long int));
450 
452  file.write(reinterpret_cast <char *>(&m_nTex),sizeof(unsigned long int));
453 
455  file.write(reinterpret_cast <char *>(&m_nFaces),sizeof(unsigned long int));
456  file.write(reinterpret_cast <char *>(&m_center.m_x),sizeof(Real));
457  file.write(reinterpret_cast <char *>(&m_center.m_y),sizeof(Real));
458  file.write(reinterpret_cast <char *>(&m_center.m_z),sizeof(Real));
459 
460  file.write(reinterpret_cast <char *>(&m_texture),sizeof(bool));
461 
462  file.write(reinterpret_cast <char *>(&m_maxX),sizeof(Real));
463  file.write(reinterpret_cast <char *>(&m_maxY),sizeof(Real));
464  file.write(reinterpret_cast <char *>(&m_maxZ),sizeof(Real));
465  file.write(reinterpret_cast <char *>(&m_minX),sizeof(Real));
466  file.write(reinterpret_cast <char *>(&m_minY),sizeof(Real));
467  file.write(reinterpret_cast <char *>(&m_minZ),sizeof(Real));
468 
469  file.write(reinterpret_cast <char *>(& m_dataPackType),sizeof(GLuint));
470  file.write(reinterpret_cast <char *>(& m_indexSize),sizeof(unsigned int));
471  file.write(reinterpret_cast <char *>(& m_bufferPackSize),sizeof(unsigned int));
473  unsigned int size=m_indexSize*m_bufferPackSize*sizeof(GLfloat);
474  std::cout<<"size is"<<size<<std::endl;
475  file.write(reinterpret_cast <char *>(&size),sizeof(unsigned int));
476 
477 
478  Real *vboMem=this->mapVAOVerts();
479  file.write(reinterpret_cast<char *>(vboMem),size);
480 
481  // now write the indices
482  // first the size
483  size=m_outIndices.size();
484  std::cout<<"Size of out indices ="<<size<<std::endl;
485  file.write(reinterpret_cast <char *>(&size),sizeof(unsigned int));
486 
487 
488  for (auto d : m_outIndices)
489  {
490  file.write(reinterpret_cast <char *>(d),sizeof(unsigned int));
491  }
492 
493  file.close();
494  this->unMapVAO();
495 
496 }
497 
502 {
503 auto size=m_verts.size();
504 if( size <=0 )
505 {
506  std::cerr<<"now vertices loaded \n";
507  m_sphereCenter=0;
508  m_sphereRadius=0;
509  return;
510 
511 }
512 // find minimal and maximal extents and indexs into
513 // into vert array
514 int minXI=0; int minYI=0; int minZI=0;
515 int maxXI=0; int maxYI=0; int maxZI=0;
516 Real minX=m_verts[0].m_x; Real maxX=m_verts[0].m_x;
517 Real minY=m_verts[0].m_y; Real maxY=m_verts[0].m_y;
518 Real minZ=m_verts[0].m_z; Real maxZ=m_verts[0].m_z;
519 
520 for(unsigned int i=0; i<size; ++i)
521 {
522  if(m_verts[i].m_x < minX) { minXI=i; minX=m_verts[i].m_x; }
523  if(m_verts[i].m_x > maxX) { maxXI=i; maxX=m_verts[i].m_x; }
524  if(m_verts[i].m_y < minY) { minYI=i; minY=m_verts[i].m_y; }
525  if(m_verts[i].m_y > maxY) { maxYI=i; maxY=m_verts[i].m_y; }
526  if(m_verts[i].m_z < minZ) { minZI=i; minZ=m_verts[i].m_z; }
527  if(m_verts[i].m_z > maxZ) { maxZI=i; maxZ=m_verts[i].m_z; }
528 }
529 // now we find maximally seperated points from the 3 pairs
530 // we will use this to initialise the spheres
531 Real dx=m_verts[minXI].m_x-m_verts[maxXI].m_x;
532 Real dy=m_verts[minXI].m_y-m_verts[maxXI].m_y;
533 Real dz=m_verts[minXI].m_z-m_verts[maxXI].m_z;
534 Real diam2x=dx*dx+dy*dy+dz*dz;
535 
536 dx=m_verts[minYI].m_x-m_verts[maxYI].m_x;
537 dy=m_verts[minYI].m_y-m_verts[maxYI].m_y;
538 dz=m_verts[minYI].m_z-m_verts[maxYI].m_z;
539 Real diam2y=dx*dx+dy*dy+dz*dz;
540 
541 dx=m_verts[minZI].m_x-m_verts[maxZI].m_x;
542 dy=m_verts[minZI].m_y-m_verts[maxZI].m_y;
543 dz=m_verts[minZI].m_z-m_verts[maxZI].m_z;
544 Real diam2z=dx*dx+dy*dy+dz*dz;
545 
546 Real diamTwo=diam2x;
547 int p1i=minXI;
548 int p2i=maxXI;
549 if(diam2y>diamTwo){ diamTwo=diam2y; p1i=minYI; p2i=maxYI;}
550 if(diam2z>diamTwo){ diamTwo=diam2z; p1i=minZI; p2i=maxZI;}
551 // now we can get the center of the sphere as the average
552 // of the two points
553 m_sphereCenter=(m_verts[p1i]+m_verts[p2i])/2.0;
554 // now calculate radius and radius^2 of the initial sphere
555 Real radTwo=diamTwo/4.0;
556 Real rad=sqrt(radTwo);
557 // now check and adjust for outlying points
558 Vec3 newCenter;
559 Real newRad2;
560 Real newRad;
561 Real dist2;
562 Real dist;
563 Real delta;
564 
565 for (auto v : m_verts)
566 {
567  dx=v.m_x-m_sphereCenter.m_x;
568  dy=v.m_y-m_sphereCenter.m_y;
569  dz=v.m_z-m_sphereCenter.m_z;
570  // distance squared of old center to current point
571  dist2=dx*dx+dy*dy+dz*dz;
572  // need to update the sphere if this point is outside the radius
573  if(dist2 > radTwo)
574  {
575  dist=sqrt(dist2);
576  newRad=(rad+dist)/2.0;
577  newRad2=newRad*newRad;
578  delta=dist-newRad;
579  // now compute new center using the weights above
580  newCenter.m_x=(newRad*m_sphereCenter.m_x+delta*v.m_x)/dist;
581  newCenter.m_y=(newRad*m_sphereCenter.m_y+delta*v.m_y)/dist;
582  newCenter.m_z=(newRad*m_sphereCenter.m_z+delta*v.m_z)/dist;
583  // now test to see if we have a fit
584  dx=v.m_x-newCenter.m_x;
585  dy=v.m_y-newCenter.m_y;
586  dz=v.m_z-newCenter.m_z;
587  dist2=dx*dx+dy*dy+dz*dz;
588  if(dist2 > newRad2)
589  {
590  std::cerr<<"something wrong here\n";
591  std::cerr<<"error margin "<<dist2-newRad2<<"\n";
592  }
593  m_sphereCenter=newCenter;
594  rad=newRad;
595  radTwo=rad*rad;
596  } // end if dist2>rad2
597  m_sphereRadius=rad;
598 
599 }
600 
601 m_sphereRadius=rad;
602 std::cout<<m_sphereCenter<<" rad "<<m_sphereRadius<<"\n";
603 
604 }
606 
607 
608 } //end ngl namespace
609 
610 
some useful definitions and functions
GLfloat minY
Definition: glew.h:3548
unsigned int GLuint
Definition: glew.h:280
GLuint counter
Definition: glew.h:2743
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
static AbstractVAO * createVAO(const std::string &_type, GLenum _mode=GL_TRIANGLES)
Definition: VAOFactory.cpp:19
Real m_minX
The Min X value in the obj file used to calculate the extents bbox.
Definition: AbstractMesh.h:346
#define glMapBuffer
Definition: glew.h:1719
std::vector< Vec3 > m_tex
Pointer to the Texture co-ord list (note that only x and y are used)
Definition: AbstractMesh.h:289
#define glUnmapBuffer
Definition: glew.h:1720
a series of classes used to define an abstract 3D mesh of Faces, Vertex Normals and TexCords ...
#define GL_TRIANGLES
Definition: glew.h:330
GLuint setTextureGL() const noexcept
set the image as an OpenGL texture object
Definition: Texture.cpp:64
std::vector< Vec3 > m_verts
Pointer to the Vertex list.
Definition: AbstractMesh.h:281
GLdouble GLdouble t
Definition: glew.h:1401
Real m_maxX
The Maximum X value in the obj file used to calculate the extents bbox.
Definition: AbstractMesh.h:342
simple Vec3 encapsulates a 3 float object like glsl vec3 but not maths use the Vec3 class for maths a...
Definition: Vec3.h:51
GLfloat GLfloat GLfloat GLfloat GLfloat maxY
Definition: glew.h:3548
implementation files for RibExport class
Definition: AABB.cpp:22
float GLfloat
Definition: glew.h:289
std::unique_ptr< AbstractVAO > m_vaoMesh
id for our vertexArray object
Definition: AbstractMesh.h:318
void writeToRibSubdiv(RibExport &_ribFile) const noexcept
GLfloat GLfloat GLfloat GLfloat maxX
Definition: glew.h:3548
PRECISION Real
create a variable called Real which is the main data type we use (GLfloat for most cases) ...
Definition: Types.h:127
GLAPI void GLAPIENTRY glBindTexture(GLenum target, GLuint texture)
#define FCompare(a, b)
FCompare macro used for floating point comparision functions.
Definition: Types.h:136
Vec3 m_center
Center of the object.
Definition: AbstractMesh.h:297
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
Real m_y
y component
Definition: Vec3.h:311
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
void scale(Real _sx, Real _sy, Real _sz) noexcept
scale the obj by multiplying the actual vertex values by sx,sy and sz
bool m_texture
flag to indicate if texture assigned
Definition: AbstractMesh.h:334
const GLuint GLenum const void * binary
Definition: glew.h:3514
simple texture object using QImage to load and convert to OpenGL texturing, needs loads of work for m...
Definition: Texture.h:42
const GLdouble * v
Definition: glew.h:1394
unsigned int m_nVerts
The number of vertices in the object.
Definition: AbstractMesh.h:265
#define GL_READ_WRITE
Definition: glew.h:1664
std::vector< Vec3 > m_norm
Pointer to the Normal List.
Definition: AbstractMesh.h:285
stream helpers for ngl data types
Real m_x
x component
Definition: Vec3.h:310
unsigned int m_nNorm
The number of normals in the object.
Definition: AbstractMesh.h:269
void saveNCCABinaryMesh(const std::string &_fname) noexcept
save the mesh as NCCA Binary VBO format basically this format is the processed binary vbo mesh data a...
Real * mapVAOVerts() noexcept
map the VBO vertex data
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
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
void draw() const noexcept
draw method to draw the obj as a VBO. The VBO first needs to be created using the CreateVBO method ...
virtual ~AbstractMesh() noexcept
destructor this will clear out all the vert data and the vbo if created
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
virtual void createVAO() noexcept
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
GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat maxZ
Definition: glew.h:3548
GLsizeiptr size
Definition: glew.h:1684
void loadTexture(const std::string &_fname) noexcept
load int a texture and set it as the active texture of the Obj
void calcBoundingSphere() noexcept
a method to caluculate the bounding Sphere will set m_sphereCenter and m_sphereRadius ...
void unMapVAO() noexcept
unmap the VBO based
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
#define glDeleteBuffers
Definition: glew.h:1706
void drawBBox() const noexcept
method to draw the bounding box
#define glBindBuffer
Definition: glew.h:1703
Real m_minZ
The Min Z value in the obj file used to calculate the extents bbox.
Definition: AbstractMesh.h:362
#define GL_ARRAY_BUFFER
Definition: glew.h:1648
unsigned int m_nTex
the number of texture co-ordinates in the object
Definition: AbstractMesh.h:273
#define GL_FLOAT
Definition: glew.h:642
size_t m_indexSize
the size of the index array
Definition: AbstractMesh.h:309
bool isTriangular() noexcept
check to see if obj is triangulated as we only support tri or quad objs at the moment ...
void calcDimensions() noexcept
a method to set the BBox and center
Vec3 m_sphereCenter
the center of the bounding sphere
Definition: AbstractMesh.h:388
GLfloat GLfloat minZ
Definition: glew.h:3548
#define GL_TEXTURE_2D
Definition: glew.h:10194
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
Real m_z
z component
Definition: Vec3.h:312
GLclampf f
Definition: glew.h:3511
bool m_vao
flag to indicate if a VBO has been created
Definition: AbstractMesh.h:326