Invalid polygon triangulation

Avatar
  • updated
  • Declined

I am trying to create a progress bar in a custom polygon shape, as seen below.  The polygon in blue fills up to indicate the durability of a shield.

Image 621

However, at certain point configurations, I am getting the following error:

Invalid polygon triangulation - no convex edges found. Your polygon is likely self-intersecting.
Failed point set:
[1]: Reflex
[3]: Reflex
[4]: Reflex
[6]: Reflex
[7]: Reflex
[9]: Reflex
[10]: Reflex

This comes about when the points are set as follows - the y-position between the first set of points (0.04505) is very close to the second set of points (0.045):

Image 622

If I modulate the y-position of the first set of points, then values about y = 0.0451316 render fine without creating the invalid polygon triangulation error.  I can create a hack in my code to clamp y-values to this threshold, but it seems like a bug in the triangulation code? 

Reporting a bug? please specify Unity version:
2021.3.3 LTS
Reporting a bug? please specify Shapes version:
4.1.3
Reporting a bug? please specify Render Pipeline:
URP
Avatar
airoll
Quote from Freya Holmér

I uh, I'm working on getting better! got work done today at least, so that's good, I think!

That's good to hear! Quick follow up question, now that I realized that you can do this with polygons, is there any way to create a fill with lines or discs?  I'm guessing not because it doesn't look like I can set anything in the editor to that extent?  But even if it were possible, would it be less performant than having a line for the meter on top of a line for the background?

Avatar
Freya Holmér creator

I uh, I'm working on getting better! got work done today at least, so that's good, I think!

Avatar
airoll

Wow I didn't know you could do that,  thank you so much Freya!  Thanks so much for the quick response. Hope you are doing better these days! 


Avatar
Freya Holmér creator
  • Declined

this is a side effect of floating point precision and making polygons that are very close to degenerate, which is what you have in your case. Well, there are two issues - first, you have two identical points after each other, this will always lead to triangulation errors, but even if you remove the duplicate point (point #3), it still fails to triangulate. Fixing this issue on my end is difficult, because it will almost certainly make the algorithm much slower for more valid cases too, not just the near-degenerate cases like this one.

I would recommend not altering the vertices for this progress bar, but instead you can always show the full polygon, using the linear fill gradient to indicate progress. This is also much faster from a performance point of view