Add NavigationPolygon border_size
property for tile baking
#87961
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adds NavigationPolygon
border_size
property for tile baking. Also addsbaking_rect
Rect2 bounds.This is a 2D version of #87378.
This allows users to partition larger game worlds into regions that have navigation meshes with easy to align tile edges. This tile edges can be efficiently merged by the navigation map using edgekeys. It also avoids problems with the agent_radius offset affecting the tile edges.
Since 2D had no baking AABB like 3D this also adds a baking Rect2 for 2D to the NavigationPolygon that allows to limit the baked area with a rectangle. This rect also clips the outline polygons upfront before the major polygon operations so using this can help to avoid a lot of unnecessary processing by discarding all polygons parts outside this rect.
The difference between baking Rect and border size is, that the Rect limits the entire source geometry used in the baking as a bounding area while the border size limits the surface of the resulting navigation mesh.
This means in conjunction they can be used to limit the final navigation mesh without having unwanted offsets by e.g. agent radius at tile edges.
E.g. this allows to split a large Tilemap into source geometry chunks and bake chunk navigation meshes that have border edges aligned so they can be merged efficiently by the navigation map without using the edge connection margin.
So more advanced users can start to only bake navigation mesh chunks around their active actors instead of for the entire TileMap. (Re)baking a large TileMap as one big navigation mesh is basically performance impossible at runtime and also not very efficient in general.
This also adds a few smaller performance improvements like reserve() for the larger std::vectors for a small but still noticeable speedup on large maps.
Note that while the functions accepts a float and Rect2 value the final value used by the baking when all positions and additions are added up will be rasterized to an integer grid.