Ported from godot4: Make navigation mesh edge connections optional

Makes navigation mesh edge connections optional.
- smix8
f986b52b3c
This commit is contained in:
Relintai 2023-06-09 20:54:05 +02:00
parent 81c392489a
commit 6384b9624f
25 changed files with 276 additions and 3 deletions

View File

@ -357,6 +357,13 @@
Returns all navigation regions [RID]s that are currently assigned to the requested navigation [code]map[/code].
</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" />
<argument index="0" name="map" type="RID" />
@ -412,6 +419,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="region_create" qualifiers="const">
<return type="RID" />
<description>
@ -476,6 +491,13 @@
Returns the [code]travel_cost[/code] of this [code]region[/code].
</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" />
<argument index="0" name="region" type="RID" />
@ -542,6 +564,14 @@
Sets the [code]travel_cost[/code] for this [code]region[/code].
</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>
</methods>
<signals>
<signal name="map_changed">

View File

@ -74,6 +74,9 @@
<member name="travel_cost" type="float" setter="set_travel_cost" getter="get_travel_cost" default="1.0">
When pathfinding moves inside this regions navmesh 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">

View File

@ -73,6 +73,9 @@
<member name="travel_cost" type="float" setter="set_travel_cost" getter="get_travel_cost" default="1.0">
When pathfinding moves inside this regions navmesh 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>
<constants>
</constants>

View File

@ -390,6 +390,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" />
<argument index="0" name="map" type="RID" />
@ -445,6 +452,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="process">
<return type="void" />
<argument index="0" name="delta_time" type="float" />
@ -526,6 +541,13 @@
Returns the [code]travel_cost[/code] of this [code]region[/code].
</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" />
<argument index="0" name="region" type="RID" />
@ -592,6 +614,14 @@
Sets the [code]travel_cost[/code] for this [code]region[/code].
</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" qualifiers="const">
<return type="void" />
<argument index="0" name="active" type="bool" />

View File

@ -1390,6 +1390,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_height" type="float" setter="" getter="" default="0.25">
Default cell height for 3D navigation maps. See [method NavigationServer.map_set_cell_height].
</member>
@ -1405,6 +1408,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="network/limits/debugger_stdout/max_chars_per_second" type="int" setter="" getter="" default="2048">
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.
</member>

View File

@ -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<Vector3> 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;

View File

@ -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;

View File

@ -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() {}

View File

@ -43,6 +43,8 @@ class NavRegion : public NavBase {
Ref<NavigationMesh> mesh;
Vector<gd::Edge::Connection> 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;

View File

@ -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);

View File

@ -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;

View File

@ -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

View File

@ -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

View File

@ -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 {}

View File

@ -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 {}

View File

@ -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();

View File

@ -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;

View File

@ -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);

View File

@ -41,6 +41,8 @@ class NavigationMeshInstance : public Spatial {
GDCLASS(NavigationMeshInstance, Spatial);
bool enabled;
bool use_edge_connections;
RID region;
RID map_override;
Ref<NavigationMesh> 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;

View File

@ -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);
}

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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;