Update TileMap to use new navigation polygon baking

Updates TileMap to use new navigation polygon baking.
This commit is contained in:
smix8 2023-09-28 02:36:15 +02:00
parent 4c3dc26367
commit 27267b62cb
2 changed files with 30 additions and 13 deletions

View File

@ -49,9 +49,7 @@
#include "scene/gui/separator.h" #include "scene/gui/separator.h"
#include "scene/gui/spin_box.h" #include "scene/gui/spin_box.h"
#ifdef DEBUG_ENABLED #include "servers/navigation_server_2d.h"
#include "servers/navigation_server_3d.h"
#endif // DEBUG_ENABLED
void TileDataEditor::_tile_set_changed_plan_update() { void TileDataEditor::_tile_set_changed_plan_update() {
_tile_set_changed_update_needed = true; _tile_set_changed_update_needed = true;
@ -2826,12 +2824,20 @@ Variant TileDataNavigationEditor::_get_painted_value() {
Ref<NavigationPolygon> nav_polygon; Ref<NavigationPolygon> nav_polygon;
nav_polygon.instantiate(); nav_polygon.instantiate();
for (int i = 0; i < polygon_editor->get_polygon_count(); i++) { if (polygon_editor->get_polygon_count() > 0) {
Vector<Vector2> polygon = polygon_editor->get_polygon(i); Ref<NavigationMeshSourceGeometryData2D> source_geometry_data;
nav_polygon->add_outline(polygon); source_geometry_data.instantiate();
for (int i = 0; i < polygon_editor->get_polygon_count(); i++) {
Vector<Vector2> 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; return nav_polygon;
} }
@ -2881,7 +2887,7 @@ void TileDataNavigationEditor::_notification(int p_what) {
switch (p_what) { switch (p_what) {
case NOTIFICATION_ENTER_TREE: { case NOTIFICATION_ENTER_TREE: {
#ifdef DEBUG_ENABLED #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 #endif // DEBUG_ENABLED
} break; } 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); Color color = Color(0.5, 1.0, 1.0, 1.0);
#ifdef DEBUG_ENABLED #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 #endif // DEBUG_ENABLED
if (p_selected) { if (p_selected) {
Color grid_color = EDITOR_GET("editors/tiles_editor/grid_color"); Color grid_color = EDITOR_GET("editors/tiles_editor/grid_color");

View File

@ -54,6 +54,8 @@
#include "core/math/geometry_2d.h" #include "core/math/geometry_2d.h"
#include "core/os/keyboard.h" #include "core/os/keyboard.h"
#include "servers/navigation_server_2d.h"
void TileSetAtlasSourceEditor::TileSetAtlasSourceProxyObject::set_id(int p_id) { void TileSetAtlasSourceEditor::TileSetAtlasSourceProxyObject::set_id(int p_id) {
ERR_FAIL_COND(p_id < 0); ERR_FAIL_COND(p_id < 0);
if (source_id == p_id) { if (source_id == p_id) {
@ -2745,11 +2747,20 @@ void EditorPropertyTilePolygon::_polygons_changed() {
Ref<NavigationPolygon> navigation_polygon; Ref<NavigationPolygon> navigation_polygon;
if (generic_tile_polygon_editor->get_polygon_count() >= 1) { if (generic_tile_polygon_editor->get_polygon_count() >= 1) {
navigation_polygon.instantiate(); navigation_polygon.instantiate();
for (int i = 0; i < generic_tile_polygon_editor->get_polygon_count(); i++) {
Vector<Vector2> polygon = generic_tile_polygon_editor->get_polygon(i); if (generic_tile_polygon_editor->get_polygon_count() > 0) {
navigation_polygon->add_outline(polygon); Ref<NavigationMeshSourceGeometryData2D> source_geometry_data;
source_geometry_data.instantiate();
for (int i = 0; i < generic_tile_polygon_editor->get_polygon_count(); i++) {
Vector<Vector2> 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); emit_changed(get_edited_property(), navigation_polygon);
} }