Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add clear function to NavigationMesh / NavigationPolygon #79157

Merged
merged 1 commit into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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