From 27267b62cbd364c53728076fdfc9ab7554a4f043 Mon Sep 17 00:00:00 2001 From: smix8 <52464204+smix8@users.noreply.github.com> Date: Thu, 28 Sep 2023 02:36:15 +0200 Subject: [PATCH] Update TileMap to use new navigation polygon baking Updates TileMap to use new navigation polygon baking. --- editor/plugins/tiles/tile_data_editors.cpp | 24 ++++++++++++------- .../tiles/tile_set_atlas_source_editor.cpp | 19 +++++++++++---- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/editor/plugins/tiles/tile_data_editors.cpp b/editor/plugins/tiles/tile_data_editors.cpp index aefad2ec628..d634d957b3e 100644 --- a/editor/plugins/tiles/tile_data_editors.cpp +++ b/editor/plugins/tiles/tile_data_editors.cpp @@ -49,9 +49,7 @@ #include "scene/gui/separator.h" #include "scene/gui/spin_box.h" -#ifdef DEBUG_ENABLED -#include "servers/navigation_server_3d.h" -#endif // DEBUG_ENABLED +#include "servers/navigation_server_2d.h" void TileDataEditor::_tile_set_changed_plan_update() { _tile_set_changed_update_needed = true; @@ -2826,12 +2824,20 @@ Variant TileDataNavigationEditor::_get_painted_value() { Ref nav_polygon; nav_polygon.instantiate(); - for (int i = 0; i < polygon_editor->get_polygon_count(); i++) { - Vector polygon = polygon_editor->get_polygon(i); - nav_polygon->add_outline(polygon); + if (polygon_editor->get_polygon_count() > 0) { + Ref source_geometry_data; + source_geometry_data.instantiate(); + for (int i = 0; i < polygon_editor->get_polygon_count(); i++) { + Vector polygon = polygon_editor->get_polygon(i); + nav_polygon->add_outline(polygon); + source_geometry_data->add_traversable_outline(polygon); + } + nav_polygon->set_agent_radius(0.0); + NavigationServer2D::get_singleton()->bake_from_source_geometry_data(nav_polygon, source_geometry_data); + } else { + nav_polygon->clear(); } - nav_polygon->make_polygons_from_outlines(); return nav_polygon; } @@ -2881,7 +2887,7 @@ void TileDataNavigationEditor::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_TREE: { #ifdef DEBUG_ENABLED - polygon_editor->set_polygons_color(NavigationServer3D::get_singleton()->get_debug_navigation_geometry_face_color()); + polygon_editor->set_polygons_color(NavigationServer2D::get_singleton()->get_debug_navigation_geometry_face_color()); #endif // DEBUG_ENABLED } break; } @@ -2909,7 +2915,7 @@ void TileDataNavigationEditor::draw_over_tile(CanvasItem *p_canvas_item, Transfo Color color = Color(0.5, 1.0, 1.0, 1.0); #ifdef DEBUG_ENABLED - color = NavigationServer3D::get_singleton()->get_debug_navigation_geometry_face_color(); + color = NavigationServer2D::get_singleton()->get_debug_navigation_geometry_face_color(); #endif // DEBUG_ENABLED if (p_selected) { Color grid_color = EDITOR_GET("editors/tiles_editor/grid_color"); diff --git a/editor/plugins/tiles/tile_set_atlas_source_editor.cpp b/editor/plugins/tiles/tile_set_atlas_source_editor.cpp index ee32083628f..4e7db8cb070 100644 --- a/editor/plugins/tiles/tile_set_atlas_source_editor.cpp +++ b/editor/plugins/tiles/tile_set_atlas_source_editor.cpp @@ -54,6 +54,8 @@ #include "core/math/geometry_2d.h" #include "core/os/keyboard.h" +#include "servers/navigation_server_2d.h" + void TileSetAtlasSourceEditor::TileSetAtlasSourceProxyObject::set_id(int p_id) { ERR_FAIL_COND(p_id < 0); if (source_id == p_id) { @@ -2745,11 +2747,20 @@ void EditorPropertyTilePolygon::_polygons_changed() { Ref navigation_polygon; if (generic_tile_polygon_editor->get_polygon_count() >= 1) { navigation_polygon.instantiate(); - for (int i = 0; i < generic_tile_polygon_editor->get_polygon_count(); i++) { - Vector polygon = generic_tile_polygon_editor->get_polygon(i); - navigation_polygon->add_outline(polygon); + + if (generic_tile_polygon_editor->get_polygon_count() > 0) { + Ref source_geometry_data; + source_geometry_data.instantiate(); + for (int i = 0; i < generic_tile_polygon_editor->get_polygon_count(); i++) { + Vector polygon = generic_tile_polygon_editor->get_polygon(i); + navigation_polygon->add_outline(polygon); + source_geometry_data->add_traversable_outline(polygon); + } + navigation_polygon->set_agent_radius(0.0); + NavigationServer2D::get_singleton()->bake_from_source_geometry_data(navigation_polygon, source_geometry_data); + } else { + navigation_polygon->clear(); } - navigation_polygon->make_polygons_from_outlines(); } emit_changed(get_edited_property(), navigation_polygon); }