Function TileHandler.SnapEdges
Find cut vertices that lie exactly on the polygon edges, and insert them into the polygon.
void SnapEdges (
ref NativeArray<Point64Wrapper> | triBuffer | |
ref int | vertexCount | |
contours | ||
ref NativeList<int> | interestingCuts | |
ref NativeArray<Point64Wrapper> | contourVerticesP64 |
Find cut vertices that lie exactly on the polygon edges, and insert them into the polygon.
These vertices will need to be added to the polygon outline before cutting, to ensure they end up in the final triangulation. This is because adjacent triangles may have a cut there, and if this triangle doesn't also get a cut there, connections between nodes may not be created properly.
/| /\ / | / \ / |/ / /___| \ /
The EdgeSnappingMaxDistance must be at least 1 (possibly only 0.5) for this to handle all edge cases. If it is larger, it will nicely prevent too small triangles, but it can also cause issues when snapping very thin triangles so much that they become invalid. So a value of 1 seems best.
Using this method adds some overhead for cutting, but it is necessary to handle edge cases where navmesh cuts exactly touch the edges of the triangles. The overhead seems to be roughly 1% of the total cutting time.