101 std::list< int > lVertLink;
102 std::list< int >::iterator vertLinkItr;
103 std::vector< float > vVerts;
104 std::vector< float >::iterator vertsItr;
107 if( _ribFile.isOpen() != 0 )
109 _ribFile.comment(
"OBJ AbstractMeshect" );
111 _ribFile.getStream() <<
"SubdivisionMesh \"catmull-clark\" [ ";
114 for (
unsigned long int I=0; I<
m_nVerts; ++I)
117 _ribFile.getStream() <<
m_face[I].m_numVerts <<
" ";
119 for (
unsigned long int i = 0; i <
m_face[I].m_numVerts; ++i)
122 size_t iVecSize = vVerts.size();
127 for (
unsigned int j = 0; j < iVecSize; j = j + 3)
151 lVertLink.push_back( counter );
155 lVertLink.push_back( counter );
162 _ribFile.getStream() <<
"] [ ";
165 std::list< int >::iterator vertLinkEnd=lVertLink.end();
166 for (vertLinkItr = lVertLink.begin(); vertLinkItr != vertLinkEnd; ++vertLinkItr)
168 _ribFile.getStream() << *vertLinkItr <<
" ";
171 _ribFile.getStream() <<
"] [\"interpolateboundary\"] [0 0] [] [] \"P\" [ ";
173 std::vector< float >::iterator vVertEnd=vVerts.end();
174 for (vertsItr = vVerts.begin(); vertsItr != vVertEnd; ++vertsItr)
176 _ribFile.getStream() << *vertsItr <<
" ";
180 _ribFile.getStream() <<
"]\n\n";
219 std::cout<<
"VAO exist so returning\n";
227 std::cout <<
"Doing Tri Data"<<std::endl;
232 std::cerr<<
"Can only create VBO from all Triangle or ALL Quad data at present"<<std::endl;
237 std::vector <VertData> vboMesh;
242 for(
unsigned int i=0;i<
m_nFaces;++i)
245 for(
unsigned int j=0;j<3;++j)
289 vboMesh.push_back(d);
404 for(
auto v :m_verts)
414 for(
auto v : m_verts)
440 std::cerr<<
"problems Opening File "<<_fname<<std::endl;
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));
452 file.write(reinterpret_cast <char *>(&
m_nTex),
sizeof(
unsigned long int));
455 file.write(reinterpret_cast <char *>(&
m_nFaces),
sizeof(
unsigned long int));
460 file.write(reinterpret_cast <char *>(&
m_texture),
sizeof(
bool));
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));
470 file.write(reinterpret_cast <char *>(&
m_indexSize),
sizeof(
unsigned int));
471 file.write(reinterpret_cast <char *>(&
m_bufferPackSize),
sizeof(
unsigned int));
474 std::cout<<
"size is"<<size<<std::endl;
475 file.write(reinterpret_cast <char *>(&size),
sizeof(
unsigned int));
479 file.write(reinterpret_cast<char *>(vboMem),size);
484 std::cout<<
"Size of out indices ="<<size<<std::endl;
485 file.write(reinterpret_cast <char *>(&size),
sizeof(
unsigned int));
490 file.write(reinterpret_cast <char *>(d),
sizeof(
unsigned int));
506 std::cerr<<
"now vertices loaded \n";
514 int minXI=0;
int minYI=0;
int minZI=0;
515 int maxXI=0;
int maxYI=0;
int maxZI=0;
520 for(
unsigned int i=0; i<
size; ++i)
534 Real diam2x=dx*dx+dy*dy+dz*dz;
539 Real diam2y=dx*dx+dy*dy+dz*dz;
544 Real diam2z=dx*dx+dy*dy+dz*dz;
549 if(diam2y>diamTwo){ diamTwo=diam2y; p1i=minYI; p2i=maxYI;}
550 if(diam2z>diamTwo){ diamTwo=diam2z; p1i=minZI; p2i=maxZI;}
555 Real radTwo=diamTwo/4.0;
556 Real rad=sqrt(radTwo);
571 dist2=dx*dx+dy*dy+dz*dz;
576 newRad=(rad+dist)/2.0;
577 newRad2=newRad*newRad;
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;
590 std::cerr<<
"something wrong here\n";
591 std::cerr<<
"error margin "<<dist2-newRad2<<
"\n";
some useful definitions and functions
std::vector< IndexRef > m_indices
a vector of indices used to pass the index into the Data arrays to the VBO
static AbstractVAO * createVAO(const std::string &_type, GLenum _mode=GL_TRIANGLES)
Real m_minX
The Min X value in the obj file used to calculate the extents bbox.
std::vector< Vec3 > m_tex
Pointer to the Texture co-ord list (note that only x and y are used)
a series of classes used to define an abstract 3D mesh of Faces, Vertex Normals and TexCords ...
GLuint setTextureGL() const noexcept
set the image as an OpenGL texture object
std::vector< Vec3 > m_verts
Pointer to the Vertex list.
Real m_maxX
The Maximum X value in the obj file used to calculate the extents bbox.
simple Vec3 encapsulates a 3 float object like glsl vec3 but not maths use the Vec3 class for maths a...
GLfloat GLfloat GLfloat GLfloat GLfloat maxY
implementation files for RibExport class
std::unique_ptr< AbstractVAO > m_vaoMesh
id for our vertexArray object
void writeToRibSubdiv(RibExport &_ribFile) const noexcept
GLfloat GLfloat GLfloat GLfloat maxX
PRECISION Real
create a variable called Real which is the main data type we use (GLfloat for most cases) ...
GLAPI void GLAPIENTRY glBindTexture(GLenum target, GLuint texture)
#define FCompare(a, b)
FCompare macro used for floating point comparision functions.
Vec3 m_center
Center of the object.
simple rib export class, attempts to auto tab the rib file etc. needs lots of work to make it complet...
bool m_loaded
flag to indicate if anything loaded for dtor
GLuint m_vboBuffers
buffers for the VBO in order Vert, Tex, Norm
std::unique_ptr< BBox > m_ext
Create a bounding box of the object to store it's extents.
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
const GLuint GLenum const void * binary
simple texture object using QImage to load and convert to OpenGL texturing, needs loads of work for m...
unsigned int m_nVerts
The number of vertices in the object.
std::vector< Vec3 > m_norm
Pointer to the Normal List.
stream helpers for ngl data types
unsigned int m_nNorm
The number of normals in the object.
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...
GLuint m_dataPackType
determines if the data is Packed as either TRI or QUAD
Real m_maxY
The Max Y value in the obj file used to calculate the extents bbox.
unsigned int m_nFaces
the number of faces in the object
Real m_maxZ
The Max Z value in the obj file used to calculate the extents bbox.
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
GLuint m_textureID
The openGL id of the texture for the texture generation.
virtual void createVAO() noexcept
std::vector< GLuint > m_outIndices
a vectr of indices without duplicates which are actually passed to the VBO when creating ...
bool m_vboMapped
flag to indicate if the VBO vertex data has been mapped
GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat maxZ
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
Simple Bounding box class used in various parts of ngl and other example programs.
void drawBBox() const noexcept
method to draw the bounding box
Real m_minZ
The Min Z value in the obj file used to calculate the extents bbox.
unsigned int m_nTex
the number of texture co-ordinates in the object
size_t m_indexSize
the size of the index array
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
GLsizei const GLchar *const * string
Real m_minY
The Min Y value in the obj file used to calculate the extents bbox.
std::vector< Face > m_face
Pointer to the Face list.
bool m_vao
flag to indicate if a VBO has been created