Road mesh creation based on grid

Hi, I’d like to place roads on a grid with square grid positions. A few points:

  • All roads will be straight and not diagonal across cells

  • Roads will either be dot (no connected road), single, straight, corner, tee or cross

  • Grid cells are made up of 2x triangles. A road can be placed on the cell if it is flat or within a specific incline in one direction (north, south, east or west)

I’m unsure on the following points:

  • When a road is placed on a cell, that cell as well as the north, south east and west cells are updated. When a cell is updated it runs through a switch with 16x cases to define the road type and orientation. Is there a less intensive way of doing this?
  • The easiest way to generate the road mesh would be to generate a separate mesh for each cell with a road on it. This also seems a bit intensive? Would the mesh draw calls be batched?
  • I was thinking another way to do it would be to create a mesh for each type of road, all cells with that type of road would go onto one mesh (within a certain area depending on grid size). I think this would be okay for straight roads but unsure how to do this for corners and tees. If there’s two corners or tees connecting and sharing vertices, how would i handle the uvs? Would I have to duplicate vertices? Should you ever duplicate vertices (it seems wrong)?
  • Is there another way of doing this that I’m missing?

Thanks for any help on this! When I get chance, I’m going to go with the separate meshes per cell to begin with because it will be the easiest! But just wanted to get some more opinions on it as well.

What have you got so far?

The purpose of this forum is to assist people who are ready to learn by doing, and who are unafraid to get their hands dirty learning how to code, particularly in the context of Unity3D.

I recommend starting with any Youtube tutorial for how to make the existing game that is closest to your idea.

If you want to see some of my examples of procedural generation, check out my MakeGeo project.

MakeGeo is presently hosted at these locations:

https://bitbucket.org/kurtdekker/makegeo