Add NavigationLink debug direction indicator

Adds direction indicator arrows to the NavigationLink debug depending on if a link is onewyay or bidirectional.
This commit is contained in:
smix8 2025-01-02 01:04:03 +01:00
parent 2582793d40
commit 8dd0579bcd
3 changed files with 89 additions and 0 deletions

View file

@ -125,6 +125,34 @@ void NavigationLink3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
}
}
const Vector3 link_segment = end_position - start_position;
const Vector3 up = Vector3(0.0, 1.0, 0.0);
const float arror_len = 0.5;
{
Vector3 anchor = start_position + (link_segment * 0.75);
Vector3 direction = start_position.direction_to(end_position);
Vector3 arrow_dir = direction.cross(up);
lines.push_back(anchor);
lines.push_back(anchor + (arrow_dir - direction) * arror_len);
arrow_dir = -direction.cross(up);
lines.push_back(anchor);
lines.push_back(anchor + (arrow_dir - direction) * arror_len);
}
if (link->is_bidirectional()) {
Vector3 anchor = start_position + (link_segment * 0.25);
Vector3 direction = end_position.direction_to(start_position);
Vector3 arrow_dir = direction.cross(up);
lines.push_back(anchor);
lines.push_back(anchor + (arrow_dir - direction) * arror_len);
arrow_dir = -direction.cross(up);
lines.push_back(anchor);
lines.push_back(anchor + (arrow_dir - direction) * arror_len);
}
p_gizmo->add_lines(lines, link->is_enabled() ? link_material : link_material_disabled);
p_gizmo->add_collision_segments(lines);

View file

@ -198,6 +198,10 @@ void NavigationLink2D::set_bidirectional(bool p_bidirectional) {
bidirectional = p_bidirectional;
NavigationServer2D::get_singleton()->link_set_bidirectional(link, bidirectional);
#ifdef DEBUG_ENABLED
queue_redraw();
#endif // DEBUG_ENABLED
}
void NavigationLink2D::set_navigation_layers(uint32_t p_navigation_layers) {
@ -396,6 +400,29 @@ void NavigationLink2D::_update_debug_mesh() {
draw_line(get_start_position(), get_end_position(), color);
draw_arc(get_start_position(), radius, 0, Math_TAU, 10, color);
draw_arc(get_end_position(), radius, 0, Math_TAU, 10, color);
const Vector2 link_segment = end_position - start_position;
const float arror_len = 5.0;
{
Vector2 anchor = start_position + (link_segment * 0.75);
Vector2 direction = start_position.direction_to(end_position);
Vector2 arrow_dir = -direction.orthogonal();
draw_line(anchor, anchor + (arrow_dir - direction) * arror_len, color);
arrow_dir = direction.orthogonal();
draw_line(anchor, anchor + (arrow_dir - direction) * arror_len, color);
}
if (is_bidirectional()) {
Vector2 anchor = start_position + (link_segment * 0.25);
Vector2 direction = end_position.direction_to(start_position);
Vector2 arrow_dir = -direction.orthogonal();
draw_line(anchor, anchor + (arrow_dir - direction) * arror_len, color);
arrow_dir = direction.orthogonal();
draw_line(anchor, anchor + (arrow_dir - direction) * arror_len, color);
}
}
#endif // DEBUG_ENABLED

View file

@ -122,6 +122,34 @@ void NavigationLink3D::_update_debug_mesh() {
}
}
const Vector3 link_segment = end_position - start_position;
const Vector3 up = Vector3(0.0, 1.0, 0.0);
const float arror_len = 0.5;
{
Vector3 anchor = start_position + (link_segment * 0.75);
Vector3 direction = start_position.direction_to(end_position);
Vector3 arrow_dir = direction.cross(up);
lines.push_back(anchor);
lines.push_back(anchor + (arrow_dir - direction) * arror_len);
arrow_dir = -direction.cross(up);
lines.push_back(anchor);
lines.push_back(anchor + (arrow_dir - direction) * arror_len);
}
if (is_bidirectional()) {
Vector3 anchor = start_position + (link_segment * 0.25);
Vector3 direction = end_position.direction_to(start_position);
Vector3 arrow_dir = direction.cross(up);
lines.push_back(anchor);
lines.push_back(anchor + (arrow_dir - direction) * arror_len);
arrow_dir = -direction.cross(up);
lines.push_back(anchor);
lines.push_back(anchor + (arrow_dir - direction) * arror_len);
}
Array mesh_array;
mesh_array.resize(Mesh::ARRAY_MAX);
mesh_array[Mesh::ARRAY_VERTEX] = lines;
@ -321,6 +349,12 @@ void NavigationLink3D::set_bidirectional(bool p_bidirectional) {
bidirectional = p_bidirectional;
NavigationServer3D::get_singleton()->link_set_bidirectional(link, bidirectional);
#ifdef DEBUG_ENABLED
_update_debug_mesh();
#endif // DEBUG_ENABLED
update_gizmos();
}
void NavigationLink3D::set_navigation_layers(uint32_t p_navigation_layers) {