Search Unity

Custom mesh problems

Discussion in 'Scripting' started by Balistic_penguin, Mar 28, 2017.

  1. Balistic_penguin

    Balistic_penguin

    Joined:
    Jan 18, 2017
    Posts:
    107
    I'm having a problem with a custom hexagon mesh. The shape of it is randomized and sometimes it overlaps itself like this:


    How can I set up the triangles and/or script them so that they don't overlap and just make a line from point to point?
     
  2. AndyGainey

    AndyGainey

    Joined:
    Dec 2, 2015
    Posts:
    216
    Depending on the nature of your randomness, you might be able to simply add an extra vertex in the middle (just take the average position of all the outer vertices), and then make a triangle fan around that middle vertex as the pivot, more like an umbrella. Doing so will of course increase the vertex and triangle count a bit, but will likely save plenty of programming time.

    Otherwise, you'll have to use some fancier algorithm to triangulate the polygon, such as decomposing it into multiple monotone polygons that can each be more easily triangulated.
     
  3. Balistic_penguin

    Balistic_penguin

    Joined:
    Jan 18, 2017
    Posts:
    107
    Adding another vertex worked, thanks!