Added utility functions to the new NavigationServer:

- Vector3 get_closest_point_to_segment(const Vector3 &p_from, const Vector3 &p_to, const bool &p_use_collision = false);
- Vector3 get_closest_point(const Vector3 &p_point);
- Vector3 get_closest_point_normal(const Vector3 &p_point);
- Object *get_closest_point_owner(const Vector3 &p_point);
This commit is contained in:
Andrea Catania 2020-02-18 17:08:34 +01:00
parent 6e64036693
commit 79fc7d7d6a
16 changed files with 372 additions and 10 deletions

View file

@ -15,7 +15,7 @@
<description> <description>
</description> </description>
</method> </method>
<method name="get_simple_path"> <method name="get_simple_path" qualifiers="const">
<return type="PackedVector3Array"> <return type="PackedVector3Array">
</return> </return>
<argument index="0" name="start" type="Vector3"> <argument index="0" name="start" type="Vector3">
@ -28,6 +28,46 @@
Returns the path between two given points. Points are in local coordinate space. If [code]optimize[/code] is [code]true[/code] (the default), the agent properties associated with each [NavigationMesh] (radius, height, etc.) are considered in the path calculation, otherwise they are ignored. Returns the path between two given points. Points are in local coordinate space. If [code]optimize[/code] is [code]true[/code] (the default), the agent properties associated with each [NavigationMesh] (radius, height, etc.) are considered in the path calculation, otherwise they are ignored.
</description> </description>
</method> </method>
<method name="get_closest_point_to_segment" qualifiers="const">
<return type="Vector3">
</return>
<argument index="0" name="from" type="Vector3">
</argument>
<argument index="1" name="to" type="Vector3">
</argument>
<argument index="2" name="use_collision" type="bool" default="false">
</argument>
<description>
Returns the closest point between the navigation surface and the segment.
</description>
</method>
<method name="get_closest_point" qualifiers="const">
<return type="Vector3">
</return>
<argument index="0" name="point" type="Vector3">
</argument>
<description>
Returns the point closest to the provided [code]point[/code] on the navigation mesh surface.
</description>
</method>
<method name="get_closest_point_normal" qualifiers="const">
<return type="Vector3">
</return>
<argument index="0" name="point" type="Vector3">
</argument>
<description>
Returns the normal for the point returned by [method get_closest_point].
</description>
</method>
<method name="get_closest_point_owner" qualifiers="const">
<return type="RID">
</return>
<argument index="0" name="point" type="Vector3">
</argument>
<description>
Returns the owner region RID for the point returned by [method get_closest_point].
</description>
</method>
</methods> </methods>
<members> <members>
<member name="cell_size" type="float" setter="set_cell_size" getter="get_cell_size" default="0.3"> <member name="cell_size" type="float" setter="set_cell_size" getter="get_cell_size" default="0.3">

View file

@ -15,7 +15,7 @@
<description> <description>
</description> </description>
</method> </method>
<method name="get_simple_path"> <method name="get_simple_path" qualifiers="const">
<return type="PackedVector2Array"> <return type="PackedVector2Array">
</return> </return>
<argument index="0" name="start" type="Vector2"> <argument index="0" name="start" type="Vector2">
@ -28,6 +28,24 @@
Returns the path between two given points. Points are in local coordinate space. If [code]optimize[/code] is [code]true[/code] (the default), the path is smoothed by merging path segments where possible. Returns the path between two given points. Points are in local coordinate space. If [code]optimize[/code] is [code]true[/code] (the default), the path is smoothed by merging path segments where possible.
</description> </description>
</method> </method>
<method name="get_closest_point" qualifiers="const">
<return type="Vector2">
</return>
<argument index="0" name="point" type="Vector2">
</argument>
<description>
Returns the point closest to the provided [code]point[/code] on the navigation mesh surface.
</description>
</method>
<method name="get_closest_point_owner" qualifiers="const">
<return type="RID">
</return>
<argument index="0" name="point" type="Vector2">
</argument>
<description>
Returns the owner region RID for the point returned by [method get_closest_point].
</description>
</method>
</methods> </methods>
<members> <members>
<member name="cell_size" type="float" setter="set_cell_size" getter="get_cell_size" default="10.0"> <member name="cell_size" type="float" setter="set_cell_size" getter="get_cell_size" default="10.0">

View file

@ -188,6 +188,28 @@
Returns the navigation path to reach the destination from the origin, while avoiding static obstacles. Returns the navigation path to reach the destination from the origin, while avoiding static obstacles.
</description> </description>
</method> </method>
<method name="map_get_closest_point" qualifiers="const">
<return type="Vector2">
</return>
<argument index="0" name="map" type="RID">
</argument>
<argument index="1" name="point" type="Vector2">
</argument>
<description>
Returns the point closest to the provided [code]point[/code] on the navigation mesh surface.
</description>
</method>
<method name="map_get_closest_point_owner" qualifiers="const">
<return type="RID">
</return>
<argument index="0" name="map" type="RID">
</argument>
<argument index="1" name="point" type="Vector2">
</argument>
<description>
Returns the owner region RID for the point returned by [method map_get_closest_point].
</description>
</method>
<method name="map_is_active" qualifiers="const"> <method name="map_is_active" qualifiers="const">
<return type="bool"> <return type="bool">
</return> </return>

View file

@ -188,6 +188,54 @@
Returns the navigation path to reach the destination from the origin. Returns the navigation path to reach the destination from the origin.
</description> </description>
</method> </method>
<method name="map_get_closest_point_to_segment" qualifiers="const">
<return type="Vector3">
</return>
<argument index="0" name="map" type="RID">
</argument>
<argument index="1" name="from" type="Vector3">
</argument>
<argument index="2" name="to" type="Vector3">
</argument>
<argument index="3" name="use_collision" type="bool" default="false">
</argument>
<description>
Returns the closest point between the navigation surface and the segment.
</description>
</method>
<method name="map_get_closest_point" qualifiers="const">
<return type="Vector3">
</return>
<argument index="0" name="map" type="RID">
</argument>
<argument index="1" name="point" type="Vector3">
</argument>
<description>
Returns the point closest to the provided [code]point[/code] on the navigation mesh surface.
</description>
</method>
<method name="map_get_closest_point_normal" qualifiers="const">
<return type="Vector3">
</return>
<argument index="0" name="map" type="RID">
</argument>
<argument index="1" name="point" type="Vector3">
</argument>
<description>
Returns the normal for the point returned by [method map_get_closest_point].
</description>
</method>
<method name="map_get_closest_point_owner" qualifiers="const">
<return type="RID">
</return>
<argument index="0" name="map" type="RID">
</argument>
<argument index="1" name="point" type="Vector3">
</argument>
<description>
Returns the owner region RID for the point returned by [method map_get_closest_point].
</description>
</method>
<method name="map_get_up" qualifiers="const"> <method name="map_get_up" qualifiers="const">
<return type="Vector3"> <return type="Vector3">
</return> </return>

View file

@ -170,7 +170,7 @@ COMMAND_2(map_set_up, RID, p_map, Vector3, p_up) {
} }
Vector3 GdNavigationServer::map_get_up(RID p_map) const { Vector3 GdNavigationServer::map_get_up(RID p_map) const {
NavMap *map = map_owner.getornull(p_map); const NavMap *map = map_owner.getornull(p_map);
ERR_FAIL_COND_V(map == NULL, Vector3()); ERR_FAIL_COND_V(map == NULL, Vector3());
return map->get_up(); return map->get_up();
@ -184,7 +184,7 @@ COMMAND_2(map_set_cell_size, RID, p_map, real_t, p_cell_size) {
} }
real_t GdNavigationServer::map_get_cell_size(RID p_map) const { real_t GdNavigationServer::map_get_cell_size(RID p_map) const {
NavMap *map = map_owner.getornull(p_map); const NavMap *map = map_owner.getornull(p_map);
ERR_FAIL_COND_V(map == NULL, 0); ERR_FAIL_COND_V(map == NULL, 0);
return map->get_cell_size(); return map->get_cell_size();
@ -198,19 +198,47 @@ COMMAND_2(map_set_edge_connection_margin, RID, p_map, real_t, p_connection_margi
} }
real_t GdNavigationServer::map_get_edge_connection_margin(RID p_map) const { real_t GdNavigationServer::map_get_edge_connection_margin(RID p_map) const {
NavMap *map = map_owner.getornull(p_map); const NavMap *map = map_owner.getornull(p_map);
ERR_FAIL_COND_V(map == NULL, 0); ERR_FAIL_COND_V(map == NULL, 0);
return map->get_edge_connection_margin(); return map->get_edge_connection_margin();
} }
Vector<Vector3> GdNavigationServer::map_get_path(RID p_map, Vector3 p_origin, Vector3 p_destination, bool p_optimize) const { Vector<Vector3> GdNavigationServer::map_get_path(RID p_map, Vector3 p_origin, Vector3 p_destination, bool p_optimize) const {
NavMap *map = map_owner.getornull(p_map); const NavMap *map = map_owner.getornull(p_map);
ERR_FAIL_COND_V(map == NULL, Vector<Vector3>()); ERR_FAIL_COND_V(map == NULL, Vector<Vector3>());
return map->get_path(p_origin, p_destination, p_optimize); return map->get_path(p_origin, p_destination, p_optimize);
} }
Vector3 GdNavigationServer::map_get_closest_point_to_segment(RID p_map, const Vector3 &p_from, const Vector3 &p_to, const bool p_use_collision) const {
const NavMap *map = map_owner.getornull(p_map);
ERR_FAIL_COND_V(map == NULL, Vector3());
return map->get_closest_point_to_segment(p_from, p_to, p_use_collision);
}
Vector3 GdNavigationServer::map_get_closest_point(RID p_map, const Vector3 &p_point) const {
const NavMap *map = map_owner.getornull(p_map);
ERR_FAIL_COND_V(map == NULL, Vector3());
return map->get_closest_point(p_point);
}
Vector3 GdNavigationServer::map_get_closest_point_normal(RID p_map, const Vector3 &p_point) const {
const NavMap *map = map_owner.getornull(p_map);
ERR_FAIL_COND_V(map == NULL, Vector3());
return map->get_closest_point_normal(p_point);
}
RID GdNavigationServer::map_get_closest_point_owner(RID p_map, const Vector3 &p_point) const {
const NavMap *map = map_owner.getornull(p_map);
ERR_FAIL_COND_V(map == NULL, RID());
return map->get_closest_point_owner(p_point);
}
RID GdNavigationServer::region_create() const { RID GdNavigationServer::region_create() const {
auto mut_this = const_cast<GdNavigationServer *>(this); auto mut_this = const_cast<GdNavigationServer *>(this);
mut_this->operations_mutex->lock(); mut_this->operations_mutex->lock();

View file

@ -103,6 +103,11 @@ public:
virtual Vector<Vector3> map_get_path(RID p_map, Vector3 p_origin, Vector3 p_destination, bool p_optimize) const; virtual Vector<Vector3> map_get_path(RID p_map, Vector3 p_origin, Vector3 p_destination, bool p_optimize) const;
virtual Vector3 map_get_closest_point_to_segment(RID p_map, const Vector3 &p_from, const Vector3 &p_to, const bool p_use_collision = false) const;
virtual Vector3 map_get_closest_point(RID p_map, const Vector3 &p_point) const;
virtual Vector3 map_get_closest_point_normal(RID p_map, const Vector3 &p_point) const;
virtual RID map_get_closest_point_owner(RID p_map, const Vector3 &p_point) const;
virtual RID region_create() const; virtual RID region_create() const;
COMMAND_2(region_set_map, RID, p_region, RID, p_map); COMMAND_2(region_set_map, RID, p_region, RID, p_map);
COMMAND_2(region_set_transform, RID, p_region, Transform, p_transform); COMMAND_2(region_set_transform, RID, p_region, Transform, p_transform);

View file

@ -401,6 +401,144 @@ Vector<Vector3> NavMap::get_path(Vector3 p_origin, Vector3 p_destination, bool p
return Vector<Vector3>(); return Vector<Vector3>();
} }
Vector3 NavMap::get_closest_point_to_segment(const Vector3 &p_from, const Vector3 &p_to, const bool p_use_collision) const {
bool use_collision = p_use_collision;
Vector3 closest_point;
real_t closest_point_d = 1e20;
// Find the initial poly and the end poly on this map.
for (size_t i(0); i < polygons.size(); i++) {
const gd::Polygon &p = polygons[i];
// For each point cast a face and check the distance to the segment
for (size_t point_id = 2; point_id < p.points.size(); point_id += 1) {
const Face3 f(p.points[point_id - 2].pos, p.points[point_id - 1].pos, p.points[point_id].pos);
Vector3 inters;
if (f.intersects_segment(p_from, p_to, &inters)) {
const real_t d = closest_point_d = p_from.distance_to(inters);
if (use_collision == false) {
closest_point = inters;
use_collision = true;
closest_point_d = d;
} else if (closest_point_d > d) {
closest_point = inters;
closest_point_d = d;
}
}
}
if (use_collision == false) {
for (size_t point_id = 0; point_id < p.points.size(); point_id += 1) {
Vector3 a, b;
Geometry::get_closest_points_between_segments(
p_from,
p_to,
p.points[point_id].pos,
p.points[(point_id + 1) % p.points.size()].pos,
a,
b);
const real_t d = a.distance_to(b);
if (d < closest_point_d) {
closest_point_d = d;
closest_point = b;
}
}
}
}
return closest_point;
}
Vector3 NavMap::get_closest_point(const Vector3 &p_point) const {
// TODO this is really not optimal, please redesign the API to directly return all this data
Vector3 closest_point;
real_t closest_point_d = 1e20;
// Find the initial poly and the end poly on this map.
for (size_t i(0); i < polygons.size(); i++) {
const gd::Polygon &p = polygons[i];
// For each point cast a face and check the distance to the point
for (size_t point_id = 2; point_id < p.points.size(); point_id += 1) {
const Face3 f(p.points[point_id - 2].pos, p.points[point_id - 1].pos, p.points[point_id].pos);
const Vector3 inters = f.get_closest_point_to(p_point);
const real_t d = inters.distance_to(p_point);
if (d < closest_point_d) {
closest_point = inters;
closest_point_d = d;
}
}
}
return closest_point;
}
Vector3 NavMap::get_closest_point_normal(const Vector3 &p_point) const {
// TODO this is really not optimal, please redesign the API to directly return all this data
Vector3 closest_point;
Vector3 closest_point_normal;
real_t closest_point_d = 1e20;
// Find the initial poly and the end poly on this map.
for (size_t i(0); i < polygons.size(); i++) {
const gd::Polygon &p = polygons[i];
// For each point cast a face and check the distance to the point
for (size_t point_id = 2; point_id < p.points.size(); point_id += 1) {
const Face3 f(p.points[point_id - 2].pos, p.points[point_id - 1].pos, p.points[point_id].pos);
const Vector3 inters = f.get_closest_point_to(p_point);
const real_t d = inters.distance_to(p_point);
if (d < closest_point_d) {
closest_point = inters;
closest_point_normal = f.get_plane().normal;
closest_point_d = d;
}
}
}
return closest_point_normal;
}
RID NavMap::get_closest_point_owner(const Vector3 &p_point) const {
// TODO this is really not optimal, please redesign the API to directly return all this data
Vector3 closest_point;
RID closest_point_owner;
real_t closest_point_d = 1e20;
// Find the initial poly and the end poly on this map.
for (size_t i(0); i < polygons.size(); i++) {
const gd::Polygon &p = polygons[i];
// For each point cast a face and check the distance to the point
for (size_t point_id = 2; point_id < p.points.size(); point_id += 1) {
const Face3 f(p.points[point_id - 2].pos, p.points[point_id - 1].pos, p.points[point_id].pos);
const Vector3 inters = f.get_closest_point_to(p_point);
const real_t d = inters.distance_to(p_point);
if (d < closest_point_d) {
closest_point = inters;
closest_point_owner = p.owner->get_self();
closest_point_d = d;
}
}
}
return closest_point_owner;
}
void NavMap::add_region(NavRegion *p_region) { void NavMap::add_region(NavRegion *p_region) {
regions.push_back(p_region); regions.push_back(p_region);
regenerate_links = true; regenerate_links = true;

View file

@ -104,6 +104,10 @@ public:
gd::PointKey get_point_key(const Vector3 &p_pos) const; gd::PointKey get_point_key(const Vector3 &p_pos) const;
Vector<Vector3> get_path(Vector3 p_origin, Vector3 p_destination, bool p_optimize) const; Vector<Vector3> get_path(Vector3 p_origin, Vector3 p_destination, bool p_optimize) const;
Vector3 get_closest_point_to_segment(const Vector3 &p_from, const Vector3 &p_to, const bool p_use_collision) const;
Vector3 get_closest_point(const Vector3 &p_point) const;
Vector3 get_closest_point_normal(const Vector3 &p_point) const;
RID get_closest_point_owner(const Vector3 &p_point) const;
void add_region(NavRegion *p_region); void add_region(NavRegion *p_region);
void remove_region(NavRegion *p_region); void remove_region(NavRegion *p_region);

View file

@ -35,6 +35,8 @@ void Navigation2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_rid"), &Navigation2D::get_rid); ClassDB::bind_method(D_METHOD("get_rid"), &Navigation2D::get_rid);
ClassDB::bind_method(D_METHOD("get_simple_path", "start", "end", "optimize"), &Navigation2D::get_simple_path, DEFVAL(true)); ClassDB::bind_method(D_METHOD("get_simple_path", "start", "end", "optimize"), &Navigation2D::get_simple_path, DEFVAL(true));
ClassDB::bind_method(D_METHOD("get_closest_point", "to_point"), &Navigation2D::get_closest_point);
ClassDB::bind_method(D_METHOD("get_closest_point_owner", "to_point"), &Navigation2D::get_closest_point_owner);
ClassDB::bind_method(D_METHOD("set_cell_size", "cell_size"), &Navigation2D::set_cell_size); ClassDB::bind_method(D_METHOD("set_cell_size", "cell_size"), &Navigation2D::set_cell_size);
ClassDB::bind_method(D_METHOD("get_cell_size"), &Navigation2D::get_cell_size); ClassDB::bind_method(D_METHOD("get_cell_size"), &Navigation2D::get_cell_size);
@ -68,10 +70,18 @@ void Navigation2D::set_edge_connection_margin(float p_edge_connection_margin) {
Navigation2DServer::get_singleton()->map_set_edge_connection_margin(map, edge_connection_margin); Navigation2DServer::get_singleton()->map_set_edge_connection_margin(map, edge_connection_margin);
} }
Vector<Vector2> Navigation2D::get_simple_path(const Vector2 &p_start, const Vector2 &p_end, bool p_optimize) { Vector<Vector2> Navigation2D::get_simple_path(const Vector2 &p_start, const Vector2 &p_end, bool p_optimize) const {
return Navigation2DServer::get_singleton()->map_get_path(map, p_start, p_end, p_optimize); return Navigation2DServer::get_singleton()->map_get_path(map, p_start, p_end, p_optimize);
} }
Vector2 Navigation2D::get_closest_point(const Vector2 &p_point) const {
return Navigation2DServer::get_singleton()->map_get_closest_point(map, p_point);
}
RID Navigation2D::get_closest_point_owner(const Vector2 &p_point) const {
return Navigation2DServer::get_singleton()->map_get_closest_point_owner(map, p_point);
}
Navigation2D::Navigation2D() { Navigation2D::Navigation2D() {
map = Navigation2DServer::get_singleton()->map_create(); map = Navigation2DServer::get_singleton()->map_create();

View file

@ -61,7 +61,9 @@ public:
return edge_connection_margin; return edge_connection_margin;
} }
Vector<Vector2> get_simple_path(const Vector2 &p_start, const Vector2 &p_end, bool p_optimize = true); Vector<Vector2> get_simple_path(const Vector2 &p_start, const Vector2 &p_end, bool p_optimize = true) const;
Vector2 get_closest_point(const Vector2 &p_point) const;
RID get_closest_point_owner(const Vector2 &p_point) const;
Navigation2D(); Navigation2D();
}; };

View file

@ -32,11 +32,27 @@
#include "servers/navigation_server.h" #include "servers/navigation_server.h"
Vector<Vector3> Navigation::get_simple_path(const Vector3 &p_start, const Vector3 &p_end, bool p_optimize) { Vector<Vector3> Navigation::get_simple_path(const Vector3 &p_start, const Vector3 &p_end, bool p_optimize) const {
return NavigationServer::get_singleton()->map_get_path(map, p_start, p_end, p_optimize); return NavigationServer::get_singleton()->map_get_path(map, p_start, p_end, p_optimize);
} }
Vector3 Navigation::get_closest_point_to_segment(const Vector3 &p_from, const Vector3 &p_to, bool p_use_collision) const {
return NavigationServer::get_singleton()->map_get_closest_point_to_segment(map, p_from, p_to, p_use_collision);
}
Vector3 Navigation::get_closest_point(const Vector3 &p_point) const {
return NavigationServer::get_singleton()->map_get_closest_point(map, p_point);
}
Vector3 Navigation::get_closest_point_normal(const Vector3 &p_point) const {
return NavigationServer::get_singleton()->map_get_closest_point_normal(map, p_point);
}
RID Navigation::get_closest_point_owner(const Vector3 &p_point) const {
return NavigationServer::get_singleton()->map_get_closest_point_owner(map, p_point);
}
void Navigation::set_up_vector(const Vector3 &p_up) { void Navigation::set_up_vector(const Vector3 &p_up) {
up = p_up; up = p_up;
@ -63,6 +79,10 @@ void Navigation::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_rid"), &Navigation::get_rid); ClassDB::bind_method(D_METHOD("get_rid"), &Navigation::get_rid);
ClassDB::bind_method(D_METHOD("get_simple_path", "start", "end", "optimize"), &Navigation::get_simple_path, DEFVAL(true)); ClassDB::bind_method(D_METHOD("get_simple_path", "start", "end", "optimize"), &Navigation::get_simple_path, DEFVAL(true));
ClassDB::bind_method(D_METHOD("get_closest_point_to_segment", "start", "end", "use_collision"), &Navigation::get_closest_point_to_segment, DEFVAL(false));
ClassDB::bind_method(D_METHOD("get_closest_point", "to_point"), &Navigation::get_closest_point);
ClassDB::bind_method(D_METHOD("get_closest_point_normal", "to_point"), &Navigation::get_closest_point_normal);
ClassDB::bind_method(D_METHOD("get_closest_point_owner", "to_point"), &Navigation::get_closest_point_owner);
ClassDB::bind_method(D_METHOD("set_up_vector", "up"), &Navigation::set_up_vector); ClassDB::bind_method(D_METHOD("set_up_vector", "up"), &Navigation::set_up_vector);
ClassDB::bind_method(D_METHOD("get_up_vector"), &Navigation::get_up_vector); ClassDB::bind_method(D_METHOD("get_up_vector"), &Navigation::get_up_vector);

View file

@ -66,7 +66,11 @@ public:
return edge_connection_margin; return edge_connection_margin;
} }
Vector<Vector3> get_simple_path(const Vector3 &p_start, const Vector3 &p_end, bool p_optimize = true); Vector<Vector3> get_simple_path(const Vector3 &p_start, const Vector3 &p_end, bool p_optimize = true) const;
Vector3 get_closest_point_to_segment(const Vector3 &p_from, const Vector3 &p_to, bool p_use_collision = false) const;
Vector3 get_closest_point(const Vector3 &p_point) const;
Vector3 get_closest_point_normal(const Vector3 &p_point) const;
RID get_closest_point_owner(const Vector3 &p_point) const;
Navigation(); Navigation();
~Navigation(); ~Navigation();

View file

@ -62,6 +62,12 @@ Navigation2DServer *Navigation2DServer::singleton = NULL;
return NavigationServer::get_singleton()->FUNC_NAME(CONV_0(D_0), CONV_1(D_1)); \ return NavigationServer::get_singleton()->FUNC_NAME(CONV_0(D_0), CONV_1(D_1)); \
} }
#define FORWARD_2_R_C(CONV_R, FUNC_NAME, T_0, D_0, T_1, D_1, CONV_0, CONV_1) \
Navigation2DServer::FUNC_NAME(T_0 D_0, T_1 D_1) \
const { \
return CONV_R(NavigationServer::get_singleton()->FUNC_NAME(CONV_0(D_0), CONV_1(D_1))); \
}
#define FORWARD_4_R_C(CONV_R, FUNC_NAME, T_0, D_0, T_1, D_1, T_2, D_2, T_3, D_3, CONV_0, CONV_1, CONV_2, CONV_3) \ #define FORWARD_4_R_C(CONV_R, FUNC_NAME, T_0, D_0, T_1, D_1, T_2, D_2, T_3, D_3, CONV_0, CONV_1, CONV_2, CONV_3) \
Navigation2DServer::FUNC_NAME(T_0 D_0, T_1 D_1, T_2 D_2, T_3 D_3) \ Navigation2DServer::FUNC_NAME(T_0 D_0, T_1 D_1, T_2 D_2, T_3 D_3) \
const { \ const { \
@ -132,6 +138,8 @@ void Navigation2DServer::_bind_methods() {
ClassDB::bind_method(D_METHOD("map_set_edge_connection_margin", "map", "margin"), &Navigation2DServer::map_set_edge_connection_margin); ClassDB::bind_method(D_METHOD("map_set_edge_connection_margin", "map", "margin"), &Navigation2DServer::map_set_edge_connection_margin);
ClassDB::bind_method(D_METHOD("map_get_edge_connection_margin", "map"), &Navigation2DServer::map_get_edge_connection_margin); ClassDB::bind_method(D_METHOD("map_get_edge_connection_margin", "map"), &Navigation2DServer::map_get_edge_connection_margin);
ClassDB::bind_method(D_METHOD("map_get_path", "map", "origin", "destination", "optimize"), &Navigation2DServer::map_get_path); ClassDB::bind_method(D_METHOD("map_get_path", "map", "origin", "destination", "optimize"), &Navigation2DServer::map_get_path);
ClassDB::bind_method(D_METHOD("map_get_closest_point", "map", "to_point"), &Navigation2DServer::map_get_closest_point);
ClassDB::bind_method(D_METHOD("map_get_closest_point_owner", "map", "to_point"), &Navigation2DServer::map_get_closest_point_owner);
ClassDB::bind_method(D_METHOD("region_create"), &Navigation2DServer::region_create); ClassDB::bind_method(D_METHOD("region_create"), &Navigation2DServer::region_create);
ClassDB::bind_method(D_METHOD("region_set_map", "region", "map"), &Navigation2DServer::region_set_map); ClassDB::bind_method(D_METHOD("region_set_map", "region", "map"), &Navigation2DServer::region_set_map);
@ -176,6 +184,9 @@ real_t FORWARD_1_C(map_get_edge_connection_margin, RID, p_map, rid_to_rid);
Vector<Vector2> FORWARD_4_R_C(vector_v3_to_v2, map_get_path, RID, p_map, Vector2, p_origin, Vector2, p_destination, bool, p_optimize, rid_to_rid, v2_to_v3, v2_to_v3, bool_to_bool); Vector<Vector2> FORWARD_4_R_C(vector_v3_to_v2, map_get_path, RID, p_map, Vector2, p_origin, Vector2, p_destination, bool, p_optimize, rid_to_rid, v2_to_v3, v2_to_v3, bool_to_bool);
Vector2 FORWARD_2_R_C(v3_to_v2, map_get_closest_point, RID, p_map, const Vector2 &, p_point, rid_to_rid, v2_to_v3);
RID FORWARD_2_C(map_get_closest_point_owner, RID, p_map, const Vector2 &, p_point, rid_to_rid, v2_to_v3);
RID FORWARD_0_C(region_create); RID FORWARD_0_C(region_create);
void FORWARD_2_C(region_set_map, RID, p_region, RID, p_map, rid_to_rid, rid_to_rid); void FORWARD_2_C(region_set_map, RID, p_region, RID, p_map, rid_to_rid, rid_to_rid);

View file

@ -79,6 +79,9 @@ public:
/// Returns the navigation path to reach the destination from the origin. /// Returns the navigation path to reach the destination from the origin.
virtual Vector<Vector2> map_get_path(RID p_map, Vector2 p_origin, Vector2 p_destination, bool p_optimize) const; virtual Vector<Vector2> map_get_path(RID p_map, Vector2 p_origin, Vector2 p_destination, bool p_optimize) const;
virtual Vector2 map_get_closest_point(RID p_map, const Vector2 &p_point) const;
virtual RID map_get_closest_point_owner(RID p_map, const Vector2 &p_point) const;
/// Creates a new region. /// Creates a new region.
virtual RID region_create() const; virtual RID region_create() const;

View file

@ -48,6 +48,10 @@ void NavigationServer::_bind_methods() {
ClassDB::bind_method(D_METHOD("map_set_edge_connection_margin", "map", "margin"), &NavigationServer::map_set_edge_connection_margin); ClassDB::bind_method(D_METHOD("map_set_edge_connection_margin", "map", "margin"), &NavigationServer::map_set_edge_connection_margin);
ClassDB::bind_method(D_METHOD("map_get_edge_connection_margin", "map"), &NavigationServer::map_get_edge_connection_margin); ClassDB::bind_method(D_METHOD("map_get_edge_connection_margin", "map"), &NavigationServer::map_get_edge_connection_margin);
ClassDB::bind_method(D_METHOD("map_get_path", "map", "origin", "destination", "optimize"), &NavigationServer::map_get_path); ClassDB::bind_method(D_METHOD("map_get_path", "map", "origin", "destination", "optimize"), &NavigationServer::map_get_path);
ClassDB::bind_method(D_METHOD("map_get_closest_point_to_segment", "map", "start", "end", "use_collision"), &NavigationServer::map_get_closest_point_to_segment, DEFVAL(false));
ClassDB::bind_method(D_METHOD("map_get_closest_point", "map", "to_point"), &NavigationServer::map_get_closest_point);
ClassDB::bind_method(D_METHOD("map_get_closest_point_normal", "map", "to_point"), &NavigationServer::map_get_closest_point_normal);
ClassDB::bind_method(D_METHOD("map_get_closest_point_owner", "map", "to_point"), &NavigationServer::map_get_closest_point_owner);
ClassDB::bind_method(D_METHOD("region_create"), &NavigationServer::region_create); ClassDB::bind_method(D_METHOD("region_create"), &NavigationServer::region_create);
ClassDB::bind_method(D_METHOD("region_set_map", "region", "map"), &NavigationServer::region_set_map); ClassDB::bind_method(D_METHOD("region_set_map", "region", "map"), &NavigationServer::region_set_map);

View file

@ -90,6 +90,11 @@ public:
/// Returns the navigation path to reach the destination from the origin. /// Returns the navigation path to reach the destination from the origin.
virtual Vector<Vector3> map_get_path(RID p_map, Vector3 p_origin, Vector3 p_destination, bool p_optimize) const = 0; virtual Vector<Vector3> map_get_path(RID p_map, Vector3 p_origin, Vector3 p_destination, bool p_optimize) const = 0;
virtual Vector3 map_get_closest_point_to_segment(RID p_map, const Vector3 &p_from, const Vector3 &p_to, const bool p_use_collision = false) const = 0;
virtual Vector3 map_get_closest_point(RID p_map, const Vector3 &p_point) const = 0;
virtual Vector3 map_get_closest_point_normal(RID p_map, const Vector3 &p_point) const = 0;
virtual RID map_get_closest_point_owner(RID p_map, const Vector3 &p_point) const = 0;
/// Creates a new region. /// Creates a new region.
virtual RID region_create() const = 0; virtual RID region_create() const = 0;