diff --git a/doc/classes/NavigationMesh.xml b/doc/classes/NavigationMesh.xml index 3dcda01f761..247b7b5329d 100644 --- a/doc/classes/NavigationMesh.xml +++ b/doc/classes/NavigationMesh.xml @@ -18,6 +18,12 @@ Adds a polygon using the indices of the vertices you get when calling [method get_vertices]. + + + + Clears the internal arrays for vertices and polygon indices. + + diff --git a/doc/classes/NavigationPolygon.xml b/doc/classes/NavigationPolygon.xml index 1c44ffbd57a..fe28c5a468b 100644 --- a/doc/classes/NavigationPolygon.xml +++ b/doc/classes/NavigationPolygon.xml @@ -69,6 +69,12 @@ Adds a polygon using the indices of the vertices you get when calling [method get_vertices]. + + + + Clears the internal arrays for vertices and polygon indices. + + diff --git a/scene/resources/navigation_mesh.cpp b/scene/resources/navigation_mesh.cpp index 1d13f07b126..82b5c6257c0 100644 --- a/scene/resources/navigation_mesh.cpp +++ b/scene/resources/navigation_mesh.cpp @@ -341,6 +341,11 @@ void NavigationMesh::clear_polygons() { polygons.clear(); } +void NavigationMesh::clear() { + polygons.clear(); + vertices.clear(); +} + #ifdef DEBUG_ENABLED Ref NavigationMesh::get_debug_mesh() { if (debug_mesh.is_valid()) { @@ -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"); diff --git a/scene/resources/navigation_mesh.h b/scene/resources/navigation_mesh.h index c3b8c13c053..97abc122fdb 100644 --- a/scene/resources/navigation_mesh.h +++ b/scene/resources/navigation_mesh.h @@ -202,6 +202,8 @@ public: Vector get_polygon(int p_idx); void clear_polygons(); + void clear(); + #ifdef DEBUG_ENABLED Ref get_debug_mesh(); #endif // DEBUG_ENABLED diff --git a/scene/resources/navigation_polygon.cpp b/scene/resources/navigation_polygon.cpp index 0b60d46d407..e521bfb2e04 100644 --- a/scene/resources/navigation_polygon.cpp +++ b/scene/resources/navigation_polygon.cpp @@ -162,6 +162,15 @@ void NavigationPolygon::clear_polygons() { } } +void NavigationPolygon::clear() { + polygons.clear(); + vertices.clear(); + { + MutexLock lock(navigation_mesh_generation); + navigation_mesh.unref(); + } +} + Ref NavigationPolygon::get_navigation_mesh() { MutexLock lock(navigation_mesh_generation); @@ -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"); diff --git a/scene/resources/navigation_polygon.h b/scene/resources/navigation_polygon.h index 3ab666eb166..7926709a9ef 100644 --- a/scene/resources/navigation_polygon.h +++ b/scene/resources/navigation_polygon.h @@ -92,6 +92,8 @@ public: void set_cell_size(real_t p_cell_size); real_t get_cell_size() const; + void clear(); + NavigationPolygon() {} ~NavigationPolygon() {} };