From 43c11fcdf5f9e4a8272ad9db4bcfba2eba76c8d9 Mon Sep 17 00:00:00 2001 From: Relintai Date: Tue, 5 Sep 2023 09:13:54 +0200 Subject: [PATCH] Backported from godot4: Fix typo and ensure backwards compatibility for changed property names Changes to the name of the `navmesh` and `navpoly` properties on `NavigationRegion` caused navigation data to be lost on load. This PR creates uses `_set`/`_get` to handle compatibility with the older names on load, preserving the data. Also fixes a typo on `get_vertices_per_polygon` in `NavigationMesh`, and renames the property to remove the `polygon_` prefix which doesn't match the setter/getter. - DarkKilauea, akien-mga https://github.com/godotengine/godot/commit/0572346985eef45123a0f25cbd7c295e06bd9097 --- doc/classes/NavigationMesh.xml | 2 +- modules/gridmap/mesh_library.cpp | 12 ++++++ .../pandemonium_navigation_mesh_generator.cpp | 2 +- scene/2d/navigation_polygon_instance.cpp | 21 ++++++++++- scene/2d/navigation_polygon_instance.h | 5 +++ scene/3d/navigation_mesh_instance.cpp | 19 ++++++++++ scene/3d/navigation_mesh_instance.h | 5 +++ scene/resources/navigation_mesh.cpp | 37 ++++++++++++++----- scene/resources/navigation_mesh.h | 11 ++++-- 9 files changed, 99 insertions(+), 15 deletions(-) diff --git a/doc/classes/NavigationMesh.xml b/doc/classes/NavigationMesh.xml index ca1dbdaf4..d27862e65 100644 --- a/doc/classes/NavigationMesh.xml +++ b/doc/classes/NavigationMesh.xml @@ -147,7 +147,7 @@ The name of the group to scan for geometry. Only used when [member geometry_source_geometry_mode] is [constant SOURCE_GEOMETRY_GROUPS_WITH_CHILDREN] or [constant SOURCE_GEOMETRY_GROUPS_EXPLICIT]. - + The maximum number of vertices allowed for polygons generated during the contour to polygon conversion process. diff --git a/modules/gridmap/mesh_library.cpp b/modules/gridmap/mesh_library.cpp index e29eada12..5f2a58be0 100644 --- a/modules/gridmap/mesh_library.cpp +++ b/modules/gridmap/mesh_library.cpp @@ -62,6 +62,12 @@ bool MeshLibrary::_set(const StringName &p_name, const Variant &p_value) { set_item_navigation_mesh(idx, p_value); } else if (what == "navigation_mesh_transform") { set_item_navigation_mesh_transform(idx, p_value); +#ifndef DISABLE_DEPRECATED + } else if (what == "navmesh") { // Renamed after 4.0 + set_item_navigation_mesh(idx, p_value); + } else if (what == "navmesh_transform") { // Renamed after 4.0 + set_item_navigation_mesh_transform(idx, p_value); +#endif // DISABLE_DEPRECATED } else { return false; } @@ -90,6 +96,12 @@ bool MeshLibrary::_get(const StringName &p_name, Variant &r_ret) const { r_ret = get_item_navigation_mesh(idx); } else if (what == "navigation_mesh_transform") { r_ret = get_item_navigation_mesh_transform(idx); +#ifndef DISABLE_DEPRECATED + } else if (what == "navmesh") { // Renamed after 4.0 + r_ret = get_item_navigation_mesh(idx); + } else if (what == "navmesh_transform") { // Renamed after 4.0 + r_ret = get_item_navigation_mesh_transform(idx); +#endif // DISABLE_DEPRECATED } else if (what == "preview") { r_ret = get_item_preview(idx); } else { diff --git a/modules/navigation_mesh_generator/pandemonium_navigation_mesh_generator.cpp b/modules/navigation_mesh_generator/pandemonium_navigation_mesh_generator.cpp index 7e645b360..48a5f86a6 100644 --- a/modules/navigation_mesh_generator/pandemonium_navigation_mesh_generator.cpp +++ b/modules/navigation_mesh_generator/pandemonium_navigation_mesh_generator.cpp @@ -598,7 +598,7 @@ void PandemoniumNavigationMeshGenerator::_static_bake_3d_from_source_geometry_da cfg.maxSimplificationError = p_navigation_mesh->get_edge_max_error(); cfg.minRegionArea = (int)(p_navigation_mesh->get_region_min_size() * p_navigation_mesh->get_region_min_size()); cfg.mergeRegionArea = (int)(p_navigation_mesh->get_region_merge_size() * p_navigation_mesh->get_region_merge_size()); - cfg.maxVertsPerPoly = (int)p_navigation_mesh->get_vertices_per_polyon(); + cfg.maxVertsPerPoly = (int)p_navigation_mesh->get_vertices_per_polygon(); cfg.detailSampleDist = MAX(p_navigation_mesh->get_cell_size() * p_navigation_mesh->get_detail_sample_distance(), 0.1f); cfg.detailSampleMaxError = p_navigation_mesh->get_cell_height() * p_navigation_mesh->get_detail_sample_max_error(); diff --git a/scene/2d/navigation_polygon_instance.cpp b/scene/2d/navigation_polygon_instance.cpp index 4f831d444..3f86360c7 100644 --- a/scene/2d/navigation_polygon_instance.cpp +++ b/scene/2d/navigation_polygon_instance.cpp @@ -174,7 +174,7 @@ void NavigationPolygonInstance::_notification(int p_what) { } break; case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: { set_physics_process_internal(false); - + _region_update_transform(); } break; case NOTIFICATION_EXIT_TREE: { @@ -371,6 +371,25 @@ void NavigationPolygonInstance::_bind_methods() { ADD_SIGNAL(MethodInfo("bake_finished")); } +#ifndef DISABLE_DEPRECATED +//Renamed after 4.0 +bool NavigationPolygonInstance::_set(const StringName &p_name, const Variant &p_value) { + if (p_name == "navpoly") { + set_navigation_polygon(p_value); + return true; + } + return false; +} + +bool NavigationPolygonInstance::_get(const StringName &p_name, Variant &r_ret) const { + if (p_name == "navpoly") { + r_ret = get_navigation_polygon(); + return true; + } + return false; +} +#endif // DISABLE_DEPRECATED + NavigationPolygonInstance::NavigationPolygonInstance() { enabled = true; use_edge_connections = true; diff --git a/scene/2d/navigation_polygon_instance.h b/scene/2d/navigation_polygon_instance.h index 15ee63d80..fbf254324 100644 --- a/scene/2d/navigation_polygon_instance.h +++ b/scene/2d/navigation_polygon_instance.h @@ -75,6 +75,11 @@ protected: void _validate_property(PropertyInfo &p_property) const; static void _bind_methods(); +#ifndef DISABLE_DEPRECATED + bool _set(const StringName &p_name, const Variant &p_value); + bool _get(const StringName &p_name, Variant &r_ret) const; +#endif // DISABLE_DEPRECATED + public: #ifdef TOOLS_ENABLED virtual Rect2 _edit_get_rect() const; diff --git a/scene/3d/navigation_mesh_instance.cpp b/scene/3d/navigation_mesh_instance.cpp index 8a1647188..239ca8649 100644 --- a/scene/3d/navigation_mesh_instance.cpp +++ b/scene/3d/navigation_mesh_instance.cpp @@ -349,6 +349,25 @@ void NavigationMeshInstance::_bind_methods() { ADD_SIGNAL(MethodInfo("bake_finished")); } +#ifndef DISABLE_DEPRECATED +//Renamed after 4.0 +bool NavigationMeshInstance::_set(const StringName &p_name, const Variant &p_value) { + if (p_name == "navmesh") { + set_navigation_mesh(p_value); + return true; + } + return false; +} + +bool NavigationMeshInstance::_get(const StringName &p_name, Variant &r_ret) const { + if (p_name == "navmesh") { + r_ret = get_navigation_mesh(); + return true; + } + return false; +} +#endif // DISABLE_DEPRECATED + void NavigationMeshInstance::_changed_callback(Object *p_changed, const char *p_prop) { update_gizmos(); update_configuration_warning(); diff --git a/scene/3d/navigation_mesh_instance.h b/scene/3d/navigation_mesh_instance.h index 3e699644a..3a07b2ace 100644 --- a/scene/3d/navigation_mesh_instance.h +++ b/scene/3d/navigation_mesh_instance.h @@ -75,6 +75,11 @@ protected: static void _bind_methods(); void _changed_callback(Object *p_changed, const char *p_prop); +#ifndef DISABLE_DEPRECATED + bool _set(const StringName &p_name, const Variant &p_value); + bool _get(const StringName &p_name, Variant &r_ret) const; +#endif // DISABLE_DEPRECATED + public: void set_enabled(bool p_enabled); bool is_enabled() const; diff --git a/scene/resources/navigation_mesh.cpp b/scene/resources/navigation_mesh.cpp index c54363f8c..d70db7a31 100644 --- a/scene/resources/navigation_mesh.cpp +++ b/scene/resources/navigation_mesh.cpp @@ -225,13 +225,13 @@ float NavigationMesh::get_edge_max_error() const { return edge_max_error; } -void NavigationMesh::set_vertices_per_polyon(float p_value) { +void NavigationMesh::set_vertices_per_polygon(float p_value) { ERR_FAIL_COND(p_value < 3); - vertices_per_polyon = p_value; + vertices_per_polygon = p_value; } -float NavigationMesh::get_vertices_per_polyon() const { - return vertices_per_polyon; +float NavigationMesh::get_vertices_per_polygon() const { + return vertices_per_polygon; } void NavigationMesh::set_detail_sample_distance(float p_value) { @@ -526,8 +526,8 @@ void NavigationMesh::_bind_methods() { ClassDB::bind_method(D_METHOD("set_edge_max_error", "edge_max_error"), &NavigationMesh::set_edge_max_error); ClassDB::bind_method(D_METHOD("get_edge_max_error"), &NavigationMesh::get_edge_max_error); - ClassDB::bind_method(D_METHOD("set_vertices_per_polyon", "vertices_per_polyon"), &NavigationMesh::set_vertices_per_polyon); - ClassDB::bind_method(D_METHOD("get_vertices_per_polyon"), &NavigationMesh::get_vertices_per_polyon); + ClassDB::bind_method(D_METHOD("set_vertices_per_polygon", "vertices_per_polygon"), &NavigationMesh::set_vertices_per_polygon); + ClassDB::bind_method(D_METHOD("get_vertices_per_polygon"), &NavigationMesh::get_vertices_per_polygon); ClassDB::bind_method(D_METHOD("set_detail_sample_distance", "detail_sample_dist"), &NavigationMesh::set_detail_sample_distance); ClassDB::bind_method(D_METHOD("get_detail_sample_distance"), &NavigationMesh::get_detail_sample_distance); @@ -594,8 +594,8 @@ void NavigationMesh::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::REAL, "edge_max_length", PROPERTY_HINT_RANGE, "0.0,50.0,0.01,or_greater"), "set_edge_max_length", "get_edge_max_length"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "edge_max_error", PROPERTY_HINT_RANGE, "0.1,3.0,0.01,or_greater"), "set_edge_max_error", "get_edge_max_error"); - ADD_GROUP("Polygons", "polygon_"); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "polygon_vertices_per_polyon", PROPERTY_HINT_RANGE, "3.0,12.0,1.0,or_greater"), "set_vertices_per_polyon", "get_vertices_per_polyon"); + ADD_GROUP("Polygons", ""); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "vertices_per_polygon", PROPERTY_HINT_RANGE, "3.0,12.0,1.0,or_greater"), "set_vertices_per_polygon", "get_vertices_per_polygon"); ADD_GROUP("Details", "detail_"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "detail_sample_distance", PROPERTY_HINT_RANGE, "0.1,16.0,0.01,or_greater"), "set_detail_sample_distance", "get_detail_sample_distance"); @@ -640,6 +640,25 @@ void NavigationMesh::_validate_property(PropertyInfo &property) const { } } +#ifndef DISABLE_DEPRECATED +//Renamed after 4.0 +bool NavigationMesh::_set(const StringName &p_name, const Variant &p_value) { + if (p_name == "polygon_vertices_per_polyon") { // Renamed after 4.0 + set_vertices_per_polygon(p_value); + return true; + } + return false; +} + +bool NavigationMesh::_get(const StringName &p_name, Variant &r_ret) const { + if (p_name == "polygon_vertices_per_polyon") { // Renamed after 4.0 + r_ret = get_vertices_per_polygon(); + return true; + } + return false; +} +#endif // DISABLE_DEPRECATED + NavigationMesh::NavigationMesh() { cell_size = 0.25f; // Must match ProjectSettings default 3D cell_size and NavigationServer NavMap cell_size. cell_height = 0.25f; // Must match ProjectSettings default 3D cell_height and NavigationServer NavMap cell_height. @@ -651,7 +670,7 @@ NavigationMesh::NavigationMesh() { region_merge_size = 20.0f; edge_max_length = 0.0f; edge_max_error = 1.3f; - vertices_per_polyon = 6.0f; + vertices_per_polygon = 6.0f; detail_sample_distance = 6.0f; detail_sample_max_error = 5.0f; diff --git a/scene/resources/navigation_mesh.h b/scene/resources/navigation_mesh.h index b8acef2b7..7d248ff39 100644 --- a/scene/resources/navigation_mesh.h +++ b/scene/resources/navigation_mesh.h @@ -112,8 +112,8 @@ public: void set_edge_max_error(float p_value); float get_edge_max_error() const; - void set_vertices_per_polyon(float p_value); - float get_vertices_per_polyon() const; + void set_vertices_per_polygon(float p_value); + float get_vertices_per_polygon() const; void set_detail_sample_distance(float p_value); float get_detail_sample_distance() const; @@ -168,6 +168,11 @@ protected: static void _bind_methods(); virtual void _validate_property(PropertyInfo &property) const; +#ifndef DISABLE_DEPRECATED + bool _set(const StringName &p_name, const Variant &p_value); + bool _get(const StringName &p_name, Variant &r_ret) const; +#endif // DISABLE_DEPRECATED + float cell_size; float cell_height; float agent_height; @@ -178,7 +183,7 @@ protected: float region_merge_size; float edge_max_length; float edge_max_error; - float vertices_per_polyon; + float vertices_per_polygon; float detail_sample_distance; float detail_sample_max_error;