Tucano  0.1
A library for rapid prototyping with modern OpenGL and GLSL
Tucano::Mesh Class Reference

A common Mesh, usually containing triagles or points. More...

#include <mesh.hpp>

Inheritance diagram for Tucano::Mesh:
Tucano::Model Tucano::Shapes::Arrow Tucano::Shapes::Box Tucano::Shapes::CameraRep Tucano::Shapes::Cone Tucano::Shapes::Cylinder Tucano::Shapes::Plane Tucano::Shapes::Quad Tucano::Shapes::Sphere

Public Member Functions

 Mesh (void)
 Default Constructor. More...
 
int getNumberOfElements (void)
 Returns the number of elements (primitives such as triangles) of the mesh. More...
 
int getNumberOfVertices (void)
 Returns the number of vertices in the mesh. More...
 
void resetLocations (void)
 Resets all vertex attributes locations to -1. More...
 
void reset (void)
 
void loadVertices (vector< Eigen::Vector4f > &vert)
 Load vertices (x,y,z,w) and creates appropriate vertex attribute. The default attribute name is "in_Position". Computes bounding box and centroid and normalization factors (scale). More...
 
void loadNormals (vector< Eigen::Vector3f > &norm)
 Load normals (x,y,z) as a vertex attribute. More...
 
void loadTexCoords (vector< Eigen::Vector2f > &tex, bool normalize=false)
 Load tex coords (u,v) as a vertex attribute. Optionally normalizes coords in range [0,1]. More...
 
void loadColors (vector< Eigen::Vector4f > &clrs)
 Load colors (r,g,b,a) as a vertex attribute. More...
 
void loadIndices (vector< GLuint > &ind)
 Load indices into indices array. More...
 
void setDefaultAttribLocations (void)
 Sets default attribute locations. vertex coords -> location 0 normals -> location 1 colors -> location 2 texCoords -> location 3. More...
 
bool hasAttribute (const string &name) const
 Returns wether an attribute exists or not. More...
 
VertexAttributegetAttribute (const string &name)
 Returns a pointer to an attribute Given an attribute name, searches to see if it exists, if so, returns a pointer to it. More...
 
void setAttributeLocation (Shader *shader)
 Automatically sets the attribute locations for a given Shader. More...
 
void setAttributeLocation (const Shader &shader)
 
void setAttributeLocation (string name, GLint loc)
 Sets the location of a generic vertex attribute. More...
 
VertexAttributecreateAttribute (string name, vector< Eigen::Vector4f > &attrib)
 Creates and loads a new mesh attribute of 4 floats. More...
 
VertexAttributecreateAttribute (string name, vector< Eigen::Vector3f > &attrib)
 Creates and loads a new mesh attribute of 3 floats. More...
 
VertexAttributecreateAttribute (string name, vector< Eigen::Vector2f > &attrib)
 Creates and loads a new mesh attribute of 2 floats. More...
 
virtual void bindBuffers (void)
 Binds all buffers. More...
 
virtual void unbindBuffers (void)
 Unbinds all buffers. More...
 
virtual void renderPoints (void)
 Render only points without index buffer. More...
 
virtual void renderElements (void)
 Call the draw method for rendering triangles. This method requires that a index buffer has been created. More...
 
virtual void renderLineLoop (void)
 Render all vertices as a continous line loop. More...
 
virtual void renderPatches (void)
 Call the draw method for rendering patches. This method requires that a index buffer has been created. More...
 
virtual void render (void)
 Render the mesh triangles. The method binds the buffers, calls the method to render triangles, and then unbinds all buffers. Note that a index buffer is necessary. More...
 
void createParallelepiped (float x, float y, float z)
 Sets the mesh as a Parallelpiped with given dimensions, scales so larger side is equal to 1. More...
 
void createQuad (void)
 Sets the mesh as Unit Quad. More...
 
- Public Member Functions inherited from Tucano::Model
 Model (void)
 
Eigen::Vector4f getColor (void)
 Returns the default color of the model. More...
 
void setColor (const Eigen::Vector4f &color)
 Sets the default color of the model. More...
 
virtual Eigen::Vector3f getObjectCenter (void) const
 Returns the center of the axis-aligned bounding box. More...
 
virtual Eigen::Vector3f getCentroid (void) const
 Returns the centroid of the model. More...
 
virtual float getBoundingSphereRadius (void) const
 
Eigen::Affine3f getModelMatrix (void) const
 Returns the model matrix. More...
 
Eigen::Affine3f * modelMatrix (void)
 Returns a pointer to the model matrix. More...
 
void setModelMatrix (const Eigen::Affine3f &m)
 Sets the model matrix. More...
 
float getScale (void) const
 Returns the scale factor for fitting the model inside a unit cube. More...
 
void normalizeModelMatrix (void)
 Normalize model matrix to center and scale model. The model matrix will include a translation to place model's centroid at the origin, and scale the model to fit inside a unit sphere. More...
 
void desnormalizeModelMatrix (void)
 Desnormalize model matrix. More...
 
void resetModelMatrix (void)
 Resets the model matrix. More...
 

Protected Attributes

vector< Tucano::VertexAttributevertex_attributes
 Array of generic attributes. More...
 
unsigned int numberOfVertices = 0
 Number of vertices in vertices array. More...
 
unsigned int numberOfNormals = 0
 Number of normals in normals array. More...
 
unsigned int numberOfElements = 0
 Number of indices in indices array. More...
 
unsigned int numberOfTexCoords = 0
 Number of texture coordinates in texCoords array. More...
 
unsigned int numberOfColors = 0
 Number of colors in colors array. More...
 
GLuint index_buffer_id = 0
 Index Buffer. More...
 
GLuint vao_id = 0
 Vertex Array Object ID (VAO is just a descriptor, does not contain any data) More...
 
bool willTessellate = false
 Variable indicating if there will be tessellation. More...
 
std::shared_ptr< GLuint > index_buffer_sptr = 0
 Shared pointer for index buffer. More...
 
std::shared_ptr< GLuint > vao_sptr = 0
 Shared pointer for vertex array object. More...
 
- Protected Attributes inherited from Tucano::Model
Eigen::Affine3f model_matrix
 Model matrix, holds information about the models location and orientation. More...
 
Eigen::Vector3f objectCenter
 Center of the mesh object. More...
 
Eigen::Vector3f centroid
 Object's centroid (different from center of bounding box) More...
 
float radius
 Radius of the mesh bounding sphere. More...
 
float scale
 The normalization scale factor, scales the model matrix to fit the model inside a unit cube. More...
 
Eigen::Vector4f default_color = Eigen::Vector4f (0.7, 0.7, 0.7, 1.0)
 Default color. More...
 

Detailed Description

A common Mesh, usually containing triagles or points.

The Mesh class handles the buffers generation and usage. such as VBO. IBO. TBO... It also contains methods for simple meshes generation. (e.g. a quadrilateral or a cube) and a wavefront .obj loader. When a mesh is generated. geometrical computations are performed. detecting the center of the mesh through the axis-aligned bounding box and computing normalizating scale factors. The attribute locations are predefined in this class. being the location 0 used for Vertex Buffer. 1 for Normals Buffer. 2 for Color Buffer and 3 for TexCoord Buffer.

Constructor & Destructor Documentation

Tucano::Mesh::Mesh ( void  )
inline

Default Constructor.

Member Function Documentation

virtual void Tucano::Mesh::bindBuffers ( void  )
inlinevirtual

Binds all buffers.

If there is a index buffer it will also be binded. Then, binds one buffer for each vertex attribute.

VertexAttribute* Tucano::Mesh::createAttribute ( string  name,
vector< Eigen::Vector4f > &  attrib 
)
inline

Creates and loads a new mesh attribute of 4 floats.

Parameters
nameName of the attribute.
attribArray with new attribute.
Returns
Pointer to created attribute
VertexAttribute* Tucano::Mesh::createAttribute ( string  name,
vector< Eigen::Vector3f > &  attrib 
)
inline

Creates and loads a new mesh attribute of 3 floats.

Parameters
nameName of the attribute.
attribArray with new attribute.
Returns
Pointer to created attribute
VertexAttribute* Tucano::Mesh::createAttribute ( string  name,
vector< Eigen::Vector2f > &  attrib 
)
inline

Creates and loads a new mesh attribute of 2 floats.

Parameters
nameName of the attribute.
attribArray with new attribute.
Returns
Pointer to created attribute
void Tucano::Mesh::createParallelepiped ( float  x,
float  y,
float  z 
)
inline

Sets the mesh as a Parallelpiped with given dimensions, scales so larger side is equal to 1.

Parameters
xWidth
yHeight
zDepth
void Tucano::Mesh::createQuad ( void  )
inline

Sets the mesh as Unit Quad.

VertexAttribute* Tucano::Mesh::getAttribute ( const string &  name)
inline

Returns a pointer to an attribute Given an attribute name, searches to see if it exists, if so, returns a pointer to it.

Parameters
nameAttribute name
Returns
Pointer to attribute, or NULL if it does not exist
int Tucano::Mesh::getNumberOfElements ( void  )
inline

Returns the number of elements (primitives such as triangles) of the mesh.

Returns
Number of primitives.
int Tucano::Mesh::getNumberOfVertices ( void  )
inline

Returns the number of vertices in the mesh.

Returns
Number of vertices.
bool Tucano::Mesh::hasAttribute ( const string &  name) const
inline

Returns wether an attribute exists or not.

Parameters
nameName of attribute to be queried.
Returns
True if attribute exists, false otherwise.
void Tucano::Mesh::loadColors ( vector< Eigen::Vector4f > &  clrs)
inline

Load colors (r,g,b,a) as a vertex attribute.

Parameters
clrsColors array.
void Tucano::Mesh::loadIndices ( vector< GLuint > &  ind)
inline

Load indices into indices array.

Parameters
indIndices array.
void Tucano::Mesh::loadNormals ( vector< Eigen::Vector3f > &  norm)
inline

Load normals (x,y,z) as a vertex attribute.

Parameters
normNormals list.
void Tucano::Mesh::loadTexCoords ( vector< Eigen::Vector2f > &  tex,
bool  normalize = false 
)
inline

Load tex coords (u,v) as a vertex attribute. Optionally normalizes coords in range [0,1].

Parameters
texTexture coordinates array.
normalizeIf true normalizes the texcoords in range [0,1], otherwise does not normalize.
void Tucano::Mesh::loadVertices ( vector< Eigen::Vector4f > &  vert)
inline

Load vertices (x,y,z,w) and creates appropriate vertex attribute. The default attribute name is "in_Position". Computes bounding box and centroid and normalization factors (scale).

Parameters
vertArray of vertices.
virtual void Tucano::Mesh::render ( void  )
inlinevirtual

Render the mesh triangles. The method binds the buffers, calls the method to render triangles, and then unbinds all buffers. Note that a index buffer is necessary.

virtual void Tucano::Mesh::renderElements ( void  )
inlinevirtual

Call the draw method for rendering triangles. This method requires that a index buffer has been created.

virtual void Tucano::Mesh::renderLineLoop ( void  )
inlinevirtual

Render all vertices as a continous line loop.

virtual void Tucano::Mesh::renderPatches ( void  )
inlinevirtual

Call the draw method for rendering patches. This method requires that a index buffer has been created.

virtual void Tucano::Mesh::renderPoints ( void  )
inlinevirtual

Render only points without index buffer.

void Tucano::Mesh::reset ( void  )
inline
void Tucano::Mesh::resetLocations ( void  )
inline

Resets all vertex attributes locations to -1.

void Tucano::Mesh::setAttributeLocation ( Shader shader)
inline

Automatically sets the attribute locations for a given Shader.

For every mesh attribute, the Shader will be queried for an attribute with the same name, if one is found they will linked.

Parameters
shaderA pointer to the given shader.
void Tucano::Mesh::setAttributeLocation ( const Shader shader)
inline
void Tucano::Mesh::setAttributeLocation ( string  name,
GLint  loc 
)
inline

Sets the location of a generic vertex attribute.

Parameters
nameName of the given attribute
locLocation of the attribute.
void Tucano::Mesh::setDefaultAttribLocations ( void  )
inline

Sets default attribute locations. vertex coords -> location 0 normals -> location 1 colors -> location 2 texCoords -> location 3.

virtual void Tucano::Mesh::unbindBuffers ( void  )
inlinevirtual

Unbinds all buffers.

Member Data Documentation

GLuint Tucano::Mesh::index_buffer_id = 0
protected

Index Buffer.

std::shared_ptr< GLuint > Tucano::Mesh::index_buffer_sptr = 0
protected

Shared pointer for index buffer.

unsigned int Tucano::Mesh::numberOfColors = 0
protected

Number of colors in colors array.

unsigned int Tucano::Mesh::numberOfElements = 0
protected

Number of indices in indices array.

unsigned int Tucano::Mesh::numberOfNormals = 0
protected

Number of normals in normals array.

unsigned int Tucano::Mesh::numberOfTexCoords = 0
protected

Number of texture coordinates in texCoords array.

unsigned int Tucano::Mesh::numberOfVertices = 0
protected

Number of vertices in vertices array.

GLuint Tucano::Mesh::vao_id = 0
protected

Vertex Array Object ID (VAO is just a descriptor, does not contain any data)

std::shared_ptr< GLuint > Tucano::Mesh::vao_sptr = 0
protected

Shared pointer for vertex array object.

vector< Tucano::VertexAttribute > Tucano::Mesh::vertex_attributes
protected

Array of generic attributes.

bool Tucano::Mesh::willTessellate = false
protected

Variable indicating if there will be tessellation.


The documentation for this class was generated from the following file: