Skip to content

Commit

Permalink
Merge pull request #79157 from smix8/navmesh_clear_4.x
Browse files Browse the repository at this point in the history
Add `clear` function to NavigationMesh / NavigationPolygon
  • Loading branch information
YuriSizov committed Jul 24, 2023
2 parents 74d20fe + d253cd7 commit 52078dc
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 0 deletions.
6 changes: 6 additions & 0 deletions doc/classes/NavigationMesh.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
Adds a polygon using the indices of the vertices you get when calling [method get_vertices].
</description>
</method>
<method name="clear">
<return type="void" />
<description>
Clears the internal arrays for vertices and polygon indices.
</description>
</method>
<method name="clear_polygons">
<return type="void" />
<description>
Expand Down
6 changes: 6 additions & 0 deletions doc/classes/NavigationPolygon.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@
Adds a polygon using the indices of the vertices you get when calling [method get_vertices].
</description>
</method>
<method name="clear">
<return type="void" />
<description>
Clears the internal arrays for vertices and polygon indices.
</description>
</method>
<method name="clear_outlines">
<return type="void" />
<description>
Expand Down
7 changes: 7 additions & 0 deletions scene/resources/navigation_mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,11 @@ void NavigationMesh::clear_polygons() {
polygons.clear();
}

void NavigationMesh::clear() {
polygons.clear();
vertices.clear();
}

#ifdef DEBUG_ENABLED
Ref<ArrayMesh> NavigationMesh::get_debug_mesh() {
if (debug_mesh.is_valid()) {
Expand Down Expand Up @@ -518,6 +523,8 @@ void NavigationMesh::_bind_methods() {
ClassDB::bind_method(D_METHOD("_set_polygons", "polygons"), &NavigationMesh::_set_polygons);
ClassDB::bind_method(D_METHOD("_get_polygons"), &NavigationMesh::_get_polygons);

ClassDB::bind_method(D_METHOD("clear"), &NavigationMesh::clear);

ADD_PROPERTY(PropertyInfo(Variant::PACKED_VECTOR3_ARRAY, "vertices", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL), "set_vertices", "get_vertices");
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "polygons", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL), "_set_polygons", "_get_polygons");

Expand Down
2 changes: 2 additions & 0 deletions scene/resources/navigation_mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ class NavigationMesh : public Resource {
Vector<int> get_polygon(int p_idx);
void clear_polygons();

void clear();

#ifdef DEBUG_ENABLED
Ref<ArrayMesh> get_debug_mesh();
#endif // DEBUG_ENABLED
Expand Down
11 changes: 11 additions & 0 deletions scene/resources/navigation_polygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,15 @@ void NavigationPolygon::clear_polygons() {
}
}

void NavigationPolygon::clear() {
polygons.clear();
vertices.clear();
{
MutexLock lock(navigation_mesh_generation);
navigation_mesh.unref();
}
}

Ref<NavigationMesh> NavigationPolygon::get_navigation_mesh() {
MutexLock lock(navigation_mesh_generation);

Expand Down Expand Up @@ -360,6 +369,8 @@ void NavigationPolygon::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_cell_size", "cell_size"), &NavigationPolygon::set_cell_size);
ClassDB::bind_method(D_METHOD("get_cell_size"), &NavigationPolygon::get_cell_size);

ClassDB::bind_method(D_METHOD("clear"), &NavigationPolygon::clear);

ADD_PROPERTY(PropertyInfo(Variant::PACKED_VECTOR2_ARRAY, "vertices", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL), "set_vertices", "get_vertices");
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "polygons", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL), "_set_polygons", "_get_polygons");
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "outlines", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL), "_set_outlines", "_get_outlines");
Expand Down
2 changes: 2 additions & 0 deletions scene/resources/navigation_polygon.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ class NavigationPolygon : public Resource {
void set_cell_size(real_t p_cell_size);
real_t get_cell_size() const;

void clear();

NavigationPolygon() {}
~NavigationPolygon() {}
};
Expand Down

0 comments on commit 52078dc

Please sign in to comment.