diff --git a/doc/classes/Navigation2DServer.xml b/doc/classes/Navigation2DServer.xml
index ce2698c8d..07401b1a9 100644
--- a/doc/classes/Navigation2DServer.xml
+++ b/doc/classes/Navigation2DServer.xml
@@ -357,6 +357,13 @@
Returns all navigation regions [RID]s that are currently assigned to the requested navigation [code]map[/code].
+
+
+
+
+ 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.
+
+
@@ -412,6 +419,14 @@
Set the map's link connection radius used to connect links to navigation polygons.
+
+
+
+
+
+ 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.
+
+
@@ -476,6 +491,13 @@
Returns the [code]travel_cost[/code] of this [code]region[/code].
+
+
+
+
+ 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.
+
+
@@ -542,6 +564,14 @@
Sets the [code]travel_cost[/code] for this [code]region[/code].
+
+
+
+
+
+ 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.
+
+
diff --git a/doc/classes/NavigationMeshInstance.xml b/doc/classes/NavigationMeshInstance.xml
index 51e9b6559..a435b8b1a 100644
--- a/doc/classes/NavigationMeshInstance.xml
+++ b/doc/classes/NavigationMeshInstance.xml
@@ -74,6 +74,9 @@
When pathfinding moves inside this regions navmesh the traveled distances are multiplied with [code]travel_cost[/code] for determining the shortest path.
+
+ If enabled the navigation region will use edge connections to connect with other navigation regions within proximity of the navigation map edge connection margin.
+
diff --git a/doc/classes/NavigationPolygonInstance.xml b/doc/classes/NavigationPolygonInstance.xml
index e226c2f41..9332c4bf7 100644
--- a/doc/classes/NavigationPolygonInstance.xml
+++ b/doc/classes/NavigationPolygonInstance.xml
@@ -73,6 +73,9 @@
When pathfinding moves inside this regions navmesh the traveled distances are multiplied with [code]travel_cost[/code] for determining the shortest path.
+
+ If enabled the navigation region will use edge connections to connect with other navigation regions within proximity of the navigation map edge connection margin.
+
diff --git a/doc/classes/NavigationServer.xml b/doc/classes/NavigationServer.xml
index a2b4ef9b8..389326c82 100644
--- a/doc/classes/NavigationServer.xml
+++ b/doc/classes/NavigationServer.xml
@@ -390,6 +390,13 @@
Returns the map's up direction.
+
+
+
+
+ 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.
+
+
@@ -445,6 +452,14 @@
Sets the map up direction.
+
+
+
+
+
+ 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.
+
+
@@ -526,6 +541,13 @@
Returns the [code]travel_cost[/code] of this [code]region[/code].
+
+
+
+
+ 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.
+
+
@@ -592,6 +614,14 @@
Sets the [code]travel_cost[/code] for this [code]region[/code].
+
+
+
+
+
+ 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.
+
+
diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml
index 4eed6d388..7fbd821e9 100644
--- a/doc/classes/ProjectSettings.xml
+++ b/doc/classes/ProjectSettings.xml
@@ -1390,6 +1390,9 @@
Default link connection radius for 2D navigation maps. See [method NavigationServer2D.map_set_link_connection_radius].
+
+ 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.
+
Default cell height for 3D navigation maps. See [method NavigationServer.map_set_cell_height].
@@ -1405,6 +1408,9 @@
Default link connection radius for 3D navigation maps. See [method NavigationServer3D.map_set_link_connection_radius].
+
+ 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.
+
Maximum amount of characters allowed to send as output from the debugger. Over this value, content is dropped. This helps not to stall the debugger connection.
diff --git a/modules/navigation/nav_map.cpp b/modules/navigation/nav_map.cpp
index 755c0465a..50a4c555d 100644
--- a/modules/navigation/nav_map.cpp
+++ b/modules/navigation/nav_map.cpp
@@ -79,6 +79,14 @@ void NavMap::set_cell_height(real_t p_cell_height) {
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;
@@ -391,7 +399,7 @@ Vector NavMap::get_path(Vector3 p_origin, Vector3 p_destination, bool p
apex_poly = p;
left_portal = apex_point;
right_portal = apex_point;
-
+
path.push_back(apex_point);
APPEND_METADATA(apex_poly->poly);
skip = true;
@@ -751,7 +759,10 @@ void NavMap::sync() {
_new_pm_edge_merge_count += 1;
} else {
CRASH_COND_MSG(E->get().size() != 1, vformat("Number of connection != 1. Found: %d", E->get().size()));
- free_edges.push_back(E->get()[0]);
+
+ if (use_edge_connections && E->get()[0].polygon->owner->get_use_edge_connections()) {
+ free_edges.push_back(E->get()[0]);
+ }
}
}
@@ -1046,6 +1057,7 @@ NavMap::NavMap() {
deltatime = 0.0;
map_update_id = 0;
link_connection_radius = 1.0;
+ use_edge_connections = true;
// Performance Monitor
pm_region_count = 0;
diff --git a/modules/navigation/nav_map.h b/modules/navigation/nav_map.h
index 7caefb24a..ae7bc3bdc 100644
--- a/modules/navigation/nav_map.h
+++ b/modules/navigation/nav_map.h
@@ -54,6 +54,8 @@ class NavMap : public NavRid {
real_t cell_size;
real_t cell_height;
+ bool use_edge_connections;
+
/// This value is used to detect the near edges to connect.
real_t edge_connection_margin;
@@ -125,6 +127,11 @@ public:
return cell_height;
}
+ 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 1717acb1e..407f59a17 100644
--- a/modules/navigation/nav_region.cpp
+++ b/modules/navigation/nav_region.cpp
@@ -45,6 +45,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(Transform p_transform) {
if (transform == p_transform) {
return;
@@ -163,6 +170,7 @@ NavRegion::NavRegion() {
enter_cost = 0.0;
travel_cost = 1.0;
polygons_dirty = true;
+ use_edge_connections = true;
}
NavRegion::~NavRegion() {}
diff --git a/modules/navigation/nav_region.h b/modules/navigation/nav_region.h
index c7fef3771..f0164847a 100644
--- a/modules/navigation/nav_region.h
+++ b/modules/navigation/nav_region.h
@@ -43,6 +43,8 @@ class NavRegion : public NavBase {
Ref mesh;
Vector connections;
+ bool use_edge_connections;
+
bool polygons_dirty;
/// Cache
@@ -58,6 +60,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(Transform transform);
const Transform &get_transform() const {
return transform;
diff --git a/modules/navigation/pandemonium_navigation_2d_server.cpp b/modules/navigation/pandemonium_navigation_2d_server.cpp
index c6d2b270d..4eaeedf0b 100644
--- a/modules/navigation/pandemonium_navigation_2d_server.cpp
+++ b/modules/navigation/pandemonium_navigation_2d_server.cpp
@@ -58,6 +58,11 @@
return CONV_R(NavigationServer::get_singleton()->FUNC_NAME(CONV_0(D_0))); \
}
+#define FORWARD_2(FUNC_NAME, T_0, D_0, T_1, D_1, CONV_0, CONV_1) \
+ PandemoniumNavigation2DServer::FUNC_NAME(T_0 D_0, T_1 D_1) { \
+ return NavigationServer::get_singleton_mut()->FUNC_NAME(CONV_0(D_0), CONV_1(D_1)); \
+ }
+
#define FORWARD_2_C(FUNC_NAME, T_0, D_0, T_1, D_1, CONV_0, CONV_1) \
PandemoniumNavigation2DServer::FUNC_NAME(T_0 D_0, T_1 D_1) \
const { \
@@ -223,6 +228,9 @@ void PandemoniumNavigation2DServer::map_force_update(RID p_map) {
void FORWARD_2_C(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_C(map_set_cell_height, RID, p_map, real_t, p_cell_height, rid_to_rid, real_to_real);
real_t FORWARD_1_C(map_get_cell_height, RID, p_map, rid_to_rid);
@@ -239,6 +247,9 @@ RID FORWARD_2_C(map_get_closest_point_owner, RID, p_map, const Vector2 &, p_poin
RID FORWARD_0_C(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_C(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_C(region_set_travel_cost, RID, p_region, real_t, p_travel_cost, rid_to_rid, real_to_real);
diff --git a/modules/navigation/pandemonium_navigation_2d_server.h b/modules/navigation/pandemonium_navigation_2d_server.h
index b061ec94c..05f56f13b 100644
--- a/modules/navigation/pandemonium_navigation_2d_server.h
+++ b/modules/navigation/pandemonium_navigation_2d_server.h
@@ -63,6 +63,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 cell height used to weld the navigation mesh polygons.
virtual void map_set_cell_height(RID p_map, real_t p_cell_height) const;
virtual real_t map_get_cell_height(RID p_map) const;
@@ -94,6 +97,9 @@ public:
/// Creates a new region.
virtual RID region_create() const;
+ 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) const;
virtual real_t region_get_enter_cost(RID p_region) const;
diff --git a/modules/navigation/pandemonium_navigation_server.cpp b/modules/navigation/pandemonium_navigation_server.cpp
index 7e883c56e..f568a77d8 100644
--- a/modules/navigation/pandemonium_navigation_server.cpp
+++ b/modules/navigation/pandemonium_navigation_server.cpp
@@ -83,6 +83,29 @@ using namespace NavigationUtilities;
} \
void PandemoniumNavigationServer::MERGE(_cmd_, F_NAME)(T_0 D_0, T_1 D_1)
+#define COMMAND_2N(F_NAME, T_0, D_0, T_1, D_1) \
+ struct MERGE(F_NAME, _command) : public SetCommand { \
+ T_0 d_0; \
+ T_1 d_1; \
+ MERGE(F_NAME, _command) \
+ ( \
+ T_0 p_d_0, \
+ T_1 p_d_1) : \
+ d_0(p_d_0), \
+ d_1(p_d_1) {} \
+ virtual void exec(PandemoniumNavigationServer *server) { \
+ server->MERGE(_cmd_, F_NAME)(d_0, d_1); \
+ } \
+ }; \
+ void PandemoniumNavigationServer::F_NAME(T_0 D_0, T_1 D_1) { \
+ auto cmd = memnew(MERGE(F_NAME, _command)( \
+ D_0, \
+ D_1)); \
+ add_command(cmd); \
+ } \
+ void PandemoniumNavigationServer::MERGE(_cmd_, F_NAME)(T_0 D_0, T_1 D_1)
+
+
#define COMMAND_4(F_NAME, T_0, D_0, T_1, D_1, T_2, D_2, T_3, D_3) \
struct MERGE(F_NAME, _command) : public SetCommand { \
T_0 d_0; \
@@ -216,6 +239,20 @@ real_t PandemoniumNavigationServer::map_get_cell_height(RID p_map) const {
return map->get_cell_height();
}
+COMMAND_2N(map_set_use_edge_connections, RID, p_map, bool, p_enabled) {
+ NavMap *map = map_owner.getornull(p_map);
+ ERR_FAIL_COND(map == nullptr);
+
+ map->set_use_edge_connections(p_enabled);
+}
+
+bool PandemoniumNavigationServer::map_get_use_edge_connections(RID p_map) const {
+ NavMap *map = map_owner.getornull(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.getornull(p_map);
ERR_FAIL_COND(map == nullptr);
@@ -353,6 +390,20 @@ RID PandemoniumNavigationServer::region_create() const {
return rid;
}
+COMMAND_2N(region_set_use_edge_connections, RID, p_region, bool, p_enabled) {
+ NavRegion *region = region_owner.getornull(p_region);
+ ERR_FAIL_COND(region == nullptr);
+
+ region->set_use_edge_connections(p_enabled);
+}
+
+bool PandemoniumNavigationServer::region_get_use_edge_connections(RID p_region) const {
+ NavRegion *region = region_owner.getornull(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.getornull(p_region);
ERR_FAIL_COND(region == nullptr);
@@ -978,4 +1029,5 @@ int PandemoniumNavigationServer::get_process_info(ProcessInfo p_info) const {
#undef COMMAND_1
#undef COMMAND_2
+#undef COMMAND_2N
#undef COMMAND_4
diff --git a/modules/navigation/pandemonium_navigation_server.h b/modules/navigation/pandemonium_navigation_server.h
index 96e47b883..b0b6f9b9a 100644
--- a/modules/navigation/pandemonium_navigation_server.h
+++ b/modules/navigation/pandemonium_navigation_server.h
@@ -52,6 +52,10 @@
virtual void F_NAME(T_0 D_0, T_1 D_1) const; \
void MERGE(_cmd_, F_NAME)(T_0 D_0, T_1 D_1)
+#define COMMAND_2N(F_NAME, T_0, D_0, T_1, D_1) \
+ virtual void F_NAME(T_0 D_0, T_1 D_1); \
+ void MERGE(_cmd_, F_NAME)(T_0 D_0, T_1 D_1)
+
#define COMMAND_4_DEF(F_NAME, T_0, D_0, T_1, D_1, T_2, D_2, T_3, D_3, D_3_DEF) \
virtual void F_NAME(T_0 D_0, T_1 D_1, T_2 D_2, T_3 D_3 = D_3_DEF) const; \
void MERGE(_cmd_, F_NAME)(T_0 D_0, T_1 D_1, T_2 D_2, T_3 D_3)
@@ -110,6 +114,9 @@ public:
COMMAND_2(map_set_cell_height, RID, p_map, real_t, p_cell_height);
virtual real_t map_get_cell_height(RID p_map) const;
+ COMMAND_2N(map_set_use_edge_connections, RID, p_map, bool, p_enabled);
+ virtual bool map_get_use_edge_connections(RID p_map) const;
+
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;
@@ -131,6 +138,9 @@ public:
virtual RID region_create() const;
+ COMMAND_2N(region_set_use_edge_connections, RID, p_region, bool, p_enabled);
+ virtual bool region_get_use_edge_connections(RID p_region) const;
+
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;
COMMAND_2(region_set_travel_cost, RID, p_region, real_t, p_travel_cost);
@@ -198,6 +208,7 @@ public:
#undef COMMAND_1
#undef COMMAND_2
+#undef COMMAND_2N
#undef COMMAND_4_DEF
#endif // PANDEMONIUM_NAVIGATION_SERVER_H
diff --git a/modules/navigation_dummy/dummy_navigation_2d_server.h b/modules/navigation_dummy/dummy_navigation_2d_server.h
index 65561ac61..51ffa2588 100644
--- a/modules/navigation_dummy/dummy_navigation_2d_server.h
+++ b/modules/navigation_dummy/dummy_navigation_2d_server.h
@@ -18,6 +18,8 @@ public:
virtual real_t map_get_cell_size(RID p_map) const { return 0; }
virtual void map_set_cell_height(RID p_map, real_t p_cell_height) const {}
virtual real_t map_get_cell_height(RID p_map) const { return 0; }
+ void map_set_use_edge_connections(RID p_map, bool p_enabled) {}
+ bool map_get_use_edge_connections(RID p_map) const { return false; }
virtual void map_set_edge_connection_margin(RID p_map, real_t p_connection_margin) const {}
virtual real_t map_get_edge_connection_margin(RID p_map) const { return 0; }
@@ -34,6 +36,8 @@ public:
virtual void map_force_update(RID p_map) {}
virtual RID region_create() const { return RID(); }
+ void region_set_use_edge_connections(RID p_region, bool p_enabled) {}
+ bool region_get_use_edge_connections(RID p_region) const { return false; }
virtual void region_set_enter_cost(RID p_region, real_t p_enter_cost) const {}
virtual real_t region_get_enter_cost(RID p_region) const { return 0; }
virtual void region_set_travel_cost(RID p_region, real_t p_travel_cost) const {}
diff --git a/modules/navigation_dummy/dummy_navigation_server.h b/modules/navigation_dummy/dummy_navigation_server.h
index b48b5af9d..4b54053da 100644
--- a/modules/navigation_dummy/dummy_navigation_server.h
+++ b/modules/navigation_dummy/dummy_navigation_server.h
@@ -19,6 +19,8 @@ public:
virtual real_t map_get_cell_size(RID p_map) const { return 0; }
virtual void map_set_cell_height(RID p_map, real_t p_cell_height) const {}
virtual real_t map_get_cell_height(RID p_map) const { return 0; }
+ void map_set_use_edge_connections(RID p_map, bool p_enabled) {}
+ bool map_get_use_edge_connections(RID p_map) const { return false; }
virtual void map_set_edge_connection_margin(RID p_map, real_t p_connection_margin) const {}
virtual real_t map_get_edge_connection_margin(RID p_map) const { return 0; }
virtual void map_set_link_connection_radius(RID p_map, real_t p_connection_radius) const {}
@@ -36,6 +38,8 @@ public:
virtual void map_force_update(RID p_map) {}
virtual RID region_create() const { return RID(); }
+ void region_set_use_edge_connections(RID p_region, bool p_enabled) {}
+ bool region_get_use_edge_connections(RID p_region) const { return false; }
virtual void region_set_enter_cost(RID p_region, real_t p_enter_cost) const {}
virtual real_t region_get_enter_cost(RID p_region) const { return 0; }
virtual void region_set_travel_cost(RID p_region, real_t p_travel_cost) const {}
diff --git a/scene/2d/navigation_polygon_instance.cpp b/scene/2d/navigation_polygon_instance.cpp
index 147da821c..a5001cbf3 100644
--- a/scene/2d/navigation_polygon_instance.cpp
+++ b/scene/2d/navigation_polygon_instance.cpp
@@ -81,6 +81,20 @@ bool NavigationPolygonInstance::is_enabled() const {
return enabled;
}
+void NavigationPolygonInstance::set_use_edge_connections(bool p_enabled) {
+ if (use_edge_connections == p_enabled) {
+ return;
+ }
+
+ use_edge_connections = p_enabled;
+
+ Navigation2DServer::get_singleton_mut()->region_set_use_edge_connections(region, use_edge_connections);
+}
+
+bool NavigationPolygonInstance::get_use_edge_connections() const {
+ return use_edge_connections;
+}
+
void NavigationPolygonInstance::set_navigation_layers(uint32_t p_navigation_layers) {
navigation_layers = p_navigation_layers;
Navigation2DServer::get_singleton()->region_set_navigation_layers(region, navigation_layers);
@@ -342,6 +356,9 @@ void NavigationPolygonInstance::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_enabled", "enabled"), &NavigationPolygonInstance::set_enabled);
ClassDB::bind_method(D_METHOD("is_enabled"), &NavigationPolygonInstance::is_enabled);
+ ClassDB::bind_method(D_METHOD("set_use_edge_connections", "enabled"), &NavigationPolygonInstance::set_use_edge_connections);
+ ClassDB::bind_method(D_METHOD("get_use_edge_connections"), &NavigationPolygonInstance::get_use_edge_connections);
+
ClassDB::bind_method(D_METHOD("set_navigation_layers", "navigation_layers"), &NavigationPolygonInstance::set_navigation_layers);
ClassDB::bind_method(D_METHOD("get_navigation_layers"), &NavigationPolygonInstance::get_navigation_layers);
@@ -367,6 +384,7 @@ void NavigationPolygonInstance::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "navpoly", 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::REAL, "enter_cost"), "set_enter_cost", "get_enter_cost");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "travel_cost"), "set_travel_cost", "get_travel_cost");
@@ -383,6 +401,7 @@ void NavigationPolygonInstance::_bind_methods() {
NavigationPolygonInstance::NavigationPolygonInstance() {
enabled = true;
+ use_edge_connections = true;
set_notify_transform(true);
region = Navigation2DServer::get_singleton()->region_create();
@@ -480,7 +499,7 @@ void NavigationPolygonInstance::_update_debug_mesh() {
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();
diff --git a/scene/2d/navigation_polygon_instance.h b/scene/2d/navigation_polygon_instance.h
index 8a357fed4..6d1b97ccd 100644
--- a/scene/2d/navigation_polygon_instance.h
+++ b/scene/2d/navigation_polygon_instance.h
@@ -42,6 +42,8 @@ class NavigationPolygonInstance : public Node2D {
GDCLASS(NavigationPolygonInstance, Node2D);
bool enabled;
+ bool use_edge_connections;
+
RID region;
RID map_override;
Navigation2D *navigation;
@@ -77,6 +79,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_mesh_instance.cpp b/scene/3d/navigation_mesh_instance.cpp
index edd66c68c..09fc74e39 100644
--- a/scene/3d/navigation_mesh_instance.cpp
+++ b/scene/3d/navigation_mesh_instance.cpp
@@ -96,6 +96,20 @@ bool NavigationMeshInstance::is_enabled() const {
return enabled;
}
+void NavigationMeshInstance::set_use_edge_connections(bool p_enabled) {
+ if (use_edge_connections == p_enabled) {
+ return;
+ }
+
+ use_edge_connections = p_enabled;
+
+ NavigationServer::get_singleton_mut()->region_set_use_edge_connections(region, use_edge_connections);
+}
+
+bool NavigationMeshInstance::get_use_edge_connections() const {
+ return use_edge_connections;
+}
+
void NavigationMeshInstance::set_navigation_layers(uint32_t p_navigation_layers) {
navigation_layers = p_navigation_layers;
NavigationServer::get_singleton()->region_set_navigation_layers(region, navigation_layers);
@@ -346,6 +360,9 @@ void NavigationMeshInstance::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_enabled", "enabled"), &NavigationMeshInstance::set_enabled);
ClassDB::bind_method(D_METHOD("is_enabled"), &NavigationMeshInstance::is_enabled);
+ ClassDB::bind_method(D_METHOD("set_use_edge_connections", "enabled"), &NavigationMeshInstance::set_use_edge_connections);
+ ClassDB::bind_method(D_METHOD("get_use_edge_connections"), &NavigationMeshInstance::get_use_edge_connections);
+
ClassDB::bind_method(D_METHOD("set_navigation_mesh", "navmesh"), &NavigationMeshInstance::set_navigation_mesh);
ClassDB::bind_method(D_METHOD("get_navigation_mesh"), &NavigationMeshInstance::get_navigation_mesh);
@@ -378,6 +395,7 @@ void NavigationMeshInstance::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "navmesh", 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::REAL, "enter_cost"), "set_enter_cost", "get_enter_cost");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "travel_cost"), "set_travel_cost", "get_travel_cost");
@@ -395,6 +413,7 @@ NavigationMeshInstance::NavigationMeshInstance() {
set_notify_transform(true);
navigation = nullptr;
+ use_edge_connections = true;
enter_cost = 0.0;
travel_cost = 1.0;
@@ -625,6 +644,13 @@ void NavigationMeshInstance::_update_debug_edge_connections_mesh() {
return;
}
+ if (!use_edge_connections || !NavigationServer::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 (!navmesh.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_mesh_instance.h b/scene/3d/navigation_mesh_instance.h
index ac187cc3c..638c26212 100644
--- a/scene/3d/navigation_mesh_instance.h
+++ b/scene/3d/navigation_mesh_instance.h
@@ -41,6 +41,8 @@ class NavigationMeshInstance : public Spatial {
GDCLASS(NavigationMeshInstance, Spatial);
bool enabled;
+ bool use_edge_connections;
+
RID region;
RID map_override;
Ref navmesh;
@@ -77,6 +79,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 c7297812e..f003d9975 100644
--- a/scene/resources/world_2d.cpp
+++ b/scene/resources/world_2d.cpp
@@ -385,6 +385,7 @@ World2D::World2D() {
Navigation2DServer::get_singleton()->map_set_cell_height(navigation_map, GLOBAL_DEF("navigation/2d/default_cell_height", 1.0));
Navigation2DServer::get_singleton()->map_set_edge_connection_margin(navigation_map, GLOBAL_DEF("navigation/2d/default_edge_connection_margin", 1.0));
Navigation2DServer::get_singleton()->map_set_link_connection_radius(navigation_map, GLOBAL_DEF("navigation/2d/default_link_connection_radius", 4));
+ Navigation2DServer::get_singleton_mut()->map_set_use_edge_connections(navigation_map, GLOBAL_DEF("navigation/2d/use_edge_connections", true));
indexer = memnew(SpatialIndexer2D);
}
diff --git a/scene/resources/world_3d.cpp b/scene/resources/world_3d.cpp
index f8d4f9dc3..ebd29d69a 100644
--- a/scene/resources/world_3d.cpp
+++ b/scene/resources/world_3d.cpp
@@ -365,6 +365,7 @@ World3D::World3D() {
NavigationServer::get_singleton()->map_set_cell_height(navigation_map, GLOBAL_DEF("navigation/3d/default_cell_height", 0.25));
NavigationServer::get_singleton()->map_set_edge_connection_margin(navigation_map, GLOBAL_DEF("navigation/3d/default_edge_connection_margin", 0.25));
NavigationServer::get_singleton()->map_set_link_connection_radius(navigation_map, GLOBAL_DEF("navigation/3d/default_link_connection_radius", 1.0));
+ NavigationServer::get_singleton_mut()->map_set_use_edge_connections(navigation_map, GLOBAL_DEF("navigation/3d/use_edge_connections", true));
#ifdef _3D_DISABLED
indexer = NULL;
diff --git a/servers/navigation_2d_server.cpp b/servers/navigation_2d_server.cpp
index 701c95c4f..7a03d465d 100644
--- a/servers/navigation_2d_server.cpp
+++ b/servers/navigation_2d_server.cpp
@@ -45,6 +45,8 @@ void Navigation2DServer::_bind_methods() {
ClassDB::bind_method(D_METHOD("map_is_active", "map"), &Navigation2DServer::map_is_active);
ClassDB::bind_method(D_METHOD("map_set_cell_size", "map", "cell_size"), &Navigation2DServer::map_set_cell_size);
ClassDB::bind_method(D_METHOD("map_get_cell_size", "map"), &Navigation2DServer::map_get_cell_size);
+ ClassDB::bind_method(D_METHOD("map_set_use_edge_connections", "map", "enabled"), &Navigation2DServer::map_set_use_edge_connections);
+ ClassDB::bind_method(D_METHOD("map_get_use_edge_connections", "map"), &Navigation2DServer::map_get_use_edge_connections);
ClassDB::bind_method(D_METHOD("map_set_cell_height", "map", "cell_height"), &Navigation2DServer::map_set_cell_size);
ClassDB::bind_method(D_METHOD("map_get_cell_height", "map"), &Navigation2DServer::map_get_cell_size);
ClassDB::bind_method(D_METHOD("map_set_edge_connection_margin", "map", "margin"), &Navigation2DServer::map_set_edge_connection_margin);
@@ -61,6 +63,8 @@ void Navigation2DServer::_bind_methods() {
ClassDB::bind_method(D_METHOD("map_force_update", "map"), &Navigation2DServer::map_force_update);
ClassDB::bind_method(D_METHOD("region_create"), &Navigation2DServer::region_create);
+ ClassDB::bind_method(D_METHOD("region_set_use_edge_connections", "region", "enabled"), &Navigation2DServer::region_set_use_edge_connections);
+ ClassDB::bind_method(D_METHOD("region_get_use_edge_connections", "region"), &Navigation2DServer::region_get_use_edge_connections);
ClassDB::bind_method(D_METHOD("region_set_enter_cost", "region", "enter_cost"), &Navigation2DServer::region_set_enter_cost);
ClassDB::bind_method(D_METHOD("region_get_enter_cost", "region"), &Navigation2DServer::region_get_enter_cost);
ClassDB::bind_method(D_METHOD("region_set_travel_cost", "region", "travel_cost"), &Navigation2DServer::region_set_travel_cost);
diff --git a/servers/navigation_2d_server.h b/servers/navigation_2d_server.h
index 55ce17430..61bbdc53d 100644
--- a/servers/navigation_2d_server.h
+++ b/servers/navigation_2d_server.h
@@ -74,6 +74,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 cell height used to weld the navigation mesh polygons.
virtual void map_set_cell_height(RID p_map, real_t p_cell_height) const = 0;
virtual real_t map_get_cell_height(RID p_map) const = 0;
@@ -105,6 +108,9 @@ public:
/// Creates a new region.
virtual RID region_create() const = 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) const = 0;
virtual real_t region_get_enter_cost(RID p_region) const = 0;
diff --git a/servers/navigation_server.cpp b/servers/navigation_server.cpp
index 5f6f89819..e5b756817 100644
--- a/servers/navigation_server.cpp
+++ b/servers/navigation_server.cpp
@@ -57,6 +57,8 @@ void NavigationServer::_bind_methods() {
ClassDB::bind_method(D_METHOD("map_get_up", "map"), &NavigationServer::map_get_up);
ClassDB::bind_method(D_METHOD("map_set_cell_size", "map", "cell_size"), &NavigationServer::map_set_cell_size);
ClassDB::bind_method(D_METHOD("map_get_cell_size", "map"), &NavigationServer::map_get_cell_size);
+ ClassDB::bind_method(D_METHOD("map_set_use_edge_connections", "map", "enabled"), &NavigationServer::map_set_use_edge_connections);
+ ClassDB::bind_method(D_METHOD("map_get_use_edge_connections", "map"), &NavigationServer::map_get_use_edge_connections);
ClassDB::bind_method(D_METHOD("map_set_cell_height", "map", "cell_height"), &NavigationServer::map_set_cell_height);
ClassDB::bind_method(D_METHOD("map_get_cell_height", "map"), &NavigationServer::map_get_cell_height);
ClassDB::bind_method(D_METHOD("map_set_edge_connection_margin", "map", "margin"), &NavigationServer::map_set_edge_connection_margin);
@@ -77,6 +79,8 @@ void NavigationServer::_bind_methods() {
ClassDB::bind_method(D_METHOD("query_path", "parameters", "result"), &NavigationServer::query_path);
ClassDB::bind_method(D_METHOD("region_create"), &NavigationServer::region_create);
+ ClassDB::bind_method(D_METHOD("region_set_use_edge_connections", "region", "enabled"), &NavigationServer::region_set_use_edge_connections);
+ ClassDB::bind_method(D_METHOD("region_get_use_edge_connections", "region"), &NavigationServer::region_get_use_edge_connections);
ClassDB::bind_method(D_METHOD("region_set_enter_cost", "region", "enter_cost"), &NavigationServer::region_set_enter_cost);
ClassDB::bind_method(D_METHOD("region_get_enter_cost", "region"), &NavigationServer::region_get_enter_cost);
ClassDB::bind_method(D_METHOD("region_set_travel_cost", "region", "travel_cost"), &NavigationServer::region_set_travel_cost);
@@ -169,6 +173,8 @@ NavigationServer::NavigationServer() {
ERR_FAIL_COND(singleton != nullptr);
singleton = this;
+ GLOBAL_DEF("navigation/3d/use_edge_connections", true);
+
#ifdef DEBUG_ENABLED
_debug_enabled = true;
_debug_dirty = true;
diff --git a/servers/navigation_server.h b/servers/navigation_server.h
index fefd24ca2..9a30252ae 100644
--- a/servers/navigation_server.h
+++ b/servers/navigation_server.h
@@ -86,6 +86,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 cell height used to weld the navigation mesh polygons.
virtual void map_set_cell_height(RID p_map, real_t p_cell_height) const = 0;
@@ -121,6 +124,9 @@ public:
/// Creates a new region.
virtual RID region_create() const = 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) const = 0;
virtual real_t region_get_enter_cost(RID p_region) const = 0;