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 mesh source geometry parsers and callbacks #90876

Merged
merged 1 commit into from
Apr 19, 2024

Conversation

smix8
Copy link
Contributor

@smix8 smix8 commented Apr 18, 2024

Add navigation mesh source geometry parsers and callbacks so that externals can hook their own geometry into the internal navigation mesh baking process.

Proposal godotengine/godot-proposals#5138

This can be used to hook addons, modules and extensions into the navigation mesh baking process.

E.g. Terrain3D or VoxelTool to name some examples. What all those extensions have currently in common is that they need to use suboptimal processes to add their geometry for navmesh baking and can't work frictionless with the default baking.

nav_baking

If a parser with callback is registered the Callable will be called for every single node that gets parsed when the NavigationServer parse_source_geometry_data() is used by something.

The Callable will get called with 3 args, the navigation mesh for the parse and bake properties, the source geometry object to add geometry to, and the actual node that gets parsed.

If the parser is no longer needed, e.g. because addon gets disabled, free the parser RID with the NavigationServer.

2D

var source_geometry_parser: RID
var source_geometry_parser_callback: Callable

func _ready() -> void:
	source_geometry_parser_callback = Callable(self, "_on_source_geometry_parser_callback")
	source_geometry_parser = NavigationServer2D.source_geometry_parser_create()
	NavigationServer2D.source_geometry_parser_set_callback(source_geometry_parser, source_geometry_parser_callback)

func _on_source_geometry_parser_callback(
	p_navigation_mesh: NavigationPolygon,
	p_source_geometry_data: NavigationMeshSourceGeometryData2D,
	p_parsed_node: Node) -> void:
	pass
	# Add custom source geometry to p_source_geometry_data.
	# The p_navigation_mesh holds the parse settings. Do NOT edit or add directly to p_navigation_mesh.
	# The p_parsed_node is the currently parsed node.

func delete_parser() -> void:
	NavigationServer2D.free_rid(source_geometry_parser)
	source_geometry_parser = RID()

3D

var source_geometry_parser: RID
var source_geometry_parser_callback: Callable

func _ready() -> void:
	source_geometry_parser_callback = Callable(self, "_on_source_geometry_parser_callback")
	source_geometry_parser = NavigationServer3D.source_geometry_parser_create()
	NavigationServer3D.source_geometry_parser_set_callback(source_geometry_parser, source_geometry_parser_callback)

func _on_source_geometry_parser_callback(
	p_navigation_mesh: NavigationMesh,
	p_source_geometry_data: NavigationMeshSourceGeometryData3D,
	p_parsed_node: Node) -> void:
	pass
	# Add custom source geometry to p_source_geometry_data.
	# The p_navigation_mesh holds the parse settings. Do NOT edit or add directly to p_navigation_mesh.
	# The p_parsed_node is the currently parsed node.

func delete_parser() -> void:
	NavigationServer3D.free_rid(source_geometry_parser)
	source_geometry_parser = RID()

@smix8
Copy link
Contributor Author

smix8 commented Apr 18, 2024

@Zylann and @TokisanGames might be interested in (reviewing) 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.

I did not do a technical review.

Would be good to squeeze into 4.3 as it would be many more months of hanging dry addons and extensions that can not really get their users to use the hot master build.

Would be good for gdextension authors as a quality of life enhancement.

@TokisanGames
Copy link
Contributor

@tcoxon is our resident expert on navigation in Terrain3D.

modules/navigation/3d/nav_mesh_generator_3d.h Outdated Show resolved Hide resolved
modules/navigation/3d/nav_mesh_generator_3d.cpp Outdated Show resolved Hide resolved
modules/navigation/3d/godot_navigation_server_3d.cpp Outdated Show resolved Hide resolved
modules/navigation/3d/godot_navigation_server_3d.cpp Outdated Show resolved Hide resolved
modules/navigation/2d/nav_mesh_generator_2d.h Outdated Show resolved Hide resolved
modules/navigation/2d/nav_mesh_generator_2d.cpp Outdated Show resolved Hide resolved
modules/navigation/2d/godot_navigation_server_2d.cpp Outdated Show resolved Hide resolved
modules/navigation/2d/godot_navigation_server_2d.cpp Outdated Show resolved Hide resolved
modules/navigation/2d/nav_mesh_generator_2d.cpp Outdated Show resolved Hide resolved
modules/navigation/3d/nav_mesh_generator_3d.cpp Outdated Show resolved Hide resolved
Adds navigation source geometry parser callbacks so that externals can hook their own geometry into the navigation mesh baking process.
@akien-mga akien-mga merged commit fba6803 into godotengine:master Apr 19, 2024
16 checks passed
@akien-mga
Copy link
Member

Thanks!

@smix8 smix8 deleted the source_geometry_callback branch April 19, 2024 18:50
dmlary added a commit to dmlary/godot-hex-map that referenced this pull request Sep 26, 2024
Signifcant rewrite/reorg of HexMap to improve maintainability.  Key
changes:

* split octants out of HexMap and into a dedicated class
* moved IndexKey into HexMapCellId::Key
* added NavigationMesh baking support[^1]
* added "cells_changed" signal
    * emitted only when cells are changed
    * will group changed cells into a single signal
    * cell ids emitted as Array<Vector3i> for performance reasons
* removed stale code & simplified feature set
    * dropped tile scaling; scale prior to export to the MeshLibrary, or
      scale in the MeshLibrary
    * dropped baked per-tile navigation mesh [^2]; use parent
      NavigationRegion and bake the NavigationMesh
    * dropped override support for baked NavigationMesh regions
    * dropped center-x and center-z toggles; these do not make sense to
      disable for hexagonal meshes
* converted HexMap functions to use CellId instead of Vector3i
    * GDScript functions do exist for Vector3i implementations to
      avoid the performance hit of Ref<T>
* switched from cell size to cell height & radius
* added property to display collision debug mesh
    * Debug->Visible Collision Shapes doesn't apply to the editor
    * allows viewing of collision shape in editor
* added minimal profiling stuff for macos only
* moved HexMap::Planes out into HexMapPlanes
    * fixed an #include problem

[^1]: godotengine/godot#90876
[^2]: https://chat.godotengine.org/channel/devel?msg=BnEXWRwfXsepXHmDg
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.

5 participants