'How to constuct complex mesh from premade list of vertices?

I am trying to create a procedual dungeon generator. I have the floor working perfectly and have created a list of edge vertices for the walls. I duplicate the edge vertices and raise them up by the wall height and now I want to fill in the vertices with the actual wall mesh aka the tris. This is how it looks The edge vertices

Essentially I have to connect the dots However I have concluded my winding order is incorrect. Incorrect winding order

When I generate the edge vertices I run it in a nested for loop that goes along the Z axis first and then the X axis.

for(int z = 0; z < dungeonLength; z++) {
   for(int x = 0; x < dungeonWidth; x++) {
      // Generate verts here
   }
}

All I want it to do is wrap around the level. An example level of what I wish to wrap around

So at the end what do I have. I have a list of vertices, they are not ordered correctly as they go along the Z points first then the X, generating it as it is right now yields broken results How it currently looks with generated mesh

Any advice on how to handle this would be appriciated.



Solution 1:[1]

I finally figured out a solution.

I have a function called "AddEdge" where I can pass in an edge position and the direction I want it to face. This will construct my quad.

Since I'm running off a grid I pass the current cell I'm checking into a "DrawWall" function if its a wall tile or corner tile.

This DrawWall function will check any adjacent cells to that tile. If any adjacent cells are either null (outside the grid) or empty it will check the direction of that adjacent cell and add a edge accordingly.

Rinse and repeat this process for each wall.

The end result looks how I want it to look The end result

Think of it like a voxel environment where you have a chunk of cubes and you want to only render faces that are not obscuring eachother.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Lyraedan