Search Unity

Road Intersection mesh generation

Discussion in 'World Building' started by Artpen, Nov 26, 2020.

  1. Artpen

    Artpen

    Joined:
    Jan 24, 2015
    Posts:
    291
    Hi guys,

    For the last month I was learning about meshes and how procedurally generate them. For what I need it looks very straightforward.
    For my little app I planning to have a road tool (very simple), user draws lines and curves and road is generated with specific width (flat).
    So I can now create a drawing tool and generate simple mesh along the curve or line.
    Next step is to be able to construct intersections...

    I looked at lots of example but couldn't find any descriptions how it is done.
    Could you please advice what approach to take, how to identify intersection of two or multiple curves and generate mesh junction?

    Thank you

    Similar to this
    Screenshot 2020-11-26 at 08.13.39.png
     
  2. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    945
    Find the point of intersection and construct a mesh that respects the lane widths using the corners that you get from calculating the intersection of the vectors along the edges of those lanes and stitch them together.
    Alternatively find/write a method that just merges your already constructed plain meshes.
    if you intend to make your roads more useful to scripting or customizable, that's alot more complicated.
    You could have a look at https://github.com/MicroGSD/RoadArchitect that can probably give you some inspiration.
     
  3. Artpen

    Artpen

    Joined:
    Jan 24, 2015
    Posts:
    291
    Hi Flavelius,

    Thank you for the reply. Currently I am at very basic level. Can draw a line or curve with 2D mesh planes constructed along the path.

    Having trouble to find an approach to find intersections of lines?

    And I am not really sure I need to find an intersection of lines, maybe I have to find an intersection of meshes , using points coordinates with distance between them. If two points are close it means intersection is happening...

    Really hard to find anything useful online :(

    Just a wee test I did to explain what I am trying to achieve


    Also planning to make general mesh class which I can use for roads and also for buildings and land. Not sure it will work though.

    For land between roads, have you had a chance to find any good algorithm to generate a mesh from boundary points?
     
  4. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    945
    jjbish and Artpen like this.
  5. Artpen

    Artpen

    Joined:
    Jan 24, 2015
    Posts:
    291
  6. Sairam4123

    Sairam4123

    Joined:
    Oct 18, 2020
    Posts:
    2
    Hi, would you like to elaborate a little bit more on this? I mean this part.
    > construct a mesh that respects the lane widths using the corners that you get from calculating the intersection of the vectors along the edges of those lanes and stitch them together.
     
  7. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    945
    This touches a lot of topics, some with caveats that are quite complex. But basically, if you have a 'road', it's not just a line, it's more like two parallel 'edges' of that road that, when they intersect other edges (two roads joining) need to be merged with them. This involves calculating the point of intersection and tailoring your mesh generation algorithm to account for that. How that looks in detail will vary highly depending on everything involved. You could for example actually join them into a single mesh or, i think the linked asset does it, generate specific end-caps for each road and a separate joint-piece that conforms to those end-caps.