2020-01-10 12:22:34 +01:00
|
|
|
/**************************************************************************/
|
2020-02-11 14:01:43 +01:00
|
|
|
/* navigation_obstacle_2d.cpp */
|
2020-01-10 12:22:34 +01:00
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
2020-02-11 14:01:43 +01:00
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
2020-01-10 12:22:34 +01:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/**************************************************************************/
|
|
|
|
|
|
|
|
#include "navigation_obstacle_2d.h"
|
|
|
|
|
2023-01-10 07:14:16 +01:00
|
|
|
#include "core/math/geometry_2d.h"
|
2022-02-12 02:46:22 +01:00
|
|
|
#include "scene/resources/world_2d.h"
|
2020-03-27 19:21:27 +01:00
|
|
|
#include "servers/navigation_server_2d.h"
|
2023-01-10 07:14:16 +01:00
|
|
|
#include "servers/navigation_server_3d.h"
|
2020-01-10 12:22:34 +01:00
|
|
|
|
|
|
|
void NavigationObstacle2D::_bind_methods() {
|
2023-06-10 15:16:04 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_rid"), &NavigationObstacle2D::get_rid);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_avoidance_enabled", "enabled"), &NavigationObstacle2D::set_avoidance_enabled);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_avoidance_enabled"), &NavigationObstacle2D::get_avoidance_enabled);
|
2022-05-14 23:33:09 +02:00
|
|
|
|
2022-08-14 16:23:27 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("set_navigation_map", "navigation_map"), &NavigationObstacle2D::set_navigation_map);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_navigation_map"), &NavigationObstacle2D::get_navigation_map);
|
|
|
|
|
2021-10-21 22:25:06 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("set_radius", "radius"), &NavigationObstacle2D::set_radius);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_radius"), &NavigationObstacle2D::get_radius);
|
|
|
|
|
2023-01-10 07:14:16 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_velocity", "velocity"), &NavigationObstacle2D::set_velocity);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_velocity"), &NavigationObstacle2D::get_velocity);
|
2021-10-21 22:25:06 +02:00
|
|
|
|
2023-01-10 07:14:16 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_vertices", "vertices"), &NavigationObstacle2D::set_vertices);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_vertices"), &NavigationObstacle2D::get_vertices);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_avoidance_layers", "layers"), &NavigationObstacle2D::set_avoidance_layers);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_avoidance_layers"), &NavigationObstacle2D::get_avoidance_layers);
|
2024-03-01 00:30:09 +01:00
|
|
|
|
2023-01-10 07:14:16 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_avoidance_layer_value", "layer_number", "value"), &NavigationObstacle2D::set_avoidance_layer_value);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_avoidance_layer_value", "layer_number"), &NavigationObstacle2D::get_avoidance_layer_value);
|
|
|
|
|
2024-03-01 00:30:09 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_affect_navigation_mesh", "enabled"), &NavigationObstacle2D::set_affect_navigation_mesh);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_affect_navigation_mesh"), &NavigationObstacle2D::get_affect_navigation_mesh);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_carve_navigation_mesh", "enabled"), &NavigationObstacle2D::set_carve_navigation_mesh);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_carve_navigation_mesh"), &NavigationObstacle2D::get_carve_navigation_mesh);
|
|
|
|
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "radius", PROPERTY_HINT_RANGE, "0.0,500,0.01,suffix:px"), "set_radius", "get_radius");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::PACKED_VECTOR2_ARRAY, "vertices"), "set_vertices", "get_vertices");
|
|
|
|
ADD_GROUP("NavigationMesh", "");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "affect_navigation_mesh"), "set_affect_navigation_mesh", "get_affect_navigation_mesh");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "carve_navigation_mesh"), "set_carve_navigation_mesh", "get_carve_navigation_mesh");
|
2023-06-10 15:16:04 +02:00
|
|
|
ADD_GROUP("Avoidance", "");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "avoidance_enabled"), "set_avoidance_enabled", "get_avoidance_enabled");
|
2023-01-10 07:14:16 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "velocity", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_velocity", "get_velocity");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "avoidance_layers", PROPERTY_HINT_LAYERS_AVOIDANCE), "set_avoidance_layers", "get_avoidance_layers");
|
2020-01-10 12:22:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void NavigationObstacle2D::_notification(int p_what) {
|
|
|
|
switch (p_what) {
|
2022-08-14 16:23:27 +02:00
|
|
|
case NOTIFICATION_POST_ENTER_TREE: {
|
2023-01-10 07:14:16 +01:00
|
|
|
if (map_override.is_valid()) {
|
|
|
|
_update_map(map_override);
|
|
|
|
} else if (is_inside_tree()) {
|
|
|
|
_update_map(get_world_2d()->get_navigation_map());
|
|
|
|
} else {
|
|
|
|
_update_map(RID());
|
|
|
|
}
|
|
|
|
previous_transform = get_global_transform();
|
|
|
|
// need to trigger map controlled agent assignment somehow for the fake_agent since obstacles use no callback like regular agents
|
2023-06-10 15:16:04 +02:00
|
|
|
NavigationServer2D::get_singleton()->obstacle_set_avoidance_enabled(obstacle, avoidance_enabled);
|
2023-07-12 22:21:58 +02:00
|
|
|
_update_position(get_global_position());
|
2020-01-10 12:22:34 +01:00
|
|
|
set_physics_process_internal(true);
|
2024-02-27 06:51:50 +01:00
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
RS::get_singleton()->canvas_item_set_parent(debug_canvas_item, get_world_2d()->get_canvas());
|
|
|
|
#endif // DEBUG_ENABLED
|
2020-01-10 12:22:34 +01:00
|
|
|
} break;
|
2022-02-15 18:06:48 +01:00
|
|
|
|
2020-01-10 12:22:34 +01:00
|
|
|
case NOTIFICATION_EXIT_TREE: {
|
2022-08-14 16:23:27 +02:00
|
|
|
set_physics_process_internal(false);
|
2023-01-10 07:14:16 +01:00
|
|
|
_update_map(RID());
|
2024-02-27 06:51:50 +01:00
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
RS::get_singleton()->canvas_item_set_parent(debug_canvas_item, RID());
|
|
|
|
#endif // DEBUG_ENABLED
|
2021-03-08 09:47:18 +01:00
|
|
|
} break;
|
2022-02-15 18:06:48 +01:00
|
|
|
|
2022-05-17 20:08:39 +02:00
|
|
|
case NOTIFICATION_PAUSED: {
|
2023-01-10 07:14:16 +01:00
|
|
|
if (!can_process()) {
|
|
|
|
map_before_pause = map_current;
|
|
|
|
_update_map(RID());
|
|
|
|
} else if (can_process() && !(map_before_pause == RID())) {
|
|
|
|
_update_map(map_before_pause);
|
2022-05-17 20:08:39 +02:00
|
|
|
map_before_pause = RID();
|
|
|
|
}
|
2023-06-15 15:35:53 +02:00
|
|
|
NavigationServer2D::get_singleton()->obstacle_set_paused(obstacle, !can_process());
|
2022-05-17 20:08:39 +02:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case NOTIFICATION_UNPAUSED: {
|
2023-01-10 07:14:16 +01:00
|
|
|
if (!can_process()) {
|
|
|
|
map_before_pause = map_current;
|
|
|
|
_update_map(RID());
|
|
|
|
} else if (can_process() && !(map_before_pause == RID())) {
|
|
|
|
_update_map(map_before_pause);
|
2022-05-17 20:08:39 +02:00
|
|
|
map_before_pause = RID();
|
|
|
|
}
|
2023-06-15 15:35:53 +02:00
|
|
|
NavigationServer2D::get_singleton()->obstacle_set_paused(obstacle, !can_process());
|
2022-05-17 20:08:39 +02:00
|
|
|
} break;
|
|
|
|
|
2024-02-27 06:51:50 +01:00
|
|
|
case NOTIFICATION_VISIBILITY_CHANGED: {
|
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
RS::get_singleton()->canvas_item_set_visible(debug_canvas_item, is_visible_in_tree());
|
|
|
|
#endif // DEBUG_ENABLED
|
|
|
|
} break;
|
|
|
|
|
2020-01-10 12:22:34 +01:00
|
|
|
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
|
2023-01-10 07:14:16 +01:00
|
|
|
if (is_inside_tree()) {
|
2023-07-12 22:21:58 +02:00
|
|
|
_update_position(get_global_position());
|
2023-01-10 07:14:16 +01:00
|
|
|
|
|
|
|
if (velocity_submitted) {
|
|
|
|
velocity_submitted = false;
|
|
|
|
// only update if there is a noticeable change, else the rvo agent preferred velocity stays the same
|
|
|
|
if (!previous_velocity.is_equal_approx(velocity)) {
|
2023-06-10 15:16:04 +02:00
|
|
|
NavigationServer2D::get_singleton()->obstacle_set_velocity(obstacle, velocity);
|
2023-01-10 07:14:16 +01:00
|
|
|
}
|
|
|
|
previous_velocity = velocity;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case NOTIFICATION_DRAW: {
|
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
if (is_inside_tree()) {
|
|
|
|
bool is_debug_enabled = false;
|
|
|
|
if (Engine::get_singleton()->is_editor_hint()) {
|
|
|
|
is_debug_enabled = true;
|
|
|
|
} else if (NavigationServer2D::get_singleton()->get_debug_enabled() && NavigationServer2D::get_singleton()->get_debug_avoidance_enabled()) {
|
|
|
|
is_debug_enabled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_debug_enabled) {
|
2024-02-27 06:51:50 +01:00
|
|
|
RS::get_singleton()->canvas_item_clear(debug_canvas_item);
|
|
|
|
Transform2D debug_transform = Transform2D(0.0, get_global_position());
|
|
|
|
RS::get_singleton()->canvas_item_set_transform(debug_canvas_item, debug_transform);
|
2023-01-10 07:14:16 +01:00
|
|
|
_update_fake_agent_radius_debug();
|
|
|
|
_update_static_obstacle_debug();
|
|
|
|
}
|
2020-01-10 12:22:34 +01:00
|
|
|
}
|
2023-01-10 07:14:16 +01:00
|
|
|
#endif // DEBUG_ENABLED
|
2020-01-10 12:22:34 +01:00
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-12 17:01:17 +02:00
|
|
|
NavigationObstacle2D::NavigationObstacle2D() {
|
2023-01-10 07:14:16 +01:00
|
|
|
obstacle = NavigationServer2D::get_singleton()->obstacle_create();
|
|
|
|
|
2023-10-23 05:10:58 +02:00
|
|
|
NavigationServer2D::get_singleton()->obstacle_set_radius(obstacle, radius);
|
|
|
|
NavigationServer2D::get_singleton()->obstacle_set_vertices(obstacle, vertices);
|
|
|
|
NavigationServer2D::get_singleton()->obstacle_set_avoidance_layers(obstacle, avoidance_layers);
|
|
|
|
NavigationServer2D::get_singleton()->obstacle_set_avoidance_enabled(obstacle, avoidance_enabled);
|
2024-02-27 06:51:50 +01:00
|
|
|
|
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
debug_canvas_item = RenderingServer::get_singleton()->canvas_item_create();
|
|
|
|
#endif // DEBUG_ENABLED
|
2020-01-10 12:22:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
NavigationObstacle2D::~NavigationObstacle2D() {
|
2022-12-12 18:42:37 +01:00
|
|
|
ERR_FAIL_NULL(NavigationServer2D::get_singleton());
|
2020-01-10 12:22:34 +01:00
|
|
|
|
2023-01-10 07:14:16 +01:00
|
|
|
NavigationServer2D::get_singleton()->free(obstacle);
|
|
|
|
obstacle = RID();
|
2024-02-27 06:51:50 +01:00
|
|
|
|
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
if (debug_canvas_item.is_valid()) {
|
|
|
|
RenderingServer::get_singleton()->free(debug_canvas_item);
|
|
|
|
debug_canvas_item = RID();
|
|
|
|
}
|
|
|
|
#endif // DEBUG_ENABLED
|
2020-01-10 12:22:34 +01:00
|
|
|
}
|
|
|
|
|
2023-01-10 07:14:16 +01:00
|
|
|
void NavigationObstacle2D::set_vertices(const Vector<Vector2> &p_vertices) {
|
|
|
|
vertices = p_vertices;
|
|
|
|
NavigationServer2D::get_singleton()->obstacle_set_vertices(obstacle, vertices);
|
2023-07-12 22:21:58 +02:00
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
queue_redraw();
|
|
|
|
#endif // DEBUG_ENABLED
|
2021-10-21 22:25:06 +02:00
|
|
|
}
|
|
|
|
|
2023-01-10 07:14:16 +01:00
|
|
|
void NavigationObstacle2D::set_navigation_map(RID p_navigation_map) {
|
|
|
|
if (map_override == p_navigation_map) {
|
|
|
|
return;
|
2021-10-21 22:25:06 +02:00
|
|
|
}
|
2023-01-10 07:14:16 +01:00
|
|
|
map_override = p_navigation_map;
|
|
|
|
_update_map(map_override);
|
2021-10-21 22:25:06 +02:00
|
|
|
}
|
|
|
|
|
2023-01-10 07:14:16 +01:00
|
|
|
RID NavigationObstacle2D::get_navigation_map() const {
|
|
|
|
if (map_override.is_valid()) {
|
|
|
|
return map_override;
|
|
|
|
} else if (is_inside_tree()) {
|
|
|
|
return get_world_2d()->get_navigation_map();
|
2021-03-08 09:47:18 +01:00
|
|
|
}
|
2023-01-10 07:14:16 +01:00
|
|
|
return RID();
|
2021-10-21 22:25:06 +02:00
|
|
|
}
|
|
|
|
|
2023-01-10 07:14:16 +01:00
|
|
|
void NavigationObstacle2D::set_radius(real_t p_radius) {
|
|
|
|
ERR_FAIL_COND_MSG(p_radius < 0.0, "Radius must be positive.");
|
|
|
|
if (Math::is_equal_approx(radius, p_radius)) {
|
2023-02-02 08:38:28 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-10 07:14:16 +01:00
|
|
|
radius = p_radius;
|
|
|
|
|
2023-06-10 15:16:04 +02:00
|
|
|
NavigationServer2D::get_singleton()->obstacle_set_radius(obstacle, radius);
|
2023-07-12 22:21:58 +02:00
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
queue_redraw();
|
|
|
|
#endif // DEBUG_ENABLED
|
2022-08-14 16:23:27 +02:00
|
|
|
}
|
|
|
|
|
2023-01-10 07:14:16 +01:00
|
|
|
void NavigationObstacle2D::set_avoidance_layers(uint32_t p_layers) {
|
2023-06-10 15:16:04 +02:00
|
|
|
if (avoidance_layers == p_layers) {
|
|
|
|
return;
|
|
|
|
}
|
2023-01-10 07:14:16 +01:00
|
|
|
avoidance_layers = p_layers;
|
|
|
|
NavigationServer2D::get_singleton()->obstacle_set_avoidance_layers(obstacle, avoidance_layers);
|
2023-04-06 16:32:49 +02:00
|
|
|
}
|
|
|
|
|
2023-01-10 07:14:16 +01:00
|
|
|
uint32_t NavigationObstacle2D::get_avoidance_layers() const {
|
|
|
|
return avoidance_layers;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NavigationObstacle2D::set_avoidance_layer_value(int p_layer_number, bool p_value) {
|
|
|
|
ERR_FAIL_COND_MSG(p_layer_number < 1, "Avoidance layer number must be between 1 and 32 inclusive.");
|
|
|
|
ERR_FAIL_COND_MSG(p_layer_number > 32, "Avoidance layer number must be between 1 and 32 inclusive.");
|
|
|
|
uint32_t avoidance_layers_new = get_avoidance_layers();
|
|
|
|
if (p_value) {
|
|
|
|
avoidance_layers_new |= 1 << (p_layer_number - 1);
|
|
|
|
} else {
|
|
|
|
avoidance_layers_new &= ~(1 << (p_layer_number - 1));
|
2023-02-02 08:38:28 +01:00
|
|
|
}
|
2023-01-10 07:14:16 +01:00
|
|
|
set_avoidance_layers(avoidance_layers_new);
|
|
|
|
}
|
2023-02-02 08:38:28 +01:00
|
|
|
|
2023-01-10 07:14:16 +01:00
|
|
|
bool NavigationObstacle2D::get_avoidance_layer_value(int p_layer_number) const {
|
|
|
|
ERR_FAIL_COND_V_MSG(p_layer_number < 1, false, "Avoidance layer number must be between 1 and 32 inclusive.");
|
|
|
|
ERR_FAIL_COND_V_MSG(p_layer_number > 32, false, "Avoidance layer number must be between 1 and 32 inclusive.");
|
|
|
|
return get_avoidance_layers() & (1 << (p_layer_number - 1));
|
|
|
|
}
|
2023-02-02 08:38:28 +01:00
|
|
|
|
2023-06-10 15:16:04 +02:00
|
|
|
void NavigationObstacle2D::set_avoidance_enabled(bool p_enabled) {
|
|
|
|
if (avoidance_enabled == p_enabled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
avoidance_enabled = p_enabled;
|
|
|
|
NavigationServer2D::get_singleton()->obstacle_set_avoidance_enabled(obstacle, avoidance_enabled);
|
2023-07-12 22:21:58 +02:00
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
queue_redraw();
|
|
|
|
#endif // DEBUG_ENABLED
|
2023-06-10 15:16:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool NavigationObstacle2D::get_avoidance_enabled() const {
|
|
|
|
return avoidance_enabled;
|
|
|
|
}
|
|
|
|
|
2023-01-10 07:14:16 +01:00
|
|
|
void NavigationObstacle2D::set_velocity(const Vector2 p_velocity) {
|
|
|
|
velocity = p_velocity;
|
|
|
|
velocity_submitted = true;
|
2022-08-14 16:23:27 +02:00
|
|
|
}
|
|
|
|
|
2024-03-01 00:30:09 +01:00
|
|
|
void NavigationObstacle2D::set_affect_navigation_mesh(bool p_enabled) {
|
|
|
|
affect_navigation_mesh = p_enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool NavigationObstacle2D::get_affect_navigation_mesh() const {
|
|
|
|
return affect_navigation_mesh;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NavigationObstacle2D::set_carve_navigation_mesh(bool p_enabled) {
|
|
|
|
carve_navigation_mesh = p_enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool NavigationObstacle2D::get_carve_navigation_mesh() const {
|
|
|
|
return carve_navigation_mesh;
|
|
|
|
}
|
|
|
|
|
2023-01-10 07:14:16 +01:00
|
|
|
void NavigationObstacle2D::_update_map(RID p_map) {
|
|
|
|
map_current = p_map;
|
2023-06-10 15:16:04 +02:00
|
|
|
NavigationServer2D::get_singleton()->obstacle_set_map(obstacle, p_map);
|
2023-01-10 07:14:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void NavigationObstacle2D::_update_position(const Vector2 p_position) {
|
2023-06-10 15:16:04 +02:00
|
|
|
NavigationServer2D::get_singleton()->obstacle_set_position(obstacle, p_position);
|
2023-07-12 22:21:58 +02:00
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
queue_redraw();
|
|
|
|
#endif // DEBUG_ENABLED
|
2022-08-14 16:23:27 +02:00
|
|
|
}
|
|
|
|
|
2023-01-10 07:14:16 +01:00
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
void NavigationObstacle2D::_update_fake_agent_radius_debug() {
|
|
|
|
if (radius > 0.0 && NavigationServer2D::get_singleton()->get_debug_navigation_avoidance_enable_obstacles_radius()) {
|
|
|
|
Color debug_radius_color = NavigationServer2D::get_singleton()->get_debug_navigation_avoidance_obstacles_radius_color();
|
2024-02-27 06:51:50 +01:00
|
|
|
|
|
|
|
RS::get_singleton()->canvas_item_add_circle(debug_canvas_item, Vector2(), radius, debug_radius_color);
|
2023-02-02 08:38:28 +01:00
|
|
|
}
|
2023-01-10 07:14:16 +01:00
|
|
|
}
|
|
|
|
#endif // DEBUG_ENABLED
|
2023-02-02 08:38:28 +01:00
|
|
|
|
2023-01-10 07:14:16 +01:00
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
void NavigationObstacle2D::_update_static_obstacle_debug() {
|
|
|
|
if (get_vertices().size() > 2 && NavigationServer2D::get_singleton()->get_debug_navigation_avoidance_enable_obstacles_static()) {
|
|
|
|
bool obstacle_pushes_inward = Geometry2D::is_polygon_clockwise(get_vertices());
|
2023-02-02 08:38:28 +01:00
|
|
|
|
2023-01-10 07:14:16 +01:00
|
|
|
Color debug_static_obstacle_face_color;
|
2021-10-21 22:25:06 +02:00
|
|
|
|
2023-01-10 07:14:16 +01:00
|
|
|
if (obstacle_pushes_inward) {
|
|
|
|
debug_static_obstacle_face_color = NavigationServer2D::get_singleton()->get_debug_navigation_avoidance_static_obstacle_pushin_face_color();
|
|
|
|
} else {
|
|
|
|
debug_static_obstacle_face_color = NavigationServer2D::get_singleton()->get_debug_navigation_avoidance_static_obstacle_pushout_face_color();
|
|
|
|
}
|
2023-02-02 08:38:28 +01:00
|
|
|
|
2023-01-10 07:14:16 +01:00
|
|
|
Vector<Vector2> debug_obstacle_polygon_vertices = get_vertices();
|
|
|
|
|
|
|
|
Vector<Color> debug_obstacle_polygon_colors;
|
|
|
|
debug_obstacle_polygon_colors.resize(debug_obstacle_polygon_vertices.size());
|
|
|
|
debug_obstacle_polygon_colors.fill(debug_static_obstacle_face_color);
|
|
|
|
|
2024-02-27 06:51:50 +01:00
|
|
|
RS::get_singleton()->canvas_item_add_polygon(debug_canvas_item, debug_obstacle_polygon_vertices, debug_obstacle_polygon_colors);
|
2023-01-10 07:14:16 +01:00
|
|
|
|
|
|
|
Color debug_static_obstacle_edge_color;
|
|
|
|
|
|
|
|
if (obstacle_pushes_inward) {
|
|
|
|
debug_static_obstacle_edge_color = NavigationServer2D::get_singleton()->get_debug_navigation_avoidance_static_obstacle_pushin_edge_color();
|
|
|
|
} else {
|
|
|
|
debug_static_obstacle_edge_color = NavigationServer2D::get_singleton()->get_debug_navigation_avoidance_static_obstacle_pushout_edge_color();
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector<Vector2> debug_obstacle_line_vertices = get_vertices();
|
|
|
|
debug_obstacle_line_vertices.push_back(debug_obstacle_line_vertices[0]);
|
|
|
|
debug_obstacle_line_vertices.resize(debug_obstacle_line_vertices.size());
|
2023-02-02 08:38:28 +01:00
|
|
|
|
2023-01-10 07:14:16 +01:00
|
|
|
Vector<Color> debug_obstacle_line_colors;
|
|
|
|
debug_obstacle_line_colors.resize(debug_obstacle_line_vertices.size());
|
|
|
|
debug_obstacle_line_colors.fill(debug_static_obstacle_edge_color);
|
|
|
|
|
2024-02-27 06:51:50 +01:00
|
|
|
RS::get_singleton()->canvas_item_add_polyline(debug_canvas_item, debug_obstacle_line_vertices, debug_obstacle_line_colors, 4.0);
|
2023-01-10 07:14:16 +01:00
|
|
|
}
|
2020-01-10 12:22:34 +01:00
|
|
|
}
|
2023-01-10 07:14:16 +01:00
|
|
|
#endif // DEBUG_ENABLED
|