navigation_server_3d.cpp 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893
  1. /**************************************************************************/
  2. /* navigation_server_3d.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "navigation_server_3d.h"
  31. #include "core/config/project_settings.h"
  32. NavigationServer3D *NavigationServer3D::singleton = nullptr;
  33. void NavigationServer3D::_bind_methods() {
  34. ClassDB::bind_method(D_METHOD("get_maps"), &NavigationServer3D::get_maps);
  35. ClassDB::bind_method(D_METHOD("map_create"), &NavigationServer3D::map_create);
  36. ClassDB::bind_method(D_METHOD("map_set_active", "map", "active"), &NavigationServer3D::map_set_active);
  37. ClassDB::bind_method(D_METHOD("map_is_active", "map"), &NavigationServer3D::map_is_active);
  38. ClassDB::bind_method(D_METHOD("map_set_up", "map", "up"), &NavigationServer3D::map_set_up);
  39. ClassDB::bind_method(D_METHOD("map_get_up", "map"), &NavigationServer3D::map_get_up);
  40. ClassDB::bind_method(D_METHOD("map_set_cell_size", "map", "cell_size"), &NavigationServer3D::map_set_cell_size);
  41. ClassDB::bind_method(D_METHOD("map_get_cell_size", "map"), &NavigationServer3D::map_get_cell_size);
  42. ClassDB::bind_method(D_METHOD("map_set_cell_height", "map", "cell_height"), &NavigationServer3D::map_set_cell_height);
  43. ClassDB::bind_method(D_METHOD("map_get_cell_height", "map"), &NavigationServer3D::map_get_cell_height);
  44. ClassDB::bind_method(D_METHOD("map_set_use_edge_connections", "map", "enabled"), &NavigationServer3D::map_set_use_edge_connections);
  45. ClassDB::bind_method(D_METHOD("map_get_use_edge_connections", "map"), &NavigationServer3D::map_get_use_edge_connections);
  46. ClassDB::bind_method(D_METHOD("map_set_edge_connection_margin", "map", "margin"), &NavigationServer3D::map_set_edge_connection_margin);
  47. ClassDB::bind_method(D_METHOD("map_get_edge_connection_margin", "map"), &NavigationServer3D::map_get_edge_connection_margin);
  48. ClassDB::bind_method(D_METHOD("map_set_link_connection_radius", "map", "radius"), &NavigationServer3D::map_set_link_connection_radius);
  49. ClassDB::bind_method(D_METHOD("map_get_link_connection_radius", "map"), &NavigationServer3D::map_get_link_connection_radius);
  50. ClassDB::bind_method(D_METHOD("map_get_path", "map", "origin", "destination", "optimize", "navigation_layers"), &NavigationServer3D::map_get_path, DEFVAL(1));
  51. ClassDB::bind_method(D_METHOD("map_get_closest_point_to_segment", "map", "start", "end", "use_collision"), &NavigationServer3D::map_get_closest_point_to_segment, DEFVAL(false));
  52. ClassDB::bind_method(D_METHOD("map_get_closest_point", "map", "to_point"), &NavigationServer3D::map_get_closest_point);
  53. ClassDB::bind_method(D_METHOD("map_get_closest_point_normal", "map", "to_point"), &NavigationServer3D::map_get_closest_point_normal);
  54. ClassDB::bind_method(D_METHOD("map_get_closest_point_owner", "map", "to_point"), &NavigationServer3D::map_get_closest_point_owner);
  55. ClassDB::bind_method(D_METHOD("map_get_links", "map"), &NavigationServer3D::map_get_links);
  56. ClassDB::bind_method(D_METHOD("map_get_regions", "map"), &NavigationServer3D::map_get_regions);
  57. ClassDB::bind_method(D_METHOD("map_get_agents", "map"), &NavigationServer3D::map_get_agents);
  58. ClassDB::bind_method(D_METHOD("map_get_obstacles", "map"), &NavigationServer3D::map_get_obstacles);
  59. ClassDB::bind_method(D_METHOD("map_force_update", "map"), &NavigationServer3D::map_force_update);
  60. ClassDB::bind_method(D_METHOD("query_path", "parameters", "result"), &NavigationServer3D::query_path);
  61. ClassDB::bind_method(D_METHOD("region_create"), &NavigationServer3D::region_create);
  62. ClassDB::bind_method(D_METHOD("region_set_use_edge_connections", "region", "enabled"), &NavigationServer3D::region_set_use_edge_connections);
  63. ClassDB::bind_method(D_METHOD("region_get_use_edge_connections", "region"), &NavigationServer3D::region_get_use_edge_connections);
  64. ClassDB::bind_method(D_METHOD("region_set_enter_cost", "region", "enter_cost"), &NavigationServer3D::region_set_enter_cost);
  65. ClassDB::bind_method(D_METHOD("region_get_enter_cost", "region"), &NavigationServer3D::region_get_enter_cost);
  66. ClassDB::bind_method(D_METHOD("region_set_travel_cost", "region", "travel_cost"), &NavigationServer3D::region_set_travel_cost);
  67. ClassDB::bind_method(D_METHOD("region_get_travel_cost", "region"), &NavigationServer3D::region_get_travel_cost);
  68. ClassDB::bind_method(D_METHOD("region_set_owner_id", "region", "owner_id"), &NavigationServer3D::region_set_owner_id);
  69. ClassDB::bind_method(D_METHOD("region_get_owner_id", "region"), &NavigationServer3D::region_get_owner_id);
  70. ClassDB::bind_method(D_METHOD("region_owns_point", "region", "point"), &NavigationServer3D::region_owns_point);
  71. ClassDB::bind_method(D_METHOD("region_set_map", "region", "map"), &NavigationServer3D::region_set_map);
  72. ClassDB::bind_method(D_METHOD("region_get_map", "region"), &NavigationServer3D::region_get_map);
  73. ClassDB::bind_method(D_METHOD("region_set_navigation_layers", "region", "navigation_layers"), &NavigationServer3D::region_set_navigation_layers);
  74. ClassDB::bind_method(D_METHOD("region_get_navigation_layers", "region"), &NavigationServer3D::region_get_navigation_layers);
  75. ClassDB::bind_method(D_METHOD("region_set_transform", "region", "transform"), &NavigationServer3D::region_set_transform);
  76. ClassDB::bind_method(D_METHOD("region_set_navigation_mesh", "region", "navigation_mesh"), &NavigationServer3D::region_set_navigation_mesh);
  77. ClassDB::bind_method(D_METHOD("region_bake_navigation_mesh", "navigation_mesh", "root_node"), &NavigationServer3D::region_bake_navigation_mesh);
  78. ClassDB::bind_method(D_METHOD("region_get_connections_count", "region"), &NavigationServer3D::region_get_connections_count);
  79. ClassDB::bind_method(D_METHOD("region_get_connection_pathway_start", "region", "connection"), &NavigationServer3D::region_get_connection_pathway_start);
  80. ClassDB::bind_method(D_METHOD("region_get_connection_pathway_end", "region", "connection"), &NavigationServer3D::region_get_connection_pathway_end);
  81. ClassDB::bind_method(D_METHOD("link_create"), &NavigationServer3D::link_create);
  82. ClassDB::bind_method(D_METHOD("link_set_map", "link", "map"), &NavigationServer3D::link_set_map);
  83. ClassDB::bind_method(D_METHOD("link_get_map", "link"), &NavigationServer3D::link_get_map);
  84. ClassDB::bind_method(D_METHOD("link_set_bidirectional", "link", "bidirectional"), &NavigationServer3D::link_set_bidirectional);
  85. ClassDB::bind_method(D_METHOD("link_is_bidirectional", "link"), &NavigationServer3D::link_is_bidirectional);
  86. ClassDB::bind_method(D_METHOD("link_set_navigation_layers", "link", "navigation_layers"), &NavigationServer3D::link_set_navigation_layers);
  87. ClassDB::bind_method(D_METHOD("link_get_navigation_layers", "link"), &NavigationServer3D::link_get_navigation_layers);
  88. ClassDB::bind_method(D_METHOD("link_set_start_position", "link", "position"), &NavigationServer3D::link_set_start_position);
  89. ClassDB::bind_method(D_METHOD("link_get_start_position", "link"), &NavigationServer3D::link_get_start_position);
  90. ClassDB::bind_method(D_METHOD("link_set_end_position", "link", "position"), &NavigationServer3D::link_set_end_position);
  91. ClassDB::bind_method(D_METHOD("link_get_end_position", "link"), &NavigationServer3D::link_get_end_position);
  92. ClassDB::bind_method(D_METHOD("link_set_enter_cost", "link", "enter_cost"), &NavigationServer3D::link_set_enter_cost);
  93. ClassDB::bind_method(D_METHOD("link_get_enter_cost", "link"), &NavigationServer3D::link_get_enter_cost);
  94. ClassDB::bind_method(D_METHOD("link_set_travel_cost", "link", "travel_cost"), &NavigationServer3D::link_set_travel_cost);
  95. ClassDB::bind_method(D_METHOD("link_get_travel_cost", "link"), &NavigationServer3D::link_get_travel_cost);
  96. ClassDB::bind_method(D_METHOD("link_set_owner_id", "link", "owner_id"), &NavigationServer3D::link_set_owner_id);
  97. ClassDB::bind_method(D_METHOD("link_get_owner_id", "link"), &NavigationServer3D::link_get_owner_id);
  98. ClassDB::bind_method(D_METHOD("agent_create"), &NavigationServer3D::agent_create);
  99. ClassDB::bind_method(D_METHOD("agent_set_avoidance_enabled", "agent", "enabled"), &NavigationServer3D::agent_set_avoidance_enabled);
  100. ClassDB::bind_method(D_METHOD("agent_get_avoidance_enabled", "agent"), &NavigationServer3D::agent_get_avoidance_enabled);
  101. ClassDB::bind_method(D_METHOD("agent_set_use_3d_avoidance", "agent", "enabled"), &NavigationServer3D::agent_set_use_3d_avoidance);
  102. ClassDB::bind_method(D_METHOD("agent_get_use_3d_avoidance", "agent"), &NavigationServer3D::agent_get_use_3d_avoidance);
  103. ClassDB::bind_method(D_METHOD("agent_set_map", "agent", "map"), &NavigationServer3D::agent_set_map);
  104. ClassDB::bind_method(D_METHOD("agent_get_map", "agent"), &NavigationServer3D::agent_get_map);
  105. ClassDB::bind_method(D_METHOD("agent_set_paused", "agent", "paused"), &NavigationServer3D::agent_set_paused);
  106. ClassDB::bind_method(D_METHOD("agent_get_paused", "agent"), &NavigationServer3D::agent_get_paused);
  107. ClassDB::bind_method(D_METHOD("agent_set_neighbor_distance", "agent", "distance"), &NavigationServer3D::agent_set_neighbor_distance);
  108. ClassDB::bind_method(D_METHOD("agent_set_max_neighbors", "agent", "count"), &NavigationServer3D::agent_set_max_neighbors);
  109. ClassDB::bind_method(D_METHOD("agent_set_time_horizon_agents", "agent", "time_horizon"), &NavigationServer3D::agent_set_time_horizon_agents);
  110. ClassDB::bind_method(D_METHOD("agent_set_time_horizon_obstacles", "agent", "time_horizon"), &NavigationServer3D::agent_set_time_horizon_obstacles);
  111. ClassDB::bind_method(D_METHOD("agent_set_radius", "agent", "radius"), &NavigationServer3D::agent_set_radius);
  112. ClassDB::bind_method(D_METHOD("agent_set_height", "agent", "height"), &NavigationServer3D::agent_set_height);
  113. ClassDB::bind_method(D_METHOD("agent_set_max_speed", "agent", "max_speed"), &NavigationServer3D::agent_set_max_speed);
  114. ClassDB::bind_method(D_METHOD("agent_set_velocity_forced", "agent", "velocity"), &NavigationServer3D::agent_set_velocity_forced);
  115. ClassDB::bind_method(D_METHOD("agent_set_velocity", "agent", "velocity"), &NavigationServer3D::agent_set_velocity);
  116. ClassDB::bind_method(D_METHOD("agent_set_position", "agent", "position"), &NavigationServer3D::agent_set_position);
  117. ClassDB::bind_method(D_METHOD("agent_is_map_changed", "agent"), &NavigationServer3D::agent_is_map_changed);
  118. ClassDB::bind_method(D_METHOD("agent_set_avoidance_callback", "agent", "callback"), &NavigationServer3D::agent_set_avoidance_callback);
  119. ClassDB::bind_method(D_METHOD("agent_set_avoidance_layers", "agent", "layers"), &NavigationServer3D::agent_set_avoidance_layers);
  120. ClassDB::bind_method(D_METHOD("agent_set_avoidance_mask", "agent", "mask"), &NavigationServer3D::agent_set_avoidance_mask);
  121. ClassDB::bind_method(D_METHOD("agent_set_avoidance_priority", "agent", "priority"), &NavigationServer3D::agent_set_avoidance_priority);
  122. ClassDB::bind_method(D_METHOD("obstacle_create"), &NavigationServer3D::obstacle_create);
  123. ClassDB::bind_method(D_METHOD("obstacle_set_avoidance_enabled", "obstacle", "enabled"), &NavigationServer3D::obstacle_set_avoidance_enabled);
  124. ClassDB::bind_method(D_METHOD("obstacle_get_avoidance_enabled", "obstacle"), &NavigationServer3D::obstacle_get_avoidance_enabled);
  125. ClassDB::bind_method(D_METHOD("obstacle_set_use_3d_avoidance", "obstacle", "enabled"), &NavigationServer3D::obstacle_set_use_3d_avoidance);
  126. ClassDB::bind_method(D_METHOD("obstacle_get_use_3d_avoidance", "obstacle"), &NavigationServer3D::obstacle_get_use_3d_avoidance);
  127. ClassDB::bind_method(D_METHOD("obstacle_set_map", "obstacle", "map"), &NavigationServer3D::obstacle_set_map);
  128. ClassDB::bind_method(D_METHOD("obstacle_get_map", "obstacle"), &NavigationServer3D::obstacle_get_map);
  129. ClassDB::bind_method(D_METHOD("obstacle_set_paused", "obstacle", "paused"), &NavigationServer3D::obstacle_set_paused);
  130. ClassDB::bind_method(D_METHOD("obstacle_get_paused", "obstacle"), &NavigationServer3D::obstacle_get_paused);
  131. ClassDB::bind_method(D_METHOD("obstacle_set_radius", "obstacle", "radius"), &NavigationServer3D::obstacle_set_radius);
  132. ClassDB::bind_method(D_METHOD("obstacle_set_height", "obstacle", "height"), &NavigationServer3D::obstacle_set_height);
  133. ClassDB::bind_method(D_METHOD("obstacle_set_velocity", "obstacle", "velocity"), &NavigationServer3D::obstacle_set_velocity);
  134. ClassDB::bind_method(D_METHOD("obstacle_set_position", "obstacle", "position"), &NavigationServer3D::obstacle_set_position);
  135. ClassDB::bind_method(D_METHOD("obstacle_set_vertices", "obstacle", "vertices"), &NavigationServer3D::obstacle_set_vertices);
  136. ClassDB::bind_method(D_METHOD("obstacle_set_avoidance_layers", "obstacle", "layers"), &NavigationServer3D::obstacle_set_avoidance_layers);
  137. ClassDB::bind_method(D_METHOD("parse_source_geometry_data", "navigation_mesh", "source_geometry_data", "root_node", "callback"), &NavigationServer3D::parse_source_geometry_data, DEFVAL(Callable()));
  138. ClassDB::bind_method(D_METHOD("bake_from_source_geometry_data", "navigation_mesh", "source_geometry_data", "callback"), &NavigationServer3D::bake_from_source_geometry_data, DEFVAL(Callable()));
  139. ClassDB::bind_method(D_METHOD("free_rid", "rid"), &NavigationServer3D::free);
  140. ClassDB::bind_method(D_METHOD("set_active", "active"), &NavigationServer3D::set_active);
  141. ClassDB::bind_method(D_METHOD("set_debug_enabled", "enabled"), &NavigationServer3D::set_debug_enabled);
  142. ClassDB::bind_method(D_METHOD("get_debug_enabled"), &NavigationServer3D::get_debug_enabled);
  143. ADD_SIGNAL(MethodInfo("map_changed", PropertyInfo(Variant::RID, "map")));
  144. ADD_SIGNAL(MethodInfo("navigation_debug_changed"));
  145. ADD_SIGNAL(MethodInfo("avoidance_debug_changed"));
  146. ClassDB::bind_method(D_METHOD("get_process_info", "process_info"), &NavigationServer3D::get_process_info);
  147. BIND_ENUM_CONSTANT(INFO_ACTIVE_MAPS);
  148. BIND_ENUM_CONSTANT(INFO_REGION_COUNT);
  149. BIND_ENUM_CONSTANT(INFO_AGENT_COUNT);
  150. BIND_ENUM_CONSTANT(INFO_LINK_COUNT);
  151. BIND_ENUM_CONSTANT(INFO_POLYGON_COUNT);
  152. BIND_ENUM_CONSTANT(INFO_EDGE_COUNT);
  153. BIND_ENUM_CONSTANT(INFO_EDGE_MERGE_COUNT);
  154. BIND_ENUM_CONSTANT(INFO_EDGE_CONNECTION_COUNT);
  155. BIND_ENUM_CONSTANT(INFO_EDGE_FREE_COUNT);
  156. }
  157. NavigationServer3D *NavigationServer3D::get_singleton() {
  158. return singleton;
  159. }
  160. NavigationServer3D::NavigationServer3D() {
  161. ERR_FAIL_COND(singleton != nullptr);
  162. singleton = this;
  163. GLOBAL_DEF_BASIC("navigation/2d/default_cell_size", 1);
  164. GLOBAL_DEF("navigation/2d/use_edge_connections", true);
  165. GLOBAL_DEF_BASIC("navigation/2d/default_edge_connection_margin", 1);
  166. GLOBAL_DEF_BASIC("navigation/2d/default_link_connection_radius", 4);
  167. GLOBAL_DEF_BASIC("navigation/3d/default_cell_size", 0.25);
  168. GLOBAL_DEF_BASIC("navigation/3d/default_cell_height", 0.25);
  169. GLOBAL_DEF("navigation/3d/use_edge_connections", true);
  170. GLOBAL_DEF_BASIC("navigation/3d/default_edge_connection_margin", 0.25);
  171. GLOBAL_DEF_BASIC("navigation/3d/default_link_connection_radius", 1.0);
  172. GLOBAL_DEF("navigation/avoidance/thread_model/avoidance_use_multiple_threads", true);
  173. GLOBAL_DEF("navigation/avoidance/thread_model/avoidance_use_high_priority_threads", true);
  174. #ifdef DEBUG_ENABLED
  175. debug_navigation_edge_connection_color = GLOBAL_DEF("debug/shapes/navigation/edge_connection_color", Color(1.0, 0.0, 1.0, 1.0));
  176. debug_navigation_geometry_edge_color = GLOBAL_DEF("debug/shapes/navigation/geometry_edge_color", Color(0.5, 1.0, 1.0, 1.0));
  177. debug_navigation_geometry_face_color = GLOBAL_DEF("debug/shapes/navigation/geometry_face_color", Color(0.5, 1.0, 1.0, 0.4));
  178. debug_navigation_geometry_edge_disabled_color = GLOBAL_DEF("debug/shapes/navigation/geometry_edge_disabled_color", Color(0.5, 0.5, 0.5, 1.0));
  179. debug_navigation_geometry_face_disabled_color = GLOBAL_DEF("debug/shapes/navigation/geometry_face_disabled_color", Color(0.5, 0.5, 0.5, 0.4));
  180. debug_navigation_link_connection_color = GLOBAL_DEF("debug/shapes/navigation/link_connection_color", Color(1.0, 0.5, 1.0, 1.0));
  181. debug_navigation_link_connection_disabled_color = GLOBAL_DEF("debug/shapes/navigation/link_connection_disabled_color", Color(0.5, 0.5, 0.5, 1.0));
  182. debug_navigation_agent_path_color = GLOBAL_DEF("debug/shapes/navigation/agent_path_color", Color(1.0, 0.0, 0.0, 1.0));
  183. debug_navigation_enable_edge_connections = GLOBAL_DEF("debug/shapes/navigation/enable_edge_connections", true);
  184. debug_navigation_enable_edge_connections_xray = GLOBAL_DEF("debug/shapes/navigation/enable_edge_connections_xray", true);
  185. debug_navigation_enable_edge_lines = GLOBAL_DEF("debug/shapes/navigation/enable_edge_lines", true);
  186. debug_navigation_enable_edge_lines_xray = GLOBAL_DEF("debug/shapes/navigation/enable_edge_lines_xray", true);
  187. debug_navigation_enable_geometry_face_random_color = GLOBAL_DEF("debug/shapes/navigation/enable_geometry_face_random_color", true);
  188. debug_navigation_enable_link_connections = GLOBAL_DEF("debug/shapes/navigation/enable_link_connections", true);
  189. debug_navigation_enable_link_connections_xray = GLOBAL_DEF("debug/shapes/navigation/enable_link_connections_xray", true);
  190. debug_navigation_enable_agent_paths = GLOBAL_DEF("debug/shapes/navigation/enable_agent_paths", true);
  191. debug_navigation_enable_agent_paths_xray = GLOBAL_DEF("debug/shapes/navigation/enable_agent_paths_xray", true);
  192. debug_navigation_agent_path_point_size = GLOBAL_DEF("debug/shapes/navigation/agent_path_point_size", 4.0);
  193. debug_navigation_avoidance_agents_radius_color = GLOBAL_DEF("debug/shapes/avoidance/agents_radius_color", Color(1.0, 1.0, 0.0, 0.25));
  194. debug_navigation_avoidance_obstacles_radius_color = GLOBAL_DEF("debug/shapes/avoidance/obstacles_radius_color", Color(1.0, 0.5, 0.0, 0.25));
  195. debug_navigation_avoidance_static_obstacle_pushin_face_color = GLOBAL_DEF("debug/shapes/avoidance/obstacles_static_face_pushin_color", Color(1.0, 0.0, 0.0, 0.0));
  196. debug_navigation_avoidance_static_obstacle_pushin_edge_color = GLOBAL_DEF("debug/shapes/avoidance/obstacles_static_edge_pushin_color", Color(1.0, 0.0, 0.0, 1.0));
  197. debug_navigation_avoidance_static_obstacle_pushout_face_color = GLOBAL_DEF("debug/shapes/avoidance/obstacles_static_face_pushout_color", Color(1.0, 1.0, 0.0, 0.5));
  198. debug_navigation_avoidance_static_obstacle_pushout_edge_color = GLOBAL_DEF("debug/shapes/avoidance/obstacles_static_edge_pushout_color", Color(1.0, 1.0, 0.0, 1.0));
  199. debug_navigation_avoidance_enable_agents_radius = GLOBAL_DEF("debug/shapes/avoidance/enable_agents_radius", true);
  200. debug_navigation_avoidance_enable_obstacles_radius = GLOBAL_DEF("debug/shapes/avoidance/enable_obstacles_radius", true);
  201. debug_navigation_avoidance_enable_obstacles_static = GLOBAL_DEF("debug/shapes/avoidance/enable_obstacles_static", true);
  202. if (Engine::get_singleton()->is_editor_hint()) {
  203. // enable NavigationServer3D when in Editor or else navigation mesh edge connections are invisible
  204. // on runtime tests SceneTree has "Visible Navigation" set and main iteration takes care of this
  205. set_debug_enabled(true);
  206. set_debug_navigation_enabled(true);
  207. set_debug_avoidance_enabled(true);
  208. }
  209. #endif // DEBUG_ENABLED
  210. }
  211. NavigationServer3D::~NavigationServer3D() {
  212. singleton = nullptr;
  213. }
  214. void NavigationServer3D::set_debug_enabled(bool p_enabled) {
  215. #ifdef DEBUG_ENABLED
  216. if (debug_enabled != p_enabled) {
  217. debug_dirty = true;
  218. }
  219. debug_enabled = p_enabled;
  220. if (debug_dirty) {
  221. call_deferred("_emit_navigation_debug_changed_signal");
  222. }
  223. #endif // DEBUG_ENABLED
  224. }
  225. bool NavigationServer3D::get_debug_enabled() const {
  226. return debug_enabled;
  227. }
  228. #ifdef DEBUG_ENABLED
  229. void NavigationServer3D::_emit_navigation_debug_changed_signal() {
  230. if (navigation_debug_dirty) {
  231. navigation_debug_dirty = false;
  232. emit_signal(SNAME("navigation_debug_changed"));
  233. }
  234. }
  235. void NavigationServer3D::_emit_avoidance_debug_changed_signal() {
  236. if (avoidance_debug_dirty) {
  237. avoidance_debug_dirty = false;
  238. emit_signal(SNAME("avoidance_debug_changed"));
  239. }
  240. }
  241. #endif // DEBUG_ENABLED
  242. #ifdef DEBUG_ENABLED
  243. Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_geometry_face_material() {
  244. if (debug_navigation_geometry_face_material.is_valid()) {
  245. return debug_navigation_geometry_face_material;
  246. }
  247. bool enabled_geometry_face_random_color = get_debug_navigation_enable_geometry_face_random_color();
  248. Ref<StandardMaterial3D> face_material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
  249. face_material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
  250. face_material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
  251. face_material->set_albedo(get_debug_navigation_geometry_face_color());
  252. face_material->set_cull_mode(StandardMaterial3D::CULL_DISABLED);
  253. if (enabled_geometry_face_random_color) {
  254. face_material->set_flag(StandardMaterial3D::FLAG_SRGB_VERTEX_COLOR, true);
  255. face_material->set_flag(StandardMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true);
  256. }
  257. debug_navigation_geometry_face_material = face_material;
  258. return debug_navigation_geometry_face_material;
  259. }
  260. Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_geometry_edge_material() {
  261. if (debug_navigation_geometry_edge_material.is_valid()) {
  262. return debug_navigation_geometry_edge_material;
  263. }
  264. bool enabled_edge_lines_xray = get_debug_navigation_enable_edge_lines_xray();
  265. Ref<StandardMaterial3D> line_material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
  266. line_material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
  267. line_material->set_albedo(get_debug_navigation_geometry_edge_color());
  268. if (enabled_edge_lines_xray) {
  269. line_material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true);
  270. }
  271. debug_navigation_geometry_edge_material = line_material;
  272. return debug_navigation_geometry_edge_material;
  273. }
  274. Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_geometry_face_disabled_material() {
  275. if (debug_navigation_geometry_face_disabled_material.is_valid()) {
  276. return debug_navigation_geometry_face_disabled_material;
  277. }
  278. Ref<StandardMaterial3D> face_disabled_material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
  279. face_disabled_material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
  280. face_disabled_material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
  281. face_disabled_material->set_albedo(get_debug_navigation_geometry_face_disabled_color());
  282. debug_navigation_geometry_face_disabled_material = face_disabled_material;
  283. return debug_navigation_geometry_face_disabled_material;
  284. }
  285. Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_geometry_edge_disabled_material() {
  286. if (debug_navigation_geometry_edge_disabled_material.is_valid()) {
  287. return debug_navigation_geometry_edge_disabled_material;
  288. }
  289. bool enabled_edge_lines_xray = get_debug_navigation_enable_edge_lines_xray();
  290. Ref<StandardMaterial3D> line_disabled_material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
  291. line_disabled_material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
  292. line_disabled_material->set_albedo(get_debug_navigation_geometry_edge_disabled_color());
  293. if (enabled_edge_lines_xray) {
  294. line_disabled_material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true);
  295. }
  296. debug_navigation_geometry_edge_disabled_material = line_disabled_material;
  297. return debug_navigation_geometry_edge_disabled_material;
  298. }
  299. Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_edge_connections_material() {
  300. if (debug_navigation_edge_connections_material.is_valid()) {
  301. return debug_navigation_edge_connections_material;
  302. }
  303. bool enabled_edge_connections_xray = get_debug_navigation_enable_edge_connections_xray();
  304. Ref<StandardMaterial3D> edge_connections_material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
  305. edge_connections_material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
  306. edge_connections_material->set_albedo(get_debug_navigation_edge_connection_color());
  307. if (enabled_edge_connections_xray) {
  308. edge_connections_material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true);
  309. }
  310. edge_connections_material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MAX - 2);
  311. debug_navigation_edge_connections_material = edge_connections_material;
  312. return debug_navigation_edge_connections_material;
  313. }
  314. Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_link_connections_material() {
  315. if (debug_navigation_link_connections_material.is_valid()) {
  316. return debug_navigation_link_connections_material;
  317. }
  318. Ref<StandardMaterial3D> material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
  319. material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
  320. material->set_albedo(debug_navigation_link_connection_color);
  321. if (debug_navigation_enable_link_connections_xray) {
  322. material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true);
  323. }
  324. material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MAX - 2);
  325. debug_navigation_link_connections_material = material;
  326. return debug_navigation_link_connections_material;
  327. }
  328. Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_link_connections_disabled_material() {
  329. if (debug_navigation_link_connections_disabled_material.is_valid()) {
  330. return debug_navigation_link_connections_disabled_material;
  331. }
  332. Ref<StandardMaterial3D> material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
  333. material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
  334. material->set_albedo(debug_navigation_link_connection_disabled_color);
  335. if (debug_navigation_enable_link_connections_xray) {
  336. material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true);
  337. }
  338. material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MAX - 2);
  339. debug_navigation_link_connections_disabled_material = material;
  340. return debug_navigation_link_connections_disabled_material;
  341. }
  342. Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_agent_path_line_material() {
  343. if (debug_navigation_agent_path_line_material.is_valid()) {
  344. return debug_navigation_agent_path_line_material;
  345. }
  346. Ref<StandardMaterial3D> material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
  347. material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
  348. material->set_albedo(debug_navigation_agent_path_color);
  349. if (debug_navigation_enable_agent_paths_xray) {
  350. material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true);
  351. }
  352. material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MAX - 2);
  353. debug_navigation_agent_path_line_material = material;
  354. return debug_navigation_agent_path_line_material;
  355. }
  356. Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_agent_path_point_material() {
  357. if (debug_navigation_agent_path_point_material.is_valid()) {
  358. return debug_navigation_agent_path_point_material;
  359. }
  360. Ref<StandardMaterial3D> material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
  361. material->set_albedo(debug_navigation_agent_path_color);
  362. material->set_flag(StandardMaterial3D::FLAG_USE_POINT_SIZE, true);
  363. material->set_point_size(debug_navigation_agent_path_point_size);
  364. if (debug_navigation_enable_agent_paths_xray) {
  365. material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true);
  366. }
  367. material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MAX - 2);
  368. debug_navigation_agent_path_point_material = material;
  369. return debug_navigation_agent_path_point_material;
  370. }
  371. Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_avoidance_agents_radius_material() {
  372. if (debug_navigation_avoidance_agents_radius_material.is_valid()) {
  373. return debug_navigation_avoidance_agents_radius_material;
  374. }
  375. Ref<StandardMaterial3D> material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
  376. material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
  377. material->set_cull_mode(StandardMaterial3D::CULL_DISABLED);
  378. material->set_albedo(debug_navigation_avoidance_agents_radius_color);
  379. material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MIN + 2);
  380. debug_navigation_avoidance_agents_radius_material = material;
  381. return debug_navigation_avoidance_agents_radius_material;
  382. }
  383. Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_avoidance_obstacles_radius_material() {
  384. if (debug_navigation_avoidance_obstacles_radius_material.is_valid()) {
  385. return debug_navigation_avoidance_obstacles_radius_material;
  386. }
  387. Ref<StandardMaterial3D> material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
  388. material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
  389. material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
  390. material->set_cull_mode(StandardMaterial3D::CULL_DISABLED);
  391. material->set_albedo(debug_navigation_avoidance_obstacles_radius_color);
  392. material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MIN + 2);
  393. debug_navigation_avoidance_obstacles_radius_material = material;
  394. return debug_navigation_avoidance_obstacles_radius_material;
  395. }
  396. Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_avoidance_static_obstacle_pushin_face_material() {
  397. if (debug_navigation_avoidance_static_obstacle_pushin_face_material.is_valid()) {
  398. return debug_navigation_avoidance_static_obstacle_pushin_face_material;
  399. }
  400. Ref<StandardMaterial3D> material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
  401. material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
  402. material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
  403. material->set_cull_mode(StandardMaterial3D::CULL_DISABLED);
  404. material->set_albedo(debug_navigation_avoidance_static_obstacle_pushin_face_color);
  405. material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MIN + 2);
  406. debug_navigation_avoidance_static_obstacle_pushin_face_material = material;
  407. return debug_navigation_avoidance_static_obstacle_pushin_face_material;
  408. }
  409. Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_avoidance_static_obstacle_pushout_face_material() {
  410. if (debug_navigation_avoidance_static_obstacle_pushout_face_material.is_valid()) {
  411. return debug_navigation_avoidance_static_obstacle_pushout_face_material;
  412. }
  413. Ref<StandardMaterial3D> material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
  414. material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
  415. material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
  416. material->set_cull_mode(StandardMaterial3D::CULL_DISABLED);
  417. material->set_albedo(debug_navigation_avoidance_static_obstacle_pushout_face_color);
  418. material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MIN + 2);
  419. debug_navigation_avoidance_static_obstacle_pushout_face_material = material;
  420. return debug_navigation_avoidance_static_obstacle_pushout_face_material;
  421. }
  422. Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_avoidance_static_obstacle_pushin_edge_material() {
  423. if (debug_navigation_avoidance_static_obstacle_pushin_edge_material.is_valid()) {
  424. return debug_navigation_avoidance_static_obstacle_pushin_edge_material;
  425. }
  426. Ref<StandardMaterial3D> material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
  427. material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
  428. //material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
  429. //material->set_cull_mode(StandardMaterial3D::CULL_DISABLED);
  430. material->set_albedo(debug_navigation_avoidance_static_obstacle_pushin_edge_color);
  431. //material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MIN + 2);
  432. material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true);
  433. debug_navigation_avoidance_static_obstacle_pushin_edge_material = material;
  434. return debug_navigation_avoidance_static_obstacle_pushin_edge_material;
  435. }
  436. Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_avoidance_static_obstacle_pushout_edge_material() {
  437. if (debug_navigation_avoidance_static_obstacle_pushout_edge_material.is_valid()) {
  438. return debug_navigation_avoidance_static_obstacle_pushout_edge_material;
  439. }
  440. Ref<StandardMaterial3D> material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
  441. material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
  442. ///material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
  443. //material->set_cull_mode(StandardMaterial3D::CULL_DISABLED);
  444. material->set_albedo(debug_navigation_avoidance_static_obstacle_pushout_edge_color);
  445. //material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MIN + 2);
  446. material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true);
  447. debug_navigation_avoidance_static_obstacle_pushout_edge_material = material;
  448. return debug_navigation_avoidance_static_obstacle_pushout_edge_material;
  449. }
  450. void NavigationServer3D::set_debug_navigation_edge_connection_color(const Color &p_color) {
  451. debug_navigation_edge_connection_color = p_color;
  452. if (debug_navigation_edge_connections_material.is_valid()) {
  453. debug_navigation_edge_connections_material->set_albedo(debug_navigation_edge_connection_color);
  454. }
  455. }
  456. Color NavigationServer3D::get_debug_navigation_edge_connection_color() const {
  457. return debug_navigation_edge_connection_color;
  458. }
  459. void NavigationServer3D::set_debug_navigation_geometry_edge_color(const Color &p_color) {
  460. debug_navigation_geometry_edge_color = p_color;
  461. if (debug_navigation_geometry_edge_material.is_valid()) {
  462. debug_navigation_geometry_edge_material->set_albedo(debug_navigation_geometry_edge_color);
  463. }
  464. }
  465. Color NavigationServer3D::get_debug_navigation_geometry_edge_color() const {
  466. return debug_navigation_geometry_edge_color;
  467. }
  468. void NavigationServer3D::set_debug_navigation_geometry_face_color(const Color &p_color) {
  469. debug_navigation_geometry_face_color = p_color;
  470. if (debug_navigation_geometry_face_material.is_valid()) {
  471. debug_navigation_geometry_face_material->set_albedo(debug_navigation_geometry_face_color);
  472. }
  473. }
  474. Color NavigationServer3D::get_debug_navigation_geometry_face_color() const {
  475. return debug_navigation_geometry_face_color;
  476. }
  477. void NavigationServer3D::set_debug_navigation_geometry_edge_disabled_color(const Color &p_color) {
  478. debug_navigation_geometry_edge_disabled_color = p_color;
  479. if (debug_navigation_geometry_edge_disabled_material.is_valid()) {
  480. debug_navigation_geometry_edge_disabled_material->set_albedo(debug_navigation_geometry_edge_disabled_color);
  481. }
  482. }
  483. Color NavigationServer3D::get_debug_navigation_geometry_edge_disabled_color() const {
  484. return debug_navigation_geometry_edge_disabled_color;
  485. }
  486. void NavigationServer3D::set_debug_navigation_geometry_face_disabled_color(const Color &p_color) {
  487. debug_navigation_geometry_face_disabled_color = p_color;
  488. if (debug_navigation_geometry_face_disabled_material.is_valid()) {
  489. debug_navigation_geometry_face_disabled_material->set_albedo(debug_navigation_geometry_face_disabled_color);
  490. }
  491. }
  492. Color NavigationServer3D::get_debug_navigation_geometry_face_disabled_color() const {
  493. return debug_navigation_geometry_face_disabled_color;
  494. }
  495. void NavigationServer3D::set_debug_navigation_link_connection_color(const Color &p_color) {
  496. debug_navigation_link_connection_color = p_color;
  497. if (debug_navigation_link_connections_material.is_valid()) {
  498. debug_navigation_link_connections_material->set_albedo(debug_navigation_link_connection_color);
  499. }
  500. }
  501. Color NavigationServer3D::get_debug_navigation_link_connection_color() const {
  502. return debug_navigation_link_connection_color;
  503. }
  504. void NavigationServer3D::set_debug_navigation_link_connection_disabled_color(const Color &p_color) {
  505. debug_navigation_link_connection_disabled_color = p_color;
  506. if (debug_navigation_link_connections_disabled_material.is_valid()) {
  507. debug_navigation_link_connections_disabled_material->set_albedo(debug_navigation_link_connection_disabled_color);
  508. }
  509. }
  510. Color NavigationServer3D::get_debug_navigation_link_connection_disabled_color() const {
  511. return debug_navigation_link_connection_disabled_color;
  512. }
  513. void NavigationServer3D::set_debug_navigation_agent_path_point_size(real_t p_point_size) {
  514. debug_navigation_agent_path_point_size = MAX(0.1, p_point_size);
  515. if (debug_navigation_agent_path_point_material.is_valid()) {
  516. debug_navigation_agent_path_point_material->set_point_size(debug_navigation_agent_path_point_size);
  517. }
  518. }
  519. real_t NavigationServer3D::get_debug_navigation_agent_path_point_size() const {
  520. return debug_navigation_agent_path_point_size;
  521. }
  522. void NavigationServer3D::set_debug_navigation_agent_path_color(const Color &p_color) {
  523. debug_navigation_agent_path_color = p_color;
  524. if (debug_navigation_agent_path_line_material.is_valid()) {
  525. debug_navigation_agent_path_line_material->set_albedo(debug_navigation_agent_path_color);
  526. }
  527. if (debug_navigation_agent_path_point_material.is_valid()) {
  528. debug_navigation_agent_path_point_material->set_albedo(debug_navigation_agent_path_color);
  529. }
  530. }
  531. Color NavigationServer3D::get_debug_navigation_agent_path_color() const {
  532. return debug_navigation_agent_path_color;
  533. }
  534. void NavigationServer3D::set_debug_navigation_enable_edge_connections(const bool p_value) {
  535. debug_navigation_enable_edge_connections = p_value;
  536. navigation_debug_dirty = true;
  537. call_deferred("_emit_navigation_debug_changed_signal");
  538. }
  539. bool NavigationServer3D::get_debug_navigation_enable_edge_connections() const {
  540. return debug_navigation_enable_edge_connections;
  541. }
  542. void NavigationServer3D::set_debug_navigation_enable_edge_connections_xray(const bool p_value) {
  543. debug_navigation_enable_edge_connections_xray = p_value;
  544. if (debug_navigation_edge_connections_material.is_valid()) {
  545. debug_navigation_edge_connections_material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, debug_navigation_enable_edge_connections_xray);
  546. }
  547. }
  548. bool NavigationServer3D::get_debug_navigation_enable_edge_connections_xray() const {
  549. return debug_navigation_enable_edge_connections_xray;
  550. }
  551. void NavigationServer3D::set_debug_navigation_enable_edge_lines(const bool p_value) {
  552. debug_navigation_enable_edge_lines = p_value;
  553. navigation_debug_dirty = true;
  554. call_deferred("_emit_navigation_debug_changed_signal");
  555. }
  556. bool NavigationServer3D::get_debug_navigation_enable_edge_lines() const {
  557. return debug_navigation_enable_edge_lines;
  558. }
  559. void NavigationServer3D::set_debug_navigation_enable_edge_lines_xray(const bool p_value) {
  560. debug_navigation_enable_edge_lines_xray = p_value;
  561. if (debug_navigation_geometry_edge_material.is_valid()) {
  562. debug_navigation_geometry_edge_material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, debug_navigation_enable_edge_lines_xray);
  563. }
  564. }
  565. bool NavigationServer3D::get_debug_navigation_enable_edge_lines_xray() const {
  566. return debug_navigation_enable_edge_lines_xray;
  567. }
  568. void NavigationServer3D::set_debug_navigation_enable_geometry_face_random_color(const bool p_value) {
  569. debug_navigation_enable_geometry_face_random_color = p_value;
  570. navigation_debug_dirty = true;
  571. call_deferred("_emit_navigation_debug_changed_signal");
  572. }
  573. bool NavigationServer3D::get_debug_navigation_enable_geometry_face_random_color() const {
  574. return debug_navigation_enable_geometry_face_random_color;
  575. }
  576. void NavigationServer3D::set_debug_navigation_enable_link_connections(const bool p_value) {
  577. debug_navigation_enable_link_connections = p_value;
  578. navigation_debug_dirty = true;
  579. call_deferred("_emit_navigation_debug_changed_signal");
  580. }
  581. bool NavigationServer3D::get_debug_navigation_enable_link_connections() const {
  582. return debug_navigation_enable_link_connections;
  583. }
  584. void NavigationServer3D::set_debug_navigation_enable_link_connections_xray(const bool p_value) {
  585. debug_navigation_enable_link_connections_xray = p_value;
  586. if (debug_navigation_link_connections_material.is_valid()) {
  587. debug_navigation_link_connections_material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, debug_navigation_enable_link_connections_xray);
  588. }
  589. }
  590. bool NavigationServer3D::get_debug_navigation_enable_link_connections_xray() const {
  591. return debug_navigation_enable_link_connections_xray;
  592. }
  593. void NavigationServer3D::set_debug_navigation_avoidance_enable_agents_radius(const bool p_value) {
  594. debug_navigation_avoidance_enable_agents_radius = p_value;
  595. avoidance_debug_dirty = true;
  596. call_deferred("_emit_avoidance_debug_changed_signal");
  597. }
  598. bool NavigationServer3D::get_debug_navigation_avoidance_enable_agents_radius() const {
  599. return debug_navigation_avoidance_enable_agents_radius;
  600. }
  601. void NavigationServer3D::set_debug_navigation_avoidance_enable_obstacles_radius(const bool p_value) {
  602. debug_navigation_avoidance_enable_obstacles_radius = p_value;
  603. avoidance_debug_dirty = true;
  604. call_deferred("_emit_avoidance_debug_changed_signal");
  605. }
  606. bool NavigationServer3D::get_debug_navigation_avoidance_enable_obstacles_radius() const {
  607. return debug_navigation_avoidance_enable_obstacles_radius;
  608. }
  609. void NavigationServer3D::set_debug_navigation_avoidance_enable_obstacles_static(const bool p_value) {
  610. debug_navigation_avoidance_enable_obstacles_static = p_value;
  611. avoidance_debug_dirty = true;
  612. call_deferred("_emit_avoidance_debug_changed_signal");
  613. }
  614. bool NavigationServer3D::get_debug_navigation_avoidance_enable_obstacles_static() const {
  615. return debug_navigation_avoidance_enable_obstacles_static;
  616. }
  617. void NavigationServer3D::set_debug_navigation_avoidance_agents_radius_color(const Color &p_color) {
  618. debug_navigation_avoidance_agents_radius_color = p_color;
  619. if (debug_navigation_avoidance_agents_radius_material.is_valid()) {
  620. debug_navigation_avoidance_agents_radius_material->set_albedo(debug_navigation_avoidance_agents_radius_color);
  621. }
  622. }
  623. Color NavigationServer3D::get_debug_navigation_avoidance_agents_radius_color() const {
  624. return debug_navigation_avoidance_agents_radius_color;
  625. }
  626. void NavigationServer3D::set_debug_navigation_avoidance_obstacles_radius_color(const Color &p_color) {
  627. debug_navigation_avoidance_obstacles_radius_color = p_color;
  628. if (debug_navigation_avoidance_obstacles_radius_material.is_valid()) {
  629. debug_navigation_avoidance_obstacles_radius_material->set_albedo(debug_navigation_avoidance_obstacles_radius_color);
  630. }
  631. }
  632. Color NavigationServer3D::get_debug_navigation_avoidance_obstacles_radius_color() const {
  633. return debug_navigation_avoidance_obstacles_radius_color;
  634. }
  635. void NavigationServer3D::set_debug_navigation_avoidance_static_obstacle_pushin_face_color(const Color &p_color) {
  636. debug_navigation_avoidance_static_obstacle_pushin_face_color = p_color;
  637. if (debug_navigation_avoidance_static_obstacle_pushin_face_material.is_valid()) {
  638. debug_navigation_avoidance_static_obstacle_pushin_face_material->set_albedo(debug_navigation_avoidance_static_obstacle_pushin_face_color);
  639. }
  640. }
  641. Color NavigationServer3D::get_debug_navigation_avoidance_static_obstacle_pushin_face_color() const {
  642. return debug_navigation_avoidance_static_obstacle_pushin_face_color;
  643. }
  644. void NavigationServer3D::set_debug_navigation_avoidance_static_obstacle_pushout_face_color(const Color &p_color) {
  645. debug_navigation_avoidance_static_obstacle_pushout_face_color = p_color;
  646. if (debug_navigation_avoidance_static_obstacle_pushout_face_material.is_valid()) {
  647. debug_navigation_avoidance_static_obstacle_pushout_face_material->set_albedo(debug_navigation_avoidance_static_obstacle_pushout_face_color);
  648. }
  649. }
  650. Color NavigationServer3D::get_debug_navigation_avoidance_static_obstacle_pushout_face_color() const {
  651. return debug_navigation_avoidance_static_obstacle_pushout_face_color;
  652. }
  653. void NavigationServer3D::set_debug_navigation_avoidance_static_obstacle_pushin_edge_color(const Color &p_color) {
  654. debug_navigation_avoidance_static_obstacle_pushin_edge_color = p_color;
  655. if (debug_navigation_avoidance_static_obstacle_pushin_edge_material.is_valid()) {
  656. debug_navigation_avoidance_static_obstacle_pushin_edge_material->set_albedo(debug_navigation_avoidance_static_obstacle_pushin_edge_color);
  657. }
  658. }
  659. Color NavigationServer3D::get_debug_navigation_avoidance_static_obstacle_pushin_edge_color() const {
  660. return debug_navigation_avoidance_static_obstacle_pushin_edge_color;
  661. }
  662. void NavigationServer3D::set_debug_navigation_avoidance_static_obstacle_pushout_edge_color(const Color &p_color) {
  663. debug_navigation_avoidance_static_obstacle_pushout_edge_color = p_color;
  664. if (debug_navigation_avoidance_static_obstacle_pushout_edge_material.is_valid()) {
  665. debug_navigation_avoidance_static_obstacle_pushout_edge_material->set_albedo(debug_navigation_avoidance_static_obstacle_pushout_edge_color);
  666. }
  667. }
  668. Color NavigationServer3D::get_debug_navigation_avoidance_static_obstacle_pushout_edge_color() const {
  669. return debug_navigation_avoidance_static_obstacle_pushout_edge_color;
  670. }
  671. void NavigationServer3D::set_debug_navigation_enable_agent_paths(const bool p_value) {
  672. if (debug_navigation_enable_agent_paths != p_value) {
  673. debug_dirty = true;
  674. }
  675. debug_navigation_enable_agent_paths = p_value;
  676. if (debug_dirty) {
  677. call_deferred("_emit_navigation_debug_changed_signal");
  678. }
  679. }
  680. bool NavigationServer3D::get_debug_navigation_enable_agent_paths() const {
  681. return debug_navigation_enable_agent_paths;
  682. }
  683. void NavigationServer3D::set_debug_navigation_enable_agent_paths_xray(const bool p_value) {
  684. debug_navigation_enable_agent_paths_xray = p_value;
  685. if (debug_navigation_agent_path_line_material.is_valid()) {
  686. debug_navigation_agent_path_line_material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, debug_navigation_enable_agent_paths_xray);
  687. }
  688. if (debug_navigation_agent_path_point_material.is_valid()) {
  689. debug_navigation_agent_path_point_material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, debug_navigation_enable_agent_paths_xray);
  690. }
  691. }
  692. bool NavigationServer3D::get_debug_navigation_enable_agent_paths_xray() const {
  693. return debug_navigation_enable_agent_paths_xray;
  694. }
  695. void NavigationServer3D::set_debug_navigation_enabled(bool p_enabled) {
  696. debug_navigation_enabled = p_enabled;
  697. navigation_debug_dirty = true;
  698. call_deferred("_emit_navigation_debug_changed_signal");
  699. }
  700. bool NavigationServer3D::get_debug_navigation_enabled() const {
  701. return debug_navigation_enabled;
  702. }
  703. void NavigationServer3D::set_debug_avoidance_enabled(bool p_enabled) {
  704. debug_avoidance_enabled = p_enabled;
  705. avoidance_debug_dirty = true;
  706. call_deferred("_emit_avoidance_debug_changed_signal");
  707. }
  708. bool NavigationServer3D::get_debug_avoidance_enabled() const {
  709. return debug_avoidance_enabled;
  710. }
  711. #endif // DEBUG_ENABLED
  712. void NavigationServer3D::query_path(const Ref<NavigationPathQueryParameters3D> &p_query_parameters, Ref<NavigationPathQueryResult3D> p_query_result) const {
  713. ERR_FAIL_COND(!p_query_parameters.is_valid());
  714. ERR_FAIL_COND(!p_query_result.is_valid());
  715. const NavigationUtilities::PathQueryResult _query_result = _query_path(p_query_parameters->get_parameters());
  716. p_query_result->set_path(_query_result.path);
  717. p_query_result->set_path_types(_query_result.path_types);
  718. p_query_result->set_path_rids(_query_result.path_rids);
  719. p_query_result->set_path_owner_ids(_query_result.path_owner_ids);
  720. }
  721. ///////////////////////////////////////////////////////
  722. NavigationServer3DCallback NavigationServer3DManager::create_callback = nullptr;
  723. void NavigationServer3DManager::set_default_server(NavigationServer3DCallback p_callback) {
  724. create_callback = p_callback;
  725. }
  726. NavigationServer3D *NavigationServer3DManager::new_default_server() {
  727. if (create_callback == nullptr) {
  728. return nullptr;
  729. }
  730. return create_callback();
  731. }