diff options
23 files changed, 230 insertions, 2 deletions
diff --git a/doc/classes/NavigationRegion2D.xml b/doc/classes/NavigationRegion2D.xml index bb5992f112..1f1c0993d5 100644 --- a/doc/classes/NavigationRegion2D.xml +++ b/doc/classes/NavigationRegion2D.xml @@ -76,5 +76,8 @@ <member name="travel_cost" type="float" setter="set_travel_cost" getter="get_travel_cost" default="1.0"> When pathfinding moves inside this region's navigation mesh the traveled distances are multiplied with [code]travel_cost[/code] for determining the shortest path. </member> + <member name="use_edge_connections" type="bool" setter="set_use_edge_connections" getter="get_use_edge_connections" default="true"> + If enabled the navigation region will use edge connections to connect with other navigation regions within proximity of the navigation map edge connection margin. + </member> </members> </class> diff --git a/doc/classes/NavigationRegion3D.xml b/doc/classes/NavigationRegion3D.xml index a123381901..0988d07e8c 100644 --- a/doc/classes/NavigationRegion3D.xml +++ b/doc/classes/NavigationRegion3D.xml @@ -61,6 +61,9 @@ <member name="travel_cost" type="float" setter="set_travel_cost" getter="get_travel_cost" default="1.0"> When pathfinding moves inside this region's navigation mesh the traveled distances are multiplied with [code]travel_cost[/code] for determining the shortest path. </member> + <member name="use_edge_connections" type="bool" setter="set_use_edge_connections" getter="get_use_edge_connections" default="true"> + If enabled the navigation region will use edge connections to connect with other navigation regions within proximity of the navigation map edge connection margin. + </member> </members> <signals> <signal name="bake_finished"> diff --git a/doc/classes/NavigationServer2D.xml b/doc/classes/NavigationServer2D.xml index f9e6a69452..e2293f2439 100644 --- a/doc/classes/NavigationServer2D.xml +++ b/doc/classes/NavigationServer2D.xml @@ -404,6 +404,13 @@ Returns all navigation regions [RID]s that are currently assigned to the requested navigation [param map]. </description> </method> + <method name="map_get_use_edge_connections" qualifiers="const"> + <return type="bool" /> + <param index="0" name="map" type="RID" /> + <description> + Returns whether the navigation [param map] allows navigation regions to use edge connections to connect with other navigation regions within proximity of the navigation map edge connection margin. + </description> + </method> <method name="map_is_active" qualifiers="const"> <return type="bool" /> <param index="0" name="map" type="RID" /> @@ -443,6 +450,14 @@ Set the map's link connection radius used to connect links to navigation polygons. </description> </method> + <method name="map_set_use_edge_connections"> + <return type="void" /> + <param index="0" name="map" type="RID" /> + <param index="1" name="enabled" type="bool" /> + <description> + Set the navigation [param map] edge connection use. If [param enabled] the navigation map allows navigation regions to use edge connections to connect with other navigation regions within proximity of the navigation map edge connection margin. + </description> + </method> <method name="obstacle_create"> <return type="RID" /> <description> @@ -559,6 +574,13 @@ Returns the travel cost of this [param region]. </description> </method> + <method name="region_get_use_edge_connections" qualifiers="const"> + <return type="bool" /> + <param index="0" name="region" type="RID" /> + <description> + Returns whether the navigation [param region] is set to use edge connections to connect with other navigation regions within proximity of the navigation map edge connection margin. + </description> + </method> <method name="region_owns_point" qualifiers="const"> <return type="bool" /> <param index="0" name="region" type="RID" /> @@ -625,6 +647,14 @@ Sets the [param travel_cost] for this [param region]. </description> </method> + <method name="region_set_use_edge_connections"> + <return type="void" /> + <param index="0" name="region" type="RID" /> + <param index="1" name="enabled" type="bool" /> + <description> + If [param enabled] the navigation [param region] will use edge connections to connect with other navigation regions within proximity of the navigation map edge connection margin. + </description> + </method> <method name="set_debug_enabled"> <return type="void" /> <param index="0" name="enabled" type="bool" /> diff --git a/doc/classes/NavigationServer3D.xml b/doc/classes/NavigationServer3D.xml index 3fe0793715..cc6b3b8ca4 100644 --- a/doc/classes/NavigationServer3D.xml +++ b/doc/classes/NavigationServer3D.xml @@ -461,6 +461,13 @@ Returns the map's up direction. </description> </method> + <method name="map_get_use_edge_connections" qualifiers="const"> + <return type="bool" /> + <param index="0" name="map" type="RID" /> + <description> + Returns true if the navigation [param map] allows navigation regions to use edge connections to connect with other navigation regions within proximity of the navigation map edge connection margin. + </description> + </method> <method name="map_is_active" qualifiers="const"> <return type="bool" /> <param index="0" name="map" type="RID" /> @@ -508,6 +515,14 @@ Sets the map up direction. </description> </method> + <method name="map_set_use_edge_connections"> + <return type="void" /> + <param index="0" name="map" type="RID" /> + <param index="1" name="enabled" type="bool" /> + <description> + Set the navigation [param map] edge connection use. If [param enabled] the navigation map allows navigation regions to use edge connections to connect with other navigation regions within proximity of the navigation map edge connection margin. + </description> + </method> <method name="obstacle_create"> <return type="RID" /> <description> @@ -641,6 +656,13 @@ Returns the travel cost of this [param region]. </description> </method> + <method name="region_get_use_edge_connections" qualifiers="const"> + <return type="bool" /> + <param index="0" name="region" type="RID" /> + <description> + Returns true if the navigation [param region] is set to use edge connections to connect with other navigation regions within proximity of the navigation map edge connection margin. + </description> + </method> <method name="region_owns_point" qualifiers="const"> <return type="bool" /> <param index="0" name="region" type="RID" /> @@ -707,6 +729,14 @@ Sets the [param travel_cost] for this [param region]. </description> </method> + <method name="region_set_use_edge_connections"> + <return type="void" /> + <param index="0" name="region" type="RID" /> + <param index="1" name="enabled" type="bool" /> + <description> + If [param enabled] the navigation [param region] will use edge connections to connect with other navigation regions within proximity of the navigation map edge connection margin. + </description> + </method> <method name="set_active"> <return type="void" /> <param index="0" name="active" type="bool" /> diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml index 2c54e364c7..818e402067 100644 --- a/doc/classes/ProjectSettings.xml +++ b/doc/classes/ProjectSettings.xml @@ -1915,6 +1915,9 @@ <member name="navigation/2d/default_link_connection_radius" type="int" setter="" getter="" default="4"> Default link connection radius for 2D navigation maps. See [method NavigationServer2D.map_set_link_connection_radius]. </member> + <member name="navigation/2d/use_edge_connections" type="bool" setter="" getter="" default="true"> + If enabled 2D navigation regions will use edge connections to connect with other navigation regions within proximity of the navigation map edge connection margin. This setting only affects World2D default navigation maps. + </member> <member name="navigation/3d/default_cell_size" type="float" setter="" getter="" default="0.25"> Default cell size for 3D navigation maps. See [method NavigationServer3D.map_set_cell_size]. </member> @@ -1924,6 +1927,9 @@ <member name="navigation/3d/default_link_connection_radius" type="float" setter="" getter="" default="1.0"> Default link connection radius for 3D navigation maps. See [method NavigationServer3D.map_set_link_connection_radius]. </member> + <member name="navigation/3d/use_edge_connections" type="bool" setter="" getter="" default="true"> + If enabled 3D navigation regions will use edge connections to connect with other navigation regions within proximity of the navigation map edge connection margin. This setting only affects World3D default navigation maps. + </member> <member name="navigation/avoidance/thread_model/avoidance_use_high_priority_threads" type="bool" setter="" getter="" default="true"> If enabled and avoidance calculations use multiple threads the threads run with high priority. </member> diff --git a/modules/navigation/godot_navigation_server.cpp b/modules/navigation/godot_navigation_server.cpp index 63423e655c..b0b52a6732 100644 --- a/modules/navigation/godot_navigation_server.cpp +++ b/modules/navigation/godot_navigation_server.cpp @@ -166,6 +166,20 @@ real_t GodotNavigationServer::map_get_cell_size(RID p_map) const { return map->get_cell_size(); } +COMMAND_2(map_set_use_edge_connections, RID, p_map, bool, p_enabled) { + NavMap *map = map_owner.get_or_null(p_map); + ERR_FAIL_COND(map == nullptr); + + map->set_use_edge_connections(p_enabled); +} + +bool GodotNavigationServer::map_get_use_edge_connections(RID p_map) const { + NavMap *map = map_owner.get_or_null(p_map); + ERR_FAIL_COND_V(map == nullptr, false); + + return map->get_use_edge_connections(); +} + COMMAND_2(map_set_edge_connection_margin, RID, p_map, real_t, p_connection_margin) { NavMap *map = map_owner.get_or_null(p_map); ERR_FAIL_COND(map == nullptr); @@ -312,6 +326,20 @@ RID GodotNavigationServer::region_create() { return rid; } +COMMAND_2(region_set_use_edge_connections, RID, p_region, bool, p_enabled) { + NavRegion *region = region_owner.get_or_null(p_region); + ERR_FAIL_COND(region == nullptr); + + region->set_use_edge_connections(p_enabled); +} + +bool GodotNavigationServer::region_get_use_edge_connections(RID p_region) const { + NavRegion *region = region_owner.get_or_null(p_region); + ERR_FAIL_COND_V(region == nullptr, false); + + return region->get_use_edge_connections(); +} + COMMAND_2(region_set_map, RID, p_region, RID, p_map) { NavRegion *region = region_owner.get_or_null(p_region); ERR_FAIL_COND(region == nullptr); diff --git a/modules/navigation/godot_navigation_server.h b/modules/navigation/godot_navigation_server.h index ee9b1f05b7..5d68844a9b 100644 --- a/modules/navigation/godot_navigation_server.h +++ b/modules/navigation/godot_navigation_server.h @@ -107,6 +107,9 @@ public: COMMAND_2(map_set_cell_size, RID, p_map, real_t, p_cell_size); virtual real_t map_get_cell_size(RID p_map) const override; + COMMAND_2(map_set_use_edge_connections, RID, p_map, bool, p_enabled); + virtual bool map_get_use_edge_connections(RID p_map) const override; + COMMAND_2(map_set_edge_connection_margin, RID, p_map, real_t, p_connection_margin); virtual real_t map_get_edge_connection_margin(RID p_map) const override; @@ -129,6 +132,9 @@ public: virtual RID region_create() override; + COMMAND_2(region_set_use_edge_connections, RID, p_region, bool, p_enabled); + virtual bool region_get_use_edge_connections(RID p_region) const override; + COMMAND_2(region_set_enter_cost, RID, p_region, real_t, p_enter_cost); virtual real_t region_get_enter_cost(RID p_region) const override; COMMAND_2(region_set_travel_cost, RID, p_region, real_t, p_travel_cost); diff --git a/modules/navigation/nav_base.h b/modules/navigation/nav_base.h index d4354f929d..b5cdc117f2 100644 --- a/modules/navigation/nav_base.h +++ b/modules/navigation/nav_base.h @@ -48,6 +48,9 @@ protected: public: NavigationUtilities::PathSegmentType get_type() const { return type; } + virtual void set_use_edge_connections(bool p_enabled) {} + virtual bool get_use_edge_connections() const { return false; } + void set_navigation_layers(uint32_t p_navigation_layers) { navigation_layers = p_navigation_layers; } uint32_t get_navigation_layers() const { return navigation_layers; } @@ -59,6 +62,8 @@ public: void set_owner_id(ObjectID p_owner_id) { owner_id = p_owner_id; } ObjectID get_owner_id() const { return owner_id; } + + virtual ~NavBase(){}; }; #endif // NAV_BASE_H diff --git a/modules/navigation/nav_map.cpp b/modules/navigation/nav_map.cpp index 57d702e846..37e0f232e5 100644 --- a/modules/navigation/nav_map.cpp +++ b/modules/navigation/nav_map.cpp @@ -69,6 +69,14 @@ void NavMap::set_cell_size(real_t p_cell_size) { regenerate_polygons = true; } +void NavMap::set_use_edge_connections(bool p_enabled) { + if (use_edge_connections == p_enabled) { + return; + } + use_edge_connections = p_enabled; + regenerate_links = true; +} + void NavMap::set_edge_connection_margin(real_t p_edge_connection_margin) { if (edge_connection_margin == p_edge_connection_margin) { return; @@ -751,7 +759,9 @@ void NavMap::sync() { _new_pm_edge_merge_count += 1; } else { CRASH_COND_MSG(E.value.size() != 1, vformat("Number of connection != 1. Found: %d", E.value.size())); - free_edges.push_back(E.value[0]); + if (use_edge_connections && E.value[0].polygon->owner->get_use_edge_connections()) { + free_edges.push_back(E.value[0]); + } } } diff --git a/modules/navigation/nav_map.h b/modules/navigation/nav_map.h index 343f53760b..2bd9459626 100644 --- a/modules/navigation/nav_map.h +++ b/modules/navigation/nav_map.h @@ -57,6 +57,7 @@ class NavMap : public NavRid { /// each cell has the following cell_size. real_t cell_size = 0.25; + bool use_edge_connections = true; /// This value is used to detect the near edges to connect. real_t edge_connection_margin = 0.25; @@ -130,6 +131,11 @@ public: return cell_size; } + void set_use_edge_connections(bool p_enabled); + bool get_use_edge_connections() const { + return use_edge_connections; + } + void set_edge_connection_margin(real_t p_edge_connection_margin); real_t get_edge_connection_margin() const { return edge_connection_margin; diff --git a/modules/navigation/nav_region.cpp b/modules/navigation/nav_region.cpp index bcee6ed751..d0f055874e 100644 --- a/modules/navigation/nav_region.cpp +++ b/modules/navigation/nav_region.cpp @@ -43,6 +43,13 @@ void NavRegion::set_map(NavMap *p_map) { } } +void NavRegion::set_use_edge_connections(bool p_enabled) { + if (use_edge_connections != p_enabled) { + use_edge_connections = p_enabled; + polygons_dirty = true; + } +} + void NavRegion::set_transform(Transform3D p_transform) { if (transform == p_transform) { return; diff --git a/modules/navigation/nav_region.h b/modules/navigation/nav_region.h index 0942aa22f0..72299e8874 100644 --- a/modules/navigation/nav_region.h +++ b/modules/navigation/nav_region.h @@ -42,6 +42,8 @@ class NavRegion : public NavBase { Ref<NavigationMesh> mesh; Vector<gd::Edge::Connection> connections; + bool use_edge_connections = true; + bool polygons_dirty = true; /// Cache @@ -61,6 +63,11 @@ public: return map; } + void set_use_edge_connections(bool p_enabled); + bool get_use_edge_connections() const { + return use_edge_connections; + } + void set_transform(Transform3D transform); const Transform3D &get_transform() const { return transform; diff --git a/scene/2d/navigation_region_2d.cpp b/scene/2d/navigation_region_2d.cpp index cbcdb9f88e..c14fb29353 100644 --- a/scene/2d/navigation_region_2d.cpp +++ b/scene/2d/navigation_region_2d.cpp @@ -67,6 +67,20 @@ bool NavigationRegion2D::is_enabled() const { return enabled; } +void NavigationRegion2D::set_use_edge_connections(bool p_enabled) { + if (use_edge_connections == p_enabled) { + return; + } + + use_edge_connections = p_enabled; + + NavigationServer2D::get_singleton()->region_set_use_edge_connections(region, use_edge_connections); +} + +bool NavigationRegion2D::get_use_edge_connections() const { + return use_edge_connections; +} + void NavigationRegion2D::set_navigation_layers(uint32_t p_navigation_layers) { if (navigation_layers == p_navigation_layers) { return; @@ -210,7 +224,7 @@ void NavigationRegion2D::_notification(int p_what) { bool enabled_geometry_face_random_color = ns2d->get_debug_navigation_enable_geometry_face_random_color(); bool enabled_edge_lines = ns2d->get_debug_navigation_enable_edge_lines(); - bool enable_edge_connections = ns2d->get_debug_navigation_enable_edge_connections(); + bool enable_edge_connections = use_edge_connections && ns2d->get_debug_navigation_enable_edge_connections() && ns2d->map_get_use_edge_connections(get_world_2d()->get_navigation_map()); Color debug_face_color = ns2d->get_debug_navigation_geometry_face_color(); Color debug_edge_color = ns2d->get_debug_navigation_geometry_edge_color(); @@ -340,6 +354,9 @@ void NavigationRegion2D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_enabled", "enabled"), &NavigationRegion2D::set_enabled); ClassDB::bind_method(D_METHOD("is_enabled"), &NavigationRegion2D::is_enabled); + ClassDB::bind_method(D_METHOD("set_use_edge_connections", "enabled"), &NavigationRegion2D::set_use_edge_connections); + ClassDB::bind_method(D_METHOD("get_use_edge_connections"), &NavigationRegion2D::get_use_edge_connections); + ClassDB::bind_method(D_METHOD("set_navigation_layers", "navigation_layers"), &NavigationRegion2D::set_navigation_layers); ClassDB::bind_method(D_METHOD("get_navigation_layers"), &NavigationRegion2D::get_navigation_layers); @@ -365,6 +382,7 @@ void NavigationRegion2D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "navigation_polygon", PROPERTY_HINT_RESOURCE_TYPE, "NavigationPolygon"), "set_navigation_polygon", "get_navigation_polygon"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "enabled"), "set_enabled", "is_enabled"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_edge_connections"), "set_use_edge_connections", "get_use_edge_connections"); ADD_PROPERTY(PropertyInfo(Variant::INT, "navigation_layers", PROPERTY_HINT_LAYERS_2D_NAVIGATION), "set_navigation_layers", "get_navigation_layers"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "enter_cost"), "set_enter_cost", "get_enter_cost"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "travel_cost"), "set_travel_cost", "get_travel_cost"); diff --git a/scene/2d/navigation_region_2d.h b/scene/2d/navigation_region_2d.h index bd7bdc28eb..39de0a0004 100644 --- a/scene/2d/navigation_region_2d.h +++ b/scene/2d/navigation_region_2d.h @@ -37,6 +37,8 @@ class NavigationRegion2D : public Node2D { GDCLASS(NavigationRegion2D, Node2D); bool enabled = true; + bool use_edge_connections = true; + RID region; uint32_t navigation_layers = 1; real_t enter_cost = 0.0; @@ -71,6 +73,9 @@ public: void set_enabled(bool p_enabled); bool is_enabled() const; + void set_use_edge_connections(bool p_enabled); + bool get_use_edge_connections() const; + void set_navigation_layers(uint32_t p_navigation_layers); uint32_t get_navigation_layers() const; diff --git a/scene/3d/navigation_region_3d.cpp b/scene/3d/navigation_region_3d.cpp index b775ef94cb..165d44436c 100644 --- a/scene/3d/navigation_region_3d.cpp +++ b/scene/3d/navigation_region_3d.cpp @@ -81,6 +81,20 @@ bool NavigationRegion3D::is_enabled() const { return enabled; } +void NavigationRegion3D::set_use_edge_connections(bool p_enabled) { + if (use_edge_connections == p_enabled) { + return; + } + + use_edge_connections = p_enabled; + + NavigationServer3D::get_singleton()->region_set_use_edge_connections(region, use_edge_connections); +} + +bool NavigationRegion3D::get_use_edge_connections() const { + return use_edge_connections; +} + void NavigationRegion3D::set_navigation_layers(uint32_t p_navigation_layers) { if (navigation_layers == p_navigation_layers) { return; @@ -307,6 +321,9 @@ void NavigationRegion3D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_enabled", "enabled"), &NavigationRegion3D::set_enabled); ClassDB::bind_method(D_METHOD("is_enabled"), &NavigationRegion3D::is_enabled); + ClassDB::bind_method(D_METHOD("set_use_edge_connections", "enabled"), &NavigationRegion3D::set_use_edge_connections); + ClassDB::bind_method(D_METHOD("get_use_edge_connections"), &NavigationRegion3D::get_use_edge_connections); + ClassDB::bind_method(D_METHOD("set_navigation_layers", "navigation_layers"), &NavigationRegion3D::set_navigation_layers); ClassDB::bind_method(D_METHOD("get_navigation_layers"), &NavigationRegion3D::get_navigation_layers); @@ -326,6 +343,7 @@ void NavigationRegion3D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "navigation_mesh", PROPERTY_HINT_RESOURCE_TYPE, "NavigationMesh"), "set_navigation_mesh", "get_navigation_mesh"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "enabled"), "set_enabled", "is_enabled"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_edge_connections"), "set_use_edge_connections", "get_use_edge_connections"); ADD_PROPERTY(PropertyInfo(Variant::INT, "navigation_layers", PROPERTY_HINT_LAYERS_3D_NAVIGATION), "set_navigation_layers", "get_navigation_layers"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "enter_cost"), "set_enter_cost", "get_enter_cost"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "travel_cost"), "set_travel_cost", "get_travel_cost"); @@ -602,6 +620,13 @@ void NavigationRegion3D::_update_debug_edge_connections_mesh() { return; } + if (!use_edge_connections || !NavigationServer3D::get_singleton()->map_get_use_edge_connections(get_world_3d()->get_navigation_map())) { + if (debug_edge_connections_instance.is_valid()) { + RS::get_singleton()->instance_set_visible(debug_edge_connections_instance, false); + } + return; + } + if (!navigation_mesh.is_valid()) { if (debug_edge_connections_instance.is_valid()) { RS::get_singleton()->instance_set_visible(debug_edge_connections_instance, false); diff --git a/scene/3d/navigation_region_3d.h b/scene/3d/navigation_region_3d.h index 4732c340ba..fd6deebd63 100644 --- a/scene/3d/navigation_region_3d.h +++ b/scene/3d/navigation_region_3d.h @@ -38,6 +38,8 @@ class NavigationRegion3D : public Node3D { GDCLASS(NavigationRegion3D, Node3D); bool enabled = true; + bool use_edge_connections = true; + RID region; uint32_t navigation_layers = 1; real_t enter_cost = 0.0; @@ -75,6 +77,9 @@ public: void set_enabled(bool p_enabled); bool is_enabled() const; + void set_use_edge_connections(bool p_enabled); + bool get_use_edge_connections() const; + void set_navigation_layers(uint32_t p_navigation_layers); uint32_t get_navigation_layers() const; diff --git a/scene/resources/world_2d.cpp b/scene/resources/world_2d.cpp index c7304da358..f371703cba 100644 --- a/scene/resources/world_2d.cpp +++ b/scene/resources/world_2d.cpp @@ -59,6 +59,7 @@ RID World2D::get_navigation_map() const { navigation_map = NavigationServer2D::get_singleton()->map_create(); NavigationServer2D::get_singleton()->map_set_active(navigation_map, true); NavigationServer2D::get_singleton()->map_set_cell_size(navigation_map, GLOBAL_GET("navigation/2d/default_cell_size")); + NavigationServer2D::get_singleton()->map_set_use_edge_connections(navigation_map, GLOBAL_GET("navigation/2d/use_edge_connections")); NavigationServer2D::get_singleton()->map_set_edge_connection_margin(navigation_map, GLOBAL_GET("navigation/2d/default_edge_connection_margin")); NavigationServer2D::get_singleton()->map_set_link_connection_radius(navigation_map, GLOBAL_GET("navigation/2d/default_link_connection_radius")); } diff --git a/scene/resources/world_3d.cpp b/scene/resources/world_3d.cpp index 82c056d5ee..cc961941cf 100644 --- a/scene/resources/world_3d.cpp +++ b/scene/resources/world_3d.cpp @@ -67,6 +67,7 @@ RID World3D::get_navigation_map() const { navigation_map = NavigationServer3D::get_singleton()->map_create(); NavigationServer3D::get_singleton()->map_set_active(navigation_map, true); NavigationServer3D::get_singleton()->map_set_cell_size(navigation_map, GLOBAL_GET("navigation/3d/default_cell_size")); + NavigationServer3D::get_singleton()->map_set_use_edge_connections(navigation_map, GLOBAL_GET("navigation/3d/use_edge_connections")); NavigationServer3D::get_singleton()->map_set_edge_connection_margin(navigation_map, GLOBAL_GET("navigation/3d/default_edge_connection_margin")); NavigationServer3D::get_singleton()->map_set_link_connection_radius(navigation_map, GLOBAL_GET("navigation/3d/default_link_connection_radius")); } diff --git a/servers/navigation_server_2d.cpp b/servers/navigation_server_2d.cpp index 706718be19..c2dddb0627 100644 --- a/servers/navigation_server_2d.cpp +++ b/servers/navigation_server_2d.cpp @@ -371,6 +371,8 @@ void NavigationServer2D::_bind_methods() { ClassDB::bind_method(D_METHOD("map_is_active", "map"), &NavigationServer2D::map_is_active); ClassDB::bind_method(D_METHOD("map_set_cell_size", "map", "cell_size"), &NavigationServer2D::map_set_cell_size); ClassDB::bind_method(D_METHOD("map_get_cell_size", "map"), &NavigationServer2D::map_get_cell_size); + ClassDB::bind_method(D_METHOD("map_set_use_edge_connections", "map", "enabled"), &NavigationServer2D::map_set_use_edge_connections); + ClassDB::bind_method(D_METHOD("map_get_use_edge_connections", "map"), &NavigationServer2D::map_get_use_edge_connections); ClassDB::bind_method(D_METHOD("map_set_edge_connection_margin", "map", "margin"), &NavigationServer2D::map_set_edge_connection_margin); ClassDB::bind_method(D_METHOD("map_get_edge_connection_margin", "map"), &NavigationServer2D::map_get_edge_connection_margin); ClassDB::bind_method(D_METHOD("map_set_link_connection_radius", "map", "radius"), &NavigationServer2D::map_set_link_connection_radius); @@ -389,6 +391,8 @@ void NavigationServer2D::_bind_methods() { ClassDB::bind_method(D_METHOD("query_path", "parameters", "result"), &NavigationServer2D::query_path); ClassDB::bind_method(D_METHOD("region_create"), &NavigationServer2D::region_create); + ClassDB::bind_method(D_METHOD("region_set_use_edge_connections", "region", "enabled"), &NavigationServer2D::region_set_use_edge_connections); + ClassDB::bind_method(D_METHOD("region_get_use_edge_connections", "region"), &NavigationServer2D::region_get_use_edge_connections); ClassDB::bind_method(D_METHOD("region_set_enter_cost", "region", "enter_cost"), &NavigationServer2D::region_set_enter_cost); ClassDB::bind_method(D_METHOD("region_get_enter_cost", "region"), &NavigationServer2D::region_get_enter_cost); ClassDB::bind_method(D_METHOD("region_set_travel_cost", "region", "travel_cost"), &NavigationServer2D::region_set_travel_cost); @@ -508,6 +512,9 @@ void NavigationServer2D::map_force_update(RID p_map) { void FORWARD_2(map_set_cell_size, RID, p_map, real_t, p_cell_size, rid_to_rid, real_to_real); real_t FORWARD_1_C(map_get_cell_size, RID, p_map, rid_to_rid); +void FORWARD_2(map_set_use_edge_connections, RID, p_map, bool, p_enabled, rid_to_rid, bool_to_bool); +bool FORWARD_1_C(map_get_use_edge_connections, RID, p_map, rid_to_rid); + void FORWARD_2(map_set_edge_connection_margin, RID, p_map, real_t, p_connection_margin, rid_to_rid, real_to_real); real_t FORWARD_1_C(map_get_edge_connection_margin, RID, p_map, rid_to_rid); @@ -521,6 +528,9 @@ RID FORWARD_2_C(map_get_closest_point_owner, RID, p_map, const Vector2 &, p_poin RID FORWARD_0(region_create); +void FORWARD_2(region_set_use_edge_connections, RID, p_region, bool, p_enabled, rid_to_rid, bool_to_bool); +bool FORWARD_1_C(region_get_use_edge_connections, RID, p_region, rid_to_rid); + void FORWARD_2(region_set_enter_cost, RID, p_region, real_t, p_enter_cost, rid_to_rid, real_to_real); real_t FORWARD_1_C(region_get_enter_cost, RID, p_region, rid_to_rid); void FORWARD_2(region_set_travel_cost, RID, p_region, real_t, p_travel_cost, rid_to_rid, real_to_real); diff --git a/servers/navigation_server_2d.h b/servers/navigation_server_2d.h index d6e84d73b6..88246019b9 100644 --- a/servers/navigation_server_2d.h +++ b/servers/navigation_server_2d.h @@ -70,6 +70,9 @@ public: /// Returns the map cell size. virtual real_t map_get_cell_size(RID p_map) const; + virtual void map_set_use_edge_connections(RID p_map, bool p_enabled); + virtual bool map_get_use_edge_connections(RID p_map) const; + /// Set the map edge connection margin used to weld the compatible region edges. virtual void map_set_edge_connection_margin(RID p_map, real_t p_connection_margin); @@ -98,6 +101,9 @@ public: /// Creates a new region. virtual RID region_create(); + virtual void region_set_use_edge_connections(RID p_region, bool p_enabled); + virtual bool region_get_use_edge_connections(RID p_region) const; + /// Set the enter_cost of a region virtual void region_set_enter_cost(RID p_region, real_t p_enter_cost); virtual real_t region_get_enter_cost(RID p_region) const; diff --git a/servers/navigation_server_3d.cpp b/servers/navigation_server_3d.cpp index e2da97b18a..7888a28b7b 100644 --- a/servers/navigation_server_3d.cpp +++ b/servers/navigation_server_3d.cpp @@ -43,6 +43,8 @@ void NavigationServer3D::_bind_methods() { ClassDB::bind_method(D_METHOD("map_get_up", "map"), &NavigationServer3D::map_get_up); ClassDB::bind_method(D_METHOD("map_set_cell_size", "map", "cell_size"), &NavigationServer3D::map_set_cell_size); ClassDB::bind_method(D_METHOD("map_get_cell_size", "map"), &NavigationServer3D::map_get_cell_size); + ClassDB::bind_method(D_METHOD("map_set_use_edge_connections", "map", "enabled"), &NavigationServer3D::map_set_use_edge_connections); + ClassDB::bind_method(D_METHOD("map_get_use_edge_connections", "map"), &NavigationServer3D::map_get_use_edge_connections); ClassDB::bind_method(D_METHOD("map_set_edge_connection_margin", "map", "margin"), &NavigationServer3D::map_set_edge_connection_margin); ClassDB::bind_method(D_METHOD("map_get_edge_connection_margin", "map"), &NavigationServer3D::map_get_edge_connection_margin); ClassDB::bind_method(D_METHOD("map_set_link_connection_radius", "map", "radius"), &NavigationServer3D::map_set_link_connection_radius); @@ -63,6 +65,8 @@ void NavigationServer3D::_bind_methods() { ClassDB::bind_method(D_METHOD("query_path", "parameters", "result"), &NavigationServer3D::query_path); ClassDB::bind_method(D_METHOD("region_create"), &NavigationServer3D::region_create); + ClassDB::bind_method(D_METHOD("region_set_use_edge_connections", "region", "enabled"), &NavigationServer3D::region_set_use_edge_connections); + ClassDB::bind_method(D_METHOD("region_get_use_edge_connections", "region"), &NavigationServer3D::region_get_use_edge_connections); ClassDB::bind_method(D_METHOD("region_set_enter_cost", "region", "enter_cost"), &NavigationServer3D::region_set_enter_cost); ClassDB::bind_method(D_METHOD("region_get_enter_cost", "region"), &NavigationServer3D::region_get_enter_cost); ClassDB::bind_method(D_METHOD("region_set_travel_cost", "region", "travel_cost"), &NavigationServer3D::region_set_travel_cost); @@ -165,10 +169,12 @@ NavigationServer3D::NavigationServer3D() { singleton = this; GLOBAL_DEF_BASIC("navigation/2d/default_cell_size", 1); + GLOBAL_DEF("navigation/2d/use_edge_connections", true); GLOBAL_DEF_BASIC("navigation/2d/default_edge_connection_margin", 1); GLOBAL_DEF_BASIC("navigation/2d/default_link_connection_radius", 4); GLOBAL_DEF_BASIC("navigation/3d/default_cell_size", 0.25); + GLOBAL_DEF("navigation/3d/use_edge_connections", true); GLOBAL_DEF_BASIC("navigation/3d/default_edge_connection_margin", 0.25); GLOBAL_DEF_BASIC("navigation/3d/default_link_connection_radius", 1.0); diff --git a/servers/navigation_server_3d.h b/servers/navigation_server_3d.h index eb8fc59041..73698581e9 100644 --- a/servers/navigation_server_3d.h +++ b/servers/navigation_server_3d.h @@ -80,6 +80,9 @@ public: /// Returns the map cell size. virtual real_t map_get_cell_size(RID p_map) const = 0; + virtual void map_set_use_edge_connections(RID p_map, bool p_enabled) = 0; + virtual bool map_get_use_edge_connections(RID p_map) const = 0; + /// Set the map edge connection margin used to weld the compatible region edges. virtual void map_set_edge_connection_margin(RID p_map, real_t p_connection_margin) = 0; @@ -110,6 +113,9 @@ public: /// Creates a new region. virtual RID region_create() = 0; + virtual void region_set_use_edge_connections(RID p_region, bool p_enabled) = 0; + virtual bool region_get_use_edge_connections(RID p_region) const = 0; + /// Set the enter_cost of a region virtual void region_set_enter_cost(RID p_region, real_t p_enter_cost) = 0; virtual real_t region_get_enter_cost(RID p_region) const = 0; diff --git a/servers/navigation_server_3d_dummy.h b/servers/navigation_server_3d_dummy.h index c6c0eb4b34..98dc38990e 100644 --- a/servers/navigation_server_3d_dummy.h +++ b/servers/navigation_server_3d_dummy.h @@ -45,6 +45,8 @@ public: Vector3 map_get_up(RID p_map) const override { return Vector3(); } void map_set_cell_size(RID p_map, real_t p_cell_size) override {} real_t map_get_cell_size(RID p_map) const override { return 0; } + void map_set_use_edge_connections(RID p_map, bool p_enabled) override {} + bool map_get_use_edge_connections(RID p_map) const override { return false; } void map_set_edge_connection_margin(RID p_map, real_t p_connection_margin) override {} real_t map_get_edge_connection_margin(RID p_map) const override { return 0; } void map_set_link_connection_radius(RID p_map, real_t p_connection_radius) override {} @@ -60,6 +62,8 @@ public: TypedArray<RID> map_get_obstacles(RID p_map) const override { return TypedArray<RID>(); } void map_force_update(RID p_map) override {} RID region_create() override { return RID(); } + void region_set_use_edge_connections(RID p_region, bool p_enabled) override {} + bool region_get_use_edge_connections(RID p_region) const override { return false; } void region_set_enter_cost(RID p_region, real_t p_enter_cost) override {} real_t region_get_enter_cost(RID p_region) const override { return 0; } void region_set_travel_cost(RID p_region, real_t p_travel_cost) override {} |