navigation_server_3d.cpp 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917
  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_enabled", "region", "enabled"), &NavigationServer3D::region_set_enabled);
  63. ClassDB::bind_method(D_METHOD("region_get_enabled", "region"), &NavigationServer3D::region_get_enabled);
  64. ClassDB::bind_method(D_METHOD("region_set_use_edge_connections", "region", "enabled"), &NavigationServer3D::region_set_use_edge_connections);
  65. ClassDB::bind_method(D_METHOD("region_get_use_edge_connections", "region"), &NavigationServer3D::region_get_use_edge_connections);
  66. ClassDB::bind_method(D_METHOD("region_set_enter_cost", "region", "enter_cost"), &NavigationServer3D::region_set_enter_cost);
  67. ClassDB::bind_method(D_METHOD("region_get_enter_cost", "region"), &NavigationServer3D::region_get_enter_cost);
  68. ClassDB::bind_method(D_METHOD("region_set_travel_cost", "region", "travel_cost"), &NavigationServer3D::region_set_travel_cost);
  69. ClassDB::bind_method(D_METHOD("region_get_travel_cost", "region"), &NavigationServer3D::region_get_travel_cost);
  70. ClassDB::bind_method(D_METHOD("region_set_owner_id", "region", "owner_id"), &NavigationServer3D::region_set_owner_id);
  71. ClassDB::bind_method(D_METHOD("region_get_owner_id", "region"), &NavigationServer3D::region_get_owner_id);
  72. ClassDB::bind_method(D_METHOD("region_owns_point", "region", "point"), &NavigationServer3D::region_owns_point);
  73. ClassDB::bind_method(D_METHOD("region_set_map", "region", "map"), &NavigationServer3D::region_set_map);
  74. ClassDB::bind_method(D_METHOD("region_get_map", "region"), &NavigationServer3D::region_get_map);
  75. ClassDB::bind_method(D_METHOD("region_set_navigation_layers", "region", "navigation_layers"), &NavigationServer3D::region_set_navigation_layers);
  76. ClassDB::bind_method(D_METHOD("region_get_navigation_layers", "region"), &NavigationServer3D::region_get_navigation_layers);
  77. ClassDB::bind_method(D_METHOD("region_set_transform", "region", "transform"), &NavigationServer3D::region_set_transform);
  78. ClassDB::bind_method(D_METHOD("region_set_navigation_mesh", "region", "navigation_mesh"), &NavigationServer3D::region_set_navigation_mesh);
  79. #ifndef DISABLE_DEPRECATED
  80. ClassDB::bind_method(D_METHOD("region_bake_navigation_mesh", "navigation_mesh", "root_node"), &NavigationServer3D::region_bake_navigation_mesh);
  81. #endif // DISABLE_DEPRECATED
  82. ClassDB::bind_method(D_METHOD("region_get_connections_count", "region"), &NavigationServer3D::region_get_connections_count);
  83. ClassDB::bind_method(D_METHOD("region_get_connection_pathway_start", "region", "connection"), &NavigationServer3D::region_get_connection_pathway_start);
  84. ClassDB::bind_method(D_METHOD("region_get_connection_pathway_end", "region", "connection"), &NavigationServer3D::region_get_connection_pathway_end);
  85. ClassDB::bind_method(D_METHOD("link_create"), &NavigationServer3D::link_create);
  86. ClassDB::bind_method(D_METHOD("link_set_map", "link", "map"), &NavigationServer3D::link_set_map);
  87. ClassDB::bind_method(D_METHOD("link_get_map", "link"), &NavigationServer3D::link_get_map);
  88. ClassDB::bind_method(D_METHOD("link_set_enabled", "link", "enabled"), &NavigationServer3D::link_set_enabled);
  89. ClassDB::bind_method(D_METHOD("link_get_enabled", "link"), &NavigationServer3D::link_get_enabled);
  90. ClassDB::bind_method(D_METHOD("link_set_bidirectional", "link", "bidirectional"), &NavigationServer3D::link_set_bidirectional);
  91. ClassDB::bind_method(D_METHOD("link_is_bidirectional", "link"), &NavigationServer3D::link_is_bidirectional);
  92. ClassDB::bind_method(D_METHOD("link_set_navigation_layers", "link", "navigation_layers"), &NavigationServer3D::link_set_navigation_layers);
  93. ClassDB::bind_method(D_METHOD("link_get_navigation_layers", "link"), &NavigationServer3D::link_get_navigation_layers);
  94. ClassDB::bind_method(D_METHOD("link_set_start_position", "link", "position"), &NavigationServer3D::link_set_start_position);
  95. ClassDB::bind_method(D_METHOD("link_get_start_position", "link"), &NavigationServer3D::link_get_start_position);
  96. ClassDB::bind_method(D_METHOD("link_set_end_position", "link", "position"), &NavigationServer3D::link_set_end_position);
  97. ClassDB::bind_method(D_METHOD("link_get_end_position", "link"), &NavigationServer3D::link_get_end_position);
  98. ClassDB::bind_method(D_METHOD("link_set_enter_cost", "link", "enter_cost"), &NavigationServer3D::link_set_enter_cost);
  99. ClassDB::bind_method(D_METHOD("link_get_enter_cost", "link"), &NavigationServer3D::link_get_enter_cost);
  100. ClassDB::bind_method(D_METHOD("link_set_travel_cost", "link", "travel_cost"), &NavigationServer3D::link_set_travel_cost);
  101. ClassDB::bind_method(D_METHOD("link_get_travel_cost", "link"), &NavigationServer3D::link_get_travel_cost);
  102. ClassDB::bind_method(D_METHOD("link_set_owner_id", "link", "owner_id"), &NavigationServer3D::link_set_owner_id);
  103. ClassDB::bind_method(D_METHOD("link_get_owner_id", "link"), &NavigationServer3D::link_get_owner_id);
  104. ClassDB::bind_method(D_METHOD("agent_create"), &NavigationServer3D::agent_create);
  105. ClassDB::bind_method(D_METHOD("agent_set_avoidance_enabled", "agent", "enabled"), &NavigationServer3D::agent_set_avoidance_enabled);
  106. ClassDB::bind_method(D_METHOD("agent_get_avoidance_enabled", "agent"), &NavigationServer3D::agent_get_avoidance_enabled);
  107. ClassDB::bind_method(D_METHOD("agent_set_use_3d_avoidance", "agent", "enabled"), &NavigationServer3D::agent_set_use_3d_avoidance);
  108. ClassDB::bind_method(D_METHOD("agent_get_use_3d_avoidance", "agent"), &NavigationServer3D::agent_get_use_3d_avoidance);
  109. ClassDB::bind_method(D_METHOD("agent_set_map", "agent", "map"), &NavigationServer3D::agent_set_map);
  110. ClassDB::bind_method(D_METHOD("agent_get_map", "agent"), &NavigationServer3D::agent_get_map);
  111. ClassDB::bind_method(D_METHOD("agent_set_paused", "agent", "paused"), &NavigationServer3D::agent_set_paused);
  112. ClassDB::bind_method(D_METHOD("agent_get_paused", "agent"), &NavigationServer3D::agent_get_paused);
  113. ClassDB::bind_method(D_METHOD("agent_set_neighbor_distance", "agent", "distance"), &NavigationServer3D::agent_set_neighbor_distance);
  114. ClassDB::bind_method(D_METHOD("agent_set_max_neighbors", "agent", "count"), &NavigationServer3D::agent_set_max_neighbors);
  115. ClassDB::bind_method(D_METHOD("agent_set_time_horizon_agents", "agent", "time_horizon"), &NavigationServer3D::agent_set_time_horizon_agents);
  116. ClassDB::bind_method(D_METHOD("agent_set_time_horizon_obstacles", "agent", "time_horizon"), &NavigationServer3D::agent_set_time_horizon_obstacles);
  117. ClassDB::bind_method(D_METHOD("agent_set_radius", "agent", "radius"), &NavigationServer3D::agent_set_radius);
  118. ClassDB::bind_method(D_METHOD("agent_set_height", "agent", "height"), &NavigationServer3D::agent_set_height);
  119. ClassDB::bind_method(D_METHOD("agent_set_max_speed", "agent", "max_speed"), &NavigationServer3D::agent_set_max_speed);
  120. ClassDB::bind_method(D_METHOD("agent_set_velocity_forced", "agent", "velocity"), &NavigationServer3D::agent_set_velocity_forced);
  121. ClassDB::bind_method(D_METHOD("agent_set_velocity", "agent", "velocity"), &NavigationServer3D::agent_set_velocity);
  122. ClassDB::bind_method(D_METHOD("agent_set_position", "agent", "position"), &NavigationServer3D::agent_set_position);
  123. ClassDB::bind_method(D_METHOD("agent_is_map_changed", "agent"), &NavigationServer3D::agent_is_map_changed);
  124. ClassDB::bind_method(D_METHOD("agent_set_avoidance_callback", "agent", "callback"), &NavigationServer3D::agent_set_avoidance_callback);
  125. ClassDB::bind_method(D_METHOD("agent_set_avoidance_layers", "agent", "layers"), &NavigationServer3D::agent_set_avoidance_layers);
  126. ClassDB::bind_method(D_METHOD("agent_set_avoidance_mask", "agent", "mask"), &NavigationServer3D::agent_set_avoidance_mask);
  127. ClassDB::bind_method(D_METHOD("agent_set_avoidance_priority", "agent", "priority"), &NavigationServer3D::agent_set_avoidance_priority);
  128. ClassDB::bind_method(D_METHOD("obstacle_create"), &NavigationServer3D::obstacle_create);
  129. ClassDB::bind_method(D_METHOD("obstacle_set_avoidance_enabled", "obstacle", "enabled"), &NavigationServer3D::obstacle_set_avoidance_enabled);
  130. ClassDB::bind_method(D_METHOD("obstacle_get_avoidance_enabled", "obstacle"), &NavigationServer3D::obstacle_get_avoidance_enabled);
  131. ClassDB::bind_method(D_METHOD("obstacle_set_use_3d_avoidance", "obstacle", "enabled"), &NavigationServer3D::obstacle_set_use_3d_avoidance);
  132. ClassDB::bind_method(D_METHOD("obstacle_get_use_3d_avoidance", "obstacle"), &NavigationServer3D::obstacle_get_use_3d_avoidance);
  133. ClassDB::bind_method(D_METHOD("obstacle_set_map", "obstacle", "map"), &NavigationServer3D::obstacle_set_map);
  134. ClassDB::bind_method(D_METHOD("obstacle_get_map", "obstacle"), &NavigationServer3D::obstacle_get_map);
  135. ClassDB::bind_method(D_METHOD("obstacle_set_paused", "obstacle", "paused"), &NavigationServer3D::obstacle_set_paused);
  136. ClassDB::bind_method(D_METHOD("obstacle_get_paused", "obstacle"), &NavigationServer3D::obstacle_get_paused);
  137. ClassDB::bind_method(D_METHOD("obstacle_set_radius", "obstacle", "radius"), &NavigationServer3D::obstacle_set_radius);
  138. ClassDB::bind_method(D_METHOD("obstacle_set_height", "obstacle", "height"), &NavigationServer3D::obstacle_set_height);
  139. ClassDB::bind_method(D_METHOD("obstacle_set_velocity", "obstacle", "velocity"), &NavigationServer3D::obstacle_set_velocity);
  140. ClassDB::bind_method(D_METHOD("obstacle_set_position", "obstacle", "position"), &NavigationServer3D::obstacle_set_position);
  141. ClassDB::bind_method(D_METHOD("obstacle_set_vertices", "obstacle", "vertices"), &NavigationServer3D::obstacle_set_vertices);
  142. ClassDB::bind_method(D_METHOD("obstacle_set_avoidance_layers", "obstacle", "layers"), &NavigationServer3D::obstacle_set_avoidance_layers);
  143. ClassDB::bind_method(D_METHOD("parse_source_geometry_data", "navigation_mesh", "source_geometry_data", "root_node", "callback"), &NavigationServer3D::parse_source_geometry_data, DEFVAL(Callable()));
  144. ClassDB::bind_method(D_METHOD("bake_from_source_geometry_data", "navigation_mesh", "source_geometry_data", "callback"), &NavigationServer3D::bake_from_source_geometry_data, DEFVAL(Callable()));
  145. ClassDB::bind_method(D_METHOD("bake_from_source_geometry_data_async", "navigation_mesh", "source_geometry_data", "callback"), &NavigationServer3D::bake_from_source_geometry_data_async, DEFVAL(Callable()));
  146. ClassDB::bind_method(D_METHOD("free_rid", "rid"), &NavigationServer3D::free);
  147. ClassDB::bind_method(D_METHOD("set_active", "active"), &NavigationServer3D::set_active);
  148. ClassDB::bind_method(D_METHOD("set_debug_enabled", "enabled"), &NavigationServer3D::set_debug_enabled);
  149. ClassDB::bind_method(D_METHOD("get_debug_enabled"), &NavigationServer3D::get_debug_enabled);
  150. ADD_SIGNAL(MethodInfo("map_changed", PropertyInfo(Variant::RID, "map")));
  151. ADD_SIGNAL(MethodInfo("navigation_debug_changed"));
  152. ADD_SIGNAL(MethodInfo("avoidance_debug_changed"));
  153. ClassDB::bind_method(D_METHOD("get_process_info", "process_info"), &NavigationServer3D::get_process_info);
  154. BIND_ENUM_CONSTANT(INFO_ACTIVE_MAPS);
  155. BIND_ENUM_CONSTANT(INFO_REGION_COUNT);
  156. BIND_ENUM_CONSTANT(INFO_AGENT_COUNT);
  157. BIND_ENUM_CONSTANT(INFO_LINK_COUNT);
  158. BIND_ENUM_CONSTANT(INFO_POLYGON_COUNT);
  159. BIND_ENUM_CONSTANT(INFO_EDGE_COUNT);
  160. BIND_ENUM_CONSTANT(INFO_EDGE_MERGE_COUNT);
  161. BIND_ENUM_CONSTANT(INFO_EDGE_CONNECTION_COUNT);
  162. BIND_ENUM_CONSTANT(INFO_EDGE_FREE_COUNT);
  163. }
  164. NavigationServer3D *NavigationServer3D::get_singleton() {
  165. return singleton;
  166. }
  167. NavigationServer3D::NavigationServer3D() {
  168. ERR_FAIL_COND(singleton != nullptr);
  169. singleton = this;
  170. GLOBAL_DEF_BASIC("navigation/2d/default_cell_size", 1.0);
  171. GLOBAL_DEF("navigation/2d/use_edge_connections", true);
  172. GLOBAL_DEF_BASIC("navigation/2d/default_edge_connection_margin", 1.0);
  173. GLOBAL_DEF_BASIC("navigation/2d/default_link_connection_radius", 4.0);
  174. GLOBAL_DEF_BASIC("navigation/3d/default_cell_size", 0.25);
  175. GLOBAL_DEF_BASIC("navigation/3d/default_cell_height", 0.25);
  176. GLOBAL_DEF("navigation/3d/default_up", Vector3(0, 1, 0));
  177. GLOBAL_DEF("navigation/3d/use_edge_connections", true);
  178. GLOBAL_DEF_BASIC("navigation/3d/default_edge_connection_margin", 0.25);
  179. GLOBAL_DEF_BASIC("navigation/3d/default_link_connection_radius", 1.0);
  180. GLOBAL_DEF("navigation/avoidance/thread_model/avoidance_use_multiple_threads", true);
  181. GLOBAL_DEF("navigation/avoidance/thread_model/avoidance_use_high_priority_threads", true);
  182. GLOBAL_DEF("navigation/baking/thread_model/baking_use_multiple_threads", true);
  183. GLOBAL_DEF("navigation/baking/thread_model/baking_use_high_priority_threads", true);
  184. #ifdef DEBUG_ENABLED
  185. debug_navigation_edge_connection_color = GLOBAL_DEF("debug/shapes/navigation/edge_connection_color", Color(1.0, 0.0, 1.0, 1.0));
  186. debug_navigation_geometry_edge_color = GLOBAL_DEF("debug/shapes/navigation/geometry_edge_color", Color(0.5, 1.0, 1.0, 1.0));
  187. debug_navigation_geometry_face_color = GLOBAL_DEF("debug/shapes/navigation/geometry_face_color", Color(0.5, 1.0, 1.0, 0.4));
  188. debug_navigation_geometry_edge_disabled_color = GLOBAL_DEF("debug/shapes/navigation/geometry_edge_disabled_color", Color(0.5, 0.5, 0.5, 1.0));
  189. debug_navigation_geometry_face_disabled_color = GLOBAL_DEF("debug/shapes/navigation/geometry_face_disabled_color", Color(0.5, 0.5, 0.5, 0.4));
  190. debug_navigation_link_connection_color = GLOBAL_DEF("debug/shapes/navigation/link_connection_color", Color(1.0, 0.5, 1.0, 1.0));
  191. debug_navigation_link_connection_disabled_color = GLOBAL_DEF("debug/shapes/navigation/link_connection_disabled_color", Color(0.5, 0.5, 0.5, 1.0));
  192. debug_navigation_agent_path_color = GLOBAL_DEF("debug/shapes/navigation/agent_path_color", Color(1.0, 0.0, 0.0, 1.0));
  193. debug_navigation_enable_edge_connections = GLOBAL_DEF("debug/shapes/navigation/enable_edge_connections", true);
  194. debug_navigation_enable_edge_connections_xray = GLOBAL_DEF("debug/shapes/navigation/enable_edge_connections_xray", true);
  195. debug_navigation_enable_edge_lines = GLOBAL_DEF("debug/shapes/navigation/enable_edge_lines", true);
  196. debug_navigation_enable_edge_lines_xray = GLOBAL_DEF("debug/shapes/navigation/enable_edge_lines_xray", true);
  197. debug_navigation_enable_geometry_face_random_color = GLOBAL_DEF("debug/shapes/navigation/enable_geometry_face_random_color", true);
  198. debug_navigation_enable_link_connections = GLOBAL_DEF("debug/shapes/navigation/enable_link_connections", true);
  199. debug_navigation_enable_link_connections_xray = GLOBAL_DEF("debug/shapes/navigation/enable_link_connections_xray", true);
  200. debug_navigation_enable_agent_paths = GLOBAL_DEF("debug/shapes/navigation/enable_agent_paths", true);
  201. debug_navigation_enable_agent_paths_xray = GLOBAL_DEF("debug/shapes/navigation/enable_agent_paths_xray", true);
  202. debug_navigation_agent_path_point_size = GLOBAL_DEF("debug/shapes/navigation/agent_path_point_size", 4.0);
  203. debug_navigation_avoidance_agents_radius_color = GLOBAL_DEF("debug/shapes/avoidance/agents_radius_color", Color(1.0, 1.0, 0.0, 0.25));
  204. debug_navigation_avoidance_obstacles_radius_color = GLOBAL_DEF("debug/shapes/avoidance/obstacles_radius_color", Color(1.0, 0.5, 0.0, 0.25));
  205. 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));
  206. 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));
  207. 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));
  208. 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));
  209. debug_navigation_avoidance_enable_agents_radius = GLOBAL_DEF("debug/shapes/avoidance/enable_agents_radius", true);
  210. debug_navigation_avoidance_enable_obstacles_radius = GLOBAL_DEF("debug/shapes/avoidance/enable_obstacles_radius", true);
  211. debug_navigation_avoidance_enable_obstacles_static = GLOBAL_DEF("debug/shapes/avoidance/enable_obstacles_static", true);
  212. if (Engine::get_singleton()->is_editor_hint()) {
  213. // enable NavigationServer3D when in Editor or else navigation mesh edge connections are invisible
  214. // on runtime tests SceneTree has "Visible Navigation" set and main iteration takes care of this
  215. set_debug_enabled(true);
  216. set_debug_navigation_enabled(true);
  217. set_debug_avoidance_enabled(true);
  218. }
  219. #endif // DEBUG_ENABLED
  220. }
  221. NavigationServer3D::~NavigationServer3D() {
  222. singleton = nullptr;
  223. }
  224. void NavigationServer3D::set_debug_enabled(bool p_enabled) {
  225. #ifdef DEBUG_ENABLED
  226. if (debug_enabled != p_enabled) {
  227. debug_dirty = true;
  228. }
  229. debug_enabled = p_enabled;
  230. if (debug_dirty) {
  231. call_deferred("_emit_navigation_debug_changed_signal");
  232. }
  233. #endif // DEBUG_ENABLED
  234. }
  235. bool NavigationServer3D::get_debug_enabled() const {
  236. return debug_enabled;
  237. }
  238. #ifdef DEBUG_ENABLED
  239. void NavigationServer3D::_emit_navigation_debug_changed_signal() {
  240. if (navigation_debug_dirty) {
  241. navigation_debug_dirty = false;
  242. emit_signal(SNAME("navigation_debug_changed"));
  243. }
  244. }
  245. void NavigationServer3D::_emit_avoidance_debug_changed_signal() {
  246. if (avoidance_debug_dirty) {
  247. avoidance_debug_dirty = false;
  248. emit_signal(SNAME("avoidance_debug_changed"));
  249. }
  250. }
  251. #endif // DEBUG_ENABLED
  252. #ifdef DEBUG_ENABLED
  253. Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_geometry_face_material() {
  254. if (debug_navigation_geometry_face_material.is_valid()) {
  255. return debug_navigation_geometry_face_material;
  256. }
  257. bool enabled_geometry_face_random_color = get_debug_navigation_enable_geometry_face_random_color();
  258. Ref<StandardMaterial3D> face_material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
  259. face_material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
  260. face_material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
  261. face_material->set_albedo(get_debug_navigation_geometry_face_color());
  262. face_material->set_cull_mode(StandardMaterial3D::CULL_DISABLED);
  263. face_material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
  264. if (enabled_geometry_face_random_color) {
  265. face_material->set_flag(StandardMaterial3D::FLAG_SRGB_VERTEX_COLOR, true);
  266. face_material->set_flag(StandardMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true);
  267. }
  268. debug_navigation_geometry_face_material = face_material;
  269. return debug_navigation_geometry_face_material;
  270. }
  271. Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_geometry_edge_material() {
  272. if (debug_navigation_geometry_edge_material.is_valid()) {
  273. return debug_navigation_geometry_edge_material;
  274. }
  275. bool enabled_edge_lines_xray = get_debug_navigation_enable_edge_lines_xray();
  276. Ref<StandardMaterial3D> line_material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
  277. line_material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
  278. line_material->set_albedo(get_debug_navigation_geometry_edge_color());
  279. line_material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
  280. if (enabled_edge_lines_xray) {
  281. line_material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true);
  282. }
  283. debug_navigation_geometry_edge_material = line_material;
  284. return debug_navigation_geometry_edge_material;
  285. }
  286. Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_geometry_face_disabled_material() {
  287. if (debug_navigation_geometry_face_disabled_material.is_valid()) {
  288. return debug_navigation_geometry_face_disabled_material;
  289. }
  290. Ref<StandardMaterial3D> face_disabled_material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
  291. face_disabled_material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
  292. face_disabled_material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
  293. face_disabled_material->set_albedo(get_debug_navigation_geometry_face_disabled_color());
  294. face_disabled_material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
  295. debug_navigation_geometry_face_disabled_material = face_disabled_material;
  296. return debug_navigation_geometry_face_disabled_material;
  297. }
  298. Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_geometry_edge_disabled_material() {
  299. if (debug_navigation_geometry_edge_disabled_material.is_valid()) {
  300. return debug_navigation_geometry_edge_disabled_material;
  301. }
  302. bool enabled_edge_lines_xray = get_debug_navigation_enable_edge_lines_xray();
  303. Ref<StandardMaterial3D> line_disabled_material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
  304. line_disabled_material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
  305. line_disabled_material->set_albedo(get_debug_navigation_geometry_edge_disabled_color());
  306. line_disabled_material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
  307. if (enabled_edge_lines_xray) {
  308. line_disabled_material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true);
  309. }
  310. debug_navigation_geometry_edge_disabled_material = line_disabled_material;
  311. return debug_navigation_geometry_edge_disabled_material;
  312. }
  313. Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_edge_connections_material() {
  314. if (debug_navigation_edge_connections_material.is_valid()) {
  315. return debug_navigation_edge_connections_material;
  316. }
  317. bool enabled_edge_connections_xray = get_debug_navigation_enable_edge_connections_xray();
  318. Ref<StandardMaterial3D> edge_connections_material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
  319. edge_connections_material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
  320. edge_connections_material->set_albedo(get_debug_navigation_edge_connection_color());
  321. edge_connections_material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
  322. if (enabled_edge_connections_xray) {
  323. edge_connections_material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true);
  324. }
  325. edge_connections_material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MAX - 2);
  326. debug_navigation_edge_connections_material = edge_connections_material;
  327. return debug_navigation_edge_connections_material;
  328. }
  329. Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_link_connections_material() {
  330. if (debug_navigation_link_connections_material.is_valid()) {
  331. return debug_navigation_link_connections_material;
  332. }
  333. Ref<StandardMaterial3D> material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
  334. material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
  335. material->set_albedo(debug_navigation_link_connection_color);
  336. material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
  337. if (debug_navigation_enable_link_connections_xray) {
  338. material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true);
  339. }
  340. material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MAX - 2);
  341. debug_navigation_link_connections_material = material;
  342. return debug_navigation_link_connections_material;
  343. }
  344. Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_link_connections_disabled_material() {
  345. if (debug_navigation_link_connections_disabled_material.is_valid()) {
  346. return debug_navigation_link_connections_disabled_material;
  347. }
  348. Ref<StandardMaterial3D> material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
  349. material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
  350. material->set_albedo(debug_navigation_link_connection_disabled_color);
  351. material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
  352. if (debug_navigation_enable_link_connections_xray) {
  353. material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true);
  354. }
  355. material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MAX - 2);
  356. debug_navigation_link_connections_disabled_material = material;
  357. return debug_navigation_link_connections_disabled_material;
  358. }
  359. Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_agent_path_line_material() {
  360. if (debug_navigation_agent_path_line_material.is_valid()) {
  361. return debug_navigation_agent_path_line_material;
  362. }
  363. Ref<StandardMaterial3D> material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
  364. material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
  365. material->set_albedo(debug_navigation_agent_path_color);
  366. material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
  367. if (debug_navigation_enable_agent_paths_xray) {
  368. material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true);
  369. }
  370. material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MAX - 2);
  371. debug_navigation_agent_path_line_material = material;
  372. return debug_navigation_agent_path_line_material;
  373. }
  374. Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_agent_path_point_material() {
  375. if (debug_navigation_agent_path_point_material.is_valid()) {
  376. return debug_navigation_agent_path_point_material;
  377. }
  378. Ref<StandardMaterial3D> material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
  379. material->set_albedo(debug_navigation_agent_path_color);
  380. material->set_flag(StandardMaterial3D::FLAG_USE_POINT_SIZE, true);
  381. material->set_point_size(debug_navigation_agent_path_point_size);
  382. material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
  383. if (debug_navigation_enable_agent_paths_xray) {
  384. material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true);
  385. }
  386. material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MAX - 2);
  387. debug_navigation_agent_path_point_material = material;
  388. return debug_navigation_agent_path_point_material;
  389. }
  390. Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_avoidance_agents_radius_material() {
  391. if (debug_navigation_avoidance_agents_radius_material.is_valid()) {
  392. return debug_navigation_avoidance_agents_radius_material;
  393. }
  394. Ref<StandardMaterial3D> material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
  395. material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
  396. material->set_cull_mode(StandardMaterial3D::CULL_DISABLED);
  397. material->set_albedo(debug_navigation_avoidance_agents_radius_color);
  398. material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MIN + 2);
  399. debug_navigation_avoidance_agents_radius_material = material;
  400. return debug_navigation_avoidance_agents_radius_material;
  401. }
  402. Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_avoidance_obstacles_radius_material() {
  403. if (debug_navigation_avoidance_obstacles_radius_material.is_valid()) {
  404. return debug_navigation_avoidance_obstacles_radius_material;
  405. }
  406. Ref<StandardMaterial3D> material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
  407. material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
  408. material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
  409. material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
  410. material->set_cull_mode(StandardMaterial3D::CULL_DISABLED);
  411. material->set_albedo(debug_navigation_avoidance_obstacles_radius_color);
  412. material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MIN + 2);
  413. debug_navigation_avoidance_obstacles_radius_material = material;
  414. return debug_navigation_avoidance_obstacles_radius_material;
  415. }
  416. Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_avoidance_static_obstacle_pushin_face_material() {
  417. if (debug_navigation_avoidance_static_obstacle_pushin_face_material.is_valid()) {
  418. return debug_navigation_avoidance_static_obstacle_pushin_face_material;
  419. }
  420. Ref<StandardMaterial3D> material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
  421. material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
  422. material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
  423. material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
  424. material->set_cull_mode(StandardMaterial3D::CULL_DISABLED);
  425. material->set_albedo(debug_navigation_avoidance_static_obstacle_pushin_face_color);
  426. material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MIN + 2);
  427. debug_navigation_avoidance_static_obstacle_pushin_face_material = material;
  428. return debug_navigation_avoidance_static_obstacle_pushin_face_material;
  429. }
  430. Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_avoidance_static_obstacle_pushout_face_material() {
  431. if (debug_navigation_avoidance_static_obstacle_pushout_face_material.is_valid()) {
  432. return debug_navigation_avoidance_static_obstacle_pushout_face_material;
  433. }
  434. Ref<StandardMaterial3D> material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
  435. material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
  436. material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
  437. material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
  438. material->set_cull_mode(StandardMaterial3D::CULL_DISABLED);
  439. material->set_albedo(debug_navigation_avoidance_static_obstacle_pushout_face_color);
  440. material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MIN + 2);
  441. debug_navigation_avoidance_static_obstacle_pushout_face_material = material;
  442. return debug_navigation_avoidance_static_obstacle_pushout_face_material;
  443. }
  444. Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_avoidance_static_obstacle_pushin_edge_material() {
  445. if (debug_navigation_avoidance_static_obstacle_pushin_edge_material.is_valid()) {
  446. return debug_navigation_avoidance_static_obstacle_pushin_edge_material;
  447. }
  448. Ref<StandardMaterial3D> material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
  449. material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
  450. material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
  451. //material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
  452. //material->set_cull_mode(StandardMaterial3D::CULL_DISABLED);
  453. material->set_albedo(debug_navigation_avoidance_static_obstacle_pushin_edge_color);
  454. //material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MIN + 2);
  455. material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true);
  456. debug_navigation_avoidance_static_obstacle_pushin_edge_material = material;
  457. return debug_navigation_avoidance_static_obstacle_pushin_edge_material;
  458. }
  459. Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_avoidance_static_obstacle_pushout_edge_material() {
  460. if (debug_navigation_avoidance_static_obstacle_pushout_edge_material.is_valid()) {
  461. return debug_navigation_avoidance_static_obstacle_pushout_edge_material;
  462. }
  463. Ref<StandardMaterial3D> material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
  464. material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
  465. material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
  466. ///material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
  467. //material->set_cull_mode(StandardMaterial3D::CULL_DISABLED);
  468. material->set_albedo(debug_navigation_avoidance_static_obstacle_pushout_edge_color);
  469. //material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MIN + 2);
  470. material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true);
  471. debug_navigation_avoidance_static_obstacle_pushout_edge_material = material;
  472. return debug_navigation_avoidance_static_obstacle_pushout_edge_material;
  473. }
  474. void NavigationServer3D::set_debug_navigation_edge_connection_color(const Color &p_color) {
  475. debug_navigation_edge_connection_color = p_color;
  476. if (debug_navigation_edge_connections_material.is_valid()) {
  477. debug_navigation_edge_connections_material->set_albedo(debug_navigation_edge_connection_color);
  478. }
  479. }
  480. Color NavigationServer3D::get_debug_navigation_edge_connection_color() const {
  481. return debug_navigation_edge_connection_color;
  482. }
  483. void NavigationServer3D::set_debug_navigation_geometry_edge_color(const Color &p_color) {
  484. debug_navigation_geometry_edge_color = p_color;
  485. if (debug_navigation_geometry_edge_material.is_valid()) {
  486. debug_navigation_geometry_edge_material->set_albedo(debug_navigation_geometry_edge_color);
  487. }
  488. }
  489. Color NavigationServer3D::get_debug_navigation_geometry_edge_color() const {
  490. return debug_navigation_geometry_edge_color;
  491. }
  492. void NavigationServer3D::set_debug_navigation_geometry_face_color(const Color &p_color) {
  493. debug_navigation_geometry_face_color = p_color;
  494. if (debug_navigation_geometry_face_material.is_valid()) {
  495. debug_navigation_geometry_face_material->set_albedo(debug_navigation_geometry_face_color);
  496. }
  497. }
  498. Color NavigationServer3D::get_debug_navigation_geometry_face_color() const {
  499. return debug_navigation_geometry_face_color;
  500. }
  501. void NavigationServer3D::set_debug_navigation_geometry_edge_disabled_color(const Color &p_color) {
  502. debug_navigation_geometry_edge_disabled_color = p_color;
  503. if (debug_navigation_geometry_edge_disabled_material.is_valid()) {
  504. debug_navigation_geometry_edge_disabled_material->set_albedo(debug_navigation_geometry_edge_disabled_color);
  505. }
  506. }
  507. Color NavigationServer3D::get_debug_navigation_geometry_edge_disabled_color() const {
  508. return debug_navigation_geometry_edge_disabled_color;
  509. }
  510. void NavigationServer3D::set_debug_navigation_geometry_face_disabled_color(const Color &p_color) {
  511. debug_navigation_geometry_face_disabled_color = p_color;
  512. if (debug_navigation_geometry_face_disabled_material.is_valid()) {
  513. debug_navigation_geometry_face_disabled_material->set_albedo(debug_navigation_geometry_face_disabled_color);
  514. }
  515. }
  516. Color NavigationServer3D::get_debug_navigation_geometry_face_disabled_color() const {
  517. return debug_navigation_geometry_face_disabled_color;
  518. }
  519. void NavigationServer3D::set_debug_navigation_link_connection_color(const Color &p_color) {
  520. debug_navigation_link_connection_color = p_color;
  521. if (debug_navigation_link_connections_material.is_valid()) {
  522. debug_navigation_link_connections_material->set_albedo(debug_navigation_link_connection_color);
  523. }
  524. }
  525. Color NavigationServer3D::get_debug_navigation_link_connection_color() const {
  526. return debug_navigation_link_connection_color;
  527. }
  528. void NavigationServer3D::set_debug_navigation_link_connection_disabled_color(const Color &p_color) {
  529. debug_navigation_link_connection_disabled_color = p_color;
  530. if (debug_navigation_link_connections_disabled_material.is_valid()) {
  531. debug_navigation_link_connections_disabled_material->set_albedo(debug_navigation_link_connection_disabled_color);
  532. }
  533. }
  534. Color NavigationServer3D::get_debug_navigation_link_connection_disabled_color() const {
  535. return debug_navigation_link_connection_disabled_color;
  536. }
  537. void NavigationServer3D::set_debug_navigation_agent_path_point_size(real_t p_point_size) {
  538. debug_navigation_agent_path_point_size = MAX(0.1, p_point_size);
  539. if (debug_navigation_agent_path_point_material.is_valid()) {
  540. debug_navigation_agent_path_point_material->set_point_size(debug_navigation_agent_path_point_size);
  541. }
  542. }
  543. real_t NavigationServer3D::get_debug_navigation_agent_path_point_size() const {
  544. return debug_navigation_agent_path_point_size;
  545. }
  546. void NavigationServer3D::set_debug_navigation_agent_path_color(const Color &p_color) {
  547. debug_navigation_agent_path_color = p_color;
  548. if (debug_navigation_agent_path_line_material.is_valid()) {
  549. debug_navigation_agent_path_line_material->set_albedo(debug_navigation_agent_path_color);
  550. }
  551. if (debug_navigation_agent_path_point_material.is_valid()) {
  552. debug_navigation_agent_path_point_material->set_albedo(debug_navigation_agent_path_color);
  553. }
  554. }
  555. Color NavigationServer3D::get_debug_navigation_agent_path_color() const {
  556. return debug_navigation_agent_path_color;
  557. }
  558. void NavigationServer3D::set_debug_navigation_enable_edge_connections(const bool p_value) {
  559. debug_navigation_enable_edge_connections = p_value;
  560. navigation_debug_dirty = true;
  561. call_deferred("_emit_navigation_debug_changed_signal");
  562. }
  563. bool NavigationServer3D::get_debug_navigation_enable_edge_connections() const {
  564. return debug_navigation_enable_edge_connections;
  565. }
  566. void NavigationServer3D::set_debug_navigation_enable_edge_connections_xray(const bool p_value) {
  567. debug_navigation_enable_edge_connections_xray = p_value;
  568. if (debug_navigation_edge_connections_material.is_valid()) {
  569. debug_navigation_edge_connections_material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, debug_navigation_enable_edge_connections_xray);
  570. }
  571. }
  572. bool NavigationServer3D::get_debug_navigation_enable_edge_connections_xray() const {
  573. return debug_navigation_enable_edge_connections_xray;
  574. }
  575. void NavigationServer3D::set_debug_navigation_enable_edge_lines(const bool p_value) {
  576. debug_navigation_enable_edge_lines = p_value;
  577. navigation_debug_dirty = true;
  578. call_deferred("_emit_navigation_debug_changed_signal");
  579. }
  580. bool NavigationServer3D::get_debug_navigation_enable_edge_lines() const {
  581. return debug_navigation_enable_edge_lines;
  582. }
  583. void NavigationServer3D::set_debug_navigation_enable_edge_lines_xray(const bool p_value) {
  584. debug_navigation_enable_edge_lines_xray = p_value;
  585. if (debug_navigation_geometry_edge_material.is_valid()) {
  586. debug_navigation_geometry_edge_material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, debug_navigation_enable_edge_lines_xray);
  587. }
  588. }
  589. bool NavigationServer3D::get_debug_navigation_enable_edge_lines_xray() const {
  590. return debug_navigation_enable_edge_lines_xray;
  591. }
  592. void NavigationServer3D::set_debug_navigation_enable_geometry_face_random_color(const bool p_value) {
  593. debug_navigation_enable_geometry_face_random_color = p_value;
  594. navigation_debug_dirty = true;
  595. call_deferred("_emit_navigation_debug_changed_signal");
  596. }
  597. bool NavigationServer3D::get_debug_navigation_enable_geometry_face_random_color() const {
  598. return debug_navigation_enable_geometry_face_random_color;
  599. }
  600. void NavigationServer3D::set_debug_navigation_enable_link_connections(const bool p_value) {
  601. debug_navigation_enable_link_connections = p_value;
  602. navigation_debug_dirty = true;
  603. call_deferred("_emit_navigation_debug_changed_signal");
  604. }
  605. bool NavigationServer3D::get_debug_navigation_enable_link_connections() const {
  606. return debug_navigation_enable_link_connections;
  607. }
  608. void NavigationServer3D::set_debug_navigation_enable_link_connections_xray(const bool p_value) {
  609. debug_navigation_enable_link_connections_xray = p_value;
  610. if (debug_navigation_link_connections_material.is_valid()) {
  611. debug_navigation_link_connections_material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, debug_navigation_enable_link_connections_xray);
  612. }
  613. }
  614. bool NavigationServer3D::get_debug_navigation_enable_link_connections_xray() const {
  615. return debug_navigation_enable_link_connections_xray;
  616. }
  617. void NavigationServer3D::set_debug_navigation_avoidance_enable_agents_radius(const bool p_value) {
  618. debug_navigation_avoidance_enable_agents_radius = p_value;
  619. avoidance_debug_dirty = true;
  620. call_deferred("_emit_avoidance_debug_changed_signal");
  621. }
  622. bool NavigationServer3D::get_debug_navigation_avoidance_enable_agents_radius() const {
  623. return debug_navigation_avoidance_enable_agents_radius;
  624. }
  625. void NavigationServer3D::set_debug_navigation_avoidance_enable_obstacles_radius(const bool p_value) {
  626. debug_navigation_avoidance_enable_obstacles_radius = p_value;
  627. avoidance_debug_dirty = true;
  628. call_deferred("_emit_avoidance_debug_changed_signal");
  629. }
  630. bool NavigationServer3D::get_debug_navigation_avoidance_enable_obstacles_radius() const {
  631. return debug_navigation_avoidance_enable_obstacles_radius;
  632. }
  633. void NavigationServer3D::set_debug_navigation_avoidance_enable_obstacles_static(const bool p_value) {
  634. debug_navigation_avoidance_enable_obstacles_static = p_value;
  635. avoidance_debug_dirty = true;
  636. call_deferred("_emit_avoidance_debug_changed_signal");
  637. }
  638. bool NavigationServer3D::get_debug_navigation_avoidance_enable_obstacles_static() const {
  639. return debug_navigation_avoidance_enable_obstacles_static;
  640. }
  641. void NavigationServer3D::set_debug_navigation_avoidance_agents_radius_color(const Color &p_color) {
  642. debug_navigation_avoidance_agents_radius_color = p_color;
  643. if (debug_navigation_avoidance_agents_radius_material.is_valid()) {
  644. debug_navigation_avoidance_agents_radius_material->set_albedo(debug_navigation_avoidance_agents_radius_color);
  645. }
  646. }
  647. Color NavigationServer3D::get_debug_navigation_avoidance_agents_radius_color() const {
  648. return debug_navigation_avoidance_agents_radius_color;
  649. }
  650. void NavigationServer3D::set_debug_navigation_avoidance_obstacles_radius_color(const Color &p_color) {
  651. debug_navigation_avoidance_obstacles_radius_color = p_color;
  652. if (debug_navigation_avoidance_obstacles_radius_material.is_valid()) {
  653. debug_navigation_avoidance_obstacles_radius_material->set_albedo(debug_navigation_avoidance_obstacles_radius_color);
  654. }
  655. }
  656. Color NavigationServer3D::get_debug_navigation_avoidance_obstacles_radius_color() const {
  657. return debug_navigation_avoidance_obstacles_radius_color;
  658. }
  659. void NavigationServer3D::set_debug_navigation_avoidance_static_obstacle_pushin_face_color(const Color &p_color) {
  660. debug_navigation_avoidance_static_obstacle_pushin_face_color = p_color;
  661. if (debug_navigation_avoidance_static_obstacle_pushin_face_material.is_valid()) {
  662. debug_navigation_avoidance_static_obstacle_pushin_face_material->set_albedo(debug_navigation_avoidance_static_obstacle_pushin_face_color);
  663. }
  664. }
  665. Color NavigationServer3D::get_debug_navigation_avoidance_static_obstacle_pushin_face_color() const {
  666. return debug_navigation_avoidance_static_obstacle_pushin_face_color;
  667. }
  668. void NavigationServer3D::set_debug_navigation_avoidance_static_obstacle_pushout_face_color(const Color &p_color) {
  669. debug_navigation_avoidance_static_obstacle_pushout_face_color = p_color;
  670. if (debug_navigation_avoidance_static_obstacle_pushout_face_material.is_valid()) {
  671. debug_navigation_avoidance_static_obstacle_pushout_face_material->set_albedo(debug_navigation_avoidance_static_obstacle_pushout_face_color);
  672. }
  673. }
  674. Color NavigationServer3D::get_debug_navigation_avoidance_static_obstacle_pushout_face_color() const {
  675. return debug_navigation_avoidance_static_obstacle_pushout_face_color;
  676. }
  677. void NavigationServer3D::set_debug_navigation_avoidance_static_obstacle_pushin_edge_color(const Color &p_color) {
  678. debug_navigation_avoidance_static_obstacle_pushin_edge_color = p_color;
  679. if (debug_navigation_avoidance_static_obstacle_pushin_edge_material.is_valid()) {
  680. debug_navigation_avoidance_static_obstacle_pushin_edge_material->set_albedo(debug_navigation_avoidance_static_obstacle_pushin_edge_color);
  681. }
  682. }
  683. Color NavigationServer3D::get_debug_navigation_avoidance_static_obstacle_pushin_edge_color() const {
  684. return debug_navigation_avoidance_static_obstacle_pushin_edge_color;
  685. }
  686. void NavigationServer3D::set_debug_navigation_avoidance_static_obstacle_pushout_edge_color(const Color &p_color) {
  687. debug_navigation_avoidance_static_obstacle_pushout_edge_color = p_color;
  688. if (debug_navigation_avoidance_static_obstacle_pushout_edge_material.is_valid()) {
  689. debug_navigation_avoidance_static_obstacle_pushout_edge_material->set_albedo(debug_navigation_avoidance_static_obstacle_pushout_edge_color);
  690. }
  691. }
  692. Color NavigationServer3D::get_debug_navigation_avoidance_static_obstacle_pushout_edge_color() const {
  693. return debug_navigation_avoidance_static_obstacle_pushout_edge_color;
  694. }
  695. void NavigationServer3D::set_debug_navigation_enable_agent_paths(const bool p_value) {
  696. if (debug_navigation_enable_agent_paths != p_value) {
  697. debug_dirty = true;
  698. }
  699. debug_navigation_enable_agent_paths = p_value;
  700. if (debug_dirty) {
  701. call_deferred("_emit_navigation_debug_changed_signal");
  702. }
  703. }
  704. bool NavigationServer3D::get_debug_navigation_enable_agent_paths() const {
  705. return debug_navigation_enable_agent_paths;
  706. }
  707. void NavigationServer3D::set_debug_navigation_enable_agent_paths_xray(const bool p_value) {
  708. debug_navigation_enable_agent_paths_xray = p_value;
  709. if (debug_navigation_agent_path_line_material.is_valid()) {
  710. debug_navigation_agent_path_line_material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, debug_navigation_enable_agent_paths_xray);
  711. }
  712. if (debug_navigation_agent_path_point_material.is_valid()) {
  713. debug_navigation_agent_path_point_material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, debug_navigation_enable_agent_paths_xray);
  714. }
  715. }
  716. bool NavigationServer3D::get_debug_navigation_enable_agent_paths_xray() const {
  717. return debug_navigation_enable_agent_paths_xray;
  718. }
  719. void NavigationServer3D::set_debug_navigation_enabled(bool p_enabled) {
  720. debug_navigation_enabled = p_enabled;
  721. navigation_debug_dirty = true;
  722. call_deferred("_emit_navigation_debug_changed_signal");
  723. }
  724. bool NavigationServer3D::get_debug_navigation_enabled() const {
  725. return debug_navigation_enabled;
  726. }
  727. void NavigationServer3D::set_debug_avoidance_enabled(bool p_enabled) {
  728. debug_avoidance_enabled = p_enabled;
  729. avoidance_debug_dirty = true;
  730. call_deferred("_emit_avoidance_debug_changed_signal");
  731. }
  732. bool NavigationServer3D::get_debug_avoidance_enabled() const {
  733. return debug_avoidance_enabled;
  734. }
  735. #endif // DEBUG_ENABLED
  736. void NavigationServer3D::query_path(const Ref<NavigationPathQueryParameters3D> &p_query_parameters, Ref<NavigationPathQueryResult3D> p_query_result) const {
  737. ERR_FAIL_COND(!p_query_parameters.is_valid());
  738. ERR_FAIL_COND(!p_query_result.is_valid());
  739. const NavigationUtilities::PathQueryResult _query_result = _query_path(p_query_parameters->get_parameters());
  740. p_query_result->set_path(_query_result.path);
  741. p_query_result->set_path_types(_query_result.path_types);
  742. p_query_result->set_path_rids(_query_result.path_rids);
  743. p_query_result->set_path_owner_ids(_query_result.path_owner_ids);
  744. }
  745. ///////////////////////////////////////////////////////
  746. NavigationServer3DCallback NavigationServer3DManager::create_callback = nullptr;
  747. void NavigationServer3DManager::set_default_server(NavigationServer3DCallback p_callback) {
  748. create_callback = p_callback;
  749. }
  750. NavigationServer3D *NavigationServer3DManager::new_default_server() {
  751. if (create_callback == nullptr) {
  752. return nullptr;
  753. }
  754. return create_callback();
  755. }