Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Generating a plane with convex holes (at runtime via code)

Discussion in 'Scripting' started by nyonge, Jun 3, 2020.

  1. nyonge

    nyonge

    Joined:
    Jul 11, 2013
    Posts:
    49
    I need to generate a plane mesh with an arbitrary hole cut in it. Simple shapes are easy, but complex shapes become much more difficult. Doing this at runtime, C#

    Pics and captions below. Imgur album link in case those get removed: https://imgur.com/a/nmZLzE2

    Cross-post from an Answers question, sorry if that's no good! Hopefully this can help folks looking into mesh generation though?


    I want to generate a plane with an arbitrary hole cut in it I have a list of edges that make up their hole, and their normals. I also have the size of the hole overall, plus a border size.


    Generating a plane is easy. I'm struggling with generating the plane around a shape.


    A simple shape is relatively easy. I can get the nearest point on the outer edge from each of the shape's vertices. I can use those points, and neighbouring nearest-point-on-the-outer-edge points, to generate triangles.


    But complex shapes are a bit harder.


    It's still just made up of edges and normals. But what do I do about convex shapes that don't have an unobstructed line to the outermost edge?


    I want this to work with any shape, so long as it isn't self-intersecting (and even then it SHOULD still work, possibly by discarding the intersecting triangles).

    I can't detect the nearest point on the outermost plane edge. And I can't detect intersections because there are other edges with opposing normals in the way.

    Thank you!