diff --git a/editor/spatial_editor_gizmos.cpp b/editor/spatial_editor_gizmos.cpp index 831b99a4e..b9a841a2f 100644 --- a/editor/spatial_editor_gizmos.cpp +++ b/editor/spatial_editor_gizmos.cpp @@ -3542,6 +3542,11 @@ void CollisionPolygonSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) { //// NavigationMeshSpatialGizmoPlugin::NavigationMeshSpatialGizmoPlugin() { + create_material("face_material", NavigationServer::get_singleton()->get_debug_navigation_geometry_face_color(), false, false, true); + create_material("face_material_disabled", NavigationServer::get_singleton()->get_debug_navigation_geometry_face_disabled_color(), false, false, true); + create_material("edge_material", NavigationServer::get_singleton()->get_debug_navigation_geometry_edge_color()); + create_material("edge_material_disabled", NavigationServer::get_singleton()->get_debug_navigation_geometry_edge_disabled_color()); + Color baking_aabb_material_color = Color(0.8, 0.5, 0.7); baking_aabb_material_color.a = 0.1; create_material("baking_aabb_material", baking_aabb_material_color); @@ -3641,6 +3646,7 @@ void NavigationMeshSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) { tmesh->create(tmeshfaces); p_gizmo->add_collision_triangles(tmesh); + p_gizmo->add_collision_segments(lines); Ref debug_mesh = Ref(memnew(ArrayMesh)); int polygon_count = navigationmesh->get_polygon_count(); @@ -3662,6 +3668,7 @@ void NavigationMeshSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) { face_mesh_array[Mesh::ARRAY_VERTEX] = face_vertex_array; // if enabled add vertex colors to colorize each face individually + RandomPCG rand; bool enabled_geometry_face_random_color = NavigationServer::get_singleton()->get_debug_navigation_enable_geometry_face_random_color(); if (enabled_geometry_face_random_color) { Color debug_navigation_geometry_face_color = NavigationServer::get_singleton()->get_debug_navigation_geometry_face_color(); @@ -3671,7 +3678,9 @@ void NavigationMeshSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) { face_color_array.resize(polygon_count * 3); for (int i = 0; i < polygon_count; i++) { - polygon_color = debug_navigation_geometry_face_color * (Color(Math::randf(), Math::randf(), Math::randf())); + // Generate the polygon color, slightly randomly modified from the settings one. + polygon_color.set_hsv(debug_navigation_geometry_face_color.get_h() + rand.random(-1.0, 1.0) * 0.1, debug_navigation_geometry_face_color.get_s(), debug_navigation_geometry_face_color.get_v() + rand.random(-1.0, 1.0) * 0.2); + polygon_color.a = debug_navigation_geometry_face_color.a; Vector polygon = navigationmesh->get_polygon(i); @@ -3683,8 +3692,7 @@ void NavigationMeshSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) { } debug_mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, face_mesh_array); - Ref debug_geometry_face_material = NavigationServer::get_singleton_mut()->get_debug_navigation_geometry_face_material(); - debug_mesh->surface_set_material(0, debug_geometry_face_material); + p_gizmo->add_mesh(debug_mesh, navmesh_instance->is_enabled() ? get_material("face_material", p_gizmo) : get_material("face_material_disabled", p_gizmo)); // if enabled build geometry edge line surface bool enabled_edge_lines = NavigationServer::get_singleton()->get_debug_navigation_enable_edge_lines(); @@ -3704,27 +3712,8 @@ void NavigationMeshSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) { line_vertex_array.push_back(vertices[polygon[0]]); } - Array line_mesh_array; - line_mesh_array.resize(Mesh::ARRAY_MAX); - line_mesh_array[Mesh::ARRAY_VERTEX] = line_vertex_array; - debug_mesh->add_surface_from_arrays(Mesh::PRIMITIVE_LINES, line_mesh_array); - Ref debug_geometry_edge_material = NavigationServer::get_singleton_mut()->get_debug_navigation_geometry_edge_material(); - debug_mesh->surface_set_material(1, debug_geometry_edge_material); + p_gizmo->add_lines(line_vertex_array, navmesh_instance->is_enabled() ? get_material("edge_material", p_gizmo) : get_material("edge_material_disabled", p_gizmo)); } - - if (!navmesh_instance->is_enabled()) { - if (debug_mesh.is_valid()) { - if (debug_mesh->get_surface_count() > 0) { - debug_mesh->surface_set_material(0, NavigationServer::get_singleton_mut()->get_debug_navigation_geometry_face_disabled_material()); - } - if (debug_mesh->get_surface_count() > 1) { - debug_mesh->surface_set_material(1, NavigationServer::get_singleton_mut()->get_debug_navigation_geometry_edge_disabled_material()); - } - } - } - - p_gizmo->add_mesh(debug_mesh); - p_gizmo->add_collision_segments(lines); } ////// diff --git a/scene/2d/navigation_polygon_instance.cpp b/scene/2d/navigation_polygon_instance.cpp index fe1727762..de0d86ce3 100644 --- a/scene/2d/navigation_polygon_instance.cpp +++ b/scene/2d/navigation_polygon_instance.cpp @@ -188,7 +188,7 @@ void NavigationPolygonInstance::_notification(int p_what) { } // 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.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 colors; colors.push_back(random_variation_color); diff --git a/scene/3d/navigation_mesh_instance.cpp b/scene/3d/navigation_mesh_instance.cpp index d3edeb812..144a26907 100644 --- a/scene/3d/navigation_mesh_instance.cpp +++ b/scene/3d/navigation_mesh_instance.cpp @@ -448,11 +448,14 @@ void NavigationMeshInstance::_update_debug_mesh() { Ref face_material = NavigationServer::get_singleton_mut()->get_debug_navigation_geometry_face_material(); Ref line_material = NavigationServer::get_singleton_mut()->get_debug_navigation_geometry_edge_material(); + RandomPCG rand; Color polygon_color = debug_navigation_geometry_face_color; for (int i = 0; i < polygon_count; i++) { if (enabled_geometry_face_random_color) { - polygon_color = debug_navigation_geometry_face_color * (Color(Math::randf(), Math::randf(), Math::randf())); + // Generate the polygon color, slightly randomly modified from the settings one. + polygon_color.set_hsv(debug_navigation_geometry_face_color.get_h() + rand.random(-1.0, 1.0) * 0.1, debug_navigation_geometry_face_color.get_s(), debug_navigation_geometry_face_color.get_v() + rand.random(-1.0, 1.0) * 0.2); + polygon_color.a = debug_navigation_geometry_face_color.a; } Vector polygon = navmesh->get_polygon(i);