I haven't actually started programming for this one yet, but I wanted to see how I would go about doing this anyway.
Say I have a grid of tiles, all of the same size, some traversable and some not. How would I go about creating a navigation mesh of polygons from this grid?
My idea was to take the non-traversable tiles out and extend lines from there edges to make polygons... that's all I have got so far. Any advice?
Answer
Here's one of the methods I came up with when doing navmesh for an RTS game. Note that it is homebrew, no third-party tools were used, it took me about 3 weeks to implement and bugfix:
- Use Marching Squares algorithm to convert obstacle tiles into outlines. Note that map edges is an outline too and need to be included as well.
- Reduce number of points in outlines using Douglas-Peucker algorithm (purple lines on the bottom picture)
- Feed all points into Delaunay triangulation (to get most uniform triangles)
- Add additional points in empty areas and along the map edges (to get more even navmesh)
- Check along obstacle outlines and flip polygons produced by Delaunay to match outlines. - Often Delaunay could place triangles (grey) mismatching your outlines (red), then you need to detect and flip them. Adjoining them back into a polygon, split it along outline(s) and triangulate it manually
- Clip obstacles innards - remove polygons that are within obstacles (pink on the picture above)
- Fill in connectivity data between remaining triangles and vertices as you need - that's your navmesh.
Result:
No comments:
Post a Comment