Is there any way to know the specific
vertice(s) of this new combine
mesh?
Sure, just remember where you put what. The structure of your vertex buffer is completely up to you. So you have to come up with a strategy how you want to lay out your vertices so you know where they are.
Note: What you’re describing is actually a “folded” plane mesh. Though such a mesh, if stretched out would have square holes in it in a regular pattern like this:
left is the “unfolded” / flattened view while on the right is the folded view. Now you just have to generate the vertices / triangles in a logical way so it’s easy to access / find the position of one of those quads. Since each quad needs its own set of 4 vertices (in order to have a flat shaded surface), I would probably first lay out all the “red” (top) quads, just the way they are seen in the folded version. Now if you look closely at just the horizontal connecting green quads, there are just as many rows as there are rows in the folded mesh. However in my case one column is missing (since they are only in between the top faces). You probably also want the outermost faces as well, so just imagine another column at the left side and another on the right side. So if we have a grid that is 7x5, we need 8x5 horizontal connecting quads. Likewise the vertical connecting quads we have 7x6 of them.
Overall if you want to change the top face of a cell, you would just take the row and column index and use the usual (col + row*xCount)
to get the “cell index”. Since each cell top face requires 4 vertices multiply the cell index by 4 any you get the vertex offset (of course the 4 vertices would come one after the other in a fix pattern as well). To get the horizontal / vertical connecting quads, the same cell index can be used, but of course with an offset of xCountyCount4 which is the end of the top faces.
Now you just have to access the connecting quads adjacent to the cell you want to change and modify only the two adjacent vertices. Since the layout of the vertices of a quad should always be the same, it’s just a matter of picking the right offsets.
Note in my case it’s assumed that the “walls” between the cells are always the same. This layout has the advantage that unnecessary faces are already removed and the connecting faces automatically flip over if necessary. So if a cell is first at a lower position than the neighbors, the walls would face inwards forming the walls of the 4 neighboring cells. When moving the cell upwards, those walls would flip over and form the outside of the now higher cell.
if you actually need the possibility for the walls to have a different texture for each cell, or the wall texture has an “orientation” this technique is probably to complicated as adjusting the UVs accordingly would make things quite complicated. In this case it makes more sense to store “cube by cube” (so all 5 faces just right next to each other). I would still start with the top face and then the 4 wall quads in a fix order (something like top, left, bottom, right). So in this case we would have 20 vertices per cell. The calculation with the cell index would still work the same way, though we now multiply by 20 instead of 4. Such a layout requires about 66% more quads (if the grid is relatively large) than the first method.
Note in general when doing procedural meshing, you don’t wnat to combine already existing meshes. Instead you should create the mesh completely procedurally. That way you have full control over where the vertices are.