summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
authorsmix8 <52464204+smix8@users.noreply.github.com>2023-02-13 04:35:42 +0100
committersmix8 <52464204+smix8@users.noreply.github.com>2023-02-13 11:42:23 +0100
commit2b19c70664dafd3e5689fc612feb7f7ac17c1a0a (patch)
treefe63fb6874956e189f7235ff1fadbc3699d30d32 /scene
parent27b2260460ab478707d884a16429add5bb3375f1 (diff)
Fix 2D navigation debug visuals ignoring half the ProjectSettings
Fixes that NavigationRegion2D and TileMap debug visuals ignored more or less half the ProjectSetting. E.g. random color could not be disabled, edges did not display.
Diffstat (limited to 'scene')
-rw-r--r--scene/2d/navigation_region_2d.cpp90
-rw-r--r--scene/2d/tile_map.cpp56
2 files changed, 93 insertions, 53 deletions
diff --git a/scene/2d/navigation_region_2d.cpp b/scene/2d/navigation_region_2d.cpp
index 3484a9de65..5dbba313bc 100644
--- a/scene/2d/navigation_region_2d.cpp
+++ b/scene/2d/navigation_region_2d.cpp
@@ -167,58 +167,78 @@ void NavigationRegion2D::_notification(int p_what) {
case NOTIFICATION_DRAW: {
#ifdef DEBUG_ENABLED
- if (is_inside_tree() && (Engine::get_singleton()->is_editor_hint() || NavigationServer3D::get_singleton()->get_debug_enabled()) && navigation_polygon.is_valid()) {
- Vector<Vector2> verts = navigation_polygon->get_vertices();
- if (verts.size() < 3) {
+ if (is_inside_tree() && (Engine::get_singleton()->is_editor_hint() || NavigationServer2D::get_singleton()->get_debug_enabled()) && navigation_polygon.is_valid()) {
+ Vector<Vector2> navigation_polygon_vertices = navigation_polygon->get_vertices();
+ if (navigation_polygon_vertices.size() < 3) {
return;
}
- Color color;
- if (enabled) {
- color = NavigationServer3D::get_singleton()->get_debug_navigation_geometry_face_color();
- } else {
- color = NavigationServer3D::get_singleton()->get_debug_navigation_geometry_face_disabled_color();
+ const NavigationServer2D *ns2d = NavigationServer2D::get_singleton();
+
+ bool enabled_geometry_face_random_color = ns2d->get_debug_navigation_enable_geometry_face_random_color();
+ bool enabled_edge_lines = ns2d->get_debug_navigation_enable_edge_lines();
+ bool enable_edge_connections = ns2d->get_debug_navigation_enable_edge_connections();
+
+ Color debug_face_color = ns2d->get_debug_navigation_geometry_face_color();
+ Color debug_edge_color = ns2d->get_debug_navigation_geometry_edge_color();
+ Color debug_edge_connection_color = ns2d->get_debug_navigation_edge_connection_color();
+
+ if (!enabled) {
+ debug_face_color = ns2d->get_debug_navigation_geometry_face_disabled_color();
+ debug_edge_color = ns2d->get_debug_navigation_geometry_edge_disabled_color();
}
- Color doors_color = NavigationServer3D::get_singleton()->get_debug_navigation_edge_connection_color();
RandomPCG rand;
for (int i = 0; i < navigation_polygon->get_polygon_count(); i++) {
// An array of vertices for this polygon.
Vector<int> polygon = navigation_polygon->get_polygon(i);
- Vector<Vector2> vertices;
- vertices.resize(polygon.size());
+ Vector<Vector2> debug_polygon_vertices;
+ debug_polygon_vertices.resize(polygon.size());
for (int j = 0; j < polygon.size(); j++) {
- ERR_FAIL_INDEX(polygon[j], verts.size());
- vertices.write[j] = verts[polygon[j]];
+ ERR_FAIL_INDEX(polygon[j], navigation_polygon_vertices.size());
+ debug_polygon_vertices.write[j] = navigation_polygon_vertices[polygon[j]];
}
// Generate the polygon color, slightly randomly modified from the settings one.
- Color random_variation_color;
- random_variation_color.set_hsv(color.get_h() + rand.random(-1.0, 1.0) * 0.1, color.get_s(), color.get_v() + rand.random(-1.0, 1.0) * 0.2);
- random_variation_color.a = color.a;
- Vector<Color> colors;
- colors.push_back(random_variation_color);
+ Color random_variation_color = debug_face_color;
+ if (enabled_geometry_face_random_color) {
+ random_variation_color.set_hsv(
+ debug_face_color.get_h() + rand.random(-1.0, 1.0) * 0.1,
+ debug_face_color.get_s(),
+ debug_face_color.get_v() + rand.random(-1.0, 1.0) * 0.2);
+ }
+ random_variation_color.a = debug_face_color.a;
- RS::get_singleton()->canvas_item_add_polygon(get_canvas_item(), vertices, colors);
+ Vector<Color> debug_face_colors;
+ debug_face_colors.push_back(random_variation_color);
+ RS::get_singleton()->canvas_item_add_polygon(get_canvas_item(), debug_polygon_vertices, debug_face_colors);
+
+ if (enabled_edge_lines) {
+ Vector<Color> debug_edge_colors;
+ debug_edge_colors.push_back(debug_edge_color);
+ debug_polygon_vertices.push_back(debug_polygon_vertices[0]); // Add first again for closing polyline.
+ RS::get_singleton()->canvas_item_add_polyline(get_canvas_item(), debug_polygon_vertices, debug_edge_colors);
+ }
}
- // Draw the region
- Transform2D xform = get_global_transform();
- const NavigationServer2D *ns = NavigationServer2D::get_singleton();
- real_t radius = ns->map_get_edge_connection_margin(get_world_2d()->get_navigation_map()) / 2.0;
- for (int i = 0; i < ns->region_get_connections_count(region); i++) {
- // Two main points
- Vector2 a = ns->region_get_connection_pathway_start(region, i);
- a = xform.affine_inverse().xform(a);
- Vector2 b = ns->region_get_connection_pathway_end(region, i);
- b = xform.affine_inverse().xform(b);
- draw_line(a, b, doors_color);
-
- // Draw a circle to illustrate the margins.
- real_t angle = a.angle_to_point(b);
- draw_arc(a, radius, angle + Math_PI / 2.0, angle - Math_PI / 2.0 + Math_TAU, 10, doors_color);
- draw_arc(b, radius, angle - Math_PI / 2.0, angle + Math_PI / 2.0, 10, doors_color);
+ if (enable_edge_connections) {
+ // Draw the region edge connections.
+ Transform2D xform = get_global_transform();
+ real_t radius = ns2d->map_get_edge_connection_margin(get_world_2d()->get_navigation_map()) / 2.0;
+ for (int i = 0; i < ns2d->region_get_connections_count(region); i++) {
+ // Two main points
+ Vector2 a = ns2d->region_get_connection_pathway_start(region, i);
+ a = xform.affine_inverse().xform(a);
+ Vector2 b = ns2d->region_get_connection_pathway_end(region, i);
+ b = xform.affine_inverse().xform(b);
+ draw_line(a, b, debug_edge_connection_color);
+
+ // Draw a circle to illustrate the margins.
+ real_t angle = a.angle_to_point(b);
+ draw_arc(a, radius, angle + Math_PI / 2.0, angle - Math_PI / 2.0 + Math_TAU, 10, debug_edge_connection_color);
+ draw_arc(b, radius, angle - Math_PI / 2.0, angle + Math_PI / 2.0, 10, debug_edge_connection_color);
+ }
}
}
#endif // DEBUG_ENABLED
diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp
index 95bf67d38d..a4bcac2e3b 100644
--- a/scene/2d/tile_map.cpp
+++ b/scene/2d/tile_map.cpp
@@ -1795,12 +1795,16 @@ void TileMap::_navigation_draw_quadrant_debug(TileMapQuadrant *p_quadrant) {
return;
}
+#ifdef DEBUG_ENABLED
RenderingServer *rs = RenderingServer::get_singleton();
+ const NavigationServer2D *ns2d = NavigationServer2D::get_singleton();
+
+ bool enabled_geometry_face_random_color = ns2d->get_debug_navigation_enable_geometry_face_random_color();
+ bool enabled_edge_lines = ns2d->get_debug_navigation_enable_edge_lines();
+
+ Color debug_face_color = ns2d->get_debug_navigation_geometry_face_color();
+ Color debug_edge_color = ns2d->get_debug_navigation_geometry_edge_color();
- Color color = Color(0.5, 1.0, 1.0, 1.0);
-#ifdef DEBUG_ENABLED
- color = NavigationServer3D::get_singleton()->get_debug_navigation_geometry_face_color();
-#endif // DEBUG_ENABLED
RandomPCG rand;
Vector2 quadrant_pos = map_to_local(p_quadrant->coords * get_effective_quadrant_size(p_quadrant->layer));
@@ -1830,34 +1834,50 @@ void TileMap::_navigation_draw_quadrant_debug(TileMapQuadrant *p_quadrant) {
rs->canvas_item_add_set_transform(p_quadrant->debug_canvas_item, cell_to_quadrant);
for (int layer_index = 0; layer_index < tile_set->get_navigation_layers_count(); layer_index++) {
- Ref<NavigationPolygon> navpoly = tile_data->get_navigation_polygon(layer_index);
- if (navpoly.is_valid()) {
- PackedVector2Array navigation_polygon_vertices = navpoly->get_vertices();
+ Ref<NavigationPolygon> navigation_polygon = tile_data->get_navigation_polygon(layer_index);
+ if (navigation_polygon.is_valid()) {
+ Vector<Vector2> navigation_polygon_vertices = navigation_polygon->get_vertices();
+ if (navigation_polygon_vertices.size() < 3) {
+ continue;
+ }
- for (int i = 0; i < navpoly->get_polygon_count(); i++) {
+ for (int i = 0; i < navigation_polygon->get_polygon_count(); i++) {
// An array of vertices for this polygon.
- Vector<int> polygon = navpoly->get_polygon(i);
- Vector<Vector2> vertices;
- vertices.resize(polygon.size());
+ Vector<int> polygon = navigation_polygon->get_polygon(i);
+ Vector<Vector2> debug_polygon_vertices;
+ debug_polygon_vertices.resize(polygon.size());
for (int j = 0; j < polygon.size(); j++) {
ERR_FAIL_INDEX(polygon[j], navigation_polygon_vertices.size());
- vertices.write[j] = navigation_polygon_vertices[polygon[j]];
+ debug_polygon_vertices.write[j] = navigation_polygon_vertices[polygon[j]];
}
// Generate the polygon color, slightly randomly modified from the settings one.
- Color random_variation_color;
- random_variation_color.set_hsv(color.get_h() + rand.random(-1.0, 1.0) * 0.05, color.get_s(), color.get_v() + rand.random(-1.0, 1.0) * 0.1);
- random_variation_color.a = color.a;
- Vector<Color> colors;
- colors.push_back(random_variation_color);
+ Color random_variation_color = debug_face_color;
+ if (enabled_geometry_face_random_color) {
+ random_variation_color.set_hsv(
+ debug_face_color.get_h() + rand.random(-1.0, 1.0) * 0.1,
+ debug_face_color.get_s(),
+ debug_face_color.get_v() + rand.random(-1.0, 1.0) * 0.2);
+ }
+ random_variation_color.a = debug_face_color.a;
+
+ Vector<Color> debug_face_colors;
+ debug_face_colors.push_back(random_variation_color);
+ rs->canvas_item_add_polygon(p_quadrant->debug_canvas_item, debug_polygon_vertices, debug_face_colors);
- rs->canvas_item_add_polygon(p_quadrant->debug_canvas_item, vertices, colors);
+ if (enabled_edge_lines) {
+ Vector<Color> debug_edge_colors;
+ debug_edge_colors.push_back(debug_edge_color);
+ debug_polygon_vertices.push_back(debug_polygon_vertices[0]); // Add first again for closing polyline.
+ rs->canvas_item_add_polyline(p_quadrant->debug_canvas_item, debug_polygon_vertices, debug_edge_colors);
+ }
}
}
}
}
}
}
+#endif // DEBUG_ENABLED
}
/////////////////////////////// Scenes //////////////////////////////////////