Working with vertices

There are a number of functions for accessing the vertices and their properties:

  • The getNumVertices() function returns the number of vertices.
  • The getVertex( i ) function returns the position of the vertex with index i.
  • The setVertex( i, p ) function sets the position of vertex i to p. Note that this function can change the vertex but it cannot add a new vertex. So if i is greater or equal to mesh.getNumVertices(), you need to add a vertex (or vertices) using the mesh.addVertex( p ) function as described in the Using ofMesh section.
  • The removeVertex( i ) function deletes the vertex with index i. Be very careful when using this function; after deleting a vertex, you should probably also delete the corresponding normal, color, and texture coordinate, and change the indices of the triangles to keep its coherence.
  • The clearVertices() function deletes all the vertices. See corresponding cautions for removeVertex().
  • The clear() function clears the mesh, including its vertices, normals, and all other arrays.

After changing vertices, you will most probably need to update the normals using the setNormals( mesh ) function, as described in the Computing normals using the setNormals() function section.

There are similar functions for controlling normals, colors, texture coordinates, and indices; for example, functions getNumNormals(), getNumColors(), getNumTexCoords(), and getNumIndices() return number of normals, colors, texture coordinates, and indices respectively.

Let's see a simple example of modifying the positions of the vertices.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset