Tucano
0.1
A library for rapid prototyping with modern OpenGL and GLSL
|
The Mesh Class contains many basic methods to quickly load and use a mesh.
A Mesh Object contains Vertex Attributes, that are translated into OpenGL Arrays. Vertex Attributes are information per vertex, such as coordinates, normals, color, etc...
If you have an OBJ
file, you can simple load it by:
The PLY importer is equivalent.
When reading a file, the importer will look for the following vertex attributes and automatically load them with the following names:
To add a new attribute to your Mesh, lets say a Secondary Color Attribute, pass the vector with the values and the name of the attribute to the Mesh:
and link the Attributes with your Shader:
The setAttributeLocation method receives a pointer to a Shader, and looks for matches by name. If you name your shader in variables as:
they are automatically linked to the Mesh Vertex Attributes named "in_Position" and "in_SecondaryColor".
If you have different names for the Shader variable and the corresponding Vertex Attribute, you can still link the attribute:
Note that you might need to reset the locations when linking the names manually (resetLocations
is already called by setAttributeLocation
):
The Mesh Class extends the Model Class, that basically contains spatial information about the model, i.e, a Model Matrix.
To normalize the Mesh coordinates to fit in a unit cube centered at the origin, update the Model Matrix with the following call.
Note, however, that information such as centroid and scale are computed by the Importer, so if the Mesh was filled manually they have to be computed to use the normalization method.
Pass your Model Matrix to your Shader to apply the transformation:
and read it in your myshader code: