Adding vertices to mesh

Hi there, any mesh experts out there?

Im appending vertices to a mesh to extend it, like this:

The red dots are the vertices (most of which are covered by the fill).

This is the relevant code that resulted in that image (where bigMesh is the original large rectangle):

void ofApp::keyPressed(int key){

ofMesh mesh2;
mesh2.addVertex(ofVec3f(bigMesh.getVertices()[9].x+50, bigMesh.getVertices()[9].y,0));
mesh2.addVertex(ofVec3f(bigMesh.getVertices()[19].x+50, bigMesh.getVertices()[19].y,0));
mesh2.addVertex(ofVec3f(bigMesh.getVertices()[29].x+50, bigMesh.getVertices()[29].y,0));
mesh2.setMode(OF_PRIMITIVE_TRIANGLES);
bigMesh.append(mesh2);
bigMesh.addTriangle(9, 19, 100);
bigMesh.addTriangle(19, 100, 101);
}

I have a couple questions about the best way to do it.

  1. Do I need to call addTriangle on the mesh for every new vertex I add? Seems like if I dont add a triangle, the white fill will not cover the new vertex.

  2. Is there any way to add a column or row of vertices on an arbitrary side? Say, the left side for example; can I add vertices on the left without complicated mesh copying/ for loop vertex appending? I’m going to be using this logic in randomized terrain generation in a large application, so Im looking for the easiest way to do this.

Thanks!

somthing like this, in 2d, is easier to do with an ofPath where you don’t need to care about triangles, just define the outline of your shape and the ofPath will decompose it into triangles internally. When you work with ofMesh though you need to define the triangles your self since ofMesh is a more raw data container in the sense that is more or less directly used by the graphics card which only knows how to work with triangles

ok thanks arturo. My project is actually in 3D, but I’m working with these simple shapes first to get my bearings. I’ll just write a function to stitch new vertices/triangles onto my terrain. I just wanted to make sure I wasn’t overcomplicating things.

Thanks again!