Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NavigationPolygon border_size property for tile baking #87961

Merged
merged 1 commit into from
Feb 7, 2024

Conversation

smix8
Copy link
Contributor

@smix8 smix8 commented Feb 4, 2024

Adds NavigationPolygon border_size property for tile baking. Also adds baking_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.

nav_mesh2_border_size

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.

tilebaking

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.

@smix8 smix8 added this to the 4.3 milestone Feb 4, 2024
@smix8 smix8 requested a review from a team as a code owner February 4, 2024 23:35
Adds NavigationPolygon border_size property for tile baking. Also adds baking Rect2 bounds.
@smix8 smix8 force-pushed the navmesh2d_bordersize branch from 8023a73 to 085bc95 Compare February 4, 2024 23:38
@akien-mga akien-mga changed the title Add NavigationPolygon border_size property for tile baking Add NavigationPolygon border_size property for tile baking Feb 6, 2024
Copy link
Member

@akien-mga akien-mga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not familiar enough with navigation to assess the feature, but the code and docs look good. Trusting smix8 and Scony on the usefulness of this new API.

@akien-mga akien-mga merged commit 8daa633 into godotengine:master Feb 7, 2024
16 checks passed
@akien-mga
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants