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 navigation path simplification #90434

Merged
merged 1 commit into from
Apr 12, 2024
Merged

Conversation

smix8
Copy link
Contributor

@smix8 smix8 commented Apr 9, 2024

Adds navigation path simplification for NavigationServer and NavigationAgent.

Resolves #60277
Resolves #19011 (the oldest navigation issue back from 2018 ... weeee!)

This adds a variant of Ramer-Douglas-Peucker algorithm for 2D and 3D to simplify navigation paths.

Douglas-Peucker_animated

With this simplification enabled and a higher epsilon all the path points that are not critical points (like a corner or steep ground obstacle) will be removed from the path. The epsilon is in world units, so meters for 3D and pixels for 2D.

This helps with all kinds of agent movement problems in "open fields" and also helps with "steering" agents because they only have more critical path points to aim for.

Note that this simplification is a post-processing of the path query, so it does not help with path query performance, it adds performance cost.

navpath_simplify

NavigationAgents

The NavigationAgent2D and NavigationAgent3D have 2 new properties added to enable the simplification and control the epsilon.

navagent_simplify

NavigationPathQueryParameters

The NavigationPathQueryParameters2D and NavigationPathQueryParameters3D also have these 2 new properties added.

var parameters: NavigationPathQueryParameters2D = NavigationPathQueryParameters2D.new()
parameters.simplify_path = true
parameters.simplify_epsilon = 2.0
var parameters: NavigationPathQueryParameters3D = NavigationPathQueryParameters3D.new()
parameters.simplify_path = true
parameters.simplify_epsilon = 0.01

NavigationServer

The NavigationServer2D and NavigationServer3D have a new simplify_path() function added.

var path: PackedVector2Array = ....
var epsilon: float = 2.0
var simplified_path: PackedVector2Array = NavigationServer2D.simplify_path(path, epsilon)
var path: PackedVector3Array = ....
var epsilon: float = 0.01
var simplified_path: PackedVector3Array = NavigationServer3D.simplify_path(path, epsilon)

Because this NavigationServer function is not specific to navigation it can also be used with "any" path arrays.

E.g. it can also be used with point arrays commonly used in other nodes and classes like Line2D, Path2D, or Path3D.

path2d_simplify
path3d_simplify

@smix8 smix8 added this to the 4.x milestone Apr 9, 2024
@smix8 smix8 requested review from a team as code owners April 9, 2024 14:30
Copy link
Member

@mhilbrunner mhilbrunner left a comment

Choose a reason for hiding this comment

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

Approving the docs. The feature is useful to me, and the implementation looks clean and self-contained, and I didn't spot anything wrong or surprising during a brief code review. I however didn't build and test this.

Copy link
Member

@fire fire left a comment

Choose a reason for hiding this comment

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

Approving the feature, did not test the code yet.

@akien-mga akien-mga modified the milestones: 4.x, 4.3 Apr 9, 2024
@akien-mga
Copy link
Member

CC @Scony

Copy link
Contributor

@Scony Scony left a comment

Choose a reason for hiding this comment

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

Looks good - just an optional suggestion - I'd extend descriptions in .xml files so that "reason why this useful" is added. At the moment descriptions like:

If [code]true[/code] a simplified version of the path will be returned with less critical path points removed. The simplification amount is controlled by [member simplify_epsilon].

just explain what it does. Some users may find it useful if there's a one sentence summarizing when it's worth enabling that path optimization.

Adds navigation path simplification for NavigationServer and NavigationAgent.
@akien-mga akien-mga merged commit fcca9b3 into godotengine:master Apr 12, 2024
16 checks passed
@akien-mga
Copy link
Member

Thanks!

@smix8 smix8 deleted the path_simplify branch April 13, 2024 10:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants