The simplest way to achieve sharp edges is to add the vertices for all the triangles in mesh
and not use the addTriangle()
function at all and then call the mesh.setupIndicesAuto()
function, which sets indices automatically such that vertices (0, 1, 2) are used for drawing the first triangle, vertices (4, 5, 6) for the second triangle, and so on.
In the example with the pyramid, replace all the lines with addVertex()
and addTriangle()
with the following lines:
//Pyramid's base vertices
ofPoint v0 = ofPoint( -200, -100, 0 );
ofPoint v1 = ofPoint( 200, -100, 0 );
ofPoint v2 = ofPoint( 0, 200, 0 );
//Pyramid's top vertex
ofPoint v3 = ofPoint( 0, 0, 100 );
//Add triangles by its vertices
mesh.addVertex( v3 ); mesh.addVertex( v2 ); mesh.addVertex( v0 );
mesh.addVertex( v3 ); mesh.addVertex( v1 ); mesh.addVertex( v2 );
mesh.addVertex( v3 ); mesh.addVertex( v0 ); mesh.addVertex( v1 );
mesh.setupIndicesAuto(); //Set up indices
As a result, you will see a pyramid with sharp edges as shown in the following screenshot:
We have considered a basic workflow with meshes. Now we will consider other useful capabilities of the ofMesh
class.